]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #2679 from qlyoung/fix-zapi-fuzzing
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
718e3744 25#include "prefix.h"
26#include "plist.h"
27#include "buffer.h"
28#include "linklist.h"
29#include "stream.h"
30#include "thread.h"
31#include "log.h"
3b8b1855 32#include "memory.h"
fc7948fa 33#include "memory_vty.h"
4bf6a362 34#include "hash.h"
3f9c7369 35#include "queue.h"
039f3a34 36#include "filter.h"
5d5ba018 37#include "frrstr.h"
718e3744 38
39#include "bgpd/bgpd.h"
4bf6a362 40#include "bgpd/bgp_advertise.h"
718e3744 41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_aspath.h"
43#include "bgpd/bgp_community.h"
4bf6a362 44#include "bgpd/bgp_ecommunity.h"
57d187bc 45#include "bgpd/bgp_lcommunity.h"
4bf6a362 46#include "bgpd/bgp_damp.h"
718e3744 47#include "bgpd/bgp_debug.h"
e0701b79 48#include "bgpd/bgp_fsm.h"
4bf6a362 49#include "bgpd/bgp_nexthop.h"
718e3744 50#include "bgpd/bgp_open.h"
4bf6a362 51#include "bgpd/bgp_regex.h"
718e3744 52#include "bgpd/bgp_route.h"
c016b6c7 53#include "bgpd/bgp_mplsvpn.h"
718e3744 54#include "bgpd/bgp_zebra.h"
fee0f4c6 55#include "bgpd/bgp_table.h"
94f2b392 56#include "bgpd/bgp_vty.h"
165b5fff 57#include "bgpd/bgp_mpath.h"
cb1faec9 58#include "bgpd/bgp_packet.h"
3f9c7369 59#include "bgpd/bgp_updgrp.h"
c43ed2e4 60#include "bgpd/bgp_bfd.h"
555e09d4 61#include "bgpd/bgp_io.h"
94c2f693 62#include "bgpd/bgp_evpn.h"
718e3744 63
d62a17ae 64static struct peer_group *listen_range_exists(struct bgp *bgp,
65 struct prefix *range, int exact);
66
67static enum node_type bgp_node_type(afi_t afi, safi_t safi)
68{
69 switch (afi) {
70 case AFI_IP:
71 switch (safi) {
72 case SAFI_UNICAST:
73 return BGP_IPV4_NODE;
74 break;
75 case SAFI_MULTICAST:
76 return BGP_IPV4M_NODE;
77 break;
78 case SAFI_LABELED_UNICAST:
79 return BGP_IPV4L_NODE;
80 break;
81 case SAFI_MPLS_VPN:
82 return BGP_VPNV4_NODE;
83 break;
7c40bf39 84 case SAFI_FLOWSPEC:
85 return BGP_FLOWSPECV4_NODE;
5c525538
RW
86 default:
87 /* not expected */
88 return BGP_IPV4_NODE;
89 break;
d62a17ae 90 }
91 break;
92 case AFI_IP6:
93 switch (safi) {
94 case SAFI_UNICAST:
95 return BGP_IPV6_NODE;
96 break;
97 case SAFI_MULTICAST:
98 return BGP_IPV6M_NODE;
99 break;
100 case SAFI_LABELED_UNICAST:
101 return BGP_IPV6L_NODE;
102 break;
103 case SAFI_MPLS_VPN:
104 return BGP_VPNV6_NODE;
105 break;
7c40bf39 106 case SAFI_FLOWSPEC:
107 return BGP_FLOWSPECV6_NODE;
5c525538
RW
108 default:
109 /* not expected */
110 return BGP_IPV4_NODE;
111 break;
d62a17ae 112 }
113 break;
114 case AFI_L2VPN:
115 return BGP_EVPN_NODE;
116 break;
117 case AFI_MAX:
118 // We should never be here but to clarify the switch statement..
119 return BGP_IPV4_NODE;
120 break;
121 }
122
123 // Impossible to happen
124 return BGP_IPV4_NODE;
f51bae9c 125}
20eb8864 126
718e3744 127/* Utility function to get address family from current node. */
d62a17ae 128afi_t bgp_node_afi(struct vty *vty)
129{
130 afi_t afi;
131 switch (vty->node) {
132 case BGP_IPV6_NODE:
133 case BGP_IPV6M_NODE:
134 case BGP_IPV6L_NODE:
135 case BGP_VPNV6_NODE:
7c40bf39 136 case BGP_FLOWSPECV6_NODE:
d62a17ae 137 afi = AFI_IP6;
138 break;
139 case BGP_EVPN_NODE:
140 afi = AFI_L2VPN;
141 break;
142 default:
143 afi = AFI_IP;
144 break;
145 }
146 return afi;
718e3744 147}
148
149/* Utility function to get subsequent address family from current
150 node. */
d62a17ae 151safi_t bgp_node_safi(struct vty *vty)
152{
153 safi_t safi;
154 switch (vty->node) {
155 case BGP_VPNV4_NODE:
156 case BGP_VPNV6_NODE:
157 safi = SAFI_MPLS_VPN;
158 break;
159 case BGP_IPV4M_NODE:
160 case BGP_IPV6M_NODE:
161 safi = SAFI_MULTICAST;
162 break;
163 case BGP_EVPN_NODE:
164 safi = SAFI_EVPN;
165 break;
166 case BGP_IPV4L_NODE:
167 case BGP_IPV6L_NODE:
168 safi = SAFI_LABELED_UNICAST;
169 break;
7c40bf39 170 case BGP_FLOWSPECV4_NODE:
171 case BGP_FLOWSPECV6_NODE:
172 safi = SAFI_FLOWSPEC;
173 break;
d62a17ae 174 default:
175 safi = SAFI_UNICAST;
176 break;
177 }
178 return safi;
718e3744 179}
180
55f91488
QY
181/**
182 * Converts an AFI in string form to afi_t
183 *
184 * @param afi string, one of
185 * - "ipv4"
186 * - "ipv6"
187 * @return the corresponding afi_t
188 */
d62a17ae 189afi_t bgp_vty_afi_from_str(const char *afi_str)
190{
191 afi_t afi = AFI_MAX; /* unknown */
192 if (strmatch(afi_str, "ipv4"))
193 afi = AFI_IP;
194 else if (strmatch(afi_str, "ipv6"))
195 afi = AFI_IP6;
196 return afi;
197}
198
199int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
200 afi_t *afi)
201{
202 int ret = 0;
203 if (argv_find(argv, argc, "ipv4", index)) {
204 ret = 1;
205 if (afi)
206 *afi = AFI_IP;
207 } else if (argv_find(argv, argc, "ipv6", index)) {
208 ret = 1;
209 if (afi)
210 *afi = AFI_IP6;
211 }
212 return ret;
46f296b4
LB
213}
214
375a2e67 215/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 216safi_t bgp_vty_safi_from_str(const char *safi_str)
217{
218 safi_t safi = SAFI_MAX; /* unknown */
219 if (strmatch(safi_str, "multicast"))
220 safi = SAFI_MULTICAST;
221 else if (strmatch(safi_str, "unicast"))
222 safi = SAFI_UNICAST;
223 else if (strmatch(safi_str, "vpn"))
224 safi = SAFI_MPLS_VPN;
225 else if (strmatch(safi_str, "labeled-unicast"))
226 safi = SAFI_LABELED_UNICAST;
7c40bf39 227 else if (strmatch(safi_str, "flowspec"))
228 safi = SAFI_FLOWSPEC;
d62a17ae 229 return safi;
230}
231
232int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
233 safi_t *safi)
234{
235 int ret = 0;
236 if (argv_find(argv, argc, "unicast", index)) {
237 ret = 1;
238 if (safi)
239 *safi = SAFI_UNICAST;
240 } else if (argv_find(argv, argc, "multicast", index)) {
241 ret = 1;
242 if (safi)
243 *safi = SAFI_MULTICAST;
244 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
245 ret = 1;
246 if (safi)
247 *safi = SAFI_LABELED_UNICAST;
248 } else if (argv_find(argv, argc, "vpn", index)) {
249 ret = 1;
250 if (safi)
251 *safi = SAFI_MPLS_VPN;
7c40bf39 252 } else if (argv_find(argv, argc, "flowspec", index)) {
253 ret = 1;
254 if (safi)
255 *safi = SAFI_FLOWSPEC;
d62a17ae 256 }
257 return ret;
46f296b4
LB
258}
259
7eeee51e 260/*
f212a857 261 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 262 *
f212a857
DS
263 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
264 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
265 * to appropriate values for the calling function. This is to allow the
266 * calling function to make decisions appropriate for the show command
267 * that is being parsed.
268 *
269 * The show commands are generally of the form:
d62a17ae 270 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
271 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
272 *
273 * Since we use argv_find if the show command in particular doesn't have:
274 * [ip]
18c57037 275 * [<view|vrf> VIEWVRFNAME]
375a2e67 276 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
277 * The command parsing should still be ok.
278 *
279 * vty -> The vty for the command so we can output some useful data in
280 * the event of a parse error in the vrf.
281 * argv -> The command tokens
282 * argc -> How many command tokens we have
d62a17ae 283 * idx -> The current place in the command, generally should be 0 for this
284 * function
7eeee51e
DS
285 * afi -> The parsed afi if it was included in the show command, returned here
286 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 287 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
288 *
289 * The function returns the correct location in the parse tree for the
290 * last token found.
0e37c258
DS
291 *
292 * Returns 0 for failure to parse correctly, else the idx position of where
293 * it found the last token.
7eeee51e 294 */
d62a17ae 295int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
296 struct cmd_token **argv, int argc,
297 int *idx, afi_t *afi, safi_t *safi,
298 struct bgp **bgp)
299{
300 char *vrf_name = NULL;
301
302 assert(afi);
303 assert(safi);
304 assert(bgp);
305
306 if (argv_find(argv, argc, "ip", idx))
307 *afi = AFI_IP;
308
309 if (argv_find(argv, argc, "view", idx)
310 || argv_find(argv, argc, "vrf", idx)) {
311 vrf_name = argv[*idx + 1]->arg;
312
313 if (strmatch(vrf_name, "all"))
314 *bgp = NULL;
315 else {
316 *bgp = bgp_lookup_by_name(vrf_name);
317 if (!*bgp) {
318 vty_out(vty,
319 "View/Vrf specified is unknown: %s\n",
320 vrf_name);
321 *idx = 0;
322 return 0;
323 }
324 }
325 } else {
326 *bgp = bgp_get_default();
327 if (!*bgp) {
328 vty_out(vty, "Unable to find default BGP instance\n");
329 *idx = 0;
330 return 0;
331 }
332 }
333
334 if (argv_find_and_parse_afi(argv, argc, idx, afi))
335 argv_find_and_parse_safi(argv, argc, idx, safi);
336
337 *idx += 1;
338 return *idx;
339}
340
341static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
342{
343 struct interface *ifp = NULL;
344
345 if (su->sa.sa_family == AF_INET)
346 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
347 else if (su->sa.sa_family == AF_INET6)
348 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
349 su->sin6.sin6_scope_id,
350 bgp->vrf_id);
351
352 if (ifp)
353 return 1;
354
355 return 0;
718e3744 356}
357
358/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
359/* This is used only for configuration, so disallow if attempted on
360 * a dynamic neighbor.
361 */
d62a17ae 362static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
363{
364 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
365 int ret;
366 union sockunion su;
367 struct peer *peer;
368
369 if (!bgp) {
370 return NULL;
371 }
372
373 ret = str2sockunion(ip_str, &su);
374 if (ret < 0) {
375 peer = peer_lookup_by_conf_if(bgp, ip_str);
376 if (!peer) {
377 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
378 == NULL) {
379 vty_out(vty,
380 "%% Malformed address or name: %s\n",
381 ip_str);
382 return NULL;
383 }
384 }
385 } else {
386 peer = peer_lookup(bgp, &su);
387 if (!peer) {
388 vty_out(vty,
389 "%% Specify remote-as or peer-group commands first\n");
390 return NULL;
391 }
392 if (peer_dynamic_neighbor(peer)) {
393 vty_out(vty,
394 "%% Operation not allowed on a dynamic neighbor\n");
395 return NULL;
396 }
397 }
398 return peer;
718e3744 399}
400
401/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
402/* This is used only for configuration, so disallow if attempted on
403 * a dynamic neighbor.
404 */
d62a17ae 405struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
406{
407 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
408 int ret;
409 union sockunion su;
410 struct peer *peer = NULL;
411 struct peer_group *group = NULL;
412
413 if (!bgp) {
414 return NULL;
415 }
416
417 ret = str2sockunion(peer_str, &su);
418 if (ret == 0) {
419 /* IP address, locate peer. */
420 peer = peer_lookup(bgp, &su);
421 } else {
422 /* Not IP, could match either peer configured on interface or a
423 * group. */
424 peer = peer_lookup_by_conf_if(bgp, peer_str);
425 if (!peer)
426 group = peer_group_lookup(bgp, peer_str);
427 }
428
429 if (peer) {
430 if (peer_dynamic_neighbor(peer)) {
431 vty_out(vty,
432 "%% Operation not allowed on a dynamic neighbor\n");
433 return NULL;
434 }
435
436 return peer;
437 }
438
439 if (group)
440 return group->conf;
441
442 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
443
444 return NULL;
445}
446
447int bgp_vty_return(struct vty *vty, int ret)
448{
449 const char *str = NULL;
450
451 switch (ret) {
452 case BGP_ERR_INVALID_VALUE:
453 str = "Invalid value";
454 break;
455 case BGP_ERR_INVALID_FLAG:
456 str = "Invalid flag";
457 break;
458 case BGP_ERR_PEER_GROUP_SHUTDOWN:
459 str = "Peer-group has been shutdown. Activate the peer-group first";
460 break;
461 case BGP_ERR_PEER_FLAG_CONFLICT:
462 str = "Can't set override-capability and strict-capability-match at the same time";
463 break;
464 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
465 str = "Specify remote-as or peer-group remote AS first";
466 break;
467 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
468 str = "Cannot change the peer-group. Deconfigure first";
469 break;
470 case BGP_ERR_PEER_GROUP_MISMATCH:
471 str = "Peer is not a member of this peer-group";
472 break;
473 case BGP_ERR_PEER_FILTER_CONFLICT:
474 str = "Prefix/distribute list can not co-exist";
475 break;
476 case BGP_ERR_NOT_INTERNAL_PEER:
477 str = "Invalid command. Not an internal neighbor";
478 break;
479 case BGP_ERR_REMOVE_PRIVATE_AS:
480 str = "remove-private-AS cannot be configured for IBGP peers";
481 break;
482 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
483 str = "Local-AS allowed only for EBGP peers";
484 break;
485 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
486 str = "Cannot have local-as same as BGP AS number";
487 break;
488 case BGP_ERR_TCPSIG_FAILED:
489 str = "Error while applying TCP-Sig to session(s)";
490 break;
491 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
492 str = "ebgp-multihop and ttl-security cannot be configured together";
493 break;
494 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
495 str = "ttl-security only allowed for EBGP peers";
496 break;
497 case BGP_ERR_AS_OVERRIDE:
498 str = "as-override cannot be configured for IBGP peers";
499 break;
500 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
501 str = "Invalid limit for number of dynamic neighbors";
502 break;
503 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
504 str = "Dynamic neighbor listen range already exists";
505 break;
506 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
507 str = "Operation not allowed on a dynamic neighbor";
508 break;
509 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
510 str = "Operation not allowed on a directly connected neighbor";
511 break;
512 case BGP_ERR_PEER_SAFI_CONFLICT:
513 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
514 break;
515 }
516 if (str) {
517 vty_out(vty, "%% %s\n", str);
518 return CMD_WARNING_CONFIG_FAILED;
519 }
520 return CMD_SUCCESS;
718e3744 521}
522
7aafcaca 523/* BGP clear sort. */
d62a17ae 524enum clear_sort {
525 clear_all,
526 clear_peer,
527 clear_group,
528 clear_external,
529 clear_as
7aafcaca
DS
530};
531
d62a17ae 532static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
533 safi_t safi, int error)
534{
535 switch (error) {
536 case BGP_ERR_AF_UNCONFIGURED:
537 vty_out(vty,
538 "%%BGP: Enable %s address family for the neighbor %s\n",
539 afi_safi_print(afi, safi), peer->host);
540 break;
541 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
542 vty_out(vty,
543 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
544 peer->host);
545 break;
546 default:
547 break;
548 }
7aafcaca
DS
549}
550
551/* `clear ip bgp' functions. */
d62a17ae 552static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
553 enum clear_sort sort, enum bgp_clear_type stype,
554 const char *arg)
555{
556 int ret;
3ae8bfa5 557 bool found = false;
d62a17ae 558 struct peer *peer;
559 struct listnode *node, *nnode;
560
561 /* Clear all neighbors. */
562 /*
563 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
564 * nodes on the BGP instance as that may get freed if it is a
565 * doppelganger
d62a17ae 566 */
567 if (sort == clear_all) {
568 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
3ae8bfa5
PM
569 if (!peer->afc[afi][safi])
570 continue;
571
d62a17ae 572 if (stype == BGP_CLEAR_SOFT_NONE)
573 ret = peer_clear(peer, &nnode);
d62a17ae 574 else
3ae8bfa5 575 ret = peer_clear_soft(peer, afi, safi, stype);
d62a17ae 576
577 if (ret < 0)
578 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
579 else
580 found = true;
04b6bdc0 581 }
d62a17ae 582
583 /* This is to apply read-only mode on this clear. */
584 if (stype == BGP_CLEAR_SOFT_NONE)
585 bgp->update_delay_over = 0;
586
3ae8bfa5
PM
587 if (!found)
588 vty_out(vty, "%%BGP: No %s peer configured",
589 afi_safi_print(afi, safi));
590
d62a17ae 591 return CMD_SUCCESS;
7aafcaca
DS
592 }
593
3ae8bfa5 594 /* Clear specified neighbor. */
d62a17ae 595 if (sort == clear_peer) {
596 union sockunion su;
d62a17ae 597
598 /* Make sockunion for lookup. */
599 ret = str2sockunion(arg, &su);
600 if (ret < 0) {
601 peer = peer_lookup_by_conf_if(bgp, arg);
602 if (!peer) {
603 peer = peer_lookup_by_hostname(bgp, arg);
604 if (!peer) {
605 vty_out(vty,
606 "Malformed address or name: %s\n",
607 arg);
608 return CMD_WARNING;
609 }
610 }
611 } else {
612 peer = peer_lookup(bgp, &su);
613 if (!peer) {
614 vty_out(vty,
615 "%%BGP: Unknown neighbor - \"%s\"\n",
616 arg);
617 return CMD_WARNING;
618 }
619 }
7aafcaca 620
3ae8bfa5
PM
621 if (!peer->afc[afi][safi])
622 ret = BGP_ERR_AF_UNCONFIGURED;
623 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 624 ret = peer_clear(peer, NULL);
625 else
626 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 627
d62a17ae 628 if (ret < 0)
629 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 630
d62a17ae 631 return CMD_SUCCESS;
7aafcaca 632 }
7aafcaca 633
3ae8bfa5 634 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 635 if (sort == clear_group) {
636 struct peer_group *group;
7aafcaca 637
d62a17ae 638 group = peer_group_lookup(bgp, arg);
639 if (!group) {
640 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
641 return CMD_WARNING;
642 }
643
644 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
d62a17ae 645 if (!peer->afc[afi][safi])
646 continue;
647
3ae8bfa5
PM
648 if (stype == BGP_CLEAR_SOFT_NONE)
649 ret = peer_clear(peer, NULL);
650 else
651 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 652
d62a17ae 653 if (ret < 0)
654 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
655 else
656 found = true;
d62a17ae 657 }
3ae8bfa5
PM
658
659 if (!found)
660 vty_out(vty,
661 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
662 afi_safi_print(afi, safi), arg);
663
d62a17ae 664 return CMD_SUCCESS;
7aafcaca 665 }
7aafcaca 666
3ae8bfa5 667 /* Clear all external (eBGP) neighbors. */
d62a17ae 668 if (sort == clear_external) {
669 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
670 if (peer->sort == BGP_PEER_IBGP)
671 continue;
7aafcaca 672
3ae8bfa5
PM
673 if (!peer->afc[afi][safi])
674 continue;
675
d62a17ae 676 if (stype == BGP_CLEAR_SOFT_NONE)
677 ret = peer_clear(peer, &nnode);
678 else
679 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 680
d62a17ae 681 if (ret < 0)
682 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
683 else
684 found = true;
d62a17ae 685 }
3ae8bfa5
PM
686
687 if (!found)
688 vty_out(vty,
689 "%%BGP: No external %s peer is configured\n",
690 afi_safi_print(afi, safi));
691
d62a17ae 692 return CMD_SUCCESS;
693 }
694
3ae8bfa5 695 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 696 if (sort == clear_as) {
3ae8bfa5 697 as_t as = strtoul(arg, NULL, 10);
d62a17ae 698
699 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
700 if (peer->as != as)
701 continue;
702
3ae8bfa5
PM
703 if (!peer->afc[afi][safi])
704 ret = BGP_ERR_AF_UNCONFIGURED;
705 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 706 ret = peer_clear(peer, &nnode);
707 else
708 ret = peer_clear_soft(peer, afi, safi, stype);
709
710 if (ret < 0)
711 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
712 else
713 found = true;
d62a17ae 714 }
3ae8bfa5
PM
715
716 if (!found)
d62a17ae 717 vty_out(vty,
3ae8bfa5
PM
718 "%%BGP: No %s peer is configured with AS %s\n",
719 afi_safi_print(afi, safi), arg);
720
d62a17ae 721 return CMD_SUCCESS;
722 }
723
724 return CMD_SUCCESS;
725}
726
727static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
728 safi_t safi, enum clear_sort sort,
729 enum bgp_clear_type stype, const char *arg)
730{
731 struct bgp *bgp;
732
733 /* BGP structure lookup. */
734 if (name) {
735 bgp = bgp_lookup_by_name(name);
736 if (bgp == NULL) {
737 vty_out(vty, "Can't find BGP instance %s\n", name);
738 return CMD_WARNING;
739 }
740 } else {
741 bgp = bgp_get_default();
742 if (bgp == NULL) {
743 vty_out(vty, "No BGP process is configured\n");
744 return CMD_WARNING;
745 }
746 }
747
748 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
749}
750
751/* clear soft inbound */
d62a17ae 752static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 753{
d62a17ae 754 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
755 BGP_CLEAR_SOFT_IN, NULL);
756 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
757 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
758}
759
760/* clear soft outbound */
d62a17ae 761static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 762{
d62a17ae 763 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
764 BGP_CLEAR_SOFT_OUT, NULL);
765 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
766 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
767}
768
769
f787d7a0 770#ifndef VTYSH_EXTRACT_PL
2e4c2296 771#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
772#endif
773
718e3744 774/* BGP global configuration. */
1cc40660
DS
775#if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
776CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
777CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
778#endif
779DEFUN_HIDDEN (bgp_multiple_instance_func,
780 bgp_multiple_instance_cmd,
781 "bgp multiple-instance",
782 BGP_STR
783 "Enable bgp multiple instance\n")
718e3744 784{
d62a17ae 785 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
786 return CMD_SUCCESS;
718e3744 787}
788
1cc40660 789DEFUN_HIDDEN (no_bgp_multiple_instance,
718e3744 790 no_bgp_multiple_instance_cmd,
791 "no bgp multiple-instance",
792 NO_STR
793 BGP_STR
794 "BGP multiple instance\n")
795{
d62a17ae 796 int ret;
718e3744 797
1cc40660
DS
798 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
799 vty_out(vty, "if you are using this please let the developers know\n");
800 zlog_warn("Deprecated option: `bgp multiple-instance` being used");
d62a17ae 801 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
802 if (ret < 0) {
803 vty_out(vty, "%% There are more than two BGP instances\n");
804 return CMD_WARNING_CONFIG_FAILED;
805 }
806 return CMD_SUCCESS;
718e3744 807}
808
798467a2
DS
809#if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
810CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
811CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
812#endif
813DEFUN_HIDDEN (bgp_config_type,
814 bgp_config_type_cmd,
815 "bgp config-type <cisco|zebra>",
816 BGP_STR
817 "Configuration type\n"
818 "cisco\n"
819 "zebra\n")
718e3744 820{
d62a17ae 821 int idx = 0;
798467a2
DS
822 if (argv_find(argv, argc, "cisco", &idx)) {
823 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
824 vty_out(vty, "if you are using this please let the developers know!\n");
825 zlog_warn("Deprecated option: `bgp config-type cisco` being used");
d62a17ae 826 bgp_option_set(BGP_OPT_CONFIG_CISCO);
798467a2 827 } else
d62a17ae 828 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 829
d62a17ae 830 return CMD_SUCCESS;
718e3744 831}
832
798467a2
DS
833DEFUN_HIDDEN (no_bgp_config_type,
834 no_bgp_config_type_cmd,
835 "no bgp config-type [<cisco|zebra>]",
836 NO_STR
837 BGP_STR
838 "Display configuration type\n"
839 "cisco\n"
840 "zebra\n")
718e3744 841{
d62a17ae 842 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
843 return CMD_SUCCESS;
718e3744 844}
845
813d4307 846
718e3744 847DEFUN (no_synchronization,
848 no_synchronization_cmd,
849 "no synchronization",
850 NO_STR
851 "Perform IGP synchronization\n")
852{
d62a17ae 853 return CMD_SUCCESS;
718e3744 854}
855
856DEFUN (no_auto_summary,
857 no_auto_summary_cmd,
858 "no auto-summary",
859 NO_STR
860 "Enable automatic network number summarization\n")
861{
d62a17ae 862 return CMD_SUCCESS;
718e3744 863}
3d515fd9 864
718e3744 865/* "router bgp" commands. */
505e5056 866DEFUN_NOSH (router_bgp,
f412b39a 867 router_bgp_cmd,
18c57037 868 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 869 ROUTER_STR
870 BGP_STR
31500417
DW
871 AS_STR
872 BGP_INSTANCE_HELP_STR)
718e3744 873{
d62a17ae 874 int idx_asn = 2;
875 int idx_view_vrf = 3;
876 int idx_vrf = 4;
877 int ret;
878 as_t as;
879 struct bgp *bgp;
880 const char *name = NULL;
881 enum bgp_instance_type inst_type;
882
883 // "router bgp" without an ASN
884 if (argc == 2) {
885 // Pending: Make VRF option available for ASN less config
886 bgp = bgp_get_default();
887
888 if (bgp == NULL) {
889 vty_out(vty, "%% No BGP process is configured\n");
890 return CMD_WARNING_CONFIG_FAILED;
891 }
892
893 if (listcount(bm->bgp) > 1) {
996c9314 894 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 895 return CMD_WARNING_CONFIG_FAILED;
896 }
897 }
898
899 // "router bgp X"
900 else {
901 as = strtoul(argv[idx_asn]->arg, NULL, 10);
902
903 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
904 if (argc > 3) {
905 name = argv[idx_vrf]->arg;
906
907 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
908 inst_type = BGP_INSTANCE_TYPE_VRF;
909 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
910 inst_type = BGP_INSTANCE_TYPE_VIEW;
911 }
912
913 ret = bgp_get(&bgp, &as, name, inst_type);
914 switch (ret) {
915 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
916 vty_out(vty,
917 "Please specify 'bgp multiple-instance' first\n");
918 return CMD_WARNING_CONFIG_FAILED;
919 case BGP_ERR_AS_MISMATCH:
920 vty_out(vty, "BGP is already running; AS is %u\n", as);
921 return CMD_WARNING_CONFIG_FAILED;
922 case BGP_ERR_INSTANCE_MISMATCH:
923 vty_out(vty,
924 "BGP instance name and AS number mismatch\n");
925 vty_out(vty,
926 "BGP instance is already running; AS is %u\n",
927 as);
928 return CMD_WARNING_CONFIG_FAILED;
929 }
930
3bd70bf8
PZ
931 /*
932 * If we just instantiated the default instance, complete
933 * any pending VRF-VPN leaking that was configured via
934 * earlier "router bgp X vrf FOO" blocks.
935 */
936 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
937 vpn_leak_postchange_all();
938
d62a17ae 939 /* Pending: handle when user tries to change a view to vrf n vv.
940 */
941 }
942
0b5131c9
MK
943 /* unset the auto created flag as the user config is now present */
944 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 945 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
946
947 return CMD_SUCCESS;
718e3744 948}
949
718e3744 950/* "no router bgp" commands. */
951DEFUN (no_router_bgp,
952 no_router_bgp_cmd,
18c57037 953 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 954 NO_STR
955 ROUTER_STR
956 BGP_STR
31500417
DW
957 AS_STR
958 BGP_INSTANCE_HELP_STR)
718e3744 959{
d62a17ae 960 int idx_asn = 3;
961 int idx_vrf = 5;
962 as_t as;
963 struct bgp *bgp;
964 const char *name = NULL;
718e3744 965
d62a17ae 966 // "no router bgp" without an ASN
967 if (argc == 3) {
968 // Pending: Make VRF option available for ASN less config
969 bgp = bgp_get_default();
718e3744 970
d62a17ae 971 if (bgp == NULL) {
972 vty_out(vty, "%% No BGP process is configured\n");
973 return CMD_WARNING_CONFIG_FAILED;
974 }
7fb21a9f 975
d62a17ae 976 if (listcount(bm->bgp) > 1) {
996c9314 977 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 978 return CMD_WARNING_CONFIG_FAILED;
979 }
0b5131c9
MK
980
981 if (bgp->l3vni) {
982 vty_out(vty, "%% Please unconfigure l3vni %u",
983 bgp->l3vni);
984 return CMD_WARNING_CONFIG_FAILED;
985 }
d62a17ae 986 } else {
987 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 988
d62a17ae 989 if (argc > 4)
990 name = argv[idx_vrf]->arg;
7fb21a9f 991
d62a17ae 992 /* Lookup bgp structure. */
993 bgp = bgp_lookup(as, name);
994 if (!bgp) {
995 vty_out(vty, "%% Can't find BGP instance\n");
996 return CMD_WARNING_CONFIG_FAILED;
997 }
0b5131c9
MK
998
999 if (bgp->l3vni) {
1000 vty_out(vty, "%% Please unconfigure l3vni %u",
1001 bgp->l3vni);
1002 return CMD_WARNING_CONFIG_FAILED;
1003 }
d62a17ae 1004 }
718e3744 1005
d62a17ae 1006 bgp_delete(bgp);
718e3744 1007
d62a17ae 1008 return CMD_SUCCESS;
718e3744 1009}
1010
6b0655a2 1011
718e3744 1012/* BGP router-id. */
1013
f787d7a0 1014DEFPY (bgp_router_id,
718e3744 1015 bgp_router_id_cmd,
1016 "bgp router-id A.B.C.D",
1017 BGP_STR
1018 "Override configured router identifier\n"
1019 "Manually configured router identifier\n")
1020{
d62a17ae 1021 VTY_DECLVAR_CONTEXT(bgp, bgp);
1022 bgp_router_id_static_set(bgp, router_id);
1023 return CMD_SUCCESS;
718e3744 1024}
1025
f787d7a0 1026DEFPY (no_bgp_router_id,
718e3744 1027 no_bgp_router_id_cmd,
31500417 1028 "no bgp router-id [A.B.C.D]",
718e3744 1029 NO_STR
1030 BGP_STR
31500417
DW
1031 "Override configured router identifier\n"
1032 "Manually configured router identifier\n")
718e3744 1033{
d62a17ae 1034 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1035
d62a17ae 1036 if (router_id_str) {
1037 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1038 vty_out(vty, "%% BGP router-id doesn't match\n");
1039 return CMD_WARNING_CONFIG_FAILED;
1040 }
e018c7cc 1041 }
718e3744 1042
d62a17ae 1043 router_id.s_addr = 0;
1044 bgp_router_id_static_set(bgp, router_id);
718e3744 1045
d62a17ae 1046 return CMD_SUCCESS;
718e3744 1047}
1048
6b0655a2 1049
718e3744 1050/* BGP Cluster ID. */
718e3744 1051DEFUN (bgp_cluster_id,
1052 bgp_cluster_id_cmd,
838758ac 1053 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1054 BGP_STR
1055 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1056 "Route-Reflector Cluster-id in IP address format\n"
1057 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1058{
d62a17ae 1059 VTY_DECLVAR_CONTEXT(bgp, bgp);
1060 int idx_ipv4 = 2;
1061 int ret;
1062 struct in_addr cluster;
718e3744 1063
d62a17ae 1064 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1065 if (!ret) {
1066 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1067 return CMD_WARNING_CONFIG_FAILED;
1068 }
718e3744 1069
d62a17ae 1070 bgp_cluster_id_set(bgp, &cluster);
1071 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1072
d62a17ae 1073 return CMD_SUCCESS;
718e3744 1074}
1075
718e3744 1076DEFUN (no_bgp_cluster_id,
1077 no_bgp_cluster_id_cmd,
c7178fe7 1078 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1079 NO_STR
1080 BGP_STR
838758ac
DW
1081 "Configure Route-Reflector Cluster-id\n"
1082 "Route-Reflector Cluster-id in IP address format\n"
1083 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1084{
d62a17ae 1085 VTY_DECLVAR_CONTEXT(bgp, bgp);
1086 bgp_cluster_id_unset(bgp);
1087 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1088
d62a17ae 1089 return CMD_SUCCESS;
718e3744 1090}
1091
718e3744 1092DEFUN (bgp_confederation_identifier,
1093 bgp_confederation_identifier_cmd,
9ccf14f7 1094 "bgp confederation identifier (1-4294967295)",
718e3744 1095 "BGP specific commands\n"
1096 "AS confederation parameters\n"
1097 "AS number\n"
1098 "Set routing domain confederation AS\n")
1099{
d62a17ae 1100 VTY_DECLVAR_CONTEXT(bgp, bgp);
1101 int idx_number = 3;
1102 as_t as;
718e3744 1103
d62a17ae 1104 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1105
d62a17ae 1106 bgp_confederation_id_set(bgp, as);
718e3744 1107
d62a17ae 1108 return CMD_SUCCESS;
718e3744 1109}
1110
1111DEFUN (no_bgp_confederation_identifier,
1112 no_bgp_confederation_identifier_cmd,
838758ac 1113 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1114 NO_STR
1115 "BGP specific commands\n"
1116 "AS confederation parameters\n"
3a2d747c
QY
1117 "AS number\n"
1118 "Set routing domain confederation AS\n")
718e3744 1119{
d62a17ae 1120 VTY_DECLVAR_CONTEXT(bgp, bgp);
1121 bgp_confederation_id_unset(bgp);
718e3744 1122
d62a17ae 1123 return CMD_SUCCESS;
718e3744 1124}
1125
718e3744 1126DEFUN (bgp_confederation_peers,
1127 bgp_confederation_peers_cmd,
12dcf78e 1128 "bgp confederation peers (1-4294967295)...",
718e3744 1129 "BGP specific commands\n"
1130 "AS confederation parameters\n"
1131 "Peer ASs in BGP confederation\n"
1132 AS_STR)
1133{
d62a17ae 1134 VTY_DECLVAR_CONTEXT(bgp, bgp);
1135 int idx_asn = 3;
1136 as_t as;
1137 int i;
718e3744 1138
d62a17ae 1139 for (i = idx_asn; i < argc; i++) {
1140 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1141
d62a17ae 1142 if (bgp->as == as) {
1143 vty_out(vty,
1144 "%% Local member-AS not allowed in confed peer list\n");
1145 continue;
1146 }
718e3744 1147
d62a17ae 1148 bgp_confederation_peers_add(bgp, as);
1149 }
1150 return CMD_SUCCESS;
718e3744 1151}
1152
1153DEFUN (no_bgp_confederation_peers,
1154 no_bgp_confederation_peers_cmd,
e83a9414 1155 "no bgp confederation peers (1-4294967295)...",
718e3744 1156 NO_STR
1157 "BGP specific commands\n"
1158 "AS confederation parameters\n"
1159 "Peer ASs in BGP confederation\n"
1160 AS_STR)
1161{
d62a17ae 1162 VTY_DECLVAR_CONTEXT(bgp, bgp);
1163 int idx_asn = 4;
1164 as_t as;
1165 int i;
718e3744 1166
d62a17ae 1167 for (i = idx_asn; i < argc; i++) {
1168 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1169
d62a17ae 1170 bgp_confederation_peers_remove(bgp, as);
1171 }
1172 return CMD_SUCCESS;
718e3744 1173}
6b0655a2 1174
5e242b0d
DS
1175/**
1176 * Central routine for maximum-paths configuration.
1177 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1178 * @set: 1 for setting values, 0 for removing the max-paths config.
1179 */
d62a17ae 1180static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1181 const char *mpaths, uint16_t options,
d62a17ae 1182 int set)
1183{
1184 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1185 uint16_t maxpaths = 0;
d62a17ae 1186 int ret;
1187 afi_t afi;
1188 safi_t safi;
1189
1190 afi = bgp_node_afi(vty);
1191 safi = bgp_node_safi(vty);
1192
1193 if (set) {
1194 maxpaths = strtol(mpaths, NULL, 10);
1195 if (maxpaths > multipath_num) {
1196 vty_out(vty,
1197 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1198 maxpaths, multipath_num);
1199 return CMD_WARNING_CONFIG_FAILED;
1200 }
1201 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1202 options);
1203 } else
1204 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1205
1206 if (ret < 0) {
1207 vty_out(vty,
1208 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1209 (set == 1) ? "" : "un",
1210 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1211 maxpaths, afi, safi);
1212 return CMD_WARNING_CONFIG_FAILED;
1213 }
1214
1215 bgp_recalculate_all_bestpaths(bgp);
1216
1217 return CMD_SUCCESS;
165b5fff
JB
1218}
1219
abc920f8
DS
1220DEFUN (bgp_maxmed_admin,
1221 bgp_maxmed_admin_cmd,
1222 "bgp max-med administrative ",
1223 BGP_STR
1224 "Advertise routes with max-med\n"
1225 "Administratively applied, for an indefinite period\n")
1226{
d62a17ae 1227 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1228
d62a17ae 1229 bgp->v_maxmed_admin = 1;
1230 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1231
d62a17ae 1232 bgp_maxmed_update(bgp);
abc920f8 1233
d62a17ae 1234 return CMD_SUCCESS;
abc920f8
DS
1235}
1236
1237DEFUN (bgp_maxmed_admin_medv,
1238 bgp_maxmed_admin_medv_cmd,
4668a151 1239 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1240 BGP_STR
1241 "Advertise routes with max-med\n"
1242 "Administratively applied, for an indefinite period\n"
1243 "Max MED value to be used\n")
1244{
d62a17ae 1245 VTY_DECLVAR_CONTEXT(bgp, bgp);
1246 int idx_number = 3;
abc920f8 1247
d62a17ae 1248 bgp->v_maxmed_admin = 1;
1249 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1250
d62a17ae 1251 bgp_maxmed_update(bgp);
abc920f8 1252
d62a17ae 1253 return CMD_SUCCESS;
abc920f8
DS
1254}
1255
1256DEFUN (no_bgp_maxmed_admin,
1257 no_bgp_maxmed_admin_cmd,
4668a151 1258 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1259 NO_STR
1260 BGP_STR
1261 "Advertise routes with max-med\n"
838758ac
DW
1262 "Administratively applied, for an indefinite period\n"
1263 "Max MED value to be used\n")
abc920f8 1264{
d62a17ae 1265 VTY_DECLVAR_CONTEXT(bgp, bgp);
1266 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1267 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1268 bgp_maxmed_update(bgp);
abc920f8 1269
d62a17ae 1270 return CMD_SUCCESS;
abc920f8
DS
1271}
1272
abc920f8
DS
1273DEFUN (bgp_maxmed_onstartup,
1274 bgp_maxmed_onstartup_cmd,
4668a151 1275 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1276 BGP_STR
1277 "Advertise routes with max-med\n"
1278 "Effective on a startup\n"
1279 "Time (seconds) period for max-med\n"
1280 "Max MED value to be used\n")
1281{
d62a17ae 1282 VTY_DECLVAR_CONTEXT(bgp, bgp);
1283 int idx = 0;
4668a151 1284
d62a17ae 1285 argv_find(argv, argc, "(5-86400)", &idx);
1286 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1287 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1288 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1289 else
1290 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1291
d62a17ae 1292 bgp_maxmed_update(bgp);
abc920f8 1293
d62a17ae 1294 return CMD_SUCCESS;
abc920f8
DS
1295}
1296
1297DEFUN (no_bgp_maxmed_onstartup,
1298 no_bgp_maxmed_onstartup_cmd,
4668a151 1299 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1300 NO_STR
1301 BGP_STR
1302 "Advertise routes with max-med\n"
838758ac
DW
1303 "Effective on a startup\n"
1304 "Time (seconds) period for max-med\n"
1305 "Max MED value to be used\n")
abc920f8 1306{
d62a17ae 1307 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1308
d62a17ae 1309 /* Cancel max-med onstartup if its on */
1310 if (bgp->t_maxmed_onstartup) {
1311 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1312 bgp->maxmed_onstartup_over = 1;
1313 }
abc920f8 1314
d62a17ae 1315 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1316 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1317
d62a17ae 1318 bgp_maxmed_update(bgp);
abc920f8 1319
d62a17ae 1320 return CMD_SUCCESS;
abc920f8
DS
1321}
1322
d62a17ae 1323static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1324 const char *wait)
f188f2c4 1325{
d62a17ae 1326 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1327 uint16_t update_delay;
1328 uint16_t establish_wait;
f188f2c4 1329
d62a17ae 1330 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1331
d62a17ae 1332 if (!wait) /* update-delay <delay> */
1333 {
1334 bgp->v_update_delay = update_delay;
1335 bgp->v_establish_wait = bgp->v_update_delay;
1336 return CMD_SUCCESS;
1337 }
f188f2c4 1338
d62a17ae 1339 /* update-delay <delay> <establish-wait> */
1340 establish_wait = atoi(wait);
1341 if (update_delay < establish_wait) {
1342 vty_out(vty,
1343 "%%Failed: update-delay less than the establish-wait!\n");
1344 return CMD_WARNING_CONFIG_FAILED;
1345 }
f188f2c4 1346
d62a17ae 1347 bgp->v_update_delay = update_delay;
1348 bgp->v_establish_wait = establish_wait;
f188f2c4 1349
d62a17ae 1350 return CMD_SUCCESS;
f188f2c4
DS
1351}
1352
d62a17ae 1353static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1354{
d62a17ae 1355 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1356
d62a17ae 1357 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1358 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1359
d62a17ae 1360 return CMD_SUCCESS;
f188f2c4
DS
1361}
1362
2b791107 1363void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1364{
d62a17ae 1365 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1366 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1367 if (bgp->v_update_delay != bgp->v_establish_wait)
1368 vty_out(vty, " %d", bgp->v_establish_wait);
1369 vty_out(vty, "\n");
1370 }
f188f2c4
DS
1371}
1372
1373
1374/* Update-delay configuration */
1375DEFUN (bgp_update_delay,
1376 bgp_update_delay_cmd,
6147e2c6 1377 "update-delay (0-3600)",
f188f2c4
DS
1378 "Force initial delay for best-path and updates\n"
1379 "Seconds\n")
1380{
d62a17ae 1381 int idx_number = 1;
1382 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1383}
1384
1385DEFUN (bgp_update_delay_establish_wait,
1386 bgp_update_delay_establish_wait_cmd,
6147e2c6 1387 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1388 "Force initial delay for best-path and updates\n"
1389 "Seconds\n"
f188f2c4
DS
1390 "Seconds\n")
1391{
d62a17ae 1392 int idx_number = 1;
1393 int idx_number_2 = 2;
1394 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1395 argv[idx_number_2]->arg);
f188f2c4
DS
1396}
1397
1398/* Update-delay deconfiguration */
1399DEFUN (no_bgp_update_delay,
1400 no_bgp_update_delay_cmd,
838758ac
DW
1401 "no update-delay [(0-3600) [(1-3600)]]",
1402 NO_STR
f188f2c4 1403 "Force initial delay for best-path and updates\n"
838758ac 1404 "Seconds\n"
7111c1a0 1405 "Seconds\n")
f188f2c4 1406{
d62a17ae 1407 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1408}
1409
5e242b0d 1410
d62a17ae 1411static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1412 char set)
cb1faec9 1413{
d62a17ae 1414 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1415
555e09d4
QY
1416 if (set) {
1417 uint32_t quanta = strtoul(num, NULL, 10);
1418 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1419 memory_order_relaxed);
1420 } else {
1421 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1422 memory_order_relaxed);
1423 }
1424
1425 return CMD_SUCCESS;
1426}
1427
1428static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1429 char set)
1430{
1431 VTY_DECLVAR_CONTEXT(bgp, bgp);
1432
1433 if (set) {
1434 uint32_t quanta = strtoul(num, NULL, 10);
1435 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1436 memory_order_relaxed);
1437 } else {
1438 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1439 memory_order_relaxed);
1440 }
cb1faec9 1441
d62a17ae 1442 return CMD_SUCCESS;
cb1faec9
DS
1443}
1444
2b791107 1445void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1446{
555e09d4
QY
1447 uint32_t quanta =
1448 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1449 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1450 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1451}
1452
555e09d4
QY
1453void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1454{
1455 uint32_t quanta =
1456 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1457 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1458 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1459}
cb1faec9 1460
555e09d4 1461/* Packet quanta configuration */
cb1faec9
DS
1462DEFUN (bgp_wpkt_quanta,
1463 bgp_wpkt_quanta_cmd,
555e09d4 1464 "write-quanta (1-10)",
cb1faec9
DS
1465 "How many packets to write to peer socket per run\n"
1466 "Number of packets\n")
1467{
d62a17ae 1468 int idx_number = 1;
1469 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1470}
1471
cb1faec9
DS
1472DEFUN (no_bgp_wpkt_quanta,
1473 no_bgp_wpkt_quanta_cmd,
555e09d4 1474 "no write-quanta (1-10)",
d7fa34c1 1475 NO_STR
555e09d4 1476 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1477 "Number of packets\n")
1478{
d62a17ae 1479 int idx_number = 2;
1480 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1481}
1482
555e09d4
QY
1483DEFUN (bgp_rpkt_quanta,
1484 bgp_rpkt_quanta_cmd,
1485 "read-quanta (1-10)",
1486 "How many packets to read from peer socket per I/O cycle\n"
1487 "Number of packets\n")
1488{
1489 int idx_number = 1;
1490 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1491}
1492
1493DEFUN (no_bgp_rpkt_quanta,
1494 no_bgp_rpkt_quanta_cmd,
1495 "no read-quanta (1-10)",
1496 NO_STR
1497 "How many packets to read from peer socket per I/O cycle\n"
1498 "Number of packets\n")
1499{
1500 int idx_number = 2;
1501 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1502}
1503
2b791107 1504void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1505{
37a333fe 1506 if (!bgp->heuristic_coalesce)
d62a17ae 1507 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1508}
1509
1510
1511DEFUN (bgp_coalesce_time,
1512 bgp_coalesce_time_cmd,
6147e2c6 1513 "coalesce-time (0-4294967295)",
3f9c7369
DS
1514 "Subgroup coalesce timer\n"
1515 "Subgroup coalesce timer value (in ms)\n")
1516{
d62a17ae 1517 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1518
d62a17ae 1519 int idx = 0;
1520 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1521 bgp->heuristic_coalesce = false;
d62a17ae 1522 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1523 return CMD_SUCCESS;
3f9c7369
DS
1524}
1525
1526DEFUN (no_bgp_coalesce_time,
1527 no_bgp_coalesce_time_cmd,
6147e2c6 1528 "no coalesce-time (0-4294967295)",
3a2d747c 1529 NO_STR
3f9c7369
DS
1530 "Subgroup coalesce timer\n"
1531 "Subgroup coalesce timer value (in ms)\n")
1532{
d62a17ae 1533 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1534
37a333fe 1535 bgp->heuristic_coalesce = true;
d62a17ae 1536 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1537 return CMD_SUCCESS;
3f9c7369
DS
1538}
1539
5e242b0d
DS
1540/* Maximum-paths configuration */
1541DEFUN (bgp_maxpaths,
1542 bgp_maxpaths_cmd,
6319fd63 1543 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1544 "Forward packets over multiple paths\n"
1545 "Number of paths\n")
1546{
d62a17ae 1547 int idx_number = 1;
1548 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1549 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1550}
1551
d62a17ae 1552ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1553 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1554 "Forward packets over multiple paths\n"
1555 "Number of paths\n")
596c17ba 1556
165b5fff
JB
1557DEFUN (bgp_maxpaths_ibgp,
1558 bgp_maxpaths_ibgp_cmd,
6319fd63 1559 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1560 "Forward packets over multiple paths\n"
1561 "iBGP-multipath\n"
1562 "Number of paths\n")
1563{
d62a17ae 1564 int idx_number = 2;
1565 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1566 argv[idx_number]->arg, 0, 1);
5e242b0d 1567}
165b5fff 1568
d62a17ae 1569ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1570 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1571 "Forward packets over multiple paths\n"
1572 "iBGP-multipath\n"
1573 "Number of paths\n")
596c17ba 1574
5e242b0d
DS
1575DEFUN (bgp_maxpaths_ibgp_cluster,
1576 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1577 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1578 "Forward packets over multiple paths\n"
1579 "iBGP-multipath\n"
1580 "Number of paths\n"
1581 "Match the cluster length\n")
1582{
d62a17ae 1583 int idx_number = 2;
1584 return bgp_maxpaths_config_vty(
1585 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1586 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1587}
1588
d62a17ae 1589ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1590 "maximum-paths ibgp " CMD_RANGE_STR(
1591 1, MULTIPATH_NUM) " equal-cluster-length",
1592 "Forward packets over multiple paths\n"
1593 "iBGP-multipath\n"
1594 "Number of paths\n"
1595 "Match the cluster length\n")
596c17ba 1596
165b5fff
JB
1597DEFUN (no_bgp_maxpaths,
1598 no_bgp_maxpaths_cmd,
6319fd63 1599 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1600 NO_STR
1601 "Forward packets over multiple paths\n"
1602 "Number of paths\n")
1603{
d62a17ae 1604 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1605}
1606
d62a17ae 1607ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1608 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1609 "Forward packets over multiple paths\n"
1610 "Number of paths\n")
596c17ba 1611
165b5fff
JB
1612DEFUN (no_bgp_maxpaths_ibgp,
1613 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1614 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1615 NO_STR
1616 "Forward packets over multiple paths\n"
1617 "iBGP-multipath\n"
838758ac
DW
1618 "Number of paths\n"
1619 "Match the cluster length\n")
165b5fff 1620{
d62a17ae 1621 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1622}
1623
d62a17ae 1624ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1625 "no maximum-paths ibgp [" CMD_RANGE_STR(
1626 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1627 NO_STR
1628 "Forward packets over multiple paths\n"
1629 "iBGP-multipath\n"
1630 "Number of paths\n"
1631 "Match the cluster length\n")
596c17ba 1632
2b791107 1633void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1634 safi_t safi)
165b5fff 1635{
d62a17ae 1636 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1637 vty_out(vty, " maximum-paths %d\n",
1638 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1639 }
165b5fff 1640
d62a17ae 1641 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1642 vty_out(vty, " maximum-paths ibgp %d",
1643 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1644 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1645 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1646 vty_out(vty, " equal-cluster-length");
1647 vty_out(vty, "\n");
1648 }
165b5fff 1649}
6b0655a2 1650
718e3744 1651/* BGP timers. */
1652
1653DEFUN (bgp_timers,
1654 bgp_timers_cmd,
6147e2c6 1655 "timers bgp (0-65535) (0-65535)",
718e3744 1656 "Adjust routing timers\n"
1657 "BGP timers\n"
1658 "Keepalive interval\n"
1659 "Holdtime\n")
1660{
d62a17ae 1661 VTY_DECLVAR_CONTEXT(bgp, bgp);
1662 int idx_number = 2;
1663 int idx_number_2 = 3;
1664 unsigned long keepalive = 0;
1665 unsigned long holdtime = 0;
718e3744 1666
d62a17ae 1667 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1668 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1669
d62a17ae 1670 /* Holdtime value check. */
1671 if (holdtime < 3 && holdtime != 0) {
1672 vty_out(vty,
1673 "%% hold time value must be either 0 or greater than 3\n");
1674 return CMD_WARNING_CONFIG_FAILED;
1675 }
718e3744 1676
d62a17ae 1677 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1678
d62a17ae 1679 return CMD_SUCCESS;
718e3744 1680}
1681
1682DEFUN (no_bgp_timers,
1683 no_bgp_timers_cmd,
838758ac 1684 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1685 NO_STR
1686 "Adjust routing timers\n"
838758ac
DW
1687 "BGP timers\n"
1688 "Keepalive interval\n"
1689 "Holdtime\n")
718e3744 1690{
d62a17ae 1691 VTY_DECLVAR_CONTEXT(bgp, bgp);
1692 bgp_timers_unset(bgp);
718e3744 1693
d62a17ae 1694 return CMD_SUCCESS;
718e3744 1695}
1696
6b0655a2 1697
718e3744 1698DEFUN (bgp_client_to_client_reflection,
1699 bgp_client_to_client_reflection_cmd,
1700 "bgp client-to-client reflection",
1701 "BGP specific commands\n"
1702 "Configure client to client route reflection\n"
1703 "reflection of routes allowed\n")
1704{
d62a17ae 1705 VTY_DECLVAR_CONTEXT(bgp, bgp);
1706 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1707 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1708
d62a17ae 1709 return CMD_SUCCESS;
718e3744 1710}
1711
1712DEFUN (no_bgp_client_to_client_reflection,
1713 no_bgp_client_to_client_reflection_cmd,
1714 "no bgp client-to-client reflection",
1715 NO_STR
1716 "BGP specific commands\n"
1717 "Configure client to client route reflection\n"
1718 "reflection of routes allowed\n")
1719{
d62a17ae 1720 VTY_DECLVAR_CONTEXT(bgp, bgp);
1721 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1722 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1723
d62a17ae 1724 return CMD_SUCCESS;
718e3744 1725}
1726
1727/* "bgp always-compare-med" configuration. */
1728DEFUN (bgp_always_compare_med,
1729 bgp_always_compare_med_cmd,
1730 "bgp always-compare-med",
1731 "BGP specific commands\n"
1732 "Allow comparing MED from different neighbors\n")
1733{
d62a17ae 1734 VTY_DECLVAR_CONTEXT(bgp, bgp);
1735 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1736 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1737
d62a17ae 1738 return CMD_SUCCESS;
718e3744 1739}
1740
1741DEFUN (no_bgp_always_compare_med,
1742 no_bgp_always_compare_med_cmd,
1743 "no bgp always-compare-med",
1744 NO_STR
1745 "BGP specific commands\n"
1746 "Allow comparing MED from different neighbors\n")
1747{
d62a17ae 1748 VTY_DECLVAR_CONTEXT(bgp, bgp);
1749 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1750 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1751
d62a17ae 1752 return CMD_SUCCESS;
718e3744 1753}
6b0655a2 1754
718e3744 1755/* "bgp deterministic-med" configuration. */
1756DEFUN (bgp_deterministic_med,
1757 bgp_deterministic_med_cmd,
1758 "bgp deterministic-med",
1759 "BGP specific commands\n"
1760 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1761{
d62a17ae 1762 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1763
d62a17ae 1764 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1765 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1766 bgp_recalculate_all_bestpaths(bgp);
1767 }
7aafcaca 1768
d62a17ae 1769 return CMD_SUCCESS;
718e3744 1770}
1771
1772DEFUN (no_bgp_deterministic_med,
1773 no_bgp_deterministic_med_cmd,
1774 "no bgp deterministic-med",
1775 NO_STR
1776 "BGP specific commands\n"
1777 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1778{
d62a17ae 1779 VTY_DECLVAR_CONTEXT(bgp, bgp);
1780 int bestpath_per_as_used;
1781 afi_t afi;
1782 safi_t safi;
1783 struct peer *peer;
1784 struct listnode *node, *nnode;
1785
1786 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1787 bestpath_per_as_used = 0;
1788
1789 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc
QY
1790 FOREACH_AFI_SAFI (afi, safi)
1791 if (CHECK_FLAG(
1792 peer->af_flags[afi][safi],
1793 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1794 bestpath_per_as_used = 1;
1795 break;
1796 }
d62a17ae 1797
1798 if (bestpath_per_as_used)
1799 break;
1800 }
1801
1802 if (bestpath_per_as_used) {
1803 vty_out(vty,
1804 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1805 return CMD_WARNING_CONFIG_FAILED;
1806 } else {
1807 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1808 bgp_recalculate_all_bestpaths(bgp);
1809 }
1810 }
1811
1812 return CMD_SUCCESS;
718e3744 1813}
538621f2 1814
1815/* "bgp graceful-restart" configuration. */
1816DEFUN (bgp_graceful_restart,
1817 bgp_graceful_restart_cmd,
1818 "bgp graceful-restart",
1819 "BGP specific commands\n"
1820 "Graceful restart capability parameters\n")
1821{
d62a17ae 1822 VTY_DECLVAR_CONTEXT(bgp, bgp);
1823 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1824 return CMD_SUCCESS;
538621f2 1825}
1826
1827DEFUN (no_bgp_graceful_restart,
1828 no_bgp_graceful_restart_cmd,
1829 "no bgp graceful-restart",
1830 NO_STR
1831 "BGP specific commands\n"
1832 "Graceful restart capability parameters\n")
1833{
d62a17ae 1834 VTY_DECLVAR_CONTEXT(bgp, bgp);
1835 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1836 return CMD_SUCCESS;
538621f2 1837}
1838
93406d87 1839DEFUN (bgp_graceful_restart_stalepath_time,
1840 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1841 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1842 "BGP specific commands\n"
1843 "Graceful restart capability parameters\n"
1844 "Set the max time to hold onto restarting peer's stale paths\n"
1845 "Delay value (seconds)\n")
1846{
d62a17ae 1847 VTY_DECLVAR_CONTEXT(bgp, bgp);
1848 int idx_number = 3;
d7c0a89a 1849 uint32_t stalepath;
93406d87 1850
d62a17ae 1851 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1852 bgp->stalepath_time = stalepath;
1853 return CMD_SUCCESS;
93406d87 1854}
1855
eb6f1b41
PG
1856DEFUN (bgp_graceful_restart_restart_time,
1857 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1858 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1859 "BGP specific commands\n"
1860 "Graceful restart capability parameters\n"
1861 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1862 "Delay value (seconds)\n")
1863{
d62a17ae 1864 VTY_DECLVAR_CONTEXT(bgp, bgp);
1865 int idx_number = 3;
d7c0a89a 1866 uint32_t restart;
eb6f1b41 1867
d62a17ae 1868 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1869 bgp->restart_time = restart;
1870 return CMD_SUCCESS;
eb6f1b41
PG
1871}
1872
93406d87 1873DEFUN (no_bgp_graceful_restart_stalepath_time,
1874 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1875 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1876 NO_STR
1877 "BGP specific commands\n"
1878 "Graceful restart capability parameters\n"
838758ac
DW
1879 "Set the max time to hold onto restarting peer's stale paths\n"
1880 "Delay value (seconds)\n")
93406d87 1881{
d62a17ae 1882 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1883
d62a17ae 1884 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1885 return CMD_SUCCESS;
93406d87 1886}
1887
eb6f1b41
PG
1888DEFUN (no_bgp_graceful_restart_restart_time,
1889 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1890 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1891 NO_STR
1892 "BGP specific commands\n"
1893 "Graceful restart capability parameters\n"
838758ac
DW
1894 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1895 "Delay value (seconds)\n")
eb6f1b41 1896{
d62a17ae 1897 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1898
d62a17ae 1899 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1900 return CMD_SUCCESS;
eb6f1b41
PG
1901}
1902
43fc21b3
JC
1903DEFUN (bgp_graceful_restart_preserve_fw,
1904 bgp_graceful_restart_preserve_fw_cmd,
1905 "bgp graceful-restart preserve-fw-state",
1906 "BGP specific commands\n"
1907 "Graceful restart capability parameters\n"
1908 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1909{
d62a17ae 1910 VTY_DECLVAR_CONTEXT(bgp, bgp);
1911 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1912 return CMD_SUCCESS;
43fc21b3
JC
1913}
1914
1915DEFUN (no_bgp_graceful_restart_preserve_fw,
1916 no_bgp_graceful_restart_preserve_fw_cmd,
1917 "no bgp graceful-restart preserve-fw-state",
1918 NO_STR
1919 "BGP specific commands\n"
1920 "Graceful restart capability parameters\n"
1921 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1922{
d62a17ae 1923 VTY_DECLVAR_CONTEXT(bgp, bgp);
1924 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1925 return CMD_SUCCESS;
43fc21b3
JC
1926}
1927
7f323236
DW
1928static void bgp_redistribute_redo(struct bgp *bgp)
1929{
1930 afi_t afi;
1931 int i;
1932 struct list *red_list;
1933 struct listnode *node;
1934 struct bgp_redist *red;
1935
a4d82a8a
PZ
1936 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1937 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 1938
a4d82a8a
PZ
1939 red_list = bgp->redist[afi][i];
1940 if (!red_list)
1941 continue;
7f323236 1942
a4d82a8a 1943 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
1944 bgp_redistribute_resend(bgp, afi, i,
1945 red->instance);
1946 }
1947 }
1948 }
1949}
1950
1951/* "bgp graceful-shutdown" configuration */
1952DEFUN (bgp_graceful_shutdown,
1953 bgp_graceful_shutdown_cmd,
1954 "bgp graceful-shutdown",
1955 BGP_STR
1956 "Graceful shutdown parameters\n")
1957{
1958 VTY_DECLVAR_CONTEXT(bgp, bgp);
1959
1960 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1961 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1962 bgp_static_redo_import_check(bgp);
1963 bgp_redistribute_redo(bgp);
1964 bgp_clear_star_soft_out(vty, bgp->name);
1965 bgp_clear_star_soft_in(vty, bgp->name);
1966 }
1967
1968 return CMD_SUCCESS;
1969}
1970
1971DEFUN (no_bgp_graceful_shutdown,
1972 no_bgp_graceful_shutdown_cmd,
1973 "no bgp graceful-shutdown",
1974 NO_STR
1975 BGP_STR
1976 "Graceful shutdown parameters\n")
1977{
1978 VTY_DECLVAR_CONTEXT(bgp, bgp);
1979
1980 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1981 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1982 bgp_static_redo_import_check(bgp);
1983 bgp_redistribute_redo(bgp);
1984 bgp_clear_star_soft_out(vty, bgp->name);
1985 bgp_clear_star_soft_in(vty, bgp->name);
1986 }
1987
1988 return CMD_SUCCESS;
1989}
1990
718e3744 1991/* "bgp fast-external-failover" configuration. */
1992DEFUN (bgp_fast_external_failover,
1993 bgp_fast_external_failover_cmd,
1994 "bgp fast-external-failover",
1995 BGP_STR
1996 "Immediately reset session if a link to a directly connected external peer goes down\n")
1997{
d62a17ae 1998 VTY_DECLVAR_CONTEXT(bgp, bgp);
1999 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2000 return CMD_SUCCESS;
718e3744 2001}
2002
2003DEFUN (no_bgp_fast_external_failover,
2004 no_bgp_fast_external_failover_cmd,
2005 "no bgp fast-external-failover",
2006 NO_STR
2007 BGP_STR
2008 "Immediately reset session if a link to a directly connected external peer goes down\n")
2009{
d62a17ae 2010 VTY_DECLVAR_CONTEXT(bgp, bgp);
2011 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2012 return CMD_SUCCESS;
718e3744 2013}
6b0655a2 2014
718e3744 2015/* "bgp enforce-first-as" configuration. */
47cbc09b
PM
2016#if defined(VERSION_TYPE_DEV) && CONFDATE > 20180517
2017CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2018#endif
2019
f07e1c4f
QY
2020DEFUN_HIDDEN (bgp_enforce_first_as,
2021 bgp_enforce_first_as_cmd,
2022 "[no] bgp enforce-first-as",
2023 NO_STR
2024 BGP_STR
2025 "Enforce the first AS for EBGP routes\n")
718e3744 2026{
d62a17ae 2027 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2028
f07e1c4f
QY
2029 if (strmatch(argv[0]->text, "no"))
2030 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2031 else
2032 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
7aafcaca 2033
d62a17ae 2034 return CMD_SUCCESS;
718e3744 2035}
6b0655a2 2036
718e3744 2037/* "bgp bestpath compare-routerid" configuration. */
2038DEFUN (bgp_bestpath_compare_router_id,
2039 bgp_bestpath_compare_router_id_cmd,
2040 "bgp bestpath compare-routerid",
2041 "BGP specific commands\n"
2042 "Change the default bestpath selection\n"
2043 "Compare router-id for identical EBGP paths\n")
2044{
d62a17ae 2045 VTY_DECLVAR_CONTEXT(bgp, bgp);
2046 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2047 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2048
d62a17ae 2049 return CMD_SUCCESS;
718e3744 2050}
2051
2052DEFUN (no_bgp_bestpath_compare_router_id,
2053 no_bgp_bestpath_compare_router_id_cmd,
2054 "no bgp bestpath compare-routerid",
2055 NO_STR
2056 "BGP specific commands\n"
2057 "Change the default bestpath selection\n"
2058 "Compare router-id for identical EBGP paths\n")
2059{
d62a17ae 2060 VTY_DECLVAR_CONTEXT(bgp, bgp);
2061 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2062 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2063
d62a17ae 2064 return CMD_SUCCESS;
718e3744 2065}
6b0655a2 2066
718e3744 2067/* "bgp bestpath as-path ignore" configuration. */
2068DEFUN (bgp_bestpath_aspath_ignore,
2069 bgp_bestpath_aspath_ignore_cmd,
2070 "bgp bestpath as-path ignore",
2071 "BGP specific commands\n"
2072 "Change the default bestpath selection\n"
2073 "AS-path attribute\n"
2074 "Ignore as-path length in selecting a route\n")
2075{
d62a17ae 2076 VTY_DECLVAR_CONTEXT(bgp, bgp);
2077 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2078 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2079
d62a17ae 2080 return CMD_SUCCESS;
718e3744 2081}
2082
2083DEFUN (no_bgp_bestpath_aspath_ignore,
2084 no_bgp_bestpath_aspath_ignore_cmd,
2085 "no bgp bestpath as-path ignore",
2086 NO_STR
2087 "BGP specific commands\n"
2088 "Change the default bestpath selection\n"
2089 "AS-path attribute\n"
2090 "Ignore as-path length in selecting a route\n")
2091{
d62a17ae 2092 VTY_DECLVAR_CONTEXT(bgp, bgp);
2093 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2094 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2095
d62a17ae 2096 return CMD_SUCCESS;
718e3744 2097}
6b0655a2 2098
6811845b 2099/* "bgp bestpath as-path confed" configuration. */
2100DEFUN (bgp_bestpath_aspath_confed,
2101 bgp_bestpath_aspath_confed_cmd,
2102 "bgp bestpath as-path confed",
2103 "BGP specific commands\n"
2104 "Change the default bestpath selection\n"
2105 "AS-path attribute\n"
2106 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2107{
d62a17ae 2108 VTY_DECLVAR_CONTEXT(bgp, bgp);
2109 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2110 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2111
d62a17ae 2112 return CMD_SUCCESS;
6811845b 2113}
2114
2115DEFUN (no_bgp_bestpath_aspath_confed,
2116 no_bgp_bestpath_aspath_confed_cmd,
2117 "no bgp bestpath as-path confed",
2118 NO_STR
2119 "BGP specific commands\n"
2120 "Change the default bestpath selection\n"
2121 "AS-path attribute\n"
2122 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2123{
d62a17ae 2124 VTY_DECLVAR_CONTEXT(bgp, bgp);
2125 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2126 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2127
d62a17ae 2128 return CMD_SUCCESS;
6811845b 2129}
6b0655a2 2130
2fdd455c
PM
2131/* "bgp bestpath as-path multipath-relax" configuration. */
2132DEFUN (bgp_bestpath_aspath_multipath_relax,
2133 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2134 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2135 "BGP specific commands\n"
2136 "Change the default bestpath selection\n"
2137 "AS-path attribute\n"
2138 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2139 "Generate an AS_SET\n"
16fc1eec
DS
2140 "Do not generate an AS_SET\n")
2141{
d62a17ae 2142 VTY_DECLVAR_CONTEXT(bgp, bgp);
2143 int idx = 0;
2144 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2145
d62a17ae 2146 /* no-as-set is now the default behavior so we can silently
2147 * ignore it */
2148 if (argv_find(argv, argc, "as-set", &idx))
2149 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2150 else
2151 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2152
d62a17ae 2153 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2154
d62a17ae 2155 return CMD_SUCCESS;
16fc1eec
DS
2156}
2157
219178b6
DW
2158DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2159 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2160 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2161 NO_STR
2162 "BGP specific commands\n"
2163 "Change the default bestpath selection\n"
2164 "AS-path attribute\n"
2165 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2166 "Generate an AS_SET\n"
16fc1eec
DS
2167 "Do not generate an AS_SET\n")
2168{
d62a17ae 2169 VTY_DECLVAR_CONTEXT(bgp, bgp);
2170 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2171 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2172 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2173
d62a17ae 2174 return CMD_SUCCESS;
2fdd455c 2175}
6b0655a2 2176
848973c7 2177/* "bgp log-neighbor-changes" configuration. */
2178DEFUN (bgp_log_neighbor_changes,
2179 bgp_log_neighbor_changes_cmd,
2180 "bgp log-neighbor-changes",
2181 "BGP specific commands\n"
2182 "Log neighbor up/down and reset reason\n")
2183{
d62a17ae 2184 VTY_DECLVAR_CONTEXT(bgp, bgp);
2185 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2186 return CMD_SUCCESS;
848973c7 2187}
2188
2189DEFUN (no_bgp_log_neighbor_changes,
2190 no_bgp_log_neighbor_changes_cmd,
2191 "no bgp log-neighbor-changes",
2192 NO_STR
2193 "BGP specific commands\n"
2194 "Log neighbor up/down and reset reason\n")
2195{
d62a17ae 2196 VTY_DECLVAR_CONTEXT(bgp, bgp);
2197 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2198 return CMD_SUCCESS;
848973c7 2199}
6b0655a2 2200
718e3744 2201/* "bgp bestpath med" configuration. */
2202DEFUN (bgp_bestpath_med,
2203 bgp_bestpath_med_cmd,
2d8c1a4d 2204 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2205 "BGP specific commands\n"
2206 "Change the default bestpath selection\n"
2207 "MED attribute\n"
2208 "Compare MED among confederation paths\n"
838758ac
DW
2209 "Treat missing MED as the least preferred one\n"
2210 "Treat missing MED as the least preferred one\n"
2211 "Compare MED among confederation paths\n")
718e3744 2212{
d62a17ae 2213 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2214
d62a17ae 2215 int idx = 0;
2216 if (argv_find(argv, argc, "confed", &idx))
2217 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2218 idx = 0;
2219 if (argv_find(argv, argc, "missing-as-worst", &idx))
2220 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2221
d62a17ae 2222 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2223
d62a17ae 2224 return CMD_SUCCESS;
718e3744 2225}
2226
718e3744 2227DEFUN (no_bgp_bestpath_med,
2228 no_bgp_bestpath_med_cmd,
2d8c1a4d 2229 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2230 NO_STR
2231 "BGP specific commands\n"
2232 "Change the default bestpath selection\n"
2233 "MED attribute\n"
2234 "Compare MED among confederation paths\n"
3a2d747c
QY
2235 "Treat missing MED as the least preferred one\n"
2236 "Treat missing MED as the least preferred one\n"
2237 "Compare MED among confederation paths\n")
718e3744 2238{
d62a17ae 2239 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2240
d62a17ae 2241 int idx = 0;
2242 if (argv_find(argv, argc, "confed", &idx))
2243 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2244 idx = 0;
2245 if (argv_find(argv, argc, "missing-as-worst", &idx))
2246 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2247
d62a17ae 2248 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2249
d62a17ae 2250 return CMD_SUCCESS;
718e3744 2251}
2252
718e3744 2253/* "no bgp default ipv4-unicast". */
2254DEFUN (no_bgp_default_ipv4_unicast,
2255 no_bgp_default_ipv4_unicast_cmd,
2256 "no bgp default ipv4-unicast",
2257 NO_STR
2258 "BGP specific commands\n"
2259 "Configure BGP defaults\n"
2260 "Activate ipv4-unicast for a peer by default\n")
2261{
d62a17ae 2262 VTY_DECLVAR_CONTEXT(bgp, bgp);
2263 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2264 return CMD_SUCCESS;
718e3744 2265}
2266
2267DEFUN (bgp_default_ipv4_unicast,
2268 bgp_default_ipv4_unicast_cmd,
2269 "bgp default ipv4-unicast",
2270 "BGP specific commands\n"
2271 "Configure BGP defaults\n"
2272 "Activate ipv4-unicast for a peer by default\n")
2273{
d62a17ae 2274 VTY_DECLVAR_CONTEXT(bgp, bgp);
2275 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2276 return CMD_SUCCESS;
718e3744 2277}
6b0655a2 2278
04b6bdc0
DW
2279/* Display hostname in certain command outputs */
2280DEFUN (bgp_default_show_hostname,
2281 bgp_default_show_hostname_cmd,
2282 "bgp default show-hostname",
2283 "BGP specific commands\n"
2284 "Configure BGP defaults\n"
2285 "Show hostname in certain command ouputs\n")
2286{
d62a17ae 2287 VTY_DECLVAR_CONTEXT(bgp, bgp);
2288 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2289 return CMD_SUCCESS;
04b6bdc0
DW
2290}
2291
2292DEFUN (no_bgp_default_show_hostname,
2293 no_bgp_default_show_hostname_cmd,
2294 "no bgp default show-hostname",
2295 NO_STR
2296 "BGP specific commands\n"
2297 "Configure BGP defaults\n"
2298 "Show hostname in certain command ouputs\n")
2299{
d62a17ae 2300 VTY_DECLVAR_CONTEXT(bgp, bgp);
2301 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2302 return CMD_SUCCESS;
04b6bdc0
DW
2303}
2304
8233ef81 2305/* "bgp network import-check" configuration. */
718e3744 2306DEFUN (bgp_network_import_check,
2307 bgp_network_import_check_cmd,
5623e905 2308 "bgp network import-check",
718e3744 2309 "BGP specific commands\n"
2310 "BGP network command\n"
5623e905 2311 "Check BGP network route exists in IGP\n")
718e3744 2312{
d62a17ae 2313 VTY_DECLVAR_CONTEXT(bgp, bgp);
2314 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2315 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2316 bgp_static_redo_import_check(bgp);
2317 }
078430f6 2318
d62a17ae 2319 return CMD_SUCCESS;
718e3744 2320}
2321
d62a17ae 2322ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2323 "bgp network import-check exact",
2324 "BGP specific commands\n"
2325 "BGP network command\n"
2326 "Check BGP network route exists in IGP\n"
2327 "Match route precisely\n")
8233ef81 2328
718e3744 2329DEFUN (no_bgp_network_import_check,
2330 no_bgp_network_import_check_cmd,
5623e905 2331 "no bgp network import-check",
718e3744 2332 NO_STR
2333 "BGP specific commands\n"
2334 "BGP network command\n"
2335 "Check BGP network route exists in IGP\n")
2336{
d62a17ae 2337 VTY_DECLVAR_CONTEXT(bgp, bgp);
2338 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2339 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2340 bgp_static_redo_import_check(bgp);
2341 }
5623e905 2342
d62a17ae 2343 return CMD_SUCCESS;
718e3744 2344}
6b0655a2 2345
718e3744 2346DEFUN (bgp_default_local_preference,
2347 bgp_default_local_preference_cmd,
6147e2c6 2348 "bgp default local-preference (0-4294967295)",
718e3744 2349 "BGP specific commands\n"
2350 "Configure BGP defaults\n"
2351 "local preference (higher=more preferred)\n"
2352 "Configure default local preference value\n")
2353{
d62a17ae 2354 VTY_DECLVAR_CONTEXT(bgp, bgp);
2355 int idx_number = 3;
d7c0a89a 2356 uint32_t local_pref;
718e3744 2357
d62a17ae 2358 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2359
d62a17ae 2360 bgp_default_local_preference_set(bgp, local_pref);
2361 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2362
d62a17ae 2363 return CMD_SUCCESS;
718e3744 2364}
2365
2366DEFUN (no_bgp_default_local_preference,
2367 no_bgp_default_local_preference_cmd,
838758ac 2368 "no bgp default local-preference [(0-4294967295)]",
718e3744 2369 NO_STR
2370 "BGP specific commands\n"
2371 "Configure BGP defaults\n"
838758ac
DW
2372 "local preference (higher=more preferred)\n"
2373 "Configure default local preference value\n")
718e3744 2374{
d62a17ae 2375 VTY_DECLVAR_CONTEXT(bgp, bgp);
2376 bgp_default_local_preference_unset(bgp);
2377 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2378
d62a17ae 2379 return CMD_SUCCESS;
718e3744 2380}
2381
6b0655a2 2382
3f9c7369
DS
2383DEFUN (bgp_default_subgroup_pkt_queue_max,
2384 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2385 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2386 "BGP specific commands\n"
2387 "Configure BGP defaults\n"
2388 "subgroup-pkt-queue-max\n"
2389 "Configure subgroup packet queue max\n")
8bd9d948 2390{
d62a17ae 2391 VTY_DECLVAR_CONTEXT(bgp, bgp);
2392 int idx_number = 3;
d7c0a89a 2393 uint32_t max_size;
8bd9d948 2394
d62a17ae 2395 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2396
d62a17ae 2397 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2398
d62a17ae 2399 return CMD_SUCCESS;
3f9c7369
DS
2400}
2401
2402DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2403 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2404 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2405 NO_STR
2406 "BGP specific commands\n"
2407 "Configure BGP defaults\n"
838758ac
DW
2408 "subgroup-pkt-queue-max\n"
2409 "Configure subgroup packet queue max\n")
3f9c7369 2410{
d62a17ae 2411 VTY_DECLVAR_CONTEXT(bgp, bgp);
2412 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2413 return CMD_SUCCESS;
8bd9d948
DS
2414}
2415
813d4307 2416
8bd9d948
DS
2417DEFUN (bgp_rr_allow_outbound_policy,
2418 bgp_rr_allow_outbound_policy_cmd,
2419 "bgp route-reflector allow-outbound-policy",
2420 "BGP specific commands\n"
2421 "Allow modifications made by out route-map\n"
2422 "on ibgp neighbors\n")
2423{
d62a17ae 2424 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2425
d62a17ae 2426 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2427 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2428 update_group_announce_rrclients(bgp);
2429 bgp_clear_star_soft_out(vty, bgp->name);
2430 }
8bd9d948 2431
d62a17ae 2432 return CMD_SUCCESS;
8bd9d948
DS
2433}
2434
2435DEFUN (no_bgp_rr_allow_outbound_policy,
2436 no_bgp_rr_allow_outbound_policy_cmd,
2437 "no bgp route-reflector allow-outbound-policy",
2438 NO_STR
2439 "BGP specific commands\n"
2440 "Allow modifications made by out route-map\n"
2441 "on ibgp neighbors\n")
2442{
d62a17ae 2443 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2444
d62a17ae 2445 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2446 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2447 update_group_announce_rrclients(bgp);
2448 bgp_clear_star_soft_out(vty, bgp->name);
2449 }
8bd9d948 2450
d62a17ae 2451 return CMD_SUCCESS;
8bd9d948
DS
2452}
2453
f14e6fdb
DS
2454DEFUN (bgp_listen_limit,
2455 bgp_listen_limit_cmd,
9ccf14f7 2456 "bgp listen limit (1-5000)",
f14e6fdb
DS
2457 "BGP specific commands\n"
2458 "Configure BGP defaults\n"
2459 "maximum number of BGP Dynamic Neighbors that can be created\n"
2460 "Configure Dynamic Neighbors listen limit value\n")
2461{
d62a17ae 2462 VTY_DECLVAR_CONTEXT(bgp, bgp);
2463 int idx_number = 3;
2464 int listen_limit;
f14e6fdb 2465
d62a17ae 2466 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2467
d62a17ae 2468 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2469
d62a17ae 2470 return CMD_SUCCESS;
f14e6fdb
DS
2471}
2472
2473DEFUN (no_bgp_listen_limit,
2474 no_bgp_listen_limit_cmd,
838758ac 2475 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2476 "BGP specific commands\n"
2477 "Configure BGP defaults\n"
2478 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2479 "Configure Dynamic Neighbors listen limit value to default\n"
2480 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2481{
d62a17ae 2482 VTY_DECLVAR_CONTEXT(bgp, bgp);
2483 bgp_listen_limit_unset(bgp);
2484 return CMD_SUCCESS;
f14e6fdb
DS
2485}
2486
2487
20eb8864 2488/*
2489 * Check if this listen range is already configured. Check for exact
2490 * match or overlap based on input.
2491 */
d62a17ae 2492static struct peer_group *listen_range_exists(struct bgp *bgp,
2493 struct prefix *range, int exact)
2494{
2495 struct listnode *node, *nnode;
2496 struct listnode *node1, *nnode1;
2497 struct peer_group *group;
2498 struct prefix *lr;
2499 afi_t afi;
2500 int match;
2501
2502 afi = family2afi(range->family);
2503 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2504 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2505 lr)) {
2506 if (exact)
2507 match = prefix_same(range, lr);
2508 else
2509 match = (prefix_match(range, lr)
2510 || prefix_match(lr, range));
2511 if (match)
2512 return group;
2513 }
2514 }
2515
2516 return NULL;
20eb8864 2517}
2518
f14e6fdb
DS
2519DEFUN (bgp_listen_range,
2520 bgp_listen_range_cmd,
9ccf14f7 2521 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2522 "BGP specific commands\n"
d7fa34c1
QY
2523 "Configure BGP dynamic neighbors listen range\n"
2524 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2525 NEIGHBOR_ADDR_STR
2526 "Member of the peer-group\n"
2527 "Peer-group name\n")
f14e6fdb 2528{
d62a17ae 2529 VTY_DECLVAR_CONTEXT(bgp, bgp);
2530 struct prefix range;
2531 struct peer_group *group, *existing_group;
2532 afi_t afi;
2533 int ret;
2534 int idx = 0;
2535
2536 argv_find(argv, argc, "A.B.C.D/M", &idx);
2537 argv_find(argv, argc, "X:X::X:X/M", &idx);
2538 char *prefix = argv[idx]->arg;
2539 argv_find(argv, argc, "WORD", &idx);
2540 char *peergroup = argv[idx]->arg;
2541
2542 /* Convert IP prefix string to struct prefix. */
2543 ret = str2prefix(prefix, &range);
2544 if (!ret) {
2545 vty_out(vty, "%% Malformed listen range\n");
2546 return CMD_WARNING_CONFIG_FAILED;
2547 }
2548
2549 afi = family2afi(range.family);
2550
2551 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2552 vty_out(vty,
2553 "%% Malformed listen range (link-local address)\n");
2554 return CMD_WARNING_CONFIG_FAILED;
2555 }
2556
2557 apply_mask(&range);
2558
2559 /* Check if same listen range is already configured. */
2560 existing_group = listen_range_exists(bgp, &range, 1);
2561 if (existing_group) {
2562 if (strcmp(existing_group->name, peergroup) == 0)
2563 return CMD_SUCCESS;
2564 else {
2565 vty_out(vty,
2566 "%% Same listen range is attached to peer-group %s\n",
2567 existing_group->name);
2568 return CMD_WARNING_CONFIG_FAILED;
2569 }
2570 }
2571
2572 /* Check if an overlapping listen range exists. */
2573 if (listen_range_exists(bgp, &range, 0)) {
2574 vty_out(vty,
2575 "%% Listen range overlaps with existing listen range\n");
2576 return CMD_WARNING_CONFIG_FAILED;
2577 }
2578
2579 group = peer_group_lookup(bgp, peergroup);
2580 if (!group) {
2581 vty_out(vty, "%% Configure the peer-group first\n");
2582 return CMD_WARNING_CONFIG_FAILED;
2583 }
2584
2585 ret = peer_group_listen_range_add(group, &range);
2586 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2587}
2588
2589DEFUN (no_bgp_listen_range,
2590 no_bgp_listen_range_cmd,
d7fa34c1
QY
2591 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2592 NO_STR
f14e6fdb 2593 "BGP specific commands\n"
d7fa34c1
QY
2594 "Unconfigure BGP dynamic neighbors listen range\n"
2595 "Unconfigure BGP dynamic neighbors listen range\n"
2596 NEIGHBOR_ADDR_STR
2597 "Member of the peer-group\n"
2598 "Peer-group name\n")
f14e6fdb 2599{
d62a17ae 2600 VTY_DECLVAR_CONTEXT(bgp, bgp);
2601 struct prefix range;
2602 struct peer_group *group;
2603 afi_t afi;
2604 int ret;
2605 int idx = 0;
2606
2607 argv_find(argv, argc, "A.B.C.D/M", &idx);
2608 argv_find(argv, argc, "X:X::X:X/M", &idx);
2609 char *prefix = argv[idx]->arg;
2610 argv_find(argv, argc, "WORD", &idx);
2611 char *peergroup = argv[idx]->arg;
2612
2613 /* Convert IP prefix string to struct prefix. */
2614 ret = str2prefix(prefix, &range);
2615 if (!ret) {
2616 vty_out(vty, "%% Malformed listen range\n");
2617 return CMD_WARNING_CONFIG_FAILED;
2618 }
2619
2620 afi = family2afi(range.family);
2621
2622 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2623 vty_out(vty,
2624 "%% Malformed listen range (link-local address)\n");
2625 return CMD_WARNING_CONFIG_FAILED;
2626 }
2627
2628 apply_mask(&range);
2629
2630 group = peer_group_lookup(bgp, peergroup);
2631 if (!group) {
2632 vty_out(vty, "%% Peer-group does not exist\n");
2633 return CMD_WARNING_CONFIG_FAILED;
2634 }
2635
2636 ret = peer_group_listen_range_del(group, &range);
2637 return bgp_vty_return(vty, ret);
2638}
2639
2b791107 2640void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2641{
2642 struct peer_group *group;
2643 struct listnode *node, *nnode, *rnode, *nrnode;
2644 struct prefix *range;
2645 afi_t afi;
2646 char buf[PREFIX2STR_BUFFER];
2647
2648 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2649 vty_out(vty, " bgp listen limit %d\n",
2650 bgp->dynamic_neighbors_limit);
2651
2652 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2653 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2654 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2655 nrnode, range)) {
2656 prefix2str(range, buf, sizeof(buf));
2657 vty_out(vty,
2658 " bgp listen range %s peer-group %s\n",
2659 buf, group->name);
2660 }
2661 }
2662 }
f14e6fdb
DS
2663}
2664
2665
907f92c8
DS
2666DEFUN (bgp_disable_connected_route_check,
2667 bgp_disable_connected_route_check_cmd,
2668 "bgp disable-ebgp-connected-route-check",
2669 "BGP specific commands\n"
2670 "Disable checking if nexthop is connected on ebgp sessions\n")
2671{
d62a17ae 2672 VTY_DECLVAR_CONTEXT(bgp, bgp);
2673 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2674 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2675
d62a17ae 2676 return CMD_SUCCESS;
907f92c8
DS
2677}
2678
2679DEFUN (no_bgp_disable_connected_route_check,
2680 no_bgp_disable_connected_route_check_cmd,
2681 "no bgp disable-ebgp-connected-route-check",
2682 NO_STR
2683 "BGP specific commands\n"
2684 "Disable checking if nexthop is connected on ebgp sessions\n")
2685{
d62a17ae 2686 VTY_DECLVAR_CONTEXT(bgp, bgp);
2687 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2688 bgp_clear_star_soft_in(vty, bgp->name);
2689
2690 return CMD_SUCCESS;
2691}
2692
2693
2694static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2695 const char *as_str, afi_t afi, safi_t safi)
2696{
2697 VTY_DECLVAR_CONTEXT(bgp, bgp);
2698 int ret;
2699 as_t as;
2700 int as_type = AS_SPECIFIED;
2701 union sockunion su;
2702
2703 if (as_str[0] == 'i') {
2704 as = 0;
2705 as_type = AS_INTERNAL;
2706 } else if (as_str[0] == 'e') {
2707 as = 0;
2708 as_type = AS_EXTERNAL;
2709 } else {
2710 /* Get AS number. */
2711 as = strtoul(as_str, NULL, 10);
2712 }
2713
2714 /* If peer is peer group, call proper function. */
2715 ret = str2sockunion(peer_str, &su);
2716 if (ret < 0) {
2717 /* Check for peer by interface */
2718 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2719 safi);
2720 if (ret < 0) {
2721 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2722 if (ret < 0) {
2723 vty_out(vty,
2724 "%% Create the peer-group or interface first\n");
2725 return CMD_WARNING_CONFIG_FAILED;
2726 }
2727 return CMD_SUCCESS;
2728 }
2729 } else {
2730 if (peer_address_self_check(bgp, &su)) {
2731 vty_out(vty,
2732 "%% Can not configure the local system as neighbor\n");
2733 return CMD_WARNING_CONFIG_FAILED;
2734 }
2735 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2736 }
2737
2738 /* This peer belongs to peer group. */
2739 switch (ret) {
2740 case BGP_ERR_PEER_GROUP_MEMBER:
2741 vty_out(vty,
2742 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2743 as);
2744 return CMD_WARNING_CONFIG_FAILED;
2745 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2746 vty_out(vty,
2747 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2748 as, as_str);
2749 return CMD_WARNING_CONFIG_FAILED;
2750 }
2751 return bgp_vty_return(vty, ret);
718e3744 2752}
2753
f26845f9
QY
2754DEFUN (bgp_default_shutdown,
2755 bgp_default_shutdown_cmd,
2756 "[no] bgp default shutdown",
2757 NO_STR
2758 BGP_STR
2759 "Configure BGP defaults\n"
b012cbe2 2760 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2761{
2762 VTY_DECLVAR_CONTEXT(bgp, bgp);
2763 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2764 return CMD_SUCCESS;
2765}
2766
718e3744 2767DEFUN (neighbor_remote_as,
2768 neighbor_remote_as_cmd,
3a2d747c 2769 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2770 NEIGHBOR_STR
2771 NEIGHBOR_ADDR_STR2
2772 "Specify a BGP neighbor\n"
d7fa34c1 2773 AS_STR
3a2d747c
QY
2774 "Internal BGP peer\n"
2775 "External BGP peer\n")
718e3744 2776{
d62a17ae 2777 int idx_peer = 1;
2778 int idx_remote_as = 3;
2779 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2780 argv[idx_remote_as]->arg, AFI_IP,
2781 SAFI_UNICAST);
2782}
2783
2784static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2785 afi_t afi, safi_t safi, int v6only,
2786 const char *peer_group_name,
2787 const char *as_str)
2788{
2789 VTY_DECLVAR_CONTEXT(bgp, bgp);
2790 as_t as = 0;
2791 int as_type = AS_UNSPECIFIED;
2792 struct peer *peer;
2793 struct peer_group *group;
2794 int ret = 0;
2795 union sockunion su;
2796
2797 group = peer_group_lookup(bgp, conf_if);
2798
2799 if (group) {
2800 vty_out(vty, "%% Name conflict with peer-group \n");
2801 return CMD_WARNING_CONFIG_FAILED;
2802 }
2803
2804 if (as_str) {
2805 if (as_str[0] == 'i') {
2806 as_type = AS_INTERNAL;
2807 } else if (as_str[0] == 'e') {
2808 as_type = AS_EXTERNAL;
2809 } else {
2810 /* Get AS number. */
2811 as = strtoul(as_str, NULL, 10);
2812 as_type = AS_SPECIFIED;
2813 }
2814 }
2815
2816 peer = peer_lookup_by_conf_if(bgp, conf_if);
2817 if (peer) {
2818 if (as_str)
2819 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2820 afi, safi);
2821 } else {
2822 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2823 && afi == AFI_IP && safi == SAFI_UNICAST)
2824 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2825 as_type, 0, 0, NULL);
2826 else
2827 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2828 as_type, afi, safi, NULL);
2829
2830 if (!peer) {
2831 vty_out(vty, "%% BGP failed to create peer\n");
2832 return CMD_WARNING_CONFIG_FAILED;
2833 }
2834
2835 if (v6only)
527de3dc 2836 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2837
2838 /* Request zebra to initiate IPv6 RAs on this interface. We do
2839 * this
2840 * any unnumbered peer in order to not worry about run-time
2841 * transitions
2842 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2843 * address
2844 * gets deleted later etc.)
2845 */
2846 if (peer->ifp)
2847 bgp_zebra_initiate_radv(bgp, peer);
2848 }
2849
2850 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2851 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2852 if (v6only)
527de3dc 2853 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2854 else
527de3dc 2855 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2856
2857 /* v6only flag changed. Reset bgp seesion */
2858 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2859 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2860 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2861 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2862 } else
2863 bgp_session_reset(peer);
2864 }
2865
9fb964de
PM
2866 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2867 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2868 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2869 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2870 }
d62a17ae 2871
2872 if (peer_group_name) {
2873 group = peer_group_lookup(bgp, peer_group_name);
2874 if (!group) {
2875 vty_out(vty, "%% Configure the peer-group first\n");
2876 return CMD_WARNING_CONFIG_FAILED;
2877 }
2878
2879 ret = peer_group_bind(bgp, &su, peer, group, &as);
2880 }
2881
2882 return bgp_vty_return(vty, ret);
a80beece
DS
2883}
2884
4c48cf63
DW
2885DEFUN (neighbor_interface_config,
2886 neighbor_interface_config_cmd,
31500417 2887 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2888 NEIGHBOR_STR
2889 "Interface name or neighbor tag\n"
31500417
DW
2890 "Enable BGP on interface\n"
2891 "Member of the peer-group\n"
16cedbb0 2892 "Peer-group name\n")
4c48cf63 2893{
d62a17ae 2894 int idx_word = 1;
2895 int idx_peer_group_word = 4;
31500417 2896
d62a17ae 2897 if (argc > idx_peer_group_word)
2898 return peer_conf_interface_get(
2899 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2900 argv[idx_peer_group_word]->arg, NULL);
2901 else
2902 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2903 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2904}
2905
4c48cf63
DW
2906DEFUN (neighbor_interface_config_v6only,
2907 neighbor_interface_config_v6only_cmd,
31500417 2908 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2909 NEIGHBOR_STR
2910 "Interface name or neighbor tag\n"
2911 "Enable BGP on interface\n"
31500417
DW
2912 "Enable BGP with v6 link-local only\n"
2913 "Member of the peer-group\n"
16cedbb0 2914 "Peer-group name\n")
4c48cf63 2915{
d62a17ae 2916 int idx_word = 1;
2917 int idx_peer_group_word = 5;
31500417 2918
d62a17ae 2919 if (argc > idx_peer_group_word)
2920 return peer_conf_interface_get(
2921 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2922 argv[idx_peer_group_word]->arg, NULL);
31500417 2923
d62a17ae 2924 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2925 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2926}
2927
a80beece 2928
b3a39dc5
DD
2929DEFUN (neighbor_interface_config_remote_as,
2930 neighbor_interface_config_remote_as_cmd,
3a2d747c 2931 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2932 NEIGHBOR_STR
2933 "Interface name or neighbor tag\n"
2934 "Enable BGP on interface\n"
3a2d747c 2935 "Specify a BGP neighbor\n"
d7fa34c1 2936 AS_STR
3a2d747c
QY
2937 "Internal BGP peer\n"
2938 "External BGP peer\n")
b3a39dc5 2939{
d62a17ae 2940 int idx_word = 1;
2941 int idx_remote_as = 4;
2942 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2943 SAFI_UNICAST, 0, NULL,
2944 argv[idx_remote_as]->arg);
b3a39dc5
DD
2945}
2946
2947DEFUN (neighbor_interface_v6only_config_remote_as,
2948 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2949 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2950 NEIGHBOR_STR
2951 "Interface name or neighbor tag\n"
3a2d747c 2952 "Enable BGP with v6 link-local only\n"
b3a39dc5 2953 "Enable BGP on interface\n"
3a2d747c 2954 "Specify a BGP neighbor\n"
d7fa34c1 2955 AS_STR
3a2d747c
QY
2956 "Internal BGP peer\n"
2957 "External BGP peer\n")
b3a39dc5 2958{
d62a17ae 2959 int idx_word = 1;
2960 int idx_remote_as = 5;
2961 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2962 SAFI_UNICAST, 1, NULL,
2963 argv[idx_remote_as]->arg);
b3a39dc5
DD
2964}
2965
718e3744 2966DEFUN (neighbor_peer_group,
2967 neighbor_peer_group_cmd,
2968 "neighbor WORD peer-group",
2969 NEIGHBOR_STR
a80beece 2970 "Interface name or neighbor tag\n"
718e3744 2971 "Configure peer-group\n")
2972{
d62a17ae 2973 VTY_DECLVAR_CONTEXT(bgp, bgp);
2974 int idx_word = 1;
2975 struct peer *peer;
2976 struct peer_group *group;
718e3744 2977
d62a17ae 2978 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2979 if (peer) {
2980 vty_out(vty, "%% Name conflict with interface: \n");
2981 return CMD_WARNING_CONFIG_FAILED;
2982 }
718e3744 2983
d62a17ae 2984 group = peer_group_get(bgp, argv[idx_word]->arg);
2985 if (!group) {
2986 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2987 return CMD_WARNING_CONFIG_FAILED;
2988 }
718e3744 2989
d62a17ae 2990 return CMD_SUCCESS;
718e3744 2991}
2992
2993DEFUN (no_neighbor,
2994 no_neighbor_cmd,
dab8cd00 2995 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 2996 NO_STR
2997 NEIGHBOR_STR
3a2d747c
QY
2998 NEIGHBOR_ADDR_STR2
2999 "Specify a BGP neighbor\n"
3000 AS_STR
3001 "Internal BGP peer\n"
3002 "External BGP peer\n")
718e3744 3003{
d62a17ae 3004 VTY_DECLVAR_CONTEXT(bgp, bgp);
3005 int idx_peer = 2;
3006 int ret;
3007 union sockunion su;
3008 struct peer_group *group;
3009 struct peer *peer;
3010 struct peer *other;
3011
3012 ret = str2sockunion(argv[idx_peer]->arg, &su);
3013 if (ret < 0) {
3014 /* look up for neighbor by interface name config. */
3015 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3016 if (peer) {
3017 /* Request zebra to terminate IPv6 RAs on this
3018 * interface. */
3019 if (peer->ifp)
3020 bgp_zebra_terminate_radv(peer->bgp, peer);
3021 peer_delete(peer);
3022 return CMD_SUCCESS;
3023 }
f14e6fdb 3024
d62a17ae 3025 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3026 if (group)
3027 peer_group_delete(group);
3028 else {
3029 vty_out(vty, "%% Create the peer-group first\n");
3030 return CMD_WARNING_CONFIG_FAILED;
3031 }
3032 } else {
3033 peer = peer_lookup(bgp, &su);
3034 if (peer) {
3035 if (peer_dynamic_neighbor(peer)) {
3036 vty_out(vty,
3037 "%% Operation not allowed on a dynamic neighbor\n");
3038 return CMD_WARNING_CONFIG_FAILED;
3039 }
3040
3041 other = peer->doppelganger;
3042 peer_delete(peer);
3043 if (other && other->status != Deleted)
3044 peer_delete(other);
3045 }
1ff9a340 3046 }
718e3744 3047
d62a17ae 3048 return CMD_SUCCESS;
718e3744 3049}
3050
a80beece
DS
3051DEFUN (no_neighbor_interface_config,
3052 no_neighbor_interface_config_cmd,
31500417 3053 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3054 NO_STR
3055 NEIGHBOR_STR
3056 "Interface name\n"
31500417
DW
3057 "Configure BGP on interface\n"
3058 "Enable BGP with v6 link-local only\n"
3059 "Member of the peer-group\n"
16cedbb0 3060 "Peer-group name\n"
3a2d747c
QY
3061 "Specify a BGP neighbor\n"
3062 AS_STR
3063 "Internal BGP peer\n"
3064 "External BGP peer\n")
a80beece 3065{
d62a17ae 3066 VTY_DECLVAR_CONTEXT(bgp, bgp);
3067 int idx_word = 2;
3068 struct peer *peer;
3069
3070 /* look up for neighbor by interface name config. */
3071 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3072 if (peer) {
3073 /* Request zebra to terminate IPv6 RAs on this interface. */
3074 if (peer->ifp)
3075 bgp_zebra_terminate_radv(peer->bgp, peer);
3076 peer_delete(peer);
3077 } else {
3078 vty_out(vty, "%% Create the bgp interface first\n");
3079 return CMD_WARNING_CONFIG_FAILED;
3080 }
3081 return CMD_SUCCESS;
a80beece
DS
3082}
3083
718e3744 3084DEFUN (no_neighbor_peer_group,
3085 no_neighbor_peer_group_cmd,
3086 "no neighbor WORD peer-group",
3087 NO_STR
3088 NEIGHBOR_STR
3089 "Neighbor tag\n"
3090 "Configure peer-group\n")
3091{
d62a17ae 3092 VTY_DECLVAR_CONTEXT(bgp, bgp);
3093 int idx_word = 2;
3094 struct peer_group *group;
718e3744 3095
d62a17ae 3096 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3097 if (group)
3098 peer_group_delete(group);
3099 else {
3100 vty_out(vty, "%% Create the peer-group first\n");
3101 return CMD_WARNING_CONFIG_FAILED;
3102 }
3103 return CMD_SUCCESS;
718e3744 3104}
3105
a80beece
DS
3106DEFUN (no_neighbor_interface_peer_group_remote_as,
3107 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3108 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3109 NO_STR
3110 NEIGHBOR_STR
a80beece 3111 "Interface name or neighbor tag\n"
718e3744 3112 "Specify a BGP neighbor\n"
3a2d747c
QY
3113 AS_STR
3114 "Internal BGP peer\n"
3115 "External BGP peer\n")
718e3744 3116{
d62a17ae 3117 VTY_DECLVAR_CONTEXT(bgp, bgp);
3118 int idx_word = 2;
3119 struct peer_group *group;
3120 struct peer *peer;
3121
3122 /* look up for neighbor by interface name config. */
3123 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3124 if (peer) {
3125 peer_as_change(peer, 0, AS_SPECIFIED);
3126 return CMD_SUCCESS;
3127 }
3128
3129 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3130 if (group)
3131 peer_group_remote_as_delete(group);
3132 else {
3133 vty_out(vty, "%% Create the peer-group or interface first\n");
3134 return CMD_WARNING_CONFIG_FAILED;
3135 }
3136 return CMD_SUCCESS;
718e3744 3137}
6b0655a2 3138
718e3744 3139DEFUN (neighbor_local_as,
3140 neighbor_local_as_cmd,
9ccf14f7 3141 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3142 NEIGHBOR_STR
3143 NEIGHBOR_ADDR_STR2
3144 "Specify a local-as number\n"
3145 "AS number used as local AS\n")
3146{
d62a17ae 3147 int idx_peer = 1;
3148 int idx_number = 3;
3149 struct peer *peer;
3150 int ret;
3151 as_t as;
718e3744 3152
d62a17ae 3153 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3154 if (!peer)
3155 return CMD_WARNING_CONFIG_FAILED;
718e3744 3156
d62a17ae 3157 as = strtoul(argv[idx_number]->arg, NULL, 10);
3158 ret = peer_local_as_set(peer, as, 0, 0);
3159 return bgp_vty_return(vty, ret);
718e3744 3160}
3161
3162DEFUN (neighbor_local_as_no_prepend,
3163 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3164 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3165 NEIGHBOR_STR
3166 NEIGHBOR_ADDR_STR2
3167 "Specify a local-as number\n"
3168 "AS number used as local AS\n"
3169 "Do not prepend local-as to updates from ebgp peers\n")
3170{
d62a17ae 3171 int idx_peer = 1;
3172 int idx_number = 3;
3173 struct peer *peer;
3174 int ret;
3175 as_t as;
718e3744 3176
d62a17ae 3177 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3178 if (!peer)
3179 return CMD_WARNING_CONFIG_FAILED;
718e3744 3180
d62a17ae 3181 as = strtoul(argv[idx_number]->arg, NULL, 10);
3182 ret = peer_local_as_set(peer, as, 1, 0);
3183 return bgp_vty_return(vty, ret);
718e3744 3184}
3185
9d3f9705
AC
3186DEFUN (neighbor_local_as_no_prepend_replace_as,
3187 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3188 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3189 NEIGHBOR_STR
3190 NEIGHBOR_ADDR_STR2
3191 "Specify a local-as number\n"
3192 "AS number used as local AS\n"
3193 "Do not prepend local-as to updates from ebgp peers\n"
3194 "Do not prepend local-as to updates from ibgp peers\n")
3195{
d62a17ae 3196 int idx_peer = 1;
3197 int idx_number = 3;
3198 struct peer *peer;
3199 int ret;
3200 as_t as;
9d3f9705 3201
d62a17ae 3202 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3203 if (!peer)
3204 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3205
d62a17ae 3206 as = strtoul(argv[idx_number]->arg, NULL, 10);
3207 ret = peer_local_as_set(peer, as, 1, 1);
3208 return bgp_vty_return(vty, ret);
9d3f9705
AC
3209}
3210
718e3744 3211DEFUN (no_neighbor_local_as,
3212 no_neighbor_local_as_cmd,
a636c635 3213 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3214 NO_STR
3215 NEIGHBOR_STR
3216 NEIGHBOR_ADDR_STR2
a636c635
DW
3217 "Specify a local-as number\n"
3218 "AS number used as local AS\n"
3219 "Do not prepend local-as to updates from ebgp peers\n"
3220 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3221{
d62a17ae 3222 int idx_peer = 2;
3223 struct peer *peer;
3224 int ret;
718e3744 3225
d62a17ae 3226 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3227 if (!peer)
3228 return CMD_WARNING_CONFIG_FAILED;
718e3744 3229
d62a17ae 3230 ret = peer_local_as_unset(peer);
3231 return bgp_vty_return(vty, ret);
718e3744 3232}
3233
718e3744 3234
3f9c7369
DS
3235DEFUN (neighbor_solo,
3236 neighbor_solo_cmd,
9ccf14f7 3237 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3238 NEIGHBOR_STR
3239 NEIGHBOR_ADDR_STR2
3240 "Solo peer - part of its own update group\n")
3241{
d62a17ae 3242 int idx_peer = 1;
3243 struct peer *peer;
3244 int ret;
3f9c7369 3245
d62a17ae 3246 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3247 if (!peer)
3248 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3249
d62a17ae 3250 ret = update_group_adjust_soloness(peer, 1);
3251 return bgp_vty_return(vty, ret);
3f9c7369
DS
3252}
3253
3254DEFUN (no_neighbor_solo,
3255 no_neighbor_solo_cmd,
9ccf14f7 3256 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3257 NO_STR
3258 NEIGHBOR_STR
3259 NEIGHBOR_ADDR_STR2
3260 "Solo peer - part of its own update group\n")
3261{
d62a17ae 3262 int idx_peer = 2;
3263 struct peer *peer;
3264 int ret;
3f9c7369 3265
d62a17ae 3266 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3267 if (!peer)
3268 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3269
d62a17ae 3270 ret = update_group_adjust_soloness(peer, 0);
3271 return bgp_vty_return(vty, ret);
3f9c7369
DS
3272}
3273
0df7c91f
PJ
3274DEFUN (neighbor_password,
3275 neighbor_password_cmd,
9ccf14f7 3276 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3277 NEIGHBOR_STR
3278 NEIGHBOR_ADDR_STR2
3279 "Set a password\n"
3280 "The password\n")
3281{
d62a17ae 3282 int idx_peer = 1;
3283 int idx_line = 3;
3284 struct peer *peer;
3285 int ret;
0df7c91f 3286
d62a17ae 3287 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3288 if (!peer)
3289 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3290
d62a17ae 3291 ret = peer_password_set(peer, argv[idx_line]->arg);
3292 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3293}
3294
3295DEFUN (no_neighbor_password,
3296 no_neighbor_password_cmd,
a636c635 3297 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3298 NO_STR
3299 NEIGHBOR_STR
3300 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3301 "Set a password\n"
3302 "The password\n")
0df7c91f 3303{
d62a17ae 3304 int idx_peer = 2;
3305 struct peer *peer;
3306 int ret;
0df7c91f 3307
d62a17ae 3308 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3309 if (!peer)
3310 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3311
d62a17ae 3312 ret = peer_password_unset(peer);
3313 return bgp_vty_return(vty, ret);
0df7c91f 3314}
6b0655a2 3315
718e3744 3316DEFUN (neighbor_activate,
3317 neighbor_activate_cmd,
9ccf14f7 3318 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3319 NEIGHBOR_STR
3320 NEIGHBOR_ADDR_STR2
3321 "Enable the Address Family for this Neighbor\n")
3322{
d62a17ae 3323 int idx_peer = 1;
3324 int ret;
3325 struct peer *peer;
718e3744 3326
d62a17ae 3327 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3328 if (!peer)
3329 return CMD_WARNING_CONFIG_FAILED;
718e3744 3330
d62a17ae 3331 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3332 return bgp_vty_return(vty, ret);
718e3744 3333}
3334
d62a17ae 3335ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3336 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3337 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3338 "Enable the Address Family for this Neighbor\n")
596c17ba 3339
718e3744 3340DEFUN (no_neighbor_activate,
3341 no_neighbor_activate_cmd,
9ccf14f7 3342 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3343 NO_STR
3344 NEIGHBOR_STR
3345 NEIGHBOR_ADDR_STR2
3346 "Enable the Address Family for this Neighbor\n")
3347{
d62a17ae 3348 int idx_peer = 2;
3349 int ret;
3350 struct peer *peer;
718e3744 3351
d62a17ae 3352 /* Lookup peer. */
3353 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3354 if (!peer)
3355 return CMD_WARNING_CONFIG_FAILED;
718e3744 3356
d62a17ae 3357 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3358 return bgp_vty_return(vty, ret);
718e3744 3359}
6b0655a2 3360
d62a17ae 3361ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3362 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3363 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3364 "Enable the Address Family for this Neighbor\n")
596c17ba 3365
718e3744 3366DEFUN (neighbor_set_peer_group,
3367 neighbor_set_peer_group_cmd,
9ccf14f7 3368 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3369 NEIGHBOR_STR
a80beece 3370 NEIGHBOR_ADDR_STR2
718e3744 3371 "Member of the peer-group\n"
16cedbb0 3372 "Peer-group name\n")
718e3744 3373{
d62a17ae 3374 VTY_DECLVAR_CONTEXT(bgp, bgp);
3375 int idx_peer = 1;
3376 int idx_word = 3;
3377 int ret;
3378 as_t as;
3379 union sockunion su;
3380 struct peer *peer;
3381 struct peer_group *group;
3382
d62a17ae 3383 ret = str2sockunion(argv[idx_peer]->arg, &su);
3384 if (ret < 0) {
3385 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3386 if (!peer) {
3387 vty_out(vty, "%% Malformed address or name: %s\n",
3388 argv[idx_peer]->arg);
3389 return CMD_WARNING_CONFIG_FAILED;
3390 }
3391 } else {
3392 if (peer_address_self_check(bgp, &su)) {
3393 vty_out(vty,
3394 "%% Can not configure the local system as neighbor\n");
3395 return CMD_WARNING_CONFIG_FAILED;
3396 }
3397
3398 /* Disallow for dynamic neighbor. */
3399 peer = peer_lookup(bgp, &su);
3400 if (peer && peer_dynamic_neighbor(peer)) {
3401 vty_out(vty,
3402 "%% Operation not allowed on a dynamic neighbor\n");
3403 return CMD_WARNING_CONFIG_FAILED;
3404 }
3405 }
3406
3407 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3408 if (!group) {
3409 vty_out(vty, "%% Configure the peer-group first\n");
3410 return CMD_WARNING_CONFIG_FAILED;
3411 }
3412
3413 ret = peer_group_bind(bgp, &su, peer, group, &as);
3414
3415 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3416 vty_out(vty,
3417 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3418 as);
3419 return CMD_WARNING_CONFIG_FAILED;
3420 }
3421
3422 return bgp_vty_return(vty, ret);
3423}
3424
3425ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3426 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3427 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3428 "Member of the peer-group\n"
3429 "Peer-group name\n")
596c17ba 3430
718e3744 3431DEFUN (no_neighbor_set_peer_group,
3432 no_neighbor_set_peer_group_cmd,
9ccf14f7 3433 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3434 NO_STR
3435 NEIGHBOR_STR
a80beece 3436 NEIGHBOR_ADDR_STR2
718e3744 3437 "Member of the peer-group\n"
16cedbb0 3438 "Peer-group name\n")
718e3744 3439{
d62a17ae 3440 VTY_DECLVAR_CONTEXT(bgp, bgp);
3441 int idx_peer = 2;
3442 int idx_word = 4;
3443 int ret;
3444 struct peer *peer;
3445 struct peer_group *group;
3446
3447 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3448 if (!peer)
3449 return CMD_WARNING_CONFIG_FAILED;
3450
3451 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3452 if (!group) {
3453 vty_out(vty, "%% Configure the peer-group first\n");
3454 return CMD_WARNING_CONFIG_FAILED;
3455 }
718e3744 3456
827ed707 3457 ret = peer_delete(peer);
718e3744 3458
d62a17ae 3459 return bgp_vty_return(vty, ret);
718e3744 3460}
6b0655a2 3461
d62a17ae 3462ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3463 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3464 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3465 "Member of the peer-group\n"
3466 "Peer-group name\n")
596c17ba 3467
d62a17ae 3468static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3469 uint32_t flag, int set)
718e3744 3470{
d62a17ae 3471 int ret;
3472 struct peer *peer;
718e3744 3473
d62a17ae 3474 peer = peer_and_group_lookup_vty(vty, ip_str);
3475 if (!peer)
3476 return CMD_WARNING_CONFIG_FAILED;
718e3744 3477
7ebe625c
QY
3478 /*
3479 * If 'neighbor <interface>', then this is for directly connected peers,
3480 * we should not accept disable-connected-check.
3481 */
3482 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3483 vty_out(vty,
3484 "%s is directly connected peer, cannot accept disable-"
3485 "connected-check\n",
3486 ip_str);
3487 return CMD_WARNING_CONFIG_FAILED;
3488 }
3489
d62a17ae 3490 if (!set && flag == PEER_FLAG_SHUTDOWN)
3491 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3492
d62a17ae 3493 if (set)
3494 ret = peer_flag_set(peer, flag);
3495 else
3496 ret = peer_flag_unset(peer, flag);
718e3744 3497
d62a17ae 3498 return bgp_vty_return(vty, ret);
718e3744 3499}
3500
47cbc09b 3501static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3502{
d62a17ae 3503 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3504}
3505
d62a17ae 3506static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3507 uint32_t flag)
718e3744 3508{
d62a17ae 3509 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3510}
3511
3512/* neighbor passive. */
3513DEFUN (neighbor_passive,
3514 neighbor_passive_cmd,
9ccf14f7 3515 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3516 NEIGHBOR_STR
3517 NEIGHBOR_ADDR_STR2
3518 "Don't send open messages to this neighbor\n")
3519{
d62a17ae 3520 int idx_peer = 1;
3521 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3522}
3523
3524DEFUN (no_neighbor_passive,
3525 no_neighbor_passive_cmd,
9ccf14f7 3526 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3527 NO_STR
3528 NEIGHBOR_STR
3529 NEIGHBOR_ADDR_STR2
3530 "Don't send open messages to this neighbor\n")
3531{
d62a17ae 3532 int idx_peer = 2;
3533 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3534}
6b0655a2 3535
718e3744 3536/* neighbor shutdown. */
73d70fa6
DL
3537DEFUN (neighbor_shutdown_msg,
3538 neighbor_shutdown_msg_cmd,
3539 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3540 NEIGHBOR_STR
3541 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3542 "Administratively shut down this neighbor\n"
3543 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3544 "Shutdown message\n")
718e3744 3545{
d62a17ae 3546 int idx_peer = 1;
73d70fa6 3547
d62a17ae 3548 if (argc >= 5) {
3549 struct peer *peer =
3550 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3551 char *message;
73d70fa6 3552
d62a17ae 3553 if (!peer)
3554 return CMD_WARNING_CONFIG_FAILED;
3555 message = argv_concat(argv, argc, 4);
3556 peer_tx_shutdown_message_set(peer, message);
3557 XFREE(MTYPE_TMP, message);
3558 }
73d70fa6 3559
d62a17ae 3560 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3561}
3562
d62a17ae 3563ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3564 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3565 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3566 "Administratively shut down this neighbor\n")
73d70fa6
DL
3567
3568DEFUN (no_neighbor_shutdown_msg,
3569 no_neighbor_shutdown_msg_cmd,
3570 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3571 NO_STR
3572 NEIGHBOR_STR
3573 NEIGHBOR_ADDR_STR2
3574 "Administratively shut down this neighbor\n"
3575 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3576 "Shutdown message\n")
718e3744 3577{
d62a17ae 3578 int idx_peer = 2;
73d70fa6 3579
d62a17ae 3580 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3581 PEER_FLAG_SHUTDOWN);
718e3744 3582}
6b0655a2 3583
d62a17ae 3584ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3585 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3586 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3587 "Administratively shut down this neighbor\n")
73d70fa6 3588
718e3744 3589/* neighbor capability dynamic. */
3590DEFUN (neighbor_capability_dynamic,
3591 neighbor_capability_dynamic_cmd,
9ccf14f7 3592 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3593 NEIGHBOR_STR
3594 NEIGHBOR_ADDR_STR2
3595 "Advertise capability to the peer\n"
3596 "Advertise dynamic capability to this neighbor\n")
3597{
d62a17ae 3598 int idx_peer = 1;
3599 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3600 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3601}
3602
3603DEFUN (no_neighbor_capability_dynamic,
3604 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3605 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3606 NO_STR
3607 NEIGHBOR_STR
3608 NEIGHBOR_ADDR_STR2
3609 "Advertise capability to the peer\n"
3610 "Advertise dynamic capability to this neighbor\n")
3611{
d62a17ae 3612 int idx_peer = 2;
3613 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3614 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3615}
6b0655a2 3616
718e3744 3617/* neighbor dont-capability-negotiate */
3618DEFUN (neighbor_dont_capability_negotiate,
3619 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3620 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3621 NEIGHBOR_STR
3622 NEIGHBOR_ADDR_STR2
3623 "Do not perform capability negotiation\n")
3624{
d62a17ae 3625 int idx_peer = 1;
3626 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3627 PEER_FLAG_DONT_CAPABILITY);
718e3744 3628}
3629
3630DEFUN (no_neighbor_dont_capability_negotiate,
3631 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3632 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3633 NO_STR
3634 NEIGHBOR_STR
3635 NEIGHBOR_ADDR_STR2
3636 "Do not perform capability negotiation\n")
3637{
d62a17ae 3638 int idx_peer = 2;
3639 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3640 PEER_FLAG_DONT_CAPABILITY);
718e3744 3641}
6b0655a2 3642
8a92a8a0
DS
3643/* neighbor capability extended next hop encoding */
3644DEFUN (neighbor_capability_enhe,
3645 neighbor_capability_enhe_cmd,
9ccf14f7 3646 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3647 NEIGHBOR_STR
3648 NEIGHBOR_ADDR_STR2
3649 "Advertise capability to the peer\n"
3650 "Advertise extended next-hop capability to the peer\n")
3651{
d62a17ae 3652 int idx_peer = 1;
3653 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3654 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3655}
3656
3657DEFUN (no_neighbor_capability_enhe,
3658 no_neighbor_capability_enhe_cmd,
9ccf14f7 3659 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3660 NO_STR
3661 NEIGHBOR_STR
3662 NEIGHBOR_ADDR_STR2
3663 "Advertise capability to the peer\n"
3664 "Advertise extended next-hop capability to the peer\n")
3665{
d62a17ae 3666 int idx_peer = 2;
3667 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3668 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3669}
3670
d62a17ae 3671static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3672 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3673 int set)
718e3744 3674{
d62a17ae 3675 int ret;
3676 struct peer *peer;
718e3744 3677
d62a17ae 3678 peer = peer_and_group_lookup_vty(vty, peer_str);
3679 if (!peer)
3680 return CMD_WARNING_CONFIG_FAILED;
718e3744 3681
d62a17ae 3682 if (set)
3683 ret = peer_af_flag_set(peer, afi, safi, flag);
3684 else
3685 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3686
d62a17ae 3687 return bgp_vty_return(vty, ret);
718e3744 3688}
3689
d62a17ae 3690static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3691 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3692{
d62a17ae 3693 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3694}
3695
d62a17ae 3696static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3697 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3698{
d62a17ae 3699 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3700}
6b0655a2 3701
718e3744 3702/* neighbor capability orf prefix-list. */
3703DEFUN (neighbor_capability_orf_prefix,
3704 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3705 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3706 NEIGHBOR_STR
3707 NEIGHBOR_ADDR_STR2
3708 "Advertise capability to the peer\n"
3709 "Advertise ORF capability to the peer\n"
3710 "Advertise prefixlist ORF capability to this neighbor\n"
3711 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3712 "Capability to RECEIVE the ORF from this neighbor\n"
3713 "Capability to SEND the ORF to this neighbor\n")
3714{
d62a17ae 3715 int idx_peer = 1;
3716 int idx_send_recv = 5;
d7c0a89a 3717 uint16_t flag = 0;
d62a17ae 3718
3719 if (strmatch(argv[idx_send_recv]->text, "send"))
3720 flag = PEER_FLAG_ORF_PREFIX_SM;
3721 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3722 flag = PEER_FLAG_ORF_PREFIX_RM;
3723 else if (strmatch(argv[idx_send_recv]->text, "both"))
3724 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3725 else {
3726 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3727 return CMD_WARNING_CONFIG_FAILED;
3728 }
3729
3730 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3731 bgp_node_safi(vty), flag);
3732}
3733
3734ALIAS_HIDDEN(
3735 neighbor_capability_orf_prefix,
3736 neighbor_capability_orf_prefix_hidden_cmd,
3737 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3738 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3739 "Advertise capability to the peer\n"
3740 "Advertise ORF capability to the peer\n"
3741 "Advertise prefixlist ORF capability to this neighbor\n"
3742 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3743 "Capability to RECEIVE the ORF from this neighbor\n"
3744 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3745
718e3744 3746DEFUN (no_neighbor_capability_orf_prefix,
3747 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3748 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3749 NO_STR
3750 NEIGHBOR_STR
3751 NEIGHBOR_ADDR_STR2
3752 "Advertise capability to the peer\n"
3753 "Advertise ORF capability to the peer\n"
3754 "Advertise prefixlist ORF capability to this neighbor\n"
3755 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3756 "Capability to RECEIVE the ORF from this neighbor\n"
3757 "Capability to SEND the ORF to this neighbor\n")
3758{
d62a17ae 3759 int idx_peer = 2;
3760 int idx_send_recv = 6;
d7c0a89a 3761 uint16_t flag = 0;
d62a17ae 3762
3763 if (strmatch(argv[idx_send_recv]->text, "send"))
3764 flag = PEER_FLAG_ORF_PREFIX_SM;
3765 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3766 flag = PEER_FLAG_ORF_PREFIX_RM;
3767 else if (strmatch(argv[idx_send_recv]->text, "both"))
3768 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3769 else {
3770 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3771 return CMD_WARNING_CONFIG_FAILED;
3772 }
3773
3774 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3775 bgp_node_afi(vty), bgp_node_safi(vty),
3776 flag);
3777}
3778
3779ALIAS_HIDDEN(
3780 no_neighbor_capability_orf_prefix,
3781 no_neighbor_capability_orf_prefix_hidden_cmd,
3782 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3783 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3784 "Advertise capability to the peer\n"
3785 "Advertise ORF capability to the peer\n"
3786 "Advertise prefixlist ORF capability to this neighbor\n"
3787 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3788 "Capability to RECEIVE the ORF from this neighbor\n"
3789 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3790
718e3744 3791/* neighbor next-hop-self. */
3792DEFUN (neighbor_nexthop_self,
3793 neighbor_nexthop_self_cmd,
9ccf14f7 3794 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3795 NEIGHBOR_STR
3796 NEIGHBOR_ADDR_STR2
a538debe 3797 "Disable the next hop calculation for this neighbor\n")
718e3744 3798{
d62a17ae 3799 int idx_peer = 1;
3800 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3801 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3802}
9e7a53c1 3803
d62a17ae 3804ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3805 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3806 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3807 "Disable the next hop calculation for this neighbor\n")
596c17ba 3808
a538debe
DS
3809/* neighbor next-hop-self. */
3810DEFUN (neighbor_nexthop_self_force,
3811 neighbor_nexthop_self_force_cmd,
9ccf14f7 3812 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3813 NEIGHBOR_STR
3814 NEIGHBOR_ADDR_STR2
3815 "Disable the next hop calculation for this neighbor\n"
3816 "Set the next hop to self for reflected routes\n")
3817{
d62a17ae 3818 int idx_peer = 1;
3819 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3820 bgp_node_safi(vty),
3821 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3822}
3823
d62a17ae 3824ALIAS_HIDDEN(neighbor_nexthop_self_force,
3825 neighbor_nexthop_self_force_hidden_cmd,
3826 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3827 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3828 "Disable the next hop calculation for this neighbor\n"
3829 "Set the next hop to self for reflected routes\n")
596c17ba 3830
718e3744 3831DEFUN (no_neighbor_nexthop_self,
3832 no_neighbor_nexthop_self_cmd,
9ccf14f7 3833 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3834 NO_STR
3835 NEIGHBOR_STR
3836 NEIGHBOR_ADDR_STR2
a538debe 3837 "Disable the next hop calculation for this neighbor\n")
718e3744 3838{
d62a17ae 3839 int idx_peer = 2;
3840 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3841 bgp_node_afi(vty), bgp_node_safi(vty),
3842 PEER_FLAG_NEXTHOP_SELF);
718e3744 3843}
6b0655a2 3844
d62a17ae 3845ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3846 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3847 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3848 "Disable the next hop calculation for this neighbor\n")
596c17ba 3849
88b8ed8d 3850DEFUN (no_neighbor_nexthop_self_force,
a538debe 3851 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3852 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3853 NO_STR
3854 NEIGHBOR_STR
3855 NEIGHBOR_ADDR_STR2
3856 "Disable the next hop calculation for this neighbor\n"
3857 "Set the next hop to self for reflected routes\n")
88b8ed8d 3858{
d62a17ae 3859 int idx_peer = 2;
3860 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3861 bgp_node_afi(vty), bgp_node_safi(vty),
3862 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3863}
a538debe 3864
d62a17ae 3865ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3866 no_neighbor_nexthop_self_force_hidden_cmd,
3867 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3868 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3869 "Disable the next hop calculation for this neighbor\n"
3870 "Set the next hop to self for reflected routes\n")
596c17ba 3871
c7122e14
DS
3872/* neighbor as-override */
3873DEFUN (neighbor_as_override,
3874 neighbor_as_override_cmd,
9ccf14f7 3875 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3876 NEIGHBOR_STR
3877 NEIGHBOR_ADDR_STR2
3878 "Override ASNs in outbound updates if aspath equals remote-as\n")
3879{
d62a17ae 3880 int idx_peer = 1;
3881 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3882 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3883}
3884
d62a17ae 3885ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3886 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3887 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3888 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3889
c7122e14
DS
3890DEFUN (no_neighbor_as_override,
3891 no_neighbor_as_override_cmd,
9ccf14f7 3892 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3893 NO_STR
3894 NEIGHBOR_STR
3895 NEIGHBOR_ADDR_STR2
3896 "Override ASNs in outbound updates if aspath equals remote-as\n")
3897{
d62a17ae 3898 int idx_peer = 2;
3899 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3900 bgp_node_afi(vty), bgp_node_safi(vty),
3901 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3902}
3903
d62a17ae 3904ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3905 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3906 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3907 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3908
718e3744 3909/* neighbor remove-private-AS. */
3910DEFUN (neighbor_remove_private_as,
3911 neighbor_remove_private_as_cmd,
9ccf14f7 3912 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3913 NEIGHBOR_STR
3914 NEIGHBOR_ADDR_STR2
5000f21c 3915 "Remove private ASNs in outbound updates\n")
718e3744 3916{
d62a17ae 3917 int idx_peer = 1;
3918 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3919 bgp_node_safi(vty),
3920 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3921}
3922
d62a17ae 3923ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3924 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3925 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3926 "Remove private ASNs in outbound updates\n")
596c17ba 3927
5000f21c
DS
3928DEFUN (neighbor_remove_private_as_all,
3929 neighbor_remove_private_as_all_cmd,
9ccf14f7 3930 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3931 NEIGHBOR_STR
3932 NEIGHBOR_ADDR_STR2
3933 "Remove private ASNs in outbound updates\n"
efd7904e 3934 "Apply to all AS numbers\n")
5000f21c 3935{
d62a17ae 3936 int idx_peer = 1;
3937 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3938 bgp_node_safi(vty),
3939 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3940}
3941
d62a17ae 3942ALIAS_HIDDEN(neighbor_remove_private_as_all,
3943 neighbor_remove_private_as_all_hidden_cmd,
3944 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3945 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3946 "Remove private ASNs in outbound updates\n"
3947 "Apply to all AS numbers")
596c17ba 3948
5000f21c
DS
3949DEFUN (neighbor_remove_private_as_replace_as,
3950 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3951 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3952 NEIGHBOR_STR
3953 NEIGHBOR_ADDR_STR2
3954 "Remove private ASNs in outbound updates\n"
3955 "Replace private ASNs with our ASN in outbound updates\n")
3956{
d62a17ae 3957 int idx_peer = 1;
3958 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3959 bgp_node_safi(vty),
3960 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3961}
3962
d62a17ae 3963ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3964 neighbor_remove_private_as_replace_as_hidden_cmd,
3965 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3966 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3967 "Remove private ASNs in outbound updates\n"
3968 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3969
5000f21c
DS
3970DEFUN (neighbor_remove_private_as_all_replace_as,
3971 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3972 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3973 NEIGHBOR_STR
3974 NEIGHBOR_ADDR_STR2
3975 "Remove private ASNs in outbound updates\n"
16cedbb0 3976 "Apply to all AS numbers\n"
5000f21c
DS
3977 "Replace private ASNs with our ASN in outbound updates\n")
3978{
d62a17ae 3979 int idx_peer = 1;
3980 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3981 bgp_node_safi(vty),
3982 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3983}
3984
d62a17ae 3985ALIAS_HIDDEN(
3986 neighbor_remove_private_as_all_replace_as,
3987 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3988 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3989 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3990 "Remove private ASNs in outbound updates\n"
3991 "Apply to all AS numbers\n"
3992 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3993
718e3744 3994DEFUN (no_neighbor_remove_private_as,
3995 no_neighbor_remove_private_as_cmd,
9ccf14f7 3996 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3997 NO_STR
3998 NEIGHBOR_STR
3999 NEIGHBOR_ADDR_STR2
5000f21c 4000 "Remove private ASNs in outbound updates\n")
718e3744 4001{
d62a17ae 4002 int idx_peer = 2;
4003 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4004 bgp_node_afi(vty), bgp_node_safi(vty),
4005 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4006}
6b0655a2 4007
d62a17ae 4008ALIAS_HIDDEN(no_neighbor_remove_private_as,
4009 no_neighbor_remove_private_as_hidden_cmd,
4010 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4011 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4012 "Remove private ASNs in outbound updates\n")
596c17ba 4013
88b8ed8d 4014DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4015 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4016 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4017 NO_STR
4018 NEIGHBOR_STR
4019 NEIGHBOR_ADDR_STR2
4020 "Remove private ASNs in outbound updates\n"
16cedbb0 4021 "Apply to all AS numbers\n")
88b8ed8d 4022{
d62a17ae 4023 int idx_peer = 2;
4024 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4025 bgp_node_afi(vty), bgp_node_safi(vty),
4026 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4027}
5000f21c 4028
d62a17ae 4029ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4030 no_neighbor_remove_private_as_all_hidden_cmd,
4031 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4032 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4033 "Remove private ASNs in outbound updates\n"
4034 "Apply to all AS numbers\n")
596c17ba 4035
88b8ed8d 4036DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4037 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4038 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4039 NO_STR
4040 NEIGHBOR_STR
4041 NEIGHBOR_ADDR_STR2
4042 "Remove private ASNs in outbound updates\n"
4043 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4044{
d62a17ae 4045 int idx_peer = 2;
4046 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4047 bgp_node_afi(vty), bgp_node_safi(vty),
4048 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4049}
5000f21c 4050
d62a17ae 4051ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4052 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4053 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4054 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4055 "Remove private ASNs in outbound updates\n"
4056 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4057
88b8ed8d 4058DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4059 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4060 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4061 NO_STR
4062 NEIGHBOR_STR
4063 NEIGHBOR_ADDR_STR2
4064 "Remove private ASNs in outbound updates\n"
16cedbb0 4065 "Apply to all AS numbers\n"
5000f21c 4066 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4067{
d62a17ae 4068 int idx_peer = 2;
4069 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4070 bgp_node_afi(vty), bgp_node_safi(vty),
4071 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4072}
5000f21c 4073
d62a17ae 4074ALIAS_HIDDEN(
4075 no_neighbor_remove_private_as_all_replace_as,
4076 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4077 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4078 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4079 "Remove private ASNs in outbound updates\n"
4080 "Apply to all AS numbers\n"
4081 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4082
5000f21c 4083
718e3744 4084/* neighbor send-community. */
4085DEFUN (neighbor_send_community,
4086 neighbor_send_community_cmd,
9ccf14f7 4087 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4088 NEIGHBOR_STR
4089 NEIGHBOR_ADDR_STR2
4090 "Send Community attribute to this neighbor\n")
4091{
d62a17ae 4092 int idx_peer = 1;
27c05d4d 4093
d62a17ae 4094 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4095 bgp_node_safi(vty),
4096 PEER_FLAG_SEND_COMMUNITY);
718e3744 4097}
4098
d62a17ae 4099ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4100 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4101 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4102 "Send Community attribute to this neighbor\n")
596c17ba 4103
718e3744 4104DEFUN (no_neighbor_send_community,
4105 no_neighbor_send_community_cmd,
9ccf14f7 4106 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4107 NO_STR
4108 NEIGHBOR_STR
4109 NEIGHBOR_ADDR_STR2
4110 "Send Community attribute to this neighbor\n")
4111{
d62a17ae 4112 int idx_peer = 2;
27c05d4d 4113
d62a17ae 4114 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4115 bgp_node_afi(vty), bgp_node_safi(vty),
4116 PEER_FLAG_SEND_COMMUNITY);
718e3744 4117}
6b0655a2 4118
d62a17ae 4119ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4120 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4121 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4122 "Send Community attribute to this neighbor\n")
596c17ba 4123
718e3744 4124/* neighbor send-community extended. */
4125DEFUN (neighbor_send_community_type,
4126 neighbor_send_community_type_cmd,
57d187bc 4127 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4128 NEIGHBOR_STR
4129 NEIGHBOR_ADDR_STR2
4130 "Send Community attribute to this neighbor\n"
4131 "Send Standard and Extended Community attributes\n"
57d187bc 4132 "Send Standard, Large and Extended Community attributes\n"
718e3744 4133 "Send Extended Community attributes\n"
57d187bc
JS
4134 "Send Standard Community attributes\n"
4135 "Send Large Community attributes\n")
718e3744 4136{
27c05d4d 4137 int idx_peer = 1;
d7c0a89a 4138 uint32_t flag = 0;
27c05d4d 4139 const char *type = argv[argc - 1]->text;
d62a17ae 4140
27c05d4d 4141 if (strmatch(type, "standard")) {
d62a17ae 4142 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4143 } else if (strmatch(type, "extended")) {
d62a17ae 4144 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4145 } else if (strmatch(type, "large")) {
d62a17ae 4146 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4147 } else if (strmatch(type, "both")) {
d62a17ae 4148 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4149 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4150 } else { /* if (strmatch(type, "all")) */
d62a17ae 4151 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4152 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4153 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4154 }
4155
27c05d4d 4156 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4157 bgp_node_safi(vty), flag);
4158}
4159
4160ALIAS_HIDDEN(
4161 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4162 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4163 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4164 "Send Community attribute to this neighbor\n"
4165 "Send Standard and Extended Community attributes\n"
4166 "Send Standard, Large and Extended Community attributes\n"
4167 "Send Extended Community attributes\n"
4168 "Send Standard Community attributes\n"
4169 "Send Large Community attributes\n")
596c17ba 4170
718e3744 4171DEFUN (no_neighbor_send_community_type,
4172 no_neighbor_send_community_type_cmd,
57d187bc 4173 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4174 NO_STR
4175 NEIGHBOR_STR
4176 NEIGHBOR_ADDR_STR2
4177 "Send Community attribute to this neighbor\n"
4178 "Send Standard and Extended Community attributes\n"
57d187bc 4179 "Send Standard, Large and Extended Community attributes\n"
718e3744 4180 "Send Extended Community attributes\n"
57d187bc
JS
4181 "Send Standard Community attributes\n"
4182 "Send Large Community attributes\n")
718e3744 4183{
d62a17ae 4184 int idx_peer = 2;
27c05d4d 4185 uint32_t flag = 0;
d62a17ae 4186 const char *type = argv[argc - 1]->text;
4187
27c05d4d
PM
4188 if (strmatch(type, "standard")) {
4189 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4190 } else if (strmatch(type, "extended")) {
4191 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4192 } else if (strmatch(type, "large")) {
4193 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4194 } else if (strmatch(type, "both")) {
4195 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4196 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4197 } else { /* if (strmatch(type, "all")) */
4198 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4199 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4200 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4201 }
4202
4203 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4204 bgp_node_afi(vty), bgp_node_safi(vty),
4205 flag);
d62a17ae 4206}
4207
4208ALIAS_HIDDEN(
4209 no_neighbor_send_community_type,
4210 no_neighbor_send_community_type_hidden_cmd,
4211 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4212 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4213 "Send Community attribute to this neighbor\n"
4214 "Send Standard and Extended Community attributes\n"
4215 "Send Standard, Large and Extended Community attributes\n"
4216 "Send Extended Community attributes\n"
4217 "Send Standard Community attributes\n"
4218 "Send Large Community attributes\n")
596c17ba 4219
718e3744 4220/* neighbor soft-reconfig. */
4221DEFUN (neighbor_soft_reconfiguration,
4222 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4223 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4224 NEIGHBOR_STR
4225 NEIGHBOR_ADDR_STR2
4226 "Per neighbor soft reconfiguration\n"
4227 "Allow inbound soft reconfiguration for this neighbor\n")
4228{
d62a17ae 4229 int idx_peer = 1;
4230 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4231 bgp_node_safi(vty),
4232 PEER_FLAG_SOFT_RECONFIG);
718e3744 4233}
4234
d62a17ae 4235ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4236 neighbor_soft_reconfiguration_hidden_cmd,
4237 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4238 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4239 "Per neighbor soft reconfiguration\n"
4240 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4241
718e3744 4242DEFUN (no_neighbor_soft_reconfiguration,
4243 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4244 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4245 NO_STR
4246 NEIGHBOR_STR
4247 NEIGHBOR_ADDR_STR2
4248 "Per neighbor soft reconfiguration\n"
4249 "Allow inbound soft reconfiguration for this neighbor\n")
4250{
d62a17ae 4251 int idx_peer = 2;
4252 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4253 bgp_node_afi(vty), bgp_node_safi(vty),
4254 PEER_FLAG_SOFT_RECONFIG);
718e3744 4255}
6b0655a2 4256
d62a17ae 4257ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4258 no_neighbor_soft_reconfiguration_hidden_cmd,
4259 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4260 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4261 "Per neighbor soft reconfiguration\n"
4262 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4263
718e3744 4264DEFUN (neighbor_route_reflector_client,
4265 neighbor_route_reflector_client_cmd,
9ccf14f7 4266 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4267 NEIGHBOR_STR
4268 NEIGHBOR_ADDR_STR2
4269 "Configure a neighbor as Route Reflector client\n")
4270{
d62a17ae 4271 int idx_peer = 1;
4272 struct peer *peer;
718e3744 4273
4274
d62a17ae 4275 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4276 if (!peer)
4277 return CMD_WARNING_CONFIG_FAILED;
718e3744 4278
d62a17ae 4279 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4280 bgp_node_safi(vty),
4281 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4282}
4283
d62a17ae 4284ALIAS_HIDDEN(neighbor_route_reflector_client,
4285 neighbor_route_reflector_client_hidden_cmd,
4286 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4287 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4288 "Configure a neighbor as Route Reflector client\n")
596c17ba 4289
718e3744 4290DEFUN (no_neighbor_route_reflector_client,
4291 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4292 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4293 NO_STR
4294 NEIGHBOR_STR
4295 NEIGHBOR_ADDR_STR2
4296 "Configure a neighbor as Route Reflector client\n")
4297{
d62a17ae 4298 int idx_peer = 2;
4299 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4300 bgp_node_afi(vty), bgp_node_safi(vty),
4301 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4302}
6b0655a2 4303
d62a17ae 4304ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4305 no_neighbor_route_reflector_client_hidden_cmd,
4306 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4307 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4308 "Configure a neighbor as Route Reflector client\n")
596c17ba 4309
718e3744 4310/* neighbor route-server-client. */
4311DEFUN (neighbor_route_server_client,
4312 neighbor_route_server_client_cmd,
9ccf14f7 4313 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4314 NEIGHBOR_STR
4315 NEIGHBOR_ADDR_STR2
4316 "Configure a neighbor as Route Server client\n")
4317{
d62a17ae 4318 int idx_peer = 1;
4319 struct peer *peer;
2a3d5731 4320
d62a17ae 4321 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4322 if (!peer)
4323 return CMD_WARNING_CONFIG_FAILED;
4324 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4325 bgp_node_safi(vty),
4326 PEER_FLAG_RSERVER_CLIENT);
718e3744 4327}
4328
d62a17ae 4329ALIAS_HIDDEN(neighbor_route_server_client,
4330 neighbor_route_server_client_hidden_cmd,
4331 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4332 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4333 "Configure a neighbor as Route Server client\n")
596c17ba 4334
718e3744 4335DEFUN (no_neighbor_route_server_client,
4336 no_neighbor_route_server_client_cmd,
9ccf14f7 4337 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4338 NO_STR
4339 NEIGHBOR_STR
4340 NEIGHBOR_ADDR_STR2
4341 "Configure a neighbor as Route Server client\n")
fee0f4c6 4342{
d62a17ae 4343 int idx_peer = 2;
4344 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4345 bgp_node_afi(vty), bgp_node_safi(vty),
4346 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4347}
6b0655a2 4348
d62a17ae 4349ALIAS_HIDDEN(no_neighbor_route_server_client,
4350 no_neighbor_route_server_client_hidden_cmd,
4351 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4352 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4353 "Configure a neighbor as Route Server client\n")
596c17ba 4354
fee0f4c6 4355DEFUN (neighbor_nexthop_local_unchanged,
4356 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4357 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4358 NEIGHBOR_STR
4359 NEIGHBOR_ADDR_STR2
4360 "Configure treatment of outgoing link-local nexthop attribute\n"
4361 "Leave link-local nexthop unchanged for this peer\n")
4362{
d62a17ae 4363 int idx_peer = 1;
4364 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4365 bgp_node_safi(vty),
4366 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4367}
6b0655a2 4368
fee0f4c6 4369DEFUN (no_neighbor_nexthop_local_unchanged,
4370 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4371 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4372 NO_STR
4373 NEIGHBOR_STR
4374 NEIGHBOR_ADDR_STR2
4375 "Configure treatment of outgoing link-local-nexthop attribute\n"
4376 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4377{
d62a17ae 4378 int idx_peer = 2;
4379 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4380 bgp_node_afi(vty), bgp_node_safi(vty),
4381 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4382}
6b0655a2 4383
718e3744 4384DEFUN (neighbor_attr_unchanged,
4385 neighbor_attr_unchanged_cmd,
a8206004 4386 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4387 NEIGHBOR_STR
4388 NEIGHBOR_ADDR_STR2
4389 "BGP attribute is propagated unchanged to this neighbor\n"
4390 "As-path attribute\n"
4391 "Nexthop attribute\n"
a8206004 4392 "Med attribute\n")
718e3744 4393{
d62a17ae 4394 int idx = 0;
8eeb0335
DW
4395 char *peer_str = argv[1]->arg;
4396 struct peer *peer;
d7c0a89a 4397 uint16_t flags = 0;
8eeb0335
DW
4398 afi_t afi = bgp_node_afi(vty);
4399 safi_t safi = bgp_node_safi(vty);
4400
4401 peer = peer_and_group_lookup_vty(vty, peer_str);
4402 if (!peer)
4403 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4404
4405 if (argv_find(argv, argc, "as-path", &idx))
4406 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4407 idx = 0;
4408 if (argv_find(argv, argc, "next-hop", &idx))
4409 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4410 idx = 0;
4411 if (argv_find(argv, argc, "med", &idx))
4412 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4413
8eeb0335
DW
4414 /* no flags means all of them! */
4415 if (!flags) {
d62a17ae 4416 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4417 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4418 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4419 } else {
a4d82a8a
PZ
4420 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4421 && peer_af_flag_check(peer, afi, safi,
4422 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4423 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4424 PEER_FLAG_AS_PATH_UNCHANGED);
4425 }
4426
a4d82a8a
PZ
4427 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4428 && peer_af_flag_check(peer, afi, safi,
4429 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4430 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4431 PEER_FLAG_NEXTHOP_UNCHANGED);
4432 }
4433
a4d82a8a
PZ
4434 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4435 && peer_af_flag_check(peer, afi, safi,
4436 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4437 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4438 PEER_FLAG_MED_UNCHANGED);
4439 }
d62a17ae 4440 }
4441
8eeb0335 4442 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4443}
4444
4445ALIAS_HIDDEN(
4446 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4447 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4448 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4449 "BGP attribute is propagated unchanged to this neighbor\n"
4450 "As-path attribute\n"
4451 "Nexthop attribute\n"
4452 "Med attribute\n")
596c17ba 4453
718e3744 4454DEFUN (no_neighbor_attr_unchanged,
4455 no_neighbor_attr_unchanged_cmd,
a8206004 4456 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4457 NO_STR
718e3744 4458 NEIGHBOR_STR
4459 NEIGHBOR_ADDR_STR2
31500417
DW
4460 "BGP attribute is propagated unchanged to this neighbor\n"
4461 "As-path attribute\n"
40e718b5 4462 "Nexthop attribute\n"
a8206004 4463 "Med attribute\n")
718e3744 4464{
d62a17ae 4465 int idx = 0;
4466 char *peer = argv[2]->arg;
d7c0a89a 4467 uint16_t flags = 0;
d62a17ae 4468
4469 if (argv_find(argv, argc, "as-path", &idx))
4470 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4471 idx = 0;
4472 if (argv_find(argv, argc, "next-hop", &idx))
4473 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4474 idx = 0;
4475 if (argv_find(argv, argc, "med", &idx))
4476 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4477
4478 if (!flags) // no flags means all of them!
4479 {
4480 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4481 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4482 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4483 }
4484
4485 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4486 bgp_node_safi(vty), flags);
4487}
4488
4489ALIAS_HIDDEN(
4490 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4491 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4492 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4493 "BGP attribute is propagated unchanged to this neighbor\n"
4494 "As-path attribute\n"
4495 "Nexthop attribute\n"
4496 "Med attribute\n")
718e3744 4497
718e3744 4498/* EBGP multihop configuration. */
d62a17ae 4499static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4500 const char *ttl_str)
718e3744 4501{
d62a17ae 4502 struct peer *peer;
4503 unsigned int ttl;
718e3744 4504
d62a17ae 4505 peer = peer_and_group_lookup_vty(vty, ip_str);
4506 if (!peer)
4507 return CMD_WARNING_CONFIG_FAILED;
718e3744 4508
d62a17ae 4509 if (peer->conf_if)
4510 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4511
d62a17ae 4512 if (!ttl_str)
4513 ttl = MAXTTL;
4514 else
4515 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4516
d62a17ae 4517 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4518}
4519
d62a17ae 4520static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4521{
d62a17ae 4522 struct peer *peer;
718e3744 4523
d62a17ae 4524 peer = peer_and_group_lookup_vty(vty, ip_str);
4525 if (!peer)
4526 return CMD_WARNING_CONFIG_FAILED;
718e3744 4527
d62a17ae 4528 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4529}
4530
4531/* neighbor ebgp-multihop. */
4532DEFUN (neighbor_ebgp_multihop,
4533 neighbor_ebgp_multihop_cmd,
9ccf14f7 4534 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4535 NEIGHBOR_STR
4536 NEIGHBOR_ADDR_STR2
4537 "Allow EBGP neighbors not on directly connected networks\n")
4538{
d62a17ae 4539 int idx_peer = 1;
4540 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4541}
4542
4543DEFUN (neighbor_ebgp_multihop_ttl,
4544 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4545 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4546 NEIGHBOR_STR
4547 NEIGHBOR_ADDR_STR2
4548 "Allow EBGP neighbors not on directly connected networks\n"
4549 "maximum hop count\n")
4550{
d62a17ae 4551 int idx_peer = 1;
4552 int idx_number = 3;
4553 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4554 argv[idx_number]->arg);
718e3744 4555}
4556
4557DEFUN (no_neighbor_ebgp_multihop,
4558 no_neighbor_ebgp_multihop_cmd,
a636c635 4559 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4560 NO_STR
4561 NEIGHBOR_STR
4562 NEIGHBOR_ADDR_STR2
a636c635
DW
4563 "Allow EBGP neighbors not on directly connected networks\n"
4564 "maximum hop count\n")
718e3744 4565{
d62a17ae 4566 int idx_peer = 2;
4567 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4568}
4569
6b0655a2 4570
6ffd2079 4571/* disable-connected-check */
4572DEFUN (neighbor_disable_connected_check,
4573 neighbor_disable_connected_check_cmd,
7ebe625c 4574 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4575 NEIGHBOR_STR
7ebe625c 4576 NEIGHBOR_ADDR_STR2
a636c635
DW
4577 "one-hop away EBGP peer using loopback address\n"
4578 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4579{
d62a17ae 4580 int idx_peer = 1;
4581 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4582 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4583}
4584
4585DEFUN (no_neighbor_disable_connected_check,
4586 no_neighbor_disable_connected_check_cmd,
7ebe625c 4587 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4588 NO_STR
4589 NEIGHBOR_STR
7ebe625c 4590 NEIGHBOR_ADDR_STR2
a636c635
DW
4591 "one-hop away EBGP peer using loopback address\n"
4592 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4593{
d62a17ae 4594 int idx_peer = 2;
4595 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4596 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4597}
4598
47cbc09b
PM
4599
4600/* enforce-first-as */
4601DEFUN (neighbor_enforce_first_as,
4602 neighbor_enforce_first_as_cmd,
4603 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4604 NEIGHBOR_STR
4605 NEIGHBOR_ADDR_STR2
4606 "Enforce the first AS for EBGP routes\n")
4607{
4608 int idx_peer = 1;
4609
4610 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4611 PEER_FLAG_ENFORCE_FIRST_AS);
4612}
4613
4614DEFUN (no_neighbor_enforce_first_as,
4615 no_neighbor_enforce_first_as_cmd,
4616 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4617 NO_STR
4618 NEIGHBOR_STR
4619 NEIGHBOR_ADDR_STR2
4620 "Enforce the first AS for EBGP routes\n")
4621{
4622 int idx_peer = 2;
4623
4624 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4625 PEER_FLAG_ENFORCE_FIRST_AS);
4626}
4627
4628
718e3744 4629DEFUN (neighbor_description,
4630 neighbor_description_cmd,
e961923c 4631 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4632 NEIGHBOR_STR
4633 NEIGHBOR_ADDR_STR2
4634 "Neighbor specific description\n"
4635 "Up to 80 characters describing this neighbor\n")
4636{
d62a17ae 4637 int idx_peer = 1;
4638 int idx_line = 3;
4639 struct peer *peer;
4640 char *str;
718e3744 4641
d62a17ae 4642 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4643 if (!peer)
4644 return CMD_WARNING_CONFIG_FAILED;
718e3744 4645
d62a17ae 4646 str = argv_concat(argv, argc, idx_line);
718e3744 4647
d62a17ae 4648 peer_description_set(peer, str);
718e3744 4649
d62a17ae 4650 XFREE(MTYPE_TMP, str);
718e3744 4651
d62a17ae 4652 return CMD_SUCCESS;
718e3744 4653}
4654
4655DEFUN (no_neighbor_description,
4656 no_neighbor_description_cmd,
a14810f4 4657 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4658 NO_STR
4659 NEIGHBOR_STR
4660 NEIGHBOR_ADDR_STR2
a14810f4 4661 "Neighbor specific description\n")
718e3744 4662{
d62a17ae 4663 int idx_peer = 2;
4664 struct peer *peer;
718e3744 4665
d62a17ae 4666 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4667 if (!peer)
4668 return CMD_WARNING_CONFIG_FAILED;
718e3744 4669
d62a17ae 4670 peer_description_unset(peer);
718e3744 4671
d62a17ae 4672 return CMD_SUCCESS;
718e3744 4673}
4674
a14810f4
PM
4675ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4676 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4677 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4678 "Neighbor specific description\n"
4679 "Up to 80 characters describing this neighbor\n")
6b0655a2 4680
718e3744 4681/* Neighbor update-source. */
d62a17ae 4682static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4683 const char *source_str)
4684{
4685 struct peer *peer;
4686 struct prefix p;
a14810f4 4687 union sockunion su;
d62a17ae 4688
4689 peer = peer_and_group_lookup_vty(vty, peer_str);
4690 if (!peer)
4691 return CMD_WARNING_CONFIG_FAILED;
4692
4693 if (peer->conf_if)
4694 return CMD_WARNING;
4695
4696 if (source_str) {
a14810f4 4697 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4698 peer_update_source_addr_set(peer, &su);
4699 else {
4700 if (str2prefix(source_str, &p)) {
4701 vty_out(vty,
4702 "%% Invalid update-source, remove prefix length \n");
4703 return CMD_WARNING_CONFIG_FAILED;
4704 } else
4705 peer_update_source_if_set(peer, source_str);
4706 }
4707 } else
4708 peer_update_source_unset(peer);
4709
4710 return CMD_SUCCESS;
4711}
4712
4713#define BGP_UPDATE_SOURCE_HELP_STR \
4714 "IPv4 address\n" \
4715 "IPv6 address\n" \
4716 "Interface name (requires zebra to be running)\n"
369688c0 4717
718e3744 4718DEFUN (neighbor_update_source,
4719 neighbor_update_source_cmd,
9ccf14f7 4720 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4721 NEIGHBOR_STR
4722 NEIGHBOR_ADDR_STR2
4723 "Source of routing updates\n"
369688c0 4724 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4725{
d62a17ae 4726 int idx_peer = 1;
4727 int idx_peer_2 = 3;
4728 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4729 argv[idx_peer_2]->arg);
718e3744 4730}
4731
4732DEFUN (no_neighbor_update_source,
4733 no_neighbor_update_source_cmd,
c7178fe7 4734 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4735 NO_STR
4736 NEIGHBOR_STR
4737 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4738 "Source of routing updates\n"
4739 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4740{
d62a17ae 4741 int idx_peer = 2;
4742 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4743}
6b0655a2 4744
d62a17ae 4745static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4746 afi_t afi, safi_t safi,
4747 const char *rmap, int set)
718e3744 4748{
d62a17ae 4749 int ret;
4750 struct peer *peer;
718e3744 4751
d62a17ae 4752 peer = peer_and_group_lookup_vty(vty, peer_str);
4753 if (!peer)
4754 return CMD_WARNING_CONFIG_FAILED;
718e3744 4755
d62a17ae 4756 if (set)
4757 ret = peer_default_originate_set(peer, afi, safi, rmap);
4758 else
4759 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4760
d62a17ae 4761 return bgp_vty_return(vty, ret);
718e3744 4762}
4763
4764/* neighbor default-originate. */
4765DEFUN (neighbor_default_originate,
4766 neighbor_default_originate_cmd,
9ccf14f7 4767 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4768 NEIGHBOR_STR
4769 NEIGHBOR_ADDR_STR2
4770 "Originate default route to this neighbor\n")
4771{
d62a17ae 4772 int idx_peer = 1;
4773 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4774 bgp_node_afi(vty),
4775 bgp_node_safi(vty), NULL, 1);
718e3744 4776}
4777
d62a17ae 4778ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4779 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4780 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4781 "Originate default route to this neighbor\n")
596c17ba 4782
718e3744 4783DEFUN (neighbor_default_originate_rmap,
4784 neighbor_default_originate_rmap_cmd,
9ccf14f7 4785 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4786 NEIGHBOR_STR
4787 NEIGHBOR_ADDR_STR2
4788 "Originate default route to this neighbor\n"
4789 "Route-map to specify criteria to originate default\n"
4790 "route-map name\n")
4791{
d62a17ae 4792 int idx_peer = 1;
4793 int idx_word = 4;
4794 return peer_default_originate_set_vty(
4795 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4796 argv[idx_word]->arg, 1);
718e3744 4797}
4798
d62a17ae 4799ALIAS_HIDDEN(
4800 neighbor_default_originate_rmap,
4801 neighbor_default_originate_rmap_hidden_cmd,
4802 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4803 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4804 "Originate default route to this neighbor\n"
4805 "Route-map to specify criteria to originate default\n"
4806 "route-map name\n")
596c17ba 4807
718e3744 4808DEFUN (no_neighbor_default_originate,
4809 no_neighbor_default_originate_cmd,
a636c635 4810 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4811 NO_STR
4812 NEIGHBOR_STR
4813 NEIGHBOR_ADDR_STR2
a636c635
DW
4814 "Originate default route to this neighbor\n"
4815 "Route-map to specify criteria to originate default\n"
4816 "route-map name\n")
718e3744 4817{
d62a17ae 4818 int idx_peer = 2;
4819 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4820 bgp_node_afi(vty),
4821 bgp_node_safi(vty), NULL, 0);
718e3744 4822}
4823
d62a17ae 4824ALIAS_HIDDEN(
4825 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4826 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4827 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4828 "Originate default route to this neighbor\n"
4829 "Route-map to specify criteria to originate default\n"
4830 "route-map name\n")
596c17ba 4831
6b0655a2 4832
718e3744 4833/* Set neighbor's BGP port. */
d62a17ae 4834static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4835 const char *port_str)
4836{
4837 struct peer *peer;
d7c0a89a 4838 uint16_t port;
d62a17ae 4839 struct servent *sp;
4840
4841 peer = peer_lookup_vty(vty, ip_str);
4842 if (!peer)
4843 return CMD_WARNING_CONFIG_FAILED;
4844
4845 if (!port_str) {
4846 sp = getservbyname("bgp", "tcp");
4847 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4848 } else {
4849 port = strtoul(port_str, NULL, 10);
4850 }
718e3744 4851
d62a17ae 4852 peer_port_set(peer, port);
718e3744 4853
d62a17ae 4854 return CMD_SUCCESS;
718e3744 4855}
4856
f418446b 4857/* Set specified peer's BGP port. */
718e3744 4858DEFUN (neighbor_port,
4859 neighbor_port_cmd,
9ccf14f7 4860 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4861 NEIGHBOR_STR
4862 NEIGHBOR_ADDR_STR
4863 "Neighbor's BGP port\n"
4864 "TCP port number\n")
4865{
d62a17ae 4866 int idx_ip = 1;
4867 int idx_number = 3;
4868 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4869 argv[idx_number]->arg);
718e3744 4870}
4871
4872DEFUN (no_neighbor_port,
4873 no_neighbor_port_cmd,
9ccf14f7 4874 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4875 NO_STR
4876 NEIGHBOR_STR
4877 NEIGHBOR_ADDR_STR
8334fd5a
DW
4878 "Neighbor's BGP port\n"
4879 "TCP port number\n")
718e3744 4880{
d62a17ae 4881 int idx_ip = 2;
4882 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4883}
4884
6b0655a2 4885
718e3744 4886/* neighbor weight. */
d62a17ae 4887static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4888 safi_t safi, const char *weight_str)
718e3744 4889{
d62a17ae 4890 int ret;
4891 struct peer *peer;
4892 unsigned long weight;
718e3744 4893
d62a17ae 4894 peer = peer_and_group_lookup_vty(vty, ip_str);
4895 if (!peer)
4896 return CMD_WARNING_CONFIG_FAILED;
718e3744 4897
d62a17ae 4898 weight = strtoul(weight_str, NULL, 10);
718e3744 4899
d62a17ae 4900 ret = peer_weight_set(peer, afi, safi, weight);
4901 return bgp_vty_return(vty, ret);
718e3744 4902}
4903
d62a17ae 4904static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4905 safi_t safi)
718e3744 4906{
d62a17ae 4907 int ret;
4908 struct peer *peer;
718e3744 4909
d62a17ae 4910 peer = peer_and_group_lookup_vty(vty, ip_str);
4911 if (!peer)
4912 return CMD_WARNING_CONFIG_FAILED;
718e3744 4913
d62a17ae 4914 ret = peer_weight_unset(peer, afi, safi);
4915 return bgp_vty_return(vty, ret);
718e3744 4916}
4917
4918DEFUN (neighbor_weight,
4919 neighbor_weight_cmd,
9ccf14f7 4920 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4921 NEIGHBOR_STR
4922 NEIGHBOR_ADDR_STR2
4923 "Set default weight for routes from this neighbor\n"
4924 "default weight\n")
4925{
d62a17ae 4926 int idx_peer = 1;
4927 int idx_number = 3;
4928 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4929 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4930}
4931
d62a17ae 4932ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4933 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4934 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4935 "Set default weight for routes from this neighbor\n"
4936 "default weight\n")
596c17ba 4937
718e3744 4938DEFUN (no_neighbor_weight,
4939 no_neighbor_weight_cmd,
9ccf14f7 4940 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4941 NO_STR
4942 NEIGHBOR_STR
4943 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4944 "Set default weight for routes from this neighbor\n"
4945 "default weight\n")
718e3744 4946{
d62a17ae 4947 int idx_peer = 2;
4948 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4949 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4950}
4951
d62a17ae 4952ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4953 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4954 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4955 "Set default weight for routes from this neighbor\n"
4956 "default weight\n")
596c17ba 4957
6b0655a2 4958
718e3744 4959/* Override capability negotiation. */
4960DEFUN (neighbor_override_capability,
4961 neighbor_override_capability_cmd,
9ccf14f7 4962 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4963 NEIGHBOR_STR
4964 NEIGHBOR_ADDR_STR2
4965 "Override capability negotiation result\n")
4966{
d62a17ae 4967 int idx_peer = 1;
4968 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4969 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4970}
4971
4972DEFUN (no_neighbor_override_capability,
4973 no_neighbor_override_capability_cmd,
9ccf14f7 4974 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4975 NO_STR
4976 NEIGHBOR_STR
4977 NEIGHBOR_ADDR_STR2
4978 "Override capability negotiation result\n")
4979{
d62a17ae 4980 int idx_peer = 2;
4981 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4982 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4983}
6b0655a2 4984
718e3744 4985DEFUN (neighbor_strict_capability,
4986 neighbor_strict_capability_cmd,
9fb964de 4987 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 4988 NEIGHBOR_STR
9fb964de 4989 NEIGHBOR_ADDR_STR2
718e3744 4990 "Strict capability negotiation match\n")
4991{
9fb964de
PM
4992 int idx_peer = 1;
4993
4994 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 4995 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4996}
4997
4998DEFUN (no_neighbor_strict_capability,
4999 no_neighbor_strict_capability_cmd,
9fb964de 5000 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5001 NO_STR
5002 NEIGHBOR_STR
9fb964de 5003 NEIGHBOR_ADDR_STR2
718e3744 5004 "Strict capability negotiation match\n")
5005{
9fb964de
PM
5006 int idx_peer = 2;
5007
5008 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5009 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5010}
6b0655a2 5011
d62a17ae 5012static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5013 const char *keep_str, const char *hold_str)
718e3744 5014{
d62a17ae 5015 int ret;
5016 struct peer *peer;
d7c0a89a
QY
5017 uint32_t keepalive;
5018 uint32_t holdtime;
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 keepalive = strtoul(keep_str, NULL, 10);
5025 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5026
d62a17ae 5027 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5028
d62a17ae 5029 return bgp_vty_return(vty, ret);
718e3744 5030}
6b0655a2 5031
d62a17ae 5032static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5033{
d62a17ae 5034 int ret;
5035 struct peer *peer;
718e3744 5036
d62a17ae 5037 peer = peer_and_group_lookup_vty(vty, ip_str);
5038 if (!peer)
5039 return CMD_WARNING_CONFIG_FAILED;
718e3744 5040
d62a17ae 5041 ret = peer_timers_unset(peer);
718e3744 5042
d62a17ae 5043 return bgp_vty_return(vty, ret);
718e3744 5044}
5045
5046DEFUN (neighbor_timers,
5047 neighbor_timers_cmd,
9ccf14f7 5048 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5049 NEIGHBOR_STR
5050 NEIGHBOR_ADDR_STR2
5051 "BGP per neighbor timers\n"
5052 "Keepalive interval\n"
5053 "Holdtime\n")
5054{
d62a17ae 5055 int idx_peer = 1;
5056 int idx_number = 3;
5057 int idx_number_2 = 4;
5058 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5059 argv[idx_number]->arg,
5060 argv[idx_number_2]->arg);
718e3744 5061}
5062
5063DEFUN (no_neighbor_timers,
5064 no_neighbor_timers_cmd,
9ccf14f7 5065 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5066 NO_STR
5067 NEIGHBOR_STR
5068 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5069 "BGP per neighbor timers\n"
5070 "Keepalive interval\n"
5071 "Holdtime\n")
718e3744 5072{
d62a17ae 5073 int idx_peer = 2;
5074 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5075}
6b0655a2 5076
813d4307 5077
d62a17ae 5078static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5079 const char *time_str)
718e3744 5080{
d62a17ae 5081 int ret;
5082 struct peer *peer;
d7c0a89a 5083 uint32_t connect;
718e3744 5084
d62a17ae 5085 peer = peer_and_group_lookup_vty(vty, ip_str);
5086 if (!peer)
5087 return CMD_WARNING_CONFIG_FAILED;
718e3744 5088
d62a17ae 5089 connect = strtoul(time_str, NULL, 10);
718e3744 5090
d62a17ae 5091 ret = peer_timers_connect_set(peer, connect);
718e3744 5092
d62a17ae 5093 return bgp_vty_return(vty, ret);
718e3744 5094}
5095
d62a17ae 5096static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5097{
d62a17ae 5098 int ret;
5099 struct peer *peer;
718e3744 5100
d62a17ae 5101 peer = peer_and_group_lookup_vty(vty, ip_str);
5102 if (!peer)
5103 return CMD_WARNING_CONFIG_FAILED;
718e3744 5104
d62a17ae 5105 ret = peer_timers_connect_unset(peer);
718e3744 5106
d62a17ae 5107 return bgp_vty_return(vty, ret);
718e3744 5108}
5109
5110DEFUN (neighbor_timers_connect,
5111 neighbor_timers_connect_cmd,
9ccf14f7 5112 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5113 NEIGHBOR_STR
966f821c 5114 NEIGHBOR_ADDR_STR2
718e3744 5115 "BGP per neighbor timers\n"
5116 "BGP connect timer\n"
5117 "Connect timer\n")
5118{
d62a17ae 5119 int idx_peer = 1;
5120 int idx_number = 4;
5121 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5122 argv[idx_number]->arg);
718e3744 5123}
5124
5125DEFUN (no_neighbor_timers_connect,
5126 no_neighbor_timers_connect_cmd,
9ccf14f7 5127 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5128 NO_STR
5129 NEIGHBOR_STR
966f821c 5130 NEIGHBOR_ADDR_STR2
718e3744 5131 "BGP per neighbor timers\n"
8334fd5a
DW
5132 "BGP connect timer\n"
5133 "Connect timer\n")
718e3744 5134{
d62a17ae 5135 int idx_peer = 2;
5136 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5137}
5138
6b0655a2 5139
d62a17ae 5140static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5141 const char *time_str, int set)
718e3744 5142{
d62a17ae 5143 int ret;
5144 struct peer *peer;
d7c0a89a 5145 uint32_t routeadv = 0;
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 if (time_str)
5152 routeadv = strtoul(time_str, NULL, 10);
718e3744 5153
d62a17ae 5154 if (set)
5155 ret = peer_advertise_interval_set(peer, routeadv);
5156 else
5157 ret = peer_advertise_interval_unset(peer);
718e3744 5158
d62a17ae 5159 return bgp_vty_return(vty, ret);
718e3744 5160}
5161
5162DEFUN (neighbor_advertise_interval,
5163 neighbor_advertise_interval_cmd,
9ccf14f7 5164 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5165 NEIGHBOR_STR
966f821c 5166 NEIGHBOR_ADDR_STR2
718e3744 5167 "Minimum interval between sending BGP routing updates\n"
5168 "time in seconds\n")
5169{
d62a17ae 5170 int idx_peer = 1;
5171 int idx_number = 3;
5172 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5173 argv[idx_number]->arg, 1);
718e3744 5174}
5175
5176DEFUN (no_neighbor_advertise_interval,
5177 no_neighbor_advertise_interval_cmd,
9ccf14f7 5178 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5179 NO_STR
5180 NEIGHBOR_STR
966f821c 5181 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5182 "Minimum interval between sending BGP routing updates\n"
5183 "time in seconds\n")
718e3744 5184{
d62a17ae 5185 int idx_peer = 2;
5186 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5187}
5188
6b0655a2 5189
518f0eb1
DS
5190/* Time to wait before processing route-map updates */
5191DEFUN (bgp_set_route_map_delay_timer,
5192 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5193 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5194 SET_STR
5195 "BGP route-map delay timer\n"
5196 "Time in secs to wait before processing route-map changes\n"
f414725f 5197 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5198{
d62a17ae 5199 int idx_number = 3;
d7c0a89a 5200 uint32_t rmap_delay_timer;
d62a17ae 5201
5202 if (argv[idx_number]->arg) {
5203 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5204 bm->rmap_update_timer = rmap_delay_timer;
5205
5206 /* if the dynamic update handling is being disabled, and a timer
5207 * is
5208 * running, stop the timer and act as if the timer has already
5209 * fired.
5210 */
5211 if (!rmap_delay_timer && bm->t_rmap_update) {
5212 BGP_TIMER_OFF(bm->t_rmap_update);
5213 thread_execute(bm->master, bgp_route_map_update_timer,
5214 NULL, 0);
5215 }
5216 return CMD_SUCCESS;
5217 } else {
5218 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5219 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5220 }
518f0eb1
DS
5221}
5222
5223DEFUN (no_bgp_set_route_map_delay_timer,
5224 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5225 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5226 NO_STR
3a2d747c 5227 BGP_STR
518f0eb1 5228 "Default BGP route-map delay timer\n"
8334fd5a
DW
5229 "Reset to default time to wait for processing route-map changes\n"
5230 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5231{
518f0eb1 5232
d62a17ae 5233 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5234
d62a17ae 5235 return CMD_SUCCESS;
518f0eb1
DS
5236}
5237
f414725f 5238
718e3744 5239/* neighbor interface */
d62a17ae 5240static int peer_interface_vty(struct vty *vty, const char *ip_str,
5241 const char *str)
718e3744 5242{
d62a17ae 5243 struct peer *peer;
718e3744 5244
d62a17ae 5245 peer = peer_lookup_vty(vty, ip_str);
5246 if (!peer || peer->conf_if) {
5247 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5248 return CMD_WARNING_CONFIG_FAILED;
5249 }
718e3744 5250
d62a17ae 5251 if (str)
5252 peer_interface_set(peer, str);
5253 else
5254 peer_interface_unset(peer);
718e3744 5255
d62a17ae 5256 return CMD_SUCCESS;
718e3744 5257}
5258
5259DEFUN (neighbor_interface,
5260 neighbor_interface_cmd,
9ccf14f7 5261 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5262 NEIGHBOR_STR
5263 NEIGHBOR_ADDR_STR
5264 "Interface\n"
5265 "Interface name\n")
5266{
d62a17ae 5267 int idx_ip = 1;
5268 int idx_word = 3;
5269 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5270}
5271
5272DEFUN (no_neighbor_interface,
5273 no_neighbor_interface_cmd,
9ccf14f7 5274 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5275 NO_STR
5276 NEIGHBOR_STR
16cedbb0 5277 NEIGHBOR_ADDR_STR2
718e3744 5278 "Interface\n"
5279 "Interface name\n")
5280{
d62a17ae 5281 int idx_peer = 2;
5282 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5283}
6b0655a2 5284
718e3744 5285DEFUN (neighbor_distribute_list,
5286 neighbor_distribute_list_cmd,
9ccf14f7 5287 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5288 NEIGHBOR_STR
5289 NEIGHBOR_ADDR_STR2
5290 "Filter updates to/from this neighbor\n"
5291 "IP access-list number\n"
5292 "IP access-list number (expanded range)\n"
5293 "IP Access-list name\n"
5294 "Filter incoming updates\n"
5295 "Filter outgoing updates\n")
5296{
d62a17ae 5297 int idx_peer = 1;
5298 int idx_acl = 3;
5299 int direct, ret;
5300 struct peer *peer;
a8206004 5301
d62a17ae 5302 const char *pstr = argv[idx_peer]->arg;
5303 const char *acl = argv[idx_acl]->arg;
5304 const char *inout = argv[argc - 1]->text;
a8206004 5305
d62a17ae 5306 peer = peer_and_group_lookup_vty(vty, pstr);
5307 if (!peer)
5308 return CMD_WARNING_CONFIG_FAILED;
a8206004 5309
d62a17ae 5310 /* Check filter direction. */
5311 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5312 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5313 direct, acl);
a8206004 5314
d62a17ae 5315 return bgp_vty_return(vty, ret);
718e3744 5316}
5317
d62a17ae 5318ALIAS_HIDDEN(
5319 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5320 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5321 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5322 "Filter updates to/from this neighbor\n"
5323 "IP access-list number\n"
5324 "IP access-list number (expanded range)\n"
5325 "IP Access-list name\n"
5326 "Filter incoming updates\n"
5327 "Filter outgoing updates\n")
596c17ba 5328
718e3744 5329DEFUN (no_neighbor_distribute_list,
5330 no_neighbor_distribute_list_cmd,
9ccf14f7 5331 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5332 NO_STR
5333 NEIGHBOR_STR
5334 NEIGHBOR_ADDR_STR2
5335 "Filter updates to/from this neighbor\n"
5336 "IP access-list number\n"
5337 "IP access-list number (expanded range)\n"
5338 "IP Access-list name\n"
5339 "Filter incoming updates\n"
5340 "Filter outgoing updates\n")
5341{
d62a17ae 5342 int idx_peer = 2;
5343 int direct, ret;
5344 struct peer *peer;
a8206004 5345
d62a17ae 5346 const char *pstr = argv[idx_peer]->arg;
5347 const char *inout = argv[argc - 1]->text;
a8206004 5348
d62a17ae 5349 peer = peer_and_group_lookup_vty(vty, pstr);
5350 if (!peer)
5351 return CMD_WARNING_CONFIG_FAILED;
a8206004 5352
d62a17ae 5353 /* Check filter direction. */
5354 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5355 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5356 direct);
a8206004 5357
d62a17ae 5358 return bgp_vty_return(vty, ret);
718e3744 5359}
6b0655a2 5360
d62a17ae 5361ALIAS_HIDDEN(
5362 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5363 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5364 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5365 "Filter updates to/from this neighbor\n"
5366 "IP access-list number\n"
5367 "IP access-list number (expanded range)\n"
5368 "IP Access-list name\n"
5369 "Filter incoming updates\n"
5370 "Filter outgoing updates\n")
596c17ba 5371
718e3744 5372/* Set prefix list to the peer. */
d62a17ae 5373static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5374 afi_t afi, safi_t safi,
5375 const char *name_str,
5376 const char *direct_str)
718e3744 5377{
d62a17ae 5378 int ret;
d62a17ae 5379 int direct = FILTER_IN;
cf9ac8bf 5380 struct peer *peer;
718e3744 5381
d62a17ae 5382 peer = peer_and_group_lookup_vty(vty, ip_str);
5383 if (!peer)
5384 return CMD_WARNING_CONFIG_FAILED;
718e3744 5385
d62a17ae 5386 /* Check filter direction. */
5387 if (strncmp(direct_str, "i", 1) == 0)
5388 direct = FILTER_IN;
5389 else if (strncmp(direct_str, "o", 1) == 0)
5390 direct = FILTER_OUT;
718e3744 5391
d62a17ae 5392 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5393
d62a17ae 5394 return bgp_vty_return(vty, ret);
718e3744 5395}
5396
d62a17ae 5397static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5398 afi_t afi, safi_t safi,
5399 const char *direct_str)
718e3744 5400{
d62a17ae 5401 int ret;
5402 struct peer *peer;
5403 int direct = FILTER_IN;
718e3744 5404
d62a17ae 5405 peer = peer_and_group_lookup_vty(vty, ip_str);
5406 if (!peer)
5407 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5408
d62a17ae 5409 /* Check filter direction. */
5410 if (strncmp(direct_str, "i", 1) == 0)
5411 direct = FILTER_IN;
5412 else if (strncmp(direct_str, "o", 1) == 0)
5413 direct = FILTER_OUT;
718e3744 5414
d62a17ae 5415 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5416
d62a17ae 5417 return bgp_vty_return(vty, ret);
718e3744 5418}
5419
5420DEFUN (neighbor_prefix_list,
5421 neighbor_prefix_list_cmd,
9ccf14f7 5422 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5423 NEIGHBOR_STR
5424 NEIGHBOR_ADDR_STR2
5425 "Filter updates to/from this neighbor\n"
5426 "Name of a prefix list\n"
5427 "Filter incoming updates\n"
5428 "Filter outgoing updates\n")
5429{
d62a17ae 5430 int idx_peer = 1;
5431 int idx_word = 3;
5432 int idx_in_out = 4;
5433 return peer_prefix_list_set_vty(
5434 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5435 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5436}
5437
d62a17ae 5438ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5439 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5440 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5441 "Filter updates to/from this neighbor\n"
5442 "Name of a prefix list\n"
5443 "Filter incoming updates\n"
5444 "Filter outgoing updates\n")
596c17ba 5445
718e3744 5446DEFUN (no_neighbor_prefix_list,
5447 no_neighbor_prefix_list_cmd,
9ccf14f7 5448 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5449 NO_STR
5450 NEIGHBOR_STR
5451 NEIGHBOR_ADDR_STR2
5452 "Filter updates to/from this neighbor\n"
5453 "Name of a prefix list\n"
5454 "Filter incoming updates\n"
5455 "Filter outgoing updates\n")
5456{
d62a17ae 5457 int idx_peer = 2;
5458 int idx_in_out = 5;
5459 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5460 bgp_node_afi(vty), bgp_node_safi(vty),
5461 argv[idx_in_out]->arg);
718e3744 5462}
6b0655a2 5463
d62a17ae 5464ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5465 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5466 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5467 "Filter updates to/from this neighbor\n"
5468 "Name of a prefix list\n"
5469 "Filter incoming updates\n"
5470 "Filter outgoing updates\n")
596c17ba 5471
d62a17ae 5472static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5473 safi_t safi, const char *name_str,
5474 const char *direct_str)
718e3744 5475{
d62a17ae 5476 int ret;
5477 struct peer *peer;
5478 int direct = FILTER_IN;
718e3744 5479
d62a17ae 5480 peer = peer_and_group_lookup_vty(vty, ip_str);
5481 if (!peer)
5482 return CMD_WARNING_CONFIG_FAILED;
718e3744 5483
d62a17ae 5484 /* Check filter direction. */
5485 if (strncmp(direct_str, "i", 1) == 0)
5486 direct = FILTER_IN;
5487 else if (strncmp(direct_str, "o", 1) == 0)
5488 direct = FILTER_OUT;
718e3744 5489
d62a17ae 5490 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5491
d62a17ae 5492 return bgp_vty_return(vty, ret);
718e3744 5493}
5494
d62a17ae 5495static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5496 safi_t safi, const char *direct_str)
718e3744 5497{
d62a17ae 5498 int ret;
5499 struct peer *peer;
5500 int direct = FILTER_IN;
718e3744 5501
d62a17ae 5502 peer = peer_and_group_lookup_vty(vty, ip_str);
5503 if (!peer)
5504 return CMD_WARNING_CONFIG_FAILED;
718e3744 5505
d62a17ae 5506 /* Check filter direction. */
5507 if (strncmp(direct_str, "i", 1) == 0)
5508 direct = FILTER_IN;
5509 else if (strncmp(direct_str, "o", 1) == 0)
5510 direct = FILTER_OUT;
718e3744 5511
d62a17ae 5512 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5513
d62a17ae 5514 return bgp_vty_return(vty, ret);
718e3744 5515}
5516
5517DEFUN (neighbor_filter_list,
5518 neighbor_filter_list_cmd,
9ccf14f7 5519 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5520 NEIGHBOR_STR
5521 NEIGHBOR_ADDR_STR2
5522 "Establish BGP filters\n"
5523 "AS path access-list name\n"
5524 "Filter incoming routes\n"
5525 "Filter outgoing routes\n")
5526{
d62a17ae 5527 int idx_peer = 1;
5528 int idx_word = 3;
5529 int idx_in_out = 4;
5530 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5531 bgp_node_safi(vty), argv[idx_word]->arg,
5532 argv[idx_in_out]->arg);
718e3744 5533}
5534
d62a17ae 5535ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5536 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5537 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5538 "Establish BGP filters\n"
5539 "AS path access-list name\n"
5540 "Filter incoming routes\n"
5541 "Filter outgoing routes\n")
596c17ba 5542
718e3744 5543DEFUN (no_neighbor_filter_list,
5544 no_neighbor_filter_list_cmd,
9ccf14f7 5545 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5546 NO_STR
5547 NEIGHBOR_STR
5548 NEIGHBOR_ADDR_STR2
5549 "Establish BGP filters\n"
5550 "AS path access-list name\n"
5551 "Filter incoming routes\n"
5552 "Filter outgoing routes\n")
5553{
d62a17ae 5554 int idx_peer = 2;
5555 int idx_in_out = 5;
5556 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5557 bgp_node_afi(vty), bgp_node_safi(vty),
5558 argv[idx_in_out]->arg);
718e3744 5559}
6b0655a2 5560
d62a17ae 5561ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5562 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5563 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5564 "Establish BGP filters\n"
5565 "AS path access-list name\n"
5566 "Filter incoming routes\n"
5567 "Filter outgoing routes\n")
596c17ba 5568
718e3744 5569/* Set route-map to the peer. */
d62a17ae 5570static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5571 afi_t afi, safi_t safi, const char *name_str,
5572 const char *direct_str)
718e3744 5573{
d62a17ae 5574 int ret;
5575 struct peer *peer;
5576 int direct = RMAP_IN;
718e3744 5577
d62a17ae 5578 peer = peer_and_group_lookup_vty(vty, ip_str);
5579 if (!peer)
5580 return CMD_WARNING_CONFIG_FAILED;
718e3744 5581
d62a17ae 5582 /* Check filter direction. */
5583 if (strncmp(direct_str, "in", 2) == 0)
5584 direct = RMAP_IN;
5585 else if (strncmp(direct_str, "o", 1) == 0)
5586 direct = RMAP_OUT;
718e3744 5587
d62a17ae 5588 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5589
d62a17ae 5590 return bgp_vty_return(vty, ret);
718e3744 5591}
5592
d62a17ae 5593static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5594 afi_t afi, safi_t safi,
5595 const char *direct_str)
718e3744 5596{
d62a17ae 5597 int ret;
5598 struct peer *peer;
5599 int direct = RMAP_IN;
718e3744 5600
d62a17ae 5601 peer = peer_and_group_lookup_vty(vty, ip_str);
5602 if (!peer)
5603 return CMD_WARNING_CONFIG_FAILED;
718e3744 5604
d62a17ae 5605 /* Check filter direction. */
5606 if (strncmp(direct_str, "in", 2) == 0)
5607 direct = RMAP_IN;
5608 else if (strncmp(direct_str, "o", 1) == 0)
5609 direct = RMAP_OUT;
718e3744 5610
d62a17ae 5611 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5612
d62a17ae 5613 return bgp_vty_return(vty, ret);
718e3744 5614}
5615
5616DEFUN (neighbor_route_map,
5617 neighbor_route_map_cmd,
9ccf14f7 5618 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5619 NEIGHBOR_STR
5620 NEIGHBOR_ADDR_STR2
5621 "Apply route map to neighbor\n"
5622 "Name of route map\n"
5623 "Apply map to incoming routes\n"
2a3d5731 5624 "Apply map to outbound routes\n")
718e3744 5625{
d62a17ae 5626 int idx_peer = 1;
5627 int idx_word = 3;
5628 int idx_in_out = 4;
5629 return peer_route_map_set_vty(
5630 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5631 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5632}
5633
d62a17ae 5634ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5635 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5636 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5637 "Apply route map to neighbor\n"
5638 "Name of route map\n"
5639 "Apply map to incoming routes\n"
5640 "Apply map to outbound routes\n")
596c17ba 5641
718e3744 5642DEFUN (no_neighbor_route_map,
5643 no_neighbor_route_map_cmd,
9ccf14f7 5644 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5645 NO_STR
5646 NEIGHBOR_STR
5647 NEIGHBOR_ADDR_STR2
5648 "Apply route map to neighbor\n"
5649 "Name of route map\n"
5650 "Apply map to incoming routes\n"
2a3d5731 5651 "Apply map to outbound routes\n")
718e3744 5652{
d62a17ae 5653 int idx_peer = 2;
5654 int idx_in_out = 5;
5655 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5656 bgp_node_afi(vty), bgp_node_safi(vty),
5657 argv[idx_in_out]->arg);
718e3744 5658}
6b0655a2 5659
d62a17ae 5660ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5661 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5662 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5663 "Apply route map to neighbor\n"
5664 "Name of route map\n"
5665 "Apply map to incoming routes\n"
5666 "Apply map to outbound routes\n")
596c17ba 5667
718e3744 5668/* Set unsuppress-map to the peer. */
d62a17ae 5669static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5670 afi_t afi, safi_t safi,
5671 const char *name_str)
718e3744 5672{
d62a17ae 5673 int ret;
5674 struct peer *peer;
718e3744 5675
d62a17ae 5676 peer = peer_and_group_lookup_vty(vty, ip_str);
5677 if (!peer)
5678 return CMD_WARNING_CONFIG_FAILED;
718e3744 5679
d62a17ae 5680 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5681
d62a17ae 5682 return bgp_vty_return(vty, ret);
718e3744 5683}
5684
5685/* Unset route-map from the peer. */
d62a17ae 5686static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5687 afi_t afi, safi_t safi)
718e3744 5688{
d62a17ae 5689 int ret;
5690 struct peer *peer;
718e3744 5691
d62a17ae 5692 peer = peer_and_group_lookup_vty(vty, ip_str);
5693 if (!peer)
5694 return CMD_WARNING_CONFIG_FAILED;
718e3744 5695
d62a17ae 5696 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5697
d62a17ae 5698 return bgp_vty_return(vty, ret);
718e3744 5699}
5700
5701DEFUN (neighbor_unsuppress_map,
5702 neighbor_unsuppress_map_cmd,
9ccf14f7 5703 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5704 NEIGHBOR_STR
5705 NEIGHBOR_ADDR_STR2
5706 "Route-map to selectively unsuppress suppressed routes\n"
5707 "Name of route map\n")
5708{
d62a17ae 5709 int idx_peer = 1;
5710 int idx_word = 3;
5711 return peer_unsuppress_map_set_vty(
5712 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5713 argv[idx_word]->arg);
718e3744 5714}
5715
d62a17ae 5716ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5717 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5718 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5719 "Route-map to selectively unsuppress suppressed routes\n"
5720 "Name of route map\n")
596c17ba 5721
718e3744 5722DEFUN (no_neighbor_unsuppress_map,
5723 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5724 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5725 NO_STR
5726 NEIGHBOR_STR
5727 NEIGHBOR_ADDR_STR2
5728 "Route-map to selectively unsuppress suppressed routes\n"
5729 "Name of route map\n")
5730{
d62a17ae 5731 int idx_peer = 2;
5732 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5733 bgp_node_afi(vty),
5734 bgp_node_safi(vty));
718e3744 5735}
6b0655a2 5736
d62a17ae 5737ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5738 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5739 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5740 "Route-map to selectively unsuppress suppressed routes\n"
5741 "Name of route map\n")
596c17ba 5742
d62a17ae 5743static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5744 afi_t afi, safi_t safi,
5745 const char *num_str,
5746 const char *threshold_str, int warning,
5747 const char *restart_str)
718e3744 5748{
d62a17ae 5749 int ret;
5750 struct peer *peer;
d7c0a89a
QY
5751 uint32_t max;
5752 uint8_t threshold;
5753 uint16_t restart;
718e3744 5754
d62a17ae 5755 peer = peer_and_group_lookup_vty(vty, ip_str);
5756 if (!peer)
5757 return CMD_WARNING_CONFIG_FAILED;
718e3744 5758
d62a17ae 5759 max = strtoul(num_str, NULL, 10);
5760 if (threshold_str)
5761 threshold = atoi(threshold_str);
5762 else
5763 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5764
d62a17ae 5765 if (restart_str)
5766 restart = atoi(restart_str);
5767 else
5768 restart = 0;
0a486e5f 5769
d62a17ae 5770 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5771 restart);
718e3744 5772
d62a17ae 5773 return bgp_vty_return(vty, ret);
718e3744 5774}
5775
d62a17ae 5776static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5777 afi_t afi, safi_t safi)
718e3744 5778{
d62a17ae 5779 int ret;
5780 struct peer *peer;
718e3744 5781
d62a17ae 5782 peer = peer_and_group_lookup_vty(vty, ip_str);
5783 if (!peer)
5784 return CMD_WARNING_CONFIG_FAILED;
718e3744 5785
d62a17ae 5786 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5787
d62a17ae 5788 return bgp_vty_return(vty, ret);
718e3744 5789}
5790
5791/* Maximum number of prefix configuration. prefix count is different
5792 for each peer configuration. So this configuration can be set for
5793 each peer configuration. */
5794DEFUN (neighbor_maximum_prefix,
5795 neighbor_maximum_prefix_cmd,
9ccf14f7 5796 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5797 NEIGHBOR_STR
5798 NEIGHBOR_ADDR_STR2
5799 "Maximum number of prefix accept from this peer\n"
5800 "maximum no. of prefix limit\n")
5801{
d62a17ae 5802 int idx_peer = 1;
5803 int idx_number = 3;
5804 return peer_maximum_prefix_set_vty(
5805 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5806 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5807}
5808
d62a17ae 5809ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5810 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5811 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5812 "Maximum number of prefix accept from this peer\n"
5813 "maximum no. of prefix limit\n")
596c17ba 5814
e0701b79 5815DEFUN (neighbor_maximum_prefix_threshold,
5816 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5817 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5818 NEIGHBOR_STR
5819 NEIGHBOR_ADDR_STR2
5820 "Maximum number of prefix accept from this peer\n"
5821 "maximum no. of prefix limit\n"
5822 "Threshold value (%) at which to generate a warning msg\n")
5823{
d62a17ae 5824 int idx_peer = 1;
5825 int idx_number = 3;
5826 int idx_number_2 = 4;
5827 return peer_maximum_prefix_set_vty(
5828 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5829 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5830}
e0701b79 5831
d62a17ae 5832ALIAS_HIDDEN(
5833 neighbor_maximum_prefix_threshold,
5834 neighbor_maximum_prefix_threshold_hidden_cmd,
5835 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5836 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5837 "Maximum number of prefix accept from this peer\n"
5838 "maximum no. of prefix limit\n"
5839 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5840
718e3744 5841DEFUN (neighbor_maximum_prefix_warning,
5842 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5843 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5844 NEIGHBOR_STR
5845 NEIGHBOR_ADDR_STR2
5846 "Maximum number of prefix accept from this peer\n"
5847 "maximum no. of prefix limit\n"
5848 "Only give warning message when limit is exceeded\n")
5849{
d62a17ae 5850 int idx_peer = 1;
5851 int idx_number = 3;
5852 return peer_maximum_prefix_set_vty(
5853 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5854 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5855}
5856
d62a17ae 5857ALIAS_HIDDEN(
5858 neighbor_maximum_prefix_warning,
5859 neighbor_maximum_prefix_warning_hidden_cmd,
5860 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5861 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5862 "Maximum number of prefix accept from this peer\n"
5863 "maximum no. of prefix limit\n"
5864 "Only give warning message when limit is exceeded\n")
596c17ba 5865
e0701b79 5866DEFUN (neighbor_maximum_prefix_threshold_warning,
5867 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5868 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5869 NEIGHBOR_STR
5870 NEIGHBOR_ADDR_STR2
5871 "Maximum number of prefix accept from this peer\n"
5872 "maximum no. of prefix limit\n"
5873 "Threshold value (%) at which to generate a warning msg\n"
5874 "Only give warning message when limit is exceeded\n")
5875{
d62a17ae 5876 int idx_peer = 1;
5877 int idx_number = 3;
5878 int idx_number_2 = 4;
5879 return peer_maximum_prefix_set_vty(
5880 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5881 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5882}
5883
d62a17ae 5884ALIAS_HIDDEN(
5885 neighbor_maximum_prefix_threshold_warning,
5886 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5887 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5888 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5889 "Maximum number of prefix accept from this peer\n"
5890 "maximum no. of prefix limit\n"
5891 "Threshold value (%) at which to generate a warning msg\n"
5892 "Only give warning message when limit is exceeded\n")
596c17ba 5893
0a486e5f 5894DEFUN (neighbor_maximum_prefix_restart,
5895 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5896 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5897 NEIGHBOR_STR
5898 NEIGHBOR_ADDR_STR2
5899 "Maximum number of prefix accept from this peer\n"
5900 "maximum no. of prefix limit\n"
5901 "Restart bgp connection after limit is exceeded\n"
efd7904e 5902 "Restart interval in minutes\n")
0a486e5f 5903{
d62a17ae 5904 int idx_peer = 1;
5905 int idx_number = 3;
5906 int idx_number_2 = 5;
5907 return peer_maximum_prefix_set_vty(
5908 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5909 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5910}
5911
d62a17ae 5912ALIAS_HIDDEN(
5913 neighbor_maximum_prefix_restart,
5914 neighbor_maximum_prefix_restart_hidden_cmd,
5915 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5916 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5917 "Maximum number of prefix accept from this peer\n"
5918 "maximum no. of prefix limit\n"
5919 "Restart bgp connection after limit is exceeded\n"
efd7904e 5920 "Restart interval in minutes\n")
596c17ba 5921
0a486e5f 5922DEFUN (neighbor_maximum_prefix_threshold_restart,
5923 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5924 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5925 NEIGHBOR_STR
5926 NEIGHBOR_ADDR_STR2
16cedbb0 5927 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5928 "maximum no. of prefix limit\n"
5929 "Threshold value (%) at which to generate a warning msg\n"
5930 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5931 "Restart interval in minutes\n")
0a486e5f 5932{
d62a17ae 5933 int idx_peer = 1;
5934 int idx_number = 3;
5935 int idx_number_2 = 4;
5936 int idx_number_3 = 6;
5937 return peer_maximum_prefix_set_vty(
5938 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5939 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5940 argv[idx_number_3]->arg);
5941}
5942
5943ALIAS_HIDDEN(
5944 neighbor_maximum_prefix_threshold_restart,
5945 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5946 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5947 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5948 "Maximum number of prefixes to accept from this peer\n"
5949 "maximum no. of prefix limit\n"
5950 "Threshold value (%) at which to generate a warning msg\n"
5951 "Restart bgp connection after limit is exceeded\n"
5952 "Restart interval in minutes\n")
596c17ba 5953
718e3744 5954DEFUN (no_neighbor_maximum_prefix,
5955 no_neighbor_maximum_prefix_cmd,
d04c479d 5956 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5957 NO_STR
5958 NEIGHBOR_STR
5959 NEIGHBOR_ADDR_STR2
16cedbb0 5960 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5961 "maximum no. of prefix limit\n"
5962 "Threshold value (%) at which to generate a warning msg\n"
5963 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5964 "Restart interval in minutes\n"
31500417 5965 "Only give warning message when limit is exceeded\n")
718e3744 5966{
d62a17ae 5967 int idx_peer = 2;
5968 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5969 bgp_node_afi(vty),
5970 bgp_node_safi(vty));
718e3744 5971}
e52702f2 5972
d62a17ae 5973ALIAS_HIDDEN(
5974 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5975 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5976 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5977 "Maximum number of prefixes to accept from this peer\n"
5978 "maximum no. of prefix limit\n"
5979 "Threshold value (%) at which to generate a warning msg\n"
5980 "Restart bgp connection after limit is exceeded\n"
5981 "Restart interval in minutes\n"
5982 "Only give warning message when limit is exceeded\n")
596c17ba 5983
718e3744 5984
718e3744 5985/* "neighbor allowas-in" */
5986DEFUN (neighbor_allowas_in,
5987 neighbor_allowas_in_cmd,
fd8503f5 5988 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5989 NEIGHBOR_STR
5990 NEIGHBOR_ADDR_STR2
31500417 5991 "Accept as-path with my AS present in it\n"
fd8503f5
QY
5992 "Number of occurances of AS number\n"
5993 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5994{
d62a17ae 5995 int idx_peer = 1;
5996 int idx_number_origin = 3;
5997 int ret;
5998 int origin = 0;
5999 struct peer *peer;
6000 int allow_num = 0;
6001
6002 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6003 if (!peer)
6004 return CMD_WARNING_CONFIG_FAILED;
6005
6006 if (argc <= idx_number_origin)
6007 allow_num = 3;
6008 else {
6009 if (argv[idx_number_origin]->type == WORD_TKN)
6010 origin = 1;
6011 else
6012 allow_num = atoi(argv[idx_number_origin]->arg);
6013 }
6014
6015 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6016 allow_num, origin);
6017
6018 return bgp_vty_return(vty, ret);
6019}
6020
6021ALIAS_HIDDEN(
6022 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6023 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6024 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6025 "Accept as-path with my AS present in it\n"
6026 "Number of occurances of AS number\n"
6027 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6028
718e3744 6029DEFUN (no_neighbor_allowas_in,
6030 no_neighbor_allowas_in_cmd,
fd8503f5 6031 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6032 NO_STR
6033 NEIGHBOR_STR
6034 NEIGHBOR_ADDR_STR2
8334fd5a 6035 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
6036 "Number of occurances of AS number\n"
6037 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6038{
d62a17ae 6039 int idx_peer = 2;
6040 int ret;
6041 struct peer *peer;
718e3744 6042
d62a17ae 6043 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6044 if (!peer)
6045 return CMD_WARNING_CONFIG_FAILED;
718e3744 6046
d62a17ae 6047 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6048 bgp_node_safi(vty));
718e3744 6049
d62a17ae 6050 return bgp_vty_return(vty, ret);
718e3744 6051}
6b0655a2 6052
d62a17ae 6053ALIAS_HIDDEN(
6054 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6055 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6056 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6057 "allow local ASN appears in aspath attribute\n"
6058 "Number of occurances of AS number\n"
6059 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6060
fa411a21
NH
6061DEFUN (neighbor_ttl_security,
6062 neighbor_ttl_security_cmd,
7ebe625c 6063 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6064 NEIGHBOR_STR
7ebe625c 6065 NEIGHBOR_ADDR_STR2
16cedbb0 6066 "BGP ttl-security parameters\n"
d7fa34c1
QY
6067 "Specify the maximum number of hops to the BGP peer\n"
6068 "Number of hops to BGP peer\n")
fa411a21 6069{
d62a17ae 6070 int idx_peer = 1;
6071 int idx_number = 4;
6072 struct peer *peer;
6073 int gtsm_hops;
6074
6075 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6076 if (!peer)
6077 return CMD_WARNING_CONFIG_FAILED;
6078
6079 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6080
7ebe625c
QY
6081 /*
6082 * If 'neighbor swpX', then this is for directly connected peers,
6083 * we should not accept a ttl-security hops value greater than 1.
6084 */
6085 if (peer->conf_if && (gtsm_hops > 1)) {
6086 vty_out(vty,
6087 "%s is directly connected peer, hops cannot exceed 1\n",
6088 argv[idx_peer]->arg);
6089 return CMD_WARNING_CONFIG_FAILED;
6090 }
6091
d62a17ae 6092 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6093}
6094
6095DEFUN (no_neighbor_ttl_security,
6096 no_neighbor_ttl_security_cmd,
7ebe625c 6097 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6098 NO_STR
6099 NEIGHBOR_STR
7ebe625c 6100 NEIGHBOR_ADDR_STR2
16cedbb0 6101 "BGP ttl-security parameters\n"
3a2d747c
QY
6102 "Specify the maximum number of hops to the BGP peer\n"
6103 "Number of hops to BGP peer\n")
fa411a21 6104{
d62a17ae 6105 int idx_peer = 2;
6106 struct peer *peer;
fa411a21 6107
d62a17ae 6108 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6109 if (!peer)
6110 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6111
d62a17ae 6112 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6113}
6b0655a2 6114
adbac85e
DW
6115DEFUN (neighbor_addpath_tx_all_paths,
6116 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6117 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6118 NEIGHBOR_STR
6119 NEIGHBOR_ADDR_STR2
6120 "Use addpath to advertise all paths to a neighbor\n")
6121{
d62a17ae 6122 int idx_peer = 1;
6123 struct peer *peer;
adbac85e 6124
d62a17ae 6125 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6126 if (!peer)
6127 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6128
d62a17ae 6129 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6130 bgp_node_safi(vty),
6131 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6132}
6133
d62a17ae 6134ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6135 neighbor_addpath_tx_all_paths_hidden_cmd,
6136 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6137 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6138 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6139
adbac85e
DW
6140DEFUN (no_neighbor_addpath_tx_all_paths,
6141 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6142 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6143 NO_STR
6144 NEIGHBOR_STR
6145 NEIGHBOR_ADDR_STR2
6146 "Use addpath to advertise all paths to a neighbor\n")
6147{
d62a17ae 6148 int idx_peer = 2;
6149 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6150 bgp_node_afi(vty), bgp_node_safi(vty),
6151 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6152}
6153
d62a17ae 6154ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6155 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6156 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6157 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6158 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6159
06370dac
DW
6160DEFUN (neighbor_addpath_tx_bestpath_per_as,
6161 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6162 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6163 NEIGHBOR_STR
6164 NEIGHBOR_ADDR_STR2
6165 "Use addpath to advertise the bestpath per each neighboring AS\n")
6166{
d62a17ae 6167 int idx_peer = 1;
6168 struct peer *peer;
06370dac 6169
d62a17ae 6170 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6171 if (!peer)
6172 return CMD_WARNING_CONFIG_FAILED;
06370dac 6173
d62a17ae 6174 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6175 bgp_node_safi(vty),
6176 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6177}
6178
d62a17ae 6179ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6180 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6181 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6182 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6183 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6184
06370dac
DW
6185DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6186 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6187 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6188 NO_STR
6189 NEIGHBOR_STR
6190 NEIGHBOR_ADDR_STR2
6191 "Use addpath to advertise the bestpath per each neighboring AS\n")
6192{
d62a17ae 6193 int idx_peer = 2;
6194 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6195 bgp_node_afi(vty), bgp_node_safi(vty),
6196 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6197}
6198
d62a17ae 6199ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6200 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6201 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6202 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6203 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6204
b9c7bc5a
PZ
6205static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6206 struct ecommunity **list)
ddb5b488 6207{
b9c7bc5a
PZ
6208 struct ecommunity *ecom = NULL;
6209 struct ecommunity *ecomadd;
ddb5b488 6210
b9c7bc5a 6211 for (; argc; --argc, ++argv) {
ddb5b488 6212
b9c7bc5a
PZ
6213 ecomadd = ecommunity_str2com(argv[0]->arg,
6214 ECOMMUNITY_ROUTE_TARGET, 0);
6215 if (!ecomadd) {
6216 vty_out(vty, "Malformed community-list value\n");
6217 if (ecom)
6218 ecommunity_free(&ecom);
6219 return CMD_WARNING_CONFIG_FAILED;
6220 }
ddb5b488 6221
b9c7bc5a
PZ
6222 if (ecom) {
6223 ecommunity_merge(ecom, ecomadd);
6224 ecommunity_free(&ecomadd);
6225 } else {
6226 ecom = ecomadd;
6227 }
6228 }
6229
6230 if (*list) {
6231 ecommunity_free(&*list);
ddb5b488 6232 }
b9c7bc5a
PZ
6233 *list = ecom;
6234
6235 return CMD_SUCCESS;
ddb5b488
PZ
6236}
6237
0ca70ba5
DS
6238/*
6239 * v2vimport is true if we are handling a `import vrf ...` command
6240 */
6241static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6242{
0ca70ba5
DS
6243 afi_t afi;
6244
ddb5b488 6245 switch (vty->node) {
b9c7bc5a 6246 case BGP_IPV4_NODE:
0ca70ba5
DS
6247 afi = AFI_IP;
6248 break;
b9c7bc5a 6249 case BGP_IPV6_NODE:
0ca70ba5
DS
6250 afi = AFI_IP6;
6251 break;
ddb5b488
PZ
6252 default:
6253 vty_out(vty,
b9c7bc5a 6254 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6255 return AFI_MAX;
ddb5b488 6256 }
69b07479 6257
0ca70ba5
DS
6258 if (!v2vimport) {
6259 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6260 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6261 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6262 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6263 vty_out(vty,
6264 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6265 return AFI_MAX;
6266 }
6267 } else {
6268 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6269 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6270 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6271 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6272 vty_out(vty,
6273 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6274 return AFI_MAX;
6275 }
6276 }
6277 return afi;
ddb5b488
PZ
6278}
6279
b9c7bc5a
PZ
6280DEFPY (af_rd_vpn_export,
6281 af_rd_vpn_export_cmd,
6282 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6283 NO_STR
ddb5b488 6284 "Specify route distinguisher\n"
b9c7bc5a
PZ
6285 "Between current address-family and vpn\n"
6286 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6287 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6288{
6289 VTY_DECLVAR_CONTEXT(bgp, bgp);
6290 struct prefix_rd prd;
6291 int ret;
ddb5b488 6292 afi_t afi;
b9c7bc5a
PZ
6293 int idx = 0;
6294 int yes = 1;
ddb5b488 6295
b9c7bc5a 6296 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6297 yes = 0;
b9c7bc5a
PZ
6298
6299 if (yes) {
6300 ret = str2prefix_rd(rd_str, &prd);
6301 if (!ret) {
6302 vty_out(vty, "%% Malformed rd\n");
6303 return CMD_WARNING_CONFIG_FAILED;
6304 }
ddb5b488
PZ
6305 }
6306
0ca70ba5 6307 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6308 if (afi == AFI_MAX)
6309 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6310
69b07479
DS
6311 /*
6312 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6313 */
6314 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6315 bgp_get_default(), bgp);
ddb5b488 6316
69b07479
DS
6317 if (yes) {
6318 bgp->vpn_policy[afi].tovpn_rd = prd;
6319 SET_FLAG(bgp->vpn_policy[afi].flags,
6320 BGP_VPN_POLICY_TOVPN_RD_SET);
6321 } else {
6322 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6323 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6324 }
6325
69b07479
DS
6326 /* post-change: re-export vpn routes */
6327 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6328 bgp_get_default(), bgp);
6329
ddb5b488
PZ
6330 return CMD_SUCCESS;
6331}
6332
b9c7bc5a
PZ
6333ALIAS (af_rd_vpn_export,
6334 af_no_rd_vpn_export_cmd,
6335 "no rd vpn export",
ddb5b488 6336 NO_STR
b9c7bc5a
PZ
6337 "Specify route distinguisher\n"
6338 "Between current address-family and vpn\n"
6339 "For routes leaked from current address-family to vpn\n")
ddb5b488 6340
b9c7bc5a
PZ
6341DEFPY (af_label_vpn_export,
6342 af_label_vpn_export_cmd,
e70e9f8e 6343 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6344 NO_STR
ddb5b488 6345 "label value for VRF\n"
b9c7bc5a
PZ
6346 "Between current address-family and vpn\n"
6347 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6348 "Label Value <0-1048575>\n"
6349 "Automatically assign a label\n")
ddb5b488
PZ
6350{
6351 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6352 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6353 afi_t afi;
b9c7bc5a
PZ
6354 int idx = 0;
6355 int yes = 1;
6356
6357 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6358 yes = 0;
ddb5b488 6359
21a16cc2
PZ
6360 /* If "no ...", squash trailing parameter */
6361 if (!yes)
6362 label_auto = NULL;
6363
e70e9f8e
PZ
6364 if (yes) {
6365 if (!label_auto)
6366 label = label_val; /* parser should force unsigned */
6367 }
ddb5b488 6368
0ca70ba5 6369 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6370 if (afi == AFI_MAX)
6371 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6372
e70e9f8e 6373
69b07479
DS
6374 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6375 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6376 /* no change */
6377 return CMD_SUCCESS;
e70e9f8e 6378
69b07479
DS
6379 /*
6380 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6381 */
6382 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6383 bgp_get_default(), bgp);
6384
6385 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6386 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6387
6388 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6389
6390 /*
6391 * label has previously been automatically
6392 * assigned by labelpool: release it
6393 *
6394 * NB if tovpn_label == MPLS_LABEL_NONE it
6395 * means the automatic assignment is in flight
6396 * and therefore the labelpool callback must
6397 * detect that the auto label is not needed.
6398 */
6399
6400 bgp_lp_release(LP_TYPE_VRF,
6401 &bgp->vpn_policy[afi],
6402 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6403 }
69b07479
DS
6404 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6405 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6406 }
ddb5b488 6407
69b07479
DS
6408 bgp->vpn_policy[afi].tovpn_label = label;
6409 if (label_auto) {
6410 SET_FLAG(bgp->vpn_policy[afi].flags,
6411 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6412 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6413 vpn_leak_label_callback);
ddb5b488
PZ
6414 }
6415
69b07479
DS
6416 /* post-change: re-export vpn routes */
6417 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6418 bgp_get_default(), bgp);
6419
ddb5b488
PZ
6420 return CMD_SUCCESS;
6421}
6422
b9c7bc5a
PZ
6423ALIAS (af_label_vpn_export,
6424 af_no_label_vpn_export_cmd,
6425 "no label vpn export",
6426 NO_STR
6427 "label value for VRF\n"
6428 "Between current address-family and vpn\n"
6429 "For routes leaked from current address-family to vpn\n")
ddb5b488 6430
b9c7bc5a
PZ
6431DEFPY (af_nexthop_vpn_export,
6432 af_nexthop_vpn_export_cmd,
6433 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6434 NO_STR
ddb5b488 6435 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6436 "Between current address-family and vpn\n"
6437 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6438 "IPv4 prefix\n"
6439 "IPv6 prefix\n")
6440{
6441 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6442 afi_t afi;
ddb5b488 6443 struct prefix p;
b9c7bc5a
PZ
6444 int idx = 0;
6445 int yes = 1;
ddb5b488 6446
b9c7bc5a 6447 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6448 yes = 0;
b9c7bc5a
PZ
6449
6450 if (yes) {
6451 if (!sockunion2hostprefix(nexthop_str, &p))
6452 return CMD_WARNING_CONFIG_FAILED;
6453 }
ddb5b488 6454
0ca70ba5 6455 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6456 if (afi == AFI_MAX)
6457 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6458
69b07479
DS
6459 /*
6460 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6461 */
6462 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6463 bgp_get_default(), bgp);
ddb5b488 6464
69b07479
DS
6465 if (yes) {
6466 bgp->vpn_policy[afi].tovpn_nexthop = p;
6467 SET_FLAG(bgp->vpn_policy[afi].flags,
6468 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6469 } else {
6470 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6471 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6472 }
6473
69b07479
DS
6474 /* post-change: re-export vpn routes */
6475 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6476 bgp_get_default(), bgp);
6477
ddb5b488
PZ
6478 return CMD_SUCCESS;
6479}
6480
b9c7bc5a
PZ
6481ALIAS (af_nexthop_vpn_export,
6482 af_no_nexthop_vpn_export_cmd,
6483 "no nexthop vpn export",
ddb5b488 6484 NO_STR
b9c7bc5a
PZ
6485 "Specify next hop to use for VRF advertised prefixes\n"
6486 "Between current address-family and vpn\n"
6487 "For routes leaked from current address-family to vpn\n")
ddb5b488 6488
b9c7bc5a 6489static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6490{
b9c7bc5a
PZ
6491 if (!strcmp(dstr, "import")) {
6492 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6493 } else if (!strcmp(dstr, "export")) {
6494 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6495 } else if (!strcmp(dstr, "both")) {
6496 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6497 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6498 } else {
6499 vty_out(vty, "%% direction parse error\n");
6500 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6501 }
ddb5b488
PZ
6502 return CMD_SUCCESS;
6503}
6504
b9c7bc5a
PZ
6505DEFPY (af_rt_vpn_imexport,
6506 af_rt_vpn_imexport_cmd,
6507 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6508 NO_STR
6509 "Specify route target list\n"
ddb5b488 6510 "Specify route target list\n"
b9c7bc5a
PZ
6511 "Between current address-family and vpn\n"
6512 "For routes leaked from vpn to current address-family: match any\n"
6513 "For routes leaked from current address-family to vpn: set\n"
6514 "both import: match any and export: set\n"
ddb5b488
PZ
6515 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6516{
6517 VTY_DECLVAR_CONTEXT(bgp, bgp);
6518 int ret;
6519 struct ecommunity *ecom = NULL;
6520 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6521 vpn_policy_direction_t dir;
6522 afi_t afi;
6523 int idx = 0;
b9c7bc5a 6524 int yes = 1;
ddb5b488 6525
b9c7bc5a 6526 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6527 yes = 0;
b9c7bc5a 6528
0ca70ba5 6529 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6530 if (afi == AFI_MAX)
6531 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6532
b9c7bc5a 6533 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6534 if (ret != CMD_SUCCESS)
6535 return ret;
6536
b9c7bc5a
PZ
6537 if (yes) {
6538 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6539 vty_out(vty, "%% Missing RTLIST\n");
6540 return CMD_WARNING_CONFIG_FAILED;
6541 }
6542 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6543 if (ret != CMD_SUCCESS) {
6544 return ret;
6545 }
ddb5b488
PZ
6546 }
6547
69b07479
DS
6548 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6549 if (!dodir[dir])
ddb5b488 6550 continue;
ddb5b488 6551
69b07479 6552 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6553
69b07479
DS
6554 if (yes) {
6555 if (bgp->vpn_policy[afi].rtlist[dir])
6556 ecommunity_free(
6557 &bgp->vpn_policy[afi].rtlist[dir]);
6558 bgp->vpn_policy[afi].rtlist[dir] =
6559 ecommunity_dup(ecom);
6560 } else {
6561 if (bgp->vpn_policy[afi].rtlist[dir])
6562 ecommunity_free(
6563 &bgp->vpn_policy[afi].rtlist[dir]);
6564 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6565 }
69b07479
DS
6566
6567 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6568 }
69b07479 6569
d555f3e9
PZ
6570 if (ecom)
6571 ecommunity_free(&ecom);
ddb5b488
PZ
6572
6573 return CMD_SUCCESS;
6574}
6575
b9c7bc5a
PZ
6576ALIAS (af_rt_vpn_imexport,
6577 af_no_rt_vpn_imexport_cmd,
6578 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6579 NO_STR
6580 "Specify route target list\n"
b9c7bc5a
PZ
6581 "Specify route target list\n"
6582 "Between current address-family and vpn\n"
6583 "For routes leaked from vpn to current address-family\n"
6584 "For routes leaked from current address-family to vpn\n"
6585 "both import and export\n")
6586
6587DEFPY (af_route_map_vpn_imexport,
6588 af_route_map_vpn_imexport_cmd,
6589/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6590 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6591 NO_STR
ddb5b488 6592 "Specify route map\n"
b9c7bc5a
PZ
6593 "Between current address-family and vpn\n"
6594 "For routes leaked from vpn to current address-family\n"
6595 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6596 "name of route-map\n")
6597{
6598 VTY_DECLVAR_CONTEXT(bgp, bgp);
6599 int ret;
6600 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6601 vpn_policy_direction_t dir;
6602 afi_t afi;
ddb5b488 6603 int idx = 0;
b9c7bc5a 6604 int yes = 1;
ddb5b488 6605
b9c7bc5a 6606 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6607 yes = 0;
b9c7bc5a 6608
0ca70ba5 6609 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6610 if (afi == AFI_MAX)
6611 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6612
b9c7bc5a 6613 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6614 if (ret != CMD_SUCCESS)
6615 return ret;
6616
69b07479
DS
6617 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6618 if (!dodir[dir])
ddb5b488 6619 continue;
ddb5b488 6620
69b07479 6621 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6622
69b07479
DS
6623 if (yes) {
6624 if (bgp->vpn_policy[afi].rmap_name[dir])
6625 XFREE(MTYPE_ROUTE_MAP_NAME,
6626 bgp->vpn_policy[afi].rmap_name[dir]);
6627 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6628 MTYPE_ROUTE_MAP_NAME, rmap_str);
6629 bgp->vpn_policy[afi].rmap[dir] =
6630 route_map_lookup_by_name(rmap_str);
6631 if (!bgp->vpn_policy[afi].rmap[dir])
6632 return CMD_SUCCESS;
6633 } else {
6634 if (bgp->vpn_policy[afi].rmap_name[dir])
6635 XFREE(MTYPE_ROUTE_MAP_NAME,
6636 bgp->vpn_policy[afi].rmap_name[dir]);
6637 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6638 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6639 }
69b07479
DS
6640
6641 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6642 }
6643
6644 return CMD_SUCCESS;
6645}
6646
b9c7bc5a
PZ
6647ALIAS (af_route_map_vpn_imexport,
6648 af_no_route_map_vpn_imexport_cmd,
6649 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6650 NO_STR
6651 "Specify route map\n"
b9c7bc5a
PZ
6652 "Between current address-family and vpn\n"
6653 "For routes leaked from vpn to current address-family\n"
6654 "For routes leaked from current address-family to vpn\n")
6655
bb4f6190
DS
6656DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6657 "[no] import vrf route-map RMAP$rmap_str",
6658 NO_STR
6659 "Import routes from another VRF\n"
6660 "Vrf routes being filtered\n"
6661 "Specify route map\n"
6662 "name of route-map\n")
6663{
6664 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6665 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6666 afi_t afi;
6667 int idx = 0;
6668 int yes = 1;
6669 struct bgp *bgp_default;
6670
6671 if (argv_find(argv, argc, "no", &idx))
6672 yes = 0;
6673
0ca70ba5 6674 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6675 if (afi == AFI_MAX)
6676 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6677
6678 bgp_default = bgp_get_default();
6679 if (!bgp_default) {
6680 int32_t ret;
6681 as_t as = bgp->as;
6682
6683 /* Auto-create assuming the same AS */
6684 ret = bgp_get(&bgp_default, &as, NULL,
6685 BGP_INSTANCE_TYPE_DEFAULT);
6686
6687 if (ret) {
6688 vty_out(vty,
6689 "VRF default is not configured as a bgp instance\n");
6690 return CMD_WARNING;
6691 }
6692 }
6693
69b07479 6694 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6695
69b07479
DS
6696 if (yes) {
6697 if (bgp->vpn_policy[afi].rmap_name[dir])
6698 XFREE(MTYPE_ROUTE_MAP_NAME,
6699 bgp->vpn_policy[afi].rmap_name[dir]);
6700 bgp->vpn_policy[afi].rmap_name[dir] =
6701 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6702 bgp->vpn_policy[afi].rmap[dir] =
6703 route_map_lookup_by_name(rmap_str);
6704 if (!bgp->vpn_policy[afi].rmap[dir])
6705 return CMD_SUCCESS;
6706 } else {
6707 if (bgp->vpn_policy[afi].rmap_name[dir])
6708 XFREE(MTYPE_ROUTE_MAP_NAME,
6709 bgp->vpn_policy[afi].rmap_name[dir]);
6710 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6711 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6712 }
6713
69b07479
DS
6714 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6715
bb4f6190
DS
6716 return CMD_SUCCESS;
6717}
6718
6719ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6720 "no import vrf route-map",
6721 NO_STR
6722 "Import routes from another VRF\n"
6723 "Vrf routes being filtered\n"
6724 "Specify route map\n")
6725
12a844a5
DS
6726DEFPY (bgp_imexport_vrf,
6727 bgp_imexport_vrf_cmd,
6728 "[no] import vrf NAME$import_name",
6729 NO_STR
6730 "Import routes from another VRF\n"
6731 "VRF to import from\n"
6732 "The name of the VRF\n")
6733{
6734 VTY_DECLVAR_CONTEXT(bgp, bgp);
6735 struct listnode *node;
79ef8664
DS
6736 struct bgp *vrf_bgp, *bgp_default;
6737 int32_t ret = 0;
6738 as_t as = bgp->as;
12a844a5
DS
6739 bool remove = false;
6740 int32_t idx = 0;
6741 char *vname;
a8dadcf6 6742 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6743 safi_t safi;
6744 afi_t afi;
6745
867f0cca 6746 if (import_name == NULL) {
6747 vty_out(vty, "%% Missing import name\n");
6748 return CMD_WARNING;
6749 }
6750
12a844a5
DS
6751 if (argv_find(argv, argc, "no", &idx))
6752 remove = true;
6753
0ca70ba5
DS
6754 afi = vpn_policy_getafi(vty, bgp, true);
6755 if (afi == AFI_MAX)
6756 return CMD_WARNING_CONFIG_FAILED;
6757
12a844a5
DS
6758 safi = bgp_node_safi(vty);
6759
25679caa
DS
6760 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6761 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6762 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6763 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6764 remove ? "unimport" : "import", import_name);
6765 return CMD_WARNING;
6766 }
6767
79ef8664
DS
6768 bgp_default = bgp_get_default();
6769 if (!bgp_default) {
6770 /* Auto-create assuming the same AS */
6771 ret = bgp_get(&bgp_default, &as, NULL,
6772 BGP_INSTANCE_TYPE_DEFAULT);
6773
6774 if (ret) {
6775 vty_out(vty,
6776 "VRF default is not configured as a bgp instance\n");
6777 return CMD_WARNING;
6778 }
6779 }
6780
12a844a5
DS
6781 vrf_bgp = bgp_lookup_by_name(import_name);
6782 if (!vrf_bgp) {
79ef8664
DS
6783 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6784 vrf_bgp = bgp_default;
6785 else
0fb8d6e6
DS
6786 /* Auto-create assuming the same AS */
6787 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6788
6e2c7fe6 6789 if (ret) {
020a3f60
DS
6790 vty_out(vty,
6791 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6792 import_name);
6793 return CMD_WARNING;
6794 }
12a844a5
DS
6795 }
6796
12a844a5 6797 if (remove) {
44338987 6798 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6799 } else {
44338987 6800 /* Already importing from "import_vrf"? */
12a844a5
DS
6801 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6802 vname)) {
6803 if (strcmp(vname, import_name) == 0)
6804 return CMD_WARNING;
6805 }
6806
44338987 6807 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6808 }
6809
6810 return CMD_SUCCESS;
6811}
6812
b9c7bc5a
PZ
6813/* This command is valid only in a bgp vrf instance or the default instance */
6814DEFPY (bgp_imexport_vpn,
6815 bgp_imexport_vpn_cmd,
6816 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6817 NO_STR
6818 "Import routes to this address-family\n"
6819 "Export routes from this address-family\n"
6820 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6821{
6822 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6823 int previous_state;
ddb5b488 6824 afi_t afi;
b9c7bc5a 6825 safi_t safi;
ddb5b488 6826 int idx = 0;
b9c7bc5a
PZ
6827 int yes = 1;
6828 int flag;
6829 vpn_policy_direction_t dir;
ddb5b488 6830
b9c7bc5a 6831 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6832 yes = 0;
ddb5b488 6833
b9c7bc5a
PZ
6834 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6835 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6836
b9c7bc5a
PZ
6837 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6838 return CMD_WARNING_CONFIG_FAILED;
6839 }
ddb5b488 6840
b9c7bc5a
PZ
6841 afi = bgp_node_afi(vty);
6842 safi = bgp_node_safi(vty);
6843 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6844 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6845 return CMD_WARNING_CONFIG_FAILED;
6846 }
ddb5b488 6847
b9c7bc5a
PZ
6848 if (!strcmp(direction_str, "import")) {
6849 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6850 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6851 } else if (!strcmp(direction_str, "export")) {
6852 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6853 dir = BGP_VPN_POLICY_DIR_TOVPN;
6854 } else {
6855 vty_out(vty, "%% unknown direction %s\n", direction_str);
6856 return CMD_WARNING_CONFIG_FAILED;
6857 }
6858
6859 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 6860
b9c7bc5a
PZ
6861 if (yes) {
6862 SET_FLAG(bgp->af_flags[afi][safi], flag);
6863 if (!previous_state) {
6864 /* trigger export current vrf */
ddb5b488
PZ
6865 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6866 }
b9c7bc5a
PZ
6867 } else {
6868 if (previous_state) {
6869 /* trigger un-export current vrf */
6870 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6871 }
6872 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
6873 }
6874
6875 return CMD_SUCCESS;
6876}
6877
301ad80a
PG
6878DEFPY (af_routetarget_import,
6879 af_routetarget_import_cmd,
6880 "[no] <rt|route-target> redirect import RTLIST...",
6881 NO_STR
6882 "Specify route target list\n"
6883 "Specify route target list\n"
6884 "Flow-spec redirect type route target\n"
6885 "Import routes to this address-family\n"
6886 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6887{
6888 VTY_DECLVAR_CONTEXT(bgp, bgp);
6889 int ret;
6890 struct ecommunity *ecom = NULL;
301ad80a
PG
6891 afi_t afi;
6892 int idx = 0;
6893 int yes = 1;
6894
6895 if (argv_find(argv, argc, "no", &idx))
6896 yes = 0;
6897
0ca70ba5 6898 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6899 if (afi == AFI_MAX)
6900 return CMD_WARNING_CONFIG_FAILED;
6901
301ad80a
PG
6902 if (yes) {
6903 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6904 vty_out(vty, "%% Missing RTLIST\n");
6905 return CMD_WARNING_CONFIG_FAILED;
6906 }
6907 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6908 if (ret != CMD_SUCCESS)
6909 return ret;
6910 }
69b07479
DS
6911
6912 if (yes) {
6913 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6914 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6915 .import_redirect_rtlist);
69b07479
DS
6916 bgp->vpn_policy[afi].import_redirect_rtlist =
6917 ecommunity_dup(ecom);
6918 } else {
6919 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6920 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6921 .import_redirect_rtlist);
69b07479 6922 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 6923 }
69b07479 6924
301ad80a
PG
6925 if (ecom)
6926 ecommunity_free(&ecom);
6927
6928 return CMD_SUCCESS;
6929}
6930
505e5056 6931DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 6932 address_family_ipv4_safi_cmd,
6933 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6934 "Enter Address Family command mode\n"
6935 "Address Family\n"
6936 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6937{
f51bae9c 6938
d62a17ae 6939 if (argc == 3) {
2131d5cf 6940 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6941 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6942 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6943 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6944 && safi != SAFI_EVPN) {
31947174
MK
6945 vty_out(vty,
6946 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6947 return CMD_WARNING_CONFIG_FAILED;
6948 }
d62a17ae 6949 vty->node = bgp_node_type(AFI_IP, safi);
6950 } else
6951 vty->node = BGP_IPV4_NODE;
718e3744 6952
d62a17ae 6953 return CMD_SUCCESS;
718e3744 6954}
6955
505e5056 6956DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 6957 address_family_ipv6_safi_cmd,
6958 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6959 "Enter Address Family command mode\n"
6960 "Address Family\n"
6961 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6962{
d62a17ae 6963 if (argc == 3) {
2131d5cf 6964 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6965 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6966 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6967 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6968 && safi != SAFI_EVPN) {
31947174
MK
6969 vty_out(vty,
6970 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6971 return CMD_WARNING_CONFIG_FAILED;
6972 }
d62a17ae 6973 vty->node = bgp_node_type(AFI_IP6, safi);
6974 } else
6975 vty->node = BGP_IPV6_NODE;
25ffbdc1 6976
d62a17ae 6977 return CMD_SUCCESS;
25ffbdc1 6978}
718e3744 6979
d6902373 6980#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6981DEFUN_NOSH (address_family_vpnv4,
718e3744 6982 address_family_vpnv4_cmd,
8334fd5a 6983 "address-family vpnv4 [unicast]",
718e3744 6984 "Enter Address Family command mode\n"
8c3deaae 6985 "Address Family\n"
3a2d747c 6986 "Address Family modifier\n")
718e3744 6987{
d62a17ae 6988 vty->node = BGP_VPNV4_NODE;
6989 return CMD_SUCCESS;
718e3744 6990}
6991
505e5056 6992DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6993 address_family_vpnv6_cmd,
8334fd5a 6994 "address-family vpnv6 [unicast]",
8ecd3266 6995 "Enter Address Family command mode\n"
8c3deaae 6996 "Address Family\n"
3a2d747c 6997 "Address Family modifier\n")
8ecd3266 6998{
d62a17ae 6999 vty->node = BGP_VPNV6_NODE;
7000 return CMD_SUCCESS;
8ecd3266 7001}
c016b6c7 7002#endif
d6902373 7003
505e5056 7004DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7005 address_family_evpn_cmd,
7111c1a0 7006 "address-family l2vpn evpn",
4e0b7b6d 7007 "Enter Address Family command mode\n"
7111c1a0
QY
7008 "Address Family\n"
7009 "Address Family modifier\n")
4e0b7b6d 7010{
2131d5cf 7011 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7012 vty->node = BGP_EVPN_NODE;
7013 return CMD_SUCCESS;
4e0b7b6d
PG
7014}
7015
505e5056 7016DEFUN_NOSH (exit_address_family,
718e3744 7017 exit_address_family_cmd,
7018 "exit-address-family",
7019 "Exit from Address Family configuration mode\n")
7020{
d62a17ae 7021 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7022 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7023 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7024 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7025 || vty->node == BGP_EVPN_NODE
7026 || vty->node == BGP_FLOWSPECV4_NODE
7027 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7028 vty->node = BGP_NODE;
7029 return CMD_SUCCESS;
718e3744 7030}
6b0655a2 7031
8ad7271d 7032/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7033static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7034 const char *ip_str, afi_t afi, safi_t safi,
7035 struct prefix_rd *prd)
7036{
7037 int ret;
7038 struct prefix match;
7039 struct bgp_node *rn;
7040 struct bgp_node *rm;
7041 struct bgp *bgp;
7042 struct bgp_table *table;
7043 struct bgp_table *rib;
7044
7045 /* BGP structure lookup. */
7046 if (view_name) {
7047 bgp = bgp_lookup_by_name(view_name);
7048 if (bgp == NULL) {
7049 vty_out(vty, "%% Can't find BGP instance %s\n",
7050 view_name);
7051 return CMD_WARNING;
7052 }
7053 } else {
7054 bgp = bgp_get_default();
7055 if (bgp == NULL) {
7056 vty_out(vty, "%% No BGP process is configured\n");
7057 return CMD_WARNING;
7058 }
7059 }
7060
7061 /* Check IP address argument. */
7062 ret = str2prefix(ip_str, &match);
7063 if (!ret) {
7064 vty_out(vty, "%% address is malformed\n");
7065 return CMD_WARNING;
7066 }
7067
7068 match.family = afi2family(afi);
7069 rib = bgp->rib[afi][safi];
7070
7071 if (safi == SAFI_MPLS_VPN) {
7072 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7073 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7074 continue;
7075
7076 if ((table = rn->info) != NULL) {
7077 if ((rm = bgp_node_match(table, &match))
7078 != NULL) {
7079 if (rm->p.prefixlen
7080 == match.prefixlen) {
343cdb61 7081 SET_FLAG(rm->flags,
d62a17ae 7082 BGP_NODE_USER_CLEAR);
7083 bgp_process(bgp, rm, afi, safi);
7084 }
7085 bgp_unlock_node(rm);
7086 }
7087 }
7088 }
7089 } else {
7090 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7091 if (rn->p.prefixlen == match.prefixlen) {
7092 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7093 bgp_process(bgp, rn, afi, safi);
7094 }
7095 bgp_unlock_node(rn);
7096 }
7097 }
7098
7099 return CMD_SUCCESS;
8ad7271d
DS
7100}
7101
b09b5ae0 7102/* one clear bgp command to rule them all */
718e3744 7103DEFUN (clear_ip_bgp_all,
7104 clear_ip_bgp_all_cmd,
c1a44e43 7105 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
718e3744 7106 CLEAR_STR
7107 IP_STR
7108 BGP_STR
838758ac 7109 BGP_INSTANCE_HELP_STR
510afcd6
DS
7110 BGP_AFI_HELP_STR
7111 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
7112 "Clear all peers\n"
7113 "BGP neighbor address to clear\n"
a80beece 7114 "BGP IPv6 neighbor to clear\n"
838758ac 7115 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7116 "Clear peers with the AS number\n"
7117 "Clear all external peers\n"
718e3744 7118 "Clear all members of peer-group\n"
b09b5ae0 7119 "BGP peer-group name\n"
b09b5ae0
DW
7120 BGP_SOFT_STR
7121 BGP_SOFT_IN_STR
b09b5ae0
DW
7122 BGP_SOFT_OUT_STR
7123 BGP_SOFT_IN_STR
7124 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7125 BGP_SOFT_OUT_STR)
718e3744 7126{
d62a17ae 7127 char *vrf = NULL;
7128
7129 afi_t afi = AFI_IP6;
7130 safi_t safi = SAFI_UNICAST;
7131 enum clear_sort clr_sort = clear_peer;
7132 enum bgp_clear_type clr_type;
7133 char *clr_arg = NULL;
7134
7135 int idx = 0;
7136
7137 /* clear [ip] bgp */
7138 if (argv_find(argv, argc, "ip", &idx))
7139 afi = AFI_IP;
7140
7141 /* [<view|vrf> VIEWVRFNAME] */
7142 if (argv_find(argv, argc, "view", &idx)
7143 || argv_find(argv, argc, "vrf", &idx)) {
7144 vrf = argv[idx + 1]->arg;
7145 idx += 2;
7146 }
7147
7148 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7149 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7150 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7151
7152 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7153 if (argv_find(argv, argc, "*", &idx)) {
7154 clr_sort = clear_all;
7155 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7156 clr_sort = clear_peer;
7157 clr_arg = argv[idx]->arg;
7158 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7159 clr_sort = clear_peer;
7160 clr_arg = argv[idx]->arg;
7161 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7162 clr_sort = clear_group;
7163 idx++;
7164 clr_arg = argv[idx]->arg;
7165 } else if (argv_find(argv, argc, "WORD", &idx)) {
7166 clr_sort = clear_peer;
7167 clr_arg = argv[idx]->arg;
7168 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7169 clr_sort = clear_as;
7170 clr_arg = argv[idx]->arg;
7171 } else if (argv_find(argv, argc, "external", &idx)) {
7172 clr_sort = clear_external;
7173 }
7174
7175 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7176 if (argv_find(argv, argc, "soft", &idx)) {
7177 if (argv_find(argv, argc, "in", &idx)
7178 || argv_find(argv, argc, "out", &idx))
7179 clr_type = strmatch(argv[idx]->text, "in")
7180 ? BGP_CLEAR_SOFT_IN
7181 : BGP_CLEAR_SOFT_OUT;
7182 else
7183 clr_type = BGP_CLEAR_SOFT_BOTH;
7184 } else if (argv_find(argv, argc, "in", &idx)) {
7185 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7186 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7187 : BGP_CLEAR_SOFT_IN;
7188 } else if (argv_find(argv, argc, "out", &idx)) {
7189 clr_type = BGP_CLEAR_SOFT_OUT;
7190 } else
7191 clr_type = BGP_CLEAR_SOFT_NONE;
7192
7193 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7194}
01080f7c 7195
8ad7271d
DS
7196DEFUN (clear_ip_bgp_prefix,
7197 clear_ip_bgp_prefix_cmd,
18c57037 7198 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7199 CLEAR_STR
7200 IP_STR
7201 BGP_STR
838758ac 7202 BGP_INSTANCE_HELP_STR
8ad7271d 7203 "Clear bestpath and re-advertise\n"
0c7b1b01 7204 "IPv4 prefix\n")
8ad7271d 7205{
d62a17ae 7206 char *vrf = NULL;
7207 char *prefix = NULL;
8ad7271d 7208
d62a17ae 7209 int idx = 0;
01080f7c 7210
d62a17ae 7211 /* [<view|vrf> VIEWVRFNAME] */
1d35f218 7212 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
d62a17ae 7213 vrf = argv[idx]->arg;
0c7b1b01 7214
d62a17ae 7215 prefix = argv[argc - 1]->arg;
8ad7271d 7216
d62a17ae 7217 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7218}
8ad7271d 7219
b09b5ae0
DW
7220DEFUN (clear_bgp_ipv6_safi_prefix,
7221 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7222 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7223 CLEAR_STR
3a2d747c 7224 IP_STR
718e3744 7225 BGP_STR
8c3deaae 7226 "Address Family\n"
46f296b4 7227 BGP_SAFI_HELP_STR
b09b5ae0 7228 "Clear bestpath and re-advertise\n"
0c7b1b01 7229 "IPv6 prefix\n")
718e3744 7230{
9b475e76
PG
7231 int idx_safi = 0;
7232 int idx_ipv6_prefix = 0;
7233 safi_t safi = SAFI_UNICAST;
7234 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7235 argv[idx_ipv6_prefix]->arg : NULL;
7236
7237 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7238 return bgp_clear_prefix(
9b475e76
PG
7239 vty, NULL, prefix, AFI_IP6,
7240 safi, NULL);
838758ac 7241}
01080f7c 7242
b09b5ae0
DW
7243DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7244 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7245 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7246 CLEAR_STR
3a2d747c 7247 IP_STR
718e3744 7248 BGP_STR
838758ac 7249 BGP_INSTANCE_HELP_STR
8c3deaae 7250 "Address Family\n"
46f296b4 7251 BGP_SAFI_HELP_STR
b09b5ae0 7252 "Clear bestpath and re-advertise\n"
0c7b1b01 7253 "IPv6 prefix\n")
718e3744 7254{
d62a17ae 7255 int idx_word = 3;
9b475e76
PG
7256 int idx_safi = 0;
7257 int idx_ipv6_prefix = 0;
7258 safi_t safi = SAFI_UNICAST;
7259 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7260 argv[idx_ipv6_prefix]->arg : NULL;
7261 /* [<view|vrf> VIEWVRFNAME] */
7262 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7263 argv[idx_word]->arg : NULL;
7264
7265 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7266
d62a17ae 7267 return bgp_clear_prefix(
9b475e76
PG
7268 vty, vrfview, prefix,
7269 AFI_IP6, safi, NULL);
718e3744 7270}
7271
b09b5ae0
DW
7272DEFUN (show_bgp_views,
7273 show_bgp_views_cmd,
d6e3c605 7274 "show [ip] bgp views",
b09b5ae0 7275 SHOW_STR
d6e3c605 7276 IP_STR
01080f7c 7277 BGP_STR
b09b5ae0 7278 "Show the defined BGP views\n")
01080f7c 7279{
d62a17ae 7280 struct list *inst = bm->bgp;
7281 struct listnode *node;
7282 struct bgp *bgp;
01080f7c 7283
d62a17ae 7284 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7285 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7286 return CMD_WARNING;
7287 }
e52702f2 7288
d62a17ae 7289 vty_out(vty, "Defined BGP views:\n");
7290 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7291 /* Skip VRFs. */
7292 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7293 continue;
7294 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7295 bgp->as);
7296 }
e52702f2 7297
d62a17ae 7298 return CMD_SUCCESS;
e0081f70
ML
7299}
7300
8386ac43 7301DEFUN (show_bgp_vrfs,
7302 show_bgp_vrfs_cmd,
d6e3c605 7303 "show [ip] bgp vrfs [json]",
8386ac43 7304 SHOW_STR
d6e3c605 7305 IP_STR
8386ac43 7306 BGP_STR
7307 "Show BGP VRFs\n"
9973d184 7308 JSON_STR)
8386ac43 7309{
fe1dc5a3 7310 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7311 struct list *inst = bm->bgp;
7312 struct listnode *node;
7313 struct bgp *bgp;
d7c0a89a 7314 uint8_t uj = use_json(argc, argv);
d62a17ae 7315 json_object *json = NULL;
7316 json_object *json_vrfs = NULL;
7317 int count = 0;
d62a17ae 7318
7319 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7320 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7321 return CMD_WARNING;
7322 }
7323
7324 if (uj) {
7325 json = json_object_new_object();
7326 json_vrfs = json_object_new_object();
7327 }
7328
7329 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7330 const char *name, *type;
7331 struct peer *peer;
7332 struct listnode *node, *nnode;
7333 int peers_cfg, peers_estb;
7334 json_object *json_vrf = NULL;
d62a17ae 7335
7336 /* Skip Views. */
7337 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7338 continue;
7339
7340 count++;
7341 if (!uj && count == 1)
fe1dc5a3
MK
7342 vty_out(vty,
7343 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7344 "Type", "Id", "routerId", "#PeersVfg",
7345 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7346
7347 peers_cfg = peers_estb = 0;
7348 if (uj)
7349 json_vrf = json_object_new_object();
7350
7351
7352 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7353 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7354 continue;
7355 peers_cfg++;
7356 if (peer->status == Established)
7357 peers_estb++;
7358 }
7359
7360 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7361 name = "Default";
7362 type = "DFLT";
7363 } else {
7364 name = bgp->name;
7365 type = "VRF";
7366 }
7367
a8bf7d9c 7368
d62a17ae 7369 if (uj) {
a4d82a8a
PZ
7370 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7371 ? -1
7372 : (int64_t)bgp->vrf_id;
d62a17ae 7373 json_object_string_add(json_vrf, "type", type);
7374 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7375 json_object_string_add(json_vrf, "routerId",
7376 inet_ntoa(bgp->router_id));
7377 json_object_int_add(json_vrf, "numConfiguredPeers",
7378 peers_cfg);
7379 json_object_int_add(json_vrf, "numEstablishedPeers",
7380 peers_estb);
7381
fe1dc5a3 7382 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7383 json_object_string_add(
7384 json_vrf, "rmac",
7385 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7386 json_object_object_add(json_vrfs, name, json_vrf);
7387 } else
fe1dc5a3
MK
7388 vty_out(vty,
7389 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7390 type,
7391 bgp->vrf_id == VRF_UNKNOWN ? -1
7392 : (int)bgp->vrf_id,
7393 inet_ntoa(bgp->router_id), peers_cfg,
7394 peers_estb, name, bgp->l3vni,
fe1dc5a3 7395 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7396 }
7397
7398 if (uj) {
7399 json_object_object_add(json, "vrfs", json_vrfs);
7400
7401 json_object_int_add(json, "totalVrfs", count);
7402
996c9314
LB
7403 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7404 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7405 json_object_free(json);
7406 } else {
7407 if (count)
7408 vty_out(vty,
7409 "\nTotal number of VRFs (including default): %d\n",
7410 count);
7411 }
7412
7413 return CMD_SUCCESS;
8386ac43 7414}
7415
acf71666
MK
7416static void show_address_entry(struct hash_backet *backet, void *args)
7417{
60466a63
QY
7418 struct vty *vty = (struct vty *)args;
7419 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 7420
60466a63 7421 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
7422 addr->refcnt);
7423}
7424
7425static void show_tip_entry(struct hash_backet *backet, void *args)
7426{
0291c246 7427 struct vty *vty = (struct vty *)args;
60466a63 7428 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7429
60466a63 7430 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7431 tip->refcnt);
7432}
7433
7434static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7435{
7436 vty_out(vty, "self nexthop database:\n");
7437 hash_iterate(bgp->address_hash,
7438 (void (*)(struct hash_backet *, void *))show_address_entry,
7439 vty);
7440
7441 vty_out(vty, "Tunnel-ip database:\n");
7442 hash_iterate(bgp->tip_hash,
7443 (void (*)(struct hash_backet *, void *))show_tip_entry,
7444 vty);
7445}
7446
15c81ca4
DS
7447DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7448 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7449 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7450 "martian next-hops\n"
7451 "martian next-hop database\n")
acf71666 7452{
0291c246 7453 struct bgp *bgp = NULL;
15c81ca4
DS
7454 int idx = 0;
7455
7456 if (argv_find(argv, argc, "view", &idx)
7457 || argv_find(argv, argc, "vrf", &idx))
7458 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7459 else
7460 bgp = bgp_get_default();
acf71666 7461
acf71666
MK
7462 if (!bgp) {
7463 vty_out(vty, "%% No BGP process is configured\n");
7464 return CMD_WARNING;
7465 }
7466 bgp_show_martian_nexthops(vty, bgp);
7467
7468 return CMD_SUCCESS;
7469}
7470
f412b39a 7471DEFUN (show_bgp_memory,
4bf6a362 7472 show_bgp_memory_cmd,
7fa12b13 7473 "show [ip] bgp memory",
4bf6a362 7474 SHOW_STR
3a2d747c 7475 IP_STR
4bf6a362
PJ
7476 BGP_STR
7477 "Global BGP memory statistics\n")
7478{
d62a17ae 7479 char memstrbuf[MTYPE_MEMSTR_LEN];
7480 unsigned long count;
7481
7482 /* RIB related usage stats */
7483 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7484 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7485 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7486 count * sizeof(struct bgp_node)));
7487
7488 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7489 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7490 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7491 count * sizeof(struct bgp_info)));
7492 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7493 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7494 count,
7495 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7496 count * sizeof(struct bgp_info_extra)));
7497
7498 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7499 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7500 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7501 count * sizeof(struct bgp_static)));
7502
7503 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7504 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7505 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7506 count * sizeof(struct bpacket)));
7507
7508 /* Adj-In/Out */
7509 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7510 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7511 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7512 count * sizeof(struct bgp_adj_in)));
7513 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7514 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7515 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7516 count * sizeof(struct bgp_adj_out)));
7517
7518 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7519 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7520 count,
7521 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7522 count * sizeof(struct bgp_nexthop_cache)));
7523
7524 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7525 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7526 count,
7527 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7528 count * sizeof(struct bgp_damp_info)));
7529
7530 /* Attributes */
7531 count = attr_count();
7532 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7533 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7534 count * sizeof(struct attr)));
7535
7536 if ((count = attr_unknown_count()))
7537 vty_out(vty, "%ld unknown attributes\n", count);
7538
7539 /* AS_PATH attributes */
7540 count = aspath_count();
7541 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7542 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7543 count * sizeof(struct aspath)));
7544
7545 count = mtype_stats_alloc(MTYPE_AS_SEG);
7546 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7547 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7548 count * sizeof(struct assegment)));
7549
7550 /* Other attributes */
7551 if ((count = community_count()))
7552 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7553 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7554 count * sizeof(struct community)));
d62a17ae 7555 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7556 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7557 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7558 count * sizeof(struct ecommunity)));
d62a17ae 7559 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7560 vty_out(vty,
7561 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7562 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7563 count * sizeof(struct lcommunity)));
d62a17ae 7564
7565 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7566 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7567 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7568 count * sizeof(struct cluster_list)));
7569
7570 /* Peer related usage */
7571 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7572 vty_out(vty, "%ld peers, using %s of memory\n", count,
7573 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7574 count * sizeof(struct peer)));
7575
7576 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7577 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7578 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7579 count * sizeof(struct peer_group)));
7580
7581 /* Other */
7582 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7583 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7584 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7585 count * sizeof(struct hash)));
7586 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7587 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7588 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7589 count * sizeof(struct hash_backet)));
7590 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7591 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7592 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7593 count * sizeof(regex_t)));
d62a17ae 7594 return CMD_SUCCESS;
4bf6a362 7595}
fee0f4c6 7596
57a9c8a8
DS
7597static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7598{
7599 json_object *bestpath = json_object_new_object();
7600
7601 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7602 json_object_string_add(bestpath, "asPath", "ignore");
7603
7604 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7605 json_object_string_add(bestpath, "asPath", "confed");
7606
7607 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7608 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7609 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7610 "as-set");
7611 else
a4d82a8a 7612 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7613 "true");
7614 } else
a4d82a8a 7615 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7616
7617 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7618 json_object_string_add(bestpath, "compareRouterId", "true");
7619 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7620 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7621 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7622 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7623 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7624 json_object_string_add(bestpath, "med",
7625 "missing-as-worst");
7626 else
7627 json_object_string_add(bestpath, "med", "true");
7628 }
7629
7630 json_object_object_add(json, "bestPath", bestpath);
7631}
7632
718e3744 7633/* Show BGP peer's summary information. */
d62a17ae 7634static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
d7c0a89a 7635 uint8_t use_json, json_object *json)
d62a17ae 7636{
7637 struct peer *peer;
7638 struct listnode *node, *nnode;
7639 unsigned int count = 0, dn_count = 0;
7640 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7641 char neighbor_buf[VTY_BUFSIZ];
7642 int neighbor_col_default_width = 16;
7643 int len;
7644 int max_neighbor_width = 0;
7645 int pfx_rcd_safi;
7646 json_object *json_peer = NULL;
7647 json_object *json_peers = NULL;
7648
7649 /* labeled-unicast routes are installed in the unicast table so in order
7650 * to
7651 * display the correct PfxRcd value we must look at SAFI_UNICAST
7652 */
7653 if (safi == SAFI_LABELED_UNICAST)
7654 pfx_rcd_safi = SAFI_UNICAST;
7655 else
7656 pfx_rcd_safi = safi;
7657
7658 if (use_json) {
7659 if (json == NULL)
7660 json = json_object_new_object();
7661
7662 json_peers = json_object_new_object();
7663 } else {
7664 /* Loop over all neighbors that will be displayed to determine
7665 * how many
7666 * characters are needed for the Neighbor column
7667 */
7668 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7669 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7670 continue;
7671
7672 if (peer->afc[afi][safi]) {
7673 memset(dn_flag, '\0', sizeof(dn_flag));
7674 if (peer_dynamic_neighbor(peer))
7675 dn_flag[0] = '*';
7676
7677 if (peer->hostname
7678 && bgp_flag_check(bgp,
7679 BGP_FLAG_SHOW_HOSTNAME))
7680 sprintf(neighbor_buf, "%s%s(%s) ",
7681 dn_flag, peer->hostname,
7682 peer->host);
7683 else
7684 sprintf(neighbor_buf, "%s%s ", dn_flag,
7685 peer->host);
7686
7687 len = strlen(neighbor_buf);
7688
7689 if (len > max_neighbor_width)
7690 max_neighbor_width = len;
7691 }
7692 }
f933309e 7693
d62a17ae 7694 /* Originally we displayed the Neighbor column as 16
7695 * characters wide so make that the default
7696 */
7697 if (max_neighbor_width < neighbor_col_default_width)
7698 max_neighbor_width = neighbor_col_default_width;
7699 }
f933309e 7700
d62a17ae 7701 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7702 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7703 continue;
7704
ea47320b
DL
7705 if (!peer->afc[afi][safi])
7706 continue;
d62a17ae 7707
ea47320b
DL
7708 if (!count) {
7709 unsigned long ents;
7710 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7711 int64_t vrf_id_ui;
d62a17ae 7712
a4d82a8a
PZ
7713 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7714 ? -1
7715 : (int64_t)bgp->vrf_id;
ea47320b
DL
7716
7717 /* Usage summary and header */
7718 if (use_json) {
7719 json_object_string_add(
7720 json, "routerId",
7721 inet_ntoa(bgp->router_id));
60466a63
QY
7722 json_object_int_add(json, "as", bgp->as);
7723 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7724 json_object_string_add(
7725 json, "vrfName",
7726 (bgp->inst_type
7727 == BGP_INSTANCE_TYPE_DEFAULT)
7728 ? "Default"
7729 : bgp->name);
7730 } else {
7731 vty_out(vty,
7732 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7733 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7734 bgp->vrf_id == VRF_UNKNOWN
7735 ? -1
7736 : (int)bgp->vrf_id);
ea47320b
DL
7737 vty_out(vty, "\n");
7738 }
d62a17ae 7739
ea47320b 7740 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7741 if (use_json) {
ea47320b 7742 json_object_int_add(
60466a63 7743 json, "updateDelayLimit",
ea47320b 7744 bgp->v_update_delay);
d62a17ae 7745
ea47320b
DL
7746 if (bgp->v_update_delay
7747 != bgp->v_establish_wait)
d62a17ae 7748 json_object_int_add(
7749 json,
ea47320b
DL
7750 "updateDelayEstablishWait",
7751 bgp->v_establish_wait);
d62a17ae 7752
60466a63 7753 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7754 json_object_string_add(
7755 json,
7756 "updateDelayFirstNeighbor",
7757 bgp->update_delay_begin_time);
7758 json_object_boolean_true_add(
7759 json,
7760 "updateDelayInProgress");
7761 } else {
7762 if (bgp->update_delay_over) {
d62a17ae 7763 json_object_string_add(
7764 json,
7765 "updateDelayFirstNeighbor",
7766 bgp->update_delay_begin_time);
ea47320b 7767 json_object_string_add(
d62a17ae 7768 json,
ea47320b
DL
7769 "updateDelayBestpathResumed",
7770 bgp->update_delay_end_time);
7771 json_object_string_add(
d62a17ae 7772 json,
ea47320b
DL
7773 "updateDelayZebraUpdateResume",
7774 bgp->update_delay_zebra_resume_time);
7775 json_object_string_add(
7776 json,
7777 "updateDelayPeerUpdateResume",
7778 bgp->update_delay_peers_resume_time);
d62a17ae 7779 }
ea47320b
DL
7780 }
7781 } else {
7782 vty_out(vty,
7783 "Read-only mode update-delay limit: %d seconds\n",
7784 bgp->v_update_delay);
7785 if (bgp->v_update_delay
7786 != bgp->v_establish_wait)
d62a17ae 7787 vty_out(vty,
ea47320b
DL
7788 " Establish wait: %d seconds\n",
7789 bgp->v_establish_wait);
d62a17ae 7790
60466a63 7791 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7792 vty_out(vty,
7793 " First neighbor established: %s\n",
7794 bgp->update_delay_begin_time);
7795 vty_out(vty,
7796 " Delay in progress\n");
7797 } else {
7798 if (bgp->update_delay_over) {
d62a17ae 7799 vty_out(vty,
7800 " First neighbor established: %s\n",
7801 bgp->update_delay_begin_time);
7802 vty_out(vty,
ea47320b
DL
7803 " Best-paths resumed: %s\n",
7804 bgp->update_delay_end_time);
7805 vty_out(vty,
7806 " zebra update resumed: %s\n",
7807 bgp->update_delay_zebra_resume_time);
7808 vty_out(vty,
7809 " peers update resumed: %s\n",
7810 bgp->update_delay_peers_resume_time);
d62a17ae 7811 }
7812 }
7813 }
ea47320b 7814 }
d62a17ae 7815
ea47320b
DL
7816 if (use_json) {
7817 if (bgp_maxmed_onstartup_configured(bgp)
7818 && bgp->maxmed_active)
7819 json_object_boolean_true_add(
60466a63 7820 json, "maxMedOnStartup");
ea47320b
DL
7821 if (bgp->v_maxmed_admin)
7822 json_object_boolean_true_add(
60466a63 7823 json, "maxMedAdministrative");
d62a17ae 7824
ea47320b
DL
7825 json_object_int_add(
7826 json, "tableVersion",
60466a63 7827 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7828
60466a63
QY
7829 ents = bgp_table_count(bgp->rib[afi][safi]);
7830 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7831 json_object_int_add(
7832 json, "ribMemory",
7833 ents * sizeof(struct bgp_node));
d62a17ae 7834
ea47320b 7835 ents = listcount(bgp->peer);
60466a63
QY
7836 json_object_int_add(json, "peerCount", ents);
7837 json_object_int_add(json, "peerMemory",
7838 ents * sizeof(struct peer));
d62a17ae 7839
ea47320b
DL
7840 if ((ents = listcount(bgp->group))) {
7841 json_object_int_add(
60466a63 7842 json, "peerGroupCount", ents);
ea47320b
DL
7843 json_object_int_add(
7844 json, "peerGroupMemory",
996c9314
LB
7845 ents * sizeof(struct
7846 peer_group));
ea47320b 7847 }
d62a17ae 7848
ea47320b
DL
7849 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7850 BGP_CONFIG_DAMPENING))
7851 json_object_boolean_true_add(
60466a63 7852 json, "dampeningEnabled");
ea47320b
DL
7853 } else {
7854 if (bgp_maxmed_onstartup_configured(bgp)
7855 && bgp->maxmed_active)
d62a17ae 7856 vty_out(vty,
ea47320b
DL
7857 "Max-med on-startup active\n");
7858 if (bgp->v_maxmed_admin)
d62a17ae 7859 vty_out(vty,
ea47320b 7860 "Max-med administrative active\n");
d62a17ae 7861
60466a63
QY
7862 vty_out(vty, "BGP table version %" PRIu64 "\n",
7863 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 7864
60466a63 7865 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
7866 vty_out(vty,
7867 "RIB entries %ld, using %s of memory\n",
7868 ents,
996c9314
LB
7869 mtype_memstr(memstrbuf,
7870 sizeof(memstrbuf),
7871 ents * sizeof(struct
7872 bgp_node)));
ea47320b
DL
7873
7874 /* Peer related usage */
7875 ents = listcount(bgp->peer);
60466a63 7876 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7877 ents,
7878 mtype_memstr(
60466a63
QY
7879 memstrbuf, sizeof(memstrbuf),
7880 ents * sizeof(struct peer)));
ea47320b
DL
7881
7882 if ((ents = listcount(bgp->group)))
d62a17ae 7883 vty_out(vty,
ea47320b 7884 "Peer groups %ld, using %s of memory\n",
d62a17ae 7885 ents,
7886 mtype_memstr(
7887 memstrbuf,
7888 sizeof(memstrbuf),
996c9314
LB
7889 ents * sizeof(struct
7890 peer_group)));
d62a17ae 7891
ea47320b
DL
7892 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7893 BGP_CONFIG_DAMPENING))
60466a63 7894 vty_out(vty, "Dampening enabled.\n");
ea47320b 7895 vty_out(vty, "\n");
d62a17ae 7896
ea47320b
DL
7897 /* Subtract 8 here because 'Neighbor' is
7898 * 8 characters */
7899 vty_out(vty, "Neighbor");
60466a63
QY
7900 vty_out(vty, "%*s", max_neighbor_width - 8,
7901 " ");
ea47320b
DL
7902 vty_out(vty,
7903 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7904 }
ea47320b 7905 }
d62a17ae 7906
ea47320b 7907 count++;
d62a17ae 7908
ea47320b
DL
7909 if (use_json) {
7910 json_peer = json_object_new_object();
d62a17ae 7911
ea47320b 7912 if (peer_dynamic_neighbor(peer))
60466a63
QY
7913 json_object_boolean_true_add(json_peer,
7914 "dynamicPeer");
d62a17ae 7915
ea47320b 7916 if (peer->hostname)
60466a63 7917 json_object_string_add(json_peer, "hostname",
ea47320b 7918 peer->hostname);
d62a17ae 7919
ea47320b 7920 if (peer->domainname)
60466a63
QY
7921 json_object_string_add(json_peer, "domainname",
7922 peer->domainname);
d62a17ae 7923
60466a63 7924 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7925 json_object_int_add(json_peer, "version", 4);
60466a63 7926 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 7927 PEER_TOTAL_RX(peer));
60466a63 7928 json_object_int_add(json_peer, "msgSent",
0112e9e0 7929 PEER_TOTAL_TX(peer));
ea47320b
DL
7930
7931 json_object_int_add(json_peer, "tableVersion",
7932 peer->version[afi][safi]);
7933 json_object_int_add(json_peer, "outq",
7934 peer->obuf->count);
7935 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7936 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7937 use_json, json_peer);
7938 json_object_int_add(json_peer, "prefixReceivedCount",
7939 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 7940
ea47320b 7941 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7942 json_object_string_add(json_peer, "state",
ea47320b 7943 "Idle (Admin)");
9199a725
TM
7944 else if (peer->afc_recv[afi][safi])
7945 json_object_string_add(
7946 json_peer, "state",
7947 lookup_msg(bgp_status_msg, peer->status,
7948 NULL));
60466a63
QY
7949 else if (CHECK_FLAG(peer->sflags,
7950 PEER_STATUS_PREFIX_OVERFLOW))
7951 json_object_string_add(json_peer, "state",
ea47320b
DL
7952 "Idle (PfxCt)");
7953 else
7954 json_object_string_add(
7955 json_peer, "state",
60466a63
QY
7956 lookup_msg(bgp_status_msg, peer->status,
7957 NULL));
ea47320b
DL
7958
7959 if (peer->conf_if)
60466a63 7960 json_object_string_add(json_peer, "idType",
ea47320b
DL
7961 "interface");
7962 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
7963 json_object_string_add(json_peer, "idType",
7964 "ipv4");
ea47320b 7965 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
7966 json_object_string_add(json_peer, "idType",
7967 "ipv6");
d62a17ae 7968
ea47320b
DL
7969 json_object_object_add(json_peers, peer->host,
7970 json_peer);
7971 } else {
7972 memset(dn_flag, '\0', sizeof(dn_flag));
7973 if (peer_dynamic_neighbor(peer)) {
7974 dn_count++;
7975 dn_flag[0] = '*';
7976 }
d62a17ae 7977
ea47320b 7978 if (peer->hostname
60466a63 7979 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 7980 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 7981 peer->hostname, peer->host);
ea47320b 7982 else
60466a63 7983 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
7984
7985 /* pad the neighbor column with spaces */
7986 if (len < max_neighbor_width)
60466a63
QY
7987 vty_out(vty, "%*s", max_neighbor_width - len,
7988 " ");
ea47320b 7989
86a55b99 7990 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
7991 peer->as, PEER_TOTAL_RX(peer),
7992 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7993 0, peer->obuf->count,
d62a17ae 7994 peer_uptime(peer->uptime, timebuf,
ea47320b 7995 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 7996
ea47320b 7997 if (peer->status == Established)
2f8f4f10 7998 if (peer->afc_recv[afi][safi])
95077abf 7999 vty_out(vty, " %12ld",
a4d82a8a
PZ
8000 peer->pcount[afi]
8001 [pfx_rcd_safi]);
95077abf
DW
8002 else
8003 vty_out(vty, " NoNeg");
ea47320b 8004 else {
60466a63 8005 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 8006 vty_out(vty, " Idle (Admin)");
60466a63
QY
8007 else if (CHECK_FLAG(
8008 peer->sflags,
8009 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 8010 vty_out(vty, " Idle (PfxCt)");
d62a17ae 8011 else
ea47320b 8012 vty_out(vty, " %12s",
60466a63
QY
8013 lookup_msg(bgp_status_msg,
8014 peer->status, NULL));
d62a17ae 8015 }
ea47320b 8016 vty_out(vty, "\n");
d62a17ae 8017 }
8018 }
f933309e 8019
d62a17ae 8020 if (use_json) {
8021 json_object_object_add(json, "peers", json_peers);
8022
8023 json_object_int_add(json, "totalPeers", count);
8024 json_object_int_add(json, "dynamicPeers", dn_count);
8025
57a9c8a8
DS
8026 bgp_show_bestpath_json(bgp, json);
8027
996c9314
LB
8028 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8029 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8030 json_object_free(json);
8031 } else {
8032 if (count)
8033 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8034 else {
d6ceaca3 8035 vty_out(vty, "No %s neighbor is configured\n",
8036 afi_safi_print(afi, safi));
d62a17ae 8037 }
b05a1c8b 8038
d6ceaca3 8039 if (dn_count) {
d62a17ae 8040 vty_out(vty, "* - dynamic neighbor\n");
8041 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8042 dn_count, bgp->dynamic_neighbors_limit);
8043 }
8044 }
1ff9a340 8045
d62a17ae 8046 return CMD_SUCCESS;
718e3744 8047}
8048
d62a17ae 8049static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
d7c0a89a 8050 int safi, uint8_t use_json,
d62a17ae 8051 json_object *json)
8052{
8053 int is_first = 1;
8054 int afi_wildcard = (afi == AFI_MAX);
8055 int safi_wildcard = (safi == SAFI_MAX);
8056 int is_wildcard = (afi_wildcard || safi_wildcard);
8057 bool json_output = false;
8058
8059 if (use_json && is_wildcard)
8060 vty_out(vty, "{\n");
8061 if (afi_wildcard)
8062 afi = 1; /* AFI_IP */
8063 while (afi < AFI_MAX) {
8064 if (safi_wildcard)
8065 safi = 1; /* SAFI_UNICAST */
8066 while (safi < SAFI_MAX) {
318cac96 8067 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
d62a17ae 8068 json_output = true;
8069 if (is_wildcard) {
8070 /*
8071 * So limit output to those afi/safi
8072 * pairs that
8073 * actualy have something interesting in
8074 * them
8075 */
8076 if (use_json) {
8077 json = json_object_new_object();
8078
8079 if (!is_first)
8080 vty_out(vty, ",\n");
8081 else
8082 is_first = 0;
8083
8084 vty_out(vty, "\"%s\":",
8085 afi_safi_json(afi,
8086 safi));
8087 } else {
8088 vty_out(vty, "\n%s Summary:\n",
8089 afi_safi_print(afi,
8090 safi));
8091 }
8092 }
8093 bgp_show_summary(vty, bgp, afi, safi, use_json,
8094 json);
8095 }
8096 safi++;
d62a17ae 8097 if (!safi_wildcard)
8098 safi = SAFI_MAX;
8099 }
8100 afi++;
ee851c8c 8101 if (!afi_wildcard)
d62a17ae 8102 afi = AFI_MAX;
8103 }
8104
8105 if (use_json && is_wildcard)
8106 vty_out(vty, "}\n");
8107 else if (use_json && !json_output)
8108 vty_out(vty, "{}\n");
8109}
8110
8111static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
d7c0a89a 8112 safi_t safi, uint8_t use_json)
d62a17ae 8113{
8114 struct listnode *node, *nnode;
8115 struct bgp *bgp;
8116 json_object *json = NULL;
8117 int is_first = 1;
8118
8119 if (use_json)
8120 vty_out(vty, "{\n");
8121
8122 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8123 if (use_json) {
8124 json = json_object_new_object();
8125
8126 if (!is_first)
8127 vty_out(vty, ",\n");
8128 else
8129 is_first = 0;
8130
8131 vty_out(vty, "\"%s\":",
8132 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8133 ? "Default"
8134 : bgp->name);
8135 } else {
8136 vty_out(vty, "\nInstance %s:\n",
8137 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8138 ? "Default"
8139 : bgp->name);
8140 }
8141 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8142 }
8143
8144 if (use_json)
8145 vty_out(vty, "}\n");
8146}
8147
8148int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
d7c0a89a 8149 safi_t safi, uint8_t use_json)
d62a17ae 8150{
8151 struct bgp *bgp;
8152
8153 if (name) {
8154 if (strmatch(name, "all")) {
8155 bgp_show_all_instances_summary_vty(vty, afi, safi,
8156 use_json);
8157 return CMD_SUCCESS;
8158 } else {
8159 bgp = bgp_lookup_by_name(name);
8160
8161 if (!bgp) {
8162 if (use_json)
8163 vty_out(vty, "{}\n");
8164 else
8165 vty_out(vty,
8166 "%% No such BGP instance exist\n");
8167 return CMD_WARNING;
8168 }
8169
8170 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8171 NULL);
8172 return CMD_SUCCESS;
8173 }
8174 }
8175
8176 bgp = bgp_get_default();
8177
8178 if (bgp)
8179 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8180
8181 return CMD_SUCCESS;
4fb25c53
DW
8182}
8183
716b2d8a 8184/* `show [ip] bgp summary' commands. */
47fc97cc 8185DEFUN (show_ip_bgp_summary,
718e3744 8186 show_ip_bgp_summary_cmd,
dd6bd0f1 8187 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8188 SHOW_STR
8189 IP_STR
8190 BGP_STR
8386ac43 8191 BGP_INSTANCE_HELP_STR
46f296b4 8192 BGP_AFI_HELP_STR
dd6bd0f1 8193 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8194 "Summary of BGP neighbor status\n"
9973d184 8195 JSON_STR)
718e3744 8196{
d62a17ae 8197 char *vrf = NULL;
8198 afi_t afi = AFI_MAX;
8199 safi_t safi = SAFI_MAX;
8200
8201 int idx = 0;
8202
8203 /* show [ip] bgp */
8204 if (argv_find(argv, argc, "ip", &idx))
8205 afi = AFI_IP;
8206 /* [<view|vrf> VIEWVRFNAME] */
8207 if (argv_find(argv, argc, "view", &idx)
8208 || argv_find(argv, argc, "vrf", &idx))
8209 vrf = argv[++idx]->arg;
8210 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8211 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8212 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8213 }
8214
8215 int uj = use_json(argc, argv);
8216
8217 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8218}
8219
8220const char *afi_safi_print(afi_t afi, safi_t safi)
8221{
8222 if (afi == AFI_IP && safi == SAFI_UNICAST)
8223 return "IPv4 Unicast";
8224 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8225 return "IPv4 Multicast";
8226 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8227 return "IPv4 Labeled Unicast";
8228 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8229 return "IPv4 VPN";
8230 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8231 return "IPv4 Encap";
7c40bf39 8232 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8233 return "IPv4 Flowspec";
d62a17ae 8234 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8235 return "IPv6 Unicast";
8236 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8237 return "IPv6 Multicast";
8238 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8239 return "IPv6 Labeled Unicast";
8240 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8241 return "IPv6 VPN";
8242 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8243 return "IPv6 Encap";
7c40bf39 8244 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8245 return "IPv6 Flowspec";
d62a17ae 8246 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8247 return "L2VPN EVPN";
8248 else
8249 return "Unknown";
538621f2 8250}
8251
b9f77ec8
DS
8252/*
8253 * Please note that we have intentionally camelCased
8254 * the return strings here. So if you want
8255 * to use this function, please ensure you
8256 * are doing this within json output
8257 */
d62a17ae 8258const char *afi_safi_json(afi_t afi, safi_t safi)
8259{
8260 if (afi == AFI_IP && safi == SAFI_UNICAST)
8261 return "ipv4Unicast";
8262 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8263 return "ipv4Multicast";
8264 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8265 return "ipv4LabeledUnicast";
8266 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8267 return "ipv4Vpn";
8268 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8269 return "ipv4Encap";
7c40bf39 8270 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8271 return "ipv4Flowspec";
d62a17ae 8272 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8273 return "ipv6Unicast";
8274 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8275 return "ipv6Multicast";
8276 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8277 return "ipv6LabeledUnicast";
8278 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8279 return "ipv6Vpn";
8280 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8281 return "ipv6Encap";
7c40bf39 8282 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8283 return "ipv6Flowspec";
d62a17ae 8284 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8285 return "l2VpnEvpn";
8286 else
8287 return "Unknown";
27162734
LB
8288}
8289
718e3744 8290/* Show BGP peer's information. */
d62a17ae 8291enum show_type { show_all, show_peer };
8292
8293static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8294 afi_t afi, safi_t safi,
d7c0a89a
QY
8295 uint16_t adv_smcap, uint16_t adv_rmcap,
8296 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8297 uint8_t use_json, json_object *json_pref)
d62a17ae 8298{
8299 /* Send-Mode */
8300 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8301 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8302 if (use_json) {
8303 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8304 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8305 json_object_string_add(json_pref, "sendMode",
8306 "advertisedAndReceived");
8307 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8308 json_object_string_add(json_pref, "sendMode",
8309 "advertised");
8310 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8311 json_object_string_add(json_pref, "sendMode",
8312 "received");
8313 } else {
8314 vty_out(vty, " Send-mode: ");
8315 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8316 vty_out(vty, "advertised");
8317 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8318 vty_out(vty, "%sreceived",
8319 CHECK_FLAG(p->af_cap[afi][safi],
8320 adv_smcap)
8321 ? ", "
8322 : "");
8323 vty_out(vty, "\n");
8324 }
8325 }
8326
8327 /* Receive-Mode */
8328 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8329 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8330 if (use_json) {
8331 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8332 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8333 json_object_string_add(json_pref, "recvMode",
8334 "advertisedAndReceived");
8335 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8336 json_object_string_add(json_pref, "recvMode",
8337 "advertised");
8338 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8339 json_object_string_add(json_pref, "recvMode",
8340 "received");
8341 } else {
8342 vty_out(vty, " Receive-mode: ");
8343 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8344 vty_out(vty, "advertised");
8345 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8346 vty_out(vty, "%sreceived",
8347 CHECK_FLAG(p->af_cap[afi][safi],
8348 adv_rmcap)
8349 ? ", "
8350 : "");
8351 vty_out(vty, "\n");
8352 }
8353 }
8354}
8355
8356static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
d7c0a89a 8357 safi_t safi, uint8_t use_json,
d62a17ae 8358 json_object *json_neigh)
8359{
0291c246
MK
8360 struct bgp_filter *filter;
8361 struct peer_af *paf;
8362 char orf_pfx_name[BUFSIZ];
8363 int orf_pfx_count;
8364 json_object *json_af = NULL;
8365 json_object *json_prefA = NULL;
8366 json_object *json_prefB = NULL;
8367 json_object *json_addr = NULL;
d62a17ae 8368
8369 if (use_json) {
8370 json_addr = json_object_new_object();
8371 json_af = json_object_new_object();
8372 filter = &p->filter[afi][safi];
8373
8374 if (peer_group_active(p))
8375 json_object_string_add(json_addr, "peerGroupMember",
8376 p->group->name);
8377
8378 paf = peer_af_find(p, afi, safi);
8379 if (paf && PAF_SUBGRP(paf)) {
8380 json_object_int_add(json_addr, "updateGroupId",
8381 PAF_UPDGRP(paf)->id);
8382 json_object_int_add(json_addr, "subGroupId",
8383 PAF_SUBGRP(paf)->id);
8384 json_object_int_add(json_addr, "packetQueueLength",
8385 bpacket_queue_virtual_length(paf));
8386 }
8387
8388 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8389 || CHECK_FLAG(p->af_cap[afi][safi],
8390 PEER_CAP_ORF_PREFIX_SM_RCV)
8391 || CHECK_FLAG(p->af_cap[afi][safi],
8392 PEER_CAP_ORF_PREFIX_RM_ADV)
8393 || CHECK_FLAG(p->af_cap[afi][safi],
8394 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8395 json_object_int_add(json_af, "orfType",
8396 ORF_TYPE_PREFIX);
8397 json_prefA = json_object_new_object();
8398 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8399 PEER_CAP_ORF_PREFIX_SM_ADV,
8400 PEER_CAP_ORF_PREFIX_RM_ADV,
8401 PEER_CAP_ORF_PREFIX_SM_RCV,
8402 PEER_CAP_ORF_PREFIX_RM_RCV,
8403 use_json, json_prefA);
8404 json_object_object_add(json_af, "orfPrefixList",
8405 json_prefA);
8406 }
8407
8408 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8409 || CHECK_FLAG(p->af_cap[afi][safi],
8410 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8411 || CHECK_FLAG(p->af_cap[afi][safi],
8412 PEER_CAP_ORF_PREFIX_RM_ADV)
8413 || CHECK_FLAG(p->af_cap[afi][safi],
8414 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8415 json_object_int_add(json_af, "orfOldType",
8416 ORF_TYPE_PREFIX_OLD);
8417 json_prefB = json_object_new_object();
8418 bgp_show_peer_afi_orf_cap(
8419 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8420 PEER_CAP_ORF_PREFIX_RM_ADV,
8421 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8422 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8423 json_prefB);
8424 json_object_object_add(json_af, "orfOldPrefixList",
8425 json_prefB);
8426 }
8427
8428 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8429 || CHECK_FLAG(p->af_cap[afi][safi],
8430 PEER_CAP_ORF_PREFIX_SM_RCV)
8431 || CHECK_FLAG(p->af_cap[afi][safi],
8432 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8433 || CHECK_FLAG(p->af_cap[afi][safi],
8434 PEER_CAP_ORF_PREFIX_RM_ADV)
8435 || CHECK_FLAG(p->af_cap[afi][safi],
8436 PEER_CAP_ORF_PREFIX_RM_RCV)
8437 || CHECK_FLAG(p->af_cap[afi][safi],
8438 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8439 json_object_object_add(json_addr, "afDependentCap",
8440 json_af);
8441 else
8442 json_object_free(json_af);
8443
8444 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8445 orf_pfx_count = prefix_bgp_show_prefix_list(
8446 NULL, afi, orf_pfx_name, use_json);
8447
8448 if (CHECK_FLAG(p->af_sflags[afi][safi],
8449 PEER_STATUS_ORF_PREFIX_SEND)
8450 || orf_pfx_count) {
8451 if (CHECK_FLAG(p->af_sflags[afi][safi],
8452 PEER_STATUS_ORF_PREFIX_SEND))
8453 json_object_boolean_true_add(json_neigh,
8454 "orfSent");
8455 if (orf_pfx_count)
8456 json_object_int_add(json_addr, "orfRecvCounter",
8457 orf_pfx_count);
8458 }
8459 if (CHECK_FLAG(p->af_sflags[afi][safi],
8460 PEER_STATUS_ORF_WAIT_REFRESH))
8461 json_object_string_add(
8462 json_addr, "orfFirstUpdate",
8463 "deferredUntilORFOrRouteRefreshRecvd");
8464
8465 if (CHECK_FLAG(p->af_flags[afi][safi],
8466 PEER_FLAG_REFLECTOR_CLIENT))
8467 json_object_boolean_true_add(json_addr,
8468 "routeReflectorClient");
8469 if (CHECK_FLAG(p->af_flags[afi][safi],
8470 PEER_FLAG_RSERVER_CLIENT))
8471 json_object_boolean_true_add(json_addr,
8472 "routeServerClient");
8473 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8474 json_object_boolean_true_add(json_addr,
8475 "inboundSoftConfigPermit");
8476
8477 if (CHECK_FLAG(p->af_flags[afi][safi],
8478 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8479 json_object_boolean_true_add(
8480 json_addr,
8481 "privateAsNumsAllReplacedInUpdatesToNbr");
8482 else if (CHECK_FLAG(p->af_flags[afi][safi],
8483 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8484 json_object_boolean_true_add(
8485 json_addr,
8486 "privateAsNumsReplacedInUpdatesToNbr");
8487 else if (CHECK_FLAG(p->af_flags[afi][safi],
8488 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8489 json_object_boolean_true_add(
8490 json_addr,
8491 "privateAsNumsAllRemovedInUpdatesToNbr");
8492 else if (CHECK_FLAG(p->af_flags[afi][safi],
8493 PEER_FLAG_REMOVE_PRIVATE_AS))
8494 json_object_boolean_true_add(
8495 json_addr,
8496 "privateAsNumsRemovedInUpdatesToNbr");
8497
8498 if (CHECK_FLAG(p->af_flags[afi][safi],
8499 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8500 json_object_boolean_true_add(json_addr,
8501 "addpathTxAllPaths");
8502
8503 if (CHECK_FLAG(p->af_flags[afi][safi],
8504 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8505 json_object_boolean_true_add(json_addr,
8506 "addpathTxBestpathPerAS");
8507
8508 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8509 json_object_string_add(json_addr,
8510 "overrideASNsInOutboundUpdates",
8511 "ifAspathEqualRemoteAs");
8512
8513 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8514 || CHECK_FLAG(p->af_flags[afi][safi],
8515 PEER_FLAG_FORCE_NEXTHOP_SELF))
8516 json_object_boolean_true_add(json_addr,
8517 "routerAlwaysNextHop");
8518 if (CHECK_FLAG(p->af_flags[afi][safi],
8519 PEER_FLAG_AS_PATH_UNCHANGED))
8520 json_object_boolean_true_add(
8521 json_addr, "unchangedAsPathPropogatedToNbr");
8522 if (CHECK_FLAG(p->af_flags[afi][safi],
8523 PEER_FLAG_NEXTHOP_UNCHANGED))
8524 json_object_boolean_true_add(
8525 json_addr, "unchangedNextHopPropogatedToNbr");
8526 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8527 json_object_boolean_true_add(
8528 json_addr, "unchangedMedPropogatedToNbr");
8529 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8530 || CHECK_FLAG(p->af_flags[afi][safi],
8531 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8532 if (CHECK_FLAG(p->af_flags[afi][safi],
8533 PEER_FLAG_SEND_COMMUNITY)
8534 && CHECK_FLAG(p->af_flags[afi][safi],
8535 PEER_FLAG_SEND_EXT_COMMUNITY))
8536 json_object_string_add(json_addr,
8537 "commAttriSentToNbr",
8538 "extendedAndStandard");
8539 else if (CHECK_FLAG(p->af_flags[afi][safi],
8540 PEER_FLAG_SEND_EXT_COMMUNITY))
8541 json_object_string_add(json_addr,
8542 "commAttriSentToNbr",
8543 "extended");
8544 else
8545 json_object_string_add(json_addr,
8546 "commAttriSentToNbr",
8547 "standard");
8548 }
8549 if (CHECK_FLAG(p->af_flags[afi][safi],
8550 PEER_FLAG_DEFAULT_ORIGINATE)) {
8551 if (p->default_rmap[afi][safi].name)
8552 json_object_string_add(
8553 json_addr, "defaultRouteMap",
8554 p->default_rmap[afi][safi].name);
8555
8556 if (paf && PAF_SUBGRP(paf)
8557 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8558 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8559 json_object_boolean_true_add(json_addr,
8560 "defaultSent");
8561 else
8562 json_object_boolean_true_add(json_addr,
8563 "defaultNotSent");
8564 }
8565
dff8f48d 8566 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8567 if (is_evpn_enabled())
60466a63
QY
8568 json_object_boolean_true_add(
8569 json_addr, "advertiseAllVnis");
dff8f48d
MK
8570 }
8571
d62a17ae 8572 if (filter->plist[FILTER_IN].name
8573 || filter->dlist[FILTER_IN].name
8574 || filter->aslist[FILTER_IN].name
8575 || filter->map[RMAP_IN].name)
8576 json_object_boolean_true_add(json_addr,
8577 "inboundPathPolicyConfig");
8578 if (filter->plist[FILTER_OUT].name
8579 || filter->dlist[FILTER_OUT].name
8580 || filter->aslist[FILTER_OUT].name
8581 || filter->map[RMAP_OUT].name || filter->usmap.name)
8582 json_object_boolean_true_add(
8583 json_addr, "outboundPathPolicyConfig");
8584
8585 /* prefix-list */
8586 if (filter->plist[FILTER_IN].name)
8587 json_object_string_add(json_addr,
8588 "incomingUpdatePrefixFilterList",
8589 filter->plist[FILTER_IN].name);
8590 if (filter->plist[FILTER_OUT].name)
8591 json_object_string_add(json_addr,
8592 "outgoingUpdatePrefixFilterList",
8593 filter->plist[FILTER_OUT].name);
8594
8595 /* distribute-list */
8596 if (filter->dlist[FILTER_IN].name)
8597 json_object_string_add(
8598 json_addr, "incomingUpdateNetworkFilterList",
8599 filter->dlist[FILTER_IN].name);
8600 if (filter->dlist[FILTER_OUT].name)
8601 json_object_string_add(
8602 json_addr, "outgoingUpdateNetworkFilterList",
8603 filter->dlist[FILTER_OUT].name);
8604
8605 /* filter-list. */
8606 if (filter->aslist[FILTER_IN].name)
8607 json_object_string_add(json_addr,
8608 "incomingUpdateAsPathFilterList",
8609 filter->aslist[FILTER_IN].name);
8610 if (filter->aslist[FILTER_OUT].name)
8611 json_object_string_add(json_addr,
8612 "outgoingUpdateAsPathFilterList",
8613 filter->aslist[FILTER_OUT].name);
8614
8615 /* route-map. */
8616 if (filter->map[RMAP_IN].name)
8617 json_object_string_add(
8618 json_addr, "routeMapForIncomingAdvertisements",
8619 filter->map[RMAP_IN].name);
8620 if (filter->map[RMAP_OUT].name)
8621 json_object_string_add(
8622 json_addr, "routeMapForOutgoingAdvertisements",
8623 filter->map[RMAP_OUT].name);
8624
8625 /* unsuppress-map */
8626 if (filter->usmap.name)
8627 json_object_string_add(json_addr,
8628 "selectiveUnsuppressRouteMap",
8629 filter->usmap.name);
8630
8631 /* Receive prefix count */
8632 json_object_int_add(json_addr, "acceptedPrefixCounter",
8633 p->pcount[afi][safi]);
8634
8635 /* Maximum prefix */
8636 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8637 json_object_int_add(json_addr, "prefixAllowedMax",
8638 p->pmax[afi][safi]);
8639 if (CHECK_FLAG(p->af_flags[afi][safi],
8640 PEER_FLAG_MAX_PREFIX_WARNING))
8641 json_object_boolean_true_add(
8642 json_addr, "prefixAllowedMaxWarning");
8643 json_object_int_add(json_addr,
8644 "prefixAllowedWarningThresh",
8645 p->pmax_threshold[afi][safi]);
8646 if (p->pmax_restart[afi][safi])
8647 json_object_int_add(
8648 json_addr,
8649 "prefixAllowedRestartIntervalMsecs",
8650 p->pmax_restart[afi][safi] * 60000);
8651 }
8652 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8653 json_addr);
8654
8655 } else {
8656 filter = &p->filter[afi][safi];
8657
8658 vty_out(vty, " For address family: %s\n",
8659 afi_safi_print(afi, safi));
8660
8661 if (peer_group_active(p))
8662 vty_out(vty, " %s peer-group member\n",
8663 p->group->name);
8664
8665 paf = peer_af_find(p, afi, safi);
8666 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8667 vty_out(vty, " Update group %" PRIu64
8668 ", subgroup %" PRIu64 "\n",
d62a17ae 8669 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8670 vty_out(vty, " Packet Queue length %d\n",
8671 bpacket_queue_virtual_length(paf));
8672 } else {
8673 vty_out(vty, " Not part of any update group\n");
8674 }
8675 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8676 || CHECK_FLAG(p->af_cap[afi][safi],
8677 PEER_CAP_ORF_PREFIX_SM_RCV)
8678 || CHECK_FLAG(p->af_cap[afi][safi],
8679 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8680 || CHECK_FLAG(p->af_cap[afi][safi],
8681 PEER_CAP_ORF_PREFIX_RM_ADV)
8682 || CHECK_FLAG(p->af_cap[afi][safi],
8683 PEER_CAP_ORF_PREFIX_RM_RCV)
8684 || CHECK_FLAG(p->af_cap[afi][safi],
8685 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8686 vty_out(vty, " AF-dependant capabilities:\n");
8687
8688 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8689 || CHECK_FLAG(p->af_cap[afi][safi],
8690 PEER_CAP_ORF_PREFIX_SM_RCV)
8691 || CHECK_FLAG(p->af_cap[afi][safi],
8692 PEER_CAP_ORF_PREFIX_RM_ADV)
8693 || CHECK_FLAG(p->af_cap[afi][safi],
8694 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8695 vty_out(vty,
8696 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8697 ORF_TYPE_PREFIX);
8698 bgp_show_peer_afi_orf_cap(
8699 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8700 PEER_CAP_ORF_PREFIX_RM_ADV,
8701 PEER_CAP_ORF_PREFIX_SM_RCV,
8702 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8703 }
8704 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8705 || CHECK_FLAG(p->af_cap[afi][safi],
8706 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8707 || CHECK_FLAG(p->af_cap[afi][safi],
8708 PEER_CAP_ORF_PREFIX_RM_ADV)
8709 || CHECK_FLAG(p->af_cap[afi][safi],
8710 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8711 vty_out(vty,
8712 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8713 ORF_TYPE_PREFIX_OLD);
8714 bgp_show_peer_afi_orf_cap(
8715 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8716 PEER_CAP_ORF_PREFIX_RM_ADV,
8717 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8718 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8719 }
8720
8721 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8722 orf_pfx_count = prefix_bgp_show_prefix_list(
8723 NULL, afi, orf_pfx_name, use_json);
8724
8725 if (CHECK_FLAG(p->af_sflags[afi][safi],
8726 PEER_STATUS_ORF_PREFIX_SEND)
8727 || orf_pfx_count) {
8728 vty_out(vty, " Outbound Route Filter (ORF):");
8729 if (CHECK_FLAG(p->af_sflags[afi][safi],
8730 PEER_STATUS_ORF_PREFIX_SEND))
8731 vty_out(vty, " sent;");
8732 if (orf_pfx_count)
8733 vty_out(vty, " received (%d entries)",
8734 orf_pfx_count);
8735 vty_out(vty, "\n");
8736 }
8737 if (CHECK_FLAG(p->af_sflags[afi][safi],
8738 PEER_STATUS_ORF_WAIT_REFRESH))
8739 vty_out(vty,
8740 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8741
8742 if (CHECK_FLAG(p->af_flags[afi][safi],
8743 PEER_FLAG_REFLECTOR_CLIENT))
8744 vty_out(vty, " Route-Reflector Client\n");
8745 if (CHECK_FLAG(p->af_flags[afi][safi],
8746 PEER_FLAG_RSERVER_CLIENT))
8747 vty_out(vty, " Route-Server Client\n");
8748 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8749 vty_out(vty,
8750 " Inbound soft reconfiguration allowed\n");
8751
8752 if (CHECK_FLAG(p->af_flags[afi][safi],
8753 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8754 vty_out(vty,
8755 " Private AS numbers (all) replaced in updates to this neighbor\n");
8756 else if (CHECK_FLAG(p->af_flags[afi][safi],
8757 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8758 vty_out(vty,
8759 " Private AS numbers replaced in updates to this neighbor\n");
8760 else if (CHECK_FLAG(p->af_flags[afi][safi],
8761 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8762 vty_out(vty,
8763 " Private AS numbers (all) removed in updates to this neighbor\n");
8764 else if (CHECK_FLAG(p->af_flags[afi][safi],
8765 PEER_FLAG_REMOVE_PRIVATE_AS))
8766 vty_out(vty,
8767 " Private AS numbers removed in updates to this neighbor\n");
8768
8769 if (CHECK_FLAG(p->af_flags[afi][safi],
8770 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8771 vty_out(vty, " Advertise all paths via addpath\n");
8772
8773 if (CHECK_FLAG(p->af_flags[afi][safi],
8774 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8775 vty_out(vty,
8776 " Advertise bestpath per AS via addpath\n");
8777
8778 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8779 vty_out(vty,
8780 " Override ASNs in outbound updates if aspath equals remote-as\n");
8781
8782 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8783 || CHECK_FLAG(p->af_flags[afi][safi],
8784 PEER_FLAG_FORCE_NEXTHOP_SELF))
8785 vty_out(vty, " NEXT_HOP is always this router\n");
8786 if (CHECK_FLAG(p->af_flags[afi][safi],
8787 PEER_FLAG_AS_PATH_UNCHANGED))
8788 vty_out(vty,
8789 " AS_PATH is propagated unchanged to this neighbor\n");
8790 if (CHECK_FLAG(p->af_flags[afi][safi],
8791 PEER_FLAG_NEXTHOP_UNCHANGED))
8792 vty_out(vty,
8793 " NEXT_HOP is propagated unchanged to this neighbor\n");
8794 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8795 vty_out(vty,
8796 " MED is propagated unchanged to this neighbor\n");
8797 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8798 || CHECK_FLAG(p->af_flags[afi][safi],
8799 PEER_FLAG_SEND_EXT_COMMUNITY)
8800 || CHECK_FLAG(p->af_flags[afi][safi],
8801 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8802 vty_out(vty,
8803 " Community attribute sent to this neighbor");
8804 if (CHECK_FLAG(p->af_flags[afi][safi],
8805 PEER_FLAG_SEND_COMMUNITY)
8806 && CHECK_FLAG(p->af_flags[afi][safi],
8807 PEER_FLAG_SEND_EXT_COMMUNITY)
8808 && CHECK_FLAG(p->af_flags[afi][safi],
8809 PEER_FLAG_SEND_LARGE_COMMUNITY))
8810 vty_out(vty, "(all)\n");
8811 else if (CHECK_FLAG(p->af_flags[afi][safi],
8812 PEER_FLAG_SEND_LARGE_COMMUNITY))
8813 vty_out(vty, "(large)\n");
8814 else if (CHECK_FLAG(p->af_flags[afi][safi],
8815 PEER_FLAG_SEND_EXT_COMMUNITY))
8816 vty_out(vty, "(extended)\n");
8817 else
8818 vty_out(vty, "(standard)\n");
8819 }
8820 if (CHECK_FLAG(p->af_flags[afi][safi],
8821 PEER_FLAG_DEFAULT_ORIGINATE)) {
8822 vty_out(vty, " Default information originate,");
8823
8824 if (p->default_rmap[afi][safi].name)
8825 vty_out(vty, " default route-map %s%s,",
8826 p->default_rmap[afi][safi].map ? "*"
8827 : "",
8828 p->default_rmap[afi][safi].name);
8829 if (paf && PAF_SUBGRP(paf)
8830 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8831 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8832 vty_out(vty, " default sent\n");
8833 else
8834 vty_out(vty, " default not sent\n");
8835 }
8836
dff8f48d
MK
8837 /* advertise-vni-all */
8838 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8839 if (is_evpn_enabled())
dff8f48d
MK
8840 vty_out(vty, " advertise-all-vni\n");
8841 }
8842
d62a17ae 8843 if (filter->plist[FILTER_IN].name
8844 || filter->dlist[FILTER_IN].name
8845 || filter->aslist[FILTER_IN].name
8846 || filter->map[RMAP_IN].name)
8847 vty_out(vty, " Inbound path policy configured\n");
8848 if (filter->plist[FILTER_OUT].name
8849 || filter->dlist[FILTER_OUT].name
8850 || filter->aslist[FILTER_OUT].name
8851 || filter->map[RMAP_OUT].name || filter->usmap.name)
8852 vty_out(vty, " Outbound path policy configured\n");
8853
8854 /* prefix-list */
8855 if (filter->plist[FILTER_IN].name)
8856 vty_out(vty,
8857 " Incoming update prefix filter list is %s%s\n",
8858 filter->plist[FILTER_IN].plist ? "*" : "",
8859 filter->plist[FILTER_IN].name);
8860 if (filter->plist[FILTER_OUT].name)
8861 vty_out(vty,
8862 " Outgoing update prefix filter list is %s%s\n",
8863 filter->plist[FILTER_OUT].plist ? "*" : "",
8864 filter->plist[FILTER_OUT].name);
8865
8866 /* distribute-list */
8867 if (filter->dlist[FILTER_IN].name)
8868 vty_out(vty,
8869 " Incoming update network filter list is %s%s\n",
8870 filter->dlist[FILTER_IN].alist ? "*" : "",
8871 filter->dlist[FILTER_IN].name);
8872 if (filter->dlist[FILTER_OUT].name)
8873 vty_out(vty,
8874 " Outgoing update network filter list is %s%s\n",
8875 filter->dlist[FILTER_OUT].alist ? "*" : "",
8876 filter->dlist[FILTER_OUT].name);
8877
8878 /* filter-list. */
8879 if (filter->aslist[FILTER_IN].name)
8880 vty_out(vty,
8881 " Incoming update AS path filter list is %s%s\n",
8882 filter->aslist[FILTER_IN].aslist ? "*" : "",
8883 filter->aslist[FILTER_IN].name);
8884 if (filter->aslist[FILTER_OUT].name)
8885 vty_out(vty,
8886 " Outgoing update AS path filter list is %s%s\n",
8887 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8888 filter->aslist[FILTER_OUT].name);
8889
8890 /* route-map. */
8891 if (filter->map[RMAP_IN].name)
8892 vty_out(vty,
8893 " Route map for incoming advertisements is %s%s\n",
8894 filter->map[RMAP_IN].map ? "*" : "",
8895 filter->map[RMAP_IN].name);
8896 if (filter->map[RMAP_OUT].name)
8897 vty_out(vty,
8898 " Route map for outgoing advertisements is %s%s\n",
8899 filter->map[RMAP_OUT].map ? "*" : "",
8900 filter->map[RMAP_OUT].name);
8901
8902 /* unsuppress-map */
8903 if (filter->usmap.name)
8904 vty_out(vty,
8905 " Route map for selective unsuppress is %s%s\n",
8906 filter->usmap.map ? "*" : "",
8907 filter->usmap.name);
8908
8909 /* Receive prefix count */
8910 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8911
8912 /* Maximum prefix */
8913 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8914 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8915 p->pmax[afi][safi],
8916 CHECK_FLAG(p->af_flags[afi][safi],
8917 PEER_FLAG_MAX_PREFIX_WARNING)
8918 ? " (warning-only)"
8919 : "");
8920 vty_out(vty, " Threshold for warning message %d%%",
8921 p->pmax_threshold[afi][safi]);
8922 if (p->pmax_restart[afi][safi])
8923 vty_out(vty, ", restart interval %d min",
8924 p->pmax_restart[afi][safi]);
8925 vty_out(vty, "\n");
8926 }
8927
8928 vty_out(vty, "\n");
8929 }
8930}
8931
d7c0a89a 8932static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
d62a17ae 8933 json_object *json)
718e3744 8934{
d62a17ae 8935 struct bgp *bgp;
8936 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8937 char timebuf[BGP_UPTIME_LEN];
8938 char dn_flag[2];
8939 const char *subcode_str;
8940 const char *code_str;
8941 afi_t afi;
8942 safi_t safi;
d7c0a89a
QY
8943 uint16_t i;
8944 uint8_t *msg;
d62a17ae 8945 json_object *json_neigh = NULL;
8946 time_t epoch_tbuf;
718e3744 8947
d62a17ae 8948 bgp = p->bgp;
8949
8950 if (use_json)
8951 json_neigh = json_object_new_object();
8952
8953 memset(dn_flag, '\0', sizeof(dn_flag));
8954 if (!p->conf_if && peer_dynamic_neighbor(p))
8955 dn_flag[0] = '*';
8956
8957 if (!use_json) {
8958 if (p->conf_if) /* Configured interface name. */
8959 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8960 BGP_PEER_SU_UNSPEC(p)
8961 ? "None"
8962 : sockunion2str(&p->su, buf,
8963 SU_ADDRSTRLEN));
8964 else /* Configured IP address. */
8965 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8966 p->host);
8967 }
8968
8969 if (use_json) {
8970 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8971 json_object_string_add(json_neigh, "bgpNeighborAddr",
8972 "none");
8973 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8974 json_object_string_add(
8975 json_neigh, "bgpNeighborAddr",
8976 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8977
8978 json_object_int_add(json_neigh, "remoteAs", p->as);
8979
8980 if (p->change_local_as)
8981 json_object_int_add(json_neigh, "localAs",
8982 p->change_local_as);
8983 else
8984 json_object_int_add(json_neigh, "localAs", p->local_as);
8985
8986 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8987 json_object_boolean_true_add(json_neigh,
8988 "localAsNoPrepend");
8989
8990 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8991 json_object_boolean_true_add(json_neigh,
8992 "localAsReplaceAs");
8993 } else {
8994 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8995 || (p->as_type == AS_INTERNAL))
8996 vty_out(vty, "remote AS %u, ", p->as);
8997 else
8998 vty_out(vty, "remote AS Unspecified, ");
8999 vty_out(vty, "local AS %u%s%s, ",
9000 p->change_local_as ? p->change_local_as : p->local_as,
9001 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9002 ? " no-prepend"
9003 : "",
9004 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9005 ? " replace-as"
9006 : "");
9007 }
9008 /* peer type internal, external, confed-internal or confed-external */
9009 if (p->as == p->local_as) {
9010 if (use_json) {
9011 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9012 json_object_boolean_true_add(
9013 json_neigh, "nbrConfedInternalLink");
9014 else
9015 json_object_boolean_true_add(json_neigh,
9016 "nbrInternalLink");
9017 } else {
9018 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9019 vty_out(vty, "confed-internal link\n");
9020 else
9021 vty_out(vty, "internal link\n");
9022 }
9023 } else {
9024 if (use_json) {
9025 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9026 json_object_boolean_true_add(
9027 json_neigh, "nbrConfedExternalLink");
9028 else
9029 json_object_boolean_true_add(json_neigh,
9030 "nbrExternalLink");
9031 } else {
9032 if (bgp_confederation_peers_check(bgp, p->as))
9033 vty_out(vty, "confed-external link\n");
9034 else
9035 vty_out(vty, "external link\n");
9036 }
9037 }
9038
9039 /* Description. */
9040 if (p->desc) {
9041 if (use_json)
9042 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9043 else
9044 vty_out(vty, " Description: %s\n", p->desc);
9045 }
9046
9047 if (p->hostname) {
9048 if (use_json) {
9049 if (p->hostname)
9050 json_object_string_add(json_neigh, "hostname",
9051 p->hostname);
9052
9053 if (p->domainname)
9054 json_object_string_add(json_neigh, "domainname",
9055 p->domainname);
9056 } else {
9057 if (p->domainname && (p->domainname[0] != '\0'))
9058 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9059 p->domainname);
9060 else
9061 vty_out(vty, "Hostname: %s\n", p->hostname);
9062 }
9063 }
9064
9065 /* Peer-group */
9066 if (p->group) {
9067 if (use_json) {
9068 json_object_string_add(json_neigh, "peerGroup",
9069 p->group->name);
9070
9071 if (dn_flag[0]) {
9072 struct prefix prefix, *range = NULL;
9073
9074 sockunion2hostprefix(&(p->su), &prefix);
9075 range = peer_group_lookup_dynamic_neighbor_range(
9076 p->group, &prefix);
9077
9078 if (range) {
9079 prefix2str(range, buf1, sizeof(buf1));
9080 json_object_string_add(
9081 json_neigh,
9082 "peerSubnetRangeGroup", buf1);
9083 }
9084 }
9085 } else {
9086 vty_out(vty,
9087 " Member of peer-group %s for session parameters\n",
9088 p->group->name);
9089
9090 if (dn_flag[0]) {
9091 struct prefix prefix, *range = NULL;
9092
9093 sockunion2hostprefix(&(p->su), &prefix);
9094 range = peer_group_lookup_dynamic_neighbor_range(
9095 p->group, &prefix);
9096
9097 if (range) {
9098 prefix2str(range, buf1, sizeof(buf1));
9099 vty_out(vty,
9100 " Belongs to the subnet range group: %s\n",
9101 buf1);
9102 }
9103 }
9104 }
9105 }
9106
9107 if (use_json) {
9108 /* Administrative shutdown. */
9109 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9110 json_object_boolean_true_add(json_neigh,
9111 "adminShutDown");
9112
9113 /* BGP Version. */
9114 json_object_int_add(json_neigh, "bgpVersion", 4);
9115 json_object_string_add(
9116 json_neigh, "remoteRouterId",
9117 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9118
9119 /* Confederation */
9120 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9121 && bgp_confederation_peers_check(bgp, p->as))
9122 json_object_boolean_true_add(json_neigh,
9123 "nbrCommonAdmin");
9124
9125 /* Status. */
9126 json_object_string_add(
9127 json_neigh, "bgpState",
9128 lookup_msg(bgp_status_msg, p->status, NULL));
9129
9130 if (p->status == Established) {
9131 time_t uptime;
d62a17ae 9132
9133 uptime = bgp_clock();
9134 uptime -= p->uptime;
d62a17ae 9135 epoch_tbuf = time(NULL) - uptime;
9136
e24be241 9137#if defined(VERSION_TYPE_DEV) && CONFDATE > 20200101
a4d82a8a
PZ
9138 CPP_NOTICE(
9139 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9140#endif
9141 /*
9142 * bgpTimerUp was miliseconds that was accurate
9143 * up to 1 day, then the value returned
9144 * became garbage. So in order to provide
9145 * some level of backwards compatability,
9146 * we still provde the data, but now
9147 * we are returning the correct value
9148 * and also adding a new bgpTimerUpMsec
9149 * which will allow us to deprecate
9150 * this eventually
9151 */
d62a17ae 9152 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9153 uptime * 1000);
d3c7efed
DS
9154 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9155 uptime * 1000);
d62a17ae 9156 json_object_string_add(json_neigh, "bgpTimerUpString",
9157 peer_uptime(p->uptime, timebuf,
9158 BGP_UPTIME_LEN, 0,
9159 NULL));
9160 json_object_int_add(json_neigh,
9161 "bgpTimerUpEstablishedEpoch",
9162 epoch_tbuf);
9163 }
9164
9165 else if (p->status == Active) {
9166 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9167 json_object_string_add(json_neigh, "bgpStateIs",
9168 "passive");
9169 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9170 json_object_string_add(json_neigh, "bgpStateIs",
9171 "passiveNSF");
9172 }
9173
9174 /* read timer */
9175 time_t uptime;
9176 struct tm *tm;
9177
9178 uptime = bgp_clock();
9179 uptime -= p->readtime;
9180 tm = gmtime(&uptime);
9181 json_object_int_add(json_neigh, "bgpTimerLastRead",
9182 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9183 + (tm->tm_hour * 3600000));
9184
9185 uptime = bgp_clock();
9186 uptime -= p->last_write;
9187 tm = gmtime(&uptime);
9188 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9189 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9190 + (tm->tm_hour * 3600000));
9191
9192 uptime = bgp_clock();
9193 uptime -= p->update_time;
9194 tm = gmtime(&uptime);
9195 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9196 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9197 + (tm->tm_hour * 3600000));
9198
9199 /* Configured timer values. */
9200 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9201 p->v_holdtime * 1000);
9202 json_object_int_add(json_neigh,
9203 "bgpTimerKeepAliveIntervalMsecs",
9204 p->v_keepalive * 1000);
b90a8e13 9205 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9206 json_object_int_add(json_neigh,
9207 "bgpTimerConfiguredHoldTimeMsecs",
9208 p->holdtime * 1000);
9209 json_object_int_add(
9210 json_neigh,
9211 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9212 p->keepalive * 1000);
d25e4efc 9213 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9214 || (bgp->default_keepalive
9215 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9216 json_object_int_add(json_neigh,
9217 "bgpTimerConfiguredHoldTimeMsecs",
9218 bgp->default_holdtime);
9219 json_object_int_add(
9220 json_neigh,
9221 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9222 bgp->default_keepalive);
d62a17ae 9223 }
9224 } else {
9225 /* Administrative shutdown. */
9226 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9227 vty_out(vty, " Administratively shut down\n");
9228
9229 /* BGP Version. */
9230 vty_out(vty, " BGP version 4");
9231 vty_out(vty, ", remote router ID %s\n",
9232 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9233
9234 /* Confederation */
9235 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9236 && bgp_confederation_peers_check(bgp, p->as))
9237 vty_out(vty,
9238 " Neighbor under common administration\n");
9239
9240 /* Status. */
9241 vty_out(vty, " BGP state = %s",
9242 lookup_msg(bgp_status_msg, p->status, NULL));
9243
9244 if (p->status == Established)
9245 vty_out(vty, ", up for %8s",
9246 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9247 0, NULL));
9248
9249 else if (p->status == Active) {
9250 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9251 vty_out(vty, " (passive)");
9252 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9253 vty_out(vty, " (NSF passive)");
9254 }
9255 vty_out(vty, "\n");
9256
9257 /* read timer */
9258 vty_out(vty, " Last read %s",
9259 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9260 NULL));
9261 vty_out(vty, ", Last write %s\n",
9262 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9263 NULL));
9264
9265 /* Configured timer values. */
9266 vty_out(vty,
9267 " Hold time is %d, keepalive interval is %d seconds\n",
9268 p->v_holdtime, p->v_keepalive);
b90a8e13 9269 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9270 vty_out(vty, " Configured hold time is %d",
9271 p->holdtime);
9272 vty_out(vty, ", keepalive interval is %d seconds\n",
9273 p->keepalive);
d25e4efc 9274 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9275 || (bgp->default_keepalive
9276 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9277 vty_out(vty, " Configured hold time is %d",
9278 bgp->default_holdtime);
9279 vty_out(vty, ", keepalive interval is %d seconds\n",
9280 bgp->default_keepalive);
d62a17ae 9281 }
9282 }
9283 /* Capability. */
9284 if (p->status == Established) {
9285 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9286 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9287 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9288 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9289 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9290 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9291 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9292 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9293 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9294 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9295 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9296 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9297 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9298 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9299 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9300 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9301 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9302 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9303 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9304 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9305 if (use_json) {
9306 json_object *json_cap = NULL;
9307
9308 json_cap = json_object_new_object();
9309
9310 /* AS4 */
9311 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9312 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9313 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9314 && CHECK_FLAG(p->cap,
9315 PEER_CAP_AS4_RCV))
9316 json_object_string_add(
9317 json_cap, "4byteAs",
9318 "advertisedAndReceived");
9319 else if (CHECK_FLAG(p->cap,
9320 PEER_CAP_AS4_ADV))
9321 json_object_string_add(
9322 json_cap, "4byteAs",
9323 "advertised");
9324 else if (CHECK_FLAG(p->cap,
9325 PEER_CAP_AS4_RCV))
9326 json_object_string_add(
9327 json_cap, "4byteAs",
9328 "received");
9329 }
9330
9331 /* AddPath */
9332 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9333 || CHECK_FLAG(p->cap,
9334 PEER_CAP_ADDPATH_ADV)) {
9335 json_object *json_add = NULL;
9336 const char *print_store;
9337
9338 json_add = json_object_new_object();
9339
05c7a1cc
QY
9340 FOREACH_AFI_SAFI (afi, safi) {
9341 json_object *json_sub = NULL;
9342 json_sub =
9343 json_object_new_object();
9344 print_store = afi_safi_print(
9345 afi, safi);
d62a17ae 9346
05c7a1cc
QY
9347 if (CHECK_FLAG(
9348 p->af_cap[afi]
9349 [safi],
9350 PEER_CAP_ADDPATH_AF_TX_ADV)
9351 || CHECK_FLAG(
9352 p->af_cap[afi]
9353 [safi],
9354 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9355 if (CHECK_FLAG(
9356 p->af_cap
9357 [afi]
9358 [safi],
9359 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9360 && CHECK_FLAG(
d62a17ae 9361 p->af_cap
9362 [afi]
9363 [safi],
05c7a1cc
QY
9364 PEER_CAP_ADDPATH_AF_TX_RCV))
9365 json_object_boolean_true_add(
9366 json_sub,
9367 "txAdvertisedAndReceived");
9368 else if (
9369 CHECK_FLAG(
9370 p->af_cap
9371 [afi]
9372 [safi],
9373 PEER_CAP_ADDPATH_AF_TX_ADV))
9374 json_object_boolean_true_add(
9375 json_sub,
9376 "txAdvertised");
9377 else if (
9378 CHECK_FLAG(
9379 p->af_cap
9380 [afi]
9381 [safi],
9382 PEER_CAP_ADDPATH_AF_TX_RCV))
9383 json_object_boolean_true_add(
9384 json_sub,
9385 "txReceived");
9386 }
d62a17ae 9387
05c7a1cc
QY
9388 if (CHECK_FLAG(
9389 p->af_cap[afi]
9390 [safi],
9391 PEER_CAP_ADDPATH_AF_RX_ADV)
9392 || CHECK_FLAG(
9393 p->af_cap[afi]
9394 [safi],
9395 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9396 if (CHECK_FLAG(
9397 p->af_cap
9398 [afi]
9399 [safi],
9400 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9401 && CHECK_FLAG(
d62a17ae 9402 p->af_cap
9403 [afi]
9404 [safi],
9405 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9406 json_object_boolean_true_add(
9407 json_sub,
9408 "rxAdvertisedAndReceived");
9409 else if (
9410 CHECK_FLAG(
9411 p->af_cap
9412 [afi]
9413 [safi],
9414 PEER_CAP_ADDPATH_AF_RX_ADV))
9415 json_object_boolean_true_add(
9416 json_sub,
9417 "rxAdvertised");
9418 else if (
9419 CHECK_FLAG(
9420 p->af_cap
9421 [afi]
9422 [safi],
9423 PEER_CAP_ADDPATH_AF_RX_RCV))
9424 json_object_boolean_true_add(
9425 json_sub,
9426 "rxReceived");
d62a17ae 9427 }
9428
05c7a1cc
QY
9429 if (CHECK_FLAG(
9430 p->af_cap[afi]
9431 [safi],
9432 PEER_CAP_ADDPATH_AF_TX_ADV)
9433 || CHECK_FLAG(
9434 p->af_cap[afi]
9435 [safi],
9436 PEER_CAP_ADDPATH_AF_TX_RCV)
9437 || CHECK_FLAG(
9438 p->af_cap[afi]
9439 [safi],
9440 PEER_CAP_ADDPATH_AF_RX_ADV)
9441 || CHECK_FLAG(
9442 p->af_cap[afi]
9443 [safi],
9444 PEER_CAP_ADDPATH_AF_RX_RCV))
9445 json_object_object_add(
9446 json_add,
9447 print_store,
9448 json_sub);
9449 else
9450 json_object_free(
9451 json_sub);
9452 }
9453
d62a17ae 9454 json_object_object_add(
9455 json_cap, "addPath", json_add);
9456 }
9457
9458 /* Dynamic */
9459 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9460 || CHECK_FLAG(p->cap,
9461 PEER_CAP_DYNAMIC_ADV)) {
9462 if (CHECK_FLAG(p->cap,
9463 PEER_CAP_DYNAMIC_ADV)
9464 && CHECK_FLAG(p->cap,
9465 PEER_CAP_DYNAMIC_RCV))
9466 json_object_string_add(
9467 json_cap, "dynamic",
9468 "advertisedAndReceived");
9469 else if (CHECK_FLAG(
9470 p->cap,
9471 PEER_CAP_DYNAMIC_ADV))
9472 json_object_string_add(
9473 json_cap, "dynamic",
9474 "advertised");
9475 else if (CHECK_FLAG(
9476 p->cap,
9477 PEER_CAP_DYNAMIC_RCV))
9478 json_object_string_add(
9479 json_cap, "dynamic",
9480 "received");
9481 }
9482
9483 /* Extended nexthop */
9484 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9485 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9486 json_object *json_nxt = NULL;
9487 const char *print_store;
9488
9489
9490 if (CHECK_FLAG(p->cap,
9491 PEER_CAP_ENHE_ADV)
9492 && CHECK_FLAG(p->cap,
9493 PEER_CAP_ENHE_RCV))
9494 json_object_string_add(
9495 json_cap,
9496 "extendedNexthop",
9497 "advertisedAndReceived");
9498 else if (CHECK_FLAG(p->cap,
9499 PEER_CAP_ENHE_ADV))
9500 json_object_string_add(
9501 json_cap,
9502 "extendedNexthop",
9503 "advertised");
9504 else if (CHECK_FLAG(p->cap,
9505 PEER_CAP_ENHE_RCV))
9506 json_object_string_add(
9507 json_cap,
9508 "extendedNexthop",
9509 "received");
9510
9511 if (CHECK_FLAG(p->cap,
9512 PEER_CAP_ENHE_RCV)) {
9513 json_nxt =
9514 json_object_new_object();
9515
9516 for (safi = SAFI_UNICAST;
9517 safi < SAFI_MAX; safi++) {
9518 if (CHECK_FLAG(
9519 p->af_cap
9520 [AFI_IP]
9521 [safi],
9522 PEER_CAP_ENHE_AF_RCV)) {
9523 print_store = afi_safi_print(
9524 AFI_IP,
9525 safi);
9526 json_object_string_add(
9527 json_nxt,
9528 print_store,
9529 "recieved");
9530 }
9531 }
9532 json_object_object_add(
9533 json_cap,
9534 "extendedNexthopFamililesByPeer",
9535 json_nxt);
9536 }
9537 }
9538
9539 /* Route Refresh */
9540 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9541 || CHECK_FLAG(p->cap,
9542 PEER_CAP_REFRESH_NEW_RCV)
9543 || CHECK_FLAG(p->cap,
9544 PEER_CAP_REFRESH_OLD_RCV)) {
9545 if (CHECK_FLAG(p->cap,
9546 PEER_CAP_REFRESH_ADV)
9547 && (CHECK_FLAG(
9548 p->cap,
9549 PEER_CAP_REFRESH_NEW_RCV)
9550 || CHECK_FLAG(
9551 p->cap,
9552 PEER_CAP_REFRESH_OLD_RCV))) {
9553 if (CHECK_FLAG(
9554 p->cap,
9555 PEER_CAP_REFRESH_OLD_RCV)
9556 && CHECK_FLAG(
9557 p->cap,
9558 PEER_CAP_REFRESH_NEW_RCV))
9559 json_object_string_add(
9560 json_cap,
9561 "routeRefresh",
9562 "advertisedAndReceivedOldNew");
9563 else {
9564 if (CHECK_FLAG(
9565 p->cap,
9566 PEER_CAP_REFRESH_OLD_RCV))
9567 json_object_string_add(
9568 json_cap,
9569 "routeRefresh",
9570 "advertisedAndReceivedOld");
9571 else
9572 json_object_string_add(
9573 json_cap,
9574 "routeRefresh",
9575 "advertisedAndReceivedNew");
9576 }
9577 } else if (
9578 CHECK_FLAG(
9579 p->cap,
9580 PEER_CAP_REFRESH_ADV))
9581 json_object_string_add(
9582 json_cap,
9583 "routeRefresh",
9584 "advertised");
9585 else if (
9586 CHECK_FLAG(
9587 p->cap,
9588 PEER_CAP_REFRESH_NEW_RCV)
9589 || CHECK_FLAG(
9590 p->cap,
9591 PEER_CAP_REFRESH_OLD_RCV))
9592 json_object_string_add(
9593 json_cap,
9594 "routeRefresh",
9595 "received");
9596 }
9597
9598 /* Multiprotocol Extensions */
9599 json_object *json_multi = NULL;
9600 json_multi = json_object_new_object();
9601
05c7a1cc
QY
9602 FOREACH_AFI_SAFI (afi, safi) {
9603 if (p->afc_adv[afi][safi]
9604 || p->afc_recv[afi][safi]) {
9605 json_object *json_exten = NULL;
9606 json_exten =
9607 json_object_new_object();
9608
d62a17ae 9609 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9610 && p->afc_recv[afi][safi])
9611 json_object_boolean_true_add(
9612 json_exten,
9613 "advertisedAndReceived");
9614 else if (p->afc_adv[afi][safi])
9615 json_object_boolean_true_add(
9616 json_exten,
9617 "advertised");
9618 else if (p->afc_recv[afi][safi])
9619 json_object_boolean_true_add(
9620 json_exten,
9621 "received");
d62a17ae 9622
05c7a1cc
QY
9623 json_object_object_add(
9624 json_multi,
9625 afi_safi_print(afi,
9626 safi),
9627 json_exten);
d62a17ae 9628 }
9629 }
9630 json_object_object_add(
9631 json_cap, "multiprotocolExtensions",
9632 json_multi);
9633
d77114b7 9634 /* Hostname capabilities */
60466a63 9635 json_object *json_hname = NULL;
d77114b7
MK
9636
9637 json_hname = json_object_new_object();
9638
9639 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9640 json_object_string_add(
60466a63
QY
9641 json_hname, "advHostName",
9642 bgp->peer_self->hostname
9643 ? bgp->peer_self
9644 ->hostname
d77114b7
MK
9645 : "n/a");
9646 json_object_string_add(
60466a63
QY
9647 json_hname, "advDomainName",
9648 bgp->peer_self->domainname
9649 ? bgp->peer_self
9650 ->domainname
d77114b7
MK
9651 : "n/a");
9652 }
9653
9654
9655 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9656 json_object_string_add(
60466a63
QY
9657 json_hname, "rcvHostName",
9658 p->hostname ? p->hostname
9659 : "n/a");
d77114b7 9660 json_object_string_add(
60466a63
QY
9661 json_hname, "rcvDomainName",
9662 p->domainname ? p->domainname
9663 : "n/a");
d77114b7
MK
9664 }
9665
60466a63 9666 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9667 json_hname);
9668
d62a17ae 9669 /* Gracefull Restart */
9670 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9671 || CHECK_FLAG(p->cap,
9672 PEER_CAP_RESTART_ADV)) {
9673 if (CHECK_FLAG(p->cap,
9674 PEER_CAP_RESTART_ADV)
9675 && CHECK_FLAG(p->cap,
9676 PEER_CAP_RESTART_RCV))
9677 json_object_string_add(
9678 json_cap,
9679 "gracefulRestart",
9680 "advertisedAndReceived");
9681 else if (CHECK_FLAG(
9682 p->cap,
9683 PEER_CAP_RESTART_ADV))
9684 json_object_string_add(
9685 json_cap,
9686 "gracefulRestartCapability",
9687 "advertised");
9688 else if (CHECK_FLAG(
9689 p->cap,
9690 PEER_CAP_RESTART_RCV))
9691 json_object_string_add(
9692 json_cap,
9693 "gracefulRestartCapability",
9694 "received");
9695
9696 if (CHECK_FLAG(p->cap,
9697 PEER_CAP_RESTART_RCV)) {
9698 int restart_af_count = 0;
9699 json_object *json_restart =
9700 NULL;
9701 json_restart =
9702 json_object_new_object();
9703
9704 json_object_int_add(
9705 json_cap,
9706 "gracefulRestartRemoteTimerMsecs",
9707 p->v_gr_restart * 1000);
9708
05c7a1cc
QY
9709 FOREACH_AFI_SAFI (afi, safi) {
9710 if (CHECK_FLAG(
9711 p->af_cap
9712 [afi]
9713 [safi],
9714 PEER_CAP_RESTART_AF_RCV)) {
9715 json_object *
9716 json_sub =
9717 NULL;
9718 json_sub =
9719 json_object_new_object();
9720
d62a17ae 9721 if (CHECK_FLAG(
9722 p->af_cap
9723 [afi]
9724 [safi],
05c7a1cc
QY
9725 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9726 json_object_boolean_true_add(
9727 json_sub,
9728 "preserved");
9729 restart_af_count++;
9730 json_object_object_add(
9731 json_restart,
9732 afi_safi_print(
9733 afi,
9734 safi),
9735 json_sub);
d62a17ae 9736 }
9737 }
9738 if (!restart_af_count) {
9739 json_object_string_add(
9740 json_cap,
9741 "addressFamiliesByPeer",
9742 "none");
9743 json_object_free(
9744 json_restart);
9745 } else
9746 json_object_object_add(
9747 json_cap,
9748 "addressFamiliesByPeer",
9749 json_restart);
9750 }
9751 }
9752 json_object_object_add(json_neigh,
9753 "neighborCapabilities",
9754 json_cap);
9755 } else {
9756 vty_out(vty, " Neighbor capabilities:\n");
9757
9758 /* AS4 */
9759 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9760 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9761 vty_out(vty, " 4 Byte AS:");
9762 if (CHECK_FLAG(p->cap,
9763 PEER_CAP_AS4_ADV))
9764 vty_out(vty, " advertised");
9765 if (CHECK_FLAG(p->cap,
9766 PEER_CAP_AS4_RCV))
9767 vty_out(vty, " %sreceived",
9768 CHECK_FLAG(
9769 p->cap,
9770 PEER_CAP_AS4_ADV)
9771 ? "and "
9772 : "");
9773 vty_out(vty, "\n");
9774 }
9775
9776 /* AddPath */
9777 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9778 || CHECK_FLAG(p->cap,
9779 PEER_CAP_ADDPATH_ADV)) {
9780 vty_out(vty, " AddPath:\n");
9781
05c7a1cc
QY
9782 FOREACH_AFI_SAFI (afi, safi) {
9783 if (CHECK_FLAG(
9784 p->af_cap[afi]
9785 [safi],
9786 PEER_CAP_ADDPATH_AF_TX_ADV)
9787 || CHECK_FLAG(
9788 p->af_cap[afi]
9789 [safi],
9790 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9791 vty_out(vty,
9792 " %s: TX ",
9793 afi_safi_print(
9794 afi,
9795 safi));
9796
d62a17ae 9797 if (CHECK_FLAG(
9798 p->af_cap
9799 [afi]
9800 [safi],
05c7a1cc 9801 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 9802 vty_out(vty,
05c7a1cc 9803 "advertised %s",
d62a17ae 9804 afi_safi_print(
9805 afi,
9806 safi));
9807
05c7a1cc
QY
9808 if (CHECK_FLAG(
9809 p->af_cap
9810 [afi]
9811 [safi],
9812 PEER_CAP_ADDPATH_AF_TX_RCV))
9813 vty_out(vty,
9814 "%sreceived",
9815 CHECK_FLAG(
9816 p->af_cap
9817 [afi]
9818 [safi],
9819 PEER_CAP_ADDPATH_AF_TX_ADV)
9820 ? " and "
9821 : "");
d62a17ae 9822
05c7a1cc
QY
9823 vty_out(vty, "\n");
9824 }
d62a17ae 9825
05c7a1cc
QY
9826 if (CHECK_FLAG(
9827 p->af_cap[afi]
9828 [safi],
9829 PEER_CAP_ADDPATH_AF_RX_ADV)
9830 || CHECK_FLAG(
9831 p->af_cap[afi]
9832 [safi],
9833 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9834 vty_out(vty,
9835 " %s: RX ",
9836 afi_safi_print(
9837 afi,
9838 safi));
d62a17ae 9839
9840 if (CHECK_FLAG(
9841 p->af_cap
9842 [afi]
9843 [safi],
05c7a1cc 9844 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 9845 vty_out(vty,
05c7a1cc 9846 "advertised %s",
d62a17ae 9847 afi_safi_print(
9848 afi,
9849 safi));
9850
05c7a1cc
QY
9851 if (CHECK_FLAG(
9852 p->af_cap
9853 [afi]
9854 [safi],
9855 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 9856 vty_out(vty,
05c7a1cc
QY
9857 "%sreceived",
9858 CHECK_FLAG(
9859 p->af_cap
9860 [afi]
9861 [safi],
9862 PEER_CAP_ADDPATH_AF_RX_ADV)
9863 ? " and "
9864 : "");
9865
9866 vty_out(vty, "\n");
d62a17ae 9867 }
05c7a1cc 9868 }
d62a17ae 9869 }
9870
9871 /* Dynamic */
9872 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9873 || CHECK_FLAG(p->cap,
9874 PEER_CAP_DYNAMIC_ADV)) {
9875 vty_out(vty, " Dynamic:");
9876 if (CHECK_FLAG(p->cap,
9877 PEER_CAP_DYNAMIC_ADV))
9878 vty_out(vty, " advertised");
9879 if (CHECK_FLAG(p->cap,
9880 PEER_CAP_DYNAMIC_RCV))
9881 vty_out(vty, " %sreceived",
9882 CHECK_FLAG(
9883 p->cap,
9884 PEER_CAP_DYNAMIC_ADV)
9885 ? "and "
9886 : "");
9887 vty_out(vty, "\n");
9888 }
9889
9890 /* Extended nexthop */
9891 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9892 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9893 vty_out(vty, " Extended nexthop:");
9894 if (CHECK_FLAG(p->cap,
9895 PEER_CAP_ENHE_ADV))
9896 vty_out(vty, " advertised");
9897 if (CHECK_FLAG(p->cap,
9898 PEER_CAP_ENHE_RCV))
9899 vty_out(vty, " %sreceived",
9900 CHECK_FLAG(
9901 p->cap,
9902 PEER_CAP_ENHE_ADV)
9903 ? "and "
9904 : "");
9905 vty_out(vty, "\n");
9906
9907 if (CHECK_FLAG(p->cap,
9908 PEER_CAP_ENHE_RCV)) {
9909 vty_out(vty,
9910 " Address families by peer:\n ");
9911 for (safi = SAFI_UNICAST;
9912 safi < SAFI_MAX; safi++)
9913 if (CHECK_FLAG(
9914 p->af_cap
9915 [AFI_IP]
9916 [safi],
9917 PEER_CAP_ENHE_AF_RCV))
9918 vty_out(vty,
9919 " %s\n",
9920 afi_safi_print(
9921 AFI_IP,
9922 safi));
9923 }
9924 }
9925
9926 /* Route Refresh */
9927 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9928 || CHECK_FLAG(p->cap,
9929 PEER_CAP_REFRESH_NEW_RCV)
9930 || CHECK_FLAG(p->cap,
9931 PEER_CAP_REFRESH_OLD_RCV)) {
9932 vty_out(vty, " Route refresh:");
9933 if (CHECK_FLAG(p->cap,
9934 PEER_CAP_REFRESH_ADV))
9935 vty_out(vty, " advertised");
9936 if (CHECK_FLAG(p->cap,
9937 PEER_CAP_REFRESH_NEW_RCV)
9938 || CHECK_FLAG(
9939 p->cap,
9940 PEER_CAP_REFRESH_OLD_RCV))
9941 vty_out(vty, " %sreceived(%s)",
9942 CHECK_FLAG(
9943 p->cap,
9944 PEER_CAP_REFRESH_ADV)
9945 ? "and "
9946 : "",
9947 (CHECK_FLAG(
9948 p->cap,
9949 PEER_CAP_REFRESH_OLD_RCV)
9950 && CHECK_FLAG(
9951 p->cap,
9952 PEER_CAP_REFRESH_NEW_RCV))
9953 ? "old & new"
9954 : CHECK_FLAG(
9955 p->cap,
9956 PEER_CAP_REFRESH_OLD_RCV)
9957 ? "old"
9958 : "new");
9959
9960 vty_out(vty, "\n");
9961 }
9962
9963 /* Multiprotocol Extensions */
05c7a1cc
QY
9964 FOREACH_AFI_SAFI (afi, safi)
9965 if (p->afc_adv[afi][safi]
9966 || p->afc_recv[afi][safi]) {
9967 vty_out(vty,
9968 " Address Family %s:",
9969 afi_safi_print(afi,
9970 safi));
9971 if (p->afc_adv[afi][safi])
d62a17ae 9972 vty_out(vty,
05c7a1cc
QY
9973 " advertised");
9974 if (p->afc_recv[afi][safi])
9975 vty_out(vty,
9976 " %sreceived",
9977 p->afc_adv[afi]
9978 [safi]
9979 ? "and "
9980 : "");
9981 vty_out(vty, "\n");
9982 }
d62a17ae 9983
9984 /* Hostname capability */
60466a63 9985 vty_out(vty, " Hostname Capability:");
d77114b7
MK
9986
9987 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
9988 vty_out(vty,
9989 " advertised (name: %s,domain name: %s)",
60466a63
QY
9990 bgp->peer_self->hostname
9991 ? bgp->peer_self
9992 ->hostname
d77114b7 9993 : "n/a",
60466a63
QY
9994 bgp->peer_self->domainname
9995 ? bgp->peer_self
9996 ->domainname
d77114b7
MK
9997 : "n/a");
9998 } else {
9999 vty_out(vty, " not advertised");
d62a17ae 10000 }
10001
d77114b7 10002 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10003 vty_out(vty,
10004 " received (name: %s,domain name: %s)",
60466a63
QY
10005 p->hostname ? p->hostname
10006 : "n/a",
10007 p->domainname ? p->domainname
10008 : "n/a");
d77114b7
MK
10009 } else {
10010 vty_out(vty, " not received");
10011 }
10012
10013 vty_out(vty, "\n");
10014
d62a17ae 10015 /* Gracefull Restart */
10016 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10017 || CHECK_FLAG(p->cap,
10018 PEER_CAP_RESTART_ADV)) {
10019 vty_out(vty,
10020 " Graceful Restart Capabilty:");
10021 if (CHECK_FLAG(p->cap,
10022 PEER_CAP_RESTART_ADV))
10023 vty_out(vty, " advertised");
10024 if (CHECK_FLAG(p->cap,
10025 PEER_CAP_RESTART_RCV))
10026 vty_out(vty, " %sreceived",
10027 CHECK_FLAG(
10028 p->cap,
10029 PEER_CAP_RESTART_ADV)
10030 ? "and "
10031 : "");
10032 vty_out(vty, "\n");
10033
10034 if (CHECK_FLAG(p->cap,
10035 PEER_CAP_RESTART_RCV)) {
10036 int restart_af_count = 0;
10037
10038 vty_out(vty,
10039 " Remote Restart timer is %d seconds\n",
10040 p->v_gr_restart);
10041 vty_out(vty,
10042 " Address families by peer:\n ");
10043
05c7a1cc
QY
10044 FOREACH_AFI_SAFI (afi, safi)
10045 if (CHECK_FLAG(
10046 p->af_cap
10047 [afi]
10048 [safi],
10049 PEER_CAP_RESTART_AF_RCV)) {
10050 vty_out(vty,
10051 "%s%s(%s)",
10052 restart_af_count
10053 ? ", "
10054 : "",
10055 afi_safi_print(
10056 afi,
10057 safi),
10058 CHECK_FLAG(
10059 p->af_cap
10060 [afi]
10061 [safi],
10062 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10063 ? "preserved"
10064 : "not preserved");
10065 restart_af_count++;
10066 }
d62a17ae 10067 if (!restart_af_count)
10068 vty_out(vty, "none");
10069 vty_out(vty, "\n");
10070 }
10071 }
10072 }
10073 }
10074 }
10075
10076 /* graceful restart information */
10077 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10078 || p->t_gr_stale) {
10079 json_object *json_grace = NULL;
10080 json_object *json_grace_send = NULL;
10081 json_object *json_grace_recv = NULL;
10082 int eor_send_af_count = 0;
10083 int eor_receive_af_count = 0;
10084
10085 if (use_json) {
10086 json_grace = json_object_new_object();
10087 json_grace_send = json_object_new_object();
10088 json_grace_recv = json_object_new_object();
10089
10090 if (p->status == Established) {
05c7a1cc
QY
10091 FOREACH_AFI_SAFI (afi, safi) {
10092 if (CHECK_FLAG(p->af_sflags[afi][safi],
10093 PEER_STATUS_EOR_SEND)) {
10094 json_object_boolean_true_add(
10095 json_grace_send,
10096 afi_safi_print(afi,
10097 safi));
10098 eor_send_af_count++;
d62a17ae 10099 }
10100 }
05c7a1cc
QY
10101 FOREACH_AFI_SAFI (afi, safi) {
10102 if (CHECK_FLAG(
10103 p->af_sflags[afi][safi],
10104 PEER_STATUS_EOR_RECEIVED)) {
10105 json_object_boolean_true_add(
10106 json_grace_recv,
10107 afi_safi_print(afi,
10108 safi));
10109 eor_receive_af_count++;
d62a17ae 10110 }
10111 }
10112 }
10113
10114 json_object_object_add(json_grace, "endOfRibSend",
10115 json_grace_send);
10116 json_object_object_add(json_grace, "endOfRibRecv",
10117 json_grace_recv);
10118
10119 if (p->t_gr_restart)
10120 json_object_int_add(json_grace,
10121 "gracefulRestartTimerMsecs",
10122 thread_timer_remain_second(
10123 p->t_gr_restart)
10124 * 1000);
10125
10126 if (p->t_gr_stale)
10127 json_object_int_add(
10128 json_grace,
10129 "gracefulStalepathTimerMsecs",
10130 thread_timer_remain_second(
10131 p->t_gr_stale)
10132 * 1000);
10133
10134 json_object_object_add(
10135 json_neigh, "gracefulRestartInfo", json_grace);
10136 } else {
10137 vty_out(vty, " Graceful restart informations:\n");
10138 if (p->status == Established) {
10139 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10140 FOREACH_AFI_SAFI (afi, safi) {
10141 if (CHECK_FLAG(p->af_sflags[afi][safi],
10142 PEER_STATUS_EOR_SEND)) {
10143 vty_out(vty, "%s%s",
10144 eor_send_af_count ? ", "
10145 : "",
10146 afi_safi_print(afi,
10147 safi));
10148 eor_send_af_count++;
d62a17ae 10149 }
10150 }
10151 vty_out(vty, "\n");
10152 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10153 FOREACH_AFI_SAFI (afi, safi) {
10154 if (CHECK_FLAG(
10155 p->af_sflags[afi][safi],
10156 PEER_STATUS_EOR_RECEIVED)) {
10157 vty_out(vty, "%s%s",
10158 eor_receive_af_count
10159 ? ", "
10160 : "",
10161 afi_safi_print(afi,
10162 safi));
10163 eor_receive_af_count++;
d62a17ae 10164 }
10165 }
10166 vty_out(vty, "\n");
10167 }
10168
10169 if (p->t_gr_restart)
10170 vty_out(vty,
10171 " The remaining time of restart timer is %ld\n",
10172 thread_timer_remain_second(
10173 p->t_gr_restart));
10174
10175 if (p->t_gr_stale)
10176 vty_out(vty,
10177 " The remaining time of stalepath timer is %ld\n",
10178 thread_timer_remain_second(
10179 p->t_gr_stale));
10180 }
10181 }
10182 if (use_json) {
10183 json_object *json_stat = NULL;
10184 json_stat = json_object_new_object();
10185 /* Packet counts. */
10186 json_object_int_add(json_stat, "depthInq", 0);
10187 json_object_int_add(json_stat, "depthOutq",
10188 (unsigned long)p->obuf->count);
0112e9e0
QY
10189 json_object_int_add(json_stat, "opensSent",
10190 atomic_load_explicit(&p->open_out,
10191 memory_order_relaxed));
10192 json_object_int_add(json_stat, "opensRecv",
10193 atomic_load_explicit(&p->open_in,
10194 memory_order_relaxed));
d62a17ae 10195 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10196 atomic_load_explicit(&p->notify_out,
10197 memory_order_relaxed));
d62a17ae 10198 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10199 atomic_load_explicit(&p->notify_in,
10200 memory_order_relaxed));
10201 json_object_int_add(json_stat, "updatesSent",
10202 atomic_load_explicit(&p->update_out,
10203 memory_order_relaxed));
10204 json_object_int_add(json_stat, "updatesRecv",
10205 atomic_load_explicit(&p->update_in,
10206 memory_order_relaxed));
d62a17ae 10207 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10208 atomic_load_explicit(&p->keepalive_out,
10209 memory_order_relaxed));
d62a17ae 10210 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10211 atomic_load_explicit(&p->keepalive_in,
10212 memory_order_relaxed));
d62a17ae 10213 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10214 atomic_load_explicit(&p->refresh_out,
10215 memory_order_relaxed));
d62a17ae 10216 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10217 atomic_load_explicit(&p->refresh_in,
10218 memory_order_relaxed));
d62a17ae 10219 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10220 atomic_load_explicit(&p->dynamic_cap_out,
10221 memory_order_relaxed));
d62a17ae 10222 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10223 atomic_load_explicit(&p->dynamic_cap_in,
10224 memory_order_relaxed));
10225 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10226 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10227 json_object_object_add(json_neigh, "messageStats", json_stat);
10228 } else {
10229 /* Packet counts. */
10230 vty_out(vty, " Message statistics:\n");
10231 vty_out(vty, " Inq depth is 0\n");
10232 vty_out(vty, " Outq depth is %lu\n",
10233 (unsigned long)p->obuf->count);
10234 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10235 vty_out(vty, " Opens: %10d %10d\n",
10236 atomic_load_explicit(&p->open_out,
10237 memory_order_relaxed),
10238 atomic_load_explicit(&p->open_in,
10239 memory_order_relaxed));
10240 vty_out(vty, " Notifications: %10d %10d\n",
10241 atomic_load_explicit(&p->notify_out,
10242 memory_order_relaxed),
10243 atomic_load_explicit(&p->notify_in,
10244 memory_order_relaxed));
10245 vty_out(vty, " Updates: %10d %10d\n",
10246 atomic_load_explicit(&p->update_out,
10247 memory_order_relaxed),
10248 atomic_load_explicit(&p->update_in,
10249 memory_order_relaxed));
10250 vty_out(vty, " Keepalives: %10d %10d\n",
10251 atomic_load_explicit(&p->keepalive_out,
10252 memory_order_relaxed),
10253 atomic_load_explicit(&p->keepalive_in,
10254 memory_order_relaxed));
10255 vty_out(vty, " Route Refresh: %10d %10d\n",
10256 atomic_load_explicit(&p->refresh_out,
10257 memory_order_relaxed),
10258 atomic_load_explicit(&p->refresh_in,
10259 memory_order_relaxed));
d62a17ae 10260 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10261 atomic_load_explicit(&p->dynamic_cap_out,
10262 memory_order_relaxed),
10263 atomic_load_explicit(&p->dynamic_cap_in,
10264 memory_order_relaxed));
10265 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10266 PEER_TOTAL_RX(p));
d62a17ae 10267 }
10268
10269 if (use_json) {
10270 /* advertisement-interval */
10271 json_object_int_add(json_neigh,
10272 "minBtwnAdvertisementRunsTimerMsecs",
10273 p->v_routeadv * 1000);
10274
10275 /* Update-source. */
10276 if (p->update_if || p->update_source) {
10277 if (p->update_if)
10278 json_object_string_add(json_neigh,
10279 "updateSource",
10280 p->update_if);
10281 else if (p->update_source)
10282 json_object_string_add(
10283 json_neigh, "updateSource",
10284 sockunion2str(p->update_source, buf1,
10285 SU_ADDRSTRLEN));
10286 }
10287 } else {
10288 /* advertisement-interval */
10289 vty_out(vty,
10290 " Minimum time between advertisement runs is %d seconds\n",
10291 p->v_routeadv);
10292
10293 /* Update-source. */
10294 if (p->update_if || p->update_source) {
10295 vty_out(vty, " Update source is ");
10296 if (p->update_if)
10297 vty_out(vty, "%s", p->update_if);
10298 else if (p->update_source)
10299 vty_out(vty, "%s",
10300 sockunion2str(p->update_source, buf1,
10301 SU_ADDRSTRLEN));
10302 vty_out(vty, "\n");
10303 }
10304
10305 vty_out(vty, "\n");
10306 }
10307
10308 /* Address Family Information */
10309 json_object *json_hold = NULL;
10310
10311 if (use_json)
10312 json_hold = json_object_new_object();
10313
05c7a1cc
QY
10314 FOREACH_AFI_SAFI (afi, safi)
10315 if (p->afc[afi][safi])
10316 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10317 json_hold);
d62a17ae 10318
10319 if (use_json) {
10320 json_object_object_add(json_neigh, "addressFamilyInfo",
10321 json_hold);
10322 json_object_int_add(json_neigh, "connectionsEstablished",
10323 p->established);
10324 json_object_int_add(json_neigh, "connectionsDropped",
10325 p->dropped);
10326 } else
10327 vty_out(vty, " Connections established %d; dropped %d\n",
10328 p->established, p->dropped);
10329
10330 if (!p->last_reset) {
10331 if (use_json)
10332 json_object_string_add(json_neigh, "lastReset",
10333 "never");
10334 else
10335 vty_out(vty, " Last reset never\n");
10336 } else {
10337 if (use_json) {
10338 time_t uptime;
10339 struct tm *tm;
10340
10341 uptime = bgp_clock();
10342 uptime -= p->resettime;
10343 tm = gmtime(&uptime);
10344 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10345 (tm->tm_sec * 1000)
10346 + (tm->tm_min * 60000)
10347 + (tm->tm_hour * 3600000));
10348 json_object_string_add(
10349 json_neigh, "lastResetDueTo",
10350 peer_down_str[(int)p->last_reset]);
10351 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10352 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10353 char errorcodesubcode_hexstr[5];
10354 char errorcodesubcode_str[256];
10355
10356 code_str = bgp_notify_code_str(p->notify.code);
10357 subcode_str = bgp_notify_subcode_str(
10358 p->notify.code, p->notify.subcode);
10359
10360 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10361 p->notify.code, p->notify.subcode);
10362 json_object_string_add(json_neigh,
10363 "lastErrorCodeSubcode",
10364 errorcodesubcode_hexstr);
10365 snprintf(errorcodesubcode_str, 255, "%s%s",
10366 code_str, subcode_str);
10367 json_object_string_add(json_neigh,
10368 "lastNotificationReason",
10369 errorcodesubcode_str);
10370 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10371 && p->notify.code == BGP_NOTIFY_CEASE
10372 && (p->notify.subcode
10373 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10374 || p->notify.subcode
10375 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10376 && p->notify.length) {
10377 char msgbuf[1024];
10378 const char *msg_str;
10379
10380 msg_str = bgp_notify_admin_message(
10381 msgbuf, sizeof(msgbuf),
d7c0a89a 10382 (uint8_t *)p->notify.data,
d62a17ae 10383 p->notify.length);
10384 if (msg_str)
10385 json_object_string_add(
10386 json_neigh,
10387 "lastShutdownDescription",
10388 msg_str);
10389 }
10390 }
10391 } else {
10392 vty_out(vty, " Last reset %s, ",
10393 peer_uptime(p->resettime, timebuf,
10394 BGP_UPTIME_LEN, 0, NULL));
10395
10396 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10397 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10398 code_str = bgp_notify_code_str(p->notify.code);
10399 subcode_str = bgp_notify_subcode_str(
10400 p->notify.code, p->notify.subcode);
10401 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10402 p->last_reset == PEER_DOWN_NOTIFY_SEND
10403 ? "sent"
10404 : "received",
10405 code_str, subcode_str);
10406 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10407 && p->notify.code == BGP_NOTIFY_CEASE
10408 && (p->notify.subcode
10409 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10410 || p->notify.subcode
10411 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10412 && p->notify.length) {
10413 char msgbuf[1024];
10414 const char *msg_str;
10415
10416 msg_str = bgp_notify_admin_message(
10417 msgbuf, sizeof(msgbuf),
d7c0a89a 10418 (uint8_t *)p->notify.data,
d62a17ae 10419 p->notify.length);
10420 if (msg_str)
10421 vty_out(vty,
10422 " Message: \"%s\"\n",
10423 msg_str);
10424 }
10425 } else {
10426 vty_out(vty, "due to %s\n",
10427 peer_down_str[(int)p->last_reset]);
10428 }
10429
10430 if (p->last_reset_cause_size) {
10431 msg = p->last_reset_cause;
10432 vty_out(vty,
10433 " Message received that caused BGP to send a NOTIFICATION:\n ");
10434 for (i = 1; i <= p->last_reset_cause_size;
10435 i++) {
10436 vty_out(vty, "%02X", *msg++);
10437
10438 if (i != p->last_reset_cause_size) {
10439 if (i % 16 == 0) {
10440 vty_out(vty, "\n ");
10441 } else if (i % 4 == 0) {
10442 vty_out(vty, " ");
10443 }
10444 }
10445 }
10446 vty_out(vty, "\n");
10447 }
10448 }
10449 }
10450
10451 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10452 if (use_json)
10453 json_object_boolean_true_add(json_neigh,
10454 "prefixesConfigExceedMax");
10455 else
10456 vty_out(vty,
10457 " Peer had exceeded the max. no. of prefixes configured.\n");
10458
10459 if (p->t_pmax_restart) {
10460 if (use_json) {
10461 json_object_boolean_true_add(
10462 json_neigh, "reducePrefixNumFrom");
10463 json_object_int_add(json_neigh,
10464 "restartInTimerMsec",
10465 thread_timer_remain_second(
10466 p->t_pmax_restart)
10467 * 1000);
10468 } else
10469 vty_out(vty,
10470 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10471 p->host, thread_timer_remain_second(
10472 p->t_pmax_restart));
d62a17ae 10473 } else {
10474 if (use_json)
10475 json_object_boolean_true_add(
10476 json_neigh,
10477 "reducePrefixNumAndClearIpBgp");
10478 else
10479 vty_out(vty,
10480 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10481 p->host);
10482 }
10483 }
10484
10485 /* EBGP Multihop and GTSM */
10486 if (p->sort != BGP_PEER_IBGP) {
10487 if (use_json) {
10488 if (p->gtsm_hops > 0)
10489 json_object_int_add(json_neigh,
10490 "externalBgpNbrMaxHopsAway",
10491 p->gtsm_hops);
10492 else if (p->ttl > 1)
10493 json_object_int_add(json_neigh,
10494 "externalBgpNbrMaxHopsAway",
10495 p->ttl);
10496 } else {
10497 if (p->gtsm_hops > 0)
10498 vty_out(vty,
10499 " External BGP neighbor may be up to %d hops away.\n",
10500 p->gtsm_hops);
10501 else if (p->ttl > 1)
10502 vty_out(vty,
10503 " External BGP neighbor may be up to %d hops away.\n",
10504 p->ttl);
10505 }
10506 } else {
10507 if (p->gtsm_hops > 0) {
10508 if (use_json)
10509 json_object_int_add(json_neigh,
10510 "internalBgpNbrMaxHopsAway",
10511 p->gtsm_hops);
10512 else
10513 vty_out(vty,
10514 " Internal BGP neighbor may be up to %d hops away.\n",
10515 p->gtsm_hops);
10516 }
10517 }
10518
10519 /* Local address. */
10520 if (p->su_local) {
10521 if (use_json) {
10522 json_object_string_add(json_neigh, "hostLocal",
10523 sockunion2str(p->su_local, buf1,
10524 SU_ADDRSTRLEN));
10525 json_object_int_add(json_neigh, "portLocal",
10526 ntohs(p->su_local->sin.sin_port));
10527 } else
10528 vty_out(vty, "Local host: %s, Local port: %d\n",
10529 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10530 ntohs(p->su_local->sin.sin_port));
10531 }
10532
10533 /* Remote address. */
10534 if (p->su_remote) {
10535 if (use_json) {
10536 json_object_string_add(json_neigh, "hostForeign",
10537 sockunion2str(p->su_remote, buf1,
10538 SU_ADDRSTRLEN));
10539 json_object_int_add(json_neigh, "portForeign",
10540 ntohs(p->su_remote->sin.sin_port));
10541 } else
10542 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10543 sockunion2str(p->su_remote, buf1,
10544 SU_ADDRSTRLEN),
10545 ntohs(p->su_remote->sin.sin_port));
10546 }
10547
10548 /* Nexthop display. */
10549 if (p->su_local) {
10550 if (use_json) {
10551 json_object_string_add(json_neigh, "nexthop",
10552 inet_ntop(AF_INET,
10553 &p->nexthop.v4, buf1,
10554 sizeof(buf1)));
10555 json_object_string_add(json_neigh, "nexthopGlobal",
10556 inet_ntop(AF_INET6,
10557 &p->nexthop.v6_global,
10558 buf1, sizeof(buf1)));
10559 json_object_string_add(json_neigh, "nexthopLocal",
10560 inet_ntop(AF_INET6,
10561 &p->nexthop.v6_local,
10562 buf1, sizeof(buf1)));
10563 if (p->shared_network)
10564 json_object_string_add(json_neigh,
10565 "bgpConnection",
10566 "sharedNetwork");
10567 else
10568 json_object_string_add(json_neigh,
10569 "bgpConnection",
10570 "nonSharedNetwork");
10571 } else {
10572 vty_out(vty, "Nexthop: %s\n",
10573 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10574 sizeof(buf1)));
10575 vty_out(vty, "Nexthop global: %s\n",
10576 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10577 sizeof(buf1)));
10578 vty_out(vty, "Nexthop local: %s\n",
10579 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10580 sizeof(buf1)));
10581 vty_out(vty, "BGP connection: %s\n",
10582 p->shared_network ? "shared network"
10583 : "non shared network");
10584 }
10585 }
10586
10587 /* Timer information. */
10588 if (use_json) {
10589 json_object_int_add(json_neigh, "connectRetryTimer",
10590 p->v_connect);
10591 if (p->status == Established && p->rtt)
10592 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10593 p->rtt);
10594 if (p->t_start)
10595 json_object_int_add(
10596 json_neigh, "nextStartTimerDueInMsecs",
10597 thread_timer_remain_second(p->t_start) * 1000);
10598 if (p->t_connect)
10599 json_object_int_add(
10600 json_neigh, "nextConnectTimerDueInMsecs",
10601 thread_timer_remain_second(p->t_connect)
10602 * 1000);
10603 if (p->t_routeadv) {
10604 json_object_int_add(json_neigh, "mraiInterval",
10605 p->v_routeadv);
10606 json_object_int_add(
10607 json_neigh, "mraiTimerExpireInMsecs",
10608 thread_timer_remain_second(p->t_routeadv)
10609 * 1000);
10610 }
10611 if (p->password)
10612 json_object_int_add(json_neigh, "authenticationEnabled",
10613 1);
10614
10615 if (p->t_read)
10616 json_object_string_add(json_neigh, "readThread", "on");
10617 else
10618 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10619
10620 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10621 json_object_string_add(json_neigh, "writeThread", "on");
10622 else
10623 json_object_string_add(json_neigh, "writeThread",
10624 "off");
10625 } else {
10626 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10627 p->v_connect);
10628 if (p->status == Established && p->rtt)
10629 vty_out(vty, "Estimated round trip time: %d ms\n",
10630 p->rtt);
10631 if (p->t_start)
10632 vty_out(vty, "Next start timer due in %ld seconds\n",
10633 thread_timer_remain_second(p->t_start));
10634 if (p->t_connect)
10635 vty_out(vty, "Next connect timer due in %ld seconds\n",
10636 thread_timer_remain_second(p->t_connect));
10637 if (p->t_routeadv)
10638 vty_out(vty,
10639 "MRAI (interval %u) timer expires in %ld seconds\n",
10640 p->v_routeadv,
10641 thread_timer_remain_second(p->t_routeadv));
10642 if (p->password)
10643 vty_out(vty, "Peer Authentication Enabled\n");
10644
10645 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10646 p->t_read ? "on" : "off",
10647 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10648 ? "on"
10649 : "off");
d62a17ae 10650 }
10651
10652 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10653 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10654 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10655
10656 if (!use_json)
10657 vty_out(vty, "\n");
10658
10659 /* BFD information. */
10660 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10661
10662 if (use_json) {
10663 if (p->conf_if) /* Configured interface name. */
10664 json_object_object_add(json, p->conf_if, json_neigh);
10665 else /* Configured IP address. */
10666 json_object_object_add(json, p->host, json_neigh);
10667 }
10668}
10669
10670static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10671 enum show_type type, union sockunion *su,
d7c0a89a 10672 const char *conf_if, uint8_t use_json,
d62a17ae 10673 json_object *json)
10674{
10675 struct listnode *node, *nnode;
10676 struct peer *peer;
10677 int find = 0;
10678
10679 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10680 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10681 continue;
10682
10683 switch (type) {
10684 case show_all:
10685 bgp_show_peer(vty, peer, use_json, json);
10686 break;
10687 case show_peer:
10688 if (conf_if) {
10689 if ((peer->conf_if
10690 && !strcmp(peer->conf_if, conf_if))
10691 || (peer->hostname
10692 && !strcmp(peer->hostname, conf_if))) {
10693 find = 1;
10694 bgp_show_peer(vty, peer, use_json,
10695 json);
10696 }
10697 } else {
10698 if (sockunion_same(&peer->su, su)) {
10699 find = 1;
10700 bgp_show_peer(vty, peer, use_json,
10701 json);
10702 }
10703 }
10704 break;
10705 }
10706 }
10707
10708 if (type == show_peer && !find) {
10709 if (use_json)
10710 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10711 else
88b7d255 10712 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 10713 }
10714
10715 if (use_json) {
996c9314
LB
10716 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10717 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10718 json_object_free(json);
10719 } else {
10720 vty_out(vty, "\n");
10721 }
10722
10723 return CMD_SUCCESS;
10724}
10725
10726static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10727 enum show_type type,
10728 const char *ip_str,
d7c0a89a 10729 uint8_t use_json)
d62a17ae 10730{
0291c246
MK
10731 struct listnode *node, *nnode;
10732 struct bgp *bgp;
71aedaa3 10733 union sockunion su;
0291c246 10734 json_object *json = NULL;
71aedaa3 10735 int ret, is_first = 1;
d62a17ae 10736
10737 if (use_json)
10738 vty_out(vty, "{\n");
10739
10740 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10741 if (use_json) {
10742 if (!(json = json_object_new_object())) {
10743 zlog_err(
10744 "Unable to allocate memory for JSON object");
10745 vty_out(vty,
10746 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10747 return;
10748 }
10749
10750 json_object_int_add(json, "vrfId",
10751 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10752 ? -1
10753 : (int64_t)bgp->vrf_id);
d62a17ae 10754 json_object_string_add(
10755 json, "vrfName",
10756 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10757 ? "Default"
10758 : bgp->name);
10759
10760 if (!is_first)
10761 vty_out(vty, ",\n");
10762 else
10763 is_first = 0;
10764
10765 vty_out(vty, "\"%s\":",
10766 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10767 ? "Default"
10768 : bgp->name);
10769 } else {
10770 vty_out(vty, "\nInstance %s:\n",
10771 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10772 ? "Default"
10773 : bgp->name);
10774 }
71aedaa3
DS
10775
10776 if (type == show_peer) {
10777 ret = str2sockunion(ip_str, &su);
10778 if (ret < 0)
10779 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10780 use_json, json);
10781 else
10782 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10783 use_json, json);
10784 } else {
10785 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10786 use_json, json);
10787 }
d62a17ae 10788 }
10789
10790 if (use_json)
10791 vty_out(vty, "}\n");
10792}
10793
10794static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10795 enum show_type type, const char *ip_str,
d7c0a89a 10796 uint8_t use_json)
d62a17ae 10797{
10798 int ret;
10799 struct bgp *bgp;
10800 union sockunion su;
10801 json_object *json = NULL;
10802
10803 if (name) {
10804 if (strmatch(name, "all")) {
71aedaa3
DS
10805 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10806 use_json);
d62a17ae 10807 return CMD_SUCCESS;
10808 } else {
10809 bgp = bgp_lookup_by_name(name);
10810 if (!bgp) {
10811 if (use_json) {
10812 json = json_object_new_object();
10813 json_object_boolean_true_add(
10814 json, "bgpNoSuchInstance");
10815 vty_out(vty, "%s\n",
10816 json_object_to_json_string_ext(
10817 json,
10818 JSON_C_TO_STRING_PRETTY));
10819 json_object_free(json);
10820 } else
10821 vty_out(vty,
10822 "%% No such BGP instance exist\n");
10823
10824 return CMD_WARNING;
10825 }
10826 }
10827 } else {
10828 bgp = bgp_get_default();
10829 }
10830
10831 if (bgp) {
10832 json = json_object_new_object();
10833 if (ip_str) {
10834 ret = str2sockunion(ip_str, &su);
10835 if (ret < 0)
10836 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10837 use_json, json);
10838 else
10839 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10840 use_json, json);
10841 } else {
10842 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10843 json);
10844 }
10845 json_object_free(json);
10846 }
10847
10848 return CMD_SUCCESS;
4fb25c53
DW
10849}
10850
716b2d8a 10851/* "show [ip] bgp neighbors" commands. */
718e3744 10852DEFUN (show_ip_bgp_neighbors,
10853 show_ip_bgp_neighbors_cmd,
24345e82 10854 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 10855 SHOW_STR
10856 IP_STR
10857 BGP_STR
f2a8972b 10858 BGP_INSTANCE_HELP_STR
8c3deaae
QY
10859 "Address Family\n"
10860 "Address Family\n"
718e3744 10861 "Detailed information on TCP and BGP neighbor connections\n"
10862 "Neighbor to display information about\n"
a80beece 10863 "Neighbor to display information about\n"
91d37724 10864 "Neighbor on BGP configured interface\n"
9973d184 10865 JSON_STR)
718e3744 10866{
d62a17ae 10867 char *vrf = NULL;
10868 char *sh_arg = NULL;
10869 enum show_type sh_type;
718e3744 10870
d7c0a89a 10871 uint8_t uj = use_json(argc, argv);
718e3744 10872
d62a17ae 10873 int idx = 0;
718e3744 10874
d62a17ae 10875 if (argv_find(argv, argc, "view", &idx)
10876 || argv_find(argv, argc, "vrf", &idx))
10877 vrf = argv[idx + 1]->arg;
718e3744 10878
d62a17ae 10879 idx++;
10880 if (argv_find(argv, argc, "A.B.C.D", &idx)
10881 || argv_find(argv, argc, "X:X::X:X", &idx)
10882 || argv_find(argv, argc, "WORD", &idx)) {
10883 sh_type = show_peer;
10884 sh_arg = argv[idx]->arg;
10885 } else
10886 sh_type = show_all;
856ca177 10887
d62a17ae 10888 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10889}
10890
716b2d8a 10891/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10892 paths' and `show ip mbgp paths'. Those functions results are the
10893 same.*/
f412b39a 10894DEFUN (show_ip_bgp_paths,
718e3744 10895 show_ip_bgp_paths_cmd,
46f296b4 10896 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10897 SHOW_STR
10898 IP_STR
10899 BGP_STR
46f296b4 10900 BGP_SAFI_HELP_STR
718e3744 10901 "Path information\n")
10902{
d62a17ae 10903 vty_out(vty, "Address Refcnt Path\n");
10904 aspath_print_all_vty(vty);
10905 return CMD_SUCCESS;
718e3744 10906}
10907
718e3744 10908#include "hash.h"
10909
d62a17ae 10910static void community_show_all_iterator(struct hash_backet *backet,
10911 struct vty *vty)
718e3744 10912{
d62a17ae 10913 struct community *com;
718e3744 10914
d62a17ae 10915 com = (struct community *)backet->data;
3f65c5b1 10916 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 10917 community_str(com, false));
718e3744 10918}
10919
10920/* Show BGP's community internal data. */
f412b39a 10921DEFUN (show_ip_bgp_community_info,
718e3744 10922 show_ip_bgp_community_info_cmd,
bec37ba5 10923 "show [ip] bgp community-info",
718e3744 10924 SHOW_STR
10925 IP_STR
10926 BGP_STR
10927 "List all bgp community information\n")
10928{
d62a17ae 10929 vty_out(vty, "Address Refcnt Community\n");
718e3744 10930
d62a17ae 10931 hash_iterate(community_hash(),
10932 (void (*)(struct hash_backet *,
10933 void *))community_show_all_iterator,
10934 vty);
718e3744 10935
d62a17ae 10936 return CMD_SUCCESS;
718e3744 10937}
10938
d62a17ae 10939static void lcommunity_show_all_iterator(struct hash_backet *backet,
10940 struct vty *vty)
57d187bc 10941{
d62a17ae 10942 struct lcommunity *lcom;
57d187bc 10943
d62a17ae 10944 lcom = (struct lcommunity *)backet->data;
3f65c5b1 10945 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 10946 lcommunity_str(lcom, false));
57d187bc
JS
10947}
10948
10949/* Show BGP's community internal data. */
10950DEFUN (show_ip_bgp_lcommunity_info,
10951 show_ip_bgp_lcommunity_info_cmd,
10952 "show ip bgp large-community-info",
10953 SHOW_STR
10954 IP_STR
10955 BGP_STR
10956 "List all bgp large-community information\n")
10957{
d62a17ae 10958 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 10959
d62a17ae 10960 hash_iterate(lcommunity_hash(),
10961 (void (*)(struct hash_backet *,
10962 void *))lcommunity_show_all_iterator,
10963 vty);
57d187bc 10964
d62a17ae 10965 return CMD_SUCCESS;
57d187bc
JS
10966}
10967
10968
f412b39a 10969DEFUN (show_ip_bgp_attr_info,
718e3744 10970 show_ip_bgp_attr_info_cmd,
bec37ba5 10971 "show [ip] bgp attribute-info",
718e3744 10972 SHOW_STR
10973 IP_STR
10974 BGP_STR
10975 "List all bgp attribute information\n")
10976{
d62a17ae 10977 attr_show_all(vty);
10978 return CMD_SUCCESS;
718e3744 10979}
6b0655a2 10980
53089bec 10981static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10982 afi_t afi, safi_t safi)
10983{
10984 struct bgp *bgp;
10985 struct listnode *node;
10986 char *vname;
10987 char buf1[INET6_ADDRSTRLEN];
10988 char *ecom_str;
10989 vpn_policy_direction_t dir;
10990
10991 if (name) {
10992 bgp = bgp_lookup_by_name(name);
10993 if (!bgp) {
10994 vty_out(vty, "%% No such BGP instance exist\n");
10995 return CMD_WARNING;
10996 }
10997 } else {
10998 bgp = bgp_get_default();
10999 if (!bgp) {
020a3f60
DS
11000 vty_out(vty,
11001 "%% Default BGP instance does not exist\n");
53089bec 11002 return CMD_WARNING;
11003 }
11004 }
11005
11006 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11007 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
020a3f60
DS
11008 vty_out(vty,
11009 "This VRF is not importing %s routes from any other VRF\n",
53089bec 11010 afi_safi_print(afi, safi));
11011 } else {
020a3f60
DS
11012 vty_out(vty,
11013 "This VRF is importing %s routes from the following VRFs:\n",
53089bec 11014 afi_safi_print(afi, safi));
11015 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
11016 vname)) {
11017 vty_out(vty, " %s\n", vname);
11018 }
11019 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11020 ecom_str = ecommunity_ecom2str(
11021 bgp->vpn_policy[afi].rtlist[dir],
11022 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11023 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11024 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11025 }
11026
11027 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11028 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
020a3f60
DS
11029 vty_out(vty,
11030 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11031 afi_safi_print(afi, safi));
11032 } else {
020a3f60
DS
11033 vty_out(vty,
11034 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11035 afi_safi_print(afi, safi));
11036 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
11037 vname)) {
11038 vty_out(vty, " %s\n", vname);
11039 }
11040 vty_out(vty, "RD: %s\n",
11041 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11042 buf1, RD_ADDRSTRLEN));
11043 dir = BGP_VPN_POLICY_DIR_TOVPN;
11044 ecom_str = ecommunity_ecom2str(
11045 bgp->vpn_policy[afi].rtlist[dir],
11046 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11047 vty_out(vty, "Emport RT: %s\n", ecom_str);
11048 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11049 }
11050
11051 return CMD_SUCCESS;
11052}
11053
11054/* "show [ip] bgp route-leak" command. */
11055DEFUN (show_ip_bgp_route_leak,
11056 show_ip_bgp_route_leak_cmd,
11057 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
11058 SHOW_STR
11059 IP_STR
11060 BGP_STR
11061 BGP_INSTANCE_HELP_STR
11062 BGP_AFI_HELP_STR
11063 BGP_SAFI_HELP_STR
11064 "Route leaking information\n")
11065{
11066 char *vrf = NULL;
11067 afi_t afi = AFI_MAX;
11068 safi_t safi = SAFI_MAX;
11069
11070 int idx = 0;
11071
11072 /* show [ip] bgp */
11073 if (argv_find(argv, argc, "ip", &idx)) {
11074 afi = AFI_IP;
11075 safi = SAFI_UNICAST;
11076 }
11077 /* [vrf VIEWVRFNAME] */
11078 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11079 vty_out(vty,
11080 "%% This command is not applicable to BGP views\n");
53089bec 11081 return CMD_WARNING;
11082 }
11083
11084 if (argv_find(argv, argc, "vrf", &idx))
11085 vrf = argv[++idx]->arg;
11086 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11087 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11088 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11089 }
11090
11091 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11092 vty_out(vty,
11093 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11094 return CMD_WARNING;
11095 }
11096
11097 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11098}
11099
d62a17ae 11100static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11101 safi_t safi)
f186de26 11102{
d62a17ae 11103 struct listnode *node, *nnode;
11104 struct bgp *bgp;
f186de26 11105
d62a17ae 11106 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11107 vty_out(vty, "\nInstance %s:\n",
11108 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11109 ? "Default"
11110 : bgp->name);
11111 update_group_show(bgp, afi, safi, vty, 0);
11112 }
f186de26 11113}
11114
d62a17ae 11115static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11116 int safi, uint64_t subgrp_id)
4fb25c53 11117{
d62a17ae 11118 struct bgp *bgp;
4fb25c53 11119
d62a17ae 11120 if (name) {
11121 if (strmatch(name, "all")) {
11122 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11123 return CMD_SUCCESS;
11124 } else {
11125 bgp = bgp_lookup_by_name(name);
11126 }
11127 } else {
11128 bgp = bgp_get_default();
11129 }
4fb25c53 11130
d62a17ae 11131 if (bgp)
11132 update_group_show(bgp, afi, safi, vty, subgrp_id);
11133 return CMD_SUCCESS;
4fb25c53
DW
11134}
11135
8fe8a7f6
DS
11136DEFUN (show_ip_bgp_updgrps,
11137 show_ip_bgp_updgrps_cmd,
c1a44e43 11138 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11139 SHOW_STR
11140 IP_STR
11141 BGP_STR
11142 BGP_INSTANCE_HELP_STR
c9e571b4 11143 BGP_AFI_HELP_STR
9bedbb1e 11144 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11145 "Detailed info about dynamic update groups\n"
11146 "Specific subgroup to display detailed info for\n")
8386ac43 11147{
d62a17ae 11148 char *vrf = NULL;
11149 afi_t afi = AFI_IP6;
11150 safi_t safi = SAFI_UNICAST;
11151 uint64_t subgrp_id = 0;
11152
11153 int idx = 0;
11154
11155 /* show [ip] bgp */
11156 if (argv_find(argv, argc, "ip", &idx))
11157 afi = AFI_IP;
11158 /* [<view|vrf> VIEWVRFNAME] */
11159 if (argv_find(argv, argc, "view", &idx)
11160 || argv_find(argv, argc, "vrf", &idx))
11161 vrf = argv[++idx]->arg;
11162 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11163 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11164 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11165 }
5bf15956 11166
d62a17ae 11167 /* get subgroup id, if provided */
11168 idx = argc - 1;
11169 if (argv[idx]->type == VARIABLE_TKN)
11170 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11171
d62a17ae 11172 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11173}
11174
f186de26 11175DEFUN (show_bgp_instance_all_ipv6_updgrps,
11176 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11177 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11178 SHOW_STR
716b2d8a 11179 IP_STR
f186de26 11180 BGP_STR
11181 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11182 "Detailed info about dynamic update groups\n")
f186de26 11183{
d62a17ae 11184 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11185 return CMD_SUCCESS;
f186de26 11186}
11187
5bf15956
DW
11188DEFUN (show_bgp_updgrps_stats,
11189 show_bgp_updgrps_stats_cmd,
716b2d8a 11190 "show [ip] bgp update-groups statistics",
3f9c7369 11191 SHOW_STR
716b2d8a 11192 IP_STR
3f9c7369 11193 BGP_STR
0c7b1b01 11194 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11195 "Statistics\n")
11196{
d62a17ae 11197 struct bgp *bgp;
3f9c7369 11198
d62a17ae 11199 bgp = bgp_get_default();
11200 if (bgp)
11201 update_group_show_stats(bgp, vty);
3f9c7369 11202
d62a17ae 11203 return CMD_SUCCESS;
3f9c7369
DS
11204}
11205
8386ac43 11206DEFUN (show_bgp_instance_updgrps_stats,
11207 show_bgp_instance_updgrps_stats_cmd,
18c57037 11208 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11209 SHOW_STR
716b2d8a 11210 IP_STR
8386ac43 11211 BGP_STR
11212 BGP_INSTANCE_HELP_STR
0c7b1b01 11213 "Detailed info about dynamic update groups\n"
8386ac43 11214 "Statistics\n")
11215{
d62a17ae 11216 int idx_word = 3;
11217 struct bgp *bgp;
8386ac43 11218
d62a17ae 11219 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11220 if (bgp)
11221 update_group_show_stats(bgp, vty);
8386ac43 11222
d62a17ae 11223 return CMD_SUCCESS;
8386ac43 11224}
11225
d62a17ae 11226static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11227 afi_t afi, safi_t safi,
11228 const char *what, uint64_t subgrp_id)
3f9c7369 11229{
d62a17ae 11230 struct bgp *bgp;
8386ac43 11231
d62a17ae 11232 if (name)
11233 bgp = bgp_lookup_by_name(name);
11234 else
11235 bgp = bgp_get_default();
8386ac43 11236
d62a17ae 11237 if (bgp) {
11238 if (!strcmp(what, "advertise-queue"))
11239 update_group_show_adj_queue(bgp, afi, safi, vty,
11240 subgrp_id);
11241 else if (!strcmp(what, "advertised-routes"))
11242 update_group_show_advertised(bgp, afi, safi, vty,
11243 subgrp_id);
11244 else if (!strcmp(what, "packet-queue"))
11245 update_group_show_packet_queue(bgp, afi, safi, vty,
11246 subgrp_id);
11247 }
3f9c7369
DS
11248}
11249
dc64bdec
QY
11250DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11251 show_ip_bgp_instance_updgrps_adj_s_cmd,
11252 "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",
11253 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11254 BGP_SAFI_HELP_STR
11255 "Detailed info about dynamic update groups\n"
11256 "Specific subgroup to display info for\n"
11257 "Advertisement queue\n"
11258 "Announced routes\n"
11259 "Packet queue\n")
3f9c7369 11260{
dc64bdec
QY
11261 uint64_t subgrp_id = 0;
11262 afi_t afiz;
11263 safi_t safiz;
11264 if (sgid)
11265 subgrp_id = strtoull(sgid, NULL, 10);
11266
11267 if (!ip && !afi)
11268 afiz = AFI_IP6;
11269 if (!ip && afi)
11270 afiz = bgp_vty_afi_from_str(afi);
11271 if (ip && !afi)
11272 afiz = AFI_IP;
11273 if (ip && afi) {
11274 afiz = bgp_vty_afi_from_str(afi);
11275 if (afiz != AFI_IP)
11276 vty_out(vty,
11277 "%% Cannot specify both 'ip' and 'ipv6'\n");
11278 return CMD_WARNING;
11279 }
d62a17ae 11280
dc64bdec 11281 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11282
dc64bdec 11283 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11284 return CMD_SUCCESS;
11285}
11286
d62a17ae 11287static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11288{
11289 struct listnode *node, *nnode;
11290 struct prefix *range;
11291 struct peer *conf;
11292 struct peer *peer;
11293 char buf[PREFIX2STR_BUFFER];
11294 afi_t afi;
11295 safi_t safi;
11296 const char *peer_status;
11297 const char *af_str;
11298 int lr_count;
11299 int dynamic;
11300 int af_cfgd;
11301
11302 conf = group->conf;
11303
11304 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11305 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11306 conf->as);
11307 } else if (conf->as_type == AS_INTERNAL) {
11308 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11309 group->bgp->as);
11310 } else {
11311 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11312 }
f14e6fdb 11313
d62a17ae 11314 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11315 vty_out(vty, " Peer-group type is internal\n");
11316 else
11317 vty_out(vty, " Peer-group type is external\n");
11318
11319 /* Display AFs configured. */
11320 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11321 FOREACH_AFI_SAFI (afi, safi) {
11322 if (conf->afc[afi][safi]) {
11323 af_cfgd = 1;
11324 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11325 }
05c7a1cc 11326 }
d62a17ae 11327 if (!af_cfgd)
11328 vty_out(vty, " none\n");
11329 else
11330 vty_out(vty, "\n");
11331
11332 /* Display listen ranges (for dynamic neighbors), if any */
11333 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11334 if (afi == AFI_IP)
11335 af_str = "IPv4";
11336 else if (afi == AFI_IP6)
11337 af_str = "IPv6";
11338 else
11339 af_str = "???";
11340 lr_count = listcount(group->listen_range[afi]);
11341 if (lr_count) {
11342 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11343 af_str);
11344
11345
11346 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11347 nnode, range)) {
11348 prefix2str(range, buf, sizeof(buf));
11349 vty_out(vty, " %s\n", buf);
11350 }
11351 }
11352 }
f14e6fdb 11353
d62a17ae 11354 /* Display group members and their status */
11355 if (listcount(group->peer)) {
11356 vty_out(vty, " Peer-group members:\n");
11357 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11358 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11359 peer_status = "Idle (Admin)";
11360 else if (CHECK_FLAG(peer->sflags,
11361 PEER_STATUS_PREFIX_OVERFLOW))
11362 peer_status = "Idle (PfxCt)";
11363 else
11364 peer_status = lookup_msg(bgp_status_msg,
11365 peer->status, NULL);
11366
11367 dynamic = peer_dynamic_neighbor(peer);
11368 vty_out(vty, " %s %s %s \n", peer->host,
11369 dynamic ? "(dynamic)" : "", peer_status);
11370 }
11371 }
f14e6fdb 11372
d62a17ae 11373 return CMD_SUCCESS;
11374}
11375
ff9959b0
QY
11376static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11377 const char *group_name)
d62a17ae 11378{
ff9959b0 11379 struct bgp *bgp;
d62a17ae 11380 struct listnode *node, *nnode;
11381 struct peer_group *group;
ff9959b0
QY
11382 bool found = false;
11383
11384 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11385
11386 if (!bgp) {
11387 vty_out(vty, "%% No such BGP instance exists\n");
11388 return CMD_WARNING;
11389 }
d62a17ae 11390
11391 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11392 if (group_name) {
11393 if (strmatch(group->name, group_name)) {
d62a17ae 11394 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11395 found = true;
11396 break;
d62a17ae 11397 }
ff9959b0
QY
11398 } else {
11399 bgp_show_one_peer_group(vty, group);
d62a17ae 11400 }
f14e6fdb 11401 }
f14e6fdb 11402
ff9959b0 11403 if (group_name && !found)
d62a17ae 11404 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11405
d62a17ae 11406 return CMD_SUCCESS;
f14e6fdb
DS
11407}
11408
f14e6fdb
DS
11409DEFUN (show_ip_bgp_peer_groups,
11410 show_ip_bgp_peer_groups_cmd,
18c57037 11411 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11412 SHOW_STR
11413 IP_STR
11414 BGP_STR
8386ac43 11415 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11416 "Detailed information on BGP peer groups\n"
11417 "Peer group name\n")
f14e6fdb 11418{
d62a17ae 11419 char *vrf, *pg;
d62a17ae 11420 int idx = 0;
f14e6fdb 11421
a4d82a8a
PZ
11422 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11423 : NULL;
d62a17ae 11424 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11425
ff9959b0 11426 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11427}
3f9c7369 11428
d6e3c605 11429
718e3744 11430/* Redistribute VTY commands. */
11431
718e3744 11432DEFUN (bgp_redistribute_ipv4,
11433 bgp_redistribute_ipv4_cmd,
40d1cbfb 11434 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11435 "Redistribute information from another routing protocol\n"
ab0181ee 11436 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11437{
d62a17ae 11438 VTY_DECLVAR_CONTEXT(bgp, bgp);
11439 int idx_protocol = 1;
11440 int type;
718e3744 11441
d62a17ae 11442 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11443 if (type < 0) {
11444 vty_out(vty, "%% Invalid route type\n");
11445 return CMD_WARNING_CONFIG_FAILED;
11446 }
7f323236 11447
d62a17ae 11448 bgp_redist_add(bgp, AFI_IP, type, 0);
11449 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11450}
11451
d62a17ae 11452ALIAS_HIDDEN(
11453 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11454 "redistribute " FRR_IP_REDIST_STR_BGPD,
11455 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11456
718e3744 11457DEFUN (bgp_redistribute_ipv4_rmap,
11458 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11459 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11460 "Redistribute information from another routing protocol\n"
ab0181ee 11461 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11462 "Route map reference\n"
11463 "Pointer to route-map entries\n")
11464{
d62a17ae 11465 VTY_DECLVAR_CONTEXT(bgp, bgp);
11466 int idx_protocol = 1;
11467 int idx_word = 3;
11468 int type;
11469 struct bgp_redist *red;
718e3744 11470
d62a17ae 11471 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11472 if (type < 0) {
11473 vty_out(vty, "%% Invalid route type\n");
11474 return CMD_WARNING_CONFIG_FAILED;
11475 }
718e3744 11476
d62a17ae 11477 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11478 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11479 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11480}
11481
d62a17ae 11482ALIAS_HIDDEN(
11483 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11484 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11485 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11486 "Route map reference\n"
11487 "Pointer to route-map entries\n")
596c17ba 11488
718e3744 11489DEFUN (bgp_redistribute_ipv4_metric,
11490 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11491 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11492 "Redistribute information from another routing protocol\n"
ab0181ee 11493 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11494 "Metric for redistributed routes\n"
11495 "Default metric\n")
11496{
d62a17ae 11497 VTY_DECLVAR_CONTEXT(bgp, bgp);
11498 int idx_protocol = 1;
11499 int idx_number = 3;
11500 int type;
d7c0a89a 11501 uint32_t metric;
d62a17ae 11502 struct bgp_redist *red;
11503
11504 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11505 if (type < 0) {
11506 vty_out(vty, "%% Invalid route type\n");
11507 return CMD_WARNING_CONFIG_FAILED;
11508 }
11509 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11510
11511 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11512 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11513 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11514}
11515
11516ALIAS_HIDDEN(
11517 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11518 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11519 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11520 "Metric for redistributed routes\n"
11521 "Default metric\n")
596c17ba 11522
718e3744 11523DEFUN (bgp_redistribute_ipv4_rmap_metric,
11524 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11525 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11526 "Redistribute information from another routing protocol\n"
ab0181ee 11527 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11528 "Route map reference\n"
11529 "Pointer to route-map entries\n"
11530 "Metric for redistributed routes\n"
11531 "Default metric\n")
11532{
d62a17ae 11533 VTY_DECLVAR_CONTEXT(bgp, bgp);
11534 int idx_protocol = 1;
11535 int idx_word = 3;
11536 int idx_number = 5;
11537 int type;
d7c0a89a 11538 uint32_t metric;
d62a17ae 11539 struct bgp_redist *red;
11540
11541 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11542 if (type < 0) {
11543 vty_out(vty, "%% Invalid route type\n");
11544 return CMD_WARNING_CONFIG_FAILED;
11545 }
11546 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11547
11548 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11549 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11550 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11551 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11552}
11553
11554ALIAS_HIDDEN(
11555 bgp_redistribute_ipv4_rmap_metric,
11556 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11557 "redistribute " FRR_IP_REDIST_STR_BGPD
11558 " route-map WORD metric (0-4294967295)",
11559 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11560 "Route map reference\n"
11561 "Pointer to route-map entries\n"
11562 "Metric for redistributed routes\n"
11563 "Default metric\n")
596c17ba 11564
718e3744 11565DEFUN (bgp_redistribute_ipv4_metric_rmap,
11566 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11567 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11568 "Redistribute information from another routing protocol\n"
ab0181ee 11569 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11570 "Metric for redistributed routes\n"
11571 "Default metric\n"
11572 "Route map reference\n"
11573 "Pointer to route-map entries\n")
11574{
d62a17ae 11575 VTY_DECLVAR_CONTEXT(bgp, bgp);
11576 int idx_protocol = 1;
11577 int idx_number = 3;
11578 int idx_word = 5;
11579 int type;
d7c0a89a 11580 uint32_t metric;
d62a17ae 11581 struct bgp_redist *red;
11582
11583 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11584 if (type < 0) {
11585 vty_out(vty, "%% Invalid route type\n");
11586 return CMD_WARNING_CONFIG_FAILED;
11587 }
11588 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11589
11590 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11591 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11592 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11593 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11594}
11595
11596ALIAS_HIDDEN(
11597 bgp_redistribute_ipv4_metric_rmap,
11598 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11599 "redistribute " FRR_IP_REDIST_STR_BGPD
11600 " metric (0-4294967295) route-map WORD",
11601 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11602 "Metric for redistributed routes\n"
11603 "Default metric\n"
11604 "Route map reference\n"
11605 "Pointer to route-map entries\n")
596c17ba 11606
7c8ff89e
DS
11607DEFUN (bgp_redistribute_ipv4_ospf,
11608 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11609 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11610 "Redistribute information from another routing protocol\n"
11611 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11612 "Non-main Kernel Routing Table\n"
11613 "Instance ID/Table ID\n")
7c8ff89e 11614{
d62a17ae 11615 VTY_DECLVAR_CONTEXT(bgp, bgp);
11616 int idx_ospf_table = 1;
11617 int idx_number = 2;
d7c0a89a
QY
11618 unsigned short instance;
11619 unsigned short protocol;
7c8ff89e 11620
d62a17ae 11621 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11622
d62a17ae 11623 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11624 protocol = ZEBRA_ROUTE_OSPF;
11625 else
11626 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11627
d62a17ae 11628 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11629 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
11630}
11631
d62a17ae 11632ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11633 "redistribute <ospf|table> (1-65535)",
11634 "Redistribute information from another routing protocol\n"
11635 "Open Shortest Path First (OSPFv2)\n"
11636 "Non-main Kernel Routing Table\n"
11637 "Instance ID/Table ID\n")
596c17ba 11638
7c8ff89e
DS
11639DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11640 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11641 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11642 "Redistribute information from another routing protocol\n"
11643 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11644 "Non-main Kernel Routing Table\n"
11645 "Instance ID/Table ID\n"
7c8ff89e
DS
11646 "Route map reference\n"
11647 "Pointer to route-map entries\n")
11648{
d62a17ae 11649 VTY_DECLVAR_CONTEXT(bgp, bgp);
11650 int idx_ospf_table = 1;
11651 int idx_number = 2;
11652 int idx_word = 4;
11653 struct bgp_redist *red;
d7c0a89a 11654 unsigned short instance;
d62a17ae 11655 int protocol;
11656
11657 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11658 protocol = ZEBRA_ROUTE_OSPF;
11659 else
11660 protocol = ZEBRA_ROUTE_TABLE;
11661
11662 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11663 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11664 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11665 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11666}
11667
11668ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11669 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11670 "redistribute <ospf|table> (1-65535) route-map WORD",
11671 "Redistribute information from another routing protocol\n"
11672 "Open Shortest Path First (OSPFv2)\n"
11673 "Non-main Kernel Routing Table\n"
11674 "Instance ID/Table ID\n"
11675 "Route map reference\n"
11676 "Pointer to route-map entries\n")
596c17ba 11677
7c8ff89e
DS
11678DEFUN (bgp_redistribute_ipv4_ospf_metric,
11679 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 11680 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
11681 "Redistribute information from another routing protocol\n"
11682 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11683 "Non-main Kernel Routing Table\n"
11684 "Instance ID/Table ID\n"
7c8ff89e
DS
11685 "Metric for redistributed routes\n"
11686 "Default metric\n")
11687{
d62a17ae 11688 VTY_DECLVAR_CONTEXT(bgp, bgp);
11689 int idx_ospf_table = 1;
11690 int idx_number = 2;
11691 int idx_number_2 = 4;
d7c0a89a 11692 uint32_t metric;
d62a17ae 11693 struct bgp_redist *red;
d7c0a89a 11694 unsigned short instance;
d62a17ae 11695 int protocol;
11696
11697 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11698 protocol = ZEBRA_ROUTE_OSPF;
11699 else
11700 protocol = ZEBRA_ROUTE_TABLE;
11701
11702 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11703 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11704
11705 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11706 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11707 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11708}
11709
11710ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11711 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11712 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11713 "Redistribute information from another routing protocol\n"
11714 "Open Shortest Path First (OSPFv2)\n"
11715 "Non-main Kernel Routing Table\n"
11716 "Instance ID/Table ID\n"
11717 "Metric for redistributed routes\n"
11718 "Default metric\n")
596c17ba 11719
7c8ff89e
DS
11720DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11721 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 11722 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
11723 "Redistribute information from another routing protocol\n"
11724 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11725 "Non-main Kernel Routing Table\n"
11726 "Instance ID/Table ID\n"
7c8ff89e
DS
11727 "Route map reference\n"
11728 "Pointer to route-map entries\n"
11729 "Metric for redistributed routes\n"
11730 "Default metric\n")
11731{
d62a17ae 11732 VTY_DECLVAR_CONTEXT(bgp, bgp);
11733 int idx_ospf_table = 1;
11734 int idx_number = 2;
11735 int idx_word = 4;
11736 int idx_number_2 = 6;
d7c0a89a 11737 uint32_t metric;
d62a17ae 11738 struct bgp_redist *red;
d7c0a89a 11739 unsigned short instance;
d62a17ae 11740 int protocol;
11741
11742 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11743 protocol = ZEBRA_ROUTE_OSPF;
11744 else
11745 protocol = ZEBRA_ROUTE_TABLE;
11746
11747 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11748 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11749
11750 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11751 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11752 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11753 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11754}
11755
11756ALIAS_HIDDEN(
11757 bgp_redistribute_ipv4_ospf_rmap_metric,
11758 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11759 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11760 "Redistribute information from another routing protocol\n"
11761 "Open Shortest Path First (OSPFv2)\n"
11762 "Non-main Kernel Routing Table\n"
11763 "Instance ID/Table ID\n"
11764 "Route map reference\n"
11765 "Pointer to route-map entries\n"
11766 "Metric for redistributed routes\n"
11767 "Default metric\n")
596c17ba 11768
7c8ff89e
DS
11769DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11770 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 11771 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
11772 "Redistribute information from another routing protocol\n"
11773 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11774 "Non-main Kernel Routing Table\n"
11775 "Instance ID/Table ID\n"
7c8ff89e
DS
11776 "Metric for redistributed routes\n"
11777 "Default metric\n"
11778 "Route map reference\n"
11779 "Pointer to route-map entries\n")
11780{
d62a17ae 11781 VTY_DECLVAR_CONTEXT(bgp, bgp);
11782 int idx_ospf_table = 1;
11783 int idx_number = 2;
11784 int idx_number_2 = 4;
11785 int idx_word = 6;
d7c0a89a 11786 uint32_t metric;
d62a17ae 11787 struct bgp_redist *red;
d7c0a89a 11788 unsigned short instance;
d62a17ae 11789 int protocol;
11790
11791 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11792 protocol = ZEBRA_ROUTE_OSPF;
11793 else
11794 protocol = ZEBRA_ROUTE_TABLE;
11795
11796 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11797 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11798
11799 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11800 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11801 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11802 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11803}
11804
11805ALIAS_HIDDEN(
11806 bgp_redistribute_ipv4_ospf_metric_rmap,
11807 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11808 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11809 "Redistribute information from another routing protocol\n"
11810 "Open Shortest Path First (OSPFv2)\n"
11811 "Non-main Kernel Routing Table\n"
11812 "Instance ID/Table ID\n"
11813 "Metric for redistributed routes\n"
11814 "Default metric\n"
11815 "Route map reference\n"
11816 "Pointer to route-map entries\n")
596c17ba 11817
7c8ff89e
DS
11818DEFUN (no_bgp_redistribute_ipv4_ospf,
11819 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 11820 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
11821 NO_STR
11822 "Redistribute information from another routing protocol\n"
11823 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 11824 "Non-main Kernel Routing Table\n"
31500417
DW
11825 "Instance ID/Table ID\n"
11826 "Metric for redistributed routes\n"
11827 "Default metric\n"
11828 "Route map reference\n"
11829 "Pointer to route-map entries\n")
7c8ff89e 11830{
d62a17ae 11831 VTY_DECLVAR_CONTEXT(bgp, bgp);
11832 int idx_ospf_table = 2;
11833 int idx_number = 3;
d7c0a89a 11834 unsigned short instance;
d62a17ae 11835 int protocol;
11836
11837 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11838 protocol = ZEBRA_ROUTE_OSPF;
11839 else
11840 protocol = ZEBRA_ROUTE_TABLE;
11841
11842 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11843 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11844}
11845
11846ALIAS_HIDDEN(
11847 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11848 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11849 NO_STR
11850 "Redistribute information from another routing protocol\n"
11851 "Open Shortest Path First (OSPFv2)\n"
11852 "Non-main Kernel Routing Table\n"
11853 "Instance ID/Table ID\n"
11854 "Metric for redistributed routes\n"
11855 "Default metric\n"
11856 "Route map reference\n"
11857 "Pointer to route-map entries\n")
596c17ba 11858
718e3744 11859DEFUN (no_bgp_redistribute_ipv4,
11860 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 11861 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11862 NO_STR
11863 "Redistribute information from another routing protocol\n"
3b14d86e 11864 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
11865 "Metric for redistributed routes\n"
11866 "Default metric\n"
11867 "Route map reference\n"
11868 "Pointer to route-map entries\n")
718e3744 11869{
d62a17ae 11870 VTY_DECLVAR_CONTEXT(bgp, bgp);
11871 int idx_protocol = 2;
11872 int type;
11873
11874 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11875 if (type < 0) {
11876 vty_out(vty, "%% Invalid route type\n");
11877 return CMD_WARNING_CONFIG_FAILED;
11878 }
11879 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11880}
11881
11882ALIAS_HIDDEN(
11883 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11884 "no redistribute " FRR_IP_REDIST_STR_BGPD
11885 " [metric (0-4294967295)] [route-map WORD]",
11886 NO_STR
11887 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11888 "Metric for redistributed routes\n"
11889 "Default metric\n"
11890 "Route map reference\n"
11891 "Pointer to route-map entries\n")
596c17ba 11892
718e3744 11893DEFUN (bgp_redistribute_ipv6,
11894 bgp_redistribute_ipv6_cmd,
40d1cbfb 11895 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11896 "Redistribute information from another routing protocol\n"
ab0181ee 11897 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11898{
d62a17ae 11899 VTY_DECLVAR_CONTEXT(bgp, bgp);
11900 int idx_protocol = 1;
11901 int type;
718e3744 11902
d62a17ae 11903 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11904 if (type < 0) {
11905 vty_out(vty, "%% Invalid route type\n");
11906 return CMD_WARNING_CONFIG_FAILED;
11907 }
718e3744 11908
d62a17ae 11909 bgp_redist_add(bgp, AFI_IP6, type, 0);
11910 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11911}
11912
11913DEFUN (bgp_redistribute_ipv6_rmap,
11914 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11915 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11916 "Redistribute information from another routing protocol\n"
ab0181ee 11917 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11918 "Route map reference\n"
11919 "Pointer to route-map entries\n")
11920{
d62a17ae 11921 VTY_DECLVAR_CONTEXT(bgp, bgp);
11922 int idx_protocol = 1;
11923 int idx_word = 3;
11924 int type;
11925 struct bgp_redist *red;
718e3744 11926
d62a17ae 11927 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11928 if (type < 0) {
11929 vty_out(vty, "%% Invalid route type\n");
11930 return CMD_WARNING_CONFIG_FAILED;
11931 }
718e3744 11932
d62a17ae 11933 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11934 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11935 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11936}
11937
11938DEFUN (bgp_redistribute_ipv6_metric,
11939 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11940 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11941 "Redistribute information from another routing protocol\n"
ab0181ee 11942 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11943 "Metric for redistributed routes\n"
11944 "Default metric\n")
11945{
d62a17ae 11946 VTY_DECLVAR_CONTEXT(bgp, bgp);
11947 int idx_protocol = 1;
11948 int idx_number = 3;
11949 int type;
d7c0a89a 11950 uint32_t metric;
d62a17ae 11951 struct bgp_redist *red;
11952
11953 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11954 if (type < 0) {
11955 vty_out(vty, "%% Invalid route type\n");
11956 return CMD_WARNING_CONFIG_FAILED;
11957 }
11958 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11959
d62a17ae 11960 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11961 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11962 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11963}
11964
11965DEFUN (bgp_redistribute_ipv6_rmap_metric,
11966 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11967 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11968 "Redistribute information from another routing protocol\n"
ab0181ee 11969 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11970 "Route map reference\n"
11971 "Pointer to route-map entries\n"
11972 "Metric for redistributed routes\n"
11973 "Default metric\n")
11974{
d62a17ae 11975 VTY_DECLVAR_CONTEXT(bgp, bgp);
11976 int idx_protocol = 1;
11977 int idx_word = 3;
11978 int idx_number = 5;
11979 int type;
d7c0a89a 11980 uint32_t metric;
d62a17ae 11981 struct bgp_redist *red;
11982
11983 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11984 if (type < 0) {
11985 vty_out(vty, "%% Invalid route type\n");
11986 return CMD_WARNING_CONFIG_FAILED;
11987 }
11988 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11989
d62a17ae 11990 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11991 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11992 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11993 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11994}
11995
11996DEFUN (bgp_redistribute_ipv6_metric_rmap,
11997 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11998 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11999 "Redistribute information from another routing protocol\n"
ab0181ee 12000 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12001 "Metric for redistributed routes\n"
12002 "Default metric\n"
12003 "Route map reference\n"
12004 "Pointer to route-map entries\n")
12005{
d62a17ae 12006 VTY_DECLVAR_CONTEXT(bgp, bgp);
12007 int idx_protocol = 1;
12008 int idx_number = 3;
12009 int idx_word = 5;
12010 int type;
d7c0a89a 12011 uint32_t metric;
d62a17ae 12012 struct bgp_redist *red;
12013
12014 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12015 if (type < 0) {
12016 vty_out(vty, "%% Invalid route type\n");
12017 return CMD_WARNING_CONFIG_FAILED;
12018 }
12019 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12020
d62a17ae 12021 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12022 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
12023 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12024 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 12025}
12026
12027DEFUN (no_bgp_redistribute_ipv6,
12028 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 12029 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12030 NO_STR
12031 "Redistribute information from another routing protocol\n"
3b14d86e 12032 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12033 "Metric for redistributed routes\n"
12034 "Default metric\n"
12035 "Route map reference\n"
12036 "Pointer to route-map entries\n")
718e3744 12037{
d62a17ae 12038 VTY_DECLVAR_CONTEXT(bgp, bgp);
12039 int idx_protocol = 2;
12040 int type;
718e3744 12041
d62a17ae 12042 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12043 if (type < 0) {
12044 vty_out(vty, "%% Invalid route type\n");
12045 return CMD_WARNING_CONFIG_FAILED;
12046 }
718e3744 12047
d62a17ae 12048 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12049}
12050
2b791107 12051void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12052 safi_t safi)
d62a17ae 12053{
12054 int i;
12055
12056 /* Unicast redistribution only. */
12057 if (safi != SAFI_UNICAST)
2b791107 12058 return;
d62a17ae 12059
12060 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12061 /* Redistribute BGP does not make sense. */
12062 if (i != ZEBRA_ROUTE_BGP) {
12063 struct list *red_list;
12064 struct listnode *node;
12065 struct bgp_redist *red;
12066
12067 red_list = bgp->redist[afi][i];
12068 if (!red_list)
12069 continue;
12070
12071 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12072 /* "redistribute" configuration. */
12073 vty_out(vty, " redistribute %s",
12074 zebra_route_string(i));
12075 if (red->instance)
12076 vty_out(vty, " %d", red->instance);
12077 if (red->redist_metric_flag)
12078 vty_out(vty, " metric %u",
12079 red->redist_metric);
12080 if (red->rmap.name)
12081 vty_out(vty, " route-map %s",
12082 red->rmap.name);
12083 vty_out(vty, "\n");
12084 }
12085 }
12086 }
718e3744 12087}
6b0655a2 12088
b9c7bc5a
PZ
12089/* This is part of the address-family block (unicast only) */
12090void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12091 afi_t afi)
12092{
b9c7bc5a 12093 int indent = 2;
ddb5b488 12094
bb4f6190
DS
12095 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12096 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12097 bgp->vpn_policy[afi]
12098 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12099
12a844a5
DS
12100 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12101 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12102 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12103 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12104 return;
12105
e70e9f8e
PZ
12106 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12107 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12108
12109 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12110
12111 } else {
12112 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12113 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12114 bgp->vpn_policy[afi].tovpn_label);
12115 }
ddb5b488
PZ
12116 }
12117 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12118 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12119 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12120 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12121 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12122 sizeof(buf)));
12123 }
12124 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12125 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12126
12127 char buf[PREFIX_STRLEN];
12128 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12129 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12130 sizeof(buf))) {
12131
b9c7bc5a
PZ
12132 vty_out(vty, "%*snexthop vpn export %s\n",
12133 indent, "", buf);
ddb5b488
PZ
12134 }
12135 }
12136 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12137 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12138 && ecommunity_cmp(
12139 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12140 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12141
12142 char *b = ecommunity_ecom2str(
12143 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12144 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12145 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12146 XFREE(MTYPE_ECOMMUNITY_STR, b);
12147 } else {
12148 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12149 char *b = ecommunity_ecom2str(
12150 bgp->vpn_policy[afi]
12151 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12152 ECOMMUNITY_FORMAT_ROUTE_MAP,
12153 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12154 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12155 XFREE(MTYPE_ECOMMUNITY_STR, b);
12156 }
12157 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12158 char *b = ecommunity_ecom2str(
12159 bgp->vpn_policy[afi]
12160 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12161 ECOMMUNITY_FORMAT_ROUTE_MAP,
12162 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12163 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12164 XFREE(MTYPE_ECOMMUNITY_STR, b);
12165 }
12166 }
bb4f6190
DS
12167
12168 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12169 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12170 bgp->vpn_policy[afi]
12171 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12172
301ad80a
PG
12173 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12174 char *b = ecommunity_ecom2str(
12175 bgp->vpn_policy[afi]
12176 .import_redirect_rtlist,
12177 ECOMMUNITY_FORMAT_ROUTE_MAP,
12178 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12179
301ad80a
PG
12180 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12181 XFREE(MTYPE_ECOMMUNITY_STR, b);
12182 }
ddb5b488
PZ
12183}
12184
12185
718e3744 12186/* BGP node structure. */
d62a17ae 12187static struct cmd_node bgp_node = {
9d303b37 12188 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12189};
12190
d62a17ae 12191static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12192 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12193};
12194
d62a17ae 12195static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12196 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12197};
12198
d62a17ae 12199static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12200 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12201};
12202
d62a17ae 12203static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12204 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12205};
12206
d62a17ae 12207static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12208 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12209};
12210
d62a17ae 12211static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12212 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12213};
12214
d62a17ae 12215static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12216 "%s(config-router-af)# ", 1};
6b0655a2 12217
d62a17ae 12218static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12219 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12220
d62a17ae 12221static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12222 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12223
d62a17ae 12224static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12225 "%s(config-router-af-vni)# ", 1};
90e60aa7 12226
7c40bf39 12227static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12228 "%s(config-router-af)# ", 1};
12229
12230static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12231 "%s(config-router-af-vpnv6)# ", 1};
12232
d62a17ae 12233static void community_list_vty(void);
1f8ae70b 12234
d62a17ae 12235static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12236{
d62a17ae 12237 struct bgp *bgp;
12238 struct peer *peer;
d62a17ae 12239 struct listnode *lnbgp, *lnpeer;
b8a815e5 12240
d62a17ae 12241 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12242 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12243 /* only provide suggestions on the appropriate input
12244 * token type,
12245 * they'll otherwise show up multiple times */
12246 enum cmd_token_type match_type;
12247 char *name = peer->host;
d48ed3e0 12248
d62a17ae 12249 if (peer->conf_if) {
12250 match_type = VARIABLE_TKN;
12251 name = peer->conf_if;
12252 } else if (strchr(peer->host, ':'))
12253 match_type = IPV6_TKN;
12254 else
12255 match_type = IPV4_TKN;
d48ed3e0 12256
d62a17ae 12257 if (token->type != match_type)
12258 continue;
d48ed3e0 12259
d62a17ae 12260 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12261 }
d62a17ae 12262 }
b8a815e5
DL
12263}
12264
12265static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12266 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12267 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12268 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12269 {.completions = NULL}};
12270
47a306a0
DS
12271static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12272{
12273 struct bgp *bgp;
12274 struct peer_group *group;
12275 struct listnode *lnbgp, *lnpeer;
12276
12277 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12278 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12279 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12280 group->name));
12281 }
12282}
12283
12284static const struct cmd_variable_handler bgp_var_peergroup[] = {
12285 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12286 {.completions = NULL} };
12287
d62a17ae 12288void bgp_vty_init(void)
12289{
12290 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12291 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12292
12293 /* Install bgp top node. */
12294 install_node(&bgp_node, bgp_config_write);
12295 install_node(&bgp_ipv4_unicast_node, NULL);
12296 install_node(&bgp_ipv4_multicast_node, NULL);
12297 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12298 install_node(&bgp_ipv6_unicast_node, NULL);
12299 install_node(&bgp_ipv6_multicast_node, NULL);
12300 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12301 install_node(&bgp_vpnv4_node, NULL);
12302 install_node(&bgp_vpnv6_node, NULL);
12303 install_node(&bgp_evpn_node, NULL);
12304 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12305 install_node(&bgp_flowspecv4_node, NULL);
12306 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12307
12308 /* Install default VTY commands to new nodes. */
12309 install_default(BGP_NODE);
12310 install_default(BGP_IPV4_NODE);
12311 install_default(BGP_IPV4M_NODE);
12312 install_default(BGP_IPV4L_NODE);
12313 install_default(BGP_IPV6_NODE);
12314 install_default(BGP_IPV6M_NODE);
12315 install_default(BGP_IPV6L_NODE);
12316 install_default(BGP_VPNV4_NODE);
12317 install_default(BGP_VPNV6_NODE);
7c40bf39 12318 install_default(BGP_FLOWSPECV4_NODE);
12319 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12320 install_default(BGP_EVPN_NODE);
12321 install_default(BGP_EVPN_VNI_NODE);
12322
12323 /* "bgp multiple-instance" commands. */
12324 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12325 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12326
12327 /* "bgp config-type" commands. */
12328 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12329 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12330
12331 /* bgp route-map delay-timer commands. */
12332 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12333 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12334
12335 /* Dummy commands (Currently not supported) */
12336 install_element(BGP_NODE, &no_synchronization_cmd);
12337 install_element(BGP_NODE, &no_auto_summary_cmd);
12338
12339 /* "router bgp" commands. */
12340 install_element(CONFIG_NODE, &router_bgp_cmd);
12341
12342 /* "no router bgp" commands. */
12343 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12344
12345 /* "bgp router-id" commands. */
12346 install_element(BGP_NODE, &bgp_router_id_cmd);
12347 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12348
12349 /* "bgp cluster-id" commands. */
12350 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12351 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12352
12353 /* "bgp confederation" commands. */
12354 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12355 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12356
12357 /* "bgp confederation peers" commands. */
12358 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12359 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12360
12361 /* bgp max-med command */
12362 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12363 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12364 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12365 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12366 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12367
12368 /* bgp disable-ebgp-connected-nh-check */
12369 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12370 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12371
12372 /* bgp update-delay command */
12373 install_element(BGP_NODE, &bgp_update_delay_cmd);
12374 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12375 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12376
12377 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12378 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12379 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12380 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12381
12382 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12383 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12384
12385 /* "maximum-paths" commands. */
12386 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12387 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12388 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12389 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12390 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12391 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12392 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12393 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12394 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12395 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12396 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12397 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12398 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12399 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12400 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12401
12402 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12403 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12404 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12405 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12406 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12407
12408 /* "timers bgp" commands. */
12409 install_element(BGP_NODE, &bgp_timers_cmd);
12410 install_element(BGP_NODE, &no_bgp_timers_cmd);
12411
12412 /* route-map delay-timer commands - per instance for backwards compat.
12413 */
12414 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12415 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12416
12417 /* "bgp client-to-client reflection" commands */
12418 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12419 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12420
12421 /* "bgp always-compare-med" commands */
12422 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12423 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12424
12425 /* "bgp deterministic-med" commands */
12426 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12427 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12428
12429 /* "bgp graceful-restart" commands */
12430 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12431 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12432 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12433 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12434 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12435 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12436
12437 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12438 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12439
7f323236
DW
12440 /* "bgp graceful-shutdown" commands */
12441 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12442 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12443
d62a17ae 12444 /* "bgp fast-external-failover" commands */
12445 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12446 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12447
12448 /* "bgp enforce-first-as" commands */
12449 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
d62a17ae 12450
12451 /* "bgp bestpath compare-routerid" commands */
12452 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12453 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12454
12455 /* "bgp bestpath as-path ignore" commands */
12456 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12457 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12458
12459 /* "bgp bestpath as-path confed" commands */
12460 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12461 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12462
12463 /* "bgp bestpath as-path multipath-relax" commands */
12464 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12465 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12466
12467 /* "bgp log-neighbor-changes" commands */
12468 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12469 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12470
12471 /* "bgp bestpath med" commands */
12472 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12473 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12474
12475 /* "no bgp default ipv4-unicast" commands. */
12476 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12477 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12478
12479 /* "bgp network import-check" commands. */
12480 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12481 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12482 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12483
12484 /* "bgp default local-preference" commands. */
12485 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12486 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12487
12488 /* bgp default show-hostname */
12489 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12490 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12491
12492 /* "bgp default subgroup-pkt-queue-max" commands. */
12493 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12494 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12495
12496 /* bgp ibgp-allow-policy-mods command */
12497 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12498 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12499
12500 /* "bgp listen limit" commands. */
12501 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12502 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12503
12504 /* "bgp listen range" commands. */
12505 install_element(BGP_NODE, &bgp_listen_range_cmd);
12506 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12507
8175f54a 12508 /* "bgp default shutdown" command */
f26845f9
QY
12509 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12510
d62a17ae 12511 /* "neighbor remote-as" commands. */
12512 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12513 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12514 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12515 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12516 install_element(BGP_NODE,
12517 &neighbor_interface_v6only_config_remote_as_cmd);
12518 install_element(BGP_NODE, &no_neighbor_cmd);
12519 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12520
12521 /* "neighbor peer-group" commands. */
12522 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12523 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12524 install_element(BGP_NODE,
12525 &no_neighbor_interface_peer_group_remote_as_cmd);
12526
12527 /* "neighbor local-as" commands. */
12528 install_element(BGP_NODE, &neighbor_local_as_cmd);
12529 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12530 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12531 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12532
12533 /* "neighbor solo" commands. */
12534 install_element(BGP_NODE, &neighbor_solo_cmd);
12535 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12536
12537 /* "neighbor password" commands. */
12538 install_element(BGP_NODE, &neighbor_password_cmd);
12539 install_element(BGP_NODE, &no_neighbor_password_cmd);
12540
12541 /* "neighbor activate" commands. */
12542 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12543 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12544 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12545 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12546 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12547 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12548 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12549 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12550 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 12551 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12552 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 12553 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12554
12555 /* "no neighbor activate" commands. */
12556 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12557 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12558 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12559 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12560 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12561 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12562 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12563 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12564 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 12565 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12566 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 12567 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12568
12569 /* "neighbor peer-group" set commands. */
12570 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12571 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12572 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12573 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12574 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12575 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12576 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12577 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 12578 install_element(BGP_FLOWSPECV4_NODE,
12579 &neighbor_set_peer_group_hidden_cmd);
12580 install_element(BGP_FLOWSPECV6_NODE,
12581 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 12582
12583 /* "no neighbor peer-group unset" commands. */
12584 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12585 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12586 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12587 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12588 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12589 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12590 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12591 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 12592 install_element(BGP_FLOWSPECV4_NODE,
12593 &no_neighbor_set_peer_group_hidden_cmd);
12594 install_element(BGP_FLOWSPECV6_NODE,
12595 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 12596
12597 /* "neighbor softreconfiguration inbound" commands.*/
12598 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12599 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12600 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12601 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12602 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12603 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12604 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12605 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12606 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12607 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12608 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12609 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12610 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12611 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12612 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12613 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12614 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12615 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 12616 install_element(BGP_FLOWSPECV4_NODE,
12617 &neighbor_soft_reconfiguration_cmd);
12618 install_element(BGP_FLOWSPECV4_NODE,
12619 &no_neighbor_soft_reconfiguration_cmd);
12620 install_element(BGP_FLOWSPECV6_NODE,
12621 &neighbor_soft_reconfiguration_cmd);
12622 install_element(BGP_FLOWSPECV6_NODE,
12623 &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 12624
12625 /* "neighbor attribute-unchanged" commands. */
12626 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12627 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12628 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12629 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12630 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12631 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12632 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12633 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12634 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12635 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12636 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12637 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12638 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12639 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12640 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12641 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12642 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12643 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12644
12645 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12646 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12647
12648 /* "nexthop-local unchanged" commands */
12649 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12650 install_element(BGP_IPV6_NODE,
12651 &no_neighbor_nexthop_local_unchanged_cmd);
12652
12653 /* "neighbor next-hop-self" commands. */
12654 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12655 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12656 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12657 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12658 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12659 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12660 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12661 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12662 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12663 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12664 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12665 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12666 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12667 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12668 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12669 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12670 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12671 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
12672 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12673 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 12674
12675 /* "neighbor next-hop-self force" commands. */
12676 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12677 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12678 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12679 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12680 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12681 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12682 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12683 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12684 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12685 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12686 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12687 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12688 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12689 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12690 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12691 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12692 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12693 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12694
12695 /* "neighbor as-override" commands. */
12696 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12697 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12698 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12699 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12700 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12701 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12702 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12703 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12704 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12705 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12706 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12707 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12708 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12709 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12710 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12711 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12712 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12713 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12714
12715 /* "neighbor remove-private-AS" commands. */
12716 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12717 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12718 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12719 install_element(BGP_NODE,
12720 &no_neighbor_remove_private_as_all_hidden_cmd);
12721 install_element(BGP_NODE,
12722 &neighbor_remove_private_as_replace_as_hidden_cmd);
12723 install_element(BGP_NODE,
12724 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12725 install_element(BGP_NODE,
12726 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12727 install_element(
12728 BGP_NODE,
12729 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12730 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12731 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12732 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12733 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12734 install_element(BGP_IPV4_NODE,
12735 &neighbor_remove_private_as_replace_as_cmd);
12736 install_element(BGP_IPV4_NODE,
12737 &no_neighbor_remove_private_as_replace_as_cmd);
12738 install_element(BGP_IPV4_NODE,
12739 &neighbor_remove_private_as_all_replace_as_cmd);
12740 install_element(BGP_IPV4_NODE,
12741 &no_neighbor_remove_private_as_all_replace_as_cmd);
12742 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12743 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12744 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12745 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12746 install_element(BGP_IPV4M_NODE,
12747 &neighbor_remove_private_as_replace_as_cmd);
12748 install_element(BGP_IPV4M_NODE,
12749 &no_neighbor_remove_private_as_replace_as_cmd);
12750 install_element(BGP_IPV4M_NODE,
12751 &neighbor_remove_private_as_all_replace_as_cmd);
12752 install_element(BGP_IPV4M_NODE,
12753 &no_neighbor_remove_private_as_all_replace_as_cmd);
12754 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12755 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12756 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12757 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12758 install_element(BGP_IPV4L_NODE,
12759 &neighbor_remove_private_as_replace_as_cmd);
12760 install_element(BGP_IPV4L_NODE,
12761 &no_neighbor_remove_private_as_replace_as_cmd);
12762 install_element(BGP_IPV4L_NODE,
12763 &neighbor_remove_private_as_all_replace_as_cmd);
12764 install_element(BGP_IPV4L_NODE,
12765 &no_neighbor_remove_private_as_all_replace_as_cmd);
12766 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12767 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12768 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12769 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12770 install_element(BGP_IPV6_NODE,
12771 &neighbor_remove_private_as_replace_as_cmd);
12772 install_element(BGP_IPV6_NODE,
12773 &no_neighbor_remove_private_as_replace_as_cmd);
12774 install_element(BGP_IPV6_NODE,
12775 &neighbor_remove_private_as_all_replace_as_cmd);
12776 install_element(BGP_IPV6_NODE,
12777 &no_neighbor_remove_private_as_all_replace_as_cmd);
12778 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12779 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12780 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12781 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12782 install_element(BGP_IPV6M_NODE,
12783 &neighbor_remove_private_as_replace_as_cmd);
12784 install_element(BGP_IPV6M_NODE,
12785 &no_neighbor_remove_private_as_replace_as_cmd);
12786 install_element(BGP_IPV6M_NODE,
12787 &neighbor_remove_private_as_all_replace_as_cmd);
12788 install_element(BGP_IPV6M_NODE,
12789 &no_neighbor_remove_private_as_all_replace_as_cmd);
12790 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12791 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12792 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12793 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12794 install_element(BGP_IPV6L_NODE,
12795 &neighbor_remove_private_as_replace_as_cmd);
12796 install_element(BGP_IPV6L_NODE,
12797 &no_neighbor_remove_private_as_replace_as_cmd);
12798 install_element(BGP_IPV6L_NODE,
12799 &neighbor_remove_private_as_all_replace_as_cmd);
12800 install_element(BGP_IPV6L_NODE,
12801 &no_neighbor_remove_private_as_all_replace_as_cmd);
12802 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12803 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12804 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12805 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12806 install_element(BGP_VPNV4_NODE,
12807 &neighbor_remove_private_as_replace_as_cmd);
12808 install_element(BGP_VPNV4_NODE,
12809 &no_neighbor_remove_private_as_replace_as_cmd);
12810 install_element(BGP_VPNV4_NODE,
12811 &neighbor_remove_private_as_all_replace_as_cmd);
12812 install_element(BGP_VPNV4_NODE,
12813 &no_neighbor_remove_private_as_all_replace_as_cmd);
12814 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12815 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12816 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12817 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12818 install_element(BGP_VPNV6_NODE,
12819 &neighbor_remove_private_as_replace_as_cmd);
12820 install_element(BGP_VPNV6_NODE,
12821 &no_neighbor_remove_private_as_replace_as_cmd);
12822 install_element(BGP_VPNV6_NODE,
12823 &neighbor_remove_private_as_all_replace_as_cmd);
12824 install_element(BGP_VPNV6_NODE,
12825 &no_neighbor_remove_private_as_all_replace_as_cmd);
12826
12827 /* "neighbor send-community" commands.*/
12828 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12829 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12830 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12831 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12832 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12833 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12834 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12835 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12836 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12837 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12838 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12839 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12840 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12841 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12842 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12843 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12844 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12845 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12846 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12847 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12848 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12849 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12850 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12851 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12852 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12853 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12854 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12855 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12856 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12857 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12858 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12859 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12860 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12861 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12862 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12863 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12864
12865 /* "neighbor route-reflector" commands.*/
12866 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12867 install_element(BGP_NODE,
12868 &no_neighbor_route_reflector_client_hidden_cmd);
12869 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12870 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12871 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12872 install_element(BGP_IPV4M_NODE,
12873 &no_neighbor_route_reflector_client_cmd);
12874 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12875 install_element(BGP_IPV4L_NODE,
12876 &no_neighbor_route_reflector_client_cmd);
12877 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12878 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12879 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12880 install_element(BGP_IPV6M_NODE,
12881 &no_neighbor_route_reflector_client_cmd);
12882 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12883 install_element(BGP_IPV6L_NODE,
12884 &no_neighbor_route_reflector_client_cmd);
12885 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12886 install_element(BGP_VPNV4_NODE,
12887 &no_neighbor_route_reflector_client_cmd);
12888 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12889 install_element(BGP_VPNV6_NODE,
12890 &no_neighbor_route_reflector_client_cmd);
7c40bf39 12891 install_element(BGP_FLOWSPECV4_NODE,
12892 &neighbor_route_reflector_client_cmd);
12893 install_element(BGP_FLOWSPECV4_NODE,
12894 &no_neighbor_route_reflector_client_cmd);
12895 install_element(BGP_FLOWSPECV6_NODE,
12896 &neighbor_route_reflector_client_cmd);
12897 install_element(BGP_FLOWSPECV6_NODE,
12898 &no_neighbor_route_reflector_client_cmd);
d62a17ae 12899 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12900 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12901
12902 /* "neighbor route-server" commands.*/
12903 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12904 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12905 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12906 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12907 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12908 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12909 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12910 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12911 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12912 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12913 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12914 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12915 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12916 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12917 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12918 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12919 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12920 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 12921 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12922 install_element(BGP_FLOWSPECV4_NODE,
12923 &no_neighbor_route_server_client_cmd);
12924 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12925 install_element(BGP_FLOWSPECV6_NODE,
12926 &no_neighbor_route_server_client_cmd);
d62a17ae 12927
12928 /* "neighbor addpath-tx-all-paths" commands.*/
12929 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12930 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12931 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12932 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12933 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12934 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12935 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12936 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12937 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12938 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12939 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12940 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12941 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12942 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12943 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12944 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12945 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12946 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12947
12948 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12949 install_element(BGP_NODE,
12950 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12951 install_element(BGP_NODE,
12952 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12953 install_element(BGP_IPV4_NODE,
12954 &neighbor_addpath_tx_bestpath_per_as_cmd);
12955 install_element(BGP_IPV4_NODE,
12956 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12957 install_element(BGP_IPV4M_NODE,
12958 &neighbor_addpath_tx_bestpath_per_as_cmd);
12959 install_element(BGP_IPV4M_NODE,
12960 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12961 install_element(BGP_IPV4L_NODE,
12962 &neighbor_addpath_tx_bestpath_per_as_cmd);
12963 install_element(BGP_IPV4L_NODE,
12964 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12965 install_element(BGP_IPV6_NODE,
12966 &neighbor_addpath_tx_bestpath_per_as_cmd);
12967 install_element(BGP_IPV6_NODE,
12968 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12969 install_element(BGP_IPV6M_NODE,
12970 &neighbor_addpath_tx_bestpath_per_as_cmd);
12971 install_element(BGP_IPV6M_NODE,
12972 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12973 install_element(BGP_IPV6L_NODE,
12974 &neighbor_addpath_tx_bestpath_per_as_cmd);
12975 install_element(BGP_IPV6L_NODE,
12976 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12977 install_element(BGP_VPNV4_NODE,
12978 &neighbor_addpath_tx_bestpath_per_as_cmd);
12979 install_element(BGP_VPNV4_NODE,
12980 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12981 install_element(BGP_VPNV6_NODE,
12982 &neighbor_addpath_tx_bestpath_per_as_cmd);
12983 install_element(BGP_VPNV6_NODE,
12984 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12985
12986 /* "neighbor passive" commands. */
12987 install_element(BGP_NODE, &neighbor_passive_cmd);
12988 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12989
12990
12991 /* "neighbor shutdown" commands. */
12992 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12993 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12994 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12995 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12996
12997 /* "neighbor capability extended-nexthop" commands.*/
12998 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12999 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13000
13001 /* "neighbor capability orf prefix-list" commands.*/
13002 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13003 install_element(BGP_NODE,
13004 &no_neighbor_capability_orf_prefix_hidden_cmd);
13005 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13006 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13007 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13008 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13009 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13010 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13011 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13012 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13013 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13014 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13015 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13016 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13017
13018 /* "neighbor capability dynamic" commands.*/
13019 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13020 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13021
13022 /* "neighbor dont-capability-negotiate" commands. */
13023 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13024 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13025
13026 /* "neighbor ebgp-multihop" commands. */
13027 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13028 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13029 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13030
13031 /* "neighbor disable-connected-check" commands. */
13032 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13033 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13034
47cbc09b
PM
13035 /* "neighbor enforce-first-as" commands. */
13036 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13037 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13038
d62a17ae 13039 /* "neighbor description" commands. */
13040 install_element(BGP_NODE, &neighbor_description_cmd);
13041 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13042 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13043
13044 /* "neighbor update-source" commands. "*/
13045 install_element(BGP_NODE, &neighbor_update_source_cmd);
13046 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13047
13048 /* "neighbor default-originate" commands. */
13049 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13050 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13051 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13052 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13053 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13054 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13055 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13056 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13057 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13058 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13059 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13060 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13061 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13062 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13063 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13064 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13065 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13066 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13067 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13068 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13069 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13070
13071 /* "neighbor port" commands. */
13072 install_element(BGP_NODE, &neighbor_port_cmd);
13073 install_element(BGP_NODE, &no_neighbor_port_cmd);
13074
13075 /* "neighbor weight" commands. */
13076 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13077 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13078
13079 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13080 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13081 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13082 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13083 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13084 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13085 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13086 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13087 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13088 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13089 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13090 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13091 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13092 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13093 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13094 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13095
13096 /* "neighbor override-capability" commands. */
13097 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13098 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13099
13100 /* "neighbor strict-capability-match" commands. */
13101 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13102 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13103
13104 /* "neighbor timers" commands. */
13105 install_element(BGP_NODE, &neighbor_timers_cmd);
13106 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13107
13108 /* "neighbor timers connect" commands. */
13109 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13110 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13111
13112 /* "neighbor advertisement-interval" commands. */
13113 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13114 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13115
13116 /* "neighbor interface" commands. */
13117 install_element(BGP_NODE, &neighbor_interface_cmd);
13118 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13119
13120 /* "neighbor distribute" commands. */
13121 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13122 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13123 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13124 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13125 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13126 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13127 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13128 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13129 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13130 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13131 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13132 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13133 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13134 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13135 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13136 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13137 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13138 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13139
13140 /* "neighbor prefix-list" commands. */
13141 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13142 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13143 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13144 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13145 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13146 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13147 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13148 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13149 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13150 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13151 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13152 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13153 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13154 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13155 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13156 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13157 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13158 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13159 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13160 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13161 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13162 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13163
13164 /* "neighbor filter-list" commands. */
13165 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13166 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13167 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13168 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13169 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13170 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13171 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13172 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13173 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13174 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13175 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13176 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13177 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13178 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13179 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13180 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13181 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13182 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13183 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13184 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13185 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13186 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13187
13188 /* "neighbor route-map" commands. */
13189 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13190 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13191 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13192 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13193 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13194 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13195 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13196 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13197 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13198 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13199 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13200 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13201 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13202 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13203 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13204 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13205 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13206 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13207 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13208 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13209 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13210 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13211 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13212 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13213
13214 /* "neighbor unsuppress-map" commands. */
13215 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13216 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13217 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13218 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13219 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13220 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13221 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13222 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13223 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13224 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13225 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13226 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13227 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13228 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13229 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13230 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13231 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13232 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13233
13234 /* "neighbor maximum-prefix" commands. */
13235 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13236 install_element(BGP_NODE,
13237 &neighbor_maximum_prefix_threshold_hidden_cmd);
13238 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13239 install_element(BGP_NODE,
13240 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13241 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13242 install_element(BGP_NODE,
13243 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13244 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13245 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13246 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13247 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13248 install_element(BGP_IPV4_NODE,
13249 &neighbor_maximum_prefix_threshold_warning_cmd);
13250 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13251 install_element(BGP_IPV4_NODE,
13252 &neighbor_maximum_prefix_threshold_restart_cmd);
13253 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13254 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13255 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13256 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13257 install_element(BGP_IPV4M_NODE,
13258 &neighbor_maximum_prefix_threshold_warning_cmd);
13259 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13260 install_element(BGP_IPV4M_NODE,
13261 &neighbor_maximum_prefix_threshold_restart_cmd);
13262 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13263 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13264 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13265 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13266 install_element(BGP_IPV4L_NODE,
13267 &neighbor_maximum_prefix_threshold_warning_cmd);
13268 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13269 install_element(BGP_IPV4L_NODE,
13270 &neighbor_maximum_prefix_threshold_restart_cmd);
13271 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13272 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13273 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13274 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13275 install_element(BGP_IPV6_NODE,
13276 &neighbor_maximum_prefix_threshold_warning_cmd);
13277 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13278 install_element(BGP_IPV6_NODE,
13279 &neighbor_maximum_prefix_threshold_restart_cmd);
13280 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13281 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13282 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13283 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13284 install_element(BGP_IPV6M_NODE,
13285 &neighbor_maximum_prefix_threshold_warning_cmd);
13286 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13287 install_element(BGP_IPV6M_NODE,
13288 &neighbor_maximum_prefix_threshold_restart_cmd);
13289 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13290 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13291 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13292 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13293 install_element(BGP_IPV6L_NODE,
13294 &neighbor_maximum_prefix_threshold_warning_cmd);
13295 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13296 install_element(BGP_IPV6L_NODE,
13297 &neighbor_maximum_prefix_threshold_restart_cmd);
13298 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13299 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13300 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13301 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13302 install_element(BGP_VPNV4_NODE,
13303 &neighbor_maximum_prefix_threshold_warning_cmd);
13304 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13305 install_element(BGP_VPNV4_NODE,
13306 &neighbor_maximum_prefix_threshold_restart_cmd);
13307 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13308 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13309 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13310 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13311 install_element(BGP_VPNV6_NODE,
13312 &neighbor_maximum_prefix_threshold_warning_cmd);
13313 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13314 install_element(BGP_VPNV6_NODE,
13315 &neighbor_maximum_prefix_threshold_restart_cmd);
13316 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13317
13318 /* "neighbor allowas-in" */
13319 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13320 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13321 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13322 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13323 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13324 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13325 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13326 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13327 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13328 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13329 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13330 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13331 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13332 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13333 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13334 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13335 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13336 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13337 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13338 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13339
13340 /* address-family commands. */
13341 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13342 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13343#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13344 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13345 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13346#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13347
d62a17ae 13348 install_element(BGP_NODE, &address_family_evpn_cmd);
13349
13350 /* "exit-address-family" command. */
13351 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13352 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13353 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13354 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13355 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13356 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13357 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13358 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13359 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13360 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13361 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13362
13363 /* "clear ip bgp commands" */
13364 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13365
13366 /* clear ip bgp prefix */
13367 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13368 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13369 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13370
13371 /* "show [ip] bgp summary" commands. */
13372 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
d62a17ae 13373 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13374 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13375 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13376 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13377 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13378
13379 /* "show [ip] bgp neighbors" commands. */
13380 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13381
13382 /* "show [ip] bgp peer-group" commands. */
13383 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13384
13385 /* "show [ip] bgp paths" commands. */
13386 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13387
13388 /* "show [ip] bgp community" commands. */
13389 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13390
13391 /* "show ip bgp large-community" commands. */
13392 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13393 /* "show [ip] bgp attribute-info" commands. */
13394 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13395 /* "show [ip] bgp route-leak" command */
13396 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13397
13398 /* "redistribute" commands. */
13399 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13400 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13401 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13402 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13403 install_element(BGP_NODE,
13404 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13405 install_element(BGP_NODE,
13406 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13407 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13408 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13409 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13410 install_element(BGP_NODE,
13411 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13412 install_element(BGP_NODE,
13413 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13414 install_element(BGP_NODE,
13415 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13416 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13417 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13418 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13419 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13420 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13421 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13422 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13423 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13424 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13425 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13426 install_element(BGP_IPV4_NODE,
13427 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13428 install_element(BGP_IPV4_NODE,
13429 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13430 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13431 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13432 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13433 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13434 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13435 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13436
b9c7bc5a
PZ
13437 /* import|export vpn [route-map WORD] */
13438 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13439 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13440
12a844a5
DS
13441 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13442 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13443
d62a17ae 13444 /* ttl_security commands */
13445 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13446 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13447
13448 /* "show [ip] bgp memory" commands. */
13449 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13450
acf71666
MK
13451 /* "show bgp martian next-hop" */
13452 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13453
d62a17ae 13454 /* "show [ip] bgp views" commands. */
13455 install_element(VIEW_NODE, &show_bgp_views_cmd);
13456
13457 /* "show [ip] bgp vrfs" commands. */
13458 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13459
13460 /* Community-list. */
13461 community_list_vty();
ddb5b488
PZ
13462
13463 /* vpn-policy commands */
b9c7bc5a
PZ
13464 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13465 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13466 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13467 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13468 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13469 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13470 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13471 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13472 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13473 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
13474 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13475 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 13476
301ad80a
PG
13477 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13478 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13479
b9c7bc5a
PZ
13480 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13481 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13482 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13483 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13484 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13485 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13486 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13487 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13488 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13489 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
13490 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13491 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 13492}
6b0655a2 13493
718e3744 13494#include "memory.h"
13495#include "bgp_regex.h"
13496#include "bgp_clist.h"
13497#include "bgp_ecommunity.h"
13498
13499/* VTY functions. */
13500
13501/* Direction value to string conversion. */
d62a17ae 13502static const char *community_direct_str(int direct)
13503{
13504 switch (direct) {
13505 case COMMUNITY_DENY:
13506 return "deny";
13507 case COMMUNITY_PERMIT:
13508 return "permit";
13509 default:
13510 return "unknown";
13511 }
718e3744 13512}
13513
13514/* Display error string. */
d62a17ae 13515static void community_list_perror(struct vty *vty, int ret)
13516{
13517 switch (ret) {
13518 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13519 vty_out(vty, "%% Can't find community-list\n");
13520 break;
13521 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13522 vty_out(vty, "%% Malformed community-list value\n");
13523 break;
13524 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13525 vty_out(vty,
13526 "%% Community name conflict, previously defined as standard community\n");
13527 break;
13528 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13529 vty_out(vty,
13530 "%% Community name conflict, previously defined as expanded community\n");
13531 break;
13532 }
718e3744 13533}
13534
5bf15956
DW
13535/* "community-list" keyword help string. */
13536#define COMMUNITY_LIST_STR "Add a community list entry\n"
13537
5bf15956 13538/* ip community-list standard */
718e3744 13539DEFUN (ip_community_list_standard,
13540 ip_community_list_standard_cmd,
e961923c 13541 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13542 IP_STR
13543 COMMUNITY_LIST_STR
13544 "Community list number (standard)\n"
5bf15956 13545 "Add an standard community-list entry\n"
718e3744 13546 "Community list name\n"
13547 "Specify community to reject\n"
13548 "Specify community to accept\n"
13549 COMMUNITY_VAL_STR)
13550{
d62a17ae 13551 char *cl_name_or_number = NULL;
13552 int direct = 0;
13553 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13554
d62a17ae 13555 int idx = 0;
13556 argv_find(argv, argc, "(1-99)", &idx);
13557 argv_find(argv, argc, "WORD", &idx);
13558 cl_name_or_number = argv[idx]->arg;
13559 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13560 : COMMUNITY_DENY;
13561 argv_find(argv, argc, "AA:NN", &idx);
13562 char *str = argv_concat(argv, argc, idx);
42f914d4 13563
d62a17ae 13564 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13565 style);
42f914d4 13566
d62a17ae 13567 XFREE(MTYPE_TMP, str);
42f914d4 13568
d62a17ae 13569 if (ret < 0) {
13570 /* Display error string. */
13571 community_list_perror(vty, ret);
13572 return CMD_WARNING_CONFIG_FAILED;
13573 }
42f914d4 13574
d62a17ae 13575 return CMD_SUCCESS;
718e3744 13576}
13577
fee6e4e4 13578DEFUN (no_ip_community_list_standard_all,
13579 no_ip_community_list_standard_all_cmd,
e961923c 13580 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13581 NO_STR
13582 IP_STR
13583 COMMUNITY_LIST_STR
13584 "Community list number (standard)\n"
5bf15956
DW
13585 "Add an standard community-list entry\n"
13586 "Community list name\n"
718e3744 13587 "Specify community to reject\n"
13588 "Specify community to accept\n"
13589 COMMUNITY_VAL_STR)
13590{
d62a17ae 13591 char *cl_name_or_number = NULL;
13592 int direct = 0;
13593 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13594
d62a17ae 13595 int idx = 0;
13596 argv_find(argv, argc, "(1-99)", &idx);
13597 argv_find(argv, argc, "WORD", &idx);
13598 cl_name_or_number = argv[idx]->arg;
13599 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13600 : COMMUNITY_DENY;
13601 argv_find(argv, argc, "AA:NN", &idx);
13602 char *str = argv_concat(argv, argc, idx);
42f914d4 13603
d62a17ae 13604 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13605 direct, style);
42f914d4 13606
d62a17ae 13607 XFREE(MTYPE_TMP, str);
daf9ddbb 13608
d62a17ae 13609 if (ret < 0) {
13610 community_list_perror(vty, ret);
13611 return CMD_WARNING_CONFIG_FAILED;
13612 }
42f914d4 13613
d62a17ae 13614 return CMD_SUCCESS;
718e3744 13615}
13616
5bf15956
DW
13617/* ip community-list expanded */
13618DEFUN (ip_community_list_expanded_all,
13619 ip_community_list_expanded_all_cmd,
42f914d4 13620 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13621 IP_STR
13622 COMMUNITY_LIST_STR
13623 "Community list number (expanded)\n"
5bf15956 13624 "Add an expanded community-list entry\n"
718e3744 13625 "Community list name\n"
13626 "Specify community to reject\n"
13627 "Specify community to accept\n"
13628 COMMUNITY_VAL_STR)
13629{
d62a17ae 13630 char *cl_name_or_number = NULL;
13631 int direct = 0;
13632 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13633
d62a17ae 13634 int idx = 0;
13635 argv_find(argv, argc, "(100-500)", &idx);
13636 argv_find(argv, argc, "WORD", &idx);
13637 cl_name_or_number = argv[idx]->arg;
13638 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13639 : COMMUNITY_DENY;
13640 argv_find(argv, argc, "AA:NN", &idx);
13641 char *str = argv_concat(argv, argc, idx);
42f914d4 13642
d62a17ae 13643 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13644 style);
42f914d4 13645
d62a17ae 13646 XFREE(MTYPE_TMP, str);
42f914d4 13647
d62a17ae 13648 if (ret < 0) {
13649 /* Display error string. */
13650 community_list_perror(vty, ret);
13651 return CMD_WARNING_CONFIG_FAILED;
13652 }
42f914d4 13653
d62a17ae 13654 return CMD_SUCCESS;
718e3744 13655}
13656
5bf15956
DW
13657DEFUN (no_ip_community_list_expanded_all,
13658 no_ip_community_list_expanded_all_cmd,
42f914d4 13659 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13660 NO_STR
13661 IP_STR
13662 COMMUNITY_LIST_STR
5bf15956
DW
13663 "Community list number (expanded)\n"
13664 "Add an expanded community-list entry\n"
718e3744 13665 "Community list name\n"
13666 "Specify community to reject\n"
13667 "Specify community to accept\n"
5bf15956 13668 COMMUNITY_VAL_STR)
718e3744 13669{
d62a17ae 13670 char *cl_name_or_number = NULL;
13671 int direct = 0;
13672 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13673
d62a17ae 13674 int idx = 0;
13675 argv_find(argv, argc, "(100-500)", &idx);
13676 argv_find(argv, argc, "WORD", &idx);
13677 cl_name_or_number = argv[idx]->arg;
13678 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13679 : COMMUNITY_DENY;
13680 argv_find(argv, argc, "AA:NN", &idx);
13681 char *str = argv_concat(argv, argc, idx);
42f914d4 13682
d62a17ae 13683 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13684 direct, style);
42f914d4 13685
d62a17ae 13686 XFREE(MTYPE_TMP, str);
daf9ddbb 13687
d62a17ae 13688 if (ret < 0) {
13689 community_list_perror(vty, ret);
13690 return CMD_WARNING_CONFIG_FAILED;
13691 }
42f914d4 13692
d62a17ae 13693 return CMD_SUCCESS;
718e3744 13694}
13695
8d9b8ed9
PM
13696/* Return configuration string of community-list entry. */
13697static const char *community_list_config_str(struct community_entry *entry)
13698{
13699 const char *str;
13700
13701 if (entry->any)
13702 str = "";
13703 else {
13704 if (entry->style == COMMUNITY_LIST_STANDARD)
13705 str = community_str(entry->u.com, false);
13706 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13707 str = lcommunity_str(entry->u.lcom, false);
13708 else
13709 str = entry->config;
13710 }
13711 return str;
13712}
13713
d62a17ae 13714static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 13715{
d62a17ae 13716 struct community_entry *entry;
718e3744 13717
d62a17ae 13718 for (entry = list->head; entry; entry = entry->next) {
13719 if (entry == list->head) {
13720 if (all_digit(list->name))
13721 vty_out(vty, "Community %s list %s\n",
13722 entry->style == COMMUNITY_LIST_STANDARD
13723 ? "standard"
13724 : "(expanded) access",
13725 list->name);
13726 else
13727 vty_out(vty, "Named Community %s list %s\n",
13728 entry->style == COMMUNITY_LIST_STANDARD
13729 ? "standard"
13730 : "expanded",
13731 list->name);
13732 }
13733 if (entry->any)
13734 vty_out(vty, " %s\n",
13735 community_direct_str(entry->direct));
13736 else
13737 vty_out(vty, " %s %s\n",
13738 community_direct_str(entry->direct),
8d9b8ed9 13739 community_list_config_str(entry));
d62a17ae 13740 }
718e3744 13741}
13742
13743DEFUN (show_ip_community_list,
13744 show_ip_community_list_cmd,
13745 "show ip community-list",
13746 SHOW_STR
13747 IP_STR
13748 "List community-list\n")
13749{
d62a17ae 13750 struct community_list *list;
13751 struct community_list_master *cm;
718e3744 13752
d62a17ae 13753 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13754 if (!cm)
13755 return CMD_SUCCESS;
718e3744 13756
d62a17ae 13757 for (list = cm->num.head; list; list = list->next)
13758 community_list_show(vty, list);
718e3744 13759
d62a17ae 13760 for (list = cm->str.head; list; list = list->next)
13761 community_list_show(vty, list);
718e3744 13762
d62a17ae 13763 return CMD_SUCCESS;
718e3744 13764}
13765
13766DEFUN (show_ip_community_list_arg,
13767 show_ip_community_list_arg_cmd,
6147e2c6 13768 "show ip community-list <(1-500)|WORD>",
718e3744 13769 SHOW_STR
13770 IP_STR
13771 "List community-list\n"
13772 "Community-list number\n"
13773 "Community-list name\n")
13774{
d62a17ae 13775 int idx_comm_list = 3;
13776 struct community_list *list;
718e3744 13777
d62a17ae 13778 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13779 COMMUNITY_LIST_MASTER);
13780 if (!list) {
13781 vty_out(vty, "%% Can't find community-list\n");
13782 return CMD_WARNING;
13783 }
718e3744 13784
d62a17ae 13785 community_list_show(vty, list);
718e3744 13786
d62a17ae 13787 return CMD_SUCCESS;
718e3744 13788}
6b0655a2 13789
57d187bc
JS
13790/*
13791 * Large Community code.
13792 */
d62a17ae 13793static int lcommunity_list_set_vty(struct vty *vty, int argc,
13794 struct cmd_token **argv, int style,
13795 int reject_all_digit_name)
13796{
13797 int ret;
13798 int direct;
13799 char *str;
13800 int idx = 0;
13801 char *cl_name;
13802
13803 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13804 : COMMUNITY_DENY;
13805
13806 /* All digit name check. */
13807 idx = 0;
13808 argv_find(argv, argc, "WORD", &idx);
13809 argv_find(argv, argc, "(1-99)", &idx);
13810 argv_find(argv, argc, "(100-500)", &idx);
13811 cl_name = argv[idx]->arg;
13812 if (reject_all_digit_name && all_digit(cl_name)) {
13813 vty_out(vty, "%% Community name cannot have all digits\n");
13814 return CMD_WARNING_CONFIG_FAILED;
13815 }
13816
13817 idx = 0;
13818 argv_find(argv, argc, "AA:BB:CC", &idx);
13819 argv_find(argv, argc, "LINE", &idx);
13820 /* Concat community string argument. */
13821 if (idx)
13822 str = argv_concat(argv, argc, idx);
13823 else
13824 str = NULL;
13825
13826 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13827
13828 /* Free temporary community list string allocated by
13829 argv_concat(). */
13830 if (str)
13831 XFREE(MTYPE_TMP, str);
13832
13833 if (ret < 0) {
13834 community_list_perror(vty, ret);
13835 return CMD_WARNING_CONFIG_FAILED;
13836 }
13837 return CMD_SUCCESS;
13838}
13839
13840static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13841 struct cmd_token **argv, int style)
13842{
13843 int ret;
13844 int direct = 0;
13845 char *str = NULL;
13846 int idx = 0;
13847
13848 argv_find(argv, argc, "permit", &idx);
13849 argv_find(argv, argc, "deny", &idx);
13850
13851 if (idx) {
13852 /* Check the list direct. */
13853 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13854 direct = COMMUNITY_PERMIT;
13855 else
13856 direct = COMMUNITY_DENY;
13857
13858 idx = 0;
13859 argv_find(argv, argc, "LINE", &idx);
13860 argv_find(argv, argc, "AA:AA:NN", &idx);
13861 /* Concat community string argument. */
13862 str = argv_concat(argv, argc, idx);
13863 }
13864
13865 idx = 0;
13866 argv_find(argv, argc, "(1-99)", &idx);
13867 argv_find(argv, argc, "(100-500)", &idx);
13868 argv_find(argv, argc, "WORD", &idx);
13869
13870 /* Unset community list. */
13871 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13872 style);
13873
13874 /* Free temporary community list string allocated by
13875 argv_concat(). */
13876 if (str)
13877 XFREE(MTYPE_TMP, str);
13878
13879 if (ret < 0) {
13880 community_list_perror(vty, ret);
13881 return CMD_WARNING_CONFIG_FAILED;
13882 }
13883
13884 return CMD_SUCCESS;
57d187bc
JS
13885}
13886
13887/* "large-community-list" keyword help string. */
13888#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13889#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13890
13891DEFUN (ip_lcommunity_list_standard,
13892 ip_lcommunity_list_standard_cmd,
52951b63
DS
13893 "ip large-community-list (1-99) <deny|permit>",
13894 IP_STR
13895 LCOMMUNITY_LIST_STR
13896 "Large Community list number (standard)\n"
13897 "Specify large community to reject\n"
7111c1a0 13898 "Specify large community to accept\n")
52951b63 13899{
d62a17ae 13900 return lcommunity_list_set_vty(vty, argc, argv,
13901 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
13902}
13903
13904DEFUN (ip_lcommunity_list_standard1,
13905 ip_lcommunity_list_standard1_cmd,
13906 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
13907 IP_STR
13908 LCOMMUNITY_LIST_STR
13909 "Large Community list number (standard)\n"
13910 "Specify large community to reject\n"
13911 "Specify large community to accept\n"
13912 LCOMMUNITY_VAL_STR)
13913{
d62a17ae 13914 return lcommunity_list_set_vty(vty, argc, argv,
13915 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
13916}
13917
13918DEFUN (ip_lcommunity_list_expanded,
13919 ip_lcommunity_list_expanded_cmd,
13920 "ip large-community-list (100-500) <deny|permit> LINE...",
13921 IP_STR
13922 LCOMMUNITY_LIST_STR
13923 "Large Community list number (expanded)\n"
13924 "Specify large community to reject\n"
13925 "Specify large community to accept\n"
13926 "An ordered list as a regular-expression\n")
13927{
d62a17ae 13928 return lcommunity_list_set_vty(vty, argc, argv,
13929 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
13930}
13931
13932DEFUN (ip_lcommunity_list_name_standard,
13933 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
13934 "ip large-community-list standard WORD <deny|permit>",
13935 IP_STR
13936 LCOMMUNITY_LIST_STR
13937 "Specify standard large-community-list\n"
13938 "Large Community list name\n"
13939 "Specify large community to reject\n"
13940 "Specify large community to accept\n")
13941{
d62a17ae 13942 return lcommunity_list_set_vty(vty, argc, argv,
13943 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
13944}
13945
13946DEFUN (ip_lcommunity_list_name_standard1,
13947 ip_lcommunity_list_name_standard1_cmd,
13948 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
13949 IP_STR
13950 LCOMMUNITY_LIST_STR
13951 "Specify standard large-community-list\n"
13952 "Large Community list name\n"
13953 "Specify large community to reject\n"
13954 "Specify large community to accept\n"
13955 LCOMMUNITY_VAL_STR)
13956{
d62a17ae 13957 return lcommunity_list_set_vty(vty, argc, argv,
13958 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
13959}
13960
13961DEFUN (ip_lcommunity_list_name_expanded,
13962 ip_lcommunity_list_name_expanded_cmd,
13963 "ip large-community-list expanded WORD <deny|permit> LINE...",
13964 IP_STR
13965 LCOMMUNITY_LIST_STR
13966 "Specify expanded large-community-list\n"
13967 "Large Community list name\n"
13968 "Specify large community to reject\n"
13969 "Specify large community to accept\n"
13970 "An ordered list as a regular-expression\n")
13971{
d62a17ae 13972 return lcommunity_list_set_vty(vty, argc, argv,
13973 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
13974}
13975
13976DEFUN (no_ip_lcommunity_list_standard_all,
13977 no_ip_lcommunity_list_standard_all_cmd,
13978 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13979 NO_STR
13980 IP_STR
13981 LCOMMUNITY_LIST_STR
13982 "Large Community list number (standard)\n"
13983 "Large Community list number (expanded)\n"
13984 "Large Community list name\n")
13985{
d62a17ae 13986 return lcommunity_list_unset_vty(vty, argc, argv,
13987 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13988}
13989
13990DEFUN (no_ip_lcommunity_list_name_expanded_all,
13991 no_ip_lcommunity_list_name_expanded_all_cmd,
13992 "no ip large-community-list expanded WORD",
13993 NO_STR
13994 IP_STR
13995 LCOMMUNITY_LIST_STR
13996 "Specify expanded large-community-list\n"
13997 "Large Community list name\n")
13998{
d62a17ae 13999 return lcommunity_list_unset_vty(vty, argc, argv,
14000 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14001}
14002
14003DEFUN (no_ip_lcommunity_list_standard,
14004 no_ip_lcommunity_list_standard_cmd,
14005 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14006 NO_STR
14007 IP_STR
14008 LCOMMUNITY_LIST_STR
14009 "Large Community list number (standard)\n"
14010 "Specify large community to reject\n"
14011 "Specify large community to accept\n"
14012 LCOMMUNITY_VAL_STR)
14013{
d62a17ae 14014 return lcommunity_list_unset_vty(vty, argc, argv,
14015 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14016}
14017
14018DEFUN (no_ip_lcommunity_list_expanded,
14019 no_ip_lcommunity_list_expanded_cmd,
14020 "no ip large-community-list (100-500) <deny|permit> LINE...",
14021 NO_STR
14022 IP_STR
14023 LCOMMUNITY_LIST_STR
14024 "Large Community list number (expanded)\n"
14025 "Specify large community to reject\n"
14026 "Specify large community to accept\n"
14027 "An ordered list as a regular-expression\n")
14028{
d62a17ae 14029 return lcommunity_list_unset_vty(vty, argc, argv,
14030 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14031}
14032
14033DEFUN (no_ip_lcommunity_list_name_standard,
14034 no_ip_lcommunity_list_name_standard_cmd,
14035 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14036 NO_STR
14037 IP_STR
14038 LCOMMUNITY_LIST_STR
14039 "Specify standard large-community-list\n"
14040 "Large Community list name\n"
14041 "Specify large community to reject\n"
14042 "Specify large community to accept\n"
14043 LCOMMUNITY_VAL_STR)
14044{
d62a17ae 14045 return lcommunity_list_unset_vty(vty, argc, argv,
14046 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14047}
14048
14049DEFUN (no_ip_lcommunity_list_name_expanded,
14050 no_ip_lcommunity_list_name_expanded_cmd,
14051 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14052 NO_STR
14053 IP_STR
14054 LCOMMUNITY_LIST_STR
14055 "Specify expanded large-community-list\n"
14056 "Large community list name\n"
14057 "Specify large community to reject\n"
14058 "Specify large community to accept\n"
14059 "An ordered list as a regular-expression\n")
14060{
d62a17ae 14061 return lcommunity_list_unset_vty(vty, argc, argv,
14062 LARGE_COMMUNITY_LIST_EXPANDED);
14063}
14064
14065static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14066{
14067 struct community_entry *entry;
14068
14069 for (entry = list->head; entry; entry = entry->next) {
14070 if (entry == list->head) {
14071 if (all_digit(list->name))
14072 vty_out(vty, "Large community %s list %s\n",
14073 entry->style == EXTCOMMUNITY_LIST_STANDARD
14074 ? "standard"
14075 : "(expanded) access",
14076 list->name);
14077 else
14078 vty_out(vty,
14079 "Named large community %s list %s\n",
14080 entry->style == EXTCOMMUNITY_LIST_STANDARD
14081 ? "standard"
14082 : "expanded",
14083 list->name);
14084 }
14085 if (entry->any)
14086 vty_out(vty, " %s\n",
14087 community_direct_str(entry->direct));
14088 else
14089 vty_out(vty, " %s %s\n",
14090 community_direct_str(entry->direct),
8d9b8ed9 14091 community_list_config_str(entry));
d62a17ae 14092 }
57d187bc
JS
14093}
14094
14095DEFUN (show_ip_lcommunity_list,
14096 show_ip_lcommunity_list_cmd,
14097 "show ip large-community-list",
14098 SHOW_STR
14099 IP_STR
14100 "List large-community list\n")
14101{
d62a17ae 14102 struct community_list *list;
14103 struct community_list_master *cm;
57d187bc 14104
d62a17ae 14105 cm = community_list_master_lookup(bgp_clist,
14106 LARGE_COMMUNITY_LIST_MASTER);
14107 if (!cm)
14108 return CMD_SUCCESS;
57d187bc 14109
d62a17ae 14110 for (list = cm->num.head; list; list = list->next)
14111 lcommunity_list_show(vty, list);
57d187bc 14112
d62a17ae 14113 for (list = cm->str.head; list; list = list->next)
14114 lcommunity_list_show(vty, list);
57d187bc 14115
d62a17ae 14116 return CMD_SUCCESS;
57d187bc
JS
14117}
14118
14119DEFUN (show_ip_lcommunity_list_arg,
14120 show_ip_lcommunity_list_arg_cmd,
14121 "show ip large-community-list <(1-500)|WORD>",
14122 SHOW_STR
14123 IP_STR
14124 "List large-community list\n"
14125 "large-community-list number\n"
14126 "large-community-list name\n")
14127{
d62a17ae 14128 struct community_list *list;
57d187bc 14129
d62a17ae 14130 list = community_list_lookup(bgp_clist, argv[3]->arg,
14131 LARGE_COMMUNITY_LIST_MASTER);
14132 if (!list) {
14133 vty_out(vty, "%% Can't find extcommunity-list\n");
14134 return CMD_WARNING;
14135 }
57d187bc 14136
d62a17ae 14137 lcommunity_list_show(vty, list);
57d187bc 14138
d62a17ae 14139 return CMD_SUCCESS;
57d187bc
JS
14140}
14141
718e3744 14142/* "extcommunity-list" keyword help string. */
14143#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14144#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14145
14146DEFUN (ip_extcommunity_list_standard,
14147 ip_extcommunity_list_standard_cmd,
e961923c 14148 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14149 IP_STR
14150 EXTCOMMUNITY_LIST_STR
14151 "Extended Community list number (standard)\n"
718e3744 14152 "Specify standard extcommunity-list\n"
5bf15956 14153 "Community list name\n"
718e3744 14154 "Specify community to reject\n"
14155 "Specify community to accept\n"
14156 EXTCOMMUNITY_VAL_STR)
14157{
d62a17ae 14158 int style = EXTCOMMUNITY_LIST_STANDARD;
14159 int direct = 0;
14160 char *cl_number_or_name = NULL;
42f914d4 14161
d62a17ae 14162 int idx = 0;
14163 argv_find(argv, argc, "(1-99)", &idx);
14164 argv_find(argv, argc, "WORD", &idx);
14165 cl_number_or_name = argv[idx]->arg;
14166 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14167 : COMMUNITY_DENY;
14168 argv_find(argv, argc, "AA:NN", &idx);
14169 char *str = argv_concat(argv, argc, idx);
42f914d4 14170
d62a17ae 14171 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14172 direct, style);
42f914d4 14173
d62a17ae 14174 XFREE(MTYPE_TMP, str);
42f914d4 14175
d62a17ae 14176 if (ret < 0) {
14177 community_list_perror(vty, ret);
14178 return CMD_WARNING_CONFIG_FAILED;
14179 }
42f914d4 14180
d62a17ae 14181 return CMD_SUCCESS;
718e3744 14182}
14183
718e3744 14184DEFUN (ip_extcommunity_list_name_expanded,
14185 ip_extcommunity_list_name_expanded_cmd,
e961923c 14186 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14187 IP_STR
14188 EXTCOMMUNITY_LIST_STR
5bf15956 14189 "Extended Community list number (expanded)\n"
718e3744 14190 "Specify expanded extcommunity-list\n"
14191 "Extended Community list name\n"
14192 "Specify community to reject\n"
14193 "Specify community to accept\n"
14194 "An ordered list as a regular-expression\n")
14195{
d62a17ae 14196 int style = EXTCOMMUNITY_LIST_EXPANDED;
14197 int direct = 0;
14198 char *cl_number_or_name = NULL;
42f914d4 14199
d62a17ae 14200 int idx = 0;
14201 argv_find(argv, argc, "(100-500)", &idx);
14202 argv_find(argv, argc, "WORD", &idx);
14203 cl_number_or_name = argv[idx]->arg;
14204 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14205 : COMMUNITY_DENY;
14206 argv_find(argv, argc, "LINE", &idx);
14207 char *str = argv_concat(argv, argc, idx);
42f914d4 14208
d62a17ae 14209 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14210 direct, style);
42f914d4 14211
d62a17ae 14212 XFREE(MTYPE_TMP, str);
42f914d4 14213
d62a17ae 14214 if (ret < 0) {
14215 community_list_perror(vty, ret);
14216 return CMD_WARNING_CONFIG_FAILED;
14217 }
42f914d4 14218
d62a17ae 14219 return CMD_SUCCESS;
718e3744 14220}
14221
fee6e4e4 14222DEFUN (no_ip_extcommunity_list_standard_all,
14223 no_ip_extcommunity_list_standard_all_cmd,
e961923c 14224 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
14225 NO_STR
14226 IP_STR
14227 EXTCOMMUNITY_LIST_STR
14228 "Extended Community list number (standard)\n"
718e3744 14229 "Specify standard extcommunity-list\n"
5bf15956 14230 "Community list name\n"
718e3744 14231 "Specify community to reject\n"
14232 "Specify community to accept\n"
14233 EXTCOMMUNITY_VAL_STR)
14234{
d62a17ae 14235 int style = EXTCOMMUNITY_LIST_STANDARD;
14236 int direct = 0;
14237 char *cl_number_or_name = NULL;
42f914d4 14238
d62a17ae 14239 int idx = 0;
14240 argv_find(argv, argc, "(1-99)", &idx);
14241 argv_find(argv, argc, "WORD", &idx);
14242 cl_number_or_name = argv[idx]->arg;
14243 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14244 : COMMUNITY_DENY;
14245 argv_find(argv, argc, "AA:NN", &idx);
14246 char *str = argv_concat(argv, argc, idx);
42f914d4 14247
d62a17ae 14248 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14249 direct, style);
42f914d4 14250
d62a17ae 14251 XFREE(MTYPE_TMP, str);
42f914d4 14252
d62a17ae 14253 if (ret < 0) {
14254 community_list_perror(vty, ret);
14255 return CMD_WARNING_CONFIG_FAILED;
14256 }
42f914d4 14257
d62a17ae 14258 return CMD_SUCCESS;
718e3744 14259}
14260
5bf15956
DW
14261DEFUN (no_ip_extcommunity_list_expanded_all,
14262 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 14263 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14264 NO_STR
14265 IP_STR
14266 EXTCOMMUNITY_LIST_STR
14267 "Extended Community list number (expanded)\n"
718e3744 14268 "Specify expanded extcommunity-list\n"
5bf15956 14269 "Extended Community list name\n"
718e3744 14270 "Specify community to reject\n"
14271 "Specify community to accept\n"
14272 "An ordered list as a regular-expression\n")
14273{
d62a17ae 14274 int style = EXTCOMMUNITY_LIST_EXPANDED;
14275 int direct = 0;
14276 char *cl_number_or_name = NULL;
42f914d4 14277
d62a17ae 14278 int idx = 0;
14279 argv_find(argv, argc, "(100-500)", &idx);
14280 argv_find(argv, argc, "WORD", &idx);
14281 cl_number_or_name = argv[idx]->arg;
14282 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14283 : COMMUNITY_DENY;
14284 argv_find(argv, argc, "LINE", &idx);
14285 char *str = argv_concat(argv, argc, idx);
42f914d4 14286
d62a17ae 14287 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14288 direct, style);
42f914d4 14289
d62a17ae 14290 XFREE(MTYPE_TMP, str);
42f914d4 14291
d62a17ae 14292 if (ret < 0) {
14293 community_list_perror(vty, ret);
14294 return CMD_WARNING_CONFIG_FAILED;
14295 }
42f914d4 14296
d62a17ae 14297 return CMD_SUCCESS;
718e3744 14298}
14299
d62a17ae 14300static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 14301{
d62a17ae 14302 struct community_entry *entry;
718e3744 14303
d62a17ae 14304 for (entry = list->head; entry; entry = entry->next) {
14305 if (entry == list->head) {
14306 if (all_digit(list->name))
14307 vty_out(vty, "Extended community %s list %s\n",
14308 entry->style == EXTCOMMUNITY_LIST_STANDARD
14309 ? "standard"
14310 : "(expanded) access",
14311 list->name);
14312 else
14313 vty_out(vty,
14314 "Named extended community %s list %s\n",
14315 entry->style == EXTCOMMUNITY_LIST_STANDARD
14316 ? "standard"
14317 : "expanded",
14318 list->name);
14319 }
14320 if (entry->any)
14321 vty_out(vty, " %s\n",
14322 community_direct_str(entry->direct));
14323 else
14324 vty_out(vty, " %s %s\n",
14325 community_direct_str(entry->direct),
8d9b8ed9 14326 community_list_config_str(entry));
d62a17ae 14327 }
718e3744 14328}
14329
14330DEFUN (show_ip_extcommunity_list,
14331 show_ip_extcommunity_list_cmd,
14332 "show ip extcommunity-list",
14333 SHOW_STR
14334 IP_STR
14335 "List extended-community list\n")
14336{
d62a17ae 14337 struct community_list *list;
14338 struct community_list_master *cm;
718e3744 14339
d62a17ae 14340 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14341 if (!cm)
14342 return CMD_SUCCESS;
718e3744 14343
d62a17ae 14344 for (list = cm->num.head; list; list = list->next)
14345 extcommunity_list_show(vty, list);
718e3744 14346
d62a17ae 14347 for (list = cm->str.head; list; list = list->next)
14348 extcommunity_list_show(vty, list);
718e3744 14349
d62a17ae 14350 return CMD_SUCCESS;
718e3744 14351}
14352
14353DEFUN (show_ip_extcommunity_list_arg,
14354 show_ip_extcommunity_list_arg_cmd,
6147e2c6 14355 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 14356 SHOW_STR
14357 IP_STR
14358 "List extended-community list\n"
14359 "Extcommunity-list number\n"
14360 "Extcommunity-list name\n")
14361{
d62a17ae 14362 int idx_comm_list = 3;
14363 struct community_list *list;
718e3744 14364
d62a17ae 14365 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14366 EXTCOMMUNITY_LIST_MASTER);
14367 if (!list) {
14368 vty_out(vty, "%% Can't find extcommunity-list\n");
14369 return CMD_WARNING;
14370 }
718e3744 14371
d62a17ae 14372 extcommunity_list_show(vty, list);
718e3744 14373
d62a17ae 14374 return CMD_SUCCESS;
718e3744 14375}
6b0655a2 14376
718e3744 14377/* Display community-list and extcommunity-list configuration. */
d62a17ae 14378static int community_list_config_write(struct vty *vty)
14379{
14380 struct community_list *list;
14381 struct community_entry *entry;
14382 struct community_list_master *cm;
14383 int write = 0;
14384
14385 /* Community-list. */
14386 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14387
14388 for (list = cm->num.head; list; list = list->next)
14389 for (entry = list->head; entry; entry = entry->next) {
14390 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14391 community_direct_str(entry->direct),
14392 community_list_config_str(entry));
14393 write++;
14394 }
14395 for (list = cm->str.head; list; list = list->next)
14396 for (entry = list->head; entry; entry = entry->next) {
14397 vty_out(vty, "ip community-list %s %s %s %s\n",
14398 entry->style == COMMUNITY_LIST_STANDARD
14399 ? "standard"
14400 : "expanded",
14401 list->name, community_direct_str(entry->direct),
14402 community_list_config_str(entry));
14403 write++;
14404 }
14405
14406 /* Extcommunity-list. */
14407 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14408
14409 for (list = cm->num.head; list; list = list->next)
14410 for (entry = list->head; entry; entry = entry->next) {
14411 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14412 list->name, community_direct_str(entry->direct),
14413 community_list_config_str(entry));
14414 write++;
14415 }
14416 for (list = cm->str.head; list; list = list->next)
14417 for (entry = list->head; entry; entry = entry->next) {
14418 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14419 entry->style == EXTCOMMUNITY_LIST_STANDARD
14420 ? "standard"
14421 : "expanded",
14422 list->name, community_direct_str(entry->direct),
14423 community_list_config_str(entry));
14424 write++;
14425 }
14426
14427
14428 /* lcommunity-list. */
14429 cm = community_list_master_lookup(bgp_clist,
14430 LARGE_COMMUNITY_LIST_MASTER);
14431
14432 for (list = cm->num.head; list; list = list->next)
14433 for (entry = list->head; entry; entry = entry->next) {
14434 vty_out(vty, "ip large-community-list %s %s %s\n",
14435 list->name, community_direct_str(entry->direct),
14436 community_list_config_str(entry));
14437 write++;
14438 }
14439 for (list = cm->str.head; list; list = list->next)
14440 for (entry = list->head; entry; entry = entry->next) {
14441 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14442 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14443 ? "standard"
14444 : "expanded",
14445 list->name, community_direct_str(entry->direct),
14446 community_list_config_str(entry));
14447 write++;
14448 }
14449
14450 return write;
14451}
14452
14453static struct cmd_node community_list_node = {
14454 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 14455};
14456
d62a17ae 14457static void community_list_vty(void)
14458{
14459 install_node(&community_list_node, community_list_config_write);
14460
14461 /* Community-list. */
14462 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14463 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14464 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14465 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14466 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14467 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14468
14469 /* Extcommunity-list. */
14470 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14471 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14472 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14473 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14474 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14475 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14476
14477 /* Large Community List */
14478 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14479 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14480 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14481 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14482 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14483 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14484 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14485 install_element(CONFIG_NODE,
14486 &no_ip_lcommunity_list_name_expanded_all_cmd);
14487 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14488 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14489 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14490 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14491 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14492 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 14493}