]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd/ospfd: resolve warnings for bgp/ospf json commit
[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,
9f049418 304 struct bgp **bgp, bool use_json)
d62a17ae 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) {
9f049418
DS
324 use_json
325 ? vty_out(vty, "{}\n")
326 : vty_out(vty,
327 "View/Vrf specified is unknown: %s\n",
328 vrf_name);
d62a17ae 329 *idx = 0;
330 return 0;
331 }
332 }
333 } else {
334 *bgp = bgp_get_default();
335 if (!*bgp) {
9f049418
DS
336 use_json
337 ? vty_out(vty, "{}\n")
338 : vty_out(vty,
339 "Unable to find default BGP instance\n");
d62a17ae 340 *idx = 0;
341 return 0;
342 }
343 }
344
345 if (argv_find_and_parse_afi(argv, argc, idx, afi))
346 argv_find_and_parse_safi(argv, argc, idx, safi);
347
348 *idx += 1;
349 return *idx;
350}
351
352static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
353{
354 struct interface *ifp = NULL;
355
356 if (su->sa.sa_family == AF_INET)
357 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
358 else if (su->sa.sa_family == AF_INET6)
359 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
360 su->sin6.sin6_scope_id,
361 bgp->vrf_id);
362
363 if (ifp)
364 return 1;
365
366 return 0;
718e3744 367}
368
369/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
370/* This is used only for configuration, so disallow if attempted on
371 * a dynamic neighbor.
372 */
d62a17ae 373static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
374{
375 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
376 int ret;
377 union sockunion su;
378 struct peer *peer;
379
380 if (!bgp) {
381 return NULL;
382 }
383
384 ret = str2sockunion(ip_str, &su);
385 if (ret < 0) {
386 peer = peer_lookup_by_conf_if(bgp, ip_str);
387 if (!peer) {
388 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
389 == NULL) {
390 vty_out(vty,
391 "%% Malformed address or name: %s\n",
392 ip_str);
393 return NULL;
394 }
395 }
396 } else {
397 peer = peer_lookup(bgp, &su);
398 if (!peer) {
399 vty_out(vty,
400 "%% Specify remote-as or peer-group commands first\n");
401 return NULL;
402 }
403 if (peer_dynamic_neighbor(peer)) {
404 vty_out(vty,
405 "%% Operation not allowed on a dynamic neighbor\n");
406 return NULL;
407 }
408 }
409 return peer;
718e3744 410}
411
412/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
413/* This is used only for configuration, so disallow if attempted on
414 * a dynamic neighbor.
415 */
d62a17ae 416struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
417{
418 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
419 int ret;
420 union sockunion su;
421 struct peer *peer = NULL;
422 struct peer_group *group = NULL;
423
424 if (!bgp) {
425 return NULL;
426 }
427
428 ret = str2sockunion(peer_str, &su);
429 if (ret == 0) {
430 /* IP address, locate peer. */
431 peer = peer_lookup(bgp, &su);
432 } else {
433 /* Not IP, could match either peer configured on interface or a
434 * group. */
435 peer = peer_lookup_by_conf_if(bgp, peer_str);
436 if (!peer)
437 group = peer_group_lookup(bgp, peer_str);
438 }
439
440 if (peer) {
441 if (peer_dynamic_neighbor(peer)) {
442 vty_out(vty,
443 "%% Operation not allowed on a dynamic neighbor\n");
444 return NULL;
445 }
446
447 return peer;
448 }
449
450 if (group)
451 return group->conf;
452
453 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
454
455 return NULL;
456}
457
458int bgp_vty_return(struct vty *vty, int ret)
459{
460 const char *str = NULL;
461
462 switch (ret) {
463 case BGP_ERR_INVALID_VALUE:
464 str = "Invalid value";
465 break;
466 case BGP_ERR_INVALID_FLAG:
467 str = "Invalid flag";
468 break;
469 case BGP_ERR_PEER_GROUP_SHUTDOWN:
470 str = "Peer-group has been shutdown. Activate the peer-group first";
471 break;
472 case BGP_ERR_PEER_FLAG_CONFLICT:
473 str = "Can't set override-capability and strict-capability-match at the same time";
474 break;
475 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
476 str = "Specify remote-as or peer-group remote AS first";
477 break;
478 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
479 str = "Cannot change the peer-group. Deconfigure first";
480 break;
481 case BGP_ERR_PEER_GROUP_MISMATCH:
482 str = "Peer is not a member of this peer-group";
483 break;
484 case BGP_ERR_PEER_FILTER_CONFLICT:
485 str = "Prefix/distribute list can not co-exist";
486 break;
487 case BGP_ERR_NOT_INTERNAL_PEER:
488 str = "Invalid command. Not an internal neighbor";
489 break;
490 case BGP_ERR_REMOVE_PRIVATE_AS:
491 str = "remove-private-AS cannot be configured for IBGP peers";
492 break;
493 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
494 str = "Local-AS allowed only for EBGP peers";
495 break;
496 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
497 str = "Cannot have local-as same as BGP AS number";
498 break;
499 case BGP_ERR_TCPSIG_FAILED:
500 str = "Error while applying TCP-Sig to session(s)";
501 break;
502 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
503 str = "ebgp-multihop and ttl-security cannot be configured together";
504 break;
505 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
506 str = "ttl-security only allowed for EBGP peers";
507 break;
508 case BGP_ERR_AS_OVERRIDE:
509 str = "as-override cannot be configured for IBGP peers";
510 break;
511 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
512 str = "Invalid limit for number of dynamic neighbors";
513 break;
514 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
515 str = "Dynamic neighbor listen range already exists";
516 break;
517 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
518 str = "Operation not allowed on a dynamic neighbor";
519 break;
520 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
521 str = "Operation not allowed on a directly connected neighbor";
522 break;
523 case BGP_ERR_PEER_SAFI_CONFLICT:
524 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
525 break;
526 }
527 if (str) {
528 vty_out(vty, "%% %s\n", str);
529 return CMD_WARNING_CONFIG_FAILED;
530 }
531 return CMD_SUCCESS;
718e3744 532}
533
7aafcaca 534/* BGP clear sort. */
d62a17ae 535enum clear_sort {
536 clear_all,
537 clear_peer,
538 clear_group,
539 clear_external,
540 clear_as
7aafcaca
DS
541};
542
d62a17ae 543static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
544 safi_t safi, int error)
545{
546 switch (error) {
547 case BGP_ERR_AF_UNCONFIGURED:
548 vty_out(vty,
549 "%%BGP: Enable %s address family for the neighbor %s\n",
550 afi_safi_print(afi, safi), peer->host);
551 break;
552 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
553 vty_out(vty,
554 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
555 peer->host);
556 break;
557 default:
558 break;
559 }
7aafcaca
DS
560}
561
562/* `clear ip bgp' functions. */
d62a17ae 563static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
564 enum clear_sort sort, enum bgp_clear_type stype,
565 const char *arg)
566{
567 int ret;
3ae8bfa5 568 bool found = false;
d62a17ae 569 struct peer *peer;
570 struct listnode *node, *nnode;
571
572 /* Clear all neighbors. */
573 /*
574 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
575 * nodes on the BGP instance as that may get freed if it is a
576 * doppelganger
d62a17ae 577 */
578 if (sort == clear_all) {
579 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
3ae8bfa5
PM
580 if (!peer->afc[afi][safi])
581 continue;
582
d62a17ae 583 if (stype == BGP_CLEAR_SOFT_NONE)
584 ret = peer_clear(peer, &nnode);
d62a17ae 585 else
3ae8bfa5 586 ret = peer_clear_soft(peer, afi, safi, stype);
d62a17ae 587
588 if (ret < 0)
589 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
590 else
591 found = true;
04b6bdc0 592 }
d62a17ae 593
594 /* This is to apply read-only mode on this clear. */
595 if (stype == BGP_CLEAR_SOFT_NONE)
596 bgp->update_delay_over = 0;
597
3ae8bfa5
PM
598 if (!found)
599 vty_out(vty, "%%BGP: No %s peer configured",
600 afi_safi_print(afi, safi));
601
d62a17ae 602 return CMD_SUCCESS;
7aafcaca
DS
603 }
604
3ae8bfa5 605 /* Clear specified neighbor. */
d62a17ae 606 if (sort == clear_peer) {
607 union sockunion su;
d62a17ae 608
609 /* Make sockunion for lookup. */
610 ret = str2sockunion(arg, &su);
611 if (ret < 0) {
612 peer = peer_lookup_by_conf_if(bgp, arg);
613 if (!peer) {
614 peer = peer_lookup_by_hostname(bgp, arg);
615 if (!peer) {
616 vty_out(vty,
617 "Malformed address or name: %s\n",
618 arg);
619 return CMD_WARNING;
620 }
621 }
622 } else {
623 peer = peer_lookup(bgp, &su);
624 if (!peer) {
625 vty_out(vty,
626 "%%BGP: Unknown neighbor - \"%s\"\n",
627 arg);
628 return CMD_WARNING;
629 }
630 }
7aafcaca 631
3ae8bfa5
PM
632 if (!peer->afc[afi][safi])
633 ret = BGP_ERR_AF_UNCONFIGURED;
634 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 635 ret = peer_clear(peer, NULL);
636 else
637 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 638
d62a17ae 639 if (ret < 0)
640 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 641
d62a17ae 642 return CMD_SUCCESS;
7aafcaca 643 }
7aafcaca 644
3ae8bfa5 645 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 646 if (sort == clear_group) {
647 struct peer_group *group;
7aafcaca 648
d62a17ae 649 group = peer_group_lookup(bgp, arg);
650 if (!group) {
651 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
652 return CMD_WARNING;
653 }
654
655 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
d62a17ae 656 if (!peer->afc[afi][safi])
657 continue;
658
3ae8bfa5
PM
659 if (stype == BGP_CLEAR_SOFT_NONE)
660 ret = peer_clear(peer, NULL);
661 else
662 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 663
d62a17ae 664 if (ret < 0)
665 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
666 else
667 found = true;
d62a17ae 668 }
3ae8bfa5
PM
669
670 if (!found)
671 vty_out(vty,
672 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
673 afi_safi_print(afi, safi), arg);
674
d62a17ae 675 return CMD_SUCCESS;
7aafcaca 676 }
7aafcaca 677
3ae8bfa5 678 /* Clear all external (eBGP) neighbors. */
d62a17ae 679 if (sort == clear_external) {
680 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
681 if (peer->sort == BGP_PEER_IBGP)
682 continue;
7aafcaca 683
3ae8bfa5
PM
684 if (!peer->afc[afi][safi])
685 continue;
686
d62a17ae 687 if (stype == BGP_CLEAR_SOFT_NONE)
688 ret = peer_clear(peer, &nnode);
689 else
690 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 691
d62a17ae 692 if (ret < 0)
693 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
694 else
695 found = true;
d62a17ae 696 }
3ae8bfa5
PM
697
698 if (!found)
699 vty_out(vty,
700 "%%BGP: No external %s peer is configured\n",
701 afi_safi_print(afi, safi));
702
d62a17ae 703 return CMD_SUCCESS;
704 }
705
3ae8bfa5 706 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 707 if (sort == clear_as) {
3ae8bfa5 708 as_t as = strtoul(arg, NULL, 10);
d62a17ae 709
710 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
711 if (peer->as != as)
712 continue;
713
3ae8bfa5
PM
714 if (!peer->afc[afi][safi])
715 ret = BGP_ERR_AF_UNCONFIGURED;
716 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 717 ret = peer_clear(peer, &nnode);
718 else
719 ret = peer_clear_soft(peer, afi, safi, stype);
720
721 if (ret < 0)
722 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
723 else
724 found = true;
d62a17ae 725 }
3ae8bfa5
PM
726
727 if (!found)
d62a17ae 728 vty_out(vty,
3ae8bfa5
PM
729 "%%BGP: No %s peer is configured with AS %s\n",
730 afi_safi_print(afi, safi), arg);
731
d62a17ae 732 return CMD_SUCCESS;
733 }
734
735 return CMD_SUCCESS;
736}
737
738static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
739 safi_t safi, enum clear_sort sort,
740 enum bgp_clear_type stype, const char *arg)
741{
742 struct bgp *bgp;
743
744 /* BGP structure lookup. */
745 if (name) {
746 bgp = bgp_lookup_by_name(name);
747 if (bgp == NULL) {
748 vty_out(vty, "Can't find BGP instance %s\n", name);
749 return CMD_WARNING;
750 }
751 } else {
752 bgp = bgp_get_default();
753 if (bgp == NULL) {
754 vty_out(vty, "No BGP process is configured\n");
755 return CMD_WARNING;
756 }
757 }
758
759 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
760}
761
762/* clear soft inbound */
d62a17ae 763static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 764{
d62a17ae 765 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
766 BGP_CLEAR_SOFT_IN, NULL);
767 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
768 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
769}
770
771/* clear soft outbound */
d62a17ae 772static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 773{
d62a17ae 774 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
775 BGP_CLEAR_SOFT_OUT, NULL);
776 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
777 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
778}
779
780
f787d7a0 781#ifndef VTYSH_EXTRACT_PL
2e4c2296 782#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
783#endif
784
718e3744 785/* BGP global configuration. */
bee57a7a 786#if (CONFDATE > 20190601)
1cc40660
DS
787CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
788CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
789#endif
790DEFUN_HIDDEN (bgp_multiple_instance_func,
791 bgp_multiple_instance_cmd,
792 "bgp multiple-instance",
793 BGP_STR
794 "Enable bgp multiple instance\n")
718e3744 795{
d62a17ae 796 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
797 return CMD_SUCCESS;
718e3744 798}
799
1cc40660 800DEFUN_HIDDEN (no_bgp_multiple_instance,
718e3744 801 no_bgp_multiple_instance_cmd,
802 "no bgp multiple-instance",
803 NO_STR
804 BGP_STR
805 "BGP multiple instance\n")
806{
d62a17ae 807 int ret;
718e3744 808
1cc40660
DS
809 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
810 vty_out(vty, "if you are using this please let the developers know\n");
b7cd3069 811 zlog_info("Deprecated option: `bgp multiple-instance` being used");
d62a17ae 812 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
813 if (ret < 0) {
814 vty_out(vty, "%% There are more than two BGP instances\n");
815 return CMD_WARNING_CONFIG_FAILED;
816 }
817 return CMD_SUCCESS;
718e3744 818}
819
bee57a7a 820#if (CONFDATE > 20190601)
798467a2
DS
821CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
822CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
823#endif
824DEFUN_HIDDEN (bgp_config_type,
825 bgp_config_type_cmd,
826 "bgp config-type <cisco|zebra>",
827 BGP_STR
828 "Configuration type\n"
829 "cisco\n"
830 "zebra\n")
718e3744 831{
d62a17ae 832 int idx = 0;
798467a2
DS
833 if (argv_find(argv, argc, "cisco", &idx)) {
834 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
835 vty_out(vty, "if you are using this please let the developers know!\n");
b7cd3069 836 zlog_info("Deprecated option: `bgp config-type cisco` being used");
d62a17ae 837 bgp_option_set(BGP_OPT_CONFIG_CISCO);
798467a2 838 } else
d62a17ae 839 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 840
d62a17ae 841 return CMD_SUCCESS;
718e3744 842}
843
798467a2
DS
844DEFUN_HIDDEN (no_bgp_config_type,
845 no_bgp_config_type_cmd,
846 "no bgp config-type [<cisco|zebra>]",
847 NO_STR
848 BGP_STR
849 "Display configuration type\n"
850 "cisco\n"
851 "zebra\n")
718e3744 852{
d62a17ae 853 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
854 return CMD_SUCCESS;
718e3744 855}
856
813d4307 857
718e3744 858DEFUN (no_synchronization,
859 no_synchronization_cmd,
860 "no synchronization",
861 NO_STR
862 "Perform IGP synchronization\n")
863{
d62a17ae 864 return CMD_SUCCESS;
718e3744 865}
866
867DEFUN (no_auto_summary,
868 no_auto_summary_cmd,
869 "no auto-summary",
870 NO_STR
871 "Enable automatic network number summarization\n")
872{
d62a17ae 873 return CMD_SUCCESS;
718e3744 874}
3d515fd9 875
718e3744 876/* "router bgp" commands. */
505e5056 877DEFUN_NOSH (router_bgp,
f412b39a 878 router_bgp_cmd,
18c57037 879 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 880 ROUTER_STR
881 BGP_STR
31500417
DW
882 AS_STR
883 BGP_INSTANCE_HELP_STR)
718e3744 884{
d62a17ae 885 int idx_asn = 2;
886 int idx_view_vrf = 3;
887 int idx_vrf = 4;
888 int ret;
889 as_t as;
890 struct bgp *bgp;
891 const char *name = NULL;
892 enum bgp_instance_type inst_type;
893
894 // "router bgp" without an ASN
895 if (argc == 2) {
896 // Pending: Make VRF option available for ASN less config
897 bgp = bgp_get_default();
898
899 if (bgp == NULL) {
900 vty_out(vty, "%% No BGP process is configured\n");
901 return CMD_WARNING_CONFIG_FAILED;
902 }
903
904 if (listcount(bm->bgp) > 1) {
996c9314 905 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 906 return CMD_WARNING_CONFIG_FAILED;
907 }
908 }
909
910 // "router bgp X"
911 else {
912 as = strtoul(argv[idx_asn]->arg, NULL, 10);
913
914 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
915 if (argc > 3) {
916 name = argv[idx_vrf]->arg;
917
918 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
919 inst_type = BGP_INSTANCE_TYPE_VRF;
920 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
921 inst_type = BGP_INSTANCE_TYPE_VIEW;
922 }
923
924 ret = bgp_get(&bgp, &as, name, inst_type);
925 switch (ret) {
926 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
927 vty_out(vty,
928 "Please specify 'bgp multiple-instance' first\n");
929 return CMD_WARNING_CONFIG_FAILED;
930 case BGP_ERR_AS_MISMATCH:
931 vty_out(vty, "BGP is already running; AS is %u\n", as);
932 return CMD_WARNING_CONFIG_FAILED;
933 case BGP_ERR_INSTANCE_MISMATCH:
934 vty_out(vty,
935 "BGP instance name and AS number mismatch\n");
936 vty_out(vty,
937 "BGP instance is already running; AS is %u\n",
938 as);
939 return CMD_WARNING_CONFIG_FAILED;
940 }
941
3bd70bf8
PZ
942 /*
943 * If we just instantiated the default instance, complete
944 * any pending VRF-VPN leaking that was configured via
945 * earlier "router bgp X vrf FOO" blocks.
946 */
947 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
948 vpn_leak_postchange_all();
949
d62a17ae 950 /* Pending: handle when user tries to change a view to vrf n vv.
951 */
952 }
953
0b5131c9
MK
954 /* unset the auto created flag as the user config is now present */
955 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 956 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
957
958 return CMD_SUCCESS;
718e3744 959}
960
718e3744 961/* "no router bgp" commands. */
962DEFUN (no_router_bgp,
963 no_router_bgp_cmd,
18c57037 964 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 965 NO_STR
966 ROUTER_STR
967 BGP_STR
31500417
DW
968 AS_STR
969 BGP_INSTANCE_HELP_STR)
718e3744 970{
d62a17ae 971 int idx_asn = 3;
972 int idx_vrf = 5;
973 as_t as;
974 struct bgp *bgp;
975 const char *name = NULL;
718e3744 976
d62a17ae 977 // "no router bgp" without an ASN
978 if (argc == 3) {
979 // Pending: Make VRF option available for ASN less config
980 bgp = bgp_get_default();
718e3744 981
d62a17ae 982 if (bgp == NULL) {
983 vty_out(vty, "%% No BGP process is configured\n");
984 return CMD_WARNING_CONFIG_FAILED;
985 }
7fb21a9f 986
d62a17ae 987 if (listcount(bm->bgp) > 1) {
996c9314 988 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 989 return CMD_WARNING_CONFIG_FAILED;
990 }
0b5131c9
MK
991
992 if (bgp->l3vni) {
993 vty_out(vty, "%% Please unconfigure l3vni %u",
994 bgp->l3vni);
995 return CMD_WARNING_CONFIG_FAILED;
996 }
d62a17ae 997 } else {
998 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 999
d62a17ae 1000 if (argc > 4)
1001 name = argv[idx_vrf]->arg;
7fb21a9f 1002
d62a17ae 1003 /* Lookup bgp structure. */
1004 bgp = bgp_lookup(as, name);
1005 if (!bgp) {
1006 vty_out(vty, "%% Can't find BGP instance\n");
1007 return CMD_WARNING_CONFIG_FAILED;
1008 }
0b5131c9
MK
1009
1010 if (bgp->l3vni) {
1011 vty_out(vty, "%% Please unconfigure l3vni %u",
1012 bgp->l3vni);
1013 return CMD_WARNING_CONFIG_FAILED;
1014 }
d62a17ae 1015 }
718e3744 1016
d62a17ae 1017 bgp_delete(bgp);
718e3744 1018
d62a17ae 1019 return CMD_SUCCESS;
718e3744 1020}
1021
6b0655a2 1022
718e3744 1023/* BGP router-id. */
1024
f787d7a0 1025DEFPY (bgp_router_id,
718e3744 1026 bgp_router_id_cmd,
1027 "bgp router-id A.B.C.D",
1028 BGP_STR
1029 "Override configured router identifier\n"
1030 "Manually configured router identifier\n")
1031{
d62a17ae 1032 VTY_DECLVAR_CONTEXT(bgp, bgp);
1033 bgp_router_id_static_set(bgp, router_id);
1034 return CMD_SUCCESS;
718e3744 1035}
1036
f787d7a0 1037DEFPY (no_bgp_router_id,
718e3744 1038 no_bgp_router_id_cmd,
31500417 1039 "no bgp router-id [A.B.C.D]",
718e3744 1040 NO_STR
1041 BGP_STR
31500417
DW
1042 "Override configured router identifier\n"
1043 "Manually configured router identifier\n")
718e3744 1044{
d62a17ae 1045 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1046
d62a17ae 1047 if (router_id_str) {
1048 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1049 vty_out(vty, "%% BGP router-id doesn't match\n");
1050 return CMD_WARNING_CONFIG_FAILED;
1051 }
e018c7cc 1052 }
718e3744 1053
d62a17ae 1054 router_id.s_addr = 0;
1055 bgp_router_id_static_set(bgp, router_id);
718e3744 1056
d62a17ae 1057 return CMD_SUCCESS;
718e3744 1058}
1059
6b0655a2 1060
718e3744 1061/* BGP Cluster ID. */
718e3744 1062DEFUN (bgp_cluster_id,
1063 bgp_cluster_id_cmd,
838758ac 1064 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1065 BGP_STR
1066 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1067 "Route-Reflector Cluster-id in IP address format\n"
1068 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1069{
d62a17ae 1070 VTY_DECLVAR_CONTEXT(bgp, bgp);
1071 int idx_ipv4 = 2;
1072 int ret;
1073 struct in_addr cluster;
718e3744 1074
d62a17ae 1075 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1076 if (!ret) {
1077 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1078 return CMD_WARNING_CONFIG_FAILED;
1079 }
718e3744 1080
d62a17ae 1081 bgp_cluster_id_set(bgp, &cluster);
1082 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1083
d62a17ae 1084 return CMD_SUCCESS;
718e3744 1085}
1086
718e3744 1087DEFUN (no_bgp_cluster_id,
1088 no_bgp_cluster_id_cmd,
c7178fe7 1089 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1090 NO_STR
1091 BGP_STR
838758ac
DW
1092 "Configure Route-Reflector Cluster-id\n"
1093 "Route-Reflector Cluster-id in IP address format\n"
1094 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1095{
d62a17ae 1096 VTY_DECLVAR_CONTEXT(bgp, bgp);
1097 bgp_cluster_id_unset(bgp);
1098 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1099
d62a17ae 1100 return CMD_SUCCESS;
718e3744 1101}
1102
718e3744 1103DEFUN (bgp_confederation_identifier,
1104 bgp_confederation_identifier_cmd,
9ccf14f7 1105 "bgp confederation identifier (1-4294967295)",
718e3744 1106 "BGP specific commands\n"
1107 "AS confederation parameters\n"
1108 "AS number\n"
1109 "Set routing domain confederation AS\n")
1110{
d62a17ae 1111 VTY_DECLVAR_CONTEXT(bgp, bgp);
1112 int idx_number = 3;
1113 as_t as;
718e3744 1114
d62a17ae 1115 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1116
d62a17ae 1117 bgp_confederation_id_set(bgp, as);
718e3744 1118
d62a17ae 1119 return CMD_SUCCESS;
718e3744 1120}
1121
1122DEFUN (no_bgp_confederation_identifier,
1123 no_bgp_confederation_identifier_cmd,
838758ac 1124 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1125 NO_STR
1126 "BGP specific commands\n"
1127 "AS confederation parameters\n"
3a2d747c
QY
1128 "AS number\n"
1129 "Set routing domain confederation AS\n")
718e3744 1130{
d62a17ae 1131 VTY_DECLVAR_CONTEXT(bgp, bgp);
1132 bgp_confederation_id_unset(bgp);
718e3744 1133
d62a17ae 1134 return CMD_SUCCESS;
718e3744 1135}
1136
718e3744 1137DEFUN (bgp_confederation_peers,
1138 bgp_confederation_peers_cmd,
12dcf78e 1139 "bgp confederation peers (1-4294967295)...",
718e3744 1140 "BGP specific commands\n"
1141 "AS confederation parameters\n"
1142 "Peer ASs in BGP confederation\n"
1143 AS_STR)
1144{
d62a17ae 1145 VTY_DECLVAR_CONTEXT(bgp, bgp);
1146 int idx_asn = 3;
1147 as_t as;
1148 int i;
718e3744 1149
d62a17ae 1150 for (i = idx_asn; i < argc; i++) {
1151 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1152
d62a17ae 1153 if (bgp->as == as) {
1154 vty_out(vty,
1155 "%% Local member-AS not allowed in confed peer list\n");
1156 continue;
1157 }
718e3744 1158
d62a17ae 1159 bgp_confederation_peers_add(bgp, as);
1160 }
1161 return CMD_SUCCESS;
718e3744 1162}
1163
1164DEFUN (no_bgp_confederation_peers,
1165 no_bgp_confederation_peers_cmd,
e83a9414 1166 "no bgp confederation peers (1-4294967295)...",
718e3744 1167 NO_STR
1168 "BGP specific commands\n"
1169 "AS confederation parameters\n"
1170 "Peer ASs in BGP confederation\n"
1171 AS_STR)
1172{
d62a17ae 1173 VTY_DECLVAR_CONTEXT(bgp, bgp);
1174 int idx_asn = 4;
1175 as_t as;
1176 int i;
718e3744 1177
d62a17ae 1178 for (i = idx_asn; i < argc; i++) {
1179 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1180
d62a17ae 1181 bgp_confederation_peers_remove(bgp, as);
1182 }
1183 return CMD_SUCCESS;
718e3744 1184}
6b0655a2 1185
5e242b0d
DS
1186/**
1187 * Central routine for maximum-paths configuration.
1188 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1189 * @set: 1 for setting values, 0 for removing the max-paths config.
1190 */
d62a17ae 1191static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1192 const char *mpaths, uint16_t options,
d62a17ae 1193 int set)
1194{
1195 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1196 uint16_t maxpaths = 0;
d62a17ae 1197 int ret;
1198 afi_t afi;
1199 safi_t safi;
1200
1201 afi = bgp_node_afi(vty);
1202 safi = bgp_node_safi(vty);
1203
1204 if (set) {
1205 maxpaths = strtol(mpaths, NULL, 10);
1206 if (maxpaths > multipath_num) {
1207 vty_out(vty,
1208 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1209 maxpaths, multipath_num);
1210 return CMD_WARNING_CONFIG_FAILED;
1211 }
1212 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1213 options);
1214 } else
1215 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1216
1217 if (ret < 0) {
1218 vty_out(vty,
1219 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1220 (set == 1) ? "" : "un",
1221 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1222 maxpaths, afi, safi);
1223 return CMD_WARNING_CONFIG_FAILED;
1224 }
1225
1226 bgp_recalculate_all_bestpaths(bgp);
1227
1228 return CMD_SUCCESS;
165b5fff
JB
1229}
1230
abc920f8
DS
1231DEFUN (bgp_maxmed_admin,
1232 bgp_maxmed_admin_cmd,
1233 "bgp max-med administrative ",
1234 BGP_STR
1235 "Advertise routes with max-med\n"
1236 "Administratively applied, for an indefinite period\n")
1237{
d62a17ae 1238 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1239
d62a17ae 1240 bgp->v_maxmed_admin = 1;
1241 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1242
d62a17ae 1243 bgp_maxmed_update(bgp);
abc920f8 1244
d62a17ae 1245 return CMD_SUCCESS;
abc920f8
DS
1246}
1247
1248DEFUN (bgp_maxmed_admin_medv,
1249 bgp_maxmed_admin_medv_cmd,
4668a151 1250 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1251 BGP_STR
1252 "Advertise routes with max-med\n"
1253 "Administratively applied, for an indefinite period\n"
1254 "Max MED value to be used\n")
1255{
d62a17ae 1256 VTY_DECLVAR_CONTEXT(bgp, bgp);
1257 int idx_number = 3;
abc920f8 1258
d62a17ae 1259 bgp->v_maxmed_admin = 1;
1260 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1261
d62a17ae 1262 bgp_maxmed_update(bgp);
abc920f8 1263
d62a17ae 1264 return CMD_SUCCESS;
abc920f8
DS
1265}
1266
1267DEFUN (no_bgp_maxmed_admin,
1268 no_bgp_maxmed_admin_cmd,
4668a151 1269 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1270 NO_STR
1271 BGP_STR
1272 "Advertise routes with max-med\n"
838758ac
DW
1273 "Administratively applied, for an indefinite period\n"
1274 "Max MED value to be used\n")
abc920f8 1275{
d62a17ae 1276 VTY_DECLVAR_CONTEXT(bgp, bgp);
1277 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1278 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1279 bgp_maxmed_update(bgp);
abc920f8 1280
d62a17ae 1281 return CMD_SUCCESS;
abc920f8
DS
1282}
1283
abc920f8
DS
1284DEFUN (bgp_maxmed_onstartup,
1285 bgp_maxmed_onstartup_cmd,
4668a151 1286 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1287 BGP_STR
1288 "Advertise routes with max-med\n"
1289 "Effective on a startup\n"
1290 "Time (seconds) period for max-med\n"
1291 "Max MED value to be used\n")
1292{
d62a17ae 1293 VTY_DECLVAR_CONTEXT(bgp, bgp);
1294 int idx = 0;
4668a151 1295
d62a17ae 1296 argv_find(argv, argc, "(5-86400)", &idx);
1297 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1298 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1299 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1300 else
1301 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1302
d62a17ae 1303 bgp_maxmed_update(bgp);
abc920f8 1304
d62a17ae 1305 return CMD_SUCCESS;
abc920f8
DS
1306}
1307
1308DEFUN (no_bgp_maxmed_onstartup,
1309 no_bgp_maxmed_onstartup_cmd,
4668a151 1310 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1311 NO_STR
1312 BGP_STR
1313 "Advertise routes with max-med\n"
838758ac
DW
1314 "Effective on a startup\n"
1315 "Time (seconds) period for max-med\n"
1316 "Max MED value to be used\n")
abc920f8 1317{
d62a17ae 1318 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1319
d62a17ae 1320 /* Cancel max-med onstartup if its on */
1321 if (bgp->t_maxmed_onstartup) {
1322 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1323 bgp->maxmed_onstartup_over = 1;
1324 }
abc920f8 1325
d62a17ae 1326 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1327 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1328
d62a17ae 1329 bgp_maxmed_update(bgp);
abc920f8 1330
d62a17ae 1331 return CMD_SUCCESS;
abc920f8
DS
1332}
1333
d62a17ae 1334static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1335 const char *wait)
f188f2c4 1336{
d62a17ae 1337 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1338 uint16_t update_delay;
1339 uint16_t establish_wait;
f188f2c4 1340
d62a17ae 1341 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1342
d62a17ae 1343 if (!wait) /* update-delay <delay> */
1344 {
1345 bgp->v_update_delay = update_delay;
1346 bgp->v_establish_wait = bgp->v_update_delay;
1347 return CMD_SUCCESS;
1348 }
f188f2c4 1349
d62a17ae 1350 /* update-delay <delay> <establish-wait> */
1351 establish_wait = atoi(wait);
1352 if (update_delay < establish_wait) {
1353 vty_out(vty,
1354 "%%Failed: update-delay less than the establish-wait!\n");
1355 return CMD_WARNING_CONFIG_FAILED;
1356 }
f188f2c4 1357
d62a17ae 1358 bgp->v_update_delay = update_delay;
1359 bgp->v_establish_wait = establish_wait;
f188f2c4 1360
d62a17ae 1361 return CMD_SUCCESS;
f188f2c4
DS
1362}
1363
d62a17ae 1364static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1365{
d62a17ae 1366 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1367
d62a17ae 1368 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1369 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1370
d62a17ae 1371 return CMD_SUCCESS;
f188f2c4
DS
1372}
1373
2b791107 1374void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1375{
d62a17ae 1376 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1377 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1378 if (bgp->v_update_delay != bgp->v_establish_wait)
1379 vty_out(vty, " %d", bgp->v_establish_wait);
1380 vty_out(vty, "\n");
1381 }
f188f2c4
DS
1382}
1383
1384
1385/* Update-delay configuration */
1386DEFUN (bgp_update_delay,
1387 bgp_update_delay_cmd,
6147e2c6 1388 "update-delay (0-3600)",
f188f2c4
DS
1389 "Force initial delay for best-path and updates\n"
1390 "Seconds\n")
1391{
d62a17ae 1392 int idx_number = 1;
1393 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1394}
1395
1396DEFUN (bgp_update_delay_establish_wait,
1397 bgp_update_delay_establish_wait_cmd,
6147e2c6 1398 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1399 "Force initial delay for best-path and updates\n"
1400 "Seconds\n"
f188f2c4
DS
1401 "Seconds\n")
1402{
d62a17ae 1403 int idx_number = 1;
1404 int idx_number_2 = 2;
1405 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1406 argv[idx_number_2]->arg);
f188f2c4
DS
1407}
1408
1409/* Update-delay deconfiguration */
1410DEFUN (no_bgp_update_delay,
1411 no_bgp_update_delay_cmd,
838758ac
DW
1412 "no update-delay [(0-3600) [(1-3600)]]",
1413 NO_STR
f188f2c4 1414 "Force initial delay for best-path and updates\n"
838758ac 1415 "Seconds\n"
7111c1a0 1416 "Seconds\n")
f188f2c4 1417{
d62a17ae 1418 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1419}
1420
5e242b0d 1421
d62a17ae 1422static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1423 char set)
cb1faec9 1424{
d62a17ae 1425 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1426
555e09d4
QY
1427 if (set) {
1428 uint32_t quanta = strtoul(num, NULL, 10);
1429 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1430 memory_order_relaxed);
1431 } else {
1432 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1433 memory_order_relaxed);
1434 }
1435
1436 return CMD_SUCCESS;
1437}
1438
1439static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1440 char set)
1441{
1442 VTY_DECLVAR_CONTEXT(bgp, bgp);
1443
1444 if (set) {
1445 uint32_t quanta = strtoul(num, NULL, 10);
1446 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1447 memory_order_relaxed);
1448 } else {
1449 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1450 memory_order_relaxed);
1451 }
cb1faec9 1452
d62a17ae 1453 return CMD_SUCCESS;
cb1faec9
DS
1454}
1455
2b791107 1456void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1457{
555e09d4
QY
1458 uint32_t quanta =
1459 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1460 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1461 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1462}
1463
555e09d4
QY
1464void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1465{
1466 uint32_t quanta =
1467 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1468 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1469 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1470}
cb1faec9 1471
555e09d4 1472/* Packet quanta configuration */
cb1faec9
DS
1473DEFUN (bgp_wpkt_quanta,
1474 bgp_wpkt_quanta_cmd,
555e09d4 1475 "write-quanta (1-10)",
cb1faec9
DS
1476 "How many packets to write to peer socket per run\n"
1477 "Number of packets\n")
1478{
d62a17ae 1479 int idx_number = 1;
1480 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1481}
1482
cb1faec9
DS
1483DEFUN (no_bgp_wpkt_quanta,
1484 no_bgp_wpkt_quanta_cmd,
555e09d4 1485 "no write-quanta (1-10)",
d7fa34c1 1486 NO_STR
555e09d4 1487 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1488 "Number of packets\n")
1489{
d62a17ae 1490 int idx_number = 2;
1491 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1492}
1493
555e09d4
QY
1494DEFUN (bgp_rpkt_quanta,
1495 bgp_rpkt_quanta_cmd,
1496 "read-quanta (1-10)",
1497 "How many packets to read from peer socket per I/O cycle\n"
1498 "Number of packets\n")
1499{
1500 int idx_number = 1;
1501 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1502}
1503
1504DEFUN (no_bgp_rpkt_quanta,
1505 no_bgp_rpkt_quanta_cmd,
1506 "no read-quanta (1-10)",
1507 NO_STR
1508 "How many packets to read from peer socket per I/O cycle\n"
1509 "Number of packets\n")
1510{
1511 int idx_number = 2;
1512 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1513}
1514
2b791107 1515void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1516{
37a333fe 1517 if (!bgp->heuristic_coalesce)
d62a17ae 1518 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1519}
1520
1521
1522DEFUN (bgp_coalesce_time,
1523 bgp_coalesce_time_cmd,
6147e2c6 1524 "coalesce-time (0-4294967295)",
3f9c7369
DS
1525 "Subgroup coalesce timer\n"
1526 "Subgroup coalesce timer value (in ms)\n")
1527{
d62a17ae 1528 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1529
d62a17ae 1530 int idx = 0;
1531 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1532 bgp->heuristic_coalesce = false;
d62a17ae 1533 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1534 return CMD_SUCCESS;
3f9c7369
DS
1535}
1536
1537DEFUN (no_bgp_coalesce_time,
1538 no_bgp_coalesce_time_cmd,
6147e2c6 1539 "no coalesce-time (0-4294967295)",
3a2d747c 1540 NO_STR
3f9c7369
DS
1541 "Subgroup coalesce timer\n"
1542 "Subgroup coalesce timer value (in ms)\n")
1543{
d62a17ae 1544 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1545
37a333fe 1546 bgp->heuristic_coalesce = true;
d62a17ae 1547 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1548 return CMD_SUCCESS;
3f9c7369
DS
1549}
1550
5e242b0d
DS
1551/* Maximum-paths configuration */
1552DEFUN (bgp_maxpaths,
1553 bgp_maxpaths_cmd,
6319fd63 1554 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1555 "Forward packets over multiple paths\n"
1556 "Number of paths\n")
1557{
d62a17ae 1558 int idx_number = 1;
1559 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1560 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1561}
1562
d62a17ae 1563ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1564 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1565 "Forward packets over multiple paths\n"
1566 "Number of paths\n")
596c17ba 1567
165b5fff
JB
1568DEFUN (bgp_maxpaths_ibgp,
1569 bgp_maxpaths_ibgp_cmd,
6319fd63 1570 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1571 "Forward packets over multiple paths\n"
1572 "iBGP-multipath\n"
1573 "Number of paths\n")
1574{
d62a17ae 1575 int idx_number = 2;
1576 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1577 argv[idx_number]->arg, 0, 1);
5e242b0d 1578}
165b5fff 1579
d62a17ae 1580ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1581 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1582 "Forward packets over multiple paths\n"
1583 "iBGP-multipath\n"
1584 "Number of paths\n")
596c17ba 1585
5e242b0d
DS
1586DEFUN (bgp_maxpaths_ibgp_cluster,
1587 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1588 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1589 "Forward packets over multiple paths\n"
1590 "iBGP-multipath\n"
1591 "Number of paths\n"
1592 "Match the cluster length\n")
1593{
d62a17ae 1594 int idx_number = 2;
1595 return bgp_maxpaths_config_vty(
1596 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1597 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1598}
1599
d62a17ae 1600ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1601 "maximum-paths ibgp " CMD_RANGE_STR(
1602 1, MULTIPATH_NUM) " equal-cluster-length",
1603 "Forward packets over multiple paths\n"
1604 "iBGP-multipath\n"
1605 "Number of paths\n"
1606 "Match the cluster length\n")
596c17ba 1607
165b5fff
JB
1608DEFUN (no_bgp_maxpaths,
1609 no_bgp_maxpaths_cmd,
6319fd63 1610 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1611 NO_STR
1612 "Forward packets over multiple paths\n"
1613 "Number of paths\n")
1614{
d62a17ae 1615 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1616}
1617
d62a17ae 1618ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1619 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1620 "Forward packets over multiple paths\n"
1621 "Number of paths\n")
596c17ba 1622
165b5fff
JB
1623DEFUN (no_bgp_maxpaths_ibgp,
1624 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1625 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1626 NO_STR
1627 "Forward packets over multiple paths\n"
1628 "iBGP-multipath\n"
838758ac
DW
1629 "Number of paths\n"
1630 "Match the cluster length\n")
165b5fff 1631{
d62a17ae 1632 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1633}
1634
d62a17ae 1635ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1636 "no maximum-paths ibgp [" CMD_RANGE_STR(
1637 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1638 NO_STR
1639 "Forward packets over multiple paths\n"
1640 "iBGP-multipath\n"
1641 "Number of paths\n"
1642 "Match the cluster length\n")
596c17ba 1643
2b791107 1644void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1645 safi_t safi)
165b5fff 1646{
d62a17ae 1647 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1648 vty_out(vty, " maximum-paths %d\n",
1649 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1650 }
165b5fff 1651
d62a17ae 1652 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1653 vty_out(vty, " maximum-paths ibgp %d",
1654 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1655 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1656 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1657 vty_out(vty, " equal-cluster-length");
1658 vty_out(vty, "\n");
1659 }
165b5fff 1660}
6b0655a2 1661
718e3744 1662/* BGP timers. */
1663
1664DEFUN (bgp_timers,
1665 bgp_timers_cmd,
6147e2c6 1666 "timers bgp (0-65535) (0-65535)",
718e3744 1667 "Adjust routing timers\n"
1668 "BGP timers\n"
1669 "Keepalive interval\n"
1670 "Holdtime\n")
1671{
d62a17ae 1672 VTY_DECLVAR_CONTEXT(bgp, bgp);
1673 int idx_number = 2;
1674 int idx_number_2 = 3;
1675 unsigned long keepalive = 0;
1676 unsigned long holdtime = 0;
718e3744 1677
d62a17ae 1678 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1679 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1680
d62a17ae 1681 /* Holdtime value check. */
1682 if (holdtime < 3 && holdtime != 0) {
1683 vty_out(vty,
1684 "%% hold time value must be either 0 or greater than 3\n");
1685 return CMD_WARNING_CONFIG_FAILED;
1686 }
718e3744 1687
d62a17ae 1688 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1689
d62a17ae 1690 return CMD_SUCCESS;
718e3744 1691}
1692
1693DEFUN (no_bgp_timers,
1694 no_bgp_timers_cmd,
838758ac 1695 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1696 NO_STR
1697 "Adjust routing timers\n"
838758ac
DW
1698 "BGP timers\n"
1699 "Keepalive interval\n"
1700 "Holdtime\n")
718e3744 1701{
d62a17ae 1702 VTY_DECLVAR_CONTEXT(bgp, bgp);
1703 bgp_timers_unset(bgp);
718e3744 1704
d62a17ae 1705 return CMD_SUCCESS;
718e3744 1706}
1707
6b0655a2 1708
718e3744 1709DEFUN (bgp_client_to_client_reflection,
1710 bgp_client_to_client_reflection_cmd,
1711 "bgp client-to-client reflection",
1712 "BGP specific commands\n"
1713 "Configure client to client route reflection\n"
1714 "reflection of routes allowed\n")
1715{
d62a17ae 1716 VTY_DECLVAR_CONTEXT(bgp, bgp);
1717 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1718 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1719
d62a17ae 1720 return CMD_SUCCESS;
718e3744 1721}
1722
1723DEFUN (no_bgp_client_to_client_reflection,
1724 no_bgp_client_to_client_reflection_cmd,
1725 "no bgp client-to-client reflection",
1726 NO_STR
1727 "BGP specific commands\n"
1728 "Configure client to client route reflection\n"
1729 "reflection of routes allowed\n")
1730{
d62a17ae 1731 VTY_DECLVAR_CONTEXT(bgp, bgp);
1732 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1733 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1734
d62a17ae 1735 return CMD_SUCCESS;
718e3744 1736}
1737
1738/* "bgp always-compare-med" configuration. */
1739DEFUN (bgp_always_compare_med,
1740 bgp_always_compare_med_cmd,
1741 "bgp always-compare-med",
1742 "BGP specific commands\n"
1743 "Allow comparing MED from different neighbors\n")
1744{
d62a17ae 1745 VTY_DECLVAR_CONTEXT(bgp, bgp);
1746 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1747 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1748
d62a17ae 1749 return CMD_SUCCESS;
718e3744 1750}
1751
1752DEFUN (no_bgp_always_compare_med,
1753 no_bgp_always_compare_med_cmd,
1754 "no bgp always-compare-med",
1755 NO_STR
1756 "BGP specific commands\n"
1757 "Allow comparing MED from different neighbors\n")
1758{
d62a17ae 1759 VTY_DECLVAR_CONTEXT(bgp, bgp);
1760 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1761 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1762
d62a17ae 1763 return CMD_SUCCESS;
718e3744 1764}
6b0655a2 1765
718e3744 1766/* "bgp deterministic-med" configuration. */
1767DEFUN (bgp_deterministic_med,
1768 bgp_deterministic_med_cmd,
1769 "bgp deterministic-med",
1770 "BGP specific commands\n"
1771 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1772{
d62a17ae 1773 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1774
d62a17ae 1775 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1776 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1777 bgp_recalculate_all_bestpaths(bgp);
1778 }
7aafcaca 1779
d62a17ae 1780 return CMD_SUCCESS;
718e3744 1781}
1782
1783DEFUN (no_bgp_deterministic_med,
1784 no_bgp_deterministic_med_cmd,
1785 "no bgp deterministic-med",
1786 NO_STR
1787 "BGP specific commands\n"
1788 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1789{
d62a17ae 1790 VTY_DECLVAR_CONTEXT(bgp, bgp);
1791 int bestpath_per_as_used;
1792 afi_t afi;
1793 safi_t safi;
1794 struct peer *peer;
1795 struct listnode *node, *nnode;
1796
1797 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1798 bestpath_per_as_used = 0;
1799
1800 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc
QY
1801 FOREACH_AFI_SAFI (afi, safi)
1802 if (CHECK_FLAG(
1803 peer->af_flags[afi][safi],
1804 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1805 bestpath_per_as_used = 1;
1806 break;
1807 }
d62a17ae 1808
1809 if (bestpath_per_as_used)
1810 break;
1811 }
1812
1813 if (bestpath_per_as_used) {
1814 vty_out(vty,
1815 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1816 return CMD_WARNING_CONFIG_FAILED;
1817 } else {
1818 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1819 bgp_recalculate_all_bestpaths(bgp);
1820 }
1821 }
1822
1823 return CMD_SUCCESS;
718e3744 1824}
538621f2 1825
1826/* "bgp graceful-restart" configuration. */
1827DEFUN (bgp_graceful_restart,
1828 bgp_graceful_restart_cmd,
1829 "bgp graceful-restart",
1830 "BGP specific commands\n"
1831 "Graceful restart capability parameters\n")
1832{
d62a17ae 1833 VTY_DECLVAR_CONTEXT(bgp, bgp);
1834 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1835 return CMD_SUCCESS;
538621f2 1836}
1837
1838DEFUN (no_bgp_graceful_restart,
1839 no_bgp_graceful_restart_cmd,
1840 "no bgp graceful-restart",
1841 NO_STR
1842 "BGP specific commands\n"
1843 "Graceful restart capability parameters\n")
1844{
d62a17ae 1845 VTY_DECLVAR_CONTEXT(bgp, bgp);
1846 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1847 return CMD_SUCCESS;
538621f2 1848}
1849
93406d87 1850DEFUN (bgp_graceful_restart_stalepath_time,
1851 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1852 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1853 "BGP specific commands\n"
1854 "Graceful restart capability parameters\n"
1855 "Set the max time to hold onto restarting peer's stale paths\n"
1856 "Delay value (seconds)\n")
1857{
d62a17ae 1858 VTY_DECLVAR_CONTEXT(bgp, bgp);
1859 int idx_number = 3;
d7c0a89a 1860 uint32_t stalepath;
93406d87 1861
d62a17ae 1862 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1863 bgp->stalepath_time = stalepath;
1864 return CMD_SUCCESS;
93406d87 1865}
1866
eb6f1b41
PG
1867DEFUN (bgp_graceful_restart_restart_time,
1868 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1869 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1870 "BGP specific commands\n"
1871 "Graceful restart capability parameters\n"
1872 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1873 "Delay value (seconds)\n")
1874{
d62a17ae 1875 VTY_DECLVAR_CONTEXT(bgp, bgp);
1876 int idx_number = 3;
d7c0a89a 1877 uint32_t restart;
eb6f1b41 1878
d62a17ae 1879 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1880 bgp->restart_time = restart;
1881 return CMD_SUCCESS;
eb6f1b41
PG
1882}
1883
93406d87 1884DEFUN (no_bgp_graceful_restart_stalepath_time,
1885 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1886 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1887 NO_STR
1888 "BGP specific commands\n"
1889 "Graceful restart capability parameters\n"
838758ac
DW
1890 "Set the max time to hold onto restarting peer's stale paths\n"
1891 "Delay value (seconds)\n")
93406d87 1892{
d62a17ae 1893 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1894
d62a17ae 1895 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1896 return CMD_SUCCESS;
93406d87 1897}
1898
eb6f1b41
PG
1899DEFUN (no_bgp_graceful_restart_restart_time,
1900 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1901 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1902 NO_STR
1903 "BGP specific commands\n"
1904 "Graceful restart capability parameters\n"
838758ac
DW
1905 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1906 "Delay value (seconds)\n")
eb6f1b41 1907{
d62a17ae 1908 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1909
d62a17ae 1910 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1911 return CMD_SUCCESS;
eb6f1b41
PG
1912}
1913
43fc21b3
JC
1914DEFUN (bgp_graceful_restart_preserve_fw,
1915 bgp_graceful_restart_preserve_fw_cmd,
1916 "bgp graceful-restart preserve-fw-state",
1917 "BGP specific commands\n"
1918 "Graceful restart capability parameters\n"
1919 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1920{
d62a17ae 1921 VTY_DECLVAR_CONTEXT(bgp, bgp);
1922 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1923 return CMD_SUCCESS;
43fc21b3
JC
1924}
1925
1926DEFUN (no_bgp_graceful_restart_preserve_fw,
1927 no_bgp_graceful_restart_preserve_fw_cmd,
1928 "no bgp graceful-restart preserve-fw-state",
1929 NO_STR
1930 "BGP specific commands\n"
1931 "Graceful restart capability parameters\n"
1932 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1933{
d62a17ae 1934 VTY_DECLVAR_CONTEXT(bgp, bgp);
1935 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1936 return CMD_SUCCESS;
43fc21b3
JC
1937}
1938
7f323236
DW
1939static void bgp_redistribute_redo(struct bgp *bgp)
1940{
1941 afi_t afi;
1942 int i;
1943 struct list *red_list;
1944 struct listnode *node;
1945 struct bgp_redist *red;
1946
a4d82a8a
PZ
1947 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1948 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 1949
a4d82a8a
PZ
1950 red_list = bgp->redist[afi][i];
1951 if (!red_list)
1952 continue;
7f323236 1953
a4d82a8a 1954 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
1955 bgp_redistribute_resend(bgp, afi, i,
1956 red->instance);
1957 }
1958 }
1959 }
1960}
1961
1962/* "bgp graceful-shutdown" configuration */
1963DEFUN (bgp_graceful_shutdown,
1964 bgp_graceful_shutdown_cmd,
1965 "bgp graceful-shutdown",
1966 BGP_STR
1967 "Graceful shutdown parameters\n")
1968{
1969 VTY_DECLVAR_CONTEXT(bgp, bgp);
1970
1971 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1972 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1973 bgp_static_redo_import_check(bgp);
1974 bgp_redistribute_redo(bgp);
1975 bgp_clear_star_soft_out(vty, bgp->name);
1976 bgp_clear_star_soft_in(vty, bgp->name);
1977 }
1978
1979 return CMD_SUCCESS;
1980}
1981
1982DEFUN (no_bgp_graceful_shutdown,
1983 no_bgp_graceful_shutdown_cmd,
1984 "no bgp graceful-shutdown",
1985 NO_STR
1986 BGP_STR
1987 "Graceful shutdown parameters\n")
1988{
1989 VTY_DECLVAR_CONTEXT(bgp, bgp);
1990
1991 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1992 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1993 bgp_static_redo_import_check(bgp);
1994 bgp_redistribute_redo(bgp);
1995 bgp_clear_star_soft_out(vty, bgp->name);
1996 bgp_clear_star_soft_in(vty, bgp->name);
1997 }
1998
1999 return CMD_SUCCESS;
2000}
2001
718e3744 2002/* "bgp fast-external-failover" configuration. */
2003DEFUN (bgp_fast_external_failover,
2004 bgp_fast_external_failover_cmd,
2005 "bgp fast-external-failover",
2006 BGP_STR
2007 "Immediately reset session if a link to a directly connected external peer goes down\n")
2008{
d62a17ae 2009 VTY_DECLVAR_CONTEXT(bgp, bgp);
2010 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2011 return CMD_SUCCESS;
718e3744 2012}
2013
2014DEFUN (no_bgp_fast_external_failover,
2015 no_bgp_fast_external_failover_cmd,
2016 "no bgp fast-external-failover",
2017 NO_STR
2018 BGP_STR
2019 "Immediately reset session if a link to a directly connected external peer goes down\n")
2020{
d62a17ae 2021 VTY_DECLVAR_CONTEXT(bgp, bgp);
2022 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2023 return CMD_SUCCESS;
718e3744 2024}
6b0655a2 2025
718e3744 2026/* "bgp enforce-first-as" configuration. */
ec4f0750 2027#if CONFDATE > 20190517
47cbc09b
PM
2028CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2029#endif
2030
f07e1c4f
QY
2031DEFUN_HIDDEN (bgp_enforce_first_as,
2032 bgp_enforce_first_as_cmd,
2033 "[no] bgp enforce-first-as",
2034 NO_STR
2035 BGP_STR
2036 "Enforce the first AS for EBGP routes\n")
718e3744 2037{
d62a17ae 2038 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2039
f07e1c4f
QY
2040 if (strmatch(argv[0]->text, "no"))
2041 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2042 else
2043 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
7aafcaca 2044
d62a17ae 2045 return CMD_SUCCESS;
718e3744 2046}
6b0655a2 2047
718e3744 2048/* "bgp bestpath compare-routerid" configuration. */
2049DEFUN (bgp_bestpath_compare_router_id,
2050 bgp_bestpath_compare_router_id_cmd,
2051 "bgp bestpath compare-routerid",
2052 "BGP specific commands\n"
2053 "Change the default bestpath selection\n"
2054 "Compare router-id for identical EBGP paths\n")
2055{
d62a17ae 2056 VTY_DECLVAR_CONTEXT(bgp, bgp);
2057 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2058 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2059
d62a17ae 2060 return CMD_SUCCESS;
718e3744 2061}
2062
2063DEFUN (no_bgp_bestpath_compare_router_id,
2064 no_bgp_bestpath_compare_router_id_cmd,
2065 "no bgp bestpath compare-routerid",
2066 NO_STR
2067 "BGP specific commands\n"
2068 "Change the default bestpath selection\n"
2069 "Compare router-id for identical EBGP paths\n")
2070{
d62a17ae 2071 VTY_DECLVAR_CONTEXT(bgp, bgp);
2072 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2073 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2074
d62a17ae 2075 return CMD_SUCCESS;
718e3744 2076}
6b0655a2 2077
718e3744 2078/* "bgp bestpath as-path ignore" configuration. */
2079DEFUN (bgp_bestpath_aspath_ignore,
2080 bgp_bestpath_aspath_ignore_cmd,
2081 "bgp bestpath as-path ignore",
2082 "BGP specific commands\n"
2083 "Change the default bestpath selection\n"
2084 "AS-path attribute\n"
2085 "Ignore as-path length in selecting a route\n")
2086{
d62a17ae 2087 VTY_DECLVAR_CONTEXT(bgp, bgp);
2088 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2089 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2090
d62a17ae 2091 return CMD_SUCCESS;
718e3744 2092}
2093
2094DEFUN (no_bgp_bestpath_aspath_ignore,
2095 no_bgp_bestpath_aspath_ignore_cmd,
2096 "no bgp bestpath as-path ignore",
2097 NO_STR
2098 "BGP specific commands\n"
2099 "Change the default bestpath selection\n"
2100 "AS-path attribute\n"
2101 "Ignore as-path length in selecting a route\n")
2102{
d62a17ae 2103 VTY_DECLVAR_CONTEXT(bgp, bgp);
2104 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2105 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2106
d62a17ae 2107 return CMD_SUCCESS;
718e3744 2108}
6b0655a2 2109
6811845b 2110/* "bgp bestpath as-path confed" configuration. */
2111DEFUN (bgp_bestpath_aspath_confed,
2112 bgp_bestpath_aspath_confed_cmd,
2113 "bgp bestpath as-path confed",
2114 "BGP specific commands\n"
2115 "Change the default bestpath selection\n"
2116 "AS-path attribute\n"
2117 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2118{
d62a17ae 2119 VTY_DECLVAR_CONTEXT(bgp, bgp);
2120 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2121 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2122
d62a17ae 2123 return CMD_SUCCESS;
6811845b 2124}
2125
2126DEFUN (no_bgp_bestpath_aspath_confed,
2127 no_bgp_bestpath_aspath_confed_cmd,
2128 "no bgp bestpath as-path confed",
2129 NO_STR
2130 "BGP specific commands\n"
2131 "Change the default bestpath selection\n"
2132 "AS-path attribute\n"
2133 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2134{
d62a17ae 2135 VTY_DECLVAR_CONTEXT(bgp, bgp);
2136 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2137 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2138
d62a17ae 2139 return CMD_SUCCESS;
6811845b 2140}
6b0655a2 2141
2fdd455c
PM
2142/* "bgp bestpath as-path multipath-relax" configuration. */
2143DEFUN (bgp_bestpath_aspath_multipath_relax,
2144 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2145 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2146 "BGP specific commands\n"
2147 "Change the default bestpath selection\n"
2148 "AS-path attribute\n"
2149 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2150 "Generate an AS_SET\n"
16fc1eec
DS
2151 "Do not generate an AS_SET\n")
2152{
d62a17ae 2153 VTY_DECLVAR_CONTEXT(bgp, bgp);
2154 int idx = 0;
2155 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2156
d62a17ae 2157 /* no-as-set is now the default behavior so we can silently
2158 * ignore it */
2159 if (argv_find(argv, argc, "as-set", &idx))
2160 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2161 else
2162 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2163
d62a17ae 2164 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2165
d62a17ae 2166 return CMD_SUCCESS;
16fc1eec
DS
2167}
2168
219178b6
DW
2169DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2170 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2171 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2172 NO_STR
2173 "BGP specific commands\n"
2174 "Change the default bestpath selection\n"
2175 "AS-path attribute\n"
2176 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2177 "Generate an AS_SET\n"
16fc1eec
DS
2178 "Do not generate an AS_SET\n")
2179{
d62a17ae 2180 VTY_DECLVAR_CONTEXT(bgp, bgp);
2181 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2182 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2183 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2184
d62a17ae 2185 return CMD_SUCCESS;
2fdd455c 2186}
6b0655a2 2187
848973c7 2188/* "bgp log-neighbor-changes" configuration. */
2189DEFUN (bgp_log_neighbor_changes,
2190 bgp_log_neighbor_changes_cmd,
2191 "bgp log-neighbor-changes",
2192 "BGP specific commands\n"
2193 "Log neighbor up/down and reset reason\n")
2194{
d62a17ae 2195 VTY_DECLVAR_CONTEXT(bgp, bgp);
2196 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2197 return CMD_SUCCESS;
848973c7 2198}
2199
2200DEFUN (no_bgp_log_neighbor_changes,
2201 no_bgp_log_neighbor_changes_cmd,
2202 "no bgp log-neighbor-changes",
2203 NO_STR
2204 "BGP specific commands\n"
2205 "Log neighbor up/down and reset reason\n")
2206{
d62a17ae 2207 VTY_DECLVAR_CONTEXT(bgp, bgp);
2208 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2209 return CMD_SUCCESS;
848973c7 2210}
6b0655a2 2211
718e3744 2212/* "bgp bestpath med" configuration. */
2213DEFUN (bgp_bestpath_med,
2214 bgp_bestpath_med_cmd,
2d8c1a4d 2215 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2216 "BGP specific commands\n"
2217 "Change the default bestpath selection\n"
2218 "MED attribute\n"
2219 "Compare MED among confederation paths\n"
838758ac
DW
2220 "Treat missing MED as the least preferred one\n"
2221 "Treat missing MED as the least preferred one\n"
2222 "Compare MED among confederation paths\n")
718e3744 2223{
d62a17ae 2224 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2225
d62a17ae 2226 int idx = 0;
2227 if (argv_find(argv, argc, "confed", &idx))
2228 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2229 idx = 0;
2230 if (argv_find(argv, argc, "missing-as-worst", &idx))
2231 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2232
d62a17ae 2233 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2234
d62a17ae 2235 return CMD_SUCCESS;
718e3744 2236}
2237
718e3744 2238DEFUN (no_bgp_bestpath_med,
2239 no_bgp_bestpath_med_cmd,
2d8c1a4d 2240 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2241 NO_STR
2242 "BGP specific commands\n"
2243 "Change the default bestpath selection\n"
2244 "MED attribute\n"
2245 "Compare MED among confederation paths\n"
3a2d747c
QY
2246 "Treat missing MED as the least preferred one\n"
2247 "Treat missing MED as the least preferred one\n"
2248 "Compare MED among confederation paths\n")
718e3744 2249{
d62a17ae 2250 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2251
d62a17ae 2252 int idx = 0;
2253 if (argv_find(argv, argc, "confed", &idx))
2254 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2255 idx = 0;
2256 if (argv_find(argv, argc, "missing-as-worst", &idx))
2257 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2258
d62a17ae 2259 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2260
d62a17ae 2261 return CMD_SUCCESS;
718e3744 2262}
2263
718e3744 2264/* "no bgp default ipv4-unicast". */
2265DEFUN (no_bgp_default_ipv4_unicast,
2266 no_bgp_default_ipv4_unicast_cmd,
2267 "no bgp default ipv4-unicast",
2268 NO_STR
2269 "BGP specific commands\n"
2270 "Configure BGP defaults\n"
2271 "Activate ipv4-unicast for a peer by default\n")
2272{
d62a17ae 2273 VTY_DECLVAR_CONTEXT(bgp, bgp);
2274 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2275 return CMD_SUCCESS;
718e3744 2276}
2277
2278DEFUN (bgp_default_ipv4_unicast,
2279 bgp_default_ipv4_unicast_cmd,
2280 "bgp default ipv4-unicast",
2281 "BGP specific commands\n"
2282 "Configure BGP defaults\n"
2283 "Activate ipv4-unicast for a peer by default\n")
2284{
d62a17ae 2285 VTY_DECLVAR_CONTEXT(bgp, bgp);
2286 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2287 return CMD_SUCCESS;
718e3744 2288}
6b0655a2 2289
04b6bdc0
DW
2290/* Display hostname in certain command outputs */
2291DEFUN (bgp_default_show_hostname,
2292 bgp_default_show_hostname_cmd,
2293 "bgp default show-hostname",
2294 "BGP specific commands\n"
2295 "Configure BGP defaults\n"
2296 "Show hostname in certain command ouputs\n")
2297{
d62a17ae 2298 VTY_DECLVAR_CONTEXT(bgp, bgp);
2299 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2300 return CMD_SUCCESS;
04b6bdc0
DW
2301}
2302
2303DEFUN (no_bgp_default_show_hostname,
2304 no_bgp_default_show_hostname_cmd,
2305 "no bgp default show-hostname",
2306 NO_STR
2307 "BGP specific commands\n"
2308 "Configure BGP defaults\n"
2309 "Show hostname in certain command ouputs\n")
2310{
d62a17ae 2311 VTY_DECLVAR_CONTEXT(bgp, bgp);
2312 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2313 return CMD_SUCCESS;
04b6bdc0
DW
2314}
2315
8233ef81 2316/* "bgp network import-check" configuration. */
718e3744 2317DEFUN (bgp_network_import_check,
2318 bgp_network_import_check_cmd,
5623e905 2319 "bgp network import-check",
718e3744 2320 "BGP specific commands\n"
2321 "BGP network command\n"
5623e905 2322 "Check BGP network route exists in IGP\n")
718e3744 2323{
d62a17ae 2324 VTY_DECLVAR_CONTEXT(bgp, bgp);
2325 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2326 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2327 bgp_static_redo_import_check(bgp);
2328 }
078430f6 2329
d62a17ae 2330 return CMD_SUCCESS;
718e3744 2331}
2332
d62a17ae 2333ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2334 "bgp network import-check exact",
2335 "BGP specific commands\n"
2336 "BGP network command\n"
2337 "Check BGP network route exists in IGP\n"
2338 "Match route precisely\n")
8233ef81 2339
718e3744 2340DEFUN (no_bgp_network_import_check,
2341 no_bgp_network_import_check_cmd,
5623e905 2342 "no bgp network import-check",
718e3744 2343 NO_STR
2344 "BGP specific commands\n"
2345 "BGP network command\n"
2346 "Check BGP network route exists in IGP\n")
2347{
d62a17ae 2348 VTY_DECLVAR_CONTEXT(bgp, bgp);
2349 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2350 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2351 bgp_static_redo_import_check(bgp);
2352 }
5623e905 2353
d62a17ae 2354 return CMD_SUCCESS;
718e3744 2355}
6b0655a2 2356
718e3744 2357DEFUN (bgp_default_local_preference,
2358 bgp_default_local_preference_cmd,
6147e2c6 2359 "bgp default local-preference (0-4294967295)",
718e3744 2360 "BGP specific commands\n"
2361 "Configure BGP defaults\n"
2362 "local preference (higher=more preferred)\n"
2363 "Configure default local preference value\n")
2364{
d62a17ae 2365 VTY_DECLVAR_CONTEXT(bgp, bgp);
2366 int idx_number = 3;
d7c0a89a 2367 uint32_t local_pref;
718e3744 2368
d62a17ae 2369 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2370
d62a17ae 2371 bgp_default_local_preference_set(bgp, local_pref);
2372 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2373
d62a17ae 2374 return CMD_SUCCESS;
718e3744 2375}
2376
2377DEFUN (no_bgp_default_local_preference,
2378 no_bgp_default_local_preference_cmd,
838758ac 2379 "no bgp default local-preference [(0-4294967295)]",
718e3744 2380 NO_STR
2381 "BGP specific commands\n"
2382 "Configure BGP defaults\n"
838758ac
DW
2383 "local preference (higher=more preferred)\n"
2384 "Configure default local preference value\n")
718e3744 2385{
d62a17ae 2386 VTY_DECLVAR_CONTEXT(bgp, bgp);
2387 bgp_default_local_preference_unset(bgp);
2388 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2389
d62a17ae 2390 return CMD_SUCCESS;
718e3744 2391}
2392
6b0655a2 2393
3f9c7369
DS
2394DEFUN (bgp_default_subgroup_pkt_queue_max,
2395 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2396 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2397 "BGP specific commands\n"
2398 "Configure BGP defaults\n"
2399 "subgroup-pkt-queue-max\n"
2400 "Configure subgroup packet queue max\n")
8bd9d948 2401{
d62a17ae 2402 VTY_DECLVAR_CONTEXT(bgp, bgp);
2403 int idx_number = 3;
d7c0a89a 2404 uint32_t max_size;
8bd9d948 2405
d62a17ae 2406 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2407
d62a17ae 2408 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2409
d62a17ae 2410 return CMD_SUCCESS;
3f9c7369
DS
2411}
2412
2413DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2414 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2415 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2416 NO_STR
2417 "BGP specific commands\n"
2418 "Configure BGP defaults\n"
838758ac
DW
2419 "subgroup-pkt-queue-max\n"
2420 "Configure subgroup packet queue max\n")
3f9c7369 2421{
d62a17ae 2422 VTY_DECLVAR_CONTEXT(bgp, bgp);
2423 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2424 return CMD_SUCCESS;
8bd9d948
DS
2425}
2426
813d4307 2427
8bd9d948
DS
2428DEFUN (bgp_rr_allow_outbound_policy,
2429 bgp_rr_allow_outbound_policy_cmd,
2430 "bgp route-reflector allow-outbound-policy",
2431 "BGP specific commands\n"
2432 "Allow modifications made by out route-map\n"
2433 "on ibgp neighbors\n")
2434{
d62a17ae 2435 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2436
d62a17ae 2437 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2438 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2439 update_group_announce_rrclients(bgp);
2440 bgp_clear_star_soft_out(vty, bgp->name);
2441 }
8bd9d948 2442
d62a17ae 2443 return CMD_SUCCESS;
8bd9d948
DS
2444}
2445
2446DEFUN (no_bgp_rr_allow_outbound_policy,
2447 no_bgp_rr_allow_outbound_policy_cmd,
2448 "no bgp route-reflector allow-outbound-policy",
2449 NO_STR
2450 "BGP specific commands\n"
2451 "Allow modifications made by out route-map\n"
2452 "on ibgp neighbors\n")
2453{
d62a17ae 2454 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2455
d62a17ae 2456 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2457 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2458 update_group_announce_rrclients(bgp);
2459 bgp_clear_star_soft_out(vty, bgp->name);
2460 }
8bd9d948 2461
d62a17ae 2462 return CMD_SUCCESS;
8bd9d948
DS
2463}
2464
f14e6fdb
DS
2465DEFUN (bgp_listen_limit,
2466 bgp_listen_limit_cmd,
9ccf14f7 2467 "bgp listen limit (1-5000)",
f14e6fdb
DS
2468 "BGP specific commands\n"
2469 "Configure BGP defaults\n"
2470 "maximum number of BGP Dynamic Neighbors that can be created\n"
2471 "Configure Dynamic Neighbors listen limit value\n")
2472{
d62a17ae 2473 VTY_DECLVAR_CONTEXT(bgp, bgp);
2474 int idx_number = 3;
2475 int listen_limit;
f14e6fdb 2476
d62a17ae 2477 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2478
d62a17ae 2479 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2480
d62a17ae 2481 return CMD_SUCCESS;
f14e6fdb
DS
2482}
2483
2484DEFUN (no_bgp_listen_limit,
2485 no_bgp_listen_limit_cmd,
838758ac 2486 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2487 "BGP specific commands\n"
2488 "Configure BGP defaults\n"
2489 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2490 "Configure Dynamic Neighbors listen limit value to default\n"
2491 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2492{
d62a17ae 2493 VTY_DECLVAR_CONTEXT(bgp, bgp);
2494 bgp_listen_limit_unset(bgp);
2495 return CMD_SUCCESS;
f14e6fdb
DS
2496}
2497
2498
20eb8864 2499/*
2500 * Check if this listen range is already configured. Check for exact
2501 * match or overlap based on input.
2502 */
d62a17ae 2503static struct peer_group *listen_range_exists(struct bgp *bgp,
2504 struct prefix *range, int exact)
2505{
2506 struct listnode *node, *nnode;
2507 struct listnode *node1, *nnode1;
2508 struct peer_group *group;
2509 struct prefix *lr;
2510 afi_t afi;
2511 int match;
2512
2513 afi = family2afi(range->family);
2514 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2515 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2516 lr)) {
2517 if (exact)
2518 match = prefix_same(range, lr);
2519 else
2520 match = (prefix_match(range, lr)
2521 || prefix_match(lr, range));
2522 if (match)
2523 return group;
2524 }
2525 }
2526
2527 return NULL;
20eb8864 2528}
2529
f14e6fdb
DS
2530DEFUN (bgp_listen_range,
2531 bgp_listen_range_cmd,
9ccf14f7 2532 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2533 "BGP specific commands\n"
d7fa34c1
QY
2534 "Configure BGP dynamic neighbors listen range\n"
2535 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2536 NEIGHBOR_ADDR_STR
2537 "Member of the peer-group\n"
2538 "Peer-group name\n")
f14e6fdb 2539{
d62a17ae 2540 VTY_DECLVAR_CONTEXT(bgp, bgp);
2541 struct prefix range;
2542 struct peer_group *group, *existing_group;
2543 afi_t afi;
2544 int ret;
2545 int idx = 0;
2546
2547 argv_find(argv, argc, "A.B.C.D/M", &idx);
2548 argv_find(argv, argc, "X:X::X:X/M", &idx);
2549 char *prefix = argv[idx]->arg;
2550 argv_find(argv, argc, "WORD", &idx);
2551 char *peergroup = argv[idx]->arg;
2552
2553 /* Convert IP prefix string to struct prefix. */
2554 ret = str2prefix(prefix, &range);
2555 if (!ret) {
2556 vty_out(vty, "%% Malformed listen range\n");
2557 return CMD_WARNING_CONFIG_FAILED;
2558 }
2559
2560 afi = family2afi(range.family);
2561
2562 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2563 vty_out(vty,
2564 "%% Malformed listen range (link-local address)\n");
2565 return CMD_WARNING_CONFIG_FAILED;
2566 }
2567
2568 apply_mask(&range);
2569
2570 /* Check if same listen range is already configured. */
2571 existing_group = listen_range_exists(bgp, &range, 1);
2572 if (existing_group) {
2573 if (strcmp(existing_group->name, peergroup) == 0)
2574 return CMD_SUCCESS;
2575 else {
2576 vty_out(vty,
2577 "%% Same listen range is attached to peer-group %s\n",
2578 existing_group->name);
2579 return CMD_WARNING_CONFIG_FAILED;
2580 }
2581 }
2582
2583 /* Check if an overlapping listen range exists. */
2584 if (listen_range_exists(bgp, &range, 0)) {
2585 vty_out(vty,
2586 "%% Listen range overlaps with existing listen range\n");
2587 return CMD_WARNING_CONFIG_FAILED;
2588 }
2589
2590 group = peer_group_lookup(bgp, peergroup);
2591 if (!group) {
2592 vty_out(vty, "%% Configure the peer-group first\n");
2593 return CMD_WARNING_CONFIG_FAILED;
2594 }
2595
2596 ret = peer_group_listen_range_add(group, &range);
2597 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2598}
2599
2600DEFUN (no_bgp_listen_range,
2601 no_bgp_listen_range_cmd,
d7fa34c1
QY
2602 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2603 NO_STR
f14e6fdb 2604 "BGP specific commands\n"
d7fa34c1
QY
2605 "Unconfigure BGP dynamic neighbors listen range\n"
2606 "Unconfigure BGP dynamic neighbors listen range\n"
2607 NEIGHBOR_ADDR_STR
2608 "Member of the peer-group\n"
2609 "Peer-group name\n")
f14e6fdb 2610{
d62a17ae 2611 VTY_DECLVAR_CONTEXT(bgp, bgp);
2612 struct prefix range;
2613 struct peer_group *group;
2614 afi_t afi;
2615 int ret;
2616 int idx = 0;
2617
2618 argv_find(argv, argc, "A.B.C.D/M", &idx);
2619 argv_find(argv, argc, "X:X::X:X/M", &idx);
2620 char *prefix = argv[idx]->arg;
2621 argv_find(argv, argc, "WORD", &idx);
2622 char *peergroup = argv[idx]->arg;
2623
2624 /* Convert IP prefix string to struct prefix. */
2625 ret = str2prefix(prefix, &range);
2626 if (!ret) {
2627 vty_out(vty, "%% Malformed listen range\n");
2628 return CMD_WARNING_CONFIG_FAILED;
2629 }
2630
2631 afi = family2afi(range.family);
2632
2633 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2634 vty_out(vty,
2635 "%% Malformed listen range (link-local address)\n");
2636 return CMD_WARNING_CONFIG_FAILED;
2637 }
2638
2639 apply_mask(&range);
2640
2641 group = peer_group_lookup(bgp, peergroup);
2642 if (!group) {
2643 vty_out(vty, "%% Peer-group does not exist\n");
2644 return CMD_WARNING_CONFIG_FAILED;
2645 }
2646
2647 ret = peer_group_listen_range_del(group, &range);
2648 return bgp_vty_return(vty, ret);
2649}
2650
2b791107 2651void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2652{
2653 struct peer_group *group;
2654 struct listnode *node, *nnode, *rnode, *nrnode;
2655 struct prefix *range;
2656 afi_t afi;
2657 char buf[PREFIX2STR_BUFFER];
2658
2659 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2660 vty_out(vty, " bgp listen limit %d\n",
2661 bgp->dynamic_neighbors_limit);
2662
2663 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2664 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2665 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2666 nrnode, range)) {
2667 prefix2str(range, buf, sizeof(buf));
2668 vty_out(vty,
2669 " bgp listen range %s peer-group %s\n",
2670 buf, group->name);
2671 }
2672 }
2673 }
f14e6fdb
DS
2674}
2675
2676
907f92c8
DS
2677DEFUN (bgp_disable_connected_route_check,
2678 bgp_disable_connected_route_check_cmd,
2679 "bgp disable-ebgp-connected-route-check",
2680 "BGP specific commands\n"
2681 "Disable checking if nexthop is connected on ebgp sessions\n")
2682{
d62a17ae 2683 VTY_DECLVAR_CONTEXT(bgp, bgp);
2684 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2685 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2686
d62a17ae 2687 return CMD_SUCCESS;
907f92c8
DS
2688}
2689
2690DEFUN (no_bgp_disable_connected_route_check,
2691 no_bgp_disable_connected_route_check_cmd,
2692 "no bgp disable-ebgp-connected-route-check",
2693 NO_STR
2694 "BGP specific commands\n"
2695 "Disable checking if nexthop is connected on ebgp sessions\n")
2696{
d62a17ae 2697 VTY_DECLVAR_CONTEXT(bgp, bgp);
2698 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2699 bgp_clear_star_soft_in(vty, bgp->name);
2700
2701 return CMD_SUCCESS;
2702}
2703
2704
2705static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2706 const char *as_str, afi_t afi, safi_t safi)
2707{
2708 VTY_DECLVAR_CONTEXT(bgp, bgp);
2709 int ret;
2710 as_t as;
2711 int as_type = AS_SPECIFIED;
2712 union sockunion su;
2713
2714 if (as_str[0] == 'i') {
2715 as = 0;
2716 as_type = AS_INTERNAL;
2717 } else if (as_str[0] == 'e') {
2718 as = 0;
2719 as_type = AS_EXTERNAL;
2720 } else {
2721 /* Get AS number. */
2722 as = strtoul(as_str, NULL, 10);
2723 }
2724
2725 /* If peer is peer group, call proper function. */
2726 ret = str2sockunion(peer_str, &su);
2727 if (ret < 0) {
2728 /* Check for peer by interface */
2729 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2730 safi);
2731 if (ret < 0) {
2732 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2733 if (ret < 0) {
2734 vty_out(vty,
2735 "%% Create the peer-group or interface first\n");
2736 return CMD_WARNING_CONFIG_FAILED;
2737 }
2738 return CMD_SUCCESS;
2739 }
2740 } else {
2741 if (peer_address_self_check(bgp, &su)) {
2742 vty_out(vty,
2743 "%% Can not configure the local system as neighbor\n");
2744 return CMD_WARNING_CONFIG_FAILED;
2745 }
2746 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2747 }
2748
2749 /* This peer belongs to peer group. */
2750 switch (ret) {
2751 case BGP_ERR_PEER_GROUP_MEMBER:
2752 vty_out(vty,
2753 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2754 as);
2755 return CMD_WARNING_CONFIG_FAILED;
2756 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2757 vty_out(vty,
2758 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2759 as, as_str);
2760 return CMD_WARNING_CONFIG_FAILED;
2761 }
2762 return bgp_vty_return(vty, ret);
718e3744 2763}
2764
f26845f9
QY
2765DEFUN (bgp_default_shutdown,
2766 bgp_default_shutdown_cmd,
2767 "[no] bgp default shutdown",
2768 NO_STR
2769 BGP_STR
2770 "Configure BGP defaults\n"
b012cbe2 2771 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2772{
2773 VTY_DECLVAR_CONTEXT(bgp, bgp);
2774 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2775 return CMD_SUCCESS;
2776}
2777
718e3744 2778DEFUN (neighbor_remote_as,
2779 neighbor_remote_as_cmd,
3a2d747c 2780 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2781 NEIGHBOR_STR
2782 NEIGHBOR_ADDR_STR2
2783 "Specify a BGP neighbor\n"
d7fa34c1 2784 AS_STR
3a2d747c
QY
2785 "Internal BGP peer\n"
2786 "External BGP peer\n")
718e3744 2787{
d62a17ae 2788 int idx_peer = 1;
2789 int idx_remote_as = 3;
2790 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2791 argv[idx_remote_as]->arg, AFI_IP,
2792 SAFI_UNICAST);
2793}
2794
2795static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2796 afi_t afi, safi_t safi, int v6only,
2797 const char *peer_group_name,
2798 const char *as_str)
2799{
2800 VTY_DECLVAR_CONTEXT(bgp, bgp);
2801 as_t as = 0;
2802 int as_type = AS_UNSPECIFIED;
2803 struct peer *peer;
2804 struct peer_group *group;
2805 int ret = 0;
2806 union sockunion su;
2807
2808 group = peer_group_lookup(bgp, conf_if);
2809
2810 if (group) {
2811 vty_out(vty, "%% Name conflict with peer-group \n");
2812 return CMD_WARNING_CONFIG_FAILED;
2813 }
2814
2815 if (as_str) {
2816 if (as_str[0] == 'i') {
2817 as_type = AS_INTERNAL;
2818 } else if (as_str[0] == 'e') {
2819 as_type = AS_EXTERNAL;
2820 } else {
2821 /* Get AS number. */
2822 as = strtoul(as_str, NULL, 10);
2823 as_type = AS_SPECIFIED;
2824 }
2825 }
2826
2827 peer = peer_lookup_by_conf_if(bgp, conf_if);
2828 if (peer) {
2829 if (as_str)
2830 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2831 afi, safi);
2832 } else {
2833 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2834 && afi == AFI_IP && safi == SAFI_UNICAST)
2835 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2836 as_type, 0, 0, NULL);
2837 else
2838 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2839 as_type, afi, safi, NULL);
2840
2841 if (!peer) {
2842 vty_out(vty, "%% BGP failed to create peer\n");
2843 return CMD_WARNING_CONFIG_FAILED;
2844 }
2845
2846 if (v6only)
527de3dc 2847 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2848
2849 /* Request zebra to initiate IPv6 RAs on this interface. We do
2850 * this
2851 * any unnumbered peer in order to not worry about run-time
2852 * transitions
2853 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2854 * address
2855 * gets deleted later etc.)
2856 */
2857 if (peer->ifp)
2858 bgp_zebra_initiate_radv(bgp, peer);
2859 }
2860
2861 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2862 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2863 if (v6only)
527de3dc 2864 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2865 else
527de3dc 2866 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2867
2868 /* v6only flag changed. Reset bgp seesion */
2869 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2870 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2871 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2872 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2873 } else
2874 bgp_session_reset(peer);
2875 }
2876
9fb964de
PM
2877 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2878 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2879 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2880 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2881 }
d62a17ae 2882
2883 if (peer_group_name) {
2884 group = peer_group_lookup(bgp, peer_group_name);
2885 if (!group) {
2886 vty_out(vty, "%% Configure the peer-group first\n");
2887 return CMD_WARNING_CONFIG_FAILED;
2888 }
2889
2890 ret = peer_group_bind(bgp, &su, peer, group, &as);
2891 }
2892
2893 return bgp_vty_return(vty, ret);
a80beece
DS
2894}
2895
4c48cf63
DW
2896DEFUN (neighbor_interface_config,
2897 neighbor_interface_config_cmd,
31500417 2898 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2899 NEIGHBOR_STR
2900 "Interface name or neighbor tag\n"
31500417
DW
2901 "Enable BGP on interface\n"
2902 "Member of the peer-group\n"
16cedbb0 2903 "Peer-group name\n")
4c48cf63 2904{
d62a17ae 2905 int idx_word = 1;
2906 int idx_peer_group_word = 4;
31500417 2907
d62a17ae 2908 if (argc > idx_peer_group_word)
2909 return peer_conf_interface_get(
2910 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2911 argv[idx_peer_group_word]->arg, NULL);
2912 else
2913 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2914 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2915}
2916
4c48cf63
DW
2917DEFUN (neighbor_interface_config_v6only,
2918 neighbor_interface_config_v6only_cmd,
31500417 2919 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2920 NEIGHBOR_STR
2921 "Interface name or neighbor tag\n"
2922 "Enable BGP on interface\n"
31500417
DW
2923 "Enable BGP with v6 link-local only\n"
2924 "Member of the peer-group\n"
16cedbb0 2925 "Peer-group name\n")
4c48cf63 2926{
d62a17ae 2927 int idx_word = 1;
2928 int idx_peer_group_word = 5;
31500417 2929
d62a17ae 2930 if (argc > idx_peer_group_word)
2931 return peer_conf_interface_get(
2932 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2933 argv[idx_peer_group_word]->arg, NULL);
31500417 2934
d62a17ae 2935 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2936 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2937}
2938
a80beece 2939
b3a39dc5
DD
2940DEFUN (neighbor_interface_config_remote_as,
2941 neighbor_interface_config_remote_as_cmd,
3a2d747c 2942 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2943 NEIGHBOR_STR
2944 "Interface name or neighbor tag\n"
2945 "Enable BGP on interface\n"
3a2d747c 2946 "Specify a BGP neighbor\n"
d7fa34c1 2947 AS_STR
3a2d747c
QY
2948 "Internal BGP peer\n"
2949 "External BGP peer\n")
b3a39dc5 2950{
d62a17ae 2951 int idx_word = 1;
2952 int idx_remote_as = 4;
2953 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2954 SAFI_UNICAST, 0, NULL,
2955 argv[idx_remote_as]->arg);
b3a39dc5
DD
2956}
2957
2958DEFUN (neighbor_interface_v6only_config_remote_as,
2959 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2960 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2961 NEIGHBOR_STR
2962 "Interface name or neighbor tag\n"
3a2d747c 2963 "Enable BGP with v6 link-local only\n"
b3a39dc5 2964 "Enable BGP on interface\n"
3a2d747c 2965 "Specify a BGP neighbor\n"
d7fa34c1 2966 AS_STR
3a2d747c
QY
2967 "Internal BGP peer\n"
2968 "External BGP peer\n")
b3a39dc5 2969{
d62a17ae 2970 int idx_word = 1;
2971 int idx_remote_as = 5;
2972 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2973 SAFI_UNICAST, 1, NULL,
2974 argv[idx_remote_as]->arg);
b3a39dc5
DD
2975}
2976
718e3744 2977DEFUN (neighbor_peer_group,
2978 neighbor_peer_group_cmd,
2979 "neighbor WORD peer-group",
2980 NEIGHBOR_STR
a80beece 2981 "Interface name or neighbor tag\n"
718e3744 2982 "Configure peer-group\n")
2983{
d62a17ae 2984 VTY_DECLVAR_CONTEXT(bgp, bgp);
2985 int idx_word = 1;
2986 struct peer *peer;
2987 struct peer_group *group;
718e3744 2988
d62a17ae 2989 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2990 if (peer) {
2991 vty_out(vty, "%% Name conflict with interface: \n");
2992 return CMD_WARNING_CONFIG_FAILED;
2993 }
718e3744 2994
d62a17ae 2995 group = peer_group_get(bgp, argv[idx_word]->arg);
2996 if (!group) {
2997 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2998 return CMD_WARNING_CONFIG_FAILED;
2999 }
718e3744 3000
d62a17ae 3001 return CMD_SUCCESS;
718e3744 3002}
3003
3004DEFUN (no_neighbor,
3005 no_neighbor_cmd,
dab8cd00 3006 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3007 NO_STR
3008 NEIGHBOR_STR
3a2d747c
QY
3009 NEIGHBOR_ADDR_STR2
3010 "Specify a BGP neighbor\n"
3011 AS_STR
3012 "Internal BGP peer\n"
3013 "External BGP peer\n")
718e3744 3014{
d62a17ae 3015 VTY_DECLVAR_CONTEXT(bgp, bgp);
3016 int idx_peer = 2;
3017 int ret;
3018 union sockunion su;
3019 struct peer_group *group;
3020 struct peer *peer;
3021 struct peer *other;
3022
3023 ret = str2sockunion(argv[idx_peer]->arg, &su);
3024 if (ret < 0) {
3025 /* look up for neighbor by interface name config. */
3026 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3027 if (peer) {
3028 /* Request zebra to terminate IPv6 RAs on this
3029 * interface. */
3030 if (peer->ifp)
3031 bgp_zebra_terminate_radv(peer->bgp, peer);
3032 peer_delete(peer);
3033 return CMD_SUCCESS;
3034 }
f14e6fdb 3035
d62a17ae 3036 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3037 if (group)
3038 peer_group_delete(group);
3039 else {
3040 vty_out(vty, "%% Create the peer-group first\n");
3041 return CMD_WARNING_CONFIG_FAILED;
3042 }
3043 } else {
3044 peer = peer_lookup(bgp, &su);
3045 if (peer) {
3046 if (peer_dynamic_neighbor(peer)) {
3047 vty_out(vty,
3048 "%% Operation not allowed on a dynamic neighbor\n");
3049 return CMD_WARNING_CONFIG_FAILED;
3050 }
3051
3052 other = peer->doppelganger;
3053 peer_delete(peer);
3054 if (other && other->status != Deleted)
3055 peer_delete(other);
3056 }
1ff9a340 3057 }
718e3744 3058
d62a17ae 3059 return CMD_SUCCESS;
718e3744 3060}
3061
a80beece
DS
3062DEFUN (no_neighbor_interface_config,
3063 no_neighbor_interface_config_cmd,
31500417 3064 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3065 NO_STR
3066 NEIGHBOR_STR
3067 "Interface name\n"
31500417
DW
3068 "Configure BGP on interface\n"
3069 "Enable BGP with v6 link-local only\n"
3070 "Member of the peer-group\n"
16cedbb0 3071 "Peer-group name\n"
3a2d747c
QY
3072 "Specify a BGP neighbor\n"
3073 AS_STR
3074 "Internal BGP peer\n"
3075 "External BGP peer\n")
a80beece 3076{
d62a17ae 3077 VTY_DECLVAR_CONTEXT(bgp, bgp);
3078 int idx_word = 2;
3079 struct peer *peer;
3080
3081 /* look up for neighbor by interface name config. */
3082 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3083 if (peer) {
3084 /* Request zebra to terminate IPv6 RAs on this interface. */
3085 if (peer->ifp)
3086 bgp_zebra_terminate_radv(peer->bgp, peer);
3087 peer_delete(peer);
3088 } else {
3089 vty_out(vty, "%% Create the bgp interface first\n");
3090 return CMD_WARNING_CONFIG_FAILED;
3091 }
3092 return CMD_SUCCESS;
a80beece
DS
3093}
3094
718e3744 3095DEFUN (no_neighbor_peer_group,
3096 no_neighbor_peer_group_cmd,
3097 "no neighbor WORD peer-group",
3098 NO_STR
3099 NEIGHBOR_STR
3100 "Neighbor tag\n"
3101 "Configure peer-group\n")
3102{
d62a17ae 3103 VTY_DECLVAR_CONTEXT(bgp, bgp);
3104 int idx_word = 2;
3105 struct peer_group *group;
718e3744 3106
d62a17ae 3107 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3108 if (group)
3109 peer_group_delete(group);
3110 else {
3111 vty_out(vty, "%% Create the peer-group first\n");
3112 return CMD_WARNING_CONFIG_FAILED;
3113 }
3114 return CMD_SUCCESS;
718e3744 3115}
3116
a80beece
DS
3117DEFUN (no_neighbor_interface_peer_group_remote_as,
3118 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3119 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3120 NO_STR
3121 NEIGHBOR_STR
a80beece 3122 "Interface name or neighbor tag\n"
718e3744 3123 "Specify a BGP neighbor\n"
3a2d747c
QY
3124 AS_STR
3125 "Internal BGP peer\n"
3126 "External BGP peer\n")
718e3744 3127{
d62a17ae 3128 VTY_DECLVAR_CONTEXT(bgp, bgp);
3129 int idx_word = 2;
3130 struct peer_group *group;
3131 struct peer *peer;
3132
3133 /* look up for neighbor by interface name config. */
3134 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3135 if (peer) {
3136 peer_as_change(peer, 0, AS_SPECIFIED);
3137 return CMD_SUCCESS;
3138 }
3139
3140 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3141 if (group)
3142 peer_group_remote_as_delete(group);
3143 else {
3144 vty_out(vty, "%% Create the peer-group or interface first\n");
3145 return CMD_WARNING_CONFIG_FAILED;
3146 }
3147 return CMD_SUCCESS;
718e3744 3148}
6b0655a2 3149
718e3744 3150DEFUN (neighbor_local_as,
3151 neighbor_local_as_cmd,
9ccf14f7 3152 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3153 NEIGHBOR_STR
3154 NEIGHBOR_ADDR_STR2
3155 "Specify a local-as number\n"
3156 "AS number used as local AS\n")
3157{
d62a17ae 3158 int idx_peer = 1;
3159 int idx_number = 3;
3160 struct peer *peer;
3161 int ret;
3162 as_t as;
718e3744 3163
d62a17ae 3164 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3165 if (!peer)
3166 return CMD_WARNING_CONFIG_FAILED;
718e3744 3167
d62a17ae 3168 as = strtoul(argv[idx_number]->arg, NULL, 10);
3169 ret = peer_local_as_set(peer, as, 0, 0);
3170 return bgp_vty_return(vty, ret);
718e3744 3171}
3172
3173DEFUN (neighbor_local_as_no_prepend,
3174 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3175 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3176 NEIGHBOR_STR
3177 NEIGHBOR_ADDR_STR2
3178 "Specify a local-as number\n"
3179 "AS number used as local AS\n"
3180 "Do not prepend local-as to updates from ebgp peers\n")
3181{
d62a17ae 3182 int idx_peer = 1;
3183 int idx_number = 3;
3184 struct peer *peer;
3185 int ret;
3186 as_t as;
718e3744 3187
d62a17ae 3188 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3189 if (!peer)
3190 return CMD_WARNING_CONFIG_FAILED;
718e3744 3191
d62a17ae 3192 as = strtoul(argv[idx_number]->arg, NULL, 10);
3193 ret = peer_local_as_set(peer, as, 1, 0);
3194 return bgp_vty_return(vty, ret);
718e3744 3195}
3196
9d3f9705
AC
3197DEFUN (neighbor_local_as_no_prepend_replace_as,
3198 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3199 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3200 NEIGHBOR_STR
3201 NEIGHBOR_ADDR_STR2
3202 "Specify a local-as number\n"
3203 "AS number used as local AS\n"
3204 "Do not prepend local-as to updates from ebgp peers\n"
3205 "Do not prepend local-as to updates from ibgp peers\n")
3206{
d62a17ae 3207 int idx_peer = 1;
3208 int idx_number = 3;
3209 struct peer *peer;
3210 int ret;
3211 as_t as;
9d3f9705 3212
d62a17ae 3213 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3214 if (!peer)
3215 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3216
d62a17ae 3217 as = strtoul(argv[idx_number]->arg, NULL, 10);
3218 ret = peer_local_as_set(peer, as, 1, 1);
3219 return bgp_vty_return(vty, ret);
9d3f9705
AC
3220}
3221
718e3744 3222DEFUN (no_neighbor_local_as,
3223 no_neighbor_local_as_cmd,
a636c635 3224 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3225 NO_STR
3226 NEIGHBOR_STR
3227 NEIGHBOR_ADDR_STR2
a636c635
DW
3228 "Specify a local-as number\n"
3229 "AS number used as local AS\n"
3230 "Do not prepend local-as to updates from ebgp peers\n"
3231 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3232{
d62a17ae 3233 int idx_peer = 2;
3234 struct peer *peer;
3235 int ret;
718e3744 3236
d62a17ae 3237 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3238 if (!peer)
3239 return CMD_WARNING_CONFIG_FAILED;
718e3744 3240
d62a17ae 3241 ret = peer_local_as_unset(peer);
3242 return bgp_vty_return(vty, ret);
718e3744 3243}
3244
718e3744 3245
3f9c7369
DS
3246DEFUN (neighbor_solo,
3247 neighbor_solo_cmd,
9ccf14f7 3248 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3249 NEIGHBOR_STR
3250 NEIGHBOR_ADDR_STR2
3251 "Solo peer - part of its own update group\n")
3252{
d62a17ae 3253 int idx_peer = 1;
3254 struct peer *peer;
3255 int ret;
3f9c7369 3256
d62a17ae 3257 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3258 if (!peer)
3259 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3260
d62a17ae 3261 ret = update_group_adjust_soloness(peer, 1);
3262 return bgp_vty_return(vty, ret);
3f9c7369
DS
3263}
3264
3265DEFUN (no_neighbor_solo,
3266 no_neighbor_solo_cmd,
9ccf14f7 3267 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3268 NO_STR
3269 NEIGHBOR_STR
3270 NEIGHBOR_ADDR_STR2
3271 "Solo peer - part of its own update group\n")
3272{
d62a17ae 3273 int idx_peer = 2;
3274 struct peer *peer;
3275 int ret;
3f9c7369 3276
d62a17ae 3277 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3278 if (!peer)
3279 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3280
d62a17ae 3281 ret = update_group_adjust_soloness(peer, 0);
3282 return bgp_vty_return(vty, ret);
3f9c7369
DS
3283}
3284
0df7c91f
PJ
3285DEFUN (neighbor_password,
3286 neighbor_password_cmd,
9ccf14f7 3287 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3288 NEIGHBOR_STR
3289 NEIGHBOR_ADDR_STR2
3290 "Set a password\n"
3291 "The password\n")
3292{
d62a17ae 3293 int idx_peer = 1;
3294 int idx_line = 3;
3295 struct peer *peer;
3296 int ret;
0df7c91f 3297
d62a17ae 3298 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3299 if (!peer)
3300 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3301
d62a17ae 3302 ret = peer_password_set(peer, argv[idx_line]->arg);
3303 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3304}
3305
3306DEFUN (no_neighbor_password,
3307 no_neighbor_password_cmd,
a636c635 3308 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3309 NO_STR
3310 NEIGHBOR_STR
3311 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3312 "Set a password\n"
3313 "The password\n")
0df7c91f 3314{
d62a17ae 3315 int idx_peer = 2;
3316 struct peer *peer;
3317 int ret;
0df7c91f 3318
d62a17ae 3319 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3320 if (!peer)
3321 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3322
d62a17ae 3323 ret = peer_password_unset(peer);
3324 return bgp_vty_return(vty, ret);
0df7c91f 3325}
6b0655a2 3326
718e3744 3327DEFUN (neighbor_activate,
3328 neighbor_activate_cmd,
9ccf14f7 3329 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3330 NEIGHBOR_STR
3331 NEIGHBOR_ADDR_STR2
3332 "Enable the Address Family for this Neighbor\n")
3333{
d62a17ae 3334 int idx_peer = 1;
3335 int ret;
3336 struct peer *peer;
718e3744 3337
d62a17ae 3338 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3339 if (!peer)
3340 return CMD_WARNING_CONFIG_FAILED;
718e3744 3341
d62a17ae 3342 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3343 return bgp_vty_return(vty, ret);
718e3744 3344}
3345
d62a17ae 3346ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3347 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3348 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3349 "Enable the Address Family for this Neighbor\n")
596c17ba 3350
718e3744 3351DEFUN (no_neighbor_activate,
3352 no_neighbor_activate_cmd,
9ccf14f7 3353 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3354 NO_STR
3355 NEIGHBOR_STR
3356 NEIGHBOR_ADDR_STR2
3357 "Enable the Address Family for this Neighbor\n")
3358{
d62a17ae 3359 int idx_peer = 2;
3360 int ret;
3361 struct peer *peer;
718e3744 3362
d62a17ae 3363 /* Lookup peer. */
3364 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3365 if (!peer)
3366 return CMD_WARNING_CONFIG_FAILED;
718e3744 3367
d62a17ae 3368 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3369 return bgp_vty_return(vty, ret);
718e3744 3370}
6b0655a2 3371
d62a17ae 3372ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3373 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3374 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3375 "Enable the Address Family for this Neighbor\n")
596c17ba 3376
718e3744 3377DEFUN (neighbor_set_peer_group,
3378 neighbor_set_peer_group_cmd,
9ccf14f7 3379 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3380 NEIGHBOR_STR
a80beece 3381 NEIGHBOR_ADDR_STR2
718e3744 3382 "Member of the peer-group\n"
16cedbb0 3383 "Peer-group name\n")
718e3744 3384{
d62a17ae 3385 VTY_DECLVAR_CONTEXT(bgp, bgp);
3386 int idx_peer = 1;
3387 int idx_word = 3;
3388 int ret;
3389 as_t as;
3390 union sockunion su;
3391 struct peer *peer;
3392 struct peer_group *group;
3393
d62a17ae 3394 ret = str2sockunion(argv[idx_peer]->arg, &su);
3395 if (ret < 0) {
3396 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3397 if (!peer) {
3398 vty_out(vty, "%% Malformed address or name: %s\n",
3399 argv[idx_peer]->arg);
3400 return CMD_WARNING_CONFIG_FAILED;
3401 }
3402 } else {
3403 if (peer_address_self_check(bgp, &su)) {
3404 vty_out(vty,
3405 "%% Can not configure the local system as neighbor\n");
3406 return CMD_WARNING_CONFIG_FAILED;
3407 }
3408
3409 /* Disallow for dynamic neighbor. */
3410 peer = peer_lookup(bgp, &su);
3411 if (peer && peer_dynamic_neighbor(peer)) {
3412 vty_out(vty,
3413 "%% Operation not allowed on a dynamic neighbor\n");
3414 return CMD_WARNING_CONFIG_FAILED;
3415 }
3416 }
3417
3418 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3419 if (!group) {
3420 vty_out(vty, "%% Configure the peer-group first\n");
3421 return CMD_WARNING_CONFIG_FAILED;
3422 }
3423
3424 ret = peer_group_bind(bgp, &su, peer, group, &as);
3425
3426 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3427 vty_out(vty,
3428 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3429 as);
3430 return CMD_WARNING_CONFIG_FAILED;
3431 }
3432
3433 return bgp_vty_return(vty, ret);
3434}
3435
3436ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3437 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3438 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3439 "Member of the peer-group\n"
3440 "Peer-group name\n")
596c17ba 3441
718e3744 3442DEFUN (no_neighbor_set_peer_group,
3443 no_neighbor_set_peer_group_cmd,
9ccf14f7 3444 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3445 NO_STR
3446 NEIGHBOR_STR
a80beece 3447 NEIGHBOR_ADDR_STR2
718e3744 3448 "Member of the peer-group\n"
16cedbb0 3449 "Peer-group name\n")
718e3744 3450{
d62a17ae 3451 VTY_DECLVAR_CONTEXT(bgp, bgp);
3452 int idx_peer = 2;
3453 int idx_word = 4;
3454 int ret;
3455 struct peer *peer;
3456 struct peer_group *group;
3457
3458 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3459 if (!peer)
3460 return CMD_WARNING_CONFIG_FAILED;
3461
3462 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3463 if (!group) {
3464 vty_out(vty, "%% Configure the peer-group first\n");
3465 return CMD_WARNING_CONFIG_FAILED;
3466 }
718e3744 3467
827ed707 3468 ret = peer_delete(peer);
718e3744 3469
d62a17ae 3470 return bgp_vty_return(vty, ret);
718e3744 3471}
6b0655a2 3472
d62a17ae 3473ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3474 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3475 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3476 "Member of the peer-group\n"
3477 "Peer-group name\n")
596c17ba 3478
d62a17ae 3479static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3480 uint32_t flag, int set)
718e3744 3481{
d62a17ae 3482 int ret;
3483 struct peer *peer;
718e3744 3484
d62a17ae 3485 peer = peer_and_group_lookup_vty(vty, ip_str);
3486 if (!peer)
3487 return CMD_WARNING_CONFIG_FAILED;
718e3744 3488
7ebe625c
QY
3489 /*
3490 * If 'neighbor <interface>', then this is for directly connected peers,
3491 * we should not accept disable-connected-check.
3492 */
3493 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3494 vty_out(vty,
3495 "%s is directly connected peer, cannot accept disable-"
3496 "connected-check\n",
3497 ip_str);
3498 return CMD_WARNING_CONFIG_FAILED;
3499 }
3500
d62a17ae 3501 if (!set && flag == PEER_FLAG_SHUTDOWN)
3502 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3503
d62a17ae 3504 if (set)
3505 ret = peer_flag_set(peer, flag);
3506 else
3507 ret = peer_flag_unset(peer, flag);
718e3744 3508
d62a17ae 3509 return bgp_vty_return(vty, ret);
718e3744 3510}
3511
47cbc09b 3512static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3513{
d62a17ae 3514 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3515}
3516
d62a17ae 3517static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3518 uint32_t flag)
718e3744 3519{
d62a17ae 3520 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3521}
3522
3523/* neighbor passive. */
3524DEFUN (neighbor_passive,
3525 neighbor_passive_cmd,
9ccf14f7 3526 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3527 NEIGHBOR_STR
3528 NEIGHBOR_ADDR_STR2
3529 "Don't send open messages to this neighbor\n")
3530{
d62a17ae 3531 int idx_peer = 1;
3532 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3533}
3534
3535DEFUN (no_neighbor_passive,
3536 no_neighbor_passive_cmd,
9ccf14f7 3537 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3538 NO_STR
3539 NEIGHBOR_STR
3540 NEIGHBOR_ADDR_STR2
3541 "Don't send open messages to this neighbor\n")
3542{
d62a17ae 3543 int idx_peer = 2;
3544 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3545}
6b0655a2 3546
718e3744 3547/* neighbor shutdown. */
73d70fa6
DL
3548DEFUN (neighbor_shutdown_msg,
3549 neighbor_shutdown_msg_cmd,
3550 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3551 NEIGHBOR_STR
3552 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3553 "Administratively shut down this neighbor\n"
3554 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3555 "Shutdown message\n")
718e3744 3556{
d62a17ae 3557 int idx_peer = 1;
73d70fa6 3558
d62a17ae 3559 if (argc >= 5) {
3560 struct peer *peer =
3561 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3562 char *message;
73d70fa6 3563
d62a17ae 3564 if (!peer)
3565 return CMD_WARNING_CONFIG_FAILED;
3566 message = argv_concat(argv, argc, 4);
3567 peer_tx_shutdown_message_set(peer, message);
3568 XFREE(MTYPE_TMP, message);
3569 }
73d70fa6 3570
d62a17ae 3571 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3572}
3573
d62a17ae 3574ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3575 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3576 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3577 "Administratively shut down this neighbor\n")
73d70fa6
DL
3578
3579DEFUN (no_neighbor_shutdown_msg,
3580 no_neighbor_shutdown_msg_cmd,
3581 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3582 NO_STR
3583 NEIGHBOR_STR
3584 NEIGHBOR_ADDR_STR2
3585 "Administratively shut down this neighbor\n"
3586 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3587 "Shutdown message\n")
718e3744 3588{
d62a17ae 3589 int idx_peer = 2;
73d70fa6 3590
d62a17ae 3591 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3592 PEER_FLAG_SHUTDOWN);
718e3744 3593}
6b0655a2 3594
d62a17ae 3595ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3596 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3597 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3598 "Administratively shut down this neighbor\n")
73d70fa6 3599
718e3744 3600/* neighbor capability dynamic. */
3601DEFUN (neighbor_capability_dynamic,
3602 neighbor_capability_dynamic_cmd,
9ccf14f7 3603 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3604 NEIGHBOR_STR
3605 NEIGHBOR_ADDR_STR2
3606 "Advertise capability to the peer\n"
3607 "Advertise dynamic capability to this neighbor\n")
3608{
d62a17ae 3609 int idx_peer = 1;
3610 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3611 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3612}
3613
3614DEFUN (no_neighbor_capability_dynamic,
3615 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3616 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3617 NO_STR
3618 NEIGHBOR_STR
3619 NEIGHBOR_ADDR_STR2
3620 "Advertise capability to the peer\n"
3621 "Advertise dynamic capability to this neighbor\n")
3622{
d62a17ae 3623 int idx_peer = 2;
3624 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3625 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3626}
6b0655a2 3627
718e3744 3628/* neighbor dont-capability-negotiate */
3629DEFUN (neighbor_dont_capability_negotiate,
3630 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3631 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3632 NEIGHBOR_STR
3633 NEIGHBOR_ADDR_STR2
3634 "Do not perform capability negotiation\n")
3635{
d62a17ae 3636 int idx_peer = 1;
3637 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3638 PEER_FLAG_DONT_CAPABILITY);
718e3744 3639}
3640
3641DEFUN (no_neighbor_dont_capability_negotiate,
3642 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3643 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3644 NO_STR
3645 NEIGHBOR_STR
3646 NEIGHBOR_ADDR_STR2
3647 "Do not perform capability negotiation\n")
3648{
d62a17ae 3649 int idx_peer = 2;
3650 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3651 PEER_FLAG_DONT_CAPABILITY);
718e3744 3652}
6b0655a2 3653
8a92a8a0
DS
3654/* neighbor capability extended next hop encoding */
3655DEFUN (neighbor_capability_enhe,
3656 neighbor_capability_enhe_cmd,
9ccf14f7 3657 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3658 NEIGHBOR_STR
3659 NEIGHBOR_ADDR_STR2
3660 "Advertise capability to the peer\n"
3661 "Advertise extended next-hop capability to the peer\n")
3662{
d62a17ae 3663 int idx_peer = 1;
3664 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3665 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3666}
3667
3668DEFUN (no_neighbor_capability_enhe,
3669 no_neighbor_capability_enhe_cmd,
9ccf14f7 3670 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3671 NO_STR
3672 NEIGHBOR_STR
3673 NEIGHBOR_ADDR_STR2
3674 "Advertise capability to the peer\n"
3675 "Advertise extended next-hop capability to the peer\n")
3676{
d62a17ae 3677 int idx_peer = 2;
3678 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3679 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3680}
3681
d62a17ae 3682static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3683 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3684 int set)
718e3744 3685{
d62a17ae 3686 int ret;
3687 struct peer *peer;
718e3744 3688
d62a17ae 3689 peer = peer_and_group_lookup_vty(vty, peer_str);
3690 if (!peer)
3691 return CMD_WARNING_CONFIG_FAILED;
718e3744 3692
d62a17ae 3693 if (set)
3694 ret = peer_af_flag_set(peer, afi, safi, flag);
3695 else
3696 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3697
d62a17ae 3698 return bgp_vty_return(vty, ret);
718e3744 3699}
3700
d62a17ae 3701static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3702 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3703{
d62a17ae 3704 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3705}
3706
d62a17ae 3707static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3708 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3709{
d62a17ae 3710 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3711}
6b0655a2 3712
718e3744 3713/* neighbor capability orf prefix-list. */
3714DEFUN (neighbor_capability_orf_prefix,
3715 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3716 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3717 NEIGHBOR_STR
3718 NEIGHBOR_ADDR_STR2
3719 "Advertise capability to the peer\n"
3720 "Advertise ORF capability to the peer\n"
3721 "Advertise prefixlist ORF capability to this neighbor\n"
3722 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3723 "Capability to RECEIVE the ORF from this neighbor\n"
3724 "Capability to SEND the ORF to this neighbor\n")
3725{
d62a17ae 3726 int idx_peer = 1;
3727 int idx_send_recv = 5;
d7c0a89a 3728 uint16_t flag = 0;
d62a17ae 3729
3730 if (strmatch(argv[idx_send_recv]->text, "send"))
3731 flag = PEER_FLAG_ORF_PREFIX_SM;
3732 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3733 flag = PEER_FLAG_ORF_PREFIX_RM;
3734 else if (strmatch(argv[idx_send_recv]->text, "both"))
3735 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3736 else {
3737 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3738 return CMD_WARNING_CONFIG_FAILED;
3739 }
3740
3741 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3742 bgp_node_safi(vty), flag);
3743}
3744
3745ALIAS_HIDDEN(
3746 neighbor_capability_orf_prefix,
3747 neighbor_capability_orf_prefix_hidden_cmd,
3748 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3749 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3750 "Advertise capability to the peer\n"
3751 "Advertise ORF capability to the peer\n"
3752 "Advertise prefixlist ORF capability to this neighbor\n"
3753 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3754 "Capability to RECEIVE the ORF from this neighbor\n"
3755 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3756
718e3744 3757DEFUN (no_neighbor_capability_orf_prefix,
3758 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3759 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3760 NO_STR
3761 NEIGHBOR_STR
3762 NEIGHBOR_ADDR_STR2
3763 "Advertise capability to the peer\n"
3764 "Advertise ORF capability to the peer\n"
3765 "Advertise prefixlist ORF capability to this neighbor\n"
3766 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3767 "Capability to RECEIVE the ORF from this neighbor\n"
3768 "Capability to SEND the ORF to this neighbor\n")
3769{
d62a17ae 3770 int idx_peer = 2;
3771 int idx_send_recv = 6;
d7c0a89a 3772 uint16_t flag = 0;
d62a17ae 3773
3774 if (strmatch(argv[idx_send_recv]->text, "send"))
3775 flag = PEER_FLAG_ORF_PREFIX_SM;
3776 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3777 flag = PEER_FLAG_ORF_PREFIX_RM;
3778 else if (strmatch(argv[idx_send_recv]->text, "both"))
3779 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3780 else {
3781 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3782 return CMD_WARNING_CONFIG_FAILED;
3783 }
3784
3785 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3786 bgp_node_afi(vty), bgp_node_safi(vty),
3787 flag);
3788}
3789
3790ALIAS_HIDDEN(
3791 no_neighbor_capability_orf_prefix,
3792 no_neighbor_capability_orf_prefix_hidden_cmd,
3793 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3794 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3795 "Advertise capability to the peer\n"
3796 "Advertise ORF capability to the peer\n"
3797 "Advertise prefixlist ORF capability to this neighbor\n"
3798 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3799 "Capability to RECEIVE the ORF from this neighbor\n"
3800 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3801
718e3744 3802/* neighbor next-hop-self. */
3803DEFUN (neighbor_nexthop_self,
3804 neighbor_nexthop_self_cmd,
9ccf14f7 3805 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3806 NEIGHBOR_STR
3807 NEIGHBOR_ADDR_STR2
a538debe 3808 "Disable the next hop calculation for this neighbor\n")
718e3744 3809{
d62a17ae 3810 int idx_peer = 1;
3811 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3812 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3813}
9e7a53c1 3814
d62a17ae 3815ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3816 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3817 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3818 "Disable the next hop calculation for this neighbor\n")
596c17ba 3819
a538debe
DS
3820/* neighbor next-hop-self. */
3821DEFUN (neighbor_nexthop_self_force,
3822 neighbor_nexthop_self_force_cmd,
9ccf14f7 3823 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3824 NEIGHBOR_STR
3825 NEIGHBOR_ADDR_STR2
3826 "Disable the next hop calculation for this neighbor\n"
3827 "Set the next hop to self for reflected routes\n")
3828{
d62a17ae 3829 int idx_peer = 1;
3830 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3831 bgp_node_safi(vty),
3832 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3833}
3834
d62a17ae 3835ALIAS_HIDDEN(neighbor_nexthop_self_force,
3836 neighbor_nexthop_self_force_hidden_cmd,
3837 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3838 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3839 "Disable the next hop calculation for this neighbor\n"
3840 "Set the next hop to self for reflected routes\n")
596c17ba 3841
718e3744 3842DEFUN (no_neighbor_nexthop_self,
3843 no_neighbor_nexthop_self_cmd,
9ccf14f7 3844 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3845 NO_STR
3846 NEIGHBOR_STR
3847 NEIGHBOR_ADDR_STR2
a538debe 3848 "Disable the next hop calculation for this neighbor\n")
718e3744 3849{
d62a17ae 3850 int idx_peer = 2;
3851 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3852 bgp_node_afi(vty), bgp_node_safi(vty),
3853 PEER_FLAG_NEXTHOP_SELF);
718e3744 3854}
6b0655a2 3855
d62a17ae 3856ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3857 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3858 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3859 "Disable the next hop calculation for this neighbor\n")
596c17ba 3860
88b8ed8d 3861DEFUN (no_neighbor_nexthop_self_force,
a538debe 3862 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3863 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3864 NO_STR
3865 NEIGHBOR_STR
3866 NEIGHBOR_ADDR_STR2
3867 "Disable the next hop calculation for this neighbor\n"
3868 "Set the next hop to self for reflected routes\n")
88b8ed8d 3869{
d62a17ae 3870 int idx_peer = 2;
3871 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3872 bgp_node_afi(vty), bgp_node_safi(vty),
3873 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3874}
a538debe 3875
d62a17ae 3876ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3877 no_neighbor_nexthop_self_force_hidden_cmd,
3878 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3879 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3880 "Disable the next hop calculation for this neighbor\n"
3881 "Set the next hop to self for reflected routes\n")
596c17ba 3882
c7122e14
DS
3883/* neighbor as-override */
3884DEFUN (neighbor_as_override,
3885 neighbor_as_override_cmd,
9ccf14f7 3886 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3887 NEIGHBOR_STR
3888 NEIGHBOR_ADDR_STR2
3889 "Override ASNs in outbound updates if aspath equals remote-as\n")
3890{
d62a17ae 3891 int idx_peer = 1;
3892 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3893 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3894}
3895
d62a17ae 3896ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3897 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3898 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3899 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3900
c7122e14
DS
3901DEFUN (no_neighbor_as_override,
3902 no_neighbor_as_override_cmd,
9ccf14f7 3903 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3904 NO_STR
3905 NEIGHBOR_STR
3906 NEIGHBOR_ADDR_STR2
3907 "Override ASNs in outbound updates if aspath equals remote-as\n")
3908{
d62a17ae 3909 int idx_peer = 2;
3910 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3911 bgp_node_afi(vty), bgp_node_safi(vty),
3912 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3913}
3914
d62a17ae 3915ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3916 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3917 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3918 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3919
718e3744 3920/* neighbor remove-private-AS. */
3921DEFUN (neighbor_remove_private_as,
3922 neighbor_remove_private_as_cmd,
9ccf14f7 3923 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3924 NEIGHBOR_STR
3925 NEIGHBOR_ADDR_STR2
5000f21c 3926 "Remove private ASNs in outbound updates\n")
718e3744 3927{
d62a17ae 3928 int idx_peer = 1;
3929 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3930 bgp_node_safi(vty),
3931 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3932}
3933
d62a17ae 3934ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3935 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3936 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3937 "Remove private ASNs in outbound updates\n")
596c17ba 3938
5000f21c
DS
3939DEFUN (neighbor_remove_private_as_all,
3940 neighbor_remove_private_as_all_cmd,
9ccf14f7 3941 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3942 NEIGHBOR_STR
3943 NEIGHBOR_ADDR_STR2
3944 "Remove private ASNs in outbound updates\n"
efd7904e 3945 "Apply to all AS numbers\n")
5000f21c 3946{
d62a17ae 3947 int idx_peer = 1;
3948 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3949 bgp_node_safi(vty),
3950 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3951}
3952
d62a17ae 3953ALIAS_HIDDEN(neighbor_remove_private_as_all,
3954 neighbor_remove_private_as_all_hidden_cmd,
3955 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3956 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3957 "Remove private ASNs in outbound updates\n"
3958 "Apply to all AS numbers")
596c17ba 3959
5000f21c
DS
3960DEFUN (neighbor_remove_private_as_replace_as,
3961 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3962 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3963 NEIGHBOR_STR
3964 NEIGHBOR_ADDR_STR2
3965 "Remove private ASNs in outbound updates\n"
3966 "Replace private ASNs with our ASN in outbound updates\n")
3967{
d62a17ae 3968 int idx_peer = 1;
3969 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3970 bgp_node_safi(vty),
3971 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3972}
3973
d62a17ae 3974ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3975 neighbor_remove_private_as_replace_as_hidden_cmd,
3976 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3977 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3978 "Remove private ASNs in outbound updates\n"
3979 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3980
5000f21c
DS
3981DEFUN (neighbor_remove_private_as_all_replace_as,
3982 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3983 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3984 NEIGHBOR_STR
3985 NEIGHBOR_ADDR_STR2
3986 "Remove private ASNs in outbound updates\n"
16cedbb0 3987 "Apply to all AS numbers\n"
5000f21c
DS
3988 "Replace private ASNs with our ASN in outbound updates\n")
3989{
d62a17ae 3990 int idx_peer = 1;
3991 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3992 bgp_node_safi(vty),
3993 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3994}
3995
d62a17ae 3996ALIAS_HIDDEN(
3997 neighbor_remove_private_as_all_replace_as,
3998 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3999 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4000 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4001 "Remove private ASNs in outbound updates\n"
4002 "Apply to all AS numbers\n"
4003 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4004
718e3744 4005DEFUN (no_neighbor_remove_private_as,
4006 no_neighbor_remove_private_as_cmd,
9ccf14f7 4007 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4008 NO_STR
4009 NEIGHBOR_STR
4010 NEIGHBOR_ADDR_STR2
5000f21c 4011 "Remove private ASNs in outbound updates\n")
718e3744 4012{
d62a17ae 4013 int idx_peer = 2;
4014 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4015 bgp_node_afi(vty), bgp_node_safi(vty),
4016 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4017}
6b0655a2 4018
d62a17ae 4019ALIAS_HIDDEN(no_neighbor_remove_private_as,
4020 no_neighbor_remove_private_as_hidden_cmd,
4021 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4022 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4023 "Remove private ASNs in outbound updates\n")
596c17ba 4024
88b8ed8d 4025DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4026 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4027 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4028 NO_STR
4029 NEIGHBOR_STR
4030 NEIGHBOR_ADDR_STR2
4031 "Remove private ASNs in outbound updates\n"
16cedbb0 4032 "Apply to all AS numbers\n")
88b8ed8d 4033{
d62a17ae 4034 int idx_peer = 2;
4035 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4036 bgp_node_afi(vty), bgp_node_safi(vty),
4037 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4038}
5000f21c 4039
d62a17ae 4040ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4041 no_neighbor_remove_private_as_all_hidden_cmd,
4042 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4043 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4044 "Remove private ASNs in outbound updates\n"
4045 "Apply to all AS numbers\n")
596c17ba 4046
88b8ed8d 4047DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4048 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4049 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4050 NO_STR
4051 NEIGHBOR_STR
4052 NEIGHBOR_ADDR_STR2
4053 "Remove private ASNs in outbound updates\n"
4054 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4055{
d62a17ae 4056 int idx_peer = 2;
4057 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4058 bgp_node_afi(vty), bgp_node_safi(vty),
4059 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4060}
5000f21c 4061
d62a17ae 4062ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4063 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4064 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4065 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4066 "Remove private ASNs in outbound updates\n"
4067 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4068
88b8ed8d 4069DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4070 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4071 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4072 NO_STR
4073 NEIGHBOR_STR
4074 NEIGHBOR_ADDR_STR2
4075 "Remove private ASNs in outbound updates\n"
16cedbb0 4076 "Apply to all AS numbers\n"
5000f21c 4077 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4078{
d62a17ae 4079 int idx_peer = 2;
4080 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4081 bgp_node_afi(vty), bgp_node_safi(vty),
4082 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4083}
5000f21c 4084
d62a17ae 4085ALIAS_HIDDEN(
4086 no_neighbor_remove_private_as_all_replace_as,
4087 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4088 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4089 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4090 "Remove private ASNs in outbound updates\n"
4091 "Apply to all AS numbers\n"
4092 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4093
5000f21c 4094
718e3744 4095/* neighbor send-community. */
4096DEFUN (neighbor_send_community,
4097 neighbor_send_community_cmd,
9ccf14f7 4098 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4099 NEIGHBOR_STR
4100 NEIGHBOR_ADDR_STR2
4101 "Send Community attribute to this neighbor\n")
4102{
d62a17ae 4103 int idx_peer = 1;
27c05d4d 4104
d62a17ae 4105 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4106 bgp_node_safi(vty),
4107 PEER_FLAG_SEND_COMMUNITY);
718e3744 4108}
4109
d62a17ae 4110ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4111 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4112 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4113 "Send Community attribute to this neighbor\n")
596c17ba 4114
718e3744 4115DEFUN (no_neighbor_send_community,
4116 no_neighbor_send_community_cmd,
9ccf14f7 4117 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4118 NO_STR
4119 NEIGHBOR_STR
4120 NEIGHBOR_ADDR_STR2
4121 "Send Community attribute to this neighbor\n")
4122{
d62a17ae 4123 int idx_peer = 2;
27c05d4d 4124
d62a17ae 4125 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4126 bgp_node_afi(vty), bgp_node_safi(vty),
4127 PEER_FLAG_SEND_COMMUNITY);
718e3744 4128}
6b0655a2 4129
d62a17ae 4130ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4131 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4132 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4133 "Send Community attribute to this neighbor\n")
596c17ba 4134
718e3744 4135/* neighbor send-community extended. */
4136DEFUN (neighbor_send_community_type,
4137 neighbor_send_community_type_cmd,
57d187bc 4138 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4139 NEIGHBOR_STR
4140 NEIGHBOR_ADDR_STR2
4141 "Send Community attribute to this neighbor\n"
4142 "Send Standard and Extended Community attributes\n"
57d187bc 4143 "Send Standard, Large and Extended Community attributes\n"
718e3744 4144 "Send Extended Community attributes\n"
57d187bc
JS
4145 "Send Standard Community attributes\n"
4146 "Send Large Community attributes\n")
718e3744 4147{
27c05d4d 4148 int idx_peer = 1;
d7c0a89a 4149 uint32_t flag = 0;
27c05d4d 4150 const char *type = argv[argc - 1]->text;
d62a17ae 4151
27c05d4d 4152 if (strmatch(type, "standard")) {
d62a17ae 4153 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4154 } else if (strmatch(type, "extended")) {
d62a17ae 4155 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4156 } else if (strmatch(type, "large")) {
d62a17ae 4157 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4158 } else if (strmatch(type, "both")) {
d62a17ae 4159 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4160 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4161 } else { /* if (strmatch(type, "all")) */
d62a17ae 4162 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4163 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4164 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4165 }
4166
27c05d4d 4167 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4168 bgp_node_safi(vty), flag);
4169}
4170
4171ALIAS_HIDDEN(
4172 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4173 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4174 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4175 "Send Community attribute to this neighbor\n"
4176 "Send Standard and Extended Community attributes\n"
4177 "Send Standard, Large and Extended Community attributes\n"
4178 "Send Extended Community attributes\n"
4179 "Send Standard Community attributes\n"
4180 "Send Large Community attributes\n")
596c17ba 4181
718e3744 4182DEFUN (no_neighbor_send_community_type,
4183 no_neighbor_send_community_type_cmd,
57d187bc 4184 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4185 NO_STR
4186 NEIGHBOR_STR
4187 NEIGHBOR_ADDR_STR2
4188 "Send Community attribute to this neighbor\n"
4189 "Send Standard and Extended Community attributes\n"
57d187bc 4190 "Send Standard, Large and Extended Community attributes\n"
718e3744 4191 "Send Extended Community attributes\n"
57d187bc
JS
4192 "Send Standard Community attributes\n"
4193 "Send Large Community attributes\n")
718e3744 4194{
d62a17ae 4195 int idx_peer = 2;
27c05d4d 4196 uint32_t flag = 0;
d62a17ae 4197 const char *type = argv[argc - 1]->text;
4198
27c05d4d
PM
4199 if (strmatch(type, "standard")) {
4200 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4201 } else if (strmatch(type, "extended")) {
4202 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4203 } else if (strmatch(type, "large")) {
4204 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4205 } else if (strmatch(type, "both")) {
4206 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4207 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4208 } else { /* if (strmatch(type, "all")) */
4209 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4210 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4211 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4212 }
4213
4214 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4215 bgp_node_afi(vty), bgp_node_safi(vty),
4216 flag);
d62a17ae 4217}
4218
4219ALIAS_HIDDEN(
4220 no_neighbor_send_community_type,
4221 no_neighbor_send_community_type_hidden_cmd,
4222 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4223 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4224 "Send Community attribute to this neighbor\n"
4225 "Send Standard and Extended Community attributes\n"
4226 "Send Standard, Large and Extended Community attributes\n"
4227 "Send Extended Community attributes\n"
4228 "Send Standard Community attributes\n"
4229 "Send Large Community attributes\n")
596c17ba 4230
718e3744 4231/* neighbor soft-reconfig. */
4232DEFUN (neighbor_soft_reconfiguration,
4233 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4234 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4235 NEIGHBOR_STR
4236 NEIGHBOR_ADDR_STR2
4237 "Per neighbor soft reconfiguration\n"
4238 "Allow inbound soft reconfiguration for this neighbor\n")
4239{
d62a17ae 4240 int idx_peer = 1;
4241 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4242 bgp_node_safi(vty),
4243 PEER_FLAG_SOFT_RECONFIG);
718e3744 4244}
4245
d62a17ae 4246ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4247 neighbor_soft_reconfiguration_hidden_cmd,
4248 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4249 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4250 "Per neighbor soft reconfiguration\n"
4251 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4252
718e3744 4253DEFUN (no_neighbor_soft_reconfiguration,
4254 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4255 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4256 NO_STR
4257 NEIGHBOR_STR
4258 NEIGHBOR_ADDR_STR2
4259 "Per neighbor soft reconfiguration\n"
4260 "Allow inbound soft reconfiguration for this neighbor\n")
4261{
d62a17ae 4262 int idx_peer = 2;
4263 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4264 bgp_node_afi(vty), bgp_node_safi(vty),
4265 PEER_FLAG_SOFT_RECONFIG);
718e3744 4266}
6b0655a2 4267
d62a17ae 4268ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4269 no_neighbor_soft_reconfiguration_hidden_cmd,
4270 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4271 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4272 "Per neighbor soft reconfiguration\n"
4273 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4274
718e3744 4275DEFUN (neighbor_route_reflector_client,
4276 neighbor_route_reflector_client_cmd,
9ccf14f7 4277 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4278 NEIGHBOR_STR
4279 NEIGHBOR_ADDR_STR2
4280 "Configure a neighbor as Route Reflector client\n")
4281{
d62a17ae 4282 int idx_peer = 1;
4283 struct peer *peer;
718e3744 4284
4285
d62a17ae 4286 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4287 if (!peer)
4288 return CMD_WARNING_CONFIG_FAILED;
718e3744 4289
d62a17ae 4290 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4291 bgp_node_safi(vty),
4292 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4293}
4294
d62a17ae 4295ALIAS_HIDDEN(neighbor_route_reflector_client,
4296 neighbor_route_reflector_client_hidden_cmd,
4297 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4298 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4299 "Configure a neighbor as Route Reflector client\n")
596c17ba 4300
718e3744 4301DEFUN (no_neighbor_route_reflector_client,
4302 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4303 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4304 NO_STR
4305 NEIGHBOR_STR
4306 NEIGHBOR_ADDR_STR2
4307 "Configure a neighbor as Route Reflector client\n")
4308{
d62a17ae 4309 int idx_peer = 2;
4310 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4311 bgp_node_afi(vty), bgp_node_safi(vty),
4312 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4313}
6b0655a2 4314
d62a17ae 4315ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4316 no_neighbor_route_reflector_client_hidden_cmd,
4317 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4318 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4319 "Configure a neighbor as Route Reflector client\n")
596c17ba 4320
718e3744 4321/* neighbor route-server-client. */
4322DEFUN (neighbor_route_server_client,
4323 neighbor_route_server_client_cmd,
9ccf14f7 4324 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4325 NEIGHBOR_STR
4326 NEIGHBOR_ADDR_STR2
4327 "Configure a neighbor as Route Server client\n")
4328{
d62a17ae 4329 int idx_peer = 1;
4330 struct peer *peer;
2a3d5731 4331
d62a17ae 4332 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4333 if (!peer)
4334 return CMD_WARNING_CONFIG_FAILED;
4335 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4336 bgp_node_safi(vty),
4337 PEER_FLAG_RSERVER_CLIENT);
718e3744 4338}
4339
d62a17ae 4340ALIAS_HIDDEN(neighbor_route_server_client,
4341 neighbor_route_server_client_hidden_cmd,
4342 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4343 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4344 "Configure a neighbor as Route Server client\n")
596c17ba 4345
718e3744 4346DEFUN (no_neighbor_route_server_client,
4347 no_neighbor_route_server_client_cmd,
9ccf14f7 4348 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4349 NO_STR
4350 NEIGHBOR_STR
4351 NEIGHBOR_ADDR_STR2
4352 "Configure a neighbor as Route Server client\n")
fee0f4c6 4353{
d62a17ae 4354 int idx_peer = 2;
4355 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4356 bgp_node_afi(vty), bgp_node_safi(vty),
4357 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4358}
6b0655a2 4359
d62a17ae 4360ALIAS_HIDDEN(no_neighbor_route_server_client,
4361 no_neighbor_route_server_client_hidden_cmd,
4362 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4363 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4364 "Configure a neighbor as Route Server client\n")
596c17ba 4365
fee0f4c6 4366DEFUN (neighbor_nexthop_local_unchanged,
4367 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4368 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4369 NEIGHBOR_STR
4370 NEIGHBOR_ADDR_STR2
4371 "Configure treatment of outgoing link-local nexthop attribute\n"
4372 "Leave link-local nexthop unchanged for this peer\n")
4373{
d62a17ae 4374 int idx_peer = 1;
4375 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4376 bgp_node_safi(vty),
4377 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4378}
6b0655a2 4379
fee0f4c6 4380DEFUN (no_neighbor_nexthop_local_unchanged,
4381 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4382 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4383 NO_STR
4384 NEIGHBOR_STR
4385 NEIGHBOR_ADDR_STR2
4386 "Configure treatment of outgoing link-local-nexthop attribute\n"
4387 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4388{
d62a17ae 4389 int idx_peer = 2;
4390 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4391 bgp_node_afi(vty), bgp_node_safi(vty),
4392 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4393}
6b0655a2 4394
718e3744 4395DEFUN (neighbor_attr_unchanged,
4396 neighbor_attr_unchanged_cmd,
a8206004 4397 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4398 NEIGHBOR_STR
4399 NEIGHBOR_ADDR_STR2
4400 "BGP attribute is propagated unchanged to this neighbor\n"
4401 "As-path attribute\n"
4402 "Nexthop attribute\n"
a8206004 4403 "Med attribute\n")
718e3744 4404{
d62a17ae 4405 int idx = 0;
8eeb0335
DW
4406 char *peer_str = argv[1]->arg;
4407 struct peer *peer;
d7c0a89a 4408 uint16_t flags = 0;
8eeb0335
DW
4409 afi_t afi = bgp_node_afi(vty);
4410 safi_t safi = bgp_node_safi(vty);
4411
4412 peer = peer_and_group_lookup_vty(vty, peer_str);
4413 if (!peer)
4414 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4415
4416 if (argv_find(argv, argc, "as-path", &idx))
4417 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4418 idx = 0;
4419 if (argv_find(argv, argc, "next-hop", &idx))
4420 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4421 idx = 0;
4422 if (argv_find(argv, argc, "med", &idx))
4423 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4424
8eeb0335
DW
4425 /* no flags means all of them! */
4426 if (!flags) {
d62a17ae 4427 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4428 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4429 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4430 } else {
a4d82a8a
PZ
4431 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4432 && peer_af_flag_check(peer, afi, safi,
4433 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4434 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4435 PEER_FLAG_AS_PATH_UNCHANGED);
4436 }
4437
a4d82a8a
PZ
4438 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4439 && peer_af_flag_check(peer, afi, safi,
4440 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4441 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4442 PEER_FLAG_NEXTHOP_UNCHANGED);
4443 }
4444
a4d82a8a
PZ
4445 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4446 && peer_af_flag_check(peer, afi, safi,
4447 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4448 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4449 PEER_FLAG_MED_UNCHANGED);
4450 }
d62a17ae 4451 }
4452
8eeb0335 4453 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4454}
4455
4456ALIAS_HIDDEN(
4457 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4458 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4459 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4460 "BGP attribute is propagated unchanged to this neighbor\n"
4461 "As-path attribute\n"
4462 "Nexthop attribute\n"
4463 "Med attribute\n")
596c17ba 4464
718e3744 4465DEFUN (no_neighbor_attr_unchanged,
4466 no_neighbor_attr_unchanged_cmd,
a8206004 4467 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4468 NO_STR
718e3744 4469 NEIGHBOR_STR
4470 NEIGHBOR_ADDR_STR2
31500417
DW
4471 "BGP attribute is propagated unchanged to this neighbor\n"
4472 "As-path attribute\n"
40e718b5 4473 "Nexthop attribute\n"
a8206004 4474 "Med attribute\n")
718e3744 4475{
d62a17ae 4476 int idx = 0;
4477 char *peer = argv[2]->arg;
d7c0a89a 4478 uint16_t flags = 0;
d62a17ae 4479
4480 if (argv_find(argv, argc, "as-path", &idx))
4481 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4482 idx = 0;
4483 if (argv_find(argv, argc, "next-hop", &idx))
4484 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4485 idx = 0;
4486 if (argv_find(argv, argc, "med", &idx))
4487 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4488
4489 if (!flags) // no flags means all of them!
4490 {
4491 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4492 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4493 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4494 }
4495
4496 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4497 bgp_node_safi(vty), flags);
4498}
4499
4500ALIAS_HIDDEN(
4501 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4502 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4503 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4504 "BGP attribute is propagated unchanged to this neighbor\n"
4505 "As-path attribute\n"
4506 "Nexthop attribute\n"
4507 "Med attribute\n")
718e3744 4508
718e3744 4509/* EBGP multihop configuration. */
d62a17ae 4510static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4511 const char *ttl_str)
718e3744 4512{
d62a17ae 4513 struct peer *peer;
4514 unsigned int ttl;
718e3744 4515
d62a17ae 4516 peer = peer_and_group_lookup_vty(vty, ip_str);
4517 if (!peer)
4518 return CMD_WARNING_CONFIG_FAILED;
718e3744 4519
d62a17ae 4520 if (peer->conf_if)
4521 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4522
d62a17ae 4523 if (!ttl_str)
4524 ttl = MAXTTL;
4525 else
4526 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4527
d62a17ae 4528 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4529}
4530
d62a17ae 4531static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4532{
d62a17ae 4533 struct peer *peer;
718e3744 4534
d62a17ae 4535 peer = peer_and_group_lookup_vty(vty, ip_str);
4536 if (!peer)
4537 return CMD_WARNING_CONFIG_FAILED;
718e3744 4538
d62a17ae 4539 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4540}
4541
4542/* neighbor ebgp-multihop. */
4543DEFUN (neighbor_ebgp_multihop,
4544 neighbor_ebgp_multihop_cmd,
9ccf14f7 4545 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4546 NEIGHBOR_STR
4547 NEIGHBOR_ADDR_STR2
4548 "Allow EBGP neighbors not on directly connected networks\n")
4549{
d62a17ae 4550 int idx_peer = 1;
4551 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4552}
4553
4554DEFUN (neighbor_ebgp_multihop_ttl,
4555 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4556 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4557 NEIGHBOR_STR
4558 NEIGHBOR_ADDR_STR2
4559 "Allow EBGP neighbors not on directly connected networks\n"
4560 "maximum hop count\n")
4561{
d62a17ae 4562 int idx_peer = 1;
4563 int idx_number = 3;
4564 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4565 argv[idx_number]->arg);
718e3744 4566}
4567
4568DEFUN (no_neighbor_ebgp_multihop,
4569 no_neighbor_ebgp_multihop_cmd,
a636c635 4570 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4571 NO_STR
4572 NEIGHBOR_STR
4573 NEIGHBOR_ADDR_STR2
a636c635
DW
4574 "Allow EBGP neighbors not on directly connected networks\n"
4575 "maximum hop count\n")
718e3744 4576{
d62a17ae 4577 int idx_peer = 2;
4578 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4579}
4580
6b0655a2 4581
6ffd2079 4582/* disable-connected-check */
4583DEFUN (neighbor_disable_connected_check,
4584 neighbor_disable_connected_check_cmd,
7ebe625c 4585 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4586 NEIGHBOR_STR
7ebe625c 4587 NEIGHBOR_ADDR_STR2
a636c635
DW
4588 "one-hop away EBGP peer using loopback address\n"
4589 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4590{
d62a17ae 4591 int idx_peer = 1;
4592 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4593 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4594}
4595
4596DEFUN (no_neighbor_disable_connected_check,
4597 no_neighbor_disable_connected_check_cmd,
7ebe625c 4598 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4599 NO_STR
4600 NEIGHBOR_STR
7ebe625c 4601 NEIGHBOR_ADDR_STR2
a636c635
DW
4602 "one-hop away EBGP peer using loopback address\n"
4603 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4604{
d62a17ae 4605 int idx_peer = 2;
4606 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4607 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4608}
4609
47cbc09b
PM
4610
4611/* enforce-first-as */
4612DEFUN (neighbor_enforce_first_as,
4613 neighbor_enforce_first_as_cmd,
4614 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4615 NEIGHBOR_STR
4616 NEIGHBOR_ADDR_STR2
4617 "Enforce the first AS for EBGP routes\n")
4618{
4619 int idx_peer = 1;
4620
4621 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4622 PEER_FLAG_ENFORCE_FIRST_AS);
4623}
4624
4625DEFUN (no_neighbor_enforce_first_as,
4626 no_neighbor_enforce_first_as_cmd,
4627 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4628 NO_STR
4629 NEIGHBOR_STR
4630 NEIGHBOR_ADDR_STR2
4631 "Enforce the first AS for EBGP routes\n")
4632{
4633 int idx_peer = 2;
4634
4635 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4636 PEER_FLAG_ENFORCE_FIRST_AS);
4637}
4638
4639
718e3744 4640DEFUN (neighbor_description,
4641 neighbor_description_cmd,
e961923c 4642 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4643 NEIGHBOR_STR
4644 NEIGHBOR_ADDR_STR2
4645 "Neighbor specific description\n"
4646 "Up to 80 characters describing this neighbor\n")
4647{
d62a17ae 4648 int idx_peer = 1;
4649 int idx_line = 3;
4650 struct peer *peer;
4651 char *str;
718e3744 4652
d62a17ae 4653 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4654 if (!peer)
4655 return CMD_WARNING_CONFIG_FAILED;
718e3744 4656
d62a17ae 4657 str = argv_concat(argv, argc, idx_line);
718e3744 4658
d62a17ae 4659 peer_description_set(peer, str);
718e3744 4660
d62a17ae 4661 XFREE(MTYPE_TMP, str);
718e3744 4662
d62a17ae 4663 return CMD_SUCCESS;
718e3744 4664}
4665
4666DEFUN (no_neighbor_description,
4667 no_neighbor_description_cmd,
a14810f4 4668 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4669 NO_STR
4670 NEIGHBOR_STR
4671 NEIGHBOR_ADDR_STR2
a14810f4 4672 "Neighbor specific description\n")
718e3744 4673{
d62a17ae 4674 int idx_peer = 2;
4675 struct peer *peer;
718e3744 4676
d62a17ae 4677 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4678 if (!peer)
4679 return CMD_WARNING_CONFIG_FAILED;
718e3744 4680
d62a17ae 4681 peer_description_unset(peer);
718e3744 4682
d62a17ae 4683 return CMD_SUCCESS;
718e3744 4684}
4685
a14810f4
PM
4686ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4687 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4688 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4689 "Neighbor specific description\n"
4690 "Up to 80 characters describing this neighbor\n")
6b0655a2 4691
718e3744 4692/* Neighbor update-source. */
d62a17ae 4693static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4694 const char *source_str)
4695{
4696 struct peer *peer;
4697 struct prefix p;
a14810f4 4698 union sockunion su;
d62a17ae 4699
4700 peer = peer_and_group_lookup_vty(vty, peer_str);
4701 if (!peer)
4702 return CMD_WARNING_CONFIG_FAILED;
4703
4704 if (peer->conf_if)
4705 return CMD_WARNING;
4706
4707 if (source_str) {
a14810f4 4708 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4709 peer_update_source_addr_set(peer, &su);
4710 else {
4711 if (str2prefix(source_str, &p)) {
4712 vty_out(vty,
4713 "%% Invalid update-source, remove prefix length \n");
4714 return CMD_WARNING_CONFIG_FAILED;
4715 } else
4716 peer_update_source_if_set(peer, source_str);
4717 }
4718 } else
4719 peer_update_source_unset(peer);
4720
4721 return CMD_SUCCESS;
4722}
4723
4724#define BGP_UPDATE_SOURCE_HELP_STR \
4725 "IPv4 address\n" \
4726 "IPv6 address\n" \
4727 "Interface name (requires zebra to be running)\n"
369688c0 4728
718e3744 4729DEFUN (neighbor_update_source,
4730 neighbor_update_source_cmd,
9ccf14f7 4731 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4732 NEIGHBOR_STR
4733 NEIGHBOR_ADDR_STR2
4734 "Source of routing updates\n"
369688c0 4735 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4736{
d62a17ae 4737 int idx_peer = 1;
4738 int idx_peer_2 = 3;
4739 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4740 argv[idx_peer_2]->arg);
718e3744 4741}
4742
4743DEFUN (no_neighbor_update_source,
4744 no_neighbor_update_source_cmd,
c7178fe7 4745 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4746 NO_STR
4747 NEIGHBOR_STR
4748 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4749 "Source of routing updates\n"
4750 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4751{
d62a17ae 4752 int idx_peer = 2;
4753 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4754}
6b0655a2 4755
d62a17ae 4756static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4757 afi_t afi, safi_t safi,
4758 const char *rmap, int set)
718e3744 4759{
d62a17ae 4760 int ret;
4761 struct peer *peer;
718e3744 4762
d62a17ae 4763 peer = peer_and_group_lookup_vty(vty, peer_str);
4764 if (!peer)
4765 return CMD_WARNING_CONFIG_FAILED;
718e3744 4766
d62a17ae 4767 if (set)
4768 ret = peer_default_originate_set(peer, afi, safi, rmap);
4769 else
4770 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4771
d62a17ae 4772 return bgp_vty_return(vty, ret);
718e3744 4773}
4774
4775/* neighbor default-originate. */
4776DEFUN (neighbor_default_originate,
4777 neighbor_default_originate_cmd,
9ccf14f7 4778 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4779 NEIGHBOR_STR
4780 NEIGHBOR_ADDR_STR2
4781 "Originate default route to this neighbor\n")
4782{
d62a17ae 4783 int idx_peer = 1;
4784 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4785 bgp_node_afi(vty),
4786 bgp_node_safi(vty), NULL, 1);
718e3744 4787}
4788
d62a17ae 4789ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4790 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4791 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4792 "Originate default route to this neighbor\n")
596c17ba 4793
718e3744 4794DEFUN (neighbor_default_originate_rmap,
4795 neighbor_default_originate_rmap_cmd,
9ccf14f7 4796 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4797 NEIGHBOR_STR
4798 NEIGHBOR_ADDR_STR2
4799 "Originate default route to this neighbor\n"
4800 "Route-map to specify criteria to originate default\n"
4801 "route-map name\n")
4802{
d62a17ae 4803 int idx_peer = 1;
4804 int idx_word = 4;
4805 return peer_default_originate_set_vty(
4806 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4807 argv[idx_word]->arg, 1);
718e3744 4808}
4809
d62a17ae 4810ALIAS_HIDDEN(
4811 neighbor_default_originate_rmap,
4812 neighbor_default_originate_rmap_hidden_cmd,
4813 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4814 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4815 "Originate default route to this neighbor\n"
4816 "Route-map to specify criteria to originate default\n"
4817 "route-map name\n")
596c17ba 4818
718e3744 4819DEFUN (no_neighbor_default_originate,
4820 no_neighbor_default_originate_cmd,
a636c635 4821 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4822 NO_STR
4823 NEIGHBOR_STR
4824 NEIGHBOR_ADDR_STR2
a636c635
DW
4825 "Originate default route to this neighbor\n"
4826 "Route-map to specify criteria to originate default\n"
4827 "route-map name\n")
718e3744 4828{
d62a17ae 4829 int idx_peer = 2;
4830 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4831 bgp_node_afi(vty),
4832 bgp_node_safi(vty), NULL, 0);
718e3744 4833}
4834
d62a17ae 4835ALIAS_HIDDEN(
4836 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4837 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4838 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4839 "Originate default route to this neighbor\n"
4840 "Route-map to specify criteria to originate default\n"
4841 "route-map name\n")
596c17ba 4842
6b0655a2 4843
718e3744 4844/* Set neighbor's BGP port. */
d62a17ae 4845static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4846 const char *port_str)
4847{
4848 struct peer *peer;
d7c0a89a 4849 uint16_t port;
d62a17ae 4850 struct servent *sp;
4851
4852 peer = peer_lookup_vty(vty, ip_str);
4853 if (!peer)
4854 return CMD_WARNING_CONFIG_FAILED;
4855
4856 if (!port_str) {
4857 sp = getservbyname("bgp", "tcp");
4858 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4859 } else {
4860 port = strtoul(port_str, NULL, 10);
4861 }
718e3744 4862
d62a17ae 4863 peer_port_set(peer, port);
718e3744 4864
d62a17ae 4865 return CMD_SUCCESS;
718e3744 4866}
4867
f418446b 4868/* Set specified peer's BGP port. */
718e3744 4869DEFUN (neighbor_port,
4870 neighbor_port_cmd,
9ccf14f7 4871 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4872 NEIGHBOR_STR
4873 NEIGHBOR_ADDR_STR
4874 "Neighbor's BGP port\n"
4875 "TCP port number\n")
4876{
d62a17ae 4877 int idx_ip = 1;
4878 int idx_number = 3;
4879 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4880 argv[idx_number]->arg);
718e3744 4881}
4882
4883DEFUN (no_neighbor_port,
4884 no_neighbor_port_cmd,
9ccf14f7 4885 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4886 NO_STR
4887 NEIGHBOR_STR
4888 NEIGHBOR_ADDR_STR
8334fd5a
DW
4889 "Neighbor's BGP port\n"
4890 "TCP port number\n")
718e3744 4891{
d62a17ae 4892 int idx_ip = 2;
4893 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4894}
4895
6b0655a2 4896
718e3744 4897/* neighbor weight. */
d62a17ae 4898static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4899 safi_t safi, const char *weight_str)
718e3744 4900{
d62a17ae 4901 int ret;
4902 struct peer *peer;
4903 unsigned long weight;
718e3744 4904
d62a17ae 4905 peer = peer_and_group_lookup_vty(vty, ip_str);
4906 if (!peer)
4907 return CMD_WARNING_CONFIG_FAILED;
718e3744 4908
d62a17ae 4909 weight = strtoul(weight_str, NULL, 10);
718e3744 4910
d62a17ae 4911 ret = peer_weight_set(peer, afi, safi, weight);
4912 return bgp_vty_return(vty, ret);
718e3744 4913}
4914
d62a17ae 4915static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4916 safi_t safi)
718e3744 4917{
d62a17ae 4918 int ret;
4919 struct peer *peer;
718e3744 4920
d62a17ae 4921 peer = peer_and_group_lookup_vty(vty, ip_str);
4922 if (!peer)
4923 return CMD_WARNING_CONFIG_FAILED;
718e3744 4924
d62a17ae 4925 ret = peer_weight_unset(peer, afi, safi);
4926 return bgp_vty_return(vty, ret);
718e3744 4927}
4928
4929DEFUN (neighbor_weight,
4930 neighbor_weight_cmd,
9ccf14f7 4931 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4932 NEIGHBOR_STR
4933 NEIGHBOR_ADDR_STR2
4934 "Set default weight for routes from this neighbor\n"
4935 "default weight\n")
4936{
d62a17ae 4937 int idx_peer = 1;
4938 int idx_number = 3;
4939 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4940 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4941}
4942
d62a17ae 4943ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4944 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4945 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4946 "Set default weight for routes from this neighbor\n"
4947 "default weight\n")
596c17ba 4948
718e3744 4949DEFUN (no_neighbor_weight,
4950 no_neighbor_weight_cmd,
9ccf14f7 4951 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4952 NO_STR
4953 NEIGHBOR_STR
4954 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4955 "Set default weight for routes from this neighbor\n"
4956 "default weight\n")
718e3744 4957{
d62a17ae 4958 int idx_peer = 2;
4959 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4960 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4961}
4962
d62a17ae 4963ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4964 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4965 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4966 "Set default weight for routes from this neighbor\n"
4967 "default weight\n")
596c17ba 4968
6b0655a2 4969
718e3744 4970/* Override capability negotiation. */
4971DEFUN (neighbor_override_capability,
4972 neighbor_override_capability_cmd,
9ccf14f7 4973 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4974 NEIGHBOR_STR
4975 NEIGHBOR_ADDR_STR2
4976 "Override capability negotiation result\n")
4977{
d62a17ae 4978 int idx_peer = 1;
4979 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4980 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4981}
4982
4983DEFUN (no_neighbor_override_capability,
4984 no_neighbor_override_capability_cmd,
9ccf14f7 4985 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4986 NO_STR
4987 NEIGHBOR_STR
4988 NEIGHBOR_ADDR_STR2
4989 "Override capability negotiation result\n")
4990{
d62a17ae 4991 int idx_peer = 2;
4992 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4993 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4994}
6b0655a2 4995
718e3744 4996DEFUN (neighbor_strict_capability,
4997 neighbor_strict_capability_cmd,
9fb964de 4998 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 4999 NEIGHBOR_STR
9fb964de 5000 NEIGHBOR_ADDR_STR2
718e3744 5001 "Strict capability negotiation match\n")
5002{
9fb964de
PM
5003 int idx_peer = 1;
5004
5005 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5006 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5007}
5008
5009DEFUN (no_neighbor_strict_capability,
5010 no_neighbor_strict_capability_cmd,
9fb964de 5011 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5012 NO_STR
5013 NEIGHBOR_STR
9fb964de 5014 NEIGHBOR_ADDR_STR2
718e3744 5015 "Strict capability negotiation match\n")
5016{
9fb964de
PM
5017 int idx_peer = 2;
5018
5019 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5020 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5021}
6b0655a2 5022
d62a17ae 5023static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5024 const char *keep_str, const char *hold_str)
718e3744 5025{
d62a17ae 5026 int ret;
5027 struct peer *peer;
d7c0a89a
QY
5028 uint32_t keepalive;
5029 uint32_t holdtime;
718e3744 5030
d62a17ae 5031 peer = peer_and_group_lookup_vty(vty, ip_str);
5032 if (!peer)
5033 return CMD_WARNING_CONFIG_FAILED;
718e3744 5034
d62a17ae 5035 keepalive = strtoul(keep_str, NULL, 10);
5036 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5037
d62a17ae 5038 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5039
d62a17ae 5040 return bgp_vty_return(vty, ret);
718e3744 5041}
6b0655a2 5042
d62a17ae 5043static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5044{
d62a17ae 5045 int ret;
5046 struct peer *peer;
718e3744 5047
d62a17ae 5048 peer = peer_and_group_lookup_vty(vty, ip_str);
5049 if (!peer)
5050 return CMD_WARNING_CONFIG_FAILED;
718e3744 5051
d62a17ae 5052 ret = peer_timers_unset(peer);
718e3744 5053
d62a17ae 5054 return bgp_vty_return(vty, ret);
718e3744 5055}
5056
5057DEFUN (neighbor_timers,
5058 neighbor_timers_cmd,
9ccf14f7 5059 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5060 NEIGHBOR_STR
5061 NEIGHBOR_ADDR_STR2
5062 "BGP per neighbor timers\n"
5063 "Keepalive interval\n"
5064 "Holdtime\n")
5065{
d62a17ae 5066 int idx_peer = 1;
5067 int idx_number = 3;
5068 int idx_number_2 = 4;
5069 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5070 argv[idx_number]->arg,
5071 argv[idx_number_2]->arg);
718e3744 5072}
5073
5074DEFUN (no_neighbor_timers,
5075 no_neighbor_timers_cmd,
9ccf14f7 5076 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5077 NO_STR
5078 NEIGHBOR_STR
5079 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5080 "BGP per neighbor timers\n"
5081 "Keepalive interval\n"
5082 "Holdtime\n")
718e3744 5083{
d62a17ae 5084 int idx_peer = 2;
5085 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5086}
6b0655a2 5087
813d4307 5088
d62a17ae 5089static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5090 const char *time_str)
718e3744 5091{
d62a17ae 5092 int ret;
5093 struct peer *peer;
d7c0a89a 5094 uint32_t connect;
718e3744 5095
d62a17ae 5096 peer = peer_and_group_lookup_vty(vty, ip_str);
5097 if (!peer)
5098 return CMD_WARNING_CONFIG_FAILED;
718e3744 5099
d62a17ae 5100 connect = strtoul(time_str, NULL, 10);
718e3744 5101
d62a17ae 5102 ret = peer_timers_connect_set(peer, connect);
718e3744 5103
d62a17ae 5104 return bgp_vty_return(vty, ret);
718e3744 5105}
5106
d62a17ae 5107static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5108{
d62a17ae 5109 int ret;
5110 struct peer *peer;
718e3744 5111
d62a17ae 5112 peer = peer_and_group_lookup_vty(vty, ip_str);
5113 if (!peer)
5114 return CMD_WARNING_CONFIG_FAILED;
718e3744 5115
d62a17ae 5116 ret = peer_timers_connect_unset(peer);
718e3744 5117
d62a17ae 5118 return bgp_vty_return(vty, ret);
718e3744 5119}
5120
5121DEFUN (neighbor_timers_connect,
5122 neighbor_timers_connect_cmd,
9ccf14f7 5123 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5124 NEIGHBOR_STR
966f821c 5125 NEIGHBOR_ADDR_STR2
718e3744 5126 "BGP per neighbor timers\n"
5127 "BGP connect timer\n"
5128 "Connect timer\n")
5129{
d62a17ae 5130 int idx_peer = 1;
5131 int idx_number = 4;
5132 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5133 argv[idx_number]->arg);
718e3744 5134}
5135
5136DEFUN (no_neighbor_timers_connect,
5137 no_neighbor_timers_connect_cmd,
9ccf14f7 5138 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5139 NO_STR
5140 NEIGHBOR_STR
966f821c 5141 NEIGHBOR_ADDR_STR2
718e3744 5142 "BGP per neighbor timers\n"
8334fd5a
DW
5143 "BGP connect timer\n"
5144 "Connect timer\n")
718e3744 5145{
d62a17ae 5146 int idx_peer = 2;
5147 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5148}
5149
6b0655a2 5150
d62a17ae 5151static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5152 const char *time_str, int set)
718e3744 5153{
d62a17ae 5154 int ret;
5155 struct peer *peer;
d7c0a89a 5156 uint32_t routeadv = 0;
718e3744 5157
d62a17ae 5158 peer = peer_and_group_lookup_vty(vty, ip_str);
5159 if (!peer)
5160 return CMD_WARNING_CONFIG_FAILED;
718e3744 5161
d62a17ae 5162 if (time_str)
5163 routeadv = strtoul(time_str, NULL, 10);
718e3744 5164
d62a17ae 5165 if (set)
5166 ret = peer_advertise_interval_set(peer, routeadv);
5167 else
5168 ret = peer_advertise_interval_unset(peer);
718e3744 5169
d62a17ae 5170 return bgp_vty_return(vty, ret);
718e3744 5171}
5172
5173DEFUN (neighbor_advertise_interval,
5174 neighbor_advertise_interval_cmd,
9ccf14f7 5175 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5176 NEIGHBOR_STR
966f821c 5177 NEIGHBOR_ADDR_STR2
718e3744 5178 "Minimum interval between sending BGP routing updates\n"
5179 "time in seconds\n")
5180{
d62a17ae 5181 int idx_peer = 1;
5182 int idx_number = 3;
5183 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5184 argv[idx_number]->arg, 1);
718e3744 5185}
5186
5187DEFUN (no_neighbor_advertise_interval,
5188 no_neighbor_advertise_interval_cmd,
9ccf14f7 5189 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5190 NO_STR
5191 NEIGHBOR_STR
966f821c 5192 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5193 "Minimum interval between sending BGP routing updates\n"
5194 "time in seconds\n")
718e3744 5195{
d62a17ae 5196 int idx_peer = 2;
5197 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5198}
5199
6b0655a2 5200
518f0eb1
DS
5201/* Time to wait before processing route-map updates */
5202DEFUN (bgp_set_route_map_delay_timer,
5203 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5204 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5205 SET_STR
5206 "BGP route-map delay timer\n"
5207 "Time in secs to wait before processing route-map changes\n"
f414725f 5208 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5209{
d62a17ae 5210 int idx_number = 3;
d7c0a89a 5211 uint32_t rmap_delay_timer;
d62a17ae 5212
5213 if (argv[idx_number]->arg) {
5214 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5215 bm->rmap_update_timer = rmap_delay_timer;
5216
5217 /* if the dynamic update handling is being disabled, and a timer
5218 * is
5219 * running, stop the timer and act as if the timer has already
5220 * fired.
5221 */
5222 if (!rmap_delay_timer && bm->t_rmap_update) {
5223 BGP_TIMER_OFF(bm->t_rmap_update);
5224 thread_execute(bm->master, bgp_route_map_update_timer,
5225 NULL, 0);
5226 }
5227 return CMD_SUCCESS;
5228 } else {
5229 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5230 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5231 }
518f0eb1
DS
5232}
5233
5234DEFUN (no_bgp_set_route_map_delay_timer,
5235 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5236 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5237 NO_STR
3a2d747c 5238 BGP_STR
518f0eb1 5239 "Default BGP route-map delay timer\n"
8334fd5a
DW
5240 "Reset to default time to wait for processing route-map changes\n"
5241 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5242{
518f0eb1 5243
d62a17ae 5244 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5245
d62a17ae 5246 return CMD_SUCCESS;
518f0eb1
DS
5247}
5248
f414725f 5249
718e3744 5250/* neighbor interface */
d62a17ae 5251static int peer_interface_vty(struct vty *vty, const char *ip_str,
5252 const char *str)
718e3744 5253{
d62a17ae 5254 struct peer *peer;
718e3744 5255
d62a17ae 5256 peer = peer_lookup_vty(vty, ip_str);
5257 if (!peer || peer->conf_if) {
5258 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5259 return CMD_WARNING_CONFIG_FAILED;
5260 }
718e3744 5261
d62a17ae 5262 if (str)
5263 peer_interface_set(peer, str);
5264 else
5265 peer_interface_unset(peer);
718e3744 5266
d62a17ae 5267 return CMD_SUCCESS;
718e3744 5268}
5269
5270DEFUN (neighbor_interface,
5271 neighbor_interface_cmd,
9ccf14f7 5272 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5273 NEIGHBOR_STR
5274 NEIGHBOR_ADDR_STR
5275 "Interface\n"
5276 "Interface name\n")
5277{
d62a17ae 5278 int idx_ip = 1;
5279 int idx_word = 3;
5280 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5281}
5282
5283DEFUN (no_neighbor_interface,
5284 no_neighbor_interface_cmd,
9ccf14f7 5285 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5286 NO_STR
5287 NEIGHBOR_STR
16cedbb0 5288 NEIGHBOR_ADDR_STR2
718e3744 5289 "Interface\n"
5290 "Interface name\n")
5291{
d62a17ae 5292 int idx_peer = 2;
5293 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5294}
6b0655a2 5295
718e3744 5296DEFUN (neighbor_distribute_list,
5297 neighbor_distribute_list_cmd,
9ccf14f7 5298 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5299 NEIGHBOR_STR
5300 NEIGHBOR_ADDR_STR2
5301 "Filter updates to/from this neighbor\n"
5302 "IP access-list number\n"
5303 "IP access-list number (expanded range)\n"
5304 "IP Access-list name\n"
5305 "Filter incoming updates\n"
5306 "Filter outgoing updates\n")
5307{
d62a17ae 5308 int idx_peer = 1;
5309 int idx_acl = 3;
5310 int direct, ret;
5311 struct peer *peer;
a8206004 5312
d62a17ae 5313 const char *pstr = argv[idx_peer]->arg;
5314 const char *acl = argv[idx_acl]->arg;
5315 const char *inout = argv[argc - 1]->text;
a8206004 5316
d62a17ae 5317 peer = peer_and_group_lookup_vty(vty, pstr);
5318 if (!peer)
5319 return CMD_WARNING_CONFIG_FAILED;
a8206004 5320
d62a17ae 5321 /* Check filter direction. */
5322 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5323 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5324 direct, acl);
a8206004 5325
d62a17ae 5326 return bgp_vty_return(vty, ret);
718e3744 5327}
5328
d62a17ae 5329ALIAS_HIDDEN(
5330 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5331 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5332 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5333 "Filter updates to/from this neighbor\n"
5334 "IP access-list number\n"
5335 "IP access-list number (expanded range)\n"
5336 "IP Access-list name\n"
5337 "Filter incoming updates\n"
5338 "Filter outgoing updates\n")
596c17ba 5339
718e3744 5340DEFUN (no_neighbor_distribute_list,
5341 no_neighbor_distribute_list_cmd,
9ccf14f7 5342 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5343 NO_STR
5344 NEIGHBOR_STR
5345 NEIGHBOR_ADDR_STR2
5346 "Filter updates to/from this neighbor\n"
5347 "IP access-list number\n"
5348 "IP access-list number (expanded range)\n"
5349 "IP Access-list name\n"
5350 "Filter incoming updates\n"
5351 "Filter outgoing updates\n")
5352{
d62a17ae 5353 int idx_peer = 2;
5354 int direct, ret;
5355 struct peer *peer;
a8206004 5356
d62a17ae 5357 const char *pstr = argv[idx_peer]->arg;
5358 const char *inout = argv[argc - 1]->text;
a8206004 5359
d62a17ae 5360 peer = peer_and_group_lookup_vty(vty, pstr);
5361 if (!peer)
5362 return CMD_WARNING_CONFIG_FAILED;
a8206004 5363
d62a17ae 5364 /* Check filter direction. */
5365 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5366 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5367 direct);
a8206004 5368
d62a17ae 5369 return bgp_vty_return(vty, ret);
718e3744 5370}
6b0655a2 5371
d62a17ae 5372ALIAS_HIDDEN(
5373 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5374 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5375 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5376 "Filter updates to/from this neighbor\n"
5377 "IP access-list number\n"
5378 "IP access-list number (expanded range)\n"
5379 "IP Access-list name\n"
5380 "Filter incoming updates\n"
5381 "Filter outgoing updates\n")
596c17ba 5382
718e3744 5383/* Set prefix list to the peer. */
d62a17ae 5384static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5385 afi_t afi, safi_t safi,
5386 const char *name_str,
5387 const char *direct_str)
718e3744 5388{
d62a17ae 5389 int ret;
d62a17ae 5390 int direct = FILTER_IN;
cf9ac8bf 5391 struct peer *peer;
718e3744 5392
d62a17ae 5393 peer = peer_and_group_lookup_vty(vty, ip_str);
5394 if (!peer)
5395 return CMD_WARNING_CONFIG_FAILED;
718e3744 5396
d62a17ae 5397 /* Check filter direction. */
5398 if (strncmp(direct_str, "i", 1) == 0)
5399 direct = FILTER_IN;
5400 else if (strncmp(direct_str, "o", 1) == 0)
5401 direct = FILTER_OUT;
718e3744 5402
d62a17ae 5403 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5404
d62a17ae 5405 return bgp_vty_return(vty, ret);
718e3744 5406}
5407
d62a17ae 5408static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5409 afi_t afi, safi_t safi,
5410 const char *direct_str)
718e3744 5411{
d62a17ae 5412 int ret;
5413 struct peer *peer;
5414 int direct = FILTER_IN;
718e3744 5415
d62a17ae 5416 peer = peer_and_group_lookup_vty(vty, ip_str);
5417 if (!peer)
5418 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5419
d62a17ae 5420 /* Check filter direction. */
5421 if (strncmp(direct_str, "i", 1) == 0)
5422 direct = FILTER_IN;
5423 else if (strncmp(direct_str, "o", 1) == 0)
5424 direct = FILTER_OUT;
718e3744 5425
d62a17ae 5426 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5427
d62a17ae 5428 return bgp_vty_return(vty, ret);
718e3744 5429}
5430
5431DEFUN (neighbor_prefix_list,
5432 neighbor_prefix_list_cmd,
9ccf14f7 5433 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5434 NEIGHBOR_STR
5435 NEIGHBOR_ADDR_STR2
5436 "Filter updates to/from this neighbor\n"
5437 "Name of a prefix list\n"
5438 "Filter incoming updates\n"
5439 "Filter outgoing updates\n")
5440{
d62a17ae 5441 int idx_peer = 1;
5442 int idx_word = 3;
5443 int idx_in_out = 4;
5444 return peer_prefix_list_set_vty(
5445 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5446 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5447}
5448
d62a17ae 5449ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5450 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5451 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5452 "Filter updates to/from this neighbor\n"
5453 "Name of a prefix list\n"
5454 "Filter incoming updates\n"
5455 "Filter outgoing updates\n")
596c17ba 5456
718e3744 5457DEFUN (no_neighbor_prefix_list,
5458 no_neighbor_prefix_list_cmd,
9ccf14f7 5459 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5460 NO_STR
5461 NEIGHBOR_STR
5462 NEIGHBOR_ADDR_STR2
5463 "Filter updates to/from this neighbor\n"
5464 "Name of a prefix list\n"
5465 "Filter incoming updates\n"
5466 "Filter outgoing updates\n")
5467{
d62a17ae 5468 int idx_peer = 2;
5469 int idx_in_out = 5;
5470 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5471 bgp_node_afi(vty), bgp_node_safi(vty),
5472 argv[idx_in_out]->arg);
718e3744 5473}
6b0655a2 5474
d62a17ae 5475ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5476 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5477 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5478 "Filter updates to/from this neighbor\n"
5479 "Name of a prefix list\n"
5480 "Filter incoming updates\n"
5481 "Filter outgoing updates\n")
596c17ba 5482
d62a17ae 5483static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5484 safi_t safi, const char *name_str,
5485 const char *direct_str)
718e3744 5486{
d62a17ae 5487 int ret;
5488 struct peer *peer;
5489 int direct = FILTER_IN;
718e3744 5490
d62a17ae 5491 peer = peer_and_group_lookup_vty(vty, ip_str);
5492 if (!peer)
5493 return CMD_WARNING_CONFIG_FAILED;
718e3744 5494
d62a17ae 5495 /* Check filter direction. */
5496 if (strncmp(direct_str, "i", 1) == 0)
5497 direct = FILTER_IN;
5498 else if (strncmp(direct_str, "o", 1) == 0)
5499 direct = FILTER_OUT;
718e3744 5500
d62a17ae 5501 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5502
d62a17ae 5503 return bgp_vty_return(vty, ret);
718e3744 5504}
5505
d62a17ae 5506static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5507 safi_t safi, const char *direct_str)
718e3744 5508{
d62a17ae 5509 int ret;
5510 struct peer *peer;
5511 int direct = FILTER_IN;
718e3744 5512
d62a17ae 5513 peer = peer_and_group_lookup_vty(vty, ip_str);
5514 if (!peer)
5515 return CMD_WARNING_CONFIG_FAILED;
718e3744 5516
d62a17ae 5517 /* Check filter direction. */
5518 if (strncmp(direct_str, "i", 1) == 0)
5519 direct = FILTER_IN;
5520 else if (strncmp(direct_str, "o", 1) == 0)
5521 direct = FILTER_OUT;
718e3744 5522
d62a17ae 5523 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5524
d62a17ae 5525 return bgp_vty_return(vty, ret);
718e3744 5526}
5527
5528DEFUN (neighbor_filter_list,
5529 neighbor_filter_list_cmd,
9ccf14f7 5530 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5531 NEIGHBOR_STR
5532 NEIGHBOR_ADDR_STR2
5533 "Establish BGP filters\n"
5534 "AS path access-list name\n"
5535 "Filter incoming routes\n"
5536 "Filter outgoing routes\n")
5537{
d62a17ae 5538 int idx_peer = 1;
5539 int idx_word = 3;
5540 int idx_in_out = 4;
5541 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5542 bgp_node_safi(vty), argv[idx_word]->arg,
5543 argv[idx_in_out]->arg);
718e3744 5544}
5545
d62a17ae 5546ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5547 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5548 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5549 "Establish BGP filters\n"
5550 "AS path access-list name\n"
5551 "Filter incoming routes\n"
5552 "Filter outgoing routes\n")
596c17ba 5553
718e3744 5554DEFUN (no_neighbor_filter_list,
5555 no_neighbor_filter_list_cmd,
9ccf14f7 5556 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5557 NO_STR
5558 NEIGHBOR_STR
5559 NEIGHBOR_ADDR_STR2
5560 "Establish BGP filters\n"
5561 "AS path access-list name\n"
5562 "Filter incoming routes\n"
5563 "Filter outgoing routes\n")
5564{
d62a17ae 5565 int idx_peer = 2;
5566 int idx_in_out = 5;
5567 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5568 bgp_node_afi(vty), bgp_node_safi(vty),
5569 argv[idx_in_out]->arg);
718e3744 5570}
6b0655a2 5571
d62a17ae 5572ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5573 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5574 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5575 "Establish BGP filters\n"
5576 "AS path access-list name\n"
5577 "Filter incoming routes\n"
5578 "Filter outgoing routes\n")
596c17ba 5579
718e3744 5580/* Set route-map to the peer. */
d62a17ae 5581static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5582 afi_t afi, safi_t safi, const char *name_str,
5583 const char *direct_str)
718e3744 5584{
d62a17ae 5585 int ret;
5586 struct peer *peer;
5587 int direct = RMAP_IN;
718e3744 5588
d62a17ae 5589 peer = peer_and_group_lookup_vty(vty, ip_str);
5590 if (!peer)
5591 return CMD_WARNING_CONFIG_FAILED;
718e3744 5592
d62a17ae 5593 /* Check filter direction. */
5594 if (strncmp(direct_str, "in", 2) == 0)
5595 direct = RMAP_IN;
5596 else if (strncmp(direct_str, "o", 1) == 0)
5597 direct = RMAP_OUT;
718e3744 5598
d62a17ae 5599 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5600
d62a17ae 5601 return bgp_vty_return(vty, ret);
718e3744 5602}
5603
d62a17ae 5604static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5605 afi_t afi, safi_t safi,
5606 const char *direct_str)
718e3744 5607{
d62a17ae 5608 int ret;
5609 struct peer *peer;
5610 int direct = RMAP_IN;
718e3744 5611
d62a17ae 5612 peer = peer_and_group_lookup_vty(vty, ip_str);
5613 if (!peer)
5614 return CMD_WARNING_CONFIG_FAILED;
718e3744 5615
d62a17ae 5616 /* Check filter direction. */
5617 if (strncmp(direct_str, "in", 2) == 0)
5618 direct = RMAP_IN;
5619 else if (strncmp(direct_str, "o", 1) == 0)
5620 direct = RMAP_OUT;
718e3744 5621
d62a17ae 5622 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5623
d62a17ae 5624 return bgp_vty_return(vty, ret);
718e3744 5625}
5626
5627DEFUN (neighbor_route_map,
5628 neighbor_route_map_cmd,
9ccf14f7 5629 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5630 NEIGHBOR_STR
5631 NEIGHBOR_ADDR_STR2
5632 "Apply route map to neighbor\n"
5633 "Name of route map\n"
5634 "Apply map to incoming routes\n"
2a3d5731 5635 "Apply map to outbound routes\n")
718e3744 5636{
d62a17ae 5637 int idx_peer = 1;
5638 int idx_word = 3;
5639 int idx_in_out = 4;
5640 return peer_route_map_set_vty(
5641 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5642 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5643}
5644
d62a17ae 5645ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5646 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5647 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5648 "Apply route map to neighbor\n"
5649 "Name of route map\n"
5650 "Apply map to incoming routes\n"
5651 "Apply map to outbound routes\n")
596c17ba 5652
718e3744 5653DEFUN (no_neighbor_route_map,
5654 no_neighbor_route_map_cmd,
9ccf14f7 5655 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5656 NO_STR
5657 NEIGHBOR_STR
5658 NEIGHBOR_ADDR_STR2
5659 "Apply route map to neighbor\n"
5660 "Name of route map\n"
5661 "Apply map to incoming routes\n"
2a3d5731 5662 "Apply map to outbound routes\n")
718e3744 5663{
d62a17ae 5664 int idx_peer = 2;
5665 int idx_in_out = 5;
5666 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5667 bgp_node_afi(vty), bgp_node_safi(vty),
5668 argv[idx_in_out]->arg);
718e3744 5669}
6b0655a2 5670
d62a17ae 5671ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5672 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5673 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5674 "Apply route map to neighbor\n"
5675 "Name of route map\n"
5676 "Apply map to incoming routes\n"
5677 "Apply map to outbound routes\n")
596c17ba 5678
718e3744 5679/* Set unsuppress-map to the peer. */
d62a17ae 5680static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5681 afi_t afi, safi_t safi,
5682 const char *name_str)
718e3744 5683{
d62a17ae 5684 int ret;
5685 struct peer *peer;
718e3744 5686
d62a17ae 5687 peer = peer_and_group_lookup_vty(vty, ip_str);
5688 if (!peer)
5689 return CMD_WARNING_CONFIG_FAILED;
718e3744 5690
d62a17ae 5691 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5692
d62a17ae 5693 return bgp_vty_return(vty, ret);
718e3744 5694}
5695
5696/* Unset route-map from the peer. */
d62a17ae 5697static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5698 afi_t afi, safi_t safi)
718e3744 5699{
d62a17ae 5700 int ret;
5701 struct peer *peer;
718e3744 5702
d62a17ae 5703 peer = peer_and_group_lookup_vty(vty, ip_str);
5704 if (!peer)
5705 return CMD_WARNING_CONFIG_FAILED;
718e3744 5706
d62a17ae 5707 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5708
d62a17ae 5709 return bgp_vty_return(vty, ret);
718e3744 5710}
5711
5712DEFUN (neighbor_unsuppress_map,
5713 neighbor_unsuppress_map_cmd,
9ccf14f7 5714 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5715 NEIGHBOR_STR
5716 NEIGHBOR_ADDR_STR2
5717 "Route-map to selectively unsuppress suppressed routes\n"
5718 "Name of route map\n")
5719{
d62a17ae 5720 int idx_peer = 1;
5721 int idx_word = 3;
5722 return peer_unsuppress_map_set_vty(
5723 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5724 argv[idx_word]->arg);
718e3744 5725}
5726
d62a17ae 5727ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5728 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5729 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5730 "Route-map to selectively unsuppress suppressed routes\n"
5731 "Name of route map\n")
596c17ba 5732
718e3744 5733DEFUN (no_neighbor_unsuppress_map,
5734 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5735 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5736 NO_STR
5737 NEIGHBOR_STR
5738 NEIGHBOR_ADDR_STR2
5739 "Route-map to selectively unsuppress suppressed routes\n"
5740 "Name of route map\n")
5741{
d62a17ae 5742 int idx_peer = 2;
5743 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5744 bgp_node_afi(vty),
5745 bgp_node_safi(vty));
718e3744 5746}
6b0655a2 5747
d62a17ae 5748ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5749 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5750 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5751 "Route-map to selectively unsuppress suppressed routes\n"
5752 "Name of route map\n")
596c17ba 5753
d62a17ae 5754static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5755 afi_t afi, safi_t safi,
5756 const char *num_str,
5757 const char *threshold_str, int warning,
5758 const char *restart_str)
718e3744 5759{
d62a17ae 5760 int ret;
5761 struct peer *peer;
d7c0a89a
QY
5762 uint32_t max;
5763 uint8_t threshold;
5764 uint16_t restart;
718e3744 5765
d62a17ae 5766 peer = peer_and_group_lookup_vty(vty, ip_str);
5767 if (!peer)
5768 return CMD_WARNING_CONFIG_FAILED;
718e3744 5769
d62a17ae 5770 max = strtoul(num_str, NULL, 10);
5771 if (threshold_str)
5772 threshold = atoi(threshold_str);
5773 else
5774 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5775
d62a17ae 5776 if (restart_str)
5777 restart = atoi(restart_str);
5778 else
5779 restart = 0;
0a486e5f 5780
d62a17ae 5781 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5782 restart);
718e3744 5783
d62a17ae 5784 return bgp_vty_return(vty, ret);
718e3744 5785}
5786
d62a17ae 5787static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5788 afi_t afi, safi_t safi)
718e3744 5789{
d62a17ae 5790 int ret;
5791 struct peer *peer;
718e3744 5792
d62a17ae 5793 peer = peer_and_group_lookup_vty(vty, ip_str);
5794 if (!peer)
5795 return CMD_WARNING_CONFIG_FAILED;
718e3744 5796
d62a17ae 5797 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5798
d62a17ae 5799 return bgp_vty_return(vty, ret);
718e3744 5800}
5801
5802/* Maximum number of prefix configuration. prefix count is different
5803 for each peer configuration. So this configuration can be set for
5804 each peer configuration. */
5805DEFUN (neighbor_maximum_prefix,
5806 neighbor_maximum_prefix_cmd,
9ccf14f7 5807 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5808 NEIGHBOR_STR
5809 NEIGHBOR_ADDR_STR2
5810 "Maximum number of prefix accept from this peer\n"
5811 "maximum no. of prefix limit\n")
5812{
d62a17ae 5813 int idx_peer = 1;
5814 int idx_number = 3;
5815 return peer_maximum_prefix_set_vty(
5816 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5817 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5818}
5819
d62a17ae 5820ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5821 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5822 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5823 "Maximum number of prefix accept from this peer\n"
5824 "maximum no. of prefix limit\n")
596c17ba 5825
e0701b79 5826DEFUN (neighbor_maximum_prefix_threshold,
5827 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5828 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5829 NEIGHBOR_STR
5830 NEIGHBOR_ADDR_STR2
5831 "Maximum number of prefix accept from this peer\n"
5832 "maximum no. of prefix limit\n"
5833 "Threshold value (%) at which to generate a warning msg\n")
5834{
d62a17ae 5835 int idx_peer = 1;
5836 int idx_number = 3;
5837 int idx_number_2 = 4;
5838 return peer_maximum_prefix_set_vty(
5839 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5840 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5841}
e0701b79 5842
d62a17ae 5843ALIAS_HIDDEN(
5844 neighbor_maximum_prefix_threshold,
5845 neighbor_maximum_prefix_threshold_hidden_cmd,
5846 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5847 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5848 "Maximum number of prefix accept from this peer\n"
5849 "maximum no. of prefix limit\n"
5850 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5851
718e3744 5852DEFUN (neighbor_maximum_prefix_warning,
5853 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5854 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5855 NEIGHBOR_STR
5856 NEIGHBOR_ADDR_STR2
5857 "Maximum number of prefix accept from this peer\n"
5858 "maximum no. of prefix limit\n"
5859 "Only give warning message when limit is exceeded\n")
5860{
d62a17ae 5861 int idx_peer = 1;
5862 int idx_number = 3;
5863 return peer_maximum_prefix_set_vty(
5864 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5865 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5866}
5867
d62a17ae 5868ALIAS_HIDDEN(
5869 neighbor_maximum_prefix_warning,
5870 neighbor_maximum_prefix_warning_hidden_cmd,
5871 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5872 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5873 "Maximum number of prefix accept from this peer\n"
5874 "maximum no. of prefix limit\n"
5875 "Only give warning message when limit is exceeded\n")
596c17ba 5876
e0701b79 5877DEFUN (neighbor_maximum_prefix_threshold_warning,
5878 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5879 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5880 NEIGHBOR_STR
5881 NEIGHBOR_ADDR_STR2
5882 "Maximum number of prefix accept from this peer\n"
5883 "maximum no. of prefix limit\n"
5884 "Threshold value (%) at which to generate a warning msg\n"
5885 "Only give warning message when limit is exceeded\n")
5886{
d62a17ae 5887 int idx_peer = 1;
5888 int idx_number = 3;
5889 int idx_number_2 = 4;
5890 return peer_maximum_prefix_set_vty(
5891 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5892 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5893}
5894
d62a17ae 5895ALIAS_HIDDEN(
5896 neighbor_maximum_prefix_threshold_warning,
5897 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5898 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5899 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5900 "Maximum number of prefix accept from this peer\n"
5901 "maximum no. of prefix limit\n"
5902 "Threshold value (%) at which to generate a warning msg\n"
5903 "Only give warning message when limit is exceeded\n")
596c17ba 5904
0a486e5f 5905DEFUN (neighbor_maximum_prefix_restart,
5906 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5907 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5908 NEIGHBOR_STR
5909 NEIGHBOR_ADDR_STR2
5910 "Maximum number of prefix accept from this peer\n"
5911 "maximum no. of prefix limit\n"
5912 "Restart bgp connection after limit is exceeded\n"
efd7904e 5913 "Restart interval in minutes\n")
0a486e5f 5914{
d62a17ae 5915 int idx_peer = 1;
5916 int idx_number = 3;
5917 int idx_number_2 = 5;
5918 return peer_maximum_prefix_set_vty(
5919 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5920 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5921}
5922
d62a17ae 5923ALIAS_HIDDEN(
5924 neighbor_maximum_prefix_restart,
5925 neighbor_maximum_prefix_restart_hidden_cmd,
5926 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5927 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5928 "Maximum number of prefix accept from this peer\n"
5929 "maximum no. of prefix limit\n"
5930 "Restart bgp connection after limit is exceeded\n"
efd7904e 5931 "Restart interval in minutes\n")
596c17ba 5932
0a486e5f 5933DEFUN (neighbor_maximum_prefix_threshold_restart,
5934 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5935 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5936 NEIGHBOR_STR
5937 NEIGHBOR_ADDR_STR2
16cedbb0 5938 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5939 "maximum no. of prefix limit\n"
5940 "Threshold value (%) at which to generate a warning msg\n"
5941 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5942 "Restart interval in minutes\n")
0a486e5f 5943{
d62a17ae 5944 int idx_peer = 1;
5945 int idx_number = 3;
5946 int idx_number_2 = 4;
5947 int idx_number_3 = 6;
5948 return peer_maximum_prefix_set_vty(
5949 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5950 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5951 argv[idx_number_3]->arg);
5952}
5953
5954ALIAS_HIDDEN(
5955 neighbor_maximum_prefix_threshold_restart,
5956 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5957 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5958 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5959 "Maximum number of prefixes to accept from this peer\n"
5960 "maximum no. of prefix limit\n"
5961 "Threshold value (%) at which to generate a warning msg\n"
5962 "Restart bgp connection after limit is exceeded\n"
5963 "Restart interval in minutes\n")
596c17ba 5964
718e3744 5965DEFUN (no_neighbor_maximum_prefix,
5966 no_neighbor_maximum_prefix_cmd,
d04c479d 5967 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5968 NO_STR
5969 NEIGHBOR_STR
5970 NEIGHBOR_ADDR_STR2
16cedbb0 5971 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5972 "maximum no. of prefix limit\n"
5973 "Threshold value (%) at which to generate a warning msg\n"
5974 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5975 "Restart interval in minutes\n"
31500417 5976 "Only give warning message when limit is exceeded\n")
718e3744 5977{
d62a17ae 5978 int idx_peer = 2;
5979 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5980 bgp_node_afi(vty),
5981 bgp_node_safi(vty));
718e3744 5982}
e52702f2 5983
d62a17ae 5984ALIAS_HIDDEN(
5985 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5986 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5987 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5988 "Maximum number of prefixes to accept from this peer\n"
5989 "maximum no. of prefix limit\n"
5990 "Threshold value (%) at which to generate a warning msg\n"
5991 "Restart bgp connection after limit is exceeded\n"
5992 "Restart interval in minutes\n"
5993 "Only give warning message when limit is exceeded\n")
596c17ba 5994
718e3744 5995
718e3744 5996/* "neighbor allowas-in" */
5997DEFUN (neighbor_allowas_in,
5998 neighbor_allowas_in_cmd,
fd8503f5 5999 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6000 NEIGHBOR_STR
6001 NEIGHBOR_ADDR_STR2
31500417 6002 "Accept as-path with my AS present in it\n"
fd8503f5
QY
6003 "Number of occurances of AS number\n"
6004 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6005{
d62a17ae 6006 int idx_peer = 1;
6007 int idx_number_origin = 3;
6008 int ret;
6009 int origin = 0;
6010 struct peer *peer;
6011 int allow_num = 0;
6012
6013 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6014 if (!peer)
6015 return CMD_WARNING_CONFIG_FAILED;
6016
6017 if (argc <= idx_number_origin)
6018 allow_num = 3;
6019 else {
6020 if (argv[idx_number_origin]->type == WORD_TKN)
6021 origin = 1;
6022 else
6023 allow_num = atoi(argv[idx_number_origin]->arg);
6024 }
6025
6026 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6027 allow_num, origin);
6028
6029 return bgp_vty_return(vty, ret);
6030}
6031
6032ALIAS_HIDDEN(
6033 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6034 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6035 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6036 "Accept as-path with my AS present in it\n"
6037 "Number of occurances of AS number\n"
6038 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6039
718e3744 6040DEFUN (no_neighbor_allowas_in,
6041 no_neighbor_allowas_in_cmd,
fd8503f5 6042 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6043 NO_STR
6044 NEIGHBOR_STR
6045 NEIGHBOR_ADDR_STR2
8334fd5a 6046 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
6047 "Number of occurances of AS number\n"
6048 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6049{
d62a17ae 6050 int idx_peer = 2;
6051 int ret;
6052 struct peer *peer;
718e3744 6053
d62a17ae 6054 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6055 if (!peer)
6056 return CMD_WARNING_CONFIG_FAILED;
718e3744 6057
d62a17ae 6058 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6059 bgp_node_safi(vty));
718e3744 6060
d62a17ae 6061 return bgp_vty_return(vty, ret);
718e3744 6062}
6b0655a2 6063
d62a17ae 6064ALIAS_HIDDEN(
6065 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6066 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6067 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6068 "allow local ASN appears in aspath attribute\n"
6069 "Number of occurances of AS number\n"
6070 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6071
fa411a21
NH
6072DEFUN (neighbor_ttl_security,
6073 neighbor_ttl_security_cmd,
7ebe625c 6074 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6075 NEIGHBOR_STR
7ebe625c 6076 NEIGHBOR_ADDR_STR2
16cedbb0 6077 "BGP ttl-security parameters\n"
d7fa34c1
QY
6078 "Specify the maximum number of hops to the BGP peer\n"
6079 "Number of hops to BGP peer\n")
fa411a21 6080{
d62a17ae 6081 int idx_peer = 1;
6082 int idx_number = 4;
6083 struct peer *peer;
6084 int gtsm_hops;
6085
6086 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6087 if (!peer)
6088 return CMD_WARNING_CONFIG_FAILED;
6089
6090 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6091
7ebe625c
QY
6092 /*
6093 * If 'neighbor swpX', then this is for directly connected peers,
6094 * we should not accept a ttl-security hops value greater than 1.
6095 */
6096 if (peer->conf_if && (gtsm_hops > 1)) {
6097 vty_out(vty,
6098 "%s is directly connected peer, hops cannot exceed 1\n",
6099 argv[idx_peer]->arg);
6100 return CMD_WARNING_CONFIG_FAILED;
6101 }
6102
d62a17ae 6103 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6104}
6105
6106DEFUN (no_neighbor_ttl_security,
6107 no_neighbor_ttl_security_cmd,
7ebe625c 6108 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6109 NO_STR
6110 NEIGHBOR_STR
7ebe625c 6111 NEIGHBOR_ADDR_STR2
16cedbb0 6112 "BGP ttl-security parameters\n"
3a2d747c
QY
6113 "Specify the maximum number of hops to the BGP peer\n"
6114 "Number of hops to BGP peer\n")
fa411a21 6115{
d62a17ae 6116 int idx_peer = 2;
6117 struct peer *peer;
fa411a21 6118
d62a17ae 6119 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6120 if (!peer)
6121 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6122
d62a17ae 6123 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6124}
6b0655a2 6125
adbac85e
DW
6126DEFUN (neighbor_addpath_tx_all_paths,
6127 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6128 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6129 NEIGHBOR_STR
6130 NEIGHBOR_ADDR_STR2
6131 "Use addpath to advertise all paths to a neighbor\n")
6132{
d62a17ae 6133 int idx_peer = 1;
6134 struct peer *peer;
adbac85e 6135
d62a17ae 6136 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6137 if (!peer)
6138 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6139
d62a17ae 6140 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6141 bgp_node_safi(vty),
6142 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6143}
6144
d62a17ae 6145ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6146 neighbor_addpath_tx_all_paths_hidden_cmd,
6147 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6148 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6149 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6150
adbac85e
DW
6151DEFUN (no_neighbor_addpath_tx_all_paths,
6152 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6153 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6154 NO_STR
6155 NEIGHBOR_STR
6156 NEIGHBOR_ADDR_STR2
6157 "Use addpath to advertise all paths to a neighbor\n")
6158{
d62a17ae 6159 int idx_peer = 2;
6160 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6161 bgp_node_afi(vty), bgp_node_safi(vty),
6162 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6163}
6164
d62a17ae 6165ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6166 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6167 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6168 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6169 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6170
06370dac
DW
6171DEFUN (neighbor_addpath_tx_bestpath_per_as,
6172 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6173 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6174 NEIGHBOR_STR
6175 NEIGHBOR_ADDR_STR2
6176 "Use addpath to advertise the bestpath per each neighboring AS\n")
6177{
d62a17ae 6178 int idx_peer = 1;
6179 struct peer *peer;
06370dac 6180
d62a17ae 6181 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6182 if (!peer)
6183 return CMD_WARNING_CONFIG_FAILED;
06370dac 6184
d62a17ae 6185 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6186 bgp_node_safi(vty),
6187 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6188}
6189
d62a17ae 6190ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6191 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6192 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6193 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6194 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6195
06370dac
DW
6196DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6197 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6198 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6199 NO_STR
6200 NEIGHBOR_STR
6201 NEIGHBOR_ADDR_STR2
6202 "Use addpath to advertise the bestpath per each neighboring AS\n")
6203{
d62a17ae 6204 int idx_peer = 2;
6205 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6206 bgp_node_afi(vty), bgp_node_safi(vty),
6207 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6208}
6209
d62a17ae 6210ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6211 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6212 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6213 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6214 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6215
b9c7bc5a
PZ
6216static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6217 struct ecommunity **list)
ddb5b488 6218{
b9c7bc5a
PZ
6219 struct ecommunity *ecom = NULL;
6220 struct ecommunity *ecomadd;
ddb5b488 6221
b9c7bc5a 6222 for (; argc; --argc, ++argv) {
ddb5b488 6223
b9c7bc5a
PZ
6224 ecomadd = ecommunity_str2com(argv[0]->arg,
6225 ECOMMUNITY_ROUTE_TARGET, 0);
6226 if (!ecomadd) {
6227 vty_out(vty, "Malformed community-list value\n");
6228 if (ecom)
6229 ecommunity_free(&ecom);
6230 return CMD_WARNING_CONFIG_FAILED;
6231 }
ddb5b488 6232
b9c7bc5a
PZ
6233 if (ecom) {
6234 ecommunity_merge(ecom, ecomadd);
6235 ecommunity_free(&ecomadd);
6236 } else {
6237 ecom = ecomadd;
6238 }
6239 }
6240
6241 if (*list) {
6242 ecommunity_free(&*list);
ddb5b488 6243 }
b9c7bc5a
PZ
6244 *list = ecom;
6245
6246 return CMD_SUCCESS;
ddb5b488
PZ
6247}
6248
0ca70ba5
DS
6249/*
6250 * v2vimport is true if we are handling a `import vrf ...` command
6251 */
6252static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6253{
0ca70ba5
DS
6254 afi_t afi;
6255
ddb5b488 6256 switch (vty->node) {
b9c7bc5a 6257 case BGP_IPV4_NODE:
0ca70ba5
DS
6258 afi = AFI_IP;
6259 break;
b9c7bc5a 6260 case BGP_IPV6_NODE:
0ca70ba5
DS
6261 afi = AFI_IP6;
6262 break;
ddb5b488
PZ
6263 default:
6264 vty_out(vty,
b9c7bc5a 6265 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6266 return AFI_MAX;
ddb5b488 6267 }
69b07479 6268
0ca70ba5
DS
6269 if (!v2vimport) {
6270 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6271 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6272 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6273 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6274 vty_out(vty,
6275 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6276 return AFI_MAX;
6277 }
6278 } else {
6279 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6280 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6281 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6282 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6283 vty_out(vty,
6284 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6285 return AFI_MAX;
6286 }
6287 }
6288 return afi;
ddb5b488
PZ
6289}
6290
b9c7bc5a
PZ
6291DEFPY (af_rd_vpn_export,
6292 af_rd_vpn_export_cmd,
6293 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6294 NO_STR
ddb5b488 6295 "Specify route distinguisher\n"
b9c7bc5a
PZ
6296 "Between current address-family and vpn\n"
6297 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6298 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6299{
6300 VTY_DECLVAR_CONTEXT(bgp, bgp);
6301 struct prefix_rd prd;
6302 int ret;
ddb5b488 6303 afi_t afi;
b9c7bc5a
PZ
6304 int idx = 0;
6305 int yes = 1;
ddb5b488 6306
b9c7bc5a 6307 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6308 yes = 0;
b9c7bc5a
PZ
6309
6310 if (yes) {
6311 ret = str2prefix_rd(rd_str, &prd);
6312 if (!ret) {
6313 vty_out(vty, "%% Malformed rd\n");
6314 return CMD_WARNING_CONFIG_FAILED;
6315 }
ddb5b488
PZ
6316 }
6317
0ca70ba5 6318 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6319 if (afi == AFI_MAX)
6320 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6321
69b07479
DS
6322 /*
6323 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6324 */
6325 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6326 bgp_get_default(), bgp);
ddb5b488 6327
69b07479
DS
6328 if (yes) {
6329 bgp->vpn_policy[afi].tovpn_rd = prd;
6330 SET_FLAG(bgp->vpn_policy[afi].flags,
6331 BGP_VPN_POLICY_TOVPN_RD_SET);
6332 } else {
6333 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6334 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6335 }
6336
69b07479
DS
6337 /* post-change: re-export vpn routes */
6338 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6339 bgp_get_default(), bgp);
6340
ddb5b488
PZ
6341 return CMD_SUCCESS;
6342}
6343
b9c7bc5a
PZ
6344ALIAS (af_rd_vpn_export,
6345 af_no_rd_vpn_export_cmd,
6346 "no rd vpn export",
ddb5b488 6347 NO_STR
b9c7bc5a
PZ
6348 "Specify route distinguisher\n"
6349 "Between current address-family and vpn\n"
6350 "For routes leaked from current address-family to vpn\n")
ddb5b488 6351
b9c7bc5a
PZ
6352DEFPY (af_label_vpn_export,
6353 af_label_vpn_export_cmd,
e70e9f8e 6354 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6355 NO_STR
ddb5b488 6356 "label value for VRF\n"
b9c7bc5a
PZ
6357 "Between current address-family and vpn\n"
6358 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6359 "Label Value <0-1048575>\n"
6360 "Automatically assign a label\n")
ddb5b488
PZ
6361{
6362 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6363 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6364 afi_t afi;
b9c7bc5a
PZ
6365 int idx = 0;
6366 int yes = 1;
6367
6368 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6369 yes = 0;
ddb5b488 6370
21a16cc2
PZ
6371 /* If "no ...", squash trailing parameter */
6372 if (!yes)
6373 label_auto = NULL;
6374
e70e9f8e
PZ
6375 if (yes) {
6376 if (!label_auto)
6377 label = label_val; /* parser should force unsigned */
6378 }
ddb5b488 6379
0ca70ba5 6380 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6381 if (afi == AFI_MAX)
6382 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6383
e70e9f8e 6384
69b07479
DS
6385 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6386 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6387 /* no change */
6388 return CMD_SUCCESS;
e70e9f8e 6389
69b07479
DS
6390 /*
6391 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6392 */
6393 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6394 bgp_get_default(), bgp);
6395
6396 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6397 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6398
6399 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6400
6401 /*
6402 * label has previously been automatically
6403 * assigned by labelpool: release it
6404 *
6405 * NB if tovpn_label == MPLS_LABEL_NONE it
6406 * means the automatic assignment is in flight
6407 * and therefore the labelpool callback must
6408 * detect that the auto label is not needed.
6409 */
6410
6411 bgp_lp_release(LP_TYPE_VRF,
6412 &bgp->vpn_policy[afi],
6413 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6414 }
69b07479
DS
6415 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6416 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6417 }
ddb5b488 6418
69b07479
DS
6419 bgp->vpn_policy[afi].tovpn_label = label;
6420 if (label_auto) {
6421 SET_FLAG(bgp->vpn_policy[afi].flags,
6422 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6423 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6424 vpn_leak_label_callback);
ddb5b488
PZ
6425 }
6426
69b07479
DS
6427 /* post-change: re-export vpn routes */
6428 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6429 bgp_get_default(), bgp);
6430
ddb5b488
PZ
6431 return CMD_SUCCESS;
6432}
6433
b9c7bc5a
PZ
6434ALIAS (af_label_vpn_export,
6435 af_no_label_vpn_export_cmd,
6436 "no label vpn export",
6437 NO_STR
6438 "label value for VRF\n"
6439 "Between current address-family and vpn\n"
6440 "For routes leaked from current address-family to vpn\n")
ddb5b488 6441
b9c7bc5a
PZ
6442DEFPY (af_nexthop_vpn_export,
6443 af_nexthop_vpn_export_cmd,
6444 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6445 NO_STR
ddb5b488 6446 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6447 "Between current address-family and vpn\n"
6448 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6449 "IPv4 prefix\n"
6450 "IPv6 prefix\n")
6451{
6452 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6453 afi_t afi;
ddb5b488 6454 struct prefix p;
b9c7bc5a
PZ
6455 int idx = 0;
6456 int yes = 1;
ddb5b488 6457
b9c7bc5a 6458 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6459 yes = 0;
b9c7bc5a
PZ
6460
6461 if (yes) {
6462 if (!sockunion2hostprefix(nexthop_str, &p))
6463 return CMD_WARNING_CONFIG_FAILED;
6464 }
ddb5b488 6465
0ca70ba5 6466 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6467 if (afi == AFI_MAX)
6468 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6469
69b07479
DS
6470 /*
6471 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6472 */
6473 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6474 bgp_get_default(), bgp);
ddb5b488 6475
69b07479
DS
6476 if (yes) {
6477 bgp->vpn_policy[afi].tovpn_nexthop = p;
6478 SET_FLAG(bgp->vpn_policy[afi].flags,
6479 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6480 } else {
6481 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6482 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6483 }
6484
69b07479
DS
6485 /* post-change: re-export vpn routes */
6486 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6487 bgp_get_default(), bgp);
6488
ddb5b488
PZ
6489 return CMD_SUCCESS;
6490}
6491
b9c7bc5a
PZ
6492ALIAS (af_nexthop_vpn_export,
6493 af_no_nexthop_vpn_export_cmd,
6494 "no nexthop vpn export",
ddb5b488 6495 NO_STR
b9c7bc5a
PZ
6496 "Specify next hop to use for VRF advertised prefixes\n"
6497 "Between current address-family and vpn\n"
6498 "For routes leaked from current address-family to vpn\n")
ddb5b488 6499
b9c7bc5a 6500static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6501{
b9c7bc5a
PZ
6502 if (!strcmp(dstr, "import")) {
6503 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6504 } else if (!strcmp(dstr, "export")) {
6505 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6506 } else if (!strcmp(dstr, "both")) {
6507 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6508 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6509 } else {
6510 vty_out(vty, "%% direction parse error\n");
6511 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6512 }
ddb5b488
PZ
6513 return CMD_SUCCESS;
6514}
6515
b9c7bc5a
PZ
6516DEFPY (af_rt_vpn_imexport,
6517 af_rt_vpn_imexport_cmd,
6518 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6519 NO_STR
6520 "Specify route target list\n"
ddb5b488 6521 "Specify route target list\n"
b9c7bc5a
PZ
6522 "Between current address-family and vpn\n"
6523 "For routes leaked from vpn to current address-family: match any\n"
6524 "For routes leaked from current address-family to vpn: set\n"
6525 "both import: match any and export: set\n"
ddb5b488
PZ
6526 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6527{
6528 VTY_DECLVAR_CONTEXT(bgp, bgp);
6529 int ret;
6530 struct ecommunity *ecom = NULL;
6531 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6532 vpn_policy_direction_t dir;
6533 afi_t afi;
6534 int idx = 0;
b9c7bc5a 6535 int yes = 1;
ddb5b488 6536
b9c7bc5a 6537 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6538 yes = 0;
b9c7bc5a 6539
0ca70ba5 6540 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6541 if (afi == AFI_MAX)
6542 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6543
b9c7bc5a 6544 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6545 if (ret != CMD_SUCCESS)
6546 return ret;
6547
b9c7bc5a
PZ
6548 if (yes) {
6549 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6550 vty_out(vty, "%% Missing RTLIST\n");
6551 return CMD_WARNING_CONFIG_FAILED;
6552 }
6553 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6554 if (ret != CMD_SUCCESS) {
6555 return ret;
6556 }
ddb5b488
PZ
6557 }
6558
69b07479
DS
6559 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6560 if (!dodir[dir])
ddb5b488 6561 continue;
ddb5b488 6562
69b07479 6563 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6564
69b07479
DS
6565 if (yes) {
6566 if (bgp->vpn_policy[afi].rtlist[dir])
6567 ecommunity_free(
6568 &bgp->vpn_policy[afi].rtlist[dir]);
6569 bgp->vpn_policy[afi].rtlist[dir] =
6570 ecommunity_dup(ecom);
6571 } else {
6572 if (bgp->vpn_policy[afi].rtlist[dir])
6573 ecommunity_free(
6574 &bgp->vpn_policy[afi].rtlist[dir]);
6575 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6576 }
69b07479
DS
6577
6578 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6579 }
69b07479 6580
d555f3e9
PZ
6581 if (ecom)
6582 ecommunity_free(&ecom);
ddb5b488
PZ
6583
6584 return CMD_SUCCESS;
6585}
6586
b9c7bc5a
PZ
6587ALIAS (af_rt_vpn_imexport,
6588 af_no_rt_vpn_imexport_cmd,
6589 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6590 NO_STR
6591 "Specify route target list\n"
b9c7bc5a
PZ
6592 "Specify route target list\n"
6593 "Between current address-family and vpn\n"
6594 "For routes leaked from vpn to current address-family\n"
6595 "For routes leaked from current address-family to vpn\n"
6596 "both import and export\n")
6597
6598DEFPY (af_route_map_vpn_imexport,
6599 af_route_map_vpn_imexport_cmd,
6600/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6601 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6602 NO_STR
ddb5b488 6603 "Specify route map\n"
b9c7bc5a
PZ
6604 "Between current address-family and vpn\n"
6605 "For routes leaked from vpn to current address-family\n"
6606 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6607 "name of route-map\n")
6608{
6609 VTY_DECLVAR_CONTEXT(bgp, bgp);
6610 int ret;
6611 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6612 vpn_policy_direction_t dir;
6613 afi_t afi;
ddb5b488 6614 int idx = 0;
b9c7bc5a 6615 int yes = 1;
ddb5b488 6616
b9c7bc5a 6617 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6618 yes = 0;
b9c7bc5a 6619
0ca70ba5 6620 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6621 if (afi == AFI_MAX)
6622 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6623
b9c7bc5a 6624 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6625 if (ret != CMD_SUCCESS)
6626 return ret;
6627
69b07479
DS
6628 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6629 if (!dodir[dir])
ddb5b488 6630 continue;
ddb5b488 6631
69b07479 6632 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6633
69b07479
DS
6634 if (yes) {
6635 if (bgp->vpn_policy[afi].rmap_name[dir])
6636 XFREE(MTYPE_ROUTE_MAP_NAME,
6637 bgp->vpn_policy[afi].rmap_name[dir]);
6638 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6639 MTYPE_ROUTE_MAP_NAME, rmap_str);
6640 bgp->vpn_policy[afi].rmap[dir] =
6641 route_map_lookup_by_name(rmap_str);
6642 if (!bgp->vpn_policy[afi].rmap[dir])
6643 return CMD_SUCCESS;
6644 } else {
6645 if (bgp->vpn_policy[afi].rmap_name[dir])
6646 XFREE(MTYPE_ROUTE_MAP_NAME,
6647 bgp->vpn_policy[afi].rmap_name[dir]);
6648 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6649 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6650 }
69b07479
DS
6651
6652 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6653 }
6654
6655 return CMD_SUCCESS;
6656}
6657
b9c7bc5a
PZ
6658ALIAS (af_route_map_vpn_imexport,
6659 af_no_route_map_vpn_imexport_cmd,
6660 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6661 NO_STR
6662 "Specify route map\n"
b9c7bc5a
PZ
6663 "Between current address-family and vpn\n"
6664 "For routes leaked from vpn to current address-family\n"
6665 "For routes leaked from current address-family to vpn\n")
6666
bb4f6190
DS
6667DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6668 "[no] import vrf route-map RMAP$rmap_str",
6669 NO_STR
6670 "Import routes from another VRF\n"
6671 "Vrf routes being filtered\n"
6672 "Specify route map\n"
6673 "name of route-map\n")
6674{
6675 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6676 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6677 afi_t afi;
6678 int idx = 0;
6679 int yes = 1;
6680 struct bgp *bgp_default;
6681
6682 if (argv_find(argv, argc, "no", &idx))
6683 yes = 0;
6684
0ca70ba5 6685 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6686 if (afi == AFI_MAX)
6687 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6688
6689 bgp_default = bgp_get_default();
6690 if (!bgp_default) {
6691 int32_t ret;
6692 as_t as = bgp->as;
6693
6694 /* Auto-create assuming the same AS */
6695 ret = bgp_get(&bgp_default, &as, NULL,
6696 BGP_INSTANCE_TYPE_DEFAULT);
6697
6698 if (ret) {
6699 vty_out(vty,
6700 "VRF default is not configured as a bgp instance\n");
6701 return CMD_WARNING;
6702 }
6703 }
6704
69b07479 6705 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6706
69b07479
DS
6707 if (yes) {
6708 if (bgp->vpn_policy[afi].rmap_name[dir])
6709 XFREE(MTYPE_ROUTE_MAP_NAME,
6710 bgp->vpn_policy[afi].rmap_name[dir]);
6711 bgp->vpn_policy[afi].rmap_name[dir] =
6712 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6713 bgp->vpn_policy[afi].rmap[dir] =
6714 route_map_lookup_by_name(rmap_str);
6715 if (!bgp->vpn_policy[afi].rmap[dir])
6716 return CMD_SUCCESS;
6717 } else {
6718 if (bgp->vpn_policy[afi].rmap_name[dir])
6719 XFREE(MTYPE_ROUTE_MAP_NAME,
6720 bgp->vpn_policy[afi].rmap_name[dir]);
6721 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6722 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6723 }
6724
69b07479
DS
6725 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6726
bb4f6190
DS
6727 return CMD_SUCCESS;
6728}
6729
6730ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6731 "no import vrf route-map",
6732 NO_STR
6733 "Import routes from another VRF\n"
6734 "Vrf routes being filtered\n"
6735 "Specify route map\n")
6736
12a844a5
DS
6737DEFPY (bgp_imexport_vrf,
6738 bgp_imexport_vrf_cmd,
6739 "[no] import vrf NAME$import_name",
6740 NO_STR
6741 "Import routes from another VRF\n"
6742 "VRF to import from\n"
6743 "The name of the VRF\n")
6744{
6745 VTY_DECLVAR_CONTEXT(bgp, bgp);
6746 struct listnode *node;
79ef8664
DS
6747 struct bgp *vrf_bgp, *bgp_default;
6748 int32_t ret = 0;
6749 as_t as = bgp->as;
12a844a5
DS
6750 bool remove = false;
6751 int32_t idx = 0;
6752 char *vname;
a8dadcf6 6753 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6754 safi_t safi;
6755 afi_t afi;
6756
867f0cca 6757 if (import_name == NULL) {
6758 vty_out(vty, "%% Missing import name\n");
6759 return CMD_WARNING;
6760 }
6761
12a844a5
DS
6762 if (argv_find(argv, argc, "no", &idx))
6763 remove = true;
6764
0ca70ba5
DS
6765 afi = vpn_policy_getafi(vty, bgp, true);
6766 if (afi == AFI_MAX)
6767 return CMD_WARNING_CONFIG_FAILED;
6768
12a844a5
DS
6769 safi = bgp_node_safi(vty);
6770
25679caa
DS
6771 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6772 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6773 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6774 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6775 remove ? "unimport" : "import", import_name);
6776 return CMD_WARNING;
6777 }
6778
79ef8664
DS
6779 bgp_default = bgp_get_default();
6780 if (!bgp_default) {
6781 /* Auto-create assuming the same AS */
6782 ret = bgp_get(&bgp_default, &as, NULL,
6783 BGP_INSTANCE_TYPE_DEFAULT);
6784
6785 if (ret) {
6786 vty_out(vty,
6787 "VRF default is not configured as a bgp instance\n");
6788 return CMD_WARNING;
6789 }
6790 }
6791
12a844a5
DS
6792 vrf_bgp = bgp_lookup_by_name(import_name);
6793 if (!vrf_bgp) {
79ef8664
DS
6794 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6795 vrf_bgp = bgp_default;
6796 else
0fb8d6e6
DS
6797 /* Auto-create assuming the same AS */
6798 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6799
6e2c7fe6 6800 if (ret) {
020a3f60
DS
6801 vty_out(vty,
6802 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6803 import_name);
6804 return CMD_WARNING;
6805 }
12a844a5
DS
6806 }
6807
12a844a5 6808 if (remove) {
44338987 6809 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6810 } else {
44338987 6811 /* Already importing from "import_vrf"? */
12a844a5
DS
6812 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6813 vname)) {
6814 if (strcmp(vname, import_name) == 0)
6815 return CMD_WARNING;
6816 }
6817
44338987 6818 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6819 }
6820
6821 return CMD_SUCCESS;
6822}
6823
b9c7bc5a
PZ
6824/* This command is valid only in a bgp vrf instance or the default instance */
6825DEFPY (bgp_imexport_vpn,
6826 bgp_imexport_vpn_cmd,
6827 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6828 NO_STR
6829 "Import routes to this address-family\n"
6830 "Export routes from this address-family\n"
6831 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6832{
6833 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6834 int previous_state;
ddb5b488 6835 afi_t afi;
b9c7bc5a 6836 safi_t safi;
ddb5b488 6837 int idx = 0;
b9c7bc5a
PZ
6838 int yes = 1;
6839 int flag;
6840 vpn_policy_direction_t dir;
ddb5b488 6841
b9c7bc5a 6842 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6843 yes = 0;
ddb5b488 6844
b9c7bc5a
PZ
6845 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6846 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6847
b9c7bc5a
PZ
6848 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6849 return CMD_WARNING_CONFIG_FAILED;
6850 }
ddb5b488 6851
b9c7bc5a
PZ
6852 afi = bgp_node_afi(vty);
6853 safi = bgp_node_safi(vty);
6854 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6855 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6856 return CMD_WARNING_CONFIG_FAILED;
6857 }
ddb5b488 6858
b9c7bc5a
PZ
6859 if (!strcmp(direction_str, "import")) {
6860 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6861 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6862 } else if (!strcmp(direction_str, "export")) {
6863 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6864 dir = BGP_VPN_POLICY_DIR_TOVPN;
6865 } else {
6866 vty_out(vty, "%% unknown direction %s\n", direction_str);
6867 return CMD_WARNING_CONFIG_FAILED;
6868 }
6869
6870 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 6871
b9c7bc5a
PZ
6872 if (yes) {
6873 SET_FLAG(bgp->af_flags[afi][safi], flag);
6874 if (!previous_state) {
6875 /* trigger export current vrf */
ddb5b488
PZ
6876 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6877 }
b9c7bc5a
PZ
6878 } else {
6879 if (previous_state) {
6880 /* trigger un-export current vrf */
6881 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6882 }
6883 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
6884 }
6885
6886 return CMD_SUCCESS;
6887}
6888
301ad80a
PG
6889DEFPY (af_routetarget_import,
6890 af_routetarget_import_cmd,
6891 "[no] <rt|route-target> redirect import RTLIST...",
6892 NO_STR
6893 "Specify route target list\n"
6894 "Specify route target list\n"
6895 "Flow-spec redirect type route target\n"
6896 "Import routes to this address-family\n"
6897 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6898{
6899 VTY_DECLVAR_CONTEXT(bgp, bgp);
6900 int ret;
6901 struct ecommunity *ecom = NULL;
301ad80a
PG
6902 afi_t afi;
6903 int idx = 0;
6904 int yes = 1;
6905
6906 if (argv_find(argv, argc, "no", &idx))
6907 yes = 0;
6908
0ca70ba5 6909 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6910 if (afi == AFI_MAX)
6911 return CMD_WARNING_CONFIG_FAILED;
6912
301ad80a
PG
6913 if (yes) {
6914 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6915 vty_out(vty, "%% Missing RTLIST\n");
6916 return CMD_WARNING_CONFIG_FAILED;
6917 }
6918 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6919 if (ret != CMD_SUCCESS)
6920 return ret;
6921 }
69b07479
DS
6922
6923 if (yes) {
6924 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6925 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6926 .import_redirect_rtlist);
69b07479
DS
6927 bgp->vpn_policy[afi].import_redirect_rtlist =
6928 ecommunity_dup(ecom);
6929 } else {
6930 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6931 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6932 .import_redirect_rtlist);
69b07479 6933 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 6934 }
69b07479 6935
301ad80a
PG
6936 if (ecom)
6937 ecommunity_free(&ecom);
6938
6939 return CMD_SUCCESS;
6940}
6941
505e5056 6942DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 6943 address_family_ipv4_safi_cmd,
6944 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6945 "Enter Address Family command mode\n"
6946 "Address Family\n"
6947 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6948{
f51bae9c 6949
d62a17ae 6950 if (argc == 3) {
2131d5cf 6951 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6952 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6953 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6954 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6955 && safi != SAFI_EVPN) {
31947174
MK
6956 vty_out(vty,
6957 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6958 return CMD_WARNING_CONFIG_FAILED;
6959 }
d62a17ae 6960 vty->node = bgp_node_type(AFI_IP, safi);
6961 } else
6962 vty->node = BGP_IPV4_NODE;
718e3744 6963
d62a17ae 6964 return CMD_SUCCESS;
718e3744 6965}
6966
505e5056 6967DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 6968 address_family_ipv6_safi_cmd,
6969 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6970 "Enter Address Family command mode\n"
6971 "Address Family\n"
6972 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6973{
d62a17ae 6974 if (argc == 3) {
2131d5cf 6975 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6976 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6977 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6978 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6979 && safi != SAFI_EVPN) {
31947174
MK
6980 vty_out(vty,
6981 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6982 return CMD_WARNING_CONFIG_FAILED;
6983 }
d62a17ae 6984 vty->node = bgp_node_type(AFI_IP6, safi);
6985 } else
6986 vty->node = BGP_IPV6_NODE;
25ffbdc1 6987
d62a17ae 6988 return CMD_SUCCESS;
25ffbdc1 6989}
718e3744 6990
d6902373 6991#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6992DEFUN_NOSH (address_family_vpnv4,
718e3744 6993 address_family_vpnv4_cmd,
8334fd5a 6994 "address-family vpnv4 [unicast]",
718e3744 6995 "Enter Address Family command mode\n"
8c3deaae 6996 "Address Family\n"
3a2d747c 6997 "Address Family modifier\n")
718e3744 6998{
d62a17ae 6999 vty->node = BGP_VPNV4_NODE;
7000 return CMD_SUCCESS;
718e3744 7001}
7002
505e5056 7003DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7004 address_family_vpnv6_cmd,
8334fd5a 7005 "address-family vpnv6 [unicast]",
8ecd3266 7006 "Enter Address Family command mode\n"
8c3deaae 7007 "Address Family\n"
3a2d747c 7008 "Address Family modifier\n")
8ecd3266 7009{
d62a17ae 7010 vty->node = BGP_VPNV6_NODE;
7011 return CMD_SUCCESS;
8ecd3266 7012}
c016b6c7 7013#endif
d6902373 7014
505e5056 7015DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7016 address_family_evpn_cmd,
7111c1a0 7017 "address-family l2vpn evpn",
4e0b7b6d 7018 "Enter Address Family command mode\n"
7111c1a0
QY
7019 "Address Family\n"
7020 "Address Family modifier\n")
4e0b7b6d 7021{
2131d5cf 7022 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7023 vty->node = BGP_EVPN_NODE;
7024 return CMD_SUCCESS;
4e0b7b6d
PG
7025}
7026
505e5056 7027DEFUN_NOSH (exit_address_family,
718e3744 7028 exit_address_family_cmd,
7029 "exit-address-family",
7030 "Exit from Address Family configuration mode\n")
7031{
d62a17ae 7032 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7033 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7034 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7035 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7036 || vty->node == BGP_EVPN_NODE
7037 || vty->node == BGP_FLOWSPECV4_NODE
7038 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7039 vty->node = BGP_NODE;
7040 return CMD_SUCCESS;
718e3744 7041}
6b0655a2 7042
8ad7271d 7043/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7044static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7045 const char *ip_str, afi_t afi, safi_t safi,
7046 struct prefix_rd *prd)
7047{
7048 int ret;
7049 struct prefix match;
7050 struct bgp_node *rn;
7051 struct bgp_node *rm;
7052 struct bgp *bgp;
7053 struct bgp_table *table;
7054 struct bgp_table *rib;
7055
7056 /* BGP structure lookup. */
7057 if (view_name) {
7058 bgp = bgp_lookup_by_name(view_name);
7059 if (bgp == NULL) {
7060 vty_out(vty, "%% Can't find BGP instance %s\n",
7061 view_name);
7062 return CMD_WARNING;
7063 }
7064 } else {
7065 bgp = bgp_get_default();
7066 if (bgp == NULL) {
7067 vty_out(vty, "%% No BGP process is configured\n");
7068 return CMD_WARNING;
7069 }
7070 }
7071
7072 /* Check IP address argument. */
7073 ret = str2prefix(ip_str, &match);
7074 if (!ret) {
7075 vty_out(vty, "%% address is malformed\n");
7076 return CMD_WARNING;
7077 }
7078
7079 match.family = afi2family(afi);
7080 rib = bgp->rib[afi][safi];
7081
7082 if (safi == SAFI_MPLS_VPN) {
7083 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7084 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7085 continue;
7086
7087 if ((table = rn->info) != NULL) {
7088 if ((rm = bgp_node_match(table, &match))
7089 != NULL) {
7090 if (rm->p.prefixlen
7091 == match.prefixlen) {
343cdb61 7092 SET_FLAG(rm->flags,
d62a17ae 7093 BGP_NODE_USER_CLEAR);
7094 bgp_process(bgp, rm, afi, safi);
7095 }
7096 bgp_unlock_node(rm);
7097 }
7098 }
7099 }
7100 } else {
7101 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7102 if (rn->p.prefixlen == match.prefixlen) {
7103 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7104 bgp_process(bgp, rn, afi, safi);
7105 }
7106 bgp_unlock_node(rn);
7107 }
7108 }
7109
7110 return CMD_SUCCESS;
8ad7271d
DS
7111}
7112
b09b5ae0 7113/* one clear bgp command to rule them all */
718e3744 7114DEFUN (clear_ip_bgp_all,
7115 clear_ip_bgp_all_cmd,
c1a44e43 7116 "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 7117 CLEAR_STR
7118 IP_STR
7119 BGP_STR
838758ac 7120 BGP_INSTANCE_HELP_STR
510afcd6
DS
7121 BGP_AFI_HELP_STR
7122 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
7123 "Clear all peers\n"
7124 "BGP neighbor address to clear\n"
a80beece 7125 "BGP IPv6 neighbor to clear\n"
838758ac 7126 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7127 "Clear peers with the AS number\n"
7128 "Clear all external peers\n"
718e3744 7129 "Clear all members of peer-group\n"
b09b5ae0 7130 "BGP peer-group name\n"
b09b5ae0
DW
7131 BGP_SOFT_STR
7132 BGP_SOFT_IN_STR
b09b5ae0
DW
7133 BGP_SOFT_OUT_STR
7134 BGP_SOFT_IN_STR
7135 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7136 BGP_SOFT_OUT_STR)
718e3744 7137{
d62a17ae 7138 char *vrf = NULL;
7139
7140 afi_t afi = AFI_IP6;
7141 safi_t safi = SAFI_UNICAST;
7142 enum clear_sort clr_sort = clear_peer;
7143 enum bgp_clear_type clr_type;
7144 char *clr_arg = NULL;
7145
7146 int idx = 0;
7147
7148 /* clear [ip] bgp */
7149 if (argv_find(argv, argc, "ip", &idx))
7150 afi = AFI_IP;
7151
7152 /* [<view|vrf> VIEWVRFNAME] */
7153 if (argv_find(argv, argc, "view", &idx)
7154 || argv_find(argv, argc, "vrf", &idx)) {
7155 vrf = argv[idx + 1]->arg;
7156 idx += 2;
7157 }
7158
7159 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7160 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7161 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7162
7163 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7164 if (argv_find(argv, argc, "*", &idx)) {
7165 clr_sort = clear_all;
7166 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7167 clr_sort = clear_peer;
7168 clr_arg = argv[idx]->arg;
7169 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7170 clr_sort = clear_peer;
7171 clr_arg = argv[idx]->arg;
7172 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7173 clr_sort = clear_group;
7174 idx++;
7175 clr_arg = argv[idx]->arg;
7176 } else if (argv_find(argv, argc, "WORD", &idx)) {
7177 clr_sort = clear_peer;
7178 clr_arg = argv[idx]->arg;
7179 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7180 clr_sort = clear_as;
7181 clr_arg = argv[idx]->arg;
7182 } else if (argv_find(argv, argc, "external", &idx)) {
7183 clr_sort = clear_external;
7184 }
7185
7186 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7187 if (argv_find(argv, argc, "soft", &idx)) {
7188 if (argv_find(argv, argc, "in", &idx)
7189 || argv_find(argv, argc, "out", &idx))
7190 clr_type = strmatch(argv[idx]->text, "in")
7191 ? BGP_CLEAR_SOFT_IN
7192 : BGP_CLEAR_SOFT_OUT;
7193 else
7194 clr_type = BGP_CLEAR_SOFT_BOTH;
7195 } else if (argv_find(argv, argc, "in", &idx)) {
7196 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7197 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7198 : BGP_CLEAR_SOFT_IN;
7199 } else if (argv_find(argv, argc, "out", &idx)) {
7200 clr_type = BGP_CLEAR_SOFT_OUT;
7201 } else
7202 clr_type = BGP_CLEAR_SOFT_NONE;
7203
7204 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7205}
01080f7c 7206
8ad7271d
DS
7207DEFUN (clear_ip_bgp_prefix,
7208 clear_ip_bgp_prefix_cmd,
18c57037 7209 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7210 CLEAR_STR
7211 IP_STR
7212 BGP_STR
838758ac 7213 BGP_INSTANCE_HELP_STR
8ad7271d 7214 "Clear bestpath and re-advertise\n"
0c7b1b01 7215 "IPv4 prefix\n")
8ad7271d 7216{
d62a17ae 7217 char *vrf = NULL;
7218 char *prefix = NULL;
8ad7271d 7219
d62a17ae 7220 int idx = 0;
01080f7c 7221
d62a17ae 7222 /* [<view|vrf> VIEWVRFNAME] */
1d35f218 7223 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
d62a17ae 7224 vrf = argv[idx]->arg;
0c7b1b01 7225
d62a17ae 7226 prefix = argv[argc - 1]->arg;
8ad7271d 7227
d62a17ae 7228 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7229}
8ad7271d 7230
b09b5ae0
DW
7231DEFUN (clear_bgp_ipv6_safi_prefix,
7232 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7233 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7234 CLEAR_STR
3a2d747c 7235 IP_STR
718e3744 7236 BGP_STR
8c3deaae 7237 "Address Family\n"
46f296b4 7238 BGP_SAFI_HELP_STR
b09b5ae0 7239 "Clear bestpath and re-advertise\n"
0c7b1b01 7240 "IPv6 prefix\n")
718e3744 7241{
9b475e76
PG
7242 int idx_safi = 0;
7243 int idx_ipv6_prefix = 0;
7244 safi_t safi = SAFI_UNICAST;
7245 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7246 argv[idx_ipv6_prefix]->arg : NULL;
7247
7248 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7249 return bgp_clear_prefix(
9b475e76
PG
7250 vty, NULL, prefix, AFI_IP6,
7251 safi, NULL);
838758ac 7252}
01080f7c 7253
b09b5ae0
DW
7254DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7255 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7256 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7257 CLEAR_STR
3a2d747c 7258 IP_STR
718e3744 7259 BGP_STR
838758ac 7260 BGP_INSTANCE_HELP_STR
8c3deaae 7261 "Address Family\n"
46f296b4 7262 BGP_SAFI_HELP_STR
b09b5ae0 7263 "Clear bestpath and re-advertise\n"
0c7b1b01 7264 "IPv6 prefix\n")
718e3744 7265{
d62a17ae 7266 int idx_word = 3;
9b475e76
PG
7267 int idx_safi = 0;
7268 int idx_ipv6_prefix = 0;
7269 safi_t safi = SAFI_UNICAST;
7270 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7271 argv[idx_ipv6_prefix]->arg : NULL;
7272 /* [<view|vrf> VIEWVRFNAME] */
7273 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7274 argv[idx_word]->arg : NULL;
7275
7276 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7277
d62a17ae 7278 return bgp_clear_prefix(
9b475e76
PG
7279 vty, vrfview, prefix,
7280 AFI_IP6, safi, NULL);
718e3744 7281}
7282
b09b5ae0
DW
7283DEFUN (show_bgp_views,
7284 show_bgp_views_cmd,
d6e3c605 7285 "show [ip] bgp views",
b09b5ae0 7286 SHOW_STR
d6e3c605 7287 IP_STR
01080f7c 7288 BGP_STR
b09b5ae0 7289 "Show the defined BGP views\n")
01080f7c 7290{
d62a17ae 7291 struct list *inst = bm->bgp;
7292 struct listnode *node;
7293 struct bgp *bgp;
01080f7c 7294
d62a17ae 7295 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7296 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7297 return CMD_WARNING;
7298 }
e52702f2 7299
d62a17ae 7300 vty_out(vty, "Defined BGP views:\n");
7301 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7302 /* Skip VRFs. */
7303 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7304 continue;
7305 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7306 bgp->as);
7307 }
e52702f2 7308
d62a17ae 7309 return CMD_SUCCESS;
e0081f70
ML
7310}
7311
8386ac43 7312DEFUN (show_bgp_vrfs,
7313 show_bgp_vrfs_cmd,
d6e3c605 7314 "show [ip] bgp vrfs [json]",
8386ac43 7315 SHOW_STR
d6e3c605 7316 IP_STR
8386ac43 7317 BGP_STR
7318 "Show BGP VRFs\n"
9973d184 7319 JSON_STR)
8386ac43 7320{
fe1dc5a3 7321 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7322 struct list *inst = bm->bgp;
7323 struct listnode *node;
7324 struct bgp *bgp;
9f049418 7325 bool uj = use_json(argc, argv);
d62a17ae 7326 json_object *json = NULL;
7327 json_object *json_vrfs = NULL;
7328 int count = 0;
d62a17ae 7329
7330 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7331 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7332 return CMD_WARNING;
7333 }
7334
7335 if (uj) {
7336 json = json_object_new_object();
7337 json_vrfs = json_object_new_object();
7338 }
7339
7340 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7341 const char *name, *type;
7342 struct peer *peer;
7343 struct listnode *node, *nnode;
7344 int peers_cfg, peers_estb;
7345 json_object *json_vrf = NULL;
d62a17ae 7346
7347 /* Skip Views. */
7348 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7349 continue;
7350
7351 count++;
7352 if (!uj && count == 1)
fe1dc5a3
MK
7353 vty_out(vty,
7354 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7355 "Type", "Id", "routerId", "#PeersVfg",
7356 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7357
7358 peers_cfg = peers_estb = 0;
7359 if (uj)
7360 json_vrf = json_object_new_object();
7361
7362
7363 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7364 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7365 continue;
7366 peers_cfg++;
7367 if (peer->status == Established)
7368 peers_estb++;
7369 }
7370
7371 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7372 name = "Default";
7373 type = "DFLT";
7374 } else {
7375 name = bgp->name;
7376 type = "VRF";
7377 }
7378
a8bf7d9c 7379
d62a17ae 7380 if (uj) {
a4d82a8a
PZ
7381 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7382 ? -1
7383 : (int64_t)bgp->vrf_id;
d62a17ae 7384 json_object_string_add(json_vrf, "type", type);
7385 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7386 json_object_string_add(json_vrf, "routerId",
7387 inet_ntoa(bgp->router_id));
7388 json_object_int_add(json_vrf, "numConfiguredPeers",
7389 peers_cfg);
7390 json_object_int_add(json_vrf, "numEstablishedPeers",
7391 peers_estb);
7392
fe1dc5a3 7393 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7394 json_object_string_add(
7395 json_vrf, "rmac",
7396 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7397 json_object_object_add(json_vrfs, name, json_vrf);
7398 } else
fe1dc5a3
MK
7399 vty_out(vty,
7400 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7401 type,
7402 bgp->vrf_id == VRF_UNKNOWN ? -1
7403 : (int)bgp->vrf_id,
7404 inet_ntoa(bgp->router_id), peers_cfg,
7405 peers_estb, name, bgp->l3vni,
fe1dc5a3 7406 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7407 }
7408
7409 if (uj) {
7410 json_object_object_add(json, "vrfs", json_vrfs);
7411
7412 json_object_int_add(json, "totalVrfs", count);
7413
996c9314
LB
7414 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7415 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7416 json_object_free(json);
7417 } else {
7418 if (count)
7419 vty_out(vty,
7420 "\nTotal number of VRFs (including default): %d\n",
7421 count);
7422 }
7423
7424 return CMD_SUCCESS;
8386ac43 7425}
7426
acf71666
MK
7427static void show_address_entry(struct hash_backet *backet, void *args)
7428{
60466a63
QY
7429 struct vty *vty = (struct vty *)args;
7430 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 7431
60466a63 7432 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
7433 addr->refcnt);
7434}
7435
7436static void show_tip_entry(struct hash_backet *backet, void *args)
7437{
0291c246 7438 struct vty *vty = (struct vty *)args;
60466a63 7439 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7440
60466a63 7441 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7442 tip->refcnt);
7443}
7444
7445static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7446{
7447 vty_out(vty, "self nexthop database:\n");
7448 hash_iterate(bgp->address_hash,
7449 (void (*)(struct hash_backet *, void *))show_address_entry,
7450 vty);
7451
7452 vty_out(vty, "Tunnel-ip database:\n");
7453 hash_iterate(bgp->tip_hash,
7454 (void (*)(struct hash_backet *, void *))show_tip_entry,
7455 vty);
7456}
7457
15c81ca4
DS
7458DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7459 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7460 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7461 "martian next-hops\n"
7462 "martian next-hop database\n")
acf71666 7463{
0291c246 7464 struct bgp *bgp = NULL;
15c81ca4
DS
7465 int idx = 0;
7466
7467 if (argv_find(argv, argc, "view", &idx)
7468 || argv_find(argv, argc, "vrf", &idx))
7469 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7470 else
7471 bgp = bgp_get_default();
acf71666 7472
acf71666
MK
7473 if (!bgp) {
7474 vty_out(vty, "%% No BGP process is configured\n");
7475 return CMD_WARNING;
7476 }
7477 bgp_show_martian_nexthops(vty, bgp);
7478
7479 return CMD_SUCCESS;
7480}
7481
f412b39a 7482DEFUN (show_bgp_memory,
4bf6a362 7483 show_bgp_memory_cmd,
7fa12b13 7484 "show [ip] bgp memory",
4bf6a362 7485 SHOW_STR
3a2d747c 7486 IP_STR
4bf6a362
PJ
7487 BGP_STR
7488 "Global BGP memory statistics\n")
7489{
d62a17ae 7490 char memstrbuf[MTYPE_MEMSTR_LEN];
7491 unsigned long count;
7492
7493 /* RIB related usage stats */
7494 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7495 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7496 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7497 count * sizeof(struct bgp_node)));
7498
7499 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7500 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7501 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7502 count * sizeof(struct bgp_info)));
7503 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7504 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7505 count,
7506 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7507 count * sizeof(struct bgp_info_extra)));
7508
7509 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7510 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7511 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7512 count * sizeof(struct bgp_static)));
7513
7514 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7515 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7516 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7517 count * sizeof(struct bpacket)));
7518
7519 /* Adj-In/Out */
7520 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7521 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7522 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7523 count * sizeof(struct bgp_adj_in)));
7524 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7525 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7526 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7527 count * sizeof(struct bgp_adj_out)));
7528
7529 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7530 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7531 count,
7532 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7533 count * sizeof(struct bgp_nexthop_cache)));
7534
7535 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7536 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7537 count,
7538 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7539 count * sizeof(struct bgp_damp_info)));
7540
7541 /* Attributes */
7542 count = attr_count();
7543 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7544 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7545 count * sizeof(struct attr)));
7546
7547 if ((count = attr_unknown_count()))
7548 vty_out(vty, "%ld unknown attributes\n", count);
7549
7550 /* AS_PATH attributes */
7551 count = aspath_count();
7552 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7553 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7554 count * sizeof(struct aspath)));
7555
7556 count = mtype_stats_alloc(MTYPE_AS_SEG);
7557 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7558 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7559 count * sizeof(struct assegment)));
7560
7561 /* Other attributes */
7562 if ((count = community_count()))
7563 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7564 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7565 count * sizeof(struct community)));
d62a17ae 7566 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7567 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7568 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7569 count * sizeof(struct ecommunity)));
d62a17ae 7570 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7571 vty_out(vty,
7572 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7573 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7574 count * sizeof(struct lcommunity)));
d62a17ae 7575
7576 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7577 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7578 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7579 count * sizeof(struct cluster_list)));
7580
7581 /* Peer related usage */
7582 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7583 vty_out(vty, "%ld peers, using %s of memory\n", count,
7584 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7585 count * sizeof(struct peer)));
7586
7587 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7588 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7589 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7590 count * sizeof(struct peer_group)));
7591
7592 /* Other */
7593 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7594 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7595 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7596 count * sizeof(struct hash)));
7597 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7598 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7599 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7600 count * sizeof(struct hash_backet)));
7601 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7602 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7603 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7604 count * sizeof(regex_t)));
d62a17ae 7605 return CMD_SUCCESS;
4bf6a362 7606}
fee0f4c6 7607
57a9c8a8
DS
7608static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7609{
7610 json_object *bestpath = json_object_new_object();
7611
7612 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7613 json_object_string_add(bestpath, "asPath", "ignore");
7614
7615 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7616 json_object_string_add(bestpath, "asPath", "confed");
7617
7618 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7619 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7620 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7621 "as-set");
7622 else
a4d82a8a 7623 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7624 "true");
7625 } else
a4d82a8a 7626 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7627
7628 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7629 json_object_string_add(bestpath, "compareRouterId", "true");
7630 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7631 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7632 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7633 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7634 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7635 json_object_string_add(bestpath, "med",
7636 "missing-as-worst");
7637 else
7638 json_object_string_add(bestpath, "med", "true");
7639 }
7640
7641 json_object_object_add(json, "bestPath", bestpath);
7642}
7643
718e3744 7644/* Show BGP peer's summary information. */
d62a17ae 7645static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
9f049418 7646 bool use_json, json_object *json)
d62a17ae 7647{
7648 struct peer *peer;
7649 struct listnode *node, *nnode;
7650 unsigned int count = 0, dn_count = 0;
7651 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7652 char neighbor_buf[VTY_BUFSIZ];
7653 int neighbor_col_default_width = 16;
7654 int len;
7655 int max_neighbor_width = 0;
7656 int pfx_rcd_safi;
7657 json_object *json_peer = NULL;
7658 json_object *json_peers = NULL;
7659
7660 /* labeled-unicast routes are installed in the unicast table so in order
7661 * to
7662 * display the correct PfxRcd value we must look at SAFI_UNICAST
7663 */
7664 if (safi == SAFI_LABELED_UNICAST)
7665 pfx_rcd_safi = SAFI_UNICAST;
7666 else
7667 pfx_rcd_safi = safi;
7668
7669 if (use_json) {
7670 if (json == NULL)
7671 json = json_object_new_object();
7672
7673 json_peers = json_object_new_object();
7674 } else {
7675 /* Loop over all neighbors that will be displayed to determine
7676 * how many
7677 * characters are needed for the Neighbor column
7678 */
7679 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7680 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7681 continue;
7682
7683 if (peer->afc[afi][safi]) {
7684 memset(dn_flag, '\0', sizeof(dn_flag));
7685 if (peer_dynamic_neighbor(peer))
7686 dn_flag[0] = '*';
7687
7688 if (peer->hostname
7689 && bgp_flag_check(bgp,
7690 BGP_FLAG_SHOW_HOSTNAME))
7691 sprintf(neighbor_buf, "%s%s(%s) ",
7692 dn_flag, peer->hostname,
7693 peer->host);
7694 else
7695 sprintf(neighbor_buf, "%s%s ", dn_flag,
7696 peer->host);
7697
7698 len = strlen(neighbor_buf);
7699
7700 if (len > max_neighbor_width)
7701 max_neighbor_width = len;
7702 }
7703 }
f933309e 7704
d62a17ae 7705 /* Originally we displayed the Neighbor column as 16
7706 * characters wide so make that the default
7707 */
7708 if (max_neighbor_width < neighbor_col_default_width)
7709 max_neighbor_width = neighbor_col_default_width;
7710 }
f933309e 7711
d62a17ae 7712 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7713 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7714 continue;
7715
ea47320b
DL
7716 if (!peer->afc[afi][safi])
7717 continue;
d62a17ae 7718
ea47320b
DL
7719 if (!count) {
7720 unsigned long ents;
7721 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7722 int64_t vrf_id_ui;
d62a17ae 7723
a4d82a8a
PZ
7724 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7725 ? -1
7726 : (int64_t)bgp->vrf_id;
ea47320b
DL
7727
7728 /* Usage summary and header */
7729 if (use_json) {
7730 json_object_string_add(
7731 json, "routerId",
7732 inet_ntoa(bgp->router_id));
60466a63
QY
7733 json_object_int_add(json, "as", bgp->as);
7734 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7735 json_object_string_add(
7736 json, "vrfName",
7737 (bgp->inst_type
7738 == BGP_INSTANCE_TYPE_DEFAULT)
7739 ? "Default"
7740 : bgp->name);
7741 } else {
7742 vty_out(vty,
7743 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7744 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7745 bgp->vrf_id == VRF_UNKNOWN
7746 ? -1
7747 : (int)bgp->vrf_id);
ea47320b
DL
7748 vty_out(vty, "\n");
7749 }
d62a17ae 7750
ea47320b 7751 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7752 if (use_json) {
ea47320b 7753 json_object_int_add(
60466a63 7754 json, "updateDelayLimit",
ea47320b 7755 bgp->v_update_delay);
d62a17ae 7756
ea47320b
DL
7757 if (bgp->v_update_delay
7758 != bgp->v_establish_wait)
d62a17ae 7759 json_object_int_add(
7760 json,
ea47320b
DL
7761 "updateDelayEstablishWait",
7762 bgp->v_establish_wait);
d62a17ae 7763
60466a63 7764 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7765 json_object_string_add(
7766 json,
7767 "updateDelayFirstNeighbor",
7768 bgp->update_delay_begin_time);
7769 json_object_boolean_true_add(
7770 json,
7771 "updateDelayInProgress");
7772 } else {
7773 if (bgp->update_delay_over) {
d62a17ae 7774 json_object_string_add(
7775 json,
7776 "updateDelayFirstNeighbor",
7777 bgp->update_delay_begin_time);
ea47320b 7778 json_object_string_add(
d62a17ae 7779 json,
ea47320b
DL
7780 "updateDelayBestpathResumed",
7781 bgp->update_delay_end_time);
7782 json_object_string_add(
d62a17ae 7783 json,
ea47320b
DL
7784 "updateDelayZebraUpdateResume",
7785 bgp->update_delay_zebra_resume_time);
7786 json_object_string_add(
7787 json,
7788 "updateDelayPeerUpdateResume",
7789 bgp->update_delay_peers_resume_time);
d62a17ae 7790 }
ea47320b
DL
7791 }
7792 } else {
7793 vty_out(vty,
7794 "Read-only mode update-delay limit: %d seconds\n",
7795 bgp->v_update_delay);
7796 if (bgp->v_update_delay
7797 != bgp->v_establish_wait)
d62a17ae 7798 vty_out(vty,
ea47320b
DL
7799 " Establish wait: %d seconds\n",
7800 bgp->v_establish_wait);
d62a17ae 7801
60466a63 7802 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7803 vty_out(vty,
7804 " First neighbor established: %s\n",
7805 bgp->update_delay_begin_time);
7806 vty_out(vty,
7807 " Delay in progress\n");
7808 } else {
7809 if (bgp->update_delay_over) {
d62a17ae 7810 vty_out(vty,
7811 " First neighbor established: %s\n",
7812 bgp->update_delay_begin_time);
7813 vty_out(vty,
ea47320b
DL
7814 " Best-paths resumed: %s\n",
7815 bgp->update_delay_end_time);
7816 vty_out(vty,
7817 " zebra update resumed: %s\n",
7818 bgp->update_delay_zebra_resume_time);
7819 vty_out(vty,
7820 " peers update resumed: %s\n",
7821 bgp->update_delay_peers_resume_time);
d62a17ae 7822 }
7823 }
7824 }
ea47320b 7825 }
d62a17ae 7826
ea47320b
DL
7827 if (use_json) {
7828 if (bgp_maxmed_onstartup_configured(bgp)
7829 && bgp->maxmed_active)
7830 json_object_boolean_true_add(
60466a63 7831 json, "maxMedOnStartup");
ea47320b
DL
7832 if (bgp->v_maxmed_admin)
7833 json_object_boolean_true_add(
60466a63 7834 json, "maxMedAdministrative");
d62a17ae 7835
ea47320b
DL
7836 json_object_int_add(
7837 json, "tableVersion",
60466a63 7838 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7839
60466a63
QY
7840 ents = bgp_table_count(bgp->rib[afi][safi]);
7841 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7842 json_object_int_add(
7843 json, "ribMemory",
7844 ents * sizeof(struct bgp_node));
d62a17ae 7845
ea47320b 7846 ents = listcount(bgp->peer);
60466a63
QY
7847 json_object_int_add(json, "peerCount", ents);
7848 json_object_int_add(json, "peerMemory",
7849 ents * sizeof(struct peer));
d62a17ae 7850
ea47320b
DL
7851 if ((ents = listcount(bgp->group))) {
7852 json_object_int_add(
60466a63 7853 json, "peerGroupCount", ents);
ea47320b
DL
7854 json_object_int_add(
7855 json, "peerGroupMemory",
996c9314
LB
7856 ents * sizeof(struct
7857 peer_group));
ea47320b 7858 }
d62a17ae 7859
ea47320b
DL
7860 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7861 BGP_CONFIG_DAMPENING))
7862 json_object_boolean_true_add(
60466a63 7863 json, "dampeningEnabled");
ea47320b
DL
7864 } else {
7865 if (bgp_maxmed_onstartup_configured(bgp)
7866 && bgp->maxmed_active)
d62a17ae 7867 vty_out(vty,
ea47320b
DL
7868 "Max-med on-startup active\n");
7869 if (bgp->v_maxmed_admin)
d62a17ae 7870 vty_out(vty,
ea47320b 7871 "Max-med administrative active\n");
d62a17ae 7872
60466a63
QY
7873 vty_out(vty, "BGP table version %" PRIu64 "\n",
7874 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 7875
60466a63 7876 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
7877 vty_out(vty,
7878 "RIB entries %ld, using %s of memory\n",
7879 ents,
996c9314
LB
7880 mtype_memstr(memstrbuf,
7881 sizeof(memstrbuf),
7882 ents * sizeof(struct
7883 bgp_node)));
ea47320b
DL
7884
7885 /* Peer related usage */
7886 ents = listcount(bgp->peer);
60466a63 7887 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7888 ents,
7889 mtype_memstr(
60466a63
QY
7890 memstrbuf, sizeof(memstrbuf),
7891 ents * sizeof(struct peer)));
ea47320b
DL
7892
7893 if ((ents = listcount(bgp->group)))
d62a17ae 7894 vty_out(vty,
ea47320b 7895 "Peer groups %ld, using %s of memory\n",
d62a17ae 7896 ents,
7897 mtype_memstr(
7898 memstrbuf,
7899 sizeof(memstrbuf),
996c9314
LB
7900 ents * sizeof(struct
7901 peer_group)));
d62a17ae 7902
ea47320b
DL
7903 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7904 BGP_CONFIG_DAMPENING))
60466a63 7905 vty_out(vty, "Dampening enabled.\n");
ea47320b 7906 vty_out(vty, "\n");
d62a17ae 7907
ea47320b
DL
7908 /* Subtract 8 here because 'Neighbor' is
7909 * 8 characters */
7910 vty_out(vty, "Neighbor");
60466a63
QY
7911 vty_out(vty, "%*s", max_neighbor_width - 8,
7912 " ");
ea47320b
DL
7913 vty_out(vty,
7914 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7915 }
ea47320b 7916 }
d62a17ae 7917
ea47320b 7918 count++;
d62a17ae 7919
ea47320b
DL
7920 if (use_json) {
7921 json_peer = json_object_new_object();
d62a17ae 7922
b4e9dcba
DD
7923 if (peer_dynamic_neighbor(peer)) {
7924 dn_count++;
60466a63
QY
7925 json_object_boolean_true_add(json_peer,
7926 "dynamicPeer");
b4e9dcba 7927 }
d62a17ae 7928
ea47320b 7929 if (peer->hostname)
60466a63 7930 json_object_string_add(json_peer, "hostname",
ea47320b 7931 peer->hostname);
d62a17ae 7932
ea47320b 7933 if (peer->domainname)
60466a63
QY
7934 json_object_string_add(json_peer, "domainname",
7935 peer->domainname);
d62a17ae 7936
60466a63 7937 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7938 json_object_int_add(json_peer, "version", 4);
60466a63 7939 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 7940 PEER_TOTAL_RX(peer));
60466a63 7941 json_object_int_add(json_peer, "msgSent",
0112e9e0 7942 PEER_TOTAL_TX(peer));
ea47320b
DL
7943
7944 json_object_int_add(json_peer, "tableVersion",
7945 peer->version[afi][safi]);
7946 json_object_int_add(json_peer, "outq",
7947 peer->obuf->count);
7948 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7949 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7950 use_json, json_peer);
7951 json_object_int_add(json_peer, "prefixReceivedCount",
7952 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 7953
ea47320b 7954 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7955 json_object_string_add(json_peer, "state",
ea47320b 7956 "Idle (Admin)");
9199a725
TM
7957 else if (peer->afc_recv[afi][safi])
7958 json_object_string_add(
7959 json_peer, "state",
7960 lookup_msg(bgp_status_msg, peer->status,
7961 NULL));
60466a63
QY
7962 else if (CHECK_FLAG(peer->sflags,
7963 PEER_STATUS_PREFIX_OVERFLOW))
7964 json_object_string_add(json_peer, "state",
ea47320b
DL
7965 "Idle (PfxCt)");
7966 else
7967 json_object_string_add(
7968 json_peer, "state",
60466a63
QY
7969 lookup_msg(bgp_status_msg, peer->status,
7970 NULL));
ea47320b
DL
7971
7972 if (peer->conf_if)
60466a63 7973 json_object_string_add(json_peer, "idType",
ea47320b
DL
7974 "interface");
7975 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
7976 json_object_string_add(json_peer, "idType",
7977 "ipv4");
ea47320b 7978 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
7979 json_object_string_add(json_peer, "idType",
7980 "ipv6");
d62a17ae 7981
ea47320b
DL
7982 json_object_object_add(json_peers, peer->host,
7983 json_peer);
7984 } else {
7985 memset(dn_flag, '\0', sizeof(dn_flag));
7986 if (peer_dynamic_neighbor(peer)) {
7987 dn_count++;
7988 dn_flag[0] = '*';
7989 }
d62a17ae 7990
ea47320b 7991 if (peer->hostname
60466a63 7992 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 7993 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 7994 peer->hostname, peer->host);
ea47320b 7995 else
60466a63 7996 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
7997
7998 /* pad the neighbor column with spaces */
7999 if (len < max_neighbor_width)
60466a63
QY
8000 vty_out(vty, "%*s", max_neighbor_width - len,
8001 " ");
ea47320b 8002
86a55b99 8003 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
8004 peer->as, PEER_TOTAL_RX(peer),
8005 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8006 0, peer->obuf->count,
d62a17ae 8007 peer_uptime(peer->uptime, timebuf,
ea47320b 8008 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 8009
ea47320b 8010 if (peer->status == Established)
2f8f4f10 8011 if (peer->afc_recv[afi][safi])
95077abf 8012 vty_out(vty, " %12ld",
a4d82a8a
PZ
8013 peer->pcount[afi]
8014 [pfx_rcd_safi]);
95077abf
DW
8015 else
8016 vty_out(vty, " NoNeg");
ea47320b 8017 else {
60466a63 8018 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 8019 vty_out(vty, " Idle (Admin)");
60466a63
QY
8020 else if (CHECK_FLAG(
8021 peer->sflags,
8022 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 8023 vty_out(vty, " Idle (PfxCt)");
d62a17ae 8024 else
ea47320b 8025 vty_out(vty, " %12s",
60466a63
QY
8026 lookup_msg(bgp_status_msg,
8027 peer->status, NULL));
d62a17ae 8028 }
ea47320b 8029 vty_out(vty, "\n");
d62a17ae 8030 }
8031 }
f933309e 8032
d62a17ae 8033 if (use_json) {
8034 json_object_object_add(json, "peers", json_peers);
8035
8036 json_object_int_add(json, "totalPeers", count);
8037 json_object_int_add(json, "dynamicPeers", dn_count);
8038
57a9c8a8
DS
8039 bgp_show_bestpath_json(bgp, json);
8040
996c9314
LB
8041 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8042 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8043 json_object_free(json);
8044 } else {
8045 if (count)
8046 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8047 else {
d6ceaca3 8048 vty_out(vty, "No %s neighbor is configured\n",
8049 afi_safi_print(afi, safi));
d62a17ae 8050 }
b05a1c8b 8051
d6ceaca3 8052 if (dn_count) {
d62a17ae 8053 vty_out(vty, "* - dynamic neighbor\n");
8054 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8055 dn_count, bgp->dynamic_neighbors_limit);
8056 }
8057 }
1ff9a340 8058
d62a17ae 8059 return CMD_SUCCESS;
718e3744 8060}
8061
d62a17ae 8062static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
9f049418 8063 int safi, bool use_json,
d62a17ae 8064 json_object *json)
8065{
8066 int is_first = 1;
8067 int afi_wildcard = (afi == AFI_MAX);
8068 int safi_wildcard = (safi == SAFI_MAX);
8069 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 8070 bool nbr_output = false;
d62a17ae 8071
8072 if (use_json && is_wildcard)
8073 vty_out(vty, "{\n");
8074 if (afi_wildcard)
8075 afi = 1; /* AFI_IP */
8076 while (afi < AFI_MAX) {
8077 if (safi_wildcard)
8078 safi = 1; /* SAFI_UNICAST */
8079 while (safi < SAFI_MAX) {
318cac96 8080 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 8081 nbr_output = true;
d62a17ae 8082 if (is_wildcard) {
8083 /*
8084 * So limit output to those afi/safi
8085 * pairs that
8086 * actualy have something interesting in
8087 * them
8088 */
8089 if (use_json) {
8090 json = json_object_new_object();
8091
8092 if (!is_first)
8093 vty_out(vty, ",\n");
8094 else
8095 is_first = 0;
8096
8097 vty_out(vty, "\"%s\":",
8098 afi_safi_json(afi,
8099 safi));
8100 } else {
8101 vty_out(vty, "\n%s Summary:\n",
8102 afi_safi_print(afi,
8103 safi));
8104 }
8105 }
8106 bgp_show_summary(vty, bgp, afi, safi, use_json,
8107 json);
8108 }
8109 safi++;
d62a17ae 8110 if (!safi_wildcard)
8111 safi = SAFI_MAX;
8112 }
8113 afi++;
ee851c8c 8114 if (!afi_wildcard)
d62a17ae 8115 afi = AFI_MAX;
8116 }
8117
8118 if (use_json && is_wildcard)
8119 vty_out(vty, "}\n");
9f049418
DS
8120 else if (!nbr_output)
8121 use_json ? vty_out(vty, "{}\n")
8122 : vty_out(vty, "%% No BGP neighbors found\n");
d62a17ae 8123}
8124
8125static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
9f049418 8126 safi_t safi, bool use_json)
d62a17ae 8127{
8128 struct listnode *node, *nnode;
8129 struct bgp *bgp;
8130 json_object *json = NULL;
8131 int is_first = 1;
9f049418 8132 bool nbr_output = false;
d62a17ae 8133
8134 if (use_json)
8135 vty_out(vty, "{\n");
8136
8137 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 8138 nbr_output = true;
d62a17ae 8139 if (use_json) {
8140 json = json_object_new_object();
8141
8142 if (!is_first)
8143 vty_out(vty, ",\n");
8144 else
8145 is_first = 0;
8146
8147 vty_out(vty, "\"%s\":",
8148 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8149 ? "Default"
8150 : bgp->name);
8151 } else {
8152 vty_out(vty, "\nInstance %s:\n",
8153 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8154 ? "Default"
8155 : bgp->name);
8156 }
8157 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8158 }
8159
8160 if (use_json)
8161 vty_out(vty, "}\n");
9f049418
DS
8162 else if (!nbr_output)
8163 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 8164}
8165
8166int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
9f049418 8167 safi_t safi, bool use_json)
d62a17ae 8168{
8169 struct bgp *bgp;
8170
8171 if (name) {
8172 if (strmatch(name, "all")) {
8173 bgp_show_all_instances_summary_vty(vty, afi, safi,
8174 use_json);
8175 return CMD_SUCCESS;
8176 } else {
8177 bgp = bgp_lookup_by_name(name);
8178
8179 if (!bgp) {
9f049418
DS
8180 use_json
8181 ? vty_out(vty, "{}\n")
8182 : vty_out(vty,
8183 "%% BGP instance not found\n");
d62a17ae 8184 return CMD_WARNING;
8185 }
8186
8187 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8188 NULL);
8189 return CMD_SUCCESS;
8190 }
8191 }
8192
8193 bgp = bgp_get_default();
8194
8195 if (bgp)
8196 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
9f049418
DS
8197 else {
8198 use_json ? vty_out(vty, "{}\n")
8199 : vty_out(vty, "%% No such BGP instance exist\n");
8200 return CMD_WARNING;
8201 }
d62a17ae 8202
8203 return CMD_SUCCESS;
4fb25c53
DW
8204}
8205
716b2d8a 8206/* `show [ip] bgp summary' commands. */
47fc97cc 8207DEFUN (show_ip_bgp_summary,
718e3744 8208 show_ip_bgp_summary_cmd,
dd6bd0f1 8209 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8210 SHOW_STR
8211 IP_STR
8212 BGP_STR
8386ac43 8213 BGP_INSTANCE_HELP_STR
46f296b4 8214 BGP_AFI_HELP_STR
dd6bd0f1 8215 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8216 "Summary of BGP neighbor status\n"
9973d184 8217 JSON_STR)
718e3744 8218{
d62a17ae 8219 char *vrf = NULL;
8220 afi_t afi = AFI_MAX;
8221 safi_t safi = SAFI_MAX;
8222
8223 int idx = 0;
8224
8225 /* show [ip] bgp */
8226 if (argv_find(argv, argc, "ip", &idx))
8227 afi = AFI_IP;
8228 /* [<view|vrf> VIEWVRFNAME] */
8229 if (argv_find(argv, argc, "view", &idx)
8230 || argv_find(argv, argc, "vrf", &idx))
8231 vrf = argv[++idx]->arg;
8232 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8233 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8234 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8235 }
8236
9f049418 8237 bool uj = use_json(argc, argv);
d62a17ae 8238
8239 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8240}
8241
8242const char *afi_safi_print(afi_t afi, safi_t safi)
8243{
8244 if (afi == AFI_IP && safi == SAFI_UNICAST)
8245 return "IPv4 Unicast";
8246 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8247 return "IPv4 Multicast";
8248 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8249 return "IPv4 Labeled Unicast";
8250 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8251 return "IPv4 VPN";
8252 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8253 return "IPv4 Encap";
7c40bf39 8254 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8255 return "IPv4 Flowspec";
d62a17ae 8256 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8257 return "IPv6 Unicast";
8258 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8259 return "IPv6 Multicast";
8260 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8261 return "IPv6 Labeled Unicast";
8262 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8263 return "IPv6 VPN";
8264 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8265 return "IPv6 Encap";
7c40bf39 8266 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8267 return "IPv6 Flowspec";
d62a17ae 8268 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8269 return "L2VPN EVPN";
8270 else
8271 return "Unknown";
538621f2 8272}
8273
b9f77ec8
DS
8274/*
8275 * Please note that we have intentionally camelCased
8276 * the return strings here. So if you want
8277 * to use this function, please ensure you
8278 * are doing this within json output
8279 */
d62a17ae 8280const char *afi_safi_json(afi_t afi, safi_t safi)
8281{
8282 if (afi == AFI_IP && safi == SAFI_UNICAST)
8283 return "ipv4Unicast";
8284 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8285 return "ipv4Multicast";
8286 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8287 return "ipv4LabeledUnicast";
8288 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8289 return "ipv4Vpn";
8290 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8291 return "ipv4Encap";
7c40bf39 8292 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8293 return "ipv4Flowspec";
d62a17ae 8294 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8295 return "ipv6Unicast";
8296 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8297 return "ipv6Multicast";
8298 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8299 return "ipv6LabeledUnicast";
8300 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8301 return "ipv6Vpn";
8302 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8303 return "ipv6Encap";
7c40bf39 8304 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8305 return "ipv6Flowspec";
d62a17ae 8306 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8307 return "l2VpnEvpn";
8308 else
8309 return "Unknown";
27162734
LB
8310}
8311
718e3744 8312/* Show BGP peer's information. */
d62a17ae 8313enum show_type { show_all, show_peer };
8314
8315static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8316 afi_t afi, safi_t safi,
d7c0a89a
QY
8317 uint16_t adv_smcap, uint16_t adv_rmcap,
8318 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 8319 bool use_json, json_object *json_pref)
d62a17ae 8320{
8321 /* Send-Mode */
8322 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8323 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8324 if (use_json) {
8325 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8326 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8327 json_object_string_add(json_pref, "sendMode",
8328 "advertisedAndReceived");
8329 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8330 json_object_string_add(json_pref, "sendMode",
8331 "advertised");
8332 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8333 json_object_string_add(json_pref, "sendMode",
8334 "received");
8335 } else {
8336 vty_out(vty, " Send-mode: ");
8337 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8338 vty_out(vty, "advertised");
8339 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8340 vty_out(vty, "%sreceived",
8341 CHECK_FLAG(p->af_cap[afi][safi],
8342 adv_smcap)
8343 ? ", "
8344 : "");
8345 vty_out(vty, "\n");
8346 }
8347 }
8348
8349 /* Receive-Mode */
8350 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8351 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8352 if (use_json) {
8353 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8354 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8355 json_object_string_add(json_pref, "recvMode",
8356 "advertisedAndReceived");
8357 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8358 json_object_string_add(json_pref, "recvMode",
8359 "advertised");
8360 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8361 json_object_string_add(json_pref, "recvMode",
8362 "received");
8363 } else {
8364 vty_out(vty, " Receive-mode: ");
8365 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8366 vty_out(vty, "advertised");
8367 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8368 vty_out(vty, "%sreceived",
8369 CHECK_FLAG(p->af_cap[afi][safi],
8370 adv_rmcap)
8371 ? ", "
8372 : "");
8373 vty_out(vty, "\n");
8374 }
8375 }
8376}
8377
8378static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 8379 safi_t safi, bool use_json,
d62a17ae 8380 json_object *json_neigh)
8381{
0291c246
MK
8382 struct bgp_filter *filter;
8383 struct peer_af *paf;
8384 char orf_pfx_name[BUFSIZ];
8385 int orf_pfx_count;
8386 json_object *json_af = NULL;
8387 json_object *json_prefA = NULL;
8388 json_object *json_prefB = NULL;
8389 json_object *json_addr = NULL;
d62a17ae 8390
8391 if (use_json) {
8392 json_addr = json_object_new_object();
8393 json_af = json_object_new_object();
8394 filter = &p->filter[afi][safi];
8395
8396 if (peer_group_active(p))
8397 json_object_string_add(json_addr, "peerGroupMember",
8398 p->group->name);
8399
8400 paf = peer_af_find(p, afi, safi);
8401 if (paf && PAF_SUBGRP(paf)) {
8402 json_object_int_add(json_addr, "updateGroupId",
8403 PAF_UPDGRP(paf)->id);
8404 json_object_int_add(json_addr, "subGroupId",
8405 PAF_SUBGRP(paf)->id);
8406 json_object_int_add(json_addr, "packetQueueLength",
8407 bpacket_queue_virtual_length(paf));
8408 }
8409
8410 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8411 || CHECK_FLAG(p->af_cap[afi][safi],
8412 PEER_CAP_ORF_PREFIX_SM_RCV)
8413 || CHECK_FLAG(p->af_cap[afi][safi],
8414 PEER_CAP_ORF_PREFIX_RM_ADV)
8415 || CHECK_FLAG(p->af_cap[afi][safi],
8416 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8417 json_object_int_add(json_af, "orfType",
8418 ORF_TYPE_PREFIX);
8419 json_prefA = json_object_new_object();
8420 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8421 PEER_CAP_ORF_PREFIX_SM_ADV,
8422 PEER_CAP_ORF_PREFIX_RM_ADV,
8423 PEER_CAP_ORF_PREFIX_SM_RCV,
8424 PEER_CAP_ORF_PREFIX_RM_RCV,
8425 use_json, json_prefA);
8426 json_object_object_add(json_af, "orfPrefixList",
8427 json_prefA);
8428 }
8429
8430 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8431 || CHECK_FLAG(p->af_cap[afi][safi],
8432 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8433 || CHECK_FLAG(p->af_cap[afi][safi],
8434 PEER_CAP_ORF_PREFIX_RM_ADV)
8435 || CHECK_FLAG(p->af_cap[afi][safi],
8436 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8437 json_object_int_add(json_af, "orfOldType",
8438 ORF_TYPE_PREFIX_OLD);
8439 json_prefB = json_object_new_object();
8440 bgp_show_peer_afi_orf_cap(
8441 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8442 PEER_CAP_ORF_PREFIX_RM_ADV,
8443 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8444 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8445 json_prefB);
8446 json_object_object_add(json_af, "orfOldPrefixList",
8447 json_prefB);
8448 }
8449
8450 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8451 || CHECK_FLAG(p->af_cap[afi][safi],
8452 PEER_CAP_ORF_PREFIX_SM_RCV)
8453 || CHECK_FLAG(p->af_cap[afi][safi],
8454 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8455 || CHECK_FLAG(p->af_cap[afi][safi],
8456 PEER_CAP_ORF_PREFIX_RM_ADV)
8457 || CHECK_FLAG(p->af_cap[afi][safi],
8458 PEER_CAP_ORF_PREFIX_RM_RCV)
8459 || CHECK_FLAG(p->af_cap[afi][safi],
8460 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8461 json_object_object_add(json_addr, "afDependentCap",
8462 json_af);
8463 else
8464 json_object_free(json_af);
8465
8466 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8467 orf_pfx_count = prefix_bgp_show_prefix_list(
8468 NULL, afi, orf_pfx_name, use_json);
8469
8470 if (CHECK_FLAG(p->af_sflags[afi][safi],
8471 PEER_STATUS_ORF_PREFIX_SEND)
8472 || orf_pfx_count) {
8473 if (CHECK_FLAG(p->af_sflags[afi][safi],
8474 PEER_STATUS_ORF_PREFIX_SEND))
8475 json_object_boolean_true_add(json_neigh,
8476 "orfSent");
8477 if (orf_pfx_count)
8478 json_object_int_add(json_addr, "orfRecvCounter",
8479 orf_pfx_count);
8480 }
8481 if (CHECK_FLAG(p->af_sflags[afi][safi],
8482 PEER_STATUS_ORF_WAIT_REFRESH))
8483 json_object_string_add(
8484 json_addr, "orfFirstUpdate",
8485 "deferredUntilORFOrRouteRefreshRecvd");
8486
8487 if (CHECK_FLAG(p->af_flags[afi][safi],
8488 PEER_FLAG_REFLECTOR_CLIENT))
8489 json_object_boolean_true_add(json_addr,
8490 "routeReflectorClient");
8491 if (CHECK_FLAG(p->af_flags[afi][safi],
8492 PEER_FLAG_RSERVER_CLIENT))
8493 json_object_boolean_true_add(json_addr,
8494 "routeServerClient");
8495 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8496 json_object_boolean_true_add(json_addr,
8497 "inboundSoftConfigPermit");
8498
8499 if (CHECK_FLAG(p->af_flags[afi][safi],
8500 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8501 json_object_boolean_true_add(
8502 json_addr,
8503 "privateAsNumsAllReplacedInUpdatesToNbr");
8504 else if (CHECK_FLAG(p->af_flags[afi][safi],
8505 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8506 json_object_boolean_true_add(
8507 json_addr,
8508 "privateAsNumsReplacedInUpdatesToNbr");
8509 else if (CHECK_FLAG(p->af_flags[afi][safi],
8510 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8511 json_object_boolean_true_add(
8512 json_addr,
8513 "privateAsNumsAllRemovedInUpdatesToNbr");
8514 else if (CHECK_FLAG(p->af_flags[afi][safi],
8515 PEER_FLAG_REMOVE_PRIVATE_AS))
8516 json_object_boolean_true_add(
8517 json_addr,
8518 "privateAsNumsRemovedInUpdatesToNbr");
8519
8520 if (CHECK_FLAG(p->af_flags[afi][safi],
8521 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8522 json_object_boolean_true_add(json_addr,
8523 "addpathTxAllPaths");
8524
8525 if (CHECK_FLAG(p->af_flags[afi][safi],
8526 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8527 json_object_boolean_true_add(json_addr,
8528 "addpathTxBestpathPerAS");
8529
8530 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8531 json_object_string_add(json_addr,
8532 "overrideASNsInOutboundUpdates",
8533 "ifAspathEqualRemoteAs");
8534
8535 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8536 || CHECK_FLAG(p->af_flags[afi][safi],
8537 PEER_FLAG_FORCE_NEXTHOP_SELF))
8538 json_object_boolean_true_add(json_addr,
8539 "routerAlwaysNextHop");
8540 if (CHECK_FLAG(p->af_flags[afi][safi],
8541 PEER_FLAG_AS_PATH_UNCHANGED))
8542 json_object_boolean_true_add(
8543 json_addr, "unchangedAsPathPropogatedToNbr");
8544 if (CHECK_FLAG(p->af_flags[afi][safi],
8545 PEER_FLAG_NEXTHOP_UNCHANGED))
8546 json_object_boolean_true_add(
8547 json_addr, "unchangedNextHopPropogatedToNbr");
8548 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8549 json_object_boolean_true_add(
8550 json_addr, "unchangedMedPropogatedToNbr");
8551 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8552 || CHECK_FLAG(p->af_flags[afi][safi],
8553 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8554 if (CHECK_FLAG(p->af_flags[afi][safi],
8555 PEER_FLAG_SEND_COMMUNITY)
8556 && CHECK_FLAG(p->af_flags[afi][safi],
8557 PEER_FLAG_SEND_EXT_COMMUNITY))
8558 json_object_string_add(json_addr,
8559 "commAttriSentToNbr",
8560 "extendedAndStandard");
8561 else if (CHECK_FLAG(p->af_flags[afi][safi],
8562 PEER_FLAG_SEND_EXT_COMMUNITY))
8563 json_object_string_add(json_addr,
8564 "commAttriSentToNbr",
8565 "extended");
8566 else
8567 json_object_string_add(json_addr,
8568 "commAttriSentToNbr",
8569 "standard");
8570 }
8571 if (CHECK_FLAG(p->af_flags[afi][safi],
8572 PEER_FLAG_DEFAULT_ORIGINATE)) {
8573 if (p->default_rmap[afi][safi].name)
8574 json_object_string_add(
8575 json_addr, "defaultRouteMap",
8576 p->default_rmap[afi][safi].name);
8577
8578 if (paf && PAF_SUBGRP(paf)
8579 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8580 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8581 json_object_boolean_true_add(json_addr,
8582 "defaultSent");
8583 else
8584 json_object_boolean_true_add(json_addr,
8585 "defaultNotSent");
8586 }
8587
dff8f48d 8588 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8589 if (is_evpn_enabled())
60466a63
QY
8590 json_object_boolean_true_add(
8591 json_addr, "advertiseAllVnis");
dff8f48d
MK
8592 }
8593
d62a17ae 8594 if (filter->plist[FILTER_IN].name
8595 || filter->dlist[FILTER_IN].name
8596 || filter->aslist[FILTER_IN].name
8597 || filter->map[RMAP_IN].name)
8598 json_object_boolean_true_add(json_addr,
8599 "inboundPathPolicyConfig");
8600 if (filter->plist[FILTER_OUT].name
8601 || filter->dlist[FILTER_OUT].name
8602 || filter->aslist[FILTER_OUT].name
8603 || filter->map[RMAP_OUT].name || filter->usmap.name)
8604 json_object_boolean_true_add(
8605 json_addr, "outboundPathPolicyConfig");
8606
8607 /* prefix-list */
8608 if (filter->plist[FILTER_IN].name)
8609 json_object_string_add(json_addr,
8610 "incomingUpdatePrefixFilterList",
8611 filter->plist[FILTER_IN].name);
8612 if (filter->plist[FILTER_OUT].name)
8613 json_object_string_add(json_addr,
8614 "outgoingUpdatePrefixFilterList",
8615 filter->plist[FILTER_OUT].name);
8616
8617 /* distribute-list */
8618 if (filter->dlist[FILTER_IN].name)
8619 json_object_string_add(
8620 json_addr, "incomingUpdateNetworkFilterList",
8621 filter->dlist[FILTER_IN].name);
8622 if (filter->dlist[FILTER_OUT].name)
8623 json_object_string_add(
8624 json_addr, "outgoingUpdateNetworkFilterList",
8625 filter->dlist[FILTER_OUT].name);
8626
8627 /* filter-list. */
8628 if (filter->aslist[FILTER_IN].name)
8629 json_object_string_add(json_addr,
8630 "incomingUpdateAsPathFilterList",
8631 filter->aslist[FILTER_IN].name);
8632 if (filter->aslist[FILTER_OUT].name)
8633 json_object_string_add(json_addr,
8634 "outgoingUpdateAsPathFilterList",
8635 filter->aslist[FILTER_OUT].name);
8636
8637 /* route-map. */
8638 if (filter->map[RMAP_IN].name)
8639 json_object_string_add(
8640 json_addr, "routeMapForIncomingAdvertisements",
8641 filter->map[RMAP_IN].name);
8642 if (filter->map[RMAP_OUT].name)
8643 json_object_string_add(
8644 json_addr, "routeMapForOutgoingAdvertisements",
8645 filter->map[RMAP_OUT].name);
8646
8647 /* unsuppress-map */
8648 if (filter->usmap.name)
8649 json_object_string_add(json_addr,
8650 "selectiveUnsuppressRouteMap",
8651 filter->usmap.name);
8652
8653 /* Receive prefix count */
8654 json_object_int_add(json_addr, "acceptedPrefixCounter",
8655 p->pcount[afi][safi]);
8656
8657 /* Maximum prefix */
8658 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8659 json_object_int_add(json_addr, "prefixAllowedMax",
8660 p->pmax[afi][safi]);
8661 if (CHECK_FLAG(p->af_flags[afi][safi],
8662 PEER_FLAG_MAX_PREFIX_WARNING))
8663 json_object_boolean_true_add(
8664 json_addr, "prefixAllowedMaxWarning");
8665 json_object_int_add(json_addr,
8666 "prefixAllowedWarningThresh",
8667 p->pmax_threshold[afi][safi]);
8668 if (p->pmax_restart[afi][safi])
8669 json_object_int_add(
8670 json_addr,
8671 "prefixAllowedRestartIntervalMsecs",
8672 p->pmax_restart[afi][safi] * 60000);
8673 }
8674 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8675 json_addr);
8676
8677 } else {
8678 filter = &p->filter[afi][safi];
8679
8680 vty_out(vty, " For address family: %s\n",
8681 afi_safi_print(afi, safi));
8682
8683 if (peer_group_active(p))
8684 vty_out(vty, " %s peer-group member\n",
8685 p->group->name);
8686
8687 paf = peer_af_find(p, afi, safi);
8688 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8689 vty_out(vty, " Update group %" PRIu64
8690 ", subgroup %" PRIu64 "\n",
d62a17ae 8691 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8692 vty_out(vty, " Packet Queue length %d\n",
8693 bpacket_queue_virtual_length(paf));
8694 } else {
8695 vty_out(vty, " Not part of any update group\n");
8696 }
8697 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8698 || CHECK_FLAG(p->af_cap[afi][safi],
8699 PEER_CAP_ORF_PREFIX_SM_RCV)
8700 || CHECK_FLAG(p->af_cap[afi][safi],
8701 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8702 || CHECK_FLAG(p->af_cap[afi][safi],
8703 PEER_CAP_ORF_PREFIX_RM_ADV)
8704 || CHECK_FLAG(p->af_cap[afi][safi],
8705 PEER_CAP_ORF_PREFIX_RM_RCV)
8706 || CHECK_FLAG(p->af_cap[afi][safi],
8707 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8708 vty_out(vty, " AF-dependant capabilities:\n");
8709
8710 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8711 || CHECK_FLAG(p->af_cap[afi][safi],
8712 PEER_CAP_ORF_PREFIX_SM_RCV)
8713 || CHECK_FLAG(p->af_cap[afi][safi],
8714 PEER_CAP_ORF_PREFIX_RM_ADV)
8715 || CHECK_FLAG(p->af_cap[afi][safi],
8716 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8717 vty_out(vty,
8718 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8719 ORF_TYPE_PREFIX);
8720 bgp_show_peer_afi_orf_cap(
8721 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8722 PEER_CAP_ORF_PREFIX_RM_ADV,
8723 PEER_CAP_ORF_PREFIX_SM_RCV,
8724 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8725 }
8726 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8727 || CHECK_FLAG(p->af_cap[afi][safi],
8728 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8729 || CHECK_FLAG(p->af_cap[afi][safi],
8730 PEER_CAP_ORF_PREFIX_RM_ADV)
8731 || CHECK_FLAG(p->af_cap[afi][safi],
8732 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8733 vty_out(vty,
8734 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8735 ORF_TYPE_PREFIX_OLD);
8736 bgp_show_peer_afi_orf_cap(
8737 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8738 PEER_CAP_ORF_PREFIX_RM_ADV,
8739 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8740 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8741 }
8742
8743 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8744 orf_pfx_count = prefix_bgp_show_prefix_list(
8745 NULL, afi, orf_pfx_name, use_json);
8746
8747 if (CHECK_FLAG(p->af_sflags[afi][safi],
8748 PEER_STATUS_ORF_PREFIX_SEND)
8749 || orf_pfx_count) {
8750 vty_out(vty, " Outbound Route Filter (ORF):");
8751 if (CHECK_FLAG(p->af_sflags[afi][safi],
8752 PEER_STATUS_ORF_PREFIX_SEND))
8753 vty_out(vty, " sent;");
8754 if (orf_pfx_count)
8755 vty_out(vty, " received (%d entries)",
8756 orf_pfx_count);
8757 vty_out(vty, "\n");
8758 }
8759 if (CHECK_FLAG(p->af_sflags[afi][safi],
8760 PEER_STATUS_ORF_WAIT_REFRESH))
8761 vty_out(vty,
8762 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8763
8764 if (CHECK_FLAG(p->af_flags[afi][safi],
8765 PEER_FLAG_REFLECTOR_CLIENT))
8766 vty_out(vty, " Route-Reflector Client\n");
8767 if (CHECK_FLAG(p->af_flags[afi][safi],
8768 PEER_FLAG_RSERVER_CLIENT))
8769 vty_out(vty, " Route-Server Client\n");
8770 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8771 vty_out(vty,
8772 " Inbound soft reconfiguration allowed\n");
8773
8774 if (CHECK_FLAG(p->af_flags[afi][safi],
8775 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8776 vty_out(vty,
8777 " Private AS numbers (all) replaced in updates to this neighbor\n");
8778 else if (CHECK_FLAG(p->af_flags[afi][safi],
8779 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8780 vty_out(vty,
8781 " Private AS numbers replaced in updates to this neighbor\n");
8782 else if (CHECK_FLAG(p->af_flags[afi][safi],
8783 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8784 vty_out(vty,
8785 " Private AS numbers (all) removed in updates to this neighbor\n");
8786 else if (CHECK_FLAG(p->af_flags[afi][safi],
8787 PEER_FLAG_REMOVE_PRIVATE_AS))
8788 vty_out(vty,
8789 " Private AS numbers removed in updates to this neighbor\n");
8790
8791 if (CHECK_FLAG(p->af_flags[afi][safi],
8792 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8793 vty_out(vty, " Advertise all paths via addpath\n");
8794
8795 if (CHECK_FLAG(p->af_flags[afi][safi],
8796 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8797 vty_out(vty,
8798 " Advertise bestpath per AS via addpath\n");
8799
8800 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8801 vty_out(vty,
8802 " Override ASNs in outbound updates if aspath equals remote-as\n");
8803
8804 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8805 || CHECK_FLAG(p->af_flags[afi][safi],
8806 PEER_FLAG_FORCE_NEXTHOP_SELF))
8807 vty_out(vty, " NEXT_HOP is always this router\n");
8808 if (CHECK_FLAG(p->af_flags[afi][safi],
8809 PEER_FLAG_AS_PATH_UNCHANGED))
8810 vty_out(vty,
8811 " AS_PATH is propagated unchanged to this neighbor\n");
8812 if (CHECK_FLAG(p->af_flags[afi][safi],
8813 PEER_FLAG_NEXTHOP_UNCHANGED))
8814 vty_out(vty,
8815 " NEXT_HOP is propagated unchanged to this neighbor\n");
8816 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8817 vty_out(vty,
8818 " MED is propagated unchanged to this neighbor\n");
8819 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8820 || CHECK_FLAG(p->af_flags[afi][safi],
8821 PEER_FLAG_SEND_EXT_COMMUNITY)
8822 || CHECK_FLAG(p->af_flags[afi][safi],
8823 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8824 vty_out(vty,
8825 " Community attribute sent to this neighbor");
8826 if (CHECK_FLAG(p->af_flags[afi][safi],
8827 PEER_FLAG_SEND_COMMUNITY)
8828 && CHECK_FLAG(p->af_flags[afi][safi],
8829 PEER_FLAG_SEND_EXT_COMMUNITY)
8830 && CHECK_FLAG(p->af_flags[afi][safi],
8831 PEER_FLAG_SEND_LARGE_COMMUNITY))
8832 vty_out(vty, "(all)\n");
8833 else if (CHECK_FLAG(p->af_flags[afi][safi],
8834 PEER_FLAG_SEND_LARGE_COMMUNITY))
8835 vty_out(vty, "(large)\n");
8836 else if (CHECK_FLAG(p->af_flags[afi][safi],
8837 PEER_FLAG_SEND_EXT_COMMUNITY))
8838 vty_out(vty, "(extended)\n");
8839 else
8840 vty_out(vty, "(standard)\n");
8841 }
8842 if (CHECK_FLAG(p->af_flags[afi][safi],
8843 PEER_FLAG_DEFAULT_ORIGINATE)) {
8844 vty_out(vty, " Default information originate,");
8845
8846 if (p->default_rmap[afi][safi].name)
8847 vty_out(vty, " default route-map %s%s,",
8848 p->default_rmap[afi][safi].map ? "*"
8849 : "",
8850 p->default_rmap[afi][safi].name);
8851 if (paf && PAF_SUBGRP(paf)
8852 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8853 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8854 vty_out(vty, " default sent\n");
8855 else
8856 vty_out(vty, " default not sent\n");
8857 }
8858
dff8f48d
MK
8859 /* advertise-vni-all */
8860 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8861 if (is_evpn_enabled())
dff8f48d
MK
8862 vty_out(vty, " advertise-all-vni\n");
8863 }
8864
d62a17ae 8865 if (filter->plist[FILTER_IN].name
8866 || filter->dlist[FILTER_IN].name
8867 || filter->aslist[FILTER_IN].name
8868 || filter->map[RMAP_IN].name)
8869 vty_out(vty, " Inbound path policy configured\n");
8870 if (filter->plist[FILTER_OUT].name
8871 || filter->dlist[FILTER_OUT].name
8872 || filter->aslist[FILTER_OUT].name
8873 || filter->map[RMAP_OUT].name || filter->usmap.name)
8874 vty_out(vty, " Outbound path policy configured\n");
8875
8876 /* prefix-list */
8877 if (filter->plist[FILTER_IN].name)
8878 vty_out(vty,
8879 " Incoming update prefix filter list is %s%s\n",
8880 filter->plist[FILTER_IN].plist ? "*" : "",
8881 filter->plist[FILTER_IN].name);
8882 if (filter->plist[FILTER_OUT].name)
8883 vty_out(vty,
8884 " Outgoing update prefix filter list is %s%s\n",
8885 filter->plist[FILTER_OUT].plist ? "*" : "",
8886 filter->plist[FILTER_OUT].name);
8887
8888 /* distribute-list */
8889 if (filter->dlist[FILTER_IN].name)
8890 vty_out(vty,
8891 " Incoming update network filter list is %s%s\n",
8892 filter->dlist[FILTER_IN].alist ? "*" : "",
8893 filter->dlist[FILTER_IN].name);
8894 if (filter->dlist[FILTER_OUT].name)
8895 vty_out(vty,
8896 " Outgoing update network filter list is %s%s\n",
8897 filter->dlist[FILTER_OUT].alist ? "*" : "",
8898 filter->dlist[FILTER_OUT].name);
8899
8900 /* filter-list. */
8901 if (filter->aslist[FILTER_IN].name)
8902 vty_out(vty,
8903 " Incoming update AS path filter list is %s%s\n",
8904 filter->aslist[FILTER_IN].aslist ? "*" : "",
8905 filter->aslist[FILTER_IN].name);
8906 if (filter->aslist[FILTER_OUT].name)
8907 vty_out(vty,
8908 " Outgoing update AS path filter list is %s%s\n",
8909 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8910 filter->aslist[FILTER_OUT].name);
8911
8912 /* route-map. */
8913 if (filter->map[RMAP_IN].name)
8914 vty_out(vty,
8915 " Route map for incoming advertisements is %s%s\n",
8916 filter->map[RMAP_IN].map ? "*" : "",
8917 filter->map[RMAP_IN].name);
8918 if (filter->map[RMAP_OUT].name)
8919 vty_out(vty,
8920 " Route map for outgoing advertisements is %s%s\n",
8921 filter->map[RMAP_OUT].map ? "*" : "",
8922 filter->map[RMAP_OUT].name);
8923
8924 /* unsuppress-map */
8925 if (filter->usmap.name)
8926 vty_out(vty,
8927 " Route map for selective unsuppress is %s%s\n",
8928 filter->usmap.map ? "*" : "",
8929 filter->usmap.name);
8930
8931 /* Receive prefix count */
8932 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8933
8934 /* Maximum prefix */
8935 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8936 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8937 p->pmax[afi][safi],
8938 CHECK_FLAG(p->af_flags[afi][safi],
8939 PEER_FLAG_MAX_PREFIX_WARNING)
8940 ? " (warning-only)"
8941 : "");
8942 vty_out(vty, " Threshold for warning message %d%%",
8943 p->pmax_threshold[afi][safi]);
8944 if (p->pmax_restart[afi][safi])
8945 vty_out(vty, ", restart interval %d min",
8946 p->pmax_restart[afi][safi]);
8947 vty_out(vty, "\n");
8948 }
8949
8950 vty_out(vty, "\n");
8951 }
8952}
8953
9f049418 8954static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 8955 json_object *json)
718e3744 8956{
d62a17ae 8957 struct bgp *bgp;
8958 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8959 char timebuf[BGP_UPTIME_LEN];
8960 char dn_flag[2];
8961 const char *subcode_str;
8962 const char *code_str;
8963 afi_t afi;
8964 safi_t safi;
d7c0a89a
QY
8965 uint16_t i;
8966 uint8_t *msg;
d62a17ae 8967 json_object *json_neigh = NULL;
8968 time_t epoch_tbuf;
718e3744 8969
d62a17ae 8970 bgp = p->bgp;
8971
8972 if (use_json)
8973 json_neigh = json_object_new_object();
8974
8975 memset(dn_flag, '\0', sizeof(dn_flag));
8976 if (!p->conf_if && peer_dynamic_neighbor(p))
8977 dn_flag[0] = '*';
8978
8979 if (!use_json) {
8980 if (p->conf_if) /* Configured interface name. */
8981 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8982 BGP_PEER_SU_UNSPEC(p)
8983 ? "None"
8984 : sockunion2str(&p->su, buf,
8985 SU_ADDRSTRLEN));
8986 else /* Configured IP address. */
8987 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8988 p->host);
8989 }
8990
8991 if (use_json) {
8992 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8993 json_object_string_add(json_neigh, "bgpNeighborAddr",
8994 "none");
8995 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8996 json_object_string_add(
8997 json_neigh, "bgpNeighborAddr",
8998 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8999
9000 json_object_int_add(json_neigh, "remoteAs", p->as);
9001
9002 if (p->change_local_as)
9003 json_object_int_add(json_neigh, "localAs",
9004 p->change_local_as);
9005 else
9006 json_object_int_add(json_neigh, "localAs", p->local_as);
9007
9008 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9009 json_object_boolean_true_add(json_neigh,
9010 "localAsNoPrepend");
9011
9012 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9013 json_object_boolean_true_add(json_neigh,
9014 "localAsReplaceAs");
9015 } else {
9016 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9017 || (p->as_type == AS_INTERNAL))
9018 vty_out(vty, "remote AS %u, ", p->as);
9019 else
9020 vty_out(vty, "remote AS Unspecified, ");
9021 vty_out(vty, "local AS %u%s%s, ",
9022 p->change_local_as ? p->change_local_as : p->local_as,
9023 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9024 ? " no-prepend"
9025 : "",
9026 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9027 ? " replace-as"
9028 : "");
9029 }
9030 /* peer type internal, external, confed-internal or confed-external */
9031 if (p->as == p->local_as) {
9032 if (use_json) {
9033 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9034 json_object_boolean_true_add(
9035 json_neigh, "nbrConfedInternalLink");
9036 else
9037 json_object_boolean_true_add(json_neigh,
9038 "nbrInternalLink");
9039 } else {
9040 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9041 vty_out(vty, "confed-internal link\n");
9042 else
9043 vty_out(vty, "internal link\n");
9044 }
9045 } else {
9046 if (use_json) {
9047 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9048 json_object_boolean_true_add(
9049 json_neigh, "nbrConfedExternalLink");
9050 else
9051 json_object_boolean_true_add(json_neigh,
9052 "nbrExternalLink");
9053 } else {
9054 if (bgp_confederation_peers_check(bgp, p->as))
9055 vty_out(vty, "confed-external link\n");
9056 else
9057 vty_out(vty, "external link\n");
9058 }
9059 }
9060
9061 /* Description. */
9062 if (p->desc) {
9063 if (use_json)
9064 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9065 else
9066 vty_out(vty, " Description: %s\n", p->desc);
9067 }
9068
9069 if (p->hostname) {
9070 if (use_json) {
9071 if (p->hostname)
9072 json_object_string_add(json_neigh, "hostname",
9073 p->hostname);
9074
9075 if (p->domainname)
9076 json_object_string_add(json_neigh, "domainname",
9077 p->domainname);
9078 } else {
9079 if (p->domainname && (p->domainname[0] != '\0'))
9080 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9081 p->domainname);
9082 else
9083 vty_out(vty, "Hostname: %s\n", p->hostname);
9084 }
9085 }
9086
9087 /* Peer-group */
9088 if (p->group) {
9089 if (use_json) {
9090 json_object_string_add(json_neigh, "peerGroup",
9091 p->group->name);
9092
9093 if (dn_flag[0]) {
9094 struct prefix prefix, *range = NULL;
9095
9096 sockunion2hostprefix(&(p->su), &prefix);
9097 range = peer_group_lookup_dynamic_neighbor_range(
9098 p->group, &prefix);
9099
9100 if (range) {
9101 prefix2str(range, buf1, sizeof(buf1));
9102 json_object_string_add(
9103 json_neigh,
9104 "peerSubnetRangeGroup", buf1);
9105 }
9106 }
9107 } else {
9108 vty_out(vty,
9109 " Member of peer-group %s for session parameters\n",
9110 p->group->name);
9111
9112 if (dn_flag[0]) {
9113 struct prefix prefix, *range = NULL;
9114
9115 sockunion2hostprefix(&(p->su), &prefix);
9116 range = peer_group_lookup_dynamic_neighbor_range(
9117 p->group, &prefix);
9118
9119 if (range) {
9120 prefix2str(range, buf1, sizeof(buf1));
9121 vty_out(vty,
9122 " Belongs to the subnet range group: %s\n",
9123 buf1);
9124 }
9125 }
9126 }
9127 }
9128
9129 if (use_json) {
9130 /* Administrative shutdown. */
9131 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9132 json_object_boolean_true_add(json_neigh,
9133 "adminShutDown");
9134
9135 /* BGP Version. */
9136 json_object_int_add(json_neigh, "bgpVersion", 4);
9137 json_object_string_add(
9138 json_neigh, "remoteRouterId",
9139 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
9140 json_object_string_add(
9141 json_neigh, "localRouterId",
9142 inet_ntop(AF_INET, &bgp->router_id, buf1,
9143 sizeof(buf1)));
d62a17ae 9144
9145 /* Confederation */
9146 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9147 && bgp_confederation_peers_check(bgp, p->as))
9148 json_object_boolean_true_add(json_neigh,
9149 "nbrCommonAdmin");
9150
9151 /* Status. */
9152 json_object_string_add(
9153 json_neigh, "bgpState",
9154 lookup_msg(bgp_status_msg, p->status, NULL));
9155
9156 if (p->status == Established) {
9157 time_t uptime;
d62a17ae 9158
9159 uptime = bgp_clock();
9160 uptime -= p->uptime;
d62a17ae 9161 epoch_tbuf = time(NULL) - uptime;
9162
bee57a7a 9163#if CONFDATE > 20200101
a4d82a8a
PZ
9164 CPP_NOTICE(
9165 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9166#endif
9167 /*
9168 * bgpTimerUp was miliseconds that was accurate
9169 * up to 1 day, then the value returned
9170 * became garbage. So in order to provide
9171 * some level of backwards compatability,
9172 * we still provde the data, but now
9173 * we are returning the correct value
9174 * and also adding a new bgpTimerUpMsec
9175 * which will allow us to deprecate
9176 * this eventually
9177 */
d62a17ae 9178 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9179 uptime * 1000);
d3c7efed
DS
9180 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9181 uptime * 1000);
d62a17ae 9182 json_object_string_add(json_neigh, "bgpTimerUpString",
9183 peer_uptime(p->uptime, timebuf,
9184 BGP_UPTIME_LEN, 0,
9185 NULL));
9186 json_object_int_add(json_neigh,
9187 "bgpTimerUpEstablishedEpoch",
9188 epoch_tbuf);
9189 }
9190
9191 else if (p->status == Active) {
9192 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9193 json_object_string_add(json_neigh, "bgpStateIs",
9194 "passive");
9195 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9196 json_object_string_add(json_neigh, "bgpStateIs",
9197 "passiveNSF");
9198 }
9199
9200 /* read timer */
9201 time_t uptime;
9202 struct tm *tm;
9203
9204 uptime = bgp_clock();
9205 uptime -= p->readtime;
9206 tm = gmtime(&uptime);
9207 json_object_int_add(json_neigh, "bgpTimerLastRead",
9208 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9209 + (tm->tm_hour * 3600000));
9210
9211 uptime = bgp_clock();
9212 uptime -= p->last_write;
9213 tm = gmtime(&uptime);
9214 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9215 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9216 + (tm->tm_hour * 3600000));
9217
9218 uptime = bgp_clock();
9219 uptime -= p->update_time;
9220 tm = gmtime(&uptime);
9221 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9222 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9223 + (tm->tm_hour * 3600000));
9224
9225 /* Configured timer values. */
9226 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9227 p->v_holdtime * 1000);
9228 json_object_int_add(json_neigh,
9229 "bgpTimerKeepAliveIntervalMsecs",
9230 p->v_keepalive * 1000);
b90a8e13 9231 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9232 json_object_int_add(json_neigh,
9233 "bgpTimerConfiguredHoldTimeMsecs",
9234 p->holdtime * 1000);
9235 json_object_int_add(
9236 json_neigh,
9237 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9238 p->keepalive * 1000);
d25e4efc 9239 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9240 || (bgp->default_keepalive
9241 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9242 json_object_int_add(json_neigh,
9243 "bgpTimerConfiguredHoldTimeMsecs",
9244 bgp->default_holdtime);
9245 json_object_int_add(
9246 json_neigh,
9247 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9248 bgp->default_keepalive);
d62a17ae 9249 }
9250 } else {
9251 /* Administrative shutdown. */
9252 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9253 vty_out(vty, " Administratively shut down\n");
9254
9255 /* BGP Version. */
9256 vty_out(vty, " BGP version 4");
0e38aeb4 9257 vty_out(vty, ", remote router ID %s",
d62a17ae 9258 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
9259 vty_out(vty, ", local router ID %s\n",
9260 inet_ntop(AF_INET, &bgp->router_id, buf1,
9261 sizeof(buf1)));
d62a17ae 9262
9263 /* Confederation */
9264 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9265 && bgp_confederation_peers_check(bgp, p->as))
9266 vty_out(vty,
9267 " Neighbor under common administration\n");
9268
9269 /* Status. */
9270 vty_out(vty, " BGP state = %s",
9271 lookup_msg(bgp_status_msg, p->status, NULL));
9272
9273 if (p->status == Established)
9274 vty_out(vty, ", up for %8s",
9275 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9276 0, NULL));
9277
9278 else if (p->status == Active) {
9279 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9280 vty_out(vty, " (passive)");
9281 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9282 vty_out(vty, " (NSF passive)");
9283 }
9284 vty_out(vty, "\n");
9285
9286 /* read timer */
9287 vty_out(vty, " Last read %s",
9288 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9289 NULL));
9290 vty_out(vty, ", Last write %s\n",
9291 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9292 NULL));
9293
9294 /* Configured timer values. */
9295 vty_out(vty,
9296 " Hold time is %d, keepalive interval is %d seconds\n",
9297 p->v_holdtime, p->v_keepalive);
b90a8e13 9298 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9299 vty_out(vty, " Configured hold time is %d",
9300 p->holdtime);
9301 vty_out(vty, ", keepalive interval is %d seconds\n",
9302 p->keepalive);
d25e4efc 9303 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9304 || (bgp->default_keepalive
9305 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9306 vty_out(vty, " Configured hold time is %d",
9307 bgp->default_holdtime);
9308 vty_out(vty, ", keepalive interval is %d seconds\n",
9309 bgp->default_keepalive);
d62a17ae 9310 }
9311 }
9312 /* Capability. */
9313 if (p->status == Established) {
9314 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9315 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9316 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9317 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9318 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9319 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9320 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9321 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9322 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9323 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9324 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9325 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9326 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9327 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9328 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9329 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9330 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9331 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9332 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9333 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9334 if (use_json) {
9335 json_object *json_cap = NULL;
9336
9337 json_cap = json_object_new_object();
9338
9339 /* AS4 */
9340 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9341 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9342 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9343 && CHECK_FLAG(p->cap,
9344 PEER_CAP_AS4_RCV))
9345 json_object_string_add(
9346 json_cap, "4byteAs",
9347 "advertisedAndReceived");
9348 else if (CHECK_FLAG(p->cap,
9349 PEER_CAP_AS4_ADV))
9350 json_object_string_add(
9351 json_cap, "4byteAs",
9352 "advertised");
9353 else if (CHECK_FLAG(p->cap,
9354 PEER_CAP_AS4_RCV))
9355 json_object_string_add(
9356 json_cap, "4byteAs",
9357 "received");
9358 }
9359
9360 /* AddPath */
9361 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9362 || CHECK_FLAG(p->cap,
9363 PEER_CAP_ADDPATH_ADV)) {
9364 json_object *json_add = NULL;
9365 const char *print_store;
9366
9367 json_add = json_object_new_object();
9368
05c7a1cc
QY
9369 FOREACH_AFI_SAFI (afi, safi) {
9370 json_object *json_sub = NULL;
9371 json_sub =
9372 json_object_new_object();
9373 print_store = afi_safi_print(
9374 afi, safi);
d62a17ae 9375
05c7a1cc
QY
9376 if (CHECK_FLAG(
9377 p->af_cap[afi]
9378 [safi],
9379 PEER_CAP_ADDPATH_AF_TX_ADV)
9380 || CHECK_FLAG(
9381 p->af_cap[afi]
9382 [safi],
9383 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9384 if (CHECK_FLAG(
9385 p->af_cap
9386 [afi]
9387 [safi],
9388 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9389 && CHECK_FLAG(
d62a17ae 9390 p->af_cap
9391 [afi]
9392 [safi],
05c7a1cc
QY
9393 PEER_CAP_ADDPATH_AF_TX_RCV))
9394 json_object_boolean_true_add(
9395 json_sub,
9396 "txAdvertisedAndReceived");
9397 else if (
9398 CHECK_FLAG(
9399 p->af_cap
9400 [afi]
9401 [safi],
9402 PEER_CAP_ADDPATH_AF_TX_ADV))
9403 json_object_boolean_true_add(
9404 json_sub,
9405 "txAdvertised");
9406 else if (
9407 CHECK_FLAG(
9408 p->af_cap
9409 [afi]
9410 [safi],
9411 PEER_CAP_ADDPATH_AF_TX_RCV))
9412 json_object_boolean_true_add(
9413 json_sub,
9414 "txReceived");
9415 }
d62a17ae 9416
05c7a1cc
QY
9417 if (CHECK_FLAG(
9418 p->af_cap[afi]
9419 [safi],
9420 PEER_CAP_ADDPATH_AF_RX_ADV)
9421 || CHECK_FLAG(
9422 p->af_cap[afi]
9423 [safi],
9424 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9425 if (CHECK_FLAG(
9426 p->af_cap
9427 [afi]
9428 [safi],
9429 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9430 && CHECK_FLAG(
d62a17ae 9431 p->af_cap
9432 [afi]
9433 [safi],
9434 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9435 json_object_boolean_true_add(
9436 json_sub,
9437 "rxAdvertisedAndReceived");
9438 else if (
9439 CHECK_FLAG(
9440 p->af_cap
9441 [afi]
9442 [safi],
9443 PEER_CAP_ADDPATH_AF_RX_ADV))
9444 json_object_boolean_true_add(
9445 json_sub,
9446 "rxAdvertised");
9447 else if (
9448 CHECK_FLAG(
9449 p->af_cap
9450 [afi]
9451 [safi],
9452 PEER_CAP_ADDPATH_AF_RX_RCV))
9453 json_object_boolean_true_add(
9454 json_sub,
9455 "rxReceived");
d62a17ae 9456 }
9457
05c7a1cc
QY
9458 if (CHECK_FLAG(
9459 p->af_cap[afi]
9460 [safi],
9461 PEER_CAP_ADDPATH_AF_TX_ADV)
9462 || CHECK_FLAG(
9463 p->af_cap[afi]
9464 [safi],
9465 PEER_CAP_ADDPATH_AF_TX_RCV)
9466 || CHECK_FLAG(
9467 p->af_cap[afi]
9468 [safi],
9469 PEER_CAP_ADDPATH_AF_RX_ADV)
9470 || CHECK_FLAG(
9471 p->af_cap[afi]
9472 [safi],
9473 PEER_CAP_ADDPATH_AF_RX_RCV))
9474 json_object_object_add(
9475 json_add,
9476 print_store,
9477 json_sub);
9478 else
9479 json_object_free(
9480 json_sub);
9481 }
9482
d62a17ae 9483 json_object_object_add(
9484 json_cap, "addPath", json_add);
9485 }
9486
9487 /* Dynamic */
9488 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9489 || CHECK_FLAG(p->cap,
9490 PEER_CAP_DYNAMIC_ADV)) {
9491 if (CHECK_FLAG(p->cap,
9492 PEER_CAP_DYNAMIC_ADV)
9493 && CHECK_FLAG(p->cap,
9494 PEER_CAP_DYNAMIC_RCV))
9495 json_object_string_add(
9496 json_cap, "dynamic",
9497 "advertisedAndReceived");
9498 else if (CHECK_FLAG(
9499 p->cap,
9500 PEER_CAP_DYNAMIC_ADV))
9501 json_object_string_add(
9502 json_cap, "dynamic",
9503 "advertised");
9504 else if (CHECK_FLAG(
9505 p->cap,
9506 PEER_CAP_DYNAMIC_RCV))
9507 json_object_string_add(
9508 json_cap, "dynamic",
9509 "received");
9510 }
9511
9512 /* Extended nexthop */
9513 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9514 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9515 json_object *json_nxt = NULL;
9516 const char *print_store;
9517
9518
9519 if (CHECK_FLAG(p->cap,
9520 PEER_CAP_ENHE_ADV)
9521 && CHECK_FLAG(p->cap,
9522 PEER_CAP_ENHE_RCV))
9523 json_object_string_add(
9524 json_cap,
9525 "extendedNexthop",
9526 "advertisedAndReceived");
9527 else if (CHECK_FLAG(p->cap,
9528 PEER_CAP_ENHE_ADV))
9529 json_object_string_add(
9530 json_cap,
9531 "extendedNexthop",
9532 "advertised");
9533 else if (CHECK_FLAG(p->cap,
9534 PEER_CAP_ENHE_RCV))
9535 json_object_string_add(
9536 json_cap,
9537 "extendedNexthop",
9538 "received");
9539
9540 if (CHECK_FLAG(p->cap,
9541 PEER_CAP_ENHE_RCV)) {
9542 json_nxt =
9543 json_object_new_object();
9544
9545 for (safi = SAFI_UNICAST;
9546 safi < SAFI_MAX; safi++) {
9547 if (CHECK_FLAG(
9548 p->af_cap
9549 [AFI_IP]
9550 [safi],
9551 PEER_CAP_ENHE_AF_RCV)) {
9552 print_store = afi_safi_print(
9553 AFI_IP,
9554 safi);
9555 json_object_string_add(
9556 json_nxt,
9557 print_store,
9558 "recieved");
9559 }
9560 }
9561 json_object_object_add(
9562 json_cap,
9563 "extendedNexthopFamililesByPeer",
9564 json_nxt);
9565 }
9566 }
9567
9568 /* Route Refresh */
9569 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9570 || CHECK_FLAG(p->cap,
9571 PEER_CAP_REFRESH_NEW_RCV)
9572 || CHECK_FLAG(p->cap,
9573 PEER_CAP_REFRESH_OLD_RCV)) {
9574 if (CHECK_FLAG(p->cap,
9575 PEER_CAP_REFRESH_ADV)
9576 && (CHECK_FLAG(
9577 p->cap,
9578 PEER_CAP_REFRESH_NEW_RCV)
9579 || CHECK_FLAG(
9580 p->cap,
9581 PEER_CAP_REFRESH_OLD_RCV))) {
9582 if (CHECK_FLAG(
9583 p->cap,
9584 PEER_CAP_REFRESH_OLD_RCV)
9585 && CHECK_FLAG(
9586 p->cap,
9587 PEER_CAP_REFRESH_NEW_RCV))
9588 json_object_string_add(
9589 json_cap,
9590 "routeRefresh",
9591 "advertisedAndReceivedOldNew");
9592 else {
9593 if (CHECK_FLAG(
9594 p->cap,
9595 PEER_CAP_REFRESH_OLD_RCV))
9596 json_object_string_add(
9597 json_cap,
9598 "routeRefresh",
9599 "advertisedAndReceivedOld");
9600 else
9601 json_object_string_add(
9602 json_cap,
9603 "routeRefresh",
9604 "advertisedAndReceivedNew");
9605 }
9606 } else if (
9607 CHECK_FLAG(
9608 p->cap,
9609 PEER_CAP_REFRESH_ADV))
9610 json_object_string_add(
9611 json_cap,
9612 "routeRefresh",
9613 "advertised");
9614 else if (
9615 CHECK_FLAG(
9616 p->cap,
9617 PEER_CAP_REFRESH_NEW_RCV)
9618 || CHECK_FLAG(
9619 p->cap,
9620 PEER_CAP_REFRESH_OLD_RCV))
9621 json_object_string_add(
9622 json_cap,
9623 "routeRefresh",
9624 "received");
9625 }
9626
9627 /* Multiprotocol Extensions */
9628 json_object *json_multi = NULL;
9629 json_multi = json_object_new_object();
9630
05c7a1cc
QY
9631 FOREACH_AFI_SAFI (afi, safi) {
9632 if (p->afc_adv[afi][safi]
9633 || p->afc_recv[afi][safi]) {
9634 json_object *json_exten = NULL;
9635 json_exten =
9636 json_object_new_object();
9637
d62a17ae 9638 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9639 && p->afc_recv[afi][safi])
9640 json_object_boolean_true_add(
9641 json_exten,
9642 "advertisedAndReceived");
9643 else if (p->afc_adv[afi][safi])
9644 json_object_boolean_true_add(
9645 json_exten,
9646 "advertised");
9647 else if (p->afc_recv[afi][safi])
9648 json_object_boolean_true_add(
9649 json_exten,
9650 "received");
d62a17ae 9651
05c7a1cc
QY
9652 json_object_object_add(
9653 json_multi,
9654 afi_safi_print(afi,
9655 safi),
9656 json_exten);
d62a17ae 9657 }
9658 }
9659 json_object_object_add(
9660 json_cap, "multiprotocolExtensions",
9661 json_multi);
9662
d77114b7 9663 /* Hostname capabilities */
60466a63 9664 json_object *json_hname = NULL;
d77114b7
MK
9665
9666 json_hname = json_object_new_object();
9667
9668 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9669 json_object_string_add(
60466a63
QY
9670 json_hname, "advHostName",
9671 bgp->peer_self->hostname
9672 ? bgp->peer_self
9673 ->hostname
d77114b7
MK
9674 : "n/a");
9675 json_object_string_add(
60466a63
QY
9676 json_hname, "advDomainName",
9677 bgp->peer_self->domainname
9678 ? bgp->peer_self
9679 ->domainname
d77114b7
MK
9680 : "n/a");
9681 }
9682
9683
9684 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9685 json_object_string_add(
60466a63
QY
9686 json_hname, "rcvHostName",
9687 p->hostname ? p->hostname
9688 : "n/a");
d77114b7 9689 json_object_string_add(
60466a63
QY
9690 json_hname, "rcvDomainName",
9691 p->domainname ? p->domainname
9692 : "n/a");
d77114b7
MK
9693 }
9694
60466a63 9695 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9696 json_hname);
9697
d62a17ae 9698 /* Gracefull Restart */
9699 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9700 || CHECK_FLAG(p->cap,
9701 PEER_CAP_RESTART_ADV)) {
9702 if (CHECK_FLAG(p->cap,
9703 PEER_CAP_RESTART_ADV)
9704 && CHECK_FLAG(p->cap,
9705 PEER_CAP_RESTART_RCV))
9706 json_object_string_add(
9707 json_cap,
9708 "gracefulRestart",
9709 "advertisedAndReceived");
9710 else if (CHECK_FLAG(
9711 p->cap,
9712 PEER_CAP_RESTART_ADV))
9713 json_object_string_add(
9714 json_cap,
9715 "gracefulRestartCapability",
9716 "advertised");
9717 else if (CHECK_FLAG(
9718 p->cap,
9719 PEER_CAP_RESTART_RCV))
9720 json_object_string_add(
9721 json_cap,
9722 "gracefulRestartCapability",
9723 "received");
9724
9725 if (CHECK_FLAG(p->cap,
9726 PEER_CAP_RESTART_RCV)) {
9727 int restart_af_count = 0;
9728 json_object *json_restart =
9729 NULL;
9730 json_restart =
9731 json_object_new_object();
9732
9733 json_object_int_add(
9734 json_cap,
9735 "gracefulRestartRemoteTimerMsecs",
9736 p->v_gr_restart * 1000);
9737
05c7a1cc
QY
9738 FOREACH_AFI_SAFI (afi, safi) {
9739 if (CHECK_FLAG(
9740 p->af_cap
9741 [afi]
9742 [safi],
9743 PEER_CAP_RESTART_AF_RCV)) {
9744 json_object *
9745 json_sub =
9746 NULL;
9747 json_sub =
9748 json_object_new_object();
9749
d62a17ae 9750 if (CHECK_FLAG(
9751 p->af_cap
9752 [afi]
9753 [safi],
05c7a1cc
QY
9754 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9755 json_object_boolean_true_add(
9756 json_sub,
9757 "preserved");
9758 restart_af_count++;
9759 json_object_object_add(
9760 json_restart,
9761 afi_safi_print(
9762 afi,
9763 safi),
9764 json_sub);
d62a17ae 9765 }
9766 }
9767 if (!restart_af_count) {
9768 json_object_string_add(
9769 json_cap,
9770 "addressFamiliesByPeer",
9771 "none");
9772 json_object_free(
9773 json_restart);
9774 } else
9775 json_object_object_add(
9776 json_cap,
9777 "addressFamiliesByPeer",
9778 json_restart);
9779 }
9780 }
9781 json_object_object_add(json_neigh,
9782 "neighborCapabilities",
9783 json_cap);
9784 } else {
9785 vty_out(vty, " Neighbor capabilities:\n");
9786
9787 /* AS4 */
9788 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9789 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9790 vty_out(vty, " 4 Byte AS:");
9791 if (CHECK_FLAG(p->cap,
9792 PEER_CAP_AS4_ADV))
9793 vty_out(vty, " advertised");
9794 if (CHECK_FLAG(p->cap,
9795 PEER_CAP_AS4_RCV))
9796 vty_out(vty, " %sreceived",
9797 CHECK_FLAG(
9798 p->cap,
9799 PEER_CAP_AS4_ADV)
9800 ? "and "
9801 : "");
9802 vty_out(vty, "\n");
9803 }
9804
9805 /* AddPath */
9806 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9807 || CHECK_FLAG(p->cap,
9808 PEER_CAP_ADDPATH_ADV)) {
9809 vty_out(vty, " AddPath:\n");
9810
05c7a1cc
QY
9811 FOREACH_AFI_SAFI (afi, safi) {
9812 if (CHECK_FLAG(
9813 p->af_cap[afi]
9814 [safi],
9815 PEER_CAP_ADDPATH_AF_TX_ADV)
9816 || CHECK_FLAG(
9817 p->af_cap[afi]
9818 [safi],
9819 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9820 vty_out(vty,
9821 " %s: TX ",
9822 afi_safi_print(
9823 afi,
9824 safi));
9825
d62a17ae 9826 if (CHECK_FLAG(
9827 p->af_cap
9828 [afi]
9829 [safi],
05c7a1cc 9830 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 9831 vty_out(vty,
05c7a1cc 9832 "advertised %s",
d62a17ae 9833 afi_safi_print(
9834 afi,
9835 safi));
9836
05c7a1cc
QY
9837 if (CHECK_FLAG(
9838 p->af_cap
9839 [afi]
9840 [safi],
9841 PEER_CAP_ADDPATH_AF_TX_RCV))
9842 vty_out(vty,
9843 "%sreceived",
9844 CHECK_FLAG(
9845 p->af_cap
9846 [afi]
9847 [safi],
9848 PEER_CAP_ADDPATH_AF_TX_ADV)
9849 ? " and "
9850 : "");
d62a17ae 9851
05c7a1cc
QY
9852 vty_out(vty, "\n");
9853 }
d62a17ae 9854
05c7a1cc
QY
9855 if (CHECK_FLAG(
9856 p->af_cap[afi]
9857 [safi],
9858 PEER_CAP_ADDPATH_AF_RX_ADV)
9859 || CHECK_FLAG(
9860 p->af_cap[afi]
9861 [safi],
9862 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9863 vty_out(vty,
9864 " %s: RX ",
9865 afi_safi_print(
9866 afi,
9867 safi));
d62a17ae 9868
9869 if (CHECK_FLAG(
9870 p->af_cap
9871 [afi]
9872 [safi],
05c7a1cc 9873 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 9874 vty_out(vty,
05c7a1cc 9875 "advertised %s",
d62a17ae 9876 afi_safi_print(
9877 afi,
9878 safi));
9879
05c7a1cc
QY
9880 if (CHECK_FLAG(
9881 p->af_cap
9882 [afi]
9883 [safi],
9884 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 9885 vty_out(vty,
05c7a1cc
QY
9886 "%sreceived",
9887 CHECK_FLAG(
9888 p->af_cap
9889 [afi]
9890 [safi],
9891 PEER_CAP_ADDPATH_AF_RX_ADV)
9892 ? " and "
9893 : "");
9894
9895 vty_out(vty, "\n");
d62a17ae 9896 }
05c7a1cc 9897 }
d62a17ae 9898 }
9899
9900 /* Dynamic */
9901 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9902 || CHECK_FLAG(p->cap,
9903 PEER_CAP_DYNAMIC_ADV)) {
9904 vty_out(vty, " Dynamic:");
9905 if (CHECK_FLAG(p->cap,
9906 PEER_CAP_DYNAMIC_ADV))
9907 vty_out(vty, " advertised");
9908 if (CHECK_FLAG(p->cap,
9909 PEER_CAP_DYNAMIC_RCV))
9910 vty_out(vty, " %sreceived",
9911 CHECK_FLAG(
9912 p->cap,
9913 PEER_CAP_DYNAMIC_ADV)
9914 ? "and "
9915 : "");
9916 vty_out(vty, "\n");
9917 }
9918
9919 /* Extended nexthop */
9920 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9921 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9922 vty_out(vty, " Extended nexthop:");
9923 if (CHECK_FLAG(p->cap,
9924 PEER_CAP_ENHE_ADV))
9925 vty_out(vty, " advertised");
9926 if (CHECK_FLAG(p->cap,
9927 PEER_CAP_ENHE_RCV))
9928 vty_out(vty, " %sreceived",
9929 CHECK_FLAG(
9930 p->cap,
9931 PEER_CAP_ENHE_ADV)
9932 ? "and "
9933 : "");
9934 vty_out(vty, "\n");
9935
9936 if (CHECK_FLAG(p->cap,
9937 PEER_CAP_ENHE_RCV)) {
9938 vty_out(vty,
9939 " Address families by peer:\n ");
9940 for (safi = SAFI_UNICAST;
9941 safi < SAFI_MAX; safi++)
9942 if (CHECK_FLAG(
9943 p->af_cap
9944 [AFI_IP]
9945 [safi],
9946 PEER_CAP_ENHE_AF_RCV))
9947 vty_out(vty,
9948 " %s\n",
9949 afi_safi_print(
9950 AFI_IP,
9951 safi));
9952 }
9953 }
9954
9955 /* Route Refresh */
9956 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9957 || CHECK_FLAG(p->cap,
9958 PEER_CAP_REFRESH_NEW_RCV)
9959 || CHECK_FLAG(p->cap,
9960 PEER_CAP_REFRESH_OLD_RCV)) {
9961 vty_out(vty, " Route refresh:");
9962 if (CHECK_FLAG(p->cap,
9963 PEER_CAP_REFRESH_ADV))
9964 vty_out(vty, " advertised");
9965 if (CHECK_FLAG(p->cap,
9966 PEER_CAP_REFRESH_NEW_RCV)
9967 || CHECK_FLAG(
9968 p->cap,
9969 PEER_CAP_REFRESH_OLD_RCV))
9970 vty_out(vty, " %sreceived(%s)",
9971 CHECK_FLAG(
9972 p->cap,
9973 PEER_CAP_REFRESH_ADV)
9974 ? "and "
9975 : "",
9976 (CHECK_FLAG(
9977 p->cap,
9978 PEER_CAP_REFRESH_OLD_RCV)
9979 && CHECK_FLAG(
9980 p->cap,
9981 PEER_CAP_REFRESH_NEW_RCV))
9982 ? "old & new"
9983 : CHECK_FLAG(
9984 p->cap,
9985 PEER_CAP_REFRESH_OLD_RCV)
9986 ? "old"
9987 : "new");
9988
9989 vty_out(vty, "\n");
9990 }
9991
9992 /* Multiprotocol Extensions */
05c7a1cc
QY
9993 FOREACH_AFI_SAFI (afi, safi)
9994 if (p->afc_adv[afi][safi]
9995 || p->afc_recv[afi][safi]) {
9996 vty_out(vty,
9997 " Address Family %s:",
9998 afi_safi_print(afi,
9999 safi));
10000 if (p->afc_adv[afi][safi])
d62a17ae 10001 vty_out(vty,
05c7a1cc
QY
10002 " advertised");
10003 if (p->afc_recv[afi][safi])
10004 vty_out(vty,
10005 " %sreceived",
10006 p->afc_adv[afi]
10007 [safi]
10008 ? "and "
10009 : "");
10010 vty_out(vty, "\n");
10011 }
d62a17ae 10012
10013 /* Hostname capability */
60466a63 10014 vty_out(vty, " Hostname Capability:");
d77114b7
MK
10015
10016 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
10017 vty_out(vty,
10018 " advertised (name: %s,domain name: %s)",
60466a63
QY
10019 bgp->peer_self->hostname
10020 ? bgp->peer_self
10021 ->hostname
d77114b7 10022 : "n/a",
60466a63
QY
10023 bgp->peer_self->domainname
10024 ? bgp->peer_self
10025 ->domainname
d77114b7
MK
10026 : "n/a");
10027 } else {
10028 vty_out(vty, " not advertised");
d62a17ae 10029 }
10030
d77114b7 10031 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10032 vty_out(vty,
10033 " received (name: %s,domain name: %s)",
60466a63
QY
10034 p->hostname ? p->hostname
10035 : "n/a",
10036 p->domainname ? p->domainname
10037 : "n/a");
d77114b7
MK
10038 } else {
10039 vty_out(vty, " not received");
10040 }
10041
10042 vty_out(vty, "\n");
10043
d62a17ae 10044 /* Gracefull Restart */
10045 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10046 || CHECK_FLAG(p->cap,
10047 PEER_CAP_RESTART_ADV)) {
10048 vty_out(vty,
10049 " Graceful Restart Capabilty:");
10050 if (CHECK_FLAG(p->cap,
10051 PEER_CAP_RESTART_ADV))
10052 vty_out(vty, " advertised");
10053 if (CHECK_FLAG(p->cap,
10054 PEER_CAP_RESTART_RCV))
10055 vty_out(vty, " %sreceived",
10056 CHECK_FLAG(
10057 p->cap,
10058 PEER_CAP_RESTART_ADV)
10059 ? "and "
10060 : "");
10061 vty_out(vty, "\n");
10062
10063 if (CHECK_FLAG(p->cap,
10064 PEER_CAP_RESTART_RCV)) {
10065 int restart_af_count = 0;
10066
10067 vty_out(vty,
10068 " Remote Restart timer is %d seconds\n",
10069 p->v_gr_restart);
10070 vty_out(vty,
10071 " Address families by peer:\n ");
10072
05c7a1cc
QY
10073 FOREACH_AFI_SAFI (afi, safi)
10074 if (CHECK_FLAG(
10075 p->af_cap
10076 [afi]
10077 [safi],
10078 PEER_CAP_RESTART_AF_RCV)) {
10079 vty_out(vty,
10080 "%s%s(%s)",
10081 restart_af_count
10082 ? ", "
10083 : "",
10084 afi_safi_print(
10085 afi,
10086 safi),
10087 CHECK_FLAG(
10088 p->af_cap
10089 [afi]
10090 [safi],
10091 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10092 ? "preserved"
10093 : "not preserved");
10094 restart_af_count++;
10095 }
d62a17ae 10096 if (!restart_af_count)
10097 vty_out(vty, "none");
10098 vty_out(vty, "\n");
10099 }
10100 }
10101 }
10102 }
10103 }
10104
10105 /* graceful restart information */
10106 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10107 || p->t_gr_stale) {
10108 json_object *json_grace = NULL;
10109 json_object *json_grace_send = NULL;
10110 json_object *json_grace_recv = NULL;
10111 int eor_send_af_count = 0;
10112 int eor_receive_af_count = 0;
10113
10114 if (use_json) {
10115 json_grace = json_object_new_object();
10116 json_grace_send = json_object_new_object();
10117 json_grace_recv = json_object_new_object();
10118
10119 if (p->status == Established) {
05c7a1cc
QY
10120 FOREACH_AFI_SAFI (afi, safi) {
10121 if (CHECK_FLAG(p->af_sflags[afi][safi],
10122 PEER_STATUS_EOR_SEND)) {
10123 json_object_boolean_true_add(
10124 json_grace_send,
10125 afi_safi_print(afi,
10126 safi));
10127 eor_send_af_count++;
d62a17ae 10128 }
10129 }
05c7a1cc
QY
10130 FOREACH_AFI_SAFI (afi, safi) {
10131 if (CHECK_FLAG(
10132 p->af_sflags[afi][safi],
10133 PEER_STATUS_EOR_RECEIVED)) {
10134 json_object_boolean_true_add(
10135 json_grace_recv,
10136 afi_safi_print(afi,
10137 safi));
10138 eor_receive_af_count++;
d62a17ae 10139 }
10140 }
10141 }
10142
10143 json_object_object_add(json_grace, "endOfRibSend",
10144 json_grace_send);
10145 json_object_object_add(json_grace, "endOfRibRecv",
10146 json_grace_recv);
10147
10148 if (p->t_gr_restart)
10149 json_object_int_add(json_grace,
10150 "gracefulRestartTimerMsecs",
10151 thread_timer_remain_second(
10152 p->t_gr_restart)
10153 * 1000);
10154
10155 if (p->t_gr_stale)
10156 json_object_int_add(
10157 json_grace,
10158 "gracefulStalepathTimerMsecs",
10159 thread_timer_remain_second(
10160 p->t_gr_stale)
10161 * 1000);
10162
10163 json_object_object_add(
10164 json_neigh, "gracefulRestartInfo", json_grace);
10165 } else {
10166 vty_out(vty, " Graceful restart informations:\n");
10167 if (p->status == Established) {
10168 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10169 FOREACH_AFI_SAFI (afi, safi) {
10170 if (CHECK_FLAG(p->af_sflags[afi][safi],
10171 PEER_STATUS_EOR_SEND)) {
10172 vty_out(vty, "%s%s",
10173 eor_send_af_count ? ", "
10174 : "",
10175 afi_safi_print(afi,
10176 safi));
10177 eor_send_af_count++;
d62a17ae 10178 }
10179 }
10180 vty_out(vty, "\n");
10181 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10182 FOREACH_AFI_SAFI (afi, safi) {
10183 if (CHECK_FLAG(
10184 p->af_sflags[afi][safi],
10185 PEER_STATUS_EOR_RECEIVED)) {
10186 vty_out(vty, "%s%s",
10187 eor_receive_af_count
10188 ? ", "
10189 : "",
10190 afi_safi_print(afi,
10191 safi));
10192 eor_receive_af_count++;
d62a17ae 10193 }
10194 }
10195 vty_out(vty, "\n");
10196 }
10197
10198 if (p->t_gr_restart)
10199 vty_out(vty,
10200 " The remaining time of restart timer is %ld\n",
10201 thread_timer_remain_second(
10202 p->t_gr_restart));
10203
10204 if (p->t_gr_stale)
10205 vty_out(vty,
10206 " The remaining time of stalepath timer is %ld\n",
10207 thread_timer_remain_second(
10208 p->t_gr_stale));
10209 }
10210 }
10211 if (use_json) {
10212 json_object *json_stat = NULL;
10213 json_stat = json_object_new_object();
10214 /* Packet counts. */
10215 json_object_int_add(json_stat, "depthInq", 0);
10216 json_object_int_add(json_stat, "depthOutq",
10217 (unsigned long)p->obuf->count);
0112e9e0
QY
10218 json_object_int_add(json_stat, "opensSent",
10219 atomic_load_explicit(&p->open_out,
10220 memory_order_relaxed));
10221 json_object_int_add(json_stat, "opensRecv",
10222 atomic_load_explicit(&p->open_in,
10223 memory_order_relaxed));
d62a17ae 10224 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10225 atomic_load_explicit(&p->notify_out,
10226 memory_order_relaxed));
d62a17ae 10227 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10228 atomic_load_explicit(&p->notify_in,
10229 memory_order_relaxed));
10230 json_object_int_add(json_stat, "updatesSent",
10231 atomic_load_explicit(&p->update_out,
10232 memory_order_relaxed));
10233 json_object_int_add(json_stat, "updatesRecv",
10234 atomic_load_explicit(&p->update_in,
10235 memory_order_relaxed));
d62a17ae 10236 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10237 atomic_load_explicit(&p->keepalive_out,
10238 memory_order_relaxed));
d62a17ae 10239 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10240 atomic_load_explicit(&p->keepalive_in,
10241 memory_order_relaxed));
d62a17ae 10242 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10243 atomic_load_explicit(&p->refresh_out,
10244 memory_order_relaxed));
d62a17ae 10245 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10246 atomic_load_explicit(&p->refresh_in,
10247 memory_order_relaxed));
d62a17ae 10248 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10249 atomic_load_explicit(&p->dynamic_cap_out,
10250 memory_order_relaxed));
d62a17ae 10251 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10252 atomic_load_explicit(&p->dynamic_cap_in,
10253 memory_order_relaxed));
10254 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10255 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10256 json_object_object_add(json_neigh, "messageStats", json_stat);
10257 } else {
10258 /* Packet counts. */
10259 vty_out(vty, " Message statistics:\n");
10260 vty_out(vty, " Inq depth is 0\n");
10261 vty_out(vty, " Outq depth is %lu\n",
10262 (unsigned long)p->obuf->count);
10263 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10264 vty_out(vty, " Opens: %10d %10d\n",
10265 atomic_load_explicit(&p->open_out,
10266 memory_order_relaxed),
10267 atomic_load_explicit(&p->open_in,
10268 memory_order_relaxed));
10269 vty_out(vty, " Notifications: %10d %10d\n",
10270 atomic_load_explicit(&p->notify_out,
10271 memory_order_relaxed),
10272 atomic_load_explicit(&p->notify_in,
10273 memory_order_relaxed));
10274 vty_out(vty, " Updates: %10d %10d\n",
10275 atomic_load_explicit(&p->update_out,
10276 memory_order_relaxed),
10277 atomic_load_explicit(&p->update_in,
10278 memory_order_relaxed));
10279 vty_out(vty, " Keepalives: %10d %10d\n",
10280 atomic_load_explicit(&p->keepalive_out,
10281 memory_order_relaxed),
10282 atomic_load_explicit(&p->keepalive_in,
10283 memory_order_relaxed));
10284 vty_out(vty, " Route Refresh: %10d %10d\n",
10285 atomic_load_explicit(&p->refresh_out,
10286 memory_order_relaxed),
10287 atomic_load_explicit(&p->refresh_in,
10288 memory_order_relaxed));
d62a17ae 10289 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10290 atomic_load_explicit(&p->dynamic_cap_out,
10291 memory_order_relaxed),
10292 atomic_load_explicit(&p->dynamic_cap_in,
10293 memory_order_relaxed));
10294 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10295 PEER_TOTAL_RX(p));
d62a17ae 10296 }
10297
10298 if (use_json) {
10299 /* advertisement-interval */
10300 json_object_int_add(json_neigh,
10301 "minBtwnAdvertisementRunsTimerMsecs",
10302 p->v_routeadv * 1000);
10303
10304 /* Update-source. */
10305 if (p->update_if || p->update_source) {
10306 if (p->update_if)
10307 json_object_string_add(json_neigh,
10308 "updateSource",
10309 p->update_if);
10310 else if (p->update_source)
10311 json_object_string_add(
10312 json_neigh, "updateSource",
10313 sockunion2str(p->update_source, buf1,
10314 SU_ADDRSTRLEN));
10315 }
10316 } else {
10317 /* advertisement-interval */
10318 vty_out(vty,
10319 " Minimum time between advertisement runs is %d seconds\n",
10320 p->v_routeadv);
10321
10322 /* Update-source. */
10323 if (p->update_if || p->update_source) {
10324 vty_out(vty, " Update source is ");
10325 if (p->update_if)
10326 vty_out(vty, "%s", p->update_if);
10327 else if (p->update_source)
10328 vty_out(vty, "%s",
10329 sockunion2str(p->update_source, buf1,
10330 SU_ADDRSTRLEN));
10331 vty_out(vty, "\n");
10332 }
10333
10334 vty_out(vty, "\n");
10335 }
10336
10337 /* Address Family Information */
10338 json_object *json_hold = NULL;
10339
10340 if (use_json)
10341 json_hold = json_object_new_object();
10342
05c7a1cc
QY
10343 FOREACH_AFI_SAFI (afi, safi)
10344 if (p->afc[afi][safi])
10345 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10346 json_hold);
d62a17ae 10347
10348 if (use_json) {
10349 json_object_object_add(json_neigh, "addressFamilyInfo",
10350 json_hold);
10351 json_object_int_add(json_neigh, "connectionsEstablished",
10352 p->established);
10353 json_object_int_add(json_neigh, "connectionsDropped",
10354 p->dropped);
10355 } else
10356 vty_out(vty, " Connections established %d; dropped %d\n",
10357 p->established, p->dropped);
10358
10359 if (!p->last_reset) {
10360 if (use_json)
10361 json_object_string_add(json_neigh, "lastReset",
10362 "never");
10363 else
10364 vty_out(vty, " Last reset never\n");
10365 } else {
10366 if (use_json) {
10367 time_t uptime;
10368 struct tm *tm;
10369
10370 uptime = bgp_clock();
10371 uptime -= p->resettime;
10372 tm = gmtime(&uptime);
10373 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10374 (tm->tm_sec * 1000)
10375 + (tm->tm_min * 60000)
10376 + (tm->tm_hour * 3600000));
10377 json_object_string_add(
10378 json_neigh, "lastResetDueTo",
10379 peer_down_str[(int)p->last_reset]);
10380 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10381 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10382 char errorcodesubcode_hexstr[5];
10383 char errorcodesubcode_str[256];
10384
10385 code_str = bgp_notify_code_str(p->notify.code);
10386 subcode_str = bgp_notify_subcode_str(
10387 p->notify.code, p->notify.subcode);
10388
10389 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10390 p->notify.code, p->notify.subcode);
10391 json_object_string_add(json_neigh,
10392 "lastErrorCodeSubcode",
10393 errorcodesubcode_hexstr);
10394 snprintf(errorcodesubcode_str, 255, "%s%s",
10395 code_str, subcode_str);
10396 json_object_string_add(json_neigh,
10397 "lastNotificationReason",
10398 errorcodesubcode_str);
10399 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10400 && p->notify.code == BGP_NOTIFY_CEASE
10401 && (p->notify.subcode
10402 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10403 || p->notify.subcode
10404 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10405 && p->notify.length) {
10406 char msgbuf[1024];
10407 const char *msg_str;
10408
10409 msg_str = bgp_notify_admin_message(
10410 msgbuf, sizeof(msgbuf),
d7c0a89a 10411 (uint8_t *)p->notify.data,
d62a17ae 10412 p->notify.length);
10413 if (msg_str)
10414 json_object_string_add(
10415 json_neigh,
10416 "lastShutdownDescription",
10417 msg_str);
10418 }
10419 }
10420 } else {
10421 vty_out(vty, " Last reset %s, ",
10422 peer_uptime(p->resettime, timebuf,
10423 BGP_UPTIME_LEN, 0, NULL));
10424
10425 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10426 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10427 code_str = bgp_notify_code_str(p->notify.code);
10428 subcode_str = bgp_notify_subcode_str(
10429 p->notify.code, p->notify.subcode);
10430 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10431 p->last_reset == PEER_DOWN_NOTIFY_SEND
10432 ? "sent"
10433 : "received",
10434 code_str, subcode_str);
10435 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10436 && p->notify.code == BGP_NOTIFY_CEASE
10437 && (p->notify.subcode
10438 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10439 || p->notify.subcode
10440 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10441 && p->notify.length) {
10442 char msgbuf[1024];
10443 const char *msg_str;
10444
10445 msg_str = bgp_notify_admin_message(
10446 msgbuf, sizeof(msgbuf),
d7c0a89a 10447 (uint8_t *)p->notify.data,
d62a17ae 10448 p->notify.length);
10449 if (msg_str)
10450 vty_out(vty,
10451 " Message: \"%s\"\n",
10452 msg_str);
10453 }
10454 } else {
10455 vty_out(vty, "due to %s\n",
10456 peer_down_str[(int)p->last_reset]);
10457 }
10458
10459 if (p->last_reset_cause_size) {
10460 msg = p->last_reset_cause;
10461 vty_out(vty,
10462 " Message received that caused BGP to send a NOTIFICATION:\n ");
10463 for (i = 1; i <= p->last_reset_cause_size;
10464 i++) {
10465 vty_out(vty, "%02X", *msg++);
10466
10467 if (i != p->last_reset_cause_size) {
10468 if (i % 16 == 0) {
10469 vty_out(vty, "\n ");
10470 } else if (i % 4 == 0) {
10471 vty_out(vty, " ");
10472 }
10473 }
10474 }
10475 vty_out(vty, "\n");
10476 }
10477 }
10478 }
10479
10480 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10481 if (use_json)
10482 json_object_boolean_true_add(json_neigh,
10483 "prefixesConfigExceedMax");
10484 else
10485 vty_out(vty,
10486 " Peer had exceeded the max. no. of prefixes configured.\n");
10487
10488 if (p->t_pmax_restart) {
10489 if (use_json) {
10490 json_object_boolean_true_add(
10491 json_neigh, "reducePrefixNumFrom");
10492 json_object_int_add(json_neigh,
10493 "restartInTimerMsec",
10494 thread_timer_remain_second(
10495 p->t_pmax_restart)
10496 * 1000);
10497 } else
10498 vty_out(vty,
10499 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10500 p->host, thread_timer_remain_second(
10501 p->t_pmax_restart));
d62a17ae 10502 } else {
10503 if (use_json)
10504 json_object_boolean_true_add(
10505 json_neigh,
10506 "reducePrefixNumAndClearIpBgp");
10507 else
10508 vty_out(vty,
10509 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10510 p->host);
10511 }
10512 }
10513
10514 /* EBGP Multihop and GTSM */
10515 if (p->sort != BGP_PEER_IBGP) {
10516 if (use_json) {
10517 if (p->gtsm_hops > 0)
10518 json_object_int_add(json_neigh,
10519 "externalBgpNbrMaxHopsAway",
10520 p->gtsm_hops);
10521 else if (p->ttl > 1)
10522 json_object_int_add(json_neigh,
10523 "externalBgpNbrMaxHopsAway",
10524 p->ttl);
10525 } else {
10526 if (p->gtsm_hops > 0)
10527 vty_out(vty,
10528 " External BGP neighbor may be up to %d hops away.\n",
10529 p->gtsm_hops);
10530 else if (p->ttl > 1)
10531 vty_out(vty,
10532 " External BGP neighbor may be up to %d hops away.\n",
10533 p->ttl);
10534 }
10535 } else {
10536 if (p->gtsm_hops > 0) {
10537 if (use_json)
10538 json_object_int_add(json_neigh,
10539 "internalBgpNbrMaxHopsAway",
10540 p->gtsm_hops);
10541 else
10542 vty_out(vty,
10543 " Internal BGP neighbor may be up to %d hops away.\n",
10544 p->gtsm_hops);
10545 }
10546 }
10547
10548 /* Local address. */
10549 if (p->su_local) {
10550 if (use_json) {
10551 json_object_string_add(json_neigh, "hostLocal",
10552 sockunion2str(p->su_local, buf1,
10553 SU_ADDRSTRLEN));
10554 json_object_int_add(json_neigh, "portLocal",
10555 ntohs(p->su_local->sin.sin_port));
10556 } else
10557 vty_out(vty, "Local host: %s, Local port: %d\n",
10558 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10559 ntohs(p->su_local->sin.sin_port));
10560 }
10561
10562 /* Remote address. */
10563 if (p->su_remote) {
10564 if (use_json) {
10565 json_object_string_add(json_neigh, "hostForeign",
10566 sockunion2str(p->su_remote, buf1,
10567 SU_ADDRSTRLEN));
10568 json_object_int_add(json_neigh, "portForeign",
10569 ntohs(p->su_remote->sin.sin_port));
10570 } else
10571 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10572 sockunion2str(p->su_remote, buf1,
10573 SU_ADDRSTRLEN),
10574 ntohs(p->su_remote->sin.sin_port));
10575 }
10576
10577 /* Nexthop display. */
10578 if (p->su_local) {
10579 if (use_json) {
10580 json_object_string_add(json_neigh, "nexthop",
10581 inet_ntop(AF_INET,
10582 &p->nexthop.v4, buf1,
10583 sizeof(buf1)));
10584 json_object_string_add(json_neigh, "nexthopGlobal",
10585 inet_ntop(AF_INET6,
10586 &p->nexthop.v6_global,
10587 buf1, sizeof(buf1)));
10588 json_object_string_add(json_neigh, "nexthopLocal",
10589 inet_ntop(AF_INET6,
10590 &p->nexthop.v6_local,
10591 buf1, sizeof(buf1)));
10592 if (p->shared_network)
10593 json_object_string_add(json_neigh,
10594 "bgpConnection",
10595 "sharedNetwork");
10596 else
10597 json_object_string_add(json_neigh,
10598 "bgpConnection",
10599 "nonSharedNetwork");
10600 } else {
10601 vty_out(vty, "Nexthop: %s\n",
10602 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10603 sizeof(buf1)));
10604 vty_out(vty, "Nexthop global: %s\n",
10605 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10606 sizeof(buf1)));
10607 vty_out(vty, "Nexthop local: %s\n",
10608 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10609 sizeof(buf1)));
10610 vty_out(vty, "BGP connection: %s\n",
10611 p->shared_network ? "shared network"
10612 : "non shared network");
10613 }
10614 }
10615
10616 /* Timer information. */
10617 if (use_json) {
10618 json_object_int_add(json_neigh, "connectRetryTimer",
10619 p->v_connect);
10620 if (p->status == Established && p->rtt)
10621 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10622 p->rtt);
10623 if (p->t_start)
10624 json_object_int_add(
10625 json_neigh, "nextStartTimerDueInMsecs",
10626 thread_timer_remain_second(p->t_start) * 1000);
10627 if (p->t_connect)
10628 json_object_int_add(
10629 json_neigh, "nextConnectTimerDueInMsecs",
10630 thread_timer_remain_second(p->t_connect)
10631 * 1000);
10632 if (p->t_routeadv) {
10633 json_object_int_add(json_neigh, "mraiInterval",
10634 p->v_routeadv);
10635 json_object_int_add(
10636 json_neigh, "mraiTimerExpireInMsecs",
10637 thread_timer_remain_second(p->t_routeadv)
10638 * 1000);
10639 }
10640 if (p->password)
10641 json_object_int_add(json_neigh, "authenticationEnabled",
10642 1);
10643
10644 if (p->t_read)
10645 json_object_string_add(json_neigh, "readThread", "on");
10646 else
10647 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10648
10649 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10650 json_object_string_add(json_neigh, "writeThread", "on");
10651 else
10652 json_object_string_add(json_neigh, "writeThread",
10653 "off");
10654 } else {
10655 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10656 p->v_connect);
10657 if (p->status == Established && p->rtt)
10658 vty_out(vty, "Estimated round trip time: %d ms\n",
10659 p->rtt);
10660 if (p->t_start)
10661 vty_out(vty, "Next start timer due in %ld seconds\n",
10662 thread_timer_remain_second(p->t_start));
10663 if (p->t_connect)
10664 vty_out(vty, "Next connect timer due in %ld seconds\n",
10665 thread_timer_remain_second(p->t_connect));
10666 if (p->t_routeadv)
10667 vty_out(vty,
10668 "MRAI (interval %u) timer expires in %ld seconds\n",
10669 p->v_routeadv,
10670 thread_timer_remain_second(p->t_routeadv));
10671 if (p->password)
10672 vty_out(vty, "Peer Authentication Enabled\n");
10673
10674 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10675 p->t_read ? "on" : "off",
10676 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10677 ? "on"
10678 : "off");
d62a17ae 10679 }
10680
10681 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10682 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10683 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10684
10685 if (!use_json)
10686 vty_out(vty, "\n");
10687
10688 /* BFD information. */
10689 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10690
10691 if (use_json) {
10692 if (p->conf_if) /* Configured interface name. */
10693 json_object_object_add(json, p->conf_if, json_neigh);
10694 else /* Configured IP address. */
10695 json_object_object_add(json, p->host, json_neigh);
10696 }
10697}
10698
10699static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10700 enum show_type type, union sockunion *su,
9f049418 10701 const char *conf_if, bool use_json,
d62a17ae 10702 json_object *json)
10703{
10704 struct listnode *node, *nnode;
10705 struct peer *peer;
10706 int find = 0;
9f049418 10707 bool nbr_output = false;
d62a17ae 10708
10709 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10710 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10711 continue;
10712
10713 switch (type) {
10714 case show_all:
10715 bgp_show_peer(vty, peer, use_json, json);
9f049418 10716 nbr_output = true;
d62a17ae 10717 break;
10718 case show_peer:
10719 if (conf_if) {
10720 if ((peer->conf_if
10721 && !strcmp(peer->conf_if, conf_if))
10722 || (peer->hostname
10723 && !strcmp(peer->hostname, conf_if))) {
10724 find = 1;
10725 bgp_show_peer(vty, peer, use_json,
10726 json);
10727 }
10728 } else {
10729 if (sockunion_same(&peer->su, su)) {
10730 find = 1;
10731 bgp_show_peer(vty, peer, use_json,
10732 json);
10733 }
10734 }
10735 break;
10736 }
10737 }
10738
10739 if (type == show_peer && !find) {
10740 if (use_json)
10741 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10742 else
88b7d255 10743 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 10744 }
10745
9f049418 10746 if (type != show_peer && !nbr_output && !use_json)
94d4c685 10747 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 10748
d62a17ae 10749 if (use_json) {
996c9314
LB
10750 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10751 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10752 json_object_free(json);
10753 } else {
10754 vty_out(vty, "\n");
10755 }
10756
10757 return CMD_SUCCESS;
10758}
10759
10760static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10761 enum show_type type,
10762 const char *ip_str,
9f049418 10763 bool use_json)
d62a17ae 10764{
0291c246
MK
10765 struct listnode *node, *nnode;
10766 struct bgp *bgp;
71aedaa3 10767 union sockunion su;
0291c246 10768 json_object *json = NULL;
71aedaa3 10769 int ret, is_first = 1;
9f049418 10770 bool nbr_output = false;
d62a17ae 10771
10772 if (use_json)
10773 vty_out(vty, "{\n");
10774
10775 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10776 nbr_output = true;
d62a17ae 10777 if (use_json) {
10778 if (!(json = json_object_new_object())) {
af4c2728 10779 flog_err(
14454c9f 10780 BGP_ERR_JSON_MEM_ERROR,
d62a17ae 10781 "Unable to allocate memory for JSON object");
10782 vty_out(vty,
10783 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10784 return;
10785 }
10786
10787 json_object_int_add(json, "vrfId",
10788 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10789 ? -1
10790 : (int64_t)bgp->vrf_id);
d62a17ae 10791 json_object_string_add(
10792 json, "vrfName",
10793 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10794 ? "Default"
10795 : bgp->name);
10796
10797 if (!is_first)
10798 vty_out(vty, ",\n");
10799 else
10800 is_first = 0;
10801
10802 vty_out(vty, "\"%s\":",
10803 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10804 ? "Default"
10805 : bgp->name);
10806 } else {
10807 vty_out(vty, "\nInstance %s:\n",
10808 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10809 ? "Default"
10810 : bgp->name);
10811 }
71aedaa3
DS
10812
10813 if (type == show_peer) {
10814 ret = str2sockunion(ip_str, &su);
10815 if (ret < 0)
10816 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10817 use_json, json);
10818 else
10819 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10820 use_json, json);
10821 } else {
10822 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10823 use_json, json);
10824 }
d62a17ae 10825 }
10826
10827 if (use_json)
10828 vty_out(vty, "}\n");
9f049418
DS
10829 else if (!nbr_output)
10830 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 10831}
10832
10833static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10834 enum show_type type, const char *ip_str,
9f049418 10835 bool use_json)
d62a17ae 10836{
10837 int ret;
10838 struct bgp *bgp;
10839 union sockunion su;
10840 json_object *json = NULL;
10841
10842 if (name) {
10843 if (strmatch(name, "all")) {
71aedaa3
DS
10844 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10845 use_json);
d62a17ae 10846 return CMD_SUCCESS;
10847 } else {
10848 bgp = bgp_lookup_by_name(name);
10849 if (!bgp) {
10850 if (use_json) {
10851 json = json_object_new_object();
d62a17ae 10852 vty_out(vty, "%s\n",
10853 json_object_to_json_string_ext(
10854 json,
10855 JSON_C_TO_STRING_PRETTY));
10856 json_object_free(json);
10857 } else
10858 vty_out(vty,
9f049418 10859 "%% BGP instance not found\n");
d62a17ae 10860
10861 return CMD_WARNING;
10862 }
10863 }
10864 } else {
10865 bgp = bgp_get_default();
10866 }
10867
10868 if (bgp) {
10869 json = json_object_new_object();
10870 if (ip_str) {
10871 ret = str2sockunion(ip_str, &su);
10872 if (ret < 0)
10873 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10874 use_json, json);
10875 else
10876 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10877 use_json, json);
10878 } else {
10879 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10880 json);
10881 }
10882 json_object_free(json);
9f049418
DS
10883 } else {
10884 use_json ? vty_out(vty, "{}\n")
10885 : vty_out(vty, "%% BGP instance not found\n");
d62a17ae 10886 }
10887
10888 return CMD_SUCCESS;
4fb25c53
DW
10889}
10890
716b2d8a 10891/* "show [ip] bgp neighbors" commands. */
718e3744 10892DEFUN (show_ip_bgp_neighbors,
10893 show_ip_bgp_neighbors_cmd,
24345e82 10894 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 10895 SHOW_STR
10896 IP_STR
10897 BGP_STR
f2a8972b 10898 BGP_INSTANCE_HELP_STR
8c3deaae
QY
10899 "Address Family\n"
10900 "Address Family\n"
718e3744 10901 "Detailed information on TCP and BGP neighbor connections\n"
10902 "Neighbor to display information about\n"
a80beece 10903 "Neighbor to display information about\n"
91d37724 10904 "Neighbor on BGP configured interface\n"
9973d184 10905 JSON_STR)
718e3744 10906{
d62a17ae 10907 char *vrf = NULL;
10908 char *sh_arg = NULL;
10909 enum show_type sh_type;
718e3744 10910
9f049418 10911 bool uj = use_json(argc, argv);
718e3744 10912
d62a17ae 10913 int idx = 0;
718e3744 10914
d62a17ae 10915 if (argv_find(argv, argc, "view", &idx)
10916 || argv_find(argv, argc, "vrf", &idx))
10917 vrf = argv[idx + 1]->arg;
718e3744 10918
d62a17ae 10919 idx++;
10920 if (argv_find(argv, argc, "A.B.C.D", &idx)
10921 || argv_find(argv, argc, "X:X::X:X", &idx)
10922 || argv_find(argv, argc, "WORD", &idx)) {
10923 sh_type = show_peer;
10924 sh_arg = argv[idx]->arg;
10925 } else
10926 sh_type = show_all;
856ca177 10927
d62a17ae 10928 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10929}
10930
716b2d8a 10931/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10932 paths' and `show ip mbgp paths'. Those functions results are the
10933 same.*/
f412b39a 10934DEFUN (show_ip_bgp_paths,
718e3744 10935 show_ip_bgp_paths_cmd,
46f296b4 10936 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10937 SHOW_STR
10938 IP_STR
10939 BGP_STR
46f296b4 10940 BGP_SAFI_HELP_STR
718e3744 10941 "Path information\n")
10942{
d62a17ae 10943 vty_out(vty, "Address Refcnt Path\n");
10944 aspath_print_all_vty(vty);
10945 return CMD_SUCCESS;
718e3744 10946}
10947
718e3744 10948#include "hash.h"
10949
d62a17ae 10950static void community_show_all_iterator(struct hash_backet *backet,
10951 struct vty *vty)
718e3744 10952{
d62a17ae 10953 struct community *com;
718e3744 10954
d62a17ae 10955 com = (struct community *)backet->data;
3f65c5b1 10956 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 10957 community_str(com, false));
718e3744 10958}
10959
10960/* Show BGP's community internal data. */
f412b39a 10961DEFUN (show_ip_bgp_community_info,
718e3744 10962 show_ip_bgp_community_info_cmd,
bec37ba5 10963 "show [ip] bgp community-info",
718e3744 10964 SHOW_STR
10965 IP_STR
10966 BGP_STR
10967 "List all bgp community information\n")
10968{
d62a17ae 10969 vty_out(vty, "Address Refcnt Community\n");
718e3744 10970
d62a17ae 10971 hash_iterate(community_hash(),
10972 (void (*)(struct hash_backet *,
10973 void *))community_show_all_iterator,
10974 vty);
718e3744 10975
d62a17ae 10976 return CMD_SUCCESS;
718e3744 10977}
10978
d62a17ae 10979static void lcommunity_show_all_iterator(struct hash_backet *backet,
10980 struct vty *vty)
57d187bc 10981{
d62a17ae 10982 struct lcommunity *lcom;
57d187bc 10983
d62a17ae 10984 lcom = (struct lcommunity *)backet->data;
3f65c5b1 10985 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 10986 lcommunity_str(lcom, false));
57d187bc
JS
10987}
10988
10989/* Show BGP's community internal data. */
10990DEFUN (show_ip_bgp_lcommunity_info,
10991 show_ip_bgp_lcommunity_info_cmd,
10992 "show ip bgp large-community-info",
10993 SHOW_STR
10994 IP_STR
10995 BGP_STR
10996 "List all bgp large-community information\n")
10997{
d62a17ae 10998 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 10999
d62a17ae 11000 hash_iterate(lcommunity_hash(),
11001 (void (*)(struct hash_backet *,
11002 void *))lcommunity_show_all_iterator,
11003 vty);
57d187bc 11004
d62a17ae 11005 return CMD_SUCCESS;
57d187bc
JS
11006}
11007
11008
f412b39a 11009DEFUN (show_ip_bgp_attr_info,
718e3744 11010 show_ip_bgp_attr_info_cmd,
bec37ba5 11011 "show [ip] bgp attribute-info",
718e3744 11012 SHOW_STR
11013 IP_STR
11014 BGP_STR
11015 "List all bgp attribute information\n")
11016{
d62a17ae 11017 attr_show_all(vty);
11018 return CMD_SUCCESS;
718e3744 11019}
6b0655a2 11020
9f049418
DS
11021static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi,
11022 safi_t safi, bool use_json)
53089bec 11023{
11024 struct bgp *bgp;
11025 struct listnode *node;
11026 char *vname;
11027 char buf1[INET6_ADDRSTRLEN];
11028 char *ecom_str;
11029 vpn_policy_direction_t dir;
11030
b46dfd20
DS
11031 if (use_json) {
11032 json_object *json = NULL;
11033 json_object *json_import_vrfs = NULL;
11034 json_object *json_export_vrfs = NULL;
11035
11036 json = json_object_new_object();
b46dfd20 11037
b46dfd20
DS
11038 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11039
53089bec 11040 if (!bgp) {
b46dfd20
DS
11041 vty_out(vty, "%s\n",
11042 json_object_to_json_string_ext(
11043 json,
11044 JSON_C_TO_STRING_PRETTY));
11045 json_object_free(json);
11046
53089bec 11047 return CMD_WARNING;
11048 }
b46dfd20 11049
94d4c685
DS
11050 /* Provide context for the block */
11051 json_object_string_add(json, "vrf", name ? name : "default");
11052 json_object_string_add(json, "afiSafi",
11053 afi_safi_print(afi, safi));
11054
b46dfd20
DS
11055 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11056 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11057 json_object_string_add(json, "importFromVrfs", "none");
11058 json_object_string_add(json, "importRts", "none");
11059 } else {
6ce24e52
DS
11060 json_import_vrfs = json_object_new_array();
11061
b46dfd20
DS
11062 for (ALL_LIST_ELEMENTS_RO(
11063 bgp->vpn_policy[afi].import_vrf,
11064 node, vname))
11065 json_object_array_add(json_import_vrfs,
11066 json_object_new_string(vname));
11067
11068 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11069 ecom_str = ecommunity_ecom2str(
11070 bgp->vpn_policy[afi].rtlist[dir],
11071 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11072 json_object_object_add(json, "importFromVrfs",
11073 json_import_vrfs);
11074 json_object_string_add(json, "importRts", ecom_str);
11075
11076 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11077 }
11078
11079 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11080 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11081 json_object_string_add(json, "exportToVrfs", "none");
11082 json_object_string_add(json, "routeDistinguisher",
11083 "none");
11084 json_object_string_add(json, "exportRts", "none");
11085 } else {
6ce24e52
DS
11086 json_export_vrfs = json_object_new_array();
11087
b46dfd20
DS
11088 for (ALL_LIST_ELEMENTS_RO(
11089 bgp->vpn_policy[afi].export_vrf,
11090 node, vname))
11091 json_object_array_add(json_export_vrfs,
11092 json_object_new_string(vname));
11093 json_object_object_add(json, "exportToVrfs",
11094 json_export_vrfs);
11095 json_object_string_add(json, "routeDistinguisher",
11096 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11097 buf1, RD_ADDRSTRLEN));
11098
11099 dir = BGP_VPN_POLICY_DIR_TOVPN;
11100 ecom_str = ecommunity_ecom2str(
11101 bgp->vpn_policy[afi].rtlist[dir],
11102 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11103 json_object_string_add(json, "exportRts", ecom_str);
11104
11105 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11106 }
11107
11108 vty_out(vty, "%s\n",
11109 json_object_to_json_string_ext(json,
11110 JSON_C_TO_STRING_PRETTY));
11111 json_object_free(json);
11112
53089bec 11113 } else {
b46dfd20
DS
11114 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11115
53089bec 11116 if (!bgp) {
b46dfd20 11117 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 11118 return CMD_WARNING;
11119 }
53089bec 11120
b46dfd20
DS
11121 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11122 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11123 vty_out(vty,
11124 "This VRF is not importing %s routes from any other VRF\n",
11125 afi_safi_print(afi, safi));
11126 else {
11127 vty_out(vty,
11128 "This VRF is importing %s routes from the following VRFs:\n",
11129 afi_safi_print(afi, safi));
11130
11131 for (ALL_LIST_ELEMENTS_RO(
11132 bgp->vpn_policy[afi].import_vrf,
11133 node, vname))
11134 vty_out(vty, " %s\n", vname);
11135
11136 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11137 ecom_str = ecommunity_ecom2str(
11138 bgp->vpn_policy[afi].rtlist[dir],
11139 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11140 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11141
11142 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11143 }
53089bec 11144
b46dfd20
DS
11145 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11146 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11147 vty_out(vty,
11148 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11149 afi_safi_print(afi, safi));
b46dfd20
DS
11150 else {
11151 vty_out(vty,
04c9077f 11152 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11153 afi_safi_print(afi, safi));
b46dfd20
DS
11154
11155 for (ALL_LIST_ELEMENTS_RO(
11156 bgp->vpn_policy[afi].export_vrf,
11157 node, vname))
11158 vty_out(vty, " %s\n", vname);
11159
11160 vty_out(vty, "RD: %s\n",
11161 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11162 buf1, RD_ADDRSTRLEN));
11163
11164 dir = BGP_VPN_POLICY_DIR_TOVPN;
11165 ecom_str = ecommunity_ecom2str(
11166 bgp->vpn_policy[afi].rtlist[dir],
11167 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11168 vty_out(vty, "Export RT: %s\n", ecom_str);
04c9077f 11169 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11170 }
53089bec 11171 }
11172
11173 return CMD_SUCCESS;
11174}
11175
11176/* "show [ip] bgp route-leak" command. */
11177DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
11178 show_ip_bgp_route_leak_cmd,
11179 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
11180 SHOW_STR
11181 IP_STR
11182 BGP_STR
11183 BGP_INSTANCE_HELP_STR
11184 BGP_AFI_HELP_STR
11185 BGP_SAFI_HELP_STR
11186 "Route leaking information\n"
11187 JSON_STR)
53089bec 11188{
11189 char *vrf = NULL;
11190 afi_t afi = AFI_MAX;
11191 safi_t safi = SAFI_MAX;
11192
9f049418 11193 bool uj = use_json(argc, argv);
53089bec 11194 int idx = 0;
11195
11196 /* show [ip] bgp */
11197 if (argv_find(argv, argc, "ip", &idx)) {
11198 afi = AFI_IP;
11199 safi = SAFI_UNICAST;
11200 }
11201 /* [vrf VIEWVRFNAME] */
11202 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11203 vty_out(vty,
11204 "%% This command is not applicable to BGP views\n");
53089bec 11205 return CMD_WARNING;
11206 }
11207
11208 if (argv_find(argv, argc, "vrf", &idx))
11209 vrf = argv[++idx]->arg;
11210 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11211 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11212 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11213 }
11214
11215 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11216 vty_out(vty,
11217 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11218 return CMD_WARNING;
11219 }
11220
b46dfd20 11221 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
53089bec 11222}
11223
d62a17ae 11224static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11225 safi_t safi)
f186de26 11226{
d62a17ae 11227 struct listnode *node, *nnode;
11228 struct bgp *bgp;
f186de26 11229
d62a17ae 11230 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11231 vty_out(vty, "\nInstance %s:\n",
11232 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11233 ? "Default"
11234 : bgp->name);
11235 update_group_show(bgp, afi, safi, vty, 0);
11236 }
f186de26 11237}
11238
d62a17ae 11239static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11240 int safi, uint64_t subgrp_id)
4fb25c53 11241{
d62a17ae 11242 struct bgp *bgp;
4fb25c53 11243
d62a17ae 11244 if (name) {
11245 if (strmatch(name, "all")) {
11246 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11247 return CMD_SUCCESS;
11248 } else {
11249 bgp = bgp_lookup_by_name(name);
11250 }
11251 } else {
11252 bgp = bgp_get_default();
11253 }
4fb25c53 11254
d62a17ae 11255 if (bgp)
11256 update_group_show(bgp, afi, safi, vty, subgrp_id);
11257 return CMD_SUCCESS;
4fb25c53
DW
11258}
11259
8fe8a7f6
DS
11260DEFUN (show_ip_bgp_updgrps,
11261 show_ip_bgp_updgrps_cmd,
c1a44e43 11262 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11263 SHOW_STR
11264 IP_STR
11265 BGP_STR
11266 BGP_INSTANCE_HELP_STR
c9e571b4 11267 BGP_AFI_HELP_STR
9bedbb1e 11268 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11269 "Detailed info about dynamic update groups\n"
11270 "Specific subgroup to display detailed info for\n")
8386ac43 11271{
d62a17ae 11272 char *vrf = NULL;
11273 afi_t afi = AFI_IP6;
11274 safi_t safi = SAFI_UNICAST;
11275 uint64_t subgrp_id = 0;
11276
11277 int idx = 0;
11278
11279 /* show [ip] bgp */
11280 if (argv_find(argv, argc, "ip", &idx))
11281 afi = AFI_IP;
11282 /* [<view|vrf> VIEWVRFNAME] */
11283 if (argv_find(argv, argc, "view", &idx)
11284 || argv_find(argv, argc, "vrf", &idx))
11285 vrf = argv[++idx]->arg;
11286 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11287 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11288 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11289 }
5bf15956 11290
d62a17ae 11291 /* get subgroup id, if provided */
11292 idx = argc - 1;
11293 if (argv[idx]->type == VARIABLE_TKN)
11294 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11295
d62a17ae 11296 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11297}
11298
f186de26 11299DEFUN (show_bgp_instance_all_ipv6_updgrps,
11300 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11301 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11302 SHOW_STR
716b2d8a 11303 IP_STR
f186de26 11304 BGP_STR
11305 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11306 "Detailed info about dynamic update groups\n")
f186de26 11307{
d62a17ae 11308 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11309 return CMD_SUCCESS;
f186de26 11310}
11311
5bf15956
DW
11312DEFUN (show_bgp_updgrps_stats,
11313 show_bgp_updgrps_stats_cmd,
716b2d8a 11314 "show [ip] bgp update-groups statistics",
3f9c7369 11315 SHOW_STR
716b2d8a 11316 IP_STR
3f9c7369 11317 BGP_STR
0c7b1b01 11318 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11319 "Statistics\n")
11320{
d62a17ae 11321 struct bgp *bgp;
3f9c7369 11322
d62a17ae 11323 bgp = bgp_get_default();
11324 if (bgp)
11325 update_group_show_stats(bgp, vty);
3f9c7369 11326
d62a17ae 11327 return CMD_SUCCESS;
3f9c7369
DS
11328}
11329
8386ac43 11330DEFUN (show_bgp_instance_updgrps_stats,
11331 show_bgp_instance_updgrps_stats_cmd,
18c57037 11332 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11333 SHOW_STR
716b2d8a 11334 IP_STR
8386ac43 11335 BGP_STR
11336 BGP_INSTANCE_HELP_STR
0c7b1b01 11337 "Detailed info about dynamic update groups\n"
8386ac43 11338 "Statistics\n")
11339{
d62a17ae 11340 int idx_word = 3;
11341 struct bgp *bgp;
8386ac43 11342
d62a17ae 11343 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11344 if (bgp)
11345 update_group_show_stats(bgp, vty);
8386ac43 11346
d62a17ae 11347 return CMD_SUCCESS;
8386ac43 11348}
11349
d62a17ae 11350static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11351 afi_t afi, safi_t safi,
11352 const char *what, uint64_t subgrp_id)
3f9c7369 11353{
d62a17ae 11354 struct bgp *bgp;
8386ac43 11355
d62a17ae 11356 if (name)
11357 bgp = bgp_lookup_by_name(name);
11358 else
11359 bgp = bgp_get_default();
8386ac43 11360
d62a17ae 11361 if (bgp) {
11362 if (!strcmp(what, "advertise-queue"))
11363 update_group_show_adj_queue(bgp, afi, safi, vty,
11364 subgrp_id);
11365 else if (!strcmp(what, "advertised-routes"))
11366 update_group_show_advertised(bgp, afi, safi, vty,
11367 subgrp_id);
11368 else if (!strcmp(what, "packet-queue"))
11369 update_group_show_packet_queue(bgp, afi, safi, vty,
11370 subgrp_id);
11371 }
3f9c7369
DS
11372}
11373
dc64bdec
QY
11374DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11375 show_ip_bgp_instance_updgrps_adj_s_cmd,
11376 "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",
11377 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11378 BGP_SAFI_HELP_STR
11379 "Detailed info about dynamic update groups\n"
11380 "Specific subgroup to display info for\n"
11381 "Advertisement queue\n"
11382 "Announced routes\n"
11383 "Packet queue\n")
3f9c7369 11384{
dc64bdec
QY
11385 uint64_t subgrp_id = 0;
11386 afi_t afiz;
11387 safi_t safiz;
11388 if (sgid)
11389 subgrp_id = strtoull(sgid, NULL, 10);
11390
11391 if (!ip && !afi)
11392 afiz = AFI_IP6;
11393 if (!ip && afi)
11394 afiz = bgp_vty_afi_from_str(afi);
11395 if (ip && !afi)
11396 afiz = AFI_IP;
11397 if (ip && afi) {
11398 afiz = bgp_vty_afi_from_str(afi);
11399 if (afiz != AFI_IP)
11400 vty_out(vty,
11401 "%% Cannot specify both 'ip' and 'ipv6'\n");
11402 return CMD_WARNING;
11403 }
d62a17ae 11404
dc64bdec 11405 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11406
dc64bdec 11407 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11408 return CMD_SUCCESS;
11409}
11410
d62a17ae 11411static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11412{
11413 struct listnode *node, *nnode;
11414 struct prefix *range;
11415 struct peer *conf;
11416 struct peer *peer;
11417 char buf[PREFIX2STR_BUFFER];
11418 afi_t afi;
11419 safi_t safi;
11420 const char *peer_status;
11421 const char *af_str;
11422 int lr_count;
11423 int dynamic;
11424 int af_cfgd;
11425
11426 conf = group->conf;
11427
11428 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11429 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11430 conf->as);
11431 } else if (conf->as_type == AS_INTERNAL) {
11432 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11433 group->bgp->as);
11434 } else {
11435 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11436 }
f14e6fdb 11437
d62a17ae 11438 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11439 vty_out(vty, " Peer-group type is internal\n");
11440 else
11441 vty_out(vty, " Peer-group type is external\n");
11442
11443 /* Display AFs configured. */
11444 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11445 FOREACH_AFI_SAFI (afi, safi) {
11446 if (conf->afc[afi][safi]) {
11447 af_cfgd = 1;
11448 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11449 }
05c7a1cc 11450 }
d62a17ae 11451 if (!af_cfgd)
11452 vty_out(vty, " none\n");
11453 else
11454 vty_out(vty, "\n");
11455
11456 /* Display listen ranges (for dynamic neighbors), if any */
11457 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11458 if (afi == AFI_IP)
11459 af_str = "IPv4";
11460 else if (afi == AFI_IP6)
11461 af_str = "IPv6";
11462 else
11463 af_str = "???";
11464 lr_count = listcount(group->listen_range[afi]);
11465 if (lr_count) {
11466 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11467 af_str);
11468
11469
11470 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11471 nnode, range)) {
11472 prefix2str(range, buf, sizeof(buf));
11473 vty_out(vty, " %s\n", buf);
11474 }
11475 }
11476 }
f14e6fdb 11477
d62a17ae 11478 /* Display group members and their status */
11479 if (listcount(group->peer)) {
11480 vty_out(vty, " Peer-group members:\n");
11481 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11482 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11483 peer_status = "Idle (Admin)";
11484 else if (CHECK_FLAG(peer->sflags,
11485 PEER_STATUS_PREFIX_OVERFLOW))
11486 peer_status = "Idle (PfxCt)";
11487 else
11488 peer_status = lookup_msg(bgp_status_msg,
11489 peer->status, NULL);
11490
11491 dynamic = peer_dynamic_neighbor(peer);
11492 vty_out(vty, " %s %s %s \n", peer->host,
11493 dynamic ? "(dynamic)" : "", peer_status);
11494 }
11495 }
f14e6fdb 11496
d62a17ae 11497 return CMD_SUCCESS;
11498}
11499
ff9959b0
QY
11500static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11501 const char *group_name)
d62a17ae 11502{
ff9959b0 11503 struct bgp *bgp;
d62a17ae 11504 struct listnode *node, *nnode;
11505 struct peer_group *group;
ff9959b0
QY
11506 bool found = false;
11507
11508 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11509
11510 if (!bgp) {
9f049418 11511 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
11512 return CMD_WARNING;
11513 }
d62a17ae 11514
11515 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11516 if (group_name) {
11517 if (strmatch(group->name, group_name)) {
d62a17ae 11518 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11519 found = true;
11520 break;
d62a17ae 11521 }
ff9959b0
QY
11522 } else {
11523 bgp_show_one_peer_group(vty, group);
d62a17ae 11524 }
f14e6fdb 11525 }
f14e6fdb 11526
ff9959b0 11527 if (group_name && !found)
d62a17ae 11528 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11529
d62a17ae 11530 return CMD_SUCCESS;
f14e6fdb
DS
11531}
11532
f14e6fdb
DS
11533DEFUN (show_ip_bgp_peer_groups,
11534 show_ip_bgp_peer_groups_cmd,
18c57037 11535 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11536 SHOW_STR
11537 IP_STR
11538 BGP_STR
8386ac43 11539 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11540 "Detailed information on BGP peer groups\n"
11541 "Peer group name\n")
f14e6fdb 11542{
d62a17ae 11543 char *vrf, *pg;
d62a17ae 11544 int idx = 0;
f14e6fdb 11545
a4d82a8a
PZ
11546 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11547 : NULL;
d62a17ae 11548 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11549
ff9959b0 11550 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11551}
3f9c7369 11552
d6e3c605 11553
718e3744 11554/* Redistribute VTY commands. */
11555
718e3744 11556DEFUN (bgp_redistribute_ipv4,
11557 bgp_redistribute_ipv4_cmd,
40d1cbfb 11558 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11559 "Redistribute information from another routing protocol\n"
ab0181ee 11560 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11561{
d62a17ae 11562 VTY_DECLVAR_CONTEXT(bgp, bgp);
11563 int idx_protocol = 1;
11564 int type;
718e3744 11565
d62a17ae 11566 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11567 if (type < 0) {
11568 vty_out(vty, "%% Invalid route type\n");
11569 return CMD_WARNING_CONFIG_FAILED;
11570 }
7f323236 11571
d62a17ae 11572 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11573 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 11574}
11575
d62a17ae 11576ALIAS_HIDDEN(
11577 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11578 "redistribute " FRR_IP_REDIST_STR_BGPD,
11579 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11580
718e3744 11581DEFUN (bgp_redistribute_ipv4_rmap,
11582 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11583 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11584 "Redistribute information from another routing protocol\n"
ab0181ee 11585 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11586 "Route map reference\n"
11587 "Pointer to route-map entries\n")
11588{
d62a17ae 11589 VTY_DECLVAR_CONTEXT(bgp, bgp);
11590 int idx_protocol = 1;
11591 int idx_word = 3;
11592 int type;
11593 struct bgp_redist *red;
e923dd62 11594 bool changed;
718e3744 11595
d62a17ae 11596 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11597 if (type < 0) {
11598 vty_out(vty, "%% Invalid route type\n");
11599 return CMD_WARNING_CONFIG_FAILED;
11600 }
718e3744 11601
d62a17ae 11602 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11603 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11604 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 11605}
11606
d62a17ae 11607ALIAS_HIDDEN(
11608 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11609 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11610 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11611 "Route map reference\n"
11612 "Pointer to route-map entries\n")
596c17ba 11613
718e3744 11614DEFUN (bgp_redistribute_ipv4_metric,
11615 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11616 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11617 "Redistribute information from another routing protocol\n"
ab0181ee 11618 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11619 "Metric for redistributed routes\n"
11620 "Default metric\n")
11621{
d62a17ae 11622 VTY_DECLVAR_CONTEXT(bgp, bgp);
11623 int idx_protocol = 1;
11624 int idx_number = 3;
11625 int type;
d7c0a89a 11626 uint32_t metric;
d62a17ae 11627 struct bgp_redist *red;
e923dd62 11628 bool changed;
d62a17ae 11629
11630 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11631 if (type < 0) {
11632 vty_out(vty, "%% Invalid route type\n");
11633 return CMD_WARNING_CONFIG_FAILED;
11634 }
11635 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11636
11637 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11638 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11639 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11640}
11641
11642ALIAS_HIDDEN(
11643 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11644 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11645 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11646 "Metric for redistributed routes\n"
11647 "Default metric\n")
596c17ba 11648
718e3744 11649DEFUN (bgp_redistribute_ipv4_rmap_metric,
11650 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11651 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11652 "Redistribute information from another routing protocol\n"
ab0181ee 11653 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11654 "Route map reference\n"
11655 "Pointer to route-map entries\n"
11656 "Metric for redistributed routes\n"
11657 "Default metric\n")
11658{
d62a17ae 11659 VTY_DECLVAR_CONTEXT(bgp, bgp);
11660 int idx_protocol = 1;
11661 int idx_word = 3;
11662 int idx_number = 5;
11663 int type;
d7c0a89a 11664 uint32_t metric;
d62a17ae 11665 struct bgp_redist *red;
e923dd62 11666 bool changed;
d62a17ae 11667
11668 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11669 if (type < 0) {
11670 vty_out(vty, "%% Invalid route type\n");
11671 return CMD_WARNING_CONFIG_FAILED;
11672 }
11673 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11674
11675 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11676 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11677 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11678 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11679}
11680
11681ALIAS_HIDDEN(
11682 bgp_redistribute_ipv4_rmap_metric,
11683 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11684 "redistribute " FRR_IP_REDIST_STR_BGPD
11685 " route-map WORD metric (0-4294967295)",
11686 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11687 "Route map reference\n"
11688 "Pointer to route-map entries\n"
11689 "Metric for redistributed routes\n"
11690 "Default metric\n")
596c17ba 11691
718e3744 11692DEFUN (bgp_redistribute_ipv4_metric_rmap,
11693 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11694 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11695 "Redistribute information from another routing protocol\n"
ab0181ee 11696 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11697 "Metric for redistributed routes\n"
11698 "Default metric\n"
11699 "Route map reference\n"
11700 "Pointer to route-map entries\n")
11701{
d62a17ae 11702 VTY_DECLVAR_CONTEXT(bgp, bgp);
11703 int idx_protocol = 1;
11704 int idx_number = 3;
11705 int idx_word = 5;
11706 int type;
d7c0a89a 11707 uint32_t metric;
d62a17ae 11708 struct bgp_redist *red;
e923dd62 11709 bool changed;
d62a17ae 11710
11711 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11712 if (type < 0) {
11713 vty_out(vty, "%% Invalid route type\n");
11714 return CMD_WARNING_CONFIG_FAILED;
11715 }
11716 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11717
11718 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11719 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11720 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11721 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11722}
11723
11724ALIAS_HIDDEN(
11725 bgp_redistribute_ipv4_metric_rmap,
11726 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11727 "redistribute " FRR_IP_REDIST_STR_BGPD
11728 " metric (0-4294967295) route-map WORD",
11729 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11730 "Metric for redistributed routes\n"
11731 "Default metric\n"
11732 "Route map reference\n"
11733 "Pointer to route-map entries\n")
596c17ba 11734
7c8ff89e
DS
11735DEFUN (bgp_redistribute_ipv4_ospf,
11736 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11737 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11738 "Redistribute information from another routing protocol\n"
11739 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11740 "Non-main Kernel Routing Table\n"
11741 "Instance ID/Table ID\n")
7c8ff89e 11742{
d62a17ae 11743 VTY_DECLVAR_CONTEXT(bgp, bgp);
11744 int idx_ospf_table = 1;
11745 int idx_number = 2;
d7c0a89a
QY
11746 unsigned short instance;
11747 unsigned short protocol;
7c8ff89e 11748
d62a17ae 11749 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11750
d62a17ae 11751 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11752 protocol = ZEBRA_ROUTE_OSPF;
11753 else
11754 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11755
d62a17ae 11756 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11757 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
11758}
11759
d62a17ae 11760ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11761 "redistribute <ospf|table> (1-65535)",
11762 "Redistribute information from another routing protocol\n"
11763 "Open Shortest Path First (OSPFv2)\n"
11764 "Non-main Kernel Routing Table\n"
11765 "Instance ID/Table ID\n")
596c17ba 11766
7c8ff89e
DS
11767DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11768 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11769 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11770 "Redistribute information from another routing protocol\n"
11771 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11772 "Non-main Kernel Routing Table\n"
11773 "Instance ID/Table ID\n"
7c8ff89e
DS
11774 "Route map reference\n"
11775 "Pointer to route-map entries\n")
11776{
d62a17ae 11777 VTY_DECLVAR_CONTEXT(bgp, bgp);
11778 int idx_ospf_table = 1;
11779 int idx_number = 2;
11780 int idx_word = 4;
11781 struct bgp_redist *red;
d7c0a89a 11782 unsigned short instance;
d62a17ae 11783 int protocol;
e923dd62 11784 bool changed;
d62a17ae 11785
11786 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11787 protocol = ZEBRA_ROUTE_OSPF;
11788 else
11789 protocol = ZEBRA_ROUTE_TABLE;
11790
11791 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11792 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11793 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11794 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11795}
11796
11797ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11798 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11799 "redistribute <ospf|table> (1-65535) route-map WORD",
11800 "Redistribute information from another routing protocol\n"
11801 "Open Shortest Path First (OSPFv2)\n"
11802 "Non-main Kernel Routing Table\n"
11803 "Instance ID/Table ID\n"
11804 "Route map reference\n"
11805 "Pointer to route-map entries\n")
596c17ba 11806
7c8ff89e
DS
11807DEFUN (bgp_redistribute_ipv4_ospf_metric,
11808 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 11809 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
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 "Metric for redistributed routes\n"
11815 "Default metric\n")
11816{
d62a17ae 11817 VTY_DECLVAR_CONTEXT(bgp, bgp);
11818 int idx_ospf_table = 1;
11819 int idx_number = 2;
11820 int idx_number_2 = 4;
d7c0a89a 11821 uint32_t metric;
d62a17ae 11822 struct bgp_redist *red;
d7c0a89a 11823 unsigned short instance;
d62a17ae 11824 int protocol;
e923dd62 11825 bool changed;
d62a17ae 11826
11827 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11828 protocol = ZEBRA_ROUTE_OSPF;
11829 else
11830 protocol = ZEBRA_ROUTE_TABLE;
11831
11832 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11833 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11834
11835 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11836 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11837 metric);
11838 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11839}
11840
11841ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11842 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11843 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11844 "Redistribute information from another routing protocol\n"
11845 "Open Shortest Path First (OSPFv2)\n"
11846 "Non-main Kernel Routing Table\n"
11847 "Instance ID/Table ID\n"
11848 "Metric for redistributed routes\n"
11849 "Default metric\n")
596c17ba 11850
7c8ff89e
DS
11851DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11852 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 11853 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
11854 "Redistribute information from another routing protocol\n"
11855 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11856 "Non-main Kernel Routing Table\n"
11857 "Instance ID/Table ID\n"
7c8ff89e
DS
11858 "Route map reference\n"
11859 "Pointer to route-map entries\n"
11860 "Metric for redistributed routes\n"
11861 "Default metric\n")
11862{
d62a17ae 11863 VTY_DECLVAR_CONTEXT(bgp, bgp);
11864 int idx_ospf_table = 1;
11865 int idx_number = 2;
11866 int idx_word = 4;
11867 int idx_number_2 = 6;
d7c0a89a 11868 uint32_t metric;
d62a17ae 11869 struct bgp_redist *red;
d7c0a89a 11870 unsigned short instance;
d62a17ae 11871 int protocol;
e923dd62 11872 bool changed;
d62a17ae 11873
11874 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11875 protocol = ZEBRA_ROUTE_OSPF;
11876 else
11877 protocol = ZEBRA_ROUTE_TABLE;
11878
11879 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11880 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11881
11882 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11883 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11884 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11885 metric);
11886 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11887}
11888
11889ALIAS_HIDDEN(
11890 bgp_redistribute_ipv4_ospf_rmap_metric,
11891 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11892 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11893 "Redistribute information from another routing protocol\n"
11894 "Open Shortest Path First (OSPFv2)\n"
11895 "Non-main Kernel Routing Table\n"
11896 "Instance ID/Table ID\n"
11897 "Route map reference\n"
11898 "Pointer to route-map entries\n"
11899 "Metric for redistributed routes\n"
11900 "Default metric\n")
596c17ba 11901
7c8ff89e
DS
11902DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11903 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 11904 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
11905 "Redistribute information from another routing protocol\n"
11906 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11907 "Non-main Kernel Routing Table\n"
11908 "Instance ID/Table ID\n"
7c8ff89e
DS
11909 "Metric for redistributed routes\n"
11910 "Default metric\n"
11911 "Route map reference\n"
11912 "Pointer to route-map entries\n")
11913{
d62a17ae 11914 VTY_DECLVAR_CONTEXT(bgp, bgp);
11915 int idx_ospf_table = 1;
11916 int idx_number = 2;
11917 int idx_number_2 = 4;
11918 int idx_word = 6;
d7c0a89a 11919 uint32_t metric;
d62a17ae 11920 struct bgp_redist *red;
d7c0a89a 11921 unsigned short instance;
d62a17ae 11922 int protocol;
e923dd62 11923 bool changed;
d62a17ae 11924
11925 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11926 protocol = ZEBRA_ROUTE_OSPF;
11927 else
11928 protocol = ZEBRA_ROUTE_TABLE;
11929
11930 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11931 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11932
11933 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11934 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11935 metric);
11936 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11937 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11938}
11939
11940ALIAS_HIDDEN(
11941 bgp_redistribute_ipv4_ospf_metric_rmap,
11942 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11943 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11944 "Redistribute information from another routing protocol\n"
11945 "Open Shortest Path First (OSPFv2)\n"
11946 "Non-main Kernel Routing Table\n"
11947 "Instance ID/Table ID\n"
11948 "Metric for redistributed routes\n"
11949 "Default metric\n"
11950 "Route map reference\n"
11951 "Pointer to route-map entries\n")
596c17ba 11952
7c8ff89e
DS
11953DEFUN (no_bgp_redistribute_ipv4_ospf,
11954 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 11955 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
11956 NO_STR
11957 "Redistribute information from another routing protocol\n"
11958 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 11959 "Non-main Kernel Routing Table\n"
31500417
DW
11960 "Instance ID/Table ID\n"
11961 "Metric for redistributed routes\n"
11962 "Default metric\n"
11963 "Route map reference\n"
11964 "Pointer to route-map entries\n")
7c8ff89e 11965{
d62a17ae 11966 VTY_DECLVAR_CONTEXT(bgp, bgp);
11967 int idx_ospf_table = 2;
11968 int idx_number = 3;
d7c0a89a 11969 unsigned short instance;
d62a17ae 11970 int protocol;
11971
11972 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11973 protocol = ZEBRA_ROUTE_OSPF;
11974 else
11975 protocol = ZEBRA_ROUTE_TABLE;
11976
11977 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11978 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11979}
11980
11981ALIAS_HIDDEN(
11982 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11983 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11984 NO_STR
11985 "Redistribute information from another routing protocol\n"
11986 "Open Shortest Path First (OSPFv2)\n"
11987 "Non-main Kernel Routing Table\n"
11988 "Instance ID/Table ID\n"
11989 "Metric for redistributed routes\n"
11990 "Default metric\n"
11991 "Route map reference\n"
11992 "Pointer to route-map entries\n")
596c17ba 11993
718e3744 11994DEFUN (no_bgp_redistribute_ipv4,
11995 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 11996 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11997 NO_STR
11998 "Redistribute information from another routing protocol\n"
3b14d86e 11999 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
12000 "Metric for redistributed routes\n"
12001 "Default metric\n"
12002 "Route map reference\n"
12003 "Pointer to route-map entries\n")
718e3744 12004{
d62a17ae 12005 VTY_DECLVAR_CONTEXT(bgp, bgp);
12006 int idx_protocol = 2;
12007 int type;
12008
12009 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12010 if (type < 0) {
12011 vty_out(vty, "%% Invalid route type\n");
12012 return CMD_WARNING_CONFIG_FAILED;
12013 }
12014 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12015}
12016
12017ALIAS_HIDDEN(
12018 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12019 "no redistribute " FRR_IP_REDIST_STR_BGPD
12020 " [metric (0-4294967295)] [route-map WORD]",
12021 NO_STR
12022 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12023 "Metric for redistributed routes\n"
12024 "Default metric\n"
12025 "Route map reference\n"
12026 "Pointer to route-map entries\n")
596c17ba 12027
718e3744 12028DEFUN (bgp_redistribute_ipv6,
12029 bgp_redistribute_ipv6_cmd,
40d1cbfb 12030 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 12031 "Redistribute information from another routing protocol\n"
ab0181ee 12032 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 12033{
d62a17ae 12034 VTY_DECLVAR_CONTEXT(bgp, bgp);
12035 int idx_protocol = 1;
12036 int type;
718e3744 12037
d62a17ae 12038 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12039 if (type < 0) {
12040 vty_out(vty, "%% Invalid route type\n");
12041 return CMD_WARNING_CONFIG_FAILED;
12042 }
718e3744 12043
d62a17ae 12044 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12045 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 12046}
12047
12048DEFUN (bgp_redistribute_ipv6_rmap,
12049 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 12050 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 12051 "Redistribute information from another routing protocol\n"
ab0181ee 12052 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12053 "Route map reference\n"
12054 "Pointer to route-map entries\n")
12055{
d62a17ae 12056 VTY_DECLVAR_CONTEXT(bgp, bgp);
12057 int idx_protocol = 1;
12058 int idx_word = 3;
12059 int type;
12060 struct bgp_redist *red;
e923dd62 12061 bool changed;
718e3744 12062
d62a17ae 12063 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12064 if (type < 0) {
12065 vty_out(vty, "%% Invalid route type\n");
12066 return CMD_WARNING_CONFIG_FAILED;
12067 }
718e3744 12068
d62a17ae 12069 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12070 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12071 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12072}
12073
12074DEFUN (bgp_redistribute_ipv6_metric,
12075 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 12076 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12077 "Redistribute information from another routing protocol\n"
ab0181ee 12078 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12079 "Metric for redistributed routes\n"
12080 "Default metric\n")
12081{
d62a17ae 12082 VTY_DECLVAR_CONTEXT(bgp, bgp);
12083 int idx_protocol = 1;
12084 int idx_number = 3;
12085 int type;
d7c0a89a 12086 uint32_t metric;
d62a17ae 12087 struct bgp_redist *red;
e923dd62 12088 bool changed;
d62a17ae 12089
12090 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12091 if (type < 0) {
12092 vty_out(vty, "%% Invalid route type\n");
12093 return CMD_WARNING_CONFIG_FAILED;
12094 }
12095 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12096
d62a17ae 12097 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12098 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12099 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12100}
12101
12102DEFUN (bgp_redistribute_ipv6_rmap_metric,
12103 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 12104 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12105 "Redistribute information from another routing protocol\n"
ab0181ee 12106 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12107 "Route map reference\n"
12108 "Pointer to route-map entries\n"
12109 "Metric for redistributed routes\n"
12110 "Default metric\n")
12111{
d62a17ae 12112 VTY_DECLVAR_CONTEXT(bgp, bgp);
12113 int idx_protocol = 1;
12114 int idx_word = 3;
12115 int idx_number = 5;
12116 int type;
d7c0a89a 12117 uint32_t metric;
d62a17ae 12118 struct bgp_redist *red;
e923dd62 12119 bool changed;
d62a17ae 12120
12121 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12122 if (type < 0) {
12123 vty_out(vty, "%% Invalid route type\n");
12124 return CMD_WARNING_CONFIG_FAILED;
12125 }
12126 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12127
d62a17ae 12128 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12129 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12130 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12131 metric);
12132 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12133}
12134
12135DEFUN (bgp_redistribute_ipv6_metric_rmap,
12136 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 12137 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12138 "Redistribute information from another routing protocol\n"
ab0181ee 12139 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12140 "Metric for redistributed routes\n"
12141 "Default metric\n"
12142 "Route map reference\n"
12143 "Pointer to route-map entries\n")
12144{
d62a17ae 12145 VTY_DECLVAR_CONTEXT(bgp, bgp);
12146 int idx_protocol = 1;
12147 int idx_number = 3;
12148 int idx_word = 5;
12149 int type;
d7c0a89a 12150 uint32_t metric;
d62a17ae 12151 struct bgp_redist *red;
e923dd62 12152 bool changed;
d62a17ae 12153
12154 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12155 if (type < 0) {
12156 vty_out(vty, "%% Invalid route type\n");
12157 return CMD_WARNING_CONFIG_FAILED;
12158 }
12159 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12160
d62a17ae 12161 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12162 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12163 metric);
12164 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12165 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12166}
12167
12168DEFUN (no_bgp_redistribute_ipv6,
12169 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 12170 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12171 NO_STR
12172 "Redistribute information from another routing protocol\n"
3b14d86e 12173 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12174 "Metric for redistributed routes\n"
12175 "Default metric\n"
12176 "Route map reference\n"
12177 "Pointer to route-map entries\n")
718e3744 12178{
d62a17ae 12179 VTY_DECLVAR_CONTEXT(bgp, bgp);
12180 int idx_protocol = 2;
12181 int type;
718e3744 12182
d62a17ae 12183 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12184 if (type < 0) {
12185 vty_out(vty, "%% Invalid route type\n");
12186 return CMD_WARNING_CONFIG_FAILED;
12187 }
718e3744 12188
d62a17ae 12189 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12190}
12191
2b791107 12192void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12193 safi_t safi)
d62a17ae 12194{
12195 int i;
12196
12197 /* Unicast redistribution only. */
12198 if (safi != SAFI_UNICAST)
2b791107 12199 return;
d62a17ae 12200
12201 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12202 /* Redistribute BGP does not make sense. */
12203 if (i != ZEBRA_ROUTE_BGP) {
12204 struct list *red_list;
12205 struct listnode *node;
12206 struct bgp_redist *red;
12207
12208 red_list = bgp->redist[afi][i];
12209 if (!red_list)
12210 continue;
12211
12212 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12213 /* "redistribute" configuration. */
12214 vty_out(vty, " redistribute %s",
12215 zebra_route_string(i));
12216 if (red->instance)
12217 vty_out(vty, " %d", red->instance);
12218 if (red->redist_metric_flag)
12219 vty_out(vty, " metric %u",
12220 red->redist_metric);
12221 if (red->rmap.name)
12222 vty_out(vty, " route-map %s",
12223 red->rmap.name);
12224 vty_out(vty, "\n");
12225 }
12226 }
12227 }
718e3744 12228}
6b0655a2 12229
b9c7bc5a
PZ
12230/* This is part of the address-family block (unicast only) */
12231void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12232 afi_t afi)
12233{
b9c7bc5a 12234 int indent = 2;
ddb5b488 12235
bb4f6190
DS
12236 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12237 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12238 bgp->vpn_policy[afi]
12239 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12240
12a844a5
DS
12241 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12242 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12243 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12244 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12245 return;
12246
e70e9f8e
PZ
12247 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12248 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12249
12250 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12251
12252 } else {
12253 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12254 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12255 bgp->vpn_policy[afi].tovpn_label);
12256 }
ddb5b488
PZ
12257 }
12258 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12259 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12260 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12261 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12262 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12263 sizeof(buf)));
12264 }
12265 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12266 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12267
12268 char buf[PREFIX_STRLEN];
12269 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12270 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12271 sizeof(buf))) {
12272
b9c7bc5a
PZ
12273 vty_out(vty, "%*snexthop vpn export %s\n",
12274 indent, "", buf);
ddb5b488
PZ
12275 }
12276 }
12277 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12278 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12279 && ecommunity_cmp(
12280 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12281 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12282
12283 char *b = ecommunity_ecom2str(
12284 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12285 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12286 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12287 XFREE(MTYPE_ECOMMUNITY_STR, b);
12288 } else {
12289 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12290 char *b = ecommunity_ecom2str(
12291 bgp->vpn_policy[afi]
12292 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12293 ECOMMUNITY_FORMAT_ROUTE_MAP,
12294 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12295 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12296 XFREE(MTYPE_ECOMMUNITY_STR, b);
12297 }
12298 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12299 char *b = ecommunity_ecom2str(
12300 bgp->vpn_policy[afi]
12301 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12302 ECOMMUNITY_FORMAT_ROUTE_MAP,
12303 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12304 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12305 XFREE(MTYPE_ECOMMUNITY_STR, b);
12306 }
12307 }
bb4f6190
DS
12308
12309 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12310 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12311 bgp->vpn_policy[afi]
12312 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12313
301ad80a
PG
12314 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12315 char *b = ecommunity_ecom2str(
12316 bgp->vpn_policy[afi]
12317 .import_redirect_rtlist,
12318 ECOMMUNITY_FORMAT_ROUTE_MAP,
12319 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12320
301ad80a
PG
12321 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12322 XFREE(MTYPE_ECOMMUNITY_STR, b);
12323 }
ddb5b488
PZ
12324}
12325
12326
718e3744 12327/* BGP node structure. */
d62a17ae 12328static struct cmd_node bgp_node = {
9d303b37 12329 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12330};
12331
d62a17ae 12332static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12333 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12334};
12335
d62a17ae 12336static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12337 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12338};
12339
d62a17ae 12340static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12341 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12342};
12343
d62a17ae 12344static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12345 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12346};
12347
d62a17ae 12348static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12349 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12350};
12351
d62a17ae 12352static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12353 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12354};
12355
d62a17ae 12356static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12357 "%s(config-router-af)# ", 1};
6b0655a2 12358
d62a17ae 12359static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12360 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12361
d62a17ae 12362static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12363 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12364
d62a17ae 12365static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12366 "%s(config-router-af-vni)# ", 1};
90e60aa7 12367
7c40bf39 12368static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12369 "%s(config-router-af)# ", 1};
12370
12371static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12372 "%s(config-router-af-vpnv6)# ", 1};
12373
d62a17ae 12374static void community_list_vty(void);
1f8ae70b 12375
d62a17ae 12376static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12377{
d62a17ae 12378 struct bgp *bgp;
12379 struct peer *peer;
d62a17ae 12380 struct listnode *lnbgp, *lnpeer;
b8a815e5 12381
d62a17ae 12382 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12383 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12384 /* only provide suggestions on the appropriate input
12385 * token type,
12386 * they'll otherwise show up multiple times */
12387 enum cmd_token_type match_type;
12388 char *name = peer->host;
d48ed3e0 12389
d62a17ae 12390 if (peer->conf_if) {
12391 match_type = VARIABLE_TKN;
12392 name = peer->conf_if;
12393 } else if (strchr(peer->host, ':'))
12394 match_type = IPV6_TKN;
12395 else
12396 match_type = IPV4_TKN;
d48ed3e0 12397
d62a17ae 12398 if (token->type != match_type)
12399 continue;
d48ed3e0 12400
d62a17ae 12401 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12402 }
d62a17ae 12403 }
b8a815e5
DL
12404}
12405
12406static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12407 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12408 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12409 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12410 {.completions = NULL}};
12411
47a306a0
DS
12412static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12413{
12414 struct bgp *bgp;
12415 struct peer_group *group;
12416 struct listnode *lnbgp, *lnpeer;
12417
12418 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12419 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12420 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12421 group->name));
12422 }
12423}
12424
12425static const struct cmd_variable_handler bgp_var_peergroup[] = {
12426 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12427 {.completions = NULL} };
12428
d62a17ae 12429void bgp_vty_init(void)
12430{
12431 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12432 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12433
12434 /* Install bgp top node. */
12435 install_node(&bgp_node, bgp_config_write);
12436 install_node(&bgp_ipv4_unicast_node, NULL);
12437 install_node(&bgp_ipv4_multicast_node, NULL);
12438 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12439 install_node(&bgp_ipv6_unicast_node, NULL);
12440 install_node(&bgp_ipv6_multicast_node, NULL);
12441 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12442 install_node(&bgp_vpnv4_node, NULL);
12443 install_node(&bgp_vpnv6_node, NULL);
12444 install_node(&bgp_evpn_node, NULL);
12445 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12446 install_node(&bgp_flowspecv4_node, NULL);
12447 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12448
12449 /* Install default VTY commands to new nodes. */
12450 install_default(BGP_NODE);
12451 install_default(BGP_IPV4_NODE);
12452 install_default(BGP_IPV4M_NODE);
12453 install_default(BGP_IPV4L_NODE);
12454 install_default(BGP_IPV6_NODE);
12455 install_default(BGP_IPV6M_NODE);
12456 install_default(BGP_IPV6L_NODE);
12457 install_default(BGP_VPNV4_NODE);
12458 install_default(BGP_VPNV6_NODE);
7c40bf39 12459 install_default(BGP_FLOWSPECV4_NODE);
12460 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12461 install_default(BGP_EVPN_NODE);
12462 install_default(BGP_EVPN_VNI_NODE);
12463
12464 /* "bgp multiple-instance" commands. */
12465 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12466 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12467
12468 /* "bgp config-type" commands. */
12469 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12470 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12471
12472 /* bgp route-map delay-timer commands. */
12473 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12474 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12475
12476 /* Dummy commands (Currently not supported) */
12477 install_element(BGP_NODE, &no_synchronization_cmd);
12478 install_element(BGP_NODE, &no_auto_summary_cmd);
12479
12480 /* "router bgp" commands. */
12481 install_element(CONFIG_NODE, &router_bgp_cmd);
12482
12483 /* "no router bgp" commands. */
12484 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12485
12486 /* "bgp router-id" commands. */
12487 install_element(BGP_NODE, &bgp_router_id_cmd);
12488 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12489
12490 /* "bgp cluster-id" commands. */
12491 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12492 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12493
12494 /* "bgp confederation" commands. */
12495 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12496 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12497
12498 /* "bgp confederation peers" commands. */
12499 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12500 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12501
12502 /* bgp max-med command */
12503 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12504 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12505 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12506 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12507 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12508
12509 /* bgp disable-ebgp-connected-nh-check */
12510 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12511 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12512
12513 /* bgp update-delay command */
12514 install_element(BGP_NODE, &bgp_update_delay_cmd);
12515 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12516 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12517
12518 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12519 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12520 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12521 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12522
12523 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12524 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12525
12526 /* "maximum-paths" commands. */
12527 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12528 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12529 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12530 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12531 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12532 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12533 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12534 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12535 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12536 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12537 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12538 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12539 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12540 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12541 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12542
12543 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12544 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12545 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12546 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12547 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12548
12549 /* "timers bgp" commands. */
12550 install_element(BGP_NODE, &bgp_timers_cmd);
12551 install_element(BGP_NODE, &no_bgp_timers_cmd);
12552
12553 /* route-map delay-timer commands - per instance for backwards compat.
12554 */
12555 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12556 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12557
12558 /* "bgp client-to-client reflection" commands */
12559 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12560 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12561
12562 /* "bgp always-compare-med" commands */
12563 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12564 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12565
12566 /* "bgp deterministic-med" commands */
12567 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12568 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12569
12570 /* "bgp graceful-restart" commands */
12571 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12572 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12573 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12574 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12575 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12576 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12577
12578 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12579 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12580
7f323236
DW
12581 /* "bgp graceful-shutdown" commands */
12582 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12583 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12584
d62a17ae 12585 /* "bgp fast-external-failover" commands */
12586 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12587 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12588
12589 /* "bgp enforce-first-as" commands */
12590 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
d62a17ae 12591
12592 /* "bgp bestpath compare-routerid" commands */
12593 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12594 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12595
12596 /* "bgp bestpath as-path ignore" commands */
12597 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12598 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12599
12600 /* "bgp bestpath as-path confed" commands */
12601 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12602 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12603
12604 /* "bgp bestpath as-path multipath-relax" commands */
12605 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12606 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12607
12608 /* "bgp log-neighbor-changes" commands */
12609 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12610 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12611
12612 /* "bgp bestpath med" commands */
12613 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12614 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12615
12616 /* "no bgp default ipv4-unicast" commands. */
12617 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12618 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12619
12620 /* "bgp network import-check" commands. */
12621 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12622 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12623 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12624
12625 /* "bgp default local-preference" commands. */
12626 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12627 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12628
12629 /* bgp default show-hostname */
12630 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12631 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12632
12633 /* "bgp default subgroup-pkt-queue-max" commands. */
12634 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12635 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12636
12637 /* bgp ibgp-allow-policy-mods command */
12638 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12639 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12640
12641 /* "bgp listen limit" commands. */
12642 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12643 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12644
12645 /* "bgp listen range" commands. */
12646 install_element(BGP_NODE, &bgp_listen_range_cmd);
12647 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12648
8175f54a 12649 /* "bgp default shutdown" command */
f26845f9
QY
12650 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12651
d62a17ae 12652 /* "neighbor remote-as" commands. */
12653 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12654 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12655 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12656 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12657 install_element(BGP_NODE,
12658 &neighbor_interface_v6only_config_remote_as_cmd);
12659 install_element(BGP_NODE, &no_neighbor_cmd);
12660 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12661
12662 /* "neighbor peer-group" commands. */
12663 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12664 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12665 install_element(BGP_NODE,
12666 &no_neighbor_interface_peer_group_remote_as_cmd);
12667
12668 /* "neighbor local-as" commands. */
12669 install_element(BGP_NODE, &neighbor_local_as_cmd);
12670 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12671 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12672 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12673
12674 /* "neighbor solo" commands. */
12675 install_element(BGP_NODE, &neighbor_solo_cmd);
12676 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12677
12678 /* "neighbor password" commands. */
12679 install_element(BGP_NODE, &neighbor_password_cmd);
12680 install_element(BGP_NODE, &no_neighbor_password_cmd);
12681
12682 /* "neighbor activate" commands. */
12683 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12684 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12685 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12686 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12687 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12688 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12689 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12690 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12691 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 12692 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12693 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 12694 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12695
12696 /* "no neighbor activate" commands. */
12697 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12698 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12699 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12700 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12701 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12702 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12703 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12704 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12705 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 12706 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12707 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 12708 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12709
12710 /* "neighbor peer-group" set commands. */
12711 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12712 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12713 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12714 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12715 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12716 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12717 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12718 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 12719 install_element(BGP_FLOWSPECV4_NODE,
12720 &neighbor_set_peer_group_hidden_cmd);
12721 install_element(BGP_FLOWSPECV6_NODE,
12722 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 12723
12724 /* "no neighbor peer-group unset" commands. */
12725 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12726 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12727 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12728 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12729 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12730 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12731 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12732 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 12733 install_element(BGP_FLOWSPECV4_NODE,
12734 &no_neighbor_set_peer_group_hidden_cmd);
12735 install_element(BGP_FLOWSPECV6_NODE,
12736 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 12737
12738 /* "neighbor softreconfiguration inbound" commands.*/
12739 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12740 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12741 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12742 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12743 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12744 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12745 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12746 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12747 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12748 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12749 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12750 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12751 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12752 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12753 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12754 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12755 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12756 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 12757 install_element(BGP_FLOWSPECV4_NODE,
12758 &neighbor_soft_reconfiguration_cmd);
12759 install_element(BGP_FLOWSPECV4_NODE,
12760 &no_neighbor_soft_reconfiguration_cmd);
12761 install_element(BGP_FLOWSPECV6_NODE,
12762 &neighbor_soft_reconfiguration_cmd);
12763 install_element(BGP_FLOWSPECV6_NODE,
12764 &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 12765
12766 /* "neighbor attribute-unchanged" commands. */
12767 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12768 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12769 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12770 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12771 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12772 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12773 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12774 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12775 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12776 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12777 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12778 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12779 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12780 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12781 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12782 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12783 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12784 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12785
12786 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12787 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12788
12789 /* "nexthop-local unchanged" commands */
12790 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12791 install_element(BGP_IPV6_NODE,
12792 &no_neighbor_nexthop_local_unchanged_cmd);
12793
12794 /* "neighbor next-hop-self" commands. */
12795 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12796 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12797 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12798 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12799 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12800 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12801 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12802 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12803 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12804 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12805 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12806 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12807 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12808 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12809 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12810 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12811 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12812 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
12813 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12814 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 12815
12816 /* "neighbor next-hop-self force" commands. */
12817 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12818 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12819 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12820 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12821 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12822 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12823 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12824 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12825 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12826 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12827 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12828 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12829 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12830 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12831 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12832 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12833 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12834 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12835
12836 /* "neighbor as-override" commands. */
12837 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12838 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12839 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12840 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12841 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12842 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12843 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12844 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12845 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12846 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12847 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12848 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12849 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12850 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12851 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12852 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12853 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12854 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12855
12856 /* "neighbor remove-private-AS" commands. */
12857 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12858 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12859 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12860 install_element(BGP_NODE,
12861 &no_neighbor_remove_private_as_all_hidden_cmd);
12862 install_element(BGP_NODE,
12863 &neighbor_remove_private_as_replace_as_hidden_cmd);
12864 install_element(BGP_NODE,
12865 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12866 install_element(BGP_NODE,
12867 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12868 install_element(
12869 BGP_NODE,
12870 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12871 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12872 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12873 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12874 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12875 install_element(BGP_IPV4_NODE,
12876 &neighbor_remove_private_as_replace_as_cmd);
12877 install_element(BGP_IPV4_NODE,
12878 &no_neighbor_remove_private_as_replace_as_cmd);
12879 install_element(BGP_IPV4_NODE,
12880 &neighbor_remove_private_as_all_replace_as_cmd);
12881 install_element(BGP_IPV4_NODE,
12882 &no_neighbor_remove_private_as_all_replace_as_cmd);
12883 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12884 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12885 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12886 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12887 install_element(BGP_IPV4M_NODE,
12888 &neighbor_remove_private_as_replace_as_cmd);
12889 install_element(BGP_IPV4M_NODE,
12890 &no_neighbor_remove_private_as_replace_as_cmd);
12891 install_element(BGP_IPV4M_NODE,
12892 &neighbor_remove_private_as_all_replace_as_cmd);
12893 install_element(BGP_IPV4M_NODE,
12894 &no_neighbor_remove_private_as_all_replace_as_cmd);
12895 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12896 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12897 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12898 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12899 install_element(BGP_IPV4L_NODE,
12900 &neighbor_remove_private_as_replace_as_cmd);
12901 install_element(BGP_IPV4L_NODE,
12902 &no_neighbor_remove_private_as_replace_as_cmd);
12903 install_element(BGP_IPV4L_NODE,
12904 &neighbor_remove_private_as_all_replace_as_cmd);
12905 install_element(BGP_IPV4L_NODE,
12906 &no_neighbor_remove_private_as_all_replace_as_cmd);
12907 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12908 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12909 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12910 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12911 install_element(BGP_IPV6_NODE,
12912 &neighbor_remove_private_as_replace_as_cmd);
12913 install_element(BGP_IPV6_NODE,
12914 &no_neighbor_remove_private_as_replace_as_cmd);
12915 install_element(BGP_IPV6_NODE,
12916 &neighbor_remove_private_as_all_replace_as_cmd);
12917 install_element(BGP_IPV6_NODE,
12918 &no_neighbor_remove_private_as_all_replace_as_cmd);
12919 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12920 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12921 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12922 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12923 install_element(BGP_IPV6M_NODE,
12924 &neighbor_remove_private_as_replace_as_cmd);
12925 install_element(BGP_IPV6M_NODE,
12926 &no_neighbor_remove_private_as_replace_as_cmd);
12927 install_element(BGP_IPV6M_NODE,
12928 &neighbor_remove_private_as_all_replace_as_cmd);
12929 install_element(BGP_IPV6M_NODE,
12930 &no_neighbor_remove_private_as_all_replace_as_cmd);
12931 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12932 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12933 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12934 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12935 install_element(BGP_IPV6L_NODE,
12936 &neighbor_remove_private_as_replace_as_cmd);
12937 install_element(BGP_IPV6L_NODE,
12938 &no_neighbor_remove_private_as_replace_as_cmd);
12939 install_element(BGP_IPV6L_NODE,
12940 &neighbor_remove_private_as_all_replace_as_cmd);
12941 install_element(BGP_IPV6L_NODE,
12942 &no_neighbor_remove_private_as_all_replace_as_cmd);
12943 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12944 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12945 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12946 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12947 install_element(BGP_VPNV4_NODE,
12948 &neighbor_remove_private_as_replace_as_cmd);
12949 install_element(BGP_VPNV4_NODE,
12950 &no_neighbor_remove_private_as_replace_as_cmd);
12951 install_element(BGP_VPNV4_NODE,
12952 &neighbor_remove_private_as_all_replace_as_cmd);
12953 install_element(BGP_VPNV4_NODE,
12954 &no_neighbor_remove_private_as_all_replace_as_cmd);
12955 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12956 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12957 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12958 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12959 install_element(BGP_VPNV6_NODE,
12960 &neighbor_remove_private_as_replace_as_cmd);
12961 install_element(BGP_VPNV6_NODE,
12962 &no_neighbor_remove_private_as_replace_as_cmd);
12963 install_element(BGP_VPNV6_NODE,
12964 &neighbor_remove_private_as_all_replace_as_cmd);
12965 install_element(BGP_VPNV6_NODE,
12966 &no_neighbor_remove_private_as_all_replace_as_cmd);
12967
12968 /* "neighbor send-community" commands.*/
12969 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12970 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12971 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12972 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12973 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12974 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12975 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12976 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12977 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12978 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12979 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12980 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12981 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12982 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12983 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12984 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12985 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12986 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12987 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12988 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12989 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12990 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12991 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12992 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12993 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12994 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12995 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12996 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12997 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12998 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12999 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13000 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13001 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13002 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13003 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13004 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13005
13006 /* "neighbor route-reflector" commands.*/
13007 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13008 install_element(BGP_NODE,
13009 &no_neighbor_route_reflector_client_hidden_cmd);
13010 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13011 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13012 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13013 install_element(BGP_IPV4M_NODE,
13014 &no_neighbor_route_reflector_client_cmd);
13015 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13016 install_element(BGP_IPV4L_NODE,
13017 &no_neighbor_route_reflector_client_cmd);
13018 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13019 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13020 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13021 install_element(BGP_IPV6M_NODE,
13022 &no_neighbor_route_reflector_client_cmd);
13023 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13024 install_element(BGP_IPV6L_NODE,
13025 &no_neighbor_route_reflector_client_cmd);
13026 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13027 install_element(BGP_VPNV4_NODE,
13028 &no_neighbor_route_reflector_client_cmd);
13029 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13030 install_element(BGP_VPNV6_NODE,
13031 &no_neighbor_route_reflector_client_cmd);
7c40bf39 13032 install_element(BGP_FLOWSPECV4_NODE,
13033 &neighbor_route_reflector_client_cmd);
13034 install_element(BGP_FLOWSPECV4_NODE,
13035 &no_neighbor_route_reflector_client_cmd);
13036 install_element(BGP_FLOWSPECV6_NODE,
13037 &neighbor_route_reflector_client_cmd);
13038 install_element(BGP_FLOWSPECV6_NODE,
13039 &no_neighbor_route_reflector_client_cmd);
d62a17ae 13040 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13041 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13042
13043 /* "neighbor route-server" commands.*/
13044 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13045 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13046 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13047 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13048 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13049 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13050 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13051 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13052 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13053 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13054 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13055 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13056 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13057 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13058 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13059 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13060 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13061 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 13062 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13063 install_element(BGP_FLOWSPECV4_NODE,
13064 &no_neighbor_route_server_client_cmd);
13065 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13066 install_element(BGP_FLOWSPECV6_NODE,
13067 &no_neighbor_route_server_client_cmd);
d62a17ae 13068
13069 /* "neighbor addpath-tx-all-paths" commands.*/
13070 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13071 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13072 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13073 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13074 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13075 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13076 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13077 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13078 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13079 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13080 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13081 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13082 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13083 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13084 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13085 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13086 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13087 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13088
13089 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13090 install_element(BGP_NODE,
13091 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13092 install_element(BGP_NODE,
13093 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13094 install_element(BGP_IPV4_NODE,
13095 &neighbor_addpath_tx_bestpath_per_as_cmd);
13096 install_element(BGP_IPV4_NODE,
13097 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13098 install_element(BGP_IPV4M_NODE,
13099 &neighbor_addpath_tx_bestpath_per_as_cmd);
13100 install_element(BGP_IPV4M_NODE,
13101 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13102 install_element(BGP_IPV4L_NODE,
13103 &neighbor_addpath_tx_bestpath_per_as_cmd);
13104 install_element(BGP_IPV4L_NODE,
13105 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13106 install_element(BGP_IPV6_NODE,
13107 &neighbor_addpath_tx_bestpath_per_as_cmd);
13108 install_element(BGP_IPV6_NODE,
13109 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13110 install_element(BGP_IPV6M_NODE,
13111 &neighbor_addpath_tx_bestpath_per_as_cmd);
13112 install_element(BGP_IPV6M_NODE,
13113 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13114 install_element(BGP_IPV6L_NODE,
13115 &neighbor_addpath_tx_bestpath_per_as_cmd);
13116 install_element(BGP_IPV6L_NODE,
13117 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13118 install_element(BGP_VPNV4_NODE,
13119 &neighbor_addpath_tx_bestpath_per_as_cmd);
13120 install_element(BGP_VPNV4_NODE,
13121 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13122 install_element(BGP_VPNV6_NODE,
13123 &neighbor_addpath_tx_bestpath_per_as_cmd);
13124 install_element(BGP_VPNV6_NODE,
13125 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13126
13127 /* "neighbor passive" commands. */
13128 install_element(BGP_NODE, &neighbor_passive_cmd);
13129 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13130
13131
13132 /* "neighbor shutdown" commands. */
13133 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13134 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13135 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13136 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13137
13138 /* "neighbor capability extended-nexthop" commands.*/
13139 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13140 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13141
13142 /* "neighbor capability orf prefix-list" commands.*/
13143 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13144 install_element(BGP_NODE,
13145 &no_neighbor_capability_orf_prefix_hidden_cmd);
13146 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13147 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13148 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13149 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13150 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13151 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13152 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13153 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13154 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13155 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13156 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13157 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13158
13159 /* "neighbor capability dynamic" commands.*/
13160 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13161 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13162
13163 /* "neighbor dont-capability-negotiate" commands. */
13164 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13165 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13166
13167 /* "neighbor ebgp-multihop" commands. */
13168 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13169 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13170 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13171
13172 /* "neighbor disable-connected-check" commands. */
13173 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13174 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13175
47cbc09b
PM
13176 /* "neighbor enforce-first-as" commands. */
13177 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13178 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13179
d62a17ae 13180 /* "neighbor description" commands. */
13181 install_element(BGP_NODE, &neighbor_description_cmd);
13182 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13183 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13184
13185 /* "neighbor update-source" commands. "*/
13186 install_element(BGP_NODE, &neighbor_update_source_cmd);
13187 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13188
13189 /* "neighbor default-originate" commands. */
13190 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13191 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13192 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13193 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13194 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13195 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13196 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13197 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13198 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13199 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13200 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13201 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13202 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13203 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13204 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13205 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13206 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13207 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13208 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13209 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13210 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13211
13212 /* "neighbor port" commands. */
13213 install_element(BGP_NODE, &neighbor_port_cmd);
13214 install_element(BGP_NODE, &no_neighbor_port_cmd);
13215
13216 /* "neighbor weight" commands. */
13217 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13218 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13219
13220 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13221 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13222 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13223 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13224 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13225 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13226 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13227 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13228 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13229 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13230 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13231 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13232 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13233 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13234 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13235 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13236
13237 /* "neighbor override-capability" commands. */
13238 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13239 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13240
13241 /* "neighbor strict-capability-match" commands. */
13242 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13243 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13244
13245 /* "neighbor timers" commands. */
13246 install_element(BGP_NODE, &neighbor_timers_cmd);
13247 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13248
13249 /* "neighbor timers connect" commands. */
13250 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13251 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13252
13253 /* "neighbor advertisement-interval" commands. */
13254 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13255 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13256
13257 /* "neighbor interface" commands. */
13258 install_element(BGP_NODE, &neighbor_interface_cmd);
13259 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13260
13261 /* "neighbor distribute" commands. */
13262 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13263 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13264 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13265 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13266 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13267 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13268 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13269 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13270 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13271 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13272 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13273 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13274 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13275 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13276 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13277 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13278 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13279 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13280
13281 /* "neighbor prefix-list" commands. */
13282 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13283 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13284 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13285 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13286 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13287 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13288 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13289 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13290 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13291 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13292 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13293 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13294 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13295 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13296 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13297 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13298 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13299 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13300 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13301 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13302 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13303 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13304
13305 /* "neighbor filter-list" commands. */
13306 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13307 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13308 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13309 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13310 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13311 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13312 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13313 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13314 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13315 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13316 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13317 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13318 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13319 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13320 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13321 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13322 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13323 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13324 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13325 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13326 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13327 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13328
13329 /* "neighbor route-map" commands. */
13330 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13331 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13332 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13333 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13334 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13335 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13336 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13337 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13338 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13339 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13340 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13341 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13342 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13343 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13344 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13345 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13346 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13347 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13348 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13349 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13350 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13351 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13352 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13353 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13354
13355 /* "neighbor unsuppress-map" commands. */
13356 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13357 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13358 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13359 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13360 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13361 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13362 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13363 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13364 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13365 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13366 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13367 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13368 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13369 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13370 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13371 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13372 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13373 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13374
13375 /* "neighbor maximum-prefix" commands. */
13376 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13377 install_element(BGP_NODE,
13378 &neighbor_maximum_prefix_threshold_hidden_cmd);
13379 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13380 install_element(BGP_NODE,
13381 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13382 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13383 install_element(BGP_NODE,
13384 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13385 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13386 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13387 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13388 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13389 install_element(BGP_IPV4_NODE,
13390 &neighbor_maximum_prefix_threshold_warning_cmd);
13391 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13392 install_element(BGP_IPV4_NODE,
13393 &neighbor_maximum_prefix_threshold_restart_cmd);
13394 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13395 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13396 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13397 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13398 install_element(BGP_IPV4M_NODE,
13399 &neighbor_maximum_prefix_threshold_warning_cmd);
13400 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13401 install_element(BGP_IPV4M_NODE,
13402 &neighbor_maximum_prefix_threshold_restart_cmd);
13403 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13404 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13405 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13406 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13407 install_element(BGP_IPV4L_NODE,
13408 &neighbor_maximum_prefix_threshold_warning_cmd);
13409 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13410 install_element(BGP_IPV4L_NODE,
13411 &neighbor_maximum_prefix_threshold_restart_cmd);
13412 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13413 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13414 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13415 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13416 install_element(BGP_IPV6_NODE,
13417 &neighbor_maximum_prefix_threshold_warning_cmd);
13418 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13419 install_element(BGP_IPV6_NODE,
13420 &neighbor_maximum_prefix_threshold_restart_cmd);
13421 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13422 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13423 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13424 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13425 install_element(BGP_IPV6M_NODE,
13426 &neighbor_maximum_prefix_threshold_warning_cmd);
13427 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13428 install_element(BGP_IPV6M_NODE,
13429 &neighbor_maximum_prefix_threshold_restart_cmd);
13430 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13431 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13432 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13433 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13434 install_element(BGP_IPV6L_NODE,
13435 &neighbor_maximum_prefix_threshold_warning_cmd);
13436 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13437 install_element(BGP_IPV6L_NODE,
13438 &neighbor_maximum_prefix_threshold_restart_cmd);
13439 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13440 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13441 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13442 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13443 install_element(BGP_VPNV4_NODE,
13444 &neighbor_maximum_prefix_threshold_warning_cmd);
13445 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13446 install_element(BGP_VPNV4_NODE,
13447 &neighbor_maximum_prefix_threshold_restart_cmd);
13448 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13449 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13450 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13451 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13452 install_element(BGP_VPNV6_NODE,
13453 &neighbor_maximum_prefix_threshold_warning_cmd);
13454 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13455 install_element(BGP_VPNV6_NODE,
13456 &neighbor_maximum_prefix_threshold_restart_cmd);
13457 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13458
13459 /* "neighbor allowas-in" */
13460 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13461 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13462 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13463 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13464 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13465 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13466 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13467 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13468 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13469 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13470 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13471 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13472 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13473 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13474 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13475 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13476 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13477 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13478 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13479 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13480
13481 /* address-family commands. */
13482 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13483 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13484#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13485 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13486 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13487#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13488
d62a17ae 13489 install_element(BGP_NODE, &address_family_evpn_cmd);
13490
13491 /* "exit-address-family" command. */
13492 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13493 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13494 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13495 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13496 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13497 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13498 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13499 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13500 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13501 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13502 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13503
13504 /* "clear ip bgp commands" */
13505 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13506
13507 /* clear ip bgp prefix */
13508 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13509 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13510 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13511
13512 /* "show [ip] bgp summary" commands. */
13513 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
d62a17ae 13514 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13515 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13516 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13517 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13518 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13519
13520 /* "show [ip] bgp neighbors" commands. */
13521 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13522
13523 /* "show [ip] bgp peer-group" commands. */
13524 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13525
13526 /* "show [ip] bgp paths" commands. */
13527 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13528
13529 /* "show [ip] bgp community" commands. */
13530 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13531
13532 /* "show ip bgp large-community" commands. */
13533 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13534 /* "show [ip] bgp attribute-info" commands. */
13535 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13536 /* "show [ip] bgp route-leak" command */
13537 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13538
13539 /* "redistribute" commands. */
13540 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13541 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13542 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13543 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13544 install_element(BGP_NODE,
13545 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13546 install_element(BGP_NODE,
13547 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13548 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13549 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13550 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13551 install_element(BGP_NODE,
13552 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13553 install_element(BGP_NODE,
13554 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13555 install_element(BGP_NODE,
13556 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13557 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13558 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13559 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13560 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13561 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13562 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13563 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13564 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13565 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13566 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13567 install_element(BGP_IPV4_NODE,
13568 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13569 install_element(BGP_IPV4_NODE,
13570 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13571 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13572 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13573 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13574 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13575 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13576 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13577
b9c7bc5a
PZ
13578 /* import|export vpn [route-map WORD] */
13579 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13580 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13581
12a844a5
DS
13582 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13583 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13584
d62a17ae 13585 /* ttl_security commands */
13586 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13587 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13588
13589 /* "show [ip] bgp memory" commands. */
13590 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13591
acf71666
MK
13592 /* "show bgp martian next-hop" */
13593 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13594
d62a17ae 13595 /* "show [ip] bgp views" commands. */
13596 install_element(VIEW_NODE, &show_bgp_views_cmd);
13597
13598 /* "show [ip] bgp vrfs" commands. */
13599 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13600
13601 /* Community-list. */
13602 community_list_vty();
ddb5b488
PZ
13603
13604 /* vpn-policy commands */
b9c7bc5a
PZ
13605 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13606 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13607 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13608 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13609 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13610 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13611 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13612 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13613 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13614 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
13615 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13616 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 13617
301ad80a
PG
13618 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13619 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13620
b9c7bc5a
PZ
13621 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13622 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13623 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13624 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13625 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13626 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13627 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13628 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13629 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13630 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
13631 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13632 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 13633}
6b0655a2 13634
718e3744 13635#include "memory.h"
13636#include "bgp_regex.h"
13637#include "bgp_clist.h"
13638#include "bgp_ecommunity.h"
13639
13640/* VTY functions. */
13641
13642/* Direction value to string conversion. */
d62a17ae 13643static const char *community_direct_str(int direct)
13644{
13645 switch (direct) {
13646 case COMMUNITY_DENY:
13647 return "deny";
13648 case COMMUNITY_PERMIT:
13649 return "permit";
13650 default:
13651 return "unknown";
13652 }
718e3744 13653}
13654
13655/* Display error string. */
d62a17ae 13656static void community_list_perror(struct vty *vty, int ret)
13657{
13658 switch (ret) {
13659 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13660 vty_out(vty, "%% Can't find community-list\n");
13661 break;
13662 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13663 vty_out(vty, "%% Malformed community-list value\n");
13664 break;
13665 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13666 vty_out(vty,
13667 "%% Community name conflict, previously defined as standard community\n");
13668 break;
13669 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13670 vty_out(vty,
13671 "%% Community name conflict, previously defined as expanded community\n");
13672 break;
13673 }
718e3744 13674}
13675
5bf15956
DW
13676/* "community-list" keyword help string. */
13677#define COMMUNITY_LIST_STR "Add a community list entry\n"
13678
5bf15956 13679/* ip community-list standard */
718e3744 13680DEFUN (ip_community_list_standard,
13681 ip_community_list_standard_cmd,
e961923c 13682 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13683 IP_STR
13684 COMMUNITY_LIST_STR
13685 "Community list number (standard)\n"
5bf15956 13686 "Add an standard community-list entry\n"
718e3744 13687 "Community list name\n"
13688 "Specify community to reject\n"
13689 "Specify community to accept\n"
13690 COMMUNITY_VAL_STR)
13691{
d62a17ae 13692 char *cl_name_or_number = NULL;
13693 int direct = 0;
13694 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13695
d62a17ae 13696 int idx = 0;
13697 argv_find(argv, argc, "(1-99)", &idx);
13698 argv_find(argv, argc, "WORD", &idx);
13699 cl_name_or_number = argv[idx]->arg;
13700 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13701 : COMMUNITY_DENY;
13702 argv_find(argv, argc, "AA:NN", &idx);
13703 char *str = argv_concat(argv, argc, idx);
42f914d4 13704
d62a17ae 13705 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13706 style);
42f914d4 13707
d62a17ae 13708 XFREE(MTYPE_TMP, str);
42f914d4 13709
d62a17ae 13710 if (ret < 0) {
13711 /* Display error string. */
13712 community_list_perror(vty, ret);
13713 return CMD_WARNING_CONFIG_FAILED;
13714 }
42f914d4 13715
d62a17ae 13716 return CMD_SUCCESS;
718e3744 13717}
13718
fee6e4e4 13719DEFUN (no_ip_community_list_standard_all,
13720 no_ip_community_list_standard_all_cmd,
e961923c 13721 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13722 NO_STR
13723 IP_STR
13724 COMMUNITY_LIST_STR
13725 "Community list number (standard)\n"
5bf15956
DW
13726 "Add an standard community-list entry\n"
13727 "Community list name\n"
718e3744 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_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13746 direct, style);
42f914d4 13747
d62a17ae 13748 XFREE(MTYPE_TMP, str);
daf9ddbb 13749
d62a17ae 13750 if (ret < 0) {
13751 community_list_perror(vty, ret);
13752 return CMD_WARNING_CONFIG_FAILED;
13753 }
42f914d4 13754
d62a17ae 13755 return CMD_SUCCESS;
718e3744 13756}
13757
5bf15956
DW
13758/* ip community-list expanded */
13759DEFUN (ip_community_list_expanded_all,
13760 ip_community_list_expanded_all_cmd,
42f914d4 13761 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13762 IP_STR
13763 COMMUNITY_LIST_STR
13764 "Community list number (expanded)\n"
5bf15956 13765 "Add an expanded community-list entry\n"
718e3744 13766 "Community list name\n"
13767 "Specify community to reject\n"
13768 "Specify community to accept\n"
13769 COMMUNITY_VAL_STR)
13770{
d62a17ae 13771 char *cl_name_or_number = NULL;
13772 int direct = 0;
13773 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13774
d62a17ae 13775 int idx = 0;
13776 argv_find(argv, argc, "(100-500)", &idx);
13777 argv_find(argv, argc, "WORD", &idx);
13778 cl_name_or_number = argv[idx]->arg;
13779 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13780 : COMMUNITY_DENY;
13781 argv_find(argv, argc, "AA:NN", &idx);
13782 char *str = argv_concat(argv, argc, idx);
42f914d4 13783
d62a17ae 13784 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13785 style);
42f914d4 13786
d62a17ae 13787 XFREE(MTYPE_TMP, str);
42f914d4 13788
d62a17ae 13789 if (ret < 0) {
13790 /* Display error string. */
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
13798DEFUN (no_ip_community_list_expanded_all,
13799 no_ip_community_list_expanded_all_cmd,
42f914d4 13800 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13801 NO_STR
13802 IP_STR
13803 COMMUNITY_LIST_STR
5bf15956
DW
13804 "Community list number (expanded)\n"
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"
5bf15956 13809 COMMUNITY_VAL_STR)
718e3744 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_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13825 direct, style);
42f914d4 13826
d62a17ae 13827 XFREE(MTYPE_TMP, str);
daf9ddbb 13828
d62a17ae 13829 if (ret < 0) {
13830 community_list_perror(vty, ret);
13831 return CMD_WARNING_CONFIG_FAILED;
13832 }
42f914d4 13833
d62a17ae 13834 return CMD_SUCCESS;
718e3744 13835}
13836
8d9b8ed9
PM
13837/* Return configuration string of community-list entry. */
13838static const char *community_list_config_str(struct community_entry *entry)
13839{
13840 const char *str;
13841
13842 if (entry->any)
13843 str = "";
13844 else {
13845 if (entry->style == COMMUNITY_LIST_STANDARD)
13846 str = community_str(entry->u.com, false);
13847 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13848 str = lcommunity_str(entry->u.lcom, false);
13849 else
13850 str = entry->config;
13851 }
13852 return str;
13853}
13854
d62a17ae 13855static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 13856{
d62a17ae 13857 struct community_entry *entry;
718e3744 13858
d62a17ae 13859 for (entry = list->head; entry; entry = entry->next) {
13860 if (entry == list->head) {
13861 if (all_digit(list->name))
13862 vty_out(vty, "Community %s list %s\n",
13863 entry->style == COMMUNITY_LIST_STANDARD
13864 ? "standard"
13865 : "(expanded) access",
13866 list->name);
13867 else
13868 vty_out(vty, "Named Community %s list %s\n",
13869 entry->style == COMMUNITY_LIST_STANDARD
13870 ? "standard"
13871 : "expanded",
13872 list->name);
13873 }
13874 if (entry->any)
13875 vty_out(vty, " %s\n",
13876 community_direct_str(entry->direct));
13877 else
13878 vty_out(vty, " %s %s\n",
13879 community_direct_str(entry->direct),
8d9b8ed9 13880 community_list_config_str(entry));
d62a17ae 13881 }
718e3744 13882}
13883
13884DEFUN (show_ip_community_list,
13885 show_ip_community_list_cmd,
13886 "show ip community-list",
13887 SHOW_STR
13888 IP_STR
13889 "List community-list\n")
13890{
d62a17ae 13891 struct community_list *list;
13892 struct community_list_master *cm;
718e3744 13893
d62a17ae 13894 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13895 if (!cm)
13896 return CMD_SUCCESS;
718e3744 13897
d62a17ae 13898 for (list = cm->num.head; list; list = list->next)
13899 community_list_show(vty, list);
718e3744 13900
d62a17ae 13901 for (list = cm->str.head; list; list = list->next)
13902 community_list_show(vty, list);
718e3744 13903
d62a17ae 13904 return CMD_SUCCESS;
718e3744 13905}
13906
13907DEFUN (show_ip_community_list_arg,
13908 show_ip_community_list_arg_cmd,
6147e2c6 13909 "show ip community-list <(1-500)|WORD>",
718e3744 13910 SHOW_STR
13911 IP_STR
13912 "List community-list\n"
13913 "Community-list number\n"
13914 "Community-list name\n")
13915{
d62a17ae 13916 int idx_comm_list = 3;
13917 struct community_list *list;
718e3744 13918
d62a17ae 13919 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13920 COMMUNITY_LIST_MASTER);
13921 if (!list) {
13922 vty_out(vty, "%% Can't find community-list\n");
13923 return CMD_WARNING;
13924 }
718e3744 13925
d62a17ae 13926 community_list_show(vty, list);
718e3744 13927
d62a17ae 13928 return CMD_SUCCESS;
718e3744 13929}
6b0655a2 13930
57d187bc
JS
13931/*
13932 * Large Community code.
13933 */
d62a17ae 13934static int lcommunity_list_set_vty(struct vty *vty, int argc,
13935 struct cmd_token **argv, int style,
13936 int reject_all_digit_name)
13937{
13938 int ret;
13939 int direct;
13940 char *str;
13941 int idx = 0;
13942 char *cl_name;
13943
13944 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13945 : COMMUNITY_DENY;
13946
13947 /* All digit name check. */
13948 idx = 0;
13949 argv_find(argv, argc, "WORD", &idx);
13950 argv_find(argv, argc, "(1-99)", &idx);
13951 argv_find(argv, argc, "(100-500)", &idx);
13952 cl_name = argv[idx]->arg;
13953 if (reject_all_digit_name && all_digit(cl_name)) {
13954 vty_out(vty, "%% Community name cannot have all digits\n");
13955 return CMD_WARNING_CONFIG_FAILED;
13956 }
13957
13958 idx = 0;
13959 argv_find(argv, argc, "AA:BB:CC", &idx);
13960 argv_find(argv, argc, "LINE", &idx);
13961 /* Concat community string argument. */
13962 if (idx)
13963 str = argv_concat(argv, argc, idx);
13964 else
13965 str = NULL;
13966
13967 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13968
13969 /* Free temporary community list string allocated by
13970 argv_concat(). */
13971 if (str)
13972 XFREE(MTYPE_TMP, str);
13973
13974 if (ret < 0) {
13975 community_list_perror(vty, ret);
13976 return CMD_WARNING_CONFIG_FAILED;
13977 }
13978 return CMD_SUCCESS;
13979}
13980
13981static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13982 struct cmd_token **argv, int style)
13983{
13984 int ret;
13985 int direct = 0;
13986 char *str = NULL;
13987 int idx = 0;
13988
13989 argv_find(argv, argc, "permit", &idx);
13990 argv_find(argv, argc, "deny", &idx);
13991
13992 if (idx) {
13993 /* Check the list direct. */
13994 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13995 direct = COMMUNITY_PERMIT;
13996 else
13997 direct = COMMUNITY_DENY;
13998
13999 idx = 0;
14000 argv_find(argv, argc, "LINE", &idx);
14001 argv_find(argv, argc, "AA:AA:NN", &idx);
14002 /* Concat community string argument. */
14003 str = argv_concat(argv, argc, idx);
14004 }
14005
14006 idx = 0;
14007 argv_find(argv, argc, "(1-99)", &idx);
14008 argv_find(argv, argc, "(100-500)", &idx);
14009 argv_find(argv, argc, "WORD", &idx);
14010
14011 /* Unset community list. */
14012 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14013 style);
14014
14015 /* Free temporary community list string allocated by
14016 argv_concat(). */
14017 if (str)
14018 XFREE(MTYPE_TMP, str);
14019
14020 if (ret < 0) {
14021 community_list_perror(vty, ret);
14022 return CMD_WARNING_CONFIG_FAILED;
14023 }
14024
14025 return CMD_SUCCESS;
57d187bc
JS
14026}
14027
14028/* "large-community-list" keyword help string. */
14029#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14030#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14031
14032DEFUN (ip_lcommunity_list_standard,
14033 ip_lcommunity_list_standard_cmd,
52951b63
DS
14034 "ip large-community-list (1-99) <deny|permit>",
14035 IP_STR
14036 LCOMMUNITY_LIST_STR
14037 "Large Community list number (standard)\n"
14038 "Specify large community to reject\n"
7111c1a0 14039 "Specify large community to accept\n")
52951b63 14040{
d62a17ae 14041 return lcommunity_list_set_vty(vty, argc, argv,
14042 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
14043}
14044
14045DEFUN (ip_lcommunity_list_standard1,
14046 ip_lcommunity_list_standard1_cmd,
14047 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
14048 IP_STR
14049 LCOMMUNITY_LIST_STR
14050 "Large Community list number (standard)\n"
14051 "Specify large community to reject\n"
14052 "Specify large community to accept\n"
14053 LCOMMUNITY_VAL_STR)
14054{
d62a17ae 14055 return lcommunity_list_set_vty(vty, argc, argv,
14056 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
14057}
14058
14059DEFUN (ip_lcommunity_list_expanded,
14060 ip_lcommunity_list_expanded_cmd,
14061 "ip large-community-list (100-500) <deny|permit> LINE...",
14062 IP_STR
14063 LCOMMUNITY_LIST_STR
14064 "Large Community list number (expanded)\n"
14065 "Specify large community to reject\n"
14066 "Specify large community to accept\n"
14067 "An ordered list as a regular-expression\n")
14068{
d62a17ae 14069 return lcommunity_list_set_vty(vty, argc, argv,
14070 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
14071}
14072
14073DEFUN (ip_lcommunity_list_name_standard,
14074 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
14075 "ip large-community-list standard WORD <deny|permit>",
14076 IP_STR
14077 LCOMMUNITY_LIST_STR
14078 "Specify standard large-community-list\n"
14079 "Large Community list name\n"
14080 "Specify large community to reject\n"
14081 "Specify large community to accept\n")
14082{
d62a17ae 14083 return lcommunity_list_set_vty(vty, argc, argv,
14084 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
14085}
14086
14087DEFUN (ip_lcommunity_list_name_standard1,
14088 ip_lcommunity_list_name_standard1_cmd,
14089 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
14090 IP_STR
14091 LCOMMUNITY_LIST_STR
14092 "Specify standard large-community-list\n"
14093 "Large Community list name\n"
14094 "Specify large community to reject\n"
14095 "Specify large community to accept\n"
14096 LCOMMUNITY_VAL_STR)
14097{
d62a17ae 14098 return lcommunity_list_set_vty(vty, argc, argv,
14099 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
14100}
14101
14102DEFUN (ip_lcommunity_list_name_expanded,
14103 ip_lcommunity_list_name_expanded_cmd,
14104 "ip large-community-list expanded WORD <deny|permit> LINE...",
14105 IP_STR
14106 LCOMMUNITY_LIST_STR
14107 "Specify expanded large-community-list\n"
14108 "Large Community list name\n"
14109 "Specify large community to reject\n"
14110 "Specify large community to accept\n"
14111 "An ordered list as a regular-expression\n")
14112{
d62a17ae 14113 return lcommunity_list_set_vty(vty, argc, argv,
14114 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
14115}
14116
14117DEFUN (no_ip_lcommunity_list_standard_all,
14118 no_ip_lcommunity_list_standard_all_cmd,
14119 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14120 NO_STR
14121 IP_STR
14122 LCOMMUNITY_LIST_STR
14123 "Large Community list number (standard)\n"
14124 "Large Community list number (expanded)\n"
14125 "Large Community list name\n")
14126{
d62a17ae 14127 return lcommunity_list_unset_vty(vty, argc, argv,
14128 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14129}
14130
14131DEFUN (no_ip_lcommunity_list_name_expanded_all,
14132 no_ip_lcommunity_list_name_expanded_all_cmd,
14133 "no ip large-community-list expanded WORD",
14134 NO_STR
14135 IP_STR
14136 LCOMMUNITY_LIST_STR
14137 "Specify expanded large-community-list\n"
14138 "Large Community list name\n")
14139{
d62a17ae 14140 return lcommunity_list_unset_vty(vty, argc, argv,
14141 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14142}
14143
14144DEFUN (no_ip_lcommunity_list_standard,
14145 no_ip_lcommunity_list_standard_cmd,
14146 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14147 NO_STR
14148 IP_STR
14149 LCOMMUNITY_LIST_STR
14150 "Large Community list number (standard)\n"
14151 "Specify large community to reject\n"
14152 "Specify large community to accept\n"
14153 LCOMMUNITY_VAL_STR)
14154{
d62a17ae 14155 return lcommunity_list_unset_vty(vty, argc, argv,
14156 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14157}
14158
14159DEFUN (no_ip_lcommunity_list_expanded,
14160 no_ip_lcommunity_list_expanded_cmd,
14161 "no ip large-community-list (100-500) <deny|permit> LINE...",
14162 NO_STR
14163 IP_STR
14164 LCOMMUNITY_LIST_STR
14165 "Large Community list number (expanded)\n"
14166 "Specify large community to reject\n"
14167 "Specify large community to accept\n"
14168 "An ordered list as a regular-expression\n")
14169{
d62a17ae 14170 return lcommunity_list_unset_vty(vty, argc, argv,
14171 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14172}
14173
14174DEFUN (no_ip_lcommunity_list_name_standard,
14175 no_ip_lcommunity_list_name_standard_cmd,
14176 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14177 NO_STR
14178 IP_STR
14179 LCOMMUNITY_LIST_STR
14180 "Specify standard large-community-list\n"
14181 "Large Community list name\n"
14182 "Specify large community to reject\n"
14183 "Specify large community to accept\n"
14184 LCOMMUNITY_VAL_STR)
14185{
d62a17ae 14186 return lcommunity_list_unset_vty(vty, argc, argv,
14187 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14188}
14189
14190DEFUN (no_ip_lcommunity_list_name_expanded,
14191 no_ip_lcommunity_list_name_expanded_cmd,
14192 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14193 NO_STR
14194 IP_STR
14195 LCOMMUNITY_LIST_STR
14196 "Specify expanded large-community-list\n"
14197 "Large community list name\n"
14198 "Specify large community to reject\n"
14199 "Specify large community to accept\n"
14200 "An ordered list as a regular-expression\n")
14201{
d62a17ae 14202 return lcommunity_list_unset_vty(vty, argc, argv,
14203 LARGE_COMMUNITY_LIST_EXPANDED);
14204}
14205
14206static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14207{
14208 struct community_entry *entry;
14209
14210 for (entry = list->head; entry; entry = entry->next) {
14211 if (entry == list->head) {
14212 if (all_digit(list->name))
14213 vty_out(vty, "Large community %s list %s\n",
14214 entry->style == EXTCOMMUNITY_LIST_STANDARD
14215 ? "standard"
14216 : "(expanded) access",
14217 list->name);
14218 else
14219 vty_out(vty,
14220 "Named large community %s list %s\n",
14221 entry->style == EXTCOMMUNITY_LIST_STANDARD
14222 ? "standard"
14223 : "expanded",
14224 list->name);
14225 }
14226 if (entry->any)
14227 vty_out(vty, " %s\n",
14228 community_direct_str(entry->direct));
14229 else
14230 vty_out(vty, " %s %s\n",
14231 community_direct_str(entry->direct),
8d9b8ed9 14232 community_list_config_str(entry));
d62a17ae 14233 }
57d187bc
JS
14234}
14235
14236DEFUN (show_ip_lcommunity_list,
14237 show_ip_lcommunity_list_cmd,
14238 "show ip large-community-list",
14239 SHOW_STR
14240 IP_STR
14241 "List large-community list\n")
14242{
d62a17ae 14243 struct community_list *list;
14244 struct community_list_master *cm;
57d187bc 14245
d62a17ae 14246 cm = community_list_master_lookup(bgp_clist,
14247 LARGE_COMMUNITY_LIST_MASTER);
14248 if (!cm)
14249 return CMD_SUCCESS;
57d187bc 14250
d62a17ae 14251 for (list = cm->num.head; list; list = list->next)
14252 lcommunity_list_show(vty, list);
57d187bc 14253
d62a17ae 14254 for (list = cm->str.head; list; list = list->next)
14255 lcommunity_list_show(vty, list);
57d187bc 14256
d62a17ae 14257 return CMD_SUCCESS;
57d187bc
JS
14258}
14259
14260DEFUN (show_ip_lcommunity_list_arg,
14261 show_ip_lcommunity_list_arg_cmd,
14262 "show ip large-community-list <(1-500)|WORD>",
14263 SHOW_STR
14264 IP_STR
14265 "List large-community list\n"
14266 "large-community-list number\n"
14267 "large-community-list name\n")
14268{
d62a17ae 14269 struct community_list *list;
57d187bc 14270
d62a17ae 14271 list = community_list_lookup(bgp_clist, argv[3]->arg,
14272 LARGE_COMMUNITY_LIST_MASTER);
14273 if (!list) {
14274 vty_out(vty, "%% Can't find extcommunity-list\n");
14275 return CMD_WARNING;
14276 }
57d187bc 14277
d62a17ae 14278 lcommunity_list_show(vty, list);
57d187bc 14279
d62a17ae 14280 return CMD_SUCCESS;
57d187bc
JS
14281}
14282
718e3744 14283/* "extcommunity-list" keyword help string. */
14284#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14285#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14286
14287DEFUN (ip_extcommunity_list_standard,
14288 ip_extcommunity_list_standard_cmd,
e961923c 14289 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14290 IP_STR
14291 EXTCOMMUNITY_LIST_STR
14292 "Extended Community list number (standard)\n"
718e3744 14293 "Specify standard extcommunity-list\n"
5bf15956 14294 "Community list name\n"
718e3744 14295 "Specify community to reject\n"
14296 "Specify community to accept\n"
14297 EXTCOMMUNITY_VAL_STR)
14298{
d62a17ae 14299 int style = EXTCOMMUNITY_LIST_STANDARD;
14300 int direct = 0;
14301 char *cl_number_or_name = NULL;
42f914d4 14302
d62a17ae 14303 int idx = 0;
14304 argv_find(argv, argc, "(1-99)", &idx);
14305 argv_find(argv, argc, "WORD", &idx);
14306 cl_number_or_name = argv[idx]->arg;
14307 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14308 : COMMUNITY_DENY;
14309 argv_find(argv, argc, "AA:NN", &idx);
14310 char *str = argv_concat(argv, argc, idx);
42f914d4 14311
d62a17ae 14312 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14313 direct, style);
42f914d4 14314
d62a17ae 14315 XFREE(MTYPE_TMP, str);
42f914d4 14316
d62a17ae 14317 if (ret < 0) {
14318 community_list_perror(vty, ret);
14319 return CMD_WARNING_CONFIG_FAILED;
14320 }
42f914d4 14321
d62a17ae 14322 return CMD_SUCCESS;
718e3744 14323}
14324
718e3744 14325DEFUN (ip_extcommunity_list_name_expanded,
14326 ip_extcommunity_list_name_expanded_cmd,
e961923c 14327 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14328 IP_STR
14329 EXTCOMMUNITY_LIST_STR
5bf15956 14330 "Extended Community list number (expanded)\n"
718e3744 14331 "Specify expanded extcommunity-list\n"
14332 "Extended Community list name\n"
14333 "Specify community to reject\n"
14334 "Specify community to accept\n"
14335 "An ordered list as a regular-expression\n")
14336{
d62a17ae 14337 int style = EXTCOMMUNITY_LIST_EXPANDED;
14338 int direct = 0;
14339 char *cl_number_or_name = NULL;
42f914d4 14340
d62a17ae 14341 int idx = 0;
14342 argv_find(argv, argc, "(100-500)", &idx);
14343 argv_find(argv, argc, "WORD", &idx);
14344 cl_number_or_name = argv[idx]->arg;
14345 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14346 : COMMUNITY_DENY;
14347 argv_find(argv, argc, "LINE", &idx);
14348 char *str = argv_concat(argv, argc, idx);
42f914d4 14349
d62a17ae 14350 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14351 direct, style);
42f914d4 14352
d62a17ae 14353 XFREE(MTYPE_TMP, str);
42f914d4 14354
d62a17ae 14355 if (ret < 0) {
14356 community_list_perror(vty, ret);
14357 return CMD_WARNING_CONFIG_FAILED;
14358 }
42f914d4 14359
d62a17ae 14360 return CMD_SUCCESS;
718e3744 14361}
14362
fee6e4e4 14363DEFUN (no_ip_extcommunity_list_standard_all,
14364 no_ip_extcommunity_list_standard_all_cmd,
e961923c 14365 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
14366 NO_STR
14367 IP_STR
14368 EXTCOMMUNITY_LIST_STR
14369 "Extended Community list number (standard)\n"
718e3744 14370 "Specify standard extcommunity-list\n"
5bf15956 14371 "Community list name\n"
718e3744 14372 "Specify community to reject\n"
14373 "Specify community to accept\n"
14374 EXTCOMMUNITY_VAL_STR)
14375{
d62a17ae 14376 int style = EXTCOMMUNITY_LIST_STANDARD;
14377 int direct = 0;
14378 char *cl_number_or_name = NULL;
42f914d4 14379
d62a17ae 14380 int idx = 0;
14381 argv_find(argv, argc, "(1-99)", &idx);
14382 argv_find(argv, argc, "WORD", &idx);
14383 cl_number_or_name = argv[idx]->arg;
14384 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14385 : COMMUNITY_DENY;
14386 argv_find(argv, argc, "AA:NN", &idx);
14387 char *str = argv_concat(argv, argc, idx);
42f914d4 14388
d62a17ae 14389 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14390 direct, style);
42f914d4 14391
d62a17ae 14392 XFREE(MTYPE_TMP, str);
42f914d4 14393
d62a17ae 14394 if (ret < 0) {
14395 community_list_perror(vty, ret);
14396 return CMD_WARNING_CONFIG_FAILED;
14397 }
42f914d4 14398
d62a17ae 14399 return CMD_SUCCESS;
718e3744 14400}
14401
5bf15956
DW
14402DEFUN (no_ip_extcommunity_list_expanded_all,
14403 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 14404 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14405 NO_STR
14406 IP_STR
14407 EXTCOMMUNITY_LIST_STR
14408 "Extended Community list number (expanded)\n"
718e3744 14409 "Specify expanded extcommunity-list\n"
5bf15956 14410 "Extended Community list name\n"
718e3744 14411 "Specify community to reject\n"
14412 "Specify community to accept\n"
14413 "An ordered list as a regular-expression\n")
14414{
d62a17ae 14415 int style = EXTCOMMUNITY_LIST_EXPANDED;
14416 int direct = 0;
14417 char *cl_number_or_name = NULL;
42f914d4 14418
d62a17ae 14419 int idx = 0;
14420 argv_find(argv, argc, "(100-500)", &idx);
14421 argv_find(argv, argc, "WORD", &idx);
14422 cl_number_or_name = argv[idx]->arg;
14423 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14424 : COMMUNITY_DENY;
14425 argv_find(argv, argc, "LINE", &idx);
14426 char *str = argv_concat(argv, argc, idx);
42f914d4 14427
d62a17ae 14428 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14429 direct, style);
42f914d4 14430
d62a17ae 14431 XFREE(MTYPE_TMP, str);
42f914d4 14432
d62a17ae 14433 if (ret < 0) {
14434 community_list_perror(vty, ret);
14435 return CMD_WARNING_CONFIG_FAILED;
14436 }
42f914d4 14437
d62a17ae 14438 return CMD_SUCCESS;
718e3744 14439}
14440
d62a17ae 14441static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 14442{
d62a17ae 14443 struct community_entry *entry;
718e3744 14444
d62a17ae 14445 for (entry = list->head; entry; entry = entry->next) {
14446 if (entry == list->head) {
14447 if (all_digit(list->name))
14448 vty_out(vty, "Extended community %s list %s\n",
14449 entry->style == EXTCOMMUNITY_LIST_STANDARD
14450 ? "standard"
14451 : "(expanded) access",
14452 list->name);
14453 else
14454 vty_out(vty,
14455 "Named extended community %s list %s\n",
14456 entry->style == EXTCOMMUNITY_LIST_STANDARD
14457 ? "standard"
14458 : "expanded",
14459 list->name);
14460 }
14461 if (entry->any)
14462 vty_out(vty, " %s\n",
14463 community_direct_str(entry->direct));
14464 else
14465 vty_out(vty, " %s %s\n",
14466 community_direct_str(entry->direct),
8d9b8ed9 14467 community_list_config_str(entry));
d62a17ae 14468 }
718e3744 14469}
14470
14471DEFUN (show_ip_extcommunity_list,
14472 show_ip_extcommunity_list_cmd,
14473 "show ip extcommunity-list",
14474 SHOW_STR
14475 IP_STR
14476 "List extended-community list\n")
14477{
d62a17ae 14478 struct community_list *list;
14479 struct community_list_master *cm;
718e3744 14480
d62a17ae 14481 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14482 if (!cm)
14483 return CMD_SUCCESS;
718e3744 14484
d62a17ae 14485 for (list = cm->num.head; list; list = list->next)
14486 extcommunity_list_show(vty, list);
718e3744 14487
d62a17ae 14488 for (list = cm->str.head; list; list = list->next)
14489 extcommunity_list_show(vty, list);
718e3744 14490
d62a17ae 14491 return CMD_SUCCESS;
718e3744 14492}
14493
14494DEFUN (show_ip_extcommunity_list_arg,
14495 show_ip_extcommunity_list_arg_cmd,
6147e2c6 14496 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 14497 SHOW_STR
14498 IP_STR
14499 "List extended-community list\n"
14500 "Extcommunity-list number\n"
14501 "Extcommunity-list name\n")
14502{
d62a17ae 14503 int idx_comm_list = 3;
14504 struct community_list *list;
718e3744 14505
d62a17ae 14506 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14507 EXTCOMMUNITY_LIST_MASTER);
14508 if (!list) {
14509 vty_out(vty, "%% Can't find extcommunity-list\n");
14510 return CMD_WARNING;
14511 }
718e3744 14512
d62a17ae 14513 extcommunity_list_show(vty, list);
718e3744 14514
d62a17ae 14515 return CMD_SUCCESS;
718e3744 14516}
6b0655a2 14517
718e3744 14518/* Display community-list and extcommunity-list configuration. */
d62a17ae 14519static int community_list_config_write(struct vty *vty)
14520{
14521 struct community_list *list;
14522 struct community_entry *entry;
14523 struct community_list_master *cm;
14524 int write = 0;
14525
14526 /* Community-list. */
14527 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14528
14529 for (list = cm->num.head; list; list = list->next)
14530 for (entry = list->head; entry; entry = entry->next) {
14531 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14532 community_direct_str(entry->direct),
14533 community_list_config_str(entry));
14534 write++;
14535 }
14536 for (list = cm->str.head; list; list = list->next)
14537 for (entry = list->head; entry; entry = entry->next) {
14538 vty_out(vty, "ip community-list %s %s %s %s\n",
14539 entry->style == COMMUNITY_LIST_STANDARD
14540 ? "standard"
14541 : "expanded",
14542 list->name, community_direct_str(entry->direct),
14543 community_list_config_str(entry));
14544 write++;
14545 }
14546
14547 /* Extcommunity-list. */
14548 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14549
14550 for (list = cm->num.head; list; list = list->next)
14551 for (entry = list->head; entry; entry = entry->next) {
14552 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14553 list->name, community_direct_str(entry->direct),
14554 community_list_config_str(entry));
14555 write++;
14556 }
14557 for (list = cm->str.head; list; list = list->next)
14558 for (entry = list->head; entry; entry = entry->next) {
14559 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14560 entry->style == EXTCOMMUNITY_LIST_STANDARD
14561 ? "standard"
14562 : "expanded",
14563 list->name, community_direct_str(entry->direct),
14564 community_list_config_str(entry));
14565 write++;
14566 }
14567
14568
14569 /* lcommunity-list. */
14570 cm = community_list_master_lookup(bgp_clist,
14571 LARGE_COMMUNITY_LIST_MASTER);
14572
14573 for (list = cm->num.head; list; list = list->next)
14574 for (entry = list->head; entry; entry = entry->next) {
14575 vty_out(vty, "ip large-community-list %s %s %s\n",
14576 list->name, community_direct_str(entry->direct),
14577 community_list_config_str(entry));
14578 write++;
14579 }
14580 for (list = cm->str.head; list; list = list->next)
14581 for (entry = list->head; entry; entry = entry->next) {
14582 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14583 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14584 ? "standard"
14585 : "expanded",
14586 list->name, community_direct_str(entry->direct),
14587 community_list_config_str(entry));
14588 write++;
14589 }
14590
14591 return write;
14592}
14593
14594static struct cmd_node community_list_node = {
14595 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 14596};
14597
d62a17ae 14598static void community_list_vty(void)
14599{
14600 install_node(&community_list_node, community_list_config_write);
14601
14602 /* Community-list. */
14603 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14604 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14605 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14606 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14607 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14608 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14609
14610 /* Extcommunity-list. */
14611 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14612 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14613 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14614 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14615 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14616 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14617
14618 /* Large Community List */
14619 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14620 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14621 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14622 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14623 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14624 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14625 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14626 install_element(CONFIG_NODE,
14627 &no_ip_lcommunity_list_name_expanded_all_cmd);
14628 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14629 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14630 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14631 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14632 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14633 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 14634}