]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #2563 from pacovn/Coverity_1465494_String_not_null_terminated_2
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
718e3744 25#include "prefix.h"
26#include "plist.h"
27#include "buffer.h"
28#include "linklist.h"
29#include "stream.h"
30#include "thread.h"
31#include "log.h"
3b8b1855 32#include "memory.h"
fc7948fa 33#include "memory_vty.h"
4bf6a362 34#include "hash.h"
3f9c7369 35#include "queue.h"
039f3a34 36#include "filter.h"
5d5ba018 37#include "frrstr.h"
718e3744 38
39#include "bgpd/bgpd.h"
4bf6a362 40#include "bgpd/bgp_advertise.h"
718e3744 41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_aspath.h"
43#include "bgpd/bgp_community.h"
4bf6a362 44#include "bgpd/bgp_ecommunity.h"
57d187bc 45#include "bgpd/bgp_lcommunity.h"
4bf6a362 46#include "bgpd/bgp_damp.h"
718e3744 47#include "bgpd/bgp_debug.h"
e0701b79 48#include "bgpd/bgp_fsm.h"
4bf6a362 49#include "bgpd/bgp_nexthop.h"
718e3744 50#include "bgpd/bgp_open.h"
4bf6a362 51#include "bgpd/bgp_regex.h"
718e3744 52#include "bgpd/bgp_route.h"
c016b6c7 53#include "bgpd/bgp_mplsvpn.h"
718e3744 54#include "bgpd/bgp_zebra.h"
fee0f4c6 55#include "bgpd/bgp_table.h"
94f2b392 56#include "bgpd/bgp_vty.h"
165b5fff 57#include "bgpd/bgp_mpath.h"
cb1faec9 58#include "bgpd/bgp_packet.h"
3f9c7369 59#include "bgpd/bgp_updgrp.h"
c43ed2e4 60#include "bgpd/bgp_bfd.h"
555e09d4 61#include "bgpd/bgp_io.h"
94c2f693 62#include "bgpd/bgp_evpn.h"
718e3744 63
d62a17ae 64static struct peer_group *listen_range_exists(struct bgp *bgp,
65 struct prefix *range, int exact);
66
67static enum node_type bgp_node_type(afi_t afi, safi_t safi)
68{
69 switch (afi) {
70 case AFI_IP:
71 switch (safi) {
72 case SAFI_UNICAST:
73 return BGP_IPV4_NODE;
74 break;
75 case SAFI_MULTICAST:
76 return BGP_IPV4M_NODE;
77 break;
78 case SAFI_LABELED_UNICAST:
79 return BGP_IPV4L_NODE;
80 break;
81 case SAFI_MPLS_VPN:
82 return BGP_VPNV4_NODE;
83 break;
7c40bf39 84 case SAFI_FLOWSPEC:
85 return BGP_FLOWSPECV4_NODE;
5c525538
RW
86 default:
87 /* not expected */
88 return BGP_IPV4_NODE;
89 break;
d62a17ae 90 }
91 break;
92 case AFI_IP6:
93 switch (safi) {
94 case SAFI_UNICAST:
95 return BGP_IPV6_NODE;
96 break;
97 case SAFI_MULTICAST:
98 return BGP_IPV6M_NODE;
99 break;
100 case SAFI_LABELED_UNICAST:
101 return BGP_IPV6L_NODE;
102 break;
103 case SAFI_MPLS_VPN:
104 return BGP_VPNV6_NODE;
105 break;
7c40bf39 106 case SAFI_FLOWSPEC:
107 return BGP_FLOWSPECV6_NODE;
5c525538
RW
108 default:
109 /* not expected */
110 return BGP_IPV4_NODE;
111 break;
d62a17ae 112 }
113 break;
114 case AFI_L2VPN:
115 return BGP_EVPN_NODE;
116 break;
117 case AFI_MAX:
118 // We should never be here but to clarify the switch statement..
119 return BGP_IPV4_NODE;
120 break;
121 }
122
123 // Impossible to happen
124 return BGP_IPV4_NODE;
f51bae9c 125}
20eb8864 126
718e3744 127/* Utility function to get address family from current node. */
d62a17ae 128afi_t bgp_node_afi(struct vty *vty)
129{
130 afi_t afi;
131 switch (vty->node) {
132 case BGP_IPV6_NODE:
133 case BGP_IPV6M_NODE:
134 case BGP_IPV6L_NODE:
135 case BGP_VPNV6_NODE:
7c40bf39 136 case BGP_FLOWSPECV6_NODE:
d62a17ae 137 afi = AFI_IP6;
138 break;
139 case BGP_EVPN_NODE:
140 afi = AFI_L2VPN;
141 break;
142 default:
143 afi = AFI_IP;
144 break;
145 }
146 return afi;
718e3744 147}
148
149/* Utility function to get subsequent address family from current
150 node. */
d62a17ae 151safi_t bgp_node_safi(struct vty *vty)
152{
153 safi_t safi;
154 switch (vty->node) {
155 case BGP_VPNV4_NODE:
156 case BGP_VPNV6_NODE:
157 safi = SAFI_MPLS_VPN;
158 break;
159 case BGP_IPV4M_NODE:
160 case BGP_IPV6M_NODE:
161 safi = SAFI_MULTICAST;
162 break;
163 case BGP_EVPN_NODE:
164 safi = SAFI_EVPN;
165 break;
166 case BGP_IPV4L_NODE:
167 case BGP_IPV6L_NODE:
168 safi = SAFI_LABELED_UNICAST;
169 break;
7c40bf39 170 case BGP_FLOWSPECV4_NODE:
171 case BGP_FLOWSPECV6_NODE:
172 safi = SAFI_FLOWSPEC;
173 break;
d62a17ae 174 default:
175 safi = SAFI_UNICAST;
176 break;
177 }
178 return safi;
718e3744 179}
180
55f91488
QY
181/**
182 * Converts an AFI in string form to afi_t
183 *
184 * @param afi string, one of
185 * - "ipv4"
186 * - "ipv6"
187 * @return the corresponding afi_t
188 */
d62a17ae 189afi_t bgp_vty_afi_from_str(const char *afi_str)
190{
191 afi_t afi = AFI_MAX; /* unknown */
192 if (strmatch(afi_str, "ipv4"))
193 afi = AFI_IP;
194 else if (strmatch(afi_str, "ipv6"))
195 afi = AFI_IP6;
196 return afi;
197}
198
199int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
200 afi_t *afi)
201{
202 int ret = 0;
203 if (argv_find(argv, argc, "ipv4", index)) {
204 ret = 1;
205 if (afi)
206 *afi = AFI_IP;
207 } else if (argv_find(argv, argc, "ipv6", index)) {
208 ret = 1;
209 if (afi)
210 *afi = AFI_IP6;
211 }
212 return ret;
46f296b4
LB
213}
214
375a2e67 215/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 216safi_t bgp_vty_safi_from_str(const char *safi_str)
217{
218 safi_t safi = SAFI_MAX; /* unknown */
219 if (strmatch(safi_str, "multicast"))
220 safi = SAFI_MULTICAST;
221 else if (strmatch(safi_str, "unicast"))
222 safi = SAFI_UNICAST;
223 else if (strmatch(safi_str, "vpn"))
224 safi = SAFI_MPLS_VPN;
225 else if (strmatch(safi_str, "labeled-unicast"))
226 safi = SAFI_LABELED_UNICAST;
7c40bf39 227 else if (strmatch(safi_str, "flowspec"))
228 safi = SAFI_FLOWSPEC;
d62a17ae 229 return safi;
230}
231
232int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
233 safi_t *safi)
234{
235 int ret = 0;
236 if (argv_find(argv, argc, "unicast", index)) {
237 ret = 1;
238 if (safi)
239 *safi = SAFI_UNICAST;
240 } else if (argv_find(argv, argc, "multicast", index)) {
241 ret = 1;
242 if (safi)
243 *safi = SAFI_MULTICAST;
244 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
245 ret = 1;
246 if (safi)
247 *safi = SAFI_LABELED_UNICAST;
248 } else if (argv_find(argv, argc, "vpn", index)) {
249 ret = 1;
250 if (safi)
251 *safi = SAFI_MPLS_VPN;
7c40bf39 252 } else if (argv_find(argv, argc, "flowspec", index)) {
253 ret = 1;
254 if (safi)
255 *safi = SAFI_FLOWSPEC;
d62a17ae 256 }
257 return ret;
46f296b4
LB
258}
259
7eeee51e 260/*
f212a857 261 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 262 *
f212a857
DS
263 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
264 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
265 * to appropriate values for the calling function. This is to allow the
266 * calling function to make decisions appropriate for the show command
267 * that is being parsed.
268 *
269 * The show commands are generally of the form:
d62a17ae 270 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
271 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
272 *
273 * Since we use argv_find if the show command in particular doesn't have:
274 * [ip]
18c57037 275 * [<view|vrf> VIEWVRFNAME]
375a2e67 276 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
277 * The command parsing should still be ok.
278 *
279 * vty -> The vty for the command so we can output some useful data in
280 * the event of a parse error in the vrf.
281 * argv -> The command tokens
282 * argc -> How many command tokens we have
d62a17ae 283 * idx -> The current place in the command, generally should be 0 for this
284 * function
7eeee51e
DS
285 * afi -> The parsed afi if it was included in the show command, returned here
286 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 287 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
288 *
289 * The function returns the correct location in the parse tree for the
290 * last token found.
0e37c258
DS
291 *
292 * Returns 0 for failure to parse correctly, else the idx position of where
293 * it found the last token.
7eeee51e 294 */
d62a17ae 295int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
296 struct cmd_token **argv, int argc,
297 int *idx, afi_t *afi, safi_t *safi,
298 struct bgp **bgp)
299{
300 char *vrf_name = NULL;
301
302 assert(afi);
303 assert(safi);
304 assert(bgp);
305
306 if (argv_find(argv, argc, "ip", idx))
307 *afi = AFI_IP;
308
309 if (argv_find(argv, argc, "view", idx)
310 || argv_find(argv, argc, "vrf", idx)) {
311 vrf_name = argv[*idx + 1]->arg;
312
313 if (strmatch(vrf_name, "all"))
314 *bgp = NULL;
315 else {
316 *bgp = bgp_lookup_by_name(vrf_name);
317 if (!*bgp) {
318 vty_out(vty,
319 "View/Vrf specified is unknown: %s\n",
320 vrf_name);
321 *idx = 0;
322 return 0;
323 }
324 }
325 } else {
326 *bgp = bgp_get_default();
327 if (!*bgp) {
328 vty_out(vty, "Unable to find default BGP instance\n");
329 *idx = 0;
330 return 0;
331 }
332 }
333
334 if (argv_find_and_parse_afi(argv, argc, idx, afi))
335 argv_find_and_parse_safi(argv, argc, idx, safi);
336
337 *idx += 1;
338 return *idx;
339}
340
341static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
342{
343 struct interface *ifp = NULL;
344
345 if (su->sa.sa_family == AF_INET)
346 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
347 else if (su->sa.sa_family == AF_INET6)
348 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
349 su->sin6.sin6_scope_id,
350 bgp->vrf_id);
351
352 if (ifp)
353 return 1;
354
355 return 0;
718e3744 356}
357
358/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
359/* This is used only for configuration, so disallow if attempted on
360 * a dynamic neighbor.
361 */
d62a17ae 362static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
363{
364 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
365 int ret;
366 union sockunion su;
367 struct peer *peer;
368
369 if (!bgp) {
370 return NULL;
371 }
372
373 ret = str2sockunion(ip_str, &su);
374 if (ret < 0) {
375 peer = peer_lookup_by_conf_if(bgp, ip_str);
376 if (!peer) {
377 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
378 == NULL) {
379 vty_out(vty,
380 "%% Malformed address or name: %s\n",
381 ip_str);
382 return NULL;
383 }
384 }
385 } else {
386 peer = peer_lookup(bgp, &su);
387 if (!peer) {
388 vty_out(vty,
389 "%% Specify remote-as or peer-group commands first\n");
390 return NULL;
391 }
392 if (peer_dynamic_neighbor(peer)) {
393 vty_out(vty,
394 "%% Operation not allowed on a dynamic neighbor\n");
395 return NULL;
396 }
397 }
398 return peer;
718e3744 399}
400
401/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
402/* This is used only for configuration, so disallow if attempted on
403 * a dynamic neighbor.
404 */
d62a17ae 405struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
406{
407 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
408 int ret;
409 union sockunion su;
410 struct peer *peer = NULL;
411 struct peer_group *group = NULL;
412
413 if (!bgp) {
414 return NULL;
415 }
416
417 ret = str2sockunion(peer_str, &su);
418 if (ret == 0) {
419 /* IP address, locate peer. */
420 peer = peer_lookup(bgp, &su);
421 } else {
422 /* Not IP, could match either peer configured on interface or a
423 * group. */
424 peer = peer_lookup_by_conf_if(bgp, peer_str);
425 if (!peer)
426 group = peer_group_lookup(bgp, peer_str);
427 }
428
429 if (peer) {
430 if (peer_dynamic_neighbor(peer)) {
431 vty_out(vty,
432 "%% Operation not allowed on a dynamic neighbor\n");
433 return NULL;
434 }
435
436 return peer;
437 }
438
439 if (group)
440 return group->conf;
441
442 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
443
444 return NULL;
445}
446
447int bgp_vty_return(struct vty *vty, int ret)
448{
449 const char *str = NULL;
450
451 switch (ret) {
452 case BGP_ERR_INVALID_VALUE:
453 str = "Invalid value";
454 break;
455 case BGP_ERR_INVALID_FLAG:
456 str = "Invalid flag";
457 break;
458 case BGP_ERR_PEER_GROUP_SHUTDOWN:
459 str = "Peer-group has been shutdown. Activate the peer-group first";
460 break;
461 case BGP_ERR_PEER_FLAG_CONFLICT:
462 str = "Can't set override-capability and strict-capability-match at the same time";
463 break;
464 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
465 str = "Specify remote-as or peer-group remote AS first";
466 break;
467 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
468 str = "Cannot change the peer-group. Deconfigure first";
469 break;
470 case BGP_ERR_PEER_GROUP_MISMATCH:
471 str = "Peer is not a member of this peer-group";
472 break;
473 case BGP_ERR_PEER_FILTER_CONFLICT:
474 str = "Prefix/distribute list can not co-exist";
475 break;
476 case BGP_ERR_NOT_INTERNAL_PEER:
477 str = "Invalid command. Not an internal neighbor";
478 break;
479 case BGP_ERR_REMOVE_PRIVATE_AS:
480 str = "remove-private-AS cannot be configured for IBGP peers";
481 break;
482 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
483 str = "Local-AS allowed only for EBGP peers";
484 break;
485 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
486 str = "Cannot have local-as same as BGP AS number";
487 break;
488 case BGP_ERR_TCPSIG_FAILED:
489 str = "Error while applying TCP-Sig to session(s)";
490 break;
491 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
492 str = "ebgp-multihop and ttl-security cannot be configured together";
493 break;
494 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
495 str = "ttl-security only allowed for EBGP peers";
496 break;
497 case BGP_ERR_AS_OVERRIDE:
498 str = "as-override cannot be configured for IBGP peers";
499 break;
500 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
501 str = "Invalid limit for number of dynamic neighbors";
502 break;
503 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
504 str = "Dynamic neighbor listen range already exists";
505 break;
506 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
507 str = "Operation not allowed on a dynamic neighbor";
508 break;
509 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
510 str = "Operation not allowed on a directly connected neighbor";
511 break;
512 case BGP_ERR_PEER_SAFI_CONFLICT:
513 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
514 break;
515 }
516 if (str) {
517 vty_out(vty, "%% %s\n", str);
518 return CMD_WARNING_CONFIG_FAILED;
519 }
520 return CMD_SUCCESS;
718e3744 521}
522
7aafcaca 523/* BGP clear sort. */
d62a17ae 524enum clear_sort {
525 clear_all,
526 clear_peer,
527 clear_group,
528 clear_external,
529 clear_as
7aafcaca
DS
530};
531
d62a17ae 532static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
533 safi_t safi, int error)
534{
535 switch (error) {
536 case BGP_ERR_AF_UNCONFIGURED:
537 vty_out(vty,
538 "%%BGP: Enable %s address family for the neighbor %s\n",
539 afi_safi_print(afi, safi), peer->host);
540 break;
541 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
542 vty_out(vty,
543 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
544 peer->host);
545 break;
546 default:
547 break;
548 }
7aafcaca
DS
549}
550
551/* `clear ip bgp' functions. */
d62a17ae 552static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
553 enum clear_sort sort, enum bgp_clear_type stype,
554 const char *arg)
555{
556 int ret;
3ae8bfa5 557 bool found = false;
d62a17ae 558 struct peer *peer;
559 struct listnode *node, *nnode;
560
561 /* Clear all neighbors. */
562 /*
563 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
564 * nodes on the BGP instance as that may get freed if it is a
565 * doppelganger
d62a17ae 566 */
567 if (sort == clear_all) {
568 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
3ae8bfa5
PM
569 if (!peer->afc[afi][safi])
570 continue;
571
d62a17ae 572 if (stype == BGP_CLEAR_SOFT_NONE)
573 ret = peer_clear(peer, &nnode);
d62a17ae 574 else
3ae8bfa5 575 ret = peer_clear_soft(peer, afi, safi, stype);
d62a17ae 576
577 if (ret < 0)
578 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
579 else
580 found = true;
04b6bdc0 581 }
d62a17ae 582
583 /* This is to apply read-only mode on this clear. */
584 if (stype == BGP_CLEAR_SOFT_NONE)
585 bgp->update_delay_over = 0;
586
3ae8bfa5
PM
587 if (!found)
588 vty_out(vty, "%%BGP: No %s peer configured",
589 afi_safi_print(afi, safi));
590
d62a17ae 591 return CMD_SUCCESS;
7aafcaca
DS
592 }
593
3ae8bfa5 594 /* Clear specified neighbor. */
d62a17ae 595 if (sort == clear_peer) {
596 union sockunion su;
d62a17ae 597
598 /* Make sockunion for lookup. */
599 ret = str2sockunion(arg, &su);
600 if (ret < 0) {
601 peer = peer_lookup_by_conf_if(bgp, arg);
602 if (!peer) {
603 peer = peer_lookup_by_hostname(bgp, arg);
604 if (!peer) {
605 vty_out(vty,
606 "Malformed address or name: %s\n",
607 arg);
608 return CMD_WARNING;
609 }
610 }
611 } else {
612 peer = peer_lookup(bgp, &su);
613 if (!peer) {
614 vty_out(vty,
615 "%%BGP: Unknown neighbor - \"%s\"\n",
616 arg);
617 return CMD_WARNING;
618 }
619 }
7aafcaca 620
3ae8bfa5
PM
621 if (!peer->afc[afi][safi])
622 ret = BGP_ERR_AF_UNCONFIGURED;
623 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 624 ret = peer_clear(peer, NULL);
625 else
626 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 627
d62a17ae 628 if (ret < 0)
629 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 630
d62a17ae 631 return CMD_SUCCESS;
7aafcaca 632 }
7aafcaca 633
3ae8bfa5 634 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 635 if (sort == clear_group) {
636 struct peer_group *group;
7aafcaca 637
d62a17ae 638 group = peer_group_lookup(bgp, arg);
639 if (!group) {
640 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
641 return CMD_WARNING;
642 }
643
644 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
d62a17ae 645 if (!peer->afc[afi][safi])
646 continue;
647
3ae8bfa5
PM
648 if (stype == BGP_CLEAR_SOFT_NONE)
649 ret = peer_clear(peer, NULL);
650 else
651 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 652
d62a17ae 653 if (ret < 0)
654 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
655 else
656 found = true;
d62a17ae 657 }
3ae8bfa5
PM
658
659 if (!found)
660 vty_out(vty,
661 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
662 afi_safi_print(afi, safi), arg);
663
d62a17ae 664 return CMD_SUCCESS;
7aafcaca 665 }
7aafcaca 666
3ae8bfa5 667 /* Clear all external (eBGP) neighbors. */
d62a17ae 668 if (sort == clear_external) {
669 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
670 if (peer->sort == BGP_PEER_IBGP)
671 continue;
7aafcaca 672
3ae8bfa5
PM
673 if (!peer->afc[afi][safi])
674 continue;
675
d62a17ae 676 if (stype == BGP_CLEAR_SOFT_NONE)
677 ret = peer_clear(peer, &nnode);
678 else
679 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 680
d62a17ae 681 if (ret < 0)
682 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
683 else
684 found = true;
d62a17ae 685 }
3ae8bfa5
PM
686
687 if (!found)
688 vty_out(vty,
689 "%%BGP: No external %s peer is configured\n",
690 afi_safi_print(afi, safi));
691
d62a17ae 692 return CMD_SUCCESS;
693 }
694
3ae8bfa5 695 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 696 if (sort == clear_as) {
3ae8bfa5 697 as_t as = strtoul(arg, NULL, 10);
d62a17ae 698
699 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
700 if (peer->as != as)
701 continue;
702
3ae8bfa5
PM
703 if (!peer->afc[afi][safi])
704 ret = BGP_ERR_AF_UNCONFIGURED;
705 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 706 ret = peer_clear(peer, &nnode);
707 else
708 ret = peer_clear_soft(peer, afi, safi, stype);
709
710 if (ret < 0)
711 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
712 else
713 found = true;
d62a17ae 714 }
3ae8bfa5
PM
715
716 if (!found)
d62a17ae 717 vty_out(vty,
3ae8bfa5
PM
718 "%%BGP: No %s peer is configured with AS %s\n",
719 afi_safi_print(afi, safi), arg);
720
d62a17ae 721 return CMD_SUCCESS;
722 }
723
724 return CMD_SUCCESS;
725}
726
727static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
728 safi_t safi, enum clear_sort sort,
729 enum bgp_clear_type stype, const char *arg)
730{
731 struct bgp *bgp;
732
733 /* BGP structure lookup. */
734 if (name) {
735 bgp = bgp_lookup_by_name(name);
736 if (bgp == NULL) {
737 vty_out(vty, "Can't find BGP instance %s\n", name);
738 return CMD_WARNING;
739 }
740 } else {
741 bgp = bgp_get_default();
742 if (bgp == NULL) {
743 vty_out(vty, "No BGP process is configured\n");
744 return CMD_WARNING;
745 }
746 }
747
748 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
749}
750
751/* clear soft inbound */
d62a17ae 752static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 753{
d62a17ae 754 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
755 BGP_CLEAR_SOFT_IN, NULL);
756 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
757 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
758}
759
760/* clear soft outbound */
d62a17ae 761static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 762{
d62a17ae 763 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
764 BGP_CLEAR_SOFT_OUT, NULL);
765 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
766 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
767}
768
769
f787d7a0 770#ifndef VTYSH_EXTRACT_PL
2e4c2296 771#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
772#endif
773
718e3744 774/* BGP global configuration. */
1cc40660
DS
775#if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
776CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
777CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
778#endif
779DEFUN_HIDDEN (bgp_multiple_instance_func,
780 bgp_multiple_instance_cmd,
781 "bgp multiple-instance",
782 BGP_STR
783 "Enable bgp multiple instance\n")
718e3744 784{
d62a17ae 785 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
786 return CMD_SUCCESS;
718e3744 787}
788
1cc40660 789DEFUN_HIDDEN (no_bgp_multiple_instance,
718e3744 790 no_bgp_multiple_instance_cmd,
791 "no bgp multiple-instance",
792 NO_STR
793 BGP_STR
794 "BGP multiple instance\n")
795{
d62a17ae 796 int ret;
718e3744 797
1cc40660
DS
798 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
799 vty_out(vty, "if you are using this please let the developers know\n");
800 zlog_warn("Deprecated option: `bgp multiple-instance` being used");
d62a17ae 801 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
802 if (ret < 0) {
803 vty_out(vty, "%% There are more than two BGP instances\n");
804 return CMD_WARNING_CONFIG_FAILED;
805 }
806 return CMD_SUCCESS;
718e3744 807}
808
798467a2
DS
809#if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
810CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
811CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
812#endif
813DEFUN_HIDDEN (bgp_config_type,
814 bgp_config_type_cmd,
815 "bgp config-type <cisco|zebra>",
816 BGP_STR
817 "Configuration type\n"
818 "cisco\n"
819 "zebra\n")
718e3744 820{
d62a17ae 821 int idx = 0;
798467a2
DS
822 if (argv_find(argv, argc, "cisco", &idx)) {
823 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
824 vty_out(vty, "if you are using this please let the developers know!\n");
825 zlog_warn("Deprecated option: `bgp config-type cisco` being used");
d62a17ae 826 bgp_option_set(BGP_OPT_CONFIG_CISCO);
798467a2 827 } else
d62a17ae 828 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 829
d62a17ae 830 return CMD_SUCCESS;
718e3744 831}
832
798467a2
DS
833DEFUN_HIDDEN (no_bgp_config_type,
834 no_bgp_config_type_cmd,
835 "no bgp config-type [<cisco|zebra>]",
836 NO_STR
837 BGP_STR
838 "Display configuration type\n"
839 "cisco\n"
840 "zebra\n")
718e3744 841{
d62a17ae 842 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
843 return CMD_SUCCESS;
718e3744 844}
845
813d4307 846
718e3744 847DEFUN (no_synchronization,
848 no_synchronization_cmd,
849 "no synchronization",
850 NO_STR
851 "Perform IGP synchronization\n")
852{
d62a17ae 853 return CMD_SUCCESS;
718e3744 854}
855
856DEFUN (no_auto_summary,
857 no_auto_summary_cmd,
858 "no auto-summary",
859 NO_STR
860 "Enable automatic network number summarization\n")
861{
d62a17ae 862 return CMD_SUCCESS;
718e3744 863}
3d515fd9 864
718e3744 865/* "router bgp" commands. */
505e5056 866DEFUN_NOSH (router_bgp,
f412b39a 867 router_bgp_cmd,
18c57037 868 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 869 ROUTER_STR
870 BGP_STR
31500417
DW
871 AS_STR
872 BGP_INSTANCE_HELP_STR)
718e3744 873{
d62a17ae 874 int idx_asn = 2;
875 int idx_view_vrf = 3;
876 int idx_vrf = 4;
877 int ret;
878 as_t as;
879 struct bgp *bgp;
880 const char *name = NULL;
881 enum bgp_instance_type inst_type;
882
883 // "router bgp" without an ASN
884 if (argc == 2) {
885 // Pending: Make VRF option available for ASN less config
886 bgp = bgp_get_default();
887
888 if (bgp == NULL) {
889 vty_out(vty, "%% No BGP process is configured\n");
890 return CMD_WARNING_CONFIG_FAILED;
891 }
892
893 if (listcount(bm->bgp) > 1) {
996c9314 894 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 895 return CMD_WARNING_CONFIG_FAILED;
896 }
897 }
898
899 // "router bgp X"
900 else {
901 as = strtoul(argv[idx_asn]->arg, NULL, 10);
902
903 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
904 if (argc > 3) {
905 name = argv[idx_vrf]->arg;
906
907 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
908 inst_type = BGP_INSTANCE_TYPE_VRF;
909 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
910 inst_type = BGP_INSTANCE_TYPE_VIEW;
911 }
912
913 ret = bgp_get(&bgp, &as, name, inst_type);
914 switch (ret) {
915 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
916 vty_out(vty,
917 "Please specify 'bgp multiple-instance' first\n");
918 return CMD_WARNING_CONFIG_FAILED;
919 case BGP_ERR_AS_MISMATCH:
920 vty_out(vty, "BGP is already running; AS is %u\n", as);
921 return CMD_WARNING_CONFIG_FAILED;
922 case BGP_ERR_INSTANCE_MISMATCH:
923 vty_out(vty,
924 "BGP instance name and AS number mismatch\n");
925 vty_out(vty,
926 "BGP instance is already running; AS is %u\n",
927 as);
928 return CMD_WARNING_CONFIG_FAILED;
929 }
930
931 /* Pending: handle when user tries to change a view to vrf n vv.
932 */
933 }
934
0b5131c9
MK
935 /* unset the auto created flag as the user config is now present */
936 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 937 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
938
939 return CMD_SUCCESS;
718e3744 940}
941
718e3744 942/* "no router bgp" commands. */
943DEFUN (no_router_bgp,
944 no_router_bgp_cmd,
18c57037 945 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 946 NO_STR
947 ROUTER_STR
948 BGP_STR
31500417
DW
949 AS_STR
950 BGP_INSTANCE_HELP_STR)
718e3744 951{
d62a17ae 952 int idx_asn = 3;
953 int idx_vrf = 5;
954 as_t as;
955 struct bgp *bgp;
956 const char *name = NULL;
718e3744 957
d62a17ae 958 // "no router bgp" without an ASN
959 if (argc == 3) {
960 // Pending: Make VRF option available for ASN less config
961 bgp = bgp_get_default();
718e3744 962
d62a17ae 963 if (bgp == NULL) {
964 vty_out(vty, "%% No BGP process is configured\n");
965 return CMD_WARNING_CONFIG_FAILED;
966 }
7fb21a9f 967
d62a17ae 968 if (listcount(bm->bgp) > 1) {
996c9314 969 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 970 return CMD_WARNING_CONFIG_FAILED;
971 }
0b5131c9
MK
972
973 if (bgp->l3vni) {
974 vty_out(vty, "%% Please unconfigure l3vni %u",
975 bgp->l3vni);
976 return CMD_WARNING_CONFIG_FAILED;
977 }
d62a17ae 978 } else {
979 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 980
d62a17ae 981 if (argc > 4)
982 name = argv[idx_vrf]->arg;
7fb21a9f 983
d62a17ae 984 /* Lookup bgp structure. */
985 bgp = bgp_lookup(as, name);
986 if (!bgp) {
987 vty_out(vty, "%% Can't find BGP instance\n");
988 return CMD_WARNING_CONFIG_FAILED;
989 }
0b5131c9
MK
990
991 if (bgp->l3vni) {
992 vty_out(vty, "%% Please unconfigure l3vni %u",
993 bgp->l3vni);
994 return CMD_WARNING_CONFIG_FAILED;
995 }
d62a17ae 996 }
718e3744 997
d62a17ae 998 bgp_delete(bgp);
718e3744 999
d62a17ae 1000 return CMD_SUCCESS;
718e3744 1001}
1002
6b0655a2 1003
718e3744 1004/* BGP router-id. */
1005
f787d7a0 1006DEFPY (bgp_router_id,
718e3744 1007 bgp_router_id_cmd,
1008 "bgp router-id A.B.C.D",
1009 BGP_STR
1010 "Override configured router identifier\n"
1011 "Manually configured router identifier\n")
1012{
d62a17ae 1013 VTY_DECLVAR_CONTEXT(bgp, bgp);
1014 bgp_router_id_static_set(bgp, router_id);
1015 return CMD_SUCCESS;
718e3744 1016}
1017
f787d7a0 1018DEFPY (no_bgp_router_id,
718e3744 1019 no_bgp_router_id_cmd,
31500417 1020 "no bgp router-id [A.B.C.D]",
718e3744 1021 NO_STR
1022 BGP_STR
31500417
DW
1023 "Override configured router identifier\n"
1024 "Manually configured router identifier\n")
718e3744 1025{
d62a17ae 1026 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1027
d62a17ae 1028 if (router_id_str) {
1029 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1030 vty_out(vty, "%% BGP router-id doesn't match\n");
1031 return CMD_WARNING_CONFIG_FAILED;
1032 }
e018c7cc 1033 }
718e3744 1034
d62a17ae 1035 router_id.s_addr = 0;
1036 bgp_router_id_static_set(bgp, router_id);
718e3744 1037
d62a17ae 1038 return CMD_SUCCESS;
718e3744 1039}
1040
6b0655a2 1041
718e3744 1042/* BGP Cluster ID. */
718e3744 1043DEFUN (bgp_cluster_id,
1044 bgp_cluster_id_cmd,
838758ac 1045 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1046 BGP_STR
1047 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1048 "Route-Reflector Cluster-id in IP address format\n"
1049 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1050{
d62a17ae 1051 VTY_DECLVAR_CONTEXT(bgp, bgp);
1052 int idx_ipv4 = 2;
1053 int ret;
1054 struct in_addr cluster;
718e3744 1055
d62a17ae 1056 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1057 if (!ret) {
1058 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1059 return CMD_WARNING_CONFIG_FAILED;
1060 }
718e3744 1061
d62a17ae 1062 bgp_cluster_id_set(bgp, &cluster);
1063 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1064
d62a17ae 1065 return CMD_SUCCESS;
718e3744 1066}
1067
718e3744 1068DEFUN (no_bgp_cluster_id,
1069 no_bgp_cluster_id_cmd,
c7178fe7 1070 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1071 NO_STR
1072 BGP_STR
838758ac
DW
1073 "Configure Route-Reflector Cluster-id\n"
1074 "Route-Reflector Cluster-id in IP address format\n"
1075 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1076{
d62a17ae 1077 VTY_DECLVAR_CONTEXT(bgp, bgp);
1078 bgp_cluster_id_unset(bgp);
1079 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1080
d62a17ae 1081 return CMD_SUCCESS;
718e3744 1082}
1083
718e3744 1084DEFUN (bgp_confederation_identifier,
1085 bgp_confederation_identifier_cmd,
9ccf14f7 1086 "bgp confederation identifier (1-4294967295)",
718e3744 1087 "BGP specific commands\n"
1088 "AS confederation parameters\n"
1089 "AS number\n"
1090 "Set routing domain confederation AS\n")
1091{
d62a17ae 1092 VTY_DECLVAR_CONTEXT(bgp, bgp);
1093 int idx_number = 3;
1094 as_t as;
718e3744 1095
d62a17ae 1096 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1097
d62a17ae 1098 bgp_confederation_id_set(bgp, as);
718e3744 1099
d62a17ae 1100 return CMD_SUCCESS;
718e3744 1101}
1102
1103DEFUN (no_bgp_confederation_identifier,
1104 no_bgp_confederation_identifier_cmd,
838758ac 1105 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1106 NO_STR
1107 "BGP specific commands\n"
1108 "AS confederation parameters\n"
3a2d747c
QY
1109 "AS number\n"
1110 "Set routing domain confederation AS\n")
718e3744 1111{
d62a17ae 1112 VTY_DECLVAR_CONTEXT(bgp, bgp);
1113 bgp_confederation_id_unset(bgp);
718e3744 1114
d62a17ae 1115 return CMD_SUCCESS;
718e3744 1116}
1117
718e3744 1118DEFUN (bgp_confederation_peers,
1119 bgp_confederation_peers_cmd,
12dcf78e 1120 "bgp confederation peers (1-4294967295)...",
718e3744 1121 "BGP specific commands\n"
1122 "AS confederation parameters\n"
1123 "Peer ASs in BGP confederation\n"
1124 AS_STR)
1125{
d62a17ae 1126 VTY_DECLVAR_CONTEXT(bgp, bgp);
1127 int idx_asn = 3;
1128 as_t as;
1129 int i;
718e3744 1130
d62a17ae 1131 for (i = idx_asn; i < argc; i++) {
1132 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1133
d62a17ae 1134 if (bgp->as == as) {
1135 vty_out(vty,
1136 "%% Local member-AS not allowed in confed peer list\n");
1137 continue;
1138 }
718e3744 1139
d62a17ae 1140 bgp_confederation_peers_add(bgp, as);
1141 }
1142 return CMD_SUCCESS;
718e3744 1143}
1144
1145DEFUN (no_bgp_confederation_peers,
1146 no_bgp_confederation_peers_cmd,
e83a9414 1147 "no bgp confederation peers (1-4294967295)...",
718e3744 1148 NO_STR
1149 "BGP specific commands\n"
1150 "AS confederation parameters\n"
1151 "Peer ASs in BGP confederation\n"
1152 AS_STR)
1153{
d62a17ae 1154 VTY_DECLVAR_CONTEXT(bgp, bgp);
1155 int idx_asn = 4;
1156 as_t as;
1157 int i;
718e3744 1158
d62a17ae 1159 for (i = idx_asn; i < argc; i++) {
1160 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1161
d62a17ae 1162 bgp_confederation_peers_remove(bgp, as);
1163 }
1164 return CMD_SUCCESS;
718e3744 1165}
6b0655a2 1166
5e242b0d
DS
1167/**
1168 * Central routine for maximum-paths configuration.
1169 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1170 * @set: 1 for setting values, 0 for removing the max-paths config.
1171 */
d62a17ae 1172static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1173 const char *mpaths, uint16_t options,
d62a17ae 1174 int set)
1175{
1176 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1177 uint16_t maxpaths = 0;
d62a17ae 1178 int ret;
1179 afi_t afi;
1180 safi_t safi;
1181
1182 afi = bgp_node_afi(vty);
1183 safi = bgp_node_safi(vty);
1184
1185 if (set) {
1186 maxpaths = strtol(mpaths, NULL, 10);
1187 if (maxpaths > multipath_num) {
1188 vty_out(vty,
1189 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1190 maxpaths, multipath_num);
1191 return CMD_WARNING_CONFIG_FAILED;
1192 }
1193 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1194 options);
1195 } else
1196 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1197
1198 if (ret < 0) {
1199 vty_out(vty,
1200 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1201 (set == 1) ? "" : "un",
1202 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1203 maxpaths, afi, safi);
1204 return CMD_WARNING_CONFIG_FAILED;
1205 }
1206
1207 bgp_recalculate_all_bestpaths(bgp);
1208
1209 return CMD_SUCCESS;
165b5fff
JB
1210}
1211
abc920f8
DS
1212DEFUN (bgp_maxmed_admin,
1213 bgp_maxmed_admin_cmd,
1214 "bgp max-med administrative ",
1215 BGP_STR
1216 "Advertise routes with max-med\n"
1217 "Administratively applied, for an indefinite period\n")
1218{
d62a17ae 1219 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1220
d62a17ae 1221 bgp->v_maxmed_admin = 1;
1222 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1223
d62a17ae 1224 bgp_maxmed_update(bgp);
abc920f8 1225
d62a17ae 1226 return CMD_SUCCESS;
abc920f8
DS
1227}
1228
1229DEFUN (bgp_maxmed_admin_medv,
1230 bgp_maxmed_admin_medv_cmd,
4668a151 1231 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1232 BGP_STR
1233 "Advertise routes with max-med\n"
1234 "Administratively applied, for an indefinite period\n"
1235 "Max MED value to be used\n")
1236{
d62a17ae 1237 VTY_DECLVAR_CONTEXT(bgp, bgp);
1238 int idx_number = 3;
abc920f8 1239
d62a17ae 1240 bgp->v_maxmed_admin = 1;
1241 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1242
d62a17ae 1243 bgp_maxmed_update(bgp);
abc920f8 1244
d62a17ae 1245 return CMD_SUCCESS;
abc920f8
DS
1246}
1247
1248DEFUN (no_bgp_maxmed_admin,
1249 no_bgp_maxmed_admin_cmd,
4668a151 1250 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1251 NO_STR
1252 BGP_STR
1253 "Advertise routes with max-med\n"
838758ac
DW
1254 "Administratively applied, for an indefinite period\n"
1255 "Max MED value to be used\n")
abc920f8 1256{
d62a17ae 1257 VTY_DECLVAR_CONTEXT(bgp, bgp);
1258 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1259 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1260 bgp_maxmed_update(bgp);
abc920f8 1261
d62a17ae 1262 return CMD_SUCCESS;
abc920f8
DS
1263}
1264
abc920f8
DS
1265DEFUN (bgp_maxmed_onstartup,
1266 bgp_maxmed_onstartup_cmd,
4668a151 1267 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1268 BGP_STR
1269 "Advertise routes with max-med\n"
1270 "Effective on a startup\n"
1271 "Time (seconds) period for max-med\n"
1272 "Max MED value to be used\n")
1273{
d62a17ae 1274 VTY_DECLVAR_CONTEXT(bgp, bgp);
1275 int idx = 0;
4668a151 1276
d62a17ae 1277 argv_find(argv, argc, "(5-86400)", &idx);
1278 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1279 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1280 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1281 else
1282 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1283
d62a17ae 1284 bgp_maxmed_update(bgp);
abc920f8 1285
d62a17ae 1286 return CMD_SUCCESS;
abc920f8
DS
1287}
1288
1289DEFUN (no_bgp_maxmed_onstartup,
1290 no_bgp_maxmed_onstartup_cmd,
4668a151 1291 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1292 NO_STR
1293 BGP_STR
1294 "Advertise routes with max-med\n"
838758ac
DW
1295 "Effective on a startup\n"
1296 "Time (seconds) period for max-med\n"
1297 "Max MED value to be used\n")
abc920f8 1298{
d62a17ae 1299 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1300
d62a17ae 1301 /* Cancel max-med onstartup if its on */
1302 if (bgp->t_maxmed_onstartup) {
1303 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1304 bgp->maxmed_onstartup_over = 1;
1305 }
abc920f8 1306
d62a17ae 1307 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1308 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1309
d62a17ae 1310 bgp_maxmed_update(bgp);
abc920f8 1311
d62a17ae 1312 return CMD_SUCCESS;
abc920f8
DS
1313}
1314
d62a17ae 1315static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1316 const char *wait)
f188f2c4 1317{
d62a17ae 1318 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1319 uint16_t update_delay;
1320 uint16_t establish_wait;
f188f2c4 1321
d62a17ae 1322 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1323
d62a17ae 1324 if (!wait) /* update-delay <delay> */
1325 {
1326 bgp->v_update_delay = update_delay;
1327 bgp->v_establish_wait = bgp->v_update_delay;
1328 return CMD_SUCCESS;
1329 }
f188f2c4 1330
d62a17ae 1331 /* update-delay <delay> <establish-wait> */
1332 establish_wait = atoi(wait);
1333 if (update_delay < establish_wait) {
1334 vty_out(vty,
1335 "%%Failed: update-delay less than the establish-wait!\n");
1336 return CMD_WARNING_CONFIG_FAILED;
1337 }
f188f2c4 1338
d62a17ae 1339 bgp->v_update_delay = update_delay;
1340 bgp->v_establish_wait = establish_wait;
f188f2c4 1341
d62a17ae 1342 return CMD_SUCCESS;
f188f2c4
DS
1343}
1344
d62a17ae 1345static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1346{
d62a17ae 1347 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1348
d62a17ae 1349 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1350 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1351
d62a17ae 1352 return CMD_SUCCESS;
f188f2c4
DS
1353}
1354
2b791107 1355void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1356{
d62a17ae 1357 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1358 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1359 if (bgp->v_update_delay != bgp->v_establish_wait)
1360 vty_out(vty, " %d", bgp->v_establish_wait);
1361 vty_out(vty, "\n");
1362 }
f188f2c4
DS
1363}
1364
1365
1366/* Update-delay configuration */
1367DEFUN (bgp_update_delay,
1368 bgp_update_delay_cmd,
6147e2c6 1369 "update-delay (0-3600)",
f188f2c4
DS
1370 "Force initial delay for best-path and updates\n"
1371 "Seconds\n")
1372{
d62a17ae 1373 int idx_number = 1;
1374 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1375}
1376
1377DEFUN (bgp_update_delay_establish_wait,
1378 bgp_update_delay_establish_wait_cmd,
6147e2c6 1379 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1380 "Force initial delay for best-path and updates\n"
1381 "Seconds\n"
f188f2c4
DS
1382 "Seconds\n")
1383{
d62a17ae 1384 int idx_number = 1;
1385 int idx_number_2 = 2;
1386 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1387 argv[idx_number_2]->arg);
f188f2c4
DS
1388}
1389
1390/* Update-delay deconfiguration */
1391DEFUN (no_bgp_update_delay,
1392 no_bgp_update_delay_cmd,
838758ac
DW
1393 "no update-delay [(0-3600) [(1-3600)]]",
1394 NO_STR
f188f2c4 1395 "Force initial delay for best-path and updates\n"
838758ac 1396 "Seconds\n"
7111c1a0 1397 "Seconds\n")
f188f2c4 1398{
d62a17ae 1399 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1400}
1401
5e242b0d 1402
d62a17ae 1403static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1404 char set)
cb1faec9 1405{
d62a17ae 1406 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1407
555e09d4
QY
1408 if (set) {
1409 uint32_t quanta = strtoul(num, NULL, 10);
1410 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1411 memory_order_relaxed);
1412 } else {
1413 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1414 memory_order_relaxed);
1415 }
1416
1417 return CMD_SUCCESS;
1418}
1419
1420static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1421 char set)
1422{
1423 VTY_DECLVAR_CONTEXT(bgp, bgp);
1424
1425 if (set) {
1426 uint32_t quanta = strtoul(num, NULL, 10);
1427 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1428 memory_order_relaxed);
1429 } else {
1430 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1431 memory_order_relaxed);
1432 }
cb1faec9 1433
d62a17ae 1434 return CMD_SUCCESS;
cb1faec9
DS
1435}
1436
2b791107 1437void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1438{
555e09d4
QY
1439 uint32_t quanta =
1440 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1441 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1442 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1443}
1444
555e09d4
QY
1445void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1446{
1447 uint32_t quanta =
1448 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1449 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1450 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1451}
cb1faec9 1452
555e09d4 1453/* Packet quanta configuration */
cb1faec9
DS
1454DEFUN (bgp_wpkt_quanta,
1455 bgp_wpkt_quanta_cmd,
555e09d4 1456 "write-quanta (1-10)",
cb1faec9
DS
1457 "How many packets to write to peer socket per run\n"
1458 "Number of packets\n")
1459{
d62a17ae 1460 int idx_number = 1;
1461 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1462}
1463
cb1faec9
DS
1464DEFUN (no_bgp_wpkt_quanta,
1465 no_bgp_wpkt_quanta_cmd,
555e09d4 1466 "no write-quanta (1-10)",
d7fa34c1 1467 NO_STR
555e09d4 1468 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1469 "Number of packets\n")
1470{
d62a17ae 1471 int idx_number = 2;
1472 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1473}
1474
555e09d4
QY
1475DEFUN (bgp_rpkt_quanta,
1476 bgp_rpkt_quanta_cmd,
1477 "read-quanta (1-10)",
1478 "How many packets to read from peer socket per I/O cycle\n"
1479 "Number of packets\n")
1480{
1481 int idx_number = 1;
1482 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1483}
1484
1485DEFUN (no_bgp_rpkt_quanta,
1486 no_bgp_rpkt_quanta_cmd,
1487 "no read-quanta (1-10)",
1488 NO_STR
1489 "How many packets to read from peer socket per I/O cycle\n"
1490 "Number of packets\n")
1491{
1492 int idx_number = 2;
1493 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1494}
1495
2b791107 1496void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1497{
37a333fe 1498 if (!bgp->heuristic_coalesce)
d62a17ae 1499 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1500}
1501
1502
1503DEFUN (bgp_coalesce_time,
1504 bgp_coalesce_time_cmd,
6147e2c6 1505 "coalesce-time (0-4294967295)",
3f9c7369
DS
1506 "Subgroup coalesce timer\n"
1507 "Subgroup coalesce timer value (in ms)\n")
1508{
d62a17ae 1509 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1510
d62a17ae 1511 int idx = 0;
1512 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1513 bgp->heuristic_coalesce = false;
d62a17ae 1514 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1515 return CMD_SUCCESS;
3f9c7369
DS
1516}
1517
1518DEFUN (no_bgp_coalesce_time,
1519 no_bgp_coalesce_time_cmd,
6147e2c6 1520 "no coalesce-time (0-4294967295)",
3a2d747c 1521 NO_STR
3f9c7369
DS
1522 "Subgroup coalesce timer\n"
1523 "Subgroup coalesce timer value (in ms)\n")
1524{
d62a17ae 1525 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1526
37a333fe 1527 bgp->heuristic_coalesce = true;
d62a17ae 1528 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1529 return CMD_SUCCESS;
3f9c7369
DS
1530}
1531
5e242b0d
DS
1532/* Maximum-paths configuration */
1533DEFUN (bgp_maxpaths,
1534 bgp_maxpaths_cmd,
6319fd63 1535 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1536 "Forward packets over multiple paths\n"
1537 "Number of paths\n")
1538{
d62a17ae 1539 int idx_number = 1;
1540 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1541 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1542}
1543
d62a17ae 1544ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1545 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1546 "Forward packets over multiple paths\n"
1547 "Number of paths\n")
596c17ba 1548
165b5fff
JB
1549DEFUN (bgp_maxpaths_ibgp,
1550 bgp_maxpaths_ibgp_cmd,
6319fd63 1551 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1552 "Forward packets over multiple paths\n"
1553 "iBGP-multipath\n"
1554 "Number of paths\n")
1555{
d62a17ae 1556 int idx_number = 2;
1557 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1558 argv[idx_number]->arg, 0, 1);
5e242b0d 1559}
165b5fff 1560
d62a17ae 1561ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1562 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1563 "Forward packets over multiple paths\n"
1564 "iBGP-multipath\n"
1565 "Number of paths\n")
596c17ba 1566
5e242b0d
DS
1567DEFUN (bgp_maxpaths_ibgp_cluster,
1568 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1569 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1570 "Forward packets over multiple paths\n"
1571 "iBGP-multipath\n"
1572 "Number of paths\n"
1573 "Match the cluster length\n")
1574{
d62a17ae 1575 int idx_number = 2;
1576 return bgp_maxpaths_config_vty(
1577 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1578 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1579}
1580
d62a17ae 1581ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1582 "maximum-paths ibgp " CMD_RANGE_STR(
1583 1, MULTIPATH_NUM) " equal-cluster-length",
1584 "Forward packets over multiple paths\n"
1585 "iBGP-multipath\n"
1586 "Number of paths\n"
1587 "Match the cluster length\n")
596c17ba 1588
165b5fff
JB
1589DEFUN (no_bgp_maxpaths,
1590 no_bgp_maxpaths_cmd,
6319fd63 1591 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1592 NO_STR
1593 "Forward packets over multiple paths\n"
1594 "Number of paths\n")
1595{
d62a17ae 1596 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1597}
1598
d62a17ae 1599ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1600 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1601 "Forward packets over multiple paths\n"
1602 "Number of paths\n")
596c17ba 1603
165b5fff
JB
1604DEFUN (no_bgp_maxpaths_ibgp,
1605 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1606 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1607 NO_STR
1608 "Forward packets over multiple paths\n"
1609 "iBGP-multipath\n"
838758ac
DW
1610 "Number of paths\n"
1611 "Match the cluster length\n")
165b5fff 1612{
d62a17ae 1613 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1614}
1615
d62a17ae 1616ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1617 "no maximum-paths ibgp [" CMD_RANGE_STR(
1618 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1619 NO_STR
1620 "Forward packets over multiple paths\n"
1621 "iBGP-multipath\n"
1622 "Number of paths\n"
1623 "Match the cluster length\n")
596c17ba 1624
2b791107 1625void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1626 safi_t safi)
165b5fff 1627{
d62a17ae 1628 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1629 vty_out(vty, " maximum-paths %d\n",
1630 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1631 }
165b5fff 1632
d62a17ae 1633 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1634 vty_out(vty, " maximum-paths ibgp %d",
1635 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1636 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1637 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1638 vty_out(vty, " equal-cluster-length");
1639 vty_out(vty, "\n");
1640 }
165b5fff 1641}
6b0655a2 1642
718e3744 1643/* BGP timers. */
1644
1645DEFUN (bgp_timers,
1646 bgp_timers_cmd,
6147e2c6 1647 "timers bgp (0-65535) (0-65535)",
718e3744 1648 "Adjust routing timers\n"
1649 "BGP timers\n"
1650 "Keepalive interval\n"
1651 "Holdtime\n")
1652{
d62a17ae 1653 VTY_DECLVAR_CONTEXT(bgp, bgp);
1654 int idx_number = 2;
1655 int idx_number_2 = 3;
1656 unsigned long keepalive = 0;
1657 unsigned long holdtime = 0;
718e3744 1658
d62a17ae 1659 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1660 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1661
d62a17ae 1662 /* Holdtime value check. */
1663 if (holdtime < 3 && holdtime != 0) {
1664 vty_out(vty,
1665 "%% hold time value must be either 0 or greater than 3\n");
1666 return CMD_WARNING_CONFIG_FAILED;
1667 }
718e3744 1668
d62a17ae 1669 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1670
d62a17ae 1671 return CMD_SUCCESS;
718e3744 1672}
1673
1674DEFUN (no_bgp_timers,
1675 no_bgp_timers_cmd,
838758ac 1676 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1677 NO_STR
1678 "Adjust routing timers\n"
838758ac
DW
1679 "BGP timers\n"
1680 "Keepalive interval\n"
1681 "Holdtime\n")
718e3744 1682{
d62a17ae 1683 VTY_DECLVAR_CONTEXT(bgp, bgp);
1684 bgp_timers_unset(bgp);
718e3744 1685
d62a17ae 1686 return CMD_SUCCESS;
718e3744 1687}
1688
6b0655a2 1689
718e3744 1690DEFUN (bgp_client_to_client_reflection,
1691 bgp_client_to_client_reflection_cmd,
1692 "bgp client-to-client reflection",
1693 "BGP specific commands\n"
1694 "Configure client to client route reflection\n"
1695 "reflection of routes allowed\n")
1696{
d62a17ae 1697 VTY_DECLVAR_CONTEXT(bgp, bgp);
1698 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1699 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1700
d62a17ae 1701 return CMD_SUCCESS;
718e3744 1702}
1703
1704DEFUN (no_bgp_client_to_client_reflection,
1705 no_bgp_client_to_client_reflection_cmd,
1706 "no bgp client-to-client reflection",
1707 NO_STR
1708 "BGP specific commands\n"
1709 "Configure client to client route reflection\n"
1710 "reflection of routes allowed\n")
1711{
d62a17ae 1712 VTY_DECLVAR_CONTEXT(bgp, bgp);
1713 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1714 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1715
d62a17ae 1716 return CMD_SUCCESS;
718e3744 1717}
1718
1719/* "bgp always-compare-med" configuration. */
1720DEFUN (bgp_always_compare_med,
1721 bgp_always_compare_med_cmd,
1722 "bgp always-compare-med",
1723 "BGP specific commands\n"
1724 "Allow comparing MED from different neighbors\n")
1725{
d62a17ae 1726 VTY_DECLVAR_CONTEXT(bgp, bgp);
1727 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1728 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1729
d62a17ae 1730 return CMD_SUCCESS;
718e3744 1731}
1732
1733DEFUN (no_bgp_always_compare_med,
1734 no_bgp_always_compare_med_cmd,
1735 "no bgp always-compare-med",
1736 NO_STR
1737 "BGP specific commands\n"
1738 "Allow comparing MED from different neighbors\n")
1739{
d62a17ae 1740 VTY_DECLVAR_CONTEXT(bgp, bgp);
1741 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1742 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1743
d62a17ae 1744 return CMD_SUCCESS;
718e3744 1745}
6b0655a2 1746
718e3744 1747/* "bgp deterministic-med" configuration. */
1748DEFUN (bgp_deterministic_med,
1749 bgp_deterministic_med_cmd,
1750 "bgp deterministic-med",
1751 "BGP specific commands\n"
1752 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1753{
d62a17ae 1754 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1755
d62a17ae 1756 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1757 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1758 bgp_recalculate_all_bestpaths(bgp);
1759 }
7aafcaca 1760
d62a17ae 1761 return CMD_SUCCESS;
718e3744 1762}
1763
1764DEFUN (no_bgp_deterministic_med,
1765 no_bgp_deterministic_med_cmd,
1766 "no bgp deterministic-med",
1767 NO_STR
1768 "BGP specific commands\n"
1769 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1770{
d62a17ae 1771 VTY_DECLVAR_CONTEXT(bgp, bgp);
1772 int bestpath_per_as_used;
1773 afi_t afi;
1774 safi_t safi;
1775 struct peer *peer;
1776 struct listnode *node, *nnode;
1777
1778 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1779 bestpath_per_as_used = 0;
1780
1781 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc
QY
1782 FOREACH_AFI_SAFI (afi, safi)
1783 if (CHECK_FLAG(
1784 peer->af_flags[afi][safi],
1785 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1786 bestpath_per_as_used = 1;
1787 break;
1788 }
d62a17ae 1789
1790 if (bestpath_per_as_used)
1791 break;
1792 }
1793
1794 if (bestpath_per_as_used) {
1795 vty_out(vty,
1796 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1797 return CMD_WARNING_CONFIG_FAILED;
1798 } else {
1799 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1800 bgp_recalculate_all_bestpaths(bgp);
1801 }
1802 }
1803
1804 return CMD_SUCCESS;
718e3744 1805}
538621f2 1806
1807/* "bgp graceful-restart" configuration. */
1808DEFUN (bgp_graceful_restart,
1809 bgp_graceful_restart_cmd,
1810 "bgp graceful-restart",
1811 "BGP specific commands\n"
1812 "Graceful restart capability parameters\n")
1813{
d62a17ae 1814 VTY_DECLVAR_CONTEXT(bgp, bgp);
1815 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1816 return CMD_SUCCESS;
538621f2 1817}
1818
1819DEFUN (no_bgp_graceful_restart,
1820 no_bgp_graceful_restart_cmd,
1821 "no bgp graceful-restart",
1822 NO_STR
1823 "BGP specific commands\n"
1824 "Graceful restart capability parameters\n")
1825{
d62a17ae 1826 VTY_DECLVAR_CONTEXT(bgp, bgp);
1827 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1828 return CMD_SUCCESS;
538621f2 1829}
1830
93406d87 1831DEFUN (bgp_graceful_restart_stalepath_time,
1832 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1833 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1834 "BGP specific commands\n"
1835 "Graceful restart capability parameters\n"
1836 "Set the max time to hold onto restarting peer's stale paths\n"
1837 "Delay value (seconds)\n")
1838{
d62a17ae 1839 VTY_DECLVAR_CONTEXT(bgp, bgp);
1840 int idx_number = 3;
d7c0a89a 1841 uint32_t stalepath;
93406d87 1842
d62a17ae 1843 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1844 bgp->stalepath_time = stalepath;
1845 return CMD_SUCCESS;
93406d87 1846}
1847
eb6f1b41
PG
1848DEFUN (bgp_graceful_restart_restart_time,
1849 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1850 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1851 "BGP specific commands\n"
1852 "Graceful restart capability parameters\n"
1853 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1854 "Delay value (seconds)\n")
1855{
d62a17ae 1856 VTY_DECLVAR_CONTEXT(bgp, bgp);
1857 int idx_number = 3;
d7c0a89a 1858 uint32_t restart;
eb6f1b41 1859
d62a17ae 1860 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1861 bgp->restart_time = restart;
1862 return CMD_SUCCESS;
eb6f1b41
PG
1863}
1864
93406d87 1865DEFUN (no_bgp_graceful_restart_stalepath_time,
1866 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1867 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1868 NO_STR
1869 "BGP specific commands\n"
1870 "Graceful restart capability parameters\n"
838758ac
DW
1871 "Set the max time to hold onto restarting peer's stale paths\n"
1872 "Delay value (seconds)\n")
93406d87 1873{
d62a17ae 1874 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1875
d62a17ae 1876 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1877 return CMD_SUCCESS;
93406d87 1878}
1879
eb6f1b41
PG
1880DEFUN (no_bgp_graceful_restart_restart_time,
1881 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1882 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1883 NO_STR
1884 "BGP specific commands\n"
1885 "Graceful restart capability parameters\n"
838758ac
DW
1886 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1887 "Delay value (seconds)\n")
eb6f1b41 1888{
d62a17ae 1889 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1890
d62a17ae 1891 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1892 return CMD_SUCCESS;
eb6f1b41
PG
1893}
1894
43fc21b3
JC
1895DEFUN (bgp_graceful_restart_preserve_fw,
1896 bgp_graceful_restart_preserve_fw_cmd,
1897 "bgp graceful-restart preserve-fw-state",
1898 "BGP specific commands\n"
1899 "Graceful restart capability parameters\n"
1900 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1901{
d62a17ae 1902 VTY_DECLVAR_CONTEXT(bgp, bgp);
1903 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1904 return CMD_SUCCESS;
43fc21b3
JC
1905}
1906
1907DEFUN (no_bgp_graceful_restart_preserve_fw,
1908 no_bgp_graceful_restart_preserve_fw_cmd,
1909 "no bgp graceful-restart preserve-fw-state",
1910 NO_STR
1911 "BGP specific commands\n"
1912 "Graceful restart capability parameters\n"
1913 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1914{
d62a17ae 1915 VTY_DECLVAR_CONTEXT(bgp, bgp);
1916 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1917 return CMD_SUCCESS;
43fc21b3
JC
1918}
1919
7f323236
DW
1920static void bgp_redistribute_redo(struct bgp *bgp)
1921{
1922 afi_t afi;
1923 int i;
1924 struct list *red_list;
1925 struct listnode *node;
1926 struct bgp_redist *red;
1927
a4d82a8a
PZ
1928 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1929 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 1930
a4d82a8a
PZ
1931 red_list = bgp->redist[afi][i];
1932 if (!red_list)
1933 continue;
7f323236 1934
a4d82a8a 1935 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
1936 bgp_redistribute_resend(bgp, afi, i,
1937 red->instance);
1938 }
1939 }
1940 }
1941}
1942
1943/* "bgp graceful-shutdown" configuration */
1944DEFUN (bgp_graceful_shutdown,
1945 bgp_graceful_shutdown_cmd,
1946 "bgp graceful-shutdown",
1947 BGP_STR
1948 "Graceful shutdown parameters\n")
1949{
1950 VTY_DECLVAR_CONTEXT(bgp, bgp);
1951
1952 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1953 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1954 bgp_static_redo_import_check(bgp);
1955 bgp_redistribute_redo(bgp);
1956 bgp_clear_star_soft_out(vty, bgp->name);
1957 bgp_clear_star_soft_in(vty, bgp->name);
1958 }
1959
1960 return CMD_SUCCESS;
1961}
1962
1963DEFUN (no_bgp_graceful_shutdown,
1964 no_bgp_graceful_shutdown_cmd,
1965 "no bgp graceful-shutdown",
1966 NO_STR
1967 BGP_STR
1968 "Graceful shutdown parameters\n")
1969{
1970 VTY_DECLVAR_CONTEXT(bgp, bgp);
1971
1972 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1973 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1974 bgp_static_redo_import_check(bgp);
1975 bgp_redistribute_redo(bgp);
1976 bgp_clear_star_soft_out(vty, bgp->name);
1977 bgp_clear_star_soft_in(vty, bgp->name);
1978 }
1979
1980 return CMD_SUCCESS;
1981}
1982
718e3744 1983/* "bgp fast-external-failover" configuration. */
1984DEFUN (bgp_fast_external_failover,
1985 bgp_fast_external_failover_cmd,
1986 "bgp fast-external-failover",
1987 BGP_STR
1988 "Immediately reset session if a link to a directly connected external peer goes down\n")
1989{
d62a17ae 1990 VTY_DECLVAR_CONTEXT(bgp, bgp);
1991 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1992 return CMD_SUCCESS;
718e3744 1993}
1994
1995DEFUN (no_bgp_fast_external_failover,
1996 no_bgp_fast_external_failover_cmd,
1997 "no bgp fast-external-failover",
1998 NO_STR
1999 BGP_STR
2000 "Immediately reset session if a link to a directly connected external peer goes down\n")
2001{
d62a17ae 2002 VTY_DECLVAR_CONTEXT(bgp, bgp);
2003 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2004 return CMD_SUCCESS;
718e3744 2005}
6b0655a2 2006
718e3744 2007/* "bgp enforce-first-as" configuration. */
47cbc09b
PM
2008#if defined(VERSION_TYPE_DEV) && CONFDATE > 20180517
2009CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2010#endif
2011
f07e1c4f
QY
2012DEFUN_HIDDEN (bgp_enforce_first_as,
2013 bgp_enforce_first_as_cmd,
2014 "[no] bgp enforce-first-as",
2015 NO_STR
2016 BGP_STR
2017 "Enforce the first AS for EBGP routes\n")
718e3744 2018{
d62a17ae 2019 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2020
f07e1c4f
QY
2021 if (strmatch(argv[0]->text, "no"))
2022 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2023 else
2024 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
7aafcaca 2025
d62a17ae 2026 return CMD_SUCCESS;
718e3744 2027}
6b0655a2 2028
718e3744 2029/* "bgp bestpath compare-routerid" configuration. */
2030DEFUN (bgp_bestpath_compare_router_id,
2031 bgp_bestpath_compare_router_id_cmd,
2032 "bgp bestpath compare-routerid",
2033 "BGP specific commands\n"
2034 "Change the default bestpath selection\n"
2035 "Compare router-id for identical EBGP paths\n")
2036{
d62a17ae 2037 VTY_DECLVAR_CONTEXT(bgp, bgp);
2038 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2039 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2040
d62a17ae 2041 return CMD_SUCCESS;
718e3744 2042}
2043
2044DEFUN (no_bgp_bestpath_compare_router_id,
2045 no_bgp_bestpath_compare_router_id_cmd,
2046 "no bgp bestpath compare-routerid",
2047 NO_STR
2048 "BGP specific commands\n"
2049 "Change the default bestpath selection\n"
2050 "Compare router-id for identical EBGP paths\n")
2051{
d62a17ae 2052 VTY_DECLVAR_CONTEXT(bgp, bgp);
2053 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2054 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2055
d62a17ae 2056 return CMD_SUCCESS;
718e3744 2057}
6b0655a2 2058
718e3744 2059/* "bgp bestpath as-path ignore" configuration. */
2060DEFUN (bgp_bestpath_aspath_ignore,
2061 bgp_bestpath_aspath_ignore_cmd,
2062 "bgp bestpath as-path ignore",
2063 "BGP specific commands\n"
2064 "Change the default bestpath selection\n"
2065 "AS-path attribute\n"
2066 "Ignore as-path length in selecting a route\n")
2067{
d62a17ae 2068 VTY_DECLVAR_CONTEXT(bgp, bgp);
2069 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2070 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2071
d62a17ae 2072 return CMD_SUCCESS;
718e3744 2073}
2074
2075DEFUN (no_bgp_bestpath_aspath_ignore,
2076 no_bgp_bestpath_aspath_ignore_cmd,
2077 "no bgp bestpath as-path ignore",
2078 NO_STR
2079 "BGP specific commands\n"
2080 "Change the default bestpath selection\n"
2081 "AS-path attribute\n"
2082 "Ignore as-path length in selecting a route\n")
2083{
d62a17ae 2084 VTY_DECLVAR_CONTEXT(bgp, bgp);
2085 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2086 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2087
d62a17ae 2088 return CMD_SUCCESS;
718e3744 2089}
6b0655a2 2090
6811845b 2091/* "bgp bestpath as-path confed" configuration. */
2092DEFUN (bgp_bestpath_aspath_confed,
2093 bgp_bestpath_aspath_confed_cmd,
2094 "bgp bestpath as-path confed",
2095 "BGP specific commands\n"
2096 "Change the default bestpath selection\n"
2097 "AS-path attribute\n"
2098 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2099{
d62a17ae 2100 VTY_DECLVAR_CONTEXT(bgp, bgp);
2101 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2102 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2103
d62a17ae 2104 return CMD_SUCCESS;
6811845b 2105}
2106
2107DEFUN (no_bgp_bestpath_aspath_confed,
2108 no_bgp_bestpath_aspath_confed_cmd,
2109 "no bgp bestpath as-path confed",
2110 NO_STR
2111 "BGP specific commands\n"
2112 "Change the default bestpath selection\n"
2113 "AS-path attribute\n"
2114 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2115{
d62a17ae 2116 VTY_DECLVAR_CONTEXT(bgp, bgp);
2117 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2118 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2119
d62a17ae 2120 return CMD_SUCCESS;
6811845b 2121}
6b0655a2 2122
2fdd455c
PM
2123/* "bgp bestpath as-path multipath-relax" configuration. */
2124DEFUN (bgp_bestpath_aspath_multipath_relax,
2125 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2126 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2127 "BGP specific commands\n"
2128 "Change the default bestpath selection\n"
2129 "AS-path attribute\n"
2130 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2131 "Generate an AS_SET\n"
16fc1eec
DS
2132 "Do not generate an AS_SET\n")
2133{
d62a17ae 2134 VTY_DECLVAR_CONTEXT(bgp, bgp);
2135 int idx = 0;
2136 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2137
d62a17ae 2138 /* no-as-set is now the default behavior so we can silently
2139 * ignore it */
2140 if (argv_find(argv, argc, "as-set", &idx))
2141 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2142 else
2143 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2144
d62a17ae 2145 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2146
d62a17ae 2147 return CMD_SUCCESS;
16fc1eec
DS
2148}
2149
219178b6
DW
2150DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2151 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2152 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2153 NO_STR
2154 "BGP specific commands\n"
2155 "Change the default bestpath selection\n"
2156 "AS-path attribute\n"
2157 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2158 "Generate an AS_SET\n"
16fc1eec
DS
2159 "Do not generate an AS_SET\n")
2160{
d62a17ae 2161 VTY_DECLVAR_CONTEXT(bgp, bgp);
2162 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2163 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2164 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2165
d62a17ae 2166 return CMD_SUCCESS;
2fdd455c 2167}
6b0655a2 2168
848973c7 2169/* "bgp log-neighbor-changes" configuration. */
2170DEFUN (bgp_log_neighbor_changes,
2171 bgp_log_neighbor_changes_cmd,
2172 "bgp log-neighbor-changes",
2173 "BGP specific commands\n"
2174 "Log neighbor up/down and reset reason\n")
2175{
d62a17ae 2176 VTY_DECLVAR_CONTEXT(bgp, bgp);
2177 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2178 return CMD_SUCCESS;
848973c7 2179}
2180
2181DEFUN (no_bgp_log_neighbor_changes,
2182 no_bgp_log_neighbor_changes_cmd,
2183 "no bgp log-neighbor-changes",
2184 NO_STR
2185 "BGP specific commands\n"
2186 "Log neighbor up/down and reset reason\n")
2187{
d62a17ae 2188 VTY_DECLVAR_CONTEXT(bgp, bgp);
2189 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2190 return CMD_SUCCESS;
848973c7 2191}
6b0655a2 2192
718e3744 2193/* "bgp bestpath med" configuration. */
2194DEFUN (bgp_bestpath_med,
2195 bgp_bestpath_med_cmd,
2d8c1a4d 2196 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2197 "BGP specific commands\n"
2198 "Change the default bestpath selection\n"
2199 "MED attribute\n"
2200 "Compare MED among confederation paths\n"
838758ac
DW
2201 "Treat missing MED as the least preferred one\n"
2202 "Treat missing MED as the least preferred one\n"
2203 "Compare MED among confederation paths\n")
718e3744 2204{
d62a17ae 2205 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2206
d62a17ae 2207 int idx = 0;
2208 if (argv_find(argv, argc, "confed", &idx))
2209 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2210 idx = 0;
2211 if (argv_find(argv, argc, "missing-as-worst", &idx))
2212 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2213
d62a17ae 2214 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2215
d62a17ae 2216 return CMD_SUCCESS;
718e3744 2217}
2218
718e3744 2219DEFUN (no_bgp_bestpath_med,
2220 no_bgp_bestpath_med_cmd,
2d8c1a4d 2221 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2222 NO_STR
2223 "BGP specific commands\n"
2224 "Change the default bestpath selection\n"
2225 "MED attribute\n"
2226 "Compare MED among confederation paths\n"
3a2d747c
QY
2227 "Treat missing MED as the least preferred one\n"
2228 "Treat missing MED as the least preferred one\n"
2229 "Compare MED among confederation paths\n")
718e3744 2230{
d62a17ae 2231 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2232
d62a17ae 2233 int idx = 0;
2234 if (argv_find(argv, argc, "confed", &idx))
2235 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2236 idx = 0;
2237 if (argv_find(argv, argc, "missing-as-worst", &idx))
2238 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2239
d62a17ae 2240 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2241
d62a17ae 2242 return CMD_SUCCESS;
718e3744 2243}
2244
718e3744 2245/* "no bgp default ipv4-unicast". */
2246DEFUN (no_bgp_default_ipv4_unicast,
2247 no_bgp_default_ipv4_unicast_cmd,
2248 "no bgp default ipv4-unicast",
2249 NO_STR
2250 "BGP specific commands\n"
2251 "Configure BGP defaults\n"
2252 "Activate ipv4-unicast for a peer by default\n")
2253{
d62a17ae 2254 VTY_DECLVAR_CONTEXT(bgp, bgp);
2255 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2256 return CMD_SUCCESS;
718e3744 2257}
2258
2259DEFUN (bgp_default_ipv4_unicast,
2260 bgp_default_ipv4_unicast_cmd,
2261 "bgp default ipv4-unicast",
2262 "BGP specific commands\n"
2263 "Configure BGP defaults\n"
2264 "Activate ipv4-unicast for a peer by default\n")
2265{
d62a17ae 2266 VTY_DECLVAR_CONTEXT(bgp, bgp);
2267 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2268 return CMD_SUCCESS;
718e3744 2269}
6b0655a2 2270
04b6bdc0
DW
2271/* Display hostname in certain command outputs */
2272DEFUN (bgp_default_show_hostname,
2273 bgp_default_show_hostname_cmd,
2274 "bgp default show-hostname",
2275 "BGP specific commands\n"
2276 "Configure BGP defaults\n"
2277 "Show hostname in certain command ouputs\n")
2278{
d62a17ae 2279 VTY_DECLVAR_CONTEXT(bgp, bgp);
2280 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2281 return CMD_SUCCESS;
04b6bdc0
DW
2282}
2283
2284DEFUN (no_bgp_default_show_hostname,
2285 no_bgp_default_show_hostname_cmd,
2286 "no bgp default show-hostname",
2287 NO_STR
2288 "BGP specific commands\n"
2289 "Configure BGP defaults\n"
2290 "Show hostname in certain command ouputs\n")
2291{
d62a17ae 2292 VTY_DECLVAR_CONTEXT(bgp, bgp);
2293 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2294 return CMD_SUCCESS;
04b6bdc0
DW
2295}
2296
8233ef81 2297/* "bgp network import-check" configuration. */
718e3744 2298DEFUN (bgp_network_import_check,
2299 bgp_network_import_check_cmd,
5623e905 2300 "bgp network import-check",
718e3744 2301 "BGP specific commands\n"
2302 "BGP network command\n"
5623e905 2303 "Check BGP network route exists in IGP\n")
718e3744 2304{
d62a17ae 2305 VTY_DECLVAR_CONTEXT(bgp, bgp);
2306 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2307 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2308 bgp_static_redo_import_check(bgp);
2309 }
078430f6 2310
d62a17ae 2311 return CMD_SUCCESS;
718e3744 2312}
2313
d62a17ae 2314ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2315 "bgp network import-check exact",
2316 "BGP specific commands\n"
2317 "BGP network command\n"
2318 "Check BGP network route exists in IGP\n"
2319 "Match route precisely\n")
8233ef81 2320
718e3744 2321DEFUN (no_bgp_network_import_check,
2322 no_bgp_network_import_check_cmd,
5623e905 2323 "no bgp network import-check",
718e3744 2324 NO_STR
2325 "BGP specific commands\n"
2326 "BGP network command\n"
2327 "Check BGP network route exists in IGP\n")
2328{
d62a17ae 2329 VTY_DECLVAR_CONTEXT(bgp, bgp);
2330 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2331 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2332 bgp_static_redo_import_check(bgp);
2333 }
5623e905 2334
d62a17ae 2335 return CMD_SUCCESS;
718e3744 2336}
6b0655a2 2337
718e3744 2338DEFUN (bgp_default_local_preference,
2339 bgp_default_local_preference_cmd,
6147e2c6 2340 "bgp default local-preference (0-4294967295)",
718e3744 2341 "BGP specific commands\n"
2342 "Configure BGP defaults\n"
2343 "local preference (higher=more preferred)\n"
2344 "Configure default local preference value\n")
2345{
d62a17ae 2346 VTY_DECLVAR_CONTEXT(bgp, bgp);
2347 int idx_number = 3;
d7c0a89a 2348 uint32_t local_pref;
718e3744 2349
d62a17ae 2350 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2351
d62a17ae 2352 bgp_default_local_preference_set(bgp, local_pref);
2353 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2354
d62a17ae 2355 return CMD_SUCCESS;
718e3744 2356}
2357
2358DEFUN (no_bgp_default_local_preference,
2359 no_bgp_default_local_preference_cmd,
838758ac 2360 "no bgp default local-preference [(0-4294967295)]",
718e3744 2361 NO_STR
2362 "BGP specific commands\n"
2363 "Configure BGP defaults\n"
838758ac
DW
2364 "local preference (higher=more preferred)\n"
2365 "Configure default local preference value\n")
718e3744 2366{
d62a17ae 2367 VTY_DECLVAR_CONTEXT(bgp, bgp);
2368 bgp_default_local_preference_unset(bgp);
2369 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2370
d62a17ae 2371 return CMD_SUCCESS;
718e3744 2372}
2373
6b0655a2 2374
3f9c7369
DS
2375DEFUN (bgp_default_subgroup_pkt_queue_max,
2376 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2377 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2378 "BGP specific commands\n"
2379 "Configure BGP defaults\n"
2380 "subgroup-pkt-queue-max\n"
2381 "Configure subgroup packet queue max\n")
8bd9d948 2382{
d62a17ae 2383 VTY_DECLVAR_CONTEXT(bgp, bgp);
2384 int idx_number = 3;
d7c0a89a 2385 uint32_t max_size;
8bd9d948 2386
d62a17ae 2387 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2388
d62a17ae 2389 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2390
d62a17ae 2391 return CMD_SUCCESS;
3f9c7369
DS
2392}
2393
2394DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2395 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2396 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2397 NO_STR
2398 "BGP specific commands\n"
2399 "Configure BGP defaults\n"
838758ac
DW
2400 "subgroup-pkt-queue-max\n"
2401 "Configure subgroup packet queue max\n")
3f9c7369 2402{
d62a17ae 2403 VTY_DECLVAR_CONTEXT(bgp, bgp);
2404 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2405 return CMD_SUCCESS;
8bd9d948
DS
2406}
2407
813d4307 2408
8bd9d948
DS
2409DEFUN (bgp_rr_allow_outbound_policy,
2410 bgp_rr_allow_outbound_policy_cmd,
2411 "bgp route-reflector allow-outbound-policy",
2412 "BGP specific commands\n"
2413 "Allow modifications made by out route-map\n"
2414 "on ibgp neighbors\n")
2415{
d62a17ae 2416 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2417
d62a17ae 2418 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2419 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2420 update_group_announce_rrclients(bgp);
2421 bgp_clear_star_soft_out(vty, bgp->name);
2422 }
8bd9d948 2423
d62a17ae 2424 return CMD_SUCCESS;
8bd9d948
DS
2425}
2426
2427DEFUN (no_bgp_rr_allow_outbound_policy,
2428 no_bgp_rr_allow_outbound_policy_cmd,
2429 "no bgp route-reflector allow-outbound-policy",
2430 NO_STR
2431 "BGP specific commands\n"
2432 "Allow modifications made by out route-map\n"
2433 "on ibgp neighbors\n")
2434{
d62a17ae 2435 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2436
d62a17ae 2437 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2438 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2439 update_group_announce_rrclients(bgp);
2440 bgp_clear_star_soft_out(vty, bgp->name);
2441 }
8bd9d948 2442
d62a17ae 2443 return CMD_SUCCESS;
8bd9d948
DS
2444}
2445
f14e6fdb
DS
2446DEFUN (bgp_listen_limit,
2447 bgp_listen_limit_cmd,
9ccf14f7 2448 "bgp listen limit (1-5000)",
f14e6fdb
DS
2449 "BGP specific commands\n"
2450 "Configure BGP defaults\n"
2451 "maximum number of BGP Dynamic Neighbors that can be created\n"
2452 "Configure Dynamic Neighbors listen limit value\n")
2453{
d62a17ae 2454 VTY_DECLVAR_CONTEXT(bgp, bgp);
2455 int idx_number = 3;
2456 int listen_limit;
f14e6fdb 2457
d62a17ae 2458 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2459
d62a17ae 2460 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2461
d62a17ae 2462 return CMD_SUCCESS;
f14e6fdb
DS
2463}
2464
2465DEFUN (no_bgp_listen_limit,
2466 no_bgp_listen_limit_cmd,
838758ac 2467 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2468 "BGP specific commands\n"
2469 "Configure BGP defaults\n"
2470 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2471 "Configure Dynamic Neighbors listen limit value to default\n"
2472 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2473{
d62a17ae 2474 VTY_DECLVAR_CONTEXT(bgp, bgp);
2475 bgp_listen_limit_unset(bgp);
2476 return CMD_SUCCESS;
f14e6fdb
DS
2477}
2478
2479
20eb8864 2480/*
2481 * Check if this listen range is already configured. Check for exact
2482 * match or overlap based on input.
2483 */
d62a17ae 2484static struct peer_group *listen_range_exists(struct bgp *bgp,
2485 struct prefix *range, int exact)
2486{
2487 struct listnode *node, *nnode;
2488 struct listnode *node1, *nnode1;
2489 struct peer_group *group;
2490 struct prefix *lr;
2491 afi_t afi;
2492 int match;
2493
2494 afi = family2afi(range->family);
2495 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2496 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2497 lr)) {
2498 if (exact)
2499 match = prefix_same(range, lr);
2500 else
2501 match = (prefix_match(range, lr)
2502 || prefix_match(lr, range));
2503 if (match)
2504 return group;
2505 }
2506 }
2507
2508 return NULL;
20eb8864 2509}
2510
f14e6fdb
DS
2511DEFUN (bgp_listen_range,
2512 bgp_listen_range_cmd,
9ccf14f7 2513 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2514 "BGP specific commands\n"
d7fa34c1
QY
2515 "Configure BGP dynamic neighbors listen range\n"
2516 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2517 NEIGHBOR_ADDR_STR
2518 "Member of the peer-group\n"
2519 "Peer-group name\n")
f14e6fdb 2520{
d62a17ae 2521 VTY_DECLVAR_CONTEXT(bgp, bgp);
2522 struct prefix range;
2523 struct peer_group *group, *existing_group;
2524 afi_t afi;
2525 int ret;
2526 int idx = 0;
2527
2528 argv_find(argv, argc, "A.B.C.D/M", &idx);
2529 argv_find(argv, argc, "X:X::X:X/M", &idx);
2530 char *prefix = argv[idx]->arg;
2531 argv_find(argv, argc, "WORD", &idx);
2532 char *peergroup = argv[idx]->arg;
2533
2534 /* Convert IP prefix string to struct prefix. */
2535 ret = str2prefix(prefix, &range);
2536 if (!ret) {
2537 vty_out(vty, "%% Malformed listen range\n");
2538 return CMD_WARNING_CONFIG_FAILED;
2539 }
2540
2541 afi = family2afi(range.family);
2542
2543 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2544 vty_out(vty,
2545 "%% Malformed listen range (link-local address)\n");
2546 return CMD_WARNING_CONFIG_FAILED;
2547 }
2548
2549 apply_mask(&range);
2550
2551 /* Check if same listen range is already configured. */
2552 existing_group = listen_range_exists(bgp, &range, 1);
2553 if (existing_group) {
2554 if (strcmp(existing_group->name, peergroup) == 0)
2555 return CMD_SUCCESS;
2556 else {
2557 vty_out(vty,
2558 "%% Same listen range is attached to peer-group %s\n",
2559 existing_group->name);
2560 return CMD_WARNING_CONFIG_FAILED;
2561 }
2562 }
2563
2564 /* Check if an overlapping listen range exists. */
2565 if (listen_range_exists(bgp, &range, 0)) {
2566 vty_out(vty,
2567 "%% Listen range overlaps with existing listen range\n");
2568 return CMD_WARNING_CONFIG_FAILED;
2569 }
2570
2571 group = peer_group_lookup(bgp, peergroup);
2572 if (!group) {
2573 vty_out(vty, "%% Configure the peer-group first\n");
2574 return CMD_WARNING_CONFIG_FAILED;
2575 }
2576
2577 ret = peer_group_listen_range_add(group, &range);
2578 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2579}
2580
2581DEFUN (no_bgp_listen_range,
2582 no_bgp_listen_range_cmd,
d7fa34c1
QY
2583 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2584 NO_STR
f14e6fdb 2585 "BGP specific commands\n"
d7fa34c1
QY
2586 "Unconfigure BGP dynamic neighbors listen range\n"
2587 "Unconfigure BGP dynamic neighbors listen range\n"
2588 NEIGHBOR_ADDR_STR
2589 "Member of the peer-group\n"
2590 "Peer-group name\n")
f14e6fdb 2591{
d62a17ae 2592 VTY_DECLVAR_CONTEXT(bgp, bgp);
2593 struct prefix range;
2594 struct peer_group *group;
2595 afi_t afi;
2596 int ret;
2597 int idx = 0;
2598
2599 argv_find(argv, argc, "A.B.C.D/M", &idx);
2600 argv_find(argv, argc, "X:X::X:X/M", &idx);
2601 char *prefix = argv[idx]->arg;
2602 argv_find(argv, argc, "WORD", &idx);
2603 char *peergroup = argv[idx]->arg;
2604
2605 /* Convert IP prefix string to struct prefix. */
2606 ret = str2prefix(prefix, &range);
2607 if (!ret) {
2608 vty_out(vty, "%% Malformed listen range\n");
2609 return CMD_WARNING_CONFIG_FAILED;
2610 }
2611
2612 afi = family2afi(range.family);
2613
2614 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2615 vty_out(vty,
2616 "%% Malformed listen range (link-local address)\n");
2617 return CMD_WARNING_CONFIG_FAILED;
2618 }
2619
2620 apply_mask(&range);
2621
2622 group = peer_group_lookup(bgp, peergroup);
2623 if (!group) {
2624 vty_out(vty, "%% Peer-group does not exist\n");
2625 return CMD_WARNING_CONFIG_FAILED;
2626 }
2627
2628 ret = peer_group_listen_range_del(group, &range);
2629 return bgp_vty_return(vty, ret);
2630}
2631
2b791107 2632void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2633{
2634 struct peer_group *group;
2635 struct listnode *node, *nnode, *rnode, *nrnode;
2636 struct prefix *range;
2637 afi_t afi;
2638 char buf[PREFIX2STR_BUFFER];
2639
2640 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2641 vty_out(vty, " bgp listen limit %d\n",
2642 bgp->dynamic_neighbors_limit);
2643
2644 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2645 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2646 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2647 nrnode, range)) {
2648 prefix2str(range, buf, sizeof(buf));
2649 vty_out(vty,
2650 " bgp listen range %s peer-group %s\n",
2651 buf, group->name);
2652 }
2653 }
2654 }
f14e6fdb
DS
2655}
2656
2657
907f92c8
DS
2658DEFUN (bgp_disable_connected_route_check,
2659 bgp_disable_connected_route_check_cmd,
2660 "bgp disable-ebgp-connected-route-check",
2661 "BGP specific commands\n"
2662 "Disable checking if nexthop is connected on ebgp sessions\n")
2663{
d62a17ae 2664 VTY_DECLVAR_CONTEXT(bgp, bgp);
2665 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2666 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2667
d62a17ae 2668 return CMD_SUCCESS;
907f92c8
DS
2669}
2670
2671DEFUN (no_bgp_disable_connected_route_check,
2672 no_bgp_disable_connected_route_check_cmd,
2673 "no bgp disable-ebgp-connected-route-check",
2674 NO_STR
2675 "BGP specific commands\n"
2676 "Disable checking if nexthop is connected on ebgp sessions\n")
2677{
d62a17ae 2678 VTY_DECLVAR_CONTEXT(bgp, bgp);
2679 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2680 bgp_clear_star_soft_in(vty, bgp->name);
2681
2682 return CMD_SUCCESS;
2683}
2684
2685
2686static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2687 const char *as_str, afi_t afi, safi_t safi)
2688{
2689 VTY_DECLVAR_CONTEXT(bgp, bgp);
2690 int ret;
2691 as_t as;
2692 int as_type = AS_SPECIFIED;
2693 union sockunion su;
2694
2695 if (as_str[0] == 'i') {
2696 as = 0;
2697 as_type = AS_INTERNAL;
2698 } else if (as_str[0] == 'e') {
2699 as = 0;
2700 as_type = AS_EXTERNAL;
2701 } else {
2702 /* Get AS number. */
2703 as = strtoul(as_str, NULL, 10);
2704 }
2705
2706 /* If peer is peer group, call proper function. */
2707 ret = str2sockunion(peer_str, &su);
2708 if (ret < 0) {
2709 /* Check for peer by interface */
2710 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2711 safi);
2712 if (ret < 0) {
2713 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2714 if (ret < 0) {
2715 vty_out(vty,
2716 "%% Create the peer-group or interface first\n");
2717 return CMD_WARNING_CONFIG_FAILED;
2718 }
2719 return CMD_SUCCESS;
2720 }
2721 } else {
2722 if (peer_address_self_check(bgp, &su)) {
2723 vty_out(vty,
2724 "%% Can not configure the local system as neighbor\n");
2725 return CMD_WARNING_CONFIG_FAILED;
2726 }
2727 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2728 }
2729
2730 /* This peer belongs to peer group. */
2731 switch (ret) {
2732 case BGP_ERR_PEER_GROUP_MEMBER:
2733 vty_out(vty,
2734 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2735 as);
2736 return CMD_WARNING_CONFIG_FAILED;
2737 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2738 vty_out(vty,
2739 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2740 as, as_str);
2741 return CMD_WARNING_CONFIG_FAILED;
2742 }
2743 return bgp_vty_return(vty, ret);
718e3744 2744}
2745
f26845f9
QY
2746DEFUN (bgp_default_shutdown,
2747 bgp_default_shutdown_cmd,
2748 "[no] bgp default shutdown",
2749 NO_STR
2750 BGP_STR
2751 "Configure BGP defaults\n"
b012cbe2 2752 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2753{
2754 VTY_DECLVAR_CONTEXT(bgp, bgp);
2755 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2756 return CMD_SUCCESS;
2757}
2758
718e3744 2759DEFUN (neighbor_remote_as,
2760 neighbor_remote_as_cmd,
3a2d747c 2761 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2762 NEIGHBOR_STR
2763 NEIGHBOR_ADDR_STR2
2764 "Specify a BGP neighbor\n"
d7fa34c1 2765 AS_STR
3a2d747c
QY
2766 "Internal BGP peer\n"
2767 "External BGP peer\n")
718e3744 2768{
d62a17ae 2769 int idx_peer = 1;
2770 int idx_remote_as = 3;
2771 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2772 argv[idx_remote_as]->arg, AFI_IP,
2773 SAFI_UNICAST);
2774}
2775
2776static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2777 afi_t afi, safi_t safi, int v6only,
2778 const char *peer_group_name,
2779 const char *as_str)
2780{
2781 VTY_DECLVAR_CONTEXT(bgp, bgp);
2782 as_t as = 0;
2783 int as_type = AS_UNSPECIFIED;
2784 struct peer *peer;
2785 struct peer_group *group;
2786 int ret = 0;
2787 union sockunion su;
2788
2789 group = peer_group_lookup(bgp, conf_if);
2790
2791 if (group) {
2792 vty_out(vty, "%% Name conflict with peer-group \n");
2793 return CMD_WARNING_CONFIG_FAILED;
2794 }
2795
2796 if (as_str) {
2797 if (as_str[0] == 'i') {
2798 as_type = AS_INTERNAL;
2799 } else if (as_str[0] == 'e') {
2800 as_type = AS_EXTERNAL;
2801 } else {
2802 /* Get AS number. */
2803 as = strtoul(as_str, NULL, 10);
2804 as_type = AS_SPECIFIED;
2805 }
2806 }
2807
2808 peer = peer_lookup_by_conf_if(bgp, conf_if);
2809 if (peer) {
2810 if (as_str)
2811 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2812 afi, safi);
2813 } else {
2814 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2815 && afi == AFI_IP && safi == SAFI_UNICAST)
2816 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2817 as_type, 0, 0, NULL);
2818 else
2819 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2820 as_type, afi, safi, NULL);
2821
2822 if (!peer) {
2823 vty_out(vty, "%% BGP failed to create peer\n");
2824 return CMD_WARNING_CONFIG_FAILED;
2825 }
2826
2827 if (v6only)
527de3dc 2828 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2829
2830 /* Request zebra to initiate IPv6 RAs on this interface. We do
2831 * this
2832 * any unnumbered peer in order to not worry about run-time
2833 * transitions
2834 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2835 * address
2836 * gets deleted later etc.)
2837 */
2838 if (peer->ifp)
2839 bgp_zebra_initiate_radv(bgp, peer);
2840 }
2841
2842 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2843 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2844 if (v6only)
527de3dc 2845 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2846 else
527de3dc 2847 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2848
2849 /* v6only flag changed. Reset bgp seesion */
2850 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2851 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2852 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2853 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2854 } else
2855 bgp_session_reset(peer);
2856 }
2857
9fb964de
PM
2858 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2859 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2860 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2861 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2862 }
d62a17ae 2863
2864 if (peer_group_name) {
2865 group = peer_group_lookup(bgp, peer_group_name);
2866 if (!group) {
2867 vty_out(vty, "%% Configure the peer-group first\n");
2868 return CMD_WARNING_CONFIG_FAILED;
2869 }
2870
2871 ret = peer_group_bind(bgp, &su, peer, group, &as);
2872 }
2873
2874 return bgp_vty_return(vty, ret);
a80beece
DS
2875}
2876
4c48cf63
DW
2877DEFUN (neighbor_interface_config,
2878 neighbor_interface_config_cmd,
31500417 2879 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2880 NEIGHBOR_STR
2881 "Interface name or neighbor tag\n"
31500417
DW
2882 "Enable BGP on interface\n"
2883 "Member of the peer-group\n"
16cedbb0 2884 "Peer-group name\n")
4c48cf63 2885{
d62a17ae 2886 int idx_word = 1;
2887 int idx_peer_group_word = 4;
31500417 2888
d62a17ae 2889 if (argc > idx_peer_group_word)
2890 return peer_conf_interface_get(
2891 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2892 argv[idx_peer_group_word]->arg, NULL);
2893 else
2894 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2895 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2896}
2897
4c48cf63
DW
2898DEFUN (neighbor_interface_config_v6only,
2899 neighbor_interface_config_v6only_cmd,
31500417 2900 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2901 NEIGHBOR_STR
2902 "Interface name or neighbor tag\n"
2903 "Enable BGP on interface\n"
31500417
DW
2904 "Enable BGP with v6 link-local only\n"
2905 "Member of the peer-group\n"
16cedbb0 2906 "Peer-group name\n")
4c48cf63 2907{
d62a17ae 2908 int idx_word = 1;
2909 int idx_peer_group_word = 5;
31500417 2910
d62a17ae 2911 if (argc > idx_peer_group_word)
2912 return peer_conf_interface_get(
2913 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2914 argv[idx_peer_group_word]->arg, NULL);
31500417 2915
d62a17ae 2916 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2917 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2918}
2919
a80beece 2920
b3a39dc5
DD
2921DEFUN (neighbor_interface_config_remote_as,
2922 neighbor_interface_config_remote_as_cmd,
3a2d747c 2923 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2924 NEIGHBOR_STR
2925 "Interface name or neighbor tag\n"
2926 "Enable BGP on interface\n"
3a2d747c 2927 "Specify a BGP neighbor\n"
d7fa34c1 2928 AS_STR
3a2d747c
QY
2929 "Internal BGP peer\n"
2930 "External BGP peer\n")
b3a39dc5 2931{
d62a17ae 2932 int idx_word = 1;
2933 int idx_remote_as = 4;
2934 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2935 SAFI_UNICAST, 0, NULL,
2936 argv[idx_remote_as]->arg);
b3a39dc5
DD
2937}
2938
2939DEFUN (neighbor_interface_v6only_config_remote_as,
2940 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2941 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2942 NEIGHBOR_STR
2943 "Interface name or neighbor tag\n"
3a2d747c 2944 "Enable BGP with v6 link-local only\n"
b3a39dc5 2945 "Enable BGP on interface\n"
3a2d747c 2946 "Specify a BGP neighbor\n"
d7fa34c1 2947 AS_STR
3a2d747c
QY
2948 "Internal BGP peer\n"
2949 "External BGP peer\n")
b3a39dc5 2950{
d62a17ae 2951 int idx_word = 1;
2952 int idx_remote_as = 5;
2953 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2954 SAFI_UNICAST, 1, NULL,
2955 argv[idx_remote_as]->arg);
b3a39dc5
DD
2956}
2957
718e3744 2958DEFUN (neighbor_peer_group,
2959 neighbor_peer_group_cmd,
2960 "neighbor WORD peer-group",
2961 NEIGHBOR_STR
a80beece 2962 "Interface name or neighbor tag\n"
718e3744 2963 "Configure peer-group\n")
2964{
d62a17ae 2965 VTY_DECLVAR_CONTEXT(bgp, bgp);
2966 int idx_word = 1;
2967 struct peer *peer;
2968 struct peer_group *group;
718e3744 2969
d62a17ae 2970 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2971 if (peer) {
2972 vty_out(vty, "%% Name conflict with interface: \n");
2973 return CMD_WARNING_CONFIG_FAILED;
2974 }
718e3744 2975
d62a17ae 2976 group = peer_group_get(bgp, argv[idx_word]->arg);
2977 if (!group) {
2978 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2979 return CMD_WARNING_CONFIG_FAILED;
2980 }
718e3744 2981
d62a17ae 2982 return CMD_SUCCESS;
718e3744 2983}
2984
2985DEFUN (no_neighbor,
2986 no_neighbor_cmd,
dab8cd00 2987 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 2988 NO_STR
2989 NEIGHBOR_STR
3a2d747c
QY
2990 NEIGHBOR_ADDR_STR2
2991 "Specify a BGP neighbor\n"
2992 AS_STR
2993 "Internal BGP peer\n"
2994 "External BGP peer\n")
718e3744 2995{
d62a17ae 2996 VTY_DECLVAR_CONTEXT(bgp, bgp);
2997 int idx_peer = 2;
2998 int ret;
2999 union sockunion su;
3000 struct peer_group *group;
3001 struct peer *peer;
3002 struct peer *other;
3003
3004 ret = str2sockunion(argv[idx_peer]->arg, &su);
3005 if (ret < 0) {
3006 /* look up for neighbor by interface name config. */
3007 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3008 if (peer) {
3009 /* Request zebra to terminate IPv6 RAs on this
3010 * interface. */
3011 if (peer->ifp)
3012 bgp_zebra_terminate_radv(peer->bgp, peer);
3013 peer_delete(peer);
3014 return CMD_SUCCESS;
3015 }
f14e6fdb 3016
d62a17ae 3017 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3018 if (group)
3019 peer_group_delete(group);
3020 else {
3021 vty_out(vty, "%% Create the peer-group first\n");
3022 return CMD_WARNING_CONFIG_FAILED;
3023 }
3024 } else {
3025 peer = peer_lookup(bgp, &su);
3026 if (peer) {
3027 if (peer_dynamic_neighbor(peer)) {
3028 vty_out(vty,
3029 "%% Operation not allowed on a dynamic neighbor\n");
3030 return CMD_WARNING_CONFIG_FAILED;
3031 }
3032
3033 other = peer->doppelganger;
3034 peer_delete(peer);
3035 if (other && other->status != Deleted)
3036 peer_delete(other);
3037 }
1ff9a340 3038 }
718e3744 3039
d62a17ae 3040 return CMD_SUCCESS;
718e3744 3041}
3042
a80beece
DS
3043DEFUN (no_neighbor_interface_config,
3044 no_neighbor_interface_config_cmd,
31500417 3045 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3046 NO_STR
3047 NEIGHBOR_STR
3048 "Interface name\n"
31500417
DW
3049 "Configure BGP on interface\n"
3050 "Enable BGP with v6 link-local only\n"
3051 "Member of the peer-group\n"
16cedbb0 3052 "Peer-group name\n"
3a2d747c
QY
3053 "Specify a BGP neighbor\n"
3054 AS_STR
3055 "Internal BGP peer\n"
3056 "External BGP peer\n")
a80beece 3057{
d62a17ae 3058 VTY_DECLVAR_CONTEXT(bgp, bgp);
3059 int idx_word = 2;
3060 struct peer *peer;
3061
3062 /* look up for neighbor by interface name config. */
3063 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3064 if (peer) {
3065 /* Request zebra to terminate IPv6 RAs on this interface. */
3066 if (peer->ifp)
3067 bgp_zebra_terminate_radv(peer->bgp, peer);
3068 peer_delete(peer);
3069 } else {
3070 vty_out(vty, "%% Create the bgp interface first\n");
3071 return CMD_WARNING_CONFIG_FAILED;
3072 }
3073 return CMD_SUCCESS;
a80beece
DS
3074}
3075
718e3744 3076DEFUN (no_neighbor_peer_group,
3077 no_neighbor_peer_group_cmd,
3078 "no neighbor WORD peer-group",
3079 NO_STR
3080 NEIGHBOR_STR
3081 "Neighbor tag\n"
3082 "Configure peer-group\n")
3083{
d62a17ae 3084 VTY_DECLVAR_CONTEXT(bgp, bgp);
3085 int idx_word = 2;
3086 struct peer_group *group;
718e3744 3087
d62a17ae 3088 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3089 if (group)
3090 peer_group_delete(group);
3091 else {
3092 vty_out(vty, "%% Create the peer-group first\n");
3093 return CMD_WARNING_CONFIG_FAILED;
3094 }
3095 return CMD_SUCCESS;
718e3744 3096}
3097
a80beece
DS
3098DEFUN (no_neighbor_interface_peer_group_remote_as,
3099 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3100 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3101 NO_STR
3102 NEIGHBOR_STR
a80beece 3103 "Interface name or neighbor tag\n"
718e3744 3104 "Specify a BGP neighbor\n"
3a2d747c
QY
3105 AS_STR
3106 "Internal BGP peer\n"
3107 "External BGP peer\n")
718e3744 3108{
d62a17ae 3109 VTY_DECLVAR_CONTEXT(bgp, bgp);
3110 int idx_word = 2;
3111 struct peer_group *group;
3112 struct peer *peer;
3113
3114 /* look up for neighbor by interface name config. */
3115 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3116 if (peer) {
3117 peer_as_change(peer, 0, AS_SPECIFIED);
3118 return CMD_SUCCESS;
3119 }
3120
3121 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3122 if (group)
3123 peer_group_remote_as_delete(group);
3124 else {
3125 vty_out(vty, "%% Create the peer-group or interface first\n");
3126 return CMD_WARNING_CONFIG_FAILED;
3127 }
3128 return CMD_SUCCESS;
718e3744 3129}
6b0655a2 3130
718e3744 3131DEFUN (neighbor_local_as,
3132 neighbor_local_as_cmd,
9ccf14f7 3133 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3134 NEIGHBOR_STR
3135 NEIGHBOR_ADDR_STR2
3136 "Specify a local-as number\n"
3137 "AS number used as local AS\n")
3138{
d62a17ae 3139 int idx_peer = 1;
3140 int idx_number = 3;
3141 struct peer *peer;
3142 int ret;
3143 as_t as;
718e3744 3144
d62a17ae 3145 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3146 if (!peer)
3147 return CMD_WARNING_CONFIG_FAILED;
718e3744 3148
d62a17ae 3149 as = strtoul(argv[idx_number]->arg, NULL, 10);
3150 ret = peer_local_as_set(peer, as, 0, 0);
3151 return bgp_vty_return(vty, ret);
718e3744 3152}
3153
3154DEFUN (neighbor_local_as_no_prepend,
3155 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3156 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3157 NEIGHBOR_STR
3158 NEIGHBOR_ADDR_STR2
3159 "Specify a local-as number\n"
3160 "AS number used as local AS\n"
3161 "Do not prepend local-as to updates from ebgp peers\n")
3162{
d62a17ae 3163 int idx_peer = 1;
3164 int idx_number = 3;
3165 struct peer *peer;
3166 int ret;
3167 as_t as;
718e3744 3168
d62a17ae 3169 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3170 if (!peer)
3171 return CMD_WARNING_CONFIG_FAILED;
718e3744 3172
d62a17ae 3173 as = strtoul(argv[idx_number]->arg, NULL, 10);
3174 ret = peer_local_as_set(peer, as, 1, 0);
3175 return bgp_vty_return(vty, ret);
718e3744 3176}
3177
9d3f9705
AC
3178DEFUN (neighbor_local_as_no_prepend_replace_as,
3179 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3180 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3181 NEIGHBOR_STR
3182 NEIGHBOR_ADDR_STR2
3183 "Specify a local-as number\n"
3184 "AS number used as local AS\n"
3185 "Do not prepend local-as to updates from ebgp peers\n"
3186 "Do not prepend local-as to updates from ibgp peers\n")
3187{
d62a17ae 3188 int idx_peer = 1;
3189 int idx_number = 3;
3190 struct peer *peer;
3191 int ret;
3192 as_t as;
9d3f9705 3193
d62a17ae 3194 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3195 if (!peer)
3196 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3197
d62a17ae 3198 as = strtoul(argv[idx_number]->arg, NULL, 10);
3199 ret = peer_local_as_set(peer, as, 1, 1);
3200 return bgp_vty_return(vty, ret);
9d3f9705
AC
3201}
3202
718e3744 3203DEFUN (no_neighbor_local_as,
3204 no_neighbor_local_as_cmd,
a636c635 3205 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3206 NO_STR
3207 NEIGHBOR_STR
3208 NEIGHBOR_ADDR_STR2
a636c635
DW
3209 "Specify a local-as number\n"
3210 "AS number used as local AS\n"
3211 "Do not prepend local-as to updates from ebgp peers\n"
3212 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3213{
d62a17ae 3214 int idx_peer = 2;
3215 struct peer *peer;
3216 int ret;
718e3744 3217
d62a17ae 3218 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3219 if (!peer)
3220 return CMD_WARNING_CONFIG_FAILED;
718e3744 3221
d62a17ae 3222 ret = peer_local_as_unset(peer);
3223 return bgp_vty_return(vty, ret);
718e3744 3224}
3225
718e3744 3226
3f9c7369
DS
3227DEFUN (neighbor_solo,
3228 neighbor_solo_cmd,
9ccf14f7 3229 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3230 NEIGHBOR_STR
3231 NEIGHBOR_ADDR_STR2
3232 "Solo peer - part of its own update group\n")
3233{
d62a17ae 3234 int idx_peer = 1;
3235 struct peer *peer;
3236 int ret;
3f9c7369 3237
d62a17ae 3238 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3239 if (!peer)
3240 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3241
d62a17ae 3242 ret = update_group_adjust_soloness(peer, 1);
3243 return bgp_vty_return(vty, ret);
3f9c7369
DS
3244}
3245
3246DEFUN (no_neighbor_solo,
3247 no_neighbor_solo_cmd,
9ccf14f7 3248 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3249 NO_STR
3250 NEIGHBOR_STR
3251 NEIGHBOR_ADDR_STR2
3252 "Solo peer - part of its own update group\n")
3253{
d62a17ae 3254 int idx_peer = 2;
3255 struct peer *peer;
3256 int ret;
3f9c7369 3257
d62a17ae 3258 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3259 if (!peer)
3260 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3261
d62a17ae 3262 ret = update_group_adjust_soloness(peer, 0);
3263 return bgp_vty_return(vty, ret);
3f9c7369
DS
3264}
3265
0df7c91f
PJ
3266DEFUN (neighbor_password,
3267 neighbor_password_cmd,
9ccf14f7 3268 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3269 NEIGHBOR_STR
3270 NEIGHBOR_ADDR_STR2
3271 "Set a password\n"
3272 "The password\n")
3273{
d62a17ae 3274 int idx_peer = 1;
3275 int idx_line = 3;
3276 struct peer *peer;
3277 int ret;
0df7c91f 3278
d62a17ae 3279 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3280 if (!peer)
3281 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3282
d62a17ae 3283 ret = peer_password_set(peer, argv[idx_line]->arg);
3284 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3285}
3286
3287DEFUN (no_neighbor_password,
3288 no_neighbor_password_cmd,
a636c635 3289 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3290 NO_STR
3291 NEIGHBOR_STR
3292 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3293 "Set a password\n"
3294 "The password\n")
0df7c91f 3295{
d62a17ae 3296 int idx_peer = 2;
3297 struct peer *peer;
3298 int ret;
0df7c91f 3299
d62a17ae 3300 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3301 if (!peer)
3302 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3303
d62a17ae 3304 ret = peer_password_unset(peer);
3305 return bgp_vty_return(vty, ret);
0df7c91f 3306}
6b0655a2 3307
718e3744 3308DEFUN (neighbor_activate,
3309 neighbor_activate_cmd,
9ccf14f7 3310 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3311 NEIGHBOR_STR
3312 NEIGHBOR_ADDR_STR2
3313 "Enable the Address Family for this Neighbor\n")
3314{
d62a17ae 3315 int idx_peer = 1;
3316 int ret;
3317 struct peer *peer;
718e3744 3318
d62a17ae 3319 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3320 if (!peer)
3321 return CMD_WARNING_CONFIG_FAILED;
718e3744 3322
d62a17ae 3323 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3324 return bgp_vty_return(vty, ret);
718e3744 3325}
3326
d62a17ae 3327ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3328 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3329 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3330 "Enable the Address Family for this Neighbor\n")
596c17ba 3331
718e3744 3332DEFUN (no_neighbor_activate,
3333 no_neighbor_activate_cmd,
9ccf14f7 3334 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3335 NO_STR
3336 NEIGHBOR_STR
3337 NEIGHBOR_ADDR_STR2
3338 "Enable the Address Family for this Neighbor\n")
3339{
d62a17ae 3340 int idx_peer = 2;
3341 int ret;
3342 struct peer *peer;
718e3744 3343
d62a17ae 3344 /* Lookup peer. */
3345 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3346 if (!peer)
3347 return CMD_WARNING_CONFIG_FAILED;
718e3744 3348
d62a17ae 3349 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3350 return bgp_vty_return(vty, ret);
718e3744 3351}
6b0655a2 3352
d62a17ae 3353ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3354 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3355 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3356 "Enable the Address Family for this Neighbor\n")
596c17ba 3357
718e3744 3358DEFUN (neighbor_set_peer_group,
3359 neighbor_set_peer_group_cmd,
9ccf14f7 3360 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3361 NEIGHBOR_STR
a80beece 3362 NEIGHBOR_ADDR_STR2
718e3744 3363 "Member of the peer-group\n"
16cedbb0 3364 "Peer-group name\n")
718e3744 3365{
d62a17ae 3366 VTY_DECLVAR_CONTEXT(bgp, bgp);
3367 int idx_peer = 1;
3368 int idx_word = 3;
3369 int ret;
3370 as_t as;
3371 union sockunion su;
3372 struct peer *peer;
3373 struct peer_group *group;
3374
3375 peer = NULL;
3376
3377 ret = str2sockunion(argv[idx_peer]->arg, &su);
3378 if (ret < 0) {
3379 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3380 if (!peer) {
3381 vty_out(vty, "%% Malformed address or name: %s\n",
3382 argv[idx_peer]->arg);
3383 return CMD_WARNING_CONFIG_FAILED;
3384 }
3385 } else {
3386 if (peer_address_self_check(bgp, &su)) {
3387 vty_out(vty,
3388 "%% Can not configure the local system as neighbor\n");
3389 return CMD_WARNING_CONFIG_FAILED;
3390 }
3391
3392 /* Disallow for dynamic neighbor. */
3393 peer = peer_lookup(bgp, &su);
3394 if (peer && peer_dynamic_neighbor(peer)) {
3395 vty_out(vty,
3396 "%% Operation not allowed on a dynamic neighbor\n");
3397 return CMD_WARNING_CONFIG_FAILED;
3398 }
3399 }
3400
3401 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3402 if (!group) {
3403 vty_out(vty, "%% Configure the peer-group first\n");
3404 return CMD_WARNING_CONFIG_FAILED;
3405 }
3406
3407 ret = peer_group_bind(bgp, &su, peer, group, &as);
3408
3409 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3410 vty_out(vty,
3411 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3412 as);
3413 return CMD_WARNING_CONFIG_FAILED;
3414 }
3415
3416 return bgp_vty_return(vty, ret);
3417}
3418
3419ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3420 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3421 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3422 "Member of the peer-group\n"
3423 "Peer-group name\n")
596c17ba 3424
718e3744 3425DEFUN (no_neighbor_set_peer_group,
3426 no_neighbor_set_peer_group_cmd,
9ccf14f7 3427 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3428 NO_STR
3429 NEIGHBOR_STR
a80beece 3430 NEIGHBOR_ADDR_STR2
718e3744 3431 "Member of the peer-group\n"
16cedbb0 3432 "Peer-group name\n")
718e3744 3433{
d62a17ae 3434 VTY_DECLVAR_CONTEXT(bgp, bgp);
3435 int idx_peer = 2;
3436 int idx_word = 4;
3437 int ret;
3438 struct peer *peer;
3439 struct peer_group *group;
3440
3441 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3442 if (!peer)
3443 return CMD_WARNING_CONFIG_FAILED;
3444
3445 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3446 if (!group) {
3447 vty_out(vty, "%% Configure the peer-group first\n");
3448 return CMD_WARNING_CONFIG_FAILED;
3449 }
718e3744 3450
827ed707 3451 ret = peer_delete(peer);
718e3744 3452
d62a17ae 3453 return bgp_vty_return(vty, ret);
718e3744 3454}
6b0655a2 3455
d62a17ae 3456ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3457 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3458 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3459 "Member of the peer-group\n"
3460 "Peer-group name\n")
596c17ba 3461
d62a17ae 3462static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3463 uint32_t flag, int set)
718e3744 3464{
d62a17ae 3465 int ret;
3466 struct peer *peer;
718e3744 3467
d62a17ae 3468 peer = peer_and_group_lookup_vty(vty, ip_str);
3469 if (!peer)
3470 return CMD_WARNING_CONFIG_FAILED;
718e3744 3471
7ebe625c
QY
3472 /*
3473 * If 'neighbor <interface>', then this is for directly connected peers,
3474 * we should not accept disable-connected-check.
3475 */
3476 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3477 vty_out(vty,
3478 "%s is directly connected peer, cannot accept disable-"
3479 "connected-check\n",
3480 ip_str);
3481 return CMD_WARNING_CONFIG_FAILED;
3482 }
3483
d62a17ae 3484 if (!set && flag == PEER_FLAG_SHUTDOWN)
3485 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3486
d62a17ae 3487 if (set)
3488 ret = peer_flag_set(peer, flag);
3489 else
3490 ret = peer_flag_unset(peer, flag);
718e3744 3491
d62a17ae 3492 return bgp_vty_return(vty, ret);
718e3744 3493}
3494
47cbc09b 3495static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3496{
d62a17ae 3497 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3498}
3499
d62a17ae 3500static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3501 uint32_t flag)
718e3744 3502{
d62a17ae 3503 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3504}
3505
3506/* neighbor passive. */
3507DEFUN (neighbor_passive,
3508 neighbor_passive_cmd,
9ccf14f7 3509 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3510 NEIGHBOR_STR
3511 NEIGHBOR_ADDR_STR2
3512 "Don't send open messages to this neighbor\n")
3513{
d62a17ae 3514 int idx_peer = 1;
3515 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3516}
3517
3518DEFUN (no_neighbor_passive,
3519 no_neighbor_passive_cmd,
9ccf14f7 3520 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3521 NO_STR
3522 NEIGHBOR_STR
3523 NEIGHBOR_ADDR_STR2
3524 "Don't send open messages to this neighbor\n")
3525{
d62a17ae 3526 int idx_peer = 2;
3527 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3528}
6b0655a2 3529
718e3744 3530/* neighbor shutdown. */
73d70fa6
DL
3531DEFUN (neighbor_shutdown_msg,
3532 neighbor_shutdown_msg_cmd,
3533 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3534 NEIGHBOR_STR
3535 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3536 "Administratively shut down this neighbor\n"
3537 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3538 "Shutdown message\n")
718e3744 3539{
d62a17ae 3540 int idx_peer = 1;
73d70fa6 3541
d62a17ae 3542 if (argc >= 5) {
3543 struct peer *peer =
3544 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3545 char *message;
73d70fa6 3546
d62a17ae 3547 if (!peer)
3548 return CMD_WARNING_CONFIG_FAILED;
3549 message = argv_concat(argv, argc, 4);
3550 peer_tx_shutdown_message_set(peer, message);
3551 XFREE(MTYPE_TMP, message);
3552 }
73d70fa6 3553
d62a17ae 3554 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3555}
3556
d62a17ae 3557ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3558 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3559 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3560 "Administratively shut down this neighbor\n")
73d70fa6
DL
3561
3562DEFUN (no_neighbor_shutdown_msg,
3563 no_neighbor_shutdown_msg_cmd,
3564 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3565 NO_STR
3566 NEIGHBOR_STR
3567 NEIGHBOR_ADDR_STR2
3568 "Administratively shut down this neighbor\n"
3569 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3570 "Shutdown message\n")
718e3744 3571{
d62a17ae 3572 int idx_peer = 2;
73d70fa6 3573
d62a17ae 3574 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3575 PEER_FLAG_SHUTDOWN);
718e3744 3576}
6b0655a2 3577
d62a17ae 3578ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3579 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3580 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3581 "Administratively shut down this neighbor\n")
73d70fa6 3582
718e3744 3583/* neighbor capability dynamic. */
3584DEFUN (neighbor_capability_dynamic,
3585 neighbor_capability_dynamic_cmd,
9ccf14f7 3586 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3587 NEIGHBOR_STR
3588 NEIGHBOR_ADDR_STR2
3589 "Advertise capability to the peer\n"
3590 "Advertise dynamic capability to this neighbor\n")
3591{
d62a17ae 3592 int idx_peer = 1;
3593 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3594 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3595}
3596
3597DEFUN (no_neighbor_capability_dynamic,
3598 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3599 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3600 NO_STR
3601 NEIGHBOR_STR
3602 NEIGHBOR_ADDR_STR2
3603 "Advertise capability to the peer\n"
3604 "Advertise dynamic capability to this neighbor\n")
3605{
d62a17ae 3606 int idx_peer = 2;
3607 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3608 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3609}
6b0655a2 3610
718e3744 3611/* neighbor dont-capability-negotiate */
3612DEFUN (neighbor_dont_capability_negotiate,
3613 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3614 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3615 NEIGHBOR_STR
3616 NEIGHBOR_ADDR_STR2
3617 "Do not perform capability negotiation\n")
3618{
d62a17ae 3619 int idx_peer = 1;
3620 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3621 PEER_FLAG_DONT_CAPABILITY);
718e3744 3622}
3623
3624DEFUN (no_neighbor_dont_capability_negotiate,
3625 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3626 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3627 NO_STR
3628 NEIGHBOR_STR
3629 NEIGHBOR_ADDR_STR2
3630 "Do not perform capability negotiation\n")
3631{
d62a17ae 3632 int idx_peer = 2;
3633 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3634 PEER_FLAG_DONT_CAPABILITY);
718e3744 3635}
6b0655a2 3636
8a92a8a0
DS
3637/* neighbor capability extended next hop encoding */
3638DEFUN (neighbor_capability_enhe,
3639 neighbor_capability_enhe_cmd,
9ccf14f7 3640 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3641 NEIGHBOR_STR
3642 NEIGHBOR_ADDR_STR2
3643 "Advertise capability to the peer\n"
3644 "Advertise extended next-hop capability to the peer\n")
3645{
d62a17ae 3646 int idx_peer = 1;
3647 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3648 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3649}
3650
3651DEFUN (no_neighbor_capability_enhe,
3652 no_neighbor_capability_enhe_cmd,
9ccf14f7 3653 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3654 NO_STR
3655 NEIGHBOR_STR
3656 NEIGHBOR_ADDR_STR2
3657 "Advertise capability to the peer\n"
3658 "Advertise extended next-hop capability to the peer\n")
3659{
d62a17ae 3660 int idx_peer = 2;
3661 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3662 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3663}
3664
d62a17ae 3665static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3666 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3667 int set)
718e3744 3668{
d62a17ae 3669 int ret;
3670 struct peer *peer;
718e3744 3671
d62a17ae 3672 peer = peer_and_group_lookup_vty(vty, peer_str);
3673 if (!peer)
3674 return CMD_WARNING_CONFIG_FAILED;
718e3744 3675
d62a17ae 3676 if (set)
3677 ret = peer_af_flag_set(peer, afi, safi, flag);
3678 else
3679 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3680
d62a17ae 3681 return bgp_vty_return(vty, ret);
718e3744 3682}
3683
d62a17ae 3684static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3685 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3686{
d62a17ae 3687 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3688}
3689
d62a17ae 3690static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3691 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3692{
d62a17ae 3693 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3694}
6b0655a2 3695
718e3744 3696/* neighbor capability orf prefix-list. */
3697DEFUN (neighbor_capability_orf_prefix,
3698 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3699 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3700 NEIGHBOR_STR
3701 NEIGHBOR_ADDR_STR2
3702 "Advertise capability to the peer\n"
3703 "Advertise ORF capability to the peer\n"
3704 "Advertise prefixlist ORF capability to this neighbor\n"
3705 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3706 "Capability to RECEIVE the ORF from this neighbor\n"
3707 "Capability to SEND the ORF to this neighbor\n")
3708{
d62a17ae 3709 int idx_peer = 1;
3710 int idx_send_recv = 5;
d7c0a89a 3711 uint16_t flag = 0;
d62a17ae 3712
3713 if (strmatch(argv[idx_send_recv]->text, "send"))
3714 flag = PEER_FLAG_ORF_PREFIX_SM;
3715 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3716 flag = PEER_FLAG_ORF_PREFIX_RM;
3717 else if (strmatch(argv[idx_send_recv]->text, "both"))
3718 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3719 else {
3720 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3721 return CMD_WARNING_CONFIG_FAILED;
3722 }
3723
3724 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3725 bgp_node_safi(vty), flag);
3726}
3727
3728ALIAS_HIDDEN(
3729 neighbor_capability_orf_prefix,
3730 neighbor_capability_orf_prefix_hidden_cmd,
3731 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3732 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3733 "Advertise capability to the peer\n"
3734 "Advertise ORF capability to the peer\n"
3735 "Advertise prefixlist ORF capability to this neighbor\n"
3736 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3737 "Capability to RECEIVE the ORF from this neighbor\n"
3738 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3739
718e3744 3740DEFUN (no_neighbor_capability_orf_prefix,
3741 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3742 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3743 NO_STR
3744 NEIGHBOR_STR
3745 NEIGHBOR_ADDR_STR2
3746 "Advertise capability to the peer\n"
3747 "Advertise ORF capability to the peer\n"
3748 "Advertise prefixlist ORF capability to this neighbor\n"
3749 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3750 "Capability to RECEIVE the ORF from this neighbor\n"
3751 "Capability to SEND the ORF to this neighbor\n")
3752{
d62a17ae 3753 int idx_peer = 2;
3754 int idx_send_recv = 6;
d7c0a89a 3755 uint16_t flag = 0;
d62a17ae 3756
3757 if (strmatch(argv[idx_send_recv]->text, "send"))
3758 flag = PEER_FLAG_ORF_PREFIX_SM;
3759 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3760 flag = PEER_FLAG_ORF_PREFIX_RM;
3761 else if (strmatch(argv[idx_send_recv]->text, "both"))
3762 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3763 else {
3764 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3765 return CMD_WARNING_CONFIG_FAILED;
3766 }
3767
3768 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3769 bgp_node_afi(vty), bgp_node_safi(vty),
3770 flag);
3771}
3772
3773ALIAS_HIDDEN(
3774 no_neighbor_capability_orf_prefix,
3775 no_neighbor_capability_orf_prefix_hidden_cmd,
3776 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3777 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3778 "Advertise capability to the peer\n"
3779 "Advertise ORF capability to the peer\n"
3780 "Advertise prefixlist ORF capability to this neighbor\n"
3781 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3782 "Capability to RECEIVE the ORF from this neighbor\n"
3783 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3784
718e3744 3785/* neighbor next-hop-self. */
3786DEFUN (neighbor_nexthop_self,
3787 neighbor_nexthop_self_cmd,
9ccf14f7 3788 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3789 NEIGHBOR_STR
3790 NEIGHBOR_ADDR_STR2
a538debe 3791 "Disable the next hop calculation for this neighbor\n")
718e3744 3792{
d62a17ae 3793 int idx_peer = 1;
3794 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3795 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3796}
9e7a53c1 3797
d62a17ae 3798ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3799 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3800 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3801 "Disable the next hop calculation for this neighbor\n")
596c17ba 3802
a538debe
DS
3803/* neighbor next-hop-self. */
3804DEFUN (neighbor_nexthop_self_force,
3805 neighbor_nexthop_self_force_cmd,
9ccf14f7 3806 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3807 NEIGHBOR_STR
3808 NEIGHBOR_ADDR_STR2
3809 "Disable the next hop calculation for this neighbor\n"
3810 "Set the next hop to self for reflected routes\n")
3811{
d62a17ae 3812 int idx_peer = 1;
3813 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3814 bgp_node_safi(vty),
3815 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3816}
3817
d62a17ae 3818ALIAS_HIDDEN(neighbor_nexthop_self_force,
3819 neighbor_nexthop_self_force_hidden_cmd,
3820 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3821 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3822 "Disable the next hop calculation for this neighbor\n"
3823 "Set the next hop to self for reflected routes\n")
596c17ba 3824
718e3744 3825DEFUN (no_neighbor_nexthop_self,
3826 no_neighbor_nexthop_self_cmd,
9ccf14f7 3827 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3828 NO_STR
3829 NEIGHBOR_STR
3830 NEIGHBOR_ADDR_STR2
a538debe 3831 "Disable the next hop calculation for this neighbor\n")
718e3744 3832{
d62a17ae 3833 int idx_peer = 2;
3834 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3835 bgp_node_afi(vty), bgp_node_safi(vty),
3836 PEER_FLAG_NEXTHOP_SELF);
718e3744 3837}
6b0655a2 3838
d62a17ae 3839ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3840 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3841 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3842 "Disable the next hop calculation for this neighbor\n")
596c17ba 3843
88b8ed8d 3844DEFUN (no_neighbor_nexthop_self_force,
a538debe 3845 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3846 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3847 NO_STR
3848 NEIGHBOR_STR
3849 NEIGHBOR_ADDR_STR2
3850 "Disable the next hop calculation for this neighbor\n"
3851 "Set the next hop to self for reflected routes\n")
88b8ed8d 3852{
d62a17ae 3853 int idx_peer = 2;
3854 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3855 bgp_node_afi(vty), bgp_node_safi(vty),
3856 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3857}
a538debe 3858
d62a17ae 3859ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3860 no_neighbor_nexthop_self_force_hidden_cmd,
3861 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3862 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3863 "Disable the next hop calculation for this neighbor\n"
3864 "Set the next hop to self for reflected routes\n")
596c17ba 3865
c7122e14
DS
3866/* neighbor as-override */
3867DEFUN (neighbor_as_override,
3868 neighbor_as_override_cmd,
9ccf14f7 3869 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3870 NEIGHBOR_STR
3871 NEIGHBOR_ADDR_STR2
3872 "Override ASNs in outbound updates if aspath equals remote-as\n")
3873{
d62a17ae 3874 int idx_peer = 1;
3875 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3876 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3877}
3878
d62a17ae 3879ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3880 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3881 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3882 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3883
c7122e14
DS
3884DEFUN (no_neighbor_as_override,
3885 no_neighbor_as_override_cmd,
9ccf14f7 3886 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3887 NO_STR
3888 NEIGHBOR_STR
3889 NEIGHBOR_ADDR_STR2
3890 "Override ASNs in outbound updates if aspath equals remote-as\n")
3891{
d62a17ae 3892 int idx_peer = 2;
3893 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3894 bgp_node_afi(vty), bgp_node_safi(vty),
3895 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3896}
3897
d62a17ae 3898ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3899 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3900 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3901 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3902
718e3744 3903/* neighbor remove-private-AS. */
3904DEFUN (neighbor_remove_private_as,
3905 neighbor_remove_private_as_cmd,
9ccf14f7 3906 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3907 NEIGHBOR_STR
3908 NEIGHBOR_ADDR_STR2
5000f21c 3909 "Remove private ASNs in outbound updates\n")
718e3744 3910{
d62a17ae 3911 int idx_peer = 1;
3912 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3913 bgp_node_safi(vty),
3914 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3915}
3916
d62a17ae 3917ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3918 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3919 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3920 "Remove private ASNs in outbound updates\n")
596c17ba 3921
5000f21c
DS
3922DEFUN (neighbor_remove_private_as_all,
3923 neighbor_remove_private_as_all_cmd,
9ccf14f7 3924 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3925 NEIGHBOR_STR
3926 NEIGHBOR_ADDR_STR2
3927 "Remove private ASNs in outbound updates\n"
efd7904e 3928 "Apply to all AS numbers\n")
5000f21c 3929{
d62a17ae 3930 int idx_peer = 1;
3931 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3932 bgp_node_safi(vty),
3933 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3934}
3935
d62a17ae 3936ALIAS_HIDDEN(neighbor_remove_private_as_all,
3937 neighbor_remove_private_as_all_hidden_cmd,
3938 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3939 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3940 "Remove private ASNs in outbound updates\n"
3941 "Apply to all AS numbers")
596c17ba 3942
5000f21c
DS
3943DEFUN (neighbor_remove_private_as_replace_as,
3944 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3945 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3946 NEIGHBOR_STR
3947 NEIGHBOR_ADDR_STR2
3948 "Remove private ASNs in outbound updates\n"
3949 "Replace private ASNs with our ASN in outbound updates\n")
3950{
d62a17ae 3951 int idx_peer = 1;
3952 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3953 bgp_node_safi(vty),
3954 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3955}
3956
d62a17ae 3957ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3958 neighbor_remove_private_as_replace_as_hidden_cmd,
3959 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3960 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3961 "Remove private ASNs in outbound updates\n"
3962 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3963
5000f21c
DS
3964DEFUN (neighbor_remove_private_as_all_replace_as,
3965 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3966 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3967 NEIGHBOR_STR
3968 NEIGHBOR_ADDR_STR2
3969 "Remove private ASNs in outbound updates\n"
16cedbb0 3970 "Apply to all AS numbers\n"
5000f21c
DS
3971 "Replace private ASNs with our ASN in outbound updates\n")
3972{
d62a17ae 3973 int idx_peer = 1;
3974 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3975 bgp_node_safi(vty),
3976 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3977}
3978
d62a17ae 3979ALIAS_HIDDEN(
3980 neighbor_remove_private_as_all_replace_as,
3981 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3982 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3983 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3984 "Remove private ASNs in outbound updates\n"
3985 "Apply to all AS numbers\n"
3986 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3987
718e3744 3988DEFUN (no_neighbor_remove_private_as,
3989 no_neighbor_remove_private_as_cmd,
9ccf14f7 3990 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3991 NO_STR
3992 NEIGHBOR_STR
3993 NEIGHBOR_ADDR_STR2
5000f21c 3994 "Remove private ASNs in outbound updates\n")
718e3744 3995{
d62a17ae 3996 int idx_peer = 2;
3997 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3998 bgp_node_afi(vty), bgp_node_safi(vty),
3999 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4000}
6b0655a2 4001
d62a17ae 4002ALIAS_HIDDEN(no_neighbor_remove_private_as,
4003 no_neighbor_remove_private_as_hidden_cmd,
4004 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4005 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4006 "Remove private ASNs in outbound updates\n")
596c17ba 4007
88b8ed8d 4008DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4009 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4010 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4011 NO_STR
4012 NEIGHBOR_STR
4013 NEIGHBOR_ADDR_STR2
4014 "Remove private ASNs in outbound updates\n"
16cedbb0 4015 "Apply to all AS numbers\n")
88b8ed8d 4016{
d62a17ae 4017 int idx_peer = 2;
4018 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4019 bgp_node_afi(vty), bgp_node_safi(vty),
4020 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4021}
5000f21c 4022
d62a17ae 4023ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4024 no_neighbor_remove_private_as_all_hidden_cmd,
4025 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4026 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4027 "Remove private ASNs in outbound updates\n"
4028 "Apply to all AS numbers\n")
596c17ba 4029
88b8ed8d 4030DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4031 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4032 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4033 NO_STR
4034 NEIGHBOR_STR
4035 NEIGHBOR_ADDR_STR2
4036 "Remove private ASNs in outbound updates\n"
4037 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4038{
d62a17ae 4039 int idx_peer = 2;
4040 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4041 bgp_node_afi(vty), bgp_node_safi(vty),
4042 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4043}
5000f21c 4044
d62a17ae 4045ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4046 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4047 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4048 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4049 "Remove private ASNs in outbound updates\n"
4050 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4051
88b8ed8d 4052DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4053 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4054 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4055 NO_STR
4056 NEIGHBOR_STR
4057 NEIGHBOR_ADDR_STR2
4058 "Remove private ASNs in outbound updates\n"
16cedbb0 4059 "Apply to all AS numbers\n"
5000f21c 4060 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4061{
d62a17ae 4062 int idx_peer = 2;
4063 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4064 bgp_node_afi(vty), bgp_node_safi(vty),
4065 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4066}
5000f21c 4067
d62a17ae 4068ALIAS_HIDDEN(
4069 no_neighbor_remove_private_as_all_replace_as,
4070 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4071 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4072 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4073 "Remove private ASNs in outbound updates\n"
4074 "Apply to all AS numbers\n"
4075 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4076
5000f21c 4077
718e3744 4078/* neighbor send-community. */
4079DEFUN (neighbor_send_community,
4080 neighbor_send_community_cmd,
9ccf14f7 4081 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4082 NEIGHBOR_STR
4083 NEIGHBOR_ADDR_STR2
4084 "Send Community attribute to this neighbor\n")
4085{
d62a17ae 4086 int idx_peer = 1;
27c05d4d 4087
d62a17ae 4088 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4089 bgp_node_safi(vty),
4090 PEER_FLAG_SEND_COMMUNITY);
718e3744 4091}
4092
d62a17ae 4093ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4094 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4095 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4096 "Send Community attribute to this neighbor\n")
596c17ba 4097
718e3744 4098DEFUN (no_neighbor_send_community,
4099 no_neighbor_send_community_cmd,
9ccf14f7 4100 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4101 NO_STR
4102 NEIGHBOR_STR
4103 NEIGHBOR_ADDR_STR2
4104 "Send Community attribute to this neighbor\n")
4105{
d62a17ae 4106 int idx_peer = 2;
27c05d4d 4107
d62a17ae 4108 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4109 bgp_node_afi(vty), bgp_node_safi(vty),
4110 PEER_FLAG_SEND_COMMUNITY);
718e3744 4111}
6b0655a2 4112
d62a17ae 4113ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4114 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4115 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4116 "Send Community attribute to this neighbor\n")
596c17ba 4117
718e3744 4118/* neighbor send-community extended. */
4119DEFUN (neighbor_send_community_type,
4120 neighbor_send_community_type_cmd,
57d187bc 4121 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4122 NEIGHBOR_STR
4123 NEIGHBOR_ADDR_STR2
4124 "Send Community attribute to this neighbor\n"
4125 "Send Standard and Extended Community attributes\n"
57d187bc 4126 "Send Standard, Large and Extended Community attributes\n"
718e3744 4127 "Send Extended Community attributes\n"
57d187bc
JS
4128 "Send Standard Community attributes\n"
4129 "Send Large Community attributes\n")
718e3744 4130{
27c05d4d 4131 int idx_peer = 1;
d7c0a89a 4132 uint32_t flag = 0;
27c05d4d 4133 const char *type = argv[argc - 1]->text;
d62a17ae 4134
27c05d4d 4135 if (strmatch(type, "standard")) {
d62a17ae 4136 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4137 } else if (strmatch(type, "extended")) {
d62a17ae 4138 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4139 } else if (strmatch(type, "large")) {
d62a17ae 4140 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4141 } else if (strmatch(type, "both")) {
d62a17ae 4142 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4143 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4144 } else { /* if (strmatch(type, "all")) */
d62a17ae 4145 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4146 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4147 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4148 }
4149
27c05d4d 4150 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4151 bgp_node_safi(vty), flag);
4152}
4153
4154ALIAS_HIDDEN(
4155 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4156 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4157 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4158 "Send Community attribute to this neighbor\n"
4159 "Send Standard and Extended Community attributes\n"
4160 "Send Standard, Large and Extended Community attributes\n"
4161 "Send Extended Community attributes\n"
4162 "Send Standard Community attributes\n"
4163 "Send Large Community attributes\n")
596c17ba 4164
718e3744 4165DEFUN (no_neighbor_send_community_type,
4166 no_neighbor_send_community_type_cmd,
57d187bc 4167 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4168 NO_STR
4169 NEIGHBOR_STR
4170 NEIGHBOR_ADDR_STR2
4171 "Send Community attribute to this neighbor\n"
4172 "Send Standard and Extended Community attributes\n"
57d187bc 4173 "Send Standard, Large and Extended Community attributes\n"
718e3744 4174 "Send Extended Community attributes\n"
57d187bc
JS
4175 "Send Standard Community attributes\n"
4176 "Send Large Community attributes\n")
718e3744 4177{
d62a17ae 4178 int idx_peer = 2;
27c05d4d 4179 uint32_t flag = 0;
d62a17ae 4180 const char *type = argv[argc - 1]->text;
4181
27c05d4d
PM
4182 if (strmatch(type, "standard")) {
4183 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4184 } else if (strmatch(type, "extended")) {
4185 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4186 } else if (strmatch(type, "large")) {
4187 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4188 } else if (strmatch(type, "both")) {
4189 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4190 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4191 } else { /* if (strmatch(type, "all")) */
4192 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4193 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4194 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4195 }
4196
4197 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4198 bgp_node_afi(vty), bgp_node_safi(vty),
4199 flag);
d62a17ae 4200}
4201
4202ALIAS_HIDDEN(
4203 no_neighbor_send_community_type,
4204 no_neighbor_send_community_type_hidden_cmd,
4205 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4206 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4207 "Send Community attribute to this neighbor\n"
4208 "Send Standard and Extended Community attributes\n"
4209 "Send Standard, Large and Extended Community attributes\n"
4210 "Send Extended Community attributes\n"
4211 "Send Standard Community attributes\n"
4212 "Send Large Community attributes\n")
596c17ba 4213
718e3744 4214/* neighbor soft-reconfig. */
4215DEFUN (neighbor_soft_reconfiguration,
4216 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4217 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4218 NEIGHBOR_STR
4219 NEIGHBOR_ADDR_STR2
4220 "Per neighbor soft reconfiguration\n"
4221 "Allow inbound soft reconfiguration for this neighbor\n")
4222{
d62a17ae 4223 int idx_peer = 1;
4224 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4225 bgp_node_safi(vty),
4226 PEER_FLAG_SOFT_RECONFIG);
718e3744 4227}
4228
d62a17ae 4229ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4230 neighbor_soft_reconfiguration_hidden_cmd,
4231 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4232 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4233 "Per neighbor soft reconfiguration\n"
4234 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4235
718e3744 4236DEFUN (no_neighbor_soft_reconfiguration,
4237 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4238 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4239 NO_STR
4240 NEIGHBOR_STR
4241 NEIGHBOR_ADDR_STR2
4242 "Per neighbor soft reconfiguration\n"
4243 "Allow inbound soft reconfiguration for this neighbor\n")
4244{
d62a17ae 4245 int idx_peer = 2;
4246 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4247 bgp_node_afi(vty), bgp_node_safi(vty),
4248 PEER_FLAG_SOFT_RECONFIG);
718e3744 4249}
6b0655a2 4250
d62a17ae 4251ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4252 no_neighbor_soft_reconfiguration_hidden_cmd,
4253 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4254 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4255 "Per neighbor soft reconfiguration\n"
4256 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4257
718e3744 4258DEFUN (neighbor_route_reflector_client,
4259 neighbor_route_reflector_client_cmd,
9ccf14f7 4260 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4261 NEIGHBOR_STR
4262 NEIGHBOR_ADDR_STR2
4263 "Configure a neighbor as Route Reflector client\n")
4264{
d62a17ae 4265 int idx_peer = 1;
4266 struct peer *peer;
718e3744 4267
4268
d62a17ae 4269 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4270 if (!peer)
4271 return CMD_WARNING_CONFIG_FAILED;
718e3744 4272
d62a17ae 4273 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4274 bgp_node_safi(vty),
4275 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4276}
4277
d62a17ae 4278ALIAS_HIDDEN(neighbor_route_reflector_client,
4279 neighbor_route_reflector_client_hidden_cmd,
4280 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4281 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4282 "Configure a neighbor as Route Reflector client\n")
596c17ba 4283
718e3744 4284DEFUN (no_neighbor_route_reflector_client,
4285 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4286 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4287 NO_STR
4288 NEIGHBOR_STR
4289 NEIGHBOR_ADDR_STR2
4290 "Configure a neighbor as Route Reflector client\n")
4291{
d62a17ae 4292 int idx_peer = 2;
4293 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4294 bgp_node_afi(vty), bgp_node_safi(vty),
4295 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4296}
6b0655a2 4297
d62a17ae 4298ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4299 no_neighbor_route_reflector_client_hidden_cmd,
4300 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4301 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4302 "Configure a neighbor as Route Reflector client\n")
596c17ba 4303
718e3744 4304/* neighbor route-server-client. */
4305DEFUN (neighbor_route_server_client,
4306 neighbor_route_server_client_cmd,
9ccf14f7 4307 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4308 NEIGHBOR_STR
4309 NEIGHBOR_ADDR_STR2
4310 "Configure a neighbor as Route Server client\n")
4311{
d62a17ae 4312 int idx_peer = 1;
4313 struct peer *peer;
2a3d5731 4314
d62a17ae 4315 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4316 if (!peer)
4317 return CMD_WARNING_CONFIG_FAILED;
4318 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4319 bgp_node_safi(vty),
4320 PEER_FLAG_RSERVER_CLIENT);
718e3744 4321}
4322
d62a17ae 4323ALIAS_HIDDEN(neighbor_route_server_client,
4324 neighbor_route_server_client_hidden_cmd,
4325 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4326 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4327 "Configure a neighbor as Route Server client\n")
596c17ba 4328
718e3744 4329DEFUN (no_neighbor_route_server_client,
4330 no_neighbor_route_server_client_cmd,
9ccf14f7 4331 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4332 NO_STR
4333 NEIGHBOR_STR
4334 NEIGHBOR_ADDR_STR2
4335 "Configure a neighbor as Route Server client\n")
fee0f4c6 4336{
d62a17ae 4337 int idx_peer = 2;
4338 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4339 bgp_node_afi(vty), bgp_node_safi(vty),
4340 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4341}
6b0655a2 4342
d62a17ae 4343ALIAS_HIDDEN(no_neighbor_route_server_client,
4344 no_neighbor_route_server_client_hidden_cmd,
4345 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4346 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4347 "Configure a neighbor as Route Server client\n")
596c17ba 4348
fee0f4c6 4349DEFUN (neighbor_nexthop_local_unchanged,
4350 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4351 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4352 NEIGHBOR_STR
4353 NEIGHBOR_ADDR_STR2
4354 "Configure treatment of outgoing link-local nexthop attribute\n"
4355 "Leave link-local nexthop unchanged for this peer\n")
4356{
d62a17ae 4357 int idx_peer = 1;
4358 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4359 bgp_node_safi(vty),
4360 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4361}
6b0655a2 4362
fee0f4c6 4363DEFUN (no_neighbor_nexthop_local_unchanged,
4364 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4365 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4366 NO_STR
4367 NEIGHBOR_STR
4368 NEIGHBOR_ADDR_STR2
4369 "Configure treatment of outgoing link-local-nexthop attribute\n"
4370 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4371{
d62a17ae 4372 int idx_peer = 2;
4373 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4374 bgp_node_afi(vty), bgp_node_safi(vty),
4375 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4376}
6b0655a2 4377
718e3744 4378DEFUN (neighbor_attr_unchanged,
4379 neighbor_attr_unchanged_cmd,
a8206004 4380 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4381 NEIGHBOR_STR
4382 NEIGHBOR_ADDR_STR2
4383 "BGP attribute is propagated unchanged to this neighbor\n"
4384 "As-path attribute\n"
4385 "Nexthop attribute\n"
a8206004 4386 "Med attribute\n")
718e3744 4387{
d62a17ae 4388 int idx = 0;
8eeb0335
DW
4389 char *peer_str = argv[1]->arg;
4390 struct peer *peer;
d7c0a89a 4391 uint16_t flags = 0;
8eeb0335
DW
4392 afi_t afi = bgp_node_afi(vty);
4393 safi_t safi = bgp_node_safi(vty);
4394
4395 peer = peer_and_group_lookup_vty(vty, peer_str);
4396 if (!peer)
4397 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4398
4399 if (argv_find(argv, argc, "as-path", &idx))
4400 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4401 idx = 0;
4402 if (argv_find(argv, argc, "next-hop", &idx))
4403 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4404 idx = 0;
4405 if (argv_find(argv, argc, "med", &idx))
4406 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4407
8eeb0335
DW
4408 /* no flags means all of them! */
4409 if (!flags) {
d62a17ae 4410 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4411 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4412 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4413 } else {
a4d82a8a
PZ
4414 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4415 && peer_af_flag_check(peer, afi, safi,
4416 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4417 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4418 PEER_FLAG_AS_PATH_UNCHANGED);
4419 }
4420
a4d82a8a
PZ
4421 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4422 && peer_af_flag_check(peer, afi, safi,
4423 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4424 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4425 PEER_FLAG_NEXTHOP_UNCHANGED);
4426 }
4427
a4d82a8a
PZ
4428 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4429 && peer_af_flag_check(peer, afi, safi,
4430 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4431 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4432 PEER_FLAG_MED_UNCHANGED);
4433 }
d62a17ae 4434 }
4435
8eeb0335 4436 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4437}
4438
4439ALIAS_HIDDEN(
4440 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4441 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4442 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4443 "BGP attribute is propagated unchanged to this neighbor\n"
4444 "As-path attribute\n"
4445 "Nexthop attribute\n"
4446 "Med attribute\n")
596c17ba 4447
718e3744 4448DEFUN (no_neighbor_attr_unchanged,
4449 no_neighbor_attr_unchanged_cmd,
a8206004 4450 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4451 NO_STR
718e3744 4452 NEIGHBOR_STR
4453 NEIGHBOR_ADDR_STR2
31500417
DW
4454 "BGP attribute is propagated unchanged to this neighbor\n"
4455 "As-path attribute\n"
40e718b5 4456 "Nexthop attribute\n"
a8206004 4457 "Med attribute\n")
718e3744 4458{
d62a17ae 4459 int idx = 0;
4460 char *peer = argv[2]->arg;
d7c0a89a 4461 uint16_t flags = 0;
d62a17ae 4462
4463 if (argv_find(argv, argc, "as-path", &idx))
4464 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4465 idx = 0;
4466 if (argv_find(argv, argc, "next-hop", &idx))
4467 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4468 idx = 0;
4469 if (argv_find(argv, argc, "med", &idx))
4470 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4471
4472 if (!flags) // no flags means all of them!
4473 {
4474 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4475 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4476 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4477 }
4478
4479 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4480 bgp_node_safi(vty), flags);
4481}
4482
4483ALIAS_HIDDEN(
4484 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4485 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4486 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4487 "BGP attribute is propagated unchanged to this neighbor\n"
4488 "As-path attribute\n"
4489 "Nexthop attribute\n"
4490 "Med attribute\n")
718e3744 4491
718e3744 4492/* EBGP multihop configuration. */
d62a17ae 4493static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4494 const char *ttl_str)
718e3744 4495{
d62a17ae 4496 struct peer *peer;
4497 unsigned int ttl;
718e3744 4498
d62a17ae 4499 peer = peer_and_group_lookup_vty(vty, ip_str);
4500 if (!peer)
4501 return CMD_WARNING_CONFIG_FAILED;
718e3744 4502
d62a17ae 4503 if (peer->conf_if)
4504 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4505
d62a17ae 4506 if (!ttl_str)
4507 ttl = MAXTTL;
4508 else
4509 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4510
d62a17ae 4511 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4512}
4513
d62a17ae 4514static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4515{
d62a17ae 4516 struct peer *peer;
718e3744 4517
d62a17ae 4518 peer = peer_and_group_lookup_vty(vty, ip_str);
4519 if (!peer)
4520 return CMD_WARNING_CONFIG_FAILED;
718e3744 4521
d62a17ae 4522 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4523}
4524
4525/* neighbor ebgp-multihop. */
4526DEFUN (neighbor_ebgp_multihop,
4527 neighbor_ebgp_multihop_cmd,
9ccf14f7 4528 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4529 NEIGHBOR_STR
4530 NEIGHBOR_ADDR_STR2
4531 "Allow EBGP neighbors not on directly connected networks\n")
4532{
d62a17ae 4533 int idx_peer = 1;
4534 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4535}
4536
4537DEFUN (neighbor_ebgp_multihop_ttl,
4538 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4539 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4540 NEIGHBOR_STR
4541 NEIGHBOR_ADDR_STR2
4542 "Allow EBGP neighbors not on directly connected networks\n"
4543 "maximum hop count\n")
4544{
d62a17ae 4545 int idx_peer = 1;
4546 int idx_number = 3;
4547 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4548 argv[idx_number]->arg);
718e3744 4549}
4550
4551DEFUN (no_neighbor_ebgp_multihop,
4552 no_neighbor_ebgp_multihop_cmd,
a636c635 4553 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4554 NO_STR
4555 NEIGHBOR_STR
4556 NEIGHBOR_ADDR_STR2
a636c635
DW
4557 "Allow EBGP neighbors not on directly connected networks\n"
4558 "maximum hop count\n")
718e3744 4559{
d62a17ae 4560 int idx_peer = 2;
4561 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4562}
4563
6b0655a2 4564
6ffd2079 4565/* disable-connected-check */
4566DEFUN (neighbor_disable_connected_check,
4567 neighbor_disable_connected_check_cmd,
7ebe625c 4568 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4569 NEIGHBOR_STR
7ebe625c 4570 NEIGHBOR_ADDR_STR2
a636c635
DW
4571 "one-hop away EBGP peer using loopback address\n"
4572 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4573{
d62a17ae 4574 int idx_peer = 1;
4575 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4576 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4577}
4578
4579DEFUN (no_neighbor_disable_connected_check,
4580 no_neighbor_disable_connected_check_cmd,
7ebe625c 4581 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4582 NO_STR
4583 NEIGHBOR_STR
7ebe625c 4584 NEIGHBOR_ADDR_STR2
a636c635
DW
4585 "one-hop away EBGP peer using loopback address\n"
4586 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4587{
d62a17ae 4588 int idx_peer = 2;
4589 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4590 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4591}
4592
47cbc09b
PM
4593
4594/* enforce-first-as */
4595DEFUN (neighbor_enforce_first_as,
4596 neighbor_enforce_first_as_cmd,
4597 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4598 NEIGHBOR_STR
4599 NEIGHBOR_ADDR_STR2
4600 "Enforce the first AS for EBGP routes\n")
4601{
4602 int idx_peer = 1;
4603
4604 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4605 PEER_FLAG_ENFORCE_FIRST_AS);
4606}
4607
4608DEFUN (no_neighbor_enforce_first_as,
4609 no_neighbor_enforce_first_as_cmd,
4610 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4611 NO_STR
4612 NEIGHBOR_STR
4613 NEIGHBOR_ADDR_STR2
4614 "Enforce the first AS for EBGP routes\n")
4615{
4616 int idx_peer = 2;
4617
4618 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4619 PEER_FLAG_ENFORCE_FIRST_AS);
4620}
4621
4622
718e3744 4623DEFUN (neighbor_description,
4624 neighbor_description_cmd,
e961923c 4625 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4626 NEIGHBOR_STR
4627 NEIGHBOR_ADDR_STR2
4628 "Neighbor specific description\n"
4629 "Up to 80 characters describing this neighbor\n")
4630{
d62a17ae 4631 int idx_peer = 1;
4632 int idx_line = 3;
4633 struct peer *peer;
4634 char *str;
718e3744 4635
d62a17ae 4636 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4637 if (!peer)
4638 return CMD_WARNING_CONFIG_FAILED;
718e3744 4639
d62a17ae 4640 str = argv_concat(argv, argc, idx_line);
718e3744 4641
d62a17ae 4642 peer_description_set(peer, str);
718e3744 4643
d62a17ae 4644 XFREE(MTYPE_TMP, str);
718e3744 4645
d62a17ae 4646 return CMD_SUCCESS;
718e3744 4647}
4648
4649DEFUN (no_neighbor_description,
4650 no_neighbor_description_cmd,
a14810f4 4651 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4652 NO_STR
4653 NEIGHBOR_STR
4654 NEIGHBOR_ADDR_STR2
a14810f4 4655 "Neighbor specific description\n")
718e3744 4656{
d62a17ae 4657 int idx_peer = 2;
4658 struct peer *peer;
718e3744 4659
d62a17ae 4660 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4661 if (!peer)
4662 return CMD_WARNING_CONFIG_FAILED;
718e3744 4663
d62a17ae 4664 peer_description_unset(peer);
718e3744 4665
d62a17ae 4666 return CMD_SUCCESS;
718e3744 4667}
4668
a14810f4
PM
4669ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4670 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4671 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4672 "Neighbor specific description\n"
4673 "Up to 80 characters describing this neighbor\n")
6b0655a2 4674
718e3744 4675/* Neighbor update-source. */
d62a17ae 4676static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4677 const char *source_str)
4678{
4679 struct peer *peer;
4680 struct prefix p;
a14810f4 4681 union sockunion su;
d62a17ae 4682
4683 peer = peer_and_group_lookup_vty(vty, peer_str);
4684 if (!peer)
4685 return CMD_WARNING_CONFIG_FAILED;
4686
4687 if (peer->conf_if)
4688 return CMD_WARNING;
4689
4690 if (source_str) {
a14810f4 4691 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4692 peer_update_source_addr_set(peer, &su);
4693 else {
4694 if (str2prefix(source_str, &p)) {
4695 vty_out(vty,
4696 "%% Invalid update-source, remove prefix length \n");
4697 return CMD_WARNING_CONFIG_FAILED;
4698 } else
4699 peer_update_source_if_set(peer, source_str);
4700 }
4701 } else
4702 peer_update_source_unset(peer);
4703
4704 return CMD_SUCCESS;
4705}
4706
4707#define BGP_UPDATE_SOURCE_HELP_STR \
4708 "IPv4 address\n" \
4709 "IPv6 address\n" \
4710 "Interface name (requires zebra to be running)\n"
369688c0 4711
718e3744 4712DEFUN (neighbor_update_source,
4713 neighbor_update_source_cmd,
9ccf14f7 4714 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4715 NEIGHBOR_STR
4716 NEIGHBOR_ADDR_STR2
4717 "Source of routing updates\n"
369688c0 4718 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4719{
d62a17ae 4720 int idx_peer = 1;
4721 int idx_peer_2 = 3;
4722 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4723 argv[idx_peer_2]->arg);
718e3744 4724}
4725
4726DEFUN (no_neighbor_update_source,
4727 no_neighbor_update_source_cmd,
c7178fe7 4728 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4729 NO_STR
4730 NEIGHBOR_STR
4731 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4732 "Source of routing updates\n"
4733 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4734{
d62a17ae 4735 int idx_peer = 2;
4736 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4737}
6b0655a2 4738
d62a17ae 4739static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4740 afi_t afi, safi_t safi,
4741 const char *rmap, int set)
718e3744 4742{
d62a17ae 4743 int ret;
4744 struct peer *peer;
718e3744 4745
d62a17ae 4746 peer = peer_and_group_lookup_vty(vty, peer_str);
4747 if (!peer)
4748 return CMD_WARNING_CONFIG_FAILED;
718e3744 4749
d62a17ae 4750 if (set)
4751 ret = peer_default_originate_set(peer, afi, safi, rmap);
4752 else
4753 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4754
d62a17ae 4755 return bgp_vty_return(vty, ret);
718e3744 4756}
4757
4758/* neighbor default-originate. */
4759DEFUN (neighbor_default_originate,
4760 neighbor_default_originate_cmd,
9ccf14f7 4761 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4762 NEIGHBOR_STR
4763 NEIGHBOR_ADDR_STR2
4764 "Originate default route to this neighbor\n")
4765{
d62a17ae 4766 int idx_peer = 1;
4767 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4768 bgp_node_afi(vty),
4769 bgp_node_safi(vty), NULL, 1);
718e3744 4770}
4771
d62a17ae 4772ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4773 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4774 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4775 "Originate default route to this neighbor\n")
596c17ba 4776
718e3744 4777DEFUN (neighbor_default_originate_rmap,
4778 neighbor_default_originate_rmap_cmd,
9ccf14f7 4779 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4780 NEIGHBOR_STR
4781 NEIGHBOR_ADDR_STR2
4782 "Originate default route to this neighbor\n"
4783 "Route-map to specify criteria to originate default\n"
4784 "route-map name\n")
4785{
d62a17ae 4786 int idx_peer = 1;
4787 int idx_word = 4;
4788 return peer_default_originate_set_vty(
4789 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4790 argv[idx_word]->arg, 1);
718e3744 4791}
4792
d62a17ae 4793ALIAS_HIDDEN(
4794 neighbor_default_originate_rmap,
4795 neighbor_default_originate_rmap_hidden_cmd,
4796 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4797 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4798 "Originate default route to this neighbor\n"
4799 "Route-map to specify criteria to originate default\n"
4800 "route-map name\n")
596c17ba 4801
718e3744 4802DEFUN (no_neighbor_default_originate,
4803 no_neighbor_default_originate_cmd,
a636c635 4804 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4805 NO_STR
4806 NEIGHBOR_STR
4807 NEIGHBOR_ADDR_STR2
a636c635
DW
4808 "Originate default route to this neighbor\n"
4809 "Route-map to specify criteria to originate default\n"
4810 "route-map name\n")
718e3744 4811{
d62a17ae 4812 int idx_peer = 2;
4813 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4814 bgp_node_afi(vty),
4815 bgp_node_safi(vty), NULL, 0);
718e3744 4816}
4817
d62a17ae 4818ALIAS_HIDDEN(
4819 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4820 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4821 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4822 "Originate default route to this neighbor\n"
4823 "Route-map to specify criteria to originate default\n"
4824 "route-map name\n")
596c17ba 4825
6b0655a2 4826
718e3744 4827/* Set neighbor's BGP port. */
d62a17ae 4828static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4829 const char *port_str)
4830{
4831 struct peer *peer;
d7c0a89a 4832 uint16_t port;
d62a17ae 4833 struct servent *sp;
4834
4835 peer = peer_lookup_vty(vty, ip_str);
4836 if (!peer)
4837 return CMD_WARNING_CONFIG_FAILED;
4838
4839 if (!port_str) {
4840 sp = getservbyname("bgp", "tcp");
4841 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4842 } else {
4843 port = strtoul(port_str, NULL, 10);
4844 }
718e3744 4845
d62a17ae 4846 peer_port_set(peer, port);
718e3744 4847
d62a17ae 4848 return CMD_SUCCESS;
718e3744 4849}
4850
f418446b 4851/* Set specified peer's BGP port. */
718e3744 4852DEFUN (neighbor_port,
4853 neighbor_port_cmd,
9ccf14f7 4854 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4855 NEIGHBOR_STR
4856 NEIGHBOR_ADDR_STR
4857 "Neighbor's BGP port\n"
4858 "TCP port number\n")
4859{
d62a17ae 4860 int idx_ip = 1;
4861 int idx_number = 3;
4862 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4863 argv[idx_number]->arg);
718e3744 4864}
4865
4866DEFUN (no_neighbor_port,
4867 no_neighbor_port_cmd,
9ccf14f7 4868 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4869 NO_STR
4870 NEIGHBOR_STR
4871 NEIGHBOR_ADDR_STR
8334fd5a
DW
4872 "Neighbor's BGP port\n"
4873 "TCP port number\n")
718e3744 4874{
d62a17ae 4875 int idx_ip = 2;
4876 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4877}
4878
6b0655a2 4879
718e3744 4880/* neighbor weight. */
d62a17ae 4881static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4882 safi_t safi, const char *weight_str)
718e3744 4883{
d62a17ae 4884 int ret;
4885 struct peer *peer;
4886 unsigned long weight;
718e3744 4887
d62a17ae 4888 peer = peer_and_group_lookup_vty(vty, ip_str);
4889 if (!peer)
4890 return CMD_WARNING_CONFIG_FAILED;
718e3744 4891
d62a17ae 4892 weight = strtoul(weight_str, NULL, 10);
718e3744 4893
d62a17ae 4894 ret = peer_weight_set(peer, afi, safi, weight);
4895 return bgp_vty_return(vty, ret);
718e3744 4896}
4897
d62a17ae 4898static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4899 safi_t safi)
718e3744 4900{
d62a17ae 4901 int ret;
4902 struct peer *peer;
718e3744 4903
d62a17ae 4904 peer = peer_and_group_lookup_vty(vty, ip_str);
4905 if (!peer)
4906 return CMD_WARNING_CONFIG_FAILED;
718e3744 4907
d62a17ae 4908 ret = peer_weight_unset(peer, afi, safi);
4909 return bgp_vty_return(vty, ret);
718e3744 4910}
4911
4912DEFUN (neighbor_weight,
4913 neighbor_weight_cmd,
9ccf14f7 4914 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4915 NEIGHBOR_STR
4916 NEIGHBOR_ADDR_STR2
4917 "Set default weight for routes from this neighbor\n"
4918 "default weight\n")
4919{
d62a17ae 4920 int idx_peer = 1;
4921 int idx_number = 3;
4922 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4923 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4924}
4925
d62a17ae 4926ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4927 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4928 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4929 "Set default weight for routes from this neighbor\n"
4930 "default weight\n")
596c17ba 4931
718e3744 4932DEFUN (no_neighbor_weight,
4933 no_neighbor_weight_cmd,
9ccf14f7 4934 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4935 NO_STR
4936 NEIGHBOR_STR
4937 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4938 "Set default weight for routes from this neighbor\n"
4939 "default weight\n")
718e3744 4940{
d62a17ae 4941 int idx_peer = 2;
4942 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4943 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4944}
4945
d62a17ae 4946ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4947 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4948 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4949 "Set default weight for routes from this neighbor\n"
4950 "default weight\n")
596c17ba 4951
6b0655a2 4952
718e3744 4953/* Override capability negotiation. */
4954DEFUN (neighbor_override_capability,
4955 neighbor_override_capability_cmd,
9ccf14f7 4956 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4957 NEIGHBOR_STR
4958 NEIGHBOR_ADDR_STR2
4959 "Override capability negotiation result\n")
4960{
d62a17ae 4961 int idx_peer = 1;
4962 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4963 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4964}
4965
4966DEFUN (no_neighbor_override_capability,
4967 no_neighbor_override_capability_cmd,
9ccf14f7 4968 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4969 NO_STR
4970 NEIGHBOR_STR
4971 NEIGHBOR_ADDR_STR2
4972 "Override capability negotiation result\n")
4973{
d62a17ae 4974 int idx_peer = 2;
4975 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4976 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4977}
6b0655a2 4978
718e3744 4979DEFUN (neighbor_strict_capability,
4980 neighbor_strict_capability_cmd,
9fb964de 4981 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 4982 NEIGHBOR_STR
9fb964de 4983 NEIGHBOR_ADDR_STR2
718e3744 4984 "Strict capability negotiation match\n")
4985{
9fb964de
PM
4986 int idx_peer = 1;
4987
4988 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 4989 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4990}
4991
4992DEFUN (no_neighbor_strict_capability,
4993 no_neighbor_strict_capability_cmd,
9fb964de 4994 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 4995 NO_STR
4996 NEIGHBOR_STR
9fb964de 4997 NEIGHBOR_ADDR_STR2
718e3744 4998 "Strict capability negotiation match\n")
4999{
9fb964de
PM
5000 int idx_peer = 2;
5001
5002 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5003 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5004}
6b0655a2 5005
d62a17ae 5006static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5007 const char *keep_str, const char *hold_str)
718e3744 5008{
d62a17ae 5009 int ret;
5010 struct peer *peer;
d7c0a89a
QY
5011 uint32_t keepalive;
5012 uint32_t holdtime;
718e3744 5013
d62a17ae 5014 peer = peer_and_group_lookup_vty(vty, ip_str);
5015 if (!peer)
5016 return CMD_WARNING_CONFIG_FAILED;
718e3744 5017
d62a17ae 5018 keepalive = strtoul(keep_str, NULL, 10);
5019 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5020
d62a17ae 5021 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5022
d62a17ae 5023 return bgp_vty_return(vty, ret);
718e3744 5024}
6b0655a2 5025
d62a17ae 5026static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5027{
d62a17ae 5028 int ret;
5029 struct peer *peer;
718e3744 5030
d62a17ae 5031 peer = peer_and_group_lookup_vty(vty, ip_str);
5032 if (!peer)
5033 return CMD_WARNING_CONFIG_FAILED;
718e3744 5034
d62a17ae 5035 ret = peer_timers_unset(peer);
718e3744 5036
d62a17ae 5037 return bgp_vty_return(vty, ret);
718e3744 5038}
5039
5040DEFUN (neighbor_timers,
5041 neighbor_timers_cmd,
9ccf14f7 5042 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5043 NEIGHBOR_STR
5044 NEIGHBOR_ADDR_STR2
5045 "BGP per neighbor timers\n"
5046 "Keepalive interval\n"
5047 "Holdtime\n")
5048{
d62a17ae 5049 int idx_peer = 1;
5050 int idx_number = 3;
5051 int idx_number_2 = 4;
5052 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5053 argv[idx_number]->arg,
5054 argv[idx_number_2]->arg);
718e3744 5055}
5056
5057DEFUN (no_neighbor_timers,
5058 no_neighbor_timers_cmd,
9ccf14f7 5059 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5060 NO_STR
5061 NEIGHBOR_STR
5062 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5063 "BGP per neighbor timers\n"
5064 "Keepalive interval\n"
5065 "Holdtime\n")
718e3744 5066{
d62a17ae 5067 int idx_peer = 2;
5068 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5069}
6b0655a2 5070
813d4307 5071
d62a17ae 5072static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5073 const char *time_str)
718e3744 5074{
d62a17ae 5075 int ret;
5076 struct peer *peer;
d7c0a89a 5077 uint32_t connect;
718e3744 5078
d62a17ae 5079 peer = peer_and_group_lookup_vty(vty, ip_str);
5080 if (!peer)
5081 return CMD_WARNING_CONFIG_FAILED;
718e3744 5082
d62a17ae 5083 connect = strtoul(time_str, NULL, 10);
718e3744 5084
d62a17ae 5085 ret = peer_timers_connect_set(peer, connect);
718e3744 5086
d62a17ae 5087 return bgp_vty_return(vty, ret);
718e3744 5088}
5089
d62a17ae 5090static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5091{
d62a17ae 5092 int ret;
5093 struct peer *peer;
718e3744 5094
d62a17ae 5095 peer = peer_and_group_lookup_vty(vty, ip_str);
5096 if (!peer)
5097 return CMD_WARNING_CONFIG_FAILED;
718e3744 5098
d62a17ae 5099 ret = peer_timers_connect_unset(peer);
718e3744 5100
d62a17ae 5101 return bgp_vty_return(vty, ret);
718e3744 5102}
5103
5104DEFUN (neighbor_timers_connect,
5105 neighbor_timers_connect_cmd,
9ccf14f7 5106 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5107 NEIGHBOR_STR
966f821c 5108 NEIGHBOR_ADDR_STR2
718e3744 5109 "BGP per neighbor timers\n"
5110 "BGP connect timer\n"
5111 "Connect timer\n")
5112{
d62a17ae 5113 int idx_peer = 1;
5114 int idx_number = 4;
5115 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5116 argv[idx_number]->arg);
718e3744 5117}
5118
5119DEFUN (no_neighbor_timers_connect,
5120 no_neighbor_timers_connect_cmd,
9ccf14f7 5121 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5122 NO_STR
5123 NEIGHBOR_STR
966f821c 5124 NEIGHBOR_ADDR_STR2
718e3744 5125 "BGP per neighbor timers\n"
8334fd5a
DW
5126 "BGP connect timer\n"
5127 "Connect timer\n")
718e3744 5128{
d62a17ae 5129 int idx_peer = 2;
5130 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5131}
5132
6b0655a2 5133
d62a17ae 5134static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5135 const char *time_str, int set)
718e3744 5136{
d62a17ae 5137 int ret;
5138 struct peer *peer;
d7c0a89a 5139 uint32_t routeadv = 0;
718e3744 5140
d62a17ae 5141 peer = peer_and_group_lookup_vty(vty, ip_str);
5142 if (!peer)
5143 return CMD_WARNING_CONFIG_FAILED;
718e3744 5144
d62a17ae 5145 if (time_str)
5146 routeadv = strtoul(time_str, NULL, 10);
718e3744 5147
d62a17ae 5148 if (set)
5149 ret = peer_advertise_interval_set(peer, routeadv);
5150 else
5151 ret = peer_advertise_interval_unset(peer);
718e3744 5152
d62a17ae 5153 return bgp_vty_return(vty, ret);
718e3744 5154}
5155
5156DEFUN (neighbor_advertise_interval,
5157 neighbor_advertise_interval_cmd,
9ccf14f7 5158 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5159 NEIGHBOR_STR
966f821c 5160 NEIGHBOR_ADDR_STR2
718e3744 5161 "Minimum interval between sending BGP routing updates\n"
5162 "time in seconds\n")
5163{
d62a17ae 5164 int idx_peer = 1;
5165 int idx_number = 3;
5166 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5167 argv[idx_number]->arg, 1);
718e3744 5168}
5169
5170DEFUN (no_neighbor_advertise_interval,
5171 no_neighbor_advertise_interval_cmd,
9ccf14f7 5172 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5173 NO_STR
5174 NEIGHBOR_STR
966f821c 5175 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5176 "Minimum interval between sending BGP routing updates\n"
5177 "time in seconds\n")
718e3744 5178{
d62a17ae 5179 int idx_peer = 2;
5180 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5181}
5182
6b0655a2 5183
518f0eb1
DS
5184/* Time to wait before processing route-map updates */
5185DEFUN (bgp_set_route_map_delay_timer,
5186 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5187 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5188 SET_STR
5189 "BGP route-map delay timer\n"
5190 "Time in secs to wait before processing route-map changes\n"
f414725f 5191 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5192{
d62a17ae 5193 int idx_number = 3;
d7c0a89a 5194 uint32_t rmap_delay_timer;
d62a17ae 5195
5196 if (argv[idx_number]->arg) {
5197 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5198 bm->rmap_update_timer = rmap_delay_timer;
5199
5200 /* if the dynamic update handling is being disabled, and a timer
5201 * is
5202 * running, stop the timer and act as if the timer has already
5203 * fired.
5204 */
5205 if (!rmap_delay_timer && bm->t_rmap_update) {
5206 BGP_TIMER_OFF(bm->t_rmap_update);
5207 thread_execute(bm->master, bgp_route_map_update_timer,
5208 NULL, 0);
5209 }
5210 return CMD_SUCCESS;
5211 } else {
5212 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5213 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5214 }
518f0eb1
DS
5215}
5216
5217DEFUN (no_bgp_set_route_map_delay_timer,
5218 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5219 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5220 NO_STR
3a2d747c 5221 BGP_STR
518f0eb1 5222 "Default BGP route-map delay timer\n"
8334fd5a
DW
5223 "Reset to default time to wait for processing route-map changes\n"
5224 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5225{
518f0eb1 5226
d62a17ae 5227 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5228
d62a17ae 5229 return CMD_SUCCESS;
518f0eb1
DS
5230}
5231
f414725f 5232
718e3744 5233/* neighbor interface */
d62a17ae 5234static int peer_interface_vty(struct vty *vty, const char *ip_str,
5235 const char *str)
718e3744 5236{
d62a17ae 5237 struct peer *peer;
718e3744 5238
d62a17ae 5239 peer = peer_lookup_vty(vty, ip_str);
5240 if (!peer || peer->conf_if) {
5241 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5242 return CMD_WARNING_CONFIG_FAILED;
5243 }
718e3744 5244
d62a17ae 5245 if (str)
5246 peer_interface_set(peer, str);
5247 else
5248 peer_interface_unset(peer);
718e3744 5249
d62a17ae 5250 return CMD_SUCCESS;
718e3744 5251}
5252
5253DEFUN (neighbor_interface,
5254 neighbor_interface_cmd,
9ccf14f7 5255 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5256 NEIGHBOR_STR
5257 NEIGHBOR_ADDR_STR
5258 "Interface\n"
5259 "Interface name\n")
5260{
d62a17ae 5261 int idx_ip = 1;
5262 int idx_word = 3;
5263 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5264}
5265
5266DEFUN (no_neighbor_interface,
5267 no_neighbor_interface_cmd,
9ccf14f7 5268 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5269 NO_STR
5270 NEIGHBOR_STR
16cedbb0 5271 NEIGHBOR_ADDR_STR2
718e3744 5272 "Interface\n"
5273 "Interface name\n")
5274{
d62a17ae 5275 int idx_peer = 2;
5276 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5277}
6b0655a2 5278
718e3744 5279DEFUN (neighbor_distribute_list,
5280 neighbor_distribute_list_cmd,
9ccf14f7 5281 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5282 NEIGHBOR_STR
5283 NEIGHBOR_ADDR_STR2
5284 "Filter updates to/from this neighbor\n"
5285 "IP access-list number\n"
5286 "IP access-list number (expanded range)\n"
5287 "IP Access-list name\n"
5288 "Filter incoming updates\n"
5289 "Filter outgoing updates\n")
5290{
d62a17ae 5291 int idx_peer = 1;
5292 int idx_acl = 3;
5293 int direct, ret;
5294 struct peer *peer;
a8206004 5295
d62a17ae 5296 const char *pstr = argv[idx_peer]->arg;
5297 const char *acl = argv[idx_acl]->arg;
5298 const char *inout = argv[argc - 1]->text;
a8206004 5299
d62a17ae 5300 peer = peer_and_group_lookup_vty(vty, pstr);
5301 if (!peer)
5302 return CMD_WARNING_CONFIG_FAILED;
a8206004 5303
d62a17ae 5304 /* Check filter direction. */
5305 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5306 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5307 direct, acl);
a8206004 5308
d62a17ae 5309 return bgp_vty_return(vty, ret);
718e3744 5310}
5311
d62a17ae 5312ALIAS_HIDDEN(
5313 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5314 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5315 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5316 "Filter updates to/from this neighbor\n"
5317 "IP access-list number\n"
5318 "IP access-list number (expanded range)\n"
5319 "IP Access-list name\n"
5320 "Filter incoming updates\n"
5321 "Filter outgoing updates\n")
596c17ba 5322
718e3744 5323DEFUN (no_neighbor_distribute_list,
5324 no_neighbor_distribute_list_cmd,
9ccf14f7 5325 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5326 NO_STR
5327 NEIGHBOR_STR
5328 NEIGHBOR_ADDR_STR2
5329 "Filter updates to/from this neighbor\n"
5330 "IP access-list number\n"
5331 "IP access-list number (expanded range)\n"
5332 "IP Access-list name\n"
5333 "Filter incoming updates\n"
5334 "Filter outgoing updates\n")
5335{
d62a17ae 5336 int idx_peer = 2;
5337 int direct, ret;
5338 struct peer *peer;
a8206004 5339
d62a17ae 5340 const char *pstr = argv[idx_peer]->arg;
5341 const char *inout = argv[argc - 1]->text;
a8206004 5342
d62a17ae 5343 peer = peer_and_group_lookup_vty(vty, pstr);
5344 if (!peer)
5345 return CMD_WARNING_CONFIG_FAILED;
a8206004 5346
d62a17ae 5347 /* Check filter direction. */
5348 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5349 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5350 direct);
a8206004 5351
d62a17ae 5352 return bgp_vty_return(vty, ret);
718e3744 5353}
6b0655a2 5354
d62a17ae 5355ALIAS_HIDDEN(
5356 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5357 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5358 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5359 "Filter updates to/from this neighbor\n"
5360 "IP access-list number\n"
5361 "IP access-list number (expanded range)\n"
5362 "IP Access-list name\n"
5363 "Filter incoming updates\n"
5364 "Filter outgoing updates\n")
596c17ba 5365
718e3744 5366/* Set prefix list to the peer. */
d62a17ae 5367static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5368 afi_t afi, safi_t safi,
5369 const char *name_str,
5370 const char *direct_str)
718e3744 5371{
d62a17ae 5372 int ret;
d62a17ae 5373 int direct = FILTER_IN;
cf9ac8bf 5374 struct peer *peer;
718e3744 5375
d62a17ae 5376 peer = peer_and_group_lookup_vty(vty, ip_str);
5377 if (!peer)
5378 return CMD_WARNING_CONFIG_FAILED;
718e3744 5379
d62a17ae 5380 /* Check filter direction. */
5381 if (strncmp(direct_str, "i", 1) == 0)
5382 direct = FILTER_IN;
5383 else if (strncmp(direct_str, "o", 1) == 0)
5384 direct = FILTER_OUT;
718e3744 5385
d62a17ae 5386 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5387
d62a17ae 5388 return bgp_vty_return(vty, ret);
718e3744 5389}
5390
d62a17ae 5391static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5392 afi_t afi, safi_t safi,
5393 const char *direct_str)
718e3744 5394{
d62a17ae 5395 int ret;
5396 struct peer *peer;
5397 int direct = FILTER_IN;
718e3744 5398
d62a17ae 5399 peer = peer_and_group_lookup_vty(vty, ip_str);
5400 if (!peer)
5401 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5402
d62a17ae 5403 /* Check filter direction. */
5404 if (strncmp(direct_str, "i", 1) == 0)
5405 direct = FILTER_IN;
5406 else if (strncmp(direct_str, "o", 1) == 0)
5407 direct = FILTER_OUT;
718e3744 5408
d62a17ae 5409 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5410
d62a17ae 5411 return bgp_vty_return(vty, ret);
718e3744 5412}
5413
5414DEFUN (neighbor_prefix_list,
5415 neighbor_prefix_list_cmd,
9ccf14f7 5416 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5417 NEIGHBOR_STR
5418 NEIGHBOR_ADDR_STR2
5419 "Filter updates to/from this neighbor\n"
5420 "Name of a prefix list\n"
5421 "Filter incoming updates\n"
5422 "Filter outgoing updates\n")
5423{
d62a17ae 5424 int idx_peer = 1;
5425 int idx_word = 3;
5426 int idx_in_out = 4;
5427 return peer_prefix_list_set_vty(
5428 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5429 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5430}
5431
d62a17ae 5432ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5433 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5434 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5435 "Filter updates to/from this neighbor\n"
5436 "Name of a prefix list\n"
5437 "Filter incoming updates\n"
5438 "Filter outgoing updates\n")
596c17ba 5439
718e3744 5440DEFUN (no_neighbor_prefix_list,
5441 no_neighbor_prefix_list_cmd,
9ccf14f7 5442 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5443 NO_STR
5444 NEIGHBOR_STR
5445 NEIGHBOR_ADDR_STR2
5446 "Filter updates to/from this neighbor\n"
5447 "Name of a prefix list\n"
5448 "Filter incoming updates\n"
5449 "Filter outgoing updates\n")
5450{
d62a17ae 5451 int idx_peer = 2;
5452 int idx_in_out = 5;
5453 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5454 bgp_node_afi(vty), bgp_node_safi(vty),
5455 argv[idx_in_out]->arg);
718e3744 5456}
6b0655a2 5457
d62a17ae 5458ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5459 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5460 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5461 "Filter updates to/from this neighbor\n"
5462 "Name of a prefix list\n"
5463 "Filter incoming updates\n"
5464 "Filter outgoing updates\n")
596c17ba 5465
d62a17ae 5466static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5467 safi_t safi, const char *name_str,
5468 const char *direct_str)
718e3744 5469{
d62a17ae 5470 int ret;
5471 struct peer *peer;
5472 int direct = FILTER_IN;
718e3744 5473
d62a17ae 5474 peer = peer_and_group_lookup_vty(vty, ip_str);
5475 if (!peer)
5476 return CMD_WARNING_CONFIG_FAILED;
718e3744 5477
d62a17ae 5478 /* Check filter direction. */
5479 if (strncmp(direct_str, "i", 1) == 0)
5480 direct = FILTER_IN;
5481 else if (strncmp(direct_str, "o", 1) == 0)
5482 direct = FILTER_OUT;
718e3744 5483
d62a17ae 5484 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5485
d62a17ae 5486 return bgp_vty_return(vty, ret);
718e3744 5487}
5488
d62a17ae 5489static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5490 safi_t safi, const char *direct_str)
718e3744 5491{
d62a17ae 5492 int ret;
5493 struct peer *peer;
5494 int direct = FILTER_IN;
718e3744 5495
d62a17ae 5496 peer = peer_and_group_lookup_vty(vty, ip_str);
5497 if (!peer)
5498 return CMD_WARNING_CONFIG_FAILED;
718e3744 5499
d62a17ae 5500 /* Check filter direction. */
5501 if (strncmp(direct_str, "i", 1) == 0)
5502 direct = FILTER_IN;
5503 else if (strncmp(direct_str, "o", 1) == 0)
5504 direct = FILTER_OUT;
718e3744 5505
d62a17ae 5506 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5507
d62a17ae 5508 return bgp_vty_return(vty, ret);
718e3744 5509}
5510
5511DEFUN (neighbor_filter_list,
5512 neighbor_filter_list_cmd,
9ccf14f7 5513 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5514 NEIGHBOR_STR
5515 NEIGHBOR_ADDR_STR2
5516 "Establish BGP filters\n"
5517 "AS path access-list name\n"
5518 "Filter incoming routes\n"
5519 "Filter outgoing routes\n")
5520{
d62a17ae 5521 int idx_peer = 1;
5522 int idx_word = 3;
5523 int idx_in_out = 4;
5524 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5525 bgp_node_safi(vty), argv[idx_word]->arg,
5526 argv[idx_in_out]->arg);
718e3744 5527}
5528
d62a17ae 5529ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5530 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5531 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5532 "Establish BGP filters\n"
5533 "AS path access-list name\n"
5534 "Filter incoming routes\n"
5535 "Filter outgoing routes\n")
596c17ba 5536
718e3744 5537DEFUN (no_neighbor_filter_list,
5538 no_neighbor_filter_list_cmd,
9ccf14f7 5539 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5540 NO_STR
5541 NEIGHBOR_STR
5542 NEIGHBOR_ADDR_STR2
5543 "Establish BGP filters\n"
5544 "AS path access-list name\n"
5545 "Filter incoming routes\n"
5546 "Filter outgoing routes\n")
5547{
d62a17ae 5548 int idx_peer = 2;
5549 int idx_in_out = 5;
5550 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5551 bgp_node_afi(vty), bgp_node_safi(vty),
5552 argv[idx_in_out]->arg);
718e3744 5553}
6b0655a2 5554
d62a17ae 5555ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5556 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5557 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5558 "Establish BGP filters\n"
5559 "AS path access-list name\n"
5560 "Filter incoming routes\n"
5561 "Filter outgoing routes\n")
596c17ba 5562
718e3744 5563/* Set route-map to the peer. */
d62a17ae 5564static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5565 afi_t afi, safi_t safi, const char *name_str,
5566 const char *direct_str)
718e3744 5567{
d62a17ae 5568 int ret;
5569 struct peer *peer;
5570 int direct = RMAP_IN;
718e3744 5571
d62a17ae 5572 peer = peer_and_group_lookup_vty(vty, ip_str);
5573 if (!peer)
5574 return CMD_WARNING_CONFIG_FAILED;
718e3744 5575
d62a17ae 5576 /* Check filter direction. */
5577 if (strncmp(direct_str, "in", 2) == 0)
5578 direct = RMAP_IN;
5579 else if (strncmp(direct_str, "o", 1) == 0)
5580 direct = RMAP_OUT;
718e3744 5581
d62a17ae 5582 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5583
d62a17ae 5584 return bgp_vty_return(vty, ret);
718e3744 5585}
5586
d62a17ae 5587static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5588 afi_t afi, safi_t safi,
5589 const char *direct_str)
718e3744 5590{
d62a17ae 5591 int ret;
5592 struct peer *peer;
5593 int direct = RMAP_IN;
718e3744 5594
d62a17ae 5595 peer = peer_and_group_lookup_vty(vty, ip_str);
5596 if (!peer)
5597 return CMD_WARNING_CONFIG_FAILED;
718e3744 5598
d62a17ae 5599 /* Check filter direction. */
5600 if (strncmp(direct_str, "in", 2) == 0)
5601 direct = RMAP_IN;
5602 else if (strncmp(direct_str, "o", 1) == 0)
5603 direct = RMAP_OUT;
718e3744 5604
d62a17ae 5605 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5606
d62a17ae 5607 return bgp_vty_return(vty, ret);
718e3744 5608}
5609
5610DEFUN (neighbor_route_map,
5611 neighbor_route_map_cmd,
9ccf14f7 5612 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5613 NEIGHBOR_STR
5614 NEIGHBOR_ADDR_STR2
5615 "Apply route map to neighbor\n"
5616 "Name of route map\n"
5617 "Apply map to incoming routes\n"
2a3d5731 5618 "Apply map to outbound routes\n")
718e3744 5619{
d62a17ae 5620 int idx_peer = 1;
5621 int idx_word = 3;
5622 int idx_in_out = 4;
5623 return peer_route_map_set_vty(
5624 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5625 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5626}
5627
d62a17ae 5628ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5629 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5630 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5631 "Apply route map to neighbor\n"
5632 "Name of route map\n"
5633 "Apply map to incoming routes\n"
5634 "Apply map to outbound routes\n")
596c17ba 5635
718e3744 5636DEFUN (no_neighbor_route_map,
5637 no_neighbor_route_map_cmd,
9ccf14f7 5638 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5639 NO_STR
5640 NEIGHBOR_STR
5641 NEIGHBOR_ADDR_STR2
5642 "Apply route map to neighbor\n"
5643 "Name of route map\n"
5644 "Apply map to incoming routes\n"
2a3d5731 5645 "Apply map to outbound routes\n")
718e3744 5646{
d62a17ae 5647 int idx_peer = 2;
5648 int idx_in_out = 5;
5649 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5650 bgp_node_afi(vty), bgp_node_safi(vty),
5651 argv[idx_in_out]->arg);
718e3744 5652}
6b0655a2 5653
d62a17ae 5654ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5655 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5656 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5657 "Apply route map to neighbor\n"
5658 "Name of route map\n"
5659 "Apply map to incoming routes\n"
5660 "Apply map to outbound routes\n")
596c17ba 5661
718e3744 5662/* Set unsuppress-map to the peer. */
d62a17ae 5663static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5664 afi_t afi, safi_t safi,
5665 const char *name_str)
718e3744 5666{
d62a17ae 5667 int ret;
5668 struct peer *peer;
718e3744 5669
d62a17ae 5670 peer = peer_and_group_lookup_vty(vty, ip_str);
5671 if (!peer)
5672 return CMD_WARNING_CONFIG_FAILED;
718e3744 5673
d62a17ae 5674 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5675
d62a17ae 5676 return bgp_vty_return(vty, ret);
718e3744 5677}
5678
5679/* Unset route-map from the peer. */
d62a17ae 5680static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5681 afi_t afi, safi_t safi)
718e3744 5682{
d62a17ae 5683 int ret;
5684 struct peer *peer;
718e3744 5685
d62a17ae 5686 peer = peer_and_group_lookup_vty(vty, ip_str);
5687 if (!peer)
5688 return CMD_WARNING_CONFIG_FAILED;
718e3744 5689
d62a17ae 5690 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5691
d62a17ae 5692 return bgp_vty_return(vty, ret);
718e3744 5693}
5694
5695DEFUN (neighbor_unsuppress_map,
5696 neighbor_unsuppress_map_cmd,
9ccf14f7 5697 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5698 NEIGHBOR_STR
5699 NEIGHBOR_ADDR_STR2
5700 "Route-map to selectively unsuppress suppressed routes\n"
5701 "Name of route map\n")
5702{
d62a17ae 5703 int idx_peer = 1;
5704 int idx_word = 3;
5705 return peer_unsuppress_map_set_vty(
5706 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5707 argv[idx_word]->arg);
718e3744 5708}
5709
d62a17ae 5710ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5711 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5712 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5713 "Route-map to selectively unsuppress suppressed routes\n"
5714 "Name of route map\n")
596c17ba 5715
718e3744 5716DEFUN (no_neighbor_unsuppress_map,
5717 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5718 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5719 NO_STR
5720 NEIGHBOR_STR
5721 NEIGHBOR_ADDR_STR2
5722 "Route-map to selectively unsuppress suppressed routes\n"
5723 "Name of route map\n")
5724{
d62a17ae 5725 int idx_peer = 2;
5726 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5727 bgp_node_afi(vty),
5728 bgp_node_safi(vty));
718e3744 5729}
6b0655a2 5730
d62a17ae 5731ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5732 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5733 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5734 "Route-map to selectively unsuppress suppressed routes\n"
5735 "Name of route map\n")
596c17ba 5736
d62a17ae 5737static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5738 afi_t afi, safi_t safi,
5739 const char *num_str,
5740 const char *threshold_str, int warning,
5741 const char *restart_str)
718e3744 5742{
d62a17ae 5743 int ret;
5744 struct peer *peer;
d7c0a89a
QY
5745 uint32_t max;
5746 uint8_t threshold;
5747 uint16_t restart;
718e3744 5748
d62a17ae 5749 peer = peer_and_group_lookup_vty(vty, ip_str);
5750 if (!peer)
5751 return CMD_WARNING_CONFIG_FAILED;
718e3744 5752
d62a17ae 5753 max = strtoul(num_str, NULL, 10);
5754 if (threshold_str)
5755 threshold = atoi(threshold_str);
5756 else
5757 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5758
d62a17ae 5759 if (restart_str)
5760 restart = atoi(restart_str);
5761 else
5762 restart = 0;
0a486e5f 5763
d62a17ae 5764 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5765 restart);
718e3744 5766
d62a17ae 5767 return bgp_vty_return(vty, ret);
718e3744 5768}
5769
d62a17ae 5770static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5771 afi_t afi, safi_t safi)
718e3744 5772{
d62a17ae 5773 int ret;
5774 struct peer *peer;
718e3744 5775
d62a17ae 5776 peer = peer_and_group_lookup_vty(vty, ip_str);
5777 if (!peer)
5778 return CMD_WARNING_CONFIG_FAILED;
718e3744 5779
d62a17ae 5780 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5781
d62a17ae 5782 return bgp_vty_return(vty, ret);
718e3744 5783}
5784
5785/* Maximum number of prefix configuration. prefix count is different
5786 for each peer configuration. So this configuration can be set for
5787 each peer configuration. */
5788DEFUN (neighbor_maximum_prefix,
5789 neighbor_maximum_prefix_cmd,
9ccf14f7 5790 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5791 NEIGHBOR_STR
5792 NEIGHBOR_ADDR_STR2
5793 "Maximum number of prefix accept from this peer\n"
5794 "maximum no. of prefix limit\n")
5795{
d62a17ae 5796 int idx_peer = 1;
5797 int idx_number = 3;
5798 return peer_maximum_prefix_set_vty(
5799 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5800 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5801}
5802
d62a17ae 5803ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5804 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5805 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5806 "Maximum number of prefix accept from this peer\n"
5807 "maximum no. of prefix limit\n")
596c17ba 5808
e0701b79 5809DEFUN (neighbor_maximum_prefix_threshold,
5810 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5811 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5812 NEIGHBOR_STR
5813 NEIGHBOR_ADDR_STR2
5814 "Maximum number of prefix accept from this peer\n"
5815 "maximum no. of prefix limit\n"
5816 "Threshold value (%) at which to generate a warning msg\n")
5817{
d62a17ae 5818 int idx_peer = 1;
5819 int idx_number = 3;
5820 int idx_number_2 = 4;
5821 return peer_maximum_prefix_set_vty(
5822 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5823 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5824}
e0701b79 5825
d62a17ae 5826ALIAS_HIDDEN(
5827 neighbor_maximum_prefix_threshold,
5828 neighbor_maximum_prefix_threshold_hidden_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5831 "Maximum number of prefix accept from this peer\n"
5832 "maximum no. of prefix limit\n"
5833 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5834
718e3744 5835DEFUN (neighbor_maximum_prefix_warning,
5836 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5837 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5838 NEIGHBOR_STR
5839 NEIGHBOR_ADDR_STR2
5840 "Maximum number of prefix accept from this peer\n"
5841 "maximum no. of prefix limit\n"
5842 "Only give warning message when limit is exceeded\n")
5843{
d62a17ae 5844 int idx_peer = 1;
5845 int idx_number = 3;
5846 return peer_maximum_prefix_set_vty(
5847 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5848 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5849}
5850
d62a17ae 5851ALIAS_HIDDEN(
5852 neighbor_maximum_prefix_warning,
5853 neighbor_maximum_prefix_warning_hidden_cmd,
5854 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5855 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5856 "Maximum number of prefix accept from this peer\n"
5857 "maximum no. of prefix limit\n"
5858 "Only give warning message when limit is exceeded\n")
596c17ba 5859
e0701b79 5860DEFUN (neighbor_maximum_prefix_threshold_warning,
5861 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5862 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5863 NEIGHBOR_STR
5864 NEIGHBOR_ADDR_STR2
5865 "Maximum number of prefix accept from this peer\n"
5866 "maximum no. of prefix limit\n"
5867 "Threshold value (%) at which to generate a warning msg\n"
5868 "Only give warning message when limit is exceeded\n")
5869{
d62a17ae 5870 int idx_peer = 1;
5871 int idx_number = 3;
5872 int idx_number_2 = 4;
5873 return peer_maximum_prefix_set_vty(
5874 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5875 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5876}
5877
d62a17ae 5878ALIAS_HIDDEN(
5879 neighbor_maximum_prefix_threshold_warning,
5880 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5881 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5882 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5883 "Maximum number of prefix accept from this peer\n"
5884 "maximum no. of prefix limit\n"
5885 "Threshold value (%) at which to generate a warning msg\n"
5886 "Only give warning message when limit is exceeded\n")
596c17ba 5887
0a486e5f 5888DEFUN (neighbor_maximum_prefix_restart,
5889 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5890 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5891 NEIGHBOR_STR
5892 NEIGHBOR_ADDR_STR2
5893 "Maximum number of prefix accept from this peer\n"
5894 "maximum no. of prefix limit\n"
5895 "Restart bgp connection after limit is exceeded\n"
efd7904e 5896 "Restart interval in minutes\n")
0a486e5f 5897{
d62a17ae 5898 int idx_peer = 1;
5899 int idx_number = 3;
5900 int idx_number_2 = 5;
5901 return peer_maximum_prefix_set_vty(
5902 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5903 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5904}
5905
d62a17ae 5906ALIAS_HIDDEN(
5907 neighbor_maximum_prefix_restart,
5908 neighbor_maximum_prefix_restart_hidden_cmd,
5909 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5910 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5911 "Maximum number of prefix accept from this peer\n"
5912 "maximum no. of prefix limit\n"
5913 "Restart bgp connection after limit is exceeded\n"
efd7904e 5914 "Restart interval in minutes\n")
596c17ba 5915
0a486e5f 5916DEFUN (neighbor_maximum_prefix_threshold_restart,
5917 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5918 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5919 NEIGHBOR_STR
5920 NEIGHBOR_ADDR_STR2
16cedbb0 5921 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5922 "maximum no. of prefix limit\n"
5923 "Threshold value (%) at which to generate a warning msg\n"
5924 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5925 "Restart interval in minutes\n")
0a486e5f 5926{
d62a17ae 5927 int idx_peer = 1;
5928 int idx_number = 3;
5929 int idx_number_2 = 4;
5930 int idx_number_3 = 6;
5931 return peer_maximum_prefix_set_vty(
5932 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5933 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5934 argv[idx_number_3]->arg);
5935}
5936
5937ALIAS_HIDDEN(
5938 neighbor_maximum_prefix_threshold_restart,
5939 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5940 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5941 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5942 "Maximum number of prefixes to accept from this peer\n"
5943 "maximum no. of prefix limit\n"
5944 "Threshold value (%) at which to generate a warning msg\n"
5945 "Restart bgp connection after limit is exceeded\n"
5946 "Restart interval in minutes\n")
596c17ba 5947
718e3744 5948DEFUN (no_neighbor_maximum_prefix,
5949 no_neighbor_maximum_prefix_cmd,
d04c479d 5950 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5951 NO_STR
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
16cedbb0 5954 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5955 "maximum no. of prefix limit\n"
5956 "Threshold value (%) at which to generate a warning msg\n"
5957 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5958 "Restart interval in minutes\n"
31500417 5959 "Only give warning message when limit is exceeded\n")
718e3744 5960{
d62a17ae 5961 int idx_peer = 2;
5962 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5963 bgp_node_afi(vty),
5964 bgp_node_safi(vty));
718e3744 5965}
e52702f2 5966
d62a17ae 5967ALIAS_HIDDEN(
5968 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5969 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5970 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5971 "Maximum number of prefixes to accept from this peer\n"
5972 "maximum no. of prefix limit\n"
5973 "Threshold value (%) at which to generate a warning msg\n"
5974 "Restart bgp connection after limit is exceeded\n"
5975 "Restart interval in minutes\n"
5976 "Only give warning message when limit is exceeded\n")
596c17ba 5977
718e3744 5978
718e3744 5979/* "neighbor allowas-in" */
5980DEFUN (neighbor_allowas_in,
5981 neighbor_allowas_in_cmd,
fd8503f5 5982 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5983 NEIGHBOR_STR
5984 NEIGHBOR_ADDR_STR2
31500417 5985 "Accept as-path with my AS present in it\n"
fd8503f5
QY
5986 "Number of occurances of AS number\n"
5987 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5988{
d62a17ae 5989 int idx_peer = 1;
5990 int idx_number_origin = 3;
5991 int ret;
5992 int origin = 0;
5993 struct peer *peer;
5994 int allow_num = 0;
5995
5996 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5997 if (!peer)
5998 return CMD_WARNING_CONFIG_FAILED;
5999
6000 if (argc <= idx_number_origin)
6001 allow_num = 3;
6002 else {
6003 if (argv[idx_number_origin]->type == WORD_TKN)
6004 origin = 1;
6005 else
6006 allow_num = atoi(argv[idx_number_origin]->arg);
6007 }
6008
6009 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6010 allow_num, origin);
6011
6012 return bgp_vty_return(vty, ret);
6013}
6014
6015ALIAS_HIDDEN(
6016 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6017 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6018 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6019 "Accept as-path with my AS present in it\n"
6020 "Number of occurances of AS number\n"
6021 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6022
718e3744 6023DEFUN (no_neighbor_allowas_in,
6024 no_neighbor_allowas_in_cmd,
fd8503f5 6025 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6026 NO_STR
6027 NEIGHBOR_STR
6028 NEIGHBOR_ADDR_STR2
8334fd5a 6029 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
6030 "Number of occurances of AS number\n"
6031 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6032{
d62a17ae 6033 int idx_peer = 2;
6034 int ret;
6035 struct peer *peer;
718e3744 6036
d62a17ae 6037 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6038 if (!peer)
6039 return CMD_WARNING_CONFIG_FAILED;
718e3744 6040
d62a17ae 6041 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6042 bgp_node_safi(vty));
718e3744 6043
d62a17ae 6044 return bgp_vty_return(vty, ret);
718e3744 6045}
6b0655a2 6046
d62a17ae 6047ALIAS_HIDDEN(
6048 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6049 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6050 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6051 "allow local ASN appears in aspath attribute\n"
6052 "Number of occurances of AS number\n"
6053 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6054
fa411a21
NH
6055DEFUN (neighbor_ttl_security,
6056 neighbor_ttl_security_cmd,
7ebe625c 6057 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6058 NEIGHBOR_STR
7ebe625c 6059 NEIGHBOR_ADDR_STR2
16cedbb0 6060 "BGP ttl-security parameters\n"
d7fa34c1
QY
6061 "Specify the maximum number of hops to the BGP peer\n"
6062 "Number of hops to BGP peer\n")
fa411a21 6063{
d62a17ae 6064 int idx_peer = 1;
6065 int idx_number = 4;
6066 struct peer *peer;
6067 int gtsm_hops;
6068
6069 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6070 if (!peer)
6071 return CMD_WARNING_CONFIG_FAILED;
6072
6073 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6074
7ebe625c
QY
6075 /*
6076 * If 'neighbor swpX', then this is for directly connected peers,
6077 * we should not accept a ttl-security hops value greater than 1.
6078 */
6079 if (peer->conf_if && (gtsm_hops > 1)) {
6080 vty_out(vty,
6081 "%s is directly connected peer, hops cannot exceed 1\n",
6082 argv[idx_peer]->arg);
6083 return CMD_WARNING_CONFIG_FAILED;
6084 }
6085
d62a17ae 6086 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6087}
6088
6089DEFUN (no_neighbor_ttl_security,
6090 no_neighbor_ttl_security_cmd,
7ebe625c 6091 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6092 NO_STR
6093 NEIGHBOR_STR
7ebe625c 6094 NEIGHBOR_ADDR_STR2
16cedbb0 6095 "BGP ttl-security parameters\n"
3a2d747c
QY
6096 "Specify the maximum number of hops to the BGP peer\n"
6097 "Number of hops to BGP peer\n")
fa411a21 6098{
d62a17ae 6099 int idx_peer = 2;
6100 struct peer *peer;
fa411a21 6101
d62a17ae 6102 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6103 if (!peer)
6104 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6105
d62a17ae 6106 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6107}
6b0655a2 6108
adbac85e
DW
6109DEFUN (neighbor_addpath_tx_all_paths,
6110 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6111 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6112 NEIGHBOR_STR
6113 NEIGHBOR_ADDR_STR2
6114 "Use addpath to advertise all paths to a neighbor\n")
6115{
d62a17ae 6116 int idx_peer = 1;
6117 struct peer *peer;
adbac85e 6118
d62a17ae 6119 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6120 if (!peer)
6121 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6122
d62a17ae 6123 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6124 bgp_node_safi(vty),
6125 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6126}
6127
d62a17ae 6128ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6129 neighbor_addpath_tx_all_paths_hidden_cmd,
6130 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6131 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6132 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6133
adbac85e
DW
6134DEFUN (no_neighbor_addpath_tx_all_paths,
6135 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6136 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6137 NO_STR
6138 NEIGHBOR_STR
6139 NEIGHBOR_ADDR_STR2
6140 "Use addpath to advertise all paths to a neighbor\n")
6141{
d62a17ae 6142 int idx_peer = 2;
6143 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6144 bgp_node_afi(vty), bgp_node_safi(vty),
6145 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6146}
6147
d62a17ae 6148ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6149 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6150 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6152 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6153
06370dac
DW
6154DEFUN (neighbor_addpath_tx_bestpath_per_as,
6155 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6156 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6157 NEIGHBOR_STR
6158 NEIGHBOR_ADDR_STR2
6159 "Use addpath to advertise the bestpath per each neighboring AS\n")
6160{
d62a17ae 6161 int idx_peer = 1;
6162 struct peer *peer;
06370dac 6163
d62a17ae 6164 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6165 if (!peer)
6166 return CMD_WARNING_CONFIG_FAILED;
06370dac 6167
d62a17ae 6168 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6169 bgp_node_safi(vty),
6170 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6171}
6172
d62a17ae 6173ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6174 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6175 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6176 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6177 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6178
06370dac
DW
6179DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6180 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6181 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6182 NO_STR
6183 NEIGHBOR_STR
6184 NEIGHBOR_ADDR_STR2
6185 "Use addpath to advertise the bestpath per each neighboring AS\n")
6186{
d62a17ae 6187 int idx_peer = 2;
6188 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6189 bgp_node_afi(vty), bgp_node_safi(vty),
6190 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6191}
6192
d62a17ae 6193ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6194 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6195 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6196 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6197 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6198
b9c7bc5a
PZ
6199static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6200 struct ecommunity **list)
ddb5b488 6201{
b9c7bc5a
PZ
6202 struct ecommunity *ecom = NULL;
6203 struct ecommunity *ecomadd;
ddb5b488 6204
b9c7bc5a 6205 for (; argc; --argc, ++argv) {
ddb5b488 6206
b9c7bc5a
PZ
6207 ecomadd = ecommunity_str2com(argv[0]->arg,
6208 ECOMMUNITY_ROUTE_TARGET, 0);
6209 if (!ecomadd) {
6210 vty_out(vty, "Malformed community-list value\n");
6211 if (ecom)
6212 ecommunity_free(&ecom);
6213 return CMD_WARNING_CONFIG_FAILED;
6214 }
ddb5b488 6215
b9c7bc5a
PZ
6216 if (ecom) {
6217 ecommunity_merge(ecom, ecomadd);
6218 ecommunity_free(&ecomadd);
6219 } else {
6220 ecom = ecomadd;
6221 }
6222 }
6223
6224 if (*list) {
6225 ecommunity_free(&*list);
ddb5b488 6226 }
b9c7bc5a
PZ
6227 *list = ecom;
6228
6229 return CMD_SUCCESS;
ddb5b488
PZ
6230}
6231
0ca70ba5
DS
6232/*
6233 * v2vimport is true if we are handling a `import vrf ...` command
6234 */
6235static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6236{
0ca70ba5
DS
6237 afi_t afi;
6238
ddb5b488 6239 switch (vty->node) {
b9c7bc5a 6240 case BGP_IPV4_NODE:
0ca70ba5
DS
6241 afi = AFI_IP;
6242 break;
b9c7bc5a 6243 case BGP_IPV6_NODE:
0ca70ba5
DS
6244 afi = AFI_IP6;
6245 break;
ddb5b488
PZ
6246 default:
6247 vty_out(vty,
b9c7bc5a 6248 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6249 return AFI_MAX;
ddb5b488 6250 }
69b07479 6251
0ca70ba5
DS
6252 if (!v2vimport) {
6253 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6254 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6255 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6256 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6257 vty_out(vty,
6258 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6259 return AFI_MAX;
6260 }
6261 } else {
6262 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6263 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6264 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6265 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6266 vty_out(vty,
6267 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6268 return AFI_MAX;
6269 }
6270 }
6271 return afi;
ddb5b488
PZ
6272}
6273
b9c7bc5a
PZ
6274DEFPY (af_rd_vpn_export,
6275 af_rd_vpn_export_cmd,
6276 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6277 NO_STR
ddb5b488 6278 "Specify route distinguisher\n"
b9c7bc5a
PZ
6279 "Between current address-family and vpn\n"
6280 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6281 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6282{
6283 VTY_DECLVAR_CONTEXT(bgp, bgp);
6284 struct prefix_rd prd;
6285 int ret;
ddb5b488 6286 afi_t afi;
b9c7bc5a
PZ
6287 int idx = 0;
6288 int yes = 1;
ddb5b488 6289
b9c7bc5a 6290 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6291 yes = 0;
b9c7bc5a
PZ
6292
6293 if (yes) {
6294 ret = str2prefix_rd(rd_str, &prd);
6295 if (!ret) {
6296 vty_out(vty, "%% Malformed rd\n");
6297 return CMD_WARNING_CONFIG_FAILED;
6298 }
ddb5b488
PZ
6299 }
6300
0ca70ba5 6301 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6302 if (afi == AFI_MAX)
6303 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6304
69b07479
DS
6305 /*
6306 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6307 */
6308 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6309 bgp_get_default(), bgp);
ddb5b488 6310
69b07479
DS
6311 if (yes) {
6312 bgp->vpn_policy[afi].tovpn_rd = prd;
6313 SET_FLAG(bgp->vpn_policy[afi].flags,
6314 BGP_VPN_POLICY_TOVPN_RD_SET);
6315 } else {
6316 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6317 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6318 }
6319
69b07479
DS
6320 /* post-change: re-export vpn routes */
6321 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6322 bgp_get_default(), bgp);
6323
ddb5b488
PZ
6324 return CMD_SUCCESS;
6325}
6326
b9c7bc5a
PZ
6327ALIAS (af_rd_vpn_export,
6328 af_no_rd_vpn_export_cmd,
6329 "no rd vpn export",
ddb5b488 6330 NO_STR
b9c7bc5a
PZ
6331 "Specify route distinguisher\n"
6332 "Between current address-family and vpn\n"
6333 "For routes leaked from current address-family to vpn\n")
ddb5b488 6334
b9c7bc5a
PZ
6335DEFPY (af_label_vpn_export,
6336 af_label_vpn_export_cmd,
e70e9f8e 6337 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6338 NO_STR
ddb5b488 6339 "label value for VRF\n"
b9c7bc5a
PZ
6340 "Between current address-family and vpn\n"
6341 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6342 "Label Value <0-1048575>\n"
6343 "Automatically assign a label\n")
ddb5b488
PZ
6344{
6345 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6346 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6347 afi_t afi;
b9c7bc5a
PZ
6348 int idx = 0;
6349 int yes = 1;
6350
6351 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6352 yes = 0;
ddb5b488 6353
21a16cc2
PZ
6354 /* If "no ...", squash trailing parameter */
6355 if (!yes)
6356 label_auto = NULL;
6357
e70e9f8e
PZ
6358 if (yes) {
6359 if (!label_auto)
6360 label = label_val; /* parser should force unsigned */
6361 }
ddb5b488 6362
0ca70ba5 6363 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6364 if (afi == AFI_MAX)
6365 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6366
e70e9f8e 6367
69b07479
DS
6368 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6369 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6370 /* no change */
6371 return CMD_SUCCESS;
e70e9f8e 6372
69b07479
DS
6373 /*
6374 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6375 */
6376 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6377 bgp_get_default(), bgp);
6378
6379 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6380 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6381
6382 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6383
6384 /*
6385 * label has previously been automatically
6386 * assigned by labelpool: release it
6387 *
6388 * NB if tovpn_label == MPLS_LABEL_NONE it
6389 * means the automatic assignment is in flight
6390 * and therefore the labelpool callback must
6391 * detect that the auto label is not needed.
6392 */
6393
6394 bgp_lp_release(LP_TYPE_VRF,
6395 &bgp->vpn_policy[afi],
6396 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6397 }
69b07479
DS
6398 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6399 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6400 }
ddb5b488 6401
69b07479
DS
6402 bgp->vpn_policy[afi].tovpn_label = label;
6403 if (label_auto) {
6404 SET_FLAG(bgp->vpn_policy[afi].flags,
6405 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6406 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6407 vpn_leak_label_callback);
ddb5b488
PZ
6408 }
6409
69b07479
DS
6410 /* post-change: re-export vpn routes */
6411 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6412 bgp_get_default(), bgp);
6413
ddb5b488
PZ
6414 return CMD_SUCCESS;
6415}
6416
b9c7bc5a
PZ
6417ALIAS (af_label_vpn_export,
6418 af_no_label_vpn_export_cmd,
6419 "no label vpn export",
6420 NO_STR
6421 "label value for VRF\n"
6422 "Between current address-family and vpn\n"
6423 "For routes leaked from current address-family to vpn\n")
ddb5b488 6424
b9c7bc5a
PZ
6425DEFPY (af_nexthop_vpn_export,
6426 af_nexthop_vpn_export_cmd,
6427 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6428 NO_STR
ddb5b488 6429 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6430 "Between current address-family and vpn\n"
6431 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6432 "IPv4 prefix\n"
6433 "IPv6 prefix\n")
6434{
6435 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6436 afi_t afi;
ddb5b488 6437 struct prefix p;
b9c7bc5a
PZ
6438 int idx = 0;
6439 int yes = 1;
ddb5b488 6440
b9c7bc5a 6441 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6442 yes = 0;
b9c7bc5a
PZ
6443
6444 if (yes) {
6445 if (!sockunion2hostprefix(nexthop_str, &p))
6446 return CMD_WARNING_CONFIG_FAILED;
6447 }
ddb5b488 6448
0ca70ba5 6449 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6450 if (afi == AFI_MAX)
6451 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6452
69b07479
DS
6453 /*
6454 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6455 */
6456 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6457 bgp_get_default(), bgp);
ddb5b488 6458
69b07479
DS
6459 if (yes) {
6460 bgp->vpn_policy[afi].tovpn_nexthop = p;
6461 SET_FLAG(bgp->vpn_policy[afi].flags,
6462 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6463 } else {
6464 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6465 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6466 }
6467
69b07479
DS
6468 /* post-change: re-export vpn routes */
6469 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6470 bgp_get_default(), bgp);
6471
ddb5b488
PZ
6472 return CMD_SUCCESS;
6473}
6474
b9c7bc5a
PZ
6475ALIAS (af_nexthop_vpn_export,
6476 af_no_nexthop_vpn_export_cmd,
6477 "no nexthop vpn export",
ddb5b488 6478 NO_STR
b9c7bc5a
PZ
6479 "Specify next hop to use for VRF advertised prefixes\n"
6480 "Between current address-family and vpn\n"
6481 "For routes leaked from current address-family to vpn\n")
ddb5b488 6482
b9c7bc5a 6483static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6484{
b9c7bc5a
PZ
6485 if (!strcmp(dstr, "import")) {
6486 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6487 } else if (!strcmp(dstr, "export")) {
6488 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6489 } else if (!strcmp(dstr, "both")) {
6490 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6491 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6492 } else {
6493 vty_out(vty, "%% direction parse error\n");
6494 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6495 }
ddb5b488
PZ
6496 return CMD_SUCCESS;
6497}
6498
b9c7bc5a
PZ
6499DEFPY (af_rt_vpn_imexport,
6500 af_rt_vpn_imexport_cmd,
6501 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6502 NO_STR
6503 "Specify route target list\n"
ddb5b488 6504 "Specify route target list\n"
b9c7bc5a
PZ
6505 "Between current address-family and vpn\n"
6506 "For routes leaked from vpn to current address-family: match any\n"
6507 "For routes leaked from current address-family to vpn: set\n"
6508 "both import: match any and export: set\n"
ddb5b488
PZ
6509 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6510{
6511 VTY_DECLVAR_CONTEXT(bgp, bgp);
6512 int ret;
6513 struct ecommunity *ecom = NULL;
6514 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6515 vpn_policy_direction_t dir;
6516 afi_t afi;
6517 int idx = 0;
b9c7bc5a 6518 int yes = 1;
ddb5b488 6519
b9c7bc5a 6520 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6521 yes = 0;
b9c7bc5a 6522
0ca70ba5 6523 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6524 if (afi == AFI_MAX)
6525 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6526
b9c7bc5a 6527 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6528 if (ret != CMD_SUCCESS)
6529 return ret;
6530
b9c7bc5a
PZ
6531 if (yes) {
6532 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6533 vty_out(vty, "%% Missing RTLIST\n");
6534 return CMD_WARNING_CONFIG_FAILED;
6535 }
6536 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6537 if (ret != CMD_SUCCESS) {
6538 return ret;
6539 }
ddb5b488
PZ
6540 }
6541
69b07479
DS
6542 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6543 if (!dodir[dir])
ddb5b488 6544 continue;
ddb5b488 6545
69b07479 6546 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6547
69b07479
DS
6548 if (yes) {
6549 if (bgp->vpn_policy[afi].rtlist[dir])
6550 ecommunity_free(
6551 &bgp->vpn_policy[afi].rtlist[dir]);
6552 bgp->vpn_policy[afi].rtlist[dir] =
6553 ecommunity_dup(ecom);
6554 } else {
6555 if (bgp->vpn_policy[afi].rtlist[dir])
6556 ecommunity_free(
6557 &bgp->vpn_policy[afi].rtlist[dir]);
6558 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6559 }
69b07479
DS
6560
6561 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6562 }
69b07479 6563
d555f3e9
PZ
6564 if (ecom)
6565 ecommunity_free(&ecom);
ddb5b488
PZ
6566
6567 return CMD_SUCCESS;
6568}
6569
b9c7bc5a
PZ
6570ALIAS (af_rt_vpn_imexport,
6571 af_no_rt_vpn_imexport_cmd,
6572 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6573 NO_STR
6574 "Specify route target list\n"
b9c7bc5a
PZ
6575 "Specify route target list\n"
6576 "Between current address-family and vpn\n"
6577 "For routes leaked from vpn to current address-family\n"
6578 "For routes leaked from current address-family to vpn\n"
6579 "both import and export\n")
6580
6581DEFPY (af_route_map_vpn_imexport,
6582 af_route_map_vpn_imexport_cmd,
6583/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6584 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6585 NO_STR
ddb5b488 6586 "Specify route map\n"
b9c7bc5a
PZ
6587 "Between current address-family and vpn\n"
6588 "For routes leaked from vpn to current address-family\n"
6589 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6590 "name of route-map\n")
6591{
6592 VTY_DECLVAR_CONTEXT(bgp, bgp);
6593 int ret;
6594 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6595 vpn_policy_direction_t dir;
6596 afi_t afi;
ddb5b488 6597 int idx = 0;
b9c7bc5a 6598 int yes = 1;
ddb5b488 6599
b9c7bc5a 6600 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6601 yes = 0;
b9c7bc5a 6602
0ca70ba5 6603 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6604 if (afi == AFI_MAX)
6605 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6606
b9c7bc5a 6607 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6608 if (ret != CMD_SUCCESS)
6609 return ret;
6610
69b07479
DS
6611 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6612 if (!dodir[dir])
ddb5b488 6613 continue;
ddb5b488 6614
69b07479 6615 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6616
69b07479
DS
6617 if (yes) {
6618 if (bgp->vpn_policy[afi].rmap_name[dir])
6619 XFREE(MTYPE_ROUTE_MAP_NAME,
6620 bgp->vpn_policy[afi].rmap_name[dir]);
6621 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6622 MTYPE_ROUTE_MAP_NAME, rmap_str);
6623 bgp->vpn_policy[afi].rmap[dir] =
6624 route_map_lookup_by_name(rmap_str);
6625 if (!bgp->vpn_policy[afi].rmap[dir])
6626 return CMD_SUCCESS;
6627 } else {
6628 if (bgp->vpn_policy[afi].rmap_name[dir])
6629 XFREE(MTYPE_ROUTE_MAP_NAME,
6630 bgp->vpn_policy[afi].rmap_name[dir]);
6631 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6632 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6633 }
69b07479
DS
6634
6635 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6636 }
6637
6638 return CMD_SUCCESS;
6639}
6640
b9c7bc5a
PZ
6641ALIAS (af_route_map_vpn_imexport,
6642 af_no_route_map_vpn_imexport_cmd,
6643 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6644 NO_STR
6645 "Specify route map\n"
b9c7bc5a
PZ
6646 "Between current address-family and vpn\n"
6647 "For routes leaked from vpn to current address-family\n"
6648 "For routes leaked from current address-family to vpn\n")
6649
bb4f6190
DS
6650DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6651 "[no] import vrf route-map RMAP$rmap_str",
6652 NO_STR
6653 "Import routes from another VRF\n"
6654 "Vrf routes being filtered\n"
6655 "Specify route map\n"
6656 "name of route-map\n")
6657{
6658 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6659 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6660 afi_t afi;
6661 int idx = 0;
6662 int yes = 1;
6663 struct bgp *bgp_default;
6664
6665 if (argv_find(argv, argc, "no", &idx))
6666 yes = 0;
6667
0ca70ba5 6668 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6669 if (afi == AFI_MAX)
6670 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6671
6672 bgp_default = bgp_get_default();
6673 if (!bgp_default) {
6674 int32_t ret;
6675 as_t as = bgp->as;
6676
6677 /* Auto-create assuming the same AS */
6678 ret = bgp_get(&bgp_default, &as, NULL,
6679 BGP_INSTANCE_TYPE_DEFAULT);
6680
6681 if (ret) {
6682 vty_out(vty,
6683 "VRF default is not configured as a bgp instance\n");
6684 return CMD_WARNING;
6685 }
6686 }
6687
69b07479 6688 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6689
69b07479
DS
6690 if (yes) {
6691 if (bgp->vpn_policy[afi].rmap_name[dir])
6692 XFREE(MTYPE_ROUTE_MAP_NAME,
6693 bgp->vpn_policy[afi].rmap_name[dir]);
6694 bgp->vpn_policy[afi].rmap_name[dir] =
6695 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6696 bgp->vpn_policy[afi].rmap[dir] =
6697 route_map_lookup_by_name(rmap_str);
6698 if (!bgp->vpn_policy[afi].rmap[dir])
6699 return CMD_SUCCESS;
6700 } else {
6701 if (bgp->vpn_policy[afi].rmap_name[dir])
6702 XFREE(MTYPE_ROUTE_MAP_NAME,
6703 bgp->vpn_policy[afi].rmap_name[dir]);
6704 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6705 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6706 }
6707
69b07479
DS
6708 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6709
bb4f6190
DS
6710 return CMD_SUCCESS;
6711}
6712
6713ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6714 "no import vrf route-map",
6715 NO_STR
6716 "Import routes from another VRF\n"
6717 "Vrf routes being filtered\n"
6718 "Specify route map\n")
6719
12a844a5
DS
6720DEFPY (bgp_imexport_vrf,
6721 bgp_imexport_vrf_cmd,
6722 "[no] import vrf NAME$import_name",
6723 NO_STR
6724 "Import routes from another VRF\n"
6725 "VRF to import from\n"
6726 "The name of the VRF\n")
6727{
6728 VTY_DECLVAR_CONTEXT(bgp, bgp);
6729 struct listnode *node;
79ef8664
DS
6730 struct bgp *vrf_bgp, *bgp_default;
6731 int32_t ret = 0;
6732 as_t as = bgp->as;
12a844a5
DS
6733 bool remove = false;
6734 int32_t idx = 0;
6735 char *vname;
a8dadcf6 6736 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6737 safi_t safi;
6738 afi_t afi;
6739
867f0cca 6740 if (import_name == NULL) {
6741 vty_out(vty, "%% Missing import name\n");
6742 return CMD_WARNING;
6743 }
6744
12a844a5
DS
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);
b90a8e13 9194 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9195 json_object_int_add(json_neigh,
9196 "bgpTimerConfiguredHoldTimeMsecs",
9197 p->holdtime * 1000);
9198 json_object_int_add(
9199 json_neigh,
9200 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9201 p->keepalive * 1000);
d25e4efc 9202 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9203 || (bgp->default_keepalive
9204 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9205 json_object_int_add(json_neigh,
9206 "bgpTimerConfiguredHoldTimeMsecs",
9207 bgp->default_holdtime);
9208 json_object_int_add(
9209 json_neigh,
9210 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9211 bgp->default_keepalive);
d62a17ae 9212 }
9213 } else {
9214 /* Administrative shutdown. */
9215 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9216 vty_out(vty, " Administratively shut down\n");
9217
9218 /* BGP Version. */
9219 vty_out(vty, " BGP version 4");
9220 vty_out(vty, ", remote router ID %s\n",
9221 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9222
9223 /* Confederation */
9224 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9225 && bgp_confederation_peers_check(bgp, p->as))
9226 vty_out(vty,
9227 " Neighbor under common administration\n");
9228
9229 /* Status. */
9230 vty_out(vty, " BGP state = %s",
9231 lookup_msg(bgp_status_msg, p->status, NULL));
9232
9233 if (p->status == Established)
9234 vty_out(vty, ", up for %8s",
9235 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9236 0, NULL));
9237
9238 else if (p->status == Active) {
9239 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9240 vty_out(vty, " (passive)");
9241 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9242 vty_out(vty, " (NSF passive)");
9243 }
9244 vty_out(vty, "\n");
9245
9246 /* read timer */
9247 vty_out(vty, " Last read %s",
9248 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9249 NULL));
9250 vty_out(vty, ", Last write %s\n",
9251 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9252 NULL));
9253
9254 /* Configured timer values. */
9255 vty_out(vty,
9256 " Hold time is %d, keepalive interval is %d seconds\n",
9257 p->v_holdtime, p->v_keepalive);
b90a8e13 9258 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9259 vty_out(vty, " Configured hold time is %d",
9260 p->holdtime);
9261 vty_out(vty, ", keepalive interval is %d seconds\n",
9262 p->keepalive);
d25e4efc 9263 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9264 || (bgp->default_keepalive
9265 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9266 vty_out(vty, " Configured hold time is %d",
9267 bgp->default_holdtime);
9268 vty_out(vty, ", keepalive interval is %d seconds\n",
9269 bgp->default_keepalive);
d62a17ae 9270 }
9271 }
9272 /* Capability. */
9273 if (p->status == Established) {
9274 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9275 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9276 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9277 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9278 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9279 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9280 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9281 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9282 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9283 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9284 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9285 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9286 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9287 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9288 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9289 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9290 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9291 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9292 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9293 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9294 if (use_json) {
9295 json_object *json_cap = NULL;
9296
9297 json_cap = json_object_new_object();
9298
9299 /* AS4 */
9300 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9301 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9302 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9303 && CHECK_FLAG(p->cap,
9304 PEER_CAP_AS4_RCV))
9305 json_object_string_add(
9306 json_cap, "4byteAs",
9307 "advertisedAndReceived");
9308 else if (CHECK_FLAG(p->cap,
9309 PEER_CAP_AS4_ADV))
9310 json_object_string_add(
9311 json_cap, "4byteAs",
9312 "advertised");
9313 else if (CHECK_FLAG(p->cap,
9314 PEER_CAP_AS4_RCV))
9315 json_object_string_add(
9316 json_cap, "4byteAs",
9317 "received");
9318 }
9319
9320 /* AddPath */
9321 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9322 || CHECK_FLAG(p->cap,
9323 PEER_CAP_ADDPATH_ADV)) {
9324 json_object *json_add = NULL;
9325 const char *print_store;
9326
9327 json_add = json_object_new_object();
9328
05c7a1cc
QY
9329 FOREACH_AFI_SAFI (afi, safi) {
9330 json_object *json_sub = NULL;
9331 json_sub =
9332 json_object_new_object();
9333 print_store = afi_safi_print(
9334 afi, safi);
d62a17ae 9335
05c7a1cc
QY
9336 if (CHECK_FLAG(
9337 p->af_cap[afi]
9338 [safi],
9339 PEER_CAP_ADDPATH_AF_TX_ADV)
9340 || CHECK_FLAG(
9341 p->af_cap[afi]
9342 [safi],
9343 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9344 if (CHECK_FLAG(
9345 p->af_cap
9346 [afi]
9347 [safi],
9348 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9349 && CHECK_FLAG(
d62a17ae 9350 p->af_cap
9351 [afi]
9352 [safi],
05c7a1cc
QY
9353 PEER_CAP_ADDPATH_AF_TX_RCV))
9354 json_object_boolean_true_add(
9355 json_sub,
9356 "txAdvertisedAndReceived");
9357 else if (
9358 CHECK_FLAG(
9359 p->af_cap
9360 [afi]
9361 [safi],
9362 PEER_CAP_ADDPATH_AF_TX_ADV))
9363 json_object_boolean_true_add(
9364 json_sub,
9365 "txAdvertised");
9366 else if (
9367 CHECK_FLAG(
9368 p->af_cap
9369 [afi]
9370 [safi],
9371 PEER_CAP_ADDPATH_AF_TX_RCV))
9372 json_object_boolean_true_add(
9373 json_sub,
9374 "txReceived");
9375 }
d62a17ae 9376
05c7a1cc
QY
9377 if (CHECK_FLAG(
9378 p->af_cap[afi]
9379 [safi],
9380 PEER_CAP_ADDPATH_AF_RX_ADV)
9381 || CHECK_FLAG(
9382 p->af_cap[afi]
9383 [safi],
9384 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9385 if (CHECK_FLAG(
9386 p->af_cap
9387 [afi]
9388 [safi],
9389 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9390 && CHECK_FLAG(
d62a17ae 9391 p->af_cap
9392 [afi]
9393 [safi],
9394 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9395 json_object_boolean_true_add(
9396 json_sub,
9397 "rxAdvertisedAndReceived");
9398 else if (
9399 CHECK_FLAG(
9400 p->af_cap
9401 [afi]
9402 [safi],
9403 PEER_CAP_ADDPATH_AF_RX_ADV))
9404 json_object_boolean_true_add(
9405 json_sub,
9406 "rxAdvertised");
9407 else if (
9408 CHECK_FLAG(
9409 p->af_cap
9410 [afi]
9411 [safi],
9412 PEER_CAP_ADDPATH_AF_RX_RCV))
9413 json_object_boolean_true_add(
9414 json_sub,
9415 "rxReceived");
d62a17ae 9416 }
9417
05c7a1cc
QY
9418 if (CHECK_FLAG(
9419 p->af_cap[afi]
9420 [safi],
9421 PEER_CAP_ADDPATH_AF_TX_ADV)
9422 || CHECK_FLAG(
9423 p->af_cap[afi]
9424 [safi],
9425 PEER_CAP_ADDPATH_AF_TX_RCV)
9426 || CHECK_FLAG(
9427 p->af_cap[afi]
9428 [safi],
9429 PEER_CAP_ADDPATH_AF_RX_ADV)
9430 || CHECK_FLAG(
9431 p->af_cap[afi]
9432 [safi],
9433 PEER_CAP_ADDPATH_AF_RX_RCV))
9434 json_object_object_add(
9435 json_add,
9436 print_store,
9437 json_sub);
9438 else
9439 json_object_free(
9440 json_sub);
9441 }
9442
d62a17ae 9443 json_object_object_add(
9444 json_cap, "addPath", json_add);
9445 }
9446
9447 /* Dynamic */
9448 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9449 || CHECK_FLAG(p->cap,
9450 PEER_CAP_DYNAMIC_ADV)) {
9451 if (CHECK_FLAG(p->cap,
9452 PEER_CAP_DYNAMIC_ADV)
9453 && CHECK_FLAG(p->cap,
9454 PEER_CAP_DYNAMIC_RCV))
9455 json_object_string_add(
9456 json_cap, "dynamic",
9457 "advertisedAndReceived");
9458 else if (CHECK_FLAG(
9459 p->cap,
9460 PEER_CAP_DYNAMIC_ADV))
9461 json_object_string_add(
9462 json_cap, "dynamic",
9463 "advertised");
9464 else if (CHECK_FLAG(
9465 p->cap,
9466 PEER_CAP_DYNAMIC_RCV))
9467 json_object_string_add(
9468 json_cap, "dynamic",
9469 "received");
9470 }
9471
9472 /* Extended nexthop */
9473 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9474 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9475 json_object *json_nxt = NULL;
9476 const char *print_store;
9477
9478
9479 if (CHECK_FLAG(p->cap,
9480 PEER_CAP_ENHE_ADV)
9481 && CHECK_FLAG(p->cap,
9482 PEER_CAP_ENHE_RCV))
9483 json_object_string_add(
9484 json_cap,
9485 "extendedNexthop",
9486 "advertisedAndReceived");
9487 else if (CHECK_FLAG(p->cap,
9488 PEER_CAP_ENHE_ADV))
9489 json_object_string_add(
9490 json_cap,
9491 "extendedNexthop",
9492 "advertised");
9493 else if (CHECK_FLAG(p->cap,
9494 PEER_CAP_ENHE_RCV))
9495 json_object_string_add(
9496 json_cap,
9497 "extendedNexthop",
9498 "received");
9499
9500 if (CHECK_FLAG(p->cap,
9501 PEER_CAP_ENHE_RCV)) {
9502 json_nxt =
9503 json_object_new_object();
9504
9505 for (safi = SAFI_UNICAST;
9506 safi < SAFI_MAX; safi++) {
9507 if (CHECK_FLAG(
9508 p->af_cap
9509 [AFI_IP]
9510 [safi],
9511 PEER_CAP_ENHE_AF_RCV)) {
9512 print_store = afi_safi_print(
9513 AFI_IP,
9514 safi);
9515 json_object_string_add(
9516 json_nxt,
9517 print_store,
9518 "recieved");
9519 }
9520 }
9521 json_object_object_add(
9522 json_cap,
9523 "extendedNexthopFamililesByPeer",
9524 json_nxt);
9525 }
9526 }
9527
9528 /* Route Refresh */
9529 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9530 || CHECK_FLAG(p->cap,
9531 PEER_CAP_REFRESH_NEW_RCV)
9532 || CHECK_FLAG(p->cap,
9533 PEER_CAP_REFRESH_OLD_RCV)) {
9534 if (CHECK_FLAG(p->cap,
9535 PEER_CAP_REFRESH_ADV)
9536 && (CHECK_FLAG(
9537 p->cap,
9538 PEER_CAP_REFRESH_NEW_RCV)
9539 || CHECK_FLAG(
9540 p->cap,
9541 PEER_CAP_REFRESH_OLD_RCV))) {
9542 if (CHECK_FLAG(
9543 p->cap,
9544 PEER_CAP_REFRESH_OLD_RCV)
9545 && CHECK_FLAG(
9546 p->cap,
9547 PEER_CAP_REFRESH_NEW_RCV))
9548 json_object_string_add(
9549 json_cap,
9550 "routeRefresh",
9551 "advertisedAndReceivedOldNew");
9552 else {
9553 if (CHECK_FLAG(
9554 p->cap,
9555 PEER_CAP_REFRESH_OLD_RCV))
9556 json_object_string_add(
9557 json_cap,
9558 "routeRefresh",
9559 "advertisedAndReceivedOld");
9560 else
9561 json_object_string_add(
9562 json_cap,
9563 "routeRefresh",
9564 "advertisedAndReceivedNew");
9565 }
9566 } else if (
9567 CHECK_FLAG(
9568 p->cap,
9569 PEER_CAP_REFRESH_ADV))
9570 json_object_string_add(
9571 json_cap,
9572 "routeRefresh",
9573 "advertised");
9574 else if (
9575 CHECK_FLAG(
9576 p->cap,
9577 PEER_CAP_REFRESH_NEW_RCV)
9578 || CHECK_FLAG(
9579 p->cap,
9580 PEER_CAP_REFRESH_OLD_RCV))
9581 json_object_string_add(
9582 json_cap,
9583 "routeRefresh",
9584 "received");
9585 }
9586
9587 /* Multiprotocol Extensions */
9588 json_object *json_multi = NULL;
9589 json_multi = json_object_new_object();
9590
05c7a1cc
QY
9591 FOREACH_AFI_SAFI (afi, safi) {
9592 if (p->afc_adv[afi][safi]
9593 || p->afc_recv[afi][safi]) {
9594 json_object *json_exten = NULL;
9595 json_exten =
9596 json_object_new_object();
9597
d62a17ae 9598 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9599 && p->afc_recv[afi][safi])
9600 json_object_boolean_true_add(
9601 json_exten,
9602 "advertisedAndReceived");
9603 else if (p->afc_adv[afi][safi])
9604 json_object_boolean_true_add(
9605 json_exten,
9606 "advertised");
9607 else if (p->afc_recv[afi][safi])
9608 json_object_boolean_true_add(
9609 json_exten,
9610 "received");
d62a17ae 9611
05c7a1cc
QY
9612 json_object_object_add(
9613 json_multi,
9614 afi_safi_print(afi,
9615 safi),
9616 json_exten);
d62a17ae 9617 }
9618 }
9619 json_object_object_add(
9620 json_cap, "multiprotocolExtensions",
9621 json_multi);
9622
d77114b7 9623 /* Hostname capabilities */
60466a63 9624 json_object *json_hname = NULL;
d77114b7
MK
9625
9626 json_hname = json_object_new_object();
9627
9628 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9629 json_object_string_add(
60466a63
QY
9630 json_hname, "advHostName",
9631 bgp->peer_self->hostname
9632 ? bgp->peer_self
9633 ->hostname
d77114b7
MK
9634 : "n/a");
9635 json_object_string_add(
60466a63
QY
9636 json_hname, "advDomainName",
9637 bgp->peer_self->domainname
9638 ? bgp->peer_self
9639 ->domainname
d77114b7
MK
9640 : "n/a");
9641 }
9642
9643
9644 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9645 json_object_string_add(
60466a63
QY
9646 json_hname, "rcvHostName",
9647 p->hostname ? p->hostname
9648 : "n/a");
d77114b7 9649 json_object_string_add(
60466a63
QY
9650 json_hname, "rcvDomainName",
9651 p->domainname ? p->domainname
9652 : "n/a");
d77114b7
MK
9653 }
9654
60466a63 9655 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9656 json_hname);
9657
d62a17ae 9658 /* Gracefull Restart */
9659 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9660 || CHECK_FLAG(p->cap,
9661 PEER_CAP_RESTART_ADV)) {
9662 if (CHECK_FLAG(p->cap,
9663 PEER_CAP_RESTART_ADV)
9664 && CHECK_FLAG(p->cap,
9665 PEER_CAP_RESTART_RCV))
9666 json_object_string_add(
9667 json_cap,
9668 "gracefulRestart",
9669 "advertisedAndReceived");
9670 else if (CHECK_FLAG(
9671 p->cap,
9672 PEER_CAP_RESTART_ADV))
9673 json_object_string_add(
9674 json_cap,
9675 "gracefulRestartCapability",
9676 "advertised");
9677 else if (CHECK_FLAG(
9678 p->cap,
9679 PEER_CAP_RESTART_RCV))
9680 json_object_string_add(
9681 json_cap,
9682 "gracefulRestartCapability",
9683 "received");
9684
9685 if (CHECK_FLAG(p->cap,
9686 PEER_CAP_RESTART_RCV)) {
9687 int restart_af_count = 0;
9688 json_object *json_restart =
9689 NULL;
9690 json_restart =
9691 json_object_new_object();
9692
9693 json_object_int_add(
9694 json_cap,
9695 "gracefulRestartRemoteTimerMsecs",
9696 p->v_gr_restart * 1000);
9697
05c7a1cc
QY
9698 FOREACH_AFI_SAFI (afi, safi) {
9699 if (CHECK_FLAG(
9700 p->af_cap
9701 [afi]
9702 [safi],
9703 PEER_CAP_RESTART_AF_RCV)) {
9704 json_object *
9705 json_sub =
9706 NULL;
9707 json_sub =
9708 json_object_new_object();
9709
d62a17ae 9710 if (CHECK_FLAG(
9711 p->af_cap
9712 [afi]
9713 [safi],
05c7a1cc
QY
9714 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9715 json_object_boolean_true_add(
9716 json_sub,
9717 "preserved");
9718 restart_af_count++;
9719 json_object_object_add(
9720 json_restart,
9721 afi_safi_print(
9722 afi,
9723 safi),
9724 json_sub);
d62a17ae 9725 }
9726 }
9727 if (!restart_af_count) {
9728 json_object_string_add(
9729 json_cap,
9730 "addressFamiliesByPeer",
9731 "none");
9732 json_object_free(
9733 json_restart);
9734 } else
9735 json_object_object_add(
9736 json_cap,
9737 "addressFamiliesByPeer",
9738 json_restart);
9739 }
9740 }
9741 json_object_object_add(json_neigh,
9742 "neighborCapabilities",
9743 json_cap);
9744 } else {
9745 vty_out(vty, " Neighbor capabilities:\n");
9746
9747 /* AS4 */
9748 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9749 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9750 vty_out(vty, " 4 Byte AS:");
9751 if (CHECK_FLAG(p->cap,
9752 PEER_CAP_AS4_ADV))
9753 vty_out(vty, " advertised");
9754 if (CHECK_FLAG(p->cap,
9755 PEER_CAP_AS4_RCV))
9756 vty_out(vty, " %sreceived",
9757 CHECK_FLAG(
9758 p->cap,
9759 PEER_CAP_AS4_ADV)
9760 ? "and "
9761 : "");
9762 vty_out(vty, "\n");
9763 }
9764
9765 /* AddPath */
9766 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9767 || CHECK_FLAG(p->cap,
9768 PEER_CAP_ADDPATH_ADV)) {
9769 vty_out(vty, " AddPath:\n");
9770
05c7a1cc
QY
9771 FOREACH_AFI_SAFI (afi, safi) {
9772 if (CHECK_FLAG(
9773 p->af_cap[afi]
9774 [safi],
9775 PEER_CAP_ADDPATH_AF_TX_ADV)
9776 || CHECK_FLAG(
9777 p->af_cap[afi]
9778 [safi],
9779 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9780 vty_out(vty,
9781 " %s: TX ",
9782 afi_safi_print(
9783 afi,
9784 safi));
9785
d62a17ae 9786 if (CHECK_FLAG(
9787 p->af_cap
9788 [afi]
9789 [safi],
05c7a1cc 9790 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 9791 vty_out(vty,
05c7a1cc 9792 "advertised %s",
d62a17ae 9793 afi_safi_print(
9794 afi,
9795 safi));
9796
05c7a1cc
QY
9797 if (CHECK_FLAG(
9798 p->af_cap
9799 [afi]
9800 [safi],
9801 PEER_CAP_ADDPATH_AF_TX_RCV))
9802 vty_out(vty,
9803 "%sreceived",
9804 CHECK_FLAG(
9805 p->af_cap
9806 [afi]
9807 [safi],
9808 PEER_CAP_ADDPATH_AF_TX_ADV)
9809 ? " and "
9810 : "");
d62a17ae 9811
05c7a1cc
QY
9812 vty_out(vty, "\n");
9813 }
d62a17ae 9814
05c7a1cc
QY
9815 if (CHECK_FLAG(
9816 p->af_cap[afi]
9817 [safi],
9818 PEER_CAP_ADDPATH_AF_RX_ADV)
9819 || CHECK_FLAG(
9820 p->af_cap[afi]
9821 [safi],
9822 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9823 vty_out(vty,
9824 " %s: RX ",
9825 afi_safi_print(
9826 afi,
9827 safi));
d62a17ae 9828
9829 if (CHECK_FLAG(
9830 p->af_cap
9831 [afi]
9832 [safi],
05c7a1cc 9833 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 9834 vty_out(vty,
05c7a1cc 9835 "advertised %s",
d62a17ae 9836 afi_safi_print(
9837 afi,
9838 safi));
9839
05c7a1cc
QY
9840 if (CHECK_FLAG(
9841 p->af_cap
9842 [afi]
9843 [safi],
9844 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 9845 vty_out(vty,
05c7a1cc
QY
9846 "%sreceived",
9847 CHECK_FLAG(
9848 p->af_cap
9849 [afi]
9850 [safi],
9851 PEER_CAP_ADDPATH_AF_RX_ADV)
9852 ? " and "
9853 : "");
9854
9855 vty_out(vty, "\n");
d62a17ae 9856 }
05c7a1cc 9857 }
d62a17ae 9858 }
9859
9860 /* Dynamic */
9861 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9862 || CHECK_FLAG(p->cap,
9863 PEER_CAP_DYNAMIC_ADV)) {
9864 vty_out(vty, " Dynamic:");
9865 if (CHECK_FLAG(p->cap,
9866 PEER_CAP_DYNAMIC_ADV))
9867 vty_out(vty, " advertised");
9868 if (CHECK_FLAG(p->cap,
9869 PEER_CAP_DYNAMIC_RCV))
9870 vty_out(vty, " %sreceived",
9871 CHECK_FLAG(
9872 p->cap,
9873 PEER_CAP_DYNAMIC_ADV)
9874 ? "and "
9875 : "");
9876 vty_out(vty, "\n");
9877 }
9878
9879 /* Extended nexthop */
9880 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9881 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9882 vty_out(vty, " Extended nexthop:");
9883 if (CHECK_FLAG(p->cap,
9884 PEER_CAP_ENHE_ADV))
9885 vty_out(vty, " advertised");
9886 if (CHECK_FLAG(p->cap,
9887 PEER_CAP_ENHE_RCV))
9888 vty_out(vty, " %sreceived",
9889 CHECK_FLAG(
9890 p->cap,
9891 PEER_CAP_ENHE_ADV)
9892 ? "and "
9893 : "");
9894 vty_out(vty, "\n");
9895
9896 if (CHECK_FLAG(p->cap,
9897 PEER_CAP_ENHE_RCV)) {
9898 vty_out(vty,
9899 " Address families by peer:\n ");
9900 for (safi = SAFI_UNICAST;
9901 safi < SAFI_MAX; safi++)
9902 if (CHECK_FLAG(
9903 p->af_cap
9904 [AFI_IP]
9905 [safi],
9906 PEER_CAP_ENHE_AF_RCV))
9907 vty_out(vty,
9908 " %s\n",
9909 afi_safi_print(
9910 AFI_IP,
9911 safi));
9912 }
9913 }
9914
9915 /* Route Refresh */
9916 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9917 || CHECK_FLAG(p->cap,
9918 PEER_CAP_REFRESH_NEW_RCV)
9919 || CHECK_FLAG(p->cap,
9920 PEER_CAP_REFRESH_OLD_RCV)) {
9921 vty_out(vty, " Route refresh:");
9922 if (CHECK_FLAG(p->cap,
9923 PEER_CAP_REFRESH_ADV))
9924 vty_out(vty, " advertised");
9925 if (CHECK_FLAG(p->cap,
9926 PEER_CAP_REFRESH_NEW_RCV)
9927 || CHECK_FLAG(
9928 p->cap,
9929 PEER_CAP_REFRESH_OLD_RCV))
9930 vty_out(vty, " %sreceived(%s)",
9931 CHECK_FLAG(
9932 p->cap,
9933 PEER_CAP_REFRESH_ADV)
9934 ? "and "
9935 : "",
9936 (CHECK_FLAG(
9937 p->cap,
9938 PEER_CAP_REFRESH_OLD_RCV)
9939 && CHECK_FLAG(
9940 p->cap,
9941 PEER_CAP_REFRESH_NEW_RCV))
9942 ? "old & new"
9943 : CHECK_FLAG(
9944 p->cap,
9945 PEER_CAP_REFRESH_OLD_RCV)
9946 ? "old"
9947 : "new");
9948
9949 vty_out(vty, "\n");
9950 }
9951
9952 /* Multiprotocol Extensions */
05c7a1cc
QY
9953 FOREACH_AFI_SAFI (afi, safi)
9954 if (p->afc_adv[afi][safi]
9955 || p->afc_recv[afi][safi]) {
9956 vty_out(vty,
9957 " Address Family %s:",
9958 afi_safi_print(afi,
9959 safi));
9960 if (p->afc_adv[afi][safi])
d62a17ae 9961 vty_out(vty,
05c7a1cc
QY
9962 " advertised");
9963 if (p->afc_recv[afi][safi])
9964 vty_out(vty,
9965 " %sreceived",
9966 p->afc_adv[afi]
9967 [safi]
9968 ? "and "
9969 : "");
9970 vty_out(vty, "\n");
9971 }
d62a17ae 9972
9973 /* Hostname capability */
60466a63 9974 vty_out(vty, " Hostname Capability:");
d77114b7
MK
9975
9976 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
9977 vty_out(vty,
9978 " advertised (name: %s,domain name: %s)",
60466a63
QY
9979 bgp->peer_self->hostname
9980 ? bgp->peer_self
9981 ->hostname
d77114b7 9982 : "n/a",
60466a63
QY
9983 bgp->peer_self->domainname
9984 ? bgp->peer_self
9985 ->domainname
d77114b7
MK
9986 : "n/a");
9987 } else {
9988 vty_out(vty, " not advertised");
d62a17ae 9989 }
9990
d77114b7 9991 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
9992 vty_out(vty,
9993 " received (name: %s,domain name: %s)",
60466a63
QY
9994 p->hostname ? p->hostname
9995 : "n/a",
9996 p->domainname ? p->domainname
9997 : "n/a");
d77114b7
MK
9998 } else {
9999 vty_out(vty, " not received");
10000 }
10001
10002 vty_out(vty, "\n");
10003
d62a17ae 10004 /* Gracefull Restart */
10005 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10006 || CHECK_FLAG(p->cap,
10007 PEER_CAP_RESTART_ADV)) {
10008 vty_out(vty,
10009 " Graceful Restart Capabilty:");
10010 if (CHECK_FLAG(p->cap,
10011 PEER_CAP_RESTART_ADV))
10012 vty_out(vty, " advertised");
10013 if (CHECK_FLAG(p->cap,
10014 PEER_CAP_RESTART_RCV))
10015 vty_out(vty, " %sreceived",
10016 CHECK_FLAG(
10017 p->cap,
10018 PEER_CAP_RESTART_ADV)
10019 ? "and "
10020 : "");
10021 vty_out(vty, "\n");
10022
10023 if (CHECK_FLAG(p->cap,
10024 PEER_CAP_RESTART_RCV)) {
10025 int restart_af_count = 0;
10026
10027 vty_out(vty,
10028 " Remote Restart timer is %d seconds\n",
10029 p->v_gr_restart);
10030 vty_out(vty,
10031 " Address families by peer:\n ");
10032
05c7a1cc
QY
10033 FOREACH_AFI_SAFI (afi, safi)
10034 if (CHECK_FLAG(
10035 p->af_cap
10036 [afi]
10037 [safi],
10038 PEER_CAP_RESTART_AF_RCV)) {
10039 vty_out(vty,
10040 "%s%s(%s)",
10041 restart_af_count
10042 ? ", "
10043 : "",
10044 afi_safi_print(
10045 afi,
10046 safi),
10047 CHECK_FLAG(
10048 p->af_cap
10049 [afi]
10050 [safi],
10051 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10052 ? "preserved"
10053 : "not preserved");
10054 restart_af_count++;
10055 }
d62a17ae 10056 if (!restart_af_count)
10057 vty_out(vty, "none");
10058 vty_out(vty, "\n");
10059 }
10060 }
10061 }
10062 }
10063 }
10064
10065 /* graceful restart information */
10066 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10067 || p->t_gr_stale) {
10068 json_object *json_grace = NULL;
10069 json_object *json_grace_send = NULL;
10070 json_object *json_grace_recv = NULL;
10071 int eor_send_af_count = 0;
10072 int eor_receive_af_count = 0;
10073
10074 if (use_json) {
10075 json_grace = json_object_new_object();
10076 json_grace_send = json_object_new_object();
10077 json_grace_recv = json_object_new_object();
10078
10079 if (p->status == Established) {
05c7a1cc
QY
10080 FOREACH_AFI_SAFI (afi, safi) {
10081 if (CHECK_FLAG(p->af_sflags[afi][safi],
10082 PEER_STATUS_EOR_SEND)) {
10083 json_object_boolean_true_add(
10084 json_grace_send,
10085 afi_safi_print(afi,
10086 safi));
10087 eor_send_af_count++;
d62a17ae 10088 }
10089 }
05c7a1cc
QY
10090 FOREACH_AFI_SAFI (afi, safi) {
10091 if (CHECK_FLAG(
10092 p->af_sflags[afi][safi],
10093 PEER_STATUS_EOR_RECEIVED)) {
10094 json_object_boolean_true_add(
10095 json_grace_recv,
10096 afi_safi_print(afi,
10097 safi));
10098 eor_receive_af_count++;
d62a17ae 10099 }
10100 }
10101 }
10102
10103 json_object_object_add(json_grace, "endOfRibSend",
10104 json_grace_send);
10105 json_object_object_add(json_grace, "endOfRibRecv",
10106 json_grace_recv);
10107
10108 if (p->t_gr_restart)
10109 json_object_int_add(json_grace,
10110 "gracefulRestartTimerMsecs",
10111 thread_timer_remain_second(
10112 p->t_gr_restart)
10113 * 1000);
10114
10115 if (p->t_gr_stale)
10116 json_object_int_add(
10117 json_grace,
10118 "gracefulStalepathTimerMsecs",
10119 thread_timer_remain_second(
10120 p->t_gr_stale)
10121 * 1000);
10122
10123 json_object_object_add(
10124 json_neigh, "gracefulRestartInfo", json_grace);
10125 } else {
10126 vty_out(vty, " Graceful restart informations:\n");
10127 if (p->status == Established) {
10128 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10129 FOREACH_AFI_SAFI (afi, safi) {
10130 if (CHECK_FLAG(p->af_sflags[afi][safi],
10131 PEER_STATUS_EOR_SEND)) {
10132 vty_out(vty, "%s%s",
10133 eor_send_af_count ? ", "
10134 : "",
10135 afi_safi_print(afi,
10136 safi));
10137 eor_send_af_count++;
d62a17ae 10138 }
10139 }
10140 vty_out(vty, "\n");
10141 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10142 FOREACH_AFI_SAFI (afi, safi) {
10143 if (CHECK_FLAG(
10144 p->af_sflags[afi][safi],
10145 PEER_STATUS_EOR_RECEIVED)) {
10146 vty_out(vty, "%s%s",
10147 eor_receive_af_count
10148 ? ", "
10149 : "",
10150 afi_safi_print(afi,
10151 safi));
10152 eor_receive_af_count++;
d62a17ae 10153 }
10154 }
10155 vty_out(vty, "\n");
10156 }
10157
10158 if (p->t_gr_restart)
10159 vty_out(vty,
10160 " The remaining time of restart timer is %ld\n",
10161 thread_timer_remain_second(
10162 p->t_gr_restart));
10163
10164 if (p->t_gr_stale)
10165 vty_out(vty,
10166 " The remaining time of stalepath timer is %ld\n",
10167 thread_timer_remain_second(
10168 p->t_gr_stale));
10169 }
10170 }
10171 if (use_json) {
10172 json_object *json_stat = NULL;
10173 json_stat = json_object_new_object();
10174 /* Packet counts. */
10175 json_object_int_add(json_stat, "depthInq", 0);
10176 json_object_int_add(json_stat, "depthOutq",
10177 (unsigned long)p->obuf->count);
0112e9e0
QY
10178 json_object_int_add(json_stat, "opensSent",
10179 atomic_load_explicit(&p->open_out,
10180 memory_order_relaxed));
10181 json_object_int_add(json_stat, "opensRecv",
10182 atomic_load_explicit(&p->open_in,
10183 memory_order_relaxed));
d62a17ae 10184 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10185 atomic_load_explicit(&p->notify_out,
10186 memory_order_relaxed));
d62a17ae 10187 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10188 atomic_load_explicit(&p->notify_in,
10189 memory_order_relaxed));
10190 json_object_int_add(json_stat, "updatesSent",
10191 atomic_load_explicit(&p->update_out,
10192 memory_order_relaxed));
10193 json_object_int_add(json_stat, "updatesRecv",
10194 atomic_load_explicit(&p->update_in,
10195 memory_order_relaxed));
d62a17ae 10196 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10197 atomic_load_explicit(&p->keepalive_out,
10198 memory_order_relaxed));
d62a17ae 10199 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10200 atomic_load_explicit(&p->keepalive_in,
10201 memory_order_relaxed));
d62a17ae 10202 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10203 atomic_load_explicit(&p->refresh_out,
10204 memory_order_relaxed));
d62a17ae 10205 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10206 atomic_load_explicit(&p->refresh_in,
10207 memory_order_relaxed));
d62a17ae 10208 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10209 atomic_load_explicit(&p->dynamic_cap_out,
10210 memory_order_relaxed));
d62a17ae 10211 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10212 atomic_load_explicit(&p->dynamic_cap_in,
10213 memory_order_relaxed));
10214 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10215 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10216 json_object_object_add(json_neigh, "messageStats", json_stat);
10217 } else {
10218 /* Packet counts. */
10219 vty_out(vty, " Message statistics:\n");
10220 vty_out(vty, " Inq depth is 0\n");
10221 vty_out(vty, " Outq depth is %lu\n",
10222 (unsigned long)p->obuf->count);
10223 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10224 vty_out(vty, " Opens: %10d %10d\n",
10225 atomic_load_explicit(&p->open_out,
10226 memory_order_relaxed),
10227 atomic_load_explicit(&p->open_in,
10228 memory_order_relaxed));
10229 vty_out(vty, " Notifications: %10d %10d\n",
10230 atomic_load_explicit(&p->notify_out,
10231 memory_order_relaxed),
10232 atomic_load_explicit(&p->notify_in,
10233 memory_order_relaxed));
10234 vty_out(vty, " Updates: %10d %10d\n",
10235 atomic_load_explicit(&p->update_out,
10236 memory_order_relaxed),
10237 atomic_load_explicit(&p->update_in,
10238 memory_order_relaxed));
10239 vty_out(vty, " Keepalives: %10d %10d\n",
10240 atomic_load_explicit(&p->keepalive_out,
10241 memory_order_relaxed),
10242 atomic_load_explicit(&p->keepalive_in,
10243 memory_order_relaxed));
10244 vty_out(vty, " Route Refresh: %10d %10d\n",
10245 atomic_load_explicit(&p->refresh_out,
10246 memory_order_relaxed),
10247 atomic_load_explicit(&p->refresh_in,
10248 memory_order_relaxed));
d62a17ae 10249 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10250 atomic_load_explicit(&p->dynamic_cap_out,
10251 memory_order_relaxed),
10252 atomic_load_explicit(&p->dynamic_cap_in,
10253 memory_order_relaxed));
10254 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10255 PEER_TOTAL_RX(p));
d62a17ae 10256 }
10257
10258 if (use_json) {
10259 /* advertisement-interval */
10260 json_object_int_add(json_neigh,
10261 "minBtwnAdvertisementRunsTimerMsecs",
10262 p->v_routeadv * 1000);
10263
10264 /* Update-source. */
10265 if (p->update_if || p->update_source) {
10266 if (p->update_if)
10267 json_object_string_add(json_neigh,
10268 "updateSource",
10269 p->update_if);
10270 else if (p->update_source)
10271 json_object_string_add(
10272 json_neigh, "updateSource",
10273 sockunion2str(p->update_source, buf1,
10274 SU_ADDRSTRLEN));
10275 }
10276 } else {
10277 /* advertisement-interval */
10278 vty_out(vty,
10279 " Minimum time between advertisement runs is %d seconds\n",
10280 p->v_routeadv);
10281
10282 /* Update-source. */
10283 if (p->update_if || p->update_source) {
10284 vty_out(vty, " Update source is ");
10285 if (p->update_if)
10286 vty_out(vty, "%s", p->update_if);
10287 else if (p->update_source)
10288 vty_out(vty, "%s",
10289 sockunion2str(p->update_source, buf1,
10290 SU_ADDRSTRLEN));
10291 vty_out(vty, "\n");
10292 }
10293
10294 vty_out(vty, "\n");
10295 }
10296
10297 /* Address Family Information */
10298 json_object *json_hold = NULL;
10299
10300 if (use_json)
10301 json_hold = json_object_new_object();
10302
05c7a1cc
QY
10303 FOREACH_AFI_SAFI (afi, safi)
10304 if (p->afc[afi][safi])
10305 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10306 json_hold);
d62a17ae 10307
10308 if (use_json) {
10309 json_object_object_add(json_neigh, "addressFamilyInfo",
10310 json_hold);
10311 json_object_int_add(json_neigh, "connectionsEstablished",
10312 p->established);
10313 json_object_int_add(json_neigh, "connectionsDropped",
10314 p->dropped);
10315 } else
10316 vty_out(vty, " Connections established %d; dropped %d\n",
10317 p->established, p->dropped);
10318
10319 if (!p->last_reset) {
10320 if (use_json)
10321 json_object_string_add(json_neigh, "lastReset",
10322 "never");
10323 else
10324 vty_out(vty, " Last reset never\n");
10325 } else {
10326 if (use_json) {
10327 time_t uptime;
10328 struct tm *tm;
10329
10330 uptime = bgp_clock();
10331 uptime -= p->resettime;
10332 tm = gmtime(&uptime);
10333 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10334 (tm->tm_sec * 1000)
10335 + (tm->tm_min * 60000)
10336 + (tm->tm_hour * 3600000));
10337 json_object_string_add(
10338 json_neigh, "lastResetDueTo",
10339 peer_down_str[(int)p->last_reset]);
10340 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10341 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10342 char errorcodesubcode_hexstr[5];
10343 char errorcodesubcode_str[256];
10344
10345 code_str = bgp_notify_code_str(p->notify.code);
10346 subcode_str = bgp_notify_subcode_str(
10347 p->notify.code, p->notify.subcode);
10348
10349 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10350 p->notify.code, p->notify.subcode);
10351 json_object_string_add(json_neigh,
10352 "lastErrorCodeSubcode",
10353 errorcodesubcode_hexstr);
10354 snprintf(errorcodesubcode_str, 255, "%s%s",
10355 code_str, subcode_str);
10356 json_object_string_add(json_neigh,
10357 "lastNotificationReason",
10358 errorcodesubcode_str);
10359 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10360 && p->notify.code == BGP_NOTIFY_CEASE
10361 && (p->notify.subcode
10362 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10363 || p->notify.subcode
10364 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10365 && p->notify.length) {
10366 char msgbuf[1024];
10367 const char *msg_str;
10368
10369 msg_str = bgp_notify_admin_message(
10370 msgbuf, sizeof(msgbuf),
d7c0a89a 10371 (uint8_t *)p->notify.data,
d62a17ae 10372 p->notify.length);
10373 if (msg_str)
10374 json_object_string_add(
10375 json_neigh,
10376 "lastShutdownDescription",
10377 msg_str);
10378 }
10379 }
10380 } else {
10381 vty_out(vty, " Last reset %s, ",
10382 peer_uptime(p->resettime, timebuf,
10383 BGP_UPTIME_LEN, 0, NULL));
10384
10385 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10386 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10387 code_str = bgp_notify_code_str(p->notify.code);
10388 subcode_str = bgp_notify_subcode_str(
10389 p->notify.code, p->notify.subcode);
10390 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10391 p->last_reset == PEER_DOWN_NOTIFY_SEND
10392 ? "sent"
10393 : "received",
10394 code_str, subcode_str);
10395 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10396 && p->notify.code == BGP_NOTIFY_CEASE
10397 && (p->notify.subcode
10398 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10399 || p->notify.subcode
10400 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10401 && p->notify.length) {
10402 char msgbuf[1024];
10403 const char *msg_str;
10404
10405 msg_str = bgp_notify_admin_message(
10406 msgbuf, sizeof(msgbuf),
d7c0a89a 10407 (uint8_t *)p->notify.data,
d62a17ae 10408 p->notify.length);
10409 if (msg_str)
10410 vty_out(vty,
10411 " Message: \"%s\"\n",
10412 msg_str);
10413 }
10414 } else {
10415 vty_out(vty, "due to %s\n",
10416 peer_down_str[(int)p->last_reset]);
10417 }
10418
10419 if (p->last_reset_cause_size) {
10420 msg = p->last_reset_cause;
10421 vty_out(vty,
10422 " Message received that caused BGP to send a NOTIFICATION:\n ");
10423 for (i = 1; i <= p->last_reset_cause_size;
10424 i++) {
10425 vty_out(vty, "%02X", *msg++);
10426
10427 if (i != p->last_reset_cause_size) {
10428 if (i % 16 == 0) {
10429 vty_out(vty, "\n ");
10430 } else if (i % 4 == 0) {
10431 vty_out(vty, " ");
10432 }
10433 }
10434 }
10435 vty_out(vty, "\n");
10436 }
10437 }
10438 }
10439
10440 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10441 if (use_json)
10442 json_object_boolean_true_add(json_neigh,
10443 "prefixesConfigExceedMax");
10444 else
10445 vty_out(vty,
10446 " Peer had exceeded the max. no. of prefixes configured.\n");
10447
10448 if (p->t_pmax_restart) {
10449 if (use_json) {
10450 json_object_boolean_true_add(
10451 json_neigh, "reducePrefixNumFrom");
10452 json_object_int_add(json_neigh,
10453 "restartInTimerMsec",
10454 thread_timer_remain_second(
10455 p->t_pmax_restart)
10456 * 1000);
10457 } else
10458 vty_out(vty,
10459 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10460 p->host, thread_timer_remain_second(
10461 p->t_pmax_restart));
d62a17ae 10462 } else {
10463 if (use_json)
10464 json_object_boolean_true_add(
10465 json_neigh,
10466 "reducePrefixNumAndClearIpBgp");
10467 else
10468 vty_out(vty,
10469 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10470 p->host);
10471 }
10472 }
10473
10474 /* EBGP Multihop and GTSM */
10475 if (p->sort != BGP_PEER_IBGP) {
10476 if (use_json) {
10477 if (p->gtsm_hops > 0)
10478 json_object_int_add(json_neigh,
10479 "externalBgpNbrMaxHopsAway",
10480 p->gtsm_hops);
10481 else if (p->ttl > 1)
10482 json_object_int_add(json_neigh,
10483 "externalBgpNbrMaxHopsAway",
10484 p->ttl);
10485 } else {
10486 if (p->gtsm_hops > 0)
10487 vty_out(vty,
10488 " External BGP neighbor may be up to %d hops away.\n",
10489 p->gtsm_hops);
10490 else if (p->ttl > 1)
10491 vty_out(vty,
10492 " External BGP neighbor may be up to %d hops away.\n",
10493 p->ttl);
10494 }
10495 } else {
10496 if (p->gtsm_hops > 0) {
10497 if (use_json)
10498 json_object_int_add(json_neigh,
10499 "internalBgpNbrMaxHopsAway",
10500 p->gtsm_hops);
10501 else
10502 vty_out(vty,
10503 " Internal BGP neighbor may be up to %d hops away.\n",
10504 p->gtsm_hops);
10505 }
10506 }
10507
10508 /* Local address. */
10509 if (p->su_local) {
10510 if (use_json) {
10511 json_object_string_add(json_neigh, "hostLocal",
10512 sockunion2str(p->su_local, buf1,
10513 SU_ADDRSTRLEN));
10514 json_object_int_add(json_neigh, "portLocal",
10515 ntohs(p->su_local->sin.sin_port));
10516 } else
10517 vty_out(vty, "Local host: %s, Local port: %d\n",
10518 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10519 ntohs(p->su_local->sin.sin_port));
10520 }
10521
10522 /* Remote address. */
10523 if (p->su_remote) {
10524 if (use_json) {
10525 json_object_string_add(json_neigh, "hostForeign",
10526 sockunion2str(p->su_remote, buf1,
10527 SU_ADDRSTRLEN));
10528 json_object_int_add(json_neigh, "portForeign",
10529 ntohs(p->su_remote->sin.sin_port));
10530 } else
10531 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10532 sockunion2str(p->su_remote, buf1,
10533 SU_ADDRSTRLEN),
10534 ntohs(p->su_remote->sin.sin_port));
10535 }
10536
10537 /* Nexthop display. */
10538 if (p->su_local) {
10539 if (use_json) {
10540 json_object_string_add(json_neigh, "nexthop",
10541 inet_ntop(AF_INET,
10542 &p->nexthop.v4, buf1,
10543 sizeof(buf1)));
10544 json_object_string_add(json_neigh, "nexthopGlobal",
10545 inet_ntop(AF_INET6,
10546 &p->nexthop.v6_global,
10547 buf1, sizeof(buf1)));
10548 json_object_string_add(json_neigh, "nexthopLocal",
10549 inet_ntop(AF_INET6,
10550 &p->nexthop.v6_local,
10551 buf1, sizeof(buf1)));
10552 if (p->shared_network)
10553 json_object_string_add(json_neigh,
10554 "bgpConnection",
10555 "sharedNetwork");
10556 else
10557 json_object_string_add(json_neigh,
10558 "bgpConnection",
10559 "nonSharedNetwork");
10560 } else {
10561 vty_out(vty, "Nexthop: %s\n",
10562 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10563 sizeof(buf1)));
10564 vty_out(vty, "Nexthop global: %s\n",
10565 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10566 sizeof(buf1)));
10567 vty_out(vty, "Nexthop local: %s\n",
10568 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10569 sizeof(buf1)));
10570 vty_out(vty, "BGP connection: %s\n",
10571 p->shared_network ? "shared network"
10572 : "non shared network");
10573 }
10574 }
10575
10576 /* Timer information. */
10577 if (use_json) {
10578 json_object_int_add(json_neigh, "connectRetryTimer",
10579 p->v_connect);
10580 if (p->status == Established && p->rtt)
10581 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10582 p->rtt);
10583 if (p->t_start)
10584 json_object_int_add(
10585 json_neigh, "nextStartTimerDueInMsecs",
10586 thread_timer_remain_second(p->t_start) * 1000);
10587 if (p->t_connect)
10588 json_object_int_add(
10589 json_neigh, "nextConnectTimerDueInMsecs",
10590 thread_timer_remain_second(p->t_connect)
10591 * 1000);
10592 if (p->t_routeadv) {
10593 json_object_int_add(json_neigh, "mraiInterval",
10594 p->v_routeadv);
10595 json_object_int_add(
10596 json_neigh, "mraiTimerExpireInMsecs",
10597 thread_timer_remain_second(p->t_routeadv)
10598 * 1000);
10599 }
10600 if (p->password)
10601 json_object_int_add(json_neigh, "authenticationEnabled",
10602 1);
10603
10604 if (p->t_read)
10605 json_object_string_add(json_neigh, "readThread", "on");
10606 else
10607 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10608
10609 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10610 json_object_string_add(json_neigh, "writeThread", "on");
10611 else
10612 json_object_string_add(json_neigh, "writeThread",
10613 "off");
10614 } else {
10615 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10616 p->v_connect);
10617 if (p->status == Established && p->rtt)
10618 vty_out(vty, "Estimated round trip time: %d ms\n",
10619 p->rtt);
10620 if (p->t_start)
10621 vty_out(vty, "Next start timer due in %ld seconds\n",
10622 thread_timer_remain_second(p->t_start));
10623 if (p->t_connect)
10624 vty_out(vty, "Next connect timer due in %ld seconds\n",
10625 thread_timer_remain_second(p->t_connect));
10626 if (p->t_routeadv)
10627 vty_out(vty,
10628 "MRAI (interval %u) timer expires in %ld seconds\n",
10629 p->v_routeadv,
10630 thread_timer_remain_second(p->t_routeadv));
10631 if (p->password)
10632 vty_out(vty, "Peer Authentication Enabled\n");
10633
10634 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10635 p->t_read ? "on" : "off",
10636 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10637 ? "on"
10638 : "off");
d62a17ae 10639 }
10640
10641 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10642 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10643 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10644
10645 if (!use_json)
10646 vty_out(vty, "\n");
10647
10648 /* BFD information. */
10649 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10650
10651 if (use_json) {
10652 if (p->conf_if) /* Configured interface name. */
10653 json_object_object_add(json, p->conf_if, json_neigh);
10654 else /* Configured IP address. */
10655 json_object_object_add(json, p->host, json_neigh);
10656 }
10657}
10658
10659static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10660 enum show_type type, union sockunion *su,
d7c0a89a 10661 const char *conf_if, uint8_t use_json,
d62a17ae 10662 json_object *json)
10663{
10664 struct listnode *node, *nnode;
10665 struct peer *peer;
10666 int find = 0;
10667
10668 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10669 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10670 continue;
10671
10672 switch (type) {
10673 case show_all:
10674 bgp_show_peer(vty, peer, use_json, json);
10675 break;
10676 case show_peer:
10677 if (conf_if) {
10678 if ((peer->conf_if
10679 && !strcmp(peer->conf_if, conf_if))
10680 || (peer->hostname
10681 && !strcmp(peer->hostname, conf_if))) {
10682 find = 1;
10683 bgp_show_peer(vty, peer, use_json,
10684 json);
10685 }
10686 } else {
10687 if (sockunion_same(&peer->su, su)) {
10688 find = 1;
10689 bgp_show_peer(vty, peer, use_json,
10690 json);
10691 }
10692 }
10693 break;
10694 }
10695 }
10696
10697 if (type == show_peer && !find) {
10698 if (use_json)
10699 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10700 else
88b7d255 10701 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 10702 }
10703
10704 if (use_json) {
996c9314
LB
10705 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10706 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10707 json_object_free(json);
10708 } else {
10709 vty_out(vty, "\n");
10710 }
10711
10712 return CMD_SUCCESS;
10713}
10714
10715static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10716 enum show_type type,
10717 const char *ip_str,
d7c0a89a 10718 uint8_t use_json)
d62a17ae 10719{
0291c246
MK
10720 struct listnode *node, *nnode;
10721 struct bgp *bgp;
71aedaa3 10722 union sockunion su;
0291c246 10723 json_object *json = NULL;
71aedaa3 10724 int ret, is_first = 1;
d62a17ae 10725
10726 if (use_json)
10727 vty_out(vty, "{\n");
10728
10729 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10730 if (use_json) {
10731 if (!(json = json_object_new_object())) {
10732 zlog_err(
10733 "Unable to allocate memory for JSON object");
10734 vty_out(vty,
10735 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10736 return;
10737 }
10738
10739 json_object_int_add(json, "vrfId",
10740 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10741 ? -1
10742 : (int64_t)bgp->vrf_id);
d62a17ae 10743 json_object_string_add(
10744 json, "vrfName",
10745 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10746 ? "Default"
10747 : bgp->name);
10748
10749 if (!is_first)
10750 vty_out(vty, ",\n");
10751 else
10752 is_first = 0;
10753
10754 vty_out(vty, "\"%s\":",
10755 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10756 ? "Default"
10757 : bgp->name);
10758 } else {
10759 vty_out(vty, "\nInstance %s:\n",
10760 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10761 ? "Default"
10762 : bgp->name);
10763 }
71aedaa3
DS
10764
10765 if (type == show_peer) {
10766 ret = str2sockunion(ip_str, &su);
10767 if (ret < 0)
10768 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10769 use_json, json);
10770 else
10771 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10772 use_json, json);
10773 } else {
10774 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10775 use_json, json);
10776 }
d62a17ae 10777 }
10778
10779 if (use_json)
10780 vty_out(vty, "}\n");
10781}
10782
10783static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10784 enum show_type type, const char *ip_str,
d7c0a89a 10785 uint8_t use_json)
d62a17ae 10786{
10787 int ret;
10788 struct bgp *bgp;
10789 union sockunion su;
10790 json_object *json = NULL;
10791
10792 if (name) {
10793 if (strmatch(name, "all")) {
71aedaa3
DS
10794 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10795 use_json);
d62a17ae 10796 return CMD_SUCCESS;
10797 } else {
10798 bgp = bgp_lookup_by_name(name);
10799 if (!bgp) {
10800 if (use_json) {
10801 json = json_object_new_object();
10802 json_object_boolean_true_add(
10803 json, "bgpNoSuchInstance");
10804 vty_out(vty, "%s\n",
10805 json_object_to_json_string_ext(
10806 json,
10807 JSON_C_TO_STRING_PRETTY));
10808 json_object_free(json);
10809 } else
10810 vty_out(vty,
10811 "%% No such BGP instance exist\n");
10812
10813 return CMD_WARNING;
10814 }
10815 }
10816 } else {
10817 bgp = bgp_get_default();
10818 }
10819
10820 if (bgp) {
10821 json = json_object_new_object();
10822 if (ip_str) {
10823 ret = str2sockunion(ip_str, &su);
10824 if (ret < 0)
10825 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10826 use_json, json);
10827 else
10828 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10829 use_json, json);
10830 } else {
10831 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10832 json);
10833 }
10834 json_object_free(json);
10835 }
10836
10837 return CMD_SUCCESS;
4fb25c53
DW
10838}
10839
716b2d8a 10840/* "show [ip] bgp neighbors" commands. */
718e3744 10841DEFUN (show_ip_bgp_neighbors,
10842 show_ip_bgp_neighbors_cmd,
24345e82 10843 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 10844 SHOW_STR
10845 IP_STR
10846 BGP_STR
f2a8972b 10847 BGP_INSTANCE_HELP_STR
8c3deaae
QY
10848 "Address Family\n"
10849 "Address Family\n"
718e3744 10850 "Detailed information on TCP and BGP neighbor connections\n"
10851 "Neighbor to display information about\n"
a80beece 10852 "Neighbor to display information about\n"
91d37724 10853 "Neighbor on BGP configured interface\n"
9973d184 10854 JSON_STR)
718e3744 10855{
d62a17ae 10856 char *vrf = NULL;
10857 char *sh_arg = NULL;
10858 enum show_type sh_type;
718e3744 10859
d7c0a89a 10860 uint8_t uj = use_json(argc, argv);
718e3744 10861
d62a17ae 10862 int idx = 0;
718e3744 10863
d62a17ae 10864 if (argv_find(argv, argc, "view", &idx)
10865 || argv_find(argv, argc, "vrf", &idx))
10866 vrf = argv[idx + 1]->arg;
718e3744 10867
d62a17ae 10868 idx++;
10869 if (argv_find(argv, argc, "A.B.C.D", &idx)
10870 || argv_find(argv, argc, "X:X::X:X", &idx)
10871 || argv_find(argv, argc, "WORD", &idx)) {
10872 sh_type = show_peer;
10873 sh_arg = argv[idx]->arg;
10874 } else
10875 sh_type = show_all;
856ca177 10876
d62a17ae 10877 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10878}
10879
716b2d8a 10880/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10881 paths' and `show ip mbgp paths'. Those functions results are the
10882 same.*/
f412b39a 10883DEFUN (show_ip_bgp_paths,
718e3744 10884 show_ip_bgp_paths_cmd,
46f296b4 10885 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10886 SHOW_STR
10887 IP_STR
10888 BGP_STR
46f296b4 10889 BGP_SAFI_HELP_STR
718e3744 10890 "Path information\n")
10891{
d62a17ae 10892 vty_out(vty, "Address Refcnt Path\n");
10893 aspath_print_all_vty(vty);
10894 return CMD_SUCCESS;
718e3744 10895}
10896
718e3744 10897#include "hash.h"
10898
d62a17ae 10899static void community_show_all_iterator(struct hash_backet *backet,
10900 struct vty *vty)
718e3744 10901{
d62a17ae 10902 struct community *com;
718e3744 10903
d62a17ae 10904 com = (struct community *)backet->data;
3f65c5b1 10905 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 10906 community_str(com, false));
718e3744 10907}
10908
10909/* Show BGP's community internal data. */
f412b39a 10910DEFUN (show_ip_bgp_community_info,
718e3744 10911 show_ip_bgp_community_info_cmd,
bec37ba5 10912 "show [ip] bgp community-info",
718e3744 10913 SHOW_STR
10914 IP_STR
10915 BGP_STR
10916 "List all bgp community information\n")
10917{
d62a17ae 10918 vty_out(vty, "Address Refcnt Community\n");
718e3744 10919
d62a17ae 10920 hash_iterate(community_hash(),
10921 (void (*)(struct hash_backet *,
10922 void *))community_show_all_iterator,
10923 vty);
718e3744 10924
d62a17ae 10925 return CMD_SUCCESS;
718e3744 10926}
10927
d62a17ae 10928static void lcommunity_show_all_iterator(struct hash_backet *backet,
10929 struct vty *vty)
57d187bc 10930{
d62a17ae 10931 struct lcommunity *lcom;
57d187bc 10932
d62a17ae 10933 lcom = (struct lcommunity *)backet->data;
3f65c5b1 10934 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 10935 lcommunity_str(lcom, false));
57d187bc
JS
10936}
10937
10938/* Show BGP's community internal data. */
10939DEFUN (show_ip_bgp_lcommunity_info,
10940 show_ip_bgp_lcommunity_info_cmd,
10941 "show ip bgp large-community-info",
10942 SHOW_STR
10943 IP_STR
10944 BGP_STR
10945 "List all bgp large-community information\n")
10946{
d62a17ae 10947 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 10948
d62a17ae 10949 hash_iterate(lcommunity_hash(),
10950 (void (*)(struct hash_backet *,
10951 void *))lcommunity_show_all_iterator,
10952 vty);
57d187bc 10953
d62a17ae 10954 return CMD_SUCCESS;
57d187bc
JS
10955}
10956
10957
f412b39a 10958DEFUN (show_ip_bgp_attr_info,
718e3744 10959 show_ip_bgp_attr_info_cmd,
bec37ba5 10960 "show [ip] bgp attribute-info",
718e3744 10961 SHOW_STR
10962 IP_STR
10963 BGP_STR
10964 "List all bgp attribute information\n")
10965{
d62a17ae 10966 attr_show_all(vty);
10967 return CMD_SUCCESS;
718e3744 10968}
6b0655a2 10969
53089bec 10970static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10971 afi_t afi, safi_t safi)
10972{
10973 struct bgp *bgp;
10974 struct listnode *node;
10975 char *vname;
10976 char buf1[INET6_ADDRSTRLEN];
10977 char *ecom_str;
10978 vpn_policy_direction_t dir;
10979
10980 if (name) {
10981 bgp = bgp_lookup_by_name(name);
10982 if (!bgp) {
10983 vty_out(vty, "%% No such BGP instance exist\n");
10984 return CMD_WARNING;
10985 }
10986 } else {
10987 bgp = bgp_get_default();
10988 if (!bgp) {
020a3f60
DS
10989 vty_out(vty,
10990 "%% Default BGP instance does not exist\n");
53089bec 10991 return CMD_WARNING;
10992 }
10993 }
10994
10995 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10996 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
020a3f60
DS
10997 vty_out(vty,
10998 "This VRF is not importing %s routes from any other VRF\n",
53089bec 10999 afi_safi_print(afi, safi));
11000 } else {
020a3f60
DS
11001 vty_out(vty,
11002 "This VRF is importing %s routes from the following VRFs:\n",
53089bec 11003 afi_safi_print(afi, safi));
11004 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
11005 vname)) {
11006 vty_out(vty, " %s\n", vname);
11007 }
11008 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11009 ecom_str = ecommunity_ecom2str(
11010 bgp->vpn_policy[afi].rtlist[dir],
11011 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11012 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11013 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11014 }
11015
11016 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11017 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
020a3f60
DS
11018 vty_out(vty,
11019 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11020 afi_safi_print(afi, safi));
11021 } else {
020a3f60
DS
11022 vty_out(vty,
11023 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11024 afi_safi_print(afi, safi));
11025 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
11026 vname)) {
11027 vty_out(vty, " %s\n", vname);
11028 }
11029 vty_out(vty, "RD: %s\n",
11030 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11031 buf1, RD_ADDRSTRLEN));
11032 dir = BGP_VPN_POLICY_DIR_TOVPN;
11033 ecom_str = ecommunity_ecom2str(
11034 bgp->vpn_policy[afi].rtlist[dir],
11035 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11036 vty_out(vty, "Emport RT: %s\n", ecom_str);
11037 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11038 }
11039
11040 return CMD_SUCCESS;
11041}
11042
11043/* "show [ip] bgp route-leak" command. */
11044DEFUN (show_ip_bgp_route_leak,
11045 show_ip_bgp_route_leak_cmd,
11046 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
11047 SHOW_STR
11048 IP_STR
11049 BGP_STR
11050 BGP_INSTANCE_HELP_STR
11051 BGP_AFI_HELP_STR
11052 BGP_SAFI_HELP_STR
11053 "Route leaking information\n")
11054{
11055 char *vrf = NULL;
11056 afi_t afi = AFI_MAX;
11057 safi_t safi = SAFI_MAX;
11058
11059 int idx = 0;
11060
11061 /* show [ip] bgp */
11062 if (argv_find(argv, argc, "ip", &idx)) {
11063 afi = AFI_IP;
11064 safi = SAFI_UNICAST;
11065 }
11066 /* [vrf VIEWVRFNAME] */
11067 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11068 vty_out(vty,
11069 "%% This command is not applicable to BGP views\n");
53089bec 11070 return CMD_WARNING;
11071 }
11072
11073 if (argv_find(argv, argc, "vrf", &idx))
11074 vrf = argv[++idx]->arg;
11075 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11076 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11077 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11078 }
11079
11080 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11081 vty_out(vty,
11082 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11083 return CMD_WARNING;
11084 }
11085
11086 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11087}
11088
d62a17ae 11089static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11090 safi_t safi)
f186de26 11091{
d62a17ae 11092 struct listnode *node, *nnode;
11093 struct bgp *bgp;
f186de26 11094
d62a17ae 11095 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11096 vty_out(vty, "\nInstance %s:\n",
11097 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11098 ? "Default"
11099 : bgp->name);
11100 update_group_show(bgp, afi, safi, vty, 0);
11101 }
f186de26 11102}
11103
d62a17ae 11104static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11105 int safi, uint64_t subgrp_id)
4fb25c53 11106{
d62a17ae 11107 struct bgp *bgp;
4fb25c53 11108
d62a17ae 11109 if (name) {
11110 if (strmatch(name, "all")) {
11111 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11112 return CMD_SUCCESS;
11113 } else {
11114 bgp = bgp_lookup_by_name(name);
11115 }
11116 } else {
11117 bgp = bgp_get_default();
11118 }
4fb25c53 11119
d62a17ae 11120 if (bgp)
11121 update_group_show(bgp, afi, safi, vty, subgrp_id);
11122 return CMD_SUCCESS;
4fb25c53
DW
11123}
11124
8fe8a7f6
DS
11125DEFUN (show_ip_bgp_updgrps,
11126 show_ip_bgp_updgrps_cmd,
c1a44e43 11127 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11128 SHOW_STR
11129 IP_STR
11130 BGP_STR
11131 BGP_INSTANCE_HELP_STR
c9e571b4 11132 BGP_AFI_HELP_STR
9bedbb1e 11133 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11134 "Detailed info about dynamic update groups\n"
11135 "Specific subgroup to display detailed info for\n")
8386ac43 11136{
d62a17ae 11137 char *vrf = NULL;
11138 afi_t afi = AFI_IP6;
11139 safi_t safi = SAFI_UNICAST;
11140 uint64_t subgrp_id = 0;
11141
11142 int idx = 0;
11143
11144 /* show [ip] bgp */
11145 if (argv_find(argv, argc, "ip", &idx))
11146 afi = AFI_IP;
11147 /* [<view|vrf> VIEWVRFNAME] */
11148 if (argv_find(argv, argc, "view", &idx)
11149 || argv_find(argv, argc, "vrf", &idx))
11150 vrf = argv[++idx]->arg;
11151 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11152 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11153 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11154 }
5bf15956 11155
d62a17ae 11156 /* get subgroup id, if provided */
11157 idx = argc - 1;
11158 if (argv[idx]->type == VARIABLE_TKN)
11159 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11160
d62a17ae 11161 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11162}
11163
f186de26 11164DEFUN (show_bgp_instance_all_ipv6_updgrps,
11165 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11166 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11167 SHOW_STR
716b2d8a 11168 IP_STR
f186de26 11169 BGP_STR
11170 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11171 "Detailed info about dynamic update groups\n")
f186de26 11172{
d62a17ae 11173 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11174 return CMD_SUCCESS;
f186de26 11175}
11176
5bf15956
DW
11177DEFUN (show_bgp_updgrps_stats,
11178 show_bgp_updgrps_stats_cmd,
716b2d8a 11179 "show [ip] bgp update-groups statistics",
3f9c7369 11180 SHOW_STR
716b2d8a 11181 IP_STR
3f9c7369 11182 BGP_STR
0c7b1b01 11183 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11184 "Statistics\n")
11185{
d62a17ae 11186 struct bgp *bgp;
3f9c7369 11187
d62a17ae 11188 bgp = bgp_get_default();
11189 if (bgp)
11190 update_group_show_stats(bgp, vty);
3f9c7369 11191
d62a17ae 11192 return CMD_SUCCESS;
3f9c7369
DS
11193}
11194
8386ac43 11195DEFUN (show_bgp_instance_updgrps_stats,
11196 show_bgp_instance_updgrps_stats_cmd,
18c57037 11197 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11198 SHOW_STR
716b2d8a 11199 IP_STR
8386ac43 11200 BGP_STR
11201 BGP_INSTANCE_HELP_STR
0c7b1b01 11202 "Detailed info about dynamic update groups\n"
8386ac43 11203 "Statistics\n")
11204{
d62a17ae 11205 int idx_word = 3;
11206 struct bgp *bgp;
8386ac43 11207
d62a17ae 11208 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11209 if (bgp)
11210 update_group_show_stats(bgp, vty);
8386ac43 11211
d62a17ae 11212 return CMD_SUCCESS;
8386ac43 11213}
11214
d62a17ae 11215static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11216 afi_t afi, safi_t safi,
11217 const char *what, uint64_t subgrp_id)
3f9c7369 11218{
d62a17ae 11219 struct bgp *bgp;
8386ac43 11220
d62a17ae 11221 if (name)
11222 bgp = bgp_lookup_by_name(name);
11223 else
11224 bgp = bgp_get_default();
8386ac43 11225
d62a17ae 11226 if (bgp) {
11227 if (!strcmp(what, "advertise-queue"))
11228 update_group_show_adj_queue(bgp, afi, safi, vty,
11229 subgrp_id);
11230 else if (!strcmp(what, "advertised-routes"))
11231 update_group_show_advertised(bgp, afi, safi, vty,
11232 subgrp_id);
11233 else if (!strcmp(what, "packet-queue"))
11234 update_group_show_packet_queue(bgp, afi, safi, vty,
11235 subgrp_id);
11236 }
3f9c7369
DS
11237}
11238
dc64bdec
QY
11239DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11240 show_ip_bgp_instance_updgrps_adj_s_cmd,
11241 "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",
11242 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11243 BGP_SAFI_HELP_STR
11244 "Detailed info about dynamic update groups\n"
11245 "Specific subgroup to display info for\n"
11246 "Advertisement queue\n"
11247 "Announced routes\n"
11248 "Packet queue\n")
3f9c7369 11249{
dc64bdec
QY
11250 uint64_t subgrp_id = 0;
11251 afi_t afiz;
11252 safi_t safiz;
11253 if (sgid)
11254 subgrp_id = strtoull(sgid, NULL, 10);
11255
11256 if (!ip && !afi)
11257 afiz = AFI_IP6;
11258 if (!ip && afi)
11259 afiz = bgp_vty_afi_from_str(afi);
11260 if (ip && !afi)
11261 afiz = AFI_IP;
11262 if (ip && afi) {
11263 afiz = bgp_vty_afi_from_str(afi);
11264 if (afiz != AFI_IP)
11265 vty_out(vty,
11266 "%% Cannot specify both 'ip' and 'ipv6'\n");
11267 return CMD_WARNING;
11268 }
d62a17ae 11269
dc64bdec 11270 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11271
dc64bdec 11272 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11273 return CMD_SUCCESS;
11274}
11275
d62a17ae 11276static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11277{
11278 struct listnode *node, *nnode;
11279 struct prefix *range;
11280 struct peer *conf;
11281 struct peer *peer;
11282 char buf[PREFIX2STR_BUFFER];
11283 afi_t afi;
11284 safi_t safi;
11285 const char *peer_status;
11286 const char *af_str;
11287 int lr_count;
11288 int dynamic;
11289 int af_cfgd;
11290
11291 conf = group->conf;
11292
11293 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11294 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11295 conf->as);
11296 } else if (conf->as_type == AS_INTERNAL) {
11297 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11298 group->bgp->as);
11299 } else {
11300 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11301 }
f14e6fdb 11302
d62a17ae 11303 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11304 vty_out(vty, " Peer-group type is internal\n");
11305 else
11306 vty_out(vty, " Peer-group type is external\n");
11307
11308 /* Display AFs configured. */
11309 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11310 FOREACH_AFI_SAFI (afi, safi) {
11311 if (conf->afc[afi][safi]) {
11312 af_cfgd = 1;
11313 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11314 }
05c7a1cc 11315 }
d62a17ae 11316 if (!af_cfgd)
11317 vty_out(vty, " none\n");
11318 else
11319 vty_out(vty, "\n");
11320
11321 /* Display listen ranges (for dynamic neighbors), if any */
11322 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11323 if (afi == AFI_IP)
11324 af_str = "IPv4";
11325 else if (afi == AFI_IP6)
11326 af_str = "IPv6";
11327 else
11328 af_str = "???";
11329 lr_count = listcount(group->listen_range[afi]);
11330 if (lr_count) {
11331 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11332 af_str);
11333
11334
11335 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11336 nnode, range)) {
11337 prefix2str(range, buf, sizeof(buf));
11338 vty_out(vty, " %s\n", buf);
11339 }
11340 }
11341 }
f14e6fdb 11342
d62a17ae 11343 /* Display group members and their status */
11344 if (listcount(group->peer)) {
11345 vty_out(vty, " Peer-group members:\n");
11346 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11347 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11348 peer_status = "Idle (Admin)";
11349 else if (CHECK_FLAG(peer->sflags,
11350 PEER_STATUS_PREFIX_OVERFLOW))
11351 peer_status = "Idle (PfxCt)";
11352 else
11353 peer_status = lookup_msg(bgp_status_msg,
11354 peer->status, NULL);
11355
11356 dynamic = peer_dynamic_neighbor(peer);
11357 vty_out(vty, " %s %s %s \n", peer->host,
11358 dynamic ? "(dynamic)" : "", peer_status);
11359 }
11360 }
f14e6fdb 11361
d62a17ae 11362 return CMD_SUCCESS;
11363}
11364
ff9959b0
QY
11365static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11366 const char *group_name)
d62a17ae 11367{
ff9959b0 11368 struct bgp *bgp;
d62a17ae 11369 struct listnode *node, *nnode;
11370 struct peer_group *group;
ff9959b0
QY
11371 bool found = false;
11372
11373 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11374
11375 if (!bgp) {
11376 vty_out(vty, "%% No such BGP instance exists\n");
11377 return CMD_WARNING;
11378 }
d62a17ae 11379
11380 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11381 if (group_name) {
11382 if (strmatch(group->name, group_name)) {
d62a17ae 11383 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11384 found = true;
11385 break;
d62a17ae 11386 }
ff9959b0
QY
11387 } else {
11388 bgp_show_one_peer_group(vty, group);
d62a17ae 11389 }
f14e6fdb 11390 }
f14e6fdb 11391
ff9959b0 11392 if (group_name && !found)
d62a17ae 11393 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11394
d62a17ae 11395 return CMD_SUCCESS;
f14e6fdb
DS
11396}
11397
f14e6fdb
DS
11398DEFUN (show_ip_bgp_peer_groups,
11399 show_ip_bgp_peer_groups_cmd,
18c57037 11400 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11401 SHOW_STR
11402 IP_STR
11403 BGP_STR
8386ac43 11404 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11405 "Detailed information on BGP peer groups\n"
11406 "Peer group name\n")
f14e6fdb 11407{
d62a17ae 11408 char *vrf, *pg;
d62a17ae 11409 int idx = 0;
f14e6fdb 11410
a4d82a8a
PZ
11411 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11412 : NULL;
d62a17ae 11413 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11414
ff9959b0 11415 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11416}
3f9c7369 11417
d6e3c605 11418
718e3744 11419/* Redistribute VTY commands. */
11420
718e3744 11421DEFUN (bgp_redistribute_ipv4,
11422 bgp_redistribute_ipv4_cmd,
40d1cbfb 11423 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11424 "Redistribute information from another routing protocol\n"
ab0181ee 11425 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11426{
d62a17ae 11427 VTY_DECLVAR_CONTEXT(bgp, bgp);
11428 int idx_protocol = 1;
11429 int type;
718e3744 11430
d62a17ae 11431 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11432 if (type < 0) {
11433 vty_out(vty, "%% Invalid route type\n");
11434 return CMD_WARNING_CONFIG_FAILED;
11435 }
7f323236 11436
d62a17ae 11437 bgp_redist_add(bgp, AFI_IP, type, 0);
11438 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11439}
11440
d62a17ae 11441ALIAS_HIDDEN(
11442 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11443 "redistribute " FRR_IP_REDIST_STR_BGPD,
11444 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11445
718e3744 11446DEFUN (bgp_redistribute_ipv4_rmap,
11447 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11448 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11449 "Redistribute information from another routing protocol\n"
ab0181ee 11450 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11451 "Route map reference\n"
11452 "Pointer to route-map entries\n")
11453{
d62a17ae 11454 VTY_DECLVAR_CONTEXT(bgp, bgp);
11455 int idx_protocol = 1;
11456 int idx_word = 3;
11457 int type;
11458 struct bgp_redist *red;
718e3744 11459
d62a17ae 11460 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11461 if (type < 0) {
11462 vty_out(vty, "%% Invalid route type\n");
11463 return CMD_WARNING_CONFIG_FAILED;
11464 }
718e3744 11465
d62a17ae 11466 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11467 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11468 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11469}
11470
d62a17ae 11471ALIAS_HIDDEN(
11472 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11473 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11474 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11475 "Route map reference\n"
11476 "Pointer to route-map entries\n")
596c17ba 11477
718e3744 11478DEFUN (bgp_redistribute_ipv4_metric,
11479 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11480 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11481 "Redistribute information from another routing protocol\n"
ab0181ee 11482 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11483 "Metric for redistributed routes\n"
11484 "Default metric\n")
11485{
d62a17ae 11486 VTY_DECLVAR_CONTEXT(bgp, bgp);
11487 int idx_protocol = 1;
11488 int idx_number = 3;
11489 int type;
d7c0a89a 11490 uint32_t metric;
d62a17ae 11491 struct bgp_redist *red;
11492
11493 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11494 if (type < 0) {
11495 vty_out(vty, "%% Invalid route type\n");
11496 return CMD_WARNING_CONFIG_FAILED;
11497 }
11498 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11499
11500 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11501 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11502 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11503}
11504
11505ALIAS_HIDDEN(
11506 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11507 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11508 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11509 "Metric for redistributed routes\n"
11510 "Default metric\n")
596c17ba 11511
718e3744 11512DEFUN (bgp_redistribute_ipv4_rmap_metric,
11513 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11514 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11515 "Redistribute information from another routing protocol\n"
ab0181ee 11516 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11517 "Route map reference\n"
11518 "Pointer to route-map entries\n"
11519 "Metric for redistributed routes\n"
11520 "Default metric\n")
11521{
d62a17ae 11522 VTY_DECLVAR_CONTEXT(bgp, bgp);
11523 int idx_protocol = 1;
11524 int idx_word = 3;
11525 int idx_number = 5;
11526 int type;
d7c0a89a 11527 uint32_t metric;
d62a17ae 11528 struct bgp_redist *red;
11529
11530 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11531 if (type < 0) {
11532 vty_out(vty, "%% Invalid route type\n");
11533 return CMD_WARNING_CONFIG_FAILED;
11534 }
11535 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11536
11537 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11538 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11539 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11540 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11541}
11542
11543ALIAS_HIDDEN(
11544 bgp_redistribute_ipv4_rmap_metric,
11545 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11546 "redistribute " FRR_IP_REDIST_STR_BGPD
11547 " route-map WORD metric (0-4294967295)",
11548 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11549 "Route map reference\n"
11550 "Pointer to route-map entries\n"
11551 "Metric for redistributed routes\n"
11552 "Default metric\n")
596c17ba 11553
718e3744 11554DEFUN (bgp_redistribute_ipv4_metric_rmap,
11555 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11556 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11557 "Redistribute information from another routing protocol\n"
ab0181ee 11558 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11559 "Metric for redistributed routes\n"
11560 "Default metric\n"
11561 "Route map reference\n"
11562 "Pointer to route-map entries\n")
11563{
d62a17ae 11564 VTY_DECLVAR_CONTEXT(bgp, bgp);
11565 int idx_protocol = 1;
11566 int idx_number = 3;
11567 int idx_word = 5;
11568 int type;
d7c0a89a 11569 uint32_t metric;
d62a17ae 11570 struct bgp_redist *red;
11571
11572 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11573 if (type < 0) {
11574 vty_out(vty, "%% Invalid route type\n");
11575 return CMD_WARNING_CONFIG_FAILED;
11576 }
11577 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11578
11579 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11580 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11581 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11582 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11583}
11584
11585ALIAS_HIDDEN(
11586 bgp_redistribute_ipv4_metric_rmap,
11587 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11588 "redistribute " FRR_IP_REDIST_STR_BGPD
11589 " metric (0-4294967295) route-map WORD",
11590 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11591 "Metric for redistributed routes\n"
11592 "Default metric\n"
11593 "Route map reference\n"
11594 "Pointer to route-map entries\n")
596c17ba 11595
7c8ff89e
DS
11596DEFUN (bgp_redistribute_ipv4_ospf,
11597 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11598 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11599 "Redistribute information from another routing protocol\n"
11600 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11601 "Non-main Kernel Routing Table\n"
11602 "Instance ID/Table ID\n")
7c8ff89e 11603{
d62a17ae 11604 VTY_DECLVAR_CONTEXT(bgp, bgp);
11605 int idx_ospf_table = 1;
11606 int idx_number = 2;
d7c0a89a
QY
11607 unsigned short instance;
11608 unsigned short protocol;
7c8ff89e 11609
d62a17ae 11610 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11611
d62a17ae 11612 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11613 protocol = ZEBRA_ROUTE_OSPF;
11614 else
11615 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11616
d62a17ae 11617 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11618 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
11619}
11620
d62a17ae 11621ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11622 "redistribute <ospf|table> (1-65535)",
11623 "Redistribute information from another routing protocol\n"
11624 "Open Shortest Path First (OSPFv2)\n"
11625 "Non-main Kernel Routing Table\n"
11626 "Instance ID/Table ID\n")
596c17ba 11627
7c8ff89e
DS
11628DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11629 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11630 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11631 "Redistribute information from another routing protocol\n"
11632 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11633 "Non-main Kernel Routing Table\n"
11634 "Instance ID/Table ID\n"
7c8ff89e
DS
11635 "Route map reference\n"
11636 "Pointer to route-map entries\n")
11637{
d62a17ae 11638 VTY_DECLVAR_CONTEXT(bgp, bgp);
11639 int idx_ospf_table = 1;
11640 int idx_number = 2;
11641 int idx_word = 4;
11642 struct bgp_redist *red;
d7c0a89a 11643 unsigned short instance;
d62a17ae 11644 int protocol;
11645
11646 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11647 protocol = ZEBRA_ROUTE_OSPF;
11648 else
11649 protocol = ZEBRA_ROUTE_TABLE;
11650
11651 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11652 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11653 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11654 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11655}
11656
11657ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11658 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11659 "redistribute <ospf|table> (1-65535) route-map WORD",
11660 "Redistribute information from another routing protocol\n"
11661 "Open Shortest Path First (OSPFv2)\n"
11662 "Non-main Kernel Routing Table\n"
11663 "Instance ID/Table ID\n"
11664 "Route map reference\n"
11665 "Pointer to route-map entries\n")
596c17ba 11666
7c8ff89e
DS
11667DEFUN (bgp_redistribute_ipv4_ospf_metric,
11668 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 11669 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
11670 "Redistribute information from another routing protocol\n"
11671 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11672 "Non-main Kernel Routing Table\n"
11673 "Instance ID/Table ID\n"
7c8ff89e
DS
11674 "Metric for redistributed routes\n"
11675 "Default metric\n")
11676{
d62a17ae 11677 VTY_DECLVAR_CONTEXT(bgp, bgp);
11678 int idx_ospf_table = 1;
11679 int idx_number = 2;
11680 int idx_number_2 = 4;
d7c0a89a 11681 uint32_t metric;
d62a17ae 11682 struct bgp_redist *red;
d7c0a89a 11683 unsigned short instance;
d62a17ae 11684 int protocol;
11685
11686 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11687 protocol = ZEBRA_ROUTE_OSPF;
11688 else
11689 protocol = ZEBRA_ROUTE_TABLE;
11690
11691 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11692 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11693
11694 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11695 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11696 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11697}
11698
11699ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11700 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11701 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11702 "Redistribute information from another routing protocol\n"
11703 "Open Shortest Path First (OSPFv2)\n"
11704 "Non-main Kernel Routing Table\n"
11705 "Instance ID/Table ID\n"
11706 "Metric for redistributed routes\n"
11707 "Default metric\n")
596c17ba 11708
7c8ff89e
DS
11709DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11710 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 11711 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
11712 "Redistribute information from another routing protocol\n"
11713 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11714 "Non-main Kernel Routing Table\n"
11715 "Instance ID/Table ID\n"
7c8ff89e
DS
11716 "Route map reference\n"
11717 "Pointer to route-map entries\n"
11718 "Metric for redistributed routes\n"
11719 "Default metric\n")
11720{
d62a17ae 11721 VTY_DECLVAR_CONTEXT(bgp, bgp);
11722 int idx_ospf_table = 1;
11723 int idx_number = 2;
11724 int idx_word = 4;
11725 int idx_number_2 = 6;
d7c0a89a 11726 uint32_t metric;
d62a17ae 11727 struct bgp_redist *red;
d7c0a89a 11728 unsigned short instance;
d62a17ae 11729 int protocol;
11730
11731 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11732 protocol = ZEBRA_ROUTE_OSPF;
11733 else
11734 protocol = ZEBRA_ROUTE_TABLE;
11735
11736 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11737 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11738
11739 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11740 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11741 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11742 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11743}
11744
11745ALIAS_HIDDEN(
11746 bgp_redistribute_ipv4_ospf_rmap_metric,
11747 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11748 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11749 "Redistribute information from another routing protocol\n"
11750 "Open Shortest Path First (OSPFv2)\n"
11751 "Non-main Kernel Routing Table\n"
11752 "Instance ID/Table ID\n"
11753 "Route map reference\n"
11754 "Pointer to route-map entries\n"
11755 "Metric for redistributed routes\n"
11756 "Default metric\n")
596c17ba 11757
7c8ff89e
DS
11758DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11759 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 11760 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
11761 "Redistribute information from another routing protocol\n"
11762 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11763 "Non-main Kernel Routing Table\n"
11764 "Instance ID/Table ID\n"
7c8ff89e
DS
11765 "Metric for redistributed routes\n"
11766 "Default metric\n"
11767 "Route map reference\n"
11768 "Pointer to route-map entries\n")
11769{
d62a17ae 11770 VTY_DECLVAR_CONTEXT(bgp, bgp);
11771 int idx_ospf_table = 1;
11772 int idx_number = 2;
11773 int idx_number_2 = 4;
11774 int idx_word = 6;
d7c0a89a 11775 uint32_t metric;
d62a17ae 11776 struct bgp_redist *red;
d7c0a89a 11777 unsigned short instance;
d62a17ae 11778 int protocol;
11779
11780 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11781 protocol = ZEBRA_ROUTE_OSPF;
11782 else
11783 protocol = ZEBRA_ROUTE_TABLE;
11784
11785 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11786 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11787
11788 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11789 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11790 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11791 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11792}
11793
11794ALIAS_HIDDEN(
11795 bgp_redistribute_ipv4_ospf_metric_rmap,
11796 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11797 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11798 "Redistribute information from another routing protocol\n"
11799 "Open Shortest Path First (OSPFv2)\n"
11800 "Non-main Kernel Routing Table\n"
11801 "Instance ID/Table ID\n"
11802 "Metric for redistributed routes\n"
11803 "Default metric\n"
11804 "Route map reference\n"
11805 "Pointer to route-map entries\n")
596c17ba 11806
7c8ff89e
DS
11807DEFUN (no_bgp_redistribute_ipv4_ospf,
11808 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 11809 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
11810 NO_STR
11811 "Redistribute information from another routing protocol\n"
11812 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 11813 "Non-main Kernel Routing Table\n"
31500417
DW
11814 "Instance ID/Table ID\n"
11815 "Metric for redistributed routes\n"
11816 "Default metric\n"
11817 "Route map reference\n"
11818 "Pointer to route-map entries\n")
7c8ff89e 11819{
d62a17ae 11820 VTY_DECLVAR_CONTEXT(bgp, bgp);
11821 int idx_ospf_table = 2;
11822 int idx_number = 3;
d7c0a89a 11823 unsigned short instance;
d62a17ae 11824 int protocol;
11825
11826 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11827 protocol = ZEBRA_ROUTE_OSPF;
11828 else
11829 protocol = ZEBRA_ROUTE_TABLE;
11830
11831 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11832 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11833}
11834
11835ALIAS_HIDDEN(
11836 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11837 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11838 NO_STR
11839 "Redistribute information from another routing protocol\n"
11840 "Open Shortest Path First (OSPFv2)\n"
11841 "Non-main Kernel Routing Table\n"
11842 "Instance ID/Table ID\n"
11843 "Metric for redistributed routes\n"
11844 "Default metric\n"
11845 "Route map reference\n"
11846 "Pointer to route-map entries\n")
596c17ba 11847
718e3744 11848DEFUN (no_bgp_redistribute_ipv4,
11849 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 11850 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11851 NO_STR
11852 "Redistribute information from another routing protocol\n"
3b14d86e 11853 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
11854 "Metric for redistributed routes\n"
11855 "Default metric\n"
11856 "Route map reference\n"
11857 "Pointer to route-map entries\n")
718e3744 11858{
d62a17ae 11859 VTY_DECLVAR_CONTEXT(bgp, bgp);
11860 int idx_protocol = 2;
11861 int type;
11862
11863 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11864 if (type < 0) {
11865 vty_out(vty, "%% Invalid route type\n");
11866 return CMD_WARNING_CONFIG_FAILED;
11867 }
11868 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11869}
11870
11871ALIAS_HIDDEN(
11872 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11873 "no redistribute " FRR_IP_REDIST_STR_BGPD
11874 " [metric (0-4294967295)] [route-map WORD]",
11875 NO_STR
11876 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11877 "Metric for redistributed routes\n"
11878 "Default metric\n"
11879 "Route map reference\n"
11880 "Pointer to route-map entries\n")
596c17ba 11881
718e3744 11882DEFUN (bgp_redistribute_ipv6,
11883 bgp_redistribute_ipv6_cmd,
40d1cbfb 11884 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11885 "Redistribute information from another routing protocol\n"
ab0181ee 11886 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11887{
d62a17ae 11888 VTY_DECLVAR_CONTEXT(bgp, bgp);
11889 int idx_protocol = 1;
11890 int type;
718e3744 11891
d62a17ae 11892 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11893 if (type < 0) {
11894 vty_out(vty, "%% Invalid route type\n");
11895 return CMD_WARNING_CONFIG_FAILED;
11896 }
718e3744 11897
d62a17ae 11898 bgp_redist_add(bgp, AFI_IP6, type, 0);
11899 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11900}
11901
11902DEFUN (bgp_redistribute_ipv6_rmap,
11903 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11904 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11905 "Redistribute information from another routing protocol\n"
ab0181ee 11906 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11907 "Route map reference\n"
11908 "Pointer to route-map entries\n")
11909{
d62a17ae 11910 VTY_DECLVAR_CONTEXT(bgp, bgp);
11911 int idx_protocol = 1;
11912 int idx_word = 3;
11913 int type;
11914 struct bgp_redist *red;
718e3744 11915
d62a17ae 11916 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11917 if (type < 0) {
11918 vty_out(vty, "%% Invalid route type\n");
11919 return CMD_WARNING_CONFIG_FAILED;
11920 }
718e3744 11921
d62a17ae 11922 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11923 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11924 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11925}
11926
11927DEFUN (bgp_redistribute_ipv6_metric,
11928 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11929 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11930 "Redistribute information from another routing protocol\n"
ab0181ee 11931 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11932 "Metric for redistributed routes\n"
11933 "Default metric\n")
11934{
d62a17ae 11935 VTY_DECLVAR_CONTEXT(bgp, bgp);
11936 int idx_protocol = 1;
11937 int idx_number = 3;
11938 int type;
d7c0a89a 11939 uint32_t metric;
d62a17ae 11940 struct bgp_redist *red;
11941
11942 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11943 if (type < 0) {
11944 vty_out(vty, "%% Invalid route type\n");
11945 return CMD_WARNING_CONFIG_FAILED;
11946 }
11947 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11948
d62a17ae 11949 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11950 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11951 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11952}
11953
11954DEFUN (bgp_redistribute_ipv6_rmap_metric,
11955 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11956 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11957 "Redistribute information from another routing protocol\n"
ab0181ee 11958 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11959 "Route map reference\n"
11960 "Pointer to route-map entries\n"
11961 "Metric for redistributed routes\n"
11962 "Default metric\n")
11963{
d62a17ae 11964 VTY_DECLVAR_CONTEXT(bgp, bgp);
11965 int idx_protocol = 1;
11966 int idx_word = 3;
11967 int idx_number = 5;
11968 int type;
d7c0a89a 11969 uint32_t metric;
d62a17ae 11970 struct bgp_redist *red;
11971
11972 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11973 if (type < 0) {
11974 vty_out(vty, "%% Invalid route type\n");
11975 return CMD_WARNING_CONFIG_FAILED;
11976 }
11977 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11978
d62a17ae 11979 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11980 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11981 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11982 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11983}
11984
11985DEFUN (bgp_redistribute_ipv6_metric_rmap,
11986 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11987 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11988 "Redistribute information from another routing protocol\n"
ab0181ee 11989 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11990 "Metric for redistributed routes\n"
11991 "Default metric\n"
11992 "Route map reference\n"
11993 "Pointer to route-map entries\n")
11994{
d62a17ae 11995 VTY_DECLVAR_CONTEXT(bgp, bgp);
11996 int idx_protocol = 1;
11997 int idx_number = 3;
11998 int idx_word = 5;
11999 int type;
d7c0a89a 12000 uint32_t metric;
d62a17ae 12001 struct bgp_redist *red;
12002
12003 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12004 if (type < 0) {
12005 vty_out(vty, "%% Invalid route type\n");
12006 return CMD_WARNING_CONFIG_FAILED;
12007 }
12008 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12009
d62a17ae 12010 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12011 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
12012 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12013 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 12014}
12015
12016DEFUN (no_bgp_redistribute_ipv6,
12017 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 12018 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12019 NO_STR
12020 "Redistribute information from another routing protocol\n"
3b14d86e 12021 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12022 "Metric for redistributed routes\n"
12023 "Default metric\n"
12024 "Route map reference\n"
12025 "Pointer to route-map entries\n")
718e3744 12026{
d62a17ae 12027 VTY_DECLVAR_CONTEXT(bgp, bgp);
12028 int idx_protocol = 2;
12029 int type;
718e3744 12030
d62a17ae 12031 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12032 if (type < 0) {
12033 vty_out(vty, "%% Invalid route type\n");
12034 return CMD_WARNING_CONFIG_FAILED;
12035 }
718e3744 12036
d62a17ae 12037 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12038}
12039
2b791107 12040void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12041 safi_t safi)
d62a17ae 12042{
12043 int i;
12044
12045 /* Unicast redistribution only. */
12046 if (safi != SAFI_UNICAST)
2b791107 12047 return;
d62a17ae 12048
12049 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12050 /* Redistribute BGP does not make sense. */
12051 if (i != ZEBRA_ROUTE_BGP) {
12052 struct list *red_list;
12053 struct listnode *node;
12054 struct bgp_redist *red;
12055
12056 red_list = bgp->redist[afi][i];
12057 if (!red_list)
12058 continue;
12059
12060 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12061 /* "redistribute" configuration. */
12062 vty_out(vty, " redistribute %s",
12063 zebra_route_string(i));
12064 if (red->instance)
12065 vty_out(vty, " %d", red->instance);
12066 if (red->redist_metric_flag)
12067 vty_out(vty, " metric %u",
12068 red->redist_metric);
12069 if (red->rmap.name)
12070 vty_out(vty, " route-map %s",
12071 red->rmap.name);
12072 vty_out(vty, "\n");
12073 }
12074 }
12075 }
718e3744 12076}
6b0655a2 12077
b9c7bc5a
PZ
12078/* This is part of the address-family block (unicast only) */
12079void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12080 afi_t afi)
12081{
b9c7bc5a 12082 int indent = 2;
ddb5b488 12083
bb4f6190
DS
12084 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12085 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12086 bgp->vpn_policy[afi]
12087 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12088
12a844a5
DS
12089 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12090 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12091 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12092 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12093 return;
12094
e70e9f8e
PZ
12095 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12096 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12097
12098 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12099
12100 } else {
12101 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12102 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12103 bgp->vpn_policy[afi].tovpn_label);
12104 }
ddb5b488
PZ
12105 }
12106 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12107 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12108 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12109 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12110 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12111 sizeof(buf)));
12112 }
12113 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12114 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12115
12116 char buf[PREFIX_STRLEN];
12117 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12118 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12119 sizeof(buf))) {
12120
b9c7bc5a
PZ
12121 vty_out(vty, "%*snexthop vpn export %s\n",
12122 indent, "", buf);
ddb5b488
PZ
12123 }
12124 }
12125 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12126 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12127 && ecommunity_cmp(
12128 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12129 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12130
12131 char *b = ecommunity_ecom2str(
12132 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12133 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12134 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12135 XFREE(MTYPE_ECOMMUNITY_STR, b);
12136 } else {
12137 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12138 char *b = ecommunity_ecom2str(
12139 bgp->vpn_policy[afi]
12140 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12141 ECOMMUNITY_FORMAT_ROUTE_MAP,
12142 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12143 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12144 XFREE(MTYPE_ECOMMUNITY_STR, b);
12145 }
12146 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12147 char *b = ecommunity_ecom2str(
12148 bgp->vpn_policy[afi]
12149 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12150 ECOMMUNITY_FORMAT_ROUTE_MAP,
12151 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12152 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12153 XFREE(MTYPE_ECOMMUNITY_STR, b);
12154 }
12155 }
bb4f6190
DS
12156
12157 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12158 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12159 bgp->vpn_policy[afi]
12160 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12161
301ad80a
PG
12162 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12163 char *b = ecommunity_ecom2str(
12164 bgp->vpn_policy[afi]
12165 .import_redirect_rtlist,
12166 ECOMMUNITY_FORMAT_ROUTE_MAP,
12167 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12168
301ad80a
PG
12169 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12170 XFREE(MTYPE_ECOMMUNITY_STR, b);
12171 }
ddb5b488
PZ
12172}
12173
12174
718e3744 12175/* BGP node structure. */
d62a17ae 12176static struct cmd_node bgp_node = {
9d303b37 12177 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12178};
12179
d62a17ae 12180static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12181 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12182};
12183
d62a17ae 12184static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12185 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12186};
12187
d62a17ae 12188static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12189 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12190};
12191
d62a17ae 12192static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12193 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12194};
12195
d62a17ae 12196static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12197 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12198};
12199
d62a17ae 12200static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12201 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12202};
12203
d62a17ae 12204static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12205 "%s(config-router-af)# ", 1};
6b0655a2 12206
d62a17ae 12207static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12208 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12209
d62a17ae 12210static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12211 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12212
d62a17ae 12213static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12214 "%s(config-router-af-vni)# ", 1};
90e60aa7 12215
7c40bf39 12216static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12217 "%s(config-router-af)# ", 1};
12218
12219static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12220 "%s(config-router-af-vpnv6)# ", 1};
12221
d62a17ae 12222static void community_list_vty(void);
1f8ae70b 12223
d62a17ae 12224static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12225{
d62a17ae 12226 struct bgp *bgp;
12227 struct peer *peer;
d62a17ae 12228 struct listnode *lnbgp, *lnpeer;
b8a815e5 12229
d62a17ae 12230 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12231 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12232 /* only provide suggestions on the appropriate input
12233 * token type,
12234 * they'll otherwise show up multiple times */
12235 enum cmd_token_type match_type;
12236 char *name = peer->host;
d48ed3e0 12237
d62a17ae 12238 if (peer->conf_if) {
12239 match_type = VARIABLE_TKN;
12240 name = peer->conf_if;
12241 } else if (strchr(peer->host, ':'))
12242 match_type = IPV6_TKN;
12243 else
12244 match_type = IPV4_TKN;
d48ed3e0 12245
d62a17ae 12246 if (token->type != match_type)
12247 continue;
d48ed3e0 12248
d62a17ae 12249 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12250 }
d62a17ae 12251 }
b8a815e5
DL
12252}
12253
12254static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12255 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12256 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12257 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12258 {.completions = NULL}};
12259
47a306a0
DS
12260static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12261{
12262 struct bgp *bgp;
12263 struct peer_group *group;
12264 struct listnode *lnbgp, *lnpeer;
12265
12266 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12267 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12268 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12269 group->name));
12270 }
12271}
12272
12273static const struct cmd_variable_handler bgp_var_peergroup[] = {
12274 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12275 {.completions = NULL} };
12276
d62a17ae 12277void bgp_vty_init(void)
12278{
12279 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12280 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12281
12282 /* Install bgp top node. */
12283 install_node(&bgp_node, bgp_config_write);
12284 install_node(&bgp_ipv4_unicast_node, NULL);
12285 install_node(&bgp_ipv4_multicast_node, NULL);
12286 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12287 install_node(&bgp_ipv6_unicast_node, NULL);
12288 install_node(&bgp_ipv6_multicast_node, NULL);
12289 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12290 install_node(&bgp_vpnv4_node, NULL);
12291 install_node(&bgp_vpnv6_node, NULL);
12292 install_node(&bgp_evpn_node, NULL);
12293 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12294 install_node(&bgp_flowspecv4_node, NULL);
12295 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12296
12297 /* Install default VTY commands to new nodes. */
12298 install_default(BGP_NODE);
12299 install_default(BGP_IPV4_NODE);
12300 install_default(BGP_IPV4M_NODE);
12301 install_default(BGP_IPV4L_NODE);
12302 install_default(BGP_IPV6_NODE);
12303 install_default(BGP_IPV6M_NODE);
12304 install_default(BGP_IPV6L_NODE);
12305 install_default(BGP_VPNV4_NODE);
12306 install_default(BGP_VPNV6_NODE);
7c40bf39 12307 install_default(BGP_FLOWSPECV4_NODE);
12308 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12309 install_default(BGP_EVPN_NODE);
12310 install_default(BGP_EVPN_VNI_NODE);
12311
12312 /* "bgp multiple-instance" commands. */
12313 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12314 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12315
12316 /* "bgp config-type" commands. */
12317 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12318 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12319
12320 /* bgp route-map delay-timer commands. */
12321 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12322 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12323
12324 /* Dummy commands (Currently not supported) */
12325 install_element(BGP_NODE, &no_synchronization_cmd);
12326 install_element(BGP_NODE, &no_auto_summary_cmd);
12327
12328 /* "router bgp" commands. */
12329 install_element(CONFIG_NODE, &router_bgp_cmd);
12330
12331 /* "no router bgp" commands. */
12332 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12333
12334 /* "bgp router-id" commands. */
12335 install_element(BGP_NODE, &bgp_router_id_cmd);
12336 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12337
12338 /* "bgp cluster-id" commands. */
12339 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12340 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12341
12342 /* "bgp confederation" commands. */
12343 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12344 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12345
12346 /* "bgp confederation peers" commands. */
12347 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12348 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12349
12350 /* bgp max-med command */
12351 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12352 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12353 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12354 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12355 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12356
12357 /* bgp disable-ebgp-connected-nh-check */
12358 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12359 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12360
12361 /* bgp update-delay command */
12362 install_element(BGP_NODE, &bgp_update_delay_cmd);
12363 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12364 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12365
12366 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12367 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12368 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12369 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12370
12371 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12372 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12373
12374 /* "maximum-paths" commands. */
12375 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12376 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12377 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12378 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12379 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12380 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12381 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12382 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12383 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12384 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12385 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12386 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12387 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12388 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12389 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12390
12391 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12392 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12393 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12394 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12395 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12396
12397 /* "timers bgp" commands. */
12398 install_element(BGP_NODE, &bgp_timers_cmd);
12399 install_element(BGP_NODE, &no_bgp_timers_cmd);
12400
12401 /* route-map delay-timer commands - per instance for backwards compat.
12402 */
12403 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12404 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12405
12406 /* "bgp client-to-client reflection" commands */
12407 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12408 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12409
12410 /* "bgp always-compare-med" commands */
12411 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12412 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12413
12414 /* "bgp deterministic-med" commands */
12415 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12416 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12417
12418 /* "bgp graceful-restart" commands */
12419 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12420 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12421 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12422 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12423 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12424 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12425
12426 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12427 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12428
7f323236
DW
12429 /* "bgp graceful-shutdown" commands */
12430 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12431 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12432
d62a17ae 12433 /* "bgp fast-external-failover" commands */
12434 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12435 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12436
12437 /* "bgp enforce-first-as" commands */
12438 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
d62a17ae 12439
12440 /* "bgp bestpath compare-routerid" commands */
12441 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12442 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12443
12444 /* "bgp bestpath as-path ignore" commands */
12445 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12446 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12447
12448 /* "bgp bestpath as-path confed" commands */
12449 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12450 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12451
12452 /* "bgp bestpath as-path multipath-relax" commands */
12453 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12454 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12455
12456 /* "bgp log-neighbor-changes" commands */
12457 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12458 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12459
12460 /* "bgp bestpath med" commands */
12461 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12462 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12463
12464 /* "no bgp default ipv4-unicast" commands. */
12465 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12466 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12467
12468 /* "bgp network import-check" commands. */
12469 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12470 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12471 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12472
12473 /* "bgp default local-preference" commands. */
12474 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12475 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12476
12477 /* bgp default show-hostname */
12478 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12479 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12480
12481 /* "bgp default subgroup-pkt-queue-max" commands. */
12482 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12483 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12484
12485 /* bgp ibgp-allow-policy-mods command */
12486 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12487 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12488
12489 /* "bgp listen limit" commands. */
12490 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12491 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12492
12493 /* "bgp listen range" commands. */
12494 install_element(BGP_NODE, &bgp_listen_range_cmd);
12495 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12496
8175f54a 12497 /* "bgp default shutdown" command */
f26845f9
QY
12498 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12499
d62a17ae 12500 /* "neighbor remote-as" commands. */
12501 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12502 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12503 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12504 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12505 install_element(BGP_NODE,
12506 &neighbor_interface_v6only_config_remote_as_cmd);
12507 install_element(BGP_NODE, &no_neighbor_cmd);
12508 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12509
12510 /* "neighbor peer-group" commands. */
12511 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12512 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12513 install_element(BGP_NODE,
12514 &no_neighbor_interface_peer_group_remote_as_cmd);
12515
12516 /* "neighbor local-as" commands. */
12517 install_element(BGP_NODE, &neighbor_local_as_cmd);
12518 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12519 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12520 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12521
12522 /* "neighbor solo" commands. */
12523 install_element(BGP_NODE, &neighbor_solo_cmd);
12524 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12525
12526 /* "neighbor password" commands. */
12527 install_element(BGP_NODE, &neighbor_password_cmd);
12528 install_element(BGP_NODE, &no_neighbor_password_cmd);
12529
12530 /* "neighbor activate" commands. */
12531 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12532 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12533 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12534 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12535 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12536 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12537 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12538 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12539 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 12540 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12541 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 12542 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12543
12544 /* "no neighbor activate" commands. */
12545 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12546 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12547 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12548 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12549 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12550 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12551 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12552 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12553 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 12554 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12555 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 12556 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12557
12558 /* "neighbor peer-group" set commands. */
12559 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12560 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12561 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12562 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12563 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12564 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12565 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12566 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 12567 install_element(BGP_FLOWSPECV4_NODE,
12568 &neighbor_set_peer_group_hidden_cmd);
12569 install_element(BGP_FLOWSPECV6_NODE,
12570 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 12571
12572 /* "no neighbor peer-group unset" commands. */
12573 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12574 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12575 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12576 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12577 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12578 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12579 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12580 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 12581 install_element(BGP_FLOWSPECV4_NODE,
12582 &no_neighbor_set_peer_group_hidden_cmd);
12583 install_element(BGP_FLOWSPECV6_NODE,
12584 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 12585
12586 /* "neighbor softreconfiguration inbound" commands.*/
12587 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12588 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12589 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12590 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12591 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12592 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12593 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12594 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12595 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12596 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12597 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12598 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12599 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12600 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12601 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12602 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12603 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12604 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 12605 install_element(BGP_FLOWSPECV4_NODE,
12606 &neighbor_soft_reconfiguration_cmd);
12607 install_element(BGP_FLOWSPECV4_NODE,
12608 &no_neighbor_soft_reconfiguration_cmd);
12609 install_element(BGP_FLOWSPECV6_NODE,
12610 &neighbor_soft_reconfiguration_cmd);
12611 install_element(BGP_FLOWSPECV6_NODE,
12612 &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 12613
12614 /* "neighbor attribute-unchanged" commands. */
12615 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12616 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12617 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12618 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12619 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12620 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12621 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12622 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12623 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12624 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12625 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12626 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12627 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12628 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12629 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12630 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12631 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12632 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12633
12634 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12635 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12636
12637 /* "nexthop-local unchanged" commands */
12638 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12639 install_element(BGP_IPV6_NODE,
12640 &no_neighbor_nexthop_local_unchanged_cmd);
12641
12642 /* "neighbor next-hop-self" commands. */
12643 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12644 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12645 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12646 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12647 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12648 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12649 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12650 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12651 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12652 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12653 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12654 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12655 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12656 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12657 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12658 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12659 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12660 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
12661 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12662 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 12663
12664 /* "neighbor next-hop-self force" commands. */
12665 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12666 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12667 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12668 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12669 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12670 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12671 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12672 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12673 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12674 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12675 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12676 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12677 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12678 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12679 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12680 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12681 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12682 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12683
12684 /* "neighbor as-override" commands. */
12685 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12686 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12687 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12688 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12689 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12690 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12691 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12692 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12693 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12694 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12695 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12696 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12697 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12698 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12699 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12700 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12701 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12702 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12703
12704 /* "neighbor remove-private-AS" commands. */
12705 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12706 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12707 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12708 install_element(BGP_NODE,
12709 &no_neighbor_remove_private_as_all_hidden_cmd);
12710 install_element(BGP_NODE,
12711 &neighbor_remove_private_as_replace_as_hidden_cmd);
12712 install_element(BGP_NODE,
12713 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12714 install_element(BGP_NODE,
12715 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12716 install_element(
12717 BGP_NODE,
12718 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12719 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12720 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12721 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12722 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12723 install_element(BGP_IPV4_NODE,
12724 &neighbor_remove_private_as_replace_as_cmd);
12725 install_element(BGP_IPV4_NODE,
12726 &no_neighbor_remove_private_as_replace_as_cmd);
12727 install_element(BGP_IPV4_NODE,
12728 &neighbor_remove_private_as_all_replace_as_cmd);
12729 install_element(BGP_IPV4_NODE,
12730 &no_neighbor_remove_private_as_all_replace_as_cmd);
12731 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12732 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12733 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12734 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12735 install_element(BGP_IPV4M_NODE,
12736 &neighbor_remove_private_as_replace_as_cmd);
12737 install_element(BGP_IPV4M_NODE,
12738 &no_neighbor_remove_private_as_replace_as_cmd);
12739 install_element(BGP_IPV4M_NODE,
12740 &neighbor_remove_private_as_all_replace_as_cmd);
12741 install_element(BGP_IPV4M_NODE,
12742 &no_neighbor_remove_private_as_all_replace_as_cmd);
12743 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12744 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12745 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12746 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12747 install_element(BGP_IPV4L_NODE,
12748 &neighbor_remove_private_as_replace_as_cmd);
12749 install_element(BGP_IPV4L_NODE,
12750 &no_neighbor_remove_private_as_replace_as_cmd);
12751 install_element(BGP_IPV4L_NODE,
12752 &neighbor_remove_private_as_all_replace_as_cmd);
12753 install_element(BGP_IPV4L_NODE,
12754 &no_neighbor_remove_private_as_all_replace_as_cmd);
12755 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12756 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12757 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12758 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12759 install_element(BGP_IPV6_NODE,
12760 &neighbor_remove_private_as_replace_as_cmd);
12761 install_element(BGP_IPV6_NODE,
12762 &no_neighbor_remove_private_as_replace_as_cmd);
12763 install_element(BGP_IPV6_NODE,
12764 &neighbor_remove_private_as_all_replace_as_cmd);
12765 install_element(BGP_IPV6_NODE,
12766 &no_neighbor_remove_private_as_all_replace_as_cmd);
12767 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12768 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12769 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12770 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12771 install_element(BGP_IPV6M_NODE,
12772 &neighbor_remove_private_as_replace_as_cmd);
12773 install_element(BGP_IPV6M_NODE,
12774 &no_neighbor_remove_private_as_replace_as_cmd);
12775 install_element(BGP_IPV6M_NODE,
12776 &neighbor_remove_private_as_all_replace_as_cmd);
12777 install_element(BGP_IPV6M_NODE,
12778 &no_neighbor_remove_private_as_all_replace_as_cmd);
12779 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12780 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12781 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12782 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12783 install_element(BGP_IPV6L_NODE,
12784 &neighbor_remove_private_as_replace_as_cmd);
12785 install_element(BGP_IPV6L_NODE,
12786 &no_neighbor_remove_private_as_replace_as_cmd);
12787 install_element(BGP_IPV6L_NODE,
12788 &neighbor_remove_private_as_all_replace_as_cmd);
12789 install_element(BGP_IPV6L_NODE,
12790 &no_neighbor_remove_private_as_all_replace_as_cmd);
12791 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12792 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12793 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12794 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12795 install_element(BGP_VPNV4_NODE,
12796 &neighbor_remove_private_as_replace_as_cmd);
12797 install_element(BGP_VPNV4_NODE,
12798 &no_neighbor_remove_private_as_replace_as_cmd);
12799 install_element(BGP_VPNV4_NODE,
12800 &neighbor_remove_private_as_all_replace_as_cmd);
12801 install_element(BGP_VPNV4_NODE,
12802 &no_neighbor_remove_private_as_all_replace_as_cmd);
12803 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12804 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12805 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12806 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12807 install_element(BGP_VPNV6_NODE,
12808 &neighbor_remove_private_as_replace_as_cmd);
12809 install_element(BGP_VPNV6_NODE,
12810 &no_neighbor_remove_private_as_replace_as_cmd);
12811 install_element(BGP_VPNV6_NODE,
12812 &neighbor_remove_private_as_all_replace_as_cmd);
12813 install_element(BGP_VPNV6_NODE,
12814 &no_neighbor_remove_private_as_all_replace_as_cmd);
12815
12816 /* "neighbor send-community" commands.*/
12817 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12818 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12819 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12820 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12821 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12822 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12823 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12824 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12825 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12826 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12827 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12828 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12829 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12830 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12831 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12832 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12833 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12834 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12835 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12836 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12837 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12838 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12839 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12840 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12841 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12842 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12843 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12844 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12845 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12846 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12847 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12848 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12849 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12850 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12851 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12852 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12853
12854 /* "neighbor route-reflector" commands.*/
12855 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12856 install_element(BGP_NODE,
12857 &no_neighbor_route_reflector_client_hidden_cmd);
12858 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12859 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12860 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12861 install_element(BGP_IPV4M_NODE,
12862 &no_neighbor_route_reflector_client_cmd);
12863 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12864 install_element(BGP_IPV4L_NODE,
12865 &no_neighbor_route_reflector_client_cmd);
12866 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12867 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12868 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12869 install_element(BGP_IPV6M_NODE,
12870 &no_neighbor_route_reflector_client_cmd);
12871 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12872 install_element(BGP_IPV6L_NODE,
12873 &no_neighbor_route_reflector_client_cmd);
12874 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12875 install_element(BGP_VPNV4_NODE,
12876 &no_neighbor_route_reflector_client_cmd);
12877 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12878 install_element(BGP_VPNV6_NODE,
12879 &no_neighbor_route_reflector_client_cmd);
7c40bf39 12880 install_element(BGP_FLOWSPECV4_NODE,
12881 &neighbor_route_reflector_client_cmd);
12882 install_element(BGP_FLOWSPECV4_NODE,
12883 &no_neighbor_route_reflector_client_cmd);
12884 install_element(BGP_FLOWSPECV6_NODE,
12885 &neighbor_route_reflector_client_cmd);
12886 install_element(BGP_FLOWSPECV6_NODE,
12887 &no_neighbor_route_reflector_client_cmd);
d62a17ae 12888 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12889 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12890
12891 /* "neighbor route-server" commands.*/
12892 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12893 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12894 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12895 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12896 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12897 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12898 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12899 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12900 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12901 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12902 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12903 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12904 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12905 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12906 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12907 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12908 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12909 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 12910 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12911 install_element(BGP_FLOWSPECV4_NODE,
12912 &no_neighbor_route_server_client_cmd);
12913 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12914 install_element(BGP_FLOWSPECV6_NODE,
12915 &no_neighbor_route_server_client_cmd);
d62a17ae 12916
12917 /* "neighbor addpath-tx-all-paths" commands.*/
12918 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12919 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12920 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12921 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12922 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12923 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12924 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12925 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12926 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12927 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12928 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12929 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12930 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12931 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12932 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12933 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12934 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12935 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12936
12937 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12938 install_element(BGP_NODE,
12939 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12940 install_element(BGP_NODE,
12941 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12942 install_element(BGP_IPV4_NODE,
12943 &neighbor_addpath_tx_bestpath_per_as_cmd);
12944 install_element(BGP_IPV4_NODE,
12945 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12946 install_element(BGP_IPV4M_NODE,
12947 &neighbor_addpath_tx_bestpath_per_as_cmd);
12948 install_element(BGP_IPV4M_NODE,
12949 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12950 install_element(BGP_IPV4L_NODE,
12951 &neighbor_addpath_tx_bestpath_per_as_cmd);
12952 install_element(BGP_IPV4L_NODE,
12953 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12954 install_element(BGP_IPV6_NODE,
12955 &neighbor_addpath_tx_bestpath_per_as_cmd);
12956 install_element(BGP_IPV6_NODE,
12957 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12958 install_element(BGP_IPV6M_NODE,
12959 &neighbor_addpath_tx_bestpath_per_as_cmd);
12960 install_element(BGP_IPV6M_NODE,
12961 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12962 install_element(BGP_IPV6L_NODE,
12963 &neighbor_addpath_tx_bestpath_per_as_cmd);
12964 install_element(BGP_IPV6L_NODE,
12965 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12966 install_element(BGP_VPNV4_NODE,
12967 &neighbor_addpath_tx_bestpath_per_as_cmd);
12968 install_element(BGP_VPNV4_NODE,
12969 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12970 install_element(BGP_VPNV6_NODE,
12971 &neighbor_addpath_tx_bestpath_per_as_cmd);
12972 install_element(BGP_VPNV6_NODE,
12973 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12974
12975 /* "neighbor passive" commands. */
12976 install_element(BGP_NODE, &neighbor_passive_cmd);
12977 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12978
12979
12980 /* "neighbor shutdown" commands. */
12981 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12982 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12983 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12984 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12985
12986 /* "neighbor capability extended-nexthop" commands.*/
12987 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12988 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12989
12990 /* "neighbor capability orf prefix-list" commands.*/
12991 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12992 install_element(BGP_NODE,
12993 &no_neighbor_capability_orf_prefix_hidden_cmd);
12994 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12995 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12996 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
12997 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12998 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
12999 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13000 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13001 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13002 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13003 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13004 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13005 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13006
13007 /* "neighbor capability dynamic" commands.*/
13008 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13009 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13010
13011 /* "neighbor dont-capability-negotiate" commands. */
13012 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13013 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13014
13015 /* "neighbor ebgp-multihop" commands. */
13016 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13017 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13018 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13019
13020 /* "neighbor disable-connected-check" commands. */
13021 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13022 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13023
47cbc09b
PM
13024 /* "neighbor enforce-first-as" commands. */
13025 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13026 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13027
d62a17ae 13028 /* "neighbor description" commands. */
13029 install_element(BGP_NODE, &neighbor_description_cmd);
13030 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13031 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13032
13033 /* "neighbor update-source" commands. "*/
13034 install_element(BGP_NODE, &neighbor_update_source_cmd);
13035 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13036
13037 /* "neighbor default-originate" commands. */
13038 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13039 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13040 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13041 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13042 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13043 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13044 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13045 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13046 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13047 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13048 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13049 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13050 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13051 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13052 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13053 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13054 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13055 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13056 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13057 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13058 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13059
13060 /* "neighbor port" commands. */
13061 install_element(BGP_NODE, &neighbor_port_cmd);
13062 install_element(BGP_NODE, &no_neighbor_port_cmd);
13063
13064 /* "neighbor weight" commands. */
13065 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13066 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13067
13068 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13069 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13070 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13071 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13072 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13073 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13074 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13075 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13076 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13077 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13078 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13079 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13080 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13081 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13082 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13083 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13084
13085 /* "neighbor override-capability" commands. */
13086 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13087 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13088
13089 /* "neighbor strict-capability-match" commands. */
13090 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13091 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13092
13093 /* "neighbor timers" commands. */
13094 install_element(BGP_NODE, &neighbor_timers_cmd);
13095 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13096
13097 /* "neighbor timers connect" commands. */
13098 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13099 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13100
13101 /* "neighbor advertisement-interval" commands. */
13102 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13103 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13104
13105 /* "neighbor interface" commands. */
13106 install_element(BGP_NODE, &neighbor_interface_cmd);
13107 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13108
13109 /* "neighbor distribute" commands. */
13110 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13111 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13112 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13113 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13114 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13115 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13116 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13117 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13118 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13119 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13120 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13121 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13122 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13123 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13124 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13125 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13126 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13127 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13128
13129 /* "neighbor prefix-list" commands. */
13130 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13131 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13132 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13133 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13134 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13135 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13136 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13137 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13138 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13139 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13140 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13141 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13142 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13143 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13144 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13145 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13146 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13147 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13148 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13149 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13150 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13151 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13152
13153 /* "neighbor filter-list" commands. */
13154 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13155 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13156 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13157 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13158 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13159 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13160 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13161 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13162 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13163 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13164 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13165 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13166 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13167 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13168 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13169 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13170 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13171 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13172 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13173 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13174 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13175 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13176
13177 /* "neighbor route-map" commands. */
13178 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13179 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13180 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13181 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13182 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13183 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13184 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13185 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13186 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13187 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13188 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13189 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13190 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13191 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13192 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13193 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13194 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13195 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13196 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13197 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13198 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13199 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13200 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13201 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13202
13203 /* "neighbor unsuppress-map" commands. */
13204 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13205 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13206 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13207 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13208 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13209 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13210 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13211 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13212 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13213 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13214 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13215 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13216 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13217 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13218 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13219 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13220 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13221 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13222
13223 /* "neighbor maximum-prefix" commands. */
13224 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13225 install_element(BGP_NODE,
13226 &neighbor_maximum_prefix_threshold_hidden_cmd);
13227 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13228 install_element(BGP_NODE,
13229 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13230 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13231 install_element(BGP_NODE,
13232 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13233 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13234 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13235 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13236 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13237 install_element(BGP_IPV4_NODE,
13238 &neighbor_maximum_prefix_threshold_warning_cmd);
13239 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13240 install_element(BGP_IPV4_NODE,
13241 &neighbor_maximum_prefix_threshold_restart_cmd);
13242 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13243 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13244 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13245 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13246 install_element(BGP_IPV4M_NODE,
13247 &neighbor_maximum_prefix_threshold_warning_cmd);
13248 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13249 install_element(BGP_IPV4M_NODE,
13250 &neighbor_maximum_prefix_threshold_restart_cmd);
13251 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13252 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13253 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13254 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13255 install_element(BGP_IPV4L_NODE,
13256 &neighbor_maximum_prefix_threshold_warning_cmd);
13257 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13258 install_element(BGP_IPV4L_NODE,
13259 &neighbor_maximum_prefix_threshold_restart_cmd);
13260 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13261 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13262 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13263 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13264 install_element(BGP_IPV6_NODE,
13265 &neighbor_maximum_prefix_threshold_warning_cmd);
13266 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13267 install_element(BGP_IPV6_NODE,
13268 &neighbor_maximum_prefix_threshold_restart_cmd);
13269 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13270 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13271 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13272 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13273 install_element(BGP_IPV6M_NODE,
13274 &neighbor_maximum_prefix_threshold_warning_cmd);
13275 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13276 install_element(BGP_IPV6M_NODE,
13277 &neighbor_maximum_prefix_threshold_restart_cmd);
13278 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13279 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13280 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13281 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13282 install_element(BGP_IPV6L_NODE,
13283 &neighbor_maximum_prefix_threshold_warning_cmd);
13284 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13285 install_element(BGP_IPV6L_NODE,
13286 &neighbor_maximum_prefix_threshold_restart_cmd);
13287 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13288 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13289 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13290 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13291 install_element(BGP_VPNV4_NODE,
13292 &neighbor_maximum_prefix_threshold_warning_cmd);
13293 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13294 install_element(BGP_VPNV4_NODE,
13295 &neighbor_maximum_prefix_threshold_restart_cmd);
13296 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13297 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13298 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13299 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13300 install_element(BGP_VPNV6_NODE,
13301 &neighbor_maximum_prefix_threshold_warning_cmd);
13302 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13303 install_element(BGP_VPNV6_NODE,
13304 &neighbor_maximum_prefix_threshold_restart_cmd);
13305 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13306
13307 /* "neighbor allowas-in" */
13308 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13309 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13310 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13311 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13312 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13313 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13314 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13315 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13316 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13317 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13318 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13319 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13320 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13321 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13322 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13323 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13324 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13325 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13326 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13327 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13328
13329 /* address-family commands. */
13330 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13331 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13332#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13333 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13334 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13335#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13336
d62a17ae 13337 install_element(BGP_NODE, &address_family_evpn_cmd);
13338
13339 /* "exit-address-family" command. */
13340 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13341 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13342 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13343 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13344 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13345 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13346 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13347 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13348 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13349 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13350 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13351
13352 /* "clear ip bgp commands" */
13353 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13354
13355 /* clear ip bgp prefix */
13356 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13357 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13358 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13359
13360 /* "show [ip] bgp summary" commands. */
13361 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
d62a17ae 13362 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13363 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13364 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13365 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13366 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13367
13368 /* "show [ip] bgp neighbors" commands. */
13369 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13370
13371 /* "show [ip] bgp peer-group" commands. */
13372 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13373
13374 /* "show [ip] bgp paths" commands. */
13375 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13376
13377 /* "show [ip] bgp community" commands. */
13378 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13379
13380 /* "show ip bgp large-community" commands. */
13381 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13382 /* "show [ip] bgp attribute-info" commands. */
13383 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13384 /* "show [ip] bgp route-leak" command */
13385 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13386
13387 /* "redistribute" commands. */
13388 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13389 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13390 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13391 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13392 install_element(BGP_NODE,
13393 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13394 install_element(BGP_NODE,
13395 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13396 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13397 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13398 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13399 install_element(BGP_NODE,
13400 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13401 install_element(BGP_NODE,
13402 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13403 install_element(BGP_NODE,
13404 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13405 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13406 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13407 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13408 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13409 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13410 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13411 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13412 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13413 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13414 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13415 install_element(BGP_IPV4_NODE,
13416 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13417 install_element(BGP_IPV4_NODE,
13418 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13419 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13420 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13421 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13422 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13423 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13424 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13425
b9c7bc5a
PZ
13426 /* import|export vpn [route-map WORD] */
13427 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13428 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13429
12a844a5
DS
13430 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13431 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13432
d62a17ae 13433 /* ttl_security commands */
13434 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13435 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13436
13437 /* "show [ip] bgp memory" commands. */
13438 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13439
acf71666
MK
13440 /* "show bgp martian next-hop" */
13441 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13442
d62a17ae 13443 /* "show [ip] bgp views" commands. */
13444 install_element(VIEW_NODE, &show_bgp_views_cmd);
13445
13446 /* "show [ip] bgp vrfs" commands. */
13447 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13448
13449 /* Community-list. */
13450 community_list_vty();
ddb5b488
PZ
13451
13452 /* vpn-policy commands */
b9c7bc5a
PZ
13453 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13454 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13455 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13456 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13457 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13458 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13459 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13460 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13461 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13462 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
13463 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13464 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 13465
301ad80a
PG
13466 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13467 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13468
b9c7bc5a
PZ
13469 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13470 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13471 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13472 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13473 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13474 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13475 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13476 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13477 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13478 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
13479 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13480 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 13481}
6b0655a2 13482
718e3744 13483#include "memory.h"
13484#include "bgp_regex.h"
13485#include "bgp_clist.h"
13486#include "bgp_ecommunity.h"
13487
13488/* VTY functions. */
13489
13490/* Direction value to string conversion. */
d62a17ae 13491static const char *community_direct_str(int direct)
13492{
13493 switch (direct) {
13494 case COMMUNITY_DENY:
13495 return "deny";
13496 case COMMUNITY_PERMIT:
13497 return "permit";
13498 default:
13499 return "unknown";
13500 }
718e3744 13501}
13502
13503/* Display error string. */
d62a17ae 13504static void community_list_perror(struct vty *vty, int ret)
13505{
13506 switch (ret) {
13507 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13508 vty_out(vty, "%% Can't find community-list\n");
13509 break;
13510 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13511 vty_out(vty, "%% Malformed community-list value\n");
13512 break;
13513 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13514 vty_out(vty,
13515 "%% Community name conflict, previously defined as standard community\n");
13516 break;
13517 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13518 vty_out(vty,
13519 "%% Community name conflict, previously defined as expanded community\n");
13520 break;
13521 }
718e3744 13522}
13523
5bf15956
DW
13524/* "community-list" keyword help string. */
13525#define COMMUNITY_LIST_STR "Add a community list entry\n"
13526
5bf15956 13527/* ip community-list standard */
718e3744 13528DEFUN (ip_community_list_standard,
13529 ip_community_list_standard_cmd,
e961923c 13530 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13531 IP_STR
13532 COMMUNITY_LIST_STR
13533 "Community list number (standard)\n"
5bf15956 13534 "Add an standard community-list entry\n"
718e3744 13535 "Community list name\n"
13536 "Specify community to reject\n"
13537 "Specify community to accept\n"
13538 COMMUNITY_VAL_STR)
13539{
d62a17ae 13540 char *cl_name_or_number = NULL;
13541 int direct = 0;
13542 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13543
d62a17ae 13544 int idx = 0;
13545 argv_find(argv, argc, "(1-99)", &idx);
13546 argv_find(argv, argc, "WORD", &idx);
13547 cl_name_or_number = argv[idx]->arg;
13548 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13549 : COMMUNITY_DENY;
13550 argv_find(argv, argc, "AA:NN", &idx);
13551 char *str = argv_concat(argv, argc, idx);
42f914d4 13552
d62a17ae 13553 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13554 style);
42f914d4 13555
d62a17ae 13556 XFREE(MTYPE_TMP, str);
42f914d4 13557
d62a17ae 13558 if (ret < 0) {
13559 /* Display error string. */
13560 community_list_perror(vty, ret);
13561 return CMD_WARNING_CONFIG_FAILED;
13562 }
42f914d4 13563
d62a17ae 13564 return CMD_SUCCESS;
718e3744 13565}
13566
fee6e4e4 13567DEFUN (no_ip_community_list_standard_all,
13568 no_ip_community_list_standard_all_cmd,
e961923c 13569 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13570 NO_STR
13571 IP_STR
13572 COMMUNITY_LIST_STR
13573 "Community list number (standard)\n"
5bf15956
DW
13574 "Add an standard community-list entry\n"
13575 "Community list name\n"
718e3744 13576 "Specify community to reject\n"
13577 "Specify community to accept\n"
13578 COMMUNITY_VAL_STR)
13579{
d62a17ae 13580 char *cl_name_or_number = NULL;
13581 int direct = 0;
13582 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13583
d62a17ae 13584 int idx = 0;
13585 argv_find(argv, argc, "(1-99)", &idx);
13586 argv_find(argv, argc, "WORD", &idx);
13587 cl_name_or_number = argv[idx]->arg;
13588 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13589 : COMMUNITY_DENY;
13590 argv_find(argv, argc, "AA:NN", &idx);
13591 char *str = argv_concat(argv, argc, idx);
42f914d4 13592
d62a17ae 13593 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13594 direct, style);
42f914d4 13595
d62a17ae 13596 XFREE(MTYPE_TMP, str);
daf9ddbb 13597
d62a17ae 13598 if (ret < 0) {
13599 community_list_perror(vty, ret);
13600 return CMD_WARNING_CONFIG_FAILED;
13601 }
42f914d4 13602
d62a17ae 13603 return CMD_SUCCESS;
718e3744 13604}
13605
5bf15956
DW
13606/* ip community-list expanded */
13607DEFUN (ip_community_list_expanded_all,
13608 ip_community_list_expanded_all_cmd,
42f914d4 13609 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13610 IP_STR
13611 COMMUNITY_LIST_STR
13612 "Community list number (expanded)\n"
5bf15956 13613 "Add an expanded community-list entry\n"
718e3744 13614 "Community list name\n"
13615 "Specify community to reject\n"
13616 "Specify community to accept\n"
13617 COMMUNITY_VAL_STR)
13618{
d62a17ae 13619 char *cl_name_or_number = NULL;
13620 int direct = 0;
13621 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13622
d62a17ae 13623 int idx = 0;
13624 argv_find(argv, argc, "(100-500)", &idx);
13625 argv_find(argv, argc, "WORD", &idx);
13626 cl_name_or_number = argv[idx]->arg;
13627 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13628 : COMMUNITY_DENY;
13629 argv_find(argv, argc, "AA:NN", &idx);
13630 char *str = argv_concat(argv, argc, idx);
42f914d4 13631
d62a17ae 13632 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13633 style);
42f914d4 13634
d62a17ae 13635 XFREE(MTYPE_TMP, str);
42f914d4 13636
d62a17ae 13637 if (ret < 0) {
13638 /* Display error string. */
13639 community_list_perror(vty, ret);
13640 return CMD_WARNING_CONFIG_FAILED;
13641 }
42f914d4 13642
d62a17ae 13643 return CMD_SUCCESS;
718e3744 13644}
13645
5bf15956
DW
13646DEFUN (no_ip_community_list_expanded_all,
13647 no_ip_community_list_expanded_all_cmd,
42f914d4 13648 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13649 NO_STR
13650 IP_STR
13651 COMMUNITY_LIST_STR
5bf15956
DW
13652 "Community list number (expanded)\n"
13653 "Add an expanded community-list entry\n"
718e3744 13654 "Community list name\n"
13655 "Specify community to reject\n"
13656 "Specify community to accept\n"
5bf15956 13657 COMMUNITY_VAL_STR)
718e3744 13658{
d62a17ae 13659 char *cl_name_or_number = NULL;
13660 int direct = 0;
13661 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13662
d62a17ae 13663 int idx = 0;
13664 argv_find(argv, argc, "(100-500)", &idx);
13665 argv_find(argv, argc, "WORD", &idx);
13666 cl_name_or_number = argv[idx]->arg;
13667 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13668 : COMMUNITY_DENY;
13669 argv_find(argv, argc, "AA:NN", &idx);
13670 char *str = argv_concat(argv, argc, idx);
42f914d4 13671
d62a17ae 13672 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13673 direct, style);
42f914d4 13674
d62a17ae 13675 XFREE(MTYPE_TMP, str);
daf9ddbb 13676
d62a17ae 13677 if (ret < 0) {
13678 community_list_perror(vty, ret);
13679 return CMD_WARNING_CONFIG_FAILED;
13680 }
42f914d4 13681
d62a17ae 13682 return CMD_SUCCESS;
718e3744 13683}
13684
8d9b8ed9
PM
13685/* Return configuration string of community-list entry. */
13686static const char *community_list_config_str(struct community_entry *entry)
13687{
13688 const char *str;
13689
13690 if (entry->any)
13691 str = "";
13692 else {
13693 if (entry->style == COMMUNITY_LIST_STANDARD)
13694 str = community_str(entry->u.com, false);
13695 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13696 str = lcommunity_str(entry->u.lcom, false);
13697 else
13698 str = entry->config;
13699 }
13700 return str;
13701}
13702
d62a17ae 13703static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 13704{
d62a17ae 13705 struct community_entry *entry;
718e3744 13706
d62a17ae 13707 for (entry = list->head; entry; entry = entry->next) {
13708 if (entry == list->head) {
13709 if (all_digit(list->name))
13710 vty_out(vty, "Community %s list %s\n",
13711 entry->style == COMMUNITY_LIST_STANDARD
13712 ? "standard"
13713 : "(expanded) access",
13714 list->name);
13715 else
13716 vty_out(vty, "Named Community %s list %s\n",
13717 entry->style == COMMUNITY_LIST_STANDARD
13718 ? "standard"
13719 : "expanded",
13720 list->name);
13721 }
13722 if (entry->any)
13723 vty_out(vty, " %s\n",
13724 community_direct_str(entry->direct));
13725 else
13726 vty_out(vty, " %s %s\n",
13727 community_direct_str(entry->direct),
8d9b8ed9 13728 community_list_config_str(entry));
d62a17ae 13729 }
718e3744 13730}
13731
13732DEFUN (show_ip_community_list,
13733 show_ip_community_list_cmd,
13734 "show ip community-list",
13735 SHOW_STR
13736 IP_STR
13737 "List community-list\n")
13738{
d62a17ae 13739 struct community_list *list;
13740 struct community_list_master *cm;
718e3744 13741
d62a17ae 13742 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13743 if (!cm)
13744 return CMD_SUCCESS;
718e3744 13745
d62a17ae 13746 for (list = cm->num.head; list; list = list->next)
13747 community_list_show(vty, list);
718e3744 13748
d62a17ae 13749 for (list = cm->str.head; list; list = list->next)
13750 community_list_show(vty, list);
718e3744 13751
d62a17ae 13752 return CMD_SUCCESS;
718e3744 13753}
13754
13755DEFUN (show_ip_community_list_arg,
13756 show_ip_community_list_arg_cmd,
6147e2c6 13757 "show ip community-list <(1-500)|WORD>",
718e3744 13758 SHOW_STR
13759 IP_STR
13760 "List community-list\n"
13761 "Community-list number\n"
13762 "Community-list name\n")
13763{
d62a17ae 13764 int idx_comm_list = 3;
13765 struct community_list *list;
718e3744 13766
d62a17ae 13767 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13768 COMMUNITY_LIST_MASTER);
13769 if (!list) {
13770 vty_out(vty, "%% Can't find community-list\n");
13771 return CMD_WARNING;
13772 }
718e3744 13773
d62a17ae 13774 community_list_show(vty, list);
718e3744 13775
d62a17ae 13776 return CMD_SUCCESS;
718e3744 13777}
6b0655a2 13778
57d187bc
JS
13779/*
13780 * Large Community code.
13781 */
d62a17ae 13782static int lcommunity_list_set_vty(struct vty *vty, int argc,
13783 struct cmd_token **argv, int style,
13784 int reject_all_digit_name)
13785{
13786 int ret;
13787 int direct;
13788 char *str;
13789 int idx = 0;
13790 char *cl_name;
13791
13792 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13793 : COMMUNITY_DENY;
13794
13795 /* All digit name check. */
13796 idx = 0;
13797 argv_find(argv, argc, "WORD", &idx);
13798 argv_find(argv, argc, "(1-99)", &idx);
13799 argv_find(argv, argc, "(100-500)", &idx);
13800 cl_name = argv[idx]->arg;
13801 if (reject_all_digit_name && all_digit(cl_name)) {
13802 vty_out(vty, "%% Community name cannot have all digits\n");
13803 return CMD_WARNING_CONFIG_FAILED;
13804 }
13805
13806 idx = 0;
13807 argv_find(argv, argc, "AA:BB:CC", &idx);
13808 argv_find(argv, argc, "LINE", &idx);
13809 /* Concat community string argument. */
13810 if (idx)
13811 str = argv_concat(argv, argc, idx);
13812 else
13813 str = NULL;
13814
13815 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13816
13817 /* Free temporary community list string allocated by
13818 argv_concat(). */
13819 if (str)
13820 XFREE(MTYPE_TMP, str);
13821
13822 if (ret < 0) {
13823 community_list_perror(vty, ret);
13824 return CMD_WARNING_CONFIG_FAILED;
13825 }
13826 return CMD_SUCCESS;
13827}
13828
13829static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13830 struct cmd_token **argv, int style)
13831{
13832 int ret;
13833 int direct = 0;
13834 char *str = NULL;
13835 int idx = 0;
13836
13837 argv_find(argv, argc, "permit", &idx);
13838 argv_find(argv, argc, "deny", &idx);
13839
13840 if (idx) {
13841 /* Check the list direct. */
13842 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13843 direct = COMMUNITY_PERMIT;
13844 else
13845 direct = COMMUNITY_DENY;
13846
13847 idx = 0;
13848 argv_find(argv, argc, "LINE", &idx);
13849 argv_find(argv, argc, "AA:AA:NN", &idx);
13850 /* Concat community string argument. */
13851 str = argv_concat(argv, argc, idx);
13852 }
13853
13854 idx = 0;
13855 argv_find(argv, argc, "(1-99)", &idx);
13856 argv_find(argv, argc, "(100-500)", &idx);
13857 argv_find(argv, argc, "WORD", &idx);
13858
13859 /* Unset community list. */
13860 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13861 style);
13862
13863 /* Free temporary community list string allocated by
13864 argv_concat(). */
13865 if (str)
13866 XFREE(MTYPE_TMP, str);
13867
13868 if (ret < 0) {
13869 community_list_perror(vty, ret);
13870 return CMD_WARNING_CONFIG_FAILED;
13871 }
13872
13873 return CMD_SUCCESS;
57d187bc
JS
13874}
13875
13876/* "large-community-list" keyword help string. */
13877#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13878#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13879
13880DEFUN (ip_lcommunity_list_standard,
13881 ip_lcommunity_list_standard_cmd,
52951b63
DS
13882 "ip large-community-list (1-99) <deny|permit>",
13883 IP_STR
13884 LCOMMUNITY_LIST_STR
13885 "Large Community list number (standard)\n"
13886 "Specify large community to reject\n"
7111c1a0 13887 "Specify large community to accept\n")
52951b63 13888{
d62a17ae 13889 return lcommunity_list_set_vty(vty, argc, argv,
13890 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
13891}
13892
13893DEFUN (ip_lcommunity_list_standard1,
13894 ip_lcommunity_list_standard1_cmd,
13895 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
13896 IP_STR
13897 LCOMMUNITY_LIST_STR
13898 "Large Community list number (standard)\n"
13899 "Specify large community to reject\n"
13900 "Specify large community to accept\n"
13901 LCOMMUNITY_VAL_STR)
13902{
d62a17ae 13903 return lcommunity_list_set_vty(vty, argc, argv,
13904 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
13905}
13906
13907DEFUN (ip_lcommunity_list_expanded,
13908 ip_lcommunity_list_expanded_cmd,
13909 "ip large-community-list (100-500) <deny|permit> LINE...",
13910 IP_STR
13911 LCOMMUNITY_LIST_STR
13912 "Large Community list number (expanded)\n"
13913 "Specify large community to reject\n"
13914 "Specify large community to accept\n"
13915 "An ordered list as a regular-expression\n")
13916{
d62a17ae 13917 return lcommunity_list_set_vty(vty, argc, argv,
13918 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
13919}
13920
13921DEFUN (ip_lcommunity_list_name_standard,
13922 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
13923 "ip large-community-list standard WORD <deny|permit>",
13924 IP_STR
13925 LCOMMUNITY_LIST_STR
13926 "Specify standard large-community-list\n"
13927 "Large Community list name\n"
13928 "Specify large community to reject\n"
13929 "Specify large community to accept\n")
13930{
d62a17ae 13931 return lcommunity_list_set_vty(vty, argc, argv,
13932 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
13933}
13934
13935DEFUN (ip_lcommunity_list_name_standard1,
13936 ip_lcommunity_list_name_standard1_cmd,
13937 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
13938 IP_STR
13939 LCOMMUNITY_LIST_STR
13940 "Specify standard large-community-list\n"
13941 "Large Community list name\n"
13942 "Specify large community to reject\n"
13943 "Specify large community to accept\n"
13944 LCOMMUNITY_VAL_STR)
13945{
d62a17ae 13946 return lcommunity_list_set_vty(vty, argc, argv,
13947 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
13948}
13949
13950DEFUN (ip_lcommunity_list_name_expanded,
13951 ip_lcommunity_list_name_expanded_cmd,
13952 "ip large-community-list expanded WORD <deny|permit> LINE...",
13953 IP_STR
13954 LCOMMUNITY_LIST_STR
13955 "Specify expanded large-community-list\n"
13956 "Large Community list name\n"
13957 "Specify large community to reject\n"
13958 "Specify large community to accept\n"
13959 "An ordered list as a regular-expression\n")
13960{
d62a17ae 13961 return lcommunity_list_set_vty(vty, argc, argv,
13962 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
13963}
13964
13965DEFUN (no_ip_lcommunity_list_standard_all,
13966 no_ip_lcommunity_list_standard_all_cmd,
13967 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13968 NO_STR
13969 IP_STR
13970 LCOMMUNITY_LIST_STR
13971 "Large Community list number (standard)\n"
13972 "Large Community list number (expanded)\n"
13973 "Large Community list name\n")
13974{
d62a17ae 13975 return lcommunity_list_unset_vty(vty, argc, argv,
13976 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13977}
13978
13979DEFUN (no_ip_lcommunity_list_name_expanded_all,
13980 no_ip_lcommunity_list_name_expanded_all_cmd,
13981 "no ip large-community-list expanded WORD",
13982 NO_STR
13983 IP_STR
13984 LCOMMUNITY_LIST_STR
13985 "Specify expanded large-community-list\n"
13986 "Large Community list name\n")
13987{
d62a17ae 13988 return lcommunity_list_unset_vty(vty, argc, argv,
13989 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13990}
13991
13992DEFUN (no_ip_lcommunity_list_standard,
13993 no_ip_lcommunity_list_standard_cmd,
13994 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13995 NO_STR
13996 IP_STR
13997 LCOMMUNITY_LIST_STR
13998 "Large Community list number (standard)\n"
13999 "Specify large community to reject\n"
14000 "Specify large community to accept\n"
14001 LCOMMUNITY_VAL_STR)
14002{
d62a17ae 14003 return lcommunity_list_unset_vty(vty, argc, argv,
14004 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14005}
14006
14007DEFUN (no_ip_lcommunity_list_expanded,
14008 no_ip_lcommunity_list_expanded_cmd,
14009 "no ip large-community-list (100-500) <deny|permit> LINE...",
14010 NO_STR
14011 IP_STR
14012 LCOMMUNITY_LIST_STR
14013 "Large Community list number (expanded)\n"
14014 "Specify large community to reject\n"
14015 "Specify large community to accept\n"
14016 "An ordered list as a regular-expression\n")
14017{
d62a17ae 14018 return lcommunity_list_unset_vty(vty, argc, argv,
14019 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14020}
14021
14022DEFUN (no_ip_lcommunity_list_name_standard,
14023 no_ip_lcommunity_list_name_standard_cmd,
14024 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14025 NO_STR
14026 IP_STR
14027 LCOMMUNITY_LIST_STR
14028 "Specify standard large-community-list\n"
14029 "Large Community list name\n"
14030 "Specify large community to reject\n"
14031 "Specify large community to accept\n"
14032 LCOMMUNITY_VAL_STR)
14033{
d62a17ae 14034 return lcommunity_list_unset_vty(vty, argc, argv,
14035 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14036}
14037
14038DEFUN (no_ip_lcommunity_list_name_expanded,
14039 no_ip_lcommunity_list_name_expanded_cmd,
14040 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14041 NO_STR
14042 IP_STR
14043 LCOMMUNITY_LIST_STR
14044 "Specify expanded large-community-list\n"
14045 "Large community list name\n"
14046 "Specify large community to reject\n"
14047 "Specify large community to accept\n"
14048 "An ordered list as a regular-expression\n")
14049{
d62a17ae 14050 return lcommunity_list_unset_vty(vty, argc, argv,
14051 LARGE_COMMUNITY_LIST_EXPANDED);
14052}
14053
14054static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14055{
14056 struct community_entry *entry;
14057
14058 for (entry = list->head; entry; entry = entry->next) {
14059 if (entry == list->head) {
14060 if (all_digit(list->name))
14061 vty_out(vty, "Large community %s list %s\n",
14062 entry->style == EXTCOMMUNITY_LIST_STANDARD
14063 ? "standard"
14064 : "(expanded) access",
14065 list->name);
14066 else
14067 vty_out(vty,
14068 "Named large community %s list %s\n",
14069 entry->style == EXTCOMMUNITY_LIST_STANDARD
14070 ? "standard"
14071 : "expanded",
14072 list->name);
14073 }
14074 if (entry->any)
14075 vty_out(vty, " %s\n",
14076 community_direct_str(entry->direct));
14077 else
14078 vty_out(vty, " %s %s\n",
14079 community_direct_str(entry->direct),
8d9b8ed9 14080 community_list_config_str(entry));
d62a17ae 14081 }
57d187bc
JS
14082}
14083
14084DEFUN (show_ip_lcommunity_list,
14085 show_ip_lcommunity_list_cmd,
14086 "show ip large-community-list",
14087 SHOW_STR
14088 IP_STR
14089 "List large-community list\n")
14090{
d62a17ae 14091 struct community_list *list;
14092 struct community_list_master *cm;
57d187bc 14093
d62a17ae 14094 cm = community_list_master_lookup(bgp_clist,
14095 LARGE_COMMUNITY_LIST_MASTER);
14096 if (!cm)
14097 return CMD_SUCCESS;
57d187bc 14098
d62a17ae 14099 for (list = cm->num.head; list; list = list->next)
14100 lcommunity_list_show(vty, list);
57d187bc 14101
d62a17ae 14102 for (list = cm->str.head; list; list = list->next)
14103 lcommunity_list_show(vty, list);
57d187bc 14104
d62a17ae 14105 return CMD_SUCCESS;
57d187bc
JS
14106}
14107
14108DEFUN (show_ip_lcommunity_list_arg,
14109 show_ip_lcommunity_list_arg_cmd,
14110 "show ip large-community-list <(1-500)|WORD>",
14111 SHOW_STR
14112 IP_STR
14113 "List large-community list\n"
14114 "large-community-list number\n"
14115 "large-community-list name\n")
14116{
d62a17ae 14117 struct community_list *list;
57d187bc 14118
d62a17ae 14119 list = community_list_lookup(bgp_clist, argv[3]->arg,
14120 LARGE_COMMUNITY_LIST_MASTER);
14121 if (!list) {
14122 vty_out(vty, "%% Can't find extcommunity-list\n");
14123 return CMD_WARNING;
14124 }
57d187bc 14125
d62a17ae 14126 lcommunity_list_show(vty, list);
57d187bc 14127
d62a17ae 14128 return CMD_SUCCESS;
57d187bc
JS
14129}
14130
718e3744 14131/* "extcommunity-list" keyword help string. */
14132#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14133#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14134
14135DEFUN (ip_extcommunity_list_standard,
14136 ip_extcommunity_list_standard_cmd,
e961923c 14137 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14138 IP_STR
14139 EXTCOMMUNITY_LIST_STR
14140 "Extended Community list number (standard)\n"
718e3744 14141 "Specify standard extcommunity-list\n"
5bf15956 14142 "Community list name\n"
718e3744 14143 "Specify community to reject\n"
14144 "Specify community to accept\n"
14145 EXTCOMMUNITY_VAL_STR)
14146{
d62a17ae 14147 int style = EXTCOMMUNITY_LIST_STANDARD;
14148 int direct = 0;
14149 char *cl_number_or_name = NULL;
42f914d4 14150
d62a17ae 14151 int idx = 0;
14152 argv_find(argv, argc, "(1-99)", &idx);
14153 argv_find(argv, argc, "WORD", &idx);
14154 cl_number_or_name = argv[idx]->arg;
14155 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14156 : COMMUNITY_DENY;
14157 argv_find(argv, argc, "AA:NN", &idx);
14158 char *str = argv_concat(argv, argc, idx);
42f914d4 14159
d62a17ae 14160 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14161 direct, style);
42f914d4 14162
d62a17ae 14163 XFREE(MTYPE_TMP, str);
42f914d4 14164
d62a17ae 14165 if (ret < 0) {
14166 community_list_perror(vty, ret);
14167 return CMD_WARNING_CONFIG_FAILED;
14168 }
42f914d4 14169
d62a17ae 14170 return CMD_SUCCESS;
718e3744 14171}
14172
718e3744 14173DEFUN (ip_extcommunity_list_name_expanded,
14174 ip_extcommunity_list_name_expanded_cmd,
e961923c 14175 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14176 IP_STR
14177 EXTCOMMUNITY_LIST_STR
5bf15956 14178 "Extended Community list number (expanded)\n"
718e3744 14179 "Specify expanded extcommunity-list\n"
14180 "Extended Community list name\n"
14181 "Specify community to reject\n"
14182 "Specify community to accept\n"
14183 "An ordered list as a regular-expression\n")
14184{
d62a17ae 14185 int style = EXTCOMMUNITY_LIST_EXPANDED;
14186 int direct = 0;
14187 char *cl_number_or_name = NULL;
42f914d4 14188
d62a17ae 14189 int idx = 0;
14190 argv_find(argv, argc, "(100-500)", &idx);
14191 argv_find(argv, argc, "WORD", &idx);
14192 cl_number_or_name = argv[idx]->arg;
14193 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14194 : COMMUNITY_DENY;
14195 argv_find(argv, argc, "LINE", &idx);
14196 char *str = argv_concat(argv, argc, idx);
42f914d4 14197
d62a17ae 14198 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14199 direct, style);
42f914d4 14200
d62a17ae 14201 XFREE(MTYPE_TMP, str);
42f914d4 14202
d62a17ae 14203 if (ret < 0) {
14204 community_list_perror(vty, ret);
14205 return CMD_WARNING_CONFIG_FAILED;
14206 }
42f914d4 14207
d62a17ae 14208 return CMD_SUCCESS;
718e3744 14209}
14210
fee6e4e4 14211DEFUN (no_ip_extcommunity_list_standard_all,
14212 no_ip_extcommunity_list_standard_all_cmd,
e961923c 14213 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
14214 NO_STR
14215 IP_STR
14216 EXTCOMMUNITY_LIST_STR
14217 "Extended Community list number (standard)\n"
718e3744 14218 "Specify standard extcommunity-list\n"
5bf15956 14219 "Community list name\n"
718e3744 14220 "Specify community to reject\n"
14221 "Specify community to accept\n"
14222 EXTCOMMUNITY_VAL_STR)
14223{
d62a17ae 14224 int style = EXTCOMMUNITY_LIST_STANDARD;
14225 int direct = 0;
14226 char *cl_number_or_name = NULL;
42f914d4 14227
d62a17ae 14228 int idx = 0;
14229 argv_find(argv, argc, "(1-99)", &idx);
14230 argv_find(argv, argc, "WORD", &idx);
14231 cl_number_or_name = argv[idx]->arg;
14232 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14233 : COMMUNITY_DENY;
14234 argv_find(argv, argc, "AA:NN", &idx);
14235 char *str = argv_concat(argv, argc, idx);
42f914d4 14236
d62a17ae 14237 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14238 direct, style);
42f914d4 14239
d62a17ae 14240 XFREE(MTYPE_TMP, str);
42f914d4 14241
d62a17ae 14242 if (ret < 0) {
14243 community_list_perror(vty, ret);
14244 return CMD_WARNING_CONFIG_FAILED;
14245 }
42f914d4 14246
d62a17ae 14247 return CMD_SUCCESS;
718e3744 14248}
14249
5bf15956
DW
14250DEFUN (no_ip_extcommunity_list_expanded_all,
14251 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 14252 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14253 NO_STR
14254 IP_STR
14255 EXTCOMMUNITY_LIST_STR
14256 "Extended Community list number (expanded)\n"
718e3744 14257 "Specify expanded extcommunity-list\n"
5bf15956 14258 "Extended Community list name\n"
718e3744 14259 "Specify community to reject\n"
14260 "Specify community to accept\n"
14261 "An ordered list as a regular-expression\n")
14262{
d62a17ae 14263 int style = EXTCOMMUNITY_LIST_EXPANDED;
14264 int direct = 0;
14265 char *cl_number_or_name = NULL;
42f914d4 14266
d62a17ae 14267 int idx = 0;
14268 argv_find(argv, argc, "(100-500)", &idx);
14269 argv_find(argv, argc, "WORD", &idx);
14270 cl_number_or_name = argv[idx]->arg;
14271 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14272 : COMMUNITY_DENY;
14273 argv_find(argv, argc, "LINE", &idx);
14274 char *str = argv_concat(argv, argc, idx);
42f914d4 14275
d62a17ae 14276 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14277 direct, style);
42f914d4 14278
d62a17ae 14279 XFREE(MTYPE_TMP, str);
42f914d4 14280
d62a17ae 14281 if (ret < 0) {
14282 community_list_perror(vty, ret);
14283 return CMD_WARNING_CONFIG_FAILED;
14284 }
42f914d4 14285
d62a17ae 14286 return CMD_SUCCESS;
718e3744 14287}
14288
d62a17ae 14289static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 14290{
d62a17ae 14291 struct community_entry *entry;
718e3744 14292
d62a17ae 14293 for (entry = list->head; entry; entry = entry->next) {
14294 if (entry == list->head) {
14295 if (all_digit(list->name))
14296 vty_out(vty, "Extended community %s list %s\n",
14297 entry->style == EXTCOMMUNITY_LIST_STANDARD
14298 ? "standard"
14299 : "(expanded) access",
14300 list->name);
14301 else
14302 vty_out(vty,
14303 "Named extended community %s list %s\n",
14304 entry->style == EXTCOMMUNITY_LIST_STANDARD
14305 ? "standard"
14306 : "expanded",
14307 list->name);
14308 }
14309 if (entry->any)
14310 vty_out(vty, " %s\n",
14311 community_direct_str(entry->direct));
14312 else
14313 vty_out(vty, " %s %s\n",
14314 community_direct_str(entry->direct),
8d9b8ed9 14315 community_list_config_str(entry));
d62a17ae 14316 }
718e3744 14317}
14318
14319DEFUN (show_ip_extcommunity_list,
14320 show_ip_extcommunity_list_cmd,
14321 "show ip extcommunity-list",
14322 SHOW_STR
14323 IP_STR
14324 "List extended-community list\n")
14325{
d62a17ae 14326 struct community_list *list;
14327 struct community_list_master *cm;
718e3744 14328
d62a17ae 14329 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14330 if (!cm)
14331 return CMD_SUCCESS;
718e3744 14332
d62a17ae 14333 for (list = cm->num.head; list; list = list->next)
14334 extcommunity_list_show(vty, list);
718e3744 14335
d62a17ae 14336 for (list = cm->str.head; list; list = list->next)
14337 extcommunity_list_show(vty, list);
718e3744 14338
d62a17ae 14339 return CMD_SUCCESS;
718e3744 14340}
14341
14342DEFUN (show_ip_extcommunity_list_arg,
14343 show_ip_extcommunity_list_arg_cmd,
6147e2c6 14344 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 14345 SHOW_STR
14346 IP_STR
14347 "List extended-community list\n"
14348 "Extcommunity-list number\n"
14349 "Extcommunity-list name\n")
14350{
d62a17ae 14351 int idx_comm_list = 3;
14352 struct community_list *list;
718e3744 14353
d62a17ae 14354 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14355 EXTCOMMUNITY_LIST_MASTER);
14356 if (!list) {
14357 vty_out(vty, "%% Can't find extcommunity-list\n");
14358 return CMD_WARNING;
14359 }
718e3744 14360
d62a17ae 14361 extcommunity_list_show(vty, list);
718e3744 14362
d62a17ae 14363 return CMD_SUCCESS;
718e3744 14364}
6b0655a2 14365
718e3744 14366/* Display community-list and extcommunity-list configuration. */
d62a17ae 14367static int community_list_config_write(struct vty *vty)
14368{
14369 struct community_list *list;
14370 struct community_entry *entry;
14371 struct community_list_master *cm;
14372 int write = 0;
14373
14374 /* Community-list. */
14375 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14376
14377 for (list = cm->num.head; list; list = list->next)
14378 for (entry = list->head; entry; entry = entry->next) {
14379 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14380 community_direct_str(entry->direct),
14381 community_list_config_str(entry));
14382 write++;
14383 }
14384 for (list = cm->str.head; list; list = list->next)
14385 for (entry = list->head; entry; entry = entry->next) {
14386 vty_out(vty, "ip community-list %s %s %s %s\n",
14387 entry->style == COMMUNITY_LIST_STANDARD
14388 ? "standard"
14389 : "expanded",
14390 list->name, community_direct_str(entry->direct),
14391 community_list_config_str(entry));
14392 write++;
14393 }
14394
14395 /* Extcommunity-list. */
14396 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14397
14398 for (list = cm->num.head; list; list = list->next)
14399 for (entry = list->head; entry; entry = entry->next) {
14400 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14401 list->name, community_direct_str(entry->direct),
14402 community_list_config_str(entry));
14403 write++;
14404 }
14405 for (list = cm->str.head; list; list = list->next)
14406 for (entry = list->head; entry; entry = entry->next) {
14407 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14408 entry->style == EXTCOMMUNITY_LIST_STANDARD
14409 ? "standard"
14410 : "expanded",
14411 list->name, community_direct_str(entry->direct),
14412 community_list_config_str(entry));
14413 write++;
14414 }
14415
14416
14417 /* lcommunity-list. */
14418 cm = community_list_master_lookup(bgp_clist,
14419 LARGE_COMMUNITY_LIST_MASTER);
14420
14421 for (list = cm->num.head; list; list = list->next)
14422 for (entry = list->head; entry; entry = entry->next) {
14423 vty_out(vty, "ip large-community-list %s %s %s\n",
14424 list->name, community_direct_str(entry->direct),
14425 community_list_config_str(entry));
14426 write++;
14427 }
14428 for (list = cm->str.head; list; list = list->next)
14429 for (entry = list->head; entry; entry = entry->next) {
14430 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14431 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14432 ? "standard"
14433 : "expanded",
14434 list->name, community_direct_str(entry->direct),
14435 community_list_config_str(entry));
14436 write++;
14437 }
14438
14439 return write;
14440}
14441
14442static struct cmd_node community_list_node = {
14443 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 14444};
14445
d62a17ae 14446static void community_list_vty(void)
14447{
14448 install_node(&community_list_node, community_list_config_write);
14449
14450 /* Community-list. */
14451 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14452 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14453 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14454 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14455 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14456 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14457
14458 /* Extcommunity-list. */
14459 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14460 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14461 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14462 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14463 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14464 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14465
14466 /* Large Community List */
14467 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14468 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14469 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14470 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14471 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14472 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14473 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14474 install_element(CONFIG_NODE,
14475 &no_ip_lcommunity_list_name_expanded_all_cmd);
14476 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14477 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14478 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14479 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14480 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14481 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 14482}