]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: 'show bgp [ipv4|ipv6] neighbors' displays all af neighbors
[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"
14454c9f 48#include "bgpd/bgp_errors.h"
e0701b79 49#include "bgpd/bgp_fsm.h"
4bf6a362 50#include "bgpd/bgp_nexthop.h"
718e3744 51#include "bgpd/bgp_open.h"
4bf6a362 52#include "bgpd/bgp_regex.h"
718e3744 53#include "bgpd/bgp_route.h"
c016b6c7 54#include "bgpd/bgp_mplsvpn.h"
718e3744 55#include "bgpd/bgp_zebra.h"
fee0f4c6 56#include "bgpd/bgp_table.h"
94f2b392 57#include "bgpd/bgp_vty.h"
165b5fff 58#include "bgpd/bgp_mpath.h"
cb1faec9 59#include "bgpd/bgp_packet.h"
3f9c7369 60#include "bgpd/bgp_updgrp.h"
c43ed2e4 61#include "bgpd/bgp_bfd.h"
555e09d4 62#include "bgpd/bgp_io.h"
94c2f693 63#include "bgpd/bgp_evpn.h"
718e3744 64
d62a17ae 65static struct peer_group *listen_range_exists(struct bgp *bgp,
66 struct prefix *range, int exact);
67
68static enum node_type bgp_node_type(afi_t afi, safi_t safi)
69{
70 switch (afi) {
71 case AFI_IP:
72 switch (safi) {
73 case SAFI_UNICAST:
74 return BGP_IPV4_NODE;
75 break;
76 case SAFI_MULTICAST:
77 return BGP_IPV4M_NODE;
78 break;
79 case SAFI_LABELED_UNICAST:
80 return BGP_IPV4L_NODE;
81 break;
82 case SAFI_MPLS_VPN:
83 return BGP_VPNV4_NODE;
84 break;
7c40bf39 85 case SAFI_FLOWSPEC:
86 return BGP_FLOWSPECV4_NODE;
5c525538
RW
87 default:
88 /* not expected */
89 return BGP_IPV4_NODE;
90 break;
d62a17ae 91 }
92 break;
93 case AFI_IP6:
94 switch (safi) {
95 case SAFI_UNICAST:
96 return BGP_IPV6_NODE;
97 break;
98 case SAFI_MULTICAST:
99 return BGP_IPV6M_NODE;
100 break;
101 case SAFI_LABELED_UNICAST:
102 return BGP_IPV6L_NODE;
103 break;
104 case SAFI_MPLS_VPN:
105 return BGP_VPNV6_NODE;
106 break;
7c40bf39 107 case SAFI_FLOWSPEC:
108 return BGP_FLOWSPECV6_NODE;
5c525538
RW
109 default:
110 /* not expected */
111 return BGP_IPV4_NODE;
112 break;
d62a17ae 113 }
114 break;
115 case AFI_L2VPN:
116 return BGP_EVPN_NODE;
117 break;
118 case AFI_MAX:
119 // We should never be here but to clarify the switch statement..
120 return BGP_IPV4_NODE;
121 break;
122 }
123
124 // Impossible to happen
125 return BGP_IPV4_NODE;
f51bae9c 126}
20eb8864 127
718e3744 128/* Utility function to get address family from current node. */
d62a17ae 129afi_t bgp_node_afi(struct vty *vty)
130{
131 afi_t afi;
132 switch (vty->node) {
133 case BGP_IPV6_NODE:
134 case BGP_IPV6M_NODE:
135 case BGP_IPV6L_NODE:
136 case BGP_VPNV6_NODE:
7c40bf39 137 case BGP_FLOWSPECV6_NODE:
d62a17ae 138 afi = AFI_IP6;
139 break;
140 case BGP_EVPN_NODE:
141 afi = AFI_L2VPN;
142 break;
143 default:
144 afi = AFI_IP;
145 break;
146 }
147 return afi;
718e3744 148}
149
150/* Utility function to get subsequent address family from current
151 node. */
d62a17ae 152safi_t bgp_node_safi(struct vty *vty)
153{
154 safi_t safi;
155 switch (vty->node) {
156 case BGP_VPNV4_NODE:
157 case BGP_VPNV6_NODE:
158 safi = SAFI_MPLS_VPN;
159 break;
160 case BGP_IPV4M_NODE:
161 case BGP_IPV6M_NODE:
162 safi = SAFI_MULTICAST;
163 break;
164 case BGP_EVPN_NODE:
165 safi = SAFI_EVPN;
166 break;
167 case BGP_IPV4L_NODE:
168 case BGP_IPV6L_NODE:
169 safi = SAFI_LABELED_UNICAST;
170 break;
7c40bf39 171 case BGP_FLOWSPECV4_NODE:
172 case BGP_FLOWSPECV6_NODE:
173 safi = SAFI_FLOWSPEC;
174 break;
d62a17ae 175 default:
176 safi = SAFI_UNICAST;
177 break;
178 }
179 return safi;
718e3744 180}
181
55f91488
QY
182/**
183 * Converts an AFI in string form to afi_t
184 *
185 * @param afi string, one of
186 * - "ipv4"
187 * - "ipv6"
81cf0de5 188 * - "l2vpn"
55f91488
QY
189 * @return the corresponding afi_t
190 */
d62a17ae 191afi_t bgp_vty_afi_from_str(const char *afi_str)
192{
193 afi_t afi = AFI_MAX; /* unknown */
194 if (strmatch(afi_str, "ipv4"))
195 afi = AFI_IP;
196 else if (strmatch(afi_str, "ipv6"))
197 afi = AFI_IP6;
81cf0de5
CS
198 else if (strmatch(afi_str, "l2vpn"))
199 afi = AFI_L2VPN;
d62a17ae 200 return afi;
201}
202
203int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
204 afi_t *afi)
205{
206 int ret = 0;
207 if (argv_find(argv, argc, "ipv4", index)) {
208 ret = 1;
209 if (afi)
210 *afi = AFI_IP;
211 } else if (argv_find(argv, argc, "ipv6", index)) {
212 ret = 1;
213 if (afi)
214 *afi = AFI_IP6;
215 }
216 return ret;
46f296b4
LB
217}
218
375a2e67 219/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 220safi_t bgp_vty_safi_from_str(const char *safi_str)
221{
222 safi_t safi = SAFI_MAX; /* unknown */
223 if (strmatch(safi_str, "multicast"))
224 safi = SAFI_MULTICAST;
225 else if (strmatch(safi_str, "unicast"))
226 safi = SAFI_UNICAST;
227 else if (strmatch(safi_str, "vpn"))
228 safi = SAFI_MPLS_VPN;
81cf0de5
CS
229 else if (strmatch(safi_str, "evpn"))
230 safi = SAFI_EVPN;
d62a17ae 231 else if (strmatch(safi_str, "labeled-unicast"))
232 safi = SAFI_LABELED_UNICAST;
7c40bf39 233 else if (strmatch(safi_str, "flowspec"))
234 safi = SAFI_FLOWSPEC;
d62a17ae 235 return safi;
236}
237
238int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
239 safi_t *safi)
240{
241 int ret = 0;
242 if (argv_find(argv, argc, "unicast", index)) {
243 ret = 1;
244 if (safi)
245 *safi = SAFI_UNICAST;
246 } else if (argv_find(argv, argc, "multicast", index)) {
247 ret = 1;
248 if (safi)
249 *safi = SAFI_MULTICAST;
250 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
251 ret = 1;
252 if (safi)
253 *safi = SAFI_LABELED_UNICAST;
254 } else if (argv_find(argv, argc, "vpn", index)) {
255 ret = 1;
256 if (safi)
257 *safi = SAFI_MPLS_VPN;
7c40bf39 258 } else if (argv_find(argv, argc, "flowspec", index)) {
259 ret = 1;
260 if (safi)
261 *safi = SAFI_FLOWSPEC;
d62a17ae 262 }
263 return ret;
46f296b4
LB
264}
265
7eeee51e 266/*
f212a857 267 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 268 *
f212a857
DS
269 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
270 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
271 * to appropriate values for the calling function. This is to allow the
272 * calling function to make decisions appropriate for the show command
273 * that is being parsed.
274 *
275 * The show commands are generally of the form:
d62a17ae 276 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
277 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
278 *
279 * Since we use argv_find if the show command in particular doesn't have:
280 * [ip]
18c57037 281 * [<view|vrf> VIEWVRFNAME]
375a2e67 282 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
283 * The command parsing should still be ok.
284 *
285 * vty -> The vty for the command so we can output some useful data in
286 * the event of a parse error in the vrf.
287 * argv -> The command tokens
288 * argc -> How many command tokens we have
d62a17ae 289 * idx -> The current place in the command, generally should be 0 for this
290 * function
7eeee51e
DS
291 * afi -> The parsed afi if it was included in the show command, returned here
292 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 293 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
294 *
295 * The function returns the correct location in the parse tree for the
296 * last token found.
0e37c258
DS
297 *
298 * Returns 0 for failure to parse correctly, else the idx position of where
299 * it found the last token.
7eeee51e 300 */
d62a17ae 301int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
302 struct cmd_token **argv, int argc,
303 int *idx, afi_t *afi, safi_t *safi,
304 struct bgp **bgp)
305{
306 char *vrf_name = NULL;
307
308 assert(afi);
309 assert(safi);
310 assert(bgp);
311
312 if (argv_find(argv, argc, "ip", idx))
313 *afi = AFI_IP;
314
315 if (argv_find(argv, argc, "view", idx)
316 || argv_find(argv, argc, "vrf", idx)) {
317 vrf_name = argv[*idx + 1]->arg;
318
319 if (strmatch(vrf_name, "all"))
320 *bgp = NULL;
321 else {
322 *bgp = bgp_lookup_by_name(vrf_name);
323 if (!*bgp) {
324 vty_out(vty,
325 "View/Vrf specified is unknown: %s\n",
326 vrf_name);
327 *idx = 0;
328 return 0;
329 }
330 }
331 } else {
332 *bgp = bgp_get_default();
333 if (!*bgp) {
334 vty_out(vty, "Unable to find default BGP instance\n");
335 *idx = 0;
336 return 0;
337 }
338 }
339
340 if (argv_find_and_parse_afi(argv, argc, idx, afi))
341 argv_find_and_parse_safi(argv, argc, idx, safi);
342
343 *idx += 1;
344 return *idx;
345}
346
347static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
348{
349 struct interface *ifp = NULL;
350
351 if (su->sa.sa_family == AF_INET)
352 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
353 else if (su->sa.sa_family == AF_INET6)
354 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
355 su->sin6.sin6_scope_id,
356 bgp->vrf_id);
357
358 if (ifp)
359 return 1;
360
361 return 0;
718e3744 362}
363
364/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
365/* This is used only for configuration, so disallow if attempted on
366 * a dynamic neighbor.
367 */
d62a17ae 368static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
369{
370 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
371 int ret;
372 union sockunion su;
373 struct peer *peer;
374
375 if (!bgp) {
376 return NULL;
377 }
378
379 ret = str2sockunion(ip_str, &su);
380 if (ret < 0) {
381 peer = peer_lookup_by_conf_if(bgp, ip_str);
382 if (!peer) {
383 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
384 == NULL) {
385 vty_out(vty,
386 "%% Malformed address or name: %s\n",
387 ip_str);
388 return NULL;
389 }
390 }
391 } else {
392 peer = peer_lookup(bgp, &su);
393 if (!peer) {
394 vty_out(vty,
395 "%% Specify remote-as or peer-group commands first\n");
396 return NULL;
397 }
398 if (peer_dynamic_neighbor(peer)) {
399 vty_out(vty,
400 "%% Operation not allowed on a dynamic neighbor\n");
401 return NULL;
402 }
403 }
404 return peer;
718e3744 405}
406
407/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
408/* This is used only for configuration, so disallow if attempted on
409 * a dynamic neighbor.
410 */
d62a17ae 411struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
412{
413 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
414 int ret;
415 union sockunion su;
416 struct peer *peer = NULL;
417 struct peer_group *group = NULL;
418
419 if (!bgp) {
420 return NULL;
421 }
422
423 ret = str2sockunion(peer_str, &su);
424 if (ret == 0) {
425 /* IP address, locate peer. */
426 peer = peer_lookup(bgp, &su);
427 } else {
428 /* Not IP, could match either peer configured on interface or a
429 * group. */
430 peer = peer_lookup_by_conf_if(bgp, peer_str);
431 if (!peer)
432 group = peer_group_lookup(bgp, peer_str);
433 }
434
435 if (peer) {
436 if (peer_dynamic_neighbor(peer)) {
437 vty_out(vty,
438 "%% Operation not allowed on a dynamic neighbor\n");
439 return NULL;
440 }
441
442 return peer;
443 }
444
445 if (group)
446 return group->conf;
447
448 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
449
450 return NULL;
451}
452
453int bgp_vty_return(struct vty *vty, int ret)
454{
455 const char *str = NULL;
456
457 switch (ret) {
458 case BGP_ERR_INVALID_VALUE:
459 str = "Invalid value";
460 break;
461 case BGP_ERR_INVALID_FLAG:
462 str = "Invalid flag";
463 break;
464 case BGP_ERR_PEER_GROUP_SHUTDOWN:
465 str = "Peer-group has been shutdown. Activate the peer-group first";
466 break;
467 case BGP_ERR_PEER_FLAG_CONFLICT:
468 str = "Can't set override-capability and strict-capability-match at the same time";
469 break;
470 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
471 str = "Specify remote-as or peer-group remote AS first";
472 break;
473 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
474 str = "Cannot change the peer-group. Deconfigure first";
475 break;
476 case BGP_ERR_PEER_GROUP_MISMATCH:
477 str = "Peer is not a member of this peer-group";
478 break;
479 case BGP_ERR_PEER_FILTER_CONFLICT:
480 str = "Prefix/distribute list can not co-exist";
481 break;
482 case BGP_ERR_NOT_INTERNAL_PEER:
483 str = "Invalid command. Not an internal neighbor";
484 break;
485 case BGP_ERR_REMOVE_PRIVATE_AS:
486 str = "remove-private-AS cannot be configured for IBGP peers";
487 break;
488 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
489 str = "Local-AS allowed only for EBGP peers";
490 break;
491 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
492 str = "Cannot have local-as same as BGP AS number";
493 break;
494 case BGP_ERR_TCPSIG_FAILED:
495 str = "Error while applying TCP-Sig to session(s)";
496 break;
497 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
498 str = "ebgp-multihop and ttl-security cannot be configured together";
499 break;
500 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
501 str = "ttl-security only allowed for EBGP peers";
502 break;
503 case BGP_ERR_AS_OVERRIDE:
504 str = "as-override cannot be configured for IBGP peers";
505 break;
506 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
507 str = "Invalid limit for number of dynamic neighbors";
508 break;
509 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
510 str = "Dynamic neighbor listen range already exists";
511 break;
512 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
513 str = "Operation not allowed on a dynamic neighbor";
514 break;
515 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
516 str = "Operation not allowed on a directly connected neighbor";
517 break;
518 case BGP_ERR_PEER_SAFI_CONFLICT:
519 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
520 break;
521 }
522 if (str) {
523 vty_out(vty, "%% %s\n", str);
524 return CMD_WARNING_CONFIG_FAILED;
525 }
526 return CMD_SUCCESS;
718e3744 527}
528
7aafcaca 529/* BGP clear sort. */
d62a17ae 530enum clear_sort {
531 clear_all,
532 clear_peer,
533 clear_group,
534 clear_external,
535 clear_as
7aafcaca
DS
536};
537
d62a17ae 538static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
539 safi_t safi, int error)
540{
541 switch (error) {
542 case BGP_ERR_AF_UNCONFIGURED:
543 vty_out(vty,
544 "%%BGP: Enable %s address family for the neighbor %s\n",
545 afi_safi_print(afi, safi), peer->host);
546 break;
547 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
548 vty_out(vty,
549 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
550 peer->host);
551 break;
552 default:
553 break;
554 }
7aafcaca
DS
555}
556
557/* `clear ip bgp' functions. */
d62a17ae 558static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
559 enum clear_sort sort, enum bgp_clear_type stype,
560 const char *arg)
561{
562 int ret;
3ae8bfa5 563 bool found = false;
d62a17ae 564 struct peer *peer;
565 struct listnode *node, *nnode;
566
567 /* Clear all neighbors. */
568 /*
569 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
570 * nodes on the BGP instance as that may get freed if it is a
571 * doppelganger
d62a17ae 572 */
573 if (sort == clear_all) {
574 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
3ae8bfa5
PM
575 if (!peer->afc[afi][safi])
576 continue;
577
d62a17ae 578 if (stype == BGP_CLEAR_SOFT_NONE)
579 ret = peer_clear(peer, &nnode);
d62a17ae 580 else
3ae8bfa5 581 ret = peer_clear_soft(peer, afi, safi, stype);
d62a17ae 582
583 if (ret < 0)
584 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
585 else
586 found = true;
04b6bdc0 587 }
d62a17ae 588
589 /* This is to apply read-only mode on this clear. */
590 if (stype == BGP_CLEAR_SOFT_NONE)
591 bgp->update_delay_over = 0;
592
3ae8bfa5
PM
593 if (!found)
594 vty_out(vty, "%%BGP: No %s peer configured",
595 afi_safi_print(afi, safi));
596
d62a17ae 597 return CMD_SUCCESS;
7aafcaca
DS
598 }
599
3ae8bfa5 600 /* Clear specified neighbor. */
d62a17ae 601 if (sort == clear_peer) {
602 union sockunion su;
d62a17ae 603
604 /* Make sockunion for lookup. */
605 ret = str2sockunion(arg, &su);
606 if (ret < 0) {
607 peer = peer_lookup_by_conf_if(bgp, arg);
608 if (!peer) {
609 peer = peer_lookup_by_hostname(bgp, arg);
610 if (!peer) {
611 vty_out(vty,
612 "Malformed address or name: %s\n",
613 arg);
614 return CMD_WARNING;
615 }
616 }
617 } else {
618 peer = peer_lookup(bgp, &su);
619 if (!peer) {
620 vty_out(vty,
621 "%%BGP: Unknown neighbor - \"%s\"\n",
622 arg);
623 return CMD_WARNING;
624 }
625 }
7aafcaca 626
3ae8bfa5
PM
627 if (!peer->afc[afi][safi])
628 ret = BGP_ERR_AF_UNCONFIGURED;
629 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 630 ret = peer_clear(peer, NULL);
631 else
632 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 633
d62a17ae 634 if (ret < 0)
635 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 636
d62a17ae 637 return CMD_SUCCESS;
7aafcaca 638 }
7aafcaca 639
3ae8bfa5 640 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 641 if (sort == clear_group) {
642 struct peer_group *group;
7aafcaca 643
d62a17ae 644 group = peer_group_lookup(bgp, arg);
645 if (!group) {
646 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
647 return CMD_WARNING;
648 }
649
650 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
d62a17ae 651 if (!peer->afc[afi][safi])
652 continue;
653
3ae8bfa5
PM
654 if (stype == BGP_CLEAR_SOFT_NONE)
655 ret = peer_clear(peer, NULL);
656 else
657 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 658
d62a17ae 659 if (ret < 0)
660 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
661 else
662 found = true;
d62a17ae 663 }
3ae8bfa5
PM
664
665 if (!found)
666 vty_out(vty,
667 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
668 afi_safi_print(afi, safi), arg);
669
d62a17ae 670 return CMD_SUCCESS;
7aafcaca 671 }
7aafcaca 672
3ae8bfa5 673 /* Clear all external (eBGP) neighbors. */
d62a17ae 674 if (sort == clear_external) {
675 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
676 if (peer->sort == BGP_PEER_IBGP)
677 continue;
7aafcaca 678
3ae8bfa5
PM
679 if (!peer->afc[afi][safi])
680 continue;
681
d62a17ae 682 if (stype == BGP_CLEAR_SOFT_NONE)
683 ret = peer_clear(peer, &nnode);
684 else
685 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 686
d62a17ae 687 if (ret < 0)
688 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
689 else
690 found = true;
d62a17ae 691 }
3ae8bfa5
PM
692
693 if (!found)
694 vty_out(vty,
695 "%%BGP: No external %s peer is configured\n",
696 afi_safi_print(afi, safi));
697
d62a17ae 698 return CMD_SUCCESS;
699 }
700
3ae8bfa5 701 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 702 if (sort == clear_as) {
3ae8bfa5 703 as_t as = strtoul(arg, NULL, 10);
d62a17ae 704
705 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
706 if (peer->as != as)
707 continue;
708
3ae8bfa5
PM
709 if (!peer->afc[afi][safi])
710 ret = BGP_ERR_AF_UNCONFIGURED;
711 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 712 ret = peer_clear(peer, &nnode);
713 else
714 ret = peer_clear_soft(peer, afi, safi, stype);
715
716 if (ret < 0)
717 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
718 else
719 found = true;
d62a17ae 720 }
3ae8bfa5
PM
721
722 if (!found)
d62a17ae 723 vty_out(vty,
3ae8bfa5
PM
724 "%%BGP: No %s peer is configured with AS %s\n",
725 afi_safi_print(afi, safi), arg);
726
d62a17ae 727 return CMD_SUCCESS;
728 }
729
730 return CMD_SUCCESS;
731}
732
733static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
734 safi_t safi, enum clear_sort sort,
735 enum bgp_clear_type stype, const char *arg)
736{
737 struct bgp *bgp;
738
739 /* BGP structure lookup. */
740 if (name) {
741 bgp = bgp_lookup_by_name(name);
742 if (bgp == NULL) {
743 vty_out(vty, "Can't find BGP instance %s\n", name);
744 return CMD_WARNING;
745 }
746 } else {
747 bgp = bgp_get_default();
748 if (bgp == NULL) {
749 vty_out(vty, "No BGP process is configured\n");
750 return CMD_WARNING;
751 }
752 }
753
754 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
755}
756
757/* clear soft inbound */
d62a17ae 758static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 759{
d62a17ae 760 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
761 BGP_CLEAR_SOFT_IN, NULL);
762 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
763 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
764}
765
766/* clear soft outbound */
d62a17ae 767static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 768{
d62a17ae 769 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
770 BGP_CLEAR_SOFT_OUT, NULL);
771 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
772 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
773}
774
775
f787d7a0 776#ifndef VTYSH_EXTRACT_PL
2e4c2296 777#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
778#endif
779
718e3744 780/* BGP global configuration. */
bee57a7a 781#if (CONFDATE > 20190601)
1cc40660
DS
782CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
783CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
784#endif
785DEFUN_HIDDEN (bgp_multiple_instance_func,
786 bgp_multiple_instance_cmd,
787 "bgp multiple-instance",
788 BGP_STR
789 "Enable bgp multiple instance\n")
718e3744 790{
d62a17ae 791 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
792 return CMD_SUCCESS;
718e3744 793}
794
1cc40660 795DEFUN_HIDDEN (no_bgp_multiple_instance,
718e3744 796 no_bgp_multiple_instance_cmd,
797 "no bgp multiple-instance",
798 NO_STR
799 BGP_STR
800 "BGP multiple instance\n")
801{
d62a17ae 802 int ret;
718e3744 803
1cc40660
DS
804 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
805 vty_out(vty, "if you are using this please let the developers know\n");
b7cd3069 806 zlog_info("Deprecated option: `bgp multiple-instance` being used");
d62a17ae 807 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
808 if (ret < 0) {
809 vty_out(vty, "%% There are more than two BGP instances\n");
810 return CMD_WARNING_CONFIG_FAILED;
811 }
812 return CMD_SUCCESS;
718e3744 813}
814
bee57a7a 815#if (CONFDATE > 20190601)
798467a2
DS
816CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
817CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
818#endif
819DEFUN_HIDDEN (bgp_config_type,
820 bgp_config_type_cmd,
821 "bgp config-type <cisco|zebra>",
822 BGP_STR
823 "Configuration type\n"
824 "cisco\n"
825 "zebra\n")
718e3744 826{
d62a17ae 827 int idx = 0;
798467a2
DS
828 if (argv_find(argv, argc, "cisco", &idx)) {
829 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
830 vty_out(vty, "if you are using this please let the developers know!\n");
b7cd3069 831 zlog_info("Deprecated option: `bgp config-type cisco` being used");
d62a17ae 832 bgp_option_set(BGP_OPT_CONFIG_CISCO);
798467a2 833 } else
d62a17ae 834 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 835
d62a17ae 836 return CMD_SUCCESS;
718e3744 837}
838
798467a2
DS
839DEFUN_HIDDEN (no_bgp_config_type,
840 no_bgp_config_type_cmd,
841 "no bgp config-type [<cisco|zebra>]",
842 NO_STR
843 BGP_STR
844 "Display configuration type\n"
845 "cisco\n"
846 "zebra\n")
718e3744 847{
d62a17ae 848 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
849 return CMD_SUCCESS;
718e3744 850}
851
813d4307 852
718e3744 853DEFUN (no_synchronization,
854 no_synchronization_cmd,
855 "no synchronization",
856 NO_STR
857 "Perform IGP synchronization\n")
858{
d62a17ae 859 return CMD_SUCCESS;
718e3744 860}
861
862DEFUN (no_auto_summary,
863 no_auto_summary_cmd,
864 "no auto-summary",
865 NO_STR
866 "Enable automatic network number summarization\n")
867{
d62a17ae 868 return CMD_SUCCESS;
718e3744 869}
3d515fd9 870
718e3744 871/* "router bgp" commands. */
505e5056 872DEFUN_NOSH (router_bgp,
f412b39a 873 router_bgp_cmd,
18c57037 874 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 875 ROUTER_STR
876 BGP_STR
31500417
DW
877 AS_STR
878 BGP_INSTANCE_HELP_STR)
718e3744 879{
d62a17ae 880 int idx_asn = 2;
881 int idx_view_vrf = 3;
882 int idx_vrf = 4;
883 int ret;
884 as_t as;
885 struct bgp *bgp;
886 const char *name = NULL;
887 enum bgp_instance_type inst_type;
888
889 // "router bgp" without an ASN
890 if (argc == 2) {
891 // Pending: Make VRF option available for ASN less config
892 bgp = bgp_get_default();
893
894 if (bgp == NULL) {
895 vty_out(vty, "%% No BGP process is configured\n");
896 return CMD_WARNING_CONFIG_FAILED;
897 }
898
899 if (listcount(bm->bgp) > 1) {
996c9314 900 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 901 return CMD_WARNING_CONFIG_FAILED;
902 }
903 }
904
905 // "router bgp X"
906 else {
907 as = strtoul(argv[idx_asn]->arg, NULL, 10);
908
909 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
910 if (argc > 3) {
911 name = argv[idx_vrf]->arg;
912
913 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
914 inst_type = BGP_INSTANCE_TYPE_VRF;
915 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
916 inst_type = BGP_INSTANCE_TYPE_VIEW;
917 }
918
919 ret = bgp_get(&bgp, &as, name, inst_type);
920 switch (ret) {
921 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
922 vty_out(vty,
923 "Please specify 'bgp multiple-instance' first\n");
924 return CMD_WARNING_CONFIG_FAILED;
925 case BGP_ERR_AS_MISMATCH:
926 vty_out(vty, "BGP is already running; AS is %u\n", as);
927 return CMD_WARNING_CONFIG_FAILED;
928 case BGP_ERR_INSTANCE_MISMATCH:
929 vty_out(vty,
930 "BGP instance name and AS number mismatch\n");
931 vty_out(vty,
932 "BGP instance is already running; AS is %u\n",
933 as);
934 return CMD_WARNING_CONFIG_FAILED;
935 }
936
3bd70bf8
PZ
937 /*
938 * If we just instantiated the default instance, complete
939 * any pending VRF-VPN leaking that was configured via
940 * earlier "router bgp X vrf FOO" blocks.
941 */
942 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
943 vpn_leak_postchange_all();
944
d62a17ae 945 /* Pending: handle when user tries to change a view to vrf n vv.
946 */
947 }
948
0b5131c9
MK
949 /* unset the auto created flag as the user config is now present */
950 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 951 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
952
953 return CMD_SUCCESS;
718e3744 954}
955
718e3744 956/* "no router bgp" commands. */
957DEFUN (no_router_bgp,
958 no_router_bgp_cmd,
18c57037 959 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 960 NO_STR
961 ROUTER_STR
962 BGP_STR
31500417
DW
963 AS_STR
964 BGP_INSTANCE_HELP_STR)
718e3744 965{
d62a17ae 966 int idx_asn = 3;
967 int idx_vrf = 5;
968 as_t as;
969 struct bgp *bgp;
970 const char *name = NULL;
718e3744 971
d62a17ae 972 // "no router bgp" without an ASN
973 if (argc == 3) {
974 // Pending: Make VRF option available for ASN less config
975 bgp = bgp_get_default();
718e3744 976
d62a17ae 977 if (bgp == NULL) {
978 vty_out(vty, "%% No BGP process is configured\n");
979 return CMD_WARNING_CONFIG_FAILED;
980 }
7fb21a9f 981
d62a17ae 982 if (listcount(bm->bgp) > 1) {
996c9314 983 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 984 return CMD_WARNING_CONFIG_FAILED;
985 }
0b5131c9
MK
986
987 if (bgp->l3vni) {
988 vty_out(vty, "%% Please unconfigure l3vni %u",
989 bgp->l3vni);
990 return CMD_WARNING_CONFIG_FAILED;
991 }
d62a17ae 992 } else {
993 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 994
d62a17ae 995 if (argc > 4)
996 name = argv[idx_vrf]->arg;
7fb21a9f 997
d62a17ae 998 /* Lookup bgp structure. */
999 bgp = bgp_lookup(as, name);
1000 if (!bgp) {
1001 vty_out(vty, "%% Can't find BGP instance\n");
1002 return CMD_WARNING_CONFIG_FAILED;
1003 }
0b5131c9
MK
1004
1005 if (bgp->l3vni) {
1006 vty_out(vty, "%% Please unconfigure l3vni %u",
1007 bgp->l3vni);
1008 return CMD_WARNING_CONFIG_FAILED;
1009 }
d62a17ae 1010 }
718e3744 1011
d62a17ae 1012 bgp_delete(bgp);
718e3744 1013
d62a17ae 1014 return CMD_SUCCESS;
718e3744 1015}
1016
6b0655a2 1017
718e3744 1018/* BGP router-id. */
1019
f787d7a0 1020DEFPY (bgp_router_id,
718e3744 1021 bgp_router_id_cmd,
1022 "bgp router-id A.B.C.D",
1023 BGP_STR
1024 "Override configured router identifier\n"
1025 "Manually configured router identifier\n")
1026{
d62a17ae 1027 VTY_DECLVAR_CONTEXT(bgp, bgp);
1028 bgp_router_id_static_set(bgp, router_id);
1029 return CMD_SUCCESS;
718e3744 1030}
1031
f787d7a0 1032DEFPY (no_bgp_router_id,
718e3744 1033 no_bgp_router_id_cmd,
31500417 1034 "no bgp router-id [A.B.C.D]",
718e3744 1035 NO_STR
1036 BGP_STR
31500417
DW
1037 "Override configured router identifier\n"
1038 "Manually configured router identifier\n")
718e3744 1039{
d62a17ae 1040 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1041
d62a17ae 1042 if (router_id_str) {
1043 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1044 vty_out(vty, "%% BGP router-id doesn't match\n");
1045 return CMD_WARNING_CONFIG_FAILED;
1046 }
e018c7cc 1047 }
718e3744 1048
d62a17ae 1049 router_id.s_addr = 0;
1050 bgp_router_id_static_set(bgp, router_id);
718e3744 1051
d62a17ae 1052 return CMD_SUCCESS;
718e3744 1053}
1054
6b0655a2 1055
718e3744 1056/* BGP Cluster ID. */
718e3744 1057DEFUN (bgp_cluster_id,
1058 bgp_cluster_id_cmd,
838758ac 1059 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1060 BGP_STR
1061 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1062 "Route-Reflector Cluster-id in IP address format\n"
1063 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1064{
d62a17ae 1065 VTY_DECLVAR_CONTEXT(bgp, bgp);
1066 int idx_ipv4 = 2;
1067 int ret;
1068 struct in_addr cluster;
718e3744 1069
d62a17ae 1070 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1071 if (!ret) {
1072 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1073 return CMD_WARNING_CONFIG_FAILED;
1074 }
718e3744 1075
d62a17ae 1076 bgp_cluster_id_set(bgp, &cluster);
1077 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1078
d62a17ae 1079 return CMD_SUCCESS;
718e3744 1080}
1081
718e3744 1082DEFUN (no_bgp_cluster_id,
1083 no_bgp_cluster_id_cmd,
c7178fe7 1084 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1085 NO_STR
1086 BGP_STR
838758ac
DW
1087 "Configure Route-Reflector Cluster-id\n"
1088 "Route-Reflector Cluster-id in IP address format\n"
1089 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1090{
d62a17ae 1091 VTY_DECLVAR_CONTEXT(bgp, bgp);
1092 bgp_cluster_id_unset(bgp);
1093 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1094
d62a17ae 1095 return CMD_SUCCESS;
718e3744 1096}
1097
718e3744 1098DEFUN (bgp_confederation_identifier,
1099 bgp_confederation_identifier_cmd,
9ccf14f7 1100 "bgp confederation identifier (1-4294967295)",
718e3744 1101 "BGP specific commands\n"
1102 "AS confederation parameters\n"
1103 "AS number\n"
1104 "Set routing domain confederation AS\n")
1105{
d62a17ae 1106 VTY_DECLVAR_CONTEXT(bgp, bgp);
1107 int idx_number = 3;
1108 as_t as;
718e3744 1109
d62a17ae 1110 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1111
d62a17ae 1112 bgp_confederation_id_set(bgp, as);
718e3744 1113
d62a17ae 1114 return CMD_SUCCESS;
718e3744 1115}
1116
1117DEFUN (no_bgp_confederation_identifier,
1118 no_bgp_confederation_identifier_cmd,
838758ac 1119 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1120 NO_STR
1121 "BGP specific commands\n"
1122 "AS confederation parameters\n"
3a2d747c
QY
1123 "AS number\n"
1124 "Set routing domain confederation AS\n")
718e3744 1125{
d62a17ae 1126 VTY_DECLVAR_CONTEXT(bgp, bgp);
1127 bgp_confederation_id_unset(bgp);
718e3744 1128
d62a17ae 1129 return CMD_SUCCESS;
718e3744 1130}
1131
718e3744 1132DEFUN (bgp_confederation_peers,
1133 bgp_confederation_peers_cmd,
12dcf78e 1134 "bgp confederation peers (1-4294967295)...",
718e3744 1135 "BGP specific commands\n"
1136 "AS confederation parameters\n"
1137 "Peer ASs in BGP confederation\n"
1138 AS_STR)
1139{
d62a17ae 1140 VTY_DECLVAR_CONTEXT(bgp, bgp);
1141 int idx_asn = 3;
1142 as_t as;
1143 int i;
718e3744 1144
d62a17ae 1145 for (i = idx_asn; i < argc; i++) {
1146 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1147
d62a17ae 1148 if (bgp->as == as) {
1149 vty_out(vty,
1150 "%% Local member-AS not allowed in confed peer list\n");
1151 continue;
1152 }
718e3744 1153
d62a17ae 1154 bgp_confederation_peers_add(bgp, as);
1155 }
1156 return CMD_SUCCESS;
718e3744 1157}
1158
1159DEFUN (no_bgp_confederation_peers,
1160 no_bgp_confederation_peers_cmd,
e83a9414 1161 "no bgp confederation peers (1-4294967295)...",
718e3744 1162 NO_STR
1163 "BGP specific commands\n"
1164 "AS confederation parameters\n"
1165 "Peer ASs in BGP confederation\n"
1166 AS_STR)
1167{
d62a17ae 1168 VTY_DECLVAR_CONTEXT(bgp, bgp);
1169 int idx_asn = 4;
1170 as_t as;
1171 int i;
718e3744 1172
d62a17ae 1173 for (i = idx_asn; i < argc; i++) {
1174 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1175
d62a17ae 1176 bgp_confederation_peers_remove(bgp, as);
1177 }
1178 return CMD_SUCCESS;
718e3744 1179}
6b0655a2 1180
5e242b0d
DS
1181/**
1182 * Central routine for maximum-paths configuration.
1183 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1184 * @set: 1 for setting values, 0 for removing the max-paths config.
1185 */
d62a17ae 1186static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1187 const char *mpaths, uint16_t options,
d62a17ae 1188 int set)
1189{
1190 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1191 uint16_t maxpaths = 0;
d62a17ae 1192 int ret;
1193 afi_t afi;
1194 safi_t safi;
1195
1196 afi = bgp_node_afi(vty);
1197 safi = bgp_node_safi(vty);
1198
1199 if (set) {
1200 maxpaths = strtol(mpaths, NULL, 10);
1201 if (maxpaths > multipath_num) {
1202 vty_out(vty,
1203 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1204 maxpaths, multipath_num);
1205 return CMD_WARNING_CONFIG_FAILED;
1206 }
1207 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1208 options);
1209 } else
1210 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1211
1212 if (ret < 0) {
1213 vty_out(vty,
1214 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1215 (set == 1) ? "" : "un",
1216 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1217 maxpaths, afi, safi);
1218 return CMD_WARNING_CONFIG_FAILED;
1219 }
1220
1221 bgp_recalculate_all_bestpaths(bgp);
1222
1223 return CMD_SUCCESS;
165b5fff
JB
1224}
1225
abc920f8
DS
1226DEFUN (bgp_maxmed_admin,
1227 bgp_maxmed_admin_cmd,
1228 "bgp max-med administrative ",
1229 BGP_STR
1230 "Advertise routes with max-med\n"
1231 "Administratively applied, for an indefinite period\n")
1232{
d62a17ae 1233 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1234
d62a17ae 1235 bgp->v_maxmed_admin = 1;
1236 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1237
d62a17ae 1238 bgp_maxmed_update(bgp);
abc920f8 1239
d62a17ae 1240 return CMD_SUCCESS;
abc920f8
DS
1241}
1242
1243DEFUN (bgp_maxmed_admin_medv,
1244 bgp_maxmed_admin_medv_cmd,
4668a151 1245 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1246 BGP_STR
1247 "Advertise routes with max-med\n"
1248 "Administratively applied, for an indefinite period\n"
1249 "Max MED value to be used\n")
1250{
d62a17ae 1251 VTY_DECLVAR_CONTEXT(bgp, bgp);
1252 int idx_number = 3;
abc920f8 1253
d62a17ae 1254 bgp->v_maxmed_admin = 1;
1255 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1256
d62a17ae 1257 bgp_maxmed_update(bgp);
abc920f8 1258
d62a17ae 1259 return CMD_SUCCESS;
abc920f8
DS
1260}
1261
1262DEFUN (no_bgp_maxmed_admin,
1263 no_bgp_maxmed_admin_cmd,
4668a151 1264 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1265 NO_STR
1266 BGP_STR
1267 "Advertise routes with max-med\n"
838758ac
DW
1268 "Administratively applied, for an indefinite period\n"
1269 "Max MED value to be used\n")
abc920f8 1270{
d62a17ae 1271 VTY_DECLVAR_CONTEXT(bgp, bgp);
1272 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1273 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1274 bgp_maxmed_update(bgp);
abc920f8 1275
d62a17ae 1276 return CMD_SUCCESS;
abc920f8
DS
1277}
1278
abc920f8
DS
1279DEFUN (bgp_maxmed_onstartup,
1280 bgp_maxmed_onstartup_cmd,
4668a151 1281 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1282 BGP_STR
1283 "Advertise routes with max-med\n"
1284 "Effective on a startup\n"
1285 "Time (seconds) period for max-med\n"
1286 "Max MED value to be used\n")
1287{
d62a17ae 1288 VTY_DECLVAR_CONTEXT(bgp, bgp);
1289 int idx = 0;
4668a151 1290
d62a17ae 1291 argv_find(argv, argc, "(5-86400)", &idx);
1292 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1293 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1294 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1295 else
1296 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1297
d62a17ae 1298 bgp_maxmed_update(bgp);
abc920f8 1299
d62a17ae 1300 return CMD_SUCCESS;
abc920f8
DS
1301}
1302
1303DEFUN (no_bgp_maxmed_onstartup,
1304 no_bgp_maxmed_onstartup_cmd,
4668a151 1305 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1306 NO_STR
1307 BGP_STR
1308 "Advertise routes with max-med\n"
838758ac
DW
1309 "Effective on a startup\n"
1310 "Time (seconds) period for max-med\n"
1311 "Max MED value to be used\n")
abc920f8 1312{
d62a17ae 1313 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1314
d62a17ae 1315 /* Cancel max-med onstartup if its on */
1316 if (bgp->t_maxmed_onstartup) {
1317 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1318 bgp->maxmed_onstartup_over = 1;
1319 }
abc920f8 1320
d62a17ae 1321 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1322 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1323
d62a17ae 1324 bgp_maxmed_update(bgp);
abc920f8 1325
d62a17ae 1326 return CMD_SUCCESS;
abc920f8
DS
1327}
1328
d62a17ae 1329static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1330 const char *wait)
f188f2c4 1331{
d62a17ae 1332 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1333 uint16_t update_delay;
1334 uint16_t establish_wait;
f188f2c4 1335
d62a17ae 1336 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1337
d62a17ae 1338 if (!wait) /* update-delay <delay> */
1339 {
1340 bgp->v_update_delay = update_delay;
1341 bgp->v_establish_wait = bgp->v_update_delay;
1342 return CMD_SUCCESS;
1343 }
f188f2c4 1344
d62a17ae 1345 /* update-delay <delay> <establish-wait> */
1346 establish_wait = atoi(wait);
1347 if (update_delay < establish_wait) {
1348 vty_out(vty,
1349 "%%Failed: update-delay less than the establish-wait!\n");
1350 return CMD_WARNING_CONFIG_FAILED;
1351 }
f188f2c4 1352
d62a17ae 1353 bgp->v_update_delay = update_delay;
1354 bgp->v_establish_wait = establish_wait;
f188f2c4 1355
d62a17ae 1356 return CMD_SUCCESS;
f188f2c4
DS
1357}
1358
d62a17ae 1359static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1360{
d62a17ae 1361 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1362
d62a17ae 1363 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1364 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1365
d62a17ae 1366 return CMD_SUCCESS;
f188f2c4
DS
1367}
1368
2b791107 1369void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1370{
d62a17ae 1371 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1372 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1373 if (bgp->v_update_delay != bgp->v_establish_wait)
1374 vty_out(vty, " %d", bgp->v_establish_wait);
1375 vty_out(vty, "\n");
1376 }
f188f2c4
DS
1377}
1378
1379
1380/* Update-delay configuration */
1381DEFUN (bgp_update_delay,
1382 bgp_update_delay_cmd,
6147e2c6 1383 "update-delay (0-3600)",
f188f2c4
DS
1384 "Force initial delay for best-path and updates\n"
1385 "Seconds\n")
1386{
d62a17ae 1387 int idx_number = 1;
1388 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1389}
1390
1391DEFUN (bgp_update_delay_establish_wait,
1392 bgp_update_delay_establish_wait_cmd,
6147e2c6 1393 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1394 "Force initial delay for best-path and updates\n"
1395 "Seconds\n"
f188f2c4
DS
1396 "Seconds\n")
1397{
d62a17ae 1398 int idx_number = 1;
1399 int idx_number_2 = 2;
1400 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1401 argv[idx_number_2]->arg);
f188f2c4
DS
1402}
1403
1404/* Update-delay deconfiguration */
1405DEFUN (no_bgp_update_delay,
1406 no_bgp_update_delay_cmd,
838758ac
DW
1407 "no update-delay [(0-3600) [(1-3600)]]",
1408 NO_STR
f188f2c4 1409 "Force initial delay for best-path and updates\n"
838758ac 1410 "Seconds\n"
7111c1a0 1411 "Seconds\n")
f188f2c4 1412{
d62a17ae 1413 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1414}
1415
5e242b0d 1416
d62a17ae 1417static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1418 char set)
cb1faec9 1419{
d62a17ae 1420 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1421
555e09d4
QY
1422 if (set) {
1423 uint32_t quanta = strtoul(num, NULL, 10);
1424 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1425 memory_order_relaxed);
1426 } else {
1427 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1428 memory_order_relaxed);
1429 }
1430
1431 return CMD_SUCCESS;
1432}
1433
1434static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1435 char set)
1436{
1437 VTY_DECLVAR_CONTEXT(bgp, bgp);
1438
1439 if (set) {
1440 uint32_t quanta = strtoul(num, NULL, 10);
1441 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1442 memory_order_relaxed);
1443 } else {
1444 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1445 memory_order_relaxed);
1446 }
cb1faec9 1447
d62a17ae 1448 return CMD_SUCCESS;
cb1faec9
DS
1449}
1450
2b791107 1451void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1452{
555e09d4
QY
1453 uint32_t quanta =
1454 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1455 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1456 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1457}
1458
555e09d4
QY
1459void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1460{
1461 uint32_t quanta =
1462 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1463 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1464 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1465}
cb1faec9 1466
555e09d4 1467/* Packet quanta configuration */
cb1faec9
DS
1468DEFUN (bgp_wpkt_quanta,
1469 bgp_wpkt_quanta_cmd,
555e09d4 1470 "write-quanta (1-10)",
cb1faec9
DS
1471 "How many packets to write to peer socket per run\n"
1472 "Number of packets\n")
1473{
d62a17ae 1474 int idx_number = 1;
1475 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1476}
1477
cb1faec9
DS
1478DEFUN (no_bgp_wpkt_quanta,
1479 no_bgp_wpkt_quanta_cmd,
555e09d4 1480 "no write-quanta (1-10)",
d7fa34c1 1481 NO_STR
555e09d4 1482 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1483 "Number of packets\n")
1484{
d62a17ae 1485 int idx_number = 2;
1486 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1487}
1488
555e09d4
QY
1489DEFUN (bgp_rpkt_quanta,
1490 bgp_rpkt_quanta_cmd,
1491 "read-quanta (1-10)",
1492 "How many packets to read from peer socket per I/O cycle\n"
1493 "Number of packets\n")
1494{
1495 int idx_number = 1;
1496 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1497}
1498
1499DEFUN (no_bgp_rpkt_quanta,
1500 no_bgp_rpkt_quanta_cmd,
1501 "no read-quanta (1-10)",
1502 NO_STR
1503 "How many packets to read from peer socket per I/O cycle\n"
1504 "Number of packets\n")
1505{
1506 int idx_number = 2;
1507 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1508}
1509
2b791107 1510void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1511{
37a333fe 1512 if (!bgp->heuristic_coalesce)
d62a17ae 1513 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1514}
1515
1516
1517DEFUN (bgp_coalesce_time,
1518 bgp_coalesce_time_cmd,
6147e2c6 1519 "coalesce-time (0-4294967295)",
3f9c7369
DS
1520 "Subgroup coalesce timer\n"
1521 "Subgroup coalesce timer value (in ms)\n")
1522{
d62a17ae 1523 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1524
d62a17ae 1525 int idx = 0;
1526 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1527 bgp->heuristic_coalesce = false;
d62a17ae 1528 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1529 return CMD_SUCCESS;
3f9c7369
DS
1530}
1531
1532DEFUN (no_bgp_coalesce_time,
1533 no_bgp_coalesce_time_cmd,
6147e2c6 1534 "no coalesce-time (0-4294967295)",
3a2d747c 1535 NO_STR
3f9c7369
DS
1536 "Subgroup coalesce timer\n"
1537 "Subgroup coalesce timer value (in ms)\n")
1538{
d62a17ae 1539 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1540
37a333fe 1541 bgp->heuristic_coalesce = true;
d62a17ae 1542 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1543 return CMD_SUCCESS;
3f9c7369
DS
1544}
1545
5e242b0d
DS
1546/* Maximum-paths configuration */
1547DEFUN (bgp_maxpaths,
1548 bgp_maxpaths_cmd,
6319fd63 1549 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1550 "Forward packets over multiple paths\n"
1551 "Number of paths\n")
1552{
d62a17ae 1553 int idx_number = 1;
1554 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1555 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1556}
1557
d62a17ae 1558ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1559 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1560 "Forward packets over multiple paths\n"
1561 "Number of paths\n")
596c17ba 1562
165b5fff
JB
1563DEFUN (bgp_maxpaths_ibgp,
1564 bgp_maxpaths_ibgp_cmd,
6319fd63 1565 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1566 "Forward packets over multiple paths\n"
1567 "iBGP-multipath\n"
1568 "Number of paths\n")
1569{
d62a17ae 1570 int idx_number = 2;
1571 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1572 argv[idx_number]->arg, 0, 1);
5e242b0d 1573}
165b5fff 1574
d62a17ae 1575ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1576 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1577 "Forward packets over multiple paths\n"
1578 "iBGP-multipath\n"
1579 "Number of paths\n")
596c17ba 1580
5e242b0d
DS
1581DEFUN (bgp_maxpaths_ibgp_cluster,
1582 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1583 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1584 "Forward packets over multiple paths\n"
1585 "iBGP-multipath\n"
1586 "Number of paths\n"
1587 "Match the cluster length\n")
1588{
d62a17ae 1589 int idx_number = 2;
1590 return bgp_maxpaths_config_vty(
1591 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1592 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1593}
1594
d62a17ae 1595ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1596 "maximum-paths ibgp " CMD_RANGE_STR(
1597 1, MULTIPATH_NUM) " equal-cluster-length",
1598 "Forward packets over multiple paths\n"
1599 "iBGP-multipath\n"
1600 "Number of paths\n"
1601 "Match the cluster length\n")
596c17ba 1602
165b5fff
JB
1603DEFUN (no_bgp_maxpaths,
1604 no_bgp_maxpaths_cmd,
6319fd63 1605 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1606 NO_STR
1607 "Forward packets over multiple paths\n"
1608 "Number of paths\n")
1609{
d62a17ae 1610 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1611}
1612
d62a17ae 1613ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1614 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1615 "Forward packets over multiple paths\n"
1616 "Number of paths\n")
596c17ba 1617
165b5fff
JB
1618DEFUN (no_bgp_maxpaths_ibgp,
1619 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1620 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1621 NO_STR
1622 "Forward packets over multiple paths\n"
1623 "iBGP-multipath\n"
838758ac
DW
1624 "Number of paths\n"
1625 "Match the cluster length\n")
165b5fff 1626{
d62a17ae 1627 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1628}
1629
d62a17ae 1630ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1631 "no maximum-paths ibgp [" CMD_RANGE_STR(
1632 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1633 NO_STR
1634 "Forward packets over multiple paths\n"
1635 "iBGP-multipath\n"
1636 "Number of paths\n"
1637 "Match the cluster length\n")
596c17ba 1638
2b791107 1639void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1640 safi_t safi)
165b5fff 1641{
d62a17ae 1642 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1643 vty_out(vty, " maximum-paths %d\n",
1644 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1645 }
165b5fff 1646
d62a17ae 1647 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1648 vty_out(vty, " maximum-paths ibgp %d",
1649 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1650 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1651 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1652 vty_out(vty, " equal-cluster-length");
1653 vty_out(vty, "\n");
1654 }
165b5fff 1655}
6b0655a2 1656
718e3744 1657/* BGP timers. */
1658
1659DEFUN (bgp_timers,
1660 bgp_timers_cmd,
6147e2c6 1661 "timers bgp (0-65535) (0-65535)",
718e3744 1662 "Adjust routing timers\n"
1663 "BGP timers\n"
1664 "Keepalive interval\n"
1665 "Holdtime\n")
1666{
d62a17ae 1667 VTY_DECLVAR_CONTEXT(bgp, bgp);
1668 int idx_number = 2;
1669 int idx_number_2 = 3;
1670 unsigned long keepalive = 0;
1671 unsigned long holdtime = 0;
718e3744 1672
d62a17ae 1673 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1674 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1675
d62a17ae 1676 /* Holdtime value check. */
1677 if (holdtime < 3 && holdtime != 0) {
1678 vty_out(vty,
1679 "%% hold time value must be either 0 or greater than 3\n");
1680 return CMD_WARNING_CONFIG_FAILED;
1681 }
718e3744 1682
d62a17ae 1683 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1684
d62a17ae 1685 return CMD_SUCCESS;
718e3744 1686}
1687
1688DEFUN (no_bgp_timers,
1689 no_bgp_timers_cmd,
838758ac 1690 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1691 NO_STR
1692 "Adjust routing timers\n"
838758ac
DW
1693 "BGP timers\n"
1694 "Keepalive interval\n"
1695 "Holdtime\n")
718e3744 1696{
d62a17ae 1697 VTY_DECLVAR_CONTEXT(bgp, bgp);
1698 bgp_timers_unset(bgp);
718e3744 1699
d62a17ae 1700 return CMD_SUCCESS;
718e3744 1701}
1702
6b0655a2 1703
718e3744 1704DEFUN (bgp_client_to_client_reflection,
1705 bgp_client_to_client_reflection_cmd,
1706 "bgp client-to-client reflection",
1707 "BGP specific commands\n"
1708 "Configure client to client route reflection\n"
1709 "reflection of routes allowed\n")
1710{
d62a17ae 1711 VTY_DECLVAR_CONTEXT(bgp, bgp);
1712 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1713 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1714
d62a17ae 1715 return CMD_SUCCESS;
718e3744 1716}
1717
1718DEFUN (no_bgp_client_to_client_reflection,
1719 no_bgp_client_to_client_reflection_cmd,
1720 "no bgp client-to-client reflection",
1721 NO_STR
1722 "BGP specific commands\n"
1723 "Configure client to client route reflection\n"
1724 "reflection of routes allowed\n")
1725{
d62a17ae 1726 VTY_DECLVAR_CONTEXT(bgp, bgp);
1727 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1728 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1729
d62a17ae 1730 return CMD_SUCCESS;
718e3744 1731}
1732
1733/* "bgp always-compare-med" configuration. */
1734DEFUN (bgp_always_compare_med,
1735 bgp_always_compare_med_cmd,
1736 "bgp always-compare-med",
1737 "BGP specific commands\n"
1738 "Allow comparing MED from different neighbors\n")
1739{
d62a17ae 1740 VTY_DECLVAR_CONTEXT(bgp, bgp);
1741 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1742 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1743
d62a17ae 1744 return CMD_SUCCESS;
718e3744 1745}
1746
1747DEFUN (no_bgp_always_compare_med,
1748 no_bgp_always_compare_med_cmd,
1749 "no bgp always-compare-med",
1750 NO_STR
1751 "BGP specific commands\n"
1752 "Allow comparing MED from different neighbors\n")
1753{
d62a17ae 1754 VTY_DECLVAR_CONTEXT(bgp, bgp);
1755 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1756 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1757
d62a17ae 1758 return CMD_SUCCESS;
718e3744 1759}
6b0655a2 1760
718e3744 1761/* "bgp deterministic-med" configuration. */
1762DEFUN (bgp_deterministic_med,
1763 bgp_deterministic_med_cmd,
1764 "bgp deterministic-med",
1765 "BGP specific commands\n"
1766 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1767{
d62a17ae 1768 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1769
d62a17ae 1770 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1771 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1772 bgp_recalculate_all_bestpaths(bgp);
1773 }
7aafcaca 1774
d62a17ae 1775 return CMD_SUCCESS;
718e3744 1776}
1777
1778DEFUN (no_bgp_deterministic_med,
1779 no_bgp_deterministic_med_cmd,
1780 "no bgp deterministic-med",
1781 NO_STR
1782 "BGP specific commands\n"
1783 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1784{
d62a17ae 1785 VTY_DECLVAR_CONTEXT(bgp, bgp);
1786 int bestpath_per_as_used;
1787 afi_t afi;
1788 safi_t safi;
1789 struct peer *peer;
1790 struct listnode *node, *nnode;
1791
1792 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1793 bestpath_per_as_used = 0;
1794
1795 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc
QY
1796 FOREACH_AFI_SAFI (afi, safi)
1797 if (CHECK_FLAG(
1798 peer->af_flags[afi][safi],
1799 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1800 bestpath_per_as_used = 1;
1801 break;
1802 }
d62a17ae 1803
1804 if (bestpath_per_as_used)
1805 break;
1806 }
1807
1808 if (bestpath_per_as_used) {
1809 vty_out(vty,
1810 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1811 return CMD_WARNING_CONFIG_FAILED;
1812 } else {
1813 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1814 bgp_recalculate_all_bestpaths(bgp);
1815 }
1816 }
1817
1818 return CMD_SUCCESS;
718e3744 1819}
538621f2 1820
1821/* "bgp graceful-restart" configuration. */
1822DEFUN (bgp_graceful_restart,
1823 bgp_graceful_restart_cmd,
1824 "bgp graceful-restart",
1825 "BGP specific commands\n"
1826 "Graceful restart capability parameters\n")
1827{
d62a17ae 1828 VTY_DECLVAR_CONTEXT(bgp, bgp);
1829 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1830 return CMD_SUCCESS;
538621f2 1831}
1832
1833DEFUN (no_bgp_graceful_restart,
1834 no_bgp_graceful_restart_cmd,
1835 "no bgp graceful-restart",
1836 NO_STR
1837 "BGP specific commands\n"
1838 "Graceful restart capability parameters\n")
1839{
d62a17ae 1840 VTY_DECLVAR_CONTEXT(bgp, bgp);
1841 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1842 return CMD_SUCCESS;
538621f2 1843}
1844
93406d87 1845DEFUN (bgp_graceful_restart_stalepath_time,
1846 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1847 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1848 "BGP specific commands\n"
1849 "Graceful restart capability parameters\n"
1850 "Set the max time to hold onto restarting peer's stale paths\n"
1851 "Delay value (seconds)\n")
1852{
d62a17ae 1853 VTY_DECLVAR_CONTEXT(bgp, bgp);
1854 int idx_number = 3;
d7c0a89a 1855 uint32_t stalepath;
93406d87 1856
d62a17ae 1857 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1858 bgp->stalepath_time = stalepath;
1859 return CMD_SUCCESS;
93406d87 1860}
1861
eb6f1b41
PG
1862DEFUN (bgp_graceful_restart_restart_time,
1863 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1864 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1865 "BGP specific commands\n"
1866 "Graceful restart capability parameters\n"
1867 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1868 "Delay value (seconds)\n")
1869{
d62a17ae 1870 VTY_DECLVAR_CONTEXT(bgp, bgp);
1871 int idx_number = 3;
d7c0a89a 1872 uint32_t restart;
eb6f1b41 1873
d62a17ae 1874 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1875 bgp->restart_time = restart;
1876 return CMD_SUCCESS;
eb6f1b41
PG
1877}
1878
93406d87 1879DEFUN (no_bgp_graceful_restart_stalepath_time,
1880 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1881 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1882 NO_STR
1883 "BGP specific commands\n"
1884 "Graceful restart capability parameters\n"
838758ac
DW
1885 "Set the max time to hold onto restarting peer's stale paths\n"
1886 "Delay value (seconds)\n")
93406d87 1887{
d62a17ae 1888 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1889
d62a17ae 1890 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1891 return CMD_SUCCESS;
93406d87 1892}
1893
eb6f1b41
PG
1894DEFUN (no_bgp_graceful_restart_restart_time,
1895 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1896 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1897 NO_STR
1898 "BGP specific commands\n"
1899 "Graceful restart capability parameters\n"
838758ac
DW
1900 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1901 "Delay value (seconds)\n")
eb6f1b41 1902{
d62a17ae 1903 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1904
d62a17ae 1905 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1906 return CMD_SUCCESS;
eb6f1b41
PG
1907}
1908
43fc21b3
JC
1909DEFUN (bgp_graceful_restart_preserve_fw,
1910 bgp_graceful_restart_preserve_fw_cmd,
1911 "bgp graceful-restart preserve-fw-state",
1912 "BGP specific commands\n"
1913 "Graceful restart capability parameters\n"
1914 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1915{
d62a17ae 1916 VTY_DECLVAR_CONTEXT(bgp, bgp);
1917 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1918 return CMD_SUCCESS;
43fc21b3
JC
1919}
1920
1921DEFUN (no_bgp_graceful_restart_preserve_fw,
1922 no_bgp_graceful_restart_preserve_fw_cmd,
1923 "no bgp graceful-restart preserve-fw-state",
1924 NO_STR
1925 "BGP specific commands\n"
1926 "Graceful restart capability parameters\n"
1927 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1928{
d62a17ae 1929 VTY_DECLVAR_CONTEXT(bgp, bgp);
1930 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1931 return CMD_SUCCESS;
43fc21b3
JC
1932}
1933
7f323236
DW
1934static void bgp_redistribute_redo(struct bgp *bgp)
1935{
1936 afi_t afi;
1937 int i;
1938 struct list *red_list;
1939 struct listnode *node;
1940 struct bgp_redist *red;
1941
a4d82a8a
PZ
1942 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1943 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 1944
a4d82a8a
PZ
1945 red_list = bgp->redist[afi][i];
1946 if (!red_list)
1947 continue;
7f323236 1948
a4d82a8a 1949 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
1950 bgp_redistribute_resend(bgp, afi, i,
1951 red->instance);
1952 }
1953 }
1954 }
1955}
1956
1957/* "bgp graceful-shutdown" configuration */
1958DEFUN (bgp_graceful_shutdown,
1959 bgp_graceful_shutdown_cmd,
1960 "bgp graceful-shutdown",
1961 BGP_STR
1962 "Graceful shutdown parameters\n")
1963{
1964 VTY_DECLVAR_CONTEXT(bgp, bgp);
1965
1966 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1967 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1968 bgp_static_redo_import_check(bgp);
1969 bgp_redistribute_redo(bgp);
1970 bgp_clear_star_soft_out(vty, bgp->name);
1971 bgp_clear_star_soft_in(vty, bgp->name);
1972 }
1973
1974 return CMD_SUCCESS;
1975}
1976
1977DEFUN (no_bgp_graceful_shutdown,
1978 no_bgp_graceful_shutdown_cmd,
1979 "no bgp graceful-shutdown",
1980 NO_STR
1981 BGP_STR
1982 "Graceful shutdown parameters\n")
1983{
1984 VTY_DECLVAR_CONTEXT(bgp, bgp);
1985
1986 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1987 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1988 bgp_static_redo_import_check(bgp);
1989 bgp_redistribute_redo(bgp);
1990 bgp_clear_star_soft_out(vty, bgp->name);
1991 bgp_clear_star_soft_in(vty, bgp->name);
1992 }
1993
1994 return CMD_SUCCESS;
1995}
1996
718e3744 1997/* "bgp fast-external-failover" configuration. */
1998DEFUN (bgp_fast_external_failover,
1999 bgp_fast_external_failover_cmd,
2000 "bgp fast-external-failover",
2001 BGP_STR
2002 "Immediately reset session if a link to a directly connected external peer goes down\n")
2003{
d62a17ae 2004 VTY_DECLVAR_CONTEXT(bgp, bgp);
2005 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2006 return CMD_SUCCESS;
718e3744 2007}
2008
2009DEFUN (no_bgp_fast_external_failover,
2010 no_bgp_fast_external_failover_cmd,
2011 "no bgp fast-external-failover",
2012 NO_STR
2013 BGP_STR
2014 "Immediately reset session if a link to a directly connected external peer goes down\n")
2015{
d62a17ae 2016 VTY_DECLVAR_CONTEXT(bgp, bgp);
2017 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2018 return CMD_SUCCESS;
718e3744 2019}
6b0655a2 2020
718e3744 2021/* "bgp enforce-first-as" configuration. */
ec4f0750 2022#if CONFDATE > 20190517
47cbc09b
PM
2023CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2024#endif
2025
f07e1c4f
QY
2026DEFUN_HIDDEN (bgp_enforce_first_as,
2027 bgp_enforce_first_as_cmd,
2028 "[no] bgp enforce-first-as",
2029 NO_STR
2030 BGP_STR
2031 "Enforce the first AS for EBGP routes\n")
718e3744 2032{
d62a17ae 2033 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2034
f07e1c4f
QY
2035 if (strmatch(argv[0]->text, "no"))
2036 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2037 else
2038 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
7aafcaca 2039
d62a17ae 2040 return CMD_SUCCESS;
718e3744 2041}
6b0655a2 2042
718e3744 2043/* "bgp bestpath compare-routerid" configuration. */
2044DEFUN (bgp_bestpath_compare_router_id,
2045 bgp_bestpath_compare_router_id_cmd,
2046 "bgp bestpath compare-routerid",
2047 "BGP specific commands\n"
2048 "Change the default bestpath selection\n"
2049 "Compare router-id for identical EBGP paths\n")
2050{
d62a17ae 2051 VTY_DECLVAR_CONTEXT(bgp, bgp);
2052 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2053 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2054
d62a17ae 2055 return CMD_SUCCESS;
718e3744 2056}
2057
2058DEFUN (no_bgp_bestpath_compare_router_id,
2059 no_bgp_bestpath_compare_router_id_cmd,
2060 "no bgp bestpath compare-routerid",
2061 NO_STR
2062 "BGP specific commands\n"
2063 "Change the default bestpath selection\n"
2064 "Compare router-id for identical EBGP paths\n")
2065{
d62a17ae 2066 VTY_DECLVAR_CONTEXT(bgp, bgp);
2067 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2068 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2069
d62a17ae 2070 return CMD_SUCCESS;
718e3744 2071}
6b0655a2 2072
718e3744 2073/* "bgp bestpath as-path ignore" configuration. */
2074DEFUN (bgp_bestpath_aspath_ignore,
2075 bgp_bestpath_aspath_ignore_cmd,
2076 "bgp bestpath as-path ignore",
2077 "BGP specific commands\n"
2078 "Change the default bestpath selection\n"
2079 "AS-path attribute\n"
2080 "Ignore as-path length in selecting a route\n")
2081{
d62a17ae 2082 VTY_DECLVAR_CONTEXT(bgp, bgp);
2083 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2084 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2085
d62a17ae 2086 return CMD_SUCCESS;
718e3744 2087}
2088
2089DEFUN (no_bgp_bestpath_aspath_ignore,
2090 no_bgp_bestpath_aspath_ignore_cmd,
2091 "no bgp bestpath as-path ignore",
2092 NO_STR
2093 "BGP specific commands\n"
2094 "Change the default bestpath selection\n"
2095 "AS-path attribute\n"
2096 "Ignore as-path length in selecting a route\n")
2097{
d62a17ae 2098 VTY_DECLVAR_CONTEXT(bgp, bgp);
2099 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2100 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2101
d62a17ae 2102 return CMD_SUCCESS;
718e3744 2103}
6b0655a2 2104
6811845b 2105/* "bgp bestpath as-path confed" configuration. */
2106DEFUN (bgp_bestpath_aspath_confed,
2107 bgp_bestpath_aspath_confed_cmd,
2108 "bgp bestpath as-path confed",
2109 "BGP specific commands\n"
2110 "Change the default bestpath selection\n"
2111 "AS-path attribute\n"
2112 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2113{
d62a17ae 2114 VTY_DECLVAR_CONTEXT(bgp, bgp);
2115 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2116 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2117
d62a17ae 2118 return CMD_SUCCESS;
6811845b 2119}
2120
2121DEFUN (no_bgp_bestpath_aspath_confed,
2122 no_bgp_bestpath_aspath_confed_cmd,
2123 "no bgp bestpath as-path confed",
2124 NO_STR
2125 "BGP specific commands\n"
2126 "Change the default bestpath selection\n"
2127 "AS-path attribute\n"
2128 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2129{
d62a17ae 2130 VTY_DECLVAR_CONTEXT(bgp, bgp);
2131 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2132 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2133
d62a17ae 2134 return CMD_SUCCESS;
6811845b 2135}
6b0655a2 2136
2fdd455c
PM
2137/* "bgp bestpath as-path multipath-relax" configuration. */
2138DEFUN (bgp_bestpath_aspath_multipath_relax,
2139 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2140 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2141 "BGP specific commands\n"
2142 "Change the default bestpath selection\n"
2143 "AS-path attribute\n"
2144 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2145 "Generate an AS_SET\n"
16fc1eec
DS
2146 "Do not generate an AS_SET\n")
2147{
d62a17ae 2148 VTY_DECLVAR_CONTEXT(bgp, bgp);
2149 int idx = 0;
2150 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2151
d62a17ae 2152 /* no-as-set is now the default behavior so we can silently
2153 * ignore it */
2154 if (argv_find(argv, argc, "as-set", &idx))
2155 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2156 else
2157 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2158
d62a17ae 2159 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2160
d62a17ae 2161 return CMD_SUCCESS;
16fc1eec
DS
2162}
2163
219178b6
DW
2164DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2165 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2166 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2167 NO_STR
2168 "BGP specific commands\n"
2169 "Change the default bestpath selection\n"
2170 "AS-path attribute\n"
2171 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2172 "Generate an AS_SET\n"
16fc1eec
DS
2173 "Do not generate an AS_SET\n")
2174{
d62a17ae 2175 VTY_DECLVAR_CONTEXT(bgp, bgp);
2176 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2177 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2178 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2179
d62a17ae 2180 return CMD_SUCCESS;
2fdd455c 2181}
6b0655a2 2182
848973c7 2183/* "bgp log-neighbor-changes" configuration. */
2184DEFUN (bgp_log_neighbor_changes,
2185 bgp_log_neighbor_changes_cmd,
2186 "bgp log-neighbor-changes",
2187 "BGP specific commands\n"
2188 "Log neighbor up/down and reset reason\n")
2189{
d62a17ae 2190 VTY_DECLVAR_CONTEXT(bgp, bgp);
2191 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2192 return CMD_SUCCESS;
848973c7 2193}
2194
2195DEFUN (no_bgp_log_neighbor_changes,
2196 no_bgp_log_neighbor_changes_cmd,
2197 "no bgp log-neighbor-changes",
2198 NO_STR
2199 "BGP specific commands\n"
2200 "Log neighbor up/down and reset reason\n")
2201{
d62a17ae 2202 VTY_DECLVAR_CONTEXT(bgp, bgp);
2203 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2204 return CMD_SUCCESS;
848973c7 2205}
6b0655a2 2206
718e3744 2207/* "bgp bestpath med" configuration. */
2208DEFUN (bgp_bestpath_med,
2209 bgp_bestpath_med_cmd,
2d8c1a4d 2210 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2211 "BGP specific commands\n"
2212 "Change the default bestpath selection\n"
2213 "MED attribute\n"
2214 "Compare MED among confederation paths\n"
838758ac
DW
2215 "Treat missing MED as the least preferred one\n"
2216 "Treat missing MED as the least preferred one\n"
2217 "Compare MED among confederation paths\n")
718e3744 2218{
d62a17ae 2219 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2220
d62a17ae 2221 int idx = 0;
2222 if (argv_find(argv, argc, "confed", &idx))
2223 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2224 idx = 0;
2225 if (argv_find(argv, argc, "missing-as-worst", &idx))
2226 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2227
d62a17ae 2228 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2229
d62a17ae 2230 return CMD_SUCCESS;
718e3744 2231}
2232
718e3744 2233DEFUN (no_bgp_bestpath_med,
2234 no_bgp_bestpath_med_cmd,
2d8c1a4d 2235 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2236 NO_STR
2237 "BGP specific commands\n"
2238 "Change the default bestpath selection\n"
2239 "MED attribute\n"
2240 "Compare MED among confederation paths\n"
3a2d747c
QY
2241 "Treat missing MED as the least preferred one\n"
2242 "Treat missing MED as the least preferred one\n"
2243 "Compare MED among confederation paths\n")
718e3744 2244{
d62a17ae 2245 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2246
d62a17ae 2247 int idx = 0;
2248 if (argv_find(argv, argc, "confed", &idx))
2249 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2250 idx = 0;
2251 if (argv_find(argv, argc, "missing-as-worst", &idx))
2252 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2253
d62a17ae 2254 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2255
d62a17ae 2256 return CMD_SUCCESS;
718e3744 2257}
2258
718e3744 2259/* "no bgp default ipv4-unicast". */
2260DEFUN (no_bgp_default_ipv4_unicast,
2261 no_bgp_default_ipv4_unicast_cmd,
2262 "no bgp default ipv4-unicast",
2263 NO_STR
2264 "BGP specific commands\n"
2265 "Configure BGP defaults\n"
2266 "Activate ipv4-unicast for a peer by default\n")
2267{
d62a17ae 2268 VTY_DECLVAR_CONTEXT(bgp, bgp);
2269 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2270 return CMD_SUCCESS;
718e3744 2271}
2272
2273DEFUN (bgp_default_ipv4_unicast,
2274 bgp_default_ipv4_unicast_cmd,
2275 "bgp default ipv4-unicast",
2276 "BGP specific commands\n"
2277 "Configure BGP defaults\n"
2278 "Activate ipv4-unicast for a peer by default\n")
2279{
d62a17ae 2280 VTY_DECLVAR_CONTEXT(bgp, bgp);
2281 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2282 return CMD_SUCCESS;
718e3744 2283}
6b0655a2 2284
04b6bdc0
DW
2285/* Display hostname in certain command outputs */
2286DEFUN (bgp_default_show_hostname,
2287 bgp_default_show_hostname_cmd,
2288 "bgp default show-hostname",
2289 "BGP specific commands\n"
2290 "Configure BGP defaults\n"
4e69658c 2291 "Show hostname in certain command outputs\n")
04b6bdc0 2292{
d62a17ae 2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
2294 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2295 return CMD_SUCCESS;
04b6bdc0
DW
2296}
2297
2298DEFUN (no_bgp_default_show_hostname,
2299 no_bgp_default_show_hostname_cmd,
2300 "no bgp default show-hostname",
2301 NO_STR
2302 "BGP specific commands\n"
2303 "Configure BGP defaults\n"
4e69658c 2304 "Show hostname in certain command outputs\n")
04b6bdc0 2305{
d62a17ae 2306 VTY_DECLVAR_CONTEXT(bgp, bgp);
2307 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2308 return CMD_SUCCESS;
04b6bdc0
DW
2309}
2310
8233ef81 2311/* "bgp network import-check" configuration. */
718e3744 2312DEFUN (bgp_network_import_check,
2313 bgp_network_import_check_cmd,
5623e905 2314 "bgp network import-check",
718e3744 2315 "BGP specific commands\n"
2316 "BGP network command\n"
5623e905 2317 "Check BGP network route exists in IGP\n")
718e3744 2318{
d62a17ae 2319 VTY_DECLVAR_CONTEXT(bgp, bgp);
2320 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2321 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2322 bgp_static_redo_import_check(bgp);
2323 }
078430f6 2324
d62a17ae 2325 return CMD_SUCCESS;
718e3744 2326}
2327
d62a17ae 2328ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2329 "bgp network import-check exact",
2330 "BGP specific commands\n"
2331 "BGP network command\n"
2332 "Check BGP network route exists in IGP\n"
2333 "Match route precisely\n")
8233ef81 2334
718e3744 2335DEFUN (no_bgp_network_import_check,
2336 no_bgp_network_import_check_cmd,
5623e905 2337 "no bgp network import-check",
718e3744 2338 NO_STR
2339 "BGP specific commands\n"
2340 "BGP network command\n"
2341 "Check BGP network route exists in IGP\n")
2342{
d62a17ae 2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
2344 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2345 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2346 bgp_static_redo_import_check(bgp);
2347 }
5623e905 2348
d62a17ae 2349 return CMD_SUCCESS;
718e3744 2350}
6b0655a2 2351
718e3744 2352DEFUN (bgp_default_local_preference,
2353 bgp_default_local_preference_cmd,
6147e2c6 2354 "bgp default local-preference (0-4294967295)",
718e3744 2355 "BGP specific commands\n"
2356 "Configure BGP defaults\n"
2357 "local preference (higher=more preferred)\n"
2358 "Configure default local preference value\n")
2359{
d62a17ae 2360 VTY_DECLVAR_CONTEXT(bgp, bgp);
2361 int idx_number = 3;
d7c0a89a 2362 uint32_t local_pref;
718e3744 2363
d62a17ae 2364 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2365
d62a17ae 2366 bgp_default_local_preference_set(bgp, local_pref);
2367 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2368
d62a17ae 2369 return CMD_SUCCESS;
718e3744 2370}
2371
2372DEFUN (no_bgp_default_local_preference,
2373 no_bgp_default_local_preference_cmd,
838758ac 2374 "no bgp default local-preference [(0-4294967295)]",
718e3744 2375 NO_STR
2376 "BGP specific commands\n"
2377 "Configure BGP defaults\n"
838758ac
DW
2378 "local preference (higher=more preferred)\n"
2379 "Configure default local preference value\n")
718e3744 2380{
d62a17ae 2381 VTY_DECLVAR_CONTEXT(bgp, bgp);
2382 bgp_default_local_preference_unset(bgp);
2383 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2384
d62a17ae 2385 return CMD_SUCCESS;
718e3744 2386}
2387
6b0655a2 2388
3f9c7369
DS
2389DEFUN (bgp_default_subgroup_pkt_queue_max,
2390 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2391 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2392 "BGP specific commands\n"
2393 "Configure BGP defaults\n"
2394 "subgroup-pkt-queue-max\n"
2395 "Configure subgroup packet queue max\n")
8bd9d948 2396{
d62a17ae 2397 VTY_DECLVAR_CONTEXT(bgp, bgp);
2398 int idx_number = 3;
d7c0a89a 2399 uint32_t max_size;
8bd9d948 2400
d62a17ae 2401 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2402
d62a17ae 2403 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2404
d62a17ae 2405 return CMD_SUCCESS;
3f9c7369
DS
2406}
2407
2408DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2409 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2410 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2411 NO_STR
2412 "BGP specific commands\n"
2413 "Configure BGP defaults\n"
838758ac
DW
2414 "subgroup-pkt-queue-max\n"
2415 "Configure subgroup packet queue max\n")
3f9c7369 2416{
d62a17ae 2417 VTY_DECLVAR_CONTEXT(bgp, bgp);
2418 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2419 return CMD_SUCCESS;
8bd9d948
DS
2420}
2421
813d4307 2422
8bd9d948
DS
2423DEFUN (bgp_rr_allow_outbound_policy,
2424 bgp_rr_allow_outbound_policy_cmd,
2425 "bgp route-reflector allow-outbound-policy",
2426 "BGP specific commands\n"
2427 "Allow modifications made by out route-map\n"
2428 "on ibgp neighbors\n")
2429{
d62a17ae 2430 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2431
d62a17ae 2432 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2433 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2434 update_group_announce_rrclients(bgp);
2435 bgp_clear_star_soft_out(vty, bgp->name);
2436 }
8bd9d948 2437
d62a17ae 2438 return CMD_SUCCESS;
8bd9d948
DS
2439}
2440
2441DEFUN (no_bgp_rr_allow_outbound_policy,
2442 no_bgp_rr_allow_outbound_policy_cmd,
2443 "no bgp route-reflector allow-outbound-policy",
2444 NO_STR
2445 "BGP specific commands\n"
2446 "Allow modifications made by out route-map\n"
2447 "on ibgp neighbors\n")
2448{
d62a17ae 2449 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2450
d62a17ae 2451 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2452 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2453 update_group_announce_rrclients(bgp);
2454 bgp_clear_star_soft_out(vty, bgp->name);
2455 }
8bd9d948 2456
d62a17ae 2457 return CMD_SUCCESS;
8bd9d948
DS
2458}
2459
f14e6fdb
DS
2460DEFUN (bgp_listen_limit,
2461 bgp_listen_limit_cmd,
9ccf14f7 2462 "bgp listen limit (1-5000)",
f14e6fdb
DS
2463 "BGP specific commands\n"
2464 "Configure BGP defaults\n"
2465 "maximum number of BGP Dynamic Neighbors that can be created\n"
2466 "Configure Dynamic Neighbors listen limit value\n")
2467{
d62a17ae 2468 VTY_DECLVAR_CONTEXT(bgp, bgp);
2469 int idx_number = 3;
2470 int listen_limit;
f14e6fdb 2471
d62a17ae 2472 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2473
d62a17ae 2474 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2475
d62a17ae 2476 return CMD_SUCCESS;
f14e6fdb
DS
2477}
2478
2479DEFUN (no_bgp_listen_limit,
2480 no_bgp_listen_limit_cmd,
838758ac 2481 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2482 "BGP specific commands\n"
2483 "Configure BGP defaults\n"
2484 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2485 "Configure Dynamic Neighbors listen limit value to default\n"
2486 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2487{
d62a17ae 2488 VTY_DECLVAR_CONTEXT(bgp, bgp);
2489 bgp_listen_limit_unset(bgp);
2490 return CMD_SUCCESS;
f14e6fdb
DS
2491}
2492
2493
20eb8864 2494/*
2495 * Check if this listen range is already configured. Check for exact
2496 * match or overlap based on input.
2497 */
d62a17ae 2498static struct peer_group *listen_range_exists(struct bgp *bgp,
2499 struct prefix *range, int exact)
2500{
2501 struct listnode *node, *nnode;
2502 struct listnode *node1, *nnode1;
2503 struct peer_group *group;
2504 struct prefix *lr;
2505 afi_t afi;
2506 int match;
2507
2508 afi = family2afi(range->family);
2509 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2510 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2511 lr)) {
2512 if (exact)
2513 match = prefix_same(range, lr);
2514 else
2515 match = (prefix_match(range, lr)
2516 || prefix_match(lr, range));
2517 if (match)
2518 return group;
2519 }
2520 }
2521
2522 return NULL;
20eb8864 2523}
2524
f14e6fdb
DS
2525DEFUN (bgp_listen_range,
2526 bgp_listen_range_cmd,
9ccf14f7 2527 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2528 "BGP specific commands\n"
d7fa34c1
QY
2529 "Configure BGP dynamic neighbors listen range\n"
2530 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2531 NEIGHBOR_ADDR_STR
2532 "Member of the peer-group\n"
2533 "Peer-group name\n")
f14e6fdb 2534{
d62a17ae 2535 VTY_DECLVAR_CONTEXT(bgp, bgp);
2536 struct prefix range;
2537 struct peer_group *group, *existing_group;
2538 afi_t afi;
2539 int ret;
2540 int idx = 0;
2541
2542 argv_find(argv, argc, "A.B.C.D/M", &idx);
2543 argv_find(argv, argc, "X:X::X:X/M", &idx);
2544 char *prefix = argv[idx]->arg;
2545 argv_find(argv, argc, "WORD", &idx);
2546 char *peergroup = argv[idx]->arg;
2547
2548 /* Convert IP prefix string to struct prefix. */
2549 ret = str2prefix(prefix, &range);
2550 if (!ret) {
2551 vty_out(vty, "%% Malformed listen range\n");
2552 return CMD_WARNING_CONFIG_FAILED;
2553 }
2554
2555 afi = family2afi(range.family);
2556
2557 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2558 vty_out(vty,
2559 "%% Malformed listen range (link-local address)\n");
2560 return CMD_WARNING_CONFIG_FAILED;
2561 }
2562
2563 apply_mask(&range);
2564
2565 /* Check if same listen range is already configured. */
2566 existing_group = listen_range_exists(bgp, &range, 1);
2567 if (existing_group) {
2568 if (strcmp(existing_group->name, peergroup) == 0)
2569 return CMD_SUCCESS;
2570 else {
2571 vty_out(vty,
2572 "%% Same listen range is attached to peer-group %s\n",
2573 existing_group->name);
2574 return CMD_WARNING_CONFIG_FAILED;
2575 }
2576 }
2577
2578 /* Check if an overlapping listen range exists. */
2579 if (listen_range_exists(bgp, &range, 0)) {
2580 vty_out(vty,
2581 "%% Listen range overlaps with existing listen range\n");
2582 return CMD_WARNING_CONFIG_FAILED;
2583 }
2584
2585 group = peer_group_lookup(bgp, peergroup);
2586 if (!group) {
2587 vty_out(vty, "%% Configure the peer-group first\n");
2588 return CMD_WARNING_CONFIG_FAILED;
2589 }
2590
2591 ret = peer_group_listen_range_add(group, &range);
2592 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2593}
2594
2595DEFUN (no_bgp_listen_range,
2596 no_bgp_listen_range_cmd,
d7fa34c1
QY
2597 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2598 NO_STR
f14e6fdb 2599 "BGP specific commands\n"
d7fa34c1
QY
2600 "Unconfigure BGP dynamic neighbors listen range\n"
2601 "Unconfigure BGP dynamic neighbors listen range\n"
2602 NEIGHBOR_ADDR_STR
2603 "Member of the peer-group\n"
2604 "Peer-group name\n")
f14e6fdb 2605{
d62a17ae 2606 VTY_DECLVAR_CONTEXT(bgp, bgp);
2607 struct prefix range;
2608 struct peer_group *group;
2609 afi_t afi;
2610 int ret;
2611 int idx = 0;
2612
2613 argv_find(argv, argc, "A.B.C.D/M", &idx);
2614 argv_find(argv, argc, "X:X::X:X/M", &idx);
2615 char *prefix = argv[idx]->arg;
2616 argv_find(argv, argc, "WORD", &idx);
2617 char *peergroup = argv[idx]->arg;
2618
2619 /* Convert IP prefix string to struct prefix. */
2620 ret = str2prefix(prefix, &range);
2621 if (!ret) {
2622 vty_out(vty, "%% Malformed listen range\n");
2623 return CMD_WARNING_CONFIG_FAILED;
2624 }
2625
2626 afi = family2afi(range.family);
2627
2628 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2629 vty_out(vty,
2630 "%% Malformed listen range (link-local address)\n");
2631 return CMD_WARNING_CONFIG_FAILED;
2632 }
2633
2634 apply_mask(&range);
2635
2636 group = peer_group_lookup(bgp, peergroup);
2637 if (!group) {
2638 vty_out(vty, "%% Peer-group does not exist\n");
2639 return CMD_WARNING_CONFIG_FAILED;
2640 }
2641
2642 ret = peer_group_listen_range_del(group, &range);
2643 return bgp_vty_return(vty, ret);
2644}
2645
2b791107 2646void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2647{
2648 struct peer_group *group;
2649 struct listnode *node, *nnode, *rnode, *nrnode;
2650 struct prefix *range;
2651 afi_t afi;
2652 char buf[PREFIX2STR_BUFFER];
2653
2654 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2655 vty_out(vty, " bgp listen limit %d\n",
2656 bgp->dynamic_neighbors_limit);
2657
2658 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2659 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2660 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2661 nrnode, range)) {
2662 prefix2str(range, buf, sizeof(buf));
2663 vty_out(vty,
2664 " bgp listen range %s peer-group %s\n",
2665 buf, group->name);
2666 }
2667 }
2668 }
f14e6fdb
DS
2669}
2670
2671
907f92c8
DS
2672DEFUN (bgp_disable_connected_route_check,
2673 bgp_disable_connected_route_check_cmd,
2674 "bgp disable-ebgp-connected-route-check",
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_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2680 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2681
d62a17ae 2682 return CMD_SUCCESS;
907f92c8
DS
2683}
2684
2685DEFUN (no_bgp_disable_connected_route_check,
2686 no_bgp_disable_connected_route_check_cmd,
2687 "no bgp disable-ebgp-connected-route-check",
2688 NO_STR
2689 "BGP specific commands\n"
2690 "Disable checking if nexthop is connected on ebgp sessions\n")
2691{
d62a17ae 2692 VTY_DECLVAR_CONTEXT(bgp, bgp);
2693 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2694 bgp_clear_star_soft_in(vty, bgp->name);
2695
2696 return CMD_SUCCESS;
2697}
2698
2699
2700static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2701 const char *as_str, afi_t afi, safi_t safi)
2702{
2703 VTY_DECLVAR_CONTEXT(bgp, bgp);
2704 int ret;
2705 as_t as;
2706 int as_type = AS_SPECIFIED;
2707 union sockunion su;
2708
2709 if (as_str[0] == 'i') {
2710 as = 0;
2711 as_type = AS_INTERNAL;
2712 } else if (as_str[0] == 'e') {
2713 as = 0;
2714 as_type = AS_EXTERNAL;
2715 } else {
2716 /* Get AS number. */
2717 as = strtoul(as_str, NULL, 10);
2718 }
2719
2720 /* If peer is peer group, call proper function. */
2721 ret = str2sockunion(peer_str, &su);
2722 if (ret < 0) {
2723 /* Check for peer by interface */
2724 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2725 safi);
2726 if (ret < 0) {
2727 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2728 if (ret < 0) {
2729 vty_out(vty,
2730 "%% Create the peer-group or interface first\n");
2731 return CMD_WARNING_CONFIG_FAILED;
2732 }
2733 return CMD_SUCCESS;
2734 }
2735 } else {
2736 if (peer_address_self_check(bgp, &su)) {
2737 vty_out(vty,
2738 "%% Can not configure the local system as neighbor\n");
2739 return CMD_WARNING_CONFIG_FAILED;
2740 }
2741 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2742 }
2743
2744 /* This peer belongs to peer group. */
2745 switch (ret) {
2746 case BGP_ERR_PEER_GROUP_MEMBER:
2747 vty_out(vty,
2748 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2749 as);
2750 return CMD_WARNING_CONFIG_FAILED;
2751 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2752 vty_out(vty,
2753 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2754 as, as_str);
2755 return CMD_WARNING_CONFIG_FAILED;
2756 }
2757 return bgp_vty_return(vty, ret);
718e3744 2758}
2759
f26845f9
QY
2760DEFUN (bgp_default_shutdown,
2761 bgp_default_shutdown_cmd,
2762 "[no] bgp default shutdown",
2763 NO_STR
2764 BGP_STR
2765 "Configure BGP defaults\n"
b012cbe2 2766 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2767{
2768 VTY_DECLVAR_CONTEXT(bgp, bgp);
2769 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2770 return CMD_SUCCESS;
2771}
2772
718e3744 2773DEFUN (neighbor_remote_as,
2774 neighbor_remote_as_cmd,
3a2d747c 2775 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2776 NEIGHBOR_STR
2777 NEIGHBOR_ADDR_STR2
2778 "Specify a BGP neighbor\n"
d7fa34c1 2779 AS_STR
3a2d747c
QY
2780 "Internal BGP peer\n"
2781 "External BGP peer\n")
718e3744 2782{
d62a17ae 2783 int idx_peer = 1;
2784 int idx_remote_as = 3;
2785 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2786 argv[idx_remote_as]->arg, AFI_IP,
2787 SAFI_UNICAST);
2788}
2789
2790static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2791 afi_t afi, safi_t safi, int v6only,
2792 const char *peer_group_name,
2793 const char *as_str)
2794{
2795 VTY_DECLVAR_CONTEXT(bgp, bgp);
2796 as_t as = 0;
2797 int as_type = AS_UNSPECIFIED;
2798 struct peer *peer;
2799 struct peer_group *group;
2800 int ret = 0;
2801 union sockunion su;
2802
2803 group = peer_group_lookup(bgp, conf_if);
2804
2805 if (group) {
2806 vty_out(vty, "%% Name conflict with peer-group \n");
2807 return CMD_WARNING_CONFIG_FAILED;
2808 }
2809
2810 if (as_str) {
2811 if (as_str[0] == 'i') {
2812 as_type = AS_INTERNAL;
2813 } else if (as_str[0] == 'e') {
2814 as_type = AS_EXTERNAL;
2815 } else {
2816 /* Get AS number. */
2817 as = strtoul(as_str, NULL, 10);
2818 as_type = AS_SPECIFIED;
2819 }
2820 }
2821
2822 peer = peer_lookup_by_conf_if(bgp, conf_if);
2823 if (peer) {
2824 if (as_str)
2825 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2826 afi, safi);
2827 } else {
2828 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2829 && afi == AFI_IP && safi == SAFI_UNICAST)
2830 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2831 as_type, 0, 0, NULL);
2832 else
2833 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2834 as_type, afi, safi, NULL);
2835
2836 if (!peer) {
2837 vty_out(vty, "%% BGP failed to create peer\n");
2838 return CMD_WARNING_CONFIG_FAILED;
2839 }
2840
2841 if (v6only)
527de3dc 2842 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2843
2844 /* Request zebra to initiate IPv6 RAs on this interface. We do
2845 * this
2846 * any unnumbered peer in order to not worry about run-time
2847 * transitions
2848 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2849 * address
2850 * gets deleted later etc.)
2851 */
2852 if (peer->ifp)
2853 bgp_zebra_initiate_radv(bgp, peer);
2854 }
2855
2856 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2857 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2858 if (v6only)
527de3dc 2859 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2860 else
527de3dc 2861 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2862
2863 /* v6only flag changed. Reset bgp seesion */
2864 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2865 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2866 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2867 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2868 } else
2869 bgp_session_reset(peer);
2870 }
2871
9fb964de
PM
2872 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2873 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2874 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2875 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2876 }
d62a17ae 2877
2878 if (peer_group_name) {
2879 group = peer_group_lookup(bgp, peer_group_name);
2880 if (!group) {
2881 vty_out(vty, "%% Configure the peer-group first\n");
2882 return CMD_WARNING_CONFIG_FAILED;
2883 }
2884
2885 ret = peer_group_bind(bgp, &su, peer, group, &as);
2886 }
2887
2888 return bgp_vty_return(vty, ret);
a80beece
DS
2889}
2890
4c48cf63
DW
2891DEFUN (neighbor_interface_config,
2892 neighbor_interface_config_cmd,
31500417 2893 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2894 NEIGHBOR_STR
2895 "Interface name or neighbor tag\n"
31500417
DW
2896 "Enable BGP on interface\n"
2897 "Member of the peer-group\n"
16cedbb0 2898 "Peer-group name\n")
4c48cf63 2899{
d62a17ae 2900 int idx_word = 1;
2901 int idx_peer_group_word = 4;
31500417 2902
d62a17ae 2903 if (argc > idx_peer_group_word)
2904 return peer_conf_interface_get(
2905 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2906 argv[idx_peer_group_word]->arg, NULL);
2907 else
2908 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2909 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2910}
2911
4c48cf63
DW
2912DEFUN (neighbor_interface_config_v6only,
2913 neighbor_interface_config_v6only_cmd,
31500417 2914 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2915 NEIGHBOR_STR
2916 "Interface name or neighbor tag\n"
2917 "Enable BGP on interface\n"
31500417
DW
2918 "Enable BGP with v6 link-local only\n"
2919 "Member of the peer-group\n"
16cedbb0 2920 "Peer-group name\n")
4c48cf63 2921{
d62a17ae 2922 int idx_word = 1;
2923 int idx_peer_group_word = 5;
31500417 2924
d62a17ae 2925 if (argc > idx_peer_group_word)
2926 return peer_conf_interface_get(
2927 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2928 argv[idx_peer_group_word]->arg, NULL);
31500417 2929
d62a17ae 2930 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2931 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2932}
2933
a80beece 2934
b3a39dc5
DD
2935DEFUN (neighbor_interface_config_remote_as,
2936 neighbor_interface_config_remote_as_cmd,
3a2d747c 2937 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2938 NEIGHBOR_STR
2939 "Interface name or neighbor tag\n"
2940 "Enable BGP on interface\n"
3a2d747c 2941 "Specify a BGP neighbor\n"
d7fa34c1 2942 AS_STR
3a2d747c
QY
2943 "Internal BGP peer\n"
2944 "External BGP peer\n")
b3a39dc5 2945{
d62a17ae 2946 int idx_word = 1;
2947 int idx_remote_as = 4;
2948 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2949 SAFI_UNICAST, 0, NULL,
2950 argv[idx_remote_as]->arg);
b3a39dc5
DD
2951}
2952
2953DEFUN (neighbor_interface_v6only_config_remote_as,
2954 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2955 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2956 NEIGHBOR_STR
2957 "Interface name or neighbor tag\n"
3a2d747c 2958 "Enable BGP with v6 link-local only\n"
b3a39dc5 2959 "Enable BGP on interface\n"
3a2d747c 2960 "Specify a BGP neighbor\n"
d7fa34c1 2961 AS_STR
3a2d747c
QY
2962 "Internal BGP peer\n"
2963 "External BGP peer\n")
b3a39dc5 2964{
d62a17ae 2965 int idx_word = 1;
2966 int idx_remote_as = 5;
2967 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2968 SAFI_UNICAST, 1, NULL,
2969 argv[idx_remote_as]->arg);
b3a39dc5
DD
2970}
2971
718e3744 2972DEFUN (neighbor_peer_group,
2973 neighbor_peer_group_cmd,
2974 "neighbor WORD peer-group",
2975 NEIGHBOR_STR
a80beece 2976 "Interface name or neighbor tag\n"
718e3744 2977 "Configure peer-group\n")
2978{
d62a17ae 2979 VTY_DECLVAR_CONTEXT(bgp, bgp);
2980 int idx_word = 1;
2981 struct peer *peer;
2982 struct peer_group *group;
718e3744 2983
d62a17ae 2984 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2985 if (peer) {
2986 vty_out(vty, "%% Name conflict with interface: \n");
2987 return CMD_WARNING_CONFIG_FAILED;
2988 }
718e3744 2989
d62a17ae 2990 group = peer_group_get(bgp, argv[idx_word]->arg);
2991 if (!group) {
2992 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2993 return CMD_WARNING_CONFIG_FAILED;
2994 }
718e3744 2995
d62a17ae 2996 return CMD_SUCCESS;
718e3744 2997}
2998
2999DEFUN (no_neighbor,
3000 no_neighbor_cmd,
dab8cd00 3001 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3002 NO_STR
3003 NEIGHBOR_STR
3a2d747c
QY
3004 NEIGHBOR_ADDR_STR2
3005 "Specify a BGP neighbor\n"
3006 AS_STR
3007 "Internal BGP peer\n"
3008 "External BGP peer\n")
718e3744 3009{
d62a17ae 3010 VTY_DECLVAR_CONTEXT(bgp, bgp);
3011 int idx_peer = 2;
3012 int ret;
3013 union sockunion su;
3014 struct peer_group *group;
3015 struct peer *peer;
3016 struct peer *other;
3017
3018 ret = str2sockunion(argv[idx_peer]->arg, &su);
3019 if (ret < 0) {
3020 /* look up for neighbor by interface name config. */
3021 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3022 if (peer) {
3023 /* Request zebra to terminate IPv6 RAs on this
3024 * interface. */
3025 if (peer->ifp)
3026 bgp_zebra_terminate_radv(peer->bgp, peer);
3027 peer_delete(peer);
3028 return CMD_SUCCESS;
3029 }
f14e6fdb 3030
d62a17ae 3031 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3032 if (group)
3033 peer_group_delete(group);
3034 else {
3035 vty_out(vty, "%% Create the peer-group first\n");
3036 return CMD_WARNING_CONFIG_FAILED;
3037 }
3038 } else {
3039 peer = peer_lookup(bgp, &su);
3040 if (peer) {
3041 if (peer_dynamic_neighbor(peer)) {
3042 vty_out(vty,
3043 "%% Operation not allowed on a dynamic neighbor\n");
3044 return CMD_WARNING_CONFIG_FAILED;
3045 }
3046
3047 other = peer->doppelganger;
3048 peer_delete(peer);
3049 if (other && other->status != Deleted)
3050 peer_delete(other);
3051 }
1ff9a340 3052 }
718e3744 3053
d62a17ae 3054 return CMD_SUCCESS;
718e3744 3055}
3056
a80beece
DS
3057DEFUN (no_neighbor_interface_config,
3058 no_neighbor_interface_config_cmd,
31500417 3059 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3060 NO_STR
3061 NEIGHBOR_STR
3062 "Interface name\n"
31500417
DW
3063 "Configure BGP on interface\n"
3064 "Enable BGP with v6 link-local only\n"
3065 "Member of the peer-group\n"
16cedbb0 3066 "Peer-group name\n"
3a2d747c
QY
3067 "Specify a BGP neighbor\n"
3068 AS_STR
3069 "Internal BGP peer\n"
3070 "External BGP peer\n")
a80beece 3071{
d62a17ae 3072 VTY_DECLVAR_CONTEXT(bgp, bgp);
3073 int idx_word = 2;
3074 struct peer *peer;
3075
3076 /* look up for neighbor by interface name config. */
3077 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3078 if (peer) {
3079 /* Request zebra to terminate IPv6 RAs on this interface. */
3080 if (peer->ifp)
3081 bgp_zebra_terminate_radv(peer->bgp, peer);
3082 peer_delete(peer);
3083 } else {
3084 vty_out(vty, "%% Create the bgp interface first\n");
3085 return CMD_WARNING_CONFIG_FAILED;
3086 }
3087 return CMD_SUCCESS;
a80beece
DS
3088}
3089
718e3744 3090DEFUN (no_neighbor_peer_group,
3091 no_neighbor_peer_group_cmd,
3092 "no neighbor WORD peer-group",
3093 NO_STR
3094 NEIGHBOR_STR
3095 "Neighbor tag\n"
3096 "Configure peer-group\n")
3097{
d62a17ae 3098 VTY_DECLVAR_CONTEXT(bgp, bgp);
3099 int idx_word = 2;
3100 struct peer_group *group;
718e3744 3101
d62a17ae 3102 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3103 if (group)
3104 peer_group_delete(group);
3105 else {
3106 vty_out(vty, "%% Create the peer-group first\n");
3107 return CMD_WARNING_CONFIG_FAILED;
3108 }
3109 return CMD_SUCCESS;
718e3744 3110}
3111
a80beece
DS
3112DEFUN (no_neighbor_interface_peer_group_remote_as,
3113 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3114 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3115 NO_STR
3116 NEIGHBOR_STR
a80beece 3117 "Interface name or neighbor tag\n"
718e3744 3118 "Specify a BGP neighbor\n"
3a2d747c
QY
3119 AS_STR
3120 "Internal BGP peer\n"
3121 "External BGP peer\n")
718e3744 3122{
d62a17ae 3123 VTY_DECLVAR_CONTEXT(bgp, bgp);
3124 int idx_word = 2;
3125 struct peer_group *group;
3126 struct peer *peer;
3127
3128 /* look up for neighbor by interface name config. */
3129 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3130 if (peer) {
3131 peer_as_change(peer, 0, AS_SPECIFIED);
3132 return CMD_SUCCESS;
3133 }
3134
3135 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3136 if (group)
3137 peer_group_remote_as_delete(group);
3138 else {
3139 vty_out(vty, "%% Create the peer-group or interface first\n");
3140 return CMD_WARNING_CONFIG_FAILED;
3141 }
3142 return CMD_SUCCESS;
718e3744 3143}
6b0655a2 3144
718e3744 3145DEFUN (neighbor_local_as,
3146 neighbor_local_as_cmd,
9ccf14f7 3147 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3148 NEIGHBOR_STR
3149 NEIGHBOR_ADDR_STR2
3150 "Specify a local-as number\n"
3151 "AS number used as local AS\n")
3152{
d62a17ae 3153 int idx_peer = 1;
3154 int idx_number = 3;
3155 struct peer *peer;
3156 int ret;
3157 as_t as;
718e3744 3158
d62a17ae 3159 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3160 if (!peer)
3161 return CMD_WARNING_CONFIG_FAILED;
718e3744 3162
d62a17ae 3163 as = strtoul(argv[idx_number]->arg, NULL, 10);
3164 ret = peer_local_as_set(peer, as, 0, 0);
3165 return bgp_vty_return(vty, ret);
718e3744 3166}
3167
3168DEFUN (neighbor_local_as_no_prepend,
3169 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3170 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3171 NEIGHBOR_STR
3172 NEIGHBOR_ADDR_STR2
3173 "Specify a local-as number\n"
3174 "AS number used as local AS\n"
3175 "Do not prepend local-as to updates from ebgp peers\n")
3176{
d62a17ae 3177 int idx_peer = 1;
3178 int idx_number = 3;
3179 struct peer *peer;
3180 int ret;
3181 as_t as;
718e3744 3182
d62a17ae 3183 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3184 if (!peer)
3185 return CMD_WARNING_CONFIG_FAILED;
718e3744 3186
d62a17ae 3187 as = strtoul(argv[idx_number]->arg, NULL, 10);
3188 ret = peer_local_as_set(peer, as, 1, 0);
3189 return bgp_vty_return(vty, ret);
718e3744 3190}
3191
9d3f9705
AC
3192DEFUN (neighbor_local_as_no_prepend_replace_as,
3193 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3194 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3195 NEIGHBOR_STR
3196 NEIGHBOR_ADDR_STR2
3197 "Specify a local-as number\n"
3198 "AS number used as local AS\n"
3199 "Do not prepend local-as to updates from ebgp peers\n"
3200 "Do not prepend local-as to updates from ibgp peers\n")
3201{
d62a17ae 3202 int idx_peer = 1;
3203 int idx_number = 3;
3204 struct peer *peer;
3205 int ret;
3206 as_t as;
9d3f9705 3207
d62a17ae 3208 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3209 if (!peer)
3210 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3211
d62a17ae 3212 as = strtoul(argv[idx_number]->arg, NULL, 10);
3213 ret = peer_local_as_set(peer, as, 1, 1);
3214 return bgp_vty_return(vty, ret);
9d3f9705
AC
3215}
3216
718e3744 3217DEFUN (no_neighbor_local_as,
3218 no_neighbor_local_as_cmd,
a636c635 3219 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3220 NO_STR
3221 NEIGHBOR_STR
3222 NEIGHBOR_ADDR_STR2
a636c635
DW
3223 "Specify a local-as number\n"
3224 "AS number used as local AS\n"
3225 "Do not prepend local-as to updates from ebgp peers\n"
3226 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3227{
d62a17ae 3228 int idx_peer = 2;
3229 struct peer *peer;
3230 int ret;
718e3744 3231
d62a17ae 3232 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3233 if (!peer)
3234 return CMD_WARNING_CONFIG_FAILED;
718e3744 3235
d62a17ae 3236 ret = peer_local_as_unset(peer);
3237 return bgp_vty_return(vty, ret);
718e3744 3238}
3239
718e3744 3240
3f9c7369
DS
3241DEFUN (neighbor_solo,
3242 neighbor_solo_cmd,
9ccf14f7 3243 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3244 NEIGHBOR_STR
3245 NEIGHBOR_ADDR_STR2
3246 "Solo peer - part of its own update group\n")
3247{
d62a17ae 3248 int idx_peer = 1;
3249 struct peer *peer;
3250 int ret;
3f9c7369 3251
d62a17ae 3252 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3253 if (!peer)
3254 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3255
d62a17ae 3256 ret = update_group_adjust_soloness(peer, 1);
3257 return bgp_vty_return(vty, ret);
3f9c7369
DS
3258}
3259
3260DEFUN (no_neighbor_solo,
3261 no_neighbor_solo_cmd,
9ccf14f7 3262 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3263 NO_STR
3264 NEIGHBOR_STR
3265 NEIGHBOR_ADDR_STR2
3266 "Solo peer - part of its own update group\n")
3267{
d62a17ae 3268 int idx_peer = 2;
3269 struct peer *peer;
3270 int ret;
3f9c7369 3271
d62a17ae 3272 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3273 if (!peer)
3274 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3275
d62a17ae 3276 ret = update_group_adjust_soloness(peer, 0);
3277 return bgp_vty_return(vty, ret);
3f9c7369
DS
3278}
3279
0df7c91f
PJ
3280DEFUN (neighbor_password,
3281 neighbor_password_cmd,
9ccf14f7 3282 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3283 NEIGHBOR_STR
3284 NEIGHBOR_ADDR_STR2
3285 "Set a password\n"
3286 "The password\n")
3287{
d62a17ae 3288 int idx_peer = 1;
3289 int idx_line = 3;
3290 struct peer *peer;
3291 int ret;
0df7c91f 3292
d62a17ae 3293 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3294 if (!peer)
3295 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3296
d62a17ae 3297 ret = peer_password_set(peer, argv[idx_line]->arg);
3298 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3299}
3300
3301DEFUN (no_neighbor_password,
3302 no_neighbor_password_cmd,
a636c635 3303 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3304 NO_STR
3305 NEIGHBOR_STR
3306 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3307 "Set a password\n"
3308 "The password\n")
0df7c91f 3309{
d62a17ae 3310 int idx_peer = 2;
3311 struct peer *peer;
3312 int ret;
0df7c91f 3313
d62a17ae 3314 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3315 if (!peer)
3316 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3317
d62a17ae 3318 ret = peer_password_unset(peer);
3319 return bgp_vty_return(vty, ret);
0df7c91f 3320}
6b0655a2 3321
718e3744 3322DEFUN (neighbor_activate,
3323 neighbor_activate_cmd,
9ccf14f7 3324 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3325 NEIGHBOR_STR
3326 NEIGHBOR_ADDR_STR2
3327 "Enable the Address Family for this Neighbor\n")
3328{
d62a17ae 3329 int idx_peer = 1;
3330 int ret;
3331 struct peer *peer;
718e3744 3332
d62a17ae 3333 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3334 if (!peer)
3335 return CMD_WARNING_CONFIG_FAILED;
718e3744 3336
d62a17ae 3337 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3338 return bgp_vty_return(vty, ret);
718e3744 3339}
3340
d62a17ae 3341ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3342 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3343 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3344 "Enable the Address Family for this Neighbor\n")
596c17ba 3345
718e3744 3346DEFUN (no_neighbor_activate,
3347 no_neighbor_activate_cmd,
9ccf14f7 3348 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3349 NO_STR
3350 NEIGHBOR_STR
3351 NEIGHBOR_ADDR_STR2
3352 "Enable the Address Family for this Neighbor\n")
3353{
d62a17ae 3354 int idx_peer = 2;
3355 int ret;
3356 struct peer *peer;
718e3744 3357
d62a17ae 3358 /* Lookup peer. */
3359 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3360 if (!peer)
3361 return CMD_WARNING_CONFIG_FAILED;
718e3744 3362
d62a17ae 3363 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3364 return bgp_vty_return(vty, ret);
718e3744 3365}
6b0655a2 3366
d62a17ae 3367ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3368 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3369 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3370 "Enable the Address Family for this Neighbor\n")
596c17ba 3371
718e3744 3372DEFUN (neighbor_set_peer_group,
3373 neighbor_set_peer_group_cmd,
9ccf14f7 3374 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3375 NEIGHBOR_STR
a80beece 3376 NEIGHBOR_ADDR_STR2
718e3744 3377 "Member of the peer-group\n"
16cedbb0 3378 "Peer-group name\n")
718e3744 3379{
d62a17ae 3380 VTY_DECLVAR_CONTEXT(bgp, bgp);
3381 int idx_peer = 1;
3382 int idx_word = 3;
3383 int ret;
3384 as_t as;
3385 union sockunion su;
3386 struct peer *peer;
3387 struct peer_group *group;
3388
d62a17ae 3389 ret = str2sockunion(argv[idx_peer]->arg, &su);
3390 if (ret < 0) {
3391 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3392 if (!peer) {
3393 vty_out(vty, "%% Malformed address or name: %s\n",
3394 argv[idx_peer]->arg);
3395 return CMD_WARNING_CONFIG_FAILED;
3396 }
3397 } else {
3398 if (peer_address_self_check(bgp, &su)) {
3399 vty_out(vty,
3400 "%% Can not configure the local system as neighbor\n");
3401 return CMD_WARNING_CONFIG_FAILED;
3402 }
3403
3404 /* Disallow for dynamic neighbor. */
3405 peer = peer_lookup(bgp, &su);
3406 if (peer && peer_dynamic_neighbor(peer)) {
3407 vty_out(vty,
3408 "%% Operation not allowed on a dynamic neighbor\n");
3409 return CMD_WARNING_CONFIG_FAILED;
3410 }
3411 }
3412
3413 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3414 if (!group) {
3415 vty_out(vty, "%% Configure the peer-group first\n");
3416 return CMD_WARNING_CONFIG_FAILED;
3417 }
3418
3419 ret = peer_group_bind(bgp, &su, peer, group, &as);
3420
3421 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3422 vty_out(vty,
3423 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3424 as);
3425 return CMD_WARNING_CONFIG_FAILED;
3426 }
3427
3428 return bgp_vty_return(vty, ret);
3429}
3430
3431ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3432 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3433 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3434 "Member of the peer-group\n"
3435 "Peer-group name\n")
596c17ba 3436
718e3744 3437DEFUN (no_neighbor_set_peer_group,
3438 no_neighbor_set_peer_group_cmd,
9ccf14f7 3439 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3440 NO_STR
3441 NEIGHBOR_STR
a80beece 3442 NEIGHBOR_ADDR_STR2
718e3744 3443 "Member of the peer-group\n"
16cedbb0 3444 "Peer-group name\n")
718e3744 3445{
d62a17ae 3446 VTY_DECLVAR_CONTEXT(bgp, bgp);
3447 int idx_peer = 2;
3448 int idx_word = 4;
3449 int ret;
3450 struct peer *peer;
3451 struct peer_group *group;
3452
3453 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3454 if (!peer)
3455 return CMD_WARNING_CONFIG_FAILED;
3456
3457 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3458 if (!group) {
3459 vty_out(vty, "%% Configure the peer-group first\n");
3460 return CMD_WARNING_CONFIG_FAILED;
3461 }
718e3744 3462
827ed707 3463 ret = peer_delete(peer);
718e3744 3464
d62a17ae 3465 return bgp_vty_return(vty, ret);
718e3744 3466}
6b0655a2 3467
d62a17ae 3468ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3469 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3470 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3471 "Member of the peer-group\n"
3472 "Peer-group name\n")
596c17ba 3473
d62a17ae 3474static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3475 uint32_t flag, int set)
718e3744 3476{
d62a17ae 3477 int ret;
3478 struct peer *peer;
718e3744 3479
d62a17ae 3480 peer = peer_and_group_lookup_vty(vty, ip_str);
3481 if (!peer)
3482 return CMD_WARNING_CONFIG_FAILED;
718e3744 3483
7ebe625c
QY
3484 /*
3485 * If 'neighbor <interface>', then this is for directly connected peers,
3486 * we should not accept disable-connected-check.
3487 */
3488 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3489 vty_out(vty,
3490 "%s is directly connected peer, cannot accept disable-"
3491 "connected-check\n",
3492 ip_str);
3493 return CMD_WARNING_CONFIG_FAILED;
3494 }
3495
d62a17ae 3496 if (!set && flag == PEER_FLAG_SHUTDOWN)
3497 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3498
d62a17ae 3499 if (set)
3500 ret = peer_flag_set(peer, flag);
3501 else
3502 ret = peer_flag_unset(peer, flag);
718e3744 3503
d62a17ae 3504 return bgp_vty_return(vty, ret);
718e3744 3505}
3506
47cbc09b 3507static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3508{
d62a17ae 3509 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3510}
3511
d62a17ae 3512static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3513 uint32_t flag)
718e3744 3514{
d62a17ae 3515 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3516}
3517
3518/* neighbor passive. */
3519DEFUN (neighbor_passive,
3520 neighbor_passive_cmd,
9ccf14f7 3521 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3522 NEIGHBOR_STR
3523 NEIGHBOR_ADDR_STR2
3524 "Don't send open messages to this neighbor\n")
3525{
d62a17ae 3526 int idx_peer = 1;
3527 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3528}
3529
3530DEFUN (no_neighbor_passive,
3531 no_neighbor_passive_cmd,
9ccf14f7 3532 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3533 NO_STR
3534 NEIGHBOR_STR
3535 NEIGHBOR_ADDR_STR2
3536 "Don't send open messages to this neighbor\n")
3537{
d62a17ae 3538 int idx_peer = 2;
3539 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3540}
6b0655a2 3541
718e3744 3542/* neighbor shutdown. */
73d70fa6
DL
3543DEFUN (neighbor_shutdown_msg,
3544 neighbor_shutdown_msg_cmd,
3545 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3546 NEIGHBOR_STR
3547 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3548 "Administratively shut down this neighbor\n"
3549 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3550 "Shutdown message\n")
718e3744 3551{
d62a17ae 3552 int idx_peer = 1;
73d70fa6 3553
d62a17ae 3554 if (argc >= 5) {
3555 struct peer *peer =
3556 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3557 char *message;
73d70fa6 3558
d62a17ae 3559 if (!peer)
3560 return CMD_WARNING_CONFIG_FAILED;
3561 message = argv_concat(argv, argc, 4);
3562 peer_tx_shutdown_message_set(peer, message);
3563 XFREE(MTYPE_TMP, message);
3564 }
73d70fa6 3565
d62a17ae 3566 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3567}
3568
d62a17ae 3569ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3570 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3571 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3572 "Administratively shut down this neighbor\n")
73d70fa6
DL
3573
3574DEFUN (no_neighbor_shutdown_msg,
3575 no_neighbor_shutdown_msg_cmd,
3576 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3577 NO_STR
3578 NEIGHBOR_STR
3579 NEIGHBOR_ADDR_STR2
3580 "Administratively shut down this neighbor\n"
3581 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3582 "Shutdown message\n")
718e3744 3583{
d62a17ae 3584 int idx_peer = 2;
73d70fa6 3585
d62a17ae 3586 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3587 PEER_FLAG_SHUTDOWN);
718e3744 3588}
6b0655a2 3589
d62a17ae 3590ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3591 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3592 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3593 "Administratively shut down this neighbor\n")
73d70fa6 3594
718e3744 3595/* neighbor capability dynamic. */
3596DEFUN (neighbor_capability_dynamic,
3597 neighbor_capability_dynamic_cmd,
9ccf14f7 3598 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3599 NEIGHBOR_STR
3600 NEIGHBOR_ADDR_STR2
3601 "Advertise capability to the peer\n"
3602 "Advertise dynamic capability to this neighbor\n")
3603{
d62a17ae 3604 int idx_peer = 1;
3605 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3606 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3607}
3608
3609DEFUN (no_neighbor_capability_dynamic,
3610 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3611 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3612 NO_STR
3613 NEIGHBOR_STR
3614 NEIGHBOR_ADDR_STR2
3615 "Advertise capability to the peer\n"
3616 "Advertise dynamic capability to this neighbor\n")
3617{
d62a17ae 3618 int idx_peer = 2;
3619 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3620 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3621}
6b0655a2 3622
718e3744 3623/* neighbor dont-capability-negotiate */
3624DEFUN (neighbor_dont_capability_negotiate,
3625 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3626 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3627 NEIGHBOR_STR
3628 NEIGHBOR_ADDR_STR2
3629 "Do not perform capability negotiation\n")
3630{
d62a17ae 3631 int idx_peer = 1;
3632 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3633 PEER_FLAG_DONT_CAPABILITY);
718e3744 3634}
3635
3636DEFUN (no_neighbor_dont_capability_negotiate,
3637 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3638 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3639 NO_STR
3640 NEIGHBOR_STR
3641 NEIGHBOR_ADDR_STR2
3642 "Do not perform capability negotiation\n")
3643{
d62a17ae 3644 int idx_peer = 2;
3645 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3646 PEER_FLAG_DONT_CAPABILITY);
718e3744 3647}
6b0655a2 3648
8a92a8a0
DS
3649/* neighbor capability extended next hop encoding */
3650DEFUN (neighbor_capability_enhe,
3651 neighbor_capability_enhe_cmd,
9ccf14f7 3652 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3653 NEIGHBOR_STR
3654 NEIGHBOR_ADDR_STR2
3655 "Advertise capability to the peer\n"
3656 "Advertise extended next-hop capability to the peer\n")
3657{
d62a17ae 3658 int idx_peer = 1;
3659 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3660 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3661}
3662
3663DEFUN (no_neighbor_capability_enhe,
3664 no_neighbor_capability_enhe_cmd,
9ccf14f7 3665 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3666 NO_STR
3667 NEIGHBOR_STR
3668 NEIGHBOR_ADDR_STR2
3669 "Advertise capability to the peer\n"
3670 "Advertise extended next-hop capability to the peer\n")
3671{
d62a17ae 3672 int idx_peer = 2;
3673 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3674 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3675}
3676
d62a17ae 3677static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3678 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3679 int set)
718e3744 3680{
d62a17ae 3681 int ret;
3682 struct peer *peer;
718e3744 3683
d62a17ae 3684 peer = peer_and_group_lookup_vty(vty, peer_str);
3685 if (!peer)
3686 return CMD_WARNING_CONFIG_FAILED;
718e3744 3687
d62a17ae 3688 if (set)
3689 ret = peer_af_flag_set(peer, afi, safi, flag);
3690 else
3691 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3692
d62a17ae 3693 return bgp_vty_return(vty, ret);
718e3744 3694}
3695
d62a17ae 3696static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3697 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3698{
d62a17ae 3699 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3700}
3701
d62a17ae 3702static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3703 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3704{
d62a17ae 3705 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3706}
6b0655a2 3707
718e3744 3708/* neighbor capability orf prefix-list. */
3709DEFUN (neighbor_capability_orf_prefix,
3710 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3711 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3712 NEIGHBOR_STR
3713 NEIGHBOR_ADDR_STR2
3714 "Advertise capability to the peer\n"
3715 "Advertise ORF capability to the peer\n"
3716 "Advertise prefixlist ORF capability to this neighbor\n"
3717 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3718 "Capability to RECEIVE the ORF from this neighbor\n"
3719 "Capability to SEND the ORF to this neighbor\n")
3720{
d62a17ae 3721 int idx_peer = 1;
3722 int idx_send_recv = 5;
d7c0a89a 3723 uint16_t flag = 0;
d62a17ae 3724
3725 if (strmatch(argv[idx_send_recv]->text, "send"))
3726 flag = PEER_FLAG_ORF_PREFIX_SM;
3727 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3728 flag = PEER_FLAG_ORF_PREFIX_RM;
3729 else if (strmatch(argv[idx_send_recv]->text, "both"))
3730 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3731 else {
3732 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3733 return CMD_WARNING_CONFIG_FAILED;
3734 }
3735
3736 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3737 bgp_node_safi(vty), flag);
3738}
3739
3740ALIAS_HIDDEN(
3741 neighbor_capability_orf_prefix,
3742 neighbor_capability_orf_prefix_hidden_cmd,
3743 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3744 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3745 "Advertise capability to the peer\n"
3746 "Advertise ORF capability to the peer\n"
3747 "Advertise prefixlist ORF capability to this neighbor\n"
3748 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3749 "Capability to RECEIVE the ORF from this neighbor\n"
3750 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3751
718e3744 3752DEFUN (no_neighbor_capability_orf_prefix,
3753 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3754 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3755 NO_STR
3756 NEIGHBOR_STR
3757 NEIGHBOR_ADDR_STR2
3758 "Advertise capability to the peer\n"
3759 "Advertise ORF capability to the peer\n"
3760 "Advertise prefixlist ORF capability to this neighbor\n"
3761 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3762 "Capability to RECEIVE the ORF from this neighbor\n"
3763 "Capability to SEND the ORF to this neighbor\n")
3764{
d62a17ae 3765 int idx_peer = 2;
3766 int idx_send_recv = 6;
d7c0a89a 3767 uint16_t flag = 0;
d62a17ae 3768
3769 if (strmatch(argv[idx_send_recv]->text, "send"))
3770 flag = PEER_FLAG_ORF_PREFIX_SM;
3771 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3772 flag = PEER_FLAG_ORF_PREFIX_RM;
3773 else if (strmatch(argv[idx_send_recv]->text, "both"))
3774 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3775 else {
3776 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3777 return CMD_WARNING_CONFIG_FAILED;
3778 }
3779
3780 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3781 bgp_node_afi(vty), bgp_node_safi(vty),
3782 flag);
3783}
3784
3785ALIAS_HIDDEN(
3786 no_neighbor_capability_orf_prefix,
3787 no_neighbor_capability_orf_prefix_hidden_cmd,
3788 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3789 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3790 "Advertise capability to the peer\n"
3791 "Advertise ORF capability to the peer\n"
3792 "Advertise prefixlist ORF capability to this neighbor\n"
3793 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3794 "Capability to RECEIVE the ORF from this neighbor\n"
3795 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3796
718e3744 3797/* neighbor next-hop-self. */
3798DEFUN (neighbor_nexthop_self,
3799 neighbor_nexthop_self_cmd,
9ccf14f7 3800 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3801 NEIGHBOR_STR
3802 NEIGHBOR_ADDR_STR2
a538debe 3803 "Disable the next hop calculation for this neighbor\n")
718e3744 3804{
d62a17ae 3805 int idx_peer = 1;
3806 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3807 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3808}
9e7a53c1 3809
d62a17ae 3810ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3811 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3812 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3813 "Disable the next hop calculation for this neighbor\n")
596c17ba 3814
a538debe
DS
3815/* neighbor next-hop-self. */
3816DEFUN (neighbor_nexthop_self_force,
3817 neighbor_nexthop_self_force_cmd,
9ccf14f7 3818 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3819 NEIGHBOR_STR
3820 NEIGHBOR_ADDR_STR2
3821 "Disable the next hop calculation for this neighbor\n"
3822 "Set the next hop to self for reflected routes\n")
3823{
d62a17ae 3824 int idx_peer = 1;
3825 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3826 bgp_node_safi(vty),
3827 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3828}
3829
d62a17ae 3830ALIAS_HIDDEN(neighbor_nexthop_self_force,
3831 neighbor_nexthop_self_force_hidden_cmd,
3832 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3833 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3834 "Disable the next hop calculation for this neighbor\n"
3835 "Set the next hop to self for reflected routes\n")
596c17ba 3836
718e3744 3837DEFUN (no_neighbor_nexthop_self,
3838 no_neighbor_nexthop_self_cmd,
9ccf14f7 3839 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3840 NO_STR
3841 NEIGHBOR_STR
3842 NEIGHBOR_ADDR_STR2
a538debe 3843 "Disable the next hop calculation for this neighbor\n")
718e3744 3844{
d62a17ae 3845 int idx_peer = 2;
3846 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3847 bgp_node_afi(vty), bgp_node_safi(vty),
3848 PEER_FLAG_NEXTHOP_SELF);
718e3744 3849}
6b0655a2 3850
d62a17ae 3851ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3852 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3853 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3854 "Disable the next hop calculation for this neighbor\n")
596c17ba 3855
88b8ed8d 3856DEFUN (no_neighbor_nexthop_self_force,
a538debe 3857 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3858 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3859 NO_STR
3860 NEIGHBOR_STR
3861 NEIGHBOR_ADDR_STR2
3862 "Disable the next hop calculation for this neighbor\n"
3863 "Set the next hop to self for reflected routes\n")
88b8ed8d 3864{
d62a17ae 3865 int idx_peer = 2;
3866 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3867 bgp_node_afi(vty), bgp_node_safi(vty),
3868 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3869}
a538debe 3870
d62a17ae 3871ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3872 no_neighbor_nexthop_self_force_hidden_cmd,
3873 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3874 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3875 "Disable the next hop calculation for this neighbor\n"
3876 "Set the next hop to self for reflected routes\n")
596c17ba 3877
c7122e14
DS
3878/* neighbor as-override */
3879DEFUN (neighbor_as_override,
3880 neighbor_as_override_cmd,
9ccf14f7 3881 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3882 NEIGHBOR_STR
3883 NEIGHBOR_ADDR_STR2
3884 "Override ASNs in outbound updates if aspath equals remote-as\n")
3885{
d62a17ae 3886 int idx_peer = 1;
3887 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3888 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3889}
3890
d62a17ae 3891ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3892 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3893 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3894 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3895
c7122e14
DS
3896DEFUN (no_neighbor_as_override,
3897 no_neighbor_as_override_cmd,
9ccf14f7 3898 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3899 NO_STR
3900 NEIGHBOR_STR
3901 NEIGHBOR_ADDR_STR2
3902 "Override ASNs in outbound updates if aspath equals remote-as\n")
3903{
d62a17ae 3904 int idx_peer = 2;
3905 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3906 bgp_node_afi(vty), bgp_node_safi(vty),
3907 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3908}
3909
d62a17ae 3910ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3911 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3912 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3913 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3914
718e3744 3915/* neighbor remove-private-AS. */
3916DEFUN (neighbor_remove_private_as,
3917 neighbor_remove_private_as_cmd,
9ccf14f7 3918 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3919 NEIGHBOR_STR
3920 NEIGHBOR_ADDR_STR2
5000f21c 3921 "Remove private ASNs in outbound updates\n")
718e3744 3922{
d62a17ae 3923 int idx_peer = 1;
3924 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3925 bgp_node_safi(vty),
3926 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3927}
3928
d62a17ae 3929ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3930 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3931 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3932 "Remove private ASNs in outbound updates\n")
596c17ba 3933
5000f21c
DS
3934DEFUN (neighbor_remove_private_as_all,
3935 neighbor_remove_private_as_all_cmd,
9ccf14f7 3936 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3937 NEIGHBOR_STR
3938 NEIGHBOR_ADDR_STR2
3939 "Remove private ASNs in outbound updates\n"
efd7904e 3940 "Apply to all AS numbers\n")
5000f21c 3941{
d62a17ae 3942 int idx_peer = 1;
3943 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3944 bgp_node_safi(vty),
3945 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3946}
3947
d62a17ae 3948ALIAS_HIDDEN(neighbor_remove_private_as_all,
3949 neighbor_remove_private_as_all_hidden_cmd,
3950 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3951 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3952 "Remove private ASNs in outbound updates\n"
3953 "Apply to all AS numbers")
596c17ba 3954
5000f21c
DS
3955DEFUN (neighbor_remove_private_as_replace_as,
3956 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3957 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3958 NEIGHBOR_STR
3959 NEIGHBOR_ADDR_STR2
3960 "Remove private ASNs in outbound updates\n"
3961 "Replace private ASNs with our ASN in outbound updates\n")
3962{
d62a17ae 3963 int idx_peer = 1;
3964 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3965 bgp_node_safi(vty),
3966 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3967}
3968
d62a17ae 3969ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3970 neighbor_remove_private_as_replace_as_hidden_cmd,
3971 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3972 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3973 "Remove private ASNs in outbound updates\n"
3974 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3975
5000f21c
DS
3976DEFUN (neighbor_remove_private_as_all_replace_as,
3977 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3978 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3979 NEIGHBOR_STR
3980 NEIGHBOR_ADDR_STR2
3981 "Remove private ASNs in outbound updates\n"
16cedbb0 3982 "Apply to all AS numbers\n"
5000f21c
DS
3983 "Replace private ASNs with our ASN in outbound updates\n")
3984{
d62a17ae 3985 int idx_peer = 1;
3986 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3987 bgp_node_safi(vty),
3988 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3989}
3990
d62a17ae 3991ALIAS_HIDDEN(
3992 neighbor_remove_private_as_all_replace_as,
3993 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3994 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3995 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3996 "Remove private ASNs in outbound updates\n"
3997 "Apply to all AS numbers\n"
3998 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3999
718e3744 4000DEFUN (no_neighbor_remove_private_as,
4001 no_neighbor_remove_private_as_cmd,
9ccf14f7 4002 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4003 NO_STR
4004 NEIGHBOR_STR
4005 NEIGHBOR_ADDR_STR2
5000f21c 4006 "Remove private ASNs in outbound updates\n")
718e3744 4007{
d62a17ae 4008 int idx_peer = 2;
4009 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4010 bgp_node_afi(vty), bgp_node_safi(vty),
4011 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4012}
6b0655a2 4013
d62a17ae 4014ALIAS_HIDDEN(no_neighbor_remove_private_as,
4015 no_neighbor_remove_private_as_hidden_cmd,
4016 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4017 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4018 "Remove private ASNs in outbound updates\n")
596c17ba 4019
88b8ed8d 4020DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4021 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4022 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4023 NO_STR
4024 NEIGHBOR_STR
4025 NEIGHBOR_ADDR_STR2
4026 "Remove private ASNs in outbound updates\n"
16cedbb0 4027 "Apply to all AS numbers\n")
88b8ed8d 4028{
d62a17ae 4029 int idx_peer = 2;
4030 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4031 bgp_node_afi(vty), bgp_node_safi(vty),
4032 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4033}
5000f21c 4034
d62a17ae 4035ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4036 no_neighbor_remove_private_as_all_hidden_cmd,
4037 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4038 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4039 "Remove private ASNs in outbound updates\n"
4040 "Apply to all AS numbers\n")
596c17ba 4041
88b8ed8d 4042DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4043 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4044 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4045 NO_STR
4046 NEIGHBOR_STR
4047 NEIGHBOR_ADDR_STR2
4048 "Remove private ASNs in outbound updates\n"
4049 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4050{
d62a17ae 4051 int idx_peer = 2;
4052 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4053 bgp_node_afi(vty), bgp_node_safi(vty),
4054 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4055}
5000f21c 4056
d62a17ae 4057ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4058 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4059 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4060 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4061 "Remove private ASNs in outbound updates\n"
4062 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4063
88b8ed8d 4064DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4065 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4066 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4067 NO_STR
4068 NEIGHBOR_STR
4069 NEIGHBOR_ADDR_STR2
4070 "Remove private ASNs in outbound updates\n"
16cedbb0 4071 "Apply to all AS numbers\n"
5000f21c 4072 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4073{
d62a17ae 4074 int idx_peer = 2;
4075 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4076 bgp_node_afi(vty), bgp_node_safi(vty),
4077 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4078}
5000f21c 4079
d62a17ae 4080ALIAS_HIDDEN(
4081 no_neighbor_remove_private_as_all_replace_as,
4082 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4083 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4084 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4085 "Remove private ASNs in outbound updates\n"
4086 "Apply to all AS numbers\n"
4087 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4088
5000f21c 4089
718e3744 4090/* neighbor send-community. */
4091DEFUN (neighbor_send_community,
4092 neighbor_send_community_cmd,
9ccf14f7 4093 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4094 NEIGHBOR_STR
4095 NEIGHBOR_ADDR_STR2
4096 "Send Community attribute to this neighbor\n")
4097{
d62a17ae 4098 int idx_peer = 1;
27c05d4d 4099
d62a17ae 4100 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4101 bgp_node_safi(vty),
4102 PEER_FLAG_SEND_COMMUNITY);
718e3744 4103}
4104
d62a17ae 4105ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4106 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4107 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4108 "Send Community attribute to this neighbor\n")
596c17ba 4109
718e3744 4110DEFUN (no_neighbor_send_community,
4111 no_neighbor_send_community_cmd,
9ccf14f7 4112 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4113 NO_STR
4114 NEIGHBOR_STR
4115 NEIGHBOR_ADDR_STR2
4116 "Send Community attribute to this neighbor\n")
4117{
d62a17ae 4118 int idx_peer = 2;
27c05d4d 4119
d62a17ae 4120 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4121 bgp_node_afi(vty), bgp_node_safi(vty),
4122 PEER_FLAG_SEND_COMMUNITY);
718e3744 4123}
6b0655a2 4124
d62a17ae 4125ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4126 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4127 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4128 "Send Community attribute to this neighbor\n")
596c17ba 4129
718e3744 4130/* neighbor send-community extended. */
4131DEFUN (neighbor_send_community_type,
4132 neighbor_send_community_type_cmd,
57d187bc 4133 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4134 NEIGHBOR_STR
4135 NEIGHBOR_ADDR_STR2
4136 "Send Community attribute to this neighbor\n"
4137 "Send Standard and Extended Community attributes\n"
57d187bc 4138 "Send Standard, Large and Extended Community attributes\n"
718e3744 4139 "Send Extended Community attributes\n"
57d187bc
JS
4140 "Send Standard Community attributes\n"
4141 "Send Large Community attributes\n")
718e3744 4142{
27c05d4d 4143 int idx_peer = 1;
d7c0a89a 4144 uint32_t flag = 0;
27c05d4d 4145 const char *type = argv[argc - 1]->text;
d62a17ae 4146
27c05d4d 4147 if (strmatch(type, "standard")) {
d62a17ae 4148 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4149 } else if (strmatch(type, "extended")) {
d62a17ae 4150 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4151 } else if (strmatch(type, "large")) {
d62a17ae 4152 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4153 } else if (strmatch(type, "both")) {
d62a17ae 4154 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4155 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4156 } else { /* if (strmatch(type, "all")) */
d62a17ae 4157 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4158 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4159 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4160 }
4161
27c05d4d 4162 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4163 bgp_node_safi(vty), flag);
4164}
4165
4166ALIAS_HIDDEN(
4167 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4168 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4169 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4170 "Send Community attribute to this neighbor\n"
4171 "Send Standard and Extended Community attributes\n"
4172 "Send Standard, Large and Extended Community attributes\n"
4173 "Send Extended Community attributes\n"
4174 "Send Standard Community attributes\n"
4175 "Send Large Community attributes\n")
596c17ba 4176
718e3744 4177DEFUN (no_neighbor_send_community_type,
4178 no_neighbor_send_community_type_cmd,
57d187bc 4179 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4180 NO_STR
4181 NEIGHBOR_STR
4182 NEIGHBOR_ADDR_STR2
4183 "Send Community attribute to this neighbor\n"
4184 "Send Standard and Extended Community attributes\n"
57d187bc 4185 "Send Standard, Large and Extended Community attributes\n"
718e3744 4186 "Send Extended Community attributes\n"
57d187bc
JS
4187 "Send Standard Community attributes\n"
4188 "Send Large Community attributes\n")
718e3744 4189{
d62a17ae 4190 int idx_peer = 2;
27c05d4d 4191 uint32_t flag = 0;
d62a17ae 4192 const char *type = argv[argc - 1]->text;
4193
27c05d4d
PM
4194 if (strmatch(type, "standard")) {
4195 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4196 } else if (strmatch(type, "extended")) {
4197 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4198 } else if (strmatch(type, "large")) {
4199 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4200 } else if (strmatch(type, "both")) {
4201 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4202 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4203 } else { /* if (strmatch(type, "all")) */
4204 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4205 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4206 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4207 }
4208
4209 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4210 bgp_node_afi(vty), bgp_node_safi(vty),
4211 flag);
d62a17ae 4212}
4213
4214ALIAS_HIDDEN(
4215 no_neighbor_send_community_type,
4216 no_neighbor_send_community_type_hidden_cmd,
4217 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4218 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4219 "Send Community attribute to this neighbor\n"
4220 "Send Standard and Extended Community attributes\n"
4221 "Send Standard, Large and Extended Community attributes\n"
4222 "Send Extended Community attributes\n"
4223 "Send Standard Community attributes\n"
4224 "Send Large Community attributes\n")
596c17ba 4225
718e3744 4226/* neighbor soft-reconfig. */
4227DEFUN (neighbor_soft_reconfiguration,
4228 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4229 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4230 NEIGHBOR_STR
4231 NEIGHBOR_ADDR_STR2
4232 "Per neighbor soft reconfiguration\n"
4233 "Allow inbound soft reconfiguration for this neighbor\n")
4234{
d62a17ae 4235 int idx_peer = 1;
4236 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4237 bgp_node_safi(vty),
4238 PEER_FLAG_SOFT_RECONFIG);
718e3744 4239}
4240
d62a17ae 4241ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4242 neighbor_soft_reconfiguration_hidden_cmd,
4243 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4244 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4245 "Per neighbor soft reconfiguration\n"
4246 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4247
718e3744 4248DEFUN (no_neighbor_soft_reconfiguration,
4249 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4250 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4251 NO_STR
4252 NEIGHBOR_STR
4253 NEIGHBOR_ADDR_STR2
4254 "Per neighbor soft reconfiguration\n"
4255 "Allow inbound soft reconfiguration for this neighbor\n")
4256{
d62a17ae 4257 int idx_peer = 2;
4258 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4259 bgp_node_afi(vty), bgp_node_safi(vty),
4260 PEER_FLAG_SOFT_RECONFIG);
718e3744 4261}
6b0655a2 4262
d62a17ae 4263ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4264 no_neighbor_soft_reconfiguration_hidden_cmd,
4265 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4266 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4267 "Per neighbor soft reconfiguration\n"
4268 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4269
718e3744 4270DEFUN (neighbor_route_reflector_client,
4271 neighbor_route_reflector_client_cmd,
9ccf14f7 4272 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4273 NEIGHBOR_STR
4274 NEIGHBOR_ADDR_STR2
4275 "Configure a neighbor as Route Reflector client\n")
4276{
d62a17ae 4277 int idx_peer = 1;
4278 struct peer *peer;
718e3744 4279
4280
d62a17ae 4281 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4282 if (!peer)
4283 return CMD_WARNING_CONFIG_FAILED;
718e3744 4284
d62a17ae 4285 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4286 bgp_node_safi(vty),
4287 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4288}
4289
d62a17ae 4290ALIAS_HIDDEN(neighbor_route_reflector_client,
4291 neighbor_route_reflector_client_hidden_cmd,
4292 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4293 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4294 "Configure a neighbor as Route Reflector client\n")
596c17ba 4295
718e3744 4296DEFUN (no_neighbor_route_reflector_client,
4297 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4298 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4299 NO_STR
4300 NEIGHBOR_STR
4301 NEIGHBOR_ADDR_STR2
4302 "Configure a neighbor as Route Reflector client\n")
4303{
d62a17ae 4304 int idx_peer = 2;
4305 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4306 bgp_node_afi(vty), bgp_node_safi(vty),
4307 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4308}
6b0655a2 4309
d62a17ae 4310ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4311 no_neighbor_route_reflector_client_hidden_cmd,
4312 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4313 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4314 "Configure a neighbor as Route Reflector client\n")
596c17ba 4315
718e3744 4316/* neighbor route-server-client. */
4317DEFUN (neighbor_route_server_client,
4318 neighbor_route_server_client_cmd,
9ccf14f7 4319 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4320 NEIGHBOR_STR
4321 NEIGHBOR_ADDR_STR2
4322 "Configure a neighbor as Route Server client\n")
4323{
d62a17ae 4324 int idx_peer = 1;
4325 struct peer *peer;
2a3d5731 4326
d62a17ae 4327 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4328 if (!peer)
4329 return CMD_WARNING_CONFIG_FAILED;
4330 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4331 bgp_node_safi(vty),
4332 PEER_FLAG_RSERVER_CLIENT);
718e3744 4333}
4334
d62a17ae 4335ALIAS_HIDDEN(neighbor_route_server_client,
4336 neighbor_route_server_client_hidden_cmd,
4337 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4338 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4339 "Configure a neighbor as Route Server client\n")
596c17ba 4340
718e3744 4341DEFUN (no_neighbor_route_server_client,
4342 no_neighbor_route_server_client_cmd,
9ccf14f7 4343 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4344 NO_STR
4345 NEIGHBOR_STR
4346 NEIGHBOR_ADDR_STR2
4347 "Configure a neighbor as Route Server client\n")
fee0f4c6 4348{
d62a17ae 4349 int idx_peer = 2;
4350 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4351 bgp_node_afi(vty), bgp_node_safi(vty),
4352 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4353}
6b0655a2 4354
d62a17ae 4355ALIAS_HIDDEN(no_neighbor_route_server_client,
4356 no_neighbor_route_server_client_hidden_cmd,
4357 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4358 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4359 "Configure a neighbor as Route Server client\n")
596c17ba 4360
fee0f4c6 4361DEFUN (neighbor_nexthop_local_unchanged,
4362 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4363 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4364 NEIGHBOR_STR
4365 NEIGHBOR_ADDR_STR2
4366 "Configure treatment of outgoing link-local nexthop attribute\n"
4367 "Leave link-local nexthop unchanged for this peer\n")
4368{
d62a17ae 4369 int idx_peer = 1;
4370 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4371 bgp_node_safi(vty),
4372 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4373}
6b0655a2 4374
fee0f4c6 4375DEFUN (no_neighbor_nexthop_local_unchanged,
4376 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4377 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4378 NO_STR
4379 NEIGHBOR_STR
4380 NEIGHBOR_ADDR_STR2
4381 "Configure treatment of outgoing link-local-nexthop attribute\n"
4382 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4383{
d62a17ae 4384 int idx_peer = 2;
4385 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4386 bgp_node_afi(vty), bgp_node_safi(vty),
4387 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4388}
6b0655a2 4389
718e3744 4390DEFUN (neighbor_attr_unchanged,
4391 neighbor_attr_unchanged_cmd,
a8206004 4392 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4393 NEIGHBOR_STR
4394 NEIGHBOR_ADDR_STR2
4395 "BGP attribute is propagated unchanged to this neighbor\n"
4396 "As-path attribute\n"
4397 "Nexthop attribute\n"
a8206004 4398 "Med attribute\n")
718e3744 4399{
d62a17ae 4400 int idx = 0;
8eeb0335
DW
4401 char *peer_str = argv[1]->arg;
4402 struct peer *peer;
d7c0a89a 4403 uint16_t flags = 0;
8eeb0335
DW
4404 afi_t afi = bgp_node_afi(vty);
4405 safi_t safi = bgp_node_safi(vty);
4406
4407 peer = peer_and_group_lookup_vty(vty, peer_str);
4408 if (!peer)
4409 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4410
4411 if (argv_find(argv, argc, "as-path", &idx))
4412 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4413 idx = 0;
4414 if (argv_find(argv, argc, "next-hop", &idx))
4415 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4416 idx = 0;
4417 if (argv_find(argv, argc, "med", &idx))
4418 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4419
8eeb0335
DW
4420 /* no flags means all of them! */
4421 if (!flags) {
d62a17ae 4422 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4423 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4424 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4425 } else {
a4d82a8a
PZ
4426 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4427 && peer_af_flag_check(peer, afi, safi,
4428 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4429 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4430 PEER_FLAG_AS_PATH_UNCHANGED);
4431 }
4432
a4d82a8a
PZ
4433 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4434 && peer_af_flag_check(peer, afi, safi,
4435 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4436 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4437 PEER_FLAG_NEXTHOP_UNCHANGED);
4438 }
4439
a4d82a8a
PZ
4440 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4441 && peer_af_flag_check(peer, afi, safi,
4442 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4443 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4444 PEER_FLAG_MED_UNCHANGED);
4445 }
d62a17ae 4446 }
4447
8eeb0335 4448 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4449}
4450
4451ALIAS_HIDDEN(
4452 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4453 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4454 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4455 "BGP attribute is propagated unchanged to this neighbor\n"
4456 "As-path attribute\n"
4457 "Nexthop attribute\n"
4458 "Med attribute\n")
596c17ba 4459
718e3744 4460DEFUN (no_neighbor_attr_unchanged,
4461 no_neighbor_attr_unchanged_cmd,
a8206004 4462 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4463 NO_STR
718e3744 4464 NEIGHBOR_STR
4465 NEIGHBOR_ADDR_STR2
31500417
DW
4466 "BGP attribute is propagated unchanged to this neighbor\n"
4467 "As-path attribute\n"
40e718b5 4468 "Nexthop attribute\n"
a8206004 4469 "Med attribute\n")
718e3744 4470{
d62a17ae 4471 int idx = 0;
4472 char *peer = argv[2]->arg;
d7c0a89a 4473 uint16_t flags = 0;
d62a17ae 4474
4475 if (argv_find(argv, argc, "as-path", &idx))
4476 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4477 idx = 0;
4478 if (argv_find(argv, argc, "next-hop", &idx))
4479 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4480 idx = 0;
4481 if (argv_find(argv, argc, "med", &idx))
4482 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4483
4484 if (!flags) // no flags means all of them!
4485 {
4486 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4487 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4488 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4489 }
4490
4491 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4492 bgp_node_safi(vty), flags);
4493}
4494
4495ALIAS_HIDDEN(
4496 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4497 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4498 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4499 "BGP attribute is propagated unchanged to this neighbor\n"
4500 "As-path attribute\n"
4501 "Nexthop attribute\n"
4502 "Med attribute\n")
718e3744 4503
718e3744 4504/* EBGP multihop configuration. */
d62a17ae 4505static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4506 const char *ttl_str)
718e3744 4507{
d62a17ae 4508 struct peer *peer;
4509 unsigned int ttl;
718e3744 4510
d62a17ae 4511 peer = peer_and_group_lookup_vty(vty, ip_str);
4512 if (!peer)
4513 return CMD_WARNING_CONFIG_FAILED;
718e3744 4514
d62a17ae 4515 if (peer->conf_if)
4516 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4517
d62a17ae 4518 if (!ttl_str)
4519 ttl = MAXTTL;
4520 else
4521 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4522
d62a17ae 4523 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4524}
4525
d62a17ae 4526static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4527{
d62a17ae 4528 struct peer *peer;
718e3744 4529
d62a17ae 4530 peer = peer_and_group_lookup_vty(vty, ip_str);
4531 if (!peer)
4532 return CMD_WARNING_CONFIG_FAILED;
718e3744 4533
d62a17ae 4534 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4535}
4536
4537/* neighbor ebgp-multihop. */
4538DEFUN (neighbor_ebgp_multihop,
4539 neighbor_ebgp_multihop_cmd,
9ccf14f7 4540 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4541 NEIGHBOR_STR
4542 NEIGHBOR_ADDR_STR2
4543 "Allow EBGP neighbors not on directly connected networks\n")
4544{
d62a17ae 4545 int idx_peer = 1;
4546 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4547}
4548
4549DEFUN (neighbor_ebgp_multihop_ttl,
4550 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4551 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4552 NEIGHBOR_STR
4553 NEIGHBOR_ADDR_STR2
4554 "Allow EBGP neighbors not on directly connected networks\n"
4555 "maximum hop count\n")
4556{
d62a17ae 4557 int idx_peer = 1;
4558 int idx_number = 3;
4559 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4560 argv[idx_number]->arg);
718e3744 4561}
4562
4563DEFUN (no_neighbor_ebgp_multihop,
4564 no_neighbor_ebgp_multihop_cmd,
a636c635 4565 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4566 NO_STR
4567 NEIGHBOR_STR
4568 NEIGHBOR_ADDR_STR2
a636c635
DW
4569 "Allow EBGP neighbors not on directly connected networks\n"
4570 "maximum hop count\n")
718e3744 4571{
d62a17ae 4572 int idx_peer = 2;
4573 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4574}
4575
6b0655a2 4576
6ffd2079 4577/* disable-connected-check */
4578DEFUN (neighbor_disable_connected_check,
4579 neighbor_disable_connected_check_cmd,
7ebe625c 4580 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4581 NEIGHBOR_STR
7ebe625c 4582 NEIGHBOR_ADDR_STR2
a636c635
DW
4583 "one-hop away EBGP peer using loopback address\n"
4584 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4585{
d62a17ae 4586 int idx_peer = 1;
4587 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4588 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4589}
4590
4591DEFUN (no_neighbor_disable_connected_check,
4592 no_neighbor_disable_connected_check_cmd,
7ebe625c 4593 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4594 NO_STR
4595 NEIGHBOR_STR
7ebe625c 4596 NEIGHBOR_ADDR_STR2
a636c635
DW
4597 "one-hop away EBGP peer using loopback address\n"
4598 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4599{
d62a17ae 4600 int idx_peer = 2;
4601 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4602 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4603}
4604
47cbc09b
PM
4605
4606/* enforce-first-as */
4607DEFUN (neighbor_enforce_first_as,
4608 neighbor_enforce_first_as_cmd,
4609 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4610 NEIGHBOR_STR
4611 NEIGHBOR_ADDR_STR2
4612 "Enforce the first AS for EBGP routes\n")
4613{
4614 int idx_peer = 1;
4615
4616 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4617 PEER_FLAG_ENFORCE_FIRST_AS);
4618}
4619
4620DEFUN (no_neighbor_enforce_first_as,
4621 no_neighbor_enforce_first_as_cmd,
4622 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4623 NO_STR
4624 NEIGHBOR_STR
4625 NEIGHBOR_ADDR_STR2
4626 "Enforce the first AS for EBGP routes\n")
4627{
4628 int idx_peer = 2;
4629
4630 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4631 PEER_FLAG_ENFORCE_FIRST_AS);
4632}
4633
4634
718e3744 4635DEFUN (neighbor_description,
4636 neighbor_description_cmd,
e961923c 4637 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4638 NEIGHBOR_STR
4639 NEIGHBOR_ADDR_STR2
4640 "Neighbor specific description\n"
4641 "Up to 80 characters describing this neighbor\n")
4642{
d62a17ae 4643 int idx_peer = 1;
4644 int idx_line = 3;
4645 struct peer *peer;
4646 char *str;
718e3744 4647
d62a17ae 4648 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4649 if (!peer)
4650 return CMD_WARNING_CONFIG_FAILED;
718e3744 4651
d62a17ae 4652 str = argv_concat(argv, argc, idx_line);
718e3744 4653
d62a17ae 4654 peer_description_set(peer, str);
718e3744 4655
d62a17ae 4656 XFREE(MTYPE_TMP, str);
718e3744 4657
d62a17ae 4658 return CMD_SUCCESS;
718e3744 4659}
4660
4661DEFUN (no_neighbor_description,
4662 no_neighbor_description_cmd,
a14810f4 4663 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4664 NO_STR
4665 NEIGHBOR_STR
4666 NEIGHBOR_ADDR_STR2
a14810f4 4667 "Neighbor specific description\n")
718e3744 4668{
d62a17ae 4669 int idx_peer = 2;
4670 struct peer *peer;
718e3744 4671
d62a17ae 4672 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4673 if (!peer)
4674 return CMD_WARNING_CONFIG_FAILED;
718e3744 4675
d62a17ae 4676 peer_description_unset(peer);
718e3744 4677
d62a17ae 4678 return CMD_SUCCESS;
718e3744 4679}
4680
a14810f4
PM
4681ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4682 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4683 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4684 "Neighbor specific description\n"
4685 "Up to 80 characters describing this neighbor\n")
6b0655a2 4686
718e3744 4687/* Neighbor update-source. */
d62a17ae 4688static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4689 const char *source_str)
4690{
4691 struct peer *peer;
4692 struct prefix p;
a14810f4 4693 union sockunion su;
d62a17ae 4694
4695 peer = peer_and_group_lookup_vty(vty, peer_str);
4696 if (!peer)
4697 return CMD_WARNING_CONFIG_FAILED;
4698
4699 if (peer->conf_if)
4700 return CMD_WARNING;
4701
4702 if (source_str) {
a14810f4 4703 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4704 peer_update_source_addr_set(peer, &su);
4705 else {
4706 if (str2prefix(source_str, &p)) {
4707 vty_out(vty,
4708 "%% Invalid update-source, remove prefix length \n");
4709 return CMD_WARNING_CONFIG_FAILED;
4710 } else
4711 peer_update_source_if_set(peer, source_str);
4712 }
4713 } else
4714 peer_update_source_unset(peer);
4715
4716 return CMD_SUCCESS;
4717}
4718
4719#define BGP_UPDATE_SOURCE_HELP_STR \
4720 "IPv4 address\n" \
4721 "IPv6 address\n" \
4722 "Interface name (requires zebra to be running)\n"
369688c0 4723
718e3744 4724DEFUN (neighbor_update_source,
4725 neighbor_update_source_cmd,
9ccf14f7 4726 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4727 NEIGHBOR_STR
4728 NEIGHBOR_ADDR_STR2
4729 "Source of routing updates\n"
369688c0 4730 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4731{
d62a17ae 4732 int idx_peer = 1;
4733 int idx_peer_2 = 3;
4734 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4735 argv[idx_peer_2]->arg);
718e3744 4736}
4737
4738DEFUN (no_neighbor_update_source,
4739 no_neighbor_update_source_cmd,
c7178fe7 4740 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4741 NO_STR
4742 NEIGHBOR_STR
4743 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4744 "Source of routing updates\n"
4745 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4746{
d62a17ae 4747 int idx_peer = 2;
4748 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4749}
6b0655a2 4750
d62a17ae 4751static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4752 afi_t afi, safi_t safi,
4753 const char *rmap, int set)
718e3744 4754{
d62a17ae 4755 int ret;
4756 struct peer *peer;
718e3744 4757
d62a17ae 4758 peer = peer_and_group_lookup_vty(vty, peer_str);
4759 if (!peer)
4760 return CMD_WARNING_CONFIG_FAILED;
718e3744 4761
d62a17ae 4762 if (set)
4763 ret = peer_default_originate_set(peer, afi, safi, rmap);
4764 else
4765 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4766
d62a17ae 4767 return bgp_vty_return(vty, ret);
718e3744 4768}
4769
4770/* neighbor default-originate. */
4771DEFUN (neighbor_default_originate,
4772 neighbor_default_originate_cmd,
9ccf14f7 4773 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4774 NEIGHBOR_STR
4775 NEIGHBOR_ADDR_STR2
4776 "Originate default route to this neighbor\n")
4777{
d62a17ae 4778 int idx_peer = 1;
4779 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4780 bgp_node_afi(vty),
4781 bgp_node_safi(vty), NULL, 1);
718e3744 4782}
4783
d62a17ae 4784ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4785 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4786 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4787 "Originate default route to this neighbor\n")
596c17ba 4788
718e3744 4789DEFUN (neighbor_default_originate_rmap,
4790 neighbor_default_originate_rmap_cmd,
9ccf14f7 4791 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4792 NEIGHBOR_STR
4793 NEIGHBOR_ADDR_STR2
4794 "Originate default route to this neighbor\n"
4795 "Route-map to specify criteria to originate default\n"
4796 "route-map name\n")
4797{
d62a17ae 4798 int idx_peer = 1;
4799 int idx_word = 4;
4800 return peer_default_originate_set_vty(
4801 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4802 argv[idx_word]->arg, 1);
718e3744 4803}
4804
d62a17ae 4805ALIAS_HIDDEN(
4806 neighbor_default_originate_rmap,
4807 neighbor_default_originate_rmap_hidden_cmd,
4808 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4809 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4810 "Originate default route to this neighbor\n"
4811 "Route-map to specify criteria to originate default\n"
4812 "route-map name\n")
596c17ba 4813
718e3744 4814DEFUN (no_neighbor_default_originate,
4815 no_neighbor_default_originate_cmd,
a636c635 4816 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4817 NO_STR
4818 NEIGHBOR_STR
4819 NEIGHBOR_ADDR_STR2
a636c635
DW
4820 "Originate default route to this neighbor\n"
4821 "Route-map to specify criteria to originate default\n"
4822 "route-map name\n")
718e3744 4823{
d62a17ae 4824 int idx_peer = 2;
4825 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4826 bgp_node_afi(vty),
4827 bgp_node_safi(vty), NULL, 0);
718e3744 4828}
4829
d62a17ae 4830ALIAS_HIDDEN(
4831 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4832 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4833 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4834 "Originate default route to this neighbor\n"
4835 "Route-map to specify criteria to originate default\n"
4836 "route-map name\n")
596c17ba 4837
6b0655a2 4838
718e3744 4839/* Set neighbor's BGP port. */
d62a17ae 4840static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4841 const char *port_str)
4842{
4843 struct peer *peer;
d7c0a89a 4844 uint16_t port;
d62a17ae 4845 struct servent *sp;
4846
4847 peer = peer_lookup_vty(vty, ip_str);
4848 if (!peer)
4849 return CMD_WARNING_CONFIG_FAILED;
4850
4851 if (!port_str) {
4852 sp = getservbyname("bgp", "tcp");
4853 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4854 } else {
4855 port = strtoul(port_str, NULL, 10);
4856 }
718e3744 4857
d62a17ae 4858 peer_port_set(peer, port);
718e3744 4859
d62a17ae 4860 return CMD_SUCCESS;
718e3744 4861}
4862
f418446b 4863/* Set specified peer's BGP port. */
718e3744 4864DEFUN (neighbor_port,
4865 neighbor_port_cmd,
9ccf14f7 4866 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4867 NEIGHBOR_STR
4868 NEIGHBOR_ADDR_STR
4869 "Neighbor's BGP port\n"
4870 "TCP port number\n")
4871{
d62a17ae 4872 int idx_ip = 1;
4873 int idx_number = 3;
4874 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4875 argv[idx_number]->arg);
718e3744 4876}
4877
4878DEFUN (no_neighbor_port,
4879 no_neighbor_port_cmd,
9ccf14f7 4880 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4881 NO_STR
4882 NEIGHBOR_STR
4883 NEIGHBOR_ADDR_STR
8334fd5a
DW
4884 "Neighbor's BGP port\n"
4885 "TCP port number\n")
718e3744 4886{
d62a17ae 4887 int idx_ip = 2;
4888 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4889}
4890
6b0655a2 4891
718e3744 4892/* neighbor weight. */
d62a17ae 4893static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4894 safi_t safi, const char *weight_str)
718e3744 4895{
d62a17ae 4896 int ret;
4897 struct peer *peer;
4898 unsigned long weight;
718e3744 4899
d62a17ae 4900 peer = peer_and_group_lookup_vty(vty, ip_str);
4901 if (!peer)
4902 return CMD_WARNING_CONFIG_FAILED;
718e3744 4903
d62a17ae 4904 weight = strtoul(weight_str, NULL, 10);
718e3744 4905
d62a17ae 4906 ret = peer_weight_set(peer, afi, safi, weight);
4907 return bgp_vty_return(vty, ret);
718e3744 4908}
4909
d62a17ae 4910static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4911 safi_t safi)
718e3744 4912{
d62a17ae 4913 int ret;
4914 struct peer *peer;
718e3744 4915
d62a17ae 4916 peer = peer_and_group_lookup_vty(vty, ip_str);
4917 if (!peer)
4918 return CMD_WARNING_CONFIG_FAILED;
718e3744 4919
d62a17ae 4920 ret = peer_weight_unset(peer, afi, safi);
4921 return bgp_vty_return(vty, ret);
718e3744 4922}
4923
4924DEFUN (neighbor_weight,
4925 neighbor_weight_cmd,
9ccf14f7 4926 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4927 NEIGHBOR_STR
4928 NEIGHBOR_ADDR_STR2
4929 "Set default weight for routes from this neighbor\n"
4930 "default weight\n")
4931{
d62a17ae 4932 int idx_peer = 1;
4933 int idx_number = 3;
4934 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4935 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4936}
4937
d62a17ae 4938ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4939 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4940 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4941 "Set default weight for routes from this neighbor\n"
4942 "default weight\n")
596c17ba 4943
718e3744 4944DEFUN (no_neighbor_weight,
4945 no_neighbor_weight_cmd,
9ccf14f7 4946 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4947 NO_STR
4948 NEIGHBOR_STR
4949 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4950 "Set default weight for routes from this neighbor\n"
4951 "default weight\n")
718e3744 4952{
d62a17ae 4953 int idx_peer = 2;
4954 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4955 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4956}
4957
d62a17ae 4958ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4959 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4960 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4961 "Set default weight for routes from this neighbor\n"
4962 "default weight\n")
596c17ba 4963
6b0655a2 4964
718e3744 4965/* Override capability negotiation. */
4966DEFUN (neighbor_override_capability,
4967 neighbor_override_capability_cmd,
9ccf14f7 4968 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4969 NEIGHBOR_STR
4970 NEIGHBOR_ADDR_STR2
4971 "Override capability negotiation result\n")
4972{
d62a17ae 4973 int idx_peer = 1;
4974 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4975 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4976}
4977
4978DEFUN (no_neighbor_override_capability,
4979 no_neighbor_override_capability_cmd,
9ccf14f7 4980 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4981 NO_STR
4982 NEIGHBOR_STR
4983 NEIGHBOR_ADDR_STR2
4984 "Override capability negotiation result\n")
4985{
d62a17ae 4986 int idx_peer = 2;
4987 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4988 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4989}
6b0655a2 4990
718e3744 4991DEFUN (neighbor_strict_capability,
4992 neighbor_strict_capability_cmd,
9fb964de 4993 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 4994 NEIGHBOR_STR
9fb964de 4995 NEIGHBOR_ADDR_STR2
718e3744 4996 "Strict capability negotiation match\n")
4997{
9fb964de
PM
4998 int idx_peer = 1;
4999
5000 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5001 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5002}
5003
5004DEFUN (no_neighbor_strict_capability,
5005 no_neighbor_strict_capability_cmd,
9fb964de 5006 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5007 NO_STR
5008 NEIGHBOR_STR
9fb964de 5009 NEIGHBOR_ADDR_STR2
718e3744 5010 "Strict capability negotiation match\n")
5011{
9fb964de
PM
5012 int idx_peer = 2;
5013
5014 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5015 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5016}
6b0655a2 5017
d62a17ae 5018static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5019 const char *keep_str, const char *hold_str)
718e3744 5020{
d62a17ae 5021 int ret;
5022 struct peer *peer;
d7c0a89a
QY
5023 uint32_t keepalive;
5024 uint32_t holdtime;
718e3744 5025
d62a17ae 5026 peer = peer_and_group_lookup_vty(vty, ip_str);
5027 if (!peer)
5028 return CMD_WARNING_CONFIG_FAILED;
718e3744 5029
d62a17ae 5030 keepalive = strtoul(keep_str, NULL, 10);
5031 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5032
d62a17ae 5033 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5034
d62a17ae 5035 return bgp_vty_return(vty, ret);
718e3744 5036}
6b0655a2 5037
d62a17ae 5038static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5039{
d62a17ae 5040 int ret;
5041 struct peer *peer;
718e3744 5042
d62a17ae 5043 peer = peer_and_group_lookup_vty(vty, ip_str);
5044 if (!peer)
5045 return CMD_WARNING_CONFIG_FAILED;
718e3744 5046
d62a17ae 5047 ret = peer_timers_unset(peer);
718e3744 5048
d62a17ae 5049 return bgp_vty_return(vty, ret);
718e3744 5050}
5051
5052DEFUN (neighbor_timers,
5053 neighbor_timers_cmd,
9ccf14f7 5054 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5055 NEIGHBOR_STR
5056 NEIGHBOR_ADDR_STR2
5057 "BGP per neighbor timers\n"
5058 "Keepalive interval\n"
5059 "Holdtime\n")
5060{
d62a17ae 5061 int idx_peer = 1;
5062 int idx_number = 3;
5063 int idx_number_2 = 4;
5064 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5065 argv[idx_number]->arg,
5066 argv[idx_number_2]->arg);
718e3744 5067}
5068
5069DEFUN (no_neighbor_timers,
5070 no_neighbor_timers_cmd,
9ccf14f7 5071 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5072 NO_STR
5073 NEIGHBOR_STR
5074 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5075 "BGP per neighbor timers\n"
5076 "Keepalive interval\n"
5077 "Holdtime\n")
718e3744 5078{
d62a17ae 5079 int idx_peer = 2;
5080 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5081}
6b0655a2 5082
813d4307 5083
d62a17ae 5084static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5085 const char *time_str)
718e3744 5086{
d62a17ae 5087 int ret;
5088 struct peer *peer;
d7c0a89a 5089 uint32_t connect;
718e3744 5090
d62a17ae 5091 peer = peer_and_group_lookup_vty(vty, ip_str);
5092 if (!peer)
5093 return CMD_WARNING_CONFIG_FAILED;
718e3744 5094
d62a17ae 5095 connect = strtoul(time_str, NULL, 10);
718e3744 5096
d62a17ae 5097 ret = peer_timers_connect_set(peer, connect);
718e3744 5098
d62a17ae 5099 return bgp_vty_return(vty, ret);
718e3744 5100}
5101
d62a17ae 5102static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5103{
d62a17ae 5104 int ret;
5105 struct peer *peer;
718e3744 5106
d62a17ae 5107 peer = peer_and_group_lookup_vty(vty, ip_str);
5108 if (!peer)
5109 return CMD_WARNING_CONFIG_FAILED;
718e3744 5110
d62a17ae 5111 ret = peer_timers_connect_unset(peer);
718e3744 5112
d62a17ae 5113 return bgp_vty_return(vty, ret);
718e3744 5114}
5115
5116DEFUN (neighbor_timers_connect,
5117 neighbor_timers_connect_cmd,
9ccf14f7 5118 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5119 NEIGHBOR_STR
966f821c 5120 NEIGHBOR_ADDR_STR2
718e3744 5121 "BGP per neighbor timers\n"
5122 "BGP connect timer\n"
5123 "Connect timer\n")
5124{
d62a17ae 5125 int idx_peer = 1;
5126 int idx_number = 4;
5127 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5128 argv[idx_number]->arg);
718e3744 5129}
5130
5131DEFUN (no_neighbor_timers_connect,
5132 no_neighbor_timers_connect_cmd,
9ccf14f7 5133 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5134 NO_STR
5135 NEIGHBOR_STR
966f821c 5136 NEIGHBOR_ADDR_STR2
718e3744 5137 "BGP per neighbor timers\n"
8334fd5a
DW
5138 "BGP connect timer\n"
5139 "Connect timer\n")
718e3744 5140{
d62a17ae 5141 int idx_peer = 2;
5142 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5143}
5144
6b0655a2 5145
d62a17ae 5146static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5147 const char *time_str, int set)
718e3744 5148{
d62a17ae 5149 int ret;
5150 struct peer *peer;
d7c0a89a 5151 uint32_t routeadv = 0;
718e3744 5152
d62a17ae 5153 peer = peer_and_group_lookup_vty(vty, ip_str);
5154 if (!peer)
5155 return CMD_WARNING_CONFIG_FAILED;
718e3744 5156
d62a17ae 5157 if (time_str)
5158 routeadv = strtoul(time_str, NULL, 10);
718e3744 5159
d62a17ae 5160 if (set)
5161 ret = peer_advertise_interval_set(peer, routeadv);
5162 else
5163 ret = peer_advertise_interval_unset(peer);
718e3744 5164
d62a17ae 5165 return bgp_vty_return(vty, ret);
718e3744 5166}
5167
5168DEFUN (neighbor_advertise_interval,
5169 neighbor_advertise_interval_cmd,
9ccf14f7 5170 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5171 NEIGHBOR_STR
966f821c 5172 NEIGHBOR_ADDR_STR2
718e3744 5173 "Minimum interval between sending BGP routing updates\n"
5174 "time in seconds\n")
5175{
d62a17ae 5176 int idx_peer = 1;
5177 int idx_number = 3;
5178 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5179 argv[idx_number]->arg, 1);
718e3744 5180}
5181
5182DEFUN (no_neighbor_advertise_interval,
5183 no_neighbor_advertise_interval_cmd,
9ccf14f7 5184 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5185 NO_STR
5186 NEIGHBOR_STR
966f821c 5187 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5188 "Minimum interval between sending BGP routing updates\n"
5189 "time in seconds\n")
718e3744 5190{
d62a17ae 5191 int idx_peer = 2;
5192 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5193}
5194
6b0655a2 5195
518f0eb1
DS
5196/* Time to wait before processing route-map updates */
5197DEFUN (bgp_set_route_map_delay_timer,
5198 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5199 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5200 SET_STR
5201 "BGP route-map delay timer\n"
5202 "Time in secs to wait before processing route-map changes\n"
f414725f 5203 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5204{
d62a17ae 5205 int idx_number = 3;
d7c0a89a 5206 uint32_t rmap_delay_timer;
d62a17ae 5207
5208 if (argv[idx_number]->arg) {
5209 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5210 bm->rmap_update_timer = rmap_delay_timer;
5211
5212 /* if the dynamic update handling is being disabled, and a timer
5213 * is
5214 * running, stop the timer and act as if the timer has already
5215 * fired.
5216 */
5217 if (!rmap_delay_timer && bm->t_rmap_update) {
5218 BGP_TIMER_OFF(bm->t_rmap_update);
5219 thread_execute(bm->master, bgp_route_map_update_timer,
5220 NULL, 0);
5221 }
5222 return CMD_SUCCESS;
5223 } else {
5224 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5225 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5226 }
518f0eb1
DS
5227}
5228
5229DEFUN (no_bgp_set_route_map_delay_timer,
5230 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5231 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5232 NO_STR
3a2d747c 5233 BGP_STR
518f0eb1 5234 "Default BGP route-map delay timer\n"
8334fd5a
DW
5235 "Reset to default time to wait for processing route-map changes\n"
5236 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5237{
518f0eb1 5238
d62a17ae 5239 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5240
d62a17ae 5241 return CMD_SUCCESS;
518f0eb1
DS
5242}
5243
f414725f 5244
718e3744 5245/* neighbor interface */
d62a17ae 5246static int peer_interface_vty(struct vty *vty, const char *ip_str,
5247 const char *str)
718e3744 5248{
d62a17ae 5249 struct peer *peer;
718e3744 5250
d62a17ae 5251 peer = peer_lookup_vty(vty, ip_str);
5252 if (!peer || peer->conf_if) {
5253 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5254 return CMD_WARNING_CONFIG_FAILED;
5255 }
718e3744 5256
d62a17ae 5257 if (str)
5258 peer_interface_set(peer, str);
5259 else
5260 peer_interface_unset(peer);
718e3744 5261
d62a17ae 5262 return CMD_SUCCESS;
718e3744 5263}
5264
5265DEFUN (neighbor_interface,
5266 neighbor_interface_cmd,
9ccf14f7 5267 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5268 NEIGHBOR_STR
5269 NEIGHBOR_ADDR_STR
5270 "Interface\n"
5271 "Interface name\n")
5272{
d62a17ae 5273 int idx_ip = 1;
5274 int idx_word = 3;
5275 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5276}
5277
5278DEFUN (no_neighbor_interface,
5279 no_neighbor_interface_cmd,
9ccf14f7 5280 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5281 NO_STR
5282 NEIGHBOR_STR
16cedbb0 5283 NEIGHBOR_ADDR_STR2
718e3744 5284 "Interface\n"
5285 "Interface name\n")
5286{
d62a17ae 5287 int idx_peer = 2;
5288 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5289}
6b0655a2 5290
718e3744 5291DEFUN (neighbor_distribute_list,
5292 neighbor_distribute_list_cmd,
9ccf14f7 5293 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5294 NEIGHBOR_STR
5295 NEIGHBOR_ADDR_STR2
5296 "Filter updates to/from this neighbor\n"
5297 "IP access-list number\n"
5298 "IP access-list number (expanded range)\n"
5299 "IP Access-list name\n"
5300 "Filter incoming updates\n"
5301 "Filter outgoing updates\n")
5302{
d62a17ae 5303 int idx_peer = 1;
5304 int idx_acl = 3;
5305 int direct, ret;
5306 struct peer *peer;
a8206004 5307
d62a17ae 5308 const char *pstr = argv[idx_peer]->arg;
5309 const char *acl = argv[idx_acl]->arg;
5310 const char *inout = argv[argc - 1]->text;
a8206004 5311
d62a17ae 5312 peer = peer_and_group_lookup_vty(vty, pstr);
5313 if (!peer)
5314 return CMD_WARNING_CONFIG_FAILED;
a8206004 5315
d62a17ae 5316 /* Check filter direction. */
5317 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5318 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5319 direct, acl);
a8206004 5320
d62a17ae 5321 return bgp_vty_return(vty, ret);
718e3744 5322}
5323
d62a17ae 5324ALIAS_HIDDEN(
5325 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5326 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5327 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5328 "Filter updates to/from this neighbor\n"
5329 "IP access-list number\n"
5330 "IP access-list number (expanded range)\n"
5331 "IP Access-list name\n"
5332 "Filter incoming updates\n"
5333 "Filter outgoing updates\n")
596c17ba 5334
718e3744 5335DEFUN (no_neighbor_distribute_list,
5336 no_neighbor_distribute_list_cmd,
9ccf14f7 5337 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5338 NO_STR
5339 NEIGHBOR_STR
5340 NEIGHBOR_ADDR_STR2
5341 "Filter updates to/from this neighbor\n"
5342 "IP access-list number\n"
5343 "IP access-list number (expanded range)\n"
5344 "IP Access-list name\n"
5345 "Filter incoming updates\n"
5346 "Filter outgoing updates\n")
5347{
d62a17ae 5348 int idx_peer = 2;
5349 int direct, ret;
5350 struct peer *peer;
a8206004 5351
d62a17ae 5352 const char *pstr = argv[idx_peer]->arg;
5353 const char *inout = argv[argc - 1]->text;
a8206004 5354
d62a17ae 5355 peer = peer_and_group_lookup_vty(vty, pstr);
5356 if (!peer)
5357 return CMD_WARNING_CONFIG_FAILED;
a8206004 5358
d62a17ae 5359 /* Check filter direction. */
5360 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5361 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5362 direct);
a8206004 5363
d62a17ae 5364 return bgp_vty_return(vty, ret);
718e3744 5365}
6b0655a2 5366
d62a17ae 5367ALIAS_HIDDEN(
5368 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5369 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5370 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5371 "Filter updates to/from this neighbor\n"
5372 "IP access-list number\n"
5373 "IP access-list number (expanded range)\n"
5374 "IP Access-list name\n"
5375 "Filter incoming updates\n"
5376 "Filter outgoing updates\n")
596c17ba 5377
718e3744 5378/* Set prefix list to the peer. */
d62a17ae 5379static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5380 afi_t afi, safi_t safi,
5381 const char *name_str,
5382 const char *direct_str)
718e3744 5383{
d62a17ae 5384 int ret;
d62a17ae 5385 int direct = FILTER_IN;
cf9ac8bf 5386 struct peer *peer;
718e3744 5387
d62a17ae 5388 peer = peer_and_group_lookup_vty(vty, ip_str);
5389 if (!peer)
5390 return CMD_WARNING_CONFIG_FAILED;
718e3744 5391
d62a17ae 5392 /* Check filter direction. */
5393 if (strncmp(direct_str, "i", 1) == 0)
5394 direct = FILTER_IN;
5395 else if (strncmp(direct_str, "o", 1) == 0)
5396 direct = FILTER_OUT;
718e3744 5397
d62a17ae 5398 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5399
d62a17ae 5400 return bgp_vty_return(vty, ret);
718e3744 5401}
5402
d62a17ae 5403static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5404 afi_t afi, safi_t safi,
5405 const char *direct_str)
718e3744 5406{
d62a17ae 5407 int ret;
5408 struct peer *peer;
5409 int direct = FILTER_IN;
718e3744 5410
d62a17ae 5411 peer = peer_and_group_lookup_vty(vty, ip_str);
5412 if (!peer)
5413 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5414
d62a17ae 5415 /* Check filter direction. */
5416 if (strncmp(direct_str, "i", 1) == 0)
5417 direct = FILTER_IN;
5418 else if (strncmp(direct_str, "o", 1) == 0)
5419 direct = FILTER_OUT;
718e3744 5420
d62a17ae 5421 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5422
d62a17ae 5423 return bgp_vty_return(vty, ret);
718e3744 5424}
5425
5426DEFUN (neighbor_prefix_list,
5427 neighbor_prefix_list_cmd,
9ccf14f7 5428 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5429 NEIGHBOR_STR
5430 NEIGHBOR_ADDR_STR2
5431 "Filter updates to/from this neighbor\n"
5432 "Name of a prefix list\n"
5433 "Filter incoming updates\n"
5434 "Filter outgoing updates\n")
5435{
d62a17ae 5436 int idx_peer = 1;
5437 int idx_word = 3;
5438 int idx_in_out = 4;
5439 return peer_prefix_list_set_vty(
5440 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5441 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5442}
5443
d62a17ae 5444ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5445 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5446 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5447 "Filter updates to/from this neighbor\n"
5448 "Name of a prefix list\n"
5449 "Filter incoming updates\n"
5450 "Filter outgoing updates\n")
596c17ba 5451
718e3744 5452DEFUN (no_neighbor_prefix_list,
5453 no_neighbor_prefix_list_cmd,
9ccf14f7 5454 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5455 NO_STR
5456 NEIGHBOR_STR
5457 NEIGHBOR_ADDR_STR2
5458 "Filter updates to/from this neighbor\n"
5459 "Name of a prefix list\n"
5460 "Filter incoming updates\n"
5461 "Filter outgoing updates\n")
5462{
d62a17ae 5463 int idx_peer = 2;
5464 int idx_in_out = 5;
5465 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5466 bgp_node_afi(vty), bgp_node_safi(vty),
5467 argv[idx_in_out]->arg);
718e3744 5468}
6b0655a2 5469
d62a17ae 5470ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5471 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5472 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5473 "Filter updates to/from this neighbor\n"
5474 "Name of a prefix list\n"
5475 "Filter incoming updates\n"
5476 "Filter outgoing updates\n")
596c17ba 5477
d62a17ae 5478static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5479 safi_t safi, const char *name_str,
5480 const char *direct_str)
718e3744 5481{
d62a17ae 5482 int ret;
5483 struct peer *peer;
5484 int direct = FILTER_IN;
718e3744 5485
d62a17ae 5486 peer = peer_and_group_lookup_vty(vty, ip_str);
5487 if (!peer)
5488 return CMD_WARNING_CONFIG_FAILED;
718e3744 5489
d62a17ae 5490 /* Check filter direction. */
5491 if (strncmp(direct_str, "i", 1) == 0)
5492 direct = FILTER_IN;
5493 else if (strncmp(direct_str, "o", 1) == 0)
5494 direct = FILTER_OUT;
718e3744 5495
d62a17ae 5496 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5497
d62a17ae 5498 return bgp_vty_return(vty, ret);
718e3744 5499}
5500
d62a17ae 5501static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5502 safi_t safi, const char *direct_str)
718e3744 5503{
d62a17ae 5504 int ret;
5505 struct peer *peer;
5506 int direct = FILTER_IN;
718e3744 5507
d62a17ae 5508 peer = peer_and_group_lookup_vty(vty, ip_str);
5509 if (!peer)
5510 return CMD_WARNING_CONFIG_FAILED;
718e3744 5511
d62a17ae 5512 /* Check filter direction. */
5513 if (strncmp(direct_str, "i", 1) == 0)
5514 direct = FILTER_IN;
5515 else if (strncmp(direct_str, "o", 1) == 0)
5516 direct = FILTER_OUT;
718e3744 5517
d62a17ae 5518 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5519
d62a17ae 5520 return bgp_vty_return(vty, ret);
718e3744 5521}
5522
5523DEFUN (neighbor_filter_list,
5524 neighbor_filter_list_cmd,
9ccf14f7 5525 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5526 NEIGHBOR_STR
5527 NEIGHBOR_ADDR_STR2
5528 "Establish BGP filters\n"
5529 "AS path access-list name\n"
5530 "Filter incoming routes\n"
5531 "Filter outgoing routes\n")
5532{
d62a17ae 5533 int idx_peer = 1;
5534 int idx_word = 3;
5535 int idx_in_out = 4;
5536 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5537 bgp_node_safi(vty), argv[idx_word]->arg,
5538 argv[idx_in_out]->arg);
718e3744 5539}
5540
d62a17ae 5541ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5542 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5543 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5544 "Establish BGP filters\n"
5545 "AS path access-list name\n"
5546 "Filter incoming routes\n"
5547 "Filter outgoing routes\n")
596c17ba 5548
718e3744 5549DEFUN (no_neighbor_filter_list,
5550 no_neighbor_filter_list_cmd,
9ccf14f7 5551 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5552 NO_STR
5553 NEIGHBOR_STR
5554 NEIGHBOR_ADDR_STR2
5555 "Establish BGP filters\n"
5556 "AS path access-list name\n"
5557 "Filter incoming routes\n"
5558 "Filter outgoing routes\n")
5559{
d62a17ae 5560 int idx_peer = 2;
5561 int idx_in_out = 5;
5562 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5563 bgp_node_afi(vty), bgp_node_safi(vty),
5564 argv[idx_in_out]->arg);
718e3744 5565}
6b0655a2 5566
d62a17ae 5567ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5568 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5569 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5570 "Establish BGP filters\n"
5571 "AS path access-list name\n"
5572 "Filter incoming routes\n"
5573 "Filter outgoing routes\n")
596c17ba 5574
718e3744 5575/* Set route-map to the peer. */
d62a17ae 5576static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5577 afi_t afi, safi_t safi, const char *name_str,
5578 const char *direct_str)
718e3744 5579{
d62a17ae 5580 int ret;
5581 struct peer *peer;
5582 int direct = RMAP_IN;
718e3744 5583
d62a17ae 5584 peer = peer_and_group_lookup_vty(vty, ip_str);
5585 if (!peer)
5586 return CMD_WARNING_CONFIG_FAILED;
718e3744 5587
d62a17ae 5588 /* Check filter direction. */
5589 if (strncmp(direct_str, "in", 2) == 0)
5590 direct = RMAP_IN;
5591 else if (strncmp(direct_str, "o", 1) == 0)
5592 direct = RMAP_OUT;
718e3744 5593
d62a17ae 5594 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5595
d62a17ae 5596 return bgp_vty_return(vty, ret);
718e3744 5597}
5598
d62a17ae 5599static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5600 afi_t afi, safi_t safi,
5601 const char *direct_str)
718e3744 5602{
d62a17ae 5603 int ret;
5604 struct peer *peer;
5605 int direct = RMAP_IN;
718e3744 5606
d62a17ae 5607 peer = peer_and_group_lookup_vty(vty, ip_str);
5608 if (!peer)
5609 return CMD_WARNING_CONFIG_FAILED;
718e3744 5610
d62a17ae 5611 /* Check filter direction. */
5612 if (strncmp(direct_str, "in", 2) == 0)
5613 direct = RMAP_IN;
5614 else if (strncmp(direct_str, "o", 1) == 0)
5615 direct = RMAP_OUT;
718e3744 5616
d62a17ae 5617 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5618
d62a17ae 5619 return bgp_vty_return(vty, ret);
718e3744 5620}
5621
5622DEFUN (neighbor_route_map,
5623 neighbor_route_map_cmd,
9ccf14f7 5624 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5625 NEIGHBOR_STR
5626 NEIGHBOR_ADDR_STR2
5627 "Apply route map to neighbor\n"
5628 "Name of route map\n"
5629 "Apply map to incoming routes\n"
2a3d5731 5630 "Apply map to outbound routes\n")
718e3744 5631{
d62a17ae 5632 int idx_peer = 1;
5633 int idx_word = 3;
5634 int idx_in_out = 4;
5635 return peer_route_map_set_vty(
5636 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5637 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5638}
5639
d62a17ae 5640ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5641 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5642 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5643 "Apply route map to neighbor\n"
5644 "Name of route map\n"
5645 "Apply map to incoming routes\n"
5646 "Apply map to outbound routes\n")
596c17ba 5647
718e3744 5648DEFUN (no_neighbor_route_map,
5649 no_neighbor_route_map_cmd,
9ccf14f7 5650 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5651 NO_STR
5652 NEIGHBOR_STR
5653 NEIGHBOR_ADDR_STR2
5654 "Apply route map to neighbor\n"
5655 "Name of route map\n"
5656 "Apply map to incoming routes\n"
2a3d5731 5657 "Apply map to outbound routes\n")
718e3744 5658{
d62a17ae 5659 int idx_peer = 2;
5660 int idx_in_out = 5;
5661 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5662 bgp_node_afi(vty), bgp_node_safi(vty),
5663 argv[idx_in_out]->arg);
718e3744 5664}
6b0655a2 5665
d62a17ae 5666ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5667 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5668 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5669 "Apply route map to neighbor\n"
5670 "Name of route map\n"
5671 "Apply map to incoming routes\n"
5672 "Apply map to outbound routes\n")
596c17ba 5673
718e3744 5674/* Set unsuppress-map to the peer. */
d62a17ae 5675static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5676 afi_t afi, safi_t safi,
5677 const char *name_str)
718e3744 5678{
d62a17ae 5679 int ret;
5680 struct peer *peer;
718e3744 5681
d62a17ae 5682 peer = peer_and_group_lookup_vty(vty, ip_str);
5683 if (!peer)
5684 return CMD_WARNING_CONFIG_FAILED;
718e3744 5685
d62a17ae 5686 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5687
d62a17ae 5688 return bgp_vty_return(vty, ret);
718e3744 5689}
5690
5691/* Unset route-map from the peer. */
d62a17ae 5692static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5693 afi_t afi, safi_t safi)
718e3744 5694{
d62a17ae 5695 int ret;
5696 struct peer *peer;
718e3744 5697
d62a17ae 5698 peer = peer_and_group_lookup_vty(vty, ip_str);
5699 if (!peer)
5700 return CMD_WARNING_CONFIG_FAILED;
718e3744 5701
d62a17ae 5702 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5703
d62a17ae 5704 return bgp_vty_return(vty, ret);
718e3744 5705}
5706
5707DEFUN (neighbor_unsuppress_map,
5708 neighbor_unsuppress_map_cmd,
9ccf14f7 5709 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5710 NEIGHBOR_STR
5711 NEIGHBOR_ADDR_STR2
5712 "Route-map to selectively unsuppress suppressed routes\n"
5713 "Name of route map\n")
5714{
d62a17ae 5715 int idx_peer = 1;
5716 int idx_word = 3;
5717 return peer_unsuppress_map_set_vty(
5718 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5719 argv[idx_word]->arg);
718e3744 5720}
5721
d62a17ae 5722ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5723 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5724 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5725 "Route-map to selectively unsuppress suppressed routes\n"
5726 "Name of route map\n")
596c17ba 5727
718e3744 5728DEFUN (no_neighbor_unsuppress_map,
5729 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5730 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5731 NO_STR
5732 NEIGHBOR_STR
5733 NEIGHBOR_ADDR_STR2
5734 "Route-map to selectively unsuppress suppressed routes\n"
5735 "Name of route map\n")
5736{
d62a17ae 5737 int idx_peer = 2;
5738 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5739 bgp_node_afi(vty),
5740 bgp_node_safi(vty));
718e3744 5741}
6b0655a2 5742
d62a17ae 5743ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5744 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5745 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5746 "Route-map to selectively unsuppress suppressed routes\n"
5747 "Name of route map\n")
596c17ba 5748
d62a17ae 5749static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5750 afi_t afi, safi_t safi,
5751 const char *num_str,
5752 const char *threshold_str, int warning,
5753 const char *restart_str)
718e3744 5754{
d62a17ae 5755 int ret;
5756 struct peer *peer;
d7c0a89a
QY
5757 uint32_t max;
5758 uint8_t threshold;
5759 uint16_t restart;
718e3744 5760
d62a17ae 5761 peer = peer_and_group_lookup_vty(vty, ip_str);
5762 if (!peer)
5763 return CMD_WARNING_CONFIG_FAILED;
718e3744 5764
d62a17ae 5765 max = strtoul(num_str, NULL, 10);
5766 if (threshold_str)
5767 threshold = atoi(threshold_str);
5768 else
5769 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5770
d62a17ae 5771 if (restart_str)
5772 restart = atoi(restart_str);
5773 else
5774 restart = 0;
0a486e5f 5775
d62a17ae 5776 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5777 restart);
718e3744 5778
d62a17ae 5779 return bgp_vty_return(vty, ret);
718e3744 5780}
5781
d62a17ae 5782static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5783 afi_t afi, safi_t safi)
718e3744 5784{
d62a17ae 5785 int ret;
5786 struct peer *peer;
718e3744 5787
d62a17ae 5788 peer = peer_and_group_lookup_vty(vty, ip_str);
5789 if (!peer)
5790 return CMD_WARNING_CONFIG_FAILED;
718e3744 5791
d62a17ae 5792 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5793
d62a17ae 5794 return bgp_vty_return(vty, ret);
718e3744 5795}
5796
5797/* Maximum number of prefix configuration. prefix count is different
5798 for each peer configuration. So this configuration can be set for
5799 each peer configuration. */
5800DEFUN (neighbor_maximum_prefix,
5801 neighbor_maximum_prefix_cmd,
9ccf14f7 5802 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5803 NEIGHBOR_STR
5804 NEIGHBOR_ADDR_STR2
5805 "Maximum number of prefix accept from this peer\n"
5806 "maximum no. of prefix limit\n")
5807{
d62a17ae 5808 int idx_peer = 1;
5809 int idx_number = 3;
5810 return peer_maximum_prefix_set_vty(
5811 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5812 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5813}
5814
d62a17ae 5815ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5816 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5817 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5818 "Maximum number of prefix accept from this peer\n"
5819 "maximum no. of prefix limit\n")
596c17ba 5820
e0701b79 5821DEFUN (neighbor_maximum_prefix_threshold,
5822 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5823 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5824 NEIGHBOR_STR
5825 NEIGHBOR_ADDR_STR2
5826 "Maximum number of prefix accept from this peer\n"
5827 "maximum no. of prefix limit\n"
5828 "Threshold value (%) at which to generate a warning msg\n")
5829{
d62a17ae 5830 int idx_peer = 1;
5831 int idx_number = 3;
5832 int idx_number_2 = 4;
5833 return peer_maximum_prefix_set_vty(
5834 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5835 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5836}
e0701b79 5837
d62a17ae 5838ALIAS_HIDDEN(
5839 neighbor_maximum_prefix_threshold,
5840 neighbor_maximum_prefix_threshold_hidden_cmd,
5841 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5842 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5843 "Maximum number of prefix accept from this peer\n"
5844 "maximum no. of prefix limit\n"
5845 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5846
718e3744 5847DEFUN (neighbor_maximum_prefix_warning,
5848 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5849 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5850 NEIGHBOR_STR
5851 NEIGHBOR_ADDR_STR2
5852 "Maximum number of prefix accept from this peer\n"
5853 "maximum no. of prefix limit\n"
5854 "Only give warning message when limit is exceeded\n")
5855{
d62a17ae 5856 int idx_peer = 1;
5857 int idx_number = 3;
5858 return peer_maximum_prefix_set_vty(
5859 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5860 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5861}
5862
d62a17ae 5863ALIAS_HIDDEN(
5864 neighbor_maximum_prefix_warning,
5865 neighbor_maximum_prefix_warning_hidden_cmd,
5866 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5867 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5868 "Maximum number of prefix accept from this peer\n"
5869 "maximum no. of prefix limit\n"
5870 "Only give warning message when limit is exceeded\n")
596c17ba 5871
e0701b79 5872DEFUN (neighbor_maximum_prefix_threshold_warning,
5873 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5874 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5875 NEIGHBOR_STR
5876 NEIGHBOR_ADDR_STR2
5877 "Maximum number of prefix accept from this peer\n"
5878 "maximum no. of prefix limit\n"
5879 "Threshold value (%) at which to generate a warning msg\n"
5880 "Only give warning message when limit is exceeded\n")
5881{
d62a17ae 5882 int idx_peer = 1;
5883 int idx_number = 3;
5884 int idx_number_2 = 4;
5885 return peer_maximum_prefix_set_vty(
5886 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5887 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5888}
5889
d62a17ae 5890ALIAS_HIDDEN(
5891 neighbor_maximum_prefix_threshold_warning,
5892 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5893 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5894 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5895 "Maximum number of prefix accept from this peer\n"
5896 "maximum no. of prefix limit\n"
5897 "Threshold value (%) at which to generate a warning msg\n"
5898 "Only give warning message when limit is exceeded\n")
596c17ba 5899
0a486e5f 5900DEFUN (neighbor_maximum_prefix_restart,
5901 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5902 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5903 NEIGHBOR_STR
5904 NEIGHBOR_ADDR_STR2
5905 "Maximum number of prefix accept from this peer\n"
5906 "maximum no. of prefix limit\n"
5907 "Restart bgp connection after limit is exceeded\n"
efd7904e 5908 "Restart interval in minutes\n")
0a486e5f 5909{
d62a17ae 5910 int idx_peer = 1;
5911 int idx_number = 3;
5912 int idx_number_2 = 5;
5913 return peer_maximum_prefix_set_vty(
5914 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5915 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5916}
5917
d62a17ae 5918ALIAS_HIDDEN(
5919 neighbor_maximum_prefix_restart,
5920 neighbor_maximum_prefix_restart_hidden_cmd,
5921 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5922 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5923 "Maximum number of prefix accept from this peer\n"
5924 "maximum no. of prefix limit\n"
5925 "Restart bgp connection after limit is exceeded\n"
efd7904e 5926 "Restart interval in minutes\n")
596c17ba 5927
0a486e5f 5928DEFUN (neighbor_maximum_prefix_threshold_restart,
5929 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5930 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5931 NEIGHBOR_STR
5932 NEIGHBOR_ADDR_STR2
16cedbb0 5933 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5934 "maximum no. of prefix limit\n"
5935 "Threshold value (%) at which to generate a warning msg\n"
5936 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5937 "Restart interval in minutes\n")
0a486e5f 5938{
d62a17ae 5939 int idx_peer = 1;
5940 int idx_number = 3;
5941 int idx_number_2 = 4;
5942 int idx_number_3 = 6;
5943 return peer_maximum_prefix_set_vty(
5944 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5945 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5946 argv[idx_number_3]->arg);
5947}
5948
5949ALIAS_HIDDEN(
5950 neighbor_maximum_prefix_threshold_restart,
5951 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5952 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5953 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5954 "Maximum number of prefixes to accept from this peer\n"
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"
5958 "Restart interval in minutes\n")
596c17ba 5959
718e3744 5960DEFUN (no_neighbor_maximum_prefix,
5961 no_neighbor_maximum_prefix_cmd,
d04c479d 5962 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5963 NO_STR
5964 NEIGHBOR_STR
5965 NEIGHBOR_ADDR_STR2
16cedbb0 5966 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5967 "maximum no. of prefix limit\n"
5968 "Threshold value (%) at which to generate a warning msg\n"
5969 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5970 "Restart interval in minutes\n"
31500417 5971 "Only give warning message when limit is exceeded\n")
718e3744 5972{
d62a17ae 5973 int idx_peer = 2;
5974 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5975 bgp_node_afi(vty),
5976 bgp_node_safi(vty));
718e3744 5977}
e52702f2 5978
d62a17ae 5979ALIAS_HIDDEN(
5980 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5981 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5982 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5983 "Maximum number of prefixes to accept from this peer\n"
5984 "maximum no. of prefix limit\n"
5985 "Threshold value (%) at which to generate a warning msg\n"
5986 "Restart bgp connection after limit is exceeded\n"
5987 "Restart interval in minutes\n"
5988 "Only give warning message when limit is exceeded\n")
596c17ba 5989
718e3744 5990
718e3744 5991/* "neighbor allowas-in" */
5992DEFUN (neighbor_allowas_in,
5993 neighbor_allowas_in_cmd,
fd8503f5 5994 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5995 NEIGHBOR_STR
5996 NEIGHBOR_ADDR_STR2
31500417 5997 "Accept as-path with my AS present in it\n"
4e69658c 5998 "Number of occurrences of AS number\n"
fd8503f5 5999 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6000{
d62a17ae 6001 int idx_peer = 1;
6002 int idx_number_origin = 3;
6003 int ret;
6004 int origin = 0;
6005 struct peer *peer;
6006 int allow_num = 0;
6007
6008 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6009 if (!peer)
6010 return CMD_WARNING_CONFIG_FAILED;
6011
6012 if (argc <= idx_number_origin)
6013 allow_num = 3;
6014 else {
6015 if (argv[idx_number_origin]->type == WORD_TKN)
6016 origin = 1;
6017 else
6018 allow_num = atoi(argv[idx_number_origin]->arg);
6019 }
6020
6021 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6022 allow_num, origin);
6023
6024 return bgp_vty_return(vty, ret);
6025}
6026
6027ALIAS_HIDDEN(
6028 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6029 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6030 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6031 "Accept as-path with my AS present in it\n"
4e69658c 6032 "Number of occurrences of AS number\n"
d62a17ae 6033 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6034
718e3744 6035DEFUN (no_neighbor_allowas_in,
6036 no_neighbor_allowas_in_cmd,
fd8503f5 6037 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6038 NO_STR
6039 NEIGHBOR_STR
6040 NEIGHBOR_ADDR_STR2
8334fd5a 6041 "allow local ASN appears in aspath attribute\n"
4e69658c 6042 "Number of occurrences of AS number\n"
fd8503f5 6043 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6044{
d62a17ae 6045 int idx_peer = 2;
6046 int ret;
6047 struct peer *peer;
718e3744 6048
d62a17ae 6049 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6050 if (!peer)
6051 return CMD_WARNING_CONFIG_FAILED;
718e3744 6052
d62a17ae 6053 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6054 bgp_node_safi(vty));
718e3744 6055
d62a17ae 6056 return bgp_vty_return(vty, ret);
718e3744 6057}
6b0655a2 6058
d62a17ae 6059ALIAS_HIDDEN(
6060 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6061 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6062 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6063 "allow local ASN appears in aspath attribute\n"
4e69658c 6064 "Number of occurrences of AS number\n"
d62a17ae 6065 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6066
fa411a21
NH
6067DEFUN (neighbor_ttl_security,
6068 neighbor_ttl_security_cmd,
7ebe625c 6069 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6070 NEIGHBOR_STR
7ebe625c 6071 NEIGHBOR_ADDR_STR2
16cedbb0 6072 "BGP ttl-security parameters\n"
d7fa34c1
QY
6073 "Specify the maximum number of hops to the BGP peer\n"
6074 "Number of hops to BGP peer\n")
fa411a21 6075{
d62a17ae 6076 int idx_peer = 1;
6077 int idx_number = 4;
6078 struct peer *peer;
6079 int gtsm_hops;
6080
6081 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6082 if (!peer)
6083 return CMD_WARNING_CONFIG_FAILED;
6084
6085 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6086
7ebe625c
QY
6087 /*
6088 * If 'neighbor swpX', then this is for directly connected peers,
6089 * we should not accept a ttl-security hops value greater than 1.
6090 */
6091 if (peer->conf_if && (gtsm_hops > 1)) {
6092 vty_out(vty,
6093 "%s is directly connected peer, hops cannot exceed 1\n",
6094 argv[idx_peer]->arg);
6095 return CMD_WARNING_CONFIG_FAILED;
6096 }
6097
d62a17ae 6098 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6099}
6100
6101DEFUN (no_neighbor_ttl_security,
6102 no_neighbor_ttl_security_cmd,
7ebe625c 6103 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6104 NO_STR
6105 NEIGHBOR_STR
7ebe625c 6106 NEIGHBOR_ADDR_STR2
16cedbb0 6107 "BGP ttl-security parameters\n"
3a2d747c
QY
6108 "Specify the maximum number of hops to the BGP peer\n"
6109 "Number of hops to BGP peer\n")
fa411a21 6110{
d62a17ae 6111 int idx_peer = 2;
6112 struct peer *peer;
fa411a21 6113
d62a17ae 6114 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6115 if (!peer)
6116 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6117
d62a17ae 6118 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6119}
6b0655a2 6120
adbac85e
DW
6121DEFUN (neighbor_addpath_tx_all_paths,
6122 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6123 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6124 NEIGHBOR_STR
6125 NEIGHBOR_ADDR_STR2
6126 "Use addpath to advertise all paths to a neighbor\n")
6127{
d62a17ae 6128 int idx_peer = 1;
6129 struct peer *peer;
adbac85e 6130
d62a17ae 6131 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6132 if (!peer)
6133 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6134
d62a17ae 6135 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6136 bgp_node_safi(vty),
6137 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6138}
6139
d62a17ae 6140ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6141 neighbor_addpath_tx_all_paths_hidden_cmd,
6142 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6143 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6144 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6145
adbac85e
DW
6146DEFUN (no_neighbor_addpath_tx_all_paths,
6147 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6148 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6149 NO_STR
6150 NEIGHBOR_STR
6151 NEIGHBOR_ADDR_STR2
6152 "Use addpath to advertise all paths to a neighbor\n")
6153{
d62a17ae 6154 int idx_peer = 2;
6155 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6156 bgp_node_afi(vty), bgp_node_safi(vty),
6157 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6158}
6159
d62a17ae 6160ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6161 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6162 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6163 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6164 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6165
06370dac
DW
6166DEFUN (neighbor_addpath_tx_bestpath_per_as,
6167 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6168 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6169 NEIGHBOR_STR
6170 NEIGHBOR_ADDR_STR2
6171 "Use addpath to advertise the bestpath per each neighboring AS\n")
6172{
d62a17ae 6173 int idx_peer = 1;
6174 struct peer *peer;
06370dac 6175
d62a17ae 6176 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6177 if (!peer)
6178 return CMD_WARNING_CONFIG_FAILED;
06370dac 6179
d62a17ae 6180 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6181 bgp_node_safi(vty),
6182 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6183}
6184
d62a17ae 6185ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6186 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6187 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6188 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6189 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6190
06370dac
DW
6191DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6192 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6193 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6194 NO_STR
6195 NEIGHBOR_STR
6196 NEIGHBOR_ADDR_STR2
6197 "Use addpath to advertise the bestpath per each neighboring AS\n")
6198{
d62a17ae 6199 int idx_peer = 2;
6200 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6201 bgp_node_afi(vty), bgp_node_safi(vty),
6202 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6203}
6204
d62a17ae 6205ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6206 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6207 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6208 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6209 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6210
b9c7bc5a
PZ
6211static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6212 struct ecommunity **list)
ddb5b488 6213{
b9c7bc5a
PZ
6214 struct ecommunity *ecom = NULL;
6215 struct ecommunity *ecomadd;
ddb5b488 6216
b9c7bc5a 6217 for (; argc; --argc, ++argv) {
ddb5b488 6218
b9c7bc5a
PZ
6219 ecomadd = ecommunity_str2com(argv[0]->arg,
6220 ECOMMUNITY_ROUTE_TARGET, 0);
6221 if (!ecomadd) {
6222 vty_out(vty, "Malformed community-list value\n");
6223 if (ecom)
6224 ecommunity_free(&ecom);
6225 return CMD_WARNING_CONFIG_FAILED;
6226 }
ddb5b488 6227
b9c7bc5a
PZ
6228 if (ecom) {
6229 ecommunity_merge(ecom, ecomadd);
6230 ecommunity_free(&ecomadd);
6231 } else {
6232 ecom = ecomadd;
6233 }
6234 }
6235
6236 if (*list) {
6237 ecommunity_free(&*list);
ddb5b488 6238 }
b9c7bc5a
PZ
6239 *list = ecom;
6240
6241 return CMD_SUCCESS;
ddb5b488
PZ
6242}
6243
0ca70ba5
DS
6244/*
6245 * v2vimport is true if we are handling a `import vrf ...` command
6246 */
6247static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6248{
0ca70ba5
DS
6249 afi_t afi;
6250
ddb5b488 6251 switch (vty->node) {
b9c7bc5a 6252 case BGP_IPV4_NODE:
0ca70ba5
DS
6253 afi = AFI_IP;
6254 break;
b9c7bc5a 6255 case BGP_IPV6_NODE:
0ca70ba5
DS
6256 afi = AFI_IP6;
6257 break;
ddb5b488
PZ
6258 default:
6259 vty_out(vty,
b9c7bc5a 6260 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6261 return AFI_MAX;
ddb5b488 6262 }
69b07479 6263
0ca70ba5
DS
6264 if (!v2vimport) {
6265 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6266 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6267 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6268 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6269 vty_out(vty,
6270 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6271 return AFI_MAX;
6272 }
6273 } else {
6274 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6275 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6276 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6277 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6278 vty_out(vty,
6279 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6280 return AFI_MAX;
6281 }
6282 }
6283 return afi;
ddb5b488
PZ
6284}
6285
b9c7bc5a
PZ
6286DEFPY (af_rd_vpn_export,
6287 af_rd_vpn_export_cmd,
6288 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6289 NO_STR
ddb5b488 6290 "Specify route distinguisher\n"
b9c7bc5a
PZ
6291 "Between current address-family and vpn\n"
6292 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6293 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6294{
6295 VTY_DECLVAR_CONTEXT(bgp, bgp);
6296 struct prefix_rd prd;
6297 int ret;
ddb5b488 6298 afi_t afi;
b9c7bc5a
PZ
6299 int idx = 0;
6300 int yes = 1;
ddb5b488 6301
b9c7bc5a 6302 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6303 yes = 0;
b9c7bc5a
PZ
6304
6305 if (yes) {
6306 ret = str2prefix_rd(rd_str, &prd);
6307 if (!ret) {
6308 vty_out(vty, "%% Malformed rd\n");
6309 return CMD_WARNING_CONFIG_FAILED;
6310 }
ddb5b488
PZ
6311 }
6312
0ca70ba5 6313 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6314 if (afi == AFI_MAX)
6315 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6316
69b07479
DS
6317 /*
6318 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6319 */
6320 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6321 bgp_get_default(), bgp);
ddb5b488 6322
69b07479
DS
6323 if (yes) {
6324 bgp->vpn_policy[afi].tovpn_rd = prd;
6325 SET_FLAG(bgp->vpn_policy[afi].flags,
6326 BGP_VPN_POLICY_TOVPN_RD_SET);
6327 } else {
6328 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6329 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6330 }
6331
69b07479
DS
6332 /* post-change: re-export vpn routes */
6333 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6334 bgp_get_default(), bgp);
6335
ddb5b488
PZ
6336 return CMD_SUCCESS;
6337}
6338
b9c7bc5a
PZ
6339ALIAS (af_rd_vpn_export,
6340 af_no_rd_vpn_export_cmd,
6341 "no rd vpn export",
ddb5b488 6342 NO_STR
b9c7bc5a
PZ
6343 "Specify route distinguisher\n"
6344 "Between current address-family and vpn\n"
6345 "For routes leaked from current address-family to vpn\n")
ddb5b488 6346
b9c7bc5a
PZ
6347DEFPY (af_label_vpn_export,
6348 af_label_vpn_export_cmd,
e70e9f8e 6349 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6350 NO_STR
ddb5b488 6351 "label value for VRF\n"
b9c7bc5a
PZ
6352 "Between current address-family and vpn\n"
6353 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6354 "Label Value <0-1048575>\n"
6355 "Automatically assign a label\n")
ddb5b488
PZ
6356{
6357 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6358 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6359 afi_t afi;
b9c7bc5a
PZ
6360 int idx = 0;
6361 int yes = 1;
6362
6363 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6364 yes = 0;
ddb5b488 6365
21a16cc2
PZ
6366 /* If "no ...", squash trailing parameter */
6367 if (!yes)
6368 label_auto = NULL;
6369
e70e9f8e
PZ
6370 if (yes) {
6371 if (!label_auto)
6372 label = label_val; /* parser should force unsigned */
6373 }
ddb5b488 6374
0ca70ba5 6375 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6376 if (afi == AFI_MAX)
6377 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6378
e70e9f8e 6379
69b07479
DS
6380 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6381 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6382 /* no change */
6383 return CMD_SUCCESS;
e70e9f8e 6384
69b07479
DS
6385 /*
6386 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6387 */
6388 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6389 bgp_get_default(), bgp);
6390
6391 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6392 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6393
6394 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6395
6396 /*
6397 * label has previously been automatically
6398 * assigned by labelpool: release it
6399 *
6400 * NB if tovpn_label == MPLS_LABEL_NONE it
6401 * means the automatic assignment is in flight
6402 * and therefore the labelpool callback must
6403 * detect that the auto label is not needed.
6404 */
6405
6406 bgp_lp_release(LP_TYPE_VRF,
6407 &bgp->vpn_policy[afi],
6408 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6409 }
69b07479
DS
6410 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6411 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6412 }
ddb5b488 6413
69b07479
DS
6414 bgp->vpn_policy[afi].tovpn_label = label;
6415 if (label_auto) {
6416 SET_FLAG(bgp->vpn_policy[afi].flags,
6417 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6418 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6419 vpn_leak_label_callback);
ddb5b488
PZ
6420 }
6421
69b07479
DS
6422 /* post-change: re-export vpn routes */
6423 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6424 bgp_get_default(), bgp);
6425
ddb5b488
PZ
6426 return CMD_SUCCESS;
6427}
6428
b9c7bc5a
PZ
6429ALIAS (af_label_vpn_export,
6430 af_no_label_vpn_export_cmd,
6431 "no label vpn export",
6432 NO_STR
6433 "label value for VRF\n"
6434 "Between current address-family and vpn\n"
6435 "For routes leaked from current address-family to vpn\n")
ddb5b488 6436
b9c7bc5a
PZ
6437DEFPY (af_nexthop_vpn_export,
6438 af_nexthop_vpn_export_cmd,
6439 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6440 NO_STR
ddb5b488 6441 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6442 "Between current address-family and vpn\n"
6443 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6444 "IPv4 prefix\n"
6445 "IPv6 prefix\n")
6446{
6447 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6448 afi_t afi;
ddb5b488 6449 struct prefix p;
b9c7bc5a
PZ
6450 int idx = 0;
6451 int yes = 1;
ddb5b488 6452
b9c7bc5a 6453 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6454 yes = 0;
b9c7bc5a
PZ
6455
6456 if (yes) {
6457 if (!sockunion2hostprefix(nexthop_str, &p))
6458 return CMD_WARNING_CONFIG_FAILED;
6459 }
ddb5b488 6460
0ca70ba5 6461 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6462 if (afi == AFI_MAX)
6463 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6464
69b07479
DS
6465 /*
6466 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6467 */
6468 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6469 bgp_get_default(), bgp);
ddb5b488 6470
69b07479
DS
6471 if (yes) {
6472 bgp->vpn_policy[afi].tovpn_nexthop = p;
6473 SET_FLAG(bgp->vpn_policy[afi].flags,
6474 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6475 } else {
6476 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6477 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6478 }
6479
69b07479
DS
6480 /* post-change: re-export vpn routes */
6481 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6482 bgp_get_default(), bgp);
6483
ddb5b488
PZ
6484 return CMD_SUCCESS;
6485}
6486
b9c7bc5a
PZ
6487ALIAS (af_nexthop_vpn_export,
6488 af_no_nexthop_vpn_export_cmd,
6489 "no nexthop vpn export",
ddb5b488 6490 NO_STR
b9c7bc5a
PZ
6491 "Specify next hop to use for VRF advertised prefixes\n"
6492 "Between current address-family and vpn\n"
6493 "For routes leaked from current address-family to vpn\n")
ddb5b488 6494
b9c7bc5a 6495static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6496{
b9c7bc5a
PZ
6497 if (!strcmp(dstr, "import")) {
6498 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6499 } else if (!strcmp(dstr, "export")) {
6500 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6501 } else if (!strcmp(dstr, "both")) {
6502 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6503 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6504 } else {
6505 vty_out(vty, "%% direction parse error\n");
6506 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6507 }
ddb5b488
PZ
6508 return CMD_SUCCESS;
6509}
6510
b9c7bc5a
PZ
6511DEFPY (af_rt_vpn_imexport,
6512 af_rt_vpn_imexport_cmd,
6513 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6514 NO_STR
6515 "Specify route target list\n"
ddb5b488 6516 "Specify route target list\n"
b9c7bc5a
PZ
6517 "Between current address-family and vpn\n"
6518 "For routes leaked from vpn to current address-family: match any\n"
6519 "For routes leaked from current address-family to vpn: set\n"
6520 "both import: match any and export: set\n"
ddb5b488
PZ
6521 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6522{
6523 VTY_DECLVAR_CONTEXT(bgp, bgp);
6524 int ret;
6525 struct ecommunity *ecom = NULL;
6526 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6527 vpn_policy_direction_t dir;
6528 afi_t afi;
6529 int idx = 0;
b9c7bc5a 6530 int yes = 1;
ddb5b488 6531
b9c7bc5a 6532 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6533 yes = 0;
b9c7bc5a 6534
0ca70ba5 6535 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6536 if (afi == AFI_MAX)
6537 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6538
b9c7bc5a 6539 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6540 if (ret != CMD_SUCCESS)
6541 return ret;
6542
b9c7bc5a
PZ
6543 if (yes) {
6544 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6545 vty_out(vty, "%% Missing RTLIST\n");
6546 return CMD_WARNING_CONFIG_FAILED;
6547 }
6548 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6549 if (ret != CMD_SUCCESS) {
6550 return ret;
6551 }
ddb5b488
PZ
6552 }
6553
69b07479
DS
6554 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6555 if (!dodir[dir])
ddb5b488 6556 continue;
ddb5b488 6557
69b07479 6558 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6559
69b07479
DS
6560 if (yes) {
6561 if (bgp->vpn_policy[afi].rtlist[dir])
6562 ecommunity_free(
6563 &bgp->vpn_policy[afi].rtlist[dir]);
6564 bgp->vpn_policy[afi].rtlist[dir] =
6565 ecommunity_dup(ecom);
6566 } else {
6567 if (bgp->vpn_policy[afi].rtlist[dir])
6568 ecommunity_free(
6569 &bgp->vpn_policy[afi].rtlist[dir]);
6570 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6571 }
69b07479
DS
6572
6573 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6574 }
69b07479 6575
d555f3e9
PZ
6576 if (ecom)
6577 ecommunity_free(&ecom);
ddb5b488
PZ
6578
6579 return CMD_SUCCESS;
6580}
6581
b9c7bc5a
PZ
6582ALIAS (af_rt_vpn_imexport,
6583 af_no_rt_vpn_imexport_cmd,
6584 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6585 NO_STR
6586 "Specify route target list\n"
b9c7bc5a
PZ
6587 "Specify route target list\n"
6588 "Between current address-family and vpn\n"
6589 "For routes leaked from vpn to current address-family\n"
6590 "For routes leaked from current address-family to vpn\n"
6591 "both import and export\n")
6592
6593DEFPY (af_route_map_vpn_imexport,
6594 af_route_map_vpn_imexport_cmd,
6595/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6596 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6597 NO_STR
ddb5b488 6598 "Specify route map\n"
b9c7bc5a
PZ
6599 "Between current address-family and vpn\n"
6600 "For routes leaked from vpn to current address-family\n"
6601 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6602 "name of route-map\n")
6603{
6604 VTY_DECLVAR_CONTEXT(bgp, bgp);
6605 int ret;
6606 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6607 vpn_policy_direction_t dir;
6608 afi_t afi;
ddb5b488 6609 int idx = 0;
b9c7bc5a 6610 int yes = 1;
ddb5b488 6611
b9c7bc5a 6612 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6613 yes = 0;
b9c7bc5a 6614
0ca70ba5 6615 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6616 if (afi == AFI_MAX)
6617 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6618
b9c7bc5a 6619 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6620 if (ret != CMD_SUCCESS)
6621 return ret;
6622
69b07479
DS
6623 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6624 if (!dodir[dir])
ddb5b488 6625 continue;
ddb5b488 6626
69b07479 6627 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6628
69b07479
DS
6629 if (yes) {
6630 if (bgp->vpn_policy[afi].rmap_name[dir])
6631 XFREE(MTYPE_ROUTE_MAP_NAME,
6632 bgp->vpn_policy[afi].rmap_name[dir]);
6633 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6634 MTYPE_ROUTE_MAP_NAME, rmap_str);
6635 bgp->vpn_policy[afi].rmap[dir] =
6636 route_map_lookup_by_name(rmap_str);
6637 if (!bgp->vpn_policy[afi].rmap[dir])
6638 return CMD_SUCCESS;
6639 } else {
6640 if (bgp->vpn_policy[afi].rmap_name[dir])
6641 XFREE(MTYPE_ROUTE_MAP_NAME,
6642 bgp->vpn_policy[afi].rmap_name[dir]);
6643 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6644 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6645 }
69b07479
DS
6646
6647 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6648 }
6649
6650 return CMD_SUCCESS;
6651}
6652
b9c7bc5a
PZ
6653ALIAS (af_route_map_vpn_imexport,
6654 af_no_route_map_vpn_imexport_cmd,
6655 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6656 NO_STR
6657 "Specify route map\n"
b9c7bc5a
PZ
6658 "Between current address-family and vpn\n"
6659 "For routes leaked from vpn to current address-family\n"
6660 "For routes leaked from current address-family to vpn\n")
6661
bb4f6190
DS
6662DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6663 "[no] import vrf route-map RMAP$rmap_str",
6664 NO_STR
6665 "Import routes from another VRF\n"
6666 "Vrf routes being filtered\n"
6667 "Specify route map\n"
6668 "name of route-map\n")
6669{
6670 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6671 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6672 afi_t afi;
6673 int idx = 0;
6674 int yes = 1;
6675 struct bgp *bgp_default;
6676
6677 if (argv_find(argv, argc, "no", &idx))
6678 yes = 0;
6679
0ca70ba5 6680 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6681 if (afi == AFI_MAX)
6682 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6683
6684 bgp_default = bgp_get_default();
6685 if (!bgp_default) {
6686 int32_t ret;
6687 as_t as = bgp->as;
6688
6689 /* Auto-create assuming the same AS */
6690 ret = bgp_get(&bgp_default, &as, NULL,
6691 BGP_INSTANCE_TYPE_DEFAULT);
6692
6693 if (ret) {
6694 vty_out(vty,
6695 "VRF default is not configured as a bgp instance\n");
6696 return CMD_WARNING;
6697 }
6698 }
6699
69b07479 6700 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6701
69b07479
DS
6702 if (yes) {
6703 if (bgp->vpn_policy[afi].rmap_name[dir])
6704 XFREE(MTYPE_ROUTE_MAP_NAME,
6705 bgp->vpn_policy[afi].rmap_name[dir]);
6706 bgp->vpn_policy[afi].rmap_name[dir] =
6707 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6708 bgp->vpn_policy[afi].rmap[dir] =
6709 route_map_lookup_by_name(rmap_str);
6710 if (!bgp->vpn_policy[afi].rmap[dir])
6711 return CMD_SUCCESS;
6712 } else {
6713 if (bgp->vpn_policy[afi].rmap_name[dir])
6714 XFREE(MTYPE_ROUTE_MAP_NAME,
6715 bgp->vpn_policy[afi].rmap_name[dir]);
6716 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6717 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6718 }
6719
69b07479
DS
6720 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6721
bb4f6190
DS
6722 return CMD_SUCCESS;
6723}
6724
6725ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6726 "no import vrf route-map",
6727 NO_STR
6728 "Import routes from another VRF\n"
6729 "Vrf routes being filtered\n"
6730 "Specify route map\n")
6731
12a844a5
DS
6732DEFPY (bgp_imexport_vrf,
6733 bgp_imexport_vrf_cmd,
6734 "[no] import vrf NAME$import_name",
6735 NO_STR
6736 "Import routes from another VRF\n"
6737 "VRF to import from\n"
6738 "The name of the VRF\n")
6739{
6740 VTY_DECLVAR_CONTEXT(bgp, bgp);
6741 struct listnode *node;
79ef8664
DS
6742 struct bgp *vrf_bgp, *bgp_default;
6743 int32_t ret = 0;
6744 as_t as = bgp->as;
12a844a5
DS
6745 bool remove = false;
6746 int32_t idx = 0;
6747 char *vname;
a8dadcf6 6748 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6749 safi_t safi;
6750 afi_t afi;
6751
867f0cca 6752 if (import_name == NULL) {
6753 vty_out(vty, "%% Missing import name\n");
6754 return CMD_WARNING;
6755 }
6756
12a844a5
DS
6757 if (argv_find(argv, argc, "no", &idx))
6758 remove = true;
6759
0ca70ba5
DS
6760 afi = vpn_policy_getafi(vty, bgp, true);
6761 if (afi == AFI_MAX)
6762 return CMD_WARNING_CONFIG_FAILED;
6763
12a844a5
DS
6764 safi = bgp_node_safi(vty);
6765
25679caa
DS
6766 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6767 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6768 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6769 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6770 remove ? "unimport" : "import", import_name);
6771 return CMD_WARNING;
6772 }
6773
79ef8664
DS
6774 bgp_default = bgp_get_default();
6775 if (!bgp_default) {
6776 /* Auto-create assuming the same AS */
6777 ret = bgp_get(&bgp_default, &as, NULL,
6778 BGP_INSTANCE_TYPE_DEFAULT);
6779
6780 if (ret) {
6781 vty_out(vty,
6782 "VRF default is not configured as a bgp instance\n");
6783 return CMD_WARNING;
6784 }
6785 }
6786
12a844a5
DS
6787 vrf_bgp = bgp_lookup_by_name(import_name);
6788 if (!vrf_bgp) {
79ef8664
DS
6789 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6790 vrf_bgp = bgp_default;
6791 else
0fb8d6e6
DS
6792 /* Auto-create assuming the same AS */
6793 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6794
6e2c7fe6 6795 if (ret) {
020a3f60
DS
6796 vty_out(vty,
6797 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6798 import_name);
6799 return CMD_WARNING;
6800 }
12a844a5
DS
6801 }
6802
12a844a5 6803 if (remove) {
44338987 6804 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6805 } else {
44338987 6806 /* Already importing from "import_vrf"? */
12a844a5
DS
6807 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6808 vname)) {
6809 if (strcmp(vname, import_name) == 0)
6810 return CMD_WARNING;
6811 }
6812
44338987 6813 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6814 }
6815
6816 return CMD_SUCCESS;
6817}
6818
b9c7bc5a
PZ
6819/* This command is valid only in a bgp vrf instance or the default instance */
6820DEFPY (bgp_imexport_vpn,
6821 bgp_imexport_vpn_cmd,
6822 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6823 NO_STR
6824 "Import routes to this address-family\n"
6825 "Export routes from this address-family\n"
6826 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6827{
6828 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6829 int previous_state;
ddb5b488 6830 afi_t afi;
b9c7bc5a 6831 safi_t safi;
ddb5b488 6832 int idx = 0;
b9c7bc5a
PZ
6833 int yes = 1;
6834 int flag;
6835 vpn_policy_direction_t dir;
ddb5b488 6836
b9c7bc5a 6837 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6838 yes = 0;
ddb5b488 6839
b9c7bc5a
PZ
6840 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6841 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6842
b9c7bc5a
PZ
6843 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6844 return CMD_WARNING_CONFIG_FAILED;
6845 }
ddb5b488 6846
b9c7bc5a
PZ
6847 afi = bgp_node_afi(vty);
6848 safi = bgp_node_safi(vty);
6849 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6850 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6851 return CMD_WARNING_CONFIG_FAILED;
6852 }
ddb5b488 6853
b9c7bc5a
PZ
6854 if (!strcmp(direction_str, "import")) {
6855 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6856 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6857 } else if (!strcmp(direction_str, "export")) {
6858 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6859 dir = BGP_VPN_POLICY_DIR_TOVPN;
6860 } else {
6861 vty_out(vty, "%% unknown direction %s\n", direction_str);
6862 return CMD_WARNING_CONFIG_FAILED;
6863 }
6864
6865 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 6866
b9c7bc5a
PZ
6867 if (yes) {
6868 SET_FLAG(bgp->af_flags[afi][safi], flag);
6869 if (!previous_state) {
6870 /* trigger export current vrf */
ddb5b488
PZ
6871 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6872 }
b9c7bc5a
PZ
6873 } else {
6874 if (previous_state) {
6875 /* trigger un-export current vrf */
6876 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6877 }
6878 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
6879 }
6880
6881 return CMD_SUCCESS;
6882}
6883
301ad80a
PG
6884DEFPY (af_routetarget_import,
6885 af_routetarget_import_cmd,
6886 "[no] <rt|route-target> redirect import RTLIST...",
6887 NO_STR
6888 "Specify route target list\n"
6889 "Specify route target list\n"
6890 "Flow-spec redirect type route target\n"
6891 "Import routes to this address-family\n"
6892 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6893{
6894 VTY_DECLVAR_CONTEXT(bgp, bgp);
6895 int ret;
6896 struct ecommunity *ecom = NULL;
301ad80a
PG
6897 afi_t afi;
6898 int idx = 0;
6899 int yes = 1;
6900
6901 if (argv_find(argv, argc, "no", &idx))
6902 yes = 0;
6903
0ca70ba5 6904 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6905 if (afi == AFI_MAX)
6906 return CMD_WARNING_CONFIG_FAILED;
6907
301ad80a
PG
6908 if (yes) {
6909 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6910 vty_out(vty, "%% Missing RTLIST\n");
6911 return CMD_WARNING_CONFIG_FAILED;
6912 }
6913 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6914 if (ret != CMD_SUCCESS)
6915 return ret;
6916 }
69b07479
DS
6917
6918 if (yes) {
6919 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6920 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6921 .import_redirect_rtlist);
69b07479
DS
6922 bgp->vpn_policy[afi].import_redirect_rtlist =
6923 ecommunity_dup(ecom);
6924 } else {
6925 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6926 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6927 .import_redirect_rtlist);
69b07479 6928 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 6929 }
69b07479 6930
301ad80a
PG
6931 if (ecom)
6932 ecommunity_free(&ecom);
6933
6934 return CMD_SUCCESS;
6935}
6936
505e5056 6937DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 6938 address_family_ipv4_safi_cmd,
6939 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6940 "Enter Address Family command mode\n"
6941 "Address Family\n"
6942 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6943{
f51bae9c 6944
d62a17ae 6945 if (argc == 3) {
2131d5cf 6946 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6947 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6948 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6949 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6950 && safi != SAFI_EVPN) {
31947174
MK
6951 vty_out(vty,
6952 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6953 return CMD_WARNING_CONFIG_FAILED;
6954 }
d62a17ae 6955 vty->node = bgp_node_type(AFI_IP, safi);
6956 } else
6957 vty->node = BGP_IPV4_NODE;
718e3744 6958
d62a17ae 6959 return CMD_SUCCESS;
718e3744 6960}
6961
505e5056 6962DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 6963 address_family_ipv6_safi_cmd,
6964 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6965 "Enter Address Family command mode\n"
6966 "Address Family\n"
6967 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6968{
d62a17ae 6969 if (argc == 3) {
2131d5cf 6970 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6971 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6972 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6973 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6974 && safi != SAFI_EVPN) {
31947174
MK
6975 vty_out(vty,
6976 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6977 return CMD_WARNING_CONFIG_FAILED;
6978 }
d62a17ae 6979 vty->node = bgp_node_type(AFI_IP6, safi);
6980 } else
6981 vty->node = BGP_IPV6_NODE;
25ffbdc1 6982
d62a17ae 6983 return CMD_SUCCESS;
25ffbdc1 6984}
718e3744 6985
d6902373 6986#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6987DEFUN_NOSH (address_family_vpnv4,
718e3744 6988 address_family_vpnv4_cmd,
8334fd5a 6989 "address-family vpnv4 [unicast]",
718e3744 6990 "Enter Address Family command mode\n"
8c3deaae 6991 "Address Family\n"
3a2d747c 6992 "Address Family modifier\n")
718e3744 6993{
d62a17ae 6994 vty->node = BGP_VPNV4_NODE;
6995 return CMD_SUCCESS;
718e3744 6996}
6997
505e5056 6998DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6999 address_family_vpnv6_cmd,
8334fd5a 7000 "address-family vpnv6 [unicast]",
8ecd3266 7001 "Enter Address Family command mode\n"
8c3deaae 7002 "Address Family\n"
3a2d747c 7003 "Address Family modifier\n")
8ecd3266 7004{
d62a17ae 7005 vty->node = BGP_VPNV6_NODE;
7006 return CMD_SUCCESS;
8ecd3266 7007}
c016b6c7 7008#endif
d6902373 7009
505e5056 7010DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7011 address_family_evpn_cmd,
7111c1a0 7012 "address-family l2vpn evpn",
4e0b7b6d 7013 "Enter Address Family command mode\n"
7111c1a0
QY
7014 "Address Family\n"
7015 "Address Family modifier\n")
4e0b7b6d 7016{
2131d5cf 7017 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7018 vty->node = BGP_EVPN_NODE;
7019 return CMD_SUCCESS;
4e0b7b6d
PG
7020}
7021
505e5056 7022DEFUN_NOSH (exit_address_family,
718e3744 7023 exit_address_family_cmd,
7024 "exit-address-family",
7025 "Exit from Address Family configuration mode\n")
7026{
d62a17ae 7027 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7028 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7029 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7030 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7031 || vty->node == BGP_EVPN_NODE
7032 || vty->node == BGP_FLOWSPECV4_NODE
7033 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7034 vty->node = BGP_NODE;
7035 return CMD_SUCCESS;
718e3744 7036}
6b0655a2 7037
8ad7271d 7038/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7039static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7040 const char *ip_str, afi_t afi, safi_t safi,
7041 struct prefix_rd *prd)
7042{
7043 int ret;
7044 struct prefix match;
7045 struct bgp_node *rn;
7046 struct bgp_node *rm;
7047 struct bgp *bgp;
7048 struct bgp_table *table;
7049 struct bgp_table *rib;
7050
7051 /* BGP structure lookup. */
7052 if (view_name) {
7053 bgp = bgp_lookup_by_name(view_name);
7054 if (bgp == NULL) {
7055 vty_out(vty, "%% Can't find BGP instance %s\n",
7056 view_name);
7057 return CMD_WARNING;
7058 }
7059 } else {
7060 bgp = bgp_get_default();
7061 if (bgp == NULL) {
7062 vty_out(vty, "%% No BGP process is configured\n");
7063 return CMD_WARNING;
7064 }
7065 }
7066
7067 /* Check IP address argument. */
7068 ret = str2prefix(ip_str, &match);
7069 if (!ret) {
7070 vty_out(vty, "%% address is malformed\n");
7071 return CMD_WARNING;
7072 }
7073
7074 match.family = afi2family(afi);
7075 rib = bgp->rib[afi][safi];
7076
7077 if (safi == SAFI_MPLS_VPN) {
7078 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7079 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7080 continue;
7081
7082 if ((table = rn->info) != NULL) {
7083 if ((rm = bgp_node_match(table, &match))
7084 != NULL) {
7085 if (rm->p.prefixlen
7086 == match.prefixlen) {
343cdb61 7087 SET_FLAG(rm->flags,
d62a17ae 7088 BGP_NODE_USER_CLEAR);
7089 bgp_process(bgp, rm, afi, safi);
7090 }
7091 bgp_unlock_node(rm);
7092 }
7093 }
7094 }
7095 } else {
7096 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7097 if (rn->p.prefixlen == match.prefixlen) {
7098 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7099 bgp_process(bgp, rn, afi, safi);
7100 }
7101 bgp_unlock_node(rn);
7102 }
7103 }
7104
7105 return CMD_SUCCESS;
8ad7271d
DS
7106}
7107
b09b5ae0 7108/* one clear bgp command to rule them all */
718e3744 7109DEFUN (clear_ip_bgp_all,
7110 clear_ip_bgp_all_cmd,
c1a44e43 7111 "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 7112 CLEAR_STR
7113 IP_STR
7114 BGP_STR
838758ac 7115 BGP_INSTANCE_HELP_STR
510afcd6
DS
7116 BGP_AFI_HELP_STR
7117 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
7118 "Clear all peers\n"
7119 "BGP neighbor address to clear\n"
a80beece 7120 "BGP IPv6 neighbor to clear\n"
838758ac 7121 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7122 "Clear peers with the AS number\n"
7123 "Clear all external peers\n"
718e3744 7124 "Clear all members of peer-group\n"
b09b5ae0 7125 "BGP peer-group name\n"
b09b5ae0
DW
7126 BGP_SOFT_STR
7127 BGP_SOFT_IN_STR
b09b5ae0
DW
7128 BGP_SOFT_OUT_STR
7129 BGP_SOFT_IN_STR
7130 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7131 BGP_SOFT_OUT_STR)
718e3744 7132{
d62a17ae 7133 char *vrf = NULL;
7134
7135 afi_t afi = AFI_IP6;
7136 safi_t safi = SAFI_UNICAST;
7137 enum clear_sort clr_sort = clear_peer;
7138 enum bgp_clear_type clr_type;
7139 char *clr_arg = NULL;
7140
7141 int idx = 0;
7142
7143 /* clear [ip] bgp */
7144 if (argv_find(argv, argc, "ip", &idx))
7145 afi = AFI_IP;
7146
7147 /* [<view|vrf> VIEWVRFNAME] */
7148 if (argv_find(argv, argc, "view", &idx)
7149 || argv_find(argv, argc, "vrf", &idx)) {
7150 vrf = argv[idx + 1]->arg;
7151 idx += 2;
7152 }
7153
7154 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7155 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7156 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7157
7158 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7159 if (argv_find(argv, argc, "*", &idx)) {
7160 clr_sort = clear_all;
7161 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7162 clr_sort = clear_peer;
7163 clr_arg = argv[idx]->arg;
7164 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7165 clr_sort = clear_peer;
7166 clr_arg = argv[idx]->arg;
7167 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7168 clr_sort = clear_group;
7169 idx++;
7170 clr_arg = argv[idx]->arg;
7171 } else if (argv_find(argv, argc, "WORD", &idx)) {
7172 clr_sort = clear_peer;
7173 clr_arg = argv[idx]->arg;
7174 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7175 clr_sort = clear_as;
7176 clr_arg = argv[idx]->arg;
7177 } else if (argv_find(argv, argc, "external", &idx)) {
7178 clr_sort = clear_external;
7179 }
7180
7181 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7182 if (argv_find(argv, argc, "soft", &idx)) {
7183 if (argv_find(argv, argc, "in", &idx)
7184 || argv_find(argv, argc, "out", &idx))
7185 clr_type = strmatch(argv[idx]->text, "in")
7186 ? BGP_CLEAR_SOFT_IN
7187 : BGP_CLEAR_SOFT_OUT;
7188 else
7189 clr_type = BGP_CLEAR_SOFT_BOTH;
7190 } else if (argv_find(argv, argc, "in", &idx)) {
7191 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7192 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7193 : BGP_CLEAR_SOFT_IN;
7194 } else if (argv_find(argv, argc, "out", &idx)) {
7195 clr_type = BGP_CLEAR_SOFT_OUT;
7196 } else
7197 clr_type = BGP_CLEAR_SOFT_NONE;
7198
7199 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7200}
01080f7c 7201
8ad7271d
DS
7202DEFUN (clear_ip_bgp_prefix,
7203 clear_ip_bgp_prefix_cmd,
18c57037 7204 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7205 CLEAR_STR
7206 IP_STR
7207 BGP_STR
838758ac 7208 BGP_INSTANCE_HELP_STR
8ad7271d 7209 "Clear bestpath and re-advertise\n"
0c7b1b01 7210 "IPv4 prefix\n")
8ad7271d 7211{
d62a17ae 7212 char *vrf = NULL;
7213 char *prefix = NULL;
8ad7271d 7214
d62a17ae 7215 int idx = 0;
01080f7c 7216
d62a17ae 7217 /* [<view|vrf> VIEWVRFNAME] */
1d35f218 7218 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
d62a17ae 7219 vrf = argv[idx]->arg;
0c7b1b01 7220
d62a17ae 7221 prefix = argv[argc - 1]->arg;
8ad7271d 7222
d62a17ae 7223 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7224}
8ad7271d 7225
b09b5ae0
DW
7226DEFUN (clear_bgp_ipv6_safi_prefix,
7227 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7228 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7229 CLEAR_STR
3a2d747c 7230 IP_STR
718e3744 7231 BGP_STR
8c3deaae 7232 "Address Family\n"
46f296b4 7233 BGP_SAFI_HELP_STR
b09b5ae0 7234 "Clear bestpath and re-advertise\n"
0c7b1b01 7235 "IPv6 prefix\n")
718e3744 7236{
9b475e76
PG
7237 int idx_safi = 0;
7238 int idx_ipv6_prefix = 0;
7239 safi_t safi = SAFI_UNICAST;
7240 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7241 argv[idx_ipv6_prefix]->arg : NULL;
7242
7243 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7244 return bgp_clear_prefix(
9b475e76
PG
7245 vty, NULL, prefix, AFI_IP6,
7246 safi, NULL);
838758ac 7247}
01080f7c 7248
b09b5ae0
DW
7249DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7250 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7251 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7252 CLEAR_STR
3a2d747c 7253 IP_STR
718e3744 7254 BGP_STR
838758ac 7255 BGP_INSTANCE_HELP_STR
8c3deaae 7256 "Address Family\n"
46f296b4 7257 BGP_SAFI_HELP_STR
b09b5ae0 7258 "Clear bestpath and re-advertise\n"
0c7b1b01 7259 "IPv6 prefix\n")
718e3744 7260{
d62a17ae 7261 int idx_word = 3;
9b475e76
PG
7262 int idx_safi = 0;
7263 int idx_ipv6_prefix = 0;
7264 safi_t safi = SAFI_UNICAST;
7265 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7266 argv[idx_ipv6_prefix]->arg : NULL;
7267 /* [<view|vrf> VIEWVRFNAME] */
7268 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7269 argv[idx_word]->arg : NULL;
7270
7271 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7272
d62a17ae 7273 return bgp_clear_prefix(
9b475e76
PG
7274 vty, vrfview, prefix,
7275 AFI_IP6, safi, NULL);
718e3744 7276}
7277
b09b5ae0
DW
7278DEFUN (show_bgp_views,
7279 show_bgp_views_cmd,
d6e3c605 7280 "show [ip] bgp views",
b09b5ae0 7281 SHOW_STR
d6e3c605 7282 IP_STR
01080f7c 7283 BGP_STR
b09b5ae0 7284 "Show the defined BGP views\n")
01080f7c 7285{
d62a17ae 7286 struct list *inst = bm->bgp;
7287 struct listnode *node;
7288 struct bgp *bgp;
01080f7c 7289
d62a17ae 7290 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7291 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7292 return CMD_WARNING;
7293 }
e52702f2 7294
d62a17ae 7295 vty_out(vty, "Defined BGP views:\n");
7296 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7297 /* Skip VRFs. */
7298 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7299 continue;
7300 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7301 bgp->as);
7302 }
e52702f2 7303
d62a17ae 7304 return CMD_SUCCESS;
e0081f70
ML
7305}
7306
8386ac43 7307DEFUN (show_bgp_vrfs,
7308 show_bgp_vrfs_cmd,
d6e3c605 7309 "show [ip] bgp vrfs [json]",
8386ac43 7310 SHOW_STR
d6e3c605 7311 IP_STR
8386ac43 7312 BGP_STR
7313 "Show BGP VRFs\n"
9973d184 7314 JSON_STR)
8386ac43 7315{
fe1dc5a3 7316 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7317 struct list *inst = bm->bgp;
7318 struct listnode *node;
7319 struct bgp *bgp;
d7c0a89a 7320 uint8_t uj = use_json(argc, argv);
d62a17ae 7321 json_object *json = NULL;
7322 json_object *json_vrfs = NULL;
7323 int count = 0;
d62a17ae 7324
7325 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7326 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7327 return CMD_WARNING;
7328 }
7329
7330 if (uj) {
7331 json = json_object_new_object();
7332 json_vrfs = json_object_new_object();
7333 }
7334
7335 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7336 const char *name, *type;
7337 struct peer *peer;
7338 struct listnode *node, *nnode;
7339 int peers_cfg, peers_estb;
7340 json_object *json_vrf = NULL;
d62a17ae 7341
7342 /* Skip Views. */
7343 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7344 continue;
7345
7346 count++;
7347 if (!uj && count == 1)
fe1dc5a3
MK
7348 vty_out(vty,
7349 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7350 "Type", "Id", "routerId", "#PeersVfg",
7351 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7352
7353 peers_cfg = peers_estb = 0;
7354 if (uj)
7355 json_vrf = json_object_new_object();
7356
7357
7358 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7359 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7360 continue;
7361 peers_cfg++;
7362 if (peer->status == Established)
7363 peers_estb++;
7364 }
7365
7366 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7367 name = "Default";
7368 type = "DFLT";
7369 } else {
7370 name = bgp->name;
7371 type = "VRF";
7372 }
7373
a8bf7d9c 7374
d62a17ae 7375 if (uj) {
a4d82a8a
PZ
7376 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7377 ? -1
7378 : (int64_t)bgp->vrf_id;
d62a17ae 7379 json_object_string_add(json_vrf, "type", type);
7380 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7381 json_object_string_add(json_vrf, "routerId",
7382 inet_ntoa(bgp->router_id));
7383 json_object_int_add(json_vrf, "numConfiguredPeers",
7384 peers_cfg);
7385 json_object_int_add(json_vrf, "numEstablishedPeers",
7386 peers_estb);
7387
fe1dc5a3 7388 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7389 json_object_string_add(
7390 json_vrf, "rmac",
7391 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7392 json_object_object_add(json_vrfs, name, json_vrf);
7393 } else
fe1dc5a3
MK
7394 vty_out(vty,
7395 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7396 type,
7397 bgp->vrf_id == VRF_UNKNOWN ? -1
7398 : (int)bgp->vrf_id,
7399 inet_ntoa(bgp->router_id), peers_cfg,
7400 peers_estb, name, bgp->l3vni,
fe1dc5a3 7401 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7402 }
7403
7404 if (uj) {
7405 json_object_object_add(json, "vrfs", json_vrfs);
7406
7407 json_object_int_add(json, "totalVrfs", count);
7408
996c9314
LB
7409 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7410 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7411 json_object_free(json);
7412 } else {
7413 if (count)
7414 vty_out(vty,
7415 "\nTotal number of VRFs (including default): %d\n",
7416 count);
7417 }
7418
7419 return CMD_SUCCESS;
8386ac43 7420}
7421
acf71666
MK
7422static void show_address_entry(struct hash_backet *backet, void *args)
7423{
60466a63
QY
7424 struct vty *vty = (struct vty *)args;
7425 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 7426
60466a63 7427 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
7428 addr->refcnt);
7429}
7430
7431static void show_tip_entry(struct hash_backet *backet, void *args)
7432{
0291c246 7433 struct vty *vty = (struct vty *)args;
60466a63 7434 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7435
60466a63 7436 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7437 tip->refcnt);
7438}
7439
7440static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7441{
7442 vty_out(vty, "self nexthop database:\n");
7443 hash_iterate(bgp->address_hash,
7444 (void (*)(struct hash_backet *, void *))show_address_entry,
7445 vty);
7446
7447 vty_out(vty, "Tunnel-ip database:\n");
7448 hash_iterate(bgp->tip_hash,
7449 (void (*)(struct hash_backet *, void *))show_tip_entry,
7450 vty);
7451}
7452
15c81ca4
DS
7453DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7454 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7455 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7456 "martian next-hops\n"
7457 "martian next-hop database\n")
acf71666 7458{
0291c246 7459 struct bgp *bgp = NULL;
15c81ca4
DS
7460 int idx = 0;
7461
7462 if (argv_find(argv, argc, "view", &idx)
7463 || argv_find(argv, argc, "vrf", &idx))
7464 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7465 else
7466 bgp = bgp_get_default();
acf71666 7467
acf71666
MK
7468 if (!bgp) {
7469 vty_out(vty, "%% No BGP process is configured\n");
7470 return CMD_WARNING;
7471 }
7472 bgp_show_martian_nexthops(vty, bgp);
7473
7474 return CMD_SUCCESS;
7475}
7476
f412b39a 7477DEFUN (show_bgp_memory,
4bf6a362 7478 show_bgp_memory_cmd,
7fa12b13 7479 "show [ip] bgp memory",
4bf6a362 7480 SHOW_STR
3a2d747c 7481 IP_STR
4bf6a362
PJ
7482 BGP_STR
7483 "Global BGP memory statistics\n")
7484{
d62a17ae 7485 char memstrbuf[MTYPE_MEMSTR_LEN];
7486 unsigned long count;
7487
7488 /* RIB related usage stats */
7489 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7490 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7491 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7492 count * sizeof(struct bgp_node)));
7493
7494 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7495 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7496 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7497 count * sizeof(struct bgp_info)));
7498 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7499 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7500 count,
7501 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7502 count * sizeof(struct bgp_info_extra)));
7503
7504 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7505 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7506 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7507 count * sizeof(struct bgp_static)));
7508
7509 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7510 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7511 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7512 count * sizeof(struct bpacket)));
7513
7514 /* Adj-In/Out */
7515 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7516 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7517 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7518 count * sizeof(struct bgp_adj_in)));
7519 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7520 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7521 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7522 count * sizeof(struct bgp_adj_out)));
7523
7524 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7525 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7526 count,
7527 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7528 count * sizeof(struct bgp_nexthop_cache)));
7529
7530 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7531 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7532 count,
7533 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7534 count * sizeof(struct bgp_damp_info)));
7535
7536 /* Attributes */
7537 count = attr_count();
7538 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7539 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7540 count * sizeof(struct attr)));
7541
7542 if ((count = attr_unknown_count()))
7543 vty_out(vty, "%ld unknown attributes\n", count);
7544
7545 /* AS_PATH attributes */
7546 count = aspath_count();
7547 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7548 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7549 count * sizeof(struct aspath)));
7550
7551 count = mtype_stats_alloc(MTYPE_AS_SEG);
7552 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7553 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7554 count * sizeof(struct assegment)));
7555
7556 /* Other attributes */
7557 if ((count = community_count()))
7558 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7559 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7560 count * sizeof(struct community)));
d62a17ae 7561 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7562 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7563 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7564 count * sizeof(struct ecommunity)));
d62a17ae 7565 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7566 vty_out(vty,
7567 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7568 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7569 count * sizeof(struct lcommunity)));
d62a17ae 7570
7571 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7572 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7573 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7574 count * sizeof(struct cluster_list)));
7575
7576 /* Peer related usage */
7577 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7578 vty_out(vty, "%ld peers, using %s of memory\n", count,
7579 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7580 count * sizeof(struct peer)));
7581
7582 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7583 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7584 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7585 count * sizeof(struct peer_group)));
7586
7587 /* Other */
7588 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7589 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7590 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7591 count * sizeof(struct hash)));
7592 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7593 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7594 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7595 count * sizeof(struct hash_backet)));
7596 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7597 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7598 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7599 count * sizeof(regex_t)));
d62a17ae 7600 return CMD_SUCCESS;
4bf6a362 7601}
fee0f4c6 7602
57a9c8a8
DS
7603static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7604{
7605 json_object *bestpath = json_object_new_object();
7606
7607 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7608 json_object_string_add(bestpath, "asPath", "ignore");
7609
7610 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7611 json_object_string_add(bestpath, "asPath", "confed");
7612
7613 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7614 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7615 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7616 "as-set");
7617 else
a4d82a8a 7618 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7619 "true");
7620 } else
a4d82a8a 7621 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7622
7623 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7624 json_object_string_add(bestpath, "compareRouterId", "true");
7625 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7626 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7627 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7628 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7629 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7630 json_object_string_add(bestpath, "med",
7631 "missing-as-worst");
7632 else
7633 json_object_string_add(bestpath, "med", "true");
7634 }
7635
7636 json_object_object_add(json, "bestPath", bestpath);
7637}
7638
718e3744 7639/* Show BGP peer's summary information. */
d62a17ae 7640static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
d7c0a89a 7641 uint8_t use_json, json_object *json)
d62a17ae 7642{
7643 struct peer *peer;
7644 struct listnode *node, *nnode;
7645 unsigned int count = 0, dn_count = 0;
7646 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7647 char neighbor_buf[VTY_BUFSIZ];
7648 int neighbor_col_default_width = 16;
7649 int len;
7650 int max_neighbor_width = 0;
7651 int pfx_rcd_safi;
7652 json_object *json_peer = NULL;
7653 json_object *json_peers = NULL;
7654
7655 /* labeled-unicast routes are installed in the unicast table so in order
7656 * to
7657 * display the correct PfxRcd value we must look at SAFI_UNICAST
7658 */
7659 if (safi == SAFI_LABELED_UNICAST)
7660 pfx_rcd_safi = SAFI_UNICAST;
7661 else
7662 pfx_rcd_safi = safi;
7663
7664 if (use_json) {
7665 if (json == NULL)
7666 json = json_object_new_object();
7667
7668 json_peers = json_object_new_object();
7669 } else {
7670 /* Loop over all neighbors that will be displayed to determine
7671 * how many
7672 * characters are needed for the Neighbor column
7673 */
7674 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7675 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7676 continue;
7677
7678 if (peer->afc[afi][safi]) {
7679 memset(dn_flag, '\0', sizeof(dn_flag));
7680 if (peer_dynamic_neighbor(peer))
7681 dn_flag[0] = '*';
7682
7683 if (peer->hostname
7684 && bgp_flag_check(bgp,
7685 BGP_FLAG_SHOW_HOSTNAME))
7686 sprintf(neighbor_buf, "%s%s(%s) ",
7687 dn_flag, peer->hostname,
7688 peer->host);
7689 else
7690 sprintf(neighbor_buf, "%s%s ", dn_flag,
7691 peer->host);
7692
7693 len = strlen(neighbor_buf);
7694
7695 if (len > max_neighbor_width)
7696 max_neighbor_width = len;
7697 }
7698 }
f933309e 7699
d62a17ae 7700 /* Originally we displayed the Neighbor column as 16
7701 * characters wide so make that the default
7702 */
7703 if (max_neighbor_width < neighbor_col_default_width)
7704 max_neighbor_width = neighbor_col_default_width;
7705 }
f933309e 7706
d62a17ae 7707 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7708 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7709 continue;
7710
ea47320b
DL
7711 if (!peer->afc[afi][safi])
7712 continue;
d62a17ae 7713
ea47320b
DL
7714 if (!count) {
7715 unsigned long ents;
7716 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7717 int64_t vrf_id_ui;
d62a17ae 7718
a4d82a8a
PZ
7719 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7720 ? -1
7721 : (int64_t)bgp->vrf_id;
ea47320b
DL
7722
7723 /* Usage summary and header */
7724 if (use_json) {
7725 json_object_string_add(
7726 json, "routerId",
7727 inet_ntoa(bgp->router_id));
60466a63
QY
7728 json_object_int_add(json, "as", bgp->as);
7729 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7730 json_object_string_add(
7731 json, "vrfName",
7732 (bgp->inst_type
7733 == BGP_INSTANCE_TYPE_DEFAULT)
7734 ? "Default"
7735 : bgp->name);
7736 } else {
7737 vty_out(vty,
7738 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7739 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7740 bgp->vrf_id == VRF_UNKNOWN
7741 ? -1
7742 : (int)bgp->vrf_id);
ea47320b
DL
7743 vty_out(vty, "\n");
7744 }
d62a17ae 7745
ea47320b 7746 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7747 if (use_json) {
ea47320b 7748 json_object_int_add(
60466a63 7749 json, "updateDelayLimit",
ea47320b 7750 bgp->v_update_delay);
d62a17ae 7751
ea47320b
DL
7752 if (bgp->v_update_delay
7753 != bgp->v_establish_wait)
d62a17ae 7754 json_object_int_add(
7755 json,
ea47320b
DL
7756 "updateDelayEstablishWait",
7757 bgp->v_establish_wait);
d62a17ae 7758
60466a63 7759 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7760 json_object_string_add(
7761 json,
7762 "updateDelayFirstNeighbor",
7763 bgp->update_delay_begin_time);
7764 json_object_boolean_true_add(
7765 json,
7766 "updateDelayInProgress");
7767 } else {
7768 if (bgp->update_delay_over) {
d62a17ae 7769 json_object_string_add(
7770 json,
7771 "updateDelayFirstNeighbor",
7772 bgp->update_delay_begin_time);
ea47320b 7773 json_object_string_add(
d62a17ae 7774 json,
ea47320b
DL
7775 "updateDelayBestpathResumed",
7776 bgp->update_delay_end_time);
7777 json_object_string_add(
d62a17ae 7778 json,
ea47320b
DL
7779 "updateDelayZebraUpdateResume",
7780 bgp->update_delay_zebra_resume_time);
7781 json_object_string_add(
7782 json,
7783 "updateDelayPeerUpdateResume",
7784 bgp->update_delay_peers_resume_time);
d62a17ae 7785 }
ea47320b
DL
7786 }
7787 } else {
7788 vty_out(vty,
7789 "Read-only mode update-delay limit: %d seconds\n",
7790 bgp->v_update_delay);
7791 if (bgp->v_update_delay
7792 != bgp->v_establish_wait)
d62a17ae 7793 vty_out(vty,
ea47320b
DL
7794 " Establish wait: %d seconds\n",
7795 bgp->v_establish_wait);
d62a17ae 7796
60466a63 7797 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7798 vty_out(vty,
7799 " First neighbor established: %s\n",
7800 bgp->update_delay_begin_time);
7801 vty_out(vty,
7802 " Delay in progress\n");
7803 } else {
7804 if (bgp->update_delay_over) {
d62a17ae 7805 vty_out(vty,
7806 " First neighbor established: %s\n",
7807 bgp->update_delay_begin_time);
7808 vty_out(vty,
ea47320b
DL
7809 " Best-paths resumed: %s\n",
7810 bgp->update_delay_end_time);
7811 vty_out(vty,
7812 " zebra update resumed: %s\n",
7813 bgp->update_delay_zebra_resume_time);
7814 vty_out(vty,
7815 " peers update resumed: %s\n",
7816 bgp->update_delay_peers_resume_time);
d62a17ae 7817 }
7818 }
7819 }
ea47320b 7820 }
d62a17ae 7821
ea47320b
DL
7822 if (use_json) {
7823 if (bgp_maxmed_onstartup_configured(bgp)
7824 && bgp->maxmed_active)
7825 json_object_boolean_true_add(
60466a63 7826 json, "maxMedOnStartup");
ea47320b
DL
7827 if (bgp->v_maxmed_admin)
7828 json_object_boolean_true_add(
60466a63 7829 json, "maxMedAdministrative");
d62a17ae 7830
ea47320b
DL
7831 json_object_int_add(
7832 json, "tableVersion",
60466a63 7833 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7834
60466a63
QY
7835 ents = bgp_table_count(bgp->rib[afi][safi]);
7836 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7837 json_object_int_add(
7838 json, "ribMemory",
7839 ents * sizeof(struct bgp_node));
d62a17ae 7840
ea47320b 7841 ents = listcount(bgp->peer);
60466a63
QY
7842 json_object_int_add(json, "peerCount", ents);
7843 json_object_int_add(json, "peerMemory",
7844 ents * sizeof(struct peer));
d62a17ae 7845
ea47320b
DL
7846 if ((ents = listcount(bgp->group))) {
7847 json_object_int_add(
60466a63 7848 json, "peerGroupCount", ents);
ea47320b
DL
7849 json_object_int_add(
7850 json, "peerGroupMemory",
996c9314
LB
7851 ents * sizeof(struct
7852 peer_group));
ea47320b 7853 }
d62a17ae 7854
ea47320b
DL
7855 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7856 BGP_CONFIG_DAMPENING))
7857 json_object_boolean_true_add(
60466a63 7858 json, "dampeningEnabled");
ea47320b
DL
7859 } else {
7860 if (bgp_maxmed_onstartup_configured(bgp)
7861 && bgp->maxmed_active)
d62a17ae 7862 vty_out(vty,
ea47320b
DL
7863 "Max-med on-startup active\n");
7864 if (bgp->v_maxmed_admin)
d62a17ae 7865 vty_out(vty,
ea47320b 7866 "Max-med administrative active\n");
d62a17ae 7867
60466a63
QY
7868 vty_out(vty, "BGP table version %" PRIu64 "\n",
7869 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 7870
60466a63 7871 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
7872 vty_out(vty,
7873 "RIB entries %ld, using %s of memory\n",
7874 ents,
996c9314
LB
7875 mtype_memstr(memstrbuf,
7876 sizeof(memstrbuf),
7877 ents * sizeof(struct
7878 bgp_node)));
ea47320b
DL
7879
7880 /* Peer related usage */
7881 ents = listcount(bgp->peer);
60466a63 7882 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7883 ents,
7884 mtype_memstr(
60466a63
QY
7885 memstrbuf, sizeof(memstrbuf),
7886 ents * sizeof(struct peer)));
ea47320b
DL
7887
7888 if ((ents = listcount(bgp->group)))
d62a17ae 7889 vty_out(vty,
ea47320b 7890 "Peer groups %ld, using %s of memory\n",
d62a17ae 7891 ents,
7892 mtype_memstr(
7893 memstrbuf,
7894 sizeof(memstrbuf),
996c9314
LB
7895 ents * sizeof(struct
7896 peer_group)));
d62a17ae 7897
ea47320b
DL
7898 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7899 BGP_CONFIG_DAMPENING))
60466a63 7900 vty_out(vty, "Dampening enabled.\n");
ea47320b 7901 vty_out(vty, "\n");
d62a17ae 7902
ea47320b
DL
7903 /* Subtract 8 here because 'Neighbor' is
7904 * 8 characters */
7905 vty_out(vty, "Neighbor");
60466a63
QY
7906 vty_out(vty, "%*s", max_neighbor_width - 8,
7907 " ");
ea47320b
DL
7908 vty_out(vty,
7909 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7910 }
ea47320b 7911 }
d62a17ae 7912
ea47320b 7913 count++;
d62a17ae 7914
ea47320b
DL
7915 if (use_json) {
7916 json_peer = json_object_new_object();
d62a17ae 7917
b4e9dcba
DD
7918 if (peer_dynamic_neighbor(peer)) {
7919 dn_count++;
60466a63
QY
7920 json_object_boolean_true_add(json_peer,
7921 "dynamicPeer");
b4e9dcba 7922 }
d62a17ae 7923
ea47320b 7924 if (peer->hostname)
60466a63 7925 json_object_string_add(json_peer, "hostname",
ea47320b 7926 peer->hostname);
d62a17ae 7927
ea47320b 7928 if (peer->domainname)
60466a63
QY
7929 json_object_string_add(json_peer, "domainname",
7930 peer->domainname);
d62a17ae 7931
60466a63 7932 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7933 json_object_int_add(json_peer, "version", 4);
60466a63 7934 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 7935 PEER_TOTAL_RX(peer));
60466a63 7936 json_object_int_add(json_peer, "msgSent",
0112e9e0 7937 PEER_TOTAL_TX(peer));
ea47320b
DL
7938
7939 json_object_int_add(json_peer, "tableVersion",
7940 peer->version[afi][safi]);
7941 json_object_int_add(json_peer, "outq",
7942 peer->obuf->count);
7943 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7944 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7945 use_json, json_peer);
7946 json_object_int_add(json_peer, "prefixReceivedCount",
7947 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 7948
ea47320b 7949 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7950 json_object_string_add(json_peer, "state",
ea47320b 7951 "Idle (Admin)");
9199a725
TM
7952 else if (peer->afc_recv[afi][safi])
7953 json_object_string_add(
7954 json_peer, "state",
7955 lookup_msg(bgp_status_msg, peer->status,
7956 NULL));
60466a63
QY
7957 else if (CHECK_FLAG(peer->sflags,
7958 PEER_STATUS_PREFIX_OVERFLOW))
7959 json_object_string_add(json_peer, "state",
ea47320b
DL
7960 "Idle (PfxCt)");
7961 else
7962 json_object_string_add(
7963 json_peer, "state",
60466a63
QY
7964 lookup_msg(bgp_status_msg, peer->status,
7965 NULL));
ea47320b
DL
7966
7967 if (peer->conf_if)
60466a63 7968 json_object_string_add(json_peer, "idType",
ea47320b
DL
7969 "interface");
7970 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
7971 json_object_string_add(json_peer, "idType",
7972 "ipv4");
ea47320b 7973 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
7974 json_object_string_add(json_peer, "idType",
7975 "ipv6");
d62a17ae 7976
ea47320b
DL
7977 json_object_object_add(json_peers, peer->host,
7978 json_peer);
7979 } else {
7980 memset(dn_flag, '\0', sizeof(dn_flag));
7981 if (peer_dynamic_neighbor(peer)) {
7982 dn_count++;
7983 dn_flag[0] = '*';
7984 }
d62a17ae 7985
ea47320b 7986 if (peer->hostname
60466a63 7987 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 7988 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 7989 peer->hostname, peer->host);
ea47320b 7990 else
60466a63 7991 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
7992
7993 /* pad the neighbor column with spaces */
7994 if (len < max_neighbor_width)
60466a63
QY
7995 vty_out(vty, "%*s", max_neighbor_width - len,
7996 " ");
ea47320b 7997
86a55b99 7998 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
7999 peer->as, PEER_TOTAL_RX(peer),
8000 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8001 0, peer->obuf->count,
d62a17ae 8002 peer_uptime(peer->uptime, timebuf,
ea47320b 8003 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 8004
ea47320b 8005 if (peer->status == Established)
2f8f4f10 8006 if (peer->afc_recv[afi][safi])
95077abf 8007 vty_out(vty, " %12ld",
a4d82a8a
PZ
8008 peer->pcount[afi]
8009 [pfx_rcd_safi]);
95077abf
DW
8010 else
8011 vty_out(vty, " NoNeg");
ea47320b 8012 else {
60466a63 8013 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 8014 vty_out(vty, " Idle (Admin)");
60466a63
QY
8015 else if (CHECK_FLAG(
8016 peer->sflags,
8017 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 8018 vty_out(vty, " Idle (PfxCt)");
d62a17ae 8019 else
ea47320b 8020 vty_out(vty, " %12s",
60466a63
QY
8021 lookup_msg(bgp_status_msg,
8022 peer->status, NULL));
d62a17ae 8023 }
ea47320b 8024 vty_out(vty, "\n");
d62a17ae 8025 }
8026 }
f933309e 8027
d62a17ae 8028 if (use_json) {
8029 json_object_object_add(json, "peers", json_peers);
8030
8031 json_object_int_add(json, "totalPeers", count);
8032 json_object_int_add(json, "dynamicPeers", dn_count);
8033
57a9c8a8
DS
8034 bgp_show_bestpath_json(bgp, json);
8035
996c9314
LB
8036 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8037 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8038 json_object_free(json);
8039 } else {
8040 if (count)
8041 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8042 else {
d6ceaca3 8043 vty_out(vty, "No %s neighbor is configured\n",
8044 afi_safi_print(afi, safi));
d62a17ae 8045 }
b05a1c8b 8046
d6ceaca3 8047 if (dn_count) {
d62a17ae 8048 vty_out(vty, "* - dynamic neighbor\n");
8049 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8050 dn_count, bgp->dynamic_neighbors_limit);
8051 }
8052 }
1ff9a340 8053
d62a17ae 8054 return CMD_SUCCESS;
718e3744 8055}
8056
d62a17ae 8057static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
d7c0a89a 8058 int safi, uint8_t use_json,
d62a17ae 8059 json_object *json)
8060{
8061 int is_first = 1;
8062 int afi_wildcard = (afi == AFI_MAX);
8063 int safi_wildcard = (safi == SAFI_MAX);
8064 int is_wildcard = (afi_wildcard || safi_wildcard);
8065 bool json_output = false;
8066
8067 if (use_json && is_wildcard)
8068 vty_out(vty, "{\n");
8069 if (afi_wildcard)
8070 afi = 1; /* AFI_IP */
8071 while (afi < AFI_MAX) {
8072 if (safi_wildcard)
8073 safi = 1; /* SAFI_UNICAST */
8074 while (safi < SAFI_MAX) {
318cac96 8075 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
d62a17ae 8076 json_output = true;
8077 if (is_wildcard) {
8078 /*
8079 * So limit output to those afi/safi
8080 * pairs that
8081 * actualy have something interesting in
8082 * them
8083 */
8084 if (use_json) {
8085 json = json_object_new_object();
8086
8087 if (!is_first)
8088 vty_out(vty, ",\n");
8089 else
8090 is_first = 0;
8091
8092 vty_out(vty, "\"%s\":",
8093 afi_safi_json(afi,
8094 safi));
8095 } else {
8096 vty_out(vty, "\n%s Summary:\n",
8097 afi_safi_print(afi,
8098 safi));
8099 }
8100 }
8101 bgp_show_summary(vty, bgp, afi, safi, use_json,
8102 json);
8103 }
8104 safi++;
d62a17ae 8105 if (!safi_wildcard)
8106 safi = SAFI_MAX;
8107 }
8108 afi++;
ee851c8c 8109 if (!afi_wildcard)
d62a17ae 8110 afi = AFI_MAX;
8111 }
8112
8113 if (use_json && is_wildcard)
8114 vty_out(vty, "}\n");
8115 else if (use_json && !json_output)
8116 vty_out(vty, "{}\n");
8117}
8118
8119static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
d7c0a89a 8120 safi_t safi, uint8_t use_json)
d62a17ae 8121{
8122 struct listnode *node, *nnode;
8123 struct bgp *bgp;
8124 json_object *json = NULL;
8125 int is_first = 1;
8126
8127 if (use_json)
8128 vty_out(vty, "{\n");
8129
8130 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8131 if (use_json) {
8132 json = json_object_new_object();
8133
8134 if (!is_first)
8135 vty_out(vty, ",\n");
8136 else
8137 is_first = 0;
8138
8139 vty_out(vty, "\"%s\":",
8140 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8141 ? "Default"
8142 : bgp->name);
8143 } else {
8144 vty_out(vty, "\nInstance %s:\n",
8145 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8146 ? "Default"
8147 : bgp->name);
8148 }
8149 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8150 }
8151
8152 if (use_json)
8153 vty_out(vty, "}\n");
8154}
8155
8156int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
d7c0a89a 8157 safi_t safi, uint8_t use_json)
d62a17ae 8158{
8159 struct bgp *bgp;
8160
8161 if (name) {
8162 if (strmatch(name, "all")) {
8163 bgp_show_all_instances_summary_vty(vty, afi, safi,
8164 use_json);
8165 return CMD_SUCCESS;
8166 } else {
8167 bgp = bgp_lookup_by_name(name);
8168
8169 if (!bgp) {
8170 if (use_json)
8171 vty_out(vty, "{}\n");
8172 else
8173 vty_out(vty,
8174 "%% No such BGP instance exist\n");
8175 return CMD_WARNING;
8176 }
8177
8178 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8179 NULL);
8180 return CMD_SUCCESS;
8181 }
8182 }
8183
8184 bgp = bgp_get_default();
8185
8186 if (bgp)
8187 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8188
8189 return CMD_SUCCESS;
4fb25c53
DW
8190}
8191
716b2d8a 8192/* `show [ip] bgp summary' commands. */
47fc97cc 8193DEFUN (show_ip_bgp_summary,
718e3744 8194 show_ip_bgp_summary_cmd,
dd6bd0f1 8195 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8196 SHOW_STR
8197 IP_STR
8198 BGP_STR
8386ac43 8199 BGP_INSTANCE_HELP_STR
46f296b4 8200 BGP_AFI_HELP_STR
dd6bd0f1 8201 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8202 "Summary of BGP neighbor status\n"
9973d184 8203 JSON_STR)
718e3744 8204{
d62a17ae 8205 char *vrf = NULL;
8206 afi_t afi = AFI_MAX;
8207 safi_t safi = SAFI_MAX;
8208
8209 int idx = 0;
8210
8211 /* show [ip] bgp */
8212 if (argv_find(argv, argc, "ip", &idx))
8213 afi = AFI_IP;
8214 /* [<view|vrf> VIEWVRFNAME] */
8215 if (argv_find(argv, argc, "view", &idx)
8216 || argv_find(argv, argc, "vrf", &idx))
8217 vrf = argv[++idx]->arg;
8218 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8219 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8220 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8221 }
8222
8223 int uj = use_json(argc, argv);
8224
8225 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8226}
8227
8228const char *afi_safi_print(afi_t afi, safi_t safi)
8229{
8230 if (afi == AFI_IP && safi == SAFI_UNICAST)
8231 return "IPv4 Unicast";
8232 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8233 return "IPv4 Multicast";
8234 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8235 return "IPv4 Labeled Unicast";
8236 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8237 return "IPv4 VPN";
8238 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8239 return "IPv4 Encap";
7c40bf39 8240 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8241 return "IPv4 Flowspec";
d62a17ae 8242 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8243 return "IPv6 Unicast";
8244 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8245 return "IPv6 Multicast";
8246 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8247 return "IPv6 Labeled Unicast";
8248 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8249 return "IPv6 VPN";
8250 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8251 return "IPv6 Encap";
7c40bf39 8252 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8253 return "IPv6 Flowspec";
d62a17ae 8254 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8255 return "L2VPN EVPN";
8256 else
8257 return "Unknown";
538621f2 8258}
8259
b9f77ec8
DS
8260/*
8261 * Please note that we have intentionally camelCased
8262 * the return strings here. So if you want
8263 * to use this function, please ensure you
8264 * are doing this within json output
8265 */
d62a17ae 8266const char *afi_safi_json(afi_t afi, safi_t safi)
8267{
8268 if (afi == AFI_IP && safi == SAFI_UNICAST)
8269 return "ipv4Unicast";
8270 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8271 return "ipv4Multicast";
8272 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8273 return "ipv4LabeledUnicast";
8274 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8275 return "ipv4Vpn";
8276 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8277 return "ipv4Encap";
7c40bf39 8278 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8279 return "ipv4Flowspec";
d62a17ae 8280 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8281 return "ipv6Unicast";
8282 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8283 return "ipv6Multicast";
8284 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8285 return "ipv6LabeledUnicast";
8286 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8287 return "ipv6Vpn";
8288 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8289 return "ipv6Encap";
7c40bf39 8290 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8291 return "ipv6Flowspec";
d62a17ae 8292 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8293 return "l2VpnEvpn";
8294 else
8295 return "Unknown";
27162734
LB
8296}
8297
718e3744 8298/* Show BGP peer's information. */
c5d6a9d8 8299enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
d62a17ae 8300
8301static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8302 afi_t afi, safi_t safi,
d7c0a89a
QY
8303 uint16_t adv_smcap, uint16_t adv_rmcap,
8304 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8305 uint8_t use_json, json_object *json_pref)
d62a17ae 8306{
8307 /* Send-Mode */
8308 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8309 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8310 if (use_json) {
8311 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8312 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8313 json_object_string_add(json_pref, "sendMode",
8314 "advertisedAndReceived");
8315 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8316 json_object_string_add(json_pref, "sendMode",
8317 "advertised");
8318 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8319 json_object_string_add(json_pref, "sendMode",
8320 "received");
8321 } else {
8322 vty_out(vty, " Send-mode: ");
8323 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8324 vty_out(vty, "advertised");
8325 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8326 vty_out(vty, "%sreceived",
8327 CHECK_FLAG(p->af_cap[afi][safi],
8328 adv_smcap)
8329 ? ", "
8330 : "");
8331 vty_out(vty, "\n");
8332 }
8333 }
8334
8335 /* Receive-Mode */
8336 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8337 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8338 if (use_json) {
8339 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8340 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8341 json_object_string_add(json_pref, "recvMode",
8342 "advertisedAndReceived");
8343 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8344 json_object_string_add(json_pref, "recvMode",
8345 "advertised");
8346 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8347 json_object_string_add(json_pref, "recvMode",
8348 "received");
8349 } else {
8350 vty_out(vty, " Receive-mode: ");
8351 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8352 vty_out(vty, "advertised");
8353 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8354 vty_out(vty, "%sreceived",
8355 CHECK_FLAG(p->af_cap[afi][safi],
8356 adv_rmcap)
8357 ? ", "
8358 : "");
8359 vty_out(vty, "\n");
8360 }
8361 }
8362}
8363
8364static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
d7c0a89a 8365 safi_t safi, uint8_t use_json,
d62a17ae 8366 json_object *json_neigh)
8367{
0291c246
MK
8368 struct bgp_filter *filter;
8369 struct peer_af *paf;
8370 char orf_pfx_name[BUFSIZ];
8371 int orf_pfx_count;
8372 json_object *json_af = NULL;
8373 json_object *json_prefA = NULL;
8374 json_object *json_prefB = NULL;
8375 json_object *json_addr = NULL;
d62a17ae 8376
8377 if (use_json) {
8378 json_addr = json_object_new_object();
8379 json_af = json_object_new_object();
8380 filter = &p->filter[afi][safi];
8381
8382 if (peer_group_active(p))
8383 json_object_string_add(json_addr, "peerGroupMember",
8384 p->group->name);
8385
8386 paf = peer_af_find(p, afi, safi);
8387 if (paf && PAF_SUBGRP(paf)) {
8388 json_object_int_add(json_addr, "updateGroupId",
8389 PAF_UPDGRP(paf)->id);
8390 json_object_int_add(json_addr, "subGroupId",
8391 PAF_SUBGRP(paf)->id);
8392 json_object_int_add(json_addr, "packetQueueLength",
8393 bpacket_queue_virtual_length(paf));
8394 }
8395
8396 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8397 || CHECK_FLAG(p->af_cap[afi][safi],
8398 PEER_CAP_ORF_PREFIX_SM_RCV)
8399 || CHECK_FLAG(p->af_cap[afi][safi],
8400 PEER_CAP_ORF_PREFIX_RM_ADV)
8401 || CHECK_FLAG(p->af_cap[afi][safi],
8402 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8403 json_object_int_add(json_af, "orfType",
8404 ORF_TYPE_PREFIX);
8405 json_prefA = json_object_new_object();
8406 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8407 PEER_CAP_ORF_PREFIX_SM_ADV,
8408 PEER_CAP_ORF_PREFIX_RM_ADV,
8409 PEER_CAP_ORF_PREFIX_SM_RCV,
8410 PEER_CAP_ORF_PREFIX_RM_RCV,
8411 use_json, json_prefA);
8412 json_object_object_add(json_af, "orfPrefixList",
8413 json_prefA);
8414 }
8415
8416 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8417 || CHECK_FLAG(p->af_cap[afi][safi],
8418 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8419 || CHECK_FLAG(p->af_cap[afi][safi],
8420 PEER_CAP_ORF_PREFIX_RM_ADV)
8421 || CHECK_FLAG(p->af_cap[afi][safi],
8422 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8423 json_object_int_add(json_af, "orfOldType",
8424 ORF_TYPE_PREFIX_OLD);
8425 json_prefB = json_object_new_object();
8426 bgp_show_peer_afi_orf_cap(
8427 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8428 PEER_CAP_ORF_PREFIX_RM_ADV,
8429 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8430 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8431 json_prefB);
8432 json_object_object_add(json_af, "orfOldPrefixList",
8433 json_prefB);
8434 }
8435
8436 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8437 || CHECK_FLAG(p->af_cap[afi][safi],
8438 PEER_CAP_ORF_PREFIX_SM_RCV)
8439 || CHECK_FLAG(p->af_cap[afi][safi],
8440 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8441 || CHECK_FLAG(p->af_cap[afi][safi],
8442 PEER_CAP_ORF_PREFIX_RM_ADV)
8443 || CHECK_FLAG(p->af_cap[afi][safi],
8444 PEER_CAP_ORF_PREFIX_RM_RCV)
8445 || CHECK_FLAG(p->af_cap[afi][safi],
8446 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8447 json_object_object_add(json_addr, "afDependentCap",
8448 json_af);
8449 else
8450 json_object_free(json_af);
8451
8452 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8453 orf_pfx_count = prefix_bgp_show_prefix_list(
8454 NULL, afi, orf_pfx_name, use_json);
8455
8456 if (CHECK_FLAG(p->af_sflags[afi][safi],
8457 PEER_STATUS_ORF_PREFIX_SEND)
8458 || orf_pfx_count) {
8459 if (CHECK_FLAG(p->af_sflags[afi][safi],
8460 PEER_STATUS_ORF_PREFIX_SEND))
8461 json_object_boolean_true_add(json_neigh,
8462 "orfSent");
8463 if (orf_pfx_count)
8464 json_object_int_add(json_addr, "orfRecvCounter",
8465 orf_pfx_count);
8466 }
8467 if (CHECK_FLAG(p->af_sflags[afi][safi],
8468 PEER_STATUS_ORF_WAIT_REFRESH))
8469 json_object_string_add(
8470 json_addr, "orfFirstUpdate",
8471 "deferredUntilORFOrRouteRefreshRecvd");
8472
8473 if (CHECK_FLAG(p->af_flags[afi][safi],
8474 PEER_FLAG_REFLECTOR_CLIENT))
8475 json_object_boolean_true_add(json_addr,
8476 "routeReflectorClient");
8477 if (CHECK_FLAG(p->af_flags[afi][safi],
8478 PEER_FLAG_RSERVER_CLIENT))
8479 json_object_boolean_true_add(json_addr,
8480 "routeServerClient");
8481 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8482 json_object_boolean_true_add(json_addr,
8483 "inboundSoftConfigPermit");
8484
8485 if (CHECK_FLAG(p->af_flags[afi][safi],
8486 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8487 json_object_boolean_true_add(
8488 json_addr,
8489 "privateAsNumsAllReplacedInUpdatesToNbr");
8490 else if (CHECK_FLAG(p->af_flags[afi][safi],
8491 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8492 json_object_boolean_true_add(
8493 json_addr,
8494 "privateAsNumsReplacedInUpdatesToNbr");
8495 else if (CHECK_FLAG(p->af_flags[afi][safi],
8496 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8497 json_object_boolean_true_add(
8498 json_addr,
8499 "privateAsNumsAllRemovedInUpdatesToNbr");
8500 else if (CHECK_FLAG(p->af_flags[afi][safi],
8501 PEER_FLAG_REMOVE_PRIVATE_AS))
8502 json_object_boolean_true_add(
8503 json_addr,
8504 "privateAsNumsRemovedInUpdatesToNbr");
8505
8506 if (CHECK_FLAG(p->af_flags[afi][safi],
8507 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8508 json_object_boolean_true_add(json_addr,
8509 "addpathTxAllPaths");
8510
8511 if (CHECK_FLAG(p->af_flags[afi][safi],
8512 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8513 json_object_boolean_true_add(json_addr,
8514 "addpathTxBestpathPerAS");
8515
8516 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8517 json_object_string_add(json_addr,
8518 "overrideASNsInOutboundUpdates",
8519 "ifAspathEqualRemoteAs");
8520
8521 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8522 || CHECK_FLAG(p->af_flags[afi][safi],
8523 PEER_FLAG_FORCE_NEXTHOP_SELF))
8524 json_object_boolean_true_add(json_addr,
8525 "routerAlwaysNextHop");
8526 if (CHECK_FLAG(p->af_flags[afi][safi],
8527 PEER_FLAG_AS_PATH_UNCHANGED))
8528 json_object_boolean_true_add(
8529 json_addr, "unchangedAsPathPropogatedToNbr");
8530 if (CHECK_FLAG(p->af_flags[afi][safi],
8531 PEER_FLAG_NEXTHOP_UNCHANGED))
8532 json_object_boolean_true_add(
8533 json_addr, "unchangedNextHopPropogatedToNbr");
8534 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8535 json_object_boolean_true_add(
8536 json_addr, "unchangedMedPropogatedToNbr");
8537 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8538 || CHECK_FLAG(p->af_flags[afi][safi],
8539 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8540 if (CHECK_FLAG(p->af_flags[afi][safi],
8541 PEER_FLAG_SEND_COMMUNITY)
8542 && CHECK_FLAG(p->af_flags[afi][safi],
8543 PEER_FLAG_SEND_EXT_COMMUNITY))
8544 json_object_string_add(json_addr,
8545 "commAttriSentToNbr",
8546 "extendedAndStandard");
8547 else if (CHECK_FLAG(p->af_flags[afi][safi],
8548 PEER_FLAG_SEND_EXT_COMMUNITY))
8549 json_object_string_add(json_addr,
8550 "commAttriSentToNbr",
8551 "extended");
8552 else
8553 json_object_string_add(json_addr,
8554 "commAttriSentToNbr",
8555 "standard");
8556 }
8557 if (CHECK_FLAG(p->af_flags[afi][safi],
8558 PEER_FLAG_DEFAULT_ORIGINATE)) {
8559 if (p->default_rmap[afi][safi].name)
8560 json_object_string_add(
8561 json_addr, "defaultRouteMap",
8562 p->default_rmap[afi][safi].name);
8563
8564 if (paf && PAF_SUBGRP(paf)
8565 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8566 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8567 json_object_boolean_true_add(json_addr,
8568 "defaultSent");
8569 else
8570 json_object_boolean_true_add(json_addr,
8571 "defaultNotSent");
8572 }
8573
dff8f48d 8574 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8575 if (is_evpn_enabled())
60466a63
QY
8576 json_object_boolean_true_add(
8577 json_addr, "advertiseAllVnis");
dff8f48d
MK
8578 }
8579
d62a17ae 8580 if (filter->plist[FILTER_IN].name
8581 || filter->dlist[FILTER_IN].name
8582 || filter->aslist[FILTER_IN].name
8583 || filter->map[RMAP_IN].name)
8584 json_object_boolean_true_add(json_addr,
8585 "inboundPathPolicyConfig");
8586 if (filter->plist[FILTER_OUT].name
8587 || filter->dlist[FILTER_OUT].name
8588 || filter->aslist[FILTER_OUT].name
8589 || filter->map[RMAP_OUT].name || filter->usmap.name)
8590 json_object_boolean_true_add(
8591 json_addr, "outboundPathPolicyConfig");
8592
8593 /* prefix-list */
8594 if (filter->plist[FILTER_IN].name)
8595 json_object_string_add(json_addr,
8596 "incomingUpdatePrefixFilterList",
8597 filter->plist[FILTER_IN].name);
8598 if (filter->plist[FILTER_OUT].name)
8599 json_object_string_add(json_addr,
8600 "outgoingUpdatePrefixFilterList",
8601 filter->plist[FILTER_OUT].name);
8602
8603 /* distribute-list */
8604 if (filter->dlist[FILTER_IN].name)
8605 json_object_string_add(
8606 json_addr, "incomingUpdateNetworkFilterList",
8607 filter->dlist[FILTER_IN].name);
8608 if (filter->dlist[FILTER_OUT].name)
8609 json_object_string_add(
8610 json_addr, "outgoingUpdateNetworkFilterList",
8611 filter->dlist[FILTER_OUT].name);
8612
8613 /* filter-list. */
8614 if (filter->aslist[FILTER_IN].name)
8615 json_object_string_add(json_addr,
8616 "incomingUpdateAsPathFilterList",
8617 filter->aslist[FILTER_IN].name);
8618 if (filter->aslist[FILTER_OUT].name)
8619 json_object_string_add(json_addr,
8620 "outgoingUpdateAsPathFilterList",
8621 filter->aslist[FILTER_OUT].name);
8622
8623 /* route-map. */
8624 if (filter->map[RMAP_IN].name)
8625 json_object_string_add(
8626 json_addr, "routeMapForIncomingAdvertisements",
8627 filter->map[RMAP_IN].name);
8628 if (filter->map[RMAP_OUT].name)
8629 json_object_string_add(
8630 json_addr, "routeMapForOutgoingAdvertisements",
8631 filter->map[RMAP_OUT].name);
8632
8633 /* unsuppress-map */
8634 if (filter->usmap.name)
8635 json_object_string_add(json_addr,
8636 "selectiveUnsuppressRouteMap",
8637 filter->usmap.name);
8638
8639 /* Receive prefix count */
8640 json_object_int_add(json_addr, "acceptedPrefixCounter",
8641 p->pcount[afi][safi]);
8642
8643 /* Maximum prefix */
8644 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8645 json_object_int_add(json_addr, "prefixAllowedMax",
8646 p->pmax[afi][safi]);
8647 if (CHECK_FLAG(p->af_flags[afi][safi],
8648 PEER_FLAG_MAX_PREFIX_WARNING))
8649 json_object_boolean_true_add(
8650 json_addr, "prefixAllowedMaxWarning");
8651 json_object_int_add(json_addr,
8652 "prefixAllowedWarningThresh",
8653 p->pmax_threshold[afi][safi]);
8654 if (p->pmax_restart[afi][safi])
8655 json_object_int_add(
8656 json_addr,
8657 "prefixAllowedRestartIntervalMsecs",
8658 p->pmax_restart[afi][safi] * 60000);
8659 }
8660 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8661 json_addr);
8662
8663 } else {
8664 filter = &p->filter[afi][safi];
8665
8666 vty_out(vty, " For address family: %s\n",
8667 afi_safi_print(afi, safi));
8668
8669 if (peer_group_active(p))
8670 vty_out(vty, " %s peer-group member\n",
8671 p->group->name);
8672
8673 paf = peer_af_find(p, afi, safi);
8674 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8675 vty_out(vty, " Update group %" PRIu64
8676 ", subgroup %" PRIu64 "\n",
d62a17ae 8677 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8678 vty_out(vty, " Packet Queue length %d\n",
8679 bpacket_queue_virtual_length(paf));
8680 } else {
8681 vty_out(vty, " Not part of any update group\n");
8682 }
8683 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8684 || CHECK_FLAG(p->af_cap[afi][safi],
8685 PEER_CAP_ORF_PREFIX_SM_RCV)
8686 || CHECK_FLAG(p->af_cap[afi][safi],
8687 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8688 || CHECK_FLAG(p->af_cap[afi][safi],
8689 PEER_CAP_ORF_PREFIX_RM_ADV)
8690 || CHECK_FLAG(p->af_cap[afi][safi],
8691 PEER_CAP_ORF_PREFIX_RM_RCV)
8692 || CHECK_FLAG(p->af_cap[afi][safi],
8693 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8694 vty_out(vty, " AF-dependant capabilities:\n");
8695
8696 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8697 || CHECK_FLAG(p->af_cap[afi][safi],
8698 PEER_CAP_ORF_PREFIX_SM_RCV)
8699 || CHECK_FLAG(p->af_cap[afi][safi],
8700 PEER_CAP_ORF_PREFIX_RM_ADV)
8701 || CHECK_FLAG(p->af_cap[afi][safi],
8702 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8703 vty_out(vty,
8704 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8705 ORF_TYPE_PREFIX);
8706 bgp_show_peer_afi_orf_cap(
8707 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8708 PEER_CAP_ORF_PREFIX_RM_ADV,
8709 PEER_CAP_ORF_PREFIX_SM_RCV,
8710 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8711 }
8712 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8713 || CHECK_FLAG(p->af_cap[afi][safi],
8714 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8715 || CHECK_FLAG(p->af_cap[afi][safi],
8716 PEER_CAP_ORF_PREFIX_RM_ADV)
8717 || CHECK_FLAG(p->af_cap[afi][safi],
8718 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8719 vty_out(vty,
8720 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8721 ORF_TYPE_PREFIX_OLD);
8722 bgp_show_peer_afi_orf_cap(
8723 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8724 PEER_CAP_ORF_PREFIX_RM_ADV,
8725 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8726 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8727 }
8728
8729 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8730 orf_pfx_count = prefix_bgp_show_prefix_list(
8731 NULL, afi, orf_pfx_name, use_json);
8732
8733 if (CHECK_FLAG(p->af_sflags[afi][safi],
8734 PEER_STATUS_ORF_PREFIX_SEND)
8735 || orf_pfx_count) {
8736 vty_out(vty, " Outbound Route Filter (ORF):");
8737 if (CHECK_FLAG(p->af_sflags[afi][safi],
8738 PEER_STATUS_ORF_PREFIX_SEND))
8739 vty_out(vty, " sent;");
8740 if (orf_pfx_count)
8741 vty_out(vty, " received (%d entries)",
8742 orf_pfx_count);
8743 vty_out(vty, "\n");
8744 }
8745 if (CHECK_FLAG(p->af_sflags[afi][safi],
8746 PEER_STATUS_ORF_WAIT_REFRESH))
8747 vty_out(vty,
8748 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8749
8750 if (CHECK_FLAG(p->af_flags[afi][safi],
8751 PEER_FLAG_REFLECTOR_CLIENT))
8752 vty_out(vty, " Route-Reflector Client\n");
8753 if (CHECK_FLAG(p->af_flags[afi][safi],
8754 PEER_FLAG_RSERVER_CLIENT))
8755 vty_out(vty, " Route-Server Client\n");
8756 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8757 vty_out(vty,
8758 " Inbound soft reconfiguration allowed\n");
8759
8760 if (CHECK_FLAG(p->af_flags[afi][safi],
8761 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8762 vty_out(vty,
8763 " Private AS numbers (all) replaced in updates to this neighbor\n");
8764 else if (CHECK_FLAG(p->af_flags[afi][safi],
8765 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8766 vty_out(vty,
8767 " Private AS numbers replaced in updates to this neighbor\n");
8768 else if (CHECK_FLAG(p->af_flags[afi][safi],
8769 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8770 vty_out(vty,
8771 " Private AS numbers (all) removed in updates to this neighbor\n");
8772 else if (CHECK_FLAG(p->af_flags[afi][safi],
8773 PEER_FLAG_REMOVE_PRIVATE_AS))
8774 vty_out(vty,
8775 " Private AS numbers removed in updates to this neighbor\n");
8776
8777 if (CHECK_FLAG(p->af_flags[afi][safi],
8778 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8779 vty_out(vty, " Advertise all paths via addpath\n");
8780
8781 if (CHECK_FLAG(p->af_flags[afi][safi],
8782 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8783 vty_out(vty,
8784 " Advertise bestpath per AS via addpath\n");
8785
8786 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8787 vty_out(vty,
8788 " Override ASNs in outbound updates if aspath equals remote-as\n");
8789
8790 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8791 || CHECK_FLAG(p->af_flags[afi][safi],
8792 PEER_FLAG_FORCE_NEXTHOP_SELF))
8793 vty_out(vty, " NEXT_HOP is always this router\n");
8794 if (CHECK_FLAG(p->af_flags[afi][safi],
8795 PEER_FLAG_AS_PATH_UNCHANGED))
8796 vty_out(vty,
8797 " AS_PATH is propagated unchanged to this neighbor\n");
8798 if (CHECK_FLAG(p->af_flags[afi][safi],
8799 PEER_FLAG_NEXTHOP_UNCHANGED))
8800 vty_out(vty,
8801 " NEXT_HOP is propagated unchanged to this neighbor\n");
8802 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8803 vty_out(vty,
8804 " MED is propagated unchanged to this neighbor\n");
8805 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8806 || CHECK_FLAG(p->af_flags[afi][safi],
8807 PEER_FLAG_SEND_EXT_COMMUNITY)
8808 || CHECK_FLAG(p->af_flags[afi][safi],
8809 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8810 vty_out(vty,
8811 " Community attribute sent to this neighbor");
8812 if (CHECK_FLAG(p->af_flags[afi][safi],
8813 PEER_FLAG_SEND_COMMUNITY)
8814 && CHECK_FLAG(p->af_flags[afi][safi],
8815 PEER_FLAG_SEND_EXT_COMMUNITY)
8816 && CHECK_FLAG(p->af_flags[afi][safi],
8817 PEER_FLAG_SEND_LARGE_COMMUNITY))
8818 vty_out(vty, "(all)\n");
8819 else if (CHECK_FLAG(p->af_flags[afi][safi],
8820 PEER_FLAG_SEND_LARGE_COMMUNITY))
8821 vty_out(vty, "(large)\n");
8822 else if (CHECK_FLAG(p->af_flags[afi][safi],
8823 PEER_FLAG_SEND_EXT_COMMUNITY))
8824 vty_out(vty, "(extended)\n");
8825 else
8826 vty_out(vty, "(standard)\n");
8827 }
8828 if (CHECK_FLAG(p->af_flags[afi][safi],
8829 PEER_FLAG_DEFAULT_ORIGINATE)) {
8830 vty_out(vty, " Default information originate,");
8831
8832 if (p->default_rmap[afi][safi].name)
8833 vty_out(vty, " default route-map %s%s,",
8834 p->default_rmap[afi][safi].map ? "*"
8835 : "",
8836 p->default_rmap[afi][safi].name);
8837 if (paf && PAF_SUBGRP(paf)
8838 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8839 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8840 vty_out(vty, " default sent\n");
8841 else
8842 vty_out(vty, " default not sent\n");
8843 }
8844
dff8f48d
MK
8845 /* advertise-vni-all */
8846 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8847 if (is_evpn_enabled())
dff8f48d
MK
8848 vty_out(vty, " advertise-all-vni\n");
8849 }
8850
d62a17ae 8851 if (filter->plist[FILTER_IN].name
8852 || filter->dlist[FILTER_IN].name
8853 || filter->aslist[FILTER_IN].name
8854 || filter->map[RMAP_IN].name)
8855 vty_out(vty, " Inbound path policy configured\n");
8856 if (filter->plist[FILTER_OUT].name
8857 || filter->dlist[FILTER_OUT].name
8858 || filter->aslist[FILTER_OUT].name
8859 || filter->map[RMAP_OUT].name || filter->usmap.name)
8860 vty_out(vty, " Outbound path policy configured\n");
8861
8862 /* prefix-list */
8863 if (filter->plist[FILTER_IN].name)
8864 vty_out(vty,
8865 " Incoming update prefix filter list is %s%s\n",
8866 filter->plist[FILTER_IN].plist ? "*" : "",
8867 filter->plist[FILTER_IN].name);
8868 if (filter->plist[FILTER_OUT].name)
8869 vty_out(vty,
8870 " Outgoing update prefix filter list is %s%s\n",
8871 filter->plist[FILTER_OUT].plist ? "*" : "",
8872 filter->plist[FILTER_OUT].name);
8873
8874 /* distribute-list */
8875 if (filter->dlist[FILTER_IN].name)
8876 vty_out(vty,
8877 " Incoming update network filter list is %s%s\n",
8878 filter->dlist[FILTER_IN].alist ? "*" : "",
8879 filter->dlist[FILTER_IN].name);
8880 if (filter->dlist[FILTER_OUT].name)
8881 vty_out(vty,
8882 " Outgoing update network filter list is %s%s\n",
8883 filter->dlist[FILTER_OUT].alist ? "*" : "",
8884 filter->dlist[FILTER_OUT].name);
8885
8886 /* filter-list. */
8887 if (filter->aslist[FILTER_IN].name)
8888 vty_out(vty,
8889 " Incoming update AS path filter list is %s%s\n",
8890 filter->aslist[FILTER_IN].aslist ? "*" : "",
8891 filter->aslist[FILTER_IN].name);
8892 if (filter->aslist[FILTER_OUT].name)
8893 vty_out(vty,
8894 " Outgoing update AS path filter list is %s%s\n",
8895 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8896 filter->aslist[FILTER_OUT].name);
8897
8898 /* route-map. */
8899 if (filter->map[RMAP_IN].name)
8900 vty_out(vty,
8901 " Route map for incoming advertisements is %s%s\n",
8902 filter->map[RMAP_IN].map ? "*" : "",
8903 filter->map[RMAP_IN].name);
8904 if (filter->map[RMAP_OUT].name)
8905 vty_out(vty,
8906 " Route map for outgoing advertisements is %s%s\n",
8907 filter->map[RMAP_OUT].map ? "*" : "",
8908 filter->map[RMAP_OUT].name);
8909
8910 /* unsuppress-map */
8911 if (filter->usmap.name)
8912 vty_out(vty,
8913 " Route map for selective unsuppress is %s%s\n",
8914 filter->usmap.map ? "*" : "",
8915 filter->usmap.name);
8916
8917 /* Receive prefix count */
8918 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8919
8920 /* Maximum prefix */
8921 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8922 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8923 p->pmax[afi][safi],
8924 CHECK_FLAG(p->af_flags[afi][safi],
8925 PEER_FLAG_MAX_PREFIX_WARNING)
8926 ? " (warning-only)"
8927 : "");
8928 vty_out(vty, " Threshold for warning message %d%%",
8929 p->pmax_threshold[afi][safi]);
8930 if (p->pmax_restart[afi][safi])
8931 vty_out(vty, ", restart interval %d min",
8932 p->pmax_restart[afi][safi]);
8933 vty_out(vty, "\n");
8934 }
8935
8936 vty_out(vty, "\n");
8937 }
8938}
8939
d7c0a89a 8940static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
d62a17ae 8941 json_object *json)
718e3744 8942{
d62a17ae 8943 struct bgp *bgp;
8944 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8945 char timebuf[BGP_UPTIME_LEN];
8946 char dn_flag[2];
8947 const char *subcode_str;
8948 const char *code_str;
8949 afi_t afi;
8950 safi_t safi;
d7c0a89a
QY
8951 uint16_t i;
8952 uint8_t *msg;
d62a17ae 8953 json_object *json_neigh = NULL;
8954 time_t epoch_tbuf;
718e3744 8955
d62a17ae 8956 bgp = p->bgp;
8957
8958 if (use_json)
8959 json_neigh = json_object_new_object();
8960
8961 memset(dn_flag, '\0', sizeof(dn_flag));
8962 if (!p->conf_if && peer_dynamic_neighbor(p))
8963 dn_flag[0] = '*';
8964
8965 if (!use_json) {
8966 if (p->conf_if) /* Configured interface name. */
8967 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8968 BGP_PEER_SU_UNSPEC(p)
8969 ? "None"
8970 : sockunion2str(&p->su, buf,
8971 SU_ADDRSTRLEN));
8972 else /* Configured IP address. */
8973 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8974 p->host);
8975 }
8976
8977 if (use_json) {
8978 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8979 json_object_string_add(json_neigh, "bgpNeighborAddr",
8980 "none");
8981 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8982 json_object_string_add(
8983 json_neigh, "bgpNeighborAddr",
8984 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8985
8986 json_object_int_add(json_neigh, "remoteAs", p->as);
8987
8988 if (p->change_local_as)
8989 json_object_int_add(json_neigh, "localAs",
8990 p->change_local_as);
8991 else
8992 json_object_int_add(json_neigh, "localAs", p->local_as);
8993
8994 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8995 json_object_boolean_true_add(json_neigh,
8996 "localAsNoPrepend");
8997
8998 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8999 json_object_boolean_true_add(json_neigh,
9000 "localAsReplaceAs");
9001 } else {
9002 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9003 || (p->as_type == AS_INTERNAL))
759f6308 9004 vty_out(vty, "remote AS %" PRIu32 ", ", p->as);
d62a17ae 9005 else
9006 vty_out(vty, "remote AS Unspecified, ");
9007 vty_out(vty, "local AS %u%s%s, ",
9008 p->change_local_as ? p->change_local_as : p->local_as,
9009 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9010 ? " no-prepend"
9011 : "",
9012 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9013 ? " replace-as"
9014 : "");
9015 }
9016 /* peer type internal, external, confed-internal or confed-external */
9017 if (p->as == p->local_as) {
9018 if (use_json) {
9019 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9020 json_object_boolean_true_add(
9021 json_neigh, "nbrConfedInternalLink");
9022 else
9023 json_object_boolean_true_add(json_neigh,
9024 "nbrInternalLink");
9025 } else {
9026 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9027 vty_out(vty, "confed-internal link\n");
9028 else
9029 vty_out(vty, "internal link\n");
9030 }
9031 } else {
9032 if (use_json) {
9033 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9034 json_object_boolean_true_add(
9035 json_neigh, "nbrConfedExternalLink");
9036 else
9037 json_object_boolean_true_add(json_neigh,
9038 "nbrExternalLink");
9039 } else {
9040 if (bgp_confederation_peers_check(bgp, p->as))
9041 vty_out(vty, "confed-external link\n");
9042 else
9043 vty_out(vty, "external link\n");
9044 }
9045 }
9046
9047 /* Description. */
9048 if (p->desc) {
9049 if (use_json)
9050 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9051 else
9052 vty_out(vty, " Description: %s\n", p->desc);
9053 }
9054
9055 if (p->hostname) {
9056 if (use_json) {
9057 if (p->hostname)
9058 json_object_string_add(json_neigh, "hostname",
9059 p->hostname);
9060
9061 if (p->domainname)
9062 json_object_string_add(json_neigh, "domainname",
9063 p->domainname);
9064 } else {
9065 if (p->domainname && (p->domainname[0] != '\0'))
9066 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9067 p->domainname);
9068 else
9069 vty_out(vty, "Hostname: %s\n", p->hostname);
9070 }
9071 }
9072
9073 /* Peer-group */
9074 if (p->group) {
9075 if (use_json) {
9076 json_object_string_add(json_neigh, "peerGroup",
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 json_object_string_add(
9089 json_neigh,
9090 "peerSubnetRangeGroup", buf1);
9091 }
9092 }
9093 } else {
9094 vty_out(vty,
9095 " Member of peer-group %s for session parameters\n",
9096 p->group->name);
9097
9098 if (dn_flag[0]) {
9099 struct prefix prefix, *range = NULL;
9100
9101 sockunion2hostprefix(&(p->su), &prefix);
9102 range = peer_group_lookup_dynamic_neighbor_range(
9103 p->group, &prefix);
9104
9105 if (range) {
9106 prefix2str(range, buf1, sizeof(buf1));
9107 vty_out(vty,
9108 " Belongs to the subnet range group: %s\n",
9109 buf1);
9110 }
9111 }
9112 }
9113 }
9114
9115 if (use_json) {
9116 /* Administrative shutdown. */
9117 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9118 json_object_boolean_true_add(json_neigh,
9119 "adminShutDown");
9120
9121 /* BGP Version. */
9122 json_object_int_add(json_neigh, "bgpVersion", 4);
9123 json_object_string_add(
9124 json_neigh, "remoteRouterId",
9125 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
9126 json_object_string_add(
9127 json_neigh, "localRouterId",
9128 inet_ntop(AF_INET, &bgp->router_id, buf1,
9129 sizeof(buf1)));
d62a17ae 9130
9131 /* Confederation */
9132 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9133 && bgp_confederation_peers_check(bgp, p->as))
9134 json_object_boolean_true_add(json_neigh,
9135 "nbrCommonAdmin");
9136
9137 /* Status. */
9138 json_object_string_add(
9139 json_neigh, "bgpState",
9140 lookup_msg(bgp_status_msg, p->status, NULL));
9141
9142 if (p->status == Established) {
9143 time_t uptime;
d62a17ae 9144
9145 uptime = bgp_clock();
9146 uptime -= p->uptime;
d62a17ae 9147 epoch_tbuf = time(NULL) - uptime;
9148
bee57a7a 9149#if CONFDATE > 20200101
a4d82a8a
PZ
9150 CPP_NOTICE(
9151 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9152#endif
9153 /*
9154 * bgpTimerUp was miliseconds that was accurate
9155 * up to 1 day, then the value returned
9156 * became garbage. So in order to provide
9157 * some level of backwards compatability,
9158 * we still provde the data, but now
9159 * we are returning the correct value
9160 * and also adding a new bgpTimerUpMsec
9161 * which will allow us to deprecate
9162 * this eventually
9163 */
d62a17ae 9164 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9165 uptime * 1000);
d3c7efed
DS
9166 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9167 uptime * 1000);
d62a17ae 9168 json_object_string_add(json_neigh, "bgpTimerUpString",
9169 peer_uptime(p->uptime, timebuf,
9170 BGP_UPTIME_LEN, 0,
9171 NULL));
9172 json_object_int_add(json_neigh,
9173 "bgpTimerUpEstablishedEpoch",
9174 epoch_tbuf);
9175 }
9176
9177 else if (p->status == Active) {
9178 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9179 json_object_string_add(json_neigh, "bgpStateIs",
9180 "passive");
9181 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9182 json_object_string_add(json_neigh, "bgpStateIs",
9183 "passiveNSF");
9184 }
9185
9186 /* read timer */
9187 time_t uptime;
9188 struct tm *tm;
9189
9190 uptime = bgp_clock();
9191 uptime -= p->readtime;
9192 tm = gmtime(&uptime);
9193 json_object_int_add(json_neigh, "bgpTimerLastRead",
9194 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9195 + (tm->tm_hour * 3600000));
9196
9197 uptime = bgp_clock();
9198 uptime -= p->last_write;
9199 tm = gmtime(&uptime);
9200 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9201 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9202 + (tm->tm_hour * 3600000));
9203
9204 uptime = bgp_clock();
9205 uptime -= p->update_time;
9206 tm = gmtime(&uptime);
9207 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9208 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9209 + (tm->tm_hour * 3600000));
9210
9211 /* Configured timer values. */
9212 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9213 p->v_holdtime * 1000);
9214 json_object_int_add(json_neigh,
9215 "bgpTimerKeepAliveIntervalMsecs",
9216 p->v_keepalive * 1000);
b90a8e13 9217 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9218 json_object_int_add(json_neigh,
9219 "bgpTimerConfiguredHoldTimeMsecs",
9220 p->holdtime * 1000);
9221 json_object_int_add(
9222 json_neigh,
9223 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9224 p->keepalive * 1000);
d25e4efc 9225 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9226 || (bgp->default_keepalive
9227 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9228 json_object_int_add(json_neigh,
9229 "bgpTimerConfiguredHoldTimeMsecs",
9230 bgp->default_holdtime);
9231 json_object_int_add(
9232 json_neigh,
9233 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9234 bgp->default_keepalive);
d62a17ae 9235 }
9236 } else {
9237 /* Administrative shutdown. */
9238 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9239 vty_out(vty, " Administratively shut down\n");
9240
9241 /* BGP Version. */
9242 vty_out(vty, " BGP version 4");
0e38aeb4 9243 vty_out(vty, ", remote router ID %s",
d62a17ae 9244 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
9245 vty_out(vty, ", local router ID %s\n",
9246 inet_ntop(AF_INET, &bgp->router_id, buf1,
9247 sizeof(buf1)));
d62a17ae 9248
9249 /* Confederation */
9250 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9251 && bgp_confederation_peers_check(bgp, p->as))
9252 vty_out(vty,
9253 " Neighbor under common administration\n");
9254
9255 /* Status. */
9256 vty_out(vty, " BGP state = %s",
9257 lookup_msg(bgp_status_msg, p->status, NULL));
9258
9259 if (p->status == Established)
9260 vty_out(vty, ", up for %8s",
9261 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9262 0, NULL));
9263
9264 else if (p->status == Active) {
9265 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9266 vty_out(vty, " (passive)");
9267 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9268 vty_out(vty, " (NSF passive)");
9269 }
9270 vty_out(vty, "\n");
9271
9272 /* read timer */
9273 vty_out(vty, " Last read %s",
9274 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9275 NULL));
9276 vty_out(vty, ", Last write %s\n",
9277 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9278 NULL));
9279
9280 /* Configured timer values. */
9281 vty_out(vty,
9282 " Hold time is %d, keepalive interval is %d seconds\n",
9283 p->v_holdtime, p->v_keepalive);
b90a8e13 9284 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9285 vty_out(vty, " Configured hold time is %d",
9286 p->holdtime);
9287 vty_out(vty, ", keepalive interval is %d seconds\n",
9288 p->keepalive);
d25e4efc 9289 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9290 || (bgp->default_keepalive
9291 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9292 vty_out(vty, " Configured hold time is %d",
9293 bgp->default_holdtime);
9294 vty_out(vty, ", keepalive interval is %d seconds\n",
9295 bgp->default_keepalive);
d62a17ae 9296 }
9297 }
9298 /* Capability. */
9299 if (p->status == Established) {
9300 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9301 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9302 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9303 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9304 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9305 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9306 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9307 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9308 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9309 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9310 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9311 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9312 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9313 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9314 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9315 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9316 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9317 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9318 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9319 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9320 if (use_json) {
9321 json_object *json_cap = NULL;
9322
9323 json_cap = json_object_new_object();
9324
9325 /* AS4 */
9326 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9327 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9328 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9329 && CHECK_FLAG(p->cap,
9330 PEER_CAP_AS4_RCV))
9331 json_object_string_add(
9332 json_cap, "4byteAs",
9333 "advertisedAndReceived");
9334 else if (CHECK_FLAG(p->cap,
9335 PEER_CAP_AS4_ADV))
9336 json_object_string_add(
9337 json_cap, "4byteAs",
9338 "advertised");
9339 else if (CHECK_FLAG(p->cap,
9340 PEER_CAP_AS4_RCV))
9341 json_object_string_add(
9342 json_cap, "4byteAs",
9343 "received");
9344 }
9345
9346 /* AddPath */
9347 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9348 || CHECK_FLAG(p->cap,
9349 PEER_CAP_ADDPATH_ADV)) {
9350 json_object *json_add = NULL;
9351 const char *print_store;
9352
9353 json_add = json_object_new_object();
9354
05c7a1cc
QY
9355 FOREACH_AFI_SAFI (afi, safi) {
9356 json_object *json_sub = NULL;
9357 json_sub =
9358 json_object_new_object();
9359 print_store = afi_safi_print(
9360 afi, safi);
d62a17ae 9361
05c7a1cc
QY
9362 if (CHECK_FLAG(
9363 p->af_cap[afi]
9364 [safi],
9365 PEER_CAP_ADDPATH_AF_TX_ADV)
9366 || CHECK_FLAG(
9367 p->af_cap[afi]
9368 [safi],
9369 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9370 if (CHECK_FLAG(
9371 p->af_cap
9372 [afi]
9373 [safi],
9374 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9375 && CHECK_FLAG(
d62a17ae 9376 p->af_cap
9377 [afi]
9378 [safi],
05c7a1cc
QY
9379 PEER_CAP_ADDPATH_AF_TX_RCV))
9380 json_object_boolean_true_add(
9381 json_sub,
9382 "txAdvertisedAndReceived");
9383 else if (
9384 CHECK_FLAG(
9385 p->af_cap
9386 [afi]
9387 [safi],
9388 PEER_CAP_ADDPATH_AF_TX_ADV))
9389 json_object_boolean_true_add(
9390 json_sub,
9391 "txAdvertised");
9392 else if (
9393 CHECK_FLAG(
9394 p->af_cap
9395 [afi]
9396 [safi],
9397 PEER_CAP_ADDPATH_AF_TX_RCV))
9398 json_object_boolean_true_add(
9399 json_sub,
9400 "txReceived");
9401 }
d62a17ae 9402
05c7a1cc
QY
9403 if (CHECK_FLAG(
9404 p->af_cap[afi]
9405 [safi],
9406 PEER_CAP_ADDPATH_AF_RX_ADV)
9407 || CHECK_FLAG(
9408 p->af_cap[afi]
9409 [safi],
9410 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9411 if (CHECK_FLAG(
9412 p->af_cap
9413 [afi]
9414 [safi],
9415 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9416 && CHECK_FLAG(
d62a17ae 9417 p->af_cap
9418 [afi]
9419 [safi],
9420 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9421 json_object_boolean_true_add(
9422 json_sub,
9423 "rxAdvertisedAndReceived");
9424 else if (
9425 CHECK_FLAG(
9426 p->af_cap
9427 [afi]
9428 [safi],
9429 PEER_CAP_ADDPATH_AF_RX_ADV))
9430 json_object_boolean_true_add(
9431 json_sub,
9432 "rxAdvertised");
9433 else if (
9434 CHECK_FLAG(
9435 p->af_cap
9436 [afi]
9437 [safi],
9438 PEER_CAP_ADDPATH_AF_RX_RCV))
9439 json_object_boolean_true_add(
9440 json_sub,
9441 "rxReceived");
d62a17ae 9442 }
9443
05c7a1cc
QY
9444 if (CHECK_FLAG(
9445 p->af_cap[afi]
9446 [safi],
9447 PEER_CAP_ADDPATH_AF_TX_ADV)
9448 || CHECK_FLAG(
9449 p->af_cap[afi]
9450 [safi],
9451 PEER_CAP_ADDPATH_AF_TX_RCV)
9452 || CHECK_FLAG(
9453 p->af_cap[afi]
9454 [safi],
9455 PEER_CAP_ADDPATH_AF_RX_ADV)
9456 || CHECK_FLAG(
9457 p->af_cap[afi]
9458 [safi],
9459 PEER_CAP_ADDPATH_AF_RX_RCV))
9460 json_object_object_add(
9461 json_add,
9462 print_store,
9463 json_sub);
9464 else
9465 json_object_free(
9466 json_sub);
9467 }
9468
d62a17ae 9469 json_object_object_add(
9470 json_cap, "addPath", json_add);
9471 }
9472
9473 /* Dynamic */
9474 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9475 || CHECK_FLAG(p->cap,
9476 PEER_CAP_DYNAMIC_ADV)) {
9477 if (CHECK_FLAG(p->cap,
9478 PEER_CAP_DYNAMIC_ADV)
9479 && CHECK_FLAG(p->cap,
9480 PEER_CAP_DYNAMIC_RCV))
9481 json_object_string_add(
9482 json_cap, "dynamic",
9483 "advertisedAndReceived");
9484 else if (CHECK_FLAG(
9485 p->cap,
9486 PEER_CAP_DYNAMIC_ADV))
9487 json_object_string_add(
9488 json_cap, "dynamic",
9489 "advertised");
9490 else if (CHECK_FLAG(
9491 p->cap,
9492 PEER_CAP_DYNAMIC_RCV))
9493 json_object_string_add(
9494 json_cap, "dynamic",
9495 "received");
9496 }
9497
9498 /* Extended nexthop */
9499 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9500 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9501 json_object *json_nxt = NULL;
9502 const char *print_store;
9503
9504
9505 if (CHECK_FLAG(p->cap,
9506 PEER_CAP_ENHE_ADV)
9507 && CHECK_FLAG(p->cap,
9508 PEER_CAP_ENHE_RCV))
9509 json_object_string_add(
9510 json_cap,
9511 "extendedNexthop",
9512 "advertisedAndReceived");
9513 else if (CHECK_FLAG(p->cap,
9514 PEER_CAP_ENHE_ADV))
9515 json_object_string_add(
9516 json_cap,
9517 "extendedNexthop",
9518 "advertised");
9519 else if (CHECK_FLAG(p->cap,
9520 PEER_CAP_ENHE_RCV))
9521 json_object_string_add(
9522 json_cap,
9523 "extendedNexthop",
9524 "received");
9525
9526 if (CHECK_FLAG(p->cap,
9527 PEER_CAP_ENHE_RCV)) {
9528 json_nxt =
9529 json_object_new_object();
9530
9531 for (safi = SAFI_UNICAST;
9532 safi < SAFI_MAX; safi++) {
9533 if (CHECK_FLAG(
9534 p->af_cap
9535 [AFI_IP]
9536 [safi],
9537 PEER_CAP_ENHE_AF_RCV)) {
9538 print_store = afi_safi_print(
9539 AFI_IP,
9540 safi);
9541 json_object_string_add(
9542 json_nxt,
9543 print_store,
9544 "recieved");
9545 }
9546 }
9547 json_object_object_add(
9548 json_cap,
9549 "extendedNexthopFamililesByPeer",
9550 json_nxt);
9551 }
9552 }
9553
9554 /* Route Refresh */
9555 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9556 || CHECK_FLAG(p->cap,
9557 PEER_CAP_REFRESH_NEW_RCV)
9558 || CHECK_FLAG(p->cap,
9559 PEER_CAP_REFRESH_OLD_RCV)) {
9560 if (CHECK_FLAG(p->cap,
9561 PEER_CAP_REFRESH_ADV)
9562 && (CHECK_FLAG(
9563 p->cap,
9564 PEER_CAP_REFRESH_NEW_RCV)
9565 || CHECK_FLAG(
9566 p->cap,
9567 PEER_CAP_REFRESH_OLD_RCV))) {
9568 if (CHECK_FLAG(
9569 p->cap,
9570 PEER_CAP_REFRESH_OLD_RCV)
9571 && CHECK_FLAG(
9572 p->cap,
9573 PEER_CAP_REFRESH_NEW_RCV))
9574 json_object_string_add(
9575 json_cap,
9576 "routeRefresh",
9577 "advertisedAndReceivedOldNew");
9578 else {
9579 if (CHECK_FLAG(
9580 p->cap,
9581 PEER_CAP_REFRESH_OLD_RCV))
9582 json_object_string_add(
9583 json_cap,
9584 "routeRefresh",
9585 "advertisedAndReceivedOld");
9586 else
9587 json_object_string_add(
9588 json_cap,
9589 "routeRefresh",
9590 "advertisedAndReceivedNew");
9591 }
9592 } else if (
9593 CHECK_FLAG(
9594 p->cap,
9595 PEER_CAP_REFRESH_ADV))
9596 json_object_string_add(
9597 json_cap,
9598 "routeRefresh",
9599 "advertised");
9600 else if (
9601 CHECK_FLAG(
9602 p->cap,
9603 PEER_CAP_REFRESH_NEW_RCV)
9604 || CHECK_FLAG(
9605 p->cap,
9606 PEER_CAP_REFRESH_OLD_RCV))
9607 json_object_string_add(
9608 json_cap,
9609 "routeRefresh",
9610 "received");
9611 }
9612
9613 /* Multiprotocol Extensions */
9614 json_object *json_multi = NULL;
9615 json_multi = json_object_new_object();
9616
05c7a1cc
QY
9617 FOREACH_AFI_SAFI (afi, safi) {
9618 if (p->afc_adv[afi][safi]
9619 || p->afc_recv[afi][safi]) {
9620 json_object *json_exten = NULL;
9621 json_exten =
9622 json_object_new_object();
9623
d62a17ae 9624 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9625 && p->afc_recv[afi][safi])
9626 json_object_boolean_true_add(
9627 json_exten,
9628 "advertisedAndReceived");
9629 else if (p->afc_adv[afi][safi])
9630 json_object_boolean_true_add(
9631 json_exten,
9632 "advertised");
9633 else if (p->afc_recv[afi][safi])
9634 json_object_boolean_true_add(
9635 json_exten,
9636 "received");
d62a17ae 9637
05c7a1cc
QY
9638 json_object_object_add(
9639 json_multi,
9640 afi_safi_print(afi,
9641 safi),
9642 json_exten);
d62a17ae 9643 }
9644 }
9645 json_object_object_add(
9646 json_cap, "multiprotocolExtensions",
9647 json_multi);
9648
d77114b7 9649 /* Hostname capabilities */
60466a63 9650 json_object *json_hname = NULL;
d77114b7
MK
9651
9652 json_hname = json_object_new_object();
9653
9654 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9655 json_object_string_add(
60466a63
QY
9656 json_hname, "advHostName",
9657 bgp->peer_self->hostname
9658 ? bgp->peer_self
9659 ->hostname
d77114b7
MK
9660 : "n/a");
9661 json_object_string_add(
60466a63
QY
9662 json_hname, "advDomainName",
9663 bgp->peer_self->domainname
9664 ? bgp->peer_self
9665 ->domainname
d77114b7
MK
9666 : "n/a");
9667 }
9668
9669
9670 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9671 json_object_string_add(
60466a63
QY
9672 json_hname, "rcvHostName",
9673 p->hostname ? p->hostname
9674 : "n/a");
d77114b7 9675 json_object_string_add(
60466a63
QY
9676 json_hname, "rcvDomainName",
9677 p->domainname ? p->domainname
9678 : "n/a");
d77114b7
MK
9679 }
9680
60466a63 9681 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9682 json_hname);
9683
d62a17ae 9684 /* Gracefull Restart */
9685 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9686 || CHECK_FLAG(p->cap,
9687 PEER_CAP_RESTART_ADV)) {
9688 if (CHECK_FLAG(p->cap,
9689 PEER_CAP_RESTART_ADV)
9690 && CHECK_FLAG(p->cap,
9691 PEER_CAP_RESTART_RCV))
9692 json_object_string_add(
9693 json_cap,
9694 "gracefulRestart",
9695 "advertisedAndReceived");
9696 else if (CHECK_FLAG(
9697 p->cap,
9698 PEER_CAP_RESTART_ADV))
9699 json_object_string_add(
9700 json_cap,
9701 "gracefulRestartCapability",
9702 "advertised");
9703 else if (CHECK_FLAG(
9704 p->cap,
9705 PEER_CAP_RESTART_RCV))
9706 json_object_string_add(
9707 json_cap,
9708 "gracefulRestartCapability",
9709 "received");
9710
9711 if (CHECK_FLAG(p->cap,
9712 PEER_CAP_RESTART_RCV)) {
9713 int restart_af_count = 0;
9714 json_object *json_restart =
9715 NULL;
9716 json_restart =
9717 json_object_new_object();
9718
9719 json_object_int_add(
9720 json_cap,
9721 "gracefulRestartRemoteTimerMsecs",
9722 p->v_gr_restart * 1000);
9723
05c7a1cc
QY
9724 FOREACH_AFI_SAFI (afi, safi) {
9725 if (CHECK_FLAG(
9726 p->af_cap
9727 [afi]
9728 [safi],
9729 PEER_CAP_RESTART_AF_RCV)) {
9730 json_object *
9731 json_sub =
9732 NULL;
9733 json_sub =
9734 json_object_new_object();
9735
d62a17ae 9736 if (CHECK_FLAG(
9737 p->af_cap
9738 [afi]
9739 [safi],
05c7a1cc
QY
9740 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9741 json_object_boolean_true_add(
9742 json_sub,
9743 "preserved");
9744 restart_af_count++;
9745 json_object_object_add(
9746 json_restart,
9747 afi_safi_print(
9748 afi,
9749 safi),
9750 json_sub);
d62a17ae 9751 }
9752 }
9753 if (!restart_af_count) {
9754 json_object_string_add(
9755 json_cap,
9756 "addressFamiliesByPeer",
9757 "none");
9758 json_object_free(
9759 json_restart);
9760 } else
9761 json_object_object_add(
9762 json_cap,
9763 "addressFamiliesByPeer",
9764 json_restart);
9765 }
9766 }
9767 json_object_object_add(json_neigh,
9768 "neighborCapabilities",
9769 json_cap);
9770 } else {
9771 vty_out(vty, " Neighbor capabilities:\n");
9772
9773 /* AS4 */
9774 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9775 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9776 vty_out(vty, " 4 Byte AS:");
9777 if (CHECK_FLAG(p->cap,
9778 PEER_CAP_AS4_ADV))
9779 vty_out(vty, " advertised");
9780 if (CHECK_FLAG(p->cap,
9781 PEER_CAP_AS4_RCV))
9782 vty_out(vty, " %sreceived",
9783 CHECK_FLAG(
9784 p->cap,
9785 PEER_CAP_AS4_ADV)
9786 ? "and "
9787 : "");
9788 vty_out(vty, "\n");
9789 }
9790
9791 /* AddPath */
9792 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9793 || CHECK_FLAG(p->cap,
9794 PEER_CAP_ADDPATH_ADV)) {
9795 vty_out(vty, " AddPath:\n");
9796
05c7a1cc
QY
9797 FOREACH_AFI_SAFI (afi, safi) {
9798 if (CHECK_FLAG(
9799 p->af_cap[afi]
9800 [safi],
9801 PEER_CAP_ADDPATH_AF_TX_ADV)
9802 || CHECK_FLAG(
9803 p->af_cap[afi]
9804 [safi],
9805 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9806 vty_out(vty,
9807 " %s: TX ",
9808 afi_safi_print(
9809 afi,
9810 safi));
9811
d62a17ae 9812 if (CHECK_FLAG(
9813 p->af_cap
9814 [afi]
9815 [safi],
05c7a1cc 9816 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 9817 vty_out(vty,
05c7a1cc 9818 "advertised %s",
d62a17ae 9819 afi_safi_print(
9820 afi,
9821 safi));
9822
05c7a1cc
QY
9823 if (CHECK_FLAG(
9824 p->af_cap
9825 [afi]
9826 [safi],
9827 PEER_CAP_ADDPATH_AF_TX_RCV))
9828 vty_out(vty,
9829 "%sreceived",
9830 CHECK_FLAG(
9831 p->af_cap
9832 [afi]
9833 [safi],
9834 PEER_CAP_ADDPATH_AF_TX_ADV)
9835 ? " and "
9836 : "");
d62a17ae 9837
05c7a1cc
QY
9838 vty_out(vty, "\n");
9839 }
d62a17ae 9840
05c7a1cc
QY
9841 if (CHECK_FLAG(
9842 p->af_cap[afi]
9843 [safi],
9844 PEER_CAP_ADDPATH_AF_RX_ADV)
9845 || CHECK_FLAG(
9846 p->af_cap[afi]
9847 [safi],
9848 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9849 vty_out(vty,
9850 " %s: RX ",
9851 afi_safi_print(
9852 afi,
9853 safi));
d62a17ae 9854
9855 if (CHECK_FLAG(
9856 p->af_cap
9857 [afi]
9858 [safi],
05c7a1cc 9859 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 9860 vty_out(vty,
05c7a1cc 9861 "advertised %s",
d62a17ae 9862 afi_safi_print(
9863 afi,
9864 safi));
9865
05c7a1cc
QY
9866 if (CHECK_FLAG(
9867 p->af_cap
9868 [afi]
9869 [safi],
9870 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 9871 vty_out(vty,
05c7a1cc
QY
9872 "%sreceived",
9873 CHECK_FLAG(
9874 p->af_cap
9875 [afi]
9876 [safi],
9877 PEER_CAP_ADDPATH_AF_RX_ADV)
9878 ? " and "
9879 : "");
9880
9881 vty_out(vty, "\n");
d62a17ae 9882 }
05c7a1cc 9883 }
d62a17ae 9884 }
9885
9886 /* Dynamic */
9887 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9888 || CHECK_FLAG(p->cap,
9889 PEER_CAP_DYNAMIC_ADV)) {
9890 vty_out(vty, " Dynamic:");
9891 if (CHECK_FLAG(p->cap,
9892 PEER_CAP_DYNAMIC_ADV))
9893 vty_out(vty, " advertised");
9894 if (CHECK_FLAG(p->cap,
9895 PEER_CAP_DYNAMIC_RCV))
9896 vty_out(vty, " %sreceived",
9897 CHECK_FLAG(
9898 p->cap,
9899 PEER_CAP_DYNAMIC_ADV)
9900 ? "and "
9901 : "");
9902 vty_out(vty, "\n");
9903 }
9904
9905 /* Extended nexthop */
9906 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9907 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9908 vty_out(vty, " Extended nexthop:");
9909 if (CHECK_FLAG(p->cap,
9910 PEER_CAP_ENHE_ADV))
9911 vty_out(vty, " advertised");
9912 if (CHECK_FLAG(p->cap,
9913 PEER_CAP_ENHE_RCV))
9914 vty_out(vty, " %sreceived",
9915 CHECK_FLAG(
9916 p->cap,
9917 PEER_CAP_ENHE_ADV)
9918 ? "and "
9919 : "");
9920 vty_out(vty, "\n");
9921
9922 if (CHECK_FLAG(p->cap,
9923 PEER_CAP_ENHE_RCV)) {
9924 vty_out(vty,
9925 " Address families by peer:\n ");
9926 for (safi = SAFI_UNICAST;
9927 safi < SAFI_MAX; safi++)
9928 if (CHECK_FLAG(
9929 p->af_cap
9930 [AFI_IP]
9931 [safi],
9932 PEER_CAP_ENHE_AF_RCV))
9933 vty_out(vty,
9934 " %s\n",
9935 afi_safi_print(
9936 AFI_IP,
9937 safi));
9938 }
9939 }
9940
9941 /* Route Refresh */
9942 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9943 || CHECK_FLAG(p->cap,
9944 PEER_CAP_REFRESH_NEW_RCV)
9945 || CHECK_FLAG(p->cap,
9946 PEER_CAP_REFRESH_OLD_RCV)) {
9947 vty_out(vty, " Route refresh:");
9948 if (CHECK_FLAG(p->cap,
9949 PEER_CAP_REFRESH_ADV))
9950 vty_out(vty, " advertised");
9951 if (CHECK_FLAG(p->cap,
9952 PEER_CAP_REFRESH_NEW_RCV)
9953 || CHECK_FLAG(
9954 p->cap,
9955 PEER_CAP_REFRESH_OLD_RCV))
9956 vty_out(vty, " %sreceived(%s)",
9957 CHECK_FLAG(
9958 p->cap,
9959 PEER_CAP_REFRESH_ADV)
9960 ? "and "
9961 : "",
9962 (CHECK_FLAG(
9963 p->cap,
9964 PEER_CAP_REFRESH_OLD_RCV)
9965 && CHECK_FLAG(
9966 p->cap,
9967 PEER_CAP_REFRESH_NEW_RCV))
9968 ? "old & new"
9969 : CHECK_FLAG(
9970 p->cap,
9971 PEER_CAP_REFRESH_OLD_RCV)
9972 ? "old"
9973 : "new");
9974
9975 vty_out(vty, "\n");
9976 }
9977
9978 /* Multiprotocol Extensions */
05c7a1cc
QY
9979 FOREACH_AFI_SAFI (afi, safi)
9980 if (p->afc_adv[afi][safi]
9981 || p->afc_recv[afi][safi]) {
9982 vty_out(vty,
9983 " Address Family %s:",
9984 afi_safi_print(afi,
9985 safi));
9986 if (p->afc_adv[afi][safi])
d62a17ae 9987 vty_out(vty,
05c7a1cc
QY
9988 " advertised");
9989 if (p->afc_recv[afi][safi])
9990 vty_out(vty,
9991 " %sreceived",
9992 p->afc_adv[afi]
9993 [safi]
9994 ? "and "
9995 : "");
9996 vty_out(vty, "\n");
9997 }
d62a17ae 9998
9999 /* Hostname capability */
60466a63 10000 vty_out(vty, " Hostname Capability:");
d77114b7
MK
10001
10002 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
10003 vty_out(vty,
10004 " advertised (name: %s,domain name: %s)",
60466a63
QY
10005 bgp->peer_self->hostname
10006 ? bgp->peer_self
10007 ->hostname
d77114b7 10008 : "n/a",
60466a63
QY
10009 bgp->peer_self->domainname
10010 ? bgp->peer_self
10011 ->domainname
d77114b7
MK
10012 : "n/a");
10013 } else {
10014 vty_out(vty, " not advertised");
d62a17ae 10015 }
10016
d77114b7 10017 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10018 vty_out(vty,
10019 " received (name: %s,domain name: %s)",
60466a63
QY
10020 p->hostname ? p->hostname
10021 : "n/a",
10022 p->domainname ? p->domainname
10023 : "n/a");
d77114b7
MK
10024 } else {
10025 vty_out(vty, " not received");
10026 }
10027
10028 vty_out(vty, "\n");
10029
d62a17ae 10030 /* Gracefull Restart */
10031 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10032 || CHECK_FLAG(p->cap,
10033 PEER_CAP_RESTART_ADV)) {
10034 vty_out(vty,
10035 " Graceful Restart Capabilty:");
10036 if (CHECK_FLAG(p->cap,
10037 PEER_CAP_RESTART_ADV))
10038 vty_out(vty, " advertised");
10039 if (CHECK_FLAG(p->cap,
10040 PEER_CAP_RESTART_RCV))
10041 vty_out(vty, " %sreceived",
10042 CHECK_FLAG(
10043 p->cap,
10044 PEER_CAP_RESTART_ADV)
10045 ? "and "
10046 : "");
10047 vty_out(vty, "\n");
10048
10049 if (CHECK_FLAG(p->cap,
10050 PEER_CAP_RESTART_RCV)) {
10051 int restart_af_count = 0;
10052
10053 vty_out(vty,
10054 " Remote Restart timer is %d seconds\n",
10055 p->v_gr_restart);
10056 vty_out(vty,
10057 " Address families by peer:\n ");
10058
05c7a1cc
QY
10059 FOREACH_AFI_SAFI (afi, safi)
10060 if (CHECK_FLAG(
10061 p->af_cap
10062 [afi]
10063 [safi],
10064 PEER_CAP_RESTART_AF_RCV)) {
10065 vty_out(vty,
10066 "%s%s(%s)",
10067 restart_af_count
10068 ? ", "
10069 : "",
10070 afi_safi_print(
10071 afi,
10072 safi),
10073 CHECK_FLAG(
10074 p->af_cap
10075 [afi]
10076 [safi],
10077 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10078 ? "preserved"
10079 : "not preserved");
10080 restart_af_count++;
10081 }
d62a17ae 10082 if (!restart_af_count)
10083 vty_out(vty, "none");
10084 vty_out(vty, "\n");
10085 }
10086 }
10087 }
10088 }
10089 }
10090
10091 /* graceful restart information */
10092 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10093 || p->t_gr_stale) {
10094 json_object *json_grace = NULL;
10095 json_object *json_grace_send = NULL;
10096 json_object *json_grace_recv = NULL;
10097 int eor_send_af_count = 0;
10098 int eor_receive_af_count = 0;
10099
10100 if (use_json) {
10101 json_grace = json_object_new_object();
10102 json_grace_send = json_object_new_object();
10103 json_grace_recv = json_object_new_object();
10104
10105 if (p->status == Established) {
05c7a1cc
QY
10106 FOREACH_AFI_SAFI (afi, safi) {
10107 if (CHECK_FLAG(p->af_sflags[afi][safi],
10108 PEER_STATUS_EOR_SEND)) {
10109 json_object_boolean_true_add(
10110 json_grace_send,
10111 afi_safi_print(afi,
10112 safi));
10113 eor_send_af_count++;
d62a17ae 10114 }
10115 }
05c7a1cc
QY
10116 FOREACH_AFI_SAFI (afi, safi) {
10117 if (CHECK_FLAG(
10118 p->af_sflags[afi][safi],
10119 PEER_STATUS_EOR_RECEIVED)) {
10120 json_object_boolean_true_add(
10121 json_grace_recv,
10122 afi_safi_print(afi,
10123 safi));
10124 eor_receive_af_count++;
d62a17ae 10125 }
10126 }
10127 }
10128
10129 json_object_object_add(json_grace, "endOfRibSend",
10130 json_grace_send);
10131 json_object_object_add(json_grace, "endOfRibRecv",
10132 json_grace_recv);
10133
10134 if (p->t_gr_restart)
10135 json_object_int_add(json_grace,
10136 "gracefulRestartTimerMsecs",
10137 thread_timer_remain_second(
10138 p->t_gr_restart)
10139 * 1000);
10140
10141 if (p->t_gr_stale)
10142 json_object_int_add(
10143 json_grace,
10144 "gracefulStalepathTimerMsecs",
10145 thread_timer_remain_second(
10146 p->t_gr_stale)
10147 * 1000);
10148
10149 json_object_object_add(
10150 json_neigh, "gracefulRestartInfo", json_grace);
10151 } else {
4e69658c 10152 vty_out(vty, " Graceful restart information:\n");
d62a17ae 10153 if (p->status == Established) {
10154 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10155 FOREACH_AFI_SAFI (afi, safi) {
10156 if (CHECK_FLAG(p->af_sflags[afi][safi],
10157 PEER_STATUS_EOR_SEND)) {
10158 vty_out(vty, "%s%s",
10159 eor_send_af_count ? ", "
10160 : "",
10161 afi_safi_print(afi,
10162 safi));
10163 eor_send_af_count++;
d62a17ae 10164 }
10165 }
10166 vty_out(vty, "\n");
10167 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10168 FOREACH_AFI_SAFI (afi, safi) {
10169 if (CHECK_FLAG(
10170 p->af_sflags[afi][safi],
10171 PEER_STATUS_EOR_RECEIVED)) {
10172 vty_out(vty, "%s%s",
10173 eor_receive_af_count
10174 ? ", "
10175 : "",
10176 afi_safi_print(afi,
10177 safi));
10178 eor_receive_af_count++;
d62a17ae 10179 }
10180 }
10181 vty_out(vty, "\n");
10182 }
10183
10184 if (p->t_gr_restart)
10185 vty_out(vty,
10186 " The remaining time of restart timer is %ld\n",
10187 thread_timer_remain_second(
10188 p->t_gr_restart));
10189
10190 if (p->t_gr_stale)
10191 vty_out(vty,
10192 " The remaining time of stalepath timer is %ld\n",
10193 thread_timer_remain_second(
10194 p->t_gr_stale));
10195 }
10196 }
10197 if (use_json) {
10198 json_object *json_stat = NULL;
10199 json_stat = json_object_new_object();
10200 /* Packet counts. */
10201 json_object_int_add(json_stat, "depthInq", 0);
10202 json_object_int_add(json_stat, "depthOutq",
10203 (unsigned long)p->obuf->count);
0112e9e0
QY
10204 json_object_int_add(json_stat, "opensSent",
10205 atomic_load_explicit(&p->open_out,
10206 memory_order_relaxed));
10207 json_object_int_add(json_stat, "opensRecv",
10208 atomic_load_explicit(&p->open_in,
10209 memory_order_relaxed));
d62a17ae 10210 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10211 atomic_load_explicit(&p->notify_out,
10212 memory_order_relaxed));
d62a17ae 10213 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10214 atomic_load_explicit(&p->notify_in,
10215 memory_order_relaxed));
10216 json_object_int_add(json_stat, "updatesSent",
10217 atomic_load_explicit(&p->update_out,
10218 memory_order_relaxed));
10219 json_object_int_add(json_stat, "updatesRecv",
10220 atomic_load_explicit(&p->update_in,
10221 memory_order_relaxed));
d62a17ae 10222 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10223 atomic_load_explicit(&p->keepalive_out,
10224 memory_order_relaxed));
d62a17ae 10225 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10226 atomic_load_explicit(&p->keepalive_in,
10227 memory_order_relaxed));
d62a17ae 10228 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10229 atomic_load_explicit(&p->refresh_out,
10230 memory_order_relaxed));
d62a17ae 10231 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10232 atomic_load_explicit(&p->refresh_in,
10233 memory_order_relaxed));
d62a17ae 10234 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10235 atomic_load_explicit(&p->dynamic_cap_out,
10236 memory_order_relaxed));
d62a17ae 10237 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10238 atomic_load_explicit(&p->dynamic_cap_in,
10239 memory_order_relaxed));
10240 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10241 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10242 json_object_object_add(json_neigh, "messageStats", json_stat);
10243 } else {
10244 /* Packet counts. */
10245 vty_out(vty, " Message statistics:\n");
10246 vty_out(vty, " Inq depth is 0\n");
10247 vty_out(vty, " Outq depth is %lu\n",
10248 (unsigned long)p->obuf->count);
10249 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10250 vty_out(vty, " Opens: %10d %10d\n",
10251 atomic_load_explicit(&p->open_out,
10252 memory_order_relaxed),
10253 atomic_load_explicit(&p->open_in,
10254 memory_order_relaxed));
10255 vty_out(vty, " Notifications: %10d %10d\n",
10256 atomic_load_explicit(&p->notify_out,
10257 memory_order_relaxed),
10258 atomic_load_explicit(&p->notify_in,
10259 memory_order_relaxed));
10260 vty_out(vty, " Updates: %10d %10d\n",
10261 atomic_load_explicit(&p->update_out,
10262 memory_order_relaxed),
10263 atomic_load_explicit(&p->update_in,
10264 memory_order_relaxed));
10265 vty_out(vty, " Keepalives: %10d %10d\n",
10266 atomic_load_explicit(&p->keepalive_out,
10267 memory_order_relaxed),
10268 atomic_load_explicit(&p->keepalive_in,
10269 memory_order_relaxed));
10270 vty_out(vty, " Route Refresh: %10d %10d\n",
10271 atomic_load_explicit(&p->refresh_out,
10272 memory_order_relaxed),
10273 atomic_load_explicit(&p->refresh_in,
10274 memory_order_relaxed));
d62a17ae 10275 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10276 atomic_load_explicit(&p->dynamic_cap_out,
10277 memory_order_relaxed),
10278 atomic_load_explicit(&p->dynamic_cap_in,
10279 memory_order_relaxed));
10280 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10281 PEER_TOTAL_RX(p));
d62a17ae 10282 }
10283
10284 if (use_json) {
10285 /* advertisement-interval */
10286 json_object_int_add(json_neigh,
10287 "minBtwnAdvertisementRunsTimerMsecs",
10288 p->v_routeadv * 1000);
10289
10290 /* Update-source. */
10291 if (p->update_if || p->update_source) {
10292 if (p->update_if)
10293 json_object_string_add(json_neigh,
10294 "updateSource",
10295 p->update_if);
10296 else if (p->update_source)
10297 json_object_string_add(
10298 json_neigh, "updateSource",
10299 sockunion2str(p->update_source, buf1,
10300 SU_ADDRSTRLEN));
10301 }
10302 } else {
10303 /* advertisement-interval */
10304 vty_out(vty,
10305 " Minimum time between advertisement runs is %d seconds\n",
10306 p->v_routeadv);
10307
10308 /* Update-source. */
10309 if (p->update_if || p->update_source) {
10310 vty_out(vty, " Update source is ");
10311 if (p->update_if)
10312 vty_out(vty, "%s", p->update_if);
10313 else if (p->update_source)
10314 vty_out(vty, "%s",
10315 sockunion2str(p->update_source, buf1,
10316 SU_ADDRSTRLEN));
10317 vty_out(vty, "\n");
10318 }
10319
10320 vty_out(vty, "\n");
10321 }
10322
10323 /* Address Family Information */
10324 json_object *json_hold = NULL;
10325
10326 if (use_json)
10327 json_hold = json_object_new_object();
10328
05c7a1cc
QY
10329 FOREACH_AFI_SAFI (afi, safi)
10330 if (p->afc[afi][safi])
10331 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10332 json_hold);
d62a17ae 10333
10334 if (use_json) {
10335 json_object_object_add(json_neigh, "addressFamilyInfo",
10336 json_hold);
10337 json_object_int_add(json_neigh, "connectionsEstablished",
10338 p->established);
10339 json_object_int_add(json_neigh, "connectionsDropped",
10340 p->dropped);
10341 } else
10342 vty_out(vty, " Connections established %d; dropped %d\n",
10343 p->established, p->dropped);
10344
10345 if (!p->last_reset) {
10346 if (use_json)
10347 json_object_string_add(json_neigh, "lastReset",
10348 "never");
10349 else
10350 vty_out(vty, " Last reset never\n");
10351 } else {
10352 if (use_json) {
10353 time_t uptime;
10354 struct tm *tm;
10355
10356 uptime = bgp_clock();
10357 uptime -= p->resettime;
10358 tm = gmtime(&uptime);
10359 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10360 (tm->tm_sec * 1000)
10361 + (tm->tm_min * 60000)
10362 + (tm->tm_hour * 3600000));
10363 json_object_string_add(
10364 json_neigh, "lastResetDueTo",
10365 peer_down_str[(int)p->last_reset]);
10366 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10367 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10368 char errorcodesubcode_hexstr[5];
10369 char errorcodesubcode_str[256];
10370
10371 code_str = bgp_notify_code_str(p->notify.code);
10372 subcode_str = bgp_notify_subcode_str(
10373 p->notify.code, p->notify.subcode);
10374
10375 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10376 p->notify.code, p->notify.subcode);
10377 json_object_string_add(json_neigh,
10378 "lastErrorCodeSubcode",
10379 errorcodesubcode_hexstr);
10380 snprintf(errorcodesubcode_str, 255, "%s%s",
10381 code_str, subcode_str);
10382 json_object_string_add(json_neigh,
10383 "lastNotificationReason",
10384 errorcodesubcode_str);
10385 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10386 && p->notify.code == BGP_NOTIFY_CEASE
10387 && (p->notify.subcode
10388 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10389 || p->notify.subcode
10390 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10391 && p->notify.length) {
10392 char msgbuf[1024];
10393 const char *msg_str;
10394
10395 msg_str = bgp_notify_admin_message(
10396 msgbuf, sizeof(msgbuf),
d7c0a89a 10397 (uint8_t *)p->notify.data,
d62a17ae 10398 p->notify.length);
10399 if (msg_str)
10400 json_object_string_add(
10401 json_neigh,
10402 "lastShutdownDescription",
10403 msg_str);
10404 }
10405 }
10406 } else {
10407 vty_out(vty, " Last reset %s, ",
10408 peer_uptime(p->resettime, timebuf,
10409 BGP_UPTIME_LEN, 0, NULL));
10410
10411 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10412 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10413 code_str = bgp_notify_code_str(p->notify.code);
10414 subcode_str = bgp_notify_subcode_str(
10415 p->notify.code, p->notify.subcode);
10416 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10417 p->last_reset == PEER_DOWN_NOTIFY_SEND
10418 ? "sent"
10419 : "received",
10420 code_str, subcode_str);
10421 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10422 && p->notify.code == BGP_NOTIFY_CEASE
10423 && (p->notify.subcode
10424 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10425 || p->notify.subcode
10426 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10427 && p->notify.length) {
10428 char msgbuf[1024];
10429 const char *msg_str;
10430
10431 msg_str = bgp_notify_admin_message(
10432 msgbuf, sizeof(msgbuf),
d7c0a89a 10433 (uint8_t *)p->notify.data,
d62a17ae 10434 p->notify.length);
10435 if (msg_str)
10436 vty_out(vty,
10437 " Message: \"%s\"\n",
10438 msg_str);
10439 }
10440 } else {
10441 vty_out(vty, "due to %s\n",
10442 peer_down_str[(int)p->last_reset]);
10443 }
10444
10445 if (p->last_reset_cause_size) {
10446 msg = p->last_reset_cause;
10447 vty_out(vty,
10448 " Message received that caused BGP to send a NOTIFICATION:\n ");
10449 for (i = 1; i <= p->last_reset_cause_size;
10450 i++) {
10451 vty_out(vty, "%02X", *msg++);
10452
10453 if (i != p->last_reset_cause_size) {
10454 if (i % 16 == 0) {
10455 vty_out(vty, "\n ");
10456 } else if (i % 4 == 0) {
10457 vty_out(vty, " ");
10458 }
10459 }
10460 }
10461 vty_out(vty, "\n");
10462 }
10463 }
10464 }
10465
10466 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10467 if (use_json)
10468 json_object_boolean_true_add(json_neigh,
10469 "prefixesConfigExceedMax");
10470 else
10471 vty_out(vty,
10472 " Peer had exceeded the max. no. of prefixes configured.\n");
10473
10474 if (p->t_pmax_restart) {
10475 if (use_json) {
10476 json_object_boolean_true_add(
10477 json_neigh, "reducePrefixNumFrom");
10478 json_object_int_add(json_neigh,
10479 "restartInTimerMsec",
10480 thread_timer_remain_second(
10481 p->t_pmax_restart)
10482 * 1000);
10483 } else
10484 vty_out(vty,
10485 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10486 p->host, thread_timer_remain_second(
10487 p->t_pmax_restart));
d62a17ae 10488 } else {
10489 if (use_json)
10490 json_object_boolean_true_add(
10491 json_neigh,
10492 "reducePrefixNumAndClearIpBgp");
10493 else
10494 vty_out(vty,
10495 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10496 p->host);
10497 }
10498 }
10499
10500 /* EBGP Multihop and GTSM */
10501 if (p->sort != BGP_PEER_IBGP) {
10502 if (use_json) {
10503 if (p->gtsm_hops > 0)
10504 json_object_int_add(json_neigh,
10505 "externalBgpNbrMaxHopsAway",
10506 p->gtsm_hops);
10507 else if (p->ttl > 1)
10508 json_object_int_add(json_neigh,
10509 "externalBgpNbrMaxHopsAway",
10510 p->ttl);
10511 } else {
10512 if (p->gtsm_hops > 0)
10513 vty_out(vty,
10514 " External BGP neighbor may be up to %d hops away.\n",
10515 p->gtsm_hops);
10516 else if (p->ttl > 1)
10517 vty_out(vty,
10518 " External BGP neighbor may be up to %d hops away.\n",
10519 p->ttl);
10520 }
10521 } else {
10522 if (p->gtsm_hops > 0) {
10523 if (use_json)
10524 json_object_int_add(json_neigh,
10525 "internalBgpNbrMaxHopsAway",
10526 p->gtsm_hops);
10527 else
10528 vty_out(vty,
10529 " Internal BGP neighbor may be up to %d hops away.\n",
10530 p->gtsm_hops);
10531 }
10532 }
10533
10534 /* Local address. */
10535 if (p->su_local) {
10536 if (use_json) {
10537 json_object_string_add(json_neigh, "hostLocal",
10538 sockunion2str(p->su_local, buf1,
10539 SU_ADDRSTRLEN));
10540 json_object_int_add(json_neigh, "portLocal",
10541 ntohs(p->su_local->sin.sin_port));
10542 } else
10543 vty_out(vty, "Local host: %s, Local port: %d\n",
10544 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10545 ntohs(p->su_local->sin.sin_port));
10546 }
10547
10548 /* Remote address. */
10549 if (p->su_remote) {
10550 if (use_json) {
10551 json_object_string_add(json_neigh, "hostForeign",
10552 sockunion2str(p->su_remote, buf1,
10553 SU_ADDRSTRLEN));
10554 json_object_int_add(json_neigh, "portForeign",
10555 ntohs(p->su_remote->sin.sin_port));
10556 } else
10557 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10558 sockunion2str(p->su_remote, buf1,
10559 SU_ADDRSTRLEN),
10560 ntohs(p->su_remote->sin.sin_port));
10561 }
10562
10563 /* Nexthop display. */
10564 if (p->su_local) {
10565 if (use_json) {
10566 json_object_string_add(json_neigh, "nexthop",
10567 inet_ntop(AF_INET,
10568 &p->nexthop.v4, buf1,
10569 sizeof(buf1)));
10570 json_object_string_add(json_neigh, "nexthopGlobal",
10571 inet_ntop(AF_INET6,
10572 &p->nexthop.v6_global,
10573 buf1, sizeof(buf1)));
10574 json_object_string_add(json_neigh, "nexthopLocal",
10575 inet_ntop(AF_INET6,
10576 &p->nexthop.v6_local,
10577 buf1, sizeof(buf1)));
10578 if (p->shared_network)
10579 json_object_string_add(json_neigh,
10580 "bgpConnection",
10581 "sharedNetwork");
10582 else
10583 json_object_string_add(json_neigh,
10584 "bgpConnection",
10585 "nonSharedNetwork");
10586 } else {
10587 vty_out(vty, "Nexthop: %s\n",
10588 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10589 sizeof(buf1)));
10590 vty_out(vty, "Nexthop global: %s\n",
10591 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10592 sizeof(buf1)));
10593 vty_out(vty, "Nexthop local: %s\n",
10594 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10595 sizeof(buf1)));
10596 vty_out(vty, "BGP connection: %s\n",
10597 p->shared_network ? "shared network"
10598 : "non shared network");
10599 }
10600 }
10601
10602 /* Timer information. */
10603 if (use_json) {
10604 json_object_int_add(json_neigh, "connectRetryTimer",
10605 p->v_connect);
10606 if (p->status == Established && p->rtt)
10607 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10608 p->rtt);
10609 if (p->t_start)
10610 json_object_int_add(
10611 json_neigh, "nextStartTimerDueInMsecs",
10612 thread_timer_remain_second(p->t_start) * 1000);
10613 if (p->t_connect)
10614 json_object_int_add(
10615 json_neigh, "nextConnectTimerDueInMsecs",
10616 thread_timer_remain_second(p->t_connect)
10617 * 1000);
10618 if (p->t_routeadv) {
10619 json_object_int_add(json_neigh, "mraiInterval",
10620 p->v_routeadv);
10621 json_object_int_add(
10622 json_neigh, "mraiTimerExpireInMsecs",
10623 thread_timer_remain_second(p->t_routeadv)
10624 * 1000);
10625 }
10626 if (p->password)
10627 json_object_int_add(json_neigh, "authenticationEnabled",
10628 1);
10629
10630 if (p->t_read)
10631 json_object_string_add(json_neigh, "readThread", "on");
10632 else
10633 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10634
10635 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10636 json_object_string_add(json_neigh, "writeThread", "on");
10637 else
10638 json_object_string_add(json_neigh, "writeThread",
10639 "off");
10640 } else {
10641 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10642 p->v_connect);
10643 if (p->status == Established && p->rtt)
10644 vty_out(vty, "Estimated round trip time: %d ms\n",
10645 p->rtt);
10646 if (p->t_start)
10647 vty_out(vty, "Next start timer due in %ld seconds\n",
10648 thread_timer_remain_second(p->t_start));
10649 if (p->t_connect)
10650 vty_out(vty, "Next connect timer due in %ld seconds\n",
10651 thread_timer_remain_second(p->t_connect));
10652 if (p->t_routeadv)
10653 vty_out(vty,
10654 "MRAI (interval %u) timer expires in %ld seconds\n",
10655 p->v_routeadv,
10656 thread_timer_remain_second(p->t_routeadv));
10657 if (p->password)
10658 vty_out(vty, "Peer Authentication Enabled\n");
10659
10660 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10661 p->t_read ? "on" : "off",
10662 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10663 ? "on"
10664 : "off");
d62a17ae 10665 }
10666
10667 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10668 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10669 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10670
10671 if (!use_json)
10672 vty_out(vty, "\n");
10673
10674 /* BFD information. */
10675 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10676
10677 if (use_json) {
10678 if (p->conf_if) /* Configured interface name. */
10679 json_object_object_add(json, p->conf_if, json_neigh);
10680 else /* Configured IP address. */
10681 json_object_object_add(json, p->host, json_neigh);
10682 }
10683}
10684
10685static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10686 enum show_type type, union sockunion *su,
d7c0a89a 10687 const char *conf_if, uint8_t use_json,
d62a17ae 10688 json_object *json)
10689{
10690 struct listnode *node, *nnode;
10691 struct peer *peer;
10692 int find = 0;
c5d6a9d8
KK
10693 afi_t afi = AFI_MAX;
10694 safi_t safi = SAFI_MAX;
10695
10696 if (type == show_ipv4_peer || type == show_ipv4_all) {
10697 afi = AFI_IP;
10698 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10699 afi = AFI_IP6;
10700 }
d62a17ae 10701
10702 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10703 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10704 continue;
10705
10706 switch (type) {
10707 case show_all:
10708 bgp_show_peer(vty, peer, use_json, json);
10709 break;
10710 case show_peer:
10711 if (conf_if) {
10712 if ((peer->conf_if
10713 && !strcmp(peer->conf_if, conf_if))
10714 || (peer->hostname
10715 && !strcmp(peer->hostname, conf_if))) {
10716 find = 1;
10717 bgp_show_peer(vty, peer, use_json,
10718 json);
10719 }
10720 } else {
10721 if (sockunion_same(&peer->su, su)) {
10722 find = 1;
10723 bgp_show_peer(vty, peer, use_json,
10724 json);
10725 }
10726 }
10727 break;
c5d6a9d8
KK
10728 case show_ipv4_peer:
10729 case show_ipv6_peer:
10730 FOREACH_SAFI (safi) {
10731 if (peer->afc[afi][safi]) {
10732 if (conf_if) {
10733 if ((peer->conf_if
10734 && !strcmp(peer->conf_if, conf_if))
10735 || (peer->hostname
10736 && !strcmp(peer->hostname, conf_if))) {
10737 find = 1;
10738 bgp_show_peer(vty, peer, use_json,
10739 json);
10740 break;
10741 }
10742 } else {
10743 if (sockunion_same(&peer->su, su)) {
10744 find = 1;
10745 bgp_show_peer(vty, peer, use_json,
10746 json);
10747 break;
10748 }
10749 }
10750 }
10751 }
10752 break;
10753 case show_ipv4_all:
10754 case show_ipv6_all:
10755 FOREACH_SAFI (safi) {
10756 if (peer->afc[afi][safi]) {
10757 bgp_show_peer(vty, peer, use_json, json);
10758 break;
10759 }
10760 }
10761 break;
d62a17ae 10762 }
10763 }
10764
c5d6a9d8
KK
10765 if ((type == show_peer || type == show_ipv4_peer ||
10766 type == show_ipv6_peer) && !find) {
d62a17ae 10767 if (use_json)
10768 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10769 else
88b7d255 10770 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 10771 }
10772
10773 if (use_json) {
996c9314
LB
10774 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10775 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10776 } else {
10777 vty_out(vty, "\n");
10778 }
10779
10780 return CMD_SUCCESS;
10781}
10782
10783static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10784 enum show_type type,
10785 const char *ip_str,
d7c0a89a 10786 uint8_t use_json)
d62a17ae 10787{
0291c246
MK
10788 struct listnode *node, *nnode;
10789 struct bgp *bgp;
71aedaa3 10790 union sockunion su;
0291c246 10791 json_object *json = NULL;
71aedaa3 10792 int ret, is_first = 1;
d62a17ae 10793
10794 if (use_json)
10795 vty_out(vty, "{\n");
10796
10797 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10798 if (use_json) {
10799 if (!(json = json_object_new_object())) {
af4c2728 10800 flog_err(
14454c9f 10801 BGP_ERR_JSON_MEM_ERROR,
d62a17ae 10802 "Unable to allocate memory for JSON object");
10803 vty_out(vty,
10804 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10805 return;
10806 }
10807
10808 json_object_int_add(json, "vrfId",
10809 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10810 ? -1
10811 : (int64_t)bgp->vrf_id);
d62a17ae 10812 json_object_string_add(
10813 json, "vrfName",
10814 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10815 ? "Default"
10816 : bgp->name);
10817
10818 if (!is_first)
10819 vty_out(vty, ",\n");
10820 else
10821 is_first = 0;
10822
10823 vty_out(vty, "\"%s\":",
10824 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10825 ? "Default"
10826 : bgp->name);
10827 } else {
10828 vty_out(vty, "\nInstance %s:\n",
10829 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10830 ? "Default"
10831 : bgp->name);
10832 }
71aedaa3 10833
c5d6a9d8
KK
10834 if (type == show_peer || type == show_ipv4_peer ||
10835 type == show_ipv6_peer) {
71aedaa3
DS
10836 ret = str2sockunion(ip_str, &su);
10837 if (ret < 0)
10838 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10839 use_json, json);
10840 else
10841 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10842 use_json, json);
10843 } else {
c5d6a9d8 10844 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
10845 use_json, json);
10846 }
d62a17ae 10847 }
10848
f26dca2b 10849 if (use_json) {
d62a17ae 10850 vty_out(vty, "}\n");
f26dca2b
QY
10851 json_object_free(json);
10852 }
d62a17ae 10853}
10854
10855static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10856 enum show_type type, const char *ip_str,
d7c0a89a 10857 uint8_t use_json)
d62a17ae 10858{
10859 int ret;
10860 struct bgp *bgp;
10861 union sockunion su;
10862 json_object *json = NULL;
10863
10864 if (name) {
10865 if (strmatch(name, "all")) {
71aedaa3
DS
10866 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10867 use_json);
d62a17ae 10868 return CMD_SUCCESS;
10869 } else {
10870 bgp = bgp_lookup_by_name(name);
10871 if (!bgp) {
10872 if (use_json) {
10873 json = json_object_new_object();
10874 json_object_boolean_true_add(
10875 json, "bgpNoSuchInstance");
10876 vty_out(vty, "%s\n",
10877 json_object_to_json_string_ext(
10878 json,
10879 JSON_C_TO_STRING_PRETTY));
10880 json_object_free(json);
10881 } else
10882 vty_out(vty,
10883 "%% No such BGP instance exist\n");
10884
10885 return CMD_WARNING;
10886 }
10887 }
10888 } else {
10889 bgp = bgp_get_default();
10890 }
10891
10892 if (bgp) {
10893 json = json_object_new_object();
10894 if (ip_str) {
10895 ret = str2sockunion(ip_str, &su);
10896 if (ret < 0)
10897 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10898 use_json, json);
10899 else
10900 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10901 use_json, json);
10902 } else {
10903 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10904 json);
10905 }
10906 json_object_free(json);
10907 }
10908
10909 return CMD_SUCCESS;
4fb25c53
DW
10910}
10911
716b2d8a 10912/* "show [ip] bgp neighbors" commands. */
718e3744 10913DEFUN (show_ip_bgp_neighbors,
10914 show_ip_bgp_neighbors_cmd,
24345e82 10915 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 10916 SHOW_STR
10917 IP_STR
10918 BGP_STR
f2a8972b 10919 BGP_INSTANCE_HELP_STR
8c3deaae
QY
10920 "Address Family\n"
10921 "Address Family\n"
718e3744 10922 "Detailed information on TCP and BGP neighbor connections\n"
10923 "Neighbor to display information about\n"
a80beece 10924 "Neighbor to display information about\n"
91d37724 10925 "Neighbor on BGP configured interface\n"
9973d184 10926 JSON_STR)
718e3744 10927{
d62a17ae 10928 char *vrf = NULL;
10929 char *sh_arg = NULL;
10930 enum show_type sh_type;
c5d6a9d8 10931 afi_t afi = AFI_MAX;
718e3744 10932
d7c0a89a 10933 uint8_t uj = use_json(argc, argv);
718e3744 10934
d62a17ae 10935 int idx = 0;
718e3744 10936
d62a17ae 10937 if (argv_find(argv, argc, "view", &idx)
10938 || argv_find(argv, argc, "vrf", &idx))
10939 vrf = argv[idx + 1]->arg;
718e3744 10940
d62a17ae 10941 idx++;
c5d6a9d8
KK
10942
10943 if (argv_find(argv, argc, "ipv4", &idx)) {
10944 sh_type = show_ipv4_all;
10945 afi = AFI_IP;
10946 } else if (argv_find(argv, argc, "ipv6", &idx)) {
10947 sh_type = show_ipv6_all;
10948 afi = AFI_IP6;
10949 } else {
10950 sh_type = show_all;
10951 }
10952
d62a17ae 10953 if (argv_find(argv, argc, "A.B.C.D", &idx)
10954 || argv_find(argv, argc, "X:X::X:X", &idx)
10955 || argv_find(argv, argc, "WORD", &idx)) {
10956 sh_type = show_peer;
10957 sh_arg = argv[idx]->arg;
c5d6a9d8
KK
10958 }
10959
10960 if (sh_type == show_peer && afi == AFI_IP) {
10961 sh_type = show_ipv4_peer;
10962 } else if (sh_type == show_peer && afi == AFI_IP6) {
10963 sh_type = show_ipv6_peer;
10964 }
856ca177 10965
d62a17ae 10966 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10967}
10968
716b2d8a 10969/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10970 paths' and `show ip mbgp paths'. Those functions results are the
10971 same.*/
f412b39a 10972DEFUN (show_ip_bgp_paths,
718e3744 10973 show_ip_bgp_paths_cmd,
46f296b4 10974 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10975 SHOW_STR
10976 IP_STR
10977 BGP_STR
46f296b4 10978 BGP_SAFI_HELP_STR
718e3744 10979 "Path information\n")
10980{
d62a17ae 10981 vty_out(vty, "Address Refcnt Path\n");
10982 aspath_print_all_vty(vty);
10983 return CMD_SUCCESS;
718e3744 10984}
10985
718e3744 10986#include "hash.h"
10987
d62a17ae 10988static void community_show_all_iterator(struct hash_backet *backet,
10989 struct vty *vty)
718e3744 10990{
d62a17ae 10991 struct community *com;
718e3744 10992
d62a17ae 10993 com = (struct community *)backet->data;
3f65c5b1 10994 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 10995 community_str(com, false));
718e3744 10996}
10997
10998/* Show BGP's community internal data. */
f412b39a 10999DEFUN (show_ip_bgp_community_info,
718e3744 11000 show_ip_bgp_community_info_cmd,
bec37ba5 11001 "show [ip] bgp community-info",
718e3744 11002 SHOW_STR
11003 IP_STR
11004 BGP_STR
11005 "List all bgp community information\n")
11006{
d62a17ae 11007 vty_out(vty, "Address Refcnt Community\n");
718e3744 11008
d62a17ae 11009 hash_iterate(community_hash(),
11010 (void (*)(struct hash_backet *,
11011 void *))community_show_all_iterator,
11012 vty);
718e3744 11013
d62a17ae 11014 return CMD_SUCCESS;
718e3744 11015}
11016
d62a17ae 11017static void lcommunity_show_all_iterator(struct hash_backet *backet,
11018 struct vty *vty)
57d187bc 11019{
d62a17ae 11020 struct lcommunity *lcom;
57d187bc 11021
d62a17ae 11022 lcom = (struct lcommunity *)backet->data;
3f65c5b1 11023 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 11024 lcommunity_str(lcom, false));
57d187bc
JS
11025}
11026
11027/* Show BGP's community internal data. */
11028DEFUN (show_ip_bgp_lcommunity_info,
11029 show_ip_bgp_lcommunity_info_cmd,
11030 "show ip bgp large-community-info",
11031 SHOW_STR
11032 IP_STR
11033 BGP_STR
11034 "List all bgp large-community information\n")
11035{
d62a17ae 11036 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 11037
d62a17ae 11038 hash_iterate(lcommunity_hash(),
11039 (void (*)(struct hash_backet *,
11040 void *))lcommunity_show_all_iterator,
11041 vty);
57d187bc 11042
d62a17ae 11043 return CMD_SUCCESS;
57d187bc
JS
11044}
11045
11046
f412b39a 11047DEFUN (show_ip_bgp_attr_info,
718e3744 11048 show_ip_bgp_attr_info_cmd,
bec37ba5 11049 "show [ip] bgp attribute-info",
718e3744 11050 SHOW_STR
11051 IP_STR
11052 BGP_STR
11053 "List all bgp attribute information\n")
11054{
d62a17ae 11055 attr_show_all(vty);
11056 return CMD_SUCCESS;
718e3744 11057}
6b0655a2 11058
53089bec 11059static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
b46dfd20 11060 afi_t afi, safi_t safi, uint8_t use_json)
53089bec 11061{
11062 struct bgp *bgp;
11063 struct listnode *node;
11064 char *vname;
11065 char buf1[INET6_ADDRSTRLEN];
11066 char *ecom_str;
11067 vpn_policy_direction_t dir;
11068
b46dfd20
DS
11069 if (use_json) {
11070 json_object *json = NULL;
11071 json_object *json_import_vrfs = NULL;
11072 json_object *json_export_vrfs = NULL;
11073
11074 json = json_object_new_object();
b46dfd20
DS
11075
11076 /* Provide context for the block */
11077 json_object_string_add(json, "vrf", name ? name : "default");
11078 json_object_string_add(json, "afiSafi",
11079 afi_safi_print(afi, safi));
11080
11081 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11082
53089bec 11083 if (!bgp) {
b46dfd20
DS
11084 json_object_boolean_true_add(json,
11085 "bgpNoSuchInstance");
11086 vty_out(vty, "%s\n",
11087 json_object_to_json_string_ext(
11088 json,
11089 JSON_C_TO_STRING_PRETTY));
11090 json_object_free(json);
11091
53089bec 11092 return CMD_WARNING;
11093 }
b46dfd20
DS
11094
11095 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11096 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11097 json_object_string_add(json, "importFromVrfs", "none");
11098 json_object_string_add(json, "importRts", "none");
11099 } else {
6ce24e52
DS
11100 json_import_vrfs = json_object_new_array();
11101
b46dfd20
DS
11102 for (ALL_LIST_ELEMENTS_RO(
11103 bgp->vpn_policy[afi].import_vrf,
11104 node, vname))
11105 json_object_array_add(json_import_vrfs,
11106 json_object_new_string(vname));
11107
11108 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11109 ecom_str = ecommunity_ecom2str(
11110 bgp->vpn_policy[afi].rtlist[dir],
11111 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11112 json_object_object_add(json, "importFromVrfs",
11113 json_import_vrfs);
11114 json_object_string_add(json, "importRts", ecom_str);
11115
11116 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11117 }
11118
11119 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11120 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11121 json_object_string_add(json, "exportToVrfs", "none");
11122 json_object_string_add(json, "routeDistinguisher",
11123 "none");
11124 json_object_string_add(json, "exportRts", "none");
11125 } else {
6ce24e52
DS
11126 json_export_vrfs = json_object_new_array();
11127
b46dfd20
DS
11128 for (ALL_LIST_ELEMENTS_RO(
11129 bgp->vpn_policy[afi].export_vrf,
11130 node, vname))
11131 json_object_array_add(json_export_vrfs,
11132 json_object_new_string(vname));
11133 json_object_object_add(json, "exportToVrfs",
11134 json_export_vrfs);
11135 json_object_string_add(json, "routeDistinguisher",
11136 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11137 buf1, RD_ADDRSTRLEN));
11138
11139 dir = BGP_VPN_POLICY_DIR_TOVPN;
11140 ecom_str = ecommunity_ecom2str(
11141 bgp->vpn_policy[afi].rtlist[dir],
11142 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11143 json_object_string_add(json, "exportRts", ecom_str);
11144
11145 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11146 }
11147
11148 vty_out(vty, "%s\n",
11149 json_object_to_json_string_ext(json,
11150 JSON_C_TO_STRING_PRETTY));
11151 json_object_free(json);
11152
53089bec 11153 } else {
b46dfd20
DS
11154 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11155
53089bec 11156 if (!bgp) {
b46dfd20 11157 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 11158 return CMD_WARNING;
11159 }
53089bec 11160
b46dfd20
DS
11161 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11162 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11163 vty_out(vty,
11164 "This VRF is not importing %s routes from any other VRF\n",
11165 afi_safi_print(afi, safi));
11166 else {
11167 vty_out(vty,
11168 "This VRF is importing %s routes from the following VRFs:\n",
11169 afi_safi_print(afi, safi));
11170
11171 for (ALL_LIST_ELEMENTS_RO(
11172 bgp->vpn_policy[afi].import_vrf,
11173 node, vname))
11174 vty_out(vty, " %s\n", vname);
11175
11176 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11177 ecom_str = ecommunity_ecom2str(
11178 bgp->vpn_policy[afi].rtlist[dir],
11179 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11180 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11181
11182 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11183 }
53089bec 11184
b46dfd20
DS
11185 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11186 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11187 vty_out(vty,
11188 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11189 afi_safi_print(afi, safi));
b46dfd20
DS
11190 else {
11191 vty_out(vty,
04c9077f 11192 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11193 afi_safi_print(afi, safi));
b46dfd20
DS
11194
11195 for (ALL_LIST_ELEMENTS_RO(
11196 bgp->vpn_policy[afi].export_vrf,
11197 node, vname))
11198 vty_out(vty, " %s\n", vname);
11199
11200 vty_out(vty, "RD: %s\n",
11201 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11202 buf1, RD_ADDRSTRLEN));
11203
11204 dir = BGP_VPN_POLICY_DIR_TOVPN;
11205 ecom_str = ecommunity_ecom2str(
11206 bgp->vpn_policy[afi].rtlist[dir],
11207 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11208 vty_out(vty, "Export RT: %s\n", ecom_str);
04c9077f 11209 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11210 }
53089bec 11211 }
11212
11213 return CMD_SUCCESS;
11214}
11215
11216/* "show [ip] bgp route-leak" command. */
11217DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
11218 show_ip_bgp_route_leak_cmd,
11219 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
11220 SHOW_STR
11221 IP_STR
11222 BGP_STR
11223 BGP_INSTANCE_HELP_STR
11224 BGP_AFI_HELP_STR
11225 BGP_SAFI_HELP_STR
11226 "Route leaking information\n"
11227 JSON_STR)
53089bec 11228{
11229 char *vrf = NULL;
11230 afi_t afi = AFI_MAX;
11231 safi_t safi = SAFI_MAX;
11232
b46dfd20 11233 uint8_t uj = use_json(argc, argv);
53089bec 11234 int idx = 0;
11235
11236 /* show [ip] bgp */
11237 if (argv_find(argv, argc, "ip", &idx)) {
11238 afi = AFI_IP;
11239 safi = SAFI_UNICAST;
11240 }
11241 /* [vrf VIEWVRFNAME] */
11242 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11243 vty_out(vty,
11244 "%% This command is not applicable to BGP views\n");
53089bec 11245 return CMD_WARNING;
11246 }
11247
11248 if (argv_find(argv, argc, "vrf", &idx))
11249 vrf = argv[++idx]->arg;
11250 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11251 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11252 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11253 }
11254
11255 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11256 vty_out(vty,
11257 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11258 return CMD_WARNING;
11259 }
11260
b46dfd20 11261 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
53089bec 11262}
11263
d62a17ae 11264static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11265 safi_t safi)
f186de26 11266{
d62a17ae 11267 struct listnode *node, *nnode;
11268 struct bgp *bgp;
f186de26 11269
d62a17ae 11270 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11271 vty_out(vty, "\nInstance %s:\n",
11272 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11273 ? "Default"
11274 : bgp->name);
11275 update_group_show(bgp, afi, safi, vty, 0);
11276 }
f186de26 11277}
11278
d62a17ae 11279static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11280 int safi, uint64_t subgrp_id)
4fb25c53 11281{
d62a17ae 11282 struct bgp *bgp;
4fb25c53 11283
d62a17ae 11284 if (name) {
11285 if (strmatch(name, "all")) {
11286 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11287 return CMD_SUCCESS;
11288 } else {
11289 bgp = bgp_lookup_by_name(name);
11290 }
11291 } else {
11292 bgp = bgp_get_default();
11293 }
4fb25c53 11294
d62a17ae 11295 if (bgp)
11296 update_group_show(bgp, afi, safi, vty, subgrp_id);
11297 return CMD_SUCCESS;
4fb25c53
DW
11298}
11299
8fe8a7f6
DS
11300DEFUN (show_ip_bgp_updgrps,
11301 show_ip_bgp_updgrps_cmd,
c1a44e43 11302 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11303 SHOW_STR
11304 IP_STR
11305 BGP_STR
11306 BGP_INSTANCE_HELP_STR
c9e571b4 11307 BGP_AFI_HELP_STR
9bedbb1e 11308 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11309 "Detailed info about dynamic update groups\n"
11310 "Specific subgroup to display detailed info for\n")
8386ac43 11311{
d62a17ae 11312 char *vrf = NULL;
11313 afi_t afi = AFI_IP6;
11314 safi_t safi = SAFI_UNICAST;
11315 uint64_t subgrp_id = 0;
11316
11317 int idx = 0;
11318
11319 /* show [ip] bgp */
11320 if (argv_find(argv, argc, "ip", &idx))
11321 afi = AFI_IP;
11322 /* [<view|vrf> VIEWVRFNAME] */
11323 if (argv_find(argv, argc, "view", &idx)
11324 || argv_find(argv, argc, "vrf", &idx))
11325 vrf = argv[++idx]->arg;
11326 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11327 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11328 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11329 }
5bf15956 11330
d62a17ae 11331 /* get subgroup id, if provided */
11332 idx = argc - 1;
11333 if (argv[idx]->type == VARIABLE_TKN)
11334 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11335
d62a17ae 11336 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11337}
11338
f186de26 11339DEFUN (show_bgp_instance_all_ipv6_updgrps,
11340 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11341 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11342 SHOW_STR
716b2d8a 11343 IP_STR
f186de26 11344 BGP_STR
11345 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11346 "Detailed info about dynamic update groups\n")
f186de26 11347{
d62a17ae 11348 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11349 return CMD_SUCCESS;
f186de26 11350}
11351
5bf15956
DW
11352DEFUN (show_bgp_updgrps_stats,
11353 show_bgp_updgrps_stats_cmd,
716b2d8a 11354 "show [ip] bgp update-groups statistics",
3f9c7369 11355 SHOW_STR
716b2d8a 11356 IP_STR
3f9c7369 11357 BGP_STR
0c7b1b01 11358 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11359 "Statistics\n")
11360{
d62a17ae 11361 struct bgp *bgp;
3f9c7369 11362
d62a17ae 11363 bgp = bgp_get_default();
11364 if (bgp)
11365 update_group_show_stats(bgp, vty);
3f9c7369 11366
d62a17ae 11367 return CMD_SUCCESS;
3f9c7369
DS
11368}
11369
8386ac43 11370DEFUN (show_bgp_instance_updgrps_stats,
11371 show_bgp_instance_updgrps_stats_cmd,
18c57037 11372 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11373 SHOW_STR
716b2d8a 11374 IP_STR
8386ac43 11375 BGP_STR
11376 BGP_INSTANCE_HELP_STR
0c7b1b01 11377 "Detailed info about dynamic update groups\n"
8386ac43 11378 "Statistics\n")
11379{
d62a17ae 11380 int idx_word = 3;
11381 struct bgp *bgp;
8386ac43 11382
d62a17ae 11383 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11384 if (bgp)
11385 update_group_show_stats(bgp, vty);
8386ac43 11386
d62a17ae 11387 return CMD_SUCCESS;
8386ac43 11388}
11389
d62a17ae 11390static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11391 afi_t afi, safi_t safi,
11392 const char *what, uint64_t subgrp_id)
3f9c7369 11393{
d62a17ae 11394 struct bgp *bgp;
8386ac43 11395
d62a17ae 11396 if (name)
11397 bgp = bgp_lookup_by_name(name);
11398 else
11399 bgp = bgp_get_default();
8386ac43 11400
d62a17ae 11401 if (bgp) {
11402 if (!strcmp(what, "advertise-queue"))
11403 update_group_show_adj_queue(bgp, afi, safi, vty,
11404 subgrp_id);
11405 else if (!strcmp(what, "advertised-routes"))
11406 update_group_show_advertised(bgp, afi, safi, vty,
11407 subgrp_id);
11408 else if (!strcmp(what, "packet-queue"))
11409 update_group_show_packet_queue(bgp, afi, safi, vty,
11410 subgrp_id);
11411 }
3f9c7369
DS
11412}
11413
dc64bdec
QY
11414DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11415 show_ip_bgp_instance_updgrps_adj_s_cmd,
11416 "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",
11417 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11418 BGP_SAFI_HELP_STR
11419 "Detailed info about dynamic update groups\n"
11420 "Specific subgroup to display info for\n"
11421 "Advertisement queue\n"
11422 "Announced routes\n"
11423 "Packet queue\n")
3f9c7369 11424{
dc64bdec
QY
11425 uint64_t subgrp_id = 0;
11426 afi_t afiz;
11427 safi_t safiz;
11428 if (sgid)
11429 subgrp_id = strtoull(sgid, NULL, 10);
11430
11431 if (!ip && !afi)
11432 afiz = AFI_IP6;
11433 if (!ip && afi)
11434 afiz = bgp_vty_afi_from_str(afi);
11435 if (ip && !afi)
11436 afiz = AFI_IP;
11437 if (ip && afi) {
11438 afiz = bgp_vty_afi_from_str(afi);
11439 if (afiz != AFI_IP)
11440 vty_out(vty,
11441 "%% Cannot specify both 'ip' and 'ipv6'\n");
11442 return CMD_WARNING;
11443 }
d62a17ae 11444
dc64bdec 11445 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11446
dc64bdec 11447 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11448 return CMD_SUCCESS;
11449}
11450
d62a17ae 11451static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11452{
11453 struct listnode *node, *nnode;
11454 struct prefix *range;
11455 struct peer *conf;
11456 struct peer *peer;
11457 char buf[PREFIX2STR_BUFFER];
11458 afi_t afi;
11459 safi_t safi;
11460 const char *peer_status;
11461 const char *af_str;
11462 int lr_count;
11463 int dynamic;
11464 int af_cfgd;
11465
11466 conf = group->conf;
11467
11468 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
759f6308
KK
11469 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11470 group->name, conf->as);
d62a17ae 11471 } else if (conf->as_type == AS_INTERNAL) {
759f6308
KK
11472 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11473 group->name, group->bgp->as);
d62a17ae 11474 } else {
11475 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11476 }
f14e6fdb 11477
d62a17ae 11478 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11479 vty_out(vty, " Peer-group type is internal\n");
11480 else
11481 vty_out(vty, " Peer-group type is external\n");
11482
11483 /* Display AFs configured. */
11484 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11485 FOREACH_AFI_SAFI (afi, safi) {
11486 if (conf->afc[afi][safi]) {
11487 af_cfgd = 1;
11488 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11489 }
05c7a1cc 11490 }
d62a17ae 11491 if (!af_cfgd)
11492 vty_out(vty, " none\n");
11493 else
11494 vty_out(vty, "\n");
11495
11496 /* Display listen ranges (for dynamic neighbors), if any */
11497 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11498 if (afi == AFI_IP)
11499 af_str = "IPv4";
11500 else if (afi == AFI_IP6)
11501 af_str = "IPv6";
11502 else
11503 af_str = "???";
11504 lr_count = listcount(group->listen_range[afi]);
11505 if (lr_count) {
11506 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11507 af_str);
11508
11509
11510 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11511 nnode, range)) {
11512 prefix2str(range, buf, sizeof(buf));
11513 vty_out(vty, " %s\n", buf);
11514 }
11515 }
11516 }
f14e6fdb 11517
d62a17ae 11518 /* Display group members and their status */
11519 if (listcount(group->peer)) {
11520 vty_out(vty, " Peer-group members:\n");
11521 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11522 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11523 peer_status = "Idle (Admin)";
11524 else if (CHECK_FLAG(peer->sflags,
11525 PEER_STATUS_PREFIX_OVERFLOW))
11526 peer_status = "Idle (PfxCt)";
11527 else
11528 peer_status = lookup_msg(bgp_status_msg,
11529 peer->status, NULL);
11530
11531 dynamic = peer_dynamic_neighbor(peer);
11532 vty_out(vty, " %s %s %s \n", peer->host,
11533 dynamic ? "(dynamic)" : "", peer_status);
11534 }
11535 }
f14e6fdb 11536
d62a17ae 11537 return CMD_SUCCESS;
11538}
11539
ff9959b0
QY
11540static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11541 const char *group_name)
d62a17ae 11542{
ff9959b0 11543 struct bgp *bgp;
d62a17ae 11544 struct listnode *node, *nnode;
11545 struct peer_group *group;
ff9959b0
QY
11546 bool found = false;
11547
11548 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11549
11550 if (!bgp) {
11551 vty_out(vty, "%% No such BGP instance exists\n");
11552 return CMD_WARNING;
11553 }
d62a17ae 11554
11555 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11556 if (group_name) {
11557 if (strmatch(group->name, group_name)) {
d62a17ae 11558 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11559 found = true;
11560 break;
d62a17ae 11561 }
ff9959b0
QY
11562 } else {
11563 bgp_show_one_peer_group(vty, group);
d62a17ae 11564 }
f14e6fdb 11565 }
f14e6fdb 11566
ff9959b0 11567 if (group_name && !found)
d62a17ae 11568 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11569
d62a17ae 11570 return CMD_SUCCESS;
f14e6fdb
DS
11571}
11572
f14e6fdb
DS
11573DEFUN (show_ip_bgp_peer_groups,
11574 show_ip_bgp_peer_groups_cmd,
18c57037 11575 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11576 SHOW_STR
11577 IP_STR
11578 BGP_STR
8386ac43 11579 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11580 "Detailed information on BGP peer groups\n"
11581 "Peer group name\n")
f14e6fdb 11582{
d62a17ae 11583 char *vrf, *pg;
d62a17ae 11584 int idx = 0;
f14e6fdb 11585
a4d82a8a
PZ
11586 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11587 : NULL;
d62a17ae 11588 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11589
ff9959b0 11590 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11591}
3f9c7369 11592
d6e3c605 11593
718e3744 11594/* Redistribute VTY commands. */
11595
718e3744 11596DEFUN (bgp_redistribute_ipv4,
11597 bgp_redistribute_ipv4_cmd,
40d1cbfb 11598 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11599 "Redistribute information from another routing protocol\n"
ab0181ee 11600 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11601{
d62a17ae 11602 VTY_DECLVAR_CONTEXT(bgp, bgp);
11603 int idx_protocol = 1;
11604 int type;
718e3744 11605
d62a17ae 11606 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11607 if (type < 0) {
11608 vty_out(vty, "%% Invalid route type\n");
11609 return CMD_WARNING_CONFIG_FAILED;
11610 }
7f323236 11611
d62a17ae 11612 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11613 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 11614}
11615
d62a17ae 11616ALIAS_HIDDEN(
11617 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11618 "redistribute " FRR_IP_REDIST_STR_BGPD,
11619 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11620
718e3744 11621DEFUN (bgp_redistribute_ipv4_rmap,
11622 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11623 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11624 "Redistribute information from another routing protocol\n"
ab0181ee 11625 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11626 "Route map reference\n"
11627 "Pointer to route-map entries\n")
11628{
d62a17ae 11629 VTY_DECLVAR_CONTEXT(bgp, bgp);
11630 int idx_protocol = 1;
11631 int idx_word = 3;
11632 int type;
11633 struct bgp_redist *red;
e923dd62 11634 bool changed;
718e3744 11635
d62a17ae 11636 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11637 if (type < 0) {
11638 vty_out(vty, "%% Invalid route type\n");
11639 return CMD_WARNING_CONFIG_FAILED;
11640 }
718e3744 11641
d62a17ae 11642 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11643 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11644 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 11645}
11646
d62a17ae 11647ALIAS_HIDDEN(
11648 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11649 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11650 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11651 "Route map reference\n"
11652 "Pointer to route-map entries\n")
596c17ba 11653
718e3744 11654DEFUN (bgp_redistribute_ipv4_metric,
11655 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11656 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11657 "Redistribute information from another routing protocol\n"
ab0181ee 11658 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11659 "Metric for redistributed routes\n"
11660 "Default metric\n")
11661{
d62a17ae 11662 VTY_DECLVAR_CONTEXT(bgp, bgp);
11663 int idx_protocol = 1;
11664 int idx_number = 3;
11665 int type;
d7c0a89a 11666 uint32_t metric;
d62a17ae 11667 struct bgp_redist *red;
e923dd62 11668 bool changed;
d62a17ae 11669
11670 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11671 if (type < 0) {
11672 vty_out(vty, "%% Invalid route type\n");
11673 return CMD_WARNING_CONFIG_FAILED;
11674 }
11675 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11676
11677 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11678 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11679 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11680}
11681
11682ALIAS_HIDDEN(
11683 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11684 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11685 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11686 "Metric for redistributed routes\n"
11687 "Default metric\n")
596c17ba 11688
718e3744 11689DEFUN (bgp_redistribute_ipv4_rmap_metric,
11690 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11691 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11692 "Redistribute information from another routing protocol\n"
ab0181ee 11693 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11694 "Route map reference\n"
11695 "Pointer to route-map entries\n"
11696 "Metric for redistributed routes\n"
11697 "Default metric\n")
11698{
d62a17ae 11699 VTY_DECLVAR_CONTEXT(bgp, bgp);
11700 int idx_protocol = 1;
11701 int idx_word = 3;
11702 int idx_number = 5;
11703 int type;
d7c0a89a 11704 uint32_t metric;
d62a17ae 11705 struct bgp_redist *red;
e923dd62 11706 bool changed;
d62a17ae 11707
11708 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11709 if (type < 0) {
11710 vty_out(vty, "%% Invalid route type\n");
11711 return CMD_WARNING_CONFIG_FAILED;
11712 }
11713 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11714
11715 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11716 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11717 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11718 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11719}
11720
11721ALIAS_HIDDEN(
11722 bgp_redistribute_ipv4_rmap_metric,
11723 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11724 "redistribute " FRR_IP_REDIST_STR_BGPD
11725 " route-map WORD metric (0-4294967295)",
11726 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11727 "Route map reference\n"
11728 "Pointer to route-map entries\n"
11729 "Metric for redistributed routes\n"
11730 "Default metric\n")
596c17ba 11731
718e3744 11732DEFUN (bgp_redistribute_ipv4_metric_rmap,
11733 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11734 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11735 "Redistribute information from another routing protocol\n"
ab0181ee 11736 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11737 "Metric for redistributed routes\n"
11738 "Default metric\n"
11739 "Route map reference\n"
11740 "Pointer to route-map entries\n")
11741{
d62a17ae 11742 VTY_DECLVAR_CONTEXT(bgp, bgp);
11743 int idx_protocol = 1;
11744 int idx_number = 3;
11745 int idx_word = 5;
11746 int type;
d7c0a89a 11747 uint32_t metric;
d62a17ae 11748 struct bgp_redist *red;
e923dd62 11749 bool changed;
d62a17ae 11750
11751 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11752 if (type < 0) {
11753 vty_out(vty, "%% Invalid route type\n");
11754 return CMD_WARNING_CONFIG_FAILED;
11755 }
11756 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11757
11758 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11759 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11760 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11761 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11762}
11763
11764ALIAS_HIDDEN(
11765 bgp_redistribute_ipv4_metric_rmap,
11766 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11767 "redistribute " FRR_IP_REDIST_STR_BGPD
11768 " metric (0-4294967295) route-map WORD",
11769 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11770 "Metric for redistributed routes\n"
11771 "Default metric\n"
11772 "Route map reference\n"
11773 "Pointer to route-map entries\n")
596c17ba 11774
7c8ff89e
DS
11775DEFUN (bgp_redistribute_ipv4_ospf,
11776 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11777 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11778 "Redistribute information from another routing protocol\n"
11779 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11780 "Non-main Kernel Routing Table\n"
11781 "Instance ID/Table ID\n")
7c8ff89e 11782{
d62a17ae 11783 VTY_DECLVAR_CONTEXT(bgp, bgp);
11784 int idx_ospf_table = 1;
11785 int idx_number = 2;
d7c0a89a
QY
11786 unsigned short instance;
11787 unsigned short protocol;
7c8ff89e 11788
d62a17ae 11789 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11790
d62a17ae 11791 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11792 protocol = ZEBRA_ROUTE_OSPF;
11793 else
11794 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11795
d62a17ae 11796 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11797 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
11798}
11799
d62a17ae 11800ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11801 "redistribute <ospf|table> (1-65535)",
11802 "Redistribute information from another routing protocol\n"
11803 "Open Shortest Path First (OSPFv2)\n"
11804 "Non-main Kernel Routing Table\n"
11805 "Instance ID/Table ID\n")
596c17ba 11806
7c8ff89e
DS
11807DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11808 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11809 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11810 "Redistribute information from another routing protocol\n"
11811 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11812 "Non-main Kernel Routing Table\n"
11813 "Instance ID/Table ID\n"
7c8ff89e
DS
11814 "Route map reference\n"
11815 "Pointer to route-map entries\n")
11816{
d62a17ae 11817 VTY_DECLVAR_CONTEXT(bgp, bgp);
11818 int idx_ospf_table = 1;
11819 int idx_number = 2;
11820 int idx_word = 4;
11821 struct bgp_redist *red;
d7c0a89a 11822 unsigned short instance;
d62a17ae 11823 int protocol;
e923dd62 11824 bool changed;
d62a17ae 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 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11833 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11834 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11835}
11836
11837ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11838 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11839 "redistribute <ospf|table> (1-65535) route-map WORD",
11840 "Redistribute information from another routing protocol\n"
11841 "Open Shortest Path First (OSPFv2)\n"
11842 "Non-main Kernel Routing Table\n"
11843 "Instance ID/Table ID\n"
11844 "Route map reference\n"
11845 "Pointer to route-map entries\n")
596c17ba 11846
7c8ff89e
DS
11847DEFUN (bgp_redistribute_ipv4_ospf_metric,
11848 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 11849 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
11850 "Redistribute information from another routing protocol\n"
11851 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11852 "Non-main Kernel Routing Table\n"
11853 "Instance ID/Table ID\n"
7c8ff89e
DS
11854 "Metric for redistributed routes\n"
11855 "Default metric\n")
11856{
d62a17ae 11857 VTY_DECLVAR_CONTEXT(bgp, bgp);
11858 int idx_ospf_table = 1;
11859 int idx_number = 2;
11860 int idx_number_2 = 4;
d7c0a89a 11861 uint32_t metric;
d62a17ae 11862 struct bgp_redist *red;
d7c0a89a 11863 unsigned short instance;
d62a17ae 11864 int protocol;
e923dd62 11865 bool changed;
d62a17ae 11866
11867 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11868 protocol = ZEBRA_ROUTE_OSPF;
11869 else
11870 protocol = ZEBRA_ROUTE_TABLE;
11871
11872 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11873 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11874
11875 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11876 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11877 metric);
11878 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11879}
11880
11881ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11882 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11883 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11884 "Redistribute information from another routing protocol\n"
11885 "Open Shortest Path First (OSPFv2)\n"
11886 "Non-main Kernel Routing Table\n"
11887 "Instance ID/Table ID\n"
11888 "Metric for redistributed routes\n"
11889 "Default metric\n")
596c17ba 11890
7c8ff89e
DS
11891DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11892 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 11893 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
11894 "Redistribute information from another routing protocol\n"
11895 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11896 "Non-main Kernel Routing Table\n"
11897 "Instance ID/Table ID\n"
7c8ff89e
DS
11898 "Route map reference\n"
11899 "Pointer to route-map entries\n"
11900 "Metric for redistributed routes\n"
11901 "Default metric\n")
11902{
d62a17ae 11903 VTY_DECLVAR_CONTEXT(bgp, bgp);
11904 int idx_ospf_table = 1;
11905 int idx_number = 2;
11906 int idx_word = 4;
11907 int idx_number_2 = 6;
d7c0a89a 11908 uint32_t metric;
d62a17ae 11909 struct bgp_redist *red;
d7c0a89a 11910 unsigned short instance;
d62a17ae 11911 int protocol;
e923dd62 11912 bool changed;
d62a17ae 11913
11914 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11915 protocol = ZEBRA_ROUTE_OSPF;
11916 else
11917 protocol = ZEBRA_ROUTE_TABLE;
11918
11919 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11920 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11921
11922 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11923 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11924 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11925 metric);
11926 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11927}
11928
11929ALIAS_HIDDEN(
11930 bgp_redistribute_ipv4_ospf_rmap_metric,
11931 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11932 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11933 "Redistribute information from another routing protocol\n"
11934 "Open Shortest Path First (OSPFv2)\n"
11935 "Non-main Kernel Routing Table\n"
11936 "Instance ID/Table ID\n"
11937 "Route map reference\n"
11938 "Pointer to route-map entries\n"
11939 "Metric for redistributed routes\n"
11940 "Default metric\n")
596c17ba 11941
7c8ff89e
DS
11942DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11943 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 11944 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
11945 "Redistribute information from another routing protocol\n"
11946 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11947 "Non-main Kernel Routing Table\n"
11948 "Instance ID/Table ID\n"
7c8ff89e
DS
11949 "Metric for redistributed routes\n"
11950 "Default metric\n"
11951 "Route map reference\n"
11952 "Pointer to route-map entries\n")
11953{
d62a17ae 11954 VTY_DECLVAR_CONTEXT(bgp, bgp);
11955 int idx_ospf_table = 1;
11956 int idx_number = 2;
11957 int idx_number_2 = 4;
11958 int idx_word = 6;
d7c0a89a 11959 uint32_t metric;
d62a17ae 11960 struct bgp_redist *red;
d7c0a89a 11961 unsigned short instance;
d62a17ae 11962 int protocol;
e923dd62 11963 bool changed;
d62a17ae 11964
11965 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11966 protocol = ZEBRA_ROUTE_OSPF;
11967 else
11968 protocol = ZEBRA_ROUTE_TABLE;
11969
11970 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11971 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11972
11973 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11974 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11975 metric);
11976 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11977 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11978}
11979
11980ALIAS_HIDDEN(
11981 bgp_redistribute_ipv4_ospf_metric_rmap,
11982 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11983 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11984 "Redistribute information from another routing protocol\n"
11985 "Open Shortest Path First (OSPFv2)\n"
11986 "Non-main Kernel Routing Table\n"
11987 "Instance ID/Table ID\n"
11988 "Metric for redistributed routes\n"
11989 "Default metric\n"
11990 "Route map reference\n"
11991 "Pointer to route-map entries\n")
596c17ba 11992
7c8ff89e
DS
11993DEFUN (no_bgp_redistribute_ipv4_ospf,
11994 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 11995 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
11996 NO_STR
11997 "Redistribute information from another routing protocol\n"
11998 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 11999 "Non-main Kernel Routing Table\n"
31500417
DW
12000 "Instance ID/Table ID\n"
12001 "Metric for redistributed routes\n"
12002 "Default metric\n"
12003 "Route map reference\n"
12004 "Pointer to route-map entries\n")
7c8ff89e 12005{
d62a17ae 12006 VTY_DECLVAR_CONTEXT(bgp, bgp);
12007 int idx_ospf_table = 2;
12008 int idx_number = 3;
d7c0a89a 12009 unsigned short instance;
d62a17ae 12010 int protocol;
12011
12012 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12013 protocol = ZEBRA_ROUTE_OSPF;
12014 else
12015 protocol = ZEBRA_ROUTE_TABLE;
12016
12017 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12018 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12019}
12020
12021ALIAS_HIDDEN(
12022 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12023 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12024 NO_STR
12025 "Redistribute information from another routing protocol\n"
12026 "Open Shortest Path First (OSPFv2)\n"
12027 "Non-main Kernel Routing Table\n"
12028 "Instance ID/Table ID\n"
12029 "Metric for redistributed routes\n"
12030 "Default metric\n"
12031 "Route map reference\n"
12032 "Pointer to route-map entries\n")
596c17ba 12033
718e3744 12034DEFUN (no_bgp_redistribute_ipv4,
12035 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 12036 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12037 NO_STR
12038 "Redistribute information from another routing protocol\n"
3b14d86e 12039 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
12040 "Metric for redistributed routes\n"
12041 "Default metric\n"
12042 "Route map reference\n"
12043 "Pointer to route-map entries\n")
718e3744 12044{
d62a17ae 12045 VTY_DECLVAR_CONTEXT(bgp, bgp);
12046 int idx_protocol = 2;
12047 int type;
12048
12049 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12050 if (type < 0) {
12051 vty_out(vty, "%% Invalid route type\n");
12052 return CMD_WARNING_CONFIG_FAILED;
12053 }
12054 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12055}
12056
12057ALIAS_HIDDEN(
12058 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12059 "no redistribute " FRR_IP_REDIST_STR_BGPD
12060 " [metric (0-4294967295)] [route-map WORD]",
12061 NO_STR
12062 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12063 "Metric for redistributed routes\n"
12064 "Default metric\n"
12065 "Route map reference\n"
12066 "Pointer to route-map entries\n")
596c17ba 12067
718e3744 12068DEFUN (bgp_redistribute_ipv6,
12069 bgp_redistribute_ipv6_cmd,
40d1cbfb 12070 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 12071 "Redistribute information from another routing protocol\n"
ab0181ee 12072 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 12073{
d62a17ae 12074 VTY_DECLVAR_CONTEXT(bgp, bgp);
12075 int idx_protocol = 1;
12076 int type;
718e3744 12077
d62a17ae 12078 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12079 if (type < 0) {
12080 vty_out(vty, "%% Invalid route type\n");
12081 return CMD_WARNING_CONFIG_FAILED;
12082 }
718e3744 12083
d62a17ae 12084 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12085 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 12086}
12087
12088DEFUN (bgp_redistribute_ipv6_rmap,
12089 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 12090 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 12091 "Redistribute information from another routing protocol\n"
ab0181ee 12092 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12093 "Route map reference\n"
12094 "Pointer to route-map entries\n")
12095{
d62a17ae 12096 VTY_DECLVAR_CONTEXT(bgp, bgp);
12097 int idx_protocol = 1;
12098 int idx_word = 3;
12099 int type;
12100 struct bgp_redist *red;
e923dd62 12101 bool changed;
718e3744 12102
d62a17ae 12103 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12104 if (type < 0) {
12105 vty_out(vty, "%% Invalid route type\n");
12106 return CMD_WARNING_CONFIG_FAILED;
12107 }
718e3744 12108
d62a17ae 12109 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12110 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12111 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12112}
12113
12114DEFUN (bgp_redistribute_ipv6_metric,
12115 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 12116 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12117 "Redistribute information from another routing protocol\n"
ab0181ee 12118 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12119 "Metric for redistributed routes\n"
12120 "Default metric\n")
12121{
d62a17ae 12122 VTY_DECLVAR_CONTEXT(bgp, bgp);
12123 int idx_protocol = 1;
12124 int idx_number = 3;
12125 int type;
d7c0a89a 12126 uint32_t metric;
d62a17ae 12127 struct bgp_redist *red;
e923dd62 12128 bool changed;
d62a17ae 12129
12130 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12131 if (type < 0) {
12132 vty_out(vty, "%% Invalid route type\n");
12133 return CMD_WARNING_CONFIG_FAILED;
12134 }
12135 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12136
d62a17ae 12137 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12138 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12139 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12140}
12141
12142DEFUN (bgp_redistribute_ipv6_rmap_metric,
12143 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 12144 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12145 "Redistribute information from another routing protocol\n"
ab0181ee 12146 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12147 "Route map reference\n"
12148 "Pointer to route-map entries\n"
12149 "Metric for redistributed routes\n"
12150 "Default metric\n")
12151{
d62a17ae 12152 VTY_DECLVAR_CONTEXT(bgp, bgp);
12153 int idx_protocol = 1;
12154 int idx_word = 3;
12155 int idx_number = 5;
12156 int type;
d7c0a89a 12157 uint32_t metric;
d62a17ae 12158 struct bgp_redist *red;
e923dd62 12159 bool changed;
d62a17ae 12160
12161 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12162 if (type < 0) {
12163 vty_out(vty, "%% Invalid route type\n");
12164 return CMD_WARNING_CONFIG_FAILED;
12165 }
12166 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12167
d62a17ae 12168 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12169 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12170 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12171 metric);
12172 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12173}
12174
12175DEFUN (bgp_redistribute_ipv6_metric_rmap,
12176 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 12177 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12178 "Redistribute information from another routing protocol\n"
ab0181ee 12179 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12180 "Metric for redistributed routes\n"
12181 "Default metric\n"
12182 "Route map reference\n"
12183 "Pointer to route-map entries\n")
12184{
d62a17ae 12185 VTY_DECLVAR_CONTEXT(bgp, bgp);
12186 int idx_protocol = 1;
12187 int idx_number = 3;
12188 int idx_word = 5;
12189 int type;
d7c0a89a 12190 uint32_t metric;
d62a17ae 12191 struct bgp_redist *red;
e923dd62 12192 bool changed;
d62a17ae 12193
12194 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12195 if (type < 0) {
12196 vty_out(vty, "%% Invalid route type\n");
12197 return CMD_WARNING_CONFIG_FAILED;
12198 }
12199 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12200
d62a17ae 12201 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12202 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12203 metric);
12204 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12205 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12206}
12207
12208DEFUN (no_bgp_redistribute_ipv6,
12209 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 12210 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12211 NO_STR
12212 "Redistribute information from another routing protocol\n"
3b14d86e 12213 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12214 "Metric for redistributed routes\n"
12215 "Default metric\n"
12216 "Route map reference\n"
12217 "Pointer to route-map entries\n")
718e3744 12218{
d62a17ae 12219 VTY_DECLVAR_CONTEXT(bgp, bgp);
12220 int idx_protocol = 2;
12221 int type;
718e3744 12222
d62a17ae 12223 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12224 if (type < 0) {
12225 vty_out(vty, "%% Invalid route type\n");
12226 return CMD_WARNING_CONFIG_FAILED;
12227 }
718e3744 12228
d62a17ae 12229 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12230}
12231
2b791107 12232void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12233 safi_t safi)
d62a17ae 12234{
12235 int i;
12236
12237 /* Unicast redistribution only. */
12238 if (safi != SAFI_UNICAST)
2b791107 12239 return;
d62a17ae 12240
12241 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12242 /* Redistribute BGP does not make sense. */
12243 if (i != ZEBRA_ROUTE_BGP) {
12244 struct list *red_list;
12245 struct listnode *node;
12246 struct bgp_redist *red;
12247
12248 red_list = bgp->redist[afi][i];
12249 if (!red_list)
12250 continue;
12251
12252 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12253 /* "redistribute" configuration. */
12254 vty_out(vty, " redistribute %s",
12255 zebra_route_string(i));
12256 if (red->instance)
12257 vty_out(vty, " %d", red->instance);
12258 if (red->redist_metric_flag)
12259 vty_out(vty, " metric %u",
12260 red->redist_metric);
12261 if (red->rmap.name)
12262 vty_out(vty, " route-map %s",
12263 red->rmap.name);
12264 vty_out(vty, "\n");
12265 }
12266 }
12267 }
718e3744 12268}
6b0655a2 12269
b9c7bc5a
PZ
12270/* This is part of the address-family block (unicast only) */
12271void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12272 afi_t afi)
12273{
b9c7bc5a 12274 int indent = 2;
ddb5b488 12275
bb4f6190
DS
12276 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12277 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12278 bgp->vpn_policy[afi]
12279 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12280
12a844a5
DS
12281 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12282 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12283 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12284 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12285 return;
12286
e70e9f8e
PZ
12287 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12288 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12289
12290 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12291
12292 } else {
12293 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12294 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12295 bgp->vpn_policy[afi].tovpn_label);
12296 }
ddb5b488
PZ
12297 }
12298 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12299 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12300 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12301 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12302 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12303 sizeof(buf)));
12304 }
12305 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12306 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12307
12308 char buf[PREFIX_STRLEN];
12309 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12310 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12311 sizeof(buf))) {
12312
b9c7bc5a
PZ
12313 vty_out(vty, "%*snexthop vpn export %s\n",
12314 indent, "", buf);
ddb5b488
PZ
12315 }
12316 }
12317 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12318 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12319 && ecommunity_cmp(
12320 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12321 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12322
12323 char *b = ecommunity_ecom2str(
12324 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12325 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12326 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12327 XFREE(MTYPE_ECOMMUNITY_STR, b);
12328 } else {
12329 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12330 char *b = ecommunity_ecom2str(
12331 bgp->vpn_policy[afi]
12332 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12333 ECOMMUNITY_FORMAT_ROUTE_MAP,
12334 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12335 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12336 XFREE(MTYPE_ECOMMUNITY_STR, b);
12337 }
12338 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12339 char *b = ecommunity_ecom2str(
12340 bgp->vpn_policy[afi]
12341 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12342 ECOMMUNITY_FORMAT_ROUTE_MAP,
12343 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12344 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12345 XFREE(MTYPE_ECOMMUNITY_STR, b);
12346 }
12347 }
bb4f6190
DS
12348
12349 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12350 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12351 bgp->vpn_policy[afi]
12352 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12353
301ad80a
PG
12354 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12355 char *b = ecommunity_ecom2str(
12356 bgp->vpn_policy[afi]
12357 .import_redirect_rtlist,
12358 ECOMMUNITY_FORMAT_ROUTE_MAP,
12359 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12360
301ad80a
PG
12361 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12362 XFREE(MTYPE_ECOMMUNITY_STR, b);
12363 }
ddb5b488
PZ
12364}
12365
12366
718e3744 12367/* BGP node structure. */
d62a17ae 12368static struct cmd_node bgp_node = {
9d303b37 12369 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12370};
12371
d62a17ae 12372static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12373 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12374};
12375
d62a17ae 12376static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12377 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12378};
12379
d62a17ae 12380static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12381 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12382};
12383
d62a17ae 12384static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12385 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12386};
12387
d62a17ae 12388static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12389 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12390};
12391
d62a17ae 12392static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12393 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12394};
12395
d62a17ae 12396static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12397 "%s(config-router-af)# ", 1};
6b0655a2 12398
d62a17ae 12399static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12400 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12401
d62a17ae 12402static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12403 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12404
d62a17ae 12405static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12406 "%s(config-router-af-vni)# ", 1};
90e60aa7 12407
7c40bf39 12408static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12409 "%s(config-router-af)# ", 1};
12410
12411static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12412 "%s(config-router-af-vpnv6)# ", 1};
12413
d62a17ae 12414static void community_list_vty(void);
1f8ae70b 12415
d62a17ae 12416static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12417{
d62a17ae 12418 struct bgp *bgp;
12419 struct peer *peer;
d62a17ae 12420 struct listnode *lnbgp, *lnpeer;
b8a815e5 12421
d62a17ae 12422 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12423 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12424 /* only provide suggestions on the appropriate input
12425 * token type,
12426 * they'll otherwise show up multiple times */
12427 enum cmd_token_type match_type;
12428 char *name = peer->host;
d48ed3e0 12429
d62a17ae 12430 if (peer->conf_if) {
12431 match_type = VARIABLE_TKN;
12432 name = peer->conf_if;
12433 } else if (strchr(peer->host, ':'))
12434 match_type = IPV6_TKN;
12435 else
12436 match_type = IPV4_TKN;
d48ed3e0 12437
d62a17ae 12438 if (token->type != match_type)
12439 continue;
d48ed3e0 12440
d62a17ae 12441 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12442 }
d62a17ae 12443 }
b8a815e5
DL
12444}
12445
12446static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12447 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12448 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12449 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12450 {.completions = NULL}};
12451
47a306a0
DS
12452static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12453{
12454 struct bgp *bgp;
12455 struct peer_group *group;
12456 struct listnode *lnbgp, *lnpeer;
12457
12458 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12459 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12460 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12461 group->name));
12462 }
12463}
12464
12465static const struct cmd_variable_handler bgp_var_peergroup[] = {
12466 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12467 {.completions = NULL} };
12468
d62a17ae 12469void bgp_vty_init(void)
12470{
12471 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12472 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12473
12474 /* Install bgp top node. */
12475 install_node(&bgp_node, bgp_config_write);
12476 install_node(&bgp_ipv4_unicast_node, NULL);
12477 install_node(&bgp_ipv4_multicast_node, NULL);
12478 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12479 install_node(&bgp_ipv6_unicast_node, NULL);
12480 install_node(&bgp_ipv6_multicast_node, NULL);
12481 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12482 install_node(&bgp_vpnv4_node, NULL);
12483 install_node(&bgp_vpnv6_node, NULL);
12484 install_node(&bgp_evpn_node, NULL);
12485 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12486 install_node(&bgp_flowspecv4_node, NULL);
12487 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12488
12489 /* Install default VTY commands to new nodes. */
12490 install_default(BGP_NODE);
12491 install_default(BGP_IPV4_NODE);
12492 install_default(BGP_IPV4M_NODE);
12493 install_default(BGP_IPV4L_NODE);
12494 install_default(BGP_IPV6_NODE);
12495 install_default(BGP_IPV6M_NODE);
12496 install_default(BGP_IPV6L_NODE);
12497 install_default(BGP_VPNV4_NODE);
12498 install_default(BGP_VPNV6_NODE);
7c40bf39 12499 install_default(BGP_FLOWSPECV4_NODE);
12500 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12501 install_default(BGP_EVPN_NODE);
12502 install_default(BGP_EVPN_VNI_NODE);
12503
12504 /* "bgp multiple-instance" commands. */
12505 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12506 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12507
12508 /* "bgp config-type" commands. */
12509 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12510 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12511
12512 /* bgp route-map delay-timer commands. */
12513 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12514 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12515
12516 /* Dummy commands (Currently not supported) */
12517 install_element(BGP_NODE, &no_synchronization_cmd);
12518 install_element(BGP_NODE, &no_auto_summary_cmd);
12519
12520 /* "router bgp" commands. */
12521 install_element(CONFIG_NODE, &router_bgp_cmd);
12522
12523 /* "no router bgp" commands. */
12524 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12525
12526 /* "bgp router-id" commands. */
12527 install_element(BGP_NODE, &bgp_router_id_cmd);
12528 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12529
12530 /* "bgp cluster-id" commands. */
12531 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12532 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12533
12534 /* "bgp confederation" commands. */
12535 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12536 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12537
12538 /* "bgp confederation peers" commands. */
12539 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12540 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12541
12542 /* bgp max-med command */
12543 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12544 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12545 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12546 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12547 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12548
12549 /* bgp disable-ebgp-connected-nh-check */
12550 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12551 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12552
12553 /* bgp update-delay command */
12554 install_element(BGP_NODE, &bgp_update_delay_cmd);
12555 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12556 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12557
12558 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12559 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12560 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12561 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12562
12563 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12564 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12565
12566 /* "maximum-paths" commands. */
12567 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12568 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12569 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12570 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12571 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12572 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12573 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12574 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12575 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12576 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12577 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12578 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12579 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12580 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12581 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12582
12583 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12584 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12585 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12586 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12587 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12588
12589 /* "timers bgp" commands. */
12590 install_element(BGP_NODE, &bgp_timers_cmd);
12591 install_element(BGP_NODE, &no_bgp_timers_cmd);
12592
12593 /* route-map delay-timer commands - per instance for backwards compat.
12594 */
12595 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12596 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12597
12598 /* "bgp client-to-client reflection" commands */
12599 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12600 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12601
12602 /* "bgp always-compare-med" commands */
12603 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12604 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12605
12606 /* "bgp deterministic-med" commands */
12607 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12608 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12609
12610 /* "bgp graceful-restart" commands */
12611 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12612 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12613 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12614 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12615 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12616 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12617
12618 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12619 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12620
7f323236
DW
12621 /* "bgp graceful-shutdown" commands */
12622 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12623 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12624
d62a17ae 12625 /* "bgp fast-external-failover" commands */
12626 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12627 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12628
12629 /* "bgp enforce-first-as" commands */
12630 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
d62a17ae 12631
12632 /* "bgp bestpath compare-routerid" commands */
12633 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12634 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12635
12636 /* "bgp bestpath as-path ignore" commands */
12637 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12638 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12639
12640 /* "bgp bestpath as-path confed" commands */
12641 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12642 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12643
12644 /* "bgp bestpath as-path multipath-relax" commands */
12645 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12646 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12647
12648 /* "bgp log-neighbor-changes" commands */
12649 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12650 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12651
12652 /* "bgp bestpath med" commands */
12653 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12654 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12655
12656 /* "no bgp default ipv4-unicast" commands. */
12657 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12658 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12659
12660 /* "bgp network import-check" commands. */
12661 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12662 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12663 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12664
12665 /* "bgp default local-preference" commands. */
12666 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12667 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12668
12669 /* bgp default show-hostname */
12670 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12671 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12672
12673 /* "bgp default subgroup-pkt-queue-max" commands. */
12674 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12675 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12676
12677 /* bgp ibgp-allow-policy-mods command */
12678 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12679 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12680
12681 /* "bgp listen limit" commands. */
12682 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12683 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12684
12685 /* "bgp listen range" commands. */
12686 install_element(BGP_NODE, &bgp_listen_range_cmd);
12687 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12688
8175f54a 12689 /* "bgp default shutdown" command */
f26845f9
QY
12690 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12691
d62a17ae 12692 /* "neighbor remote-as" commands. */
12693 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12694 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12695 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12696 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12697 install_element(BGP_NODE,
12698 &neighbor_interface_v6only_config_remote_as_cmd);
12699 install_element(BGP_NODE, &no_neighbor_cmd);
12700 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12701
12702 /* "neighbor peer-group" commands. */
12703 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12704 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12705 install_element(BGP_NODE,
12706 &no_neighbor_interface_peer_group_remote_as_cmd);
12707
12708 /* "neighbor local-as" commands. */
12709 install_element(BGP_NODE, &neighbor_local_as_cmd);
12710 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12711 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12712 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12713
12714 /* "neighbor solo" commands. */
12715 install_element(BGP_NODE, &neighbor_solo_cmd);
12716 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12717
12718 /* "neighbor password" commands. */
12719 install_element(BGP_NODE, &neighbor_password_cmd);
12720 install_element(BGP_NODE, &no_neighbor_password_cmd);
12721
12722 /* "neighbor activate" commands. */
12723 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12724 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12725 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12726 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12727 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12728 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12729 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12730 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12731 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 12732 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12733 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 12734 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12735
12736 /* "no neighbor activate" commands. */
12737 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12738 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12739 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12740 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12741 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12742 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12743 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12744 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12745 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 12746 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12747 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 12748 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12749
12750 /* "neighbor peer-group" set commands. */
12751 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12752 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12753 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12754 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12755 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12756 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12757 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12758 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 12759 install_element(BGP_FLOWSPECV4_NODE,
12760 &neighbor_set_peer_group_hidden_cmd);
12761 install_element(BGP_FLOWSPECV6_NODE,
12762 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 12763
12764 /* "no neighbor peer-group unset" commands. */
12765 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12766 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12767 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12768 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12769 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12770 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12771 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12772 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 12773 install_element(BGP_FLOWSPECV4_NODE,
12774 &no_neighbor_set_peer_group_hidden_cmd);
12775 install_element(BGP_FLOWSPECV6_NODE,
12776 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 12777
12778 /* "neighbor softreconfiguration inbound" commands.*/
12779 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12780 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12781 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12782 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12783 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12784 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12785 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12786 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12787 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12788 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12789 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12790 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12791 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12792 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12793 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12794 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12795 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12796 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 12797 install_element(BGP_FLOWSPECV4_NODE,
12798 &neighbor_soft_reconfiguration_cmd);
12799 install_element(BGP_FLOWSPECV4_NODE,
12800 &no_neighbor_soft_reconfiguration_cmd);
12801 install_element(BGP_FLOWSPECV6_NODE,
12802 &neighbor_soft_reconfiguration_cmd);
12803 install_element(BGP_FLOWSPECV6_NODE,
12804 &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 12805
12806 /* "neighbor attribute-unchanged" commands. */
12807 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12808 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12809 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12810 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12811 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12812 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12813 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12814 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12815 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12816 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12817 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12818 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12819 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12820 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12821 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12822 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12823 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12824 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12825
12826 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12827 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12828
12829 /* "nexthop-local unchanged" commands */
12830 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12831 install_element(BGP_IPV6_NODE,
12832 &no_neighbor_nexthop_local_unchanged_cmd);
12833
12834 /* "neighbor next-hop-self" commands. */
12835 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12836 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12837 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12838 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12839 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12840 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12841 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12842 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12843 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12844 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12845 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12846 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12847 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12848 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12849 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12850 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12851 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12852 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
12853 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12854 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 12855
12856 /* "neighbor next-hop-self force" commands. */
12857 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12858 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12859 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12860 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12861 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12862 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12863 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12864 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12865 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12866 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12867 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12868 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12869 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12870 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12871 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12872 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12873 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12874 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12875
12876 /* "neighbor as-override" commands. */
12877 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12878 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12879 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12880 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12881 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12882 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12883 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12884 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12885 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12886 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12887 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12888 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12889 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12890 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12891 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12892 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12893 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12894 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12895
12896 /* "neighbor remove-private-AS" commands. */
12897 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12898 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12899 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12900 install_element(BGP_NODE,
12901 &no_neighbor_remove_private_as_all_hidden_cmd);
12902 install_element(BGP_NODE,
12903 &neighbor_remove_private_as_replace_as_hidden_cmd);
12904 install_element(BGP_NODE,
12905 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12906 install_element(BGP_NODE,
12907 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12908 install_element(
12909 BGP_NODE,
12910 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12911 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12912 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12913 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12914 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12915 install_element(BGP_IPV4_NODE,
12916 &neighbor_remove_private_as_replace_as_cmd);
12917 install_element(BGP_IPV4_NODE,
12918 &no_neighbor_remove_private_as_replace_as_cmd);
12919 install_element(BGP_IPV4_NODE,
12920 &neighbor_remove_private_as_all_replace_as_cmd);
12921 install_element(BGP_IPV4_NODE,
12922 &no_neighbor_remove_private_as_all_replace_as_cmd);
12923 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12924 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12925 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12926 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12927 install_element(BGP_IPV4M_NODE,
12928 &neighbor_remove_private_as_replace_as_cmd);
12929 install_element(BGP_IPV4M_NODE,
12930 &no_neighbor_remove_private_as_replace_as_cmd);
12931 install_element(BGP_IPV4M_NODE,
12932 &neighbor_remove_private_as_all_replace_as_cmd);
12933 install_element(BGP_IPV4M_NODE,
12934 &no_neighbor_remove_private_as_all_replace_as_cmd);
12935 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12936 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12937 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12938 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12939 install_element(BGP_IPV4L_NODE,
12940 &neighbor_remove_private_as_replace_as_cmd);
12941 install_element(BGP_IPV4L_NODE,
12942 &no_neighbor_remove_private_as_replace_as_cmd);
12943 install_element(BGP_IPV4L_NODE,
12944 &neighbor_remove_private_as_all_replace_as_cmd);
12945 install_element(BGP_IPV4L_NODE,
12946 &no_neighbor_remove_private_as_all_replace_as_cmd);
12947 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12948 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12949 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12950 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12951 install_element(BGP_IPV6_NODE,
12952 &neighbor_remove_private_as_replace_as_cmd);
12953 install_element(BGP_IPV6_NODE,
12954 &no_neighbor_remove_private_as_replace_as_cmd);
12955 install_element(BGP_IPV6_NODE,
12956 &neighbor_remove_private_as_all_replace_as_cmd);
12957 install_element(BGP_IPV6_NODE,
12958 &no_neighbor_remove_private_as_all_replace_as_cmd);
12959 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12960 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12961 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12962 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12963 install_element(BGP_IPV6M_NODE,
12964 &neighbor_remove_private_as_replace_as_cmd);
12965 install_element(BGP_IPV6M_NODE,
12966 &no_neighbor_remove_private_as_replace_as_cmd);
12967 install_element(BGP_IPV6M_NODE,
12968 &neighbor_remove_private_as_all_replace_as_cmd);
12969 install_element(BGP_IPV6M_NODE,
12970 &no_neighbor_remove_private_as_all_replace_as_cmd);
12971 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12972 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12973 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12974 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12975 install_element(BGP_IPV6L_NODE,
12976 &neighbor_remove_private_as_replace_as_cmd);
12977 install_element(BGP_IPV6L_NODE,
12978 &no_neighbor_remove_private_as_replace_as_cmd);
12979 install_element(BGP_IPV6L_NODE,
12980 &neighbor_remove_private_as_all_replace_as_cmd);
12981 install_element(BGP_IPV6L_NODE,
12982 &no_neighbor_remove_private_as_all_replace_as_cmd);
12983 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12984 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12985 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12986 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12987 install_element(BGP_VPNV4_NODE,
12988 &neighbor_remove_private_as_replace_as_cmd);
12989 install_element(BGP_VPNV4_NODE,
12990 &no_neighbor_remove_private_as_replace_as_cmd);
12991 install_element(BGP_VPNV4_NODE,
12992 &neighbor_remove_private_as_all_replace_as_cmd);
12993 install_element(BGP_VPNV4_NODE,
12994 &no_neighbor_remove_private_as_all_replace_as_cmd);
12995 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12996 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12997 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12998 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12999 install_element(BGP_VPNV6_NODE,
13000 &neighbor_remove_private_as_replace_as_cmd);
13001 install_element(BGP_VPNV6_NODE,
13002 &no_neighbor_remove_private_as_replace_as_cmd);
13003 install_element(BGP_VPNV6_NODE,
13004 &neighbor_remove_private_as_all_replace_as_cmd);
13005 install_element(BGP_VPNV6_NODE,
13006 &no_neighbor_remove_private_as_all_replace_as_cmd);
13007
13008 /* "neighbor send-community" commands.*/
13009 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13010 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13011 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13012 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13013 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13014 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13015 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13016 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13017 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13018 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13019 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13020 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13021 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13022 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13023 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13024 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13025 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13026 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13027 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13028 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13029 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13030 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13031 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13032 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13033 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13034 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13035 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13036 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13037 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13038 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13039 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13040 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13041 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13042 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13043 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13044 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13045
13046 /* "neighbor route-reflector" commands.*/
13047 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13048 install_element(BGP_NODE,
13049 &no_neighbor_route_reflector_client_hidden_cmd);
13050 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13051 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13052 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13053 install_element(BGP_IPV4M_NODE,
13054 &no_neighbor_route_reflector_client_cmd);
13055 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13056 install_element(BGP_IPV4L_NODE,
13057 &no_neighbor_route_reflector_client_cmd);
13058 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13059 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13060 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13061 install_element(BGP_IPV6M_NODE,
13062 &no_neighbor_route_reflector_client_cmd);
13063 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13064 install_element(BGP_IPV6L_NODE,
13065 &no_neighbor_route_reflector_client_cmd);
13066 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13067 install_element(BGP_VPNV4_NODE,
13068 &no_neighbor_route_reflector_client_cmd);
13069 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13070 install_element(BGP_VPNV6_NODE,
13071 &no_neighbor_route_reflector_client_cmd);
7c40bf39 13072 install_element(BGP_FLOWSPECV4_NODE,
13073 &neighbor_route_reflector_client_cmd);
13074 install_element(BGP_FLOWSPECV4_NODE,
13075 &no_neighbor_route_reflector_client_cmd);
13076 install_element(BGP_FLOWSPECV6_NODE,
13077 &neighbor_route_reflector_client_cmd);
13078 install_element(BGP_FLOWSPECV6_NODE,
13079 &no_neighbor_route_reflector_client_cmd);
d62a17ae 13080 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13081 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13082
13083 /* "neighbor route-server" commands.*/
13084 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13085 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13086 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13087 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13088 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13089 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13090 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13091 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13092 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13093 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13094 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13095 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13096 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13097 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13098 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13099 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13100 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13101 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 13102 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13103 install_element(BGP_FLOWSPECV4_NODE,
13104 &no_neighbor_route_server_client_cmd);
13105 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13106 install_element(BGP_FLOWSPECV6_NODE,
13107 &no_neighbor_route_server_client_cmd);
d62a17ae 13108
13109 /* "neighbor addpath-tx-all-paths" commands.*/
13110 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13111 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13112 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13113 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13114 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13115 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13116 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13117 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13118 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13119 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13120 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13121 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13122 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13123 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13124 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13125 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13126 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13127 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13128
13129 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13130 install_element(BGP_NODE,
13131 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13132 install_element(BGP_NODE,
13133 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13134 install_element(BGP_IPV4_NODE,
13135 &neighbor_addpath_tx_bestpath_per_as_cmd);
13136 install_element(BGP_IPV4_NODE,
13137 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13138 install_element(BGP_IPV4M_NODE,
13139 &neighbor_addpath_tx_bestpath_per_as_cmd);
13140 install_element(BGP_IPV4M_NODE,
13141 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13142 install_element(BGP_IPV4L_NODE,
13143 &neighbor_addpath_tx_bestpath_per_as_cmd);
13144 install_element(BGP_IPV4L_NODE,
13145 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13146 install_element(BGP_IPV6_NODE,
13147 &neighbor_addpath_tx_bestpath_per_as_cmd);
13148 install_element(BGP_IPV6_NODE,
13149 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13150 install_element(BGP_IPV6M_NODE,
13151 &neighbor_addpath_tx_bestpath_per_as_cmd);
13152 install_element(BGP_IPV6M_NODE,
13153 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13154 install_element(BGP_IPV6L_NODE,
13155 &neighbor_addpath_tx_bestpath_per_as_cmd);
13156 install_element(BGP_IPV6L_NODE,
13157 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13158 install_element(BGP_VPNV4_NODE,
13159 &neighbor_addpath_tx_bestpath_per_as_cmd);
13160 install_element(BGP_VPNV4_NODE,
13161 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13162 install_element(BGP_VPNV6_NODE,
13163 &neighbor_addpath_tx_bestpath_per_as_cmd);
13164 install_element(BGP_VPNV6_NODE,
13165 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13166
13167 /* "neighbor passive" commands. */
13168 install_element(BGP_NODE, &neighbor_passive_cmd);
13169 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13170
13171
13172 /* "neighbor shutdown" commands. */
13173 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13174 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13175 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13176 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13177
13178 /* "neighbor capability extended-nexthop" commands.*/
13179 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13180 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13181
13182 /* "neighbor capability orf prefix-list" commands.*/
13183 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13184 install_element(BGP_NODE,
13185 &no_neighbor_capability_orf_prefix_hidden_cmd);
13186 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13187 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13188 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13189 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13190 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13191 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13192 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13193 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13194 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13195 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13196 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13197 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13198
13199 /* "neighbor capability dynamic" commands.*/
13200 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13201 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13202
13203 /* "neighbor dont-capability-negotiate" commands. */
13204 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13205 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13206
13207 /* "neighbor ebgp-multihop" commands. */
13208 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13209 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13210 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13211
13212 /* "neighbor disable-connected-check" commands. */
13213 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13214 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13215
47cbc09b
PM
13216 /* "neighbor enforce-first-as" commands. */
13217 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13218 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13219
d62a17ae 13220 /* "neighbor description" commands. */
13221 install_element(BGP_NODE, &neighbor_description_cmd);
13222 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13223 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13224
13225 /* "neighbor update-source" commands. "*/
13226 install_element(BGP_NODE, &neighbor_update_source_cmd);
13227 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13228
13229 /* "neighbor default-originate" commands. */
13230 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13231 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13232 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13233 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13234 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13235 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13236 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13237 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13238 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13239 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13240 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13241 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13242 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13243 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13244 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13245 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13246 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13247 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13248 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13249 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13250 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13251
13252 /* "neighbor port" commands. */
13253 install_element(BGP_NODE, &neighbor_port_cmd);
13254 install_element(BGP_NODE, &no_neighbor_port_cmd);
13255
13256 /* "neighbor weight" commands. */
13257 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13258 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13259
13260 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13261 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13262 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13263 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13264 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13265 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13266 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13267 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13268 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13269 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13270 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13271 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13272 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13273 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13274 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13275 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13276
13277 /* "neighbor override-capability" commands. */
13278 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13279 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13280
13281 /* "neighbor strict-capability-match" commands. */
13282 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13283 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13284
13285 /* "neighbor timers" commands. */
13286 install_element(BGP_NODE, &neighbor_timers_cmd);
13287 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13288
13289 /* "neighbor timers connect" commands. */
13290 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13291 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13292
13293 /* "neighbor advertisement-interval" commands. */
13294 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13295 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13296
13297 /* "neighbor interface" commands. */
13298 install_element(BGP_NODE, &neighbor_interface_cmd);
13299 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13300
13301 /* "neighbor distribute" commands. */
13302 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13303 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13304 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13305 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13306 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13307 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13308 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13309 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13310 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13311 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13312 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13313 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13314 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13315 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13316 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13317 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13318 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13319 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13320
13321 /* "neighbor prefix-list" commands. */
13322 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13323 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13324 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13325 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13326 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13327 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13328 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13329 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13330 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13331 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13332 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13333 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13334 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13335 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13336 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13337 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13338 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13339 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13340 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13341 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13342 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13343 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13344
13345 /* "neighbor filter-list" commands. */
13346 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13347 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13348 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13349 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13350 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13351 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13352 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13353 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13354 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13355 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13356 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13357 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13358 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13359 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13360 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13361 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13362 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13363 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13364 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13365 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13366 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13367 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13368
13369 /* "neighbor route-map" commands. */
13370 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13371 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13372 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13373 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13374 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13375 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13376 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13377 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13378 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13379 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13380 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13381 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13382 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13383 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13384 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13385 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13386 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13387 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13388 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13389 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13390 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13391 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13392 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13393 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13394
13395 /* "neighbor unsuppress-map" commands. */
13396 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13397 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13398 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13399 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13400 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13401 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13402 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13403 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13404 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13405 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13406 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13407 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13408 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13409 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13410 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13411 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13412 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13413 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13414
13415 /* "neighbor maximum-prefix" commands. */
13416 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13417 install_element(BGP_NODE,
13418 &neighbor_maximum_prefix_threshold_hidden_cmd);
13419 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13420 install_element(BGP_NODE,
13421 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13422 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13423 install_element(BGP_NODE,
13424 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13425 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13426 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13427 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13428 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13429 install_element(BGP_IPV4_NODE,
13430 &neighbor_maximum_prefix_threshold_warning_cmd);
13431 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13432 install_element(BGP_IPV4_NODE,
13433 &neighbor_maximum_prefix_threshold_restart_cmd);
13434 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13435 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13436 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13437 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13438 install_element(BGP_IPV4M_NODE,
13439 &neighbor_maximum_prefix_threshold_warning_cmd);
13440 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13441 install_element(BGP_IPV4M_NODE,
13442 &neighbor_maximum_prefix_threshold_restart_cmd);
13443 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13444 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13445 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13446 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13447 install_element(BGP_IPV4L_NODE,
13448 &neighbor_maximum_prefix_threshold_warning_cmd);
13449 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13450 install_element(BGP_IPV4L_NODE,
13451 &neighbor_maximum_prefix_threshold_restart_cmd);
13452 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13453 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13454 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13455 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13456 install_element(BGP_IPV6_NODE,
13457 &neighbor_maximum_prefix_threshold_warning_cmd);
13458 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13459 install_element(BGP_IPV6_NODE,
13460 &neighbor_maximum_prefix_threshold_restart_cmd);
13461 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13462 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13463 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13464 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13465 install_element(BGP_IPV6M_NODE,
13466 &neighbor_maximum_prefix_threshold_warning_cmd);
13467 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13468 install_element(BGP_IPV6M_NODE,
13469 &neighbor_maximum_prefix_threshold_restart_cmd);
13470 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13471 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13472 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13473 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13474 install_element(BGP_IPV6L_NODE,
13475 &neighbor_maximum_prefix_threshold_warning_cmd);
13476 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13477 install_element(BGP_IPV6L_NODE,
13478 &neighbor_maximum_prefix_threshold_restart_cmd);
13479 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13480 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13481 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13482 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13483 install_element(BGP_VPNV4_NODE,
13484 &neighbor_maximum_prefix_threshold_warning_cmd);
13485 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13486 install_element(BGP_VPNV4_NODE,
13487 &neighbor_maximum_prefix_threshold_restart_cmd);
13488 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13489 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13490 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13491 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13492 install_element(BGP_VPNV6_NODE,
13493 &neighbor_maximum_prefix_threshold_warning_cmd);
13494 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13495 install_element(BGP_VPNV6_NODE,
13496 &neighbor_maximum_prefix_threshold_restart_cmd);
13497 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13498
13499 /* "neighbor allowas-in" */
13500 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13501 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13502 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13503 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13504 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13505 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13506 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13507 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13508 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13509 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13510 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13511 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13512 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13513 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13514 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13515 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13516 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13517 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13518 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13519 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13520
13521 /* address-family commands. */
13522 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13523 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13524#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13525 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13526 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13527#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13528
d62a17ae 13529 install_element(BGP_NODE, &address_family_evpn_cmd);
13530
13531 /* "exit-address-family" command. */
13532 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13533 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13534 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13535 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13536 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13537 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13538 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13539 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13540 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13541 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13542 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13543
13544 /* "clear ip bgp commands" */
13545 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13546
13547 /* clear ip bgp prefix */
13548 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13549 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13550 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13551
13552 /* "show [ip] bgp summary" commands. */
13553 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
d62a17ae 13554 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13555 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13556 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13557 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13558 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13559
13560 /* "show [ip] bgp neighbors" commands. */
13561 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13562
13563 /* "show [ip] bgp peer-group" commands. */
13564 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13565
13566 /* "show [ip] bgp paths" commands. */
13567 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13568
13569 /* "show [ip] bgp community" commands. */
13570 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13571
13572 /* "show ip bgp large-community" commands. */
13573 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13574 /* "show [ip] bgp attribute-info" commands. */
13575 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13576 /* "show [ip] bgp route-leak" command */
13577 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13578
13579 /* "redistribute" commands. */
13580 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13581 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13582 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13583 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13584 install_element(BGP_NODE,
13585 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13586 install_element(BGP_NODE,
13587 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13588 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13589 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13590 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13591 install_element(BGP_NODE,
13592 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13593 install_element(BGP_NODE,
13594 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13595 install_element(BGP_NODE,
13596 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13597 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13598 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13599 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13600 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13601 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13602 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13603 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13604 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13605 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13606 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13607 install_element(BGP_IPV4_NODE,
13608 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13609 install_element(BGP_IPV4_NODE,
13610 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13611 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13612 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13613 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13614 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13615 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13616 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13617
b9c7bc5a
PZ
13618 /* import|export vpn [route-map WORD] */
13619 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13620 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13621
12a844a5
DS
13622 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13623 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13624
d62a17ae 13625 /* ttl_security commands */
13626 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13627 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13628
13629 /* "show [ip] bgp memory" commands. */
13630 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13631
acf71666
MK
13632 /* "show bgp martian next-hop" */
13633 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13634
d62a17ae 13635 /* "show [ip] bgp views" commands. */
13636 install_element(VIEW_NODE, &show_bgp_views_cmd);
13637
13638 /* "show [ip] bgp vrfs" commands. */
13639 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13640
13641 /* Community-list. */
13642 community_list_vty();
ddb5b488
PZ
13643
13644 /* vpn-policy commands */
b9c7bc5a
PZ
13645 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13646 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13647 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13648 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13649 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13650 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13651 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13652 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13653 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13654 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
13655 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13656 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 13657
301ad80a
PG
13658 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13659 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13660
b9c7bc5a
PZ
13661 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13662 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13663 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13664 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13665 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13666 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13667 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13668 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13669 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13670 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
13671 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13672 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 13673}
6b0655a2 13674
718e3744 13675#include "memory.h"
13676#include "bgp_regex.h"
13677#include "bgp_clist.h"
13678#include "bgp_ecommunity.h"
13679
13680/* VTY functions. */
13681
13682/* Direction value to string conversion. */
d62a17ae 13683static const char *community_direct_str(int direct)
13684{
13685 switch (direct) {
13686 case COMMUNITY_DENY:
13687 return "deny";
13688 case COMMUNITY_PERMIT:
13689 return "permit";
13690 default:
13691 return "unknown";
13692 }
718e3744 13693}
13694
13695/* Display error string. */
d62a17ae 13696static void community_list_perror(struct vty *vty, int ret)
13697{
13698 switch (ret) {
13699 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13700 vty_out(vty, "%% Can't find community-list\n");
13701 break;
13702 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13703 vty_out(vty, "%% Malformed community-list value\n");
13704 break;
13705 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13706 vty_out(vty,
13707 "%% Community name conflict, previously defined as standard community\n");
13708 break;
13709 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13710 vty_out(vty,
13711 "%% Community name conflict, previously defined as expanded community\n");
13712 break;
13713 }
718e3744 13714}
13715
5bf15956
DW
13716/* "community-list" keyword help string. */
13717#define COMMUNITY_LIST_STR "Add a community list entry\n"
13718
5bf15956 13719/* ip community-list standard */
718e3744 13720DEFUN (ip_community_list_standard,
13721 ip_community_list_standard_cmd,
e961923c 13722 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13723 IP_STR
13724 COMMUNITY_LIST_STR
13725 "Community list number (standard)\n"
5bf15956 13726 "Add an standard community-list entry\n"
718e3744 13727 "Community list name\n"
13728 "Specify community to reject\n"
13729 "Specify community to accept\n"
13730 COMMUNITY_VAL_STR)
13731{
d62a17ae 13732 char *cl_name_or_number = NULL;
13733 int direct = 0;
13734 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13735
d62a17ae 13736 int idx = 0;
13737 argv_find(argv, argc, "(1-99)", &idx);
13738 argv_find(argv, argc, "WORD", &idx);
13739 cl_name_or_number = argv[idx]->arg;
13740 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13741 : COMMUNITY_DENY;
13742 argv_find(argv, argc, "AA:NN", &idx);
13743 char *str = argv_concat(argv, argc, idx);
42f914d4 13744
d62a17ae 13745 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13746 style);
42f914d4 13747
d62a17ae 13748 XFREE(MTYPE_TMP, str);
42f914d4 13749
d62a17ae 13750 if (ret < 0) {
13751 /* Display error string. */
13752 community_list_perror(vty, ret);
13753 return CMD_WARNING_CONFIG_FAILED;
13754 }
42f914d4 13755
d62a17ae 13756 return CMD_SUCCESS;
718e3744 13757}
13758
fee6e4e4 13759DEFUN (no_ip_community_list_standard_all,
13760 no_ip_community_list_standard_all_cmd,
e961923c 13761 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13762 NO_STR
13763 IP_STR
13764 COMMUNITY_LIST_STR
13765 "Community list number (standard)\n"
5bf15956
DW
13766 "Add an standard community-list entry\n"
13767 "Community list name\n"
718e3744 13768 "Specify community to reject\n"
13769 "Specify community to accept\n"
13770 COMMUNITY_VAL_STR)
13771{
d62a17ae 13772 char *cl_name_or_number = NULL;
13773 int direct = 0;
13774 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13775
d62a17ae 13776 int idx = 0;
13777 argv_find(argv, argc, "(1-99)", &idx);
13778 argv_find(argv, argc, "WORD", &idx);
13779 cl_name_or_number = argv[idx]->arg;
13780 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13781 : COMMUNITY_DENY;
13782 argv_find(argv, argc, "AA:NN", &idx);
13783 char *str = argv_concat(argv, argc, idx);
42f914d4 13784
d62a17ae 13785 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13786 direct, style);
42f914d4 13787
d62a17ae 13788 XFREE(MTYPE_TMP, str);
daf9ddbb 13789
d62a17ae 13790 if (ret < 0) {
13791 community_list_perror(vty, ret);
13792 return CMD_WARNING_CONFIG_FAILED;
13793 }
42f914d4 13794
d62a17ae 13795 return CMD_SUCCESS;
718e3744 13796}
13797
5bf15956
DW
13798/* ip community-list expanded */
13799DEFUN (ip_community_list_expanded_all,
13800 ip_community_list_expanded_all_cmd,
42f914d4 13801 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13802 IP_STR
13803 COMMUNITY_LIST_STR
13804 "Community list number (expanded)\n"
5bf15956 13805 "Add an expanded community-list entry\n"
718e3744 13806 "Community list name\n"
13807 "Specify community to reject\n"
13808 "Specify community to accept\n"
13809 COMMUNITY_VAL_STR)
13810{
d62a17ae 13811 char *cl_name_or_number = NULL;
13812 int direct = 0;
13813 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13814
d62a17ae 13815 int idx = 0;
13816 argv_find(argv, argc, "(100-500)", &idx);
13817 argv_find(argv, argc, "WORD", &idx);
13818 cl_name_or_number = argv[idx]->arg;
13819 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13820 : COMMUNITY_DENY;
13821 argv_find(argv, argc, "AA:NN", &idx);
13822 char *str = argv_concat(argv, argc, idx);
42f914d4 13823
d62a17ae 13824 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13825 style);
42f914d4 13826
d62a17ae 13827 XFREE(MTYPE_TMP, str);
42f914d4 13828
d62a17ae 13829 if (ret < 0) {
13830 /* Display error string. */
13831 community_list_perror(vty, ret);
13832 return CMD_WARNING_CONFIG_FAILED;
13833 }
42f914d4 13834
d62a17ae 13835 return CMD_SUCCESS;
718e3744 13836}
13837
5bf15956
DW
13838DEFUN (no_ip_community_list_expanded_all,
13839 no_ip_community_list_expanded_all_cmd,
42f914d4 13840 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13841 NO_STR
13842 IP_STR
13843 COMMUNITY_LIST_STR
5bf15956
DW
13844 "Community list number (expanded)\n"
13845 "Add an expanded community-list entry\n"
718e3744 13846 "Community list name\n"
13847 "Specify community to reject\n"
13848 "Specify community to accept\n"
5bf15956 13849 COMMUNITY_VAL_STR)
718e3744 13850{
d62a17ae 13851 char *cl_name_or_number = NULL;
13852 int direct = 0;
13853 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13854
d62a17ae 13855 int idx = 0;
13856 argv_find(argv, argc, "(100-500)", &idx);
13857 argv_find(argv, argc, "WORD", &idx);
13858 cl_name_or_number = argv[idx]->arg;
13859 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13860 : COMMUNITY_DENY;
13861 argv_find(argv, argc, "AA:NN", &idx);
13862 char *str = argv_concat(argv, argc, idx);
42f914d4 13863
d62a17ae 13864 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13865 direct, style);
42f914d4 13866
d62a17ae 13867 XFREE(MTYPE_TMP, str);
daf9ddbb 13868
d62a17ae 13869 if (ret < 0) {
13870 community_list_perror(vty, ret);
13871 return CMD_WARNING_CONFIG_FAILED;
13872 }
42f914d4 13873
d62a17ae 13874 return CMD_SUCCESS;
718e3744 13875}
13876
8d9b8ed9
PM
13877/* Return configuration string of community-list entry. */
13878static const char *community_list_config_str(struct community_entry *entry)
13879{
13880 const char *str;
13881
13882 if (entry->any)
13883 str = "";
13884 else {
13885 if (entry->style == COMMUNITY_LIST_STANDARD)
13886 str = community_str(entry->u.com, false);
13887 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13888 str = lcommunity_str(entry->u.lcom, false);
13889 else
13890 str = entry->config;
13891 }
13892 return str;
13893}
13894
d62a17ae 13895static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 13896{
d62a17ae 13897 struct community_entry *entry;
718e3744 13898
d62a17ae 13899 for (entry = list->head; entry; entry = entry->next) {
13900 if (entry == list->head) {
13901 if (all_digit(list->name))
13902 vty_out(vty, "Community %s list %s\n",
13903 entry->style == COMMUNITY_LIST_STANDARD
13904 ? "standard"
13905 : "(expanded) access",
13906 list->name);
13907 else
13908 vty_out(vty, "Named Community %s list %s\n",
13909 entry->style == COMMUNITY_LIST_STANDARD
13910 ? "standard"
13911 : "expanded",
13912 list->name);
13913 }
13914 if (entry->any)
13915 vty_out(vty, " %s\n",
13916 community_direct_str(entry->direct));
13917 else
13918 vty_out(vty, " %s %s\n",
13919 community_direct_str(entry->direct),
8d9b8ed9 13920 community_list_config_str(entry));
d62a17ae 13921 }
718e3744 13922}
13923
13924DEFUN (show_ip_community_list,
13925 show_ip_community_list_cmd,
13926 "show ip community-list",
13927 SHOW_STR
13928 IP_STR
13929 "List community-list\n")
13930{
d62a17ae 13931 struct community_list *list;
13932 struct community_list_master *cm;
718e3744 13933
d62a17ae 13934 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13935 if (!cm)
13936 return CMD_SUCCESS;
718e3744 13937
d62a17ae 13938 for (list = cm->num.head; list; list = list->next)
13939 community_list_show(vty, list);
718e3744 13940
d62a17ae 13941 for (list = cm->str.head; list; list = list->next)
13942 community_list_show(vty, list);
718e3744 13943
d62a17ae 13944 return CMD_SUCCESS;
718e3744 13945}
13946
13947DEFUN (show_ip_community_list_arg,
13948 show_ip_community_list_arg_cmd,
6147e2c6 13949 "show ip community-list <(1-500)|WORD>",
718e3744 13950 SHOW_STR
13951 IP_STR
13952 "List community-list\n"
13953 "Community-list number\n"
13954 "Community-list name\n")
13955{
d62a17ae 13956 int idx_comm_list = 3;
13957 struct community_list *list;
718e3744 13958
d62a17ae 13959 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13960 COMMUNITY_LIST_MASTER);
13961 if (!list) {
13962 vty_out(vty, "%% Can't find community-list\n");
13963 return CMD_WARNING;
13964 }
718e3744 13965
d62a17ae 13966 community_list_show(vty, list);
718e3744 13967
d62a17ae 13968 return CMD_SUCCESS;
718e3744 13969}
6b0655a2 13970
57d187bc
JS
13971/*
13972 * Large Community code.
13973 */
d62a17ae 13974static int lcommunity_list_set_vty(struct vty *vty, int argc,
13975 struct cmd_token **argv, int style,
13976 int reject_all_digit_name)
13977{
13978 int ret;
13979 int direct;
13980 char *str;
13981 int idx = 0;
13982 char *cl_name;
13983
13984 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13985 : COMMUNITY_DENY;
13986
13987 /* All digit name check. */
13988 idx = 0;
13989 argv_find(argv, argc, "WORD", &idx);
13990 argv_find(argv, argc, "(1-99)", &idx);
13991 argv_find(argv, argc, "(100-500)", &idx);
13992 cl_name = argv[idx]->arg;
13993 if (reject_all_digit_name && all_digit(cl_name)) {
13994 vty_out(vty, "%% Community name cannot have all digits\n");
13995 return CMD_WARNING_CONFIG_FAILED;
13996 }
13997
13998 idx = 0;
13999 argv_find(argv, argc, "AA:BB:CC", &idx);
14000 argv_find(argv, argc, "LINE", &idx);
14001 /* Concat community string argument. */
14002 if (idx)
14003 str = argv_concat(argv, argc, idx);
14004 else
14005 str = NULL;
14006
14007 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14008
14009 /* Free temporary community list string allocated by
14010 argv_concat(). */
14011 if (str)
14012 XFREE(MTYPE_TMP, str);
14013
14014 if (ret < 0) {
14015 community_list_perror(vty, ret);
14016 return CMD_WARNING_CONFIG_FAILED;
14017 }
14018 return CMD_SUCCESS;
14019}
14020
14021static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14022 struct cmd_token **argv, int style)
14023{
14024 int ret;
14025 int direct = 0;
14026 char *str = NULL;
14027 int idx = 0;
14028
14029 argv_find(argv, argc, "permit", &idx);
14030 argv_find(argv, argc, "deny", &idx);
14031
14032 if (idx) {
14033 /* Check the list direct. */
14034 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14035 direct = COMMUNITY_PERMIT;
14036 else
14037 direct = COMMUNITY_DENY;
14038
14039 idx = 0;
14040 argv_find(argv, argc, "LINE", &idx);
14041 argv_find(argv, argc, "AA:AA:NN", &idx);
14042 /* Concat community string argument. */
14043 str = argv_concat(argv, argc, idx);
14044 }
14045
14046 idx = 0;
14047 argv_find(argv, argc, "(1-99)", &idx);
14048 argv_find(argv, argc, "(100-500)", &idx);
14049 argv_find(argv, argc, "WORD", &idx);
14050
14051 /* Unset community list. */
14052 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14053 style);
14054
14055 /* Free temporary community list string allocated by
14056 argv_concat(). */
14057 if (str)
14058 XFREE(MTYPE_TMP, str);
14059
14060 if (ret < 0) {
14061 community_list_perror(vty, ret);
14062 return CMD_WARNING_CONFIG_FAILED;
14063 }
14064
14065 return CMD_SUCCESS;
57d187bc
JS
14066}
14067
14068/* "large-community-list" keyword help string. */
14069#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14070#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14071
14072DEFUN (ip_lcommunity_list_standard,
14073 ip_lcommunity_list_standard_cmd,
52951b63
DS
14074 "ip large-community-list (1-99) <deny|permit>",
14075 IP_STR
14076 LCOMMUNITY_LIST_STR
14077 "Large Community list number (standard)\n"
14078 "Specify large community to reject\n"
7111c1a0 14079 "Specify large community to accept\n")
52951b63 14080{
d62a17ae 14081 return lcommunity_list_set_vty(vty, argc, argv,
14082 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
14083}
14084
14085DEFUN (ip_lcommunity_list_standard1,
14086 ip_lcommunity_list_standard1_cmd,
14087 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
14088 IP_STR
14089 LCOMMUNITY_LIST_STR
14090 "Large Community list number (standard)\n"
14091 "Specify large community to reject\n"
14092 "Specify large community to accept\n"
14093 LCOMMUNITY_VAL_STR)
14094{
d62a17ae 14095 return lcommunity_list_set_vty(vty, argc, argv,
14096 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
14097}
14098
14099DEFUN (ip_lcommunity_list_expanded,
14100 ip_lcommunity_list_expanded_cmd,
14101 "ip large-community-list (100-500) <deny|permit> LINE...",
14102 IP_STR
14103 LCOMMUNITY_LIST_STR
14104 "Large Community list number (expanded)\n"
14105 "Specify large community to reject\n"
14106 "Specify large community to accept\n"
14107 "An ordered list as a regular-expression\n")
14108{
d62a17ae 14109 return lcommunity_list_set_vty(vty, argc, argv,
14110 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
14111}
14112
14113DEFUN (ip_lcommunity_list_name_standard,
14114 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
14115 "ip large-community-list standard WORD <deny|permit>",
14116 IP_STR
14117 LCOMMUNITY_LIST_STR
14118 "Specify standard large-community-list\n"
14119 "Large Community list name\n"
14120 "Specify large community to reject\n"
14121 "Specify large community to accept\n")
14122{
d62a17ae 14123 return lcommunity_list_set_vty(vty, argc, argv,
14124 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
14125}
14126
14127DEFUN (ip_lcommunity_list_name_standard1,
14128 ip_lcommunity_list_name_standard1_cmd,
14129 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
14130 IP_STR
14131 LCOMMUNITY_LIST_STR
14132 "Specify standard large-community-list\n"
14133 "Large Community list name\n"
14134 "Specify large community to reject\n"
14135 "Specify large community to accept\n"
14136 LCOMMUNITY_VAL_STR)
14137{
d62a17ae 14138 return lcommunity_list_set_vty(vty, argc, argv,
14139 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
14140}
14141
14142DEFUN (ip_lcommunity_list_name_expanded,
14143 ip_lcommunity_list_name_expanded_cmd,
14144 "ip large-community-list expanded WORD <deny|permit> LINE...",
14145 IP_STR
14146 LCOMMUNITY_LIST_STR
14147 "Specify expanded large-community-list\n"
14148 "Large Community list name\n"
14149 "Specify large community to reject\n"
14150 "Specify large community to accept\n"
14151 "An ordered list as a regular-expression\n")
14152{
d62a17ae 14153 return lcommunity_list_set_vty(vty, argc, argv,
14154 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
14155}
14156
14157DEFUN (no_ip_lcommunity_list_standard_all,
14158 no_ip_lcommunity_list_standard_all_cmd,
14159 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14160 NO_STR
14161 IP_STR
14162 LCOMMUNITY_LIST_STR
14163 "Large Community list number (standard)\n"
14164 "Large Community list number (expanded)\n"
14165 "Large Community list name\n")
14166{
d62a17ae 14167 return lcommunity_list_unset_vty(vty, argc, argv,
14168 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14169}
14170
14171DEFUN (no_ip_lcommunity_list_name_expanded_all,
14172 no_ip_lcommunity_list_name_expanded_all_cmd,
14173 "no ip large-community-list expanded WORD",
14174 NO_STR
14175 IP_STR
14176 LCOMMUNITY_LIST_STR
14177 "Specify expanded large-community-list\n"
14178 "Large Community list name\n")
14179{
d62a17ae 14180 return lcommunity_list_unset_vty(vty, argc, argv,
14181 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14182}
14183
14184DEFUN (no_ip_lcommunity_list_standard,
14185 no_ip_lcommunity_list_standard_cmd,
14186 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14187 NO_STR
14188 IP_STR
14189 LCOMMUNITY_LIST_STR
14190 "Large Community list number (standard)\n"
14191 "Specify large community to reject\n"
14192 "Specify large community to accept\n"
14193 LCOMMUNITY_VAL_STR)
14194{
d62a17ae 14195 return lcommunity_list_unset_vty(vty, argc, argv,
14196 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14197}
14198
14199DEFUN (no_ip_lcommunity_list_expanded,
14200 no_ip_lcommunity_list_expanded_cmd,
14201 "no ip large-community-list (100-500) <deny|permit> LINE...",
14202 NO_STR
14203 IP_STR
14204 LCOMMUNITY_LIST_STR
14205 "Large Community list number (expanded)\n"
14206 "Specify large community to reject\n"
14207 "Specify large community to accept\n"
14208 "An ordered list as a regular-expression\n")
14209{
d62a17ae 14210 return lcommunity_list_unset_vty(vty, argc, argv,
14211 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14212}
14213
14214DEFUN (no_ip_lcommunity_list_name_standard,
14215 no_ip_lcommunity_list_name_standard_cmd,
14216 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14217 NO_STR
14218 IP_STR
14219 LCOMMUNITY_LIST_STR
14220 "Specify standard large-community-list\n"
14221 "Large Community list name\n"
14222 "Specify large community to reject\n"
14223 "Specify large community to accept\n"
14224 LCOMMUNITY_VAL_STR)
14225{
d62a17ae 14226 return lcommunity_list_unset_vty(vty, argc, argv,
14227 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14228}
14229
14230DEFUN (no_ip_lcommunity_list_name_expanded,
14231 no_ip_lcommunity_list_name_expanded_cmd,
14232 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14233 NO_STR
14234 IP_STR
14235 LCOMMUNITY_LIST_STR
14236 "Specify expanded large-community-list\n"
14237 "Large community list name\n"
14238 "Specify large community to reject\n"
14239 "Specify large community to accept\n"
14240 "An ordered list as a regular-expression\n")
14241{
d62a17ae 14242 return lcommunity_list_unset_vty(vty, argc, argv,
14243 LARGE_COMMUNITY_LIST_EXPANDED);
14244}
14245
14246static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14247{
14248 struct community_entry *entry;
14249
14250 for (entry = list->head; entry; entry = entry->next) {
14251 if (entry == list->head) {
14252 if (all_digit(list->name))
14253 vty_out(vty, "Large community %s list %s\n",
14254 entry->style == EXTCOMMUNITY_LIST_STANDARD
14255 ? "standard"
14256 : "(expanded) access",
14257 list->name);
14258 else
14259 vty_out(vty,
14260 "Named large community %s list %s\n",
14261 entry->style == EXTCOMMUNITY_LIST_STANDARD
14262 ? "standard"
14263 : "expanded",
14264 list->name);
14265 }
14266 if (entry->any)
14267 vty_out(vty, " %s\n",
14268 community_direct_str(entry->direct));
14269 else
14270 vty_out(vty, " %s %s\n",
14271 community_direct_str(entry->direct),
8d9b8ed9 14272 community_list_config_str(entry));
d62a17ae 14273 }
57d187bc
JS
14274}
14275
14276DEFUN (show_ip_lcommunity_list,
14277 show_ip_lcommunity_list_cmd,
14278 "show ip large-community-list",
14279 SHOW_STR
14280 IP_STR
14281 "List large-community list\n")
14282{
d62a17ae 14283 struct community_list *list;
14284 struct community_list_master *cm;
57d187bc 14285
d62a17ae 14286 cm = community_list_master_lookup(bgp_clist,
14287 LARGE_COMMUNITY_LIST_MASTER);
14288 if (!cm)
14289 return CMD_SUCCESS;
57d187bc 14290
d62a17ae 14291 for (list = cm->num.head; list; list = list->next)
14292 lcommunity_list_show(vty, list);
57d187bc 14293
d62a17ae 14294 for (list = cm->str.head; list; list = list->next)
14295 lcommunity_list_show(vty, list);
57d187bc 14296
d62a17ae 14297 return CMD_SUCCESS;
57d187bc
JS
14298}
14299
14300DEFUN (show_ip_lcommunity_list_arg,
14301 show_ip_lcommunity_list_arg_cmd,
14302 "show ip large-community-list <(1-500)|WORD>",
14303 SHOW_STR
14304 IP_STR
14305 "List large-community list\n"
14306 "large-community-list number\n"
14307 "large-community-list name\n")
14308{
d62a17ae 14309 struct community_list *list;
57d187bc 14310
d62a17ae 14311 list = community_list_lookup(bgp_clist, argv[3]->arg,
14312 LARGE_COMMUNITY_LIST_MASTER);
14313 if (!list) {
14314 vty_out(vty, "%% Can't find extcommunity-list\n");
14315 return CMD_WARNING;
14316 }
57d187bc 14317
d62a17ae 14318 lcommunity_list_show(vty, list);
57d187bc 14319
d62a17ae 14320 return CMD_SUCCESS;
57d187bc
JS
14321}
14322
718e3744 14323/* "extcommunity-list" keyword help string. */
14324#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14325#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14326
14327DEFUN (ip_extcommunity_list_standard,
14328 ip_extcommunity_list_standard_cmd,
e961923c 14329 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14330 IP_STR
14331 EXTCOMMUNITY_LIST_STR
14332 "Extended Community list number (standard)\n"
718e3744 14333 "Specify standard extcommunity-list\n"
5bf15956 14334 "Community list name\n"
718e3744 14335 "Specify community to reject\n"
14336 "Specify community to accept\n"
14337 EXTCOMMUNITY_VAL_STR)
14338{
d62a17ae 14339 int style = EXTCOMMUNITY_LIST_STANDARD;
14340 int direct = 0;
14341 char *cl_number_or_name = NULL;
42f914d4 14342
d62a17ae 14343 int idx = 0;
14344 argv_find(argv, argc, "(1-99)", &idx);
14345 argv_find(argv, argc, "WORD", &idx);
14346 cl_number_or_name = argv[idx]->arg;
14347 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14348 : COMMUNITY_DENY;
14349 argv_find(argv, argc, "AA:NN", &idx);
14350 char *str = argv_concat(argv, argc, idx);
42f914d4 14351
d62a17ae 14352 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14353 direct, style);
42f914d4 14354
d62a17ae 14355 XFREE(MTYPE_TMP, str);
42f914d4 14356
d62a17ae 14357 if (ret < 0) {
14358 community_list_perror(vty, ret);
14359 return CMD_WARNING_CONFIG_FAILED;
14360 }
42f914d4 14361
d62a17ae 14362 return CMD_SUCCESS;
718e3744 14363}
14364
718e3744 14365DEFUN (ip_extcommunity_list_name_expanded,
14366 ip_extcommunity_list_name_expanded_cmd,
e961923c 14367 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14368 IP_STR
14369 EXTCOMMUNITY_LIST_STR
5bf15956 14370 "Extended Community list number (expanded)\n"
718e3744 14371 "Specify expanded extcommunity-list\n"
14372 "Extended Community list name\n"
14373 "Specify community to reject\n"
14374 "Specify community to accept\n"
14375 "An ordered list as a regular-expression\n")
14376{
d62a17ae 14377 int style = EXTCOMMUNITY_LIST_EXPANDED;
14378 int direct = 0;
14379 char *cl_number_or_name = NULL;
42f914d4 14380
d62a17ae 14381 int idx = 0;
14382 argv_find(argv, argc, "(100-500)", &idx);
14383 argv_find(argv, argc, "WORD", &idx);
14384 cl_number_or_name = argv[idx]->arg;
14385 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14386 : COMMUNITY_DENY;
14387 argv_find(argv, argc, "LINE", &idx);
14388 char *str = argv_concat(argv, argc, idx);
42f914d4 14389
d62a17ae 14390 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14391 direct, style);
42f914d4 14392
d62a17ae 14393 XFREE(MTYPE_TMP, str);
42f914d4 14394
d62a17ae 14395 if (ret < 0) {
14396 community_list_perror(vty, ret);
14397 return CMD_WARNING_CONFIG_FAILED;
14398 }
42f914d4 14399
d62a17ae 14400 return CMD_SUCCESS;
718e3744 14401}
14402
fee6e4e4 14403DEFUN (no_ip_extcommunity_list_standard_all,
14404 no_ip_extcommunity_list_standard_all_cmd,
e961923c 14405 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
14406 NO_STR
14407 IP_STR
14408 EXTCOMMUNITY_LIST_STR
14409 "Extended Community list number (standard)\n"
718e3744 14410 "Specify standard extcommunity-list\n"
5bf15956 14411 "Community list name\n"
718e3744 14412 "Specify community to reject\n"
14413 "Specify community to accept\n"
14414 EXTCOMMUNITY_VAL_STR)
14415{
d62a17ae 14416 int style = EXTCOMMUNITY_LIST_STANDARD;
14417 int direct = 0;
14418 char *cl_number_or_name = NULL;
42f914d4 14419
d62a17ae 14420 int idx = 0;
14421 argv_find(argv, argc, "(1-99)", &idx);
14422 argv_find(argv, argc, "WORD", &idx);
14423 cl_number_or_name = argv[idx]->arg;
14424 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14425 : COMMUNITY_DENY;
14426 argv_find(argv, argc, "AA:NN", &idx);
14427 char *str = argv_concat(argv, argc, idx);
42f914d4 14428
d62a17ae 14429 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14430 direct, style);
42f914d4 14431
d62a17ae 14432 XFREE(MTYPE_TMP, str);
42f914d4 14433
d62a17ae 14434 if (ret < 0) {
14435 community_list_perror(vty, ret);
14436 return CMD_WARNING_CONFIG_FAILED;
14437 }
42f914d4 14438
d62a17ae 14439 return CMD_SUCCESS;
718e3744 14440}
14441
5bf15956
DW
14442DEFUN (no_ip_extcommunity_list_expanded_all,
14443 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 14444 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14445 NO_STR
14446 IP_STR
14447 EXTCOMMUNITY_LIST_STR
14448 "Extended Community list number (expanded)\n"
718e3744 14449 "Specify expanded extcommunity-list\n"
5bf15956 14450 "Extended Community list name\n"
718e3744 14451 "Specify community to reject\n"
14452 "Specify community to accept\n"
14453 "An ordered list as a regular-expression\n")
14454{
d62a17ae 14455 int style = EXTCOMMUNITY_LIST_EXPANDED;
14456 int direct = 0;
14457 char *cl_number_or_name = NULL;
42f914d4 14458
d62a17ae 14459 int idx = 0;
14460 argv_find(argv, argc, "(100-500)", &idx);
14461 argv_find(argv, argc, "WORD", &idx);
14462 cl_number_or_name = argv[idx]->arg;
14463 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14464 : COMMUNITY_DENY;
14465 argv_find(argv, argc, "LINE", &idx);
14466 char *str = argv_concat(argv, argc, idx);
42f914d4 14467
d62a17ae 14468 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14469 direct, style);
42f914d4 14470
d62a17ae 14471 XFREE(MTYPE_TMP, str);
42f914d4 14472
d62a17ae 14473 if (ret < 0) {
14474 community_list_perror(vty, ret);
14475 return CMD_WARNING_CONFIG_FAILED;
14476 }
42f914d4 14477
d62a17ae 14478 return CMD_SUCCESS;
718e3744 14479}
14480
d62a17ae 14481static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 14482{
d62a17ae 14483 struct community_entry *entry;
718e3744 14484
d62a17ae 14485 for (entry = list->head; entry; entry = entry->next) {
14486 if (entry == list->head) {
14487 if (all_digit(list->name))
14488 vty_out(vty, "Extended community %s list %s\n",
14489 entry->style == EXTCOMMUNITY_LIST_STANDARD
14490 ? "standard"
14491 : "(expanded) access",
14492 list->name);
14493 else
14494 vty_out(vty,
14495 "Named extended community %s list %s\n",
14496 entry->style == EXTCOMMUNITY_LIST_STANDARD
14497 ? "standard"
14498 : "expanded",
14499 list->name);
14500 }
14501 if (entry->any)
14502 vty_out(vty, " %s\n",
14503 community_direct_str(entry->direct));
14504 else
14505 vty_out(vty, " %s %s\n",
14506 community_direct_str(entry->direct),
8d9b8ed9 14507 community_list_config_str(entry));
d62a17ae 14508 }
718e3744 14509}
14510
14511DEFUN (show_ip_extcommunity_list,
14512 show_ip_extcommunity_list_cmd,
14513 "show ip extcommunity-list",
14514 SHOW_STR
14515 IP_STR
14516 "List extended-community list\n")
14517{
d62a17ae 14518 struct community_list *list;
14519 struct community_list_master *cm;
718e3744 14520
d62a17ae 14521 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14522 if (!cm)
14523 return CMD_SUCCESS;
718e3744 14524
d62a17ae 14525 for (list = cm->num.head; list; list = list->next)
14526 extcommunity_list_show(vty, list);
718e3744 14527
d62a17ae 14528 for (list = cm->str.head; list; list = list->next)
14529 extcommunity_list_show(vty, list);
718e3744 14530
d62a17ae 14531 return CMD_SUCCESS;
718e3744 14532}
14533
14534DEFUN (show_ip_extcommunity_list_arg,
14535 show_ip_extcommunity_list_arg_cmd,
6147e2c6 14536 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 14537 SHOW_STR
14538 IP_STR
14539 "List extended-community list\n"
14540 "Extcommunity-list number\n"
14541 "Extcommunity-list name\n")
14542{
d62a17ae 14543 int idx_comm_list = 3;
14544 struct community_list *list;
718e3744 14545
d62a17ae 14546 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14547 EXTCOMMUNITY_LIST_MASTER);
14548 if (!list) {
14549 vty_out(vty, "%% Can't find extcommunity-list\n");
14550 return CMD_WARNING;
14551 }
718e3744 14552
d62a17ae 14553 extcommunity_list_show(vty, list);
718e3744 14554
d62a17ae 14555 return CMD_SUCCESS;
718e3744 14556}
6b0655a2 14557
718e3744 14558/* Display community-list and extcommunity-list configuration. */
d62a17ae 14559static int community_list_config_write(struct vty *vty)
14560{
14561 struct community_list *list;
14562 struct community_entry *entry;
14563 struct community_list_master *cm;
14564 int write = 0;
14565
14566 /* Community-list. */
14567 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14568
14569 for (list = cm->num.head; list; list = list->next)
14570 for (entry = list->head; entry; entry = entry->next) {
14571 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14572 community_direct_str(entry->direct),
14573 community_list_config_str(entry));
14574 write++;
14575 }
14576 for (list = cm->str.head; list; list = list->next)
14577 for (entry = list->head; entry; entry = entry->next) {
14578 vty_out(vty, "ip community-list %s %s %s %s\n",
14579 entry->style == COMMUNITY_LIST_STANDARD
14580 ? "standard"
14581 : "expanded",
14582 list->name, community_direct_str(entry->direct),
14583 community_list_config_str(entry));
14584 write++;
14585 }
14586
14587 /* Extcommunity-list. */
14588 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14589
14590 for (list = cm->num.head; list; list = list->next)
14591 for (entry = list->head; entry; entry = entry->next) {
14592 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14593 list->name, community_direct_str(entry->direct),
14594 community_list_config_str(entry));
14595 write++;
14596 }
14597 for (list = cm->str.head; list; list = list->next)
14598 for (entry = list->head; entry; entry = entry->next) {
14599 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14600 entry->style == EXTCOMMUNITY_LIST_STANDARD
14601 ? "standard"
14602 : "expanded",
14603 list->name, community_direct_str(entry->direct),
14604 community_list_config_str(entry));
14605 write++;
14606 }
14607
14608
14609 /* lcommunity-list. */
14610 cm = community_list_master_lookup(bgp_clist,
14611 LARGE_COMMUNITY_LIST_MASTER);
14612
14613 for (list = cm->num.head; list; list = list->next)
14614 for (entry = list->head; entry; entry = entry->next) {
14615 vty_out(vty, "ip large-community-list %s %s %s\n",
14616 list->name, community_direct_str(entry->direct),
14617 community_list_config_str(entry));
14618 write++;
14619 }
14620 for (list = cm->str.head; list; list = list->next)
14621 for (entry = list->head; entry; entry = entry->next) {
14622 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14623 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14624 ? "standard"
14625 : "expanded",
14626 list->name, community_direct_str(entry->direct),
14627 community_list_config_str(entry));
14628 write++;
14629 }
14630
14631 return write;
14632}
14633
14634static struct cmd_node community_list_node = {
14635 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 14636};
14637
d62a17ae 14638static void community_list_vty(void)
14639{
14640 install_node(&community_list_node, community_list_config_write);
14641
14642 /* Community-list. */
14643 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14644 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14645 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14646 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14647 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14648 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14649
14650 /* Extcommunity-list. */
14651 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14652 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14653 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14654 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14655 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14656 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14657
14658 /* Large Community List */
14659 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14660 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14661 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14662 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14663 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14664 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14665 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14666 install_element(CONFIG_NODE,
14667 &no_ip_lcommunity_list_name_expanded_all_cmd);
14668 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14669 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14670 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14671 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14672 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14673 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 14674}