]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: Improve test suite for peer-group overrides
[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. */
1cc40660
DS
774#if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
775CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
776CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
777#endif
778DEFUN_HIDDEN (bgp_multiple_instance_func,
779 bgp_multiple_instance_cmd,
780 "bgp multiple-instance",
781 BGP_STR
782 "Enable bgp multiple instance\n")
718e3744 783{
d62a17ae 784 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
785 return CMD_SUCCESS;
718e3744 786}
787
1cc40660 788DEFUN_HIDDEN (no_bgp_multiple_instance,
718e3744 789 no_bgp_multiple_instance_cmd,
790 "no bgp multiple-instance",
791 NO_STR
792 BGP_STR
793 "BGP multiple instance\n")
794{
d62a17ae 795 int ret;
718e3744 796
1cc40660
DS
797 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
798 vty_out(vty, "if you are using this please let the developers know\n");
799 zlog_warn("Deprecated option: `bgp multiple-instance` being used");
d62a17ae 800 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
801 if (ret < 0) {
802 vty_out(vty, "%% There are more than two BGP instances\n");
803 return CMD_WARNING_CONFIG_FAILED;
804 }
805 return CMD_SUCCESS;
718e3744 806}
807
798467a2
DS
808#if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
809CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
810CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
811#endif
812DEFUN_HIDDEN (bgp_config_type,
813 bgp_config_type_cmd,
814 "bgp config-type <cisco|zebra>",
815 BGP_STR
816 "Configuration type\n"
817 "cisco\n"
818 "zebra\n")
718e3744 819{
d62a17ae 820 int idx = 0;
798467a2
DS
821 if (argv_find(argv, argc, "cisco", &idx)) {
822 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
823 vty_out(vty, "if you are using this please let the developers know!\n");
824 zlog_warn("Deprecated option: `bgp config-type cisco` being used");
d62a17ae 825 bgp_option_set(BGP_OPT_CONFIG_CISCO);
798467a2 826 } else
d62a17ae 827 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 828
d62a17ae 829 return CMD_SUCCESS;
718e3744 830}
831
798467a2
DS
832DEFUN_HIDDEN (no_bgp_config_type,
833 no_bgp_config_type_cmd,
834 "no bgp config-type [<cisco|zebra>]",
835 NO_STR
836 BGP_STR
837 "Display configuration type\n"
838 "cisco\n"
839 "zebra\n")
718e3744 840{
d62a17ae 841 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
842 return CMD_SUCCESS;
718e3744 843}
844
813d4307 845
718e3744 846DEFUN (no_synchronization,
847 no_synchronization_cmd,
848 "no synchronization",
849 NO_STR
850 "Perform IGP synchronization\n")
851{
d62a17ae 852 return CMD_SUCCESS;
718e3744 853}
854
855DEFUN (no_auto_summary,
856 no_auto_summary_cmd,
857 "no auto-summary",
858 NO_STR
859 "Enable automatic network number summarization\n")
860{
d62a17ae 861 return CMD_SUCCESS;
718e3744 862}
3d515fd9 863
718e3744 864/* "router bgp" commands. */
505e5056 865DEFUN_NOSH (router_bgp,
f412b39a 866 router_bgp_cmd,
18c57037 867 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 868 ROUTER_STR
869 BGP_STR
31500417
DW
870 AS_STR
871 BGP_INSTANCE_HELP_STR)
718e3744 872{
d62a17ae 873 int idx_asn = 2;
874 int idx_view_vrf = 3;
875 int idx_vrf = 4;
876 int ret;
877 as_t as;
878 struct bgp *bgp;
879 const char *name = NULL;
880 enum bgp_instance_type inst_type;
881
882 // "router bgp" without an ASN
883 if (argc == 2) {
884 // Pending: Make VRF option available for ASN less config
885 bgp = bgp_get_default();
886
887 if (bgp == NULL) {
888 vty_out(vty, "%% No BGP process is configured\n");
889 return CMD_WARNING_CONFIG_FAILED;
890 }
891
892 if (listcount(bm->bgp) > 1) {
996c9314 893 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 894 return CMD_WARNING_CONFIG_FAILED;
895 }
896 }
897
898 // "router bgp X"
899 else {
900 as = strtoul(argv[idx_asn]->arg, NULL, 10);
901
902 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
903 if (argc > 3) {
904 name = argv[idx_vrf]->arg;
905
906 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
907 inst_type = BGP_INSTANCE_TYPE_VRF;
908 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
909 inst_type = BGP_INSTANCE_TYPE_VIEW;
910 }
911
912 ret = bgp_get(&bgp, &as, name, inst_type);
913 switch (ret) {
914 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
915 vty_out(vty,
916 "Please specify 'bgp multiple-instance' first\n");
917 return CMD_WARNING_CONFIG_FAILED;
918 case BGP_ERR_AS_MISMATCH:
919 vty_out(vty, "BGP is already running; AS is %u\n", as);
920 return CMD_WARNING_CONFIG_FAILED;
921 case BGP_ERR_INSTANCE_MISMATCH:
922 vty_out(vty,
923 "BGP instance name and AS number mismatch\n");
924 vty_out(vty,
925 "BGP instance is already running; AS is %u\n",
926 as);
927 return CMD_WARNING_CONFIG_FAILED;
928 }
929
930 /* Pending: handle when user tries to change a view to vrf n vv.
931 */
932 }
933
0b5131c9
MK
934 /* unset the auto created flag as the user config is now present */
935 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 936 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
937
938 return CMD_SUCCESS;
718e3744 939}
940
718e3744 941/* "no router bgp" commands. */
942DEFUN (no_router_bgp,
943 no_router_bgp_cmd,
18c57037 944 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 945 NO_STR
946 ROUTER_STR
947 BGP_STR
31500417
DW
948 AS_STR
949 BGP_INSTANCE_HELP_STR)
718e3744 950{
d62a17ae 951 int idx_asn = 3;
952 int idx_vrf = 5;
953 as_t as;
954 struct bgp *bgp;
955 const char *name = NULL;
718e3744 956
d62a17ae 957 // "no router bgp" without an ASN
958 if (argc == 3) {
959 // Pending: Make VRF option available for ASN less config
960 bgp = bgp_get_default();
718e3744 961
d62a17ae 962 if (bgp == NULL) {
963 vty_out(vty, "%% No BGP process is configured\n");
964 return CMD_WARNING_CONFIG_FAILED;
965 }
7fb21a9f 966
d62a17ae 967 if (listcount(bm->bgp) > 1) {
996c9314 968 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 969 return CMD_WARNING_CONFIG_FAILED;
970 }
0b5131c9
MK
971
972 if (bgp->l3vni) {
973 vty_out(vty, "%% Please unconfigure l3vni %u",
974 bgp->l3vni);
975 return CMD_WARNING_CONFIG_FAILED;
976 }
d62a17ae 977 } else {
978 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 979
d62a17ae 980 if (argc > 4)
981 name = argv[idx_vrf]->arg;
7fb21a9f 982
d62a17ae 983 /* Lookup bgp structure. */
984 bgp = bgp_lookup(as, name);
985 if (!bgp) {
986 vty_out(vty, "%% Can't find BGP instance\n");
987 return CMD_WARNING_CONFIG_FAILED;
988 }
0b5131c9
MK
989
990 if (bgp->l3vni) {
991 vty_out(vty, "%% Please unconfigure l3vni %u",
992 bgp->l3vni);
993 return CMD_WARNING_CONFIG_FAILED;
994 }
d62a17ae 995 }
718e3744 996
d62a17ae 997 bgp_delete(bgp);
718e3744 998
d62a17ae 999 return CMD_SUCCESS;
718e3744 1000}
1001
6b0655a2 1002
718e3744 1003/* BGP router-id. */
1004
f787d7a0 1005DEFPY (bgp_router_id,
718e3744 1006 bgp_router_id_cmd,
1007 "bgp router-id A.B.C.D",
1008 BGP_STR
1009 "Override configured router identifier\n"
1010 "Manually configured router identifier\n")
1011{
d62a17ae 1012 VTY_DECLVAR_CONTEXT(bgp, bgp);
1013 bgp_router_id_static_set(bgp, router_id);
1014 return CMD_SUCCESS;
718e3744 1015}
1016
f787d7a0 1017DEFPY (no_bgp_router_id,
718e3744 1018 no_bgp_router_id_cmd,
31500417 1019 "no bgp router-id [A.B.C.D]",
718e3744 1020 NO_STR
1021 BGP_STR
31500417
DW
1022 "Override configured router identifier\n"
1023 "Manually configured router identifier\n")
718e3744 1024{
d62a17ae 1025 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1026
d62a17ae 1027 if (router_id_str) {
1028 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1029 vty_out(vty, "%% BGP router-id doesn't match\n");
1030 return CMD_WARNING_CONFIG_FAILED;
1031 }
e018c7cc 1032 }
718e3744 1033
d62a17ae 1034 router_id.s_addr = 0;
1035 bgp_router_id_static_set(bgp, router_id);
718e3744 1036
d62a17ae 1037 return CMD_SUCCESS;
718e3744 1038}
1039
6b0655a2 1040
718e3744 1041/* BGP Cluster ID. */
718e3744 1042DEFUN (bgp_cluster_id,
1043 bgp_cluster_id_cmd,
838758ac 1044 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1045 BGP_STR
1046 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1047 "Route-Reflector Cluster-id in IP address format\n"
1048 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1049{
d62a17ae 1050 VTY_DECLVAR_CONTEXT(bgp, bgp);
1051 int idx_ipv4 = 2;
1052 int ret;
1053 struct in_addr cluster;
718e3744 1054
d62a17ae 1055 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1056 if (!ret) {
1057 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1058 return CMD_WARNING_CONFIG_FAILED;
1059 }
718e3744 1060
d62a17ae 1061 bgp_cluster_id_set(bgp, &cluster);
1062 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1063
d62a17ae 1064 return CMD_SUCCESS;
718e3744 1065}
1066
718e3744 1067DEFUN (no_bgp_cluster_id,
1068 no_bgp_cluster_id_cmd,
c7178fe7 1069 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1070 NO_STR
1071 BGP_STR
838758ac
DW
1072 "Configure Route-Reflector Cluster-id\n"
1073 "Route-Reflector Cluster-id in IP address format\n"
1074 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1075{
d62a17ae 1076 VTY_DECLVAR_CONTEXT(bgp, bgp);
1077 bgp_cluster_id_unset(bgp);
1078 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1079
d62a17ae 1080 return CMD_SUCCESS;
718e3744 1081}
1082
718e3744 1083DEFUN (bgp_confederation_identifier,
1084 bgp_confederation_identifier_cmd,
9ccf14f7 1085 "bgp confederation identifier (1-4294967295)",
718e3744 1086 "BGP specific commands\n"
1087 "AS confederation parameters\n"
1088 "AS number\n"
1089 "Set routing domain confederation AS\n")
1090{
d62a17ae 1091 VTY_DECLVAR_CONTEXT(bgp, bgp);
1092 int idx_number = 3;
1093 as_t as;
718e3744 1094
d62a17ae 1095 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1096
d62a17ae 1097 bgp_confederation_id_set(bgp, as);
718e3744 1098
d62a17ae 1099 return CMD_SUCCESS;
718e3744 1100}
1101
1102DEFUN (no_bgp_confederation_identifier,
1103 no_bgp_confederation_identifier_cmd,
838758ac 1104 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1105 NO_STR
1106 "BGP specific commands\n"
1107 "AS confederation parameters\n"
3a2d747c
QY
1108 "AS number\n"
1109 "Set routing domain confederation AS\n")
718e3744 1110{
d62a17ae 1111 VTY_DECLVAR_CONTEXT(bgp, bgp);
1112 bgp_confederation_id_unset(bgp);
718e3744 1113
d62a17ae 1114 return CMD_SUCCESS;
718e3744 1115}
1116
718e3744 1117DEFUN (bgp_confederation_peers,
1118 bgp_confederation_peers_cmd,
12dcf78e 1119 "bgp confederation peers (1-4294967295)...",
718e3744 1120 "BGP specific commands\n"
1121 "AS confederation parameters\n"
1122 "Peer ASs in BGP confederation\n"
1123 AS_STR)
1124{
d62a17ae 1125 VTY_DECLVAR_CONTEXT(bgp, bgp);
1126 int idx_asn = 3;
1127 as_t as;
1128 int i;
718e3744 1129
d62a17ae 1130 for (i = idx_asn; i < argc; i++) {
1131 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1132
d62a17ae 1133 if (bgp->as == as) {
1134 vty_out(vty,
1135 "%% Local member-AS not allowed in confed peer list\n");
1136 continue;
1137 }
718e3744 1138
d62a17ae 1139 bgp_confederation_peers_add(bgp, as);
1140 }
1141 return CMD_SUCCESS;
718e3744 1142}
1143
1144DEFUN (no_bgp_confederation_peers,
1145 no_bgp_confederation_peers_cmd,
e83a9414 1146 "no bgp confederation peers (1-4294967295)...",
718e3744 1147 NO_STR
1148 "BGP specific commands\n"
1149 "AS confederation parameters\n"
1150 "Peer ASs in BGP confederation\n"
1151 AS_STR)
1152{
d62a17ae 1153 VTY_DECLVAR_CONTEXT(bgp, bgp);
1154 int idx_asn = 4;
1155 as_t as;
1156 int i;
718e3744 1157
d62a17ae 1158 for (i = idx_asn; i < argc; i++) {
1159 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1160
d62a17ae 1161 bgp_confederation_peers_remove(bgp, as);
1162 }
1163 return CMD_SUCCESS;
718e3744 1164}
6b0655a2 1165
5e242b0d
DS
1166/**
1167 * Central routine for maximum-paths configuration.
1168 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1169 * @set: 1 for setting values, 0 for removing the max-paths config.
1170 */
d62a17ae 1171static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1172 const char *mpaths, uint16_t options,
d62a17ae 1173 int set)
1174{
1175 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1176 uint16_t maxpaths = 0;
d62a17ae 1177 int ret;
1178 afi_t afi;
1179 safi_t safi;
1180
1181 afi = bgp_node_afi(vty);
1182 safi = bgp_node_safi(vty);
1183
1184 if (set) {
1185 maxpaths = strtol(mpaths, NULL, 10);
1186 if (maxpaths > multipath_num) {
1187 vty_out(vty,
1188 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1189 maxpaths, multipath_num);
1190 return CMD_WARNING_CONFIG_FAILED;
1191 }
1192 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1193 options);
1194 } else
1195 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1196
1197 if (ret < 0) {
1198 vty_out(vty,
1199 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1200 (set == 1) ? "" : "un",
1201 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1202 maxpaths, afi, safi);
1203 return CMD_WARNING_CONFIG_FAILED;
1204 }
1205
1206 bgp_recalculate_all_bestpaths(bgp);
1207
1208 return CMD_SUCCESS;
165b5fff
JB
1209}
1210
abc920f8
DS
1211DEFUN (bgp_maxmed_admin,
1212 bgp_maxmed_admin_cmd,
1213 "bgp max-med administrative ",
1214 BGP_STR
1215 "Advertise routes with max-med\n"
1216 "Administratively applied, for an indefinite period\n")
1217{
d62a17ae 1218 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1219
d62a17ae 1220 bgp->v_maxmed_admin = 1;
1221 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1222
d62a17ae 1223 bgp_maxmed_update(bgp);
abc920f8 1224
d62a17ae 1225 return CMD_SUCCESS;
abc920f8
DS
1226}
1227
1228DEFUN (bgp_maxmed_admin_medv,
1229 bgp_maxmed_admin_medv_cmd,
4668a151 1230 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1231 BGP_STR
1232 "Advertise routes with max-med\n"
1233 "Administratively applied, for an indefinite period\n"
1234 "Max MED value to be used\n")
1235{
d62a17ae 1236 VTY_DECLVAR_CONTEXT(bgp, bgp);
1237 int idx_number = 3;
abc920f8 1238
d62a17ae 1239 bgp->v_maxmed_admin = 1;
1240 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1241
d62a17ae 1242 bgp_maxmed_update(bgp);
abc920f8 1243
d62a17ae 1244 return CMD_SUCCESS;
abc920f8
DS
1245}
1246
1247DEFUN (no_bgp_maxmed_admin,
1248 no_bgp_maxmed_admin_cmd,
4668a151 1249 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1250 NO_STR
1251 BGP_STR
1252 "Advertise routes with max-med\n"
838758ac
DW
1253 "Administratively applied, for an indefinite period\n"
1254 "Max MED value to be used\n")
abc920f8 1255{
d62a17ae 1256 VTY_DECLVAR_CONTEXT(bgp, bgp);
1257 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1258 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1259 bgp_maxmed_update(bgp);
abc920f8 1260
d62a17ae 1261 return CMD_SUCCESS;
abc920f8
DS
1262}
1263
abc920f8
DS
1264DEFUN (bgp_maxmed_onstartup,
1265 bgp_maxmed_onstartup_cmd,
4668a151 1266 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1267 BGP_STR
1268 "Advertise routes with max-med\n"
1269 "Effective on a startup\n"
1270 "Time (seconds) period for max-med\n"
1271 "Max MED value to be used\n")
1272{
d62a17ae 1273 VTY_DECLVAR_CONTEXT(bgp, bgp);
1274 int idx = 0;
4668a151 1275
d62a17ae 1276 argv_find(argv, argc, "(5-86400)", &idx);
1277 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1278 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1279 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1280 else
1281 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1282
d62a17ae 1283 bgp_maxmed_update(bgp);
abc920f8 1284
d62a17ae 1285 return CMD_SUCCESS;
abc920f8
DS
1286}
1287
1288DEFUN (no_bgp_maxmed_onstartup,
1289 no_bgp_maxmed_onstartup_cmd,
4668a151 1290 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1291 NO_STR
1292 BGP_STR
1293 "Advertise routes with max-med\n"
838758ac
DW
1294 "Effective on a startup\n"
1295 "Time (seconds) period for max-med\n"
1296 "Max MED value to be used\n")
abc920f8 1297{
d62a17ae 1298 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1299
d62a17ae 1300 /* Cancel max-med onstartup if its on */
1301 if (bgp->t_maxmed_onstartup) {
1302 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1303 bgp->maxmed_onstartup_over = 1;
1304 }
abc920f8 1305
d62a17ae 1306 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1307 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1308
d62a17ae 1309 bgp_maxmed_update(bgp);
abc920f8 1310
d62a17ae 1311 return CMD_SUCCESS;
abc920f8
DS
1312}
1313
d62a17ae 1314static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1315 const char *wait)
f188f2c4 1316{
d62a17ae 1317 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1318 uint16_t update_delay;
1319 uint16_t establish_wait;
f188f2c4 1320
d62a17ae 1321 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1322
d62a17ae 1323 if (!wait) /* update-delay <delay> */
1324 {
1325 bgp->v_update_delay = update_delay;
1326 bgp->v_establish_wait = bgp->v_update_delay;
1327 return CMD_SUCCESS;
1328 }
f188f2c4 1329
d62a17ae 1330 /* update-delay <delay> <establish-wait> */
1331 establish_wait = atoi(wait);
1332 if (update_delay < establish_wait) {
1333 vty_out(vty,
1334 "%%Failed: update-delay less than the establish-wait!\n");
1335 return CMD_WARNING_CONFIG_FAILED;
1336 }
f188f2c4 1337
d62a17ae 1338 bgp->v_update_delay = update_delay;
1339 bgp->v_establish_wait = establish_wait;
f188f2c4 1340
d62a17ae 1341 return CMD_SUCCESS;
f188f2c4
DS
1342}
1343
d62a17ae 1344static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1345{
d62a17ae 1346 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1347
d62a17ae 1348 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1349 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1350
d62a17ae 1351 return CMD_SUCCESS;
f188f2c4
DS
1352}
1353
2b791107 1354void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1355{
d62a17ae 1356 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1357 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1358 if (bgp->v_update_delay != bgp->v_establish_wait)
1359 vty_out(vty, " %d", bgp->v_establish_wait);
1360 vty_out(vty, "\n");
1361 }
f188f2c4
DS
1362}
1363
1364
1365/* Update-delay configuration */
1366DEFUN (bgp_update_delay,
1367 bgp_update_delay_cmd,
6147e2c6 1368 "update-delay (0-3600)",
f188f2c4
DS
1369 "Force initial delay for best-path and updates\n"
1370 "Seconds\n")
1371{
d62a17ae 1372 int idx_number = 1;
1373 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1374}
1375
1376DEFUN (bgp_update_delay_establish_wait,
1377 bgp_update_delay_establish_wait_cmd,
6147e2c6 1378 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1379 "Force initial delay for best-path and updates\n"
1380 "Seconds\n"
f188f2c4
DS
1381 "Seconds\n")
1382{
d62a17ae 1383 int idx_number = 1;
1384 int idx_number_2 = 2;
1385 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1386 argv[idx_number_2]->arg);
f188f2c4
DS
1387}
1388
1389/* Update-delay deconfiguration */
1390DEFUN (no_bgp_update_delay,
1391 no_bgp_update_delay_cmd,
838758ac
DW
1392 "no update-delay [(0-3600) [(1-3600)]]",
1393 NO_STR
f188f2c4 1394 "Force initial delay for best-path and updates\n"
838758ac 1395 "Seconds\n"
7111c1a0 1396 "Seconds\n")
f188f2c4 1397{
d62a17ae 1398 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1399}
1400
5e242b0d 1401
d62a17ae 1402static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1403 char set)
cb1faec9 1404{
d62a17ae 1405 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1406
555e09d4
QY
1407 if (set) {
1408 uint32_t quanta = strtoul(num, NULL, 10);
1409 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1410 memory_order_relaxed);
1411 } else {
1412 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1413 memory_order_relaxed);
1414 }
1415
1416 return CMD_SUCCESS;
1417}
1418
1419static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1420 char set)
1421{
1422 VTY_DECLVAR_CONTEXT(bgp, bgp);
1423
1424 if (set) {
1425 uint32_t quanta = strtoul(num, NULL, 10);
1426 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1427 memory_order_relaxed);
1428 } else {
1429 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1430 memory_order_relaxed);
1431 }
cb1faec9 1432
d62a17ae 1433 return CMD_SUCCESS;
cb1faec9
DS
1434}
1435
2b791107 1436void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1437{
555e09d4
QY
1438 uint32_t quanta =
1439 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1440 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1441 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1442}
1443
555e09d4
QY
1444void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1445{
1446 uint32_t quanta =
1447 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1448 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1449 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1450}
cb1faec9 1451
555e09d4 1452/* Packet quanta configuration */
cb1faec9
DS
1453DEFUN (bgp_wpkt_quanta,
1454 bgp_wpkt_quanta_cmd,
555e09d4 1455 "write-quanta (1-10)",
cb1faec9
DS
1456 "How many packets to write to peer socket per run\n"
1457 "Number of packets\n")
1458{
d62a17ae 1459 int idx_number = 1;
1460 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1461}
1462
cb1faec9
DS
1463DEFUN (no_bgp_wpkt_quanta,
1464 no_bgp_wpkt_quanta_cmd,
555e09d4 1465 "no write-quanta (1-10)",
d7fa34c1 1466 NO_STR
555e09d4 1467 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1468 "Number of packets\n")
1469{
d62a17ae 1470 int idx_number = 2;
1471 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1472}
1473
555e09d4
QY
1474DEFUN (bgp_rpkt_quanta,
1475 bgp_rpkt_quanta_cmd,
1476 "read-quanta (1-10)",
1477 "How many packets to read from peer socket per I/O cycle\n"
1478 "Number of packets\n")
1479{
1480 int idx_number = 1;
1481 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1482}
1483
1484DEFUN (no_bgp_rpkt_quanta,
1485 no_bgp_rpkt_quanta_cmd,
1486 "no read-quanta (1-10)",
1487 NO_STR
1488 "How many packets to read from peer socket per I/O cycle\n"
1489 "Number of packets\n")
1490{
1491 int idx_number = 2;
1492 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1493}
1494
2b791107 1495void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1496{
37a333fe 1497 if (!bgp->heuristic_coalesce)
d62a17ae 1498 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1499}
1500
1501
1502DEFUN (bgp_coalesce_time,
1503 bgp_coalesce_time_cmd,
6147e2c6 1504 "coalesce-time (0-4294967295)",
3f9c7369
DS
1505 "Subgroup coalesce timer\n"
1506 "Subgroup coalesce timer value (in ms)\n")
1507{
d62a17ae 1508 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1509
d62a17ae 1510 int idx = 0;
1511 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1512 bgp->heuristic_coalesce = false;
d62a17ae 1513 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1514 return CMD_SUCCESS;
3f9c7369
DS
1515}
1516
1517DEFUN (no_bgp_coalesce_time,
1518 no_bgp_coalesce_time_cmd,
6147e2c6 1519 "no coalesce-time (0-4294967295)",
3a2d747c 1520 NO_STR
3f9c7369
DS
1521 "Subgroup coalesce timer\n"
1522 "Subgroup coalesce timer value (in ms)\n")
1523{
d62a17ae 1524 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1525
37a333fe 1526 bgp->heuristic_coalesce = true;
d62a17ae 1527 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1528 return CMD_SUCCESS;
3f9c7369
DS
1529}
1530
5e242b0d
DS
1531/* Maximum-paths configuration */
1532DEFUN (bgp_maxpaths,
1533 bgp_maxpaths_cmd,
6319fd63 1534 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1535 "Forward packets over multiple paths\n"
1536 "Number of paths\n")
1537{
d62a17ae 1538 int idx_number = 1;
1539 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1540 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1541}
1542
d62a17ae 1543ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1544 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1545 "Forward packets over multiple paths\n"
1546 "Number of paths\n")
596c17ba 1547
165b5fff
JB
1548DEFUN (bgp_maxpaths_ibgp,
1549 bgp_maxpaths_ibgp_cmd,
6319fd63 1550 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1551 "Forward packets over multiple paths\n"
1552 "iBGP-multipath\n"
1553 "Number of paths\n")
1554{
d62a17ae 1555 int idx_number = 2;
1556 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1557 argv[idx_number]->arg, 0, 1);
5e242b0d 1558}
165b5fff 1559
d62a17ae 1560ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1561 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1562 "Forward packets over multiple paths\n"
1563 "iBGP-multipath\n"
1564 "Number of paths\n")
596c17ba 1565
5e242b0d
DS
1566DEFUN (bgp_maxpaths_ibgp_cluster,
1567 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1568 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1569 "Forward packets over multiple paths\n"
1570 "iBGP-multipath\n"
1571 "Number of paths\n"
1572 "Match the cluster length\n")
1573{
d62a17ae 1574 int idx_number = 2;
1575 return bgp_maxpaths_config_vty(
1576 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1577 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1578}
1579
d62a17ae 1580ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1581 "maximum-paths ibgp " CMD_RANGE_STR(
1582 1, MULTIPATH_NUM) " equal-cluster-length",
1583 "Forward packets over multiple paths\n"
1584 "iBGP-multipath\n"
1585 "Number of paths\n"
1586 "Match the cluster length\n")
596c17ba 1587
165b5fff
JB
1588DEFUN (no_bgp_maxpaths,
1589 no_bgp_maxpaths_cmd,
6319fd63 1590 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1591 NO_STR
1592 "Forward packets over multiple paths\n"
1593 "Number of paths\n")
1594{
d62a17ae 1595 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1596}
1597
d62a17ae 1598ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1599 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1600 "Forward packets over multiple paths\n"
1601 "Number of paths\n")
596c17ba 1602
165b5fff
JB
1603DEFUN (no_bgp_maxpaths_ibgp,
1604 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1605 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1606 NO_STR
1607 "Forward packets over multiple paths\n"
1608 "iBGP-multipath\n"
838758ac
DW
1609 "Number of paths\n"
1610 "Match the cluster length\n")
165b5fff 1611{
d62a17ae 1612 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1613}
1614
d62a17ae 1615ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1616 "no maximum-paths ibgp [" CMD_RANGE_STR(
1617 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1618 NO_STR
1619 "Forward packets over multiple paths\n"
1620 "iBGP-multipath\n"
1621 "Number of paths\n"
1622 "Match the cluster length\n")
596c17ba 1623
2b791107 1624void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1625 safi_t safi)
165b5fff 1626{
d62a17ae 1627 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1628 vty_out(vty, " maximum-paths %d\n",
1629 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1630 }
165b5fff 1631
d62a17ae 1632 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1633 vty_out(vty, " maximum-paths ibgp %d",
1634 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1635 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1636 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1637 vty_out(vty, " equal-cluster-length");
1638 vty_out(vty, "\n");
1639 }
165b5fff 1640}
6b0655a2 1641
718e3744 1642/* BGP timers. */
1643
1644DEFUN (bgp_timers,
1645 bgp_timers_cmd,
6147e2c6 1646 "timers bgp (0-65535) (0-65535)",
718e3744 1647 "Adjust routing timers\n"
1648 "BGP timers\n"
1649 "Keepalive interval\n"
1650 "Holdtime\n")
1651{
d62a17ae 1652 VTY_DECLVAR_CONTEXT(bgp, bgp);
1653 int idx_number = 2;
1654 int idx_number_2 = 3;
1655 unsigned long keepalive = 0;
1656 unsigned long holdtime = 0;
718e3744 1657
d62a17ae 1658 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1659 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1660
d62a17ae 1661 /* Holdtime value check. */
1662 if (holdtime < 3 && holdtime != 0) {
1663 vty_out(vty,
1664 "%% hold time value must be either 0 or greater than 3\n");
1665 return CMD_WARNING_CONFIG_FAILED;
1666 }
718e3744 1667
d62a17ae 1668 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1669
d62a17ae 1670 return CMD_SUCCESS;
718e3744 1671}
1672
1673DEFUN (no_bgp_timers,
1674 no_bgp_timers_cmd,
838758ac 1675 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1676 NO_STR
1677 "Adjust routing timers\n"
838758ac
DW
1678 "BGP timers\n"
1679 "Keepalive interval\n"
1680 "Holdtime\n")
718e3744 1681{
d62a17ae 1682 VTY_DECLVAR_CONTEXT(bgp, bgp);
1683 bgp_timers_unset(bgp);
718e3744 1684
d62a17ae 1685 return CMD_SUCCESS;
718e3744 1686}
1687
6b0655a2 1688
718e3744 1689DEFUN (bgp_client_to_client_reflection,
1690 bgp_client_to_client_reflection_cmd,
1691 "bgp client-to-client reflection",
1692 "BGP specific commands\n"
1693 "Configure client to client route reflection\n"
1694 "reflection of routes allowed\n")
1695{
d62a17ae 1696 VTY_DECLVAR_CONTEXT(bgp, bgp);
1697 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1698 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1699
d62a17ae 1700 return CMD_SUCCESS;
718e3744 1701}
1702
1703DEFUN (no_bgp_client_to_client_reflection,
1704 no_bgp_client_to_client_reflection_cmd,
1705 "no bgp client-to-client reflection",
1706 NO_STR
1707 "BGP specific commands\n"
1708 "Configure client to client route reflection\n"
1709 "reflection of routes allowed\n")
1710{
d62a17ae 1711 VTY_DECLVAR_CONTEXT(bgp, bgp);
1712 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1713 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1714
d62a17ae 1715 return CMD_SUCCESS;
718e3744 1716}
1717
1718/* "bgp always-compare-med" configuration. */
1719DEFUN (bgp_always_compare_med,
1720 bgp_always_compare_med_cmd,
1721 "bgp always-compare-med",
1722 "BGP specific commands\n"
1723 "Allow comparing MED from different neighbors\n")
1724{
d62a17ae 1725 VTY_DECLVAR_CONTEXT(bgp, bgp);
1726 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1727 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1728
d62a17ae 1729 return CMD_SUCCESS;
718e3744 1730}
1731
1732DEFUN (no_bgp_always_compare_med,
1733 no_bgp_always_compare_med_cmd,
1734 "no bgp always-compare-med",
1735 NO_STR
1736 "BGP specific commands\n"
1737 "Allow comparing MED from different neighbors\n")
1738{
d62a17ae 1739 VTY_DECLVAR_CONTEXT(bgp, bgp);
1740 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1741 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1742
d62a17ae 1743 return CMD_SUCCESS;
718e3744 1744}
6b0655a2 1745
718e3744 1746/* "bgp deterministic-med" configuration. */
1747DEFUN (bgp_deterministic_med,
1748 bgp_deterministic_med_cmd,
1749 "bgp deterministic-med",
1750 "BGP specific commands\n"
1751 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1752{
d62a17ae 1753 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1754
d62a17ae 1755 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1756 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1757 bgp_recalculate_all_bestpaths(bgp);
1758 }
7aafcaca 1759
d62a17ae 1760 return CMD_SUCCESS;
718e3744 1761}
1762
1763DEFUN (no_bgp_deterministic_med,
1764 no_bgp_deterministic_med_cmd,
1765 "no bgp deterministic-med",
1766 NO_STR
1767 "BGP specific commands\n"
1768 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1769{
d62a17ae 1770 VTY_DECLVAR_CONTEXT(bgp, bgp);
1771 int bestpath_per_as_used;
1772 afi_t afi;
1773 safi_t safi;
1774 struct peer *peer;
1775 struct listnode *node, *nnode;
1776
1777 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1778 bestpath_per_as_used = 0;
1779
1780 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc
QY
1781 FOREACH_AFI_SAFI (afi, safi)
1782 if (CHECK_FLAG(
1783 peer->af_flags[afi][safi],
1784 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1785 bestpath_per_as_used = 1;
1786 break;
1787 }
d62a17ae 1788
1789 if (bestpath_per_as_used)
1790 break;
1791 }
1792
1793 if (bestpath_per_as_used) {
1794 vty_out(vty,
1795 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1796 return CMD_WARNING_CONFIG_FAILED;
1797 } else {
1798 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1799 bgp_recalculate_all_bestpaths(bgp);
1800 }
1801 }
1802
1803 return CMD_SUCCESS;
718e3744 1804}
538621f2 1805
1806/* "bgp graceful-restart" configuration. */
1807DEFUN (bgp_graceful_restart,
1808 bgp_graceful_restart_cmd,
1809 "bgp graceful-restart",
1810 "BGP specific commands\n"
1811 "Graceful restart capability parameters\n")
1812{
d62a17ae 1813 VTY_DECLVAR_CONTEXT(bgp, bgp);
1814 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1815 return CMD_SUCCESS;
538621f2 1816}
1817
1818DEFUN (no_bgp_graceful_restart,
1819 no_bgp_graceful_restart_cmd,
1820 "no bgp graceful-restart",
1821 NO_STR
1822 "BGP specific commands\n"
1823 "Graceful restart capability parameters\n")
1824{
d62a17ae 1825 VTY_DECLVAR_CONTEXT(bgp, bgp);
1826 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1827 return CMD_SUCCESS;
538621f2 1828}
1829
93406d87 1830DEFUN (bgp_graceful_restart_stalepath_time,
1831 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1832 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1833 "BGP specific commands\n"
1834 "Graceful restart capability parameters\n"
1835 "Set the max time to hold onto restarting peer's stale paths\n"
1836 "Delay value (seconds)\n")
1837{
d62a17ae 1838 VTY_DECLVAR_CONTEXT(bgp, bgp);
1839 int idx_number = 3;
d7c0a89a 1840 uint32_t stalepath;
93406d87 1841
d62a17ae 1842 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1843 bgp->stalepath_time = stalepath;
1844 return CMD_SUCCESS;
93406d87 1845}
1846
eb6f1b41
PG
1847DEFUN (bgp_graceful_restart_restart_time,
1848 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1849 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1850 "BGP specific commands\n"
1851 "Graceful restart capability parameters\n"
1852 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1853 "Delay value (seconds)\n")
1854{
d62a17ae 1855 VTY_DECLVAR_CONTEXT(bgp, bgp);
1856 int idx_number = 3;
d7c0a89a 1857 uint32_t restart;
eb6f1b41 1858
d62a17ae 1859 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1860 bgp->restart_time = restart;
1861 return CMD_SUCCESS;
eb6f1b41
PG
1862}
1863
93406d87 1864DEFUN (no_bgp_graceful_restart_stalepath_time,
1865 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1866 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1867 NO_STR
1868 "BGP specific commands\n"
1869 "Graceful restart capability parameters\n"
838758ac
DW
1870 "Set the max time to hold onto restarting peer's stale paths\n"
1871 "Delay value (seconds)\n")
93406d87 1872{
d62a17ae 1873 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1874
d62a17ae 1875 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1876 return CMD_SUCCESS;
93406d87 1877}
1878
eb6f1b41
PG
1879DEFUN (no_bgp_graceful_restart_restart_time,
1880 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1881 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1882 NO_STR
1883 "BGP specific commands\n"
1884 "Graceful restart capability parameters\n"
838758ac
DW
1885 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1886 "Delay value (seconds)\n")
eb6f1b41 1887{
d62a17ae 1888 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1889
d62a17ae 1890 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1891 return CMD_SUCCESS;
eb6f1b41
PG
1892}
1893
43fc21b3
JC
1894DEFUN (bgp_graceful_restart_preserve_fw,
1895 bgp_graceful_restart_preserve_fw_cmd,
1896 "bgp graceful-restart preserve-fw-state",
1897 "BGP specific commands\n"
1898 "Graceful restart capability parameters\n"
1899 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1900{
d62a17ae 1901 VTY_DECLVAR_CONTEXT(bgp, bgp);
1902 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1903 return CMD_SUCCESS;
43fc21b3
JC
1904}
1905
1906DEFUN (no_bgp_graceful_restart_preserve_fw,
1907 no_bgp_graceful_restart_preserve_fw_cmd,
1908 "no bgp graceful-restart preserve-fw-state",
1909 NO_STR
1910 "BGP specific commands\n"
1911 "Graceful restart capability parameters\n"
1912 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1913{
d62a17ae 1914 VTY_DECLVAR_CONTEXT(bgp, bgp);
1915 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1916 return CMD_SUCCESS;
43fc21b3
JC
1917}
1918
7f323236
DW
1919static void bgp_redistribute_redo(struct bgp *bgp)
1920{
1921 afi_t afi;
1922 int i;
1923 struct list *red_list;
1924 struct listnode *node;
1925 struct bgp_redist *red;
1926
a4d82a8a
PZ
1927 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1928 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 1929
a4d82a8a
PZ
1930 red_list = bgp->redist[afi][i];
1931 if (!red_list)
1932 continue;
7f323236 1933
a4d82a8a 1934 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
1935 bgp_redistribute_resend(bgp, afi, i,
1936 red->instance);
1937 }
1938 }
1939 }
1940}
1941
1942/* "bgp graceful-shutdown" configuration */
1943DEFUN (bgp_graceful_shutdown,
1944 bgp_graceful_shutdown_cmd,
1945 "bgp graceful-shutdown",
1946 BGP_STR
1947 "Graceful shutdown parameters\n")
1948{
1949 VTY_DECLVAR_CONTEXT(bgp, bgp);
1950
1951 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1952 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1953 bgp_static_redo_import_check(bgp);
1954 bgp_redistribute_redo(bgp);
1955 bgp_clear_star_soft_out(vty, bgp->name);
1956 bgp_clear_star_soft_in(vty, bgp->name);
1957 }
1958
1959 return CMD_SUCCESS;
1960}
1961
1962DEFUN (no_bgp_graceful_shutdown,
1963 no_bgp_graceful_shutdown_cmd,
1964 "no bgp graceful-shutdown",
1965 NO_STR
1966 BGP_STR
1967 "Graceful shutdown parameters\n")
1968{
1969 VTY_DECLVAR_CONTEXT(bgp, bgp);
1970
1971 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1972 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1973 bgp_static_redo_import_check(bgp);
1974 bgp_redistribute_redo(bgp);
1975 bgp_clear_star_soft_out(vty, bgp->name);
1976 bgp_clear_star_soft_in(vty, bgp->name);
1977 }
1978
1979 return CMD_SUCCESS;
1980}
1981
718e3744 1982/* "bgp fast-external-failover" configuration. */
1983DEFUN (bgp_fast_external_failover,
1984 bgp_fast_external_failover_cmd,
1985 "bgp fast-external-failover",
1986 BGP_STR
1987 "Immediately reset session if a link to a directly connected external peer goes down\n")
1988{
d62a17ae 1989 VTY_DECLVAR_CONTEXT(bgp, bgp);
1990 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1991 return CMD_SUCCESS;
718e3744 1992}
1993
1994DEFUN (no_bgp_fast_external_failover,
1995 no_bgp_fast_external_failover_cmd,
1996 "no bgp fast-external-failover",
1997 NO_STR
1998 BGP_STR
1999 "Immediately reset session if a link to a directly connected external peer goes down\n")
2000{
d62a17ae 2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
2002 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2003 return CMD_SUCCESS;
718e3744 2004}
6b0655a2 2005
718e3744 2006/* "bgp enforce-first-as" configuration. */
47cbc09b
PM
2007#if defined(VERSION_TYPE_DEV) && CONFDATE > 20180517
2008CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2009#endif
2010
2011DEFUN_DEPRECATED (bgp_enforce_first_as,
718e3744 2012 bgp_enforce_first_as_cmd,
2013 "bgp enforce-first-as",
2014 BGP_STR
2015 "Enforce the first AS for EBGP routes\n")
2016{
d62a17ae 2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
2018 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
7aafcaca 2019
d62a17ae 2020 return CMD_SUCCESS;
718e3744 2021}
2022
47cbc09b 2023DEFUN_DEPRECATED (no_bgp_enforce_first_as,
718e3744 2024 no_bgp_enforce_first_as_cmd,
2025 "no bgp enforce-first-as",
2026 NO_STR
2027 BGP_STR
2028 "Enforce the first AS for EBGP routes\n")
2029{
d62a17ae 2030 VTY_DECLVAR_CONTEXT(bgp, bgp);
2031 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
7aafcaca 2032
d62a17ae 2033 return CMD_SUCCESS;
718e3744 2034}
6b0655a2 2035
718e3744 2036/* "bgp bestpath compare-routerid" configuration. */
2037DEFUN (bgp_bestpath_compare_router_id,
2038 bgp_bestpath_compare_router_id_cmd,
2039 "bgp bestpath compare-routerid",
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_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2046 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2047
d62a17ae 2048 return CMD_SUCCESS;
718e3744 2049}
2050
2051DEFUN (no_bgp_bestpath_compare_router_id,
2052 no_bgp_bestpath_compare_router_id_cmd,
2053 "no bgp bestpath compare-routerid",
2054 NO_STR
2055 "BGP specific commands\n"
2056 "Change the default bestpath selection\n"
2057 "Compare router-id for identical EBGP paths\n")
2058{
d62a17ae 2059 VTY_DECLVAR_CONTEXT(bgp, bgp);
2060 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2061 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2062
d62a17ae 2063 return CMD_SUCCESS;
718e3744 2064}
6b0655a2 2065
718e3744 2066/* "bgp bestpath as-path ignore" configuration. */
2067DEFUN (bgp_bestpath_aspath_ignore,
2068 bgp_bestpath_aspath_ignore_cmd,
2069 "bgp bestpath as-path ignore",
2070 "BGP specific commands\n"
2071 "Change the default bestpath selection\n"
2072 "AS-path attribute\n"
2073 "Ignore as-path length in selecting a route\n")
2074{
d62a17ae 2075 VTY_DECLVAR_CONTEXT(bgp, bgp);
2076 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2077 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2078
d62a17ae 2079 return CMD_SUCCESS;
718e3744 2080}
2081
2082DEFUN (no_bgp_bestpath_aspath_ignore,
2083 no_bgp_bestpath_aspath_ignore_cmd,
2084 "no bgp bestpath as-path ignore",
2085 NO_STR
2086 "BGP specific commands\n"
2087 "Change the default bestpath selection\n"
2088 "AS-path attribute\n"
2089 "Ignore as-path length in selecting a route\n")
2090{
d62a17ae 2091 VTY_DECLVAR_CONTEXT(bgp, bgp);
2092 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2093 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2094
d62a17ae 2095 return CMD_SUCCESS;
718e3744 2096}
6b0655a2 2097
6811845b 2098/* "bgp bestpath as-path confed" configuration. */
2099DEFUN (bgp_bestpath_aspath_confed,
2100 bgp_bestpath_aspath_confed_cmd,
2101 "bgp bestpath as-path confed",
2102 "BGP specific commands\n"
2103 "Change the default bestpath selection\n"
2104 "AS-path attribute\n"
2105 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2106{
d62a17ae 2107 VTY_DECLVAR_CONTEXT(bgp, bgp);
2108 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2109 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2110
d62a17ae 2111 return CMD_SUCCESS;
6811845b 2112}
2113
2114DEFUN (no_bgp_bestpath_aspath_confed,
2115 no_bgp_bestpath_aspath_confed_cmd,
2116 "no bgp bestpath as-path confed",
2117 NO_STR
2118 "BGP specific commands\n"
2119 "Change the default bestpath selection\n"
2120 "AS-path attribute\n"
2121 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2122{
d62a17ae 2123 VTY_DECLVAR_CONTEXT(bgp, bgp);
2124 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2125 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2126
d62a17ae 2127 return CMD_SUCCESS;
6811845b 2128}
6b0655a2 2129
2fdd455c
PM
2130/* "bgp bestpath as-path multipath-relax" configuration. */
2131DEFUN (bgp_bestpath_aspath_multipath_relax,
2132 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2133 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2134 "BGP specific commands\n"
2135 "Change the default bestpath selection\n"
2136 "AS-path attribute\n"
2137 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2138 "Generate an AS_SET\n"
16fc1eec
DS
2139 "Do not generate an AS_SET\n")
2140{
d62a17ae 2141 VTY_DECLVAR_CONTEXT(bgp, bgp);
2142 int idx = 0;
2143 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2144
d62a17ae 2145 /* no-as-set is now the default behavior so we can silently
2146 * ignore it */
2147 if (argv_find(argv, argc, "as-set", &idx))
2148 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2149 else
2150 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2151
d62a17ae 2152 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2153
d62a17ae 2154 return CMD_SUCCESS;
16fc1eec
DS
2155}
2156
219178b6
DW
2157DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2158 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2159 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2160 NO_STR
2161 "BGP specific commands\n"
2162 "Change the default bestpath selection\n"
2163 "AS-path attribute\n"
2164 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2165 "Generate an AS_SET\n"
16fc1eec
DS
2166 "Do not generate an AS_SET\n")
2167{
d62a17ae 2168 VTY_DECLVAR_CONTEXT(bgp, bgp);
2169 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2170 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2171 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2172
d62a17ae 2173 return CMD_SUCCESS;
2fdd455c 2174}
6b0655a2 2175
848973c7 2176/* "bgp log-neighbor-changes" configuration. */
2177DEFUN (bgp_log_neighbor_changes,
2178 bgp_log_neighbor_changes_cmd,
2179 "bgp log-neighbor-changes",
2180 "BGP specific commands\n"
2181 "Log neighbor up/down and reset reason\n")
2182{
d62a17ae 2183 VTY_DECLVAR_CONTEXT(bgp, bgp);
2184 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2185 return CMD_SUCCESS;
848973c7 2186}
2187
2188DEFUN (no_bgp_log_neighbor_changes,
2189 no_bgp_log_neighbor_changes_cmd,
2190 "no bgp log-neighbor-changes",
2191 NO_STR
2192 "BGP specific commands\n"
2193 "Log neighbor up/down and reset reason\n")
2194{
d62a17ae 2195 VTY_DECLVAR_CONTEXT(bgp, bgp);
2196 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2197 return CMD_SUCCESS;
848973c7 2198}
6b0655a2 2199
718e3744 2200/* "bgp bestpath med" configuration. */
2201DEFUN (bgp_bestpath_med,
2202 bgp_bestpath_med_cmd,
2d8c1a4d 2203 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2204 "BGP specific commands\n"
2205 "Change the default bestpath selection\n"
2206 "MED attribute\n"
2207 "Compare MED among confederation paths\n"
838758ac
DW
2208 "Treat missing MED as the least preferred one\n"
2209 "Treat missing MED as the least preferred one\n"
2210 "Compare MED among confederation paths\n")
718e3744 2211{
d62a17ae 2212 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2213
d62a17ae 2214 int idx = 0;
2215 if (argv_find(argv, argc, "confed", &idx))
2216 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2217 idx = 0;
2218 if (argv_find(argv, argc, "missing-as-worst", &idx))
2219 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2220
d62a17ae 2221 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2222
d62a17ae 2223 return CMD_SUCCESS;
718e3744 2224}
2225
718e3744 2226DEFUN (no_bgp_bestpath_med,
2227 no_bgp_bestpath_med_cmd,
2d8c1a4d 2228 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2229 NO_STR
2230 "BGP specific commands\n"
2231 "Change the default bestpath selection\n"
2232 "MED attribute\n"
2233 "Compare MED among confederation paths\n"
3a2d747c
QY
2234 "Treat missing MED as the least preferred one\n"
2235 "Treat missing MED as the least preferred one\n"
2236 "Compare MED among confederation paths\n")
718e3744 2237{
d62a17ae 2238 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2239
d62a17ae 2240 int idx = 0;
2241 if (argv_find(argv, argc, "confed", &idx))
2242 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2243 idx = 0;
2244 if (argv_find(argv, argc, "missing-as-worst", &idx))
2245 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2246
d62a17ae 2247 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2248
d62a17ae 2249 return CMD_SUCCESS;
718e3744 2250}
2251
718e3744 2252/* "no bgp default ipv4-unicast". */
2253DEFUN (no_bgp_default_ipv4_unicast,
2254 no_bgp_default_ipv4_unicast_cmd,
2255 "no bgp default ipv4-unicast",
2256 NO_STR
2257 "BGP specific commands\n"
2258 "Configure BGP defaults\n"
2259 "Activate ipv4-unicast for a peer by default\n")
2260{
d62a17ae 2261 VTY_DECLVAR_CONTEXT(bgp, bgp);
2262 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2263 return CMD_SUCCESS;
718e3744 2264}
2265
2266DEFUN (bgp_default_ipv4_unicast,
2267 bgp_default_ipv4_unicast_cmd,
2268 "bgp default ipv4-unicast",
2269 "BGP specific commands\n"
2270 "Configure BGP defaults\n"
2271 "Activate ipv4-unicast for a peer by default\n")
2272{
d62a17ae 2273 VTY_DECLVAR_CONTEXT(bgp, bgp);
2274 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2275 return CMD_SUCCESS;
718e3744 2276}
6b0655a2 2277
04b6bdc0
DW
2278/* Display hostname in certain command outputs */
2279DEFUN (bgp_default_show_hostname,
2280 bgp_default_show_hostname_cmd,
2281 "bgp default show-hostname",
2282 "BGP specific commands\n"
2283 "Configure BGP defaults\n"
2284 "Show hostname in certain command ouputs\n")
2285{
d62a17ae 2286 VTY_DECLVAR_CONTEXT(bgp, bgp);
2287 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2288 return CMD_SUCCESS;
04b6bdc0
DW
2289}
2290
2291DEFUN (no_bgp_default_show_hostname,
2292 no_bgp_default_show_hostname_cmd,
2293 "no bgp default show-hostname",
2294 NO_STR
2295 "BGP specific commands\n"
2296 "Configure BGP defaults\n"
2297 "Show hostname in certain command ouputs\n")
2298{
d62a17ae 2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2301 return CMD_SUCCESS;
04b6bdc0
DW
2302}
2303
8233ef81 2304/* "bgp network import-check" configuration. */
718e3744 2305DEFUN (bgp_network_import_check,
2306 bgp_network_import_check_cmd,
5623e905 2307 "bgp network import-check",
718e3744 2308 "BGP specific commands\n"
2309 "BGP network command\n"
5623e905 2310 "Check BGP network route exists in IGP\n")
718e3744 2311{
d62a17ae 2312 VTY_DECLVAR_CONTEXT(bgp, bgp);
2313 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2314 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2315 bgp_static_redo_import_check(bgp);
2316 }
078430f6 2317
d62a17ae 2318 return CMD_SUCCESS;
718e3744 2319}
2320
d62a17ae 2321ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2322 "bgp network import-check exact",
2323 "BGP specific commands\n"
2324 "BGP network command\n"
2325 "Check BGP network route exists in IGP\n"
2326 "Match route precisely\n")
8233ef81 2327
718e3744 2328DEFUN (no_bgp_network_import_check,
2329 no_bgp_network_import_check_cmd,
5623e905 2330 "no bgp network import-check",
718e3744 2331 NO_STR
2332 "BGP specific commands\n"
2333 "BGP network command\n"
2334 "Check BGP network route exists in IGP\n")
2335{
d62a17ae 2336 VTY_DECLVAR_CONTEXT(bgp, bgp);
2337 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2338 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2339 bgp_static_redo_import_check(bgp);
2340 }
5623e905 2341
d62a17ae 2342 return CMD_SUCCESS;
718e3744 2343}
6b0655a2 2344
718e3744 2345DEFUN (bgp_default_local_preference,
2346 bgp_default_local_preference_cmd,
6147e2c6 2347 "bgp default local-preference (0-4294967295)",
718e3744 2348 "BGP specific commands\n"
2349 "Configure BGP defaults\n"
2350 "local preference (higher=more preferred)\n"
2351 "Configure default local preference value\n")
2352{
d62a17ae 2353 VTY_DECLVAR_CONTEXT(bgp, bgp);
2354 int idx_number = 3;
d7c0a89a 2355 uint32_t local_pref;
718e3744 2356
d62a17ae 2357 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2358
d62a17ae 2359 bgp_default_local_preference_set(bgp, local_pref);
2360 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2361
d62a17ae 2362 return CMD_SUCCESS;
718e3744 2363}
2364
2365DEFUN (no_bgp_default_local_preference,
2366 no_bgp_default_local_preference_cmd,
838758ac 2367 "no bgp default local-preference [(0-4294967295)]",
718e3744 2368 NO_STR
2369 "BGP specific commands\n"
2370 "Configure BGP defaults\n"
838758ac
DW
2371 "local preference (higher=more preferred)\n"
2372 "Configure default local preference value\n")
718e3744 2373{
d62a17ae 2374 VTY_DECLVAR_CONTEXT(bgp, bgp);
2375 bgp_default_local_preference_unset(bgp);
2376 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2377
d62a17ae 2378 return CMD_SUCCESS;
718e3744 2379}
2380
6b0655a2 2381
3f9c7369
DS
2382DEFUN (bgp_default_subgroup_pkt_queue_max,
2383 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2384 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2385 "BGP specific commands\n"
2386 "Configure BGP defaults\n"
2387 "subgroup-pkt-queue-max\n"
2388 "Configure subgroup packet queue max\n")
8bd9d948 2389{
d62a17ae 2390 VTY_DECLVAR_CONTEXT(bgp, bgp);
2391 int idx_number = 3;
d7c0a89a 2392 uint32_t max_size;
8bd9d948 2393
d62a17ae 2394 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2395
d62a17ae 2396 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2397
d62a17ae 2398 return CMD_SUCCESS;
3f9c7369
DS
2399}
2400
2401DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2402 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2403 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2404 NO_STR
2405 "BGP specific commands\n"
2406 "Configure BGP defaults\n"
838758ac
DW
2407 "subgroup-pkt-queue-max\n"
2408 "Configure subgroup packet queue max\n")
3f9c7369 2409{
d62a17ae 2410 VTY_DECLVAR_CONTEXT(bgp, bgp);
2411 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2412 return CMD_SUCCESS;
8bd9d948
DS
2413}
2414
813d4307 2415
8bd9d948
DS
2416DEFUN (bgp_rr_allow_outbound_policy,
2417 bgp_rr_allow_outbound_policy_cmd,
2418 "bgp route-reflector allow-outbound-policy",
2419 "BGP specific commands\n"
2420 "Allow modifications made by out route-map\n"
2421 "on ibgp neighbors\n")
2422{
d62a17ae 2423 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2424
d62a17ae 2425 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2426 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2427 update_group_announce_rrclients(bgp);
2428 bgp_clear_star_soft_out(vty, bgp->name);
2429 }
8bd9d948 2430
d62a17ae 2431 return CMD_SUCCESS;
8bd9d948
DS
2432}
2433
2434DEFUN (no_bgp_rr_allow_outbound_policy,
2435 no_bgp_rr_allow_outbound_policy_cmd,
2436 "no bgp route-reflector allow-outbound-policy",
2437 NO_STR
2438 "BGP specific commands\n"
2439 "Allow modifications made by out route-map\n"
2440 "on ibgp neighbors\n")
2441{
d62a17ae 2442 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2443
d62a17ae 2444 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2445 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2446 update_group_announce_rrclients(bgp);
2447 bgp_clear_star_soft_out(vty, bgp->name);
2448 }
8bd9d948 2449
d62a17ae 2450 return CMD_SUCCESS;
8bd9d948
DS
2451}
2452
f14e6fdb
DS
2453DEFUN (bgp_listen_limit,
2454 bgp_listen_limit_cmd,
9ccf14f7 2455 "bgp listen limit (1-5000)",
f14e6fdb
DS
2456 "BGP specific commands\n"
2457 "Configure BGP defaults\n"
2458 "maximum number of BGP Dynamic Neighbors that can be created\n"
2459 "Configure Dynamic Neighbors listen limit value\n")
2460{
d62a17ae 2461 VTY_DECLVAR_CONTEXT(bgp, bgp);
2462 int idx_number = 3;
2463 int listen_limit;
f14e6fdb 2464
d62a17ae 2465 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2466
d62a17ae 2467 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2468
d62a17ae 2469 return CMD_SUCCESS;
f14e6fdb
DS
2470}
2471
2472DEFUN (no_bgp_listen_limit,
2473 no_bgp_listen_limit_cmd,
838758ac 2474 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2475 "BGP specific commands\n"
2476 "Configure BGP defaults\n"
2477 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2478 "Configure Dynamic Neighbors listen limit value to default\n"
2479 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2480{
d62a17ae 2481 VTY_DECLVAR_CONTEXT(bgp, bgp);
2482 bgp_listen_limit_unset(bgp);
2483 return CMD_SUCCESS;
f14e6fdb
DS
2484}
2485
2486
20eb8864 2487/*
2488 * Check if this listen range is already configured. Check for exact
2489 * match or overlap based on input.
2490 */
d62a17ae 2491static struct peer_group *listen_range_exists(struct bgp *bgp,
2492 struct prefix *range, int exact)
2493{
2494 struct listnode *node, *nnode;
2495 struct listnode *node1, *nnode1;
2496 struct peer_group *group;
2497 struct prefix *lr;
2498 afi_t afi;
2499 int match;
2500
2501 afi = family2afi(range->family);
2502 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2503 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2504 lr)) {
2505 if (exact)
2506 match = prefix_same(range, lr);
2507 else
2508 match = (prefix_match(range, lr)
2509 || prefix_match(lr, range));
2510 if (match)
2511 return group;
2512 }
2513 }
2514
2515 return NULL;
20eb8864 2516}
2517
f14e6fdb
DS
2518DEFUN (bgp_listen_range,
2519 bgp_listen_range_cmd,
9ccf14f7 2520 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2521 "BGP specific commands\n"
d7fa34c1
QY
2522 "Configure BGP dynamic neighbors listen range\n"
2523 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2524 NEIGHBOR_ADDR_STR
2525 "Member of the peer-group\n"
2526 "Peer-group name\n")
f14e6fdb 2527{
d62a17ae 2528 VTY_DECLVAR_CONTEXT(bgp, bgp);
2529 struct prefix range;
2530 struct peer_group *group, *existing_group;
2531 afi_t afi;
2532 int ret;
2533 int idx = 0;
2534
2535 argv_find(argv, argc, "A.B.C.D/M", &idx);
2536 argv_find(argv, argc, "X:X::X:X/M", &idx);
2537 char *prefix = argv[idx]->arg;
2538 argv_find(argv, argc, "WORD", &idx);
2539 char *peergroup = argv[idx]->arg;
2540
2541 /* Convert IP prefix string to struct prefix. */
2542 ret = str2prefix(prefix, &range);
2543 if (!ret) {
2544 vty_out(vty, "%% Malformed listen range\n");
2545 return CMD_WARNING_CONFIG_FAILED;
2546 }
2547
2548 afi = family2afi(range.family);
2549
2550 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2551 vty_out(vty,
2552 "%% Malformed listen range (link-local address)\n");
2553 return CMD_WARNING_CONFIG_FAILED;
2554 }
2555
2556 apply_mask(&range);
2557
2558 /* Check if same listen range is already configured. */
2559 existing_group = listen_range_exists(bgp, &range, 1);
2560 if (existing_group) {
2561 if (strcmp(existing_group->name, peergroup) == 0)
2562 return CMD_SUCCESS;
2563 else {
2564 vty_out(vty,
2565 "%% Same listen range is attached to peer-group %s\n",
2566 existing_group->name);
2567 return CMD_WARNING_CONFIG_FAILED;
2568 }
2569 }
2570
2571 /* Check if an overlapping listen range exists. */
2572 if (listen_range_exists(bgp, &range, 0)) {
2573 vty_out(vty,
2574 "%% Listen range overlaps with existing listen range\n");
2575 return CMD_WARNING_CONFIG_FAILED;
2576 }
2577
2578 group = peer_group_lookup(bgp, peergroup);
2579 if (!group) {
2580 vty_out(vty, "%% Configure the peer-group first\n");
2581 return CMD_WARNING_CONFIG_FAILED;
2582 }
2583
2584 ret = peer_group_listen_range_add(group, &range);
2585 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2586}
2587
2588DEFUN (no_bgp_listen_range,
2589 no_bgp_listen_range_cmd,
d7fa34c1
QY
2590 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2591 NO_STR
f14e6fdb 2592 "BGP specific commands\n"
d7fa34c1
QY
2593 "Unconfigure BGP dynamic neighbors listen range\n"
2594 "Unconfigure BGP dynamic neighbors listen range\n"
2595 NEIGHBOR_ADDR_STR
2596 "Member of the peer-group\n"
2597 "Peer-group name\n")
f14e6fdb 2598{
d62a17ae 2599 VTY_DECLVAR_CONTEXT(bgp, bgp);
2600 struct prefix range;
2601 struct peer_group *group;
2602 afi_t afi;
2603 int ret;
2604 int idx = 0;
2605
2606 argv_find(argv, argc, "A.B.C.D/M", &idx);
2607 argv_find(argv, argc, "X:X::X:X/M", &idx);
2608 char *prefix = argv[idx]->arg;
2609 argv_find(argv, argc, "WORD", &idx);
2610 char *peergroup = argv[idx]->arg;
2611
2612 /* Convert IP prefix string to struct prefix. */
2613 ret = str2prefix(prefix, &range);
2614 if (!ret) {
2615 vty_out(vty, "%% Malformed listen range\n");
2616 return CMD_WARNING_CONFIG_FAILED;
2617 }
2618
2619 afi = family2afi(range.family);
2620
2621 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2622 vty_out(vty,
2623 "%% Malformed listen range (link-local address)\n");
2624 return CMD_WARNING_CONFIG_FAILED;
2625 }
2626
2627 apply_mask(&range);
2628
2629 group = peer_group_lookup(bgp, peergroup);
2630 if (!group) {
2631 vty_out(vty, "%% Peer-group does not exist\n");
2632 return CMD_WARNING_CONFIG_FAILED;
2633 }
2634
2635 ret = peer_group_listen_range_del(group, &range);
2636 return bgp_vty_return(vty, ret);
2637}
2638
2b791107 2639void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2640{
2641 struct peer_group *group;
2642 struct listnode *node, *nnode, *rnode, *nrnode;
2643 struct prefix *range;
2644 afi_t afi;
2645 char buf[PREFIX2STR_BUFFER];
2646
2647 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2648 vty_out(vty, " bgp listen limit %d\n",
2649 bgp->dynamic_neighbors_limit);
2650
2651 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2652 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2653 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2654 nrnode, range)) {
2655 prefix2str(range, buf, sizeof(buf));
2656 vty_out(vty,
2657 " bgp listen range %s peer-group %s\n",
2658 buf, group->name);
2659 }
2660 }
2661 }
f14e6fdb
DS
2662}
2663
2664
907f92c8
DS
2665DEFUN (bgp_disable_connected_route_check,
2666 bgp_disable_connected_route_check_cmd,
2667 "bgp disable-ebgp-connected-route-check",
2668 "BGP specific commands\n"
2669 "Disable checking if nexthop is connected on ebgp sessions\n")
2670{
d62a17ae 2671 VTY_DECLVAR_CONTEXT(bgp, bgp);
2672 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2673 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2674
d62a17ae 2675 return CMD_SUCCESS;
907f92c8
DS
2676}
2677
2678DEFUN (no_bgp_disable_connected_route_check,
2679 no_bgp_disable_connected_route_check_cmd,
2680 "no bgp disable-ebgp-connected-route-check",
2681 NO_STR
2682 "BGP specific commands\n"
2683 "Disable checking if nexthop is connected on ebgp sessions\n")
2684{
d62a17ae 2685 VTY_DECLVAR_CONTEXT(bgp, bgp);
2686 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2687 bgp_clear_star_soft_in(vty, bgp->name);
2688
2689 return CMD_SUCCESS;
2690}
2691
2692
2693static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2694 const char *as_str, afi_t afi, safi_t safi)
2695{
2696 VTY_DECLVAR_CONTEXT(bgp, bgp);
2697 int ret;
2698 as_t as;
2699 int as_type = AS_SPECIFIED;
2700 union sockunion su;
2701
2702 if (as_str[0] == 'i') {
2703 as = 0;
2704 as_type = AS_INTERNAL;
2705 } else if (as_str[0] == 'e') {
2706 as = 0;
2707 as_type = AS_EXTERNAL;
2708 } else {
2709 /* Get AS number. */
2710 as = strtoul(as_str, NULL, 10);
2711 }
2712
2713 /* If peer is peer group, call proper function. */
2714 ret = str2sockunion(peer_str, &su);
2715 if (ret < 0) {
2716 /* Check for peer by interface */
2717 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2718 safi);
2719 if (ret < 0) {
2720 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2721 if (ret < 0) {
2722 vty_out(vty,
2723 "%% Create the peer-group or interface first\n");
2724 return CMD_WARNING_CONFIG_FAILED;
2725 }
2726 return CMD_SUCCESS;
2727 }
2728 } else {
2729 if (peer_address_self_check(bgp, &su)) {
2730 vty_out(vty,
2731 "%% Can not configure the local system as neighbor\n");
2732 return CMD_WARNING_CONFIG_FAILED;
2733 }
2734 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2735 }
2736
2737 /* This peer belongs to peer group. */
2738 switch (ret) {
2739 case BGP_ERR_PEER_GROUP_MEMBER:
2740 vty_out(vty,
2741 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2742 as);
2743 return CMD_WARNING_CONFIG_FAILED;
2744 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2745 vty_out(vty,
2746 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2747 as, as_str);
2748 return CMD_WARNING_CONFIG_FAILED;
2749 }
2750 return bgp_vty_return(vty, ret);
718e3744 2751}
2752
f26845f9
QY
2753DEFUN (bgp_default_shutdown,
2754 bgp_default_shutdown_cmd,
2755 "[no] bgp default shutdown",
2756 NO_STR
2757 BGP_STR
2758 "Configure BGP defaults\n"
b012cbe2 2759 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2760{
2761 VTY_DECLVAR_CONTEXT(bgp, bgp);
2762 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2763 return CMD_SUCCESS;
2764}
2765
718e3744 2766DEFUN (neighbor_remote_as,
2767 neighbor_remote_as_cmd,
3a2d747c 2768 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2769 NEIGHBOR_STR
2770 NEIGHBOR_ADDR_STR2
2771 "Specify a BGP neighbor\n"
d7fa34c1 2772 AS_STR
3a2d747c
QY
2773 "Internal BGP peer\n"
2774 "External BGP peer\n")
718e3744 2775{
d62a17ae 2776 int idx_peer = 1;
2777 int idx_remote_as = 3;
2778 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2779 argv[idx_remote_as]->arg, AFI_IP,
2780 SAFI_UNICAST);
2781}
2782
2783static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2784 afi_t afi, safi_t safi, int v6only,
2785 const char *peer_group_name,
2786 const char *as_str)
2787{
2788 VTY_DECLVAR_CONTEXT(bgp, bgp);
2789 as_t as = 0;
2790 int as_type = AS_UNSPECIFIED;
2791 struct peer *peer;
2792 struct peer_group *group;
2793 int ret = 0;
2794 union sockunion su;
2795
2796 group = peer_group_lookup(bgp, conf_if);
2797
2798 if (group) {
2799 vty_out(vty, "%% Name conflict with peer-group \n");
2800 return CMD_WARNING_CONFIG_FAILED;
2801 }
2802
2803 if (as_str) {
2804 if (as_str[0] == 'i') {
2805 as_type = AS_INTERNAL;
2806 } else if (as_str[0] == 'e') {
2807 as_type = AS_EXTERNAL;
2808 } else {
2809 /* Get AS number. */
2810 as = strtoul(as_str, NULL, 10);
2811 as_type = AS_SPECIFIED;
2812 }
2813 }
2814
2815 peer = peer_lookup_by_conf_if(bgp, conf_if);
2816 if (peer) {
2817 if (as_str)
2818 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2819 afi, safi);
2820 } else {
2821 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2822 && afi == AFI_IP && safi == SAFI_UNICAST)
2823 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2824 as_type, 0, 0, NULL);
2825 else
2826 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2827 as_type, afi, safi, NULL);
2828
2829 if (!peer) {
2830 vty_out(vty, "%% BGP failed to create peer\n");
2831 return CMD_WARNING_CONFIG_FAILED;
2832 }
2833
2834 if (v6only)
527de3dc 2835 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2836
2837 /* Request zebra to initiate IPv6 RAs on this interface. We do
2838 * this
2839 * any unnumbered peer in order to not worry about run-time
2840 * transitions
2841 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2842 * address
2843 * gets deleted later etc.)
2844 */
2845 if (peer->ifp)
2846 bgp_zebra_initiate_radv(bgp, peer);
2847 }
2848
2849 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2850 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2851 if (v6only)
527de3dc 2852 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2853 else
527de3dc 2854 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2855
2856 /* v6only flag changed. Reset bgp seesion */
2857 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2858 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2859 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2860 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2861 } else
2862 bgp_session_reset(peer);
2863 }
2864
9fb964de
PM
2865 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2866 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2867 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2868 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2869 }
d62a17ae 2870
2871 if (peer_group_name) {
2872 group = peer_group_lookup(bgp, peer_group_name);
2873 if (!group) {
2874 vty_out(vty, "%% Configure the peer-group first\n");
2875 return CMD_WARNING_CONFIG_FAILED;
2876 }
2877
2878 ret = peer_group_bind(bgp, &su, peer, group, &as);
2879 }
2880
2881 return bgp_vty_return(vty, ret);
a80beece
DS
2882}
2883
4c48cf63
DW
2884DEFUN (neighbor_interface_config,
2885 neighbor_interface_config_cmd,
31500417 2886 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2887 NEIGHBOR_STR
2888 "Interface name or neighbor tag\n"
31500417
DW
2889 "Enable BGP on interface\n"
2890 "Member of the peer-group\n"
16cedbb0 2891 "Peer-group name\n")
4c48cf63 2892{
d62a17ae 2893 int idx_word = 1;
2894 int idx_peer_group_word = 4;
31500417 2895
d62a17ae 2896 if (argc > idx_peer_group_word)
2897 return peer_conf_interface_get(
2898 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2899 argv[idx_peer_group_word]->arg, NULL);
2900 else
2901 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2902 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2903}
2904
4c48cf63
DW
2905DEFUN (neighbor_interface_config_v6only,
2906 neighbor_interface_config_v6only_cmd,
31500417 2907 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2908 NEIGHBOR_STR
2909 "Interface name or neighbor tag\n"
2910 "Enable BGP on interface\n"
31500417
DW
2911 "Enable BGP with v6 link-local only\n"
2912 "Member of the peer-group\n"
16cedbb0 2913 "Peer-group name\n")
4c48cf63 2914{
d62a17ae 2915 int idx_word = 1;
2916 int idx_peer_group_word = 5;
31500417 2917
d62a17ae 2918 if (argc > idx_peer_group_word)
2919 return peer_conf_interface_get(
2920 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2921 argv[idx_peer_group_word]->arg, NULL);
31500417 2922
d62a17ae 2923 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2924 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2925}
2926
a80beece 2927
b3a39dc5
DD
2928DEFUN (neighbor_interface_config_remote_as,
2929 neighbor_interface_config_remote_as_cmd,
3a2d747c 2930 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2931 NEIGHBOR_STR
2932 "Interface name or neighbor tag\n"
2933 "Enable BGP on interface\n"
3a2d747c 2934 "Specify a BGP neighbor\n"
d7fa34c1 2935 AS_STR
3a2d747c
QY
2936 "Internal BGP peer\n"
2937 "External BGP peer\n")
b3a39dc5 2938{
d62a17ae 2939 int idx_word = 1;
2940 int idx_remote_as = 4;
2941 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2942 SAFI_UNICAST, 0, NULL,
2943 argv[idx_remote_as]->arg);
b3a39dc5
DD
2944}
2945
2946DEFUN (neighbor_interface_v6only_config_remote_as,
2947 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2948 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2949 NEIGHBOR_STR
2950 "Interface name or neighbor tag\n"
3a2d747c 2951 "Enable BGP with v6 link-local only\n"
b3a39dc5 2952 "Enable BGP on interface\n"
3a2d747c 2953 "Specify a BGP neighbor\n"
d7fa34c1 2954 AS_STR
3a2d747c
QY
2955 "Internal BGP peer\n"
2956 "External BGP peer\n")
b3a39dc5 2957{
d62a17ae 2958 int idx_word = 1;
2959 int idx_remote_as = 5;
2960 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2961 SAFI_UNICAST, 1, NULL,
2962 argv[idx_remote_as]->arg);
b3a39dc5
DD
2963}
2964
718e3744 2965DEFUN (neighbor_peer_group,
2966 neighbor_peer_group_cmd,
2967 "neighbor WORD peer-group",
2968 NEIGHBOR_STR
a80beece 2969 "Interface name or neighbor tag\n"
718e3744 2970 "Configure peer-group\n")
2971{
d62a17ae 2972 VTY_DECLVAR_CONTEXT(bgp, bgp);
2973 int idx_word = 1;
2974 struct peer *peer;
2975 struct peer_group *group;
718e3744 2976
d62a17ae 2977 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2978 if (peer) {
2979 vty_out(vty, "%% Name conflict with interface: \n");
2980 return CMD_WARNING_CONFIG_FAILED;
2981 }
718e3744 2982
d62a17ae 2983 group = peer_group_get(bgp, argv[idx_word]->arg);
2984 if (!group) {
2985 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2986 return CMD_WARNING_CONFIG_FAILED;
2987 }
718e3744 2988
d62a17ae 2989 return CMD_SUCCESS;
718e3744 2990}
2991
2992DEFUN (no_neighbor,
2993 no_neighbor_cmd,
dab8cd00 2994 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 2995 NO_STR
2996 NEIGHBOR_STR
3a2d747c
QY
2997 NEIGHBOR_ADDR_STR2
2998 "Specify a BGP neighbor\n"
2999 AS_STR
3000 "Internal BGP peer\n"
3001 "External BGP peer\n")
718e3744 3002{
d62a17ae 3003 VTY_DECLVAR_CONTEXT(bgp, bgp);
3004 int idx_peer = 2;
3005 int ret;
3006 union sockunion su;
3007 struct peer_group *group;
3008 struct peer *peer;
3009 struct peer *other;
3010
3011 ret = str2sockunion(argv[idx_peer]->arg, &su);
3012 if (ret < 0) {
3013 /* look up for neighbor by interface name config. */
3014 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3015 if (peer) {
3016 /* Request zebra to terminate IPv6 RAs on this
3017 * interface. */
3018 if (peer->ifp)
3019 bgp_zebra_terminate_radv(peer->bgp, peer);
3020 peer_delete(peer);
3021 return CMD_SUCCESS;
3022 }
f14e6fdb 3023
d62a17ae 3024 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3025 if (group)
3026 peer_group_delete(group);
3027 else {
3028 vty_out(vty, "%% Create the peer-group first\n");
3029 return CMD_WARNING_CONFIG_FAILED;
3030 }
3031 } else {
3032 peer = peer_lookup(bgp, &su);
3033 if (peer) {
3034 if (peer_dynamic_neighbor(peer)) {
3035 vty_out(vty,
3036 "%% Operation not allowed on a dynamic neighbor\n");
3037 return CMD_WARNING_CONFIG_FAILED;
3038 }
3039
3040 other = peer->doppelganger;
3041 peer_delete(peer);
3042 if (other && other->status != Deleted)
3043 peer_delete(other);
3044 }
1ff9a340 3045 }
718e3744 3046
d62a17ae 3047 return CMD_SUCCESS;
718e3744 3048}
3049
a80beece
DS
3050DEFUN (no_neighbor_interface_config,
3051 no_neighbor_interface_config_cmd,
31500417 3052 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3053 NO_STR
3054 NEIGHBOR_STR
3055 "Interface name\n"
31500417
DW
3056 "Configure BGP on interface\n"
3057 "Enable BGP with v6 link-local only\n"
3058 "Member of the peer-group\n"
16cedbb0 3059 "Peer-group name\n"
3a2d747c
QY
3060 "Specify a BGP neighbor\n"
3061 AS_STR
3062 "Internal BGP peer\n"
3063 "External BGP peer\n")
a80beece 3064{
d62a17ae 3065 VTY_DECLVAR_CONTEXT(bgp, bgp);
3066 int idx_word = 2;
3067 struct peer *peer;
3068
3069 /* look up for neighbor by interface name config. */
3070 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3071 if (peer) {
3072 /* Request zebra to terminate IPv6 RAs on this interface. */
3073 if (peer->ifp)
3074 bgp_zebra_terminate_radv(peer->bgp, peer);
3075 peer_delete(peer);
3076 } else {
3077 vty_out(vty, "%% Create the bgp interface first\n");
3078 return CMD_WARNING_CONFIG_FAILED;
3079 }
3080 return CMD_SUCCESS;
a80beece
DS
3081}
3082
718e3744 3083DEFUN (no_neighbor_peer_group,
3084 no_neighbor_peer_group_cmd,
3085 "no neighbor WORD peer-group",
3086 NO_STR
3087 NEIGHBOR_STR
3088 "Neighbor tag\n"
3089 "Configure peer-group\n")
3090{
d62a17ae 3091 VTY_DECLVAR_CONTEXT(bgp, bgp);
3092 int idx_word = 2;
3093 struct peer_group *group;
718e3744 3094
d62a17ae 3095 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3096 if (group)
3097 peer_group_delete(group);
3098 else {
3099 vty_out(vty, "%% Create the peer-group first\n");
3100 return CMD_WARNING_CONFIG_FAILED;
3101 }
3102 return CMD_SUCCESS;
718e3744 3103}
3104
a80beece
DS
3105DEFUN (no_neighbor_interface_peer_group_remote_as,
3106 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3107 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3108 NO_STR
3109 NEIGHBOR_STR
a80beece 3110 "Interface name or neighbor tag\n"
718e3744 3111 "Specify a BGP neighbor\n"
3a2d747c
QY
3112 AS_STR
3113 "Internal BGP peer\n"
3114 "External BGP peer\n")
718e3744 3115{
d62a17ae 3116 VTY_DECLVAR_CONTEXT(bgp, bgp);
3117 int idx_word = 2;
3118 struct peer_group *group;
3119 struct peer *peer;
3120
3121 /* look up for neighbor by interface name config. */
3122 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3123 if (peer) {
3124 peer_as_change(peer, 0, AS_SPECIFIED);
3125 return CMD_SUCCESS;
3126 }
3127
3128 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3129 if (group)
3130 peer_group_remote_as_delete(group);
3131 else {
3132 vty_out(vty, "%% Create the peer-group or interface first\n");
3133 return CMD_WARNING_CONFIG_FAILED;
3134 }
3135 return CMD_SUCCESS;
718e3744 3136}
6b0655a2 3137
718e3744 3138DEFUN (neighbor_local_as,
3139 neighbor_local_as_cmd,
9ccf14f7 3140 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3141 NEIGHBOR_STR
3142 NEIGHBOR_ADDR_STR2
3143 "Specify a local-as number\n"
3144 "AS number used as local AS\n")
3145{
d62a17ae 3146 int idx_peer = 1;
3147 int idx_number = 3;
3148 struct peer *peer;
3149 int ret;
3150 as_t as;
718e3744 3151
d62a17ae 3152 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3153 if (!peer)
3154 return CMD_WARNING_CONFIG_FAILED;
718e3744 3155
d62a17ae 3156 as = strtoul(argv[idx_number]->arg, NULL, 10);
3157 ret = peer_local_as_set(peer, as, 0, 0);
3158 return bgp_vty_return(vty, ret);
718e3744 3159}
3160
3161DEFUN (neighbor_local_as_no_prepend,
3162 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3163 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3164 NEIGHBOR_STR
3165 NEIGHBOR_ADDR_STR2
3166 "Specify a local-as number\n"
3167 "AS number used as local AS\n"
3168 "Do not prepend local-as to updates from ebgp peers\n")
3169{
d62a17ae 3170 int idx_peer = 1;
3171 int idx_number = 3;
3172 struct peer *peer;
3173 int ret;
3174 as_t as;
718e3744 3175
d62a17ae 3176 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3177 if (!peer)
3178 return CMD_WARNING_CONFIG_FAILED;
718e3744 3179
d62a17ae 3180 as = strtoul(argv[idx_number]->arg, NULL, 10);
3181 ret = peer_local_as_set(peer, as, 1, 0);
3182 return bgp_vty_return(vty, ret);
718e3744 3183}
3184
9d3f9705
AC
3185DEFUN (neighbor_local_as_no_prepend_replace_as,
3186 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3187 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3188 NEIGHBOR_STR
3189 NEIGHBOR_ADDR_STR2
3190 "Specify a local-as number\n"
3191 "AS number used as local AS\n"
3192 "Do not prepend local-as to updates from ebgp peers\n"
3193 "Do not prepend local-as to updates from ibgp peers\n")
3194{
d62a17ae 3195 int idx_peer = 1;
3196 int idx_number = 3;
3197 struct peer *peer;
3198 int ret;
3199 as_t as;
9d3f9705 3200
d62a17ae 3201 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3202 if (!peer)
3203 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3204
d62a17ae 3205 as = strtoul(argv[idx_number]->arg, NULL, 10);
3206 ret = peer_local_as_set(peer, as, 1, 1);
3207 return bgp_vty_return(vty, ret);
9d3f9705
AC
3208}
3209
718e3744 3210DEFUN (no_neighbor_local_as,
3211 no_neighbor_local_as_cmd,
a636c635 3212 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3213 NO_STR
3214 NEIGHBOR_STR
3215 NEIGHBOR_ADDR_STR2
a636c635
DW
3216 "Specify a local-as number\n"
3217 "AS number used as local AS\n"
3218 "Do not prepend local-as to updates from ebgp peers\n"
3219 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3220{
d62a17ae 3221 int idx_peer = 2;
3222 struct peer *peer;
3223 int ret;
718e3744 3224
d62a17ae 3225 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3226 if (!peer)
3227 return CMD_WARNING_CONFIG_FAILED;
718e3744 3228
d62a17ae 3229 ret = peer_local_as_unset(peer);
3230 return bgp_vty_return(vty, ret);
718e3744 3231}
3232
718e3744 3233
3f9c7369
DS
3234DEFUN (neighbor_solo,
3235 neighbor_solo_cmd,
9ccf14f7 3236 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3237 NEIGHBOR_STR
3238 NEIGHBOR_ADDR_STR2
3239 "Solo peer - part of its own update group\n")
3240{
d62a17ae 3241 int idx_peer = 1;
3242 struct peer *peer;
3243 int ret;
3f9c7369 3244
d62a17ae 3245 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3246 if (!peer)
3247 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3248
d62a17ae 3249 ret = update_group_adjust_soloness(peer, 1);
3250 return bgp_vty_return(vty, ret);
3f9c7369
DS
3251}
3252
3253DEFUN (no_neighbor_solo,
3254 no_neighbor_solo_cmd,
9ccf14f7 3255 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3256 NO_STR
3257 NEIGHBOR_STR
3258 NEIGHBOR_ADDR_STR2
3259 "Solo peer - part of its own update group\n")
3260{
d62a17ae 3261 int idx_peer = 2;
3262 struct peer *peer;
3263 int ret;
3f9c7369 3264
d62a17ae 3265 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3266 if (!peer)
3267 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3268
d62a17ae 3269 ret = update_group_adjust_soloness(peer, 0);
3270 return bgp_vty_return(vty, ret);
3f9c7369
DS
3271}
3272
0df7c91f
PJ
3273DEFUN (neighbor_password,
3274 neighbor_password_cmd,
9ccf14f7 3275 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3276 NEIGHBOR_STR
3277 NEIGHBOR_ADDR_STR2
3278 "Set a password\n"
3279 "The password\n")
3280{
d62a17ae 3281 int idx_peer = 1;
3282 int idx_line = 3;
3283 struct peer *peer;
3284 int ret;
0df7c91f 3285
d62a17ae 3286 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3287 if (!peer)
3288 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3289
d62a17ae 3290 ret = peer_password_set(peer, argv[idx_line]->arg);
3291 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3292}
3293
3294DEFUN (no_neighbor_password,
3295 no_neighbor_password_cmd,
a636c635 3296 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3297 NO_STR
3298 NEIGHBOR_STR
3299 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3300 "Set a password\n"
3301 "The password\n")
0df7c91f 3302{
d62a17ae 3303 int idx_peer = 2;
3304 struct peer *peer;
3305 int ret;
0df7c91f 3306
d62a17ae 3307 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3308 if (!peer)
3309 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3310
d62a17ae 3311 ret = peer_password_unset(peer);
3312 return bgp_vty_return(vty, ret);
0df7c91f 3313}
6b0655a2 3314
718e3744 3315DEFUN (neighbor_activate,
3316 neighbor_activate_cmd,
9ccf14f7 3317 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3318 NEIGHBOR_STR
3319 NEIGHBOR_ADDR_STR2
3320 "Enable the Address Family for this Neighbor\n")
3321{
d62a17ae 3322 int idx_peer = 1;
3323 int ret;
3324 struct peer *peer;
718e3744 3325
d62a17ae 3326 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3327 if (!peer)
3328 return CMD_WARNING_CONFIG_FAILED;
718e3744 3329
d62a17ae 3330 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3331 return bgp_vty_return(vty, ret);
718e3744 3332}
3333
d62a17ae 3334ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3335 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3336 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3337 "Enable the Address Family for this Neighbor\n")
596c17ba 3338
718e3744 3339DEFUN (no_neighbor_activate,
3340 no_neighbor_activate_cmd,
9ccf14f7 3341 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3342 NO_STR
3343 NEIGHBOR_STR
3344 NEIGHBOR_ADDR_STR2
3345 "Enable the Address Family for this Neighbor\n")
3346{
d62a17ae 3347 int idx_peer = 2;
3348 int ret;
3349 struct peer *peer;
718e3744 3350
d62a17ae 3351 /* Lookup peer. */
3352 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3353 if (!peer)
3354 return CMD_WARNING_CONFIG_FAILED;
718e3744 3355
d62a17ae 3356 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3357 return bgp_vty_return(vty, ret);
718e3744 3358}
6b0655a2 3359
d62a17ae 3360ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3361 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3362 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3363 "Enable the Address Family for this Neighbor\n")
596c17ba 3364
718e3744 3365DEFUN (neighbor_set_peer_group,
3366 neighbor_set_peer_group_cmd,
9ccf14f7 3367 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3368 NEIGHBOR_STR
a80beece 3369 NEIGHBOR_ADDR_STR2
718e3744 3370 "Member of the peer-group\n"
16cedbb0 3371 "Peer-group name\n")
718e3744 3372{
d62a17ae 3373 VTY_DECLVAR_CONTEXT(bgp, bgp);
3374 int idx_peer = 1;
3375 int idx_word = 3;
3376 int ret;
3377 as_t as;
3378 union sockunion su;
3379 struct peer *peer;
3380 struct peer_group *group;
3381
3382 peer = NULL;
3383
3384 ret = str2sockunion(argv[idx_peer]->arg, &su);
3385 if (ret < 0) {
3386 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3387 if (!peer) {
3388 vty_out(vty, "%% Malformed address or name: %s\n",
3389 argv[idx_peer]->arg);
3390 return CMD_WARNING_CONFIG_FAILED;
3391 }
3392 } else {
3393 if (peer_address_self_check(bgp, &su)) {
3394 vty_out(vty,
3395 "%% Can not configure the local system as neighbor\n");
3396 return CMD_WARNING_CONFIG_FAILED;
3397 }
3398
3399 /* Disallow for dynamic neighbor. */
3400 peer = peer_lookup(bgp, &su);
3401 if (peer && peer_dynamic_neighbor(peer)) {
3402 vty_out(vty,
3403 "%% Operation not allowed on a dynamic neighbor\n");
3404 return CMD_WARNING_CONFIG_FAILED;
3405 }
3406 }
3407
3408 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3409 if (!group) {
3410 vty_out(vty, "%% Configure the peer-group first\n");
3411 return CMD_WARNING_CONFIG_FAILED;
3412 }
3413
3414 ret = peer_group_bind(bgp, &su, peer, group, &as);
3415
3416 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3417 vty_out(vty,
3418 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3419 as);
3420 return CMD_WARNING_CONFIG_FAILED;
3421 }
3422
3423 return bgp_vty_return(vty, ret);
3424}
3425
3426ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3427 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3428 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3429 "Member of the peer-group\n"
3430 "Peer-group name\n")
596c17ba 3431
718e3744 3432DEFUN (no_neighbor_set_peer_group,
3433 no_neighbor_set_peer_group_cmd,
9ccf14f7 3434 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3435 NO_STR
3436 NEIGHBOR_STR
a80beece 3437 NEIGHBOR_ADDR_STR2
718e3744 3438 "Member of the peer-group\n"
16cedbb0 3439 "Peer-group name\n")
718e3744 3440{
d62a17ae 3441 VTY_DECLVAR_CONTEXT(bgp, bgp);
3442 int idx_peer = 2;
3443 int idx_word = 4;
3444 int ret;
3445 struct peer *peer;
3446 struct peer_group *group;
3447
3448 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3449 if (!peer)
3450 return CMD_WARNING_CONFIG_FAILED;
3451
3452 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3453 if (!group) {
3454 vty_out(vty, "%% Configure the peer-group first\n");
3455 return CMD_WARNING_CONFIG_FAILED;
3456 }
718e3744 3457
827ed707 3458 ret = peer_delete(peer);
718e3744 3459
d62a17ae 3460 return bgp_vty_return(vty, ret);
718e3744 3461}
6b0655a2 3462
d62a17ae 3463ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3464 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3465 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3466 "Member of the peer-group\n"
3467 "Peer-group name\n")
596c17ba 3468
d62a17ae 3469static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3470 uint32_t flag, int set)
718e3744 3471{
d62a17ae 3472 int ret;
3473 struct peer *peer;
718e3744 3474
d62a17ae 3475 peer = peer_and_group_lookup_vty(vty, ip_str);
3476 if (!peer)
3477 return CMD_WARNING_CONFIG_FAILED;
718e3744 3478
7ebe625c
QY
3479 /*
3480 * If 'neighbor <interface>', then this is for directly connected peers,
3481 * we should not accept disable-connected-check.
3482 */
3483 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3484 vty_out(vty,
3485 "%s is directly connected peer, cannot accept disable-"
3486 "connected-check\n",
3487 ip_str);
3488 return CMD_WARNING_CONFIG_FAILED;
3489 }
3490
d62a17ae 3491 if (!set && flag == PEER_FLAG_SHUTDOWN)
3492 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3493
d62a17ae 3494 if (set)
3495 ret = peer_flag_set(peer, flag);
3496 else
3497 ret = peer_flag_unset(peer, flag);
718e3744 3498
d62a17ae 3499 return bgp_vty_return(vty, ret);
718e3744 3500}
3501
47cbc09b 3502static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3503{
d62a17ae 3504 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3505}
3506
d62a17ae 3507static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3508 uint32_t flag)
718e3744 3509{
d62a17ae 3510 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3511}
3512
3513/* neighbor passive. */
3514DEFUN (neighbor_passive,
3515 neighbor_passive_cmd,
9ccf14f7 3516 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3517 NEIGHBOR_STR
3518 NEIGHBOR_ADDR_STR2
3519 "Don't send open messages to this neighbor\n")
3520{
d62a17ae 3521 int idx_peer = 1;
3522 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3523}
3524
3525DEFUN (no_neighbor_passive,
3526 no_neighbor_passive_cmd,
9ccf14f7 3527 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3528 NO_STR
3529 NEIGHBOR_STR
3530 NEIGHBOR_ADDR_STR2
3531 "Don't send open messages to this neighbor\n")
3532{
d62a17ae 3533 int idx_peer = 2;
3534 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3535}
6b0655a2 3536
718e3744 3537/* neighbor shutdown. */
73d70fa6
DL
3538DEFUN (neighbor_shutdown_msg,
3539 neighbor_shutdown_msg_cmd,
3540 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3541 NEIGHBOR_STR
3542 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3543 "Administratively shut down this neighbor\n"
3544 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3545 "Shutdown message\n")
718e3744 3546{
d62a17ae 3547 int idx_peer = 1;
73d70fa6 3548
d62a17ae 3549 if (argc >= 5) {
3550 struct peer *peer =
3551 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3552 char *message;
73d70fa6 3553
d62a17ae 3554 if (!peer)
3555 return CMD_WARNING_CONFIG_FAILED;
3556 message = argv_concat(argv, argc, 4);
3557 peer_tx_shutdown_message_set(peer, message);
3558 XFREE(MTYPE_TMP, message);
3559 }
73d70fa6 3560
d62a17ae 3561 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3562}
3563
d62a17ae 3564ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3565 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3566 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3567 "Administratively shut down this neighbor\n")
73d70fa6
DL
3568
3569DEFUN (no_neighbor_shutdown_msg,
3570 no_neighbor_shutdown_msg_cmd,
3571 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3572 NO_STR
3573 NEIGHBOR_STR
3574 NEIGHBOR_ADDR_STR2
3575 "Administratively shut down this neighbor\n"
3576 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3577 "Shutdown message\n")
718e3744 3578{
d62a17ae 3579 int idx_peer = 2;
73d70fa6 3580
d62a17ae 3581 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3582 PEER_FLAG_SHUTDOWN);
718e3744 3583}
6b0655a2 3584
d62a17ae 3585ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3586 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3587 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3588 "Administratively shut down this neighbor\n")
73d70fa6 3589
718e3744 3590/* neighbor capability dynamic. */
3591DEFUN (neighbor_capability_dynamic,
3592 neighbor_capability_dynamic_cmd,
9ccf14f7 3593 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3594 NEIGHBOR_STR
3595 NEIGHBOR_ADDR_STR2
3596 "Advertise capability to the peer\n"
3597 "Advertise dynamic capability to this neighbor\n")
3598{
d62a17ae 3599 int idx_peer = 1;
3600 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3601 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3602}
3603
3604DEFUN (no_neighbor_capability_dynamic,
3605 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3606 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3607 NO_STR
3608 NEIGHBOR_STR
3609 NEIGHBOR_ADDR_STR2
3610 "Advertise capability to the peer\n"
3611 "Advertise dynamic capability to this neighbor\n")
3612{
d62a17ae 3613 int idx_peer = 2;
3614 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3615 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3616}
6b0655a2 3617
718e3744 3618/* neighbor dont-capability-negotiate */
3619DEFUN (neighbor_dont_capability_negotiate,
3620 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3621 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3622 NEIGHBOR_STR
3623 NEIGHBOR_ADDR_STR2
3624 "Do not perform capability negotiation\n")
3625{
d62a17ae 3626 int idx_peer = 1;
3627 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3628 PEER_FLAG_DONT_CAPABILITY);
718e3744 3629}
3630
3631DEFUN (no_neighbor_dont_capability_negotiate,
3632 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3633 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3634 NO_STR
3635 NEIGHBOR_STR
3636 NEIGHBOR_ADDR_STR2
3637 "Do not perform capability negotiation\n")
3638{
d62a17ae 3639 int idx_peer = 2;
3640 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3641 PEER_FLAG_DONT_CAPABILITY);
718e3744 3642}
6b0655a2 3643
8a92a8a0
DS
3644/* neighbor capability extended next hop encoding */
3645DEFUN (neighbor_capability_enhe,
3646 neighbor_capability_enhe_cmd,
9ccf14f7 3647 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3648 NEIGHBOR_STR
3649 NEIGHBOR_ADDR_STR2
3650 "Advertise capability to the peer\n"
3651 "Advertise extended next-hop capability to the peer\n")
3652{
d62a17ae 3653 int idx_peer = 1;
3654 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3655 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3656}
3657
3658DEFUN (no_neighbor_capability_enhe,
3659 no_neighbor_capability_enhe_cmd,
9ccf14f7 3660 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3661 NO_STR
3662 NEIGHBOR_STR
3663 NEIGHBOR_ADDR_STR2
3664 "Advertise capability to the peer\n"
3665 "Advertise extended next-hop capability to the peer\n")
3666{
d62a17ae 3667 int idx_peer = 2;
3668 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3669 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3670}
3671
d62a17ae 3672static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3673 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3674 int set)
718e3744 3675{
d62a17ae 3676 int ret;
3677 struct peer *peer;
718e3744 3678
d62a17ae 3679 peer = peer_and_group_lookup_vty(vty, peer_str);
3680 if (!peer)
3681 return CMD_WARNING_CONFIG_FAILED;
718e3744 3682
d62a17ae 3683 if (set)
3684 ret = peer_af_flag_set(peer, afi, safi, flag);
3685 else
3686 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3687
d62a17ae 3688 return bgp_vty_return(vty, ret);
718e3744 3689}
3690
d62a17ae 3691static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3692 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3693{
d62a17ae 3694 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3695}
3696
d62a17ae 3697static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3698 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3699{
d62a17ae 3700 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3701}
6b0655a2 3702
718e3744 3703/* neighbor capability orf prefix-list. */
3704DEFUN (neighbor_capability_orf_prefix,
3705 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3706 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3707 NEIGHBOR_STR
3708 NEIGHBOR_ADDR_STR2
3709 "Advertise capability to the peer\n"
3710 "Advertise ORF capability to the peer\n"
3711 "Advertise prefixlist ORF capability to this neighbor\n"
3712 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3713 "Capability to RECEIVE the ORF from this neighbor\n"
3714 "Capability to SEND the ORF to this neighbor\n")
3715{
d62a17ae 3716 int idx_peer = 1;
3717 int idx_send_recv = 5;
d7c0a89a 3718 uint16_t flag = 0;
d62a17ae 3719
3720 if (strmatch(argv[idx_send_recv]->text, "send"))
3721 flag = PEER_FLAG_ORF_PREFIX_SM;
3722 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3723 flag = PEER_FLAG_ORF_PREFIX_RM;
3724 else if (strmatch(argv[idx_send_recv]->text, "both"))
3725 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3726 else {
3727 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3728 return CMD_WARNING_CONFIG_FAILED;
3729 }
3730
3731 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3732 bgp_node_safi(vty), flag);
3733}
3734
3735ALIAS_HIDDEN(
3736 neighbor_capability_orf_prefix,
3737 neighbor_capability_orf_prefix_hidden_cmd,
3738 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3739 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3740 "Advertise capability to the peer\n"
3741 "Advertise ORF capability to the peer\n"
3742 "Advertise prefixlist ORF capability to this neighbor\n"
3743 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3744 "Capability to RECEIVE the ORF from this neighbor\n"
3745 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3746
718e3744 3747DEFUN (no_neighbor_capability_orf_prefix,
3748 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3749 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3750 NO_STR
3751 NEIGHBOR_STR
3752 NEIGHBOR_ADDR_STR2
3753 "Advertise capability to the peer\n"
3754 "Advertise ORF capability to the peer\n"
3755 "Advertise prefixlist ORF capability to this neighbor\n"
3756 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3757 "Capability to RECEIVE the ORF from this neighbor\n"
3758 "Capability to SEND the ORF to this neighbor\n")
3759{
d62a17ae 3760 int idx_peer = 2;
3761 int idx_send_recv = 6;
d7c0a89a 3762 uint16_t flag = 0;
d62a17ae 3763
3764 if (strmatch(argv[idx_send_recv]->text, "send"))
3765 flag = PEER_FLAG_ORF_PREFIX_SM;
3766 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3767 flag = PEER_FLAG_ORF_PREFIX_RM;
3768 else if (strmatch(argv[idx_send_recv]->text, "both"))
3769 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3770 else {
3771 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3772 return CMD_WARNING_CONFIG_FAILED;
3773 }
3774
3775 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3776 bgp_node_afi(vty), bgp_node_safi(vty),
3777 flag);
3778}
3779
3780ALIAS_HIDDEN(
3781 no_neighbor_capability_orf_prefix,
3782 no_neighbor_capability_orf_prefix_hidden_cmd,
3783 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3784 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3785 "Advertise capability to the peer\n"
3786 "Advertise ORF capability to the peer\n"
3787 "Advertise prefixlist ORF capability to this neighbor\n"
3788 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3789 "Capability to RECEIVE the ORF from this neighbor\n"
3790 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3791
718e3744 3792/* neighbor next-hop-self. */
3793DEFUN (neighbor_nexthop_self,
3794 neighbor_nexthop_self_cmd,
9ccf14f7 3795 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3796 NEIGHBOR_STR
3797 NEIGHBOR_ADDR_STR2
a538debe 3798 "Disable the next hop calculation for this neighbor\n")
718e3744 3799{
d62a17ae 3800 int idx_peer = 1;
3801 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3802 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3803}
9e7a53c1 3804
d62a17ae 3805ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3806 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3807 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3808 "Disable the next hop calculation for this neighbor\n")
596c17ba 3809
a538debe
DS
3810/* neighbor next-hop-self. */
3811DEFUN (neighbor_nexthop_self_force,
3812 neighbor_nexthop_self_force_cmd,
9ccf14f7 3813 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3814 NEIGHBOR_STR
3815 NEIGHBOR_ADDR_STR2
3816 "Disable the next hop calculation for this neighbor\n"
3817 "Set the next hop to self for reflected routes\n")
3818{
d62a17ae 3819 int idx_peer = 1;
3820 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3821 bgp_node_safi(vty),
3822 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3823}
3824
d62a17ae 3825ALIAS_HIDDEN(neighbor_nexthop_self_force,
3826 neighbor_nexthop_self_force_hidden_cmd,
3827 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3828 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3829 "Disable the next hop calculation for this neighbor\n"
3830 "Set the next hop to self for reflected routes\n")
596c17ba 3831
718e3744 3832DEFUN (no_neighbor_nexthop_self,
3833 no_neighbor_nexthop_self_cmd,
9ccf14f7 3834 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3835 NO_STR
3836 NEIGHBOR_STR
3837 NEIGHBOR_ADDR_STR2
a538debe 3838 "Disable the next hop calculation for this neighbor\n")
718e3744 3839{
d62a17ae 3840 int idx_peer = 2;
3841 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3842 bgp_node_afi(vty), bgp_node_safi(vty),
3843 PEER_FLAG_NEXTHOP_SELF);
718e3744 3844}
6b0655a2 3845
d62a17ae 3846ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3847 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3848 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3849 "Disable the next hop calculation for this neighbor\n")
596c17ba 3850
88b8ed8d 3851DEFUN (no_neighbor_nexthop_self_force,
a538debe 3852 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3853 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3854 NO_STR
3855 NEIGHBOR_STR
3856 NEIGHBOR_ADDR_STR2
3857 "Disable the next hop calculation for this neighbor\n"
3858 "Set the next hop to self for reflected routes\n")
88b8ed8d 3859{
d62a17ae 3860 int idx_peer = 2;
3861 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3862 bgp_node_afi(vty), bgp_node_safi(vty),
3863 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3864}
a538debe 3865
d62a17ae 3866ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3867 no_neighbor_nexthop_self_force_hidden_cmd,
3868 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3869 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3870 "Disable the next hop calculation for this neighbor\n"
3871 "Set the next hop to self for reflected routes\n")
596c17ba 3872
c7122e14
DS
3873/* neighbor as-override */
3874DEFUN (neighbor_as_override,
3875 neighbor_as_override_cmd,
9ccf14f7 3876 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
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 = 1;
3882 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3883 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3884}
3885
d62a17ae 3886ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3887 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3888 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3889 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3890
c7122e14
DS
3891DEFUN (no_neighbor_as_override,
3892 no_neighbor_as_override_cmd,
9ccf14f7 3893 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3894 NO_STR
3895 NEIGHBOR_STR
3896 NEIGHBOR_ADDR_STR2
3897 "Override ASNs in outbound updates if aspath equals remote-as\n")
3898{
d62a17ae 3899 int idx_peer = 2;
3900 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3901 bgp_node_afi(vty), bgp_node_safi(vty),
3902 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3903}
3904
d62a17ae 3905ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3906 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3907 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3908 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3909
718e3744 3910/* neighbor remove-private-AS. */
3911DEFUN (neighbor_remove_private_as,
3912 neighbor_remove_private_as_cmd,
9ccf14f7 3913 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3914 NEIGHBOR_STR
3915 NEIGHBOR_ADDR_STR2
5000f21c 3916 "Remove private ASNs in outbound updates\n")
718e3744 3917{
d62a17ae 3918 int idx_peer = 1;
3919 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3920 bgp_node_safi(vty),
3921 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3922}
3923
d62a17ae 3924ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3925 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3926 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3927 "Remove private ASNs in outbound updates\n")
596c17ba 3928
5000f21c
DS
3929DEFUN (neighbor_remove_private_as_all,
3930 neighbor_remove_private_as_all_cmd,
9ccf14f7 3931 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3932 NEIGHBOR_STR
3933 NEIGHBOR_ADDR_STR2
3934 "Remove private ASNs in outbound updates\n"
efd7904e 3935 "Apply to all AS numbers\n")
5000f21c 3936{
d62a17ae 3937 int idx_peer = 1;
3938 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3939 bgp_node_safi(vty),
3940 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3941}
3942
d62a17ae 3943ALIAS_HIDDEN(neighbor_remove_private_as_all,
3944 neighbor_remove_private_as_all_hidden_cmd,
3945 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3946 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3947 "Remove private ASNs in outbound updates\n"
3948 "Apply to all AS numbers")
596c17ba 3949
5000f21c
DS
3950DEFUN (neighbor_remove_private_as_replace_as,
3951 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3952 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3953 NEIGHBOR_STR
3954 NEIGHBOR_ADDR_STR2
3955 "Remove private ASNs in outbound updates\n"
3956 "Replace private ASNs with our ASN in outbound updates\n")
3957{
d62a17ae 3958 int idx_peer = 1;
3959 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3960 bgp_node_safi(vty),
3961 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3962}
3963
d62a17ae 3964ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3965 neighbor_remove_private_as_replace_as_hidden_cmd,
3966 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3967 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3968 "Remove private ASNs in outbound updates\n"
3969 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3970
5000f21c
DS
3971DEFUN (neighbor_remove_private_as_all_replace_as,
3972 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3973 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3974 NEIGHBOR_STR
3975 NEIGHBOR_ADDR_STR2
3976 "Remove private ASNs in outbound updates\n"
16cedbb0 3977 "Apply to all AS numbers\n"
5000f21c
DS
3978 "Replace private ASNs with our ASN in outbound updates\n")
3979{
d62a17ae 3980 int idx_peer = 1;
3981 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3982 bgp_node_safi(vty),
3983 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3984}
3985
d62a17ae 3986ALIAS_HIDDEN(
3987 neighbor_remove_private_as_all_replace_as,
3988 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3989 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3990 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3991 "Remove private ASNs in outbound updates\n"
3992 "Apply to all AS numbers\n"
3993 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3994
718e3744 3995DEFUN (no_neighbor_remove_private_as,
3996 no_neighbor_remove_private_as_cmd,
9ccf14f7 3997 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3998 NO_STR
3999 NEIGHBOR_STR
4000 NEIGHBOR_ADDR_STR2
5000f21c 4001 "Remove private ASNs in outbound updates\n")
718e3744 4002{
d62a17ae 4003 int idx_peer = 2;
4004 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4005 bgp_node_afi(vty), bgp_node_safi(vty),
4006 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4007}
6b0655a2 4008
d62a17ae 4009ALIAS_HIDDEN(no_neighbor_remove_private_as,
4010 no_neighbor_remove_private_as_hidden_cmd,
4011 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4012 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4013 "Remove private ASNs in outbound updates\n")
596c17ba 4014
88b8ed8d 4015DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4016 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4017 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4018 NO_STR
4019 NEIGHBOR_STR
4020 NEIGHBOR_ADDR_STR2
4021 "Remove private ASNs in outbound updates\n"
16cedbb0 4022 "Apply to all AS numbers\n")
88b8ed8d 4023{
d62a17ae 4024 int idx_peer = 2;
4025 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4026 bgp_node_afi(vty), bgp_node_safi(vty),
4027 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4028}
5000f21c 4029
d62a17ae 4030ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4031 no_neighbor_remove_private_as_all_hidden_cmd,
4032 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4033 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4034 "Remove private ASNs in outbound updates\n"
4035 "Apply to all AS numbers\n")
596c17ba 4036
88b8ed8d 4037DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4038 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4039 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4040 NO_STR
4041 NEIGHBOR_STR
4042 NEIGHBOR_ADDR_STR2
4043 "Remove private ASNs in outbound updates\n"
4044 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4045{
d62a17ae 4046 int idx_peer = 2;
4047 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4048 bgp_node_afi(vty), bgp_node_safi(vty),
4049 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4050}
5000f21c 4051
d62a17ae 4052ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4053 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4054 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4055 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4056 "Remove private ASNs in outbound updates\n"
4057 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4058
88b8ed8d 4059DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4060 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4061 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4062 NO_STR
4063 NEIGHBOR_STR
4064 NEIGHBOR_ADDR_STR2
4065 "Remove private ASNs in outbound updates\n"
16cedbb0 4066 "Apply to all AS numbers\n"
5000f21c 4067 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4068{
d62a17ae 4069 int idx_peer = 2;
4070 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4071 bgp_node_afi(vty), bgp_node_safi(vty),
4072 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4073}
5000f21c 4074
d62a17ae 4075ALIAS_HIDDEN(
4076 no_neighbor_remove_private_as_all_replace_as,
4077 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4078 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4079 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4080 "Remove private ASNs in outbound updates\n"
4081 "Apply to all AS numbers\n"
4082 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4083
5000f21c 4084
718e3744 4085/* neighbor send-community. */
4086DEFUN (neighbor_send_community,
4087 neighbor_send_community_cmd,
9ccf14f7 4088 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4089 NEIGHBOR_STR
4090 NEIGHBOR_ADDR_STR2
4091 "Send Community attribute to this neighbor\n")
4092{
d62a17ae 4093 int idx_peer = 1;
27c05d4d 4094
d62a17ae 4095 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4096 bgp_node_safi(vty),
4097 PEER_FLAG_SEND_COMMUNITY);
718e3744 4098}
4099
d62a17ae 4100ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4101 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4102 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4103 "Send Community attribute to this neighbor\n")
596c17ba 4104
718e3744 4105DEFUN (no_neighbor_send_community,
4106 no_neighbor_send_community_cmd,
9ccf14f7 4107 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4108 NO_STR
4109 NEIGHBOR_STR
4110 NEIGHBOR_ADDR_STR2
4111 "Send Community attribute to this neighbor\n")
4112{
d62a17ae 4113 int idx_peer = 2;
27c05d4d 4114
d62a17ae 4115 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4116 bgp_node_afi(vty), bgp_node_safi(vty),
4117 PEER_FLAG_SEND_COMMUNITY);
718e3744 4118}
6b0655a2 4119
d62a17ae 4120ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4121 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4122 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4123 "Send Community attribute to this neighbor\n")
596c17ba 4124
718e3744 4125/* neighbor send-community extended. */
4126DEFUN (neighbor_send_community_type,
4127 neighbor_send_community_type_cmd,
57d187bc 4128 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4129 NEIGHBOR_STR
4130 NEIGHBOR_ADDR_STR2
4131 "Send Community attribute to this neighbor\n"
4132 "Send Standard and Extended Community attributes\n"
57d187bc 4133 "Send Standard, Large and Extended Community attributes\n"
718e3744 4134 "Send Extended Community attributes\n"
57d187bc
JS
4135 "Send Standard Community attributes\n"
4136 "Send Large Community attributes\n")
718e3744 4137{
27c05d4d 4138 int idx_peer = 1;
d7c0a89a 4139 uint32_t flag = 0;
27c05d4d 4140 const char *type = argv[argc - 1]->text;
d62a17ae 4141
27c05d4d 4142 if (strmatch(type, "standard")) {
d62a17ae 4143 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4144 } else if (strmatch(type, "extended")) {
d62a17ae 4145 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4146 } else if (strmatch(type, "large")) {
d62a17ae 4147 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4148 } else if (strmatch(type, "both")) {
d62a17ae 4149 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4150 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4151 } else { /* if (strmatch(type, "all")) */
d62a17ae 4152 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4153 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4154 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4155 }
4156
27c05d4d 4157 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4158 bgp_node_safi(vty), flag);
4159}
4160
4161ALIAS_HIDDEN(
4162 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4163 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4164 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4165 "Send Community attribute to this neighbor\n"
4166 "Send Standard and Extended Community attributes\n"
4167 "Send Standard, Large and Extended Community attributes\n"
4168 "Send Extended Community attributes\n"
4169 "Send Standard Community attributes\n"
4170 "Send Large Community attributes\n")
596c17ba 4171
718e3744 4172DEFUN (no_neighbor_send_community_type,
4173 no_neighbor_send_community_type_cmd,
57d187bc 4174 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4175 NO_STR
4176 NEIGHBOR_STR
4177 NEIGHBOR_ADDR_STR2
4178 "Send Community attribute to this neighbor\n"
4179 "Send Standard and Extended Community attributes\n"
57d187bc 4180 "Send Standard, Large and Extended Community attributes\n"
718e3744 4181 "Send Extended Community attributes\n"
57d187bc
JS
4182 "Send Standard Community attributes\n"
4183 "Send Large Community attributes\n")
718e3744 4184{
d62a17ae 4185 int idx_peer = 2;
27c05d4d 4186 uint32_t flag = 0;
d62a17ae 4187 const char *type = argv[argc - 1]->text;
4188
27c05d4d
PM
4189 if (strmatch(type, "standard")) {
4190 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4191 } else if (strmatch(type, "extended")) {
4192 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4193 } else if (strmatch(type, "large")) {
4194 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4195 } else if (strmatch(type, "both")) {
4196 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4197 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4198 } else { /* if (strmatch(type, "all")) */
4199 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4200 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4201 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4202 }
4203
4204 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4205 bgp_node_afi(vty), bgp_node_safi(vty),
4206 flag);
d62a17ae 4207}
4208
4209ALIAS_HIDDEN(
4210 no_neighbor_send_community_type,
4211 no_neighbor_send_community_type_hidden_cmd,
4212 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4213 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4214 "Send Community attribute to this neighbor\n"
4215 "Send Standard and Extended Community attributes\n"
4216 "Send Standard, Large and Extended Community attributes\n"
4217 "Send Extended Community attributes\n"
4218 "Send Standard Community attributes\n"
4219 "Send Large Community attributes\n")
596c17ba 4220
718e3744 4221/* neighbor soft-reconfig. */
4222DEFUN (neighbor_soft_reconfiguration,
4223 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4224 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4225 NEIGHBOR_STR
4226 NEIGHBOR_ADDR_STR2
4227 "Per neighbor soft reconfiguration\n"
4228 "Allow inbound soft reconfiguration for this neighbor\n")
4229{
d62a17ae 4230 int idx_peer = 1;
4231 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4232 bgp_node_safi(vty),
4233 PEER_FLAG_SOFT_RECONFIG);
718e3744 4234}
4235
d62a17ae 4236ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4237 neighbor_soft_reconfiguration_hidden_cmd,
4238 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4239 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4240 "Per neighbor soft reconfiguration\n"
4241 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4242
718e3744 4243DEFUN (no_neighbor_soft_reconfiguration,
4244 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4245 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4246 NO_STR
4247 NEIGHBOR_STR
4248 NEIGHBOR_ADDR_STR2
4249 "Per neighbor soft reconfiguration\n"
4250 "Allow inbound soft reconfiguration for this neighbor\n")
4251{
d62a17ae 4252 int idx_peer = 2;
4253 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4254 bgp_node_afi(vty), bgp_node_safi(vty),
4255 PEER_FLAG_SOFT_RECONFIG);
718e3744 4256}
6b0655a2 4257
d62a17ae 4258ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4259 no_neighbor_soft_reconfiguration_hidden_cmd,
4260 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4261 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4262 "Per neighbor soft reconfiguration\n"
4263 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4264
718e3744 4265DEFUN (neighbor_route_reflector_client,
4266 neighbor_route_reflector_client_cmd,
9ccf14f7 4267 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4268 NEIGHBOR_STR
4269 NEIGHBOR_ADDR_STR2
4270 "Configure a neighbor as Route Reflector client\n")
4271{
d62a17ae 4272 int idx_peer = 1;
4273 struct peer *peer;
718e3744 4274
4275
d62a17ae 4276 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4277 if (!peer)
4278 return CMD_WARNING_CONFIG_FAILED;
718e3744 4279
d62a17ae 4280 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4281 bgp_node_safi(vty),
4282 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4283}
4284
d62a17ae 4285ALIAS_HIDDEN(neighbor_route_reflector_client,
4286 neighbor_route_reflector_client_hidden_cmd,
4287 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4288 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4289 "Configure a neighbor as Route Reflector client\n")
596c17ba 4290
718e3744 4291DEFUN (no_neighbor_route_reflector_client,
4292 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4293 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4294 NO_STR
4295 NEIGHBOR_STR
4296 NEIGHBOR_ADDR_STR2
4297 "Configure a neighbor as Route Reflector client\n")
4298{
d62a17ae 4299 int idx_peer = 2;
4300 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4301 bgp_node_afi(vty), bgp_node_safi(vty),
4302 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4303}
6b0655a2 4304
d62a17ae 4305ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4306 no_neighbor_route_reflector_client_hidden_cmd,
4307 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4308 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4309 "Configure a neighbor as Route Reflector client\n")
596c17ba 4310
718e3744 4311/* neighbor route-server-client. */
4312DEFUN (neighbor_route_server_client,
4313 neighbor_route_server_client_cmd,
9ccf14f7 4314 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4315 NEIGHBOR_STR
4316 NEIGHBOR_ADDR_STR2
4317 "Configure a neighbor as Route Server client\n")
4318{
d62a17ae 4319 int idx_peer = 1;
4320 struct peer *peer;
2a3d5731 4321
d62a17ae 4322 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4323 if (!peer)
4324 return CMD_WARNING_CONFIG_FAILED;
4325 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4326 bgp_node_safi(vty),
4327 PEER_FLAG_RSERVER_CLIENT);
718e3744 4328}
4329
d62a17ae 4330ALIAS_HIDDEN(neighbor_route_server_client,
4331 neighbor_route_server_client_hidden_cmd,
4332 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4333 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4334 "Configure a neighbor as Route Server client\n")
596c17ba 4335
718e3744 4336DEFUN (no_neighbor_route_server_client,
4337 no_neighbor_route_server_client_cmd,
9ccf14f7 4338 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4339 NO_STR
4340 NEIGHBOR_STR
4341 NEIGHBOR_ADDR_STR2
4342 "Configure a neighbor as Route Server client\n")
fee0f4c6 4343{
d62a17ae 4344 int idx_peer = 2;
4345 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4346 bgp_node_afi(vty), bgp_node_safi(vty),
4347 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4348}
6b0655a2 4349
d62a17ae 4350ALIAS_HIDDEN(no_neighbor_route_server_client,
4351 no_neighbor_route_server_client_hidden_cmd,
4352 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4353 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4354 "Configure a neighbor as Route Server client\n")
596c17ba 4355
fee0f4c6 4356DEFUN (neighbor_nexthop_local_unchanged,
4357 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4358 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4359 NEIGHBOR_STR
4360 NEIGHBOR_ADDR_STR2
4361 "Configure treatment of outgoing link-local nexthop attribute\n"
4362 "Leave link-local nexthop unchanged for this peer\n")
4363{
d62a17ae 4364 int idx_peer = 1;
4365 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4366 bgp_node_safi(vty),
4367 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4368}
6b0655a2 4369
fee0f4c6 4370DEFUN (no_neighbor_nexthop_local_unchanged,
4371 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4372 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4373 NO_STR
4374 NEIGHBOR_STR
4375 NEIGHBOR_ADDR_STR2
4376 "Configure treatment of outgoing link-local-nexthop attribute\n"
4377 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4378{
d62a17ae 4379 int idx_peer = 2;
4380 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4381 bgp_node_afi(vty), bgp_node_safi(vty),
4382 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4383}
6b0655a2 4384
718e3744 4385DEFUN (neighbor_attr_unchanged,
4386 neighbor_attr_unchanged_cmd,
a8206004 4387 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4388 NEIGHBOR_STR
4389 NEIGHBOR_ADDR_STR2
4390 "BGP attribute is propagated unchanged to this neighbor\n"
4391 "As-path attribute\n"
4392 "Nexthop attribute\n"
a8206004 4393 "Med attribute\n")
718e3744 4394{
d62a17ae 4395 int idx = 0;
8eeb0335
DW
4396 char *peer_str = argv[1]->arg;
4397 struct peer *peer;
d7c0a89a 4398 uint16_t flags = 0;
8eeb0335
DW
4399 afi_t afi = bgp_node_afi(vty);
4400 safi_t safi = bgp_node_safi(vty);
4401
4402 peer = peer_and_group_lookup_vty(vty, peer_str);
4403 if (!peer)
4404 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4405
4406 if (argv_find(argv, argc, "as-path", &idx))
4407 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4408 idx = 0;
4409 if (argv_find(argv, argc, "next-hop", &idx))
4410 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4411 idx = 0;
4412 if (argv_find(argv, argc, "med", &idx))
4413 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4414
8eeb0335
DW
4415 /* no flags means all of them! */
4416 if (!flags) {
d62a17ae 4417 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4418 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4419 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4420 } else {
a4d82a8a
PZ
4421 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4422 && peer_af_flag_check(peer, afi, safi,
4423 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4424 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4425 PEER_FLAG_AS_PATH_UNCHANGED);
4426 }
4427
a4d82a8a
PZ
4428 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4429 && peer_af_flag_check(peer, afi, safi,
4430 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4431 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4432 PEER_FLAG_NEXTHOP_UNCHANGED);
4433 }
4434
a4d82a8a
PZ
4435 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4436 && peer_af_flag_check(peer, afi, safi,
4437 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4438 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4439 PEER_FLAG_MED_UNCHANGED);
4440 }
d62a17ae 4441 }
4442
8eeb0335 4443 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4444}
4445
4446ALIAS_HIDDEN(
4447 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4448 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4449 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4450 "BGP attribute is propagated unchanged to this neighbor\n"
4451 "As-path attribute\n"
4452 "Nexthop attribute\n"
4453 "Med attribute\n")
596c17ba 4454
718e3744 4455DEFUN (no_neighbor_attr_unchanged,
4456 no_neighbor_attr_unchanged_cmd,
a8206004 4457 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4458 NO_STR
718e3744 4459 NEIGHBOR_STR
4460 NEIGHBOR_ADDR_STR2
31500417
DW
4461 "BGP attribute is propagated unchanged to this neighbor\n"
4462 "As-path attribute\n"
40e718b5 4463 "Nexthop attribute\n"
a8206004 4464 "Med attribute\n")
718e3744 4465{
d62a17ae 4466 int idx = 0;
4467 char *peer = argv[2]->arg;
d7c0a89a 4468 uint16_t flags = 0;
d62a17ae 4469
4470 if (argv_find(argv, argc, "as-path", &idx))
4471 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4472 idx = 0;
4473 if (argv_find(argv, argc, "next-hop", &idx))
4474 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4475 idx = 0;
4476 if (argv_find(argv, argc, "med", &idx))
4477 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4478
4479 if (!flags) // no flags means all of them!
4480 {
4481 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4482 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4483 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4484 }
4485
4486 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4487 bgp_node_safi(vty), flags);
4488}
4489
4490ALIAS_HIDDEN(
4491 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4492 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4493 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4494 "BGP attribute is propagated unchanged to this neighbor\n"
4495 "As-path attribute\n"
4496 "Nexthop attribute\n"
4497 "Med attribute\n")
718e3744 4498
718e3744 4499/* EBGP multihop configuration. */
d62a17ae 4500static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4501 const char *ttl_str)
718e3744 4502{
d62a17ae 4503 struct peer *peer;
4504 unsigned int ttl;
718e3744 4505
d62a17ae 4506 peer = peer_and_group_lookup_vty(vty, ip_str);
4507 if (!peer)
4508 return CMD_WARNING_CONFIG_FAILED;
718e3744 4509
d62a17ae 4510 if (peer->conf_if)
4511 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4512
d62a17ae 4513 if (!ttl_str)
4514 ttl = MAXTTL;
4515 else
4516 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4517
d62a17ae 4518 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4519}
4520
d62a17ae 4521static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4522{
d62a17ae 4523 struct peer *peer;
718e3744 4524
d62a17ae 4525 peer = peer_and_group_lookup_vty(vty, ip_str);
4526 if (!peer)
4527 return CMD_WARNING_CONFIG_FAILED;
718e3744 4528
d62a17ae 4529 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4530}
4531
4532/* neighbor ebgp-multihop. */
4533DEFUN (neighbor_ebgp_multihop,
4534 neighbor_ebgp_multihop_cmd,
9ccf14f7 4535 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4536 NEIGHBOR_STR
4537 NEIGHBOR_ADDR_STR2
4538 "Allow EBGP neighbors not on directly connected networks\n")
4539{
d62a17ae 4540 int idx_peer = 1;
4541 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4542}
4543
4544DEFUN (neighbor_ebgp_multihop_ttl,
4545 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4546 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4547 NEIGHBOR_STR
4548 NEIGHBOR_ADDR_STR2
4549 "Allow EBGP neighbors not on directly connected networks\n"
4550 "maximum hop count\n")
4551{
d62a17ae 4552 int idx_peer = 1;
4553 int idx_number = 3;
4554 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4555 argv[idx_number]->arg);
718e3744 4556}
4557
4558DEFUN (no_neighbor_ebgp_multihop,
4559 no_neighbor_ebgp_multihop_cmd,
a636c635 4560 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4561 NO_STR
4562 NEIGHBOR_STR
4563 NEIGHBOR_ADDR_STR2
a636c635
DW
4564 "Allow EBGP neighbors not on directly connected networks\n"
4565 "maximum hop count\n")
718e3744 4566{
d62a17ae 4567 int idx_peer = 2;
4568 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4569}
4570
6b0655a2 4571
6ffd2079 4572/* disable-connected-check */
4573DEFUN (neighbor_disable_connected_check,
4574 neighbor_disable_connected_check_cmd,
7ebe625c 4575 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4576 NEIGHBOR_STR
7ebe625c 4577 NEIGHBOR_ADDR_STR2
a636c635
DW
4578 "one-hop away EBGP peer using loopback address\n"
4579 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4580{
d62a17ae 4581 int idx_peer = 1;
4582 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4583 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4584}
4585
4586DEFUN (no_neighbor_disable_connected_check,
4587 no_neighbor_disable_connected_check_cmd,
7ebe625c 4588 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4589 NO_STR
4590 NEIGHBOR_STR
7ebe625c 4591 NEIGHBOR_ADDR_STR2
a636c635
DW
4592 "one-hop away EBGP peer using loopback address\n"
4593 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4594{
d62a17ae 4595 int idx_peer = 2;
4596 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4597 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4598}
4599
47cbc09b
PM
4600
4601/* enforce-first-as */
4602DEFUN (neighbor_enforce_first_as,
4603 neighbor_enforce_first_as_cmd,
4604 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4605 NEIGHBOR_STR
4606 NEIGHBOR_ADDR_STR2
4607 "Enforce the first AS for EBGP routes\n")
4608{
4609 int idx_peer = 1;
4610
4611 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4612 PEER_FLAG_ENFORCE_FIRST_AS);
4613}
4614
4615DEFUN (no_neighbor_enforce_first_as,
4616 no_neighbor_enforce_first_as_cmd,
4617 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4618 NO_STR
4619 NEIGHBOR_STR
4620 NEIGHBOR_ADDR_STR2
4621 "Enforce the first AS for EBGP routes\n")
4622{
4623 int idx_peer = 2;
4624
4625 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4626 PEER_FLAG_ENFORCE_FIRST_AS);
4627}
4628
4629
718e3744 4630DEFUN (neighbor_description,
4631 neighbor_description_cmd,
e961923c 4632 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4633 NEIGHBOR_STR
4634 NEIGHBOR_ADDR_STR2
4635 "Neighbor specific description\n"
4636 "Up to 80 characters describing this neighbor\n")
4637{
d62a17ae 4638 int idx_peer = 1;
4639 int idx_line = 3;
4640 struct peer *peer;
4641 char *str;
718e3744 4642
d62a17ae 4643 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4644 if (!peer)
4645 return CMD_WARNING_CONFIG_FAILED;
718e3744 4646
d62a17ae 4647 str = argv_concat(argv, argc, idx_line);
718e3744 4648
d62a17ae 4649 peer_description_set(peer, str);
718e3744 4650
d62a17ae 4651 XFREE(MTYPE_TMP, str);
718e3744 4652
d62a17ae 4653 return CMD_SUCCESS;
718e3744 4654}
4655
4656DEFUN (no_neighbor_description,
4657 no_neighbor_description_cmd,
a636c635 4658 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
718e3744 4659 NO_STR
4660 NEIGHBOR_STR
4661 NEIGHBOR_ADDR_STR2
a636c635
DW
4662 "Neighbor specific description\n"
4663 "Up to 80 characters describing this neighbor\n")
718e3744 4664{
d62a17ae 4665 int idx_peer = 2;
4666 struct peer *peer;
718e3744 4667
d62a17ae 4668 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4669 if (!peer)
4670 return CMD_WARNING_CONFIG_FAILED;
718e3744 4671
d62a17ae 4672 peer_description_unset(peer);
718e3744 4673
d62a17ae 4674 return CMD_SUCCESS;
718e3744 4675}
4676
6b0655a2 4677
718e3744 4678/* Neighbor update-source. */
d62a17ae 4679static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4680 const char *source_str)
4681{
4682 struct peer *peer;
4683 struct prefix p;
4684
4685 peer = peer_and_group_lookup_vty(vty, peer_str);
4686 if (!peer)
4687 return CMD_WARNING_CONFIG_FAILED;
4688
4689 if (peer->conf_if)
4690 return CMD_WARNING;
4691
4692 if (source_str) {
4693 union sockunion su;
4694 int ret = str2sockunion(source_str, &su);
4695
4696 if (ret == 0)
4697 peer_update_source_addr_set(peer, &su);
4698 else {
4699 if (str2prefix(source_str, &p)) {
4700 vty_out(vty,
4701 "%% Invalid update-source, remove prefix length \n");
4702 return CMD_WARNING_CONFIG_FAILED;
4703 } else
4704 peer_update_source_if_set(peer, source_str);
4705 }
4706 } else
4707 peer_update_source_unset(peer);
4708
4709 return CMD_SUCCESS;
4710}
4711
4712#define BGP_UPDATE_SOURCE_HELP_STR \
4713 "IPv4 address\n" \
4714 "IPv6 address\n" \
4715 "Interface name (requires zebra to be running)\n"
369688c0 4716
718e3744 4717DEFUN (neighbor_update_source,
4718 neighbor_update_source_cmd,
9ccf14f7 4719 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4720 NEIGHBOR_STR
4721 NEIGHBOR_ADDR_STR2
4722 "Source of routing updates\n"
369688c0 4723 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4724{
d62a17ae 4725 int idx_peer = 1;
4726 int idx_peer_2 = 3;
4727 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4728 argv[idx_peer_2]->arg);
718e3744 4729}
4730
4731DEFUN (no_neighbor_update_source,
4732 no_neighbor_update_source_cmd,
c7178fe7 4733 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4734 NO_STR
4735 NEIGHBOR_STR
4736 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4737 "Source of routing updates\n"
4738 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4739{
d62a17ae 4740 int idx_peer = 2;
4741 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4742}
6b0655a2 4743
d62a17ae 4744static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4745 afi_t afi, safi_t safi,
4746 const char *rmap, int set)
718e3744 4747{
d62a17ae 4748 int ret;
4749 struct peer *peer;
718e3744 4750
d62a17ae 4751 peer = peer_and_group_lookup_vty(vty, peer_str);
4752 if (!peer)
4753 return CMD_WARNING_CONFIG_FAILED;
718e3744 4754
d62a17ae 4755 if (set)
4756 ret = peer_default_originate_set(peer, afi, safi, rmap);
4757 else
4758 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4759
d62a17ae 4760 return bgp_vty_return(vty, ret);
718e3744 4761}
4762
4763/* neighbor default-originate. */
4764DEFUN (neighbor_default_originate,
4765 neighbor_default_originate_cmd,
9ccf14f7 4766 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4767 NEIGHBOR_STR
4768 NEIGHBOR_ADDR_STR2
4769 "Originate default route to this neighbor\n")
4770{
d62a17ae 4771 int idx_peer = 1;
4772 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4773 bgp_node_afi(vty),
4774 bgp_node_safi(vty), NULL, 1);
718e3744 4775}
4776
d62a17ae 4777ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4778 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4779 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4780 "Originate default route to this neighbor\n")
596c17ba 4781
718e3744 4782DEFUN (neighbor_default_originate_rmap,
4783 neighbor_default_originate_rmap_cmd,
9ccf14f7 4784 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4785 NEIGHBOR_STR
4786 NEIGHBOR_ADDR_STR2
4787 "Originate default route to this neighbor\n"
4788 "Route-map to specify criteria to originate default\n"
4789 "route-map name\n")
4790{
d62a17ae 4791 int idx_peer = 1;
4792 int idx_word = 4;
4793 return peer_default_originate_set_vty(
4794 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4795 argv[idx_word]->arg, 1);
718e3744 4796}
4797
d62a17ae 4798ALIAS_HIDDEN(
4799 neighbor_default_originate_rmap,
4800 neighbor_default_originate_rmap_hidden_cmd,
4801 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4802 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4803 "Originate default route to this neighbor\n"
4804 "Route-map to specify criteria to originate default\n"
4805 "route-map name\n")
596c17ba 4806
718e3744 4807DEFUN (no_neighbor_default_originate,
4808 no_neighbor_default_originate_cmd,
a636c635 4809 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4810 NO_STR
4811 NEIGHBOR_STR
4812 NEIGHBOR_ADDR_STR2
a636c635
DW
4813 "Originate default route to this neighbor\n"
4814 "Route-map to specify criteria to originate default\n"
4815 "route-map name\n")
718e3744 4816{
d62a17ae 4817 int idx_peer = 2;
4818 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4819 bgp_node_afi(vty),
4820 bgp_node_safi(vty), NULL, 0);
718e3744 4821}
4822
d62a17ae 4823ALIAS_HIDDEN(
4824 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4825 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4826 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4827 "Originate default route to this neighbor\n"
4828 "Route-map to specify criteria to originate default\n"
4829 "route-map name\n")
596c17ba 4830
6b0655a2 4831
718e3744 4832/* Set neighbor's BGP port. */
d62a17ae 4833static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4834 const char *port_str)
4835{
4836 struct peer *peer;
d7c0a89a 4837 uint16_t port;
d62a17ae 4838 struct servent *sp;
4839
4840 peer = peer_lookup_vty(vty, ip_str);
4841 if (!peer)
4842 return CMD_WARNING_CONFIG_FAILED;
4843
4844 if (!port_str) {
4845 sp = getservbyname("bgp", "tcp");
4846 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4847 } else {
4848 port = strtoul(port_str, NULL, 10);
4849 }
718e3744 4850
d62a17ae 4851 peer_port_set(peer, port);
718e3744 4852
d62a17ae 4853 return CMD_SUCCESS;
718e3744 4854}
4855
f418446b 4856/* Set specified peer's BGP port. */
718e3744 4857DEFUN (neighbor_port,
4858 neighbor_port_cmd,
9ccf14f7 4859 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4860 NEIGHBOR_STR
4861 NEIGHBOR_ADDR_STR
4862 "Neighbor's BGP port\n"
4863 "TCP port number\n")
4864{
d62a17ae 4865 int idx_ip = 1;
4866 int idx_number = 3;
4867 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4868 argv[idx_number]->arg);
718e3744 4869}
4870
4871DEFUN (no_neighbor_port,
4872 no_neighbor_port_cmd,
9ccf14f7 4873 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4874 NO_STR
4875 NEIGHBOR_STR
4876 NEIGHBOR_ADDR_STR
8334fd5a
DW
4877 "Neighbor's BGP port\n"
4878 "TCP port number\n")
718e3744 4879{
d62a17ae 4880 int idx_ip = 2;
4881 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4882}
4883
6b0655a2 4884
718e3744 4885/* neighbor weight. */
d62a17ae 4886static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4887 safi_t safi, const char *weight_str)
718e3744 4888{
d62a17ae 4889 int ret;
4890 struct peer *peer;
4891 unsigned long weight;
718e3744 4892
d62a17ae 4893 peer = peer_and_group_lookup_vty(vty, ip_str);
4894 if (!peer)
4895 return CMD_WARNING_CONFIG_FAILED;
718e3744 4896
d62a17ae 4897 weight = strtoul(weight_str, NULL, 10);
718e3744 4898
d62a17ae 4899 ret = peer_weight_set(peer, afi, safi, weight);
4900 return bgp_vty_return(vty, ret);
718e3744 4901}
4902
d62a17ae 4903static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4904 safi_t safi)
718e3744 4905{
d62a17ae 4906 int ret;
4907 struct peer *peer;
718e3744 4908
d62a17ae 4909 peer = peer_and_group_lookup_vty(vty, ip_str);
4910 if (!peer)
4911 return CMD_WARNING_CONFIG_FAILED;
718e3744 4912
d62a17ae 4913 ret = peer_weight_unset(peer, afi, safi);
4914 return bgp_vty_return(vty, ret);
718e3744 4915}
4916
4917DEFUN (neighbor_weight,
4918 neighbor_weight_cmd,
9ccf14f7 4919 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4920 NEIGHBOR_STR
4921 NEIGHBOR_ADDR_STR2
4922 "Set default weight for routes from this neighbor\n"
4923 "default weight\n")
4924{
d62a17ae 4925 int idx_peer = 1;
4926 int idx_number = 3;
4927 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4928 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4929}
4930
d62a17ae 4931ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4932 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4933 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4934 "Set default weight for routes from this neighbor\n"
4935 "default weight\n")
596c17ba 4936
718e3744 4937DEFUN (no_neighbor_weight,
4938 no_neighbor_weight_cmd,
9ccf14f7 4939 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4940 NO_STR
4941 NEIGHBOR_STR
4942 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4943 "Set default weight for routes from this neighbor\n"
4944 "default weight\n")
718e3744 4945{
d62a17ae 4946 int idx_peer = 2;
4947 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4948 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4949}
4950
d62a17ae 4951ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4952 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4953 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4954 "Set default weight for routes from this neighbor\n"
4955 "default weight\n")
596c17ba 4956
6b0655a2 4957
718e3744 4958/* Override capability negotiation. */
4959DEFUN (neighbor_override_capability,
4960 neighbor_override_capability_cmd,
9ccf14f7 4961 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4962 NEIGHBOR_STR
4963 NEIGHBOR_ADDR_STR2
4964 "Override capability negotiation result\n")
4965{
d62a17ae 4966 int idx_peer = 1;
4967 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4968 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4969}
4970
4971DEFUN (no_neighbor_override_capability,
4972 no_neighbor_override_capability_cmd,
9ccf14f7 4973 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4974 NO_STR
4975 NEIGHBOR_STR
4976 NEIGHBOR_ADDR_STR2
4977 "Override capability negotiation result\n")
4978{
d62a17ae 4979 int idx_peer = 2;
4980 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4981 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4982}
6b0655a2 4983
718e3744 4984DEFUN (neighbor_strict_capability,
4985 neighbor_strict_capability_cmd,
9fb964de 4986 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 4987 NEIGHBOR_STR
9fb964de 4988 NEIGHBOR_ADDR_STR2
718e3744 4989 "Strict capability negotiation match\n")
4990{
9fb964de
PM
4991 int idx_peer = 1;
4992
4993 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 4994 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4995}
4996
4997DEFUN (no_neighbor_strict_capability,
4998 no_neighbor_strict_capability_cmd,
9fb964de 4999 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5000 NO_STR
5001 NEIGHBOR_STR
9fb964de 5002 NEIGHBOR_ADDR_STR2
718e3744 5003 "Strict capability negotiation match\n")
5004{
9fb964de
PM
5005 int idx_peer = 2;
5006
5007 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5008 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5009}
6b0655a2 5010
d62a17ae 5011static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5012 const char *keep_str, const char *hold_str)
718e3744 5013{
d62a17ae 5014 int ret;
5015 struct peer *peer;
d7c0a89a
QY
5016 uint32_t keepalive;
5017 uint32_t holdtime;
718e3744 5018
d62a17ae 5019 peer = peer_and_group_lookup_vty(vty, ip_str);
5020 if (!peer)
5021 return CMD_WARNING_CONFIG_FAILED;
718e3744 5022
d62a17ae 5023 keepalive = strtoul(keep_str, NULL, 10);
5024 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5025
d62a17ae 5026 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5027
d62a17ae 5028 return bgp_vty_return(vty, ret);
718e3744 5029}
6b0655a2 5030
d62a17ae 5031static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5032{
d62a17ae 5033 int ret;
5034 struct peer *peer;
718e3744 5035
d62a17ae 5036 peer = peer_and_group_lookup_vty(vty, ip_str);
5037 if (!peer)
5038 return CMD_WARNING_CONFIG_FAILED;
718e3744 5039
d62a17ae 5040 ret = peer_timers_unset(peer);
718e3744 5041
d62a17ae 5042 return bgp_vty_return(vty, ret);
718e3744 5043}
5044
5045DEFUN (neighbor_timers,
5046 neighbor_timers_cmd,
9ccf14f7 5047 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5048 NEIGHBOR_STR
5049 NEIGHBOR_ADDR_STR2
5050 "BGP per neighbor timers\n"
5051 "Keepalive interval\n"
5052 "Holdtime\n")
5053{
d62a17ae 5054 int idx_peer = 1;
5055 int idx_number = 3;
5056 int idx_number_2 = 4;
5057 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5058 argv[idx_number]->arg,
5059 argv[idx_number_2]->arg);
718e3744 5060}
5061
5062DEFUN (no_neighbor_timers,
5063 no_neighbor_timers_cmd,
9ccf14f7 5064 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5065 NO_STR
5066 NEIGHBOR_STR
5067 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5068 "BGP per neighbor timers\n"
5069 "Keepalive interval\n"
5070 "Holdtime\n")
718e3744 5071{
d62a17ae 5072 int idx_peer = 2;
5073 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5074}
6b0655a2 5075
813d4307 5076
d62a17ae 5077static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5078 const char *time_str)
718e3744 5079{
d62a17ae 5080 int ret;
5081 struct peer *peer;
d7c0a89a 5082 uint32_t connect;
718e3744 5083
d62a17ae 5084 peer = peer_and_group_lookup_vty(vty, ip_str);
5085 if (!peer)
5086 return CMD_WARNING_CONFIG_FAILED;
718e3744 5087
d62a17ae 5088 connect = strtoul(time_str, NULL, 10);
718e3744 5089
d62a17ae 5090 ret = peer_timers_connect_set(peer, connect);
718e3744 5091
d62a17ae 5092 return bgp_vty_return(vty, ret);
718e3744 5093}
5094
d62a17ae 5095static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5096{
d62a17ae 5097 int ret;
5098 struct peer *peer;
718e3744 5099
d62a17ae 5100 peer = peer_and_group_lookup_vty(vty, ip_str);
5101 if (!peer)
5102 return CMD_WARNING_CONFIG_FAILED;
718e3744 5103
d62a17ae 5104 ret = peer_timers_connect_unset(peer);
718e3744 5105
d62a17ae 5106 return bgp_vty_return(vty, ret);
718e3744 5107}
5108
5109DEFUN (neighbor_timers_connect,
5110 neighbor_timers_connect_cmd,
9ccf14f7 5111 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5112 NEIGHBOR_STR
966f821c 5113 NEIGHBOR_ADDR_STR2
718e3744 5114 "BGP per neighbor timers\n"
5115 "BGP connect timer\n"
5116 "Connect timer\n")
5117{
d62a17ae 5118 int idx_peer = 1;
5119 int idx_number = 4;
5120 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5121 argv[idx_number]->arg);
718e3744 5122}
5123
5124DEFUN (no_neighbor_timers_connect,
5125 no_neighbor_timers_connect_cmd,
9ccf14f7 5126 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5127 NO_STR
5128 NEIGHBOR_STR
966f821c 5129 NEIGHBOR_ADDR_STR2
718e3744 5130 "BGP per neighbor timers\n"
8334fd5a
DW
5131 "BGP connect timer\n"
5132 "Connect timer\n")
718e3744 5133{
d62a17ae 5134 int idx_peer = 2;
5135 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5136}
5137
6b0655a2 5138
d62a17ae 5139static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5140 const char *time_str, int set)
718e3744 5141{
d62a17ae 5142 int ret;
5143 struct peer *peer;
d7c0a89a 5144 uint32_t routeadv = 0;
718e3744 5145
d62a17ae 5146 peer = peer_and_group_lookup_vty(vty, ip_str);
5147 if (!peer)
5148 return CMD_WARNING_CONFIG_FAILED;
718e3744 5149
d62a17ae 5150 if (time_str)
5151 routeadv = strtoul(time_str, NULL, 10);
718e3744 5152
d62a17ae 5153 if (set)
5154 ret = peer_advertise_interval_set(peer, routeadv);
5155 else
5156 ret = peer_advertise_interval_unset(peer);
718e3744 5157
d62a17ae 5158 return bgp_vty_return(vty, ret);
718e3744 5159}
5160
5161DEFUN (neighbor_advertise_interval,
5162 neighbor_advertise_interval_cmd,
9ccf14f7 5163 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5164 NEIGHBOR_STR
966f821c 5165 NEIGHBOR_ADDR_STR2
718e3744 5166 "Minimum interval between sending BGP routing updates\n"
5167 "time in seconds\n")
5168{
d62a17ae 5169 int idx_peer = 1;
5170 int idx_number = 3;
5171 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5172 argv[idx_number]->arg, 1);
718e3744 5173}
5174
5175DEFUN (no_neighbor_advertise_interval,
5176 no_neighbor_advertise_interval_cmd,
9ccf14f7 5177 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5178 NO_STR
5179 NEIGHBOR_STR
966f821c 5180 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5181 "Minimum interval between sending BGP routing updates\n"
5182 "time in seconds\n")
718e3744 5183{
d62a17ae 5184 int idx_peer = 2;
5185 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5186}
5187
6b0655a2 5188
518f0eb1
DS
5189/* Time to wait before processing route-map updates */
5190DEFUN (bgp_set_route_map_delay_timer,
5191 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5192 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5193 SET_STR
5194 "BGP route-map delay timer\n"
5195 "Time in secs to wait before processing route-map changes\n"
f414725f 5196 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5197{
d62a17ae 5198 int idx_number = 3;
d7c0a89a 5199 uint32_t rmap_delay_timer;
d62a17ae 5200
5201 if (argv[idx_number]->arg) {
5202 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5203 bm->rmap_update_timer = rmap_delay_timer;
5204
5205 /* if the dynamic update handling is being disabled, and a timer
5206 * is
5207 * running, stop the timer and act as if the timer has already
5208 * fired.
5209 */
5210 if (!rmap_delay_timer && bm->t_rmap_update) {
5211 BGP_TIMER_OFF(bm->t_rmap_update);
5212 thread_execute(bm->master, bgp_route_map_update_timer,
5213 NULL, 0);
5214 }
5215 return CMD_SUCCESS;
5216 } else {
5217 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5218 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5219 }
518f0eb1
DS
5220}
5221
5222DEFUN (no_bgp_set_route_map_delay_timer,
5223 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5224 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5225 NO_STR
3a2d747c 5226 BGP_STR
518f0eb1 5227 "Default BGP route-map delay timer\n"
8334fd5a
DW
5228 "Reset to default time to wait for processing route-map changes\n"
5229 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5230{
518f0eb1 5231
d62a17ae 5232 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5233
d62a17ae 5234 return CMD_SUCCESS;
518f0eb1
DS
5235}
5236
f414725f 5237
718e3744 5238/* neighbor interface */
d62a17ae 5239static int peer_interface_vty(struct vty *vty, const char *ip_str,
5240 const char *str)
718e3744 5241{
d62a17ae 5242 struct peer *peer;
718e3744 5243
d62a17ae 5244 peer = peer_lookup_vty(vty, ip_str);
5245 if (!peer || peer->conf_if) {
5246 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5247 return CMD_WARNING_CONFIG_FAILED;
5248 }
718e3744 5249
d62a17ae 5250 if (str)
5251 peer_interface_set(peer, str);
5252 else
5253 peer_interface_unset(peer);
718e3744 5254
d62a17ae 5255 return CMD_SUCCESS;
718e3744 5256}
5257
5258DEFUN (neighbor_interface,
5259 neighbor_interface_cmd,
9ccf14f7 5260 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5261 NEIGHBOR_STR
5262 NEIGHBOR_ADDR_STR
5263 "Interface\n"
5264 "Interface name\n")
5265{
d62a17ae 5266 int idx_ip = 1;
5267 int idx_word = 3;
5268 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5269}
5270
5271DEFUN (no_neighbor_interface,
5272 no_neighbor_interface_cmd,
9ccf14f7 5273 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5274 NO_STR
5275 NEIGHBOR_STR
16cedbb0 5276 NEIGHBOR_ADDR_STR2
718e3744 5277 "Interface\n"
5278 "Interface name\n")
5279{
d62a17ae 5280 int idx_peer = 2;
5281 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5282}
6b0655a2 5283
718e3744 5284DEFUN (neighbor_distribute_list,
5285 neighbor_distribute_list_cmd,
9ccf14f7 5286 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 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 = 1;
5297 int idx_acl = 3;
5298 int direct, ret;
5299 struct peer *peer;
a8206004 5300
d62a17ae 5301 const char *pstr = argv[idx_peer]->arg;
5302 const char *acl = argv[idx_acl]->arg;
5303 const char *inout = argv[argc - 1]->text;
a8206004 5304
d62a17ae 5305 peer = peer_and_group_lookup_vty(vty, pstr);
5306 if (!peer)
5307 return CMD_WARNING_CONFIG_FAILED;
a8206004 5308
d62a17ae 5309 /* Check filter direction. */
5310 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5311 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5312 direct, acl);
a8206004 5313
d62a17ae 5314 return bgp_vty_return(vty, ret);
718e3744 5315}
5316
d62a17ae 5317ALIAS_HIDDEN(
5318 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5319 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5320 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5321 "Filter updates to/from this neighbor\n"
5322 "IP access-list number\n"
5323 "IP access-list number (expanded range)\n"
5324 "IP Access-list name\n"
5325 "Filter incoming updates\n"
5326 "Filter outgoing updates\n")
596c17ba 5327
718e3744 5328DEFUN (no_neighbor_distribute_list,
5329 no_neighbor_distribute_list_cmd,
9ccf14f7 5330 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5331 NO_STR
5332 NEIGHBOR_STR
5333 NEIGHBOR_ADDR_STR2
5334 "Filter updates to/from this neighbor\n"
5335 "IP access-list number\n"
5336 "IP access-list number (expanded range)\n"
5337 "IP Access-list name\n"
5338 "Filter incoming updates\n"
5339 "Filter outgoing updates\n")
5340{
d62a17ae 5341 int idx_peer = 2;
5342 int direct, ret;
5343 struct peer *peer;
a8206004 5344
d62a17ae 5345 const char *pstr = argv[idx_peer]->arg;
5346 const char *inout = argv[argc - 1]->text;
a8206004 5347
d62a17ae 5348 peer = peer_and_group_lookup_vty(vty, pstr);
5349 if (!peer)
5350 return CMD_WARNING_CONFIG_FAILED;
a8206004 5351
d62a17ae 5352 /* Check filter direction. */
5353 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5354 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5355 direct);
a8206004 5356
d62a17ae 5357 return bgp_vty_return(vty, ret);
718e3744 5358}
6b0655a2 5359
d62a17ae 5360ALIAS_HIDDEN(
5361 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5362 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5363 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5364 "Filter updates to/from this neighbor\n"
5365 "IP access-list number\n"
5366 "IP access-list number (expanded range)\n"
5367 "IP Access-list name\n"
5368 "Filter incoming updates\n"
5369 "Filter outgoing updates\n")
596c17ba 5370
718e3744 5371/* Set prefix list to the peer. */
d62a17ae 5372static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5373 afi_t afi, safi_t safi,
5374 const char *name_str,
5375 const char *direct_str)
718e3744 5376{
d62a17ae 5377 int ret;
d62a17ae 5378 int direct = FILTER_IN;
cf9ac8bf 5379 struct peer *peer;
718e3744 5380
d62a17ae 5381 peer = peer_and_group_lookup_vty(vty, ip_str);
5382 if (!peer)
5383 return CMD_WARNING_CONFIG_FAILED;
718e3744 5384
d62a17ae 5385 /* Check filter direction. */
5386 if (strncmp(direct_str, "i", 1) == 0)
5387 direct = FILTER_IN;
5388 else if (strncmp(direct_str, "o", 1) == 0)
5389 direct = FILTER_OUT;
718e3744 5390
d62a17ae 5391 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5392
d62a17ae 5393 return bgp_vty_return(vty, ret);
718e3744 5394}
5395
d62a17ae 5396static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5397 afi_t afi, safi_t safi,
5398 const char *direct_str)
718e3744 5399{
d62a17ae 5400 int ret;
5401 struct peer *peer;
5402 int direct = FILTER_IN;
718e3744 5403
d62a17ae 5404 peer = peer_and_group_lookup_vty(vty, ip_str);
5405 if (!peer)
5406 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5407
d62a17ae 5408 /* Check filter direction. */
5409 if (strncmp(direct_str, "i", 1) == 0)
5410 direct = FILTER_IN;
5411 else if (strncmp(direct_str, "o", 1) == 0)
5412 direct = FILTER_OUT;
718e3744 5413
d62a17ae 5414 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5415
d62a17ae 5416 return bgp_vty_return(vty, ret);
718e3744 5417}
5418
5419DEFUN (neighbor_prefix_list,
5420 neighbor_prefix_list_cmd,
9ccf14f7 5421 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5422 NEIGHBOR_STR
5423 NEIGHBOR_ADDR_STR2
5424 "Filter updates to/from this neighbor\n"
5425 "Name of a prefix list\n"
5426 "Filter incoming updates\n"
5427 "Filter outgoing updates\n")
5428{
d62a17ae 5429 int idx_peer = 1;
5430 int idx_word = 3;
5431 int idx_in_out = 4;
5432 return peer_prefix_list_set_vty(
5433 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5434 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5435}
5436
d62a17ae 5437ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5438 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5439 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5440 "Filter updates to/from this neighbor\n"
5441 "Name of a prefix list\n"
5442 "Filter incoming updates\n"
5443 "Filter outgoing updates\n")
596c17ba 5444
718e3744 5445DEFUN (no_neighbor_prefix_list,
5446 no_neighbor_prefix_list_cmd,
9ccf14f7 5447 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5448 NO_STR
5449 NEIGHBOR_STR
5450 NEIGHBOR_ADDR_STR2
5451 "Filter updates to/from this neighbor\n"
5452 "Name of a prefix list\n"
5453 "Filter incoming updates\n"
5454 "Filter outgoing updates\n")
5455{
d62a17ae 5456 int idx_peer = 2;
5457 int idx_in_out = 5;
5458 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5459 bgp_node_afi(vty), bgp_node_safi(vty),
5460 argv[idx_in_out]->arg);
718e3744 5461}
6b0655a2 5462
d62a17ae 5463ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5464 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5465 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5466 "Filter updates to/from this neighbor\n"
5467 "Name of a prefix list\n"
5468 "Filter incoming updates\n"
5469 "Filter outgoing updates\n")
596c17ba 5470
d62a17ae 5471static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5472 safi_t safi, const char *name_str,
5473 const char *direct_str)
718e3744 5474{
d62a17ae 5475 int ret;
5476 struct peer *peer;
5477 int direct = FILTER_IN;
718e3744 5478
d62a17ae 5479 peer = peer_and_group_lookup_vty(vty, ip_str);
5480 if (!peer)
5481 return CMD_WARNING_CONFIG_FAILED;
718e3744 5482
d62a17ae 5483 /* Check filter direction. */
5484 if (strncmp(direct_str, "i", 1) == 0)
5485 direct = FILTER_IN;
5486 else if (strncmp(direct_str, "o", 1) == 0)
5487 direct = FILTER_OUT;
718e3744 5488
d62a17ae 5489 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5490
d62a17ae 5491 return bgp_vty_return(vty, ret);
718e3744 5492}
5493
d62a17ae 5494static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5495 safi_t safi, const char *direct_str)
718e3744 5496{
d62a17ae 5497 int ret;
5498 struct peer *peer;
5499 int direct = FILTER_IN;
718e3744 5500
d62a17ae 5501 peer = peer_and_group_lookup_vty(vty, ip_str);
5502 if (!peer)
5503 return CMD_WARNING_CONFIG_FAILED;
718e3744 5504
d62a17ae 5505 /* Check filter direction. */
5506 if (strncmp(direct_str, "i", 1) == 0)
5507 direct = FILTER_IN;
5508 else if (strncmp(direct_str, "o", 1) == 0)
5509 direct = FILTER_OUT;
718e3744 5510
d62a17ae 5511 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5512
d62a17ae 5513 return bgp_vty_return(vty, ret);
718e3744 5514}
5515
5516DEFUN (neighbor_filter_list,
5517 neighbor_filter_list_cmd,
9ccf14f7 5518 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5519 NEIGHBOR_STR
5520 NEIGHBOR_ADDR_STR2
5521 "Establish BGP filters\n"
5522 "AS path access-list name\n"
5523 "Filter incoming routes\n"
5524 "Filter outgoing routes\n")
5525{
d62a17ae 5526 int idx_peer = 1;
5527 int idx_word = 3;
5528 int idx_in_out = 4;
5529 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5530 bgp_node_safi(vty), argv[idx_word]->arg,
5531 argv[idx_in_out]->arg);
718e3744 5532}
5533
d62a17ae 5534ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5535 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5536 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5537 "Establish BGP filters\n"
5538 "AS path access-list name\n"
5539 "Filter incoming routes\n"
5540 "Filter outgoing routes\n")
596c17ba 5541
718e3744 5542DEFUN (no_neighbor_filter_list,
5543 no_neighbor_filter_list_cmd,
9ccf14f7 5544 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5545 NO_STR
5546 NEIGHBOR_STR
5547 NEIGHBOR_ADDR_STR2
5548 "Establish BGP filters\n"
5549 "AS path access-list name\n"
5550 "Filter incoming routes\n"
5551 "Filter outgoing routes\n")
5552{
d62a17ae 5553 int idx_peer = 2;
5554 int idx_in_out = 5;
5555 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5556 bgp_node_afi(vty), bgp_node_safi(vty),
5557 argv[idx_in_out]->arg);
718e3744 5558}
6b0655a2 5559
d62a17ae 5560ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5561 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5562 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5563 "Establish BGP filters\n"
5564 "AS path access-list name\n"
5565 "Filter incoming routes\n"
5566 "Filter outgoing routes\n")
596c17ba 5567
718e3744 5568/* Set route-map to the peer. */
d62a17ae 5569static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5570 afi_t afi, safi_t safi, const char *name_str,
5571 const char *direct_str)
718e3744 5572{
d62a17ae 5573 int ret;
5574 struct peer *peer;
5575 int direct = RMAP_IN;
718e3744 5576
d62a17ae 5577 peer = peer_and_group_lookup_vty(vty, ip_str);
5578 if (!peer)
5579 return CMD_WARNING_CONFIG_FAILED;
718e3744 5580
d62a17ae 5581 /* Check filter direction. */
5582 if (strncmp(direct_str, "in", 2) == 0)
5583 direct = RMAP_IN;
5584 else if (strncmp(direct_str, "o", 1) == 0)
5585 direct = RMAP_OUT;
718e3744 5586
d62a17ae 5587 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5588
d62a17ae 5589 return bgp_vty_return(vty, ret);
718e3744 5590}
5591
d62a17ae 5592static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5593 afi_t afi, safi_t safi,
5594 const char *direct_str)
718e3744 5595{
d62a17ae 5596 int ret;
5597 struct peer *peer;
5598 int direct = RMAP_IN;
718e3744 5599
d62a17ae 5600 peer = peer_and_group_lookup_vty(vty, ip_str);
5601 if (!peer)
5602 return CMD_WARNING_CONFIG_FAILED;
718e3744 5603
d62a17ae 5604 /* Check filter direction. */
5605 if (strncmp(direct_str, "in", 2) == 0)
5606 direct = RMAP_IN;
5607 else if (strncmp(direct_str, "o", 1) == 0)
5608 direct = RMAP_OUT;
718e3744 5609
d62a17ae 5610 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5611
d62a17ae 5612 return bgp_vty_return(vty, ret);
718e3744 5613}
5614
5615DEFUN (neighbor_route_map,
5616 neighbor_route_map_cmd,
9ccf14f7 5617 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5618 NEIGHBOR_STR
5619 NEIGHBOR_ADDR_STR2
5620 "Apply route map to neighbor\n"
5621 "Name of route map\n"
5622 "Apply map to incoming routes\n"
2a3d5731 5623 "Apply map to outbound routes\n")
718e3744 5624{
d62a17ae 5625 int idx_peer = 1;
5626 int idx_word = 3;
5627 int idx_in_out = 4;
5628 return peer_route_map_set_vty(
5629 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5630 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5631}
5632
d62a17ae 5633ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5634 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5635 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5636 "Apply route map to neighbor\n"
5637 "Name of route map\n"
5638 "Apply map to incoming routes\n"
5639 "Apply map to outbound routes\n")
596c17ba 5640
718e3744 5641DEFUN (no_neighbor_route_map,
5642 no_neighbor_route_map_cmd,
9ccf14f7 5643 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5644 NO_STR
5645 NEIGHBOR_STR
5646 NEIGHBOR_ADDR_STR2
5647 "Apply route map to neighbor\n"
5648 "Name of route map\n"
5649 "Apply map to incoming routes\n"
2a3d5731 5650 "Apply map to outbound routes\n")
718e3744 5651{
d62a17ae 5652 int idx_peer = 2;
5653 int idx_in_out = 5;
5654 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5655 bgp_node_afi(vty), bgp_node_safi(vty),
5656 argv[idx_in_out]->arg);
718e3744 5657}
6b0655a2 5658
d62a17ae 5659ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5660 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5661 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5662 "Apply route map to neighbor\n"
5663 "Name of route map\n"
5664 "Apply map to incoming routes\n"
5665 "Apply map to outbound routes\n")
596c17ba 5666
718e3744 5667/* Set unsuppress-map to the peer. */
d62a17ae 5668static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5669 afi_t afi, safi_t safi,
5670 const char *name_str)
718e3744 5671{
d62a17ae 5672 int ret;
5673 struct peer *peer;
718e3744 5674
d62a17ae 5675 peer = peer_and_group_lookup_vty(vty, ip_str);
5676 if (!peer)
5677 return CMD_WARNING_CONFIG_FAILED;
718e3744 5678
d62a17ae 5679 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5680
d62a17ae 5681 return bgp_vty_return(vty, ret);
718e3744 5682}
5683
5684/* Unset route-map from the peer. */
d62a17ae 5685static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5686 afi_t afi, safi_t safi)
718e3744 5687{
d62a17ae 5688 int ret;
5689 struct peer *peer;
718e3744 5690
d62a17ae 5691 peer = peer_and_group_lookup_vty(vty, ip_str);
5692 if (!peer)
5693 return CMD_WARNING_CONFIG_FAILED;
718e3744 5694
d62a17ae 5695 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5696
d62a17ae 5697 return bgp_vty_return(vty, ret);
718e3744 5698}
5699
5700DEFUN (neighbor_unsuppress_map,
5701 neighbor_unsuppress_map_cmd,
9ccf14f7 5702 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5703 NEIGHBOR_STR
5704 NEIGHBOR_ADDR_STR2
5705 "Route-map to selectively unsuppress suppressed routes\n"
5706 "Name of route map\n")
5707{
d62a17ae 5708 int idx_peer = 1;
5709 int idx_word = 3;
5710 return peer_unsuppress_map_set_vty(
5711 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5712 argv[idx_word]->arg);
718e3744 5713}
5714
d62a17ae 5715ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5716 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5717 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5718 "Route-map to selectively unsuppress suppressed routes\n"
5719 "Name of route map\n")
596c17ba 5720
718e3744 5721DEFUN (no_neighbor_unsuppress_map,
5722 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5723 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5724 NO_STR
5725 NEIGHBOR_STR
5726 NEIGHBOR_ADDR_STR2
5727 "Route-map to selectively unsuppress suppressed routes\n"
5728 "Name of route map\n")
5729{
d62a17ae 5730 int idx_peer = 2;
5731 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5732 bgp_node_afi(vty),
5733 bgp_node_safi(vty));
718e3744 5734}
6b0655a2 5735
d62a17ae 5736ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5737 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5738 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5739 "Route-map to selectively unsuppress suppressed routes\n"
5740 "Name of route map\n")
596c17ba 5741
d62a17ae 5742static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5743 afi_t afi, safi_t safi,
5744 const char *num_str,
5745 const char *threshold_str, int warning,
5746 const char *restart_str)
718e3744 5747{
d62a17ae 5748 int ret;
5749 struct peer *peer;
d7c0a89a
QY
5750 uint32_t max;
5751 uint8_t threshold;
5752 uint16_t restart;
718e3744 5753
d62a17ae 5754 peer = peer_and_group_lookup_vty(vty, ip_str);
5755 if (!peer)
5756 return CMD_WARNING_CONFIG_FAILED;
718e3744 5757
d62a17ae 5758 max = strtoul(num_str, NULL, 10);
5759 if (threshold_str)
5760 threshold = atoi(threshold_str);
5761 else
5762 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5763
d62a17ae 5764 if (restart_str)
5765 restart = atoi(restart_str);
5766 else
5767 restart = 0;
0a486e5f 5768
d62a17ae 5769 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5770 restart);
718e3744 5771
d62a17ae 5772 return bgp_vty_return(vty, ret);
718e3744 5773}
5774
d62a17ae 5775static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5776 afi_t afi, safi_t safi)
718e3744 5777{
d62a17ae 5778 int ret;
5779 struct peer *peer;
718e3744 5780
d62a17ae 5781 peer = peer_and_group_lookup_vty(vty, ip_str);
5782 if (!peer)
5783 return CMD_WARNING_CONFIG_FAILED;
718e3744 5784
d62a17ae 5785 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5786
d62a17ae 5787 return bgp_vty_return(vty, ret);
718e3744 5788}
5789
5790/* Maximum number of prefix configuration. prefix count is different
5791 for each peer configuration. So this configuration can be set for
5792 each peer configuration. */
5793DEFUN (neighbor_maximum_prefix,
5794 neighbor_maximum_prefix_cmd,
9ccf14f7 5795 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5796 NEIGHBOR_STR
5797 NEIGHBOR_ADDR_STR2
5798 "Maximum number of prefix accept from this peer\n"
5799 "maximum no. of prefix limit\n")
5800{
d62a17ae 5801 int idx_peer = 1;
5802 int idx_number = 3;
5803 return peer_maximum_prefix_set_vty(
5804 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5805 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5806}
5807
d62a17ae 5808ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5809 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5810 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5811 "Maximum number of prefix accept from this peer\n"
5812 "maximum no. of prefix limit\n")
596c17ba 5813
e0701b79 5814DEFUN (neighbor_maximum_prefix_threshold,
5815 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5816 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5817 NEIGHBOR_STR
5818 NEIGHBOR_ADDR_STR2
5819 "Maximum number of prefix accept from this peer\n"
5820 "maximum no. of prefix limit\n"
5821 "Threshold value (%) at which to generate a warning msg\n")
5822{
d62a17ae 5823 int idx_peer = 1;
5824 int idx_number = 3;
5825 int idx_number_2 = 4;
5826 return peer_maximum_prefix_set_vty(
5827 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5828 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5829}
e0701b79 5830
d62a17ae 5831ALIAS_HIDDEN(
5832 neighbor_maximum_prefix_threshold,
5833 neighbor_maximum_prefix_threshold_hidden_cmd,
5834 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5835 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5836 "Maximum number of prefix accept from this peer\n"
5837 "maximum no. of prefix limit\n"
5838 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5839
718e3744 5840DEFUN (neighbor_maximum_prefix_warning,
5841 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5842 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5843 NEIGHBOR_STR
5844 NEIGHBOR_ADDR_STR2
5845 "Maximum number of prefix accept from this peer\n"
5846 "maximum no. of prefix limit\n"
5847 "Only give warning message when limit is exceeded\n")
5848{
d62a17ae 5849 int idx_peer = 1;
5850 int idx_number = 3;
5851 return peer_maximum_prefix_set_vty(
5852 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5853 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5854}
5855
d62a17ae 5856ALIAS_HIDDEN(
5857 neighbor_maximum_prefix_warning,
5858 neighbor_maximum_prefix_warning_hidden_cmd,
5859 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5860 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5861 "Maximum number of prefix accept from this peer\n"
5862 "maximum no. of prefix limit\n"
5863 "Only give warning message when limit is exceeded\n")
596c17ba 5864
e0701b79 5865DEFUN (neighbor_maximum_prefix_threshold_warning,
5866 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5867 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5868 NEIGHBOR_STR
5869 NEIGHBOR_ADDR_STR2
5870 "Maximum number of prefix accept from this peer\n"
5871 "maximum no. of prefix limit\n"
5872 "Threshold value (%) at which to generate a warning msg\n"
5873 "Only give warning message when limit is exceeded\n")
5874{
d62a17ae 5875 int idx_peer = 1;
5876 int idx_number = 3;
5877 int idx_number_2 = 4;
5878 return peer_maximum_prefix_set_vty(
5879 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5880 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5881}
5882
d62a17ae 5883ALIAS_HIDDEN(
5884 neighbor_maximum_prefix_threshold_warning,
5885 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5886 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5887 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5888 "Maximum number of prefix accept from this peer\n"
5889 "maximum no. of prefix limit\n"
5890 "Threshold value (%) at which to generate a warning msg\n"
5891 "Only give warning message when limit is exceeded\n")
596c17ba 5892
0a486e5f 5893DEFUN (neighbor_maximum_prefix_restart,
5894 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5895 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5896 NEIGHBOR_STR
5897 NEIGHBOR_ADDR_STR2
5898 "Maximum number of prefix accept from this peer\n"
5899 "maximum no. of prefix limit\n"
5900 "Restart bgp connection after limit is exceeded\n"
efd7904e 5901 "Restart interval in minutes\n")
0a486e5f 5902{
d62a17ae 5903 int idx_peer = 1;
5904 int idx_number = 3;
5905 int idx_number_2 = 5;
5906 return peer_maximum_prefix_set_vty(
5907 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5908 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5909}
5910
d62a17ae 5911ALIAS_HIDDEN(
5912 neighbor_maximum_prefix_restart,
5913 neighbor_maximum_prefix_restart_hidden_cmd,
5914 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5915 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5916 "Maximum number of prefix accept from this peer\n"
5917 "maximum no. of prefix limit\n"
5918 "Restart bgp connection after limit is exceeded\n"
efd7904e 5919 "Restart interval in minutes\n")
596c17ba 5920
0a486e5f 5921DEFUN (neighbor_maximum_prefix_threshold_restart,
5922 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5923 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5924 NEIGHBOR_STR
5925 NEIGHBOR_ADDR_STR2
16cedbb0 5926 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5927 "maximum no. of prefix limit\n"
5928 "Threshold value (%) at which to generate a warning msg\n"
5929 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5930 "Restart interval in minutes\n")
0a486e5f 5931{
d62a17ae 5932 int idx_peer = 1;
5933 int idx_number = 3;
5934 int idx_number_2 = 4;
5935 int idx_number_3 = 6;
5936 return peer_maximum_prefix_set_vty(
5937 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5938 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5939 argv[idx_number_3]->arg);
5940}
5941
5942ALIAS_HIDDEN(
5943 neighbor_maximum_prefix_threshold_restart,
5944 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5945 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5946 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5947 "Maximum number of prefixes to accept from this peer\n"
5948 "maximum no. of prefix limit\n"
5949 "Threshold value (%) at which to generate a warning msg\n"
5950 "Restart bgp connection after limit is exceeded\n"
5951 "Restart interval in minutes\n")
596c17ba 5952
718e3744 5953DEFUN (no_neighbor_maximum_prefix,
5954 no_neighbor_maximum_prefix_cmd,
d04c479d 5955 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5956 NO_STR
5957 NEIGHBOR_STR
5958 NEIGHBOR_ADDR_STR2
16cedbb0 5959 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5960 "maximum no. of prefix limit\n"
5961 "Threshold value (%) at which to generate a warning msg\n"
5962 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5963 "Restart interval in minutes\n"
31500417 5964 "Only give warning message when limit is exceeded\n")
718e3744 5965{
d62a17ae 5966 int idx_peer = 2;
5967 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5968 bgp_node_afi(vty),
5969 bgp_node_safi(vty));
718e3744 5970}
e52702f2 5971
d62a17ae 5972ALIAS_HIDDEN(
5973 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5974 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5975 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5976 "Maximum number of prefixes to accept from this peer\n"
5977 "maximum no. of prefix limit\n"
5978 "Threshold value (%) at which to generate a warning msg\n"
5979 "Restart bgp connection after limit is exceeded\n"
5980 "Restart interval in minutes\n"
5981 "Only give warning message when limit is exceeded\n")
596c17ba 5982
718e3744 5983
718e3744 5984/* "neighbor allowas-in" */
5985DEFUN (neighbor_allowas_in,
5986 neighbor_allowas_in_cmd,
fd8503f5 5987 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5988 NEIGHBOR_STR
5989 NEIGHBOR_ADDR_STR2
31500417 5990 "Accept as-path with my AS present in it\n"
fd8503f5
QY
5991 "Number of occurances of AS number\n"
5992 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5993{
d62a17ae 5994 int idx_peer = 1;
5995 int idx_number_origin = 3;
5996 int ret;
5997 int origin = 0;
5998 struct peer *peer;
5999 int allow_num = 0;
6000
6001 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6002 if (!peer)
6003 return CMD_WARNING_CONFIG_FAILED;
6004
6005 if (argc <= idx_number_origin)
6006 allow_num = 3;
6007 else {
6008 if (argv[idx_number_origin]->type == WORD_TKN)
6009 origin = 1;
6010 else
6011 allow_num = atoi(argv[idx_number_origin]->arg);
6012 }
6013
6014 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6015 allow_num, origin);
6016
6017 return bgp_vty_return(vty, ret);
6018}
6019
6020ALIAS_HIDDEN(
6021 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6022 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6023 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6024 "Accept as-path with my AS present in it\n"
6025 "Number of occurances of AS number\n"
6026 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6027
718e3744 6028DEFUN (no_neighbor_allowas_in,
6029 no_neighbor_allowas_in_cmd,
fd8503f5 6030 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6031 NO_STR
6032 NEIGHBOR_STR
6033 NEIGHBOR_ADDR_STR2
8334fd5a 6034 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
6035 "Number of occurances of AS number\n"
6036 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6037{
d62a17ae 6038 int idx_peer = 2;
6039 int ret;
6040 struct peer *peer;
718e3744 6041
d62a17ae 6042 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6043 if (!peer)
6044 return CMD_WARNING_CONFIG_FAILED;
718e3744 6045
d62a17ae 6046 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6047 bgp_node_safi(vty));
718e3744 6048
d62a17ae 6049 return bgp_vty_return(vty, ret);
718e3744 6050}
6b0655a2 6051
d62a17ae 6052ALIAS_HIDDEN(
6053 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6054 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6055 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6056 "allow local ASN appears in aspath attribute\n"
6057 "Number of occurances of AS number\n"
6058 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6059
fa411a21
NH
6060DEFUN (neighbor_ttl_security,
6061 neighbor_ttl_security_cmd,
7ebe625c 6062 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6063 NEIGHBOR_STR
7ebe625c 6064 NEIGHBOR_ADDR_STR2
16cedbb0 6065 "BGP ttl-security parameters\n"
d7fa34c1
QY
6066 "Specify the maximum number of hops to the BGP peer\n"
6067 "Number of hops to BGP peer\n")
fa411a21 6068{
d62a17ae 6069 int idx_peer = 1;
6070 int idx_number = 4;
6071 struct peer *peer;
6072 int gtsm_hops;
6073
6074 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6075 if (!peer)
6076 return CMD_WARNING_CONFIG_FAILED;
6077
6078 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6079
7ebe625c
QY
6080 /*
6081 * If 'neighbor swpX', then this is for directly connected peers,
6082 * we should not accept a ttl-security hops value greater than 1.
6083 */
6084 if (peer->conf_if && (gtsm_hops > 1)) {
6085 vty_out(vty,
6086 "%s is directly connected peer, hops cannot exceed 1\n",
6087 argv[idx_peer]->arg);
6088 return CMD_WARNING_CONFIG_FAILED;
6089 }
6090
d62a17ae 6091 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6092}
6093
6094DEFUN (no_neighbor_ttl_security,
6095 no_neighbor_ttl_security_cmd,
7ebe625c 6096 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6097 NO_STR
6098 NEIGHBOR_STR
7ebe625c 6099 NEIGHBOR_ADDR_STR2
16cedbb0 6100 "BGP ttl-security parameters\n"
3a2d747c
QY
6101 "Specify the maximum number of hops to the BGP peer\n"
6102 "Number of hops to BGP peer\n")
fa411a21 6103{
d62a17ae 6104 int idx_peer = 2;
6105 struct peer *peer;
fa411a21 6106
d62a17ae 6107 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6108 if (!peer)
6109 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6110
d62a17ae 6111 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6112}
6b0655a2 6113
adbac85e
DW
6114DEFUN (neighbor_addpath_tx_all_paths,
6115 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6116 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6117 NEIGHBOR_STR
6118 NEIGHBOR_ADDR_STR2
6119 "Use addpath to advertise all paths to a neighbor\n")
6120{
d62a17ae 6121 int idx_peer = 1;
6122 struct peer *peer;
adbac85e 6123
d62a17ae 6124 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6125 if (!peer)
6126 return CMD_WARNING_CONFIG_FAILED;
adbac85e 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_ALL_PATHS);
adbac85e
DW
6131}
6132
d62a17ae 6133ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6134 neighbor_addpath_tx_all_paths_hidden_cmd,
6135 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6136 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6137 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6138
adbac85e
DW
6139DEFUN (no_neighbor_addpath_tx_all_paths,
6140 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6141 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6142 NO_STR
6143 NEIGHBOR_STR
6144 NEIGHBOR_ADDR_STR2
6145 "Use addpath to advertise all paths to a neighbor\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_ALL_PATHS);
adbac85e
DW
6151}
6152
d62a17ae 6153ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6154 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6155 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6156 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6157 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6158
06370dac
DW
6159DEFUN (neighbor_addpath_tx_bestpath_per_as,
6160 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6161 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6162 NEIGHBOR_STR
6163 NEIGHBOR_ADDR_STR2
6164 "Use addpath to advertise the bestpath per each neighboring AS\n")
6165{
d62a17ae 6166 int idx_peer = 1;
6167 struct peer *peer;
06370dac 6168
d62a17ae 6169 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6170 if (!peer)
6171 return CMD_WARNING_CONFIG_FAILED;
06370dac 6172
d62a17ae 6173 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6174 bgp_node_safi(vty),
6175 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6176}
6177
d62a17ae 6178ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6179 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6180 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6181 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6182 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6183
06370dac
DW
6184DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6185 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6186 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6187 NO_STR
6188 NEIGHBOR_STR
6189 NEIGHBOR_ADDR_STR2
6190 "Use addpath to advertise the bestpath per each neighboring AS\n")
6191{
d62a17ae 6192 int idx_peer = 2;
6193 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6194 bgp_node_afi(vty), bgp_node_safi(vty),
6195 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6196}
6197
d62a17ae 6198ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6199 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6200 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6201 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6202 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6203
b9c7bc5a
PZ
6204static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6205 struct ecommunity **list)
ddb5b488 6206{
b9c7bc5a
PZ
6207 struct ecommunity *ecom = NULL;
6208 struct ecommunity *ecomadd;
ddb5b488 6209
b9c7bc5a 6210 for (; argc; --argc, ++argv) {
ddb5b488 6211
b9c7bc5a
PZ
6212 ecomadd = ecommunity_str2com(argv[0]->arg,
6213 ECOMMUNITY_ROUTE_TARGET, 0);
6214 if (!ecomadd) {
6215 vty_out(vty, "Malformed community-list value\n");
6216 if (ecom)
6217 ecommunity_free(&ecom);
6218 return CMD_WARNING_CONFIG_FAILED;
6219 }
ddb5b488 6220
b9c7bc5a
PZ
6221 if (ecom) {
6222 ecommunity_merge(ecom, ecomadd);
6223 ecommunity_free(&ecomadd);
6224 } else {
6225 ecom = ecomadd;
6226 }
6227 }
6228
6229 if (*list) {
6230 ecommunity_free(&*list);
ddb5b488 6231 }
b9c7bc5a
PZ
6232 *list = ecom;
6233
6234 return CMD_SUCCESS;
ddb5b488
PZ
6235}
6236
0ca70ba5
DS
6237/*
6238 * v2vimport is true if we are handling a `import vrf ...` command
6239 */
6240static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6241{
0ca70ba5
DS
6242 afi_t afi;
6243
ddb5b488 6244 switch (vty->node) {
b9c7bc5a 6245 case BGP_IPV4_NODE:
0ca70ba5
DS
6246 afi = AFI_IP;
6247 break;
b9c7bc5a 6248 case BGP_IPV6_NODE:
0ca70ba5
DS
6249 afi = AFI_IP6;
6250 break;
ddb5b488
PZ
6251 default:
6252 vty_out(vty,
b9c7bc5a 6253 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6254 return AFI_MAX;
ddb5b488 6255 }
69b07479 6256
0ca70ba5
DS
6257 if (!v2vimport) {
6258 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6259 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6260 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6261 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6262 vty_out(vty,
6263 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6264 return AFI_MAX;
6265 }
6266 } else {
6267 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6268 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6269 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6270 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6271 vty_out(vty,
6272 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6273 return AFI_MAX;
6274 }
6275 }
6276 return afi;
ddb5b488
PZ
6277}
6278
b9c7bc5a
PZ
6279DEFPY (af_rd_vpn_export,
6280 af_rd_vpn_export_cmd,
6281 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6282 NO_STR
ddb5b488 6283 "Specify route distinguisher\n"
b9c7bc5a
PZ
6284 "Between current address-family and vpn\n"
6285 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6286 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6287{
6288 VTY_DECLVAR_CONTEXT(bgp, bgp);
6289 struct prefix_rd prd;
6290 int ret;
ddb5b488 6291 afi_t afi;
b9c7bc5a
PZ
6292 int idx = 0;
6293 int yes = 1;
ddb5b488 6294
b9c7bc5a 6295 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6296 yes = 0;
b9c7bc5a
PZ
6297
6298 if (yes) {
6299 ret = str2prefix_rd(rd_str, &prd);
6300 if (!ret) {
6301 vty_out(vty, "%% Malformed rd\n");
6302 return CMD_WARNING_CONFIG_FAILED;
6303 }
ddb5b488
PZ
6304 }
6305
0ca70ba5 6306 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6307 if (afi == AFI_MAX)
6308 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6309
69b07479
DS
6310 /*
6311 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6312 */
6313 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6314 bgp_get_default(), bgp);
ddb5b488 6315
69b07479
DS
6316 if (yes) {
6317 bgp->vpn_policy[afi].tovpn_rd = prd;
6318 SET_FLAG(bgp->vpn_policy[afi].flags,
6319 BGP_VPN_POLICY_TOVPN_RD_SET);
6320 } else {
6321 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6322 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6323 }
6324
69b07479
DS
6325 /* post-change: re-export vpn routes */
6326 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6327 bgp_get_default(), bgp);
6328
ddb5b488
PZ
6329 return CMD_SUCCESS;
6330}
6331
b9c7bc5a
PZ
6332ALIAS (af_rd_vpn_export,
6333 af_no_rd_vpn_export_cmd,
6334 "no rd vpn export",
ddb5b488 6335 NO_STR
b9c7bc5a
PZ
6336 "Specify route distinguisher\n"
6337 "Between current address-family and vpn\n"
6338 "For routes leaked from current address-family to vpn\n")
ddb5b488 6339
b9c7bc5a
PZ
6340DEFPY (af_label_vpn_export,
6341 af_label_vpn_export_cmd,
e70e9f8e 6342 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6343 NO_STR
ddb5b488 6344 "label value for VRF\n"
b9c7bc5a
PZ
6345 "Between current address-family and vpn\n"
6346 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6347 "Label Value <0-1048575>\n"
6348 "Automatically assign a label\n")
ddb5b488
PZ
6349{
6350 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6351 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6352 afi_t afi;
b9c7bc5a
PZ
6353 int idx = 0;
6354 int yes = 1;
6355
6356 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6357 yes = 0;
ddb5b488 6358
21a16cc2
PZ
6359 /* If "no ...", squash trailing parameter */
6360 if (!yes)
6361 label_auto = NULL;
6362
e70e9f8e
PZ
6363 if (yes) {
6364 if (!label_auto)
6365 label = label_val; /* parser should force unsigned */
6366 }
ddb5b488 6367
0ca70ba5 6368 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6369 if (afi == AFI_MAX)
6370 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6371
e70e9f8e 6372
69b07479
DS
6373 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6374 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6375 /* no change */
6376 return CMD_SUCCESS;
e70e9f8e 6377
69b07479
DS
6378 /*
6379 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6380 */
6381 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6382 bgp_get_default(), bgp);
6383
6384 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6385 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6386
6387 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6388
6389 /*
6390 * label has previously been automatically
6391 * assigned by labelpool: release it
6392 *
6393 * NB if tovpn_label == MPLS_LABEL_NONE it
6394 * means the automatic assignment is in flight
6395 * and therefore the labelpool callback must
6396 * detect that the auto label is not needed.
6397 */
6398
6399 bgp_lp_release(LP_TYPE_VRF,
6400 &bgp->vpn_policy[afi],
6401 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6402 }
69b07479
DS
6403 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6404 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6405 }
ddb5b488 6406
69b07479
DS
6407 bgp->vpn_policy[afi].tovpn_label = label;
6408 if (label_auto) {
6409 SET_FLAG(bgp->vpn_policy[afi].flags,
6410 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6411 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6412 vpn_leak_label_callback);
ddb5b488
PZ
6413 }
6414
69b07479
DS
6415 /* post-change: re-export vpn routes */
6416 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6417 bgp_get_default(), bgp);
6418
ddb5b488
PZ
6419 return CMD_SUCCESS;
6420}
6421
b9c7bc5a
PZ
6422ALIAS (af_label_vpn_export,
6423 af_no_label_vpn_export_cmd,
6424 "no label vpn export",
6425 NO_STR
6426 "label value for VRF\n"
6427 "Between current address-family and vpn\n"
6428 "For routes leaked from current address-family to vpn\n")
ddb5b488 6429
b9c7bc5a
PZ
6430DEFPY (af_nexthop_vpn_export,
6431 af_nexthop_vpn_export_cmd,
6432 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6433 NO_STR
ddb5b488 6434 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6435 "Between current address-family and vpn\n"
6436 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6437 "IPv4 prefix\n"
6438 "IPv6 prefix\n")
6439{
6440 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6441 afi_t afi;
ddb5b488 6442 struct prefix p;
b9c7bc5a
PZ
6443 int idx = 0;
6444 int yes = 1;
ddb5b488 6445
b9c7bc5a 6446 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6447 yes = 0;
b9c7bc5a
PZ
6448
6449 if (yes) {
6450 if (!sockunion2hostprefix(nexthop_str, &p))
6451 return CMD_WARNING_CONFIG_FAILED;
6452 }
ddb5b488 6453
0ca70ba5 6454 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6455 if (afi == AFI_MAX)
6456 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6457
69b07479
DS
6458 /*
6459 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6460 */
6461 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6462 bgp_get_default(), bgp);
ddb5b488 6463
69b07479
DS
6464 if (yes) {
6465 bgp->vpn_policy[afi].tovpn_nexthop = p;
6466 SET_FLAG(bgp->vpn_policy[afi].flags,
6467 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6468 } else {
6469 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6470 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6471 }
6472
69b07479
DS
6473 /* post-change: re-export vpn routes */
6474 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6475 bgp_get_default(), bgp);
6476
ddb5b488
PZ
6477 return CMD_SUCCESS;
6478}
6479
b9c7bc5a
PZ
6480ALIAS (af_nexthop_vpn_export,
6481 af_no_nexthop_vpn_export_cmd,
6482 "no nexthop vpn export",
ddb5b488 6483 NO_STR
b9c7bc5a
PZ
6484 "Specify next hop to use for VRF advertised prefixes\n"
6485 "Between current address-family and vpn\n"
6486 "For routes leaked from current address-family to vpn\n")
ddb5b488 6487
b9c7bc5a 6488static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6489{
b9c7bc5a
PZ
6490 if (!strcmp(dstr, "import")) {
6491 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6492 } else if (!strcmp(dstr, "export")) {
6493 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6494 } else if (!strcmp(dstr, "both")) {
6495 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6496 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6497 } else {
6498 vty_out(vty, "%% direction parse error\n");
6499 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6500 }
ddb5b488
PZ
6501 return CMD_SUCCESS;
6502}
6503
b9c7bc5a
PZ
6504DEFPY (af_rt_vpn_imexport,
6505 af_rt_vpn_imexport_cmd,
6506 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6507 NO_STR
6508 "Specify route target list\n"
ddb5b488 6509 "Specify route target list\n"
b9c7bc5a
PZ
6510 "Between current address-family and vpn\n"
6511 "For routes leaked from vpn to current address-family: match any\n"
6512 "For routes leaked from current address-family to vpn: set\n"
6513 "both import: match any and export: set\n"
ddb5b488
PZ
6514 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6515{
6516 VTY_DECLVAR_CONTEXT(bgp, bgp);
6517 int ret;
6518 struct ecommunity *ecom = NULL;
6519 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6520 vpn_policy_direction_t dir;
6521 afi_t afi;
6522 int idx = 0;
b9c7bc5a 6523 int yes = 1;
ddb5b488 6524
b9c7bc5a 6525 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6526 yes = 0;
b9c7bc5a 6527
0ca70ba5 6528 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6529 if (afi == AFI_MAX)
6530 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6531
b9c7bc5a 6532 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6533 if (ret != CMD_SUCCESS)
6534 return ret;
6535
b9c7bc5a
PZ
6536 if (yes) {
6537 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6538 vty_out(vty, "%% Missing RTLIST\n");
6539 return CMD_WARNING_CONFIG_FAILED;
6540 }
6541 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6542 if (ret != CMD_SUCCESS) {
6543 return ret;
6544 }
ddb5b488
PZ
6545 }
6546
69b07479
DS
6547 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6548 if (!dodir[dir])
ddb5b488 6549 continue;
ddb5b488 6550
69b07479 6551 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6552
69b07479
DS
6553 if (yes) {
6554 if (bgp->vpn_policy[afi].rtlist[dir])
6555 ecommunity_free(
6556 &bgp->vpn_policy[afi].rtlist[dir]);
6557 bgp->vpn_policy[afi].rtlist[dir] =
6558 ecommunity_dup(ecom);
6559 } else {
6560 if (bgp->vpn_policy[afi].rtlist[dir])
6561 ecommunity_free(
6562 &bgp->vpn_policy[afi].rtlist[dir]);
6563 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6564 }
69b07479
DS
6565
6566 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6567 }
69b07479 6568
d555f3e9
PZ
6569 if (ecom)
6570 ecommunity_free(&ecom);
ddb5b488
PZ
6571
6572 return CMD_SUCCESS;
6573}
6574
b9c7bc5a
PZ
6575ALIAS (af_rt_vpn_imexport,
6576 af_no_rt_vpn_imexport_cmd,
6577 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6578 NO_STR
6579 "Specify route target list\n"
b9c7bc5a
PZ
6580 "Specify route target list\n"
6581 "Between current address-family and vpn\n"
6582 "For routes leaked from vpn to current address-family\n"
6583 "For routes leaked from current address-family to vpn\n"
6584 "both import and export\n")
6585
6586DEFPY (af_route_map_vpn_imexport,
6587 af_route_map_vpn_imexport_cmd,
6588/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6589 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6590 NO_STR
ddb5b488 6591 "Specify route map\n"
b9c7bc5a
PZ
6592 "Between current address-family and vpn\n"
6593 "For routes leaked from vpn to current address-family\n"
6594 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6595 "name of route-map\n")
6596{
6597 VTY_DECLVAR_CONTEXT(bgp, bgp);
6598 int ret;
6599 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6600 vpn_policy_direction_t dir;
6601 afi_t afi;
ddb5b488 6602 int idx = 0;
b9c7bc5a 6603 int yes = 1;
ddb5b488 6604
b9c7bc5a 6605 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6606 yes = 0;
b9c7bc5a 6607
0ca70ba5 6608 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6609 if (afi == AFI_MAX)
6610 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6611
b9c7bc5a 6612 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6613 if (ret != CMD_SUCCESS)
6614 return ret;
6615
69b07479
DS
6616 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6617 if (!dodir[dir])
ddb5b488 6618 continue;
ddb5b488 6619
69b07479 6620 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6621
69b07479
DS
6622 if (yes) {
6623 if (bgp->vpn_policy[afi].rmap_name[dir])
6624 XFREE(MTYPE_ROUTE_MAP_NAME,
6625 bgp->vpn_policy[afi].rmap_name[dir]);
6626 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6627 MTYPE_ROUTE_MAP_NAME, rmap_str);
6628 bgp->vpn_policy[afi].rmap[dir] =
6629 route_map_lookup_by_name(rmap_str);
6630 if (!bgp->vpn_policy[afi].rmap[dir])
6631 return CMD_SUCCESS;
6632 } else {
6633 if (bgp->vpn_policy[afi].rmap_name[dir])
6634 XFREE(MTYPE_ROUTE_MAP_NAME,
6635 bgp->vpn_policy[afi].rmap_name[dir]);
6636 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6637 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6638 }
69b07479
DS
6639
6640 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6641 }
6642
6643 return CMD_SUCCESS;
6644}
6645
b9c7bc5a
PZ
6646ALIAS (af_route_map_vpn_imexport,
6647 af_no_route_map_vpn_imexport_cmd,
6648 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6649 NO_STR
6650 "Specify route map\n"
b9c7bc5a
PZ
6651 "Between current address-family and vpn\n"
6652 "For routes leaked from vpn to current address-family\n"
6653 "For routes leaked from current address-family to vpn\n")
6654
bb4f6190
DS
6655DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6656 "[no] import vrf route-map RMAP$rmap_str",
6657 NO_STR
6658 "Import routes from another VRF\n"
6659 "Vrf routes being filtered\n"
6660 "Specify route map\n"
6661 "name of route-map\n")
6662{
6663 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6664 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6665 afi_t afi;
6666 int idx = 0;
6667 int yes = 1;
6668 struct bgp *bgp_default;
6669
6670 if (argv_find(argv, argc, "no", &idx))
6671 yes = 0;
6672
0ca70ba5 6673 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6674 if (afi == AFI_MAX)
6675 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6676
6677 bgp_default = bgp_get_default();
6678 if (!bgp_default) {
6679 int32_t ret;
6680 as_t as = bgp->as;
6681
6682 /* Auto-create assuming the same AS */
6683 ret = bgp_get(&bgp_default, &as, NULL,
6684 BGP_INSTANCE_TYPE_DEFAULT);
6685
6686 if (ret) {
6687 vty_out(vty,
6688 "VRF default is not configured as a bgp instance\n");
6689 return CMD_WARNING;
6690 }
6691 }
6692
69b07479 6693 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6694
69b07479
DS
6695 if (yes) {
6696 if (bgp->vpn_policy[afi].rmap_name[dir])
6697 XFREE(MTYPE_ROUTE_MAP_NAME,
6698 bgp->vpn_policy[afi].rmap_name[dir]);
6699 bgp->vpn_policy[afi].rmap_name[dir] =
6700 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6701 bgp->vpn_policy[afi].rmap[dir] =
6702 route_map_lookup_by_name(rmap_str);
6703 if (!bgp->vpn_policy[afi].rmap[dir])
6704 return CMD_SUCCESS;
6705 } else {
6706 if (bgp->vpn_policy[afi].rmap_name[dir])
6707 XFREE(MTYPE_ROUTE_MAP_NAME,
6708 bgp->vpn_policy[afi].rmap_name[dir]);
6709 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6710 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6711 }
6712
69b07479
DS
6713 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6714
bb4f6190
DS
6715 return CMD_SUCCESS;
6716}
6717
6718ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6719 "no import vrf route-map",
6720 NO_STR
6721 "Import routes from another VRF\n"
6722 "Vrf routes being filtered\n"
6723 "Specify route map\n")
6724
12a844a5
DS
6725DEFPY (bgp_imexport_vrf,
6726 bgp_imexport_vrf_cmd,
6727 "[no] import vrf NAME$import_name",
6728 NO_STR
6729 "Import routes from another VRF\n"
6730 "VRF to import from\n"
6731 "The name of the VRF\n")
6732{
6733 VTY_DECLVAR_CONTEXT(bgp, bgp);
6734 struct listnode *node;
79ef8664
DS
6735 struct bgp *vrf_bgp, *bgp_default;
6736 int32_t ret = 0;
6737 as_t as = bgp->as;
12a844a5
DS
6738 bool remove = false;
6739 int32_t idx = 0;
6740 char *vname;
a8dadcf6 6741 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6742 safi_t safi;
6743 afi_t afi;
6744
6745 if (argv_find(argv, argc, "no", &idx))
6746 remove = true;
6747
0ca70ba5
DS
6748 afi = vpn_policy_getafi(vty, bgp, true);
6749 if (afi == AFI_MAX)
6750 return CMD_WARNING_CONFIG_FAILED;
6751
12a844a5
DS
6752 safi = bgp_node_safi(vty);
6753
25679caa
DS
6754 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6755 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6756 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6757 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6758 remove ? "unimport" : "import", import_name);
6759 return CMD_WARNING;
6760 }
6761
79ef8664
DS
6762 bgp_default = bgp_get_default();
6763 if (!bgp_default) {
6764 /* Auto-create assuming the same AS */
6765 ret = bgp_get(&bgp_default, &as, NULL,
6766 BGP_INSTANCE_TYPE_DEFAULT);
6767
6768 if (ret) {
6769 vty_out(vty,
6770 "VRF default is not configured as a bgp instance\n");
6771 return CMD_WARNING;
6772 }
6773 }
6774
12a844a5
DS
6775 vrf_bgp = bgp_lookup_by_name(import_name);
6776 if (!vrf_bgp) {
79ef8664
DS
6777 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6778 vrf_bgp = bgp_default;
6779 else
0fb8d6e6
DS
6780 /* Auto-create assuming the same AS */
6781 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6782
6e2c7fe6 6783 if (ret) {
020a3f60
DS
6784 vty_out(vty,
6785 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6786 import_name);
6787 return CMD_WARNING;
6788 }
12a844a5
DS
6789 }
6790
12a844a5 6791 if (remove) {
44338987 6792 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6793 } else {
44338987 6794 /* Already importing from "import_vrf"? */
12a844a5
DS
6795 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6796 vname)) {
6797 if (strcmp(vname, import_name) == 0)
6798 return CMD_WARNING;
6799 }
6800
44338987 6801 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6802 }
6803
6804 return CMD_SUCCESS;
6805}
6806
b9c7bc5a
PZ
6807/* This command is valid only in a bgp vrf instance or the default instance */
6808DEFPY (bgp_imexport_vpn,
6809 bgp_imexport_vpn_cmd,
6810 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6811 NO_STR
6812 "Import routes to this address-family\n"
6813 "Export routes from this address-family\n"
6814 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6815{
6816 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6817 int previous_state;
ddb5b488 6818 afi_t afi;
b9c7bc5a 6819 safi_t safi;
ddb5b488 6820 int idx = 0;
b9c7bc5a
PZ
6821 int yes = 1;
6822 int flag;
6823 vpn_policy_direction_t dir;
ddb5b488 6824
b9c7bc5a 6825 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6826 yes = 0;
ddb5b488 6827
b9c7bc5a
PZ
6828 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6829 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6830
b9c7bc5a
PZ
6831 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6832 return CMD_WARNING_CONFIG_FAILED;
6833 }
ddb5b488 6834
b9c7bc5a
PZ
6835 afi = bgp_node_afi(vty);
6836 safi = bgp_node_safi(vty);
6837 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6838 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6839 return CMD_WARNING_CONFIG_FAILED;
6840 }
ddb5b488 6841
b9c7bc5a
PZ
6842 if (!strcmp(direction_str, "import")) {
6843 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6844 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6845 } else if (!strcmp(direction_str, "export")) {
6846 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6847 dir = BGP_VPN_POLICY_DIR_TOVPN;
6848 } else {
6849 vty_out(vty, "%% unknown direction %s\n", direction_str);
6850 return CMD_WARNING_CONFIG_FAILED;
6851 }
6852
6853 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 6854
b9c7bc5a
PZ
6855 if (yes) {
6856 SET_FLAG(bgp->af_flags[afi][safi], flag);
6857 if (!previous_state) {
6858 /* trigger export current vrf */
ddb5b488
PZ
6859 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6860 }
b9c7bc5a
PZ
6861 } else {
6862 if (previous_state) {
6863 /* trigger un-export current vrf */
6864 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6865 }
6866 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
6867 }
6868
6869 return CMD_SUCCESS;
6870}
6871
301ad80a
PG
6872DEFPY (af_routetarget_import,
6873 af_routetarget_import_cmd,
6874 "[no] <rt|route-target> redirect import RTLIST...",
6875 NO_STR
6876 "Specify route target list\n"
6877 "Specify route target list\n"
6878 "Flow-spec redirect type route target\n"
6879 "Import routes to this address-family\n"
6880 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6881{
6882 VTY_DECLVAR_CONTEXT(bgp, bgp);
6883 int ret;
6884 struct ecommunity *ecom = NULL;
301ad80a
PG
6885 afi_t afi;
6886 int idx = 0;
6887 int yes = 1;
6888
6889 if (argv_find(argv, argc, "no", &idx))
6890 yes = 0;
6891
0ca70ba5 6892 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6893 if (afi == AFI_MAX)
6894 return CMD_WARNING_CONFIG_FAILED;
6895
301ad80a
PG
6896 if (yes) {
6897 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6898 vty_out(vty, "%% Missing RTLIST\n");
6899 return CMD_WARNING_CONFIG_FAILED;
6900 }
6901 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6902 if (ret != CMD_SUCCESS)
6903 return ret;
6904 }
69b07479
DS
6905
6906 if (yes) {
6907 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6908 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6909 .import_redirect_rtlist);
69b07479
DS
6910 bgp->vpn_policy[afi].import_redirect_rtlist =
6911 ecommunity_dup(ecom);
6912 } else {
6913 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6914 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6915 .import_redirect_rtlist);
69b07479 6916 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 6917 }
69b07479 6918
301ad80a
PG
6919 if (ecom)
6920 ecommunity_free(&ecom);
6921
6922 return CMD_SUCCESS;
6923}
6924
505e5056 6925DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 6926 address_family_ipv4_safi_cmd,
6927 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6928 "Enter Address Family command mode\n"
6929 "Address Family\n"
6930 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6931{
f51bae9c 6932
d62a17ae 6933 if (argc == 3) {
2131d5cf 6934 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6935 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6936 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6937 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6938 && safi != SAFI_EVPN) {
31947174
MK
6939 vty_out(vty,
6940 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6941 return CMD_WARNING_CONFIG_FAILED;
6942 }
d62a17ae 6943 vty->node = bgp_node_type(AFI_IP, safi);
6944 } else
6945 vty->node = BGP_IPV4_NODE;
718e3744 6946
d62a17ae 6947 return CMD_SUCCESS;
718e3744 6948}
6949
505e5056 6950DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 6951 address_family_ipv6_safi_cmd,
6952 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6953 "Enter Address Family command mode\n"
6954 "Address Family\n"
6955 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6956{
d62a17ae 6957 if (argc == 3) {
2131d5cf 6958 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6959 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6960 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6961 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6962 && safi != SAFI_EVPN) {
31947174
MK
6963 vty_out(vty,
6964 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6965 return CMD_WARNING_CONFIG_FAILED;
6966 }
d62a17ae 6967 vty->node = bgp_node_type(AFI_IP6, safi);
6968 } else
6969 vty->node = BGP_IPV6_NODE;
25ffbdc1 6970
d62a17ae 6971 return CMD_SUCCESS;
25ffbdc1 6972}
718e3744 6973
d6902373 6974#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6975DEFUN_NOSH (address_family_vpnv4,
718e3744 6976 address_family_vpnv4_cmd,
8334fd5a 6977 "address-family vpnv4 [unicast]",
718e3744 6978 "Enter Address Family command mode\n"
8c3deaae 6979 "Address Family\n"
3a2d747c 6980 "Address Family modifier\n")
718e3744 6981{
d62a17ae 6982 vty->node = BGP_VPNV4_NODE;
6983 return CMD_SUCCESS;
718e3744 6984}
6985
505e5056 6986DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6987 address_family_vpnv6_cmd,
8334fd5a 6988 "address-family vpnv6 [unicast]",
8ecd3266 6989 "Enter Address Family command mode\n"
8c3deaae 6990 "Address Family\n"
3a2d747c 6991 "Address Family modifier\n")
8ecd3266 6992{
d62a17ae 6993 vty->node = BGP_VPNV6_NODE;
6994 return CMD_SUCCESS;
8ecd3266 6995}
c016b6c7 6996#endif
d6902373 6997
505e5056 6998DEFUN_NOSH (address_family_evpn,
4e0b7b6d 6999 address_family_evpn_cmd,
7111c1a0 7000 "address-family l2vpn evpn",
4e0b7b6d 7001 "Enter Address Family command mode\n"
7111c1a0
QY
7002 "Address Family\n"
7003 "Address Family modifier\n")
4e0b7b6d 7004{
2131d5cf 7005 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7006 vty->node = BGP_EVPN_NODE;
7007 return CMD_SUCCESS;
4e0b7b6d
PG
7008}
7009
505e5056 7010DEFUN_NOSH (exit_address_family,
718e3744 7011 exit_address_family_cmd,
7012 "exit-address-family",
7013 "Exit from Address Family configuration mode\n")
7014{
d62a17ae 7015 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7016 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7017 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7018 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7019 || vty->node == BGP_EVPN_NODE
7020 || vty->node == BGP_FLOWSPECV4_NODE
7021 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7022 vty->node = BGP_NODE;
7023 return CMD_SUCCESS;
718e3744 7024}
6b0655a2 7025
8ad7271d 7026/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7027static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7028 const char *ip_str, afi_t afi, safi_t safi,
7029 struct prefix_rd *prd)
7030{
7031 int ret;
7032 struct prefix match;
7033 struct bgp_node *rn;
7034 struct bgp_node *rm;
7035 struct bgp *bgp;
7036 struct bgp_table *table;
7037 struct bgp_table *rib;
7038
7039 /* BGP structure lookup. */
7040 if (view_name) {
7041 bgp = bgp_lookup_by_name(view_name);
7042 if (bgp == NULL) {
7043 vty_out(vty, "%% Can't find BGP instance %s\n",
7044 view_name);
7045 return CMD_WARNING;
7046 }
7047 } else {
7048 bgp = bgp_get_default();
7049 if (bgp == NULL) {
7050 vty_out(vty, "%% No BGP process is configured\n");
7051 return CMD_WARNING;
7052 }
7053 }
7054
7055 /* Check IP address argument. */
7056 ret = str2prefix(ip_str, &match);
7057 if (!ret) {
7058 vty_out(vty, "%% address is malformed\n");
7059 return CMD_WARNING;
7060 }
7061
7062 match.family = afi2family(afi);
7063 rib = bgp->rib[afi][safi];
7064
7065 if (safi == SAFI_MPLS_VPN) {
7066 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7067 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7068 continue;
7069
7070 if ((table = rn->info) != NULL) {
7071 if ((rm = bgp_node_match(table, &match))
7072 != NULL) {
7073 if (rm->p.prefixlen
7074 == match.prefixlen) {
7075 SET_FLAG(rn->flags,
7076 BGP_NODE_USER_CLEAR);
7077 bgp_process(bgp, rm, afi, safi);
7078 }
7079 bgp_unlock_node(rm);
7080 }
7081 }
7082 }
7083 } else {
7084 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7085 if (rn->p.prefixlen == match.prefixlen) {
7086 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7087 bgp_process(bgp, rn, afi, safi);
7088 }
7089 bgp_unlock_node(rn);
7090 }
7091 }
7092
7093 return CMD_SUCCESS;
8ad7271d
DS
7094}
7095
b09b5ae0 7096/* one clear bgp command to rule them all */
718e3744 7097DEFUN (clear_ip_bgp_all,
7098 clear_ip_bgp_all_cmd,
c1a44e43 7099 "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 7100 CLEAR_STR
7101 IP_STR
7102 BGP_STR
838758ac 7103 BGP_INSTANCE_HELP_STR
510afcd6
DS
7104 BGP_AFI_HELP_STR
7105 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
7106 "Clear all peers\n"
7107 "BGP neighbor address to clear\n"
a80beece 7108 "BGP IPv6 neighbor to clear\n"
838758ac 7109 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7110 "Clear peers with the AS number\n"
7111 "Clear all external peers\n"
718e3744 7112 "Clear all members of peer-group\n"
b09b5ae0 7113 "BGP peer-group name\n"
b09b5ae0
DW
7114 BGP_SOFT_STR
7115 BGP_SOFT_IN_STR
b09b5ae0
DW
7116 BGP_SOFT_OUT_STR
7117 BGP_SOFT_IN_STR
7118 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7119 BGP_SOFT_OUT_STR)
718e3744 7120{
d62a17ae 7121 char *vrf = NULL;
7122
7123 afi_t afi = AFI_IP6;
7124 safi_t safi = SAFI_UNICAST;
7125 enum clear_sort clr_sort = clear_peer;
7126 enum bgp_clear_type clr_type;
7127 char *clr_arg = NULL;
7128
7129 int idx = 0;
7130
7131 /* clear [ip] bgp */
7132 if (argv_find(argv, argc, "ip", &idx))
7133 afi = AFI_IP;
7134
7135 /* [<view|vrf> VIEWVRFNAME] */
7136 if (argv_find(argv, argc, "view", &idx)
7137 || argv_find(argv, argc, "vrf", &idx)) {
7138 vrf = argv[idx + 1]->arg;
7139 idx += 2;
7140 }
7141
7142 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7143 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7144 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7145
7146 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7147 if (argv_find(argv, argc, "*", &idx)) {
7148 clr_sort = clear_all;
7149 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7150 clr_sort = clear_peer;
7151 clr_arg = argv[idx]->arg;
7152 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7153 clr_sort = clear_peer;
7154 clr_arg = argv[idx]->arg;
7155 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7156 clr_sort = clear_group;
7157 idx++;
7158 clr_arg = argv[idx]->arg;
7159 } else if (argv_find(argv, argc, "WORD", &idx)) {
7160 clr_sort = clear_peer;
7161 clr_arg = argv[idx]->arg;
7162 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7163 clr_sort = clear_as;
7164 clr_arg = argv[idx]->arg;
7165 } else if (argv_find(argv, argc, "external", &idx)) {
7166 clr_sort = clear_external;
7167 }
7168
7169 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7170 if (argv_find(argv, argc, "soft", &idx)) {
7171 if (argv_find(argv, argc, "in", &idx)
7172 || argv_find(argv, argc, "out", &idx))
7173 clr_type = strmatch(argv[idx]->text, "in")
7174 ? BGP_CLEAR_SOFT_IN
7175 : BGP_CLEAR_SOFT_OUT;
7176 else
7177 clr_type = BGP_CLEAR_SOFT_BOTH;
7178 } else if (argv_find(argv, argc, "in", &idx)) {
7179 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7180 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7181 : BGP_CLEAR_SOFT_IN;
7182 } else if (argv_find(argv, argc, "out", &idx)) {
7183 clr_type = BGP_CLEAR_SOFT_OUT;
7184 } else
7185 clr_type = BGP_CLEAR_SOFT_NONE;
7186
7187 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7188}
01080f7c 7189
8ad7271d
DS
7190DEFUN (clear_ip_bgp_prefix,
7191 clear_ip_bgp_prefix_cmd,
18c57037 7192 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7193 CLEAR_STR
7194 IP_STR
7195 BGP_STR
838758ac 7196 BGP_INSTANCE_HELP_STR
8ad7271d 7197 "Clear bestpath and re-advertise\n"
0c7b1b01 7198 "IPv4 prefix\n")
8ad7271d 7199{
d62a17ae 7200 char *vrf = NULL;
7201 char *prefix = NULL;
8ad7271d 7202
d62a17ae 7203 int idx = 0;
01080f7c 7204
d62a17ae 7205 /* [<view|vrf> VIEWVRFNAME] */
1d35f218 7206 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
d62a17ae 7207 vrf = argv[idx]->arg;
0c7b1b01 7208
d62a17ae 7209 prefix = argv[argc - 1]->arg;
8ad7271d 7210
d62a17ae 7211 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7212}
8ad7271d 7213
b09b5ae0
DW
7214DEFUN (clear_bgp_ipv6_safi_prefix,
7215 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7216 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7217 CLEAR_STR
3a2d747c 7218 IP_STR
718e3744 7219 BGP_STR
8c3deaae 7220 "Address Family\n"
46f296b4 7221 BGP_SAFI_HELP_STR
b09b5ae0 7222 "Clear bestpath and re-advertise\n"
0c7b1b01 7223 "IPv6 prefix\n")
718e3744 7224{
9b475e76
PG
7225 int idx_safi = 0;
7226 int idx_ipv6_prefix = 0;
7227 safi_t safi = SAFI_UNICAST;
7228 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7229 argv[idx_ipv6_prefix]->arg : NULL;
7230
7231 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7232 return bgp_clear_prefix(
9b475e76
PG
7233 vty, NULL, prefix, AFI_IP6,
7234 safi, NULL);
838758ac 7235}
01080f7c 7236
b09b5ae0
DW
7237DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7238 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7239 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7240 CLEAR_STR
3a2d747c 7241 IP_STR
718e3744 7242 BGP_STR
838758ac 7243 BGP_INSTANCE_HELP_STR
8c3deaae 7244 "Address Family\n"
46f296b4 7245 BGP_SAFI_HELP_STR
b09b5ae0 7246 "Clear bestpath and re-advertise\n"
0c7b1b01 7247 "IPv6 prefix\n")
718e3744 7248{
d62a17ae 7249 int idx_word = 3;
9b475e76
PG
7250 int idx_safi = 0;
7251 int idx_ipv6_prefix = 0;
7252 safi_t safi = SAFI_UNICAST;
7253 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7254 argv[idx_ipv6_prefix]->arg : NULL;
7255 /* [<view|vrf> VIEWVRFNAME] */
7256 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7257 argv[idx_word]->arg : NULL;
7258
7259 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7260
d62a17ae 7261 return bgp_clear_prefix(
9b475e76
PG
7262 vty, vrfview, prefix,
7263 AFI_IP6, safi, NULL);
718e3744 7264}
7265
b09b5ae0
DW
7266DEFUN (show_bgp_views,
7267 show_bgp_views_cmd,
d6e3c605 7268 "show [ip] bgp views",
b09b5ae0 7269 SHOW_STR
d6e3c605 7270 IP_STR
01080f7c 7271 BGP_STR
b09b5ae0 7272 "Show the defined BGP views\n")
01080f7c 7273{
d62a17ae 7274 struct list *inst = bm->bgp;
7275 struct listnode *node;
7276 struct bgp *bgp;
01080f7c 7277
d62a17ae 7278 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7279 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7280 return CMD_WARNING;
7281 }
e52702f2 7282
d62a17ae 7283 vty_out(vty, "Defined BGP views:\n");
7284 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7285 /* Skip VRFs. */
7286 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7287 continue;
7288 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7289 bgp->as);
7290 }
e52702f2 7291
d62a17ae 7292 return CMD_SUCCESS;
e0081f70
ML
7293}
7294
8386ac43 7295DEFUN (show_bgp_vrfs,
7296 show_bgp_vrfs_cmd,
d6e3c605 7297 "show [ip] bgp vrfs [json]",
8386ac43 7298 SHOW_STR
d6e3c605 7299 IP_STR
8386ac43 7300 BGP_STR
7301 "Show BGP VRFs\n"
9973d184 7302 JSON_STR)
8386ac43 7303{
fe1dc5a3 7304 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7305 struct list *inst = bm->bgp;
7306 struct listnode *node;
7307 struct bgp *bgp;
d7c0a89a 7308 uint8_t uj = use_json(argc, argv);
d62a17ae 7309 json_object *json = NULL;
7310 json_object *json_vrfs = NULL;
7311 int count = 0;
d62a17ae 7312
7313 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7314 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7315 return CMD_WARNING;
7316 }
7317
7318 if (uj) {
7319 json = json_object_new_object();
7320 json_vrfs = json_object_new_object();
7321 }
7322
7323 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7324 const char *name, *type;
7325 struct peer *peer;
7326 struct listnode *node, *nnode;
7327 int peers_cfg, peers_estb;
7328 json_object *json_vrf = NULL;
d62a17ae 7329
7330 /* Skip Views. */
7331 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7332 continue;
7333
7334 count++;
7335 if (!uj && count == 1)
fe1dc5a3
MK
7336 vty_out(vty,
7337 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7338 "Type", "Id", "routerId", "#PeersVfg",
7339 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7340
7341 peers_cfg = peers_estb = 0;
7342 if (uj)
7343 json_vrf = json_object_new_object();
7344
7345
7346 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7347 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7348 continue;
7349 peers_cfg++;
7350 if (peer->status == Established)
7351 peers_estb++;
7352 }
7353
7354 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7355 name = "Default";
7356 type = "DFLT";
7357 } else {
7358 name = bgp->name;
7359 type = "VRF";
7360 }
7361
a8bf7d9c 7362
d62a17ae 7363 if (uj) {
a4d82a8a
PZ
7364 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7365 ? -1
7366 : (int64_t)bgp->vrf_id;
d62a17ae 7367 json_object_string_add(json_vrf, "type", type);
7368 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7369 json_object_string_add(json_vrf, "routerId",
7370 inet_ntoa(bgp->router_id));
7371 json_object_int_add(json_vrf, "numConfiguredPeers",
7372 peers_cfg);
7373 json_object_int_add(json_vrf, "numEstablishedPeers",
7374 peers_estb);
7375
fe1dc5a3 7376 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7377 json_object_string_add(
7378 json_vrf, "rmac",
7379 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7380 json_object_object_add(json_vrfs, name, json_vrf);
7381 } else
fe1dc5a3
MK
7382 vty_out(vty,
7383 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7384 type,
7385 bgp->vrf_id == VRF_UNKNOWN ? -1
7386 : (int)bgp->vrf_id,
7387 inet_ntoa(bgp->router_id), peers_cfg,
7388 peers_estb, name, bgp->l3vni,
fe1dc5a3 7389 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7390 }
7391
7392 if (uj) {
7393 json_object_object_add(json, "vrfs", json_vrfs);
7394
7395 json_object_int_add(json, "totalVrfs", count);
7396
996c9314
LB
7397 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7398 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7399 json_object_free(json);
7400 } else {
7401 if (count)
7402 vty_out(vty,
7403 "\nTotal number of VRFs (including default): %d\n",
7404 count);
7405 }
7406
7407 return CMD_SUCCESS;
8386ac43 7408}
7409
acf71666
MK
7410static void show_address_entry(struct hash_backet *backet, void *args)
7411{
60466a63
QY
7412 struct vty *vty = (struct vty *)args;
7413 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 7414
60466a63 7415 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
7416 addr->refcnt);
7417}
7418
7419static void show_tip_entry(struct hash_backet *backet, void *args)
7420{
0291c246 7421 struct vty *vty = (struct vty *)args;
60466a63 7422 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7423
60466a63 7424 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7425 tip->refcnt);
7426}
7427
7428static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7429{
7430 vty_out(vty, "self nexthop database:\n");
7431 hash_iterate(bgp->address_hash,
7432 (void (*)(struct hash_backet *, void *))show_address_entry,
7433 vty);
7434
7435 vty_out(vty, "Tunnel-ip database:\n");
7436 hash_iterate(bgp->tip_hash,
7437 (void (*)(struct hash_backet *, void *))show_tip_entry,
7438 vty);
7439}
7440
15c81ca4
DS
7441DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7442 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7443 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7444 "martian next-hops\n"
7445 "martian next-hop database\n")
acf71666 7446{
0291c246 7447 struct bgp *bgp = NULL;
15c81ca4
DS
7448 int idx = 0;
7449
7450 if (argv_find(argv, argc, "view", &idx)
7451 || argv_find(argv, argc, "vrf", &idx))
7452 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7453 else
7454 bgp = bgp_get_default();
acf71666 7455
acf71666
MK
7456 if (!bgp) {
7457 vty_out(vty, "%% No BGP process is configured\n");
7458 return CMD_WARNING;
7459 }
7460 bgp_show_martian_nexthops(vty, bgp);
7461
7462 return CMD_SUCCESS;
7463}
7464
f412b39a 7465DEFUN (show_bgp_memory,
4bf6a362 7466 show_bgp_memory_cmd,
7fa12b13 7467 "show [ip] bgp memory",
4bf6a362 7468 SHOW_STR
3a2d747c 7469 IP_STR
4bf6a362
PJ
7470 BGP_STR
7471 "Global BGP memory statistics\n")
7472{
d62a17ae 7473 char memstrbuf[MTYPE_MEMSTR_LEN];
7474 unsigned long count;
7475
7476 /* RIB related usage stats */
7477 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7478 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7479 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7480 count * sizeof(struct bgp_node)));
7481
7482 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7483 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7484 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7485 count * sizeof(struct bgp_info)));
7486 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7487 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7488 count,
7489 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7490 count * sizeof(struct bgp_info_extra)));
7491
7492 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7493 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7494 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7495 count * sizeof(struct bgp_static)));
7496
7497 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7498 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7499 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7500 count * sizeof(struct bpacket)));
7501
7502 /* Adj-In/Out */
7503 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7504 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7505 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7506 count * sizeof(struct bgp_adj_in)));
7507 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7508 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7509 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7510 count * sizeof(struct bgp_adj_out)));
7511
7512 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7513 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7514 count,
7515 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7516 count * sizeof(struct bgp_nexthop_cache)));
7517
7518 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7519 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7520 count,
7521 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7522 count * sizeof(struct bgp_damp_info)));
7523
7524 /* Attributes */
7525 count = attr_count();
7526 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7527 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7528 count * sizeof(struct attr)));
7529
7530 if ((count = attr_unknown_count()))
7531 vty_out(vty, "%ld unknown attributes\n", count);
7532
7533 /* AS_PATH attributes */
7534 count = aspath_count();
7535 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7536 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7537 count * sizeof(struct aspath)));
7538
7539 count = mtype_stats_alloc(MTYPE_AS_SEG);
7540 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7541 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7542 count * sizeof(struct assegment)));
7543
7544 /* Other attributes */
7545 if ((count = community_count()))
7546 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7547 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7548 count * sizeof(struct community)));
d62a17ae 7549 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7550 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7551 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7552 count * sizeof(struct ecommunity)));
d62a17ae 7553 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7554 vty_out(vty,
7555 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7556 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7557 count * sizeof(struct lcommunity)));
d62a17ae 7558
7559 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7560 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7561 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7562 count * sizeof(struct cluster_list)));
7563
7564 /* Peer related usage */
7565 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7566 vty_out(vty, "%ld peers, using %s of memory\n", count,
7567 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7568 count * sizeof(struct peer)));
7569
7570 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7571 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7572 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7573 count * sizeof(struct peer_group)));
7574
7575 /* Other */
7576 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7577 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7578 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7579 count * sizeof(struct hash)));
7580 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7581 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7582 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7583 count * sizeof(struct hash_backet)));
7584 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7585 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7586 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7587 count * sizeof(regex_t)));
d62a17ae 7588 return CMD_SUCCESS;
4bf6a362 7589}
fee0f4c6 7590
57a9c8a8
DS
7591static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7592{
7593 json_object *bestpath = json_object_new_object();
7594
7595 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7596 json_object_string_add(bestpath, "asPath", "ignore");
7597
7598 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7599 json_object_string_add(bestpath, "asPath", "confed");
7600
7601 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7602 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7603 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7604 "as-set");
7605 else
a4d82a8a 7606 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7607 "true");
7608 } else
a4d82a8a 7609 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7610
7611 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7612 json_object_string_add(bestpath, "compareRouterId", "true");
7613 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7614 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7615 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7616 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7617 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7618 json_object_string_add(bestpath, "med",
7619 "missing-as-worst");
7620 else
7621 json_object_string_add(bestpath, "med", "true");
7622 }
7623
7624 json_object_object_add(json, "bestPath", bestpath);
7625}
7626
718e3744 7627/* Show BGP peer's summary information. */
d62a17ae 7628static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
d7c0a89a 7629 uint8_t use_json, json_object *json)
d62a17ae 7630{
7631 struct peer *peer;
7632 struct listnode *node, *nnode;
7633 unsigned int count = 0, dn_count = 0;
7634 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7635 char neighbor_buf[VTY_BUFSIZ];
7636 int neighbor_col_default_width = 16;
7637 int len;
7638 int max_neighbor_width = 0;
7639 int pfx_rcd_safi;
7640 json_object *json_peer = NULL;
7641 json_object *json_peers = NULL;
7642
7643 /* labeled-unicast routes are installed in the unicast table so in order
7644 * to
7645 * display the correct PfxRcd value we must look at SAFI_UNICAST
7646 */
7647 if (safi == SAFI_LABELED_UNICAST)
7648 pfx_rcd_safi = SAFI_UNICAST;
7649 else
7650 pfx_rcd_safi = safi;
7651
7652 if (use_json) {
7653 if (json == NULL)
7654 json = json_object_new_object();
7655
7656 json_peers = json_object_new_object();
7657 } else {
7658 /* Loop over all neighbors that will be displayed to determine
7659 * how many
7660 * characters are needed for the Neighbor column
7661 */
7662 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7663 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7664 continue;
7665
7666 if (peer->afc[afi][safi]) {
7667 memset(dn_flag, '\0', sizeof(dn_flag));
7668 if (peer_dynamic_neighbor(peer))
7669 dn_flag[0] = '*';
7670
7671 if (peer->hostname
7672 && bgp_flag_check(bgp,
7673 BGP_FLAG_SHOW_HOSTNAME))
7674 sprintf(neighbor_buf, "%s%s(%s) ",
7675 dn_flag, peer->hostname,
7676 peer->host);
7677 else
7678 sprintf(neighbor_buf, "%s%s ", dn_flag,
7679 peer->host);
7680
7681 len = strlen(neighbor_buf);
7682
7683 if (len > max_neighbor_width)
7684 max_neighbor_width = len;
7685 }
7686 }
f933309e 7687
d62a17ae 7688 /* Originally we displayed the Neighbor column as 16
7689 * characters wide so make that the default
7690 */
7691 if (max_neighbor_width < neighbor_col_default_width)
7692 max_neighbor_width = neighbor_col_default_width;
7693 }
f933309e 7694
d62a17ae 7695 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7696 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7697 continue;
7698
ea47320b
DL
7699 if (!peer->afc[afi][safi])
7700 continue;
d62a17ae 7701
ea47320b
DL
7702 if (!count) {
7703 unsigned long ents;
7704 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7705 int64_t vrf_id_ui;
d62a17ae 7706
a4d82a8a
PZ
7707 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7708 ? -1
7709 : (int64_t)bgp->vrf_id;
ea47320b
DL
7710
7711 /* Usage summary and header */
7712 if (use_json) {
7713 json_object_string_add(
7714 json, "routerId",
7715 inet_ntoa(bgp->router_id));
60466a63
QY
7716 json_object_int_add(json, "as", bgp->as);
7717 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7718 json_object_string_add(
7719 json, "vrfName",
7720 (bgp->inst_type
7721 == BGP_INSTANCE_TYPE_DEFAULT)
7722 ? "Default"
7723 : bgp->name);
7724 } else {
7725 vty_out(vty,
7726 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7727 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7728 bgp->vrf_id == VRF_UNKNOWN
7729 ? -1
7730 : (int)bgp->vrf_id);
ea47320b
DL
7731 vty_out(vty, "\n");
7732 }
d62a17ae 7733
ea47320b 7734 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7735 if (use_json) {
ea47320b 7736 json_object_int_add(
60466a63 7737 json, "updateDelayLimit",
ea47320b 7738 bgp->v_update_delay);
d62a17ae 7739
ea47320b
DL
7740 if (bgp->v_update_delay
7741 != bgp->v_establish_wait)
d62a17ae 7742 json_object_int_add(
7743 json,
ea47320b
DL
7744 "updateDelayEstablishWait",
7745 bgp->v_establish_wait);
d62a17ae 7746
60466a63 7747 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7748 json_object_string_add(
7749 json,
7750 "updateDelayFirstNeighbor",
7751 bgp->update_delay_begin_time);
7752 json_object_boolean_true_add(
7753 json,
7754 "updateDelayInProgress");
7755 } else {
7756 if (bgp->update_delay_over) {
d62a17ae 7757 json_object_string_add(
7758 json,
7759 "updateDelayFirstNeighbor",
7760 bgp->update_delay_begin_time);
ea47320b 7761 json_object_string_add(
d62a17ae 7762 json,
ea47320b
DL
7763 "updateDelayBestpathResumed",
7764 bgp->update_delay_end_time);
7765 json_object_string_add(
d62a17ae 7766 json,
ea47320b
DL
7767 "updateDelayZebraUpdateResume",
7768 bgp->update_delay_zebra_resume_time);
7769 json_object_string_add(
7770 json,
7771 "updateDelayPeerUpdateResume",
7772 bgp->update_delay_peers_resume_time);
d62a17ae 7773 }
ea47320b
DL
7774 }
7775 } else {
7776 vty_out(vty,
7777 "Read-only mode update-delay limit: %d seconds\n",
7778 bgp->v_update_delay);
7779 if (bgp->v_update_delay
7780 != bgp->v_establish_wait)
d62a17ae 7781 vty_out(vty,
ea47320b
DL
7782 " Establish wait: %d seconds\n",
7783 bgp->v_establish_wait);
d62a17ae 7784
60466a63 7785 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7786 vty_out(vty,
7787 " First neighbor established: %s\n",
7788 bgp->update_delay_begin_time);
7789 vty_out(vty,
7790 " Delay in progress\n");
7791 } else {
7792 if (bgp->update_delay_over) {
d62a17ae 7793 vty_out(vty,
7794 " First neighbor established: %s\n",
7795 bgp->update_delay_begin_time);
7796 vty_out(vty,
ea47320b
DL
7797 " Best-paths resumed: %s\n",
7798 bgp->update_delay_end_time);
7799 vty_out(vty,
7800 " zebra update resumed: %s\n",
7801 bgp->update_delay_zebra_resume_time);
7802 vty_out(vty,
7803 " peers update resumed: %s\n",
7804 bgp->update_delay_peers_resume_time);
d62a17ae 7805 }
7806 }
7807 }
ea47320b 7808 }
d62a17ae 7809
ea47320b
DL
7810 if (use_json) {
7811 if (bgp_maxmed_onstartup_configured(bgp)
7812 && bgp->maxmed_active)
7813 json_object_boolean_true_add(
60466a63 7814 json, "maxMedOnStartup");
ea47320b
DL
7815 if (bgp->v_maxmed_admin)
7816 json_object_boolean_true_add(
60466a63 7817 json, "maxMedAdministrative");
d62a17ae 7818
ea47320b
DL
7819 json_object_int_add(
7820 json, "tableVersion",
60466a63 7821 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7822
60466a63
QY
7823 ents = bgp_table_count(bgp->rib[afi][safi]);
7824 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7825 json_object_int_add(
7826 json, "ribMemory",
7827 ents * sizeof(struct bgp_node));
d62a17ae 7828
ea47320b 7829 ents = listcount(bgp->peer);
60466a63
QY
7830 json_object_int_add(json, "peerCount", ents);
7831 json_object_int_add(json, "peerMemory",
7832 ents * sizeof(struct peer));
d62a17ae 7833
ea47320b
DL
7834 if ((ents = listcount(bgp->group))) {
7835 json_object_int_add(
60466a63 7836 json, "peerGroupCount", ents);
ea47320b
DL
7837 json_object_int_add(
7838 json, "peerGroupMemory",
996c9314
LB
7839 ents * sizeof(struct
7840 peer_group));
ea47320b 7841 }
d62a17ae 7842
ea47320b
DL
7843 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7844 BGP_CONFIG_DAMPENING))
7845 json_object_boolean_true_add(
60466a63 7846 json, "dampeningEnabled");
ea47320b
DL
7847 } else {
7848 if (bgp_maxmed_onstartup_configured(bgp)
7849 && bgp->maxmed_active)
d62a17ae 7850 vty_out(vty,
ea47320b
DL
7851 "Max-med on-startup active\n");
7852 if (bgp->v_maxmed_admin)
d62a17ae 7853 vty_out(vty,
ea47320b 7854 "Max-med administrative active\n");
d62a17ae 7855
60466a63
QY
7856 vty_out(vty, "BGP table version %" PRIu64 "\n",
7857 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 7858
60466a63 7859 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
7860 vty_out(vty,
7861 "RIB entries %ld, using %s of memory\n",
7862 ents,
996c9314
LB
7863 mtype_memstr(memstrbuf,
7864 sizeof(memstrbuf),
7865 ents * sizeof(struct
7866 bgp_node)));
ea47320b
DL
7867
7868 /* Peer related usage */
7869 ents = listcount(bgp->peer);
60466a63 7870 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7871 ents,
7872 mtype_memstr(
60466a63
QY
7873 memstrbuf, sizeof(memstrbuf),
7874 ents * sizeof(struct peer)));
ea47320b
DL
7875
7876 if ((ents = listcount(bgp->group)))
d62a17ae 7877 vty_out(vty,
ea47320b 7878 "Peer groups %ld, using %s of memory\n",
d62a17ae 7879 ents,
7880 mtype_memstr(
7881 memstrbuf,
7882 sizeof(memstrbuf),
996c9314
LB
7883 ents * sizeof(struct
7884 peer_group)));
d62a17ae 7885
ea47320b
DL
7886 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7887 BGP_CONFIG_DAMPENING))
60466a63 7888 vty_out(vty, "Dampening enabled.\n");
ea47320b 7889 vty_out(vty, "\n");
d62a17ae 7890
ea47320b
DL
7891 /* Subtract 8 here because 'Neighbor' is
7892 * 8 characters */
7893 vty_out(vty, "Neighbor");
60466a63
QY
7894 vty_out(vty, "%*s", max_neighbor_width - 8,
7895 " ");
ea47320b
DL
7896 vty_out(vty,
7897 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7898 }
ea47320b 7899 }
d62a17ae 7900
ea47320b 7901 count++;
d62a17ae 7902
ea47320b
DL
7903 if (use_json) {
7904 json_peer = json_object_new_object();
d62a17ae 7905
ea47320b 7906 if (peer_dynamic_neighbor(peer))
60466a63
QY
7907 json_object_boolean_true_add(json_peer,
7908 "dynamicPeer");
d62a17ae 7909
ea47320b 7910 if (peer->hostname)
60466a63 7911 json_object_string_add(json_peer, "hostname",
ea47320b 7912 peer->hostname);
d62a17ae 7913
ea47320b 7914 if (peer->domainname)
60466a63
QY
7915 json_object_string_add(json_peer, "domainname",
7916 peer->domainname);
d62a17ae 7917
60466a63 7918 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7919 json_object_int_add(json_peer, "version", 4);
60466a63 7920 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 7921 PEER_TOTAL_RX(peer));
60466a63 7922 json_object_int_add(json_peer, "msgSent",
0112e9e0 7923 PEER_TOTAL_TX(peer));
ea47320b
DL
7924
7925 json_object_int_add(json_peer, "tableVersion",
7926 peer->version[afi][safi]);
7927 json_object_int_add(json_peer, "outq",
7928 peer->obuf->count);
7929 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7930 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7931 use_json, json_peer);
7932 json_object_int_add(json_peer, "prefixReceivedCount",
7933 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 7934
ea47320b 7935 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7936 json_object_string_add(json_peer, "state",
ea47320b 7937 "Idle (Admin)");
60466a63
QY
7938 else if (CHECK_FLAG(peer->sflags,
7939 PEER_STATUS_PREFIX_OVERFLOW))
7940 json_object_string_add(json_peer, "state",
ea47320b
DL
7941 "Idle (PfxCt)");
7942 else
7943 json_object_string_add(
7944 json_peer, "state",
60466a63
QY
7945 lookup_msg(bgp_status_msg, peer->status,
7946 NULL));
ea47320b
DL
7947
7948 if (peer->conf_if)
60466a63 7949 json_object_string_add(json_peer, "idType",
ea47320b
DL
7950 "interface");
7951 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
7952 json_object_string_add(json_peer, "idType",
7953 "ipv4");
ea47320b 7954 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
7955 json_object_string_add(json_peer, "idType",
7956 "ipv6");
d62a17ae 7957
ea47320b
DL
7958 json_object_object_add(json_peers, peer->host,
7959 json_peer);
7960 } else {
7961 memset(dn_flag, '\0', sizeof(dn_flag));
7962 if (peer_dynamic_neighbor(peer)) {
7963 dn_count++;
7964 dn_flag[0] = '*';
7965 }
d62a17ae 7966
ea47320b 7967 if (peer->hostname
60466a63 7968 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 7969 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 7970 peer->hostname, peer->host);
ea47320b 7971 else
60466a63 7972 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
7973
7974 /* pad the neighbor column with spaces */
7975 if (len < max_neighbor_width)
60466a63
QY
7976 vty_out(vty, "%*s", max_neighbor_width - len,
7977 " ");
ea47320b 7978
86a55b99 7979 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
7980 peer->as, PEER_TOTAL_RX(peer),
7981 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7982 0, peer->obuf->count,
d62a17ae 7983 peer_uptime(peer->uptime, timebuf,
ea47320b 7984 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 7985
ea47320b 7986 if (peer->status == Established)
2f8f4f10 7987 if (peer->afc_recv[afi][safi])
95077abf 7988 vty_out(vty, " %12ld",
a4d82a8a
PZ
7989 peer->pcount[afi]
7990 [pfx_rcd_safi]);
95077abf
DW
7991 else
7992 vty_out(vty, " NoNeg");
ea47320b 7993 else {
60466a63 7994 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 7995 vty_out(vty, " Idle (Admin)");
60466a63
QY
7996 else if (CHECK_FLAG(
7997 peer->sflags,
7998 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 7999 vty_out(vty, " Idle (PfxCt)");
d62a17ae 8000 else
ea47320b 8001 vty_out(vty, " %12s",
60466a63
QY
8002 lookup_msg(bgp_status_msg,
8003 peer->status, NULL));
d62a17ae 8004 }
ea47320b 8005 vty_out(vty, "\n");
d62a17ae 8006 }
8007 }
f933309e 8008
d62a17ae 8009 if (use_json) {
8010 json_object_object_add(json, "peers", json_peers);
8011
8012 json_object_int_add(json, "totalPeers", count);
8013 json_object_int_add(json, "dynamicPeers", dn_count);
8014
57a9c8a8
DS
8015 bgp_show_bestpath_json(bgp, json);
8016
996c9314
LB
8017 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8018 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8019 json_object_free(json);
8020 } else {
8021 if (count)
8022 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8023 else {
d6ceaca3 8024 vty_out(vty, "No %s neighbor is configured\n",
8025 afi_safi_print(afi, safi));
d62a17ae 8026 }
b05a1c8b 8027
d6ceaca3 8028 if (dn_count) {
d62a17ae 8029 vty_out(vty, "* - dynamic neighbor\n");
8030 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8031 dn_count, bgp->dynamic_neighbors_limit);
8032 }
8033 }
1ff9a340 8034
d62a17ae 8035 return CMD_SUCCESS;
718e3744 8036}
8037
d62a17ae 8038static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
d7c0a89a 8039 int safi, uint8_t use_json,
d62a17ae 8040 json_object *json)
8041{
8042 int is_first = 1;
8043 int afi_wildcard = (afi == AFI_MAX);
8044 int safi_wildcard = (safi == SAFI_MAX);
8045 int is_wildcard = (afi_wildcard || safi_wildcard);
8046 bool json_output = false;
8047
8048 if (use_json && is_wildcard)
8049 vty_out(vty, "{\n");
8050 if (afi_wildcard)
8051 afi = 1; /* AFI_IP */
8052 while (afi < AFI_MAX) {
8053 if (safi_wildcard)
8054 safi = 1; /* SAFI_UNICAST */
8055 while (safi < SAFI_MAX) {
318cac96 8056 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
d62a17ae 8057 json_output = true;
8058 if (is_wildcard) {
8059 /*
8060 * So limit output to those afi/safi
8061 * pairs that
8062 * actualy have something interesting in
8063 * them
8064 */
8065 if (use_json) {
8066 json = json_object_new_object();
8067
8068 if (!is_first)
8069 vty_out(vty, ",\n");
8070 else
8071 is_first = 0;
8072
8073 vty_out(vty, "\"%s\":",
8074 afi_safi_json(afi,
8075 safi));
8076 } else {
8077 vty_out(vty, "\n%s Summary:\n",
8078 afi_safi_print(afi,
8079 safi));
8080 }
8081 }
8082 bgp_show_summary(vty, bgp, afi, safi, use_json,
8083 json);
8084 }
8085 safi++;
d62a17ae 8086 if (!safi_wildcard)
8087 safi = SAFI_MAX;
8088 }
8089 afi++;
ee851c8c 8090 if (!afi_wildcard)
d62a17ae 8091 afi = AFI_MAX;
8092 }
8093
8094 if (use_json && is_wildcard)
8095 vty_out(vty, "}\n");
8096 else if (use_json && !json_output)
8097 vty_out(vty, "{}\n");
8098}
8099
8100static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
d7c0a89a 8101 safi_t safi, uint8_t use_json)
d62a17ae 8102{
8103 struct listnode *node, *nnode;
8104 struct bgp *bgp;
8105 json_object *json = NULL;
8106 int is_first = 1;
8107
8108 if (use_json)
8109 vty_out(vty, "{\n");
8110
8111 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8112 if (use_json) {
8113 json = json_object_new_object();
8114
8115 if (!is_first)
8116 vty_out(vty, ",\n");
8117 else
8118 is_first = 0;
8119
8120 vty_out(vty, "\"%s\":",
8121 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8122 ? "Default"
8123 : bgp->name);
8124 } else {
8125 vty_out(vty, "\nInstance %s:\n",
8126 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8127 ? "Default"
8128 : bgp->name);
8129 }
8130 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8131 }
8132
8133 if (use_json)
8134 vty_out(vty, "}\n");
8135}
8136
8137int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
d7c0a89a 8138 safi_t safi, uint8_t use_json)
d62a17ae 8139{
8140 struct bgp *bgp;
8141
8142 if (name) {
8143 if (strmatch(name, "all")) {
8144 bgp_show_all_instances_summary_vty(vty, afi, safi,
8145 use_json);
8146 return CMD_SUCCESS;
8147 } else {
8148 bgp = bgp_lookup_by_name(name);
8149
8150 if (!bgp) {
8151 if (use_json)
8152 vty_out(vty, "{}\n");
8153 else
8154 vty_out(vty,
8155 "%% No such BGP instance exist\n");
8156 return CMD_WARNING;
8157 }
8158
8159 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8160 NULL);
8161 return CMD_SUCCESS;
8162 }
8163 }
8164
8165 bgp = bgp_get_default();
8166
8167 if (bgp)
8168 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8169
8170 return CMD_SUCCESS;
4fb25c53
DW
8171}
8172
716b2d8a 8173/* `show [ip] bgp summary' commands. */
47fc97cc 8174DEFUN (show_ip_bgp_summary,
718e3744 8175 show_ip_bgp_summary_cmd,
dd6bd0f1 8176 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8177 SHOW_STR
8178 IP_STR
8179 BGP_STR
8386ac43 8180 BGP_INSTANCE_HELP_STR
46f296b4 8181 BGP_AFI_HELP_STR
dd6bd0f1 8182 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8183 "Summary of BGP neighbor status\n"
9973d184 8184 JSON_STR)
718e3744 8185{
d62a17ae 8186 char *vrf = NULL;
8187 afi_t afi = AFI_MAX;
8188 safi_t safi = SAFI_MAX;
8189
8190 int idx = 0;
8191
8192 /* show [ip] bgp */
8193 if (argv_find(argv, argc, "ip", &idx))
8194 afi = AFI_IP;
8195 /* [<view|vrf> VIEWVRFNAME] */
8196 if (argv_find(argv, argc, "view", &idx)
8197 || argv_find(argv, argc, "vrf", &idx))
8198 vrf = argv[++idx]->arg;
8199 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8200 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8201 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8202 }
8203
8204 int uj = use_json(argc, argv);
8205
8206 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8207}
8208
8209const char *afi_safi_print(afi_t afi, safi_t safi)
8210{
8211 if (afi == AFI_IP && safi == SAFI_UNICAST)
8212 return "IPv4 Unicast";
8213 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8214 return "IPv4 Multicast";
8215 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8216 return "IPv4 Labeled Unicast";
8217 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8218 return "IPv4 VPN";
8219 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8220 return "IPv4 Encap";
7c40bf39 8221 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8222 return "IPv4 Flowspec";
d62a17ae 8223 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8224 return "IPv6 Unicast";
8225 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8226 return "IPv6 Multicast";
8227 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8228 return "IPv6 Labeled Unicast";
8229 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8230 return "IPv6 VPN";
8231 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8232 return "IPv6 Encap";
7c40bf39 8233 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8234 return "IPv6 Flowspec";
d62a17ae 8235 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8236 return "L2VPN EVPN";
8237 else
8238 return "Unknown";
538621f2 8239}
8240
b9f77ec8
DS
8241/*
8242 * Please note that we have intentionally camelCased
8243 * the return strings here. So if you want
8244 * to use this function, please ensure you
8245 * are doing this within json output
8246 */
d62a17ae 8247const char *afi_safi_json(afi_t afi, safi_t safi)
8248{
8249 if (afi == AFI_IP && safi == SAFI_UNICAST)
8250 return "ipv4Unicast";
8251 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8252 return "ipv4Multicast";
8253 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8254 return "ipv4LabeledUnicast";
8255 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8256 return "ipv4Vpn";
8257 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8258 return "ipv4Encap";
7c40bf39 8259 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8260 return "ipv4Flowspec";
d62a17ae 8261 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8262 return "ipv6Unicast";
8263 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8264 return "ipv6Multicast";
8265 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8266 return "ipv6LabeledUnicast";
8267 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8268 return "ipv6Vpn";
8269 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8270 return "ipv6Encap";
7c40bf39 8271 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8272 return "ipv6Flowspec";
d62a17ae 8273 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8274 return "l2VpnEvpn";
8275 else
8276 return "Unknown";
27162734
LB
8277}
8278
718e3744 8279/* Show BGP peer's information. */
d62a17ae 8280enum show_type { show_all, show_peer };
8281
8282static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8283 afi_t afi, safi_t safi,
d7c0a89a
QY
8284 uint16_t adv_smcap, uint16_t adv_rmcap,
8285 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8286 uint8_t use_json, json_object *json_pref)
d62a17ae 8287{
8288 /* Send-Mode */
8289 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8290 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8291 if (use_json) {
8292 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8293 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8294 json_object_string_add(json_pref, "sendMode",
8295 "advertisedAndReceived");
8296 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8297 json_object_string_add(json_pref, "sendMode",
8298 "advertised");
8299 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8300 json_object_string_add(json_pref, "sendMode",
8301 "received");
8302 } else {
8303 vty_out(vty, " Send-mode: ");
8304 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8305 vty_out(vty, "advertised");
8306 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8307 vty_out(vty, "%sreceived",
8308 CHECK_FLAG(p->af_cap[afi][safi],
8309 adv_smcap)
8310 ? ", "
8311 : "");
8312 vty_out(vty, "\n");
8313 }
8314 }
8315
8316 /* Receive-Mode */
8317 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8318 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8319 if (use_json) {
8320 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8321 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8322 json_object_string_add(json_pref, "recvMode",
8323 "advertisedAndReceived");
8324 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8325 json_object_string_add(json_pref, "recvMode",
8326 "advertised");
8327 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8328 json_object_string_add(json_pref, "recvMode",
8329 "received");
8330 } else {
8331 vty_out(vty, " Receive-mode: ");
8332 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8333 vty_out(vty, "advertised");
8334 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8335 vty_out(vty, "%sreceived",
8336 CHECK_FLAG(p->af_cap[afi][safi],
8337 adv_rmcap)
8338 ? ", "
8339 : "");
8340 vty_out(vty, "\n");
8341 }
8342 }
8343}
8344
8345static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
d7c0a89a 8346 safi_t safi, uint8_t use_json,
d62a17ae 8347 json_object *json_neigh)
8348{
0291c246
MK
8349 struct bgp_filter *filter;
8350 struct peer_af *paf;
8351 char orf_pfx_name[BUFSIZ];
8352 int orf_pfx_count;
8353 json_object *json_af = NULL;
8354 json_object *json_prefA = NULL;
8355 json_object *json_prefB = NULL;
8356 json_object *json_addr = NULL;
d62a17ae 8357
8358 if (use_json) {
8359 json_addr = json_object_new_object();
8360 json_af = json_object_new_object();
8361 filter = &p->filter[afi][safi];
8362
8363 if (peer_group_active(p))
8364 json_object_string_add(json_addr, "peerGroupMember",
8365 p->group->name);
8366
8367 paf = peer_af_find(p, afi, safi);
8368 if (paf && PAF_SUBGRP(paf)) {
8369 json_object_int_add(json_addr, "updateGroupId",
8370 PAF_UPDGRP(paf)->id);
8371 json_object_int_add(json_addr, "subGroupId",
8372 PAF_SUBGRP(paf)->id);
8373 json_object_int_add(json_addr, "packetQueueLength",
8374 bpacket_queue_virtual_length(paf));
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_RM_ADV)
8382 || CHECK_FLAG(p->af_cap[afi][safi],
8383 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8384 json_object_int_add(json_af, "orfType",
8385 ORF_TYPE_PREFIX);
8386 json_prefA = json_object_new_object();
8387 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8388 PEER_CAP_ORF_PREFIX_SM_ADV,
8389 PEER_CAP_ORF_PREFIX_RM_ADV,
8390 PEER_CAP_ORF_PREFIX_SM_RCV,
8391 PEER_CAP_ORF_PREFIX_RM_RCV,
8392 use_json, json_prefA);
8393 json_object_object_add(json_af, "orfPrefixList",
8394 json_prefA);
8395 }
8396
8397 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8398 || CHECK_FLAG(p->af_cap[afi][safi],
8399 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8400 || CHECK_FLAG(p->af_cap[afi][safi],
8401 PEER_CAP_ORF_PREFIX_RM_ADV)
8402 || CHECK_FLAG(p->af_cap[afi][safi],
8403 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8404 json_object_int_add(json_af, "orfOldType",
8405 ORF_TYPE_PREFIX_OLD);
8406 json_prefB = json_object_new_object();
8407 bgp_show_peer_afi_orf_cap(
8408 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8409 PEER_CAP_ORF_PREFIX_RM_ADV,
8410 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8411 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8412 json_prefB);
8413 json_object_object_add(json_af, "orfOldPrefixList",
8414 json_prefB);
8415 }
8416
8417 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8418 || CHECK_FLAG(p->af_cap[afi][safi],
8419 PEER_CAP_ORF_PREFIX_SM_RCV)
8420 || CHECK_FLAG(p->af_cap[afi][safi],
8421 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8422 || CHECK_FLAG(p->af_cap[afi][safi],
8423 PEER_CAP_ORF_PREFIX_RM_ADV)
8424 || CHECK_FLAG(p->af_cap[afi][safi],
8425 PEER_CAP_ORF_PREFIX_RM_RCV)
8426 || CHECK_FLAG(p->af_cap[afi][safi],
8427 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8428 json_object_object_add(json_addr, "afDependentCap",
8429 json_af);
8430 else
8431 json_object_free(json_af);
8432
8433 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8434 orf_pfx_count = prefix_bgp_show_prefix_list(
8435 NULL, afi, orf_pfx_name, use_json);
8436
8437 if (CHECK_FLAG(p->af_sflags[afi][safi],
8438 PEER_STATUS_ORF_PREFIX_SEND)
8439 || orf_pfx_count) {
8440 if (CHECK_FLAG(p->af_sflags[afi][safi],
8441 PEER_STATUS_ORF_PREFIX_SEND))
8442 json_object_boolean_true_add(json_neigh,
8443 "orfSent");
8444 if (orf_pfx_count)
8445 json_object_int_add(json_addr, "orfRecvCounter",
8446 orf_pfx_count);
8447 }
8448 if (CHECK_FLAG(p->af_sflags[afi][safi],
8449 PEER_STATUS_ORF_WAIT_REFRESH))
8450 json_object_string_add(
8451 json_addr, "orfFirstUpdate",
8452 "deferredUntilORFOrRouteRefreshRecvd");
8453
8454 if (CHECK_FLAG(p->af_flags[afi][safi],
8455 PEER_FLAG_REFLECTOR_CLIENT))
8456 json_object_boolean_true_add(json_addr,
8457 "routeReflectorClient");
8458 if (CHECK_FLAG(p->af_flags[afi][safi],
8459 PEER_FLAG_RSERVER_CLIENT))
8460 json_object_boolean_true_add(json_addr,
8461 "routeServerClient");
8462 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8463 json_object_boolean_true_add(json_addr,
8464 "inboundSoftConfigPermit");
8465
8466 if (CHECK_FLAG(p->af_flags[afi][safi],
8467 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8468 json_object_boolean_true_add(
8469 json_addr,
8470 "privateAsNumsAllReplacedInUpdatesToNbr");
8471 else if (CHECK_FLAG(p->af_flags[afi][safi],
8472 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8473 json_object_boolean_true_add(
8474 json_addr,
8475 "privateAsNumsReplacedInUpdatesToNbr");
8476 else if (CHECK_FLAG(p->af_flags[afi][safi],
8477 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8478 json_object_boolean_true_add(
8479 json_addr,
8480 "privateAsNumsAllRemovedInUpdatesToNbr");
8481 else if (CHECK_FLAG(p->af_flags[afi][safi],
8482 PEER_FLAG_REMOVE_PRIVATE_AS))
8483 json_object_boolean_true_add(
8484 json_addr,
8485 "privateAsNumsRemovedInUpdatesToNbr");
8486
8487 if (CHECK_FLAG(p->af_flags[afi][safi],
8488 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8489 json_object_boolean_true_add(json_addr,
8490 "addpathTxAllPaths");
8491
8492 if (CHECK_FLAG(p->af_flags[afi][safi],
8493 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8494 json_object_boolean_true_add(json_addr,
8495 "addpathTxBestpathPerAS");
8496
8497 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8498 json_object_string_add(json_addr,
8499 "overrideASNsInOutboundUpdates",
8500 "ifAspathEqualRemoteAs");
8501
8502 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8503 || CHECK_FLAG(p->af_flags[afi][safi],
8504 PEER_FLAG_FORCE_NEXTHOP_SELF))
8505 json_object_boolean_true_add(json_addr,
8506 "routerAlwaysNextHop");
8507 if (CHECK_FLAG(p->af_flags[afi][safi],
8508 PEER_FLAG_AS_PATH_UNCHANGED))
8509 json_object_boolean_true_add(
8510 json_addr, "unchangedAsPathPropogatedToNbr");
8511 if (CHECK_FLAG(p->af_flags[afi][safi],
8512 PEER_FLAG_NEXTHOP_UNCHANGED))
8513 json_object_boolean_true_add(
8514 json_addr, "unchangedNextHopPropogatedToNbr");
8515 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8516 json_object_boolean_true_add(
8517 json_addr, "unchangedMedPropogatedToNbr");
8518 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8519 || CHECK_FLAG(p->af_flags[afi][safi],
8520 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8521 if (CHECK_FLAG(p->af_flags[afi][safi],
8522 PEER_FLAG_SEND_COMMUNITY)
8523 && CHECK_FLAG(p->af_flags[afi][safi],
8524 PEER_FLAG_SEND_EXT_COMMUNITY))
8525 json_object_string_add(json_addr,
8526 "commAttriSentToNbr",
8527 "extendedAndStandard");
8528 else if (CHECK_FLAG(p->af_flags[afi][safi],
8529 PEER_FLAG_SEND_EXT_COMMUNITY))
8530 json_object_string_add(json_addr,
8531 "commAttriSentToNbr",
8532 "extended");
8533 else
8534 json_object_string_add(json_addr,
8535 "commAttriSentToNbr",
8536 "standard");
8537 }
8538 if (CHECK_FLAG(p->af_flags[afi][safi],
8539 PEER_FLAG_DEFAULT_ORIGINATE)) {
8540 if (p->default_rmap[afi][safi].name)
8541 json_object_string_add(
8542 json_addr, "defaultRouteMap",
8543 p->default_rmap[afi][safi].name);
8544
8545 if (paf && PAF_SUBGRP(paf)
8546 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8547 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8548 json_object_boolean_true_add(json_addr,
8549 "defaultSent");
8550 else
8551 json_object_boolean_true_add(json_addr,
8552 "defaultNotSent");
8553 }
8554
dff8f48d 8555 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8556 if (is_evpn_enabled())
60466a63
QY
8557 json_object_boolean_true_add(
8558 json_addr, "advertiseAllVnis");
dff8f48d
MK
8559 }
8560
d62a17ae 8561 if (filter->plist[FILTER_IN].name
8562 || filter->dlist[FILTER_IN].name
8563 || filter->aslist[FILTER_IN].name
8564 || filter->map[RMAP_IN].name)
8565 json_object_boolean_true_add(json_addr,
8566 "inboundPathPolicyConfig");
8567 if (filter->plist[FILTER_OUT].name
8568 || filter->dlist[FILTER_OUT].name
8569 || filter->aslist[FILTER_OUT].name
8570 || filter->map[RMAP_OUT].name || filter->usmap.name)
8571 json_object_boolean_true_add(
8572 json_addr, "outboundPathPolicyConfig");
8573
8574 /* prefix-list */
8575 if (filter->plist[FILTER_IN].name)
8576 json_object_string_add(json_addr,
8577 "incomingUpdatePrefixFilterList",
8578 filter->plist[FILTER_IN].name);
8579 if (filter->plist[FILTER_OUT].name)
8580 json_object_string_add(json_addr,
8581 "outgoingUpdatePrefixFilterList",
8582 filter->plist[FILTER_OUT].name);
8583
8584 /* distribute-list */
8585 if (filter->dlist[FILTER_IN].name)
8586 json_object_string_add(
8587 json_addr, "incomingUpdateNetworkFilterList",
8588 filter->dlist[FILTER_IN].name);
8589 if (filter->dlist[FILTER_OUT].name)
8590 json_object_string_add(
8591 json_addr, "outgoingUpdateNetworkFilterList",
8592 filter->dlist[FILTER_OUT].name);
8593
8594 /* filter-list. */
8595 if (filter->aslist[FILTER_IN].name)
8596 json_object_string_add(json_addr,
8597 "incomingUpdateAsPathFilterList",
8598 filter->aslist[FILTER_IN].name);
8599 if (filter->aslist[FILTER_OUT].name)
8600 json_object_string_add(json_addr,
8601 "outgoingUpdateAsPathFilterList",
8602 filter->aslist[FILTER_OUT].name);
8603
8604 /* route-map. */
8605 if (filter->map[RMAP_IN].name)
8606 json_object_string_add(
8607 json_addr, "routeMapForIncomingAdvertisements",
8608 filter->map[RMAP_IN].name);
8609 if (filter->map[RMAP_OUT].name)
8610 json_object_string_add(
8611 json_addr, "routeMapForOutgoingAdvertisements",
8612 filter->map[RMAP_OUT].name);
8613
8614 /* unsuppress-map */
8615 if (filter->usmap.name)
8616 json_object_string_add(json_addr,
8617 "selectiveUnsuppressRouteMap",
8618 filter->usmap.name);
8619
8620 /* Receive prefix count */
8621 json_object_int_add(json_addr, "acceptedPrefixCounter",
8622 p->pcount[afi][safi]);
8623
8624 /* Maximum prefix */
8625 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8626 json_object_int_add(json_addr, "prefixAllowedMax",
8627 p->pmax[afi][safi]);
8628 if (CHECK_FLAG(p->af_flags[afi][safi],
8629 PEER_FLAG_MAX_PREFIX_WARNING))
8630 json_object_boolean_true_add(
8631 json_addr, "prefixAllowedMaxWarning");
8632 json_object_int_add(json_addr,
8633 "prefixAllowedWarningThresh",
8634 p->pmax_threshold[afi][safi]);
8635 if (p->pmax_restart[afi][safi])
8636 json_object_int_add(
8637 json_addr,
8638 "prefixAllowedRestartIntervalMsecs",
8639 p->pmax_restart[afi][safi] * 60000);
8640 }
8641 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8642 json_addr);
8643
8644 } else {
8645 filter = &p->filter[afi][safi];
8646
8647 vty_out(vty, " For address family: %s\n",
8648 afi_safi_print(afi, safi));
8649
8650 if (peer_group_active(p))
8651 vty_out(vty, " %s peer-group member\n",
8652 p->group->name);
8653
8654 paf = peer_af_find(p, afi, safi);
8655 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8656 vty_out(vty, " Update group %" PRIu64
8657 ", subgroup %" PRIu64 "\n",
d62a17ae 8658 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8659 vty_out(vty, " Packet Queue length %d\n",
8660 bpacket_queue_virtual_length(paf));
8661 } else {
8662 vty_out(vty, " Not part of any update group\n");
8663 }
8664 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8665 || CHECK_FLAG(p->af_cap[afi][safi],
8666 PEER_CAP_ORF_PREFIX_SM_RCV)
8667 || CHECK_FLAG(p->af_cap[afi][safi],
8668 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8669 || CHECK_FLAG(p->af_cap[afi][safi],
8670 PEER_CAP_ORF_PREFIX_RM_ADV)
8671 || CHECK_FLAG(p->af_cap[afi][safi],
8672 PEER_CAP_ORF_PREFIX_RM_RCV)
8673 || CHECK_FLAG(p->af_cap[afi][safi],
8674 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8675 vty_out(vty, " AF-dependant capabilities:\n");
8676
8677 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8678 || CHECK_FLAG(p->af_cap[afi][safi],
8679 PEER_CAP_ORF_PREFIX_SM_RCV)
8680 || CHECK_FLAG(p->af_cap[afi][safi],
8681 PEER_CAP_ORF_PREFIX_RM_ADV)
8682 || CHECK_FLAG(p->af_cap[afi][safi],
8683 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8684 vty_out(vty,
8685 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8686 ORF_TYPE_PREFIX);
8687 bgp_show_peer_afi_orf_cap(
8688 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8689 PEER_CAP_ORF_PREFIX_RM_ADV,
8690 PEER_CAP_ORF_PREFIX_SM_RCV,
8691 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8692 }
8693 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8694 || CHECK_FLAG(p->af_cap[afi][safi],
8695 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8696 || CHECK_FLAG(p->af_cap[afi][safi],
8697 PEER_CAP_ORF_PREFIX_RM_ADV)
8698 || CHECK_FLAG(p->af_cap[afi][safi],
8699 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8700 vty_out(vty,
8701 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8702 ORF_TYPE_PREFIX_OLD);
8703 bgp_show_peer_afi_orf_cap(
8704 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8705 PEER_CAP_ORF_PREFIX_RM_ADV,
8706 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8707 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8708 }
8709
8710 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8711 orf_pfx_count = prefix_bgp_show_prefix_list(
8712 NULL, afi, orf_pfx_name, use_json);
8713
8714 if (CHECK_FLAG(p->af_sflags[afi][safi],
8715 PEER_STATUS_ORF_PREFIX_SEND)
8716 || orf_pfx_count) {
8717 vty_out(vty, " Outbound Route Filter (ORF):");
8718 if (CHECK_FLAG(p->af_sflags[afi][safi],
8719 PEER_STATUS_ORF_PREFIX_SEND))
8720 vty_out(vty, " sent;");
8721 if (orf_pfx_count)
8722 vty_out(vty, " received (%d entries)",
8723 orf_pfx_count);
8724 vty_out(vty, "\n");
8725 }
8726 if (CHECK_FLAG(p->af_sflags[afi][safi],
8727 PEER_STATUS_ORF_WAIT_REFRESH))
8728 vty_out(vty,
8729 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8730
8731 if (CHECK_FLAG(p->af_flags[afi][safi],
8732 PEER_FLAG_REFLECTOR_CLIENT))
8733 vty_out(vty, " Route-Reflector Client\n");
8734 if (CHECK_FLAG(p->af_flags[afi][safi],
8735 PEER_FLAG_RSERVER_CLIENT))
8736 vty_out(vty, " Route-Server Client\n");
8737 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8738 vty_out(vty,
8739 " Inbound soft reconfiguration allowed\n");
8740
8741 if (CHECK_FLAG(p->af_flags[afi][safi],
8742 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8743 vty_out(vty,
8744 " Private AS numbers (all) replaced in updates to this neighbor\n");
8745 else if (CHECK_FLAG(p->af_flags[afi][safi],
8746 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8747 vty_out(vty,
8748 " Private AS numbers replaced in updates to this neighbor\n");
8749 else if (CHECK_FLAG(p->af_flags[afi][safi],
8750 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8751 vty_out(vty,
8752 " Private AS numbers (all) removed in updates to this neighbor\n");
8753 else if (CHECK_FLAG(p->af_flags[afi][safi],
8754 PEER_FLAG_REMOVE_PRIVATE_AS))
8755 vty_out(vty,
8756 " Private AS numbers removed in updates to this neighbor\n");
8757
8758 if (CHECK_FLAG(p->af_flags[afi][safi],
8759 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8760 vty_out(vty, " Advertise all paths via addpath\n");
8761
8762 if (CHECK_FLAG(p->af_flags[afi][safi],
8763 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8764 vty_out(vty,
8765 " Advertise bestpath per AS via addpath\n");
8766
8767 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8768 vty_out(vty,
8769 " Override ASNs in outbound updates if aspath equals remote-as\n");
8770
8771 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8772 || CHECK_FLAG(p->af_flags[afi][safi],
8773 PEER_FLAG_FORCE_NEXTHOP_SELF))
8774 vty_out(vty, " NEXT_HOP is always this router\n");
8775 if (CHECK_FLAG(p->af_flags[afi][safi],
8776 PEER_FLAG_AS_PATH_UNCHANGED))
8777 vty_out(vty,
8778 " AS_PATH is propagated unchanged to this neighbor\n");
8779 if (CHECK_FLAG(p->af_flags[afi][safi],
8780 PEER_FLAG_NEXTHOP_UNCHANGED))
8781 vty_out(vty,
8782 " NEXT_HOP is propagated unchanged to this neighbor\n");
8783 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8784 vty_out(vty,
8785 " MED is propagated unchanged to this neighbor\n");
8786 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8787 || CHECK_FLAG(p->af_flags[afi][safi],
8788 PEER_FLAG_SEND_EXT_COMMUNITY)
8789 || CHECK_FLAG(p->af_flags[afi][safi],
8790 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8791 vty_out(vty,
8792 " Community attribute sent to this neighbor");
8793 if (CHECK_FLAG(p->af_flags[afi][safi],
8794 PEER_FLAG_SEND_COMMUNITY)
8795 && CHECK_FLAG(p->af_flags[afi][safi],
8796 PEER_FLAG_SEND_EXT_COMMUNITY)
8797 && CHECK_FLAG(p->af_flags[afi][safi],
8798 PEER_FLAG_SEND_LARGE_COMMUNITY))
8799 vty_out(vty, "(all)\n");
8800 else if (CHECK_FLAG(p->af_flags[afi][safi],
8801 PEER_FLAG_SEND_LARGE_COMMUNITY))
8802 vty_out(vty, "(large)\n");
8803 else if (CHECK_FLAG(p->af_flags[afi][safi],
8804 PEER_FLAG_SEND_EXT_COMMUNITY))
8805 vty_out(vty, "(extended)\n");
8806 else
8807 vty_out(vty, "(standard)\n");
8808 }
8809 if (CHECK_FLAG(p->af_flags[afi][safi],
8810 PEER_FLAG_DEFAULT_ORIGINATE)) {
8811 vty_out(vty, " Default information originate,");
8812
8813 if (p->default_rmap[afi][safi].name)
8814 vty_out(vty, " default route-map %s%s,",
8815 p->default_rmap[afi][safi].map ? "*"
8816 : "",
8817 p->default_rmap[afi][safi].name);
8818 if (paf && PAF_SUBGRP(paf)
8819 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8820 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8821 vty_out(vty, " default sent\n");
8822 else
8823 vty_out(vty, " default not sent\n");
8824 }
8825
dff8f48d
MK
8826 /* advertise-vni-all */
8827 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8828 if (is_evpn_enabled())
dff8f48d
MK
8829 vty_out(vty, " advertise-all-vni\n");
8830 }
8831
d62a17ae 8832 if (filter->plist[FILTER_IN].name
8833 || filter->dlist[FILTER_IN].name
8834 || filter->aslist[FILTER_IN].name
8835 || filter->map[RMAP_IN].name)
8836 vty_out(vty, " Inbound path policy configured\n");
8837 if (filter->plist[FILTER_OUT].name
8838 || filter->dlist[FILTER_OUT].name
8839 || filter->aslist[FILTER_OUT].name
8840 || filter->map[RMAP_OUT].name || filter->usmap.name)
8841 vty_out(vty, " Outbound path policy configured\n");
8842
8843 /* prefix-list */
8844 if (filter->plist[FILTER_IN].name)
8845 vty_out(vty,
8846 " Incoming update prefix filter list is %s%s\n",
8847 filter->plist[FILTER_IN].plist ? "*" : "",
8848 filter->plist[FILTER_IN].name);
8849 if (filter->plist[FILTER_OUT].name)
8850 vty_out(vty,
8851 " Outgoing update prefix filter list is %s%s\n",
8852 filter->plist[FILTER_OUT].plist ? "*" : "",
8853 filter->plist[FILTER_OUT].name);
8854
8855 /* distribute-list */
8856 if (filter->dlist[FILTER_IN].name)
8857 vty_out(vty,
8858 " Incoming update network filter list is %s%s\n",
8859 filter->dlist[FILTER_IN].alist ? "*" : "",
8860 filter->dlist[FILTER_IN].name);
8861 if (filter->dlist[FILTER_OUT].name)
8862 vty_out(vty,
8863 " Outgoing update network filter list is %s%s\n",
8864 filter->dlist[FILTER_OUT].alist ? "*" : "",
8865 filter->dlist[FILTER_OUT].name);
8866
8867 /* filter-list. */
8868 if (filter->aslist[FILTER_IN].name)
8869 vty_out(vty,
8870 " Incoming update AS path filter list is %s%s\n",
8871 filter->aslist[FILTER_IN].aslist ? "*" : "",
8872 filter->aslist[FILTER_IN].name);
8873 if (filter->aslist[FILTER_OUT].name)
8874 vty_out(vty,
8875 " Outgoing update AS path filter list is %s%s\n",
8876 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8877 filter->aslist[FILTER_OUT].name);
8878
8879 /* route-map. */
8880 if (filter->map[RMAP_IN].name)
8881 vty_out(vty,
8882 " Route map for incoming advertisements is %s%s\n",
8883 filter->map[RMAP_IN].map ? "*" : "",
8884 filter->map[RMAP_IN].name);
8885 if (filter->map[RMAP_OUT].name)
8886 vty_out(vty,
8887 " Route map for outgoing advertisements is %s%s\n",
8888 filter->map[RMAP_OUT].map ? "*" : "",
8889 filter->map[RMAP_OUT].name);
8890
8891 /* unsuppress-map */
8892 if (filter->usmap.name)
8893 vty_out(vty,
8894 " Route map for selective unsuppress is %s%s\n",
8895 filter->usmap.map ? "*" : "",
8896 filter->usmap.name);
8897
8898 /* Receive prefix count */
8899 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8900
8901 /* Maximum prefix */
8902 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8903 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8904 p->pmax[afi][safi],
8905 CHECK_FLAG(p->af_flags[afi][safi],
8906 PEER_FLAG_MAX_PREFIX_WARNING)
8907 ? " (warning-only)"
8908 : "");
8909 vty_out(vty, " Threshold for warning message %d%%",
8910 p->pmax_threshold[afi][safi]);
8911 if (p->pmax_restart[afi][safi])
8912 vty_out(vty, ", restart interval %d min",
8913 p->pmax_restart[afi][safi]);
8914 vty_out(vty, "\n");
8915 }
8916
8917 vty_out(vty, "\n");
8918 }
8919}
8920
d7c0a89a 8921static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
d62a17ae 8922 json_object *json)
718e3744 8923{
d62a17ae 8924 struct bgp *bgp;
8925 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8926 char timebuf[BGP_UPTIME_LEN];
8927 char dn_flag[2];
8928 const char *subcode_str;
8929 const char *code_str;
8930 afi_t afi;
8931 safi_t safi;
d7c0a89a
QY
8932 uint16_t i;
8933 uint8_t *msg;
d62a17ae 8934 json_object *json_neigh = NULL;
8935 time_t epoch_tbuf;
718e3744 8936
d62a17ae 8937 bgp = p->bgp;
8938
8939 if (use_json)
8940 json_neigh = json_object_new_object();
8941
8942 memset(dn_flag, '\0', sizeof(dn_flag));
8943 if (!p->conf_if && peer_dynamic_neighbor(p))
8944 dn_flag[0] = '*';
8945
8946 if (!use_json) {
8947 if (p->conf_if) /* Configured interface name. */
8948 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8949 BGP_PEER_SU_UNSPEC(p)
8950 ? "None"
8951 : sockunion2str(&p->su, buf,
8952 SU_ADDRSTRLEN));
8953 else /* Configured IP address. */
8954 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8955 p->host);
8956 }
8957
8958 if (use_json) {
8959 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8960 json_object_string_add(json_neigh, "bgpNeighborAddr",
8961 "none");
8962 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8963 json_object_string_add(
8964 json_neigh, "bgpNeighborAddr",
8965 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8966
8967 json_object_int_add(json_neigh, "remoteAs", p->as);
8968
8969 if (p->change_local_as)
8970 json_object_int_add(json_neigh, "localAs",
8971 p->change_local_as);
8972 else
8973 json_object_int_add(json_neigh, "localAs", p->local_as);
8974
8975 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8976 json_object_boolean_true_add(json_neigh,
8977 "localAsNoPrepend");
8978
8979 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8980 json_object_boolean_true_add(json_neigh,
8981 "localAsReplaceAs");
8982 } else {
8983 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8984 || (p->as_type == AS_INTERNAL))
8985 vty_out(vty, "remote AS %u, ", p->as);
8986 else
8987 vty_out(vty, "remote AS Unspecified, ");
8988 vty_out(vty, "local AS %u%s%s, ",
8989 p->change_local_as ? p->change_local_as : p->local_as,
8990 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8991 ? " no-prepend"
8992 : "",
8993 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8994 ? " replace-as"
8995 : "");
8996 }
8997 /* peer type internal, external, confed-internal or confed-external */
8998 if (p->as == p->local_as) {
8999 if (use_json) {
9000 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9001 json_object_boolean_true_add(
9002 json_neigh, "nbrConfedInternalLink");
9003 else
9004 json_object_boolean_true_add(json_neigh,
9005 "nbrInternalLink");
9006 } else {
9007 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9008 vty_out(vty, "confed-internal link\n");
9009 else
9010 vty_out(vty, "internal link\n");
9011 }
9012 } else {
9013 if (use_json) {
9014 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9015 json_object_boolean_true_add(
9016 json_neigh, "nbrConfedExternalLink");
9017 else
9018 json_object_boolean_true_add(json_neigh,
9019 "nbrExternalLink");
9020 } else {
9021 if (bgp_confederation_peers_check(bgp, p->as))
9022 vty_out(vty, "confed-external link\n");
9023 else
9024 vty_out(vty, "external link\n");
9025 }
9026 }
9027
9028 /* Description. */
9029 if (p->desc) {
9030 if (use_json)
9031 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9032 else
9033 vty_out(vty, " Description: %s\n", p->desc);
9034 }
9035
9036 if (p->hostname) {
9037 if (use_json) {
9038 if (p->hostname)
9039 json_object_string_add(json_neigh, "hostname",
9040 p->hostname);
9041
9042 if (p->domainname)
9043 json_object_string_add(json_neigh, "domainname",
9044 p->domainname);
9045 } else {
9046 if (p->domainname && (p->domainname[0] != '\0'))
9047 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9048 p->domainname);
9049 else
9050 vty_out(vty, "Hostname: %s\n", p->hostname);
9051 }
9052 }
9053
9054 /* Peer-group */
9055 if (p->group) {
9056 if (use_json) {
9057 json_object_string_add(json_neigh, "peerGroup",
9058 p->group->name);
9059
9060 if (dn_flag[0]) {
9061 struct prefix prefix, *range = NULL;
9062
9063 sockunion2hostprefix(&(p->su), &prefix);
9064 range = peer_group_lookup_dynamic_neighbor_range(
9065 p->group, &prefix);
9066
9067 if (range) {
9068 prefix2str(range, buf1, sizeof(buf1));
9069 json_object_string_add(
9070 json_neigh,
9071 "peerSubnetRangeGroup", buf1);
9072 }
9073 }
9074 } else {
9075 vty_out(vty,
9076 " Member of peer-group %s for session parameters\n",
9077 p->group->name);
9078
9079 if (dn_flag[0]) {
9080 struct prefix prefix, *range = NULL;
9081
9082 sockunion2hostprefix(&(p->su), &prefix);
9083 range = peer_group_lookup_dynamic_neighbor_range(
9084 p->group, &prefix);
9085
9086 if (range) {
9087 prefix2str(range, buf1, sizeof(buf1));
9088 vty_out(vty,
9089 " Belongs to the subnet range group: %s\n",
9090 buf1);
9091 }
9092 }
9093 }
9094 }
9095
9096 if (use_json) {
9097 /* Administrative shutdown. */
9098 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9099 json_object_boolean_true_add(json_neigh,
9100 "adminShutDown");
9101
9102 /* BGP Version. */
9103 json_object_int_add(json_neigh, "bgpVersion", 4);
9104 json_object_string_add(
9105 json_neigh, "remoteRouterId",
9106 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9107
9108 /* Confederation */
9109 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9110 && bgp_confederation_peers_check(bgp, p->as))
9111 json_object_boolean_true_add(json_neigh,
9112 "nbrCommonAdmin");
9113
9114 /* Status. */
9115 json_object_string_add(
9116 json_neigh, "bgpState",
9117 lookup_msg(bgp_status_msg, p->status, NULL));
9118
9119 if (p->status == Established) {
9120 time_t uptime;
d62a17ae 9121
9122 uptime = bgp_clock();
9123 uptime -= p->uptime;
d62a17ae 9124 epoch_tbuf = time(NULL) - uptime;
9125
e24be241 9126#if defined(VERSION_TYPE_DEV) && CONFDATE > 20200101
a4d82a8a
PZ
9127 CPP_NOTICE(
9128 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9129#endif
9130 /*
9131 * bgpTimerUp was miliseconds that was accurate
9132 * up to 1 day, then the value returned
9133 * became garbage. So in order to provide
9134 * some level of backwards compatability,
9135 * we still provde the data, but now
9136 * we are returning the correct value
9137 * and also adding a new bgpTimerUpMsec
9138 * which will allow us to deprecate
9139 * this eventually
9140 */
d62a17ae 9141 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9142 uptime * 1000);
d3c7efed
DS
9143 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9144 uptime * 1000);
d62a17ae 9145 json_object_string_add(json_neigh, "bgpTimerUpString",
9146 peer_uptime(p->uptime, timebuf,
9147 BGP_UPTIME_LEN, 0,
9148 NULL));
9149 json_object_int_add(json_neigh,
9150 "bgpTimerUpEstablishedEpoch",
9151 epoch_tbuf);
9152 }
9153
9154 else if (p->status == Active) {
9155 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9156 json_object_string_add(json_neigh, "bgpStateIs",
9157 "passive");
9158 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9159 json_object_string_add(json_neigh, "bgpStateIs",
9160 "passiveNSF");
9161 }
9162
9163 /* read timer */
9164 time_t uptime;
9165 struct tm *tm;
9166
9167 uptime = bgp_clock();
9168 uptime -= p->readtime;
9169 tm = gmtime(&uptime);
9170 json_object_int_add(json_neigh, "bgpTimerLastRead",
9171 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9172 + (tm->tm_hour * 3600000));
9173
9174 uptime = bgp_clock();
9175 uptime -= p->last_write;
9176 tm = gmtime(&uptime);
9177 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9178 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9179 + (tm->tm_hour * 3600000));
9180
9181 uptime = bgp_clock();
9182 uptime -= p->update_time;
9183 tm = gmtime(&uptime);
9184 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9185 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9186 + (tm->tm_hour * 3600000));
9187
9188 /* Configured timer values. */
9189 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9190 p->v_holdtime * 1000);
9191 json_object_int_add(json_neigh,
9192 "bgpTimerKeepAliveIntervalMsecs",
9193 p->v_keepalive * 1000);
9194
d25e4efc 9195 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 9196 json_object_int_add(json_neigh,
9197 "bgpTimerConfiguredHoldTimeMsecs",
9198 p->holdtime * 1000);
9199 json_object_int_add(
9200 json_neigh,
9201 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9202 p->keepalive * 1000);
d25e4efc 9203 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9204 || (bgp->default_keepalive
9205 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9206 json_object_int_add(json_neigh,
9207 "bgpTimerConfiguredHoldTimeMsecs",
9208 bgp->default_holdtime);
9209 json_object_int_add(
9210 json_neigh,
9211 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9212 bgp->default_keepalive);
d62a17ae 9213 }
9214 } else {
9215 /* Administrative shutdown. */
9216 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9217 vty_out(vty, " Administratively shut down\n");
9218
9219 /* BGP Version. */
9220 vty_out(vty, " BGP version 4");
9221 vty_out(vty, ", remote router ID %s\n",
9222 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9223
9224 /* Confederation */
9225 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9226 && bgp_confederation_peers_check(bgp, p->as))
9227 vty_out(vty,
9228 " Neighbor under common administration\n");
9229
9230 /* Status. */
9231 vty_out(vty, " BGP state = %s",
9232 lookup_msg(bgp_status_msg, p->status, NULL));
9233
9234 if (p->status == Established)
9235 vty_out(vty, ", up for %8s",
9236 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9237 0, NULL));
9238
9239 else if (p->status == Active) {
9240 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9241 vty_out(vty, " (passive)");
9242 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9243 vty_out(vty, " (NSF passive)");
9244 }
9245 vty_out(vty, "\n");
9246
9247 /* read timer */
9248 vty_out(vty, " Last read %s",
9249 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9250 NULL));
9251 vty_out(vty, ", Last write %s\n",
9252 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9253 NULL));
9254
9255 /* Configured timer values. */
9256 vty_out(vty,
9257 " Hold time is %d, keepalive interval is %d seconds\n",
9258 p->v_holdtime, p->v_keepalive);
d25e4efc 9259 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 9260 vty_out(vty, " Configured hold time is %d",
9261 p->holdtime);
9262 vty_out(vty, ", keepalive interval is %d seconds\n",
9263 p->keepalive);
d25e4efc 9264 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9265 || (bgp->default_keepalive
9266 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9267 vty_out(vty, " Configured hold time is %d",
9268 bgp->default_holdtime);
9269 vty_out(vty, ", keepalive interval is %d seconds\n",
9270 bgp->default_keepalive);
d62a17ae 9271 }
9272 }
9273 /* Capability. */
9274 if (p->status == Established) {
9275 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9276 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9277 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9278 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9279 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9280 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9281 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9282 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9283 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9284 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9285 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9286 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9287 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9288 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9289 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9290 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9291 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9292 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9293 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9294 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9295 if (use_json) {
9296 json_object *json_cap = NULL;
9297
9298 json_cap = json_object_new_object();
9299
9300 /* AS4 */
9301 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9302 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9303 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9304 && CHECK_FLAG(p->cap,
9305 PEER_CAP_AS4_RCV))
9306 json_object_string_add(
9307 json_cap, "4byteAs",
9308 "advertisedAndReceived");
9309 else if (CHECK_FLAG(p->cap,
9310 PEER_CAP_AS4_ADV))
9311 json_object_string_add(
9312 json_cap, "4byteAs",
9313 "advertised");
9314 else if (CHECK_FLAG(p->cap,
9315 PEER_CAP_AS4_RCV))
9316 json_object_string_add(
9317 json_cap, "4byteAs",
9318 "received");
9319 }
9320
9321 /* AddPath */
9322 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9323 || CHECK_FLAG(p->cap,
9324 PEER_CAP_ADDPATH_ADV)) {
9325 json_object *json_add = NULL;
9326 const char *print_store;
9327
9328 json_add = json_object_new_object();
9329
05c7a1cc
QY
9330 FOREACH_AFI_SAFI (afi, safi) {
9331 json_object *json_sub = NULL;
9332 json_sub =
9333 json_object_new_object();
9334 print_store = afi_safi_print(
9335 afi, safi);
d62a17ae 9336
05c7a1cc
QY
9337 if (CHECK_FLAG(
9338 p->af_cap[afi]
9339 [safi],
9340 PEER_CAP_ADDPATH_AF_TX_ADV)
9341 || CHECK_FLAG(
9342 p->af_cap[afi]
9343 [safi],
9344 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9345 if (CHECK_FLAG(
9346 p->af_cap
9347 [afi]
9348 [safi],
9349 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9350 && CHECK_FLAG(
d62a17ae 9351 p->af_cap
9352 [afi]
9353 [safi],
05c7a1cc
QY
9354 PEER_CAP_ADDPATH_AF_TX_RCV))
9355 json_object_boolean_true_add(
9356 json_sub,
9357 "txAdvertisedAndReceived");
9358 else if (
9359 CHECK_FLAG(
9360 p->af_cap
9361 [afi]
9362 [safi],
9363 PEER_CAP_ADDPATH_AF_TX_ADV))
9364 json_object_boolean_true_add(
9365 json_sub,
9366 "txAdvertised");
9367 else if (
9368 CHECK_FLAG(
9369 p->af_cap
9370 [afi]
9371 [safi],
9372 PEER_CAP_ADDPATH_AF_TX_RCV))
9373 json_object_boolean_true_add(
9374 json_sub,
9375 "txReceived");
9376 }
d62a17ae 9377
05c7a1cc
QY
9378 if (CHECK_FLAG(
9379 p->af_cap[afi]
9380 [safi],
9381 PEER_CAP_ADDPATH_AF_RX_ADV)
9382 || CHECK_FLAG(
9383 p->af_cap[afi]
9384 [safi],
9385 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9386 if (CHECK_FLAG(
9387 p->af_cap
9388 [afi]
9389 [safi],
9390 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9391 && CHECK_FLAG(
d62a17ae 9392 p->af_cap
9393 [afi]
9394 [safi],
9395 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9396 json_object_boolean_true_add(
9397 json_sub,
9398 "rxAdvertisedAndReceived");
9399 else if (
9400 CHECK_FLAG(
9401 p->af_cap
9402 [afi]
9403 [safi],
9404 PEER_CAP_ADDPATH_AF_RX_ADV))
9405 json_object_boolean_true_add(
9406 json_sub,
9407 "rxAdvertised");
9408 else if (
9409 CHECK_FLAG(
9410 p->af_cap
9411 [afi]
9412 [safi],
9413 PEER_CAP_ADDPATH_AF_RX_RCV))
9414 json_object_boolean_true_add(
9415 json_sub,
9416 "rxReceived");
d62a17ae 9417 }
9418
05c7a1cc
QY
9419 if (CHECK_FLAG(
9420 p->af_cap[afi]
9421 [safi],
9422 PEER_CAP_ADDPATH_AF_TX_ADV)
9423 || CHECK_FLAG(
9424 p->af_cap[afi]
9425 [safi],
9426 PEER_CAP_ADDPATH_AF_TX_RCV)
9427 || CHECK_FLAG(
9428 p->af_cap[afi]
9429 [safi],
9430 PEER_CAP_ADDPATH_AF_RX_ADV)
9431 || CHECK_FLAG(
9432 p->af_cap[afi]
9433 [safi],
9434 PEER_CAP_ADDPATH_AF_RX_RCV))
9435 json_object_object_add(
9436 json_add,
9437 print_store,
9438 json_sub);
9439 else
9440 json_object_free(
9441 json_sub);
9442 }
9443
d62a17ae 9444 json_object_object_add(
9445 json_cap, "addPath", json_add);
9446 }
9447
9448 /* Dynamic */
9449 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9450 || CHECK_FLAG(p->cap,
9451 PEER_CAP_DYNAMIC_ADV)) {
9452 if (CHECK_FLAG(p->cap,
9453 PEER_CAP_DYNAMIC_ADV)
9454 && CHECK_FLAG(p->cap,
9455 PEER_CAP_DYNAMIC_RCV))
9456 json_object_string_add(
9457 json_cap, "dynamic",
9458 "advertisedAndReceived");
9459 else if (CHECK_FLAG(
9460 p->cap,
9461 PEER_CAP_DYNAMIC_ADV))
9462 json_object_string_add(
9463 json_cap, "dynamic",
9464 "advertised");
9465 else if (CHECK_FLAG(
9466 p->cap,
9467 PEER_CAP_DYNAMIC_RCV))
9468 json_object_string_add(
9469 json_cap, "dynamic",
9470 "received");
9471 }
9472
9473 /* Extended nexthop */
9474 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9475 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9476 json_object *json_nxt = NULL;
9477 const char *print_store;
9478
9479
9480 if (CHECK_FLAG(p->cap,
9481 PEER_CAP_ENHE_ADV)
9482 && CHECK_FLAG(p->cap,
9483 PEER_CAP_ENHE_RCV))
9484 json_object_string_add(
9485 json_cap,
9486 "extendedNexthop",
9487 "advertisedAndReceived");
9488 else if (CHECK_FLAG(p->cap,
9489 PEER_CAP_ENHE_ADV))
9490 json_object_string_add(
9491 json_cap,
9492 "extendedNexthop",
9493 "advertised");
9494 else if (CHECK_FLAG(p->cap,
9495 PEER_CAP_ENHE_RCV))
9496 json_object_string_add(
9497 json_cap,
9498 "extendedNexthop",
9499 "received");
9500
9501 if (CHECK_FLAG(p->cap,
9502 PEER_CAP_ENHE_RCV)) {
9503 json_nxt =
9504 json_object_new_object();
9505
9506 for (safi = SAFI_UNICAST;
9507 safi < SAFI_MAX; safi++) {
9508 if (CHECK_FLAG(
9509 p->af_cap
9510 [AFI_IP]
9511 [safi],
9512 PEER_CAP_ENHE_AF_RCV)) {
9513 print_store = afi_safi_print(
9514 AFI_IP,
9515 safi);
9516 json_object_string_add(
9517 json_nxt,
9518 print_store,
9519 "recieved");
9520 }
9521 }
9522 json_object_object_add(
9523 json_cap,
9524 "extendedNexthopFamililesByPeer",
9525 json_nxt);
9526 }
9527 }
9528
9529 /* Route Refresh */
9530 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9531 || CHECK_FLAG(p->cap,
9532 PEER_CAP_REFRESH_NEW_RCV)
9533 || CHECK_FLAG(p->cap,
9534 PEER_CAP_REFRESH_OLD_RCV)) {
9535 if (CHECK_FLAG(p->cap,
9536 PEER_CAP_REFRESH_ADV)
9537 && (CHECK_FLAG(
9538 p->cap,
9539 PEER_CAP_REFRESH_NEW_RCV)
9540 || CHECK_FLAG(
9541 p->cap,
9542 PEER_CAP_REFRESH_OLD_RCV))) {
9543 if (CHECK_FLAG(
9544 p->cap,
9545 PEER_CAP_REFRESH_OLD_RCV)
9546 && CHECK_FLAG(
9547 p->cap,
9548 PEER_CAP_REFRESH_NEW_RCV))
9549 json_object_string_add(
9550 json_cap,
9551 "routeRefresh",
9552 "advertisedAndReceivedOldNew");
9553 else {
9554 if (CHECK_FLAG(
9555 p->cap,
9556 PEER_CAP_REFRESH_OLD_RCV))
9557 json_object_string_add(
9558 json_cap,
9559 "routeRefresh",
9560 "advertisedAndReceivedOld");
9561 else
9562 json_object_string_add(
9563 json_cap,
9564 "routeRefresh",
9565 "advertisedAndReceivedNew");
9566 }
9567 } else if (
9568 CHECK_FLAG(
9569 p->cap,
9570 PEER_CAP_REFRESH_ADV))
9571 json_object_string_add(
9572 json_cap,
9573 "routeRefresh",
9574 "advertised");
9575 else if (
9576 CHECK_FLAG(
9577 p->cap,
9578 PEER_CAP_REFRESH_NEW_RCV)
9579 || CHECK_FLAG(
9580 p->cap,
9581 PEER_CAP_REFRESH_OLD_RCV))
9582 json_object_string_add(
9583 json_cap,
9584 "routeRefresh",
9585 "received");
9586 }
9587
9588 /* Multiprotocol Extensions */
9589 json_object *json_multi = NULL;
9590 json_multi = json_object_new_object();
9591
05c7a1cc
QY
9592 FOREACH_AFI_SAFI (afi, safi) {
9593 if (p->afc_adv[afi][safi]
9594 || p->afc_recv[afi][safi]) {
9595 json_object *json_exten = NULL;
9596 json_exten =
9597 json_object_new_object();
9598
d62a17ae 9599 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9600 && p->afc_recv[afi][safi])
9601 json_object_boolean_true_add(
9602 json_exten,
9603 "advertisedAndReceived");
9604 else if (p->afc_adv[afi][safi])
9605 json_object_boolean_true_add(
9606 json_exten,
9607 "advertised");
9608 else if (p->afc_recv[afi][safi])
9609 json_object_boolean_true_add(
9610 json_exten,
9611 "received");
d62a17ae 9612
05c7a1cc
QY
9613 json_object_object_add(
9614 json_multi,
9615 afi_safi_print(afi,
9616 safi),
9617 json_exten);
d62a17ae 9618 }
9619 }
9620 json_object_object_add(
9621 json_cap, "multiprotocolExtensions",
9622 json_multi);
9623
d77114b7 9624 /* Hostname capabilities */
60466a63 9625 json_object *json_hname = NULL;
d77114b7
MK
9626
9627 json_hname = json_object_new_object();
9628
9629 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9630 json_object_string_add(
60466a63
QY
9631 json_hname, "advHostName",
9632 bgp->peer_self->hostname
9633 ? bgp->peer_self
9634 ->hostname
d77114b7
MK
9635 : "n/a");
9636 json_object_string_add(
60466a63
QY
9637 json_hname, "advDomainName",
9638 bgp->peer_self->domainname
9639 ? bgp->peer_self
9640 ->domainname
d77114b7
MK
9641 : "n/a");
9642 }
9643
9644
9645 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9646 json_object_string_add(
60466a63
QY
9647 json_hname, "rcvHostName",
9648 p->hostname ? p->hostname
9649 : "n/a");
d77114b7 9650 json_object_string_add(
60466a63
QY
9651 json_hname, "rcvDomainName",
9652 p->domainname ? p->domainname
9653 : "n/a");
d77114b7
MK
9654 }
9655
60466a63 9656 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9657 json_hname);
9658
d62a17ae 9659 /* Gracefull Restart */
9660 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9661 || CHECK_FLAG(p->cap,
9662 PEER_CAP_RESTART_ADV)) {
9663 if (CHECK_FLAG(p->cap,
9664 PEER_CAP_RESTART_ADV)
9665 && CHECK_FLAG(p->cap,
9666 PEER_CAP_RESTART_RCV))
9667 json_object_string_add(
9668 json_cap,
9669 "gracefulRestart",
9670 "advertisedAndReceived");
9671 else if (CHECK_FLAG(
9672 p->cap,
9673 PEER_CAP_RESTART_ADV))
9674 json_object_string_add(
9675 json_cap,
9676 "gracefulRestartCapability",
9677 "advertised");
9678 else if (CHECK_FLAG(
9679 p->cap,
9680 PEER_CAP_RESTART_RCV))
9681 json_object_string_add(
9682 json_cap,
9683 "gracefulRestartCapability",
9684 "received");
9685
9686 if (CHECK_FLAG(p->cap,
9687 PEER_CAP_RESTART_RCV)) {
9688 int restart_af_count = 0;
9689 json_object *json_restart =
9690 NULL;
9691 json_restart =
9692 json_object_new_object();
9693
9694 json_object_int_add(
9695 json_cap,
9696 "gracefulRestartRemoteTimerMsecs",
9697 p->v_gr_restart * 1000);
9698
05c7a1cc
QY
9699 FOREACH_AFI_SAFI (afi, safi) {
9700 if (CHECK_FLAG(
9701 p->af_cap
9702 [afi]
9703 [safi],
9704 PEER_CAP_RESTART_AF_RCV)) {
9705 json_object *
9706 json_sub =
9707 NULL;
9708 json_sub =
9709 json_object_new_object();
9710
d62a17ae 9711 if (CHECK_FLAG(
9712 p->af_cap
9713 [afi]
9714 [safi],
05c7a1cc
QY
9715 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9716 json_object_boolean_true_add(
9717 json_sub,
9718 "preserved");
9719 restart_af_count++;
9720 json_object_object_add(
9721 json_restart,
9722 afi_safi_print(
9723 afi,
9724 safi),
9725 json_sub);
d62a17ae 9726 }
9727 }
9728 if (!restart_af_count) {
9729 json_object_string_add(
9730 json_cap,
9731 "addressFamiliesByPeer",
9732 "none");
9733 json_object_free(
9734 json_restart);
9735 } else
9736 json_object_object_add(
9737 json_cap,
9738 "addressFamiliesByPeer",
9739 json_restart);
9740 }
9741 }
9742 json_object_object_add(json_neigh,
9743 "neighborCapabilities",
9744 json_cap);
9745 } else {
9746 vty_out(vty, " Neighbor capabilities:\n");
9747
9748 /* AS4 */
9749 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9750 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9751 vty_out(vty, " 4 Byte AS:");
9752 if (CHECK_FLAG(p->cap,
9753 PEER_CAP_AS4_ADV))
9754 vty_out(vty, " advertised");
9755 if (CHECK_FLAG(p->cap,
9756 PEER_CAP_AS4_RCV))
9757 vty_out(vty, " %sreceived",
9758 CHECK_FLAG(
9759 p->cap,
9760 PEER_CAP_AS4_ADV)
9761 ? "and "
9762 : "");
9763 vty_out(vty, "\n");
9764 }
9765
9766 /* AddPath */
9767 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9768 || CHECK_FLAG(p->cap,
9769 PEER_CAP_ADDPATH_ADV)) {
9770 vty_out(vty, " AddPath:\n");
9771
05c7a1cc
QY
9772 FOREACH_AFI_SAFI (afi, safi) {
9773 if (CHECK_FLAG(
9774 p->af_cap[afi]
9775 [safi],
9776 PEER_CAP_ADDPATH_AF_TX_ADV)
9777 || CHECK_FLAG(
9778 p->af_cap[afi]
9779 [safi],
9780 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9781 vty_out(vty,
9782 " %s: TX ",
9783 afi_safi_print(
9784 afi,
9785 safi));
9786
d62a17ae 9787 if (CHECK_FLAG(
9788 p->af_cap
9789 [afi]
9790 [safi],
05c7a1cc 9791 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 9792 vty_out(vty,
05c7a1cc 9793 "advertised %s",
d62a17ae 9794 afi_safi_print(
9795 afi,
9796 safi));
9797
05c7a1cc
QY
9798 if (CHECK_FLAG(
9799 p->af_cap
9800 [afi]
9801 [safi],
9802 PEER_CAP_ADDPATH_AF_TX_RCV))
9803 vty_out(vty,
9804 "%sreceived",
9805 CHECK_FLAG(
9806 p->af_cap
9807 [afi]
9808 [safi],
9809 PEER_CAP_ADDPATH_AF_TX_ADV)
9810 ? " and "
9811 : "");
d62a17ae 9812
05c7a1cc
QY
9813 vty_out(vty, "\n");
9814 }
d62a17ae 9815
05c7a1cc
QY
9816 if (CHECK_FLAG(
9817 p->af_cap[afi]
9818 [safi],
9819 PEER_CAP_ADDPATH_AF_RX_ADV)
9820 || CHECK_FLAG(
9821 p->af_cap[afi]
9822 [safi],
9823 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9824 vty_out(vty,
9825 " %s: RX ",
9826 afi_safi_print(
9827 afi,
9828 safi));
d62a17ae 9829
9830 if (CHECK_FLAG(
9831 p->af_cap
9832 [afi]
9833 [safi],
05c7a1cc 9834 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 9835 vty_out(vty,
05c7a1cc 9836 "advertised %s",
d62a17ae 9837 afi_safi_print(
9838 afi,
9839 safi));
9840
05c7a1cc
QY
9841 if (CHECK_FLAG(
9842 p->af_cap
9843 [afi]
9844 [safi],
9845 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 9846 vty_out(vty,
05c7a1cc
QY
9847 "%sreceived",
9848 CHECK_FLAG(
9849 p->af_cap
9850 [afi]
9851 [safi],
9852 PEER_CAP_ADDPATH_AF_RX_ADV)
9853 ? " and "
9854 : "");
9855
9856 vty_out(vty, "\n");
d62a17ae 9857 }
05c7a1cc 9858 }
d62a17ae 9859 }
9860
9861 /* Dynamic */
9862 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9863 || CHECK_FLAG(p->cap,
9864 PEER_CAP_DYNAMIC_ADV)) {
9865 vty_out(vty, " Dynamic:");
9866 if (CHECK_FLAG(p->cap,
9867 PEER_CAP_DYNAMIC_ADV))
9868 vty_out(vty, " advertised");
9869 if (CHECK_FLAG(p->cap,
9870 PEER_CAP_DYNAMIC_RCV))
9871 vty_out(vty, " %sreceived",
9872 CHECK_FLAG(
9873 p->cap,
9874 PEER_CAP_DYNAMIC_ADV)
9875 ? "and "
9876 : "");
9877 vty_out(vty, "\n");
9878 }
9879
9880 /* Extended nexthop */
9881 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9882 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9883 vty_out(vty, " Extended nexthop:");
9884 if (CHECK_FLAG(p->cap,
9885 PEER_CAP_ENHE_ADV))
9886 vty_out(vty, " advertised");
9887 if (CHECK_FLAG(p->cap,
9888 PEER_CAP_ENHE_RCV))
9889 vty_out(vty, " %sreceived",
9890 CHECK_FLAG(
9891 p->cap,
9892 PEER_CAP_ENHE_ADV)
9893 ? "and "
9894 : "");
9895 vty_out(vty, "\n");
9896
9897 if (CHECK_FLAG(p->cap,
9898 PEER_CAP_ENHE_RCV)) {
9899 vty_out(vty,
9900 " Address families by peer:\n ");
9901 for (safi = SAFI_UNICAST;
9902 safi < SAFI_MAX; safi++)
9903 if (CHECK_FLAG(
9904 p->af_cap
9905 [AFI_IP]
9906 [safi],
9907 PEER_CAP_ENHE_AF_RCV))
9908 vty_out(vty,
9909 " %s\n",
9910 afi_safi_print(
9911 AFI_IP,
9912 safi));
9913 }
9914 }
9915
9916 /* Route Refresh */
9917 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9918 || CHECK_FLAG(p->cap,
9919 PEER_CAP_REFRESH_NEW_RCV)
9920 || CHECK_FLAG(p->cap,
9921 PEER_CAP_REFRESH_OLD_RCV)) {
9922 vty_out(vty, " Route refresh:");
9923 if (CHECK_FLAG(p->cap,
9924 PEER_CAP_REFRESH_ADV))
9925 vty_out(vty, " advertised");
9926 if (CHECK_FLAG(p->cap,
9927 PEER_CAP_REFRESH_NEW_RCV)
9928 || CHECK_FLAG(
9929 p->cap,
9930 PEER_CAP_REFRESH_OLD_RCV))
9931 vty_out(vty, " %sreceived(%s)",
9932 CHECK_FLAG(
9933 p->cap,
9934 PEER_CAP_REFRESH_ADV)
9935 ? "and "
9936 : "",
9937 (CHECK_FLAG(
9938 p->cap,
9939 PEER_CAP_REFRESH_OLD_RCV)
9940 && CHECK_FLAG(
9941 p->cap,
9942 PEER_CAP_REFRESH_NEW_RCV))
9943 ? "old & new"
9944 : CHECK_FLAG(
9945 p->cap,
9946 PEER_CAP_REFRESH_OLD_RCV)
9947 ? "old"
9948 : "new");
9949
9950 vty_out(vty, "\n");
9951 }
9952
9953 /* Multiprotocol Extensions */
05c7a1cc
QY
9954 FOREACH_AFI_SAFI (afi, safi)
9955 if (p->afc_adv[afi][safi]
9956 || p->afc_recv[afi][safi]) {
9957 vty_out(vty,
9958 " Address Family %s:",
9959 afi_safi_print(afi,
9960 safi));
9961 if (p->afc_adv[afi][safi])
d62a17ae 9962 vty_out(vty,
05c7a1cc
QY
9963 " advertised");
9964 if (p->afc_recv[afi][safi])
9965 vty_out(vty,
9966 " %sreceived",
9967 p->afc_adv[afi]
9968 [safi]
9969 ? "and "
9970 : "");
9971 vty_out(vty, "\n");
9972 }
d62a17ae 9973
9974 /* Hostname capability */
60466a63 9975 vty_out(vty, " Hostname Capability:");
d77114b7
MK
9976
9977 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
9978 vty_out(vty,
9979 " advertised (name: %s,domain name: %s)",
60466a63
QY
9980 bgp->peer_self->hostname
9981 ? bgp->peer_self
9982 ->hostname
d77114b7 9983 : "n/a",
60466a63
QY
9984 bgp->peer_self->domainname
9985 ? bgp->peer_self
9986 ->domainname
d77114b7
MK
9987 : "n/a");
9988 } else {
9989 vty_out(vty, " not advertised");
d62a17ae 9990 }
9991
d77114b7 9992 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
9993 vty_out(vty,
9994 " received (name: %s,domain name: %s)",
60466a63
QY
9995 p->hostname ? p->hostname
9996 : "n/a",
9997 p->domainname ? p->domainname
9998 : "n/a");
d77114b7
MK
9999 } else {
10000 vty_out(vty, " not received");
10001 }
10002
10003 vty_out(vty, "\n");
10004
d62a17ae 10005 /* Gracefull Restart */
10006 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10007 || CHECK_FLAG(p->cap,
10008 PEER_CAP_RESTART_ADV)) {
10009 vty_out(vty,
10010 " Graceful Restart Capabilty:");
10011 if (CHECK_FLAG(p->cap,
10012 PEER_CAP_RESTART_ADV))
10013 vty_out(vty, " advertised");
10014 if (CHECK_FLAG(p->cap,
10015 PEER_CAP_RESTART_RCV))
10016 vty_out(vty, " %sreceived",
10017 CHECK_FLAG(
10018 p->cap,
10019 PEER_CAP_RESTART_ADV)
10020 ? "and "
10021 : "");
10022 vty_out(vty, "\n");
10023
10024 if (CHECK_FLAG(p->cap,
10025 PEER_CAP_RESTART_RCV)) {
10026 int restart_af_count = 0;
10027
10028 vty_out(vty,
10029 " Remote Restart timer is %d seconds\n",
10030 p->v_gr_restart);
10031 vty_out(vty,
10032 " Address families by peer:\n ");
10033
05c7a1cc
QY
10034 FOREACH_AFI_SAFI (afi, safi)
10035 if (CHECK_FLAG(
10036 p->af_cap
10037 [afi]
10038 [safi],
10039 PEER_CAP_RESTART_AF_RCV)) {
10040 vty_out(vty,
10041 "%s%s(%s)",
10042 restart_af_count
10043 ? ", "
10044 : "",
10045 afi_safi_print(
10046 afi,
10047 safi),
10048 CHECK_FLAG(
10049 p->af_cap
10050 [afi]
10051 [safi],
10052 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10053 ? "preserved"
10054 : "not preserved");
10055 restart_af_count++;
10056 }
d62a17ae 10057 if (!restart_af_count)
10058 vty_out(vty, "none");
10059 vty_out(vty, "\n");
10060 }
10061 }
10062 }
10063 }
10064 }
10065
10066 /* graceful restart information */
10067 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10068 || p->t_gr_stale) {
10069 json_object *json_grace = NULL;
10070 json_object *json_grace_send = NULL;
10071 json_object *json_grace_recv = NULL;
10072 int eor_send_af_count = 0;
10073 int eor_receive_af_count = 0;
10074
10075 if (use_json) {
10076 json_grace = json_object_new_object();
10077 json_grace_send = json_object_new_object();
10078 json_grace_recv = json_object_new_object();
10079
10080 if (p->status == Established) {
05c7a1cc
QY
10081 FOREACH_AFI_SAFI (afi, safi) {
10082 if (CHECK_FLAG(p->af_sflags[afi][safi],
10083 PEER_STATUS_EOR_SEND)) {
10084 json_object_boolean_true_add(
10085 json_grace_send,
10086 afi_safi_print(afi,
10087 safi));
10088 eor_send_af_count++;
d62a17ae 10089 }
10090 }
05c7a1cc
QY
10091 FOREACH_AFI_SAFI (afi, safi) {
10092 if (CHECK_FLAG(
10093 p->af_sflags[afi][safi],
10094 PEER_STATUS_EOR_RECEIVED)) {
10095 json_object_boolean_true_add(
10096 json_grace_recv,
10097 afi_safi_print(afi,
10098 safi));
10099 eor_receive_af_count++;
d62a17ae 10100 }
10101 }
10102 }
10103
10104 json_object_object_add(json_grace, "endOfRibSend",
10105 json_grace_send);
10106 json_object_object_add(json_grace, "endOfRibRecv",
10107 json_grace_recv);
10108
10109 if (p->t_gr_restart)
10110 json_object_int_add(json_grace,
10111 "gracefulRestartTimerMsecs",
10112 thread_timer_remain_second(
10113 p->t_gr_restart)
10114 * 1000);
10115
10116 if (p->t_gr_stale)
10117 json_object_int_add(
10118 json_grace,
10119 "gracefulStalepathTimerMsecs",
10120 thread_timer_remain_second(
10121 p->t_gr_stale)
10122 * 1000);
10123
10124 json_object_object_add(
10125 json_neigh, "gracefulRestartInfo", json_grace);
10126 } else {
10127 vty_out(vty, " Graceful restart informations:\n");
10128 if (p->status == Established) {
10129 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10130 FOREACH_AFI_SAFI (afi, safi) {
10131 if (CHECK_FLAG(p->af_sflags[afi][safi],
10132 PEER_STATUS_EOR_SEND)) {
10133 vty_out(vty, "%s%s",
10134 eor_send_af_count ? ", "
10135 : "",
10136 afi_safi_print(afi,
10137 safi));
10138 eor_send_af_count++;
d62a17ae 10139 }
10140 }
10141 vty_out(vty, "\n");
10142 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10143 FOREACH_AFI_SAFI (afi, safi) {
10144 if (CHECK_FLAG(
10145 p->af_sflags[afi][safi],
10146 PEER_STATUS_EOR_RECEIVED)) {
10147 vty_out(vty, "%s%s",
10148 eor_receive_af_count
10149 ? ", "
10150 : "",
10151 afi_safi_print(afi,
10152 safi));
10153 eor_receive_af_count++;
d62a17ae 10154 }
10155 }
10156 vty_out(vty, "\n");
10157 }
10158
10159 if (p->t_gr_restart)
10160 vty_out(vty,
10161 " The remaining time of restart timer is %ld\n",
10162 thread_timer_remain_second(
10163 p->t_gr_restart));
10164
10165 if (p->t_gr_stale)
10166 vty_out(vty,
10167 " The remaining time of stalepath timer is %ld\n",
10168 thread_timer_remain_second(
10169 p->t_gr_stale));
10170 }
10171 }
10172 if (use_json) {
10173 json_object *json_stat = NULL;
10174 json_stat = json_object_new_object();
10175 /* Packet counts. */
10176 json_object_int_add(json_stat, "depthInq", 0);
10177 json_object_int_add(json_stat, "depthOutq",
10178 (unsigned long)p->obuf->count);
0112e9e0
QY
10179 json_object_int_add(json_stat, "opensSent",
10180 atomic_load_explicit(&p->open_out,
10181 memory_order_relaxed));
10182 json_object_int_add(json_stat, "opensRecv",
10183 atomic_load_explicit(&p->open_in,
10184 memory_order_relaxed));
d62a17ae 10185 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10186 atomic_load_explicit(&p->notify_out,
10187 memory_order_relaxed));
d62a17ae 10188 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10189 atomic_load_explicit(&p->notify_in,
10190 memory_order_relaxed));
10191 json_object_int_add(json_stat, "updatesSent",
10192 atomic_load_explicit(&p->update_out,
10193 memory_order_relaxed));
10194 json_object_int_add(json_stat, "updatesRecv",
10195 atomic_load_explicit(&p->update_in,
10196 memory_order_relaxed));
d62a17ae 10197 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10198 atomic_load_explicit(&p->keepalive_out,
10199 memory_order_relaxed));
d62a17ae 10200 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10201 atomic_load_explicit(&p->keepalive_in,
10202 memory_order_relaxed));
d62a17ae 10203 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10204 atomic_load_explicit(&p->refresh_out,
10205 memory_order_relaxed));
d62a17ae 10206 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10207 atomic_load_explicit(&p->refresh_in,
10208 memory_order_relaxed));
d62a17ae 10209 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10210 atomic_load_explicit(&p->dynamic_cap_out,
10211 memory_order_relaxed));
d62a17ae 10212 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10213 atomic_load_explicit(&p->dynamic_cap_in,
10214 memory_order_relaxed));
10215 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10216 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10217 json_object_object_add(json_neigh, "messageStats", json_stat);
10218 } else {
10219 /* Packet counts. */
10220 vty_out(vty, " Message statistics:\n");
10221 vty_out(vty, " Inq depth is 0\n");
10222 vty_out(vty, " Outq depth is %lu\n",
10223 (unsigned long)p->obuf->count);
10224 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10225 vty_out(vty, " Opens: %10d %10d\n",
10226 atomic_load_explicit(&p->open_out,
10227 memory_order_relaxed),
10228 atomic_load_explicit(&p->open_in,
10229 memory_order_relaxed));
10230 vty_out(vty, " Notifications: %10d %10d\n",
10231 atomic_load_explicit(&p->notify_out,
10232 memory_order_relaxed),
10233 atomic_load_explicit(&p->notify_in,
10234 memory_order_relaxed));
10235 vty_out(vty, " Updates: %10d %10d\n",
10236 atomic_load_explicit(&p->update_out,
10237 memory_order_relaxed),
10238 atomic_load_explicit(&p->update_in,
10239 memory_order_relaxed));
10240 vty_out(vty, " Keepalives: %10d %10d\n",
10241 atomic_load_explicit(&p->keepalive_out,
10242 memory_order_relaxed),
10243 atomic_load_explicit(&p->keepalive_in,
10244 memory_order_relaxed));
10245 vty_out(vty, " Route Refresh: %10d %10d\n",
10246 atomic_load_explicit(&p->refresh_out,
10247 memory_order_relaxed),
10248 atomic_load_explicit(&p->refresh_in,
10249 memory_order_relaxed));
d62a17ae 10250 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10251 atomic_load_explicit(&p->dynamic_cap_out,
10252 memory_order_relaxed),
10253 atomic_load_explicit(&p->dynamic_cap_in,
10254 memory_order_relaxed));
10255 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10256 PEER_TOTAL_RX(p));
d62a17ae 10257 }
10258
10259 if (use_json) {
10260 /* advertisement-interval */
10261 json_object_int_add(json_neigh,
10262 "minBtwnAdvertisementRunsTimerMsecs",
10263 p->v_routeadv * 1000);
10264
10265 /* Update-source. */
10266 if (p->update_if || p->update_source) {
10267 if (p->update_if)
10268 json_object_string_add(json_neigh,
10269 "updateSource",
10270 p->update_if);
10271 else if (p->update_source)
10272 json_object_string_add(
10273 json_neigh, "updateSource",
10274 sockunion2str(p->update_source, buf1,
10275 SU_ADDRSTRLEN));
10276 }
10277 } else {
10278 /* advertisement-interval */
10279 vty_out(vty,
10280 " Minimum time between advertisement runs is %d seconds\n",
10281 p->v_routeadv);
10282
10283 /* Update-source. */
10284 if (p->update_if || p->update_source) {
10285 vty_out(vty, " Update source is ");
10286 if (p->update_if)
10287 vty_out(vty, "%s", p->update_if);
10288 else if (p->update_source)
10289 vty_out(vty, "%s",
10290 sockunion2str(p->update_source, buf1,
10291 SU_ADDRSTRLEN));
10292 vty_out(vty, "\n");
10293 }
10294
10295 vty_out(vty, "\n");
10296 }
10297
10298 /* Address Family Information */
10299 json_object *json_hold = NULL;
10300
10301 if (use_json)
10302 json_hold = json_object_new_object();
10303
05c7a1cc
QY
10304 FOREACH_AFI_SAFI (afi, safi)
10305 if (p->afc[afi][safi])
10306 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10307 json_hold);
d62a17ae 10308
10309 if (use_json) {
10310 json_object_object_add(json_neigh, "addressFamilyInfo",
10311 json_hold);
10312 json_object_int_add(json_neigh, "connectionsEstablished",
10313 p->established);
10314 json_object_int_add(json_neigh, "connectionsDropped",
10315 p->dropped);
10316 } else
10317 vty_out(vty, " Connections established %d; dropped %d\n",
10318 p->established, p->dropped);
10319
10320 if (!p->last_reset) {
10321 if (use_json)
10322 json_object_string_add(json_neigh, "lastReset",
10323 "never");
10324 else
10325 vty_out(vty, " Last reset never\n");
10326 } else {
10327 if (use_json) {
10328 time_t uptime;
10329 struct tm *tm;
10330
10331 uptime = bgp_clock();
10332 uptime -= p->resettime;
10333 tm = gmtime(&uptime);
10334 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10335 (tm->tm_sec * 1000)
10336 + (tm->tm_min * 60000)
10337 + (tm->tm_hour * 3600000));
10338 json_object_string_add(
10339 json_neigh, "lastResetDueTo",
10340 peer_down_str[(int)p->last_reset]);
10341 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10342 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10343 char errorcodesubcode_hexstr[5];
10344 char errorcodesubcode_str[256];
10345
10346 code_str = bgp_notify_code_str(p->notify.code);
10347 subcode_str = bgp_notify_subcode_str(
10348 p->notify.code, p->notify.subcode);
10349
10350 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10351 p->notify.code, p->notify.subcode);
10352 json_object_string_add(json_neigh,
10353 "lastErrorCodeSubcode",
10354 errorcodesubcode_hexstr);
10355 snprintf(errorcodesubcode_str, 255, "%s%s",
10356 code_str, subcode_str);
10357 json_object_string_add(json_neigh,
10358 "lastNotificationReason",
10359 errorcodesubcode_str);
10360 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10361 && p->notify.code == BGP_NOTIFY_CEASE
10362 && (p->notify.subcode
10363 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10364 || p->notify.subcode
10365 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10366 && p->notify.length) {
10367 char msgbuf[1024];
10368 const char *msg_str;
10369
10370 msg_str = bgp_notify_admin_message(
10371 msgbuf, sizeof(msgbuf),
d7c0a89a 10372 (uint8_t *)p->notify.data,
d62a17ae 10373 p->notify.length);
10374 if (msg_str)
10375 json_object_string_add(
10376 json_neigh,
10377 "lastShutdownDescription",
10378 msg_str);
10379 }
10380 }
10381 } else {
10382 vty_out(vty, " Last reset %s, ",
10383 peer_uptime(p->resettime, timebuf,
10384 BGP_UPTIME_LEN, 0, NULL));
10385
10386 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10387 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10388 code_str = bgp_notify_code_str(p->notify.code);
10389 subcode_str = bgp_notify_subcode_str(
10390 p->notify.code, p->notify.subcode);
10391 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10392 p->last_reset == PEER_DOWN_NOTIFY_SEND
10393 ? "sent"
10394 : "received",
10395 code_str, subcode_str);
10396 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10397 && p->notify.code == BGP_NOTIFY_CEASE
10398 && (p->notify.subcode
10399 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10400 || p->notify.subcode
10401 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10402 && p->notify.length) {
10403 char msgbuf[1024];
10404 const char *msg_str;
10405
10406 msg_str = bgp_notify_admin_message(
10407 msgbuf, sizeof(msgbuf),
d7c0a89a 10408 (uint8_t *)p->notify.data,
d62a17ae 10409 p->notify.length);
10410 if (msg_str)
10411 vty_out(vty,
10412 " Message: \"%s\"\n",
10413 msg_str);
10414 }
10415 } else {
10416 vty_out(vty, "due to %s\n",
10417 peer_down_str[(int)p->last_reset]);
10418 }
10419
10420 if (p->last_reset_cause_size) {
10421 msg = p->last_reset_cause;
10422 vty_out(vty,
10423 " Message received that caused BGP to send a NOTIFICATION:\n ");
10424 for (i = 1; i <= p->last_reset_cause_size;
10425 i++) {
10426 vty_out(vty, "%02X", *msg++);
10427
10428 if (i != p->last_reset_cause_size) {
10429 if (i % 16 == 0) {
10430 vty_out(vty, "\n ");
10431 } else if (i % 4 == 0) {
10432 vty_out(vty, " ");
10433 }
10434 }
10435 }
10436 vty_out(vty, "\n");
10437 }
10438 }
10439 }
10440
10441 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10442 if (use_json)
10443 json_object_boolean_true_add(json_neigh,
10444 "prefixesConfigExceedMax");
10445 else
10446 vty_out(vty,
10447 " Peer had exceeded the max. no. of prefixes configured.\n");
10448
10449 if (p->t_pmax_restart) {
10450 if (use_json) {
10451 json_object_boolean_true_add(
10452 json_neigh, "reducePrefixNumFrom");
10453 json_object_int_add(json_neigh,
10454 "restartInTimerMsec",
10455 thread_timer_remain_second(
10456 p->t_pmax_restart)
10457 * 1000);
10458 } else
10459 vty_out(vty,
10460 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10461 p->host, thread_timer_remain_second(
10462 p->t_pmax_restart));
d62a17ae 10463 } else {
10464 if (use_json)
10465 json_object_boolean_true_add(
10466 json_neigh,
10467 "reducePrefixNumAndClearIpBgp");
10468 else
10469 vty_out(vty,
10470 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10471 p->host);
10472 }
10473 }
10474
10475 /* EBGP Multihop and GTSM */
10476 if (p->sort != BGP_PEER_IBGP) {
10477 if (use_json) {
10478 if (p->gtsm_hops > 0)
10479 json_object_int_add(json_neigh,
10480 "externalBgpNbrMaxHopsAway",
10481 p->gtsm_hops);
10482 else if (p->ttl > 1)
10483 json_object_int_add(json_neigh,
10484 "externalBgpNbrMaxHopsAway",
10485 p->ttl);
10486 } else {
10487 if (p->gtsm_hops > 0)
10488 vty_out(vty,
10489 " External BGP neighbor may be up to %d hops away.\n",
10490 p->gtsm_hops);
10491 else if (p->ttl > 1)
10492 vty_out(vty,
10493 " External BGP neighbor may be up to %d hops away.\n",
10494 p->ttl);
10495 }
10496 } else {
10497 if (p->gtsm_hops > 0) {
10498 if (use_json)
10499 json_object_int_add(json_neigh,
10500 "internalBgpNbrMaxHopsAway",
10501 p->gtsm_hops);
10502 else
10503 vty_out(vty,
10504 " Internal BGP neighbor may be up to %d hops away.\n",
10505 p->gtsm_hops);
10506 }
10507 }
10508
10509 /* Local address. */
10510 if (p->su_local) {
10511 if (use_json) {
10512 json_object_string_add(json_neigh, "hostLocal",
10513 sockunion2str(p->su_local, buf1,
10514 SU_ADDRSTRLEN));
10515 json_object_int_add(json_neigh, "portLocal",
10516 ntohs(p->su_local->sin.sin_port));
10517 } else
10518 vty_out(vty, "Local host: %s, Local port: %d\n",
10519 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10520 ntohs(p->su_local->sin.sin_port));
10521 }
10522
10523 /* Remote address. */
10524 if (p->su_remote) {
10525 if (use_json) {
10526 json_object_string_add(json_neigh, "hostForeign",
10527 sockunion2str(p->su_remote, buf1,
10528 SU_ADDRSTRLEN));
10529 json_object_int_add(json_neigh, "portForeign",
10530 ntohs(p->su_remote->sin.sin_port));
10531 } else
10532 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10533 sockunion2str(p->su_remote, buf1,
10534 SU_ADDRSTRLEN),
10535 ntohs(p->su_remote->sin.sin_port));
10536 }
10537
10538 /* Nexthop display. */
10539 if (p->su_local) {
10540 if (use_json) {
10541 json_object_string_add(json_neigh, "nexthop",
10542 inet_ntop(AF_INET,
10543 &p->nexthop.v4, buf1,
10544 sizeof(buf1)));
10545 json_object_string_add(json_neigh, "nexthopGlobal",
10546 inet_ntop(AF_INET6,
10547 &p->nexthop.v6_global,
10548 buf1, sizeof(buf1)));
10549 json_object_string_add(json_neigh, "nexthopLocal",
10550 inet_ntop(AF_INET6,
10551 &p->nexthop.v6_local,
10552 buf1, sizeof(buf1)));
10553 if (p->shared_network)
10554 json_object_string_add(json_neigh,
10555 "bgpConnection",
10556 "sharedNetwork");
10557 else
10558 json_object_string_add(json_neigh,
10559 "bgpConnection",
10560 "nonSharedNetwork");
10561 } else {
10562 vty_out(vty, "Nexthop: %s\n",
10563 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10564 sizeof(buf1)));
10565 vty_out(vty, "Nexthop global: %s\n",
10566 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10567 sizeof(buf1)));
10568 vty_out(vty, "Nexthop local: %s\n",
10569 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10570 sizeof(buf1)));
10571 vty_out(vty, "BGP connection: %s\n",
10572 p->shared_network ? "shared network"
10573 : "non shared network");
10574 }
10575 }
10576
10577 /* Timer information. */
10578 if (use_json) {
10579 json_object_int_add(json_neigh, "connectRetryTimer",
10580 p->v_connect);
10581 if (p->status == Established && p->rtt)
10582 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10583 p->rtt);
10584 if (p->t_start)
10585 json_object_int_add(
10586 json_neigh, "nextStartTimerDueInMsecs",
10587 thread_timer_remain_second(p->t_start) * 1000);
10588 if (p->t_connect)
10589 json_object_int_add(
10590 json_neigh, "nextConnectTimerDueInMsecs",
10591 thread_timer_remain_second(p->t_connect)
10592 * 1000);
10593 if (p->t_routeadv) {
10594 json_object_int_add(json_neigh, "mraiInterval",
10595 p->v_routeadv);
10596 json_object_int_add(
10597 json_neigh, "mraiTimerExpireInMsecs",
10598 thread_timer_remain_second(p->t_routeadv)
10599 * 1000);
10600 }
10601 if (p->password)
10602 json_object_int_add(json_neigh, "authenticationEnabled",
10603 1);
10604
10605 if (p->t_read)
10606 json_object_string_add(json_neigh, "readThread", "on");
10607 else
10608 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10609
10610 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10611 json_object_string_add(json_neigh, "writeThread", "on");
10612 else
10613 json_object_string_add(json_neigh, "writeThread",
10614 "off");
10615 } else {
10616 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10617 p->v_connect);
10618 if (p->status == Established && p->rtt)
10619 vty_out(vty, "Estimated round trip time: %d ms\n",
10620 p->rtt);
10621 if (p->t_start)
10622 vty_out(vty, "Next start timer due in %ld seconds\n",
10623 thread_timer_remain_second(p->t_start));
10624 if (p->t_connect)
10625 vty_out(vty, "Next connect timer due in %ld seconds\n",
10626 thread_timer_remain_second(p->t_connect));
10627 if (p->t_routeadv)
10628 vty_out(vty,
10629 "MRAI (interval %u) timer expires in %ld seconds\n",
10630 p->v_routeadv,
10631 thread_timer_remain_second(p->t_routeadv));
10632 if (p->password)
10633 vty_out(vty, "Peer Authentication Enabled\n");
10634
10635 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10636 p->t_read ? "on" : "off",
10637 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10638 ? "on"
10639 : "off");
d62a17ae 10640 }
10641
10642 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10643 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10644 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10645
10646 if (!use_json)
10647 vty_out(vty, "\n");
10648
10649 /* BFD information. */
10650 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10651
10652 if (use_json) {
10653 if (p->conf_if) /* Configured interface name. */
10654 json_object_object_add(json, p->conf_if, json_neigh);
10655 else /* Configured IP address. */
10656 json_object_object_add(json, p->host, json_neigh);
10657 }
10658}
10659
10660static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10661 enum show_type type, union sockunion *su,
d7c0a89a 10662 const char *conf_if, uint8_t use_json,
d62a17ae 10663 json_object *json)
10664{
10665 struct listnode *node, *nnode;
10666 struct peer *peer;
10667 int find = 0;
10668
10669 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10670 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10671 continue;
10672
10673 switch (type) {
10674 case show_all:
10675 bgp_show_peer(vty, peer, use_json, json);
10676 break;
10677 case show_peer:
10678 if (conf_if) {
10679 if ((peer->conf_if
10680 && !strcmp(peer->conf_if, conf_if))
10681 || (peer->hostname
10682 && !strcmp(peer->hostname, conf_if))) {
10683 find = 1;
10684 bgp_show_peer(vty, peer, use_json,
10685 json);
10686 }
10687 } else {
10688 if (sockunion_same(&peer->su, su)) {
10689 find = 1;
10690 bgp_show_peer(vty, peer, use_json,
10691 json);
10692 }
10693 }
10694 break;
10695 }
10696 }
10697
10698 if (type == show_peer && !find) {
10699 if (use_json)
10700 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10701 else
88b7d255 10702 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 10703 }
10704
10705 if (use_json) {
996c9314
LB
10706 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10707 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10708 json_object_free(json);
10709 } else {
10710 vty_out(vty, "\n");
10711 }
10712
10713 return CMD_SUCCESS;
10714}
10715
10716static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10717 enum show_type type,
10718 const char *ip_str,
d7c0a89a 10719 uint8_t use_json)
d62a17ae 10720{
0291c246
MK
10721 struct listnode *node, *nnode;
10722 struct bgp *bgp;
71aedaa3 10723 union sockunion su;
0291c246 10724 json_object *json = NULL;
71aedaa3 10725 int ret, is_first = 1;
d62a17ae 10726
10727 if (use_json)
10728 vty_out(vty, "{\n");
10729
10730 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10731 if (use_json) {
10732 if (!(json = json_object_new_object())) {
10733 zlog_err(
10734 "Unable to allocate memory for JSON object");
10735 vty_out(vty,
10736 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10737 return;
10738 }
10739
10740 json_object_int_add(json, "vrfId",
10741 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10742 ? -1
10743 : (int64_t)bgp->vrf_id);
d62a17ae 10744 json_object_string_add(
10745 json, "vrfName",
10746 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10747 ? "Default"
10748 : bgp->name);
10749
10750 if (!is_first)
10751 vty_out(vty, ",\n");
10752 else
10753 is_first = 0;
10754
10755 vty_out(vty, "\"%s\":",
10756 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10757 ? "Default"
10758 : bgp->name);
10759 } else {
10760 vty_out(vty, "\nInstance %s:\n",
10761 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10762 ? "Default"
10763 : bgp->name);
10764 }
71aedaa3
DS
10765
10766 if (type == show_peer) {
10767 ret = str2sockunion(ip_str, &su);
10768 if (ret < 0)
10769 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10770 use_json, json);
10771 else
10772 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10773 use_json, json);
10774 } else {
10775 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10776 use_json, json);
10777 }
d62a17ae 10778 }
10779
10780 if (use_json)
10781 vty_out(vty, "}\n");
10782}
10783
10784static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10785 enum show_type type, const char *ip_str,
d7c0a89a 10786 uint8_t use_json)
d62a17ae 10787{
10788 int ret;
10789 struct bgp *bgp;
10790 union sockunion su;
10791 json_object *json = NULL;
10792
10793 if (name) {
10794 if (strmatch(name, "all")) {
71aedaa3
DS
10795 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10796 use_json);
d62a17ae 10797 return CMD_SUCCESS;
10798 } else {
10799 bgp = bgp_lookup_by_name(name);
10800 if (!bgp) {
10801 if (use_json) {
10802 json = json_object_new_object();
10803 json_object_boolean_true_add(
10804 json, "bgpNoSuchInstance");
10805 vty_out(vty, "%s\n",
10806 json_object_to_json_string_ext(
10807 json,
10808 JSON_C_TO_STRING_PRETTY));
10809 json_object_free(json);
10810 } else
10811 vty_out(vty,
10812 "%% No such BGP instance exist\n");
10813
10814 return CMD_WARNING;
10815 }
10816 }
10817 } else {
10818 bgp = bgp_get_default();
10819 }
10820
10821 if (bgp) {
10822 json = json_object_new_object();
10823 if (ip_str) {
10824 ret = str2sockunion(ip_str, &su);
10825 if (ret < 0)
10826 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10827 use_json, json);
10828 else
10829 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10830 use_json, json);
10831 } else {
10832 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10833 json);
10834 }
10835 json_object_free(json);
10836 }
10837
10838 return CMD_SUCCESS;
4fb25c53
DW
10839}
10840
716b2d8a 10841/* "show [ip] bgp neighbors" commands. */
718e3744 10842DEFUN (show_ip_bgp_neighbors,
10843 show_ip_bgp_neighbors_cmd,
24345e82 10844 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 10845 SHOW_STR
10846 IP_STR
10847 BGP_STR
f2a8972b 10848 BGP_INSTANCE_HELP_STR
8c3deaae
QY
10849 "Address Family\n"
10850 "Address Family\n"
718e3744 10851 "Detailed information on TCP and BGP neighbor connections\n"
10852 "Neighbor to display information about\n"
a80beece 10853 "Neighbor to display information about\n"
91d37724 10854 "Neighbor on BGP configured interface\n"
9973d184 10855 JSON_STR)
718e3744 10856{
d62a17ae 10857 char *vrf = NULL;
10858 char *sh_arg = NULL;
10859 enum show_type sh_type;
718e3744 10860
d7c0a89a 10861 uint8_t uj = use_json(argc, argv);
718e3744 10862
d62a17ae 10863 int idx = 0;
718e3744 10864
d62a17ae 10865 if (argv_find(argv, argc, "view", &idx)
10866 || argv_find(argv, argc, "vrf", &idx))
10867 vrf = argv[idx + 1]->arg;
718e3744 10868
d62a17ae 10869 idx++;
10870 if (argv_find(argv, argc, "A.B.C.D", &idx)
10871 || argv_find(argv, argc, "X:X::X:X", &idx)
10872 || argv_find(argv, argc, "WORD", &idx)) {
10873 sh_type = show_peer;
10874 sh_arg = argv[idx]->arg;
10875 } else
10876 sh_type = show_all;
856ca177 10877
d62a17ae 10878 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10879}
10880
716b2d8a 10881/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10882 paths' and `show ip mbgp paths'. Those functions results are the
10883 same.*/
f412b39a 10884DEFUN (show_ip_bgp_paths,
718e3744 10885 show_ip_bgp_paths_cmd,
46f296b4 10886 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10887 SHOW_STR
10888 IP_STR
10889 BGP_STR
46f296b4 10890 BGP_SAFI_HELP_STR
718e3744 10891 "Path information\n")
10892{
d62a17ae 10893 vty_out(vty, "Address Refcnt Path\n");
10894 aspath_print_all_vty(vty);
10895 return CMD_SUCCESS;
718e3744 10896}
10897
718e3744 10898#include "hash.h"
10899
d62a17ae 10900static void community_show_all_iterator(struct hash_backet *backet,
10901 struct vty *vty)
718e3744 10902{
d62a17ae 10903 struct community *com;
718e3744 10904
d62a17ae 10905 com = (struct community *)backet->data;
3f65c5b1 10906 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 10907 community_str(com, false));
718e3744 10908}
10909
10910/* Show BGP's community internal data. */
f412b39a 10911DEFUN (show_ip_bgp_community_info,
718e3744 10912 show_ip_bgp_community_info_cmd,
bec37ba5 10913 "show [ip] bgp community-info",
718e3744 10914 SHOW_STR
10915 IP_STR
10916 BGP_STR
10917 "List all bgp community information\n")
10918{
d62a17ae 10919 vty_out(vty, "Address Refcnt Community\n");
718e3744 10920
d62a17ae 10921 hash_iterate(community_hash(),
10922 (void (*)(struct hash_backet *,
10923 void *))community_show_all_iterator,
10924 vty);
718e3744 10925
d62a17ae 10926 return CMD_SUCCESS;
718e3744 10927}
10928
d62a17ae 10929static void lcommunity_show_all_iterator(struct hash_backet *backet,
10930 struct vty *vty)
57d187bc 10931{
d62a17ae 10932 struct lcommunity *lcom;
57d187bc 10933
d62a17ae 10934 lcom = (struct lcommunity *)backet->data;
3f65c5b1 10935 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 10936 lcommunity_str(lcom, false));
57d187bc
JS
10937}
10938
10939/* Show BGP's community internal data. */
10940DEFUN (show_ip_bgp_lcommunity_info,
10941 show_ip_bgp_lcommunity_info_cmd,
10942 "show ip bgp large-community-info",
10943 SHOW_STR
10944 IP_STR
10945 BGP_STR
10946 "List all bgp large-community information\n")
10947{
d62a17ae 10948 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 10949
d62a17ae 10950 hash_iterate(lcommunity_hash(),
10951 (void (*)(struct hash_backet *,
10952 void *))lcommunity_show_all_iterator,
10953 vty);
57d187bc 10954
d62a17ae 10955 return CMD_SUCCESS;
57d187bc
JS
10956}
10957
10958
f412b39a 10959DEFUN (show_ip_bgp_attr_info,
718e3744 10960 show_ip_bgp_attr_info_cmd,
bec37ba5 10961 "show [ip] bgp attribute-info",
718e3744 10962 SHOW_STR
10963 IP_STR
10964 BGP_STR
10965 "List all bgp attribute information\n")
10966{
d62a17ae 10967 attr_show_all(vty);
10968 return CMD_SUCCESS;
718e3744 10969}
6b0655a2 10970
53089bec 10971static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10972 afi_t afi, safi_t safi)
10973{
10974 struct bgp *bgp;
10975 struct listnode *node;
10976 char *vname;
10977 char buf1[INET6_ADDRSTRLEN];
10978 char *ecom_str;
10979 vpn_policy_direction_t dir;
10980
10981 if (name) {
10982 bgp = bgp_lookup_by_name(name);
10983 if (!bgp) {
10984 vty_out(vty, "%% No such BGP instance exist\n");
10985 return CMD_WARNING;
10986 }
10987 } else {
10988 bgp = bgp_get_default();
10989 if (!bgp) {
020a3f60
DS
10990 vty_out(vty,
10991 "%% Default BGP instance does not exist\n");
53089bec 10992 return CMD_WARNING;
10993 }
10994 }
10995
10996 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10997 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
020a3f60
DS
10998 vty_out(vty,
10999 "This VRF is not importing %s routes from any other VRF\n",
53089bec 11000 afi_safi_print(afi, safi));
11001 } else {
020a3f60
DS
11002 vty_out(vty,
11003 "This VRF is importing %s routes from the following VRFs:\n",
53089bec 11004 afi_safi_print(afi, safi));
11005 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
11006 vname)) {
11007 vty_out(vty, " %s\n", vname);
11008 }
11009 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11010 ecom_str = ecommunity_ecom2str(
11011 bgp->vpn_policy[afi].rtlist[dir],
11012 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11013 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11014 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11015 }
11016
11017 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11018 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
020a3f60
DS
11019 vty_out(vty,
11020 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11021 afi_safi_print(afi, safi));
11022 } else {
020a3f60
DS
11023 vty_out(vty,
11024 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11025 afi_safi_print(afi, safi));
11026 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
11027 vname)) {
11028 vty_out(vty, " %s\n", vname);
11029 }
11030 vty_out(vty, "RD: %s\n",
11031 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11032 buf1, RD_ADDRSTRLEN));
11033 dir = BGP_VPN_POLICY_DIR_TOVPN;
11034 ecom_str = ecommunity_ecom2str(
11035 bgp->vpn_policy[afi].rtlist[dir],
11036 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11037 vty_out(vty, "Emport RT: %s\n", ecom_str);
11038 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11039 }
11040
11041 return CMD_SUCCESS;
11042}
11043
11044/* "show [ip] bgp route-leak" command. */
11045DEFUN (show_ip_bgp_route_leak,
11046 show_ip_bgp_route_leak_cmd,
11047 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
11048 SHOW_STR
11049 IP_STR
11050 BGP_STR
11051 BGP_INSTANCE_HELP_STR
11052 BGP_AFI_HELP_STR
11053 BGP_SAFI_HELP_STR
11054 "Route leaking information\n")
11055{
11056 char *vrf = NULL;
11057 afi_t afi = AFI_MAX;
11058 safi_t safi = SAFI_MAX;
11059
11060 int idx = 0;
11061
11062 /* show [ip] bgp */
11063 if (argv_find(argv, argc, "ip", &idx)) {
11064 afi = AFI_IP;
11065 safi = SAFI_UNICAST;
11066 }
11067 /* [vrf VIEWVRFNAME] */
11068 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11069 vty_out(vty,
11070 "%% This command is not applicable to BGP views\n");
53089bec 11071 return CMD_WARNING;
11072 }
11073
11074 if (argv_find(argv, argc, "vrf", &idx))
11075 vrf = argv[++idx]->arg;
11076 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11077 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11078 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11079 }
11080
11081 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11082 vty_out(vty,
11083 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11084 return CMD_WARNING;
11085 }
11086
11087 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11088}
11089
d62a17ae 11090static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11091 safi_t safi)
f186de26 11092{
d62a17ae 11093 struct listnode *node, *nnode;
11094 struct bgp *bgp;
f186de26 11095
d62a17ae 11096 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11097 vty_out(vty, "\nInstance %s:\n",
11098 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11099 ? "Default"
11100 : bgp->name);
11101 update_group_show(bgp, afi, safi, vty, 0);
11102 }
f186de26 11103}
11104
d62a17ae 11105static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11106 int safi, uint64_t subgrp_id)
4fb25c53 11107{
d62a17ae 11108 struct bgp *bgp;
4fb25c53 11109
d62a17ae 11110 if (name) {
11111 if (strmatch(name, "all")) {
11112 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11113 return CMD_SUCCESS;
11114 } else {
11115 bgp = bgp_lookup_by_name(name);
11116 }
11117 } else {
11118 bgp = bgp_get_default();
11119 }
4fb25c53 11120
d62a17ae 11121 if (bgp)
11122 update_group_show(bgp, afi, safi, vty, subgrp_id);
11123 return CMD_SUCCESS;
4fb25c53
DW
11124}
11125
8fe8a7f6
DS
11126DEFUN (show_ip_bgp_updgrps,
11127 show_ip_bgp_updgrps_cmd,
c1a44e43 11128 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11129 SHOW_STR
11130 IP_STR
11131 BGP_STR
11132 BGP_INSTANCE_HELP_STR
c9e571b4 11133 BGP_AFI_HELP_STR
9bedbb1e 11134 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11135 "Detailed info about dynamic update groups\n"
11136 "Specific subgroup to display detailed info for\n")
8386ac43 11137{
d62a17ae 11138 char *vrf = NULL;
11139 afi_t afi = AFI_IP6;
11140 safi_t safi = SAFI_UNICAST;
11141 uint64_t subgrp_id = 0;
11142
11143 int idx = 0;
11144
11145 /* show [ip] bgp */
11146 if (argv_find(argv, argc, "ip", &idx))
11147 afi = AFI_IP;
11148 /* [<view|vrf> VIEWVRFNAME] */
11149 if (argv_find(argv, argc, "view", &idx)
11150 || argv_find(argv, argc, "vrf", &idx))
11151 vrf = argv[++idx]->arg;
11152 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11153 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11154 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11155 }
5bf15956 11156
d62a17ae 11157 /* get subgroup id, if provided */
11158 idx = argc - 1;
11159 if (argv[idx]->type == VARIABLE_TKN)
11160 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11161
d62a17ae 11162 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11163}
11164
f186de26 11165DEFUN (show_bgp_instance_all_ipv6_updgrps,
11166 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11167 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11168 SHOW_STR
716b2d8a 11169 IP_STR
f186de26 11170 BGP_STR
11171 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11172 "Detailed info about dynamic update groups\n")
f186de26 11173{
d62a17ae 11174 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11175 return CMD_SUCCESS;
f186de26 11176}
11177
5bf15956
DW
11178DEFUN (show_bgp_updgrps_stats,
11179 show_bgp_updgrps_stats_cmd,
716b2d8a 11180 "show [ip] bgp update-groups statistics",
3f9c7369 11181 SHOW_STR
716b2d8a 11182 IP_STR
3f9c7369 11183 BGP_STR
0c7b1b01 11184 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11185 "Statistics\n")
11186{
d62a17ae 11187 struct bgp *bgp;
3f9c7369 11188
d62a17ae 11189 bgp = bgp_get_default();
11190 if (bgp)
11191 update_group_show_stats(bgp, vty);
3f9c7369 11192
d62a17ae 11193 return CMD_SUCCESS;
3f9c7369
DS
11194}
11195
8386ac43 11196DEFUN (show_bgp_instance_updgrps_stats,
11197 show_bgp_instance_updgrps_stats_cmd,
18c57037 11198 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11199 SHOW_STR
716b2d8a 11200 IP_STR
8386ac43 11201 BGP_STR
11202 BGP_INSTANCE_HELP_STR
0c7b1b01 11203 "Detailed info about dynamic update groups\n"
8386ac43 11204 "Statistics\n")
11205{
d62a17ae 11206 int idx_word = 3;
11207 struct bgp *bgp;
8386ac43 11208
d62a17ae 11209 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11210 if (bgp)
11211 update_group_show_stats(bgp, vty);
8386ac43 11212
d62a17ae 11213 return CMD_SUCCESS;
8386ac43 11214}
11215
d62a17ae 11216static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11217 afi_t afi, safi_t safi,
11218 const char *what, uint64_t subgrp_id)
3f9c7369 11219{
d62a17ae 11220 struct bgp *bgp;
8386ac43 11221
d62a17ae 11222 if (name)
11223 bgp = bgp_lookup_by_name(name);
11224 else
11225 bgp = bgp_get_default();
8386ac43 11226
d62a17ae 11227 if (bgp) {
11228 if (!strcmp(what, "advertise-queue"))
11229 update_group_show_adj_queue(bgp, afi, safi, vty,
11230 subgrp_id);
11231 else if (!strcmp(what, "advertised-routes"))
11232 update_group_show_advertised(bgp, afi, safi, vty,
11233 subgrp_id);
11234 else if (!strcmp(what, "packet-queue"))
11235 update_group_show_packet_queue(bgp, afi, safi, vty,
11236 subgrp_id);
11237 }
3f9c7369
DS
11238}
11239
dc64bdec
QY
11240DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11241 show_ip_bgp_instance_updgrps_adj_s_cmd,
11242 "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",
11243 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11244 BGP_SAFI_HELP_STR
11245 "Detailed info about dynamic update groups\n"
11246 "Specific subgroup to display info for\n"
11247 "Advertisement queue\n"
11248 "Announced routes\n"
11249 "Packet queue\n")
3f9c7369 11250{
dc64bdec
QY
11251 uint64_t subgrp_id = 0;
11252 afi_t afiz;
11253 safi_t safiz;
11254 if (sgid)
11255 subgrp_id = strtoull(sgid, NULL, 10);
11256
11257 if (!ip && !afi)
11258 afiz = AFI_IP6;
11259 if (!ip && afi)
11260 afiz = bgp_vty_afi_from_str(afi);
11261 if (ip && !afi)
11262 afiz = AFI_IP;
11263 if (ip && afi) {
11264 afiz = bgp_vty_afi_from_str(afi);
11265 if (afiz != AFI_IP)
11266 vty_out(vty,
11267 "%% Cannot specify both 'ip' and 'ipv6'\n");
11268 return CMD_WARNING;
11269 }
d62a17ae 11270
dc64bdec 11271 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11272
dc64bdec 11273 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11274 return CMD_SUCCESS;
11275}
11276
d62a17ae 11277static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11278{
11279 struct listnode *node, *nnode;
11280 struct prefix *range;
11281 struct peer *conf;
11282 struct peer *peer;
11283 char buf[PREFIX2STR_BUFFER];
11284 afi_t afi;
11285 safi_t safi;
11286 const char *peer_status;
11287 const char *af_str;
11288 int lr_count;
11289 int dynamic;
11290 int af_cfgd;
11291
11292 conf = group->conf;
11293
11294 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11295 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11296 conf->as);
11297 } else if (conf->as_type == AS_INTERNAL) {
11298 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11299 group->bgp->as);
11300 } else {
11301 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11302 }
f14e6fdb 11303
d62a17ae 11304 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11305 vty_out(vty, " Peer-group type is internal\n");
11306 else
11307 vty_out(vty, " Peer-group type is external\n");
11308
11309 /* Display AFs configured. */
11310 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11311 FOREACH_AFI_SAFI (afi, safi) {
11312 if (conf->afc[afi][safi]) {
11313 af_cfgd = 1;
11314 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11315 }
05c7a1cc 11316 }
d62a17ae 11317 if (!af_cfgd)
11318 vty_out(vty, " none\n");
11319 else
11320 vty_out(vty, "\n");
11321
11322 /* Display listen ranges (for dynamic neighbors), if any */
11323 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11324 if (afi == AFI_IP)
11325 af_str = "IPv4";
11326 else if (afi == AFI_IP6)
11327 af_str = "IPv6";
11328 else
11329 af_str = "???";
11330 lr_count = listcount(group->listen_range[afi]);
11331 if (lr_count) {
11332 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11333 af_str);
11334
11335
11336 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11337 nnode, range)) {
11338 prefix2str(range, buf, sizeof(buf));
11339 vty_out(vty, " %s\n", buf);
11340 }
11341 }
11342 }
f14e6fdb 11343
d62a17ae 11344 /* Display group members and their status */
11345 if (listcount(group->peer)) {
11346 vty_out(vty, " Peer-group members:\n");
11347 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11348 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11349 peer_status = "Idle (Admin)";
11350 else if (CHECK_FLAG(peer->sflags,
11351 PEER_STATUS_PREFIX_OVERFLOW))
11352 peer_status = "Idle (PfxCt)";
11353 else
11354 peer_status = lookup_msg(bgp_status_msg,
11355 peer->status, NULL);
11356
11357 dynamic = peer_dynamic_neighbor(peer);
11358 vty_out(vty, " %s %s %s \n", peer->host,
11359 dynamic ? "(dynamic)" : "", peer_status);
11360 }
11361 }
f14e6fdb 11362
d62a17ae 11363 return CMD_SUCCESS;
11364}
11365
ff9959b0
QY
11366static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11367 const char *group_name)
d62a17ae 11368{
ff9959b0 11369 struct bgp *bgp;
d62a17ae 11370 struct listnode *node, *nnode;
11371 struct peer_group *group;
ff9959b0
QY
11372 bool found = false;
11373
11374 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11375
11376 if (!bgp) {
11377 vty_out(vty, "%% No such BGP instance exists\n");
11378 return CMD_WARNING;
11379 }
d62a17ae 11380
11381 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11382 if (group_name) {
11383 if (strmatch(group->name, group_name)) {
d62a17ae 11384 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11385 found = true;
11386 break;
d62a17ae 11387 }
ff9959b0
QY
11388 } else {
11389 bgp_show_one_peer_group(vty, group);
d62a17ae 11390 }
f14e6fdb 11391 }
f14e6fdb 11392
ff9959b0 11393 if (group_name && !found)
d62a17ae 11394 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11395
d62a17ae 11396 return CMD_SUCCESS;
f14e6fdb
DS
11397}
11398
f14e6fdb
DS
11399DEFUN (show_ip_bgp_peer_groups,
11400 show_ip_bgp_peer_groups_cmd,
18c57037 11401 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11402 SHOW_STR
11403 IP_STR
11404 BGP_STR
8386ac43 11405 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11406 "Detailed information on BGP peer groups\n"
11407 "Peer group name\n")
f14e6fdb 11408{
d62a17ae 11409 char *vrf, *pg;
11410 vrf = pg = NULL;
11411 int idx = 0;
f14e6fdb 11412
a4d82a8a
PZ
11413 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11414 : NULL;
d62a17ae 11415 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11416
ff9959b0 11417 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11418}
3f9c7369 11419
d6e3c605 11420
718e3744 11421/* Redistribute VTY commands. */
11422
718e3744 11423DEFUN (bgp_redistribute_ipv4,
11424 bgp_redistribute_ipv4_cmd,
40d1cbfb 11425 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11426 "Redistribute information from another routing protocol\n"
ab0181ee 11427 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11428{
d62a17ae 11429 VTY_DECLVAR_CONTEXT(bgp, bgp);
11430 int idx_protocol = 1;
11431 int type;
718e3744 11432
d62a17ae 11433 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11434 if (type < 0) {
11435 vty_out(vty, "%% Invalid route type\n");
11436 return CMD_WARNING_CONFIG_FAILED;
11437 }
7f323236 11438
d62a17ae 11439 bgp_redist_add(bgp, AFI_IP, type, 0);
11440 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11441}
11442
d62a17ae 11443ALIAS_HIDDEN(
11444 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11445 "redistribute " FRR_IP_REDIST_STR_BGPD,
11446 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11447
718e3744 11448DEFUN (bgp_redistribute_ipv4_rmap,
11449 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11450 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11451 "Redistribute information from another routing protocol\n"
ab0181ee 11452 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11453 "Route map reference\n"
11454 "Pointer to route-map entries\n")
11455{
d62a17ae 11456 VTY_DECLVAR_CONTEXT(bgp, bgp);
11457 int idx_protocol = 1;
11458 int idx_word = 3;
11459 int type;
11460 struct bgp_redist *red;
718e3744 11461
d62a17ae 11462 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11463 if (type < 0) {
11464 vty_out(vty, "%% Invalid route type\n");
11465 return CMD_WARNING_CONFIG_FAILED;
11466 }
718e3744 11467
d62a17ae 11468 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11469 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11470 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11471}
11472
d62a17ae 11473ALIAS_HIDDEN(
11474 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11475 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11476 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11477 "Route map reference\n"
11478 "Pointer to route-map entries\n")
596c17ba 11479
718e3744 11480DEFUN (bgp_redistribute_ipv4_metric,
11481 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11482 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11483 "Redistribute information from another routing protocol\n"
ab0181ee 11484 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11485 "Metric for redistributed routes\n"
11486 "Default metric\n")
11487{
d62a17ae 11488 VTY_DECLVAR_CONTEXT(bgp, bgp);
11489 int idx_protocol = 1;
11490 int idx_number = 3;
11491 int type;
d7c0a89a 11492 uint32_t metric;
d62a17ae 11493 struct bgp_redist *red;
11494
11495 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11496 if (type < 0) {
11497 vty_out(vty, "%% Invalid route type\n");
11498 return CMD_WARNING_CONFIG_FAILED;
11499 }
11500 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11501
11502 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11503 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11504 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11505}
11506
11507ALIAS_HIDDEN(
11508 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11509 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11510 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11511 "Metric for redistributed routes\n"
11512 "Default metric\n")
596c17ba 11513
718e3744 11514DEFUN (bgp_redistribute_ipv4_rmap_metric,
11515 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11516 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11517 "Redistribute information from another routing protocol\n"
ab0181ee 11518 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11519 "Route map reference\n"
11520 "Pointer to route-map entries\n"
11521 "Metric for redistributed routes\n"
11522 "Default metric\n")
11523{
d62a17ae 11524 VTY_DECLVAR_CONTEXT(bgp, bgp);
11525 int idx_protocol = 1;
11526 int idx_word = 3;
11527 int idx_number = 5;
11528 int type;
d7c0a89a 11529 uint32_t metric;
d62a17ae 11530 struct bgp_redist *red;
11531
11532 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11533 if (type < 0) {
11534 vty_out(vty, "%% Invalid route type\n");
11535 return CMD_WARNING_CONFIG_FAILED;
11536 }
11537 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11538
11539 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11540 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11541 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11542 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11543}
11544
11545ALIAS_HIDDEN(
11546 bgp_redistribute_ipv4_rmap_metric,
11547 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11548 "redistribute " FRR_IP_REDIST_STR_BGPD
11549 " route-map WORD metric (0-4294967295)",
11550 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11551 "Route map reference\n"
11552 "Pointer to route-map entries\n"
11553 "Metric for redistributed routes\n"
11554 "Default metric\n")
596c17ba 11555
718e3744 11556DEFUN (bgp_redistribute_ipv4_metric_rmap,
11557 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11558 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11559 "Redistribute information from another routing protocol\n"
ab0181ee 11560 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11561 "Metric for redistributed routes\n"
11562 "Default metric\n"
11563 "Route map reference\n"
11564 "Pointer to route-map entries\n")
11565{
d62a17ae 11566 VTY_DECLVAR_CONTEXT(bgp, bgp);
11567 int idx_protocol = 1;
11568 int idx_number = 3;
11569 int idx_word = 5;
11570 int type;
d7c0a89a 11571 uint32_t metric;
d62a17ae 11572 struct bgp_redist *red;
11573
11574 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11575 if (type < 0) {
11576 vty_out(vty, "%% Invalid route type\n");
11577 return CMD_WARNING_CONFIG_FAILED;
11578 }
11579 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11580
11581 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11582 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11583 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11584 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11585}
11586
11587ALIAS_HIDDEN(
11588 bgp_redistribute_ipv4_metric_rmap,
11589 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11590 "redistribute " FRR_IP_REDIST_STR_BGPD
11591 " metric (0-4294967295) route-map WORD",
11592 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11593 "Metric for redistributed routes\n"
11594 "Default metric\n"
11595 "Route map reference\n"
11596 "Pointer to route-map entries\n")
596c17ba 11597
7c8ff89e
DS
11598DEFUN (bgp_redistribute_ipv4_ospf,
11599 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11600 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11601 "Redistribute information from another routing protocol\n"
11602 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11603 "Non-main Kernel Routing Table\n"
11604 "Instance ID/Table ID\n")
7c8ff89e 11605{
d62a17ae 11606 VTY_DECLVAR_CONTEXT(bgp, bgp);
11607 int idx_ospf_table = 1;
11608 int idx_number = 2;
d7c0a89a
QY
11609 unsigned short instance;
11610 unsigned short protocol;
7c8ff89e 11611
d62a17ae 11612 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11613
d62a17ae 11614 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11615 protocol = ZEBRA_ROUTE_OSPF;
11616 else
11617 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11618
d62a17ae 11619 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11620 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
11621}
11622
d62a17ae 11623ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11624 "redistribute <ospf|table> (1-65535)",
11625 "Redistribute information from another routing protocol\n"
11626 "Open Shortest Path First (OSPFv2)\n"
11627 "Non-main Kernel Routing Table\n"
11628 "Instance ID/Table ID\n")
596c17ba 11629
7c8ff89e
DS
11630DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11631 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11632 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11633 "Redistribute information from another routing protocol\n"
11634 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11635 "Non-main Kernel Routing Table\n"
11636 "Instance ID/Table ID\n"
7c8ff89e
DS
11637 "Route map reference\n"
11638 "Pointer to route-map entries\n")
11639{
d62a17ae 11640 VTY_DECLVAR_CONTEXT(bgp, bgp);
11641 int idx_ospf_table = 1;
11642 int idx_number = 2;
11643 int idx_word = 4;
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 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11655 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11656 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11657}
11658
11659ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11660 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11661 "redistribute <ospf|table> (1-65535) route-map WORD",
11662 "Redistribute information from another routing protocol\n"
11663 "Open Shortest Path First (OSPFv2)\n"
11664 "Non-main Kernel Routing Table\n"
11665 "Instance ID/Table ID\n"
11666 "Route map reference\n"
11667 "Pointer to route-map entries\n")
596c17ba 11668
7c8ff89e
DS
11669DEFUN (bgp_redistribute_ipv4_ospf_metric,
11670 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 11671 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
11672 "Redistribute information from another routing protocol\n"
11673 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11674 "Non-main Kernel Routing Table\n"
11675 "Instance ID/Table ID\n"
7c8ff89e
DS
11676 "Metric for redistributed routes\n"
11677 "Default metric\n")
11678{
d62a17ae 11679 VTY_DECLVAR_CONTEXT(bgp, bgp);
11680 int idx_ospf_table = 1;
11681 int idx_number = 2;
11682 int idx_number_2 = 4;
d7c0a89a 11683 uint32_t metric;
d62a17ae 11684 struct bgp_redist *red;
d7c0a89a 11685 unsigned short instance;
d62a17ae 11686 int protocol;
11687
11688 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11689 protocol = ZEBRA_ROUTE_OSPF;
11690 else
11691 protocol = ZEBRA_ROUTE_TABLE;
11692
11693 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11694 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11695
11696 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11697 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11698 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11699}
11700
11701ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11702 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11703 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11704 "Redistribute information from another routing protocol\n"
11705 "Open Shortest Path First (OSPFv2)\n"
11706 "Non-main Kernel Routing Table\n"
11707 "Instance ID/Table ID\n"
11708 "Metric for redistributed routes\n"
11709 "Default metric\n")
596c17ba 11710
7c8ff89e
DS
11711DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11712 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 11713 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
11714 "Redistribute information from another routing protocol\n"
11715 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11716 "Non-main Kernel Routing Table\n"
11717 "Instance ID/Table ID\n"
7c8ff89e
DS
11718 "Route map reference\n"
11719 "Pointer to route-map entries\n"
11720 "Metric for redistributed routes\n"
11721 "Default metric\n")
11722{
d62a17ae 11723 VTY_DECLVAR_CONTEXT(bgp, bgp);
11724 int idx_ospf_table = 1;
11725 int idx_number = 2;
11726 int idx_word = 4;
11727 int idx_number_2 = 6;
d7c0a89a 11728 uint32_t metric;
d62a17ae 11729 struct bgp_redist *red;
d7c0a89a 11730 unsigned short instance;
d62a17ae 11731 int protocol;
11732
11733 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11734 protocol = ZEBRA_ROUTE_OSPF;
11735 else
11736 protocol = ZEBRA_ROUTE_TABLE;
11737
11738 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11739 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11740
11741 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11742 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11743 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11744 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11745}
11746
11747ALIAS_HIDDEN(
11748 bgp_redistribute_ipv4_ospf_rmap_metric,
11749 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11750 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11751 "Redistribute information from another routing protocol\n"
11752 "Open Shortest Path First (OSPFv2)\n"
11753 "Non-main Kernel Routing Table\n"
11754 "Instance ID/Table ID\n"
11755 "Route map reference\n"
11756 "Pointer to route-map entries\n"
11757 "Metric for redistributed routes\n"
11758 "Default metric\n")
596c17ba 11759
7c8ff89e
DS
11760DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11761 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 11762 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
11763 "Redistribute information from another routing protocol\n"
11764 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11765 "Non-main Kernel Routing Table\n"
11766 "Instance ID/Table ID\n"
7c8ff89e
DS
11767 "Metric for redistributed routes\n"
11768 "Default metric\n"
11769 "Route map reference\n"
11770 "Pointer to route-map entries\n")
11771{
d62a17ae 11772 VTY_DECLVAR_CONTEXT(bgp, bgp);
11773 int idx_ospf_table = 1;
11774 int idx_number = 2;
11775 int idx_number_2 = 4;
11776 int idx_word = 6;
d7c0a89a 11777 uint32_t metric;
d62a17ae 11778 struct bgp_redist *red;
d7c0a89a 11779 unsigned short instance;
d62a17ae 11780 int protocol;
11781
11782 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11783 protocol = ZEBRA_ROUTE_OSPF;
11784 else
11785 protocol = ZEBRA_ROUTE_TABLE;
11786
11787 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11788 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11789
11790 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11791 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11792 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11793 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11794}
11795
11796ALIAS_HIDDEN(
11797 bgp_redistribute_ipv4_ospf_metric_rmap,
11798 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11799 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11800 "Redistribute information from another routing protocol\n"
11801 "Open Shortest Path First (OSPFv2)\n"
11802 "Non-main Kernel Routing Table\n"
11803 "Instance ID/Table ID\n"
11804 "Metric for redistributed routes\n"
11805 "Default metric\n"
11806 "Route map reference\n"
11807 "Pointer to route-map entries\n")
596c17ba 11808
7c8ff89e
DS
11809DEFUN (no_bgp_redistribute_ipv4_ospf,
11810 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 11811 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
11812 NO_STR
11813 "Redistribute information from another routing protocol\n"
11814 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 11815 "Non-main Kernel Routing Table\n"
31500417
DW
11816 "Instance ID/Table ID\n"
11817 "Metric for redistributed routes\n"
11818 "Default metric\n"
11819 "Route map reference\n"
11820 "Pointer to route-map entries\n")
7c8ff89e 11821{
d62a17ae 11822 VTY_DECLVAR_CONTEXT(bgp, bgp);
11823 int idx_ospf_table = 2;
11824 int idx_number = 3;
d7c0a89a 11825 unsigned short instance;
d62a17ae 11826 int protocol;
11827
11828 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11829 protocol = ZEBRA_ROUTE_OSPF;
11830 else
11831 protocol = ZEBRA_ROUTE_TABLE;
11832
11833 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11834 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11835}
11836
11837ALIAS_HIDDEN(
11838 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11839 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11840 NO_STR
11841 "Redistribute information from another routing protocol\n"
11842 "Open Shortest Path First (OSPFv2)\n"
11843 "Non-main Kernel Routing Table\n"
11844 "Instance ID/Table ID\n"
11845 "Metric for redistributed routes\n"
11846 "Default metric\n"
11847 "Route map reference\n"
11848 "Pointer to route-map entries\n")
596c17ba 11849
718e3744 11850DEFUN (no_bgp_redistribute_ipv4,
11851 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 11852 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11853 NO_STR
11854 "Redistribute information from another routing protocol\n"
3b14d86e 11855 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
11856 "Metric for redistributed routes\n"
11857 "Default metric\n"
11858 "Route map reference\n"
11859 "Pointer to route-map entries\n")
718e3744 11860{
d62a17ae 11861 VTY_DECLVAR_CONTEXT(bgp, bgp);
11862 int idx_protocol = 2;
11863 int type;
11864
11865 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11866 if (type < 0) {
11867 vty_out(vty, "%% Invalid route type\n");
11868 return CMD_WARNING_CONFIG_FAILED;
11869 }
11870 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11871}
11872
11873ALIAS_HIDDEN(
11874 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11875 "no redistribute " FRR_IP_REDIST_STR_BGPD
11876 " [metric (0-4294967295)] [route-map WORD]",
11877 NO_STR
11878 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11879 "Metric for redistributed routes\n"
11880 "Default metric\n"
11881 "Route map reference\n"
11882 "Pointer to route-map entries\n")
596c17ba 11883
718e3744 11884DEFUN (bgp_redistribute_ipv6,
11885 bgp_redistribute_ipv6_cmd,
40d1cbfb 11886 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11887 "Redistribute information from another routing protocol\n"
ab0181ee 11888 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11889{
d62a17ae 11890 VTY_DECLVAR_CONTEXT(bgp, bgp);
11891 int idx_protocol = 1;
11892 int type;
718e3744 11893
d62a17ae 11894 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11895 if (type < 0) {
11896 vty_out(vty, "%% Invalid route type\n");
11897 return CMD_WARNING_CONFIG_FAILED;
11898 }
718e3744 11899
d62a17ae 11900 bgp_redist_add(bgp, AFI_IP6, type, 0);
11901 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11902}
11903
11904DEFUN (bgp_redistribute_ipv6_rmap,
11905 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11906 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11907 "Redistribute information from another routing protocol\n"
ab0181ee 11908 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11909 "Route map reference\n"
11910 "Pointer to route-map entries\n")
11911{
d62a17ae 11912 VTY_DECLVAR_CONTEXT(bgp, bgp);
11913 int idx_protocol = 1;
11914 int idx_word = 3;
11915 int type;
11916 struct bgp_redist *red;
718e3744 11917
d62a17ae 11918 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11919 if (type < 0) {
11920 vty_out(vty, "%% Invalid route type\n");
11921 return CMD_WARNING_CONFIG_FAILED;
11922 }
718e3744 11923
d62a17ae 11924 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11925 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11926 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11927}
11928
11929DEFUN (bgp_redistribute_ipv6_metric,
11930 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11931 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11932 "Redistribute information from another routing protocol\n"
ab0181ee 11933 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11934 "Metric for redistributed routes\n"
11935 "Default metric\n")
11936{
d62a17ae 11937 VTY_DECLVAR_CONTEXT(bgp, bgp);
11938 int idx_protocol = 1;
11939 int idx_number = 3;
11940 int type;
d7c0a89a 11941 uint32_t metric;
d62a17ae 11942 struct bgp_redist *red;
11943
11944 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11945 if (type < 0) {
11946 vty_out(vty, "%% Invalid route type\n");
11947 return CMD_WARNING_CONFIG_FAILED;
11948 }
11949 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11950
d62a17ae 11951 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11952 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11953 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11954}
11955
11956DEFUN (bgp_redistribute_ipv6_rmap_metric,
11957 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11958 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11959 "Redistribute information from another routing protocol\n"
ab0181ee 11960 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11961 "Route map reference\n"
11962 "Pointer to route-map entries\n"
11963 "Metric for redistributed routes\n"
11964 "Default metric\n")
11965{
d62a17ae 11966 VTY_DECLVAR_CONTEXT(bgp, bgp);
11967 int idx_protocol = 1;
11968 int idx_word = 3;
11969 int idx_number = 5;
11970 int type;
d7c0a89a 11971 uint32_t metric;
d62a17ae 11972 struct bgp_redist *red;
11973
11974 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11975 if (type < 0) {
11976 vty_out(vty, "%% Invalid route type\n");
11977 return CMD_WARNING_CONFIG_FAILED;
11978 }
11979 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11980
d62a17ae 11981 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11982 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11983 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11984 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11985}
11986
11987DEFUN (bgp_redistribute_ipv6_metric_rmap,
11988 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11989 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11990 "Redistribute information from another routing protocol\n"
ab0181ee 11991 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11992 "Metric for redistributed routes\n"
11993 "Default metric\n"
11994 "Route map reference\n"
11995 "Pointer to route-map entries\n")
11996{
d62a17ae 11997 VTY_DECLVAR_CONTEXT(bgp, bgp);
11998 int idx_protocol = 1;
11999 int idx_number = 3;
12000 int idx_word = 5;
12001 int type;
d7c0a89a 12002 uint32_t metric;
d62a17ae 12003 struct bgp_redist *red;
12004
12005 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12006 if (type < 0) {
12007 vty_out(vty, "%% Invalid route type\n");
12008 return CMD_WARNING_CONFIG_FAILED;
12009 }
12010 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12011
d62a17ae 12012 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12013 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
12014 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12015 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 12016}
12017
12018DEFUN (no_bgp_redistribute_ipv6,
12019 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 12020 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12021 NO_STR
12022 "Redistribute information from another routing protocol\n"
3b14d86e 12023 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12024 "Metric for redistributed routes\n"
12025 "Default metric\n"
12026 "Route map reference\n"
12027 "Pointer to route-map entries\n")
718e3744 12028{
d62a17ae 12029 VTY_DECLVAR_CONTEXT(bgp, bgp);
12030 int idx_protocol = 2;
12031 int type;
718e3744 12032
d62a17ae 12033 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12034 if (type < 0) {
12035 vty_out(vty, "%% Invalid route type\n");
12036 return CMD_WARNING_CONFIG_FAILED;
12037 }
718e3744 12038
d62a17ae 12039 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12040}
12041
2b791107 12042void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12043 safi_t safi)
d62a17ae 12044{
12045 int i;
12046
12047 /* Unicast redistribution only. */
12048 if (safi != SAFI_UNICAST)
2b791107 12049 return;
d62a17ae 12050
12051 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12052 /* Redistribute BGP does not make sense. */
12053 if (i != ZEBRA_ROUTE_BGP) {
12054 struct list *red_list;
12055 struct listnode *node;
12056 struct bgp_redist *red;
12057
12058 red_list = bgp->redist[afi][i];
12059 if (!red_list)
12060 continue;
12061
12062 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12063 /* "redistribute" configuration. */
12064 vty_out(vty, " redistribute %s",
12065 zebra_route_string(i));
12066 if (red->instance)
12067 vty_out(vty, " %d", red->instance);
12068 if (red->redist_metric_flag)
12069 vty_out(vty, " metric %u",
12070 red->redist_metric);
12071 if (red->rmap.name)
12072 vty_out(vty, " route-map %s",
12073 red->rmap.name);
12074 vty_out(vty, "\n");
12075 }
12076 }
12077 }
718e3744 12078}
6b0655a2 12079
b9c7bc5a
PZ
12080/* This is part of the address-family block (unicast only) */
12081void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12082 afi_t afi)
12083{
b9c7bc5a 12084 int indent = 2;
ddb5b488 12085
bb4f6190
DS
12086 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12087 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12088 bgp->vpn_policy[afi]
12089 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12090
12a844a5
DS
12091 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12092 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12093 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12094 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12095 return;
12096
e70e9f8e
PZ
12097 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12098 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12099
12100 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12101
12102 } else {
12103 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12104 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12105 bgp->vpn_policy[afi].tovpn_label);
12106 }
ddb5b488
PZ
12107 }
12108 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12109 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12110 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12111 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12112 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12113 sizeof(buf)));
12114 }
12115 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12116 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12117
12118 char buf[PREFIX_STRLEN];
12119 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12120 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12121 sizeof(buf))) {
12122
b9c7bc5a
PZ
12123 vty_out(vty, "%*snexthop vpn export %s\n",
12124 indent, "", buf);
ddb5b488
PZ
12125 }
12126 }
12127 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12128 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12129 && ecommunity_cmp(
12130 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12131 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12132
12133 char *b = ecommunity_ecom2str(
12134 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12135 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12136 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12137 XFREE(MTYPE_ECOMMUNITY_STR, b);
12138 } else {
12139 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12140 char *b = ecommunity_ecom2str(
12141 bgp->vpn_policy[afi]
12142 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12143 ECOMMUNITY_FORMAT_ROUTE_MAP,
12144 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12145 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12146 XFREE(MTYPE_ECOMMUNITY_STR, b);
12147 }
12148 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12149 char *b = ecommunity_ecom2str(
12150 bgp->vpn_policy[afi]
12151 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12152 ECOMMUNITY_FORMAT_ROUTE_MAP,
12153 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12154 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12155 XFREE(MTYPE_ECOMMUNITY_STR, b);
12156 }
12157 }
bb4f6190
DS
12158
12159 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12160 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12161 bgp->vpn_policy[afi]
12162 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12163
301ad80a
PG
12164 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12165 char *b = ecommunity_ecom2str(
12166 bgp->vpn_policy[afi]
12167 .import_redirect_rtlist,
12168 ECOMMUNITY_FORMAT_ROUTE_MAP,
12169 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12170
301ad80a
PG
12171 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12172 XFREE(MTYPE_ECOMMUNITY_STR, b);
12173 }
ddb5b488
PZ
12174}
12175
12176
718e3744 12177/* BGP node structure. */
d62a17ae 12178static struct cmd_node bgp_node = {
9d303b37 12179 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12180};
12181
d62a17ae 12182static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12183 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12184};
12185
d62a17ae 12186static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12187 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12188};
12189
d62a17ae 12190static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12191 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12192};
12193
d62a17ae 12194static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12195 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12196};
12197
d62a17ae 12198static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12199 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12200};
12201
d62a17ae 12202static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12203 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12204};
12205
d62a17ae 12206static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12207 "%s(config-router-af)# ", 1};
6b0655a2 12208
d62a17ae 12209static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12210 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12211
d62a17ae 12212static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12213 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12214
d62a17ae 12215static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12216 "%s(config-router-af-vni)# ", 1};
90e60aa7 12217
7c40bf39 12218static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12219 "%s(config-router-af)# ", 1};
12220
12221static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12222 "%s(config-router-af-vpnv6)# ", 1};
12223
d62a17ae 12224static void community_list_vty(void);
1f8ae70b 12225
d62a17ae 12226static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12227{
d62a17ae 12228 struct bgp *bgp;
12229 struct peer *peer;
d62a17ae 12230 struct listnode *lnbgp, *lnpeer;
b8a815e5 12231
d62a17ae 12232 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12233 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12234 /* only provide suggestions on the appropriate input
12235 * token type,
12236 * they'll otherwise show up multiple times */
12237 enum cmd_token_type match_type;
12238 char *name = peer->host;
d48ed3e0 12239
d62a17ae 12240 if (peer->conf_if) {
12241 match_type = VARIABLE_TKN;
12242 name = peer->conf_if;
12243 } else if (strchr(peer->host, ':'))
12244 match_type = IPV6_TKN;
12245 else
12246 match_type = IPV4_TKN;
d48ed3e0 12247
d62a17ae 12248 if (token->type != match_type)
12249 continue;
d48ed3e0 12250
d62a17ae 12251 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12252 }
d62a17ae 12253 }
b8a815e5
DL
12254}
12255
12256static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12257 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12258 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12259 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12260 {.completions = NULL}};
12261
47a306a0
DS
12262static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12263{
12264 struct bgp *bgp;
12265 struct peer_group *group;
12266 struct listnode *lnbgp, *lnpeer;
12267
12268 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12269 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12270 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12271 group->name));
12272 }
12273}
12274
12275static const struct cmd_variable_handler bgp_var_peergroup[] = {
12276 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12277 {.completions = NULL} };
12278
d62a17ae 12279void bgp_vty_init(void)
12280{
12281 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12282 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12283
12284 /* Install bgp top node. */
12285 install_node(&bgp_node, bgp_config_write);
12286 install_node(&bgp_ipv4_unicast_node, NULL);
12287 install_node(&bgp_ipv4_multicast_node, NULL);
12288 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12289 install_node(&bgp_ipv6_unicast_node, NULL);
12290 install_node(&bgp_ipv6_multicast_node, NULL);
12291 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12292 install_node(&bgp_vpnv4_node, NULL);
12293 install_node(&bgp_vpnv6_node, NULL);
12294 install_node(&bgp_evpn_node, NULL);
12295 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12296 install_node(&bgp_flowspecv4_node, NULL);
12297 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12298
12299 /* Install default VTY commands to new nodes. */
12300 install_default(BGP_NODE);
12301 install_default(BGP_IPV4_NODE);
12302 install_default(BGP_IPV4M_NODE);
12303 install_default(BGP_IPV4L_NODE);
12304 install_default(BGP_IPV6_NODE);
12305 install_default(BGP_IPV6M_NODE);
12306 install_default(BGP_IPV6L_NODE);
12307 install_default(BGP_VPNV4_NODE);
12308 install_default(BGP_VPNV6_NODE);
7c40bf39 12309 install_default(BGP_FLOWSPECV4_NODE);
12310 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12311 install_default(BGP_EVPN_NODE);
12312 install_default(BGP_EVPN_VNI_NODE);
12313
12314 /* "bgp multiple-instance" commands. */
12315 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12316 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12317
12318 /* "bgp config-type" commands. */
12319 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12320 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12321
12322 /* bgp route-map delay-timer commands. */
12323 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12324 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12325
12326 /* Dummy commands (Currently not supported) */
12327 install_element(BGP_NODE, &no_synchronization_cmd);
12328 install_element(BGP_NODE, &no_auto_summary_cmd);
12329
12330 /* "router bgp" commands. */
12331 install_element(CONFIG_NODE, &router_bgp_cmd);
12332
12333 /* "no router bgp" commands. */
12334 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12335
12336 /* "bgp router-id" commands. */
12337 install_element(BGP_NODE, &bgp_router_id_cmd);
12338 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12339
12340 /* "bgp cluster-id" commands. */
12341 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12342 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12343
12344 /* "bgp confederation" commands. */
12345 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12346 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12347
12348 /* "bgp confederation peers" commands. */
12349 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12350 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12351
12352 /* bgp max-med command */
12353 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12354 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12355 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12356 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12357 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12358
12359 /* bgp disable-ebgp-connected-nh-check */
12360 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12361 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12362
12363 /* bgp update-delay command */
12364 install_element(BGP_NODE, &bgp_update_delay_cmd);
12365 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12366 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12367
12368 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12369 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12370 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12371 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12372
12373 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12374 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12375
12376 /* "maximum-paths" commands. */
12377 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12378 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12379 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12380 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12381 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12382 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12383 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12384 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12385 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12386 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12387 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12388 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12389 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12390 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12391 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12392
12393 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12394 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12395 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12396 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12397 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12398
12399 /* "timers bgp" commands. */
12400 install_element(BGP_NODE, &bgp_timers_cmd);
12401 install_element(BGP_NODE, &no_bgp_timers_cmd);
12402
12403 /* route-map delay-timer commands - per instance for backwards compat.
12404 */
12405 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12406 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12407
12408 /* "bgp client-to-client reflection" commands */
12409 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12410 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12411
12412 /* "bgp always-compare-med" commands */
12413 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12414 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12415
12416 /* "bgp deterministic-med" commands */
12417 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12418 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12419
12420 /* "bgp graceful-restart" commands */
12421 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12422 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12423 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12424 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12425 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12426 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12427
12428 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12429 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12430
7f323236
DW
12431 /* "bgp graceful-shutdown" commands */
12432 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12433 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12434
d62a17ae 12435 /* "bgp fast-external-failover" commands */
12436 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12437 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12438
12439 /* "bgp enforce-first-as" commands */
12440 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12441 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
12442
12443 /* "bgp bestpath compare-routerid" commands */
12444 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12445 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12446
12447 /* "bgp bestpath as-path ignore" commands */
12448 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12449 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12450
12451 /* "bgp bestpath as-path confed" commands */
12452 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12453 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12454
12455 /* "bgp bestpath as-path multipath-relax" commands */
12456 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12457 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12458
12459 /* "bgp log-neighbor-changes" commands */
12460 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12461 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12462
12463 /* "bgp bestpath med" commands */
12464 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12465 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12466
12467 /* "no bgp default ipv4-unicast" commands. */
12468 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12469 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12470
12471 /* "bgp network import-check" commands. */
12472 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12473 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12474 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12475
12476 /* "bgp default local-preference" commands. */
12477 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12478 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12479
12480 /* bgp default show-hostname */
12481 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12482 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12483
12484 /* "bgp default subgroup-pkt-queue-max" commands. */
12485 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12486 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12487
12488 /* bgp ibgp-allow-policy-mods command */
12489 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12490 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12491
12492 /* "bgp listen limit" commands. */
12493 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12494 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12495
12496 /* "bgp listen range" commands. */
12497 install_element(BGP_NODE, &bgp_listen_range_cmd);
12498 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12499
8175f54a 12500 /* "bgp default shutdown" command */
f26845f9
QY
12501 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12502
d62a17ae 12503 /* "neighbor remote-as" commands. */
12504 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12505 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12506 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12507 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12508 install_element(BGP_NODE,
12509 &neighbor_interface_v6only_config_remote_as_cmd);
12510 install_element(BGP_NODE, &no_neighbor_cmd);
12511 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12512
12513 /* "neighbor peer-group" commands. */
12514 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12515 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12516 install_element(BGP_NODE,
12517 &no_neighbor_interface_peer_group_remote_as_cmd);
12518
12519 /* "neighbor local-as" commands. */
12520 install_element(BGP_NODE, &neighbor_local_as_cmd);
12521 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12522 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12523 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12524
12525 /* "neighbor solo" commands. */
12526 install_element(BGP_NODE, &neighbor_solo_cmd);
12527 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12528
12529 /* "neighbor password" commands. */
12530 install_element(BGP_NODE, &neighbor_password_cmd);
12531 install_element(BGP_NODE, &no_neighbor_password_cmd);
12532
12533 /* "neighbor activate" commands. */
12534 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12535 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12536 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12537 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12538 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12539 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12540 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12541 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12542 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 12543 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12544 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 12545 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12546
12547 /* "no neighbor activate" commands. */
12548 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12549 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12550 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12551 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12552 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12553 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12554 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12555 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12556 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 12557 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12558 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 12559 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12560
12561 /* "neighbor peer-group" set commands. */
12562 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12563 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12564 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12565 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12566 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12567 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12568 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12569 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 12570 install_element(BGP_FLOWSPECV4_NODE,
12571 &neighbor_set_peer_group_hidden_cmd);
12572 install_element(BGP_FLOWSPECV6_NODE,
12573 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 12574
12575 /* "no neighbor peer-group unset" commands. */
12576 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12577 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12578 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12579 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12580 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12581 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12582 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12583 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 12584 install_element(BGP_FLOWSPECV4_NODE,
12585 &no_neighbor_set_peer_group_hidden_cmd);
12586 install_element(BGP_FLOWSPECV6_NODE,
12587 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 12588
12589 /* "neighbor softreconfiguration inbound" commands.*/
12590 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12591 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12592 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12593 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12594 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12595 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12596 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12597 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12598 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12599 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12600 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12601 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12602 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12603 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12604 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12605 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12606 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12607 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 12608 install_element(BGP_FLOWSPECV4_NODE,
12609 &neighbor_soft_reconfiguration_cmd);
12610 install_element(BGP_FLOWSPECV4_NODE,
12611 &no_neighbor_soft_reconfiguration_cmd);
12612 install_element(BGP_FLOWSPECV6_NODE,
12613 &neighbor_soft_reconfiguration_cmd);
12614 install_element(BGP_FLOWSPECV6_NODE,
12615 &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 12616
12617 /* "neighbor attribute-unchanged" commands. */
12618 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12619 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12620 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12621 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12622 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12623 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12624 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12625 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12626 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12627 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12628 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12629 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12630 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12631 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12632 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12633 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12634 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12635 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12636
12637 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12638 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12639
12640 /* "nexthop-local unchanged" commands */
12641 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12642 install_element(BGP_IPV6_NODE,
12643 &no_neighbor_nexthop_local_unchanged_cmd);
12644
12645 /* "neighbor next-hop-self" commands. */
12646 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12647 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12648 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12649 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12650 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12651 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12652 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12653 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12654 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12655 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12656 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12657 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12658 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12659 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12660 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12661 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12662 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12663 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
12664 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12665 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 12666
12667 /* "neighbor next-hop-self force" commands. */
12668 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12669 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12670 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12671 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12672 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12673 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12674 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12675 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12676 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12677 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12678 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12679 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12680 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12681 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12682 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12683 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12684 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12685 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12686
12687 /* "neighbor as-override" commands. */
12688 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12689 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12690 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12691 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12692 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12693 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12694 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12695 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12696 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12697 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12698 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12699 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12700 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12701 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12702 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12703 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12704 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12705 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12706
12707 /* "neighbor remove-private-AS" commands. */
12708 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12709 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12710 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12711 install_element(BGP_NODE,
12712 &no_neighbor_remove_private_as_all_hidden_cmd);
12713 install_element(BGP_NODE,
12714 &neighbor_remove_private_as_replace_as_hidden_cmd);
12715 install_element(BGP_NODE,
12716 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12717 install_element(BGP_NODE,
12718 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12719 install_element(
12720 BGP_NODE,
12721 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12722 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12723 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12724 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12725 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12726 install_element(BGP_IPV4_NODE,
12727 &neighbor_remove_private_as_replace_as_cmd);
12728 install_element(BGP_IPV4_NODE,
12729 &no_neighbor_remove_private_as_replace_as_cmd);
12730 install_element(BGP_IPV4_NODE,
12731 &neighbor_remove_private_as_all_replace_as_cmd);
12732 install_element(BGP_IPV4_NODE,
12733 &no_neighbor_remove_private_as_all_replace_as_cmd);
12734 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12735 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12736 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12737 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12738 install_element(BGP_IPV4M_NODE,
12739 &neighbor_remove_private_as_replace_as_cmd);
12740 install_element(BGP_IPV4M_NODE,
12741 &no_neighbor_remove_private_as_replace_as_cmd);
12742 install_element(BGP_IPV4M_NODE,
12743 &neighbor_remove_private_as_all_replace_as_cmd);
12744 install_element(BGP_IPV4M_NODE,
12745 &no_neighbor_remove_private_as_all_replace_as_cmd);
12746 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12747 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12748 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12749 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12750 install_element(BGP_IPV4L_NODE,
12751 &neighbor_remove_private_as_replace_as_cmd);
12752 install_element(BGP_IPV4L_NODE,
12753 &no_neighbor_remove_private_as_replace_as_cmd);
12754 install_element(BGP_IPV4L_NODE,
12755 &neighbor_remove_private_as_all_replace_as_cmd);
12756 install_element(BGP_IPV4L_NODE,
12757 &no_neighbor_remove_private_as_all_replace_as_cmd);
12758 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12759 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12760 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12761 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12762 install_element(BGP_IPV6_NODE,
12763 &neighbor_remove_private_as_replace_as_cmd);
12764 install_element(BGP_IPV6_NODE,
12765 &no_neighbor_remove_private_as_replace_as_cmd);
12766 install_element(BGP_IPV6_NODE,
12767 &neighbor_remove_private_as_all_replace_as_cmd);
12768 install_element(BGP_IPV6_NODE,
12769 &no_neighbor_remove_private_as_all_replace_as_cmd);
12770 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12771 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12772 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12773 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12774 install_element(BGP_IPV6M_NODE,
12775 &neighbor_remove_private_as_replace_as_cmd);
12776 install_element(BGP_IPV6M_NODE,
12777 &no_neighbor_remove_private_as_replace_as_cmd);
12778 install_element(BGP_IPV6M_NODE,
12779 &neighbor_remove_private_as_all_replace_as_cmd);
12780 install_element(BGP_IPV6M_NODE,
12781 &no_neighbor_remove_private_as_all_replace_as_cmd);
12782 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12783 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12784 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12785 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12786 install_element(BGP_IPV6L_NODE,
12787 &neighbor_remove_private_as_replace_as_cmd);
12788 install_element(BGP_IPV6L_NODE,
12789 &no_neighbor_remove_private_as_replace_as_cmd);
12790 install_element(BGP_IPV6L_NODE,
12791 &neighbor_remove_private_as_all_replace_as_cmd);
12792 install_element(BGP_IPV6L_NODE,
12793 &no_neighbor_remove_private_as_all_replace_as_cmd);
12794 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12795 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12796 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12797 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12798 install_element(BGP_VPNV4_NODE,
12799 &neighbor_remove_private_as_replace_as_cmd);
12800 install_element(BGP_VPNV4_NODE,
12801 &no_neighbor_remove_private_as_replace_as_cmd);
12802 install_element(BGP_VPNV4_NODE,
12803 &neighbor_remove_private_as_all_replace_as_cmd);
12804 install_element(BGP_VPNV4_NODE,
12805 &no_neighbor_remove_private_as_all_replace_as_cmd);
12806 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12807 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12808 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12809 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12810 install_element(BGP_VPNV6_NODE,
12811 &neighbor_remove_private_as_replace_as_cmd);
12812 install_element(BGP_VPNV6_NODE,
12813 &no_neighbor_remove_private_as_replace_as_cmd);
12814 install_element(BGP_VPNV6_NODE,
12815 &neighbor_remove_private_as_all_replace_as_cmd);
12816 install_element(BGP_VPNV6_NODE,
12817 &no_neighbor_remove_private_as_all_replace_as_cmd);
12818
12819 /* "neighbor send-community" commands.*/
12820 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12821 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12822 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12823 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12824 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12825 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12826 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12827 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12828 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12829 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12830 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12831 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12832 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12833 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12834 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12835 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12836 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12837 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12838 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12839 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12840 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12841 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12842 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12843 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12844 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12845 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12846 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12847 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12848 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12849 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12850 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12851 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12852 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12853 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12854 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12855 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12856
12857 /* "neighbor route-reflector" commands.*/
12858 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12859 install_element(BGP_NODE,
12860 &no_neighbor_route_reflector_client_hidden_cmd);
12861 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12862 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12863 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12864 install_element(BGP_IPV4M_NODE,
12865 &no_neighbor_route_reflector_client_cmd);
12866 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12867 install_element(BGP_IPV4L_NODE,
12868 &no_neighbor_route_reflector_client_cmd);
12869 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12870 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12871 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12872 install_element(BGP_IPV6M_NODE,
12873 &no_neighbor_route_reflector_client_cmd);
12874 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12875 install_element(BGP_IPV6L_NODE,
12876 &no_neighbor_route_reflector_client_cmd);
12877 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12878 install_element(BGP_VPNV4_NODE,
12879 &no_neighbor_route_reflector_client_cmd);
12880 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12881 install_element(BGP_VPNV6_NODE,
12882 &no_neighbor_route_reflector_client_cmd);
7c40bf39 12883 install_element(BGP_FLOWSPECV4_NODE,
12884 &neighbor_route_reflector_client_cmd);
12885 install_element(BGP_FLOWSPECV4_NODE,
12886 &no_neighbor_route_reflector_client_cmd);
12887 install_element(BGP_FLOWSPECV6_NODE,
12888 &neighbor_route_reflector_client_cmd);
12889 install_element(BGP_FLOWSPECV6_NODE,
12890 &no_neighbor_route_reflector_client_cmd);
d62a17ae 12891 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12892 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12893
12894 /* "neighbor route-server" commands.*/
12895 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12896 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12897 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12898 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12899 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12900 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12901 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12902 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12903 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12904 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12905 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12906 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12907 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12908 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12909 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12910 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12911 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12912 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 12913 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12914 install_element(BGP_FLOWSPECV4_NODE,
12915 &no_neighbor_route_server_client_cmd);
12916 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12917 install_element(BGP_FLOWSPECV6_NODE,
12918 &no_neighbor_route_server_client_cmd);
d62a17ae 12919
12920 /* "neighbor addpath-tx-all-paths" commands.*/
12921 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12922 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12923 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12924 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12925 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12926 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12927 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12928 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12929 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12930 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12931 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12932 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12933 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12934 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12935 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12936 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12937 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12938 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12939
12940 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12941 install_element(BGP_NODE,
12942 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12943 install_element(BGP_NODE,
12944 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12945 install_element(BGP_IPV4_NODE,
12946 &neighbor_addpath_tx_bestpath_per_as_cmd);
12947 install_element(BGP_IPV4_NODE,
12948 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12949 install_element(BGP_IPV4M_NODE,
12950 &neighbor_addpath_tx_bestpath_per_as_cmd);
12951 install_element(BGP_IPV4M_NODE,
12952 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12953 install_element(BGP_IPV4L_NODE,
12954 &neighbor_addpath_tx_bestpath_per_as_cmd);
12955 install_element(BGP_IPV4L_NODE,
12956 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12957 install_element(BGP_IPV6_NODE,
12958 &neighbor_addpath_tx_bestpath_per_as_cmd);
12959 install_element(BGP_IPV6_NODE,
12960 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12961 install_element(BGP_IPV6M_NODE,
12962 &neighbor_addpath_tx_bestpath_per_as_cmd);
12963 install_element(BGP_IPV6M_NODE,
12964 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12965 install_element(BGP_IPV6L_NODE,
12966 &neighbor_addpath_tx_bestpath_per_as_cmd);
12967 install_element(BGP_IPV6L_NODE,
12968 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12969 install_element(BGP_VPNV4_NODE,
12970 &neighbor_addpath_tx_bestpath_per_as_cmd);
12971 install_element(BGP_VPNV4_NODE,
12972 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12973 install_element(BGP_VPNV6_NODE,
12974 &neighbor_addpath_tx_bestpath_per_as_cmd);
12975 install_element(BGP_VPNV6_NODE,
12976 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12977
12978 /* "neighbor passive" commands. */
12979 install_element(BGP_NODE, &neighbor_passive_cmd);
12980 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12981
12982
12983 /* "neighbor shutdown" commands. */
12984 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12985 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12986 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12987 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12988
12989 /* "neighbor capability extended-nexthop" commands.*/
12990 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12991 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12992
12993 /* "neighbor capability orf prefix-list" commands.*/
12994 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12995 install_element(BGP_NODE,
12996 &no_neighbor_capability_orf_prefix_hidden_cmd);
12997 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12998 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12999 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13000 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13001 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13002 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13003 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13004 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13005 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13006 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13007 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13008 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13009
13010 /* "neighbor capability dynamic" commands.*/
13011 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13012 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13013
13014 /* "neighbor dont-capability-negotiate" commands. */
13015 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13016 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13017
13018 /* "neighbor ebgp-multihop" commands. */
13019 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13020 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13021 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13022
13023 /* "neighbor disable-connected-check" commands. */
13024 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13025 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13026
47cbc09b
PM
13027 /* "neighbor enforce-first-as" commands. */
13028 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13029 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13030
d62a17ae 13031 /* "neighbor description" commands. */
13032 install_element(BGP_NODE, &neighbor_description_cmd);
13033 install_element(BGP_NODE, &no_neighbor_description_cmd);
13034
13035 /* "neighbor update-source" commands. "*/
13036 install_element(BGP_NODE, &neighbor_update_source_cmd);
13037 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13038
13039 /* "neighbor default-originate" commands. */
13040 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13041 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13042 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13043 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13044 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13045 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13046 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13047 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13048 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13049 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13050 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13051 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13052 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13053 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13054 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13055 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13056 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13057 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13058 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13059 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13060 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13061
13062 /* "neighbor port" commands. */
13063 install_element(BGP_NODE, &neighbor_port_cmd);
13064 install_element(BGP_NODE, &no_neighbor_port_cmd);
13065
13066 /* "neighbor weight" commands. */
13067 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13068 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13069
13070 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13071 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13072 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13073 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13074 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13075 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13076 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13077 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13078 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13079 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13080 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13081 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13082 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13083 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13084 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13085 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13086
13087 /* "neighbor override-capability" commands. */
13088 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13089 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13090
13091 /* "neighbor strict-capability-match" commands. */
13092 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13093 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13094
13095 /* "neighbor timers" commands. */
13096 install_element(BGP_NODE, &neighbor_timers_cmd);
13097 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13098
13099 /* "neighbor timers connect" commands. */
13100 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13101 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13102
13103 /* "neighbor advertisement-interval" commands. */
13104 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13105 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13106
13107 /* "neighbor interface" commands. */
13108 install_element(BGP_NODE, &neighbor_interface_cmd);
13109 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13110
13111 /* "neighbor distribute" commands. */
13112 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13113 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13114 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13115 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13116 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13117 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13118 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13119 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13120 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13121 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13122 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13123 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13124 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13125 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13126 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13127 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13128 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13129 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13130
13131 /* "neighbor prefix-list" commands. */
13132 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13133 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13134 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13135 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13136 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13137 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13138 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13139 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13140 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13141 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13142 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13143 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13144 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13145 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13146 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13147 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13148 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13149 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13150 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13151 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13152 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13153 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13154
13155 /* "neighbor filter-list" commands. */
13156 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13157 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13158 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13159 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13160 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13161 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13162 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13163 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13164 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13165 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13166 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13167 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13168 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13169 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13170 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13171 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13172 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13173 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13174 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13175 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13176 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13177 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13178
13179 /* "neighbor route-map" commands. */
13180 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13181 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13182 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13183 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13184 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13185 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13186 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13187 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13188 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13189 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13190 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13191 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13192 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13193 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13194 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13195 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13196 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13197 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13198 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13199 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13200 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13201 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13202 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13203 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13204
13205 /* "neighbor unsuppress-map" commands. */
13206 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13207 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13208 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13209 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13210 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13211 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13212 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13213 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13214 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13215 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13216 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13217 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13218 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13219 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13220 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13221 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13222 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13223 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13224
13225 /* "neighbor maximum-prefix" commands. */
13226 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13227 install_element(BGP_NODE,
13228 &neighbor_maximum_prefix_threshold_hidden_cmd);
13229 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13230 install_element(BGP_NODE,
13231 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13232 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13233 install_element(BGP_NODE,
13234 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13235 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13236 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13237 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13238 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13239 install_element(BGP_IPV4_NODE,
13240 &neighbor_maximum_prefix_threshold_warning_cmd);
13241 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13242 install_element(BGP_IPV4_NODE,
13243 &neighbor_maximum_prefix_threshold_restart_cmd);
13244 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13245 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13246 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13247 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13248 install_element(BGP_IPV4M_NODE,
13249 &neighbor_maximum_prefix_threshold_warning_cmd);
13250 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13251 install_element(BGP_IPV4M_NODE,
13252 &neighbor_maximum_prefix_threshold_restart_cmd);
13253 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13254 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13255 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13256 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13257 install_element(BGP_IPV4L_NODE,
13258 &neighbor_maximum_prefix_threshold_warning_cmd);
13259 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13260 install_element(BGP_IPV4L_NODE,
13261 &neighbor_maximum_prefix_threshold_restart_cmd);
13262 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13263 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13264 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13265 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13266 install_element(BGP_IPV6_NODE,
13267 &neighbor_maximum_prefix_threshold_warning_cmd);
13268 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13269 install_element(BGP_IPV6_NODE,
13270 &neighbor_maximum_prefix_threshold_restart_cmd);
13271 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13272 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13273 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13274 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13275 install_element(BGP_IPV6M_NODE,
13276 &neighbor_maximum_prefix_threshold_warning_cmd);
13277 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13278 install_element(BGP_IPV6M_NODE,
13279 &neighbor_maximum_prefix_threshold_restart_cmd);
13280 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13281 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13282 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13283 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13284 install_element(BGP_IPV6L_NODE,
13285 &neighbor_maximum_prefix_threshold_warning_cmd);
13286 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13287 install_element(BGP_IPV6L_NODE,
13288 &neighbor_maximum_prefix_threshold_restart_cmd);
13289 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13290 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13291 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13292 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13293 install_element(BGP_VPNV4_NODE,
13294 &neighbor_maximum_prefix_threshold_warning_cmd);
13295 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13296 install_element(BGP_VPNV4_NODE,
13297 &neighbor_maximum_prefix_threshold_restart_cmd);
13298 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13299 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13300 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13301 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13302 install_element(BGP_VPNV6_NODE,
13303 &neighbor_maximum_prefix_threshold_warning_cmd);
13304 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13305 install_element(BGP_VPNV6_NODE,
13306 &neighbor_maximum_prefix_threshold_restart_cmd);
13307 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13308
13309 /* "neighbor allowas-in" */
13310 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13311 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13312 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13313 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13314 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13315 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13316 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13317 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13318 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13319 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13320 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13321 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13322 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13323 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13324 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13325 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13326 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13327 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13328 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13329 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13330
13331 /* address-family commands. */
13332 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13333 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13334#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13335 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13336 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13337#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13338
d62a17ae 13339 install_element(BGP_NODE, &address_family_evpn_cmd);
13340
13341 /* "exit-address-family" command. */
13342 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13343 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13344 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13345 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13346 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13347 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13348 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13349 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13350 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13351 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13352 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13353
13354 /* "clear ip bgp commands" */
13355 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13356
13357 /* clear ip bgp prefix */
13358 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13359 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13360 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13361
13362 /* "show [ip] bgp summary" commands. */
13363 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
d62a17ae 13364 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13365 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13366 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13367 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13368 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13369
13370 /* "show [ip] bgp neighbors" commands. */
13371 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13372
13373 /* "show [ip] bgp peer-group" commands. */
13374 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13375
13376 /* "show [ip] bgp paths" commands. */
13377 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13378
13379 /* "show [ip] bgp community" commands. */
13380 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13381
13382 /* "show ip bgp large-community" commands. */
13383 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13384 /* "show [ip] bgp attribute-info" commands. */
13385 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13386 /* "show [ip] bgp route-leak" command */
13387 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13388
13389 /* "redistribute" commands. */
13390 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13391 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13392 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13393 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13394 install_element(BGP_NODE,
13395 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13396 install_element(BGP_NODE,
13397 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13398 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13399 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13400 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13401 install_element(BGP_NODE,
13402 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13403 install_element(BGP_NODE,
13404 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13405 install_element(BGP_NODE,
13406 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13407 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13408 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13409 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13410 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13411 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13412 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13413 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13414 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13415 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13416 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13417 install_element(BGP_IPV4_NODE,
13418 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13419 install_element(BGP_IPV4_NODE,
13420 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13421 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13422 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13423 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13424 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13425 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13426 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13427
b9c7bc5a
PZ
13428 /* import|export vpn [route-map WORD] */
13429 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13430 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13431
12a844a5
DS
13432 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13433 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13434
d62a17ae 13435 /* ttl_security commands */
13436 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13437 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13438
13439 /* "show [ip] bgp memory" commands. */
13440 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13441
acf71666
MK
13442 /* "show bgp martian next-hop" */
13443 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13444
d62a17ae 13445 /* "show [ip] bgp views" commands. */
13446 install_element(VIEW_NODE, &show_bgp_views_cmd);
13447
13448 /* "show [ip] bgp vrfs" commands. */
13449 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13450
13451 /* Community-list. */
13452 community_list_vty();
ddb5b488
PZ
13453
13454 /* vpn-policy commands */
b9c7bc5a
PZ
13455 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13456 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13457 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13458 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13459 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13460 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13461 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13462 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13463 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13464 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
13465 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13466 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 13467
301ad80a
PG
13468 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13469 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13470
b9c7bc5a
PZ
13471 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13472 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13473 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13474 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13475 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13476 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13477 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13478 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13479 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13480 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
13481 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13482 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 13483}
6b0655a2 13484
718e3744 13485#include "memory.h"
13486#include "bgp_regex.h"
13487#include "bgp_clist.h"
13488#include "bgp_ecommunity.h"
13489
13490/* VTY functions. */
13491
13492/* Direction value to string conversion. */
d62a17ae 13493static const char *community_direct_str(int direct)
13494{
13495 switch (direct) {
13496 case COMMUNITY_DENY:
13497 return "deny";
13498 case COMMUNITY_PERMIT:
13499 return "permit";
13500 default:
13501 return "unknown";
13502 }
718e3744 13503}
13504
13505/* Display error string. */
d62a17ae 13506static void community_list_perror(struct vty *vty, int ret)
13507{
13508 switch (ret) {
13509 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13510 vty_out(vty, "%% Can't find community-list\n");
13511 break;
13512 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13513 vty_out(vty, "%% Malformed community-list value\n");
13514 break;
13515 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13516 vty_out(vty,
13517 "%% Community name conflict, previously defined as standard community\n");
13518 break;
13519 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13520 vty_out(vty,
13521 "%% Community name conflict, previously defined as expanded community\n");
13522 break;
13523 }
718e3744 13524}
13525
5bf15956
DW
13526/* "community-list" keyword help string. */
13527#define COMMUNITY_LIST_STR "Add a community list entry\n"
13528
5bf15956 13529/* ip community-list standard */
718e3744 13530DEFUN (ip_community_list_standard,
13531 ip_community_list_standard_cmd,
e961923c 13532 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13533 IP_STR
13534 COMMUNITY_LIST_STR
13535 "Community list number (standard)\n"
5bf15956 13536 "Add an standard community-list entry\n"
718e3744 13537 "Community list name\n"
13538 "Specify community to reject\n"
13539 "Specify community to accept\n"
13540 COMMUNITY_VAL_STR)
13541{
d62a17ae 13542 char *cl_name_or_number = NULL;
13543 int direct = 0;
13544 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13545
d62a17ae 13546 int idx = 0;
13547 argv_find(argv, argc, "(1-99)", &idx);
13548 argv_find(argv, argc, "WORD", &idx);
13549 cl_name_or_number = argv[idx]->arg;
13550 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13551 : COMMUNITY_DENY;
13552 argv_find(argv, argc, "AA:NN", &idx);
13553 char *str = argv_concat(argv, argc, idx);
42f914d4 13554
d62a17ae 13555 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13556 style);
42f914d4 13557
d62a17ae 13558 XFREE(MTYPE_TMP, str);
42f914d4 13559
d62a17ae 13560 if (ret < 0) {
13561 /* Display error string. */
13562 community_list_perror(vty, ret);
13563 return CMD_WARNING_CONFIG_FAILED;
13564 }
42f914d4 13565
d62a17ae 13566 return CMD_SUCCESS;
718e3744 13567}
13568
fee6e4e4 13569DEFUN (no_ip_community_list_standard_all,
13570 no_ip_community_list_standard_all_cmd,
e961923c 13571 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13572 NO_STR
13573 IP_STR
13574 COMMUNITY_LIST_STR
13575 "Community list number (standard)\n"
5bf15956
DW
13576 "Add an standard community-list entry\n"
13577 "Community list name\n"
718e3744 13578 "Specify community to reject\n"
13579 "Specify community to accept\n"
13580 COMMUNITY_VAL_STR)
13581{
d62a17ae 13582 char *cl_name_or_number = NULL;
13583 int direct = 0;
13584 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13585
d62a17ae 13586 int idx = 0;
13587 argv_find(argv, argc, "(1-99)", &idx);
13588 argv_find(argv, argc, "WORD", &idx);
13589 cl_name_or_number = argv[idx]->arg;
13590 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13591 : COMMUNITY_DENY;
13592 argv_find(argv, argc, "AA:NN", &idx);
13593 char *str = argv_concat(argv, argc, idx);
42f914d4 13594
d62a17ae 13595 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13596 direct, style);
42f914d4 13597
d62a17ae 13598 XFREE(MTYPE_TMP, str);
daf9ddbb 13599
d62a17ae 13600 if (ret < 0) {
13601 community_list_perror(vty, ret);
13602 return CMD_WARNING_CONFIG_FAILED;
13603 }
42f914d4 13604
d62a17ae 13605 return CMD_SUCCESS;
718e3744 13606}
13607
5bf15956
DW
13608/* ip community-list expanded */
13609DEFUN (ip_community_list_expanded_all,
13610 ip_community_list_expanded_all_cmd,
42f914d4 13611 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13612 IP_STR
13613 COMMUNITY_LIST_STR
13614 "Community list number (expanded)\n"
5bf15956 13615 "Add an expanded community-list entry\n"
718e3744 13616 "Community list name\n"
13617 "Specify community to reject\n"
13618 "Specify community to accept\n"
13619 COMMUNITY_VAL_STR)
13620{
d62a17ae 13621 char *cl_name_or_number = NULL;
13622 int direct = 0;
13623 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13624
d62a17ae 13625 int idx = 0;
13626 argv_find(argv, argc, "(100-500)", &idx);
13627 argv_find(argv, argc, "WORD", &idx);
13628 cl_name_or_number = argv[idx]->arg;
13629 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13630 : COMMUNITY_DENY;
13631 argv_find(argv, argc, "AA:NN", &idx);
13632 char *str = argv_concat(argv, argc, idx);
42f914d4 13633
d62a17ae 13634 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13635 style);
42f914d4 13636
d62a17ae 13637 XFREE(MTYPE_TMP, str);
42f914d4 13638
d62a17ae 13639 if (ret < 0) {
13640 /* Display error string. */
13641 community_list_perror(vty, ret);
13642 return CMD_WARNING_CONFIG_FAILED;
13643 }
42f914d4 13644
d62a17ae 13645 return CMD_SUCCESS;
718e3744 13646}
13647
5bf15956
DW
13648DEFUN (no_ip_community_list_expanded_all,
13649 no_ip_community_list_expanded_all_cmd,
42f914d4 13650 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13651 NO_STR
13652 IP_STR
13653 COMMUNITY_LIST_STR
5bf15956
DW
13654 "Community list number (expanded)\n"
13655 "Add an expanded community-list entry\n"
718e3744 13656 "Community list name\n"
13657 "Specify community to reject\n"
13658 "Specify community to accept\n"
5bf15956 13659 COMMUNITY_VAL_STR)
718e3744 13660{
d62a17ae 13661 char *cl_name_or_number = NULL;
13662 int direct = 0;
13663 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13664
d62a17ae 13665 int idx = 0;
13666 argv_find(argv, argc, "(100-500)", &idx);
13667 argv_find(argv, argc, "WORD", &idx);
13668 cl_name_or_number = argv[idx]->arg;
13669 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13670 : COMMUNITY_DENY;
13671 argv_find(argv, argc, "AA:NN", &idx);
13672 char *str = argv_concat(argv, argc, idx);
42f914d4 13673
d62a17ae 13674 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13675 direct, style);
42f914d4 13676
d62a17ae 13677 XFREE(MTYPE_TMP, str);
daf9ddbb 13678
d62a17ae 13679 if (ret < 0) {
13680 community_list_perror(vty, ret);
13681 return CMD_WARNING_CONFIG_FAILED;
13682 }
42f914d4 13683
d62a17ae 13684 return CMD_SUCCESS;
718e3744 13685}
13686
8d9b8ed9
PM
13687/* Return configuration string of community-list entry. */
13688static const char *community_list_config_str(struct community_entry *entry)
13689{
13690 const char *str;
13691
13692 if (entry->any)
13693 str = "";
13694 else {
13695 if (entry->style == COMMUNITY_LIST_STANDARD)
13696 str = community_str(entry->u.com, false);
13697 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13698 str = lcommunity_str(entry->u.lcom, false);
13699 else
13700 str = entry->config;
13701 }
13702 return str;
13703}
13704
d62a17ae 13705static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 13706{
d62a17ae 13707 struct community_entry *entry;
718e3744 13708
d62a17ae 13709 for (entry = list->head; entry; entry = entry->next) {
13710 if (entry == list->head) {
13711 if (all_digit(list->name))
13712 vty_out(vty, "Community %s list %s\n",
13713 entry->style == COMMUNITY_LIST_STANDARD
13714 ? "standard"
13715 : "(expanded) access",
13716 list->name);
13717 else
13718 vty_out(vty, "Named Community %s list %s\n",
13719 entry->style == COMMUNITY_LIST_STANDARD
13720 ? "standard"
13721 : "expanded",
13722 list->name);
13723 }
13724 if (entry->any)
13725 vty_out(vty, " %s\n",
13726 community_direct_str(entry->direct));
13727 else
13728 vty_out(vty, " %s %s\n",
13729 community_direct_str(entry->direct),
8d9b8ed9 13730 community_list_config_str(entry));
d62a17ae 13731 }
718e3744 13732}
13733
13734DEFUN (show_ip_community_list,
13735 show_ip_community_list_cmd,
13736 "show ip community-list",
13737 SHOW_STR
13738 IP_STR
13739 "List community-list\n")
13740{
d62a17ae 13741 struct community_list *list;
13742 struct community_list_master *cm;
718e3744 13743
d62a17ae 13744 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13745 if (!cm)
13746 return CMD_SUCCESS;
718e3744 13747
d62a17ae 13748 for (list = cm->num.head; list; list = list->next)
13749 community_list_show(vty, list);
718e3744 13750
d62a17ae 13751 for (list = cm->str.head; list; list = list->next)
13752 community_list_show(vty, list);
718e3744 13753
d62a17ae 13754 return CMD_SUCCESS;
718e3744 13755}
13756
13757DEFUN (show_ip_community_list_arg,
13758 show_ip_community_list_arg_cmd,
6147e2c6 13759 "show ip community-list <(1-500)|WORD>",
718e3744 13760 SHOW_STR
13761 IP_STR
13762 "List community-list\n"
13763 "Community-list number\n"
13764 "Community-list name\n")
13765{
d62a17ae 13766 int idx_comm_list = 3;
13767 struct community_list *list;
718e3744 13768
d62a17ae 13769 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13770 COMMUNITY_LIST_MASTER);
13771 if (!list) {
13772 vty_out(vty, "%% Can't find community-list\n");
13773 return CMD_WARNING;
13774 }
718e3744 13775
d62a17ae 13776 community_list_show(vty, list);
718e3744 13777
d62a17ae 13778 return CMD_SUCCESS;
718e3744 13779}
6b0655a2 13780
57d187bc
JS
13781/*
13782 * Large Community code.
13783 */
d62a17ae 13784static int lcommunity_list_set_vty(struct vty *vty, int argc,
13785 struct cmd_token **argv, int style,
13786 int reject_all_digit_name)
13787{
13788 int ret;
13789 int direct;
13790 char *str;
13791 int idx = 0;
13792 char *cl_name;
13793
13794 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13795 : COMMUNITY_DENY;
13796
13797 /* All digit name check. */
13798 idx = 0;
13799 argv_find(argv, argc, "WORD", &idx);
13800 argv_find(argv, argc, "(1-99)", &idx);
13801 argv_find(argv, argc, "(100-500)", &idx);
13802 cl_name = argv[idx]->arg;
13803 if (reject_all_digit_name && all_digit(cl_name)) {
13804 vty_out(vty, "%% Community name cannot have all digits\n");
13805 return CMD_WARNING_CONFIG_FAILED;
13806 }
13807
13808 idx = 0;
13809 argv_find(argv, argc, "AA:BB:CC", &idx);
13810 argv_find(argv, argc, "LINE", &idx);
13811 /* Concat community string argument. */
13812 if (idx)
13813 str = argv_concat(argv, argc, idx);
13814 else
13815 str = NULL;
13816
13817 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13818
13819 /* Free temporary community list string allocated by
13820 argv_concat(). */
13821 if (str)
13822 XFREE(MTYPE_TMP, str);
13823
13824 if (ret < 0) {
13825 community_list_perror(vty, ret);
13826 return CMD_WARNING_CONFIG_FAILED;
13827 }
13828 return CMD_SUCCESS;
13829}
13830
13831static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13832 struct cmd_token **argv, int style)
13833{
13834 int ret;
13835 int direct = 0;
13836 char *str = NULL;
13837 int idx = 0;
13838
13839 argv_find(argv, argc, "permit", &idx);
13840 argv_find(argv, argc, "deny", &idx);
13841
13842 if (idx) {
13843 /* Check the list direct. */
13844 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13845 direct = COMMUNITY_PERMIT;
13846 else
13847 direct = COMMUNITY_DENY;
13848
13849 idx = 0;
13850 argv_find(argv, argc, "LINE", &idx);
13851 argv_find(argv, argc, "AA:AA:NN", &idx);
13852 /* Concat community string argument. */
13853 str = argv_concat(argv, argc, idx);
13854 }
13855
13856 idx = 0;
13857 argv_find(argv, argc, "(1-99)", &idx);
13858 argv_find(argv, argc, "(100-500)", &idx);
13859 argv_find(argv, argc, "WORD", &idx);
13860
13861 /* Unset community list. */
13862 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13863 style);
13864
13865 /* Free temporary community list string allocated by
13866 argv_concat(). */
13867 if (str)
13868 XFREE(MTYPE_TMP, str);
13869
13870 if (ret < 0) {
13871 community_list_perror(vty, ret);
13872 return CMD_WARNING_CONFIG_FAILED;
13873 }
13874
13875 return CMD_SUCCESS;
57d187bc
JS
13876}
13877
13878/* "large-community-list" keyword help string. */
13879#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13880#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13881
13882DEFUN (ip_lcommunity_list_standard,
13883 ip_lcommunity_list_standard_cmd,
52951b63
DS
13884 "ip large-community-list (1-99) <deny|permit>",
13885 IP_STR
13886 LCOMMUNITY_LIST_STR
13887 "Large Community list number (standard)\n"
13888 "Specify large community to reject\n"
7111c1a0 13889 "Specify large community to accept\n")
52951b63 13890{
d62a17ae 13891 return lcommunity_list_set_vty(vty, argc, argv,
13892 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
13893}
13894
13895DEFUN (ip_lcommunity_list_standard1,
13896 ip_lcommunity_list_standard1_cmd,
13897 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
13898 IP_STR
13899 LCOMMUNITY_LIST_STR
13900 "Large Community list number (standard)\n"
13901 "Specify large community to reject\n"
13902 "Specify large community to accept\n"
13903 LCOMMUNITY_VAL_STR)
13904{
d62a17ae 13905 return lcommunity_list_set_vty(vty, argc, argv,
13906 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
13907}
13908
13909DEFUN (ip_lcommunity_list_expanded,
13910 ip_lcommunity_list_expanded_cmd,
13911 "ip large-community-list (100-500) <deny|permit> LINE...",
13912 IP_STR
13913 LCOMMUNITY_LIST_STR
13914 "Large Community list number (expanded)\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, 0);
57d187bc
JS
13921}
13922
13923DEFUN (ip_lcommunity_list_name_standard,
13924 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
13925 "ip large-community-list standard WORD <deny|permit>",
13926 IP_STR
13927 LCOMMUNITY_LIST_STR
13928 "Specify standard large-community-list\n"
13929 "Large Community list name\n"
13930 "Specify large community to reject\n"
13931 "Specify large community to accept\n")
13932{
d62a17ae 13933 return lcommunity_list_set_vty(vty, argc, argv,
13934 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
13935}
13936
13937DEFUN (ip_lcommunity_list_name_standard1,
13938 ip_lcommunity_list_name_standard1_cmd,
13939 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
13940 IP_STR
13941 LCOMMUNITY_LIST_STR
13942 "Specify standard large-community-list\n"
13943 "Large Community list name\n"
13944 "Specify large community to reject\n"
13945 "Specify large community to accept\n"
13946 LCOMMUNITY_VAL_STR)
13947{
d62a17ae 13948 return lcommunity_list_set_vty(vty, argc, argv,
13949 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
13950}
13951
13952DEFUN (ip_lcommunity_list_name_expanded,
13953 ip_lcommunity_list_name_expanded_cmd,
13954 "ip large-community-list expanded WORD <deny|permit> LINE...",
13955 IP_STR
13956 LCOMMUNITY_LIST_STR
13957 "Specify expanded large-community-list\n"
13958 "Large Community list name\n"
13959 "Specify large community to reject\n"
13960 "Specify large community to accept\n"
13961 "An ordered list as a regular-expression\n")
13962{
d62a17ae 13963 return lcommunity_list_set_vty(vty, argc, argv,
13964 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
13965}
13966
13967DEFUN (no_ip_lcommunity_list_standard_all,
13968 no_ip_lcommunity_list_standard_all_cmd,
13969 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13970 NO_STR
13971 IP_STR
13972 LCOMMUNITY_LIST_STR
13973 "Large Community list number (standard)\n"
13974 "Large Community list number (expanded)\n"
13975 "Large Community list name\n")
13976{
d62a17ae 13977 return lcommunity_list_unset_vty(vty, argc, argv,
13978 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13979}
13980
13981DEFUN (no_ip_lcommunity_list_name_expanded_all,
13982 no_ip_lcommunity_list_name_expanded_all_cmd,
13983 "no ip large-community-list expanded WORD",
13984 NO_STR
13985 IP_STR
13986 LCOMMUNITY_LIST_STR
13987 "Specify expanded large-community-list\n"
13988 "Large Community list name\n")
13989{
d62a17ae 13990 return lcommunity_list_unset_vty(vty, argc, argv,
13991 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13992}
13993
13994DEFUN (no_ip_lcommunity_list_standard,
13995 no_ip_lcommunity_list_standard_cmd,
13996 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13997 NO_STR
13998 IP_STR
13999 LCOMMUNITY_LIST_STR
14000 "Large Community list number (standard)\n"
14001 "Specify large community to reject\n"
14002 "Specify large community to accept\n"
14003 LCOMMUNITY_VAL_STR)
14004{
d62a17ae 14005 return lcommunity_list_unset_vty(vty, argc, argv,
14006 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14007}
14008
14009DEFUN (no_ip_lcommunity_list_expanded,
14010 no_ip_lcommunity_list_expanded_cmd,
14011 "no ip large-community-list (100-500) <deny|permit> LINE...",
14012 NO_STR
14013 IP_STR
14014 LCOMMUNITY_LIST_STR
14015 "Large Community list number (expanded)\n"
14016 "Specify large community to reject\n"
14017 "Specify large community to accept\n"
14018 "An ordered list as a regular-expression\n")
14019{
d62a17ae 14020 return lcommunity_list_unset_vty(vty, argc, argv,
14021 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14022}
14023
14024DEFUN (no_ip_lcommunity_list_name_standard,
14025 no_ip_lcommunity_list_name_standard_cmd,
14026 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14027 NO_STR
14028 IP_STR
14029 LCOMMUNITY_LIST_STR
14030 "Specify standard large-community-list\n"
14031 "Large Community list name\n"
14032 "Specify large community to reject\n"
14033 "Specify large community to accept\n"
14034 LCOMMUNITY_VAL_STR)
14035{
d62a17ae 14036 return lcommunity_list_unset_vty(vty, argc, argv,
14037 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14038}
14039
14040DEFUN (no_ip_lcommunity_list_name_expanded,
14041 no_ip_lcommunity_list_name_expanded_cmd,
14042 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14043 NO_STR
14044 IP_STR
14045 LCOMMUNITY_LIST_STR
14046 "Specify expanded large-community-list\n"
14047 "Large community list name\n"
14048 "Specify large community to reject\n"
14049 "Specify large community to accept\n"
14050 "An ordered list as a regular-expression\n")
14051{
d62a17ae 14052 return lcommunity_list_unset_vty(vty, argc, argv,
14053 LARGE_COMMUNITY_LIST_EXPANDED);
14054}
14055
14056static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14057{
14058 struct community_entry *entry;
14059
14060 for (entry = list->head; entry; entry = entry->next) {
14061 if (entry == list->head) {
14062 if (all_digit(list->name))
14063 vty_out(vty, "Large community %s list %s\n",
14064 entry->style == EXTCOMMUNITY_LIST_STANDARD
14065 ? "standard"
14066 : "(expanded) access",
14067 list->name);
14068 else
14069 vty_out(vty,
14070 "Named large community %s list %s\n",
14071 entry->style == EXTCOMMUNITY_LIST_STANDARD
14072 ? "standard"
14073 : "expanded",
14074 list->name);
14075 }
14076 if (entry->any)
14077 vty_out(vty, " %s\n",
14078 community_direct_str(entry->direct));
14079 else
14080 vty_out(vty, " %s %s\n",
14081 community_direct_str(entry->direct),
8d9b8ed9 14082 community_list_config_str(entry));
d62a17ae 14083 }
57d187bc
JS
14084}
14085
14086DEFUN (show_ip_lcommunity_list,
14087 show_ip_lcommunity_list_cmd,
14088 "show ip large-community-list",
14089 SHOW_STR
14090 IP_STR
14091 "List large-community list\n")
14092{
d62a17ae 14093 struct community_list *list;
14094 struct community_list_master *cm;
57d187bc 14095
d62a17ae 14096 cm = community_list_master_lookup(bgp_clist,
14097 LARGE_COMMUNITY_LIST_MASTER);
14098 if (!cm)
14099 return CMD_SUCCESS;
57d187bc 14100
d62a17ae 14101 for (list = cm->num.head; list; list = list->next)
14102 lcommunity_list_show(vty, list);
57d187bc 14103
d62a17ae 14104 for (list = cm->str.head; list; list = list->next)
14105 lcommunity_list_show(vty, list);
57d187bc 14106
d62a17ae 14107 return CMD_SUCCESS;
57d187bc
JS
14108}
14109
14110DEFUN (show_ip_lcommunity_list_arg,
14111 show_ip_lcommunity_list_arg_cmd,
14112 "show ip large-community-list <(1-500)|WORD>",
14113 SHOW_STR
14114 IP_STR
14115 "List large-community list\n"
14116 "large-community-list number\n"
14117 "large-community-list name\n")
14118{
d62a17ae 14119 struct community_list *list;
57d187bc 14120
d62a17ae 14121 list = community_list_lookup(bgp_clist, argv[3]->arg,
14122 LARGE_COMMUNITY_LIST_MASTER);
14123 if (!list) {
14124 vty_out(vty, "%% Can't find extcommunity-list\n");
14125 return CMD_WARNING;
14126 }
57d187bc 14127
d62a17ae 14128 lcommunity_list_show(vty, list);
57d187bc 14129
d62a17ae 14130 return CMD_SUCCESS;
57d187bc
JS
14131}
14132
718e3744 14133/* "extcommunity-list" keyword help string. */
14134#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14135#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14136
14137DEFUN (ip_extcommunity_list_standard,
14138 ip_extcommunity_list_standard_cmd,
e961923c 14139 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14140 IP_STR
14141 EXTCOMMUNITY_LIST_STR
14142 "Extended Community list number (standard)\n"
718e3744 14143 "Specify standard extcommunity-list\n"
5bf15956 14144 "Community list name\n"
718e3744 14145 "Specify community to reject\n"
14146 "Specify community to accept\n"
14147 EXTCOMMUNITY_VAL_STR)
14148{
d62a17ae 14149 int style = EXTCOMMUNITY_LIST_STANDARD;
14150 int direct = 0;
14151 char *cl_number_or_name = NULL;
42f914d4 14152
d62a17ae 14153 int idx = 0;
14154 argv_find(argv, argc, "(1-99)", &idx);
14155 argv_find(argv, argc, "WORD", &idx);
14156 cl_number_or_name = argv[idx]->arg;
14157 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14158 : COMMUNITY_DENY;
14159 argv_find(argv, argc, "AA:NN", &idx);
14160 char *str = argv_concat(argv, argc, idx);
42f914d4 14161
d62a17ae 14162 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14163 direct, style);
42f914d4 14164
d62a17ae 14165 XFREE(MTYPE_TMP, str);
42f914d4 14166
d62a17ae 14167 if (ret < 0) {
14168 community_list_perror(vty, ret);
14169 return CMD_WARNING_CONFIG_FAILED;
14170 }
42f914d4 14171
d62a17ae 14172 return CMD_SUCCESS;
718e3744 14173}
14174
718e3744 14175DEFUN (ip_extcommunity_list_name_expanded,
14176 ip_extcommunity_list_name_expanded_cmd,
e961923c 14177 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14178 IP_STR
14179 EXTCOMMUNITY_LIST_STR
5bf15956 14180 "Extended Community list number (expanded)\n"
718e3744 14181 "Specify expanded extcommunity-list\n"
14182 "Extended Community list name\n"
14183 "Specify community to reject\n"
14184 "Specify community to accept\n"
14185 "An ordered list as a regular-expression\n")
14186{
d62a17ae 14187 int style = EXTCOMMUNITY_LIST_EXPANDED;
14188 int direct = 0;
14189 char *cl_number_or_name = NULL;
42f914d4 14190
d62a17ae 14191 int idx = 0;
14192 argv_find(argv, argc, "(100-500)", &idx);
14193 argv_find(argv, argc, "WORD", &idx);
14194 cl_number_or_name = argv[idx]->arg;
14195 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14196 : COMMUNITY_DENY;
14197 argv_find(argv, argc, "LINE", &idx);
14198 char *str = argv_concat(argv, argc, idx);
42f914d4 14199
d62a17ae 14200 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14201 direct, style);
42f914d4 14202
d62a17ae 14203 XFREE(MTYPE_TMP, str);
42f914d4 14204
d62a17ae 14205 if (ret < 0) {
14206 community_list_perror(vty, ret);
14207 return CMD_WARNING_CONFIG_FAILED;
14208 }
42f914d4 14209
d62a17ae 14210 return CMD_SUCCESS;
718e3744 14211}
14212
fee6e4e4 14213DEFUN (no_ip_extcommunity_list_standard_all,
14214 no_ip_extcommunity_list_standard_all_cmd,
e961923c 14215 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
14216 NO_STR
14217 IP_STR
14218 EXTCOMMUNITY_LIST_STR
14219 "Extended Community list number (standard)\n"
718e3744 14220 "Specify standard extcommunity-list\n"
5bf15956 14221 "Community list name\n"
718e3744 14222 "Specify community to reject\n"
14223 "Specify community to accept\n"
14224 EXTCOMMUNITY_VAL_STR)
14225{
d62a17ae 14226 int style = EXTCOMMUNITY_LIST_STANDARD;
14227 int direct = 0;
14228 char *cl_number_or_name = NULL;
42f914d4 14229
d62a17ae 14230 int idx = 0;
14231 argv_find(argv, argc, "(1-99)", &idx);
14232 argv_find(argv, argc, "WORD", &idx);
14233 cl_number_or_name = argv[idx]->arg;
14234 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14235 : COMMUNITY_DENY;
14236 argv_find(argv, argc, "AA:NN", &idx);
14237 char *str = argv_concat(argv, argc, idx);
42f914d4 14238
d62a17ae 14239 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14240 direct, style);
42f914d4 14241
d62a17ae 14242 XFREE(MTYPE_TMP, str);
42f914d4 14243
d62a17ae 14244 if (ret < 0) {
14245 community_list_perror(vty, ret);
14246 return CMD_WARNING_CONFIG_FAILED;
14247 }
42f914d4 14248
d62a17ae 14249 return CMD_SUCCESS;
718e3744 14250}
14251
5bf15956
DW
14252DEFUN (no_ip_extcommunity_list_expanded_all,
14253 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 14254 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14255 NO_STR
14256 IP_STR
14257 EXTCOMMUNITY_LIST_STR
14258 "Extended Community list number (expanded)\n"
718e3744 14259 "Specify expanded extcommunity-list\n"
5bf15956 14260 "Extended Community list name\n"
718e3744 14261 "Specify community to reject\n"
14262 "Specify community to accept\n"
14263 "An ordered list as a regular-expression\n")
14264{
d62a17ae 14265 int style = EXTCOMMUNITY_LIST_EXPANDED;
14266 int direct = 0;
14267 char *cl_number_or_name = NULL;
42f914d4 14268
d62a17ae 14269 int idx = 0;
14270 argv_find(argv, argc, "(100-500)", &idx);
14271 argv_find(argv, argc, "WORD", &idx);
14272 cl_number_or_name = argv[idx]->arg;
14273 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14274 : COMMUNITY_DENY;
14275 argv_find(argv, argc, "LINE", &idx);
14276 char *str = argv_concat(argv, argc, idx);
42f914d4 14277
d62a17ae 14278 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14279 direct, style);
42f914d4 14280
d62a17ae 14281 XFREE(MTYPE_TMP, str);
42f914d4 14282
d62a17ae 14283 if (ret < 0) {
14284 community_list_perror(vty, ret);
14285 return CMD_WARNING_CONFIG_FAILED;
14286 }
42f914d4 14287
d62a17ae 14288 return CMD_SUCCESS;
718e3744 14289}
14290
d62a17ae 14291static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 14292{
d62a17ae 14293 struct community_entry *entry;
718e3744 14294
d62a17ae 14295 for (entry = list->head; entry; entry = entry->next) {
14296 if (entry == list->head) {
14297 if (all_digit(list->name))
14298 vty_out(vty, "Extended community %s list %s\n",
14299 entry->style == EXTCOMMUNITY_LIST_STANDARD
14300 ? "standard"
14301 : "(expanded) access",
14302 list->name);
14303 else
14304 vty_out(vty,
14305 "Named extended community %s list %s\n",
14306 entry->style == EXTCOMMUNITY_LIST_STANDARD
14307 ? "standard"
14308 : "expanded",
14309 list->name);
14310 }
14311 if (entry->any)
14312 vty_out(vty, " %s\n",
14313 community_direct_str(entry->direct));
14314 else
14315 vty_out(vty, " %s %s\n",
14316 community_direct_str(entry->direct),
8d9b8ed9 14317 community_list_config_str(entry));
d62a17ae 14318 }
718e3744 14319}
14320
14321DEFUN (show_ip_extcommunity_list,
14322 show_ip_extcommunity_list_cmd,
14323 "show ip extcommunity-list",
14324 SHOW_STR
14325 IP_STR
14326 "List extended-community list\n")
14327{
d62a17ae 14328 struct community_list *list;
14329 struct community_list_master *cm;
718e3744 14330
d62a17ae 14331 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14332 if (!cm)
14333 return CMD_SUCCESS;
718e3744 14334
d62a17ae 14335 for (list = cm->num.head; list; list = list->next)
14336 extcommunity_list_show(vty, list);
718e3744 14337
d62a17ae 14338 for (list = cm->str.head; list; list = list->next)
14339 extcommunity_list_show(vty, list);
718e3744 14340
d62a17ae 14341 return CMD_SUCCESS;
718e3744 14342}
14343
14344DEFUN (show_ip_extcommunity_list_arg,
14345 show_ip_extcommunity_list_arg_cmd,
6147e2c6 14346 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 14347 SHOW_STR
14348 IP_STR
14349 "List extended-community list\n"
14350 "Extcommunity-list number\n"
14351 "Extcommunity-list name\n")
14352{
d62a17ae 14353 int idx_comm_list = 3;
14354 struct community_list *list;
718e3744 14355
d62a17ae 14356 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14357 EXTCOMMUNITY_LIST_MASTER);
14358 if (!list) {
14359 vty_out(vty, "%% Can't find extcommunity-list\n");
14360 return CMD_WARNING;
14361 }
718e3744 14362
d62a17ae 14363 extcommunity_list_show(vty, list);
718e3744 14364
d62a17ae 14365 return CMD_SUCCESS;
718e3744 14366}
6b0655a2 14367
718e3744 14368/* Display community-list and extcommunity-list configuration. */
d62a17ae 14369static int community_list_config_write(struct vty *vty)
14370{
14371 struct community_list *list;
14372 struct community_entry *entry;
14373 struct community_list_master *cm;
14374 int write = 0;
14375
14376 /* Community-list. */
14377 cm = community_list_master_lookup(bgp_clist, 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 community-list %s %s %s\n", list->name,
14382 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 community-list %s %s %s %s\n",
14389 entry->style == 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 /* Extcommunity-list. */
14398 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14399
14400 for (list = cm->num.head; list; list = list->next)
14401 for (entry = list->head; entry; entry = entry->next) {
14402 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14403 list->name, community_direct_str(entry->direct),
14404 community_list_config_str(entry));
14405 write++;
14406 }
14407 for (list = cm->str.head; list; list = list->next)
14408 for (entry = list->head; entry; entry = entry->next) {
14409 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14410 entry->style == EXTCOMMUNITY_LIST_STANDARD
14411 ? "standard"
14412 : "expanded",
14413 list->name, community_direct_str(entry->direct),
14414 community_list_config_str(entry));
14415 write++;
14416 }
14417
14418
14419 /* lcommunity-list. */
14420 cm = community_list_master_lookup(bgp_clist,
14421 LARGE_COMMUNITY_LIST_MASTER);
14422
14423 for (list = cm->num.head; list; list = list->next)
14424 for (entry = list->head; entry; entry = entry->next) {
14425 vty_out(vty, "ip large-community-list %s %s %s\n",
14426 list->name, community_direct_str(entry->direct),
14427 community_list_config_str(entry));
14428 write++;
14429 }
14430 for (list = cm->str.head; list; list = list->next)
14431 for (entry = list->head; entry; entry = entry->next) {
14432 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14433 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14434 ? "standard"
14435 : "expanded",
14436 list->name, community_direct_str(entry->direct),
14437 community_list_config_str(entry));
14438 write++;
14439 }
14440
14441 return write;
14442}
14443
14444static struct cmd_node community_list_node = {
14445 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 14446};
14447
d62a17ae 14448static void community_list_vty(void)
14449{
14450 install_node(&community_list_node, community_list_config_write);
14451
14452 /* Community-list. */
14453 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14454 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14455 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14456 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14457 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14458 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14459
14460 /* Extcommunity-list. */
14461 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14462 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14463 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14464 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14465 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14466 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14467
14468 /* Large Community List */
14469 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14470 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14471 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14472 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14473 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14474 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14475 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14476 install_element(CONFIG_NODE,
14477 &no_ip_lcommunity_list_name_expanded_all_cmd);
14478 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14479 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14480 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14481 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14482 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14483 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 14484}