]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #3630 from opensourcerouting/fix-show-import-check
[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"
48ecf8f5 40#include "bgpd/bgp_attr_evpn.h"
4bf6a362 41#include "bgpd/bgp_advertise.h"
718e3744 42#include "bgpd/bgp_attr.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_community.h"
4bf6a362 45#include "bgpd/bgp_ecommunity.h"
57d187bc 46#include "bgpd/bgp_lcommunity.h"
4bf6a362 47#include "bgpd/bgp_damp.h"
718e3744 48#include "bgpd/bgp_debug.h"
14454c9f 49#include "bgpd/bgp_errors.h"
e0701b79 50#include "bgpd/bgp_fsm.h"
4bf6a362 51#include "bgpd/bgp_nexthop.h"
718e3744 52#include "bgpd/bgp_open.h"
4bf6a362 53#include "bgpd/bgp_regex.h"
718e3744 54#include "bgpd/bgp_route.h"
c016b6c7 55#include "bgpd/bgp_mplsvpn.h"
718e3744 56#include "bgpd/bgp_zebra.h"
fee0f4c6 57#include "bgpd/bgp_table.h"
94f2b392 58#include "bgpd/bgp_vty.h"
165b5fff 59#include "bgpd/bgp_mpath.h"
cb1faec9 60#include "bgpd/bgp_packet.h"
3f9c7369 61#include "bgpd/bgp_updgrp.h"
c43ed2e4 62#include "bgpd/bgp_bfd.h"
555e09d4 63#include "bgpd/bgp_io.h"
94c2f693 64#include "bgpd/bgp_evpn.h"
dcc68b5e 65#include "bgpd/bgp_addpath.h"
48ecf8f5 66#include "bgpd/bgp_mac.h"
718e3744 67
d62a17ae 68static struct peer_group *listen_range_exists(struct bgp *bgp,
69 struct prefix *range, int exact);
70
71static enum node_type bgp_node_type(afi_t afi, safi_t safi)
72{
73 switch (afi) {
74 case AFI_IP:
75 switch (safi) {
76 case SAFI_UNICAST:
77 return BGP_IPV4_NODE;
78 break;
79 case SAFI_MULTICAST:
80 return BGP_IPV4M_NODE;
81 break;
82 case SAFI_LABELED_UNICAST:
83 return BGP_IPV4L_NODE;
84 break;
85 case SAFI_MPLS_VPN:
86 return BGP_VPNV4_NODE;
87 break;
7c40bf39 88 case SAFI_FLOWSPEC:
89 return BGP_FLOWSPECV4_NODE;
5c525538
RW
90 default:
91 /* not expected */
92 return BGP_IPV4_NODE;
93 break;
d62a17ae 94 }
95 break;
96 case AFI_IP6:
97 switch (safi) {
98 case SAFI_UNICAST:
99 return BGP_IPV6_NODE;
100 break;
101 case SAFI_MULTICAST:
102 return BGP_IPV6M_NODE;
103 break;
104 case SAFI_LABELED_UNICAST:
105 return BGP_IPV6L_NODE;
106 break;
107 case SAFI_MPLS_VPN:
108 return BGP_VPNV6_NODE;
109 break;
7c40bf39 110 case SAFI_FLOWSPEC:
111 return BGP_FLOWSPECV6_NODE;
5c525538
RW
112 default:
113 /* not expected */
114 return BGP_IPV4_NODE;
115 break;
d62a17ae 116 }
117 break;
118 case AFI_L2VPN:
119 return BGP_EVPN_NODE;
120 break;
121 case AFI_MAX:
122 // We should never be here but to clarify the switch statement..
123 return BGP_IPV4_NODE;
124 break;
125 }
126
127 // Impossible to happen
128 return BGP_IPV4_NODE;
f51bae9c 129}
20eb8864 130
718e3744 131/* Utility function to get address family from current node. */
d62a17ae 132afi_t bgp_node_afi(struct vty *vty)
133{
134 afi_t afi;
135 switch (vty->node) {
136 case BGP_IPV6_NODE:
137 case BGP_IPV6M_NODE:
138 case BGP_IPV6L_NODE:
139 case BGP_VPNV6_NODE:
7c40bf39 140 case BGP_FLOWSPECV6_NODE:
d62a17ae 141 afi = AFI_IP6;
142 break;
143 case BGP_EVPN_NODE:
144 afi = AFI_L2VPN;
145 break;
146 default:
147 afi = AFI_IP;
148 break;
149 }
150 return afi;
718e3744 151}
152
153/* Utility function to get subsequent address family from current
154 node. */
d62a17ae 155safi_t bgp_node_safi(struct vty *vty)
156{
157 safi_t safi;
158 switch (vty->node) {
159 case BGP_VPNV4_NODE:
160 case BGP_VPNV6_NODE:
161 safi = SAFI_MPLS_VPN;
162 break;
163 case BGP_IPV4M_NODE:
164 case BGP_IPV6M_NODE:
165 safi = SAFI_MULTICAST;
166 break;
167 case BGP_EVPN_NODE:
168 safi = SAFI_EVPN;
169 break;
170 case BGP_IPV4L_NODE:
171 case BGP_IPV6L_NODE:
172 safi = SAFI_LABELED_UNICAST;
173 break;
7c40bf39 174 case BGP_FLOWSPECV4_NODE:
175 case BGP_FLOWSPECV6_NODE:
176 safi = SAFI_FLOWSPEC;
177 break;
d62a17ae 178 default:
179 safi = SAFI_UNICAST;
180 break;
181 }
182 return safi;
718e3744 183}
184
55f91488
QY
185/**
186 * Converts an AFI in string form to afi_t
187 *
188 * @param afi string, one of
189 * - "ipv4"
190 * - "ipv6"
81cf0de5 191 * - "l2vpn"
55f91488
QY
192 * @return the corresponding afi_t
193 */
d62a17ae 194afi_t bgp_vty_afi_from_str(const char *afi_str)
195{
196 afi_t afi = AFI_MAX; /* unknown */
197 if (strmatch(afi_str, "ipv4"))
198 afi = AFI_IP;
199 else if (strmatch(afi_str, "ipv6"))
200 afi = AFI_IP6;
81cf0de5
CS
201 else if (strmatch(afi_str, "l2vpn"))
202 afi = AFI_L2VPN;
d62a17ae 203 return afi;
204}
205
206int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
207 afi_t *afi)
208{
209 int ret = 0;
210 if (argv_find(argv, argc, "ipv4", index)) {
211 ret = 1;
212 if (afi)
213 *afi = AFI_IP;
214 } else if (argv_find(argv, argc, "ipv6", index)) {
215 ret = 1;
216 if (afi)
217 *afi = AFI_IP6;
218 }
219 return ret;
46f296b4
LB
220}
221
375a2e67 222/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 223safi_t bgp_vty_safi_from_str(const char *safi_str)
224{
225 safi_t safi = SAFI_MAX; /* unknown */
226 if (strmatch(safi_str, "multicast"))
227 safi = SAFI_MULTICAST;
228 else if (strmatch(safi_str, "unicast"))
229 safi = SAFI_UNICAST;
230 else if (strmatch(safi_str, "vpn"))
231 safi = SAFI_MPLS_VPN;
81cf0de5
CS
232 else if (strmatch(safi_str, "evpn"))
233 safi = SAFI_EVPN;
d62a17ae 234 else if (strmatch(safi_str, "labeled-unicast"))
235 safi = SAFI_LABELED_UNICAST;
7c40bf39 236 else if (strmatch(safi_str, "flowspec"))
237 safi = SAFI_FLOWSPEC;
d62a17ae 238 return safi;
239}
240
241int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
242 safi_t *safi)
243{
244 int ret = 0;
245 if (argv_find(argv, argc, "unicast", index)) {
246 ret = 1;
247 if (safi)
248 *safi = SAFI_UNICAST;
249 } else if (argv_find(argv, argc, "multicast", index)) {
250 ret = 1;
251 if (safi)
252 *safi = SAFI_MULTICAST;
253 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
254 ret = 1;
255 if (safi)
256 *safi = SAFI_LABELED_UNICAST;
257 } else if (argv_find(argv, argc, "vpn", index)) {
258 ret = 1;
259 if (safi)
260 *safi = SAFI_MPLS_VPN;
7c40bf39 261 } else if (argv_find(argv, argc, "flowspec", index)) {
262 ret = 1;
263 if (safi)
264 *safi = SAFI_FLOWSPEC;
d62a17ae 265 }
266 return ret;
46f296b4
LB
267}
268
7eeee51e 269/*
f212a857 270 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 271 *
f212a857
DS
272 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
273 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
274 * to appropriate values for the calling function. This is to allow the
275 * calling function to make decisions appropriate for the show command
276 * that is being parsed.
277 *
278 * The show commands are generally of the form:
d62a17ae 279 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
280 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
281 *
282 * Since we use argv_find if the show command in particular doesn't have:
283 * [ip]
18c57037 284 * [<view|vrf> VIEWVRFNAME]
375a2e67 285 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
286 * The command parsing should still be ok.
287 *
288 * vty -> The vty for the command so we can output some useful data in
289 * the event of a parse error in the vrf.
290 * argv -> The command tokens
291 * argc -> How many command tokens we have
d62a17ae 292 * idx -> The current place in the command, generally should be 0 for this
293 * function
7eeee51e
DS
294 * afi -> The parsed afi if it was included in the show command, returned here
295 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 296 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
297 *
298 * The function returns the correct location in the parse tree for the
299 * last token found.
0e37c258
DS
300 *
301 * Returns 0 for failure to parse correctly, else the idx position of where
302 * it found the last token.
7eeee51e 303 */
d62a17ae 304int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
305 struct cmd_token **argv, int argc,
306 int *idx, afi_t *afi, safi_t *safi,
9f049418 307 struct bgp **bgp, bool use_json)
d62a17ae 308{
309 char *vrf_name = NULL;
310
311 assert(afi);
312 assert(safi);
313 assert(bgp);
314
315 if (argv_find(argv, argc, "ip", idx))
316 *afi = AFI_IP;
317
9a8bdf1c 318 if (argv_find(argv, argc, "view", idx))
d62a17ae 319 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
320 else if (argv_find(argv, argc, "vrf", idx)) {
321 vrf_name = argv[*idx + 1]->arg;
322 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
323 vrf_name = NULL;
324 }
325 if (vrf_name) {
d62a17ae 326 if (strmatch(vrf_name, "all"))
327 *bgp = NULL;
328 else {
329 *bgp = bgp_lookup_by_name(vrf_name);
330 if (!*bgp) {
ca61fd25
DS
331 if (use_json)
332 vty_out(vty, "{}\n");
333 else
334 vty_out(vty, "View/Vrf %s is unknown\n",
335 vrf_name);
d62a17ae 336 *idx = 0;
337 return 0;
338 }
339 }
340 } else {
341 *bgp = bgp_get_default();
342 if (!*bgp) {
ca61fd25
DS
343 if (use_json)
344 vty_out(vty, "{}\n");
345 else
346 vty_out(vty,
347 "Default BGP instance not found\n");
d62a17ae 348 *idx = 0;
349 return 0;
350 }
351 }
352
353 if (argv_find_and_parse_afi(argv, argc, idx, afi))
354 argv_find_and_parse_safi(argv, argc, idx, safi);
355
356 *idx += 1;
357 return *idx;
358}
359
360static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
361{
362 struct interface *ifp = NULL;
363
364 if (su->sa.sa_family == AF_INET)
365 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
366 else if (su->sa.sa_family == AF_INET6)
367 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
368 su->sin6.sin6_scope_id,
369 bgp->vrf_id);
370
371 if (ifp)
372 return 1;
373
374 return 0;
718e3744 375}
376
377/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
378/* This is used only for configuration, so disallow if attempted on
379 * a dynamic neighbor.
380 */
d62a17ae 381static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
382{
383 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
384 int ret;
385 union sockunion su;
386 struct peer *peer;
387
388 if (!bgp) {
389 return NULL;
390 }
391
392 ret = str2sockunion(ip_str, &su);
393 if (ret < 0) {
394 peer = peer_lookup_by_conf_if(bgp, ip_str);
395 if (!peer) {
396 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
397 == NULL) {
398 vty_out(vty,
399 "%% Malformed address or name: %s\n",
400 ip_str);
401 return NULL;
402 }
403 }
404 } else {
405 peer = peer_lookup(bgp, &su);
406 if (!peer) {
407 vty_out(vty,
408 "%% Specify remote-as or peer-group commands first\n");
409 return NULL;
410 }
411 if (peer_dynamic_neighbor(peer)) {
412 vty_out(vty,
413 "%% Operation not allowed on a dynamic neighbor\n");
414 return NULL;
415 }
416 }
417 return peer;
718e3744 418}
419
420/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
421/* This is used only for configuration, so disallow if attempted on
422 * a dynamic neighbor.
423 */
d62a17ae 424struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
425{
426 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
427 int ret;
428 union sockunion su;
429 struct peer *peer = NULL;
430 struct peer_group *group = NULL;
431
432 if (!bgp) {
433 return NULL;
434 }
435
436 ret = str2sockunion(peer_str, &su);
437 if (ret == 0) {
438 /* IP address, locate peer. */
439 peer = peer_lookup(bgp, &su);
440 } else {
441 /* Not IP, could match either peer configured on interface or a
442 * group. */
443 peer = peer_lookup_by_conf_if(bgp, peer_str);
444 if (!peer)
445 group = peer_group_lookup(bgp, peer_str);
446 }
447
448 if (peer) {
449 if (peer_dynamic_neighbor(peer)) {
450 vty_out(vty,
451 "%% Operation not allowed on a dynamic neighbor\n");
452 return NULL;
453 }
454
455 return peer;
456 }
457
458 if (group)
459 return group->conf;
460
461 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
462
463 return NULL;
464}
465
466int bgp_vty_return(struct vty *vty, int ret)
467{
468 const char *str = NULL;
469
470 switch (ret) {
471 case BGP_ERR_INVALID_VALUE:
472 str = "Invalid value";
473 break;
474 case BGP_ERR_INVALID_FLAG:
475 str = "Invalid flag";
476 break;
477 case BGP_ERR_PEER_GROUP_SHUTDOWN:
478 str = "Peer-group has been shutdown. Activate the peer-group first";
479 break;
480 case BGP_ERR_PEER_FLAG_CONFLICT:
481 str = "Can't set override-capability and strict-capability-match at the same time";
482 break;
483 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
484 str = "Specify remote-as or peer-group remote AS first";
485 break;
486 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
487 str = "Cannot change the peer-group. Deconfigure first";
488 break;
489 case BGP_ERR_PEER_GROUP_MISMATCH:
490 str = "Peer is not a member of this peer-group";
491 break;
492 case BGP_ERR_PEER_FILTER_CONFLICT:
493 str = "Prefix/distribute list can not co-exist";
494 break;
495 case BGP_ERR_NOT_INTERNAL_PEER:
496 str = "Invalid command. Not an internal neighbor";
497 break;
498 case BGP_ERR_REMOVE_PRIVATE_AS:
499 str = "remove-private-AS cannot be configured for IBGP peers";
500 break;
501 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
502 str = "Local-AS allowed only for EBGP peers";
503 break;
504 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
505 str = "Cannot have local-as same as BGP AS number";
506 break;
507 case BGP_ERR_TCPSIG_FAILED:
508 str = "Error while applying TCP-Sig to session(s)";
509 break;
510 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
511 str = "ebgp-multihop and ttl-security cannot be configured together";
512 break;
513 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
514 str = "ttl-security only allowed for EBGP peers";
515 break;
516 case BGP_ERR_AS_OVERRIDE:
517 str = "as-override cannot be configured for IBGP peers";
518 break;
519 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
520 str = "Invalid limit for number of dynamic neighbors";
521 break;
522 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
523 str = "Dynamic neighbor listen range already exists";
524 break;
525 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
526 str = "Operation not allowed on a dynamic neighbor";
527 break;
528 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
529 str = "Operation not allowed on a directly connected neighbor";
530 break;
531 case BGP_ERR_PEER_SAFI_CONFLICT:
532 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
533 break;
534 }
535 if (str) {
536 vty_out(vty, "%% %s\n", str);
537 return CMD_WARNING_CONFIG_FAILED;
538 }
539 return CMD_SUCCESS;
718e3744 540}
541
7aafcaca 542/* BGP clear sort. */
d62a17ae 543enum clear_sort {
544 clear_all,
545 clear_peer,
546 clear_group,
547 clear_external,
548 clear_as
7aafcaca
DS
549};
550
d62a17ae 551static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
552 safi_t safi, int error)
553{
554 switch (error) {
555 case BGP_ERR_AF_UNCONFIGURED:
556 vty_out(vty,
557 "%%BGP: Enable %s address family for the neighbor %s\n",
558 afi_safi_print(afi, safi), peer->host);
559 break;
560 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
561 vty_out(vty,
562 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
563 peer->host);
564 break;
565 default:
566 break;
567 }
7aafcaca
DS
568}
569
570/* `clear ip bgp' functions. */
d62a17ae 571static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
572 enum clear_sort sort, enum bgp_clear_type stype,
573 const char *arg)
574{
575 int ret;
3ae8bfa5 576 bool found = false;
d62a17ae 577 struct peer *peer;
578 struct listnode *node, *nnode;
579
580 /* Clear all neighbors. */
581 /*
582 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
583 * nodes on the BGP instance as that may get freed if it is a
584 * doppelganger
d62a17ae 585 */
586 if (sort == clear_all) {
587 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
3ae8bfa5
PM
588 if (!peer->afc[afi][safi])
589 continue;
590
d62a17ae 591 if (stype == BGP_CLEAR_SOFT_NONE)
592 ret = peer_clear(peer, &nnode);
d62a17ae 593 else
3ae8bfa5 594 ret = peer_clear_soft(peer, afi, safi, stype);
d62a17ae 595
596 if (ret < 0)
597 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
598 else
599 found = true;
04b6bdc0 600 }
d62a17ae 601
602 /* This is to apply read-only mode on this clear. */
603 if (stype == BGP_CLEAR_SOFT_NONE)
604 bgp->update_delay_over = 0;
605
3ae8bfa5 606 if (!found)
3702f84d 607 vty_out(vty, "%%BGP: No %s peer configured\n",
3ae8bfa5
PM
608 afi_safi_print(afi, safi));
609
d62a17ae 610 return CMD_SUCCESS;
7aafcaca
DS
611 }
612
3ae8bfa5 613 /* Clear specified neighbor. */
d62a17ae 614 if (sort == clear_peer) {
615 union sockunion su;
d62a17ae 616
617 /* Make sockunion for lookup. */
618 ret = str2sockunion(arg, &su);
619 if (ret < 0) {
620 peer = peer_lookup_by_conf_if(bgp, arg);
621 if (!peer) {
622 peer = peer_lookup_by_hostname(bgp, arg);
623 if (!peer) {
624 vty_out(vty,
625 "Malformed address or name: %s\n",
626 arg);
627 return CMD_WARNING;
628 }
629 }
630 } else {
631 peer = peer_lookup(bgp, &su);
632 if (!peer) {
633 vty_out(vty,
634 "%%BGP: Unknown neighbor - \"%s\"\n",
635 arg);
636 return CMD_WARNING;
637 }
638 }
7aafcaca 639
3ae8bfa5
PM
640 if (!peer->afc[afi][safi])
641 ret = BGP_ERR_AF_UNCONFIGURED;
642 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 643 ret = peer_clear(peer, NULL);
644 else
645 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 646
d62a17ae 647 if (ret < 0)
648 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 649
d62a17ae 650 return CMD_SUCCESS;
7aafcaca 651 }
7aafcaca 652
3ae8bfa5 653 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 654 if (sort == clear_group) {
655 struct peer_group *group;
7aafcaca 656
d62a17ae 657 group = peer_group_lookup(bgp, arg);
658 if (!group) {
659 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
660 return CMD_WARNING;
661 }
662
663 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
d62a17ae 664 if (!peer->afc[afi][safi])
665 continue;
666
3ae8bfa5
PM
667 if (stype == BGP_CLEAR_SOFT_NONE)
668 ret = peer_clear(peer, NULL);
669 else
670 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 671
d62a17ae 672 if (ret < 0)
673 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
674 else
675 found = true;
d62a17ae 676 }
3ae8bfa5
PM
677
678 if (!found)
679 vty_out(vty,
680 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
681 afi_safi_print(afi, safi), arg);
682
d62a17ae 683 return CMD_SUCCESS;
7aafcaca 684 }
7aafcaca 685
3ae8bfa5 686 /* Clear all external (eBGP) neighbors. */
d62a17ae 687 if (sort == clear_external) {
688 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
689 if (peer->sort == BGP_PEER_IBGP)
690 continue;
7aafcaca 691
3ae8bfa5
PM
692 if (!peer->afc[afi][safi])
693 continue;
694
d62a17ae 695 if (stype == BGP_CLEAR_SOFT_NONE)
696 ret = peer_clear(peer, &nnode);
697 else
698 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 699
d62a17ae 700 if (ret < 0)
701 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
702 else
703 found = true;
d62a17ae 704 }
3ae8bfa5
PM
705
706 if (!found)
707 vty_out(vty,
708 "%%BGP: No external %s peer is configured\n",
709 afi_safi_print(afi, safi));
710
d62a17ae 711 return CMD_SUCCESS;
712 }
713
3ae8bfa5 714 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 715 if (sort == clear_as) {
3ae8bfa5 716 as_t as = strtoul(arg, NULL, 10);
d62a17ae 717
718 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
719 if (peer->as != as)
720 continue;
721
3ae8bfa5
PM
722 if (!peer->afc[afi][safi])
723 ret = BGP_ERR_AF_UNCONFIGURED;
724 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 725 ret = peer_clear(peer, &nnode);
726 else
727 ret = peer_clear_soft(peer, afi, safi, stype);
728
729 if (ret < 0)
730 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
731 else
732 found = true;
d62a17ae 733 }
3ae8bfa5
PM
734
735 if (!found)
d62a17ae 736 vty_out(vty,
3ae8bfa5
PM
737 "%%BGP: No %s peer is configured with AS %s\n",
738 afi_safi_print(afi, safi), arg);
739
d62a17ae 740 return CMD_SUCCESS;
741 }
742
743 return CMD_SUCCESS;
744}
745
746static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
747 safi_t safi, enum clear_sort sort,
748 enum bgp_clear_type stype, const char *arg)
749{
750 struct bgp *bgp;
751
752 /* BGP structure lookup. */
753 if (name) {
754 bgp = bgp_lookup_by_name(name);
755 if (bgp == NULL) {
756 vty_out(vty, "Can't find BGP instance %s\n", name);
757 return CMD_WARNING;
758 }
759 } else {
760 bgp = bgp_get_default();
761 if (bgp == NULL) {
762 vty_out(vty, "No BGP process is configured\n");
763 return CMD_WARNING;
764 }
765 }
766
767 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
768}
769
770/* clear soft inbound */
d62a17ae 771static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 772{
d62a17ae 773 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
774 BGP_CLEAR_SOFT_IN, NULL);
775 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
776 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
777}
778
779/* clear soft outbound */
d62a17ae 780static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 781{
d62a17ae 782 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
783 BGP_CLEAR_SOFT_OUT, NULL);
784 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
785 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
786}
787
788
f787d7a0 789#ifndef VTYSH_EXTRACT_PL
2e4c2296 790#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
791#endif
792
718e3744 793/* BGP global configuration. */
bee57a7a 794#if (CONFDATE > 20190601)
1cc40660
DS
795CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
796CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
797#endif
798DEFUN_HIDDEN (bgp_multiple_instance_func,
799 bgp_multiple_instance_cmd,
800 "bgp multiple-instance",
801 BGP_STR
802 "Enable bgp multiple instance\n")
718e3744 803{
d62a17ae 804 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
805 return CMD_SUCCESS;
718e3744 806}
807
1cc40660 808DEFUN_HIDDEN (no_bgp_multiple_instance,
718e3744 809 no_bgp_multiple_instance_cmd,
810 "no bgp multiple-instance",
811 NO_STR
812 BGP_STR
813 "BGP multiple instance\n")
814{
d62a17ae 815 int ret;
718e3744 816
1cc40660
DS
817 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
818 vty_out(vty, "if you are using this please let the developers know\n");
b7cd3069 819 zlog_info("Deprecated option: `bgp multiple-instance` being used");
d62a17ae 820 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
821 if (ret < 0) {
822 vty_out(vty, "%% There are more than two BGP instances\n");
823 return CMD_WARNING_CONFIG_FAILED;
824 }
825 return CMD_SUCCESS;
718e3744 826}
827
8029b216
AK
828DEFUN_HIDDEN (bgp_local_mac,
829 bgp_local_mac_cmd,
093e3f23 830 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
831 BGP_STR
832 "Local MAC config\n"
833 "VxLAN Network Identifier\n"
834 "VNI number\n"
835 "local mac\n"
836 "mac address\n"
837 "mac-mobility sequence\n"
838 "seq number\n")
839{
840 int rv;
841 vni_t vni;
842 struct ethaddr mac;
843 struct ipaddr ip;
844 uint32_t seq;
845 struct bgp *bgp;
846
847 vni = strtoul(argv[3]->arg, NULL, 10);
848 if (!prefix_str2mac(argv[5]->arg, &mac)) {
849 vty_out(vty, "%% Malformed MAC address\n");
850 return CMD_WARNING;
851 }
852 memset(&ip, 0, sizeof(ip));
853 seq = strtoul(argv[7]->arg, NULL, 10);
854
855 bgp = bgp_get_default();
856 if (!bgp) {
857 vty_out(vty, "Default BGP instance is not there\n");
858 return CMD_WARNING;
859 }
860
861 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
862 if (rv < 0) {
863 vty_out(vty, "Internal error\n");
864 return CMD_WARNING;
865 }
866
867 return CMD_SUCCESS;
868}
869
870DEFUN_HIDDEN (no_bgp_local_mac,
871 no_bgp_local_mac_cmd,
093e3f23 872 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
873 NO_STR
874 BGP_STR
875 "Local MAC config\n"
876 "VxLAN Network Identifier\n"
877 "VNI number\n"
878 "local mac\n"
879 "mac address\n")
880{
881 int rv;
882 vni_t vni;
883 struct ethaddr mac;
884 struct ipaddr ip;
885 struct bgp *bgp;
886
887 vni = strtoul(argv[4]->arg, NULL, 10);
888 if (!prefix_str2mac(argv[6]->arg, &mac)) {
889 vty_out(vty, "%% Malformed MAC address\n");
890 return CMD_WARNING;
891 }
892 memset(&ip, 0, sizeof(ip));
893
894 bgp = bgp_get_default();
895 if (!bgp) {
896 vty_out(vty, "Default BGP instance is not there\n");
897 return CMD_WARNING;
898 }
899
900 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip);
901 if (rv < 0) {
902 vty_out(vty, "Internal error\n");
903 return CMD_WARNING;
904 }
905
906 return CMD_SUCCESS;
907}
908
bee57a7a 909#if (CONFDATE > 20190601)
798467a2
DS
910CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
911CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
912#endif
913DEFUN_HIDDEN (bgp_config_type,
914 bgp_config_type_cmd,
915 "bgp config-type <cisco|zebra>",
916 BGP_STR
917 "Configuration type\n"
918 "cisco\n"
919 "zebra\n")
718e3744 920{
d62a17ae 921 int idx = 0;
798467a2
DS
922 if (argv_find(argv, argc, "cisco", &idx)) {
923 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
924 vty_out(vty, "if you are using this please let the developers know!\n");
b7cd3069 925 zlog_info("Deprecated option: `bgp config-type cisco` being used");
d62a17ae 926 bgp_option_set(BGP_OPT_CONFIG_CISCO);
798467a2 927 } else
d62a17ae 928 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 929
d62a17ae 930 return CMD_SUCCESS;
718e3744 931}
932
798467a2
DS
933DEFUN_HIDDEN (no_bgp_config_type,
934 no_bgp_config_type_cmd,
935 "no bgp config-type [<cisco|zebra>]",
936 NO_STR
937 BGP_STR
938 "Display configuration type\n"
939 "cisco\n"
940 "zebra\n")
718e3744 941{
d62a17ae 942 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
943 return CMD_SUCCESS;
718e3744 944}
945
813d4307 946
718e3744 947DEFUN (no_synchronization,
948 no_synchronization_cmd,
949 "no synchronization",
950 NO_STR
951 "Perform IGP synchronization\n")
952{
d62a17ae 953 return CMD_SUCCESS;
718e3744 954}
955
956DEFUN (no_auto_summary,
957 no_auto_summary_cmd,
958 "no auto-summary",
959 NO_STR
960 "Enable automatic network number summarization\n")
961{
d62a17ae 962 return CMD_SUCCESS;
718e3744 963}
3d515fd9 964
718e3744 965/* "router bgp" commands. */
505e5056 966DEFUN_NOSH (router_bgp,
f412b39a 967 router_bgp_cmd,
18c57037 968 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 969 ROUTER_STR
970 BGP_STR
31500417
DW
971 AS_STR
972 BGP_INSTANCE_HELP_STR)
718e3744 973{
d62a17ae 974 int idx_asn = 2;
975 int idx_view_vrf = 3;
976 int idx_vrf = 4;
ecec9495 977 int is_new_bgp = 0;
d62a17ae 978 int ret;
979 as_t as;
980 struct bgp *bgp;
981 const char *name = NULL;
982 enum bgp_instance_type inst_type;
983
984 // "router bgp" without an ASN
985 if (argc == 2) {
986 // Pending: Make VRF option available for ASN less config
987 bgp = bgp_get_default();
988
989 if (bgp == NULL) {
990 vty_out(vty, "%% No BGP process is configured\n");
991 return CMD_WARNING_CONFIG_FAILED;
992 }
993
994 if (listcount(bm->bgp) > 1) {
996c9314 995 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 996 return CMD_WARNING_CONFIG_FAILED;
997 }
998 }
999
1000 // "router bgp X"
1001 else {
1002 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1003
1004 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1005 if (argc > 3) {
1006 name = argv[idx_vrf]->arg;
1007
9a8bdf1c
PG
1008 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1009 if (strmatch(name, VRF_DEFAULT_NAME))
1010 name = NULL;
1011 else
1012 inst_type = BGP_INSTANCE_TYPE_VRF;
1013 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1014 inst_type = BGP_INSTANCE_TYPE_VIEW;
1015 }
1016
ecec9495
AD
1017 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1018 is_new_bgp = (bgp_lookup(as, name) == NULL);
1019
d62a17ae 1020 ret = bgp_get(&bgp, &as, name, inst_type);
1021 switch (ret) {
1022 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1023 vty_out(vty,
1024 "Please specify 'bgp multiple-instance' first\n");
1025 return CMD_WARNING_CONFIG_FAILED;
1026 case BGP_ERR_AS_MISMATCH:
1027 vty_out(vty, "BGP is already running; AS is %u\n", as);
1028 return CMD_WARNING_CONFIG_FAILED;
1029 case BGP_ERR_INSTANCE_MISMATCH:
1030 vty_out(vty,
1031 "BGP instance name and AS number mismatch\n");
1032 vty_out(vty,
1033 "BGP instance is already running; AS is %u\n",
1034 as);
1035 return CMD_WARNING_CONFIG_FAILED;
1036 }
1037
3bd70bf8
PZ
1038 /*
1039 * If we just instantiated the default instance, complete
1040 * any pending VRF-VPN leaking that was configured via
1041 * earlier "router bgp X vrf FOO" blocks.
1042 */
ecec9495 1043 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
3bd70bf8
PZ
1044 vpn_leak_postchange_all();
1045
d62a17ae 1046 /* Pending: handle when user tries to change a view to vrf n vv.
1047 */
1048 }
1049
0b5131c9
MK
1050 /* unset the auto created flag as the user config is now present */
1051 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 1052 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1053
1054 return CMD_SUCCESS;
718e3744 1055}
1056
718e3744 1057/* "no router bgp" commands. */
1058DEFUN (no_router_bgp,
1059 no_router_bgp_cmd,
18c57037 1060 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 1061 NO_STR
1062 ROUTER_STR
1063 BGP_STR
31500417
DW
1064 AS_STR
1065 BGP_INSTANCE_HELP_STR)
718e3744 1066{
d62a17ae 1067 int idx_asn = 3;
1068 int idx_vrf = 5;
1069 as_t as;
1070 struct bgp *bgp;
1071 const char *name = NULL;
718e3744 1072
d62a17ae 1073 // "no router bgp" without an ASN
1074 if (argc == 3) {
1075 // Pending: Make VRF option available for ASN less config
1076 bgp = bgp_get_default();
718e3744 1077
d62a17ae 1078 if (bgp == NULL) {
1079 vty_out(vty, "%% No BGP process is configured\n");
1080 return CMD_WARNING_CONFIG_FAILED;
1081 }
7fb21a9f 1082
d62a17ae 1083 if (listcount(bm->bgp) > 1) {
996c9314 1084 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1085 return CMD_WARNING_CONFIG_FAILED;
1086 }
0b5131c9
MK
1087
1088 if (bgp->l3vni) {
1089 vty_out(vty, "%% Please unconfigure l3vni %u",
1090 bgp->l3vni);
1091 return CMD_WARNING_CONFIG_FAILED;
1092 }
d62a17ae 1093 } else {
1094 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1095
d62a17ae 1096 if (argc > 4)
1097 name = argv[idx_vrf]->arg;
7fb21a9f 1098
d62a17ae 1099 /* Lookup bgp structure. */
1100 bgp = bgp_lookup(as, name);
1101 if (!bgp) {
1102 vty_out(vty, "%% Can't find BGP instance\n");
1103 return CMD_WARNING_CONFIG_FAILED;
1104 }
0b5131c9
MK
1105
1106 if (bgp->l3vni) {
1107 vty_out(vty, "%% Please unconfigure l3vni %u",
1108 bgp->l3vni);
1109 return CMD_WARNING_CONFIG_FAILED;
1110 }
d62a17ae 1111 }
718e3744 1112
d62a17ae 1113 bgp_delete(bgp);
718e3744 1114
d62a17ae 1115 return CMD_SUCCESS;
718e3744 1116}
1117
6b0655a2 1118
718e3744 1119/* BGP router-id. */
1120
f787d7a0 1121DEFPY (bgp_router_id,
718e3744 1122 bgp_router_id_cmd,
1123 "bgp router-id A.B.C.D",
1124 BGP_STR
1125 "Override configured router identifier\n"
1126 "Manually configured router identifier\n")
1127{
d62a17ae 1128 VTY_DECLVAR_CONTEXT(bgp, bgp);
1129 bgp_router_id_static_set(bgp, router_id);
1130 return CMD_SUCCESS;
718e3744 1131}
1132
f787d7a0 1133DEFPY (no_bgp_router_id,
718e3744 1134 no_bgp_router_id_cmd,
31500417 1135 "no bgp router-id [A.B.C.D]",
718e3744 1136 NO_STR
1137 BGP_STR
31500417
DW
1138 "Override configured router identifier\n"
1139 "Manually configured router identifier\n")
718e3744 1140{
d62a17ae 1141 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1142
d62a17ae 1143 if (router_id_str) {
1144 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1145 vty_out(vty, "%% BGP router-id doesn't match\n");
1146 return CMD_WARNING_CONFIG_FAILED;
1147 }
e018c7cc 1148 }
718e3744 1149
d62a17ae 1150 router_id.s_addr = 0;
1151 bgp_router_id_static_set(bgp, router_id);
718e3744 1152
d62a17ae 1153 return CMD_SUCCESS;
718e3744 1154}
1155
6b0655a2 1156
718e3744 1157/* BGP Cluster ID. */
718e3744 1158DEFUN (bgp_cluster_id,
1159 bgp_cluster_id_cmd,
838758ac 1160 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1161 BGP_STR
1162 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1163 "Route-Reflector Cluster-id in IP address format\n"
1164 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1165{
d62a17ae 1166 VTY_DECLVAR_CONTEXT(bgp, bgp);
1167 int idx_ipv4 = 2;
1168 int ret;
1169 struct in_addr cluster;
718e3744 1170
d62a17ae 1171 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1172 if (!ret) {
1173 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1174 return CMD_WARNING_CONFIG_FAILED;
1175 }
718e3744 1176
d62a17ae 1177 bgp_cluster_id_set(bgp, &cluster);
1178 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1179
d62a17ae 1180 return CMD_SUCCESS;
718e3744 1181}
1182
718e3744 1183DEFUN (no_bgp_cluster_id,
1184 no_bgp_cluster_id_cmd,
c7178fe7 1185 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1186 NO_STR
1187 BGP_STR
838758ac
DW
1188 "Configure Route-Reflector Cluster-id\n"
1189 "Route-Reflector Cluster-id in IP address format\n"
1190 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1191{
d62a17ae 1192 VTY_DECLVAR_CONTEXT(bgp, bgp);
1193 bgp_cluster_id_unset(bgp);
1194 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1195
d62a17ae 1196 return CMD_SUCCESS;
718e3744 1197}
1198
718e3744 1199DEFUN (bgp_confederation_identifier,
1200 bgp_confederation_identifier_cmd,
9ccf14f7 1201 "bgp confederation identifier (1-4294967295)",
718e3744 1202 "BGP specific commands\n"
1203 "AS confederation parameters\n"
1204 "AS number\n"
1205 "Set routing domain confederation AS\n")
1206{
d62a17ae 1207 VTY_DECLVAR_CONTEXT(bgp, bgp);
1208 int idx_number = 3;
1209 as_t as;
718e3744 1210
d62a17ae 1211 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1212
d62a17ae 1213 bgp_confederation_id_set(bgp, as);
718e3744 1214
d62a17ae 1215 return CMD_SUCCESS;
718e3744 1216}
1217
1218DEFUN (no_bgp_confederation_identifier,
1219 no_bgp_confederation_identifier_cmd,
838758ac 1220 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1221 NO_STR
1222 "BGP specific commands\n"
1223 "AS confederation parameters\n"
3a2d747c
QY
1224 "AS number\n"
1225 "Set routing domain confederation AS\n")
718e3744 1226{
d62a17ae 1227 VTY_DECLVAR_CONTEXT(bgp, bgp);
1228 bgp_confederation_id_unset(bgp);
718e3744 1229
d62a17ae 1230 return CMD_SUCCESS;
718e3744 1231}
1232
718e3744 1233DEFUN (bgp_confederation_peers,
1234 bgp_confederation_peers_cmd,
12dcf78e 1235 "bgp confederation peers (1-4294967295)...",
718e3744 1236 "BGP specific commands\n"
1237 "AS confederation parameters\n"
1238 "Peer ASs in BGP confederation\n"
1239 AS_STR)
1240{
d62a17ae 1241 VTY_DECLVAR_CONTEXT(bgp, bgp);
1242 int idx_asn = 3;
1243 as_t as;
1244 int i;
718e3744 1245
d62a17ae 1246 for (i = idx_asn; i < argc; i++) {
1247 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1248
d62a17ae 1249 if (bgp->as == as) {
1250 vty_out(vty,
1251 "%% Local member-AS not allowed in confed peer list\n");
1252 continue;
1253 }
718e3744 1254
d62a17ae 1255 bgp_confederation_peers_add(bgp, as);
1256 }
1257 return CMD_SUCCESS;
718e3744 1258}
1259
1260DEFUN (no_bgp_confederation_peers,
1261 no_bgp_confederation_peers_cmd,
e83a9414 1262 "no bgp confederation peers (1-4294967295)...",
718e3744 1263 NO_STR
1264 "BGP specific commands\n"
1265 "AS confederation parameters\n"
1266 "Peer ASs in BGP confederation\n"
1267 AS_STR)
1268{
d62a17ae 1269 VTY_DECLVAR_CONTEXT(bgp, bgp);
1270 int idx_asn = 4;
1271 as_t as;
1272 int i;
718e3744 1273
d62a17ae 1274 for (i = idx_asn; i < argc; i++) {
1275 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1276
d62a17ae 1277 bgp_confederation_peers_remove(bgp, as);
1278 }
1279 return CMD_SUCCESS;
718e3744 1280}
6b0655a2 1281
5e242b0d
DS
1282/**
1283 * Central routine for maximum-paths configuration.
1284 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1285 * @set: 1 for setting values, 0 for removing the max-paths config.
1286 */
d62a17ae 1287static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1288 const char *mpaths, uint16_t options,
d62a17ae 1289 int set)
1290{
1291 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1292 uint16_t maxpaths = 0;
d62a17ae 1293 int ret;
1294 afi_t afi;
1295 safi_t safi;
1296
1297 afi = bgp_node_afi(vty);
1298 safi = bgp_node_safi(vty);
1299
1300 if (set) {
1301 maxpaths = strtol(mpaths, NULL, 10);
1302 if (maxpaths > multipath_num) {
1303 vty_out(vty,
1304 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1305 maxpaths, multipath_num);
1306 return CMD_WARNING_CONFIG_FAILED;
1307 }
1308 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1309 options);
1310 } else
1311 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1312
1313 if (ret < 0) {
1314 vty_out(vty,
1315 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1316 (set == 1) ? "" : "un",
1317 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1318 maxpaths, afi, safi);
1319 return CMD_WARNING_CONFIG_FAILED;
1320 }
1321
1322 bgp_recalculate_all_bestpaths(bgp);
1323
1324 return CMD_SUCCESS;
165b5fff
JB
1325}
1326
abc920f8
DS
1327DEFUN (bgp_maxmed_admin,
1328 bgp_maxmed_admin_cmd,
1329 "bgp max-med administrative ",
1330 BGP_STR
1331 "Advertise routes with max-med\n"
1332 "Administratively applied, for an indefinite period\n")
1333{
d62a17ae 1334 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1335
d62a17ae 1336 bgp->v_maxmed_admin = 1;
1337 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1338
d62a17ae 1339 bgp_maxmed_update(bgp);
abc920f8 1340
d62a17ae 1341 return CMD_SUCCESS;
abc920f8
DS
1342}
1343
1344DEFUN (bgp_maxmed_admin_medv,
1345 bgp_maxmed_admin_medv_cmd,
4668a151 1346 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1347 BGP_STR
1348 "Advertise routes with max-med\n"
1349 "Administratively applied, for an indefinite period\n"
1350 "Max MED value to be used\n")
1351{
d62a17ae 1352 VTY_DECLVAR_CONTEXT(bgp, bgp);
1353 int idx_number = 3;
abc920f8 1354
d62a17ae 1355 bgp->v_maxmed_admin = 1;
1356 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1357
d62a17ae 1358 bgp_maxmed_update(bgp);
abc920f8 1359
d62a17ae 1360 return CMD_SUCCESS;
abc920f8
DS
1361}
1362
1363DEFUN (no_bgp_maxmed_admin,
1364 no_bgp_maxmed_admin_cmd,
4668a151 1365 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1366 NO_STR
1367 BGP_STR
1368 "Advertise routes with max-med\n"
838758ac
DW
1369 "Administratively applied, for an indefinite period\n"
1370 "Max MED value to be used\n")
abc920f8 1371{
d62a17ae 1372 VTY_DECLVAR_CONTEXT(bgp, bgp);
1373 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1374 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1375 bgp_maxmed_update(bgp);
abc920f8 1376
d62a17ae 1377 return CMD_SUCCESS;
abc920f8
DS
1378}
1379
abc920f8
DS
1380DEFUN (bgp_maxmed_onstartup,
1381 bgp_maxmed_onstartup_cmd,
4668a151 1382 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1383 BGP_STR
1384 "Advertise routes with max-med\n"
1385 "Effective on a startup\n"
1386 "Time (seconds) period for max-med\n"
1387 "Max MED value to be used\n")
1388{
d62a17ae 1389 VTY_DECLVAR_CONTEXT(bgp, bgp);
1390 int idx = 0;
4668a151 1391
d62a17ae 1392 argv_find(argv, argc, "(5-86400)", &idx);
1393 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1394 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1395 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1396 else
1397 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1398
d62a17ae 1399 bgp_maxmed_update(bgp);
abc920f8 1400
d62a17ae 1401 return CMD_SUCCESS;
abc920f8
DS
1402}
1403
1404DEFUN (no_bgp_maxmed_onstartup,
1405 no_bgp_maxmed_onstartup_cmd,
4668a151 1406 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1407 NO_STR
1408 BGP_STR
1409 "Advertise routes with max-med\n"
838758ac
DW
1410 "Effective on a startup\n"
1411 "Time (seconds) period for max-med\n"
1412 "Max MED value to be used\n")
abc920f8 1413{
d62a17ae 1414 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1415
d62a17ae 1416 /* Cancel max-med onstartup if its on */
1417 if (bgp->t_maxmed_onstartup) {
1418 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1419 bgp->maxmed_onstartup_over = 1;
1420 }
abc920f8 1421
d62a17ae 1422 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1423 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1424
d62a17ae 1425 bgp_maxmed_update(bgp);
abc920f8 1426
d62a17ae 1427 return CMD_SUCCESS;
abc920f8
DS
1428}
1429
d62a17ae 1430static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1431 const char *wait)
f188f2c4 1432{
d62a17ae 1433 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1434 uint16_t update_delay;
1435 uint16_t establish_wait;
f188f2c4 1436
d62a17ae 1437 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1438
d62a17ae 1439 if (!wait) /* update-delay <delay> */
1440 {
1441 bgp->v_update_delay = update_delay;
1442 bgp->v_establish_wait = bgp->v_update_delay;
1443 return CMD_SUCCESS;
1444 }
f188f2c4 1445
d62a17ae 1446 /* update-delay <delay> <establish-wait> */
1447 establish_wait = atoi(wait);
1448 if (update_delay < establish_wait) {
1449 vty_out(vty,
1450 "%%Failed: update-delay less than the establish-wait!\n");
1451 return CMD_WARNING_CONFIG_FAILED;
1452 }
f188f2c4 1453
d62a17ae 1454 bgp->v_update_delay = update_delay;
1455 bgp->v_establish_wait = establish_wait;
f188f2c4 1456
d62a17ae 1457 return CMD_SUCCESS;
f188f2c4
DS
1458}
1459
d62a17ae 1460static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1461{
d62a17ae 1462 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1463
d62a17ae 1464 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1465 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1466
d62a17ae 1467 return CMD_SUCCESS;
f188f2c4
DS
1468}
1469
2b791107 1470void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1471{
d62a17ae 1472 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1473 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1474 if (bgp->v_update_delay != bgp->v_establish_wait)
1475 vty_out(vty, " %d", bgp->v_establish_wait);
1476 vty_out(vty, "\n");
1477 }
f188f2c4
DS
1478}
1479
1480
1481/* Update-delay configuration */
1482DEFUN (bgp_update_delay,
1483 bgp_update_delay_cmd,
6147e2c6 1484 "update-delay (0-3600)",
f188f2c4
DS
1485 "Force initial delay for best-path and updates\n"
1486 "Seconds\n")
1487{
d62a17ae 1488 int idx_number = 1;
1489 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1490}
1491
1492DEFUN (bgp_update_delay_establish_wait,
1493 bgp_update_delay_establish_wait_cmd,
6147e2c6 1494 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1495 "Force initial delay for best-path and updates\n"
1496 "Seconds\n"
f188f2c4
DS
1497 "Seconds\n")
1498{
d62a17ae 1499 int idx_number = 1;
1500 int idx_number_2 = 2;
1501 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1502 argv[idx_number_2]->arg);
f188f2c4
DS
1503}
1504
1505/* Update-delay deconfiguration */
1506DEFUN (no_bgp_update_delay,
1507 no_bgp_update_delay_cmd,
838758ac
DW
1508 "no update-delay [(0-3600) [(1-3600)]]",
1509 NO_STR
f188f2c4 1510 "Force initial delay for best-path and updates\n"
838758ac 1511 "Seconds\n"
7111c1a0 1512 "Seconds\n")
f188f2c4 1513{
d62a17ae 1514 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1515}
1516
5e242b0d 1517
d62a17ae 1518static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1519 char set)
cb1faec9 1520{
d62a17ae 1521 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1522
555e09d4
QY
1523 if (set) {
1524 uint32_t quanta = strtoul(num, NULL, 10);
1525 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1526 memory_order_relaxed);
1527 } else {
1528 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1529 memory_order_relaxed);
1530 }
1531
1532 return CMD_SUCCESS;
1533}
1534
1535static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1536 char set)
1537{
1538 VTY_DECLVAR_CONTEXT(bgp, bgp);
1539
1540 if (set) {
1541 uint32_t quanta = strtoul(num, NULL, 10);
1542 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1543 memory_order_relaxed);
1544 } else {
1545 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1546 memory_order_relaxed);
1547 }
cb1faec9 1548
d62a17ae 1549 return CMD_SUCCESS;
cb1faec9
DS
1550}
1551
2b791107 1552void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1553{
555e09d4
QY
1554 uint32_t quanta =
1555 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1556 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1557 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1558}
1559
555e09d4
QY
1560void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1561{
1562 uint32_t quanta =
1563 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1564 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1565 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1566}
cb1faec9 1567
555e09d4 1568/* Packet quanta configuration */
cb1faec9
DS
1569DEFUN (bgp_wpkt_quanta,
1570 bgp_wpkt_quanta_cmd,
555e09d4 1571 "write-quanta (1-10)",
cb1faec9
DS
1572 "How many packets to write to peer socket per run\n"
1573 "Number of packets\n")
1574{
d62a17ae 1575 int idx_number = 1;
1576 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1577}
1578
cb1faec9
DS
1579DEFUN (no_bgp_wpkt_quanta,
1580 no_bgp_wpkt_quanta_cmd,
555e09d4 1581 "no write-quanta (1-10)",
d7fa34c1 1582 NO_STR
555e09d4 1583 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1584 "Number of packets\n")
1585{
d62a17ae 1586 int idx_number = 2;
1587 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1588}
1589
555e09d4
QY
1590DEFUN (bgp_rpkt_quanta,
1591 bgp_rpkt_quanta_cmd,
1592 "read-quanta (1-10)",
1593 "How many packets to read from peer socket per I/O cycle\n"
1594 "Number of packets\n")
1595{
1596 int idx_number = 1;
1597 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1598}
1599
1600DEFUN (no_bgp_rpkt_quanta,
1601 no_bgp_rpkt_quanta_cmd,
1602 "no read-quanta (1-10)",
1603 NO_STR
1604 "How many packets to read from peer socket per I/O cycle\n"
1605 "Number of packets\n")
1606{
1607 int idx_number = 2;
1608 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1609}
1610
2b791107 1611void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1612{
37a333fe 1613 if (!bgp->heuristic_coalesce)
d62a17ae 1614 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1615}
1616
1617
1618DEFUN (bgp_coalesce_time,
1619 bgp_coalesce_time_cmd,
6147e2c6 1620 "coalesce-time (0-4294967295)",
3f9c7369
DS
1621 "Subgroup coalesce timer\n"
1622 "Subgroup coalesce timer value (in ms)\n")
1623{
d62a17ae 1624 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1625
d62a17ae 1626 int idx = 0;
1627 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1628 bgp->heuristic_coalesce = false;
d62a17ae 1629 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1630 return CMD_SUCCESS;
3f9c7369
DS
1631}
1632
1633DEFUN (no_bgp_coalesce_time,
1634 no_bgp_coalesce_time_cmd,
6147e2c6 1635 "no coalesce-time (0-4294967295)",
3a2d747c 1636 NO_STR
3f9c7369
DS
1637 "Subgroup coalesce timer\n"
1638 "Subgroup coalesce timer value (in ms)\n")
1639{
d62a17ae 1640 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1641
37a333fe 1642 bgp->heuristic_coalesce = true;
d62a17ae 1643 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1644 return CMD_SUCCESS;
3f9c7369
DS
1645}
1646
5e242b0d
DS
1647/* Maximum-paths configuration */
1648DEFUN (bgp_maxpaths,
1649 bgp_maxpaths_cmd,
6319fd63 1650 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1651 "Forward packets over multiple paths\n"
1652 "Number of paths\n")
1653{
d62a17ae 1654 int idx_number = 1;
1655 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1656 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1657}
1658
d62a17ae 1659ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1660 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1661 "Forward packets over multiple paths\n"
1662 "Number of paths\n")
596c17ba 1663
165b5fff
JB
1664DEFUN (bgp_maxpaths_ibgp,
1665 bgp_maxpaths_ibgp_cmd,
6319fd63 1666 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1667 "Forward packets over multiple paths\n"
1668 "iBGP-multipath\n"
1669 "Number of paths\n")
1670{
d62a17ae 1671 int idx_number = 2;
1672 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1673 argv[idx_number]->arg, 0, 1);
5e242b0d 1674}
165b5fff 1675
d62a17ae 1676ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1677 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1678 "Forward packets over multiple paths\n"
1679 "iBGP-multipath\n"
1680 "Number of paths\n")
596c17ba 1681
5e242b0d
DS
1682DEFUN (bgp_maxpaths_ibgp_cluster,
1683 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1684 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1685 "Forward packets over multiple paths\n"
1686 "iBGP-multipath\n"
1687 "Number of paths\n"
1688 "Match the cluster length\n")
1689{
d62a17ae 1690 int idx_number = 2;
1691 return bgp_maxpaths_config_vty(
1692 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1693 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1694}
1695
d62a17ae 1696ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1697 "maximum-paths ibgp " CMD_RANGE_STR(
1698 1, MULTIPATH_NUM) " equal-cluster-length",
1699 "Forward packets over multiple paths\n"
1700 "iBGP-multipath\n"
1701 "Number of paths\n"
1702 "Match the cluster length\n")
596c17ba 1703
165b5fff
JB
1704DEFUN (no_bgp_maxpaths,
1705 no_bgp_maxpaths_cmd,
6319fd63 1706 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1707 NO_STR
1708 "Forward packets over multiple paths\n"
1709 "Number of paths\n")
1710{
d62a17ae 1711 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1712}
1713
d62a17ae 1714ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1715 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1716 "Forward packets over multiple paths\n"
1717 "Number of paths\n")
596c17ba 1718
165b5fff
JB
1719DEFUN (no_bgp_maxpaths_ibgp,
1720 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1721 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1722 NO_STR
1723 "Forward packets over multiple paths\n"
1724 "iBGP-multipath\n"
838758ac
DW
1725 "Number of paths\n"
1726 "Match the cluster length\n")
165b5fff 1727{
d62a17ae 1728 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1729}
1730
d62a17ae 1731ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1732 "no maximum-paths ibgp [" CMD_RANGE_STR(
1733 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1734 NO_STR
1735 "Forward packets over multiple paths\n"
1736 "iBGP-multipath\n"
1737 "Number of paths\n"
1738 "Match the cluster length\n")
596c17ba 1739
2b791107 1740void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1741 safi_t safi)
165b5fff 1742{
d62a17ae 1743 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1744 vty_out(vty, " maximum-paths %d\n",
1745 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1746 }
165b5fff 1747
d62a17ae 1748 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1749 vty_out(vty, " maximum-paths ibgp %d",
1750 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1751 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1752 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1753 vty_out(vty, " equal-cluster-length");
1754 vty_out(vty, "\n");
1755 }
165b5fff 1756}
6b0655a2 1757
718e3744 1758/* BGP timers. */
1759
1760DEFUN (bgp_timers,
1761 bgp_timers_cmd,
6147e2c6 1762 "timers bgp (0-65535) (0-65535)",
718e3744 1763 "Adjust routing timers\n"
1764 "BGP timers\n"
1765 "Keepalive interval\n"
1766 "Holdtime\n")
1767{
d62a17ae 1768 VTY_DECLVAR_CONTEXT(bgp, bgp);
1769 int idx_number = 2;
1770 int idx_number_2 = 3;
1771 unsigned long keepalive = 0;
1772 unsigned long holdtime = 0;
718e3744 1773
d62a17ae 1774 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1775 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1776
d62a17ae 1777 /* Holdtime value check. */
1778 if (holdtime < 3 && holdtime != 0) {
1779 vty_out(vty,
1780 "%% hold time value must be either 0 or greater than 3\n");
1781 return CMD_WARNING_CONFIG_FAILED;
1782 }
718e3744 1783
d62a17ae 1784 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1785
d62a17ae 1786 return CMD_SUCCESS;
718e3744 1787}
1788
1789DEFUN (no_bgp_timers,
1790 no_bgp_timers_cmd,
838758ac 1791 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1792 NO_STR
1793 "Adjust routing timers\n"
838758ac
DW
1794 "BGP timers\n"
1795 "Keepalive interval\n"
1796 "Holdtime\n")
718e3744 1797{
d62a17ae 1798 VTY_DECLVAR_CONTEXT(bgp, bgp);
1799 bgp_timers_unset(bgp);
718e3744 1800
d62a17ae 1801 return CMD_SUCCESS;
718e3744 1802}
1803
6b0655a2 1804
718e3744 1805DEFUN (bgp_client_to_client_reflection,
1806 bgp_client_to_client_reflection_cmd,
1807 "bgp client-to-client reflection",
1808 "BGP specific commands\n"
1809 "Configure client to client route reflection\n"
1810 "reflection of routes allowed\n")
1811{
d62a17ae 1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
1813 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1814 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1815
d62a17ae 1816 return CMD_SUCCESS;
718e3744 1817}
1818
1819DEFUN (no_bgp_client_to_client_reflection,
1820 no_bgp_client_to_client_reflection_cmd,
1821 "no bgp client-to-client reflection",
1822 NO_STR
1823 "BGP specific commands\n"
1824 "Configure client to client route reflection\n"
1825 "reflection of routes allowed\n")
1826{
d62a17ae 1827 VTY_DECLVAR_CONTEXT(bgp, bgp);
1828 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1829 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1830
d62a17ae 1831 return CMD_SUCCESS;
718e3744 1832}
1833
1834/* "bgp always-compare-med" configuration. */
1835DEFUN (bgp_always_compare_med,
1836 bgp_always_compare_med_cmd,
1837 "bgp always-compare-med",
1838 "BGP specific commands\n"
1839 "Allow comparing MED from different neighbors\n")
1840{
d62a17ae 1841 VTY_DECLVAR_CONTEXT(bgp, bgp);
1842 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1843 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1844
d62a17ae 1845 return CMD_SUCCESS;
718e3744 1846}
1847
1848DEFUN (no_bgp_always_compare_med,
1849 no_bgp_always_compare_med_cmd,
1850 "no bgp always-compare-med",
1851 NO_STR
1852 "BGP specific commands\n"
1853 "Allow comparing MED from different neighbors\n")
1854{
d62a17ae 1855 VTY_DECLVAR_CONTEXT(bgp, bgp);
1856 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1857 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1858
d62a17ae 1859 return CMD_SUCCESS;
718e3744 1860}
6b0655a2 1861
718e3744 1862/* "bgp deterministic-med" configuration. */
1863DEFUN (bgp_deterministic_med,
1864 bgp_deterministic_med_cmd,
1865 "bgp deterministic-med",
1866 "BGP specific commands\n"
1867 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1868{
d62a17ae 1869 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1870
d62a17ae 1871 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1872 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1873 bgp_recalculate_all_bestpaths(bgp);
1874 }
7aafcaca 1875
d62a17ae 1876 return CMD_SUCCESS;
718e3744 1877}
1878
1879DEFUN (no_bgp_deterministic_med,
1880 no_bgp_deterministic_med_cmd,
1881 "no bgp deterministic-med",
1882 NO_STR
1883 "BGP specific commands\n"
1884 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1885{
d62a17ae 1886 VTY_DECLVAR_CONTEXT(bgp, bgp);
1887 int bestpath_per_as_used;
1888 afi_t afi;
1889 safi_t safi;
1890 struct peer *peer;
1891 struct listnode *node, *nnode;
1892
1893 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1894 bestpath_per_as_used = 0;
1895
1896 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 1897 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
1898 if (bgp_addpath_dmed_required(
1899 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
1900 bestpath_per_as_used = 1;
1901 break;
1902 }
d62a17ae 1903
1904 if (bestpath_per_as_used)
1905 break;
1906 }
1907
1908 if (bestpath_per_as_used) {
1909 vty_out(vty,
1910 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1911 return CMD_WARNING_CONFIG_FAILED;
1912 } else {
1913 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1914 bgp_recalculate_all_bestpaths(bgp);
1915 }
1916 }
1917
1918 return CMD_SUCCESS;
718e3744 1919}
538621f2 1920
1921/* "bgp graceful-restart" configuration. */
1922DEFUN (bgp_graceful_restart,
1923 bgp_graceful_restart_cmd,
1924 "bgp graceful-restart",
1925 "BGP specific commands\n"
1926 "Graceful restart capability parameters\n")
1927{
d62a17ae 1928 VTY_DECLVAR_CONTEXT(bgp, bgp);
1929 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1930 return CMD_SUCCESS;
538621f2 1931}
1932
1933DEFUN (no_bgp_graceful_restart,
1934 no_bgp_graceful_restart_cmd,
1935 "no bgp graceful-restart",
1936 NO_STR
1937 "BGP specific commands\n"
1938 "Graceful restart capability parameters\n")
1939{
d62a17ae 1940 VTY_DECLVAR_CONTEXT(bgp, bgp);
1941 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1942 return CMD_SUCCESS;
538621f2 1943}
1944
93406d87 1945DEFUN (bgp_graceful_restart_stalepath_time,
1946 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1947 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1948 "BGP specific commands\n"
1949 "Graceful restart capability parameters\n"
1950 "Set the max time to hold onto restarting peer's stale paths\n"
1951 "Delay value (seconds)\n")
1952{
d62a17ae 1953 VTY_DECLVAR_CONTEXT(bgp, bgp);
1954 int idx_number = 3;
d7c0a89a 1955 uint32_t stalepath;
93406d87 1956
d62a17ae 1957 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1958 bgp->stalepath_time = stalepath;
1959 return CMD_SUCCESS;
93406d87 1960}
1961
eb6f1b41
PG
1962DEFUN (bgp_graceful_restart_restart_time,
1963 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1964 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1965 "BGP specific commands\n"
1966 "Graceful restart capability parameters\n"
1967 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1968 "Delay value (seconds)\n")
1969{
d62a17ae 1970 VTY_DECLVAR_CONTEXT(bgp, bgp);
1971 int idx_number = 3;
d7c0a89a 1972 uint32_t restart;
eb6f1b41 1973
d62a17ae 1974 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1975 bgp->restart_time = restart;
1976 return CMD_SUCCESS;
eb6f1b41
PG
1977}
1978
93406d87 1979DEFUN (no_bgp_graceful_restart_stalepath_time,
1980 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1981 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1982 NO_STR
1983 "BGP specific commands\n"
1984 "Graceful restart capability parameters\n"
838758ac
DW
1985 "Set the max time to hold onto restarting peer's stale paths\n"
1986 "Delay value (seconds)\n")
93406d87 1987{
d62a17ae 1988 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1989
d62a17ae 1990 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1991 return CMD_SUCCESS;
93406d87 1992}
1993
eb6f1b41
PG
1994DEFUN (no_bgp_graceful_restart_restart_time,
1995 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1996 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1997 NO_STR
1998 "BGP specific commands\n"
1999 "Graceful restart capability parameters\n"
838758ac
DW
2000 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2001 "Delay value (seconds)\n")
eb6f1b41 2002{
d62a17ae 2003 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2004
d62a17ae 2005 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2006 return CMD_SUCCESS;
eb6f1b41
PG
2007}
2008
43fc21b3
JC
2009DEFUN (bgp_graceful_restart_preserve_fw,
2010 bgp_graceful_restart_preserve_fw_cmd,
2011 "bgp graceful-restart preserve-fw-state",
2012 "BGP specific commands\n"
2013 "Graceful restart capability parameters\n"
2014 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2015{
d62a17ae 2016 VTY_DECLVAR_CONTEXT(bgp, bgp);
2017 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2018 return CMD_SUCCESS;
43fc21b3
JC
2019}
2020
2021DEFUN (no_bgp_graceful_restart_preserve_fw,
2022 no_bgp_graceful_restart_preserve_fw_cmd,
2023 "no bgp graceful-restart preserve-fw-state",
2024 NO_STR
2025 "BGP specific commands\n"
2026 "Graceful restart capability parameters\n"
2027 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2028{
d62a17ae 2029 VTY_DECLVAR_CONTEXT(bgp, bgp);
2030 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2031 return CMD_SUCCESS;
43fc21b3
JC
2032}
2033
7f323236
DW
2034static void bgp_redistribute_redo(struct bgp *bgp)
2035{
2036 afi_t afi;
2037 int i;
2038 struct list *red_list;
2039 struct listnode *node;
2040 struct bgp_redist *red;
2041
a4d82a8a
PZ
2042 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2043 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 2044
a4d82a8a
PZ
2045 red_list = bgp->redist[afi][i];
2046 if (!red_list)
2047 continue;
7f323236 2048
a4d82a8a 2049 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
2050 bgp_redistribute_resend(bgp, afi, i,
2051 red->instance);
2052 }
2053 }
2054 }
2055}
2056
2057/* "bgp graceful-shutdown" configuration */
2058DEFUN (bgp_graceful_shutdown,
2059 bgp_graceful_shutdown_cmd,
2060 "bgp graceful-shutdown",
2061 BGP_STR
2062 "Graceful shutdown parameters\n")
2063{
2064 VTY_DECLVAR_CONTEXT(bgp, bgp);
2065
2066 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2067 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2068 bgp_static_redo_import_check(bgp);
2069 bgp_redistribute_redo(bgp);
2070 bgp_clear_star_soft_out(vty, bgp->name);
2071 bgp_clear_star_soft_in(vty, bgp->name);
2072 }
2073
2074 return CMD_SUCCESS;
2075}
2076
2077DEFUN (no_bgp_graceful_shutdown,
2078 no_bgp_graceful_shutdown_cmd,
2079 "no bgp graceful-shutdown",
2080 NO_STR
2081 BGP_STR
2082 "Graceful shutdown parameters\n")
2083{
2084 VTY_DECLVAR_CONTEXT(bgp, bgp);
2085
2086 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2087 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2088 bgp_static_redo_import_check(bgp);
2089 bgp_redistribute_redo(bgp);
2090 bgp_clear_star_soft_out(vty, bgp->name);
2091 bgp_clear_star_soft_in(vty, bgp->name);
2092 }
2093
2094 return CMD_SUCCESS;
2095}
2096
718e3744 2097/* "bgp fast-external-failover" configuration. */
2098DEFUN (bgp_fast_external_failover,
2099 bgp_fast_external_failover_cmd,
2100 "bgp fast-external-failover",
2101 BGP_STR
2102 "Immediately reset session if a link to a directly connected external peer goes down\n")
2103{
d62a17ae 2104 VTY_DECLVAR_CONTEXT(bgp, bgp);
2105 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2106 return CMD_SUCCESS;
718e3744 2107}
2108
2109DEFUN (no_bgp_fast_external_failover,
2110 no_bgp_fast_external_failover_cmd,
2111 "no bgp fast-external-failover",
2112 NO_STR
2113 BGP_STR
2114 "Immediately reset session if a link to a directly connected external peer goes down\n")
2115{
d62a17ae 2116 VTY_DECLVAR_CONTEXT(bgp, bgp);
2117 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2118 return CMD_SUCCESS;
718e3744 2119}
6b0655a2 2120
718e3744 2121/* "bgp enforce-first-as" configuration. */
ec4f0750 2122#if CONFDATE > 20190517
47cbc09b
PM
2123CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2124#endif
2125
f07e1c4f
QY
2126DEFUN_HIDDEN (bgp_enforce_first_as,
2127 bgp_enforce_first_as_cmd,
2128 "[no] bgp enforce-first-as",
2129 NO_STR
2130 BGP_STR
2131 "Enforce the first AS for EBGP routes\n")
718e3744 2132{
d62a17ae 2133 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2134
f07e1c4f
QY
2135 if (strmatch(argv[0]->text, "no"))
2136 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2137 else
2138 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
7aafcaca 2139
d62a17ae 2140 return CMD_SUCCESS;
718e3744 2141}
6b0655a2 2142
718e3744 2143/* "bgp bestpath compare-routerid" configuration. */
2144DEFUN (bgp_bestpath_compare_router_id,
2145 bgp_bestpath_compare_router_id_cmd,
2146 "bgp bestpath compare-routerid",
2147 "BGP specific commands\n"
2148 "Change the default bestpath selection\n"
2149 "Compare router-id for identical EBGP paths\n")
2150{
d62a17ae 2151 VTY_DECLVAR_CONTEXT(bgp, bgp);
2152 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2153 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2154
d62a17ae 2155 return CMD_SUCCESS;
718e3744 2156}
2157
2158DEFUN (no_bgp_bestpath_compare_router_id,
2159 no_bgp_bestpath_compare_router_id_cmd,
2160 "no bgp bestpath compare-routerid",
2161 NO_STR
2162 "BGP specific commands\n"
2163 "Change the default bestpath selection\n"
2164 "Compare router-id for identical EBGP paths\n")
2165{
d62a17ae 2166 VTY_DECLVAR_CONTEXT(bgp, bgp);
2167 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2168 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2169
d62a17ae 2170 return CMD_SUCCESS;
718e3744 2171}
6b0655a2 2172
718e3744 2173/* "bgp bestpath as-path ignore" configuration. */
2174DEFUN (bgp_bestpath_aspath_ignore,
2175 bgp_bestpath_aspath_ignore_cmd,
2176 "bgp bestpath as-path ignore",
2177 "BGP specific commands\n"
2178 "Change the default bestpath selection\n"
2179 "AS-path attribute\n"
2180 "Ignore as-path length in selecting a route\n")
2181{
d62a17ae 2182 VTY_DECLVAR_CONTEXT(bgp, bgp);
2183 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2184 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2185
d62a17ae 2186 return CMD_SUCCESS;
718e3744 2187}
2188
2189DEFUN (no_bgp_bestpath_aspath_ignore,
2190 no_bgp_bestpath_aspath_ignore_cmd,
2191 "no bgp bestpath as-path ignore",
2192 NO_STR
2193 "BGP specific commands\n"
2194 "Change the default bestpath selection\n"
2195 "AS-path attribute\n"
2196 "Ignore as-path length in selecting a route\n")
2197{
d62a17ae 2198 VTY_DECLVAR_CONTEXT(bgp, bgp);
2199 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2200 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2201
d62a17ae 2202 return CMD_SUCCESS;
718e3744 2203}
6b0655a2 2204
6811845b 2205/* "bgp bestpath as-path confed" configuration. */
2206DEFUN (bgp_bestpath_aspath_confed,
2207 bgp_bestpath_aspath_confed_cmd,
2208 "bgp bestpath as-path confed",
2209 "BGP specific commands\n"
2210 "Change the default bestpath selection\n"
2211 "AS-path attribute\n"
2212 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2213{
d62a17ae 2214 VTY_DECLVAR_CONTEXT(bgp, bgp);
2215 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2216 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2217
d62a17ae 2218 return CMD_SUCCESS;
6811845b 2219}
2220
2221DEFUN (no_bgp_bestpath_aspath_confed,
2222 no_bgp_bestpath_aspath_confed_cmd,
2223 "no bgp bestpath as-path confed",
2224 NO_STR
2225 "BGP specific commands\n"
2226 "Change the default bestpath selection\n"
2227 "AS-path attribute\n"
2228 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2229{
d62a17ae 2230 VTY_DECLVAR_CONTEXT(bgp, bgp);
2231 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2232 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2233
d62a17ae 2234 return CMD_SUCCESS;
6811845b 2235}
6b0655a2 2236
2fdd455c
PM
2237/* "bgp bestpath as-path multipath-relax" configuration. */
2238DEFUN (bgp_bestpath_aspath_multipath_relax,
2239 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2240 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2241 "BGP specific commands\n"
2242 "Change the default bestpath selection\n"
2243 "AS-path attribute\n"
2244 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2245 "Generate an AS_SET\n"
16fc1eec
DS
2246 "Do not generate an AS_SET\n")
2247{
d62a17ae 2248 VTY_DECLVAR_CONTEXT(bgp, bgp);
2249 int idx = 0;
2250 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2251
d62a17ae 2252 /* no-as-set is now the default behavior so we can silently
2253 * ignore it */
2254 if (argv_find(argv, argc, "as-set", &idx))
2255 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2256 else
2257 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2258
d62a17ae 2259 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2260
d62a17ae 2261 return CMD_SUCCESS;
16fc1eec
DS
2262}
2263
219178b6
DW
2264DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2265 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2266 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2267 NO_STR
2268 "BGP specific commands\n"
2269 "Change the default bestpath selection\n"
2270 "AS-path attribute\n"
2271 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2272 "Generate an AS_SET\n"
16fc1eec
DS
2273 "Do not generate an AS_SET\n")
2274{
d62a17ae 2275 VTY_DECLVAR_CONTEXT(bgp, bgp);
2276 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2277 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2278 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2279
d62a17ae 2280 return CMD_SUCCESS;
2fdd455c 2281}
6b0655a2 2282
848973c7 2283/* "bgp log-neighbor-changes" configuration. */
2284DEFUN (bgp_log_neighbor_changes,
2285 bgp_log_neighbor_changes_cmd,
2286 "bgp log-neighbor-changes",
2287 "BGP specific commands\n"
2288 "Log neighbor up/down and reset reason\n")
2289{
d62a17ae 2290 VTY_DECLVAR_CONTEXT(bgp, bgp);
2291 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2292 return CMD_SUCCESS;
848973c7 2293}
2294
2295DEFUN (no_bgp_log_neighbor_changes,
2296 no_bgp_log_neighbor_changes_cmd,
2297 "no bgp log-neighbor-changes",
2298 NO_STR
2299 "BGP specific commands\n"
2300 "Log neighbor up/down and reset reason\n")
2301{
d62a17ae 2302 VTY_DECLVAR_CONTEXT(bgp, bgp);
2303 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2304 return CMD_SUCCESS;
848973c7 2305}
6b0655a2 2306
718e3744 2307/* "bgp bestpath med" configuration. */
2308DEFUN (bgp_bestpath_med,
2309 bgp_bestpath_med_cmd,
2d8c1a4d 2310 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2311 "BGP specific commands\n"
2312 "Change the default bestpath selection\n"
2313 "MED attribute\n"
2314 "Compare MED among confederation paths\n"
838758ac
DW
2315 "Treat missing MED as the least preferred one\n"
2316 "Treat missing MED as the least preferred one\n"
2317 "Compare MED among confederation paths\n")
718e3744 2318{
d62a17ae 2319 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2320
d62a17ae 2321 int idx = 0;
2322 if (argv_find(argv, argc, "confed", &idx))
2323 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2324 idx = 0;
2325 if (argv_find(argv, argc, "missing-as-worst", &idx))
2326 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2327
d62a17ae 2328 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2329
d62a17ae 2330 return CMD_SUCCESS;
718e3744 2331}
2332
718e3744 2333DEFUN (no_bgp_bestpath_med,
2334 no_bgp_bestpath_med_cmd,
2d8c1a4d 2335 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2336 NO_STR
2337 "BGP specific commands\n"
2338 "Change the default bestpath selection\n"
2339 "MED attribute\n"
2340 "Compare MED among confederation paths\n"
3a2d747c
QY
2341 "Treat missing MED as the least preferred one\n"
2342 "Treat missing MED as the least preferred one\n"
2343 "Compare MED among confederation paths\n")
718e3744 2344{
d62a17ae 2345 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2346
d62a17ae 2347 int idx = 0;
2348 if (argv_find(argv, argc, "confed", &idx))
2349 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2350 idx = 0;
2351 if (argv_find(argv, argc, "missing-as-worst", &idx))
2352 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2353
d62a17ae 2354 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2355
d62a17ae 2356 return CMD_SUCCESS;
718e3744 2357}
2358
718e3744 2359/* "no bgp default ipv4-unicast". */
2360DEFUN (no_bgp_default_ipv4_unicast,
2361 no_bgp_default_ipv4_unicast_cmd,
2362 "no bgp default ipv4-unicast",
2363 NO_STR
2364 "BGP specific commands\n"
2365 "Configure BGP defaults\n"
2366 "Activate ipv4-unicast for a peer by default\n")
2367{
d62a17ae 2368 VTY_DECLVAR_CONTEXT(bgp, bgp);
2369 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2370 return CMD_SUCCESS;
718e3744 2371}
2372
2373DEFUN (bgp_default_ipv4_unicast,
2374 bgp_default_ipv4_unicast_cmd,
2375 "bgp default ipv4-unicast",
2376 "BGP specific commands\n"
2377 "Configure BGP defaults\n"
2378 "Activate ipv4-unicast for a peer by default\n")
2379{
d62a17ae 2380 VTY_DECLVAR_CONTEXT(bgp, bgp);
2381 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2382 return CMD_SUCCESS;
718e3744 2383}
6b0655a2 2384
04b6bdc0
DW
2385/* Display hostname in certain command outputs */
2386DEFUN (bgp_default_show_hostname,
2387 bgp_default_show_hostname_cmd,
2388 "bgp default show-hostname",
2389 "BGP specific commands\n"
2390 "Configure BGP defaults\n"
0437e105 2391 "Show hostname in certain command outputs\n")
04b6bdc0 2392{
d62a17ae 2393 VTY_DECLVAR_CONTEXT(bgp, bgp);
2394 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2395 return CMD_SUCCESS;
04b6bdc0
DW
2396}
2397
2398DEFUN (no_bgp_default_show_hostname,
2399 no_bgp_default_show_hostname_cmd,
2400 "no bgp default show-hostname",
2401 NO_STR
2402 "BGP specific commands\n"
2403 "Configure BGP defaults\n"
0437e105 2404 "Show hostname in certain command outputs\n")
04b6bdc0 2405{
d62a17ae 2406 VTY_DECLVAR_CONTEXT(bgp, bgp);
2407 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2408 return CMD_SUCCESS;
04b6bdc0
DW
2409}
2410
8233ef81 2411/* "bgp network import-check" configuration. */
718e3744 2412DEFUN (bgp_network_import_check,
2413 bgp_network_import_check_cmd,
5623e905 2414 "bgp network import-check",
718e3744 2415 "BGP specific commands\n"
2416 "BGP network command\n"
5623e905 2417 "Check BGP network route exists in IGP\n")
718e3744 2418{
d62a17ae 2419 VTY_DECLVAR_CONTEXT(bgp, bgp);
2420 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2421 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2422 bgp_static_redo_import_check(bgp);
2423 }
078430f6 2424
d62a17ae 2425 return CMD_SUCCESS;
718e3744 2426}
2427
d62a17ae 2428ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2429 "bgp network import-check exact",
2430 "BGP specific commands\n"
2431 "BGP network command\n"
2432 "Check BGP network route exists in IGP\n"
2433 "Match route precisely\n")
8233ef81 2434
718e3744 2435DEFUN (no_bgp_network_import_check,
2436 no_bgp_network_import_check_cmd,
5623e905 2437 "no bgp network import-check",
718e3744 2438 NO_STR
2439 "BGP specific commands\n"
2440 "BGP network command\n"
2441 "Check BGP network route exists in IGP\n")
2442{
d62a17ae 2443 VTY_DECLVAR_CONTEXT(bgp, bgp);
2444 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2445 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2446 bgp_static_redo_import_check(bgp);
2447 }
5623e905 2448
d62a17ae 2449 return CMD_SUCCESS;
718e3744 2450}
6b0655a2 2451
718e3744 2452DEFUN (bgp_default_local_preference,
2453 bgp_default_local_preference_cmd,
6147e2c6 2454 "bgp default local-preference (0-4294967295)",
718e3744 2455 "BGP specific commands\n"
2456 "Configure BGP defaults\n"
2457 "local preference (higher=more preferred)\n"
2458 "Configure default local preference value\n")
2459{
d62a17ae 2460 VTY_DECLVAR_CONTEXT(bgp, bgp);
2461 int idx_number = 3;
d7c0a89a 2462 uint32_t local_pref;
718e3744 2463
d62a17ae 2464 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2465
d62a17ae 2466 bgp_default_local_preference_set(bgp, local_pref);
2467 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2468
d62a17ae 2469 return CMD_SUCCESS;
718e3744 2470}
2471
2472DEFUN (no_bgp_default_local_preference,
2473 no_bgp_default_local_preference_cmd,
838758ac 2474 "no bgp default local-preference [(0-4294967295)]",
718e3744 2475 NO_STR
2476 "BGP specific commands\n"
2477 "Configure BGP defaults\n"
838758ac
DW
2478 "local preference (higher=more preferred)\n"
2479 "Configure default local preference value\n")
718e3744 2480{
d62a17ae 2481 VTY_DECLVAR_CONTEXT(bgp, bgp);
2482 bgp_default_local_preference_unset(bgp);
2483 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2484
d62a17ae 2485 return CMD_SUCCESS;
718e3744 2486}
2487
6b0655a2 2488
3f9c7369
DS
2489DEFUN (bgp_default_subgroup_pkt_queue_max,
2490 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2491 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2492 "BGP specific commands\n"
2493 "Configure BGP defaults\n"
2494 "subgroup-pkt-queue-max\n"
2495 "Configure subgroup packet queue max\n")
8bd9d948 2496{
d62a17ae 2497 VTY_DECLVAR_CONTEXT(bgp, bgp);
2498 int idx_number = 3;
d7c0a89a 2499 uint32_t max_size;
8bd9d948 2500
d62a17ae 2501 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2502
d62a17ae 2503 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2504
d62a17ae 2505 return CMD_SUCCESS;
3f9c7369
DS
2506}
2507
2508DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2509 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2510 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2511 NO_STR
2512 "BGP specific commands\n"
2513 "Configure BGP defaults\n"
838758ac
DW
2514 "subgroup-pkt-queue-max\n"
2515 "Configure subgroup packet queue max\n")
3f9c7369 2516{
d62a17ae 2517 VTY_DECLVAR_CONTEXT(bgp, bgp);
2518 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2519 return CMD_SUCCESS;
8bd9d948
DS
2520}
2521
813d4307 2522
8bd9d948
DS
2523DEFUN (bgp_rr_allow_outbound_policy,
2524 bgp_rr_allow_outbound_policy_cmd,
2525 "bgp route-reflector allow-outbound-policy",
2526 "BGP specific commands\n"
2527 "Allow modifications made by out route-map\n"
2528 "on ibgp neighbors\n")
2529{
d62a17ae 2530 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2531
d62a17ae 2532 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2533 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2534 update_group_announce_rrclients(bgp);
2535 bgp_clear_star_soft_out(vty, bgp->name);
2536 }
8bd9d948 2537
d62a17ae 2538 return CMD_SUCCESS;
8bd9d948
DS
2539}
2540
2541DEFUN (no_bgp_rr_allow_outbound_policy,
2542 no_bgp_rr_allow_outbound_policy_cmd,
2543 "no bgp route-reflector allow-outbound-policy",
2544 NO_STR
2545 "BGP specific commands\n"
2546 "Allow modifications made by out route-map\n"
2547 "on ibgp neighbors\n")
2548{
d62a17ae 2549 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2550
d62a17ae 2551 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2552 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2553 update_group_announce_rrclients(bgp);
2554 bgp_clear_star_soft_out(vty, bgp->name);
2555 }
8bd9d948 2556
d62a17ae 2557 return CMD_SUCCESS;
8bd9d948
DS
2558}
2559
f14e6fdb
DS
2560DEFUN (bgp_listen_limit,
2561 bgp_listen_limit_cmd,
9ccf14f7 2562 "bgp listen limit (1-5000)",
f14e6fdb
DS
2563 "BGP specific commands\n"
2564 "Configure BGP defaults\n"
2565 "maximum number of BGP Dynamic Neighbors that can be created\n"
2566 "Configure Dynamic Neighbors listen limit value\n")
2567{
d62a17ae 2568 VTY_DECLVAR_CONTEXT(bgp, bgp);
2569 int idx_number = 3;
2570 int listen_limit;
f14e6fdb 2571
d62a17ae 2572 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2573
d62a17ae 2574 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2575
d62a17ae 2576 return CMD_SUCCESS;
f14e6fdb
DS
2577}
2578
2579DEFUN (no_bgp_listen_limit,
2580 no_bgp_listen_limit_cmd,
838758ac 2581 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2582 "BGP specific commands\n"
2583 "Configure BGP defaults\n"
2584 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2585 "Configure Dynamic Neighbors listen limit value to default\n"
2586 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2587{
d62a17ae 2588 VTY_DECLVAR_CONTEXT(bgp, bgp);
2589 bgp_listen_limit_unset(bgp);
2590 return CMD_SUCCESS;
f14e6fdb
DS
2591}
2592
2593
20eb8864 2594/*
2595 * Check if this listen range is already configured. Check for exact
2596 * match or overlap based on input.
2597 */
d62a17ae 2598static struct peer_group *listen_range_exists(struct bgp *bgp,
2599 struct prefix *range, int exact)
2600{
2601 struct listnode *node, *nnode;
2602 struct listnode *node1, *nnode1;
2603 struct peer_group *group;
2604 struct prefix *lr;
2605 afi_t afi;
2606 int match;
2607
2608 afi = family2afi(range->family);
2609 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2610 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2611 lr)) {
2612 if (exact)
2613 match = prefix_same(range, lr);
2614 else
2615 match = (prefix_match(range, lr)
2616 || prefix_match(lr, range));
2617 if (match)
2618 return group;
2619 }
2620 }
2621
2622 return NULL;
20eb8864 2623}
2624
f14e6fdb
DS
2625DEFUN (bgp_listen_range,
2626 bgp_listen_range_cmd,
9ccf14f7 2627 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2628 "BGP specific commands\n"
d7fa34c1
QY
2629 "Configure BGP dynamic neighbors listen range\n"
2630 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2631 NEIGHBOR_ADDR_STR
2632 "Member of the peer-group\n"
2633 "Peer-group name\n")
f14e6fdb 2634{
d62a17ae 2635 VTY_DECLVAR_CONTEXT(bgp, bgp);
2636 struct prefix range;
2637 struct peer_group *group, *existing_group;
2638 afi_t afi;
2639 int ret;
2640 int idx = 0;
2641
2642 argv_find(argv, argc, "A.B.C.D/M", &idx);
2643 argv_find(argv, argc, "X:X::X:X/M", &idx);
2644 char *prefix = argv[idx]->arg;
2645 argv_find(argv, argc, "WORD", &idx);
2646 char *peergroup = argv[idx]->arg;
2647
2648 /* Convert IP prefix string to struct prefix. */
2649 ret = str2prefix(prefix, &range);
2650 if (!ret) {
2651 vty_out(vty, "%% Malformed listen range\n");
2652 return CMD_WARNING_CONFIG_FAILED;
2653 }
2654
2655 afi = family2afi(range.family);
2656
2657 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2658 vty_out(vty,
2659 "%% Malformed listen range (link-local address)\n");
2660 return CMD_WARNING_CONFIG_FAILED;
2661 }
2662
2663 apply_mask(&range);
2664
2665 /* Check if same listen range is already configured. */
2666 existing_group = listen_range_exists(bgp, &range, 1);
2667 if (existing_group) {
2668 if (strcmp(existing_group->name, peergroup) == 0)
2669 return CMD_SUCCESS;
2670 else {
2671 vty_out(vty,
2672 "%% Same listen range is attached to peer-group %s\n",
2673 existing_group->name);
2674 return CMD_WARNING_CONFIG_FAILED;
2675 }
2676 }
2677
2678 /* Check if an overlapping listen range exists. */
2679 if (listen_range_exists(bgp, &range, 0)) {
2680 vty_out(vty,
2681 "%% Listen range overlaps with existing listen range\n");
2682 return CMD_WARNING_CONFIG_FAILED;
2683 }
2684
2685 group = peer_group_lookup(bgp, peergroup);
2686 if (!group) {
2687 vty_out(vty, "%% Configure the peer-group first\n");
2688 return CMD_WARNING_CONFIG_FAILED;
2689 }
2690
2691 ret = peer_group_listen_range_add(group, &range);
2692 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2693}
2694
2695DEFUN (no_bgp_listen_range,
2696 no_bgp_listen_range_cmd,
d7fa34c1
QY
2697 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2698 NO_STR
f14e6fdb 2699 "BGP specific commands\n"
d7fa34c1
QY
2700 "Unconfigure BGP dynamic neighbors listen range\n"
2701 "Unconfigure BGP dynamic neighbors listen range\n"
2702 NEIGHBOR_ADDR_STR
2703 "Member of the peer-group\n"
2704 "Peer-group name\n")
f14e6fdb 2705{
d62a17ae 2706 VTY_DECLVAR_CONTEXT(bgp, bgp);
2707 struct prefix range;
2708 struct peer_group *group;
2709 afi_t afi;
2710 int ret;
2711 int idx = 0;
2712
2713 argv_find(argv, argc, "A.B.C.D/M", &idx);
2714 argv_find(argv, argc, "X:X::X:X/M", &idx);
2715 char *prefix = argv[idx]->arg;
2716 argv_find(argv, argc, "WORD", &idx);
2717 char *peergroup = argv[idx]->arg;
2718
2719 /* Convert IP prefix string to struct prefix. */
2720 ret = str2prefix(prefix, &range);
2721 if (!ret) {
2722 vty_out(vty, "%% Malformed listen range\n");
2723 return CMD_WARNING_CONFIG_FAILED;
2724 }
2725
2726 afi = family2afi(range.family);
2727
2728 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2729 vty_out(vty,
2730 "%% Malformed listen range (link-local address)\n");
2731 return CMD_WARNING_CONFIG_FAILED;
2732 }
2733
2734 apply_mask(&range);
2735
2736 group = peer_group_lookup(bgp, peergroup);
2737 if (!group) {
2738 vty_out(vty, "%% Peer-group does not exist\n");
2739 return CMD_WARNING_CONFIG_FAILED;
2740 }
2741
2742 ret = peer_group_listen_range_del(group, &range);
2743 return bgp_vty_return(vty, ret);
2744}
2745
2b791107 2746void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2747{
2748 struct peer_group *group;
2749 struct listnode *node, *nnode, *rnode, *nrnode;
2750 struct prefix *range;
2751 afi_t afi;
2752 char buf[PREFIX2STR_BUFFER];
2753
2754 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2755 vty_out(vty, " bgp listen limit %d\n",
2756 bgp->dynamic_neighbors_limit);
2757
2758 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2759 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2760 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2761 nrnode, range)) {
2762 prefix2str(range, buf, sizeof(buf));
2763 vty_out(vty,
2764 " bgp listen range %s peer-group %s\n",
2765 buf, group->name);
2766 }
2767 }
2768 }
f14e6fdb
DS
2769}
2770
2771
907f92c8
DS
2772DEFUN (bgp_disable_connected_route_check,
2773 bgp_disable_connected_route_check_cmd,
2774 "bgp disable-ebgp-connected-route-check",
2775 "BGP specific commands\n"
2776 "Disable checking if nexthop is connected on ebgp sessions\n")
2777{
d62a17ae 2778 VTY_DECLVAR_CONTEXT(bgp, bgp);
2779 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2780 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2781
d62a17ae 2782 return CMD_SUCCESS;
907f92c8
DS
2783}
2784
2785DEFUN (no_bgp_disable_connected_route_check,
2786 no_bgp_disable_connected_route_check_cmd,
2787 "no bgp disable-ebgp-connected-route-check",
2788 NO_STR
2789 "BGP specific commands\n"
2790 "Disable checking if nexthop is connected on ebgp sessions\n")
2791{
d62a17ae 2792 VTY_DECLVAR_CONTEXT(bgp, bgp);
2793 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2794 bgp_clear_star_soft_in(vty, bgp->name);
2795
2796 return CMD_SUCCESS;
2797}
2798
2799
2800static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2801 const char *as_str, afi_t afi, safi_t safi)
2802{
2803 VTY_DECLVAR_CONTEXT(bgp, bgp);
2804 int ret;
2805 as_t as;
2806 int as_type = AS_SPECIFIED;
2807 union sockunion su;
2808
2809 if (as_str[0] == 'i') {
2810 as = 0;
2811 as_type = AS_INTERNAL;
2812 } else if (as_str[0] == 'e') {
2813 as = 0;
2814 as_type = AS_EXTERNAL;
2815 } else {
2816 /* Get AS number. */
2817 as = strtoul(as_str, NULL, 10);
2818 }
2819
2820 /* If peer is peer group, call proper function. */
2821 ret = str2sockunion(peer_str, &su);
2822 if (ret < 0) {
2823 /* Check for peer by interface */
2824 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2825 safi);
2826 if (ret < 0) {
2827 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2828 if (ret < 0) {
2829 vty_out(vty,
d762bcc3
DS
2830 "%% Create the peer-group or interface first or specify \"interface\" keyword\n");
2831 vty_out(vty, "%% if using an unnumbered interface neighbor\n");
d62a17ae 2832 return CMD_WARNING_CONFIG_FAILED;
2833 }
2834 return CMD_SUCCESS;
2835 }
2836 } else {
2837 if (peer_address_self_check(bgp, &su)) {
2838 vty_out(vty,
2839 "%% Can not configure the local system as neighbor\n");
2840 return CMD_WARNING_CONFIG_FAILED;
2841 }
2842 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2843 }
2844
2845 /* This peer belongs to peer group. */
2846 switch (ret) {
2847 case BGP_ERR_PEER_GROUP_MEMBER:
2848 vty_out(vty,
2849 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2850 as);
2851 return CMD_WARNING_CONFIG_FAILED;
2852 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2853 vty_out(vty,
2854 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2855 as, as_str);
2856 return CMD_WARNING_CONFIG_FAILED;
2857 }
2858 return bgp_vty_return(vty, ret);
718e3744 2859}
2860
f26845f9
QY
2861DEFUN (bgp_default_shutdown,
2862 bgp_default_shutdown_cmd,
2863 "[no] bgp default shutdown",
2864 NO_STR
2865 BGP_STR
2866 "Configure BGP defaults\n"
b012cbe2 2867 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2868{
2869 VTY_DECLVAR_CONTEXT(bgp, bgp);
2870 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2871 return CMD_SUCCESS;
2872}
2873
718e3744 2874DEFUN (neighbor_remote_as,
2875 neighbor_remote_as_cmd,
3a2d747c 2876 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2877 NEIGHBOR_STR
2878 NEIGHBOR_ADDR_STR2
2879 "Specify a BGP neighbor\n"
d7fa34c1 2880 AS_STR
3a2d747c
QY
2881 "Internal BGP peer\n"
2882 "External BGP peer\n")
718e3744 2883{
d62a17ae 2884 int idx_peer = 1;
2885 int idx_remote_as = 3;
2886 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2887 argv[idx_remote_as]->arg, AFI_IP,
2888 SAFI_UNICAST);
2889}
2890
2891static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2892 afi_t afi, safi_t safi, int v6only,
2893 const char *peer_group_name,
2894 const char *as_str)
2895{
2896 VTY_DECLVAR_CONTEXT(bgp, bgp);
2897 as_t as = 0;
2898 int as_type = AS_UNSPECIFIED;
2899 struct peer *peer;
2900 struct peer_group *group;
2901 int ret = 0;
2902 union sockunion su;
2903
2904 group = peer_group_lookup(bgp, conf_if);
2905
2906 if (group) {
2907 vty_out(vty, "%% Name conflict with peer-group \n");
2908 return CMD_WARNING_CONFIG_FAILED;
2909 }
2910
2911 if (as_str) {
2912 if (as_str[0] == 'i') {
2913 as_type = AS_INTERNAL;
2914 } else if (as_str[0] == 'e') {
2915 as_type = AS_EXTERNAL;
2916 } else {
2917 /* Get AS number. */
2918 as = strtoul(as_str, NULL, 10);
2919 as_type = AS_SPECIFIED;
2920 }
2921 }
2922
2923 peer = peer_lookup_by_conf_if(bgp, conf_if);
2924 if (peer) {
2925 if (as_str)
cc4d4ce8 2926 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 2927 afi, safi);
2928 } else {
2929 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2930 && afi == AFI_IP && safi == SAFI_UNICAST)
2931 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2932 as_type, 0, 0, NULL);
2933 else
2934 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2935 as_type, afi, safi, NULL);
2936
2937 if (!peer) {
2938 vty_out(vty, "%% BGP failed to create peer\n");
2939 return CMD_WARNING_CONFIG_FAILED;
2940 }
2941
2942 if (v6only)
527de3dc 2943 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2944
2945 /* Request zebra to initiate IPv6 RAs on this interface. We do
2946 * this
2947 * any unnumbered peer in order to not worry about run-time
2948 * transitions
2949 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2950 * address
2951 * gets deleted later etc.)
2952 */
2953 if (peer->ifp)
2954 bgp_zebra_initiate_radv(bgp, peer);
2955 }
2956
2957 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2958 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2959 if (v6only)
527de3dc 2960 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2961 else
527de3dc 2962 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2963
2964 /* v6only flag changed. Reset bgp seesion */
2965 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2966 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2967 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2968 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2969 } else
2970 bgp_session_reset(peer);
2971 }
2972
9fb964de
PM
2973 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2974 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2975 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2976 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2977 }
d62a17ae 2978
2979 if (peer_group_name) {
2980 group = peer_group_lookup(bgp, peer_group_name);
2981 if (!group) {
2982 vty_out(vty, "%% Configure the peer-group first\n");
2983 return CMD_WARNING_CONFIG_FAILED;
2984 }
2985
2986 ret = peer_group_bind(bgp, &su, peer, group, &as);
2987 }
2988
2989 return bgp_vty_return(vty, ret);
a80beece
DS
2990}
2991
4c48cf63
DW
2992DEFUN (neighbor_interface_config,
2993 neighbor_interface_config_cmd,
31500417 2994 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2995 NEIGHBOR_STR
2996 "Interface name or neighbor tag\n"
31500417
DW
2997 "Enable BGP on interface\n"
2998 "Member of the peer-group\n"
16cedbb0 2999 "Peer-group name\n")
4c48cf63 3000{
d62a17ae 3001 int idx_word = 1;
3002 int idx_peer_group_word = 4;
31500417 3003
d62a17ae 3004 if (argc > idx_peer_group_word)
3005 return peer_conf_interface_get(
3006 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3007 argv[idx_peer_group_word]->arg, NULL);
3008 else
3009 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3010 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
3011}
3012
4c48cf63
DW
3013DEFUN (neighbor_interface_config_v6only,
3014 neighbor_interface_config_v6only_cmd,
31500417 3015 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
3016 NEIGHBOR_STR
3017 "Interface name or neighbor tag\n"
3018 "Enable BGP on interface\n"
31500417
DW
3019 "Enable BGP with v6 link-local only\n"
3020 "Member of the peer-group\n"
16cedbb0 3021 "Peer-group name\n")
4c48cf63 3022{
d62a17ae 3023 int idx_word = 1;
3024 int idx_peer_group_word = 5;
31500417 3025
d62a17ae 3026 if (argc > idx_peer_group_word)
3027 return peer_conf_interface_get(
3028 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3029 argv[idx_peer_group_word]->arg, NULL);
31500417 3030
d62a17ae 3031 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3032 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
3033}
3034
a80beece 3035
b3a39dc5
DD
3036DEFUN (neighbor_interface_config_remote_as,
3037 neighbor_interface_config_remote_as_cmd,
3a2d747c 3038 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3039 NEIGHBOR_STR
3040 "Interface name or neighbor tag\n"
3041 "Enable BGP on interface\n"
3a2d747c 3042 "Specify a BGP neighbor\n"
d7fa34c1 3043 AS_STR
3a2d747c
QY
3044 "Internal BGP peer\n"
3045 "External BGP peer\n")
b3a39dc5 3046{
d62a17ae 3047 int idx_word = 1;
3048 int idx_remote_as = 4;
3049 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3050 SAFI_UNICAST, 0, NULL,
3051 argv[idx_remote_as]->arg);
b3a39dc5
DD
3052}
3053
3054DEFUN (neighbor_interface_v6only_config_remote_as,
3055 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 3056 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3057 NEIGHBOR_STR
3058 "Interface name or neighbor tag\n"
3a2d747c 3059 "Enable BGP with v6 link-local only\n"
b3a39dc5 3060 "Enable BGP on interface\n"
3a2d747c 3061 "Specify a BGP neighbor\n"
d7fa34c1 3062 AS_STR
3a2d747c
QY
3063 "Internal BGP peer\n"
3064 "External BGP peer\n")
b3a39dc5 3065{
d62a17ae 3066 int idx_word = 1;
3067 int idx_remote_as = 5;
3068 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3069 SAFI_UNICAST, 1, NULL,
3070 argv[idx_remote_as]->arg);
b3a39dc5
DD
3071}
3072
718e3744 3073DEFUN (neighbor_peer_group,
3074 neighbor_peer_group_cmd,
3075 "neighbor WORD peer-group",
3076 NEIGHBOR_STR
a80beece 3077 "Interface name or neighbor tag\n"
718e3744 3078 "Configure peer-group\n")
3079{
d62a17ae 3080 VTY_DECLVAR_CONTEXT(bgp, bgp);
3081 int idx_word = 1;
3082 struct peer *peer;
3083 struct peer_group *group;
718e3744 3084
d62a17ae 3085 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3086 if (peer) {
3087 vty_out(vty, "%% Name conflict with interface: \n");
3088 return CMD_WARNING_CONFIG_FAILED;
3089 }
718e3744 3090
d62a17ae 3091 group = peer_group_get(bgp, argv[idx_word]->arg);
3092 if (!group) {
3093 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3094 return CMD_WARNING_CONFIG_FAILED;
3095 }
718e3744 3096
d62a17ae 3097 return CMD_SUCCESS;
718e3744 3098}
3099
3100DEFUN (no_neighbor,
3101 no_neighbor_cmd,
dab8cd00 3102 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3103 NO_STR
3104 NEIGHBOR_STR
3a2d747c
QY
3105 NEIGHBOR_ADDR_STR2
3106 "Specify a BGP neighbor\n"
3107 AS_STR
3108 "Internal BGP peer\n"
3109 "External BGP peer\n")
718e3744 3110{
d62a17ae 3111 VTY_DECLVAR_CONTEXT(bgp, bgp);
3112 int idx_peer = 2;
3113 int ret;
3114 union sockunion su;
3115 struct peer_group *group;
3116 struct peer *peer;
3117 struct peer *other;
3118
3119 ret = str2sockunion(argv[idx_peer]->arg, &su);
3120 if (ret < 0) {
3121 /* look up for neighbor by interface name config. */
3122 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3123 if (peer) {
3124 /* Request zebra to terminate IPv6 RAs on this
3125 * interface. */
3126 if (peer->ifp)
3127 bgp_zebra_terminate_radv(peer->bgp, peer);
3128 peer_delete(peer);
3129 return CMD_SUCCESS;
3130 }
f14e6fdb 3131
d62a17ae 3132 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3133 if (group)
3134 peer_group_delete(group);
3135 else {
3136 vty_out(vty, "%% Create the peer-group first\n");
3137 return CMD_WARNING_CONFIG_FAILED;
3138 }
3139 } else {
3140 peer = peer_lookup(bgp, &su);
3141 if (peer) {
3142 if (peer_dynamic_neighbor(peer)) {
3143 vty_out(vty,
3144 "%% Operation not allowed on a dynamic neighbor\n");
3145 return CMD_WARNING_CONFIG_FAILED;
3146 }
3147
3148 other = peer->doppelganger;
3149 peer_delete(peer);
3150 if (other && other->status != Deleted)
3151 peer_delete(other);
3152 }
1ff9a340 3153 }
718e3744 3154
d62a17ae 3155 return CMD_SUCCESS;
718e3744 3156}
3157
a80beece
DS
3158DEFUN (no_neighbor_interface_config,
3159 no_neighbor_interface_config_cmd,
31500417 3160 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3161 NO_STR
3162 NEIGHBOR_STR
3163 "Interface name\n"
31500417
DW
3164 "Configure BGP on interface\n"
3165 "Enable BGP with v6 link-local only\n"
3166 "Member of the peer-group\n"
16cedbb0 3167 "Peer-group name\n"
3a2d747c
QY
3168 "Specify a BGP neighbor\n"
3169 AS_STR
3170 "Internal BGP peer\n"
3171 "External BGP peer\n")
a80beece 3172{
d62a17ae 3173 VTY_DECLVAR_CONTEXT(bgp, bgp);
3174 int idx_word = 2;
3175 struct peer *peer;
3176
3177 /* look up for neighbor by interface name config. */
3178 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3179 if (peer) {
3180 /* Request zebra to terminate IPv6 RAs on this interface. */
3181 if (peer->ifp)
3182 bgp_zebra_terminate_radv(peer->bgp, peer);
3183 peer_delete(peer);
3184 } else {
3185 vty_out(vty, "%% Create the bgp interface first\n");
3186 return CMD_WARNING_CONFIG_FAILED;
3187 }
3188 return CMD_SUCCESS;
a80beece
DS
3189}
3190
718e3744 3191DEFUN (no_neighbor_peer_group,
3192 no_neighbor_peer_group_cmd,
3193 "no neighbor WORD peer-group",
3194 NO_STR
3195 NEIGHBOR_STR
3196 "Neighbor tag\n"
3197 "Configure peer-group\n")
3198{
d62a17ae 3199 VTY_DECLVAR_CONTEXT(bgp, bgp);
3200 int idx_word = 2;
3201 struct peer_group *group;
718e3744 3202
d62a17ae 3203 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3204 if (group)
3205 peer_group_delete(group);
3206 else {
3207 vty_out(vty, "%% Create the peer-group first\n");
3208 return CMD_WARNING_CONFIG_FAILED;
3209 }
3210 return CMD_SUCCESS;
718e3744 3211}
3212
a80beece
DS
3213DEFUN (no_neighbor_interface_peer_group_remote_as,
3214 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3215 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3216 NO_STR
3217 NEIGHBOR_STR
a80beece 3218 "Interface name or neighbor tag\n"
718e3744 3219 "Specify a BGP neighbor\n"
3a2d747c
QY
3220 AS_STR
3221 "Internal BGP peer\n"
3222 "External BGP peer\n")
718e3744 3223{
d62a17ae 3224 VTY_DECLVAR_CONTEXT(bgp, bgp);
3225 int idx_word = 2;
3226 struct peer_group *group;
3227 struct peer *peer;
3228
3229 /* look up for neighbor by interface name config. */
3230 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3231 if (peer) {
3232 peer_as_change(peer, 0, AS_SPECIFIED);
3233 return CMD_SUCCESS;
3234 }
3235
3236 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3237 if (group)
3238 peer_group_remote_as_delete(group);
3239 else {
3240 vty_out(vty, "%% Create the peer-group or interface first\n");
3241 return CMD_WARNING_CONFIG_FAILED;
3242 }
3243 return CMD_SUCCESS;
718e3744 3244}
6b0655a2 3245
718e3744 3246DEFUN (neighbor_local_as,
3247 neighbor_local_as_cmd,
9ccf14f7 3248 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3249 NEIGHBOR_STR
3250 NEIGHBOR_ADDR_STR2
3251 "Specify a local-as number\n"
3252 "AS number used as local AS\n")
3253{
d62a17ae 3254 int idx_peer = 1;
3255 int idx_number = 3;
3256 struct peer *peer;
3257 int ret;
3258 as_t as;
718e3744 3259
d62a17ae 3260 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3261 if (!peer)
3262 return CMD_WARNING_CONFIG_FAILED;
718e3744 3263
d62a17ae 3264 as = strtoul(argv[idx_number]->arg, NULL, 10);
3265 ret = peer_local_as_set(peer, as, 0, 0);
3266 return bgp_vty_return(vty, ret);
718e3744 3267}
3268
3269DEFUN (neighbor_local_as_no_prepend,
3270 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3271 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3272 NEIGHBOR_STR
3273 NEIGHBOR_ADDR_STR2
3274 "Specify a local-as number\n"
3275 "AS number used as local AS\n"
3276 "Do not prepend local-as to updates from ebgp peers\n")
3277{
d62a17ae 3278 int idx_peer = 1;
3279 int idx_number = 3;
3280 struct peer *peer;
3281 int ret;
3282 as_t as;
718e3744 3283
d62a17ae 3284 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3285 if (!peer)
3286 return CMD_WARNING_CONFIG_FAILED;
718e3744 3287
d62a17ae 3288 as = strtoul(argv[idx_number]->arg, NULL, 10);
3289 ret = peer_local_as_set(peer, as, 1, 0);
3290 return bgp_vty_return(vty, ret);
718e3744 3291}
3292
9d3f9705
AC
3293DEFUN (neighbor_local_as_no_prepend_replace_as,
3294 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3295 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3296 NEIGHBOR_STR
3297 NEIGHBOR_ADDR_STR2
3298 "Specify a local-as number\n"
3299 "AS number used as local AS\n"
3300 "Do not prepend local-as to updates from ebgp peers\n"
3301 "Do not prepend local-as to updates from ibgp peers\n")
3302{
d62a17ae 3303 int idx_peer = 1;
3304 int idx_number = 3;
3305 struct peer *peer;
3306 int ret;
3307 as_t as;
9d3f9705 3308
d62a17ae 3309 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3310 if (!peer)
3311 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3312
d62a17ae 3313 as = strtoul(argv[idx_number]->arg, NULL, 10);
3314 ret = peer_local_as_set(peer, as, 1, 1);
3315 return bgp_vty_return(vty, ret);
9d3f9705
AC
3316}
3317
718e3744 3318DEFUN (no_neighbor_local_as,
3319 no_neighbor_local_as_cmd,
a636c635 3320 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3321 NO_STR
3322 NEIGHBOR_STR
3323 NEIGHBOR_ADDR_STR2
a636c635
DW
3324 "Specify a local-as number\n"
3325 "AS number used as local AS\n"
3326 "Do not prepend local-as to updates from ebgp peers\n"
3327 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3328{
d62a17ae 3329 int idx_peer = 2;
3330 struct peer *peer;
3331 int ret;
718e3744 3332
d62a17ae 3333 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3334 if (!peer)
3335 return CMD_WARNING_CONFIG_FAILED;
718e3744 3336
d62a17ae 3337 ret = peer_local_as_unset(peer);
3338 return bgp_vty_return(vty, ret);
718e3744 3339}
3340
718e3744 3341
3f9c7369
DS
3342DEFUN (neighbor_solo,
3343 neighbor_solo_cmd,
9ccf14f7 3344 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3345 NEIGHBOR_STR
3346 NEIGHBOR_ADDR_STR2
3347 "Solo peer - part of its own update group\n")
3348{
d62a17ae 3349 int idx_peer = 1;
3350 struct peer *peer;
3351 int ret;
3f9c7369 3352
d62a17ae 3353 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3354 if (!peer)
3355 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3356
d62a17ae 3357 ret = update_group_adjust_soloness(peer, 1);
3358 return bgp_vty_return(vty, ret);
3f9c7369
DS
3359}
3360
3361DEFUN (no_neighbor_solo,
3362 no_neighbor_solo_cmd,
9ccf14f7 3363 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3364 NO_STR
3365 NEIGHBOR_STR
3366 NEIGHBOR_ADDR_STR2
3367 "Solo peer - part of its own update group\n")
3368{
d62a17ae 3369 int idx_peer = 2;
3370 struct peer *peer;
3371 int ret;
3f9c7369 3372
d62a17ae 3373 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3374 if (!peer)
3375 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3376
d62a17ae 3377 ret = update_group_adjust_soloness(peer, 0);
3378 return bgp_vty_return(vty, ret);
3f9c7369
DS
3379}
3380
0df7c91f
PJ
3381DEFUN (neighbor_password,
3382 neighbor_password_cmd,
9ccf14f7 3383 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3384 NEIGHBOR_STR
3385 NEIGHBOR_ADDR_STR2
3386 "Set a password\n"
3387 "The password\n")
3388{
d62a17ae 3389 int idx_peer = 1;
3390 int idx_line = 3;
3391 struct peer *peer;
3392 int ret;
0df7c91f 3393
d62a17ae 3394 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3395 if (!peer)
3396 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3397
d62a17ae 3398 ret = peer_password_set(peer, argv[idx_line]->arg);
3399 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3400}
3401
3402DEFUN (no_neighbor_password,
3403 no_neighbor_password_cmd,
a636c635 3404 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3405 NO_STR
3406 NEIGHBOR_STR
3407 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3408 "Set a password\n"
3409 "The password\n")
0df7c91f 3410{
d62a17ae 3411 int idx_peer = 2;
3412 struct peer *peer;
3413 int ret;
0df7c91f 3414
d62a17ae 3415 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3416 if (!peer)
3417 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3418
d62a17ae 3419 ret = peer_password_unset(peer);
3420 return bgp_vty_return(vty, ret);
0df7c91f 3421}
6b0655a2 3422
718e3744 3423DEFUN (neighbor_activate,
3424 neighbor_activate_cmd,
9ccf14f7 3425 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3426 NEIGHBOR_STR
3427 NEIGHBOR_ADDR_STR2
3428 "Enable the Address Family for this Neighbor\n")
3429{
d62a17ae 3430 int idx_peer = 1;
3431 int ret;
3432 struct peer *peer;
718e3744 3433
d62a17ae 3434 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3435 if (!peer)
3436 return CMD_WARNING_CONFIG_FAILED;
718e3744 3437
d62a17ae 3438 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3439 return bgp_vty_return(vty, ret);
718e3744 3440}
3441
d62a17ae 3442ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3443 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3444 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3445 "Enable the Address Family for this Neighbor\n")
596c17ba 3446
718e3744 3447DEFUN (no_neighbor_activate,
3448 no_neighbor_activate_cmd,
9ccf14f7 3449 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3450 NO_STR
3451 NEIGHBOR_STR
3452 NEIGHBOR_ADDR_STR2
3453 "Enable the Address Family for this Neighbor\n")
3454{
d62a17ae 3455 int idx_peer = 2;
3456 int ret;
3457 struct peer *peer;
718e3744 3458
d62a17ae 3459 /* Lookup peer. */
3460 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3461 if (!peer)
3462 return CMD_WARNING_CONFIG_FAILED;
718e3744 3463
d62a17ae 3464 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3465 return bgp_vty_return(vty, ret);
718e3744 3466}
6b0655a2 3467
d62a17ae 3468ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3469 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3470 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3471 "Enable the Address Family for this Neighbor\n")
596c17ba 3472
718e3744 3473DEFUN (neighbor_set_peer_group,
3474 neighbor_set_peer_group_cmd,
9ccf14f7 3475 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3476 NEIGHBOR_STR
a80beece 3477 NEIGHBOR_ADDR_STR2
718e3744 3478 "Member of the peer-group\n"
16cedbb0 3479 "Peer-group name\n")
718e3744 3480{
d62a17ae 3481 VTY_DECLVAR_CONTEXT(bgp, bgp);
3482 int idx_peer = 1;
3483 int idx_word = 3;
3484 int ret;
3485 as_t as;
3486 union sockunion su;
3487 struct peer *peer;
3488 struct peer_group *group;
3489
d62a17ae 3490 ret = str2sockunion(argv[idx_peer]->arg, &su);
3491 if (ret < 0) {
3492 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3493 if (!peer) {
3494 vty_out(vty, "%% Malformed address or name: %s\n",
3495 argv[idx_peer]->arg);
3496 return CMD_WARNING_CONFIG_FAILED;
3497 }
3498 } else {
3499 if (peer_address_self_check(bgp, &su)) {
3500 vty_out(vty,
3501 "%% Can not configure the local system as neighbor\n");
3502 return CMD_WARNING_CONFIG_FAILED;
3503 }
3504
3505 /* Disallow for dynamic neighbor. */
3506 peer = peer_lookup(bgp, &su);
3507 if (peer && peer_dynamic_neighbor(peer)) {
3508 vty_out(vty,
3509 "%% Operation not allowed on a dynamic neighbor\n");
3510 return CMD_WARNING_CONFIG_FAILED;
3511 }
3512 }
3513
3514 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3515 if (!group) {
3516 vty_out(vty, "%% Configure the peer-group first\n");
3517 return CMD_WARNING_CONFIG_FAILED;
3518 }
3519
3520 ret = peer_group_bind(bgp, &su, peer, group, &as);
3521
3522 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3523 vty_out(vty,
3524 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3525 as);
3526 return CMD_WARNING_CONFIG_FAILED;
3527 }
3528
3529 return bgp_vty_return(vty, ret);
3530}
3531
3532ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3533 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3534 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3535 "Member of the peer-group\n"
3536 "Peer-group name\n")
596c17ba 3537
718e3744 3538DEFUN (no_neighbor_set_peer_group,
3539 no_neighbor_set_peer_group_cmd,
9ccf14f7 3540 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3541 NO_STR
3542 NEIGHBOR_STR
a80beece 3543 NEIGHBOR_ADDR_STR2
718e3744 3544 "Member of the peer-group\n"
16cedbb0 3545 "Peer-group name\n")
718e3744 3546{
d62a17ae 3547 VTY_DECLVAR_CONTEXT(bgp, bgp);
3548 int idx_peer = 2;
3549 int idx_word = 4;
3550 int ret;
3551 struct peer *peer;
3552 struct peer_group *group;
3553
3554 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3555 if (!peer)
3556 return CMD_WARNING_CONFIG_FAILED;
3557
3558 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3559 if (!group) {
3560 vty_out(vty, "%% Configure the peer-group first\n");
3561 return CMD_WARNING_CONFIG_FAILED;
3562 }
718e3744 3563
827ed707 3564 ret = peer_delete(peer);
718e3744 3565
d62a17ae 3566 return bgp_vty_return(vty, ret);
718e3744 3567}
6b0655a2 3568
d62a17ae 3569ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3570 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3571 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3572 "Member of the peer-group\n"
3573 "Peer-group name\n")
596c17ba 3574
d62a17ae 3575static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3576 uint32_t flag, int set)
718e3744 3577{
d62a17ae 3578 int ret;
3579 struct peer *peer;
718e3744 3580
d62a17ae 3581 peer = peer_and_group_lookup_vty(vty, ip_str);
3582 if (!peer)
3583 return CMD_WARNING_CONFIG_FAILED;
718e3744 3584
7ebe625c
QY
3585 /*
3586 * If 'neighbor <interface>', then this is for directly connected peers,
3587 * we should not accept disable-connected-check.
3588 */
3589 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3590 vty_out(vty,
3591 "%s is directly connected peer, cannot accept disable-"
3592 "connected-check\n",
3593 ip_str);
3594 return CMD_WARNING_CONFIG_FAILED;
3595 }
3596
d62a17ae 3597 if (!set && flag == PEER_FLAG_SHUTDOWN)
3598 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3599
d62a17ae 3600 if (set)
3601 ret = peer_flag_set(peer, flag);
3602 else
3603 ret = peer_flag_unset(peer, flag);
718e3744 3604
d62a17ae 3605 return bgp_vty_return(vty, ret);
718e3744 3606}
3607
47cbc09b 3608static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3609{
d62a17ae 3610 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3611}
3612
d62a17ae 3613static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3614 uint32_t flag)
718e3744 3615{
d62a17ae 3616 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3617}
3618
3619/* neighbor passive. */
3620DEFUN (neighbor_passive,
3621 neighbor_passive_cmd,
9ccf14f7 3622 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3623 NEIGHBOR_STR
3624 NEIGHBOR_ADDR_STR2
3625 "Don't send open messages to this neighbor\n")
3626{
d62a17ae 3627 int idx_peer = 1;
3628 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3629}
3630
3631DEFUN (no_neighbor_passive,
3632 no_neighbor_passive_cmd,
9ccf14f7 3633 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3634 NO_STR
3635 NEIGHBOR_STR
3636 NEIGHBOR_ADDR_STR2
3637 "Don't send open messages to this neighbor\n")
3638{
d62a17ae 3639 int idx_peer = 2;
3640 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3641}
6b0655a2 3642
718e3744 3643/* neighbor shutdown. */
73d70fa6
DL
3644DEFUN (neighbor_shutdown_msg,
3645 neighbor_shutdown_msg_cmd,
3646 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3647 NEIGHBOR_STR
3648 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3649 "Administratively shut down this neighbor\n"
3650 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3651 "Shutdown message\n")
718e3744 3652{
d62a17ae 3653 int idx_peer = 1;
73d70fa6 3654
d62a17ae 3655 if (argc >= 5) {
3656 struct peer *peer =
3657 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3658 char *message;
73d70fa6 3659
d62a17ae 3660 if (!peer)
3661 return CMD_WARNING_CONFIG_FAILED;
3662 message = argv_concat(argv, argc, 4);
3663 peer_tx_shutdown_message_set(peer, message);
3664 XFREE(MTYPE_TMP, message);
3665 }
73d70fa6 3666
d62a17ae 3667 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3668}
3669
d62a17ae 3670ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3671 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3672 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3673 "Administratively shut down this neighbor\n")
73d70fa6
DL
3674
3675DEFUN (no_neighbor_shutdown_msg,
3676 no_neighbor_shutdown_msg_cmd,
3677 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3678 NO_STR
3679 NEIGHBOR_STR
3680 NEIGHBOR_ADDR_STR2
3681 "Administratively shut down this neighbor\n"
3682 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3683 "Shutdown message\n")
718e3744 3684{
d62a17ae 3685 int idx_peer = 2;
73d70fa6 3686
d62a17ae 3687 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3688 PEER_FLAG_SHUTDOWN);
718e3744 3689}
6b0655a2 3690
d62a17ae 3691ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3692 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3693 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3694 "Administratively shut down this neighbor\n")
73d70fa6 3695
718e3744 3696/* neighbor capability dynamic. */
3697DEFUN (neighbor_capability_dynamic,
3698 neighbor_capability_dynamic_cmd,
9ccf14f7 3699 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3700 NEIGHBOR_STR
3701 NEIGHBOR_ADDR_STR2
3702 "Advertise capability to the peer\n"
3703 "Advertise dynamic capability to this neighbor\n")
3704{
d62a17ae 3705 int idx_peer = 1;
3706 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3707 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3708}
3709
3710DEFUN (no_neighbor_capability_dynamic,
3711 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3712 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3713 NO_STR
3714 NEIGHBOR_STR
3715 NEIGHBOR_ADDR_STR2
3716 "Advertise capability to the peer\n"
3717 "Advertise dynamic capability to this neighbor\n")
3718{
d62a17ae 3719 int idx_peer = 2;
3720 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3721 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3722}
6b0655a2 3723
718e3744 3724/* neighbor dont-capability-negotiate */
3725DEFUN (neighbor_dont_capability_negotiate,
3726 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3727 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3728 NEIGHBOR_STR
3729 NEIGHBOR_ADDR_STR2
3730 "Do not perform capability negotiation\n")
3731{
d62a17ae 3732 int idx_peer = 1;
3733 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3734 PEER_FLAG_DONT_CAPABILITY);
718e3744 3735}
3736
3737DEFUN (no_neighbor_dont_capability_negotiate,
3738 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3739 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3740 NO_STR
3741 NEIGHBOR_STR
3742 NEIGHBOR_ADDR_STR2
3743 "Do not perform capability negotiation\n")
3744{
d62a17ae 3745 int idx_peer = 2;
3746 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3747 PEER_FLAG_DONT_CAPABILITY);
718e3744 3748}
6b0655a2 3749
8a92a8a0
DS
3750/* neighbor capability extended next hop encoding */
3751DEFUN (neighbor_capability_enhe,
3752 neighbor_capability_enhe_cmd,
9ccf14f7 3753 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3754 NEIGHBOR_STR
3755 NEIGHBOR_ADDR_STR2
3756 "Advertise capability to the peer\n"
3757 "Advertise extended next-hop capability to the peer\n")
3758{
d62a17ae 3759 int idx_peer = 1;
3760 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3761 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3762}
3763
3764DEFUN (no_neighbor_capability_enhe,
3765 no_neighbor_capability_enhe_cmd,
9ccf14f7 3766 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3767 NO_STR
3768 NEIGHBOR_STR
3769 NEIGHBOR_ADDR_STR2
3770 "Advertise capability to the peer\n"
3771 "Advertise extended next-hop capability to the peer\n")
3772{
d62a17ae 3773 int idx_peer = 2;
3774 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3775 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3776}
3777
d62a17ae 3778static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3779 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3780 int set)
718e3744 3781{
d62a17ae 3782 int ret;
3783 struct peer *peer;
718e3744 3784
d62a17ae 3785 peer = peer_and_group_lookup_vty(vty, peer_str);
3786 if (!peer)
3787 return CMD_WARNING_CONFIG_FAILED;
718e3744 3788
d62a17ae 3789 if (set)
3790 ret = peer_af_flag_set(peer, afi, safi, flag);
3791 else
3792 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3793
d62a17ae 3794 return bgp_vty_return(vty, ret);
718e3744 3795}
3796
d62a17ae 3797static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3798 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3799{
d62a17ae 3800 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3801}
3802
d62a17ae 3803static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3804 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3805{
d62a17ae 3806 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3807}
6b0655a2 3808
718e3744 3809/* neighbor capability orf prefix-list. */
3810DEFUN (neighbor_capability_orf_prefix,
3811 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3812 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3813 NEIGHBOR_STR
3814 NEIGHBOR_ADDR_STR2
3815 "Advertise capability to the peer\n"
3816 "Advertise ORF capability to the peer\n"
3817 "Advertise prefixlist ORF capability to this neighbor\n"
3818 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3819 "Capability to RECEIVE the ORF from this neighbor\n"
3820 "Capability to SEND the ORF to this neighbor\n")
3821{
d62a17ae 3822 int idx_peer = 1;
3823 int idx_send_recv = 5;
d7c0a89a 3824 uint16_t flag = 0;
d62a17ae 3825
3826 if (strmatch(argv[idx_send_recv]->text, "send"))
3827 flag = PEER_FLAG_ORF_PREFIX_SM;
3828 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3829 flag = PEER_FLAG_ORF_PREFIX_RM;
3830 else if (strmatch(argv[idx_send_recv]->text, "both"))
3831 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3832 else {
3833 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3834 return CMD_WARNING_CONFIG_FAILED;
3835 }
3836
3837 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3838 bgp_node_safi(vty), flag);
3839}
3840
3841ALIAS_HIDDEN(
3842 neighbor_capability_orf_prefix,
3843 neighbor_capability_orf_prefix_hidden_cmd,
3844 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3845 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3846 "Advertise capability to the peer\n"
3847 "Advertise ORF capability to the peer\n"
3848 "Advertise prefixlist ORF capability to this neighbor\n"
3849 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3850 "Capability to RECEIVE the ORF from this neighbor\n"
3851 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3852
718e3744 3853DEFUN (no_neighbor_capability_orf_prefix,
3854 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3855 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3856 NO_STR
3857 NEIGHBOR_STR
3858 NEIGHBOR_ADDR_STR2
3859 "Advertise capability to the peer\n"
3860 "Advertise ORF capability to the peer\n"
3861 "Advertise prefixlist ORF capability to this neighbor\n"
3862 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3863 "Capability to RECEIVE the ORF from this neighbor\n"
3864 "Capability to SEND the ORF to this neighbor\n")
3865{
d62a17ae 3866 int idx_peer = 2;
3867 int idx_send_recv = 6;
d7c0a89a 3868 uint16_t flag = 0;
d62a17ae 3869
3870 if (strmatch(argv[idx_send_recv]->text, "send"))
3871 flag = PEER_FLAG_ORF_PREFIX_SM;
3872 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3873 flag = PEER_FLAG_ORF_PREFIX_RM;
3874 else if (strmatch(argv[idx_send_recv]->text, "both"))
3875 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3876 else {
3877 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3878 return CMD_WARNING_CONFIG_FAILED;
3879 }
3880
3881 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3882 bgp_node_afi(vty), bgp_node_safi(vty),
3883 flag);
3884}
3885
3886ALIAS_HIDDEN(
3887 no_neighbor_capability_orf_prefix,
3888 no_neighbor_capability_orf_prefix_hidden_cmd,
3889 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3890 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3891 "Advertise capability to the peer\n"
3892 "Advertise ORF capability to the peer\n"
3893 "Advertise prefixlist ORF capability to this neighbor\n"
3894 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3895 "Capability to RECEIVE the ORF from this neighbor\n"
3896 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3897
718e3744 3898/* neighbor next-hop-self. */
3899DEFUN (neighbor_nexthop_self,
3900 neighbor_nexthop_self_cmd,
9ccf14f7 3901 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3902 NEIGHBOR_STR
3903 NEIGHBOR_ADDR_STR2
a538debe 3904 "Disable the next hop calculation for this neighbor\n")
718e3744 3905{
d62a17ae 3906 int idx_peer = 1;
3907 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3908 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3909}
9e7a53c1 3910
d62a17ae 3911ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3912 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3913 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3914 "Disable the next hop calculation for this neighbor\n")
596c17ba 3915
a538debe
DS
3916/* neighbor next-hop-self. */
3917DEFUN (neighbor_nexthop_self_force,
3918 neighbor_nexthop_self_force_cmd,
9ccf14f7 3919 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3920 NEIGHBOR_STR
3921 NEIGHBOR_ADDR_STR2
3922 "Disable the next hop calculation for this neighbor\n"
3923 "Set the next hop to self for reflected routes\n")
3924{
d62a17ae 3925 int idx_peer = 1;
3926 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3927 bgp_node_safi(vty),
3928 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3929}
3930
d62a17ae 3931ALIAS_HIDDEN(neighbor_nexthop_self_force,
3932 neighbor_nexthop_self_force_hidden_cmd,
3933 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3934 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3935 "Disable the next hop calculation for this neighbor\n"
3936 "Set the next hop to self for reflected routes\n")
596c17ba 3937
718e3744 3938DEFUN (no_neighbor_nexthop_self,
3939 no_neighbor_nexthop_self_cmd,
9ccf14f7 3940 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3941 NO_STR
3942 NEIGHBOR_STR
3943 NEIGHBOR_ADDR_STR2
a538debe 3944 "Disable the next hop calculation for this neighbor\n")
718e3744 3945{
d62a17ae 3946 int idx_peer = 2;
3947 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3948 bgp_node_afi(vty), bgp_node_safi(vty),
3949 PEER_FLAG_NEXTHOP_SELF);
718e3744 3950}
6b0655a2 3951
d62a17ae 3952ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3953 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3954 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3955 "Disable the next hop calculation for this neighbor\n")
596c17ba 3956
88b8ed8d 3957DEFUN (no_neighbor_nexthop_self_force,
a538debe 3958 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3959 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3960 NO_STR
3961 NEIGHBOR_STR
3962 NEIGHBOR_ADDR_STR2
3963 "Disable the next hop calculation for this neighbor\n"
3964 "Set the next hop to self for reflected routes\n")
88b8ed8d 3965{
d62a17ae 3966 int idx_peer = 2;
3967 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3968 bgp_node_afi(vty), bgp_node_safi(vty),
3969 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3970}
a538debe 3971
d62a17ae 3972ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3973 no_neighbor_nexthop_self_force_hidden_cmd,
3974 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3975 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3976 "Disable the next hop calculation for this neighbor\n"
3977 "Set the next hop to self for reflected routes\n")
596c17ba 3978
c7122e14
DS
3979/* neighbor as-override */
3980DEFUN (neighbor_as_override,
3981 neighbor_as_override_cmd,
9ccf14f7 3982 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3983 NEIGHBOR_STR
3984 NEIGHBOR_ADDR_STR2
3985 "Override ASNs in outbound updates if aspath equals remote-as\n")
3986{
d62a17ae 3987 int idx_peer = 1;
3988 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3989 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3990}
3991
d62a17ae 3992ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3993 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3994 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3995 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3996
c7122e14
DS
3997DEFUN (no_neighbor_as_override,
3998 no_neighbor_as_override_cmd,
9ccf14f7 3999 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4000 NO_STR
4001 NEIGHBOR_STR
4002 NEIGHBOR_ADDR_STR2
4003 "Override ASNs in outbound updates if aspath equals remote-as\n")
4004{
d62a17ae 4005 int idx_peer = 2;
4006 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4007 bgp_node_afi(vty), bgp_node_safi(vty),
4008 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4009}
4010
d62a17ae 4011ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4012 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4013 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4014 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4015
718e3744 4016/* neighbor remove-private-AS. */
4017DEFUN (neighbor_remove_private_as,
4018 neighbor_remove_private_as_cmd,
9ccf14f7 4019 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4020 NEIGHBOR_STR
4021 NEIGHBOR_ADDR_STR2
5000f21c 4022 "Remove private ASNs in outbound updates\n")
718e3744 4023{
d62a17ae 4024 int idx_peer = 1;
4025 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4026 bgp_node_safi(vty),
4027 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4028}
4029
d62a17ae 4030ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4031 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4032 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4033 "Remove private ASNs in outbound updates\n")
596c17ba 4034
5000f21c
DS
4035DEFUN (neighbor_remove_private_as_all,
4036 neighbor_remove_private_as_all_cmd,
9ccf14f7 4037 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4038 NEIGHBOR_STR
4039 NEIGHBOR_ADDR_STR2
4040 "Remove private ASNs in outbound updates\n"
efd7904e 4041 "Apply to all AS numbers\n")
5000f21c 4042{
d62a17ae 4043 int idx_peer = 1;
4044 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4045 bgp_node_safi(vty),
4046 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
4047}
4048
d62a17ae 4049ALIAS_HIDDEN(neighbor_remove_private_as_all,
4050 neighbor_remove_private_as_all_hidden_cmd,
4051 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4052 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4053 "Remove private ASNs in outbound updates\n"
4054 "Apply to all AS numbers")
596c17ba 4055
5000f21c
DS
4056DEFUN (neighbor_remove_private_as_replace_as,
4057 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4058 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
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")
4063{
d62a17ae 4064 int idx_peer = 1;
4065 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4066 bgp_node_safi(vty),
4067 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
4068}
4069
d62a17ae 4070ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4071 neighbor_remove_private_as_replace_as_hidden_cmd,
4072 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4073 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
5000f21c
DS
4077DEFUN (neighbor_remove_private_as_all_replace_as,
4078 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4079 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4080 NEIGHBOR_STR
4081 NEIGHBOR_ADDR_STR2
4082 "Remove private ASNs in outbound updates\n"
16cedbb0 4083 "Apply to all AS numbers\n"
5000f21c
DS
4084 "Replace private ASNs with our ASN in outbound updates\n")
4085{
d62a17ae 4086 int idx_peer = 1;
4087 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4088 bgp_node_safi(vty),
4089 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4090}
4091
d62a17ae 4092ALIAS_HIDDEN(
4093 neighbor_remove_private_as_all_replace_as,
4094 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4095 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4096 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4097 "Remove private ASNs in outbound updates\n"
4098 "Apply to all AS numbers\n"
4099 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4100
718e3744 4101DEFUN (no_neighbor_remove_private_as,
4102 no_neighbor_remove_private_as_cmd,
9ccf14f7 4103 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4104 NO_STR
4105 NEIGHBOR_STR
4106 NEIGHBOR_ADDR_STR2
5000f21c 4107 "Remove private ASNs in outbound updates\n")
718e3744 4108{
d62a17ae 4109 int idx_peer = 2;
4110 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4111 bgp_node_afi(vty), bgp_node_safi(vty),
4112 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4113}
6b0655a2 4114
d62a17ae 4115ALIAS_HIDDEN(no_neighbor_remove_private_as,
4116 no_neighbor_remove_private_as_hidden_cmd,
4117 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4118 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4119 "Remove private ASNs in outbound updates\n")
596c17ba 4120
88b8ed8d 4121DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4122 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4123 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4124 NO_STR
4125 NEIGHBOR_STR
4126 NEIGHBOR_ADDR_STR2
4127 "Remove private ASNs in outbound updates\n"
16cedbb0 4128 "Apply to all AS numbers\n")
88b8ed8d 4129{
d62a17ae 4130 int idx_peer = 2;
4131 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4132 bgp_node_afi(vty), bgp_node_safi(vty),
4133 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4134}
5000f21c 4135
d62a17ae 4136ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4137 no_neighbor_remove_private_as_all_hidden_cmd,
4138 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4139 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4140 "Remove private ASNs in outbound updates\n"
4141 "Apply to all AS numbers\n")
596c17ba 4142
88b8ed8d 4143DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4144 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4145 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4146 NO_STR
4147 NEIGHBOR_STR
4148 NEIGHBOR_ADDR_STR2
4149 "Remove private ASNs in outbound updates\n"
4150 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4151{
d62a17ae 4152 int idx_peer = 2;
4153 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4154 bgp_node_afi(vty), bgp_node_safi(vty),
4155 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4156}
5000f21c 4157
d62a17ae 4158ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4159 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4160 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4161 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4162 "Remove private ASNs in outbound updates\n"
4163 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4164
88b8ed8d 4165DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4166 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4167 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4168 NO_STR
4169 NEIGHBOR_STR
4170 NEIGHBOR_ADDR_STR2
4171 "Remove private ASNs in outbound updates\n"
16cedbb0 4172 "Apply to all AS numbers\n"
5000f21c 4173 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4174{
d62a17ae 4175 int idx_peer = 2;
4176 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4177 bgp_node_afi(vty), bgp_node_safi(vty),
4178 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4179}
5000f21c 4180
d62a17ae 4181ALIAS_HIDDEN(
4182 no_neighbor_remove_private_as_all_replace_as,
4183 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4184 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4185 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4186 "Remove private ASNs in outbound updates\n"
4187 "Apply to all AS numbers\n"
4188 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4189
5000f21c 4190
718e3744 4191/* neighbor send-community. */
4192DEFUN (neighbor_send_community,
4193 neighbor_send_community_cmd,
9ccf14f7 4194 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4195 NEIGHBOR_STR
4196 NEIGHBOR_ADDR_STR2
4197 "Send Community attribute to this neighbor\n")
4198{
d62a17ae 4199 int idx_peer = 1;
27c05d4d 4200
d62a17ae 4201 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4202 bgp_node_safi(vty),
4203 PEER_FLAG_SEND_COMMUNITY);
718e3744 4204}
4205
d62a17ae 4206ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4207 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4208 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4209 "Send Community attribute to this neighbor\n")
596c17ba 4210
718e3744 4211DEFUN (no_neighbor_send_community,
4212 no_neighbor_send_community_cmd,
9ccf14f7 4213 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4214 NO_STR
4215 NEIGHBOR_STR
4216 NEIGHBOR_ADDR_STR2
4217 "Send Community attribute to this neighbor\n")
4218{
d62a17ae 4219 int idx_peer = 2;
27c05d4d 4220
d62a17ae 4221 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4222 bgp_node_afi(vty), bgp_node_safi(vty),
4223 PEER_FLAG_SEND_COMMUNITY);
718e3744 4224}
6b0655a2 4225
d62a17ae 4226ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4227 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4228 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4229 "Send Community attribute to this neighbor\n")
596c17ba 4230
718e3744 4231/* neighbor send-community extended. */
4232DEFUN (neighbor_send_community_type,
4233 neighbor_send_community_type_cmd,
57d187bc 4234 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4235 NEIGHBOR_STR
4236 NEIGHBOR_ADDR_STR2
4237 "Send Community attribute to this neighbor\n"
4238 "Send Standard and Extended Community attributes\n"
57d187bc 4239 "Send Standard, Large and Extended Community attributes\n"
718e3744 4240 "Send Extended Community attributes\n"
57d187bc
JS
4241 "Send Standard Community attributes\n"
4242 "Send Large Community attributes\n")
718e3744 4243{
27c05d4d 4244 int idx_peer = 1;
d7c0a89a 4245 uint32_t flag = 0;
27c05d4d 4246 const char *type = argv[argc - 1]->text;
d62a17ae 4247
27c05d4d 4248 if (strmatch(type, "standard")) {
d62a17ae 4249 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4250 } else if (strmatch(type, "extended")) {
d62a17ae 4251 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4252 } else if (strmatch(type, "large")) {
d62a17ae 4253 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4254 } else if (strmatch(type, "both")) {
d62a17ae 4255 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4256 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4257 } else { /* if (strmatch(type, "all")) */
d62a17ae 4258 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4259 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4260 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4261 }
4262
27c05d4d 4263 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4264 bgp_node_safi(vty), flag);
4265}
4266
4267ALIAS_HIDDEN(
4268 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4269 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4270 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4271 "Send Community attribute to this neighbor\n"
4272 "Send Standard and Extended Community attributes\n"
4273 "Send Standard, Large and Extended Community attributes\n"
4274 "Send Extended Community attributes\n"
4275 "Send Standard Community attributes\n"
4276 "Send Large Community attributes\n")
596c17ba 4277
718e3744 4278DEFUN (no_neighbor_send_community_type,
4279 no_neighbor_send_community_type_cmd,
57d187bc 4280 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4281 NO_STR
4282 NEIGHBOR_STR
4283 NEIGHBOR_ADDR_STR2
4284 "Send Community attribute to this neighbor\n"
4285 "Send Standard and Extended Community attributes\n"
57d187bc 4286 "Send Standard, Large and Extended Community attributes\n"
718e3744 4287 "Send Extended Community attributes\n"
57d187bc
JS
4288 "Send Standard Community attributes\n"
4289 "Send Large Community attributes\n")
718e3744 4290{
d62a17ae 4291 int idx_peer = 2;
27c05d4d 4292 uint32_t flag = 0;
d62a17ae 4293 const char *type = argv[argc - 1]->text;
4294
27c05d4d
PM
4295 if (strmatch(type, "standard")) {
4296 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4297 } else if (strmatch(type, "extended")) {
4298 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4299 } else if (strmatch(type, "large")) {
4300 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4301 } else if (strmatch(type, "both")) {
4302 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4303 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4304 } else { /* if (strmatch(type, "all")) */
4305 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4306 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4307 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4308 }
4309
4310 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4311 bgp_node_afi(vty), bgp_node_safi(vty),
4312 flag);
d62a17ae 4313}
4314
4315ALIAS_HIDDEN(
4316 no_neighbor_send_community_type,
4317 no_neighbor_send_community_type_hidden_cmd,
4318 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4319 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4320 "Send Community attribute to this neighbor\n"
4321 "Send Standard and Extended Community attributes\n"
4322 "Send Standard, Large and Extended Community attributes\n"
4323 "Send Extended Community attributes\n"
4324 "Send Standard Community attributes\n"
4325 "Send Large Community attributes\n")
596c17ba 4326
718e3744 4327/* neighbor soft-reconfig. */
4328DEFUN (neighbor_soft_reconfiguration,
4329 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4330 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4331 NEIGHBOR_STR
4332 NEIGHBOR_ADDR_STR2
4333 "Per neighbor soft reconfiguration\n"
4334 "Allow inbound soft reconfiguration for this neighbor\n")
4335{
d62a17ae 4336 int idx_peer = 1;
4337 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4338 bgp_node_safi(vty),
4339 PEER_FLAG_SOFT_RECONFIG);
718e3744 4340}
4341
d62a17ae 4342ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4343 neighbor_soft_reconfiguration_hidden_cmd,
4344 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4345 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4346 "Per neighbor soft reconfiguration\n"
4347 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4348
718e3744 4349DEFUN (no_neighbor_soft_reconfiguration,
4350 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4351 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4352 NO_STR
4353 NEIGHBOR_STR
4354 NEIGHBOR_ADDR_STR2
4355 "Per neighbor soft reconfiguration\n"
4356 "Allow inbound soft reconfiguration for this neighbor\n")
4357{
d62a17ae 4358 int idx_peer = 2;
4359 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4360 bgp_node_afi(vty), bgp_node_safi(vty),
4361 PEER_FLAG_SOFT_RECONFIG);
718e3744 4362}
6b0655a2 4363
d62a17ae 4364ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4365 no_neighbor_soft_reconfiguration_hidden_cmd,
4366 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4367 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4368 "Per neighbor soft reconfiguration\n"
4369 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4370
718e3744 4371DEFUN (neighbor_route_reflector_client,
4372 neighbor_route_reflector_client_cmd,
9ccf14f7 4373 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4374 NEIGHBOR_STR
4375 NEIGHBOR_ADDR_STR2
4376 "Configure a neighbor as Route Reflector client\n")
4377{
d62a17ae 4378 int idx_peer = 1;
4379 struct peer *peer;
718e3744 4380
4381
d62a17ae 4382 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4383 if (!peer)
4384 return CMD_WARNING_CONFIG_FAILED;
718e3744 4385
d62a17ae 4386 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4387 bgp_node_safi(vty),
4388 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4389}
4390
d62a17ae 4391ALIAS_HIDDEN(neighbor_route_reflector_client,
4392 neighbor_route_reflector_client_hidden_cmd,
4393 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4394 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4395 "Configure a neighbor as Route Reflector client\n")
596c17ba 4396
718e3744 4397DEFUN (no_neighbor_route_reflector_client,
4398 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4399 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4400 NO_STR
4401 NEIGHBOR_STR
4402 NEIGHBOR_ADDR_STR2
4403 "Configure a neighbor as Route Reflector client\n")
4404{
d62a17ae 4405 int idx_peer = 2;
4406 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4407 bgp_node_afi(vty), bgp_node_safi(vty),
4408 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4409}
6b0655a2 4410
d62a17ae 4411ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4412 no_neighbor_route_reflector_client_hidden_cmd,
4413 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4414 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4415 "Configure a neighbor as Route Reflector client\n")
596c17ba 4416
718e3744 4417/* neighbor route-server-client. */
4418DEFUN (neighbor_route_server_client,
4419 neighbor_route_server_client_cmd,
9ccf14f7 4420 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4421 NEIGHBOR_STR
4422 NEIGHBOR_ADDR_STR2
4423 "Configure a neighbor as Route Server client\n")
4424{
d62a17ae 4425 int idx_peer = 1;
4426 struct peer *peer;
2a3d5731 4427
d62a17ae 4428 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4429 if (!peer)
4430 return CMD_WARNING_CONFIG_FAILED;
4431 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4432 bgp_node_safi(vty),
4433 PEER_FLAG_RSERVER_CLIENT);
718e3744 4434}
4435
d62a17ae 4436ALIAS_HIDDEN(neighbor_route_server_client,
4437 neighbor_route_server_client_hidden_cmd,
4438 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4439 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4440 "Configure a neighbor as Route Server client\n")
596c17ba 4441
718e3744 4442DEFUN (no_neighbor_route_server_client,
4443 no_neighbor_route_server_client_cmd,
9ccf14f7 4444 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4445 NO_STR
4446 NEIGHBOR_STR
4447 NEIGHBOR_ADDR_STR2
4448 "Configure a neighbor as Route Server client\n")
fee0f4c6 4449{
d62a17ae 4450 int idx_peer = 2;
4451 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4452 bgp_node_afi(vty), bgp_node_safi(vty),
4453 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4454}
6b0655a2 4455
d62a17ae 4456ALIAS_HIDDEN(no_neighbor_route_server_client,
4457 no_neighbor_route_server_client_hidden_cmd,
4458 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4459 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4460 "Configure a neighbor as Route Server client\n")
596c17ba 4461
fee0f4c6 4462DEFUN (neighbor_nexthop_local_unchanged,
4463 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4464 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4465 NEIGHBOR_STR
4466 NEIGHBOR_ADDR_STR2
4467 "Configure treatment of outgoing link-local nexthop attribute\n"
4468 "Leave link-local nexthop unchanged for this peer\n")
4469{
d62a17ae 4470 int idx_peer = 1;
4471 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4472 bgp_node_safi(vty),
4473 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4474}
6b0655a2 4475
fee0f4c6 4476DEFUN (no_neighbor_nexthop_local_unchanged,
4477 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4478 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4479 NO_STR
4480 NEIGHBOR_STR
4481 NEIGHBOR_ADDR_STR2
4482 "Configure treatment of outgoing link-local-nexthop attribute\n"
4483 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4484{
d62a17ae 4485 int idx_peer = 2;
4486 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4487 bgp_node_afi(vty), bgp_node_safi(vty),
4488 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4489}
6b0655a2 4490
718e3744 4491DEFUN (neighbor_attr_unchanged,
4492 neighbor_attr_unchanged_cmd,
a8206004 4493 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4494 NEIGHBOR_STR
4495 NEIGHBOR_ADDR_STR2
4496 "BGP attribute is propagated unchanged to this neighbor\n"
4497 "As-path attribute\n"
4498 "Nexthop attribute\n"
a8206004 4499 "Med attribute\n")
718e3744 4500{
d62a17ae 4501 int idx = 0;
8eeb0335
DW
4502 char *peer_str = argv[1]->arg;
4503 struct peer *peer;
d7c0a89a 4504 uint16_t flags = 0;
8eeb0335
DW
4505 afi_t afi = bgp_node_afi(vty);
4506 safi_t safi = bgp_node_safi(vty);
4507
4508 peer = peer_and_group_lookup_vty(vty, peer_str);
4509 if (!peer)
4510 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4511
4512 if (argv_find(argv, argc, "as-path", &idx))
4513 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4514 idx = 0;
4515 if (argv_find(argv, argc, "next-hop", &idx))
4516 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4517 idx = 0;
4518 if (argv_find(argv, argc, "med", &idx))
4519 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4520
8eeb0335
DW
4521 /* no flags means all of them! */
4522 if (!flags) {
d62a17ae 4523 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4524 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4525 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4526 } else {
a4d82a8a
PZ
4527 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4528 && peer_af_flag_check(peer, afi, safi,
4529 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4530 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4531 PEER_FLAG_AS_PATH_UNCHANGED);
4532 }
4533
a4d82a8a
PZ
4534 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4535 && peer_af_flag_check(peer, afi, safi,
4536 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4537 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4538 PEER_FLAG_NEXTHOP_UNCHANGED);
4539 }
4540
a4d82a8a
PZ
4541 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4542 && peer_af_flag_check(peer, afi, safi,
4543 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4544 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4545 PEER_FLAG_MED_UNCHANGED);
4546 }
d62a17ae 4547 }
4548
8eeb0335 4549 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4550}
4551
4552ALIAS_HIDDEN(
4553 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4554 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4555 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4556 "BGP attribute is propagated unchanged to this neighbor\n"
4557 "As-path attribute\n"
4558 "Nexthop attribute\n"
4559 "Med attribute\n")
596c17ba 4560
718e3744 4561DEFUN (no_neighbor_attr_unchanged,
4562 no_neighbor_attr_unchanged_cmd,
a8206004 4563 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4564 NO_STR
718e3744 4565 NEIGHBOR_STR
4566 NEIGHBOR_ADDR_STR2
31500417
DW
4567 "BGP attribute is propagated unchanged to this neighbor\n"
4568 "As-path attribute\n"
40e718b5 4569 "Nexthop attribute\n"
a8206004 4570 "Med attribute\n")
718e3744 4571{
d62a17ae 4572 int idx = 0;
4573 char *peer = argv[2]->arg;
d7c0a89a 4574 uint16_t flags = 0;
d62a17ae 4575
4576 if (argv_find(argv, argc, "as-path", &idx))
4577 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4578 idx = 0;
4579 if (argv_find(argv, argc, "next-hop", &idx))
4580 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4581 idx = 0;
4582 if (argv_find(argv, argc, "med", &idx))
4583 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4584
4585 if (!flags) // no flags means all of them!
4586 {
4587 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4588 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4589 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4590 }
4591
4592 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4593 bgp_node_safi(vty), flags);
4594}
4595
4596ALIAS_HIDDEN(
4597 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4598 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4599 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4600 "BGP attribute is propagated unchanged to this neighbor\n"
4601 "As-path attribute\n"
4602 "Nexthop attribute\n"
4603 "Med attribute\n")
718e3744 4604
718e3744 4605/* EBGP multihop configuration. */
d62a17ae 4606static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4607 const char *ttl_str)
718e3744 4608{
d62a17ae 4609 struct peer *peer;
4610 unsigned int ttl;
718e3744 4611
d62a17ae 4612 peer = peer_and_group_lookup_vty(vty, ip_str);
4613 if (!peer)
4614 return CMD_WARNING_CONFIG_FAILED;
718e3744 4615
d62a17ae 4616 if (peer->conf_if)
4617 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4618
d62a17ae 4619 if (!ttl_str)
4620 ttl = MAXTTL;
4621 else
4622 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4623
d62a17ae 4624 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4625}
4626
d62a17ae 4627static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4628{
d62a17ae 4629 struct peer *peer;
718e3744 4630
d62a17ae 4631 peer = peer_and_group_lookup_vty(vty, ip_str);
4632 if (!peer)
4633 return CMD_WARNING_CONFIG_FAILED;
718e3744 4634
d62a17ae 4635 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4636}
4637
4638/* neighbor ebgp-multihop. */
4639DEFUN (neighbor_ebgp_multihop,
4640 neighbor_ebgp_multihop_cmd,
9ccf14f7 4641 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4642 NEIGHBOR_STR
4643 NEIGHBOR_ADDR_STR2
4644 "Allow EBGP neighbors not on directly connected networks\n")
4645{
d62a17ae 4646 int idx_peer = 1;
4647 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4648}
4649
4650DEFUN (neighbor_ebgp_multihop_ttl,
4651 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4652 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4653 NEIGHBOR_STR
4654 NEIGHBOR_ADDR_STR2
4655 "Allow EBGP neighbors not on directly connected networks\n"
4656 "maximum hop count\n")
4657{
d62a17ae 4658 int idx_peer = 1;
4659 int idx_number = 3;
4660 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4661 argv[idx_number]->arg);
718e3744 4662}
4663
4664DEFUN (no_neighbor_ebgp_multihop,
4665 no_neighbor_ebgp_multihop_cmd,
a636c635 4666 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4667 NO_STR
4668 NEIGHBOR_STR
4669 NEIGHBOR_ADDR_STR2
a636c635
DW
4670 "Allow EBGP neighbors not on directly connected networks\n"
4671 "maximum hop count\n")
718e3744 4672{
d62a17ae 4673 int idx_peer = 2;
4674 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4675}
4676
6b0655a2 4677
6ffd2079 4678/* disable-connected-check */
4679DEFUN (neighbor_disable_connected_check,
4680 neighbor_disable_connected_check_cmd,
7ebe625c 4681 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4682 NEIGHBOR_STR
7ebe625c 4683 NEIGHBOR_ADDR_STR2
a636c635
DW
4684 "one-hop away EBGP peer using loopback address\n"
4685 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4686{
d62a17ae 4687 int idx_peer = 1;
4688 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4689 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4690}
4691
4692DEFUN (no_neighbor_disable_connected_check,
4693 no_neighbor_disable_connected_check_cmd,
7ebe625c 4694 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4695 NO_STR
4696 NEIGHBOR_STR
7ebe625c 4697 NEIGHBOR_ADDR_STR2
a636c635
DW
4698 "one-hop away EBGP peer using loopback address\n"
4699 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4700{
d62a17ae 4701 int idx_peer = 2;
4702 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4703 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4704}
4705
47cbc09b
PM
4706
4707/* enforce-first-as */
4708DEFUN (neighbor_enforce_first_as,
4709 neighbor_enforce_first_as_cmd,
4710 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4711 NEIGHBOR_STR
4712 NEIGHBOR_ADDR_STR2
4713 "Enforce the first AS for EBGP routes\n")
4714{
4715 int idx_peer = 1;
4716
4717 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4718 PEER_FLAG_ENFORCE_FIRST_AS);
4719}
4720
4721DEFUN (no_neighbor_enforce_first_as,
4722 no_neighbor_enforce_first_as_cmd,
4723 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4724 NO_STR
4725 NEIGHBOR_STR
4726 NEIGHBOR_ADDR_STR2
4727 "Enforce the first AS for EBGP routes\n")
4728{
4729 int idx_peer = 2;
4730
4731 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4732 PEER_FLAG_ENFORCE_FIRST_AS);
4733}
4734
4735
718e3744 4736DEFUN (neighbor_description,
4737 neighbor_description_cmd,
e961923c 4738 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4739 NEIGHBOR_STR
4740 NEIGHBOR_ADDR_STR2
4741 "Neighbor specific description\n"
4742 "Up to 80 characters describing this neighbor\n")
4743{
d62a17ae 4744 int idx_peer = 1;
4745 int idx_line = 3;
4746 struct peer *peer;
4747 char *str;
718e3744 4748
d62a17ae 4749 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4750 if (!peer)
4751 return CMD_WARNING_CONFIG_FAILED;
718e3744 4752
d62a17ae 4753 str = argv_concat(argv, argc, idx_line);
718e3744 4754
d62a17ae 4755 peer_description_set(peer, str);
718e3744 4756
d62a17ae 4757 XFREE(MTYPE_TMP, str);
718e3744 4758
d62a17ae 4759 return CMD_SUCCESS;
718e3744 4760}
4761
4762DEFUN (no_neighbor_description,
4763 no_neighbor_description_cmd,
a14810f4 4764 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4765 NO_STR
4766 NEIGHBOR_STR
4767 NEIGHBOR_ADDR_STR2
a14810f4 4768 "Neighbor specific description\n")
718e3744 4769{
d62a17ae 4770 int idx_peer = 2;
4771 struct peer *peer;
718e3744 4772
d62a17ae 4773 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4774 if (!peer)
4775 return CMD_WARNING_CONFIG_FAILED;
718e3744 4776
d62a17ae 4777 peer_description_unset(peer);
718e3744 4778
d62a17ae 4779 return CMD_SUCCESS;
718e3744 4780}
4781
a14810f4
PM
4782ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4783 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4784 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4785 "Neighbor specific description\n"
4786 "Up to 80 characters describing this neighbor\n")
6b0655a2 4787
718e3744 4788/* Neighbor update-source. */
d62a17ae 4789static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4790 const char *source_str)
4791{
4792 struct peer *peer;
4793 struct prefix p;
a14810f4 4794 union sockunion su;
d62a17ae 4795
4796 peer = peer_and_group_lookup_vty(vty, peer_str);
4797 if (!peer)
4798 return CMD_WARNING_CONFIG_FAILED;
4799
4800 if (peer->conf_if)
4801 return CMD_WARNING;
4802
4803 if (source_str) {
a14810f4 4804 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4805 peer_update_source_addr_set(peer, &su);
4806 else {
4807 if (str2prefix(source_str, &p)) {
4808 vty_out(vty,
4809 "%% Invalid update-source, remove prefix length \n");
4810 return CMD_WARNING_CONFIG_FAILED;
4811 } else
4812 peer_update_source_if_set(peer, source_str);
4813 }
4814 } else
4815 peer_update_source_unset(peer);
4816
4817 return CMD_SUCCESS;
4818}
4819
4820#define BGP_UPDATE_SOURCE_HELP_STR \
4821 "IPv4 address\n" \
4822 "IPv6 address\n" \
4823 "Interface name (requires zebra to be running)\n"
369688c0 4824
718e3744 4825DEFUN (neighbor_update_source,
4826 neighbor_update_source_cmd,
9ccf14f7 4827 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4828 NEIGHBOR_STR
4829 NEIGHBOR_ADDR_STR2
4830 "Source of routing updates\n"
369688c0 4831 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4832{
d62a17ae 4833 int idx_peer = 1;
4834 int idx_peer_2 = 3;
4835 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4836 argv[idx_peer_2]->arg);
718e3744 4837}
4838
4839DEFUN (no_neighbor_update_source,
4840 no_neighbor_update_source_cmd,
c7178fe7 4841 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4842 NO_STR
4843 NEIGHBOR_STR
4844 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4845 "Source of routing updates\n"
4846 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4847{
d62a17ae 4848 int idx_peer = 2;
4849 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4850}
6b0655a2 4851
d62a17ae 4852static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4853 afi_t afi, safi_t safi,
4854 const char *rmap, int set)
718e3744 4855{
d62a17ae 4856 int ret;
4857 struct peer *peer;
1de27621 4858 struct route_map *route_map;
718e3744 4859
d62a17ae 4860 peer = peer_and_group_lookup_vty(vty, peer_str);
4861 if (!peer)
4862 return CMD_WARNING_CONFIG_FAILED;
718e3744 4863
1de27621
DA
4864 if (set) {
4865 route_map = route_map_lookup_warn_noexist(vty, rmap);
4866 ret = peer_default_originate_set(peer, afi, safi,
4867 rmap, route_map);
4868 } else
d62a17ae 4869 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4870
d62a17ae 4871 return bgp_vty_return(vty, ret);
718e3744 4872}
4873
4874/* neighbor default-originate. */
4875DEFUN (neighbor_default_originate,
4876 neighbor_default_originate_cmd,
9ccf14f7 4877 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4878 NEIGHBOR_STR
4879 NEIGHBOR_ADDR_STR2
4880 "Originate default route to this neighbor\n")
4881{
d62a17ae 4882 int idx_peer = 1;
4883 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4884 bgp_node_afi(vty),
4885 bgp_node_safi(vty), NULL, 1);
718e3744 4886}
4887
d62a17ae 4888ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4889 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4890 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4891 "Originate default route to this neighbor\n")
596c17ba 4892
718e3744 4893DEFUN (neighbor_default_originate_rmap,
4894 neighbor_default_originate_rmap_cmd,
9ccf14f7 4895 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4896 NEIGHBOR_STR
4897 NEIGHBOR_ADDR_STR2
4898 "Originate default route to this neighbor\n"
4899 "Route-map to specify criteria to originate default\n"
4900 "route-map name\n")
4901{
d62a17ae 4902 int idx_peer = 1;
4903 int idx_word = 4;
4904 return peer_default_originate_set_vty(
4905 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4906 argv[idx_word]->arg, 1);
718e3744 4907}
4908
d62a17ae 4909ALIAS_HIDDEN(
4910 neighbor_default_originate_rmap,
4911 neighbor_default_originate_rmap_hidden_cmd,
4912 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4913 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4914 "Originate default route to this neighbor\n"
4915 "Route-map to specify criteria to originate default\n"
4916 "route-map name\n")
596c17ba 4917
718e3744 4918DEFUN (no_neighbor_default_originate,
4919 no_neighbor_default_originate_cmd,
a636c635 4920 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4921 NO_STR
4922 NEIGHBOR_STR
4923 NEIGHBOR_ADDR_STR2
a636c635
DW
4924 "Originate default route to this neighbor\n"
4925 "Route-map to specify criteria to originate default\n"
4926 "route-map name\n")
718e3744 4927{
d62a17ae 4928 int idx_peer = 2;
4929 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4930 bgp_node_afi(vty),
4931 bgp_node_safi(vty), NULL, 0);
718e3744 4932}
4933
d62a17ae 4934ALIAS_HIDDEN(
4935 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4936 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4937 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4938 "Originate default route to this neighbor\n"
4939 "Route-map to specify criteria to originate default\n"
4940 "route-map name\n")
596c17ba 4941
6b0655a2 4942
718e3744 4943/* Set neighbor's BGP port. */
d62a17ae 4944static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4945 const char *port_str)
4946{
4947 struct peer *peer;
d7c0a89a 4948 uint16_t port;
d62a17ae 4949 struct servent *sp;
4950
4951 peer = peer_lookup_vty(vty, ip_str);
4952 if (!peer)
4953 return CMD_WARNING_CONFIG_FAILED;
4954
4955 if (!port_str) {
4956 sp = getservbyname("bgp", "tcp");
4957 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4958 } else {
4959 port = strtoul(port_str, NULL, 10);
4960 }
718e3744 4961
d62a17ae 4962 peer_port_set(peer, port);
718e3744 4963
d62a17ae 4964 return CMD_SUCCESS;
718e3744 4965}
4966
f418446b 4967/* Set specified peer's BGP port. */
718e3744 4968DEFUN (neighbor_port,
4969 neighbor_port_cmd,
9ccf14f7 4970 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4971 NEIGHBOR_STR
4972 NEIGHBOR_ADDR_STR
4973 "Neighbor's BGP port\n"
4974 "TCP port number\n")
4975{
d62a17ae 4976 int idx_ip = 1;
4977 int idx_number = 3;
4978 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4979 argv[idx_number]->arg);
718e3744 4980}
4981
4982DEFUN (no_neighbor_port,
4983 no_neighbor_port_cmd,
9ccf14f7 4984 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4985 NO_STR
4986 NEIGHBOR_STR
4987 NEIGHBOR_ADDR_STR
8334fd5a
DW
4988 "Neighbor's BGP port\n"
4989 "TCP port number\n")
718e3744 4990{
d62a17ae 4991 int idx_ip = 2;
4992 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4993}
4994
6b0655a2 4995
718e3744 4996/* neighbor weight. */
d62a17ae 4997static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4998 safi_t safi, const char *weight_str)
718e3744 4999{
d62a17ae 5000 int ret;
5001 struct peer *peer;
5002 unsigned long weight;
718e3744 5003
d62a17ae 5004 peer = peer_and_group_lookup_vty(vty, ip_str);
5005 if (!peer)
5006 return CMD_WARNING_CONFIG_FAILED;
718e3744 5007
d62a17ae 5008 weight = strtoul(weight_str, NULL, 10);
718e3744 5009
d62a17ae 5010 ret = peer_weight_set(peer, afi, safi, weight);
5011 return bgp_vty_return(vty, ret);
718e3744 5012}
5013
d62a17ae 5014static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5015 safi_t safi)
718e3744 5016{
d62a17ae 5017 int ret;
5018 struct peer *peer;
718e3744 5019
d62a17ae 5020 peer = peer_and_group_lookup_vty(vty, ip_str);
5021 if (!peer)
5022 return CMD_WARNING_CONFIG_FAILED;
718e3744 5023
d62a17ae 5024 ret = peer_weight_unset(peer, afi, safi);
5025 return bgp_vty_return(vty, ret);
718e3744 5026}
5027
5028DEFUN (neighbor_weight,
5029 neighbor_weight_cmd,
9ccf14f7 5030 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 5031 NEIGHBOR_STR
5032 NEIGHBOR_ADDR_STR2
5033 "Set default weight for routes from this neighbor\n"
5034 "default weight\n")
5035{
d62a17ae 5036 int idx_peer = 1;
5037 int idx_number = 3;
5038 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5039 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 5040}
5041
d62a17ae 5042ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5043 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5044 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5045 "Set default weight for routes from this neighbor\n"
5046 "default weight\n")
596c17ba 5047
718e3744 5048DEFUN (no_neighbor_weight,
5049 no_neighbor_weight_cmd,
9ccf14f7 5050 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5051 NO_STR
5052 NEIGHBOR_STR
5053 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5054 "Set default weight for routes from this neighbor\n"
5055 "default weight\n")
718e3744 5056{
d62a17ae 5057 int idx_peer = 2;
5058 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5059 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 5060}
5061
d62a17ae 5062ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5063 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5064 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5065 "Set default weight for routes from this neighbor\n"
5066 "default weight\n")
596c17ba 5067
6b0655a2 5068
718e3744 5069/* Override capability negotiation. */
5070DEFUN (neighbor_override_capability,
5071 neighbor_override_capability_cmd,
9ccf14f7 5072 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5073 NEIGHBOR_STR
5074 NEIGHBOR_ADDR_STR2
5075 "Override capability negotiation result\n")
5076{
d62a17ae 5077 int idx_peer = 1;
5078 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5079 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5080}
5081
5082DEFUN (no_neighbor_override_capability,
5083 no_neighbor_override_capability_cmd,
9ccf14f7 5084 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5085 NO_STR
5086 NEIGHBOR_STR
5087 NEIGHBOR_ADDR_STR2
5088 "Override capability negotiation result\n")
5089{
d62a17ae 5090 int idx_peer = 2;
5091 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5092 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5093}
6b0655a2 5094
718e3744 5095DEFUN (neighbor_strict_capability,
5096 neighbor_strict_capability_cmd,
9fb964de 5097 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5098 NEIGHBOR_STR
9fb964de 5099 NEIGHBOR_ADDR_STR2
718e3744 5100 "Strict capability negotiation match\n")
5101{
9fb964de
PM
5102 int idx_peer = 1;
5103
5104 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5105 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5106}
5107
5108DEFUN (no_neighbor_strict_capability,
5109 no_neighbor_strict_capability_cmd,
9fb964de 5110 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5111 NO_STR
5112 NEIGHBOR_STR
9fb964de 5113 NEIGHBOR_ADDR_STR2
718e3744 5114 "Strict capability negotiation match\n")
5115{
9fb964de
PM
5116 int idx_peer = 2;
5117
5118 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5119 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5120}
6b0655a2 5121
d62a17ae 5122static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5123 const char *keep_str, const char *hold_str)
718e3744 5124{
d62a17ae 5125 int ret;
5126 struct peer *peer;
d7c0a89a
QY
5127 uint32_t keepalive;
5128 uint32_t holdtime;
718e3744 5129
d62a17ae 5130 peer = peer_and_group_lookup_vty(vty, ip_str);
5131 if (!peer)
5132 return CMD_WARNING_CONFIG_FAILED;
718e3744 5133
d62a17ae 5134 keepalive = strtoul(keep_str, NULL, 10);
5135 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5136
d62a17ae 5137 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5138
d62a17ae 5139 return bgp_vty_return(vty, ret);
718e3744 5140}
6b0655a2 5141
d62a17ae 5142static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5143{
d62a17ae 5144 int ret;
5145 struct peer *peer;
718e3744 5146
d62a17ae 5147 peer = peer_and_group_lookup_vty(vty, ip_str);
5148 if (!peer)
5149 return CMD_WARNING_CONFIG_FAILED;
718e3744 5150
d62a17ae 5151 ret = peer_timers_unset(peer);
718e3744 5152
d62a17ae 5153 return bgp_vty_return(vty, ret);
718e3744 5154}
5155
5156DEFUN (neighbor_timers,
5157 neighbor_timers_cmd,
9ccf14f7 5158 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5159 NEIGHBOR_STR
5160 NEIGHBOR_ADDR_STR2
5161 "BGP per neighbor timers\n"
5162 "Keepalive interval\n"
5163 "Holdtime\n")
5164{
d62a17ae 5165 int idx_peer = 1;
5166 int idx_number = 3;
5167 int idx_number_2 = 4;
5168 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5169 argv[idx_number]->arg,
5170 argv[idx_number_2]->arg);
718e3744 5171}
5172
5173DEFUN (no_neighbor_timers,
5174 no_neighbor_timers_cmd,
9ccf14f7 5175 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5176 NO_STR
5177 NEIGHBOR_STR
5178 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5179 "BGP per neighbor timers\n"
5180 "Keepalive interval\n"
5181 "Holdtime\n")
718e3744 5182{
d62a17ae 5183 int idx_peer = 2;
5184 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5185}
6b0655a2 5186
813d4307 5187
d62a17ae 5188static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5189 const char *time_str)
718e3744 5190{
d62a17ae 5191 int ret;
5192 struct peer *peer;
d7c0a89a 5193 uint32_t connect;
718e3744 5194
d62a17ae 5195 peer = peer_and_group_lookup_vty(vty, ip_str);
5196 if (!peer)
5197 return CMD_WARNING_CONFIG_FAILED;
718e3744 5198
d62a17ae 5199 connect = strtoul(time_str, NULL, 10);
718e3744 5200
d62a17ae 5201 ret = peer_timers_connect_set(peer, connect);
718e3744 5202
d62a17ae 5203 return bgp_vty_return(vty, ret);
718e3744 5204}
5205
d62a17ae 5206static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5207{
d62a17ae 5208 int ret;
5209 struct peer *peer;
718e3744 5210
d62a17ae 5211 peer = peer_and_group_lookup_vty(vty, ip_str);
5212 if (!peer)
5213 return CMD_WARNING_CONFIG_FAILED;
718e3744 5214
d62a17ae 5215 ret = peer_timers_connect_unset(peer);
718e3744 5216
d62a17ae 5217 return bgp_vty_return(vty, ret);
718e3744 5218}
5219
5220DEFUN (neighbor_timers_connect,
5221 neighbor_timers_connect_cmd,
9ccf14f7 5222 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5223 NEIGHBOR_STR
966f821c 5224 NEIGHBOR_ADDR_STR2
718e3744 5225 "BGP per neighbor timers\n"
5226 "BGP connect timer\n"
5227 "Connect timer\n")
5228{
d62a17ae 5229 int idx_peer = 1;
5230 int idx_number = 4;
5231 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5232 argv[idx_number]->arg);
718e3744 5233}
5234
5235DEFUN (no_neighbor_timers_connect,
5236 no_neighbor_timers_connect_cmd,
9ccf14f7 5237 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5238 NO_STR
5239 NEIGHBOR_STR
966f821c 5240 NEIGHBOR_ADDR_STR2
718e3744 5241 "BGP per neighbor timers\n"
8334fd5a
DW
5242 "BGP connect timer\n"
5243 "Connect timer\n")
718e3744 5244{
d62a17ae 5245 int idx_peer = 2;
5246 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5247}
5248
6b0655a2 5249
d62a17ae 5250static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5251 const char *time_str, int set)
718e3744 5252{
d62a17ae 5253 int ret;
5254 struct peer *peer;
d7c0a89a 5255 uint32_t routeadv = 0;
718e3744 5256
d62a17ae 5257 peer = peer_and_group_lookup_vty(vty, ip_str);
5258 if (!peer)
5259 return CMD_WARNING_CONFIG_FAILED;
718e3744 5260
d62a17ae 5261 if (time_str)
5262 routeadv = strtoul(time_str, NULL, 10);
718e3744 5263
d62a17ae 5264 if (set)
5265 ret = peer_advertise_interval_set(peer, routeadv);
5266 else
5267 ret = peer_advertise_interval_unset(peer);
718e3744 5268
d62a17ae 5269 return bgp_vty_return(vty, ret);
718e3744 5270}
5271
5272DEFUN (neighbor_advertise_interval,
5273 neighbor_advertise_interval_cmd,
9ccf14f7 5274 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5275 NEIGHBOR_STR
966f821c 5276 NEIGHBOR_ADDR_STR2
718e3744 5277 "Minimum interval between sending BGP routing updates\n"
5278 "time in seconds\n")
5279{
d62a17ae 5280 int idx_peer = 1;
5281 int idx_number = 3;
5282 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5283 argv[idx_number]->arg, 1);
718e3744 5284}
5285
5286DEFUN (no_neighbor_advertise_interval,
5287 no_neighbor_advertise_interval_cmd,
9ccf14f7 5288 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5289 NO_STR
5290 NEIGHBOR_STR
966f821c 5291 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5292 "Minimum interval between sending BGP routing updates\n"
5293 "time in seconds\n")
718e3744 5294{
d62a17ae 5295 int idx_peer = 2;
5296 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5297}
5298
6b0655a2 5299
518f0eb1
DS
5300/* Time to wait before processing route-map updates */
5301DEFUN (bgp_set_route_map_delay_timer,
5302 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5303 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5304 SET_STR
5305 "BGP route-map delay timer\n"
5306 "Time in secs to wait before processing route-map changes\n"
f414725f 5307 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5308{
d62a17ae 5309 int idx_number = 3;
d7c0a89a 5310 uint32_t rmap_delay_timer;
d62a17ae 5311
5312 if (argv[idx_number]->arg) {
5313 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5314 bm->rmap_update_timer = rmap_delay_timer;
5315
5316 /* if the dynamic update handling is being disabled, and a timer
5317 * is
5318 * running, stop the timer and act as if the timer has already
5319 * fired.
5320 */
5321 if (!rmap_delay_timer && bm->t_rmap_update) {
5322 BGP_TIMER_OFF(bm->t_rmap_update);
5323 thread_execute(bm->master, bgp_route_map_update_timer,
5324 NULL, 0);
5325 }
5326 return CMD_SUCCESS;
5327 } else {
5328 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5329 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5330 }
518f0eb1
DS
5331}
5332
5333DEFUN (no_bgp_set_route_map_delay_timer,
5334 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5335 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5336 NO_STR
3a2d747c 5337 BGP_STR
518f0eb1 5338 "Default BGP route-map delay timer\n"
8334fd5a
DW
5339 "Reset to default time to wait for processing route-map changes\n"
5340 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5341{
518f0eb1 5342
d62a17ae 5343 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5344
d62a17ae 5345 return CMD_SUCCESS;
518f0eb1
DS
5346}
5347
f414725f 5348
718e3744 5349/* neighbor interface */
d62a17ae 5350static int peer_interface_vty(struct vty *vty, const char *ip_str,
5351 const char *str)
718e3744 5352{
d62a17ae 5353 struct peer *peer;
718e3744 5354
d62a17ae 5355 peer = peer_lookup_vty(vty, ip_str);
5356 if (!peer || peer->conf_if) {
5357 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5358 return CMD_WARNING_CONFIG_FAILED;
5359 }
718e3744 5360
d62a17ae 5361 if (str)
5362 peer_interface_set(peer, str);
5363 else
5364 peer_interface_unset(peer);
718e3744 5365
d62a17ae 5366 return CMD_SUCCESS;
718e3744 5367}
5368
5369DEFUN (neighbor_interface,
5370 neighbor_interface_cmd,
9ccf14f7 5371 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5372 NEIGHBOR_STR
5373 NEIGHBOR_ADDR_STR
5374 "Interface\n"
5375 "Interface name\n")
5376{
d62a17ae 5377 int idx_ip = 1;
5378 int idx_word = 3;
5379 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5380}
5381
5382DEFUN (no_neighbor_interface,
5383 no_neighbor_interface_cmd,
9ccf14f7 5384 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5385 NO_STR
5386 NEIGHBOR_STR
16cedbb0 5387 NEIGHBOR_ADDR_STR2
718e3744 5388 "Interface\n"
5389 "Interface name\n")
5390{
d62a17ae 5391 int idx_peer = 2;
5392 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5393}
6b0655a2 5394
718e3744 5395DEFUN (neighbor_distribute_list,
5396 neighbor_distribute_list_cmd,
9ccf14f7 5397 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5398 NEIGHBOR_STR
5399 NEIGHBOR_ADDR_STR2
5400 "Filter updates to/from this neighbor\n"
5401 "IP access-list number\n"
5402 "IP access-list number (expanded range)\n"
5403 "IP Access-list name\n"
5404 "Filter incoming updates\n"
5405 "Filter outgoing updates\n")
5406{
d62a17ae 5407 int idx_peer = 1;
5408 int idx_acl = 3;
5409 int direct, ret;
5410 struct peer *peer;
a8206004 5411
d62a17ae 5412 const char *pstr = argv[idx_peer]->arg;
5413 const char *acl = argv[idx_acl]->arg;
5414 const char *inout = argv[argc - 1]->text;
a8206004 5415
d62a17ae 5416 peer = peer_and_group_lookup_vty(vty, pstr);
5417 if (!peer)
5418 return CMD_WARNING_CONFIG_FAILED;
a8206004 5419
d62a17ae 5420 /* Check filter direction. */
5421 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5422 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5423 direct, acl);
a8206004 5424
d62a17ae 5425 return bgp_vty_return(vty, ret);
718e3744 5426}
5427
d62a17ae 5428ALIAS_HIDDEN(
5429 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5430 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5431 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5432 "Filter updates to/from this neighbor\n"
5433 "IP access-list number\n"
5434 "IP access-list number (expanded range)\n"
5435 "IP Access-list name\n"
5436 "Filter incoming updates\n"
5437 "Filter outgoing updates\n")
596c17ba 5438
718e3744 5439DEFUN (no_neighbor_distribute_list,
5440 no_neighbor_distribute_list_cmd,
9ccf14f7 5441 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5442 NO_STR
5443 NEIGHBOR_STR
5444 NEIGHBOR_ADDR_STR2
5445 "Filter updates to/from this neighbor\n"
5446 "IP access-list number\n"
5447 "IP access-list number (expanded range)\n"
5448 "IP Access-list name\n"
5449 "Filter incoming updates\n"
5450 "Filter outgoing updates\n")
5451{
d62a17ae 5452 int idx_peer = 2;
5453 int direct, ret;
5454 struct peer *peer;
a8206004 5455
d62a17ae 5456 const char *pstr = argv[idx_peer]->arg;
5457 const char *inout = argv[argc - 1]->text;
a8206004 5458
d62a17ae 5459 peer = peer_and_group_lookup_vty(vty, pstr);
5460 if (!peer)
5461 return CMD_WARNING_CONFIG_FAILED;
a8206004 5462
d62a17ae 5463 /* Check filter direction. */
5464 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5465 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5466 direct);
a8206004 5467
d62a17ae 5468 return bgp_vty_return(vty, ret);
718e3744 5469}
6b0655a2 5470
d62a17ae 5471ALIAS_HIDDEN(
5472 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5473 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5474 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5475 "Filter updates to/from this neighbor\n"
5476 "IP access-list number\n"
5477 "IP access-list number (expanded range)\n"
5478 "IP Access-list name\n"
5479 "Filter incoming updates\n"
5480 "Filter outgoing updates\n")
596c17ba 5481
718e3744 5482/* Set prefix list to the peer. */
d62a17ae 5483static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5484 afi_t afi, safi_t safi,
5485 const char *name_str,
5486 const char *direct_str)
718e3744 5487{
d62a17ae 5488 int ret;
d62a17ae 5489 int direct = FILTER_IN;
cf9ac8bf 5490 struct peer *peer;
718e3744 5491
d62a17ae 5492 peer = peer_and_group_lookup_vty(vty, ip_str);
5493 if (!peer)
5494 return CMD_WARNING_CONFIG_FAILED;
718e3744 5495
d62a17ae 5496 /* Check filter direction. */
5497 if (strncmp(direct_str, "i", 1) == 0)
5498 direct = FILTER_IN;
5499 else if (strncmp(direct_str, "o", 1) == 0)
5500 direct = FILTER_OUT;
718e3744 5501
d62a17ae 5502 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5503
d62a17ae 5504 return bgp_vty_return(vty, ret);
718e3744 5505}
5506
d62a17ae 5507static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5508 afi_t afi, safi_t safi,
5509 const char *direct_str)
718e3744 5510{
d62a17ae 5511 int ret;
5512 struct peer *peer;
5513 int direct = FILTER_IN;
718e3744 5514
d62a17ae 5515 peer = peer_and_group_lookup_vty(vty, ip_str);
5516 if (!peer)
5517 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5518
d62a17ae 5519 /* Check filter direction. */
5520 if (strncmp(direct_str, "i", 1) == 0)
5521 direct = FILTER_IN;
5522 else if (strncmp(direct_str, "o", 1) == 0)
5523 direct = FILTER_OUT;
718e3744 5524
d62a17ae 5525 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5526
d62a17ae 5527 return bgp_vty_return(vty, ret);
718e3744 5528}
5529
5530DEFUN (neighbor_prefix_list,
5531 neighbor_prefix_list_cmd,
9ccf14f7 5532 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5533 NEIGHBOR_STR
5534 NEIGHBOR_ADDR_STR2
5535 "Filter updates to/from this neighbor\n"
5536 "Name of a prefix list\n"
5537 "Filter incoming updates\n"
5538 "Filter outgoing updates\n")
5539{
d62a17ae 5540 int idx_peer = 1;
5541 int idx_word = 3;
5542 int idx_in_out = 4;
5543 return peer_prefix_list_set_vty(
5544 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5545 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5546}
5547
d62a17ae 5548ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5549 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5550 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5551 "Filter updates to/from this neighbor\n"
5552 "Name of a prefix list\n"
5553 "Filter incoming updates\n"
5554 "Filter outgoing updates\n")
596c17ba 5555
718e3744 5556DEFUN (no_neighbor_prefix_list,
5557 no_neighbor_prefix_list_cmd,
9ccf14f7 5558 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5559 NO_STR
5560 NEIGHBOR_STR
5561 NEIGHBOR_ADDR_STR2
5562 "Filter updates to/from this neighbor\n"
5563 "Name of a prefix list\n"
5564 "Filter incoming updates\n"
5565 "Filter outgoing updates\n")
5566{
d62a17ae 5567 int idx_peer = 2;
5568 int idx_in_out = 5;
5569 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5570 bgp_node_afi(vty), bgp_node_safi(vty),
5571 argv[idx_in_out]->arg);
718e3744 5572}
6b0655a2 5573
d62a17ae 5574ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5575 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5576 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5577 "Filter updates to/from this neighbor\n"
5578 "Name of a prefix list\n"
5579 "Filter incoming updates\n"
5580 "Filter outgoing updates\n")
596c17ba 5581
d62a17ae 5582static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5583 safi_t safi, const char *name_str,
5584 const char *direct_str)
718e3744 5585{
d62a17ae 5586 int ret;
5587 struct peer *peer;
5588 int direct = FILTER_IN;
718e3744 5589
d62a17ae 5590 peer = peer_and_group_lookup_vty(vty, ip_str);
5591 if (!peer)
5592 return CMD_WARNING_CONFIG_FAILED;
718e3744 5593
d62a17ae 5594 /* Check filter direction. */
5595 if (strncmp(direct_str, "i", 1) == 0)
5596 direct = FILTER_IN;
5597 else if (strncmp(direct_str, "o", 1) == 0)
5598 direct = FILTER_OUT;
718e3744 5599
d62a17ae 5600 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5601
d62a17ae 5602 return bgp_vty_return(vty, ret);
718e3744 5603}
5604
d62a17ae 5605static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5606 safi_t safi, const char *direct_str)
718e3744 5607{
d62a17ae 5608 int ret;
5609 struct peer *peer;
5610 int direct = FILTER_IN;
718e3744 5611
d62a17ae 5612 peer = peer_and_group_lookup_vty(vty, ip_str);
5613 if (!peer)
5614 return CMD_WARNING_CONFIG_FAILED;
718e3744 5615
d62a17ae 5616 /* Check filter direction. */
5617 if (strncmp(direct_str, "i", 1) == 0)
5618 direct = FILTER_IN;
5619 else if (strncmp(direct_str, "o", 1) == 0)
5620 direct = FILTER_OUT;
718e3744 5621
d62a17ae 5622 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5623
d62a17ae 5624 return bgp_vty_return(vty, ret);
718e3744 5625}
5626
5627DEFUN (neighbor_filter_list,
5628 neighbor_filter_list_cmd,
9ccf14f7 5629 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5630 NEIGHBOR_STR
5631 NEIGHBOR_ADDR_STR2
5632 "Establish BGP filters\n"
5633 "AS path access-list name\n"
5634 "Filter incoming routes\n"
5635 "Filter outgoing routes\n")
5636{
d62a17ae 5637 int idx_peer = 1;
5638 int idx_word = 3;
5639 int idx_in_out = 4;
5640 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5641 bgp_node_safi(vty), argv[idx_word]->arg,
5642 argv[idx_in_out]->arg);
718e3744 5643}
5644
d62a17ae 5645ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5646 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5647 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5648 "Establish BGP filters\n"
5649 "AS path access-list name\n"
5650 "Filter incoming routes\n"
5651 "Filter outgoing routes\n")
596c17ba 5652
718e3744 5653DEFUN (no_neighbor_filter_list,
5654 no_neighbor_filter_list_cmd,
9ccf14f7 5655 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5656 NO_STR
5657 NEIGHBOR_STR
5658 NEIGHBOR_ADDR_STR2
5659 "Establish BGP filters\n"
5660 "AS path access-list name\n"
5661 "Filter incoming routes\n"
5662 "Filter outgoing routes\n")
5663{
d62a17ae 5664 int idx_peer = 2;
5665 int idx_in_out = 5;
5666 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5667 bgp_node_afi(vty), bgp_node_safi(vty),
5668 argv[idx_in_out]->arg);
718e3744 5669}
6b0655a2 5670
d62a17ae 5671ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5672 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5673 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5674 "Establish BGP filters\n"
5675 "AS path access-list name\n"
5676 "Filter incoming routes\n"
5677 "Filter outgoing routes\n")
596c17ba 5678
718e3744 5679/* Set route-map to the peer. */
d62a17ae 5680static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5681 afi_t afi, safi_t safi, const char *name_str,
5682 const char *direct_str)
718e3744 5683{
d62a17ae 5684 int ret;
5685 struct peer *peer;
5686 int direct = RMAP_IN;
1de27621 5687 struct route_map *route_map;
718e3744 5688
d62a17ae 5689 peer = peer_and_group_lookup_vty(vty, ip_str);
5690 if (!peer)
5691 return CMD_WARNING_CONFIG_FAILED;
718e3744 5692
d62a17ae 5693 /* Check filter direction. */
5694 if (strncmp(direct_str, "in", 2) == 0)
5695 direct = RMAP_IN;
5696 else if (strncmp(direct_str, "o", 1) == 0)
5697 direct = RMAP_OUT;
718e3744 5698
1de27621
DA
5699 route_map = route_map_lookup_warn_noexist(vty, name_str);
5700 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 5701
d62a17ae 5702 return bgp_vty_return(vty, ret);
718e3744 5703}
5704
d62a17ae 5705static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5706 afi_t afi, safi_t safi,
5707 const char *direct_str)
718e3744 5708{
d62a17ae 5709 int ret;
5710 struct peer *peer;
5711 int direct = RMAP_IN;
718e3744 5712
d62a17ae 5713 peer = peer_and_group_lookup_vty(vty, ip_str);
5714 if (!peer)
5715 return CMD_WARNING_CONFIG_FAILED;
718e3744 5716
d62a17ae 5717 /* Check filter direction. */
5718 if (strncmp(direct_str, "in", 2) == 0)
5719 direct = RMAP_IN;
5720 else if (strncmp(direct_str, "o", 1) == 0)
5721 direct = RMAP_OUT;
718e3744 5722
d62a17ae 5723 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5724
d62a17ae 5725 return bgp_vty_return(vty, ret);
718e3744 5726}
5727
5728DEFUN (neighbor_route_map,
5729 neighbor_route_map_cmd,
9ccf14f7 5730 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5731 NEIGHBOR_STR
5732 NEIGHBOR_ADDR_STR2
5733 "Apply route map to neighbor\n"
5734 "Name of route map\n"
5735 "Apply map to incoming routes\n"
2a3d5731 5736 "Apply map to outbound routes\n")
718e3744 5737{
d62a17ae 5738 int idx_peer = 1;
5739 int idx_word = 3;
5740 int idx_in_out = 4;
5741 return peer_route_map_set_vty(
5742 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5743 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5744}
5745
d62a17ae 5746ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5747 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5748 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5749 "Apply route map to neighbor\n"
5750 "Name of route map\n"
5751 "Apply map to incoming routes\n"
5752 "Apply map to outbound routes\n")
596c17ba 5753
718e3744 5754DEFUN (no_neighbor_route_map,
5755 no_neighbor_route_map_cmd,
9ccf14f7 5756 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5757 NO_STR
5758 NEIGHBOR_STR
5759 NEIGHBOR_ADDR_STR2
5760 "Apply route map to neighbor\n"
5761 "Name of route map\n"
5762 "Apply map to incoming routes\n"
2a3d5731 5763 "Apply map to outbound routes\n")
718e3744 5764{
d62a17ae 5765 int idx_peer = 2;
5766 int idx_in_out = 5;
5767 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5768 bgp_node_afi(vty), bgp_node_safi(vty),
5769 argv[idx_in_out]->arg);
718e3744 5770}
6b0655a2 5771
d62a17ae 5772ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5773 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5774 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5775 "Apply route map to neighbor\n"
5776 "Name of route map\n"
5777 "Apply map to incoming routes\n"
5778 "Apply map to outbound routes\n")
596c17ba 5779
718e3744 5780/* Set unsuppress-map to the peer. */
d62a17ae 5781static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5782 afi_t afi, safi_t safi,
5783 const char *name_str)
718e3744 5784{
d62a17ae 5785 int ret;
5786 struct peer *peer;
1de27621 5787 struct route_map *route_map;
718e3744 5788
d62a17ae 5789 peer = peer_and_group_lookup_vty(vty, ip_str);
5790 if (!peer)
5791 return CMD_WARNING_CONFIG_FAILED;
718e3744 5792
1de27621
DA
5793 route_map = route_map_lookup_warn_noexist(vty, name_str);
5794 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 5795
d62a17ae 5796 return bgp_vty_return(vty, ret);
718e3744 5797}
5798
5799/* Unset route-map from the peer. */
d62a17ae 5800static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5801 afi_t afi, safi_t safi)
718e3744 5802{
d62a17ae 5803 int ret;
5804 struct peer *peer;
718e3744 5805
d62a17ae 5806 peer = peer_and_group_lookup_vty(vty, ip_str);
5807 if (!peer)
5808 return CMD_WARNING_CONFIG_FAILED;
718e3744 5809
d62a17ae 5810 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5811
d62a17ae 5812 return bgp_vty_return(vty, ret);
718e3744 5813}
5814
5815DEFUN (neighbor_unsuppress_map,
5816 neighbor_unsuppress_map_cmd,
9ccf14f7 5817 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5818 NEIGHBOR_STR
5819 NEIGHBOR_ADDR_STR2
5820 "Route-map to selectively unsuppress suppressed routes\n"
5821 "Name of route map\n")
5822{
d62a17ae 5823 int idx_peer = 1;
5824 int idx_word = 3;
5825 return peer_unsuppress_map_set_vty(
5826 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5827 argv[idx_word]->arg);
718e3744 5828}
5829
d62a17ae 5830ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5831 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5832 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5833 "Route-map to selectively unsuppress suppressed routes\n"
5834 "Name of route map\n")
596c17ba 5835
718e3744 5836DEFUN (no_neighbor_unsuppress_map,
5837 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5838 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5839 NO_STR
5840 NEIGHBOR_STR
5841 NEIGHBOR_ADDR_STR2
5842 "Route-map to selectively unsuppress suppressed routes\n"
5843 "Name of route map\n")
5844{
d62a17ae 5845 int idx_peer = 2;
5846 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5847 bgp_node_afi(vty),
5848 bgp_node_safi(vty));
718e3744 5849}
6b0655a2 5850
d62a17ae 5851ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5852 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5853 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5854 "Route-map to selectively unsuppress suppressed routes\n"
5855 "Name of route map\n")
596c17ba 5856
d62a17ae 5857static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5858 afi_t afi, safi_t safi,
5859 const char *num_str,
5860 const char *threshold_str, int warning,
5861 const char *restart_str)
718e3744 5862{
d62a17ae 5863 int ret;
5864 struct peer *peer;
d7c0a89a
QY
5865 uint32_t max;
5866 uint8_t threshold;
5867 uint16_t restart;
718e3744 5868
d62a17ae 5869 peer = peer_and_group_lookup_vty(vty, ip_str);
5870 if (!peer)
5871 return CMD_WARNING_CONFIG_FAILED;
718e3744 5872
d62a17ae 5873 max = strtoul(num_str, NULL, 10);
5874 if (threshold_str)
5875 threshold = atoi(threshold_str);
5876 else
5877 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5878
d62a17ae 5879 if (restart_str)
5880 restart = atoi(restart_str);
5881 else
5882 restart = 0;
0a486e5f 5883
d62a17ae 5884 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5885 restart);
718e3744 5886
d62a17ae 5887 return bgp_vty_return(vty, ret);
718e3744 5888}
5889
d62a17ae 5890static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5891 afi_t afi, safi_t safi)
718e3744 5892{
d62a17ae 5893 int ret;
5894 struct peer *peer;
718e3744 5895
d62a17ae 5896 peer = peer_and_group_lookup_vty(vty, ip_str);
5897 if (!peer)
5898 return CMD_WARNING_CONFIG_FAILED;
718e3744 5899
d62a17ae 5900 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5901
d62a17ae 5902 return bgp_vty_return(vty, ret);
718e3744 5903}
5904
5905/* Maximum number of prefix configuration. prefix count is different
5906 for each peer configuration. So this configuration can be set for
5907 each peer configuration. */
5908DEFUN (neighbor_maximum_prefix,
5909 neighbor_maximum_prefix_cmd,
9ccf14f7 5910 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5911 NEIGHBOR_STR
5912 NEIGHBOR_ADDR_STR2
5913 "Maximum number of prefix accept from this peer\n"
5914 "maximum no. of prefix limit\n")
5915{
d62a17ae 5916 int idx_peer = 1;
5917 int idx_number = 3;
5918 return peer_maximum_prefix_set_vty(
5919 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5920 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5921}
5922
d62a17ae 5923ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5924 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5925 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5926 "Maximum number of prefix accept from this peer\n"
5927 "maximum no. of prefix limit\n")
596c17ba 5928
e0701b79 5929DEFUN (neighbor_maximum_prefix_threshold,
5930 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5931 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5932 NEIGHBOR_STR
5933 NEIGHBOR_ADDR_STR2
5934 "Maximum number of prefix accept from this peer\n"
5935 "maximum no. of prefix limit\n"
5936 "Threshold value (%) at which to generate a warning msg\n")
5937{
d62a17ae 5938 int idx_peer = 1;
5939 int idx_number = 3;
5940 int idx_number_2 = 4;
5941 return peer_maximum_prefix_set_vty(
5942 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5943 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5944}
e0701b79 5945
d62a17ae 5946ALIAS_HIDDEN(
5947 neighbor_maximum_prefix_threshold,
5948 neighbor_maximum_prefix_threshold_hidden_cmd,
5949 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5950 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5951 "Maximum number of prefix accept from this peer\n"
5952 "maximum no. of prefix limit\n"
5953 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5954
718e3744 5955DEFUN (neighbor_maximum_prefix_warning,
5956 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5957 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5958 NEIGHBOR_STR
5959 NEIGHBOR_ADDR_STR2
5960 "Maximum number of prefix accept from this peer\n"
5961 "maximum no. of prefix limit\n"
5962 "Only give warning message when limit is exceeded\n")
5963{
d62a17ae 5964 int idx_peer = 1;
5965 int idx_number = 3;
5966 return peer_maximum_prefix_set_vty(
5967 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5968 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5969}
5970
d62a17ae 5971ALIAS_HIDDEN(
5972 neighbor_maximum_prefix_warning,
5973 neighbor_maximum_prefix_warning_hidden_cmd,
5974 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5975 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5976 "Maximum number of prefix accept from this peer\n"
5977 "maximum no. of prefix limit\n"
5978 "Only give warning message when limit is exceeded\n")
596c17ba 5979
e0701b79 5980DEFUN (neighbor_maximum_prefix_threshold_warning,
5981 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5982 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5983 NEIGHBOR_STR
5984 NEIGHBOR_ADDR_STR2
5985 "Maximum number of prefix accept from this peer\n"
5986 "maximum no. of prefix limit\n"
5987 "Threshold value (%) at which to generate a warning msg\n"
5988 "Only give warning message when limit is exceeded\n")
5989{
d62a17ae 5990 int idx_peer = 1;
5991 int idx_number = 3;
5992 int idx_number_2 = 4;
5993 return peer_maximum_prefix_set_vty(
5994 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5995 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5996}
5997
d62a17ae 5998ALIAS_HIDDEN(
5999 neighbor_maximum_prefix_threshold_warning,
6000 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6001 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6002 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6003 "Maximum number of prefix accept from this peer\n"
6004 "maximum no. of prefix limit\n"
6005 "Threshold value (%) at which to generate a warning msg\n"
6006 "Only give warning message when limit is exceeded\n")
596c17ba 6007
0a486e5f 6008DEFUN (neighbor_maximum_prefix_restart,
6009 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 6010 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 6011 NEIGHBOR_STR
6012 NEIGHBOR_ADDR_STR2
6013 "Maximum number of prefix accept from this peer\n"
6014 "maximum no. of prefix limit\n"
6015 "Restart bgp connection after limit is exceeded\n"
efd7904e 6016 "Restart interval in minutes\n")
0a486e5f 6017{
d62a17ae 6018 int idx_peer = 1;
6019 int idx_number = 3;
6020 int idx_number_2 = 5;
6021 return peer_maximum_prefix_set_vty(
6022 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6023 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 6024}
6025
d62a17ae 6026ALIAS_HIDDEN(
6027 neighbor_maximum_prefix_restart,
6028 neighbor_maximum_prefix_restart_hidden_cmd,
6029 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6030 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6031 "Maximum number of prefix accept from this peer\n"
6032 "maximum no. of prefix limit\n"
6033 "Restart bgp connection after limit is exceeded\n"
efd7904e 6034 "Restart interval in minutes\n")
596c17ba 6035
0a486e5f 6036DEFUN (neighbor_maximum_prefix_threshold_restart,
6037 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 6038 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 6039 NEIGHBOR_STR
6040 NEIGHBOR_ADDR_STR2
16cedbb0 6041 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 6042 "maximum no. of prefix limit\n"
6043 "Threshold value (%) at which to generate a warning msg\n"
6044 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6045 "Restart interval in minutes\n")
0a486e5f 6046{
d62a17ae 6047 int idx_peer = 1;
6048 int idx_number = 3;
6049 int idx_number_2 = 4;
6050 int idx_number_3 = 6;
6051 return peer_maximum_prefix_set_vty(
6052 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6053 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6054 argv[idx_number_3]->arg);
6055}
6056
6057ALIAS_HIDDEN(
6058 neighbor_maximum_prefix_threshold_restart,
6059 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6060 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6061 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6062 "Maximum number of prefixes to accept from this peer\n"
6063 "maximum no. of prefix limit\n"
6064 "Threshold value (%) at which to generate a warning msg\n"
6065 "Restart bgp connection after limit is exceeded\n"
6066 "Restart interval in minutes\n")
596c17ba 6067
718e3744 6068DEFUN (no_neighbor_maximum_prefix,
6069 no_neighbor_maximum_prefix_cmd,
d04c479d 6070 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 6071 NO_STR
6072 NEIGHBOR_STR
6073 NEIGHBOR_ADDR_STR2
16cedbb0 6074 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
6075 "maximum no. of prefix limit\n"
6076 "Threshold value (%) at which to generate a warning msg\n"
6077 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6078 "Restart interval in minutes\n"
31500417 6079 "Only give warning message when limit is exceeded\n")
718e3744 6080{
d62a17ae 6081 int idx_peer = 2;
6082 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6083 bgp_node_afi(vty),
6084 bgp_node_safi(vty));
718e3744 6085}
e52702f2 6086
d62a17ae 6087ALIAS_HIDDEN(
6088 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6089 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6090 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6091 "Maximum number of prefixes to accept from this peer\n"
6092 "maximum no. of prefix limit\n"
6093 "Threshold value (%) at which to generate a warning msg\n"
6094 "Restart bgp connection after limit is exceeded\n"
6095 "Restart interval in minutes\n"
6096 "Only give warning message when limit is exceeded\n")
596c17ba 6097
718e3744 6098
718e3744 6099/* "neighbor allowas-in" */
6100DEFUN (neighbor_allowas_in,
6101 neighbor_allowas_in_cmd,
fd8503f5 6102 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6103 NEIGHBOR_STR
6104 NEIGHBOR_ADDR_STR2
31500417 6105 "Accept as-path with my AS present in it\n"
0437e105 6106 "Number of occurences of AS number\n"
fd8503f5 6107 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6108{
d62a17ae 6109 int idx_peer = 1;
6110 int idx_number_origin = 3;
6111 int ret;
6112 int origin = 0;
6113 struct peer *peer;
6114 int allow_num = 0;
6115
6116 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6117 if (!peer)
6118 return CMD_WARNING_CONFIG_FAILED;
6119
6120 if (argc <= idx_number_origin)
6121 allow_num = 3;
6122 else {
6123 if (argv[idx_number_origin]->type == WORD_TKN)
6124 origin = 1;
6125 else
6126 allow_num = atoi(argv[idx_number_origin]->arg);
6127 }
6128
6129 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6130 allow_num, origin);
6131
6132 return bgp_vty_return(vty, ret);
6133}
6134
6135ALIAS_HIDDEN(
6136 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6137 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6138 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6139 "Accept as-path with my AS present in it\n"
0437e105 6140 "Number of occurences of AS number\n"
d62a17ae 6141 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6142
718e3744 6143DEFUN (no_neighbor_allowas_in,
6144 no_neighbor_allowas_in_cmd,
fd8503f5 6145 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6146 NO_STR
6147 NEIGHBOR_STR
6148 NEIGHBOR_ADDR_STR2
8334fd5a 6149 "allow local ASN appears in aspath attribute\n"
0437e105 6150 "Number of occurences of AS number\n"
fd8503f5 6151 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6152{
d62a17ae 6153 int idx_peer = 2;
6154 int ret;
6155 struct peer *peer;
718e3744 6156
d62a17ae 6157 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6158 if (!peer)
6159 return CMD_WARNING_CONFIG_FAILED;
718e3744 6160
d62a17ae 6161 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6162 bgp_node_safi(vty));
718e3744 6163
d62a17ae 6164 return bgp_vty_return(vty, ret);
718e3744 6165}
6b0655a2 6166
d62a17ae 6167ALIAS_HIDDEN(
6168 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6169 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6170 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6171 "allow local ASN appears in aspath attribute\n"
0437e105 6172 "Number of occurences of AS number\n"
d62a17ae 6173 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6174
fa411a21
NH
6175DEFUN (neighbor_ttl_security,
6176 neighbor_ttl_security_cmd,
7ebe625c 6177 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6178 NEIGHBOR_STR
7ebe625c 6179 NEIGHBOR_ADDR_STR2
16cedbb0 6180 "BGP ttl-security parameters\n"
d7fa34c1
QY
6181 "Specify the maximum number of hops to the BGP peer\n"
6182 "Number of hops to BGP peer\n")
fa411a21 6183{
d62a17ae 6184 int idx_peer = 1;
6185 int idx_number = 4;
6186 struct peer *peer;
6187 int gtsm_hops;
6188
6189 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6190 if (!peer)
6191 return CMD_WARNING_CONFIG_FAILED;
6192
6193 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6194
7ebe625c
QY
6195 /*
6196 * If 'neighbor swpX', then this is for directly connected peers,
6197 * we should not accept a ttl-security hops value greater than 1.
6198 */
6199 if (peer->conf_if && (gtsm_hops > 1)) {
6200 vty_out(vty,
6201 "%s is directly connected peer, hops cannot exceed 1\n",
6202 argv[idx_peer]->arg);
6203 return CMD_WARNING_CONFIG_FAILED;
6204 }
6205
d62a17ae 6206 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6207}
6208
6209DEFUN (no_neighbor_ttl_security,
6210 no_neighbor_ttl_security_cmd,
7ebe625c 6211 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6212 NO_STR
6213 NEIGHBOR_STR
7ebe625c 6214 NEIGHBOR_ADDR_STR2
16cedbb0 6215 "BGP ttl-security parameters\n"
3a2d747c
QY
6216 "Specify the maximum number of hops to the BGP peer\n"
6217 "Number of hops to BGP peer\n")
fa411a21 6218{
d62a17ae 6219 int idx_peer = 2;
6220 struct peer *peer;
fa411a21 6221
d62a17ae 6222 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6223 if (!peer)
6224 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6225
d62a17ae 6226 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6227}
6b0655a2 6228
adbac85e
DW
6229DEFUN (neighbor_addpath_tx_all_paths,
6230 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6231 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6232 NEIGHBOR_STR
6233 NEIGHBOR_ADDR_STR2
6234 "Use addpath to advertise all paths to a neighbor\n")
6235{
d62a17ae 6236 int idx_peer = 1;
6237 struct peer *peer;
adbac85e 6238
d62a17ae 6239 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6240 if (!peer)
6241 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6242
dcc68b5e
MS
6243 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6244 BGP_ADDPATH_ALL);
6245 return CMD_SUCCESS;
adbac85e
DW
6246}
6247
d62a17ae 6248ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6249 neighbor_addpath_tx_all_paths_hidden_cmd,
6250 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6251 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6252 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6253
adbac85e
DW
6254DEFUN (no_neighbor_addpath_tx_all_paths,
6255 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6256 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6257 NO_STR
6258 NEIGHBOR_STR
6259 NEIGHBOR_ADDR_STR2
6260 "Use addpath to advertise all paths to a neighbor\n")
6261{
d62a17ae 6262 int idx_peer = 2;
dcc68b5e
MS
6263 struct peer *peer;
6264
6265 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6266 if (!peer)
6267 return CMD_WARNING_CONFIG_FAILED;
6268
6269 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6270 != BGP_ADDPATH_ALL) {
6271 vty_out(vty,
6272 "%% Peer not currently configured to transmit all paths.");
6273 return CMD_WARNING_CONFIG_FAILED;
6274 }
6275
6276 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6277 BGP_ADDPATH_NONE);
6278
6279 return CMD_SUCCESS;
adbac85e
DW
6280}
6281
d62a17ae 6282ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6283 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6284 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6285 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6286 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6287
06370dac
DW
6288DEFUN (neighbor_addpath_tx_bestpath_per_as,
6289 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6290 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6291 NEIGHBOR_STR
6292 NEIGHBOR_ADDR_STR2
6293 "Use addpath to advertise the bestpath per each neighboring AS\n")
6294{
d62a17ae 6295 int idx_peer = 1;
6296 struct peer *peer;
06370dac 6297
d62a17ae 6298 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6299 if (!peer)
6300 return CMD_WARNING_CONFIG_FAILED;
06370dac 6301
dcc68b5e
MS
6302 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6303 BGP_ADDPATH_BEST_PER_AS);
6304
6305 return CMD_SUCCESS;
06370dac
DW
6306}
6307
d62a17ae 6308ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6309 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6310 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6311 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6312 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6313
06370dac
DW
6314DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6315 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6316 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6317 NO_STR
6318 NEIGHBOR_STR
6319 NEIGHBOR_ADDR_STR2
6320 "Use addpath to advertise the bestpath per each neighboring AS\n")
6321{
d62a17ae 6322 int idx_peer = 2;
dcc68b5e
MS
6323 struct peer *peer;
6324
6325 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6326 if (!peer)
6327 return CMD_WARNING_CONFIG_FAILED;
6328
6329 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6330 != BGP_ADDPATH_BEST_PER_AS) {
6331 vty_out(vty,
6332 "%% Peer not currently configured to transmit all best path per as.");
6333 return CMD_WARNING_CONFIG_FAILED;
6334 }
6335
6336 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6337 BGP_ADDPATH_NONE);
6338
6339 return CMD_SUCCESS;
06370dac
DW
6340}
6341
d62a17ae 6342ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6343 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6344 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6345 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6346 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6347
b9c7bc5a
PZ
6348static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6349 struct ecommunity **list)
ddb5b488 6350{
b9c7bc5a
PZ
6351 struct ecommunity *ecom = NULL;
6352 struct ecommunity *ecomadd;
ddb5b488 6353
b9c7bc5a 6354 for (; argc; --argc, ++argv) {
ddb5b488 6355
b9c7bc5a
PZ
6356 ecomadd = ecommunity_str2com(argv[0]->arg,
6357 ECOMMUNITY_ROUTE_TARGET, 0);
6358 if (!ecomadd) {
6359 vty_out(vty, "Malformed community-list value\n");
6360 if (ecom)
6361 ecommunity_free(&ecom);
6362 return CMD_WARNING_CONFIG_FAILED;
6363 }
ddb5b488 6364
b9c7bc5a
PZ
6365 if (ecom) {
6366 ecommunity_merge(ecom, ecomadd);
6367 ecommunity_free(&ecomadd);
6368 } else {
6369 ecom = ecomadd;
6370 }
6371 }
6372
6373 if (*list) {
6374 ecommunity_free(&*list);
ddb5b488 6375 }
b9c7bc5a
PZ
6376 *list = ecom;
6377
6378 return CMD_SUCCESS;
ddb5b488
PZ
6379}
6380
0ca70ba5
DS
6381/*
6382 * v2vimport is true if we are handling a `import vrf ...` command
6383 */
6384static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6385{
0ca70ba5
DS
6386 afi_t afi;
6387
ddb5b488 6388 switch (vty->node) {
b9c7bc5a 6389 case BGP_IPV4_NODE:
0ca70ba5
DS
6390 afi = AFI_IP;
6391 break;
b9c7bc5a 6392 case BGP_IPV6_NODE:
0ca70ba5
DS
6393 afi = AFI_IP6;
6394 break;
ddb5b488
PZ
6395 default:
6396 vty_out(vty,
b9c7bc5a 6397 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6398 return AFI_MAX;
ddb5b488 6399 }
69b07479 6400
0ca70ba5
DS
6401 if (!v2vimport) {
6402 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6403 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6404 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6405 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6406 vty_out(vty,
6407 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6408 return AFI_MAX;
6409 }
6410 } else {
6411 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6412 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6413 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6414 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6415 vty_out(vty,
6416 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6417 return AFI_MAX;
6418 }
6419 }
6420 return afi;
ddb5b488
PZ
6421}
6422
b9c7bc5a
PZ
6423DEFPY (af_rd_vpn_export,
6424 af_rd_vpn_export_cmd,
6425 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6426 NO_STR
ddb5b488 6427 "Specify route distinguisher\n"
b9c7bc5a
PZ
6428 "Between current address-family and vpn\n"
6429 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6430 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6431{
6432 VTY_DECLVAR_CONTEXT(bgp, bgp);
6433 struct prefix_rd prd;
6434 int ret;
ddb5b488 6435 afi_t afi;
b9c7bc5a
PZ
6436 int idx = 0;
6437 int yes = 1;
ddb5b488 6438
b9c7bc5a 6439 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6440 yes = 0;
b9c7bc5a
PZ
6441
6442 if (yes) {
6443 ret = str2prefix_rd(rd_str, &prd);
6444 if (!ret) {
6445 vty_out(vty, "%% Malformed rd\n");
6446 return CMD_WARNING_CONFIG_FAILED;
6447 }
ddb5b488
PZ
6448 }
6449
0ca70ba5 6450 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6451 if (afi == AFI_MAX)
6452 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6453
69b07479
DS
6454 /*
6455 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6456 */
6457 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6458 bgp_get_default(), bgp);
ddb5b488 6459
69b07479
DS
6460 if (yes) {
6461 bgp->vpn_policy[afi].tovpn_rd = prd;
6462 SET_FLAG(bgp->vpn_policy[afi].flags,
6463 BGP_VPN_POLICY_TOVPN_RD_SET);
6464 } else {
6465 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6466 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6467 }
6468
69b07479
DS
6469 /* post-change: re-export vpn routes */
6470 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6471 bgp_get_default(), bgp);
6472
ddb5b488
PZ
6473 return CMD_SUCCESS;
6474}
6475
b9c7bc5a
PZ
6476ALIAS (af_rd_vpn_export,
6477 af_no_rd_vpn_export_cmd,
6478 "no rd vpn export",
ddb5b488 6479 NO_STR
b9c7bc5a
PZ
6480 "Specify route distinguisher\n"
6481 "Between current address-family and vpn\n"
6482 "For routes leaked from current address-family to vpn\n")
ddb5b488 6483
b9c7bc5a
PZ
6484DEFPY (af_label_vpn_export,
6485 af_label_vpn_export_cmd,
e70e9f8e 6486 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6487 NO_STR
ddb5b488 6488 "label value for VRF\n"
b9c7bc5a
PZ
6489 "Between current address-family and vpn\n"
6490 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6491 "Label Value <0-1048575>\n"
6492 "Automatically assign a label\n")
ddb5b488
PZ
6493{
6494 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6495 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6496 afi_t afi;
b9c7bc5a
PZ
6497 int idx = 0;
6498 int yes = 1;
6499
6500 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6501 yes = 0;
ddb5b488 6502
21a16cc2
PZ
6503 /* If "no ...", squash trailing parameter */
6504 if (!yes)
6505 label_auto = NULL;
6506
e70e9f8e
PZ
6507 if (yes) {
6508 if (!label_auto)
6509 label = label_val; /* parser should force unsigned */
6510 }
ddb5b488 6511
0ca70ba5 6512 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6513 if (afi == AFI_MAX)
6514 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6515
e70e9f8e 6516
69b07479
DS
6517 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6518 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6519 /* no change */
6520 return CMD_SUCCESS;
e70e9f8e 6521
69b07479
DS
6522 /*
6523 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6524 */
6525 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6526 bgp_get_default(), bgp);
6527
6528 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6529 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6530
6531 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6532
6533 /*
6534 * label has previously been automatically
6535 * assigned by labelpool: release it
6536 *
6537 * NB if tovpn_label == MPLS_LABEL_NONE it
6538 * means the automatic assignment is in flight
6539 * and therefore the labelpool callback must
6540 * detect that the auto label is not needed.
6541 */
6542
6543 bgp_lp_release(LP_TYPE_VRF,
6544 &bgp->vpn_policy[afi],
6545 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6546 }
69b07479
DS
6547 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6548 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6549 }
ddb5b488 6550
69b07479
DS
6551 bgp->vpn_policy[afi].tovpn_label = label;
6552 if (label_auto) {
6553 SET_FLAG(bgp->vpn_policy[afi].flags,
6554 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6555 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6556 vpn_leak_label_callback);
ddb5b488
PZ
6557 }
6558
69b07479
DS
6559 /* post-change: re-export vpn routes */
6560 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6561 bgp_get_default(), bgp);
6562
ddb5b488
PZ
6563 return CMD_SUCCESS;
6564}
6565
b9c7bc5a
PZ
6566ALIAS (af_label_vpn_export,
6567 af_no_label_vpn_export_cmd,
6568 "no label vpn export",
6569 NO_STR
6570 "label value for VRF\n"
6571 "Between current address-family and vpn\n"
6572 "For routes leaked from current address-family to vpn\n")
ddb5b488 6573
b9c7bc5a
PZ
6574DEFPY (af_nexthop_vpn_export,
6575 af_nexthop_vpn_export_cmd,
6576 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6577 NO_STR
ddb5b488 6578 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6579 "Between current address-family and vpn\n"
6580 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6581 "IPv4 prefix\n"
6582 "IPv6 prefix\n")
6583{
6584 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6585 afi_t afi;
ddb5b488 6586 struct prefix p;
b9c7bc5a
PZ
6587 int idx = 0;
6588 int yes = 1;
ddb5b488 6589
b9c7bc5a 6590 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6591 yes = 0;
b9c7bc5a
PZ
6592
6593 if (yes) {
6594 if (!sockunion2hostprefix(nexthop_str, &p))
6595 return CMD_WARNING_CONFIG_FAILED;
6596 }
ddb5b488 6597
0ca70ba5 6598 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6599 if (afi == AFI_MAX)
6600 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6601
69b07479
DS
6602 /*
6603 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6604 */
6605 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6606 bgp_get_default(), bgp);
ddb5b488 6607
69b07479
DS
6608 if (yes) {
6609 bgp->vpn_policy[afi].tovpn_nexthop = p;
6610 SET_FLAG(bgp->vpn_policy[afi].flags,
6611 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6612 } else {
6613 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6614 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6615 }
6616
69b07479
DS
6617 /* post-change: re-export vpn routes */
6618 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6619 bgp_get_default(), bgp);
6620
ddb5b488
PZ
6621 return CMD_SUCCESS;
6622}
6623
b9c7bc5a
PZ
6624ALIAS (af_nexthop_vpn_export,
6625 af_no_nexthop_vpn_export_cmd,
6626 "no nexthop vpn export",
ddb5b488 6627 NO_STR
b9c7bc5a
PZ
6628 "Specify next hop to use for VRF advertised prefixes\n"
6629 "Between current address-family and vpn\n"
6630 "For routes leaked from current address-family to vpn\n")
ddb5b488 6631
b9c7bc5a 6632static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6633{
b9c7bc5a
PZ
6634 if (!strcmp(dstr, "import")) {
6635 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6636 } else if (!strcmp(dstr, "export")) {
6637 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6638 } else if (!strcmp(dstr, "both")) {
6639 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6640 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6641 } else {
6642 vty_out(vty, "%% direction parse error\n");
6643 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6644 }
ddb5b488
PZ
6645 return CMD_SUCCESS;
6646}
6647
b9c7bc5a
PZ
6648DEFPY (af_rt_vpn_imexport,
6649 af_rt_vpn_imexport_cmd,
6650 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6651 NO_STR
6652 "Specify route target list\n"
ddb5b488 6653 "Specify route target list\n"
b9c7bc5a
PZ
6654 "Between current address-family and vpn\n"
6655 "For routes leaked from vpn to current address-family: match any\n"
6656 "For routes leaked from current address-family to vpn: set\n"
6657 "both import: match any and export: set\n"
ddb5b488
PZ
6658 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6659{
6660 VTY_DECLVAR_CONTEXT(bgp, bgp);
6661 int ret;
6662 struct ecommunity *ecom = NULL;
6663 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6664 vpn_policy_direction_t dir;
6665 afi_t afi;
6666 int idx = 0;
b9c7bc5a 6667 int yes = 1;
ddb5b488 6668
b9c7bc5a 6669 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6670 yes = 0;
b9c7bc5a 6671
0ca70ba5 6672 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6673 if (afi == AFI_MAX)
6674 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6675
b9c7bc5a 6676 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6677 if (ret != CMD_SUCCESS)
6678 return ret;
6679
b9c7bc5a
PZ
6680 if (yes) {
6681 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6682 vty_out(vty, "%% Missing RTLIST\n");
6683 return CMD_WARNING_CONFIG_FAILED;
6684 }
6685 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6686 if (ret != CMD_SUCCESS) {
6687 return ret;
6688 }
ddb5b488
PZ
6689 }
6690
69b07479
DS
6691 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6692 if (!dodir[dir])
ddb5b488 6693 continue;
ddb5b488 6694
69b07479 6695 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6696
69b07479
DS
6697 if (yes) {
6698 if (bgp->vpn_policy[afi].rtlist[dir])
6699 ecommunity_free(
6700 &bgp->vpn_policy[afi].rtlist[dir]);
6701 bgp->vpn_policy[afi].rtlist[dir] =
6702 ecommunity_dup(ecom);
6703 } else {
6704 if (bgp->vpn_policy[afi].rtlist[dir])
6705 ecommunity_free(
6706 &bgp->vpn_policy[afi].rtlist[dir]);
6707 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6708 }
69b07479
DS
6709
6710 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6711 }
69b07479 6712
d555f3e9
PZ
6713 if (ecom)
6714 ecommunity_free(&ecom);
ddb5b488
PZ
6715
6716 return CMD_SUCCESS;
6717}
6718
b9c7bc5a
PZ
6719ALIAS (af_rt_vpn_imexport,
6720 af_no_rt_vpn_imexport_cmd,
6721 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6722 NO_STR
6723 "Specify route target list\n"
b9c7bc5a
PZ
6724 "Specify route target list\n"
6725 "Between current address-family and vpn\n"
6726 "For routes leaked from vpn to current address-family\n"
6727 "For routes leaked from current address-family to vpn\n"
6728 "both import and export\n")
6729
6730DEFPY (af_route_map_vpn_imexport,
6731 af_route_map_vpn_imexport_cmd,
6732/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6733 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6734 NO_STR
ddb5b488 6735 "Specify route map\n"
b9c7bc5a
PZ
6736 "Between current address-family and vpn\n"
6737 "For routes leaked from vpn to current address-family\n"
6738 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6739 "name of route-map\n")
6740{
6741 VTY_DECLVAR_CONTEXT(bgp, bgp);
6742 int ret;
6743 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6744 vpn_policy_direction_t dir;
6745 afi_t afi;
ddb5b488 6746 int idx = 0;
b9c7bc5a 6747 int yes = 1;
ddb5b488 6748
b9c7bc5a 6749 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6750 yes = 0;
b9c7bc5a 6751
0ca70ba5 6752 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6753 if (afi == AFI_MAX)
6754 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6755
b9c7bc5a 6756 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6757 if (ret != CMD_SUCCESS)
6758 return ret;
6759
69b07479
DS
6760 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6761 if (!dodir[dir])
ddb5b488 6762 continue;
ddb5b488 6763
69b07479 6764 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6765
69b07479
DS
6766 if (yes) {
6767 if (bgp->vpn_policy[afi].rmap_name[dir])
6768 XFREE(MTYPE_ROUTE_MAP_NAME,
6769 bgp->vpn_policy[afi].rmap_name[dir]);
6770 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6771 MTYPE_ROUTE_MAP_NAME, rmap_str);
6772 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6773 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6774 if (!bgp->vpn_policy[afi].rmap[dir])
6775 return CMD_SUCCESS;
6776 } else {
6777 if (bgp->vpn_policy[afi].rmap_name[dir])
6778 XFREE(MTYPE_ROUTE_MAP_NAME,
6779 bgp->vpn_policy[afi].rmap_name[dir]);
6780 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6781 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6782 }
69b07479
DS
6783
6784 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6785 }
6786
6787 return CMD_SUCCESS;
6788}
6789
b9c7bc5a
PZ
6790ALIAS (af_route_map_vpn_imexport,
6791 af_no_route_map_vpn_imexport_cmd,
6792 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6793 NO_STR
6794 "Specify route map\n"
b9c7bc5a
PZ
6795 "Between current address-family and vpn\n"
6796 "For routes leaked from vpn to current address-family\n"
6797 "For routes leaked from current address-family to vpn\n")
6798
bb4f6190
DS
6799DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6800 "[no] import vrf route-map RMAP$rmap_str",
6801 NO_STR
6802 "Import routes from another VRF\n"
6803 "Vrf routes being filtered\n"
6804 "Specify route map\n"
6805 "name of route-map\n")
6806{
6807 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6808 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6809 afi_t afi;
6810 int idx = 0;
6811 int yes = 1;
6812 struct bgp *bgp_default;
6813
6814 if (argv_find(argv, argc, "no", &idx))
6815 yes = 0;
6816
0ca70ba5 6817 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6818 if (afi == AFI_MAX)
6819 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6820
6821 bgp_default = bgp_get_default();
6822 if (!bgp_default) {
6823 int32_t ret;
6824 as_t as = bgp->as;
6825
6826 /* Auto-create assuming the same AS */
6827 ret = bgp_get(&bgp_default, &as, NULL,
6828 BGP_INSTANCE_TYPE_DEFAULT);
6829
6830 if (ret) {
6831 vty_out(vty,
6832 "VRF default is not configured as a bgp instance\n");
6833 return CMD_WARNING;
6834 }
6835 }
6836
69b07479 6837 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6838
69b07479
DS
6839 if (yes) {
6840 if (bgp->vpn_policy[afi].rmap_name[dir])
6841 XFREE(MTYPE_ROUTE_MAP_NAME,
6842 bgp->vpn_policy[afi].rmap_name[dir]);
6843 bgp->vpn_policy[afi].rmap_name[dir] =
6844 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6845 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6846 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6847 if (!bgp->vpn_policy[afi].rmap[dir])
6848 return CMD_SUCCESS;
6849 } else {
6850 if (bgp->vpn_policy[afi].rmap_name[dir])
6851 XFREE(MTYPE_ROUTE_MAP_NAME,
6852 bgp->vpn_policy[afi].rmap_name[dir]);
6853 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6854 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6855 }
6856
69b07479
DS
6857 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6858
bb4f6190
DS
6859 return CMD_SUCCESS;
6860}
6861
6862ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6863 "no import vrf route-map",
6864 NO_STR
6865 "Import routes from another VRF\n"
6866 "Vrf routes being filtered\n"
6867 "Specify route map\n")
6868
4d1b335c
DA
6869DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6870 "[no] import vrf VIEWVRFNAME$import_name",
6871 NO_STR
6872 "Import routes from another VRF\n"
6873 "VRF to import from\n"
6874 "The name of the VRF\n")
12a844a5
DS
6875{
6876 VTY_DECLVAR_CONTEXT(bgp, bgp);
6877 struct listnode *node;
79ef8664
DS
6878 struct bgp *vrf_bgp, *bgp_default;
6879 int32_t ret = 0;
6880 as_t as = bgp->as;
12a844a5
DS
6881 bool remove = false;
6882 int32_t idx = 0;
6883 char *vname;
a8dadcf6 6884 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6885 safi_t safi;
6886 afi_t afi;
6887
867f0cca 6888 if (import_name == NULL) {
6889 vty_out(vty, "%% Missing import name\n");
6890 return CMD_WARNING;
6891 }
6892
12a844a5
DS
6893 if (argv_find(argv, argc, "no", &idx))
6894 remove = true;
6895
0ca70ba5
DS
6896 afi = vpn_policy_getafi(vty, bgp, true);
6897 if (afi == AFI_MAX)
6898 return CMD_WARNING_CONFIG_FAILED;
6899
12a844a5
DS
6900 safi = bgp_node_safi(vty);
6901
25679caa 6902 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 6903 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
6904 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6905 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6906 remove ? "unimport" : "import", import_name);
6907 return CMD_WARNING;
6908 }
6909
79ef8664
DS
6910 bgp_default = bgp_get_default();
6911 if (!bgp_default) {
6912 /* Auto-create assuming the same AS */
6913 ret = bgp_get(&bgp_default, &as, NULL,
6914 BGP_INSTANCE_TYPE_DEFAULT);
6915
6916 if (ret) {
6917 vty_out(vty,
6918 "VRF default is not configured as a bgp instance\n");
6919 return CMD_WARNING;
6920 }
6921 }
6922
12a844a5
DS
6923 vrf_bgp = bgp_lookup_by_name(import_name);
6924 if (!vrf_bgp) {
5742e42b 6925 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
6926 vrf_bgp = bgp_default;
6927 else
0fb8d6e6
DS
6928 /* Auto-create assuming the same AS */
6929 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6930
6e2c7fe6 6931 if (ret) {
020a3f60
DS
6932 vty_out(vty,
6933 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6934 import_name);
6935 return CMD_WARNING;
6936 }
12a844a5
DS
6937 }
6938
12a844a5 6939 if (remove) {
44338987 6940 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6941 } else {
44338987 6942 /* Already importing from "import_vrf"? */
12a844a5
DS
6943 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6944 vname)) {
6945 if (strcmp(vname, import_name) == 0)
6946 return CMD_WARNING;
6947 }
6948
44338987 6949 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6950 }
6951
6952 return CMD_SUCCESS;
6953}
6954
b9c7bc5a
PZ
6955/* This command is valid only in a bgp vrf instance or the default instance */
6956DEFPY (bgp_imexport_vpn,
6957 bgp_imexport_vpn_cmd,
6958 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6959 NO_STR
6960 "Import routes to this address-family\n"
6961 "Export routes from this address-family\n"
6962 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6963{
6964 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6965 int previous_state;
ddb5b488 6966 afi_t afi;
b9c7bc5a 6967 safi_t safi;
ddb5b488 6968 int idx = 0;
b9c7bc5a
PZ
6969 int yes = 1;
6970 int flag;
6971 vpn_policy_direction_t dir;
ddb5b488 6972
b9c7bc5a 6973 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6974 yes = 0;
ddb5b488 6975
b9c7bc5a
PZ
6976 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6977 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6978
b9c7bc5a
PZ
6979 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6980 return CMD_WARNING_CONFIG_FAILED;
6981 }
ddb5b488 6982
b9c7bc5a
PZ
6983 afi = bgp_node_afi(vty);
6984 safi = bgp_node_safi(vty);
6985 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6986 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6987 return CMD_WARNING_CONFIG_FAILED;
6988 }
ddb5b488 6989
b9c7bc5a
PZ
6990 if (!strcmp(direction_str, "import")) {
6991 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6992 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6993 } else if (!strcmp(direction_str, "export")) {
6994 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6995 dir = BGP_VPN_POLICY_DIR_TOVPN;
6996 } else {
6997 vty_out(vty, "%% unknown direction %s\n", direction_str);
6998 return CMD_WARNING_CONFIG_FAILED;
6999 }
7000
7001 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 7002
b9c7bc5a
PZ
7003 if (yes) {
7004 SET_FLAG(bgp->af_flags[afi][safi], flag);
7005 if (!previous_state) {
7006 /* trigger export current vrf */
ddb5b488
PZ
7007 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7008 }
b9c7bc5a
PZ
7009 } else {
7010 if (previous_state) {
7011 /* trigger un-export current vrf */
7012 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7013 }
7014 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
7015 }
7016
7017 return CMD_SUCCESS;
7018}
7019
301ad80a
PG
7020DEFPY (af_routetarget_import,
7021 af_routetarget_import_cmd,
7022 "[no] <rt|route-target> redirect import RTLIST...",
7023 NO_STR
7024 "Specify route target list\n"
7025 "Specify route target list\n"
7026 "Flow-spec redirect type route target\n"
7027 "Import routes to this address-family\n"
7028 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7029{
7030 VTY_DECLVAR_CONTEXT(bgp, bgp);
7031 int ret;
7032 struct ecommunity *ecom = NULL;
301ad80a
PG
7033 afi_t afi;
7034 int idx = 0;
7035 int yes = 1;
7036
7037 if (argv_find(argv, argc, "no", &idx))
7038 yes = 0;
7039
0ca70ba5 7040 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7041 if (afi == AFI_MAX)
7042 return CMD_WARNING_CONFIG_FAILED;
7043
301ad80a
PG
7044 if (yes) {
7045 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7046 vty_out(vty, "%% Missing RTLIST\n");
7047 return CMD_WARNING_CONFIG_FAILED;
7048 }
7049 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7050 if (ret != CMD_SUCCESS)
7051 return ret;
7052 }
69b07479
DS
7053
7054 if (yes) {
7055 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7056 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7057 .import_redirect_rtlist);
69b07479
DS
7058 bgp->vpn_policy[afi].import_redirect_rtlist =
7059 ecommunity_dup(ecom);
7060 } else {
7061 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7062 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7063 .import_redirect_rtlist);
69b07479 7064 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 7065 }
69b07479 7066
301ad80a
PG
7067 if (ecom)
7068 ecommunity_free(&ecom);
7069
7070 return CMD_SUCCESS;
7071}
7072
505e5056 7073DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 7074 address_family_ipv4_safi_cmd,
7075 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7076 "Enter Address Family command mode\n"
7077 "Address Family\n"
7078 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 7079{
f51bae9c 7080
d62a17ae 7081 if (argc == 3) {
2131d5cf 7082 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7083 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7084 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7085 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7086 && safi != SAFI_EVPN) {
31947174
MK
7087 vty_out(vty,
7088 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7089 return CMD_WARNING_CONFIG_FAILED;
7090 }
d62a17ae 7091 vty->node = bgp_node_type(AFI_IP, safi);
7092 } else
7093 vty->node = BGP_IPV4_NODE;
718e3744 7094
d62a17ae 7095 return CMD_SUCCESS;
718e3744 7096}
7097
505e5056 7098DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 7099 address_family_ipv6_safi_cmd,
7100 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7101 "Enter Address Family command mode\n"
7102 "Address Family\n"
7103 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 7104{
d62a17ae 7105 if (argc == 3) {
2131d5cf 7106 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7107 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7108 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7109 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7110 && safi != SAFI_EVPN) {
31947174
MK
7111 vty_out(vty,
7112 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7113 return CMD_WARNING_CONFIG_FAILED;
7114 }
d62a17ae 7115 vty->node = bgp_node_type(AFI_IP6, safi);
7116 } else
7117 vty->node = BGP_IPV6_NODE;
25ffbdc1 7118
d62a17ae 7119 return CMD_SUCCESS;
25ffbdc1 7120}
718e3744 7121
d6902373 7122#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7123DEFUN_NOSH (address_family_vpnv4,
718e3744 7124 address_family_vpnv4_cmd,
8334fd5a 7125 "address-family vpnv4 [unicast]",
718e3744 7126 "Enter Address Family command mode\n"
8c3deaae 7127 "Address Family\n"
3a2d747c 7128 "Address Family modifier\n")
718e3744 7129{
d62a17ae 7130 vty->node = BGP_VPNV4_NODE;
7131 return CMD_SUCCESS;
718e3744 7132}
7133
505e5056 7134DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7135 address_family_vpnv6_cmd,
8334fd5a 7136 "address-family vpnv6 [unicast]",
8ecd3266 7137 "Enter Address Family command mode\n"
8c3deaae 7138 "Address Family\n"
3a2d747c 7139 "Address Family modifier\n")
8ecd3266 7140{
d62a17ae 7141 vty->node = BGP_VPNV6_NODE;
7142 return CMD_SUCCESS;
8ecd3266 7143}
c016b6c7 7144#endif
d6902373 7145
505e5056 7146DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7147 address_family_evpn_cmd,
7111c1a0 7148 "address-family l2vpn evpn",
4e0b7b6d 7149 "Enter Address Family command mode\n"
7111c1a0
QY
7150 "Address Family\n"
7151 "Address Family modifier\n")
4e0b7b6d 7152{
2131d5cf 7153 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7154 vty->node = BGP_EVPN_NODE;
7155 return CMD_SUCCESS;
4e0b7b6d
PG
7156}
7157
505e5056 7158DEFUN_NOSH (exit_address_family,
718e3744 7159 exit_address_family_cmd,
7160 "exit-address-family",
7161 "Exit from Address Family configuration mode\n")
7162{
d62a17ae 7163 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7164 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7165 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7166 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7167 || vty->node == BGP_EVPN_NODE
7168 || vty->node == BGP_FLOWSPECV4_NODE
7169 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7170 vty->node = BGP_NODE;
7171 return CMD_SUCCESS;
718e3744 7172}
6b0655a2 7173
8ad7271d 7174/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7175static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7176 const char *ip_str, afi_t afi, safi_t safi,
7177 struct prefix_rd *prd)
7178{
7179 int ret;
7180 struct prefix match;
7181 struct bgp_node *rn;
7182 struct bgp_node *rm;
7183 struct bgp *bgp;
7184 struct bgp_table *table;
7185 struct bgp_table *rib;
7186
7187 /* BGP structure lookup. */
7188 if (view_name) {
7189 bgp = bgp_lookup_by_name(view_name);
7190 if (bgp == NULL) {
7191 vty_out(vty, "%% Can't find BGP instance %s\n",
7192 view_name);
7193 return CMD_WARNING;
7194 }
7195 } else {
7196 bgp = bgp_get_default();
7197 if (bgp == NULL) {
7198 vty_out(vty, "%% No BGP process is configured\n");
7199 return CMD_WARNING;
7200 }
7201 }
7202
7203 /* Check IP address argument. */
7204 ret = str2prefix(ip_str, &match);
7205 if (!ret) {
7206 vty_out(vty, "%% address is malformed\n");
7207 return CMD_WARNING;
7208 }
7209
7210 match.family = afi2family(afi);
7211 rib = bgp->rib[afi][safi];
7212
7213 if (safi == SAFI_MPLS_VPN) {
7214 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7215 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7216 continue;
7217
67009e22
DS
7218 table = bgp_node_get_bgp_table_info(rn);
7219 if (table != NULL) {
7220
d62a17ae 7221 if ((rm = bgp_node_match(table, &match))
7222 != NULL) {
7223 if (rm->p.prefixlen
7224 == match.prefixlen) {
343cdb61 7225 SET_FLAG(rm->flags,
d62a17ae 7226 BGP_NODE_USER_CLEAR);
7227 bgp_process(bgp, rm, afi, safi);
7228 }
7229 bgp_unlock_node(rm);
7230 }
7231 }
7232 }
7233 } else {
7234 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7235 if (rn->p.prefixlen == match.prefixlen) {
7236 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7237 bgp_process(bgp, rn, afi, safi);
7238 }
7239 bgp_unlock_node(rn);
7240 }
7241 }
7242
7243 return CMD_SUCCESS;
8ad7271d
DS
7244}
7245
b09b5ae0 7246/* one clear bgp command to rule them all */
718e3744 7247DEFUN (clear_ip_bgp_all,
7248 clear_ip_bgp_all_cmd,
fd5e7b70 7249 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
718e3744 7250 CLEAR_STR
7251 IP_STR
7252 BGP_STR
838758ac 7253 BGP_INSTANCE_HELP_STR
510afcd6 7254 BGP_AFI_HELP_STR
fd5e7b70 7255 "Address Family\n"
510afcd6 7256 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 7257 "Address Family modifier\n"
b09b5ae0
DW
7258 "Clear all peers\n"
7259 "BGP neighbor address to clear\n"
a80beece 7260 "BGP IPv6 neighbor to clear\n"
838758ac 7261 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7262 "Clear peers with the AS number\n"
7263 "Clear all external peers\n"
718e3744 7264 "Clear all members of peer-group\n"
b09b5ae0 7265 "BGP peer-group name\n"
b09b5ae0
DW
7266 BGP_SOFT_STR
7267 BGP_SOFT_IN_STR
b09b5ae0
DW
7268 BGP_SOFT_OUT_STR
7269 BGP_SOFT_IN_STR
7270 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7271 BGP_SOFT_OUT_STR)
718e3744 7272{
d62a17ae 7273 char *vrf = NULL;
7274
7275 afi_t afi = AFI_IP6;
7276 safi_t safi = SAFI_UNICAST;
7277 enum clear_sort clr_sort = clear_peer;
7278 enum bgp_clear_type clr_type;
7279 char *clr_arg = NULL;
7280
7281 int idx = 0;
7282
7283 /* clear [ip] bgp */
7284 if (argv_find(argv, argc, "ip", &idx))
7285 afi = AFI_IP;
7286
9a8bdf1c
PG
7287 /* [<vrf> VIEWVRFNAME] */
7288 if (argv_find(argv, argc, "vrf", &idx)) {
7289 vrf = argv[idx + 1]->arg;
7290 idx += 2;
7291 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7292 vrf = NULL;
7293 } else if (argv_find(argv, argc, "view", &idx)) {
7294 /* [<view> VIEWVRFNAME] */
d62a17ae 7295 vrf = argv[idx + 1]->arg;
7296 idx += 2;
7297 }
d62a17ae 7298 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7299 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7300 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7301
7302 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7303 if (argv_find(argv, argc, "*", &idx)) {
7304 clr_sort = clear_all;
7305 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7306 clr_sort = clear_peer;
7307 clr_arg = argv[idx]->arg;
7308 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7309 clr_sort = clear_peer;
7310 clr_arg = argv[idx]->arg;
7311 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7312 clr_sort = clear_group;
7313 idx++;
7314 clr_arg = argv[idx]->arg;
7315 } else if (argv_find(argv, argc, "WORD", &idx)) {
7316 clr_sort = clear_peer;
7317 clr_arg = argv[idx]->arg;
7318 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7319 clr_sort = clear_as;
7320 clr_arg = argv[idx]->arg;
7321 } else if (argv_find(argv, argc, "external", &idx)) {
7322 clr_sort = clear_external;
7323 }
7324
7325 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7326 if (argv_find(argv, argc, "soft", &idx)) {
7327 if (argv_find(argv, argc, "in", &idx)
7328 || argv_find(argv, argc, "out", &idx))
7329 clr_type = strmatch(argv[idx]->text, "in")
7330 ? BGP_CLEAR_SOFT_IN
7331 : BGP_CLEAR_SOFT_OUT;
7332 else
7333 clr_type = BGP_CLEAR_SOFT_BOTH;
7334 } else if (argv_find(argv, argc, "in", &idx)) {
7335 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7336 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7337 : BGP_CLEAR_SOFT_IN;
7338 } else if (argv_find(argv, argc, "out", &idx)) {
7339 clr_type = BGP_CLEAR_SOFT_OUT;
7340 } else
7341 clr_type = BGP_CLEAR_SOFT_NONE;
7342
7343 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7344}
01080f7c 7345
8ad7271d
DS
7346DEFUN (clear_ip_bgp_prefix,
7347 clear_ip_bgp_prefix_cmd,
18c57037 7348 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7349 CLEAR_STR
7350 IP_STR
7351 BGP_STR
838758ac 7352 BGP_INSTANCE_HELP_STR
8ad7271d 7353 "Clear bestpath and re-advertise\n"
0c7b1b01 7354 "IPv4 prefix\n")
8ad7271d 7355{
d62a17ae 7356 char *vrf = NULL;
7357 char *prefix = NULL;
8ad7271d 7358
d62a17ae 7359 int idx = 0;
01080f7c 7360
d62a17ae 7361 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
7362 if (argv_find(argv, argc, "vrf", &idx)) {
7363 vrf = argv[idx + 1]->arg;
7364 idx += 2;
7365 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7366 vrf = NULL;
7367 } else if (argv_find(argv, argc, "view", &idx)) {
7368 /* [<view> VIEWVRFNAME] */
7369 vrf = argv[idx + 1]->arg;
7370 idx += 2;
7371 }
0c7b1b01 7372
d62a17ae 7373 prefix = argv[argc - 1]->arg;
8ad7271d 7374
d62a17ae 7375 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7376}
8ad7271d 7377
b09b5ae0
DW
7378DEFUN (clear_bgp_ipv6_safi_prefix,
7379 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7380 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7381 CLEAR_STR
3a2d747c 7382 IP_STR
718e3744 7383 BGP_STR
8c3deaae 7384 "Address Family\n"
46f296b4 7385 BGP_SAFI_HELP_STR
b09b5ae0 7386 "Clear bestpath and re-advertise\n"
0c7b1b01 7387 "IPv6 prefix\n")
718e3744 7388{
9b475e76
PG
7389 int idx_safi = 0;
7390 int idx_ipv6_prefix = 0;
7391 safi_t safi = SAFI_UNICAST;
7392 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7393 argv[idx_ipv6_prefix]->arg : NULL;
7394
7395 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7396 return bgp_clear_prefix(
9b475e76
PG
7397 vty, NULL, prefix, AFI_IP6,
7398 safi, NULL);
838758ac 7399}
01080f7c 7400
b09b5ae0
DW
7401DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7402 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7403 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7404 CLEAR_STR
3a2d747c 7405 IP_STR
718e3744 7406 BGP_STR
838758ac 7407 BGP_INSTANCE_HELP_STR
8c3deaae 7408 "Address Family\n"
46f296b4 7409 BGP_SAFI_HELP_STR
b09b5ae0 7410 "Clear bestpath and re-advertise\n"
0c7b1b01 7411 "IPv6 prefix\n")
718e3744 7412{
9b475e76 7413 int idx_safi = 0;
9a8bdf1c 7414 int idx_vrfview = 0;
9b475e76
PG
7415 int idx_ipv6_prefix = 0;
7416 safi_t safi = SAFI_UNICAST;
7417 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7418 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 7419 char *vrfview = NULL;
9b475e76 7420
9a8bdf1c
PG
7421 /* [<view|vrf> VIEWVRFNAME] */
7422 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7423 vrfview = argv[idx_vrfview + 1]->arg;
7424 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7425 vrfview = NULL;
7426 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7427 /* [<view> VIEWVRFNAME] */
7428 vrfview = argv[idx_vrfview + 1]->arg;
7429 }
9b475e76
PG
7430 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7431
d62a17ae 7432 return bgp_clear_prefix(
9b475e76
PG
7433 vty, vrfview, prefix,
7434 AFI_IP6, safi, NULL);
718e3744 7435}
7436
b09b5ae0
DW
7437DEFUN (show_bgp_views,
7438 show_bgp_views_cmd,
d6e3c605 7439 "show [ip] bgp views",
b09b5ae0 7440 SHOW_STR
d6e3c605 7441 IP_STR
01080f7c 7442 BGP_STR
b09b5ae0 7443 "Show the defined BGP views\n")
01080f7c 7444{
d62a17ae 7445 struct list *inst = bm->bgp;
7446 struct listnode *node;
7447 struct bgp *bgp;
01080f7c 7448
d62a17ae 7449 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7450 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7451 return CMD_WARNING;
7452 }
e52702f2 7453
d62a17ae 7454 vty_out(vty, "Defined BGP views:\n");
7455 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7456 /* Skip VRFs. */
7457 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7458 continue;
7459 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7460 bgp->as);
7461 }
e52702f2 7462
d62a17ae 7463 return CMD_SUCCESS;
e0081f70
ML
7464}
7465
8386ac43 7466DEFUN (show_bgp_vrfs,
7467 show_bgp_vrfs_cmd,
d6e3c605 7468 "show [ip] bgp vrfs [json]",
8386ac43 7469 SHOW_STR
d6e3c605 7470 IP_STR
8386ac43 7471 BGP_STR
7472 "Show BGP VRFs\n"
9973d184 7473 JSON_STR)
8386ac43 7474{
fe1dc5a3 7475 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7476 struct list *inst = bm->bgp;
7477 struct listnode *node;
7478 struct bgp *bgp;
9f049418 7479 bool uj = use_json(argc, argv);
d62a17ae 7480 json_object *json = NULL;
7481 json_object *json_vrfs = NULL;
7482 int count = 0;
d62a17ae 7483
7484 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7485 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7486 return CMD_WARNING;
7487 }
7488
7489 if (uj) {
7490 json = json_object_new_object();
7491 json_vrfs = json_object_new_object();
7492 }
7493
7494 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7495 const char *name, *type;
7496 struct peer *peer;
7fe96307 7497 struct listnode *node2, *nnode2;
d62a17ae 7498 int peers_cfg, peers_estb;
7499 json_object *json_vrf = NULL;
d62a17ae 7500
7501 /* Skip Views. */
7502 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7503 continue;
7504
7505 count++;
7506 if (!uj && count == 1)
fe1dc5a3
MK
7507 vty_out(vty,
7508 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7509 "Type", "Id", "routerId", "#PeersVfg",
7510 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7511
7512 peers_cfg = peers_estb = 0;
7513 if (uj)
7514 json_vrf = json_object_new_object();
7515
7516
7fe96307 7517 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 7518 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7519 continue;
7520 peers_cfg++;
7521 if (peer->status == Established)
7522 peers_estb++;
7523 }
7524
7525 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 7526 name = VRF_DEFAULT_NAME;
d62a17ae 7527 type = "DFLT";
7528 } else {
7529 name = bgp->name;
7530 type = "VRF";
7531 }
7532
a8bf7d9c 7533
d62a17ae 7534 if (uj) {
a4d82a8a
PZ
7535 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7536 ? -1
7537 : (int64_t)bgp->vrf_id;
d62a17ae 7538 json_object_string_add(json_vrf, "type", type);
7539 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7540 json_object_string_add(json_vrf, "routerId",
7541 inet_ntoa(bgp->router_id));
7542 json_object_int_add(json_vrf, "numConfiguredPeers",
7543 peers_cfg);
7544 json_object_int_add(json_vrf, "numEstablishedPeers",
7545 peers_estb);
7546
fe1dc5a3 7547 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7548 json_object_string_add(
7549 json_vrf, "rmac",
7550 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7551 json_object_object_add(json_vrfs, name, json_vrf);
7552 } else
fe1dc5a3
MK
7553 vty_out(vty,
7554 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7555 type,
7556 bgp->vrf_id == VRF_UNKNOWN ? -1
7557 : (int)bgp->vrf_id,
7558 inet_ntoa(bgp->router_id), peers_cfg,
7559 peers_estb, name, bgp->l3vni,
fe1dc5a3 7560 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7561 }
7562
7563 if (uj) {
7564 json_object_object_add(json, "vrfs", json_vrfs);
7565
7566 json_object_int_add(json, "totalVrfs", count);
7567
996c9314
LB
7568 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7569 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7570 json_object_free(json);
7571 } else {
7572 if (count)
7573 vty_out(vty,
7574 "\nTotal number of VRFs (including default): %d\n",
7575 count);
7576 }
7577
7578 return CMD_SUCCESS;
8386ac43 7579}
7580
48ecf8f5
DS
7581DEFUN (show_bgp_mac_hash,
7582 show_bgp_mac_hash_cmd,
7583 "show bgp mac hash",
7584 SHOW_STR
7585 BGP_STR
7586 "Mac Address\n"
7587 "Mac Address database\n")
7588{
7589 bgp_mac_dump_table(vty);
7590
7591 return CMD_SUCCESS;
7592}
acf71666
MK
7593
7594static void show_tip_entry(struct hash_backet *backet, void *args)
7595{
0291c246 7596 struct vty *vty = (struct vty *)args;
60466a63 7597 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7598
60466a63 7599 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7600 tip->refcnt);
7601}
7602
7603static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7604{
7605 vty_out(vty, "self nexthop database:\n");
af97a18b 7606 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
7607
7608 vty_out(vty, "Tunnel-ip database:\n");
7609 hash_iterate(bgp->tip_hash,
7610 (void (*)(struct hash_backet *, void *))show_tip_entry,
7611 vty);
7612}
7613
15c81ca4
DS
7614DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7615 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7616 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7617 "martian next-hops\n"
7618 "martian next-hop database\n")
acf71666 7619{
0291c246 7620 struct bgp *bgp = NULL;
15c81ca4 7621 int idx = 0;
9a8bdf1c
PG
7622 char *name = NULL;
7623
7624 /* [<vrf> VIEWVRFNAME] */
7625 if (argv_find(argv, argc, "vrf", &idx)) {
7626 name = argv[idx + 1]->arg;
7627 if (name && strmatch(name, VRF_DEFAULT_NAME))
7628 name = NULL;
7629 } else if (argv_find(argv, argc, "view", &idx))
7630 /* [<view> VIEWVRFNAME] */
7631 name = argv[idx + 1]->arg;
7632 if (name)
7633 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
7634 else
7635 bgp = bgp_get_default();
acf71666 7636
acf71666
MK
7637 if (!bgp) {
7638 vty_out(vty, "%% No BGP process is configured\n");
7639 return CMD_WARNING;
7640 }
7641 bgp_show_martian_nexthops(vty, bgp);
7642
7643 return CMD_SUCCESS;
7644}
7645
f412b39a 7646DEFUN (show_bgp_memory,
4bf6a362 7647 show_bgp_memory_cmd,
7fa12b13 7648 "show [ip] bgp memory",
4bf6a362 7649 SHOW_STR
3a2d747c 7650 IP_STR
4bf6a362
PJ
7651 BGP_STR
7652 "Global BGP memory statistics\n")
7653{
d62a17ae 7654 char memstrbuf[MTYPE_MEMSTR_LEN];
7655 unsigned long count;
7656
7657 /* RIB related usage stats */
7658 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7659 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7660 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7661 count * sizeof(struct bgp_node)));
7662
7663 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7664 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7665 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 7666 count * sizeof(struct bgp_path_info)));
d62a17ae 7667 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7668 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7669 count,
4b7e6066
DS
7670 mtype_memstr(
7671 memstrbuf, sizeof(memstrbuf),
7672 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 7673
7674 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7675 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7676 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7677 count * sizeof(struct bgp_static)));
7678
7679 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7680 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7681 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7682 count * sizeof(struct bpacket)));
7683
7684 /* Adj-In/Out */
7685 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7686 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7687 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7688 count * sizeof(struct bgp_adj_in)));
7689 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7690 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7691 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7692 count * sizeof(struct bgp_adj_out)));
7693
7694 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7695 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7696 count,
7697 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7698 count * sizeof(struct bgp_nexthop_cache)));
7699
7700 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7701 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7702 count,
7703 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7704 count * sizeof(struct bgp_damp_info)));
7705
7706 /* Attributes */
7707 count = attr_count();
7708 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7709 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7710 count * sizeof(struct attr)));
7711
7712 if ((count = attr_unknown_count()))
7713 vty_out(vty, "%ld unknown attributes\n", count);
7714
7715 /* AS_PATH attributes */
7716 count = aspath_count();
7717 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7718 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7719 count * sizeof(struct aspath)));
7720
7721 count = mtype_stats_alloc(MTYPE_AS_SEG);
7722 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7723 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7724 count * sizeof(struct assegment)));
7725
7726 /* Other attributes */
7727 if ((count = community_count()))
7728 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7729 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7730 count * sizeof(struct community)));
d62a17ae 7731 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7732 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7733 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7734 count * sizeof(struct ecommunity)));
d62a17ae 7735 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7736 vty_out(vty,
7737 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7738 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7739 count * sizeof(struct lcommunity)));
d62a17ae 7740
7741 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7742 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7743 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7744 count * sizeof(struct cluster_list)));
7745
7746 /* Peer related usage */
7747 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7748 vty_out(vty, "%ld peers, using %s of memory\n", count,
7749 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7750 count * sizeof(struct peer)));
7751
7752 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7753 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7754 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7755 count * sizeof(struct peer_group)));
7756
7757 /* Other */
7758 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7759 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7760 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7761 count * sizeof(struct hash)));
7762 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7763 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7764 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7765 count * sizeof(struct hash_backet)));
7766 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7767 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7768 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7769 count * sizeof(regex_t)));
d62a17ae 7770 return CMD_SUCCESS;
4bf6a362 7771}
fee0f4c6 7772
57a9c8a8
DS
7773static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7774{
7775 json_object *bestpath = json_object_new_object();
7776
7777 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7778 json_object_string_add(bestpath, "asPath", "ignore");
7779
7780 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7781 json_object_string_add(bestpath, "asPath", "confed");
7782
7783 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7784 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7785 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7786 "as-set");
7787 else
a4d82a8a 7788 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7789 "true");
7790 } else
a4d82a8a 7791 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7792
7793 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7794 json_object_string_add(bestpath, "compareRouterId", "true");
7795 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7796 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7797 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7798 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7799 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7800 json_object_string_add(bestpath, "med",
7801 "missing-as-worst");
7802 else
7803 json_object_string_add(bestpath, "med", "true");
7804 }
7805
7806 json_object_object_add(json, "bestPath", bestpath);
7807}
7808
718e3744 7809/* Show BGP peer's summary information. */
d62a17ae 7810static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
9f049418 7811 bool use_json, json_object *json)
d62a17ae 7812{
7813 struct peer *peer;
7814 struct listnode *node, *nnode;
7815 unsigned int count = 0, dn_count = 0;
7816 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7817 char neighbor_buf[VTY_BUFSIZ];
7818 int neighbor_col_default_width = 16;
7819 int len;
7820 int max_neighbor_width = 0;
7821 int pfx_rcd_safi;
7822 json_object *json_peer = NULL;
7823 json_object *json_peers = NULL;
50e05855 7824 struct peer_af *paf;
d62a17ae 7825
7826 /* labeled-unicast routes are installed in the unicast table so in order
7827 * to
7828 * display the correct PfxRcd value we must look at SAFI_UNICAST
7829 */
7830 if (safi == SAFI_LABELED_UNICAST)
7831 pfx_rcd_safi = SAFI_UNICAST;
7832 else
7833 pfx_rcd_safi = safi;
7834
7835 if (use_json) {
7836 if (json == NULL)
7837 json = json_object_new_object();
7838
7839 json_peers = json_object_new_object();
7840 } else {
7841 /* Loop over all neighbors that will be displayed to determine
7842 * how many
7843 * characters are needed for the Neighbor column
7844 */
7845 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7846 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7847 continue;
7848
7849 if (peer->afc[afi][safi]) {
7850 memset(dn_flag, '\0', sizeof(dn_flag));
7851 if (peer_dynamic_neighbor(peer))
7852 dn_flag[0] = '*';
7853
7854 if (peer->hostname
7855 && bgp_flag_check(bgp,
7856 BGP_FLAG_SHOW_HOSTNAME))
7857 sprintf(neighbor_buf, "%s%s(%s) ",
7858 dn_flag, peer->hostname,
7859 peer->host);
7860 else
7861 sprintf(neighbor_buf, "%s%s ", dn_flag,
7862 peer->host);
7863
7864 len = strlen(neighbor_buf);
7865
7866 if (len > max_neighbor_width)
7867 max_neighbor_width = len;
7868 }
7869 }
f933309e 7870
d62a17ae 7871 /* Originally we displayed the Neighbor column as 16
7872 * characters wide so make that the default
7873 */
7874 if (max_neighbor_width < neighbor_col_default_width)
7875 max_neighbor_width = neighbor_col_default_width;
7876 }
f933309e 7877
d62a17ae 7878 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7879 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7880 continue;
7881
ea47320b
DL
7882 if (!peer->afc[afi][safi])
7883 continue;
d62a17ae 7884
ea47320b
DL
7885 if (!count) {
7886 unsigned long ents;
7887 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7888 int64_t vrf_id_ui;
d62a17ae 7889
a4d82a8a
PZ
7890 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7891 ? -1
7892 : (int64_t)bgp->vrf_id;
ea47320b
DL
7893
7894 /* Usage summary and header */
7895 if (use_json) {
7896 json_object_string_add(
7897 json, "routerId",
7898 inet_ntoa(bgp->router_id));
60466a63
QY
7899 json_object_int_add(json, "as", bgp->as);
7900 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7901 json_object_string_add(
7902 json, "vrfName",
7903 (bgp->inst_type
7904 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 7905 ? VRF_DEFAULT_NAME
ea47320b
DL
7906 : bgp->name);
7907 } else {
7908 vty_out(vty,
7909 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7910 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7911 bgp->vrf_id == VRF_UNKNOWN
7912 ? -1
7913 : (int)bgp->vrf_id);
ea47320b
DL
7914 vty_out(vty, "\n");
7915 }
d62a17ae 7916
ea47320b 7917 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7918 if (use_json) {
ea47320b 7919 json_object_int_add(
60466a63 7920 json, "updateDelayLimit",
ea47320b 7921 bgp->v_update_delay);
d62a17ae 7922
ea47320b
DL
7923 if (bgp->v_update_delay
7924 != bgp->v_establish_wait)
d62a17ae 7925 json_object_int_add(
7926 json,
ea47320b
DL
7927 "updateDelayEstablishWait",
7928 bgp->v_establish_wait);
d62a17ae 7929
60466a63 7930 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7931 json_object_string_add(
7932 json,
7933 "updateDelayFirstNeighbor",
7934 bgp->update_delay_begin_time);
7935 json_object_boolean_true_add(
7936 json,
7937 "updateDelayInProgress");
7938 } else {
7939 if (bgp->update_delay_over) {
d62a17ae 7940 json_object_string_add(
7941 json,
7942 "updateDelayFirstNeighbor",
7943 bgp->update_delay_begin_time);
ea47320b 7944 json_object_string_add(
d62a17ae 7945 json,
ea47320b
DL
7946 "updateDelayBestpathResumed",
7947 bgp->update_delay_end_time);
7948 json_object_string_add(
d62a17ae 7949 json,
ea47320b
DL
7950 "updateDelayZebraUpdateResume",
7951 bgp->update_delay_zebra_resume_time);
7952 json_object_string_add(
7953 json,
7954 "updateDelayPeerUpdateResume",
7955 bgp->update_delay_peers_resume_time);
d62a17ae 7956 }
ea47320b
DL
7957 }
7958 } else {
7959 vty_out(vty,
7960 "Read-only mode update-delay limit: %d seconds\n",
7961 bgp->v_update_delay);
7962 if (bgp->v_update_delay
7963 != bgp->v_establish_wait)
d62a17ae 7964 vty_out(vty,
ea47320b
DL
7965 " Establish wait: %d seconds\n",
7966 bgp->v_establish_wait);
d62a17ae 7967
60466a63 7968 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7969 vty_out(vty,
7970 " First neighbor established: %s\n",
7971 bgp->update_delay_begin_time);
7972 vty_out(vty,
7973 " Delay in progress\n");
7974 } else {
7975 if (bgp->update_delay_over) {
d62a17ae 7976 vty_out(vty,
7977 " First neighbor established: %s\n",
7978 bgp->update_delay_begin_time);
7979 vty_out(vty,
ea47320b
DL
7980 " Best-paths resumed: %s\n",
7981 bgp->update_delay_end_time);
7982 vty_out(vty,
7983 " zebra update resumed: %s\n",
7984 bgp->update_delay_zebra_resume_time);
7985 vty_out(vty,
7986 " peers update resumed: %s\n",
7987 bgp->update_delay_peers_resume_time);
d62a17ae 7988 }
7989 }
7990 }
ea47320b 7991 }
d62a17ae 7992
ea47320b
DL
7993 if (use_json) {
7994 if (bgp_maxmed_onstartup_configured(bgp)
7995 && bgp->maxmed_active)
7996 json_object_boolean_true_add(
60466a63 7997 json, "maxMedOnStartup");
ea47320b
DL
7998 if (bgp->v_maxmed_admin)
7999 json_object_boolean_true_add(
60466a63 8000 json, "maxMedAdministrative");
d62a17ae 8001
ea47320b
DL
8002 json_object_int_add(
8003 json, "tableVersion",
60466a63 8004 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 8005
60466a63
QY
8006 ents = bgp_table_count(bgp->rib[afi][safi]);
8007 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
8008 json_object_int_add(
8009 json, "ribMemory",
8010 ents * sizeof(struct bgp_node));
d62a17ae 8011
ea47320b 8012 ents = listcount(bgp->peer);
60466a63
QY
8013 json_object_int_add(json, "peerCount", ents);
8014 json_object_int_add(json, "peerMemory",
8015 ents * sizeof(struct peer));
d62a17ae 8016
ea47320b
DL
8017 if ((ents = listcount(bgp->group))) {
8018 json_object_int_add(
60466a63 8019 json, "peerGroupCount", ents);
ea47320b
DL
8020 json_object_int_add(
8021 json, "peerGroupMemory",
996c9314
LB
8022 ents * sizeof(struct
8023 peer_group));
ea47320b 8024 }
d62a17ae 8025
ea47320b
DL
8026 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8027 BGP_CONFIG_DAMPENING))
8028 json_object_boolean_true_add(
60466a63 8029 json, "dampeningEnabled");
ea47320b
DL
8030 } else {
8031 if (bgp_maxmed_onstartup_configured(bgp)
8032 && bgp->maxmed_active)
d62a17ae 8033 vty_out(vty,
ea47320b
DL
8034 "Max-med on-startup active\n");
8035 if (bgp->v_maxmed_admin)
d62a17ae 8036 vty_out(vty,
ea47320b 8037 "Max-med administrative active\n");
d62a17ae 8038
60466a63
QY
8039 vty_out(vty, "BGP table version %" PRIu64 "\n",
8040 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 8041
60466a63 8042 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
8043 vty_out(vty,
8044 "RIB entries %ld, using %s of memory\n",
8045 ents,
996c9314
LB
8046 mtype_memstr(memstrbuf,
8047 sizeof(memstrbuf),
8048 ents * sizeof(struct
8049 bgp_node)));
ea47320b
DL
8050
8051 /* Peer related usage */
8052 ents = listcount(bgp->peer);
60466a63 8053 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
8054 ents,
8055 mtype_memstr(
60466a63
QY
8056 memstrbuf, sizeof(memstrbuf),
8057 ents * sizeof(struct peer)));
ea47320b
DL
8058
8059 if ((ents = listcount(bgp->group)))
d62a17ae 8060 vty_out(vty,
ea47320b 8061 "Peer groups %ld, using %s of memory\n",
d62a17ae 8062 ents,
8063 mtype_memstr(
8064 memstrbuf,
8065 sizeof(memstrbuf),
996c9314
LB
8066 ents * sizeof(struct
8067 peer_group)));
d62a17ae 8068
ea47320b
DL
8069 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8070 BGP_CONFIG_DAMPENING))
60466a63 8071 vty_out(vty, "Dampening enabled.\n");
ea47320b 8072 vty_out(vty, "\n");
d62a17ae 8073
ea47320b
DL
8074 /* Subtract 8 here because 'Neighbor' is
8075 * 8 characters */
8076 vty_out(vty, "Neighbor");
60466a63
QY
8077 vty_out(vty, "%*s", max_neighbor_width - 8,
8078 " ");
ea47320b
DL
8079 vty_out(vty,
8080 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 8081 }
ea47320b 8082 }
d62a17ae 8083
ea47320b 8084 count++;
d62a17ae 8085
ea47320b
DL
8086 if (use_json) {
8087 json_peer = json_object_new_object();
d62a17ae 8088
b4e9dcba
DD
8089 if (peer_dynamic_neighbor(peer)) {
8090 dn_count++;
60466a63
QY
8091 json_object_boolean_true_add(json_peer,
8092 "dynamicPeer");
b4e9dcba 8093 }
d62a17ae 8094
ea47320b 8095 if (peer->hostname)
60466a63 8096 json_object_string_add(json_peer, "hostname",
ea47320b 8097 peer->hostname);
d62a17ae 8098
ea47320b 8099 if (peer->domainname)
60466a63
QY
8100 json_object_string_add(json_peer, "domainname",
8101 peer->domainname);
d62a17ae 8102
60466a63 8103 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 8104 json_object_int_add(json_peer, "version", 4);
60466a63 8105 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 8106 PEER_TOTAL_RX(peer));
60466a63 8107 json_object_int_add(json_peer, "msgSent",
0112e9e0 8108 PEER_TOTAL_TX(peer));
ea47320b
DL
8109
8110 json_object_int_add(json_peer, "tableVersion",
8111 peer->version[afi][safi]);
8112 json_object_int_add(json_peer, "outq",
8113 peer->obuf->count);
8114 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
8115 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8116 use_json, json_peer);
50e05855
AD
8117
8118 /*
8119 * Adding "pfxRcd" field to match with the corresponding
8120 * CLI. "prefixReceivedCount" will be deprecated in
8121 * future.
8122 */
60466a63
QY
8123 json_object_int_add(json_peer, "prefixReceivedCount",
8124 peer->pcount[afi][pfx_rcd_safi]);
50e05855
AD
8125 json_object_int_add(json_peer, "pfxRcd",
8126 peer->pcount[afi][pfx_rcd_safi]);
8127
8128 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8129 if (paf && PAF_SUBGRP(paf))
8130 json_object_int_add(json_peer,
8131 "pfxSnt",
8132 (PAF_SUBGRP(paf))->scount);
d62a17ae 8133
ea47320b 8134 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 8135 json_object_string_add(json_peer, "state",
ea47320b 8136 "Idle (Admin)");
9199a725
TM
8137 else if (peer->afc_recv[afi][safi])
8138 json_object_string_add(
8139 json_peer, "state",
8140 lookup_msg(bgp_status_msg, peer->status,
8141 NULL));
60466a63
QY
8142 else if (CHECK_FLAG(peer->sflags,
8143 PEER_STATUS_PREFIX_OVERFLOW))
8144 json_object_string_add(json_peer, "state",
ea47320b
DL
8145 "Idle (PfxCt)");
8146 else
8147 json_object_string_add(
8148 json_peer, "state",
60466a63
QY
8149 lookup_msg(bgp_status_msg, peer->status,
8150 NULL));
ea47320b
DL
8151
8152 if (peer->conf_if)
60466a63 8153 json_object_string_add(json_peer, "idType",
ea47320b
DL
8154 "interface");
8155 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
8156 json_object_string_add(json_peer, "idType",
8157 "ipv4");
ea47320b 8158 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
8159 json_object_string_add(json_peer, "idType",
8160 "ipv6");
d62a17ae 8161
ea47320b
DL
8162 json_object_object_add(json_peers, peer->host,
8163 json_peer);
8164 } else {
8165 memset(dn_flag, '\0', sizeof(dn_flag));
8166 if (peer_dynamic_neighbor(peer)) {
8167 dn_count++;
8168 dn_flag[0] = '*';
8169 }
d62a17ae 8170
ea47320b 8171 if (peer->hostname
60466a63 8172 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 8173 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 8174 peer->hostname, peer->host);
ea47320b 8175 else
60466a63 8176 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
8177
8178 /* pad the neighbor column with spaces */
8179 if (len < max_neighbor_width)
60466a63
QY
8180 vty_out(vty, "%*s", max_neighbor_width - len,
8181 " ");
ea47320b 8182
86a55b99 8183 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
8184 peer->as, PEER_TOTAL_RX(peer),
8185 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8186 0, peer->obuf->count,
d62a17ae 8187 peer_uptime(peer->uptime, timebuf,
ea47320b 8188 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 8189
ea47320b 8190 if (peer->status == Established)
2f8f4f10 8191 if (peer->afc_recv[afi][safi])
95077abf 8192 vty_out(vty, " %12ld",
a4d82a8a
PZ
8193 peer->pcount[afi]
8194 [pfx_rcd_safi]);
95077abf
DW
8195 else
8196 vty_out(vty, " NoNeg");
ea47320b 8197 else {
60466a63 8198 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 8199 vty_out(vty, " Idle (Admin)");
60466a63
QY
8200 else if (CHECK_FLAG(
8201 peer->sflags,
8202 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 8203 vty_out(vty, " Idle (PfxCt)");
d62a17ae 8204 else
ea47320b 8205 vty_out(vty, " %12s",
60466a63
QY
8206 lookup_msg(bgp_status_msg,
8207 peer->status, NULL));
d62a17ae 8208 }
ea47320b 8209 vty_out(vty, "\n");
d62a17ae 8210 }
8211 }
f933309e 8212
d62a17ae 8213 if (use_json) {
8214 json_object_object_add(json, "peers", json_peers);
8215
8216 json_object_int_add(json, "totalPeers", count);
8217 json_object_int_add(json, "dynamicPeers", dn_count);
8218
57a9c8a8
DS
8219 bgp_show_bestpath_json(bgp, json);
8220
996c9314
LB
8221 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8222 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8223 json_object_free(json);
8224 } else {
8225 if (count)
8226 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8227 else {
d6ceaca3 8228 vty_out(vty, "No %s neighbor is configured\n",
8229 afi_safi_print(afi, safi));
d62a17ae 8230 }
b05a1c8b 8231
d6ceaca3 8232 if (dn_count) {
d62a17ae 8233 vty_out(vty, "* - dynamic neighbor\n");
8234 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8235 dn_count, bgp->dynamic_neighbors_limit);
8236 }
8237 }
1ff9a340 8238
d62a17ae 8239 return CMD_SUCCESS;
718e3744 8240}
8241
d62a17ae 8242static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
9f049418 8243 int safi, bool use_json,
d62a17ae 8244 json_object *json)
8245{
8246 int is_first = 1;
8247 int afi_wildcard = (afi == AFI_MAX);
8248 int safi_wildcard = (safi == SAFI_MAX);
8249 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 8250 bool nbr_output = false;
d62a17ae 8251
8252 if (use_json && is_wildcard)
8253 vty_out(vty, "{\n");
8254 if (afi_wildcard)
8255 afi = 1; /* AFI_IP */
8256 while (afi < AFI_MAX) {
8257 if (safi_wildcard)
8258 safi = 1; /* SAFI_UNICAST */
8259 while (safi < SAFI_MAX) {
318cac96 8260 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 8261 nbr_output = true;
d62a17ae 8262 if (is_wildcard) {
8263 /*
8264 * So limit output to those afi/safi
8265 * pairs that
8266 * actualy have something interesting in
8267 * them
8268 */
8269 if (use_json) {
8270 json = json_object_new_object();
8271
8272 if (!is_first)
8273 vty_out(vty, ",\n");
8274 else
8275 is_first = 0;
8276
8277 vty_out(vty, "\"%s\":",
8278 afi_safi_json(afi,
8279 safi));
8280 } else {
8281 vty_out(vty, "\n%s Summary:\n",
8282 afi_safi_print(afi,
8283 safi));
8284 }
8285 }
8286 bgp_show_summary(vty, bgp, afi, safi, use_json,
8287 json);
8288 }
8289 safi++;
d62a17ae 8290 if (!safi_wildcard)
8291 safi = SAFI_MAX;
8292 }
8293 afi++;
ee851c8c 8294 if (!afi_wildcard)
d62a17ae 8295 afi = AFI_MAX;
8296 }
8297
8298 if (use_json && is_wildcard)
8299 vty_out(vty, "}\n");
ca61fd25
DS
8300 else if (!nbr_output) {
8301 if (use_json)
8302 vty_out(vty, "{}\n");
8303 else
8304 vty_out(vty, "%% No BGP neighbors found\n");
8305 }
d62a17ae 8306}
8307
8308static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
9f049418 8309 safi_t safi, bool use_json)
d62a17ae 8310{
8311 struct listnode *node, *nnode;
8312 struct bgp *bgp;
8313 json_object *json = NULL;
8314 int is_first = 1;
9f049418 8315 bool nbr_output = false;
d62a17ae 8316
8317 if (use_json)
8318 vty_out(vty, "{\n");
8319
8320 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 8321 nbr_output = true;
d62a17ae 8322 if (use_json) {
8323 json = json_object_new_object();
8324
8325 if (!is_first)
8326 vty_out(vty, ",\n");
8327 else
8328 is_first = 0;
8329
8330 vty_out(vty, "\"%s\":",
8331 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8332 ? VRF_DEFAULT_NAME
d62a17ae 8333 : bgp->name);
8334 } else {
8335 vty_out(vty, "\nInstance %s:\n",
8336 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8337 ? VRF_DEFAULT_NAME
d62a17ae 8338 : bgp->name);
8339 }
8340 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8341 }
8342
8343 if (use_json)
8344 vty_out(vty, "}\n");
9f049418
DS
8345 else if (!nbr_output)
8346 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 8347}
8348
8349int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
9f049418 8350 safi_t safi, bool use_json)
d62a17ae 8351{
8352 struct bgp *bgp;
8353
8354 if (name) {
8355 if (strmatch(name, "all")) {
8356 bgp_show_all_instances_summary_vty(vty, afi, safi,
8357 use_json);
8358 return CMD_SUCCESS;
8359 } else {
8360 bgp = bgp_lookup_by_name(name);
8361
8362 if (!bgp) {
8363 if (use_json)
8364 vty_out(vty, "{}\n");
8365 else
8366 vty_out(vty,
ca61fd25 8367 "%% BGP instance not found\n");
d62a17ae 8368 return CMD_WARNING;
8369 }
8370
8371 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8372 NULL);
8373 return CMD_SUCCESS;
8374 }
8375 }
8376
8377 bgp = bgp_get_default();
8378
8379 if (bgp)
8380 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
9f049418 8381 else {
ca61fd25
DS
8382 if (use_json)
8383 vty_out(vty, "{}\n");
8384 else
8385 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
8386 return CMD_WARNING;
8387 }
d62a17ae 8388
8389 return CMD_SUCCESS;
4fb25c53
DW
8390}
8391
716b2d8a 8392/* `show [ip] bgp summary' commands. */
47fc97cc 8393DEFUN (show_ip_bgp_summary,
718e3744 8394 show_ip_bgp_summary_cmd,
dd6bd0f1 8395 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8396 SHOW_STR
8397 IP_STR
8398 BGP_STR
8386ac43 8399 BGP_INSTANCE_HELP_STR
46f296b4 8400 BGP_AFI_HELP_STR
dd6bd0f1 8401 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8402 "Summary of BGP neighbor status\n"
9973d184 8403 JSON_STR)
718e3744 8404{
d62a17ae 8405 char *vrf = NULL;
8406 afi_t afi = AFI_MAX;
8407 safi_t safi = SAFI_MAX;
8408
8409 int idx = 0;
8410
8411 /* show [ip] bgp */
8412 if (argv_find(argv, argc, "ip", &idx))
8413 afi = AFI_IP;
9a8bdf1c
PG
8414 /* [<vrf> VIEWVRFNAME] */
8415 if (argv_find(argv, argc, "vrf", &idx)) {
8416 vrf = argv[idx + 1]->arg;
8417 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8418 vrf = NULL;
8419 } else if (argv_find(argv, argc, "view", &idx))
8420 /* [<view> VIEWVRFNAME] */
8421 vrf = argv[idx + 1]->arg;
d62a17ae 8422 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8423 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8424 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8425 }
8426
9f049418 8427 bool uj = use_json(argc, argv);
d62a17ae 8428
8429 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8430}
8431
8432const char *afi_safi_print(afi_t afi, safi_t safi)
8433{
8434 if (afi == AFI_IP && safi == SAFI_UNICAST)
8435 return "IPv4 Unicast";
8436 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8437 return "IPv4 Multicast";
8438 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8439 return "IPv4 Labeled Unicast";
8440 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8441 return "IPv4 VPN";
8442 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8443 return "IPv4 Encap";
7c40bf39 8444 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8445 return "IPv4 Flowspec";
d62a17ae 8446 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8447 return "IPv6 Unicast";
8448 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8449 return "IPv6 Multicast";
8450 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8451 return "IPv6 Labeled Unicast";
8452 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8453 return "IPv6 VPN";
8454 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8455 return "IPv6 Encap";
7c40bf39 8456 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8457 return "IPv6 Flowspec";
d62a17ae 8458 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8459 return "L2VPN EVPN";
8460 else
8461 return "Unknown";
538621f2 8462}
8463
b9f77ec8
DS
8464/*
8465 * Please note that we have intentionally camelCased
8466 * the return strings here. So if you want
8467 * to use this function, please ensure you
8468 * are doing this within json output
8469 */
d62a17ae 8470const char *afi_safi_json(afi_t afi, safi_t safi)
8471{
8472 if (afi == AFI_IP && safi == SAFI_UNICAST)
8473 return "ipv4Unicast";
8474 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8475 return "ipv4Multicast";
8476 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8477 return "ipv4LabeledUnicast";
8478 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8479 return "ipv4Vpn";
8480 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8481 return "ipv4Encap";
7c40bf39 8482 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8483 return "ipv4Flowspec";
d62a17ae 8484 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8485 return "ipv6Unicast";
8486 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8487 return "ipv6Multicast";
8488 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8489 return "ipv6LabeledUnicast";
8490 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8491 return "ipv6Vpn";
8492 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8493 return "ipv6Encap";
7c40bf39 8494 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8495 return "ipv6Flowspec";
d62a17ae 8496 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8497 return "l2VpnEvpn";
8498 else
8499 return "Unknown";
27162734
LB
8500}
8501
718e3744 8502/* Show BGP peer's information. */
d62a17ae 8503enum show_type { show_all, show_peer };
8504
8505static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8506 afi_t afi, safi_t safi,
d7c0a89a
QY
8507 uint16_t adv_smcap, uint16_t adv_rmcap,
8508 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 8509 bool use_json, json_object *json_pref)
d62a17ae 8510{
8511 /* Send-Mode */
8512 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8513 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8514 if (use_json) {
8515 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8516 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8517 json_object_string_add(json_pref, "sendMode",
8518 "advertisedAndReceived");
8519 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8520 json_object_string_add(json_pref, "sendMode",
8521 "advertised");
8522 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8523 json_object_string_add(json_pref, "sendMode",
8524 "received");
8525 } else {
8526 vty_out(vty, " Send-mode: ");
8527 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8528 vty_out(vty, "advertised");
8529 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8530 vty_out(vty, "%sreceived",
8531 CHECK_FLAG(p->af_cap[afi][safi],
8532 adv_smcap)
8533 ? ", "
8534 : "");
8535 vty_out(vty, "\n");
8536 }
8537 }
8538
8539 /* Receive-Mode */
8540 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8541 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8542 if (use_json) {
8543 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8544 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8545 json_object_string_add(json_pref, "recvMode",
8546 "advertisedAndReceived");
8547 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8548 json_object_string_add(json_pref, "recvMode",
8549 "advertised");
8550 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8551 json_object_string_add(json_pref, "recvMode",
8552 "received");
8553 } else {
8554 vty_out(vty, " Receive-mode: ");
8555 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8556 vty_out(vty, "advertised");
8557 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8558 vty_out(vty, "%sreceived",
8559 CHECK_FLAG(p->af_cap[afi][safi],
8560 adv_rmcap)
8561 ? ", "
8562 : "");
8563 vty_out(vty, "\n");
8564 }
8565 }
8566}
8567
8568static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 8569 safi_t safi, bool use_json,
d62a17ae 8570 json_object *json_neigh)
8571{
0291c246
MK
8572 struct bgp_filter *filter;
8573 struct peer_af *paf;
8574 char orf_pfx_name[BUFSIZ];
8575 int orf_pfx_count;
8576 json_object *json_af = NULL;
8577 json_object *json_prefA = NULL;
8578 json_object *json_prefB = NULL;
8579 json_object *json_addr = NULL;
d62a17ae 8580
8581 if (use_json) {
8582 json_addr = json_object_new_object();
8583 json_af = json_object_new_object();
8584 filter = &p->filter[afi][safi];
8585
8586 if (peer_group_active(p))
8587 json_object_string_add(json_addr, "peerGroupMember",
8588 p->group->name);
8589
8590 paf = peer_af_find(p, afi, safi);
8591 if (paf && PAF_SUBGRP(paf)) {
8592 json_object_int_add(json_addr, "updateGroupId",
8593 PAF_UPDGRP(paf)->id);
8594 json_object_int_add(json_addr, "subGroupId",
8595 PAF_SUBGRP(paf)->id);
8596 json_object_int_add(json_addr, "packetQueueLength",
8597 bpacket_queue_virtual_length(paf));
8598 }
8599
8600 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8601 || CHECK_FLAG(p->af_cap[afi][safi],
8602 PEER_CAP_ORF_PREFIX_SM_RCV)
8603 || CHECK_FLAG(p->af_cap[afi][safi],
8604 PEER_CAP_ORF_PREFIX_RM_ADV)
8605 || CHECK_FLAG(p->af_cap[afi][safi],
8606 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8607 json_object_int_add(json_af, "orfType",
8608 ORF_TYPE_PREFIX);
8609 json_prefA = json_object_new_object();
8610 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8611 PEER_CAP_ORF_PREFIX_SM_ADV,
8612 PEER_CAP_ORF_PREFIX_RM_ADV,
8613 PEER_CAP_ORF_PREFIX_SM_RCV,
8614 PEER_CAP_ORF_PREFIX_RM_RCV,
8615 use_json, json_prefA);
8616 json_object_object_add(json_af, "orfPrefixList",
8617 json_prefA);
8618 }
8619
8620 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8621 || CHECK_FLAG(p->af_cap[afi][safi],
8622 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8623 || CHECK_FLAG(p->af_cap[afi][safi],
8624 PEER_CAP_ORF_PREFIX_RM_ADV)
8625 || CHECK_FLAG(p->af_cap[afi][safi],
8626 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8627 json_object_int_add(json_af, "orfOldType",
8628 ORF_TYPE_PREFIX_OLD);
8629 json_prefB = json_object_new_object();
8630 bgp_show_peer_afi_orf_cap(
8631 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8632 PEER_CAP_ORF_PREFIX_RM_ADV,
8633 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8634 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8635 json_prefB);
8636 json_object_object_add(json_af, "orfOldPrefixList",
8637 json_prefB);
8638 }
8639
8640 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8641 || CHECK_FLAG(p->af_cap[afi][safi],
8642 PEER_CAP_ORF_PREFIX_SM_RCV)
8643 || CHECK_FLAG(p->af_cap[afi][safi],
8644 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8645 || CHECK_FLAG(p->af_cap[afi][safi],
8646 PEER_CAP_ORF_PREFIX_RM_ADV)
8647 || CHECK_FLAG(p->af_cap[afi][safi],
8648 PEER_CAP_ORF_PREFIX_RM_RCV)
8649 || CHECK_FLAG(p->af_cap[afi][safi],
8650 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8651 json_object_object_add(json_addr, "afDependentCap",
8652 json_af);
8653 else
8654 json_object_free(json_af);
8655
8656 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8657 orf_pfx_count = prefix_bgp_show_prefix_list(
8658 NULL, afi, orf_pfx_name, use_json);
8659
8660 if (CHECK_FLAG(p->af_sflags[afi][safi],
8661 PEER_STATUS_ORF_PREFIX_SEND)
8662 || orf_pfx_count) {
8663 if (CHECK_FLAG(p->af_sflags[afi][safi],
8664 PEER_STATUS_ORF_PREFIX_SEND))
8665 json_object_boolean_true_add(json_neigh,
8666 "orfSent");
8667 if (orf_pfx_count)
8668 json_object_int_add(json_addr, "orfRecvCounter",
8669 orf_pfx_count);
8670 }
8671 if (CHECK_FLAG(p->af_sflags[afi][safi],
8672 PEER_STATUS_ORF_WAIT_REFRESH))
8673 json_object_string_add(
8674 json_addr, "orfFirstUpdate",
8675 "deferredUntilORFOrRouteRefreshRecvd");
8676
8677 if (CHECK_FLAG(p->af_flags[afi][safi],
8678 PEER_FLAG_REFLECTOR_CLIENT))
8679 json_object_boolean_true_add(json_addr,
8680 "routeReflectorClient");
8681 if (CHECK_FLAG(p->af_flags[afi][safi],
8682 PEER_FLAG_RSERVER_CLIENT))
8683 json_object_boolean_true_add(json_addr,
8684 "routeServerClient");
8685 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8686 json_object_boolean_true_add(json_addr,
8687 "inboundSoftConfigPermit");
8688
8689 if (CHECK_FLAG(p->af_flags[afi][safi],
8690 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8691 json_object_boolean_true_add(
8692 json_addr,
8693 "privateAsNumsAllReplacedInUpdatesToNbr");
8694 else if (CHECK_FLAG(p->af_flags[afi][safi],
8695 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8696 json_object_boolean_true_add(
8697 json_addr,
8698 "privateAsNumsReplacedInUpdatesToNbr");
8699 else if (CHECK_FLAG(p->af_flags[afi][safi],
8700 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8701 json_object_boolean_true_add(
8702 json_addr,
8703 "privateAsNumsAllRemovedInUpdatesToNbr");
8704 else if (CHECK_FLAG(p->af_flags[afi][safi],
8705 PEER_FLAG_REMOVE_PRIVATE_AS))
8706 json_object_boolean_true_add(
8707 json_addr,
8708 "privateAsNumsRemovedInUpdatesToNbr");
8709
dcc68b5e
MS
8710 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8711 json_object_boolean_true_add(
8712 json_addr,
8713 bgp_addpath_names(p->addpath_type[afi][safi])
8714 ->type_json_name);
d62a17ae 8715
8716 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8717 json_object_string_add(json_addr,
8718 "overrideASNsInOutboundUpdates",
8719 "ifAspathEqualRemoteAs");
8720
8721 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8722 || CHECK_FLAG(p->af_flags[afi][safi],
8723 PEER_FLAG_FORCE_NEXTHOP_SELF))
8724 json_object_boolean_true_add(json_addr,
8725 "routerAlwaysNextHop");
8726 if (CHECK_FLAG(p->af_flags[afi][safi],
8727 PEER_FLAG_AS_PATH_UNCHANGED))
8728 json_object_boolean_true_add(
8729 json_addr, "unchangedAsPathPropogatedToNbr");
8730 if (CHECK_FLAG(p->af_flags[afi][safi],
8731 PEER_FLAG_NEXTHOP_UNCHANGED))
8732 json_object_boolean_true_add(
8733 json_addr, "unchangedNextHopPropogatedToNbr");
8734 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8735 json_object_boolean_true_add(
8736 json_addr, "unchangedMedPropogatedToNbr");
8737 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8738 || CHECK_FLAG(p->af_flags[afi][safi],
8739 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8740 if (CHECK_FLAG(p->af_flags[afi][safi],
8741 PEER_FLAG_SEND_COMMUNITY)
8742 && CHECK_FLAG(p->af_flags[afi][safi],
8743 PEER_FLAG_SEND_EXT_COMMUNITY))
8744 json_object_string_add(json_addr,
8745 "commAttriSentToNbr",
8746 "extendedAndStandard");
8747 else if (CHECK_FLAG(p->af_flags[afi][safi],
8748 PEER_FLAG_SEND_EXT_COMMUNITY))
8749 json_object_string_add(json_addr,
8750 "commAttriSentToNbr",
8751 "extended");
8752 else
8753 json_object_string_add(json_addr,
8754 "commAttriSentToNbr",
8755 "standard");
8756 }
8757 if (CHECK_FLAG(p->af_flags[afi][safi],
8758 PEER_FLAG_DEFAULT_ORIGINATE)) {
8759 if (p->default_rmap[afi][safi].name)
8760 json_object_string_add(
8761 json_addr, "defaultRouteMap",
8762 p->default_rmap[afi][safi].name);
8763
8764 if (paf && PAF_SUBGRP(paf)
8765 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8766 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8767 json_object_boolean_true_add(json_addr,
8768 "defaultSent");
8769 else
8770 json_object_boolean_true_add(json_addr,
8771 "defaultNotSent");
8772 }
8773
dff8f48d 8774 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8775 if (is_evpn_enabled())
60466a63
QY
8776 json_object_boolean_true_add(
8777 json_addr, "advertiseAllVnis");
dff8f48d
MK
8778 }
8779
d62a17ae 8780 if (filter->plist[FILTER_IN].name
8781 || filter->dlist[FILTER_IN].name
8782 || filter->aslist[FILTER_IN].name
8783 || filter->map[RMAP_IN].name)
8784 json_object_boolean_true_add(json_addr,
8785 "inboundPathPolicyConfig");
8786 if (filter->plist[FILTER_OUT].name
8787 || filter->dlist[FILTER_OUT].name
8788 || filter->aslist[FILTER_OUT].name
8789 || filter->map[RMAP_OUT].name || filter->usmap.name)
8790 json_object_boolean_true_add(
8791 json_addr, "outboundPathPolicyConfig");
8792
8793 /* prefix-list */
8794 if (filter->plist[FILTER_IN].name)
8795 json_object_string_add(json_addr,
8796 "incomingUpdatePrefixFilterList",
8797 filter->plist[FILTER_IN].name);
8798 if (filter->plist[FILTER_OUT].name)
8799 json_object_string_add(json_addr,
8800 "outgoingUpdatePrefixFilterList",
8801 filter->plist[FILTER_OUT].name);
8802
8803 /* distribute-list */
8804 if (filter->dlist[FILTER_IN].name)
8805 json_object_string_add(
8806 json_addr, "incomingUpdateNetworkFilterList",
8807 filter->dlist[FILTER_IN].name);
8808 if (filter->dlist[FILTER_OUT].name)
8809 json_object_string_add(
8810 json_addr, "outgoingUpdateNetworkFilterList",
8811 filter->dlist[FILTER_OUT].name);
8812
8813 /* filter-list. */
8814 if (filter->aslist[FILTER_IN].name)
8815 json_object_string_add(json_addr,
8816 "incomingUpdateAsPathFilterList",
8817 filter->aslist[FILTER_IN].name);
8818 if (filter->aslist[FILTER_OUT].name)
8819 json_object_string_add(json_addr,
8820 "outgoingUpdateAsPathFilterList",
8821 filter->aslist[FILTER_OUT].name);
8822
8823 /* route-map. */
8824 if (filter->map[RMAP_IN].name)
8825 json_object_string_add(
8826 json_addr, "routeMapForIncomingAdvertisements",
8827 filter->map[RMAP_IN].name);
8828 if (filter->map[RMAP_OUT].name)
8829 json_object_string_add(
8830 json_addr, "routeMapForOutgoingAdvertisements",
8831 filter->map[RMAP_OUT].name);
8832
8833 /* unsuppress-map */
8834 if (filter->usmap.name)
8835 json_object_string_add(json_addr,
8836 "selectiveUnsuppressRouteMap",
8837 filter->usmap.name);
8838
8839 /* Receive prefix count */
8840 json_object_int_add(json_addr, "acceptedPrefixCounter",
8841 p->pcount[afi][safi]);
50e05855
AD
8842 if (paf && PAF_SUBGRP(paf))
8843 json_object_int_add(json_addr, "sentPrefixCounter",
8844 (PAF_SUBGRP(paf))->scount);
d62a17ae 8845
8846 /* Maximum prefix */
8847 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8848 json_object_int_add(json_addr, "prefixAllowedMax",
8849 p->pmax[afi][safi]);
8850 if (CHECK_FLAG(p->af_flags[afi][safi],
8851 PEER_FLAG_MAX_PREFIX_WARNING))
8852 json_object_boolean_true_add(
8853 json_addr, "prefixAllowedMaxWarning");
8854 json_object_int_add(json_addr,
8855 "prefixAllowedWarningThresh",
8856 p->pmax_threshold[afi][safi]);
8857 if (p->pmax_restart[afi][safi])
8858 json_object_int_add(
8859 json_addr,
8860 "prefixAllowedRestartIntervalMsecs",
8861 p->pmax_restart[afi][safi] * 60000);
8862 }
8863 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8864 json_addr);
8865
8866 } else {
8867 filter = &p->filter[afi][safi];
8868
8869 vty_out(vty, " For address family: %s\n",
8870 afi_safi_print(afi, safi));
8871
8872 if (peer_group_active(p))
8873 vty_out(vty, " %s peer-group member\n",
8874 p->group->name);
8875
8876 paf = peer_af_find(p, afi, safi);
8877 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8878 vty_out(vty, " Update group %" PRIu64
8879 ", subgroup %" PRIu64 "\n",
d62a17ae 8880 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8881 vty_out(vty, " Packet Queue length %d\n",
8882 bpacket_queue_virtual_length(paf));
8883 } else {
8884 vty_out(vty, " Not part of any update group\n");
8885 }
8886 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8887 || CHECK_FLAG(p->af_cap[afi][safi],
8888 PEER_CAP_ORF_PREFIX_SM_RCV)
8889 || CHECK_FLAG(p->af_cap[afi][safi],
8890 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8891 || CHECK_FLAG(p->af_cap[afi][safi],
8892 PEER_CAP_ORF_PREFIX_RM_ADV)
8893 || CHECK_FLAG(p->af_cap[afi][safi],
8894 PEER_CAP_ORF_PREFIX_RM_RCV)
8895 || CHECK_FLAG(p->af_cap[afi][safi],
8896 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8897 vty_out(vty, " AF-dependant capabilities:\n");
8898
8899 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8900 || CHECK_FLAG(p->af_cap[afi][safi],
8901 PEER_CAP_ORF_PREFIX_SM_RCV)
8902 || CHECK_FLAG(p->af_cap[afi][safi],
8903 PEER_CAP_ORF_PREFIX_RM_ADV)
8904 || CHECK_FLAG(p->af_cap[afi][safi],
8905 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8906 vty_out(vty,
8907 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8908 ORF_TYPE_PREFIX);
8909 bgp_show_peer_afi_orf_cap(
8910 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8911 PEER_CAP_ORF_PREFIX_RM_ADV,
8912 PEER_CAP_ORF_PREFIX_SM_RCV,
8913 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8914 }
8915 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8916 || CHECK_FLAG(p->af_cap[afi][safi],
8917 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8918 || CHECK_FLAG(p->af_cap[afi][safi],
8919 PEER_CAP_ORF_PREFIX_RM_ADV)
8920 || CHECK_FLAG(p->af_cap[afi][safi],
8921 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8922 vty_out(vty,
8923 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8924 ORF_TYPE_PREFIX_OLD);
8925 bgp_show_peer_afi_orf_cap(
8926 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8927 PEER_CAP_ORF_PREFIX_RM_ADV,
8928 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8929 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8930 }
8931
8932 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8933 orf_pfx_count = prefix_bgp_show_prefix_list(
8934 NULL, afi, orf_pfx_name, use_json);
8935
8936 if (CHECK_FLAG(p->af_sflags[afi][safi],
8937 PEER_STATUS_ORF_PREFIX_SEND)
8938 || orf_pfx_count) {
8939 vty_out(vty, " Outbound Route Filter (ORF):");
8940 if (CHECK_FLAG(p->af_sflags[afi][safi],
8941 PEER_STATUS_ORF_PREFIX_SEND))
8942 vty_out(vty, " sent;");
8943 if (orf_pfx_count)
8944 vty_out(vty, " received (%d entries)",
8945 orf_pfx_count);
8946 vty_out(vty, "\n");
8947 }
8948 if (CHECK_FLAG(p->af_sflags[afi][safi],
8949 PEER_STATUS_ORF_WAIT_REFRESH))
8950 vty_out(vty,
8951 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8952
8953 if (CHECK_FLAG(p->af_flags[afi][safi],
8954 PEER_FLAG_REFLECTOR_CLIENT))
8955 vty_out(vty, " Route-Reflector Client\n");
8956 if (CHECK_FLAG(p->af_flags[afi][safi],
8957 PEER_FLAG_RSERVER_CLIENT))
8958 vty_out(vty, " Route-Server Client\n");
8959 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8960 vty_out(vty,
8961 " Inbound soft reconfiguration allowed\n");
8962
8963 if (CHECK_FLAG(p->af_flags[afi][safi],
8964 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8965 vty_out(vty,
8966 " Private AS numbers (all) replaced in updates to this neighbor\n");
8967 else if (CHECK_FLAG(p->af_flags[afi][safi],
8968 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8969 vty_out(vty,
8970 " Private AS numbers replaced in updates to this neighbor\n");
8971 else if (CHECK_FLAG(p->af_flags[afi][safi],
8972 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8973 vty_out(vty,
8974 " Private AS numbers (all) removed in updates to this neighbor\n");
8975 else if (CHECK_FLAG(p->af_flags[afi][safi],
8976 PEER_FLAG_REMOVE_PRIVATE_AS))
8977 vty_out(vty,
8978 " Private AS numbers removed in updates to this neighbor\n");
8979
dcc68b5e
MS
8980 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8981 vty_out(vty, " %s\n",
8982 bgp_addpath_names(p->addpath_type[afi][safi])
8983 ->human_description);
d62a17ae 8984
8985 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8986 vty_out(vty,
8987 " Override ASNs in outbound updates if aspath equals remote-as\n");
8988
8989 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8990 || CHECK_FLAG(p->af_flags[afi][safi],
8991 PEER_FLAG_FORCE_NEXTHOP_SELF))
8992 vty_out(vty, " NEXT_HOP is always this router\n");
8993 if (CHECK_FLAG(p->af_flags[afi][safi],
8994 PEER_FLAG_AS_PATH_UNCHANGED))
8995 vty_out(vty,
8996 " AS_PATH is propagated unchanged to this neighbor\n");
8997 if (CHECK_FLAG(p->af_flags[afi][safi],
8998 PEER_FLAG_NEXTHOP_UNCHANGED))
8999 vty_out(vty,
9000 " NEXT_HOP is propagated unchanged to this neighbor\n");
9001 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9002 vty_out(vty,
9003 " MED is propagated unchanged to this neighbor\n");
9004 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9005 || CHECK_FLAG(p->af_flags[afi][safi],
9006 PEER_FLAG_SEND_EXT_COMMUNITY)
9007 || CHECK_FLAG(p->af_flags[afi][safi],
9008 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9009 vty_out(vty,
9010 " Community attribute sent to this neighbor");
9011 if (CHECK_FLAG(p->af_flags[afi][safi],
9012 PEER_FLAG_SEND_COMMUNITY)
9013 && CHECK_FLAG(p->af_flags[afi][safi],
9014 PEER_FLAG_SEND_EXT_COMMUNITY)
9015 && CHECK_FLAG(p->af_flags[afi][safi],
9016 PEER_FLAG_SEND_LARGE_COMMUNITY))
9017 vty_out(vty, "(all)\n");
9018 else if (CHECK_FLAG(p->af_flags[afi][safi],
9019 PEER_FLAG_SEND_LARGE_COMMUNITY))
9020 vty_out(vty, "(large)\n");
9021 else if (CHECK_FLAG(p->af_flags[afi][safi],
9022 PEER_FLAG_SEND_EXT_COMMUNITY))
9023 vty_out(vty, "(extended)\n");
9024 else
9025 vty_out(vty, "(standard)\n");
9026 }
9027 if (CHECK_FLAG(p->af_flags[afi][safi],
9028 PEER_FLAG_DEFAULT_ORIGINATE)) {
9029 vty_out(vty, " Default information originate,");
9030
9031 if (p->default_rmap[afi][safi].name)
9032 vty_out(vty, " default route-map %s%s,",
9033 p->default_rmap[afi][safi].map ? "*"
9034 : "",
9035 p->default_rmap[afi][safi].name);
9036 if (paf && PAF_SUBGRP(paf)
9037 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9038 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9039 vty_out(vty, " default sent\n");
9040 else
9041 vty_out(vty, " default not sent\n");
9042 }
9043
dff8f48d
MK
9044 /* advertise-vni-all */
9045 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 9046 if (is_evpn_enabled())
dff8f48d
MK
9047 vty_out(vty, " advertise-all-vni\n");
9048 }
9049
d62a17ae 9050 if (filter->plist[FILTER_IN].name
9051 || filter->dlist[FILTER_IN].name
9052 || filter->aslist[FILTER_IN].name
9053 || filter->map[RMAP_IN].name)
9054 vty_out(vty, " Inbound path policy configured\n");
9055 if (filter->plist[FILTER_OUT].name
9056 || filter->dlist[FILTER_OUT].name
9057 || filter->aslist[FILTER_OUT].name
9058 || filter->map[RMAP_OUT].name || filter->usmap.name)
9059 vty_out(vty, " Outbound path policy configured\n");
9060
9061 /* prefix-list */
9062 if (filter->plist[FILTER_IN].name)
9063 vty_out(vty,
9064 " Incoming update prefix filter list is %s%s\n",
9065 filter->plist[FILTER_IN].plist ? "*" : "",
9066 filter->plist[FILTER_IN].name);
9067 if (filter->plist[FILTER_OUT].name)
9068 vty_out(vty,
9069 " Outgoing update prefix filter list is %s%s\n",
9070 filter->plist[FILTER_OUT].plist ? "*" : "",
9071 filter->plist[FILTER_OUT].name);
9072
9073 /* distribute-list */
9074 if (filter->dlist[FILTER_IN].name)
9075 vty_out(vty,
9076 " Incoming update network filter list is %s%s\n",
9077 filter->dlist[FILTER_IN].alist ? "*" : "",
9078 filter->dlist[FILTER_IN].name);
9079 if (filter->dlist[FILTER_OUT].name)
9080 vty_out(vty,
9081 " Outgoing update network filter list is %s%s\n",
9082 filter->dlist[FILTER_OUT].alist ? "*" : "",
9083 filter->dlist[FILTER_OUT].name);
9084
9085 /* filter-list. */
9086 if (filter->aslist[FILTER_IN].name)
9087 vty_out(vty,
9088 " Incoming update AS path filter list is %s%s\n",
9089 filter->aslist[FILTER_IN].aslist ? "*" : "",
9090 filter->aslist[FILTER_IN].name);
9091 if (filter->aslist[FILTER_OUT].name)
9092 vty_out(vty,
9093 " Outgoing update AS path filter list is %s%s\n",
9094 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9095 filter->aslist[FILTER_OUT].name);
9096
9097 /* route-map. */
9098 if (filter->map[RMAP_IN].name)
9099 vty_out(vty,
9100 " Route map for incoming advertisements is %s%s\n",
9101 filter->map[RMAP_IN].map ? "*" : "",
9102 filter->map[RMAP_IN].name);
9103 if (filter->map[RMAP_OUT].name)
9104 vty_out(vty,
9105 " Route map for outgoing advertisements is %s%s\n",
9106 filter->map[RMAP_OUT].map ? "*" : "",
9107 filter->map[RMAP_OUT].name);
9108
9109 /* unsuppress-map */
9110 if (filter->usmap.name)
9111 vty_out(vty,
9112 " Route map for selective unsuppress is %s%s\n",
9113 filter->usmap.map ? "*" : "",
9114 filter->usmap.name);
9115
9116 /* Receive prefix count */
9117 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9118
9119 /* Maximum prefix */
9120 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9121 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9122 p->pmax[afi][safi],
9123 CHECK_FLAG(p->af_flags[afi][safi],
9124 PEER_FLAG_MAX_PREFIX_WARNING)
9125 ? " (warning-only)"
9126 : "");
9127 vty_out(vty, " Threshold for warning message %d%%",
9128 p->pmax_threshold[afi][safi]);
9129 if (p->pmax_restart[afi][safi])
9130 vty_out(vty, ", restart interval %d min",
9131 p->pmax_restart[afi][safi]);
9132 vty_out(vty, "\n");
9133 }
9134
9135 vty_out(vty, "\n");
9136 }
9137}
9138
9f049418 9139static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 9140 json_object *json)
718e3744 9141{
d62a17ae 9142 struct bgp *bgp;
9143 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9144 char timebuf[BGP_UPTIME_LEN];
9145 char dn_flag[2];
9146 const char *subcode_str;
9147 const char *code_str;
9148 afi_t afi;
9149 safi_t safi;
d7c0a89a
QY
9150 uint16_t i;
9151 uint8_t *msg;
d62a17ae 9152 json_object *json_neigh = NULL;
9153 time_t epoch_tbuf;
718e3744 9154
d62a17ae 9155 bgp = p->bgp;
9156
9157 if (use_json)
9158 json_neigh = json_object_new_object();
9159
9160 memset(dn_flag, '\0', sizeof(dn_flag));
9161 if (!p->conf_if && peer_dynamic_neighbor(p))
9162 dn_flag[0] = '*';
9163
9164 if (!use_json) {
9165 if (p->conf_if) /* Configured interface name. */
9166 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9167 BGP_PEER_SU_UNSPEC(p)
9168 ? "None"
9169 : sockunion2str(&p->su, buf,
9170 SU_ADDRSTRLEN));
9171 else /* Configured IP address. */
9172 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9173 p->host);
9174 }
9175
9176 if (use_json) {
9177 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9178 json_object_string_add(json_neigh, "bgpNeighborAddr",
9179 "none");
9180 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9181 json_object_string_add(
9182 json_neigh, "bgpNeighborAddr",
9183 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9184
9185 json_object_int_add(json_neigh, "remoteAs", p->as);
9186
9187 if (p->change_local_as)
9188 json_object_int_add(json_neigh, "localAs",
9189 p->change_local_as);
9190 else
9191 json_object_int_add(json_neigh, "localAs", p->local_as);
9192
9193 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9194 json_object_boolean_true_add(json_neigh,
9195 "localAsNoPrepend");
9196
9197 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9198 json_object_boolean_true_add(json_neigh,
9199 "localAsReplaceAs");
9200 } else {
9201 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9202 || (p->as_type == AS_INTERNAL))
9203 vty_out(vty, "remote AS %u, ", p->as);
9204 else
9205 vty_out(vty, "remote AS Unspecified, ");
9206 vty_out(vty, "local AS %u%s%s, ",
9207 p->change_local_as ? p->change_local_as : p->local_as,
9208 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9209 ? " no-prepend"
9210 : "",
9211 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9212 ? " replace-as"
9213 : "");
9214 }
9215 /* peer type internal, external, confed-internal or confed-external */
9216 if (p->as == p->local_as) {
9217 if (use_json) {
9218 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9219 json_object_boolean_true_add(
9220 json_neigh, "nbrConfedInternalLink");
9221 else
9222 json_object_boolean_true_add(json_neigh,
9223 "nbrInternalLink");
9224 } else {
9225 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9226 vty_out(vty, "confed-internal link\n");
9227 else
9228 vty_out(vty, "internal link\n");
9229 }
9230 } else {
9231 if (use_json) {
9232 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9233 json_object_boolean_true_add(
9234 json_neigh, "nbrConfedExternalLink");
9235 else
9236 json_object_boolean_true_add(json_neigh,
9237 "nbrExternalLink");
9238 } else {
9239 if (bgp_confederation_peers_check(bgp, p->as))
9240 vty_out(vty, "confed-external link\n");
9241 else
9242 vty_out(vty, "external link\n");
9243 }
9244 }
9245
9246 /* Description. */
9247 if (p->desc) {
9248 if (use_json)
9249 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9250 else
9251 vty_out(vty, " Description: %s\n", p->desc);
9252 }
9253
9254 if (p->hostname) {
9255 if (use_json) {
9256 if (p->hostname)
9257 json_object_string_add(json_neigh, "hostname",
9258 p->hostname);
9259
9260 if (p->domainname)
9261 json_object_string_add(json_neigh, "domainname",
9262 p->domainname);
9263 } else {
9264 if (p->domainname && (p->domainname[0] != '\0'))
9265 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9266 p->domainname);
9267 else
9268 vty_out(vty, "Hostname: %s\n", p->hostname);
9269 }
9270 }
9271
9272 /* Peer-group */
9273 if (p->group) {
9274 if (use_json) {
9275 json_object_string_add(json_neigh, "peerGroup",
9276 p->group->name);
9277
9278 if (dn_flag[0]) {
9279 struct prefix prefix, *range = NULL;
9280
9281 sockunion2hostprefix(&(p->su), &prefix);
9282 range = peer_group_lookup_dynamic_neighbor_range(
9283 p->group, &prefix);
9284
9285 if (range) {
9286 prefix2str(range, buf1, sizeof(buf1));
9287 json_object_string_add(
9288 json_neigh,
9289 "peerSubnetRangeGroup", buf1);
9290 }
9291 }
9292 } else {
9293 vty_out(vty,
9294 " Member of peer-group %s for session parameters\n",
9295 p->group->name);
9296
9297 if (dn_flag[0]) {
9298 struct prefix prefix, *range = NULL;
9299
9300 sockunion2hostprefix(&(p->su), &prefix);
9301 range = peer_group_lookup_dynamic_neighbor_range(
9302 p->group, &prefix);
9303
9304 if (range) {
9305 prefix2str(range, buf1, sizeof(buf1));
9306 vty_out(vty,
9307 " Belongs to the subnet range group: %s\n",
9308 buf1);
9309 }
9310 }
9311 }
9312 }
9313
9314 if (use_json) {
9315 /* Administrative shutdown. */
9316 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9317 json_object_boolean_true_add(json_neigh,
9318 "adminShutDown");
9319
9320 /* BGP Version. */
9321 json_object_int_add(json_neigh, "bgpVersion", 4);
9322 json_object_string_add(
9323 json_neigh, "remoteRouterId",
9324 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
9325 json_object_string_add(
9326 json_neigh, "localRouterId",
9327 inet_ntop(AF_INET, &bgp->router_id, buf1,
9328 sizeof(buf1)));
d62a17ae 9329
9330 /* Confederation */
9331 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9332 && bgp_confederation_peers_check(bgp, p->as))
9333 json_object_boolean_true_add(json_neigh,
9334 "nbrCommonAdmin");
9335
9336 /* Status. */
9337 json_object_string_add(
9338 json_neigh, "bgpState",
9339 lookup_msg(bgp_status_msg, p->status, NULL));
9340
9341 if (p->status == Established) {
9342 time_t uptime;
d62a17ae 9343
9344 uptime = bgp_clock();
9345 uptime -= p->uptime;
d62a17ae 9346 epoch_tbuf = time(NULL) - uptime;
9347
bee57a7a 9348#if CONFDATE > 20200101
a4d82a8a
PZ
9349 CPP_NOTICE(
9350 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9351#endif
9352 /*
9353 * bgpTimerUp was miliseconds that was accurate
9354 * up to 1 day, then the value returned
9355 * became garbage. So in order to provide
9356 * some level of backwards compatability,
9357 * we still provde the data, but now
9358 * we are returning the correct value
9359 * and also adding a new bgpTimerUpMsec
9360 * which will allow us to deprecate
9361 * this eventually
9362 */
d62a17ae 9363 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9364 uptime * 1000);
d3c7efed
DS
9365 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9366 uptime * 1000);
d62a17ae 9367 json_object_string_add(json_neigh, "bgpTimerUpString",
9368 peer_uptime(p->uptime, timebuf,
9369 BGP_UPTIME_LEN, 0,
9370 NULL));
9371 json_object_int_add(json_neigh,
9372 "bgpTimerUpEstablishedEpoch",
9373 epoch_tbuf);
9374 }
9375
9376 else if (p->status == Active) {
9377 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9378 json_object_string_add(json_neigh, "bgpStateIs",
9379 "passive");
9380 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9381 json_object_string_add(json_neigh, "bgpStateIs",
9382 "passiveNSF");
9383 }
9384
9385 /* read timer */
9386 time_t uptime;
9387 struct tm *tm;
9388
9389 uptime = bgp_clock();
9390 uptime -= p->readtime;
9391 tm = gmtime(&uptime);
9392 json_object_int_add(json_neigh, "bgpTimerLastRead",
9393 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9394 + (tm->tm_hour * 3600000));
9395
9396 uptime = bgp_clock();
9397 uptime -= p->last_write;
9398 tm = gmtime(&uptime);
9399 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9400 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9401 + (tm->tm_hour * 3600000));
9402
9403 uptime = bgp_clock();
9404 uptime -= p->update_time;
9405 tm = gmtime(&uptime);
9406 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9407 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9408 + (tm->tm_hour * 3600000));
9409
9410 /* Configured timer values. */
9411 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9412 p->v_holdtime * 1000);
9413 json_object_int_add(json_neigh,
9414 "bgpTimerKeepAliveIntervalMsecs",
9415 p->v_keepalive * 1000);
b90a8e13 9416 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9417 json_object_int_add(json_neigh,
9418 "bgpTimerConfiguredHoldTimeMsecs",
9419 p->holdtime * 1000);
9420 json_object_int_add(
9421 json_neigh,
9422 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9423 p->keepalive * 1000);
d25e4efc 9424 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9425 || (bgp->default_keepalive
9426 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9427 json_object_int_add(json_neigh,
9428 "bgpTimerConfiguredHoldTimeMsecs",
9429 bgp->default_holdtime);
9430 json_object_int_add(
9431 json_neigh,
9432 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9433 bgp->default_keepalive);
d62a17ae 9434 }
9435 } else {
9436 /* Administrative shutdown. */
9437 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9438 vty_out(vty, " Administratively shut down\n");
9439
9440 /* BGP Version. */
9441 vty_out(vty, " BGP version 4");
0e38aeb4 9442 vty_out(vty, ", remote router ID %s",
d62a17ae 9443 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
9444 vty_out(vty, ", local router ID %s\n",
9445 inet_ntop(AF_INET, &bgp->router_id, buf1,
9446 sizeof(buf1)));
d62a17ae 9447
9448 /* Confederation */
9449 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9450 && bgp_confederation_peers_check(bgp, p->as))
9451 vty_out(vty,
9452 " Neighbor under common administration\n");
9453
9454 /* Status. */
9455 vty_out(vty, " BGP state = %s",
9456 lookup_msg(bgp_status_msg, p->status, NULL));
9457
9458 if (p->status == Established)
9459 vty_out(vty, ", up for %8s",
9460 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9461 0, NULL));
9462
9463 else if (p->status == Active) {
9464 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9465 vty_out(vty, " (passive)");
9466 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9467 vty_out(vty, " (NSF passive)");
9468 }
9469 vty_out(vty, "\n");
9470
9471 /* read timer */
9472 vty_out(vty, " Last read %s",
9473 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9474 NULL));
9475 vty_out(vty, ", Last write %s\n",
9476 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9477 NULL));
9478
9479 /* Configured timer values. */
9480 vty_out(vty,
9481 " Hold time is %d, keepalive interval is %d seconds\n",
9482 p->v_holdtime, p->v_keepalive);
b90a8e13 9483 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9484 vty_out(vty, " Configured hold time is %d",
9485 p->holdtime);
9486 vty_out(vty, ", keepalive interval is %d seconds\n",
9487 p->keepalive);
d25e4efc 9488 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9489 || (bgp->default_keepalive
9490 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9491 vty_out(vty, " Configured hold time is %d",
9492 bgp->default_holdtime);
9493 vty_out(vty, ", keepalive interval is %d seconds\n",
9494 bgp->default_keepalive);
d62a17ae 9495 }
9496 }
9497 /* Capability. */
9498 if (p->status == Established) {
9499 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9500 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9501 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9502 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9503 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9504 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9505 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9506 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9507 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9508 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9509 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9510 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9511 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9512 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9513 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9514 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9515 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9516 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9517 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9518 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9519 if (use_json) {
9520 json_object *json_cap = NULL;
9521
9522 json_cap = json_object_new_object();
9523
9524 /* AS4 */
9525 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9526 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9527 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9528 && CHECK_FLAG(p->cap,
9529 PEER_CAP_AS4_RCV))
9530 json_object_string_add(
9531 json_cap, "4byteAs",
9532 "advertisedAndReceived");
9533 else if (CHECK_FLAG(p->cap,
9534 PEER_CAP_AS4_ADV))
9535 json_object_string_add(
9536 json_cap, "4byteAs",
9537 "advertised");
9538 else if (CHECK_FLAG(p->cap,
9539 PEER_CAP_AS4_RCV))
9540 json_object_string_add(
9541 json_cap, "4byteAs",
9542 "received");
9543 }
9544
9545 /* AddPath */
9546 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9547 || CHECK_FLAG(p->cap,
9548 PEER_CAP_ADDPATH_ADV)) {
9549 json_object *json_add = NULL;
9550 const char *print_store;
9551
9552 json_add = json_object_new_object();
9553
05c7a1cc
QY
9554 FOREACH_AFI_SAFI (afi, safi) {
9555 json_object *json_sub = NULL;
9556 json_sub =
9557 json_object_new_object();
9558 print_store = afi_safi_print(
9559 afi, safi);
d62a17ae 9560
05c7a1cc
QY
9561 if (CHECK_FLAG(
9562 p->af_cap[afi]
9563 [safi],
9564 PEER_CAP_ADDPATH_AF_TX_ADV)
9565 || CHECK_FLAG(
9566 p->af_cap[afi]
9567 [safi],
9568 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9569 if (CHECK_FLAG(
9570 p->af_cap
9571 [afi]
9572 [safi],
9573 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9574 && CHECK_FLAG(
d62a17ae 9575 p->af_cap
9576 [afi]
9577 [safi],
05c7a1cc
QY
9578 PEER_CAP_ADDPATH_AF_TX_RCV))
9579 json_object_boolean_true_add(
9580 json_sub,
9581 "txAdvertisedAndReceived");
9582 else if (
9583 CHECK_FLAG(
9584 p->af_cap
9585 [afi]
9586 [safi],
9587 PEER_CAP_ADDPATH_AF_TX_ADV))
9588 json_object_boolean_true_add(
9589 json_sub,
9590 "txAdvertised");
9591 else if (
9592 CHECK_FLAG(
9593 p->af_cap
9594 [afi]
9595 [safi],
9596 PEER_CAP_ADDPATH_AF_TX_RCV))
9597 json_object_boolean_true_add(
9598 json_sub,
9599 "txReceived");
9600 }
d62a17ae 9601
05c7a1cc
QY
9602 if (CHECK_FLAG(
9603 p->af_cap[afi]
9604 [safi],
9605 PEER_CAP_ADDPATH_AF_RX_ADV)
9606 || CHECK_FLAG(
9607 p->af_cap[afi]
9608 [safi],
9609 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9610 if (CHECK_FLAG(
9611 p->af_cap
9612 [afi]
9613 [safi],
9614 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9615 && CHECK_FLAG(
d62a17ae 9616 p->af_cap
9617 [afi]
9618 [safi],
9619 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9620 json_object_boolean_true_add(
9621 json_sub,
9622 "rxAdvertisedAndReceived");
9623 else if (
9624 CHECK_FLAG(
9625 p->af_cap
9626 [afi]
9627 [safi],
9628 PEER_CAP_ADDPATH_AF_RX_ADV))
9629 json_object_boolean_true_add(
9630 json_sub,
9631 "rxAdvertised");
9632 else if (
9633 CHECK_FLAG(
9634 p->af_cap
9635 [afi]
9636 [safi],
9637 PEER_CAP_ADDPATH_AF_RX_RCV))
9638 json_object_boolean_true_add(
9639 json_sub,
9640 "rxReceived");
d62a17ae 9641 }
9642
05c7a1cc
QY
9643 if (CHECK_FLAG(
9644 p->af_cap[afi]
9645 [safi],
9646 PEER_CAP_ADDPATH_AF_TX_ADV)
9647 || CHECK_FLAG(
9648 p->af_cap[afi]
9649 [safi],
9650 PEER_CAP_ADDPATH_AF_TX_RCV)
9651 || CHECK_FLAG(
9652 p->af_cap[afi]
9653 [safi],
9654 PEER_CAP_ADDPATH_AF_RX_ADV)
9655 || CHECK_FLAG(
9656 p->af_cap[afi]
9657 [safi],
9658 PEER_CAP_ADDPATH_AF_RX_RCV))
9659 json_object_object_add(
9660 json_add,
9661 print_store,
9662 json_sub);
9663 else
9664 json_object_free(
9665 json_sub);
9666 }
9667
d62a17ae 9668 json_object_object_add(
9669 json_cap, "addPath", json_add);
9670 }
9671
9672 /* Dynamic */
9673 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9674 || CHECK_FLAG(p->cap,
9675 PEER_CAP_DYNAMIC_ADV)) {
9676 if (CHECK_FLAG(p->cap,
9677 PEER_CAP_DYNAMIC_ADV)
9678 && CHECK_FLAG(p->cap,
9679 PEER_CAP_DYNAMIC_RCV))
9680 json_object_string_add(
9681 json_cap, "dynamic",
9682 "advertisedAndReceived");
9683 else if (CHECK_FLAG(
9684 p->cap,
9685 PEER_CAP_DYNAMIC_ADV))
9686 json_object_string_add(
9687 json_cap, "dynamic",
9688 "advertised");
9689 else if (CHECK_FLAG(
9690 p->cap,
9691 PEER_CAP_DYNAMIC_RCV))
9692 json_object_string_add(
9693 json_cap, "dynamic",
9694 "received");
9695 }
9696
9697 /* Extended nexthop */
9698 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9699 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9700 json_object *json_nxt = NULL;
9701 const char *print_store;
9702
9703
9704 if (CHECK_FLAG(p->cap,
9705 PEER_CAP_ENHE_ADV)
9706 && CHECK_FLAG(p->cap,
9707 PEER_CAP_ENHE_RCV))
9708 json_object_string_add(
9709 json_cap,
9710 "extendedNexthop",
9711 "advertisedAndReceived");
9712 else if (CHECK_FLAG(p->cap,
9713 PEER_CAP_ENHE_ADV))
9714 json_object_string_add(
9715 json_cap,
9716 "extendedNexthop",
9717 "advertised");
9718 else if (CHECK_FLAG(p->cap,
9719 PEER_CAP_ENHE_RCV))
9720 json_object_string_add(
9721 json_cap,
9722 "extendedNexthop",
9723 "received");
9724
9725 if (CHECK_FLAG(p->cap,
9726 PEER_CAP_ENHE_RCV)) {
9727 json_nxt =
9728 json_object_new_object();
9729
9730 for (safi = SAFI_UNICAST;
9731 safi < SAFI_MAX; safi++) {
9732 if (CHECK_FLAG(
9733 p->af_cap
9734 [AFI_IP]
9735 [safi],
9736 PEER_CAP_ENHE_AF_RCV)) {
9737 print_store = afi_safi_print(
9738 AFI_IP,
9739 safi);
9740 json_object_string_add(
9741 json_nxt,
9742 print_store,
54f29523 9743 "recieved"); /* misspelled for compatibility */
d62a17ae 9744 }
9745 }
9746 json_object_object_add(
9747 json_cap,
9748 "extendedNexthopFamililesByPeer",
9749 json_nxt);
9750 }
9751 }
9752
9753 /* Route Refresh */
9754 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9755 || CHECK_FLAG(p->cap,
9756 PEER_CAP_REFRESH_NEW_RCV)
9757 || CHECK_FLAG(p->cap,
9758 PEER_CAP_REFRESH_OLD_RCV)) {
9759 if (CHECK_FLAG(p->cap,
9760 PEER_CAP_REFRESH_ADV)
9761 && (CHECK_FLAG(
9762 p->cap,
9763 PEER_CAP_REFRESH_NEW_RCV)
9764 || CHECK_FLAG(
9765 p->cap,
9766 PEER_CAP_REFRESH_OLD_RCV))) {
9767 if (CHECK_FLAG(
9768 p->cap,
9769 PEER_CAP_REFRESH_OLD_RCV)
9770 && CHECK_FLAG(
9771 p->cap,
9772 PEER_CAP_REFRESH_NEW_RCV))
9773 json_object_string_add(
9774 json_cap,
9775 "routeRefresh",
9776 "advertisedAndReceivedOldNew");
9777 else {
9778 if (CHECK_FLAG(
9779 p->cap,
9780 PEER_CAP_REFRESH_OLD_RCV))
9781 json_object_string_add(
9782 json_cap,
9783 "routeRefresh",
9784 "advertisedAndReceivedOld");
9785 else
9786 json_object_string_add(
9787 json_cap,
9788 "routeRefresh",
9789 "advertisedAndReceivedNew");
9790 }
9791 } else if (
9792 CHECK_FLAG(
9793 p->cap,
9794 PEER_CAP_REFRESH_ADV))
9795 json_object_string_add(
9796 json_cap,
9797 "routeRefresh",
9798 "advertised");
9799 else if (
9800 CHECK_FLAG(
9801 p->cap,
9802 PEER_CAP_REFRESH_NEW_RCV)
9803 || CHECK_FLAG(
9804 p->cap,
9805 PEER_CAP_REFRESH_OLD_RCV))
9806 json_object_string_add(
9807 json_cap,
9808 "routeRefresh",
9809 "received");
9810 }
9811
9812 /* Multiprotocol Extensions */
9813 json_object *json_multi = NULL;
9814 json_multi = json_object_new_object();
9815
05c7a1cc
QY
9816 FOREACH_AFI_SAFI (afi, safi) {
9817 if (p->afc_adv[afi][safi]
9818 || p->afc_recv[afi][safi]) {
9819 json_object *json_exten = NULL;
9820 json_exten =
9821 json_object_new_object();
9822
d62a17ae 9823 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9824 && p->afc_recv[afi][safi])
9825 json_object_boolean_true_add(
9826 json_exten,
9827 "advertisedAndReceived");
9828 else if (p->afc_adv[afi][safi])
9829 json_object_boolean_true_add(
9830 json_exten,
9831 "advertised");
9832 else if (p->afc_recv[afi][safi])
9833 json_object_boolean_true_add(
9834 json_exten,
9835 "received");
d62a17ae 9836
05c7a1cc
QY
9837 json_object_object_add(
9838 json_multi,
9839 afi_safi_print(afi,
9840 safi),
9841 json_exten);
d62a17ae 9842 }
9843 }
9844 json_object_object_add(
9845 json_cap, "multiprotocolExtensions",
9846 json_multi);
9847
d77114b7 9848 /* Hostname capabilities */
60466a63 9849 json_object *json_hname = NULL;
d77114b7
MK
9850
9851 json_hname = json_object_new_object();
9852
9853 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9854 json_object_string_add(
60466a63
QY
9855 json_hname, "advHostName",
9856 bgp->peer_self->hostname
9857 ? bgp->peer_self
9858 ->hostname
d77114b7
MK
9859 : "n/a");
9860 json_object_string_add(
60466a63
QY
9861 json_hname, "advDomainName",
9862 bgp->peer_self->domainname
9863 ? bgp->peer_self
9864 ->domainname
d77114b7
MK
9865 : "n/a");
9866 }
9867
9868
9869 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9870 json_object_string_add(
60466a63
QY
9871 json_hname, "rcvHostName",
9872 p->hostname ? p->hostname
9873 : "n/a");
d77114b7 9874 json_object_string_add(
60466a63
QY
9875 json_hname, "rcvDomainName",
9876 p->domainname ? p->domainname
9877 : "n/a");
d77114b7
MK
9878 }
9879
60466a63 9880 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9881 json_hname);
9882
d62a17ae 9883 /* Gracefull Restart */
9884 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9885 || CHECK_FLAG(p->cap,
9886 PEER_CAP_RESTART_ADV)) {
9887 if (CHECK_FLAG(p->cap,
9888 PEER_CAP_RESTART_ADV)
9889 && CHECK_FLAG(p->cap,
9890 PEER_CAP_RESTART_RCV))
9891 json_object_string_add(
9892 json_cap,
9893 "gracefulRestart",
9894 "advertisedAndReceived");
9895 else if (CHECK_FLAG(
9896 p->cap,
9897 PEER_CAP_RESTART_ADV))
9898 json_object_string_add(
9899 json_cap,
9900 "gracefulRestartCapability",
9901 "advertised");
9902 else if (CHECK_FLAG(
9903 p->cap,
9904 PEER_CAP_RESTART_RCV))
9905 json_object_string_add(
9906 json_cap,
9907 "gracefulRestartCapability",
9908 "received");
9909
9910 if (CHECK_FLAG(p->cap,
9911 PEER_CAP_RESTART_RCV)) {
9912 int restart_af_count = 0;
9913 json_object *json_restart =
9914 NULL;
9915 json_restart =
9916 json_object_new_object();
9917
9918 json_object_int_add(
9919 json_cap,
9920 "gracefulRestartRemoteTimerMsecs",
9921 p->v_gr_restart * 1000);
9922
05c7a1cc
QY
9923 FOREACH_AFI_SAFI (afi, safi) {
9924 if (CHECK_FLAG(
9925 p->af_cap
9926 [afi]
9927 [safi],
9928 PEER_CAP_RESTART_AF_RCV)) {
9929 json_object *
9930 json_sub =
9931 NULL;
9932 json_sub =
9933 json_object_new_object();
9934
d62a17ae 9935 if (CHECK_FLAG(
9936 p->af_cap
9937 [afi]
9938 [safi],
05c7a1cc
QY
9939 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9940 json_object_boolean_true_add(
9941 json_sub,
9942 "preserved");
9943 restart_af_count++;
9944 json_object_object_add(
9945 json_restart,
9946 afi_safi_print(
9947 afi,
9948 safi),
9949 json_sub);
d62a17ae 9950 }
9951 }
9952 if (!restart_af_count) {
9953 json_object_string_add(
9954 json_cap,
9955 "addressFamiliesByPeer",
9956 "none");
9957 json_object_free(
9958 json_restart);
9959 } else
9960 json_object_object_add(
9961 json_cap,
9962 "addressFamiliesByPeer",
9963 json_restart);
9964 }
9965 }
9966 json_object_object_add(json_neigh,
9967 "neighborCapabilities",
9968 json_cap);
9969 } else {
9970 vty_out(vty, " Neighbor capabilities:\n");
9971
9972 /* AS4 */
9973 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9974 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9975 vty_out(vty, " 4 Byte AS:");
9976 if (CHECK_FLAG(p->cap,
9977 PEER_CAP_AS4_ADV))
9978 vty_out(vty, " advertised");
9979 if (CHECK_FLAG(p->cap,
9980 PEER_CAP_AS4_RCV))
9981 vty_out(vty, " %sreceived",
9982 CHECK_FLAG(
9983 p->cap,
9984 PEER_CAP_AS4_ADV)
9985 ? "and "
9986 : "");
9987 vty_out(vty, "\n");
9988 }
9989
9990 /* AddPath */
9991 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9992 || CHECK_FLAG(p->cap,
9993 PEER_CAP_ADDPATH_ADV)) {
9994 vty_out(vty, " AddPath:\n");
9995
05c7a1cc
QY
9996 FOREACH_AFI_SAFI (afi, safi) {
9997 if (CHECK_FLAG(
9998 p->af_cap[afi]
9999 [safi],
10000 PEER_CAP_ADDPATH_AF_TX_ADV)
10001 || CHECK_FLAG(
10002 p->af_cap[afi]
10003 [safi],
10004 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10005 vty_out(vty,
10006 " %s: TX ",
10007 afi_safi_print(
10008 afi,
10009 safi));
10010
d62a17ae 10011 if (CHECK_FLAG(
10012 p->af_cap
10013 [afi]
10014 [safi],
05c7a1cc 10015 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 10016 vty_out(vty,
05c7a1cc 10017 "advertised %s",
d62a17ae 10018 afi_safi_print(
10019 afi,
10020 safi));
10021
05c7a1cc
QY
10022 if (CHECK_FLAG(
10023 p->af_cap
10024 [afi]
10025 [safi],
10026 PEER_CAP_ADDPATH_AF_TX_RCV))
10027 vty_out(vty,
10028 "%sreceived",
10029 CHECK_FLAG(
10030 p->af_cap
10031 [afi]
10032 [safi],
10033 PEER_CAP_ADDPATH_AF_TX_ADV)
10034 ? " and "
10035 : "");
d62a17ae 10036
05c7a1cc
QY
10037 vty_out(vty, "\n");
10038 }
d62a17ae 10039
05c7a1cc
QY
10040 if (CHECK_FLAG(
10041 p->af_cap[afi]
10042 [safi],
10043 PEER_CAP_ADDPATH_AF_RX_ADV)
10044 || CHECK_FLAG(
10045 p->af_cap[afi]
10046 [safi],
10047 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10048 vty_out(vty,
10049 " %s: RX ",
10050 afi_safi_print(
10051 afi,
10052 safi));
d62a17ae 10053
10054 if (CHECK_FLAG(
10055 p->af_cap
10056 [afi]
10057 [safi],
05c7a1cc 10058 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 10059 vty_out(vty,
05c7a1cc 10060 "advertised %s",
d62a17ae 10061 afi_safi_print(
10062 afi,
10063 safi));
10064
05c7a1cc
QY
10065 if (CHECK_FLAG(
10066 p->af_cap
10067 [afi]
10068 [safi],
10069 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 10070 vty_out(vty,
05c7a1cc
QY
10071 "%sreceived",
10072 CHECK_FLAG(
10073 p->af_cap
10074 [afi]
10075 [safi],
10076 PEER_CAP_ADDPATH_AF_RX_ADV)
10077 ? " and "
10078 : "");
10079
10080 vty_out(vty, "\n");
d62a17ae 10081 }
05c7a1cc 10082 }
d62a17ae 10083 }
10084
10085 /* Dynamic */
10086 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10087 || CHECK_FLAG(p->cap,
10088 PEER_CAP_DYNAMIC_ADV)) {
10089 vty_out(vty, " Dynamic:");
10090 if (CHECK_FLAG(p->cap,
10091 PEER_CAP_DYNAMIC_ADV))
10092 vty_out(vty, " advertised");
10093 if (CHECK_FLAG(p->cap,
10094 PEER_CAP_DYNAMIC_RCV))
10095 vty_out(vty, " %sreceived",
10096 CHECK_FLAG(
10097 p->cap,
10098 PEER_CAP_DYNAMIC_ADV)
10099 ? "and "
10100 : "");
10101 vty_out(vty, "\n");
10102 }
10103
10104 /* Extended nexthop */
10105 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10106 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10107 vty_out(vty, " Extended nexthop:");
10108 if (CHECK_FLAG(p->cap,
10109 PEER_CAP_ENHE_ADV))
10110 vty_out(vty, " advertised");
10111 if (CHECK_FLAG(p->cap,
10112 PEER_CAP_ENHE_RCV))
10113 vty_out(vty, " %sreceived",
10114 CHECK_FLAG(
10115 p->cap,
10116 PEER_CAP_ENHE_ADV)
10117 ? "and "
10118 : "");
10119 vty_out(vty, "\n");
10120
10121 if (CHECK_FLAG(p->cap,
10122 PEER_CAP_ENHE_RCV)) {
10123 vty_out(vty,
10124 " Address families by peer:\n ");
10125 for (safi = SAFI_UNICAST;
10126 safi < SAFI_MAX; safi++)
10127 if (CHECK_FLAG(
10128 p->af_cap
10129 [AFI_IP]
10130 [safi],
10131 PEER_CAP_ENHE_AF_RCV))
10132 vty_out(vty,
10133 " %s\n",
10134 afi_safi_print(
10135 AFI_IP,
10136 safi));
10137 }
10138 }
10139
10140 /* Route Refresh */
10141 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10142 || CHECK_FLAG(p->cap,
10143 PEER_CAP_REFRESH_NEW_RCV)
10144 || CHECK_FLAG(p->cap,
10145 PEER_CAP_REFRESH_OLD_RCV)) {
10146 vty_out(vty, " Route refresh:");
10147 if (CHECK_FLAG(p->cap,
10148 PEER_CAP_REFRESH_ADV))
10149 vty_out(vty, " advertised");
10150 if (CHECK_FLAG(p->cap,
10151 PEER_CAP_REFRESH_NEW_RCV)
10152 || CHECK_FLAG(
10153 p->cap,
10154 PEER_CAP_REFRESH_OLD_RCV))
10155 vty_out(vty, " %sreceived(%s)",
10156 CHECK_FLAG(
10157 p->cap,
10158 PEER_CAP_REFRESH_ADV)
10159 ? "and "
10160 : "",
10161 (CHECK_FLAG(
10162 p->cap,
10163 PEER_CAP_REFRESH_OLD_RCV)
10164 && CHECK_FLAG(
10165 p->cap,
10166 PEER_CAP_REFRESH_NEW_RCV))
10167 ? "old & new"
10168 : CHECK_FLAG(
10169 p->cap,
10170 PEER_CAP_REFRESH_OLD_RCV)
10171 ? "old"
10172 : "new");
10173
10174 vty_out(vty, "\n");
10175 }
10176
10177 /* Multiprotocol Extensions */
05c7a1cc
QY
10178 FOREACH_AFI_SAFI (afi, safi)
10179 if (p->afc_adv[afi][safi]
10180 || p->afc_recv[afi][safi]) {
10181 vty_out(vty,
10182 " Address Family %s:",
10183 afi_safi_print(afi,
10184 safi));
10185 if (p->afc_adv[afi][safi])
d62a17ae 10186 vty_out(vty,
05c7a1cc
QY
10187 " advertised");
10188 if (p->afc_recv[afi][safi])
10189 vty_out(vty,
10190 " %sreceived",
10191 p->afc_adv[afi]
10192 [safi]
10193 ? "and "
10194 : "");
10195 vty_out(vty, "\n");
10196 }
d62a17ae 10197
10198 /* Hostname capability */
60466a63 10199 vty_out(vty, " Hostname Capability:");
d77114b7
MK
10200
10201 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
10202 vty_out(vty,
10203 " advertised (name: %s,domain name: %s)",
60466a63
QY
10204 bgp->peer_self->hostname
10205 ? bgp->peer_self
10206 ->hostname
d77114b7 10207 : "n/a",
60466a63
QY
10208 bgp->peer_self->domainname
10209 ? bgp->peer_self
10210 ->domainname
d77114b7
MK
10211 : "n/a");
10212 } else {
10213 vty_out(vty, " not advertised");
d62a17ae 10214 }
10215
d77114b7 10216 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10217 vty_out(vty,
10218 " received (name: %s,domain name: %s)",
60466a63
QY
10219 p->hostname ? p->hostname
10220 : "n/a",
10221 p->domainname ? p->domainname
10222 : "n/a");
d77114b7
MK
10223 } else {
10224 vty_out(vty, " not received");
10225 }
10226
10227 vty_out(vty, "\n");
10228
d62a17ae 10229 /* Gracefull Restart */
10230 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10231 || CHECK_FLAG(p->cap,
10232 PEER_CAP_RESTART_ADV)) {
10233 vty_out(vty,
10234 " Graceful Restart Capabilty:");
10235 if (CHECK_FLAG(p->cap,
10236 PEER_CAP_RESTART_ADV))
10237 vty_out(vty, " advertised");
10238 if (CHECK_FLAG(p->cap,
10239 PEER_CAP_RESTART_RCV))
10240 vty_out(vty, " %sreceived",
10241 CHECK_FLAG(
10242 p->cap,
10243 PEER_CAP_RESTART_ADV)
10244 ? "and "
10245 : "");
10246 vty_out(vty, "\n");
10247
10248 if (CHECK_FLAG(p->cap,
10249 PEER_CAP_RESTART_RCV)) {
10250 int restart_af_count = 0;
10251
10252 vty_out(vty,
10253 " Remote Restart timer is %d seconds\n",
10254 p->v_gr_restart);
10255 vty_out(vty,
10256 " Address families by peer:\n ");
10257
05c7a1cc
QY
10258 FOREACH_AFI_SAFI (afi, safi)
10259 if (CHECK_FLAG(
10260 p->af_cap
10261 [afi]
10262 [safi],
10263 PEER_CAP_RESTART_AF_RCV)) {
10264 vty_out(vty,
10265 "%s%s(%s)",
10266 restart_af_count
10267 ? ", "
10268 : "",
10269 afi_safi_print(
10270 afi,
10271 safi),
10272 CHECK_FLAG(
10273 p->af_cap
10274 [afi]
10275 [safi],
10276 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10277 ? "preserved"
10278 : "not preserved");
10279 restart_af_count++;
10280 }
d62a17ae 10281 if (!restart_af_count)
10282 vty_out(vty, "none");
10283 vty_out(vty, "\n");
10284 }
10285 }
10286 }
10287 }
10288 }
10289
10290 /* graceful restart information */
10291 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10292 || p->t_gr_stale) {
10293 json_object *json_grace = NULL;
10294 json_object *json_grace_send = NULL;
10295 json_object *json_grace_recv = NULL;
10296 int eor_send_af_count = 0;
10297 int eor_receive_af_count = 0;
10298
10299 if (use_json) {
10300 json_grace = json_object_new_object();
10301 json_grace_send = json_object_new_object();
10302 json_grace_recv = json_object_new_object();
10303
10304 if (p->status == Established) {
05c7a1cc
QY
10305 FOREACH_AFI_SAFI (afi, safi) {
10306 if (CHECK_FLAG(p->af_sflags[afi][safi],
10307 PEER_STATUS_EOR_SEND)) {
10308 json_object_boolean_true_add(
10309 json_grace_send,
10310 afi_safi_print(afi,
10311 safi));
10312 eor_send_af_count++;
d62a17ae 10313 }
10314 }
05c7a1cc
QY
10315 FOREACH_AFI_SAFI (afi, safi) {
10316 if (CHECK_FLAG(
10317 p->af_sflags[afi][safi],
10318 PEER_STATUS_EOR_RECEIVED)) {
10319 json_object_boolean_true_add(
10320 json_grace_recv,
10321 afi_safi_print(afi,
10322 safi));
10323 eor_receive_af_count++;
d62a17ae 10324 }
10325 }
10326 }
10327
10328 json_object_object_add(json_grace, "endOfRibSend",
10329 json_grace_send);
10330 json_object_object_add(json_grace, "endOfRibRecv",
10331 json_grace_recv);
10332
10333 if (p->t_gr_restart)
10334 json_object_int_add(json_grace,
10335 "gracefulRestartTimerMsecs",
10336 thread_timer_remain_second(
10337 p->t_gr_restart)
10338 * 1000);
10339
10340 if (p->t_gr_stale)
10341 json_object_int_add(
10342 json_grace,
10343 "gracefulStalepathTimerMsecs",
10344 thread_timer_remain_second(
10345 p->t_gr_stale)
10346 * 1000);
10347
10348 json_object_object_add(
10349 json_neigh, "gracefulRestartInfo", json_grace);
10350 } else {
0437e105 10351 vty_out(vty, " Graceful restart information:\n");
d62a17ae 10352 if (p->status == Established) {
10353 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10354 FOREACH_AFI_SAFI (afi, safi) {
10355 if (CHECK_FLAG(p->af_sflags[afi][safi],
10356 PEER_STATUS_EOR_SEND)) {
10357 vty_out(vty, "%s%s",
10358 eor_send_af_count ? ", "
10359 : "",
10360 afi_safi_print(afi,
10361 safi));
10362 eor_send_af_count++;
d62a17ae 10363 }
10364 }
10365 vty_out(vty, "\n");
10366 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10367 FOREACH_AFI_SAFI (afi, safi) {
10368 if (CHECK_FLAG(
10369 p->af_sflags[afi][safi],
10370 PEER_STATUS_EOR_RECEIVED)) {
10371 vty_out(vty, "%s%s",
10372 eor_receive_af_count
10373 ? ", "
10374 : "",
10375 afi_safi_print(afi,
10376 safi));
10377 eor_receive_af_count++;
d62a17ae 10378 }
10379 }
10380 vty_out(vty, "\n");
10381 }
10382
10383 if (p->t_gr_restart)
10384 vty_out(vty,
10385 " The remaining time of restart timer is %ld\n",
10386 thread_timer_remain_second(
10387 p->t_gr_restart));
10388
10389 if (p->t_gr_stale)
10390 vty_out(vty,
10391 " The remaining time of stalepath timer is %ld\n",
10392 thread_timer_remain_second(
10393 p->t_gr_stale));
10394 }
10395 }
10396 if (use_json) {
10397 json_object *json_stat = NULL;
10398 json_stat = json_object_new_object();
10399 /* Packet counts. */
10400 json_object_int_add(json_stat, "depthInq", 0);
10401 json_object_int_add(json_stat, "depthOutq",
10402 (unsigned long)p->obuf->count);
0112e9e0
QY
10403 json_object_int_add(json_stat, "opensSent",
10404 atomic_load_explicit(&p->open_out,
10405 memory_order_relaxed));
10406 json_object_int_add(json_stat, "opensRecv",
10407 atomic_load_explicit(&p->open_in,
10408 memory_order_relaxed));
d62a17ae 10409 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10410 atomic_load_explicit(&p->notify_out,
10411 memory_order_relaxed));
d62a17ae 10412 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10413 atomic_load_explicit(&p->notify_in,
10414 memory_order_relaxed));
10415 json_object_int_add(json_stat, "updatesSent",
10416 atomic_load_explicit(&p->update_out,
10417 memory_order_relaxed));
10418 json_object_int_add(json_stat, "updatesRecv",
10419 atomic_load_explicit(&p->update_in,
10420 memory_order_relaxed));
d62a17ae 10421 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10422 atomic_load_explicit(&p->keepalive_out,
10423 memory_order_relaxed));
d62a17ae 10424 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10425 atomic_load_explicit(&p->keepalive_in,
10426 memory_order_relaxed));
d62a17ae 10427 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10428 atomic_load_explicit(&p->refresh_out,
10429 memory_order_relaxed));
d62a17ae 10430 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10431 atomic_load_explicit(&p->refresh_in,
10432 memory_order_relaxed));
d62a17ae 10433 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10434 atomic_load_explicit(&p->dynamic_cap_out,
10435 memory_order_relaxed));
d62a17ae 10436 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10437 atomic_load_explicit(&p->dynamic_cap_in,
10438 memory_order_relaxed));
10439 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10440 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10441 json_object_object_add(json_neigh, "messageStats", json_stat);
10442 } else {
10443 /* Packet counts. */
10444 vty_out(vty, " Message statistics:\n");
10445 vty_out(vty, " Inq depth is 0\n");
10446 vty_out(vty, " Outq depth is %lu\n",
10447 (unsigned long)p->obuf->count);
10448 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10449 vty_out(vty, " Opens: %10d %10d\n",
10450 atomic_load_explicit(&p->open_out,
10451 memory_order_relaxed),
10452 atomic_load_explicit(&p->open_in,
10453 memory_order_relaxed));
10454 vty_out(vty, " Notifications: %10d %10d\n",
10455 atomic_load_explicit(&p->notify_out,
10456 memory_order_relaxed),
10457 atomic_load_explicit(&p->notify_in,
10458 memory_order_relaxed));
10459 vty_out(vty, " Updates: %10d %10d\n",
10460 atomic_load_explicit(&p->update_out,
10461 memory_order_relaxed),
10462 atomic_load_explicit(&p->update_in,
10463 memory_order_relaxed));
10464 vty_out(vty, " Keepalives: %10d %10d\n",
10465 atomic_load_explicit(&p->keepalive_out,
10466 memory_order_relaxed),
10467 atomic_load_explicit(&p->keepalive_in,
10468 memory_order_relaxed));
10469 vty_out(vty, " Route Refresh: %10d %10d\n",
10470 atomic_load_explicit(&p->refresh_out,
10471 memory_order_relaxed),
10472 atomic_load_explicit(&p->refresh_in,
10473 memory_order_relaxed));
d62a17ae 10474 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10475 atomic_load_explicit(&p->dynamic_cap_out,
10476 memory_order_relaxed),
10477 atomic_load_explicit(&p->dynamic_cap_in,
10478 memory_order_relaxed));
10479 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10480 PEER_TOTAL_RX(p));
d62a17ae 10481 }
10482
10483 if (use_json) {
10484 /* advertisement-interval */
10485 json_object_int_add(json_neigh,
10486 "minBtwnAdvertisementRunsTimerMsecs",
10487 p->v_routeadv * 1000);
10488
10489 /* Update-source. */
10490 if (p->update_if || p->update_source) {
10491 if (p->update_if)
10492 json_object_string_add(json_neigh,
10493 "updateSource",
10494 p->update_if);
10495 else if (p->update_source)
10496 json_object_string_add(
10497 json_neigh, "updateSource",
10498 sockunion2str(p->update_source, buf1,
10499 SU_ADDRSTRLEN));
10500 }
10501 } else {
10502 /* advertisement-interval */
10503 vty_out(vty,
10504 " Minimum time between advertisement runs is %d seconds\n",
10505 p->v_routeadv);
10506
10507 /* Update-source. */
10508 if (p->update_if || p->update_source) {
10509 vty_out(vty, " Update source is ");
10510 if (p->update_if)
10511 vty_out(vty, "%s", p->update_if);
10512 else if (p->update_source)
10513 vty_out(vty, "%s",
10514 sockunion2str(p->update_source, buf1,
10515 SU_ADDRSTRLEN));
10516 vty_out(vty, "\n");
10517 }
10518
10519 vty_out(vty, "\n");
10520 }
10521
10522 /* Address Family Information */
10523 json_object *json_hold = NULL;
10524
10525 if (use_json)
10526 json_hold = json_object_new_object();
10527
05c7a1cc
QY
10528 FOREACH_AFI_SAFI (afi, safi)
10529 if (p->afc[afi][safi])
10530 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10531 json_hold);
d62a17ae 10532
10533 if (use_json) {
10534 json_object_object_add(json_neigh, "addressFamilyInfo",
10535 json_hold);
10536 json_object_int_add(json_neigh, "connectionsEstablished",
10537 p->established);
10538 json_object_int_add(json_neigh, "connectionsDropped",
10539 p->dropped);
10540 } else
10541 vty_out(vty, " Connections established %d; dropped %d\n",
10542 p->established, p->dropped);
10543
10544 if (!p->last_reset) {
10545 if (use_json)
10546 json_object_string_add(json_neigh, "lastReset",
10547 "never");
10548 else
10549 vty_out(vty, " Last reset never\n");
10550 } else {
10551 if (use_json) {
10552 time_t uptime;
10553 struct tm *tm;
10554
10555 uptime = bgp_clock();
10556 uptime -= p->resettime;
10557 tm = gmtime(&uptime);
10558 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10559 (tm->tm_sec * 1000)
10560 + (tm->tm_min * 60000)
10561 + (tm->tm_hour * 3600000));
10562 json_object_string_add(
10563 json_neigh, "lastResetDueTo",
10564 peer_down_str[(int)p->last_reset]);
10565 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10566 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10567 char errorcodesubcode_hexstr[5];
10568 char errorcodesubcode_str[256];
10569
10570 code_str = bgp_notify_code_str(p->notify.code);
10571 subcode_str = bgp_notify_subcode_str(
10572 p->notify.code, p->notify.subcode);
10573
10574 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10575 p->notify.code, p->notify.subcode);
10576 json_object_string_add(json_neigh,
10577 "lastErrorCodeSubcode",
10578 errorcodesubcode_hexstr);
10579 snprintf(errorcodesubcode_str, 255, "%s%s",
10580 code_str, subcode_str);
10581 json_object_string_add(json_neigh,
10582 "lastNotificationReason",
10583 errorcodesubcode_str);
10584 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10585 && p->notify.code == BGP_NOTIFY_CEASE
10586 && (p->notify.subcode
10587 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10588 || p->notify.subcode
10589 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10590 && p->notify.length) {
10591 char msgbuf[1024];
10592 const char *msg_str;
10593
10594 msg_str = bgp_notify_admin_message(
10595 msgbuf, sizeof(msgbuf),
d7c0a89a 10596 (uint8_t *)p->notify.data,
d62a17ae 10597 p->notify.length);
10598 if (msg_str)
10599 json_object_string_add(
10600 json_neigh,
10601 "lastShutdownDescription",
10602 msg_str);
10603 }
10604 }
10605 } else {
10606 vty_out(vty, " Last reset %s, ",
10607 peer_uptime(p->resettime, timebuf,
10608 BGP_UPTIME_LEN, 0, NULL));
10609
10610 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10611 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10612 code_str = bgp_notify_code_str(p->notify.code);
10613 subcode_str = bgp_notify_subcode_str(
10614 p->notify.code, p->notify.subcode);
10615 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10616 p->last_reset == PEER_DOWN_NOTIFY_SEND
10617 ? "sent"
10618 : "received",
10619 code_str, subcode_str);
10620 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10621 && p->notify.code == BGP_NOTIFY_CEASE
10622 && (p->notify.subcode
10623 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10624 || p->notify.subcode
10625 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10626 && p->notify.length) {
10627 char msgbuf[1024];
10628 const char *msg_str;
10629
10630 msg_str = bgp_notify_admin_message(
10631 msgbuf, sizeof(msgbuf),
d7c0a89a 10632 (uint8_t *)p->notify.data,
d62a17ae 10633 p->notify.length);
10634 if (msg_str)
10635 vty_out(vty,
10636 " Message: \"%s\"\n",
10637 msg_str);
10638 }
10639 } else {
10640 vty_out(vty, "due to %s\n",
10641 peer_down_str[(int)p->last_reset]);
10642 }
10643
10644 if (p->last_reset_cause_size) {
10645 msg = p->last_reset_cause;
10646 vty_out(vty,
10647 " Message received that caused BGP to send a NOTIFICATION:\n ");
10648 for (i = 1; i <= p->last_reset_cause_size;
10649 i++) {
10650 vty_out(vty, "%02X", *msg++);
10651
10652 if (i != p->last_reset_cause_size) {
10653 if (i % 16 == 0) {
10654 vty_out(vty, "\n ");
10655 } else if (i % 4 == 0) {
10656 vty_out(vty, " ");
10657 }
10658 }
10659 }
10660 vty_out(vty, "\n");
10661 }
10662 }
10663 }
10664
10665 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10666 if (use_json)
10667 json_object_boolean_true_add(json_neigh,
10668 "prefixesConfigExceedMax");
10669 else
10670 vty_out(vty,
10671 " Peer had exceeded the max. no. of prefixes configured.\n");
10672
10673 if (p->t_pmax_restart) {
10674 if (use_json) {
10675 json_object_boolean_true_add(
10676 json_neigh, "reducePrefixNumFrom");
10677 json_object_int_add(json_neigh,
10678 "restartInTimerMsec",
10679 thread_timer_remain_second(
10680 p->t_pmax_restart)
10681 * 1000);
10682 } else
10683 vty_out(vty,
10684 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10685 p->host, thread_timer_remain_second(
10686 p->t_pmax_restart));
d62a17ae 10687 } else {
10688 if (use_json)
10689 json_object_boolean_true_add(
10690 json_neigh,
10691 "reducePrefixNumAndClearIpBgp");
10692 else
10693 vty_out(vty,
10694 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10695 p->host);
10696 }
10697 }
10698
10699 /* EBGP Multihop and GTSM */
10700 if (p->sort != BGP_PEER_IBGP) {
10701 if (use_json) {
10702 if (p->gtsm_hops > 0)
10703 json_object_int_add(json_neigh,
10704 "externalBgpNbrMaxHopsAway",
10705 p->gtsm_hops);
10706 else if (p->ttl > 1)
10707 json_object_int_add(json_neigh,
10708 "externalBgpNbrMaxHopsAway",
10709 p->ttl);
10710 } else {
10711 if (p->gtsm_hops > 0)
10712 vty_out(vty,
10713 " External BGP neighbor may be up to %d hops away.\n",
10714 p->gtsm_hops);
10715 else if (p->ttl > 1)
10716 vty_out(vty,
10717 " External BGP neighbor may be up to %d hops away.\n",
10718 p->ttl);
10719 }
10720 } else {
10721 if (p->gtsm_hops > 0) {
10722 if (use_json)
10723 json_object_int_add(json_neigh,
10724 "internalBgpNbrMaxHopsAway",
10725 p->gtsm_hops);
10726 else
10727 vty_out(vty,
10728 " Internal BGP neighbor may be up to %d hops away.\n",
10729 p->gtsm_hops);
10730 }
10731 }
10732
10733 /* Local address. */
10734 if (p->su_local) {
10735 if (use_json) {
10736 json_object_string_add(json_neigh, "hostLocal",
10737 sockunion2str(p->su_local, buf1,
10738 SU_ADDRSTRLEN));
10739 json_object_int_add(json_neigh, "portLocal",
10740 ntohs(p->su_local->sin.sin_port));
10741 } else
10742 vty_out(vty, "Local host: %s, Local port: %d\n",
10743 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10744 ntohs(p->su_local->sin.sin_port));
10745 }
10746
10747 /* Remote address. */
10748 if (p->su_remote) {
10749 if (use_json) {
10750 json_object_string_add(json_neigh, "hostForeign",
10751 sockunion2str(p->su_remote, buf1,
10752 SU_ADDRSTRLEN));
10753 json_object_int_add(json_neigh, "portForeign",
10754 ntohs(p->su_remote->sin.sin_port));
10755 } else
10756 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10757 sockunion2str(p->su_remote, buf1,
10758 SU_ADDRSTRLEN),
10759 ntohs(p->su_remote->sin.sin_port));
10760 }
10761
10762 /* Nexthop display. */
10763 if (p->su_local) {
10764 if (use_json) {
10765 json_object_string_add(json_neigh, "nexthop",
10766 inet_ntop(AF_INET,
10767 &p->nexthop.v4, buf1,
10768 sizeof(buf1)));
10769 json_object_string_add(json_neigh, "nexthopGlobal",
10770 inet_ntop(AF_INET6,
10771 &p->nexthop.v6_global,
10772 buf1, sizeof(buf1)));
10773 json_object_string_add(json_neigh, "nexthopLocal",
10774 inet_ntop(AF_INET6,
10775 &p->nexthop.v6_local,
10776 buf1, sizeof(buf1)));
10777 if (p->shared_network)
10778 json_object_string_add(json_neigh,
10779 "bgpConnection",
10780 "sharedNetwork");
10781 else
10782 json_object_string_add(json_neigh,
10783 "bgpConnection",
10784 "nonSharedNetwork");
10785 } else {
10786 vty_out(vty, "Nexthop: %s\n",
10787 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10788 sizeof(buf1)));
10789 vty_out(vty, "Nexthop global: %s\n",
10790 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10791 sizeof(buf1)));
10792 vty_out(vty, "Nexthop local: %s\n",
10793 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10794 sizeof(buf1)));
10795 vty_out(vty, "BGP connection: %s\n",
10796 p->shared_network ? "shared network"
10797 : "non shared network");
10798 }
10799 }
10800
10801 /* Timer information. */
10802 if (use_json) {
10803 json_object_int_add(json_neigh, "connectRetryTimer",
10804 p->v_connect);
10805 if (p->status == Established && p->rtt)
10806 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10807 p->rtt);
10808 if (p->t_start)
10809 json_object_int_add(
10810 json_neigh, "nextStartTimerDueInMsecs",
10811 thread_timer_remain_second(p->t_start) * 1000);
10812 if (p->t_connect)
10813 json_object_int_add(
10814 json_neigh, "nextConnectTimerDueInMsecs",
10815 thread_timer_remain_second(p->t_connect)
10816 * 1000);
10817 if (p->t_routeadv) {
10818 json_object_int_add(json_neigh, "mraiInterval",
10819 p->v_routeadv);
10820 json_object_int_add(
10821 json_neigh, "mraiTimerExpireInMsecs",
10822 thread_timer_remain_second(p->t_routeadv)
10823 * 1000);
10824 }
10825 if (p->password)
10826 json_object_int_add(json_neigh, "authenticationEnabled",
10827 1);
10828
10829 if (p->t_read)
10830 json_object_string_add(json_neigh, "readThread", "on");
10831 else
10832 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10833
10834 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10835 json_object_string_add(json_neigh, "writeThread", "on");
10836 else
10837 json_object_string_add(json_neigh, "writeThread",
10838 "off");
10839 } else {
10840 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10841 p->v_connect);
10842 if (p->status == Established && p->rtt)
10843 vty_out(vty, "Estimated round trip time: %d ms\n",
10844 p->rtt);
10845 if (p->t_start)
10846 vty_out(vty, "Next start timer due in %ld seconds\n",
10847 thread_timer_remain_second(p->t_start));
10848 if (p->t_connect)
10849 vty_out(vty, "Next connect timer due in %ld seconds\n",
10850 thread_timer_remain_second(p->t_connect));
10851 if (p->t_routeadv)
10852 vty_out(vty,
10853 "MRAI (interval %u) timer expires in %ld seconds\n",
10854 p->v_routeadv,
10855 thread_timer_remain_second(p->t_routeadv));
10856 if (p->password)
10857 vty_out(vty, "Peer Authentication Enabled\n");
10858
10859 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10860 p->t_read ? "on" : "off",
10861 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10862 ? "on"
10863 : "off");
d62a17ae 10864 }
10865
10866 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10867 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10868 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10869
10870 if (!use_json)
10871 vty_out(vty, "\n");
10872
10873 /* BFD information. */
10874 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10875
10876 if (use_json) {
10877 if (p->conf_if) /* Configured interface name. */
10878 json_object_object_add(json, p->conf_if, json_neigh);
10879 else /* Configured IP address. */
10880 json_object_object_add(json, p->host, json_neigh);
10881 }
10882}
10883
10884static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10885 enum show_type type, union sockunion *su,
9f049418 10886 const char *conf_if, bool use_json,
d62a17ae 10887 json_object *json)
10888{
10889 struct listnode *node, *nnode;
10890 struct peer *peer;
10891 int find = 0;
9f049418 10892 bool nbr_output = false;
d62a17ae 10893
10894 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10895 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10896 continue;
10897
10898 switch (type) {
10899 case show_all:
10900 bgp_show_peer(vty, peer, use_json, json);
9f049418 10901 nbr_output = true;
d62a17ae 10902 break;
10903 case show_peer:
10904 if (conf_if) {
10905 if ((peer->conf_if
10906 && !strcmp(peer->conf_if, conf_if))
10907 || (peer->hostname
10908 && !strcmp(peer->hostname, conf_if))) {
10909 find = 1;
10910 bgp_show_peer(vty, peer, use_json,
10911 json);
10912 }
10913 } else {
10914 if (sockunion_same(&peer->su, su)) {
10915 find = 1;
10916 bgp_show_peer(vty, peer, use_json,
10917 json);
10918 }
10919 }
10920 break;
10921 }
10922 }
10923
10924 if (type == show_peer && !find) {
10925 if (use_json)
10926 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10927 else
88b7d255 10928 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 10929 }
10930
9f049418 10931 if (type != show_peer && !nbr_output && !use_json)
94d4c685 10932 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 10933
d62a17ae 10934 if (use_json) {
996c9314
LB
10935 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10936 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10937 } else {
10938 vty_out(vty, "\n");
10939 }
10940
10941 return CMD_SUCCESS;
10942}
10943
10944static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10945 enum show_type type,
10946 const char *ip_str,
9f049418 10947 bool use_json)
d62a17ae 10948{
0291c246
MK
10949 struct listnode *node, *nnode;
10950 struct bgp *bgp;
71aedaa3 10951 union sockunion su;
0291c246 10952 json_object *json = NULL;
71aedaa3 10953 int ret, is_first = 1;
9f049418 10954 bool nbr_output = false;
d62a17ae 10955
10956 if (use_json)
10957 vty_out(vty, "{\n");
10958
10959 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10960 nbr_output = true;
d62a17ae 10961 if (use_json) {
10962 if (!(json = json_object_new_object())) {
af4c2728 10963 flog_err(
e50f7cfd 10964 EC_BGP_JSON_MEM_ERROR,
d62a17ae 10965 "Unable to allocate memory for JSON object");
10966 vty_out(vty,
10967 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10968 return;
10969 }
10970
10971 json_object_int_add(json, "vrfId",
10972 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10973 ? -1
10974 : (int64_t)bgp->vrf_id);
d62a17ae 10975 json_object_string_add(
10976 json, "vrfName",
10977 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10978 ? VRF_DEFAULT_NAME
d62a17ae 10979 : bgp->name);
10980
10981 if (!is_first)
10982 vty_out(vty, ",\n");
10983 else
10984 is_first = 0;
10985
10986 vty_out(vty, "\"%s\":",
10987 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10988 ? VRF_DEFAULT_NAME
d62a17ae 10989 : bgp->name);
10990 } else {
10991 vty_out(vty, "\nInstance %s:\n",
10992 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10993 ? VRF_DEFAULT_NAME
d62a17ae 10994 : bgp->name);
10995 }
71aedaa3
DS
10996
10997 if (type == show_peer) {
10998 ret = str2sockunion(ip_str, &su);
10999 if (ret < 0)
11000 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11001 use_json, json);
11002 else
11003 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11004 use_json, json);
11005 } else {
11006 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
11007 use_json, json);
11008 }
d62a17ae 11009 }
11010
01cbfd04 11011 if (use_json) {
d62a17ae 11012 vty_out(vty, "}\n");
01cbfd04
QY
11013 json_object_free(json);
11014 }
9f049418
DS
11015 else if (!nbr_output)
11016 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11017}
11018
11019static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11020 enum show_type type, const char *ip_str,
9f049418 11021 bool use_json)
d62a17ae 11022{
11023 int ret;
11024 struct bgp *bgp;
11025 union sockunion su;
11026 json_object *json = NULL;
11027
11028 if (name) {
11029 if (strmatch(name, "all")) {
71aedaa3
DS
11030 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11031 use_json);
d62a17ae 11032 return CMD_SUCCESS;
11033 } else {
11034 bgp = bgp_lookup_by_name(name);
11035 if (!bgp) {
11036 if (use_json) {
11037 json = json_object_new_object();
d62a17ae 11038 vty_out(vty, "%s\n",
11039 json_object_to_json_string_ext(
11040 json,
11041 JSON_C_TO_STRING_PRETTY));
11042 json_object_free(json);
11043 } else
11044 vty_out(vty,
9f049418 11045 "%% BGP instance not found\n");
d62a17ae 11046
11047 return CMD_WARNING;
11048 }
11049 }
11050 } else {
11051 bgp = bgp_get_default();
11052 }
11053
11054 if (bgp) {
11055 json = json_object_new_object();
11056 if (ip_str) {
11057 ret = str2sockunion(ip_str, &su);
11058 if (ret < 0)
11059 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11060 use_json, json);
11061 else
11062 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11063 use_json, json);
11064 } else {
11065 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11066 json);
11067 }
11068 json_object_free(json);
ca61fd25
DS
11069 } else {
11070 if (use_json)
11071 vty_out(vty, "{}\n");
11072 else
11073 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11074 }
11075
11076 return CMD_SUCCESS;
4fb25c53
DW
11077}
11078
716b2d8a 11079/* "show [ip] bgp neighbors" commands. */
718e3744 11080DEFUN (show_ip_bgp_neighbors,
11081 show_ip_bgp_neighbors_cmd,
24345e82 11082 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 11083 SHOW_STR
11084 IP_STR
11085 BGP_STR
f2a8972b 11086 BGP_INSTANCE_HELP_STR
8c3deaae
QY
11087 "Address Family\n"
11088 "Address Family\n"
718e3744 11089 "Detailed information on TCP and BGP neighbor connections\n"
11090 "Neighbor to display information about\n"
a80beece 11091 "Neighbor to display information about\n"
91d37724 11092 "Neighbor on BGP configured interface\n"
9973d184 11093 JSON_STR)
718e3744 11094{
d62a17ae 11095 char *vrf = NULL;
11096 char *sh_arg = NULL;
11097 enum show_type sh_type;
718e3744 11098
9f049418 11099 bool uj = use_json(argc, argv);
718e3744 11100
d62a17ae 11101 int idx = 0;
718e3744 11102
9a8bdf1c
PG
11103 /* [<vrf> VIEWVRFNAME] */
11104 if (argv_find(argv, argc, "vrf", &idx)) {
11105 vrf = argv[idx + 1]->arg;
11106 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11107 vrf = NULL;
11108 } else if (argv_find(argv, argc, "view", &idx))
11109 /* [<view> VIEWVRFNAME] */
d62a17ae 11110 vrf = argv[idx + 1]->arg;
718e3744 11111
d62a17ae 11112 idx++;
11113 if (argv_find(argv, argc, "A.B.C.D", &idx)
11114 || argv_find(argv, argc, "X:X::X:X", &idx)
11115 || argv_find(argv, argc, "WORD", &idx)) {
11116 sh_type = show_peer;
11117 sh_arg = argv[idx]->arg;
11118 } else
11119 sh_type = show_all;
856ca177 11120
d62a17ae 11121 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 11122}
11123
716b2d8a 11124/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 11125 paths' and `show ip mbgp paths'. Those functions results are the
11126 same.*/
f412b39a 11127DEFUN (show_ip_bgp_paths,
718e3744 11128 show_ip_bgp_paths_cmd,
46f296b4 11129 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 11130 SHOW_STR
11131 IP_STR
11132 BGP_STR
46f296b4 11133 BGP_SAFI_HELP_STR
718e3744 11134 "Path information\n")
11135{
d62a17ae 11136 vty_out(vty, "Address Refcnt Path\n");
11137 aspath_print_all_vty(vty);
11138 return CMD_SUCCESS;
718e3744 11139}
11140
718e3744 11141#include "hash.h"
11142
d62a17ae 11143static void community_show_all_iterator(struct hash_backet *backet,
11144 struct vty *vty)
718e3744 11145{
d62a17ae 11146 struct community *com;
718e3744 11147
d62a17ae 11148 com = (struct community *)backet->data;
3f65c5b1 11149 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 11150 community_str(com, false));
718e3744 11151}
11152
11153/* Show BGP's community internal data. */
f412b39a 11154DEFUN (show_ip_bgp_community_info,
718e3744 11155 show_ip_bgp_community_info_cmd,
bec37ba5 11156 "show [ip] bgp community-info",
718e3744 11157 SHOW_STR
11158 IP_STR
11159 BGP_STR
11160 "List all bgp community information\n")
11161{
d62a17ae 11162 vty_out(vty, "Address Refcnt Community\n");
718e3744 11163
d62a17ae 11164 hash_iterate(community_hash(),
11165 (void (*)(struct hash_backet *,
11166 void *))community_show_all_iterator,
11167 vty);
718e3744 11168
d62a17ae 11169 return CMD_SUCCESS;
718e3744 11170}
11171
d62a17ae 11172static void lcommunity_show_all_iterator(struct hash_backet *backet,
11173 struct vty *vty)
57d187bc 11174{
d62a17ae 11175 struct lcommunity *lcom;
57d187bc 11176
d62a17ae 11177 lcom = (struct lcommunity *)backet->data;
3f65c5b1 11178 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 11179 lcommunity_str(lcom, false));
57d187bc
JS
11180}
11181
11182/* Show BGP's community internal data. */
11183DEFUN (show_ip_bgp_lcommunity_info,
11184 show_ip_bgp_lcommunity_info_cmd,
11185 "show ip bgp large-community-info",
11186 SHOW_STR
11187 IP_STR
11188 BGP_STR
11189 "List all bgp large-community information\n")
11190{
d62a17ae 11191 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 11192
d62a17ae 11193 hash_iterate(lcommunity_hash(),
11194 (void (*)(struct hash_backet *,
11195 void *))lcommunity_show_all_iterator,
11196 vty);
57d187bc 11197
d62a17ae 11198 return CMD_SUCCESS;
57d187bc
JS
11199}
11200
11201
f412b39a 11202DEFUN (show_ip_bgp_attr_info,
718e3744 11203 show_ip_bgp_attr_info_cmd,
bec37ba5 11204 "show [ip] bgp attribute-info",
718e3744 11205 SHOW_STR
11206 IP_STR
11207 BGP_STR
11208 "List all bgp attribute information\n")
11209{
d62a17ae 11210 attr_show_all(vty);
11211 return CMD_SUCCESS;
718e3744 11212}
6b0655a2 11213
9f049418
DS
11214static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi,
11215 safi_t safi, bool use_json)
53089bec 11216{
11217 struct bgp *bgp;
11218 struct listnode *node;
11219 char *vname;
11220 char buf1[INET6_ADDRSTRLEN];
11221 char *ecom_str;
11222 vpn_policy_direction_t dir;
11223
b46dfd20
DS
11224 if (use_json) {
11225 json_object *json = NULL;
11226 json_object *json_import_vrfs = NULL;
11227 json_object *json_export_vrfs = NULL;
11228
11229 json = json_object_new_object();
b46dfd20 11230
b46dfd20
DS
11231 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11232
53089bec 11233 if (!bgp) {
b46dfd20
DS
11234 vty_out(vty, "%s\n",
11235 json_object_to_json_string_ext(
11236 json,
11237 JSON_C_TO_STRING_PRETTY));
11238 json_object_free(json);
11239
53089bec 11240 return CMD_WARNING;
11241 }
b46dfd20 11242
94d4c685
DS
11243 /* Provide context for the block */
11244 json_object_string_add(json, "vrf", name ? name : "default");
11245 json_object_string_add(json, "afiSafi",
11246 afi_safi_print(afi, safi));
11247
b46dfd20
DS
11248 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11249 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11250 json_object_string_add(json, "importFromVrfs", "none");
11251 json_object_string_add(json, "importRts", "none");
11252 } else {
6ce24e52
DS
11253 json_import_vrfs = json_object_new_array();
11254
b46dfd20
DS
11255 for (ALL_LIST_ELEMENTS_RO(
11256 bgp->vpn_policy[afi].import_vrf,
11257 node, vname))
11258 json_object_array_add(json_import_vrfs,
11259 json_object_new_string(vname));
11260
11261 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11262 ecom_str = ecommunity_ecom2str(
11263 bgp->vpn_policy[afi].rtlist[dir],
11264 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11265 json_object_object_add(json, "importFromVrfs",
11266 json_import_vrfs);
11267 json_object_string_add(json, "importRts", ecom_str);
11268
11269 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11270 }
11271
11272 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11273 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11274 json_object_string_add(json, "exportToVrfs", "none");
11275 json_object_string_add(json, "routeDistinguisher",
11276 "none");
11277 json_object_string_add(json, "exportRts", "none");
11278 } else {
6ce24e52
DS
11279 json_export_vrfs = json_object_new_array();
11280
b46dfd20
DS
11281 for (ALL_LIST_ELEMENTS_RO(
11282 bgp->vpn_policy[afi].export_vrf,
11283 node, vname))
11284 json_object_array_add(json_export_vrfs,
11285 json_object_new_string(vname));
11286 json_object_object_add(json, "exportToVrfs",
11287 json_export_vrfs);
11288 json_object_string_add(json, "routeDistinguisher",
11289 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11290 buf1, RD_ADDRSTRLEN));
11291
11292 dir = BGP_VPN_POLICY_DIR_TOVPN;
11293 ecom_str = ecommunity_ecom2str(
11294 bgp->vpn_policy[afi].rtlist[dir],
11295 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11296 json_object_string_add(json, "exportRts", ecom_str);
11297
11298 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11299 }
11300
11301 vty_out(vty, "%s\n",
11302 json_object_to_json_string_ext(json,
11303 JSON_C_TO_STRING_PRETTY));
11304 json_object_free(json);
11305
53089bec 11306 } else {
b46dfd20
DS
11307 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11308
53089bec 11309 if (!bgp) {
b46dfd20 11310 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 11311 return CMD_WARNING;
11312 }
53089bec 11313
b46dfd20
DS
11314 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11315 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11316 vty_out(vty,
11317 "This VRF is not importing %s routes from any other VRF\n",
11318 afi_safi_print(afi, safi));
11319 else {
11320 vty_out(vty,
11321 "This VRF is importing %s routes from the following VRFs:\n",
11322 afi_safi_print(afi, safi));
11323
11324 for (ALL_LIST_ELEMENTS_RO(
11325 bgp->vpn_policy[afi].import_vrf,
11326 node, vname))
11327 vty_out(vty, " %s\n", vname);
11328
11329 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11330 ecom_str = ecommunity_ecom2str(
11331 bgp->vpn_policy[afi].rtlist[dir],
11332 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11333 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11334
11335 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11336 }
53089bec 11337
b46dfd20
DS
11338 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11339 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11340 vty_out(vty,
11341 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11342 afi_safi_print(afi, safi));
b46dfd20
DS
11343 else {
11344 vty_out(vty,
04c9077f 11345 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11346 afi_safi_print(afi, safi));
b46dfd20
DS
11347
11348 for (ALL_LIST_ELEMENTS_RO(
11349 bgp->vpn_policy[afi].export_vrf,
11350 node, vname))
11351 vty_out(vty, " %s\n", vname);
11352
11353 vty_out(vty, "RD: %s\n",
11354 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11355 buf1, RD_ADDRSTRLEN));
11356
11357 dir = BGP_VPN_POLICY_DIR_TOVPN;
11358 ecom_str = ecommunity_ecom2str(
11359 bgp->vpn_policy[afi].rtlist[dir],
11360 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11361 vty_out(vty, "Export RT: %s\n", ecom_str);
04c9077f 11362 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11363 }
53089bec 11364 }
11365
11366 return CMD_SUCCESS;
11367}
11368
11369/* "show [ip] bgp route-leak" command. */
11370DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
11371 show_ip_bgp_route_leak_cmd,
11372 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
11373 SHOW_STR
11374 IP_STR
11375 BGP_STR
11376 BGP_INSTANCE_HELP_STR
11377 BGP_AFI_HELP_STR
11378 BGP_SAFI_HELP_STR
11379 "Route leaking information\n"
11380 JSON_STR)
53089bec 11381{
11382 char *vrf = NULL;
11383 afi_t afi = AFI_MAX;
11384 safi_t safi = SAFI_MAX;
11385
9f049418 11386 bool uj = use_json(argc, argv);
53089bec 11387 int idx = 0;
11388
11389 /* show [ip] bgp */
11390 if (argv_find(argv, argc, "ip", &idx)) {
11391 afi = AFI_IP;
11392 safi = SAFI_UNICAST;
11393 }
11394 /* [vrf VIEWVRFNAME] */
11395 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11396 vty_out(vty,
11397 "%% This command is not applicable to BGP views\n");
53089bec 11398 return CMD_WARNING;
11399 }
11400
9a8bdf1c
PG
11401 if (argv_find(argv, argc, "vrf", &idx)) {
11402 vrf = argv[idx + 1]->arg;
11403 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11404 vrf = NULL;
11405 }
53089bec 11406 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11407 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11408 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11409 }
11410
11411 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11412 vty_out(vty,
11413 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11414 return CMD_WARNING;
11415 }
11416
b46dfd20 11417 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
53089bec 11418}
11419
d62a17ae 11420static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11421 safi_t safi)
f186de26 11422{
d62a17ae 11423 struct listnode *node, *nnode;
11424 struct bgp *bgp;
f186de26 11425
d62a17ae 11426 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11427 vty_out(vty, "\nInstance %s:\n",
11428 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11429 ? VRF_DEFAULT_NAME
d62a17ae 11430 : bgp->name);
11431 update_group_show(bgp, afi, safi, vty, 0);
11432 }
f186de26 11433}
11434
d62a17ae 11435static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11436 int safi, uint64_t subgrp_id)
4fb25c53 11437{
d62a17ae 11438 struct bgp *bgp;
4fb25c53 11439
d62a17ae 11440 if (name) {
11441 if (strmatch(name, "all")) {
11442 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11443 return CMD_SUCCESS;
11444 } else {
11445 bgp = bgp_lookup_by_name(name);
11446 }
11447 } else {
11448 bgp = bgp_get_default();
11449 }
4fb25c53 11450
d62a17ae 11451 if (bgp)
11452 update_group_show(bgp, afi, safi, vty, subgrp_id);
11453 return CMD_SUCCESS;
4fb25c53
DW
11454}
11455
8fe8a7f6
DS
11456DEFUN (show_ip_bgp_updgrps,
11457 show_ip_bgp_updgrps_cmd,
c1a44e43 11458 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11459 SHOW_STR
11460 IP_STR
11461 BGP_STR
11462 BGP_INSTANCE_HELP_STR
c9e571b4 11463 BGP_AFI_HELP_STR
9bedbb1e 11464 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11465 "Detailed info about dynamic update groups\n"
11466 "Specific subgroup to display detailed info for\n")
8386ac43 11467{
d62a17ae 11468 char *vrf = NULL;
11469 afi_t afi = AFI_IP6;
11470 safi_t safi = SAFI_UNICAST;
11471 uint64_t subgrp_id = 0;
11472
11473 int idx = 0;
11474
11475 /* show [ip] bgp */
11476 if (argv_find(argv, argc, "ip", &idx))
11477 afi = AFI_IP;
9a8bdf1c
PG
11478 /* [<vrf> VIEWVRFNAME] */
11479 if (argv_find(argv, argc, "vrf", &idx)) {
11480 vrf = argv[idx + 1]->arg;
11481 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11482 vrf = NULL;
11483 } else if (argv_find(argv, argc, "view", &idx))
11484 /* [<view> VIEWVRFNAME] */
11485 vrf = argv[idx + 1]->arg;
d62a17ae 11486 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11487 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11488 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11489 }
5bf15956 11490
d62a17ae 11491 /* get subgroup id, if provided */
11492 idx = argc - 1;
11493 if (argv[idx]->type == VARIABLE_TKN)
11494 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11495
d62a17ae 11496 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11497}
11498
f186de26 11499DEFUN (show_bgp_instance_all_ipv6_updgrps,
11500 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11501 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11502 SHOW_STR
716b2d8a 11503 IP_STR
f186de26 11504 BGP_STR
11505 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11506 "Detailed info about dynamic update groups\n")
f186de26 11507{
d62a17ae 11508 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11509 return CMD_SUCCESS;
f186de26 11510}
11511
43d3f4fc
DS
11512DEFUN (show_bgp_l2vpn_evpn_updgrps,
11513 show_bgp_l2vpn_evpn_updgrps_cmd,
11514 "show [ip] bgp l2vpn evpn update-groups",
11515 SHOW_STR
11516 IP_STR
11517 BGP_STR
11518 "l2vpn address family\n"
11519 "evpn sub-address family\n"
11520 "Detailed info about dynamic update groups\n")
11521{
11522 char *vrf = NULL;
11523 uint64_t subgrp_id = 0;
11524
11525 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11526 return CMD_SUCCESS;
11527}
11528
5bf15956
DW
11529DEFUN (show_bgp_updgrps_stats,
11530 show_bgp_updgrps_stats_cmd,
716b2d8a 11531 "show [ip] bgp update-groups statistics",
3f9c7369 11532 SHOW_STR
716b2d8a 11533 IP_STR
3f9c7369 11534 BGP_STR
0c7b1b01 11535 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11536 "Statistics\n")
11537{
d62a17ae 11538 struct bgp *bgp;
3f9c7369 11539
d62a17ae 11540 bgp = bgp_get_default();
11541 if (bgp)
11542 update_group_show_stats(bgp, vty);
3f9c7369 11543
d62a17ae 11544 return CMD_SUCCESS;
3f9c7369
DS
11545}
11546
8386ac43 11547DEFUN (show_bgp_instance_updgrps_stats,
11548 show_bgp_instance_updgrps_stats_cmd,
18c57037 11549 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11550 SHOW_STR
716b2d8a 11551 IP_STR
8386ac43 11552 BGP_STR
11553 BGP_INSTANCE_HELP_STR
0c7b1b01 11554 "Detailed info about dynamic update groups\n"
8386ac43 11555 "Statistics\n")
11556{
d62a17ae 11557 int idx_word = 3;
11558 struct bgp *bgp;
8386ac43 11559
d62a17ae 11560 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11561 if (bgp)
11562 update_group_show_stats(bgp, vty);
8386ac43 11563
d62a17ae 11564 return CMD_SUCCESS;
8386ac43 11565}
11566
d62a17ae 11567static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11568 afi_t afi, safi_t safi,
11569 const char *what, uint64_t subgrp_id)
3f9c7369 11570{
d62a17ae 11571 struct bgp *bgp;
8386ac43 11572
d62a17ae 11573 if (name)
11574 bgp = bgp_lookup_by_name(name);
11575 else
11576 bgp = bgp_get_default();
8386ac43 11577
d62a17ae 11578 if (bgp) {
11579 if (!strcmp(what, "advertise-queue"))
11580 update_group_show_adj_queue(bgp, afi, safi, vty,
11581 subgrp_id);
11582 else if (!strcmp(what, "advertised-routes"))
11583 update_group_show_advertised(bgp, afi, safi, vty,
11584 subgrp_id);
11585 else if (!strcmp(what, "packet-queue"))
11586 update_group_show_packet_queue(bgp, afi, safi, vty,
11587 subgrp_id);
11588 }
3f9c7369
DS
11589}
11590
dc64bdec
QY
11591DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11592 show_ip_bgp_instance_updgrps_adj_s_cmd,
11593 "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",
11594 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11595 BGP_SAFI_HELP_STR
11596 "Detailed info about dynamic update groups\n"
11597 "Specific subgroup to display info for\n"
11598 "Advertisement queue\n"
11599 "Announced routes\n"
11600 "Packet queue\n")
3f9c7369 11601{
dc64bdec
QY
11602 uint64_t subgrp_id = 0;
11603 afi_t afiz;
11604 safi_t safiz;
11605 if (sgid)
11606 subgrp_id = strtoull(sgid, NULL, 10);
11607
11608 if (!ip && !afi)
11609 afiz = AFI_IP6;
11610 if (!ip && afi)
11611 afiz = bgp_vty_afi_from_str(afi);
11612 if (ip && !afi)
11613 afiz = AFI_IP;
11614 if (ip && afi) {
11615 afiz = bgp_vty_afi_from_str(afi);
11616 if (afiz != AFI_IP)
11617 vty_out(vty,
11618 "%% Cannot specify both 'ip' and 'ipv6'\n");
11619 return CMD_WARNING;
11620 }
d62a17ae 11621
dc64bdec 11622 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11623
dc64bdec 11624 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11625 return CMD_SUCCESS;
11626}
11627
d62a17ae 11628static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11629{
11630 struct listnode *node, *nnode;
11631 struct prefix *range;
11632 struct peer *conf;
11633 struct peer *peer;
11634 char buf[PREFIX2STR_BUFFER];
11635 afi_t afi;
11636 safi_t safi;
11637 const char *peer_status;
11638 const char *af_str;
11639 int lr_count;
11640 int dynamic;
11641 int af_cfgd;
11642
11643 conf = group->conf;
11644
11645 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11646 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11647 conf->as);
11648 } else if (conf->as_type == AS_INTERNAL) {
11649 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11650 group->bgp->as);
11651 } else {
11652 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11653 }
f14e6fdb 11654
d62a17ae 11655 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11656 vty_out(vty, " Peer-group type is internal\n");
11657 else
11658 vty_out(vty, " Peer-group type is external\n");
11659
11660 /* Display AFs configured. */
11661 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11662 FOREACH_AFI_SAFI (afi, safi) {
11663 if (conf->afc[afi][safi]) {
11664 af_cfgd = 1;
11665 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11666 }
05c7a1cc 11667 }
d62a17ae 11668 if (!af_cfgd)
11669 vty_out(vty, " none\n");
11670 else
11671 vty_out(vty, "\n");
11672
11673 /* Display listen ranges (for dynamic neighbors), if any */
11674 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11675 if (afi == AFI_IP)
11676 af_str = "IPv4";
11677 else if (afi == AFI_IP6)
11678 af_str = "IPv6";
11679 else
11680 af_str = "???";
11681 lr_count = listcount(group->listen_range[afi]);
11682 if (lr_count) {
11683 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11684 af_str);
11685
11686
11687 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11688 nnode, range)) {
11689 prefix2str(range, buf, sizeof(buf));
11690 vty_out(vty, " %s\n", buf);
11691 }
11692 }
11693 }
f14e6fdb 11694
d62a17ae 11695 /* Display group members and their status */
11696 if (listcount(group->peer)) {
11697 vty_out(vty, " Peer-group members:\n");
11698 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11699 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11700 peer_status = "Idle (Admin)";
11701 else if (CHECK_FLAG(peer->sflags,
11702 PEER_STATUS_PREFIX_OVERFLOW))
11703 peer_status = "Idle (PfxCt)";
11704 else
11705 peer_status = lookup_msg(bgp_status_msg,
11706 peer->status, NULL);
11707
11708 dynamic = peer_dynamic_neighbor(peer);
11709 vty_out(vty, " %s %s %s \n", peer->host,
11710 dynamic ? "(dynamic)" : "", peer_status);
11711 }
11712 }
f14e6fdb 11713
d62a17ae 11714 return CMD_SUCCESS;
11715}
11716
ff9959b0
QY
11717static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11718 const char *group_name)
d62a17ae 11719{
ff9959b0 11720 struct bgp *bgp;
d62a17ae 11721 struct listnode *node, *nnode;
11722 struct peer_group *group;
ff9959b0
QY
11723 bool found = false;
11724
11725 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11726
11727 if (!bgp) {
9f049418 11728 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
11729 return CMD_WARNING;
11730 }
d62a17ae 11731
11732 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11733 if (group_name) {
11734 if (strmatch(group->name, group_name)) {
d62a17ae 11735 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11736 found = true;
11737 break;
d62a17ae 11738 }
ff9959b0
QY
11739 } else {
11740 bgp_show_one_peer_group(vty, group);
d62a17ae 11741 }
f14e6fdb 11742 }
f14e6fdb 11743
ff9959b0 11744 if (group_name && !found)
d62a17ae 11745 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11746
d62a17ae 11747 return CMD_SUCCESS;
f14e6fdb
DS
11748}
11749
f14e6fdb
DS
11750DEFUN (show_ip_bgp_peer_groups,
11751 show_ip_bgp_peer_groups_cmd,
18c57037 11752 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11753 SHOW_STR
11754 IP_STR
11755 BGP_STR
8386ac43 11756 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11757 "Detailed information on BGP peer groups\n"
11758 "Peer group name\n")
f14e6fdb 11759{
d62a17ae 11760 char *vrf, *pg;
d62a17ae 11761 int idx = 0;
f14e6fdb 11762
a4d82a8a
PZ
11763 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11764 : NULL;
d62a17ae 11765 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11766
ff9959b0 11767 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11768}
3f9c7369 11769
d6e3c605 11770
718e3744 11771/* Redistribute VTY commands. */
11772
718e3744 11773DEFUN (bgp_redistribute_ipv4,
11774 bgp_redistribute_ipv4_cmd,
40d1cbfb 11775 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11776 "Redistribute information from another routing protocol\n"
ab0181ee 11777 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11778{
d62a17ae 11779 VTY_DECLVAR_CONTEXT(bgp, bgp);
11780 int idx_protocol = 1;
11781 int type;
718e3744 11782
d62a17ae 11783 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11784 if (type < 0) {
11785 vty_out(vty, "%% Invalid route type\n");
11786 return CMD_WARNING_CONFIG_FAILED;
11787 }
7f323236 11788
d62a17ae 11789 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11790 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 11791}
11792
d62a17ae 11793ALIAS_HIDDEN(
11794 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11795 "redistribute " FRR_IP_REDIST_STR_BGPD,
11796 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11797
718e3744 11798DEFUN (bgp_redistribute_ipv4_rmap,
11799 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11800 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11801 "Redistribute information from another routing protocol\n"
ab0181ee 11802 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11803 "Route map reference\n"
11804 "Pointer to route-map entries\n")
11805{
d62a17ae 11806 VTY_DECLVAR_CONTEXT(bgp, bgp);
11807 int idx_protocol = 1;
11808 int idx_word = 3;
11809 int type;
11810 struct bgp_redist *red;
e923dd62 11811 bool changed;
1de27621
DA
11812 struct route_map *route_map = route_map_lookup_warn_noexist(
11813 vty, argv[idx_word]->arg);
718e3744 11814
d62a17ae 11815 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11816 if (type < 0) {
11817 vty_out(vty, "%% Invalid route type\n");
11818 return CMD_WARNING_CONFIG_FAILED;
11819 }
718e3744 11820
d62a17ae 11821 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
11822 changed =
11823 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11824 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 11825}
11826
d62a17ae 11827ALIAS_HIDDEN(
11828 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11829 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11830 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11831 "Route map reference\n"
11832 "Pointer to route-map entries\n")
596c17ba 11833
718e3744 11834DEFUN (bgp_redistribute_ipv4_metric,
11835 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11836 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11837 "Redistribute information from another routing protocol\n"
ab0181ee 11838 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11839 "Metric for redistributed routes\n"
11840 "Default metric\n")
11841{
d62a17ae 11842 VTY_DECLVAR_CONTEXT(bgp, bgp);
11843 int idx_protocol = 1;
11844 int idx_number = 3;
11845 int type;
d7c0a89a 11846 uint32_t metric;
d62a17ae 11847 struct bgp_redist *red;
e923dd62 11848 bool changed;
d62a17ae 11849
11850 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11851 if (type < 0) {
11852 vty_out(vty, "%% Invalid route type\n");
11853 return CMD_WARNING_CONFIG_FAILED;
11854 }
11855 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11856
11857 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11858 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11859 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11860}
11861
11862ALIAS_HIDDEN(
11863 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11864 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11865 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11866 "Metric for redistributed routes\n"
11867 "Default metric\n")
596c17ba 11868
718e3744 11869DEFUN (bgp_redistribute_ipv4_rmap_metric,
11870 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11871 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11872 "Redistribute information from another routing protocol\n"
ab0181ee 11873 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11874 "Route map reference\n"
11875 "Pointer to route-map entries\n"
11876 "Metric for redistributed routes\n"
11877 "Default metric\n")
11878{
d62a17ae 11879 VTY_DECLVAR_CONTEXT(bgp, bgp);
11880 int idx_protocol = 1;
11881 int idx_word = 3;
11882 int idx_number = 5;
11883 int type;
d7c0a89a 11884 uint32_t metric;
d62a17ae 11885 struct bgp_redist *red;
e923dd62 11886 bool changed;
1de27621
DA
11887 struct route_map *route_map =
11888 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 11889
11890 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11891 if (type < 0) {
11892 vty_out(vty, "%% Invalid route type\n");
11893 return CMD_WARNING_CONFIG_FAILED;
11894 }
11895 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11896
11897 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
11898 changed =
11899 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11900 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11901 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11902}
11903
11904ALIAS_HIDDEN(
11905 bgp_redistribute_ipv4_rmap_metric,
11906 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11907 "redistribute " FRR_IP_REDIST_STR_BGPD
11908 " route-map WORD metric (0-4294967295)",
11909 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11910 "Route map reference\n"
11911 "Pointer to route-map entries\n"
11912 "Metric for redistributed routes\n"
11913 "Default metric\n")
596c17ba 11914
718e3744 11915DEFUN (bgp_redistribute_ipv4_metric_rmap,
11916 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11917 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11918 "Redistribute information from another routing protocol\n"
ab0181ee 11919 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11920 "Metric for redistributed routes\n"
11921 "Default metric\n"
11922 "Route map reference\n"
11923 "Pointer to route-map entries\n")
11924{
d62a17ae 11925 VTY_DECLVAR_CONTEXT(bgp, bgp);
11926 int idx_protocol = 1;
11927 int idx_number = 3;
11928 int idx_word = 5;
11929 int type;
d7c0a89a 11930 uint32_t metric;
d62a17ae 11931 struct bgp_redist *red;
e923dd62 11932 bool changed;
1de27621
DA
11933 struct route_map *route_map =
11934 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 11935
11936 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11937 if (type < 0) {
11938 vty_out(vty, "%% Invalid route type\n");
11939 return CMD_WARNING_CONFIG_FAILED;
11940 }
11941 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11942
11943 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11944 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
11945 changed |=
11946 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11947 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11948}
11949
11950ALIAS_HIDDEN(
11951 bgp_redistribute_ipv4_metric_rmap,
11952 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11953 "redistribute " FRR_IP_REDIST_STR_BGPD
11954 " metric (0-4294967295) route-map WORD",
11955 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11956 "Metric for redistributed routes\n"
11957 "Default metric\n"
11958 "Route map reference\n"
11959 "Pointer to route-map entries\n")
596c17ba 11960
7c8ff89e
DS
11961DEFUN (bgp_redistribute_ipv4_ospf,
11962 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11963 "redistribute <ospf|table> (1-65535)",
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 11968{
d62a17ae 11969 VTY_DECLVAR_CONTEXT(bgp, bgp);
11970 int idx_ospf_table = 1;
11971 int idx_number = 2;
d7c0a89a
QY
11972 unsigned short instance;
11973 unsigned short protocol;
7c8ff89e 11974
d62a17ae 11975 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11976
d62a17ae 11977 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11978 protocol = ZEBRA_ROUTE_OSPF;
11979 else
11980 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11981
d62a17ae 11982 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11983 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
11984}
11985
d62a17ae 11986ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11987 "redistribute <ospf|table> (1-65535)",
11988 "Redistribute information from another routing protocol\n"
11989 "Open Shortest Path First (OSPFv2)\n"
11990 "Non-main Kernel Routing Table\n"
11991 "Instance ID/Table ID\n")
596c17ba 11992
7c8ff89e
DS
11993DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11994 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11995 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11996 "Redistribute information from another routing protocol\n"
11997 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11998 "Non-main Kernel Routing Table\n"
11999 "Instance ID/Table ID\n"
7c8ff89e
DS
12000 "Route map reference\n"
12001 "Pointer to route-map entries\n")
12002{
d62a17ae 12003 VTY_DECLVAR_CONTEXT(bgp, bgp);
12004 int idx_ospf_table = 1;
12005 int idx_number = 2;
12006 int idx_word = 4;
12007 struct bgp_redist *red;
d7c0a89a 12008 unsigned short instance;
d62a17ae 12009 int protocol;
e923dd62 12010 bool changed;
1de27621
DA
12011 struct route_map *route_map =
12012 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12013
12014 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12015 protocol = ZEBRA_ROUTE_OSPF;
12016 else
12017 protocol = ZEBRA_ROUTE_TABLE;
12018
12019 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12020 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12021 changed =
12022 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12023 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12024}
12025
12026ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12027 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12028 "redistribute <ospf|table> (1-65535) route-map WORD",
12029 "Redistribute information from another routing protocol\n"
12030 "Open Shortest Path First (OSPFv2)\n"
12031 "Non-main Kernel Routing Table\n"
12032 "Instance ID/Table ID\n"
12033 "Route map reference\n"
12034 "Pointer to route-map entries\n")
596c17ba 12035
7c8ff89e
DS
12036DEFUN (bgp_redistribute_ipv4_ospf_metric,
12037 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 12038 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
12039 "Redistribute information from another routing protocol\n"
12040 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12041 "Non-main Kernel Routing Table\n"
12042 "Instance ID/Table ID\n"
7c8ff89e
DS
12043 "Metric for redistributed routes\n"
12044 "Default metric\n")
12045{
d62a17ae 12046 VTY_DECLVAR_CONTEXT(bgp, bgp);
12047 int idx_ospf_table = 1;
12048 int idx_number = 2;
12049 int idx_number_2 = 4;
d7c0a89a 12050 uint32_t metric;
d62a17ae 12051 struct bgp_redist *red;
d7c0a89a 12052 unsigned short instance;
d62a17ae 12053 int protocol;
e923dd62 12054 bool changed;
d62a17ae 12055
12056 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12057 protocol = ZEBRA_ROUTE_OSPF;
12058 else
12059 protocol = ZEBRA_ROUTE_TABLE;
12060
12061 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12062 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12063
12064 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12065 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12066 metric);
12067 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12068}
12069
12070ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12071 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12072 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12073 "Redistribute information from another routing protocol\n"
12074 "Open Shortest Path First (OSPFv2)\n"
12075 "Non-main Kernel Routing Table\n"
12076 "Instance ID/Table ID\n"
12077 "Metric for redistributed routes\n"
12078 "Default metric\n")
596c17ba 12079
7c8ff89e
DS
12080DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12081 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 12082 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
12083 "Redistribute information from another routing protocol\n"
12084 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12085 "Non-main Kernel Routing Table\n"
12086 "Instance ID/Table ID\n"
7c8ff89e
DS
12087 "Route map reference\n"
12088 "Pointer to route-map entries\n"
12089 "Metric for redistributed routes\n"
12090 "Default metric\n")
12091{
d62a17ae 12092 VTY_DECLVAR_CONTEXT(bgp, bgp);
12093 int idx_ospf_table = 1;
12094 int idx_number = 2;
12095 int idx_word = 4;
12096 int idx_number_2 = 6;
d7c0a89a 12097 uint32_t metric;
d62a17ae 12098 struct bgp_redist *red;
d7c0a89a 12099 unsigned short instance;
d62a17ae 12100 int protocol;
e923dd62 12101 bool changed;
1de27621
DA
12102 struct route_map *route_map =
12103 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12104
12105 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12106 protocol = ZEBRA_ROUTE_OSPF;
12107 else
12108 protocol = ZEBRA_ROUTE_TABLE;
12109
12110 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12111 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12112
12113 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12114 changed =
12115 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12116 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12117 metric);
12118 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12119}
12120
12121ALIAS_HIDDEN(
12122 bgp_redistribute_ipv4_ospf_rmap_metric,
12123 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12124 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12125 "Redistribute information from another routing protocol\n"
12126 "Open Shortest Path First (OSPFv2)\n"
12127 "Non-main Kernel Routing Table\n"
12128 "Instance ID/Table ID\n"
12129 "Route map reference\n"
12130 "Pointer to route-map entries\n"
12131 "Metric for redistributed routes\n"
12132 "Default metric\n")
596c17ba 12133
7c8ff89e
DS
12134DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12135 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 12136 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
12137 "Redistribute information from another routing protocol\n"
12138 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12139 "Non-main Kernel Routing Table\n"
12140 "Instance ID/Table ID\n"
7c8ff89e
DS
12141 "Metric for redistributed routes\n"
12142 "Default metric\n"
12143 "Route map reference\n"
12144 "Pointer to route-map entries\n")
12145{
d62a17ae 12146 VTY_DECLVAR_CONTEXT(bgp, bgp);
12147 int idx_ospf_table = 1;
12148 int idx_number = 2;
12149 int idx_number_2 = 4;
12150 int idx_word = 6;
d7c0a89a 12151 uint32_t metric;
d62a17ae 12152 struct bgp_redist *red;
d7c0a89a 12153 unsigned short instance;
d62a17ae 12154 int protocol;
e923dd62 12155 bool changed;
1de27621
DA
12156 struct route_map *route_map =
12157 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12158
12159 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12160 protocol = ZEBRA_ROUTE_OSPF;
12161 else
12162 protocol = ZEBRA_ROUTE_TABLE;
12163
12164 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12165 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12166
12167 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12168 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12169 metric);
1de27621
DA
12170 changed |=
12171 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12172 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12173}
12174
12175ALIAS_HIDDEN(
12176 bgp_redistribute_ipv4_ospf_metric_rmap,
12177 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12178 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12179 "Redistribute information from another routing protocol\n"
12180 "Open Shortest Path First (OSPFv2)\n"
12181 "Non-main Kernel Routing Table\n"
12182 "Instance ID/Table ID\n"
12183 "Metric for redistributed routes\n"
12184 "Default metric\n"
12185 "Route map reference\n"
12186 "Pointer to route-map entries\n")
596c17ba 12187
7c8ff89e
DS
12188DEFUN (no_bgp_redistribute_ipv4_ospf,
12189 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 12190 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
12191 NO_STR
12192 "Redistribute information from another routing protocol\n"
12193 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 12194 "Non-main Kernel Routing Table\n"
31500417
DW
12195 "Instance ID/Table ID\n"
12196 "Metric for redistributed routes\n"
12197 "Default metric\n"
12198 "Route map reference\n"
12199 "Pointer to route-map entries\n")
7c8ff89e 12200{
d62a17ae 12201 VTY_DECLVAR_CONTEXT(bgp, bgp);
12202 int idx_ospf_table = 2;
12203 int idx_number = 3;
d7c0a89a 12204 unsigned short instance;
d62a17ae 12205 int protocol;
12206
12207 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12208 protocol = ZEBRA_ROUTE_OSPF;
12209 else
12210 protocol = ZEBRA_ROUTE_TABLE;
12211
12212 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12213 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12214}
12215
12216ALIAS_HIDDEN(
12217 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12218 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12219 NO_STR
12220 "Redistribute information from another routing protocol\n"
12221 "Open Shortest Path First (OSPFv2)\n"
12222 "Non-main Kernel Routing Table\n"
12223 "Instance ID/Table ID\n"
12224 "Metric for redistributed routes\n"
12225 "Default metric\n"
12226 "Route map reference\n"
12227 "Pointer to route-map entries\n")
596c17ba 12228
718e3744 12229DEFUN (no_bgp_redistribute_ipv4,
12230 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 12231 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12232 NO_STR
12233 "Redistribute information from another routing protocol\n"
3b14d86e 12234 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
12235 "Metric for redistributed routes\n"
12236 "Default metric\n"
12237 "Route map reference\n"
12238 "Pointer to route-map entries\n")
718e3744 12239{
d62a17ae 12240 VTY_DECLVAR_CONTEXT(bgp, bgp);
12241 int idx_protocol = 2;
12242 int type;
12243
12244 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12245 if (type < 0) {
12246 vty_out(vty, "%% Invalid route type\n");
12247 return CMD_WARNING_CONFIG_FAILED;
12248 }
12249 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12250}
12251
12252ALIAS_HIDDEN(
12253 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12254 "no redistribute " FRR_IP_REDIST_STR_BGPD
12255 " [metric (0-4294967295)] [route-map WORD]",
12256 NO_STR
12257 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12258 "Metric for redistributed routes\n"
12259 "Default metric\n"
12260 "Route map reference\n"
12261 "Pointer to route-map entries\n")
596c17ba 12262
718e3744 12263DEFUN (bgp_redistribute_ipv6,
12264 bgp_redistribute_ipv6_cmd,
40d1cbfb 12265 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 12266 "Redistribute information from another routing protocol\n"
ab0181ee 12267 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 12268{
d62a17ae 12269 VTY_DECLVAR_CONTEXT(bgp, bgp);
12270 int idx_protocol = 1;
12271 int type;
718e3744 12272
d62a17ae 12273 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12274 if (type < 0) {
12275 vty_out(vty, "%% Invalid route type\n");
12276 return CMD_WARNING_CONFIG_FAILED;
12277 }
718e3744 12278
d62a17ae 12279 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12280 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 12281}
12282
12283DEFUN (bgp_redistribute_ipv6_rmap,
12284 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 12285 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 12286 "Redistribute information from another routing protocol\n"
ab0181ee 12287 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12288 "Route map reference\n"
12289 "Pointer to route-map entries\n")
12290{
d62a17ae 12291 VTY_DECLVAR_CONTEXT(bgp, bgp);
12292 int idx_protocol = 1;
12293 int idx_word = 3;
12294 int type;
12295 struct bgp_redist *red;
e923dd62 12296 bool changed;
1de27621
DA
12297 struct route_map *route_map =
12298 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 12299
d62a17ae 12300 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12301 if (type < 0) {
12302 vty_out(vty, "%% Invalid route type\n");
12303 return CMD_WARNING_CONFIG_FAILED;
12304 }
718e3744 12305
d62a17ae 12306 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12307 changed =
12308 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12309 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12310}
12311
12312DEFUN (bgp_redistribute_ipv6_metric,
12313 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 12314 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12315 "Redistribute information from another routing protocol\n"
ab0181ee 12316 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12317 "Metric for redistributed routes\n"
12318 "Default metric\n")
12319{
d62a17ae 12320 VTY_DECLVAR_CONTEXT(bgp, bgp);
12321 int idx_protocol = 1;
12322 int idx_number = 3;
12323 int type;
d7c0a89a 12324 uint32_t metric;
d62a17ae 12325 struct bgp_redist *red;
e923dd62 12326 bool changed;
d62a17ae 12327
12328 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12329 if (type < 0) {
12330 vty_out(vty, "%% Invalid route type\n");
12331 return CMD_WARNING_CONFIG_FAILED;
12332 }
12333 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12334
d62a17ae 12335 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12336 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12337 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12338}
12339
12340DEFUN (bgp_redistribute_ipv6_rmap_metric,
12341 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 12342 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12343 "Redistribute information from another routing protocol\n"
ab0181ee 12344 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12345 "Route map reference\n"
12346 "Pointer to route-map entries\n"
12347 "Metric for redistributed routes\n"
12348 "Default metric\n")
12349{
d62a17ae 12350 VTY_DECLVAR_CONTEXT(bgp, bgp);
12351 int idx_protocol = 1;
12352 int idx_word = 3;
12353 int idx_number = 5;
12354 int type;
d7c0a89a 12355 uint32_t metric;
d62a17ae 12356 struct bgp_redist *red;
e923dd62 12357 bool changed;
1de27621
DA
12358 struct route_map *route_map =
12359 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12360
12361 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12362 if (type < 0) {
12363 vty_out(vty, "%% Invalid route type\n");
12364 return CMD_WARNING_CONFIG_FAILED;
12365 }
12366 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12367
d62a17ae 12368 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12369 changed =
12370 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12371 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12372 metric);
12373 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12374}
12375
12376DEFUN (bgp_redistribute_ipv6_metric_rmap,
12377 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 12378 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12379 "Redistribute information from another routing protocol\n"
ab0181ee 12380 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12381 "Metric for redistributed routes\n"
12382 "Default metric\n"
12383 "Route map reference\n"
12384 "Pointer to route-map entries\n")
12385{
d62a17ae 12386 VTY_DECLVAR_CONTEXT(bgp, bgp);
12387 int idx_protocol = 1;
12388 int idx_number = 3;
12389 int idx_word = 5;
12390 int type;
d7c0a89a 12391 uint32_t metric;
d62a17ae 12392 struct bgp_redist *red;
e923dd62 12393 bool changed;
1de27621
DA
12394 struct route_map *route_map =
12395 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12396
12397 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12398 if (type < 0) {
12399 vty_out(vty, "%% Invalid route type\n");
12400 return CMD_WARNING_CONFIG_FAILED;
12401 }
12402 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12403
d62a17ae 12404 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12405 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12406 metric);
1de27621
DA
12407 changed |=
12408 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12409 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12410}
12411
12412DEFUN (no_bgp_redistribute_ipv6,
12413 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 12414 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12415 NO_STR
12416 "Redistribute information from another routing protocol\n"
3b14d86e 12417 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12418 "Metric for redistributed routes\n"
12419 "Default metric\n"
12420 "Route map reference\n"
12421 "Pointer to route-map entries\n")
718e3744 12422{
d62a17ae 12423 VTY_DECLVAR_CONTEXT(bgp, bgp);
12424 int idx_protocol = 2;
12425 int type;
718e3744 12426
d62a17ae 12427 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12428 if (type < 0) {
12429 vty_out(vty, "%% Invalid route type\n");
12430 return CMD_WARNING_CONFIG_FAILED;
12431 }
718e3744 12432
d62a17ae 12433 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12434}
12435
2b791107 12436void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12437 safi_t safi)
d62a17ae 12438{
12439 int i;
12440
12441 /* Unicast redistribution only. */
12442 if (safi != SAFI_UNICAST)
2b791107 12443 return;
d62a17ae 12444
12445 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12446 /* Redistribute BGP does not make sense. */
12447 if (i != ZEBRA_ROUTE_BGP) {
12448 struct list *red_list;
12449 struct listnode *node;
12450 struct bgp_redist *red;
12451
12452 red_list = bgp->redist[afi][i];
12453 if (!red_list)
12454 continue;
12455
12456 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12457 /* "redistribute" configuration. */
12458 vty_out(vty, " redistribute %s",
12459 zebra_route_string(i));
12460 if (red->instance)
12461 vty_out(vty, " %d", red->instance);
12462 if (red->redist_metric_flag)
12463 vty_out(vty, " metric %u",
12464 red->redist_metric);
12465 if (red->rmap.name)
12466 vty_out(vty, " route-map %s",
12467 red->rmap.name);
12468 vty_out(vty, "\n");
12469 }
12470 }
12471 }
718e3744 12472}
6b0655a2 12473
b9c7bc5a
PZ
12474/* This is part of the address-family block (unicast only) */
12475void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12476 afi_t afi)
12477{
b9c7bc5a 12478 int indent = 2;
ddb5b488 12479
8a066a70
PG
12480 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12481 if (listcount(bgp->vpn_policy[afi].import_vrf))
12482 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12483 bgp->vpn_policy[afi]
bb4f6190 12484 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
12485 else
12486 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12487 bgp->vpn_policy[afi]
12488 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12489 }
12a844a5
DS
12490 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12491 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12492 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12493 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12494 return;
12495
e70e9f8e
PZ
12496 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12497 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12498
12499 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12500
12501 } else {
12502 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12503 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12504 bgp->vpn_policy[afi].tovpn_label);
12505 }
ddb5b488
PZ
12506 }
12507 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12508 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12509 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12510 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12511 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12512 sizeof(buf)));
12513 }
12514 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12515 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12516
12517 char buf[PREFIX_STRLEN];
12518 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12519 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12520 sizeof(buf))) {
12521
b9c7bc5a
PZ
12522 vty_out(vty, "%*snexthop vpn export %s\n",
12523 indent, "", buf);
ddb5b488
PZ
12524 }
12525 }
12526 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12527 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12528 && ecommunity_cmp(
12529 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12530 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12531
12532 char *b = ecommunity_ecom2str(
12533 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12534 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12535 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12536 XFREE(MTYPE_ECOMMUNITY_STR, b);
12537 } else {
12538 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12539 char *b = ecommunity_ecom2str(
12540 bgp->vpn_policy[afi]
12541 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12542 ECOMMUNITY_FORMAT_ROUTE_MAP,
12543 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12544 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12545 XFREE(MTYPE_ECOMMUNITY_STR, b);
12546 }
12547 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12548 char *b = ecommunity_ecom2str(
12549 bgp->vpn_policy[afi]
12550 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12551 ECOMMUNITY_FORMAT_ROUTE_MAP,
12552 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12553 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12554 XFREE(MTYPE_ECOMMUNITY_STR, b);
12555 }
12556 }
bb4f6190
DS
12557
12558 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12559 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12560 bgp->vpn_policy[afi]
12561 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12562
301ad80a
PG
12563 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12564 char *b = ecommunity_ecom2str(
12565 bgp->vpn_policy[afi]
12566 .import_redirect_rtlist,
12567 ECOMMUNITY_FORMAT_ROUTE_MAP,
12568 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12569
301ad80a
PG
12570 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12571 XFREE(MTYPE_ECOMMUNITY_STR, b);
12572 }
ddb5b488
PZ
12573}
12574
12575
718e3744 12576/* BGP node structure. */
d62a17ae 12577static struct cmd_node bgp_node = {
9d303b37 12578 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12579};
12580
d62a17ae 12581static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12582 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12583};
12584
d62a17ae 12585static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12586 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12587};
12588
d62a17ae 12589static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12590 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12591};
12592
d62a17ae 12593static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12594 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12595};
12596
d62a17ae 12597static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12598 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12599};
12600
d62a17ae 12601static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12602 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12603};
12604
d62a17ae 12605static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12606 "%s(config-router-af)# ", 1};
6b0655a2 12607
d62a17ae 12608static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12609 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12610
d62a17ae 12611static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12612 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12613
d62a17ae 12614static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12615 "%s(config-router-af-vni)# ", 1};
90e60aa7 12616
7c40bf39 12617static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12618 "%s(config-router-af)# ", 1};
12619
12620static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12621 "%s(config-router-af-vpnv6)# ", 1};
12622
d62a17ae 12623static void community_list_vty(void);
1f8ae70b 12624
d62a17ae 12625static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12626{
d62a17ae 12627 struct bgp *bgp;
12628 struct peer *peer;
d62a17ae 12629 struct listnode *lnbgp, *lnpeer;
b8a815e5 12630
d62a17ae 12631 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12632 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12633 /* only provide suggestions on the appropriate input
12634 * token type,
12635 * they'll otherwise show up multiple times */
12636 enum cmd_token_type match_type;
12637 char *name = peer->host;
d48ed3e0 12638
d62a17ae 12639 if (peer->conf_if) {
12640 match_type = VARIABLE_TKN;
12641 name = peer->conf_if;
12642 } else if (strchr(peer->host, ':'))
12643 match_type = IPV6_TKN;
12644 else
12645 match_type = IPV4_TKN;
d48ed3e0 12646
d62a17ae 12647 if (token->type != match_type)
12648 continue;
d48ed3e0 12649
d62a17ae 12650 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12651 }
d62a17ae 12652 }
b8a815e5
DL
12653}
12654
12655static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12656 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12657 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12658 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12659 {.completions = NULL}};
12660
47a306a0
DS
12661static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12662{
12663 struct bgp *bgp;
12664 struct peer_group *group;
12665 struct listnode *lnbgp, *lnpeer;
12666
12667 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12668 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12669 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12670 group->name));
12671 }
12672}
12673
12674static const struct cmd_variable_handler bgp_var_peergroup[] = {
12675 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12676 {.completions = NULL} };
12677
d62a17ae 12678void bgp_vty_init(void)
12679{
12680 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12681 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12682
12683 /* Install bgp top node. */
12684 install_node(&bgp_node, bgp_config_write);
12685 install_node(&bgp_ipv4_unicast_node, NULL);
12686 install_node(&bgp_ipv4_multicast_node, NULL);
12687 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12688 install_node(&bgp_ipv6_unicast_node, NULL);
12689 install_node(&bgp_ipv6_multicast_node, NULL);
12690 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12691 install_node(&bgp_vpnv4_node, NULL);
12692 install_node(&bgp_vpnv6_node, NULL);
12693 install_node(&bgp_evpn_node, NULL);
12694 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12695 install_node(&bgp_flowspecv4_node, NULL);
12696 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12697
12698 /* Install default VTY commands to new nodes. */
12699 install_default(BGP_NODE);
12700 install_default(BGP_IPV4_NODE);
12701 install_default(BGP_IPV4M_NODE);
12702 install_default(BGP_IPV4L_NODE);
12703 install_default(BGP_IPV6_NODE);
12704 install_default(BGP_IPV6M_NODE);
12705 install_default(BGP_IPV6L_NODE);
12706 install_default(BGP_VPNV4_NODE);
12707 install_default(BGP_VPNV6_NODE);
7c40bf39 12708 install_default(BGP_FLOWSPECV4_NODE);
12709 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12710 install_default(BGP_EVPN_NODE);
12711 install_default(BGP_EVPN_VNI_NODE);
12712
12713 /* "bgp multiple-instance" commands. */
12714 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12715 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12716
12717 /* "bgp config-type" commands. */
12718 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12719 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12720
8029b216
AK
12721 /* "bgp local-mac" hidden commands. */
12722 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12723 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12724
d62a17ae 12725 /* bgp route-map delay-timer commands. */
12726 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12727 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12728
12729 /* Dummy commands (Currently not supported) */
12730 install_element(BGP_NODE, &no_synchronization_cmd);
12731 install_element(BGP_NODE, &no_auto_summary_cmd);
12732
12733 /* "router bgp" commands. */
12734 install_element(CONFIG_NODE, &router_bgp_cmd);
12735
12736 /* "no router bgp" commands. */
12737 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12738
12739 /* "bgp router-id" commands. */
12740 install_element(BGP_NODE, &bgp_router_id_cmd);
12741 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12742
12743 /* "bgp cluster-id" commands. */
12744 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12745 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12746
12747 /* "bgp confederation" commands. */
12748 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12749 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12750
12751 /* "bgp confederation peers" commands. */
12752 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12753 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12754
12755 /* bgp max-med command */
12756 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12757 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12758 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12759 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12760 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12761
12762 /* bgp disable-ebgp-connected-nh-check */
12763 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12764 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12765
12766 /* bgp update-delay command */
12767 install_element(BGP_NODE, &bgp_update_delay_cmd);
12768 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12769 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12770
12771 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12772 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12773 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12774 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12775
12776 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12777 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12778
12779 /* "maximum-paths" commands. */
12780 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12781 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12782 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12783 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12784 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12785 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12786 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12787 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12788 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12789 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12790 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12791 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12792 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12793 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12794 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12795
12796 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12797 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12798 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12799 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12800 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12801
12802 /* "timers bgp" commands. */
12803 install_element(BGP_NODE, &bgp_timers_cmd);
12804 install_element(BGP_NODE, &no_bgp_timers_cmd);
12805
12806 /* route-map delay-timer commands - per instance for backwards compat.
12807 */
12808 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12809 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12810
12811 /* "bgp client-to-client reflection" commands */
12812 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12813 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12814
12815 /* "bgp always-compare-med" commands */
12816 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12817 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12818
12819 /* "bgp deterministic-med" commands */
12820 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12821 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12822
12823 /* "bgp graceful-restart" commands */
12824 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12825 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12826 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12827 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12828 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12829 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12830
12831 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12832 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12833
7f323236
DW
12834 /* "bgp graceful-shutdown" commands */
12835 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12836 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12837
d62a17ae 12838 /* "bgp fast-external-failover" commands */
12839 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12840 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12841
12842 /* "bgp enforce-first-as" commands */
12843 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
d62a17ae 12844
12845 /* "bgp bestpath compare-routerid" commands */
12846 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12847 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12848
12849 /* "bgp bestpath as-path ignore" commands */
12850 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12851 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12852
12853 /* "bgp bestpath as-path confed" commands */
12854 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12855 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12856
12857 /* "bgp bestpath as-path multipath-relax" commands */
12858 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12859 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12860
12861 /* "bgp log-neighbor-changes" commands */
12862 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12863 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12864
12865 /* "bgp bestpath med" commands */
12866 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12867 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12868
12869 /* "no bgp default ipv4-unicast" commands. */
12870 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12871 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12872
12873 /* "bgp network import-check" commands. */
12874 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12875 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12876 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12877
12878 /* "bgp default local-preference" commands. */
12879 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12880 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12881
12882 /* bgp default show-hostname */
12883 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12884 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12885
12886 /* "bgp default subgroup-pkt-queue-max" commands. */
12887 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12888 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12889
12890 /* bgp ibgp-allow-policy-mods command */
12891 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12892 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12893
12894 /* "bgp listen limit" commands. */
12895 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12896 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12897
12898 /* "bgp listen range" commands. */
12899 install_element(BGP_NODE, &bgp_listen_range_cmd);
12900 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12901
8175f54a 12902 /* "bgp default shutdown" command */
f26845f9
QY
12903 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12904
d62a17ae 12905 /* "neighbor remote-as" commands. */
12906 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12907 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12908 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12909 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12910 install_element(BGP_NODE,
12911 &neighbor_interface_v6only_config_remote_as_cmd);
12912 install_element(BGP_NODE, &no_neighbor_cmd);
12913 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12914
12915 /* "neighbor peer-group" commands. */
12916 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12917 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12918 install_element(BGP_NODE,
12919 &no_neighbor_interface_peer_group_remote_as_cmd);
12920
12921 /* "neighbor local-as" commands. */
12922 install_element(BGP_NODE, &neighbor_local_as_cmd);
12923 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12924 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12925 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12926
12927 /* "neighbor solo" commands. */
12928 install_element(BGP_NODE, &neighbor_solo_cmd);
12929 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12930
12931 /* "neighbor password" commands. */
12932 install_element(BGP_NODE, &neighbor_password_cmd);
12933 install_element(BGP_NODE, &no_neighbor_password_cmd);
12934
12935 /* "neighbor activate" commands. */
12936 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12937 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12938 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12939 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12940 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12941 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12942 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12943 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12944 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 12945 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12946 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 12947 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12948
12949 /* "no neighbor activate" commands. */
12950 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12951 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12952 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12953 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12954 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12955 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12956 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12957 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12958 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 12959 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12960 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 12961 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12962
12963 /* "neighbor peer-group" set commands. */
12964 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12965 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12966 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12967 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12968 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12969 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12970 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12971 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 12972 install_element(BGP_FLOWSPECV4_NODE,
12973 &neighbor_set_peer_group_hidden_cmd);
12974 install_element(BGP_FLOWSPECV6_NODE,
12975 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 12976
12977 /* "no neighbor peer-group unset" commands. */
12978 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12979 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12980 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12981 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12982 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12983 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12984 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12985 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 12986 install_element(BGP_FLOWSPECV4_NODE,
12987 &no_neighbor_set_peer_group_hidden_cmd);
12988 install_element(BGP_FLOWSPECV6_NODE,
12989 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 12990
12991 /* "neighbor softreconfiguration inbound" commands.*/
12992 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12993 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12994 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12995 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12996 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12997 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12998 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12999 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13000 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13001 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13002 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13003 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13004 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13005 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13006 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13007 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13008 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13009 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 13010 install_element(BGP_FLOWSPECV4_NODE,
13011 &neighbor_soft_reconfiguration_cmd);
13012 install_element(BGP_FLOWSPECV4_NODE,
13013 &no_neighbor_soft_reconfiguration_cmd);
13014 install_element(BGP_FLOWSPECV6_NODE,
13015 &neighbor_soft_reconfiguration_cmd);
13016 install_element(BGP_FLOWSPECV6_NODE,
13017 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
13018 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13019 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 13020
13021 /* "neighbor attribute-unchanged" commands. */
13022 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13023 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13024 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13025 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13026 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13027 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13028 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13029 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13030 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13031 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13032 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13033 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13034 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13035 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13036 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13037 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13038 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13039 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13040
13041 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13042 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13043
13044 /* "nexthop-local unchanged" commands */
13045 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13046 install_element(BGP_IPV6_NODE,
13047 &no_neighbor_nexthop_local_unchanged_cmd);
13048
13049 /* "neighbor next-hop-self" commands. */
13050 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13051 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13052 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13053 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13054 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13055 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13056 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13057 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13058 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13059 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13060 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13061 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13062 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13063 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13064 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13065 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13066 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13067 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
13068 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13069 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 13070
13071 /* "neighbor next-hop-self force" commands. */
13072 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13073 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13074 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13075 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13076 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13077 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13078 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13079 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13080 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13081 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13082 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13083 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13084 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13085 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13086 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13087 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13088 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13089 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13090
13091 /* "neighbor as-override" commands. */
13092 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13093 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13094 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13095 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13096 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13097 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13098 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13099 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13100 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13101 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13102 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13103 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13104 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13105 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13106 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13107 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13108 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13109 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13110
13111 /* "neighbor remove-private-AS" commands. */
13112 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13113 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13114 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13115 install_element(BGP_NODE,
13116 &no_neighbor_remove_private_as_all_hidden_cmd);
13117 install_element(BGP_NODE,
13118 &neighbor_remove_private_as_replace_as_hidden_cmd);
13119 install_element(BGP_NODE,
13120 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13121 install_element(BGP_NODE,
13122 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13123 install_element(
13124 BGP_NODE,
13125 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13126 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13127 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13128 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13129 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13130 install_element(BGP_IPV4_NODE,
13131 &neighbor_remove_private_as_replace_as_cmd);
13132 install_element(BGP_IPV4_NODE,
13133 &no_neighbor_remove_private_as_replace_as_cmd);
13134 install_element(BGP_IPV4_NODE,
13135 &neighbor_remove_private_as_all_replace_as_cmd);
13136 install_element(BGP_IPV4_NODE,
13137 &no_neighbor_remove_private_as_all_replace_as_cmd);
13138 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13139 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13140 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13141 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13142 install_element(BGP_IPV4M_NODE,
13143 &neighbor_remove_private_as_replace_as_cmd);
13144 install_element(BGP_IPV4M_NODE,
13145 &no_neighbor_remove_private_as_replace_as_cmd);
13146 install_element(BGP_IPV4M_NODE,
13147 &neighbor_remove_private_as_all_replace_as_cmd);
13148 install_element(BGP_IPV4M_NODE,
13149 &no_neighbor_remove_private_as_all_replace_as_cmd);
13150 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13151 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13152 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13153 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13154 install_element(BGP_IPV4L_NODE,
13155 &neighbor_remove_private_as_replace_as_cmd);
13156 install_element(BGP_IPV4L_NODE,
13157 &no_neighbor_remove_private_as_replace_as_cmd);
13158 install_element(BGP_IPV4L_NODE,
13159 &neighbor_remove_private_as_all_replace_as_cmd);
13160 install_element(BGP_IPV4L_NODE,
13161 &no_neighbor_remove_private_as_all_replace_as_cmd);
13162 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13163 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13164 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13165 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13166 install_element(BGP_IPV6_NODE,
13167 &neighbor_remove_private_as_replace_as_cmd);
13168 install_element(BGP_IPV6_NODE,
13169 &no_neighbor_remove_private_as_replace_as_cmd);
13170 install_element(BGP_IPV6_NODE,
13171 &neighbor_remove_private_as_all_replace_as_cmd);
13172 install_element(BGP_IPV6_NODE,
13173 &no_neighbor_remove_private_as_all_replace_as_cmd);
13174 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13175 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13176 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13177 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13178 install_element(BGP_IPV6M_NODE,
13179 &neighbor_remove_private_as_replace_as_cmd);
13180 install_element(BGP_IPV6M_NODE,
13181 &no_neighbor_remove_private_as_replace_as_cmd);
13182 install_element(BGP_IPV6M_NODE,
13183 &neighbor_remove_private_as_all_replace_as_cmd);
13184 install_element(BGP_IPV6M_NODE,
13185 &no_neighbor_remove_private_as_all_replace_as_cmd);
13186 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13187 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13188 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13189 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13190 install_element(BGP_IPV6L_NODE,
13191 &neighbor_remove_private_as_replace_as_cmd);
13192 install_element(BGP_IPV6L_NODE,
13193 &no_neighbor_remove_private_as_replace_as_cmd);
13194 install_element(BGP_IPV6L_NODE,
13195 &neighbor_remove_private_as_all_replace_as_cmd);
13196 install_element(BGP_IPV6L_NODE,
13197 &no_neighbor_remove_private_as_all_replace_as_cmd);
13198 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13199 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13200 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13201 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13202 install_element(BGP_VPNV4_NODE,
13203 &neighbor_remove_private_as_replace_as_cmd);
13204 install_element(BGP_VPNV4_NODE,
13205 &no_neighbor_remove_private_as_replace_as_cmd);
13206 install_element(BGP_VPNV4_NODE,
13207 &neighbor_remove_private_as_all_replace_as_cmd);
13208 install_element(BGP_VPNV4_NODE,
13209 &no_neighbor_remove_private_as_all_replace_as_cmd);
13210 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13211 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13212 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13213 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13214 install_element(BGP_VPNV6_NODE,
13215 &neighbor_remove_private_as_replace_as_cmd);
13216 install_element(BGP_VPNV6_NODE,
13217 &no_neighbor_remove_private_as_replace_as_cmd);
13218 install_element(BGP_VPNV6_NODE,
13219 &neighbor_remove_private_as_all_replace_as_cmd);
13220 install_element(BGP_VPNV6_NODE,
13221 &no_neighbor_remove_private_as_all_replace_as_cmd);
13222
13223 /* "neighbor send-community" commands.*/
13224 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13225 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13226 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13227 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13228 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13229 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13230 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13231 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13232 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13233 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13234 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13235 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13236 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13237 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13238 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13239 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13240 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13241 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13242 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13243 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13244 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13245 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13246 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13247 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13248 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13249 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13250 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13251 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13252 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13253 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13254 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13255 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13256 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13257 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13258 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13259 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13260
13261 /* "neighbor route-reflector" commands.*/
13262 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13263 install_element(BGP_NODE,
13264 &no_neighbor_route_reflector_client_hidden_cmd);
13265 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13266 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13267 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13268 install_element(BGP_IPV4M_NODE,
13269 &no_neighbor_route_reflector_client_cmd);
13270 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13271 install_element(BGP_IPV4L_NODE,
13272 &no_neighbor_route_reflector_client_cmd);
13273 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13274 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13275 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13276 install_element(BGP_IPV6M_NODE,
13277 &no_neighbor_route_reflector_client_cmd);
13278 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13279 install_element(BGP_IPV6L_NODE,
13280 &no_neighbor_route_reflector_client_cmd);
13281 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13282 install_element(BGP_VPNV4_NODE,
13283 &no_neighbor_route_reflector_client_cmd);
13284 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13285 install_element(BGP_VPNV6_NODE,
13286 &no_neighbor_route_reflector_client_cmd);
7c40bf39 13287 install_element(BGP_FLOWSPECV4_NODE,
13288 &neighbor_route_reflector_client_cmd);
13289 install_element(BGP_FLOWSPECV4_NODE,
13290 &no_neighbor_route_reflector_client_cmd);
13291 install_element(BGP_FLOWSPECV6_NODE,
13292 &neighbor_route_reflector_client_cmd);
13293 install_element(BGP_FLOWSPECV6_NODE,
13294 &no_neighbor_route_reflector_client_cmd);
d62a17ae 13295 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13296 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13297
13298 /* "neighbor route-server" commands.*/
13299 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13300 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13301 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13302 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13303 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13304 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13305 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13306 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13307 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13308 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13309 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13310 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13311 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13312 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13313 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13314 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13315 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13316 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
13317 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13318 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 13319 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13320 install_element(BGP_FLOWSPECV4_NODE,
13321 &no_neighbor_route_server_client_cmd);
13322 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13323 install_element(BGP_FLOWSPECV6_NODE,
13324 &no_neighbor_route_server_client_cmd);
d62a17ae 13325
13326 /* "neighbor addpath-tx-all-paths" commands.*/
13327 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13328 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13329 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13330 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13331 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13332 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13333 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13334 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13335 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13336 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13337 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13338 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13339 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13340 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13341 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13342 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13343 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13344 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13345
13346 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13347 install_element(BGP_NODE,
13348 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13349 install_element(BGP_NODE,
13350 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13351 install_element(BGP_IPV4_NODE,
13352 &neighbor_addpath_tx_bestpath_per_as_cmd);
13353 install_element(BGP_IPV4_NODE,
13354 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13355 install_element(BGP_IPV4M_NODE,
13356 &neighbor_addpath_tx_bestpath_per_as_cmd);
13357 install_element(BGP_IPV4M_NODE,
13358 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13359 install_element(BGP_IPV4L_NODE,
13360 &neighbor_addpath_tx_bestpath_per_as_cmd);
13361 install_element(BGP_IPV4L_NODE,
13362 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13363 install_element(BGP_IPV6_NODE,
13364 &neighbor_addpath_tx_bestpath_per_as_cmd);
13365 install_element(BGP_IPV6_NODE,
13366 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13367 install_element(BGP_IPV6M_NODE,
13368 &neighbor_addpath_tx_bestpath_per_as_cmd);
13369 install_element(BGP_IPV6M_NODE,
13370 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13371 install_element(BGP_IPV6L_NODE,
13372 &neighbor_addpath_tx_bestpath_per_as_cmd);
13373 install_element(BGP_IPV6L_NODE,
13374 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13375 install_element(BGP_VPNV4_NODE,
13376 &neighbor_addpath_tx_bestpath_per_as_cmd);
13377 install_element(BGP_VPNV4_NODE,
13378 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13379 install_element(BGP_VPNV6_NODE,
13380 &neighbor_addpath_tx_bestpath_per_as_cmd);
13381 install_element(BGP_VPNV6_NODE,
13382 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13383
13384 /* "neighbor passive" commands. */
13385 install_element(BGP_NODE, &neighbor_passive_cmd);
13386 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13387
13388
13389 /* "neighbor shutdown" commands. */
13390 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13391 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13392 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13393 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13394
13395 /* "neighbor capability extended-nexthop" commands.*/
13396 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13397 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13398
13399 /* "neighbor capability orf prefix-list" commands.*/
13400 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13401 install_element(BGP_NODE,
13402 &no_neighbor_capability_orf_prefix_hidden_cmd);
13403 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13404 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13405 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13406 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13407 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13408 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13409 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13410 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13411 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13412 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13413 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13414 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13415
13416 /* "neighbor capability dynamic" commands.*/
13417 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13418 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13419
13420 /* "neighbor dont-capability-negotiate" commands. */
13421 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13422 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13423
13424 /* "neighbor ebgp-multihop" commands. */
13425 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13426 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13427 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13428
13429 /* "neighbor disable-connected-check" commands. */
13430 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13431 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13432
47cbc09b
PM
13433 /* "neighbor enforce-first-as" commands. */
13434 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13435 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13436
d62a17ae 13437 /* "neighbor description" commands. */
13438 install_element(BGP_NODE, &neighbor_description_cmd);
13439 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13440 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13441
13442 /* "neighbor update-source" commands. "*/
13443 install_element(BGP_NODE, &neighbor_update_source_cmd);
13444 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13445
13446 /* "neighbor default-originate" commands. */
13447 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13448 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13449 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13450 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13451 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13452 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13453 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13454 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13455 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13456 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13457 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13458 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13459 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13460 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13461 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13462 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13463 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13464 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13465 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13466 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13467 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13468
13469 /* "neighbor port" commands. */
13470 install_element(BGP_NODE, &neighbor_port_cmd);
13471 install_element(BGP_NODE, &no_neighbor_port_cmd);
13472
13473 /* "neighbor weight" commands. */
13474 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13475 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13476
13477 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13478 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13479 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13480 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13481 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13482 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13483 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13484 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13485 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13486 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13487 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13488 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13489 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13490 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13491 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13492 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13493
13494 /* "neighbor override-capability" commands. */
13495 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13496 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13497
13498 /* "neighbor strict-capability-match" commands. */
13499 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13500 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13501
13502 /* "neighbor timers" commands. */
13503 install_element(BGP_NODE, &neighbor_timers_cmd);
13504 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13505
13506 /* "neighbor timers connect" commands. */
13507 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13508 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13509
13510 /* "neighbor advertisement-interval" commands. */
13511 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13512 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13513
13514 /* "neighbor interface" commands. */
13515 install_element(BGP_NODE, &neighbor_interface_cmd);
13516 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13517
13518 /* "neighbor distribute" commands. */
13519 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13520 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13521 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13522 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13523 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13524 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13525 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13526 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13527 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13528 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13529 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13530 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13531 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13532 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13533 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13534 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13535 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13536 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13537
13538 /* "neighbor prefix-list" commands. */
13539 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13540 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13541 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13542 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13543 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13544 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13545 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13546 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13547 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13548 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13549 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13550 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13551 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13552 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13553 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13554 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13555 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13556 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13557 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13558 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13559 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13560 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13561
13562 /* "neighbor filter-list" commands. */
13563 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13564 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13565 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13566 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13567 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13568 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13569 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13570 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13571 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13572 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13573 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13574 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13575 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13576 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13577 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13578 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13579 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13580 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13581 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13582 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13583 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13584 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13585
13586 /* "neighbor route-map" commands. */
13587 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13588 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13589 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13590 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13591 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13592 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13593 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13594 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13595 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13596 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13597 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13598 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13599 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13600 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13601 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13602 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13603 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13604 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13605 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13606 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13607 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13608 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13609 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13610 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13611
13612 /* "neighbor unsuppress-map" commands. */
13613 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13614 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13615 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13616 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13617 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13618 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13619 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13620 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13621 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13622 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13623 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13624 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13625 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13626 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13627 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13628 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13629 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13630 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13631
13632 /* "neighbor maximum-prefix" commands. */
13633 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13634 install_element(BGP_NODE,
13635 &neighbor_maximum_prefix_threshold_hidden_cmd);
13636 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13637 install_element(BGP_NODE,
13638 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13639 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13640 install_element(BGP_NODE,
13641 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13642 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13643 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13644 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13645 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13646 install_element(BGP_IPV4_NODE,
13647 &neighbor_maximum_prefix_threshold_warning_cmd);
13648 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13649 install_element(BGP_IPV4_NODE,
13650 &neighbor_maximum_prefix_threshold_restart_cmd);
13651 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13652 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13653 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13654 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13655 install_element(BGP_IPV4M_NODE,
13656 &neighbor_maximum_prefix_threshold_warning_cmd);
13657 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13658 install_element(BGP_IPV4M_NODE,
13659 &neighbor_maximum_prefix_threshold_restart_cmd);
13660 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13661 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13662 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13663 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13664 install_element(BGP_IPV4L_NODE,
13665 &neighbor_maximum_prefix_threshold_warning_cmd);
13666 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13667 install_element(BGP_IPV4L_NODE,
13668 &neighbor_maximum_prefix_threshold_restart_cmd);
13669 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13670 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13671 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13672 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13673 install_element(BGP_IPV6_NODE,
13674 &neighbor_maximum_prefix_threshold_warning_cmd);
13675 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13676 install_element(BGP_IPV6_NODE,
13677 &neighbor_maximum_prefix_threshold_restart_cmd);
13678 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13679 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13680 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13681 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13682 install_element(BGP_IPV6M_NODE,
13683 &neighbor_maximum_prefix_threshold_warning_cmd);
13684 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13685 install_element(BGP_IPV6M_NODE,
13686 &neighbor_maximum_prefix_threshold_restart_cmd);
13687 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13688 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13689 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13690 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13691 install_element(BGP_IPV6L_NODE,
13692 &neighbor_maximum_prefix_threshold_warning_cmd);
13693 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13694 install_element(BGP_IPV6L_NODE,
13695 &neighbor_maximum_prefix_threshold_restart_cmd);
13696 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13697 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13698 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13699 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13700 install_element(BGP_VPNV4_NODE,
13701 &neighbor_maximum_prefix_threshold_warning_cmd);
13702 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13703 install_element(BGP_VPNV4_NODE,
13704 &neighbor_maximum_prefix_threshold_restart_cmd);
13705 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13706 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13707 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13708 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13709 install_element(BGP_VPNV6_NODE,
13710 &neighbor_maximum_prefix_threshold_warning_cmd);
13711 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13712 install_element(BGP_VPNV6_NODE,
13713 &neighbor_maximum_prefix_threshold_restart_cmd);
13714 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13715
13716 /* "neighbor allowas-in" */
13717 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13718 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13719 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13720 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13721 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13722 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13723 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13724 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13725 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13726 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13727 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13728 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13729 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13730 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13731 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13732 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13733 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13734 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13735 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13736 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13737
13738 /* address-family commands. */
13739 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13740 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13741#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13742 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13743 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13744#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13745
d62a17ae 13746 install_element(BGP_NODE, &address_family_evpn_cmd);
13747
13748 /* "exit-address-family" command. */
13749 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13750 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13751 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13752 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13753 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13754 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13755 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13756 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13757 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13758 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13759 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13760
13761 /* "clear ip bgp commands" */
13762 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13763
13764 /* clear ip bgp prefix */
13765 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13766 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13767 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13768
13769 /* "show [ip] bgp summary" commands. */
13770 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 13771 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 13772 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13773 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13774 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13775 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13776 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13777
13778 /* "show [ip] bgp neighbors" commands. */
13779 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13780
13781 /* "show [ip] bgp peer-group" commands. */
13782 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13783
13784 /* "show [ip] bgp paths" commands. */
13785 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13786
13787 /* "show [ip] bgp community" commands. */
13788 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13789
13790 /* "show ip bgp large-community" commands. */
13791 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13792 /* "show [ip] bgp attribute-info" commands. */
13793 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13794 /* "show [ip] bgp route-leak" command */
13795 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13796
13797 /* "redistribute" commands. */
13798 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13799 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13800 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13801 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13802 install_element(BGP_NODE,
13803 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13804 install_element(BGP_NODE,
13805 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13806 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13807 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13808 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13809 install_element(BGP_NODE,
13810 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13811 install_element(BGP_NODE,
13812 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13813 install_element(BGP_NODE,
13814 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13815 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13816 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13817 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13818 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13819 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13820 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13821 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13822 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13823 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13824 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13825 install_element(BGP_IPV4_NODE,
13826 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13827 install_element(BGP_IPV4_NODE,
13828 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13829 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13830 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13831 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13832 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13833 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13834 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13835
b9c7bc5a
PZ
13836 /* import|export vpn [route-map WORD] */
13837 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13838 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13839
12a844a5
DS
13840 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13841 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13842
d62a17ae 13843 /* ttl_security commands */
13844 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13845 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13846
13847 /* "show [ip] bgp memory" commands. */
13848 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13849
acf71666
MK
13850 /* "show bgp martian next-hop" */
13851 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13852
48ecf8f5
DS
13853 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
13854
d62a17ae 13855 /* "show [ip] bgp views" commands. */
13856 install_element(VIEW_NODE, &show_bgp_views_cmd);
13857
13858 /* "show [ip] bgp vrfs" commands. */
13859 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13860
13861 /* Community-list. */
13862 community_list_vty();
ddb5b488
PZ
13863
13864 /* vpn-policy commands */
b9c7bc5a
PZ
13865 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13866 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13867 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13868 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13869 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13870 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13871 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13872 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13873 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13874 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
13875 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13876 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 13877
301ad80a
PG
13878 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13879 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13880
b9c7bc5a
PZ
13881 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13882 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13883 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13884 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13885 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13886 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13887 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13888 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13889 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13890 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
13891 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13892 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 13893}
6b0655a2 13894
718e3744 13895#include "memory.h"
13896#include "bgp_regex.h"
13897#include "bgp_clist.h"
13898#include "bgp_ecommunity.h"
13899
13900/* VTY functions. */
13901
13902/* Direction value to string conversion. */
d62a17ae 13903static const char *community_direct_str(int direct)
13904{
13905 switch (direct) {
13906 case COMMUNITY_DENY:
13907 return "deny";
13908 case COMMUNITY_PERMIT:
13909 return "permit";
13910 default:
13911 return "unknown";
13912 }
718e3744 13913}
13914
13915/* Display error string. */
d62a17ae 13916static void community_list_perror(struct vty *vty, int ret)
13917{
13918 switch (ret) {
13919 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13920 vty_out(vty, "%% Can't find community-list\n");
13921 break;
13922 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13923 vty_out(vty, "%% Malformed community-list value\n");
13924 break;
13925 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13926 vty_out(vty,
13927 "%% Community name conflict, previously defined as standard community\n");
13928 break;
13929 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13930 vty_out(vty,
13931 "%% Community name conflict, previously defined as expanded community\n");
13932 break;
13933 }
718e3744 13934}
13935
5bf15956
DW
13936/* "community-list" keyword help string. */
13937#define COMMUNITY_LIST_STR "Add a community list entry\n"
13938
7336e101
SP
13939/*community-list standard */
13940DEFUN (community_list_standard,
13941 bgp_community_list_standard_cmd,
13942 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13943 BGP_STR
718e3744 13944 COMMUNITY_LIST_STR
13945 "Community list number (standard)\n"
5bf15956 13946 "Add an standard community-list entry\n"
718e3744 13947 "Community list name\n"
13948 "Specify community to reject\n"
13949 "Specify community to accept\n"
13950 COMMUNITY_VAL_STR)
13951{
d62a17ae 13952 char *cl_name_or_number = NULL;
13953 int direct = 0;
13954 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13955
d62a17ae 13956 int idx = 0;
7336e101
SP
13957
13958 if (argv_find(argv, argc, "ip", &idx)) {
13959 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
13960 vty_out(vty, "if you are using this please migrate to the below command.\n");
13961 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13962 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
13963 }
13964
d62a17ae 13965 argv_find(argv, argc, "(1-99)", &idx);
13966 argv_find(argv, argc, "WORD", &idx);
13967 cl_name_or_number = argv[idx]->arg;
13968 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13969 : COMMUNITY_DENY;
13970 argv_find(argv, argc, "AA:NN", &idx);
13971 char *str = argv_concat(argv, argc, idx);
42f914d4 13972
d62a17ae 13973 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13974 style);
42f914d4 13975
d62a17ae 13976 XFREE(MTYPE_TMP, str);
42f914d4 13977
d62a17ae 13978 if (ret < 0) {
13979 /* Display error string. */
13980 community_list_perror(vty, ret);
13981 return CMD_WARNING_CONFIG_FAILED;
13982 }
42f914d4 13983
d62a17ae 13984 return CMD_SUCCESS;
718e3744 13985}
13986
7336e101
SP
13987#if CONFDATE > 20191005
13988CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
13989#endif
13990ALIAS (community_list_standard,
13991 ip_community_list_standard_cmd,
13992 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13993 IP_STR
13994 COMMUNITY_LIST_STR
13995 "Community list number (standard)\n"
5bf15956
DW
13996 "Add an standard community-list entry\n"
13997 "Community list name\n"
718e3744 13998 "Specify community to reject\n"
13999 "Specify community to accept\n"
14000 COMMUNITY_VAL_STR)
7336e101
SP
14001
14002DEFUN (no_community_list_standard_all,
14003 no_bgp_community_list_standard_all_cmd,
14004 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14005 NO_STR
14006 BGP_STR
14007 COMMUNITY_LIST_STR
14008 "Community list number (standard)\n"
14009 "Add an standard community-list entry\n"
14010 "Community list name\n"
14011 "Specify community to reject\n"
14012 "Specify community to accept\n"
14013 COMMUNITY_VAL_STR)
718e3744 14014{
d62a17ae 14015 char *cl_name_or_number = NULL;
174b5cb9 14016 char *str = NULL;
d62a17ae 14017 int direct = 0;
14018 int style = COMMUNITY_LIST_STANDARD;
42f914d4 14019
d62a17ae 14020 int idx = 0;
7336e101
SP
14021
14022 if (argv_find(argv, argc, "ip", &idx)) {
14023 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14024 vty_out(vty, "if you are using this please migrate to the below command.\n");
14025 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14026 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14027 }
14028
174b5cb9
DA
14029 argv_find(argv, argc, "permit", &idx);
14030 argv_find(argv, argc, "deny", &idx);
14031
14032 if (idx) {
14033 direct = argv_find(argv, argc, "permit", &idx)
14034 ? COMMUNITY_PERMIT
14035 : COMMUNITY_DENY;
14036
14037 idx = 0;
14038 argv_find(argv, argc, "AA:NN", &idx);
14039 str = argv_concat(argv, argc, idx);
14040 }
14041
14042 idx = 0;
d62a17ae 14043 argv_find(argv, argc, "(1-99)", &idx);
14044 argv_find(argv, argc, "WORD", &idx);
14045 cl_name_or_number = argv[idx]->arg;
42f914d4 14046
d62a17ae 14047 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14048 direct, style);
42f914d4 14049
d62a17ae 14050 XFREE(MTYPE_TMP, str);
daf9ddbb 14051
d62a17ae 14052 if (ret < 0) {
14053 community_list_perror(vty, ret);
14054 return CMD_WARNING_CONFIG_FAILED;
14055 }
42f914d4 14056
d62a17ae 14057 return CMD_SUCCESS;
718e3744 14058}
7336e101
SP
14059ALIAS (no_community_list_standard_all,
14060 no_ip_community_list_standard_all_cmd,
14061 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14062 NO_STR
718e3744 14063 IP_STR
14064 COMMUNITY_LIST_STR
7336e101
SP
14065 "Community list number (standard)\n"
14066 "Add an standard community-list entry\n"
14067 "Community list name\n"
14068 "Specify community to reject\n"
14069 "Specify community to accept\n"
14070 COMMUNITY_VAL_STR)
14071
174b5cb9
DA
14072ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14073 "no bgp community-list <(1-99)|standard WORD>",
14074 NO_STR BGP_STR COMMUNITY_LIST_STR
14075 "Community list number (standard)\n"
14076 "Add an standard community-list entry\n"
14077 "Community list name\n")
14078
14079ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14080 "no ip community-list <(1-99)|standard WORD>",
14081 NO_STR BGP_STR COMMUNITY_LIST_STR
14082 "Community list number (standard)\n"
14083 "Add an standard community-list entry\n"
14084 "Community list name\n")
14085
7336e101
SP
14086/*community-list expanded */
14087DEFUN (community_list_expanded_all,
14088 bgp_community_list_expanded_all_cmd,
14089 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14090 BGP_STR
14091 COMMUNITY_LIST_STR
718e3744 14092 "Community list number (expanded)\n"
5bf15956 14093 "Add an expanded community-list entry\n"
718e3744 14094 "Community list name\n"
14095 "Specify community to reject\n"
14096 "Specify community to accept\n"
14097 COMMUNITY_VAL_STR)
14098{
d62a17ae 14099 char *cl_name_or_number = NULL;
14100 int direct = 0;
14101 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14102
d62a17ae 14103 int idx = 0;
7336e101
SP
14104 if (argv_find(argv, argc, "ip", &idx)) {
14105 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14106 vty_out(vty, "if you are using this please migrate to the below command.\n");
14107 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14108 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14109 }
d62a17ae 14110 argv_find(argv, argc, "(100-500)", &idx);
14111 argv_find(argv, argc, "WORD", &idx);
14112 cl_name_or_number = argv[idx]->arg;
14113 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14114 : COMMUNITY_DENY;
14115 argv_find(argv, argc, "AA:NN", &idx);
14116 char *str = argv_concat(argv, argc, idx);
42f914d4 14117
d62a17ae 14118 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14119 style);
42f914d4 14120
d62a17ae 14121 XFREE(MTYPE_TMP, str);
42f914d4 14122
d62a17ae 14123 if (ret < 0) {
14124 /* Display error string. */
14125 community_list_perror(vty, ret);
14126 return CMD_WARNING_CONFIG_FAILED;
14127 }
42f914d4 14128
d62a17ae 14129 return CMD_SUCCESS;
718e3744 14130}
14131
7336e101
SP
14132ALIAS (community_list_expanded_all,
14133 ip_community_list_expanded_all_cmd,
14134 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 14135 IP_STR
14136 COMMUNITY_LIST_STR
5bf15956
DW
14137 "Community list number (expanded)\n"
14138 "Add an expanded community-list entry\n"
718e3744 14139 "Community list name\n"
14140 "Specify community to reject\n"
14141 "Specify community to accept\n"
5bf15956 14142 COMMUNITY_VAL_STR)
7336e101
SP
14143
14144DEFUN (no_community_list_expanded_all,
14145 no_bgp_community_list_expanded_all_cmd,
14146 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14147 NO_STR
14148 BGP_STR
14149 COMMUNITY_LIST_STR
14150 "Community list number (expanded)\n"
14151 "Add an expanded community-list entry\n"
14152 "Community list name\n"
14153 "Specify community to reject\n"
14154 "Specify community to accept\n"
14155 COMMUNITY_VAL_STR)
718e3744 14156{
d62a17ae 14157 char *cl_name_or_number = NULL;
174b5cb9 14158 char *str = NULL;
d62a17ae 14159 int direct = 0;
14160 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14161
d62a17ae 14162 int idx = 0;
7336e101
SP
14163 if (argv_find(argv, argc, "ip", &idx)) {
14164 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14165 vty_out(vty, "if you are using this please migrate to the below command.\n");
174b5cb9
DA
14166 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14167 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14168 }
14169
3c4b8fe2 14170 idx = 0;
174b5cb9
DA
14171 argv_find(argv, argc, "permit", &idx);
14172 argv_find(argv, argc, "deny", &idx);
14173
14174 if (idx) {
14175 direct = argv_find(argv, argc, "permit", &idx)
14176 ? COMMUNITY_PERMIT
14177 : COMMUNITY_DENY;
14178
14179 idx = 0;
14180 argv_find(argv, argc, "AA:NN", &idx);
14181 str = argv_concat(argv, argc, idx);
7336e101 14182 }
174b5cb9
DA
14183
14184 idx = 0;
d62a17ae 14185 argv_find(argv, argc, "(100-500)", &idx);
14186 argv_find(argv, argc, "WORD", &idx);
14187 cl_name_or_number = argv[idx]->arg;
42f914d4 14188
d62a17ae 14189 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14190 direct, style);
42f914d4 14191
d62a17ae 14192 XFREE(MTYPE_TMP, str);
daf9ddbb 14193
d62a17ae 14194 if (ret < 0) {
14195 community_list_perror(vty, ret);
14196 return CMD_WARNING_CONFIG_FAILED;
14197 }
42f914d4 14198
d62a17ae 14199 return CMD_SUCCESS;
718e3744 14200}
14201
7336e101
SP
14202ALIAS (no_community_list_expanded_all,
14203 no_ip_community_list_expanded_all_cmd,
14204 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14205 NO_STR
14206 IP_STR
14207 COMMUNITY_LIST_STR
14208 "Community list number (expanded)\n"
14209 "Add an expanded community-list entry\n"
14210 "Community list name\n"
14211 "Specify community to reject\n"
14212 "Specify community to accept\n"
14213 COMMUNITY_VAL_STR)
14214
174b5cb9
DA
14215ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14216 "no bgp community-list <(100-500)|expanded WORD>",
14217 NO_STR IP_STR COMMUNITY_LIST_STR
14218 "Community list number (expanded)\n"
14219 "Add an expanded community-list entry\n"
14220 "Community list name\n")
14221
14222ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14223 "no ip community-list <(100-500)|expanded WORD>",
14224 NO_STR IP_STR COMMUNITY_LIST_STR
14225 "Community list number (expanded)\n"
14226 "Add an expanded community-list entry\n"
14227 "Community list name\n")
14228
8d9b8ed9
PM
14229/* Return configuration string of community-list entry. */
14230static const char *community_list_config_str(struct community_entry *entry)
14231{
14232 const char *str;
14233
14234 if (entry->any)
14235 str = "";
14236 else {
14237 if (entry->style == COMMUNITY_LIST_STANDARD)
14238 str = community_str(entry->u.com, false);
14239 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14240 str = lcommunity_str(entry->u.lcom, false);
14241 else
14242 str = entry->config;
14243 }
14244 return str;
14245}
14246
d62a17ae 14247static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 14248{
d62a17ae 14249 struct community_entry *entry;
718e3744 14250
d62a17ae 14251 for (entry = list->head; entry; entry = entry->next) {
14252 if (entry == list->head) {
14253 if (all_digit(list->name))
14254 vty_out(vty, "Community %s list %s\n",
14255 entry->style == COMMUNITY_LIST_STANDARD
14256 ? "standard"
14257 : "(expanded) access",
14258 list->name);
14259 else
14260 vty_out(vty, "Named Community %s list %s\n",
14261 entry->style == COMMUNITY_LIST_STANDARD
14262 ? "standard"
14263 : "expanded",
14264 list->name);
14265 }
14266 if (entry->any)
14267 vty_out(vty, " %s\n",
14268 community_direct_str(entry->direct));
14269 else
14270 vty_out(vty, " %s %s\n",
14271 community_direct_str(entry->direct),
8d9b8ed9 14272 community_list_config_str(entry));
d62a17ae 14273 }
718e3744 14274}
14275
7336e101
SP
14276DEFUN (show_community_list,
14277 show_bgp_community_list_cmd,
14278 "show bgp community-list",
718e3744 14279 SHOW_STR
7336e101 14280 BGP_STR
718e3744 14281 "List community-list\n")
14282{
d62a17ae 14283 struct community_list *list;
14284 struct community_list_master *cm;
718e3744 14285
7336e101
SP
14286 int idx = 0;
14287 if (argv_find(argv, argc, "ip", &idx)) {
14288 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14289 vty_out(vty, "if you are using this please migrate to the below command.\n");
14290 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14291 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14292 }
d62a17ae 14293 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14294 if (!cm)
14295 return CMD_SUCCESS;
718e3744 14296
d62a17ae 14297 for (list = cm->num.head; list; list = list->next)
14298 community_list_show(vty, list);
718e3744 14299
d62a17ae 14300 for (list = cm->str.head; list; list = list->next)
14301 community_list_show(vty, list);
718e3744 14302
d62a17ae 14303 return CMD_SUCCESS;
718e3744 14304}
14305
7336e101
SP
14306ALIAS (show_community_list,
14307 show_ip_community_list_cmd,
14308 "show ip community-list",
718e3744 14309 SHOW_STR
14310 IP_STR
7336e101
SP
14311 "List community-list\n")
14312
14313DEFUN (show_community_list_arg,
14314 show_bgp_community_list_arg_cmd,
14315 "show bgp community-list <(1-500)|WORD>",
14316 SHOW_STR
14317 BGP_STR
718e3744 14318 "List community-list\n"
14319 "Community-list number\n"
14320 "Community-list name\n")
14321{
d62a17ae 14322 int idx_comm_list = 3;
14323 struct community_list *list;
718e3744 14324
7336e101
SP
14325 int idx = 0;
14326 if (argv_find(argv, argc, "ip", &idx)) {
14327 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14328 vty_out(vty, "if you are using this please migrate to the below command.\n");
14329 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14330 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14331 }
e237b0d2 14332 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 14333 COMMUNITY_LIST_MASTER);
14334 if (!list) {
14335 vty_out(vty, "%% Can't find community-list\n");
14336 return CMD_WARNING;
14337 }
718e3744 14338
d62a17ae 14339 community_list_show(vty, list);
718e3744 14340
d62a17ae 14341 return CMD_SUCCESS;
718e3744 14342}
6b0655a2 14343
7336e101
SP
14344ALIAS (show_community_list_arg,
14345 show_ip_community_list_arg_cmd,
14346 "show ip community-list <(1-500)|WORD>",
14347 SHOW_STR
14348 IP_STR
14349 "List community-list\n"
14350 "Community-list number\n"
14351 "Community-list name\n")
14352
57d187bc
JS
14353/*
14354 * Large Community code.
14355 */
d62a17ae 14356static int lcommunity_list_set_vty(struct vty *vty, int argc,
14357 struct cmd_token **argv, int style,
14358 int reject_all_digit_name)
14359{
14360 int ret;
14361 int direct;
14362 char *str;
14363 int idx = 0;
14364 char *cl_name;
14365
7336e101
SP
14366 if (argv_find(argv, argc, "ip", &idx)) {
14367 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14368 vty_out(vty, "if you are using this please migrate to the below command.\n");
14369 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14370 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14371 }
d62a17ae 14372 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14373 : COMMUNITY_DENY;
14374
14375 /* All digit name check. */
14376 idx = 0;
14377 argv_find(argv, argc, "WORD", &idx);
14378 argv_find(argv, argc, "(1-99)", &idx);
14379 argv_find(argv, argc, "(100-500)", &idx);
14380 cl_name = argv[idx]->arg;
14381 if (reject_all_digit_name && all_digit(cl_name)) {
14382 vty_out(vty, "%% Community name cannot have all digits\n");
14383 return CMD_WARNING_CONFIG_FAILED;
14384 }
14385
14386 idx = 0;
14387 argv_find(argv, argc, "AA:BB:CC", &idx);
14388 argv_find(argv, argc, "LINE", &idx);
14389 /* Concat community string argument. */
14390 if (idx)
14391 str = argv_concat(argv, argc, idx);
14392 else
14393 str = NULL;
14394
14395 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14396
14397 /* Free temporary community list string allocated by
14398 argv_concat(). */
14399 if (str)
14400 XFREE(MTYPE_TMP, str);
14401
14402 if (ret < 0) {
14403 community_list_perror(vty, ret);
14404 return CMD_WARNING_CONFIG_FAILED;
14405 }
14406 return CMD_SUCCESS;
14407}
14408
14409static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14410 struct cmd_token **argv, int style)
14411{
14412 int ret;
14413 int direct = 0;
14414 char *str = NULL;
14415 int idx = 0;
14416
7336e101
SP
14417 if (argv_find(argv, argc, "ip", &idx)) {
14418 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14419 vty_out(vty, "if you are using this please migrate to the below command.\n");
14420 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14421 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14422 }
d62a17ae 14423 argv_find(argv, argc, "permit", &idx);
14424 argv_find(argv, argc, "deny", &idx);
14425
14426 if (idx) {
14427 /* Check the list direct. */
14428 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14429 direct = COMMUNITY_PERMIT;
14430 else
14431 direct = COMMUNITY_DENY;
14432
14433 idx = 0;
14434 argv_find(argv, argc, "LINE", &idx);
14435 argv_find(argv, argc, "AA:AA:NN", &idx);
14436 /* Concat community string argument. */
14437 str = argv_concat(argv, argc, idx);
14438 }
14439
14440 idx = 0;
14441 argv_find(argv, argc, "(1-99)", &idx);
14442 argv_find(argv, argc, "(100-500)", &idx);
14443 argv_find(argv, argc, "WORD", &idx);
14444
14445 /* Unset community list. */
14446 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14447 style);
14448
14449 /* Free temporary community list string allocated by
14450 argv_concat(). */
14451 if (str)
14452 XFREE(MTYPE_TMP, str);
14453
14454 if (ret < 0) {
14455 community_list_perror(vty, ret);
14456 return CMD_WARNING_CONFIG_FAILED;
14457 }
14458
14459 return CMD_SUCCESS;
57d187bc
JS
14460}
14461
14462/* "large-community-list" keyword help string. */
14463#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14464#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14465
7336e101
SP
14466#if CONFDATE > 20191005
14467CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14468#endif
14469DEFUN (lcommunity_list_standard,
14470 bgp_lcommunity_list_standard_cmd,
14471 "bgp large-community-list (1-99) <deny|permit>",
14472 BGP_STR
14473 LCOMMUNITY_LIST_STR
14474 "Large Community list number (standard)\n"
14475 "Specify large community to reject\n"
14476 "Specify large community to accept\n")
14477{
14478 return lcommunity_list_set_vty(vty, argc, argv,
14479 LARGE_COMMUNITY_LIST_STANDARD, 0);
14480}
14481
14482ALIAS (lcommunity_list_standard,
57d187bc 14483 ip_lcommunity_list_standard_cmd,
52951b63
DS
14484 "ip large-community-list (1-99) <deny|permit>",
14485 IP_STR
14486 LCOMMUNITY_LIST_STR
14487 "Large Community list number (standard)\n"
14488 "Specify large community to reject\n"
7111c1a0 14489 "Specify large community to accept\n")
7336e101
SP
14490
14491DEFUN (lcommunity_list_standard1,
14492 bgp_lcommunity_list_standard1_cmd,
14493 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14494 BGP_STR
14495 LCOMMUNITY_LIST_STR
14496 "Large Community list number (standard)\n"
14497 "Specify large community to reject\n"
14498 "Specify large community to accept\n"
14499 LCOMMUNITY_VAL_STR)
52951b63 14500{
d62a17ae 14501 return lcommunity_list_set_vty(vty, argc, argv,
14502 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
14503}
14504
7336e101 14505ALIAS (lcommunity_list_standard1,
52951b63
DS
14506 ip_lcommunity_list_standard1_cmd,
14507 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
14508 IP_STR
14509 LCOMMUNITY_LIST_STR
14510 "Large Community list number (standard)\n"
14511 "Specify large community to reject\n"
14512 "Specify large community to accept\n"
14513 LCOMMUNITY_VAL_STR)
7336e101
SP
14514
14515DEFUN (lcommunity_list_expanded,
14516 bgp_lcommunity_list_expanded_cmd,
14517 "bgp large-community-list (100-500) <deny|permit> LINE...",
14518 BGP_STR
14519 LCOMMUNITY_LIST_STR
14520 "Large Community list number (expanded)\n"
14521 "Specify large community to reject\n"
14522 "Specify large community to accept\n"
14523 "An ordered list as a regular-expression\n")
57d187bc 14524{
d62a17ae 14525 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14526 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
14527}
14528
7336e101 14529ALIAS (lcommunity_list_expanded,
57d187bc
JS
14530 ip_lcommunity_list_expanded_cmd,
14531 "ip large-community-list (100-500) <deny|permit> LINE...",
14532 IP_STR
14533 LCOMMUNITY_LIST_STR
14534 "Large Community list number (expanded)\n"
14535 "Specify large community to reject\n"
14536 "Specify large community to accept\n"
14537 "An ordered list as a regular-expression\n")
7336e101
SP
14538
14539DEFUN (lcommunity_list_name_standard,
14540 bgp_lcommunity_list_name_standard_cmd,
14541 "bgp large-community-list standard WORD <deny|permit>",
14542 BGP_STR
14543 LCOMMUNITY_LIST_STR
14544 "Specify standard large-community-list\n"
14545 "Large Community list name\n"
14546 "Specify large community to reject\n"
14547 "Specify large community to accept\n")
57d187bc 14548{
d62a17ae 14549 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14550 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
14551}
14552
7336e101 14553ALIAS (lcommunity_list_name_standard,
57d187bc 14554 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
14555 "ip large-community-list standard WORD <deny|permit>",
14556 IP_STR
14557 LCOMMUNITY_LIST_STR
14558 "Specify standard large-community-list\n"
14559 "Large Community list name\n"
14560 "Specify large community to reject\n"
14561 "Specify large community to accept\n")
7336e101
SP
14562
14563DEFUN (lcommunity_list_name_standard1,
14564 bgp_lcommunity_list_name_standard1_cmd,
14565 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14566 BGP_STR
14567 LCOMMUNITY_LIST_STR
14568 "Specify standard large-community-list\n"
14569 "Large Community list name\n"
14570 "Specify large community to reject\n"
14571 "Specify large community to accept\n"
14572 LCOMMUNITY_VAL_STR)
52951b63 14573{
d62a17ae 14574 return lcommunity_list_set_vty(vty, argc, argv,
14575 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
14576}
14577
7336e101 14578ALIAS (lcommunity_list_name_standard1,
52951b63
DS
14579 ip_lcommunity_list_name_standard1_cmd,
14580 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
14581 IP_STR
14582 LCOMMUNITY_LIST_STR
14583 "Specify standard large-community-list\n"
14584 "Large Community list name\n"
14585 "Specify large community to reject\n"
14586 "Specify large community to accept\n"
14587 LCOMMUNITY_VAL_STR)
7336e101
SP
14588
14589DEFUN (lcommunity_list_name_expanded,
14590 bgp_lcommunity_list_name_expanded_cmd,
14591 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14592 BGP_STR
14593 LCOMMUNITY_LIST_STR
14594 "Specify expanded large-community-list\n"
14595 "Large Community list name\n"
14596 "Specify large community to reject\n"
14597 "Specify large community to accept\n"
14598 "An ordered list as a regular-expression\n")
57d187bc 14599{
d62a17ae 14600 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14601 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
14602}
14603
7336e101 14604ALIAS (lcommunity_list_name_expanded,
57d187bc
JS
14605 ip_lcommunity_list_name_expanded_cmd,
14606 "ip large-community-list expanded WORD <deny|permit> LINE...",
14607 IP_STR
14608 LCOMMUNITY_LIST_STR
14609 "Specify expanded large-community-list\n"
14610 "Large Community list name\n"
14611 "Specify large community to reject\n"
14612 "Specify large community to accept\n"
14613 "An ordered list as a regular-expression\n")
7336e101
SP
14614
14615DEFUN (no_lcommunity_list_standard_all,
14616 no_bgp_lcommunity_list_standard_all_cmd,
14617 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14618 NO_STR
14619 BGP_STR
14620 LCOMMUNITY_LIST_STR
14621 "Large Community list number (standard)\n"
14622 "Large Community list number (expanded)\n"
14623 "Large Community list name\n")
57d187bc 14624{
7336e101
SP
14625 return lcommunity_list_unset_vty(vty, argc, argv,
14626 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14627}
14628
7336e101 14629ALIAS (no_lcommunity_list_standard_all,
57d187bc
JS
14630 no_ip_lcommunity_list_standard_all_cmd,
14631 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14632 NO_STR
14633 IP_STR
14634 LCOMMUNITY_LIST_STR
14635 "Large Community list number (standard)\n"
14636 "Large Community list number (expanded)\n"
14637 "Large Community list name\n")
7336e101
SP
14638
14639DEFUN (no_lcommunity_list_name_expanded_all,
14640 no_bgp_lcommunity_list_name_expanded_all_cmd,
14641 "no bgp large-community-list expanded WORD",
14642 NO_STR
14643 BGP_STR
14644 LCOMMUNITY_LIST_STR
14645 "Specify expanded large-community-list\n"
14646 "Large Community list name\n")
57d187bc 14647{
d62a17ae 14648 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14649 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14650}
14651
7336e101 14652ALIAS (no_lcommunity_list_name_expanded_all,
57d187bc
JS
14653 no_ip_lcommunity_list_name_expanded_all_cmd,
14654 "no ip large-community-list expanded WORD",
14655 NO_STR
14656 IP_STR
14657 LCOMMUNITY_LIST_STR
14658 "Specify expanded large-community-list\n"
14659 "Large Community list name\n")
7336e101
SP
14660
14661DEFUN (no_lcommunity_list_standard,
14662 no_bgp_lcommunity_list_standard_cmd,
14663 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14664 NO_STR
14665 BGP_STR
14666 LCOMMUNITY_LIST_STR
14667 "Large Community list number (standard)\n"
14668 "Specify large community to reject\n"
14669 "Specify large community to accept\n"
14670 LCOMMUNITY_VAL_STR)
57d187bc 14671{
d62a17ae 14672 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14673 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14674}
14675
7336e101 14676ALIAS (no_lcommunity_list_standard,
57d187bc
JS
14677 no_ip_lcommunity_list_standard_cmd,
14678 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14679 NO_STR
14680 IP_STR
14681 LCOMMUNITY_LIST_STR
14682 "Large Community list number (standard)\n"
14683 "Specify large community to reject\n"
14684 "Specify large community to accept\n"
14685 LCOMMUNITY_VAL_STR)
7336e101
SP
14686
14687DEFUN (no_lcommunity_list_expanded,
14688 no_bgp_lcommunity_list_expanded_cmd,
14689 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14690 NO_STR
14691 BGP_STR
14692 LCOMMUNITY_LIST_STR
14693 "Large Community list number (expanded)\n"
14694 "Specify large community to reject\n"
14695 "Specify large community to accept\n"
14696 "An ordered list as a regular-expression\n")
57d187bc 14697{
d62a17ae 14698 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14699 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14700}
14701
7336e101 14702ALIAS (no_lcommunity_list_expanded,
57d187bc
JS
14703 no_ip_lcommunity_list_expanded_cmd,
14704 "no ip large-community-list (100-500) <deny|permit> LINE...",
14705 NO_STR
14706 IP_STR
14707 LCOMMUNITY_LIST_STR
14708 "Large Community list number (expanded)\n"
14709 "Specify large community to reject\n"
14710 "Specify large community to accept\n"
14711 "An ordered list as a regular-expression\n")
7336e101
SP
14712
14713DEFUN (no_lcommunity_list_name_standard,
14714 no_bgp_lcommunity_list_name_standard_cmd,
14715 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14716 NO_STR
14717 BGP_STR
14718 LCOMMUNITY_LIST_STR
14719 "Specify standard large-community-list\n"
14720 "Large Community list name\n"
14721 "Specify large community to reject\n"
14722 "Specify large community to accept\n"
14723 LCOMMUNITY_VAL_STR)
57d187bc 14724{
d62a17ae 14725 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14726 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14727}
14728
7336e101 14729ALIAS (no_lcommunity_list_name_standard,
57d187bc
JS
14730 no_ip_lcommunity_list_name_standard_cmd,
14731 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14732 NO_STR
14733 IP_STR
14734 LCOMMUNITY_LIST_STR
14735 "Specify standard large-community-list\n"
14736 "Large Community list name\n"
14737 "Specify large community to reject\n"
14738 "Specify large community to accept\n"
14739 LCOMMUNITY_VAL_STR)
7336e101
SP
14740
14741DEFUN (no_lcommunity_list_name_expanded,
14742 no_bgp_lcommunity_list_name_expanded_cmd,
14743 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14744 NO_STR
14745 BGP_STR
14746 LCOMMUNITY_LIST_STR
14747 "Specify expanded large-community-list\n"
14748 "Large community list name\n"
14749 "Specify large community to reject\n"
14750 "Specify large community to accept\n"
14751 "An ordered list as a regular-expression\n")
57d187bc 14752{
d62a17ae 14753 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14754 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14755}
14756
7336e101 14757ALIAS (no_lcommunity_list_name_expanded,
57d187bc
JS
14758 no_ip_lcommunity_list_name_expanded_cmd,
14759 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14760 NO_STR
14761 IP_STR
14762 LCOMMUNITY_LIST_STR
14763 "Specify expanded large-community-list\n"
14764 "Large community list name\n"
14765 "Specify large community to reject\n"
14766 "Specify large community to accept\n"
14767 "An ordered list as a regular-expression\n")
d62a17ae 14768
14769static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14770{
14771 struct community_entry *entry;
14772
14773 for (entry = list->head; entry; entry = entry->next) {
14774 if (entry == list->head) {
14775 if (all_digit(list->name))
14776 vty_out(vty, "Large community %s list %s\n",
14777 entry->style == EXTCOMMUNITY_LIST_STANDARD
14778 ? "standard"
14779 : "(expanded) access",
14780 list->name);
14781 else
14782 vty_out(vty,
14783 "Named large community %s list %s\n",
14784 entry->style == EXTCOMMUNITY_LIST_STANDARD
14785 ? "standard"
14786 : "expanded",
14787 list->name);
14788 }
14789 if (entry->any)
14790 vty_out(vty, " %s\n",
14791 community_direct_str(entry->direct));
14792 else
14793 vty_out(vty, " %s %s\n",
14794 community_direct_str(entry->direct),
8d9b8ed9 14795 community_list_config_str(entry));
d62a17ae 14796 }
57d187bc
JS
14797}
14798
7336e101
SP
14799DEFUN (show_lcommunity_list,
14800 show_bgp_lcommunity_list_cmd,
14801 "show bgp large-community-list",
57d187bc 14802 SHOW_STR
7336e101 14803 BGP_STR
57d187bc
JS
14804 "List large-community list\n")
14805{
d62a17ae 14806 struct community_list *list;
14807 struct community_list_master *cm;
7336e101
SP
14808 int idx = 0;
14809
14810 if (argv_find(argv, argc, "ip", &idx)) {
14811 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14812 vty_out(vty, "if you are using this please migrate to the below command.\n");
14813 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14814 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14815 }
57d187bc 14816
d62a17ae 14817 cm = community_list_master_lookup(bgp_clist,
14818 LARGE_COMMUNITY_LIST_MASTER);
14819 if (!cm)
14820 return CMD_SUCCESS;
57d187bc 14821
d62a17ae 14822 for (list = cm->num.head; list; list = list->next)
14823 lcommunity_list_show(vty, list);
57d187bc 14824
d62a17ae 14825 for (list = cm->str.head; list; list = list->next)
14826 lcommunity_list_show(vty, list);
57d187bc 14827
d62a17ae 14828 return CMD_SUCCESS;
57d187bc
JS
14829}
14830
7336e101
SP
14831ALIAS (show_lcommunity_list,
14832 show_ip_lcommunity_list_cmd,
14833 "show ip large-community-list",
57d187bc
JS
14834 SHOW_STR
14835 IP_STR
7336e101
SP
14836 "List large-community list\n")
14837
14838DEFUN (show_lcommunity_list_arg,
14839 show_bgp_lcommunity_list_arg_cmd,
14840 "show bgp large-community-list <(1-500)|WORD>",
14841 SHOW_STR
14842 BGP_STR
57d187bc
JS
14843 "List large-community list\n"
14844 "large-community-list number\n"
14845 "large-community-list name\n")
14846{
d62a17ae 14847 struct community_list *list;
7336e101
SP
14848 int idx = 0;
14849
14850 if (argv_find(argv, argc, "ip", &idx)) {
14851 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14852 vty_out(vty, "if you are using this please migrate to the below command.\n");
14853 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14854 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14855 }
57d187bc 14856
e237b0d2 14857 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 14858 LARGE_COMMUNITY_LIST_MASTER);
14859 if (!list) {
14860 vty_out(vty, "%% Can't find extcommunity-list\n");
14861 return CMD_WARNING;
14862 }
57d187bc 14863
d62a17ae 14864 lcommunity_list_show(vty, list);
57d187bc 14865
d62a17ae 14866 return CMD_SUCCESS;
57d187bc
JS
14867}
14868
7336e101
SP
14869ALIAS (show_lcommunity_list_arg,
14870 show_ip_lcommunity_list_arg_cmd,
14871 "show ip large-community-list <(1-500)|WORD>",
14872 SHOW_STR
14873 IP_STR
14874 "List large-community list\n"
14875 "large-community-list number\n"
14876 "large-community-list name\n")
14877
718e3744 14878/* "extcommunity-list" keyword help string. */
14879#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14880#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14881
7336e101
SP
14882DEFUN (extcommunity_list_standard,
14883 bgp_extcommunity_list_standard_cmd,
14884 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14885 BGP_STR
718e3744 14886 EXTCOMMUNITY_LIST_STR
14887 "Extended Community list number (standard)\n"
718e3744 14888 "Specify standard extcommunity-list\n"
5bf15956 14889 "Community list name\n"
718e3744 14890 "Specify community to reject\n"
14891 "Specify community to accept\n"
14892 EXTCOMMUNITY_VAL_STR)
14893{
d62a17ae 14894 int style = EXTCOMMUNITY_LIST_STANDARD;
14895 int direct = 0;
14896 char *cl_number_or_name = NULL;
42f914d4 14897
d62a17ae 14898 int idx = 0;
7336e101
SP
14899 if (argv_find(argv, argc, "ip", &idx)) {
14900 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14901 vty_out(vty, "if you are using this please migrate to the below command.\n");
14902 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14903 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14904 }
d62a17ae 14905 argv_find(argv, argc, "(1-99)", &idx);
14906 argv_find(argv, argc, "WORD", &idx);
14907 cl_number_or_name = argv[idx]->arg;
14908 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14909 : COMMUNITY_DENY;
14910 argv_find(argv, argc, "AA:NN", &idx);
14911 char *str = argv_concat(argv, argc, idx);
42f914d4 14912
d62a17ae 14913 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14914 direct, style);
42f914d4 14915
d62a17ae 14916 XFREE(MTYPE_TMP, str);
42f914d4 14917
d62a17ae 14918 if (ret < 0) {
14919 community_list_perror(vty, ret);
14920 return CMD_WARNING_CONFIG_FAILED;
14921 }
42f914d4 14922
d62a17ae 14923 return CMD_SUCCESS;
718e3744 14924}
14925
7336e101
SP
14926#if CONFDATE > 20191005
14927CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
14928#endif
14929ALIAS (extcommunity_list_standard,
14930 ip_extcommunity_list_standard_cmd,
14931 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14932 IP_STR
14933 EXTCOMMUNITY_LIST_STR
7336e101
SP
14934 "Extended Community list number (standard)\n"
14935 "Specify standard extcommunity-list\n"
14936 "Community list name\n"
14937 "Specify community to reject\n"
14938 "Specify community to accept\n"
14939 EXTCOMMUNITY_VAL_STR)
14940
14941DEFUN (extcommunity_list_name_expanded,
14942 bgp_extcommunity_list_name_expanded_cmd,
14943 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14944 BGP_STR
14945 EXTCOMMUNITY_LIST_STR
5bf15956 14946 "Extended Community list number (expanded)\n"
718e3744 14947 "Specify expanded extcommunity-list\n"
14948 "Extended Community list name\n"
14949 "Specify community to reject\n"
14950 "Specify community to accept\n"
14951 "An ordered list as a regular-expression\n")
14952{
d62a17ae 14953 int style = EXTCOMMUNITY_LIST_EXPANDED;
14954 int direct = 0;
14955 char *cl_number_or_name = NULL;
42f914d4 14956
d62a17ae 14957 int idx = 0;
7336e101
SP
14958 if (argv_find(argv, argc, "ip", &idx)) {
14959 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14960 vty_out(vty, "if you are using this please migrate to the below command.\n");
14961 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14962 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14963 }
14964
d62a17ae 14965 argv_find(argv, argc, "(100-500)", &idx);
14966 argv_find(argv, argc, "WORD", &idx);
14967 cl_number_or_name = argv[idx]->arg;
14968 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14969 : COMMUNITY_DENY;
14970 argv_find(argv, argc, "LINE", &idx);
14971 char *str = argv_concat(argv, argc, idx);
42f914d4 14972
d62a17ae 14973 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14974 direct, style);
42f914d4 14975
d62a17ae 14976 XFREE(MTYPE_TMP, str);
42f914d4 14977
d62a17ae 14978 if (ret < 0) {
14979 community_list_perror(vty, ret);
14980 return CMD_WARNING_CONFIG_FAILED;
14981 }
42f914d4 14982
d62a17ae 14983 return CMD_SUCCESS;
718e3744 14984}
14985
7336e101
SP
14986ALIAS (extcommunity_list_name_expanded,
14987 ip_extcommunity_list_name_expanded_cmd,
14988 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
813d4307
DW
14989 IP_STR
14990 EXTCOMMUNITY_LIST_STR
7336e101
SP
14991 "Extended Community list number (expanded)\n"
14992 "Specify expanded extcommunity-list\n"
14993 "Extended Community list name\n"
14994 "Specify community to reject\n"
14995 "Specify community to accept\n"
14996 "An ordered list as a regular-expression\n")
14997
14998DEFUN (no_extcommunity_list_standard_all,
14999 no_bgp_extcommunity_list_standard_all_cmd,
15000 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15001 NO_STR
15002 BGP_STR
15003 EXTCOMMUNITY_LIST_STR
813d4307 15004 "Extended Community list number (standard)\n"
718e3744 15005 "Specify standard extcommunity-list\n"
5bf15956 15006 "Community list name\n"
718e3744 15007 "Specify community to reject\n"
15008 "Specify community to accept\n"
15009 EXTCOMMUNITY_VAL_STR)
15010{
d62a17ae 15011 int style = EXTCOMMUNITY_LIST_STANDARD;
15012 int direct = 0;
15013 char *cl_number_or_name = NULL;
d4455c89 15014 char *str = NULL;
42f914d4 15015
d62a17ae 15016 int idx = 0;
7336e101
SP
15017 if (argv_find(argv, argc, "ip", &idx)) {
15018 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15019 vty_out(vty, "if you are using this please migrate to the below command.\n");
15020 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15021 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15022 }
d4455c89
DA
15023
15024 idx = 0;
15025 argv_find(argv, argc, "permit", &idx);
15026 argv_find(argv, argc, "deny", &idx);
15027
15028 if (idx) {
15029 direct = argv_find(argv, argc, "permit", &idx)
15030 ? COMMUNITY_PERMIT
15031 : COMMUNITY_DENY;
15032
15033 idx = 0;
15034 argv_find(argv, argc, "AA:NN", &idx);
15035 str = argv_concat(argv, argc, idx);
15036 }
15037
15038 idx = 0;
d62a17ae 15039 argv_find(argv, argc, "(1-99)", &idx);
15040 argv_find(argv, argc, "WORD", &idx);
15041 cl_number_or_name = argv[idx]->arg;
42f914d4 15042
d62a17ae 15043 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15044 direct, style);
42f914d4 15045
d62a17ae 15046 XFREE(MTYPE_TMP, str);
42f914d4 15047
d62a17ae 15048 if (ret < 0) {
15049 community_list_perror(vty, ret);
15050 return CMD_WARNING_CONFIG_FAILED;
15051 }
42f914d4 15052
d62a17ae 15053 return CMD_SUCCESS;
718e3744 15054}
15055
7336e101
SP
15056ALIAS (no_extcommunity_list_standard_all,
15057 no_ip_extcommunity_list_standard_all_cmd,
15058 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 15059 NO_STR
15060 IP_STR
15061 EXTCOMMUNITY_LIST_STR
7336e101
SP
15062 "Extended Community list number (standard)\n"
15063 "Specify standard extcommunity-list\n"
15064 "Community list name\n"
15065 "Specify community to reject\n"
15066 "Specify community to accept\n"
15067 EXTCOMMUNITY_VAL_STR)
15068
d4455c89
DA
15069ALIAS(no_extcommunity_list_standard_all,
15070 no_bgp_extcommunity_list_standard_all_list_cmd,
15071 "no bgp extcommunity-list <(1-99)|standard WORD>",
15072 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15073 "Extended Community list number (standard)\n"
15074 "Specify standard extcommunity-list\n"
15075 "Community list name\n")
15076
15077ALIAS(no_extcommunity_list_standard_all,
15078 no_ip_extcommunity_list_standard_all_list_cmd,
15079 "no ip extcommunity-list <(1-99)|standard WORD>",
15080 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15081 "Extended Community list number (standard)\n"
15082 "Specify standard extcommunity-list\n"
15083 "Community list name\n")
15084
7336e101
SP
15085DEFUN (no_extcommunity_list_expanded_all,
15086 no_bgp_extcommunity_list_expanded_all_cmd,
15087 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15088 NO_STR
15089 BGP_STR
15090 EXTCOMMUNITY_LIST_STR
718e3744 15091 "Extended Community list number (expanded)\n"
718e3744 15092 "Specify expanded extcommunity-list\n"
5bf15956 15093 "Extended Community list name\n"
718e3744 15094 "Specify community to reject\n"
15095 "Specify community to accept\n"
15096 "An ordered list as a regular-expression\n")
15097{
d62a17ae 15098 int style = EXTCOMMUNITY_LIST_EXPANDED;
15099 int direct = 0;
15100 char *cl_number_or_name = NULL;
d4455c89 15101 char *str = NULL;
42f914d4 15102
d62a17ae 15103 int idx = 0;
7336e101
SP
15104 if (argv_find(argv, argc, "ip", &idx)) {
15105 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15106 vty_out(vty, "if you are using this please migrate to the below command.\n");
15107 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15108 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15109 }
d4455c89
DA
15110
15111 idx = 0;
15112 argv_find(argv, argc, "permit", &idx);
15113 argv_find(argv, argc, "deny", &idx);
15114
15115 if (idx) {
15116 direct = argv_find(argv, argc, "permit", &idx)
15117 ? COMMUNITY_PERMIT
15118 : COMMUNITY_DENY;
15119
15120 idx = 0;
15121 argv_find(argv, argc, "LINE", &idx);
15122 str = argv_concat(argv, argc, idx);
15123 }
15124
15125 idx = 0;
d62a17ae 15126 argv_find(argv, argc, "(100-500)", &idx);
15127 argv_find(argv, argc, "WORD", &idx);
15128 cl_number_or_name = argv[idx]->arg;
42f914d4 15129
d62a17ae 15130 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15131 direct, style);
42f914d4 15132
d62a17ae 15133 XFREE(MTYPE_TMP, str);
42f914d4 15134
d62a17ae 15135 if (ret < 0) {
15136 community_list_perror(vty, ret);
15137 return CMD_WARNING_CONFIG_FAILED;
15138 }
42f914d4 15139
d62a17ae 15140 return CMD_SUCCESS;
718e3744 15141}
15142
7336e101
SP
15143ALIAS (no_extcommunity_list_expanded_all,
15144 no_ip_extcommunity_list_expanded_all_cmd,
15145 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15146 NO_STR
15147 IP_STR
15148 EXTCOMMUNITY_LIST_STR
15149 "Extended Community list number (expanded)\n"
15150 "Specify expanded extcommunity-list\n"
15151 "Extended Community list name\n"
15152 "Specify community to reject\n"
15153 "Specify community to accept\n"
15154 "An ordered list as a regular-expression\n")
15155
d4455c89
DA
15156ALIAS(no_extcommunity_list_expanded_all,
15157 no_ip_extcommunity_list_expanded_all_list_cmd,
15158 "no ip extcommunity-list <(100-500)|expanded WORD>",
15159 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15160 "Extended Community list number (expanded)\n"
15161 "Specify expanded extcommunity-list\n"
15162 "Extended Community list name\n")
15163
15164ALIAS(no_extcommunity_list_expanded_all,
15165 no_bgp_extcommunity_list_expanded_all_list_cmd,
15166 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15167 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15168 "Extended Community list number (expanded)\n"
15169 "Specify expanded extcommunity-list\n"
15170 "Extended Community list name\n")
15171
d62a17ae 15172static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 15173{
d62a17ae 15174 struct community_entry *entry;
718e3744 15175
d62a17ae 15176 for (entry = list->head; entry; entry = entry->next) {
15177 if (entry == list->head) {
15178 if (all_digit(list->name))
15179 vty_out(vty, "Extended community %s list %s\n",
15180 entry->style == EXTCOMMUNITY_LIST_STANDARD
15181 ? "standard"
15182 : "(expanded) access",
15183 list->name);
15184 else
15185 vty_out(vty,
15186 "Named extended community %s list %s\n",
15187 entry->style == EXTCOMMUNITY_LIST_STANDARD
15188 ? "standard"
15189 : "expanded",
15190 list->name);
15191 }
15192 if (entry->any)
15193 vty_out(vty, " %s\n",
15194 community_direct_str(entry->direct));
15195 else
15196 vty_out(vty, " %s %s\n",
15197 community_direct_str(entry->direct),
8d9b8ed9 15198 community_list_config_str(entry));
d62a17ae 15199 }
718e3744 15200}
15201
7336e101
SP
15202DEFUN (show_extcommunity_list,
15203 show_bgp_extcommunity_list_cmd,
15204 "show bgp extcommunity-list",
718e3744 15205 SHOW_STR
7336e101 15206 BGP_STR
718e3744 15207 "List extended-community list\n")
15208{
d62a17ae 15209 struct community_list *list;
15210 struct community_list_master *cm;
7336e101 15211 int idx = 0;
718e3744 15212
7336e101
SP
15213 if (argv_find(argv, argc, "ip", &idx)) {
15214 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15215 vty_out(vty, "if you are using this please migrate to the below command.\n");
15216 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15217 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15218 }
d62a17ae 15219 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15220 if (!cm)
15221 return CMD_SUCCESS;
718e3744 15222
d62a17ae 15223 for (list = cm->num.head; list; list = list->next)
15224 extcommunity_list_show(vty, list);
718e3744 15225
d62a17ae 15226 for (list = cm->str.head; list; list = list->next)
15227 extcommunity_list_show(vty, list);
718e3744 15228
d62a17ae 15229 return CMD_SUCCESS;
718e3744 15230}
15231
7336e101
SP
15232ALIAS (show_extcommunity_list,
15233 show_ip_extcommunity_list_cmd,
15234 "show ip extcommunity-list",
718e3744 15235 SHOW_STR
15236 IP_STR
7336e101
SP
15237 "List extended-community list\n")
15238
15239DEFUN (show_extcommunity_list_arg,
15240 show_bgp_extcommunity_list_arg_cmd,
15241 "show bgp extcommunity-list <(1-500)|WORD>",
15242 SHOW_STR
15243 BGP_STR
718e3744 15244 "List extended-community list\n"
15245 "Extcommunity-list number\n"
15246 "Extcommunity-list name\n")
15247{
d62a17ae 15248 int idx_comm_list = 3;
15249 struct community_list *list;
7336e101 15250 int idx = 0;
718e3744 15251
7336e101
SP
15252 if (argv_find(argv, argc, "ip", &idx)) {
15253 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15254 vty_out(vty, "if you are using this please migrate to the below command.\n");
15255 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15256 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15257 }
e237b0d2 15258 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 15259 EXTCOMMUNITY_LIST_MASTER);
15260 if (!list) {
15261 vty_out(vty, "%% Can't find extcommunity-list\n");
15262 return CMD_WARNING;
15263 }
718e3744 15264
d62a17ae 15265 extcommunity_list_show(vty, list);
718e3744 15266
d62a17ae 15267 return CMD_SUCCESS;
718e3744 15268}
6b0655a2 15269
7336e101
SP
15270ALIAS (show_extcommunity_list_arg,
15271 show_ip_extcommunity_list_arg_cmd,
15272 "show ip extcommunity-list <(1-500)|WORD>",
15273 SHOW_STR
15274 IP_STR
15275 "List extended-community list\n"
15276 "Extcommunity-list number\n"
15277 "Extcommunity-list name\n")
15278
718e3744 15279/* Display community-list and extcommunity-list configuration. */
d62a17ae 15280static int community_list_config_write(struct vty *vty)
15281{
15282 struct community_list *list;
15283 struct community_entry *entry;
15284 struct community_list_master *cm;
15285 int write = 0;
15286
15287 /* Community-list. */
15288 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15289
15290 for (list = cm->num.head; list; list = list->next)
15291 for (entry = list->head; entry; entry = entry->next) {
7336e101 15292 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
d62a17ae 15293 community_direct_str(entry->direct),
15294 community_list_config_str(entry));
15295 write++;
15296 }
15297 for (list = cm->str.head; list; list = list->next)
15298 for (entry = list->head; entry; entry = entry->next) {
7336e101 15299 vty_out(vty, "bgp community-list %s %s %s %s\n",
d62a17ae 15300 entry->style == COMMUNITY_LIST_STANDARD
15301 ? "standard"
15302 : "expanded",
15303 list->name, community_direct_str(entry->direct),
15304 community_list_config_str(entry));
15305 write++;
15306 }
15307
15308 /* Extcommunity-list. */
15309 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15310
15311 for (list = cm->num.head; list; list = list->next)
15312 for (entry = list->head; entry; entry = entry->next) {
7336e101 15313 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
d62a17ae 15314 list->name, community_direct_str(entry->direct),
15315 community_list_config_str(entry));
15316 write++;
15317 }
15318 for (list = cm->str.head; list; list = list->next)
15319 for (entry = list->head; entry; entry = entry->next) {
7336e101 15320 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
d62a17ae 15321 entry->style == EXTCOMMUNITY_LIST_STANDARD
15322 ? "standard"
15323 : "expanded",
15324 list->name, community_direct_str(entry->direct),
15325 community_list_config_str(entry));
15326 write++;
15327 }
15328
15329
15330 /* lcommunity-list. */
15331 cm = community_list_master_lookup(bgp_clist,
15332 LARGE_COMMUNITY_LIST_MASTER);
15333
15334 for (list = cm->num.head; list; list = list->next)
15335 for (entry = list->head; entry; entry = entry->next) {
7336e101 15336 vty_out(vty, "bgp large-community-list %s %s %s\n",
d62a17ae 15337 list->name, community_direct_str(entry->direct),
15338 community_list_config_str(entry));
15339 write++;
15340 }
15341 for (list = cm->str.head; list; list = list->next)
15342 for (entry = list->head; entry; entry = entry->next) {
7336e101 15343 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
d62a17ae 15344 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15345 ? "standard"
15346 : "expanded",
15347 list->name, community_direct_str(entry->direct),
15348 community_list_config_str(entry));
15349 write++;
15350 }
15351
15352 return write;
15353}
15354
15355static struct cmd_node community_list_node = {
15356 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 15357};
15358
d62a17ae 15359static void community_list_vty(void)
15360{
15361 install_node(&community_list_node, community_list_config_write);
15362
15363 /* Community-list. */
7336e101
SP
15364 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15365 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15366 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 15367 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 15368 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 15369 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
15370 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15371 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 15372 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15373 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15374 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
174b5cb9 15375 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
d62a17ae 15376 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
174b5cb9 15377 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
d62a17ae 15378 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15379 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15380
15381 /* Extcommunity-list. */
7336e101
SP
15382 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15383 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15384 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
15385 install_element(CONFIG_NODE,
15386 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 15387 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
15388 install_element(CONFIG_NODE,
15389 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
15390 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15391 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 15392 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15393 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15394 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
d4455c89 15395 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
d62a17ae 15396 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
d4455c89 15397 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
d62a17ae 15398 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15399 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15400
15401 /* Large Community List */
7336e101
SP
15402 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15403 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15404 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15405 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15406 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15407 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15408 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15409 install_element(CONFIG_NODE,
15410 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15411 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15412 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15413 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15414 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15415 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15416 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
d62a17ae 15417 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15418 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15419 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15420 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15421 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15422 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15423 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15424 install_element(CONFIG_NODE,
15425 &no_ip_lcommunity_list_name_expanded_all_cmd);
15426 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15427 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15428 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15429 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15430 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15431 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 15432}