]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #2250 from donaldsharp/watchfrr
[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;
3ae8bfa5 556 bool found = false;
d62a17ae 557 struct peer *peer;
558 struct listnode *node, *nnode;
559
560 /* Clear all neighbors. */
561 /*
562 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
563 * nodes on the BGP instance as that may get freed if it is a
564 * doppelganger
d62a17ae 565 */
566 if (sort == clear_all) {
567 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
3ae8bfa5
PM
568 if (!peer->afc[afi][safi])
569 continue;
570
d62a17ae 571 if (stype == BGP_CLEAR_SOFT_NONE)
572 ret = peer_clear(peer, &nnode);
d62a17ae 573 else
3ae8bfa5 574 ret = peer_clear_soft(peer, afi, safi, stype);
d62a17ae 575
576 if (ret < 0)
577 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
578 else
579 found = true;
04b6bdc0 580 }
d62a17ae 581
582 /* This is to apply read-only mode on this clear. */
583 if (stype == BGP_CLEAR_SOFT_NONE)
584 bgp->update_delay_over = 0;
585
3ae8bfa5
PM
586 if (!found)
587 vty_out(vty, "%%BGP: No %s peer configured",
588 afi_safi_print(afi, safi));
589
d62a17ae 590 return CMD_SUCCESS;
7aafcaca
DS
591 }
592
3ae8bfa5 593 /* Clear specified neighbor. */
d62a17ae 594 if (sort == clear_peer) {
595 union sockunion su;
d62a17ae 596
597 /* Make sockunion for lookup. */
598 ret = str2sockunion(arg, &su);
599 if (ret < 0) {
600 peer = peer_lookup_by_conf_if(bgp, arg);
601 if (!peer) {
602 peer = peer_lookup_by_hostname(bgp, arg);
603 if (!peer) {
604 vty_out(vty,
605 "Malformed address or name: %s\n",
606 arg);
607 return CMD_WARNING;
608 }
609 }
610 } else {
611 peer = peer_lookup(bgp, &su);
612 if (!peer) {
613 vty_out(vty,
614 "%%BGP: Unknown neighbor - \"%s\"\n",
615 arg);
616 return CMD_WARNING;
617 }
618 }
7aafcaca 619
3ae8bfa5
PM
620 if (!peer->afc[afi][safi])
621 ret = BGP_ERR_AF_UNCONFIGURED;
622 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 623 ret = peer_clear(peer, NULL);
624 else
625 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 626
d62a17ae 627 if (ret < 0)
628 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 629
d62a17ae 630 return CMD_SUCCESS;
7aafcaca 631 }
7aafcaca 632
3ae8bfa5 633 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 634 if (sort == clear_group) {
635 struct peer_group *group;
7aafcaca 636
d62a17ae 637 group = peer_group_lookup(bgp, arg);
638 if (!group) {
639 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
640 return CMD_WARNING;
641 }
642
643 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
d62a17ae 644 if (!peer->afc[afi][safi])
645 continue;
646
3ae8bfa5
PM
647 if (stype == BGP_CLEAR_SOFT_NONE)
648 ret = peer_clear(peer, NULL);
649 else
650 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 651
d62a17ae 652 if (ret < 0)
653 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
654 else
655 found = true;
d62a17ae 656 }
3ae8bfa5
PM
657
658 if (!found)
659 vty_out(vty,
660 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
661 afi_safi_print(afi, safi), arg);
662
d62a17ae 663 return CMD_SUCCESS;
7aafcaca 664 }
7aafcaca 665
3ae8bfa5 666 /* Clear all external (eBGP) neighbors. */
d62a17ae 667 if (sort == clear_external) {
668 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
669 if (peer->sort == BGP_PEER_IBGP)
670 continue;
7aafcaca 671
3ae8bfa5
PM
672 if (!peer->afc[afi][safi])
673 continue;
674
d62a17ae 675 if (stype == BGP_CLEAR_SOFT_NONE)
676 ret = peer_clear(peer, &nnode);
677 else
678 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 679
d62a17ae 680 if (ret < 0)
681 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
682 else
683 found = true;
d62a17ae 684 }
3ae8bfa5
PM
685
686 if (!found)
687 vty_out(vty,
688 "%%BGP: No external %s peer is configured\n",
689 afi_safi_print(afi, safi));
690
d62a17ae 691 return CMD_SUCCESS;
692 }
693
3ae8bfa5 694 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 695 if (sort == clear_as) {
3ae8bfa5 696 as_t as = strtoul(arg, NULL, 10);
d62a17ae 697
698 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
699 if (peer->as != as)
700 continue;
701
3ae8bfa5
PM
702 if (!peer->afc[afi][safi])
703 ret = BGP_ERR_AF_UNCONFIGURED;
704 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 705 ret = peer_clear(peer, &nnode);
706 else
707 ret = peer_clear_soft(peer, afi, safi, stype);
708
709 if (ret < 0)
710 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
711 else
712 found = true;
d62a17ae 713 }
3ae8bfa5
PM
714
715 if (!found)
d62a17ae 716 vty_out(vty,
3ae8bfa5
PM
717 "%%BGP: No %s peer is configured with AS %s\n",
718 afi_safi_print(afi, safi), arg);
719
d62a17ae 720 return CMD_SUCCESS;
721 }
722
723 return CMD_SUCCESS;
724}
725
726static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
727 safi_t safi, enum clear_sort sort,
728 enum bgp_clear_type stype, const char *arg)
729{
730 struct bgp *bgp;
731
732 /* BGP structure lookup. */
733 if (name) {
734 bgp = bgp_lookup_by_name(name);
735 if (bgp == NULL) {
736 vty_out(vty, "Can't find BGP instance %s\n", name);
737 return CMD_WARNING;
738 }
739 } else {
740 bgp = bgp_get_default();
741 if (bgp == NULL) {
742 vty_out(vty, "No BGP process is configured\n");
743 return CMD_WARNING;
744 }
745 }
746
747 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
748}
749
750/* clear soft inbound */
d62a17ae 751static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 752{
d62a17ae 753 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
754 BGP_CLEAR_SOFT_IN, NULL);
755 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
756 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
757}
758
759/* clear soft outbound */
d62a17ae 760static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 761{
d62a17ae 762 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
763 BGP_CLEAR_SOFT_OUT, NULL);
764 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
765 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
766}
767
768
f787d7a0 769#ifndef VTYSH_EXTRACT_PL
2e4c2296 770#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
771#endif
772
718e3744 773/* BGP global configuration. */
774
775DEFUN (bgp_multiple_instance_func,
776 bgp_multiple_instance_cmd,
777 "bgp multiple-instance",
778 BGP_STR
779 "Enable bgp multiple instance\n")
780{
d62a17ae 781 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
782 return CMD_SUCCESS;
718e3744 783}
784
785DEFUN (no_bgp_multiple_instance,
786 no_bgp_multiple_instance_cmd,
787 "no bgp multiple-instance",
788 NO_STR
789 BGP_STR
790 "BGP multiple instance\n")
791{
d62a17ae 792 int ret;
718e3744 793
d62a17ae 794 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
795 if (ret < 0) {
796 vty_out(vty, "%% There are more than two BGP instances\n");
797 return CMD_WARNING_CONFIG_FAILED;
798 }
799 return CMD_SUCCESS;
718e3744 800}
801
802DEFUN (bgp_config_type,
803 bgp_config_type_cmd,
6147e2c6 804 "bgp config-type <cisco|zebra>",
718e3744 805 BGP_STR
806 "Configuration type\n"
807 "cisco\n"
808 "zebra\n")
809{
d62a17ae 810 int idx = 0;
811 if (argv_find(argv, argc, "cisco", &idx))
812 bgp_option_set(BGP_OPT_CONFIG_CISCO);
813 else
814 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 815
d62a17ae 816 return CMD_SUCCESS;
718e3744 817}
818
819DEFUN (no_bgp_config_type,
820 no_bgp_config_type_cmd,
c7178fe7 821 "no bgp config-type [<cisco|zebra>]",
718e3744 822 NO_STR
823 BGP_STR
838758ac
DW
824 "Display configuration type\n"
825 "cisco\n"
826 "zebra\n")
718e3744 827{
d62a17ae 828 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
829 return CMD_SUCCESS;
718e3744 830}
831
813d4307 832
718e3744 833DEFUN (no_synchronization,
834 no_synchronization_cmd,
835 "no synchronization",
836 NO_STR
837 "Perform IGP synchronization\n")
838{
d62a17ae 839 return CMD_SUCCESS;
718e3744 840}
841
842DEFUN (no_auto_summary,
843 no_auto_summary_cmd,
844 "no auto-summary",
845 NO_STR
846 "Enable automatic network number summarization\n")
847{
d62a17ae 848 return CMD_SUCCESS;
718e3744 849}
3d515fd9 850
718e3744 851/* "router bgp" commands. */
505e5056 852DEFUN_NOSH (router_bgp,
f412b39a 853 router_bgp_cmd,
18c57037 854 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 855 ROUTER_STR
856 BGP_STR
31500417
DW
857 AS_STR
858 BGP_INSTANCE_HELP_STR)
718e3744 859{
d62a17ae 860 int idx_asn = 2;
861 int idx_view_vrf = 3;
862 int idx_vrf = 4;
863 int ret;
864 as_t as;
865 struct bgp *bgp;
866 const char *name = NULL;
867 enum bgp_instance_type inst_type;
868
869 // "router bgp" without an ASN
870 if (argc == 2) {
871 // Pending: Make VRF option available for ASN less config
872 bgp = bgp_get_default();
873
874 if (bgp == NULL) {
875 vty_out(vty, "%% No BGP process is configured\n");
876 return CMD_WARNING_CONFIG_FAILED;
877 }
878
879 if (listcount(bm->bgp) > 1) {
996c9314 880 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 881 return CMD_WARNING_CONFIG_FAILED;
882 }
883 }
884
885 // "router bgp X"
886 else {
887 as = strtoul(argv[idx_asn]->arg, NULL, 10);
888
889 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
890 if (argc > 3) {
891 name = argv[idx_vrf]->arg;
892
893 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
894 inst_type = BGP_INSTANCE_TYPE_VRF;
895 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
896 inst_type = BGP_INSTANCE_TYPE_VIEW;
897 }
898
899 ret = bgp_get(&bgp, &as, name, inst_type);
900 switch (ret) {
901 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
902 vty_out(vty,
903 "Please specify 'bgp multiple-instance' first\n");
904 return CMD_WARNING_CONFIG_FAILED;
905 case BGP_ERR_AS_MISMATCH:
906 vty_out(vty, "BGP is already running; AS is %u\n", as);
907 return CMD_WARNING_CONFIG_FAILED;
908 case BGP_ERR_INSTANCE_MISMATCH:
909 vty_out(vty,
910 "BGP instance name and AS number mismatch\n");
911 vty_out(vty,
912 "BGP instance is already running; AS is %u\n",
913 as);
914 return CMD_WARNING_CONFIG_FAILED;
915 }
916
917 /* Pending: handle when user tries to change a view to vrf n vv.
918 */
919 }
920
0b5131c9
MK
921 /* unset the auto created flag as the user config is now present */
922 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 923 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
924
925 return CMD_SUCCESS;
718e3744 926}
927
718e3744 928/* "no router bgp" commands. */
929DEFUN (no_router_bgp,
930 no_router_bgp_cmd,
18c57037 931 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 932 NO_STR
933 ROUTER_STR
934 BGP_STR
31500417
DW
935 AS_STR
936 BGP_INSTANCE_HELP_STR)
718e3744 937{
d62a17ae 938 int idx_asn = 3;
939 int idx_vrf = 5;
940 as_t as;
941 struct bgp *bgp;
942 const char *name = NULL;
718e3744 943
d62a17ae 944 // "no router bgp" without an ASN
945 if (argc == 3) {
946 // Pending: Make VRF option available for ASN less config
947 bgp = bgp_get_default();
718e3744 948
d62a17ae 949 if (bgp == NULL) {
950 vty_out(vty, "%% No BGP process is configured\n");
951 return CMD_WARNING_CONFIG_FAILED;
952 }
7fb21a9f 953
d62a17ae 954 if (listcount(bm->bgp) > 1) {
996c9314 955 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 956 return CMD_WARNING_CONFIG_FAILED;
957 }
0b5131c9
MK
958
959 if (bgp->l3vni) {
960 vty_out(vty, "%% Please unconfigure l3vni %u",
961 bgp->l3vni);
962 return CMD_WARNING_CONFIG_FAILED;
963 }
d62a17ae 964 } else {
965 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 966
d62a17ae 967 if (argc > 4)
968 name = argv[idx_vrf]->arg;
7fb21a9f 969
d62a17ae 970 /* Lookup bgp structure. */
971 bgp = bgp_lookup(as, name);
972 if (!bgp) {
973 vty_out(vty, "%% Can't find BGP instance\n");
974 return CMD_WARNING_CONFIG_FAILED;
975 }
0b5131c9
MK
976
977 if (bgp->l3vni) {
978 vty_out(vty, "%% Please unconfigure l3vni %u",
979 bgp->l3vni);
980 return CMD_WARNING_CONFIG_FAILED;
981 }
d62a17ae 982 }
718e3744 983
d62a17ae 984 bgp_delete(bgp);
718e3744 985
d62a17ae 986 return CMD_SUCCESS;
718e3744 987}
988
6b0655a2 989
718e3744 990/* BGP router-id. */
991
f787d7a0 992DEFPY (bgp_router_id,
718e3744 993 bgp_router_id_cmd,
994 "bgp router-id A.B.C.D",
995 BGP_STR
996 "Override configured router identifier\n"
997 "Manually configured router identifier\n")
998{
d62a17ae 999 VTY_DECLVAR_CONTEXT(bgp, bgp);
1000 bgp_router_id_static_set(bgp, router_id);
1001 return CMD_SUCCESS;
718e3744 1002}
1003
f787d7a0 1004DEFPY (no_bgp_router_id,
718e3744 1005 no_bgp_router_id_cmd,
31500417 1006 "no bgp router-id [A.B.C.D]",
718e3744 1007 NO_STR
1008 BGP_STR
31500417
DW
1009 "Override configured router identifier\n"
1010 "Manually configured router identifier\n")
718e3744 1011{
d62a17ae 1012 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1013
d62a17ae 1014 if (router_id_str) {
1015 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1016 vty_out(vty, "%% BGP router-id doesn't match\n");
1017 return CMD_WARNING_CONFIG_FAILED;
1018 }
e018c7cc 1019 }
718e3744 1020
d62a17ae 1021 router_id.s_addr = 0;
1022 bgp_router_id_static_set(bgp, router_id);
718e3744 1023
d62a17ae 1024 return CMD_SUCCESS;
718e3744 1025}
1026
6b0655a2 1027
718e3744 1028/* BGP Cluster ID. */
718e3744 1029DEFUN (bgp_cluster_id,
1030 bgp_cluster_id_cmd,
838758ac 1031 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1032 BGP_STR
1033 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1034 "Route-Reflector Cluster-id in IP address format\n"
1035 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1036{
d62a17ae 1037 VTY_DECLVAR_CONTEXT(bgp, bgp);
1038 int idx_ipv4 = 2;
1039 int ret;
1040 struct in_addr cluster;
718e3744 1041
d62a17ae 1042 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1043 if (!ret) {
1044 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1045 return CMD_WARNING_CONFIG_FAILED;
1046 }
718e3744 1047
d62a17ae 1048 bgp_cluster_id_set(bgp, &cluster);
1049 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1050
d62a17ae 1051 return CMD_SUCCESS;
718e3744 1052}
1053
718e3744 1054DEFUN (no_bgp_cluster_id,
1055 no_bgp_cluster_id_cmd,
c7178fe7 1056 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1057 NO_STR
1058 BGP_STR
838758ac
DW
1059 "Configure Route-Reflector Cluster-id\n"
1060 "Route-Reflector Cluster-id in IP address format\n"
1061 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1062{
d62a17ae 1063 VTY_DECLVAR_CONTEXT(bgp, bgp);
1064 bgp_cluster_id_unset(bgp);
1065 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1066
d62a17ae 1067 return CMD_SUCCESS;
718e3744 1068}
1069
718e3744 1070DEFUN (bgp_confederation_identifier,
1071 bgp_confederation_identifier_cmd,
9ccf14f7 1072 "bgp confederation identifier (1-4294967295)",
718e3744 1073 "BGP specific commands\n"
1074 "AS confederation parameters\n"
1075 "AS number\n"
1076 "Set routing domain confederation AS\n")
1077{
d62a17ae 1078 VTY_DECLVAR_CONTEXT(bgp, bgp);
1079 int idx_number = 3;
1080 as_t as;
718e3744 1081
d62a17ae 1082 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1083
d62a17ae 1084 bgp_confederation_id_set(bgp, as);
718e3744 1085
d62a17ae 1086 return CMD_SUCCESS;
718e3744 1087}
1088
1089DEFUN (no_bgp_confederation_identifier,
1090 no_bgp_confederation_identifier_cmd,
838758ac 1091 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1092 NO_STR
1093 "BGP specific commands\n"
1094 "AS confederation parameters\n"
3a2d747c
QY
1095 "AS number\n"
1096 "Set routing domain confederation AS\n")
718e3744 1097{
d62a17ae 1098 VTY_DECLVAR_CONTEXT(bgp, bgp);
1099 bgp_confederation_id_unset(bgp);
718e3744 1100
d62a17ae 1101 return CMD_SUCCESS;
718e3744 1102}
1103
718e3744 1104DEFUN (bgp_confederation_peers,
1105 bgp_confederation_peers_cmd,
12dcf78e 1106 "bgp confederation peers (1-4294967295)...",
718e3744 1107 "BGP specific commands\n"
1108 "AS confederation parameters\n"
1109 "Peer ASs in BGP confederation\n"
1110 AS_STR)
1111{
d62a17ae 1112 VTY_DECLVAR_CONTEXT(bgp, bgp);
1113 int idx_asn = 3;
1114 as_t as;
1115 int i;
718e3744 1116
d62a17ae 1117 for (i = idx_asn; i < argc; i++) {
1118 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1119
d62a17ae 1120 if (bgp->as == as) {
1121 vty_out(vty,
1122 "%% Local member-AS not allowed in confed peer list\n");
1123 continue;
1124 }
718e3744 1125
d62a17ae 1126 bgp_confederation_peers_add(bgp, as);
1127 }
1128 return CMD_SUCCESS;
718e3744 1129}
1130
1131DEFUN (no_bgp_confederation_peers,
1132 no_bgp_confederation_peers_cmd,
e83a9414 1133 "no bgp confederation peers (1-4294967295)...",
718e3744 1134 NO_STR
1135 "BGP specific commands\n"
1136 "AS confederation parameters\n"
1137 "Peer ASs in BGP confederation\n"
1138 AS_STR)
1139{
d62a17ae 1140 VTY_DECLVAR_CONTEXT(bgp, bgp);
1141 int idx_asn = 4;
1142 as_t as;
1143 int i;
718e3744 1144
d62a17ae 1145 for (i = idx_asn; i < argc; i++) {
1146 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1147
d62a17ae 1148 bgp_confederation_peers_remove(bgp, as);
1149 }
1150 return CMD_SUCCESS;
718e3744 1151}
6b0655a2 1152
5e242b0d
DS
1153/**
1154 * Central routine for maximum-paths configuration.
1155 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1156 * @set: 1 for setting values, 0 for removing the max-paths config.
1157 */
d62a17ae 1158static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1159 const char *mpaths, uint16_t options,
d62a17ae 1160 int set)
1161{
1162 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1163 uint16_t maxpaths = 0;
d62a17ae 1164 int ret;
1165 afi_t afi;
1166 safi_t safi;
1167
1168 afi = bgp_node_afi(vty);
1169 safi = bgp_node_safi(vty);
1170
1171 if (set) {
1172 maxpaths = strtol(mpaths, NULL, 10);
1173 if (maxpaths > multipath_num) {
1174 vty_out(vty,
1175 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1176 maxpaths, multipath_num);
1177 return CMD_WARNING_CONFIG_FAILED;
1178 }
1179 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1180 options);
1181 } else
1182 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1183
1184 if (ret < 0) {
1185 vty_out(vty,
1186 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1187 (set == 1) ? "" : "un",
1188 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1189 maxpaths, afi, safi);
1190 return CMD_WARNING_CONFIG_FAILED;
1191 }
1192
1193 bgp_recalculate_all_bestpaths(bgp);
1194
1195 return CMD_SUCCESS;
165b5fff
JB
1196}
1197
abc920f8
DS
1198DEFUN (bgp_maxmed_admin,
1199 bgp_maxmed_admin_cmd,
1200 "bgp max-med administrative ",
1201 BGP_STR
1202 "Advertise routes with max-med\n"
1203 "Administratively applied, for an indefinite period\n")
1204{
d62a17ae 1205 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1206
d62a17ae 1207 bgp->v_maxmed_admin = 1;
1208 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1209
d62a17ae 1210 bgp_maxmed_update(bgp);
abc920f8 1211
d62a17ae 1212 return CMD_SUCCESS;
abc920f8
DS
1213}
1214
1215DEFUN (bgp_maxmed_admin_medv,
1216 bgp_maxmed_admin_medv_cmd,
4668a151 1217 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1218 BGP_STR
1219 "Advertise routes with max-med\n"
1220 "Administratively applied, for an indefinite period\n"
1221 "Max MED value to be used\n")
1222{
d62a17ae 1223 VTY_DECLVAR_CONTEXT(bgp, bgp);
1224 int idx_number = 3;
abc920f8 1225
d62a17ae 1226 bgp->v_maxmed_admin = 1;
1227 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1228
d62a17ae 1229 bgp_maxmed_update(bgp);
abc920f8 1230
d62a17ae 1231 return CMD_SUCCESS;
abc920f8
DS
1232}
1233
1234DEFUN (no_bgp_maxmed_admin,
1235 no_bgp_maxmed_admin_cmd,
4668a151 1236 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1237 NO_STR
1238 BGP_STR
1239 "Advertise routes with max-med\n"
838758ac
DW
1240 "Administratively applied, for an indefinite period\n"
1241 "Max MED value to be used\n")
abc920f8 1242{
d62a17ae 1243 VTY_DECLVAR_CONTEXT(bgp, bgp);
1244 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1245 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1246 bgp_maxmed_update(bgp);
abc920f8 1247
d62a17ae 1248 return CMD_SUCCESS;
abc920f8
DS
1249}
1250
abc920f8
DS
1251DEFUN (bgp_maxmed_onstartup,
1252 bgp_maxmed_onstartup_cmd,
4668a151 1253 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1254 BGP_STR
1255 "Advertise routes with max-med\n"
1256 "Effective on a startup\n"
1257 "Time (seconds) period for max-med\n"
1258 "Max MED value to be used\n")
1259{
d62a17ae 1260 VTY_DECLVAR_CONTEXT(bgp, bgp);
1261 int idx = 0;
4668a151 1262
d62a17ae 1263 argv_find(argv, argc, "(5-86400)", &idx);
1264 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1265 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1266 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1267 else
1268 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1269
d62a17ae 1270 bgp_maxmed_update(bgp);
abc920f8 1271
d62a17ae 1272 return CMD_SUCCESS;
abc920f8
DS
1273}
1274
1275DEFUN (no_bgp_maxmed_onstartup,
1276 no_bgp_maxmed_onstartup_cmd,
4668a151 1277 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1278 NO_STR
1279 BGP_STR
1280 "Advertise routes with max-med\n"
838758ac
DW
1281 "Effective on a startup\n"
1282 "Time (seconds) period for max-med\n"
1283 "Max MED value to be used\n")
abc920f8 1284{
d62a17ae 1285 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1286
d62a17ae 1287 /* Cancel max-med onstartup if its on */
1288 if (bgp->t_maxmed_onstartup) {
1289 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1290 bgp->maxmed_onstartup_over = 1;
1291 }
abc920f8 1292
d62a17ae 1293 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1294 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1295
d62a17ae 1296 bgp_maxmed_update(bgp);
abc920f8 1297
d62a17ae 1298 return CMD_SUCCESS;
abc920f8
DS
1299}
1300
d62a17ae 1301static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1302 const char *wait)
f188f2c4 1303{
d62a17ae 1304 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1305 uint16_t update_delay;
1306 uint16_t establish_wait;
f188f2c4 1307
d62a17ae 1308 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1309
d62a17ae 1310 if (!wait) /* update-delay <delay> */
1311 {
1312 bgp->v_update_delay = update_delay;
1313 bgp->v_establish_wait = bgp->v_update_delay;
1314 return CMD_SUCCESS;
1315 }
f188f2c4 1316
d62a17ae 1317 /* update-delay <delay> <establish-wait> */
1318 establish_wait = atoi(wait);
1319 if (update_delay < establish_wait) {
1320 vty_out(vty,
1321 "%%Failed: update-delay less than the establish-wait!\n");
1322 return CMD_WARNING_CONFIG_FAILED;
1323 }
f188f2c4 1324
d62a17ae 1325 bgp->v_update_delay = update_delay;
1326 bgp->v_establish_wait = establish_wait;
f188f2c4 1327
d62a17ae 1328 return CMD_SUCCESS;
f188f2c4
DS
1329}
1330
d62a17ae 1331static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1332{
d62a17ae 1333 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1334
d62a17ae 1335 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1336 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1337
d62a17ae 1338 return CMD_SUCCESS;
f188f2c4
DS
1339}
1340
2b791107 1341void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1342{
d62a17ae 1343 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1344 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1345 if (bgp->v_update_delay != bgp->v_establish_wait)
1346 vty_out(vty, " %d", bgp->v_establish_wait);
1347 vty_out(vty, "\n");
1348 }
f188f2c4
DS
1349}
1350
1351
1352/* Update-delay configuration */
1353DEFUN (bgp_update_delay,
1354 bgp_update_delay_cmd,
6147e2c6 1355 "update-delay (0-3600)",
f188f2c4
DS
1356 "Force initial delay for best-path and updates\n"
1357 "Seconds\n")
1358{
d62a17ae 1359 int idx_number = 1;
1360 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1361}
1362
1363DEFUN (bgp_update_delay_establish_wait,
1364 bgp_update_delay_establish_wait_cmd,
6147e2c6 1365 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1366 "Force initial delay for best-path and updates\n"
1367 "Seconds\n"
f188f2c4
DS
1368 "Seconds\n")
1369{
d62a17ae 1370 int idx_number = 1;
1371 int idx_number_2 = 2;
1372 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1373 argv[idx_number_2]->arg);
f188f2c4
DS
1374}
1375
1376/* Update-delay deconfiguration */
1377DEFUN (no_bgp_update_delay,
1378 no_bgp_update_delay_cmd,
838758ac
DW
1379 "no update-delay [(0-3600) [(1-3600)]]",
1380 NO_STR
f188f2c4 1381 "Force initial delay for best-path and updates\n"
838758ac 1382 "Seconds\n"
7111c1a0 1383 "Seconds\n")
f188f2c4 1384{
d62a17ae 1385 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1386}
1387
5e242b0d 1388
d62a17ae 1389static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1390 char set)
cb1faec9 1391{
d62a17ae 1392 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1393
555e09d4
QY
1394 if (set) {
1395 uint32_t quanta = strtoul(num, NULL, 10);
1396 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1397 memory_order_relaxed);
1398 } else {
1399 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1400 memory_order_relaxed);
1401 }
1402
1403 return CMD_SUCCESS;
1404}
1405
1406static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1407 char set)
1408{
1409 VTY_DECLVAR_CONTEXT(bgp, bgp);
1410
1411 if (set) {
1412 uint32_t quanta = strtoul(num, NULL, 10);
1413 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1414 memory_order_relaxed);
1415 } else {
1416 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1417 memory_order_relaxed);
1418 }
cb1faec9 1419
d62a17ae 1420 return CMD_SUCCESS;
cb1faec9
DS
1421}
1422
2b791107 1423void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1424{
555e09d4
QY
1425 uint32_t quanta =
1426 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1427 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1428 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1429}
1430
555e09d4
QY
1431void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1432{
1433 uint32_t quanta =
1434 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1435 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1436 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1437}
cb1faec9 1438
555e09d4 1439/* Packet quanta configuration */
cb1faec9
DS
1440DEFUN (bgp_wpkt_quanta,
1441 bgp_wpkt_quanta_cmd,
555e09d4 1442 "write-quanta (1-10)",
cb1faec9
DS
1443 "How many packets to write to peer socket per run\n"
1444 "Number of packets\n")
1445{
d62a17ae 1446 int idx_number = 1;
1447 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1448}
1449
cb1faec9
DS
1450DEFUN (no_bgp_wpkt_quanta,
1451 no_bgp_wpkt_quanta_cmd,
555e09d4 1452 "no write-quanta (1-10)",
d7fa34c1 1453 NO_STR
555e09d4 1454 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1455 "Number of packets\n")
1456{
d62a17ae 1457 int idx_number = 2;
1458 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1459}
1460
555e09d4
QY
1461DEFUN (bgp_rpkt_quanta,
1462 bgp_rpkt_quanta_cmd,
1463 "read-quanta (1-10)",
1464 "How many packets to read from peer socket per I/O cycle\n"
1465 "Number of packets\n")
1466{
1467 int idx_number = 1;
1468 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1469}
1470
1471DEFUN (no_bgp_rpkt_quanta,
1472 no_bgp_rpkt_quanta_cmd,
1473 "no read-quanta (1-10)",
1474 NO_STR
1475 "How many packets to read from peer socket per I/O cycle\n"
1476 "Number of packets\n")
1477{
1478 int idx_number = 2;
1479 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1480}
1481
2b791107 1482void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1483{
37a333fe 1484 if (!bgp->heuristic_coalesce)
d62a17ae 1485 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1486}
1487
1488
1489DEFUN (bgp_coalesce_time,
1490 bgp_coalesce_time_cmd,
6147e2c6 1491 "coalesce-time (0-4294967295)",
3f9c7369
DS
1492 "Subgroup coalesce timer\n"
1493 "Subgroup coalesce timer value (in ms)\n")
1494{
d62a17ae 1495 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1496
d62a17ae 1497 int idx = 0;
1498 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1499 bgp->heuristic_coalesce = false;
d62a17ae 1500 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1501 return CMD_SUCCESS;
3f9c7369
DS
1502}
1503
1504DEFUN (no_bgp_coalesce_time,
1505 no_bgp_coalesce_time_cmd,
6147e2c6 1506 "no coalesce-time (0-4294967295)",
3a2d747c 1507 NO_STR
3f9c7369
DS
1508 "Subgroup coalesce timer\n"
1509 "Subgroup coalesce timer value (in ms)\n")
1510{
d62a17ae 1511 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1512
37a333fe 1513 bgp->heuristic_coalesce = true;
d62a17ae 1514 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1515 return CMD_SUCCESS;
3f9c7369
DS
1516}
1517
5e242b0d
DS
1518/* Maximum-paths configuration */
1519DEFUN (bgp_maxpaths,
1520 bgp_maxpaths_cmd,
6319fd63 1521 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1522 "Forward packets over multiple paths\n"
1523 "Number of paths\n")
1524{
d62a17ae 1525 int idx_number = 1;
1526 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1527 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1528}
1529
d62a17ae 1530ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1531 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1532 "Forward packets over multiple paths\n"
1533 "Number of paths\n")
596c17ba 1534
165b5fff
JB
1535DEFUN (bgp_maxpaths_ibgp,
1536 bgp_maxpaths_ibgp_cmd,
6319fd63 1537 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1538 "Forward packets over multiple paths\n"
1539 "iBGP-multipath\n"
1540 "Number of paths\n")
1541{
d62a17ae 1542 int idx_number = 2;
1543 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1544 argv[idx_number]->arg, 0, 1);
5e242b0d 1545}
165b5fff 1546
d62a17ae 1547ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1548 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1549 "Forward packets over multiple paths\n"
1550 "iBGP-multipath\n"
1551 "Number of paths\n")
596c17ba 1552
5e242b0d
DS
1553DEFUN (bgp_maxpaths_ibgp_cluster,
1554 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1555 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1556 "Forward packets over multiple paths\n"
1557 "iBGP-multipath\n"
1558 "Number of paths\n"
1559 "Match the cluster length\n")
1560{
d62a17ae 1561 int idx_number = 2;
1562 return bgp_maxpaths_config_vty(
1563 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1564 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1565}
1566
d62a17ae 1567ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1568 "maximum-paths ibgp " CMD_RANGE_STR(
1569 1, MULTIPATH_NUM) " equal-cluster-length",
1570 "Forward packets over multiple paths\n"
1571 "iBGP-multipath\n"
1572 "Number of paths\n"
1573 "Match the cluster length\n")
596c17ba 1574
165b5fff
JB
1575DEFUN (no_bgp_maxpaths,
1576 no_bgp_maxpaths_cmd,
6319fd63 1577 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1578 NO_STR
1579 "Forward packets over multiple paths\n"
1580 "Number of paths\n")
1581{
d62a17ae 1582 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1583}
1584
d62a17ae 1585ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1586 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1587 "Forward packets over multiple paths\n"
1588 "Number of paths\n")
596c17ba 1589
165b5fff
JB
1590DEFUN (no_bgp_maxpaths_ibgp,
1591 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1592 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1593 NO_STR
1594 "Forward packets over multiple paths\n"
1595 "iBGP-multipath\n"
838758ac
DW
1596 "Number of paths\n"
1597 "Match the cluster length\n")
165b5fff 1598{
d62a17ae 1599 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1600}
1601
d62a17ae 1602ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1603 "no maximum-paths ibgp [" CMD_RANGE_STR(
1604 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1605 NO_STR
1606 "Forward packets over multiple paths\n"
1607 "iBGP-multipath\n"
1608 "Number of paths\n"
1609 "Match the cluster length\n")
596c17ba 1610
2b791107 1611void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1612 safi_t safi)
165b5fff 1613{
d62a17ae 1614 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1615 vty_out(vty, " maximum-paths %d\n",
1616 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1617 }
165b5fff 1618
d62a17ae 1619 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1620 vty_out(vty, " maximum-paths ibgp %d",
1621 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1622 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1623 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1624 vty_out(vty, " equal-cluster-length");
1625 vty_out(vty, "\n");
1626 }
165b5fff 1627}
6b0655a2 1628
718e3744 1629/* BGP timers. */
1630
1631DEFUN (bgp_timers,
1632 bgp_timers_cmd,
6147e2c6 1633 "timers bgp (0-65535) (0-65535)",
718e3744 1634 "Adjust routing timers\n"
1635 "BGP timers\n"
1636 "Keepalive interval\n"
1637 "Holdtime\n")
1638{
d62a17ae 1639 VTY_DECLVAR_CONTEXT(bgp, bgp);
1640 int idx_number = 2;
1641 int idx_number_2 = 3;
1642 unsigned long keepalive = 0;
1643 unsigned long holdtime = 0;
718e3744 1644
d62a17ae 1645 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1646 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1647
d62a17ae 1648 /* Holdtime value check. */
1649 if (holdtime < 3 && holdtime != 0) {
1650 vty_out(vty,
1651 "%% hold time value must be either 0 or greater than 3\n");
1652 return CMD_WARNING_CONFIG_FAILED;
1653 }
718e3744 1654
d62a17ae 1655 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1656
d62a17ae 1657 return CMD_SUCCESS;
718e3744 1658}
1659
1660DEFUN (no_bgp_timers,
1661 no_bgp_timers_cmd,
838758ac 1662 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1663 NO_STR
1664 "Adjust routing timers\n"
838758ac
DW
1665 "BGP timers\n"
1666 "Keepalive interval\n"
1667 "Holdtime\n")
718e3744 1668{
d62a17ae 1669 VTY_DECLVAR_CONTEXT(bgp, bgp);
1670 bgp_timers_unset(bgp);
718e3744 1671
d62a17ae 1672 return CMD_SUCCESS;
718e3744 1673}
1674
6b0655a2 1675
718e3744 1676DEFUN (bgp_client_to_client_reflection,
1677 bgp_client_to_client_reflection_cmd,
1678 "bgp client-to-client reflection",
1679 "BGP specific commands\n"
1680 "Configure client to client route reflection\n"
1681 "reflection of routes allowed\n")
1682{
d62a17ae 1683 VTY_DECLVAR_CONTEXT(bgp, bgp);
1684 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1685 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1686
d62a17ae 1687 return CMD_SUCCESS;
718e3744 1688}
1689
1690DEFUN (no_bgp_client_to_client_reflection,
1691 no_bgp_client_to_client_reflection_cmd,
1692 "no bgp client-to-client reflection",
1693 NO_STR
1694 "BGP specific commands\n"
1695 "Configure client to client route reflection\n"
1696 "reflection of routes allowed\n")
1697{
d62a17ae 1698 VTY_DECLVAR_CONTEXT(bgp, bgp);
1699 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1700 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1701
d62a17ae 1702 return CMD_SUCCESS;
718e3744 1703}
1704
1705/* "bgp always-compare-med" configuration. */
1706DEFUN (bgp_always_compare_med,
1707 bgp_always_compare_med_cmd,
1708 "bgp always-compare-med",
1709 "BGP specific commands\n"
1710 "Allow comparing MED from different neighbors\n")
1711{
d62a17ae 1712 VTY_DECLVAR_CONTEXT(bgp, bgp);
1713 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1714 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1715
d62a17ae 1716 return CMD_SUCCESS;
718e3744 1717}
1718
1719DEFUN (no_bgp_always_compare_med,
1720 no_bgp_always_compare_med_cmd,
1721 "no bgp always-compare-med",
1722 NO_STR
1723 "BGP specific commands\n"
1724 "Allow comparing MED from different neighbors\n")
1725{
d62a17ae 1726 VTY_DECLVAR_CONTEXT(bgp, bgp);
1727 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1728 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1729
d62a17ae 1730 return CMD_SUCCESS;
718e3744 1731}
6b0655a2 1732
718e3744 1733/* "bgp deterministic-med" configuration. */
1734DEFUN (bgp_deterministic_med,
1735 bgp_deterministic_med_cmd,
1736 "bgp deterministic-med",
1737 "BGP specific commands\n"
1738 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1739{
d62a17ae 1740 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1741
d62a17ae 1742 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1743 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1744 bgp_recalculate_all_bestpaths(bgp);
1745 }
7aafcaca 1746
d62a17ae 1747 return CMD_SUCCESS;
718e3744 1748}
1749
1750DEFUN (no_bgp_deterministic_med,
1751 no_bgp_deterministic_med_cmd,
1752 "no bgp deterministic-med",
1753 NO_STR
1754 "BGP specific commands\n"
1755 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1756{
d62a17ae 1757 VTY_DECLVAR_CONTEXT(bgp, bgp);
1758 int bestpath_per_as_used;
1759 afi_t afi;
1760 safi_t safi;
1761 struct peer *peer;
1762 struct listnode *node, *nnode;
1763
1764 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1765 bestpath_per_as_used = 0;
1766
1767 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc
QY
1768 FOREACH_AFI_SAFI (afi, safi)
1769 if (CHECK_FLAG(
1770 peer->af_flags[afi][safi],
1771 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1772 bestpath_per_as_used = 1;
1773 break;
1774 }
d62a17ae 1775
1776 if (bestpath_per_as_used)
1777 break;
1778 }
1779
1780 if (bestpath_per_as_used) {
1781 vty_out(vty,
1782 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1783 return CMD_WARNING_CONFIG_FAILED;
1784 } else {
1785 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1786 bgp_recalculate_all_bestpaths(bgp);
1787 }
1788 }
1789
1790 return CMD_SUCCESS;
718e3744 1791}
538621f2 1792
1793/* "bgp graceful-restart" configuration. */
1794DEFUN (bgp_graceful_restart,
1795 bgp_graceful_restart_cmd,
1796 "bgp graceful-restart",
1797 "BGP specific commands\n"
1798 "Graceful restart capability parameters\n")
1799{
d62a17ae 1800 VTY_DECLVAR_CONTEXT(bgp, bgp);
1801 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1802 return CMD_SUCCESS;
538621f2 1803}
1804
1805DEFUN (no_bgp_graceful_restart,
1806 no_bgp_graceful_restart_cmd,
1807 "no bgp graceful-restart",
1808 NO_STR
1809 "BGP specific commands\n"
1810 "Graceful restart capability parameters\n")
1811{
d62a17ae 1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
1813 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1814 return CMD_SUCCESS;
538621f2 1815}
1816
93406d87 1817DEFUN (bgp_graceful_restart_stalepath_time,
1818 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1819 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1820 "BGP specific commands\n"
1821 "Graceful restart capability parameters\n"
1822 "Set the max time to hold onto restarting peer's stale paths\n"
1823 "Delay value (seconds)\n")
1824{
d62a17ae 1825 VTY_DECLVAR_CONTEXT(bgp, bgp);
1826 int idx_number = 3;
d7c0a89a 1827 uint32_t stalepath;
93406d87 1828
d62a17ae 1829 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1830 bgp->stalepath_time = stalepath;
1831 return CMD_SUCCESS;
93406d87 1832}
1833
eb6f1b41
PG
1834DEFUN (bgp_graceful_restart_restart_time,
1835 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1836 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1837 "BGP specific commands\n"
1838 "Graceful restart capability parameters\n"
1839 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1840 "Delay value (seconds)\n")
1841{
d62a17ae 1842 VTY_DECLVAR_CONTEXT(bgp, bgp);
1843 int idx_number = 3;
d7c0a89a 1844 uint32_t restart;
eb6f1b41 1845
d62a17ae 1846 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1847 bgp->restart_time = restart;
1848 return CMD_SUCCESS;
eb6f1b41
PG
1849}
1850
93406d87 1851DEFUN (no_bgp_graceful_restart_stalepath_time,
1852 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1853 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1854 NO_STR
1855 "BGP specific commands\n"
1856 "Graceful restart capability parameters\n"
838758ac
DW
1857 "Set the max time to hold onto restarting peer's stale paths\n"
1858 "Delay value (seconds)\n")
93406d87 1859{
d62a17ae 1860 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1861
d62a17ae 1862 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1863 return CMD_SUCCESS;
93406d87 1864}
1865
eb6f1b41
PG
1866DEFUN (no_bgp_graceful_restart_restart_time,
1867 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1868 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1869 NO_STR
1870 "BGP specific commands\n"
1871 "Graceful restart capability parameters\n"
838758ac
DW
1872 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1873 "Delay value (seconds)\n")
eb6f1b41 1874{
d62a17ae 1875 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1876
d62a17ae 1877 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1878 return CMD_SUCCESS;
eb6f1b41
PG
1879}
1880
43fc21b3
JC
1881DEFUN (bgp_graceful_restart_preserve_fw,
1882 bgp_graceful_restart_preserve_fw_cmd,
1883 "bgp graceful-restart preserve-fw-state",
1884 "BGP specific commands\n"
1885 "Graceful restart capability parameters\n"
1886 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1887{
d62a17ae 1888 VTY_DECLVAR_CONTEXT(bgp, bgp);
1889 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1890 return CMD_SUCCESS;
43fc21b3
JC
1891}
1892
1893DEFUN (no_bgp_graceful_restart_preserve_fw,
1894 no_bgp_graceful_restart_preserve_fw_cmd,
1895 "no bgp graceful-restart preserve-fw-state",
1896 NO_STR
1897 "BGP specific commands\n"
1898 "Graceful restart capability parameters\n"
1899 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1900{
d62a17ae 1901 VTY_DECLVAR_CONTEXT(bgp, bgp);
1902 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1903 return CMD_SUCCESS;
43fc21b3
JC
1904}
1905
7f323236
DW
1906static void bgp_redistribute_redo(struct bgp *bgp)
1907{
1908 afi_t afi;
1909 int i;
1910 struct list *red_list;
1911 struct listnode *node;
1912 struct bgp_redist *red;
1913
a4d82a8a
PZ
1914 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1915 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 1916
a4d82a8a
PZ
1917 red_list = bgp->redist[afi][i];
1918 if (!red_list)
1919 continue;
7f323236 1920
a4d82a8a 1921 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
1922 bgp_redistribute_resend(bgp, afi, i,
1923 red->instance);
1924 }
1925 }
1926 }
1927}
1928
1929/* "bgp graceful-shutdown" configuration */
1930DEFUN (bgp_graceful_shutdown,
1931 bgp_graceful_shutdown_cmd,
1932 "bgp graceful-shutdown",
1933 BGP_STR
1934 "Graceful shutdown parameters\n")
1935{
1936 VTY_DECLVAR_CONTEXT(bgp, bgp);
1937
1938 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1939 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1940 bgp_static_redo_import_check(bgp);
1941 bgp_redistribute_redo(bgp);
1942 bgp_clear_star_soft_out(vty, bgp->name);
1943 bgp_clear_star_soft_in(vty, bgp->name);
1944 }
1945
1946 return CMD_SUCCESS;
1947}
1948
1949DEFUN (no_bgp_graceful_shutdown,
1950 no_bgp_graceful_shutdown_cmd,
1951 "no bgp graceful-shutdown",
1952 NO_STR
1953 BGP_STR
1954 "Graceful shutdown parameters\n")
1955{
1956 VTY_DECLVAR_CONTEXT(bgp, bgp);
1957
1958 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1959 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1960 bgp_static_redo_import_check(bgp);
1961 bgp_redistribute_redo(bgp);
1962 bgp_clear_star_soft_out(vty, bgp->name);
1963 bgp_clear_star_soft_in(vty, bgp->name);
1964 }
1965
1966 return CMD_SUCCESS;
1967}
1968
718e3744 1969/* "bgp fast-external-failover" configuration. */
1970DEFUN (bgp_fast_external_failover,
1971 bgp_fast_external_failover_cmd,
1972 "bgp fast-external-failover",
1973 BGP_STR
1974 "Immediately reset session if a link to a directly connected external peer goes down\n")
1975{
d62a17ae 1976 VTY_DECLVAR_CONTEXT(bgp, bgp);
1977 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1978 return CMD_SUCCESS;
718e3744 1979}
1980
1981DEFUN (no_bgp_fast_external_failover,
1982 no_bgp_fast_external_failover_cmd,
1983 "no bgp fast-external-failover",
1984 NO_STR
1985 BGP_STR
1986 "Immediately reset session if a link to a directly connected external peer goes down\n")
1987{
d62a17ae 1988 VTY_DECLVAR_CONTEXT(bgp, bgp);
1989 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1990 return CMD_SUCCESS;
718e3744 1991}
6b0655a2 1992
718e3744 1993/* "bgp enforce-first-as" configuration. */
1994DEFUN (bgp_enforce_first_as,
1995 bgp_enforce_first_as_cmd,
1996 "bgp enforce-first-as",
1997 BGP_STR
1998 "Enforce the first AS for EBGP routes\n")
1999{
d62a17ae 2000 VTY_DECLVAR_CONTEXT(bgp, bgp);
2001 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2002 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2003
d62a17ae 2004 return CMD_SUCCESS;
718e3744 2005}
2006
2007DEFUN (no_bgp_enforce_first_as,
2008 no_bgp_enforce_first_as_cmd,
2009 "no bgp enforce-first-as",
2010 NO_STR
2011 BGP_STR
2012 "Enforce the first AS for EBGP routes\n")
2013{
d62a17ae 2014 VTY_DECLVAR_CONTEXT(bgp, bgp);
2015 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2016 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2017
d62a17ae 2018 return CMD_SUCCESS;
718e3744 2019}
6b0655a2 2020
718e3744 2021/* "bgp bestpath compare-routerid" configuration. */
2022DEFUN (bgp_bestpath_compare_router_id,
2023 bgp_bestpath_compare_router_id_cmd,
2024 "bgp bestpath compare-routerid",
2025 "BGP specific commands\n"
2026 "Change the default bestpath selection\n"
2027 "Compare router-id for identical EBGP paths\n")
2028{
d62a17ae 2029 VTY_DECLVAR_CONTEXT(bgp, bgp);
2030 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2031 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2032
d62a17ae 2033 return CMD_SUCCESS;
718e3744 2034}
2035
2036DEFUN (no_bgp_bestpath_compare_router_id,
2037 no_bgp_bestpath_compare_router_id_cmd,
2038 "no bgp bestpath compare-routerid",
2039 NO_STR
2040 "BGP specific commands\n"
2041 "Change the default bestpath selection\n"
2042 "Compare router-id for identical EBGP paths\n")
2043{
d62a17ae 2044 VTY_DECLVAR_CONTEXT(bgp, bgp);
2045 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2046 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2047
d62a17ae 2048 return CMD_SUCCESS;
718e3744 2049}
6b0655a2 2050
718e3744 2051/* "bgp bestpath as-path ignore" configuration. */
2052DEFUN (bgp_bestpath_aspath_ignore,
2053 bgp_bestpath_aspath_ignore_cmd,
2054 "bgp bestpath as-path ignore",
2055 "BGP specific commands\n"
2056 "Change the default bestpath selection\n"
2057 "AS-path attribute\n"
2058 "Ignore as-path length in selecting a route\n")
2059{
d62a17ae 2060 VTY_DECLVAR_CONTEXT(bgp, bgp);
2061 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2062 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2063
d62a17ae 2064 return CMD_SUCCESS;
718e3744 2065}
2066
2067DEFUN (no_bgp_bestpath_aspath_ignore,
2068 no_bgp_bestpath_aspath_ignore_cmd,
2069 "no bgp bestpath as-path ignore",
2070 NO_STR
2071 "BGP specific commands\n"
2072 "Change the default bestpath selection\n"
2073 "AS-path attribute\n"
2074 "Ignore as-path length in selecting a route\n")
2075{
d62a17ae 2076 VTY_DECLVAR_CONTEXT(bgp, bgp);
2077 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2078 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2079
d62a17ae 2080 return CMD_SUCCESS;
718e3744 2081}
6b0655a2 2082
6811845b 2083/* "bgp bestpath as-path confed" configuration. */
2084DEFUN (bgp_bestpath_aspath_confed,
2085 bgp_bestpath_aspath_confed_cmd,
2086 "bgp bestpath as-path confed",
2087 "BGP specific commands\n"
2088 "Change the default bestpath selection\n"
2089 "AS-path attribute\n"
2090 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2091{
d62a17ae 2092 VTY_DECLVAR_CONTEXT(bgp, bgp);
2093 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2094 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2095
d62a17ae 2096 return CMD_SUCCESS;
6811845b 2097}
2098
2099DEFUN (no_bgp_bestpath_aspath_confed,
2100 no_bgp_bestpath_aspath_confed_cmd,
2101 "no bgp bestpath as-path confed",
2102 NO_STR
2103 "BGP specific commands\n"
2104 "Change the default bestpath selection\n"
2105 "AS-path attribute\n"
2106 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2107{
d62a17ae 2108 VTY_DECLVAR_CONTEXT(bgp, bgp);
2109 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2110 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2111
d62a17ae 2112 return CMD_SUCCESS;
6811845b 2113}
6b0655a2 2114
2fdd455c
PM
2115/* "bgp bestpath as-path multipath-relax" configuration. */
2116DEFUN (bgp_bestpath_aspath_multipath_relax,
2117 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2118 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2119 "BGP specific commands\n"
2120 "Change the default bestpath selection\n"
2121 "AS-path attribute\n"
2122 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2123 "Generate an AS_SET\n"
16fc1eec
DS
2124 "Do not generate an AS_SET\n")
2125{
d62a17ae 2126 VTY_DECLVAR_CONTEXT(bgp, bgp);
2127 int idx = 0;
2128 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2129
d62a17ae 2130 /* no-as-set is now the default behavior so we can silently
2131 * ignore it */
2132 if (argv_find(argv, argc, "as-set", &idx))
2133 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2134 else
2135 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2136
d62a17ae 2137 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2138
d62a17ae 2139 return CMD_SUCCESS;
16fc1eec
DS
2140}
2141
219178b6
DW
2142DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2143 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2144 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2145 NO_STR
2146 "BGP specific commands\n"
2147 "Change the default bestpath selection\n"
2148 "AS-path attribute\n"
2149 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2150 "Generate an AS_SET\n"
16fc1eec
DS
2151 "Do not generate an AS_SET\n")
2152{
d62a17ae 2153 VTY_DECLVAR_CONTEXT(bgp, bgp);
2154 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2155 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2156 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2157
d62a17ae 2158 return CMD_SUCCESS;
2fdd455c 2159}
6b0655a2 2160
848973c7 2161/* "bgp log-neighbor-changes" configuration. */
2162DEFUN (bgp_log_neighbor_changes,
2163 bgp_log_neighbor_changes_cmd,
2164 "bgp log-neighbor-changes",
2165 "BGP specific commands\n"
2166 "Log neighbor up/down and reset reason\n")
2167{
d62a17ae 2168 VTY_DECLVAR_CONTEXT(bgp, bgp);
2169 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2170 return CMD_SUCCESS;
848973c7 2171}
2172
2173DEFUN (no_bgp_log_neighbor_changes,
2174 no_bgp_log_neighbor_changes_cmd,
2175 "no bgp log-neighbor-changes",
2176 NO_STR
2177 "BGP specific commands\n"
2178 "Log neighbor up/down and reset reason\n")
2179{
d62a17ae 2180 VTY_DECLVAR_CONTEXT(bgp, bgp);
2181 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2182 return CMD_SUCCESS;
848973c7 2183}
6b0655a2 2184
718e3744 2185/* "bgp bestpath med" configuration. */
2186DEFUN (bgp_bestpath_med,
2187 bgp_bestpath_med_cmd,
2d8c1a4d 2188 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2189 "BGP specific commands\n"
2190 "Change the default bestpath selection\n"
2191 "MED attribute\n"
2192 "Compare MED among confederation paths\n"
838758ac
DW
2193 "Treat missing MED as the least preferred one\n"
2194 "Treat missing MED as the least preferred one\n"
2195 "Compare MED among confederation paths\n")
718e3744 2196{
d62a17ae 2197 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2198
d62a17ae 2199 int idx = 0;
2200 if (argv_find(argv, argc, "confed", &idx))
2201 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2202 idx = 0;
2203 if (argv_find(argv, argc, "missing-as-worst", &idx))
2204 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2205
d62a17ae 2206 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2207
d62a17ae 2208 return CMD_SUCCESS;
718e3744 2209}
2210
718e3744 2211DEFUN (no_bgp_bestpath_med,
2212 no_bgp_bestpath_med_cmd,
2d8c1a4d 2213 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2214 NO_STR
2215 "BGP specific commands\n"
2216 "Change the default bestpath selection\n"
2217 "MED attribute\n"
2218 "Compare MED among confederation paths\n"
3a2d747c
QY
2219 "Treat missing MED as the least preferred one\n"
2220 "Treat missing MED as the least preferred one\n"
2221 "Compare MED among confederation paths\n")
718e3744 2222{
d62a17ae 2223 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2224
d62a17ae 2225 int idx = 0;
2226 if (argv_find(argv, argc, "confed", &idx))
2227 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2228 idx = 0;
2229 if (argv_find(argv, argc, "missing-as-worst", &idx))
2230 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2231
d62a17ae 2232 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2233
d62a17ae 2234 return CMD_SUCCESS;
718e3744 2235}
2236
718e3744 2237/* "no bgp default ipv4-unicast". */
2238DEFUN (no_bgp_default_ipv4_unicast,
2239 no_bgp_default_ipv4_unicast_cmd,
2240 "no bgp default ipv4-unicast",
2241 NO_STR
2242 "BGP specific commands\n"
2243 "Configure BGP defaults\n"
2244 "Activate ipv4-unicast for a peer by default\n")
2245{
d62a17ae 2246 VTY_DECLVAR_CONTEXT(bgp, bgp);
2247 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2248 return CMD_SUCCESS;
718e3744 2249}
2250
2251DEFUN (bgp_default_ipv4_unicast,
2252 bgp_default_ipv4_unicast_cmd,
2253 "bgp default ipv4-unicast",
2254 "BGP specific commands\n"
2255 "Configure BGP defaults\n"
2256 "Activate ipv4-unicast for a peer by default\n")
2257{
d62a17ae 2258 VTY_DECLVAR_CONTEXT(bgp, bgp);
2259 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2260 return CMD_SUCCESS;
718e3744 2261}
6b0655a2 2262
04b6bdc0
DW
2263/* Display hostname in certain command outputs */
2264DEFUN (bgp_default_show_hostname,
2265 bgp_default_show_hostname_cmd,
2266 "bgp default show-hostname",
2267 "BGP specific commands\n"
2268 "Configure BGP defaults\n"
2269 "Show hostname in certain command ouputs\n")
2270{
d62a17ae 2271 VTY_DECLVAR_CONTEXT(bgp, bgp);
2272 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2273 return CMD_SUCCESS;
04b6bdc0
DW
2274}
2275
2276DEFUN (no_bgp_default_show_hostname,
2277 no_bgp_default_show_hostname_cmd,
2278 "no bgp default show-hostname",
2279 NO_STR
2280 "BGP specific commands\n"
2281 "Configure BGP defaults\n"
2282 "Show hostname in certain command ouputs\n")
2283{
d62a17ae 2284 VTY_DECLVAR_CONTEXT(bgp, bgp);
2285 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2286 return CMD_SUCCESS;
04b6bdc0
DW
2287}
2288
8233ef81 2289/* "bgp network import-check" configuration. */
718e3744 2290DEFUN (bgp_network_import_check,
2291 bgp_network_import_check_cmd,
5623e905 2292 "bgp network import-check",
718e3744 2293 "BGP specific commands\n"
2294 "BGP network command\n"
5623e905 2295 "Check BGP network route exists in IGP\n")
718e3744 2296{
d62a17ae 2297 VTY_DECLVAR_CONTEXT(bgp, bgp);
2298 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2299 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2300 bgp_static_redo_import_check(bgp);
2301 }
078430f6 2302
d62a17ae 2303 return CMD_SUCCESS;
718e3744 2304}
2305
d62a17ae 2306ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2307 "bgp network import-check exact",
2308 "BGP specific commands\n"
2309 "BGP network command\n"
2310 "Check BGP network route exists in IGP\n"
2311 "Match route precisely\n")
8233ef81 2312
718e3744 2313DEFUN (no_bgp_network_import_check,
2314 no_bgp_network_import_check_cmd,
5623e905 2315 "no bgp network import-check",
718e3744 2316 NO_STR
2317 "BGP specific commands\n"
2318 "BGP network command\n"
2319 "Check BGP network route exists in IGP\n")
2320{
d62a17ae 2321 VTY_DECLVAR_CONTEXT(bgp, bgp);
2322 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2323 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2324 bgp_static_redo_import_check(bgp);
2325 }
5623e905 2326
d62a17ae 2327 return CMD_SUCCESS;
718e3744 2328}
6b0655a2 2329
718e3744 2330DEFUN (bgp_default_local_preference,
2331 bgp_default_local_preference_cmd,
6147e2c6 2332 "bgp default local-preference (0-4294967295)",
718e3744 2333 "BGP specific commands\n"
2334 "Configure BGP defaults\n"
2335 "local preference (higher=more preferred)\n"
2336 "Configure default local preference value\n")
2337{
d62a17ae 2338 VTY_DECLVAR_CONTEXT(bgp, bgp);
2339 int idx_number = 3;
d7c0a89a 2340 uint32_t local_pref;
718e3744 2341
d62a17ae 2342 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2343
d62a17ae 2344 bgp_default_local_preference_set(bgp, local_pref);
2345 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2346
d62a17ae 2347 return CMD_SUCCESS;
718e3744 2348}
2349
2350DEFUN (no_bgp_default_local_preference,
2351 no_bgp_default_local_preference_cmd,
838758ac 2352 "no bgp default local-preference [(0-4294967295)]",
718e3744 2353 NO_STR
2354 "BGP specific commands\n"
2355 "Configure BGP defaults\n"
838758ac
DW
2356 "local preference (higher=more preferred)\n"
2357 "Configure default local preference value\n")
718e3744 2358{
d62a17ae 2359 VTY_DECLVAR_CONTEXT(bgp, bgp);
2360 bgp_default_local_preference_unset(bgp);
2361 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2362
d62a17ae 2363 return CMD_SUCCESS;
718e3744 2364}
2365
6b0655a2 2366
3f9c7369
DS
2367DEFUN (bgp_default_subgroup_pkt_queue_max,
2368 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2369 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2370 "BGP specific commands\n"
2371 "Configure BGP defaults\n"
2372 "subgroup-pkt-queue-max\n"
2373 "Configure subgroup packet queue max\n")
8bd9d948 2374{
d62a17ae 2375 VTY_DECLVAR_CONTEXT(bgp, bgp);
2376 int idx_number = 3;
d7c0a89a 2377 uint32_t max_size;
8bd9d948 2378
d62a17ae 2379 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2380
d62a17ae 2381 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2382
d62a17ae 2383 return CMD_SUCCESS;
3f9c7369
DS
2384}
2385
2386DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2387 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2388 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2389 NO_STR
2390 "BGP specific commands\n"
2391 "Configure BGP defaults\n"
838758ac
DW
2392 "subgroup-pkt-queue-max\n"
2393 "Configure subgroup packet queue max\n")
3f9c7369 2394{
d62a17ae 2395 VTY_DECLVAR_CONTEXT(bgp, bgp);
2396 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2397 return CMD_SUCCESS;
8bd9d948
DS
2398}
2399
813d4307 2400
8bd9d948
DS
2401DEFUN (bgp_rr_allow_outbound_policy,
2402 bgp_rr_allow_outbound_policy_cmd,
2403 "bgp route-reflector allow-outbound-policy",
2404 "BGP specific commands\n"
2405 "Allow modifications made by out route-map\n"
2406 "on ibgp neighbors\n")
2407{
d62a17ae 2408 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2409
d62a17ae 2410 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2411 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2412 update_group_announce_rrclients(bgp);
2413 bgp_clear_star_soft_out(vty, bgp->name);
2414 }
8bd9d948 2415
d62a17ae 2416 return CMD_SUCCESS;
8bd9d948
DS
2417}
2418
2419DEFUN (no_bgp_rr_allow_outbound_policy,
2420 no_bgp_rr_allow_outbound_policy_cmd,
2421 "no bgp route-reflector allow-outbound-policy",
2422 NO_STR
2423 "BGP specific commands\n"
2424 "Allow modifications made by out route-map\n"
2425 "on ibgp neighbors\n")
2426{
d62a17ae 2427 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2428
d62a17ae 2429 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2430 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2431 update_group_announce_rrclients(bgp);
2432 bgp_clear_star_soft_out(vty, bgp->name);
2433 }
8bd9d948 2434
d62a17ae 2435 return CMD_SUCCESS;
8bd9d948
DS
2436}
2437
f14e6fdb
DS
2438DEFUN (bgp_listen_limit,
2439 bgp_listen_limit_cmd,
9ccf14f7 2440 "bgp listen limit (1-5000)",
f14e6fdb
DS
2441 "BGP specific commands\n"
2442 "Configure BGP defaults\n"
2443 "maximum number of BGP Dynamic Neighbors that can be created\n"
2444 "Configure Dynamic Neighbors listen limit value\n")
2445{
d62a17ae 2446 VTY_DECLVAR_CONTEXT(bgp, bgp);
2447 int idx_number = 3;
2448 int listen_limit;
f14e6fdb 2449
d62a17ae 2450 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2451
d62a17ae 2452 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2453
d62a17ae 2454 return CMD_SUCCESS;
f14e6fdb
DS
2455}
2456
2457DEFUN (no_bgp_listen_limit,
2458 no_bgp_listen_limit_cmd,
838758ac 2459 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2460 "BGP specific commands\n"
2461 "Configure BGP defaults\n"
2462 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2463 "Configure Dynamic Neighbors listen limit value to default\n"
2464 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2465{
d62a17ae 2466 VTY_DECLVAR_CONTEXT(bgp, bgp);
2467 bgp_listen_limit_unset(bgp);
2468 return CMD_SUCCESS;
f14e6fdb
DS
2469}
2470
2471
20eb8864 2472/*
2473 * Check if this listen range is already configured. Check for exact
2474 * match or overlap based on input.
2475 */
d62a17ae 2476static struct peer_group *listen_range_exists(struct bgp *bgp,
2477 struct prefix *range, int exact)
2478{
2479 struct listnode *node, *nnode;
2480 struct listnode *node1, *nnode1;
2481 struct peer_group *group;
2482 struct prefix *lr;
2483 afi_t afi;
2484 int match;
2485
2486 afi = family2afi(range->family);
2487 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2488 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2489 lr)) {
2490 if (exact)
2491 match = prefix_same(range, lr);
2492 else
2493 match = (prefix_match(range, lr)
2494 || prefix_match(lr, range));
2495 if (match)
2496 return group;
2497 }
2498 }
2499
2500 return NULL;
20eb8864 2501}
2502
f14e6fdb
DS
2503DEFUN (bgp_listen_range,
2504 bgp_listen_range_cmd,
9ccf14f7 2505 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2506 "BGP specific commands\n"
d7fa34c1
QY
2507 "Configure BGP dynamic neighbors listen range\n"
2508 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2509 NEIGHBOR_ADDR_STR
2510 "Member of the peer-group\n"
2511 "Peer-group name\n")
f14e6fdb 2512{
d62a17ae 2513 VTY_DECLVAR_CONTEXT(bgp, bgp);
2514 struct prefix range;
2515 struct peer_group *group, *existing_group;
2516 afi_t afi;
2517 int ret;
2518 int idx = 0;
2519
2520 argv_find(argv, argc, "A.B.C.D/M", &idx);
2521 argv_find(argv, argc, "X:X::X:X/M", &idx);
2522 char *prefix = argv[idx]->arg;
2523 argv_find(argv, argc, "WORD", &idx);
2524 char *peergroup = argv[idx]->arg;
2525
2526 /* Convert IP prefix string to struct prefix. */
2527 ret = str2prefix(prefix, &range);
2528 if (!ret) {
2529 vty_out(vty, "%% Malformed listen range\n");
2530 return CMD_WARNING_CONFIG_FAILED;
2531 }
2532
2533 afi = family2afi(range.family);
2534
2535 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2536 vty_out(vty,
2537 "%% Malformed listen range (link-local address)\n");
2538 return CMD_WARNING_CONFIG_FAILED;
2539 }
2540
2541 apply_mask(&range);
2542
2543 /* Check if same listen range is already configured. */
2544 existing_group = listen_range_exists(bgp, &range, 1);
2545 if (existing_group) {
2546 if (strcmp(existing_group->name, peergroup) == 0)
2547 return CMD_SUCCESS;
2548 else {
2549 vty_out(vty,
2550 "%% Same listen range is attached to peer-group %s\n",
2551 existing_group->name);
2552 return CMD_WARNING_CONFIG_FAILED;
2553 }
2554 }
2555
2556 /* Check if an overlapping listen range exists. */
2557 if (listen_range_exists(bgp, &range, 0)) {
2558 vty_out(vty,
2559 "%% Listen range overlaps with existing listen range\n");
2560 return CMD_WARNING_CONFIG_FAILED;
2561 }
2562
2563 group = peer_group_lookup(bgp, peergroup);
2564 if (!group) {
2565 vty_out(vty, "%% Configure the peer-group first\n");
2566 return CMD_WARNING_CONFIG_FAILED;
2567 }
2568
2569 ret = peer_group_listen_range_add(group, &range);
2570 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2571}
2572
2573DEFUN (no_bgp_listen_range,
2574 no_bgp_listen_range_cmd,
d7fa34c1
QY
2575 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2576 NO_STR
f14e6fdb 2577 "BGP specific commands\n"
d7fa34c1
QY
2578 "Unconfigure BGP dynamic neighbors listen range\n"
2579 "Unconfigure BGP dynamic neighbors listen range\n"
2580 NEIGHBOR_ADDR_STR
2581 "Member of the peer-group\n"
2582 "Peer-group name\n")
f14e6fdb 2583{
d62a17ae 2584 VTY_DECLVAR_CONTEXT(bgp, bgp);
2585 struct prefix range;
2586 struct peer_group *group;
2587 afi_t afi;
2588 int ret;
2589 int idx = 0;
2590
2591 argv_find(argv, argc, "A.B.C.D/M", &idx);
2592 argv_find(argv, argc, "X:X::X:X/M", &idx);
2593 char *prefix = argv[idx]->arg;
2594 argv_find(argv, argc, "WORD", &idx);
2595 char *peergroup = argv[idx]->arg;
2596
2597 /* Convert IP prefix string to struct prefix. */
2598 ret = str2prefix(prefix, &range);
2599 if (!ret) {
2600 vty_out(vty, "%% Malformed listen range\n");
2601 return CMD_WARNING_CONFIG_FAILED;
2602 }
2603
2604 afi = family2afi(range.family);
2605
2606 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2607 vty_out(vty,
2608 "%% Malformed listen range (link-local address)\n");
2609 return CMD_WARNING_CONFIG_FAILED;
2610 }
2611
2612 apply_mask(&range);
2613
2614 group = peer_group_lookup(bgp, peergroup);
2615 if (!group) {
2616 vty_out(vty, "%% Peer-group does not exist\n");
2617 return CMD_WARNING_CONFIG_FAILED;
2618 }
2619
2620 ret = peer_group_listen_range_del(group, &range);
2621 return bgp_vty_return(vty, ret);
2622}
2623
2b791107 2624void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2625{
2626 struct peer_group *group;
2627 struct listnode *node, *nnode, *rnode, *nrnode;
2628 struct prefix *range;
2629 afi_t afi;
2630 char buf[PREFIX2STR_BUFFER];
2631
2632 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2633 vty_out(vty, " bgp listen limit %d\n",
2634 bgp->dynamic_neighbors_limit);
2635
2636 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2637 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2638 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2639 nrnode, range)) {
2640 prefix2str(range, buf, sizeof(buf));
2641 vty_out(vty,
2642 " bgp listen range %s peer-group %s\n",
2643 buf, group->name);
2644 }
2645 }
2646 }
f14e6fdb
DS
2647}
2648
2649
907f92c8
DS
2650DEFUN (bgp_disable_connected_route_check,
2651 bgp_disable_connected_route_check_cmd,
2652 "bgp disable-ebgp-connected-route-check",
2653 "BGP specific commands\n"
2654 "Disable checking if nexthop is connected on ebgp sessions\n")
2655{
d62a17ae 2656 VTY_DECLVAR_CONTEXT(bgp, bgp);
2657 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2658 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2659
d62a17ae 2660 return CMD_SUCCESS;
907f92c8
DS
2661}
2662
2663DEFUN (no_bgp_disable_connected_route_check,
2664 no_bgp_disable_connected_route_check_cmd,
2665 "no bgp disable-ebgp-connected-route-check",
2666 NO_STR
2667 "BGP specific commands\n"
2668 "Disable checking if nexthop is connected on ebgp sessions\n")
2669{
d62a17ae 2670 VTY_DECLVAR_CONTEXT(bgp, bgp);
2671 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2672 bgp_clear_star_soft_in(vty, bgp->name);
2673
2674 return CMD_SUCCESS;
2675}
2676
2677
2678static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2679 const char *as_str, afi_t afi, safi_t safi)
2680{
2681 VTY_DECLVAR_CONTEXT(bgp, bgp);
2682 int ret;
2683 as_t as;
2684 int as_type = AS_SPECIFIED;
2685 union sockunion su;
2686
2687 if (as_str[0] == 'i') {
2688 as = 0;
2689 as_type = AS_INTERNAL;
2690 } else if (as_str[0] == 'e') {
2691 as = 0;
2692 as_type = AS_EXTERNAL;
2693 } else {
2694 /* Get AS number. */
2695 as = strtoul(as_str, NULL, 10);
2696 }
2697
2698 /* If peer is peer group, call proper function. */
2699 ret = str2sockunion(peer_str, &su);
2700 if (ret < 0) {
2701 /* Check for peer by interface */
2702 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2703 safi);
2704 if (ret < 0) {
2705 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2706 if (ret < 0) {
2707 vty_out(vty,
2708 "%% Create the peer-group or interface first\n");
2709 return CMD_WARNING_CONFIG_FAILED;
2710 }
2711 return CMD_SUCCESS;
2712 }
2713 } else {
2714 if (peer_address_self_check(bgp, &su)) {
2715 vty_out(vty,
2716 "%% Can not configure the local system as neighbor\n");
2717 return CMD_WARNING_CONFIG_FAILED;
2718 }
2719 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2720 }
2721
2722 /* This peer belongs to peer group. */
2723 switch (ret) {
2724 case BGP_ERR_PEER_GROUP_MEMBER:
2725 vty_out(vty,
2726 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2727 as);
2728 return CMD_WARNING_CONFIG_FAILED;
2729 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2730 vty_out(vty,
2731 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2732 as, as_str);
2733 return CMD_WARNING_CONFIG_FAILED;
2734 }
2735 return bgp_vty_return(vty, ret);
718e3744 2736}
2737
f26845f9
QY
2738DEFUN (bgp_default_shutdown,
2739 bgp_default_shutdown_cmd,
2740 "[no] bgp default shutdown",
2741 NO_STR
2742 BGP_STR
2743 "Configure BGP defaults\n"
b012cbe2 2744 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2745{
2746 VTY_DECLVAR_CONTEXT(bgp, bgp);
2747 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2748 return CMD_SUCCESS;
2749}
2750
718e3744 2751DEFUN (neighbor_remote_as,
2752 neighbor_remote_as_cmd,
3a2d747c 2753 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2754 NEIGHBOR_STR
2755 NEIGHBOR_ADDR_STR2
2756 "Specify a BGP neighbor\n"
d7fa34c1 2757 AS_STR
3a2d747c
QY
2758 "Internal BGP peer\n"
2759 "External BGP peer\n")
718e3744 2760{
d62a17ae 2761 int idx_peer = 1;
2762 int idx_remote_as = 3;
2763 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2764 argv[idx_remote_as]->arg, AFI_IP,
2765 SAFI_UNICAST);
2766}
2767
2768static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2769 afi_t afi, safi_t safi, int v6only,
2770 const char *peer_group_name,
2771 const char *as_str)
2772{
2773 VTY_DECLVAR_CONTEXT(bgp, bgp);
2774 as_t as = 0;
2775 int as_type = AS_UNSPECIFIED;
2776 struct peer *peer;
2777 struct peer_group *group;
2778 int ret = 0;
2779 union sockunion su;
2780
2781 group = peer_group_lookup(bgp, conf_if);
2782
2783 if (group) {
2784 vty_out(vty, "%% Name conflict with peer-group \n");
2785 return CMD_WARNING_CONFIG_FAILED;
2786 }
2787
2788 if (as_str) {
2789 if (as_str[0] == 'i') {
2790 as_type = AS_INTERNAL;
2791 } else if (as_str[0] == 'e') {
2792 as_type = AS_EXTERNAL;
2793 } else {
2794 /* Get AS number. */
2795 as = strtoul(as_str, NULL, 10);
2796 as_type = AS_SPECIFIED;
2797 }
2798 }
2799
2800 peer = peer_lookup_by_conf_if(bgp, conf_if);
2801 if (peer) {
2802 if (as_str)
2803 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2804 afi, safi);
2805 } else {
2806 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2807 && afi == AFI_IP && safi == SAFI_UNICAST)
2808 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2809 as_type, 0, 0, NULL);
2810 else
2811 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2812 as_type, afi, safi, NULL);
2813
2814 if (!peer) {
2815 vty_out(vty, "%% BGP failed to create peer\n");
2816 return CMD_WARNING_CONFIG_FAILED;
2817 }
2818
2819 if (v6only)
2820 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2821
2822 /* Request zebra to initiate IPv6 RAs on this interface. We do
2823 * this
2824 * any unnumbered peer in order to not worry about run-time
2825 * transitions
2826 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2827 * address
2828 * gets deleted later etc.)
2829 */
2830 if (peer->ifp)
2831 bgp_zebra_initiate_radv(bgp, peer);
2832 }
2833
2834 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2835 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2836 if (v6only)
2837 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2838 else
2839 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2840
2841 /* v6only flag changed. Reset bgp seesion */
2842 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2843 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2844 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2845 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2846 } else
2847 bgp_session_reset(peer);
2848 }
2849
2850 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2851 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2852
2853 if (peer_group_name) {
2854 group = peer_group_lookup(bgp, peer_group_name);
2855 if (!group) {
2856 vty_out(vty, "%% Configure the peer-group first\n");
2857 return CMD_WARNING_CONFIG_FAILED;
2858 }
2859
2860 ret = peer_group_bind(bgp, &su, peer, group, &as);
2861 }
2862
2863 return bgp_vty_return(vty, ret);
a80beece
DS
2864}
2865
4c48cf63
DW
2866DEFUN (neighbor_interface_config,
2867 neighbor_interface_config_cmd,
31500417 2868 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2869 NEIGHBOR_STR
2870 "Interface name or neighbor tag\n"
31500417
DW
2871 "Enable BGP on interface\n"
2872 "Member of the peer-group\n"
16cedbb0 2873 "Peer-group name\n")
4c48cf63 2874{
d62a17ae 2875 int idx_word = 1;
2876 int idx_peer_group_word = 4;
31500417 2877
d62a17ae 2878 if (argc > idx_peer_group_word)
2879 return peer_conf_interface_get(
2880 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2881 argv[idx_peer_group_word]->arg, NULL);
2882 else
2883 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2884 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2885}
2886
4c48cf63
DW
2887DEFUN (neighbor_interface_config_v6only,
2888 neighbor_interface_config_v6only_cmd,
31500417 2889 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2890 NEIGHBOR_STR
2891 "Interface name or neighbor tag\n"
2892 "Enable BGP on interface\n"
31500417
DW
2893 "Enable BGP with v6 link-local only\n"
2894 "Member of the peer-group\n"
16cedbb0 2895 "Peer-group name\n")
4c48cf63 2896{
d62a17ae 2897 int idx_word = 1;
2898 int idx_peer_group_word = 5;
31500417 2899
d62a17ae 2900 if (argc > idx_peer_group_word)
2901 return peer_conf_interface_get(
2902 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2903 argv[idx_peer_group_word]->arg, NULL);
31500417 2904
d62a17ae 2905 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2906 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2907}
2908
a80beece 2909
b3a39dc5
DD
2910DEFUN (neighbor_interface_config_remote_as,
2911 neighbor_interface_config_remote_as_cmd,
3a2d747c 2912 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2913 NEIGHBOR_STR
2914 "Interface name or neighbor tag\n"
2915 "Enable BGP on interface\n"
3a2d747c 2916 "Specify a BGP neighbor\n"
d7fa34c1 2917 AS_STR
3a2d747c
QY
2918 "Internal BGP peer\n"
2919 "External BGP peer\n")
b3a39dc5 2920{
d62a17ae 2921 int idx_word = 1;
2922 int idx_remote_as = 4;
2923 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2924 SAFI_UNICAST, 0, NULL,
2925 argv[idx_remote_as]->arg);
b3a39dc5
DD
2926}
2927
2928DEFUN (neighbor_interface_v6only_config_remote_as,
2929 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2930 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2931 NEIGHBOR_STR
2932 "Interface name or neighbor tag\n"
3a2d747c 2933 "Enable BGP with v6 link-local only\n"
b3a39dc5 2934 "Enable BGP on interface\n"
3a2d747c 2935 "Specify a BGP neighbor\n"
d7fa34c1 2936 AS_STR
3a2d747c
QY
2937 "Internal BGP peer\n"
2938 "External BGP peer\n")
b3a39dc5 2939{
d62a17ae 2940 int idx_word = 1;
2941 int idx_remote_as = 5;
2942 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2943 SAFI_UNICAST, 1, NULL,
2944 argv[idx_remote_as]->arg);
b3a39dc5
DD
2945}
2946
718e3744 2947DEFUN (neighbor_peer_group,
2948 neighbor_peer_group_cmd,
2949 "neighbor WORD peer-group",
2950 NEIGHBOR_STR
a80beece 2951 "Interface name or neighbor tag\n"
718e3744 2952 "Configure peer-group\n")
2953{
d62a17ae 2954 VTY_DECLVAR_CONTEXT(bgp, bgp);
2955 int idx_word = 1;
2956 struct peer *peer;
2957 struct peer_group *group;
718e3744 2958
d62a17ae 2959 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2960 if (peer) {
2961 vty_out(vty, "%% Name conflict with interface: \n");
2962 return CMD_WARNING_CONFIG_FAILED;
2963 }
718e3744 2964
d62a17ae 2965 group = peer_group_get(bgp, argv[idx_word]->arg);
2966 if (!group) {
2967 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2968 return CMD_WARNING_CONFIG_FAILED;
2969 }
718e3744 2970
d62a17ae 2971 return CMD_SUCCESS;
718e3744 2972}
2973
2974DEFUN (no_neighbor,
2975 no_neighbor_cmd,
dab8cd00 2976 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 2977 NO_STR
2978 NEIGHBOR_STR
3a2d747c
QY
2979 NEIGHBOR_ADDR_STR2
2980 "Specify a BGP neighbor\n"
2981 AS_STR
2982 "Internal BGP peer\n"
2983 "External BGP peer\n")
718e3744 2984{
d62a17ae 2985 VTY_DECLVAR_CONTEXT(bgp, bgp);
2986 int idx_peer = 2;
2987 int ret;
2988 union sockunion su;
2989 struct peer_group *group;
2990 struct peer *peer;
2991 struct peer *other;
2992
2993 ret = str2sockunion(argv[idx_peer]->arg, &su);
2994 if (ret < 0) {
2995 /* look up for neighbor by interface name config. */
2996 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
2997 if (peer) {
2998 /* Request zebra to terminate IPv6 RAs on this
2999 * interface. */
3000 if (peer->ifp)
3001 bgp_zebra_terminate_radv(peer->bgp, peer);
3002 peer_delete(peer);
3003 return CMD_SUCCESS;
3004 }
f14e6fdb 3005
d62a17ae 3006 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3007 if (group)
3008 peer_group_delete(group);
3009 else {
3010 vty_out(vty, "%% Create the peer-group first\n");
3011 return CMD_WARNING_CONFIG_FAILED;
3012 }
3013 } else {
3014 peer = peer_lookup(bgp, &su);
3015 if (peer) {
3016 if (peer_dynamic_neighbor(peer)) {
3017 vty_out(vty,
3018 "%% Operation not allowed on a dynamic neighbor\n");
3019 return CMD_WARNING_CONFIG_FAILED;
3020 }
3021
3022 other = peer->doppelganger;
3023 peer_delete(peer);
3024 if (other && other->status != Deleted)
3025 peer_delete(other);
3026 }
1ff9a340 3027 }
718e3744 3028
d62a17ae 3029 return CMD_SUCCESS;
718e3744 3030}
3031
a80beece
DS
3032DEFUN (no_neighbor_interface_config,
3033 no_neighbor_interface_config_cmd,
31500417 3034 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3035 NO_STR
3036 NEIGHBOR_STR
3037 "Interface name\n"
31500417
DW
3038 "Configure BGP on interface\n"
3039 "Enable BGP with v6 link-local only\n"
3040 "Member of the peer-group\n"
16cedbb0 3041 "Peer-group name\n"
3a2d747c
QY
3042 "Specify a BGP neighbor\n"
3043 AS_STR
3044 "Internal BGP peer\n"
3045 "External BGP peer\n")
a80beece 3046{
d62a17ae 3047 VTY_DECLVAR_CONTEXT(bgp, bgp);
3048 int idx_word = 2;
3049 struct peer *peer;
3050
3051 /* look up for neighbor by interface name config. */
3052 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3053 if (peer) {
3054 /* Request zebra to terminate IPv6 RAs on this interface. */
3055 if (peer->ifp)
3056 bgp_zebra_terminate_radv(peer->bgp, peer);
3057 peer_delete(peer);
3058 } else {
3059 vty_out(vty, "%% Create the bgp interface first\n");
3060 return CMD_WARNING_CONFIG_FAILED;
3061 }
3062 return CMD_SUCCESS;
a80beece
DS
3063}
3064
718e3744 3065DEFUN (no_neighbor_peer_group,
3066 no_neighbor_peer_group_cmd,
3067 "no neighbor WORD peer-group",
3068 NO_STR
3069 NEIGHBOR_STR
3070 "Neighbor tag\n"
3071 "Configure peer-group\n")
3072{
d62a17ae 3073 VTY_DECLVAR_CONTEXT(bgp, bgp);
3074 int idx_word = 2;
3075 struct peer_group *group;
718e3744 3076
d62a17ae 3077 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3078 if (group)
3079 peer_group_delete(group);
3080 else {
3081 vty_out(vty, "%% Create the peer-group first\n");
3082 return CMD_WARNING_CONFIG_FAILED;
3083 }
3084 return CMD_SUCCESS;
718e3744 3085}
3086
a80beece
DS
3087DEFUN (no_neighbor_interface_peer_group_remote_as,
3088 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3089 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3090 NO_STR
3091 NEIGHBOR_STR
a80beece 3092 "Interface name or neighbor tag\n"
718e3744 3093 "Specify a BGP neighbor\n"
3a2d747c
QY
3094 AS_STR
3095 "Internal BGP peer\n"
3096 "External BGP peer\n")
718e3744 3097{
d62a17ae 3098 VTY_DECLVAR_CONTEXT(bgp, bgp);
3099 int idx_word = 2;
3100 struct peer_group *group;
3101 struct peer *peer;
3102
3103 /* look up for neighbor by interface name config. */
3104 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3105 if (peer) {
3106 peer_as_change(peer, 0, AS_SPECIFIED);
3107 return CMD_SUCCESS;
3108 }
3109
3110 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3111 if (group)
3112 peer_group_remote_as_delete(group);
3113 else {
3114 vty_out(vty, "%% Create the peer-group or interface first\n");
3115 return CMD_WARNING_CONFIG_FAILED;
3116 }
3117 return CMD_SUCCESS;
718e3744 3118}
6b0655a2 3119
718e3744 3120DEFUN (neighbor_local_as,
3121 neighbor_local_as_cmd,
9ccf14f7 3122 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3123 NEIGHBOR_STR
3124 NEIGHBOR_ADDR_STR2
3125 "Specify a local-as number\n"
3126 "AS number used as local AS\n")
3127{
d62a17ae 3128 int idx_peer = 1;
3129 int idx_number = 3;
3130 struct peer *peer;
3131 int ret;
3132 as_t as;
718e3744 3133
d62a17ae 3134 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3135 if (!peer)
3136 return CMD_WARNING_CONFIG_FAILED;
718e3744 3137
d62a17ae 3138 as = strtoul(argv[idx_number]->arg, NULL, 10);
3139 ret = peer_local_as_set(peer, as, 0, 0);
3140 return bgp_vty_return(vty, ret);
718e3744 3141}
3142
3143DEFUN (neighbor_local_as_no_prepend,
3144 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3145 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3146 NEIGHBOR_STR
3147 NEIGHBOR_ADDR_STR2
3148 "Specify a local-as number\n"
3149 "AS number used as local AS\n"
3150 "Do not prepend local-as to updates from ebgp peers\n")
3151{
d62a17ae 3152 int idx_peer = 1;
3153 int idx_number = 3;
3154 struct peer *peer;
3155 int ret;
3156 as_t as;
718e3744 3157
d62a17ae 3158 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3159 if (!peer)
3160 return CMD_WARNING_CONFIG_FAILED;
718e3744 3161
d62a17ae 3162 as = strtoul(argv[idx_number]->arg, NULL, 10);
3163 ret = peer_local_as_set(peer, as, 1, 0);
3164 return bgp_vty_return(vty, ret);
718e3744 3165}
3166
9d3f9705
AC
3167DEFUN (neighbor_local_as_no_prepend_replace_as,
3168 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3169 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3170 NEIGHBOR_STR
3171 NEIGHBOR_ADDR_STR2
3172 "Specify a local-as number\n"
3173 "AS number used as local AS\n"
3174 "Do not prepend local-as to updates from ebgp peers\n"
3175 "Do not prepend local-as to updates from ibgp peers\n")
3176{
d62a17ae 3177 int idx_peer = 1;
3178 int idx_number = 3;
3179 struct peer *peer;
3180 int ret;
3181 as_t as;
9d3f9705 3182
d62a17ae 3183 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3184 if (!peer)
3185 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3186
d62a17ae 3187 as = strtoul(argv[idx_number]->arg, NULL, 10);
3188 ret = peer_local_as_set(peer, as, 1, 1);
3189 return bgp_vty_return(vty, ret);
9d3f9705
AC
3190}
3191
718e3744 3192DEFUN (no_neighbor_local_as,
3193 no_neighbor_local_as_cmd,
a636c635 3194 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3195 NO_STR
3196 NEIGHBOR_STR
3197 NEIGHBOR_ADDR_STR2
a636c635
DW
3198 "Specify a local-as number\n"
3199 "AS number used as local AS\n"
3200 "Do not prepend local-as to updates from ebgp peers\n"
3201 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3202{
d62a17ae 3203 int idx_peer = 2;
3204 struct peer *peer;
3205 int ret;
718e3744 3206
d62a17ae 3207 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3208 if (!peer)
3209 return CMD_WARNING_CONFIG_FAILED;
718e3744 3210
d62a17ae 3211 ret = peer_local_as_unset(peer);
3212 return bgp_vty_return(vty, ret);
718e3744 3213}
3214
718e3744 3215
3f9c7369
DS
3216DEFUN (neighbor_solo,
3217 neighbor_solo_cmd,
9ccf14f7 3218 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3219 NEIGHBOR_STR
3220 NEIGHBOR_ADDR_STR2
3221 "Solo peer - part of its own update group\n")
3222{
d62a17ae 3223 int idx_peer = 1;
3224 struct peer *peer;
3225 int ret;
3f9c7369 3226
d62a17ae 3227 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3228 if (!peer)
3229 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3230
d62a17ae 3231 ret = update_group_adjust_soloness(peer, 1);
3232 return bgp_vty_return(vty, ret);
3f9c7369
DS
3233}
3234
3235DEFUN (no_neighbor_solo,
3236 no_neighbor_solo_cmd,
9ccf14f7 3237 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3238 NO_STR
3239 NEIGHBOR_STR
3240 NEIGHBOR_ADDR_STR2
3241 "Solo peer - part of its own update group\n")
3242{
d62a17ae 3243 int idx_peer = 2;
3244 struct peer *peer;
3245 int ret;
3f9c7369 3246
d62a17ae 3247 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3248 if (!peer)
3249 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3250
d62a17ae 3251 ret = update_group_adjust_soloness(peer, 0);
3252 return bgp_vty_return(vty, ret);
3f9c7369
DS
3253}
3254
0df7c91f
PJ
3255DEFUN (neighbor_password,
3256 neighbor_password_cmd,
9ccf14f7 3257 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3258 NEIGHBOR_STR
3259 NEIGHBOR_ADDR_STR2
3260 "Set a password\n"
3261 "The password\n")
3262{
d62a17ae 3263 int idx_peer = 1;
3264 int idx_line = 3;
3265 struct peer *peer;
3266 int ret;
0df7c91f 3267
d62a17ae 3268 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3269 if (!peer)
3270 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3271
d62a17ae 3272 ret = peer_password_set(peer, argv[idx_line]->arg);
3273 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3274}
3275
3276DEFUN (no_neighbor_password,
3277 no_neighbor_password_cmd,
a636c635 3278 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3279 NO_STR
3280 NEIGHBOR_STR
3281 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3282 "Set a password\n"
3283 "The password\n")
0df7c91f 3284{
d62a17ae 3285 int idx_peer = 2;
3286 struct peer *peer;
3287 int ret;
0df7c91f 3288
d62a17ae 3289 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3290 if (!peer)
3291 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3292
d62a17ae 3293 ret = peer_password_unset(peer);
3294 return bgp_vty_return(vty, ret);
0df7c91f 3295}
6b0655a2 3296
718e3744 3297DEFUN (neighbor_activate,
3298 neighbor_activate_cmd,
9ccf14f7 3299 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3300 NEIGHBOR_STR
3301 NEIGHBOR_ADDR_STR2
3302 "Enable the Address Family for this Neighbor\n")
3303{
d62a17ae 3304 int idx_peer = 1;
3305 int ret;
3306 struct peer *peer;
718e3744 3307
d62a17ae 3308 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3309 if (!peer)
3310 return CMD_WARNING_CONFIG_FAILED;
718e3744 3311
d62a17ae 3312 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3313 return bgp_vty_return(vty, ret);
718e3744 3314}
3315
d62a17ae 3316ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3317 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3318 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3319 "Enable the Address Family for this Neighbor\n")
596c17ba 3320
718e3744 3321DEFUN (no_neighbor_activate,
3322 no_neighbor_activate_cmd,
9ccf14f7 3323 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3324 NO_STR
3325 NEIGHBOR_STR
3326 NEIGHBOR_ADDR_STR2
3327 "Enable the Address Family for this Neighbor\n")
3328{
d62a17ae 3329 int idx_peer = 2;
3330 int ret;
3331 struct peer *peer;
718e3744 3332
d62a17ae 3333 /* Lookup peer. */
3334 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3335 if (!peer)
3336 return CMD_WARNING_CONFIG_FAILED;
718e3744 3337
d62a17ae 3338 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3339 return bgp_vty_return(vty, ret);
718e3744 3340}
6b0655a2 3341
d62a17ae 3342ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3343 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3344 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3345 "Enable the Address Family for this Neighbor\n")
596c17ba 3346
718e3744 3347DEFUN (neighbor_set_peer_group,
3348 neighbor_set_peer_group_cmd,
9ccf14f7 3349 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3350 NEIGHBOR_STR
a80beece 3351 NEIGHBOR_ADDR_STR2
718e3744 3352 "Member of the peer-group\n"
16cedbb0 3353 "Peer-group name\n")
718e3744 3354{
d62a17ae 3355 VTY_DECLVAR_CONTEXT(bgp, bgp);
3356 int idx_peer = 1;
3357 int idx_word = 3;
3358 int ret;
3359 as_t as;
3360 union sockunion su;
3361 struct peer *peer;
3362 struct peer_group *group;
3363
3364 peer = NULL;
3365
3366 ret = str2sockunion(argv[idx_peer]->arg, &su);
3367 if (ret < 0) {
3368 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3369 if (!peer) {
3370 vty_out(vty, "%% Malformed address or name: %s\n",
3371 argv[idx_peer]->arg);
3372 return CMD_WARNING_CONFIG_FAILED;
3373 }
3374 } else {
3375 if (peer_address_self_check(bgp, &su)) {
3376 vty_out(vty,
3377 "%% Can not configure the local system as neighbor\n");
3378 return CMD_WARNING_CONFIG_FAILED;
3379 }
3380
3381 /* Disallow for dynamic neighbor. */
3382 peer = peer_lookup(bgp, &su);
3383 if (peer && peer_dynamic_neighbor(peer)) {
3384 vty_out(vty,
3385 "%% Operation not allowed on a dynamic neighbor\n");
3386 return CMD_WARNING_CONFIG_FAILED;
3387 }
3388 }
3389
3390 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3391 if (!group) {
3392 vty_out(vty, "%% Configure the peer-group first\n");
3393 return CMD_WARNING_CONFIG_FAILED;
3394 }
3395
3396 ret = peer_group_bind(bgp, &su, peer, group, &as);
3397
3398 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3399 vty_out(vty,
3400 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3401 as);
3402 return CMD_WARNING_CONFIG_FAILED;
3403 }
3404
3405 return bgp_vty_return(vty, ret);
3406}
3407
3408ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3409 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3410 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3411 "Member of the peer-group\n"
3412 "Peer-group name\n")
596c17ba 3413
718e3744 3414DEFUN (no_neighbor_set_peer_group,
3415 no_neighbor_set_peer_group_cmd,
9ccf14f7 3416 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3417 NO_STR
3418 NEIGHBOR_STR
a80beece 3419 NEIGHBOR_ADDR_STR2
718e3744 3420 "Member of the peer-group\n"
16cedbb0 3421 "Peer-group name\n")
718e3744 3422{
d62a17ae 3423 VTY_DECLVAR_CONTEXT(bgp, bgp);
3424 int idx_peer = 2;
3425 int idx_word = 4;
3426 int ret;
3427 struct peer *peer;
3428 struct peer_group *group;
3429
3430 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3431 if (!peer)
3432 return CMD_WARNING_CONFIG_FAILED;
3433
3434 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3435 if (!group) {
3436 vty_out(vty, "%% Configure the peer-group first\n");
3437 return CMD_WARNING_CONFIG_FAILED;
3438 }
718e3744 3439
827ed707 3440 ret = peer_delete(peer);
718e3744 3441
d62a17ae 3442 return bgp_vty_return(vty, ret);
718e3744 3443}
6b0655a2 3444
d62a17ae 3445ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3446 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3447 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3448 "Member of the peer-group\n"
3449 "Peer-group name\n")
596c17ba 3450
d62a17ae 3451static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
d7c0a89a 3452 uint16_t flag, int set)
718e3744 3453{
d62a17ae 3454 int ret;
3455 struct peer *peer;
718e3744 3456
d62a17ae 3457 peer = peer_and_group_lookup_vty(vty, ip_str);
3458 if (!peer)
3459 return CMD_WARNING_CONFIG_FAILED;
718e3744 3460
7ebe625c
QY
3461 /*
3462 * If 'neighbor <interface>', then this is for directly connected peers,
3463 * we should not accept disable-connected-check.
3464 */
3465 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3466 vty_out(vty,
3467 "%s is directly connected peer, cannot accept disable-"
3468 "connected-check\n",
3469 ip_str);
3470 return CMD_WARNING_CONFIG_FAILED;
3471 }
3472
d62a17ae 3473 if (!set && flag == PEER_FLAG_SHUTDOWN)
3474 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3475
d62a17ae 3476 if (set)
3477 ret = peer_flag_set(peer, flag);
3478 else
3479 ret = peer_flag_unset(peer, flag);
718e3744 3480
d62a17ae 3481 return bgp_vty_return(vty, ret);
718e3744 3482}
3483
d7c0a89a 3484static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint16_t flag)
718e3744 3485{
d62a17ae 3486 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3487}
3488
d62a17ae 3489static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
d7c0a89a 3490 uint16_t flag)
718e3744 3491{
d62a17ae 3492 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3493}
3494
3495/* neighbor passive. */
3496DEFUN (neighbor_passive,
3497 neighbor_passive_cmd,
9ccf14f7 3498 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3499 NEIGHBOR_STR
3500 NEIGHBOR_ADDR_STR2
3501 "Don't send open messages to this neighbor\n")
3502{
d62a17ae 3503 int idx_peer = 1;
3504 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3505}
3506
3507DEFUN (no_neighbor_passive,
3508 no_neighbor_passive_cmd,
9ccf14f7 3509 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3510 NO_STR
3511 NEIGHBOR_STR
3512 NEIGHBOR_ADDR_STR2
3513 "Don't send open messages to this neighbor\n")
3514{
d62a17ae 3515 int idx_peer = 2;
3516 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3517}
6b0655a2 3518
718e3744 3519/* neighbor shutdown. */
73d70fa6
DL
3520DEFUN (neighbor_shutdown_msg,
3521 neighbor_shutdown_msg_cmd,
3522 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3523 NEIGHBOR_STR
3524 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3525 "Administratively shut down this neighbor\n"
3526 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3527 "Shutdown message\n")
718e3744 3528{
d62a17ae 3529 int idx_peer = 1;
73d70fa6 3530
d62a17ae 3531 if (argc >= 5) {
3532 struct peer *peer =
3533 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3534 char *message;
73d70fa6 3535
d62a17ae 3536 if (!peer)
3537 return CMD_WARNING_CONFIG_FAILED;
3538 message = argv_concat(argv, argc, 4);
3539 peer_tx_shutdown_message_set(peer, message);
3540 XFREE(MTYPE_TMP, message);
3541 }
73d70fa6 3542
d62a17ae 3543 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3544}
3545
d62a17ae 3546ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3547 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3548 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3549 "Administratively shut down this neighbor\n")
73d70fa6
DL
3550
3551DEFUN (no_neighbor_shutdown_msg,
3552 no_neighbor_shutdown_msg_cmd,
3553 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3554 NO_STR
3555 NEIGHBOR_STR
3556 NEIGHBOR_ADDR_STR2
3557 "Administratively shut down this neighbor\n"
3558 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3559 "Shutdown message\n")
718e3744 3560{
d62a17ae 3561 int idx_peer = 2;
73d70fa6 3562
d62a17ae 3563 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3564 PEER_FLAG_SHUTDOWN);
718e3744 3565}
6b0655a2 3566
d62a17ae 3567ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3568 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3569 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3570 "Administratively shut down this neighbor\n")
73d70fa6 3571
718e3744 3572/* neighbor capability dynamic. */
3573DEFUN (neighbor_capability_dynamic,
3574 neighbor_capability_dynamic_cmd,
9ccf14f7 3575 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3576 NEIGHBOR_STR
3577 NEIGHBOR_ADDR_STR2
3578 "Advertise capability to the peer\n"
3579 "Advertise dynamic capability to this neighbor\n")
3580{
d62a17ae 3581 int idx_peer = 1;
3582 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3583 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3584}
3585
3586DEFUN (no_neighbor_capability_dynamic,
3587 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3588 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3589 NO_STR
3590 NEIGHBOR_STR
3591 NEIGHBOR_ADDR_STR2
3592 "Advertise capability to the peer\n"
3593 "Advertise dynamic capability to this neighbor\n")
3594{
d62a17ae 3595 int idx_peer = 2;
3596 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3597 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3598}
6b0655a2 3599
718e3744 3600/* neighbor dont-capability-negotiate */
3601DEFUN (neighbor_dont_capability_negotiate,
3602 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3603 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3604 NEIGHBOR_STR
3605 NEIGHBOR_ADDR_STR2
3606 "Do not perform capability negotiation\n")
3607{
d62a17ae 3608 int idx_peer = 1;
3609 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3610 PEER_FLAG_DONT_CAPABILITY);
718e3744 3611}
3612
3613DEFUN (no_neighbor_dont_capability_negotiate,
3614 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3615 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3616 NO_STR
3617 NEIGHBOR_STR
3618 NEIGHBOR_ADDR_STR2
3619 "Do not perform capability negotiation\n")
3620{
d62a17ae 3621 int idx_peer = 2;
3622 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3623 PEER_FLAG_DONT_CAPABILITY);
718e3744 3624}
6b0655a2 3625
8a92a8a0
DS
3626/* neighbor capability extended next hop encoding */
3627DEFUN (neighbor_capability_enhe,
3628 neighbor_capability_enhe_cmd,
9ccf14f7 3629 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3630 NEIGHBOR_STR
3631 NEIGHBOR_ADDR_STR2
3632 "Advertise capability to the peer\n"
3633 "Advertise extended next-hop capability to the peer\n")
3634{
d62a17ae 3635 int idx_peer = 1;
3636 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3637 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3638}
3639
3640DEFUN (no_neighbor_capability_enhe,
3641 no_neighbor_capability_enhe_cmd,
9ccf14f7 3642 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3643 NO_STR
3644 NEIGHBOR_STR
3645 NEIGHBOR_ADDR_STR2
3646 "Advertise capability to the peer\n"
3647 "Advertise extended next-hop capability to the peer\n")
3648{
d62a17ae 3649 int idx_peer = 2;
3650 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3651 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3652}
3653
d62a17ae 3654static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3655 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3656 int set)
718e3744 3657{
d62a17ae 3658 int ret;
3659 struct peer *peer;
718e3744 3660
d62a17ae 3661 peer = peer_and_group_lookup_vty(vty, peer_str);
3662 if (!peer)
3663 return CMD_WARNING_CONFIG_FAILED;
718e3744 3664
d62a17ae 3665 if (set)
3666 ret = peer_af_flag_set(peer, afi, safi, flag);
3667 else
3668 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3669
d62a17ae 3670 return bgp_vty_return(vty, ret);
718e3744 3671}
3672
d62a17ae 3673static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3674 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3675{
d62a17ae 3676 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3677}
3678
d62a17ae 3679static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3680 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3681{
d62a17ae 3682 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3683}
6b0655a2 3684
718e3744 3685/* neighbor capability orf prefix-list. */
3686DEFUN (neighbor_capability_orf_prefix,
3687 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3688 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3689 NEIGHBOR_STR
3690 NEIGHBOR_ADDR_STR2
3691 "Advertise capability to the peer\n"
3692 "Advertise ORF capability to the peer\n"
3693 "Advertise prefixlist ORF capability to this neighbor\n"
3694 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3695 "Capability to RECEIVE the ORF from this neighbor\n"
3696 "Capability to SEND the ORF to this neighbor\n")
3697{
d62a17ae 3698 int idx_peer = 1;
3699 int idx_send_recv = 5;
d7c0a89a 3700 uint16_t flag = 0;
d62a17ae 3701
3702 if (strmatch(argv[idx_send_recv]->text, "send"))
3703 flag = PEER_FLAG_ORF_PREFIX_SM;
3704 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3705 flag = PEER_FLAG_ORF_PREFIX_RM;
3706 else if (strmatch(argv[idx_send_recv]->text, "both"))
3707 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3708 else {
3709 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3710 return CMD_WARNING_CONFIG_FAILED;
3711 }
3712
3713 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3714 bgp_node_safi(vty), flag);
3715}
3716
3717ALIAS_HIDDEN(
3718 neighbor_capability_orf_prefix,
3719 neighbor_capability_orf_prefix_hidden_cmd,
3720 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3721 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3722 "Advertise capability to the peer\n"
3723 "Advertise ORF capability to the peer\n"
3724 "Advertise prefixlist ORF capability to this neighbor\n"
3725 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3726 "Capability to RECEIVE the ORF from this neighbor\n"
3727 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3728
718e3744 3729DEFUN (no_neighbor_capability_orf_prefix,
3730 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3731 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3732 NO_STR
3733 NEIGHBOR_STR
3734 NEIGHBOR_ADDR_STR2
3735 "Advertise capability to the peer\n"
3736 "Advertise ORF capability to the peer\n"
3737 "Advertise prefixlist ORF capability to this neighbor\n"
3738 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3739 "Capability to RECEIVE the ORF from this neighbor\n"
3740 "Capability to SEND the ORF to this neighbor\n")
3741{
d62a17ae 3742 int idx_peer = 2;
3743 int idx_send_recv = 6;
d7c0a89a 3744 uint16_t flag = 0;
d62a17ae 3745
3746 if (strmatch(argv[idx_send_recv]->text, "send"))
3747 flag = PEER_FLAG_ORF_PREFIX_SM;
3748 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3749 flag = PEER_FLAG_ORF_PREFIX_RM;
3750 else if (strmatch(argv[idx_send_recv]->text, "both"))
3751 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3752 else {
3753 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3754 return CMD_WARNING_CONFIG_FAILED;
3755 }
3756
3757 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3758 bgp_node_afi(vty), bgp_node_safi(vty),
3759 flag);
3760}
3761
3762ALIAS_HIDDEN(
3763 no_neighbor_capability_orf_prefix,
3764 no_neighbor_capability_orf_prefix_hidden_cmd,
3765 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3766 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3767 "Advertise capability to the peer\n"
3768 "Advertise ORF capability to the peer\n"
3769 "Advertise prefixlist ORF capability to this neighbor\n"
3770 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3771 "Capability to RECEIVE the ORF from this neighbor\n"
3772 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3773
718e3744 3774/* neighbor next-hop-self. */
3775DEFUN (neighbor_nexthop_self,
3776 neighbor_nexthop_self_cmd,
9ccf14f7 3777 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3778 NEIGHBOR_STR
3779 NEIGHBOR_ADDR_STR2
a538debe 3780 "Disable the next hop calculation for this neighbor\n")
718e3744 3781{
d62a17ae 3782 int idx_peer = 1;
3783 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3784 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3785}
9e7a53c1 3786
d62a17ae 3787ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3788 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3789 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3790 "Disable the next hop calculation for this neighbor\n")
596c17ba 3791
a538debe
DS
3792/* neighbor next-hop-self. */
3793DEFUN (neighbor_nexthop_self_force,
3794 neighbor_nexthop_self_force_cmd,
9ccf14f7 3795 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3796 NEIGHBOR_STR
3797 NEIGHBOR_ADDR_STR2
3798 "Disable the next hop calculation for this neighbor\n"
3799 "Set the next hop to self for reflected routes\n")
3800{
d62a17ae 3801 int idx_peer = 1;
3802 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3803 bgp_node_safi(vty),
3804 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3805}
3806
d62a17ae 3807ALIAS_HIDDEN(neighbor_nexthop_self_force,
3808 neighbor_nexthop_self_force_hidden_cmd,
3809 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3810 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3811 "Disable the next hop calculation for this neighbor\n"
3812 "Set the next hop to self for reflected routes\n")
596c17ba 3813
718e3744 3814DEFUN (no_neighbor_nexthop_self,
3815 no_neighbor_nexthop_self_cmd,
9ccf14f7 3816 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3817 NO_STR
3818 NEIGHBOR_STR
3819 NEIGHBOR_ADDR_STR2
a538debe 3820 "Disable the next hop calculation for this neighbor\n")
718e3744 3821{
d62a17ae 3822 int idx_peer = 2;
3823 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3824 bgp_node_afi(vty), bgp_node_safi(vty),
3825 PEER_FLAG_NEXTHOP_SELF);
718e3744 3826}
6b0655a2 3827
d62a17ae 3828ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3829 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3830 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3831 "Disable the next hop calculation for this neighbor\n")
596c17ba 3832
88b8ed8d 3833DEFUN (no_neighbor_nexthop_self_force,
a538debe 3834 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3835 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3836 NO_STR
3837 NEIGHBOR_STR
3838 NEIGHBOR_ADDR_STR2
3839 "Disable the next hop calculation for this neighbor\n"
3840 "Set the next hop to self for reflected routes\n")
88b8ed8d 3841{
d62a17ae 3842 int idx_peer = 2;
3843 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3844 bgp_node_afi(vty), bgp_node_safi(vty),
3845 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3846}
a538debe 3847
d62a17ae 3848ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3849 no_neighbor_nexthop_self_force_hidden_cmd,
3850 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3851 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3852 "Disable the next hop calculation for this neighbor\n"
3853 "Set the next hop to self for reflected routes\n")
596c17ba 3854
c7122e14
DS
3855/* neighbor as-override */
3856DEFUN (neighbor_as_override,
3857 neighbor_as_override_cmd,
9ccf14f7 3858 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3859 NEIGHBOR_STR
3860 NEIGHBOR_ADDR_STR2
3861 "Override ASNs in outbound updates if aspath equals remote-as\n")
3862{
d62a17ae 3863 int idx_peer = 1;
3864 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3865 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3866}
3867
d62a17ae 3868ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3869 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3870 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3871 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3872
c7122e14
DS
3873DEFUN (no_neighbor_as_override,
3874 no_neighbor_as_override_cmd,
9ccf14f7 3875 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3876 NO_STR
3877 NEIGHBOR_STR
3878 NEIGHBOR_ADDR_STR2
3879 "Override ASNs in outbound updates if aspath equals remote-as\n")
3880{
d62a17ae 3881 int idx_peer = 2;
3882 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3883 bgp_node_afi(vty), bgp_node_safi(vty),
3884 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3885}
3886
d62a17ae 3887ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3888 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3889 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3890 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3891
718e3744 3892/* neighbor remove-private-AS. */
3893DEFUN (neighbor_remove_private_as,
3894 neighbor_remove_private_as_cmd,
9ccf14f7 3895 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3896 NEIGHBOR_STR
3897 NEIGHBOR_ADDR_STR2
5000f21c 3898 "Remove private ASNs in outbound updates\n")
718e3744 3899{
d62a17ae 3900 int idx_peer = 1;
3901 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3902 bgp_node_safi(vty),
3903 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3904}
3905
d62a17ae 3906ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3907 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3908 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3909 "Remove private ASNs in outbound updates\n")
596c17ba 3910
5000f21c
DS
3911DEFUN (neighbor_remove_private_as_all,
3912 neighbor_remove_private_as_all_cmd,
9ccf14f7 3913 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3914 NEIGHBOR_STR
3915 NEIGHBOR_ADDR_STR2
3916 "Remove private ASNs in outbound updates\n"
efd7904e 3917 "Apply to all AS numbers\n")
5000f21c 3918{
d62a17ae 3919 int idx_peer = 1;
3920 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3921 bgp_node_safi(vty),
3922 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3923}
3924
d62a17ae 3925ALIAS_HIDDEN(neighbor_remove_private_as_all,
3926 neighbor_remove_private_as_all_hidden_cmd,
3927 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3928 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3929 "Remove private ASNs in outbound updates\n"
3930 "Apply to all AS numbers")
596c17ba 3931
5000f21c
DS
3932DEFUN (neighbor_remove_private_as_replace_as,
3933 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3934 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3935 NEIGHBOR_STR
3936 NEIGHBOR_ADDR_STR2
3937 "Remove private ASNs in outbound updates\n"
3938 "Replace private ASNs with our ASN in outbound updates\n")
3939{
d62a17ae 3940 int idx_peer = 1;
3941 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3942 bgp_node_safi(vty),
3943 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3944}
3945
d62a17ae 3946ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3947 neighbor_remove_private_as_replace_as_hidden_cmd,
3948 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3949 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3950 "Remove private ASNs in outbound updates\n"
3951 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3952
5000f21c
DS
3953DEFUN (neighbor_remove_private_as_all_replace_as,
3954 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3955 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3956 NEIGHBOR_STR
3957 NEIGHBOR_ADDR_STR2
3958 "Remove private ASNs in outbound updates\n"
16cedbb0 3959 "Apply to all AS numbers\n"
5000f21c
DS
3960 "Replace private ASNs with our ASN in outbound updates\n")
3961{
d62a17ae 3962 int idx_peer = 1;
3963 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3964 bgp_node_safi(vty),
3965 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3966}
3967
d62a17ae 3968ALIAS_HIDDEN(
3969 neighbor_remove_private_as_all_replace_as,
3970 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3971 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3972 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3973 "Remove private ASNs in outbound updates\n"
3974 "Apply to all AS numbers\n"
3975 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3976
718e3744 3977DEFUN (no_neighbor_remove_private_as,
3978 no_neighbor_remove_private_as_cmd,
9ccf14f7 3979 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3980 NO_STR
3981 NEIGHBOR_STR
3982 NEIGHBOR_ADDR_STR2
5000f21c 3983 "Remove private ASNs in outbound updates\n")
718e3744 3984{
d62a17ae 3985 int idx_peer = 2;
3986 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3987 bgp_node_afi(vty), bgp_node_safi(vty),
3988 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3989}
6b0655a2 3990
d62a17ae 3991ALIAS_HIDDEN(no_neighbor_remove_private_as,
3992 no_neighbor_remove_private_as_hidden_cmd,
3993 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3994 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3995 "Remove private ASNs in outbound updates\n")
596c17ba 3996
88b8ed8d 3997DEFUN (no_neighbor_remove_private_as_all,
5000f21c 3998 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 3999 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4000 NO_STR
4001 NEIGHBOR_STR
4002 NEIGHBOR_ADDR_STR2
4003 "Remove private ASNs in outbound updates\n"
16cedbb0 4004 "Apply to all AS numbers\n")
88b8ed8d 4005{
d62a17ae 4006 int idx_peer = 2;
4007 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4008 bgp_node_afi(vty), bgp_node_safi(vty),
4009 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4010}
5000f21c 4011
d62a17ae 4012ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4013 no_neighbor_remove_private_as_all_hidden_cmd,
4014 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4015 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4016 "Remove private ASNs in outbound updates\n"
4017 "Apply to all AS numbers\n")
596c17ba 4018
88b8ed8d 4019DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4020 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4021 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4022 NO_STR
4023 NEIGHBOR_STR
4024 NEIGHBOR_ADDR_STR2
4025 "Remove private ASNs in outbound updates\n"
4026 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4027{
d62a17ae 4028 int idx_peer = 2;
4029 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4030 bgp_node_afi(vty), bgp_node_safi(vty),
4031 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4032}
5000f21c 4033
d62a17ae 4034ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4035 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4036 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4037 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4038 "Remove private ASNs in outbound updates\n"
4039 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4040
88b8ed8d 4041DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4042 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4043 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4044 NO_STR
4045 NEIGHBOR_STR
4046 NEIGHBOR_ADDR_STR2
4047 "Remove private ASNs in outbound updates\n"
16cedbb0 4048 "Apply to all AS numbers\n"
5000f21c 4049 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4050{
d62a17ae 4051 int idx_peer = 2;
4052 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4053 bgp_node_afi(vty), bgp_node_safi(vty),
4054 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4055}
5000f21c 4056
d62a17ae 4057ALIAS_HIDDEN(
4058 no_neighbor_remove_private_as_all_replace_as,
4059 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4060 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4061 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4062 "Remove private ASNs in outbound updates\n"
4063 "Apply to all AS numbers\n"
4064 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4065
5000f21c 4066
718e3744 4067/* neighbor send-community. */
4068DEFUN (neighbor_send_community,
4069 neighbor_send_community_cmd,
9ccf14f7 4070 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4071 NEIGHBOR_STR
4072 NEIGHBOR_ADDR_STR2
4073 "Send Community attribute to this neighbor\n")
4074{
d62a17ae 4075 int idx_peer = 1;
4076 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4077 bgp_node_safi(vty),
4078 PEER_FLAG_SEND_COMMUNITY);
718e3744 4079}
4080
d62a17ae 4081ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4082 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4083 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4084 "Send Community attribute to this neighbor\n")
596c17ba 4085
718e3744 4086DEFUN (no_neighbor_send_community,
4087 no_neighbor_send_community_cmd,
9ccf14f7 4088 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4089 NO_STR
4090 NEIGHBOR_STR
4091 NEIGHBOR_ADDR_STR2
4092 "Send Community attribute to this neighbor\n")
4093{
d62a17ae 4094 int idx_peer = 2;
4095 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4096 bgp_node_afi(vty), bgp_node_safi(vty),
4097 PEER_FLAG_SEND_COMMUNITY);
718e3744 4098}
6b0655a2 4099
d62a17ae 4100ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4101 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4102 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4103 "Send Community attribute to this neighbor\n")
596c17ba 4104
718e3744 4105/* neighbor send-community extended. */
4106DEFUN (neighbor_send_community_type,
4107 neighbor_send_community_type_cmd,
57d187bc 4108 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4109 NEIGHBOR_STR
4110 NEIGHBOR_ADDR_STR2
4111 "Send Community attribute to this neighbor\n"
4112 "Send Standard and Extended Community attributes\n"
57d187bc 4113 "Send Standard, Large and Extended Community attributes\n"
718e3744 4114 "Send Extended Community attributes\n"
57d187bc
JS
4115 "Send Standard Community attributes\n"
4116 "Send Large Community attributes\n")
718e3744 4117{
d62a17ae 4118 int idx = 0;
d7c0a89a 4119 uint32_t flag = 0;
d62a17ae 4120
4121 char *peer = argv[1]->arg;
4122
4123 if (argv_find(argv, argc, "standard", &idx))
4124 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4125 else if (argv_find(argv, argc, "extended", &idx))
4126 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4127 else if (argv_find(argv, argc, "large", &idx))
4128 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4129 else if (argv_find(argv, argc, "both", &idx)) {
4130 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4131 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4132 } else {
4133 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4134 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4135 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4136 }
4137
4138 return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty),
4139 bgp_node_safi(vty), flag);
4140}
4141
4142ALIAS_HIDDEN(
4143 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4144 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4145 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4146 "Send Community attribute to this neighbor\n"
4147 "Send Standard and Extended Community attributes\n"
4148 "Send Standard, Large and Extended Community attributes\n"
4149 "Send Extended Community attributes\n"
4150 "Send Standard Community attributes\n"
4151 "Send Large Community attributes\n")
596c17ba 4152
718e3744 4153DEFUN (no_neighbor_send_community_type,
4154 no_neighbor_send_community_type_cmd,
57d187bc 4155 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4156 NO_STR
4157 NEIGHBOR_STR
4158 NEIGHBOR_ADDR_STR2
4159 "Send Community attribute to this neighbor\n"
4160 "Send Standard and Extended Community attributes\n"
57d187bc 4161 "Send Standard, Large and Extended Community attributes\n"
718e3744 4162 "Send Extended Community attributes\n"
57d187bc
JS
4163 "Send Standard Community attributes\n"
4164 "Send Large Community attributes\n")
718e3744 4165{
d62a17ae 4166 int idx_peer = 2;
4167
4168 const char *type = argv[argc - 1]->text;
4169
4170 if (strmatch(type, "standard"))
4171 return peer_af_flag_unset_vty(
4172 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4173 bgp_node_safi(vty), PEER_FLAG_SEND_COMMUNITY);
4174 if (strmatch(type, "extended"))
4175 return peer_af_flag_unset_vty(
4176 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4177 bgp_node_safi(vty), PEER_FLAG_SEND_EXT_COMMUNITY);
4178 if (strmatch(type, "large"))
4179 return peer_af_flag_unset_vty(
4180 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4181 bgp_node_safi(vty), PEER_FLAG_SEND_LARGE_COMMUNITY);
4182 if (strmatch(type, "both"))
4183 return peer_af_flag_unset_vty(
4184 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4185 bgp_node_safi(vty),
4186 PEER_FLAG_SEND_COMMUNITY
4187 | PEER_FLAG_SEND_EXT_COMMUNITY);
4188
4189 /* if (strmatch (type, "all")) */
4190 return peer_af_flag_unset_vty(
4191 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4192 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY
4193 | PEER_FLAG_SEND_LARGE_COMMUNITY));
4194}
4195
4196ALIAS_HIDDEN(
4197 no_neighbor_send_community_type,
4198 no_neighbor_send_community_type_hidden_cmd,
4199 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4200 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4201 "Send Community attribute to this neighbor\n"
4202 "Send Standard and Extended Community attributes\n"
4203 "Send Standard, Large and Extended Community attributes\n"
4204 "Send Extended Community attributes\n"
4205 "Send Standard Community attributes\n"
4206 "Send Large Community attributes\n")
596c17ba 4207
718e3744 4208/* neighbor soft-reconfig. */
4209DEFUN (neighbor_soft_reconfiguration,
4210 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4211 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4212 NEIGHBOR_STR
4213 NEIGHBOR_ADDR_STR2
4214 "Per neighbor soft reconfiguration\n"
4215 "Allow inbound soft reconfiguration for this neighbor\n")
4216{
d62a17ae 4217 int idx_peer = 1;
4218 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4219 bgp_node_safi(vty),
4220 PEER_FLAG_SOFT_RECONFIG);
718e3744 4221}
4222
d62a17ae 4223ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4224 neighbor_soft_reconfiguration_hidden_cmd,
4225 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4226 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4227 "Per neighbor soft reconfiguration\n"
4228 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4229
718e3744 4230DEFUN (no_neighbor_soft_reconfiguration,
4231 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4232 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4233 NO_STR
4234 NEIGHBOR_STR
4235 NEIGHBOR_ADDR_STR2
4236 "Per neighbor soft reconfiguration\n"
4237 "Allow inbound soft reconfiguration for this neighbor\n")
4238{
d62a17ae 4239 int idx_peer = 2;
4240 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4241 bgp_node_afi(vty), bgp_node_safi(vty),
4242 PEER_FLAG_SOFT_RECONFIG);
718e3744 4243}
6b0655a2 4244
d62a17ae 4245ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4246 no_neighbor_soft_reconfiguration_hidden_cmd,
4247 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4248 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4249 "Per neighbor soft reconfiguration\n"
4250 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4251
718e3744 4252DEFUN (neighbor_route_reflector_client,
4253 neighbor_route_reflector_client_cmd,
9ccf14f7 4254 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4255 NEIGHBOR_STR
4256 NEIGHBOR_ADDR_STR2
4257 "Configure a neighbor as Route Reflector client\n")
4258{
d62a17ae 4259 int idx_peer = 1;
4260 struct peer *peer;
718e3744 4261
4262
d62a17ae 4263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4264 if (!peer)
4265 return CMD_WARNING_CONFIG_FAILED;
718e3744 4266
d62a17ae 4267 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4268 bgp_node_safi(vty),
4269 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4270}
4271
d62a17ae 4272ALIAS_HIDDEN(neighbor_route_reflector_client,
4273 neighbor_route_reflector_client_hidden_cmd,
4274 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4275 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4276 "Configure a neighbor as Route Reflector client\n")
596c17ba 4277
718e3744 4278DEFUN (no_neighbor_route_reflector_client,
4279 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4280 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4281 NO_STR
4282 NEIGHBOR_STR
4283 NEIGHBOR_ADDR_STR2
4284 "Configure a neighbor as Route Reflector client\n")
4285{
d62a17ae 4286 int idx_peer = 2;
4287 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4288 bgp_node_afi(vty), bgp_node_safi(vty),
4289 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4290}
6b0655a2 4291
d62a17ae 4292ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4293 no_neighbor_route_reflector_client_hidden_cmd,
4294 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4295 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4296 "Configure a neighbor as Route Reflector client\n")
596c17ba 4297
718e3744 4298/* neighbor route-server-client. */
4299DEFUN (neighbor_route_server_client,
4300 neighbor_route_server_client_cmd,
9ccf14f7 4301 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4302 NEIGHBOR_STR
4303 NEIGHBOR_ADDR_STR2
4304 "Configure a neighbor as Route Server client\n")
4305{
d62a17ae 4306 int idx_peer = 1;
4307 struct peer *peer;
2a3d5731 4308
d62a17ae 4309 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4310 if (!peer)
4311 return CMD_WARNING_CONFIG_FAILED;
4312 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4313 bgp_node_safi(vty),
4314 PEER_FLAG_RSERVER_CLIENT);
718e3744 4315}
4316
d62a17ae 4317ALIAS_HIDDEN(neighbor_route_server_client,
4318 neighbor_route_server_client_hidden_cmd,
4319 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4320 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4321 "Configure a neighbor as Route Server client\n")
596c17ba 4322
718e3744 4323DEFUN (no_neighbor_route_server_client,
4324 no_neighbor_route_server_client_cmd,
9ccf14f7 4325 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4326 NO_STR
4327 NEIGHBOR_STR
4328 NEIGHBOR_ADDR_STR2
4329 "Configure a neighbor as Route Server client\n")
fee0f4c6 4330{
d62a17ae 4331 int idx_peer = 2;
4332 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4333 bgp_node_afi(vty), bgp_node_safi(vty),
4334 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4335}
6b0655a2 4336
d62a17ae 4337ALIAS_HIDDEN(no_neighbor_route_server_client,
4338 no_neighbor_route_server_client_hidden_cmd,
4339 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4340 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4341 "Configure a neighbor as Route Server client\n")
596c17ba 4342
fee0f4c6 4343DEFUN (neighbor_nexthop_local_unchanged,
4344 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4345 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4346 NEIGHBOR_STR
4347 NEIGHBOR_ADDR_STR2
4348 "Configure treatment of outgoing link-local nexthop attribute\n"
4349 "Leave link-local nexthop unchanged for this peer\n")
4350{
d62a17ae 4351 int idx_peer = 1;
4352 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4353 bgp_node_safi(vty),
4354 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4355}
6b0655a2 4356
fee0f4c6 4357DEFUN (no_neighbor_nexthop_local_unchanged,
4358 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4359 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4360 NO_STR
4361 NEIGHBOR_STR
4362 NEIGHBOR_ADDR_STR2
4363 "Configure treatment of outgoing link-local-nexthop attribute\n"
4364 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4365{
d62a17ae 4366 int idx_peer = 2;
4367 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4368 bgp_node_afi(vty), bgp_node_safi(vty),
4369 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4370}
6b0655a2 4371
718e3744 4372DEFUN (neighbor_attr_unchanged,
4373 neighbor_attr_unchanged_cmd,
a8206004 4374 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4375 NEIGHBOR_STR
4376 NEIGHBOR_ADDR_STR2
4377 "BGP attribute is propagated unchanged to this neighbor\n"
4378 "As-path attribute\n"
4379 "Nexthop attribute\n"
a8206004 4380 "Med attribute\n")
718e3744 4381{
d62a17ae 4382 int idx = 0;
8eeb0335
DW
4383 char *peer_str = argv[1]->arg;
4384 struct peer *peer;
d7c0a89a 4385 uint16_t flags = 0;
8eeb0335
DW
4386 afi_t afi = bgp_node_afi(vty);
4387 safi_t safi = bgp_node_safi(vty);
4388
4389 peer = peer_and_group_lookup_vty(vty, peer_str);
4390 if (!peer)
4391 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4392
4393 if (argv_find(argv, argc, "as-path", &idx))
4394 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4395 idx = 0;
4396 if (argv_find(argv, argc, "next-hop", &idx))
4397 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4398 idx = 0;
4399 if (argv_find(argv, argc, "med", &idx))
4400 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4401
8eeb0335
DW
4402 /* no flags means all of them! */
4403 if (!flags) {
d62a17ae 4404 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4405 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4406 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4407 } else {
a4d82a8a
PZ
4408 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4409 && peer_af_flag_check(peer, afi, safi,
4410 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4411 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4412 PEER_FLAG_AS_PATH_UNCHANGED);
4413 }
4414
a4d82a8a
PZ
4415 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4416 && peer_af_flag_check(peer, afi, safi,
4417 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4418 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4419 PEER_FLAG_NEXTHOP_UNCHANGED);
4420 }
4421
a4d82a8a
PZ
4422 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4423 && peer_af_flag_check(peer, afi, safi,
4424 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4425 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4426 PEER_FLAG_MED_UNCHANGED);
4427 }
d62a17ae 4428 }
4429
8eeb0335 4430 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4431}
4432
4433ALIAS_HIDDEN(
4434 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4435 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4436 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4437 "BGP attribute is propagated unchanged to this neighbor\n"
4438 "As-path attribute\n"
4439 "Nexthop attribute\n"
4440 "Med attribute\n")
596c17ba 4441
718e3744 4442DEFUN (no_neighbor_attr_unchanged,
4443 no_neighbor_attr_unchanged_cmd,
a8206004 4444 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4445 NO_STR
718e3744 4446 NEIGHBOR_STR
4447 NEIGHBOR_ADDR_STR2
31500417
DW
4448 "BGP attribute is propagated unchanged to this neighbor\n"
4449 "As-path attribute\n"
40e718b5 4450 "Nexthop attribute\n"
a8206004 4451 "Med attribute\n")
718e3744 4452{
d62a17ae 4453 int idx = 0;
4454 char *peer = argv[2]->arg;
d7c0a89a 4455 uint16_t flags = 0;
d62a17ae 4456
4457 if (argv_find(argv, argc, "as-path", &idx))
4458 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4459 idx = 0;
4460 if (argv_find(argv, argc, "next-hop", &idx))
4461 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4462 idx = 0;
4463 if (argv_find(argv, argc, "med", &idx))
4464 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4465
4466 if (!flags) // no flags means all of them!
4467 {
4468 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4469 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4470 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4471 }
4472
4473 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4474 bgp_node_safi(vty), flags);
4475}
4476
4477ALIAS_HIDDEN(
4478 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4479 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4480 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4481 "BGP attribute is propagated unchanged to this neighbor\n"
4482 "As-path attribute\n"
4483 "Nexthop attribute\n"
4484 "Med attribute\n")
718e3744 4485
718e3744 4486/* EBGP multihop configuration. */
d62a17ae 4487static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4488 const char *ttl_str)
718e3744 4489{
d62a17ae 4490 struct peer *peer;
4491 unsigned int ttl;
718e3744 4492
d62a17ae 4493 peer = peer_and_group_lookup_vty(vty, ip_str);
4494 if (!peer)
4495 return CMD_WARNING_CONFIG_FAILED;
718e3744 4496
d62a17ae 4497 if (peer->conf_if)
4498 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4499
d62a17ae 4500 if (!ttl_str)
4501 ttl = MAXTTL;
4502 else
4503 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4504
d62a17ae 4505 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4506}
4507
d62a17ae 4508static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4509{
d62a17ae 4510 struct peer *peer;
718e3744 4511
d62a17ae 4512 peer = peer_and_group_lookup_vty(vty, ip_str);
4513 if (!peer)
4514 return CMD_WARNING_CONFIG_FAILED;
718e3744 4515
d62a17ae 4516 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4517}
4518
4519/* neighbor ebgp-multihop. */
4520DEFUN (neighbor_ebgp_multihop,
4521 neighbor_ebgp_multihop_cmd,
9ccf14f7 4522 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4523 NEIGHBOR_STR
4524 NEIGHBOR_ADDR_STR2
4525 "Allow EBGP neighbors not on directly connected networks\n")
4526{
d62a17ae 4527 int idx_peer = 1;
4528 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4529}
4530
4531DEFUN (neighbor_ebgp_multihop_ttl,
4532 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4533 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4534 NEIGHBOR_STR
4535 NEIGHBOR_ADDR_STR2
4536 "Allow EBGP neighbors not on directly connected networks\n"
4537 "maximum hop count\n")
4538{
d62a17ae 4539 int idx_peer = 1;
4540 int idx_number = 3;
4541 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4542 argv[idx_number]->arg);
718e3744 4543}
4544
4545DEFUN (no_neighbor_ebgp_multihop,
4546 no_neighbor_ebgp_multihop_cmd,
a636c635 4547 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4548 NO_STR
4549 NEIGHBOR_STR
4550 NEIGHBOR_ADDR_STR2
a636c635
DW
4551 "Allow EBGP neighbors not on directly connected networks\n"
4552 "maximum hop count\n")
718e3744 4553{
d62a17ae 4554 int idx_peer = 2;
4555 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4556}
4557
6b0655a2 4558
6ffd2079 4559/* disable-connected-check */
4560DEFUN (neighbor_disable_connected_check,
4561 neighbor_disable_connected_check_cmd,
7ebe625c 4562 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4563 NEIGHBOR_STR
7ebe625c 4564 NEIGHBOR_ADDR_STR2
a636c635
DW
4565 "one-hop away EBGP peer using loopback address\n"
4566 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4567{
d62a17ae 4568 int idx_peer = 1;
4569 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4570 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4571}
4572
4573DEFUN (no_neighbor_disable_connected_check,
4574 no_neighbor_disable_connected_check_cmd,
7ebe625c 4575 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4576 NO_STR
4577 NEIGHBOR_STR
7ebe625c 4578 NEIGHBOR_ADDR_STR2
a636c635
DW
4579 "one-hop away EBGP peer using loopback address\n"
4580 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4581{
d62a17ae 4582 int idx_peer = 2;
4583 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4584 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4585}
4586
718e3744 4587DEFUN (neighbor_description,
4588 neighbor_description_cmd,
e961923c 4589 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4590 NEIGHBOR_STR
4591 NEIGHBOR_ADDR_STR2
4592 "Neighbor specific description\n"
4593 "Up to 80 characters describing this neighbor\n")
4594{
d62a17ae 4595 int idx_peer = 1;
4596 int idx_line = 3;
4597 struct peer *peer;
4598 char *str;
718e3744 4599
d62a17ae 4600 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4601 if (!peer)
4602 return CMD_WARNING_CONFIG_FAILED;
718e3744 4603
d62a17ae 4604 str = argv_concat(argv, argc, idx_line);
718e3744 4605
d62a17ae 4606 peer_description_set(peer, str);
718e3744 4607
d62a17ae 4608 XFREE(MTYPE_TMP, str);
718e3744 4609
d62a17ae 4610 return CMD_SUCCESS;
718e3744 4611}
4612
4613DEFUN (no_neighbor_description,
4614 no_neighbor_description_cmd,
a636c635 4615 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
718e3744 4616 NO_STR
4617 NEIGHBOR_STR
4618 NEIGHBOR_ADDR_STR2
a636c635
DW
4619 "Neighbor specific description\n"
4620 "Up to 80 characters describing this neighbor\n")
718e3744 4621{
d62a17ae 4622 int idx_peer = 2;
4623 struct peer *peer;
718e3744 4624
d62a17ae 4625 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4626 if (!peer)
4627 return CMD_WARNING_CONFIG_FAILED;
718e3744 4628
d62a17ae 4629 peer_description_unset(peer);
718e3744 4630
d62a17ae 4631 return CMD_SUCCESS;
718e3744 4632}
4633
6b0655a2 4634
718e3744 4635/* Neighbor update-source. */
d62a17ae 4636static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4637 const char *source_str)
4638{
4639 struct peer *peer;
4640 struct prefix p;
4641
4642 peer = peer_and_group_lookup_vty(vty, peer_str);
4643 if (!peer)
4644 return CMD_WARNING_CONFIG_FAILED;
4645
4646 if (peer->conf_if)
4647 return CMD_WARNING;
4648
4649 if (source_str) {
4650 union sockunion su;
4651 int ret = str2sockunion(source_str, &su);
4652
4653 if (ret == 0)
4654 peer_update_source_addr_set(peer, &su);
4655 else {
4656 if (str2prefix(source_str, &p)) {
4657 vty_out(vty,
4658 "%% Invalid update-source, remove prefix length \n");
4659 return CMD_WARNING_CONFIG_FAILED;
4660 } else
4661 peer_update_source_if_set(peer, source_str);
4662 }
4663 } else
4664 peer_update_source_unset(peer);
4665
4666 return CMD_SUCCESS;
4667}
4668
4669#define BGP_UPDATE_SOURCE_HELP_STR \
4670 "IPv4 address\n" \
4671 "IPv6 address\n" \
4672 "Interface name (requires zebra to be running)\n"
369688c0 4673
718e3744 4674DEFUN (neighbor_update_source,
4675 neighbor_update_source_cmd,
9ccf14f7 4676 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4677 NEIGHBOR_STR
4678 NEIGHBOR_ADDR_STR2
4679 "Source of routing updates\n"
369688c0 4680 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4681{
d62a17ae 4682 int idx_peer = 1;
4683 int idx_peer_2 = 3;
4684 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4685 argv[idx_peer_2]->arg);
718e3744 4686}
4687
4688DEFUN (no_neighbor_update_source,
4689 no_neighbor_update_source_cmd,
c7178fe7 4690 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4691 NO_STR
4692 NEIGHBOR_STR
4693 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4694 "Source of routing updates\n"
4695 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4696{
d62a17ae 4697 int idx_peer = 2;
4698 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4699}
6b0655a2 4700
d62a17ae 4701static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4702 afi_t afi, safi_t safi,
4703 const char *rmap, int set)
718e3744 4704{
d62a17ae 4705 int ret;
4706 struct peer *peer;
718e3744 4707
d62a17ae 4708 peer = peer_and_group_lookup_vty(vty, peer_str);
4709 if (!peer)
4710 return CMD_WARNING_CONFIG_FAILED;
718e3744 4711
d62a17ae 4712 if (set)
4713 ret = peer_default_originate_set(peer, afi, safi, rmap);
4714 else
4715 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4716
d62a17ae 4717 return bgp_vty_return(vty, ret);
718e3744 4718}
4719
4720/* neighbor default-originate. */
4721DEFUN (neighbor_default_originate,
4722 neighbor_default_originate_cmd,
9ccf14f7 4723 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4724 NEIGHBOR_STR
4725 NEIGHBOR_ADDR_STR2
4726 "Originate default route to this neighbor\n")
4727{
d62a17ae 4728 int idx_peer = 1;
4729 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4730 bgp_node_afi(vty),
4731 bgp_node_safi(vty), NULL, 1);
718e3744 4732}
4733
d62a17ae 4734ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4735 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4736 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4737 "Originate default route to this neighbor\n")
596c17ba 4738
718e3744 4739DEFUN (neighbor_default_originate_rmap,
4740 neighbor_default_originate_rmap_cmd,
9ccf14f7 4741 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4742 NEIGHBOR_STR
4743 NEIGHBOR_ADDR_STR2
4744 "Originate default route to this neighbor\n"
4745 "Route-map to specify criteria to originate default\n"
4746 "route-map name\n")
4747{
d62a17ae 4748 int idx_peer = 1;
4749 int idx_word = 4;
4750 return peer_default_originate_set_vty(
4751 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4752 argv[idx_word]->arg, 1);
718e3744 4753}
4754
d62a17ae 4755ALIAS_HIDDEN(
4756 neighbor_default_originate_rmap,
4757 neighbor_default_originate_rmap_hidden_cmd,
4758 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4759 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4760 "Originate default route to this neighbor\n"
4761 "Route-map to specify criteria to originate default\n"
4762 "route-map name\n")
596c17ba 4763
718e3744 4764DEFUN (no_neighbor_default_originate,
4765 no_neighbor_default_originate_cmd,
a636c635 4766 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4767 NO_STR
4768 NEIGHBOR_STR
4769 NEIGHBOR_ADDR_STR2
a636c635
DW
4770 "Originate default route to this neighbor\n"
4771 "Route-map to specify criteria to originate default\n"
4772 "route-map name\n")
718e3744 4773{
d62a17ae 4774 int idx_peer = 2;
4775 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4776 bgp_node_afi(vty),
4777 bgp_node_safi(vty), NULL, 0);
718e3744 4778}
4779
d62a17ae 4780ALIAS_HIDDEN(
4781 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4782 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4783 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4784 "Originate default route to this neighbor\n"
4785 "Route-map to specify criteria to originate default\n"
4786 "route-map name\n")
596c17ba 4787
6b0655a2 4788
718e3744 4789/* Set neighbor's BGP port. */
d62a17ae 4790static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4791 const char *port_str)
4792{
4793 struct peer *peer;
d7c0a89a 4794 uint16_t port;
d62a17ae 4795 struct servent *sp;
4796
4797 peer = peer_lookup_vty(vty, ip_str);
4798 if (!peer)
4799 return CMD_WARNING_CONFIG_FAILED;
4800
4801 if (!port_str) {
4802 sp = getservbyname("bgp", "tcp");
4803 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4804 } else {
4805 port = strtoul(port_str, NULL, 10);
4806 }
718e3744 4807
d62a17ae 4808 peer_port_set(peer, port);
718e3744 4809
d62a17ae 4810 return CMD_SUCCESS;
718e3744 4811}
4812
f418446b 4813/* Set specified peer's BGP port. */
718e3744 4814DEFUN (neighbor_port,
4815 neighbor_port_cmd,
9ccf14f7 4816 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4817 NEIGHBOR_STR
4818 NEIGHBOR_ADDR_STR
4819 "Neighbor's BGP port\n"
4820 "TCP port number\n")
4821{
d62a17ae 4822 int idx_ip = 1;
4823 int idx_number = 3;
4824 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4825 argv[idx_number]->arg);
718e3744 4826}
4827
4828DEFUN (no_neighbor_port,
4829 no_neighbor_port_cmd,
9ccf14f7 4830 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4831 NO_STR
4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR
8334fd5a
DW
4834 "Neighbor's BGP port\n"
4835 "TCP port number\n")
718e3744 4836{
d62a17ae 4837 int idx_ip = 2;
4838 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4839}
4840
6b0655a2 4841
718e3744 4842/* neighbor weight. */
d62a17ae 4843static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4844 safi_t safi, const char *weight_str)
718e3744 4845{
d62a17ae 4846 int ret;
4847 struct peer *peer;
4848 unsigned long weight;
718e3744 4849
d62a17ae 4850 peer = peer_and_group_lookup_vty(vty, ip_str);
4851 if (!peer)
4852 return CMD_WARNING_CONFIG_FAILED;
718e3744 4853
d62a17ae 4854 weight = strtoul(weight_str, NULL, 10);
718e3744 4855
d62a17ae 4856 ret = peer_weight_set(peer, afi, safi, weight);
4857 return bgp_vty_return(vty, ret);
718e3744 4858}
4859
d62a17ae 4860static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4861 safi_t safi)
718e3744 4862{
d62a17ae 4863 int ret;
4864 struct peer *peer;
718e3744 4865
d62a17ae 4866 peer = peer_and_group_lookup_vty(vty, ip_str);
4867 if (!peer)
4868 return CMD_WARNING_CONFIG_FAILED;
718e3744 4869
d62a17ae 4870 ret = peer_weight_unset(peer, afi, safi);
4871 return bgp_vty_return(vty, ret);
718e3744 4872}
4873
4874DEFUN (neighbor_weight,
4875 neighbor_weight_cmd,
9ccf14f7 4876 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4877 NEIGHBOR_STR
4878 NEIGHBOR_ADDR_STR2
4879 "Set default weight for routes from this neighbor\n"
4880 "default weight\n")
4881{
d62a17ae 4882 int idx_peer = 1;
4883 int idx_number = 3;
4884 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4885 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4886}
4887
d62a17ae 4888ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4889 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4890 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4891 "Set default weight for routes from this neighbor\n"
4892 "default weight\n")
596c17ba 4893
718e3744 4894DEFUN (no_neighbor_weight,
4895 no_neighbor_weight_cmd,
9ccf14f7 4896 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4897 NO_STR
4898 NEIGHBOR_STR
4899 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4900 "Set default weight for routes from this neighbor\n"
4901 "default weight\n")
718e3744 4902{
d62a17ae 4903 int idx_peer = 2;
4904 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4905 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4906}
4907
d62a17ae 4908ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4909 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4910 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4911 "Set default weight for routes from this neighbor\n"
4912 "default weight\n")
596c17ba 4913
6b0655a2 4914
718e3744 4915/* Override capability negotiation. */
4916DEFUN (neighbor_override_capability,
4917 neighbor_override_capability_cmd,
9ccf14f7 4918 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4919 NEIGHBOR_STR
4920 NEIGHBOR_ADDR_STR2
4921 "Override capability negotiation result\n")
4922{
d62a17ae 4923 int idx_peer = 1;
4924 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4925 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4926}
4927
4928DEFUN (no_neighbor_override_capability,
4929 no_neighbor_override_capability_cmd,
9ccf14f7 4930 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4931 NO_STR
4932 NEIGHBOR_STR
4933 NEIGHBOR_ADDR_STR2
4934 "Override capability negotiation result\n")
4935{
d62a17ae 4936 int idx_peer = 2;
4937 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4938 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4939}
6b0655a2 4940
718e3744 4941DEFUN (neighbor_strict_capability,
4942 neighbor_strict_capability_cmd,
9ccf14f7 4943 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4944 NEIGHBOR_STR
4945 NEIGHBOR_ADDR_STR
4946 "Strict capability negotiation match\n")
4947{
d62a17ae 4948 int idx_ip = 1;
4949 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4950 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4951}
4952
4953DEFUN (no_neighbor_strict_capability,
4954 no_neighbor_strict_capability_cmd,
9ccf14f7 4955 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4956 NO_STR
4957 NEIGHBOR_STR
4958 NEIGHBOR_ADDR_STR
4959 "Strict capability negotiation match\n")
4960{
d62a17ae 4961 int idx_ip = 2;
4962 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
4963 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4964}
6b0655a2 4965
d62a17ae 4966static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
4967 const char *keep_str, const char *hold_str)
718e3744 4968{
d62a17ae 4969 int ret;
4970 struct peer *peer;
d7c0a89a
QY
4971 uint32_t keepalive;
4972 uint32_t holdtime;
718e3744 4973
d62a17ae 4974 peer = peer_and_group_lookup_vty(vty, ip_str);
4975 if (!peer)
4976 return CMD_WARNING_CONFIG_FAILED;
718e3744 4977
d62a17ae 4978 keepalive = strtoul(keep_str, NULL, 10);
4979 holdtime = strtoul(hold_str, NULL, 10);
718e3744 4980
d62a17ae 4981 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 4982
d62a17ae 4983 return bgp_vty_return(vty, ret);
718e3744 4984}
6b0655a2 4985
d62a17ae 4986static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4987{
d62a17ae 4988 int ret;
4989 struct peer *peer;
718e3744 4990
d62a17ae 4991 peer = peer_and_group_lookup_vty(vty, ip_str);
4992 if (!peer)
4993 return CMD_WARNING_CONFIG_FAILED;
718e3744 4994
d62a17ae 4995 ret = peer_timers_unset(peer);
718e3744 4996
d62a17ae 4997 return bgp_vty_return(vty, ret);
718e3744 4998}
4999
5000DEFUN (neighbor_timers,
5001 neighbor_timers_cmd,
9ccf14f7 5002 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5003 NEIGHBOR_STR
5004 NEIGHBOR_ADDR_STR2
5005 "BGP per neighbor timers\n"
5006 "Keepalive interval\n"
5007 "Holdtime\n")
5008{
d62a17ae 5009 int idx_peer = 1;
5010 int idx_number = 3;
5011 int idx_number_2 = 4;
5012 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5013 argv[idx_number]->arg,
5014 argv[idx_number_2]->arg);
718e3744 5015}
5016
5017DEFUN (no_neighbor_timers,
5018 no_neighbor_timers_cmd,
9ccf14f7 5019 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5020 NO_STR
5021 NEIGHBOR_STR
5022 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5023 "BGP per neighbor timers\n"
5024 "Keepalive interval\n"
5025 "Holdtime\n")
718e3744 5026{
d62a17ae 5027 int idx_peer = 2;
5028 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5029}
6b0655a2 5030
813d4307 5031
d62a17ae 5032static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5033 const char *time_str)
718e3744 5034{
d62a17ae 5035 int ret;
5036 struct peer *peer;
d7c0a89a 5037 uint32_t connect;
718e3744 5038
d62a17ae 5039 peer = peer_and_group_lookup_vty(vty, ip_str);
5040 if (!peer)
5041 return CMD_WARNING_CONFIG_FAILED;
718e3744 5042
d62a17ae 5043 connect = strtoul(time_str, NULL, 10);
718e3744 5044
d62a17ae 5045 ret = peer_timers_connect_set(peer, connect);
718e3744 5046
d62a17ae 5047 return bgp_vty_return(vty, ret);
718e3744 5048}
5049
d62a17ae 5050static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5051{
d62a17ae 5052 int ret;
5053 struct peer *peer;
718e3744 5054
d62a17ae 5055 peer = peer_and_group_lookup_vty(vty, ip_str);
5056 if (!peer)
5057 return CMD_WARNING_CONFIG_FAILED;
718e3744 5058
d62a17ae 5059 ret = peer_timers_connect_unset(peer);
718e3744 5060
d62a17ae 5061 return bgp_vty_return(vty, ret);
718e3744 5062}
5063
5064DEFUN (neighbor_timers_connect,
5065 neighbor_timers_connect_cmd,
9ccf14f7 5066 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5067 NEIGHBOR_STR
966f821c 5068 NEIGHBOR_ADDR_STR2
718e3744 5069 "BGP per neighbor timers\n"
5070 "BGP connect timer\n"
5071 "Connect timer\n")
5072{
d62a17ae 5073 int idx_peer = 1;
5074 int idx_number = 4;
5075 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5076 argv[idx_number]->arg);
718e3744 5077}
5078
5079DEFUN (no_neighbor_timers_connect,
5080 no_neighbor_timers_connect_cmd,
9ccf14f7 5081 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5082 NO_STR
5083 NEIGHBOR_STR
966f821c 5084 NEIGHBOR_ADDR_STR2
718e3744 5085 "BGP per neighbor timers\n"
8334fd5a
DW
5086 "BGP connect timer\n"
5087 "Connect timer\n")
718e3744 5088{
d62a17ae 5089 int idx_peer = 2;
5090 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5091}
5092
6b0655a2 5093
d62a17ae 5094static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5095 const char *time_str, int set)
718e3744 5096{
d62a17ae 5097 int ret;
5098 struct peer *peer;
d7c0a89a 5099 uint32_t routeadv = 0;
718e3744 5100
d62a17ae 5101 peer = peer_and_group_lookup_vty(vty, ip_str);
5102 if (!peer)
5103 return CMD_WARNING_CONFIG_FAILED;
718e3744 5104
d62a17ae 5105 if (time_str)
5106 routeadv = strtoul(time_str, NULL, 10);
718e3744 5107
d62a17ae 5108 if (set)
5109 ret = peer_advertise_interval_set(peer, routeadv);
5110 else
5111 ret = peer_advertise_interval_unset(peer);
718e3744 5112
d62a17ae 5113 return bgp_vty_return(vty, ret);
718e3744 5114}
5115
5116DEFUN (neighbor_advertise_interval,
5117 neighbor_advertise_interval_cmd,
9ccf14f7 5118 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5119 NEIGHBOR_STR
966f821c 5120 NEIGHBOR_ADDR_STR2
718e3744 5121 "Minimum interval between sending BGP routing updates\n"
5122 "time in seconds\n")
5123{
d62a17ae 5124 int idx_peer = 1;
5125 int idx_number = 3;
5126 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5127 argv[idx_number]->arg, 1);
718e3744 5128}
5129
5130DEFUN (no_neighbor_advertise_interval,
5131 no_neighbor_advertise_interval_cmd,
9ccf14f7 5132 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5133 NO_STR
5134 NEIGHBOR_STR
966f821c 5135 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5136 "Minimum interval between sending BGP routing updates\n"
5137 "time in seconds\n")
718e3744 5138{
d62a17ae 5139 int idx_peer = 2;
5140 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5141}
5142
6b0655a2 5143
518f0eb1
DS
5144/* Time to wait before processing route-map updates */
5145DEFUN (bgp_set_route_map_delay_timer,
5146 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5147 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5148 SET_STR
5149 "BGP route-map delay timer\n"
5150 "Time in secs to wait before processing route-map changes\n"
f414725f 5151 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5152{
d62a17ae 5153 int idx_number = 3;
d7c0a89a 5154 uint32_t rmap_delay_timer;
d62a17ae 5155
5156 if (argv[idx_number]->arg) {
5157 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5158 bm->rmap_update_timer = rmap_delay_timer;
5159
5160 /* if the dynamic update handling is being disabled, and a timer
5161 * is
5162 * running, stop the timer and act as if the timer has already
5163 * fired.
5164 */
5165 if (!rmap_delay_timer && bm->t_rmap_update) {
5166 BGP_TIMER_OFF(bm->t_rmap_update);
5167 thread_execute(bm->master, bgp_route_map_update_timer,
5168 NULL, 0);
5169 }
5170 return CMD_SUCCESS;
5171 } else {
5172 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5173 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5174 }
518f0eb1
DS
5175}
5176
5177DEFUN (no_bgp_set_route_map_delay_timer,
5178 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5179 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5180 NO_STR
3a2d747c 5181 BGP_STR
518f0eb1 5182 "Default BGP route-map delay timer\n"
8334fd5a
DW
5183 "Reset to default time to wait for processing route-map changes\n"
5184 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5185{
518f0eb1 5186
d62a17ae 5187 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5188
d62a17ae 5189 return CMD_SUCCESS;
518f0eb1
DS
5190}
5191
f414725f 5192
718e3744 5193/* neighbor interface */
d62a17ae 5194static int peer_interface_vty(struct vty *vty, const char *ip_str,
5195 const char *str)
718e3744 5196{
d62a17ae 5197 struct peer *peer;
718e3744 5198
d62a17ae 5199 peer = peer_lookup_vty(vty, ip_str);
5200 if (!peer || peer->conf_if) {
5201 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5202 return CMD_WARNING_CONFIG_FAILED;
5203 }
718e3744 5204
d62a17ae 5205 if (str)
5206 peer_interface_set(peer, str);
5207 else
5208 peer_interface_unset(peer);
718e3744 5209
d62a17ae 5210 return CMD_SUCCESS;
718e3744 5211}
5212
5213DEFUN (neighbor_interface,
5214 neighbor_interface_cmd,
9ccf14f7 5215 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5216 NEIGHBOR_STR
5217 NEIGHBOR_ADDR_STR
5218 "Interface\n"
5219 "Interface name\n")
5220{
d62a17ae 5221 int idx_ip = 1;
5222 int idx_word = 3;
5223 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5224}
5225
5226DEFUN (no_neighbor_interface,
5227 no_neighbor_interface_cmd,
9ccf14f7 5228 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5229 NO_STR
5230 NEIGHBOR_STR
16cedbb0 5231 NEIGHBOR_ADDR_STR2
718e3744 5232 "Interface\n"
5233 "Interface name\n")
5234{
d62a17ae 5235 int idx_peer = 2;
5236 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5237}
6b0655a2 5238
718e3744 5239DEFUN (neighbor_distribute_list,
5240 neighbor_distribute_list_cmd,
9ccf14f7 5241 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5242 NEIGHBOR_STR
5243 NEIGHBOR_ADDR_STR2
5244 "Filter updates to/from this neighbor\n"
5245 "IP access-list number\n"
5246 "IP access-list number (expanded range)\n"
5247 "IP Access-list name\n"
5248 "Filter incoming updates\n"
5249 "Filter outgoing updates\n")
5250{
d62a17ae 5251 int idx_peer = 1;
5252 int idx_acl = 3;
5253 int direct, ret;
5254 struct peer *peer;
a8206004 5255
d62a17ae 5256 const char *pstr = argv[idx_peer]->arg;
5257 const char *acl = argv[idx_acl]->arg;
5258 const char *inout = argv[argc - 1]->text;
a8206004 5259
d62a17ae 5260 peer = peer_and_group_lookup_vty(vty, pstr);
5261 if (!peer)
5262 return CMD_WARNING_CONFIG_FAILED;
a8206004 5263
d62a17ae 5264 /* Check filter direction. */
5265 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5266 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5267 direct, acl);
a8206004 5268
d62a17ae 5269 return bgp_vty_return(vty, ret);
718e3744 5270}
5271
d62a17ae 5272ALIAS_HIDDEN(
5273 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5274 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5275 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5276 "Filter updates to/from this neighbor\n"
5277 "IP access-list number\n"
5278 "IP access-list number (expanded range)\n"
5279 "IP Access-list name\n"
5280 "Filter incoming updates\n"
5281 "Filter outgoing updates\n")
596c17ba 5282
718e3744 5283DEFUN (no_neighbor_distribute_list,
5284 no_neighbor_distribute_list_cmd,
9ccf14f7 5285 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5286 NO_STR
5287 NEIGHBOR_STR
5288 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")
5295{
d62a17ae 5296 int idx_peer = 2;
5297 int direct, ret;
5298 struct peer *peer;
a8206004 5299
d62a17ae 5300 const char *pstr = argv[idx_peer]->arg;
5301 const char *inout = argv[argc - 1]->text;
a8206004 5302
d62a17ae 5303 peer = peer_and_group_lookup_vty(vty, pstr);
5304 if (!peer)
5305 return CMD_WARNING_CONFIG_FAILED;
a8206004 5306
d62a17ae 5307 /* Check filter direction. */
5308 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5309 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5310 direct);
a8206004 5311
d62a17ae 5312 return bgp_vty_return(vty, ret);
718e3744 5313}
6b0655a2 5314
d62a17ae 5315ALIAS_HIDDEN(
5316 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5317 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5318 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5319 "Filter updates to/from this neighbor\n"
5320 "IP access-list number\n"
5321 "IP access-list number (expanded range)\n"
5322 "IP Access-list name\n"
5323 "Filter incoming updates\n"
5324 "Filter outgoing updates\n")
596c17ba 5325
718e3744 5326/* Set prefix list to the peer. */
d62a17ae 5327static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5328 afi_t afi, safi_t safi,
5329 const char *name_str,
5330 const char *direct_str)
718e3744 5331{
d62a17ae 5332 int ret;
5333 struct peer *peer;
5334 int direct = FILTER_IN;
718e3744 5335
d62a17ae 5336 peer = peer_and_group_lookup_vty(vty, ip_str);
5337 if (!peer)
5338 return CMD_WARNING_CONFIG_FAILED;
718e3744 5339
d62a17ae 5340 /* Check filter direction. */
5341 if (strncmp(direct_str, "i", 1) == 0)
5342 direct = FILTER_IN;
5343 else if (strncmp(direct_str, "o", 1) == 0)
5344 direct = FILTER_OUT;
718e3744 5345
d62a17ae 5346 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5347
d62a17ae 5348 return bgp_vty_return(vty, ret);
718e3744 5349}
5350
d62a17ae 5351static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5352 afi_t afi, safi_t safi,
5353 const char *direct_str)
718e3744 5354{
d62a17ae 5355 int ret;
5356 struct peer *peer;
5357 int direct = FILTER_IN;
718e3744 5358
d62a17ae 5359 peer = peer_and_group_lookup_vty(vty, ip_str);
5360 if (!peer)
5361 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5362
d62a17ae 5363 /* Check filter direction. */
5364 if (strncmp(direct_str, "i", 1) == 0)
5365 direct = FILTER_IN;
5366 else if (strncmp(direct_str, "o", 1) == 0)
5367 direct = FILTER_OUT;
718e3744 5368
d62a17ae 5369 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5370
d62a17ae 5371 return bgp_vty_return(vty, ret);
718e3744 5372}
5373
5374DEFUN (neighbor_prefix_list,
5375 neighbor_prefix_list_cmd,
9ccf14f7 5376 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5377 NEIGHBOR_STR
5378 NEIGHBOR_ADDR_STR2
5379 "Filter updates to/from this neighbor\n"
5380 "Name of a prefix list\n"
5381 "Filter incoming updates\n"
5382 "Filter outgoing updates\n")
5383{
d62a17ae 5384 int idx_peer = 1;
5385 int idx_word = 3;
5386 int idx_in_out = 4;
5387 return peer_prefix_list_set_vty(
5388 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5389 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5390}
5391
d62a17ae 5392ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5393 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5394 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5395 "Filter updates to/from this neighbor\n"
5396 "Name of a prefix list\n"
5397 "Filter incoming updates\n"
5398 "Filter outgoing updates\n")
596c17ba 5399
718e3744 5400DEFUN (no_neighbor_prefix_list,
5401 no_neighbor_prefix_list_cmd,
9ccf14f7 5402 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5403 NO_STR
5404 NEIGHBOR_STR
5405 NEIGHBOR_ADDR_STR2
5406 "Filter updates to/from this neighbor\n"
5407 "Name of a prefix list\n"
5408 "Filter incoming updates\n"
5409 "Filter outgoing updates\n")
5410{
d62a17ae 5411 int idx_peer = 2;
5412 int idx_in_out = 5;
5413 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5414 bgp_node_afi(vty), bgp_node_safi(vty),
5415 argv[idx_in_out]->arg);
718e3744 5416}
6b0655a2 5417
d62a17ae 5418ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5419 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5420 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5421 "Filter updates to/from this neighbor\n"
5422 "Name of a prefix list\n"
5423 "Filter incoming updates\n"
5424 "Filter outgoing updates\n")
596c17ba 5425
d62a17ae 5426static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5427 safi_t safi, const char *name_str,
5428 const char *direct_str)
718e3744 5429{
d62a17ae 5430 int ret;
5431 struct peer *peer;
5432 int direct = FILTER_IN;
718e3744 5433
d62a17ae 5434 peer = peer_and_group_lookup_vty(vty, ip_str);
5435 if (!peer)
5436 return CMD_WARNING_CONFIG_FAILED;
718e3744 5437
d62a17ae 5438 /* Check filter direction. */
5439 if (strncmp(direct_str, "i", 1) == 0)
5440 direct = FILTER_IN;
5441 else if (strncmp(direct_str, "o", 1) == 0)
5442 direct = FILTER_OUT;
718e3744 5443
d62a17ae 5444 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5445
d62a17ae 5446 return bgp_vty_return(vty, ret);
718e3744 5447}
5448
d62a17ae 5449static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5450 safi_t safi, const char *direct_str)
718e3744 5451{
d62a17ae 5452 int ret;
5453 struct peer *peer;
5454 int direct = FILTER_IN;
718e3744 5455
d62a17ae 5456 peer = peer_and_group_lookup_vty(vty, ip_str);
5457 if (!peer)
5458 return CMD_WARNING_CONFIG_FAILED;
718e3744 5459
d62a17ae 5460 /* Check filter direction. */
5461 if (strncmp(direct_str, "i", 1) == 0)
5462 direct = FILTER_IN;
5463 else if (strncmp(direct_str, "o", 1) == 0)
5464 direct = FILTER_OUT;
718e3744 5465
d62a17ae 5466 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5467
d62a17ae 5468 return bgp_vty_return(vty, ret);
718e3744 5469}
5470
5471DEFUN (neighbor_filter_list,
5472 neighbor_filter_list_cmd,
9ccf14f7 5473 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5474 NEIGHBOR_STR
5475 NEIGHBOR_ADDR_STR2
5476 "Establish BGP filters\n"
5477 "AS path access-list name\n"
5478 "Filter incoming routes\n"
5479 "Filter outgoing routes\n")
5480{
d62a17ae 5481 int idx_peer = 1;
5482 int idx_word = 3;
5483 int idx_in_out = 4;
5484 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5485 bgp_node_safi(vty), argv[idx_word]->arg,
5486 argv[idx_in_out]->arg);
718e3744 5487}
5488
d62a17ae 5489ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5490 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5491 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5492 "Establish BGP filters\n"
5493 "AS path access-list name\n"
5494 "Filter incoming routes\n"
5495 "Filter outgoing routes\n")
596c17ba 5496
718e3744 5497DEFUN (no_neighbor_filter_list,
5498 no_neighbor_filter_list_cmd,
9ccf14f7 5499 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5500 NO_STR
5501 NEIGHBOR_STR
5502 NEIGHBOR_ADDR_STR2
5503 "Establish BGP filters\n"
5504 "AS path access-list name\n"
5505 "Filter incoming routes\n"
5506 "Filter outgoing routes\n")
5507{
d62a17ae 5508 int idx_peer = 2;
5509 int idx_in_out = 5;
5510 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5511 bgp_node_afi(vty), bgp_node_safi(vty),
5512 argv[idx_in_out]->arg);
718e3744 5513}
6b0655a2 5514
d62a17ae 5515ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5516 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5517 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5518 "Establish BGP filters\n"
5519 "AS path access-list name\n"
5520 "Filter incoming routes\n"
5521 "Filter outgoing routes\n")
596c17ba 5522
718e3744 5523/* Set route-map to the peer. */
d62a17ae 5524static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5525 afi_t afi, safi_t safi, const char *name_str,
5526 const char *direct_str)
718e3744 5527{
d62a17ae 5528 int ret;
5529 struct peer *peer;
5530 int direct = RMAP_IN;
718e3744 5531
d62a17ae 5532 peer = peer_and_group_lookup_vty(vty, ip_str);
5533 if (!peer)
5534 return CMD_WARNING_CONFIG_FAILED;
718e3744 5535
d62a17ae 5536 /* Check filter direction. */
5537 if (strncmp(direct_str, "in", 2) == 0)
5538 direct = RMAP_IN;
5539 else if (strncmp(direct_str, "o", 1) == 0)
5540 direct = RMAP_OUT;
718e3744 5541
d62a17ae 5542 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5543
d62a17ae 5544 return bgp_vty_return(vty, ret);
718e3744 5545}
5546
d62a17ae 5547static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5548 afi_t afi, safi_t safi,
5549 const char *direct_str)
718e3744 5550{
d62a17ae 5551 int ret;
5552 struct peer *peer;
5553 int direct = RMAP_IN;
718e3744 5554
d62a17ae 5555 peer = peer_and_group_lookup_vty(vty, ip_str);
5556 if (!peer)
5557 return CMD_WARNING_CONFIG_FAILED;
718e3744 5558
d62a17ae 5559 /* Check filter direction. */
5560 if (strncmp(direct_str, "in", 2) == 0)
5561 direct = RMAP_IN;
5562 else if (strncmp(direct_str, "o", 1) == 0)
5563 direct = RMAP_OUT;
718e3744 5564
d62a17ae 5565 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5566
d62a17ae 5567 return bgp_vty_return(vty, ret);
718e3744 5568}
5569
5570DEFUN (neighbor_route_map,
5571 neighbor_route_map_cmd,
9ccf14f7 5572 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5573 NEIGHBOR_STR
5574 NEIGHBOR_ADDR_STR2
5575 "Apply route map to neighbor\n"
5576 "Name of route map\n"
5577 "Apply map to incoming routes\n"
2a3d5731 5578 "Apply map to outbound routes\n")
718e3744 5579{
d62a17ae 5580 int idx_peer = 1;
5581 int idx_word = 3;
5582 int idx_in_out = 4;
5583 return peer_route_map_set_vty(
5584 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5585 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5586}
5587
d62a17ae 5588ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5589 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5590 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5591 "Apply route map to neighbor\n"
5592 "Name of route map\n"
5593 "Apply map to incoming routes\n"
5594 "Apply map to outbound routes\n")
596c17ba 5595
718e3744 5596DEFUN (no_neighbor_route_map,
5597 no_neighbor_route_map_cmd,
9ccf14f7 5598 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5599 NO_STR
5600 NEIGHBOR_STR
5601 NEIGHBOR_ADDR_STR2
5602 "Apply route map to neighbor\n"
5603 "Name of route map\n"
5604 "Apply map to incoming routes\n"
2a3d5731 5605 "Apply map to outbound routes\n")
718e3744 5606{
d62a17ae 5607 int idx_peer = 2;
5608 int idx_in_out = 5;
5609 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5610 bgp_node_afi(vty), bgp_node_safi(vty),
5611 argv[idx_in_out]->arg);
718e3744 5612}
6b0655a2 5613
d62a17ae 5614ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5615 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5616 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5617 "Apply route map to neighbor\n"
5618 "Name of route map\n"
5619 "Apply map to incoming routes\n"
5620 "Apply map to outbound routes\n")
596c17ba 5621
718e3744 5622/* Set unsuppress-map to the peer. */
d62a17ae 5623static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5624 afi_t afi, safi_t safi,
5625 const char *name_str)
718e3744 5626{
d62a17ae 5627 int ret;
5628 struct peer *peer;
718e3744 5629
d62a17ae 5630 peer = peer_and_group_lookup_vty(vty, ip_str);
5631 if (!peer)
5632 return CMD_WARNING_CONFIG_FAILED;
718e3744 5633
d62a17ae 5634 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5635
d62a17ae 5636 return bgp_vty_return(vty, ret);
718e3744 5637}
5638
5639/* Unset route-map from the peer. */
d62a17ae 5640static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5641 afi_t afi, safi_t safi)
718e3744 5642{
d62a17ae 5643 int ret;
5644 struct peer *peer;
718e3744 5645
d62a17ae 5646 peer = peer_and_group_lookup_vty(vty, ip_str);
5647 if (!peer)
5648 return CMD_WARNING_CONFIG_FAILED;
718e3744 5649
d62a17ae 5650 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5651
d62a17ae 5652 return bgp_vty_return(vty, ret);
718e3744 5653}
5654
5655DEFUN (neighbor_unsuppress_map,
5656 neighbor_unsuppress_map_cmd,
9ccf14f7 5657 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5658 NEIGHBOR_STR
5659 NEIGHBOR_ADDR_STR2
5660 "Route-map to selectively unsuppress suppressed routes\n"
5661 "Name of route map\n")
5662{
d62a17ae 5663 int idx_peer = 1;
5664 int idx_word = 3;
5665 return peer_unsuppress_map_set_vty(
5666 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5667 argv[idx_word]->arg);
718e3744 5668}
5669
d62a17ae 5670ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5671 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5672 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5673 "Route-map to selectively unsuppress suppressed routes\n"
5674 "Name of route map\n")
596c17ba 5675
718e3744 5676DEFUN (no_neighbor_unsuppress_map,
5677 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5678 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5679 NO_STR
5680 NEIGHBOR_STR
5681 NEIGHBOR_ADDR_STR2
5682 "Route-map to selectively unsuppress suppressed routes\n"
5683 "Name of route map\n")
5684{
d62a17ae 5685 int idx_peer = 2;
5686 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5687 bgp_node_afi(vty),
5688 bgp_node_safi(vty));
718e3744 5689}
6b0655a2 5690
d62a17ae 5691ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5692 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5693 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5694 "Route-map to selectively unsuppress suppressed routes\n"
5695 "Name of route map\n")
596c17ba 5696
d62a17ae 5697static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5698 afi_t afi, safi_t safi,
5699 const char *num_str,
5700 const char *threshold_str, int warning,
5701 const char *restart_str)
718e3744 5702{
d62a17ae 5703 int ret;
5704 struct peer *peer;
d7c0a89a
QY
5705 uint32_t max;
5706 uint8_t threshold;
5707 uint16_t restart;
718e3744 5708
d62a17ae 5709 peer = peer_and_group_lookup_vty(vty, ip_str);
5710 if (!peer)
5711 return CMD_WARNING_CONFIG_FAILED;
718e3744 5712
d62a17ae 5713 max = strtoul(num_str, NULL, 10);
5714 if (threshold_str)
5715 threshold = atoi(threshold_str);
5716 else
5717 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5718
d62a17ae 5719 if (restart_str)
5720 restart = atoi(restart_str);
5721 else
5722 restart = 0;
0a486e5f 5723
d62a17ae 5724 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5725 restart);
718e3744 5726
d62a17ae 5727 return bgp_vty_return(vty, ret);
718e3744 5728}
5729
d62a17ae 5730static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5731 afi_t afi, safi_t safi)
718e3744 5732{
d62a17ae 5733 int ret;
5734 struct peer *peer;
718e3744 5735
d62a17ae 5736 peer = peer_and_group_lookup_vty(vty, ip_str);
5737 if (!peer)
5738 return CMD_WARNING_CONFIG_FAILED;
718e3744 5739
d62a17ae 5740 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5741
d62a17ae 5742 return bgp_vty_return(vty, ret);
718e3744 5743}
5744
5745/* Maximum number of prefix configuration. prefix count is different
5746 for each peer configuration. So this configuration can be set for
5747 each peer configuration. */
5748DEFUN (neighbor_maximum_prefix,
5749 neighbor_maximum_prefix_cmd,
9ccf14f7 5750 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5751 NEIGHBOR_STR
5752 NEIGHBOR_ADDR_STR2
5753 "Maximum number of prefix accept from this peer\n"
5754 "maximum no. of prefix limit\n")
5755{
d62a17ae 5756 int idx_peer = 1;
5757 int idx_number = 3;
5758 return peer_maximum_prefix_set_vty(
5759 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5760 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5761}
5762
d62a17ae 5763ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5764 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5765 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5766 "Maximum number of prefix accept from this peer\n"
5767 "maximum no. of prefix limit\n")
596c17ba 5768
e0701b79 5769DEFUN (neighbor_maximum_prefix_threshold,
5770 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5771 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5772 NEIGHBOR_STR
5773 NEIGHBOR_ADDR_STR2
5774 "Maximum number of prefix accept from this peer\n"
5775 "maximum no. of prefix limit\n"
5776 "Threshold value (%) at which to generate a warning msg\n")
5777{
d62a17ae 5778 int idx_peer = 1;
5779 int idx_number = 3;
5780 int idx_number_2 = 4;
5781 return peer_maximum_prefix_set_vty(
5782 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5783 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5784}
e0701b79 5785
d62a17ae 5786ALIAS_HIDDEN(
5787 neighbor_maximum_prefix_threshold,
5788 neighbor_maximum_prefix_threshold_hidden_cmd,
5789 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5790 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5791 "Maximum number of prefix accept from this peer\n"
5792 "maximum no. of prefix limit\n"
5793 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5794
718e3744 5795DEFUN (neighbor_maximum_prefix_warning,
5796 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5797 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5798 NEIGHBOR_STR
5799 NEIGHBOR_ADDR_STR2
5800 "Maximum number of prefix accept from this peer\n"
5801 "maximum no. of prefix limit\n"
5802 "Only give warning message when limit is exceeded\n")
5803{
d62a17ae 5804 int idx_peer = 1;
5805 int idx_number = 3;
5806 return peer_maximum_prefix_set_vty(
5807 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5808 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5809}
5810
d62a17ae 5811ALIAS_HIDDEN(
5812 neighbor_maximum_prefix_warning,
5813 neighbor_maximum_prefix_warning_hidden_cmd,
5814 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5815 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5816 "Maximum number of prefix accept from this peer\n"
5817 "maximum no. of prefix limit\n"
5818 "Only give warning message when limit is exceeded\n")
596c17ba 5819
e0701b79 5820DEFUN (neighbor_maximum_prefix_threshold_warning,
5821 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5822 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5823 NEIGHBOR_STR
5824 NEIGHBOR_ADDR_STR2
5825 "Maximum number of prefix accept from this peer\n"
5826 "maximum no. of prefix limit\n"
5827 "Threshold value (%) at which to generate a warning msg\n"
5828 "Only give warning message when limit is exceeded\n")
5829{
d62a17ae 5830 int idx_peer = 1;
5831 int idx_number = 3;
5832 int idx_number_2 = 4;
5833 return peer_maximum_prefix_set_vty(
5834 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5835 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5836}
5837
d62a17ae 5838ALIAS_HIDDEN(
5839 neighbor_maximum_prefix_threshold_warning,
5840 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5841 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5842 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5843 "Maximum number of prefix accept from this peer\n"
5844 "maximum no. of prefix limit\n"
5845 "Threshold value (%) at which to generate a warning msg\n"
5846 "Only give warning message when limit is exceeded\n")
596c17ba 5847
0a486e5f 5848DEFUN (neighbor_maximum_prefix_restart,
5849 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5850 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5851 NEIGHBOR_STR
5852 NEIGHBOR_ADDR_STR2
5853 "Maximum number of prefix accept from this peer\n"
5854 "maximum no. of prefix limit\n"
5855 "Restart bgp connection after limit is exceeded\n"
efd7904e 5856 "Restart interval in minutes\n")
0a486e5f 5857{
d62a17ae 5858 int idx_peer = 1;
5859 int idx_number = 3;
5860 int idx_number_2 = 5;
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, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5864}
5865
d62a17ae 5866ALIAS_HIDDEN(
5867 neighbor_maximum_prefix_restart,
5868 neighbor_maximum_prefix_restart_hidden_cmd,
5869 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5870 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5871 "Maximum number of prefix accept from this peer\n"
5872 "maximum no. of prefix limit\n"
5873 "Restart bgp connection after limit is exceeded\n"
efd7904e 5874 "Restart interval in minutes\n")
596c17ba 5875
0a486e5f 5876DEFUN (neighbor_maximum_prefix_threshold_restart,
5877 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5878 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5879 NEIGHBOR_STR
5880 NEIGHBOR_ADDR_STR2
16cedbb0 5881 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5882 "maximum no. of prefix limit\n"
5883 "Threshold value (%) at which to generate a warning msg\n"
5884 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5885 "Restart interval in minutes\n")
0a486e5f 5886{
d62a17ae 5887 int idx_peer = 1;
5888 int idx_number = 3;
5889 int idx_number_2 = 4;
5890 int idx_number_3 = 6;
5891 return peer_maximum_prefix_set_vty(
5892 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5893 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5894 argv[idx_number_3]->arg);
5895}
5896
5897ALIAS_HIDDEN(
5898 neighbor_maximum_prefix_threshold_restart,
5899 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5900 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5901 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5902 "Maximum number of prefixes to accept from this peer\n"
5903 "maximum no. of prefix limit\n"
5904 "Threshold value (%) at which to generate a warning msg\n"
5905 "Restart bgp connection after limit is exceeded\n"
5906 "Restart interval in minutes\n")
596c17ba 5907
718e3744 5908DEFUN (no_neighbor_maximum_prefix,
5909 no_neighbor_maximum_prefix_cmd,
d04c479d 5910 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5911 NO_STR
5912 NEIGHBOR_STR
5913 NEIGHBOR_ADDR_STR2
16cedbb0 5914 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5915 "maximum no. of prefix limit\n"
5916 "Threshold value (%) at which to generate a warning msg\n"
5917 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5918 "Restart interval in minutes\n"
31500417 5919 "Only give warning message when limit is exceeded\n")
718e3744 5920{
d62a17ae 5921 int idx_peer = 2;
5922 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5923 bgp_node_afi(vty),
5924 bgp_node_safi(vty));
718e3744 5925}
e52702f2 5926
d62a17ae 5927ALIAS_HIDDEN(
5928 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5929 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5930 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5931 "Maximum number of prefixes to accept from this peer\n"
5932 "maximum no. of prefix limit\n"
5933 "Threshold value (%) at which to generate a warning msg\n"
5934 "Restart bgp connection after limit is exceeded\n"
5935 "Restart interval in minutes\n"
5936 "Only give warning message when limit is exceeded\n")
596c17ba 5937
718e3744 5938
718e3744 5939/* "neighbor allowas-in" */
5940DEFUN (neighbor_allowas_in,
5941 neighbor_allowas_in_cmd,
fd8503f5 5942 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5943 NEIGHBOR_STR
5944 NEIGHBOR_ADDR_STR2
31500417 5945 "Accept as-path with my AS present in it\n"
fd8503f5
QY
5946 "Number of occurances of AS number\n"
5947 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5948{
d62a17ae 5949 int idx_peer = 1;
5950 int idx_number_origin = 3;
5951 int ret;
5952 int origin = 0;
5953 struct peer *peer;
5954 int allow_num = 0;
5955
5956 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5957 if (!peer)
5958 return CMD_WARNING_CONFIG_FAILED;
5959
5960 if (argc <= idx_number_origin)
5961 allow_num = 3;
5962 else {
5963 if (argv[idx_number_origin]->type == WORD_TKN)
5964 origin = 1;
5965 else
5966 allow_num = atoi(argv[idx_number_origin]->arg);
5967 }
5968
5969 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5970 allow_num, origin);
5971
5972 return bgp_vty_return(vty, ret);
5973}
5974
5975ALIAS_HIDDEN(
5976 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
5977 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5978 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5979 "Accept as-path with my AS present in it\n"
5980 "Number of occurances of AS number\n"
5981 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5982
718e3744 5983DEFUN (no_neighbor_allowas_in,
5984 no_neighbor_allowas_in_cmd,
fd8503f5 5985 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5986 NO_STR
5987 NEIGHBOR_STR
5988 NEIGHBOR_ADDR_STR2
8334fd5a 5989 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
5990 "Number of occurances of AS number\n"
5991 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5992{
d62a17ae 5993 int idx_peer = 2;
5994 int ret;
5995 struct peer *peer;
718e3744 5996
d62a17ae 5997 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5998 if (!peer)
5999 return CMD_WARNING_CONFIG_FAILED;
718e3744 6000
d62a17ae 6001 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6002 bgp_node_safi(vty));
718e3744 6003
d62a17ae 6004 return bgp_vty_return(vty, ret);
718e3744 6005}
6b0655a2 6006
d62a17ae 6007ALIAS_HIDDEN(
6008 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6009 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6010 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6011 "allow local ASN appears in aspath attribute\n"
6012 "Number of occurances of AS number\n"
6013 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6014
fa411a21
NH
6015DEFUN (neighbor_ttl_security,
6016 neighbor_ttl_security_cmd,
7ebe625c 6017 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6018 NEIGHBOR_STR
7ebe625c 6019 NEIGHBOR_ADDR_STR2
16cedbb0 6020 "BGP ttl-security parameters\n"
d7fa34c1
QY
6021 "Specify the maximum number of hops to the BGP peer\n"
6022 "Number of hops to BGP peer\n")
fa411a21 6023{
d62a17ae 6024 int idx_peer = 1;
6025 int idx_number = 4;
6026 struct peer *peer;
6027 int gtsm_hops;
6028
6029 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6030 if (!peer)
6031 return CMD_WARNING_CONFIG_FAILED;
6032
6033 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6034
7ebe625c
QY
6035 /*
6036 * If 'neighbor swpX', then this is for directly connected peers,
6037 * we should not accept a ttl-security hops value greater than 1.
6038 */
6039 if (peer->conf_if && (gtsm_hops > 1)) {
6040 vty_out(vty,
6041 "%s is directly connected peer, hops cannot exceed 1\n",
6042 argv[idx_peer]->arg);
6043 return CMD_WARNING_CONFIG_FAILED;
6044 }
6045
d62a17ae 6046 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6047}
6048
6049DEFUN (no_neighbor_ttl_security,
6050 no_neighbor_ttl_security_cmd,
7ebe625c 6051 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6052 NO_STR
6053 NEIGHBOR_STR
7ebe625c 6054 NEIGHBOR_ADDR_STR2
16cedbb0 6055 "BGP ttl-security parameters\n"
3a2d747c
QY
6056 "Specify the maximum number of hops to the BGP peer\n"
6057 "Number of hops to BGP peer\n")
fa411a21 6058{
d62a17ae 6059 int idx_peer = 2;
6060 struct peer *peer;
fa411a21 6061
d62a17ae 6062 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6063 if (!peer)
6064 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6065
d62a17ae 6066 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6067}
6b0655a2 6068
adbac85e
DW
6069DEFUN (neighbor_addpath_tx_all_paths,
6070 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6071 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6072 NEIGHBOR_STR
6073 NEIGHBOR_ADDR_STR2
6074 "Use addpath to advertise all paths to a neighbor\n")
6075{
d62a17ae 6076 int idx_peer = 1;
6077 struct peer *peer;
adbac85e 6078
d62a17ae 6079 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6080 if (!peer)
6081 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6082
d62a17ae 6083 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6084 bgp_node_safi(vty),
6085 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6086}
6087
d62a17ae 6088ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6089 neighbor_addpath_tx_all_paths_hidden_cmd,
6090 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6091 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6092 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6093
adbac85e
DW
6094DEFUN (no_neighbor_addpath_tx_all_paths,
6095 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6096 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6097 NO_STR
6098 NEIGHBOR_STR
6099 NEIGHBOR_ADDR_STR2
6100 "Use addpath to advertise all paths to a neighbor\n")
6101{
d62a17ae 6102 int idx_peer = 2;
6103 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6104 bgp_node_afi(vty), bgp_node_safi(vty),
6105 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6106}
6107
d62a17ae 6108ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6109 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6110 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6111 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6112 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6113
06370dac
DW
6114DEFUN (neighbor_addpath_tx_bestpath_per_as,
6115 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6116 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6117 NEIGHBOR_STR
6118 NEIGHBOR_ADDR_STR2
6119 "Use addpath to advertise the bestpath per each neighboring AS\n")
6120{
d62a17ae 6121 int idx_peer = 1;
6122 struct peer *peer;
06370dac 6123
d62a17ae 6124 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6125 if (!peer)
6126 return CMD_WARNING_CONFIG_FAILED;
06370dac 6127
d62a17ae 6128 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6129 bgp_node_safi(vty),
6130 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6131}
6132
d62a17ae 6133ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6134 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6135 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6136 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6137 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6138
06370dac
DW
6139DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6140 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6141 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6142 NO_STR
6143 NEIGHBOR_STR
6144 NEIGHBOR_ADDR_STR2
6145 "Use addpath to advertise the bestpath per each neighboring AS\n")
6146{
d62a17ae 6147 int idx_peer = 2;
6148 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6149 bgp_node_afi(vty), bgp_node_safi(vty),
6150 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6151}
6152
d62a17ae 6153ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6154 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6155 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6156 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6157 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6158
b9c7bc5a
PZ
6159static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6160 struct ecommunity **list)
ddb5b488 6161{
b9c7bc5a
PZ
6162 struct ecommunity *ecom = NULL;
6163 struct ecommunity *ecomadd;
ddb5b488 6164
b9c7bc5a 6165 for (; argc; --argc, ++argv) {
ddb5b488 6166
b9c7bc5a
PZ
6167 ecomadd = ecommunity_str2com(argv[0]->arg,
6168 ECOMMUNITY_ROUTE_TARGET, 0);
6169 if (!ecomadd) {
6170 vty_out(vty, "Malformed community-list value\n");
6171 if (ecom)
6172 ecommunity_free(&ecom);
6173 return CMD_WARNING_CONFIG_FAILED;
6174 }
ddb5b488 6175
b9c7bc5a
PZ
6176 if (ecom) {
6177 ecommunity_merge(ecom, ecomadd);
6178 ecommunity_free(&ecomadd);
6179 } else {
6180 ecom = ecomadd;
6181 }
6182 }
6183
6184 if (*list) {
6185 ecommunity_free(&*list);
ddb5b488 6186 }
b9c7bc5a
PZ
6187 *list = ecom;
6188
6189 return CMD_SUCCESS;
ddb5b488
PZ
6190}
6191
0ca70ba5
DS
6192/*
6193 * v2vimport is true if we are handling a `import vrf ...` command
6194 */
6195static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6196{
0ca70ba5
DS
6197 afi_t afi;
6198
ddb5b488 6199 switch (vty->node) {
b9c7bc5a 6200 case BGP_IPV4_NODE:
0ca70ba5
DS
6201 afi = AFI_IP;
6202 break;
b9c7bc5a 6203 case BGP_IPV6_NODE:
0ca70ba5
DS
6204 afi = AFI_IP6;
6205 break;
ddb5b488
PZ
6206 default:
6207 vty_out(vty,
b9c7bc5a 6208 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6209 return AFI_MAX;
ddb5b488 6210 }
69b07479 6211
0ca70ba5
DS
6212 if (!v2vimport) {
6213 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6214 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6215 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6216 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6217 vty_out(vty,
6218 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6219 return AFI_MAX;
6220 }
6221 } else {
6222 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6223 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6224 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6225 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6226 vty_out(vty,
6227 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6228 return AFI_MAX;
6229 }
6230 }
6231 return afi;
ddb5b488
PZ
6232}
6233
b9c7bc5a
PZ
6234DEFPY (af_rd_vpn_export,
6235 af_rd_vpn_export_cmd,
6236 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6237 NO_STR
ddb5b488 6238 "Specify route distinguisher\n"
b9c7bc5a
PZ
6239 "Between current address-family and vpn\n"
6240 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6241 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6242{
6243 VTY_DECLVAR_CONTEXT(bgp, bgp);
6244 struct prefix_rd prd;
6245 int ret;
ddb5b488 6246 afi_t afi;
b9c7bc5a
PZ
6247 int idx = 0;
6248 int yes = 1;
ddb5b488 6249
b9c7bc5a 6250 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6251 yes = 0;
b9c7bc5a
PZ
6252
6253 if (yes) {
6254 ret = str2prefix_rd(rd_str, &prd);
6255 if (!ret) {
6256 vty_out(vty, "%% Malformed rd\n");
6257 return CMD_WARNING_CONFIG_FAILED;
6258 }
ddb5b488
PZ
6259 }
6260
0ca70ba5 6261 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6262 if (afi == AFI_MAX)
6263 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6264
69b07479
DS
6265 /*
6266 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6267 */
6268 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6269 bgp_get_default(), bgp);
ddb5b488 6270
69b07479
DS
6271 if (yes) {
6272 bgp->vpn_policy[afi].tovpn_rd = prd;
6273 SET_FLAG(bgp->vpn_policy[afi].flags,
6274 BGP_VPN_POLICY_TOVPN_RD_SET);
6275 } else {
6276 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6277 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6278 }
6279
69b07479
DS
6280 /* post-change: re-export vpn routes */
6281 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6282 bgp_get_default(), bgp);
6283
ddb5b488
PZ
6284 return CMD_SUCCESS;
6285}
6286
b9c7bc5a
PZ
6287ALIAS (af_rd_vpn_export,
6288 af_no_rd_vpn_export_cmd,
6289 "no rd vpn export",
ddb5b488 6290 NO_STR
b9c7bc5a
PZ
6291 "Specify route distinguisher\n"
6292 "Between current address-family and vpn\n"
6293 "For routes leaked from current address-family to vpn\n")
ddb5b488 6294
b9c7bc5a
PZ
6295DEFPY (af_label_vpn_export,
6296 af_label_vpn_export_cmd,
e70e9f8e 6297 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6298 NO_STR
ddb5b488 6299 "label value for VRF\n"
b9c7bc5a
PZ
6300 "Between current address-family and vpn\n"
6301 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6302 "Label Value <0-1048575>\n"
6303 "Automatically assign a label\n")
ddb5b488
PZ
6304{
6305 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6306 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6307 afi_t afi;
b9c7bc5a
PZ
6308 int idx = 0;
6309 int yes = 1;
6310
6311 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6312 yes = 0;
ddb5b488 6313
21a16cc2
PZ
6314 /* If "no ...", squash trailing parameter */
6315 if (!yes)
6316 label_auto = NULL;
6317
e70e9f8e
PZ
6318 if (yes) {
6319 if (!label_auto)
6320 label = label_val; /* parser should force unsigned */
6321 }
ddb5b488 6322
0ca70ba5 6323 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6324 if (afi == AFI_MAX)
6325 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6326
e70e9f8e 6327
69b07479
DS
6328 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6329 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6330 /* no change */
6331 return CMD_SUCCESS;
e70e9f8e 6332
69b07479
DS
6333 /*
6334 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6335 */
6336 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6337 bgp_get_default(), bgp);
6338
6339 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6340 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6341
6342 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6343
6344 /*
6345 * label has previously been automatically
6346 * assigned by labelpool: release it
6347 *
6348 * NB if tovpn_label == MPLS_LABEL_NONE it
6349 * means the automatic assignment is in flight
6350 * and therefore the labelpool callback must
6351 * detect that the auto label is not needed.
6352 */
6353
6354 bgp_lp_release(LP_TYPE_VRF,
6355 &bgp->vpn_policy[afi],
6356 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6357 }
69b07479
DS
6358 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6359 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6360 }
ddb5b488 6361
69b07479
DS
6362 bgp->vpn_policy[afi].tovpn_label = label;
6363 if (label_auto) {
6364 SET_FLAG(bgp->vpn_policy[afi].flags,
6365 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6366 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6367 vpn_leak_label_callback);
ddb5b488
PZ
6368 }
6369
69b07479
DS
6370 /* post-change: re-export vpn routes */
6371 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6372 bgp_get_default(), bgp);
6373
ddb5b488
PZ
6374 return CMD_SUCCESS;
6375}
6376
b9c7bc5a
PZ
6377ALIAS (af_label_vpn_export,
6378 af_no_label_vpn_export_cmd,
6379 "no label vpn export",
6380 NO_STR
6381 "label value for VRF\n"
6382 "Between current address-family and vpn\n"
6383 "For routes leaked from current address-family to vpn\n")
ddb5b488 6384
b9c7bc5a
PZ
6385DEFPY (af_nexthop_vpn_export,
6386 af_nexthop_vpn_export_cmd,
6387 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6388 NO_STR
ddb5b488 6389 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6390 "Between current address-family and vpn\n"
6391 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6392 "IPv4 prefix\n"
6393 "IPv6 prefix\n")
6394{
6395 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6396 afi_t afi;
ddb5b488 6397 struct prefix p;
b9c7bc5a
PZ
6398 int idx = 0;
6399 int yes = 1;
ddb5b488 6400
b9c7bc5a 6401 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6402 yes = 0;
b9c7bc5a
PZ
6403
6404 if (yes) {
6405 if (!sockunion2hostprefix(nexthop_str, &p))
6406 return CMD_WARNING_CONFIG_FAILED;
6407 }
ddb5b488 6408
0ca70ba5 6409 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6410 if (afi == AFI_MAX)
6411 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6412
69b07479
DS
6413 /*
6414 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6415 */
6416 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6417 bgp_get_default(), bgp);
ddb5b488 6418
69b07479
DS
6419 if (yes) {
6420 bgp->vpn_policy[afi].tovpn_nexthop = p;
6421 SET_FLAG(bgp->vpn_policy[afi].flags,
6422 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6423 } else {
6424 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6425 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6426 }
6427
69b07479
DS
6428 /* post-change: re-export vpn routes */
6429 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6430 bgp_get_default(), bgp);
6431
ddb5b488
PZ
6432 return CMD_SUCCESS;
6433}
6434
b9c7bc5a
PZ
6435ALIAS (af_nexthop_vpn_export,
6436 af_no_nexthop_vpn_export_cmd,
6437 "no nexthop vpn export",
ddb5b488 6438 NO_STR
b9c7bc5a
PZ
6439 "Specify next hop to use for VRF advertised prefixes\n"
6440 "Between current address-family and vpn\n"
6441 "For routes leaked from current address-family to vpn\n")
ddb5b488 6442
b9c7bc5a 6443static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6444{
b9c7bc5a
PZ
6445 if (!strcmp(dstr, "import")) {
6446 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6447 } else if (!strcmp(dstr, "export")) {
6448 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6449 } else if (!strcmp(dstr, "both")) {
6450 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6451 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6452 } else {
6453 vty_out(vty, "%% direction parse error\n");
6454 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6455 }
ddb5b488
PZ
6456 return CMD_SUCCESS;
6457}
6458
b9c7bc5a
PZ
6459DEFPY (af_rt_vpn_imexport,
6460 af_rt_vpn_imexport_cmd,
6461 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6462 NO_STR
6463 "Specify route target list\n"
ddb5b488 6464 "Specify route target list\n"
b9c7bc5a
PZ
6465 "Between current address-family and vpn\n"
6466 "For routes leaked from vpn to current address-family: match any\n"
6467 "For routes leaked from current address-family to vpn: set\n"
6468 "both import: match any and export: set\n"
ddb5b488
PZ
6469 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6470{
6471 VTY_DECLVAR_CONTEXT(bgp, bgp);
6472 int ret;
6473 struct ecommunity *ecom = NULL;
6474 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6475 vpn_policy_direction_t dir;
6476 afi_t afi;
6477 int idx = 0;
b9c7bc5a 6478 int yes = 1;
ddb5b488 6479
b9c7bc5a 6480 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6481 yes = 0;
b9c7bc5a 6482
0ca70ba5 6483 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6484 if (afi == AFI_MAX)
6485 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6486
b9c7bc5a 6487 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6488 if (ret != CMD_SUCCESS)
6489 return ret;
6490
b9c7bc5a
PZ
6491 if (yes) {
6492 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6493 vty_out(vty, "%% Missing RTLIST\n");
6494 return CMD_WARNING_CONFIG_FAILED;
6495 }
6496 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6497 if (ret != CMD_SUCCESS) {
6498 return ret;
6499 }
ddb5b488
PZ
6500 }
6501
69b07479
DS
6502 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6503 if (!dodir[dir])
ddb5b488 6504 continue;
ddb5b488 6505
69b07479 6506 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6507
69b07479
DS
6508 if (yes) {
6509 if (bgp->vpn_policy[afi].rtlist[dir])
6510 ecommunity_free(
6511 &bgp->vpn_policy[afi].rtlist[dir]);
6512 bgp->vpn_policy[afi].rtlist[dir] =
6513 ecommunity_dup(ecom);
6514 } else {
6515 if (bgp->vpn_policy[afi].rtlist[dir])
6516 ecommunity_free(
6517 &bgp->vpn_policy[afi].rtlist[dir]);
6518 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6519 }
69b07479
DS
6520
6521 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6522 }
69b07479 6523
d555f3e9
PZ
6524 if (ecom)
6525 ecommunity_free(&ecom);
ddb5b488
PZ
6526
6527 return CMD_SUCCESS;
6528}
6529
b9c7bc5a
PZ
6530ALIAS (af_rt_vpn_imexport,
6531 af_no_rt_vpn_imexport_cmd,
6532 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6533 NO_STR
6534 "Specify route target list\n"
b9c7bc5a
PZ
6535 "Specify route target list\n"
6536 "Between current address-family and vpn\n"
6537 "For routes leaked from vpn to current address-family\n"
6538 "For routes leaked from current address-family to vpn\n"
6539 "both import and export\n")
6540
6541DEFPY (af_route_map_vpn_imexport,
6542 af_route_map_vpn_imexport_cmd,
6543/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6544 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6545 NO_STR
ddb5b488 6546 "Specify route map\n"
b9c7bc5a
PZ
6547 "Between current address-family and vpn\n"
6548 "For routes leaked from vpn to current address-family\n"
6549 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6550 "name of route-map\n")
6551{
6552 VTY_DECLVAR_CONTEXT(bgp, bgp);
6553 int ret;
6554 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6555 vpn_policy_direction_t dir;
6556 afi_t afi;
ddb5b488 6557 int idx = 0;
b9c7bc5a 6558 int yes = 1;
ddb5b488 6559
b9c7bc5a 6560 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6561 yes = 0;
b9c7bc5a 6562
0ca70ba5 6563 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6564 if (afi == AFI_MAX)
6565 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6566
b9c7bc5a 6567 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6568 if (ret != CMD_SUCCESS)
6569 return ret;
6570
69b07479
DS
6571 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6572 if (!dodir[dir])
ddb5b488 6573 continue;
ddb5b488 6574
69b07479 6575 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6576
69b07479
DS
6577 if (yes) {
6578 if (bgp->vpn_policy[afi].rmap_name[dir])
6579 XFREE(MTYPE_ROUTE_MAP_NAME,
6580 bgp->vpn_policy[afi].rmap_name[dir]);
6581 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6582 MTYPE_ROUTE_MAP_NAME, rmap_str);
6583 bgp->vpn_policy[afi].rmap[dir] =
6584 route_map_lookup_by_name(rmap_str);
6585 if (!bgp->vpn_policy[afi].rmap[dir])
6586 return CMD_SUCCESS;
6587 } else {
6588 if (bgp->vpn_policy[afi].rmap_name[dir])
6589 XFREE(MTYPE_ROUTE_MAP_NAME,
6590 bgp->vpn_policy[afi].rmap_name[dir]);
6591 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6592 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6593 }
69b07479
DS
6594
6595 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6596 }
6597
6598 return CMD_SUCCESS;
6599}
6600
b9c7bc5a
PZ
6601ALIAS (af_route_map_vpn_imexport,
6602 af_no_route_map_vpn_imexport_cmd,
6603 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6604 NO_STR
6605 "Specify route map\n"
b9c7bc5a
PZ
6606 "Between current address-family and vpn\n"
6607 "For routes leaked from vpn to current address-family\n"
6608 "For routes leaked from current address-family to vpn\n")
6609
bb4f6190
DS
6610DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6611 "[no] import vrf route-map RMAP$rmap_str",
6612 NO_STR
6613 "Import routes from another VRF\n"
6614 "Vrf routes being filtered\n"
6615 "Specify route map\n"
6616 "name of route-map\n")
6617{
6618 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6619 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6620 afi_t afi;
6621 int idx = 0;
6622 int yes = 1;
6623 struct bgp *bgp_default;
6624
6625 if (argv_find(argv, argc, "no", &idx))
6626 yes = 0;
6627
0ca70ba5 6628 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6629 if (afi == AFI_MAX)
6630 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6631
6632 bgp_default = bgp_get_default();
6633 if (!bgp_default) {
6634 int32_t ret;
6635 as_t as = bgp->as;
6636
6637 /* Auto-create assuming the same AS */
6638 ret = bgp_get(&bgp_default, &as, NULL,
6639 BGP_INSTANCE_TYPE_DEFAULT);
6640
6641 if (ret) {
6642 vty_out(vty,
6643 "VRF default is not configured as a bgp instance\n");
6644 return CMD_WARNING;
6645 }
6646 }
6647
69b07479 6648 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6649
69b07479
DS
6650 if (yes) {
6651 if (bgp->vpn_policy[afi].rmap_name[dir])
6652 XFREE(MTYPE_ROUTE_MAP_NAME,
6653 bgp->vpn_policy[afi].rmap_name[dir]);
6654 bgp->vpn_policy[afi].rmap_name[dir] =
6655 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6656 bgp->vpn_policy[afi].rmap[dir] =
6657 route_map_lookup_by_name(rmap_str);
6658 if (!bgp->vpn_policy[afi].rmap[dir])
6659 return CMD_SUCCESS;
6660 } else {
6661 if (bgp->vpn_policy[afi].rmap_name[dir])
6662 XFREE(MTYPE_ROUTE_MAP_NAME,
6663 bgp->vpn_policy[afi].rmap_name[dir]);
6664 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6665 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6666 }
6667
69b07479
DS
6668 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6669
bb4f6190
DS
6670 return CMD_SUCCESS;
6671}
6672
6673ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6674 "no import vrf route-map",
6675 NO_STR
6676 "Import routes from another VRF\n"
6677 "Vrf routes being filtered\n"
6678 "Specify route map\n")
6679
12a844a5
DS
6680DEFPY (bgp_imexport_vrf,
6681 bgp_imexport_vrf_cmd,
6682 "[no] import vrf NAME$import_name",
6683 NO_STR
6684 "Import routes from another VRF\n"
6685 "VRF to import from\n"
6686 "The name of the VRF\n")
6687{
6688 VTY_DECLVAR_CONTEXT(bgp, bgp);
6689 struct listnode *node;
79ef8664
DS
6690 struct bgp *vrf_bgp, *bgp_default;
6691 int32_t ret = 0;
6692 as_t as = bgp->as;
12a844a5
DS
6693 bool remove = false;
6694 int32_t idx = 0;
6695 char *vname;
a8dadcf6 6696 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6697 safi_t safi;
6698 afi_t afi;
6699
6700 if (argv_find(argv, argc, "no", &idx))
6701 remove = true;
6702
0ca70ba5
DS
6703 afi = vpn_policy_getafi(vty, bgp, true);
6704 if (afi == AFI_MAX)
6705 return CMD_WARNING_CONFIG_FAILED;
6706
12a844a5
DS
6707 safi = bgp_node_safi(vty);
6708
25679caa
DS
6709 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6710 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6711 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6712 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6713 remove ? "unimport" : "import", import_name);
6714 return CMD_WARNING;
6715 }
6716
79ef8664
DS
6717 bgp_default = bgp_get_default();
6718 if (!bgp_default) {
6719 /* Auto-create assuming the same AS */
6720 ret = bgp_get(&bgp_default, &as, NULL,
6721 BGP_INSTANCE_TYPE_DEFAULT);
6722
6723 if (ret) {
6724 vty_out(vty,
6725 "VRF default is not configured as a bgp instance\n");
6726 return CMD_WARNING;
6727 }
6728 }
6729
12a844a5
DS
6730 vrf_bgp = bgp_lookup_by_name(import_name);
6731 if (!vrf_bgp) {
79ef8664
DS
6732 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6733 vrf_bgp = bgp_default;
6734 else
0fb8d6e6
DS
6735 /* Auto-create assuming the same AS */
6736 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6737
6e2c7fe6 6738 if (ret) {
020a3f60
DS
6739 vty_out(vty,
6740 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6741 import_name);
6742 return CMD_WARNING;
6743 }
12a844a5
DS
6744 }
6745
12a844a5 6746 if (remove) {
44338987 6747 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6748 } else {
44338987 6749 /* Already importing from "import_vrf"? */
12a844a5
DS
6750 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6751 vname)) {
6752 if (strcmp(vname, import_name) == 0)
6753 return CMD_WARNING;
6754 }
6755
44338987 6756 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6757 }
6758
6759 return CMD_SUCCESS;
6760}
6761
b9c7bc5a
PZ
6762/* This command is valid only in a bgp vrf instance or the default instance */
6763DEFPY (bgp_imexport_vpn,
6764 bgp_imexport_vpn_cmd,
6765 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6766 NO_STR
6767 "Import routes to this address-family\n"
6768 "Export routes from this address-family\n"
6769 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6770{
6771 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6772 int previous_state;
ddb5b488 6773 afi_t afi;
b9c7bc5a 6774 safi_t safi;
ddb5b488 6775 int idx = 0;
b9c7bc5a
PZ
6776 int yes = 1;
6777 int flag;
6778 vpn_policy_direction_t dir;
ddb5b488 6779
b9c7bc5a 6780 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6781 yes = 0;
ddb5b488 6782
b9c7bc5a
PZ
6783 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6784 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6785
b9c7bc5a
PZ
6786 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6787 return CMD_WARNING_CONFIG_FAILED;
6788 }
ddb5b488 6789
b9c7bc5a
PZ
6790 afi = bgp_node_afi(vty);
6791 safi = bgp_node_safi(vty);
6792 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6793 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6794 return CMD_WARNING_CONFIG_FAILED;
6795 }
ddb5b488 6796
b9c7bc5a
PZ
6797 if (!strcmp(direction_str, "import")) {
6798 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6799 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6800 } else if (!strcmp(direction_str, "export")) {
6801 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6802 dir = BGP_VPN_POLICY_DIR_TOVPN;
6803 } else {
6804 vty_out(vty, "%% unknown direction %s\n", direction_str);
6805 return CMD_WARNING_CONFIG_FAILED;
6806 }
6807
6808 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 6809
b9c7bc5a
PZ
6810 if (yes) {
6811 SET_FLAG(bgp->af_flags[afi][safi], flag);
6812 if (!previous_state) {
6813 /* trigger export current vrf */
ddb5b488
PZ
6814 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6815 }
b9c7bc5a
PZ
6816 } else {
6817 if (previous_state) {
6818 /* trigger un-export current vrf */
6819 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6820 }
6821 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
6822 }
6823
6824 return CMD_SUCCESS;
6825}
6826
301ad80a
PG
6827DEFPY (af_routetarget_import,
6828 af_routetarget_import_cmd,
6829 "[no] <rt|route-target> redirect import RTLIST...",
6830 NO_STR
6831 "Specify route target list\n"
6832 "Specify route target list\n"
6833 "Flow-spec redirect type route target\n"
6834 "Import routes to this address-family\n"
6835 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6836{
6837 VTY_DECLVAR_CONTEXT(bgp, bgp);
6838 int ret;
6839 struct ecommunity *ecom = NULL;
301ad80a
PG
6840 afi_t afi;
6841 int idx = 0;
6842 int yes = 1;
6843
6844 if (argv_find(argv, argc, "no", &idx))
6845 yes = 0;
6846
0ca70ba5 6847 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6848 if (afi == AFI_MAX)
6849 return CMD_WARNING_CONFIG_FAILED;
6850
301ad80a
PG
6851 if (yes) {
6852 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6853 vty_out(vty, "%% Missing RTLIST\n");
6854 return CMD_WARNING_CONFIG_FAILED;
6855 }
6856 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6857 if (ret != CMD_SUCCESS)
6858 return ret;
6859 }
69b07479
DS
6860
6861 if (yes) {
6862 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6863 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6864 .import_redirect_rtlist);
69b07479
DS
6865 bgp->vpn_policy[afi].import_redirect_rtlist =
6866 ecommunity_dup(ecom);
6867 } else {
6868 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6869 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6870 .import_redirect_rtlist);
69b07479 6871 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 6872 }
69b07479 6873
301ad80a
PG
6874 if (ecom)
6875 ecommunity_free(&ecom);
6876
6877 return CMD_SUCCESS;
6878}
6879
505e5056 6880DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 6881 address_family_ipv4_safi_cmd,
6882 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6883 "Enter Address Family command mode\n"
6884 "Address Family\n"
6885 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6886{
f51bae9c 6887
d62a17ae 6888 if (argc == 3) {
2131d5cf 6889 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6890 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6891 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6892 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6893 && safi != SAFI_EVPN) {
31947174
MK
6894 vty_out(vty,
6895 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6896 return CMD_WARNING_CONFIG_FAILED;
6897 }
d62a17ae 6898 vty->node = bgp_node_type(AFI_IP, safi);
6899 } else
6900 vty->node = BGP_IPV4_NODE;
718e3744 6901
d62a17ae 6902 return CMD_SUCCESS;
718e3744 6903}
6904
505e5056 6905DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 6906 address_family_ipv6_safi_cmd,
6907 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6908 "Enter Address Family command mode\n"
6909 "Address Family\n"
6910 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6911{
d62a17ae 6912 if (argc == 3) {
2131d5cf 6913 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6914 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6915 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6916 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6917 && safi != SAFI_EVPN) {
31947174
MK
6918 vty_out(vty,
6919 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6920 return CMD_WARNING_CONFIG_FAILED;
6921 }
d62a17ae 6922 vty->node = bgp_node_type(AFI_IP6, safi);
6923 } else
6924 vty->node = BGP_IPV6_NODE;
25ffbdc1 6925
d62a17ae 6926 return CMD_SUCCESS;
25ffbdc1 6927}
718e3744 6928
d6902373 6929#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6930DEFUN_NOSH (address_family_vpnv4,
718e3744 6931 address_family_vpnv4_cmd,
8334fd5a 6932 "address-family vpnv4 [unicast]",
718e3744 6933 "Enter Address Family command mode\n"
8c3deaae 6934 "Address Family\n"
3a2d747c 6935 "Address Family modifier\n")
718e3744 6936{
d62a17ae 6937 vty->node = BGP_VPNV4_NODE;
6938 return CMD_SUCCESS;
718e3744 6939}
6940
505e5056 6941DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6942 address_family_vpnv6_cmd,
8334fd5a 6943 "address-family vpnv6 [unicast]",
8ecd3266 6944 "Enter Address Family command mode\n"
8c3deaae 6945 "Address Family\n"
3a2d747c 6946 "Address Family modifier\n")
8ecd3266 6947{
d62a17ae 6948 vty->node = BGP_VPNV6_NODE;
6949 return CMD_SUCCESS;
8ecd3266 6950}
c016b6c7 6951#endif
d6902373 6952
505e5056 6953DEFUN_NOSH (address_family_evpn,
4e0b7b6d 6954 address_family_evpn_cmd,
7111c1a0 6955 "address-family l2vpn evpn",
4e0b7b6d 6956 "Enter Address Family command mode\n"
7111c1a0
QY
6957 "Address Family\n"
6958 "Address Family modifier\n")
4e0b7b6d 6959{
2131d5cf 6960 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6961 vty->node = BGP_EVPN_NODE;
6962 return CMD_SUCCESS;
4e0b7b6d
PG
6963}
6964
505e5056 6965DEFUN_NOSH (exit_address_family,
718e3744 6966 exit_address_family_cmd,
6967 "exit-address-family",
6968 "Exit from Address Family configuration mode\n")
6969{
d62a17ae 6970 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
6971 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
6972 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
6973 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
6974 || vty->node == BGP_EVPN_NODE
6975 || vty->node == BGP_FLOWSPECV4_NODE
6976 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 6977 vty->node = BGP_NODE;
6978 return CMD_SUCCESS;
718e3744 6979}
6b0655a2 6980
8ad7271d 6981/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 6982static int bgp_clear_prefix(struct vty *vty, const char *view_name,
6983 const char *ip_str, afi_t afi, safi_t safi,
6984 struct prefix_rd *prd)
6985{
6986 int ret;
6987 struct prefix match;
6988 struct bgp_node *rn;
6989 struct bgp_node *rm;
6990 struct bgp *bgp;
6991 struct bgp_table *table;
6992 struct bgp_table *rib;
6993
6994 /* BGP structure lookup. */
6995 if (view_name) {
6996 bgp = bgp_lookup_by_name(view_name);
6997 if (bgp == NULL) {
6998 vty_out(vty, "%% Can't find BGP instance %s\n",
6999 view_name);
7000 return CMD_WARNING;
7001 }
7002 } else {
7003 bgp = bgp_get_default();
7004 if (bgp == NULL) {
7005 vty_out(vty, "%% No BGP process is configured\n");
7006 return CMD_WARNING;
7007 }
7008 }
7009
7010 /* Check IP address argument. */
7011 ret = str2prefix(ip_str, &match);
7012 if (!ret) {
7013 vty_out(vty, "%% address is malformed\n");
7014 return CMD_WARNING;
7015 }
7016
7017 match.family = afi2family(afi);
7018 rib = bgp->rib[afi][safi];
7019
7020 if (safi == SAFI_MPLS_VPN) {
7021 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7022 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7023 continue;
7024
7025 if ((table = rn->info) != NULL) {
7026 if ((rm = bgp_node_match(table, &match))
7027 != NULL) {
7028 if (rm->p.prefixlen
7029 == match.prefixlen) {
7030 SET_FLAG(rn->flags,
7031 BGP_NODE_USER_CLEAR);
7032 bgp_process(bgp, rm, afi, safi);
7033 }
7034 bgp_unlock_node(rm);
7035 }
7036 }
7037 }
7038 } else {
7039 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7040 if (rn->p.prefixlen == match.prefixlen) {
7041 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7042 bgp_process(bgp, rn, afi, safi);
7043 }
7044 bgp_unlock_node(rn);
7045 }
7046 }
7047
7048 return CMD_SUCCESS;
8ad7271d
DS
7049}
7050
b09b5ae0 7051/* one clear bgp command to rule them all */
718e3744 7052DEFUN (clear_ip_bgp_all,
7053 clear_ip_bgp_all_cmd,
c1a44e43 7054 "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 7055 CLEAR_STR
7056 IP_STR
7057 BGP_STR
838758ac 7058 BGP_INSTANCE_HELP_STR
510afcd6
DS
7059 BGP_AFI_HELP_STR
7060 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
7061 "Clear all peers\n"
7062 "BGP neighbor address to clear\n"
a80beece 7063 "BGP IPv6 neighbor to clear\n"
838758ac 7064 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7065 "Clear peers with the AS number\n"
7066 "Clear all external peers\n"
718e3744 7067 "Clear all members of peer-group\n"
b09b5ae0 7068 "BGP peer-group name\n"
b09b5ae0
DW
7069 BGP_SOFT_STR
7070 BGP_SOFT_IN_STR
b09b5ae0
DW
7071 BGP_SOFT_OUT_STR
7072 BGP_SOFT_IN_STR
7073 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7074 BGP_SOFT_OUT_STR)
718e3744 7075{
d62a17ae 7076 char *vrf = NULL;
7077
7078 afi_t afi = AFI_IP6;
7079 safi_t safi = SAFI_UNICAST;
7080 enum clear_sort clr_sort = clear_peer;
7081 enum bgp_clear_type clr_type;
7082 char *clr_arg = NULL;
7083
7084 int idx = 0;
7085
7086 /* clear [ip] bgp */
7087 if (argv_find(argv, argc, "ip", &idx))
7088 afi = AFI_IP;
7089
7090 /* [<view|vrf> VIEWVRFNAME] */
7091 if (argv_find(argv, argc, "view", &idx)
7092 || argv_find(argv, argc, "vrf", &idx)) {
7093 vrf = argv[idx + 1]->arg;
7094 idx += 2;
7095 }
7096
7097 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7098 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7099 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7100
7101 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7102 if (argv_find(argv, argc, "*", &idx)) {
7103 clr_sort = clear_all;
7104 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7105 clr_sort = clear_peer;
7106 clr_arg = argv[idx]->arg;
7107 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7108 clr_sort = clear_peer;
7109 clr_arg = argv[idx]->arg;
7110 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7111 clr_sort = clear_group;
7112 idx++;
7113 clr_arg = argv[idx]->arg;
7114 } else if (argv_find(argv, argc, "WORD", &idx)) {
7115 clr_sort = clear_peer;
7116 clr_arg = argv[idx]->arg;
7117 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7118 clr_sort = clear_as;
7119 clr_arg = argv[idx]->arg;
7120 } else if (argv_find(argv, argc, "external", &idx)) {
7121 clr_sort = clear_external;
7122 }
7123
7124 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7125 if (argv_find(argv, argc, "soft", &idx)) {
7126 if (argv_find(argv, argc, "in", &idx)
7127 || argv_find(argv, argc, "out", &idx))
7128 clr_type = strmatch(argv[idx]->text, "in")
7129 ? BGP_CLEAR_SOFT_IN
7130 : BGP_CLEAR_SOFT_OUT;
7131 else
7132 clr_type = BGP_CLEAR_SOFT_BOTH;
7133 } else if (argv_find(argv, argc, "in", &idx)) {
7134 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7135 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7136 : BGP_CLEAR_SOFT_IN;
7137 } else if (argv_find(argv, argc, "out", &idx)) {
7138 clr_type = BGP_CLEAR_SOFT_OUT;
7139 } else
7140 clr_type = BGP_CLEAR_SOFT_NONE;
7141
7142 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7143}
01080f7c 7144
8ad7271d
DS
7145DEFUN (clear_ip_bgp_prefix,
7146 clear_ip_bgp_prefix_cmd,
18c57037 7147 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7148 CLEAR_STR
7149 IP_STR
7150 BGP_STR
838758ac 7151 BGP_INSTANCE_HELP_STR
8ad7271d 7152 "Clear bestpath and re-advertise\n"
0c7b1b01 7153 "IPv4 prefix\n")
8ad7271d 7154{
d62a17ae 7155 char *vrf = NULL;
7156 char *prefix = NULL;
8ad7271d 7157
d62a17ae 7158 int idx = 0;
01080f7c 7159
d62a17ae 7160 /* [<view|vrf> VIEWVRFNAME] */
1d35f218 7161 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
d62a17ae 7162 vrf = argv[idx]->arg;
0c7b1b01 7163
d62a17ae 7164 prefix = argv[argc - 1]->arg;
8ad7271d 7165
d62a17ae 7166 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7167}
8ad7271d 7168
b09b5ae0
DW
7169DEFUN (clear_bgp_ipv6_safi_prefix,
7170 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7171 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7172 CLEAR_STR
3a2d747c 7173 IP_STR
718e3744 7174 BGP_STR
8c3deaae 7175 "Address Family\n"
46f296b4 7176 BGP_SAFI_HELP_STR
b09b5ae0 7177 "Clear bestpath and re-advertise\n"
0c7b1b01 7178 "IPv6 prefix\n")
718e3744 7179{
9b475e76
PG
7180 int idx_safi = 0;
7181 int idx_ipv6_prefix = 0;
7182 safi_t safi = SAFI_UNICAST;
7183 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7184 argv[idx_ipv6_prefix]->arg : NULL;
7185
7186 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7187 return bgp_clear_prefix(
9b475e76
PG
7188 vty, NULL, prefix, AFI_IP6,
7189 safi, NULL);
838758ac 7190}
01080f7c 7191
b09b5ae0
DW
7192DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7193 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7194 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7195 CLEAR_STR
3a2d747c 7196 IP_STR
718e3744 7197 BGP_STR
838758ac 7198 BGP_INSTANCE_HELP_STR
8c3deaae 7199 "Address Family\n"
46f296b4 7200 BGP_SAFI_HELP_STR
b09b5ae0 7201 "Clear bestpath and re-advertise\n"
0c7b1b01 7202 "IPv6 prefix\n")
718e3744 7203{
d62a17ae 7204 int idx_word = 3;
9b475e76
PG
7205 int idx_safi = 0;
7206 int idx_ipv6_prefix = 0;
7207 safi_t safi = SAFI_UNICAST;
7208 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7209 argv[idx_ipv6_prefix]->arg : NULL;
7210 /* [<view|vrf> VIEWVRFNAME] */
7211 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7212 argv[idx_word]->arg : NULL;
7213
7214 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7215
d62a17ae 7216 return bgp_clear_prefix(
9b475e76
PG
7217 vty, vrfview, prefix,
7218 AFI_IP6, safi, NULL);
718e3744 7219}
7220
b09b5ae0
DW
7221DEFUN (show_bgp_views,
7222 show_bgp_views_cmd,
d6e3c605 7223 "show [ip] bgp views",
b09b5ae0 7224 SHOW_STR
d6e3c605 7225 IP_STR
01080f7c 7226 BGP_STR
b09b5ae0 7227 "Show the defined BGP views\n")
01080f7c 7228{
d62a17ae 7229 struct list *inst = bm->bgp;
7230 struct listnode *node;
7231 struct bgp *bgp;
01080f7c 7232
d62a17ae 7233 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7234 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7235 return CMD_WARNING;
7236 }
e52702f2 7237
d62a17ae 7238 vty_out(vty, "Defined BGP views:\n");
7239 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7240 /* Skip VRFs. */
7241 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7242 continue;
7243 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7244 bgp->as);
7245 }
e52702f2 7246
d62a17ae 7247 return CMD_SUCCESS;
e0081f70
ML
7248}
7249
8386ac43 7250DEFUN (show_bgp_vrfs,
7251 show_bgp_vrfs_cmd,
d6e3c605 7252 "show [ip] bgp vrfs [json]",
8386ac43 7253 SHOW_STR
d6e3c605 7254 IP_STR
8386ac43 7255 BGP_STR
7256 "Show BGP VRFs\n"
9973d184 7257 JSON_STR)
8386ac43 7258{
fe1dc5a3 7259 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7260 struct list *inst = bm->bgp;
7261 struct listnode *node;
7262 struct bgp *bgp;
d7c0a89a 7263 uint8_t uj = use_json(argc, argv);
d62a17ae 7264 json_object *json = NULL;
7265 json_object *json_vrfs = NULL;
7266 int count = 0;
d62a17ae 7267
7268 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7269 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7270 return CMD_WARNING;
7271 }
7272
7273 if (uj) {
7274 json = json_object_new_object();
7275 json_vrfs = json_object_new_object();
7276 }
7277
7278 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7279 const char *name, *type;
7280 struct peer *peer;
7281 struct listnode *node, *nnode;
7282 int peers_cfg, peers_estb;
7283 json_object *json_vrf = NULL;
d62a17ae 7284
7285 /* Skip Views. */
7286 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7287 continue;
7288
7289 count++;
7290 if (!uj && count == 1)
fe1dc5a3
MK
7291 vty_out(vty,
7292 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7293 "Type", "Id", "routerId", "#PeersVfg",
7294 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7295
7296 peers_cfg = peers_estb = 0;
7297 if (uj)
7298 json_vrf = json_object_new_object();
7299
7300
7301 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7302 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7303 continue;
7304 peers_cfg++;
7305 if (peer->status == Established)
7306 peers_estb++;
7307 }
7308
7309 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7310 name = "Default";
7311 type = "DFLT";
7312 } else {
7313 name = bgp->name;
7314 type = "VRF";
7315 }
7316
a8bf7d9c 7317
d62a17ae 7318 if (uj) {
a4d82a8a
PZ
7319 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7320 ? -1
7321 : (int64_t)bgp->vrf_id;
d62a17ae 7322 json_object_string_add(json_vrf, "type", type);
7323 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7324 json_object_string_add(json_vrf, "routerId",
7325 inet_ntoa(bgp->router_id));
7326 json_object_int_add(json_vrf, "numConfiguredPeers",
7327 peers_cfg);
7328 json_object_int_add(json_vrf, "numEstablishedPeers",
7329 peers_estb);
7330
fe1dc5a3 7331 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7332 json_object_string_add(
7333 json_vrf, "rmac",
7334 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7335 json_object_object_add(json_vrfs, name, json_vrf);
7336 } else
fe1dc5a3
MK
7337 vty_out(vty,
7338 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7339 type,
7340 bgp->vrf_id == VRF_UNKNOWN ? -1
7341 : (int)bgp->vrf_id,
7342 inet_ntoa(bgp->router_id), peers_cfg,
7343 peers_estb, name, bgp->l3vni,
fe1dc5a3 7344 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7345 }
7346
7347 if (uj) {
7348 json_object_object_add(json, "vrfs", json_vrfs);
7349
7350 json_object_int_add(json, "totalVrfs", count);
7351
996c9314
LB
7352 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7353 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7354 json_object_free(json);
7355 } else {
7356 if (count)
7357 vty_out(vty,
7358 "\nTotal number of VRFs (including default): %d\n",
7359 count);
7360 }
7361
7362 return CMD_SUCCESS;
8386ac43 7363}
7364
acf71666
MK
7365static void show_address_entry(struct hash_backet *backet, void *args)
7366{
60466a63
QY
7367 struct vty *vty = (struct vty *)args;
7368 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 7369
60466a63 7370 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
7371 addr->refcnt);
7372}
7373
7374static void show_tip_entry(struct hash_backet *backet, void *args)
7375{
0291c246 7376 struct vty *vty = (struct vty *)args;
60466a63 7377 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7378
60466a63 7379 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7380 tip->refcnt);
7381}
7382
7383static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7384{
7385 vty_out(vty, "self nexthop database:\n");
7386 hash_iterate(bgp->address_hash,
7387 (void (*)(struct hash_backet *, void *))show_address_entry,
7388 vty);
7389
7390 vty_out(vty, "Tunnel-ip database:\n");
7391 hash_iterate(bgp->tip_hash,
7392 (void (*)(struct hash_backet *, void *))show_tip_entry,
7393 vty);
7394}
7395
15c81ca4
DS
7396DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7397 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7398 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7399 "martian next-hops\n"
7400 "martian next-hop database\n")
acf71666 7401{
0291c246 7402 struct bgp *bgp = NULL;
15c81ca4
DS
7403 int idx = 0;
7404
7405 if (argv_find(argv, argc, "view", &idx)
7406 || argv_find(argv, argc, "vrf", &idx))
7407 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7408 else
7409 bgp = bgp_get_default();
acf71666 7410
acf71666
MK
7411 if (!bgp) {
7412 vty_out(vty, "%% No BGP process is configured\n");
7413 return CMD_WARNING;
7414 }
7415 bgp_show_martian_nexthops(vty, bgp);
7416
7417 return CMD_SUCCESS;
7418}
7419
f412b39a 7420DEFUN (show_bgp_memory,
4bf6a362 7421 show_bgp_memory_cmd,
7fa12b13 7422 "show [ip] bgp memory",
4bf6a362 7423 SHOW_STR
3a2d747c 7424 IP_STR
4bf6a362
PJ
7425 BGP_STR
7426 "Global BGP memory statistics\n")
7427{
d62a17ae 7428 char memstrbuf[MTYPE_MEMSTR_LEN];
7429 unsigned long count;
7430
7431 /* RIB related usage stats */
7432 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7433 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7434 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7435 count * sizeof(struct bgp_node)));
7436
7437 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7438 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7439 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7440 count * sizeof(struct bgp_info)));
7441 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7442 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7443 count,
7444 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7445 count * sizeof(struct bgp_info_extra)));
7446
7447 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7448 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7449 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7450 count * sizeof(struct bgp_static)));
7451
7452 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7453 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7454 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7455 count * sizeof(struct bpacket)));
7456
7457 /* Adj-In/Out */
7458 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7459 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7460 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7461 count * sizeof(struct bgp_adj_in)));
7462 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7463 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7464 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7465 count * sizeof(struct bgp_adj_out)));
7466
7467 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7468 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7469 count,
7470 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7471 count * sizeof(struct bgp_nexthop_cache)));
7472
7473 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7474 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7475 count,
7476 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7477 count * sizeof(struct bgp_damp_info)));
7478
7479 /* Attributes */
7480 count = attr_count();
7481 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7482 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7483 count * sizeof(struct attr)));
7484
7485 if ((count = attr_unknown_count()))
7486 vty_out(vty, "%ld unknown attributes\n", count);
7487
7488 /* AS_PATH attributes */
7489 count = aspath_count();
7490 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7491 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7492 count * sizeof(struct aspath)));
7493
7494 count = mtype_stats_alloc(MTYPE_AS_SEG);
7495 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7496 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7497 count * sizeof(struct assegment)));
7498
7499 /* Other attributes */
7500 if ((count = community_count()))
7501 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7502 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7503 count * sizeof(struct community)));
d62a17ae 7504 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7505 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7506 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7507 count * sizeof(struct ecommunity)));
d62a17ae 7508 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7509 vty_out(vty,
7510 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7511 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7512 count * sizeof(struct lcommunity)));
d62a17ae 7513
7514 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7515 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7516 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7517 count * sizeof(struct cluster_list)));
7518
7519 /* Peer related usage */
7520 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7521 vty_out(vty, "%ld peers, using %s of memory\n", count,
7522 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7523 count * sizeof(struct peer)));
7524
7525 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7526 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7527 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7528 count * sizeof(struct peer_group)));
7529
7530 /* Other */
7531 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7532 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7533 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7534 count * sizeof(struct hash)));
7535 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7536 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7537 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7538 count * sizeof(struct hash_backet)));
7539 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7540 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7541 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7542 count * sizeof(regex_t)));
d62a17ae 7543 return CMD_SUCCESS;
4bf6a362 7544}
fee0f4c6 7545
57a9c8a8
DS
7546static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7547{
7548 json_object *bestpath = json_object_new_object();
7549
7550 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7551 json_object_string_add(bestpath, "asPath", "ignore");
7552
7553 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7554 json_object_string_add(bestpath, "asPath", "confed");
7555
7556 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7557 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7558 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7559 "as-set");
7560 else
a4d82a8a 7561 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7562 "true");
7563 } else
a4d82a8a 7564 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7565
7566 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7567 json_object_string_add(bestpath, "compareRouterId", "true");
7568 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7569 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7570 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7571 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7572 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7573 json_object_string_add(bestpath, "med",
7574 "missing-as-worst");
7575 else
7576 json_object_string_add(bestpath, "med", "true");
7577 }
7578
7579 json_object_object_add(json, "bestPath", bestpath);
7580}
7581
718e3744 7582/* Show BGP peer's summary information. */
d62a17ae 7583static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
d7c0a89a 7584 uint8_t use_json, json_object *json)
d62a17ae 7585{
7586 struct peer *peer;
7587 struct listnode *node, *nnode;
7588 unsigned int count = 0, dn_count = 0;
7589 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7590 char neighbor_buf[VTY_BUFSIZ];
7591 int neighbor_col_default_width = 16;
7592 int len;
7593 int max_neighbor_width = 0;
7594 int pfx_rcd_safi;
7595 json_object *json_peer = NULL;
7596 json_object *json_peers = NULL;
7597
7598 /* labeled-unicast routes are installed in the unicast table so in order
7599 * to
7600 * display the correct PfxRcd value we must look at SAFI_UNICAST
7601 */
7602 if (safi == SAFI_LABELED_UNICAST)
7603 pfx_rcd_safi = SAFI_UNICAST;
7604 else
7605 pfx_rcd_safi = safi;
7606
7607 if (use_json) {
7608 if (json == NULL)
7609 json = json_object_new_object();
7610
7611 json_peers = json_object_new_object();
7612 } else {
7613 /* Loop over all neighbors that will be displayed to determine
7614 * how many
7615 * characters are needed for the Neighbor column
7616 */
7617 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7618 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7619 continue;
7620
7621 if (peer->afc[afi][safi]) {
7622 memset(dn_flag, '\0', sizeof(dn_flag));
7623 if (peer_dynamic_neighbor(peer))
7624 dn_flag[0] = '*';
7625
7626 if (peer->hostname
7627 && bgp_flag_check(bgp,
7628 BGP_FLAG_SHOW_HOSTNAME))
7629 sprintf(neighbor_buf, "%s%s(%s) ",
7630 dn_flag, peer->hostname,
7631 peer->host);
7632 else
7633 sprintf(neighbor_buf, "%s%s ", dn_flag,
7634 peer->host);
7635
7636 len = strlen(neighbor_buf);
7637
7638 if (len > max_neighbor_width)
7639 max_neighbor_width = len;
7640 }
7641 }
f933309e 7642
d62a17ae 7643 /* Originally we displayed the Neighbor column as 16
7644 * characters wide so make that the default
7645 */
7646 if (max_neighbor_width < neighbor_col_default_width)
7647 max_neighbor_width = neighbor_col_default_width;
7648 }
f933309e 7649
d62a17ae 7650 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7651 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7652 continue;
7653
ea47320b
DL
7654 if (!peer->afc[afi][safi])
7655 continue;
d62a17ae 7656
ea47320b
DL
7657 if (!count) {
7658 unsigned long ents;
7659 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7660 int64_t vrf_id_ui;
d62a17ae 7661
a4d82a8a
PZ
7662 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7663 ? -1
7664 : (int64_t)bgp->vrf_id;
ea47320b
DL
7665
7666 /* Usage summary and header */
7667 if (use_json) {
7668 json_object_string_add(
7669 json, "routerId",
7670 inet_ntoa(bgp->router_id));
60466a63
QY
7671 json_object_int_add(json, "as", bgp->as);
7672 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7673 json_object_string_add(
7674 json, "vrfName",
7675 (bgp->inst_type
7676 == BGP_INSTANCE_TYPE_DEFAULT)
7677 ? "Default"
7678 : bgp->name);
7679 } else {
7680 vty_out(vty,
7681 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7682 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7683 bgp->vrf_id == VRF_UNKNOWN
7684 ? -1
7685 : (int)bgp->vrf_id);
ea47320b
DL
7686 vty_out(vty, "\n");
7687 }
d62a17ae 7688
ea47320b 7689 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7690 if (use_json) {
ea47320b 7691 json_object_int_add(
60466a63 7692 json, "updateDelayLimit",
ea47320b 7693 bgp->v_update_delay);
d62a17ae 7694
ea47320b
DL
7695 if (bgp->v_update_delay
7696 != bgp->v_establish_wait)
d62a17ae 7697 json_object_int_add(
7698 json,
ea47320b
DL
7699 "updateDelayEstablishWait",
7700 bgp->v_establish_wait);
d62a17ae 7701
60466a63 7702 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7703 json_object_string_add(
7704 json,
7705 "updateDelayFirstNeighbor",
7706 bgp->update_delay_begin_time);
7707 json_object_boolean_true_add(
7708 json,
7709 "updateDelayInProgress");
7710 } else {
7711 if (bgp->update_delay_over) {
d62a17ae 7712 json_object_string_add(
7713 json,
7714 "updateDelayFirstNeighbor",
7715 bgp->update_delay_begin_time);
ea47320b 7716 json_object_string_add(
d62a17ae 7717 json,
ea47320b
DL
7718 "updateDelayBestpathResumed",
7719 bgp->update_delay_end_time);
7720 json_object_string_add(
d62a17ae 7721 json,
ea47320b
DL
7722 "updateDelayZebraUpdateResume",
7723 bgp->update_delay_zebra_resume_time);
7724 json_object_string_add(
7725 json,
7726 "updateDelayPeerUpdateResume",
7727 bgp->update_delay_peers_resume_time);
d62a17ae 7728 }
ea47320b
DL
7729 }
7730 } else {
7731 vty_out(vty,
7732 "Read-only mode update-delay limit: %d seconds\n",
7733 bgp->v_update_delay);
7734 if (bgp->v_update_delay
7735 != bgp->v_establish_wait)
d62a17ae 7736 vty_out(vty,
ea47320b
DL
7737 " Establish wait: %d seconds\n",
7738 bgp->v_establish_wait);
d62a17ae 7739
60466a63 7740 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7741 vty_out(vty,
7742 " First neighbor established: %s\n",
7743 bgp->update_delay_begin_time);
7744 vty_out(vty,
7745 " Delay in progress\n");
7746 } else {
7747 if (bgp->update_delay_over) {
d62a17ae 7748 vty_out(vty,
7749 " First neighbor established: %s\n",
7750 bgp->update_delay_begin_time);
7751 vty_out(vty,
ea47320b
DL
7752 " Best-paths resumed: %s\n",
7753 bgp->update_delay_end_time);
7754 vty_out(vty,
7755 " zebra update resumed: %s\n",
7756 bgp->update_delay_zebra_resume_time);
7757 vty_out(vty,
7758 " peers update resumed: %s\n",
7759 bgp->update_delay_peers_resume_time);
d62a17ae 7760 }
7761 }
7762 }
ea47320b 7763 }
d62a17ae 7764
ea47320b
DL
7765 if (use_json) {
7766 if (bgp_maxmed_onstartup_configured(bgp)
7767 && bgp->maxmed_active)
7768 json_object_boolean_true_add(
60466a63 7769 json, "maxMedOnStartup");
ea47320b
DL
7770 if (bgp->v_maxmed_admin)
7771 json_object_boolean_true_add(
60466a63 7772 json, "maxMedAdministrative");
d62a17ae 7773
ea47320b
DL
7774 json_object_int_add(
7775 json, "tableVersion",
60466a63 7776 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7777
60466a63
QY
7778 ents = bgp_table_count(bgp->rib[afi][safi]);
7779 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7780 json_object_int_add(
7781 json, "ribMemory",
7782 ents * sizeof(struct bgp_node));
d62a17ae 7783
ea47320b 7784 ents = listcount(bgp->peer);
60466a63
QY
7785 json_object_int_add(json, "peerCount", ents);
7786 json_object_int_add(json, "peerMemory",
7787 ents * sizeof(struct peer));
d62a17ae 7788
ea47320b
DL
7789 if ((ents = listcount(bgp->group))) {
7790 json_object_int_add(
60466a63 7791 json, "peerGroupCount", ents);
ea47320b
DL
7792 json_object_int_add(
7793 json, "peerGroupMemory",
996c9314
LB
7794 ents * sizeof(struct
7795 peer_group));
ea47320b 7796 }
d62a17ae 7797
ea47320b
DL
7798 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7799 BGP_CONFIG_DAMPENING))
7800 json_object_boolean_true_add(
60466a63 7801 json, "dampeningEnabled");
ea47320b
DL
7802 } else {
7803 if (bgp_maxmed_onstartup_configured(bgp)
7804 && bgp->maxmed_active)
d62a17ae 7805 vty_out(vty,
ea47320b
DL
7806 "Max-med on-startup active\n");
7807 if (bgp->v_maxmed_admin)
d62a17ae 7808 vty_out(vty,
ea47320b 7809 "Max-med administrative active\n");
d62a17ae 7810
60466a63
QY
7811 vty_out(vty, "BGP table version %" PRIu64 "\n",
7812 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 7813
60466a63 7814 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
7815 vty_out(vty,
7816 "RIB entries %ld, using %s of memory\n",
7817 ents,
996c9314
LB
7818 mtype_memstr(memstrbuf,
7819 sizeof(memstrbuf),
7820 ents * sizeof(struct
7821 bgp_node)));
ea47320b
DL
7822
7823 /* Peer related usage */
7824 ents = listcount(bgp->peer);
60466a63 7825 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7826 ents,
7827 mtype_memstr(
60466a63
QY
7828 memstrbuf, sizeof(memstrbuf),
7829 ents * sizeof(struct peer)));
ea47320b
DL
7830
7831 if ((ents = listcount(bgp->group)))
d62a17ae 7832 vty_out(vty,
ea47320b 7833 "Peer groups %ld, using %s of memory\n",
d62a17ae 7834 ents,
7835 mtype_memstr(
7836 memstrbuf,
7837 sizeof(memstrbuf),
996c9314
LB
7838 ents * sizeof(struct
7839 peer_group)));
d62a17ae 7840
ea47320b
DL
7841 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7842 BGP_CONFIG_DAMPENING))
60466a63 7843 vty_out(vty, "Dampening enabled.\n");
ea47320b 7844 vty_out(vty, "\n");
d62a17ae 7845
ea47320b
DL
7846 /* Subtract 8 here because 'Neighbor' is
7847 * 8 characters */
7848 vty_out(vty, "Neighbor");
60466a63
QY
7849 vty_out(vty, "%*s", max_neighbor_width - 8,
7850 " ");
ea47320b
DL
7851 vty_out(vty,
7852 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7853 }
ea47320b 7854 }
d62a17ae 7855
ea47320b 7856 count++;
d62a17ae 7857
ea47320b
DL
7858 if (use_json) {
7859 json_peer = json_object_new_object();
d62a17ae 7860
ea47320b 7861 if (peer_dynamic_neighbor(peer))
60466a63
QY
7862 json_object_boolean_true_add(json_peer,
7863 "dynamicPeer");
d62a17ae 7864
ea47320b 7865 if (peer->hostname)
60466a63 7866 json_object_string_add(json_peer, "hostname",
ea47320b 7867 peer->hostname);
d62a17ae 7868
ea47320b 7869 if (peer->domainname)
60466a63
QY
7870 json_object_string_add(json_peer, "domainname",
7871 peer->domainname);
d62a17ae 7872
60466a63 7873 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7874 json_object_int_add(json_peer, "version", 4);
60466a63 7875 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 7876 PEER_TOTAL_RX(peer));
60466a63 7877 json_object_int_add(json_peer, "msgSent",
0112e9e0 7878 PEER_TOTAL_TX(peer));
ea47320b
DL
7879
7880 json_object_int_add(json_peer, "tableVersion",
7881 peer->version[afi][safi]);
7882 json_object_int_add(json_peer, "outq",
7883 peer->obuf->count);
7884 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7885 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7886 use_json, json_peer);
7887 json_object_int_add(json_peer, "prefixReceivedCount",
7888 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 7889
ea47320b 7890 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7891 json_object_string_add(json_peer, "state",
ea47320b 7892 "Idle (Admin)");
60466a63
QY
7893 else if (CHECK_FLAG(peer->sflags,
7894 PEER_STATUS_PREFIX_OVERFLOW))
7895 json_object_string_add(json_peer, "state",
ea47320b
DL
7896 "Idle (PfxCt)");
7897 else
7898 json_object_string_add(
7899 json_peer, "state",
60466a63
QY
7900 lookup_msg(bgp_status_msg, peer->status,
7901 NULL));
ea47320b
DL
7902
7903 if (peer->conf_if)
60466a63 7904 json_object_string_add(json_peer, "idType",
ea47320b
DL
7905 "interface");
7906 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
7907 json_object_string_add(json_peer, "idType",
7908 "ipv4");
ea47320b 7909 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
7910 json_object_string_add(json_peer, "idType",
7911 "ipv6");
d62a17ae 7912
ea47320b
DL
7913 json_object_object_add(json_peers, peer->host,
7914 json_peer);
7915 } else {
7916 memset(dn_flag, '\0', sizeof(dn_flag));
7917 if (peer_dynamic_neighbor(peer)) {
7918 dn_count++;
7919 dn_flag[0] = '*';
7920 }
d62a17ae 7921
ea47320b 7922 if (peer->hostname
60466a63 7923 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 7924 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 7925 peer->hostname, peer->host);
ea47320b 7926 else
60466a63 7927 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
7928
7929 /* pad the neighbor column with spaces */
7930 if (len < max_neighbor_width)
60466a63
QY
7931 vty_out(vty, "%*s", max_neighbor_width - len,
7932 " ");
ea47320b 7933
86a55b99 7934 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
7935 peer->as, PEER_TOTAL_RX(peer),
7936 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7937 0, peer->obuf->count,
d62a17ae 7938 peer_uptime(peer->uptime, timebuf,
ea47320b 7939 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 7940
ea47320b 7941 if (peer->status == Established)
95077abf
DW
7942 if (peer->afc_recv[afi][pfx_rcd_safi])
7943 vty_out(vty, " %12ld",
a4d82a8a
PZ
7944 peer->pcount[afi]
7945 [pfx_rcd_safi]);
95077abf
DW
7946 else
7947 vty_out(vty, " NoNeg");
ea47320b 7948 else {
60466a63 7949 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 7950 vty_out(vty, " Idle (Admin)");
60466a63
QY
7951 else if (CHECK_FLAG(
7952 peer->sflags,
7953 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 7954 vty_out(vty, " Idle (PfxCt)");
d62a17ae 7955 else
ea47320b 7956 vty_out(vty, " %12s",
60466a63
QY
7957 lookup_msg(bgp_status_msg,
7958 peer->status, NULL));
d62a17ae 7959 }
ea47320b 7960 vty_out(vty, "\n");
d62a17ae 7961 }
7962 }
f933309e 7963
d62a17ae 7964 if (use_json) {
7965 json_object_object_add(json, "peers", json_peers);
7966
7967 json_object_int_add(json, "totalPeers", count);
7968 json_object_int_add(json, "dynamicPeers", dn_count);
7969
57a9c8a8
DS
7970 bgp_show_bestpath_json(bgp, json);
7971
996c9314
LB
7972 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7973 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7974 json_object_free(json);
7975 } else {
7976 if (count)
7977 vty_out(vty, "\nTotal number of neighbors %d\n", count);
7978 else {
7979 if (use_json)
7980 vty_out(vty,
7981 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
7982 afi_safi_print(afi, safi));
7983 else
7984 vty_out(vty, "No %s neighbor is configured\n",
7985 afi_safi_print(afi, safi));
7986 }
b05a1c8b 7987
d62a17ae 7988 if (dn_count && !use_json) {
7989 vty_out(vty, "* - dynamic neighbor\n");
7990 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
7991 dn_count, bgp->dynamic_neighbors_limit);
7992 }
7993 }
1ff9a340 7994
d62a17ae 7995 return CMD_SUCCESS;
718e3744 7996}
7997
d62a17ae 7998static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
d7c0a89a 7999 int safi, uint8_t use_json,
d62a17ae 8000 json_object *json)
8001{
8002 int is_first = 1;
8003 int afi_wildcard = (afi == AFI_MAX);
8004 int safi_wildcard = (safi == SAFI_MAX);
8005 int is_wildcard = (afi_wildcard || safi_wildcard);
8006 bool json_output = false;
8007
8008 if (use_json && is_wildcard)
8009 vty_out(vty, "{\n");
8010 if (afi_wildcard)
8011 afi = 1; /* AFI_IP */
8012 while (afi < AFI_MAX) {
8013 if (safi_wildcard)
8014 safi = 1; /* SAFI_UNICAST */
8015 while (safi < SAFI_MAX) {
318cac96 8016 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
d62a17ae 8017 json_output = true;
8018 if (is_wildcard) {
8019 /*
8020 * So limit output to those afi/safi
8021 * pairs that
8022 * actualy have something interesting in
8023 * them
8024 */
8025 if (use_json) {
8026 json = json_object_new_object();
8027
8028 if (!is_first)
8029 vty_out(vty, ",\n");
8030 else
8031 is_first = 0;
8032
8033 vty_out(vty, "\"%s\":",
8034 afi_safi_json(afi,
8035 safi));
8036 } else {
8037 vty_out(vty, "\n%s Summary:\n",
8038 afi_safi_print(afi,
8039 safi));
8040 }
8041 }
8042 bgp_show_summary(vty, bgp, afi, safi, use_json,
8043 json);
8044 }
8045 safi++;
d62a17ae 8046 if (!safi_wildcard)
8047 safi = SAFI_MAX;
8048 }
8049 afi++;
ee851c8c 8050 if (!afi_wildcard)
d62a17ae 8051 afi = AFI_MAX;
8052 }
8053
8054 if (use_json && is_wildcard)
8055 vty_out(vty, "}\n");
8056 else if (use_json && !json_output)
8057 vty_out(vty, "{}\n");
8058}
8059
8060static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
d7c0a89a 8061 safi_t safi, uint8_t use_json)
d62a17ae 8062{
8063 struct listnode *node, *nnode;
8064 struct bgp *bgp;
8065 json_object *json = NULL;
8066 int is_first = 1;
8067
8068 if (use_json)
8069 vty_out(vty, "{\n");
8070
8071 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8072 if (use_json) {
8073 json = json_object_new_object();
8074
8075 if (!is_first)
8076 vty_out(vty, ",\n");
8077 else
8078 is_first = 0;
8079
8080 vty_out(vty, "\"%s\":",
8081 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8082 ? "Default"
8083 : bgp->name);
8084 } else {
8085 vty_out(vty, "\nInstance %s:\n",
8086 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8087 ? "Default"
8088 : bgp->name);
8089 }
8090 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8091 }
8092
8093 if (use_json)
8094 vty_out(vty, "}\n");
8095}
8096
8097int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
d7c0a89a 8098 safi_t safi, uint8_t use_json)
d62a17ae 8099{
8100 struct bgp *bgp;
8101
8102 if (name) {
8103 if (strmatch(name, "all")) {
8104 bgp_show_all_instances_summary_vty(vty, afi, safi,
8105 use_json);
8106 return CMD_SUCCESS;
8107 } else {
8108 bgp = bgp_lookup_by_name(name);
8109
8110 if (!bgp) {
8111 if (use_json)
8112 vty_out(vty, "{}\n");
8113 else
8114 vty_out(vty,
8115 "%% No such BGP instance exist\n");
8116 return CMD_WARNING;
8117 }
8118
8119 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8120 NULL);
8121 return CMD_SUCCESS;
8122 }
8123 }
8124
8125 bgp = bgp_get_default();
8126
8127 if (bgp)
8128 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8129
8130 return CMD_SUCCESS;
4fb25c53
DW
8131}
8132
716b2d8a 8133/* `show [ip] bgp summary' commands. */
47fc97cc 8134DEFUN (show_ip_bgp_summary,
718e3744 8135 show_ip_bgp_summary_cmd,
dd6bd0f1 8136 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8137 SHOW_STR
8138 IP_STR
8139 BGP_STR
8386ac43 8140 BGP_INSTANCE_HELP_STR
46f296b4 8141 BGP_AFI_HELP_STR
dd6bd0f1 8142 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8143 "Summary of BGP neighbor status\n"
9973d184 8144 JSON_STR)
718e3744 8145{
d62a17ae 8146 char *vrf = NULL;
8147 afi_t afi = AFI_MAX;
8148 safi_t safi = SAFI_MAX;
8149
8150 int idx = 0;
8151
8152 /* show [ip] bgp */
8153 if (argv_find(argv, argc, "ip", &idx))
8154 afi = AFI_IP;
8155 /* [<view|vrf> VIEWVRFNAME] */
8156 if (argv_find(argv, argc, "view", &idx)
8157 || argv_find(argv, argc, "vrf", &idx))
8158 vrf = argv[++idx]->arg;
8159 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8160 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8161 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8162 }
8163
8164 int uj = use_json(argc, argv);
8165
8166 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8167}
8168
8169const char *afi_safi_print(afi_t afi, safi_t safi)
8170{
8171 if (afi == AFI_IP && safi == SAFI_UNICAST)
8172 return "IPv4 Unicast";
8173 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8174 return "IPv4 Multicast";
8175 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8176 return "IPv4 Labeled Unicast";
8177 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8178 return "IPv4 VPN";
8179 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8180 return "IPv4 Encap";
7c40bf39 8181 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8182 return "IPv4 Flowspec";
d62a17ae 8183 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8184 return "IPv6 Unicast";
8185 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8186 return "IPv6 Multicast";
8187 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8188 return "IPv6 Labeled Unicast";
8189 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8190 return "IPv6 VPN";
8191 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8192 return "IPv6 Encap";
7c40bf39 8193 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8194 return "IPv6 Flowspec";
d62a17ae 8195 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8196 return "L2VPN EVPN";
8197 else
8198 return "Unknown";
538621f2 8199}
8200
b9f77ec8
DS
8201/*
8202 * Please note that we have intentionally camelCased
8203 * the return strings here. So if you want
8204 * to use this function, please ensure you
8205 * are doing this within json output
8206 */
d62a17ae 8207const char *afi_safi_json(afi_t afi, safi_t safi)
8208{
8209 if (afi == AFI_IP && safi == SAFI_UNICAST)
8210 return "ipv4Unicast";
8211 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8212 return "ipv4Multicast";
8213 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8214 return "ipv4LabeledUnicast";
8215 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8216 return "ipv4Vpn";
8217 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8218 return "ipv4Encap";
7c40bf39 8219 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8220 return "ipv4Flowspec";
d62a17ae 8221 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8222 return "ipv6Unicast";
8223 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8224 return "ipv6Multicast";
8225 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8226 return "ipv6LabeledUnicast";
8227 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8228 return "ipv6Vpn";
8229 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8230 return "ipv6Encap";
7c40bf39 8231 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8232 return "ipv6Flowspec";
d62a17ae 8233 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8234 return "l2VpnEvpn";
8235 else
8236 return "Unknown";
27162734
LB
8237}
8238
718e3744 8239/* Show BGP peer's information. */
d62a17ae 8240enum show_type { show_all, show_peer };
8241
8242static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8243 afi_t afi, safi_t safi,
d7c0a89a
QY
8244 uint16_t adv_smcap, uint16_t adv_rmcap,
8245 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8246 uint8_t use_json, json_object *json_pref)
d62a17ae 8247{
8248 /* Send-Mode */
8249 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8250 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8251 if (use_json) {
8252 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8253 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8254 json_object_string_add(json_pref, "sendMode",
8255 "advertisedAndReceived");
8256 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8257 json_object_string_add(json_pref, "sendMode",
8258 "advertised");
8259 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8260 json_object_string_add(json_pref, "sendMode",
8261 "received");
8262 } else {
8263 vty_out(vty, " Send-mode: ");
8264 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8265 vty_out(vty, "advertised");
8266 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8267 vty_out(vty, "%sreceived",
8268 CHECK_FLAG(p->af_cap[afi][safi],
8269 adv_smcap)
8270 ? ", "
8271 : "");
8272 vty_out(vty, "\n");
8273 }
8274 }
8275
8276 /* Receive-Mode */
8277 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8278 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8279 if (use_json) {
8280 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8281 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8282 json_object_string_add(json_pref, "recvMode",
8283 "advertisedAndReceived");
8284 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8285 json_object_string_add(json_pref, "recvMode",
8286 "advertised");
8287 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8288 json_object_string_add(json_pref, "recvMode",
8289 "received");
8290 } else {
8291 vty_out(vty, " Receive-mode: ");
8292 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8293 vty_out(vty, "advertised");
8294 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8295 vty_out(vty, "%sreceived",
8296 CHECK_FLAG(p->af_cap[afi][safi],
8297 adv_rmcap)
8298 ? ", "
8299 : "");
8300 vty_out(vty, "\n");
8301 }
8302 }
8303}
8304
8305static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
d7c0a89a 8306 safi_t safi, uint8_t use_json,
d62a17ae 8307 json_object *json_neigh)
8308{
0291c246
MK
8309 struct bgp_filter *filter;
8310 struct peer_af *paf;
8311 char orf_pfx_name[BUFSIZ];
8312 int orf_pfx_count;
8313 json_object *json_af = NULL;
8314 json_object *json_prefA = NULL;
8315 json_object *json_prefB = NULL;
8316 json_object *json_addr = NULL;
d62a17ae 8317
8318 if (use_json) {
8319 json_addr = json_object_new_object();
8320 json_af = json_object_new_object();
8321 filter = &p->filter[afi][safi];
8322
8323 if (peer_group_active(p))
8324 json_object_string_add(json_addr, "peerGroupMember",
8325 p->group->name);
8326
8327 paf = peer_af_find(p, afi, safi);
8328 if (paf && PAF_SUBGRP(paf)) {
8329 json_object_int_add(json_addr, "updateGroupId",
8330 PAF_UPDGRP(paf)->id);
8331 json_object_int_add(json_addr, "subGroupId",
8332 PAF_SUBGRP(paf)->id);
8333 json_object_int_add(json_addr, "packetQueueLength",
8334 bpacket_queue_virtual_length(paf));
8335 }
8336
8337 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8338 || CHECK_FLAG(p->af_cap[afi][safi],
8339 PEER_CAP_ORF_PREFIX_SM_RCV)
8340 || CHECK_FLAG(p->af_cap[afi][safi],
8341 PEER_CAP_ORF_PREFIX_RM_ADV)
8342 || CHECK_FLAG(p->af_cap[afi][safi],
8343 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8344 json_object_int_add(json_af, "orfType",
8345 ORF_TYPE_PREFIX);
8346 json_prefA = json_object_new_object();
8347 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8348 PEER_CAP_ORF_PREFIX_SM_ADV,
8349 PEER_CAP_ORF_PREFIX_RM_ADV,
8350 PEER_CAP_ORF_PREFIX_SM_RCV,
8351 PEER_CAP_ORF_PREFIX_RM_RCV,
8352 use_json, json_prefA);
8353 json_object_object_add(json_af, "orfPrefixList",
8354 json_prefA);
8355 }
8356
8357 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
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_OLD_RCV)) {
8364 json_object_int_add(json_af, "orfOldType",
8365 ORF_TYPE_PREFIX_OLD);
8366 json_prefB = json_object_new_object();
8367 bgp_show_peer_afi_orf_cap(
8368 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8369 PEER_CAP_ORF_PREFIX_RM_ADV,
8370 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8371 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8372 json_prefB);
8373 json_object_object_add(json_af, "orfOldPrefixList",
8374 json_prefB);
8375 }
8376
8377 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8378 || CHECK_FLAG(p->af_cap[afi][safi],
8379 PEER_CAP_ORF_PREFIX_SM_RCV)
8380 || CHECK_FLAG(p->af_cap[afi][safi],
8381 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8382 || CHECK_FLAG(p->af_cap[afi][safi],
8383 PEER_CAP_ORF_PREFIX_RM_ADV)
8384 || CHECK_FLAG(p->af_cap[afi][safi],
8385 PEER_CAP_ORF_PREFIX_RM_RCV)
8386 || CHECK_FLAG(p->af_cap[afi][safi],
8387 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8388 json_object_object_add(json_addr, "afDependentCap",
8389 json_af);
8390 else
8391 json_object_free(json_af);
8392
8393 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8394 orf_pfx_count = prefix_bgp_show_prefix_list(
8395 NULL, afi, orf_pfx_name, use_json);
8396
8397 if (CHECK_FLAG(p->af_sflags[afi][safi],
8398 PEER_STATUS_ORF_PREFIX_SEND)
8399 || orf_pfx_count) {
8400 if (CHECK_FLAG(p->af_sflags[afi][safi],
8401 PEER_STATUS_ORF_PREFIX_SEND))
8402 json_object_boolean_true_add(json_neigh,
8403 "orfSent");
8404 if (orf_pfx_count)
8405 json_object_int_add(json_addr, "orfRecvCounter",
8406 orf_pfx_count);
8407 }
8408 if (CHECK_FLAG(p->af_sflags[afi][safi],
8409 PEER_STATUS_ORF_WAIT_REFRESH))
8410 json_object_string_add(
8411 json_addr, "orfFirstUpdate",
8412 "deferredUntilORFOrRouteRefreshRecvd");
8413
8414 if (CHECK_FLAG(p->af_flags[afi][safi],
8415 PEER_FLAG_REFLECTOR_CLIENT))
8416 json_object_boolean_true_add(json_addr,
8417 "routeReflectorClient");
8418 if (CHECK_FLAG(p->af_flags[afi][safi],
8419 PEER_FLAG_RSERVER_CLIENT))
8420 json_object_boolean_true_add(json_addr,
8421 "routeServerClient");
8422 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8423 json_object_boolean_true_add(json_addr,
8424 "inboundSoftConfigPermit");
8425
8426 if (CHECK_FLAG(p->af_flags[afi][safi],
8427 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8428 json_object_boolean_true_add(
8429 json_addr,
8430 "privateAsNumsAllReplacedInUpdatesToNbr");
8431 else if (CHECK_FLAG(p->af_flags[afi][safi],
8432 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8433 json_object_boolean_true_add(
8434 json_addr,
8435 "privateAsNumsReplacedInUpdatesToNbr");
8436 else if (CHECK_FLAG(p->af_flags[afi][safi],
8437 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8438 json_object_boolean_true_add(
8439 json_addr,
8440 "privateAsNumsAllRemovedInUpdatesToNbr");
8441 else if (CHECK_FLAG(p->af_flags[afi][safi],
8442 PEER_FLAG_REMOVE_PRIVATE_AS))
8443 json_object_boolean_true_add(
8444 json_addr,
8445 "privateAsNumsRemovedInUpdatesToNbr");
8446
8447 if (CHECK_FLAG(p->af_flags[afi][safi],
8448 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8449 json_object_boolean_true_add(json_addr,
8450 "addpathTxAllPaths");
8451
8452 if (CHECK_FLAG(p->af_flags[afi][safi],
8453 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8454 json_object_boolean_true_add(json_addr,
8455 "addpathTxBestpathPerAS");
8456
8457 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8458 json_object_string_add(json_addr,
8459 "overrideASNsInOutboundUpdates",
8460 "ifAspathEqualRemoteAs");
8461
8462 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8463 || CHECK_FLAG(p->af_flags[afi][safi],
8464 PEER_FLAG_FORCE_NEXTHOP_SELF))
8465 json_object_boolean_true_add(json_addr,
8466 "routerAlwaysNextHop");
8467 if (CHECK_FLAG(p->af_flags[afi][safi],
8468 PEER_FLAG_AS_PATH_UNCHANGED))
8469 json_object_boolean_true_add(
8470 json_addr, "unchangedAsPathPropogatedToNbr");
8471 if (CHECK_FLAG(p->af_flags[afi][safi],
8472 PEER_FLAG_NEXTHOP_UNCHANGED))
8473 json_object_boolean_true_add(
8474 json_addr, "unchangedNextHopPropogatedToNbr");
8475 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8476 json_object_boolean_true_add(
8477 json_addr, "unchangedMedPropogatedToNbr");
8478 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8479 || CHECK_FLAG(p->af_flags[afi][safi],
8480 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8481 if (CHECK_FLAG(p->af_flags[afi][safi],
8482 PEER_FLAG_SEND_COMMUNITY)
8483 && CHECK_FLAG(p->af_flags[afi][safi],
8484 PEER_FLAG_SEND_EXT_COMMUNITY))
8485 json_object_string_add(json_addr,
8486 "commAttriSentToNbr",
8487 "extendedAndStandard");
8488 else if (CHECK_FLAG(p->af_flags[afi][safi],
8489 PEER_FLAG_SEND_EXT_COMMUNITY))
8490 json_object_string_add(json_addr,
8491 "commAttriSentToNbr",
8492 "extended");
8493 else
8494 json_object_string_add(json_addr,
8495 "commAttriSentToNbr",
8496 "standard");
8497 }
8498 if (CHECK_FLAG(p->af_flags[afi][safi],
8499 PEER_FLAG_DEFAULT_ORIGINATE)) {
8500 if (p->default_rmap[afi][safi].name)
8501 json_object_string_add(
8502 json_addr, "defaultRouteMap",
8503 p->default_rmap[afi][safi].name);
8504
8505 if (paf && PAF_SUBGRP(paf)
8506 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8507 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8508 json_object_boolean_true_add(json_addr,
8509 "defaultSent");
8510 else
8511 json_object_boolean_true_add(json_addr,
8512 "defaultNotSent");
8513 }
8514
dff8f48d 8515 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8516 if (is_evpn_enabled())
60466a63
QY
8517 json_object_boolean_true_add(
8518 json_addr, "advertiseAllVnis");
dff8f48d
MK
8519 }
8520
d62a17ae 8521 if (filter->plist[FILTER_IN].name
8522 || filter->dlist[FILTER_IN].name
8523 || filter->aslist[FILTER_IN].name
8524 || filter->map[RMAP_IN].name)
8525 json_object_boolean_true_add(json_addr,
8526 "inboundPathPolicyConfig");
8527 if (filter->plist[FILTER_OUT].name
8528 || filter->dlist[FILTER_OUT].name
8529 || filter->aslist[FILTER_OUT].name
8530 || filter->map[RMAP_OUT].name || filter->usmap.name)
8531 json_object_boolean_true_add(
8532 json_addr, "outboundPathPolicyConfig");
8533
8534 /* prefix-list */
8535 if (filter->plist[FILTER_IN].name)
8536 json_object_string_add(json_addr,
8537 "incomingUpdatePrefixFilterList",
8538 filter->plist[FILTER_IN].name);
8539 if (filter->plist[FILTER_OUT].name)
8540 json_object_string_add(json_addr,
8541 "outgoingUpdatePrefixFilterList",
8542 filter->plist[FILTER_OUT].name);
8543
8544 /* distribute-list */
8545 if (filter->dlist[FILTER_IN].name)
8546 json_object_string_add(
8547 json_addr, "incomingUpdateNetworkFilterList",
8548 filter->dlist[FILTER_IN].name);
8549 if (filter->dlist[FILTER_OUT].name)
8550 json_object_string_add(
8551 json_addr, "outgoingUpdateNetworkFilterList",
8552 filter->dlist[FILTER_OUT].name);
8553
8554 /* filter-list. */
8555 if (filter->aslist[FILTER_IN].name)
8556 json_object_string_add(json_addr,
8557 "incomingUpdateAsPathFilterList",
8558 filter->aslist[FILTER_IN].name);
8559 if (filter->aslist[FILTER_OUT].name)
8560 json_object_string_add(json_addr,
8561 "outgoingUpdateAsPathFilterList",
8562 filter->aslist[FILTER_OUT].name);
8563
8564 /* route-map. */
8565 if (filter->map[RMAP_IN].name)
8566 json_object_string_add(
8567 json_addr, "routeMapForIncomingAdvertisements",
8568 filter->map[RMAP_IN].name);
8569 if (filter->map[RMAP_OUT].name)
8570 json_object_string_add(
8571 json_addr, "routeMapForOutgoingAdvertisements",
8572 filter->map[RMAP_OUT].name);
8573
8574 /* unsuppress-map */
8575 if (filter->usmap.name)
8576 json_object_string_add(json_addr,
8577 "selectiveUnsuppressRouteMap",
8578 filter->usmap.name);
8579
8580 /* Receive prefix count */
8581 json_object_int_add(json_addr, "acceptedPrefixCounter",
8582 p->pcount[afi][safi]);
8583
8584 /* Maximum prefix */
8585 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8586 json_object_int_add(json_addr, "prefixAllowedMax",
8587 p->pmax[afi][safi]);
8588 if (CHECK_FLAG(p->af_flags[afi][safi],
8589 PEER_FLAG_MAX_PREFIX_WARNING))
8590 json_object_boolean_true_add(
8591 json_addr, "prefixAllowedMaxWarning");
8592 json_object_int_add(json_addr,
8593 "prefixAllowedWarningThresh",
8594 p->pmax_threshold[afi][safi]);
8595 if (p->pmax_restart[afi][safi])
8596 json_object_int_add(
8597 json_addr,
8598 "prefixAllowedRestartIntervalMsecs",
8599 p->pmax_restart[afi][safi] * 60000);
8600 }
8601 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8602 json_addr);
8603
8604 } else {
8605 filter = &p->filter[afi][safi];
8606
8607 vty_out(vty, " For address family: %s\n",
8608 afi_safi_print(afi, safi));
8609
8610 if (peer_group_active(p))
8611 vty_out(vty, " %s peer-group member\n",
8612 p->group->name);
8613
8614 paf = peer_af_find(p, afi, safi);
8615 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8616 vty_out(vty, " Update group %" PRIu64
8617 ", subgroup %" PRIu64 "\n",
d62a17ae 8618 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8619 vty_out(vty, " Packet Queue length %d\n",
8620 bpacket_queue_virtual_length(paf));
8621 } else {
8622 vty_out(vty, " Not part of any update group\n");
8623 }
8624 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8625 || CHECK_FLAG(p->af_cap[afi][safi],
8626 PEER_CAP_ORF_PREFIX_SM_RCV)
8627 || CHECK_FLAG(p->af_cap[afi][safi],
8628 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8629 || CHECK_FLAG(p->af_cap[afi][safi],
8630 PEER_CAP_ORF_PREFIX_RM_ADV)
8631 || CHECK_FLAG(p->af_cap[afi][safi],
8632 PEER_CAP_ORF_PREFIX_RM_RCV)
8633 || CHECK_FLAG(p->af_cap[afi][safi],
8634 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8635 vty_out(vty, " AF-dependant capabilities:\n");
8636
8637 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8638 || CHECK_FLAG(p->af_cap[afi][safi],
8639 PEER_CAP_ORF_PREFIX_SM_RCV)
8640 || CHECK_FLAG(p->af_cap[afi][safi],
8641 PEER_CAP_ORF_PREFIX_RM_ADV)
8642 || CHECK_FLAG(p->af_cap[afi][safi],
8643 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8644 vty_out(vty,
8645 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8646 ORF_TYPE_PREFIX);
8647 bgp_show_peer_afi_orf_cap(
8648 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8649 PEER_CAP_ORF_PREFIX_RM_ADV,
8650 PEER_CAP_ORF_PREFIX_SM_RCV,
8651 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8652 }
8653 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8654 || CHECK_FLAG(p->af_cap[afi][safi],
8655 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8656 || CHECK_FLAG(p->af_cap[afi][safi],
8657 PEER_CAP_ORF_PREFIX_RM_ADV)
8658 || CHECK_FLAG(p->af_cap[afi][safi],
8659 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8660 vty_out(vty,
8661 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8662 ORF_TYPE_PREFIX_OLD);
8663 bgp_show_peer_afi_orf_cap(
8664 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8665 PEER_CAP_ORF_PREFIX_RM_ADV,
8666 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8667 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8668 }
8669
8670 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8671 orf_pfx_count = prefix_bgp_show_prefix_list(
8672 NULL, afi, orf_pfx_name, use_json);
8673
8674 if (CHECK_FLAG(p->af_sflags[afi][safi],
8675 PEER_STATUS_ORF_PREFIX_SEND)
8676 || orf_pfx_count) {
8677 vty_out(vty, " Outbound Route Filter (ORF):");
8678 if (CHECK_FLAG(p->af_sflags[afi][safi],
8679 PEER_STATUS_ORF_PREFIX_SEND))
8680 vty_out(vty, " sent;");
8681 if (orf_pfx_count)
8682 vty_out(vty, " received (%d entries)",
8683 orf_pfx_count);
8684 vty_out(vty, "\n");
8685 }
8686 if (CHECK_FLAG(p->af_sflags[afi][safi],
8687 PEER_STATUS_ORF_WAIT_REFRESH))
8688 vty_out(vty,
8689 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8690
8691 if (CHECK_FLAG(p->af_flags[afi][safi],
8692 PEER_FLAG_REFLECTOR_CLIENT))
8693 vty_out(vty, " Route-Reflector Client\n");
8694 if (CHECK_FLAG(p->af_flags[afi][safi],
8695 PEER_FLAG_RSERVER_CLIENT))
8696 vty_out(vty, " Route-Server Client\n");
8697 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8698 vty_out(vty,
8699 " Inbound soft reconfiguration allowed\n");
8700
8701 if (CHECK_FLAG(p->af_flags[afi][safi],
8702 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8703 vty_out(vty,
8704 " Private AS numbers (all) replaced in updates to this neighbor\n");
8705 else if (CHECK_FLAG(p->af_flags[afi][safi],
8706 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8707 vty_out(vty,
8708 " Private AS numbers replaced in updates to this neighbor\n");
8709 else if (CHECK_FLAG(p->af_flags[afi][safi],
8710 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8711 vty_out(vty,
8712 " Private AS numbers (all) removed in updates to this neighbor\n");
8713 else if (CHECK_FLAG(p->af_flags[afi][safi],
8714 PEER_FLAG_REMOVE_PRIVATE_AS))
8715 vty_out(vty,
8716 " Private AS numbers removed in updates to this neighbor\n");
8717
8718 if (CHECK_FLAG(p->af_flags[afi][safi],
8719 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8720 vty_out(vty, " Advertise all paths via addpath\n");
8721
8722 if (CHECK_FLAG(p->af_flags[afi][safi],
8723 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8724 vty_out(vty,
8725 " Advertise bestpath per AS via addpath\n");
8726
8727 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8728 vty_out(vty,
8729 " Override ASNs in outbound updates if aspath equals remote-as\n");
8730
8731 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8732 || CHECK_FLAG(p->af_flags[afi][safi],
8733 PEER_FLAG_FORCE_NEXTHOP_SELF))
8734 vty_out(vty, " NEXT_HOP is always this router\n");
8735 if (CHECK_FLAG(p->af_flags[afi][safi],
8736 PEER_FLAG_AS_PATH_UNCHANGED))
8737 vty_out(vty,
8738 " AS_PATH is propagated unchanged to this neighbor\n");
8739 if (CHECK_FLAG(p->af_flags[afi][safi],
8740 PEER_FLAG_NEXTHOP_UNCHANGED))
8741 vty_out(vty,
8742 " NEXT_HOP is propagated unchanged to this neighbor\n");
8743 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8744 vty_out(vty,
8745 " MED is propagated unchanged to this neighbor\n");
8746 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8747 || CHECK_FLAG(p->af_flags[afi][safi],
8748 PEER_FLAG_SEND_EXT_COMMUNITY)
8749 || CHECK_FLAG(p->af_flags[afi][safi],
8750 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8751 vty_out(vty,
8752 " Community attribute sent to this neighbor");
8753 if (CHECK_FLAG(p->af_flags[afi][safi],
8754 PEER_FLAG_SEND_COMMUNITY)
8755 && CHECK_FLAG(p->af_flags[afi][safi],
8756 PEER_FLAG_SEND_EXT_COMMUNITY)
8757 && CHECK_FLAG(p->af_flags[afi][safi],
8758 PEER_FLAG_SEND_LARGE_COMMUNITY))
8759 vty_out(vty, "(all)\n");
8760 else if (CHECK_FLAG(p->af_flags[afi][safi],
8761 PEER_FLAG_SEND_LARGE_COMMUNITY))
8762 vty_out(vty, "(large)\n");
8763 else if (CHECK_FLAG(p->af_flags[afi][safi],
8764 PEER_FLAG_SEND_EXT_COMMUNITY))
8765 vty_out(vty, "(extended)\n");
8766 else
8767 vty_out(vty, "(standard)\n");
8768 }
8769 if (CHECK_FLAG(p->af_flags[afi][safi],
8770 PEER_FLAG_DEFAULT_ORIGINATE)) {
8771 vty_out(vty, " Default information originate,");
8772
8773 if (p->default_rmap[afi][safi].name)
8774 vty_out(vty, " default route-map %s%s,",
8775 p->default_rmap[afi][safi].map ? "*"
8776 : "",
8777 p->default_rmap[afi][safi].name);
8778 if (paf && PAF_SUBGRP(paf)
8779 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8780 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8781 vty_out(vty, " default sent\n");
8782 else
8783 vty_out(vty, " default not sent\n");
8784 }
8785
dff8f48d
MK
8786 /* advertise-vni-all */
8787 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8788 if (is_evpn_enabled())
dff8f48d
MK
8789 vty_out(vty, " advertise-all-vni\n");
8790 }
8791
d62a17ae 8792 if (filter->plist[FILTER_IN].name
8793 || filter->dlist[FILTER_IN].name
8794 || filter->aslist[FILTER_IN].name
8795 || filter->map[RMAP_IN].name)
8796 vty_out(vty, " Inbound path policy configured\n");
8797 if (filter->plist[FILTER_OUT].name
8798 || filter->dlist[FILTER_OUT].name
8799 || filter->aslist[FILTER_OUT].name
8800 || filter->map[RMAP_OUT].name || filter->usmap.name)
8801 vty_out(vty, " Outbound path policy configured\n");
8802
8803 /* prefix-list */
8804 if (filter->plist[FILTER_IN].name)
8805 vty_out(vty,
8806 " Incoming update prefix filter list is %s%s\n",
8807 filter->plist[FILTER_IN].plist ? "*" : "",
8808 filter->plist[FILTER_IN].name);
8809 if (filter->plist[FILTER_OUT].name)
8810 vty_out(vty,
8811 " Outgoing update prefix filter list is %s%s\n",
8812 filter->plist[FILTER_OUT].plist ? "*" : "",
8813 filter->plist[FILTER_OUT].name);
8814
8815 /* distribute-list */
8816 if (filter->dlist[FILTER_IN].name)
8817 vty_out(vty,
8818 " Incoming update network filter list is %s%s\n",
8819 filter->dlist[FILTER_IN].alist ? "*" : "",
8820 filter->dlist[FILTER_IN].name);
8821 if (filter->dlist[FILTER_OUT].name)
8822 vty_out(vty,
8823 " Outgoing update network filter list is %s%s\n",
8824 filter->dlist[FILTER_OUT].alist ? "*" : "",
8825 filter->dlist[FILTER_OUT].name);
8826
8827 /* filter-list. */
8828 if (filter->aslist[FILTER_IN].name)
8829 vty_out(vty,
8830 " Incoming update AS path filter list is %s%s\n",
8831 filter->aslist[FILTER_IN].aslist ? "*" : "",
8832 filter->aslist[FILTER_IN].name);
8833 if (filter->aslist[FILTER_OUT].name)
8834 vty_out(vty,
8835 " Outgoing update AS path filter list is %s%s\n",
8836 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8837 filter->aslist[FILTER_OUT].name);
8838
8839 /* route-map. */
8840 if (filter->map[RMAP_IN].name)
8841 vty_out(vty,
8842 " Route map for incoming advertisements is %s%s\n",
8843 filter->map[RMAP_IN].map ? "*" : "",
8844 filter->map[RMAP_IN].name);
8845 if (filter->map[RMAP_OUT].name)
8846 vty_out(vty,
8847 " Route map for outgoing advertisements is %s%s\n",
8848 filter->map[RMAP_OUT].map ? "*" : "",
8849 filter->map[RMAP_OUT].name);
8850
8851 /* unsuppress-map */
8852 if (filter->usmap.name)
8853 vty_out(vty,
8854 " Route map for selective unsuppress is %s%s\n",
8855 filter->usmap.map ? "*" : "",
8856 filter->usmap.name);
8857
8858 /* Receive prefix count */
8859 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8860
8861 /* Maximum prefix */
8862 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8863 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8864 p->pmax[afi][safi],
8865 CHECK_FLAG(p->af_flags[afi][safi],
8866 PEER_FLAG_MAX_PREFIX_WARNING)
8867 ? " (warning-only)"
8868 : "");
8869 vty_out(vty, " Threshold for warning message %d%%",
8870 p->pmax_threshold[afi][safi]);
8871 if (p->pmax_restart[afi][safi])
8872 vty_out(vty, ", restart interval %d min",
8873 p->pmax_restart[afi][safi]);
8874 vty_out(vty, "\n");
8875 }
8876
8877 vty_out(vty, "\n");
8878 }
8879}
8880
d7c0a89a 8881static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
d62a17ae 8882 json_object *json)
718e3744 8883{
d62a17ae 8884 struct bgp *bgp;
8885 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8886 char timebuf[BGP_UPTIME_LEN];
8887 char dn_flag[2];
8888 const char *subcode_str;
8889 const char *code_str;
8890 afi_t afi;
8891 safi_t safi;
d7c0a89a
QY
8892 uint16_t i;
8893 uint8_t *msg;
d62a17ae 8894 json_object *json_neigh = NULL;
8895 time_t epoch_tbuf;
718e3744 8896
d62a17ae 8897 bgp = p->bgp;
8898
8899 if (use_json)
8900 json_neigh = json_object_new_object();
8901
8902 memset(dn_flag, '\0', sizeof(dn_flag));
8903 if (!p->conf_if && peer_dynamic_neighbor(p))
8904 dn_flag[0] = '*';
8905
8906 if (!use_json) {
8907 if (p->conf_if) /* Configured interface name. */
8908 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8909 BGP_PEER_SU_UNSPEC(p)
8910 ? "None"
8911 : sockunion2str(&p->su, buf,
8912 SU_ADDRSTRLEN));
8913 else /* Configured IP address. */
8914 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8915 p->host);
8916 }
8917
8918 if (use_json) {
8919 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8920 json_object_string_add(json_neigh, "bgpNeighborAddr",
8921 "none");
8922 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8923 json_object_string_add(
8924 json_neigh, "bgpNeighborAddr",
8925 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8926
8927 json_object_int_add(json_neigh, "remoteAs", p->as);
8928
8929 if (p->change_local_as)
8930 json_object_int_add(json_neigh, "localAs",
8931 p->change_local_as);
8932 else
8933 json_object_int_add(json_neigh, "localAs", p->local_as);
8934
8935 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8936 json_object_boolean_true_add(json_neigh,
8937 "localAsNoPrepend");
8938
8939 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8940 json_object_boolean_true_add(json_neigh,
8941 "localAsReplaceAs");
8942 } else {
8943 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8944 || (p->as_type == AS_INTERNAL))
8945 vty_out(vty, "remote AS %u, ", p->as);
8946 else
8947 vty_out(vty, "remote AS Unspecified, ");
8948 vty_out(vty, "local AS %u%s%s, ",
8949 p->change_local_as ? p->change_local_as : p->local_as,
8950 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8951 ? " no-prepend"
8952 : "",
8953 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8954 ? " replace-as"
8955 : "");
8956 }
8957 /* peer type internal, external, confed-internal or confed-external */
8958 if (p->as == p->local_as) {
8959 if (use_json) {
8960 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8961 json_object_boolean_true_add(
8962 json_neigh, "nbrConfedInternalLink");
8963 else
8964 json_object_boolean_true_add(json_neigh,
8965 "nbrInternalLink");
8966 } else {
8967 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8968 vty_out(vty, "confed-internal link\n");
8969 else
8970 vty_out(vty, "internal link\n");
8971 }
8972 } else {
8973 if (use_json) {
8974 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8975 json_object_boolean_true_add(
8976 json_neigh, "nbrConfedExternalLink");
8977 else
8978 json_object_boolean_true_add(json_neigh,
8979 "nbrExternalLink");
8980 } else {
8981 if (bgp_confederation_peers_check(bgp, p->as))
8982 vty_out(vty, "confed-external link\n");
8983 else
8984 vty_out(vty, "external link\n");
8985 }
8986 }
8987
8988 /* Description. */
8989 if (p->desc) {
8990 if (use_json)
8991 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8992 else
8993 vty_out(vty, " Description: %s\n", p->desc);
8994 }
8995
8996 if (p->hostname) {
8997 if (use_json) {
8998 if (p->hostname)
8999 json_object_string_add(json_neigh, "hostname",
9000 p->hostname);
9001
9002 if (p->domainname)
9003 json_object_string_add(json_neigh, "domainname",
9004 p->domainname);
9005 } else {
9006 if (p->domainname && (p->domainname[0] != '\0'))
9007 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9008 p->domainname);
9009 else
9010 vty_out(vty, "Hostname: %s\n", p->hostname);
9011 }
9012 }
9013
9014 /* Peer-group */
9015 if (p->group) {
9016 if (use_json) {
9017 json_object_string_add(json_neigh, "peerGroup",
9018 p->group->name);
9019
9020 if (dn_flag[0]) {
9021 struct prefix prefix, *range = NULL;
9022
9023 sockunion2hostprefix(&(p->su), &prefix);
9024 range = peer_group_lookup_dynamic_neighbor_range(
9025 p->group, &prefix);
9026
9027 if (range) {
9028 prefix2str(range, buf1, sizeof(buf1));
9029 json_object_string_add(
9030 json_neigh,
9031 "peerSubnetRangeGroup", buf1);
9032 }
9033 }
9034 } else {
9035 vty_out(vty,
9036 " Member of peer-group %s for session parameters\n",
9037 p->group->name);
9038
9039 if (dn_flag[0]) {
9040 struct prefix prefix, *range = NULL;
9041
9042 sockunion2hostprefix(&(p->su), &prefix);
9043 range = peer_group_lookup_dynamic_neighbor_range(
9044 p->group, &prefix);
9045
9046 if (range) {
9047 prefix2str(range, buf1, sizeof(buf1));
9048 vty_out(vty,
9049 " Belongs to the subnet range group: %s\n",
9050 buf1);
9051 }
9052 }
9053 }
9054 }
9055
9056 if (use_json) {
9057 /* Administrative shutdown. */
9058 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9059 json_object_boolean_true_add(json_neigh,
9060 "adminShutDown");
9061
9062 /* BGP Version. */
9063 json_object_int_add(json_neigh, "bgpVersion", 4);
9064 json_object_string_add(
9065 json_neigh, "remoteRouterId",
9066 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9067
9068 /* Confederation */
9069 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9070 && bgp_confederation_peers_check(bgp, p->as))
9071 json_object_boolean_true_add(json_neigh,
9072 "nbrCommonAdmin");
9073
9074 /* Status. */
9075 json_object_string_add(
9076 json_neigh, "bgpState",
9077 lookup_msg(bgp_status_msg, p->status, NULL));
9078
9079 if (p->status == Established) {
9080 time_t uptime;
d62a17ae 9081
9082 uptime = bgp_clock();
9083 uptime -= p->uptime;
d62a17ae 9084 epoch_tbuf = time(NULL) - uptime;
9085
e24be241 9086#if defined(VERSION_TYPE_DEV) && CONFDATE > 20200101
a4d82a8a
PZ
9087 CPP_NOTICE(
9088 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9089#endif
9090 /*
9091 * bgpTimerUp was miliseconds that was accurate
9092 * up to 1 day, then the value returned
9093 * became garbage. So in order to provide
9094 * some level of backwards compatability,
9095 * we still provde the data, but now
9096 * we are returning the correct value
9097 * and also adding a new bgpTimerUpMsec
9098 * which will allow us to deprecate
9099 * this eventually
9100 */
d62a17ae 9101 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9102 uptime * 1000);
d3c7efed
DS
9103 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9104 uptime * 1000);
d62a17ae 9105 json_object_string_add(json_neigh, "bgpTimerUpString",
9106 peer_uptime(p->uptime, timebuf,
9107 BGP_UPTIME_LEN, 0,
9108 NULL));
9109 json_object_int_add(json_neigh,
9110 "bgpTimerUpEstablishedEpoch",
9111 epoch_tbuf);
9112 }
9113
9114 else if (p->status == Active) {
9115 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9116 json_object_string_add(json_neigh, "bgpStateIs",
9117 "passive");
9118 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9119 json_object_string_add(json_neigh, "bgpStateIs",
9120 "passiveNSF");
9121 }
9122
9123 /* read timer */
9124 time_t uptime;
9125 struct tm *tm;
9126
9127 uptime = bgp_clock();
9128 uptime -= p->readtime;
9129 tm = gmtime(&uptime);
9130 json_object_int_add(json_neigh, "bgpTimerLastRead",
9131 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9132 + (tm->tm_hour * 3600000));
9133
9134 uptime = bgp_clock();
9135 uptime -= p->last_write;
9136 tm = gmtime(&uptime);
9137 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9138 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9139 + (tm->tm_hour * 3600000));
9140
9141 uptime = bgp_clock();
9142 uptime -= p->update_time;
9143 tm = gmtime(&uptime);
9144 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9145 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9146 + (tm->tm_hour * 3600000));
9147
9148 /* Configured timer values. */
9149 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9150 p->v_holdtime * 1000);
9151 json_object_int_add(json_neigh,
9152 "bgpTimerKeepAliveIntervalMsecs",
9153 p->v_keepalive * 1000);
9154
d25e4efc 9155 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 9156 json_object_int_add(json_neigh,
9157 "bgpTimerConfiguredHoldTimeMsecs",
9158 p->holdtime * 1000);
9159 json_object_int_add(
9160 json_neigh,
9161 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9162 p->keepalive * 1000);
d25e4efc 9163 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9164 || (bgp->default_keepalive
9165 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9166 json_object_int_add(json_neigh,
9167 "bgpTimerConfiguredHoldTimeMsecs",
9168 bgp->default_holdtime);
9169 json_object_int_add(
9170 json_neigh,
9171 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9172 bgp->default_keepalive);
d62a17ae 9173 }
9174 } else {
9175 /* Administrative shutdown. */
9176 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9177 vty_out(vty, " Administratively shut down\n");
9178
9179 /* BGP Version. */
9180 vty_out(vty, " BGP version 4");
9181 vty_out(vty, ", remote router ID %s\n",
9182 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9183
9184 /* Confederation */
9185 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9186 && bgp_confederation_peers_check(bgp, p->as))
9187 vty_out(vty,
9188 " Neighbor under common administration\n");
9189
9190 /* Status. */
9191 vty_out(vty, " BGP state = %s",
9192 lookup_msg(bgp_status_msg, p->status, NULL));
9193
9194 if (p->status == Established)
9195 vty_out(vty, ", up for %8s",
9196 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9197 0, NULL));
9198
9199 else if (p->status == Active) {
9200 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9201 vty_out(vty, " (passive)");
9202 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9203 vty_out(vty, " (NSF passive)");
9204 }
9205 vty_out(vty, "\n");
9206
9207 /* read timer */
9208 vty_out(vty, " Last read %s",
9209 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9210 NULL));
9211 vty_out(vty, ", Last write %s\n",
9212 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9213 NULL));
9214
9215 /* Configured timer values. */
9216 vty_out(vty,
9217 " Hold time is %d, keepalive interval is %d seconds\n",
9218 p->v_holdtime, p->v_keepalive);
d25e4efc 9219 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 9220 vty_out(vty, " Configured hold time is %d",
9221 p->holdtime);
9222 vty_out(vty, ", keepalive interval is %d seconds\n",
9223 p->keepalive);
d25e4efc 9224 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9225 || (bgp->default_keepalive
9226 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9227 vty_out(vty, " Configured hold time is %d",
9228 bgp->default_holdtime);
9229 vty_out(vty, ", keepalive interval is %d seconds\n",
9230 bgp->default_keepalive);
d62a17ae 9231 }
9232 }
9233 /* Capability. */
9234 if (p->status == Established) {
9235 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9236 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9237 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9238 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9239 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9240 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9241 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9242 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9243 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9244 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9245 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9246 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9247 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9248 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9249 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9250 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9251 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9252 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9253 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9254 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9255 if (use_json) {
9256 json_object *json_cap = NULL;
9257
9258 json_cap = json_object_new_object();
9259
9260 /* AS4 */
9261 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9262 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9263 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9264 && CHECK_FLAG(p->cap,
9265 PEER_CAP_AS4_RCV))
9266 json_object_string_add(
9267 json_cap, "4byteAs",
9268 "advertisedAndReceived");
9269 else if (CHECK_FLAG(p->cap,
9270 PEER_CAP_AS4_ADV))
9271 json_object_string_add(
9272 json_cap, "4byteAs",
9273 "advertised");
9274 else if (CHECK_FLAG(p->cap,
9275 PEER_CAP_AS4_RCV))
9276 json_object_string_add(
9277 json_cap, "4byteAs",
9278 "received");
9279 }
9280
9281 /* AddPath */
9282 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9283 || CHECK_FLAG(p->cap,
9284 PEER_CAP_ADDPATH_ADV)) {
9285 json_object *json_add = NULL;
9286 const char *print_store;
9287
9288 json_add = json_object_new_object();
9289
05c7a1cc
QY
9290 FOREACH_AFI_SAFI (afi, safi) {
9291 json_object *json_sub = NULL;
9292 json_sub =
9293 json_object_new_object();
9294 print_store = afi_safi_print(
9295 afi, safi);
d62a17ae 9296
05c7a1cc
QY
9297 if (CHECK_FLAG(
9298 p->af_cap[afi]
9299 [safi],
9300 PEER_CAP_ADDPATH_AF_TX_ADV)
9301 || CHECK_FLAG(
9302 p->af_cap[afi]
9303 [safi],
9304 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9305 if (CHECK_FLAG(
9306 p->af_cap
9307 [afi]
9308 [safi],
9309 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9310 && CHECK_FLAG(
d62a17ae 9311 p->af_cap
9312 [afi]
9313 [safi],
05c7a1cc
QY
9314 PEER_CAP_ADDPATH_AF_TX_RCV))
9315 json_object_boolean_true_add(
9316 json_sub,
9317 "txAdvertisedAndReceived");
9318 else if (
9319 CHECK_FLAG(
9320 p->af_cap
9321 [afi]
9322 [safi],
9323 PEER_CAP_ADDPATH_AF_TX_ADV))
9324 json_object_boolean_true_add(
9325 json_sub,
9326 "txAdvertised");
9327 else if (
9328 CHECK_FLAG(
9329 p->af_cap
9330 [afi]
9331 [safi],
9332 PEER_CAP_ADDPATH_AF_TX_RCV))
9333 json_object_boolean_true_add(
9334 json_sub,
9335 "txReceived");
9336 }
d62a17ae 9337
05c7a1cc
QY
9338 if (CHECK_FLAG(
9339 p->af_cap[afi]
9340 [safi],
9341 PEER_CAP_ADDPATH_AF_RX_ADV)
9342 || CHECK_FLAG(
9343 p->af_cap[afi]
9344 [safi],
9345 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9346 if (CHECK_FLAG(
9347 p->af_cap
9348 [afi]
9349 [safi],
9350 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9351 && CHECK_FLAG(
d62a17ae 9352 p->af_cap
9353 [afi]
9354 [safi],
9355 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9356 json_object_boolean_true_add(
9357 json_sub,
9358 "rxAdvertisedAndReceived");
9359 else if (
9360 CHECK_FLAG(
9361 p->af_cap
9362 [afi]
9363 [safi],
9364 PEER_CAP_ADDPATH_AF_RX_ADV))
9365 json_object_boolean_true_add(
9366 json_sub,
9367 "rxAdvertised");
9368 else if (
9369 CHECK_FLAG(
9370 p->af_cap
9371 [afi]
9372 [safi],
9373 PEER_CAP_ADDPATH_AF_RX_RCV))
9374 json_object_boolean_true_add(
9375 json_sub,
9376 "rxReceived");
d62a17ae 9377 }
9378
05c7a1cc
QY
9379 if (CHECK_FLAG(
9380 p->af_cap[afi]
9381 [safi],
9382 PEER_CAP_ADDPATH_AF_TX_ADV)
9383 || CHECK_FLAG(
9384 p->af_cap[afi]
9385 [safi],
9386 PEER_CAP_ADDPATH_AF_TX_RCV)
9387 || CHECK_FLAG(
9388 p->af_cap[afi]
9389 [safi],
9390 PEER_CAP_ADDPATH_AF_RX_ADV)
9391 || CHECK_FLAG(
9392 p->af_cap[afi]
9393 [safi],
9394 PEER_CAP_ADDPATH_AF_RX_RCV))
9395 json_object_object_add(
9396 json_add,
9397 print_store,
9398 json_sub);
9399 else
9400 json_object_free(
9401 json_sub);
9402 }
9403
d62a17ae 9404 json_object_object_add(
9405 json_cap, "addPath", json_add);
9406 }
9407
9408 /* Dynamic */
9409 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9410 || CHECK_FLAG(p->cap,
9411 PEER_CAP_DYNAMIC_ADV)) {
9412 if (CHECK_FLAG(p->cap,
9413 PEER_CAP_DYNAMIC_ADV)
9414 && CHECK_FLAG(p->cap,
9415 PEER_CAP_DYNAMIC_RCV))
9416 json_object_string_add(
9417 json_cap, "dynamic",
9418 "advertisedAndReceived");
9419 else if (CHECK_FLAG(
9420 p->cap,
9421 PEER_CAP_DYNAMIC_ADV))
9422 json_object_string_add(
9423 json_cap, "dynamic",
9424 "advertised");
9425 else if (CHECK_FLAG(
9426 p->cap,
9427 PEER_CAP_DYNAMIC_RCV))
9428 json_object_string_add(
9429 json_cap, "dynamic",
9430 "received");
9431 }
9432
9433 /* Extended nexthop */
9434 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9435 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9436 json_object *json_nxt = NULL;
9437 const char *print_store;
9438
9439
9440 if (CHECK_FLAG(p->cap,
9441 PEER_CAP_ENHE_ADV)
9442 && CHECK_FLAG(p->cap,
9443 PEER_CAP_ENHE_RCV))
9444 json_object_string_add(
9445 json_cap,
9446 "extendedNexthop",
9447 "advertisedAndReceived");
9448 else if (CHECK_FLAG(p->cap,
9449 PEER_CAP_ENHE_ADV))
9450 json_object_string_add(
9451 json_cap,
9452 "extendedNexthop",
9453 "advertised");
9454 else if (CHECK_FLAG(p->cap,
9455 PEER_CAP_ENHE_RCV))
9456 json_object_string_add(
9457 json_cap,
9458 "extendedNexthop",
9459 "received");
9460
9461 if (CHECK_FLAG(p->cap,
9462 PEER_CAP_ENHE_RCV)) {
9463 json_nxt =
9464 json_object_new_object();
9465
9466 for (safi = SAFI_UNICAST;
9467 safi < SAFI_MAX; safi++) {
9468 if (CHECK_FLAG(
9469 p->af_cap
9470 [AFI_IP]
9471 [safi],
9472 PEER_CAP_ENHE_AF_RCV)) {
9473 print_store = afi_safi_print(
9474 AFI_IP,
9475 safi);
9476 json_object_string_add(
9477 json_nxt,
9478 print_store,
9479 "recieved");
9480 }
9481 }
9482 json_object_object_add(
9483 json_cap,
9484 "extendedNexthopFamililesByPeer",
9485 json_nxt);
9486 }
9487 }
9488
9489 /* Route Refresh */
9490 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9491 || CHECK_FLAG(p->cap,
9492 PEER_CAP_REFRESH_NEW_RCV)
9493 || CHECK_FLAG(p->cap,
9494 PEER_CAP_REFRESH_OLD_RCV)) {
9495 if (CHECK_FLAG(p->cap,
9496 PEER_CAP_REFRESH_ADV)
9497 && (CHECK_FLAG(
9498 p->cap,
9499 PEER_CAP_REFRESH_NEW_RCV)
9500 || CHECK_FLAG(
9501 p->cap,
9502 PEER_CAP_REFRESH_OLD_RCV))) {
9503 if (CHECK_FLAG(
9504 p->cap,
9505 PEER_CAP_REFRESH_OLD_RCV)
9506 && CHECK_FLAG(
9507 p->cap,
9508 PEER_CAP_REFRESH_NEW_RCV))
9509 json_object_string_add(
9510 json_cap,
9511 "routeRefresh",
9512 "advertisedAndReceivedOldNew");
9513 else {
9514 if (CHECK_FLAG(
9515 p->cap,
9516 PEER_CAP_REFRESH_OLD_RCV))
9517 json_object_string_add(
9518 json_cap,
9519 "routeRefresh",
9520 "advertisedAndReceivedOld");
9521 else
9522 json_object_string_add(
9523 json_cap,
9524 "routeRefresh",
9525 "advertisedAndReceivedNew");
9526 }
9527 } else if (
9528 CHECK_FLAG(
9529 p->cap,
9530 PEER_CAP_REFRESH_ADV))
9531 json_object_string_add(
9532 json_cap,
9533 "routeRefresh",
9534 "advertised");
9535 else if (
9536 CHECK_FLAG(
9537 p->cap,
9538 PEER_CAP_REFRESH_NEW_RCV)
9539 || CHECK_FLAG(
9540 p->cap,
9541 PEER_CAP_REFRESH_OLD_RCV))
9542 json_object_string_add(
9543 json_cap,
9544 "routeRefresh",
9545 "received");
9546 }
9547
9548 /* Multiprotocol Extensions */
9549 json_object *json_multi = NULL;
9550 json_multi = json_object_new_object();
9551
05c7a1cc
QY
9552 FOREACH_AFI_SAFI (afi, safi) {
9553 if (p->afc_adv[afi][safi]
9554 || p->afc_recv[afi][safi]) {
9555 json_object *json_exten = NULL;
9556 json_exten =
9557 json_object_new_object();
9558
d62a17ae 9559 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9560 && p->afc_recv[afi][safi])
9561 json_object_boolean_true_add(
9562 json_exten,
9563 "advertisedAndReceived");
9564 else if (p->afc_adv[afi][safi])
9565 json_object_boolean_true_add(
9566 json_exten,
9567 "advertised");
9568 else if (p->afc_recv[afi][safi])
9569 json_object_boolean_true_add(
9570 json_exten,
9571 "received");
d62a17ae 9572
05c7a1cc
QY
9573 json_object_object_add(
9574 json_multi,
9575 afi_safi_print(afi,
9576 safi),
9577 json_exten);
d62a17ae 9578 }
9579 }
9580 json_object_object_add(
9581 json_cap, "multiprotocolExtensions",
9582 json_multi);
9583
d77114b7 9584 /* Hostname capabilities */
60466a63 9585 json_object *json_hname = NULL;
d77114b7
MK
9586
9587 json_hname = json_object_new_object();
9588
9589 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9590 json_object_string_add(
60466a63
QY
9591 json_hname, "advHostName",
9592 bgp->peer_self->hostname
9593 ? bgp->peer_self
9594 ->hostname
d77114b7
MK
9595 : "n/a");
9596 json_object_string_add(
60466a63
QY
9597 json_hname, "advDomainName",
9598 bgp->peer_self->domainname
9599 ? bgp->peer_self
9600 ->domainname
d77114b7
MK
9601 : "n/a");
9602 }
9603
9604
9605 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9606 json_object_string_add(
60466a63
QY
9607 json_hname, "rcvHostName",
9608 p->hostname ? p->hostname
9609 : "n/a");
d77114b7 9610 json_object_string_add(
60466a63
QY
9611 json_hname, "rcvDomainName",
9612 p->domainname ? p->domainname
9613 : "n/a");
d77114b7
MK
9614 }
9615
60466a63 9616 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9617 json_hname);
9618
d62a17ae 9619 /* Gracefull Restart */
9620 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9621 || CHECK_FLAG(p->cap,
9622 PEER_CAP_RESTART_ADV)) {
9623 if (CHECK_FLAG(p->cap,
9624 PEER_CAP_RESTART_ADV)
9625 && CHECK_FLAG(p->cap,
9626 PEER_CAP_RESTART_RCV))
9627 json_object_string_add(
9628 json_cap,
9629 "gracefulRestart",
9630 "advertisedAndReceived");
9631 else if (CHECK_FLAG(
9632 p->cap,
9633 PEER_CAP_RESTART_ADV))
9634 json_object_string_add(
9635 json_cap,
9636 "gracefulRestartCapability",
9637 "advertised");
9638 else if (CHECK_FLAG(
9639 p->cap,
9640 PEER_CAP_RESTART_RCV))
9641 json_object_string_add(
9642 json_cap,
9643 "gracefulRestartCapability",
9644 "received");
9645
9646 if (CHECK_FLAG(p->cap,
9647 PEER_CAP_RESTART_RCV)) {
9648 int restart_af_count = 0;
9649 json_object *json_restart =
9650 NULL;
9651 json_restart =
9652 json_object_new_object();
9653
9654 json_object_int_add(
9655 json_cap,
9656 "gracefulRestartRemoteTimerMsecs",
9657 p->v_gr_restart * 1000);
9658
05c7a1cc
QY
9659 FOREACH_AFI_SAFI (afi, safi) {
9660 if (CHECK_FLAG(
9661 p->af_cap
9662 [afi]
9663 [safi],
9664 PEER_CAP_RESTART_AF_RCV)) {
9665 json_object *
9666 json_sub =
9667 NULL;
9668 json_sub =
9669 json_object_new_object();
9670
d62a17ae 9671 if (CHECK_FLAG(
9672 p->af_cap
9673 [afi]
9674 [safi],
05c7a1cc
QY
9675 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9676 json_object_boolean_true_add(
9677 json_sub,
9678 "preserved");
9679 restart_af_count++;
9680 json_object_object_add(
9681 json_restart,
9682 afi_safi_print(
9683 afi,
9684 safi),
9685 json_sub);
d62a17ae 9686 }
9687 }
9688 if (!restart_af_count) {
9689 json_object_string_add(
9690 json_cap,
9691 "addressFamiliesByPeer",
9692 "none");
9693 json_object_free(
9694 json_restart);
9695 } else
9696 json_object_object_add(
9697 json_cap,
9698 "addressFamiliesByPeer",
9699 json_restart);
9700 }
9701 }
9702 json_object_object_add(json_neigh,
9703 "neighborCapabilities",
9704 json_cap);
9705 } else {
9706 vty_out(vty, " Neighbor capabilities:\n");
9707
9708 /* AS4 */
9709 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9710 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9711 vty_out(vty, " 4 Byte AS:");
9712 if (CHECK_FLAG(p->cap,
9713 PEER_CAP_AS4_ADV))
9714 vty_out(vty, " advertised");
9715 if (CHECK_FLAG(p->cap,
9716 PEER_CAP_AS4_RCV))
9717 vty_out(vty, " %sreceived",
9718 CHECK_FLAG(
9719 p->cap,
9720 PEER_CAP_AS4_ADV)
9721 ? "and "
9722 : "");
9723 vty_out(vty, "\n");
9724 }
9725
9726 /* AddPath */
9727 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9728 || CHECK_FLAG(p->cap,
9729 PEER_CAP_ADDPATH_ADV)) {
9730 vty_out(vty, " AddPath:\n");
9731
05c7a1cc
QY
9732 FOREACH_AFI_SAFI (afi, safi) {
9733 if (CHECK_FLAG(
9734 p->af_cap[afi]
9735 [safi],
9736 PEER_CAP_ADDPATH_AF_TX_ADV)
9737 || CHECK_FLAG(
9738 p->af_cap[afi]
9739 [safi],
9740 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9741 vty_out(vty,
9742 " %s: TX ",
9743 afi_safi_print(
9744 afi,
9745 safi));
9746
d62a17ae 9747 if (CHECK_FLAG(
9748 p->af_cap
9749 [afi]
9750 [safi],
05c7a1cc 9751 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 9752 vty_out(vty,
05c7a1cc 9753 "advertised %s",
d62a17ae 9754 afi_safi_print(
9755 afi,
9756 safi));
9757
05c7a1cc
QY
9758 if (CHECK_FLAG(
9759 p->af_cap
9760 [afi]
9761 [safi],
9762 PEER_CAP_ADDPATH_AF_TX_RCV))
9763 vty_out(vty,
9764 "%sreceived",
9765 CHECK_FLAG(
9766 p->af_cap
9767 [afi]
9768 [safi],
9769 PEER_CAP_ADDPATH_AF_TX_ADV)
9770 ? " and "
9771 : "");
d62a17ae 9772
05c7a1cc
QY
9773 vty_out(vty, "\n");
9774 }
d62a17ae 9775
05c7a1cc
QY
9776 if (CHECK_FLAG(
9777 p->af_cap[afi]
9778 [safi],
9779 PEER_CAP_ADDPATH_AF_RX_ADV)
9780 || CHECK_FLAG(
9781 p->af_cap[afi]
9782 [safi],
9783 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9784 vty_out(vty,
9785 " %s: RX ",
9786 afi_safi_print(
9787 afi,
9788 safi));
d62a17ae 9789
9790 if (CHECK_FLAG(
9791 p->af_cap
9792 [afi]
9793 [safi],
05c7a1cc 9794 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 9795 vty_out(vty,
05c7a1cc 9796 "advertised %s",
d62a17ae 9797 afi_safi_print(
9798 afi,
9799 safi));
9800
05c7a1cc
QY
9801 if (CHECK_FLAG(
9802 p->af_cap
9803 [afi]
9804 [safi],
9805 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 9806 vty_out(vty,
05c7a1cc
QY
9807 "%sreceived",
9808 CHECK_FLAG(
9809 p->af_cap
9810 [afi]
9811 [safi],
9812 PEER_CAP_ADDPATH_AF_RX_ADV)
9813 ? " and "
9814 : "");
9815
9816 vty_out(vty, "\n");
d62a17ae 9817 }
05c7a1cc 9818 }
d62a17ae 9819 }
9820
9821 /* Dynamic */
9822 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9823 || CHECK_FLAG(p->cap,
9824 PEER_CAP_DYNAMIC_ADV)) {
9825 vty_out(vty, " Dynamic:");
9826 if (CHECK_FLAG(p->cap,
9827 PEER_CAP_DYNAMIC_ADV))
9828 vty_out(vty, " advertised");
9829 if (CHECK_FLAG(p->cap,
9830 PEER_CAP_DYNAMIC_RCV))
9831 vty_out(vty, " %sreceived",
9832 CHECK_FLAG(
9833 p->cap,
9834 PEER_CAP_DYNAMIC_ADV)
9835 ? "and "
9836 : "");
9837 vty_out(vty, "\n");
9838 }
9839
9840 /* Extended nexthop */
9841 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9842 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9843 vty_out(vty, " Extended nexthop:");
9844 if (CHECK_FLAG(p->cap,
9845 PEER_CAP_ENHE_ADV))
9846 vty_out(vty, " advertised");
9847 if (CHECK_FLAG(p->cap,
9848 PEER_CAP_ENHE_RCV))
9849 vty_out(vty, " %sreceived",
9850 CHECK_FLAG(
9851 p->cap,
9852 PEER_CAP_ENHE_ADV)
9853 ? "and "
9854 : "");
9855 vty_out(vty, "\n");
9856
9857 if (CHECK_FLAG(p->cap,
9858 PEER_CAP_ENHE_RCV)) {
9859 vty_out(vty,
9860 " Address families by peer:\n ");
9861 for (safi = SAFI_UNICAST;
9862 safi < SAFI_MAX; safi++)
9863 if (CHECK_FLAG(
9864 p->af_cap
9865 [AFI_IP]
9866 [safi],
9867 PEER_CAP_ENHE_AF_RCV))
9868 vty_out(vty,
9869 " %s\n",
9870 afi_safi_print(
9871 AFI_IP,
9872 safi));
9873 }
9874 }
9875
9876 /* Route Refresh */
9877 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9878 || CHECK_FLAG(p->cap,
9879 PEER_CAP_REFRESH_NEW_RCV)
9880 || CHECK_FLAG(p->cap,
9881 PEER_CAP_REFRESH_OLD_RCV)) {
9882 vty_out(vty, " Route refresh:");
9883 if (CHECK_FLAG(p->cap,
9884 PEER_CAP_REFRESH_ADV))
9885 vty_out(vty, " advertised");
9886 if (CHECK_FLAG(p->cap,
9887 PEER_CAP_REFRESH_NEW_RCV)
9888 || CHECK_FLAG(
9889 p->cap,
9890 PEER_CAP_REFRESH_OLD_RCV))
9891 vty_out(vty, " %sreceived(%s)",
9892 CHECK_FLAG(
9893 p->cap,
9894 PEER_CAP_REFRESH_ADV)
9895 ? "and "
9896 : "",
9897 (CHECK_FLAG(
9898 p->cap,
9899 PEER_CAP_REFRESH_OLD_RCV)
9900 && CHECK_FLAG(
9901 p->cap,
9902 PEER_CAP_REFRESH_NEW_RCV))
9903 ? "old & new"
9904 : CHECK_FLAG(
9905 p->cap,
9906 PEER_CAP_REFRESH_OLD_RCV)
9907 ? "old"
9908 : "new");
9909
9910 vty_out(vty, "\n");
9911 }
9912
9913 /* Multiprotocol Extensions */
05c7a1cc
QY
9914 FOREACH_AFI_SAFI (afi, safi)
9915 if (p->afc_adv[afi][safi]
9916 || p->afc_recv[afi][safi]) {
9917 vty_out(vty,
9918 " Address Family %s:",
9919 afi_safi_print(afi,
9920 safi));
9921 if (p->afc_adv[afi][safi])
d62a17ae 9922 vty_out(vty,
05c7a1cc
QY
9923 " advertised");
9924 if (p->afc_recv[afi][safi])
9925 vty_out(vty,
9926 " %sreceived",
9927 p->afc_adv[afi]
9928 [safi]
9929 ? "and "
9930 : "");
9931 vty_out(vty, "\n");
9932 }
d62a17ae 9933
9934 /* Hostname capability */
60466a63 9935 vty_out(vty, " Hostname Capability:");
d77114b7
MK
9936
9937 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
9938 vty_out(vty,
9939 " advertised (name: %s,domain name: %s)",
60466a63
QY
9940 bgp->peer_self->hostname
9941 ? bgp->peer_self
9942 ->hostname
d77114b7 9943 : "n/a",
60466a63
QY
9944 bgp->peer_self->domainname
9945 ? bgp->peer_self
9946 ->domainname
d77114b7
MK
9947 : "n/a");
9948 } else {
9949 vty_out(vty, " not advertised");
d62a17ae 9950 }
9951
d77114b7 9952 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
9953 vty_out(vty,
9954 " received (name: %s,domain name: %s)",
60466a63
QY
9955 p->hostname ? p->hostname
9956 : "n/a",
9957 p->domainname ? p->domainname
9958 : "n/a");
d77114b7
MK
9959 } else {
9960 vty_out(vty, " not received");
9961 }
9962
9963 vty_out(vty, "\n");
9964
d62a17ae 9965 /* Gracefull Restart */
9966 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9967 || CHECK_FLAG(p->cap,
9968 PEER_CAP_RESTART_ADV)) {
9969 vty_out(vty,
9970 " Graceful Restart Capabilty:");
9971 if (CHECK_FLAG(p->cap,
9972 PEER_CAP_RESTART_ADV))
9973 vty_out(vty, " advertised");
9974 if (CHECK_FLAG(p->cap,
9975 PEER_CAP_RESTART_RCV))
9976 vty_out(vty, " %sreceived",
9977 CHECK_FLAG(
9978 p->cap,
9979 PEER_CAP_RESTART_ADV)
9980 ? "and "
9981 : "");
9982 vty_out(vty, "\n");
9983
9984 if (CHECK_FLAG(p->cap,
9985 PEER_CAP_RESTART_RCV)) {
9986 int restart_af_count = 0;
9987
9988 vty_out(vty,
9989 " Remote Restart timer is %d seconds\n",
9990 p->v_gr_restart);
9991 vty_out(vty,
9992 " Address families by peer:\n ");
9993
05c7a1cc
QY
9994 FOREACH_AFI_SAFI (afi, safi)
9995 if (CHECK_FLAG(
9996 p->af_cap
9997 [afi]
9998 [safi],
9999 PEER_CAP_RESTART_AF_RCV)) {
10000 vty_out(vty,
10001 "%s%s(%s)",
10002 restart_af_count
10003 ? ", "
10004 : "",
10005 afi_safi_print(
10006 afi,
10007 safi),
10008 CHECK_FLAG(
10009 p->af_cap
10010 [afi]
10011 [safi],
10012 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10013 ? "preserved"
10014 : "not preserved");
10015 restart_af_count++;
10016 }
d62a17ae 10017 if (!restart_af_count)
10018 vty_out(vty, "none");
10019 vty_out(vty, "\n");
10020 }
10021 }
10022 }
10023 }
10024 }
10025
10026 /* graceful restart information */
10027 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10028 || p->t_gr_stale) {
10029 json_object *json_grace = NULL;
10030 json_object *json_grace_send = NULL;
10031 json_object *json_grace_recv = NULL;
10032 int eor_send_af_count = 0;
10033 int eor_receive_af_count = 0;
10034
10035 if (use_json) {
10036 json_grace = json_object_new_object();
10037 json_grace_send = json_object_new_object();
10038 json_grace_recv = json_object_new_object();
10039
10040 if (p->status == Established) {
05c7a1cc
QY
10041 FOREACH_AFI_SAFI (afi, safi) {
10042 if (CHECK_FLAG(p->af_sflags[afi][safi],
10043 PEER_STATUS_EOR_SEND)) {
10044 json_object_boolean_true_add(
10045 json_grace_send,
10046 afi_safi_print(afi,
10047 safi));
10048 eor_send_af_count++;
d62a17ae 10049 }
10050 }
05c7a1cc
QY
10051 FOREACH_AFI_SAFI (afi, safi) {
10052 if (CHECK_FLAG(
10053 p->af_sflags[afi][safi],
10054 PEER_STATUS_EOR_RECEIVED)) {
10055 json_object_boolean_true_add(
10056 json_grace_recv,
10057 afi_safi_print(afi,
10058 safi));
10059 eor_receive_af_count++;
d62a17ae 10060 }
10061 }
10062 }
10063
10064 json_object_object_add(json_grace, "endOfRibSend",
10065 json_grace_send);
10066 json_object_object_add(json_grace, "endOfRibRecv",
10067 json_grace_recv);
10068
10069 if (p->t_gr_restart)
10070 json_object_int_add(json_grace,
10071 "gracefulRestartTimerMsecs",
10072 thread_timer_remain_second(
10073 p->t_gr_restart)
10074 * 1000);
10075
10076 if (p->t_gr_stale)
10077 json_object_int_add(
10078 json_grace,
10079 "gracefulStalepathTimerMsecs",
10080 thread_timer_remain_second(
10081 p->t_gr_stale)
10082 * 1000);
10083
10084 json_object_object_add(
10085 json_neigh, "gracefulRestartInfo", json_grace);
10086 } else {
10087 vty_out(vty, " Graceful restart informations:\n");
10088 if (p->status == Established) {
10089 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10090 FOREACH_AFI_SAFI (afi, safi) {
10091 if (CHECK_FLAG(p->af_sflags[afi][safi],
10092 PEER_STATUS_EOR_SEND)) {
10093 vty_out(vty, "%s%s",
10094 eor_send_af_count ? ", "
10095 : "",
10096 afi_safi_print(afi,
10097 safi));
10098 eor_send_af_count++;
d62a17ae 10099 }
10100 }
10101 vty_out(vty, "\n");
10102 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10103 FOREACH_AFI_SAFI (afi, safi) {
10104 if (CHECK_FLAG(
10105 p->af_sflags[afi][safi],
10106 PEER_STATUS_EOR_RECEIVED)) {
10107 vty_out(vty, "%s%s",
10108 eor_receive_af_count
10109 ? ", "
10110 : "",
10111 afi_safi_print(afi,
10112 safi));
10113 eor_receive_af_count++;
d62a17ae 10114 }
10115 }
10116 vty_out(vty, "\n");
10117 }
10118
10119 if (p->t_gr_restart)
10120 vty_out(vty,
10121 " The remaining time of restart timer is %ld\n",
10122 thread_timer_remain_second(
10123 p->t_gr_restart));
10124
10125 if (p->t_gr_stale)
10126 vty_out(vty,
10127 " The remaining time of stalepath timer is %ld\n",
10128 thread_timer_remain_second(
10129 p->t_gr_stale));
10130 }
10131 }
10132 if (use_json) {
10133 json_object *json_stat = NULL;
10134 json_stat = json_object_new_object();
10135 /* Packet counts. */
10136 json_object_int_add(json_stat, "depthInq", 0);
10137 json_object_int_add(json_stat, "depthOutq",
10138 (unsigned long)p->obuf->count);
0112e9e0
QY
10139 json_object_int_add(json_stat, "opensSent",
10140 atomic_load_explicit(&p->open_out,
10141 memory_order_relaxed));
10142 json_object_int_add(json_stat, "opensRecv",
10143 atomic_load_explicit(&p->open_in,
10144 memory_order_relaxed));
d62a17ae 10145 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10146 atomic_load_explicit(&p->notify_out,
10147 memory_order_relaxed));
d62a17ae 10148 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10149 atomic_load_explicit(&p->notify_in,
10150 memory_order_relaxed));
10151 json_object_int_add(json_stat, "updatesSent",
10152 atomic_load_explicit(&p->update_out,
10153 memory_order_relaxed));
10154 json_object_int_add(json_stat, "updatesRecv",
10155 atomic_load_explicit(&p->update_in,
10156 memory_order_relaxed));
d62a17ae 10157 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10158 atomic_load_explicit(&p->keepalive_out,
10159 memory_order_relaxed));
d62a17ae 10160 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10161 atomic_load_explicit(&p->keepalive_in,
10162 memory_order_relaxed));
d62a17ae 10163 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10164 atomic_load_explicit(&p->refresh_out,
10165 memory_order_relaxed));
d62a17ae 10166 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10167 atomic_load_explicit(&p->refresh_in,
10168 memory_order_relaxed));
d62a17ae 10169 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10170 atomic_load_explicit(&p->dynamic_cap_out,
10171 memory_order_relaxed));
d62a17ae 10172 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10173 atomic_load_explicit(&p->dynamic_cap_in,
10174 memory_order_relaxed));
10175 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10176 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10177 json_object_object_add(json_neigh, "messageStats", json_stat);
10178 } else {
10179 /* Packet counts. */
10180 vty_out(vty, " Message statistics:\n");
10181 vty_out(vty, " Inq depth is 0\n");
10182 vty_out(vty, " Outq depth is %lu\n",
10183 (unsigned long)p->obuf->count);
10184 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10185 vty_out(vty, " Opens: %10d %10d\n",
10186 atomic_load_explicit(&p->open_out,
10187 memory_order_relaxed),
10188 atomic_load_explicit(&p->open_in,
10189 memory_order_relaxed));
10190 vty_out(vty, " Notifications: %10d %10d\n",
10191 atomic_load_explicit(&p->notify_out,
10192 memory_order_relaxed),
10193 atomic_load_explicit(&p->notify_in,
10194 memory_order_relaxed));
10195 vty_out(vty, " Updates: %10d %10d\n",
10196 atomic_load_explicit(&p->update_out,
10197 memory_order_relaxed),
10198 atomic_load_explicit(&p->update_in,
10199 memory_order_relaxed));
10200 vty_out(vty, " Keepalives: %10d %10d\n",
10201 atomic_load_explicit(&p->keepalive_out,
10202 memory_order_relaxed),
10203 atomic_load_explicit(&p->keepalive_in,
10204 memory_order_relaxed));
10205 vty_out(vty, " Route Refresh: %10d %10d\n",
10206 atomic_load_explicit(&p->refresh_out,
10207 memory_order_relaxed),
10208 atomic_load_explicit(&p->refresh_in,
10209 memory_order_relaxed));
d62a17ae 10210 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10211 atomic_load_explicit(&p->dynamic_cap_out,
10212 memory_order_relaxed),
10213 atomic_load_explicit(&p->dynamic_cap_in,
10214 memory_order_relaxed));
10215 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10216 PEER_TOTAL_RX(p));
d62a17ae 10217 }
10218
10219 if (use_json) {
10220 /* advertisement-interval */
10221 json_object_int_add(json_neigh,
10222 "minBtwnAdvertisementRunsTimerMsecs",
10223 p->v_routeadv * 1000);
10224
10225 /* Update-source. */
10226 if (p->update_if || p->update_source) {
10227 if (p->update_if)
10228 json_object_string_add(json_neigh,
10229 "updateSource",
10230 p->update_if);
10231 else if (p->update_source)
10232 json_object_string_add(
10233 json_neigh, "updateSource",
10234 sockunion2str(p->update_source, buf1,
10235 SU_ADDRSTRLEN));
10236 }
10237 } else {
10238 /* advertisement-interval */
10239 vty_out(vty,
10240 " Minimum time between advertisement runs is %d seconds\n",
10241 p->v_routeadv);
10242
10243 /* Update-source. */
10244 if (p->update_if || p->update_source) {
10245 vty_out(vty, " Update source is ");
10246 if (p->update_if)
10247 vty_out(vty, "%s", p->update_if);
10248 else if (p->update_source)
10249 vty_out(vty, "%s",
10250 sockunion2str(p->update_source, buf1,
10251 SU_ADDRSTRLEN));
10252 vty_out(vty, "\n");
10253 }
10254
10255 vty_out(vty, "\n");
10256 }
10257
10258 /* Address Family Information */
10259 json_object *json_hold = NULL;
10260
10261 if (use_json)
10262 json_hold = json_object_new_object();
10263
05c7a1cc
QY
10264 FOREACH_AFI_SAFI (afi, safi)
10265 if (p->afc[afi][safi])
10266 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10267 json_hold);
d62a17ae 10268
10269 if (use_json) {
10270 json_object_object_add(json_neigh, "addressFamilyInfo",
10271 json_hold);
10272 json_object_int_add(json_neigh, "connectionsEstablished",
10273 p->established);
10274 json_object_int_add(json_neigh, "connectionsDropped",
10275 p->dropped);
10276 } else
10277 vty_out(vty, " Connections established %d; dropped %d\n",
10278 p->established, p->dropped);
10279
10280 if (!p->last_reset) {
10281 if (use_json)
10282 json_object_string_add(json_neigh, "lastReset",
10283 "never");
10284 else
10285 vty_out(vty, " Last reset never\n");
10286 } else {
10287 if (use_json) {
10288 time_t uptime;
10289 struct tm *tm;
10290
10291 uptime = bgp_clock();
10292 uptime -= p->resettime;
10293 tm = gmtime(&uptime);
10294 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10295 (tm->tm_sec * 1000)
10296 + (tm->tm_min * 60000)
10297 + (tm->tm_hour * 3600000));
10298 json_object_string_add(
10299 json_neigh, "lastResetDueTo",
10300 peer_down_str[(int)p->last_reset]);
10301 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10302 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10303 char errorcodesubcode_hexstr[5];
10304 char errorcodesubcode_str[256];
10305
10306 code_str = bgp_notify_code_str(p->notify.code);
10307 subcode_str = bgp_notify_subcode_str(
10308 p->notify.code, p->notify.subcode);
10309
10310 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10311 p->notify.code, p->notify.subcode);
10312 json_object_string_add(json_neigh,
10313 "lastErrorCodeSubcode",
10314 errorcodesubcode_hexstr);
10315 snprintf(errorcodesubcode_str, 255, "%s%s",
10316 code_str, subcode_str);
10317 json_object_string_add(json_neigh,
10318 "lastNotificationReason",
10319 errorcodesubcode_str);
10320 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10321 && p->notify.code == BGP_NOTIFY_CEASE
10322 && (p->notify.subcode
10323 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10324 || p->notify.subcode
10325 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10326 && p->notify.length) {
10327 char msgbuf[1024];
10328 const char *msg_str;
10329
10330 msg_str = bgp_notify_admin_message(
10331 msgbuf, sizeof(msgbuf),
d7c0a89a 10332 (uint8_t *)p->notify.data,
d62a17ae 10333 p->notify.length);
10334 if (msg_str)
10335 json_object_string_add(
10336 json_neigh,
10337 "lastShutdownDescription",
10338 msg_str);
10339 }
10340 }
10341 } else {
10342 vty_out(vty, " Last reset %s, ",
10343 peer_uptime(p->resettime, timebuf,
10344 BGP_UPTIME_LEN, 0, NULL));
10345
10346 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10347 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10348 code_str = bgp_notify_code_str(p->notify.code);
10349 subcode_str = bgp_notify_subcode_str(
10350 p->notify.code, p->notify.subcode);
10351 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10352 p->last_reset == PEER_DOWN_NOTIFY_SEND
10353 ? "sent"
10354 : "received",
10355 code_str, subcode_str);
10356 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10357 && p->notify.code == BGP_NOTIFY_CEASE
10358 && (p->notify.subcode
10359 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10360 || p->notify.subcode
10361 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10362 && p->notify.length) {
10363 char msgbuf[1024];
10364 const char *msg_str;
10365
10366 msg_str = bgp_notify_admin_message(
10367 msgbuf, sizeof(msgbuf),
d7c0a89a 10368 (uint8_t *)p->notify.data,
d62a17ae 10369 p->notify.length);
10370 if (msg_str)
10371 vty_out(vty,
10372 " Message: \"%s\"\n",
10373 msg_str);
10374 }
10375 } else {
10376 vty_out(vty, "due to %s\n",
10377 peer_down_str[(int)p->last_reset]);
10378 }
10379
10380 if (p->last_reset_cause_size) {
10381 msg = p->last_reset_cause;
10382 vty_out(vty,
10383 " Message received that caused BGP to send a NOTIFICATION:\n ");
10384 for (i = 1; i <= p->last_reset_cause_size;
10385 i++) {
10386 vty_out(vty, "%02X", *msg++);
10387
10388 if (i != p->last_reset_cause_size) {
10389 if (i % 16 == 0) {
10390 vty_out(vty, "\n ");
10391 } else if (i % 4 == 0) {
10392 vty_out(vty, " ");
10393 }
10394 }
10395 }
10396 vty_out(vty, "\n");
10397 }
10398 }
10399 }
10400
10401 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10402 if (use_json)
10403 json_object_boolean_true_add(json_neigh,
10404 "prefixesConfigExceedMax");
10405 else
10406 vty_out(vty,
10407 " Peer had exceeded the max. no. of prefixes configured.\n");
10408
10409 if (p->t_pmax_restart) {
10410 if (use_json) {
10411 json_object_boolean_true_add(
10412 json_neigh, "reducePrefixNumFrom");
10413 json_object_int_add(json_neigh,
10414 "restartInTimerMsec",
10415 thread_timer_remain_second(
10416 p->t_pmax_restart)
10417 * 1000);
10418 } else
10419 vty_out(vty,
10420 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10421 p->host, thread_timer_remain_second(
10422 p->t_pmax_restart));
d62a17ae 10423 } else {
10424 if (use_json)
10425 json_object_boolean_true_add(
10426 json_neigh,
10427 "reducePrefixNumAndClearIpBgp");
10428 else
10429 vty_out(vty,
10430 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10431 p->host);
10432 }
10433 }
10434
10435 /* EBGP Multihop and GTSM */
10436 if (p->sort != BGP_PEER_IBGP) {
10437 if (use_json) {
10438 if (p->gtsm_hops > 0)
10439 json_object_int_add(json_neigh,
10440 "externalBgpNbrMaxHopsAway",
10441 p->gtsm_hops);
10442 else if (p->ttl > 1)
10443 json_object_int_add(json_neigh,
10444 "externalBgpNbrMaxHopsAway",
10445 p->ttl);
10446 } else {
10447 if (p->gtsm_hops > 0)
10448 vty_out(vty,
10449 " External BGP neighbor may be up to %d hops away.\n",
10450 p->gtsm_hops);
10451 else if (p->ttl > 1)
10452 vty_out(vty,
10453 " External BGP neighbor may be up to %d hops away.\n",
10454 p->ttl);
10455 }
10456 } else {
10457 if (p->gtsm_hops > 0) {
10458 if (use_json)
10459 json_object_int_add(json_neigh,
10460 "internalBgpNbrMaxHopsAway",
10461 p->gtsm_hops);
10462 else
10463 vty_out(vty,
10464 " Internal BGP neighbor may be up to %d hops away.\n",
10465 p->gtsm_hops);
10466 }
10467 }
10468
10469 /* Local address. */
10470 if (p->su_local) {
10471 if (use_json) {
10472 json_object_string_add(json_neigh, "hostLocal",
10473 sockunion2str(p->su_local, buf1,
10474 SU_ADDRSTRLEN));
10475 json_object_int_add(json_neigh, "portLocal",
10476 ntohs(p->su_local->sin.sin_port));
10477 } else
10478 vty_out(vty, "Local host: %s, Local port: %d\n",
10479 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10480 ntohs(p->su_local->sin.sin_port));
10481 }
10482
10483 /* Remote address. */
10484 if (p->su_remote) {
10485 if (use_json) {
10486 json_object_string_add(json_neigh, "hostForeign",
10487 sockunion2str(p->su_remote, buf1,
10488 SU_ADDRSTRLEN));
10489 json_object_int_add(json_neigh, "portForeign",
10490 ntohs(p->su_remote->sin.sin_port));
10491 } else
10492 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10493 sockunion2str(p->su_remote, buf1,
10494 SU_ADDRSTRLEN),
10495 ntohs(p->su_remote->sin.sin_port));
10496 }
10497
10498 /* Nexthop display. */
10499 if (p->su_local) {
10500 if (use_json) {
10501 json_object_string_add(json_neigh, "nexthop",
10502 inet_ntop(AF_INET,
10503 &p->nexthop.v4, buf1,
10504 sizeof(buf1)));
10505 json_object_string_add(json_neigh, "nexthopGlobal",
10506 inet_ntop(AF_INET6,
10507 &p->nexthop.v6_global,
10508 buf1, sizeof(buf1)));
10509 json_object_string_add(json_neigh, "nexthopLocal",
10510 inet_ntop(AF_INET6,
10511 &p->nexthop.v6_local,
10512 buf1, sizeof(buf1)));
10513 if (p->shared_network)
10514 json_object_string_add(json_neigh,
10515 "bgpConnection",
10516 "sharedNetwork");
10517 else
10518 json_object_string_add(json_neigh,
10519 "bgpConnection",
10520 "nonSharedNetwork");
10521 } else {
10522 vty_out(vty, "Nexthop: %s\n",
10523 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10524 sizeof(buf1)));
10525 vty_out(vty, "Nexthop global: %s\n",
10526 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10527 sizeof(buf1)));
10528 vty_out(vty, "Nexthop local: %s\n",
10529 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10530 sizeof(buf1)));
10531 vty_out(vty, "BGP connection: %s\n",
10532 p->shared_network ? "shared network"
10533 : "non shared network");
10534 }
10535 }
10536
10537 /* Timer information. */
10538 if (use_json) {
10539 json_object_int_add(json_neigh, "connectRetryTimer",
10540 p->v_connect);
10541 if (p->status == Established && p->rtt)
10542 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10543 p->rtt);
10544 if (p->t_start)
10545 json_object_int_add(
10546 json_neigh, "nextStartTimerDueInMsecs",
10547 thread_timer_remain_second(p->t_start) * 1000);
10548 if (p->t_connect)
10549 json_object_int_add(
10550 json_neigh, "nextConnectTimerDueInMsecs",
10551 thread_timer_remain_second(p->t_connect)
10552 * 1000);
10553 if (p->t_routeadv) {
10554 json_object_int_add(json_neigh, "mraiInterval",
10555 p->v_routeadv);
10556 json_object_int_add(
10557 json_neigh, "mraiTimerExpireInMsecs",
10558 thread_timer_remain_second(p->t_routeadv)
10559 * 1000);
10560 }
10561 if (p->password)
10562 json_object_int_add(json_neigh, "authenticationEnabled",
10563 1);
10564
10565 if (p->t_read)
10566 json_object_string_add(json_neigh, "readThread", "on");
10567 else
10568 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10569
10570 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10571 json_object_string_add(json_neigh, "writeThread", "on");
10572 else
10573 json_object_string_add(json_neigh, "writeThread",
10574 "off");
10575 } else {
10576 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10577 p->v_connect);
10578 if (p->status == Established && p->rtt)
10579 vty_out(vty, "Estimated round trip time: %d ms\n",
10580 p->rtt);
10581 if (p->t_start)
10582 vty_out(vty, "Next start timer due in %ld seconds\n",
10583 thread_timer_remain_second(p->t_start));
10584 if (p->t_connect)
10585 vty_out(vty, "Next connect timer due in %ld seconds\n",
10586 thread_timer_remain_second(p->t_connect));
10587 if (p->t_routeadv)
10588 vty_out(vty,
10589 "MRAI (interval %u) timer expires in %ld seconds\n",
10590 p->v_routeadv,
10591 thread_timer_remain_second(p->t_routeadv));
10592 if (p->password)
10593 vty_out(vty, "Peer Authentication Enabled\n");
10594
10595 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10596 p->t_read ? "on" : "off",
10597 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10598 ? "on"
10599 : "off");
d62a17ae 10600 }
10601
10602 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10603 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10604 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10605
10606 if (!use_json)
10607 vty_out(vty, "\n");
10608
10609 /* BFD information. */
10610 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10611
10612 if (use_json) {
10613 if (p->conf_if) /* Configured interface name. */
10614 json_object_object_add(json, p->conf_if, json_neigh);
10615 else /* Configured IP address. */
10616 json_object_object_add(json, p->host, json_neigh);
10617 }
10618}
10619
10620static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10621 enum show_type type, union sockunion *su,
d7c0a89a 10622 const char *conf_if, uint8_t use_json,
d62a17ae 10623 json_object *json)
10624{
10625 struct listnode *node, *nnode;
10626 struct peer *peer;
10627 int find = 0;
10628
10629 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10630 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10631 continue;
10632
10633 switch (type) {
10634 case show_all:
10635 bgp_show_peer(vty, peer, use_json, json);
10636 break;
10637 case show_peer:
10638 if (conf_if) {
10639 if ((peer->conf_if
10640 && !strcmp(peer->conf_if, conf_if))
10641 || (peer->hostname
10642 && !strcmp(peer->hostname, conf_if))) {
10643 find = 1;
10644 bgp_show_peer(vty, peer, use_json,
10645 json);
10646 }
10647 } else {
10648 if (sockunion_same(&peer->su, su)) {
10649 find = 1;
10650 bgp_show_peer(vty, peer, use_json,
10651 json);
10652 }
10653 }
10654 break;
10655 }
10656 }
10657
10658 if (type == show_peer && !find) {
10659 if (use_json)
10660 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10661 else
88b7d255 10662 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 10663 }
10664
10665 if (use_json) {
996c9314
LB
10666 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10667 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10668 json_object_free(json);
10669 } else {
10670 vty_out(vty, "\n");
10671 }
10672
10673 return CMD_SUCCESS;
10674}
10675
10676static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10677 enum show_type type,
10678 const char *ip_str,
d7c0a89a 10679 uint8_t use_json)
d62a17ae 10680{
0291c246
MK
10681 struct listnode *node, *nnode;
10682 struct bgp *bgp;
71aedaa3 10683 union sockunion su;
0291c246 10684 json_object *json = NULL;
71aedaa3 10685 int ret, is_first = 1;
d62a17ae 10686
10687 if (use_json)
10688 vty_out(vty, "{\n");
10689
10690 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10691 if (use_json) {
10692 if (!(json = json_object_new_object())) {
10693 zlog_err(
10694 "Unable to allocate memory for JSON object");
10695 vty_out(vty,
10696 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10697 return;
10698 }
10699
10700 json_object_int_add(json, "vrfId",
10701 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10702 ? -1
10703 : (int64_t)bgp->vrf_id);
d62a17ae 10704 json_object_string_add(
10705 json, "vrfName",
10706 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10707 ? "Default"
10708 : bgp->name);
10709
10710 if (!is_first)
10711 vty_out(vty, ",\n");
10712 else
10713 is_first = 0;
10714
10715 vty_out(vty, "\"%s\":",
10716 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10717 ? "Default"
10718 : bgp->name);
10719 } else {
10720 vty_out(vty, "\nInstance %s:\n",
10721 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10722 ? "Default"
10723 : bgp->name);
10724 }
71aedaa3
DS
10725
10726 if (type == show_peer) {
10727 ret = str2sockunion(ip_str, &su);
10728 if (ret < 0)
10729 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10730 use_json, json);
10731 else
10732 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10733 use_json, json);
10734 } else {
10735 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10736 use_json, json);
10737 }
d62a17ae 10738 }
10739
10740 if (use_json)
10741 vty_out(vty, "}\n");
10742}
10743
10744static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10745 enum show_type type, const char *ip_str,
d7c0a89a 10746 uint8_t use_json)
d62a17ae 10747{
10748 int ret;
10749 struct bgp *bgp;
10750 union sockunion su;
10751 json_object *json = NULL;
10752
10753 if (name) {
10754 if (strmatch(name, "all")) {
71aedaa3
DS
10755 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10756 use_json);
d62a17ae 10757 return CMD_SUCCESS;
10758 } else {
10759 bgp = bgp_lookup_by_name(name);
10760 if (!bgp) {
10761 if (use_json) {
10762 json = json_object_new_object();
10763 json_object_boolean_true_add(
10764 json, "bgpNoSuchInstance");
10765 vty_out(vty, "%s\n",
10766 json_object_to_json_string_ext(
10767 json,
10768 JSON_C_TO_STRING_PRETTY));
10769 json_object_free(json);
10770 } else
10771 vty_out(vty,
10772 "%% No such BGP instance exist\n");
10773
10774 return CMD_WARNING;
10775 }
10776 }
10777 } else {
10778 bgp = bgp_get_default();
10779 }
10780
10781 if (bgp) {
10782 json = json_object_new_object();
10783 if (ip_str) {
10784 ret = str2sockunion(ip_str, &su);
10785 if (ret < 0)
10786 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10787 use_json, json);
10788 else
10789 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10790 use_json, json);
10791 } else {
10792 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10793 json);
10794 }
10795 json_object_free(json);
10796 }
10797
10798 return CMD_SUCCESS;
4fb25c53
DW
10799}
10800
716b2d8a 10801/* "show [ip] bgp neighbors" commands. */
718e3744 10802DEFUN (show_ip_bgp_neighbors,
10803 show_ip_bgp_neighbors_cmd,
24345e82 10804 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 10805 SHOW_STR
10806 IP_STR
10807 BGP_STR
f2a8972b 10808 BGP_INSTANCE_HELP_STR
8c3deaae
QY
10809 "Address Family\n"
10810 "Address Family\n"
718e3744 10811 "Detailed information on TCP and BGP neighbor connections\n"
10812 "Neighbor to display information about\n"
a80beece 10813 "Neighbor to display information about\n"
91d37724 10814 "Neighbor on BGP configured interface\n"
9973d184 10815 JSON_STR)
718e3744 10816{
d62a17ae 10817 char *vrf = NULL;
10818 char *sh_arg = NULL;
10819 enum show_type sh_type;
718e3744 10820
d7c0a89a 10821 uint8_t uj = use_json(argc, argv);
718e3744 10822
d62a17ae 10823 int idx = 0;
718e3744 10824
d62a17ae 10825 if (argv_find(argv, argc, "view", &idx)
10826 || argv_find(argv, argc, "vrf", &idx))
10827 vrf = argv[idx + 1]->arg;
718e3744 10828
d62a17ae 10829 idx++;
10830 if (argv_find(argv, argc, "A.B.C.D", &idx)
10831 || argv_find(argv, argc, "X:X::X:X", &idx)
10832 || argv_find(argv, argc, "WORD", &idx)) {
10833 sh_type = show_peer;
10834 sh_arg = argv[idx]->arg;
10835 } else
10836 sh_type = show_all;
856ca177 10837
d62a17ae 10838 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10839}
10840
716b2d8a 10841/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10842 paths' and `show ip mbgp paths'. Those functions results are the
10843 same.*/
f412b39a 10844DEFUN (show_ip_bgp_paths,
718e3744 10845 show_ip_bgp_paths_cmd,
46f296b4 10846 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10847 SHOW_STR
10848 IP_STR
10849 BGP_STR
46f296b4 10850 BGP_SAFI_HELP_STR
718e3744 10851 "Path information\n")
10852{
d62a17ae 10853 vty_out(vty, "Address Refcnt Path\n");
10854 aspath_print_all_vty(vty);
10855 return CMD_SUCCESS;
718e3744 10856}
10857
718e3744 10858#include "hash.h"
10859
d62a17ae 10860static void community_show_all_iterator(struct hash_backet *backet,
10861 struct vty *vty)
718e3744 10862{
d62a17ae 10863 struct community *com;
718e3744 10864
d62a17ae 10865 com = (struct community *)backet->data;
3f65c5b1 10866 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 10867 community_str(com, false));
718e3744 10868}
10869
10870/* Show BGP's community internal data. */
f412b39a 10871DEFUN (show_ip_bgp_community_info,
718e3744 10872 show_ip_bgp_community_info_cmd,
bec37ba5 10873 "show [ip] bgp community-info",
718e3744 10874 SHOW_STR
10875 IP_STR
10876 BGP_STR
10877 "List all bgp community information\n")
10878{
d62a17ae 10879 vty_out(vty, "Address Refcnt Community\n");
718e3744 10880
d62a17ae 10881 hash_iterate(community_hash(),
10882 (void (*)(struct hash_backet *,
10883 void *))community_show_all_iterator,
10884 vty);
718e3744 10885
d62a17ae 10886 return CMD_SUCCESS;
718e3744 10887}
10888
d62a17ae 10889static void lcommunity_show_all_iterator(struct hash_backet *backet,
10890 struct vty *vty)
57d187bc 10891{
d62a17ae 10892 struct lcommunity *lcom;
57d187bc 10893
d62a17ae 10894 lcom = (struct lcommunity *)backet->data;
3f65c5b1 10895 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 10896 lcommunity_str(lcom, false));
57d187bc
JS
10897}
10898
10899/* Show BGP's community internal data. */
10900DEFUN (show_ip_bgp_lcommunity_info,
10901 show_ip_bgp_lcommunity_info_cmd,
10902 "show ip bgp large-community-info",
10903 SHOW_STR
10904 IP_STR
10905 BGP_STR
10906 "List all bgp large-community information\n")
10907{
d62a17ae 10908 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 10909
d62a17ae 10910 hash_iterate(lcommunity_hash(),
10911 (void (*)(struct hash_backet *,
10912 void *))lcommunity_show_all_iterator,
10913 vty);
57d187bc 10914
d62a17ae 10915 return CMD_SUCCESS;
57d187bc
JS
10916}
10917
10918
f412b39a 10919DEFUN (show_ip_bgp_attr_info,
718e3744 10920 show_ip_bgp_attr_info_cmd,
bec37ba5 10921 "show [ip] bgp attribute-info",
718e3744 10922 SHOW_STR
10923 IP_STR
10924 BGP_STR
10925 "List all bgp attribute information\n")
10926{
d62a17ae 10927 attr_show_all(vty);
10928 return CMD_SUCCESS;
718e3744 10929}
6b0655a2 10930
53089bec 10931static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10932 afi_t afi, safi_t safi)
10933{
10934 struct bgp *bgp;
10935 struct listnode *node;
10936 char *vname;
10937 char buf1[INET6_ADDRSTRLEN];
10938 char *ecom_str;
10939 vpn_policy_direction_t dir;
10940
10941 if (name) {
10942 bgp = bgp_lookup_by_name(name);
10943 if (!bgp) {
10944 vty_out(vty, "%% No such BGP instance exist\n");
10945 return CMD_WARNING;
10946 }
10947 } else {
10948 bgp = bgp_get_default();
10949 if (!bgp) {
020a3f60
DS
10950 vty_out(vty,
10951 "%% Default BGP instance does not exist\n");
53089bec 10952 return CMD_WARNING;
10953 }
10954 }
10955
10956 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10957 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
020a3f60
DS
10958 vty_out(vty,
10959 "This VRF is not importing %s routes from any other VRF\n",
53089bec 10960 afi_safi_print(afi, safi));
10961 } else {
020a3f60
DS
10962 vty_out(vty,
10963 "This VRF is importing %s routes from the following VRFs:\n",
53089bec 10964 afi_safi_print(afi, safi));
10965 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
10966 vname)) {
10967 vty_out(vty, " %s\n", vname);
10968 }
10969 dir = BGP_VPN_POLICY_DIR_FROMVPN;
10970 ecom_str = ecommunity_ecom2str(
10971 bgp->vpn_policy[afi].rtlist[dir],
10972 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
10973 vty_out(vty, "Import RT(s): %s\n", ecom_str);
10974 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
10975 }
10976
10977 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10978 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
020a3f60
DS
10979 vty_out(vty,
10980 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 10981 afi_safi_print(afi, safi));
10982 } else {
020a3f60
DS
10983 vty_out(vty,
10984 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 10985 afi_safi_print(afi, safi));
10986 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
10987 vname)) {
10988 vty_out(vty, " %s\n", vname);
10989 }
10990 vty_out(vty, "RD: %s\n",
10991 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
10992 buf1, RD_ADDRSTRLEN));
10993 dir = BGP_VPN_POLICY_DIR_TOVPN;
10994 ecom_str = ecommunity_ecom2str(
10995 bgp->vpn_policy[afi].rtlist[dir],
10996 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
10997 vty_out(vty, "Emport RT: %s\n", ecom_str);
10998 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
10999 }
11000
11001 return CMD_SUCCESS;
11002}
11003
11004/* "show [ip] bgp route-leak" command. */
11005DEFUN (show_ip_bgp_route_leak,
11006 show_ip_bgp_route_leak_cmd,
11007 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
11008 SHOW_STR
11009 IP_STR
11010 BGP_STR
11011 BGP_INSTANCE_HELP_STR
11012 BGP_AFI_HELP_STR
11013 BGP_SAFI_HELP_STR
11014 "Route leaking information\n")
11015{
11016 char *vrf = NULL;
11017 afi_t afi = AFI_MAX;
11018 safi_t safi = SAFI_MAX;
11019
11020 int idx = 0;
11021
11022 /* show [ip] bgp */
11023 if (argv_find(argv, argc, "ip", &idx)) {
11024 afi = AFI_IP;
11025 safi = SAFI_UNICAST;
11026 }
11027 /* [vrf VIEWVRFNAME] */
11028 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11029 vty_out(vty,
11030 "%% This command is not applicable to BGP views\n");
53089bec 11031 return CMD_WARNING;
11032 }
11033
11034 if (argv_find(argv, argc, "vrf", &idx))
11035 vrf = argv[++idx]->arg;
11036 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11037 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11038 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11039 }
11040
11041 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11042 vty_out(vty,
11043 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11044 return CMD_WARNING;
11045 }
11046
11047 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11048}
11049
d62a17ae 11050static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11051 safi_t safi)
f186de26 11052{
d62a17ae 11053 struct listnode *node, *nnode;
11054 struct bgp *bgp;
f186de26 11055
d62a17ae 11056 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11057 vty_out(vty, "\nInstance %s:\n",
11058 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11059 ? "Default"
11060 : bgp->name);
11061 update_group_show(bgp, afi, safi, vty, 0);
11062 }
f186de26 11063}
11064
d62a17ae 11065static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11066 int safi, uint64_t subgrp_id)
4fb25c53 11067{
d62a17ae 11068 struct bgp *bgp;
4fb25c53 11069
d62a17ae 11070 if (name) {
11071 if (strmatch(name, "all")) {
11072 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11073 return CMD_SUCCESS;
11074 } else {
11075 bgp = bgp_lookup_by_name(name);
11076 }
11077 } else {
11078 bgp = bgp_get_default();
11079 }
4fb25c53 11080
d62a17ae 11081 if (bgp)
11082 update_group_show(bgp, afi, safi, vty, subgrp_id);
11083 return CMD_SUCCESS;
4fb25c53
DW
11084}
11085
8fe8a7f6
DS
11086DEFUN (show_ip_bgp_updgrps,
11087 show_ip_bgp_updgrps_cmd,
c1a44e43 11088 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11089 SHOW_STR
11090 IP_STR
11091 BGP_STR
11092 BGP_INSTANCE_HELP_STR
c9e571b4 11093 BGP_AFI_HELP_STR
9bedbb1e 11094 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11095 "Detailed info about dynamic update groups\n"
11096 "Specific subgroup to display detailed info for\n")
8386ac43 11097{
d62a17ae 11098 char *vrf = NULL;
11099 afi_t afi = AFI_IP6;
11100 safi_t safi = SAFI_UNICAST;
11101 uint64_t subgrp_id = 0;
11102
11103 int idx = 0;
11104
11105 /* show [ip] bgp */
11106 if (argv_find(argv, argc, "ip", &idx))
11107 afi = AFI_IP;
11108 /* [<view|vrf> VIEWVRFNAME] */
11109 if (argv_find(argv, argc, "view", &idx)
11110 || argv_find(argv, argc, "vrf", &idx))
11111 vrf = argv[++idx]->arg;
11112 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11113 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11114 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11115 }
5bf15956 11116
d62a17ae 11117 /* get subgroup id, if provided */
11118 idx = argc - 1;
11119 if (argv[idx]->type == VARIABLE_TKN)
11120 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11121
d62a17ae 11122 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11123}
11124
f186de26 11125DEFUN (show_bgp_instance_all_ipv6_updgrps,
11126 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11127 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11128 SHOW_STR
716b2d8a 11129 IP_STR
f186de26 11130 BGP_STR
11131 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11132 "Detailed info about dynamic update groups\n")
f186de26 11133{
d62a17ae 11134 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11135 return CMD_SUCCESS;
f186de26 11136}
11137
5bf15956
DW
11138DEFUN (show_bgp_updgrps_stats,
11139 show_bgp_updgrps_stats_cmd,
716b2d8a 11140 "show [ip] bgp update-groups statistics",
3f9c7369 11141 SHOW_STR
716b2d8a 11142 IP_STR
3f9c7369 11143 BGP_STR
0c7b1b01 11144 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11145 "Statistics\n")
11146{
d62a17ae 11147 struct bgp *bgp;
3f9c7369 11148
d62a17ae 11149 bgp = bgp_get_default();
11150 if (bgp)
11151 update_group_show_stats(bgp, vty);
3f9c7369 11152
d62a17ae 11153 return CMD_SUCCESS;
3f9c7369
DS
11154}
11155
8386ac43 11156DEFUN (show_bgp_instance_updgrps_stats,
11157 show_bgp_instance_updgrps_stats_cmd,
18c57037 11158 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11159 SHOW_STR
716b2d8a 11160 IP_STR
8386ac43 11161 BGP_STR
11162 BGP_INSTANCE_HELP_STR
0c7b1b01 11163 "Detailed info about dynamic update groups\n"
8386ac43 11164 "Statistics\n")
11165{
d62a17ae 11166 int idx_word = 3;
11167 struct bgp *bgp;
8386ac43 11168
d62a17ae 11169 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11170 if (bgp)
11171 update_group_show_stats(bgp, vty);
8386ac43 11172
d62a17ae 11173 return CMD_SUCCESS;
8386ac43 11174}
11175
d62a17ae 11176static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11177 afi_t afi, safi_t safi,
11178 const char *what, uint64_t subgrp_id)
3f9c7369 11179{
d62a17ae 11180 struct bgp *bgp;
8386ac43 11181
d62a17ae 11182 if (name)
11183 bgp = bgp_lookup_by_name(name);
11184 else
11185 bgp = bgp_get_default();
8386ac43 11186
d62a17ae 11187 if (bgp) {
11188 if (!strcmp(what, "advertise-queue"))
11189 update_group_show_adj_queue(bgp, afi, safi, vty,
11190 subgrp_id);
11191 else if (!strcmp(what, "advertised-routes"))
11192 update_group_show_advertised(bgp, afi, safi, vty,
11193 subgrp_id);
11194 else if (!strcmp(what, "packet-queue"))
11195 update_group_show_packet_queue(bgp, afi, safi, vty,
11196 subgrp_id);
11197 }
3f9c7369
DS
11198}
11199
dc64bdec
QY
11200DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11201 show_ip_bgp_instance_updgrps_adj_s_cmd,
11202 "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",
11203 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11204 BGP_SAFI_HELP_STR
11205 "Detailed info about dynamic update groups\n"
11206 "Specific subgroup to display info for\n"
11207 "Advertisement queue\n"
11208 "Announced routes\n"
11209 "Packet queue\n")
3f9c7369 11210{
dc64bdec
QY
11211 uint64_t subgrp_id = 0;
11212 afi_t afiz;
11213 safi_t safiz;
11214 if (sgid)
11215 subgrp_id = strtoull(sgid, NULL, 10);
11216
11217 if (!ip && !afi)
11218 afiz = AFI_IP6;
11219 if (!ip && afi)
11220 afiz = bgp_vty_afi_from_str(afi);
11221 if (ip && !afi)
11222 afiz = AFI_IP;
11223 if (ip && afi) {
11224 afiz = bgp_vty_afi_from_str(afi);
11225 if (afiz != AFI_IP)
11226 vty_out(vty,
11227 "%% Cannot specify both 'ip' and 'ipv6'\n");
11228 return CMD_WARNING;
11229 }
d62a17ae 11230
dc64bdec 11231 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11232
dc64bdec 11233 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11234 return CMD_SUCCESS;
11235}
11236
d62a17ae 11237static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11238{
11239 struct listnode *node, *nnode;
11240 struct prefix *range;
11241 struct peer *conf;
11242 struct peer *peer;
11243 char buf[PREFIX2STR_BUFFER];
11244 afi_t afi;
11245 safi_t safi;
11246 const char *peer_status;
11247 const char *af_str;
11248 int lr_count;
11249 int dynamic;
11250 int af_cfgd;
11251
11252 conf = group->conf;
11253
11254 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11255 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11256 conf->as);
11257 } else if (conf->as_type == AS_INTERNAL) {
11258 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11259 group->bgp->as);
11260 } else {
11261 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11262 }
f14e6fdb 11263
d62a17ae 11264 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11265 vty_out(vty, " Peer-group type is internal\n");
11266 else
11267 vty_out(vty, " Peer-group type is external\n");
11268
11269 /* Display AFs configured. */
11270 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11271 FOREACH_AFI_SAFI (afi, safi) {
11272 if (conf->afc[afi][safi]) {
11273 af_cfgd = 1;
11274 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11275 }
05c7a1cc 11276 }
d62a17ae 11277 if (!af_cfgd)
11278 vty_out(vty, " none\n");
11279 else
11280 vty_out(vty, "\n");
11281
11282 /* Display listen ranges (for dynamic neighbors), if any */
11283 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11284 if (afi == AFI_IP)
11285 af_str = "IPv4";
11286 else if (afi == AFI_IP6)
11287 af_str = "IPv6";
11288 else
11289 af_str = "???";
11290 lr_count = listcount(group->listen_range[afi]);
11291 if (lr_count) {
11292 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11293 af_str);
11294
11295
11296 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11297 nnode, range)) {
11298 prefix2str(range, buf, sizeof(buf));
11299 vty_out(vty, " %s\n", buf);
11300 }
11301 }
11302 }
f14e6fdb 11303
d62a17ae 11304 /* Display group members and their status */
11305 if (listcount(group->peer)) {
11306 vty_out(vty, " Peer-group members:\n");
11307 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11308 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11309 peer_status = "Idle (Admin)";
11310 else if (CHECK_FLAG(peer->sflags,
11311 PEER_STATUS_PREFIX_OVERFLOW))
11312 peer_status = "Idle (PfxCt)";
11313 else
11314 peer_status = lookup_msg(bgp_status_msg,
11315 peer->status, NULL);
11316
11317 dynamic = peer_dynamic_neighbor(peer);
11318 vty_out(vty, " %s %s %s \n", peer->host,
11319 dynamic ? "(dynamic)" : "", peer_status);
11320 }
11321 }
f14e6fdb 11322
d62a17ae 11323 return CMD_SUCCESS;
11324}
11325
ff9959b0
QY
11326static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11327 const char *group_name)
d62a17ae 11328{
ff9959b0 11329 struct bgp *bgp;
d62a17ae 11330 struct listnode *node, *nnode;
11331 struct peer_group *group;
ff9959b0
QY
11332 bool found = false;
11333
11334 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11335
11336 if (!bgp) {
11337 vty_out(vty, "%% No such BGP instance exists\n");
11338 return CMD_WARNING;
11339 }
d62a17ae 11340
11341 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11342 if (group_name) {
11343 if (strmatch(group->name, group_name)) {
d62a17ae 11344 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11345 found = true;
11346 break;
d62a17ae 11347 }
ff9959b0
QY
11348 } else {
11349 bgp_show_one_peer_group(vty, group);
d62a17ae 11350 }
f14e6fdb 11351 }
f14e6fdb 11352
ff9959b0 11353 if (group_name && !found)
d62a17ae 11354 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11355
d62a17ae 11356 return CMD_SUCCESS;
f14e6fdb
DS
11357}
11358
f14e6fdb
DS
11359DEFUN (show_ip_bgp_peer_groups,
11360 show_ip_bgp_peer_groups_cmd,
18c57037 11361 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11362 SHOW_STR
11363 IP_STR
11364 BGP_STR
8386ac43 11365 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11366 "Detailed information on BGP peer groups\n"
11367 "Peer group name\n")
f14e6fdb 11368{
d62a17ae 11369 char *vrf, *pg;
11370 vrf = pg = NULL;
11371 int idx = 0;
f14e6fdb 11372
a4d82a8a
PZ
11373 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11374 : NULL;
d62a17ae 11375 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11376
ff9959b0 11377 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11378}
3f9c7369 11379
d6e3c605 11380
718e3744 11381/* Redistribute VTY commands. */
11382
718e3744 11383DEFUN (bgp_redistribute_ipv4,
11384 bgp_redistribute_ipv4_cmd,
40d1cbfb 11385 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11386 "Redistribute information from another routing protocol\n"
ab0181ee 11387 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11388{
d62a17ae 11389 VTY_DECLVAR_CONTEXT(bgp, bgp);
11390 int idx_protocol = 1;
11391 int type;
718e3744 11392
d62a17ae 11393 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11394 if (type < 0) {
11395 vty_out(vty, "%% Invalid route type\n");
11396 return CMD_WARNING_CONFIG_FAILED;
11397 }
7f323236 11398
d62a17ae 11399 bgp_redist_add(bgp, AFI_IP, type, 0);
11400 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11401}
11402
d62a17ae 11403ALIAS_HIDDEN(
11404 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11405 "redistribute " FRR_IP_REDIST_STR_BGPD,
11406 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11407
718e3744 11408DEFUN (bgp_redistribute_ipv4_rmap,
11409 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11410 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11411 "Redistribute information from another routing protocol\n"
ab0181ee 11412 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11413 "Route map reference\n"
11414 "Pointer to route-map entries\n")
11415{
d62a17ae 11416 VTY_DECLVAR_CONTEXT(bgp, bgp);
11417 int idx_protocol = 1;
11418 int idx_word = 3;
11419 int type;
11420 struct bgp_redist *red;
718e3744 11421
d62a17ae 11422 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11423 if (type < 0) {
11424 vty_out(vty, "%% Invalid route type\n");
11425 return CMD_WARNING_CONFIG_FAILED;
11426 }
718e3744 11427
d62a17ae 11428 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11429 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11430 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11431}
11432
d62a17ae 11433ALIAS_HIDDEN(
11434 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11435 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11436 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11437 "Route map reference\n"
11438 "Pointer to route-map entries\n")
596c17ba 11439
718e3744 11440DEFUN (bgp_redistribute_ipv4_metric,
11441 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11442 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11443 "Redistribute information from another routing protocol\n"
ab0181ee 11444 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11445 "Metric for redistributed routes\n"
11446 "Default metric\n")
11447{
d62a17ae 11448 VTY_DECLVAR_CONTEXT(bgp, bgp);
11449 int idx_protocol = 1;
11450 int idx_number = 3;
11451 int type;
d7c0a89a 11452 uint32_t metric;
d62a17ae 11453 struct bgp_redist *red;
11454
11455 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11456 if (type < 0) {
11457 vty_out(vty, "%% Invalid route type\n");
11458 return CMD_WARNING_CONFIG_FAILED;
11459 }
11460 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11461
11462 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11463 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11464 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11465}
11466
11467ALIAS_HIDDEN(
11468 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11469 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11470 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11471 "Metric for redistributed routes\n"
11472 "Default metric\n")
596c17ba 11473
718e3744 11474DEFUN (bgp_redistribute_ipv4_rmap_metric,
11475 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11476 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11477 "Redistribute information from another routing protocol\n"
ab0181ee 11478 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11479 "Route map reference\n"
11480 "Pointer to route-map entries\n"
11481 "Metric for redistributed routes\n"
11482 "Default metric\n")
11483{
d62a17ae 11484 VTY_DECLVAR_CONTEXT(bgp, bgp);
11485 int idx_protocol = 1;
11486 int idx_word = 3;
11487 int idx_number = 5;
11488 int type;
d7c0a89a 11489 uint32_t metric;
d62a17ae 11490 struct bgp_redist *red;
11491
11492 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11493 if (type < 0) {
11494 vty_out(vty, "%% Invalid route type\n");
11495 return CMD_WARNING_CONFIG_FAILED;
11496 }
11497 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11498
11499 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11500 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11501 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11502 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11503}
11504
11505ALIAS_HIDDEN(
11506 bgp_redistribute_ipv4_rmap_metric,
11507 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11508 "redistribute " FRR_IP_REDIST_STR_BGPD
11509 " route-map WORD metric (0-4294967295)",
11510 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11511 "Route map reference\n"
11512 "Pointer to route-map entries\n"
11513 "Metric for redistributed routes\n"
11514 "Default metric\n")
596c17ba 11515
718e3744 11516DEFUN (bgp_redistribute_ipv4_metric_rmap,
11517 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11518 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11519 "Redistribute information from another routing protocol\n"
ab0181ee 11520 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11521 "Metric for redistributed routes\n"
11522 "Default metric\n"
11523 "Route map reference\n"
11524 "Pointer to route-map entries\n")
11525{
d62a17ae 11526 VTY_DECLVAR_CONTEXT(bgp, bgp);
11527 int idx_protocol = 1;
11528 int idx_number = 3;
11529 int idx_word = 5;
11530 int type;
d7c0a89a 11531 uint32_t metric;
d62a17ae 11532 struct bgp_redist *red;
11533
11534 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11535 if (type < 0) {
11536 vty_out(vty, "%% Invalid route type\n");
11537 return CMD_WARNING_CONFIG_FAILED;
11538 }
11539 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11540
11541 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11542 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11543 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11544 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11545}
11546
11547ALIAS_HIDDEN(
11548 bgp_redistribute_ipv4_metric_rmap,
11549 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11550 "redistribute " FRR_IP_REDIST_STR_BGPD
11551 " metric (0-4294967295) route-map WORD",
11552 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11553 "Metric for redistributed routes\n"
11554 "Default metric\n"
11555 "Route map reference\n"
11556 "Pointer to route-map entries\n")
596c17ba 11557
7c8ff89e
DS
11558DEFUN (bgp_redistribute_ipv4_ospf,
11559 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11560 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11561 "Redistribute information from another routing protocol\n"
11562 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11563 "Non-main Kernel Routing Table\n"
11564 "Instance ID/Table ID\n")
7c8ff89e 11565{
d62a17ae 11566 VTY_DECLVAR_CONTEXT(bgp, bgp);
11567 int idx_ospf_table = 1;
11568 int idx_number = 2;
d7c0a89a
QY
11569 unsigned short instance;
11570 unsigned short protocol;
7c8ff89e 11571
d62a17ae 11572 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11573
d62a17ae 11574 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11575 protocol = ZEBRA_ROUTE_OSPF;
11576 else
11577 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11578
d62a17ae 11579 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11580 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
11581}
11582
d62a17ae 11583ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11584 "redistribute <ospf|table> (1-65535)",
11585 "Redistribute information from another routing protocol\n"
11586 "Open Shortest Path First (OSPFv2)\n"
11587 "Non-main Kernel Routing Table\n"
11588 "Instance ID/Table ID\n")
596c17ba 11589
7c8ff89e
DS
11590DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11591 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11592 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11593 "Redistribute information from another routing protocol\n"
11594 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11595 "Non-main Kernel Routing Table\n"
11596 "Instance ID/Table ID\n"
7c8ff89e
DS
11597 "Route map reference\n"
11598 "Pointer to route-map entries\n")
11599{
d62a17ae 11600 VTY_DECLVAR_CONTEXT(bgp, bgp);
11601 int idx_ospf_table = 1;
11602 int idx_number = 2;
11603 int idx_word = 4;
11604 struct bgp_redist *red;
d7c0a89a 11605 unsigned short instance;
d62a17ae 11606 int protocol;
11607
11608 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11609 protocol = ZEBRA_ROUTE_OSPF;
11610 else
11611 protocol = ZEBRA_ROUTE_TABLE;
11612
11613 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11614 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11615 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11616 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11617}
11618
11619ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11620 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11621 "redistribute <ospf|table> (1-65535) route-map WORD",
11622 "Redistribute information from another routing protocol\n"
11623 "Open Shortest Path First (OSPFv2)\n"
11624 "Non-main Kernel Routing Table\n"
11625 "Instance ID/Table ID\n"
11626 "Route map reference\n"
11627 "Pointer to route-map entries\n")
596c17ba 11628
7c8ff89e
DS
11629DEFUN (bgp_redistribute_ipv4_ospf_metric,
11630 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 11631 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
11632 "Redistribute information from another routing protocol\n"
11633 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11634 "Non-main Kernel Routing Table\n"
11635 "Instance ID/Table ID\n"
7c8ff89e
DS
11636 "Metric for redistributed routes\n"
11637 "Default metric\n")
11638{
d62a17ae 11639 VTY_DECLVAR_CONTEXT(bgp, bgp);
11640 int idx_ospf_table = 1;
11641 int idx_number = 2;
11642 int idx_number_2 = 4;
d7c0a89a 11643 uint32_t metric;
d62a17ae 11644 struct bgp_redist *red;
d7c0a89a 11645 unsigned short instance;
d62a17ae 11646 int protocol;
11647
11648 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11649 protocol = ZEBRA_ROUTE_OSPF;
11650 else
11651 protocol = ZEBRA_ROUTE_TABLE;
11652
11653 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11654 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11655
11656 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11657 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11658 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11659}
11660
11661ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11662 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11663 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11664 "Redistribute information from another routing protocol\n"
11665 "Open Shortest Path First (OSPFv2)\n"
11666 "Non-main Kernel Routing Table\n"
11667 "Instance ID/Table ID\n"
11668 "Metric for redistributed routes\n"
11669 "Default metric\n")
596c17ba 11670
7c8ff89e
DS
11671DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11672 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 11673 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
11674 "Redistribute information from another routing protocol\n"
11675 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11676 "Non-main Kernel Routing Table\n"
11677 "Instance ID/Table ID\n"
7c8ff89e
DS
11678 "Route map reference\n"
11679 "Pointer to route-map entries\n"
11680 "Metric for redistributed routes\n"
11681 "Default metric\n")
11682{
d62a17ae 11683 VTY_DECLVAR_CONTEXT(bgp, bgp);
11684 int idx_ospf_table = 1;
11685 int idx_number = 2;
11686 int idx_word = 4;
11687 int idx_number_2 = 6;
d7c0a89a 11688 uint32_t metric;
d62a17ae 11689 struct bgp_redist *red;
d7c0a89a 11690 unsigned short instance;
d62a17ae 11691 int protocol;
11692
11693 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11694 protocol = ZEBRA_ROUTE_OSPF;
11695 else
11696 protocol = ZEBRA_ROUTE_TABLE;
11697
11698 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11699 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11700
11701 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11702 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11703 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11704 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11705}
11706
11707ALIAS_HIDDEN(
11708 bgp_redistribute_ipv4_ospf_rmap_metric,
11709 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11710 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11711 "Redistribute information from another routing protocol\n"
11712 "Open Shortest Path First (OSPFv2)\n"
11713 "Non-main Kernel Routing Table\n"
11714 "Instance ID/Table ID\n"
11715 "Route map reference\n"
11716 "Pointer to route-map entries\n"
11717 "Metric for redistributed routes\n"
11718 "Default metric\n")
596c17ba 11719
7c8ff89e
DS
11720DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11721 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 11722 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
11723 "Redistribute information from another routing protocol\n"
11724 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11725 "Non-main Kernel Routing Table\n"
11726 "Instance ID/Table ID\n"
7c8ff89e
DS
11727 "Metric for redistributed routes\n"
11728 "Default metric\n"
11729 "Route map reference\n"
11730 "Pointer to route-map entries\n")
11731{
d62a17ae 11732 VTY_DECLVAR_CONTEXT(bgp, bgp);
11733 int idx_ospf_table = 1;
11734 int idx_number = 2;
11735 int idx_number_2 = 4;
11736 int idx_word = 6;
d7c0a89a 11737 uint32_t metric;
d62a17ae 11738 struct bgp_redist *red;
d7c0a89a 11739 unsigned short instance;
d62a17ae 11740 int protocol;
11741
11742 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11743 protocol = ZEBRA_ROUTE_OSPF;
11744 else
11745 protocol = ZEBRA_ROUTE_TABLE;
11746
11747 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11748 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11749
11750 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11751 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11752 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11753 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11754}
11755
11756ALIAS_HIDDEN(
11757 bgp_redistribute_ipv4_ospf_metric_rmap,
11758 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11759 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11760 "Redistribute information from another routing protocol\n"
11761 "Open Shortest Path First (OSPFv2)\n"
11762 "Non-main Kernel Routing Table\n"
11763 "Instance ID/Table ID\n"
11764 "Metric for redistributed routes\n"
11765 "Default metric\n"
11766 "Route map reference\n"
11767 "Pointer to route-map entries\n")
596c17ba 11768
7c8ff89e
DS
11769DEFUN (no_bgp_redistribute_ipv4_ospf,
11770 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 11771 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
11772 NO_STR
11773 "Redistribute information from another routing protocol\n"
11774 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 11775 "Non-main Kernel Routing Table\n"
31500417
DW
11776 "Instance ID/Table ID\n"
11777 "Metric for redistributed routes\n"
11778 "Default metric\n"
11779 "Route map reference\n"
11780 "Pointer to route-map entries\n")
7c8ff89e 11781{
d62a17ae 11782 VTY_DECLVAR_CONTEXT(bgp, bgp);
11783 int idx_ospf_table = 2;
11784 int idx_number = 3;
d7c0a89a 11785 unsigned short instance;
d62a17ae 11786 int protocol;
11787
11788 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11789 protocol = ZEBRA_ROUTE_OSPF;
11790 else
11791 protocol = ZEBRA_ROUTE_TABLE;
11792
11793 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11794 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11795}
11796
11797ALIAS_HIDDEN(
11798 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11799 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11800 NO_STR
11801 "Redistribute information from another routing protocol\n"
11802 "Open Shortest Path First (OSPFv2)\n"
11803 "Non-main Kernel Routing Table\n"
11804 "Instance ID/Table ID\n"
11805 "Metric for redistributed routes\n"
11806 "Default metric\n"
11807 "Route map reference\n"
11808 "Pointer to route-map entries\n")
596c17ba 11809
718e3744 11810DEFUN (no_bgp_redistribute_ipv4,
11811 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 11812 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11813 NO_STR
11814 "Redistribute information from another routing protocol\n"
3b14d86e 11815 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
11816 "Metric for redistributed routes\n"
11817 "Default metric\n"
11818 "Route map reference\n"
11819 "Pointer to route-map entries\n")
718e3744 11820{
d62a17ae 11821 VTY_DECLVAR_CONTEXT(bgp, bgp);
11822 int idx_protocol = 2;
11823 int type;
11824
11825 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11826 if (type < 0) {
11827 vty_out(vty, "%% Invalid route type\n");
11828 return CMD_WARNING_CONFIG_FAILED;
11829 }
11830 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11831}
11832
11833ALIAS_HIDDEN(
11834 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11835 "no redistribute " FRR_IP_REDIST_STR_BGPD
11836 " [metric (0-4294967295)] [route-map WORD]",
11837 NO_STR
11838 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11839 "Metric for redistributed routes\n"
11840 "Default metric\n"
11841 "Route map reference\n"
11842 "Pointer to route-map entries\n")
596c17ba 11843
718e3744 11844DEFUN (bgp_redistribute_ipv6,
11845 bgp_redistribute_ipv6_cmd,
40d1cbfb 11846 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11847 "Redistribute information from another routing protocol\n"
ab0181ee 11848 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11849{
d62a17ae 11850 VTY_DECLVAR_CONTEXT(bgp, bgp);
11851 int idx_protocol = 1;
11852 int type;
718e3744 11853
d62a17ae 11854 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11855 if (type < 0) {
11856 vty_out(vty, "%% Invalid route type\n");
11857 return CMD_WARNING_CONFIG_FAILED;
11858 }
718e3744 11859
d62a17ae 11860 bgp_redist_add(bgp, AFI_IP6, type, 0);
11861 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11862}
11863
11864DEFUN (bgp_redistribute_ipv6_rmap,
11865 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11866 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11867 "Redistribute information from another routing protocol\n"
ab0181ee 11868 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11869 "Route map reference\n"
11870 "Pointer to route-map entries\n")
11871{
d62a17ae 11872 VTY_DECLVAR_CONTEXT(bgp, bgp);
11873 int idx_protocol = 1;
11874 int idx_word = 3;
11875 int type;
11876 struct bgp_redist *red;
718e3744 11877
d62a17ae 11878 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11879 if (type < 0) {
11880 vty_out(vty, "%% Invalid route type\n");
11881 return CMD_WARNING_CONFIG_FAILED;
11882 }
718e3744 11883
d62a17ae 11884 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11885 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11886 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11887}
11888
11889DEFUN (bgp_redistribute_ipv6_metric,
11890 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11891 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11892 "Redistribute information from another routing protocol\n"
ab0181ee 11893 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11894 "Metric for redistributed routes\n"
11895 "Default metric\n")
11896{
d62a17ae 11897 VTY_DECLVAR_CONTEXT(bgp, bgp);
11898 int idx_protocol = 1;
11899 int idx_number = 3;
11900 int type;
d7c0a89a 11901 uint32_t metric;
d62a17ae 11902 struct bgp_redist *red;
11903
11904 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11905 if (type < 0) {
11906 vty_out(vty, "%% Invalid route type\n");
11907 return CMD_WARNING_CONFIG_FAILED;
11908 }
11909 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11910
d62a17ae 11911 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11912 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11913 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11914}
11915
11916DEFUN (bgp_redistribute_ipv6_rmap_metric,
11917 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11918 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11919 "Redistribute information from another routing protocol\n"
ab0181ee 11920 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11921 "Route map reference\n"
11922 "Pointer to route-map entries\n"
11923 "Metric for redistributed routes\n"
11924 "Default metric\n")
11925{
d62a17ae 11926 VTY_DECLVAR_CONTEXT(bgp, bgp);
11927 int idx_protocol = 1;
11928 int idx_word = 3;
11929 int idx_number = 5;
11930 int type;
d7c0a89a 11931 uint32_t metric;
d62a17ae 11932 struct bgp_redist *red;
11933
11934 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11935 if (type < 0) {
11936 vty_out(vty, "%% Invalid route type\n");
11937 return CMD_WARNING_CONFIG_FAILED;
11938 }
11939 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11940
d62a17ae 11941 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11942 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11943 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11944 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11945}
11946
11947DEFUN (bgp_redistribute_ipv6_metric_rmap,
11948 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11949 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11950 "Redistribute information from another routing protocol\n"
ab0181ee 11951 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11952 "Metric for redistributed routes\n"
11953 "Default metric\n"
11954 "Route map reference\n"
11955 "Pointer to route-map entries\n")
11956{
d62a17ae 11957 VTY_DECLVAR_CONTEXT(bgp, bgp);
11958 int idx_protocol = 1;
11959 int idx_number = 3;
11960 int idx_word = 5;
11961 int type;
d7c0a89a 11962 uint32_t metric;
d62a17ae 11963 struct bgp_redist *red;
11964
11965 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11966 if (type < 0) {
11967 vty_out(vty, "%% Invalid route type\n");
11968 return CMD_WARNING_CONFIG_FAILED;
11969 }
11970 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11971
d62a17ae 11972 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11973 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11974 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11975 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11976}
11977
11978DEFUN (no_bgp_redistribute_ipv6,
11979 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 11980 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11981 NO_STR
11982 "Redistribute information from another routing protocol\n"
3b14d86e 11983 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
11984 "Metric for redistributed routes\n"
11985 "Default metric\n"
11986 "Route map reference\n"
11987 "Pointer to route-map entries\n")
718e3744 11988{
d62a17ae 11989 VTY_DECLVAR_CONTEXT(bgp, bgp);
11990 int idx_protocol = 2;
11991 int type;
718e3744 11992
d62a17ae 11993 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11994 if (type < 0) {
11995 vty_out(vty, "%% Invalid route type\n");
11996 return CMD_WARNING_CONFIG_FAILED;
11997 }
718e3744 11998
d62a17ae 11999 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12000}
12001
2b791107 12002void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12003 safi_t safi)
d62a17ae 12004{
12005 int i;
12006
12007 /* Unicast redistribution only. */
12008 if (safi != SAFI_UNICAST)
2b791107 12009 return;
d62a17ae 12010
12011 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12012 /* Redistribute BGP does not make sense. */
12013 if (i != ZEBRA_ROUTE_BGP) {
12014 struct list *red_list;
12015 struct listnode *node;
12016 struct bgp_redist *red;
12017
12018 red_list = bgp->redist[afi][i];
12019 if (!red_list)
12020 continue;
12021
12022 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12023 /* "redistribute" configuration. */
12024 vty_out(vty, " redistribute %s",
12025 zebra_route_string(i));
12026 if (red->instance)
12027 vty_out(vty, " %d", red->instance);
12028 if (red->redist_metric_flag)
12029 vty_out(vty, " metric %u",
12030 red->redist_metric);
12031 if (red->rmap.name)
12032 vty_out(vty, " route-map %s",
12033 red->rmap.name);
12034 vty_out(vty, "\n");
12035 }
12036 }
12037 }
718e3744 12038}
6b0655a2 12039
b9c7bc5a
PZ
12040/* This is part of the address-family block (unicast only) */
12041void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12042 afi_t afi)
12043{
b9c7bc5a 12044 int indent = 2;
ddb5b488 12045
bb4f6190
DS
12046 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12047 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12048 bgp->vpn_policy[afi]
12049 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12050
12a844a5
DS
12051 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12052 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12053 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12054 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12055 return;
12056
e70e9f8e
PZ
12057 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12058 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12059
12060 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12061
12062 } else {
12063 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12064 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12065 bgp->vpn_policy[afi].tovpn_label);
12066 }
ddb5b488
PZ
12067 }
12068 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12069 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12070 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12071 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12072 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12073 sizeof(buf)));
12074 }
12075 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12076 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12077
12078 char buf[PREFIX_STRLEN];
12079 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12080 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12081 sizeof(buf))) {
12082
b9c7bc5a
PZ
12083 vty_out(vty, "%*snexthop vpn export %s\n",
12084 indent, "", buf);
ddb5b488
PZ
12085 }
12086 }
12087 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12088 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12089 && ecommunity_cmp(
12090 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12091 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12092
12093 char *b = ecommunity_ecom2str(
12094 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12095 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12096 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12097 XFREE(MTYPE_ECOMMUNITY_STR, b);
12098 } else {
12099 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12100 char *b = ecommunity_ecom2str(
12101 bgp->vpn_policy[afi]
12102 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12103 ECOMMUNITY_FORMAT_ROUTE_MAP,
12104 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12105 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12106 XFREE(MTYPE_ECOMMUNITY_STR, b);
12107 }
12108 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12109 char *b = ecommunity_ecom2str(
12110 bgp->vpn_policy[afi]
12111 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12112 ECOMMUNITY_FORMAT_ROUTE_MAP,
12113 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12114 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12115 XFREE(MTYPE_ECOMMUNITY_STR, b);
12116 }
12117 }
bb4f6190
DS
12118
12119 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12120 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12121 bgp->vpn_policy[afi]
12122 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12123
301ad80a
PG
12124 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12125 char *b = ecommunity_ecom2str(
12126 bgp->vpn_policy[afi]
12127 .import_redirect_rtlist,
12128 ECOMMUNITY_FORMAT_ROUTE_MAP,
12129 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12130
301ad80a
PG
12131 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12132 XFREE(MTYPE_ECOMMUNITY_STR, b);
12133 }
ddb5b488
PZ
12134}
12135
12136
718e3744 12137/* BGP node structure. */
d62a17ae 12138static struct cmd_node bgp_node = {
9d303b37 12139 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12140};
12141
d62a17ae 12142static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12143 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12144};
12145
d62a17ae 12146static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12147 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12148};
12149
d62a17ae 12150static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12151 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12152};
12153
d62a17ae 12154static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12155 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12156};
12157
d62a17ae 12158static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12159 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12160};
12161
d62a17ae 12162static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12163 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12164};
12165
d62a17ae 12166static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12167 "%s(config-router-af)# ", 1};
6b0655a2 12168
d62a17ae 12169static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12170 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12171
d62a17ae 12172static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12173 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12174
d62a17ae 12175static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12176 "%s(config-router-af-vni)# ", 1};
90e60aa7 12177
7c40bf39 12178static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12179 "%s(config-router-af)# ", 1};
12180
12181static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12182 "%s(config-router-af-vpnv6)# ", 1};
12183
d62a17ae 12184static void community_list_vty(void);
1f8ae70b 12185
d62a17ae 12186static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12187{
d62a17ae 12188 struct bgp *bgp;
12189 struct peer *peer;
d62a17ae 12190 struct listnode *lnbgp, *lnpeer;
b8a815e5 12191
d62a17ae 12192 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12193 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12194 /* only provide suggestions on the appropriate input
12195 * token type,
12196 * they'll otherwise show up multiple times */
12197 enum cmd_token_type match_type;
12198 char *name = peer->host;
d48ed3e0 12199
d62a17ae 12200 if (peer->conf_if) {
12201 match_type = VARIABLE_TKN;
12202 name = peer->conf_if;
12203 } else if (strchr(peer->host, ':'))
12204 match_type = IPV6_TKN;
12205 else
12206 match_type = IPV4_TKN;
d48ed3e0 12207
d62a17ae 12208 if (token->type != match_type)
12209 continue;
d48ed3e0 12210
d62a17ae 12211 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12212 }
d62a17ae 12213 }
b8a815e5
DL
12214}
12215
12216static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12217 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12218 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12219 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12220 {.completions = NULL}};
12221
47a306a0
DS
12222static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12223{
12224 struct bgp *bgp;
12225 struct peer_group *group;
12226 struct listnode *lnbgp, *lnpeer;
12227
12228 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12229 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12230 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12231 group->name));
12232 }
12233}
12234
12235static const struct cmd_variable_handler bgp_var_peergroup[] = {
12236 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12237 {.completions = NULL} };
12238
d62a17ae 12239void bgp_vty_init(void)
12240{
12241 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12242 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12243
12244 /* Install bgp top node. */
12245 install_node(&bgp_node, bgp_config_write);
12246 install_node(&bgp_ipv4_unicast_node, NULL);
12247 install_node(&bgp_ipv4_multicast_node, NULL);
12248 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12249 install_node(&bgp_ipv6_unicast_node, NULL);
12250 install_node(&bgp_ipv6_multicast_node, NULL);
12251 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12252 install_node(&bgp_vpnv4_node, NULL);
12253 install_node(&bgp_vpnv6_node, NULL);
12254 install_node(&bgp_evpn_node, NULL);
12255 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12256 install_node(&bgp_flowspecv4_node, NULL);
12257 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12258
12259 /* Install default VTY commands to new nodes. */
12260 install_default(BGP_NODE);
12261 install_default(BGP_IPV4_NODE);
12262 install_default(BGP_IPV4M_NODE);
12263 install_default(BGP_IPV4L_NODE);
12264 install_default(BGP_IPV6_NODE);
12265 install_default(BGP_IPV6M_NODE);
12266 install_default(BGP_IPV6L_NODE);
12267 install_default(BGP_VPNV4_NODE);
12268 install_default(BGP_VPNV6_NODE);
7c40bf39 12269 install_default(BGP_FLOWSPECV4_NODE);
12270 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12271 install_default(BGP_EVPN_NODE);
12272 install_default(BGP_EVPN_VNI_NODE);
12273
12274 /* "bgp multiple-instance" commands. */
12275 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12276 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12277
12278 /* "bgp config-type" commands. */
12279 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12280 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12281
12282 /* bgp route-map delay-timer commands. */
12283 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12284 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12285
12286 /* Dummy commands (Currently not supported) */
12287 install_element(BGP_NODE, &no_synchronization_cmd);
12288 install_element(BGP_NODE, &no_auto_summary_cmd);
12289
12290 /* "router bgp" commands. */
12291 install_element(CONFIG_NODE, &router_bgp_cmd);
12292
12293 /* "no router bgp" commands. */
12294 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12295
12296 /* "bgp router-id" commands. */
12297 install_element(BGP_NODE, &bgp_router_id_cmd);
12298 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12299
12300 /* "bgp cluster-id" commands. */
12301 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12302 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12303
12304 /* "bgp confederation" commands. */
12305 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12306 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12307
12308 /* "bgp confederation peers" commands. */
12309 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12310 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12311
12312 /* bgp max-med command */
12313 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12314 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12315 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12316 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12317 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12318
12319 /* bgp disable-ebgp-connected-nh-check */
12320 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12321 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12322
12323 /* bgp update-delay command */
12324 install_element(BGP_NODE, &bgp_update_delay_cmd);
12325 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12326 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12327
12328 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12329 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12330 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12331 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12332
12333 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12334 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12335
12336 /* "maximum-paths" commands. */
12337 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12338 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12339 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12340 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12341 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12342 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12343 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12344 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12345 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12346 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12347 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12348 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12349 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12350 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12351 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12352
12353 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12354 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12355 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12356 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12357 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12358
12359 /* "timers bgp" commands. */
12360 install_element(BGP_NODE, &bgp_timers_cmd);
12361 install_element(BGP_NODE, &no_bgp_timers_cmd);
12362
12363 /* route-map delay-timer commands - per instance for backwards compat.
12364 */
12365 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12366 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12367
12368 /* "bgp client-to-client reflection" commands */
12369 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12370 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12371
12372 /* "bgp always-compare-med" commands */
12373 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12374 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12375
12376 /* "bgp deterministic-med" commands */
12377 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12378 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12379
12380 /* "bgp graceful-restart" commands */
12381 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12382 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12383 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12384 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12385 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12386 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12387
12388 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12389 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12390
7f323236
DW
12391 /* "bgp graceful-shutdown" commands */
12392 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12393 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12394
d62a17ae 12395 /* "bgp fast-external-failover" commands */
12396 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12397 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12398
12399 /* "bgp enforce-first-as" commands */
12400 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12401 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
12402
12403 /* "bgp bestpath compare-routerid" commands */
12404 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12405 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12406
12407 /* "bgp bestpath as-path ignore" commands */
12408 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12409 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12410
12411 /* "bgp bestpath as-path confed" commands */
12412 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12413 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12414
12415 /* "bgp bestpath as-path multipath-relax" commands */
12416 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12417 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12418
12419 /* "bgp log-neighbor-changes" commands */
12420 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12421 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12422
12423 /* "bgp bestpath med" commands */
12424 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12425 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12426
12427 /* "no bgp default ipv4-unicast" commands. */
12428 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12429 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12430
12431 /* "bgp network import-check" commands. */
12432 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12433 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12434 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12435
12436 /* "bgp default local-preference" commands. */
12437 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12438 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12439
12440 /* bgp default show-hostname */
12441 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12442 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12443
12444 /* "bgp default subgroup-pkt-queue-max" commands. */
12445 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12446 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12447
12448 /* bgp ibgp-allow-policy-mods command */
12449 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12450 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12451
12452 /* "bgp listen limit" commands. */
12453 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12454 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12455
12456 /* "bgp listen range" commands. */
12457 install_element(BGP_NODE, &bgp_listen_range_cmd);
12458 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12459
8175f54a 12460 /* "bgp default shutdown" command */
f26845f9
QY
12461 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12462
d62a17ae 12463 /* "neighbor remote-as" commands. */
12464 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12465 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12466 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12467 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12468 install_element(BGP_NODE,
12469 &neighbor_interface_v6only_config_remote_as_cmd);
12470 install_element(BGP_NODE, &no_neighbor_cmd);
12471 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12472
12473 /* "neighbor peer-group" commands. */
12474 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12475 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12476 install_element(BGP_NODE,
12477 &no_neighbor_interface_peer_group_remote_as_cmd);
12478
12479 /* "neighbor local-as" commands. */
12480 install_element(BGP_NODE, &neighbor_local_as_cmd);
12481 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12482 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12483 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12484
12485 /* "neighbor solo" commands. */
12486 install_element(BGP_NODE, &neighbor_solo_cmd);
12487 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12488
12489 /* "neighbor password" commands. */
12490 install_element(BGP_NODE, &neighbor_password_cmd);
12491 install_element(BGP_NODE, &no_neighbor_password_cmd);
12492
12493 /* "neighbor activate" commands. */
12494 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12495 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12496 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12497 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12498 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12499 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12500 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12501 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12502 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 12503 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12504 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 12505 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12506
12507 /* "no neighbor activate" commands. */
12508 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12509 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12510 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12511 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12512 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12513 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12514 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12515 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12516 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 12517 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12518 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 12519 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12520
12521 /* "neighbor peer-group" set commands. */
12522 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12523 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12524 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12525 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12526 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12527 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12528 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12529 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 12530 install_element(BGP_FLOWSPECV4_NODE,
12531 &neighbor_set_peer_group_hidden_cmd);
12532 install_element(BGP_FLOWSPECV6_NODE,
12533 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 12534
12535 /* "no neighbor peer-group unset" commands. */
12536 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12537 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12538 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12539 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12540 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12541 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12542 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12543 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 12544 install_element(BGP_FLOWSPECV4_NODE,
12545 &no_neighbor_set_peer_group_hidden_cmd);
12546 install_element(BGP_FLOWSPECV6_NODE,
12547 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 12548
12549 /* "neighbor softreconfiguration inbound" commands.*/
12550 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12551 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12552 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12553 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12554 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12555 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12556 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12557 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12558 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12559 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12560 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12561 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12562 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12563 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12564 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12565 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12566 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12567 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 12568 install_element(BGP_FLOWSPECV4_NODE,
12569 &neighbor_soft_reconfiguration_cmd);
12570 install_element(BGP_FLOWSPECV4_NODE,
12571 &no_neighbor_soft_reconfiguration_cmd);
12572 install_element(BGP_FLOWSPECV6_NODE,
12573 &neighbor_soft_reconfiguration_cmd);
12574 install_element(BGP_FLOWSPECV6_NODE,
12575 &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 12576
12577 /* "neighbor attribute-unchanged" commands. */
12578 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12579 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12580 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12581 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12582 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12583 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12584 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12585 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12586 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12587 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12588 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12589 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12590 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12591 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12592 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12593 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12594 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12595 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12596
12597 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12598 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12599
12600 /* "nexthop-local unchanged" commands */
12601 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12602 install_element(BGP_IPV6_NODE,
12603 &no_neighbor_nexthop_local_unchanged_cmd);
12604
12605 /* "neighbor next-hop-self" commands. */
12606 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12607 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12608 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12609 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12610 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12611 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12612 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12613 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12614 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12615 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12616 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12617 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12618 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12619 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12620 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12621 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12622 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12623 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
12624 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12625 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 12626
12627 /* "neighbor next-hop-self force" commands. */
12628 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12629 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12630 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12631 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12632 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12633 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12634 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12635 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12636 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12637 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12638 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12639 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12640 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12641 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12642 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12643 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12644 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12645 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12646
12647 /* "neighbor as-override" commands. */
12648 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12649 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12650 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12651 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12652 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12653 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12654 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12655 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12656 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12657 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12658 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12659 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12660 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12661 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12662 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12663 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12664 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12665 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12666
12667 /* "neighbor remove-private-AS" commands. */
12668 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12669 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12670 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12671 install_element(BGP_NODE,
12672 &no_neighbor_remove_private_as_all_hidden_cmd);
12673 install_element(BGP_NODE,
12674 &neighbor_remove_private_as_replace_as_hidden_cmd);
12675 install_element(BGP_NODE,
12676 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12677 install_element(BGP_NODE,
12678 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12679 install_element(
12680 BGP_NODE,
12681 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12682 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12683 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12684 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12685 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12686 install_element(BGP_IPV4_NODE,
12687 &neighbor_remove_private_as_replace_as_cmd);
12688 install_element(BGP_IPV4_NODE,
12689 &no_neighbor_remove_private_as_replace_as_cmd);
12690 install_element(BGP_IPV4_NODE,
12691 &neighbor_remove_private_as_all_replace_as_cmd);
12692 install_element(BGP_IPV4_NODE,
12693 &no_neighbor_remove_private_as_all_replace_as_cmd);
12694 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12695 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12696 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12697 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12698 install_element(BGP_IPV4M_NODE,
12699 &neighbor_remove_private_as_replace_as_cmd);
12700 install_element(BGP_IPV4M_NODE,
12701 &no_neighbor_remove_private_as_replace_as_cmd);
12702 install_element(BGP_IPV4M_NODE,
12703 &neighbor_remove_private_as_all_replace_as_cmd);
12704 install_element(BGP_IPV4M_NODE,
12705 &no_neighbor_remove_private_as_all_replace_as_cmd);
12706 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12707 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12708 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12709 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12710 install_element(BGP_IPV4L_NODE,
12711 &neighbor_remove_private_as_replace_as_cmd);
12712 install_element(BGP_IPV4L_NODE,
12713 &no_neighbor_remove_private_as_replace_as_cmd);
12714 install_element(BGP_IPV4L_NODE,
12715 &neighbor_remove_private_as_all_replace_as_cmd);
12716 install_element(BGP_IPV4L_NODE,
12717 &no_neighbor_remove_private_as_all_replace_as_cmd);
12718 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12719 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12720 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12721 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12722 install_element(BGP_IPV6_NODE,
12723 &neighbor_remove_private_as_replace_as_cmd);
12724 install_element(BGP_IPV6_NODE,
12725 &no_neighbor_remove_private_as_replace_as_cmd);
12726 install_element(BGP_IPV6_NODE,
12727 &neighbor_remove_private_as_all_replace_as_cmd);
12728 install_element(BGP_IPV6_NODE,
12729 &no_neighbor_remove_private_as_all_replace_as_cmd);
12730 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12731 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12732 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12733 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12734 install_element(BGP_IPV6M_NODE,
12735 &neighbor_remove_private_as_replace_as_cmd);
12736 install_element(BGP_IPV6M_NODE,
12737 &no_neighbor_remove_private_as_replace_as_cmd);
12738 install_element(BGP_IPV6M_NODE,
12739 &neighbor_remove_private_as_all_replace_as_cmd);
12740 install_element(BGP_IPV6M_NODE,
12741 &no_neighbor_remove_private_as_all_replace_as_cmd);
12742 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12743 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12744 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12745 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12746 install_element(BGP_IPV6L_NODE,
12747 &neighbor_remove_private_as_replace_as_cmd);
12748 install_element(BGP_IPV6L_NODE,
12749 &no_neighbor_remove_private_as_replace_as_cmd);
12750 install_element(BGP_IPV6L_NODE,
12751 &neighbor_remove_private_as_all_replace_as_cmd);
12752 install_element(BGP_IPV6L_NODE,
12753 &no_neighbor_remove_private_as_all_replace_as_cmd);
12754 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12755 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12756 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12757 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12758 install_element(BGP_VPNV4_NODE,
12759 &neighbor_remove_private_as_replace_as_cmd);
12760 install_element(BGP_VPNV4_NODE,
12761 &no_neighbor_remove_private_as_replace_as_cmd);
12762 install_element(BGP_VPNV4_NODE,
12763 &neighbor_remove_private_as_all_replace_as_cmd);
12764 install_element(BGP_VPNV4_NODE,
12765 &no_neighbor_remove_private_as_all_replace_as_cmd);
12766 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12767 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12768 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12769 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12770 install_element(BGP_VPNV6_NODE,
12771 &neighbor_remove_private_as_replace_as_cmd);
12772 install_element(BGP_VPNV6_NODE,
12773 &no_neighbor_remove_private_as_replace_as_cmd);
12774 install_element(BGP_VPNV6_NODE,
12775 &neighbor_remove_private_as_all_replace_as_cmd);
12776 install_element(BGP_VPNV6_NODE,
12777 &no_neighbor_remove_private_as_all_replace_as_cmd);
12778
12779 /* "neighbor send-community" commands.*/
12780 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12781 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12782 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12783 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12784 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12785 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12786 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12787 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12788 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12789 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12790 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12791 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12792 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12793 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12794 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12795 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12796 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12797 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12798 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12799 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12800 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12801 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12802 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12803 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12804 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12805 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12806 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12807 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12808 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12809 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12810 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12811 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12812 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12813 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12814 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12815 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12816
12817 /* "neighbor route-reflector" commands.*/
12818 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12819 install_element(BGP_NODE,
12820 &no_neighbor_route_reflector_client_hidden_cmd);
12821 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12822 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12823 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12824 install_element(BGP_IPV4M_NODE,
12825 &no_neighbor_route_reflector_client_cmd);
12826 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12827 install_element(BGP_IPV4L_NODE,
12828 &no_neighbor_route_reflector_client_cmd);
12829 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12830 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12831 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12832 install_element(BGP_IPV6M_NODE,
12833 &no_neighbor_route_reflector_client_cmd);
12834 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12835 install_element(BGP_IPV6L_NODE,
12836 &no_neighbor_route_reflector_client_cmd);
12837 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12838 install_element(BGP_VPNV4_NODE,
12839 &no_neighbor_route_reflector_client_cmd);
12840 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12841 install_element(BGP_VPNV6_NODE,
12842 &no_neighbor_route_reflector_client_cmd);
7c40bf39 12843 install_element(BGP_FLOWSPECV4_NODE,
12844 &neighbor_route_reflector_client_cmd);
12845 install_element(BGP_FLOWSPECV4_NODE,
12846 &no_neighbor_route_reflector_client_cmd);
12847 install_element(BGP_FLOWSPECV6_NODE,
12848 &neighbor_route_reflector_client_cmd);
12849 install_element(BGP_FLOWSPECV6_NODE,
12850 &no_neighbor_route_reflector_client_cmd);
d62a17ae 12851 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12852 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12853
12854 /* "neighbor route-server" commands.*/
12855 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12856 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12857 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12858 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12859 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12860 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12861 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12862 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12863 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12864 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12865 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12866 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12867 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12868 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12869 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12870 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12871 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12872 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 12873 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12874 install_element(BGP_FLOWSPECV4_NODE,
12875 &no_neighbor_route_server_client_cmd);
12876 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12877 install_element(BGP_FLOWSPECV6_NODE,
12878 &no_neighbor_route_server_client_cmd);
d62a17ae 12879
12880 /* "neighbor addpath-tx-all-paths" commands.*/
12881 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12882 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12883 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12884 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12885 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12886 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12887 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12888 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12889 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12890 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12891 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12892 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12893 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12894 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12895 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12896 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12897 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12898 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12899
12900 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12901 install_element(BGP_NODE,
12902 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12903 install_element(BGP_NODE,
12904 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12905 install_element(BGP_IPV4_NODE,
12906 &neighbor_addpath_tx_bestpath_per_as_cmd);
12907 install_element(BGP_IPV4_NODE,
12908 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12909 install_element(BGP_IPV4M_NODE,
12910 &neighbor_addpath_tx_bestpath_per_as_cmd);
12911 install_element(BGP_IPV4M_NODE,
12912 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12913 install_element(BGP_IPV4L_NODE,
12914 &neighbor_addpath_tx_bestpath_per_as_cmd);
12915 install_element(BGP_IPV4L_NODE,
12916 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12917 install_element(BGP_IPV6_NODE,
12918 &neighbor_addpath_tx_bestpath_per_as_cmd);
12919 install_element(BGP_IPV6_NODE,
12920 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12921 install_element(BGP_IPV6M_NODE,
12922 &neighbor_addpath_tx_bestpath_per_as_cmd);
12923 install_element(BGP_IPV6M_NODE,
12924 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12925 install_element(BGP_IPV6L_NODE,
12926 &neighbor_addpath_tx_bestpath_per_as_cmd);
12927 install_element(BGP_IPV6L_NODE,
12928 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12929 install_element(BGP_VPNV4_NODE,
12930 &neighbor_addpath_tx_bestpath_per_as_cmd);
12931 install_element(BGP_VPNV4_NODE,
12932 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12933 install_element(BGP_VPNV6_NODE,
12934 &neighbor_addpath_tx_bestpath_per_as_cmd);
12935 install_element(BGP_VPNV6_NODE,
12936 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12937
12938 /* "neighbor passive" commands. */
12939 install_element(BGP_NODE, &neighbor_passive_cmd);
12940 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12941
12942
12943 /* "neighbor shutdown" commands. */
12944 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12945 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12946 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12947 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12948
12949 /* "neighbor capability extended-nexthop" commands.*/
12950 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12951 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12952
12953 /* "neighbor capability orf prefix-list" commands.*/
12954 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12955 install_element(BGP_NODE,
12956 &no_neighbor_capability_orf_prefix_hidden_cmd);
12957 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12958 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12959 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
12960 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12961 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
12962 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12963 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
12964 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
12965 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
12966 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12967 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
12968 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12969
12970 /* "neighbor capability dynamic" commands.*/
12971 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
12972 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
12973
12974 /* "neighbor dont-capability-negotiate" commands. */
12975 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
12976 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
12977
12978 /* "neighbor ebgp-multihop" commands. */
12979 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
12980 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
12981 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
12982
12983 /* "neighbor disable-connected-check" commands. */
12984 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
12985 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
12986
12987 /* "neighbor description" commands. */
12988 install_element(BGP_NODE, &neighbor_description_cmd);
12989 install_element(BGP_NODE, &no_neighbor_description_cmd);
12990
12991 /* "neighbor update-source" commands. "*/
12992 install_element(BGP_NODE, &neighbor_update_source_cmd);
12993 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
12994
12995 /* "neighbor default-originate" commands. */
12996 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
12997 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
12998 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
12999 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13000 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13001 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13002 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13003 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13004 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13005 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13006 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13007 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13008 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13009 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13010 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13011 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13012 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13013 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13014 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13015 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13016 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13017
13018 /* "neighbor port" commands. */
13019 install_element(BGP_NODE, &neighbor_port_cmd);
13020 install_element(BGP_NODE, &no_neighbor_port_cmd);
13021
13022 /* "neighbor weight" commands. */
13023 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13024 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13025
13026 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13027 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13028 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13029 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13030 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13031 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13032 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13033 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13034 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13035 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13036 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13037 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13038 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13039 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13040 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13041 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13042
13043 /* "neighbor override-capability" commands. */
13044 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13045 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13046
13047 /* "neighbor strict-capability-match" commands. */
13048 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13049 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13050
13051 /* "neighbor timers" commands. */
13052 install_element(BGP_NODE, &neighbor_timers_cmd);
13053 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13054
13055 /* "neighbor timers connect" commands. */
13056 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13057 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13058
13059 /* "neighbor advertisement-interval" commands. */
13060 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13061 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13062
13063 /* "neighbor interface" commands. */
13064 install_element(BGP_NODE, &neighbor_interface_cmd);
13065 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13066
13067 /* "neighbor distribute" commands. */
13068 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13069 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13070 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13071 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13072 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13073 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13074 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13075 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13076 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13077 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13078 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13079 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13080 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13081 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13082 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13083 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13084 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13085 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13086
13087 /* "neighbor prefix-list" commands. */
13088 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13089 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13090 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13091 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13092 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13093 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13094 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13095 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13096 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13097 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13098 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13099 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13100 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13101 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13102 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13103 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13104 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13105 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13106 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13107 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13108 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13109 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13110
13111 /* "neighbor filter-list" commands. */
13112 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13113 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13114 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13115 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13116 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13117 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13118 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13119 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13120 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13121 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13122 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13123 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13124 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13125 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13126 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13127 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13128 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13129 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13130 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13131 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13132 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13133 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13134
13135 /* "neighbor route-map" commands. */
13136 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13137 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13138 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13139 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13140 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13141 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13142 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13143 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13144 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13145 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13146 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13147 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13148 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13149 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13150 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13151 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13152 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13153 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13154 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13155 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13156 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13157 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13158 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13159 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13160
13161 /* "neighbor unsuppress-map" commands. */
13162 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13163 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13164 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13165 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13166 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13167 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13168 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13169 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13170 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13171 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13172 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13173 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13174 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13175 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13176 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13177 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13178 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13179 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13180
13181 /* "neighbor maximum-prefix" commands. */
13182 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13183 install_element(BGP_NODE,
13184 &neighbor_maximum_prefix_threshold_hidden_cmd);
13185 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13186 install_element(BGP_NODE,
13187 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13188 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13189 install_element(BGP_NODE,
13190 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13191 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13192 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13193 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13194 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13195 install_element(BGP_IPV4_NODE,
13196 &neighbor_maximum_prefix_threshold_warning_cmd);
13197 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13198 install_element(BGP_IPV4_NODE,
13199 &neighbor_maximum_prefix_threshold_restart_cmd);
13200 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13201 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13202 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13203 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13204 install_element(BGP_IPV4M_NODE,
13205 &neighbor_maximum_prefix_threshold_warning_cmd);
13206 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13207 install_element(BGP_IPV4M_NODE,
13208 &neighbor_maximum_prefix_threshold_restart_cmd);
13209 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13210 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13211 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13212 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13213 install_element(BGP_IPV4L_NODE,
13214 &neighbor_maximum_prefix_threshold_warning_cmd);
13215 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13216 install_element(BGP_IPV4L_NODE,
13217 &neighbor_maximum_prefix_threshold_restart_cmd);
13218 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13219 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13220 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13221 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13222 install_element(BGP_IPV6_NODE,
13223 &neighbor_maximum_prefix_threshold_warning_cmd);
13224 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13225 install_element(BGP_IPV6_NODE,
13226 &neighbor_maximum_prefix_threshold_restart_cmd);
13227 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13228 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13229 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13230 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13231 install_element(BGP_IPV6M_NODE,
13232 &neighbor_maximum_prefix_threshold_warning_cmd);
13233 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13234 install_element(BGP_IPV6M_NODE,
13235 &neighbor_maximum_prefix_threshold_restart_cmd);
13236 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13237 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13238 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13239 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13240 install_element(BGP_IPV6L_NODE,
13241 &neighbor_maximum_prefix_threshold_warning_cmd);
13242 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13243 install_element(BGP_IPV6L_NODE,
13244 &neighbor_maximum_prefix_threshold_restart_cmd);
13245 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13246 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13247 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13248 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13249 install_element(BGP_VPNV4_NODE,
13250 &neighbor_maximum_prefix_threshold_warning_cmd);
13251 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13252 install_element(BGP_VPNV4_NODE,
13253 &neighbor_maximum_prefix_threshold_restart_cmd);
13254 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13255 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13256 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13257 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13258 install_element(BGP_VPNV6_NODE,
13259 &neighbor_maximum_prefix_threshold_warning_cmd);
13260 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13261 install_element(BGP_VPNV6_NODE,
13262 &neighbor_maximum_prefix_threshold_restart_cmd);
13263 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13264
13265 /* "neighbor allowas-in" */
13266 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13267 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13268 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13269 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13270 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13271 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13272 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13273 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13274 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13275 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13276 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13277 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13278 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13279 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13280 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13281 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13282 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13283 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13284 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13285 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13286
13287 /* address-family commands. */
13288 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13289 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13290#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13291 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13292 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13293#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13294
d62a17ae 13295 install_element(BGP_NODE, &address_family_evpn_cmd);
13296
13297 /* "exit-address-family" command. */
13298 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13299 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13300 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13301 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13302 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13303 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13304 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13305 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13306 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13307 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13308 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13309
13310 /* "clear ip bgp commands" */
13311 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13312
13313 /* clear ip bgp prefix */
13314 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13315 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13316 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13317
13318 /* "show [ip] bgp summary" commands. */
13319 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
d62a17ae 13320 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13321 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13322 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13323 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13324 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13325
13326 /* "show [ip] bgp neighbors" commands. */
13327 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13328
13329 /* "show [ip] bgp peer-group" commands. */
13330 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13331
13332 /* "show [ip] bgp paths" commands. */
13333 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13334
13335 /* "show [ip] bgp community" commands. */
13336 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13337
13338 /* "show ip bgp large-community" commands. */
13339 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13340 /* "show [ip] bgp attribute-info" commands. */
13341 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13342 /* "show [ip] bgp route-leak" command */
13343 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13344
13345 /* "redistribute" commands. */
13346 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13347 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13348 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13349 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13350 install_element(BGP_NODE,
13351 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13352 install_element(BGP_NODE,
13353 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13354 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13355 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13356 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13357 install_element(BGP_NODE,
13358 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13359 install_element(BGP_NODE,
13360 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13361 install_element(BGP_NODE,
13362 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13363 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13364 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13365 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13366 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13367 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13368 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13369 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13370 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13371 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13372 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13373 install_element(BGP_IPV4_NODE,
13374 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13375 install_element(BGP_IPV4_NODE,
13376 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13377 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13378 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13379 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13380 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13381 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13382 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13383
b9c7bc5a
PZ
13384 /* import|export vpn [route-map WORD] */
13385 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13386 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13387
12a844a5
DS
13388 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13389 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13390
d62a17ae 13391 /* ttl_security commands */
13392 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13393 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13394
13395 /* "show [ip] bgp memory" commands. */
13396 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13397
acf71666
MK
13398 /* "show bgp martian next-hop" */
13399 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13400
d62a17ae 13401 /* "show [ip] bgp views" commands. */
13402 install_element(VIEW_NODE, &show_bgp_views_cmd);
13403
13404 /* "show [ip] bgp vrfs" commands. */
13405 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13406
13407 /* Community-list. */
13408 community_list_vty();
ddb5b488
PZ
13409
13410 /* vpn-policy commands */
b9c7bc5a
PZ
13411 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13412 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13413 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13414 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13415 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13416 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13417 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13418 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13419 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13420 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
13421 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13422 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 13423
301ad80a
PG
13424 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13425 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13426
b9c7bc5a
PZ
13427 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13428 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13429 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13430 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13431 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13432 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13433 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13434 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13435 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13436 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
13437 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13438 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 13439}
6b0655a2 13440
718e3744 13441#include "memory.h"
13442#include "bgp_regex.h"
13443#include "bgp_clist.h"
13444#include "bgp_ecommunity.h"
13445
13446/* VTY functions. */
13447
13448/* Direction value to string conversion. */
d62a17ae 13449static const char *community_direct_str(int direct)
13450{
13451 switch (direct) {
13452 case COMMUNITY_DENY:
13453 return "deny";
13454 case COMMUNITY_PERMIT:
13455 return "permit";
13456 default:
13457 return "unknown";
13458 }
718e3744 13459}
13460
13461/* Display error string. */
d62a17ae 13462static void community_list_perror(struct vty *vty, int ret)
13463{
13464 switch (ret) {
13465 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13466 vty_out(vty, "%% Can't find community-list\n");
13467 break;
13468 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13469 vty_out(vty, "%% Malformed community-list value\n");
13470 break;
13471 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13472 vty_out(vty,
13473 "%% Community name conflict, previously defined as standard community\n");
13474 break;
13475 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13476 vty_out(vty,
13477 "%% Community name conflict, previously defined as expanded community\n");
13478 break;
13479 }
718e3744 13480}
13481
5bf15956
DW
13482/* "community-list" keyword help string. */
13483#define COMMUNITY_LIST_STR "Add a community list entry\n"
13484
5bf15956 13485/* ip community-list standard */
718e3744 13486DEFUN (ip_community_list_standard,
13487 ip_community_list_standard_cmd,
e961923c 13488 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13489 IP_STR
13490 COMMUNITY_LIST_STR
13491 "Community list number (standard)\n"
5bf15956 13492 "Add an standard community-list entry\n"
718e3744 13493 "Community list name\n"
13494 "Specify community to reject\n"
13495 "Specify community to accept\n"
13496 COMMUNITY_VAL_STR)
13497{
d62a17ae 13498 char *cl_name_or_number = NULL;
13499 int direct = 0;
13500 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13501
d62a17ae 13502 int idx = 0;
13503 argv_find(argv, argc, "(1-99)", &idx);
13504 argv_find(argv, argc, "WORD", &idx);
13505 cl_name_or_number = argv[idx]->arg;
13506 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13507 : COMMUNITY_DENY;
13508 argv_find(argv, argc, "AA:NN", &idx);
13509 char *str = argv_concat(argv, argc, idx);
42f914d4 13510
d62a17ae 13511 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13512 style);
42f914d4 13513
d62a17ae 13514 XFREE(MTYPE_TMP, str);
42f914d4 13515
d62a17ae 13516 if (ret < 0) {
13517 /* Display error string. */
13518 community_list_perror(vty, ret);
13519 return CMD_WARNING_CONFIG_FAILED;
13520 }
42f914d4 13521
d62a17ae 13522 return CMD_SUCCESS;
718e3744 13523}
13524
fee6e4e4 13525DEFUN (no_ip_community_list_standard_all,
13526 no_ip_community_list_standard_all_cmd,
e961923c 13527 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13528 NO_STR
13529 IP_STR
13530 COMMUNITY_LIST_STR
13531 "Community list number (standard)\n"
5bf15956
DW
13532 "Add an standard community-list entry\n"
13533 "Community list name\n"
718e3744 13534 "Specify community to reject\n"
13535 "Specify community to accept\n"
13536 COMMUNITY_VAL_STR)
13537{
d62a17ae 13538 char *cl_name_or_number = NULL;
13539 int direct = 0;
13540 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13541
d62a17ae 13542 int idx = 0;
13543 argv_find(argv, argc, "(1-99)", &idx);
13544 argv_find(argv, argc, "WORD", &idx);
13545 cl_name_or_number = argv[idx]->arg;
13546 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13547 : COMMUNITY_DENY;
13548 argv_find(argv, argc, "AA:NN", &idx);
13549 char *str = argv_concat(argv, argc, idx);
42f914d4 13550
d62a17ae 13551 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13552 direct, style);
42f914d4 13553
d62a17ae 13554 XFREE(MTYPE_TMP, str);
daf9ddbb 13555
d62a17ae 13556 if (ret < 0) {
13557 community_list_perror(vty, ret);
13558 return CMD_WARNING_CONFIG_FAILED;
13559 }
42f914d4 13560
d62a17ae 13561 return CMD_SUCCESS;
718e3744 13562}
13563
5bf15956
DW
13564/* ip community-list expanded */
13565DEFUN (ip_community_list_expanded_all,
13566 ip_community_list_expanded_all_cmd,
42f914d4 13567 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13568 IP_STR
13569 COMMUNITY_LIST_STR
13570 "Community list number (expanded)\n"
5bf15956 13571 "Add an expanded community-list entry\n"
718e3744 13572 "Community list name\n"
13573 "Specify community to reject\n"
13574 "Specify community to accept\n"
13575 COMMUNITY_VAL_STR)
13576{
d62a17ae 13577 char *cl_name_or_number = NULL;
13578 int direct = 0;
13579 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13580
d62a17ae 13581 int idx = 0;
13582 argv_find(argv, argc, "(100-500)", &idx);
13583 argv_find(argv, argc, "WORD", &idx);
13584 cl_name_or_number = argv[idx]->arg;
13585 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13586 : COMMUNITY_DENY;
13587 argv_find(argv, argc, "AA:NN", &idx);
13588 char *str = argv_concat(argv, argc, idx);
42f914d4 13589
d62a17ae 13590 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13591 style);
42f914d4 13592
d62a17ae 13593 XFREE(MTYPE_TMP, str);
42f914d4 13594
d62a17ae 13595 if (ret < 0) {
13596 /* Display error string. */
13597 community_list_perror(vty, ret);
13598 return CMD_WARNING_CONFIG_FAILED;
13599 }
42f914d4 13600
d62a17ae 13601 return CMD_SUCCESS;
718e3744 13602}
13603
5bf15956
DW
13604DEFUN (no_ip_community_list_expanded_all,
13605 no_ip_community_list_expanded_all_cmd,
42f914d4 13606 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13607 NO_STR
13608 IP_STR
13609 COMMUNITY_LIST_STR
5bf15956
DW
13610 "Community list number (expanded)\n"
13611 "Add an expanded community-list entry\n"
718e3744 13612 "Community list name\n"
13613 "Specify community to reject\n"
13614 "Specify community to accept\n"
5bf15956 13615 COMMUNITY_VAL_STR)
718e3744 13616{
d62a17ae 13617 char *cl_name_or_number = NULL;
13618 int direct = 0;
13619 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13620
d62a17ae 13621 int idx = 0;
13622 argv_find(argv, argc, "(100-500)", &idx);
13623 argv_find(argv, argc, "WORD", &idx);
13624 cl_name_or_number = argv[idx]->arg;
13625 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13626 : COMMUNITY_DENY;
13627 argv_find(argv, argc, "AA:NN", &idx);
13628 char *str = argv_concat(argv, argc, idx);
42f914d4 13629
d62a17ae 13630 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13631 direct, style);
42f914d4 13632
d62a17ae 13633 XFREE(MTYPE_TMP, str);
daf9ddbb 13634
d62a17ae 13635 if (ret < 0) {
13636 community_list_perror(vty, ret);
13637 return CMD_WARNING_CONFIG_FAILED;
13638 }
42f914d4 13639
d62a17ae 13640 return CMD_SUCCESS;
718e3744 13641}
13642
8d9b8ed9
PM
13643/* Return configuration string of community-list entry. */
13644static const char *community_list_config_str(struct community_entry *entry)
13645{
13646 const char *str;
13647
13648 if (entry->any)
13649 str = "";
13650 else {
13651 if (entry->style == COMMUNITY_LIST_STANDARD)
13652 str = community_str(entry->u.com, false);
13653 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13654 str = lcommunity_str(entry->u.lcom, false);
13655 else
13656 str = entry->config;
13657 }
13658 return str;
13659}
13660
d62a17ae 13661static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 13662{
d62a17ae 13663 struct community_entry *entry;
718e3744 13664
d62a17ae 13665 for (entry = list->head; entry; entry = entry->next) {
13666 if (entry == list->head) {
13667 if (all_digit(list->name))
13668 vty_out(vty, "Community %s list %s\n",
13669 entry->style == COMMUNITY_LIST_STANDARD
13670 ? "standard"
13671 : "(expanded) access",
13672 list->name);
13673 else
13674 vty_out(vty, "Named Community %s list %s\n",
13675 entry->style == COMMUNITY_LIST_STANDARD
13676 ? "standard"
13677 : "expanded",
13678 list->name);
13679 }
13680 if (entry->any)
13681 vty_out(vty, " %s\n",
13682 community_direct_str(entry->direct));
13683 else
13684 vty_out(vty, " %s %s\n",
13685 community_direct_str(entry->direct),
8d9b8ed9 13686 community_list_config_str(entry));
d62a17ae 13687 }
718e3744 13688}
13689
13690DEFUN (show_ip_community_list,
13691 show_ip_community_list_cmd,
13692 "show ip community-list",
13693 SHOW_STR
13694 IP_STR
13695 "List community-list\n")
13696{
d62a17ae 13697 struct community_list *list;
13698 struct community_list_master *cm;
718e3744 13699
d62a17ae 13700 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13701 if (!cm)
13702 return CMD_SUCCESS;
718e3744 13703
d62a17ae 13704 for (list = cm->num.head; list; list = list->next)
13705 community_list_show(vty, list);
718e3744 13706
d62a17ae 13707 for (list = cm->str.head; list; list = list->next)
13708 community_list_show(vty, list);
718e3744 13709
d62a17ae 13710 return CMD_SUCCESS;
718e3744 13711}
13712
13713DEFUN (show_ip_community_list_arg,
13714 show_ip_community_list_arg_cmd,
6147e2c6 13715 "show ip community-list <(1-500)|WORD>",
718e3744 13716 SHOW_STR
13717 IP_STR
13718 "List community-list\n"
13719 "Community-list number\n"
13720 "Community-list name\n")
13721{
d62a17ae 13722 int idx_comm_list = 3;
13723 struct community_list *list;
718e3744 13724
d62a17ae 13725 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13726 COMMUNITY_LIST_MASTER);
13727 if (!list) {
13728 vty_out(vty, "%% Can't find community-list\n");
13729 return CMD_WARNING;
13730 }
718e3744 13731
d62a17ae 13732 community_list_show(vty, list);
718e3744 13733
d62a17ae 13734 return CMD_SUCCESS;
718e3744 13735}
6b0655a2 13736
57d187bc
JS
13737/*
13738 * Large Community code.
13739 */
d62a17ae 13740static int lcommunity_list_set_vty(struct vty *vty, int argc,
13741 struct cmd_token **argv, int style,
13742 int reject_all_digit_name)
13743{
13744 int ret;
13745 int direct;
13746 char *str;
13747 int idx = 0;
13748 char *cl_name;
13749
13750 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13751 : COMMUNITY_DENY;
13752
13753 /* All digit name check. */
13754 idx = 0;
13755 argv_find(argv, argc, "WORD", &idx);
13756 argv_find(argv, argc, "(1-99)", &idx);
13757 argv_find(argv, argc, "(100-500)", &idx);
13758 cl_name = argv[idx]->arg;
13759 if (reject_all_digit_name && all_digit(cl_name)) {
13760 vty_out(vty, "%% Community name cannot have all digits\n");
13761 return CMD_WARNING_CONFIG_FAILED;
13762 }
13763
13764 idx = 0;
13765 argv_find(argv, argc, "AA:BB:CC", &idx);
13766 argv_find(argv, argc, "LINE", &idx);
13767 /* Concat community string argument. */
13768 if (idx)
13769 str = argv_concat(argv, argc, idx);
13770 else
13771 str = NULL;
13772
13773 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13774
13775 /* Free temporary community list string allocated by
13776 argv_concat(). */
13777 if (str)
13778 XFREE(MTYPE_TMP, str);
13779
13780 if (ret < 0) {
13781 community_list_perror(vty, ret);
13782 return CMD_WARNING_CONFIG_FAILED;
13783 }
13784 return CMD_SUCCESS;
13785}
13786
13787static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13788 struct cmd_token **argv, int style)
13789{
13790 int ret;
13791 int direct = 0;
13792 char *str = NULL;
13793 int idx = 0;
13794
13795 argv_find(argv, argc, "permit", &idx);
13796 argv_find(argv, argc, "deny", &idx);
13797
13798 if (idx) {
13799 /* Check the list direct. */
13800 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13801 direct = COMMUNITY_PERMIT;
13802 else
13803 direct = COMMUNITY_DENY;
13804
13805 idx = 0;
13806 argv_find(argv, argc, "LINE", &idx);
13807 argv_find(argv, argc, "AA:AA:NN", &idx);
13808 /* Concat community string argument. */
13809 str = argv_concat(argv, argc, idx);
13810 }
13811
13812 idx = 0;
13813 argv_find(argv, argc, "(1-99)", &idx);
13814 argv_find(argv, argc, "(100-500)", &idx);
13815 argv_find(argv, argc, "WORD", &idx);
13816
13817 /* Unset community list. */
13818 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13819 style);
13820
13821 /* Free temporary community list string allocated by
13822 argv_concat(). */
13823 if (str)
13824 XFREE(MTYPE_TMP, str);
13825
13826 if (ret < 0) {
13827 community_list_perror(vty, ret);
13828 return CMD_WARNING_CONFIG_FAILED;
13829 }
13830
13831 return CMD_SUCCESS;
57d187bc
JS
13832}
13833
13834/* "large-community-list" keyword help string. */
13835#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13836#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13837
13838DEFUN (ip_lcommunity_list_standard,
13839 ip_lcommunity_list_standard_cmd,
52951b63
DS
13840 "ip large-community-list (1-99) <deny|permit>",
13841 IP_STR
13842 LCOMMUNITY_LIST_STR
13843 "Large Community list number (standard)\n"
13844 "Specify large community to reject\n"
7111c1a0 13845 "Specify large community to accept\n")
52951b63 13846{
d62a17ae 13847 return lcommunity_list_set_vty(vty, argc, argv,
13848 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
13849}
13850
13851DEFUN (ip_lcommunity_list_standard1,
13852 ip_lcommunity_list_standard1_cmd,
13853 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
13854 IP_STR
13855 LCOMMUNITY_LIST_STR
13856 "Large Community list number (standard)\n"
13857 "Specify large community to reject\n"
13858 "Specify large community to accept\n"
13859 LCOMMUNITY_VAL_STR)
13860{
d62a17ae 13861 return lcommunity_list_set_vty(vty, argc, argv,
13862 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
13863}
13864
13865DEFUN (ip_lcommunity_list_expanded,
13866 ip_lcommunity_list_expanded_cmd,
13867 "ip large-community-list (100-500) <deny|permit> LINE...",
13868 IP_STR
13869 LCOMMUNITY_LIST_STR
13870 "Large Community list number (expanded)\n"
13871 "Specify large community to reject\n"
13872 "Specify large community to accept\n"
13873 "An ordered list as a regular-expression\n")
13874{
d62a17ae 13875 return lcommunity_list_set_vty(vty, argc, argv,
13876 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
13877}
13878
13879DEFUN (ip_lcommunity_list_name_standard,
13880 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
13881 "ip large-community-list standard WORD <deny|permit>",
13882 IP_STR
13883 LCOMMUNITY_LIST_STR
13884 "Specify standard large-community-list\n"
13885 "Large Community list name\n"
13886 "Specify large community to reject\n"
13887 "Specify large community to accept\n")
13888{
d62a17ae 13889 return lcommunity_list_set_vty(vty, argc, argv,
13890 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
13891}
13892
13893DEFUN (ip_lcommunity_list_name_standard1,
13894 ip_lcommunity_list_name_standard1_cmd,
13895 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
13896 IP_STR
13897 LCOMMUNITY_LIST_STR
13898 "Specify standard large-community-list\n"
13899 "Large Community list name\n"
13900 "Specify large community to reject\n"
13901 "Specify large community to accept\n"
13902 LCOMMUNITY_VAL_STR)
13903{
d62a17ae 13904 return lcommunity_list_set_vty(vty, argc, argv,
13905 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
13906}
13907
13908DEFUN (ip_lcommunity_list_name_expanded,
13909 ip_lcommunity_list_name_expanded_cmd,
13910 "ip large-community-list expanded WORD <deny|permit> LINE...",
13911 IP_STR
13912 LCOMMUNITY_LIST_STR
13913 "Specify expanded large-community-list\n"
13914 "Large Community list name\n"
13915 "Specify large community to reject\n"
13916 "Specify large community to accept\n"
13917 "An ordered list as a regular-expression\n")
13918{
d62a17ae 13919 return lcommunity_list_set_vty(vty, argc, argv,
13920 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
13921}
13922
13923DEFUN (no_ip_lcommunity_list_standard_all,
13924 no_ip_lcommunity_list_standard_all_cmd,
13925 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13926 NO_STR
13927 IP_STR
13928 LCOMMUNITY_LIST_STR
13929 "Large Community list number (standard)\n"
13930 "Large Community list number (expanded)\n"
13931 "Large Community list name\n")
13932{
d62a17ae 13933 return lcommunity_list_unset_vty(vty, argc, argv,
13934 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13935}
13936
13937DEFUN (no_ip_lcommunity_list_name_expanded_all,
13938 no_ip_lcommunity_list_name_expanded_all_cmd,
13939 "no ip large-community-list expanded WORD",
13940 NO_STR
13941 IP_STR
13942 LCOMMUNITY_LIST_STR
13943 "Specify expanded large-community-list\n"
13944 "Large Community list name\n")
13945{
d62a17ae 13946 return lcommunity_list_unset_vty(vty, argc, argv,
13947 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13948}
13949
13950DEFUN (no_ip_lcommunity_list_standard,
13951 no_ip_lcommunity_list_standard_cmd,
13952 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13953 NO_STR
13954 IP_STR
13955 LCOMMUNITY_LIST_STR
13956 "Large Community list number (standard)\n"
13957 "Specify large community to reject\n"
13958 "Specify large community to accept\n"
13959 LCOMMUNITY_VAL_STR)
13960{
d62a17ae 13961 return lcommunity_list_unset_vty(vty, argc, argv,
13962 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13963}
13964
13965DEFUN (no_ip_lcommunity_list_expanded,
13966 no_ip_lcommunity_list_expanded_cmd,
13967 "no ip large-community-list (100-500) <deny|permit> LINE...",
13968 NO_STR
13969 IP_STR
13970 LCOMMUNITY_LIST_STR
13971 "Large Community list number (expanded)\n"
13972 "Specify large community to reject\n"
13973 "Specify large community to accept\n"
13974 "An ordered list as a regular-expression\n")
13975{
d62a17ae 13976 return lcommunity_list_unset_vty(vty, argc, argv,
13977 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13978}
13979
13980DEFUN (no_ip_lcommunity_list_name_standard,
13981 no_ip_lcommunity_list_name_standard_cmd,
13982 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
13983 NO_STR
13984 IP_STR
13985 LCOMMUNITY_LIST_STR
13986 "Specify standard large-community-list\n"
13987 "Large Community list name\n"
13988 "Specify large community to reject\n"
13989 "Specify large community to accept\n"
13990 LCOMMUNITY_VAL_STR)
13991{
d62a17ae 13992 return lcommunity_list_unset_vty(vty, argc, argv,
13993 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13994}
13995
13996DEFUN (no_ip_lcommunity_list_name_expanded,
13997 no_ip_lcommunity_list_name_expanded_cmd,
13998 "no ip large-community-list expanded WORD <deny|permit> LINE...",
13999 NO_STR
14000 IP_STR
14001 LCOMMUNITY_LIST_STR
14002 "Specify expanded large-community-list\n"
14003 "Large community list name\n"
14004 "Specify large community to reject\n"
14005 "Specify large community to accept\n"
14006 "An ordered list as a regular-expression\n")
14007{
d62a17ae 14008 return lcommunity_list_unset_vty(vty, argc, argv,
14009 LARGE_COMMUNITY_LIST_EXPANDED);
14010}
14011
14012static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14013{
14014 struct community_entry *entry;
14015
14016 for (entry = list->head; entry; entry = entry->next) {
14017 if (entry == list->head) {
14018 if (all_digit(list->name))
14019 vty_out(vty, "Large community %s list %s\n",
14020 entry->style == EXTCOMMUNITY_LIST_STANDARD
14021 ? "standard"
14022 : "(expanded) access",
14023 list->name);
14024 else
14025 vty_out(vty,
14026 "Named large community %s list %s\n",
14027 entry->style == EXTCOMMUNITY_LIST_STANDARD
14028 ? "standard"
14029 : "expanded",
14030 list->name);
14031 }
14032 if (entry->any)
14033 vty_out(vty, " %s\n",
14034 community_direct_str(entry->direct));
14035 else
14036 vty_out(vty, " %s %s\n",
14037 community_direct_str(entry->direct),
8d9b8ed9 14038 community_list_config_str(entry));
d62a17ae 14039 }
57d187bc
JS
14040}
14041
14042DEFUN (show_ip_lcommunity_list,
14043 show_ip_lcommunity_list_cmd,
14044 "show ip large-community-list",
14045 SHOW_STR
14046 IP_STR
14047 "List large-community list\n")
14048{
d62a17ae 14049 struct community_list *list;
14050 struct community_list_master *cm;
57d187bc 14051
d62a17ae 14052 cm = community_list_master_lookup(bgp_clist,
14053 LARGE_COMMUNITY_LIST_MASTER);
14054 if (!cm)
14055 return CMD_SUCCESS;
57d187bc 14056
d62a17ae 14057 for (list = cm->num.head; list; list = list->next)
14058 lcommunity_list_show(vty, list);
57d187bc 14059
d62a17ae 14060 for (list = cm->str.head; list; list = list->next)
14061 lcommunity_list_show(vty, list);
57d187bc 14062
d62a17ae 14063 return CMD_SUCCESS;
57d187bc
JS
14064}
14065
14066DEFUN (show_ip_lcommunity_list_arg,
14067 show_ip_lcommunity_list_arg_cmd,
14068 "show ip large-community-list <(1-500)|WORD>",
14069 SHOW_STR
14070 IP_STR
14071 "List large-community list\n"
14072 "large-community-list number\n"
14073 "large-community-list name\n")
14074{
d62a17ae 14075 struct community_list *list;
57d187bc 14076
d62a17ae 14077 list = community_list_lookup(bgp_clist, argv[3]->arg,
14078 LARGE_COMMUNITY_LIST_MASTER);
14079 if (!list) {
14080 vty_out(vty, "%% Can't find extcommunity-list\n");
14081 return CMD_WARNING;
14082 }
57d187bc 14083
d62a17ae 14084 lcommunity_list_show(vty, list);
57d187bc 14085
d62a17ae 14086 return CMD_SUCCESS;
57d187bc
JS
14087}
14088
718e3744 14089/* "extcommunity-list" keyword help string. */
14090#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14091#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14092
14093DEFUN (ip_extcommunity_list_standard,
14094 ip_extcommunity_list_standard_cmd,
e961923c 14095 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14096 IP_STR
14097 EXTCOMMUNITY_LIST_STR
14098 "Extended Community list number (standard)\n"
718e3744 14099 "Specify standard extcommunity-list\n"
5bf15956 14100 "Community list name\n"
718e3744 14101 "Specify community to reject\n"
14102 "Specify community to accept\n"
14103 EXTCOMMUNITY_VAL_STR)
14104{
d62a17ae 14105 int style = EXTCOMMUNITY_LIST_STANDARD;
14106 int direct = 0;
14107 char *cl_number_or_name = NULL;
42f914d4 14108
d62a17ae 14109 int idx = 0;
14110 argv_find(argv, argc, "(1-99)", &idx);
14111 argv_find(argv, argc, "WORD", &idx);
14112 cl_number_or_name = argv[idx]->arg;
14113 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14114 : COMMUNITY_DENY;
14115 argv_find(argv, argc, "AA:NN", &idx);
14116 char *str = argv_concat(argv, argc, idx);
42f914d4 14117
d62a17ae 14118 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14119 direct, style);
42f914d4 14120
d62a17ae 14121 XFREE(MTYPE_TMP, str);
42f914d4 14122
d62a17ae 14123 if (ret < 0) {
14124 community_list_perror(vty, ret);
14125 return CMD_WARNING_CONFIG_FAILED;
14126 }
42f914d4 14127
d62a17ae 14128 return CMD_SUCCESS;
718e3744 14129}
14130
718e3744 14131DEFUN (ip_extcommunity_list_name_expanded,
14132 ip_extcommunity_list_name_expanded_cmd,
e961923c 14133 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14134 IP_STR
14135 EXTCOMMUNITY_LIST_STR
5bf15956 14136 "Extended Community list number (expanded)\n"
718e3744 14137 "Specify expanded extcommunity-list\n"
14138 "Extended Community list name\n"
14139 "Specify community to reject\n"
14140 "Specify community to accept\n"
14141 "An ordered list as a regular-expression\n")
14142{
d62a17ae 14143 int style = EXTCOMMUNITY_LIST_EXPANDED;
14144 int direct = 0;
14145 char *cl_number_or_name = NULL;
42f914d4 14146
d62a17ae 14147 int idx = 0;
14148 argv_find(argv, argc, "(100-500)", &idx);
14149 argv_find(argv, argc, "WORD", &idx);
14150 cl_number_or_name = argv[idx]->arg;
14151 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14152 : COMMUNITY_DENY;
14153 argv_find(argv, argc, "LINE", &idx);
14154 char *str = argv_concat(argv, argc, idx);
42f914d4 14155
d62a17ae 14156 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14157 direct, style);
42f914d4 14158
d62a17ae 14159 XFREE(MTYPE_TMP, str);
42f914d4 14160
d62a17ae 14161 if (ret < 0) {
14162 community_list_perror(vty, ret);
14163 return CMD_WARNING_CONFIG_FAILED;
14164 }
42f914d4 14165
d62a17ae 14166 return CMD_SUCCESS;
718e3744 14167}
14168
fee6e4e4 14169DEFUN (no_ip_extcommunity_list_standard_all,
14170 no_ip_extcommunity_list_standard_all_cmd,
e961923c 14171 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
14172 NO_STR
14173 IP_STR
14174 EXTCOMMUNITY_LIST_STR
14175 "Extended Community list number (standard)\n"
718e3744 14176 "Specify standard extcommunity-list\n"
5bf15956 14177 "Community list name\n"
718e3744 14178 "Specify community to reject\n"
14179 "Specify community to accept\n"
14180 EXTCOMMUNITY_VAL_STR)
14181{
d62a17ae 14182 int style = EXTCOMMUNITY_LIST_STANDARD;
14183 int direct = 0;
14184 char *cl_number_or_name = NULL;
42f914d4 14185
d62a17ae 14186 int idx = 0;
14187 argv_find(argv, argc, "(1-99)", &idx);
14188 argv_find(argv, argc, "WORD", &idx);
14189 cl_number_or_name = argv[idx]->arg;
14190 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14191 : COMMUNITY_DENY;
14192 argv_find(argv, argc, "AA:NN", &idx);
14193 char *str = argv_concat(argv, argc, idx);
42f914d4 14194
d62a17ae 14195 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14196 direct, style);
42f914d4 14197
d62a17ae 14198 XFREE(MTYPE_TMP, str);
42f914d4 14199
d62a17ae 14200 if (ret < 0) {
14201 community_list_perror(vty, ret);
14202 return CMD_WARNING_CONFIG_FAILED;
14203 }
42f914d4 14204
d62a17ae 14205 return CMD_SUCCESS;
718e3744 14206}
14207
5bf15956
DW
14208DEFUN (no_ip_extcommunity_list_expanded_all,
14209 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 14210 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14211 NO_STR
14212 IP_STR
14213 EXTCOMMUNITY_LIST_STR
14214 "Extended Community list number (expanded)\n"
718e3744 14215 "Specify expanded extcommunity-list\n"
5bf15956 14216 "Extended Community list name\n"
718e3744 14217 "Specify community to reject\n"
14218 "Specify community to accept\n"
14219 "An ordered list as a regular-expression\n")
14220{
d62a17ae 14221 int style = EXTCOMMUNITY_LIST_EXPANDED;
14222 int direct = 0;
14223 char *cl_number_or_name = NULL;
42f914d4 14224
d62a17ae 14225 int idx = 0;
14226 argv_find(argv, argc, "(100-500)", &idx);
14227 argv_find(argv, argc, "WORD", &idx);
14228 cl_number_or_name = argv[idx]->arg;
14229 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14230 : COMMUNITY_DENY;
14231 argv_find(argv, argc, "LINE", &idx);
14232 char *str = argv_concat(argv, argc, idx);
42f914d4 14233
d62a17ae 14234 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14235 direct, style);
42f914d4 14236
d62a17ae 14237 XFREE(MTYPE_TMP, str);
42f914d4 14238
d62a17ae 14239 if (ret < 0) {
14240 community_list_perror(vty, ret);
14241 return CMD_WARNING_CONFIG_FAILED;
14242 }
42f914d4 14243
d62a17ae 14244 return CMD_SUCCESS;
718e3744 14245}
14246
d62a17ae 14247static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 14248{
d62a17ae 14249 struct community_entry *entry;
718e3744 14250
d62a17ae 14251 for (entry = list->head; entry; entry = entry->next) {
14252 if (entry == list->head) {
14253 if (all_digit(list->name))
14254 vty_out(vty, "Extended community %s list %s\n",
14255 entry->style == EXTCOMMUNITY_LIST_STANDARD
14256 ? "standard"
14257 : "(expanded) access",
14258 list->name);
14259 else
14260 vty_out(vty,
14261 "Named extended community %s list %s\n",
14262 entry->style == EXTCOMMUNITY_LIST_STANDARD
14263 ? "standard"
14264 : "expanded",
14265 list->name);
14266 }
14267 if (entry->any)
14268 vty_out(vty, " %s\n",
14269 community_direct_str(entry->direct));
14270 else
14271 vty_out(vty, " %s %s\n",
14272 community_direct_str(entry->direct),
8d9b8ed9 14273 community_list_config_str(entry));
d62a17ae 14274 }
718e3744 14275}
14276
14277DEFUN (show_ip_extcommunity_list,
14278 show_ip_extcommunity_list_cmd,
14279 "show ip extcommunity-list",
14280 SHOW_STR
14281 IP_STR
14282 "List extended-community list\n")
14283{
d62a17ae 14284 struct community_list *list;
14285 struct community_list_master *cm;
718e3744 14286
d62a17ae 14287 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14288 if (!cm)
14289 return CMD_SUCCESS;
718e3744 14290
d62a17ae 14291 for (list = cm->num.head; list; list = list->next)
14292 extcommunity_list_show(vty, list);
718e3744 14293
d62a17ae 14294 for (list = cm->str.head; list; list = list->next)
14295 extcommunity_list_show(vty, list);
718e3744 14296
d62a17ae 14297 return CMD_SUCCESS;
718e3744 14298}
14299
14300DEFUN (show_ip_extcommunity_list_arg,
14301 show_ip_extcommunity_list_arg_cmd,
6147e2c6 14302 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 14303 SHOW_STR
14304 IP_STR
14305 "List extended-community list\n"
14306 "Extcommunity-list number\n"
14307 "Extcommunity-list name\n")
14308{
d62a17ae 14309 int idx_comm_list = 3;
14310 struct community_list *list;
718e3744 14311
d62a17ae 14312 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14313 EXTCOMMUNITY_LIST_MASTER);
14314 if (!list) {
14315 vty_out(vty, "%% Can't find extcommunity-list\n");
14316 return CMD_WARNING;
14317 }
718e3744 14318
d62a17ae 14319 extcommunity_list_show(vty, list);
718e3744 14320
d62a17ae 14321 return CMD_SUCCESS;
718e3744 14322}
6b0655a2 14323
718e3744 14324/* Display community-list and extcommunity-list configuration. */
d62a17ae 14325static int community_list_config_write(struct vty *vty)
14326{
14327 struct community_list *list;
14328 struct community_entry *entry;
14329 struct community_list_master *cm;
14330 int write = 0;
14331
14332 /* Community-list. */
14333 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14334
14335 for (list = cm->num.head; list; list = list->next)
14336 for (entry = list->head; entry; entry = entry->next) {
14337 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14338 community_direct_str(entry->direct),
14339 community_list_config_str(entry));
14340 write++;
14341 }
14342 for (list = cm->str.head; list; list = list->next)
14343 for (entry = list->head; entry; entry = entry->next) {
14344 vty_out(vty, "ip community-list %s %s %s %s\n",
14345 entry->style == COMMUNITY_LIST_STANDARD
14346 ? "standard"
14347 : "expanded",
14348 list->name, community_direct_str(entry->direct),
14349 community_list_config_str(entry));
14350 write++;
14351 }
14352
14353 /* Extcommunity-list. */
14354 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14355
14356 for (list = cm->num.head; list; list = list->next)
14357 for (entry = list->head; entry; entry = entry->next) {
14358 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14359 list->name, community_direct_str(entry->direct),
14360 community_list_config_str(entry));
14361 write++;
14362 }
14363 for (list = cm->str.head; list; list = list->next)
14364 for (entry = list->head; entry; entry = entry->next) {
14365 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14366 entry->style == EXTCOMMUNITY_LIST_STANDARD
14367 ? "standard"
14368 : "expanded",
14369 list->name, community_direct_str(entry->direct),
14370 community_list_config_str(entry));
14371 write++;
14372 }
14373
14374
14375 /* lcommunity-list. */
14376 cm = community_list_master_lookup(bgp_clist,
14377 LARGE_COMMUNITY_LIST_MASTER);
14378
14379 for (list = cm->num.head; list; list = list->next)
14380 for (entry = list->head; entry; entry = entry->next) {
14381 vty_out(vty, "ip large-community-list %s %s %s\n",
14382 list->name, community_direct_str(entry->direct),
14383 community_list_config_str(entry));
14384 write++;
14385 }
14386 for (list = cm->str.head; list; list = list->next)
14387 for (entry = list->head; entry; entry = entry->next) {
14388 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14389 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14390 ? "standard"
14391 : "expanded",
14392 list->name, community_direct_str(entry->direct),
14393 community_list_config_str(entry));
14394 write++;
14395 }
14396
14397 return write;
14398}
14399
14400static struct cmd_node community_list_node = {
14401 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 14402};
14403
d62a17ae 14404static void community_list_vty(void)
14405{
14406 install_node(&community_list_node, community_list_config_write);
14407
14408 /* Community-list. */
14409 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14410 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14411 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14412 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14413 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14414 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14415
14416 /* Extcommunity-list. */
14417 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14418 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14419 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14420 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14421 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14422 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14423
14424 /* Large Community List */
14425 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14426 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14427 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14428 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14429 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14430 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14431 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14432 install_element(CONFIG_NODE,
14433 &no_ip_lcommunity_list_name_expanded_all_cmd);
14434 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14435 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14436 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14437 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14438 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14439 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 14440}