]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: disallow importing a vrf into itself
[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"
718e3744 37
38#include "bgpd/bgpd.h"
4bf6a362 39#include "bgpd/bgp_advertise.h"
718e3744 40#include "bgpd/bgp_attr.h"
41#include "bgpd/bgp_aspath.h"
42#include "bgpd/bgp_community.h"
4bf6a362 43#include "bgpd/bgp_ecommunity.h"
57d187bc 44#include "bgpd/bgp_lcommunity.h"
4bf6a362 45#include "bgpd/bgp_damp.h"
718e3744 46#include "bgpd/bgp_debug.h"
e0701b79 47#include "bgpd/bgp_fsm.h"
4bf6a362 48#include "bgpd/bgp_nexthop.h"
718e3744 49#include "bgpd/bgp_open.h"
4bf6a362 50#include "bgpd/bgp_regex.h"
718e3744 51#include "bgpd/bgp_route.h"
c016b6c7 52#include "bgpd/bgp_mplsvpn.h"
718e3744 53#include "bgpd/bgp_zebra.h"
fee0f4c6 54#include "bgpd/bgp_table.h"
94f2b392 55#include "bgpd/bgp_vty.h"
165b5fff 56#include "bgpd/bgp_mpath.h"
cb1faec9 57#include "bgpd/bgp_packet.h"
3f9c7369 58#include "bgpd/bgp_updgrp.h"
c43ed2e4 59#include "bgpd/bgp_bfd.h"
555e09d4 60#include "bgpd/bgp_io.h"
94c2f693 61#include "bgpd/bgp_evpn.h"
718e3744 62
d62a17ae 63static struct peer_group *listen_range_exists(struct bgp *bgp,
64 struct prefix *range, int exact);
65
66static enum node_type bgp_node_type(afi_t afi, safi_t safi)
67{
68 switch (afi) {
69 case AFI_IP:
70 switch (safi) {
71 case SAFI_UNICAST:
72 return BGP_IPV4_NODE;
73 break;
74 case SAFI_MULTICAST:
75 return BGP_IPV4M_NODE;
76 break;
77 case SAFI_LABELED_UNICAST:
78 return BGP_IPV4L_NODE;
79 break;
80 case SAFI_MPLS_VPN:
81 return BGP_VPNV4_NODE;
82 break;
7c40bf39 83 case SAFI_FLOWSPEC:
84 return BGP_FLOWSPECV4_NODE;
5c525538
RW
85 default:
86 /* not expected */
87 return BGP_IPV4_NODE;
88 break;
d62a17ae 89 }
90 break;
91 case AFI_IP6:
92 switch (safi) {
93 case SAFI_UNICAST:
94 return BGP_IPV6_NODE;
95 break;
96 case SAFI_MULTICAST:
97 return BGP_IPV6M_NODE;
98 break;
99 case SAFI_LABELED_UNICAST:
100 return BGP_IPV6L_NODE;
101 break;
102 case SAFI_MPLS_VPN:
103 return BGP_VPNV6_NODE;
104 break;
7c40bf39 105 case SAFI_FLOWSPEC:
106 return BGP_FLOWSPECV6_NODE;
5c525538
RW
107 default:
108 /* not expected */
109 return BGP_IPV4_NODE;
110 break;
d62a17ae 111 }
112 break;
113 case AFI_L2VPN:
114 return BGP_EVPN_NODE;
115 break;
116 case AFI_MAX:
117 // We should never be here but to clarify the switch statement..
118 return BGP_IPV4_NODE;
119 break;
120 }
121
122 // Impossible to happen
123 return BGP_IPV4_NODE;
f51bae9c 124}
20eb8864 125
718e3744 126/* Utility function to get address family from current node. */
d62a17ae 127afi_t bgp_node_afi(struct vty *vty)
128{
129 afi_t afi;
130 switch (vty->node) {
131 case BGP_IPV6_NODE:
132 case BGP_IPV6M_NODE:
133 case BGP_IPV6L_NODE:
134 case BGP_VPNV6_NODE:
7c40bf39 135 case BGP_FLOWSPECV6_NODE:
d62a17ae 136 afi = AFI_IP6;
137 break;
138 case BGP_EVPN_NODE:
139 afi = AFI_L2VPN;
140 break;
141 default:
142 afi = AFI_IP;
143 break;
144 }
145 return afi;
718e3744 146}
147
148/* Utility function to get subsequent address family from current
149 node. */
d62a17ae 150safi_t bgp_node_safi(struct vty *vty)
151{
152 safi_t safi;
153 switch (vty->node) {
154 case BGP_VPNV4_NODE:
155 case BGP_VPNV6_NODE:
156 safi = SAFI_MPLS_VPN;
157 break;
158 case BGP_IPV4M_NODE:
159 case BGP_IPV6M_NODE:
160 safi = SAFI_MULTICAST;
161 break;
162 case BGP_EVPN_NODE:
163 safi = SAFI_EVPN;
164 break;
165 case BGP_IPV4L_NODE:
166 case BGP_IPV6L_NODE:
167 safi = SAFI_LABELED_UNICAST;
168 break;
7c40bf39 169 case BGP_FLOWSPECV4_NODE:
170 case BGP_FLOWSPECV6_NODE:
171 safi = SAFI_FLOWSPEC;
172 break;
d62a17ae 173 default:
174 safi = SAFI_UNICAST;
175 break;
176 }
177 return safi;
718e3744 178}
179
55f91488
QY
180/**
181 * Converts an AFI in string form to afi_t
182 *
183 * @param afi string, one of
184 * - "ipv4"
185 * - "ipv6"
186 * @return the corresponding afi_t
187 */
d62a17ae 188afi_t bgp_vty_afi_from_str(const char *afi_str)
189{
190 afi_t afi = AFI_MAX; /* unknown */
191 if (strmatch(afi_str, "ipv4"))
192 afi = AFI_IP;
193 else if (strmatch(afi_str, "ipv6"))
194 afi = AFI_IP6;
195 return afi;
196}
197
198int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
199 afi_t *afi)
200{
201 int ret = 0;
202 if (argv_find(argv, argc, "ipv4", index)) {
203 ret = 1;
204 if (afi)
205 *afi = AFI_IP;
206 } else if (argv_find(argv, argc, "ipv6", index)) {
207 ret = 1;
208 if (afi)
209 *afi = AFI_IP6;
210 }
211 return ret;
46f296b4
LB
212}
213
375a2e67 214/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 215safi_t bgp_vty_safi_from_str(const char *safi_str)
216{
217 safi_t safi = SAFI_MAX; /* unknown */
218 if (strmatch(safi_str, "multicast"))
219 safi = SAFI_MULTICAST;
220 else if (strmatch(safi_str, "unicast"))
221 safi = SAFI_UNICAST;
222 else if (strmatch(safi_str, "vpn"))
223 safi = SAFI_MPLS_VPN;
224 else if (strmatch(safi_str, "labeled-unicast"))
225 safi = SAFI_LABELED_UNICAST;
7c40bf39 226 else if (strmatch(safi_str, "flowspec"))
227 safi = SAFI_FLOWSPEC;
d62a17ae 228 return safi;
229}
230
231int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
232 safi_t *safi)
233{
234 int ret = 0;
235 if (argv_find(argv, argc, "unicast", index)) {
236 ret = 1;
237 if (safi)
238 *safi = SAFI_UNICAST;
239 } else if (argv_find(argv, argc, "multicast", index)) {
240 ret = 1;
241 if (safi)
242 *safi = SAFI_MULTICAST;
243 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
244 ret = 1;
245 if (safi)
246 *safi = SAFI_LABELED_UNICAST;
247 } else if (argv_find(argv, argc, "vpn", index)) {
248 ret = 1;
249 if (safi)
250 *safi = SAFI_MPLS_VPN;
7c40bf39 251 } else if (argv_find(argv, argc, "flowspec", index)) {
252 ret = 1;
253 if (safi)
254 *safi = SAFI_FLOWSPEC;
d62a17ae 255 }
256 return ret;
46f296b4
LB
257}
258
7eeee51e 259/*
f212a857 260 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 261 *
f212a857
DS
262 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
263 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
264 * to appropriate values for the calling function. This is to allow the
265 * calling function to make decisions appropriate for the show command
266 * that is being parsed.
267 *
268 * The show commands are generally of the form:
d62a17ae 269 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
270 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
271 *
272 * Since we use argv_find if the show command in particular doesn't have:
273 * [ip]
18c57037 274 * [<view|vrf> VIEWVRFNAME]
375a2e67 275 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
276 * The command parsing should still be ok.
277 *
278 * vty -> The vty for the command so we can output some useful data in
279 * the event of a parse error in the vrf.
280 * argv -> The command tokens
281 * argc -> How many command tokens we have
d62a17ae 282 * idx -> The current place in the command, generally should be 0 for this
283 * function
7eeee51e
DS
284 * afi -> The parsed afi if it was included in the show command, returned here
285 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 286 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
287 *
288 * The function returns the correct location in the parse tree for the
289 * last token found.
0e37c258
DS
290 *
291 * Returns 0 for failure to parse correctly, else the idx position of where
292 * it found the last token.
7eeee51e 293 */
d62a17ae 294int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
295 struct cmd_token **argv, int argc,
296 int *idx, afi_t *afi, safi_t *safi,
297 struct bgp **bgp)
298{
299 char *vrf_name = NULL;
300
301 assert(afi);
302 assert(safi);
303 assert(bgp);
304
305 if (argv_find(argv, argc, "ip", idx))
306 *afi = AFI_IP;
307
308 if (argv_find(argv, argc, "view", idx)
309 || argv_find(argv, argc, "vrf", idx)) {
310 vrf_name = argv[*idx + 1]->arg;
311
312 if (strmatch(vrf_name, "all"))
313 *bgp = NULL;
314 else {
315 *bgp = bgp_lookup_by_name(vrf_name);
316 if (!*bgp) {
317 vty_out(vty,
318 "View/Vrf specified is unknown: %s\n",
319 vrf_name);
320 *idx = 0;
321 return 0;
322 }
323 }
324 } else {
325 *bgp = bgp_get_default();
326 if (!*bgp) {
327 vty_out(vty, "Unable to find default BGP instance\n");
328 *idx = 0;
329 return 0;
330 }
331 }
332
333 if (argv_find_and_parse_afi(argv, argc, idx, afi))
334 argv_find_and_parse_safi(argv, argc, idx, safi);
335
336 *idx += 1;
337 return *idx;
338}
339
340static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
341{
342 struct interface *ifp = NULL;
343
344 if (su->sa.sa_family == AF_INET)
345 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
346 else if (su->sa.sa_family == AF_INET6)
347 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
348 su->sin6.sin6_scope_id,
349 bgp->vrf_id);
350
351 if (ifp)
352 return 1;
353
354 return 0;
718e3744 355}
356
357/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
358/* This is used only for configuration, so disallow if attempted on
359 * a dynamic neighbor.
360 */
d62a17ae 361static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
362{
363 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
364 int ret;
365 union sockunion su;
366 struct peer *peer;
367
368 if (!bgp) {
369 return NULL;
370 }
371
372 ret = str2sockunion(ip_str, &su);
373 if (ret < 0) {
374 peer = peer_lookup_by_conf_if(bgp, ip_str);
375 if (!peer) {
376 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
377 == NULL) {
378 vty_out(vty,
379 "%% Malformed address or name: %s\n",
380 ip_str);
381 return NULL;
382 }
383 }
384 } else {
385 peer = peer_lookup(bgp, &su);
386 if (!peer) {
387 vty_out(vty,
388 "%% Specify remote-as or peer-group commands first\n");
389 return NULL;
390 }
391 if (peer_dynamic_neighbor(peer)) {
392 vty_out(vty,
393 "%% Operation not allowed on a dynamic neighbor\n");
394 return NULL;
395 }
396 }
397 return peer;
718e3744 398}
399
400/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
401/* This is used only for configuration, so disallow if attempted on
402 * a dynamic neighbor.
403 */
d62a17ae 404struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
405{
406 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
407 int ret;
408 union sockunion su;
409 struct peer *peer = NULL;
410 struct peer_group *group = NULL;
411
412 if (!bgp) {
413 return NULL;
414 }
415
416 ret = str2sockunion(peer_str, &su);
417 if (ret == 0) {
418 /* IP address, locate peer. */
419 peer = peer_lookup(bgp, &su);
420 } else {
421 /* Not IP, could match either peer configured on interface or a
422 * group. */
423 peer = peer_lookup_by_conf_if(bgp, peer_str);
424 if (!peer)
425 group = peer_group_lookup(bgp, peer_str);
426 }
427
428 if (peer) {
429 if (peer_dynamic_neighbor(peer)) {
430 vty_out(vty,
431 "%% Operation not allowed on a dynamic neighbor\n");
432 return NULL;
433 }
434
435 return peer;
436 }
437
438 if (group)
439 return group->conf;
440
441 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
442
443 return NULL;
444}
445
446int bgp_vty_return(struct vty *vty, int ret)
447{
448 const char *str = NULL;
449
450 switch (ret) {
451 case BGP_ERR_INVALID_VALUE:
452 str = "Invalid value";
453 break;
454 case BGP_ERR_INVALID_FLAG:
455 str = "Invalid flag";
456 break;
457 case BGP_ERR_PEER_GROUP_SHUTDOWN:
458 str = "Peer-group has been shutdown. Activate the peer-group first";
459 break;
460 case BGP_ERR_PEER_FLAG_CONFLICT:
461 str = "Can't set override-capability and strict-capability-match at the same time";
462 break;
463 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
464 str = "Specify remote-as or peer-group remote AS first";
465 break;
466 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
467 str = "Cannot change the peer-group. Deconfigure first";
468 break;
469 case BGP_ERR_PEER_GROUP_MISMATCH:
470 str = "Peer is not a member of this peer-group";
471 break;
472 case BGP_ERR_PEER_FILTER_CONFLICT:
473 str = "Prefix/distribute list can not co-exist";
474 break;
475 case BGP_ERR_NOT_INTERNAL_PEER:
476 str = "Invalid command. Not an internal neighbor";
477 break;
478 case BGP_ERR_REMOVE_PRIVATE_AS:
479 str = "remove-private-AS cannot be configured for IBGP peers";
480 break;
481 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
482 str = "Local-AS allowed only for EBGP peers";
483 break;
484 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
485 str = "Cannot have local-as same as BGP AS number";
486 break;
487 case BGP_ERR_TCPSIG_FAILED:
488 str = "Error while applying TCP-Sig to session(s)";
489 break;
490 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
491 str = "ebgp-multihop and ttl-security cannot be configured together";
492 break;
493 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
494 str = "ttl-security only allowed for EBGP peers";
495 break;
496 case BGP_ERR_AS_OVERRIDE:
497 str = "as-override cannot be configured for IBGP peers";
498 break;
499 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
500 str = "Invalid limit for number of dynamic neighbors";
501 break;
502 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
503 str = "Dynamic neighbor listen range already exists";
504 break;
505 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
506 str = "Operation not allowed on a dynamic neighbor";
507 break;
508 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
509 str = "Operation not allowed on a directly connected neighbor";
510 break;
511 case BGP_ERR_PEER_SAFI_CONFLICT:
512 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
513 break;
514 }
515 if (str) {
516 vty_out(vty, "%% %s\n", str);
517 return CMD_WARNING_CONFIG_FAILED;
518 }
519 return CMD_SUCCESS;
718e3744 520}
521
7aafcaca 522/* BGP clear sort. */
d62a17ae 523enum clear_sort {
524 clear_all,
525 clear_peer,
526 clear_group,
527 clear_external,
528 clear_as
7aafcaca
DS
529};
530
d62a17ae 531static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
532 safi_t safi, int error)
533{
534 switch (error) {
535 case BGP_ERR_AF_UNCONFIGURED:
536 vty_out(vty,
537 "%%BGP: Enable %s address family for the neighbor %s\n",
538 afi_safi_print(afi, safi), peer->host);
539 break;
540 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
541 vty_out(vty,
542 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
543 peer->host);
544 break;
545 default:
546 break;
547 }
7aafcaca
DS
548}
549
550/* `clear ip bgp' functions. */
d62a17ae 551static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
552 enum clear_sort sort, enum bgp_clear_type stype,
553 const char *arg)
554{
555 int ret;
556 struct peer *peer;
557 struct listnode *node, *nnode;
558
559 /* Clear all neighbors. */
560 /*
561 * Pass along pointer to next node to peer_clear() when walking all
562 * nodes
563 * on the BGP instance as that may get freed if it is a doppelganger
564 */
565 if (sort == clear_all) {
566 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
567 if (stype == BGP_CLEAR_SOFT_NONE)
568 ret = peer_clear(peer, &nnode);
569 else if (peer->afc[afi][safi])
570 ret = peer_clear_soft(peer, afi, safi, stype);
571 else
572 ret = 0;
573
574 if (ret < 0)
575 bgp_clear_vty_error(vty, peer, afi, safi, ret);
04b6bdc0 576 }
d62a17ae 577
578 /* This is to apply read-only mode on this clear. */
579 if (stype == BGP_CLEAR_SOFT_NONE)
580 bgp->update_delay_over = 0;
581
582 return CMD_SUCCESS;
7aafcaca
DS
583 }
584
d62a17ae 585 /* Clear specified neighbors. */
586 if (sort == clear_peer) {
587 union sockunion su;
588 int ret;
589
590 /* Make sockunion for lookup. */
591 ret = str2sockunion(arg, &su);
592 if (ret < 0) {
593 peer = peer_lookup_by_conf_if(bgp, arg);
594 if (!peer) {
595 peer = peer_lookup_by_hostname(bgp, arg);
596 if (!peer) {
597 vty_out(vty,
598 "Malformed address or name: %s\n",
599 arg);
600 return CMD_WARNING;
601 }
602 }
603 } else {
604 peer = peer_lookup(bgp, &su);
605 if (!peer) {
606 vty_out(vty,
607 "%%BGP: Unknown neighbor - \"%s\"\n",
608 arg);
609 return CMD_WARNING;
610 }
611 }
7aafcaca 612
d62a17ae 613 if (stype == BGP_CLEAR_SOFT_NONE)
614 ret = peer_clear(peer, NULL);
615 else
616 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 617
d62a17ae 618 if (ret < 0)
619 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 620
d62a17ae 621 return CMD_SUCCESS;
7aafcaca 622 }
7aafcaca 623
d62a17ae 624 /* Clear all peer-group members. */
625 if (sort == clear_group) {
626 struct peer_group *group;
7aafcaca 627
d62a17ae 628 group = peer_group_lookup(bgp, arg);
629 if (!group) {
630 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
631 return CMD_WARNING;
632 }
633
634 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
635 if (stype == BGP_CLEAR_SOFT_NONE) {
636 peer_clear(peer, NULL);
637 continue;
638 }
639
640 if (!peer->afc[afi][safi])
641 continue;
642
643 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 644
d62a17ae 645 if (ret < 0)
646 bgp_clear_vty_error(vty, peer, afi, safi, ret);
647 }
648 return CMD_SUCCESS;
7aafcaca 649 }
7aafcaca 650
d62a17ae 651 if (sort == clear_external) {
652 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
653 if (peer->sort == BGP_PEER_IBGP)
654 continue;
7aafcaca 655
d62a17ae 656 if (stype == BGP_CLEAR_SOFT_NONE)
657 ret = peer_clear(peer, &nnode);
658 else
659 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 660
d62a17ae 661 if (ret < 0)
662 bgp_clear_vty_error(vty, peer, afi, safi, ret);
663 }
664 return CMD_SUCCESS;
665 }
666
667 if (sort == clear_as) {
668 as_t as;
669 int find = 0;
670
671 as = strtoul(arg, NULL, 10);
672
673 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
674 if (peer->as != as)
675 continue;
676
677 find = 1;
678 if (stype == BGP_CLEAR_SOFT_NONE)
679 ret = peer_clear(peer, &nnode);
680 else
681 ret = peer_clear_soft(peer, afi, safi, stype);
682
683 if (ret < 0)
684 bgp_clear_vty_error(vty, peer, afi, safi, ret);
685 }
686 if (!find)
687 vty_out(vty,
688 "%%BGP: No peer is configured with AS %s\n",
689 arg);
690 return CMD_SUCCESS;
691 }
692
693 return CMD_SUCCESS;
694}
695
696static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
697 safi_t safi, enum clear_sort sort,
698 enum bgp_clear_type stype, const char *arg)
699{
700 struct bgp *bgp;
701
702 /* BGP structure lookup. */
703 if (name) {
704 bgp = bgp_lookup_by_name(name);
705 if (bgp == NULL) {
706 vty_out(vty, "Can't find BGP instance %s\n", name);
707 return CMD_WARNING;
708 }
709 } else {
710 bgp = bgp_get_default();
711 if (bgp == NULL) {
712 vty_out(vty, "No BGP process is configured\n");
713 return CMD_WARNING;
714 }
715 }
716
717 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
718}
719
720/* clear soft inbound */
d62a17ae 721static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 722{
d62a17ae 723 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
724 BGP_CLEAR_SOFT_IN, NULL);
725 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
726 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
727}
728
729/* clear soft outbound */
d62a17ae 730static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 731{
d62a17ae 732 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
733 BGP_CLEAR_SOFT_OUT, NULL);
734 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
735 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
736}
737
738
f787d7a0 739#ifndef VTYSH_EXTRACT_PL
2e4c2296 740#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
741#endif
742
718e3744 743/* BGP global configuration. */
744
745DEFUN (bgp_multiple_instance_func,
746 bgp_multiple_instance_cmd,
747 "bgp multiple-instance",
748 BGP_STR
749 "Enable bgp multiple instance\n")
750{
d62a17ae 751 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
752 return CMD_SUCCESS;
718e3744 753}
754
755DEFUN (no_bgp_multiple_instance,
756 no_bgp_multiple_instance_cmd,
757 "no bgp multiple-instance",
758 NO_STR
759 BGP_STR
760 "BGP multiple instance\n")
761{
d62a17ae 762 int ret;
718e3744 763
d62a17ae 764 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
765 if (ret < 0) {
766 vty_out(vty, "%% There are more than two BGP instances\n");
767 return CMD_WARNING_CONFIG_FAILED;
768 }
769 return CMD_SUCCESS;
718e3744 770}
771
772DEFUN (bgp_config_type,
773 bgp_config_type_cmd,
6147e2c6 774 "bgp config-type <cisco|zebra>",
718e3744 775 BGP_STR
776 "Configuration type\n"
777 "cisco\n"
778 "zebra\n")
779{
d62a17ae 780 int idx = 0;
781 if (argv_find(argv, argc, "cisco", &idx))
782 bgp_option_set(BGP_OPT_CONFIG_CISCO);
783 else
784 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 785
d62a17ae 786 return CMD_SUCCESS;
718e3744 787}
788
789DEFUN (no_bgp_config_type,
790 no_bgp_config_type_cmd,
c7178fe7 791 "no bgp config-type [<cisco|zebra>]",
718e3744 792 NO_STR
793 BGP_STR
838758ac
DW
794 "Display configuration type\n"
795 "cisco\n"
796 "zebra\n")
718e3744 797{
d62a17ae 798 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
799 return CMD_SUCCESS;
718e3744 800}
801
813d4307 802
718e3744 803DEFUN (no_synchronization,
804 no_synchronization_cmd,
805 "no synchronization",
806 NO_STR
807 "Perform IGP synchronization\n")
808{
d62a17ae 809 return CMD_SUCCESS;
718e3744 810}
811
812DEFUN (no_auto_summary,
813 no_auto_summary_cmd,
814 "no auto-summary",
815 NO_STR
816 "Enable automatic network number summarization\n")
817{
d62a17ae 818 return CMD_SUCCESS;
718e3744 819}
3d515fd9 820
718e3744 821/* "router bgp" commands. */
505e5056 822DEFUN_NOSH (router_bgp,
f412b39a 823 router_bgp_cmd,
18c57037 824 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 825 ROUTER_STR
826 BGP_STR
31500417
DW
827 AS_STR
828 BGP_INSTANCE_HELP_STR)
718e3744 829{
d62a17ae 830 int idx_asn = 2;
831 int idx_view_vrf = 3;
832 int idx_vrf = 4;
833 int ret;
834 as_t as;
835 struct bgp *bgp;
836 const char *name = NULL;
837 enum bgp_instance_type inst_type;
838
839 // "router bgp" without an ASN
840 if (argc == 2) {
841 // Pending: Make VRF option available for ASN less config
842 bgp = bgp_get_default();
843
844 if (bgp == NULL) {
845 vty_out(vty, "%% No BGP process is configured\n");
846 return CMD_WARNING_CONFIG_FAILED;
847 }
848
849 if (listcount(bm->bgp) > 1) {
996c9314 850 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 851 return CMD_WARNING_CONFIG_FAILED;
852 }
853 }
854
855 // "router bgp X"
856 else {
857 as = strtoul(argv[idx_asn]->arg, NULL, 10);
858
859 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
860 if (argc > 3) {
861 name = argv[idx_vrf]->arg;
862
863 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
864 inst_type = BGP_INSTANCE_TYPE_VRF;
865 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
866 inst_type = BGP_INSTANCE_TYPE_VIEW;
867 }
868
869 ret = bgp_get(&bgp, &as, name, inst_type);
870 switch (ret) {
871 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
872 vty_out(vty,
873 "Please specify 'bgp multiple-instance' first\n");
874 return CMD_WARNING_CONFIG_FAILED;
875 case BGP_ERR_AS_MISMATCH:
876 vty_out(vty, "BGP is already running; AS is %u\n", as);
877 return CMD_WARNING_CONFIG_FAILED;
878 case BGP_ERR_INSTANCE_MISMATCH:
879 vty_out(vty,
880 "BGP instance name and AS number mismatch\n");
881 vty_out(vty,
882 "BGP instance is already running; AS is %u\n",
883 as);
884 return CMD_WARNING_CONFIG_FAILED;
885 }
886
887 /* Pending: handle when user tries to change a view to vrf n vv.
888 */
889 }
890
0b5131c9
MK
891 /* unset the auto created flag as the user config is now present */
892 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 893 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
894
895 return CMD_SUCCESS;
718e3744 896}
897
718e3744 898/* "no router bgp" commands. */
899DEFUN (no_router_bgp,
900 no_router_bgp_cmd,
18c57037 901 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 902 NO_STR
903 ROUTER_STR
904 BGP_STR
31500417
DW
905 AS_STR
906 BGP_INSTANCE_HELP_STR)
718e3744 907{
d62a17ae 908 int idx_asn = 3;
909 int idx_vrf = 5;
910 as_t as;
911 struct bgp *bgp;
912 const char *name = NULL;
718e3744 913
d62a17ae 914 // "no router bgp" without an ASN
915 if (argc == 3) {
916 // Pending: Make VRF option available for ASN less config
917 bgp = bgp_get_default();
718e3744 918
d62a17ae 919 if (bgp == NULL) {
920 vty_out(vty, "%% No BGP process is configured\n");
921 return CMD_WARNING_CONFIG_FAILED;
922 }
7fb21a9f 923
d62a17ae 924 if (listcount(bm->bgp) > 1) {
996c9314 925 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 926 return CMD_WARNING_CONFIG_FAILED;
927 }
0b5131c9
MK
928
929 if (bgp->l3vni) {
930 vty_out(vty, "%% Please unconfigure l3vni %u",
931 bgp->l3vni);
932 return CMD_WARNING_CONFIG_FAILED;
933 }
d62a17ae 934 } else {
935 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 936
d62a17ae 937 if (argc > 4)
938 name = argv[idx_vrf]->arg;
7fb21a9f 939
d62a17ae 940 /* Lookup bgp structure. */
941 bgp = bgp_lookup(as, name);
942 if (!bgp) {
943 vty_out(vty, "%% Can't find BGP instance\n");
944 return CMD_WARNING_CONFIG_FAILED;
945 }
0b5131c9
MK
946
947 if (bgp->l3vni) {
948 vty_out(vty, "%% Please unconfigure l3vni %u",
949 bgp->l3vni);
950 return CMD_WARNING_CONFIG_FAILED;
951 }
d62a17ae 952 }
718e3744 953
d62a17ae 954 bgp_delete(bgp);
718e3744 955
d62a17ae 956 return CMD_SUCCESS;
718e3744 957}
958
6b0655a2 959
718e3744 960/* BGP router-id. */
961
f787d7a0 962DEFPY (bgp_router_id,
718e3744 963 bgp_router_id_cmd,
964 "bgp router-id A.B.C.D",
965 BGP_STR
966 "Override configured router identifier\n"
967 "Manually configured router identifier\n")
968{
d62a17ae 969 VTY_DECLVAR_CONTEXT(bgp, bgp);
970 bgp_router_id_static_set(bgp, router_id);
971 return CMD_SUCCESS;
718e3744 972}
973
f787d7a0 974DEFPY (no_bgp_router_id,
718e3744 975 no_bgp_router_id_cmd,
31500417 976 "no bgp router-id [A.B.C.D]",
718e3744 977 NO_STR
978 BGP_STR
31500417
DW
979 "Override configured router identifier\n"
980 "Manually configured router identifier\n")
718e3744 981{
d62a17ae 982 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 983
d62a17ae 984 if (router_id_str) {
985 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
986 vty_out(vty, "%% BGP router-id doesn't match\n");
987 return CMD_WARNING_CONFIG_FAILED;
988 }
e018c7cc 989 }
718e3744 990
d62a17ae 991 router_id.s_addr = 0;
992 bgp_router_id_static_set(bgp, router_id);
718e3744 993
d62a17ae 994 return CMD_SUCCESS;
718e3744 995}
996
6b0655a2 997
718e3744 998/* BGP Cluster ID. */
718e3744 999DEFUN (bgp_cluster_id,
1000 bgp_cluster_id_cmd,
838758ac 1001 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1002 BGP_STR
1003 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1004 "Route-Reflector Cluster-id in IP address format\n"
1005 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1006{
d62a17ae 1007 VTY_DECLVAR_CONTEXT(bgp, bgp);
1008 int idx_ipv4 = 2;
1009 int ret;
1010 struct in_addr cluster;
718e3744 1011
d62a17ae 1012 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1013 if (!ret) {
1014 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1015 return CMD_WARNING_CONFIG_FAILED;
1016 }
718e3744 1017
d62a17ae 1018 bgp_cluster_id_set(bgp, &cluster);
1019 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1020
d62a17ae 1021 return CMD_SUCCESS;
718e3744 1022}
1023
718e3744 1024DEFUN (no_bgp_cluster_id,
1025 no_bgp_cluster_id_cmd,
c7178fe7 1026 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1027 NO_STR
1028 BGP_STR
838758ac
DW
1029 "Configure Route-Reflector Cluster-id\n"
1030 "Route-Reflector Cluster-id in IP address format\n"
1031 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1032{
d62a17ae 1033 VTY_DECLVAR_CONTEXT(bgp, bgp);
1034 bgp_cluster_id_unset(bgp);
1035 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1036
d62a17ae 1037 return CMD_SUCCESS;
718e3744 1038}
1039
718e3744 1040DEFUN (bgp_confederation_identifier,
1041 bgp_confederation_identifier_cmd,
9ccf14f7 1042 "bgp confederation identifier (1-4294967295)",
718e3744 1043 "BGP specific commands\n"
1044 "AS confederation parameters\n"
1045 "AS number\n"
1046 "Set routing domain confederation AS\n")
1047{
d62a17ae 1048 VTY_DECLVAR_CONTEXT(bgp, bgp);
1049 int idx_number = 3;
1050 as_t as;
718e3744 1051
d62a17ae 1052 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1053
d62a17ae 1054 bgp_confederation_id_set(bgp, as);
718e3744 1055
d62a17ae 1056 return CMD_SUCCESS;
718e3744 1057}
1058
1059DEFUN (no_bgp_confederation_identifier,
1060 no_bgp_confederation_identifier_cmd,
838758ac 1061 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1062 NO_STR
1063 "BGP specific commands\n"
1064 "AS confederation parameters\n"
3a2d747c
QY
1065 "AS number\n"
1066 "Set routing domain confederation AS\n")
718e3744 1067{
d62a17ae 1068 VTY_DECLVAR_CONTEXT(bgp, bgp);
1069 bgp_confederation_id_unset(bgp);
718e3744 1070
d62a17ae 1071 return CMD_SUCCESS;
718e3744 1072}
1073
718e3744 1074DEFUN (bgp_confederation_peers,
1075 bgp_confederation_peers_cmd,
12dcf78e 1076 "bgp confederation peers (1-4294967295)...",
718e3744 1077 "BGP specific commands\n"
1078 "AS confederation parameters\n"
1079 "Peer ASs in BGP confederation\n"
1080 AS_STR)
1081{
d62a17ae 1082 VTY_DECLVAR_CONTEXT(bgp, bgp);
1083 int idx_asn = 3;
1084 as_t as;
1085 int i;
718e3744 1086
d62a17ae 1087 for (i = idx_asn; i < argc; i++) {
1088 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1089
d62a17ae 1090 if (bgp->as == as) {
1091 vty_out(vty,
1092 "%% Local member-AS not allowed in confed peer list\n");
1093 continue;
1094 }
718e3744 1095
d62a17ae 1096 bgp_confederation_peers_add(bgp, as);
1097 }
1098 return CMD_SUCCESS;
718e3744 1099}
1100
1101DEFUN (no_bgp_confederation_peers,
1102 no_bgp_confederation_peers_cmd,
e83a9414 1103 "no bgp confederation peers (1-4294967295)...",
718e3744 1104 NO_STR
1105 "BGP specific commands\n"
1106 "AS confederation parameters\n"
1107 "Peer ASs in BGP confederation\n"
1108 AS_STR)
1109{
d62a17ae 1110 VTY_DECLVAR_CONTEXT(bgp, bgp);
1111 int idx_asn = 4;
1112 as_t as;
1113 int i;
718e3744 1114
d62a17ae 1115 for (i = idx_asn; i < argc; i++) {
1116 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1117
d62a17ae 1118 bgp_confederation_peers_remove(bgp, as);
1119 }
1120 return CMD_SUCCESS;
718e3744 1121}
6b0655a2 1122
5e242b0d
DS
1123/**
1124 * Central routine for maximum-paths configuration.
1125 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1126 * @set: 1 for setting values, 0 for removing the max-paths config.
1127 */
d62a17ae 1128static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1129 const char *mpaths, uint16_t options,
d62a17ae 1130 int set)
1131{
1132 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1133 uint16_t maxpaths = 0;
d62a17ae 1134 int ret;
1135 afi_t afi;
1136 safi_t safi;
1137
1138 afi = bgp_node_afi(vty);
1139 safi = bgp_node_safi(vty);
1140
1141 if (set) {
1142 maxpaths = strtol(mpaths, NULL, 10);
1143 if (maxpaths > multipath_num) {
1144 vty_out(vty,
1145 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1146 maxpaths, multipath_num);
1147 return CMD_WARNING_CONFIG_FAILED;
1148 }
1149 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1150 options);
1151 } else
1152 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1153
1154 if (ret < 0) {
1155 vty_out(vty,
1156 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1157 (set == 1) ? "" : "un",
1158 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1159 maxpaths, afi, safi);
1160 return CMD_WARNING_CONFIG_FAILED;
1161 }
1162
1163 bgp_recalculate_all_bestpaths(bgp);
1164
1165 return CMD_SUCCESS;
165b5fff
JB
1166}
1167
abc920f8
DS
1168DEFUN (bgp_maxmed_admin,
1169 bgp_maxmed_admin_cmd,
1170 "bgp max-med administrative ",
1171 BGP_STR
1172 "Advertise routes with max-med\n"
1173 "Administratively applied, for an indefinite period\n")
1174{
d62a17ae 1175 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1176
d62a17ae 1177 bgp->v_maxmed_admin = 1;
1178 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1179
d62a17ae 1180 bgp_maxmed_update(bgp);
abc920f8 1181
d62a17ae 1182 return CMD_SUCCESS;
abc920f8
DS
1183}
1184
1185DEFUN (bgp_maxmed_admin_medv,
1186 bgp_maxmed_admin_medv_cmd,
4668a151 1187 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1188 BGP_STR
1189 "Advertise routes with max-med\n"
1190 "Administratively applied, for an indefinite period\n"
1191 "Max MED value to be used\n")
1192{
d62a17ae 1193 VTY_DECLVAR_CONTEXT(bgp, bgp);
1194 int idx_number = 3;
abc920f8 1195
d62a17ae 1196 bgp->v_maxmed_admin = 1;
1197 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1198
d62a17ae 1199 bgp_maxmed_update(bgp);
abc920f8 1200
d62a17ae 1201 return CMD_SUCCESS;
abc920f8
DS
1202}
1203
1204DEFUN (no_bgp_maxmed_admin,
1205 no_bgp_maxmed_admin_cmd,
4668a151 1206 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1207 NO_STR
1208 BGP_STR
1209 "Advertise routes with max-med\n"
838758ac
DW
1210 "Administratively applied, for an indefinite period\n"
1211 "Max MED value to be used\n")
abc920f8 1212{
d62a17ae 1213 VTY_DECLVAR_CONTEXT(bgp, bgp);
1214 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1215 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1216 bgp_maxmed_update(bgp);
abc920f8 1217
d62a17ae 1218 return CMD_SUCCESS;
abc920f8
DS
1219}
1220
abc920f8
DS
1221DEFUN (bgp_maxmed_onstartup,
1222 bgp_maxmed_onstartup_cmd,
4668a151 1223 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1224 BGP_STR
1225 "Advertise routes with max-med\n"
1226 "Effective on a startup\n"
1227 "Time (seconds) period for max-med\n"
1228 "Max MED value to be used\n")
1229{
d62a17ae 1230 VTY_DECLVAR_CONTEXT(bgp, bgp);
1231 int idx = 0;
4668a151 1232
d62a17ae 1233 argv_find(argv, argc, "(5-86400)", &idx);
1234 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1235 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1236 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1237 else
1238 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1239
d62a17ae 1240 bgp_maxmed_update(bgp);
abc920f8 1241
d62a17ae 1242 return CMD_SUCCESS;
abc920f8
DS
1243}
1244
1245DEFUN (no_bgp_maxmed_onstartup,
1246 no_bgp_maxmed_onstartup_cmd,
4668a151 1247 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1248 NO_STR
1249 BGP_STR
1250 "Advertise routes with max-med\n"
838758ac
DW
1251 "Effective on a startup\n"
1252 "Time (seconds) period for max-med\n"
1253 "Max MED value to be used\n")
abc920f8 1254{
d62a17ae 1255 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1256
d62a17ae 1257 /* Cancel max-med onstartup if its on */
1258 if (bgp->t_maxmed_onstartup) {
1259 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1260 bgp->maxmed_onstartup_over = 1;
1261 }
abc920f8 1262
d62a17ae 1263 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1264 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1265
d62a17ae 1266 bgp_maxmed_update(bgp);
abc920f8 1267
d62a17ae 1268 return CMD_SUCCESS;
abc920f8
DS
1269}
1270
d62a17ae 1271static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1272 const char *wait)
f188f2c4 1273{
d62a17ae 1274 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1275 uint16_t update_delay;
1276 uint16_t establish_wait;
f188f2c4 1277
d62a17ae 1278 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1279
d62a17ae 1280 if (!wait) /* update-delay <delay> */
1281 {
1282 bgp->v_update_delay = update_delay;
1283 bgp->v_establish_wait = bgp->v_update_delay;
1284 return CMD_SUCCESS;
1285 }
f188f2c4 1286
d62a17ae 1287 /* update-delay <delay> <establish-wait> */
1288 establish_wait = atoi(wait);
1289 if (update_delay < establish_wait) {
1290 vty_out(vty,
1291 "%%Failed: update-delay less than the establish-wait!\n");
1292 return CMD_WARNING_CONFIG_FAILED;
1293 }
f188f2c4 1294
d62a17ae 1295 bgp->v_update_delay = update_delay;
1296 bgp->v_establish_wait = establish_wait;
f188f2c4 1297
d62a17ae 1298 return CMD_SUCCESS;
f188f2c4
DS
1299}
1300
d62a17ae 1301static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1302{
d62a17ae 1303 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1304
d62a17ae 1305 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1306 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1307
d62a17ae 1308 return CMD_SUCCESS;
f188f2c4
DS
1309}
1310
2b791107 1311void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1312{
d62a17ae 1313 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1314 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1315 if (bgp->v_update_delay != bgp->v_establish_wait)
1316 vty_out(vty, " %d", bgp->v_establish_wait);
1317 vty_out(vty, "\n");
1318 }
f188f2c4
DS
1319}
1320
1321
1322/* Update-delay configuration */
1323DEFUN (bgp_update_delay,
1324 bgp_update_delay_cmd,
6147e2c6 1325 "update-delay (0-3600)",
f188f2c4
DS
1326 "Force initial delay for best-path and updates\n"
1327 "Seconds\n")
1328{
d62a17ae 1329 int idx_number = 1;
1330 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1331}
1332
1333DEFUN (bgp_update_delay_establish_wait,
1334 bgp_update_delay_establish_wait_cmd,
6147e2c6 1335 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1336 "Force initial delay for best-path and updates\n"
1337 "Seconds\n"
f188f2c4
DS
1338 "Seconds\n")
1339{
d62a17ae 1340 int idx_number = 1;
1341 int idx_number_2 = 2;
1342 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1343 argv[idx_number_2]->arg);
f188f2c4
DS
1344}
1345
1346/* Update-delay deconfiguration */
1347DEFUN (no_bgp_update_delay,
1348 no_bgp_update_delay_cmd,
838758ac
DW
1349 "no update-delay [(0-3600) [(1-3600)]]",
1350 NO_STR
f188f2c4 1351 "Force initial delay for best-path and updates\n"
838758ac 1352 "Seconds\n"
7111c1a0 1353 "Seconds\n")
f188f2c4 1354{
d62a17ae 1355 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1356}
1357
5e242b0d 1358
d62a17ae 1359static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1360 char set)
cb1faec9 1361{
d62a17ae 1362 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1363
555e09d4
QY
1364 if (set) {
1365 uint32_t quanta = strtoul(num, NULL, 10);
1366 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1367 memory_order_relaxed);
1368 } else {
1369 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1370 memory_order_relaxed);
1371 }
1372
1373 return CMD_SUCCESS;
1374}
1375
1376static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1377 char set)
1378{
1379 VTY_DECLVAR_CONTEXT(bgp, bgp);
1380
1381 if (set) {
1382 uint32_t quanta = strtoul(num, NULL, 10);
1383 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1384 memory_order_relaxed);
1385 } else {
1386 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1387 memory_order_relaxed);
1388 }
cb1faec9 1389
d62a17ae 1390 return CMD_SUCCESS;
cb1faec9
DS
1391}
1392
2b791107 1393void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1394{
555e09d4
QY
1395 uint32_t quanta =
1396 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1397 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1398 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1399}
1400
555e09d4
QY
1401void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1402{
1403 uint32_t quanta =
1404 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1405 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1406 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1407}
cb1faec9 1408
555e09d4 1409/* Packet quanta configuration */
cb1faec9
DS
1410DEFUN (bgp_wpkt_quanta,
1411 bgp_wpkt_quanta_cmd,
555e09d4 1412 "write-quanta (1-10)",
cb1faec9
DS
1413 "How many packets to write to peer socket per run\n"
1414 "Number of packets\n")
1415{
d62a17ae 1416 int idx_number = 1;
1417 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1418}
1419
cb1faec9
DS
1420DEFUN (no_bgp_wpkt_quanta,
1421 no_bgp_wpkt_quanta_cmd,
555e09d4 1422 "no write-quanta (1-10)",
d7fa34c1 1423 NO_STR
555e09d4 1424 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1425 "Number of packets\n")
1426{
d62a17ae 1427 int idx_number = 2;
1428 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1429}
1430
555e09d4
QY
1431DEFUN (bgp_rpkt_quanta,
1432 bgp_rpkt_quanta_cmd,
1433 "read-quanta (1-10)",
1434 "How many packets to read from peer socket per I/O cycle\n"
1435 "Number of packets\n")
1436{
1437 int idx_number = 1;
1438 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1439}
1440
1441DEFUN (no_bgp_rpkt_quanta,
1442 no_bgp_rpkt_quanta_cmd,
1443 "no read-quanta (1-10)",
1444 NO_STR
1445 "How many packets to read from peer socket per I/O cycle\n"
1446 "Number of packets\n")
1447{
1448 int idx_number = 2;
1449 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1450}
1451
2b791107 1452void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1453{
37a333fe 1454 if (!bgp->heuristic_coalesce)
d62a17ae 1455 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1456}
1457
1458
1459DEFUN (bgp_coalesce_time,
1460 bgp_coalesce_time_cmd,
6147e2c6 1461 "coalesce-time (0-4294967295)",
3f9c7369
DS
1462 "Subgroup coalesce timer\n"
1463 "Subgroup coalesce timer value (in ms)\n")
1464{
d62a17ae 1465 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1466
d62a17ae 1467 int idx = 0;
1468 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1469 bgp->heuristic_coalesce = false;
d62a17ae 1470 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1471 return CMD_SUCCESS;
3f9c7369
DS
1472}
1473
1474DEFUN (no_bgp_coalesce_time,
1475 no_bgp_coalesce_time_cmd,
6147e2c6 1476 "no coalesce-time (0-4294967295)",
3a2d747c 1477 NO_STR
3f9c7369
DS
1478 "Subgroup coalesce timer\n"
1479 "Subgroup coalesce timer value (in ms)\n")
1480{
d62a17ae 1481 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1482
37a333fe 1483 bgp->heuristic_coalesce = true;
d62a17ae 1484 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1485 return CMD_SUCCESS;
3f9c7369
DS
1486}
1487
5e242b0d
DS
1488/* Maximum-paths configuration */
1489DEFUN (bgp_maxpaths,
1490 bgp_maxpaths_cmd,
6319fd63 1491 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1492 "Forward packets over multiple paths\n"
1493 "Number of paths\n")
1494{
d62a17ae 1495 int idx_number = 1;
1496 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1497 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1498}
1499
d62a17ae 1500ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1501 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1502 "Forward packets over multiple paths\n"
1503 "Number of paths\n")
596c17ba 1504
165b5fff
JB
1505DEFUN (bgp_maxpaths_ibgp,
1506 bgp_maxpaths_ibgp_cmd,
6319fd63 1507 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1508 "Forward packets over multiple paths\n"
1509 "iBGP-multipath\n"
1510 "Number of paths\n")
1511{
d62a17ae 1512 int idx_number = 2;
1513 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1514 argv[idx_number]->arg, 0, 1);
5e242b0d 1515}
165b5fff 1516
d62a17ae 1517ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1518 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1519 "Forward packets over multiple paths\n"
1520 "iBGP-multipath\n"
1521 "Number of paths\n")
596c17ba 1522
5e242b0d
DS
1523DEFUN (bgp_maxpaths_ibgp_cluster,
1524 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1525 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1526 "Forward packets over multiple paths\n"
1527 "iBGP-multipath\n"
1528 "Number of paths\n"
1529 "Match the cluster length\n")
1530{
d62a17ae 1531 int idx_number = 2;
1532 return bgp_maxpaths_config_vty(
1533 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1534 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1535}
1536
d62a17ae 1537ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1538 "maximum-paths ibgp " CMD_RANGE_STR(
1539 1, MULTIPATH_NUM) " equal-cluster-length",
1540 "Forward packets over multiple paths\n"
1541 "iBGP-multipath\n"
1542 "Number of paths\n"
1543 "Match the cluster length\n")
596c17ba 1544
165b5fff
JB
1545DEFUN (no_bgp_maxpaths,
1546 no_bgp_maxpaths_cmd,
6319fd63 1547 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1548 NO_STR
1549 "Forward packets over multiple paths\n"
1550 "Number of paths\n")
1551{
d62a17ae 1552 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1553}
1554
d62a17ae 1555ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1556 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1557 "Forward packets over multiple paths\n"
1558 "Number of paths\n")
596c17ba 1559
165b5fff
JB
1560DEFUN (no_bgp_maxpaths_ibgp,
1561 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1562 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1563 NO_STR
1564 "Forward packets over multiple paths\n"
1565 "iBGP-multipath\n"
838758ac
DW
1566 "Number of paths\n"
1567 "Match the cluster length\n")
165b5fff 1568{
d62a17ae 1569 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1570}
1571
d62a17ae 1572ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1573 "no maximum-paths ibgp [" CMD_RANGE_STR(
1574 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1575 NO_STR
1576 "Forward packets over multiple paths\n"
1577 "iBGP-multipath\n"
1578 "Number of paths\n"
1579 "Match the cluster length\n")
596c17ba 1580
2b791107 1581void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1582 safi_t safi)
165b5fff 1583{
d62a17ae 1584 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1585 vty_out(vty, " maximum-paths %d\n",
1586 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1587 }
165b5fff 1588
d62a17ae 1589 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1590 vty_out(vty, " maximum-paths ibgp %d",
1591 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1592 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1593 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1594 vty_out(vty, " equal-cluster-length");
1595 vty_out(vty, "\n");
1596 }
165b5fff 1597}
6b0655a2 1598
718e3744 1599/* BGP timers. */
1600
1601DEFUN (bgp_timers,
1602 bgp_timers_cmd,
6147e2c6 1603 "timers bgp (0-65535) (0-65535)",
718e3744 1604 "Adjust routing timers\n"
1605 "BGP timers\n"
1606 "Keepalive interval\n"
1607 "Holdtime\n")
1608{
d62a17ae 1609 VTY_DECLVAR_CONTEXT(bgp, bgp);
1610 int idx_number = 2;
1611 int idx_number_2 = 3;
1612 unsigned long keepalive = 0;
1613 unsigned long holdtime = 0;
718e3744 1614
d62a17ae 1615 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1616 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1617
d62a17ae 1618 /* Holdtime value check. */
1619 if (holdtime < 3 && holdtime != 0) {
1620 vty_out(vty,
1621 "%% hold time value must be either 0 or greater than 3\n");
1622 return CMD_WARNING_CONFIG_FAILED;
1623 }
718e3744 1624
d62a17ae 1625 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1626
d62a17ae 1627 return CMD_SUCCESS;
718e3744 1628}
1629
1630DEFUN (no_bgp_timers,
1631 no_bgp_timers_cmd,
838758ac 1632 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1633 NO_STR
1634 "Adjust routing timers\n"
838758ac
DW
1635 "BGP timers\n"
1636 "Keepalive interval\n"
1637 "Holdtime\n")
718e3744 1638{
d62a17ae 1639 VTY_DECLVAR_CONTEXT(bgp, bgp);
1640 bgp_timers_unset(bgp);
718e3744 1641
d62a17ae 1642 return CMD_SUCCESS;
718e3744 1643}
1644
6b0655a2 1645
718e3744 1646DEFUN (bgp_client_to_client_reflection,
1647 bgp_client_to_client_reflection_cmd,
1648 "bgp client-to-client reflection",
1649 "BGP specific commands\n"
1650 "Configure client to client route reflection\n"
1651 "reflection of routes allowed\n")
1652{
d62a17ae 1653 VTY_DECLVAR_CONTEXT(bgp, bgp);
1654 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1655 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1656
d62a17ae 1657 return CMD_SUCCESS;
718e3744 1658}
1659
1660DEFUN (no_bgp_client_to_client_reflection,
1661 no_bgp_client_to_client_reflection_cmd,
1662 "no bgp client-to-client reflection",
1663 NO_STR
1664 "BGP specific commands\n"
1665 "Configure client to client route reflection\n"
1666 "reflection of routes allowed\n")
1667{
d62a17ae 1668 VTY_DECLVAR_CONTEXT(bgp, bgp);
1669 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1670 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1671
d62a17ae 1672 return CMD_SUCCESS;
718e3744 1673}
1674
1675/* "bgp always-compare-med" configuration. */
1676DEFUN (bgp_always_compare_med,
1677 bgp_always_compare_med_cmd,
1678 "bgp always-compare-med",
1679 "BGP specific commands\n"
1680 "Allow comparing MED from different neighbors\n")
1681{
d62a17ae 1682 VTY_DECLVAR_CONTEXT(bgp, bgp);
1683 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1684 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1685
d62a17ae 1686 return CMD_SUCCESS;
718e3744 1687}
1688
1689DEFUN (no_bgp_always_compare_med,
1690 no_bgp_always_compare_med_cmd,
1691 "no bgp always-compare-med",
1692 NO_STR
1693 "BGP specific commands\n"
1694 "Allow comparing MED from different neighbors\n")
1695{
d62a17ae 1696 VTY_DECLVAR_CONTEXT(bgp, bgp);
1697 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1698 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1699
d62a17ae 1700 return CMD_SUCCESS;
718e3744 1701}
6b0655a2 1702
718e3744 1703/* "bgp deterministic-med" configuration. */
1704DEFUN (bgp_deterministic_med,
1705 bgp_deterministic_med_cmd,
1706 "bgp deterministic-med",
1707 "BGP specific commands\n"
1708 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1709{
d62a17ae 1710 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1711
d62a17ae 1712 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1713 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1714 bgp_recalculate_all_bestpaths(bgp);
1715 }
7aafcaca 1716
d62a17ae 1717 return CMD_SUCCESS;
718e3744 1718}
1719
1720DEFUN (no_bgp_deterministic_med,
1721 no_bgp_deterministic_med_cmd,
1722 "no bgp deterministic-med",
1723 NO_STR
1724 "BGP specific commands\n"
1725 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1726{
d62a17ae 1727 VTY_DECLVAR_CONTEXT(bgp, bgp);
1728 int bestpath_per_as_used;
1729 afi_t afi;
1730 safi_t safi;
1731 struct peer *peer;
1732 struct listnode *node, *nnode;
1733
1734 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1735 bestpath_per_as_used = 0;
1736
1737 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc
QY
1738 FOREACH_AFI_SAFI (afi, safi)
1739 if (CHECK_FLAG(
1740 peer->af_flags[afi][safi],
1741 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1742 bestpath_per_as_used = 1;
1743 break;
1744 }
d62a17ae 1745
1746 if (bestpath_per_as_used)
1747 break;
1748 }
1749
1750 if (bestpath_per_as_used) {
1751 vty_out(vty,
1752 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1753 return CMD_WARNING_CONFIG_FAILED;
1754 } else {
1755 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1756 bgp_recalculate_all_bestpaths(bgp);
1757 }
1758 }
1759
1760 return CMD_SUCCESS;
718e3744 1761}
538621f2 1762
1763/* "bgp graceful-restart" configuration. */
1764DEFUN (bgp_graceful_restart,
1765 bgp_graceful_restart_cmd,
1766 "bgp graceful-restart",
1767 "BGP specific commands\n"
1768 "Graceful restart capability parameters\n")
1769{
d62a17ae 1770 VTY_DECLVAR_CONTEXT(bgp, bgp);
1771 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1772 return CMD_SUCCESS;
538621f2 1773}
1774
1775DEFUN (no_bgp_graceful_restart,
1776 no_bgp_graceful_restart_cmd,
1777 "no bgp graceful-restart",
1778 NO_STR
1779 "BGP specific commands\n"
1780 "Graceful restart capability parameters\n")
1781{
d62a17ae 1782 VTY_DECLVAR_CONTEXT(bgp, bgp);
1783 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1784 return CMD_SUCCESS;
538621f2 1785}
1786
93406d87 1787DEFUN (bgp_graceful_restart_stalepath_time,
1788 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1789 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1790 "BGP specific commands\n"
1791 "Graceful restart capability parameters\n"
1792 "Set the max time to hold onto restarting peer's stale paths\n"
1793 "Delay value (seconds)\n")
1794{
d62a17ae 1795 VTY_DECLVAR_CONTEXT(bgp, bgp);
1796 int idx_number = 3;
d7c0a89a 1797 uint32_t stalepath;
93406d87 1798
d62a17ae 1799 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1800 bgp->stalepath_time = stalepath;
1801 return CMD_SUCCESS;
93406d87 1802}
1803
eb6f1b41
PG
1804DEFUN (bgp_graceful_restart_restart_time,
1805 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1806 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1807 "BGP specific commands\n"
1808 "Graceful restart capability parameters\n"
1809 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1810 "Delay value (seconds)\n")
1811{
d62a17ae 1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
1813 int idx_number = 3;
d7c0a89a 1814 uint32_t restart;
eb6f1b41 1815
d62a17ae 1816 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1817 bgp->restart_time = restart;
1818 return CMD_SUCCESS;
eb6f1b41
PG
1819}
1820
93406d87 1821DEFUN (no_bgp_graceful_restart_stalepath_time,
1822 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1823 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1824 NO_STR
1825 "BGP specific commands\n"
1826 "Graceful restart capability parameters\n"
838758ac
DW
1827 "Set the max time to hold onto restarting peer's stale paths\n"
1828 "Delay value (seconds)\n")
93406d87 1829{
d62a17ae 1830 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1831
d62a17ae 1832 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1833 return CMD_SUCCESS;
93406d87 1834}
1835
eb6f1b41
PG
1836DEFUN (no_bgp_graceful_restart_restart_time,
1837 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1838 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1839 NO_STR
1840 "BGP specific commands\n"
1841 "Graceful restart capability parameters\n"
838758ac
DW
1842 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1843 "Delay value (seconds)\n")
eb6f1b41 1844{
d62a17ae 1845 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1846
d62a17ae 1847 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1848 return CMD_SUCCESS;
eb6f1b41
PG
1849}
1850
43fc21b3
JC
1851DEFUN (bgp_graceful_restart_preserve_fw,
1852 bgp_graceful_restart_preserve_fw_cmd,
1853 "bgp graceful-restart preserve-fw-state",
1854 "BGP specific commands\n"
1855 "Graceful restart capability parameters\n"
1856 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1857{
d62a17ae 1858 VTY_DECLVAR_CONTEXT(bgp, bgp);
1859 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1860 return CMD_SUCCESS;
43fc21b3
JC
1861}
1862
1863DEFUN (no_bgp_graceful_restart_preserve_fw,
1864 no_bgp_graceful_restart_preserve_fw_cmd,
1865 "no bgp graceful-restart preserve-fw-state",
1866 NO_STR
1867 "BGP specific commands\n"
1868 "Graceful restart capability parameters\n"
1869 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1870{
d62a17ae 1871 VTY_DECLVAR_CONTEXT(bgp, bgp);
1872 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1873 return CMD_SUCCESS;
43fc21b3
JC
1874}
1875
7f323236
DW
1876static void bgp_redistribute_redo(struct bgp *bgp)
1877{
1878 afi_t afi;
1879 int i;
1880 struct list *red_list;
1881 struct listnode *node;
1882 struct bgp_redist *red;
1883
a4d82a8a
PZ
1884 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1885 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 1886
a4d82a8a
PZ
1887 red_list = bgp->redist[afi][i];
1888 if (!red_list)
1889 continue;
7f323236 1890
a4d82a8a 1891 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
1892 bgp_redistribute_resend(bgp, afi, i,
1893 red->instance);
1894 }
1895 }
1896 }
1897}
1898
1899/* "bgp graceful-shutdown" configuration */
1900DEFUN (bgp_graceful_shutdown,
1901 bgp_graceful_shutdown_cmd,
1902 "bgp graceful-shutdown",
1903 BGP_STR
1904 "Graceful shutdown parameters\n")
1905{
1906 VTY_DECLVAR_CONTEXT(bgp, bgp);
1907
1908 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1909 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1910 bgp_static_redo_import_check(bgp);
1911 bgp_redistribute_redo(bgp);
1912 bgp_clear_star_soft_out(vty, bgp->name);
1913 bgp_clear_star_soft_in(vty, bgp->name);
1914 }
1915
1916 return CMD_SUCCESS;
1917}
1918
1919DEFUN (no_bgp_graceful_shutdown,
1920 no_bgp_graceful_shutdown_cmd,
1921 "no bgp graceful-shutdown",
1922 NO_STR
1923 BGP_STR
1924 "Graceful shutdown parameters\n")
1925{
1926 VTY_DECLVAR_CONTEXT(bgp, bgp);
1927
1928 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1929 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1930 bgp_static_redo_import_check(bgp);
1931 bgp_redistribute_redo(bgp);
1932 bgp_clear_star_soft_out(vty, bgp->name);
1933 bgp_clear_star_soft_in(vty, bgp->name);
1934 }
1935
1936 return CMD_SUCCESS;
1937}
1938
718e3744 1939/* "bgp fast-external-failover" configuration. */
1940DEFUN (bgp_fast_external_failover,
1941 bgp_fast_external_failover_cmd,
1942 "bgp fast-external-failover",
1943 BGP_STR
1944 "Immediately reset session if a link to a directly connected external peer goes down\n")
1945{
d62a17ae 1946 VTY_DECLVAR_CONTEXT(bgp, bgp);
1947 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1948 return CMD_SUCCESS;
718e3744 1949}
1950
1951DEFUN (no_bgp_fast_external_failover,
1952 no_bgp_fast_external_failover_cmd,
1953 "no bgp fast-external-failover",
1954 NO_STR
1955 BGP_STR
1956 "Immediately reset session if a link to a directly connected external peer goes down\n")
1957{
d62a17ae 1958 VTY_DECLVAR_CONTEXT(bgp, bgp);
1959 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1960 return CMD_SUCCESS;
718e3744 1961}
6b0655a2 1962
718e3744 1963/* "bgp enforce-first-as" configuration. */
1964DEFUN (bgp_enforce_first_as,
1965 bgp_enforce_first_as_cmd,
1966 "bgp enforce-first-as",
1967 BGP_STR
1968 "Enforce the first AS for EBGP routes\n")
1969{
d62a17ae 1970 VTY_DECLVAR_CONTEXT(bgp, bgp);
1971 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1972 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1973
d62a17ae 1974 return CMD_SUCCESS;
718e3744 1975}
1976
1977DEFUN (no_bgp_enforce_first_as,
1978 no_bgp_enforce_first_as_cmd,
1979 "no bgp enforce-first-as",
1980 NO_STR
1981 BGP_STR
1982 "Enforce the first AS for EBGP routes\n")
1983{
d62a17ae 1984 VTY_DECLVAR_CONTEXT(bgp, bgp);
1985 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1986 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1987
d62a17ae 1988 return CMD_SUCCESS;
718e3744 1989}
6b0655a2 1990
718e3744 1991/* "bgp bestpath compare-routerid" configuration. */
1992DEFUN (bgp_bestpath_compare_router_id,
1993 bgp_bestpath_compare_router_id_cmd,
1994 "bgp bestpath compare-routerid",
1995 "BGP specific commands\n"
1996 "Change the default bestpath selection\n"
1997 "Compare router-id for identical EBGP paths\n")
1998{
d62a17ae 1999 VTY_DECLVAR_CONTEXT(bgp, bgp);
2000 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2001 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2002
d62a17ae 2003 return CMD_SUCCESS;
718e3744 2004}
2005
2006DEFUN (no_bgp_bestpath_compare_router_id,
2007 no_bgp_bestpath_compare_router_id_cmd,
2008 "no bgp bestpath compare-routerid",
2009 NO_STR
2010 "BGP specific commands\n"
2011 "Change the default bestpath selection\n"
2012 "Compare router-id for identical EBGP paths\n")
2013{
d62a17ae 2014 VTY_DECLVAR_CONTEXT(bgp, bgp);
2015 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2016 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2017
d62a17ae 2018 return CMD_SUCCESS;
718e3744 2019}
6b0655a2 2020
718e3744 2021/* "bgp bestpath as-path ignore" configuration. */
2022DEFUN (bgp_bestpath_aspath_ignore,
2023 bgp_bestpath_aspath_ignore_cmd,
2024 "bgp bestpath as-path ignore",
2025 "BGP specific commands\n"
2026 "Change the default bestpath selection\n"
2027 "AS-path attribute\n"
2028 "Ignore as-path length in selecting a route\n")
2029{
d62a17ae 2030 VTY_DECLVAR_CONTEXT(bgp, bgp);
2031 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2032 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2033
d62a17ae 2034 return CMD_SUCCESS;
718e3744 2035}
2036
2037DEFUN (no_bgp_bestpath_aspath_ignore,
2038 no_bgp_bestpath_aspath_ignore_cmd,
2039 "no bgp bestpath as-path ignore",
2040 NO_STR
2041 "BGP specific commands\n"
2042 "Change the default bestpath selection\n"
2043 "AS-path attribute\n"
2044 "Ignore as-path length in selecting a route\n")
2045{
d62a17ae 2046 VTY_DECLVAR_CONTEXT(bgp, bgp);
2047 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2048 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2049
d62a17ae 2050 return CMD_SUCCESS;
718e3744 2051}
6b0655a2 2052
6811845b 2053/* "bgp bestpath as-path confed" configuration. */
2054DEFUN (bgp_bestpath_aspath_confed,
2055 bgp_bestpath_aspath_confed_cmd,
2056 "bgp bestpath as-path confed",
2057 "BGP specific commands\n"
2058 "Change the default bestpath selection\n"
2059 "AS-path attribute\n"
2060 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2061{
d62a17ae 2062 VTY_DECLVAR_CONTEXT(bgp, bgp);
2063 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2064 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2065
d62a17ae 2066 return CMD_SUCCESS;
6811845b 2067}
2068
2069DEFUN (no_bgp_bestpath_aspath_confed,
2070 no_bgp_bestpath_aspath_confed_cmd,
2071 "no bgp bestpath as-path confed",
2072 NO_STR
2073 "BGP specific commands\n"
2074 "Change the default bestpath selection\n"
2075 "AS-path attribute\n"
2076 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2077{
d62a17ae 2078 VTY_DECLVAR_CONTEXT(bgp, bgp);
2079 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2080 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2081
d62a17ae 2082 return CMD_SUCCESS;
6811845b 2083}
6b0655a2 2084
2fdd455c
PM
2085/* "bgp bestpath as-path multipath-relax" configuration. */
2086DEFUN (bgp_bestpath_aspath_multipath_relax,
2087 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2088 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2089 "BGP specific commands\n"
2090 "Change the default bestpath selection\n"
2091 "AS-path attribute\n"
2092 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2093 "Generate an AS_SET\n"
16fc1eec
DS
2094 "Do not generate an AS_SET\n")
2095{
d62a17ae 2096 VTY_DECLVAR_CONTEXT(bgp, bgp);
2097 int idx = 0;
2098 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2099
d62a17ae 2100 /* no-as-set is now the default behavior so we can silently
2101 * ignore it */
2102 if (argv_find(argv, argc, "as-set", &idx))
2103 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2104 else
2105 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2106
d62a17ae 2107 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2108
d62a17ae 2109 return CMD_SUCCESS;
16fc1eec
DS
2110}
2111
219178b6
DW
2112DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2113 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2114 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2115 NO_STR
2116 "BGP specific commands\n"
2117 "Change the default bestpath selection\n"
2118 "AS-path attribute\n"
2119 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2120 "Generate an AS_SET\n"
16fc1eec
DS
2121 "Do not generate an AS_SET\n")
2122{
d62a17ae 2123 VTY_DECLVAR_CONTEXT(bgp, bgp);
2124 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2125 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2126 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2127
d62a17ae 2128 return CMD_SUCCESS;
2fdd455c 2129}
6b0655a2 2130
848973c7 2131/* "bgp log-neighbor-changes" configuration. */
2132DEFUN (bgp_log_neighbor_changes,
2133 bgp_log_neighbor_changes_cmd,
2134 "bgp log-neighbor-changes",
2135 "BGP specific commands\n"
2136 "Log neighbor up/down and reset reason\n")
2137{
d62a17ae 2138 VTY_DECLVAR_CONTEXT(bgp, bgp);
2139 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2140 return CMD_SUCCESS;
848973c7 2141}
2142
2143DEFUN (no_bgp_log_neighbor_changes,
2144 no_bgp_log_neighbor_changes_cmd,
2145 "no bgp log-neighbor-changes",
2146 NO_STR
2147 "BGP specific commands\n"
2148 "Log neighbor up/down and reset reason\n")
2149{
d62a17ae 2150 VTY_DECLVAR_CONTEXT(bgp, bgp);
2151 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2152 return CMD_SUCCESS;
848973c7 2153}
6b0655a2 2154
718e3744 2155/* "bgp bestpath med" configuration. */
2156DEFUN (bgp_bestpath_med,
2157 bgp_bestpath_med_cmd,
2d8c1a4d 2158 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2159 "BGP specific commands\n"
2160 "Change the default bestpath selection\n"
2161 "MED attribute\n"
2162 "Compare MED among confederation paths\n"
838758ac
DW
2163 "Treat missing MED as the least preferred one\n"
2164 "Treat missing MED as the least preferred one\n"
2165 "Compare MED among confederation paths\n")
718e3744 2166{
d62a17ae 2167 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2168
d62a17ae 2169 int idx = 0;
2170 if (argv_find(argv, argc, "confed", &idx))
2171 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2172 idx = 0;
2173 if (argv_find(argv, argc, "missing-as-worst", &idx))
2174 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2175
d62a17ae 2176 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2177
d62a17ae 2178 return CMD_SUCCESS;
718e3744 2179}
2180
718e3744 2181DEFUN (no_bgp_bestpath_med,
2182 no_bgp_bestpath_med_cmd,
2d8c1a4d 2183 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2184 NO_STR
2185 "BGP specific commands\n"
2186 "Change the default bestpath selection\n"
2187 "MED attribute\n"
2188 "Compare MED among confederation paths\n"
3a2d747c
QY
2189 "Treat missing MED as the least preferred one\n"
2190 "Treat missing MED as the least preferred one\n"
2191 "Compare MED among confederation paths\n")
718e3744 2192{
d62a17ae 2193 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2194
d62a17ae 2195 int idx = 0;
2196 if (argv_find(argv, argc, "confed", &idx))
2197 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2198 idx = 0;
2199 if (argv_find(argv, argc, "missing-as-worst", &idx))
2200 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2201
d62a17ae 2202 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2203
d62a17ae 2204 return CMD_SUCCESS;
718e3744 2205}
2206
718e3744 2207/* "no bgp default ipv4-unicast". */
2208DEFUN (no_bgp_default_ipv4_unicast,
2209 no_bgp_default_ipv4_unicast_cmd,
2210 "no bgp default ipv4-unicast",
2211 NO_STR
2212 "BGP specific commands\n"
2213 "Configure BGP defaults\n"
2214 "Activate ipv4-unicast for a peer by default\n")
2215{
d62a17ae 2216 VTY_DECLVAR_CONTEXT(bgp, bgp);
2217 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2218 return CMD_SUCCESS;
718e3744 2219}
2220
2221DEFUN (bgp_default_ipv4_unicast,
2222 bgp_default_ipv4_unicast_cmd,
2223 "bgp default ipv4-unicast",
2224 "BGP specific commands\n"
2225 "Configure BGP defaults\n"
2226 "Activate ipv4-unicast for a peer by default\n")
2227{
d62a17ae 2228 VTY_DECLVAR_CONTEXT(bgp, bgp);
2229 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2230 return CMD_SUCCESS;
718e3744 2231}
6b0655a2 2232
04b6bdc0
DW
2233/* Display hostname in certain command outputs */
2234DEFUN (bgp_default_show_hostname,
2235 bgp_default_show_hostname_cmd,
2236 "bgp default show-hostname",
2237 "BGP specific commands\n"
2238 "Configure BGP defaults\n"
2239 "Show hostname in certain command ouputs\n")
2240{
d62a17ae 2241 VTY_DECLVAR_CONTEXT(bgp, bgp);
2242 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2243 return CMD_SUCCESS;
04b6bdc0
DW
2244}
2245
2246DEFUN (no_bgp_default_show_hostname,
2247 no_bgp_default_show_hostname_cmd,
2248 "no bgp default show-hostname",
2249 NO_STR
2250 "BGP specific commands\n"
2251 "Configure BGP defaults\n"
2252 "Show hostname in certain command ouputs\n")
2253{
d62a17ae 2254 VTY_DECLVAR_CONTEXT(bgp, bgp);
2255 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2256 return CMD_SUCCESS;
04b6bdc0
DW
2257}
2258
8233ef81 2259/* "bgp network import-check" configuration. */
718e3744 2260DEFUN (bgp_network_import_check,
2261 bgp_network_import_check_cmd,
5623e905 2262 "bgp network import-check",
718e3744 2263 "BGP specific commands\n"
2264 "BGP network command\n"
5623e905 2265 "Check BGP network route exists in IGP\n")
718e3744 2266{
d62a17ae 2267 VTY_DECLVAR_CONTEXT(bgp, bgp);
2268 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2269 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2270 bgp_static_redo_import_check(bgp);
2271 }
078430f6 2272
d62a17ae 2273 return CMD_SUCCESS;
718e3744 2274}
2275
d62a17ae 2276ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2277 "bgp network import-check exact",
2278 "BGP specific commands\n"
2279 "BGP network command\n"
2280 "Check BGP network route exists in IGP\n"
2281 "Match route precisely\n")
8233ef81 2282
718e3744 2283DEFUN (no_bgp_network_import_check,
2284 no_bgp_network_import_check_cmd,
5623e905 2285 "no bgp network import-check",
718e3744 2286 NO_STR
2287 "BGP specific commands\n"
2288 "BGP network command\n"
2289 "Check BGP network route exists in IGP\n")
2290{
d62a17ae 2291 VTY_DECLVAR_CONTEXT(bgp, bgp);
2292 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2293 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2294 bgp_static_redo_import_check(bgp);
2295 }
5623e905 2296
d62a17ae 2297 return CMD_SUCCESS;
718e3744 2298}
6b0655a2 2299
718e3744 2300DEFUN (bgp_default_local_preference,
2301 bgp_default_local_preference_cmd,
6147e2c6 2302 "bgp default local-preference (0-4294967295)",
718e3744 2303 "BGP specific commands\n"
2304 "Configure BGP defaults\n"
2305 "local preference (higher=more preferred)\n"
2306 "Configure default local preference value\n")
2307{
d62a17ae 2308 VTY_DECLVAR_CONTEXT(bgp, bgp);
2309 int idx_number = 3;
d7c0a89a 2310 uint32_t local_pref;
718e3744 2311
d62a17ae 2312 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2313
d62a17ae 2314 bgp_default_local_preference_set(bgp, local_pref);
2315 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2316
d62a17ae 2317 return CMD_SUCCESS;
718e3744 2318}
2319
2320DEFUN (no_bgp_default_local_preference,
2321 no_bgp_default_local_preference_cmd,
838758ac 2322 "no bgp default local-preference [(0-4294967295)]",
718e3744 2323 NO_STR
2324 "BGP specific commands\n"
2325 "Configure BGP defaults\n"
838758ac
DW
2326 "local preference (higher=more preferred)\n"
2327 "Configure default local preference value\n")
718e3744 2328{
d62a17ae 2329 VTY_DECLVAR_CONTEXT(bgp, bgp);
2330 bgp_default_local_preference_unset(bgp);
2331 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2332
d62a17ae 2333 return CMD_SUCCESS;
718e3744 2334}
2335
6b0655a2 2336
3f9c7369
DS
2337DEFUN (bgp_default_subgroup_pkt_queue_max,
2338 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2339 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2340 "BGP specific commands\n"
2341 "Configure BGP defaults\n"
2342 "subgroup-pkt-queue-max\n"
2343 "Configure subgroup packet queue max\n")
8bd9d948 2344{
d62a17ae 2345 VTY_DECLVAR_CONTEXT(bgp, bgp);
2346 int idx_number = 3;
d7c0a89a 2347 uint32_t max_size;
8bd9d948 2348
d62a17ae 2349 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2350
d62a17ae 2351 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2352
d62a17ae 2353 return CMD_SUCCESS;
3f9c7369
DS
2354}
2355
2356DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2357 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2358 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2359 NO_STR
2360 "BGP specific commands\n"
2361 "Configure BGP defaults\n"
838758ac
DW
2362 "subgroup-pkt-queue-max\n"
2363 "Configure subgroup packet queue max\n")
3f9c7369 2364{
d62a17ae 2365 VTY_DECLVAR_CONTEXT(bgp, bgp);
2366 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2367 return CMD_SUCCESS;
8bd9d948
DS
2368}
2369
813d4307 2370
8bd9d948
DS
2371DEFUN (bgp_rr_allow_outbound_policy,
2372 bgp_rr_allow_outbound_policy_cmd,
2373 "bgp route-reflector allow-outbound-policy",
2374 "BGP specific commands\n"
2375 "Allow modifications made by out route-map\n"
2376 "on ibgp neighbors\n")
2377{
d62a17ae 2378 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2379
d62a17ae 2380 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2381 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2382 update_group_announce_rrclients(bgp);
2383 bgp_clear_star_soft_out(vty, bgp->name);
2384 }
8bd9d948 2385
d62a17ae 2386 return CMD_SUCCESS;
8bd9d948
DS
2387}
2388
2389DEFUN (no_bgp_rr_allow_outbound_policy,
2390 no_bgp_rr_allow_outbound_policy_cmd,
2391 "no bgp route-reflector allow-outbound-policy",
2392 NO_STR
2393 "BGP specific commands\n"
2394 "Allow modifications made by out route-map\n"
2395 "on ibgp neighbors\n")
2396{
d62a17ae 2397 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2398
d62a17ae 2399 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2400 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2401 update_group_announce_rrclients(bgp);
2402 bgp_clear_star_soft_out(vty, bgp->name);
2403 }
8bd9d948 2404
d62a17ae 2405 return CMD_SUCCESS;
8bd9d948
DS
2406}
2407
f14e6fdb
DS
2408DEFUN (bgp_listen_limit,
2409 bgp_listen_limit_cmd,
9ccf14f7 2410 "bgp listen limit (1-5000)",
f14e6fdb
DS
2411 "BGP specific commands\n"
2412 "Configure BGP defaults\n"
2413 "maximum number of BGP Dynamic Neighbors that can be created\n"
2414 "Configure Dynamic Neighbors listen limit value\n")
2415{
d62a17ae 2416 VTY_DECLVAR_CONTEXT(bgp, bgp);
2417 int idx_number = 3;
2418 int listen_limit;
f14e6fdb 2419
d62a17ae 2420 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2421
d62a17ae 2422 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2423
d62a17ae 2424 return CMD_SUCCESS;
f14e6fdb
DS
2425}
2426
2427DEFUN (no_bgp_listen_limit,
2428 no_bgp_listen_limit_cmd,
838758ac 2429 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2430 "BGP specific commands\n"
2431 "Configure BGP defaults\n"
2432 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2433 "Configure Dynamic Neighbors listen limit value to default\n"
2434 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2435{
d62a17ae 2436 VTY_DECLVAR_CONTEXT(bgp, bgp);
2437 bgp_listen_limit_unset(bgp);
2438 return CMD_SUCCESS;
f14e6fdb
DS
2439}
2440
2441
20eb8864 2442/*
2443 * Check if this listen range is already configured. Check for exact
2444 * match or overlap based on input.
2445 */
d62a17ae 2446static struct peer_group *listen_range_exists(struct bgp *bgp,
2447 struct prefix *range, int exact)
2448{
2449 struct listnode *node, *nnode;
2450 struct listnode *node1, *nnode1;
2451 struct peer_group *group;
2452 struct prefix *lr;
2453 afi_t afi;
2454 int match;
2455
2456 afi = family2afi(range->family);
2457 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2458 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2459 lr)) {
2460 if (exact)
2461 match = prefix_same(range, lr);
2462 else
2463 match = (prefix_match(range, lr)
2464 || prefix_match(lr, range));
2465 if (match)
2466 return group;
2467 }
2468 }
2469
2470 return NULL;
20eb8864 2471}
2472
f14e6fdb
DS
2473DEFUN (bgp_listen_range,
2474 bgp_listen_range_cmd,
9ccf14f7 2475 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2476 "BGP specific commands\n"
d7fa34c1
QY
2477 "Configure BGP dynamic neighbors listen range\n"
2478 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2479 NEIGHBOR_ADDR_STR
2480 "Member of the peer-group\n"
2481 "Peer-group name\n")
f14e6fdb 2482{
d62a17ae 2483 VTY_DECLVAR_CONTEXT(bgp, bgp);
2484 struct prefix range;
2485 struct peer_group *group, *existing_group;
2486 afi_t afi;
2487 int ret;
2488 int idx = 0;
2489
2490 argv_find(argv, argc, "A.B.C.D/M", &idx);
2491 argv_find(argv, argc, "X:X::X:X/M", &idx);
2492 char *prefix = argv[idx]->arg;
2493 argv_find(argv, argc, "WORD", &idx);
2494 char *peergroup = argv[idx]->arg;
2495
2496 /* Convert IP prefix string to struct prefix. */
2497 ret = str2prefix(prefix, &range);
2498 if (!ret) {
2499 vty_out(vty, "%% Malformed listen range\n");
2500 return CMD_WARNING_CONFIG_FAILED;
2501 }
2502
2503 afi = family2afi(range.family);
2504
2505 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2506 vty_out(vty,
2507 "%% Malformed listen range (link-local address)\n");
2508 return CMD_WARNING_CONFIG_FAILED;
2509 }
2510
2511 apply_mask(&range);
2512
2513 /* Check if same listen range is already configured. */
2514 existing_group = listen_range_exists(bgp, &range, 1);
2515 if (existing_group) {
2516 if (strcmp(existing_group->name, peergroup) == 0)
2517 return CMD_SUCCESS;
2518 else {
2519 vty_out(vty,
2520 "%% Same listen range is attached to peer-group %s\n",
2521 existing_group->name);
2522 return CMD_WARNING_CONFIG_FAILED;
2523 }
2524 }
2525
2526 /* Check if an overlapping listen range exists. */
2527 if (listen_range_exists(bgp, &range, 0)) {
2528 vty_out(vty,
2529 "%% Listen range overlaps with existing listen range\n");
2530 return CMD_WARNING_CONFIG_FAILED;
2531 }
2532
2533 group = peer_group_lookup(bgp, peergroup);
2534 if (!group) {
2535 vty_out(vty, "%% Configure the peer-group first\n");
2536 return CMD_WARNING_CONFIG_FAILED;
2537 }
2538
2539 ret = peer_group_listen_range_add(group, &range);
2540 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2541}
2542
2543DEFUN (no_bgp_listen_range,
2544 no_bgp_listen_range_cmd,
d7fa34c1
QY
2545 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2546 NO_STR
f14e6fdb 2547 "BGP specific commands\n"
d7fa34c1
QY
2548 "Unconfigure BGP dynamic neighbors listen range\n"
2549 "Unconfigure BGP dynamic neighbors listen range\n"
2550 NEIGHBOR_ADDR_STR
2551 "Member of the peer-group\n"
2552 "Peer-group name\n")
f14e6fdb 2553{
d62a17ae 2554 VTY_DECLVAR_CONTEXT(bgp, bgp);
2555 struct prefix range;
2556 struct peer_group *group;
2557 afi_t afi;
2558 int ret;
2559 int idx = 0;
2560
2561 argv_find(argv, argc, "A.B.C.D/M", &idx);
2562 argv_find(argv, argc, "X:X::X:X/M", &idx);
2563 char *prefix = argv[idx]->arg;
2564 argv_find(argv, argc, "WORD", &idx);
2565 char *peergroup = argv[idx]->arg;
2566
2567 /* Convert IP prefix string to struct prefix. */
2568 ret = str2prefix(prefix, &range);
2569 if (!ret) {
2570 vty_out(vty, "%% Malformed listen range\n");
2571 return CMD_WARNING_CONFIG_FAILED;
2572 }
2573
2574 afi = family2afi(range.family);
2575
2576 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2577 vty_out(vty,
2578 "%% Malformed listen range (link-local address)\n");
2579 return CMD_WARNING_CONFIG_FAILED;
2580 }
2581
2582 apply_mask(&range);
2583
2584 group = peer_group_lookup(bgp, peergroup);
2585 if (!group) {
2586 vty_out(vty, "%% Peer-group does not exist\n");
2587 return CMD_WARNING_CONFIG_FAILED;
2588 }
2589
2590 ret = peer_group_listen_range_del(group, &range);
2591 return bgp_vty_return(vty, ret);
2592}
2593
2b791107 2594void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2595{
2596 struct peer_group *group;
2597 struct listnode *node, *nnode, *rnode, *nrnode;
2598 struct prefix *range;
2599 afi_t afi;
2600 char buf[PREFIX2STR_BUFFER];
2601
2602 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2603 vty_out(vty, " bgp listen limit %d\n",
2604 bgp->dynamic_neighbors_limit);
2605
2606 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2607 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2608 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2609 nrnode, range)) {
2610 prefix2str(range, buf, sizeof(buf));
2611 vty_out(vty,
2612 " bgp listen range %s peer-group %s\n",
2613 buf, group->name);
2614 }
2615 }
2616 }
f14e6fdb
DS
2617}
2618
2619
907f92c8
DS
2620DEFUN (bgp_disable_connected_route_check,
2621 bgp_disable_connected_route_check_cmd,
2622 "bgp disable-ebgp-connected-route-check",
2623 "BGP specific commands\n"
2624 "Disable checking if nexthop is connected on ebgp sessions\n")
2625{
d62a17ae 2626 VTY_DECLVAR_CONTEXT(bgp, bgp);
2627 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2628 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2629
d62a17ae 2630 return CMD_SUCCESS;
907f92c8
DS
2631}
2632
2633DEFUN (no_bgp_disable_connected_route_check,
2634 no_bgp_disable_connected_route_check_cmd,
2635 "no bgp disable-ebgp-connected-route-check",
2636 NO_STR
2637 "BGP specific commands\n"
2638 "Disable checking if nexthop is connected on ebgp sessions\n")
2639{
d62a17ae 2640 VTY_DECLVAR_CONTEXT(bgp, bgp);
2641 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2642 bgp_clear_star_soft_in(vty, bgp->name);
2643
2644 return CMD_SUCCESS;
2645}
2646
2647
2648static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2649 const char *as_str, afi_t afi, safi_t safi)
2650{
2651 VTY_DECLVAR_CONTEXT(bgp, bgp);
2652 int ret;
2653 as_t as;
2654 int as_type = AS_SPECIFIED;
2655 union sockunion su;
2656
2657 if (as_str[0] == 'i') {
2658 as = 0;
2659 as_type = AS_INTERNAL;
2660 } else if (as_str[0] == 'e') {
2661 as = 0;
2662 as_type = AS_EXTERNAL;
2663 } else {
2664 /* Get AS number. */
2665 as = strtoul(as_str, NULL, 10);
2666 }
2667
2668 /* If peer is peer group, call proper function. */
2669 ret = str2sockunion(peer_str, &su);
2670 if (ret < 0) {
2671 /* Check for peer by interface */
2672 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2673 safi);
2674 if (ret < 0) {
2675 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2676 if (ret < 0) {
2677 vty_out(vty,
2678 "%% Create the peer-group or interface first\n");
2679 return CMD_WARNING_CONFIG_FAILED;
2680 }
2681 return CMD_SUCCESS;
2682 }
2683 } else {
2684 if (peer_address_self_check(bgp, &su)) {
2685 vty_out(vty,
2686 "%% Can not configure the local system as neighbor\n");
2687 return CMD_WARNING_CONFIG_FAILED;
2688 }
2689 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2690 }
2691
2692 /* This peer belongs to peer group. */
2693 switch (ret) {
2694 case BGP_ERR_PEER_GROUP_MEMBER:
2695 vty_out(vty,
2696 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2697 as);
2698 return CMD_WARNING_CONFIG_FAILED;
2699 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2700 vty_out(vty,
2701 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2702 as, as_str);
2703 return CMD_WARNING_CONFIG_FAILED;
2704 }
2705 return bgp_vty_return(vty, ret);
718e3744 2706}
2707
f26845f9
QY
2708DEFUN (bgp_default_shutdown,
2709 bgp_default_shutdown_cmd,
2710 "[no] bgp default shutdown",
2711 NO_STR
2712 BGP_STR
2713 "Configure BGP defaults\n"
b012cbe2 2714 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2715{
2716 VTY_DECLVAR_CONTEXT(bgp, bgp);
2717 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2718 return CMD_SUCCESS;
2719}
2720
718e3744 2721DEFUN (neighbor_remote_as,
2722 neighbor_remote_as_cmd,
3a2d747c 2723 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2724 NEIGHBOR_STR
2725 NEIGHBOR_ADDR_STR2
2726 "Specify a BGP neighbor\n"
d7fa34c1 2727 AS_STR
3a2d747c
QY
2728 "Internal BGP peer\n"
2729 "External BGP peer\n")
718e3744 2730{
d62a17ae 2731 int idx_peer = 1;
2732 int idx_remote_as = 3;
2733 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2734 argv[idx_remote_as]->arg, AFI_IP,
2735 SAFI_UNICAST);
2736}
2737
2738static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2739 afi_t afi, safi_t safi, int v6only,
2740 const char *peer_group_name,
2741 const char *as_str)
2742{
2743 VTY_DECLVAR_CONTEXT(bgp, bgp);
2744 as_t as = 0;
2745 int as_type = AS_UNSPECIFIED;
2746 struct peer *peer;
2747 struct peer_group *group;
2748 int ret = 0;
2749 union sockunion su;
2750
2751 group = peer_group_lookup(bgp, conf_if);
2752
2753 if (group) {
2754 vty_out(vty, "%% Name conflict with peer-group \n");
2755 return CMD_WARNING_CONFIG_FAILED;
2756 }
2757
2758 if (as_str) {
2759 if (as_str[0] == 'i') {
2760 as_type = AS_INTERNAL;
2761 } else if (as_str[0] == 'e') {
2762 as_type = AS_EXTERNAL;
2763 } else {
2764 /* Get AS number. */
2765 as = strtoul(as_str, NULL, 10);
2766 as_type = AS_SPECIFIED;
2767 }
2768 }
2769
2770 peer = peer_lookup_by_conf_if(bgp, conf_if);
2771 if (peer) {
2772 if (as_str)
2773 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2774 afi, safi);
2775 } else {
2776 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2777 && afi == AFI_IP && safi == SAFI_UNICAST)
2778 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2779 as_type, 0, 0, NULL);
2780 else
2781 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2782 as_type, afi, safi, NULL);
2783
2784 if (!peer) {
2785 vty_out(vty, "%% BGP failed to create peer\n");
2786 return CMD_WARNING_CONFIG_FAILED;
2787 }
2788
2789 if (v6only)
2790 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2791
2792 /* Request zebra to initiate IPv6 RAs on this interface. We do
2793 * this
2794 * any unnumbered peer in order to not worry about run-time
2795 * transitions
2796 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2797 * address
2798 * gets deleted later etc.)
2799 */
2800 if (peer->ifp)
2801 bgp_zebra_initiate_radv(bgp, peer);
2802 }
2803
2804 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2805 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2806 if (v6only)
2807 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2808 else
2809 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2810
2811 /* v6only flag changed. Reset bgp seesion */
2812 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2813 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2814 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2815 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2816 } else
2817 bgp_session_reset(peer);
2818 }
2819
2820 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2821 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2822
2823 if (peer_group_name) {
2824 group = peer_group_lookup(bgp, peer_group_name);
2825 if (!group) {
2826 vty_out(vty, "%% Configure the peer-group first\n");
2827 return CMD_WARNING_CONFIG_FAILED;
2828 }
2829
2830 ret = peer_group_bind(bgp, &su, peer, group, &as);
2831 }
2832
2833 return bgp_vty_return(vty, ret);
a80beece
DS
2834}
2835
4c48cf63
DW
2836DEFUN (neighbor_interface_config,
2837 neighbor_interface_config_cmd,
31500417 2838 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2839 NEIGHBOR_STR
2840 "Interface name or neighbor tag\n"
31500417
DW
2841 "Enable BGP on interface\n"
2842 "Member of the peer-group\n"
16cedbb0 2843 "Peer-group name\n")
4c48cf63 2844{
d62a17ae 2845 int idx_word = 1;
2846 int idx_peer_group_word = 4;
31500417 2847
d62a17ae 2848 if (argc > idx_peer_group_word)
2849 return peer_conf_interface_get(
2850 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2851 argv[idx_peer_group_word]->arg, NULL);
2852 else
2853 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2854 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2855}
2856
4c48cf63
DW
2857DEFUN (neighbor_interface_config_v6only,
2858 neighbor_interface_config_v6only_cmd,
31500417 2859 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2860 NEIGHBOR_STR
2861 "Interface name or neighbor tag\n"
2862 "Enable BGP on interface\n"
31500417
DW
2863 "Enable BGP with v6 link-local only\n"
2864 "Member of the peer-group\n"
16cedbb0 2865 "Peer-group name\n")
4c48cf63 2866{
d62a17ae 2867 int idx_word = 1;
2868 int idx_peer_group_word = 5;
31500417 2869
d62a17ae 2870 if (argc > idx_peer_group_word)
2871 return peer_conf_interface_get(
2872 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2873 argv[idx_peer_group_word]->arg, NULL);
31500417 2874
d62a17ae 2875 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2876 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2877}
2878
a80beece 2879
b3a39dc5
DD
2880DEFUN (neighbor_interface_config_remote_as,
2881 neighbor_interface_config_remote_as_cmd,
3a2d747c 2882 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2883 NEIGHBOR_STR
2884 "Interface name or neighbor tag\n"
2885 "Enable BGP on interface\n"
3a2d747c 2886 "Specify a BGP neighbor\n"
d7fa34c1 2887 AS_STR
3a2d747c
QY
2888 "Internal BGP peer\n"
2889 "External BGP peer\n")
b3a39dc5 2890{
d62a17ae 2891 int idx_word = 1;
2892 int idx_remote_as = 4;
2893 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2894 SAFI_UNICAST, 0, NULL,
2895 argv[idx_remote_as]->arg);
b3a39dc5
DD
2896}
2897
2898DEFUN (neighbor_interface_v6only_config_remote_as,
2899 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2900 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2901 NEIGHBOR_STR
2902 "Interface name or neighbor tag\n"
3a2d747c 2903 "Enable BGP with v6 link-local only\n"
b3a39dc5 2904 "Enable BGP on interface\n"
3a2d747c 2905 "Specify a BGP neighbor\n"
d7fa34c1 2906 AS_STR
3a2d747c
QY
2907 "Internal BGP peer\n"
2908 "External BGP peer\n")
b3a39dc5 2909{
d62a17ae 2910 int idx_word = 1;
2911 int idx_remote_as = 5;
2912 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2913 SAFI_UNICAST, 1, NULL,
2914 argv[idx_remote_as]->arg);
b3a39dc5
DD
2915}
2916
718e3744 2917DEFUN (neighbor_peer_group,
2918 neighbor_peer_group_cmd,
2919 "neighbor WORD peer-group",
2920 NEIGHBOR_STR
a80beece 2921 "Interface name or neighbor tag\n"
718e3744 2922 "Configure peer-group\n")
2923{
d62a17ae 2924 VTY_DECLVAR_CONTEXT(bgp, bgp);
2925 int idx_word = 1;
2926 struct peer *peer;
2927 struct peer_group *group;
718e3744 2928
d62a17ae 2929 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2930 if (peer) {
2931 vty_out(vty, "%% Name conflict with interface: \n");
2932 return CMD_WARNING_CONFIG_FAILED;
2933 }
718e3744 2934
d62a17ae 2935 group = peer_group_get(bgp, argv[idx_word]->arg);
2936 if (!group) {
2937 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2938 return CMD_WARNING_CONFIG_FAILED;
2939 }
718e3744 2940
d62a17ae 2941 return CMD_SUCCESS;
718e3744 2942}
2943
2944DEFUN (no_neighbor,
2945 no_neighbor_cmd,
dab8cd00 2946 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 2947 NO_STR
2948 NEIGHBOR_STR
3a2d747c
QY
2949 NEIGHBOR_ADDR_STR2
2950 "Specify a BGP neighbor\n"
2951 AS_STR
2952 "Internal BGP peer\n"
2953 "External BGP peer\n")
718e3744 2954{
d62a17ae 2955 VTY_DECLVAR_CONTEXT(bgp, bgp);
2956 int idx_peer = 2;
2957 int ret;
2958 union sockunion su;
2959 struct peer_group *group;
2960 struct peer *peer;
2961 struct peer *other;
2962
2963 ret = str2sockunion(argv[idx_peer]->arg, &su);
2964 if (ret < 0) {
2965 /* look up for neighbor by interface name config. */
2966 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
2967 if (peer) {
2968 /* Request zebra to terminate IPv6 RAs on this
2969 * interface. */
2970 if (peer->ifp)
2971 bgp_zebra_terminate_radv(peer->bgp, peer);
2972 peer_delete(peer);
2973 return CMD_SUCCESS;
2974 }
f14e6fdb 2975
d62a17ae 2976 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
2977 if (group)
2978 peer_group_delete(group);
2979 else {
2980 vty_out(vty, "%% Create the peer-group first\n");
2981 return CMD_WARNING_CONFIG_FAILED;
2982 }
2983 } else {
2984 peer = peer_lookup(bgp, &su);
2985 if (peer) {
2986 if (peer_dynamic_neighbor(peer)) {
2987 vty_out(vty,
2988 "%% Operation not allowed on a dynamic neighbor\n");
2989 return CMD_WARNING_CONFIG_FAILED;
2990 }
2991
2992 other = peer->doppelganger;
2993 peer_delete(peer);
2994 if (other && other->status != Deleted)
2995 peer_delete(other);
2996 }
1ff9a340 2997 }
718e3744 2998
d62a17ae 2999 return CMD_SUCCESS;
718e3744 3000}
3001
a80beece
DS
3002DEFUN (no_neighbor_interface_config,
3003 no_neighbor_interface_config_cmd,
31500417 3004 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3005 NO_STR
3006 NEIGHBOR_STR
3007 "Interface name\n"
31500417
DW
3008 "Configure BGP on interface\n"
3009 "Enable BGP with v6 link-local only\n"
3010 "Member of the peer-group\n"
16cedbb0 3011 "Peer-group name\n"
3a2d747c
QY
3012 "Specify a BGP neighbor\n"
3013 AS_STR
3014 "Internal BGP peer\n"
3015 "External BGP peer\n")
a80beece 3016{
d62a17ae 3017 VTY_DECLVAR_CONTEXT(bgp, bgp);
3018 int idx_word = 2;
3019 struct peer *peer;
3020
3021 /* look up for neighbor by interface name config. */
3022 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3023 if (peer) {
3024 /* Request zebra to terminate IPv6 RAs on this interface. */
3025 if (peer->ifp)
3026 bgp_zebra_terminate_radv(peer->bgp, peer);
3027 peer_delete(peer);
3028 } else {
3029 vty_out(vty, "%% Create the bgp interface first\n");
3030 return CMD_WARNING_CONFIG_FAILED;
3031 }
3032 return CMD_SUCCESS;
a80beece
DS
3033}
3034
718e3744 3035DEFUN (no_neighbor_peer_group,
3036 no_neighbor_peer_group_cmd,
3037 "no neighbor WORD peer-group",
3038 NO_STR
3039 NEIGHBOR_STR
3040 "Neighbor tag\n"
3041 "Configure peer-group\n")
3042{
d62a17ae 3043 VTY_DECLVAR_CONTEXT(bgp, bgp);
3044 int idx_word = 2;
3045 struct peer_group *group;
718e3744 3046
d62a17ae 3047 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3048 if (group)
3049 peer_group_delete(group);
3050 else {
3051 vty_out(vty, "%% Create the peer-group first\n");
3052 return CMD_WARNING_CONFIG_FAILED;
3053 }
3054 return CMD_SUCCESS;
718e3744 3055}
3056
a80beece
DS
3057DEFUN (no_neighbor_interface_peer_group_remote_as,
3058 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3059 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3060 NO_STR
3061 NEIGHBOR_STR
a80beece 3062 "Interface name or neighbor tag\n"
718e3744 3063 "Specify a BGP neighbor\n"
3a2d747c
QY
3064 AS_STR
3065 "Internal BGP peer\n"
3066 "External BGP peer\n")
718e3744 3067{
d62a17ae 3068 VTY_DECLVAR_CONTEXT(bgp, bgp);
3069 int idx_word = 2;
3070 struct peer_group *group;
3071 struct peer *peer;
3072
3073 /* look up for neighbor by interface name config. */
3074 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3075 if (peer) {
3076 peer_as_change(peer, 0, AS_SPECIFIED);
3077 return CMD_SUCCESS;
3078 }
3079
3080 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3081 if (group)
3082 peer_group_remote_as_delete(group);
3083 else {
3084 vty_out(vty, "%% Create the peer-group or interface first\n");
3085 return CMD_WARNING_CONFIG_FAILED;
3086 }
3087 return CMD_SUCCESS;
718e3744 3088}
6b0655a2 3089
718e3744 3090DEFUN (neighbor_local_as,
3091 neighbor_local_as_cmd,
9ccf14f7 3092 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3093 NEIGHBOR_STR
3094 NEIGHBOR_ADDR_STR2
3095 "Specify a local-as number\n"
3096 "AS number used as local AS\n")
3097{
d62a17ae 3098 int idx_peer = 1;
3099 int idx_number = 3;
3100 struct peer *peer;
3101 int ret;
3102 as_t as;
718e3744 3103
d62a17ae 3104 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3105 if (!peer)
3106 return CMD_WARNING_CONFIG_FAILED;
718e3744 3107
d62a17ae 3108 as = strtoul(argv[idx_number]->arg, NULL, 10);
3109 ret = peer_local_as_set(peer, as, 0, 0);
3110 return bgp_vty_return(vty, ret);
718e3744 3111}
3112
3113DEFUN (neighbor_local_as_no_prepend,
3114 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3115 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3116 NEIGHBOR_STR
3117 NEIGHBOR_ADDR_STR2
3118 "Specify a local-as number\n"
3119 "AS number used as local AS\n"
3120 "Do not prepend local-as to updates from ebgp peers\n")
3121{
d62a17ae 3122 int idx_peer = 1;
3123 int idx_number = 3;
3124 struct peer *peer;
3125 int ret;
3126 as_t as;
718e3744 3127
d62a17ae 3128 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3129 if (!peer)
3130 return CMD_WARNING_CONFIG_FAILED;
718e3744 3131
d62a17ae 3132 as = strtoul(argv[idx_number]->arg, NULL, 10);
3133 ret = peer_local_as_set(peer, as, 1, 0);
3134 return bgp_vty_return(vty, ret);
718e3744 3135}
3136
9d3f9705
AC
3137DEFUN (neighbor_local_as_no_prepend_replace_as,
3138 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3139 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3140 NEIGHBOR_STR
3141 NEIGHBOR_ADDR_STR2
3142 "Specify a local-as number\n"
3143 "AS number used as local AS\n"
3144 "Do not prepend local-as to updates from ebgp peers\n"
3145 "Do not prepend local-as to updates from ibgp peers\n")
3146{
d62a17ae 3147 int idx_peer = 1;
3148 int idx_number = 3;
3149 struct peer *peer;
3150 int ret;
3151 as_t as;
9d3f9705 3152
d62a17ae 3153 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3154 if (!peer)
3155 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3156
d62a17ae 3157 as = strtoul(argv[idx_number]->arg, NULL, 10);
3158 ret = peer_local_as_set(peer, as, 1, 1);
3159 return bgp_vty_return(vty, ret);
9d3f9705
AC
3160}
3161
718e3744 3162DEFUN (no_neighbor_local_as,
3163 no_neighbor_local_as_cmd,
a636c635 3164 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3165 NO_STR
3166 NEIGHBOR_STR
3167 NEIGHBOR_ADDR_STR2
a636c635
DW
3168 "Specify a local-as number\n"
3169 "AS number used as local AS\n"
3170 "Do not prepend local-as to updates from ebgp peers\n"
3171 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3172{
d62a17ae 3173 int idx_peer = 2;
3174 struct peer *peer;
3175 int ret;
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 ret = peer_local_as_unset(peer);
3182 return bgp_vty_return(vty, ret);
718e3744 3183}
3184
718e3744 3185
3f9c7369
DS
3186DEFUN (neighbor_solo,
3187 neighbor_solo_cmd,
9ccf14f7 3188 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3189 NEIGHBOR_STR
3190 NEIGHBOR_ADDR_STR2
3191 "Solo peer - part of its own update group\n")
3192{
d62a17ae 3193 int idx_peer = 1;
3194 struct peer *peer;
3195 int ret;
3f9c7369 3196
d62a17ae 3197 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3198 if (!peer)
3199 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3200
d62a17ae 3201 ret = update_group_adjust_soloness(peer, 1);
3202 return bgp_vty_return(vty, ret);
3f9c7369
DS
3203}
3204
3205DEFUN (no_neighbor_solo,
3206 no_neighbor_solo_cmd,
9ccf14f7 3207 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3208 NO_STR
3209 NEIGHBOR_STR
3210 NEIGHBOR_ADDR_STR2
3211 "Solo peer - part of its own update group\n")
3212{
d62a17ae 3213 int idx_peer = 2;
3214 struct peer *peer;
3215 int ret;
3f9c7369 3216
d62a17ae 3217 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3218 if (!peer)
3219 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3220
d62a17ae 3221 ret = update_group_adjust_soloness(peer, 0);
3222 return bgp_vty_return(vty, ret);
3f9c7369
DS
3223}
3224
0df7c91f
PJ
3225DEFUN (neighbor_password,
3226 neighbor_password_cmd,
9ccf14f7 3227 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3228 NEIGHBOR_STR
3229 NEIGHBOR_ADDR_STR2
3230 "Set a password\n"
3231 "The password\n")
3232{
d62a17ae 3233 int idx_peer = 1;
3234 int idx_line = 3;
3235 struct peer *peer;
3236 int ret;
0df7c91f 3237
d62a17ae 3238 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3239 if (!peer)
3240 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3241
d62a17ae 3242 ret = peer_password_set(peer, argv[idx_line]->arg);
3243 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3244}
3245
3246DEFUN (no_neighbor_password,
3247 no_neighbor_password_cmd,
a636c635 3248 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3249 NO_STR
3250 NEIGHBOR_STR
3251 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3252 "Set a password\n"
3253 "The password\n")
0df7c91f 3254{
d62a17ae 3255 int idx_peer = 2;
3256 struct peer *peer;
3257 int ret;
0df7c91f 3258
d62a17ae 3259 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3260 if (!peer)
3261 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3262
d62a17ae 3263 ret = peer_password_unset(peer);
3264 return bgp_vty_return(vty, ret);
0df7c91f 3265}
6b0655a2 3266
718e3744 3267DEFUN (neighbor_activate,
3268 neighbor_activate_cmd,
9ccf14f7 3269 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3270 NEIGHBOR_STR
3271 NEIGHBOR_ADDR_STR2
3272 "Enable the Address Family for this Neighbor\n")
3273{
d62a17ae 3274 int idx_peer = 1;
3275 int ret;
3276 struct peer *peer;
718e3744 3277
d62a17ae 3278 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3279 if (!peer)
3280 return CMD_WARNING_CONFIG_FAILED;
718e3744 3281
d62a17ae 3282 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3283 return bgp_vty_return(vty, ret);
718e3744 3284}
3285
d62a17ae 3286ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3287 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3288 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3289 "Enable the Address Family for this Neighbor\n")
596c17ba 3290
718e3744 3291DEFUN (no_neighbor_activate,
3292 no_neighbor_activate_cmd,
9ccf14f7 3293 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3294 NO_STR
3295 NEIGHBOR_STR
3296 NEIGHBOR_ADDR_STR2
3297 "Enable the Address Family for this Neighbor\n")
3298{
d62a17ae 3299 int idx_peer = 2;
3300 int ret;
3301 struct peer *peer;
718e3744 3302
d62a17ae 3303 /* Lookup peer. */
3304 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3305 if (!peer)
3306 return CMD_WARNING_CONFIG_FAILED;
718e3744 3307
d62a17ae 3308 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3309 return bgp_vty_return(vty, ret);
718e3744 3310}
6b0655a2 3311
d62a17ae 3312ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3313 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3314 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3315 "Enable the Address Family for this Neighbor\n")
596c17ba 3316
718e3744 3317DEFUN (neighbor_set_peer_group,
3318 neighbor_set_peer_group_cmd,
9ccf14f7 3319 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3320 NEIGHBOR_STR
a80beece 3321 NEIGHBOR_ADDR_STR2
718e3744 3322 "Member of the peer-group\n"
16cedbb0 3323 "Peer-group name\n")
718e3744 3324{
d62a17ae 3325 VTY_DECLVAR_CONTEXT(bgp, bgp);
3326 int idx_peer = 1;
3327 int idx_word = 3;
3328 int ret;
3329 as_t as;
3330 union sockunion su;
3331 struct peer *peer;
3332 struct peer_group *group;
3333
3334 peer = NULL;
3335
3336 ret = str2sockunion(argv[idx_peer]->arg, &su);
3337 if (ret < 0) {
3338 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3339 if (!peer) {
3340 vty_out(vty, "%% Malformed address or name: %s\n",
3341 argv[idx_peer]->arg);
3342 return CMD_WARNING_CONFIG_FAILED;
3343 }
3344 } else {
3345 if (peer_address_self_check(bgp, &su)) {
3346 vty_out(vty,
3347 "%% Can not configure the local system as neighbor\n");
3348 return CMD_WARNING_CONFIG_FAILED;
3349 }
3350
3351 /* Disallow for dynamic neighbor. */
3352 peer = peer_lookup(bgp, &su);
3353 if (peer && peer_dynamic_neighbor(peer)) {
3354 vty_out(vty,
3355 "%% Operation not allowed on a dynamic neighbor\n");
3356 return CMD_WARNING_CONFIG_FAILED;
3357 }
3358 }
3359
3360 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3361 if (!group) {
3362 vty_out(vty, "%% Configure the peer-group first\n");
3363 return CMD_WARNING_CONFIG_FAILED;
3364 }
3365
3366 ret = peer_group_bind(bgp, &su, peer, group, &as);
3367
3368 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3369 vty_out(vty,
3370 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3371 as);
3372 return CMD_WARNING_CONFIG_FAILED;
3373 }
3374
3375 return bgp_vty_return(vty, ret);
3376}
3377
3378ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3379 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3380 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3381 "Member of the peer-group\n"
3382 "Peer-group name\n")
596c17ba 3383
718e3744 3384DEFUN (no_neighbor_set_peer_group,
3385 no_neighbor_set_peer_group_cmd,
9ccf14f7 3386 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3387 NO_STR
3388 NEIGHBOR_STR
a80beece 3389 NEIGHBOR_ADDR_STR2
718e3744 3390 "Member of the peer-group\n"
16cedbb0 3391 "Peer-group name\n")
718e3744 3392{
d62a17ae 3393 VTY_DECLVAR_CONTEXT(bgp, bgp);
3394 int idx_peer = 2;
3395 int idx_word = 4;
3396 int ret;
3397 struct peer *peer;
3398 struct peer_group *group;
3399
3400 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3401 if (!peer)
3402 return CMD_WARNING_CONFIG_FAILED;
3403
3404 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3405 if (!group) {
3406 vty_out(vty, "%% Configure the peer-group first\n");
3407 return CMD_WARNING_CONFIG_FAILED;
3408 }
718e3744 3409
827ed707 3410 ret = peer_delete(peer);
718e3744 3411
d62a17ae 3412 return bgp_vty_return(vty, ret);
718e3744 3413}
6b0655a2 3414
d62a17ae 3415ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3416 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3417 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3418 "Member of the peer-group\n"
3419 "Peer-group name\n")
596c17ba 3420
d62a17ae 3421static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
d7c0a89a 3422 uint16_t flag, int set)
718e3744 3423{
d62a17ae 3424 int ret;
3425 struct peer *peer;
718e3744 3426
d62a17ae 3427 peer = peer_and_group_lookup_vty(vty, ip_str);
3428 if (!peer)
3429 return CMD_WARNING_CONFIG_FAILED;
718e3744 3430
7ebe625c
QY
3431 /*
3432 * If 'neighbor <interface>', then this is for directly connected peers,
3433 * we should not accept disable-connected-check.
3434 */
3435 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3436 vty_out(vty,
3437 "%s is directly connected peer, cannot accept disable-"
3438 "connected-check\n",
3439 ip_str);
3440 return CMD_WARNING_CONFIG_FAILED;
3441 }
3442
d62a17ae 3443 if (!set && flag == PEER_FLAG_SHUTDOWN)
3444 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3445
d62a17ae 3446 if (set)
3447 ret = peer_flag_set(peer, flag);
3448 else
3449 ret = peer_flag_unset(peer, flag);
718e3744 3450
d62a17ae 3451 return bgp_vty_return(vty, ret);
718e3744 3452}
3453
d7c0a89a 3454static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint16_t flag)
718e3744 3455{
d62a17ae 3456 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3457}
3458
d62a17ae 3459static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
d7c0a89a 3460 uint16_t flag)
718e3744 3461{
d62a17ae 3462 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3463}
3464
3465/* neighbor passive. */
3466DEFUN (neighbor_passive,
3467 neighbor_passive_cmd,
9ccf14f7 3468 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3469 NEIGHBOR_STR
3470 NEIGHBOR_ADDR_STR2
3471 "Don't send open messages to this neighbor\n")
3472{
d62a17ae 3473 int idx_peer = 1;
3474 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3475}
3476
3477DEFUN (no_neighbor_passive,
3478 no_neighbor_passive_cmd,
9ccf14f7 3479 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3480 NO_STR
3481 NEIGHBOR_STR
3482 NEIGHBOR_ADDR_STR2
3483 "Don't send open messages to this neighbor\n")
3484{
d62a17ae 3485 int idx_peer = 2;
3486 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3487}
6b0655a2 3488
718e3744 3489/* neighbor shutdown. */
73d70fa6
DL
3490DEFUN (neighbor_shutdown_msg,
3491 neighbor_shutdown_msg_cmd,
3492 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3493 NEIGHBOR_STR
3494 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3495 "Administratively shut down this neighbor\n"
3496 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3497 "Shutdown message\n")
718e3744 3498{
d62a17ae 3499 int idx_peer = 1;
73d70fa6 3500
d62a17ae 3501 if (argc >= 5) {
3502 struct peer *peer =
3503 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3504 char *message;
73d70fa6 3505
d62a17ae 3506 if (!peer)
3507 return CMD_WARNING_CONFIG_FAILED;
3508 message = argv_concat(argv, argc, 4);
3509 peer_tx_shutdown_message_set(peer, message);
3510 XFREE(MTYPE_TMP, message);
3511 }
73d70fa6 3512
d62a17ae 3513 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3514}
3515
d62a17ae 3516ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3517 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3518 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3519 "Administratively shut down this neighbor\n")
73d70fa6
DL
3520
3521DEFUN (no_neighbor_shutdown_msg,
3522 no_neighbor_shutdown_msg_cmd,
3523 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3524 NO_STR
3525 NEIGHBOR_STR
3526 NEIGHBOR_ADDR_STR2
3527 "Administratively shut down this neighbor\n"
3528 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3529 "Shutdown message\n")
718e3744 3530{
d62a17ae 3531 int idx_peer = 2;
73d70fa6 3532
d62a17ae 3533 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3534 PEER_FLAG_SHUTDOWN);
718e3744 3535}
6b0655a2 3536
d62a17ae 3537ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3538 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3539 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3540 "Administratively shut down this neighbor\n")
73d70fa6 3541
718e3744 3542/* neighbor capability dynamic. */
3543DEFUN (neighbor_capability_dynamic,
3544 neighbor_capability_dynamic_cmd,
9ccf14f7 3545 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3546 NEIGHBOR_STR
3547 NEIGHBOR_ADDR_STR2
3548 "Advertise capability to the peer\n"
3549 "Advertise dynamic capability to this neighbor\n")
3550{
d62a17ae 3551 int idx_peer = 1;
3552 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3553 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3554}
3555
3556DEFUN (no_neighbor_capability_dynamic,
3557 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3558 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3559 NO_STR
3560 NEIGHBOR_STR
3561 NEIGHBOR_ADDR_STR2
3562 "Advertise capability to the peer\n"
3563 "Advertise dynamic capability to this neighbor\n")
3564{
d62a17ae 3565 int idx_peer = 2;
3566 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3567 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3568}
6b0655a2 3569
718e3744 3570/* neighbor dont-capability-negotiate */
3571DEFUN (neighbor_dont_capability_negotiate,
3572 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3573 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3574 NEIGHBOR_STR
3575 NEIGHBOR_ADDR_STR2
3576 "Do not perform capability negotiation\n")
3577{
d62a17ae 3578 int idx_peer = 1;
3579 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3580 PEER_FLAG_DONT_CAPABILITY);
718e3744 3581}
3582
3583DEFUN (no_neighbor_dont_capability_negotiate,
3584 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3585 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3586 NO_STR
3587 NEIGHBOR_STR
3588 NEIGHBOR_ADDR_STR2
3589 "Do not perform capability negotiation\n")
3590{
d62a17ae 3591 int idx_peer = 2;
3592 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3593 PEER_FLAG_DONT_CAPABILITY);
718e3744 3594}
6b0655a2 3595
8a92a8a0
DS
3596/* neighbor capability extended next hop encoding */
3597DEFUN (neighbor_capability_enhe,
3598 neighbor_capability_enhe_cmd,
9ccf14f7 3599 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3600 NEIGHBOR_STR
3601 NEIGHBOR_ADDR_STR2
3602 "Advertise capability to the peer\n"
3603 "Advertise extended next-hop capability to the peer\n")
3604{
d62a17ae 3605 int idx_peer = 1;
3606 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3607 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3608}
3609
3610DEFUN (no_neighbor_capability_enhe,
3611 no_neighbor_capability_enhe_cmd,
9ccf14f7 3612 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3613 NO_STR
3614 NEIGHBOR_STR
3615 NEIGHBOR_ADDR_STR2
3616 "Advertise capability to the peer\n"
3617 "Advertise extended next-hop capability to the peer\n")
3618{
d62a17ae 3619 int idx_peer = 2;
3620 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3621 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3622}
3623
d62a17ae 3624static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3625 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3626 int set)
718e3744 3627{
d62a17ae 3628 int ret;
3629 struct peer *peer;
718e3744 3630
d62a17ae 3631 peer = peer_and_group_lookup_vty(vty, peer_str);
3632 if (!peer)
3633 return CMD_WARNING_CONFIG_FAILED;
718e3744 3634
d62a17ae 3635 if (set)
3636 ret = peer_af_flag_set(peer, afi, safi, flag);
3637 else
3638 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3639
d62a17ae 3640 return bgp_vty_return(vty, ret);
718e3744 3641}
3642
d62a17ae 3643static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3644 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3645{
d62a17ae 3646 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3647}
3648
d62a17ae 3649static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3650 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3651{
d62a17ae 3652 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3653}
6b0655a2 3654
718e3744 3655/* neighbor capability orf prefix-list. */
3656DEFUN (neighbor_capability_orf_prefix,
3657 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3658 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3659 NEIGHBOR_STR
3660 NEIGHBOR_ADDR_STR2
3661 "Advertise capability to the peer\n"
3662 "Advertise ORF capability to the peer\n"
3663 "Advertise prefixlist ORF capability to this neighbor\n"
3664 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3665 "Capability to RECEIVE the ORF from this neighbor\n"
3666 "Capability to SEND the ORF to this neighbor\n")
3667{
d62a17ae 3668 int idx_peer = 1;
3669 int idx_send_recv = 5;
d7c0a89a 3670 uint16_t flag = 0;
d62a17ae 3671
3672 if (strmatch(argv[idx_send_recv]->text, "send"))
3673 flag = PEER_FLAG_ORF_PREFIX_SM;
3674 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3675 flag = PEER_FLAG_ORF_PREFIX_RM;
3676 else if (strmatch(argv[idx_send_recv]->text, "both"))
3677 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3678 else {
3679 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3680 return CMD_WARNING_CONFIG_FAILED;
3681 }
3682
3683 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3684 bgp_node_safi(vty), flag);
3685}
3686
3687ALIAS_HIDDEN(
3688 neighbor_capability_orf_prefix,
3689 neighbor_capability_orf_prefix_hidden_cmd,
3690 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3691 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3692 "Advertise capability to the peer\n"
3693 "Advertise ORF capability to the peer\n"
3694 "Advertise prefixlist ORF capability to this neighbor\n"
3695 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3696 "Capability to RECEIVE the ORF from this neighbor\n"
3697 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3698
718e3744 3699DEFUN (no_neighbor_capability_orf_prefix,
3700 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3701 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3702 NO_STR
3703 NEIGHBOR_STR
3704 NEIGHBOR_ADDR_STR2
3705 "Advertise capability to the peer\n"
3706 "Advertise ORF capability to the peer\n"
3707 "Advertise prefixlist ORF capability to this neighbor\n"
3708 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3709 "Capability to RECEIVE the ORF from this neighbor\n"
3710 "Capability to SEND the ORF to this neighbor\n")
3711{
d62a17ae 3712 int idx_peer = 2;
3713 int idx_send_recv = 6;
d7c0a89a 3714 uint16_t flag = 0;
d62a17ae 3715
3716 if (strmatch(argv[idx_send_recv]->text, "send"))
3717 flag = PEER_FLAG_ORF_PREFIX_SM;
3718 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3719 flag = PEER_FLAG_ORF_PREFIX_RM;
3720 else if (strmatch(argv[idx_send_recv]->text, "both"))
3721 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3722 else {
3723 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3724 return CMD_WARNING_CONFIG_FAILED;
3725 }
3726
3727 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3728 bgp_node_afi(vty), bgp_node_safi(vty),
3729 flag);
3730}
3731
3732ALIAS_HIDDEN(
3733 no_neighbor_capability_orf_prefix,
3734 no_neighbor_capability_orf_prefix_hidden_cmd,
3735 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3736 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3737 "Advertise capability to the peer\n"
3738 "Advertise ORF capability to the peer\n"
3739 "Advertise prefixlist ORF capability to this neighbor\n"
3740 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3741 "Capability to RECEIVE the ORF from this neighbor\n"
3742 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3743
718e3744 3744/* neighbor next-hop-self. */
3745DEFUN (neighbor_nexthop_self,
3746 neighbor_nexthop_self_cmd,
9ccf14f7 3747 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3748 NEIGHBOR_STR
3749 NEIGHBOR_ADDR_STR2
a538debe 3750 "Disable the next hop calculation for this neighbor\n")
718e3744 3751{
d62a17ae 3752 int idx_peer = 1;
3753 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3754 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3755}
9e7a53c1 3756
d62a17ae 3757ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3758 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3759 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3760 "Disable the next hop calculation for this neighbor\n")
596c17ba 3761
a538debe
DS
3762/* neighbor next-hop-self. */
3763DEFUN (neighbor_nexthop_self_force,
3764 neighbor_nexthop_self_force_cmd,
9ccf14f7 3765 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3766 NEIGHBOR_STR
3767 NEIGHBOR_ADDR_STR2
3768 "Disable the next hop calculation for this neighbor\n"
3769 "Set the next hop to self for reflected routes\n")
3770{
d62a17ae 3771 int idx_peer = 1;
3772 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3773 bgp_node_safi(vty),
3774 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3775}
3776
d62a17ae 3777ALIAS_HIDDEN(neighbor_nexthop_self_force,
3778 neighbor_nexthop_self_force_hidden_cmd,
3779 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3780 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3781 "Disable the next hop calculation for this neighbor\n"
3782 "Set the next hop to self for reflected routes\n")
596c17ba 3783
718e3744 3784DEFUN (no_neighbor_nexthop_self,
3785 no_neighbor_nexthop_self_cmd,
9ccf14f7 3786 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3787 NO_STR
3788 NEIGHBOR_STR
3789 NEIGHBOR_ADDR_STR2
a538debe 3790 "Disable the next hop calculation for this neighbor\n")
718e3744 3791{
d62a17ae 3792 int idx_peer = 2;
3793 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3794 bgp_node_afi(vty), bgp_node_safi(vty),
3795 PEER_FLAG_NEXTHOP_SELF);
718e3744 3796}
6b0655a2 3797
d62a17ae 3798ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3799 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3800 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3801 "Disable the next hop calculation for this neighbor\n")
596c17ba 3802
88b8ed8d 3803DEFUN (no_neighbor_nexthop_self_force,
a538debe 3804 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3805 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3806 NO_STR
3807 NEIGHBOR_STR
3808 NEIGHBOR_ADDR_STR2
3809 "Disable the next hop calculation for this neighbor\n"
3810 "Set the next hop to self for reflected routes\n")
88b8ed8d 3811{
d62a17ae 3812 int idx_peer = 2;
3813 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3814 bgp_node_afi(vty), bgp_node_safi(vty),
3815 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3816}
a538debe 3817
d62a17ae 3818ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3819 no_neighbor_nexthop_self_force_hidden_cmd,
3820 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3821 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3822 "Disable the next hop calculation for this neighbor\n"
3823 "Set the next hop to self for reflected routes\n")
596c17ba 3824
c7122e14
DS
3825/* neighbor as-override */
3826DEFUN (neighbor_as_override,
3827 neighbor_as_override_cmd,
9ccf14f7 3828 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3829 NEIGHBOR_STR
3830 NEIGHBOR_ADDR_STR2
3831 "Override ASNs in outbound updates if aspath equals remote-as\n")
3832{
d62a17ae 3833 int idx_peer = 1;
3834 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3835 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3836}
3837
d62a17ae 3838ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3839 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3840 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3841 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3842
c7122e14
DS
3843DEFUN (no_neighbor_as_override,
3844 no_neighbor_as_override_cmd,
9ccf14f7 3845 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3846 NO_STR
3847 NEIGHBOR_STR
3848 NEIGHBOR_ADDR_STR2
3849 "Override ASNs in outbound updates if aspath equals remote-as\n")
3850{
d62a17ae 3851 int idx_peer = 2;
3852 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3853 bgp_node_afi(vty), bgp_node_safi(vty),
3854 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3855}
3856
d62a17ae 3857ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3858 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3859 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3860 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3861
718e3744 3862/* neighbor remove-private-AS. */
3863DEFUN (neighbor_remove_private_as,
3864 neighbor_remove_private_as_cmd,
9ccf14f7 3865 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3866 NEIGHBOR_STR
3867 NEIGHBOR_ADDR_STR2
5000f21c 3868 "Remove private ASNs in outbound updates\n")
718e3744 3869{
d62a17ae 3870 int idx_peer = 1;
3871 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3872 bgp_node_safi(vty),
3873 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3874}
3875
d62a17ae 3876ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3877 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3878 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3879 "Remove private ASNs in outbound updates\n")
596c17ba 3880
5000f21c
DS
3881DEFUN (neighbor_remove_private_as_all,
3882 neighbor_remove_private_as_all_cmd,
9ccf14f7 3883 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3884 NEIGHBOR_STR
3885 NEIGHBOR_ADDR_STR2
3886 "Remove private ASNs in outbound updates\n"
efd7904e 3887 "Apply to all AS numbers\n")
5000f21c 3888{
d62a17ae 3889 int idx_peer = 1;
3890 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3891 bgp_node_safi(vty),
3892 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3893}
3894
d62a17ae 3895ALIAS_HIDDEN(neighbor_remove_private_as_all,
3896 neighbor_remove_private_as_all_hidden_cmd,
3897 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3898 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3899 "Remove private ASNs in outbound updates\n"
3900 "Apply to all AS numbers")
596c17ba 3901
5000f21c
DS
3902DEFUN (neighbor_remove_private_as_replace_as,
3903 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3904 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3905 NEIGHBOR_STR
3906 NEIGHBOR_ADDR_STR2
3907 "Remove private ASNs in outbound updates\n"
3908 "Replace private ASNs with our ASN in outbound updates\n")
3909{
d62a17ae 3910 int idx_peer = 1;
3911 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3912 bgp_node_safi(vty),
3913 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3914}
3915
d62a17ae 3916ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3917 neighbor_remove_private_as_replace_as_hidden_cmd,
3918 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3919 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3920 "Remove private ASNs in outbound updates\n"
3921 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3922
5000f21c
DS
3923DEFUN (neighbor_remove_private_as_all_replace_as,
3924 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3925 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3926 NEIGHBOR_STR
3927 NEIGHBOR_ADDR_STR2
3928 "Remove private ASNs in outbound updates\n"
16cedbb0 3929 "Apply to all AS numbers\n"
5000f21c
DS
3930 "Replace private ASNs with our ASN in outbound updates\n")
3931{
d62a17ae 3932 int idx_peer = 1;
3933 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3934 bgp_node_safi(vty),
3935 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3936}
3937
d62a17ae 3938ALIAS_HIDDEN(
3939 neighbor_remove_private_as_all_replace_as,
3940 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3941 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3942 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3943 "Remove private ASNs in outbound updates\n"
3944 "Apply to all AS numbers\n"
3945 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3946
718e3744 3947DEFUN (no_neighbor_remove_private_as,
3948 no_neighbor_remove_private_as_cmd,
9ccf14f7 3949 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3950 NO_STR
3951 NEIGHBOR_STR
3952 NEIGHBOR_ADDR_STR2
5000f21c 3953 "Remove private ASNs in outbound updates\n")
718e3744 3954{
d62a17ae 3955 int idx_peer = 2;
3956 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3957 bgp_node_afi(vty), bgp_node_safi(vty),
3958 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3959}
6b0655a2 3960
d62a17ae 3961ALIAS_HIDDEN(no_neighbor_remove_private_as,
3962 no_neighbor_remove_private_as_hidden_cmd,
3963 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3964 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3965 "Remove private ASNs in outbound updates\n")
596c17ba 3966
88b8ed8d 3967DEFUN (no_neighbor_remove_private_as_all,
5000f21c 3968 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 3969 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3970 NO_STR
3971 NEIGHBOR_STR
3972 NEIGHBOR_ADDR_STR2
3973 "Remove private ASNs in outbound updates\n"
16cedbb0 3974 "Apply to all AS numbers\n")
88b8ed8d 3975{
d62a17ae 3976 int idx_peer = 2;
3977 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3978 bgp_node_afi(vty), bgp_node_safi(vty),
3979 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 3980}
5000f21c 3981
d62a17ae 3982ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
3983 no_neighbor_remove_private_as_all_hidden_cmd,
3984 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3985 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3986 "Remove private ASNs in outbound updates\n"
3987 "Apply to all AS numbers\n")
596c17ba 3988
88b8ed8d 3989DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 3990 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3991 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3992 NO_STR
3993 NEIGHBOR_STR
3994 NEIGHBOR_ADDR_STR2
3995 "Remove private ASNs in outbound updates\n"
3996 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 3997{
d62a17ae 3998 int idx_peer = 2;
3999 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4000 bgp_node_afi(vty), bgp_node_safi(vty),
4001 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4002}
5000f21c 4003
d62a17ae 4004ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4005 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4006 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4007 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4008 "Remove private ASNs in outbound updates\n"
4009 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4010
88b8ed8d 4011DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4012 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4013 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4014 NO_STR
4015 NEIGHBOR_STR
4016 NEIGHBOR_ADDR_STR2
4017 "Remove private ASNs in outbound updates\n"
16cedbb0 4018 "Apply to all AS numbers\n"
5000f21c 4019 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4020{
d62a17ae 4021 int idx_peer = 2;
4022 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4023 bgp_node_afi(vty), bgp_node_safi(vty),
4024 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4025}
5000f21c 4026
d62a17ae 4027ALIAS_HIDDEN(
4028 no_neighbor_remove_private_as_all_replace_as,
4029 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4030 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4031 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4032 "Remove private ASNs in outbound updates\n"
4033 "Apply to all AS numbers\n"
4034 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4035
5000f21c 4036
718e3744 4037/* neighbor send-community. */
4038DEFUN (neighbor_send_community,
4039 neighbor_send_community_cmd,
9ccf14f7 4040 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4041 NEIGHBOR_STR
4042 NEIGHBOR_ADDR_STR2
4043 "Send Community attribute to this neighbor\n")
4044{
d62a17ae 4045 int idx_peer = 1;
4046 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4047 bgp_node_safi(vty),
4048 PEER_FLAG_SEND_COMMUNITY);
718e3744 4049}
4050
d62a17ae 4051ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4052 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4053 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4054 "Send Community attribute to this neighbor\n")
596c17ba 4055
718e3744 4056DEFUN (no_neighbor_send_community,
4057 no_neighbor_send_community_cmd,
9ccf14f7 4058 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4059 NO_STR
4060 NEIGHBOR_STR
4061 NEIGHBOR_ADDR_STR2
4062 "Send Community attribute to this neighbor\n")
4063{
d62a17ae 4064 int idx_peer = 2;
4065 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4066 bgp_node_afi(vty), bgp_node_safi(vty),
4067 PEER_FLAG_SEND_COMMUNITY);
718e3744 4068}
6b0655a2 4069
d62a17ae 4070ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4071 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4072 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4073 "Send Community attribute to this neighbor\n")
596c17ba 4074
718e3744 4075/* neighbor send-community extended. */
4076DEFUN (neighbor_send_community_type,
4077 neighbor_send_community_type_cmd,
57d187bc 4078 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4079 NEIGHBOR_STR
4080 NEIGHBOR_ADDR_STR2
4081 "Send Community attribute to this neighbor\n"
4082 "Send Standard and Extended Community attributes\n"
57d187bc 4083 "Send Standard, Large and Extended Community attributes\n"
718e3744 4084 "Send Extended Community attributes\n"
57d187bc
JS
4085 "Send Standard Community attributes\n"
4086 "Send Large Community attributes\n")
718e3744 4087{
d62a17ae 4088 int idx = 0;
d7c0a89a 4089 uint32_t flag = 0;
d62a17ae 4090
4091 char *peer = argv[1]->arg;
4092
4093 if (argv_find(argv, argc, "standard", &idx))
4094 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4095 else if (argv_find(argv, argc, "extended", &idx))
4096 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4097 else if (argv_find(argv, argc, "large", &idx))
4098 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4099 else if (argv_find(argv, argc, "both", &idx)) {
4100 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4101 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4102 } else {
4103 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4104 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4105 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4106 }
4107
4108 return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty),
4109 bgp_node_safi(vty), flag);
4110}
4111
4112ALIAS_HIDDEN(
4113 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4114 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4115 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4116 "Send Community attribute to this neighbor\n"
4117 "Send Standard and Extended Community attributes\n"
4118 "Send Standard, Large and Extended Community attributes\n"
4119 "Send Extended Community attributes\n"
4120 "Send Standard Community attributes\n"
4121 "Send Large Community attributes\n")
596c17ba 4122
718e3744 4123DEFUN (no_neighbor_send_community_type,
4124 no_neighbor_send_community_type_cmd,
57d187bc 4125 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4126 NO_STR
4127 NEIGHBOR_STR
4128 NEIGHBOR_ADDR_STR2
4129 "Send Community attribute to this neighbor\n"
4130 "Send Standard and Extended Community attributes\n"
57d187bc 4131 "Send Standard, Large and Extended Community attributes\n"
718e3744 4132 "Send Extended Community attributes\n"
57d187bc
JS
4133 "Send Standard Community attributes\n"
4134 "Send Large Community attributes\n")
718e3744 4135{
d62a17ae 4136 int idx_peer = 2;
4137
4138 const char *type = argv[argc - 1]->text;
4139
4140 if (strmatch(type, "standard"))
4141 return peer_af_flag_unset_vty(
4142 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4143 bgp_node_safi(vty), PEER_FLAG_SEND_COMMUNITY);
4144 if (strmatch(type, "extended"))
4145 return peer_af_flag_unset_vty(
4146 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4147 bgp_node_safi(vty), PEER_FLAG_SEND_EXT_COMMUNITY);
4148 if (strmatch(type, "large"))
4149 return peer_af_flag_unset_vty(
4150 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4151 bgp_node_safi(vty), PEER_FLAG_SEND_LARGE_COMMUNITY);
4152 if (strmatch(type, "both"))
4153 return peer_af_flag_unset_vty(
4154 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4155 bgp_node_safi(vty),
4156 PEER_FLAG_SEND_COMMUNITY
4157 | PEER_FLAG_SEND_EXT_COMMUNITY);
4158
4159 /* if (strmatch (type, "all")) */
4160 return peer_af_flag_unset_vty(
4161 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4162 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY
4163 | PEER_FLAG_SEND_LARGE_COMMUNITY));
4164}
4165
4166ALIAS_HIDDEN(
4167 no_neighbor_send_community_type,
4168 no_neighbor_send_community_type_hidden_cmd,
4169 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4170 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4171 "Send Community attribute to this neighbor\n"
4172 "Send Standard and Extended Community attributes\n"
4173 "Send Standard, Large and Extended Community attributes\n"
4174 "Send Extended Community attributes\n"
4175 "Send Standard Community attributes\n"
4176 "Send Large Community attributes\n")
596c17ba 4177
718e3744 4178/* neighbor soft-reconfig. */
4179DEFUN (neighbor_soft_reconfiguration,
4180 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4181 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4182 NEIGHBOR_STR
4183 NEIGHBOR_ADDR_STR2
4184 "Per neighbor soft reconfiguration\n"
4185 "Allow inbound soft reconfiguration for this neighbor\n")
4186{
d62a17ae 4187 int idx_peer = 1;
4188 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4189 bgp_node_safi(vty),
4190 PEER_FLAG_SOFT_RECONFIG);
718e3744 4191}
4192
d62a17ae 4193ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4194 neighbor_soft_reconfiguration_hidden_cmd,
4195 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4196 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4197 "Per neighbor soft reconfiguration\n"
4198 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4199
718e3744 4200DEFUN (no_neighbor_soft_reconfiguration,
4201 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4202 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4203 NO_STR
4204 NEIGHBOR_STR
4205 NEIGHBOR_ADDR_STR2
4206 "Per neighbor soft reconfiguration\n"
4207 "Allow inbound soft reconfiguration for this neighbor\n")
4208{
d62a17ae 4209 int idx_peer = 2;
4210 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4211 bgp_node_afi(vty), bgp_node_safi(vty),
4212 PEER_FLAG_SOFT_RECONFIG);
718e3744 4213}
6b0655a2 4214
d62a17ae 4215ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4216 no_neighbor_soft_reconfiguration_hidden_cmd,
4217 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4218 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4219 "Per neighbor soft reconfiguration\n"
4220 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4221
718e3744 4222DEFUN (neighbor_route_reflector_client,
4223 neighbor_route_reflector_client_cmd,
9ccf14f7 4224 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4225 NEIGHBOR_STR
4226 NEIGHBOR_ADDR_STR2
4227 "Configure a neighbor as Route Reflector client\n")
4228{
d62a17ae 4229 int idx_peer = 1;
4230 struct peer *peer;
718e3744 4231
4232
d62a17ae 4233 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4234 if (!peer)
4235 return CMD_WARNING_CONFIG_FAILED;
718e3744 4236
d62a17ae 4237 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4238 bgp_node_safi(vty),
4239 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4240}
4241
d62a17ae 4242ALIAS_HIDDEN(neighbor_route_reflector_client,
4243 neighbor_route_reflector_client_hidden_cmd,
4244 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4245 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4246 "Configure a neighbor as Route Reflector client\n")
596c17ba 4247
718e3744 4248DEFUN (no_neighbor_route_reflector_client,
4249 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4250 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4251 NO_STR
4252 NEIGHBOR_STR
4253 NEIGHBOR_ADDR_STR2
4254 "Configure a neighbor as Route Reflector client\n")
4255{
d62a17ae 4256 int idx_peer = 2;
4257 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4258 bgp_node_afi(vty), bgp_node_safi(vty),
4259 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4260}
6b0655a2 4261
d62a17ae 4262ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4263 no_neighbor_route_reflector_client_hidden_cmd,
4264 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4265 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4266 "Configure a neighbor as Route Reflector client\n")
596c17ba 4267
718e3744 4268/* neighbor route-server-client. */
4269DEFUN (neighbor_route_server_client,
4270 neighbor_route_server_client_cmd,
9ccf14f7 4271 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4272 NEIGHBOR_STR
4273 NEIGHBOR_ADDR_STR2
4274 "Configure a neighbor as Route Server client\n")
4275{
d62a17ae 4276 int idx_peer = 1;
4277 struct peer *peer;
2a3d5731 4278
d62a17ae 4279 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4280 if (!peer)
4281 return CMD_WARNING_CONFIG_FAILED;
4282 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4283 bgp_node_safi(vty),
4284 PEER_FLAG_RSERVER_CLIENT);
718e3744 4285}
4286
d62a17ae 4287ALIAS_HIDDEN(neighbor_route_server_client,
4288 neighbor_route_server_client_hidden_cmd,
4289 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4290 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4291 "Configure a neighbor as Route Server client\n")
596c17ba 4292
718e3744 4293DEFUN (no_neighbor_route_server_client,
4294 no_neighbor_route_server_client_cmd,
9ccf14f7 4295 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4296 NO_STR
4297 NEIGHBOR_STR
4298 NEIGHBOR_ADDR_STR2
4299 "Configure a neighbor as Route Server client\n")
fee0f4c6 4300{
d62a17ae 4301 int idx_peer = 2;
4302 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4303 bgp_node_afi(vty), bgp_node_safi(vty),
4304 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4305}
6b0655a2 4306
d62a17ae 4307ALIAS_HIDDEN(no_neighbor_route_server_client,
4308 no_neighbor_route_server_client_hidden_cmd,
4309 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4310 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4311 "Configure a neighbor as Route Server client\n")
596c17ba 4312
fee0f4c6 4313DEFUN (neighbor_nexthop_local_unchanged,
4314 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4315 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4316 NEIGHBOR_STR
4317 NEIGHBOR_ADDR_STR2
4318 "Configure treatment of outgoing link-local nexthop attribute\n"
4319 "Leave link-local nexthop unchanged for this peer\n")
4320{
d62a17ae 4321 int idx_peer = 1;
4322 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4323 bgp_node_safi(vty),
4324 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4325}
6b0655a2 4326
fee0f4c6 4327DEFUN (no_neighbor_nexthop_local_unchanged,
4328 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4329 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4330 NO_STR
4331 NEIGHBOR_STR
4332 NEIGHBOR_ADDR_STR2
4333 "Configure treatment of outgoing link-local-nexthop attribute\n"
4334 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4335{
d62a17ae 4336 int idx_peer = 2;
4337 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4338 bgp_node_afi(vty), bgp_node_safi(vty),
4339 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4340}
6b0655a2 4341
718e3744 4342DEFUN (neighbor_attr_unchanged,
4343 neighbor_attr_unchanged_cmd,
a8206004 4344 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4345 NEIGHBOR_STR
4346 NEIGHBOR_ADDR_STR2
4347 "BGP attribute is propagated unchanged to this neighbor\n"
4348 "As-path attribute\n"
4349 "Nexthop attribute\n"
a8206004 4350 "Med attribute\n")
718e3744 4351{
d62a17ae 4352 int idx = 0;
8eeb0335
DW
4353 char *peer_str = argv[1]->arg;
4354 struct peer *peer;
d7c0a89a 4355 uint16_t flags = 0;
8eeb0335
DW
4356 afi_t afi = bgp_node_afi(vty);
4357 safi_t safi = bgp_node_safi(vty);
4358
4359 peer = peer_and_group_lookup_vty(vty, peer_str);
4360 if (!peer)
4361 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4362
4363 if (argv_find(argv, argc, "as-path", &idx))
4364 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4365 idx = 0;
4366 if (argv_find(argv, argc, "next-hop", &idx))
4367 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4368 idx = 0;
4369 if (argv_find(argv, argc, "med", &idx))
4370 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4371
8eeb0335
DW
4372 /* no flags means all of them! */
4373 if (!flags) {
d62a17ae 4374 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4375 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4376 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4377 } else {
a4d82a8a
PZ
4378 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4379 && peer_af_flag_check(peer, afi, safi,
4380 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4381 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4382 PEER_FLAG_AS_PATH_UNCHANGED);
4383 }
4384
a4d82a8a
PZ
4385 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4386 && peer_af_flag_check(peer, afi, safi,
4387 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4388 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4389 PEER_FLAG_NEXTHOP_UNCHANGED);
4390 }
4391
a4d82a8a
PZ
4392 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4393 && peer_af_flag_check(peer, afi, safi,
4394 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4395 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4396 PEER_FLAG_MED_UNCHANGED);
4397 }
d62a17ae 4398 }
4399
8eeb0335 4400 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4401}
4402
4403ALIAS_HIDDEN(
4404 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4405 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4406 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4407 "BGP attribute is propagated unchanged to this neighbor\n"
4408 "As-path attribute\n"
4409 "Nexthop attribute\n"
4410 "Med attribute\n")
596c17ba 4411
718e3744 4412DEFUN (no_neighbor_attr_unchanged,
4413 no_neighbor_attr_unchanged_cmd,
a8206004 4414 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4415 NO_STR
718e3744 4416 NEIGHBOR_STR
4417 NEIGHBOR_ADDR_STR2
31500417
DW
4418 "BGP attribute is propagated unchanged to this neighbor\n"
4419 "As-path attribute\n"
40e718b5 4420 "Nexthop attribute\n"
a8206004 4421 "Med attribute\n")
718e3744 4422{
d62a17ae 4423 int idx = 0;
4424 char *peer = argv[2]->arg;
d7c0a89a 4425 uint16_t flags = 0;
d62a17ae 4426
4427 if (argv_find(argv, argc, "as-path", &idx))
4428 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4429 idx = 0;
4430 if (argv_find(argv, argc, "next-hop", &idx))
4431 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4432 idx = 0;
4433 if (argv_find(argv, argc, "med", &idx))
4434 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4435
4436 if (!flags) // no flags means all of them!
4437 {
4438 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4439 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4440 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4441 }
4442
4443 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4444 bgp_node_safi(vty), flags);
4445}
4446
4447ALIAS_HIDDEN(
4448 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4449 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4450 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4451 "BGP attribute is propagated unchanged to this neighbor\n"
4452 "As-path attribute\n"
4453 "Nexthop attribute\n"
4454 "Med attribute\n")
718e3744 4455
718e3744 4456/* EBGP multihop configuration. */
d62a17ae 4457static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4458 const char *ttl_str)
718e3744 4459{
d62a17ae 4460 struct peer *peer;
4461 unsigned int ttl;
718e3744 4462
d62a17ae 4463 peer = peer_and_group_lookup_vty(vty, ip_str);
4464 if (!peer)
4465 return CMD_WARNING_CONFIG_FAILED;
718e3744 4466
d62a17ae 4467 if (peer->conf_if)
4468 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4469
d62a17ae 4470 if (!ttl_str)
4471 ttl = MAXTTL;
4472 else
4473 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4474
d62a17ae 4475 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4476}
4477
d62a17ae 4478static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4479{
d62a17ae 4480 struct peer *peer;
718e3744 4481
d62a17ae 4482 peer = peer_and_group_lookup_vty(vty, ip_str);
4483 if (!peer)
4484 return CMD_WARNING_CONFIG_FAILED;
718e3744 4485
d62a17ae 4486 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4487}
4488
4489/* neighbor ebgp-multihop. */
4490DEFUN (neighbor_ebgp_multihop,
4491 neighbor_ebgp_multihop_cmd,
9ccf14f7 4492 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4493 NEIGHBOR_STR
4494 NEIGHBOR_ADDR_STR2
4495 "Allow EBGP neighbors not on directly connected networks\n")
4496{
d62a17ae 4497 int idx_peer = 1;
4498 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4499}
4500
4501DEFUN (neighbor_ebgp_multihop_ttl,
4502 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4503 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4504 NEIGHBOR_STR
4505 NEIGHBOR_ADDR_STR2
4506 "Allow EBGP neighbors not on directly connected networks\n"
4507 "maximum hop count\n")
4508{
d62a17ae 4509 int idx_peer = 1;
4510 int idx_number = 3;
4511 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4512 argv[idx_number]->arg);
718e3744 4513}
4514
4515DEFUN (no_neighbor_ebgp_multihop,
4516 no_neighbor_ebgp_multihop_cmd,
a636c635 4517 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4518 NO_STR
4519 NEIGHBOR_STR
4520 NEIGHBOR_ADDR_STR2
a636c635
DW
4521 "Allow EBGP neighbors not on directly connected networks\n"
4522 "maximum hop count\n")
718e3744 4523{
d62a17ae 4524 int idx_peer = 2;
4525 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4526}
4527
6b0655a2 4528
6ffd2079 4529/* disable-connected-check */
4530DEFUN (neighbor_disable_connected_check,
4531 neighbor_disable_connected_check_cmd,
7ebe625c 4532 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4533 NEIGHBOR_STR
7ebe625c 4534 NEIGHBOR_ADDR_STR2
a636c635
DW
4535 "one-hop away EBGP peer using loopback address\n"
4536 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4537{
d62a17ae 4538 int idx_peer = 1;
4539 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4540 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4541}
4542
4543DEFUN (no_neighbor_disable_connected_check,
4544 no_neighbor_disable_connected_check_cmd,
7ebe625c 4545 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4546 NO_STR
4547 NEIGHBOR_STR
7ebe625c 4548 NEIGHBOR_ADDR_STR2
a636c635
DW
4549 "one-hop away EBGP peer using loopback address\n"
4550 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4551{
d62a17ae 4552 int idx_peer = 2;
4553 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4554 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4555}
4556
718e3744 4557DEFUN (neighbor_description,
4558 neighbor_description_cmd,
e961923c 4559 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4560 NEIGHBOR_STR
4561 NEIGHBOR_ADDR_STR2
4562 "Neighbor specific description\n"
4563 "Up to 80 characters describing this neighbor\n")
4564{
d62a17ae 4565 int idx_peer = 1;
4566 int idx_line = 3;
4567 struct peer *peer;
4568 char *str;
718e3744 4569
d62a17ae 4570 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4571 if (!peer)
4572 return CMD_WARNING_CONFIG_FAILED;
718e3744 4573
d62a17ae 4574 str = argv_concat(argv, argc, idx_line);
718e3744 4575
d62a17ae 4576 peer_description_set(peer, str);
718e3744 4577
d62a17ae 4578 XFREE(MTYPE_TMP, str);
718e3744 4579
d62a17ae 4580 return CMD_SUCCESS;
718e3744 4581}
4582
4583DEFUN (no_neighbor_description,
4584 no_neighbor_description_cmd,
a636c635 4585 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
718e3744 4586 NO_STR
4587 NEIGHBOR_STR
4588 NEIGHBOR_ADDR_STR2
a636c635
DW
4589 "Neighbor specific description\n"
4590 "Up to 80 characters describing this neighbor\n")
718e3744 4591{
d62a17ae 4592 int idx_peer = 2;
4593 struct peer *peer;
718e3744 4594
d62a17ae 4595 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4596 if (!peer)
4597 return CMD_WARNING_CONFIG_FAILED;
718e3744 4598
d62a17ae 4599 peer_description_unset(peer);
718e3744 4600
d62a17ae 4601 return CMD_SUCCESS;
718e3744 4602}
4603
6b0655a2 4604
718e3744 4605/* Neighbor update-source. */
d62a17ae 4606static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4607 const char *source_str)
4608{
4609 struct peer *peer;
4610 struct prefix p;
4611
4612 peer = peer_and_group_lookup_vty(vty, peer_str);
4613 if (!peer)
4614 return CMD_WARNING_CONFIG_FAILED;
4615
4616 if (peer->conf_if)
4617 return CMD_WARNING;
4618
4619 if (source_str) {
4620 union sockunion su;
4621 int ret = str2sockunion(source_str, &su);
4622
4623 if (ret == 0)
4624 peer_update_source_addr_set(peer, &su);
4625 else {
4626 if (str2prefix(source_str, &p)) {
4627 vty_out(vty,
4628 "%% Invalid update-source, remove prefix length \n");
4629 return CMD_WARNING_CONFIG_FAILED;
4630 } else
4631 peer_update_source_if_set(peer, source_str);
4632 }
4633 } else
4634 peer_update_source_unset(peer);
4635
4636 return CMD_SUCCESS;
4637}
4638
4639#define BGP_UPDATE_SOURCE_HELP_STR \
4640 "IPv4 address\n" \
4641 "IPv6 address\n" \
4642 "Interface name (requires zebra to be running)\n"
369688c0 4643
718e3744 4644DEFUN (neighbor_update_source,
4645 neighbor_update_source_cmd,
9ccf14f7 4646 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4647 NEIGHBOR_STR
4648 NEIGHBOR_ADDR_STR2
4649 "Source of routing updates\n"
369688c0 4650 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4651{
d62a17ae 4652 int idx_peer = 1;
4653 int idx_peer_2 = 3;
4654 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4655 argv[idx_peer_2]->arg);
718e3744 4656}
4657
4658DEFUN (no_neighbor_update_source,
4659 no_neighbor_update_source_cmd,
c7178fe7 4660 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4661 NO_STR
4662 NEIGHBOR_STR
4663 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4664 "Source of routing updates\n"
4665 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4666{
d62a17ae 4667 int idx_peer = 2;
4668 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4669}
6b0655a2 4670
d62a17ae 4671static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4672 afi_t afi, safi_t safi,
4673 const char *rmap, int set)
718e3744 4674{
d62a17ae 4675 int ret;
4676 struct peer *peer;
718e3744 4677
d62a17ae 4678 peer = peer_and_group_lookup_vty(vty, peer_str);
4679 if (!peer)
4680 return CMD_WARNING_CONFIG_FAILED;
718e3744 4681
d62a17ae 4682 if (set)
4683 ret = peer_default_originate_set(peer, afi, safi, rmap);
4684 else
4685 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4686
d62a17ae 4687 return bgp_vty_return(vty, ret);
718e3744 4688}
4689
4690/* neighbor default-originate. */
4691DEFUN (neighbor_default_originate,
4692 neighbor_default_originate_cmd,
9ccf14f7 4693 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4694 NEIGHBOR_STR
4695 NEIGHBOR_ADDR_STR2
4696 "Originate default route to this neighbor\n")
4697{
d62a17ae 4698 int idx_peer = 1;
4699 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4700 bgp_node_afi(vty),
4701 bgp_node_safi(vty), NULL, 1);
718e3744 4702}
4703
d62a17ae 4704ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4705 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4706 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4707 "Originate default route to this neighbor\n")
596c17ba 4708
718e3744 4709DEFUN (neighbor_default_originate_rmap,
4710 neighbor_default_originate_rmap_cmd,
9ccf14f7 4711 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4712 NEIGHBOR_STR
4713 NEIGHBOR_ADDR_STR2
4714 "Originate default route to this neighbor\n"
4715 "Route-map to specify criteria to originate default\n"
4716 "route-map name\n")
4717{
d62a17ae 4718 int idx_peer = 1;
4719 int idx_word = 4;
4720 return peer_default_originate_set_vty(
4721 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4722 argv[idx_word]->arg, 1);
718e3744 4723}
4724
d62a17ae 4725ALIAS_HIDDEN(
4726 neighbor_default_originate_rmap,
4727 neighbor_default_originate_rmap_hidden_cmd,
4728 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4729 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4730 "Originate default route to this neighbor\n"
4731 "Route-map to specify criteria to originate default\n"
4732 "route-map name\n")
596c17ba 4733
718e3744 4734DEFUN (no_neighbor_default_originate,
4735 no_neighbor_default_originate_cmd,
a636c635 4736 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4737 NO_STR
4738 NEIGHBOR_STR
4739 NEIGHBOR_ADDR_STR2
a636c635
DW
4740 "Originate default route to this neighbor\n"
4741 "Route-map to specify criteria to originate default\n"
4742 "route-map name\n")
718e3744 4743{
d62a17ae 4744 int idx_peer = 2;
4745 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4746 bgp_node_afi(vty),
4747 bgp_node_safi(vty), NULL, 0);
718e3744 4748}
4749
d62a17ae 4750ALIAS_HIDDEN(
4751 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4752 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4753 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4754 "Originate default route to this neighbor\n"
4755 "Route-map to specify criteria to originate default\n"
4756 "route-map name\n")
596c17ba 4757
6b0655a2 4758
718e3744 4759/* Set neighbor's BGP port. */
d62a17ae 4760static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4761 const char *port_str)
4762{
4763 struct peer *peer;
d7c0a89a 4764 uint16_t port;
d62a17ae 4765 struct servent *sp;
4766
4767 peer = peer_lookup_vty(vty, ip_str);
4768 if (!peer)
4769 return CMD_WARNING_CONFIG_FAILED;
4770
4771 if (!port_str) {
4772 sp = getservbyname("bgp", "tcp");
4773 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4774 } else {
4775 port = strtoul(port_str, NULL, 10);
4776 }
718e3744 4777
d62a17ae 4778 peer_port_set(peer, port);
718e3744 4779
d62a17ae 4780 return CMD_SUCCESS;
718e3744 4781}
4782
f418446b 4783/* Set specified peer's BGP port. */
718e3744 4784DEFUN (neighbor_port,
4785 neighbor_port_cmd,
9ccf14f7 4786 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4787 NEIGHBOR_STR
4788 NEIGHBOR_ADDR_STR
4789 "Neighbor's BGP port\n"
4790 "TCP port number\n")
4791{
d62a17ae 4792 int idx_ip = 1;
4793 int idx_number = 3;
4794 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4795 argv[idx_number]->arg);
718e3744 4796}
4797
4798DEFUN (no_neighbor_port,
4799 no_neighbor_port_cmd,
9ccf14f7 4800 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4801 NO_STR
4802 NEIGHBOR_STR
4803 NEIGHBOR_ADDR_STR
8334fd5a
DW
4804 "Neighbor's BGP port\n"
4805 "TCP port number\n")
718e3744 4806{
d62a17ae 4807 int idx_ip = 2;
4808 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4809}
4810
6b0655a2 4811
718e3744 4812/* neighbor weight. */
d62a17ae 4813static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4814 safi_t safi, const char *weight_str)
718e3744 4815{
d62a17ae 4816 int ret;
4817 struct peer *peer;
4818 unsigned long weight;
718e3744 4819
d62a17ae 4820 peer = peer_and_group_lookup_vty(vty, ip_str);
4821 if (!peer)
4822 return CMD_WARNING_CONFIG_FAILED;
718e3744 4823
d62a17ae 4824 weight = strtoul(weight_str, NULL, 10);
718e3744 4825
d62a17ae 4826 ret = peer_weight_set(peer, afi, safi, weight);
4827 return bgp_vty_return(vty, ret);
718e3744 4828}
4829
d62a17ae 4830static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4831 safi_t safi)
718e3744 4832{
d62a17ae 4833 int ret;
4834 struct peer *peer;
718e3744 4835
d62a17ae 4836 peer = peer_and_group_lookup_vty(vty, ip_str);
4837 if (!peer)
4838 return CMD_WARNING_CONFIG_FAILED;
718e3744 4839
d62a17ae 4840 ret = peer_weight_unset(peer, afi, safi);
4841 return bgp_vty_return(vty, ret);
718e3744 4842}
4843
4844DEFUN (neighbor_weight,
4845 neighbor_weight_cmd,
9ccf14f7 4846 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4847 NEIGHBOR_STR
4848 NEIGHBOR_ADDR_STR2
4849 "Set default weight for routes from this neighbor\n"
4850 "default weight\n")
4851{
d62a17ae 4852 int idx_peer = 1;
4853 int idx_number = 3;
4854 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4855 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4856}
4857
d62a17ae 4858ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4859 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4860 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4861 "Set default weight for routes from this neighbor\n"
4862 "default weight\n")
596c17ba 4863
718e3744 4864DEFUN (no_neighbor_weight,
4865 no_neighbor_weight_cmd,
9ccf14f7 4866 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4867 NO_STR
4868 NEIGHBOR_STR
4869 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4870 "Set default weight for routes from this neighbor\n"
4871 "default weight\n")
718e3744 4872{
d62a17ae 4873 int idx_peer = 2;
4874 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4875 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4876}
4877
d62a17ae 4878ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4879 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4880 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4881 "Set default weight for routes from this neighbor\n"
4882 "default weight\n")
596c17ba 4883
6b0655a2 4884
718e3744 4885/* Override capability negotiation. */
4886DEFUN (neighbor_override_capability,
4887 neighbor_override_capability_cmd,
9ccf14f7 4888 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4889 NEIGHBOR_STR
4890 NEIGHBOR_ADDR_STR2
4891 "Override capability negotiation result\n")
4892{
d62a17ae 4893 int idx_peer = 1;
4894 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4895 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4896}
4897
4898DEFUN (no_neighbor_override_capability,
4899 no_neighbor_override_capability_cmd,
9ccf14f7 4900 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4901 NO_STR
4902 NEIGHBOR_STR
4903 NEIGHBOR_ADDR_STR2
4904 "Override capability negotiation result\n")
4905{
d62a17ae 4906 int idx_peer = 2;
4907 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4908 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4909}
6b0655a2 4910
718e3744 4911DEFUN (neighbor_strict_capability,
4912 neighbor_strict_capability_cmd,
9ccf14f7 4913 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4914 NEIGHBOR_STR
4915 NEIGHBOR_ADDR_STR
4916 "Strict capability negotiation match\n")
4917{
d62a17ae 4918 int idx_ip = 1;
4919 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4920 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4921}
4922
4923DEFUN (no_neighbor_strict_capability,
4924 no_neighbor_strict_capability_cmd,
9ccf14f7 4925 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4926 NO_STR
4927 NEIGHBOR_STR
4928 NEIGHBOR_ADDR_STR
4929 "Strict capability negotiation match\n")
4930{
d62a17ae 4931 int idx_ip = 2;
4932 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
4933 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4934}
6b0655a2 4935
d62a17ae 4936static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
4937 const char *keep_str, const char *hold_str)
718e3744 4938{
d62a17ae 4939 int ret;
4940 struct peer *peer;
d7c0a89a
QY
4941 uint32_t keepalive;
4942 uint32_t holdtime;
718e3744 4943
d62a17ae 4944 peer = peer_and_group_lookup_vty(vty, ip_str);
4945 if (!peer)
4946 return CMD_WARNING_CONFIG_FAILED;
718e3744 4947
d62a17ae 4948 keepalive = strtoul(keep_str, NULL, 10);
4949 holdtime = strtoul(hold_str, NULL, 10);
718e3744 4950
d62a17ae 4951 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 4952
d62a17ae 4953 return bgp_vty_return(vty, ret);
718e3744 4954}
6b0655a2 4955
d62a17ae 4956static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4957{
d62a17ae 4958 int ret;
4959 struct peer *peer;
718e3744 4960
d62a17ae 4961 peer = peer_and_group_lookup_vty(vty, ip_str);
4962 if (!peer)
4963 return CMD_WARNING_CONFIG_FAILED;
718e3744 4964
d62a17ae 4965 ret = peer_timers_unset(peer);
718e3744 4966
d62a17ae 4967 return bgp_vty_return(vty, ret);
718e3744 4968}
4969
4970DEFUN (neighbor_timers,
4971 neighbor_timers_cmd,
9ccf14f7 4972 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 4973 NEIGHBOR_STR
4974 NEIGHBOR_ADDR_STR2
4975 "BGP per neighbor timers\n"
4976 "Keepalive interval\n"
4977 "Holdtime\n")
4978{
d62a17ae 4979 int idx_peer = 1;
4980 int idx_number = 3;
4981 int idx_number_2 = 4;
4982 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
4983 argv[idx_number]->arg,
4984 argv[idx_number_2]->arg);
718e3744 4985}
4986
4987DEFUN (no_neighbor_timers,
4988 no_neighbor_timers_cmd,
9ccf14f7 4989 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 4990 NO_STR
4991 NEIGHBOR_STR
4992 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4993 "BGP per neighbor timers\n"
4994 "Keepalive interval\n"
4995 "Holdtime\n")
718e3744 4996{
d62a17ae 4997 int idx_peer = 2;
4998 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4999}
6b0655a2 5000
813d4307 5001
d62a17ae 5002static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5003 const char *time_str)
718e3744 5004{
d62a17ae 5005 int ret;
5006 struct peer *peer;
d7c0a89a 5007 uint32_t connect;
718e3744 5008
d62a17ae 5009 peer = peer_and_group_lookup_vty(vty, ip_str);
5010 if (!peer)
5011 return CMD_WARNING_CONFIG_FAILED;
718e3744 5012
d62a17ae 5013 connect = strtoul(time_str, NULL, 10);
718e3744 5014
d62a17ae 5015 ret = peer_timers_connect_set(peer, connect);
718e3744 5016
d62a17ae 5017 return bgp_vty_return(vty, ret);
718e3744 5018}
5019
d62a17ae 5020static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5021{
d62a17ae 5022 int ret;
5023 struct peer *peer;
718e3744 5024
d62a17ae 5025 peer = peer_and_group_lookup_vty(vty, ip_str);
5026 if (!peer)
5027 return CMD_WARNING_CONFIG_FAILED;
718e3744 5028
d62a17ae 5029 ret = peer_timers_connect_unset(peer);
718e3744 5030
d62a17ae 5031 return bgp_vty_return(vty, ret);
718e3744 5032}
5033
5034DEFUN (neighbor_timers_connect,
5035 neighbor_timers_connect_cmd,
9ccf14f7 5036 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5037 NEIGHBOR_STR
966f821c 5038 NEIGHBOR_ADDR_STR2
718e3744 5039 "BGP per neighbor timers\n"
5040 "BGP connect timer\n"
5041 "Connect timer\n")
5042{
d62a17ae 5043 int idx_peer = 1;
5044 int idx_number = 4;
5045 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5046 argv[idx_number]->arg);
718e3744 5047}
5048
5049DEFUN (no_neighbor_timers_connect,
5050 no_neighbor_timers_connect_cmd,
9ccf14f7 5051 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5052 NO_STR
5053 NEIGHBOR_STR
966f821c 5054 NEIGHBOR_ADDR_STR2
718e3744 5055 "BGP per neighbor timers\n"
8334fd5a
DW
5056 "BGP connect timer\n"
5057 "Connect timer\n")
718e3744 5058{
d62a17ae 5059 int idx_peer = 2;
5060 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5061}
5062
6b0655a2 5063
d62a17ae 5064static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5065 const char *time_str, int set)
718e3744 5066{
d62a17ae 5067 int ret;
5068 struct peer *peer;
d7c0a89a 5069 uint32_t routeadv = 0;
718e3744 5070
d62a17ae 5071 peer = peer_and_group_lookup_vty(vty, ip_str);
5072 if (!peer)
5073 return CMD_WARNING_CONFIG_FAILED;
718e3744 5074
d62a17ae 5075 if (time_str)
5076 routeadv = strtoul(time_str, NULL, 10);
718e3744 5077
d62a17ae 5078 if (set)
5079 ret = peer_advertise_interval_set(peer, routeadv);
5080 else
5081 ret = peer_advertise_interval_unset(peer);
718e3744 5082
d62a17ae 5083 return bgp_vty_return(vty, ret);
718e3744 5084}
5085
5086DEFUN (neighbor_advertise_interval,
5087 neighbor_advertise_interval_cmd,
9ccf14f7 5088 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5089 NEIGHBOR_STR
966f821c 5090 NEIGHBOR_ADDR_STR2
718e3744 5091 "Minimum interval between sending BGP routing updates\n"
5092 "time in seconds\n")
5093{
d62a17ae 5094 int idx_peer = 1;
5095 int idx_number = 3;
5096 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5097 argv[idx_number]->arg, 1);
718e3744 5098}
5099
5100DEFUN (no_neighbor_advertise_interval,
5101 no_neighbor_advertise_interval_cmd,
9ccf14f7 5102 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5103 NO_STR
5104 NEIGHBOR_STR
966f821c 5105 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5106 "Minimum interval between sending BGP routing updates\n"
5107 "time in seconds\n")
718e3744 5108{
d62a17ae 5109 int idx_peer = 2;
5110 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5111}
5112
6b0655a2 5113
518f0eb1
DS
5114/* Time to wait before processing route-map updates */
5115DEFUN (bgp_set_route_map_delay_timer,
5116 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5117 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5118 SET_STR
5119 "BGP route-map delay timer\n"
5120 "Time in secs to wait before processing route-map changes\n"
f414725f 5121 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5122{
d62a17ae 5123 int idx_number = 3;
d7c0a89a 5124 uint32_t rmap_delay_timer;
d62a17ae 5125
5126 if (argv[idx_number]->arg) {
5127 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5128 bm->rmap_update_timer = rmap_delay_timer;
5129
5130 /* if the dynamic update handling is being disabled, and a timer
5131 * is
5132 * running, stop the timer and act as if the timer has already
5133 * fired.
5134 */
5135 if (!rmap_delay_timer && bm->t_rmap_update) {
5136 BGP_TIMER_OFF(bm->t_rmap_update);
5137 thread_execute(bm->master, bgp_route_map_update_timer,
5138 NULL, 0);
5139 }
5140 return CMD_SUCCESS;
5141 } else {
5142 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5143 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5144 }
518f0eb1
DS
5145}
5146
5147DEFUN (no_bgp_set_route_map_delay_timer,
5148 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5149 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5150 NO_STR
3a2d747c 5151 BGP_STR
518f0eb1 5152 "Default BGP route-map delay timer\n"
8334fd5a
DW
5153 "Reset to default time to wait for processing route-map changes\n"
5154 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5155{
518f0eb1 5156
d62a17ae 5157 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5158
d62a17ae 5159 return CMD_SUCCESS;
518f0eb1
DS
5160}
5161
f414725f 5162
718e3744 5163/* neighbor interface */
d62a17ae 5164static int peer_interface_vty(struct vty *vty, const char *ip_str,
5165 const char *str)
718e3744 5166{
d62a17ae 5167 struct peer *peer;
718e3744 5168
d62a17ae 5169 peer = peer_lookup_vty(vty, ip_str);
5170 if (!peer || peer->conf_if) {
5171 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5172 return CMD_WARNING_CONFIG_FAILED;
5173 }
718e3744 5174
d62a17ae 5175 if (str)
5176 peer_interface_set(peer, str);
5177 else
5178 peer_interface_unset(peer);
718e3744 5179
d62a17ae 5180 return CMD_SUCCESS;
718e3744 5181}
5182
5183DEFUN (neighbor_interface,
5184 neighbor_interface_cmd,
9ccf14f7 5185 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5186 NEIGHBOR_STR
5187 NEIGHBOR_ADDR_STR
5188 "Interface\n"
5189 "Interface name\n")
5190{
d62a17ae 5191 int idx_ip = 1;
5192 int idx_word = 3;
5193 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5194}
5195
5196DEFUN (no_neighbor_interface,
5197 no_neighbor_interface_cmd,
9ccf14f7 5198 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5199 NO_STR
5200 NEIGHBOR_STR
16cedbb0 5201 NEIGHBOR_ADDR_STR2
718e3744 5202 "Interface\n"
5203 "Interface name\n")
5204{
d62a17ae 5205 int idx_peer = 2;
5206 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5207}
6b0655a2 5208
718e3744 5209DEFUN (neighbor_distribute_list,
5210 neighbor_distribute_list_cmd,
9ccf14f7 5211 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5212 NEIGHBOR_STR
5213 NEIGHBOR_ADDR_STR2
5214 "Filter updates to/from this neighbor\n"
5215 "IP access-list number\n"
5216 "IP access-list number (expanded range)\n"
5217 "IP Access-list name\n"
5218 "Filter incoming updates\n"
5219 "Filter outgoing updates\n")
5220{
d62a17ae 5221 int idx_peer = 1;
5222 int idx_acl = 3;
5223 int direct, ret;
5224 struct peer *peer;
a8206004 5225
d62a17ae 5226 const char *pstr = argv[idx_peer]->arg;
5227 const char *acl = argv[idx_acl]->arg;
5228 const char *inout = argv[argc - 1]->text;
a8206004 5229
d62a17ae 5230 peer = peer_and_group_lookup_vty(vty, pstr);
5231 if (!peer)
5232 return CMD_WARNING_CONFIG_FAILED;
a8206004 5233
d62a17ae 5234 /* Check filter direction. */
5235 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5236 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5237 direct, acl);
a8206004 5238
d62a17ae 5239 return bgp_vty_return(vty, ret);
718e3744 5240}
5241
d62a17ae 5242ALIAS_HIDDEN(
5243 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5244 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5245 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5246 "Filter updates to/from this neighbor\n"
5247 "IP access-list number\n"
5248 "IP access-list number (expanded range)\n"
5249 "IP Access-list name\n"
5250 "Filter incoming updates\n"
5251 "Filter outgoing updates\n")
596c17ba 5252
718e3744 5253DEFUN (no_neighbor_distribute_list,
5254 no_neighbor_distribute_list_cmd,
9ccf14f7 5255 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5256 NO_STR
5257 NEIGHBOR_STR
5258 NEIGHBOR_ADDR_STR2
5259 "Filter updates to/from this neighbor\n"
5260 "IP access-list number\n"
5261 "IP access-list number (expanded range)\n"
5262 "IP Access-list name\n"
5263 "Filter incoming updates\n"
5264 "Filter outgoing updates\n")
5265{
d62a17ae 5266 int idx_peer = 2;
5267 int direct, ret;
5268 struct peer *peer;
a8206004 5269
d62a17ae 5270 const char *pstr = argv[idx_peer]->arg;
5271 const char *inout = argv[argc - 1]->text;
a8206004 5272
d62a17ae 5273 peer = peer_and_group_lookup_vty(vty, pstr);
5274 if (!peer)
5275 return CMD_WARNING_CONFIG_FAILED;
a8206004 5276
d62a17ae 5277 /* Check filter direction. */
5278 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5279 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5280 direct);
a8206004 5281
d62a17ae 5282 return bgp_vty_return(vty, ret);
718e3744 5283}
6b0655a2 5284
d62a17ae 5285ALIAS_HIDDEN(
5286 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5287 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5288 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5289 "Filter updates to/from this neighbor\n"
5290 "IP access-list number\n"
5291 "IP access-list number (expanded range)\n"
5292 "IP Access-list name\n"
5293 "Filter incoming updates\n"
5294 "Filter outgoing updates\n")
596c17ba 5295
718e3744 5296/* Set prefix list to the peer. */
d62a17ae 5297static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5298 afi_t afi, safi_t safi,
5299 const char *name_str,
5300 const char *direct_str)
718e3744 5301{
d62a17ae 5302 int ret;
5303 struct peer *peer;
5304 int direct = FILTER_IN;
718e3744 5305
d62a17ae 5306 peer = peer_and_group_lookup_vty(vty, ip_str);
5307 if (!peer)
5308 return CMD_WARNING_CONFIG_FAILED;
718e3744 5309
d62a17ae 5310 /* Check filter direction. */
5311 if (strncmp(direct_str, "i", 1) == 0)
5312 direct = FILTER_IN;
5313 else if (strncmp(direct_str, "o", 1) == 0)
5314 direct = FILTER_OUT;
718e3744 5315
d62a17ae 5316 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5317
d62a17ae 5318 return bgp_vty_return(vty, ret);
718e3744 5319}
5320
d62a17ae 5321static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5322 afi_t afi, safi_t safi,
5323 const char *direct_str)
718e3744 5324{
d62a17ae 5325 int ret;
5326 struct peer *peer;
5327 int direct = FILTER_IN;
718e3744 5328
d62a17ae 5329 peer = peer_and_group_lookup_vty(vty, ip_str);
5330 if (!peer)
5331 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5332
d62a17ae 5333 /* Check filter direction. */
5334 if (strncmp(direct_str, "i", 1) == 0)
5335 direct = FILTER_IN;
5336 else if (strncmp(direct_str, "o", 1) == 0)
5337 direct = FILTER_OUT;
718e3744 5338
d62a17ae 5339 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5340
d62a17ae 5341 return bgp_vty_return(vty, ret);
718e3744 5342}
5343
5344DEFUN (neighbor_prefix_list,
5345 neighbor_prefix_list_cmd,
9ccf14f7 5346 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5347 NEIGHBOR_STR
5348 NEIGHBOR_ADDR_STR2
5349 "Filter updates to/from this neighbor\n"
5350 "Name of a prefix list\n"
5351 "Filter incoming updates\n"
5352 "Filter outgoing updates\n")
5353{
d62a17ae 5354 int idx_peer = 1;
5355 int idx_word = 3;
5356 int idx_in_out = 4;
5357 return peer_prefix_list_set_vty(
5358 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5359 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5360}
5361
d62a17ae 5362ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5363 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5364 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5365 "Filter updates to/from this neighbor\n"
5366 "Name of a prefix list\n"
5367 "Filter incoming updates\n"
5368 "Filter outgoing updates\n")
596c17ba 5369
718e3744 5370DEFUN (no_neighbor_prefix_list,
5371 no_neighbor_prefix_list_cmd,
9ccf14f7 5372 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5373 NO_STR
5374 NEIGHBOR_STR
5375 NEIGHBOR_ADDR_STR2
5376 "Filter updates to/from this neighbor\n"
5377 "Name of a prefix list\n"
5378 "Filter incoming updates\n"
5379 "Filter outgoing updates\n")
5380{
d62a17ae 5381 int idx_peer = 2;
5382 int idx_in_out = 5;
5383 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5384 bgp_node_afi(vty), bgp_node_safi(vty),
5385 argv[idx_in_out]->arg);
718e3744 5386}
6b0655a2 5387
d62a17ae 5388ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5389 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5390 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5391 "Filter updates to/from this neighbor\n"
5392 "Name of a prefix list\n"
5393 "Filter incoming updates\n"
5394 "Filter outgoing updates\n")
596c17ba 5395
d62a17ae 5396static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5397 safi_t safi, const char *name_str,
5398 const char *direct_str)
718e3744 5399{
d62a17ae 5400 int ret;
5401 struct peer *peer;
5402 int direct = FILTER_IN;
718e3744 5403
d62a17ae 5404 peer = peer_and_group_lookup_vty(vty, ip_str);
5405 if (!peer)
5406 return CMD_WARNING_CONFIG_FAILED;
718e3744 5407
d62a17ae 5408 /* Check filter direction. */
5409 if (strncmp(direct_str, "i", 1) == 0)
5410 direct = FILTER_IN;
5411 else if (strncmp(direct_str, "o", 1) == 0)
5412 direct = FILTER_OUT;
718e3744 5413
d62a17ae 5414 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5415
d62a17ae 5416 return bgp_vty_return(vty, ret);
718e3744 5417}
5418
d62a17ae 5419static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5420 safi_t safi, const char *direct_str)
718e3744 5421{
d62a17ae 5422 int ret;
5423 struct peer *peer;
5424 int direct = FILTER_IN;
718e3744 5425
d62a17ae 5426 peer = peer_and_group_lookup_vty(vty, ip_str);
5427 if (!peer)
5428 return CMD_WARNING_CONFIG_FAILED;
718e3744 5429
d62a17ae 5430 /* Check filter direction. */
5431 if (strncmp(direct_str, "i", 1) == 0)
5432 direct = FILTER_IN;
5433 else if (strncmp(direct_str, "o", 1) == 0)
5434 direct = FILTER_OUT;
718e3744 5435
d62a17ae 5436 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5437
d62a17ae 5438 return bgp_vty_return(vty, ret);
718e3744 5439}
5440
5441DEFUN (neighbor_filter_list,
5442 neighbor_filter_list_cmd,
9ccf14f7 5443 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5444 NEIGHBOR_STR
5445 NEIGHBOR_ADDR_STR2
5446 "Establish BGP filters\n"
5447 "AS path access-list name\n"
5448 "Filter incoming routes\n"
5449 "Filter outgoing routes\n")
5450{
d62a17ae 5451 int idx_peer = 1;
5452 int idx_word = 3;
5453 int idx_in_out = 4;
5454 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5455 bgp_node_safi(vty), argv[idx_word]->arg,
5456 argv[idx_in_out]->arg);
718e3744 5457}
5458
d62a17ae 5459ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5460 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5461 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5462 "Establish BGP filters\n"
5463 "AS path access-list name\n"
5464 "Filter incoming routes\n"
5465 "Filter outgoing routes\n")
596c17ba 5466
718e3744 5467DEFUN (no_neighbor_filter_list,
5468 no_neighbor_filter_list_cmd,
9ccf14f7 5469 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5470 NO_STR
5471 NEIGHBOR_STR
5472 NEIGHBOR_ADDR_STR2
5473 "Establish BGP filters\n"
5474 "AS path access-list name\n"
5475 "Filter incoming routes\n"
5476 "Filter outgoing routes\n")
5477{
d62a17ae 5478 int idx_peer = 2;
5479 int idx_in_out = 5;
5480 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5481 bgp_node_afi(vty), bgp_node_safi(vty),
5482 argv[idx_in_out]->arg);
718e3744 5483}
6b0655a2 5484
d62a17ae 5485ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5486 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5487 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5488 "Establish BGP filters\n"
5489 "AS path access-list name\n"
5490 "Filter incoming routes\n"
5491 "Filter outgoing routes\n")
596c17ba 5492
718e3744 5493/* Set route-map to the peer. */
d62a17ae 5494static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5495 afi_t afi, safi_t safi, const char *name_str,
5496 const char *direct_str)
718e3744 5497{
d62a17ae 5498 int ret;
5499 struct peer *peer;
5500 int direct = RMAP_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, "in", 2) == 0)
5508 direct = RMAP_IN;
5509 else if (strncmp(direct_str, "o", 1) == 0)
5510 direct = RMAP_OUT;
718e3744 5511
d62a17ae 5512 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5513
d62a17ae 5514 return bgp_vty_return(vty, ret);
718e3744 5515}
5516
d62a17ae 5517static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5518 afi_t afi, safi_t safi,
5519 const char *direct_str)
718e3744 5520{
d62a17ae 5521 int ret;
5522 struct peer *peer;
5523 int direct = RMAP_IN;
718e3744 5524
d62a17ae 5525 peer = peer_and_group_lookup_vty(vty, ip_str);
5526 if (!peer)
5527 return CMD_WARNING_CONFIG_FAILED;
718e3744 5528
d62a17ae 5529 /* Check filter direction. */
5530 if (strncmp(direct_str, "in", 2) == 0)
5531 direct = RMAP_IN;
5532 else if (strncmp(direct_str, "o", 1) == 0)
5533 direct = RMAP_OUT;
718e3744 5534
d62a17ae 5535 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5536
d62a17ae 5537 return bgp_vty_return(vty, ret);
718e3744 5538}
5539
5540DEFUN (neighbor_route_map,
5541 neighbor_route_map_cmd,
9ccf14f7 5542 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5543 NEIGHBOR_STR
5544 NEIGHBOR_ADDR_STR2
5545 "Apply route map to neighbor\n"
5546 "Name of route map\n"
5547 "Apply map to incoming routes\n"
2a3d5731 5548 "Apply map to outbound routes\n")
718e3744 5549{
d62a17ae 5550 int idx_peer = 1;
5551 int idx_word = 3;
5552 int idx_in_out = 4;
5553 return peer_route_map_set_vty(
5554 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5555 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5556}
5557
d62a17ae 5558ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5559 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5560 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5561 "Apply route map to neighbor\n"
5562 "Name of route map\n"
5563 "Apply map to incoming routes\n"
5564 "Apply map to outbound routes\n")
596c17ba 5565
718e3744 5566DEFUN (no_neighbor_route_map,
5567 no_neighbor_route_map_cmd,
9ccf14f7 5568 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5569 NO_STR
5570 NEIGHBOR_STR
5571 NEIGHBOR_ADDR_STR2
5572 "Apply route map to neighbor\n"
5573 "Name of route map\n"
5574 "Apply map to incoming routes\n"
2a3d5731 5575 "Apply map to outbound routes\n")
718e3744 5576{
d62a17ae 5577 int idx_peer = 2;
5578 int idx_in_out = 5;
5579 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5580 bgp_node_afi(vty), bgp_node_safi(vty),
5581 argv[idx_in_out]->arg);
718e3744 5582}
6b0655a2 5583
d62a17ae 5584ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5585 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5586 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5587 "Apply route map to neighbor\n"
5588 "Name of route map\n"
5589 "Apply map to incoming routes\n"
5590 "Apply map to outbound routes\n")
596c17ba 5591
718e3744 5592/* Set unsuppress-map to the peer. */
d62a17ae 5593static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5594 afi_t afi, safi_t safi,
5595 const char *name_str)
718e3744 5596{
d62a17ae 5597 int ret;
5598 struct peer *peer;
718e3744 5599
d62a17ae 5600 peer = peer_and_group_lookup_vty(vty, ip_str);
5601 if (!peer)
5602 return CMD_WARNING_CONFIG_FAILED;
718e3744 5603
d62a17ae 5604 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5605
d62a17ae 5606 return bgp_vty_return(vty, ret);
718e3744 5607}
5608
5609/* Unset route-map from the peer. */
d62a17ae 5610static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5611 afi_t afi, safi_t safi)
718e3744 5612{
d62a17ae 5613 int ret;
5614 struct peer *peer;
718e3744 5615
d62a17ae 5616 peer = peer_and_group_lookup_vty(vty, ip_str);
5617 if (!peer)
5618 return CMD_WARNING_CONFIG_FAILED;
718e3744 5619
d62a17ae 5620 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5621
d62a17ae 5622 return bgp_vty_return(vty, ret);
718e3744 5623}
5624
5625DEFUN (neighbor_unsuppress_map,
5626 neighbor_unsuppress_map_cmd,
9ccf14f7 5627 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5628 NEIGHBOR_STR
5629 NEIGHBOR_ADDR_STR2
5630 "Route-map to selectively unsuppress suppressed routes\n"
5631 "Name of route map\n")
5632{
d62a17ae 5633 int idx_peer = 1;
5634 int idx_word = 3;
5635 return peer_unsuppress_map_set_vty(
5636 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5637 argv[idx_word]->arg);
718e3744 5638}
5639
d62a17ae 5640ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5641 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5642 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5643 "Route-map to selectively unsuppress suppressed routes\n"
5644 "Name of route map\n")
596c17ba 5645
718e3744 5646DEFUN (no_neighbor_unsuppress_map,
5647 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5648 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5649 NO_STR
5650 NEIGHBOR_STR
5651 NEIGHBOR_ADDR_STR2
5652 "Route-map to selectively unsuppress suppressed routes\n"
5653 "Name of route map\n")
5654{
d62a17ae 5655 int idx_peer = 2;
5656 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5657 bgp_node_afi(vty),
5658 bgp_node_safi(vty));
718e3744 5659}
6b0655a2 5660
d62a17ae 5661ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5662 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5663 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5664 "Route-map to selectively unsuppress suppressed routes\n"
5665 "Name of route map\n")
596c17ba 5666
d62a17ae 5667static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5668 afi_t afi, safi_t safi,
5669 const char *num_str,
5670 const char *threshold_str, int warning,
5671 const char *restart_str)
718e3744 5672{
d62a17ae 5673 int ret;
5674 struct peer *peer;
d7c0a89a
QY
5675 uint32_t max;
5676 uint8_t threshold;
5677 uint16_t restart;
718e3744 5678
d62a17ae 5679 peer = peer_and_group_lookup_vty(vty, ip_str);
5680 if (!peer)
5681 return CMD_WARNING_CONFIG_FAILED;
718e3744 5682
d62a17ae 5683 max = strtoul(num_str, NULL, 10);
5684 if (threshold_str)
5685 threshold = atoi(threshold_str);
5686 else
5687 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5688
d62a17ae 5689 if (restart_str)
5690 restart = atoi(restart_str);
5691 else
5692 restart = 0;
0a486e5f 5693
d62a17ae 5694 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5695 restart);
718e3744 5696
d62a17ae 5697 return bgp_vty_return(vty, ret);
718e3744 5698}
5699
d62a17ae 5700static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5701 afi_t afi, safi_t safi)
718e3744 5702{
d62a17ae 5703 int ret;
5704 struct peer *peer;
718e3744 5705
d62a17ae 5706 peer = peer_and_group_lookup_vty(vty, ip_str);
5707 if (!peer)
5708 return CMD_WARNING_CONFIG_FAILED;
718e3744 5709
d62a17ae 5710 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5711
d62a17ae 5712 return bgp_vty_return(vty, ret);
718e3744 5713}
5714
5715/* Maximum number of prefix configuration. prefix count is different
5716 for each peer configuration. So this configuration can be set for
5717 each peer configuration. */
5718DEFUN (neighbor_maximum_prefix,
5719 neighbor_maximum_prefix_cmd,
9ccf14f7 5720 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5721 NEIGHBOR_STR
5722 NEIGHBOR_ADDR_STR2
5723 "Maximum number of prefix accept from this peer\n"
5724 "maximum no. of prefix limit\n")
5725{
d62a17ae 5726 int idx_peer = 1;
5727 int idx_number = 3;
5728 return peer_maximum_prefix_set_vty(
5729 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5730 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5731}
5732
d62a17ae 5733ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5734 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5735 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5736 "Maximum number of prefix accept from this peer\n"
5737 "maximum no. of prefix limit\n")
596c17ba 5738
e0701b79 5739DEFUN (neighbor_maximum_prefix_threshold,
5740 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5741 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5742 NEIGHBOR_STR
5743 NEIGHBOR_ADDR_STR2
5744 "Maximum number of prefix accept from this peer\n"
5745 "maximum no. of prefix limit\n"
5746 "Threshold value (%) at which to generate a warning msg\n")
5747{
d62a17ae 5748 int idx_peer = 1;
5749 int idx_number = 3;
5750 int idx_number_2 = 4;
5751 return peer_maximum_prefix_set_vty(
5752 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5753 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5754}
e0701b79 5755
d62a17ae 5756ALIAS_HIDDEN(
5757 neighbor_maximum_prefix_threshold,
5758 neighbor_maximum_prefix_threshold_hidden_cmd,
5759 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5760 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5761 "Maximum number of prefix accept from this peer\n"
5762 "maximum no. of prefix limit\n"
5763 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5764
718e3744 5765DEFUN (neighbor_maximum_prefix_warning,
5766 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5767 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5768 NEIGHBOR_STR
5769 NEIGHBOR_ADDR_STR2
5770 "Maximum number of prefix accept from this peer\n"
5771 "maximum no. of prefix limit\n"
5772 "Only give warning message when limit is exceeded\n")
5773{
d62a17ae 5774 int idx_peer = 1;
5775 int idx_number = 3;
5776 return peer_maximum_prefix_set_vty(
5777 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5778 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5779}
5780
d62a17ae 5781ALIAS_HIDDEN(
5782 neighbor_maximum_prefix_warning,
5783 neighbor_maximum_prefix_warning_hidden_cmd,
5784 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5785 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5786 "Maximum number of prefix accept from this peer\n"
5787 "maximum no. of prefix limit\n"
5788 "Only give warning message when limit is exceeded\n")
596c17ba 5789
e0701b79 5790DEFUN (neighbor_maximum_prefix_threshold_warning,
5791 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5792 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5793 NEIGHBOR_STR
5794 NEIGHBOR_ADDR_STR2
5795 "Maximum number of prefix accept from this peer\n"
5796 "maximum no. of prefix limit\n"
5797 "Threshold value (%) at which to generate a warning msg\n"
5798 "Only give warning message when limit is exceeded\n")
5799{
d62a17ae 5800 int idx_peer = 1;
5801 int idx_number = 3;
5802 int idx_number_2 = 4;
5803 return peer_maximum_prefix_set_vty(
5804 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5805 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5806}
5807
d62a17ae 5808ALIAS_HIDDEN(
5809 neighbor_maximum_prefix_threshold_warning,
5810 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5811 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5812 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5813 "Maximum number of prefix accept from this peer\n"
5814 "maximum no. of prefix limit\n"
5815 "Threshold value (%) at which to generate a warning msg\n"
5816 "Only give warning message when limit is exceeded\n")
596c17ba 5817
0a486e5f 5818DEFUN (neighbor_maximum_prefix_restart,
5819 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5820 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5821 NEIGHBOR_STR
5822 NEIGHBOR_ADDR_STR2
5823 "Maximum number of prefix accept from this peer\n"
5824 "maximum no. of prefix limit\n"
5825 "Restart bgp connection after limit is exceeded\n"
efd7904e 5826 "Restart interval in minutes\n")
0a486e5f 5827{
d62a17ae 5828 int idx_peer = 1;
5829 int idx_number = 3;
5830 int idx_number_2 = 5;
5831 return peer_maximum_prefix_set_vty(
5832 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5833 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5834}
5835
d62a17ae 5836ALIAS_HIDDEN(
5837 neighbor_maximum_prefix_restart,
5838 neighbor_maximum_prefix_restart_hidden_cmd,
5839 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5840 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5841 "Maximum number of prefix accept from this peer\n"
5842 "maximum no. of prefix limit\n"
5843 "Restart bgp connection after limit is exceeded\n"
efd7904e 5844 "Restart interval in minutes\n")
596c17ba 5845
0a486e5f 5846DEFUN (neighbor_maximum_prefix_threshold_restart,
5847 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5848 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5849 NEIGHBOR_STR
5850 NEIGHBOR_ADDR_STR2
16cedbb0 5851 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5852 "maximum no. of prefix limit\n"
5853 "Threshold value (%) at which to generate a warning msg\n"
5854 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5855 "Restart interval in minutes\n")
0a486e5f 5856{
d62a17ae 5857 int idx_peer = 1;
5858 int idx_number = 3;
5859 int idx_number_2 = 4;
5860 int idx_number_3 = 6;
5861 return peer_maximum_prefix_set_vty(
5862 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5863 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5864 argv[idx_number_3]->arg);
5865}
5866
5867ALIAS_HIDDEN(
5868 neighbor_maximum_prefix_threshold_restart,
5869 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5870 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5871 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5872 "Maximum number of prefixes to accept from this peer\n"
5873 "maximum no. of prefix limit\n"
5874 "Threshold value (%) at which to generate a warning msg\n"
5875 "Restart bgp connection after limit is exceeded\n"
5876 "Restart interval in minutes\n")
596c17ba 5877
718e3744 5878DEFUN (no_neighbor_maximum_prefix,
5879 no_neighbor_maximum_prefix_cmd,
d04c479d 5880 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5881 NO_STR
5882 NEIGHBOR_STR
5883 NEIGHBOR_ADDR_STR2
16cedbb0 5884 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5885 "maximum no. of prefix limit\n"
5886 "Threshold value (%) at which to generate a warning msg\n"
5887 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5888 "Restart interval in minutes\n"
31500417 5889 "Only give warning message when limit is exceeded\n")
718e3744 5890{
d62a17ae 5891 int idx_peer = 2;
5892 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5893 bgp_node_afi(vty),
5894 bgp_node_safi(vty));
718e3744 5895}
e52702f2 5896
d62a17ae 5897ALIAS_HIDDEN(
5898 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5899 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5900 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5901 "Maximum number of prefixes to accept from this peer\n"
5902 "maximum no. of prefix limit\n"
5903 "Threshold value (%) at which to generate a warning msg\n"
5904 "Restart bgp connection after limit is exceeded\n"
5905 "Restart interval in minutes\n"
5906 "Only give warning message when limit is exceeded\n")
596c17ba 5907
718e3744 5908
718e3744 5909/* "neighbor allowas-in" */
5910DEFUN (neighbor_allowas_in,
5911 neighbor_allowas_in_cmd,
fd8503f5 5912 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5913 NEIGHBOR_STR
5914 NEIGHBOR_ADDR_STR2
31500417 5915 "Accept as-path with my AS present in it\n"
fd8503f5
QY
5916 "Number of occurances of AS number\n"
5917 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5918{
d62a17ae 5919 int idx_peer = 1;
5920 int idx_number_origin = 3;
5921 int ret;
5922 int origin = 0;
5923 struct peer *peer;
5924 int allow_num = 0;
5925
5926 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5927 if (!peer)
5928 return CMD_WARNING_CONFIG_FAILED;
5929
5930 if (argc <= idx_number_origin)
5931 allow_num = 3;
5932 else {
5933 if (argv[idx_number_origin]->type == WORD_TKN)
5934 origin = 1;
5935 else
5936 allow_num = atoi(argv[idx_number_origin]->arg);
5937 }
5938
5939 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5940 allow_num, origin);
5941
5942 return bgp_vty_return(vty, ret);
5943}
5944
5945ALIAS_HIDDEN(
5946 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
5947 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5948 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5949 "Accept as-path with my AS present in it\n"
5950 "Number of occurances of AS number\n"
5951 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5952
718e3744 5953DEFUN (no_neighbor_allowas_in,
5954 no_neighbor_allowas_in_cmd,
fd8503f5 5955 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5956 NO_STR
5957 NEIGHBOR_STR
5958 NEIGHBOR_ADDR_STR2
8334fd5a 5959 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
5960 "Number of occurances of AS number\n"
5961 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5962{
d62a17ae 5963 int idx_peer = 2;
5964 int ret;
5965 struct peer *peer;
718e3744 5966
d62a17ae 5967 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5968 if (!peer)
5969 return CMD_WARNING_CONFIG_FAILED;
718e3744 5970
d62a17ae 5971 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
5972 bgp_node_safi(vty));
718e3744 5973
d62a17ae 5974 return bgp_vty_return(vty, ret);
718e3744 5975}
6b0655a2 5976
d62a17ae 5977ALIAS_HIDDEN(
5978 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
5979 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5980 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5981 "allow local ASN appears in aspath attribute\n"
5982 "Number of occurances of AS number\n"
5983 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5984
fa411a21
NH
5985DEFUN (neighbor_ttl_security,
5986 neighbor_ttl_security_cmd,
7ebe625c 5987 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 5988 NEIGHBOR_STR
7ebe625c 5989 NEIGHBOR_ADDR_STR2
16cedbb0 5990 "BGP ttl-security parameters\n"
d7fa34c1
QY
5991 "Specify the maximum number of hops to the BGP peer\n"
5992 "Number of hops to BGP peer\n")
fa411a21 5993{
d62a17ae 5994 int idx_peer = 1;
5995 int idx_number = 4;
5996 struct peer *peer;
5997 int gtsm_hops;
5998
5999 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6000 if (!peer)
6001 return CMD_WARNING_CONFIG_FAILED;
6002
6003 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6004
7ebe625c
QY
6005 /*
6006 * If 'neighbor swpX', then this is for directly connected peers,
6007 * we should not accept a ttl-security hops value greater than 1.
6008 */
6009 if (peer->conf_if && (gtsm_hops > 1)) {
6010 vty_out(vty,
6011 "%s is directly connected peer, hops cannot exceed 1\n",
6012 argv[idx_peer]->arg);
6013 return CMD_WARNING_CONFIG_FAILED;
6014 }
6015
d62a17ae 6016 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6017}
6018
6019DEFUN (no_neighbor_ttl_security,
6020 no_neighbor_ttl_security_cmd,
7ebe625c 6021 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6022 NO_STR
6023 NEIGHBOR_STR
7ebe625c 6024 NEIGHBOR_ADDR_STR2
16cedbb0 6025 "BGP ttl-security parameters\n"
3a2d747c
QY
6026 "Specify the maximum number of hops to the BGP peer\n"
6027 "Number of hops to BGP peer\n")
fa411a21 6028{
d62a17ae 6029 int idx_peer = 2;
6030 struct peer *peer;
fa411a21 6031
d62a17ae 6032 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6033 if (!peer)
6034 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6035
d62a17ae 6036 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6037}
6b0655a2 6038
adbac85e
DW
6039DEFUN (neighbor_addpath_tx_all_paths,
6040 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6041 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6042 NEIGHBOR_STR
6043 NEIGHBOR_ADDR_STR2
6044 "Use addpath to advertise all paths to a neighbor\n")
6045{
d62a17ae 6046 int idx_peer = 1;
6047 struct peer *peer;
adbac85e 6048
d62a17ae 6049 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6050 if (!peer)
6051 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6052
d62a17ae 6053 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6054 bgp_node_safi(vty),
6055 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6056}
6057
d62a17ae 6058ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6059 neighbor_addpath_tx_all_paths_hidden_cmd,
6060 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6061 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6062 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6063
adbac85e
DW
6064DEFUN (no_neighbor_addpath_tx_all_paths,
6065 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6066 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6067 NO_STR
6068 NEIGHBOR_STR
6069 NEIGHBOR_ADDR_STR2
6070 "Use addpath to advertise all paths to a neighbor\n")
6071{
d62a17ae 6072 int idx_peer = 2;
6073 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6074 bgp_node_afi(vty), bgp_node_safi(vty),
6075 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6076}
6077
d62a17ae 6078ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6079 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6080 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6081 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6082 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6083
06370dac
DW
6084DEFUN (neighbor_addpath_tx_bestpath_per_as,
6085 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6086 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6087 NEIGHBOR_STR
6088 NEIGHBOR_ADDR_STR2
6089 "Use addpath to advertise the bestpath per each neighboring AS\n")
6090{
d62a17ae 6091 int idx_peer = 1;
6092 struct peer *peer;
06370dac 6093
d62a17ae 6094 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6095 if (!peer)
6096 return CMD_WARNING_CONFIG_FAILED;
06370dac 6097
d62a17ae 6098 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6099 bgp_node_safi(vty),
6100 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6101}
6102
d62a17ae 6103ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6104 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6105 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6106 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6107 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6108
06370dac
DW
6109DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6110 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6111 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6112 NO_STR
6113 NEIGHBOR_STR
6114 NEIGHBOR_ADDR_STR2
6115 "Use addpath to advertise the bestpath per each neighboring AS\n")
6116{
d62a17ae 6117 int idx_peer = 2;
6118 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6119 bgp_node_afi(vty), bgp_node_safi(vty),
6120 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6121}
6122
d62a17ae 6123ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6124 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6125 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6126 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6127 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6128
b9c7bc5a
PZ
6129static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6130 struct ecommunity **list)
ddb5b488 6131{
b9c7bc5a
PZ
6132 struct ecommunity *ecom = NULL;
6133 struct ecommunity *ecomadd;
ddb5b488 6134
b9c7bc5a 6135 for (; argc; --argc, ++argv) {
ddb5b488 6136
b9c7bc5a
PZ
6137 ecomadd = ecommunity_str2com(argv[0]->arg,
6138 ECOMMUNITY_ROUTE_TARGET, 0);
6139 if (!ecomadd) {
6140 vty_out(vty, "Malformed community-list value\n");
6141 if (ecom)
6142 ecommunity_free(&ecom);
6143 return CMD_WARNING_CONFIG_FAILED;
6144 }
ddb5b488 6145
b9c7bc5a
PZ
6146 if (ecom) {
6147 ecommunity_merge(ecom, ecomadd);
6148 ecommunity_free(&ecomadd);
6149 } else {
6150 ecom = ecomadd;
6151 }
6152 }
6153
6154 if (*list) {
6155 ecommunity_free(&*list);
ddb5b488 6156 }
b9c7bc5a
PZ
6157 *list = ecom;
6158
6159 return CMD_SUCCESS;
ddb5b488
PZ
6160}
6161
b9c7bc5a 6162static int vpn_policy_getafi(struct vty *vty, int *doafi)
ddb5b488
PZ
6163{
6164 switch (vty->node) {
b9c7bc5a 6165 case BGP_IPV4_NODE:
ddb5b488
PZ
6166 doafi[AFI_IP] = 1;
6167 break;
b9c7bc5a 6168 case BGP_IPV6_NODE:
ddb5b488
PZ
6169 doafi[AFI_IP6] = 1;
6170 break;
6171 default:
6172 vty_out(vty,
b9c7bc5a 6173 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
ddb5b488
PZ
6174 return CMD_WARNING_CONFIG_FAILED;
6175 }
6176 return CMD_SUCCESS;
6177}
6178
b9c7bc5a
PZ
6179DEFPY (af_rd_vpn_export,
6180 af_rd_vpn_export_cmd,
6181 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6182 NO_STR
ddb5b488 6183 "Specify route distinguisher\n"
b9c7bc5a
PZ
6184 "Between current address-family and vpn\n"
6185 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6186 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6187{
6188 VTY_DECLVAR_CONTEXT(bgp, bgp);
6189 struct prefix_rd prd;
6190 int ret;
6191 int doafi[AFI_MAX] = {0};
6192 afi_t afi;
b9c7bc5a
PZ
6193 int idx = 0;
6194 int yes = 1;
ddb5b488 6195
b9c7bc5a 6196 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6197 yes = 0;
b9c7bc5a
PZ
6198
6199 if (yes) {
6200 ret = str2prefix_rd(rd_str, &prd);
6201 if (!ret) {
6202 vty_out(vty, "%% Malformed rd\n");
6203 return CMD_WARNING_CONFIG_FAILED;
6204 }
ddb5b488
PZ
6205 }
6206
b9c7bc5a 6207 ret = vpn_policy_getafi(vty, doafi);
ddb5b488
PZ
6208 if (ret != CMD_SUCCESS)
6209 return ret;
6210
6211
6212 for (afi = 0; afi < AFI_MAX; ++afi) {
6213 if (!doafi[afi])
6214 continue;
6215
6216 /* pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6217 */
6218 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6219 bgp_get_default(), bgp);
6220
b9c7bc5a
PZ
6221 if (yes) {
6222 bgp->vpn_policy[afi].tovpn_rd = prd;
6223 SET_FLAG(bgp->vpn_policy[afi].flags,
6224 BGP_VPN_POLICY_TOVPN_RD_SET);
6225 } else {
6226 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6227 BGP_VPN_POLICY_TOVPN_RD_SET);
6228 }
ddb5b488
PZ
6229
6230 /* post-change: re-export vpn routes */
6231 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6232 bgp_get_default(), bgp);
6233 }
6234
6235 return CMD_SUCCESS;
6236}
6237
b9c7bc5a
PZ
6238ALIAS (af_rd_vpn_export,
6239 af_no_rd_vpn_export_cmd,
6240 "no rd vpn export",
ddb5b488 6241 NO_STR
b9c7bc5a
PZ
6242 "Specify route distinguisher\n"
6243 "Between current address-family and vpn\n"
6244 "For routes leaked from current address-family to vpn\n")
ddb5b488 6245
b9c7bc5a
PZ
6246DEFPY (af_label_vpn_export,
6247 af_label_vpn_export_cmd,
e70e9f8e 6248 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6249 NO_STR
ddb5b488 6250 "label value for VRF\n"
b9c7bc5a
PZ
6251 "Between current address-family and vpn\n"
6252 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6253 "Label Value <0-1048575>\n"
6254 "Automatically assign a label\n")
ddb5b488
PZ
6255{
6256 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6257 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488
PZ
6258 int doafi[AFI_MAX] = {0};
6259 afi_t afi;
6260 int ret;
b9c7bc5a
PZ
6261 int idx = 0;
6262 int yes = 1;
6263
6264 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6265 yes = 0;
ddb5b488 6266
e70e9f8e
PZ
6267 if (yes) {
6268 if (!label_auto)
6269 label = label_val; /* parser should force unsigned */
6270 }
ddb5b488 6271
b9c7bc5a 6272 ret = vpn_policy_getafi(vty, doafi);
ddb5b488
PZ
6273 if (ret != CMD_SUCCESS)
6274 return ret;
6275
6276 for (afi = 0; afi < AFI_MAX; ++afi) {
6277 if (!doafi[afi])
6278 continue;
6279
e70e9f8e
PZ
6280 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6281 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6282
6283 continue; /* no change */
6284
b9c7bc5a
PZ
6285 /*
6286 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
ddb5b488
PZ
6287 */
6288 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6289 bgp_get_default(), bgp);
6290
e70e9f8e
PZ
6291 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6292 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6293
6294 if (bgp->vpn_policy[afi].tovpn_label !=
6295 MPLS_LABEL_NONE) {
6296
6297 /*
6298 * label has previously been automatically
6299 * assigned by labelpool: release it
6300 *
6301 * NB if tovpn_label == MPLS_LABEL_NONE it
6302 * means the automatic assignment is in flight
6303 * and therefore the labelpool callback must
6304 * detect that the auto label is not needed.
6305 */
6306
6307 bgp_lp_release(LP_TYPE_VRF,
6308 &bgp->vpn_policy[afi],
6309 bgp->vpn_policy[afi].tovpn_label);
6310 }
6311 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6312 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6313 }
6314
ddb5b488 6315 bgp->vpn_policy[afi].tovpn_label = label;
e70e9f8e
PZ
6316 if (label_auto) {
6317 SET_FLAG(bgp->vpn_policy[afi].flags,
6318 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6319 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6320 vpn_leak_label_callback);
6321 }
ddb5b488
PZ
6322
6323 /* post-change: re-export vpn routes */
6324 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6325 bgp_get_default(), bgp);
6326 }
6327
6328 return CMD_SUCCESS;
6329}
6330
b9c7bc5a
PZ
6331ALIAS (af_label_vpn_export,
6332 af_no_label_vpn_export_cmd,
6333 "no label vpn export",
6334 NO_STR
6335 "label value for VRF\n"
6336 "Between current address-family and vpn\n"
6337 "For routes leaked from current address-family to vpn\n")
ddb5b488 6338
b9c7bc5a
PZ
6339DEFPY (af_nexthop_vpn_export,
6340 af_nexthop_vpn_export_cmd,
6341 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6342 NO_STR
ddb5b488 6343 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6344 "Between current address-family and vpn\n"
6345 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6346 "IPv4 prefix\n"
6347 "IPv6 prefix\n")
6348{
6349 VTY_DECLVAR_CONTEXT(bgp, bgp);
6350 int doafi[AFI_MAX] = {0};
6351 afi_t afi;
6352 int ret;
6353 struct prefix p;
b9c7bc5a
PZ
6354 int idx = 0;
6355 int yes = 1;
ddb5b488 6356
b9c7bc5a 6357 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6358 yes = 0;
b9c7bc5a
PZ
6359
6360 if (yes) {
6361 if (!sockunion2hostprefix(nexthop_str, &p))
6362 return CMD_WARNING_CONFIG_FAILED;
6363 }
ddb5b488 6364
b9c7bc5a 6365 ret = vpn_policy_getafi(vty, doafi);
ddb5b488
PZ
6366 if (ret != CMD_SUCCESS)
6367 return ret;
6368
6369 for (afi = 0; afi < AFI_MAX; ++afi) {
6370 if (!doafi[afi])
6371 continue;
6372
6373 /*
6374 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6375 */
6376 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6377 bgp_get_default(), bgp);
6378
b9c7bc5a
PZ
6379 if (yes) {
6380 bgp->vpn_policy[afi].tovpn_nexthop = p;
6381 SET_FLAG(bgp->vpn_policy[afi].flags,
6382 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6383 } else {
6384 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6385 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6386 }
ddb5b488
PZ
6387
6388 /* post-change: re-export vpn routes */
6389 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6390 bgp_get_default(), bgp);
6391 }
6392
6393 return CMD_SUCCESS;
6394}
6395
b9c7bc5a
PZ
6396ALIAS (af_nexthop_vpn_export,
6397 af_no_nexthop_vpn_export_cmd,
6398 "no nexthop vpn export",
ddb5b488 6399 NO_STR
b9c7bc5a
PZ
6400 "Specify next hop to use for VRF advertised prefixes\n"
6401 "Between current address-family and vpn\n"
6402 "For routes leaked from current address-family to vpn\n")
ddb5b488 6403
b9c7bc5a 6404static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6405{
b9c7bc5a
PZ
6406 if (!strcmp(dstr, "import")) {
6407 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6408 } else if (!strcmp(dstr, "export")) {
6409 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6410 } else if (!strcmp(dstr, "both")) {
6411 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6412 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6413 } else {
6414 vty_out(vty, "%% direction parse error\n");
6415 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6416 }
ddb5b488
PZ
6417 return CMD_SUCCESS;
6418}
6419
b9c7bc5a
PZ
6420DEFPY (af_rt_vpn_imexport,
6421 af_rt_vpn_imexport_cmd,
6422 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6423 NO_STR
6424 "Specify route target list\n"
ddb5b488 6425 "Specify route target list\n"
b9c7bc5a
PZ
6426 "Between current address-family and vpn\n"
6427 "For routes leaked from vpn to current address-family: match any\n"
6428 "For routes leaked from current address-family to vpn: set\n"
6429 "both import: match any and export: set\n"
ddb5b488
PZ
6430 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6431{
6432 VTY_DECLVAR_CONTEXT(bgp, bgp);
6433 int ret;
6434 struct ecommunity *ecom = NULL;
6435 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6436 int doafi[AFI_MAX] = {0};
6437 vpn_policy_direction_t dir;
6438 afi_t afi;
6439 int idx = 0;
b9c7bc5a 6440 int yes = 1;
ddb5b488 6441
b9c7bc5a 6442 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6443 yes = 0;
b9c7bc5a
PZ
6444
6445 ret = vpn_policy_getafi(vty, doafi);
ddb5b488
PZ
6446 if (ret != CMD_SUCCESS)
6447 return ret;
6448
b9c7bc5a 6449 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6450 if (ret != CMD_SUCCESS)
6451 return ret;
6452
b9c7bc5a
PZ
6453 if (yes) {
6454 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6455 vty_out(vty, "%% Missing RTLIST\n");
6456 return CMD_WARNING_CONFIG_FAILED;
6457 }
6458 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6459 if (ret != CMD_SUCCESS) {
6460 return ret;
6461 }
ddb5b488
PZ
6462 }
6463
6464 for (afi = 0; afi < AFI_MAX; ++afi) {
6465 if (!doafi[afi])
6466 continue;
6467 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6468 if (!dodir[dir])
6469 continue;
6470
6471 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6472
b9c7bc5a
PZ
6473 if (yes) {
6474 if (bgp->vpn_policy[afi].rtlist[dir])
6475 ecommunity_free(
6476 &bgp->vpn_policy[afi].rtlist[dir]);
6477 bgp->vpn_policy[afi].rtlist[dir] =
6478 ecommunity_dup(ecom);
6479 } else {
6480 if (bgp->vpn_policy[afi].rtlist[dir])
6481 ecommunity_free(
6482 &bgp->vpn_policy[afi].rtlist[dir]);
6483 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6484 }
ddb5b488
PZ
6485
6486 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6487 }
6488 }
d555f3e9
PZ
6489 if (ecom)
6490 ecommunity_free(&ecom);
ddb5b488
PZ
6491
6492 return CMD_SUCCESS;
6493}
6494
b9c7bc5a
PZ
6495ALIAS (af_rt_vpn_imexport,
6496 af_no_rt_vpn_imexport_cmd,
6497 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6498 NO_STR
6499 "Specify route target list\n"
b9c7bc5a
PZ
6500 "Specify route target list\n"
6501 "Between current address-family and vpn\n"
6502 "For routes leaked from vpn to current address-family\n"
6503 "For routes leaked from current address-family to vpn\n"
6504 "both import and export\n")
6505
6506DEFPY (af_route_map_vpn_imexport,
6507 af_route_map_vpn_imexport_cmd,
6508/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6509 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6510 NO_STR
ddb5b488 6511 "Specify route map\n"
b9c7bc5a
PZ
6512 "Between current address-family and vpn\n"
6513 "For routes leaked from vpn to current address-family\n"
6514 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6515 "name of route-map\n")
6516{
6517 VTY_DECLVAR_CONTEXT(bgp, bgp);
6518 int ret;
6519 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6520 int doafi[AFI_MAX] = {0};
6521 vpn_policy_direction_t dir;
6522 afi_t afi;
ddb5b488 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
PZ
6528
6529 ret = vpn_policy_getafi(vty, doafi);
ddb5b488
PZ
6530 if (ret != CMD_SUCCESS)
6531 return ret;
6532
b9c7bc5a 6533 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6534 if (ret != CMD_SUCCESS)
6535 return ret;
6536
6537 for (afi = 0; afi < AFI_MAX; ++afi) {
6538 if (!doafi[afi])
6539 continue;
6540 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6541 if (!dodir[dir])
6542 continue;
6543
6544 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6545
b9c7bc5a
PZ
6546 if (yes) {
6547 if (bgp->vpn_policy[afi].rmap_name[dir])
6548 XFREE(MTYPE_ROUTE_MAP_NAME,
6549 bgp->vpn_policy[afi].rmap_name[dir]);
6550 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6551 MTYPE_ROUTE_MAP_NAME, rmap_str);
6552 bgp->vpn_policy[afi].rmap[dir] =
6553 route_map_lookup_by_name(rmap_str);
e49840c8
DS
6554 if (!bgp->vpn_policy[afi].rmap[dir])
6555 return CMD_SUCCESS;
b9c7bc5a
PZ
6556 } else {
6557 if (bgp->vpn_policy[afi].rmap_name[dir])
6558 XFREE(MTYPE_ROUTE_MAP_NAME,
6559 bgp->vpn_policy[afi].rmap_name[dir]);
6560 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6561 bgp->vpn_policy[afi].rmap[dir] = NULL;
6562 }
ddb5b488
PZ
6563
6564 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6565 }
6566 }
6567
6568 return CMD_SUCCESS;
6569}
6570
b9c7bc5a
PZ
6571ALIAS (af_route_map_vpn_imexport,
6572 af_no_route_map_vpn_imexport_cmd,
6573 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6574 NO_STR
6575 "Specify route map\n"
b9c7bc5a
PZ
6576 "Between current address-family and vpn\n"
6577 "For routes leaked from vpn to current address-family\n"
6578 "For routes leaked from current address-family to vpn\n")
6579
bb4f6190
DS
6580DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6581 "[no] import vrf route-map RMAP$rmap_str",
6582 NO_STR
6583 "Import routes from another VRF\n"
6584 "Vrf routes being filtered\n"
6585 "Specify route map\n"
6586 "name of route-map\n")
6587{
6588 VTY_DECLVAR_CONTEXT(bgp, bgp);
6589 int ret;
6590 int doafi[AFI_MAX] = {0};
6591 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6592 afi_t afi;
6593 int idx = 0;
6594 int yes = 1;
6595 struct bgp *bgp_default;
6596
6597 if (argv_find(argv, argc, "no", &idx))
6598 yes = 0;
6599
6600 ret = vpn_policy_getafi(vty, doafi);
6601 if (ret != CMD_SUCCESS)
6602 return ret;
6603
6604 bgp_default = bgp_get_default();
6605 if (!bgp_default) {
6606 int32_t ret;
6607 as_t as = bgp->as;
6608
6609 /* Auto-create assuming the same AS */
6610 ret = bgp_get(&bgp_default, &as, NULL,
6611 BGP_INSTANCE_TYPE_DEFAULT);
6612
6613 if (ret) {
6614 vty_out(vty,
6615 "VRF default is not configured as a bgp instance\n");
6616 return CMD_WARNING;
6617 }
6618 }
6619
6620 for (afi = 0; afi < AFI_MAX; ++afi) {
6621 if (!doafi[afi])
6622 continue;
6623
6624 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6625
6626 if (yes) {
6627 if (bgp->vpn_policy[afi].rmap_name[dir])
6628 XFREE(MTYPE_ROUTE_MAP_NAME,
6629 bgp->vpn_policy[afi].rmap_name[dir]);
6630 bgp->vpn_policy[afi].rmap_name[dir] =
6631 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6632 bgp->vpn_policy[afi].rmap[dir] =
6633 route_map_lookup_by_name(rmap_str);
e49840c8
DS
6634 if (!bgp->vpn_policy[afi].rmap[dir])
6635 return CMD_SUCCESS;
bb4f6190
DS
6636 } else {
6637 if (bgp->vpn_policy[afi].rmap_name[dir])
6638 XFREE(MTYPE_ROUTE_MAP_NAME,
6639 bgp->vpn_policy[afi].rmap_name[dir]);
6640 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6641 bgp->vpn_policy[afi].rmap[dir] = NULL;
6642 }
6643
6644 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6645 }
6646
6647 return CMD_SUCCESS;
6648}
6649
6650ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6651 "no import vrf route-map",
6652 NO_STR
6653 "Import routes from another VRF\n"
6654 "Vrf routes being filtered\n"
6655 "Specify route map\n")
6656
12a844a5
DS
6657DEFPY (bgp_imexport_vrf,
6658 bgp_imexport_vrf_cmd,
6659 "[no] import vrf NAME$import_name",
6660 NO_STR
6661 "Import routes from another VRF\n"
6662 "VRF to import from\n"
6663 "The name of the VRF\n")
6664{
6665 VTY_DECLVAR_CONTEXT(bgp, bgp);
6666 struct listnode *node;
79ef8664
DS
6667 struct bgp *vrf_bgp, *bgp_default;
6668 int32_t ret = 0;
6669 as_t as = bgp->as;
12a844a5
DS
6670 bool remove = false;
6671 int32_t idx = 0;
6672 char *vname;
a8dadcf6 6673 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6674 safi_t safi;
6675 afi_t afi;
6676
6677 if (argv_find(argv, argc, "no", &idx))
6678 remove = true;
6679
6680 afi = bgp_node_afi(vty);
6681 safi = bgp_node_safi(vty);
6682
25679caa
DS
6683 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6684 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6685 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6686 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6687 remove ? "unimport" : "import", import_name);
6688 return CMD_WARNING;
6689 }
6690
79ef8664
DS
6691 bgp_default = bgp_get_default();
6692 if (!bgp_default) {
6693 /* Auto-create assuming the same AS */
6694 ret = bgp_get(&bgp_default, &as, NULL,
6695 BGP_INSTANCE_TYPE_DEFAULT);
6696
6697 if (ret) {
6698 vty_out(vty,
6699 "VRF default is not configured as a bgp instance\n");
6700 return CMD_WARNING;
6701 }
6702 }
6703
12a844a5
DS
6704 vrf_bgp = bgp_lookup_by_name(import_name);
6705 if (!vrf_bgp) {
79ef8664
DS
6706 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6707 vrf_bgp = bgp_default;
6708 else
0fb8d6e6
DS
6709 /* Auto-create assuming the same AS */
6710 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6711
6e2c7fe6 6712 if (ret) {
020a3f60
DS
6713 vty_out(vty,
6714 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6715 import_name);
6716 return CMD_WARNING;
6717 }
12a844a5
DS
6718 }
6719
12a844a5 6720 if (remove) {
44338987 6721 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6722 } else {
44338987 6723 /* Already importing from "import_vrf"? */
12a844a5
DS
6724 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6725 vname)) {
6726 if (strcmp(vname, import_name) == 0)
6727 return CMD_WARNING;
6728 }
6729
44338987 6730 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6731 }
6732
6733 return CMD_SUCCESS;
6734}
6735
b9c7bc5a
PZ
6736/* This command is valid only in a bgp vrf instance or the default instance */
6737DEFPY (bgp_imexport_vpn,
6738 bgp_imexport_vpn_cmd,
6739 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6740 NO_STR
6741 "Import routes to this address-family\n"
6742 "Export routes from this address-family\n"
6743 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6744{
6745 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6746 int previous_state;
ddb5b488 6747 afi_t afi;
b9c7bc5a 6748 safi_t safi;
ddb5b488 6749 int idx = 0;
b9c7bc5a
PZ
6750 int yes = 1;
6751 int flag;
6752 vpn_policy_direction_t dir;
ddb5b488 6753
b9c7bc5a 6754 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6755 yes = 0;
ddb5b488 6756
b9c7bc5a
PZ
6757 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6758 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6759
b9c7bc5a
PZ
6760 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6761 return CMD_WARNING_CONFIG_FAILED;
6762 }
ddb5b488 6763
b9c7bc5a
PZ
6764 afi = bgp_node_afi(vty);
6765 safi = bgp_node_safi(vty);
6766 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6767 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6768 return CMD_WARNING_CONFIG_FAILED;
6769 }
ddb5b488 6770
b9c7bc5a
PZ
6771 if (!strcmp(direction_str, "import")) {
6772 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6773 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6774 } else if (!strcmp(direction_str, "export")) {
6775 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6776 dir = BGP_VPN_POLICY_DIR_TOVPN;
6777 } else {
6778 vty_out(vty, "%% unknown direction %s\n", direction_str);
6779 return CMD_WARNING_CONFIG_FAILED;
6780 }
6781
6782 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 6783
b9c7bc5a
PZ
6784 if (yes) {
6785 SET_FLAG(bgp->af_flags[afi][safi], flag);
6786 if (!previous_state) {
6787 /* trigger export current vrf */
ddb5b488
PZ
6788 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6789 }
b9c7bc5a
PZ
6790 } else {
6791 if (previous_state) {
6792 /* trigger un-export current vrf */
6793 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6794 }
6795 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
6796 }
6797
6798 return CMD_SUCCESS;
6799}
6800
301ad80a
PG
6801DEFPY (af_routetarget_import,
6802 af_routetarget_import_cmd,
6803 "[no] <rt|route-target> redirect import RTLIST...",
6804 NO_STR
6805 "Specify route target list\n"
6806 "Specify route target list\n"
6807 "Flow-spec redirect type route target\n"
6808 "Import routes to this address-family\n"
6809 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6810{
6811 VTY_DECLVAR_CONTEXT(bgp, bgp);
6812 int ret;
6813 struct ecommunity *ecom = NULL;
6814 int doafi[AFI_MAX] = {0};
6815 afi_t afi;
6816 int idx = 0;
6817 int yes = 1;
6818
6819 if (argv_find(argv, argc, "no", &idx))
6820 yes = 0;
6821
6822 ret = vpn_policy_getafi(vty, doafi);
6823 if (ret != CMD_SUCCESS)
6824 return ret;
6825 if (yes) {
6826 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6827 vty_out(vty, "%% Missing RTLIST\n");
6828 return CMD_WARNING_CONFIG_FAILED;
6829 }
6830 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6831 if (ret != CMD_SUCCESS)
6832 return ret;
6833 }
6834 for (afi = 0; afi < AFI_MAX; ++afi) {
6835 if (!doafi[afi])
6836 continue;
6837 if (yes) {
6838 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6839 ecommunity_free(
6840 &bgp->vpn_policy[afi]
6841 .import_redirect_rtlist);
6842 bgp->vpn_policy[afi].import_redirect_rtlist =
6843 ecommunity_dup(ecom);
6844 } else {
6845 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6846 ecommunity_free(
6847 &bgp->vpn_policy[afi]
6848 .import_redirect_rtlist);
6849 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
6850 }
6851 }
6852 if (ecom)
6853 ecommunity_free(&ecom);
6854
6855 return CMD_SUCCESS;
6856}
6857
505e5056 6858DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 6859 address_family_ipv4_safi_cmd,
6860 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6861 "Enter Address Family command mode\n"
6862 "Address Family\n"
6863 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6864{
f51bae9c 6865
d62a17ae 6866 if (argc == 3) {
2131d5cf 6867 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6868 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6869 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6870 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6871 && safi != SAFI_EVPN) {
31947174
MK
6872 vty_out(vty,
6873 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6874 return CMD_WARNING_CONFIG_FAILED;
6875 }
d62a17ae 6876 vty->node = bgp_node_type(AFI_IP, safi);
6877 } else
6878 vty->node = BGP_IPV4_NODE;
718e3744 6879
d62a17ae 6880 return CMD_SUCCESS;
718e3744 6881}
6882
505e5056 6883DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 6884 address_family_ipv6_safi_cmd,
6885 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6886 "Enter Address Family command mode\n"
6887 "Address Family\n"
6888 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6889{
d62a17ae 6890 if (argc == 3) {
2131d5cf 6891 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6892 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6893 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6894 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6895 && safi != SAFI_EVPN) {
31947174
MK
6896 vty_out(vty,
6897 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6898 return CMD_WARNING_CONFIG_FAILED;
6899 }
d62a17ae 6900 vty->node = bgp_node_type(AFI_IP6, safi);
6901 } else
6902 vty->node = BGP_IPV6_NODE;
25ffbdc1 6903
d62a17ae 6904 return CMD_SUCCESS;
25ffbdc1 6905}
718e3744 6906
d6902373 6907#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6908DEFUN_NOSH (address_family_vpnv4,
718e3744 6909 address_family_vpnv4_cmd,
8334fd5a 6910 "address-family vpnv4 [unicast]",
718e3744 6911 "Enter Address Family command mode\n"
8c3deaae 6912 "Address Family\n"
3a2d747c 6913 "Address Family modifier\n")
718e3744 6914{
d62a17ae 6915 vty->node = BGP_VPNV4_NODE;
6916 return CMD_SUCCESS;
718e3744 6917}
6918
505e5056 6919DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6920 address_family_vpnv6_cmd,
8334fd5a 6921 "address-family vpnv6 [unicast]",
8ecd3266 6922 "Enter Address Family command mode\n"
8c3deaae 6923 "Address Family\n"
3a2d747c 6924 "Address Family modifier\n")
8ecd3266 6925{
d62a17ae 6926 vty->node = BGP_VPNV6_NODE;
6927 return CMD_SUCCESS;
8ecd3266 6928}
c016b6c7 6929#endif
d6902373 6930
505e5056 6931DEFUN_NOSH (address_family_evpn,
4e0b7b6d 6932 address_family_evpn_cmd,
7111c1a0 6933 "address-family l2vpn evpn",
4e0b7b6d 6934 "Enter Address Family command mode\n"
7111c1a0
QY
6935 "Address Family\n"
6936 "Address Family modifier\n")
4e0b7b6d 6937{
2131d5cf 6938 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6939 vty->node = BGP_EVPN_NODE;
6940 return CMD_SUCCESS;
4e0b7b6d
PG
6941}
6942
505e5056 6943DEFUN_NOSH (exit_address_family,
718e3744 6944 exit_address_family_cmd,
6945 "exit-address-family",
6946 "Exit from Address Family configuration mode\n")
6947{
d62a17ae 6948 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
6949 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
6950 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
6951 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
6952 || vty->node == BGP_EVPN_NODE
6953 || vty->node == BGP_FLOWSPECV4_NODE
6954 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 6955 vty->node = BGP_NODE;
6956 return CMD_SUCCESS;
718e3744 6957}
6b0655a2 6958
8ad7271d 6959/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 6960static int bgp_clear_prefix(struct vty *vty, const char *view_name,
6961 const char *ip_str, afi_t afi, safi_t safi,
6962 struct prefix_rd *prd)
6963{
6964 int ret;
6965 struct prefix match;
6966 struct bgp_node *rn;
6967 struct bgp_node *rm;
6968 struct bgp *bgp;
6969 struct bgp_table *table;
6970 struct bgp_table *rib;
6971
6972 /* BGP structure lookup. */
6973 if (view_name) {
6974 bgp = bgp_lookup_by_name(view_name);
6975 if (bgp == NULL) {
6976 vty_out(vty, "%% Can't find BGP instance %s\n",
6977 view_name);
6978 return CMD_WARNING;
6979 }
6980 } else {
6981 bgp = bgp_get_default();
6982 if (bgp == NULL) {
6983 vty_out(vty, "%% No BGP process is configured\n");
6984 return CMD_WARNING;
6985 }
6986 }
6987
6988 /* Check IP address argument. */
6989 ret = str2prefix(ip_str, &match);
6990 if (!ret) {
6991 vty_out(vty, "%% address is malformed\n");
6992 return CMD_WARNING;
6993 }
6994
6995 match.family = afi2family(afi);
6996 rib = bgp->rib[afi][safi];
6997
6998 if (safi == SAFI_MPLS_VPN) {
6999 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7000 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7001 continue;
7002
7003 if ((table = rn->info) != NULL) {
7004 if ((rm = bgp_node_match(table, &match))
7005 != NULL) {
7006 if (rm->p.prefixlen
7007 == match.prefixlen) {
7008 SET_FLAG(rn->flags,
7009 BGP_NODE_USER_CLEAR);
7010 bgp_process(bgp, rm, afi, safi);
7011 }
7012 bgp_unlock_node(rm);
7013 }
7014 }
7015 }
7016 } else {
7017 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7018 if (rn->p.prefixlen == match.prefixlen) {
7019 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7020 bgp_process(bgp, rn, afi, safi);
7021 }
7022 bgp_unlock_node(rn);
7023 }
7024 }
7025
7026 return CMD_SUCCESS;
8ad7271d
DS
7027}
7028
b09b5ae0 7029/* one clear bgp command to rule them all */
718e3744 7030DEFUN (clear_ip_bgp_all,
7031 clear_ip_bgp_all_cmd,
c1a44e43 7032 "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 7033 CLEAR_STR
7034 IP_STR
7035 BGP_STR
838758ac 7036 BGP_INSTANCE_HELP_STR
510afcd6
DS
7037 BGP_AFI_HELP_STR
7038 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
7039 "Clear all peers\n"
7040 "BGP neighbor address to clear\n"
a80beece 7041 "BGP IPv6 neighbor to clear\n"
838758ac 7042 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7043 "Clear peers with the AS number\n"
7044 "Clear all external peers\n"
718e3744 7045 "Clear all members of peer-group\n"
b09b5ae0 7046 "BGP peer-group name\n"
b09b5ae0
DW
7047 BGP_SOFT_STR
7048 BGP_SOFT_IN_STR
b09b5ae0
DW
7049 BGP_SOFT_OUT_STR
7050 BGP_SOFT_IN_STR
7051 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7052 BGP_SOFT_OUT_STR)
718e3744 7053{
d62a17ae 7054 char *vrf = NULL;
7055
7056 afi_t afi = AFI_IP6;
7057 safi_t safi = SAFI_UNICAST;
7058 enum clear_sort clr_sort = clear_peer;
7059 enum bgp_clear_type clr_type;
7060 char *clr_arg = NULL;
7061
7062 int idx = 0;
7063
7064 /* clear [ip] bgp */
7065 if (argv_find(argv, argc, "ip", &idx))
7066 afi = AFI_IP;
7067
7068 /* [<view|vrf> VIEWVRFNAME] */
7069 if (argv_find(argv, argc, "view", &idx)
7070 || argv_find(argv, argc, "vrf", &idx)) {
7071 vrf = argv[idx + 1]->arg;
7072 idx += 2;
7073 }
7074
7075 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7076 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7077 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7078
7079 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7080 if (argv_find(argv, argc, "*", &idx)) {
7081 clr_sort = clear_all;
7082 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7083 clr_sort = clear_peer;
7084 clr_arg = argv[idx]->arg;
7085 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7086 clr_sort = clear_peer;
7087 clr_arg = argv[idx]->arg;
7088 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7089 clr_sort = clear_group;
7090 idx++;
7091 clr_arg = argv[idx]->arg;
7092 } else if (argv_find(argv, argc, "WORD", &idx)) {
7093 clr_sort = clear_peer;
7094 clr_arg = argv[idx]->arg;
7095 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7096 clr_sort = clear_as;
7097 clr_arg = argv[idx]->arg;
7098 } else if (argv_find(argv, argc, "external", &idx)) {
7099 clr_sort = clear_external;
7100 }
7101
7102 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7103 if (argv_find(argv, argc, "soft", &idx)) {
7104 if (argv_find(argv, argc, "in", &idx)
7105 || argv_find(argv, argc, "out", &idx))
7106 clr_type = strmatch(argv[idx]->text, "in")
7107 ? BGP_CLEAR_SOFT_IN
7108 : BGP_CLEAR_SOFT_OUT;
7109 else
7110 clr_type = BGP_CLEAR_SOFT_BOTH;
7111 } else if (argv_find(argv, argc, "in", &idx)) {
7112 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7113 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7114 : BGP_CLEAR_SOFT_IN;
7115 } else if (argv_find(argv, argc, "out", &idx)) {
7116 clr_type = BGP_CLEAR_SOFT_OUT;
7117 } else
7118 clr_type = BGP_CLEAR_SOFT_NONE;
7119
7120 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7121}
01080f7c 7122
8ad7271d
DS
7123DEFUN (clear_ip_bgp_prefix,
7124 clear_ip_bgp_prefix_cmd,
18c57037 7125 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7126 CLEAR_STR
7127 IP_STR
7128 BGP_STR
838758ac 7129 BGP_INSTANCE_HELP_STR
8ad7271d 7130 "Clear bestpath and re-advertise\n"
0c7b1b01 7131 "IPv4 prefix\n")
8ad7271d 7132{
d62a17ae 7133 char *vrf = NULL;
7134 char *prefix = NULL;
8ad7271d 7135
d62a17ae 7136 int idx = 0;
01080f7c 7137
d62a17ae 7138 /* [<view|vrf> VIEWVRFNAME] */
1d35f218 7139 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
d62a17ae 7140 vrf = argv[idx]->arg;
0c7b1b01 7141
d62a17ae 7142 prefix = argv[argc - 1]->arg;
8ad7271d 7143
d62a17ae 7144 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7145}
8ad7271d 7146
b09b5ae0
DW
7147DEFUN (clear_bgp_ipv6_safi_prefix,
7148 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7149 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7150 CLEAR_STR
3a2d747c 7151 IP_STR
718e3744 7152 BGP_STR
8c3deaae 7153 "Address Family\n"
46f296b4 7154 BGP_SAFI_HELP_STR
b09b5ae0 7155 "Clear bestpath and re-advertise\n"
0c7b1b01 7156 "IPv6 prefix\n")
718e3744 7157{
9b475e76
PG
7158 int idx_safi = 0;
7159 int idx_ipv6_prefix = 0;
7160 safi_t safi = SAFI_UNICAST;
7161 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7162 argv[idx_ipv6_prefix]->arg : NULL;
7163
7164 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7165 return bgp_clear_prefix(
9b475e76
PG
7166 vty, NULL, prefix, AFI_IP6,
7167 safi, NULL);
838758ac 7168}
01080f7c 7169
b09b5ae0
DW
7170DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7171 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7172 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7173 CLEAR_STR
3a2d747c 7174 IP_STR
718e3744 7175 BGP_STR
838758ac 7176 BGP_INSTANCE_HELP_STR
8c3deaae 7177 "Address Family\n"
46f296b4 7178 BGP_SAFI_HELP_STR
b09b5ae0 7179 "Clear bestpath and re-advertise\n"
0c7b1b01 7180 "IPv6 prefix\n")
718e3744 7181{
d62a17ae 7182 int idx_word = 3;
9b475e76
PG
7183 int idx_safi = 0;
7184 int idx_ipv6_prefix = 0;
7185 safi_t safi = SAFI_UNICAST;
7186 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7187 argv[idx_ipv6_prefix]->arg : NULL;
7188 /* [<view|vrf> VIEWVRFNAME] */
7189 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7190 argv[idx_word]->arg : NULL;
7191
7192 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7193
d62a17ae 7194 return bgp_clear_prefix(
9b475e76
PG
7195 vty, vrfview, prefix,
7196 AFI_IP6, safi, NULL);
718e3744 7197}
7198
b09b5ae0
DW
7199DEFUN (show_bgp_views,
7200 show_bgp_views_cmd,
d6e3c605 7201 "show [ip] bgp views",
b09b5ae0 7202 SHOW_STR
d6e3c605 7203 IP_STR
01080f7c 7204 BGP_STR
b09b5ae0 7205 "Show the defined BGP views\n")
01080f7c 7206{
d62a17ae 7207 struct list *inst = bm->bgp;
7208 struct listnode *node;
7209 struct bgp *bgp;
01080f7c 7210
d62a17ae 7211 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7212 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7213 return CMD_WARNING;
7214 }
e52702f2 7215
d62a17ae 7216 vty_out(vty, "Defined BGP views:\n");
7217 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7218 /* Skip VRFs. */
7219 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7220 continue;
7221 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7222 bgp->as);
7223 }
e52702f2 7224
d62a17ae 7225 return CMD_SUCCESS;
e0081f70
ML
7226}
7227
8386ac43 7228DEFUN (show_bgp_vrfs,
7229 show_bgp_vrfs_cmd,
d6e3c605 7230 "show [ip] bgp vrfs [json]",
8386ac43 7231 SHOW_STR
d6e3c605 7232 IP_STR
8386ac43 7233 BGP_STR
7234 "Show BGP VRFs\n"
9973d184 7235 JSON_STR)
8386ac43 7236{
fe1dc5a3 7237 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7238 struct list *inst = bm->bgp;
7239 struct listnode *node;
7240 struct bgp *bgp;
d7c0a89a 7241 uint8_t uj = use_json(argc, argv);
d62a17ae 7242 json_object *json = NULL;
7243 json_object *json_vrfs = NULL;
7244 int count = 0;
d62a17ae 7245
7246 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7247 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7248 return CMD_WARNING;
7249 }
7250
7251 if (uj) {
7252 json = json_object_new_object();
7253 json_vrfs = json_object_new_object();
7254 }
7255
7256 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7257 const char *name, *type;
7258 struct peer *peer;
7259 struct listnode *node, *nnode;
7260 int peers_cfg, peers_estb;
7261 json_object *json_vrf = NULL;
d62a17ae 7262
7263 /* Skip Views. */
7264 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7265 continue;
7266
7267 count++;
7268 if (!uj && count == 1)
fe1dc5a3
MK
7269 vty_out(vty,
7270 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7271 "Type", "Id", "routerId", "#PeersVfg",
7272 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7273
7274 peers_cfg = peers_estb = 0;
7275 if (uj)
7276 json_vrf = json_object_new_object();
7277
7278
7279 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7280 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7281 continue;
7282 peers_cfg++;
7283 if (peer->status == Established)
7284 peers_estb++;
7285 }
7286
7287 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7288 name = "Default";
7289 type = "DFLT";
7290 } else {
7291 name = bgp->name;
7292 type = "VRF";
7293 }
7294
a8bf7d9c 7295
d62a17ae 7296 if (uj) {
a4d82a8a
PZ
7297 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7298 ? -1
7299 : (int64_t)bgp->vrf_id;
d62a17ae 7300 json_object_string_add(json_vrf, "type", type);
7301 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7302 json_object_string_add(json_vrf, "routerId",
7303 inet_ntoa(bgp->router_id));
7304 json_object_int_add(json_vrf, "numConfiguredPeers",
7305 peers_cfg);
7306 json_object_int_add(json_vrf, "numEstablishedPeers",
7307 peers_estb);
7308
fe1dc5a3 7309 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7310 json_object_string_add(
7311 json_vrf, "rmac",
7312 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7313 json_object_object_add(json_vrfs, name, json_vrf);
7314 } else
fe1dc5a3
MK
7315 vty_out(vty,
7316 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7317 type,
7318 bgp->vrf_id == VRF_UNKNOWN ? -1
7319 : (int)bgp->vrf_id,
7320 inet_ntoa(bgp->router_id), peers_cfg,
7321 peers_estb, name, bgp->l3vni,
fe1dc5a3 7322 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7323 }
7324
7325 if (uj) {
7326 json_object_object_add(json, "vrfs", json_vrfs);
7327
7328 json_object_int_add(json, "totalVrfs", count);
7329
996c9314
LB
7330 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7331 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7332 json_object_free(json);
7333 } else {
7334 if (count)
7335 vty_out(vty,
7336 "\nTotal number of VRFs (including default): %d\n",
7337 count);
7338 }
7339
7340 return CMD_SUCCESS;
8386ac43 7341}
7342
acf71666
MK
7343static void show_address_entry(struct hash_backet *backet, void *args)
7344{
60466a63
QY
7345 struct vty *vty = (struct vty *)args;
7346 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 7347
60466a63 7348 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
7349 addr->refcnt);
7350}
7351
7352static void show_tip_entry(struct hash_backet *backet, void *args)
7353{
0291c246 7354 struct vty *vty = (struct vty *)args;
60466a63 7355 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7356
60466a63 7357 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7358 tip->refcnt);
7359}
7360
7361static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7362{
7363 vty_out(vty, "self nexthop database:\n");
7364 hash_iterate(bgp->address_hash,
7365 (void (*)(struct hash_backet *, void *))show_address_entry,
7366 vty);
7367
7368 vty_out(vty, "Tunnel-ip database:\n");
7369 hash_iterate(bgp->tip_hash,
7370 (void (*)(struct hash_backet *, void *))show_tip_entry,
7371 vty);
7372}
7373
15c81ca4
DS
7374DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7375 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7376 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7377 "martian next-hops\n"
7378 "martian next-hop database\n")
acf71666 7379{
0291c246 7380 struct bgp *bgp = NULL;
15c81ca4
DS
7381 int idx = 0;
7382
7383 if (argv_find(argv, argc, "view", &idx)
7384 || argv_find(argv, argc, "vrf", &idx))
7385 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7386 else
7387 bgp = bgp_get_default();
acf71666 7388
acf71666
MK
7389 if (!bgp) {
7390 vty_out(vty, "%% No BGP process is configured\n");
7391 return CMD_WARNING;
7392 }
7393 bgp_show_martian_nexthops(vty, bgp);
7394
7395 return CMD_SUCCESS;
7396}
7397
f412b39a 7398DEFUN (show_bgp_memory,
4bf6a362 7399 show_bgp_memory_cmd,
7fa12b13 7400 "show [ip] bgp memory",
4bf6a362 7401 SHOW_STR
3a2d747c 7402 IP_STR
4bf6a362
PJ
7403 BGP_STR
7404 "Global BGP memory statistics\n")
7405{
d62a17ae 7406 char memstrbuf[MTYPE_MEMSTR_LEN];
7407 unsigned long count;
7408
7409 /* RIB related usage stats */
7410 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7411 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7412 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7413 count * sizeof(struct bgp_node)));
7414
7415 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7416 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7417 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7418 count * sizeof(struct bgp_info)));
7419 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7420 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7421 count,
7422 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7423 count * sizeof(struct bgp_info_extra)));
7424
7425 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7426 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7427 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7428 count * sizeof(struct bgp_static)));
7429
7430 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7431 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7432 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7433 count * sizeof(struct bpacket)));
7434
7435 /* Adj-In/Out */
7436 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7437 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7438 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7439 count * sizeof(struct bgp_adj_in)));
7440 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7441 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7442 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7443 count * sizeof(struct bgp_adj_out)));
7444
7445 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7446 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7447 count,
7448 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7449 count * sizeof(struct bgp_nexthop_cache)));
7450
7451 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7452 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7453 count,
7454 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7455 count * sizeof(struct bgp_damp_info)));
7456
7457 /* Attributes */
7458 count = attr_count();
7459 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7460 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7461 count * sizeof(struct attr)));
7462
7463 if ((count = attr_unknown_count()))
7464 vty_out(vty, "%ld unknown attributes\n", count);
7465
7466 /* AS_PATH attributes */
7467 count = aspath_count();
7468 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7469 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7470 count * sizeof(struct aspath)));
7471
7472 count = mtype_stats_alloc(MTYPE_AS_SEG);
7473 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7474 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7475 count * sizeof(struct assegment)));
7476
7477 /* Other attributes */
7478 if ((count = community_count()))
7479 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7480 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7481 count * sizeof(struct community)));
d62a17ae 7482 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7483 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7484 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7485 count * sizeof(struct ecommunity)));
d62a17ae 7486 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7487 vty_out(vty,
7488 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7489 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7490 count * sizeof(struct lcommunity)));
d62a17ae 7491
7492 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7493 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7494 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7495 count * sizeof(struct cluster_list)));
7496
7497 /* Peer related usage */
7498 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7499 vty_out(vty, "%ld peers, using %s of memory\n", count,
7500 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7501 count * sizeof(struct peer)));
7502
7503 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7504 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7505 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7506 count * sizeof(struct peer_group)));
7507
7508 /* Other */
7509 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7510 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7511 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7512 count * sizeof(struct hash)));
7513 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7514 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7515 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7516 count * sizeof(struct hash_backet)));
7517 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7518 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7519 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7520 count * sizeof(regex_t)));
d62a17ae 7521 return CMD_SUCCESS;
4bf6a362 7522}
fee0f4c6 7523
57a9c8a8
DS
7524static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7525{
7526 json_object *bestpath = json_object_new_object();
7527
7528 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7529 json_object_string_add(bestpath, "asPath", "ignore");
7530
7531 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7532 json_object_string_add(bestpath, "asPath", "confed");
7533
7534 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7535 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7536 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7537 "as-set");
7538 else
a4d82a8a 7539 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7540 "true");
7541 } else
a4d82a8a 7542 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7543
7544 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7545 json_object_string_add(bestpath, "compareRouterId", "true");
7546 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7547 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7548 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7549 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7550 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7551 json_object_string_add(bestpath, "med",
7552 "missing-as-worst");
7553 else
7554 json_object_string_add(bestpath, "med", "true");
7555 }
7556
7557 json_object_object_add(json, "bestPath", bestpath);
7558}
7559
718e3744 7560/* Show BGP peer's summary information. */
d62a17ae 7561static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
d7c0a89a 7562 uint8_t use_json, json_object *json)
d62a17ae 7563{
7564 struct peer *peer;
7565 struct listnode *node, *nnode;
7566 unsigned int count = 0, dn_count = 0;
7567 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7568 char neighbor_buf[VTY_BUFSIZ];
7569 int neighbor_col_default_width = 16;
7570 int len;
7571 int max_neighbor_width = 0;
7572 int pfx_rcd_safi;
7573 json_object *json_peer = NULL;
7574 json_object *json_peers = NULL;
7575
7576 /* labeled-unicast routes are installed in the unicast table so in order
7577 * to
7578 * display the correct PfxRcd value we must look at SAFI_UNICAST
7579 */
7580 if (safi == SAFI_LABELED_UNICAST)
7581 pfx_rcd_safi = SAFI_UNICAST;
7582 else
7583 pfx_rcd_safi = safi;
7584
7585 if (use_json) {
7586 if (json == NULL)
7587 json = json_object_new_object();
7588
7589 json_peers = json_object_new_object();
7590 } else {
7591 /* Loop over all neighbors that will be displayed to determine
7592 * how many
7593 * characters are needed for the Neighbor column
7594 */
7595 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7596 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7597 continue;
7598
7599 if (peer->afc[afi][safi]) {
7600 memset(dn_flag, '\0', sizeof(dn_flag));
7601 if (peer_dynamic_neighbor(peer))
7602 dn_flag[0] = '*';
7603
7604 if (peer->hostname
7605 && bgp_flag_check(bgp,
7606 BGP_FLAG_SHOW_HOSTNAME))
7607 sprintf(neighbor_buf, "%s%s(%s) ",
7608 dn_flag, peer->hostname,
7609 peer->host);
7610 else
7611 sprintf(neighbor_buf, "%s%s ", dn_flag,
7612 peer->host);
7613
7614 len = strlen(neighbor_buf);
7615
7616 if (len > max_neighbor_width)
7617 max_neighbor_width = len;
7618 }
7619 }
f933309e 7620
d62a17ae 7621 /* Originally we displayed the Neighbor column as 16
7622 * characters wide so make that the default
7623 */
7624 if (max_neighbor_width < neighbor_col_default_width)
7625 max_neighbor_width = neighbor_col_default_width;
7626 }
f933309e 7627
d62a17ae 7628 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7629 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7630 continue;
7631
ea47320b
DL
7632 if (!peer->afc[afi][safi])
7633 continue;
d62a17ae 7634
ea47320b
DL
7635 if (!count) {
7636 unsigned long ents;
7637 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7638 int64_t vrf_id_ui;
d62a17ae 7639
a4d82a8a
PZ
7640 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7641 ? -1
7642 : (int64_t)bgp->vrf_id;
ea47320b
DL
7643
7644 /* Usage summary and header */
7645 if (use_json) {
7646 json_object_string_add(
7647 json, "routerId",
7648 inet_ntoa(bgp->router_id));
60466a63
QY
7649 json_object_int_add(json, "as", bgp->as);
7650 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7651 json_object_string_add(
7652 json, "vrfName",
7653 (bgp->inst_type
7654 == BGP_INSTANCE_TYPE_DEFAULT)
7655 ? "Default"
7656 : bgp->name);
7657 } else {
7658 vty_out(vty,
7659 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7660 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7661 bgp->vrf_id == VRF_UNKNOWN
7662 ? -1
7663 : (int)bgp->vrf_id);
ea47320b
DL
7664 vty_out(vty, "\n");
7665 }
d62a17ae 7666
ea47320b 7667 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7668 if (use_json) {
ea47320b 7669 json_object_int_add(
60466a63 7670 json, "updateDelayLimit",
ea47320b 7671 bgp->v_update_delay);
d62a17ae 7672
ea47320b
DL
7673 if (bgp->v_update_delay
7674 != bgp->v_establish_wait)
d62a17ae 7675 json_object_int_add(
7676 json,
ea47320b
DL
7677 "updateDelayEstablishWait",
7678 bgp->v_establish_wait);
d62a17ae 7679
60466a63 7680 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7681 json_object_string_add(
7682 json,
7683 "updateDelayFirstNeighbor",
7684 bgp->update_delay_begin_time);
7685 json_object_boolean_true_add(
7686 json,
7687 "updateDelayInProgress");
7688 } else {
7689 if (bgp->update_delay_over) {
d62a17ae 7690 json_object_string_add(
7691 json,
7692 "updateDelayFirstNeighbor",
7693 bgp->update_delay_begin_time);
ea47320b 7694 json_object_string_add(
d62a17ae 7695 json,
ea47320b
DL
7696 "updateDelayBestpathResumed",
7697 bgp->update_delay_end_time);
7698 json_object_string_add(
d62a17ae 7699 json,
ea47320b
DL
7700 "updateDelayZebraUpdateResume",
7701 bgp->update_delay_zebra_resume_time);
7702 json_object_string_add(
7703 json,
7704 "updateDelayPeerUpdateResume",
7705 bgp->update_delay_peers_resume_time);
d62a17ae 7706 }
ea47320b
DL
7707 }
7708 } else {
7709 vty_out(vty,
7710 "Read-only mode update-delay limit: %d seconds\n",
7711 bgp->v_update_delay);
7712 if (bgp->v_update_delay
7713 != bgp->v_establish_wait)
d62a17ae 7714 vty_out(vty,
ea47320b
DL
7715 " Establish wait: %d seconds\n",
7716 bgp->v_establish_wait);
d62a17ae 7717
60466a63 7718 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7719 vty_out(vty,
7720 " First neighbor established: %s\n",
7721 bgp->update_delay_begin_time);
7722 vty_out(vty,
7723 " Delay in progress\n");
7724 } else {
7725 if (bgp->update_delay_over) {
d62a17ae 7726 vty_out(vty,
7727 " First neighbor established: %s\n",
7728 bgp->update_delay_begin_time);
7729 vty_out(vty,
ea47320b
DL
7730 " Best-paths resumed: %s\n",
7731 bgp->update_delay_end_time);
7732 vty_out(vty,
7733 " zebra update resumed: %s\n",
7734 bgp->update_delay_zebra_resume_time);
7735 vty_out(vty,
7736 " peers update resumed: %s\n",
7737 bgp->update_delay_peers_resume_time);
d62a17ae 7738 }
7739 }
7740 }
ea47320b 7741 }
d62a17ae 7742
ea47320b
DL
7743 if (use_json) {
7744 if (bgp_maxmed_onstartup_configured(bgp)
7745 && bgp->maxmed_active)
7746 json_object_boolean_true_add(
60466a63 7747 json, "maxMedOnStartup");
ea47320b
DL
7748 if (bgp->v_maxmed_admin)
7749 json_object_boolean_true_add(
60466a63 7750 json, "maxMedAdministrative");
d62a17ae 7751
ea47320b
DL
7752 json_object_int_add(
7753 json, "tableVersion",
60466a63 7754 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7755
60466a63
QY
7756 ents = bgp_table_count(bgp->rib[afi][safi]);
7757 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7758 json_object_int_add(
7759 json, "ribMemory",
7760 ents * sizeof(struct bgp_node));
d62a17ae 7761
ea47320b 7762 ents = listcount(bgp->peer);
60466a63
QY
7763 json_object_int_add(json, "peerCount", ents);
7764 json_object_int_add(json, "peerMemory",
7765 ents * sizeof(struct peer));
d62a17ae 7766
ea47320b
DL
7767 if ((ents = listcount(bgp->group))) {
7768 json_object_int_add(
60466a63 7769 json, "peerGroupCount", ents);
ea47320b
DL
7770 json_object_int_add(
7771 json, "peerGroupMemory",
996c9314
LB
7772 ents * sizeof(struct
7773 peer_group));
ea47320b 7774 }
d62a17ae 7775
ea47320b
DL
7776 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7777 BGP_CONFIG_DAMPENING))
7778 json_object_boolean_true_add(
60466a63 7779 json, "dampeningEnabled");
ea47320b
DL
7780 } else {
7781 if (bgp_maxmed_onstartup_configured(bgp)
7782 && bgp->maxmed_active)
d62a17ae 7783 vty_out(vty,
ea47320b
DL
7784 "Max-med on-startup active\n");
7785 if (bgp->v_maxmed_admin)
d62a17ae 7786 vty_out(vty,
ea47320b 7787 "Max-med administrative active\n");
d62a17ae 7788
60466a63
QY
7789 vty_out(vty, "BGP table version %" PRIu64 "\n",
7790 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 7791
60466a63 7792 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
7793 vty_out(vty,
7794 "RIB entries %ld, using %s of memory\n",
7795 ents,
996c9314
LB
7796 mtype_memstr(memstrbuf,
7797 sizeof(memstrbuf),
7798 ents * sizeof(struct
7799 bgp_node)));
ea47320b
DL
7800
7801 /* Peer related usage */
7802 ents = listcount(bgp->peer);
60466a63 7803 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7804 ents,
7805 mtype_memstr(
60466a63
QY
7806 memstrbuf, sizeof(memstrbuf),
7807 ents * sizeof(struct peer)));
ea47320b
DL
7808
7809 if ((ents = listcount(bgp->group)))
d62a17ae 7810 vty_out(vty,
ea47320b 7811 "Peer groups %ld, using %s of memory\n",
d62a17ae 7812 ents,
7813 mtype_memstr(
7814 memstrbuf,
7815 sizeof(memstrbuf),
996c9314
LB
7816 ents * sizeof(struct
7817 peer_group)));
d62a17ae 7818
ea47320b
DL
7819 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7820 BGP_CONFIG_DAMPENING))
60466a63 7821 vty_out(vty, "Dampening enabled.\n");
ea47320b 7822 vty_out(vty, "\n");
d62a17ae 7823
ea47320b
DL
7824 /* Subtract 8 here because 'Neighbor' is
7825 * 8 characters */
7826 vty_out(vty, "Neighbor");
60466a63
QY
7827 vty_out(vty, "%*s", max_neighbor_width - 8,
7828 " ");
ea47320b
DL
7829 vty_out(vty,
7830 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7831 }
ea47320b 7832 }
d62a17ae 7833
ea47320b 7834 count++;
d62a17ae 7835
ea47320b
DL
7836 if (use_json) {
7837 json_peer = json_object_new_object();
d62a17ae 7838
ea47320b 7839 if (peer_dynamic_neighbor(peer))
60466a63
QY
7840 json_object_boolean_true_add(json_peer,
7841 "dynamicPeer");
d62a17ae 7842
ea47320b 7843 if (peer->hostname)
60466a63 7844 json_object_string_add(json_peer, "hostname",
ea47320b 7845 peer->hostname);
d62a17ae 7846
ea47320b 7847 if (peer->domainname)
60466a63
QY
7848 json_object_string_add(json_peer, "domainname",
7849 peer->domainname);
d62a17ae 7850
60466a63 7851 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7852 json_object_int_add(json_peer, "version", 4);
60466a63 7853 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 7854 PEER_TOTAL_RX(peer));
60466a63 7855 json_object_int_add(json_peer, "msgSent",
0112e9e0 7856 PEER_TOTAL_TX(peer));
ea47320b
DL
7857
7858 json_object_int_add(json_peer, "tableVersion",
7859 peer->version[afi][safi]);
7860 json_object_int_add(json_peer, "outq",
7861 peer->obuf->count);
7862 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7863 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7864 use_json, json_peer);
7865 json_object_int_add(json_peer, "prefixReceivedCount",
7866 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 7867
ea47320b 7868 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7869 json_object_string_add(json_peer, "state",
ea47320b 7870 "Idle (Admin)");
60466a63
QY
7871 else if (CHECK_FLAG(peer->sflags,
7872 PEER_STATUS_PREFIX_OVERFLOW))
7873 json_object_string_add(json_peer, "state",
ea47320b
DL
7874 "Idle (PfxCt)");
7875 else
7876 json_object_string_add(
7877 json_peer, "state",
60466a63
QY
7878 lookup_msg(bgp_status_msg, peer->status,
7879 NULL));
ea47320b
DL
7880
7881 if (peer->conf_if)
60466a63 7882 json_object_string_add(json_peer, "idType",
ea47320b
DL
7883 "interface");
7884 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
7885 json_object_string_add(json_peer, "idType",
7886 "ipv4");
ea47320b 7887 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
7888 json_object_string_add(json_peer, "idType",
7889 "ipv6");
d62a17ae 7890
ea47320b
DL
7891 json_object_object_add(json_peers, peer->host,
7892 json_peer);
7893 } else {
7894 memset(dn_flag, '\0', sizeof(dn_flag));
7895 if (peer_dynamic_neighbor(peer)) {
7896 dn_count++;
7897 dn_flag[0] = '*';
7898 }
d62a17ae 7899
ea47320b 7900 if (peer->hostname
60466a63 7901 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 7902 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 7903 peer->hostname, peer->host);
ea47320b 7904 else
60466a63 7905 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
7906
7907 /* pad the neighbor column with spaces */
7908 if (len < max_neighbor_width)
60466a63
QY
7909 vty_out(vty, "%*s", max_neighbor_width - len,
7910 " ");
ea47320b 7911
86a55b99 7912 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
7913 peer->as, PEER_TOTAL_RX(peer),
7914 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7915 0, peer->obuf->count,
d62a17ae 7916 peer_uptime(peer->uptime, timebuf,
ea47320b 7917 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 7918
ea47320b 7919 if (peer->status == Established)
95077abf
DW
7920 if (peer->afc_recv[afi][pfx_rcd_safi])
7921 vty_out(vty, " %12ld",
a4d82a8a
PZ
7922 peer->pcount[afi]
7923 [pfx_rcd_safi]);
95077abf
DW
7924 else
7925 vty_out(vty, " NoNeg");
ea47320b 7926 else {
60466a63 7927 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 7928 vty_out(vty, " Idle (Admin)");
60466a63
QY
7929 else if (CHECK_FLAG(
7930 peer->sflags,
7931 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 7932 vty_out(vty, " Idle (PfxCt)");
d62a17ae 7933 else
ea47320b 7934 vty_out(vty, " %12s",
60466a63
QY
7935 lookup_msg(bgp_status_msg,
7936 peer->status, NULL));
d62a17ae 7937 }
ea47320b 7938 vty_out(vty, "\n");
d62a17ae 7939 }
7940 }
f933309e 7941
d62a17ae 7942 if (use_json) {
7943 json_object_object_add(json, "peers", json_peers);
7944
7945 json_object_int_add(json, "totalPeers", count);
7946 json_object_int_add(json, "dynamicPeers", dn_count);
7947
57a9c8a8
DS
7948 bgp_show_bestpath_json(bgp, json);
7949
996c9314
LB
7950 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7951 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7952 json_object_free(json);
7953 } else {
7954 if (count)
7955 vty_out(vty, "\nTotal number of neighbors %d\n", count);
7956 else {
7957 if (use_json)
7958 vty_out(vty,
7959 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
7960 afi_safi_print(afi, safi));
7961 else
7962 vty_out(vty, "No %s neighbor is configured\n",
7963 afi_safi_print(afi, safi));
7964 }
b05a1c8b 7965
d62a17ae 7966 if (dn_count && !use_json) {
7967 vty_out(vty, "* - dynamic neighbor\n");
7968 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
7969 dn_count, bgp->dynamic_neighbors_limit);
7970 }
7971 }
1ff9a340 7972
d62a17ae 7973 return CMD_SUCCESS;
718e3744 7974}
7975
d62a17ae 7976static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
d7c0a89a 7977 int safi, uint8_t use_json,
d62a17ae 7978 json_object *json)
7979{
7980 int is_first = 1;
7981 int afi_wildcard = (afi == AFI_MAX);
7982 int safi_wildcard = (safi == SAFI_MAX);
7983 int is_wildcard = (afi_wildcard || safi_wildcard);
7984 bool json_output = false;
7985
7986 if (use_json && is_wildcard)
7987 vty_out(vty, "{\n");
7988 if (afi_wildcard)
7989 afi = 1; /* AFI_IP */
7990 while (afi < AFI_MAX) {
7991 if (safi_wildcard)
7992 safi = 1; /* SAFI_UNICAST */
7993 while (safi < SAFI_MAX) {
318cac96 7994 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
d62a17ae 7995 json_output = true;
7996 if (is_wildcard) {
7997 /*
7998 * So limit output to those afi/safi
7999 * pairs that
8000 * actualy have something interesting in
8001 * them
8002 */
8003 if (use_json) {
8004 json = json_object_new_object();
8005
8006 if (!is_first)
8007 vty_out(vty, ",\n");
8008 else
8009 is_first = 0;
8010
8011 vty_out(vty, "\"%s\":",
8012 afi_safi_json(afi,
8013 safi));
8014 } else {
8015 vty_out(vty, "\n%s Summary:\n",
8016 afi_safi_print(afi,
8017 safi));
8018 }
8019 }
8020 bgp_show_summary(vty, bgp, afi, safi, use_json,
8021 json);
8022 }
8023 safi++;
d62a17ae 8024 if (!safi_wildcard)
8025 safi = SAFI_MAX;
8026 }
8027 afi++;
ee851c8c 8028 if (!afi_wildcard)
d62a17ae 8029 afi = AFI_MAX;
8030 }
8031
8032 if (use_json && is_wildcard)
8033 vty_out(vty, "}\n");
8034 else if (use_json && !json_output)
8035 vty_out(vty, "{}\n");
8036}
8037
8038static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
d7c0a89a 8039 safi_t safi, uint8_t use_json)
d62a17ae 8040{
8041 struct listnode *node, *nnode;
8042 struct bgp *bgp;
8043 json_object *json = NULL;
8044 int is_first = 1;
8045
8046 if (use_json)
8047 vty_out(vty, "{\n");
8048
8049 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8050 if (use_json) {
8051 json = json_object_new_object();
8052
8053 if (!is_first)
8054 vty_out(vty, ",\n");
8055 else
8056 is_first = 0;
8057
8058 vty_out(vty, "\"%s\":",
8059 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8060 ? "Default"
8061 : bgp->name);
8062 } else {
8063 vty_out(vty, "\nInstance %s:\n",
8064 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8065 ? "Default"
8066 : bgp->name);
8067 }
8068 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8069 }
8070
8071 if (use_json)
8072 vty_out(vty, "}\n");
8073}
8074
8075int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
d7c0a89a 8076 safi_t safi, uint8_t use_json)
d62a17ae 8077{
8078 struct bgp *bgp;
8079
8080 if (name) {
8081 if (strmatch(name, "all")) {
8082 bgp_show_all_instances_summary_vty(vty, afi, safi,
8083 use_json);
8084 return CMD_SUCCESS;
8085 } else {
8086 bgp = bgp_lookup_by_name(name);
8087
8088 if (!bgp) {
8089 if (use_json)
8090 vty_out(vty, "{}\n");
8091 else
8092 vty_out(vty,
8093 "%% No such BGP instance exist\n");
8094 return CMD_WARNING;
8095 }
8096
8097 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8098 NULL);
8099 return CMD_SUCCESS;
8100 }
8101 }
8102
8103 bgp = bgp_get_default();
8104
8105 if (bgp)
8106 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8107
8108 return CMD_SUCCESS;
4fb25c53
DW
8109}
8110
716b2d8a 8111/* `show [ip] bgp summary' commands. */
47fc97cc 8112DEFUN (show_ip_bgp_summary,
718e3744 8113 show_ip_bgp_summary_cmd,
dd6bd0f1 8114 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8115 SHOW_STR
8116 IP_STR
8117 BGP_STR
8386ac43 8118 BGP_INSTANCE_HELP_STR
46f296b4 8119 BGP_AFI_HELP_STR
dd6bd0f1 8120 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8121 "Summary of BGP neighbor status\n"
9973d184 8122 JSON_STR)
718e3744 8123{
d62a17ae 8124 char *vrf = NULL;
8125 afi_t afi = AFI_MAX;
8126 safi_t safi = SAFI_MAX;
8127
8128 int idx = 0;
8129
8130 /* show [ip] bgp */
8131 if (argv_find(argv, argc, "ip", &idx))
8132 afi = AFI_IP;
8133 /* [<view|vrf> VIEWVRFNAME] */
8134 if (argv_find(argv, argc, "view", &idx)
8135 || argv_find(argv, argc, "vrf", &idx))
8136 vrf = argv[++idx]->arg;
8137 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8138 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8139 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8140 }
8141
8142 int uj = use_json(argc, argv);
8143
8144 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8145}
8146
8147const char *afi_safi_print(afi_t afi, safi_t safi)
8148{
8149 if (afi == AFI_IP && safi == SAFI_UNICAST)
8150 return "IPv4 Unicast";
8151 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8152 return "IPv4 Multicast";
8153 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8154 return "IPv4 Labeled Unicast";
8155 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8156 return "IPv4 VPN";
8157 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8158 return "IPv4 Encap";
7c40bf39 8159 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8160 return "IPv4 Flowspec";
d62a17ae 8161 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8162 return "IPv6 Unicast";
8163 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8164 return "IPv6 Multicast";
8165 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8166 return "IPv6 Labeled Unicast";
8167 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8168 return "IPv6 VPN";
8169 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8170 return "IPv6 Encap";
7c40bf39 8171 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8172 return "IPv6 Flowspec";
d62a17ae 8173 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8174 return "L2VPN EVPN";
8175 else
8176 return "Unknown";
538621f2 8177}
8178
b9f77ec8
DS
8179/*
8180 * Please note that we have intentionally camelCased
8181 * the return strings here. So if you want
8182 * to use this function, please ensure you
8183 * are doing this within json output
8184 */
d62a17ae 8185const char *afi_safi_json(afi_t afi, safi_t safi)
8186{
8187 if (afi == AFI_IP && safi == SAFI_UNICAST)
8188 return "ipv4Unicast";
8189 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8190 return "ipv4Multicast";
8191 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8192 return "ipv4LabeledUnicast";
8193 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8194 return "ipv4Vpn";
8195 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8196 return "ipv4Encap";
7c40bf39 8197 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8198 return "ipv4Flowspec";
d62a17ae 8199 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8200 return "ipv6Unicast";
8201 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8202 return "ipv6Multicast";
8203 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8204 return "ipv6LabeledUnicast";
8205 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8206 return "ipv6Vpn";
8207 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8208 return "ipv6Encap";
7c40bf39 8209 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8210 return "ipv6Flowspec";
d62a17ae 8211 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8212 return "l2VpnEvpn";
8213 else
8214 return "Unknown";
27162734
LB
8215}
8216
718e3744 8217/* Show BGP peer's information. */
d62a17ae 8218enum show_type { show_all, show_peer };
8219
8220static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8221 afi_t afi, safi_t safi,
d7c0a89a
QY
8222 uint16_t adv_smcap, uint16_t adv_rmcap,
8223 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8224 uint8_t use_json, json_object *json_pref)
d62a17ae 8225{
8226 /* Send-Mode */
8227 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8228 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8229 if (use_json) {
8230 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8231 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8232 json_object_string_add(json_pref, "sendMode",
8233 "advertisedAndReceived");
8234 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8235 json_object_string_add(json_pref, "sendMode",
8236 "advertised");
8237 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8238 json_object_string_add(json_pref, "sendMode",
8239 "received");
8240 } else {
8241 vty_out(vty, " Send-mode: ");
8242 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8243 vty_out(vty, "advertised");
8244 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8245 vty_out(vty, "%sreceived",
8246 CHECK_FLAG(p->af_cap[afi][safi],
8247 adv_smcap)
8248 ? ", "
8249 : "");
8250 vty_out(vty, "\n");
8251 }
8252 }
8253
8254 /* Receive-Mode */
8255 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8256 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8257 if (use_json) {
8258 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8259 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8260 json_object_string_add(json_pref, "recvMode",
8261 "advertisedAndReceived");
8262 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8263 json_object_string_add(json_pref, "recvMode",
8264 "advertised");
8265 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8266 json_object_string_add(json_pref, "recvMode",
8267 "received");
8268 } else {
8269 vty_out(vty, " Receive-mode: ");
8270 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8271 vty_out(vty, "advertised");
8272 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8273 vty_out(vty, "%sreceived",
8274 CHECK_FLAG(p->af_cap[afi][safi],
8275 adv_rmcap)
8276 ? ", "
8277 : "");
8278 vty_out(vty, "\n");
8279 }
8280 }
8281}
8282
8283static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
d7c0a89a 8284 safi_t safi, uint8_t use_json,
d62a17ae 8285 json_object *json_neigh)
8286{
0291c246
MK
8287 struct bgp_filter *filter;
8288 struct peer_af *paf;
8289 char orf_pfx_name[BUFSIZ];
8290 int orf_pfx_count;
8291 json_object *json_af = NULL;
8292 json_object *json_prefA = NULL;
8293 json_object *json_prefB = NULL;
8294 json_object *json_addr = NULL;
d62a17ae 8295
8296 if (use_json) {
8297 json_addr = json_object_new_object();
8298 json_af = json_object_new_object();
8299 filter = &p->filter[afi][safi];
8300
8301 if (peer_group_active(p))
8302 json_object_string_add(json_addr, "peerGroupMember",
8303 p->group->name);
8304
8305 paf = peer_af_find(p, afi, safi);
8306 if (paf && PAF_SUBGRP(paf)) {
8307 json_object_int_add(json_addr, "updateGroupId",
8308 PAF_UPDGRP(paf)->id);
8309 json_object_int_add(json_addr, "subGroupId",
8310 PAF_SUBGRP(paf)->id);
8311 json_object_int_add(json_addr, "packetQueueLength",
8312 bpacket_queue_virtual_length(paf));
8313 }
8314
8315 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8316 || CHECK_FLAG(p->af_cap[afi][safi],
8317 PEER_CAP_ORF_PREFIX_SM_RCV)
8318 || CHECK_FLAG(p->af_cap[afi][safi],
8319 PEER_CAP_ORF_PREFIX_RM_ADV)
8320 || CHECK_FLAG(p->af_cap[afi][safi],
8321 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8322 json_object_int_add(json_af, "orfType",
8323 ORF_TYPE_PREFIX);
8324 json_prefA = json_object_new_object();
8325 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8326 PEER_CAP_ORF_PREFIX_SM_ADV,
8327 PEER_CAP_ORF_PREFIX_RM_ADV,
8328 PEER_CAP_ORF_PREFIX_SM_RCV,
8329 PEER_CAP_ORF_PREFIX_RM_RCV,
8330 use_json, json_prefA);
8331 json_object_object_add(json_af, "orfPrefixList",
8332 json_prefA);
8333 }
8334
8335 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8336 || CHECK_FLAG(p->af_cap[afi][safi],
8337 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8338 || CHECK_FLAG(p->af_cap[afi][safi],
8339 PEER_CAP_ORF_PREFIX_RM_ADV)
8340 || CHECK_FLAG(p->af_cap[afi][safi],
8341 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8342 json_object_int_add(json_af, "orfOldType",
8343 ORF_TYPE_PREFIX_OLD);
8344 json_prefB = json_object_new_object();
8345 bgp_show_peer_afi_orf_cap(
8346 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8347 PEER_CAP_ORF_PREFIX_RM_ADV,
8348 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8349 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8350 json_prefB);
8351 json_object_object_add(json_af, "orfOldPrefixList",
8352 json_prefB);
8353 }
8354
8355 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8356 || CHECK_FLAG(p->af_cap[afi][safi],
8357 PEER_CAP_ORF_PREFIX_SM_RCV)
8358 || CHECK_FLAG(p->af_cap[afi][safi],
8359 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8360 || CHECK_FLAG(p->af_cap[afi][safi],
8361 PEER_CAP_ORF_PREFIX_RM_ADV)
8362 || CHECK_FLAG(p->af_cap[afi][safi],
8363 PEER_CAP_ORF_PREFIX_RM_RCV)
8364 || CHECK_FLAG(p->af_cap[afi][safi],
8365 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8366 json_object_object_add(json_addr, "afDependentCap",
8367 json_af);
8368 else
8369 json_object_free(json_af);
8370
8371 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8372 orf_pfx_count = prefix_bgp_show_prefix_list(
8373 NULL, afi, orf_pfx_name, use_json);
8374
8375 if (CHECK_FLAG(p->af_sflags[afi][safi],
8376 PEER_STATUS_ORF_PREFIX_SEND)
8377 || orf_pfx_count) {
8378 if (CHECK_FLAG(p->af_sflags[afi][safi],
8379 PEER_STATUS_ORF_PREFIX_SEND))
8380 json_object_boolean_true_add(json_neigh,
8381 "orfSent");
8382 if (orf_pfx_count)
8383 json_object_int_add(json_addr, "orfRecvCounter",
8384 orf_pfx_count);
8385 }
8386 if (CHECK_FLAG(p->af_sflags[afi][safi],
8387 PEER_STATUS_ORF_WAIT_REFRESH))
8388 json_object_string_add(
8389 json_addr, "orfFirstUpdate",
8390 "deferredUntilORFOrRouteRefreshRecvd");
8391
8392 if (CHECK_FLAG(p->af_flags[afi][safi],
8393 PEER_FLAG_REFLECTOR_CLIENT))
8394 json_object_boolean_true_add(json_addr,
8395 "routeReflectorClient");
8396 if (CHECK_FLAG(p->af_flags[afi][safi],
8397 PEER_FLAG_RSERVER_CLIENT))
8398 json_object_boolean_true_add(json_addr,
8399 "routeServerClient");
8400 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8401 json_object_boolean_true_add(json_addr,
8402 "inboundSoftConfigPermit");
8403
8404 if (CHECK_FLAG(p->af_flags[afi][safi],
8405 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8406 json_object_boolean_true_add(
8407 json_addr,
8408 "privateAsNumsAllReplacedInUpdatesToNbr");
8409 else if (CHECK_FLAG(p->af_flags[afi][safi],
8410 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8411 json_object_boolean_true_add(
8412 json_addr,
8413 "privateAsNumsReplacedInUpdatesToNbr");
8414 else if (CHECK_FLAG(p->af_flags[afi][safi],
8415 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8416 json_object_boolean_true_add(
8417 json_addr,
8418 "privateAsNumsAllRemovedInUpdatesToNbr");
8419 else if (CHECK_FLAG(p->af_flags[afi][safi],
8420 PEER_FLAG_REMOVE_PRIVATE_AS))
8421 json_object_boolean_true_add(
8422 json_addr,
8423 "privateAsNumsRemovedInUpdatesToNbr");
8424
8425 if (CHECK_FLAG(p->af_flags[afi][safi],
8426 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8427 json_object_boolean_true_add(json_addr,
8428 "addpathTxAllPaths");
8429
8430 if (CHECK_FLAG(p->af_flags[afi][safi],
8431 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8432 json_object_boolean_true_add(json_addr,
8433 "addpathTxBestpathPerAS");
8434
8435 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8436 json_object_string_add(json_addr,
8437 "overrideASNsInOutboundUpdates",
8438 "ifAspathEqualRemoteAs");
8439
8440 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8441 || CHECK_FLAG(p->af_flags[afi][safi],
8442 PEER_FLAG_FORCE_NEXTHOP_SELF))
8443 json_object_boolean_true_add(json_addr,
8444 "routerAlwaysNextHop");
8445 if (CHECK_FLAG(p->af_flags[afi][safi],
8446 PEER_FLAG_AS_PATH_UNCHANGED))
8447 json_object_boolean_true_add(
8448 json_addr, "unchangedAsPathPropogatedToNbr");
8449 if (CHECK_FLAG(p->af_flags[afi][safi],
8450 PEER_FLAG_NEXTHOP_UNCHANGED))
8451 json_object_boolean_true_add(
8452 json_addr, "unchangedNextHopPropogatedToNbr");
8453 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8454 json_object_boolean_true_add(
8455 json_addr, "unchangedMedPropogatedToNbr");
8456 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8457 || CHECK_FLAG(p->af_flags[afi][safi],
8458 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8459 if (CHECK_FLAG(p->af_flags[afi][safi],
8460 PEER_FLAG_SEND_COMMUNITY)
8461 && CHECK_FLAG(p->af_flags[afi][safi],
8462 PEER_FLAG_SEND_EXT_COMMUNITY))
8463 json_object_string_add(json_addr,
8464 "commAttriSentToNbr",
8465 "extendedAndStandard");
8466 else if (CHECK_FLAG(p->af_flags[afi][safi],
8467 PEER_FLAG_SEND_EXT_COMMUNITY))
8468 json_object_string_add(json_addr,
8469 "commAttriSentToNbr",
8470 "extended");
8471 else
8472 json_object_string_add(json_addr,
8473 "commAttriSentToNbr",
8474 "standard");
8475 }
8476 if (CHECK_FLAG(p->af_flags[afi][safi],
8477 PEER_FLAG_DEFAULT_ORIGINATE)) {
8478 if (p->default_rmap[afi][safi].name)
8479 json_object_string_add(
8480 json_addr, "defaultRouteMap",
8481 p->default_rmap[afi][safi].name);
8482
8483 if (paf && PAF_SUBGRP(paf)
8484 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8485 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8486 json_object_boolean_true_add(json_addr,
8487 "defaultSent");
8488 else
8489 json_object_boolean_true_add(json_addr,
8490 "defaultNotSent");
8491 }
8492
dff8f48d 8493 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8494 if (is_evpn_enabled())
60466a63
QY
8495 json_object_boolean_true_add(
8496 json_addr, "advertiseAllVnis");
dff8f48d
MK
8497 }
8498
d62a17ae 8499 if (filter->plist[FILTER_IN].name
8500 || filter->dlist[FILTER_IN].name
8501 || filter->aslist[FILTER_IN].name
8502 || filter->map[RMAP_IN].name)
8503 json_object_boolean_true_add(json_addr,
8504 "inboundPathPolicyConfig");
8505 if (filter->plist[FILTER_OUT].name
8506 || filter->dlist[FILTER_OUT].name
8507 || filter->aslist[FILTER_OUT].name
8508 || filter->map[RMAP_OUT].name || filter->usmap.name)
8509 json_object_boolean_true_add(
8510 json_addr, "outboundPathPolicyConfig");
8511
8512 /* prefix-list */
8513 if (filter->plist[FILTER_IN].name)
8514 json_object_string_add(json_addr,
8515 "incomingUpdatePrefixFilterList",
8516 filter->plist[FILTER_IN].name);
8517 if (filter->plist[FILTER_OUT].name)
8518 json_object_string_add(json_addr,
8519 "outgoingUpdatePrefixFilterList",
8520 filter->plist[FILTER_OUT].name);
8521
8522 /* distribute-list */
8523 if (filter->dlist[FILTER_IN].name)
8524 json_object_string_add(
8525 json_addr, "incomingUpdateNetworkFilterList",
8526 filter->dlist[FILTER_IN].name);
8527 if (filter->dlist[FILTER_OUT].name)
8528 json_object_string_add(
8529 json_addr, "outgoingUpdateNetworkFilterList",
8530 filter->dlist[FILTER_OUT].name);
8531
8532 /* filter-list. */
8533 if (filter->aslist[FILTER_IN].name)
8534 json_object_string_add(json_addr,
8535 "incomingUpdateAsPathFilterList",
8536 filter->aslist[FILTER_IN].name);
8537 if (filter->aslist[FILTER_OUT].name)
8538 json_object_string_add(json_addr,
8539 "outgoingUpdateAsPathFilterList",
8540 filter->aslist[FILTER_OUT].name);
8541
8542 /* route-map. */
8543 if (filter->map[RMAP_IN].name)
8544 json_object_string_add(
8545 json_addr, "routeMapForIncomingAdvertisements",
8546 filter->map[RMAP_IN].name);
8547 if (filter->map[RMAP_OUT].name)
8548 json_object_string_add(
8549 json_addr, "routeMapForOutgoingAdvertisements",
8550 filter->map[RMAP_OUT].name);
8551
8552 /* unsuppress-map */
8553 if (filter->usmap.name)
8554 json_object_string_add(json_addr,
8555 "selectiveUnsuppressRouteMap",
8556 filter->usmap.name);
8557
8558 /* Receive prefix count */
8559 json_object_int_add(json_addr, "acceptedPrefixCounter",
8560 p->pcount[afi][safi]);
8561
8562 /* Maximum prefix */
8563 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8564 json_object_int_add(json_addr, "prefixAllowedMax",
8565 p->pmax[afi][safi]);
8566 if (CHECK_FLAG(p->af_flags[afi][safi],
8567 PEER_FLAG_MAX_PREFIX_WARNING))
8568 json_object_boolean_true_add(
8569 json_addr, "prefixAllowedMaxWarning");
8570 json_object_int_add(json_addr,
8571 "prefixAllowedWarningThresh",
8572 p->pmax_threshold[afi][safi]);
8573 if (p->pmax_restart[afi][safi])
8574 json_object_int_add(
8575 json_addr,
8576 "prefixAllowedRestartIntervalMsecs",
8577 p->pmax_restart[afi][safi] * 60000);
8578 }
8579 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8580 json_addr);
8581
8582 } else {
8583 filter = &p->filter[afi][safi];
8584
8585 vty_out(vty, " For address family: %s\n",
8586 afi_safi_print(afi, safi));
8587
8588 if (peer_group_active(p))
8589 vty_out(vty, " %s peer-group member\n",
8590 p->group->name);
8591
8592 paf = peer_af_find(p, afi, safi);
8593 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8594 vty_out(vty, " Update group %" PRIu64
8595 ", subgroup %" PRIu64 "\n",
d62a17ae 8596 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8597 vty_out(vty, " Packet Queue length %d\n",
8598 bpacket_queue_virtual_length(paf));
8599 } else {
8600 vty_out(vty, " Not part of any update group\n");
8601 }
8602 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8603 || CHECK_FLAG(p->af_cap[afi][safi],
8604 PEER_CAP_ORF_PREFIX_SM_RCV)
8605 || CHECK_FLAG(p->af_cap[afi][safi],
8606 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8607 || CHECK_FLAG(p->af_cap[afi][safi],
8608 PEER_CAP_ORF_PREFIX_RM_ADV)
8609 || CHECK_FLAG(p->af_cap[afi][safi],
8610 PEER_CAP_ORF_PREFIX_RM_RCV)
8611 || CHECK_FLAG(p->af_cap[afi][safi],
8612 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8613 vty_out(vty, " AF-dependant capabilities:\n");
8614
8615 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8616 || CHECK_FLAG(p->af_cap[afi][safi],
8617 PEER_CAP_ORF_PREFIX_SM_RCV)
8618 || CHECK_FLAG(p->af_cap[afi][safi],
8619 PEER_CAP_ORF_PREFIX_RM_ADV)
8620 || CHECK_FLAG(p->af_cap[afi][safi],
8621 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8622 vty_out(vty,
8623 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8624 ORF_TYPE_PREFIX);
8625 bgp_show_peer_afi_orf_cap(
8626 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8627 PEER_CAP_ORF_PREFIX_RM_ADV,
8628 PEER_CAP_ORF_PREFIX_SM_RCV,
8629 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8630 }
8631 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8632 || CHECK_FLAG(p->af_cap[afi][safi],
8633 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8634 || CHECK_FLAG(p->af_cap[afi][safi],
8635 PEER_CAP_ORF_PREFIX_RM_ADV)
8636 || CHECK_FLAG(p->af_cap[afi][safi],
8637 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8638 vty_out(vty,
8639 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8640 ORF_TYPE_PREFIX_OLD);
8641 bgp_show_peer_afi_orf_cap(
8642 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8643 PEER_CAP_ORF_PREFIX_RM_ADV,
8644 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8645 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8646 }
8647
8648 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8649 orf_pfx_count = prefix_bgp_show_prefix_list(
8650 NULL, afi, orf_pfx_name, use_json);
8651
8652 if (CHECK_FLAG(p->af_sflags[afi][safi],
8653 PEER_STATUS_ORF_PREFIX_SEND)
8654 || orf_pfx_count) {
8655 vty_out(vty, " Outbound Route Filter (ORF):");
8656 if (CHECK_FLAG(p->af_sflags[afi][safi],
8657 PEER_STATUS_ORF_PREFIX_SEND))
8658 vty_out(vty, " sent;");
8659 if (orf_pfx_count)
8660 vty_out(vty, " received (%d entries)",
8661 orf_pfx_count);
8662 vty_out(vty, "\n");
8663 }
8664 if (CHECK_FLAG(p->af_sflags[afi][safi],
8665 PEER_STATUS_ORF_WAIT_REFRESH))
8666 vty_out(vty,
8667 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8668
8669 if (CHECK_FLAG(p->af_flags[afi][safi],
8670 PEER_FLAG_REFLECTOR_CLIENT))
8671 vty_out(vty, " Route-Reflector Client\n");
8672 if (CHECK_FLAG(p->af_flags[afi][safi],
8673 PEER_FLAG_RSERVER_CLIENT))
8674 vty_out(vty, " Route-Server Client\n");
8675 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8676 vty_out(vty,
8677 " Inbound soft reconfiguration allowed\n");
8678
8679 if (CHECK_FLAG(p->af_flags[afi][safi],
8680 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8681 vty_out(vty,
8682 " Private AS numbers (all) replaced in updates to this neighbor\n");
8683 else if (CHECK_FLAG(p->af_flags[afi][safi],
8684 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8685 vty_out(vty,
8686 " Private AS numbers replaced in updates to this neighbor\n");
8687 else if (CHECK_FLAG(p->af_flags[afi][safi],
8688 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8689 vty_out(vty,
8690 " Private AS numbers (all) removed in updates to this neighbor\n");
8691 else if (CHECK_FLAG(p->af_flags[afi][safi],
8692 PEER_FLAG_REMOVE_PRIVATE_AS))
8693 vty_out(vty,
8694 " Private AS numbers removed in updates to this neighbor\n");
8695
8696 if (CHECK_FLAG(p->af_flags[afi][safi],
8697 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8698 vty_out(vty, " Advertise all paths via addpath\n");
8699
8700 if (CHECK_FLAG(p->af_flags[afi][safi],
8701 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8702 vty_out(vty,
8703 " Advertise bestpath per AS via addpath\n");
8704
8705 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8706 vty_out(vty,
8707 " Override ASNs in outbound updates if aspath equals remote-as\n");
8708
8709 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8710 || CHECK_FLAG(p->af_flags[afi][safi],
8711 PEER_FLAG_FORCE_NEXTHOP_SELF))
8712 vty_out(vty, " NEXT_HOP is always this router\n");
8713 if (CHECK_FLAG(p->af_flags[afi][safi],
8714 PEER_FLAG_AS_PATH_UNCHANGED))
8715 vty_out(vty,
8716 " AS_PATH is propagated unchanged to this neighbor\n");
8717 if (CHECK_FLAG(p->af_flags[afi][safi],
8718 PEER_FLAG_NEXTHOP_UNCHANGED))
8719 vty_out(vty,
8720 " NEXT_HOP is propagated unchanged to this neighbor\n");
8721 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8722 vty_out(vty,
8723 " MED is propagated unchanged to this neighbor\n");
8724 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8725 || CHECK_FLAG(p->af_flags[afi][safi],
8726 PEER_FLAG_SEND_EXT_COMMUNITY)
8727 || CHECK_FLAG(p->af_flags[afi][safi],
8728 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8729 vty_out(vty,
8730 " Community attribute sent to this neighbor");
8731 if (CHECK_FLAG(p->af_flags[afi][safi],
8732 PEER_FLAG_SEND_COMMUNITY)
8733 && CHECK_FLAG(p->af_flags[afi][safi],
8734 PEER_FLAG_SEND_EXT_COMMUNITY)
8735 && CHECK_FLAG(p->af_flags[afi][safi],
8736 PEER_FLAG_SEND_LARGE_COMMUNITY))
8737 vty_out(vty, "(all)\n");
8738 else if (CHECK_FLAG(p->af_flags[afi][safi],
8739 PEER_FLAG_SEND_LARGE_COMMUNITY))
8740 vty_out(vty, "(large)\n");
8741 else if (CHECK_FLAG(p->af_flags[afi][safi],
8742 PEER_FLAG_SEND_EXT_COMMUNITY))
8743 vty_out(vty, "(extended)\n");
8744 else
8745 vty_out(vty, "(standard)\n");
8746 }
8747 if (CHECK_FLAG(p->af_flags[afi][safi],
8748 PEER_FLAG_DEFAULT_ORIGINATE)) {
8749 vty_out(vty, " Default information originate,");
8750
8751 if (p->default_rmap[afi][safi].name)
8752 vty_out(vty, " default route-map %s%s,",
8753 p->default_rmap[afi][safi].map ? "*"
8754 : "",
8755 p->default_rmap[afi][safi].name);
8756 if (paf && PAF_SUBGRP(paf)
8757 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8758 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8759 vty_out(vty, " default sent\n");
8760 else
8761 vty_out(vty, " default not sent\n");
8762 }
8763
dff8f48d
MK
8764 /* advertise-vni-all */
8765 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8766 if (is_evpn_enabled())
dff8f48d
MK
8767 vty_out(vty, " advertise-all-vni\n");
8768 }
8769
d62a17ae 8770 if (filter->plist[FILTER_IN].name
8771 || filter->dlist[FILTER_IN].name
8772 || filter->aslist[FILTER_IN].name
8773 || filter->map[RMAP_IN].name)
8774 vty_out(vty, " Inbound path policy configured\n");
8775 if (filter->plist[FILTER_OUT].name
8776 || filter->dlist[FILTER_OUT].name
8777 || filter->aslist[FILTER_OUT].name
8778 || filter->map[RMAP_OUT].name || filter->usmap.name)
8779 vty_out(vty, " Outbound path policy configured\n");
8780
8781 /* prefix-list */
8782 if (filter->plist[FILTER_IN].name)
8783 vty_out(vty,
8784 " Incoming update prefix filter list is %s%s\n",
8785 filter->plist[FILTER_IN].plist ? "*" : "",
8786 filter->plist[FILTER_IN].name);
8787 if (filter->plist[FILTER_OUT].name)
8788 vty_out(vty,
8789 " Outgoing update prefix filter list is %s%s\n",
8790 filter->plist[FILTER_OUT].plist ? "*" : "",
8791 filter->plist[FILTER_OUT].name);
8792
8793 /* distribute-list */
8794 if (filter->dlist[FILTER_IN].name)
8795 vty_out(vty,
8796 " Incoming update network filter list is %s%s\n",
8797 filter->dlist[FILTER_IN].alist ? "*" : "",
8798 filter->dlist[FILTER_IN].name);
8799 if (filter->dlist[FILTER_OUT].name)
8800 vty_out(vty,
8801 " Outgoing update network filter list is %s%s\n",
8802 filter->dlist[FILTER_OUT].alist ? "*" : "",
8803 filter->dlist[FILTER_OUT].name);
8804
8805 /* filter-list. */
8806 if (filter->aslist[FILTER_IN].name)
8807 vty_out(vty,
8808 " Incoming update AS path filter list is %s%s\n",
8809 filter->aslist[FILTER_IN].aslist ? "*" : "",
8810 filter->aslist[FILTER_IN].name);
8811 if (filter->aslist[FILTER_OUT].name)
8812 vty_out(vty,
8813 " Outgoing update AS path filter list is %s%s\n",
8814 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8815 filter->aslist[FILTER_OUT].name);
8816
8817 /* route-map. */
8818 if (filter->map[RMAP_IN].name)
8819 vty_out(vty,
8820 " Route map for incoming advertisements is %s%s\n",
8821 filter->map[RMAP_IN].map ? "*" : "",
8822 filter->map[RMAP_IN].name);
8823 if (filter->map[RMAP_OUT].name)
8824 vty_out(vty,
8825 " Route map for outgoing advertisements is %s%s\n",
8826 filter->map[RMAP_OUT].map ? "*" : "",
8827 filter->map[RMAP_OUT].name);
8828
8829 /* unsuppress-map */
8830 if (filter->usmap.name)
8831 vty_out(vty,
8832 " Route map for selective unsuppress is %s%s\n",
8833 filter->usmap.map ? "*" : "",
8834 filter->usmap.name);
8835
8836 /* Receive prefix count */
8837 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8838
8839 /* Maximum prefix */
8840 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8841 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8842 p->pmax[afi][safi],
8843 CHECK_FLAG(p->af_flags[afi][safi],
8844 PEER_FLAG_MAX_PREFIX_WARNING)
8845 ? " (warning-only)"
8846 : "");
8847 vty_out(vty, " Threshold for warning message %d%%",
8848 p->pmax_threshold[afi][safi]);
8849 if (p->pmax_restart[afi][safi])
8850 vty_out(vty, ", restart interval %d min",
8851 p->pmax_restart[afi][safi]);
8852 vty_out(vty, "\n");
8853 }
8854
8855 vty_out(vty, "\n");
8856 }
8857}
8858
d7c0a89a 8859static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
d62a17ae 8860 json_object *json)
718e3744 8861{
d62a17ae 8862 struct bgp *bgp;
8863 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8864 char timebuf[BGP_UPTIME_LEN];
8865 char dn_flag[2];
8866 const char *subcode_str;
8867 const char *code_str;
8868 afi_t afi;
8869 safi_t safi;
d7c0a89a
QY
8870 uint16_t i;
8871 uint8_t *msg;
d62a17ae 8872 json_object *json_neigh = NULL;
8873 time_t epoch_tbuf;
718e3744 8874
d62a17ae 8875 bgp = p->bgp;
8876
8877 if (use_json)
8878 json_neigh = json_object_new_object();
8879
8880 memset(dn_flag, '\0', sizeof(dn_flag));
8881 if (!p->conf_if && peer_dynamic_neighbor(p))
8882 dn_flag[0] = '*';
8883
8884 if (!use_json) {
8885 if (p->conf_if) /* Configured interface name. */
8886 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8887 BGP_PEER_SU_UNSPEC(p)
8888 ? "None"
8889 : sockunion2str(&p->su, buf,
8890 SU_ADDRSTRLEN));
8891 else /* Configured IP address. */
8892 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8893 p->host);
8894 }
8895
8896 if (use_json) {
8897 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8898 json_object_string_add(json_neigh, "bgpNeighborAddr",
8899 "none");
8900 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8901 json_object_string_add(
8902 json_neigh, "bgpNeighborAddr",
8903 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8904
8905 json_object_int_add(json_neigh, "remoteAs", p->as);
8906
8907 if (p->change_local_as)
8908 json_object_int_add(json_neigh, "localAs",
8909 p->change_local_as);
8910 else
8911 json_object_int_add(json_neigh, "localAs", p->local_as);
8912
8913 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8914 json_object_boolean_true_add(json_neigh,
8915 "localAsNoPrepend");
8916
8917 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8918 json_object_boolean_true_add(json_neigh,
8919 "localAsReplaceAs");
8920 } else {
8921 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8922 || (p->as_type == AS_INTERNAL))
8923 vty_out(vty, "remote AS %u, ", p->as);
8924 else
8925 vty_out(vty, "remote AS Unspecified, ");
8926 vty_out(vty, "local AS %u%s%s, ",
8927 p->change_local_as ? p->change_local_as : p->local_as,
8928 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8929 ? " no-prepend"
8930 : "",
8931 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8932 ? " replace-as"
8933 : "");
8934 }
8935 /* peer type internal, external, confed-internal or confed-external */
8936 if (p->as == p->local_as) {
8937 if (use_json) {
8938 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8939 json_object_boolean_true_add(
8940 json_neigh, "nbrConfedInternalLink");
8941 else
8942 json_object_boolean_true_add(json_neigh,
8943 "nbrInternalLink");
8944 } else {
8945 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8946 vty_out(vty, "confed-internal link\n");
8947 else
8948 vty_out(vty, "internal link\n");
8949 }
8950 } else {
8951 if (use_json) {
8952 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8953 json_object_boolean_true_add(
8954 json_neigh, "nbrConfedExternalLink");
8955 else
8956 json_object_boolean_true_add(json_neigh,
8957 "nbrExternalLink");
8958 } else {
8959 if (bgp_confederation_peers_check(bgp, p->as))
8960 vty_out(vty, "confed-external link\n");
8961 else
8962 vty_out(vty, "external link\n");
8963 }
8964 }
8965
8966 /* Description. */
8967 if (p->desc) {
8968 if (use_json)
8969 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8970 else
8971 vty_out(vty, " Description: %s\n", p->desc);
8972 }
8973
8974 if (p->hostname) {
8975 if (use_json) {
8976 if (p->hostname)
8977 json_object_string_add(json_neigh, "hostname",
8978 p->hostname);
8979
8980 if (p->domainname)
8981 json_object_string_add(json_neigh, "domainname",
8982 p->domainname);
8983 } else {
8984 if (p->domainname && (p->domainname[0] != '\0'))
8985 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
8986 p->domainname);
8987 else
8988 vty_out(vty, "Hostname: %s\n", p->hostname);
8989 }
8990 }
8991
8992 /* Peer-group */
8993 if (p->group) {
8994 if (use_json) {
8995 json_object_string_add(json_neigh, "peerGroup",
8996 p->group->name);
8997
8998 if (dn_flag[0]) {
8999 struct prefix prefix, *range = NULL;
9000
9001 sockunion2hostprefix(&(p->su), &prefix);
9002 range = peer_group_lookup_dynamic_neighbor_range(
9003 p->group, &prefix);
9004
9005 if (range) {
9006 prefix2str(range, buf1, sizeof(buf1));
9007 json_object_string_add(
9008 json_neigh,
9009 "peerSubnetRangeGroup", buf1);
9010 }
9011 }
9012 } else {
9013 vty_out(vty,
9014 " Member of peer-group %s for session parameters\n",
9015 p->group->name);
9016
9017 if (dn_flag[0]) {
9018 struct prefix prefix, *range = NULL;
9019
9020 sockunion2hostprefix(&(p->su), &prefix);
9021 range = peer_group_lookup_dynamic_neighbor_range(
9022 p->group, &prefix);
9023
9024 if (range) {
9025 prefix2str(range, buf1, sizeof(buf1));
9026 vty_out(vty,
9027 " Belongs to the subnet range group: %s\n",
9028 buf1);
9029 }
9030 }
9031 }
9032 }
9033
9034 if (use_json) {
9035 /* Administrative shutdown. */
9036 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9037 json_object_boolean_true_add(json_neigh,
9038 "adminShutDown");
9039
9040 /* BGP Version. */
9041 json_object_int_add(json_neigh, "bgpVersion", 4);
9042 json_object_string_add(
9043 json_neigh, "remoteRouterId",
9044 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9045
9046 /* Confederation */
9047 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9048 && bgp_confederation_peers_check(bgp, p->as))
9049 json_object_boolean_true_add(json_neigh,
9050 "nbrCommonAdmin");
9051
9052 /* Status. */
9053 json_object_string_add(
9054 json_neigh, "bgpState",
9055 lookup_msg(bgp_status_msg, p->status, NULL));
9056
9057 if (p->status == Established) {
9058 time_t uptime;
d62a17ae 9059
9060 uptime = bgp_clock();
9061 uptime -= p->uptime;
d62a17ae 9062 epoch_tbuf = time(NULL) - uptime;
9063
e24be241 9064#if defined(VERSION_TYPE_DEV) && CONFDATE > 20200101
a4d82a8a
PZ
9065 CPP_NOTICE(
9066 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9067#endif
9068 /*
9069 * bgpTimerUp was miliseconds that was accurate
9070 * up to 1 day, then the value returned
9071 * became garbage. So in order to provide
9072 * some level of backwards compatability,
9073 * we still provde the data, but now
9074 * we are returning the correct value
9075 * and also adding a new bgpTimerUpMsec
9076 * which will allow us to deprecate
9077 * this eventually
9078 */
d62a17ae 9079 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9080 uptime * 1000);
d3c7efed
DS
9081 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9082 uptime * 1000);
d62a17ae 9083 json_object_string_add(json_neigh, "bgpTimerUpString",
9084 peer_uptime(p->uptime, timebuf,
9085 BGP_UPTIME_LEN, 0,
9086 NULL));
9087 json_object_int_add(json_neigh,
9088 "bgpTimerUpEstablishedEpoch",
9089 epoch_tbuf);
9090 }
9091
9092 else if (p->status == Active) {
9093 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9094 json_object_string_add(json_neigh, "bgpStateIs",
9095 "passive");
9096 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9097 json_object_string_add(json_neigh, "bgpStateIs",
9098 "passiveNSF");
9099 }
9100
9101 /* read timer */
9102 time_t uptime;
9103 struct tm *tm;
9104
9105 uptime = bgp_clock();
9106 uptime -= p->readtime;
9107 tm = gmtime(&uptime);
9108 json_object_int_add(json_neigh, "bgpTimerLastRead",
9109 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9110 + (tm->tm_hour * 3600000));
9111
9112 uptime = bgp_clock();
9113 uptime -= p->last_write;
9114 tm = gmtime(&uptime);
9115 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9116 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9117 + (tm->tm_hour * 3600000));
9118
9119 uptime = bgp_clock();
9120 uptime -= p->update_time;
9121 tm = gmtime(&uptime);
9122 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9123 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9124 + (tm->tm_hour * 3600000));
9125
9126 /* Configured timer values. */
9127 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9128 p->v_holdtime * 1000);
9129 json_object_int_add(json_neigh,
9130 "bgpTimerKeepAliveIntervalMsecs",
9131 p->v_keepalive * 1000);
9132
d25e4efc 9133 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 9134 json_object_int_add(json_neigh,
9135 "bgpTimerConfiguredHoldTimeMsecs",
9136 p->holdtime * 1000);
9137 json_object_int_add(
9138 json_neigh,
9139 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9140 p->keepalive * 1000);
d25e4efc 9141 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9142 || (bgp->default_keepalive
9143 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9144 json_object_int_add(json_neigh,
9145 "bgpTimerConfiguredHoldTimeMsecs",
9146 bgp->default_holdtime);
9147 json_object_int_add(
9148 json_neigh,
9149 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9150 bgp->default_keepalive);
d62a17ae 9151 }
9152 } else {
9153 /* Administrative shutdown. */
9154 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9155 vty_out(vty, " Administratively shut down\n");
9156
9157 /* BGP Version. */
9158 vty_out(vty, " BGP version 4");
9159 vty_out(vty, ", remote router ID %s\n",
9160 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9161
9162 /* Confederation */
9163 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9164 && bgp_confederation_peers_check(bgp, p->as))
9165 vty_out(vty,
9166 " Neighbor under common administration\n");
9167
9168 /* Status. */
9169 vty_out(vty, " BGP state = %s",
9170 lookup_msg(bgp_status_msg, p->status, NULL));
9171
9172 if (p->status == Established)
9173 vty_out(vty, ", up for %8s",
9174 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9175 0, NULL));
9176
9177 else if (p->status == Active) {
9178 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9179 vty_out(vty, " (passive)");
9180 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9181 vty_out(vty, " (NSF passive)");
9182 }
9183 vty_out(vty, "\n");
9184
9185 /* read timer */
9186 vty_out(vty, " Last read %s",
9187 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9188 NULL));
9189 vty_out(vty, ", Last write %s\n",
9190 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9191 NULL));
9192
9193 /* Configured timer values. */
9194 vty_out(vty,
9195 " Hold time is %d, keepalive interval is %d seconds\n",
9196 p->v_holdtime, p->v_keepalive);
d25e4efc 9197 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 9198 vty_out(vty, " Configured hold time is %d",
9199 p->holdtime);
9200 vty_out(vty, ", keepalive interval is %d seconds\n",
9201 p->keepalive);
d25e4efc 9202 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9203 || (bgp->default_keepalive
9204 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9205 vty_out(vty, " Configured hold time is %d",
9206 bgp->default_holdtime);
9207 vty_out(vty, ", keepalive interval is %d seconds\n",
9208 bgp->default_keepalive);
d62a17ae 9209 }
9210 }
9211 /* Capability. */
9212 if (p->status == Established) {
9213 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9214 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9215 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9216 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9217 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9218 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9219 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9220 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9221 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9222 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9223 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9224 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9225 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9226 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9227 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9228 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9229 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9230 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9231 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9232 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9233 if (use_json) {
9234 json_object *json_cap = NULL;
9235
9236 json_cap = json_object_new_object();
9237
9238 /* AS4 */
9239 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9240 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9241 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9242 && CHECK_FLAG(p->cap,
9243 PEER_CAP_AS4_RCV))
9244 json_object_string_add(
9245 json_cap, "4byteAs",
9246 "advertisedAndReceived");
9247 else if (CHECK_FLAG(p->cap,
9248 PEER_CAP_AS4_ADV))
9249 json_object_string_add(
9250 json_cap, "4byteAs",
9251 "advertised");
9252 else if (CHECK_FLAG(p->cap,
9253 PEER_CAP_AS4_RCV))
9254 json_object_string_add(
9255 json_cap, "4byteAs",
9256 "received");
9257 }
9258
9259 /* AddPath */
9260 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9261 || CHECK_FLAG(p->cap,
9262 PEER_CAP_ADDPATH_ADV)) {
9263 json_object *json_add = NULL;
9264 const char *print_store;
9265
9266 json_add = json_object_new_object();
9267
05c7a1cc
QY
9268 FOREACH_AFI_SAFI (afi, safi) {
9269 json_object *json_sub = NULL;
9270 json_sub =
9271 json_object_new_object();
9272 print_store = afi_safi_print(
9273 afi, safi);
d62a17ae 9274
05c7a1cc
QY
9275 if (CHECK_FLAG(
9276 p->af_cap[afi]
9277 [safi],
9278 PEER_CAP_ADDPATH_AF_TX_ADV)
9279 || CHECK_FLAG(
9280 p->af_cap[afi]
9281 [safi],
9282 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9283 if (CHECK_FLAG(
9284 p->af_cap
9285 [afi]
9286 [safi],
9287 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9288 && CHECK_FLAG(
d62a17ae 9289 p->af_cap
9290 [afi]
9291 [safi],
05c7a1cc
QY
9292 PEER_CAP_ADDPATH_AF_TX_RCV))
9293 json_object_boolean_true_add(
9294 json_sub,
9295 "txAdvertisedAndReceived");
9296 else if (
9297 CHECK_FLAG(
9298 p->af_cap
9299 [afi]
9300 [safi],
9301 PEER_CAP_ADDPATH_AF_TX_ADV))
9302 json_object_boolean_true_add(
9303 json_sub,
9304 "txAdvertised");
9305 else if (
9306 CHECK_FLAG(
9307 p->af_cap
9308 [afi]
9309 [safi],
9310 PEER_CAP_ADDPATH_AF_TX_RCV))
9311 json_object_boolean_true_add(
9312 json_sub,
9313 "txReceived");
9314 }
d62a17ae 9315
05c7a1cc
QY
9316 if (CHECK_FLAG(
9317 p->af_cap[afi]
9318 [safi],
9319 PEER_CAP_ADDPATH_AF_RX_ADV)
9320 || CHECK_FLAG(
9321 p->af_cap[afi]
9322 [safi],
9323 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9324 if (CHECK_FLAG(
9325 p->af_cap
9326 [afi]
9327 [safi],
9328 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9329 && CHECK_FLAG(
d62a17ae 9330 p->af_cap
9331 [afi]
9332 [safi],
9333 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9334 json_object_boolean_true_add(
9335 json_sub,
9336 "rxAdvertisedAndReceived");
9337 else if (
9338 CHECK_FLAG(
9339 p->af_cap
9340 [afi]
9341 [safi],
9342 PEER_CAP_ADDPATH_AF_RX_ADV))
9343 json_object_boolean_true_add(
9344 json_sub,
9345 "rxAdvertised");
9346 else if (
9347 CHECK_FLAG(
9348 p->af_cap
9349 [afi]
9350 [safi],
9351 PEER_CAP_ADDPATH_AF_RX_RCV))
9352 json_object_boolean_true_add(
9353 json_sub,
9354 "rxReceived");
d62a17ae 9355 }
9356
05c7a1cc
QY
9357 if (CHECK_FLAG(
9358 p->af_cap[afi]
9359 [safi],
9360 PEER_CAP_ADDPATH_AF_TX_ADV)
9361 || CHECK_FLAG(
9362 p->af_cap[afi]
9363 [safi],
9364 PEER_CAP_ADDPATH_AF_TX_RCV)
9365 || CHECK_FLAG(
9366 p->af_cap[afi]
9367 [safi],
9368 PEER_CAP_ADDPATH_AF_RX_ADV)
9369 || CHECK_FLAG(
9370 p->af_cap[afi]
9371 [safi],
9372 PEER_CAP_ADDPATH_AF_RX_RCV))
9373 json_object_object_add(
9374 json_add,
9375 print_store,
9376 json_sub);
9377 else
9378 json_object_free(
9379 json_sub);
9380 }
9381
d62a17ae 9382 json_object_object_add(
9383 json_cap, "addPath", json_add);
9384 }
9385
9386 /* Dynamic */
9387 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9388 || CHECK_FLAG(p->cap,
9389 PEER_CAP_DYNAMIC_ADV)) {
9390 if (CHECK_FLAG(p->cap,
9391 PEER_CAP_DYNAMIC_ADV)
9392 && CHECK_FLAG(p->cap,
9393 PEER_CAP_DYNAMIC_RCV))
9394 json_object_string_add(
9395 json_cap, "dynamic",
9396 "advertisedAndReceived");
9397 else if (CHECK_FLAG(
9398 p->cap,
9399 PEER_CAP_DYNAMIC_ADV))
9400 json_object_string_add(
9401 json_cap, "dynamic",
9402 "advertised");
9403 else if (CHECK_FLAG(
9404 p->cap,
9405 PEER_CAP_DYNAMIC_RCV))
9406 json_object_string_add(
9407 json_cap, "dynamic",
9408 "received");
9409 }
9410
9411 /* Extended nexthop */
9412 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9413 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9414 json_object *json_nxt = NULL;
9415 const char *print_store;
9416
9417
9418 if (CHECK_FLAG(p->cap,
9419 PEER_CAP_ENHE_ADV)
9420 && CHECK_FLAG(p->cap,
9421 PEER_CAP_ENHE_RCV))
9422 json_object_string_add(
9423 json_cap,
9424 "extendedNexthop",
9425 "advertisedAndReceived");
9426 else if (CHECK_FLAG(p->cap,
9427 PEER_CAP_ENHE_ADV))
9428 json_object_string_add(
9429 json_cap,
9430 "extendedNexthop",
9431 "advertised");
9432 else if (CHECK_FLAG(p->cap,
9433 PEER_CAP_ENHE_RCV))
9434 json_object_string_add(
9435 json_cap,
9436 "extendedNexthop",
9437 "received");
9438
9439 if (CHECK_FLAG(p->cap,
9440 PEER_CAP_ENHE_RCV)) {
9441 json_nxt =
9442 json_object_new_object();
9443
9444 for (safi = SAFI_UNICAST;
9445 safi < SAFI_MAX; safi++) {
9446 if (CHECK_FLAG(
9447 p->af_cap
9448 [AFI_IP]
9449 [safi],
9450 PEER_CAP_ENHE_AF_RCV)) {
9451 print_store = afi_safi_print(
9452 AFI_IP,
9453 safi);
9454 json_object_string_add(
9455 json_nxt,
9456 print_store,
9457 "recieved");
9458 }
9459 }
9460 json_object_object_add(
9461 json_cap,
9462 "extendedNexthopFamililesByPeer",
9463 json_nxt);
9464 }
9465 }
9466
9467 /* Route Refresh */
9468 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9469 || CHECK_FLAG(p->cap,
9470 PEER_CAP_REFRESH_NEW_RCV)
9471 || CHECK_FLAG(p->cap,
9472 PEER_CAP_REFRESH_OLD_RCV)) {
9473 if (CHECK_FLAG(p->cap,
9474 PEER_CAP_REFRESH_ADV)
9475 && (CHECK_FLAG(
9476 p->cap,
9477 PEER_CAP_REFRESH_NEW_RCV)
9478 || CHECK_FLAG(
9479 p->cap,
9480 PEER_CAP_REFRESH_OLD_RCV))) {
9481 if (CHECK_FLAG(
9482 p->cap,
9483 PEER_CAP_REFRESH_OLD_RCV)
9484 && CHECK_FLAG(
9485 p->cap,
9486 PEER_CAP_REFRESH_NEW_RCV))
9487 json_object_string_add(
9488 json_cap,
9489 "routeRefresh",
9490 "advertisedAndReceivedOldNew");
9491 else {
9492 if (CHECK_FLAG(
9493 p->cap,
9494 PEER_CAP_REFRESH_OLD_RCV))
9495 json_object_string_add(
9496 json_cap,
9497 "routeRefresh",
9498 "advertisedAndReceivedOld");
9499 else
9500 json_object_string_add(
9501 json_cap,
9502 "routeRefresh",
9503 "advertisedAndReceivedNew");
9504 }
9505 } else if (
9506 CHECK_FLAG(
9507 p->cap,
9508 PEER_CAP_REFRESH_ADV))
9509 json_object_string_add(
9510 json_cap,
9511 "routeRefresh",
9512 "advertised");
9513 else if (
9514 CHECK_FLAG(
9515 p->cap,
9516 PEER_CAP_REFRESH_NEW_RCV)
9517 || CHECK_FLAG(
9518 p->cap,
9519 PEER_CAP_REFRESH_OLD_RCV))
9520 json_object_string_add(
9521 json_cap,
9522 "routeRefresh",
9523 "received");
9524 }
9525
9526 /* Multiprotocol Extensions */
9527 json_object *json_multi = NULL;
9528 json_multi = json_object_new_object();
9529
05c7a1cc
QY
9530 FOREACH_AFI_SAFI (afi, safi) {
9531 if (p->afc_adv[afi][safi]
9532 || p->afc_recv[afi][safi]) {
9533 json_object *json_exten = NULL;
9534 json_exten =
9535 json_object_new_object();
9536
d62a17ae 9537 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9538 && p->afc_recv[afi][safi])
9539 json_object_boolean_true_add(
9540 json_exten,
9541 "advertisedAndReceived");
9542 else if (p->afc_adv[afi][safi])
9543 json_object_boolean_true_add(
9544 json_exten,
9545 "advertised");
9546 else if (p->afc_recv[afi][safi])
9547 json_object_boolean_true_add(
9548 json_exten,
9549 "received");
d62a17ae 9550
05c7a1cc
QY
9551 json_object_object_add(
9552 json_multi,
9553 afi_safi_print(afi,
9554 safi),
9555 json_exten);
d62a17ae 9556 }
9557 }
9558 json_object_object_add(
9559 json_cap, "multiprotocolExtensions",
9560 json_multi);
9561
d77114b7 9562 /* Hostname capabilities */
60466a63 9563 json_object *json_hname = NULL;
d77114b7
MK
9564
9565 json_hname = json_object_new_object();
9566
9567 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9568 json_object_string_add(
60466a63
QY
9569 json_hname, "advHostName",
9570 bgp->peer_self->hostname
9571 ? bgp->peer_self
9572 ->hostname
d77114b7
MK
9573 : "n/a");
9574 json_object_string_add(
60466a63
QY
9575 json_hname, "advDomainName",
9576 bgp->peer_self->domainname
9577 ? bgp->peer_self
9578 ->domainname
d77114b7
MK
9579 : "n/a");
9580 }
9581
9582
9583 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9584 json_object_string_add(
60466a63
QY
9585 json_hname, "rcvHostName",
9586 p->hostname ? p->hostname
9587 : "n/a");
d77114b7 9588 json_object_string_add(
60466a63
QY
9589 json_hname, "rcvDomainName",
9590 p->domainname ? p->domainname
9591 : "n/a");
d77114b7
MK
9592 }
9593
60466a63 9594 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9595 json_hname);
9596
d62a17ae 9597 /* Gracefull Restart */
9598 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9599 || CHECK_FLAG(p->cap,
9600 PEER_CAP_RESTART_ADV)) {
9601 if (CHECK_FLAG(p->cap,
9602 PEER_CAP_RESTART_ADV)
9603 && CHECK_FLAG(p->cap,
9604 PEER_CAP_RESTART_RCV))
9605 json_object_string_add(
9606 json_cap,
9607 "gracefulRestart",
9608 "advertisedAndReceived");
9609 else if (CHECK_FLAG(
9610 p->cap,
9611 PEER_CAP_RESTART_ADV))
9612 json_object_string_add(
9613 json_cap,
9614 "gracefulRestartCapability",
9615 "advertised");
9616 else if (CHECK_FLAG(
9617 p->cap,
9618 PEER_CAP_RESTART_RCV))
9619 json_object_string_add(
9620 json_cap,
9621 "gracefulRestartCapability",
9622 "received");
9623
9624 if (CHECK_FLAG(p->cap,
9625 PEER_CAP_RESTART_RCV)) {
9626 int restart_af_count = 0;
9627 json_object *json_restart =
9628 NULL;
9629 json_restart =
9630 json_object_new_object();
9631
9632 json_object_int_add(
9633 json_cap,
9634 "gracefulRestartRemoteTimerMsecs",
9635 p->v_gr_restart * 1000);
9636
05c7a1cc
QY
9637 FOREACH_AFI_SAFI (afi, safi) {
9638 if (CHECK_FLAG(
9639 p->af_cap
9640 [afi]
9641 [safi],
9642 PEER_CAP_RESTART_AF_RCV)) {
9643 json_object *
9644 json_sub =
9645 NULL;
9646 json_sub =
9647 json_object_new_object();
9648
d62a17ae 9649 if (CHECK_FLAG(
9650 p->af_cap
9651 [afi]
9652 [safi],
05c7a1cc
QY
9653 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9654 json_object_boolean_true_add(
9655 json_sub,
9656 "preserved");
9657 restart_af_count++;
9658 json_object_object_add(
9659 json_restart,
9660 afi_safi_print(
9661 afi,
9662 safi),
9663 json_sub);
d62a17ae 9664 }
9665 }
9666 if (!restart_af_count) {
9667 json_object_string_add(
9668 json_cap,
9669 "addressFamiliesByPeer",
9670 "none");
9671 json_object_free(
9672 json_restart);
9673 } else
9674 json_object_object_add(
9675 json_cap,
9676 "addressFamiliesByPeer",
9677 json_restart);
9678 }
9679 }
9680 json_object_object_add(json_neigh,
9681 "neighborCapabilities",
9682 json_cap);
9683 } else {
9684 vty_out(vty, " Neighbor capabilities:\n");
9685
9686 /* AS4 */
9687 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9688 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9689 vty_out(vty, " 4 Byte AS:");
9690 if (CHECK_FLAG(p->cap,
9691 PEER_CAP_AS4_ADV))
9692 vty_out(vty, " advertised");
9693 if (CHECK_FLAG(p->cap,
9694 PEER_CAP_AS4_RCV))
9695 vty_out(vty, " %sreceived",
9696 CHECK_FLAG(
9697 p->cap,
9698 PEER_CAP_AS4_ADV)
9699 ? "and "
9700 : "");
9701 vty_out(vty, "\n");
9702 }
9703
9704 /* AddPath */
9705 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9706 || CHECK_FLAG(p->cap,
9707 PEER_CAP_ADDPATH_ADV)) {
9708 vty_out(vty, " AddPath:\n");
9709
05c7a1cc
QY
9710 FOREACH_AFI_SAFI (afi, safi) {
9711 if (CHECK_FLAG(
9712 p->af_cap[afi]
9713 [safi],
9714 PEER_CAP_ADDPATH_AF_TX_ADV)
9715 || CHECK_FLAG(
9716 p->af_cap[afi]
9717 [safi],
9718 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9719 vty_out(vty,
9720 " %s: TX ",
9721 afi_safi_print(
9722 afi,
9723 safi));
9724
d62a17ae 9725 if (CHECK_FLAG(
9726 p->af_cap
9727 [afi]
9728 [safi],
05c7a1cc 9729 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 9730 vty_out(vty,
05c7a1cc 9731 "advertised %s",
d62a17ae 9732 afi_safi_print(
9733 afi,
9734 safi));
9735
05c7a1cc
QY
9736 if (CHECK_FLAG(
9737 p->af_cap
9738 [afi]
9739 [safi],
9740 PEER_CAP_ADDPATH_AF_TX_RCV))
9741 vty_out(vty,
9742 "%sreceived",
9743 CHECK_FLAG(
9744 p->af_cap
9745 [afi]
9746 [safi],
9747 PEER_CAP_ADDPATH_AF_TX_ADV)
9748 ? " and "
9749 : "");
d62a17ae 9750
05c7a1cc
QY
9751 vty_out(vty, "\n");
9752 }
d62a17ae 9753
05c7a1cc
QY
9754 if (CHECK_FLAG(
9755 p->af_cap[afi]
9756 [safi],
9757 PEER_CAP_ADDPATH_AF_RX_ADV)
9758 || CHECK_FLAG(
9759 p->af_cap[afi]
9760 [safi],
9761 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9762 vty_out(vty,
9763 " %s: RX ",
9764 afi_safi_print(
9765 afi,
9766 safi));
d62a17ae 9767
9768 if (CHECK_FLAG(
9769 p->af_cap
9770 [afi]
9771 [safi],
05c7a1cc 9772 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 9773 vty_out(vty,
05c7a1cc 9774 "advertised %s",
d62a17ae 9775 afi_safi_print(
9776 afi,
9777 safi));
9778
05c7a1cc
QY
9779 if (CHECK_FLAG(
9780 p->af_cap
9781 [afi]
9782 [safi],
9783 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 9784 vty_out(vty,
05c7a1cc
QY
9785 "%sreceived",
9786 CHECK_FLAG(
9787 p->af_cap
9788 [afi]
9789 [safi],
9790 PEER_CAP_ADDPATH_AF_RX_ADV)
9791 ? " and "
9792 : "");
9793
9794 vty_out(vty, "\n");
d62a17ae 9795 }
05c7a1cc 9796 }
d62a17ae 9797 }
9798
9799 /* Dynamic */
9800 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9801 || CHECK_FLAG(p->cap,
9802 PEER_CAP_DYNAMIC_ADV)) {
9803 vty_out(vty, " Dynamic:");
9804 if (CHECK_FLAG(p->cap,
9805 PEER_CAP_DYNAMIC_ADV))
9806 vty_out(vty, " advertised");
9807 if (CHECK_FLAG(p->cap,
9808 PEER_CAP_DYNAMIC_RCV))
9809 vty_out(vty, " %sreceived",
9810 CHECK_FLAG(
9811 p->cap,
9812 PEER_CAP_DYNAMIC_ADV)
9813 ? "and "
9814 : "");
9815 vty_out(vty, "\n");
9816 }
9817
9818 /* Extended nexthop */
9819 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9820 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9821 vty_out(vty, " Extended nexthop:");
9822 if (CHECK_FLAG(p->cap,
9823 PEER_CAP_ENHE_ADV))
9824 vty_out(vty, " advertised");
9825 if (CHECK_FLAG(p->cap,
9826 PEER_CAP_ENHE_RCV))
9827 vty_out(vty, " %sreceived",
9828 CHECK_FLAG(
9829 p->cap,
9830 PEER_CAP_ENHE_ADV)
9831 ? "and "
9832 : "");
9833 vty_out(vty, "\n");
9834
9835 if (CHECK_FLAG(p->cap,
9836 PEER_CAP_ENHE_RCV)) {
9837 vty_out(vty,
9838 " Address families by peer:\n ");
9839 for (safi = SAFI_UNICAST;
9840 safi < SAFI_MAX; safi++)
9841 if (CHECK_FLAG(
9842 p->af_cap
9843 [AFI_IP]
9844 [safi],
9845 PEER_CAP_ENHE_AF_RCV))
9846 vty_out(vty,
9847 " %s\n",
9848 afi_safi_print(
9849 AFI_IP,
9850 safi));
9851 }
9852 }
9853
9854 /* Route Refresh */
9855 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9856 || CHECK_FLAG(p->cap,
9857 PEER_CAP_REFRESH_NEW_RCV)
9858 || CHECK_FLAG(p->cap,
9859 PEER_CAP_REFRESH_OLD_RCV)) {
9860 vty_out(vty, " Route refresh:");
9861 if (CHECK_FLAG(p->cap,
9862 PEER_CAP_REFRESH_ADV))
9863 vty_out(vty, " advertised");
9864 if (CHECK_FLAG(p->cap,
9865 PEER_CAP_REFRESH_NEW_RCV)
9866 || CHECK_FLAG(
9867 p->cap,
9868 PEER_CAP_REFRESH_OLD_RCV))
9869 vty_out(vty, " %sreceived(%s)",
9870 CHECK_FLAG(
9871 p->cap,
9872 PEER_CAP_REFRESH_ADV)
9873 ? "and "
9874 : "",
9875 (CHECK_FLAG(
9876 p->cap,
9877 PEER_CAP_REFRESH_OLD_RCV)
9878 && CHECK_FLAG(
9879 p->cap,
9880 PEER_CAP_REFRESH_NEW_RCV))
9881 ? "old & new"
9882 : CHECK_FLAG(
9883 p->cap,
9884 PEER_CAP_REFRESH_OLD_RCV)
9885 ? "old"
9886 : "new");
9887
9888 vty_out(vty, "\n");
9889 }
9890
9891 /* Multiprotocol Extensions */
05c7a1cc
QY
9892 FOREACH_AFI_SAFI (afi, safi)
9893 if (p->afc_adv[afi][safi]
9894 || p->afc_recv[afi][safi]) {
9895 vty_out(vty,
9896 " Address Family %s:",
9897 afi_safi_print(afi,
9898 safi));
9899 if (p->afc_adv[afi][safi])
d62a17ae 9900 vty_out(vty,
05c7a1cc
QY
9901 " advertised");
9902 if (p->afc_recv[afi][safi])
9903 vty_out(vty,
9904 " %sreceived",
9905 p->afc_adv[afi]
9906 [safi]
9907 ? "and "
9908 : "");
9909 vty_out(vty, "\n");
9910 }
d62a17ae 9911
9912 /* Hostname capability */
60466a63 9913 vty_out(vty, " Hostname Capability:");
d77114b7
MK
9914
9915 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
9916 vty_out(vty,
9917 " advertised (name: %s,domain name: %s)",
60466a63
QY
9918 bgp->peer_self->hostname
9919 ? bgp->peer_self
9920 ->hostname
d77114b7 9921 : "n/a",
60466a63
QY
9922 bgp->peer_self->domainname
9923 ? bgp->peer_self
9924 ->domainname
d77114b7
MK
9925 : "n/a");
9926 } else {
9927 vty_out(vty, " not advertised");
d62a17ae 9928 }
9929
d77114b7 9930 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
9931 vty_out(vty,
9932 " received (name: %s,domain name: %s)",
60466a63
QY
9933 p->hostname ? p->hostname
9934 : "n/a",
9935 p->domainname ? p->domainname
9936 : "n/a");
d77114b7
MK
9937 } else {
9938 vty_out(vty, " not received");
9939 }
9940
9941 vty_out(vty, "\n");
9942
d62a17ae 9943 /* Gracefull Restart */
9944 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9945 || CHECK_FLAG(p->cap,
9946 PEER_CAP_RESTART_ADV)) {
9947 vty_out(vty,
9948 " Graceful Restart Capabilty:");
9949 if (CHECK_FLAG(p->cap,
9950 PEER_CAP_RESTART_ADV))
9951 vty_out(vty, " advertised");
9952 if (CHECK_FLAG(p->cap,
9953 PEER_CAP_RESTART_RCV))
9954 vty_out(vty, " %sreceived",
9955 CHECK_FLAG(
9956 p->cap,
9957 PEER_CAP_RESTART_ADV)
9958 ? "and "
9959 : "");
9960 vty_out(vty, "\n");
9961
9962 if (CHECK_FLAG(p->cap,
9963 PEER_CAP_RESTART_RCV)) {
9964 int restart_af_count = 0;
9965
9966 vty_out(vty,
9967 " Remote Restart timer is %d seconds\n",
9968 p->v_gr_restart);
9969 vty_out(vty,
9970 " Address families by peer:\n ");
9971
05c7a1cc
QY
9972 FOREACH_AFI_SAFI (afi, safi)
9973 if (CHECK_FLAG(
9974 p->af_cap
9975 [afi]
9976 [safi],
9977 PEER_CAP_RESTART_AF_RCV)) {
9978 vty_out(vty,
9979 "%s%s(%s)",
9980 restart_af_count
9981 ? ", "
9982 : "",
9983 afi_safi_print(
9984 afi,
9985 safi),
9986 CHECK_FLAG(
9987 p->af_cap
9988 [afi]
9989 [safi],
9990 PEER_CAP_RESTART_AF_PRESERVE_RCV)
9991 ? "preserved"
9992 : "not preserved");
9993 restart_af_count++;
9994 }
d62a17ae 9995 if (!restart_af_count)
9996 vty_out(vty, "none");
9997 vty_out(vty, "\n");
9998 }
9999 }
10000 }
10001 }
10002 }
10003
10004 /* graceful restart information */
10005 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10006 || p->t_gr_stale) {
10007 json_object *json_grace = NULL;
10008 json_object *json_grace_send = NULL;
10009 json_object *json_grace_recv = NULL;
10010 int eor_send_af_count = 0;
10011 int eor_receive_af_count = 0;
10012
10013 if (use_json) {
10014 json_grace = json_object_new_object();
10015 json_grace_send = json_object_new_object();
10016 json_grace_recv = json_object_new_object();
10017
10018 if (p->status == Established) {
05c7a1cc
QY
10019 FOREACH_AFI_SAFI (afi, safi) {
10020 if (CHECK_FLAG(p->af_sflags[afi][safi],
10021 PEER_STATUS_EOR_SEND)) {
10022 json_object_boolean_true_add(
10023 json_grace_send,
10024 afi_safi_print(afi,
10025 safi));
10026 eor_send_af_count++;
d62a17ae 10027 }
10028 }
05c7a1cc
QY
10029 FOREACH_AFI_SAFI (afi, safi) {
10030 if (CHECK_FLAG(
10031 p->af_sflags[afi][safi],
10032 PEER_STATUS_EOR_RECEIVED)) {
10033 json_object_boolean_true_add(
10034 json_grace_recv,
10035 afi_safi_print(afi,
10036 safi));
10037 eor_receive_af_count++;
d62a17ae 10038 }
10039 }
10040 }
10041
10042 json_object_object_add(json_grace, "endOfRibSend",
10043 json_grace_send);
10044 json_object_object_add(json_grace, "endOfRibRecv",
10045 json_grace_recv);
10046
10047 if (p->t_gr_restart)
10048 json_object_int_add(json_grace,
10049 "gracefulRestartTimerMsecs",
10050 thread_timer_remain_second(
10051 p->t_gr_restart)
10052 * 1000);
10053
10054 if (p->t_gr_stale)
10055 json_object_int_add(
10056 json_grace,
10057 "gracefulStalepathTimerMsecs",
10058 thread_timer_remain_second(
10059 p->t_gr_stale)
10060 * 1000);
10061
10062 json_object_object_add(
10063 json_neigh, "gracefulRestartInfo", json_grace);
10064 } else {
10065 vty_out(vty, " Graceful restart informations:\n");
10066 if (p->status == Established) {
10067 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10068 FOREACH_AFI_SAFI (afi, safi) {
10069 if (CHECK_FLAG(p->af_sflags[afi][safi],
10070 PEER_STATUS_EOR_SEND)) {
10071 vty_out(vty, "%s%s",
10072 eor_send_af_count ? ", "
10073 : "",
10074 afi_safi_print(afi,
10075 safi));
10076 eor_send_af_count++;
d62a17ae 10077 }
10078 }
10079 vty_out(vty, "\n");
10080 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10081 FOREACH_AFI_SAFI (afi, safi) {
10082 if (CHECK_FLAG(
10083 p->af_sflags[afi][safi],
10084 PEER_STATUS_EOR_RECEIVED)) {
10085 vty_out(vty, "%s%s",
10086 eor_receive_af_count
10087 ? ", "
10088 : "",
10089 afi_safi_print(afi,
10090 safi));
10091 eor_receive_af_count++;
d62a17ae 10092 }
10093 }
10094 vty_out(vty, "\n");
10095 }
10096
10097 if (p->t_gr_restart)
10098 vty_out(vty,
10099 " The remaining time of restart timer is %ld\n",
10100 thread_timer_remain_second(
10101 p->t_gr_restart));
10102
10103 if (p->t_gr_stale)
10104 vty_out(vty,
10105 " The remaining time of stalepath timer is %ld\n",
10106 thread_timer_remain_second(
10107 p->t_gr_stale));
10108 }
10109 }
10110 if (use_json) {
10111 json_object *json_stat = NULL;
10112 json_stat = json_object_new_object();
10113 /* Packet counts. */
10114 json_object_int_add(json_stat, "depthInq", 0);
10115 json_object_int_add(json_stat, "depthOutq",
10116 (unsigned long)p->obuf->count);
0112e9e0
QY
10117 json_object_int_add(json_stat, "opensSent",
10118 atomic_load_explicit(&p->open_out,
10119 memory_order_relaxed));
10120 json_object_int_add(json_stat, "opensRecv",
10121 atomic_load_explicit(&p->open_in,
10122 memory_order_relaxed));
d62a17ae 10123 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10124 atomic_load_explicit(&p->notify_out,
10125 memory_order_relaxed));
d62a17ae 10126 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10127 atomic_load_explicit(&p->notify_in,
10128 memory_order_relaxed));
10129 json_object_int_add(json_stat, "updatesSent",
10130 atomic_load_explicit(&p->update_out,
10131 memory_order_relaxed));
10132 json_object_int_add(json_stat, "updatesRecv",
10133 atomic_load_explicit(&p->update_in,
10134 memory_order_relaxed));
d62a17ae 10135 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10136 atomic_load_explicit(&p->keepalive_out,
10137 memory_order_relaxed));
d62a17ae 10138 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10139 atomic_load_explicit(&p->keepalive_in,
10140 memory_order_relaxed));
d62a17ae 10141 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10142 atomic_load_explicit(&p->refresh_out,
10143 memory_order_relaxed));
d62a17ae 10144 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10145 atomic_load_explicit(&p->refresh_in,
10146 memory_order_relaxed));
d62a17ae 10147 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10148 atomic_load_explicit(&p->dynamic_cap_out,
10149 memory_order_relaxed));
d62a17ae 10150 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10151 atomic_load_explicit(&p->dynamic_cap_in,
10152 memory_order_relaxed));
10153 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10154 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10155 json_object_object_add(json_neigh, "messageStats", json_stat);
10156 } else {
10157 /* Packet counts. */
10158 vty_out(vty, " Message statistics:\n");
10159 vty_out(vty, " Inq depth is 0\n");
10160 vty_out(vty, " Outq depth is %lu\n",
10161 (unsigned long)p->obuf->count);
10162 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10163 vty_out(vty, " Opens: %10d %10d\n",
10164 atomic_load_explicit(&p->open_out,
10165 memory_order_relaxed),
10166 atomic_load_explicit(&p->open_in,
10167 memory_order_relaxed));
10168 vty_out(vty, " Notifications: %10d %10d\n",
10169 atomic_load_explicit(&p->notify_out,
10170 memory_order_relaxed),
10171 atomic_load_explicit(&p->notify_in,
10172 memory_order_relaxed));
10173 vty_out(vty, " Updates: %10d %10d\n",
10174 atomic_load_explicit(&p->update_out,
10175 memory_order_relaxed),
10176 atomic_load_explicit(&p->update_in,
10177 memory_order_relaxed));
10178 vty_out(vty, " Keepalives: %10d %10d\n",
10179 atomic_load_explicit(&p->keepalive_out,
10180 memory_order_relaxed),
10181 atomic_load_explicit(&p->keepalive_in,
10182 memory_order_relaxed));
10183 vty_out(vty, " Route Refresh: %10d %10d\n",
10184 atomic_load_explicit(&p->refresh_out,
10185 memory_order_relaxed),
10186 atomic_load_explicit(&p->refresh_in,
10187 memory_order_relaxed));
d62a17ae 10188 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10189 atomic_load_explicit(&p->dynamic_cap_out,
10190 memory_order_relaxed),
10191 atomic_load_explicit(&p->dynamic_cap_in,
10192 memory_order_relaxed));
10193 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10194 PEER_TOTAL_RX(p));
d62a17ae 10195 }
10196
10197 if (use_json) {
10198 /* advertisement-interval */
10199 json_object_int_add(json_neigh,
10200 "minBtwnAdvertisementRunsTimerMsecs",
10201 p->v_routeadv * 1000);
10202
10203 /* Update-source. */
10204 if (p->update_if || p->update_source) {
10205 if (p->update_if)
10206 json_object_string_add(json_neigh,
10207 "updateSource",
10208 p->update_if);
10209 else if (p->update_source)
10210 json_object_string_add(
10211 json_neigh, "updateSource",
10212 sockunion2str(p->update_source, buf1,
10213 SU_ADDRSTRLEN));
10214 }
10215 } else {
10216 /* advertisement-interval */
10217 vty_out(vty,
10218 " Minimum time between advertisement runs is %d seconds\n",
10219 p->v_routeadv);
10220
10221 /* Update-source. */
10222 if (p->update_if || p->update_source) {
10223 vty_out(vty, " Update source is ");
10224 if (p->update_if)
10225 vty_out(vty, "%s", p->update_if);
10226 else if (p->update_source)
10227 vty_out(vty, "%s",
10228 sockunion2str(p->update_source, buf1,
10229 SU_ADDRSTRLEN));
10230 vty_out(vty, "\n");
10231 }
10232
10233 vty_out(vty, "\n");
10234 }
10235
10236 /* Address Family Information */
10237 json_object *json_hold = NULL;
10238
10239 if (use_json)
10240 json_hold = json_object_new_object();
10241
05c7a1cc
QY
10242 FOREACH_AFI_SAFI (afi, safi)
10243 if (p->afc[afi][safi])
10244 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10245 json_hold);
d62a17ae 10246
10247 if (use_json) {
10248 json_object_object_add(json_neigh, "addressFamilyInfo",
10249 json_hold);
10250 json_object_int_add(json_neigh, "connectionsEstablished",
10251 p->established);
10252 json_object_int_add(json_neigh, "connectionsDropped",
10253 p->dropped);
10254 } else
10255 vty_out(vty, " Connections established %d; dropped %d\n",
10256 p->established, p->dropped);
10257
10258 if (!p->last_reset) {
10259 if (use_json)
10260 json_object_string_add(json_neigh, "lastReset",
10261 "never");
10262 else
10263 vty_out(vty, " Last reset never\n");
10264 } else {
10265 if (use_json) {
10266 time_t uptime;
10267 struct tm *tm;
10268
10269 uptime = bgp_clock();
10270 uptime -= p->resettime;
10271 tm = gmtime(&uptime);
10272 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10273 (tm->tm_sec * 1000)
10274 + (tm->tm_min * 60000)
10275 + (tm->tm_hour * 3600000));
10276 json_object_string_add(
10277 json_neigh, "lastResetDueTo",
10278 peer_down_str[(int)p->last_reset]);
10279 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10280 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10281 char errorcodesubcode_hexstr[5];
10282 char errorcodesubcode_str[256];
10283
10284 code_str = bgp_notify_code_str(p->notify.code);
10285 subcode_str = bgp_notify_subcode_str(
10286 p->notify.code, p->notify.subcode);
10287
10288 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10289 p->notify.code, p->notify.subcode);
10290 json_object_string_add(json_neigh,
10291 "lastErrorCodeSubcode",
10292 errorcodesubcode_hexstr);
10293 snprintf(errorcodesubcode_str, 255, "%s%s",
10294 code_str, subcode_str);
10295 json_object_string_add(json_neigh,
10296 "lastNotificationReason",
10297 errorcodesubcode_str);
10298 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10299 && p->notify.code == BGP_NOTIFY_CEASE
10300 && (p->notify.subcode
10301 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10302 || p->notify.subcode
10303 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10304 && p->notify.length) {
10305 char msgbuf[1024];
10306 const char *msg_str;
10307
10308 msg_str = bgp_notify_admin_message(
10309 msgbuf, sizeof(msgbuf),
d7c0a89a 10310 (uint8_t *)p->notify.data,
d62a17ae 10311 p->notify.length);
10312 if (msg_str)
10313 json_object_string_add(
10314 json_neigh,
10315 "lastShutdownDescription",
10316 msg_str);
10317 }
10318 }
10319 } else {
10320 vty_out(vty, " Last reset %s, ",
10321 peer_uptime(p->resettime, timebuf,
10322 BGP_UPTIME_LEN, 0, NULL));
10323
10324 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10325 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10326 code_str = bgp_notify_code_str(p->notify.code);
10327 subcode_str = bgp_notify_subcode_str(
10328 p->notify.code, p->notify.subcode);
10329 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10330 p->last_reset == PEER_DOWN_NOTIFY_SEND
10331 ? "sent"
10332 : "received",
10333 code_str, subcode_str);
10334 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10335 && p->notify.code == BGP_NOTIFY_CEASE
10336 && (p->notify.subcode
10337 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10338 || p->notify.subcode
10339 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10340 && p->notify.length) {
10341 char msgbuf[1024];
10342 const char *msg_str;
10343
10344 msg_str = bgp_notify_admin_message(
10345 msgbuf, sizeof(msgbuf),
d7c0a89a 10346 (uint8_t *)p->notify.data,
d62a17ae 10347 p->notify.length);
10348 if (msg_str)
10349 vty_out(vty,
10350 " Message: \"%s\"\n",
10351 msg_str);
10352 }
10353 } else {
10354 vty_out(vty, "due to %s\n",
10355 peer_down_str[(int)p->last_reset]);
10356 }
10357
10358 if (p->last_reset_cause_size) {
10359 msg = p->last_reset_cause;
10360 vty_out(vty,
10361 " Message received that caused BGP to send a NOTIFICATION:\n ");
10362 for (i = 1; i <= p->last_reset_cause_size;
10363 i++) {
10364 vty_out(vty, "%02X", *msg++);
10365
10366 if (i != p->last_reset_cause_size) {
10367 if (i % 16 == 0) {
10368 vty_out(vty, "\n ");
10369 } else if (i % 4 == 0) {
10370 vty_out(vty, " ");
10371 }
10372 }
10373 }
10374 vty_out(vty, "\n");
10375 }
10376 }
10377 }
10378
10379 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10380 if (use_json)
10381 json_object_boolean_true_add(json_neigh,
10382 "prefixesConfigExceedMax");
10383 else
10384 vty_out(vty,
10385 " Peer had exceeded the max. no. of prefixes configured.\n");
10386
10387 if (p->t_pmax_restart) {
10388 if (use_json) {
10389 json_object_boolean_true_add(
10390 json_neigh, "reducePrefixNumFrom");
10391 json_object_int_add(json_neigh,
10392 "restartInTimerMsec",
10393 thread_timer_remain_second(
10394 p->t_pmax_restart)
10395 * 1000);
10396 } else
10397 vty_out(vty,
10398 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10399 p->host, thread_timer_remain_second(
10400 p->t_pmax_restart));
d62a17ae 10401 } else {
10402 if (use_json)
10403 json_object_boolean_true_add(
10404 json_neigh,
10405 "reducePrefixNumAndClearIpBgp");
10406 else
10407 vty_out(vty,
10408 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10409 p->host);
10410 }
10411 }
10412
10413 /* EBGP Multihop and GTSM */
10414 if (p->sort != BGP_PEER_IBGP) {
10415 if (use_json) {
10416 if (p->gtsm_hops > 0)
10417 json_object_int_add(json_neigh,
10418 "externalBgpNbrMaxHopsAway",
10419 p->gtsm_hops);
10420 else if (p->ttl > 1)
10421 json_object_int_add(json_neigh,
10422 "externalBgpNbrMaxHopsAway",
10423 p->ttl);
10424 } else {
10425 if (p->gtsm_hops > 0)
10426 vty_out(vty,
10427 " External BGP neighbor may be up to %d hops away.\n",
10428 p->gtsm_hops);
10429 else if (p->ttl > 1)
10430 vty_out(vty,
10431 " External BGP neighbor may be up to %d hops away.\n",
10432 p->ttl);
10433 }
10434 } else {
10435 if (p->gtsm_hops > 0) {
10436 if (use_json)
10437 json_object_int_add(json_neigh,
10438 "internalBgpNbrMaxHopsAway",
10439 p->gtsm_hops);
10440 else
10441 vty_out(vty,
10442 " Internal BGP neighbor may be up to %d hops away.\n",
10443 p->gtsm_hops);
10444 }
10445 }
10446
10447 /* Local address. */
10448 if (p->su_local) {
10449 if (use_json) {
10450 json_object_string_add(json_neigh, "hostLocal",
10451 sockunion2str(p->su_local, buf1,
10452 SU_ADDRSTRLEN));
10453 json_object_int_add(json_neigh, "portLocal",
10454 ntohs(p->su_local->sin.sin_port));
10455 } else
10456 vty_out(vty, "Local host: %s, Local port: %d\n",
10457 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10458 ntohs(p->su_local->sin.sin_port));
10459 }
10460
10461 /* Remote address. */
10462 if (p->su_remote) {
10463 if (use_json) {
10464 json_object_string_add(json_neigh, "hostForeign",
10465 sockunion2str(p->su_remote, buf1,
10466 SU_ADDRSTRLEN));
10467 json_object_int_add(json_neigh, "portForeign",
10468 ntohs(p->su_remote->sin.sin_port));
10469 } else
10470 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10471 sockunion2str(p->su_remote, buf1,
10472 SU_ADDRSTRLEN),
10473 ntohs(p->su_remote->sin.sin_port));
10474 }
10475
10476 /* Nexthop display. */
10477 if (p->su_local) {
10478 if (use_json) {
10479 json_object_string_add(json_neigh, "nexthop",
10480 inet_ntop(AF_INET,
10481 &p->nexthop.v4, buf1,
10482 sizeof(buf1)));
10483 json_object_string_add(json_neigh, "nexthopGlobal",
10484 inet_ntop(AF_INET6,
10485 &p->nexthop.v6_global,
10486 buf1, sizeof(buf1)));
10487 json_object_string_add(json_neigh, "nexthopLocal",
10488 inet_ntop(AF_INET6,
10489 &p->nexthop.v6_local,
10490 buf1, sizeof(buf1)));
10491 if (p->shared_network)
10492 json_object_string_add(json_neigh,
10493 "bgpConnection",
10494 "sharedNetwork");
10495 else
10496 json_object_string_add(json_neigh,
10497 "bgpConnection",
10498 "nonSharedNetwork");
10499 } else {
10500 vty_out(vty, "Nexthop: %s\n",
10501 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10502 sizeof(buf1)));
10503 vty_out(vty, "Nexthop global: %s\n",
10504 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10505 sizeof(buf1)));
10506 vty_out(vty, "Nexthop local: %s\n",
10507 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10508 sizeof(buf1)));
10509 vty_out(vty, "BGP connection: %s\n",
10510 p->shared_network ? "shared network"
10511 : "non shared network");
10512 }
10513 }
10514
10515 /* Timer information. */
10516 if (use_json) {
10517 json_object_int_add(json_neigh, "connectRetryTimer",
10518 p->v_connect);
10519 if (p->status == Established && p->rtt)
10520 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10521 p->rtt);
10522 if (p->t_start)
10523 json_object_int_add(
10524 json_neigh, "nextStartTimerDueInMsecs",
10525 thread_timer_remain_second(p->t_start) * 1000);
10526 if (p->t_connect)
10527 json_object_int_add(
10528 json_neigh, "nextConnectTimerDueInMsecs",
10529 thread_timer_remain_second(p->t_connect)
10530 * 1000);
10531 if (p->t_routeadv) {
10532 json_object_int_add(json_neigh, "mraiInterval",
10533 p->v_routeadv);
10534 json_object_int_add(
10535 json_neigh, "mraiTimerExpireInMsecs",
10536 thread_timer_remain_second(p->t_routeadv)
10537 * 1000);
10538 }
10539 if (p->password)
10540 json_object_int_add(json_neigh, "authenticationEnabled",
10541 1);
10542
10543 if (p->t_read)
10544 json_object_string_add(json_neigh, "readThread", "on");
10545 else
10546 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10547
10548 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10549 json_object_string_add(json_neigh, "writeThread", "on");
10550 else
10551 json_object_string_add(json_neigh, "writeThread",
10552 "off");
10553 } else {
10554 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10555 p->v_connect);
10556 if (p->status == Established && p->rtt)
10557 vty_out(vty, "Estimated round trip time: %d ms\n",
10558 p->rtt);
10559 if (p->t_start)
10560 vty_out(vty, "Next start timer due in %ld seconds\n",
10561 thread_timer_remain_second(p->t_start));
10562 if (p->t_connect)
10563 vty_out(vty, "Next connect timer due in %ld seconds\n",
10564 thread_timer_remain_second(p->t_connect));
10565 if (p->t_routeadv)
10566 vty_out(vty,
10567 "MRAI (interval %u) timer expires in %ld seconds\n",
10568 p->v_routeadv,
10569 thread_timer_remain_second(p->t_routeadv));
10570 if (p->password)
10571 vty_out(vty, "Peer Authentication Enabled\n");
10572
10573 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10574 p->t_read ? "on" : "off",
10575 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10576 ? "on"
10577 : "off");
d62a17ae 10578 }
10579
10580 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10581 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10582 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10583
10584 if (!use_json)
10585 vty_out(vty, "\n");
10586
10587 /* BFD information. */
10588 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10589
10590 if (use_json) {
10591 if (p->conf_if) /* Configured interface name. */
10592 json_object_object_add(json, p->conf_if, json_neigh);
10593 else /* Configured IP address. */
10594 json_object_object_add(json, p->host, json_neigh);
10595 }
10596}
10597
10598static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10599 enum show_type type, union sockunion *su,
d7c0a89a 10600 const char *conf_if, uint8_t use_json,
d62a17ae 10601 json_object *json)
10602{
10603 struct listnode *node, *nnode;
10604 struct peer *peer;
10605 int find = 0;
10606
10607 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10608 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10609 continue;
10610
10611 switch (type) {
10612 case show_all:
10613 bgp_show_peer(vty, peer, use_json, json);
10614 break;
10615 case show_peer:
10616 if (conf_if) {
10617 if ((peer->conf_if
10618 && !strcmp(peer->conf_if, conf_if))
10619 || (peer->hostname
10620 && !strcmp(peer->hostname, conf_if))) {
10621 find = 1;
10622 bgp_show_peer(vty, peer, use_json,
10623 json);
10624 }
10625 } else {
10626 if (sockunion_same(&peer->su, su)) {
10627 find = 1;
10628 bgp_show_peer(vty, peer, use_json,
10629 json);
10630 }
10631 }
10632 break;
10633 }
10634 }
10635
10636 if (type == show_peer && !find) {
10637 if (use_json)
10638 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10639 else
10640 vty_out(vty, "%% No such neighbor\n");
10641 }
10642
10643 if (use_json) {
996c9314
LB
10644 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10645 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10646 json_object_free(json);
10647 } else {
10648 vty_out(vty, "\n");
10649 }
10650
10651 return CMD_SUCCESS;
10652}
10653
10654static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10655 enum show_type type,
10656 const char *ip_str,
d7c0a89a 10657 uint8_t use_json)
d62a17ae 10658{
0291c246
MK
10659 struct listnode *node, *nnode;
10660 struct bgp *bgp;
71aedaa3 10661 union sockunion su;
0291c246 10662 json_object *json = NULL;
71aedaa3 10663 int ret, is_first = 1;
d62a17ae 10664
10665 if (use_json)
10666 vty_out(vty, "{\n");
10667
10668 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10669 if (use_json) {
10670 if (!(json = json_object_new_object())) {
10671 zlog_err(
10672 "Unable to allocate memory for JSON object");
10673 vty_out(vty,
10674 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10675 return;
10676 }
10677
10678 json_object_int_add(json, "vrfId",
10679 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10680 ? -1
10681 : (int64_t)bgp->vrf_id);
d62a17ae 10682 json_object_string_add(
10683 json, "vrfName",
10684 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10685 ? "Default"
10686 : bgp->name);
10687
10688 if (!is_first)
10689 vty_out(vty, ",\n");
10690 else
10691 is_first = 0;
10692
10693 vty_out(vty, "\"%s\":",
10694 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10695 ? "Default"
10696 : bgp->name);
10697 } else {
10698 vty_out(vty, "\nInstance %s:\n",
10699 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10700 ? "Default"
10701 : bgp->name);
10702 }
71aedaa3
DS
10703
10704 if (type == show_peer) {
10705 ret = str2sockunion(ip_str, &su);
10706 if (ret < 0)
10707 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10708 use_json, json);
10709 else
10710 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10711 use_json, json);
10712 } else {
10713 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10714 use_json, json);
10715 }
d62a17ae 10716 }
10717
10718 if (use_json)
10719 vty_out(vty, "}\n");
10720}
10721
10722static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10723 enum show_type type, const char *ip_str,
d7c0a89a 10724 uint8_t use_json)
d62a17ae 10725{
10726 int ret;
10727 struct bgp *bgp;
10728 union sockunion su;
10729 json_object *json = NULL;
10730
10731 if (name) {
10732 if (strmatch(name, "all")) {
71aedaa3
DS
10733 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10734 use_json);
d62a17ae 10735 return CMD_SUCCESS;
10736 } else {
10737 bgp = bgp_lookup_by_name(name);
10738 if (!bgp) {
10739 if (use_json) {
10740 json = json_object_new_object();
10741 json_object_boolean_true_add(
10742 json, "bgpNoSuchInstance");
10743 vty_out(vty, "%s\n",
10744 json_object_to_json_string_ext(
10745 json,
10746 JSON_C_TO_STRING_PRETTY));
10747 json_object_free(json);
10748 } else
10749 vty_out(vty,
10750 "%% No such BGP instance exist\n");
10751
10752 return CMD_WARNING;
10753 }
10754 }
10755 } else {
10756 bgp = bgp_get_default();
10757 }
10758
10759 if (bgp) {
10760 json = json_object_new_object();
10761 if (ip_str) {
10762 ret = str2sockunion(ip_str, &su);
10763 if (ret < 0)
10764 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10765 use_json, json);
10766 else
10767 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10768 use_json, json);
10769 } else {
10770 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10771 json);
10772 }
10773 json_object_free(json);
10774 }
10775
10776 return CMD_SUCCESS;
4fb25c53
DW
10777}
10778
716b2d8a 10779/* "show [ip] bgp neighbors" commands. */
718e3744 10780DEFUN (show_ip_bgp_neighbors,
10781 show_ip_bgp_neighbors_cmd,
24345e82 10782 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 10783 SHOW_STR
10784 IP_STR
10785 BGP_STR
f2a8972b 10786 BGP_INSTANCE_HELP_STR
8c3deaae
QY
10787 "Address Family\n"
10788 "Address Family\n"
718e3744 10789 "Detailed information on TCP and BGP neighbor connections\n"
10790 "Neighbor to display information about\n"
a80beece 10791 "Neighbor to display information about\n"
91d37724 10792 "Neighbor on BGP configured interface\n"
9973d184 10793 JSON_STR)
718e3744 10794{
d62a17ae 10795 char *vrf = NULL;
10796 char *sh_arg = NULL;
10797 enum show_type sh_type;
718e3744 10798
d7c0a89a 10799 uint8_t uj = use_json(argc, argv);
718e3744 10800
d62a17ae 10801 int idx = 0;
718e3744 10802
d62a17ae 10803 if (argv_find(argv, argc, "view", &idx)
10804 || argv_find(argv, argc, "vrf", &idx))
10805 vrf = argv[idx + 1]->arg;
718e3744 10806
d62a17ae 10807 idx++;
10808 if (argv_find(argv, argc, "A.B.C.D", &idx)
10809 || argv_find(argv, argc, "X:X::X:X", &idx)
10810 || argv_find(argv, argc, "WORD", &idx)) {
10811 sh_type = show_peer;
10812 sh_arg = argv[idx]->arg;
10813 } else
10814 sh_type = show_all;
856ca177 10815
d62a17ae 10816 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10817}
10818
716b2d8a 10819/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10820 paths' and `show ip mbgp paths'. Those functions results are the
10821 same.*/
f412b39a 10822DEFUN (show_ip_bgp_paths,
718e3744 10823 show_ip_bgp_paths_cmd,
46f296b4 10824 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10825 SHOW_STR
10826 IP_STR
10827 BGP_STR
46f296b4 10828 BGP_SAFI_HELP_STR
718e3744 10829 "Path information\n")
10830{
d62a17ae 10831 vty_out(vty, "Address Refcnt Path\n");
10832 aspath_print_all_vty(vty);
10833 return CMD_SUCCESS;
718e3744 10834}
10835
718e3744 10836#include "hash.h"
10837
d62a17ae 10838static void community_show_all_iterator(struct hash_backet *backet,
10839 struct vty *vty)
718e3744 10840{
d62a17ae 10841 struct community *com;
718e3744 10842
d62a17ae 10843 com = (struct community *)backet->data;
3f65c5b1 10844 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 10845 community_str(com, false));
718e3744 10846}
10847
10848/* Show BGP's community internal data. */
f412b39a 10849DEFUN (show_ip_bgp_community_info,
718e3744 10850 show_ip_bgp_community_info_cmd,
bec37ba5 10851 "show [ip] bgp community-info",
718e3744 10852 SHOW_STR
10853 IP_STR
10854 BGP_STR
10855 "List all bgp community information\n")
10856{
d62a17ae 10857 vty_out(vty, "Address Refcnt Community\n");
718e3744 10858
d62a17ae 10859 hash_iterate(community_hash(),
10860 (void (*)(struct hash_backet *,
10861 void *))community_show_all_iterator,
10862 vty);
718e3744 10863
d62a17ae 10864 return CMD_SUCCESS;
718e3744 10865}
10866
d62a17ae 10867static void lcommunity_show_all_iterator(struct hash_backet *backet,
10868 struct vty *vty)
57d187bc 10869{
d62a17ae 10870 struct lcommunity *lcom;
57d187bc 10871
d62a17ae 10872 lcom = (struct lcommunity *)backet->data;
3f65c5b1 10873 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
d62a17ae 10874 lcommunity_str(lcom));
57d187bc
JS
10875}
10876
10877/* Show BGP's community internal data. */
10878DEFUN (show_ip_bgp_lcommunity_info,
10879 show_ip_bgp_lcommunity_info_cmd,
10880 "show ip bgp large-community-info",
10881 SHOW_STR
10882 IP_STR
10883 BGP_STR
10884 "List all bgp large-community information\n")
10885{
d62a17ae 10886 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 10887
d62a17ae 10888 hash_iterate(lcommunity_hash(),
10889 (void (*)(struct hash_backet *,
10890 void *))lcommunity_show_all_iterator,
10891 vty);
57d187bc 10892
d62a17ae 10893 return CMD_SUCCESS;
57d187bc
JS
10894}
10895
10896
f412b39a 10897DEFUN (show_ip_bgp_attr_info,
718e3744 10898 show_ip_bgp_attr_info_cmd,
bec37ba5 10899 "show [ip] bgp attribute-info",
718e3744 10900 SHOW_STR
10901 IP_STR
10902 BGP_STR
10903 "List all bgp attribute information\n")
10904{
d62a17ae 10905 attr_show_all(vty);
10906 return CMD_SUCCESS;
718e3744 10907}
6b0655a2 10908
53089bec 10909static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10910 afi_t afi, safi_t safi)
10911{
10912 struct bgp *bgp;
10913 struct listnode *node;
10914 char *vname;
10915 char buf1[INET6_ADDRSTRLEN];
10916 char *ecom_str;
10917 vpn_policy_direction_t dir;
10918
10919 if (name) {
10920 bgp = bgp_lookup_by_name(name);
10921 if (!bgp) {
10922 vty_out(vty, "%% No such BGP instance exist\n");
10923 return CMD_WARNING;
10924 }
10925 } else {
10926 bgp = bgp_get_default();
10927 if (!bgp) {
020a3f60
DS
10928 vty_out(vty,
10929 "%% Default BGP instance does not exist\n");
53089bec 10930 return CMD_WARNING;
10931 }
10932 }
10933
10934 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10935 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
020a3f60
DS
10936 vty_out(vty,
10937 "This VRF is not importing %s routes from any other VRF\n",
53089bec 10938 afi_safi_print(afi, safi));
10939 } else {
020a3f60
DS
10940 vty_out(vty,
10941 "This VRF is importing %s routes from the following VRFs:\n",
53089bec 10942 afi_safi_print(afi, safi));
10943 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
10944 vname)) {
10945 vty_out(vty, " %s\n", vname);
10946 }
10947 dir = BGP_VPN_POLICY_DIR_FROMVPN;
10948 ecom_str = ecommunity_ecom2str(
10949 bgp->vpn_policy[afi].rtlist[dir],
10950 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
10951 vty_out(vty, "Import RT(s): %s\n", ecom_str);
10952 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
10953 }
10954
10955 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10956 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
020a3f60
DS
10957 vty_out(vty,
10958 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 10959 afi_safi_print(afi, safi));
10960 } else {
020a3f60
DS
10961 vty_out(vty,
10962 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 10963 afi_safi_print(afi, safi));
10964 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
10965 vname)) {
10966 vty_out(vty, " %s\n", vname);
10967 }
10968 vty_out(vty, "RD: %s\n",
10969 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
10970 buf1, RD_ADDRSTRLEN));
10971 dir = BGP_VPN_POLICY_DIR_TOVPN;
10972 ecom_str = ecommunity_ecom2str(
10973 bgp->vpn_policy[afi].rtlist[dir],
10974 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
10975 vty_out(vty, "Emport RT: %s\n", ecom_str);
10976 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
10977 }
10978
10979 return CMD_SUCCESS;
10980}
10981
10982/* "show [ip] bgp route-leak" command. */
10983DEFUN (show_ip_bgp_route_leak,
10984 show_ip_bgp_route_leak_cmd,
10985 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
10986 SHOW_STR
10987 IP_STR
10988 BGP_STR
10989 BGP_INSTANCE_HELP_STR
10990 BGP_AFI_HELP_STR
10991 BGP_SAFI_HELP_STR
10992 "Route leaking information\n")
10993{
10994 char *vrf = NULL;
10995 afi_t afi = AFI_MAX;
10996 safi_t safi = SAFI_MAX;
10997
10998 int idx = 0;
10999
11000 /* show [ip] bgp */
11001 if (argv_find(argv, argc, "ip", &idx)) {
11002 afi = AFI_IP;
11003 safi = SAFI_UNICAST;
11004 }
11005 /* [vrf VIEWVRFNAME] */
11006 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11007 vty_out(vty,
11008 "%% This command is not applicable to BGP views\n");
53089bec 11009 return CMD_WARNING;
11010 }
11011
11012 if (argv_find(argv, argc, "vrf", &idx))
11013 vrf = argv[++idx]->arg;
11014 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11015 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11016 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11017 }
11018
11019 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11020 vty_out(vty,
11021 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11022 return CMD_WARNING;
11023 }
11024
11025 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11026}
11027
d62a17ae 11028static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11029 safi_t safi)
f186de26 11030{
d62a17ae 11031 struct listnode *node, *nnode;
11032 struct bgp *bgp;
f186de26 11033
d62a17ae 11034 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11035 vty_out(vty, "\nInstance %s:\n",
11036 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11037 ? "Default"
11038 : bgp->name);
11039 update_group_show(bgp, afi, safi, vty, 0);
11040 }
f186de26 11041}
11042
d62a17ae 11043static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11044 int safi, uint64_t subgrp_id)
4fb25c53 11045{
d62a17ae 11046 struct bgp *bgp;
4fb25c53 11047
d62a17ae 11048 if (name) {
11049 if (strmatch(name, "all")) {
11050 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11051 return CMD_SUCCESS;
11052 } else {
11053 bgp = bgp_lookup_by_name(name);
11054 }
11055 } else {
11056 bgp = bgp_get_default();
11057 }
4fb25c53 11058
d62a17ae 11059 if (bgp)
11060 update_group_show(bgp, afi, safi, vty, subgrp_id);
11061 return CMD_SUCCESS;
4fb25c53
DW
11062}
11063
8fe8a7f6
DS
11064DEFUN (show_ip_bgp_updgrps,
11065 show_ip_bgp_updgrps_cmd,
c1a44e43 11066 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11067 SHOW_STR
11068 IP_STR
11069 BGP_STR
11070 BGP_INSTANCE_HELP_STR
c9e571b4 11071 BGP_AFI_HELP_STR
9bedbb1e 11072 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11073 "Detailed info about dynamic update groups\n"
11074 "Specific subgroup to display detailed info for\n")
8386ac43 11075{
d62a17ae 11076 char *vrf = NULL;
11077 afi_t afi = AFI_IP6;
11078 safi_t safi = SAFI_UNICAST;
11079 uint64_t subgrp_id = 0;
11080
11081 int idx = 0;
11082
11083 /* show [ip] bgp */
11084 if (argv_find(argv, argc, "ip", &idx))
11085 afi = AFI_IP;
11086 /* [<view|vrf> VIEWVRFNAME] */
11087 if (argv_find(argv, argc, "view", &idx)
11088 || argv_find(argv, argc, "vrf", &idx))
11089 vrf = argv[++idx]->arg;
11090 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11091 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11092 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11093 }
5bf15956 11094
d62a17ae 11095 /* get subgroup id, if provided */
11096 idx = argc - 1;
11097 if (argv[idx]->type == VARIABLE_TKN)
11098 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11099
d62a17ae 11100 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11101}
11102
f186de26 11103DEFUN (show_bgp_instance_all_ipv6_updgrps,
11104 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11105 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11106 SHOW_STR
716b2d8a 11107 IP_STR
f186de26 11108 BGP_STR
11109 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11110 "Detailed info about dynamic update groups\n")
f186de26 11111{
d62a17ae 11112 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11113 return CMD_SUCCESS;
f186de26 11114}
11115
5bf15956
DW
11116DEFUN (show_bgp_updgrps_stats,
11117 show_bgp_updgrps_stats_cmd,
716b2d8a 11118 "show [ip] bgp update-groups statistics",
3f9c7369 11119 SHOW_STR
716b2d8a 11120 IP_STR
3f9c7369 11121 BGP_STR
0c7b1b01 11122 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11123 "Statistics\n")
11124{
d62a17ae 11125 struct bgp *bgp;
3f9c7369 11126
d62a17ae 11127 bgp = bgp_get_default();
11128 if (bgp)
11129 update_group_show_stats(bgp, vty);
3f9c7369 11130
d62a17ae 11131 return CMD_SUCCESS;
3f9c7369
DS
11132}
11133
8386ac43 11134DEFUN (show_bgp_instance_updgrps_stats,
11135 show_bgp_instance_updgrps_stats_cmd,
18c57037 11136 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11137 SHOW_STR
716b2d8a 11138 IP_STR
8386ac43 11139 BGP_STR
11140 BGP_INSTANCE_HELP_STR
0c7b1b01 11141 "Detailed info about dynamic update groups\n"
8386ac43 11142 "Statistics\n")
11143{
d62a17ae 11144 int idx_word = 3;
11145 struct bgp *bgp;
8386ac43 11146
d62a17ae 11147 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11148 if (bgp)
11149 update_group_show_stats(bgp, vty);
8386ac43 11150
d62a17ae 11151 return CMD_SUCCESS;
8386ac43 11152}
11153
d62a17ae 11154static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11155 afi_t afi, safi_t safi,
11156 const char *what, uint64_t subgrp_id)
3f9c7369 11157{
d62a17ae 11158 struct bgp *bgp;
8386ac43 11159
d62a17ae 11160 if (name)
11161 bgp = bgp_lookup_by_name(name);
11162 else
11163 bgp = bgp_get_default();
8386ac43 11164
d62a17ae 11165 if (bgp) {
11166 if (!strcmp(what, "advertise-queue"))
11167 update_group_show_adj_queue(bgp, afi, safi, vty,
11168 subgrp_id);
11169 else if (!strcmp(what, "advertised-routes"))
11170 update_group_show_advertised(bgp, afi, safi, vty,
11171 subgrp_id);
11172 else if (!strcmp(what, "packet-queue"))
11173 update_group_show_packet_queue(bgp, afi, safi, vty,
11174 subgrp_id);
11175 }
3f9c7369
DS
11176}
11177
dc64bdec
QY
11178DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11179 show_ip_bgp_instance_updgrps_adj_s_cmd,
11180 "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",
11181 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11182 BGP_SAFI_HELP_STR
11183 "Detailed info about dynamic update groups\n"
11184 "Specific subgroup to display info for\n"
11185 "Advertisement queue\n"
11186 "Announced routes\n"
11187 "Packet queue\n")
3f9c7369 11188{
dc64bdec
QY
11189 uint64_t subgrp_id = 0;
11190 afi_t afiz;
11191 safi_t safiz;
11192 if (sgid)
11193 subgrp_id = strtoull(sgid, NULL, 10);
11194
11195 if (!ip && !afi)
11196 afiz = AFI_IP6;
11197 if (!ip && afi)
11198 afiz = bgp_vty_afi_from_str(afi);
11199 if (ip && !afi)
11200 afiz = AFI_IP;
11201 if (ip && afi) {
11202 afiz = bgp_vty_afi_from_str(afi);
11203 if (afiz != AFI_IP)
11204 vty_out(vty,
11205 "%% Cannot specify both 'ip' and 'ipv6'\n");
11206 return CMD_WARNING;
11207 }
d62a17ae 11208
dc64bdec 11209 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11210
dc64bdec 11211 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11212 return CMD_SUCCESS;
11213}
11214
d62a17ae 11215static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11216{
11217 struct listnode *node, *nnode;
11218 struct prefix *range;
11219 struct peer *conf;
11220 struct peer *peer;
11221 char buf[PREFIX2STR_BUFFER];
11222 afi_t afi;
11223 safi_t safi;
11224 const char *peer_status;
11225 const char *af_str;
11226 int lr_count;
11227 int dynamic;
11228 int af_cfgd;
11229
11230 conf = group->conf;
11231
11232 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11233 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11234 conf->as);
11235 } else if (conf->as_type == AS_INTERNAL) {
11236 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11237 group->bgp->as);
11238 } else {
11239 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11240 }
f14e6fdb 11241
d62a17ae 11242 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11243 vty_out(vty, " Peer-group type is internal\n");
11244 else
11245 vty_out(vty, " Peer-group type is external\n");
11246
11247 /* Display AFs configured. */
11248 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11249 FOREACH_AFI_SAFI (afi, safi) {
11250 if (conf->afc[afi][safi]) {
11251 af_cfgd = 1;
11252 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11253 }
05c7a1cc 11254 }
d62a17ae 11255 if (!af_cfgd)
11256 vty_out(vty, " none\n");
11257 else
11258 vty_out(vty, "\n");
11259
11260 /* Display listen ranges (for dynamic neighbors), if any */
11261 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11262 if (afi == AFI_IP)
11263 af_str = "IPv4";
11264 else if (afi == AFI_IP6)
11265 af_str = "IPv6";
11266 else
11267 af_str = "???";
11268 lr_count = listcount(group->listen_range[afi]);
11269 if (lr_count) {
11270 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11271 af_str);
11272
11273
11274 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11275 nnode, range)) {
11276 prefix2str(range, buf, sizeof(buf));
11277 vty_out(vty, " %s\n", buf);
11278 }
11279 }
11280 }
f14e6fdb 11281
d62a17ae 11282 /* Display group members and their status */
11283 if (listcount(group->peer)) {
11284 vty_out(vty, " Peer-group members:\n");
11285 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11286 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11287 peer_status = "Idle (Admin)";
11288 else if (CHECK_FLAG(peer->sflags,
11289 PEER_STATUS_PREFIX_OVERFLOW))
11290 peer_status = "Idle (PfxCt)";
11291 else
11292 peer_status = lookup_msg(bgp_status_msg,
11293 peer->status, NULL);
11294
11295 dynamic = peer_dynamic_neighbor(peer);
11296 vty_out(vty, " %s %s %s \n", peer->host,
11297 dynamic ? "(dynamic)" : "", peer_status);
11298 }
11299 }
f14e6fdb 11300
d62a17ae 11301 return CMD_SUCCESS;
11302}
11303
ff9959b0
QY
11304static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11305 const char *group_name)
d62a17ae 11306{
ff9959b0 11307 struct bgp *bgp;
d62a17ae 11308 struct listnode *node, *nnode;
11309 struct peer_group *group;
ff9959b0
QY
11310 bool found = false;
11311
11312 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11313
11314 if (!bgp) {
11315 vty_out(vty, "%% No such BGP instance exists\n");
11316 return CMD_WARNING;
11317 }
d62a17ae 11318
11319 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11320 if (group_name) {
11321 if (strmatch(group->name, group_name)) {
d62a17ae 11322 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11323 found = true;
11324 break;
d62a17ae 11325 }
ff9959b0
QY
11326 } else {
11327 bgp_show_one_peer_group(vty, group);
d62a17ae 11328 }
f14e6fdb 11329 }
f14e6fdb 11330
ff9959b0 11331 if (group_name && !found)
d62a17ae 11332 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11333
d62a17ae 11334 return CMD_SUCCESS;
f14e6fdb
DS
11335}
11336
f14e6fdb
DS
11337DEFUN (show_ip_bgp_peer_groups,
11338 show_ip_bgp_peer_groups_cmd,
18c57037 11339 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11340 SHOW_STR
11341 IP_STR
11342 BGP_STR
8386ac43 11343 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11344 "Detailed information on BGP peer groups\n"
11345 "Peer group name\n")
f14e6fdb 11346{
d62a17ae 11347 char *vrf, *pg;
11348 vrf = pg = NULL;
11349 int idx = 0;
f14e6fdb 11350
a4d82a8a
PZ
11351 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11352 : NULL;
d62a17ae 11353 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11354
ff9959b0 11355 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11356}
3f9c7369 11357
d6e3c605 11358
718e3744 11359/* Redistribute VTY commands. */
11360
718e3744 11361DEFUN (bgp_redistribute_ipv4,
11362 bgp_redistribute_ipv4_cmd,
40d1cbfb 11363 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11364 "Redistribute information from another routing protocol\n"
ab0181ee 11365 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11366{
d62a17ae 11367 VTY_DECLVAR_CONTEXT(bgp, bgp);
11368 int idx_protocol = 1;
11369 int type;
718e3744 11370
d62a17ae 11371 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11372 if (type < 0) {
11373 vty_out(vty, "%% Invalid route type\n");
11374 return CMD_WARNING_CONFIG_FAILED;
11375 }
7f323236 11376
d62a17ae 11377 bgp_redist_add(bgp, AFI_IP, type, 0);
11378 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11379}
11380
d62a17ae 11381ALIAS_HIDDEN(
11382 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11383 "redistribute " FRR_IP_REDIST_STR_BGPD,
11384 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11385
718e3744 11386DEFUN (bgp_redistribute_ipv4_rmap,
11387 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11388 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11389 "Redistribute information from another routing protocol\n"
ab0181ee 11390 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11391 "Route map reference\n"
11392 "Pointer to route-map entries\n")
11393{
d62a17ae 11394 VTY_DECLVAR_CONTEXT(bgp, bgp);
11395 int idx_protocol = 1;
11396 int idx_word = 3;
11397 int type;
11398 struct bgp_redist *red;
718e3744 11399
d62a17ae 11400 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11401 if (type < 0) {
11402 vty_out(vty, "%% Invalid route type\n");
11403 return CMD_WARNING_CONFIG_FAILED;
11404 }
718e3744 11405
d62a17ae 11406 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11407 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11408 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11409}
11410
d62a17ae 11411ALIAS_HIDDEN(
11412 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11413 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11414 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11415 "Route map reference\n"
11416 "Pointer to route-map entries\n")
596c17ba 11417
718e3744 11418DEFUN (bgp_redistribute_ipv4_metric,
11419 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11420 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11421 "Redistribute information from another routing protocol\n"
ab0181ee 11422 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11423 "Metric for redistributed routes\n"
11424 "Default metric\n")
11425{
d62a17ae 11426 VTY_DECLVAR_CONTEXT(bgp, bgp);
11427 int idx_protocol = 1;
11428 int idx_number = 3;
11429 int type;
d7c0a89a 11430 uint32_t metric;
d62a17ae 11431 struct bgp_redist *red;
11432
11433 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11434 if (type < 0) {
11435 vty_out(vty, "%% Invalid route type\n");
11436 return CMD_WARNING_CONFIG_FAILED;
11437 }
11438 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11439
11440 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11441 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11442 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11443}
11444
11445ALIAS_HIDDEN(
11446 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11447 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11448 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11449 "Metric for redistributed routes\n"
11450 "Default metric\n")
596c17ba 11451
718e3744 11452DEFUN (bgp_redistribute_ipv4_rmap_metric,
11453 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11454 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11455 "Redistribute information from another routing protocol\n"
ab0181ee 11456 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11457 "Route map reference\n"
11458 "Pointer to route-map entries\n"
11459 "Metric for redistributed routes\n"
11460 "Default metric\n")
11461{
d62a17ae 11462 VTY_DECLVAR_CONTEXT(bgp, bgp);
11463 int idx_protocol = 1;
11464 int idx_word = 3;
11465 int idx_number = 5;
11466 int type;
d7c0a89a 11467 uint32_t metric;
d62a17ae 11468 struct bgp_redist *red;
11469
11470 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11471 if (type < 0) {
11472 vty_out(vty, "%% Invalid route type\n");
11473 return CMD_WARNING_CONFIG_FAILED;
11474 }
11475 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11476
11477 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11478 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11479 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11480 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11481}
11482
11483ALIAS_HIDDEN(
11484 bgp_redistribute_ipv4_rmap_metric,
11485 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11486 "redistribute " FRR_IP_REDIST_STR_BGPD
11487 " route-map WORD metric (0-4294967295)",
11488 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11489 "Route map reference\n"
11490 "Pointer to route-map entries\n"
11491 "Metric for redistributed routes\n"
11492 "Default metric\n")
596c17ba 11493
718e3744 11494DEFUN (bgp_redistribute_ipv4_metric_rmap,
11495 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11496 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11497 "Redistribute information from another routing protocol\n"
ab0181ee 11498 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11499 "Metric for redistributed routes\n"
11500 "Default metric\n"
11501 "Route map reference\n"
11502 "Pointer to route-map entries\n")
11503{
d62a17ae 11504 VTY_DECLVAR_CONTEXT(bgp, bgp);
11505 int idx_protocol = 1;
11506 int idx_number = 3;
11507 int idx_word = 5;
11508 int type;
d7c0a89a 11509 uint32_t metric;
d62a17ae 11510 struct bgp_redist *red;
11511
11512 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11513 if (type < 0) {
11514 vty_out(vty, "%% Invalid route type\n");
11515 return CMD_WARNING_CONFIG_FAILED;
11516 }
11517 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11518
11519 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11520 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11521 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11522 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11523}
11524
11525ALIAS_HIDDEN(
11526 bgp_redistribute_ipv4_metric_rmap,
11527 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11528 "redistribute " FRR_IP_REDIST_STR_BGPD
11529 " metric (0-4294967295) route-map WORD",
11530 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11531 "Metric for redistributed routes\n"
11532 "Default metric\n"
11533 "Route map reference\n"
11534 "Pointer to route-map entries\n")
596c17ba 11535
7c8ff89e
DS
11536DEFUN (bgp_redistribute_ipv4_ospf,
11537 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11538 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11539 "Redistribute information from another routing protocol\n"
11540 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11541 "Non-main Kernel Routing Table\n"
11542 "Instance ID/Table ID\n")
7c8ff89e 11543{
d62a17ae 11544 VTY_DECLVAR_CONTEXT(bgp, bgp);
11545 int idx_ospf_table = 1;
11546 int idx_number = 2;
d7c0a89a
QY
11547 unsigned short instance;
11548 unsigned short protocol;
7c8ff89e 11549
d62a17ae 11550 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11551
d62a17ae 11552 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11553 protocol = ZEBRA_ROUTE_OSPF;
11554 else
11555 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11556
d62a17ae 11557 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11558 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
11559}
11560
d62a17ae 11561ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11562 "redistribute <ospf|table> (1-65535)",
11563 "Redistribute information from another routing protocol\n"
11564 "Open Shortest Path First (OSPFv2)\n"
11565 "Non-main Kernel Routing Table\n"
11566 "Instance ID/Table ID\n")
596c17ba 11567
7c8ff89e
DS
11568DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11569 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11570 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11571 "Redistribute information from another routing protocol\n"
11572 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11573 "Non-main Kernel Routing Table\n"
11574 "Instance ID/Table ID\n"
7c8ff89e
DS
11575 "Route map reference\n"
11576 "Pointer to route-map entries\n")
11577{
d62a17ae 11578 VTY_DECLVAR_CONTEXT(bgp, bgp);
11579 int idx_ospf_table = 1;
11580 int idx_number = 2;
11581 int idx_word = 4;
11582 struct bgp_redist *red;
d7c0a89a 11583 unsigned short instance;
d62a17ae 11584 int protocol;
11585
11586 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11587 protocol = ZEBRA_ROUTE_OSPF;
11588 else
11589 protocol = ZEBRA_ROUTE_TABLE;
11590
11591 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11592 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11593 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11594 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11595}
11596
11597ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11598 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11599 "redistribute <ospf|table> (1-65535) route-map WORD",
11600 "Redistribute information from another routing protocol\n"
11601 "Open Shortest Path First (OSPFv2)\n"
11602 "Non-main Kernel Routing Table\n"
11603 "Instance ID/Table ID\n"
11604 "Route map reference\n"
11605 "Pointer to route-map entries\n")
596c17ba 11606
7c8ff89e
DS
11607DEFUN (bgp_redistribute_ipv4_ospf_metric,
11608 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 11609 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
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
DS
11614 "Metric for redistributed routes\n"
11615 "Default metric\n")
11616{
d62a17ae 11617 VTY_DECLVAR_CONTEXT(bgp, bgp);
11618 int idx_ospf_table = 1;
11619 int idx_number = 2;
11620 int idx_number_2 = 4;
d7c0a89a 11621 uint32_t metric;
d62a17ae 11622 struct bgp_redist *red;
d7c0a89a 11623 unsigned short instance;
d62a17ae 11624 int protocol;
11625
11626 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11627 protocol = ZEBRA_ROUTE_OSPF;
11628 else
11629 protocol = ZEBRA_ROUTE_TABLE;
11630
11631 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11632 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11633
11634 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11635 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11636 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11637}
11638
11639ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11640 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11641 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11642 "Redistribute information from another routing protocol\n"
11643 "Open Shortest Path First (OSPFv2)\n"
11644 "Non-main Kernel Routing Table\n"
11645 "Instance ID/Table ID\n"
11646 "Metric for redistributed routes\n"
11647 "Default metric\n")
596c17ba 11648
7c8ff89e
DS
11649DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11650 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 11651 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
11652 "Redistribute information from another routing protocol\n"
11653 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11654 "Non-main Kernel Routing Table\n"
11655 "Instance ID/Table ID\n"
7c8ff89e
DS
11656 "Route map reference\n"
11657 "Pointer to route-map entries\n"
11658 "Metric for redistributed routes\n"
11659 "Default metric\n")
11660{
d62a17ae 11661 VTY_DECLVAR_CONTEXT(bgp, bgp);
11662 int idx_ospf_table = 1;
11663 int idx_number = 2;
11664 int idx_word = 4;
11665 int idx_number_2 = 6;
d7c0a89a 11666 uint32_t metric;
d62a17ae 11667 struct bgp_redist *red;
d7c0a89a 11668 unsigned short instance;
d62a17ae 11669 int protocol;
11670
11671 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11672 protocol = ZEBRA_ROUTE_OSPF;
11673 else
11674 protocol = ZEBRA_ROUTE_TABLE;
11675
11676 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11677 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11678
11679 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11680 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11681 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11682 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11683}
11684
11685ALIAS_HIDDEN(
11686 bgp_redistribute_ipv4_ospf_rmap_metric,
11687 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11688 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11689 "Redistribute information from another routing protocol\n"
11690 "Open Shortest Path First (OSPFv2)\n"
11691 "Non-main Kernel Routing Table\n"
11692 "Instance ID/Table ID\n"
11693 "Route map reference\n"
11694 "Pointer to route-map entries\n"
11695 "Metric for redistributed routes\n"
11696 "Default metric\n")
596c17ba 11697
7c8ff89e
DS
11698DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11699 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 11700 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
11701 "Redistribute information from another routing protocol\n"
11702 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11703 "Non-main Kernel Routing Table\n"
11704 "Instance ID/Table ID\n"
7c8ff89e
DS
11705 "Metric for redistributed routes\n"
11706 "Default metric\n"
11707 "Route map reference\n"
11708 "Pointer to route-map entries\n")
11709{
d62a17ae 11710 VTY_DECLVAR_CONTEXT(bgp, bgp);
11711 int idx_ospf_table = 1;
11712 int idx_number = 2;
11713 int idx_number_2 = 4;
11714 int idx_word = 6;
d7c0a89a 11715 uint32_t metric;
d62a17ae 11716 struct bgp_redist *red;
d7c0a89a 11717 unsigned short instance;
d62a17ae 11718 int protocol;
11719
11720 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11721 protocol = ZEBRA_ROUTE_OSPF;
11722 else
11723 protocol = ZEBRA_ROUTE_TABLE;
11724
11725 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11726 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11727
11728 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11729 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11730 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11731 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11732}
11733
11734ALIAS_HIDDEN(
11735 bgp_redistribute_ipv4_ospf_metric_rmap,
11736 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11737 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11738 "Redistribute information from another routing protocol\n"
11739 "Open Shortest Path First (OSPFv2)\n"
11740 "Non-main Kernel Routing Table\n"
11741 "Instance ID/Table ID\n"
11742 "Metric for redistributed routes\n"
11743 "Default metric\n"
11744 "Route map reference\n"
11745 "Pointer to route-map entries\n")
596c17ba 11746
7c8ff89e
DS
11747DEFUN (no_bgp_redistribute_ipv4_ospf,
11748 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 11749 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
11750 NO_STR
11751 "Redistribute information from another routing protocol\n"
11752 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 11753 "Non-main Kernel Routing Table\n"
31500417
DW
11754 "Instance ID/Table ID\n"
11755 "Metric for redistributed routes\n"
11756 "Default metric\n"
11757 "Route map reference\n"
11758 "Pointer to route-map entries\n")
7c8ff89e 11759{
d62a17ae 11760 VTY_DECLVAR_CONTEXT(bgp, bgp);
11761 int idx_ospf_table = 2;
11762 int idx_number = 3;
d7c0a89a 11763 unsigned short instance;
d62a17ae 11764 int protocol;
11765
11766 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11767 protocol = ZEBRA_ROUTE_OSPF;
11768 else
11769 protocol = ZEBRA_ROUTE_TABLE;
11770
11771 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11772 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11773}
11774
11775ALIAS_HIDDEN(
11776 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11777 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11778 NO_STR
11779 "Redistribute information from another routing protocol\n"
11780 "Open Shortest Path First (OSPFv2)\n"
11781 "Non-main Kernel Routing Table\n"
11782 "Instance ID/Table ID\n"
11783 "Metric for redistributed routes\n"
11784 "Default metric\n"
11785 "Route map reference\n"
11786 "Pointer to route-map entries\n")
596c17ba 11787
718e3744 11788DEFUN (no_bgp_redistribute_ipv4,
11789 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 11790 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11791 NO_STR
11792 "Redistribute information from another routing protocol\n"
3b14d86e 11793 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
11794 "Metric for redistributed routes\n"
11795 "Default metric\n"
11796 "Route map reference\n"
11797 "Pointer to route-map entries\n")
718e3744 11798{
d62a17ae 11799 VTY_DECLVAR_CONTEXT(bgp, bgp);
11800 int idx_protocol = 2;
11801 int type;
11802
11803 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11804 if (type < 0) {
11805 vty_out(vty, "%% Invalid route type\n");
11806 return CMD_WARNING_CONFIG_FAILED;
11807 }
11808 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11809}
11810
11811ALIAS_HIDDEN(
11812 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11813 "no redistribute " FRR_IP_REDIST_STR_BGPD
11814 " [metric (0-4294967295)] [route-map WORD]",
11815 NO_STR
11816 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11817 "Metric for redistributed routes\n"
11818 "Default metric\n"
11819 "Route map reference\n"
11820 "Pointer to route-map entries\n")
596c17ba 11821
718e3744 11822DEFUN (bgp_redistribute_ipv6,
11823 bgp_redistribute_ipv6_cmd,
40d1cbfb 11824 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11825 "Redistribute information from another routing protocol\n"
ab0181ee 11826 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11827{
d62a17ae 11828 VTY_DECLVAR_CONTEXT(bgp, bgp);
11829 int idx_protocol = 1;
11830 int type;
718e3744 11831
d62a17ae 11832 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11833 if (type < 0) {
11834 vty_out(vty, "%% Invalid route type\n");
11835 return CMD_WARNING_CONFIG_FAILED;
11836 }
718e3744 11837
d62a17ae 11838 bgp_redist_add(bgp, AFI_IP6, type, 0);
11839 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11840}
11841
11842DEFUN (bgp_redistribute_ipv6_rmap,
11843 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11844 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11845 "Redistribute information from another routing protocol\n"
ab0181ee 11846 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11847 "Route map reference\n"
11848 "Pointer to route-map entries\n")
11849{
d62a17ae 11850 VTY_DECLVAR_CONTEXT(bgp, bgp);
11851 int idx_protocol = 1;
11852 int idx_word = 3;
11853 int type;
11854 struct bgp_redist *red;
718e3744 11855
d62a17ae 11856 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11857 if (type < 0) {
11858 vty_out(vty, "%% Invalid route type\n");
11859 return CMD_WARNING_CONFIG_FAILED;
11860 }
718e3744 11861
d62a17ae 11862 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11863 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11864 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11865}
11866
11867DEFUN (bgp_redistribute_ipv6_metric,
11868 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11869 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11870 "Redistribute information from another routing protocol\n"
ab0181ee 11871 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11872 "Metric for redistributed routes\n"
11873 "Default metric\n")
11874{
d62a17ae 11875 VTY_DECLVAR_CONTEXT(bgp, bgp);
11876 int idx_protocol = 1;
11877 int idx_number = 3;
11878 int type;
d7c0a89a 11879 uint32_t metric;
d62a17ae 11880 struct bgp_redist *red;
11881
11882 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11883 if (type < 0) {
11884 vty_out(vty, "%% Invalid route type\n");
11885 return CMD_WARNING_CONFIG_FAILED;
11886 }
11887 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11888
d62a17ae 11889 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11890 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11891 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11892}
11893
11894DEFUN (bgp_redistribute_ipv6_rmap_metric,
11895 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11896 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11897 "Redistribute information from another routing protocol\n"
ab0181ee 11898 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11899 "Route map reference\n"
11900 "Pointer to route-map entries\n"
11901 "Metric for redistributed routes\n"
11902 "Default metric\n")
11903{
d62a17ae 11904 VTY_DECLVAR_CONTEXT(bgp, bgp);
11905 int idx_protocol = 1;
11906 int idx_word = 3;
11907 int idx_number = 5;
11908 int type;
d7c0a89a 11909 uint32_t metric;
d62a17ae 11910 struct bgp_redist *red;
11911
11912 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11913 if (type < 0) {
11914 vty_out(vty, "%% Invalid route type\n");
11915 return CMD_WARNING_CONFIG_FAILED;
11916 }
11917 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11918
d62a17ae 11919 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11920 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11921 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11922 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11923}
11924
11925DEFUN (bgp_redistribute_ipv6_metric_rmap,
11926 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11927 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11928 "Redistribute information from another routing protocol\n"
ab0181ee 11929 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11930 "Metric for redistributed routes\n"
11931 "Default metric\n"
11932 "Route map reference\n"
11933 "Pointer to route-map entries\n")
11934{
d62a17ae 11935 VTY_DECLVAR_CONTEXT(bgp, bgp);
11936 int idx_protocol = 1;
11937 int idx_number = 3;
11938 int idx_word = 5;
11939 int type;
d7c0a89a 11940 uint32_t metric;
d62a17ae 11941 struct bgp_redist *red;
11942
11943 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11944 if (type < 0) {
11945 vty_out(vty, "%% Invalid route type\n");
11946 return CMD_WARNING_CONFIG_FAILED;
11947 }
11948 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11949
d62a17ae 11950 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11951 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11952 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11953 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11954}
11955
11956DEFUN (no_bgp_redistribute_ipv6,
11957 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 11958 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11959 NO_STR
11960 "Redistribute information from another routing protocol\n"
3b14d86e 11961 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
11962 "Metric for redistributed routes\n"
11963 "Default metric\n"
11964 "Route map reference\n"
11965 "Pointer to route-map entries\n")
718e3744 11966{
d62a17ae 11967 VTY_DECLVAR_CONTEXT(bgp, bgp);
11968 int idx_protocol = 2;
11969 int type;
718e3744 11970
d62a17ae 11971 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11972 if (type < 0) {
11973 vty_out(vty, "%% Invalid route type\n");
11974 return CMD_WARNING_CONFIG_FAILED;
11975 }
718e3744 11976
d62a17ae 11977 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
11978}
11979
2b791107 11980void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 11981 safi_t safi)
d62a17ae 11982{
11983 int i;
11984
11985 /* Unicast redistribution only. */
11986 if (safi != SAFI_UNICAST)
2b791107 11987 return;
d62a17ae 11988
11989 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
11990 /* Redistribute BGP does not make sense. */
11991 if (i != ZEBRA_ROUTE_BGP) {
11992 struct list *red_list;
11993 struct listnode *node;
11994 struct bgp_redist *red;
11995
11996 red_list = bgp->redist[afi][i];
11997 if (!red_list)
11998 continue;
11999
12000 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12001 /* "redistribute" configuration. */
12002 vty_out(vty, " redistribute %s",
12003 zebra_route_string(i));
12004 if (red->instance)
12005 vty_out(vty, " %d", red->instance);
12006 if (red->redist_metric_flag)
12007 vty_out(vty, " metric %u",
12008 red->redist_metric);
12009 if (red->rmap.name)
12010 vty_out(vty, " route-map %s",
12011 red->rmap.name);
12012 vty_out(vty, "\n");
12013 }
12014 }
12015 }
718e3744 12016}
6b0655a2 12017
b9c7bc5a
PZ
12018/* This is part of the address-family block (unicast only) */
12019void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12020 afi_t afi)
12021{
b9c7bc5a 12022 int indent = 2;
ddb5b488 12023
bb4f6190
DS
12024 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12025 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12026 bgp->vpn_policy[afi]
12027 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12028
12a844a5
DS
12029 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12030 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12031 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12032 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12033 return;
12034
e70e9f8e
PZ
12035 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12036 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12037
12038 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12039
12040 } else {
12041 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12042 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12043 bgp->vpn_policy[afi].tovpn_label);
12044 }
ddb5b488
PZ
12045 }
12046 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12047 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12048 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12049 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12050 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12051 sizeof(buf)));
12052 }
12053 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12054 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12055
12056 char buf[PREFIX_STRLEN];
12057 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12058 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12059 sizeof(buf))) {
12060
b9c7bc5a
PZ
12061 vty_out(vty, "%*snexthop vpn export %s\n",
12062 indent, "", buf);
ddb5b488
PZ
12063 }
12064 }
12065 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12066 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12067 && ecommunity_cmp(
12068 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12069 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12070
12071 char *b = ecommunity_ecom2str(
12072 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12073 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12074 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12075 XFREE(MTYPE_ECOMMUNITY_STR, b);
12076 } else {
12077 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12078 char *b = ecommunity_ecom2str(
12079 bgp->vpn_policy[afi]
12080 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12081 ECOMMUNITY_FORMAT_ROUTE_MAP,
12082 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12083 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12084 XFREE(MTYPE_ECOMMUNITY_STR, b);
12085 }
12086 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12087 char *b = ecommunity_ecom2str(
12088 bgp->vpn_policy[afi]
12089 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12090 ECOMMUNITY_FORMAT_ROUTE_MAP,
12091 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12092 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12093 XFREE(MTYPE_ECOMMUNITY_STR, b);
12094 }
12095 }
bb4f6190
DS
12096
12097 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12098 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12099 bgp->vpn_policy[afi]
12100 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12101
301ad80a
PG
12102 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12103 char *b = ecommunity_ecom2str(
12104 bgp->vpn_policy[afi]
12105 .import_redirect_rtlist,
12106 ECOMMUNITY_FORMAT_ROUTE_MAP,
12107 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12108
301ad80a
PG
12109 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12110 XFREE(MTYPE_ECOMMUNITY_STR, b);
12111 }
ddb5b488
PZ
12112}
12113
12114
718e3744 12115/* BGP node structure. */
d62a17ae 12116static struct cmd_node bgp_node = {
9d303b37 12117 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12118};
12119
d62a17ae 12120static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12121 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12122};
12123
d62a17ae 12124static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12125 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12126};
12127
d62a17ae 12128static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12129 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12130};
12131
d62a17ae 12132static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12133 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12134};
12135
d62a17ae 12136static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12137 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12138};
12139
d62a17ae 12140static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12141 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12142};
12143
d62a17ae 12144static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12145 "%s(config-router-af)# ", 1};
6b0655a2 12146
d62a17ae 12147static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12148 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12149
d62a17ae 12150static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12151 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12152
d62a17ae 12153static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12154 "%s(config-router-af-vni)# ", 1};
90e60aa7 12155
7c40bf39 12156static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12157 "%s(config-router-af)# ", 1};
12158
12159static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12160 "%s(config-router-af-vpnv6)# ", 1};
12161
d62a17ae 12162static void community_list_vty(void);
1f8ae70b 12163
d62a17ae 12164static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12165{
d62a17ae 12166 struct bgp *bgp;
12167 struct peer *peer;
12168 struct peer_group *group;
12169 struct listnode *lnbgp, *lnpeer;
b8a815e5 12170
d62a17ae 12171 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12172 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12173 /* only provide suggestions on the appropriate input
12174 * token type,
12175 * they'll otherwise show up multiple times */
12176 enum cmd_token_type match_type;
12177 char *name = peer->host;
d48ed3e0 12178
d62a17ae 12179 if (peer->conf_if) {
12180 match_type = VARIABLE_TKN;
12181 name = peer->conf_if;
12182 } else if (strchr(peer->host, ':'))
12183 match_type = IPV6_TKN;
12184 else
12185 match_type = IPV4_TKN;
d48ed3e0 12186
d62a17ae 12187 if (token->type != match_type)
12188 continue;
d48ed3e0 12189
d62a17ae 12190 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12191 }
d48ed3e0 12192
d62a17ae 12193 if (token->type == VARIABLE_TKN)
12194 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12195 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12196 group->name));
12197 }
b8a815e5
DL
12198}
12199
12200static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12201 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12202 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12203 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12204 {.completions = NULL}};
12205
12206void bgp_vty_init(void)
12207{
12208 cmd_variable_handler_register(bgp_var_neighbor);
12209
12210 /* Install bgp top node. */
12211 install_node(&bgp_node, bgp_config_write);
12212 install_node(&bgp_ipv4_unicast_node, NULL);
12213 install_node(&bgp_ipv4_multicast_node, NULL);
12214 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12215 install_node(&bgp_ipv6_unicast_node, NULL);
12216 install_node(&bgp_ipv6_multicast_node, NULL);
12217 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12218 install_node(&bgp_vpnv4_node, NULL);
12219 install_node(&bgp_vpnv6_node, NULL);
12220 install_node(&bgp_evpn_node, NULL);
12221 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12222 install_node(&bgp_flowspecv4_node, NULL);
12223 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12224
12225 /* Install default VTY commands to new nodes. */
12226 install_default(BGP_NODE);
12227 install_default(BGP_IPV4_NODE);
12228 install_default(BGP_IPV4M_NODE);
12229 install_default(BGP_IPV4L_NODE);
12230 install_default(BGP_IPV6_NODE);
12231 install_default(BGP_IPV6M_NODE);
12232 install_default(BGP_IPV6L_NODE);
12233 install_default(BGP_VPNV4_NODE);
12234 install_default(BGP_VPNV6_NODE);
7c40bf39 12235 install_default(BGP_FLOWSPECV4_NODE);
12236 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12237 install_default(BGP_EVPN_NODE);
12238 install_default(BGP_EVPN_VNI_NODE);
12239
12240 /* "bgp multiple-instance" commands. */
12241 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12242 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12243
12244 /* "bgp config-type" commands. */
12245 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12246 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12247
12248 /* bgp route-map delay-timer commands. */
12249 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12250 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12251
12252 /* Dummy commands (Currently not supported) */
12253 install_element(BGP_NODE, &no_synchronization_cmd);
12254 install_element(BGP_NODE, &no_auto_summary_cmd);
12255
12256 /* "router bgp" commands. */
12257 install_element(CONFIG_NODE, &router_bgp_cmd);
12258
12259 /* "no router bgp" commands. */
12260 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12261
12262 /* "bgp router-id" commands. */
12263 install_element(BGP_NODE, &bgp_router_id_cmd);
12264 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12265
12266 /* "bgp cluster-id" commands. */
12267 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12268 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12269
12270 /* "bgp confederation" commands. */
12271 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12272 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12273
12274 /* "bgp confederation peers" commands. */
12275 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12276 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12277
12278 /* bgp max-med command */
12279 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12280 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12281 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12282 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12283 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12284
12285 /* bgp disable-ebgp-connected-nh-check */
12286 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12287 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12288
12289 /* bgp update-delay command */
12290 install_element(BGP_NODE, &bgp_update_delay_cmd);
12291 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12292 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12293
12294 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12295 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12296 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12297 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12298
12299 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12300 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12301
12302 /* "maximum-paths" commands. */
12303 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12304 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12305 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12306 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12307 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12308 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12309 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12310 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12311 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12312 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12313 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12314 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12315 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12316 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12317 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12318
12319 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12320 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12321 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12322 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12323 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12324
12325 /* "timers bgp" commands. */
12326 install_element(BGP_NODE, &bgp_timers_cmd);
12327 install_element(BGP_NODE, &no_bgp_timers_cmd);
12328
12329 /* route-map delay-timer commands - per instance for backwards compat.
12330 */
12331 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12332 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12333
12334 /* "bgp client-to-client reflection" commands */
12335 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12336 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12337
12338 /* "bgp always-compare-med" commands */
12339 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12340 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12341
12342 /* "bgp deterministic-med" commands */
12343 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12344 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12345
12346 /* "bgp graceful-restart" commands */
12347 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12348 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12349 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12350 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12351 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12352 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12353
12354 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12355 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12356
7f323236
DW
12357 /* "bgp graceful-shutdown" commands */
12358 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12359 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12360
d62a17ae 12361 /* "bgp fast-external-failover" commands */
12362 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12363 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12364
12365 /* "bgp enforce-first-as" commands */
12366 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12367 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
12368
12369 /* "bgp bestpath compare-routerid" commands */
12370 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12371 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12372
12373 /* "bgp bestpath as-path ignore" commands */
12374 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12375 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12376
12377 /* "bgp bestpath as-path confed" commands */
12378 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12379 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12380
12381 /* "bgp bestpath as-path multipath-relax" commands */
12382 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12383 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12384
12385 /* "bgp log-neighbor-changes" commands */
12386 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12387 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12388
12389 /* "bgp bestpath med" commands */
12390 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12391 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12392
12393 /* "no bgp default ipv4-unicast" commands. */
12394 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12395 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12396
12397 /* "bgp network import-check" commands. */
12398 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12399 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12400 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12401
12402 /* "bgp default local-preference" commands. */
12403 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12404 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12405
12406 /* bgp default show-hostname */
12407 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12408 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12409
12410 /* "bgp default subgroup-pkt-queue-max" commands. */
12411 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12412 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12413
12414 /* bgp ibgp-allow-policy-mods command */
12415 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12416 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12417
12418 /* "bgp listen limit" commands. */
12419 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12420 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12421
12422 /* "bgp listen range" commands. */
12423 install_element(BGP_NODE, &bgp_listen_range_cmd);
12424 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12425
8175f54a 12426 /* "bgp default shutdown" command */
f26845f9
QY
12427 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12428
d62a17ae 12429 /* "neighbor remote-as" commands. */
12430 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12431 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12432 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12433 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12434 install_element(BGP_NODE,
12435 &neighbor_interface_v6only_config_remote_as_cmd);
12436 install_element(BGP_NODE, &no_neighbor_cmd);
12437 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12438
12439 /* "neighbor peer-group" commands. */
12440 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12441 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12442 install_element(BGP_NODE,
12443 &no_neighbor_interface_peer_group_remote_as_cmd);
12444
12445 /* "neighbor local-as" commands. */
12446 install_element(BGP_NODE, &neighbor_local_as_cmd);
12447 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12448 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12449 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12450
12451 /* "neighbor solo" commands. */
12452 install_element(BGP_NODE, &neighbor_solo_cmd);
12453 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12454
12455 /* "neighbor password" commands. */
12456 install_element(BGP_NODE, &neighbor_password_cmd);
12457 install_element(BGP_NODE, &no_neighbor_password_cmd);
12458
12459 /* "neighbor activate" commands. */
12460 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12461 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12462 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12463 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12464 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12465 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12466 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12467 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12468 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 12469 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12470 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 12471 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12472
12473 /* "no neighbor activate" commands. */
12474 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12475 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12476 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12477 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12478 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12479 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12480 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12481 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12482 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 12483 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12484 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 12485 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12486
12487 /* "neighbor peer-group" set commands. */
12488 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12489 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12490 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12491 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12492 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12493 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12494 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12495 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 12496 install_element(BGP_FLOWSPECV4_NODE,
12497 &neighbor_set_peer_group_hidden_cmd);
12498 install_element(BGP_FLOWSPECV6_NODE,
12499 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 12500
12501 /* "no neighbor peer-group unset" commands. */
12502 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12503 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12504 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12505 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12506 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12507 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12508 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12509 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 12510 install_element(BGP_FLOWSPECV4_NODE,
12511 &no_neighbor_set_peer_group_hidden_cmd);
12512 install_element(BGP_FLOWSPECV6_NODE,
12513 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 12514
12515 /* "neighbor softreconfiguration inbound" commands.*/
12516 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12517 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12518 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12519 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12520 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12521 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12522 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12523 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12524 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12525 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12526 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12527 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12528 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12529 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12530 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12531 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12532 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12533 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 12534 install_element(BGP_FLOWSPECV4_NODE,
12535 &neighbor_soft_reconfiguration_cmd);
12536 install_element(BGP_FLOWSPECV4_NODE,
12537 &no_neighbor_soft_reconfiguration_cmd);
12538 install_element(BGP_FLOWSPECV6_NODE,
12539 &neighbor_soft_reconfiguration_cmd);
12540 install_element(BGP_FLOWSPECV6_NODE,
12541 &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 12542
12543 /* "neighbor attribute-unchanged" commands. */
12544 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12545 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12546 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12547 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12548 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12549 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12550 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12551 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12552 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12553 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12554 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12555 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12556 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12557 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12558 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12559 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12560 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12561 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12562
12563 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12564 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12565
12566 /* "nexthop-local unchanged" commands */
12567 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12568 install_element(BGP_IPV6_NODE,
12569 &no_neighbor_nexthop_local_unchanged_cmd);
12570
12571 /* "neighbor next-hop-self" commands. */
12572 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12573 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12574 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12575 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12576 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12577 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12578 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12579 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12580 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12581 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12582 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12583 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12584 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12585 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12586 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12587 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12588 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12589 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12590
12591 /* "neighbor next-hop-self force" commands. */
12592 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12593 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12594 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12595 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12596 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12597 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12598 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12599 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12600 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12601 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12602 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12603 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12604 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12605 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12606 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12607 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12608 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12609 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12610
12611 /* "neighbor as-override" commands. */
12612 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12613 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12614 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12615 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12616 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12617 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12618 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12619 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12620 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12621 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12622 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12623 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12624 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12625 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12626 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12627 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12628 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12629 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12630
12631 /* "neighbor remove-private-AS" commands. */
12632 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12633 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12634 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12635 install_element(BGP_NODE,
12636 &no_neighbor_remove_private_as_all_hidden_cmd);
12637 install_element(BGP_NODE,
12638 &neighbor_remove_private_as_replace_as_hidden_cmd);
12639 install_element(BGP_NODE,
12640 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12641 install_element(BGP_NODE,
12642 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12643 install_element(
12644 BGP_NODE,
12645 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12646 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12647 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12648 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12649 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12650 install_element(BGP_IPV4_NODE,
12651 &neighbor_remove_private_as_replace_as_cmd);
12652 install_element(BGP_IPV4_NODE,
12653 &no_neighbor_remove_private_as_replace_as_cmd);
12654 install_element(BGP_IPV4_NODE,
12655 &neighbor_remove_private_as_all_replace_as_cmd);
12656 install_element(BGP_IPV4_NODE,
12657 &no_neighbor_remove_private_as_all_replace_as_cmd);
12658 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12659 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12660 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12661 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12662 install_element(BGP_IPV4M_NODE,
12663 &neighbor_remove_private_as_replace_as_cmd);
12664 install_element(BGP_IPV4M_NODE,
12665 &no_neighbor_remove_private_as_replace_as_cmd);
12666 install_element(BGP_IPV4M_NODE,
12667 &neighbor_remove_private_as_all_replace_as_cmd);
12668 install_element(BGP_IPV4M_NODE,
12669 &no_neighbor_remove_private_as_all_replace_as_cmd);
12670 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12671 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12672 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12673 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12674 install_element(BGP_IPV4L_NODE,
12675 &neighbor_remove_private_as_replace_as_cmd);
12676 install_element(BGP_IPV4L_NODE,
12677 &no_neighbor_remove_private_as_replace_as_cmd);
12678 install_element(BGP_IPV4L_NODE,
12679 &neighbor_remove_private_as_all_replace_as_cmd);
12680 install_element(BGP_IPV4L_NODE,
12681 &no_neighbor_remove_private_as_all_replace_as_cmd);
12682 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12683 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12684 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12685 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12686 install_element(BGP_IPV6_NODE,
12687 &neighbor_remove_private_as_replace_as_cmd);
12688 install_element(BGP_IPV6_NODE,
12689 &no_neighbor_remove_private_as_replace_as_cmd);
12690 install_element(BGP_IPV6_NODE,
12691 &neighbor_remove_private_as_all_replace_as_cmd);
12692 install_element(BGP_IPV6_NODE,
12693 &no_neighbor_remove_private_as_all_replace_as_cmd);
12694 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12695 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12696 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12697 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12698 install_element(BGP_IPV6M_NODE,
12699 &neighbor_remove_private_as_replace_as_cmd);
12700 install_element(BGP_IPV6M_NODE,
12701 &no_neighbor_remove_private_as_replace_as_cmd);
12702 install_element(BGP_IPV6M_NODE,
12703 &neighbor_remove_private_as_all_replace_as_cmd);
12704 install_element(BGP_IPV6M_NODE,
12705 &no_neighbor_remove_private_as_all_replace_as_cmd);
12706 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12707 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12708 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12709 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12710 install_element(BGP_IPV6L_NODE,
12711 &neighbor_remove_private_as_replace_as_cmd);
12712 install_element(BGP_IPV6L_NODE,
12713 &no_neighbor_remove_private_as_replace_as_cmd);
12714 install_element(BGP_IPV6L_NODE,
12715 &neighbor_remove_private_as_all_replace_as_cmd);
12716 install_element(BGP_IPV6L_NODE,
12717 &no_neighbor_remove_private_as_all_replace_as_cmd);
12718 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12719 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12720 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12721 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12722 install_element(BGP_VPNV4_NODE,
12723 &neighbor_remove_private_as_replace_as_cmd);
12724 install_element(BGP_VPNV4_NODE,
12725 &no_neighbor_remove_private_as_replace_as_cmd);
12726 install_element(BGP_VPNV4_NODE,
12727 &neighbor_remove_private_as_all_replace_as_cmd);
12728 install_element(BGP_VPNV4_NODE,
12729 &no_neighbor_remove_private_as_all_replace_as_cmd);
12730 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12731 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12732 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12733 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12734 install_element(BGP_VPNV6_NODE,
12735 &neighbor_remove_private_as_replace_as_cmd);
12736 install_element(BGP_VPNV6_NODE,
12737 &no_neighbor_remove_private_as_replace_as_cmd);
12738 install_element(BGP_VPNV6_NODE,
12739 &neighbor_remove_private_as_all_replace_as_cmd);
12740 install_element(BGP_VPNV6_NODE,
12741 &no_neighbor_remove_private_as_all_replace_as_cmd);
12742
12743 /* "neighbor send-community" commands.*/
12744 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12745 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12746 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12747 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12748 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12749 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12750 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12751 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12752 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12753 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12754 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12755 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12756 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12757 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12758 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12759 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12760 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12761 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12762 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12763 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12764 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12765 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12766 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12767 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12768 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12769 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12770 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12771 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12772 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12773 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12774 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12775 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12776 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12777 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12778 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12779 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12780
12781 /* "neighbor route-reflector" commands.*/
12782 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12783 install_element(BGP_NODE,
12784 &no_neighbor_route_reflector_client_hidden_cmd);
12785 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12786 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12787 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12788 install_element(BGP_IPV4M_NODE,
12789 &no_neighbor_route_reflector_client_cmd);
12790 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12791 install_element(BGP_IPV4L_NODE,
12792 &no_neighbor_route_reflector_client_cmd);
12793 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12794 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12795 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12796 install_element(BGP_IPV6M_NODE,
12797 &no_neighbor_route_reflector_client_cmd);
12798 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12799 install_element(BGP_IPV6L_NODE,
12800 &no_neighbor_route_reflector_client_cmd);
12801 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12802 install_element(BGP_VPNV4_NODE,
12803 &no_neighbor_route_reflector_client_cmd);
12804 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12805 install_element(BGP_VPNV6_NODE,
12806 &no_neighbor_route_reflector_client_cmd);
7c40bf39 12807 install_element(BGP_FLOWSPECV4_NODE,
12808 &neighbor_route_reflector_client_cmd);
12809 install_element(BGP_FLOWSPECV4_NODE,
12810 &no_neighbor_route_reflector_client_cmd);
12811 install_element(BGP_FLOWSPECV6_NODE,
12812 &neighbor_route_reflector_client_cmd);
12813 install_element(BGP_FLOWSPECV6_NODE,
12814 &no_neighbor_route_reflector_client_cmd);
d62a17ae 12815 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12816 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12817
12818 /* "neighbor route-server" commands.*/
12819 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12820 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12821 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12822 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12823 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12824 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12825 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12826 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12827 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12828 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12829 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12830 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12831 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12832 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12833 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12834 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12835 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12836 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 12837 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12838 install_element(BGP_FLOWSPECV4_NODE,
12839 &no_neighbor_route_server_client_cmd);
12840 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12841 install_element(BGP_FLOWSPECV6_NODE,
12842 &no_neighbor_route_server_client_cmd);
d62a17ae 12843
12844 /* "neighbor addpath-tx-all-paths" commands.*/
12845 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12846 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12847 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12848 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12849 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12850 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12851 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12852 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12853 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12854 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12855 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12856 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12857 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12858 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12859 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12860 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12861 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12862 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12863
12864 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12865 install_element(BGP_NODE,
12866 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12867 install_element(BGP_NODE,
12868 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12869 install_element(BGP_IPV4_NODE,
12870 &neighbor_addpath_tx_bestpath_per_as_cmd);
12871 install_element(BGP_IPV4_NODE,
12872 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12873 install_element(BGP_IPV4M_NODE,
12874 &neighbor_addpath_tx_bestpath_per_as_cmd);
12875 install_element(BGP_IPV4M_NODE,
12876 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12877 install_element(BGP_IPV4L_NODE,
12878 &neighbor_addpath_tx_bestpath_per_as_cmd);
12879 install_element(BGP_IPV4L_NODE,
12880 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12881 install_element(BGP_IPV6_NODE,
12882 &neighbor_addpath_tx_bestpath_per_as_cmd);
12883 install_element(BGP_IPV6_NODE,
12884 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12885 install_element(BGP_IPV6M_NODE,
12886 &neighbor_addpath_tx_bestpath_per_as_cmd);
12887 install_element(BGP_IPV6M_NODE,
12888 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12889 install_element(BGP_IPV6L_NODE,
12890 &neighbor_addpath_tx_bestpath_per_as_cmd);
12891 install_element(BGP_IPV6L_NODE,
12892 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12893 install_element(BGP_VPNV4_NODE,
12894 &neighbor_addpath_tx_bestpath_per_as_cmd);
12895 install_element(BGP_VPNV4_NODE,
12896 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12897 install_element(BGP_VPNV6_NODE,
12898 &neighbor_addpath_tx_bestpath_per_as_cmd);
12899 install_element(BGP_VPNV6_NODE,
12900 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12901
12902 /* "neighbor passive" commands. */
12903 install_element(BGP_NODE, &neighbor_passive_cmd);
12904 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12905
12906
12907 /* "neighbor shutdown" commands. */
12908 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12909 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12910 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12911 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12912
12913 /* "neighbor capability extended-nexthop" commands.*/
12914 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12915 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12916
12917 /* "neighbor capability orf prefix-list" commands.*/
12918 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12919 install_element(BGP_NODE,
12920 &no_neighbor_capability_orf_prefix_hidden_cmd);
12921 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12922 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12923 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
12924 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12925 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
12926 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12927 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
12928 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
12929 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
12930 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12931 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
12932 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12933
12934 /* "neighbor capability dynamic" commands.*/
12935 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
12936 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
12937
12938 /* "neighbor dont-capability-negotiate" commands. */
12939 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
12940 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
12941
12942 /* "neighbor ebgp-multihop" commands. */
12943 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
12944 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
12945 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
12946
12947 /* "neighbor disable-connected-check" commands. */
12948 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
12949 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
12950
12951 /* "neighbor description" commands. */
12952 install_element(BGP_NODE, &neighbor_description_cmd);
12953 install_element(BGP_NODE, &no_neighbor_description_cmd);
12954
12955 /* "neighbor update-source" commands. "*/
12956 install_element(BGP_NODE, &neighbor_update_source_cmd);
12957 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
12958
12959 /* "neighbor default-originate" commands. */
12960 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
12961 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
12962 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
12963 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
12964 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
12965 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
12966 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
12967 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
12968 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
12969 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
12970 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
12971 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
12972 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
12973 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
12974 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
12975 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
12976 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
12977 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
12978 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
12979 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
12980 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
12981
12982 /* "neighbor port" commands. */
12983 install_element(BGP_NODE, &neighbor_port_cmd);
12984 install_element(BGP_NODE, &no_neighbor_port_cmd);
12985
12986 /* "neighbor weight" commands. */
12987 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
12988 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
12989
12990 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
12991 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
12992 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
12993 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
12994 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
12995 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
12996 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
12997 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
12998 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
12999 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13000 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13001 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13002 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13003 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13004 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13005 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13006
13007 /* "neighbor override-capability" commands. */
13008 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13009 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13010
13011 /* "neighbor strict-capability-match" commands. */
13012 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13013 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13014
13015 /* "neighbor timers" commands. */
13016 install_element(BGP_NODE, &neighbor_timers_cmd);
13017 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13018
13019 /* "neighbor timers connect" commands. */
13020 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13021 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13022
13023 /* "neighbor advertisement-interval" commands. */
13024 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13025 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13026
13027 /* "neighbor interface" commands. */
13028 install_element(BGP_NODE, &neighbor_interface_cmd);
13029 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13030
13031 /* "neighbor distribute" commands. */
13032 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13033 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13034 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13035 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13036 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13037 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13038 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13039 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13040 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13041 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13042 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13043 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13044 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13045 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13046 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13047 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13048 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13049 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13050
13051 /* "neighbor prefix-list" commands. */
13052 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13053 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13054 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13055 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13056 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13057 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13058 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13059 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13060 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13061 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13062 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13063 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13064 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13065 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13066 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13067 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13068 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13069 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13070 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13071 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13072 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13073 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13074
13075 /* "neighbor filter-list" commands. */
13076 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13077 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13078 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13079 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13080 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13081 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13082 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13083 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13084 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13085 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13086 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13087 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13088 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13089 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13090 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13091 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13092 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13093 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13094 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13095 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13096 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13097 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13098
13099 /* "neighbor route-map" commands. */
13100 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13101 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13102 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13103 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13104 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13105 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13106 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13107 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13108 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13109 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13110 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13111 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13112 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13113 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13114 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13115 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13116 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13117 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13118 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13119 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13120 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13121 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13122 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13123 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13124
13125 /* "neighbor unsuppress-map" commands. */
13126 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13127 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13128 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13129 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13130 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13131 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13132 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13133 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13134 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13135 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13136 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13137 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13138 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13139 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13140 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13141 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13142 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13143 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13144
13145 /* "neighbor maximum-prefix" commands. */
13146 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13147 install_element(BGP_NODE,
13148 &neighbor_maximum_prefix_threshold_hidden_cmd);
13149 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13150 install_element(BGP_NODE,
13151 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13152 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13153 install_element(BGP_NODE,
13154 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13155 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13156 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13157 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13158 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13159 install_element(BGP_IPV4_NODE,
13160 &neighbor_maximum_prefix_threshold_warning_cmd);
13161 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13162 install_element(BGP_IPV4_NODE,
13163 &neighbor_maximum_prefix_threshold_restart_cmd);
13164 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13165 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13166 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13167 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13168 install_element(BGP_IPV4M_NODE,
13169 &neighbor_maximum_prefix_threshold_warning_cmd);
13170 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13171 install_element(BGP_IPV4M_NODE,
13172 &neighbor_maximum_prefix_threshold_restart_cmd);
13173 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13174 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13175 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13176 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13177 install_element(BGP_IPV4L_NODE,
13178 &neighbor_maximum_prefix_threshold_warning_cmd);
13179 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13180 install_element(BGP_IPV4L_NODE,
13181 &neighbor_maximum_prefix_threshold_restart_cmd);
13182 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13183 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13184 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13185 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13186 install_element(BGP_IPV6_NODE,
13187 &neighbor_maximum_prefix_threshold_warning_cmd);
13188 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13189 install_element(BGP_IPV6_NODE,
13190 &neighbor_maximum_prefix_threshold_restart_cmd);
13191 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13192 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13193 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13194 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13195 install_element(BGP_IPV6M_NODE,
13196 &neighbor_maximum_prefix_threshold_warning_cmd);
13197 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13198 install_element(BGP_IPV6M_NODE,
13199 &neighbor_maximum_prefix_threshold_restart_cmd);
13200 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13201 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13202 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13203 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13204 install_element(BGP_IPV6L_NODE,
13205 &neighbor_maximum_prefix_threshold_warning_cmd);
13206 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13207 install_element(BGP_IPV6L_NODE,
13208 &neighbor_maximum_prefix_threshold_restart_cmd);
13209 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13210 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13211 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13212 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13213 install_element(BGP_VPNV4_NODE,
13214 &neighbor_maximum_prefix_threshold_warning_cmd);
13215 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13216 install_element(BGP_VPNV4_NODE,
13217 &neighbor_maximum_prefix_threshold_restart_cmd);
13218 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13219 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13220 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13221 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13222 install_element(BGP_VPNV6_NODE,
13223 &neighbor_maximum_prefix_threshold_warning_cmd);
13224 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13225 install_element(BGP_VPNV6_NODE,
13226 &neighbor_maximum_prefix_threshold_restart_cmd);
13227 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13228
13229 /* "neighbor allowas-in" */
13230 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13231 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13232 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13233 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13234 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13235 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13236 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13237 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13238 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13239 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13240 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13241 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13242 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13243 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13244 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13245 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13246 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13247 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13248 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13249 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13250
13251 /* address-family commands. */
13252 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13253 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13254#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13255 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13256 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13257#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13258
d62a17ae 13259 install_element(BGP_NODE, &address_family_evpn_cmd);
13260
13261 /* "exit-address-family" command. */
13262 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13263 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13264 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13265 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13266 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13267 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13268 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13269 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13270 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13271 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13272 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13273
13274 /* "clear ip bgp commands" */
13275 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13276
13277 /* clear ip bgp prefix */
13278 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13279 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13280 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13281
13282 /* "show [ip] bgp summary" commands. */
13283 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
d62a17ae 13284 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13285 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13286 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13287 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13288 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13289
13290 /* "show [ip] bgp neighbors" commands. */
13291 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13292
13293 /* "show [ip] bgp peer-group" commands. */
13294 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13295
13296 /* "show [ip] bgp paths" commands. */
13297 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13298
13299 /* "show [ip] bgp community" commands. */
13300 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13301
13302 /* "show ip bgp large-community" commands. */
13303 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13304 /* "show [ip] bgp attribute-info" commands. */
13305 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13306 /* "show [ip] bgp route-leak" command */
13307 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13308
13309 /* "redistribute" commands. */
13310 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13311 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13312 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13313 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13314 install_element(BGP_NODE,
13315 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13316 install_element(BGP_NODE,
13317 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13318 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13319 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13320 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13321 install_element(BGP_NODE,
13322 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13323 install_element(BGP_NODE,
13324 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13325 install_element(BGP_NODE,
13326 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13327 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13328 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13329 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13330 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13331 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13332 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13333 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13334 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13335 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13336 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13337 install_element(BGP_IPV4_NODE,
13338 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13339 install_element(BGP_IPV4_NODE,
13340 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13341 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13342 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13343 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13344 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13345 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13346 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13347
b9c7bc5a
PZ
13348 /* import|export vpn [route-map WORD] */
13349 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13350 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13351
12a844a5
DS
13352 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13353 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13354
d62a17ae 13355 /* ttl_security commands */
13356 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13357 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13358
13359 /* "show [ip] bgp memory" commands. */
13360 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13361
acf71666
MK
13362 /* "show bgp martian next-hop" */
13363 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13364
d62a17ae 13365 /* "show [ip] bgp views" commands. */
13366 install_element(VIEW_NODE, &show_bgp_views_cmd);
13367
13368 /* "show [ip] bgp vrfs" commands. */
13369 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13370
13371 /* Community-list. */
13372 community_list_vty();
ddb5b488
PZ
13373
13374 /* vpn-policy commands */
b9c7bc5a
PZ
13375 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13376 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13377 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13378 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13379 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13380 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13381 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13382 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13383 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13384 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
13385 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13386 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 13387
301ad80a
PG
13388 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13389 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13390
b9c7bc5a
PZ
13391 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13392 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13393 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13394 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13395 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13396 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13397 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13398 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13399 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13400 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
13401 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13402 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 13403}
6b0655a2 13404
718e3744 13405#include "memory.h"
13406#include "bgp_regex.h"
13407#include "bgp_clist.h"
13408#include "bgp_ecommunity.h"
13409
13410/* VTY functions. */
13411
13412/* Direction value to string conversion. */
d62a17ae 13413static const char *community_direct_str(int direct)
13414{
13415 switch (direct) {
13416 case COMMUNITY_DENY:
13417 return "deny";
13418 case COMMUNITY_PERMIT:
13419 return "permit";
13420 default:
13421 return "unknown";
13422 }
718e3744 13423}
13424
13425/* Display error string. */
d62a17ae 13426static void community_list_perror(struct vty *vty, int ret)
13427{
13428 switch (ret) {
13429 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13430 vty_out(vty, "%% Can't find community-list\n");
13431 break;
13432 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13433 vty_out(vty, "%% Malformed community-list value\n");
13434 break;
13435 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13436 vty_out(vty,
13437 "%% Community name conflict, previously defined as standard community\n");
13438 break;
13439 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13440 vty_out(vty,
13441 "%% Community name conflict, previously defined as expanded community\n");
13442 break;
13443 }
718e3744 13444}
13445
5bf15956
DW
13446/* "community-list" keyword help string. */
13447#define COMMUNITY_LIST_STR "Add a community list entry\n"
13448
5bf15956 13449/* ip community-list standard */
718e3744 13450DEFUN (ip_community_list_standard,
13451 ip_community_list_standard_cmd,
e961923c 13452 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13453 IP_STR
13454 COMMUNITY_LIST_STR
13455 "Community list number (standard)\n"
5bf15956 13456 "Add an standard community-list entry\n"
718e3744 13457 "Community list name\n"
13458 "Specify community to reject\n"
13459 "Specify community to accept\n"
13460 COMMUNITY_VAL_STR)
13461{
d62a17ae 13462 char *cl_name_or_number = NULL;
13463 int direct = 0;
13464 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13465
d62a17ae 13466 int idx = 0;
13467 argv_find(argv, argc, "(1-99)", &idx);
13468 argv_find(argv, argc, "WORD", &idx);
13469 cl_name_or_number = argv[idx]->arg;
13470 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13471 : COMMUNITY_DENY;
13472 argv_find(argv, argc, "AA:NN", &idx);
13473 char *str = argv_concat(argv, argc, idx);
42f914d4 13474
d62a17ae 13475 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13476 style);
42f914d4 13477
d62a17ae 13478 XFREE(MTYPE_TMP, str);
42f914d4 13479
d62a17ae 13480 if (ret < 0) {
13481 /* Display error string. */
13482 community_list_perror(vty, ret);
13483 return CMD_WARNING_CONFIG_FAILED;
13484 }
42f914d4 13485
d62a17ae 13486 return CMD_SUCCESS;
718e3744 13487}
13488
fee6e4e4 13489DEFUN (no_ip_community_list_standard_all,
13490 no_ip_community_list_standard_all_cmd,
e961923c 13491 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13492 NO_STR
13493 IP_STR
13494 COMMUNITY_LIST_STR
13495 "Community list number (standard)\n"
5bf15956
DW
13496 "Add an standard community-list entry\n"
13497 "Community list name\n"
718e3744 13498 "Specify community to reject\n"
13499 "Specify community to accept\n"
13500 COMMUNITY_VAL_STR)
13501{
d62a17ae 13502 char *cl_name_or_number = NULL;
13503 int direct = 0;
13504 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13505
d62a17ae 13506 int idx = 0;
13507 argv_find(argv, argc, "(1-99)", &idx);
13508 argv_find(argv, argc, "WORD", &idx);
13509 cl_name_or_number = argv[idx]->arg;
13510 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13511 : COMMUNITY_DENY;
13512 argv_find(argv, argc, "AA:NN", &idx);
13513 char *str = argv_concat(argv, argc, idx);
42f914d4 13514
d62a17ae 13515 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13516 direct, style);
42f914d4 13517
d62a17ae 13518 XFREE(MTYPE_TMP, str);
daf9ddbb 13519
d62a17ae 13520 if (ret < 0) {
13521 community_list_perror(vty, ret);
13522 return CMD_WARNING_CONFIG_FAILED;
13523 }
42f914d4 13524
d62a17ae 13525 return CMD_SUCCESS;
718e3744 13526}
13527
5bf15956
DW
13528/* ip community-list expanded */
13529DEFUN (ip_community_list_expanded_all,
13530 ip_community_list_expanded_all_cmd,
42f914d4 13531 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13532 IP_STR
13533 COMMUNITY_LIST_STR
13534 "Community list number (expanded)\n"
5bf15956 13535 "Add an expanded community-list entry\n"
718e3744 13536 "Community list name\n"
13537 "Specify community to reject\n"
13538 "Specify community to accept\n"
13539 COMMUNITY_VAL_STR)
13540{
d62a17ae 13541 char *cl_name_or_number = NULL;
13542 int direct = 0;
13543 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13544
d62a17ae 13545 int idx = 0;
13546 argv_find(argv, argc, "(100-500)", &idx);
13547 argv_find(argv, argc, "WORD", &idx);
13548 cl_name_or_number = argv[idx]->arg;
13549 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13550 : COMMUNITY_DENY;
13551 argv_find(argv, argc, "AA:NN", &idx);
13552 char *str = argv_concat(argv, argc, idx);
42f914d4 13553
d62a17ae 13554 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13555 style);
42f914d4 13556
d62a17ae 13557 XFREE(MTYPE_TMP, str);
42f914d4 13558
d62a17ae 13559 if (ret < 0) {
13560 /* Display error string. */
13561 community_list_perror(vty, ret);
13562 return CMD_WARNING_CONFIG_FAILED;
13563 }
42f914d4 13564
d62a17ae 13565 return CMD_SUCCESS;
718e3744 13566}
13567
5bf15956
DW
13568DEFUN (no_ip_community_list_expanded_all,
13569 no_ip_community_list_expanded_all_cmd,
42f914d4 13570 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13571 NO_STR
13572 IP_STR
13573 COMMUNITY_LIST_STR
5bf15956
DW
13574 "Community list number (expanded)\n"
13575 "Add an expanded community-list entry\n"
718e3744 13576 "Community list name\n"
13577 "Specify community to reject\n"
13578 "Specify community to accept\n"
5bf15956 13579 COMMUNITY_VAL_STR)
718e3744 13580{
d62a17ae 13581 char *cl_name_or_number = NULL;
13582 int direct = 0;
13583 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13584
d62a17ae 13585 int idx = 0;
13586 argv_find(argv, argc, "(100-500)", &idx);
13587 argv_find(argv, argc, "WORD", &idx);
13588 cl_name_or_number = argv[idx]->arg;
13589 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13590 : COMMUNITY_DENY;
13591 argv_find(argv, argc, "AA:NN", &idx);
13592 char *str = argv_concat(argv, argc, idx);
42f914d4 13593
d62a17ae 13594 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13595 direct, style);
42f914d4 13596
d62a17ae 13597 XFREE(MTYPE_TMP, str);
daf9ddbb 13598
d62a17ae 13599 if (ret < 0) {
13600 community_list_perror(vty, ret);
13601 return CMD_WARNING_CONFIG_FAILED;
13602 }
42f914d4 13603
d62a17ae 13604 return CMD_SUCCESS;
718e3744 13605}
13606
d62a17ae 13607static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 13608{
d62a17ae 13609 struct community_entry *entry;
718e3744 13610
d62a17ae 13611 for (entry = list->head; entry; entry = entry->next) {
13612 if (entry == list->head) {
13613 if (all_digit(list->name))
13614 vty_out(vty, "Community %s list %s\n",
13615 entry->style == COMMUNITY_LIST_STANDARD
13616 ? "standard"
13617 : "(expanded) access",
13618 list->name);
13619 else
13620 vty_out(vty, "Named Community %s list %s\n",
13621 entry->style == COMMUNITY_LIST_STANDARD
13622 ? "standard"
13623 : "expanded",
13624 list->name);
13625 }
13626 if (entry->any)
13627 vty_out(vty, " %s\n",
13628 community_direct_str(entry->direct));
13629 else
13630 vty_out(vty, " %s %s\n",
13631 community_direct_str(entry->direct),
13632 entry->style == COMMUNITY_LIST_STANDARD
a69ea8ae 13633 ? community_str(entry->u.com, false)
d62a17ae 13634 : entry->config);
13635 }
718e3744 13636}
13637
13638DEFUN (show_ip_community_list,
13639 show_ip_community_list_cmd,
13640 "show ip community-list",
13641 SHOW_STR
13642 IP_STR
13643 "List community-list\n")
13644{
d62a17ae 13645 struct community_list *list;
13646 struct community_list_master *cm;
718e3744 13647
d62a17ae 13648 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13649 if (!cm)
13650 return CMD_SUCCESS;
718e3744 13651
d62a17ae 13652 for (list = cm->num.head; list; list = list->next)
13653 community_list_show(vty, list);
718e3744 13654
d62a17ae 13655 for (list = cm->str.head; list; list = list->next)
13656 community_list_show(vty, list);
718e3744 13657
d62a17ae 13658 return CMD_SUCCESS;
718e3744 13659}
13660
13661DEFUN (show_ip_community_list_arg,
13662 show_ip_community_list_arg_cmd,
6147e2c6 13663 "show ip community-list <(1-500)|WORD>",
718e3744 13664 SHOW_STR
13665 IP_STR
13666 "List community-list\n"
13667 "Community-list number\n"
13668 "Community-list name\n")
13669{
d62a17ae 13670 int idx_comm_list = 3;
13671 struct community_list *list;
718e3744 13672
d62a17ae 13673 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13674 COMMUNITY_LIST_MASTER);
13675 if (!list) {
13676 vty_out(vty, "%% Can't find community-list\n");
13677 return CMD_WARNING;
13678 }
718e3744 13679
d62a17ae 13680 community_list_show(vty, list);
718e3744 13681
d62a17ae 13682 return CMD_SUCCESS;
718e3744 13683}
6b0655a2 13684
57d187bc
JS
13685/*
13686 * Large Community code.
13687 */
d62a17ae 13688static int lcommunity_list_set_vty(struct vty *vty, int argc,
13689 struct cmd_token **argv, int style,
13690 int reject_all_digit_name)
13691{
13692 int ret;
13693 int direct;
13694 char *str;
13695 int idx = 0;
13696 char *cl_name;
13697
13698 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13699 : COMMUNITY_DENY;
13700
13701 /* All digit name check. */
13702 idx = 0;
13703 argv_find(argv, argc, "WORD", &idx);
13704 argv_find(argv, argc, "(1-99)", &idx);
13705 argv_find(argv, argc, "(100-500)", &idx);
13706 cl_name = argv[idx]->arg;
13707 if (reject_all_digit_name && all_digit(cl_name)) {
13708 vty_out(vty, "%% Community name cannot have all digits\n");
13709 return CMD_WARNING_CONFIG_FAILED;
13710 }
13711
13712 idx = 0;
13713 argv_find(argv, argc, "AA:BB:CC", &idx);
13714 argv_find(argv, argc, "LINE", &idx);
13715 /* Concat community string argument. */
13716 if (idx)
13717 str = argv_concat(argv, argc, idx);
13718 else
13719 str = NULL;
13720
13721 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13722
13723 /* Free temporary community list string allocated by
13724 argv_concat(). */
13725 if (str)
13726 XFREE(MTYPE_TMP, str);
13727
13728 if (ret < 0) {
13729 community_list_perror(vty, ret);
13730 return CMD_WARNING_CONFIG_FAILED;
13731 }
13732 return CMD_SUCCESS;
13733}
13734
13735static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13736 struct cmd_token **argv, int style)
13737{
13738 int ret;
13739 int direct = 0;
13740 char *str = NULL;
13741 int idx = 0;
13742
13743 argv_find(argv, argc, "permit", &idx);
13744 argv_find(argv, argc, "deny", &idx);
13745
13746 if (idx) {
13747 /* Check the list direct. */
13748 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13749 direct = COMMUNITY_PERMIT;
13750 else
13751 direct = COMMUNITY_DENY;
13752
13753 idx = 0;
13754 argv_find(argv, argc, "LINE", &idx);
13755 argv_find(argv, argc, "AA:AA:NN", &idx);
13756 /* Concat community string argument. */
13757 str = argv_concat(argv, argc, idx);
13758 }
13759
13760 idx = 0;
13761 argv_find(argv, argc, "(1-99)", &idx);
13762 argv_find(argv, argc, "(100-500)", &idx);
13763 argv_find(argv, argc, "WORD", &idx);
13764
13765 /* Unset community list. */
13766 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13767 style);
13768
13769 /* Free temporary community list string allocated by
13770 argv_concat(). */
13771 if (str)
13772 XFREE(MTYPE_TMP, str);
13773
13774 if (ret < 0) {
13775 community_list_perror(vty, ret);
13776 return CMD_WARNING_CONFIG_FAILED;
13777 }
13778
13779 return CMD_SUCCESS;
57d187bc
JS
13780}
13781
13782/* "large-community-list" keyword help string. */
13783#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13784#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13785
13786DEFUN (ip_lcommunity_list_standard,
13787 ip_lcommunity_list_standard_cmd,
52951b63
DS
13788 "ip large-community-list (1-99) <deny|permit>",
13789 IP_STR
13790 LCOMMUNITY_LIST_STR
13791 "Large Community list number (standard)\n"
13792 "Specify large community to reject\n"
7111c1a0 13793 "Specify large community to accept\n")
52951b63 13794{
d62a17ae 13795 return lcommunity_list_set_vty(vty, argc, argv,
13796 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
13797}
13798
13799DEFUN (ip_lcommunity_list_standard1,
13800 ip_lcommunity_list_standard1_cmd,
13801 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
13802 IP_STR
13803 LCOMMUNITY_LIST_STR
13804 "Large Community list number (standard)\n"
13805 "Specify large community to reject\n"
13806 "Specify large community to accept\n"
13807 LCOMMUNITY_VAL_STR)
13808{
d62a17ae 13809 return lcommunity_list_set_vty(vty, argc, argv,
13810 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
13811}
13812
13813DEFUN (ip_lcommunity_list_expanded,
13814 ip_lcommunity_list_expanded_cmd,
13815 "ip large-community-list (100-500) <deny|permit> LINE...",
13816 IP_STR
13817 LCOMMUNITY_LIST_STR
13818 "Large Community list number (expanded)\n"
13819 "Specify large community to reject\n"
13820 "Specify large community to accept\n"
13821 "An ordered list as a regular-expression\n")
13822{
d62a17ae 13823 return lcommunity_list_set_vty(vty, argc, argv,
13824 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
13825}
13826
13827DEFUN (ip_lcommunity_list_name_standard,
13828 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
13829 "ip large-community-list standard WORD <deny|permit>",
13830 IP_STR
13831 LCOMMUNITY_LIST_STR
13832 "Specify standard large-community-list\n"
13833 "Large Community list name\n"
13834 "Specify large community to reject\n"
13835 "Specify large community to accept\n")
13836{
d62a17ae 13837 return lcommunity_list_set_vty(vty, argc, argv,
13838 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
13839}
13840
13841DEFUN (ip_lcommunity_list_name_standard1,
13842 ip_lcommunity_list_name_standard1_cmd,
13843 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
13844 IP_STR
13845 LCOMMUNITY_LIST_STR
13846 "Specify standard large-community-list\n"
13847 "Large Community list name\n"
13848 "Specify large community to reject\n"
13849 "Specify large community to accept\n"
13850 LCOMMUNITY_VAL_STR)
13851{
d62a17ae 13852 return lcommunity_list_set_vty(vty, argc, argv,
13853 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
13854}
13855
13856DEFUN (ip_lcommunity_list_name_expanded,
13857 ip_lcommunity_list_name_expanded_cmd,
13858 "ip large-community-list expanded WORD <deny|permit> LINE...",
13859 IP_STR
13860 LCOMMUNITY_LIST_STR
13861 "Specify expanded large-community-list\n"
13862 "Large Community list name\n"
13863 "Specify large community to reject\n"
13864 "Specify large community to accept\n"
13865 "An ordered list as a regular-expression\n")
13866{
d62a17ae 13867 return lcommunity_list_set_vty(vty, argc, argv,
13868 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
13869}
13870
13871DEFUN (no_ip_lcommunity_list_standard_all,
13872 no_ip_lcommunity_list_standard_all_cmd,
13873 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13874 NO_STR
13875 IP_STR
13876 LCOMMUNITY_LIST_STR
13877 "Large Community list number (standard)\n"
13878 "Large Community list number (expanded)\n"
13879 "Large Community list name\n")
13880{
d62a17ae 13881 return lcommunity_list_unset_vty(vty, argc, argv,
13882 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13883}
13884
13885DEFUN (no_ip_lcommunity_list_name_expanded_all,
13886 no_ip_lcommunity_list_name_expanded_all_cmd,
13887 "no ip large-community-list expanded WORD",
13888 NO_STR
13889 IP_STR
13890 LCOMMUNITY_LIST_STR
13891 "Specify expanded large-community-list\n"
13892 "Large Community list name\n")
13893{
d62a17ae 13894 return lcommunity_list_unset_vty(vty, argc, argv,
13895 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13896}
13897
13898DEFUN (no_ip_lcommunity_list_standard,
13899 no_ip_lcommunity_list_standard_cmd,
13900 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13901 NO_STR
13902 IP_STR
13903 LCOMMUNITY_LIST_STR
13904 "Large Community list number (standard)\n"
13905 "Specify large community to reject\n"
13906 "Specify large community to accept\n"
13907 LCOMMUNITY_VAL_STR)
13908{
d62a17ae 13909 return lcommunity_list_unset_vty(vty, argc, argv,
13910 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13911}
13912
13913DEFUN (no_ip_lcommunity_list_expanded,
13914 no_ip_lcommunity_list_expanded_cmd,
13915 "no ip large-community-list (100-500) <deny|permit> LINE...",
13916 NO_STR
13917 IP_STR
13918 LCOMMUNITY_LIST_STR
13919 "Large Community list number (expanded)\n"
13920 "Specify large community to reject\n"
13921 "Specify large community to accept\n"
13922 "An ordered list as a regular-expression\n")
13923{
d62a17ae 13924 return lcommunity_list_unset_vty(vty, argc, argv,
13925 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13926}
13927
13928DEFUN (no_ip_lcommunity_list_name_standard,
13929 no_ip_lcommunity_list_name_standard_cmd,
13930 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
13931 NO_STR
13932 IP_STR
13933 LCOMMUNITY_LIST_STR
13934 "Specify standard large-community-list\n"
13935 "Large Community list name\n"
13936 "Specify large community to reject\n"
13937 "Specify large community to accept\n"
13938 LCOMMUNITY_VAL_STR)
13939{
d62a17ae 13940 return lcommunity_list_unset_vty(vty, argc, argv,
13941 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13942}
13943
13944DEFUN (no_ip_lcommunity_list_name_expanded,
13945 no_ip_lcommunity_list_name_expanded_cmd,
13946 "no ip large-community-list expanded WORD <deny|permit> LINE...",
13947 NO_STR
13948 IP_STR
13949 LCOMMUNITY_LIST_STR
13950 "Specify expanded large-community-list\n"
13951 "Large community list name\n"
13952 "Specify large community to reject\n"
13953 "Specify large community to accept\n"
13954 "An ordered list as a regular-expression\n")
13955{
d62a17ae 13956 return lcommunity_list_unset_vty(vty, argc, argv,
13957 LARGE_COMMUNITY_LIST_EXPANDED);
13958}
13959
13960static void lcommunity_list_show(struct vty *vty, struct community_list *list)
13961{
13962 struct community_entry *entry;
13963
13964 for (entry = list->head; entry; entry = entry->next) {
13965 if (entry == list->head) {
13966 if (all_digit(list->name))
13967 vty_out(vty, "Large community %s list %s\n",
13968 entry->style == EXTCOMMUNITY_LIST_STANDARD
13969 ? "standard"
13970 : "(expanded) access",
13971 list->name);
13972 else
13973 vty_out(vty,
13974 "Named large community %s list %s\n",
13975 entry->style == EXTCOMMUNITY_LIST_STANDARD
13976 ? "standard"
13977 : "expanded",
13978 list->name);
13979 }
13980 if (entry->any)
13981 vty_out(vty, " %s\n",
13982 community_direct_str(entry->direct));
13983 else
13984 vty_out(vty, " %s %s\n",
13985 community_direct_str(entry->direct),
13986 entry->style == EXTCOMMUNITY_LIST_STANDARD
13987 ? entry->u.ecom->str
13988 : entry->config);
13989 }
57d187bc
JS
13990}
13991
13992DEFUN (show_ip_lcommunity_list,
13993 show_ip_lcommunity_list_cmd,
13994 "show ip large-community-list",
13995 SHOW_STR
13996 IP_STR
13997 "List large-community list\n")
13998{
d62a17ae 13999 struct community_list *list;
14000 struct community_list_master *cm;
57d187bc 14001
d62a17ae 14002 cm = community_list_master_lookup(bgp_clist,
14003 LARGE_COMMUNITY_LIST_MASTER);
14004 if (!cm)
14005 return CMD_SUCCESS;
57d187bc 14006
d62a17ae 14007 for (list = cm->num.head; list; list = list->next)
14008 lcommunity_list_show(vty, list);
57d187bc 14009
d62a17ae 14010 for (list = cm->str.head; list; list = list->next)
14011 lcommunity_list_show(vty, list);
57d187bc 14012
d62a17ae 14013 return CMD_SUCCESS;
57d187bc
JS
14014}
14015
14016DEFUN (show_ip_lcommunity_list_arg,
14017 show_ip_lcommunity_list_arg_cmd,
14018 "show ip large-community-list <(1-500)|WORD>",
14019 SHOW_STR
14020 IP_STR
14021 "List large-community list\n"
14022 "large-community-list number\n"
14023 "large-community-list name\n")
14024{
d62a17ae 14025 struct community_list *list;
57d187bc 14026
d62a17ae 14027 list = community_list_lookup(bgp_clist, argv[3]->arg,
14028 LARGE_COMMUNITY_LIST_MASTER);
14029 if (!list) {
14030 vty_out(vty, "%% Can't find extcommunity-list\n");
14031 return CMD_WARNING;
14032 }
57d187bc 14033
d62a17ae 14034 lcommunity_list_show(vty, list);
57d187bc 14035
d62a17ae 14036 return CMD_SUCCESS;
57d187bc
JS
14037}
14038
718e3744 14039/* "extcommunity-list" keyword help string. */
14040#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14041#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14042
14043DEFUN (ip_extcommunity_list_standard,
14044 ip_extcommunity_list_standard_cmd,
e961923c 14045 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14046 IP_STR
14047 EXTCOMMUNITY_LIST_STR
14048 "Extended Community list number (standard)\n"
718e3744 14049 "Specify standard extcommunity-list\n"
5bf15956 14050 "Community list name\n"
718e3744 14051 "Specify community to reject\n"
14052 "Specify community to accept\n"
14053 EXTCOMMUNITY_VAL_STR)
14054{
d62a17ae 14055 int style = EXTCOMMUNITY_LIST_STANDARD;
14056 int direct = 0;
14057 char *cl_number_or_name = NULL;
42f914d4 14058
d62a17ae 14059 int idx = 0;
14060 argv_find(argv, argc, "(1-99)", &idx);
14061 argv_find(argv, argc, "WORD", &idx);
14062 cl_number_or_name = argv[idx]->arg;
14063 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14064 : COMMUNITY_DENY;
14065 argv_find(argv, argc, "AA:NN", &idx);
14066 char *str = argv_concat(argv, argc, idx);
42f914d4 14067
d62a17ae 14068 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14069 direct, style);
42f914d4 14070
d62a17ae 14071 XFREE(MTYPE_TMP, str);
42f914d4 14072
d62a17ae 14073 if (ret < 0) {
14074 community_list_perror(vty, ret);
14075 return CMD_WARNING_CONFIG_FAILED;
14076 }
42f914d4 14077
d62a17ae 14078 return CMD_SUCCESS;
718e3744 14079}
14080
718e3744 14081DEFUN (ip_extcommunity_list_name_expanded,
14082 ip_extcommunity_list_name_expanded_cmd,
e961923c 14083 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14084 IP_STR
14085 EXTCOMMUNITY_LIST_STR
5bf15956 14086 "Extended Community list number (expanded)\n"
718e3744 14087 "Specify expanded extcommunity-list\n"
14088 "Extended Community list name\n"
14089 "Specify community to reject\n"
14090 "Specify community to accept\n"
14091 "An ordered list as a regular-expression\n")
14092{
d62a17ae 14093 int style = EXTCOMMUNITY_LIST_EXPANDED;
14094 int direct = 0;
14095 char *cl_number_or_name = NULL;
42f914d4 14096
d62a17ae 14097 int idx = 0;
14098 argv_find(argv, argc, "(100-500)", &idx);
14099 argv_find(argv, argc, "WORD", &idx);
14100 cl_number_or_name = argv[idx]->arg;
14101 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14102 : COMMUNITY_DENY;
14103 argv_find(argv, argc, "LINE", &idx);
14104 char *str = argv_concat(argv, argc, idx);
42f914d4 14105
d62a17ae 14106 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14107 direct, style);
42f914d4 14108
d62a17ae 14109 XFREE(MTYPE_TMP, str);
42f914d4 14110
d62a17ae 14111 if (ret < 0) {
14112 community_list_perror(vty, ret);
14113 return CMD_WARNING_CONFIG_FAILED;
14114 }
42f914d4 14115
d62a17ae 14116 return CMD_SUCCESS;
718e3744 14117}
14118
fee6e4e4 14119DEFUN (no_ip_extcommunity_list_standard_all,
14120 no_ip_extcommunity_list_standard_all_cmd,
e961923c 14121 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
14122 NO_STR
14123 IP_STR
14124 EXTCOMMUNITY_LIST_STR
14125 "Extended Community list number (standard)\n"
718e3744 14126 "Specify standard extcommunity-list\n"
5bf15956 14127 "Community list name\n"
718e3744 14128 "Specify community to reject\n"
14129 "Specify community to accept\n"
14130 EXTCOMMUNITY_VAL_STR)
14131{
d62a17ae 14132 int style = EXTCOMMUNITY_LIST_STANDARD;
14133 int direct = 0;
14134 char *cl_number_or_name = NULL;
42f914d4 14135
d62a17ae 14136 int idx = 0;
14137 argv_find(argv, argc, "(1-99)", &idx);
14138 argv_find(argv, argc, "WORD", &idx);
14139 cl_number_or_name = argv[idx]->arg;
14140 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14141 : COMMUNITY_DENY;
14142 argv_find(argv, argc, "AA:NN", &idx);
14143 char *str = argv_concat(argv, argc, idx);
42f914d4 14144
d62a17ae 14145 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14146 direct, style);
42f914d4 14147
d62a17ae 14148 XFREE(MTYPE_TMP, str);
42f914d4 14149
d62a17ae 14150 if (ret < 0) {
14151 community_list_perror(vty, ret);
14152 return CMD_WARNING_CONFIG_FAILED;
14153 }
42f914d4 14154
d62a17ae 14155 return CMD_SUCCESS;
718e3744 14156}
14157
5bf15956
DW
14158DEFUN (no_ip_extcommunity_list_expanded_all,
14159 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 14160 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14161 NO_STR
14162 IP_STR
14163 EXTCOMMUNITY_LIST_STR
14164 "Extended Community list number (expanded)\n"
718e3744 14165 "Specify expanded extcommunity-list\n"
5bf15956 14166 "Extended Community list name\n"
718e3744 14167 "Specify community to reject\n"
14168 "Specify community to accept\n"
14169 "An ordered list as a regular-expression\n")
14170{
d62a17ae 14171 int style = EXTCOMMUNITY_LIST_EXPANDED;
14172 int direct = 0;
14173 char *cl_number_or_name = NULL;
42f914d4 14174
d62a17ae 14175 int idx = 0;
14176 argv_find(argv, argc, "(100-500)", &idx);
14177 argv_find(argv, argc, "WORD", &idx);
14178 cl_number_or_name = argv[idx]->arg;
14179 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14180 : COMMUNITY_DENY;
14181 argv_find(argv, argc, "LINE", &idx);
14182 char *str = argv_concat(argv, argc, idx);
42f914d4 14183
d62a17ae 14184 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14185 direct, style);
42f914d4 14186
d62a17ae 14187 XFREE(MTYPE_TMP, str);
42f914d4 14188
d62a17ae 14189 if (ret < 0) {
14190 community_list_perror(vty, ret);
14191 return CMD_WARNING_CONFIG_FAILED;
14192 }
42f914d4 14193
d62a17ae 14194 return CMD_SUCCESS;
718e3744 14195}
14196
d62a17ae 14197static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 14198{
d62a17ae 14199 struct community_entry *entry;
718e3744 14200
d62a17ae 14201 for (entry = list->head; entry; entry = entry->next) {
14202 if (entry == list->head) {
14203 if (all_digit(list->name))
14204 vty_out(vty, "Extended community %s list %s\n",
14205 entry->style == EXTCOMMUNITY_LIST_STANDARD
14206 ? "standard"
14207 : "(expanded) access",
14208 list->name);
14209 else
14210 vty_out(vty,
14211 "Named extended community %s list %s\n",
14212 entry->style == EXTCOMMUNITY_LIST_STANDARD
14213 ? "standard"
14214 : "expanded",
14215 list->name);
14216 }
14217 if (entry->any)
14218 vty_out(vty, " %s\n",
14219 community_direct_str(entry->direct));
14220 else
14221 vty_out(vty, " %s %s\n",
14222 community_direct_str(entry->direct),
14223 entry->style == EXTCOMMUNITY_LIST_STANDARD
14224 ? entry->u.ecom->str
14225 : entry->config);
14226 }
718e3744 14227}
14228
14229DEFUN (show_ip_extcommunity_list,
14230 show_ip_extcommunity_list_cmd,
14231 "show ip extcommunity-list",
14232 SHOW_STR
14233 IP_STR
14234 "List extended-community list\n")
14235{
d62a17ae 14236 struct community_list *list;
14237 struct community_list_master *cm;
718e3744 14238
d62a17ae 14239 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14240 if (!cm)
14241 return CMD_SUCCESS;
718e3744 14242
d62a17ae 14243 for (list = cm->num.head; list; list = list->next)
14244 extcommunity_list_show(vty, list);
718e3744 14245
d62a17ae 14246 for (list = cm->str.head; list; list = list->next)
14247 extcommunity_list_show(vty, list);
718e3744 14248
d62a17ae 14249 return CMD_SUCCESS;
718e3744 14250}
14251
14252DEFUN (show_ip_extcommunity_list_arg,
14253 show_ip_extcommunity_list_arg_cmd,
6147e2c6 14254 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 14255 SHOW_STR
14256 IP_STR
14257 "List extended-community list\n"
14258 "Extcommunity-list number\n"
14259 "Extcommunity-list name\n")
14260{
d62a17ae 14261 int idx_comm_list = 3;
14262 struct community_list *list;
718e3744 14263
d62a17ae 14264 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14265 EXTCOMMUNITY_LIST_MASTER);
14266 if (!list) {
14267 vty_out(vty, "%% Can't find extcommunity-list\n");
14268 return CMD_WARNING;
14269 }
718e3744 14270
d62a17ae 14271 extcommunity_list_show(vty, list);
718e3744 14272
d62a17ae 14273 return CMD_SUCCESS;
718e3744 14274}
6b0655a2 14275
718e3744 14276/* Return configuration string of community-list entry. */
d62a17ae 14277static const char *community_list_config_str(struct community_entry *entry)
718e3744 14278{
d62a17ae 14279 const char *str;
718e3744 14280
d62a17ae 14281 if (entry->any)
14282 str = "";
14283 else {
14284 if (entry->style == COMMUNITY_LIST_STANDARD)
a69ea8ae 14285 str = community_str(entry->u.com, false);
d62a17ae 14286 else
14287 str = entry->config;
14288 }
14289 return str;
718e3744 14290}
14291
14292/* Display community-list and extcommunity-list configuration. */
d62a17ae 14293static int community_list_config_write(struct vty *vty)
14294{
14295 struct community_list *list;
14296 struct community_entry *entry;
14297 struct community_list_master *cm;
14298 int write = 0;
14299
14300 /* Community-list. */
14301 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14302
14303 for (list = cm->num.head; list; list = list->next)
14304 for (entry = list->head; entry; entry = entry->next) {
14305 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14306 community_direct_str(entry->direct),
14307 community_list_config_str(entry));
14308 write++;
14309 }
14310 for (list = cm->str.head; list; list = list->next)
14311 for (entry = list->head; entry; entry = entry->next) {
14312 vty_out(vty, "ip community-list %s %s %s %s\n",
14313 entry->style == COMMUNITY_LIST_STANDARD
14314 ? "standard"
14315 : "expanded",
14316 list->name, community_direct_str(entry->direct),
14317 community_list_config_str(entry));
14318 write++;
14319 }
14320
14321 /* Extcommunity-list. */
14322 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14323
14324 for (list = cm->num.head; list; list = list->next)
14325 for (entry = list->head; entry; entry = entry->next) {
14326 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14327 list->name, community_direct_str(entry->direct),
14328 community_list_config_str(entry));
14329 write++;
14330 }
14331 for (list = cm->str.head; list; list = list->next)
14332 for (entry = list->head; entry; entry = entry->next) {
14333 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14334 entry->style == EXTCOMMUNITY_LIST_STANDARD
14335 ? "standard"
14336 : "expanded",
14337 list->name, community_direct_str(entry->direct),
14338 community_list_config_str(entry));
14339 write++;
14340 }
14341
14342
14343 /* lcommunity-list. */
14344 cm = community_list_master_lookup(bgp_clist,
14345 LARGE_COMMUNITY_LIST_MASTER);
14346
14347 for (list = cm->num.head; list; list = list->next)
14348 for (entry = list->head; entry; entry = entry->next) {
14349 vty_out(vty, "ip large-community-list %s %s %s\n",
14350 list->name, community_direct_str(entry->direct),
14351 community_list_config_str(entry));
14352 write++;
14353 }
14354 for (list = cm->str.head; list; list = list->next)
14355 for (entry = list->head; entry; entry = entry->next) {
14356 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14357 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14358 ? "standard"
14359 : "expanded",
14360 list->name, community_direct_str(entry->direct),
14361 community_list_config_str(entry));
14362 write++;
14363 }
14364
14365 return write;
14366}
14367
14368static struct cmd_node community_list_node = {
14369 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 14370};
14371
d62a17ae 14372static void community_list_vty(void)
14373{
14374 install_node(&community_list_node, community_list_config_write);
14375
14376 /* Community-list. */
14377 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14378 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14379 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14380 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14381 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14382 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14383
14384 /* Extcommunity-list. */
14385 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14386 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14387 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14388 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14389 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14390 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14391
14392 /* Large Community List */
14393 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14394 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14395 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14396 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14397 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14398 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14399 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14400 install_element(CONFIG_NODE,
14401 &no_ip_lcommunity_list_name_expanded_all_cmd);
14402 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14403 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14404 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14405 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14406 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14407 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 14408}