]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #5288 from SumitAgarwal123/bfd_docs
[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"
5cb5f4d0 25#include "lib_errors.h"
ec0ab544 26#include "lib/zclient.h"
718e3744 27#include "prefix.h"
28#include "plist.h"
29#include "buffer.h"
30#include "linklist.h"
31#include "stream.h"
32#include "thread.h"
33#include "log.h"
3b8b1855 34#include "memory.h"
fc7948fa 35#include "memory_vty.h"
4bf6a362 36#include "hash.h"
3f9c7369 37#include "queue.h"
039f3a34 38#include "filter.h"
5d5ba018 39#include "frrstr.h"
718e3744 40
41#include "bgpd/bgpd.h"
48ecf8f5 42#include "bgpd/bgp_attr_evpn.h"
4bf6a362 43#include "bgpd/bgp_advertise.h"
718e3744 44#include "bgpd/bgp_attr.h"
45#include "bgpd/bgp_aspath.h"
46#include "bgpd/bgp_community.h"
4bf6a362 47#include "bgpd/bgp_ecommunity.h"
57d187bc 48#include "bgpd/bgp_lcommunity.h"
4bf6a362 49#include "bgpd/bgp_damp.h"
718e3744 50#include "bgpd/bgp_debug.h"
14454c9f 51#include "bgpd/bgp_errors.h"
e0701b79 52#include "bgpd/bgp_fsm.h"
4bf6a362 53#include "bgpd/bgp_nexthop.h"
718e3744 54#include "bgpd/bgp_open.h"
4bf6a362 55#include "bgpd/bgp_regex.h"
718e3744 56#include "bgpd/bgp_route.h"
c016b6c7 57#include "bgpd/bgp_mplsvpn.h"
718e3744 58#include "bgpd/bgp_zebra.h"
fee0f4c6 59#include "bgpd/bgp_table.h"
94f2b392 60#include "bgpd/bgp_vty.h"
165b5fff 61#include "bgpd/bgp_mpath.h"
cb1faec9 62#include "bgpd/bgp_packet.h"
3f9c7369 63#include "bgpd/bgp_updgrp.h"
c43ed2e4 64#include "bgpd/bgp_bfd.h"
555e09d4 65#include "bgpd/bgp_io.h"
94c2f693 66#include "bgpd/bgp_evpn.h"
dcc68b5e 67#include "bgpd/bgp_addpath.h"
48ecf8f5 68#include "bgpd/bgp_mac.h"
718e3744 69
d62a17ae 70static struct peer_group *listen_range_exists(struct bgp *bgp,
71 struct prefix *range, int exact);
72
73static enum node_type bgp_node_type(afi_t afi, safi_t safi)
74{
75 switch (afi) {
76 case AFI_IP:
77 switch (safi) {
78 case SAFI_UNICAST:
79 return BGP_IPV4_NODE;
80 break;
81 case SAFI_MULTICAST:
82 return BGP_IPV4M_NODE;
83 break;
84 case SAFI_LABELED_UNICAST:
85 return BGP_IPV4L_NODE;
86 break;
87 case SAFI_MPLS_VPN:
88 return BGP_VPNV4_NODE;
89 break;
7c40bf39 90 case SAFI_FLOWSPEC:
91 return BGP_FLOWSPECV4_NODE;
5c525538
RW
92 default:
93 /* not expected */
94 return BGP_IPV4_NODE;
95 break;
d62a17ae 96 }
97 break;
98 case AFI_IP6:
99 switch (safi) {
100 case SAFI_UNICAST:
101 return BGP_IPV6_NODE;
102 break;
103 case SAFI_MULTICAST:
104 return BGP_IPV6M_NODE;
105 break;
106 case SAFI_LABELED_UNICAST:
107 return BGP_IPV6L_NODE;
108 break;
109 case SAFI_MPLS_VPN:
110 return BGP_VPNV6_NODE;
111 break;
7c40bf39 112 case SAFI_FLOWSPEC:
113 return BGP_FLOWSPECV6_NODE;
5c525538
RW
114 default:
115 /* not expected */
116 return BGP_IPV4_NODE;
117 break;
d62a17ae 118 }
119 break;
120 case AFI_L2VPN:
121 return BGP_EVPN_NODE;
122 break;
b26f891d 123 case AFI_UNSPEC:
d62a17ae 124 case AFI_MAX:
125 // We should never be here but to clarify the switch statement..
126 return BGP_IPV4_NODE;
127 break;
128 }
129
130 // Impossible to happen
131 return BGP_IPV4_NODE;
f51bae9c 132}
20eb8864 133
5cb5f4d0
DD
134static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
135{
136 if (afi == AFI_IP && safi == SAFI_UNICAST)
137 return "IPv4 Unicast";
138 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
139 return "IPv4 Multicast";
140 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
141 return "IPv4 Labeled Unicast";
142 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
143 return "IPv4 VPN";
144 else if (afi == AFI_IP && safi == SAFI_ENCAP)
145 return "IPv4 Encap";
146 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
147 return "IPv4 Flowspec";
148 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
149 return "IPv6 Unicast";
150 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
151 return "IPv6 Multicast";
152 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
153 return "IPv6 Labeled Unicast";
154 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
155 return "IPv6 VPN";
156 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
157 return "IPv6 Encap";
158 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
159 return "IPv6 Flowspec";
160 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
161 return "L2VPN EVPN";
8e5509b0 162 else
5cb5f4d0 163 return "Unknown";
5cb5f4d0
DD
164}
165
166/*
167 * Please note that we have intentionally camelCased
168 * the return strings here. So if you want
169 * to use this function, please ensure you
170 * are doing this within json output
171 */
172static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
173{
174 if (afi == AFI_IP && safi == SAFI_UNICAST)
175 return "ipv4Unicast";
176 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
177 return "ipv4Multicast";
178 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
179 return "ipv4LabeledUnicast";
180 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
181 return "ipv4Vpn";
182 else if (afi == AFI_IP && safi == SAFI_ENCAP)
183 return "ipv4Encap";
184 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
185 return "ipv4Flowspec";
186 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
187 return "ipv6Unicast";
188 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
189 return "ipv6Multicast";
190 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
191 return "ipv6LabeledUnicast";
192 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
193 return "ipv6Vpn";
194 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
195 return "ipv6Encap";
196 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
197 return "ipv6Flowspec";
198 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
199 return "l2VpnEvpn";
8e5509b0 200 else
5cb5f4d0 201 return "Unknown";
5cb5f4d0
DD
202}
203
718e3744 204/* Utility function to get address family from current node. */
d62a17ae 205afi_t bgp_node_afi(struct vty *vty)
206{
207 afi_t afi;
208 switch (vty->node) {
209 case BGP_IPV6_NODE:
210 case BGP_IPV6M_NODE:
211 case BGP_IPV6L_NODE:
212 case BGP_VPNV6_NODE:
7c40bf39 213 case BGP_FLOWSPECV6_NODE:
d62a17ae 214 afi = AFI_IP6;
215 break;
216 case BGP_EVPN_NODE:
217 afi = AFI_L2VPN;
218 break;
219 default:
220 afi = AFI_IP;
221 break;
222 }
223 return afi;
718e3744 224}
225
226/* Utility function to get subsequent address family from current
227 node. */
d62a17ae 228safi_t bgp_node_safi(struct vty *vty)
229{
230 safi_t safi;
231 switch (vty->node) {
232 case BGP_VPNV4_NODE:
233 case BGP_VPNV6_NODE:
234 safi = SAFI_MPLS_VPN;
235 break;
236 case BGP_IPV4M_NODE:
237 case BGP_IPV6M_NODE:
238 safi = SAFI_MULTICAST;
239 break;
240 case BGP_EVPN_NODE:
241 safi = SAFI_EVPN;
242 break;
243 case BGP_IPV4L_NODE:
244 case BGP_IPV6L_NODE:
245 safi = SAFI_LABELED_UNICAST;
246 break;
7c40bf39 247 case BGP_FLOWSPECV4_NODE:
248 case BGP_FLOWSPECV6_NODE:
249 safi = SAFI_FLOWSPEC;
250 break;
d62a17ae 251 default:
252 safi = SAFI_UNICAST;
253 break;
254 }
255 return safi;
718e3744 256}
257
55f91488
QY
258/**
259 * Converts an AFI in string form to afi_t
260 *
261 * @param afi string, one of
262 * - "ipv4"
263 * - "ipv6"
81cf0de5 264 * - "l2vpn"
55f91488
QY
265 * @return the corresponding afi_t
266 */
d62a17ae 267afi_t bgp_vty_afi_from_str(const char *afi_str)
268{
269 afi_t afi = AFI_MAX; /* unknown */
270 if (strmatch(afi_str, "ipv4"))
271 afi = AFI_IP;
272 else if (strmatch(afi_str, "ipv6"))
273 afi = AFI_IP6;
81cf0de5
CS
274 else if (strmatch(afi_str, "l2vpn"))
275 afi = AFI_L2VPN;
d62a17ae 276 return afi;
277}
278
279int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
280 afi_t *afi)
281{
282 int ret = 0;
283 if (argv_find(argv, argc, "ipv4", index)) {
284 ret = 1;
285 if (afi)
286 *afi = AFI_IP;
287 } else if (argv_find(argv, argc, "ipv6", index)) {
288 ret = 1;
289 if (afi)
290 *afi = AFI_IP6;
8688b3e7
DS
291 } else if (argv_find(argv, argc, "l2vpn", index)) {
292 ret = 1;
293 if (afi)
294 *afi = AFI_L2VPN;
d62a17ae 295 }
296 return ret;
46f296b4
LB
297}
298
375a2e67 299/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 300safi_t bgp_vty_safi_from_str(const char *safi_str)
301{
302 safi_t safi = SAFI_MAX; /* unknown */
303 if (strmatch(safi_str, "multicast"))
304 safi = SAFI_MULTICAST;
305 else if (strmatch(safi_str, "unicast"))
306 safi = SAFI_UNICAST;
307 else if (strmatch(safi_str, "vpn"))
308 safi = SAFI_MPLS_VPN;
81cf0de5
CS
309 else if (strmatch(safi_str, "evpn"))
310 safi = SAFI_EVPN;
d62a17ae 311 else if (strmatch(safi_str, "labeled-unicast"))
312 safi = SAFI_LABELED_UNICAST;
7c40bf39 313 else if (strmatch(safi_str, "flowspec"))
314 safi = SAFI_FLOWSPEC;
d62a17ae 315 return safi;
316}
317
318int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
319 safi_t *safi)
320{
321 int ret = 0;
322 if (argv_find(argv, argc, "unicast", index)) {
323 ret = 1;
324 if (safi)
325 *safi = SAFI_UNICAST;
326 } else if (argv_find(argv, argc, "multicast", index)) {
327 ret = 1;
328 if (safi)
329 *safi = SAFI_MULTICAST;
330 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
331 ret = 1;
332 if (safi)
333 *safi = SAFI_LABELED_UNICAST;
334 } else if (argv_find(argv, argc, "vpn", index)) {
335 ret = 1;
336 if (safi)
337 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
338 } else if (argv_find(argv, argc, "evpn", index)) {
339 ret = 1;
340 if (safi)
341 *safi = SAFI_EVPN;
7c40bf39 342 } else if (argv_find(argv, argc, "flowspec", index)) {
343 ret = 1;
344 if (safi)
345 *safi = SAFI_FLOWSPEC;
d62a17ae 346 }
347 return ret;
46f296b4
LB
348}
349
7eeee51e 350/*
f212a857 351 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 352 *
f212a857
DS
353 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
354 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
355 * to appropriate values for the calling function. This is to allow the
356 * calling function to make decisions appropriate for the show command
357 * that is being parsed.
358 *
359 * The show commands are generally of the form:
d62a17ae 360 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
361 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
362 *
363 * Since we use argv_find if the show command in particular doesn't have:
364 * [ip]
18c57037 365 * [<view|vrf> VIEWVRFNAME]
375a2e67 366 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
367 * The command parsing should still be ok.
368 *
369 * vty -> The vty for the command so we can output some useful data in
370 * the event of a parse error in the vrf.
371 * argv -> The command tokens
372 * argc -> How many command tokens we have
d62a17ae 373 * idx -> The current place in the command, generally should be 0 for this
374 * function
7eeee51e
DS
375 * afi -> The parsed afi if it was included in the show command, returned here
376 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 377 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 378 * use_json -> json is configured or not
7eeee51e
DS
379 *
380 * The function returns the correct location in the parse tree for the
381 * last token found.
0e37c258
DS
382 *
383 * Returns 0 for failure to parse correctly, else the idx position of where
384 * it found the last token.
7eeee51e 385 */
d62a17ae 386int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
387 struct cmd_token **argv, int argc,
388 int *idx, afi_t *afi, safi_t *safi,
9f049418 389 struct bgp **bgp, bool use_json)
d62a17ae 390{
391 char *vrf_name = NULL;
392
393 assert(afi);
394 assert(safi);
395 assert(bgp);
396
397 if (argv_find(argv, argc, "ip", idx))
398 *afi = AFI_IP;
399
9a8bdf1c 400 if (argv_find(argv, argc, "view", idx))
d62a17ae 401 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
402 else if (argv_find(argv, argc, "vrf", idx)) {
403 vrf_name = argv[*idx + 1]->arg;
404 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
405 vrf_name = NULL;
406 }
407 if (vrf_name) {
d62a17ae 408 if (strmatch(vrf_name, "all"))
409 *bgp = NULL;
410 else {
411 *bgp = bgp_lookup_by_name(vrf_name);
412 if (!*bgp) {
52e5b8c4
SP
413 if (use_json) {
414 json_object *json = NULL;
415 json = json_object_new_object();
416 json_object_string_add(
417 json, "warning",
418 "View/Vrf is unknown");
419 vty_out(vty, "%s\n",
420 json_object_to_json_string_ext(json,
421 JSON_C_TO_STRING_PRETTY));
422 json_object_free(json);
423 }
ca61fd25
DS
424 else
425 vty_out(vty, "View/Vrf %s is unknown\n",
426 vrf_name);
d62a17ae 427 *idx = 0;
428 return 0;
429 }
430 }
431 } else {
432 *bgp = bgp_get_default();
433 if (!*bgp) {
52e5b8c4
SP
434 if (use_json) {
435 json_object *json = NULL;
436 json = json_object_new_object();
437 json_object_string_add(
438 json, "warning",
439 "Default BGP instance not found");
440 vty_out(vty, "%s\n",
441 json_object_to_json_string_ext(json,
442 JSON_C_TO_STRING_PRETTY));
443 json_object_free(json);
444 }
ca61fd25
DS
445 else
446 vty_out(vty,
447 "Default BGP instance not found\n");
d62a17ae 448 *idx = 0;
449 return 0;
450 }
451 }
452
453 if (argv_find_and_parse_afi(argv, argc, idx, afi))
454 argv_find_and_parse_safi(argv, argc, idx, safi);
455
456 *idx += 1;
457 return *idx;
458}
459
460static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
461{
462 struct interface *ifp = NULL;
463
464 if (su->sa.sa_family == AF_INET)
465 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
466 else if (su->sa.sa_family == AF_INET6)
467 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
468 su->sin6.sin6_scope_id,
469 bgp->vrf_id);
470
471 if (ifp)
472 return 1;
473
474 return 0;
718e3744 475}
476
477/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
478/* This is used only for configuration, so disallow if attempted on
479 * a dynamic neighbor.
480 */
d62a17ae 481static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
482{
483 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
484 int ret;
485 union sockunion su;
486 struct peer *peer;
487
488 if (!bgp) {
489 return NULL;
490 }
491
492 ret = str2sockunion(ip_str, &su);
493 if (ret < 0) {
494 peer = peer_lookup_by_conf_if(bgp, ip_str);
495 if (!peer) {
496 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
497 == NULL) {
498 vty_out(vty,
499 "%% Malformed address or name: %s\n",
500 ip_str);
501 return NULL;
502 }
503 }
504 } else {
505 peer = peer_lookup(bgp, &su);
506 if (!peer) {
507 vty_out(vty,
508 "%% Specify remote-as or peer-group commands first\n");
509 return NULL;
510 }
511 if (peer_dynamic_neighbor(peer)) {
512 vty_out(vty,
513 "%% Operation not allowed on a dynamic neighbor\n");
514 return NULL;
515 }
516 }
517 return peer;
718e3744 518}
519
520/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
521/* This is used only for configuration, so disallow if attempted on
522 * a dynamic neighbor.
523 */
d62a17ae 524struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
525{
526 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
527 int ret;
528 union sockunion su;
529 struct peer *peer = NULL;
530 struct peer_group *group = NULL;
531
532 if (!bgp) {
533 return NULL;
534 }
535
536 ret = str2sockunion(peer_str, &su);
537 if (ret == 0) {
538 /* IP address, locate peer. */
539 peer = peer_lookup(bgp, &su);
540 } else {
541 /* Not IP, could match either peer configured on interface or a
542 * group. */
543 peer = peer_lookup_by_conf_if(bgp, peer_str);
544 if (!peer)
545 group = peer_group_lookup(bgp, peer_str);
546 }
547
548 if (peer) {
549 if (peer_dynamic_neighbor(peer)) {
550 vty_out(vty,
551 "%% Operation not allowed on a dynamic neighbor\n");
552 return NULL;
553 }
554
555 return peer;
556 }
557
558 if (group)
559 return group->conf;
560
561 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
562
563 return NULL;
564}
565
566int bgp_vty_return(struct vty *vty, int ret)
567{
568 const char *str = NULL;
569
570 switch (ret) {
571 case BGP_ERR_INVALID_VALUE:
572 str = "Invalid value";
573 break;
574 case BGP_ERR_INVALID_FLAG:
575 str = "Invalid flag";
576 break;
577 case BGP_ERR_PEER_GROUP_SHUTDOWN:
578 str = "Peer-group has been shutdown. Activate the peer-group first";
579 break;
580 case BGP_ERR_PEER_FLAG_CONFLICT:
581 str = "Can't set override-capability and strict-capability-match at the same time";
582 break;
583 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
584 str = "Specify remote-as or peer-group remote AS first";
585 break;
586 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
587 str = "Cannot change the peer-group. Deconfigure first";
588 break;
589 case BGP_ERR_PEER_GROUP_MISMATCH:
590 str = "Peer is not a member of this peer-group";
591 break;
592 case BGP_ERR_PEER_FILTER_CONFLICT:
593 str = "Prefix/distribute list can not co-exist";
594 break;
595 case BGP_ERR_NOT_INTERNAL_PEER:
596 str = "Invalid command. Not an internal neighbor";
597 break;
598 case BGP_ERR_REMOVE_PRIVATE_AS:
599 str = "remove-private-AS cannot be configured for IBGP peers";
600 break;
601 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
602 str = "Local-AS allowed only for EBGP peers";
603 break;
604 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
605 str = "Cannot have local-as same as BGP AS number";
606 break;
607 case BGP_ERR_TCPSIG_FAILED:
608 str = "Error while applying TCP-Sig to session(s)";
609 break;
610 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
611 str = "ebgp-multihop and ttl-security cannot be configured together";
612 break;
613 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
614 str = "ttl-security only allowed for EBGP peers";
615 break;
616 case BGP_ERR_AS_OVERRIDE:
617 str = "as-override cannot be configured for IBGP peers";
618 break;
619 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
620 str = "Invalid limit for number of dynamic neighbors";
621 break;
622 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
623 str = "Dynamic neighbor listen range already exists";
624 break;
625 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
626 str = "Operation not allowed on a dynamic neighbor";
627 break;
628 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
629 str = "Operation not allowed on a directly connected neighbor";
630 break;
631 case BGP_ERR_PEER_SAFI_CONFLICT:
632 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
633 break;
634 }
635 if (str) {
636 vty_out(vty, "%% %s\n", str);
637 return CMD_WARNING_CONFIG_FAILED;
638 }
639 return CMD_SUCCESS;
718e3744 640}
641
7aafcaca 642/* BGP clear sort. */
d62a17ae 643enum clear_sort {
644 clear_all,
645 clear_peer,
646 clear_group,
647 clear_external,
648 clear_as
7aafcaca
DS
649};
650
d62a17ae 651static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
652 safi_t safi, int error)
653{
654 switch (error) {
655 case BGP_ERR_AF_UNCONFIGURED:
656 vty_out(vty,
657 "%%BGP: Enable %s address family for the neighbor %s\n",
5cb5f4d0 658 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 659 break;
660 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
661 vty_out(vty,
662 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
663 peer->host);
664 break;
665 default:
666 break;
667 }
7aafcaca
DS
668}
669
dc912615
DS
670static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
671 struct listnode *nnode, enum bgp_clear_type stype)
672{
673 int ret = 0;
674
675 /* if afi/.safi not specified, spin thru all of them */
676 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
677 afi_t tmp_afi;
678 safi_t tmp_safi;
679
680 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
681 if (!peer->afc[tmp_afi][tmp_safi])
682 continue;
683
684 if (stype == BGP_CLEAR_SOFT_NONE)
685 ret = peer_clear(peer, &nnode);
686 else
687 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
688 stype);
689 }
690 /* if afi specified and safi not, spin thru safis on this afi */
691 } else if (safi == SAFI_UNSPEC) {
692 safi_t tmp_safi;
693
694 for (tmp_safi = SAFI_UNICAST;
695 tmp_safi < SAFI_MAX; tmp_safi++) {
696 if (!peer->afc[afi][tmp_safi])
697 continue;
698
699 if (stype == BGP_CLEAR_SOFT_NONE)
700 ret = peer_clear(peer, &nnode);
701 else
702 ret = peer_clear_soft(peer, afi,
703 tmp_safi, stype);
704 }
705 /* both afi/safi specified, let the caller know if not defined */
706 } else {
707 if (!peer->afc[afi][safi])
708 return 1;
709
710 if (stype == BGP_CLEAR_SOFT_NONE)
711 ret = peer_clear(peer, &nnode);
712 else
713 ret = peer_clear_soft(peer, afi, safi, stype);
714 }
715
716 return ret;
717}
718
7aafcaca 719/* `clear ip bgp' functions. */
d62a17ae 720static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
721 enum clear_sort sort, enum bgp_clear_type stype,
722 const char *arg)
723{
dc912615 724 int ret = 0;
3ae8bfa5 725 bool found = false;
d62a17ae 726 struct peer *peer;
727 struct listnode *node, *nnode;
728
729 /* Clear all neighbors. */
730 /*
731 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
732 * nodes on the BGP instance as that may get freed if it is a
733 * doppelganger
d62a17ae 734 */
735 if (sort == clear_all) {
736 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc912615
DS
737 ret = bgp_peer_clear(peer, afi, safi, nnode,
738 stype);
d62a17ae 739
740 if (ret < 0)
741 bgp_clear_vty_error(vty, peer, afi, safi, ret);
04b6bdc0 742 }
d62a17ae 743
744 /* This is to apply read-only mode on this clear. */
745 if (stype == BGP_CLEAR_SOFT_NONE)
746 bgp->update_delay_over = 0;
747
748 return CMD_SUCCESS;
7aafcaca
DS
749 }
750
3ae8bfa5 751 /* Clear specified neighbor. */
d62a17ae 752 if (sort == clear_peer) {
753 union sockunion su;
d62a17ae 754
755 /* Make sockunion for lookup. */
756 ret = str2sockunion(arg, &su);
757 if (ret < 0) {
758 peer = peer_lookup_by_conf_if(bgp, arg);
759 if (!peer) {
760 peer = peer_lookup_by_hostname(bgp, arg);
761 if (!peer) {
762 vty_out(vty,
763 "Malformed address or name: %s\n",
764 arg);
765 return CMD_WARNING;
766 }
767 }
768 } else {
769 peer = peer_lookup(bgp, &su);
770 if (!peer) {
771 vty_out(vty,
772 "%%BGP: Unknown neighbor - \"%s\"\n",
773 arg);
774 return CMD_WARNING;
775 }
776 }
7aafcaca 777
dc912615
DS
778 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
779
780 /* if afi/safi not defined for this peer, let caller know */
781 if (ret == 1)
3ae8bfa5 782 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 783
d62a17ae 784 if (ret < 0)
785 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 786
d62a17ae 787 return CMD_SUCCESS;
7aafcaca 788 }
7aafcaca 789
3ae8bfa5 790 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 791 if (sort == clear_group) {
792 struct peer_group *group;
7aafcaca 793
d62a17ae 794 group = peer_group_lookup(bgp, arg);
795 if (!group) {
796 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
797 return CMD_WARNING;
798 }
799
800 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
dc912615 801 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
7aafcaca 802
d62a17ae 803 if (ret < 0)
804 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
805 else
806 found = true;
d62a17ae 807 }
3ae8bfa5
PM
808
809 if (!found)
810 vty_out(vty,
811 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 812 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 813
d62a17ae 814 return CMD_SUCCESS;
7aafcaca 815 }
7aafcaca 816
3ae8bfa5 817 /* Clear all external (eBGP) neighbors. */
d62a17ae 818 if (sort == clear_external) {
819 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
820 if (peer->sort == BGP_PEER_IBGP)
821 continue;
7aafcaca 822
dc912615 823 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
7aafcaca 824
d62a17ae 825 if (ret < 0)
826 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
827 else
828 found = true;
d62a17ae 829 }
3ae8bfa5
PM
830
831 if (!found)
832 vty_out(vty,
833 "%%BGP: No external %s peer is configured\n",
5cb5f4d0 834 get_afi_safi_str(afi, safi, false));
3ae8bfa5 835
d62a17ae 836 return CMD_SUCCESS;
837 }
838
3ae8bfa5 839 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 840 if (sort == clear_as) {
3ae8bfa5 841 as_t as = strtoul(arg, NULL, 10);
d62a17ae 842
843 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
844 if (peer->as != as)
845 continue;
846
dc912615 847 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
d62a17ae 848
849 if (ret < 0)
850 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
851 else
852 found = true;
d62a17ae 853 }
3ae8bfa5
PM
854
855 if (!found)
d62a17ae 856 vty_out(vty,
3ae8bfa5 857 "%%BGP: No %s peer is configured with AS %s\n",
5cb5f4d0 858 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 859
d62a17ae 860 return CMD_SUCCESS;
861 }
862
863 return CMD_SUCCESS;
864}
865
866static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
867 safi_t safi, enum clear_sort sort,
868 enum bgp_clear_type stype, const char *arg)
869{
870 struct bgp *bgp;
871
872 /* BGP structure lookup. */
873 if (name) {
874 bgp = bgp_lookup_by_name(name);
875 if (bgp == NULL) {
876 vty_out(vty, "Can't find BGP instance %s\n", name);
877 return CMD_WARNING;
878 }
879 } else {
880 bgp = bgp_get_default();
881 if (bgp == NULL) {
882 vty_out(vty, "No BGP process is configured\n");
883 return CMD_WARNING;
884 }
885 }
886
887 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
888}
889
890/* clear soft inbound */
d62a17ae 891static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 892{
99b3ebd3
NS
893 afi_t afi;
894 safi_t safi;
895
896 FOREACH_AFI_SAFI (afi, safi)
897 bgp_clear_vty(vty, name, afi, safi, clear_all,
898 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
899}
900
901/* clear soft outbound */
d62a17ae 902static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 903{
99b3ebd3
NS
904 afi_t afi;
905 safi_t safi;
906
907 FOREACH_AFI_SAFI (afi, safi)
908 bgp_clear_vty(vty, name, afi, safi, clear_all,
909 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
910}
911
912
f787d7a0 913#ifndef VTYSH_EXTRACT_PL
2e4c2296 914#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
915#endif
916
8029b216
AK
917DEFUN_HIDDEN (bgp_local_mac,
918 bgp_local_mac_cmd,
093e3f23 919 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
920 BGP_STR
921 "Local MAC config\n"
922 "VxLAN Network Identifier\n"
923 "VNI number\n"
924 "local mac\n"
925 "mac address\n"
926 "mac-mobility sequence\n"
927 "seq number\n")
928{
929 int rv;
930 vni_t vni;
931 struct ethaddr mac;
932 struct ipaddr ip;
933 uint32_t seq;
934 struct bgp *bgp;
935
936 vni = strtoul(argv[3]->arg, NULL, 10);
937 if (!prefix_str2mac(argv[5]->arg, &mac)) {
938 vty_out(vty, "%% Malformed MAC address\n");
939 return CMD_WARNING;
940 }
941 memset(&ip, 0, sizeof(ip));
942 seq = strtoul(argv[7]->arg, NULL, 10);
943
944 bgp = bgp_get_default();
945 if (!bgp) {
946 vty_out(vty, "Default BGP instance is not there\n");
947 return CMD_WARNING;
948 }
949
950 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
951 if (rv < 0) {
952 vty_out(vty, "Internal error\n");
953 return CMD_WARNING;
954 }
955
956 return CMD_SUCCESS;
957}
958
959DEFUN_HIDDEN (no_bgp_local_mac,
960 no_bgp_local_mac_cmd,
093e3f23 961 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
962 NO_STR
963 BGP_STR
964 "Local MAC config\n"
965 "VxLAN Network Identifier\n"
966 "VNI number\n"
967 "local mac\n"
968 "mac address\n")
969{
970 int rv;
971 vni_t vni;
972 struct ethaddr mac;
973 struct ipaddr ip;
974 struct bgp *bgp;
975
976 vni = strtoul(argv[4]->arg, NULL, 10);
977 if (!prefix_str2mac(argv[6]->arg, &mac)) {
978 vty_out(vty, "%% Malformed MAC address\n");
979 return CMD_WARNING;
980 }
981 memset(&ip, 0, sizeof(ip));
982
983 bgp = bgp_get_default();
984 if (!bgp) {
985 vty_out(vty, "Default BGP instance is not there\n");
986 return CMD_WARNING;
987 }
988
ec0ab544 989 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
990 if (rv < 0) {
991 vty_out(vty, "Internal error\n");
992 return CMD_WARNING;
993 }
994
995 return CMD_SUCCESS;
996}
997
718e3744 998DEFUN (no_synchronization,
999 no_synchronization_cmd,
1000 "no synchronization",
1001 NO_STR
1002 "Perform IGP synchronization\n")
1003{
d62a17ae 1004 return CMD_SUCCESS;
718e3744 1005}
1006
1007DEFUN (no_auto_summary,
1008 no_auto_summary_cmd,
1009 "no auto-summary",
1010 NO_STR
1011 "Enable automatic network number summarization\n")
1012{
d62a17ae 1013 return CMD_SUCCESS;
718e3744 1014}
3d515fd9 1015
718e3744 1016/* "router bgp" commands. */
505e5056 1017DEFUN_NOSH (router_bgp,
f412b39a 1018 router_bgp_cmd,
2ed9fe4a 1019 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 1020 ROUTER_STR
1021 BGP_STR
31500417
DW
1022 AS_STR
1023 BGP_INSTANCE_HELP_STR)
718e3744 1024{
d62a17ae 1025 int idx_asn = 2;
1026 int idx_view_vrf = 3;
1027 int idx_vrf = 4;
ecec9495 1028 int is_new_bgp = 0;
d62a17ae 1029 int ret;
1030 as_t as;
1031 struct bgp *bgp;
1032 const char *name = NULL;
1033 enum bgp_instance_type inst_type;
1034
1035 // "router bgp" without an ASN
1036 if (argc == 2) {
1037 // Pending: Make VRF option available for ASN less config
1038 bgp = bgp_get_default();
1039
1040 if (bgp == NULL) {
1041 vty_out(vty, "%% No BGP process is configured\n");
1042 return CMD_WARNING_CONFIG_FAILED;
1043 }
1044
1045 if (listcount(bm->bgp) > 1) {
996c9314 1046 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1047 return CMD_WARNING_CONFIG_FAILED;
1048 }
1049 }
1050
1051 // "router bgp X"
1052 else {
1053 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1054
1055 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1056 if (argc > 3) {
1057 name = argv[idx_vrf]->arg;
1058
9a8bdf1c
PG
1059 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1060 if (strmatch(name, VRF_DEFAULT_NAME))
1061 name = NULL;
1062 else
1063 inst_type = BGP_INSTANCE_TYPE_VRF;
1064 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1065 inst_type = BGP_INSTANCE_TYPE_VIEW;
1066 }
1067
ecec9495
AD
1068 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1069 is_new_bgp = (bgp_lookup(as, name) == NULL);
1070
d62a17ae 1071 ret = bgp_get(&bgp, &as, name, inst_type);
1072 switch (ret) {
d62a17ae 1073 case BGP_ERR_AS_MISMATCH:
1074 vty_out(vty, "BGP is already running; AS is %u\n", as);
1075 return CMD_WARNING_CONFIG_FAILED;
1076 case BGP_ERR_INSTANCE_MISMATCH:
1077 vty_out(vty,
1078 "BGP instance name and AS number mismatch\n");
1079 vty_out(vty,
1080 "BGP instance is already running; AS is %u\n",
1081 as);
1082 return CMD_WARNING_CONFIG_FAILED;
1083 }
1084
3bd70bf8
PZ
1085 /*
1086 * If we just instantiated the default instance, complete
1087 * any pending VRF-VPN leaking that was configured via
1088 * earlier "router bgp X vrf FOO" blocks.
1089 */
ecec9495 1090 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
3bd70bf8
PZ
1091 vpn_leak_postchange_all();
1092
48381346
CS
1093 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1094 bgp_vpn_leak_export(bgp);
d62a17ae 1095 /* Pending: handle when user tries to change a view to vrf n vv.
1096 */
1097 }
1098
0b5131c9
MK
1099 /* unset the auto created flag as the user config is now present */
1100 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 1101 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1102
1103 return CMD_SUCCESS;
718e3744 1104}
1105
718e3744 1106/* "no router bgp" commands. */
1107DEFUN (no_router_bgp,
1108 no_router_bgp_cmd,
2ed9fe4a 1109 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 1110 NO_STR
1111 ROUTER_STR
1112 BGP_STR
31500417
DW
1113 AS_STR
1114 BGP_INSTANCE_HELP_STR)
718e3744 1115{
d62a17ae 1116 int idx_asn = 3;
1117 int idx_vrf = 5;
1118 as_t as;
1119 struct bgp *bgp;
1120 const char *name = NULL;
718e3744 1121
d62a17ae 1122 // "no router bgp" without an ASN
1123 if (argc == 3) {
1124 // Pending: Make VRF option available for ASN less config
1125 bgp = bgp_get_default();
718e3744 1126
d62a17ae 1127 if (bgp == NULL) {
1128 vty_out(vty, "%% No BGP process is configured\n");
1129 return CMD_WARNING_CONFIG_FAILED;
1130 }
7fb21a9f 1131
d62a17ae 1132 if (listcount(bm->bgp) > 1) {
996c9314 1133 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1134 return CMD_WARNING_CONFIG_FAILED;
1135 }
0b5131c9
MK
1136
1137 if (bgp->l3vni) {
1138 vty_out(vty, "%% Please unconfigure l3vni %u",
1139 bgp->l3vni);
1140 return CMD_WARNING_CONFIG_FAILED;
1141 }
d62a17ae 1142 } else {
1143 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1144
d62a17ae 1145 if (argc > 4)
1146 name = argv[idx_vrf]->arg;
7fb21a9f 1147
d62a17ae 1148 /* Lookup bgp structure. */
1149 bgp = bgp_lookup(as, name);
1150 if (!bgp) {
1151 vty_out(vty, "%% Can't find BGP instance\n");
1152 return CMD_WARNING_CONFIG_FAILED;
1153 }
0b5131c9
MK
1154
1155 if (bgp->l3vni) {
dd5868c2 1156 vty_out(vty, "%% Please unconfigure l3vni %u\n",
0b5131c9
MK
1157 bgp->l3vni);
1158 return CMD_WARNING_CONFIG_FAILED;
1159 }
dd5868c2
DS
1160
1161 /* Cannot delete default instance if vrf instances exist */
1162 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1163 struct listnode *node;
1164 struct bgp *tmp_bgp;
1165
1166 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1167 if (tmp_bgp->inst_type
1168 == BGP_INSTANCE_TYPE_VRF) {
1169 vty_out(vty,
1170 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1171 return CMD_WARNING_CONFIG_FAILED;
1172 }
1173 }
1174 }
d62a17ae 1175 }
718e3744 1176
9ecf931b
CS
1177 if (bgp_vpn_leak_unimport(bgp, vty))
1178 return CMD_WARNING_CONFIG_FAILED;
1179
d62a17ae 1180 bgp_delete(bgp);
718e3744 1181
d62a17ae 1182 return CMD_SUCCESS;
718e3744 1183}
1184
6b0655a2 1185
718e3744 1186/* BGP router-id. */
1187
f787d7a0 1188DEFPY (bgp_router_id,
718e3744 1189 bgp_router_id_cmd,
1190 "bgp router-id A.B.C.D",
1191 BGP_STR
1192 "Override configured router identifier\n"
1193 "Manually configured router identifier\n")
1194{
d62a17ae 1195 VTY_DECLVAR_CONTEXT(bgp, bgp);
1196 bgp_router_id_static_set(bgp, router_id);
1197 return CMD_SUCCESS;
718e3744 1198}
1199
f787d7a0 1200DEFPY (no_bgp_router_id,
718e3744 1201 no_bgp_router_id_cmd,
31500417 1202 "no bgp router-id [A.B.C.D]",
718e3744 1203 NO_STR
1204 BGP_STR
31500417
DW
1205 "Override configured router identifier\n"
1206 "Manually configured router identifier\n")
718e3744 1207{
d62a17ae 1208 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1209
d62a17ae 1210 if (router_id_str) {
1211 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1212 vty_out(vty, "%% BGP router-id doesn't match\n");
1213 return CMD_WARNING_CONFIG_FAILED;
1214 }
e018c7cc 1215 }
718e3744 1216
d62a17ae 1217 router_id.s_addr = 0;
1218 bgp_router_id_static_set(bgp, router_id);
718e3744 1219
d62a17ae 1220 return CMD_SUCCESS;
718e3744 1221}
1222
6b0655a2 1223
718e3744 1224/* BGP Cluster ID. */
718e3744 1225DEFUN (bgp_cluster_id,
1226 bgp_cluster_id_cmd,
838758ac 1227 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1228 BGP_STR
1229 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1230 "Route-Reflector Cluster-id in IP address format\n"
1231 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1232{
d62a17ae 1233 VTY_DECLVAR_CONTEXT(bgp, bgp);
1234 int idx_ipv4 = 2;
1235 int ret;
1236 struct in_addr cluster;
718e3744 1237
d62a17ae 1238 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1239 if (!ret) {
1240 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1241 return CMD_WARNING_CONFIG_FAILED;
1242 }
718e3744 1243
d62a17ae 1244 bgp_cluster_id_set(bgp, &cluster);
1245 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1246
d62a17ae 1247 return CMD_SUCCESS;
718e3744 1248}
1249
718e3744 1250DEFUN (no_bgp_cluster_id,
1251 no_bgp_cluster_id_cmd,
c7178fe7 1252 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1253 NO_STR
1254 BGP_STR
838758ac
DW
1255 "Configure Route-Reflector Cluster-id\n"
1256 "Route-Reflector Cluster-id in IP address format\n"
1257 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1258{
d62a17ae 1259 VTY_DECLVAR_CONTEXT(bgp, bgp);
1260 bgp_cluster_id_unset(bgp);
1261 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1262
d62a17ae 1263 return CMD_SUCCESS;
718e3744 1264}
1265
718e3744 1266DEFUN (bgp_confederation_identifier,
1267 bgp_confederation_identifier_cmd,
9ccf14f7 1268 "bgp confederation identifier (1-4294967295)",
718e3744 1269 "BGP specific commands\n"
1270 "AS confederation parameters\n"
1271 "AS number\n"
1272 "Set routing domain confederation AS\n")
1273{
d62a17ae 1274 VTY_DECLVAR_CONTEXT(bgp, bgp);
1275 int idx_number = 3;
1276 as_t as;
718e3744 1277
d62a17ae 1278 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1279
d62a17ae 1280 bgp_confederation_id_set(bgp, as);
718e3744 1281
d62a17ae 1282 return CMD_SUCCESS;
718e3744 1283}
1284
1285DEFUN (no_bgp_confederation_identifier,
1286 no_bgp_confederation_identifier_cmd,
838758ac 1287 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1288 NO_STR
1289 "BGP specific commands\n"
1290 "AS confederation parameters\n"
3a2d747c
QY
1291 "AS number\n"
1292 "Set routing domain confederation AS\n")
718e3744 1293{
d62a17ae 1294 VTY_DECLVAR_CONTEXT(bgp, bgp);
1295 bgp_confederation_id_unset(bgp);
718e3744 1296
d62a17ae 1297 return CMD_SUCCESS;
718e3744 1298}
1299
718e3744 1300DEFUN (bgp_confederation_peers,
1301 bgp_confederation_peers_cmd,
12dcf78e 1302 "bgp confederation peers (1-4294967295)...",
718e3744 1303 "BGP specific commands\n"
1304 "AS confederation parameters\n"
1305 "Peer ASs in BGP confederation\n"
1306 AS_STR)
1307{
d62a17ae 1308 VTY_DECLVAR_CONTEXT(bgp, bgp);
1309 int idx_asn = 3;
1310 as_t as;
1311 int i;
718e3744 1312
d62a17ae 1313 for (i = idx_asn; i < argc; i++) {
1314 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1315
d62a17ae 1316 if (bgp->as == as) {
1317 vty_out(vty,
1318 "%% Local member-AS not allowed in confed peer list\n");
1319 continue;
1320 }
718e3744 1321
d62a17ae 1322 bgp_confederation_peers_add(bgp, as);
1323 }
1324 return CMD_SUCCESS;
718e3744 1325}
1326
1327DEFUN (no_bgp_confederation_peers,
1328 no_bgp_confederation_peers_cmd,
e83a9414 1329 "no bgp confederation peers (1-4294967295)...",
718e3744 1330 NO_STR
1331 "BGP specific commands\n"
1332 "AS confederation parameters\n"
1333 "Peer ASs in BGP confederation\n"
1334 AS_STR)
1335{
d62a17ae 1336 VTY_DECLVAR_CONTEXT(bgp, bgp);
1337 int idx_asn = 4;
1338 as_t as;
1339 int i;
718e3744 1340
d62a17ae 1341 for (i = idx_asn; i < argc; i++) {
1342 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1343
d62a17ae 1344 bgp_confederation_peers_remove(bgp, as);
1345 }
1346 return CMD_SUCCESS;
718e3744 1347}
6b0655a2 1348
5e242b0d
DS
1349/**
1350 * Central routine for maximum-paths configuration.
1351 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1352 * @set: 1 for setting values, 0 for removing the max-paths config.
1353 */
d62a17ae 1354static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1355 const char *mpaths, uint16_t options,
d62a17ae 1356 int set)
1357{
1358 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1359 uint16_t maxpaths = 0;
d62a17ae 1360 int ret;
1361 afi_t afi;
1362 safi_t safi;
1363
1364 afi = bgp_node_afi(vty);
1365 safi = bgp_node_safi(vty);
1366
1367 if (set) {
1368 maxpaths = strtol(mpaths, NULL, 10);
1369 if (maxpaths > multipath_num) {
1370 vty_out(vty,
1371 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1372 maxpaths, multipath_num);
1373 return CMD_WARNING_CONFIG_FAILED;
1374 }
1375 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1376 options);
1377 } else
1378 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1379
1380 if (ret < 0) {
1381 vty_out(vty,
1382 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1383 (set == 1) ? "" : "un",
1384 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1385 maxpaths, afi, safi);
1386 return CMD_WARNING_CONFIG_FAILED;
1387 }
1388
1389 bgp_recalculate_all_bestpaths(bgp);
1390
1391 return CMD_SUCCESS;
165b5fff
JB
1392}
1393
abc920f8
DS
1394DEFUN (bgp_maxmed_admin,
1395 bgp_maxmed_admin_cmd,
1396 "bgp max-med administrative ",
1397 BGP_STR
1398 "Advertise routes with max-med\n"
1399 "Administratively applied, for an indefinite period\n")
1400{
d62a17ae 1401 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1402
d62a17ae 1403 bgp->v_maxmed_admin = 1;
1404 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1405
d62a17ae 1406 bgp_maxmed_update(bgp);
abc920f8 1407
d62a17ae 1408 return CMD_SUCCESS;
abc920f8
DS
1409}
1410
1411DEFUN (bgp_maxmed_admin_medv,
1412 bgp_maxmed_admin_medv_cmd,
4668a151 1413 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1414 BGP_STR
1415 "Advertise routes with max-med\n"
1416 "Administratively applied, for an indefinite period\n"
1417 "Max MED value to be used\n")
1418{
d62a17ae 1419 VTY_DECLVAR_CONTEXT(bgp, bgp);
1420 int idx_number = 3;
abc920f8 1421
d62a17ae 1422 bgp->v_maxmed_admin = 1;
1423 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1424
d62a17ae 1425 bgp_maxmed_update(bgp);
abc920f8 1426
d62a17ae 1427 return CMD_SUCCESS;
abc920f8
DS
1428}
1429
1430DEFUN (no_bgp_maxmed_admin,
1431 no_bgp_maxmed_admin_cmd,
4668a151 1432 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1433 NO_STR
1434 BGP_STR
1435 "Advertise routes with max-med\n"
838758ac
DW
1436 "Administratively applied, for an indefinite period\n"
1437 "Max MED value to be used\n")
abc920f8 1438{
d62a17ae 1439 VTY_DECLVAR_CONTEXT(bgp, bgp);
1440 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1441 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1442 bgp_maxmed_update(bgp);
abc920f8 1443
d62a17ae 1444 return CMD_SUCCESS;
abc920f8
DS
1445}
1446
abc920f8
DS
1447DEFUN (bgp_maxmed_onstartup,
1448 bgp_maxmed_onstartup_cmd,
4668a151 1449 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1450 BGP_STR
1451 "Advertise routes with max-med\n"
1452 "Effective on a startup\n"
1453 "Time (seconds) period for max-med\n"
1454 "Max MED value to be used\n")
1455{
d62a17ae 1456 VTY_DECLVAR_CONTEXT(bgp, bgp);
1457 int idx = 0;
4668a151 1458
d62a17ae 1459 argv_find(argv, argc, "(5-86400)", &idx);
1460 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1461 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1462 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1463 else
1464 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1465
d62a17ae 1466 bgp_maxmed_update(bgp);
abc920f8 1467
d62a17ae 1468 return CMD_SUCCESS;
abc920f8
DS
1469}
1470
1471DEFUN (no_bgp_maxmed_onstartup,
1472 no_bgp_maxmed_onstartup_cmd,
4668a151 1473 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1474 NO_STR
1475 BGP_STR
1476 "Advertise routes with max-med\n"
838758ac
DW
1477 "Effective on a startup\n"
1478 "Time (seconds) period for max-med\n"
1479 "Max MED value to be used\n")
abc920f8 1480{
d62a17ae 1481 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1482
d62a17ae 1483 /* Cancel max-med onstartup if its on */
1484 if (bgp->t_maxmed_onstartup) {
1485 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1486 bgp->maxmed_onstartup_over = 1;
1487 }
abc920f8 1488
d62a17ae 1489 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1490 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1491
d62a17ae 1492 bgp_maxmed_update(bgp);
abc920f8 1493
d62a17ae 1494 return CMD_SUCCESS;
abc920f8
DS
1495}
1496
d62a17ae 1497static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1498 const char *wait)
f188f2c4 1499{
d62a17ae 1500 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1501 uint16_t update_delay;
1502 uint16_t establish_wait;
f188f2c4 1503
d62a17ae 1504 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1505
d62a17ae 1506 if (!wait) /* update-delay <delay> */
1507 {
1508 bgp->v_update_delay = update_delay;
1509 bgp->v_establish_wait = bgp->v_update_delay;
1510 return CMD_SUCCESS;
1511 }
f188f2c4 1512
d62a17ae 1513 /* update-delay <delay> <establish-wait> */
1514 establish_wait = atoi(wait);
1515 if (update_delay < establish_wait) {
1516 vty_out(vty,
1517 "%%Failed: update-delay less than the establish-wait!\n");
1518 return CMD_WARNING_CONFIG_FAILED;
1519 }
f188f2c4 1520
d62a17ae 1521 bgp->v_update_delay = update_delay;
1522 bgp->v_establish_wait = establish_wait;
f188f2c4 1523
d62a17ae 1524 return CMD_SUCCESS;
f188f2c4
DS
1525}
1526
d62a17ae 1527static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1528{
d62a17ae 1529 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1530
d62a17ae 1531 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1532 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1533
d62a17ae 1534 return CMD_SUCCESS;
f188f2c4
DS
1535}
1536
2b791107 1537void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1538{
d62a17ae 1539 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1540 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1541 if (bgp->v_update_delay != bgp->v_establish_wait)
1542 vty_out(vty, " %d", bgp->v_establish_wait);
1543 vty_out(vty, "\n");
1544 }
f188f2c4
DS
1545}
1546
1547
1548/* Update-delay configuration */
1549DEFUN (bgp_update_delay,
1550 bgp_update_delay_cmd,
6147e2c6 1551 "update-delay (0-3600)",
f188f2c4
DS
1552 "Force initial delay for best-path and updates\n"
1553 "Seconds\n")
1554{
d62a17ae 1555 int idx_number = 1;
1556 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1557}
1558
1559DEFUN (bgp_update_delay_establish_wait,
1560 bgp_update_delay_establish_wait_cmd,
6147e2c6 1561 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1562 "Force initial delay for best-path and updates\n"
1563 "Seconds\n"
f188f2c4
DS
1564 "Seconds\n")
1565{
d62a17ae 1566 int idx_number = 1;
1567 int idx_number_2 = 2;
1568 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1569 argv[idx_number_2]->arg);
f188f2c4
DS
1570}
1571
1572/* Update-delay deconfiguration */
1573DEFUN (no_bgp_update_delay,
1574 no_bgp_update_delay_cmd,
838758ac
DW
1575 "no update-delay [(0-3600) [(1-3600)]]",
1576 NO_STR
f188f2c4 1577 "Force initial delay for best-path and updates\n"
838758ac 1578 "Seconds\n"
7111c1a0 1579 "Seconds\n")
f188f2c4 1580{
d62a17ae 1581 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1582}
1583
5e242b0d 1584
8fa7732f
QY
1585static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1586 bool set)
cb1faec9 1587{
d62a17ae 1588 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1589
8fa7732f
QY
1590 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1591 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
1592
1593 return CMD_SUCCESS;
1594}
1595
8fa7732f
QY
1596static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1597 bool set)
555e09d4
QY
1598{
1599 VTY_DECLVAR_CONTEXT(bgp, bgp);
1600
8fa7732f
QY
1601 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1602 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 1603
d62a17ae 1604 return CMD_SUCCESS;
cb1faec9
DS
1605}
1606
2b791107 1607void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1608{
555e09d4
QY
1609 uint32_t quanta =
1610 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1611 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1612 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1613}
1614
555e09d4
QY
1615void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1616{
1617 uint32_t quanta =
1618 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1619 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1620 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1621}
cb1faec9 1622
8fa7732f
QY
1623/* Packet quanta configuration
1624 *
1625 * XXX: The value set here controls the size of a stack buffer in the IO
1626 * thread. When changing these limits be careful to prevent stack overflow.
1627 *
1628 * Furthermore, the maximums used here should correspond to
1629 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1630 */
1631DEFPY (bgp_wpkt_quanta,
cb1faec9 1632 bgp_wpkt_quanta_cmd,
8fa7732f 1633 "[no] write-quanta (1-64)$quanta",
d7fa34c1 1634 NO_STR
8fa7732f 1635 "How many packets to write to peer socket per run\n"
cb1faec9
DS
1636 "Number of packets\n")
1637{
8fa7732f 1638 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
cb1faec9
DS
1639}
1640
8fa7732f 1641DEFPY (bgp_rpkt_quanta,
555e09d4 1642 bgp_rpkt_quanta_cmd,
8fa7732f 1643 "[no] read-quanta (1-10)$quanta",
555e09d4
QY
1644 NO_STR
1645 "How many packets to read from peer socket per I/O cycle\n"
1646 "Number of packets\n")
1647{
8fa7732f 1648 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
1649}
1650
2b791107 1651void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1652{
37a333fe 1653 if (!bgp->heuristic_coalesce)
d62a17ae 1654 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1655}
1656
1657
1658DEFUN (bgp_coalesce_time,
1659 bgp_coalesce_time_cmd,
6147e2c6 1660 "coalesce-time (0-4294967295)",
3f9c7369
DS
1661 "Subgroup coalesce timer\n"
1662 "Subgroup coalesce timer value (in ms)\n")
1663{
d62a17ae 1664 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1665
d62a17ae 1666 int idx = 0;
1667 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1668 bgp->heuristic_coalesce = false;
d62a17ae 1669 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1670 return CMD_SUCCESS;
3f9c7369
DS
1671}
1672
1673DEFUN (no_bgp_coalesce_time,
1674 no_bgp_coalesce_time_cmd,
6147e2c6 1675 "no coalesce-time (0-4294967295)",
3a2d747c 1676 NO_STR
3f9c7369
DS
1677 "Subgroup coalesce timer\n"
1678 "Subgroup coalesce timer value (in ms)\n")
1679{
d62a17ae 1680 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1681
37a333fe 1682 bgp->heuristic_coalesce = true;
d62a17ae 1683 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1684 return CMD_SUCCESS;
3f9c7369
DS
1685}
1686
5e242b0d
DS
1687/* Maximum-paths configuration */
1688DEFUN (bgp_maxpaths,
1689 bgp_maxpaths_cmd,
6319fd63 1690 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1691 "Forward packets over multiple paths\n"
1692 "Number of paths\n")
1693{
d62a17ae 1694 int idx_number = 1;
1695 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1696 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1697}
1698
d62a17ae 1699ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1700 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1701 "Forward packets over multiple paths\n"
1702 "Number of paths\n")
596c17ba 1703
165b5fff
JB
1704DEFUN (bgp_maxpaths_ibgp,
1705 bgp_maxpaths_ibgp_cmd,
6319fd63 1706 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1707 "Forward packets over multiple paths\n"
1708 "iBGP-multipath\n"
1709 "Number of paths\n")
1710{
d62a17ae 1711 int idx_number = 2;
1712 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1713 argv[idx_number]->arg, 0, 1);
5e242b0d 1714}
165b5fff 1715
d62a17ae 1716ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1717 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1718 "Forward packets over multiple paths\n"
1719 "iBGP-multipath\n"
1720 "Number of paths\n")
596c17ba 1721
5e242b0d
DS
1722DEFUN (bgp_maxpaths_ibgp_cluster,
1723 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1724 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1725 "Forward packets over multiple paths\n"
1726 "iBGP-multipath\n"
1727 "Number of paths\n"
1728 "Match the cluster length\n")
1729{
d62a17ae 1730 int idx_number = 2;
1731 return bgp_maxpaths_config_vty(
1732 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1733 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1734}
1735
d62a17ae 1736ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1737 "maximum-paths ibgp " CMD_RANGE_STR(
1738 1, MULTIPATH_NUM) " equal-cluster-length",
1739 "Forward packets over multiple paths\n"
1740 "iBGP-multipath\n"
1741 "Number of paths\n"
1742 "Match the cluster length\n")
596c17ba 1743
165b5fff
JB
1744DEFUN (no_bgp_maxpaths,
1745 no_bgp_maxpaths_cmd,
6319fd63 1746 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1747 NO_STR
1748 "Forward packets over multiple paths\n"
1749 "Number of paths\n")
1750{
d62a17ae 1751 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1752}
1753
d62a17ae 1754ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1755 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1756 "Forward packets over multiple paths\n"
1757 "Number of paths\n")
596c17ba 1758
165b5fff
JB
1759DEFUN (no_bgp_maxpaths_ibgp,
1760 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1761 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1762 NO_STR
1763 "Forward packets over multiple paths\n"
1764 "iBGP-multipath\n"
838758ac
DW
1765 "Number of paths\n"
1766 "Match the cluster length\n")
165b5fff 1767{
d62a17ae 1768 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1769}
1770
d62a17ae 1771ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1772 "no maximum-paths ibgp [" CMD_RANGE_STR(
1773 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1774 NO_STR
1775 "Forward packets over multiple paths\n"
1776 "iBGP-multipath\n"
1777 "Number of paths\n"
1778 "Match the cluster length\n")
596c17ba 1779
2b791107 1780void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1781 safi_t safi)
165b5fff 1782{
d62a17ae 1783 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1784 vty_out(vty, " maximum-paths %d\n",
1785 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1786 }
165b5fff 1787
d62a17ae 1788 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1789 vty_out(vty, " maximum-paths ibgp %d",
1790 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1791 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1792 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1793 vty_out(vty, " equal-cluster-length");
1794 vty_out(vty, "\n");
1795 }
165b5fff 1796}
6b0655a2 1797
718e3744 1798/* BGP timers. */
1799
1800DEFUN (bgp_timers,
1801 bgp_timers_cmd,
6147e2c6 1802 "timers bgp (0-65535) (0-65535)",
718e3744 1803 "Adjust routing timers\n"
1804 "BGP timers\n"
1805 "Keepalive interval\n"
1806 "Holdtime\n")
1807{
d62a17ae 1808 VTY_DECLVAR_CONTEXT(bgp, bgp);
1809 int idx_number = 2;
1810 int idx_number_2 = 3;
1811 unsigned long keepalive = 0;
1812 unsigned long holdtime = 0;
718e3744 1813
d62a17ae 1814 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1815 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1816
d62a17ae 1817 /* Holdtime value check. */
1818 if (holdtime < 3 && holdtime != 0) {
1819 vty_out(vty,
1820 "%% hold time value must be either 0 or greater than 3\n");
1821 return CMD_WARNING_CONFIG_FAILED;
1822 }
718e3744 1823
d62a17ae 1824 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1825
d62a17ae 1826 return CMD_SUCCESS;
718e3744 1827}
1828
1829DEFUN (no_bgp_timers,
1830 no_bgp_timers_cmd,
838758ac 1831 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1832 NO_STR
1833 "Adjust routing timers\n"
838758ac
DW
1834 "BGP timers\n"
1835 "Keepalive interval\n"
1836 "Holdtime\n")
718e3744 1837{
d62a17ae 1838 VTY_DECLVAR_CONTEXT(bgp, bgp);
1839 bgp_timers_unset(bgp);
718e3744 1840
d62a17ae 1841 return CMD_SUCCESS;
718e3744 1842}
1843
6b0655a2 1844
718e3744 1845DEFUN (bgp_client_to_client_reflection,
1846 bgp_client_to_client_reflection_cmd,
1847 "bgp client-to-client reflection",
1848 "BGP specific commands\n"
1849 "Configure client to client route reflection\n"
1850 "reflection of routes allowed\n")
1851{
d62a17ae 1852 VTY_DECLVAR_CONTEXT(bgp, bgp);
1853 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1854 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1855
d62a17ae 1856 return CMD_SUCCESS;
718e3744 1857}
1858
1859DEFUN (no_bgp_client_to_client_reflection,
1860 no_bgp_client_to_client_reflection_cmd,
1861 "no bgp client-to-client reflection",
1862 NO_STR
1863 "BGP specific commands\n"
1864 "Configure client to client route reflection\n"
1865 "reflection of routes allowed\n")
1866{
d62a17ae 1867 VTY_DECLVAR_CONTEXT(bgp, bgp);
1868 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1869 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1870
d62a17ae 1871 return CMD_SUCCESS;
718e3744 1872}
1873
1874/* "bgp always-compare-med" configuration. */
1875DEFUN (bgp_always_compare_med,
1876 bgp_always_compare_med_cmd,
1877 "bgp always-compare-med",
1878 "BGP specific commands\n"
1879 "Allow comparing MED from different neighbors\n")
1880{
d62a17ae 1881 VTY_DECLVAR_CONTEXT(bgp, bgp);
1882 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1883 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1884
d62a17ae 1885 return CMD_SUCCESS;
718e3744 1886}
1887
1888DEFUN (no_bgp_always_compare_med,
1889 no_bgp_always_compare_med_cmd,
1890 "no bgp always-compare-med",
1891 NO_STR
1892 "BGP specific commands\n"
1893 "Allow comparing MED from different neighbors\n")
1894{
d62a17ae 1895 VTY_DECLVAR_CONTEXT(bgp, bgp);
1896 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1897 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1898
d62a17ae 1899 return CMD_SUCCESS;
718e3744 1900}
6b0655a2 1901
9dac9fc8
DA
1902
1903DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1904 "bgp ebgp-requires-policy",
1905 "BGP specific commands\n"
1906 "Require in and out policy for eBGP peers (RFC8212)\n")
1907{
1908 VTY_DECLVAR_CONTEXT(bgp, bgp);
1909 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1910 return CMD_SUCCESS;
1911}
1912
1913DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1914 "no bgp ebgp-requires-policy",
1915 NO_STR
1916 "BGP specific commands\n"
1917 "Require in and out policy for eBGP peers (RFC8212)\n")
1918{
1919 VTY_DECLVAR_CONTEXT(bgp, bgp);
1920 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1921 return CMD_SUCCESS;
1922}
1923
fb29348a
DA
1924DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
1925 "bgp reject-as-sets",
1926 "BGP specific commands\n"
1927 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
1928{
1929 VTY_DECLVAR_CONTEXT(bgp, bgp);
1930 struct listnode *node, *nnode;
1931 struct peer *peer;
1932
1933 bgp->reject_as_sets = BGP_REJECT_AS_SETS_ENABLED;
1934
1935 /* Reset existing BGP sessions to reject routes
1936 * with aspath containing AS_SET or AS_CONFED_SET.
1937 */
1938 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1939 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
1940 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
1941 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
1942 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
1943 }
1944 }
1945
1946 return CMD_SUCCESS;
1947}
1948
1949DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
1950 "no bgp reject-as-sets",
1951 NO_STR
1952 "BGP specific commands\n"
1953 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
1954{
1955 VTY_DECLVAR_CONTEXT(bgp, bgp);
1956 struct listnode *node, *nnode;
1957 struct peer *peer;
1958
1959 bgp->reject_as_sets = BGP_REJECT_AS_SETS_DISABLED;
1960
1961 /* Reset existing BGP sessions to reject routes
1962 * with aspath containing AS_SET or AS_CONFED_SET.
1963 */
1964 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1965 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
1966 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
1967 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
1968 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
1969 }
1970 }
1971
1972 return CMD_SUCCESS;
1973}
9dac9fc8 1974
718e3744 1975/* "bgp deterministic-med" configuration. */
1976DEFUN (bgp_deterministic_med,
1977 bgp_deterministic_med_cmd,
1978 "bgp deterministic-med",
1979 "BGP specific commands\n"
1980 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1981{
d62a17ae 1982 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1983
d62a17ae 1984 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1985 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1986 bgp_recalculate_all_bestpaths(bgp);
1987 }
7aafcaca 1988
d62a17ae 1989 return CMD_SUCCESS;
718e3744 1990}
1991
1992DEFUN (no_bgp_deterministic_med,
1993 no_bgp_deterministic_med_cmd,
1994 "no bgp deterministic-med",
1995 NO_STR
1996 "BGP specific commands\n"
1997 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1998{
d62a17ae 1999 VTY_DECLVAR_CONTEXT(bgp, bgp);
2000 int bestpath_per_as_used;
2001 afi_t afi;
2002 safi_t safi;
2003 struct peer *peer;
2004 struct listnode *node, *nnode;
2005
2006 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
2007 bestpath_per_as_used = 0;
2008
2009 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 2010 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
2011 if (bgp_addpath_dmed_required(
2012 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
2013 bestpath_per_as_used = 1;
2014 break;
2015 }
d62a17ae 2016
2017 if (bestpath_per_as_used)
2018 break;
2019 }
2020
2021 if (bestpath_per_as_used) {
2022 vty_out(vty,
2023 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2024 return CMD_WARNING_CONFIG_FAILED;
2025 } else {
2026 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
2027 bgp_recalculate_all_bestpaths(bgp);
2028 }
2029 }
2030
2031 return CMD_SUCCESS;
718e3744 2032}
538621f2 2033
2034/* "bgp graceful-restart" configuration. */
2035DEFUN (bgp_graceful_restart,
2036 bgp_graceful_restart_cmd,
2037 "bgp graceful-restart",
2038 "BGP specific commands\n"
2039 "Graceful restart capability parameters\n")
2040{
d62a17ae 2041 VTY_DECLVAR_CONTEXT(bgp, bgp);
2042 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
2043 return CMD_SUCCESS;
538621f2 2044}
2045
2046DEFUN (no_bgp_graceful_restart,
2047 no_bgp_graceful_restart_cmd,
2048 "no bgp graceful-restart",
2049 NO_STR
2050 "BGP specific commands\n"
2051 "Graceful restart capability parameters\n")
2052{
d62a17ae 2053 VTY_DECLVAR_CONTEXT(bgp, bgp);
2054 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
2055 return CMD_SUCCESS;
538621f2 2056}
2057
93406d87 2058DEFUN (bgp_graceful_restart_stalepath_time,
2059 bgp_graceful_restart_stalepath_time_cmd,
c1779b7d 2060 "bgp graceful-restart stalepath-time (1-4095)",
93406d87 2061 "BGP specific commands\n"
2062 "Graceful restart capability parameters\n"
2063 "Set the max time to hold onto restarting peer's stale paths\n"
2064 "Delay value (seconds)\n")
2065{
d62a17ae 2066 VTY_DECLVAR_CONTEXT(bgp, bgp);
2067 int idx_number = 3;
d7c0a89a 2068 uint32_t stalepath;
93406d87 2069
d62a17ae 2070 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2071 bgp->stalepath_time = stalepath;
2072 return CMD_SUCCESS;
93406d87 2073}
2074
eb6f1b41
PG
2075DEFUN (bgp_graceful_restart_restart_time,
2076 bgp_graceful_restart_restart_time_cmd,
c72d0314 2077 "bgp graceful-restart restart-time (1-4095)",
eb6f1b41
PG
2078 "BGP specific commands\n"
2079 "Graceful restart capability parameters\n"
2080 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2081 "Delay value (seconds)\n")
2082{
d62a17ae 2083 VTY_DECLVAR_CONTEXT(bgp, bgp);
2084 int idx_number = 3;
d7c0a89a 2085 uint32_t restart;
eb6f1b41 2086
d62a17ae 2087 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2088 bgp->restart_time = restart;
2089 return CMD_SUCCESS;
eb6f1b41
PG
2090}
2091
93406d87 2092DEFUN (no_bgp_graceful_restart_stalepath_time,
2093 no_bgp_graceful_restart_stalepath_time_cmd,
c1779b7d 2094 "no bgp graceful-restart stalepath-time [(1-4095)]",
93406d87 2095 NO_STR
2096 "BGP specific commands\n"
2097 "Graceful restart capability parameters\n"
838758ac
DW
2098 "Set the max time to hold onto restarting peer's stale paths\n"
2099 "Delay value (seconds)\n")
93406d87 2100{
d62a17ae 2101 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2102
d62a17ae 2103 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2104 return CMD_SUCCESS;
93406d87 2105}
2106
eb6f1b41
PG
2107DEFUN (no_bgp_graceful_restart_restart_time,
2108 no_bgp_graceful_restart_restart_time_cmd,
c72d0314 2109 "no bgp graceful-restart restart-time [(1-4095)]",
eb6f1b41
PG
2110 NO_STR
2111 "BGP specific commands\n"
2112 "Graceful restart capability parameters\n"
838758ac
DW
2113 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2114 "Delay value (seconds)\n")
eb6f1b41 2115{
d62a17ae 2116 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2117
d62a17ae 2118 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2119 return CMD_SUCCESS;
eb6f1b41
PG
2120}
2121
43fc21b3
JC
2122DEFUN (bgp_graceful_restart_preserve_fw,
2123 bgp_graceful_restart_preserve_fw_cmd,
2124 "bgp graceful-restart preserve-fw-state",
2125 "BGP specific commands\n"
2126 "Graceful restart capability parameters\n"
2127 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2128{
d62a17ae 2129 VTY_DECLVAR_CONTEXT(bgp, bgp);
2130 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2131 return CMD_SUCCESS;
43fc21b3
JC
2132}
2133
2134DEFUN (no_bgp_graceful_restart_preserve_fw,
2135 no_bgp_graceful_restart_preserve_fw_cmd,
2136 "no bgp graceful-restart preserve-fw-state",
2137 NO_STR
2138 "BGP specific commands\n"
2139 "Graceful restart capability parameters\n"
2140 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2141{
d62a17ae 2142 VTY_DECLVAR_CONTEXT(bgp, bgp);
2143 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2144 return CMD_SUCCESS;
43fc21b3
JC
2145}
2146
7f323236
DW
2147/* "bgp graceful-shutdown" configuration */
2148DEFUN (bgp_graceful_shutdown,
2149 bgp_graceful_shutdown_cmd,
2150 "bgp graceful-shutdown",
2151 BGP_STR
2152 "Graceful shutdown parameters\n")
2153{
2154 VTY_DECLVAR_CONTEXT(bgp, bgp);
2155
2156 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2157 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2158 bgp_static_redo_import_check(bgp);
2159 bgp_redistribute_redo(bgp);
2160 bgp_clear_star_soft_out(vty, bgp->name);
2161 bgp_clear_star_soft_in(vty, bgp->name);
2162 }
2163
2164 return CMD_SUCCESS;
2165}
2166
2167DEFUN (no_bgp_graceful_shutdown,
2168 no_bgp_graceful_shutdown_cmd,
2169 "no bgp graceful-shutdown",
2170 NO_STR
2171 BGP_STR
2172 "Graceful shutdown parameters\n")
2173{
2174 VTY_DECLVAR_CONTEXT(bgp, bgp);
2175
2176 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2177 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2178 bgp_static_redo_import_check(bgp);
2179 bgp_redistribute_redo(bgp);
2180 bgp_clear_star_soft_out(vty, bgp->name);
2181 bgp_clear_star_soft_in(vty, bgp->name);
2182 }
2183
2184 return CMD_SUCCESS;
2185}
2186
718e3744 2187/* "bgp fast-external-failover" configuration. */
2188DEFUN (bgp_fast_external_failover,
2189 bgp_fast_external_failover_cmd,
2190 "bgp fast-external-failover",
2191 BGP_STR
2192 "Immediately reset session if a link to a directly connected external peer goes down\n")
2193{
d62a17ae 2194 VTY_DECLVAR_CONTEXT(bgp, bgp);
2195 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2196 return CMD_SUCCESS;
718e3744 2197}
2198
2199DEFUN (no_bgp_fast_external_failover,
2200 no_bgp_fast_external_failover_cmd,
2201 "no bgp fast-external-failover",
2202 NO_STR
2203 BGP_STR
2204 "Immediately reset session if a link to a directly connected external peer goes down\n")
2205{
d62a17ae 2206 VTY_DECLVAR_CONTEXT(bgp, bgp);
2207 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2208 return CMD_SUCCESS;
718e3744 2209}
6b0655a2 2210
718e3744 2211/* "bgp bestpath compare-routerid" configuration. */
2212DEFUN (bgp_bestpath_compare_router_id,
2213 bgp_bestpath_compare_router_id_cmd,
2214 "bgp bestpath compare-routerid",
2215 "BGP specific commands\n"
2216 "Change the default bestpath selection\n"
2217 "Compare router-id for identical EBGP paths\n")
2218{
d62a17ae 2219 VTY_DECLVAR_CONTEXT(bgp, bgp);
2220 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2221 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2222
d62a17ae 2223 return CMD_SUCCESS;
718e3744 2224}
2225
2226DEFUN (no_bgp_bestpath_compare_router_id,
2227 no_bgp_bestpath_compare_router_id_cmd,
2228 "no bgp bestpath compare-routerid",
2229 NO_STR
2230 "BGP specific commands\n"
2231 "Change the default bestpath selection\n"
2232 "Compare router-id for identical EBGP paths\n")
2233{
d62a17ae 2234 VTY_DECLVAR_CONTEXT(bgp, bgp);
2235 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2236 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2237
d62a17ae 2238 return CMD_SUCCESS;
718e3744 2239}
6b0655a2 2240
718e3744 2241/* "bgp bestpath as-path ignore" configuration. */
2242DEFUN (bgp_bestpath_aspath_ignore,
2243 bgp_bestpath_aspath_ignore_cmd,
2244 "bgp bestpath as-path ignore",
2245 "BGP specific commands\n"
2246 "Change the default bestpath selection\n"
2247 "AS-path attribute\n"
2248 "Ignore as-path length in selecting a route\n")
2249{
d62a17ae 2250 VTY_DECLVAR_CONTEXT(bgp, bgp);
2251 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2252 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2253
d62a17ae 2254 return CMD_SUCCESS;
718e3744 2255}
2256
2257DEFUN (no_bgp_bestpath_aspath_ignore,
2258 no_bgp_bestpath_aspath_ignore_cmd,
2259 "no bgp bestpath as-path ignore",
2260 NO_STR
2261 "BGP specific commands\n"
2262 "Change the default bestpath selection\n"
2263 "AS-path attribute\n"
2264 "Ignore as-path length in selecting a route\n")
2265{
d62a17ae 2266 VTY_DECLVAR_CONTEXT(bgp, bgp);
2267 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2268 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2269
d62a17ae 2270 return CMD_SUCCESS;
718e3744 2271}
6b0655a2 2272
6811845b 2273/* "bgp bestpath as-path confed" configuration. */
2274DEFUN (bgp_bestpath_aspath_confed,
2275 bgp_bestpath_aspath_confed_cmd,
2276 "bgp bestpath as-path confed",
2277 "BGP specific commands\n"
2278 "Change the default bestpath selection\n"
2279 "AS-path attribute\n"
2280 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2281{
d62a17ae 2282 VTY_DECLVAR_CONTEXT(bgp, bgp);
2283 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2284 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2285
d62a17ae 2286 return CMD_SUCCESS;
6811845b 2287}
2288
2289DEFUN (no_bgp_bestpath_aspath_confed,
2290 no_bgp_bestpath_aspath_confed_cmd,
2291 "no bgp bestpath as-path confed",
2292 NO_STR
2293 "BGP specific commands\n"
2294 "Change the default bestpath selection\n"
2295 "AS-path attribute\n"
2296 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2297{
d62a17ae 2298 VTY_DECLVAR_CONTEXT(bgp, bgp);
2299 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2300 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2301
d62a17ae 2302 return CMD_SUCCESS;
6811845b 2303}
6b0655a2 2304
2fdd455c
PM
2305/* "bgp bestpath as-path multipath-relax" configuration. */
2306DEFUN (bgp_bestpath_aspath_multipath_relax,
2307 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2308 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2309 "BGP specific commands\n"
2310 "Change the default bestpath selection\n"
2311 "AS-path attribute\n"
2312 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2313 "Generate an AS_SET\n"
16fc1eec
DS
2314 "Do not generate an AS_SET\n")
2315{
d62a17ae 2316 VTY_DECLVAR_CONTEXT(bgp, bgp);
2317 int idx = 0;
2318 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2319
d62a17ae 2320 /* no-as-set is now the default behavior so we can silently
2321 * ignore it */
2322 if (argv_find(argv, argc, "as-set", &idx))
2323 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2324 else
2325 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2326
d62a17ae 2327 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2328
d62a17ae 2329 return CMD_SUCCESS;
16fc1eec
DS
2330}
2331
219178b6
DW
2332DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2333 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2334 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2335 NO_STR
2336 "BGP specific commands\n"
2337 "Change the default bestpath selection\n"
2338 "AS-path attribute\n"
2339 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2340 "Generate an AS_SET\n"
16fc1eec
DS
2341 "Do not generate an AS_SET\n")
2342{
d62a17ae 2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
2344 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2345 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2346 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2347
d62a17ae 2348 return CMD_SUCCESS;
2fdd455c 2349}
6b0655a2 2350
848973c7 2351/* "bgp log-neighbor-changes" configuration. */
2352DEFUN (bgp_log_neighbor_changes,
2353 bgp_log_neighbor_changes_cmd,
2354 "bgp log-neighbor-changes",
2355 "BGP specific commands\n"
2356 "Log neighbor up/down and reset reason\n")
2357{
d62a17ae 2358 VTY_DECLVAR_CONTEXT(bgp, bgp);
2359 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2360 return CMD_SUCCESS;
848973c7 2361}
2362
2363DEFUN (no_bgp_log_neighbor_changes,
2364 no_bgp_log_neighbor_changes_cmd,
2365 "no bgp log-neighbor-changes",
2366 NO_STR
2367 "BGP specific commands\n"
2368 "Log neighbor up/down and reset reason\n")
2369{
d62a17ae 2370 VTY_DECLVAR_CONTEXT(bgp, bgp);
2371 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2372 return CMD_SUCCESS;
848973c7 2373}
6b0655a2 2374
718e3744 2375/* "bgp bestpath med" configuration. */
2376DEFUN (bgp_bestpath_med,
2377 bgp_bestpath_med_cmd,
2d8c1a4d 2378 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2379 "BGP specific commands\n"
2380 "Change the default bestpath selection\n"
2381 "MED attribute\n"
2382 "Compare MED among confederation paths\n"
838758ac
DW
2383 "Treat missing MED as the least preferred one\n"
2384 "Treat missing MED as the least preferred one\n"
2385 "Compare MED among confederation paths\n")
718e3744 2386{
d62a17ae 2387 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2388
d62a17ae 2389 int idx = 0;
2390 if (argv_find(argv, argc, "confed", &idx))
2391 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2392 idx = 0;
2393 if (argv_find(argv, argc, "missing-as-worst", &idx))
2394 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2395
d62a17ae 2396 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2397
d62a17ae 2398 return CMD_SUCCESS;
718e3744 2399}
2400
718e3744 2401DEFUN (no_bgp_bestpath_med,
2402 no_bgp_bestpath_med_cmd,
2d8c1a4d 2403 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2404 NO_STR
2405 "BGP specific commands\n"
2406 "Change the default bestpath selection\n"
2407 "MED attribute\n"
2408 "Compare MED among confederation paths\n"
3a2d747c
QY
2409 "Treat missing MED as the least preferred one\n"
2410 "Treat missing MED as the least preferred one\n"
2411 "Compare MED among confederation paths\n")
718e3744 2412{
d62a17ae 2413 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2414
d62a17ae 2415 int idx = 0;
2416 if (argv_find(argv, argc, "confed", &idx))
2417 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2418 idx = 0;
2419 if (argv_find(argv, argc, "missing-as-worst", &idx))
2420 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2421
d62a17ae 2422 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2423
d62a17ae 2424 return CMD_SUCCESS;
718e3744 2425}
2426
718e3744 2427/* "no bgp default ipv4-unicast". */
2428DEFUN (no_bgp_default_ipv4_unicast,
2429 no_bgp_default_ipv4_unicast_cmd,
2430 "no bgp default ipv4-unicast",
2431 NO_STR
2432 "BGP specific commands\n"
2433 "Configure BGP defaults\n"
2434 "Activate ipv4-unicast for a peer by default\n")
2435{
d62a17ae 2436 VTY_DECLVAR_CONTEXT(bgp, bgp);
2437 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2438 return CMD_SUCCESS;
718e3744 2439}
2440
2441DEFUN (bgp_default_ipv4_unicast,
2442 bgp_default_ipv4_unicast_cmd,
2443 "bgp default ipv4-unicast",
2444 "BGP specific commands\n"
2445 "Configure BGP defaults\n"
2446 "Activate ipv4-unicast for a peer by default\n")
2447{
d62a17ae 2448 VTY_DECLVAR_CONTEXT(bgp, bgp);
2449 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2450 return CMD_SUCCESS;
718e3744 2451}
6b0655a2 2452
04b6bdc0
DW
2453/* Display hostname in certain command outputs */
2454DEFUN (bgp_default_show_hostname,
2455 bgp_default_show_hostname_cmd,
2456 "bgp default show-hostname",
2457 "BGP specific commands\n"
2458 "Configure BGP defaults\n"
0437e105 2459 "Show hostname in certain command outputs\n")
04b6bdc0 2460{
d62a17ae 2461 VTY_DECLVAR_CONTEXT(bgp, bgp);
2462 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2463 return CMD_SUCCESS;
04b6bdc0
DW
2464}
2465
2466DEFUN (no_bgp_default_show_hostname,
2467 no_bgp_default_show_hostname_cmd,
2468 "no bgp default show-hostname",
2469 NO_STR
2470 "BGP specific commands\n"
2471 "Configure BGP defaults\n"
0437e105 2472 "Show hostname in certain command outputs\n")
04b6bdc0 2473{
d62a17ae 2474 VTY_DECLVAR_CONTEXT(bgp, bgp);
2475 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2476 return CMD_SUCCESS;
04b6bdc0
DW
2477}
2478
8233ef81 2479/* "bgp network import-check" configuration. */
718e3744 2480DEFUN (bgp_network_import_check,
2481 bgp_network_import_check_cmd,
5623e905 2482 "bgp network import-check",
718e3744 2483 "BGP specific commands\n"
2484 "BGP network command\n"
5623e905 2485 "Check BGP network route exists in IGP\n")
718e3744 2486{
d62a17ae 2487 VTY_DECLVAR_CONTEXT(bgp, bgp);
2488 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2489 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2490 bgp_static_redo_import_check(bgp);
2491 }
078430f6 2492
d62a17ae 2493 return CMD_SUCCESS;
718e3744 2494}
2495
d62a17ae 2496ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2497 "bgp network import-check exact",
2498 "BGP specific commands\n"
2499 "BGP network command\n"
2500 "Check BGP network route exists in IGP\n"
2501 "Match route precisely\n")
8233ef81 2502
718e3744 2503DEFUN (no_bgp_network_import_check,
2504 no_bgp_network_import_check_cmd,
5623e905 2505 "no bgp network import-check",
718e3744 2506 NO_STR
2507 "BGP specific commands\n"
2508 "BGP network command\n"
2509 "Check BGP network route exists in IGP\n")
2510{
d62a17ae 2511 VTY_DECLVAR_CONTEXT(bgp, bgp);
2512 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2513 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2514 bgp_static_redo_import_check(bgp);
2515 }
5623e905 2516
d62a17ae 2517 return CMD_SUCCESS;
718e3744 2518}
6b0655a2 2519
718e3744 2520DEFUN (bgp_default_local_preference,
2521 bgp_default_local_preference_cmd,
6147e2c6 2522 "bgp default local-preference (0-4294967295)",
718e3744 2523 "BGP specific commands\n"
2524 "Configure BGP defaults\n"
2525 "local preference (higher=more preferred)\n"
2526 "Configure default local preference value\n")
2527{
d62a17ae 2528 VTY_DECLVAR_CONTEXT(bgp, bgp);
2529 int idx_number = 3;
d7c0a89a 2530 uint32_t local_pref;
718e3744 2531
d62a17ae 2532 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2533
d62a17ae 2534 bgp_default_local_preference_set(bgp, local_pref);
2535 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2536
d62a17ae 2537 return CMD_SUCCESS;
718e3744 2538}
2539
2540DEFUN (no_bgp_default_local_preference,
2541 no_bgp_default_local_preference_cmd,
838758ac 2542 "no bgp default local-preference [(0-4294967295)]",
718e3744 2543 NO_STR
2544 "BGP specific commands\n"
2545 "Configure BGP defaults\n"
838758ac
DW
2546 "local preference (higher=more preferred)\n"
2547 "Configure default local preference value\n")
718e3744 2548{
d62a17ae 2549 VTY_DECLVAR_CONTEXT(bgp, bgp);
2550 bgp_default_local_preference_unset(bgp);
2551 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2552
d62a17ae 2553 return CMD_SUCCESS;
718e3744 2554}
2555
6b0655a2 2556
3f9c7369
DS
2557DEFUN (bgp_default_subgroup_pkt_queue_max,
2558 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2559 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2560 "BGP specific commands\n"
2561 "Configure BGP defaults\n"
2562 "subgroup-pkt-queue-max\n"
2563 "Configure subgroup packet queue max\n")
8bd9d948 2564{
d62a17ae 2565 VTY_DECLVAR_CONTEXT(bgp, bgp);
2566 int idx_number = 3;
d7c0a89a 2567 uint32_t max_size;
8bd9d948 2568
d62a17ae 2569 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2570
d62a17ae 2571 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2572
d62a17ae 2573 return CMD_SUCCESS;
3f9c7369
DS
2574}
2575
2576DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2577 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2578 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2579 NO_STR
2580 "BGP specific commands\n"
2581 "Configure BGP defaults\n"
838758ac
DW
2582 "subgroup-pkt-queue-max\n"
2583 "Configure subgroup packet queue max\n")
3f9c7369 2584{
d62a17ae 2585 VTY_DECLVAR_CONTEXT(bgp, bgp);
2586 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2587 return CMD_SUCCESS;
8bd9d948
DS
2588}
2589
813d4307 2590
8bd9d948
DS
2591DEFUN (bgp_rr_allow_outbound_policy,
2592 bgp_rr_allow_outbound_policy_cmd,
2593 "bgp route-reflector allow-outbound-policy",
2594 "BGP specific commands\n"
2595 "Allow modifications made by out route-map\n"
2596 "on ibgp neighbors\n")
2597{
d62a17ae 2598 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2599
d62a17ae 2600 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2601 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2602 update_group_announce_rrclients(bgp);
2603 bgp_clear_star_soft_out(vty, bgp->name);
2604 }
8bd9d948 2605
d62a17ae 2606 return CMD_SUCCESS;
8bd9d948
DS
2607}
2608
2609DEFUN (no_bgp_rr_allow_outbound_policy,
2610 no_bgp_rr_allow_outbound_policy_cmd,
2611 "no bgp route-reflector allow-outbound-policy",
2612 NO_STR
2613 "BGP specific commands\n"
2614 "Allow modifications made by out route-map\n"
2615 "on ibgp neighbors\n")
2616{
d62a17ae 2617 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2618
d62a17ae 2619 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2620 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2621 update_group_announce_rrclients(bgp);
2622 bgp_clear_star_soft_out(vty, bgp->name);
2623 }
8bd9d948 2624
d62a17ae 2625 return CMD_SUCCESS;
8bd9d948
DS
2626}
2627
f14e6fdb
DS
2628DEFUN (bgp_listen_limit,
2629 bgp_listen_limit_cmd,
9ccf14f7 2630 "bgp listen limit (1-5000)",
f14e6fdb
DS
2631 "BGP specific commands\n"
2632 "Configure BGP defaults\n"
2633 "maximum number of BGP Dynamic Neighbors that can be created\n"
2634 "Configure Dynamic Neighbors listen limit value\n")
2635{
d62a17ae 2636 VTY_DECLVAR_CONTEXT(bgp, bgp);
2637 int idx_number = 3;
2638 int listen_limit;
f14e6fdb 2639
d62a17ae 2640 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2641
d62a17ae 2642 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2643
d62a17ae 2644 return CMD_SUCCESS;
f14e6fdb
DS
2645}
2646
2647DEFUN (no_bgp_listen_limit,
2648 no_bgp_listen_limit_cmd,
838758ac 2649 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2650 "BGP specific commands\n"
2651 "Configure BGP defaults\n"
2652 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2653 "Configure Dynamic Neighbors listen limit value to default\n"
2654 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2655{
d62a17ae 2656 VTY_DECLVAR_CONTEXT(bgp, bgp);
2657 bgp_listen_limit_unset(bgp);
2658 return CMD_SUCCESS;
f14e6fdb
DS
2659}
2660
2661
20eb8864 2662/*
2663 * Check if this listen range is already configured. Check for exact
2664 * match or overlap based on input.
2665 */
d62a17ae 2666static struct peer_group *listen_range_exists(struct bgp *bgp,
2667 struct prefix *range, int exact)
2668{
2669 struct listnode *node, *nnode;
2670 struct listnode *node1, *nnode1;
2671 struct peer_group *group;
2672 struct prefix *lr;
2673 afi_t afi;
2674 int match;
2675
2676 afi = family2afi(range->family);
2677 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2678 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2679 lr)) {
2680 if (exact)
2681 match = prefix_same(range, lr);
2682 else
2683 match = (prefix_match(range, lr)
2684 || prefix_match(lr, range));
2685 if (match)
2686 return group;
2687 }
2688 }
2689
2690 return NULL;
20eb8864 2691}
2692
f14e6fdb
DS
2693DEFUN (bgp_listen_range,
2694 bgp_listen_range_cmd,
d7b9898c 2695 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 2696 "BGP specific commands\n"
d7fa34c1
QY
2697 "Configure BGP dynamic neighbors listen range\n"
2698 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2699 NEIGHBOR_ADDR_STR
2700 "Member of the peer-group\n"
2701 "Peer-group name\n")
f14e6fdb 2702{
d62a17ae 2703 VTY_DECLVAR_CONTEXT(bgp, bgp);
2704 struct prefix range;
2705 struct peer_group *group, *existing_group;
2706 afi_t afi;
2707 int ret;
2708 int idx = 0;
2709
2710 argv_find(argv, argc, "A.B.C.D/M", &idx);
2711 argv_find(argv, argc, "X:X::X:X/M", &idx);
2712 char *prefix = argv[idx]->arg;
d7b9898c 2713 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 2714 char *peergroup = argv[idx]->arg;
2715
2716 /* Convert IP prefix string to struct prefix. */
2717 ret = str2prefix(prefix, &range);
2718 if (!ret) {
2719 vty_out(vty, "%% Malformed listen range\n");
2720 return CMD_WARNING_CONFIG_FAILED;
2721 }
2722
2723 afi = family2afi(range.family);
2724
2725 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2726 vty_out(vty,
2727 "%% Malformed listen range (link-local address)\n");
2728 return CMD_WARNING_CONFIG_FAILED;
2729 }
2730
2731 apply_mask(&range);
2732
2733 /* Check if same listen range is already configured. */
2734 existing_group = listen_range_exists(bgp, &range, 1);
2735 if (existing_group) {
2736 if (strcmp(existing_group->name, peergroup) == 0)
2737 return CMD_SUCCESS;
2738 else {
2739 vty_out(vty,
2740 "%% Same listen range is attached to peer-group %s\n",
2741 existing_group->name);
2742 return CMD_WARNING_CONFIG_FAILED;
2743 }
2744 }
2745
2746 /* Check if an overlapping listen range exists. */
2747 if (listen_range_exists(bgp, &range, 0)) {
2748 vty_out(vty,
2749 "%% Listen range overlaps with existing listen range\n");
2750 return CMD_WARNING_CONFIG_FAILED;
2751 }
2752
2753 group = peer_group_lookup(bgp, peergroup);
2754 if (!group) {
2755 vty_out(vty, "%% Configure the peer-group first\n");
2756 return CMD_WARNING_CONFIG_FAILED;
2757 }
2758
2759 ret = peer_group_listen_range_add(group, &range);
2760 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2761}
2762
2763DEFUN (no_bgp_listen_range,
2764 no_bgp_listen_range_cmd,
d7b9898c 2765 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 2766 NO_STR
f14e6fdb 2767 "BGP specific commands\n"
d7fa34c1
QY
2768 "Unconfigure BGP dynamic neighbors listen range\n"
2769 "Unconfigure BGP dynamic neighbors listen range\n"
2770 NEIGHBOR_ADDR_STR
2771 "Member of the peer-group\n"
2772 "Peer-group name\n")
f14e6fdb 2773{
d62a17ae 2774 VTY_DECLVAR_CONTEXT(bgp, bgp);
2775 struct prefix range;
2776 struct peer_group *group;
2777 afi_t afi;
2778 int ret;
2779 int idx = 0;
2780
2781 argv_find(argv, argc, "A.B.C.D/M", &idx);
2782 argv_find(argv, argc, "X:X::X:X/M", &idx);
2783 char *prefix = argv[idx]->arg;
2784 argv_find(argv, argc, "WORD", &idx);
2785 char *peergroup = argv[idx]->arg;
2786
2787 /* Convert IP prefix string to struct prefix. */
2788 ret = str2prefix(prefix, &range);
2789 if (!ret) {
2790 vty_out(vty, "%% Malformed listen range\n");
2791 return CMD_WARNING_CONFIG_FAILED;
2792 }
2793
2794 afi = family2afi(range.family);
2795
2796 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2797 vty_out(vty,
2798 "%% Malformed listen range (link-local address)\n");
2799 return CMD_WARNING_CONFIG_FAILED;
2800 }
2801
2802 apply_mask(&range);
2803
2804 group = peer_group_lookup(bgp, peergroup);
2805 if (!group) {
2806 vty_out(vty, "%% Peer-group does not exist\n");
2807 return CMD_WARNING_CONFIG_FAILED;
2808 }
2809
2810 ret = peer_group_listen_range_del(group, &range);
2811 return bgp_vty_return(vty, ret);
2812}
2813
2b791107 2814void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2815{
2816 struct peer_group *group;
2817 struct listnode *node, *nnode, *rnode, *nrnode;
2818 struct prefix *range;
2819 afi_t afi;
2820 char buf[PREFIX2STR_BUFFER];
2821
2822 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2823 vty_out(vty, " bgp listen limit %d\n",
2824 bgp->dynamic_neighbors_limit);
2825
2826 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2827 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2828 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2829 nrnode, range)) {
2830 prefix2str(range, buf, sizeof(buf));
2831 vty_out(vty,
2832 " bgp listen range %s peer-group %s\n",
2833 buf, group->name);
2834 }
2835 }
2836 }
f14e6fdb
DS
2837}
2838
2839
907f92c8
DS
2840DEFUN (bgp_disable_connected_route_check,
2841 bgp_disable_connected_route_check_cmd,
2842 "bgp disable-ebgp-connected-route-check",
2843 "BGP specific commands\n"
2844 "Disable checking if nexthop is connected on ebgp sessions\n")
2845{
d62a17ae 2846 VTY_DECLVAR_CONTEXT(bgp, bgp);
2847 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2848 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2849
d62a17ae 2850 return CMD_SUCCESS;
907f92c8
DS
2851}
2852
2853DEFUN (no_bgp_disable_connected_route_check,
2854 no_bgp_disable_connected_route_check_cmd,
2855 "no bgp disable-ebgp-connected-route-check",
2856 NO_STR
2857 "BGP specific commands\n"
2858 "Disable checking if nexthop is connected on ebgp sessions\n")
2859{
d62a17ae 2860 VTY_DECLVAR_CONTEXT(bgp, bgp);
2861 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2862 bgp_clear_star_soft_in(vty, bgp->name);
2863
2864 return CMD_SUCCESS;
2865}
2866
2867
2868static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2869 const char *as_str, afi_t afi, safi_t safi)
2870{
2871 VTY_DECLVAR_CONTEXT(bgp, bgp);
2872 int ret;
2873 as_t as;
2874 int as_type = AS_SPECIFIED;
2875 union sockunion su;
2876
2877 if (as_str[0] == 'i') {
2878 as = 0;
2879 as_type = AS_INTERNAL;
2880 } else if (as_str[0] == 'e') {
2881 as = 0;
2882 as_type = AS_EXTERNAL;
2883 } else {
2884 /* Get AS number. */
2885 as = strtoul(as_str, NULL, 10);
2886 }
2887
390485fd 2888 /* If peer is peer group or interface peer, call proper function. */
d62a17ae 2889 ret = str2sockunion(peer_str, &su);
2890 if (ret < 0) {
390485fd
DS
2891 struct peer *peer;
2892
2893 /* Check if existing interface peer */
2894 peer = peer_lookup_by_conf_if(bgp, peer_str);
2895
d62a17ae 2896 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2897 safi);
390485fd
DS
2898
2899 /* if not interface peer, check peer-group settings */
2900 if (ret < 0 && !peer) {
d62a17ae 2901 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2902 if (ret < 0) {
2903 vty_out(vty,
390485fd 2904 "%% Create the peer-group or interface first\n");
d62a17ae 2905 return CMD_WARNING_CONFIG_FAILED;
2906 }
2907 return CMD_SUCCESS;
2908 }
2909 } else {
2910 if (peer_address_self_check(bgp, &su)) {
2911 vty_out(vty,
2912 "%% Can not configure the local system as neighbor\n");
2913 return CMD_WARNING_CONFIG_FAILED;
2914 }
2915 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2916 }
2917
2918 /* This peer belongs to peer group. */
2919 switch (ret) {
2920 case BGP_ERR_PEER_GROUP_MEMBER:
2921 vty_out(vty,
faa16034 2922 "%% Peer-group member cannot override remote-as of peer-group\n");
d62a17ae 2923 return CMD_WARNING_CONFIG_FAILED;
2924 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2925 vty_out(vty,
faa16034 2926 "%% Peer-group members must be all internal or all external\n");
d62a17ae 2927 return CMD_WARNING_CONFIG_FAILED;
2928 }
2929 return bgp_vty_return(vty, ret);
718e3744 2930}
2931
f26845f9
QY
2932DEFUN (bgp_default_shutdown,
2933 bgp_default_shutdown_cmd,
2934 "[no] bgp default shutdown",
2935 NO_STR
2936 BGP_STR
2937 "Configure BGP defaults\n"
b012cbe2 2938 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2939{
2940 VTY_DECLVAR_CONTEXT(bgp, bgp);
2941 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2942 return CMD_SUCCESS;
2943}
2944
718e3744 2945DEFUN (neighbor_remote_as,
2946 neighbor_remote_as_cmd,
3a2d747c 2947 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2948 NEIGHBOR_STR
2949 NEIGHBOR_ADDR_STR2
2950 "Specify a BGP neighbor\n"
d7fa34c1 2951 AS_STR
3a2d747c
QY
2952 "Internal BGP peer\n"
2953 "External BGP peer\n")
718e3744 2954{
d62a17ae 2955 int idx_peer = 1;
2956 int idx_remote_as = 3;
2957 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2958 argv[idx_remote_as]->arg, AFI_IP,
2959 SAFI_UNICAST);
2960}
2961
2962static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2963 afi_t afi, safi_t safi, int v6only,
2964 const char *peer_group_name,
2965 const char *as_str)
2966{
2967 VTY_DECLVAR_CONTEXT(bgp, bgp);
2968 as_t as = 0;
2969 int as_type = AS_UNSPECIFIED;
2970 struct peer *peer;
2971 struct peer_group *group;
2972 int ret = 0;
2973 union sockunion su;
2974
2975 group = peer_group_lookup(bgp, conf_if);
2976
2977 if (group) {
2978 vty_out(vty, "%% Name conflict with peer-group \n");
2979 return CMD_WARNING_CONFIG_FAILED;
2980 }
2981
2982 if (as_str) {
2983 if (as_str[0] == 'i') {
2984 as_type = AS_INTERNAL;
2985 } else if (as_str[0] == 'e') {
2986 as_type = AS_EXTERNAL;
2987 } else {
2988 /* Get AS number. */
2989 as = strtoul(as_str, NULL, 10);
2990 as_type = AS_SPECIFIED;
2991 }
2992 }
2993
2994 peer = peer_lookup_by_conf_if(bgp, conf_if);
2995 if (peer) {
2996 if (as_str)
cc4d4ce8 2997 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 2998 afi, safi);
2999 } else {
3000 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
3001 && afi == AFI_IP && safi == SAFI_UNICAST)
3002 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3003 as_type, 0, 0, NULL);
3004 else
3005 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3006 as_type, afi, safi, NULL);
3007
3008 if (!peer) {
3009 vty_out(vty, "%% BGP failed to create peer\n");
3010 return CMD_WARNING_CONFIG_FAILED;
3011 }
3012
3013 if (v6only)
527de3dc 3014 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3015
3016 /* Request zebra to initiate IPv6 RAs on this interface. We do
3017 * this
3018 * any unnumbered peer in order to not worry about run-time
3019 * transitions
3020 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
3021 * address
3022 * gets deleted later etc.)
3023 */
3024 if (peer->ifp)
3025 bgp_zebra_initiate_radv(bgp, peer);
3026 }
3027
3028 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
3029 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
3030 if (v6only)
527de3dc 3031 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3032 else
527de3dc 3033 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3034
3035 /* v6only flag changed. Reset bgp seesion */
3036 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
3037 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
3038 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
3039 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
3040 } else
3041 bgp_session_reset(peer);
3042 }
3043
9fb964de
PM
3044 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3045 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3046 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 3047 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 3048 }
d62a17ae 3049
3050 if (peer_group_name) {
3051 group = peer_group_lookup(bgp, peer_group_name);
3052 if (!group) {
3053 vty_out(vty, "%% Configure the peer-group first\n");
3054 return CMD_WARNING_CONFIG_FAILED;
3055 }
3056
3057 ret = peer_group_bind(bgp, &su, peer, group, &as);
3058 }
3059
3060 return bgp_vty_return(vty, ret);
a80beece
DS
3061}
3062
4c48cf63
DW
3063DEFUN (neighbor_interface_config,
3064 neighbor_interface_config_cmd,
d7b9898c 3065 "neighbor WORD interface [peer-group PGNAME]",
4c48cf63
DW
3066 NEIGHBOR_STR
3067 "Interface name or neighbor tag\n"
31500417
DW
3068 "Enable BGP on interface\n"
3069 "Member of the peer-group\n"
16cedbb0 3070 "Peer-group name\n")
4c48cf63 3071{
d62a17ae 3072 int idx_word = 1;
3073 int idx_peer_group_word = 4;
31500417 3074
d62a17ae 3075 if (argc > idx_peer_group_word)
3076 return peer_conf_interface_get(
3077 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3078 argv[idx_peer_group_word]->arg, NULL);
3079 else
3080 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3081 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
3082}
3083
4c48cf63
DW
3084DEFUN (neighbor_interface_config_v6only,
3085 neighbor_interface_config_v6only_cmd,
d7b9898c 3086 "neighbor WORD interface v6only [peer-group PGNAME]",
4c48cf63
DW
3087 NEIGHBOR_STR
3088 "Interface name or neighbor tag\n"
3089 "Enable BGP on interface\n"
31500417
DW
3090 "Enable BGP with v6 link-local only\n"
3091 "Member of the peer-group\n"
16cedbb0 3092 "Peer-group name\n")
4c48cf63 3093{
d62a17ae 3094 int idx_word = 1;
3095 int idx_peer_group_word = 5;
31500417 3096
d62a17ae 3097 if (argc > idx_peer_group_word)
3098 return peer_conf_interface_get(
3099 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3100 argv[idx_peer_group_word]->arg, NULL);
31500417 3101
d62a17ae 3102 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3103 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
3104}
3105
a80beece 3106
b3a39dc5
DD
3107DEFUN (neighbor_interface_config_remote_as,
3108 neighbor_interface_config_remote_as_cmd,
3a2d747c 3109 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3110 NEIGHBOR_STR
3111 "Interface name or neighbor tag\n"
3112 "Enable BGP on interface\n"
3a2d747c 3113 "Specify a BGP neighbor\n"
d7fa34c1 3114 AS_STR
3a2d747c
QY
3115 "Internal BGP peer\n"
3116 "External BGP peer\n")
b3a39dc5 3117{
d62a17ae 3118 int idx_word = 1;
3119 int idx_remote_as = 4;
3120 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3121 SAFI_UNICAST, 0, NULL,
3122 argv[idx_remote_as]->arg);
b3a39dc5
DD
3123}
3124
3125DEFUN (neighbor_interface_v6only_config_remote_as,
3126 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 3127 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3128 NEIGHBOR_STR
3129 "Interface name or neighbor tag\n"
3a2d747c 3130 "Enable BGP with v6 link-local only\n"
b3a39dc5 3131 "Enable BGP on interface\n"
3a2d747c 3132 "Specify a BGP neighbor\n"
d7fa34c1 3133 AS_STR
3a2d747c
QY
3134 "Internal BGP peer\n"
3135 "External BGP peer\n")
b3a39dc5 3136{
d62a17ae 3137 int idx_word = 1;
3138 int idx_remote_as = 5;
3139 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3140 SAFI_UNICAST, 1, NULL,
3141 argv[idx_remote_as]->arg);
b3a39dc5
DD
3142}
3143
718e3744 3144DEFUN (neighbor_peer_group,
3145 neighbor_peer_group_cmd,
3146 "neighbor WORD peer-group",
3147 NEIGHBOR_STR
a80beece 3148 "Interface name or neighbor tag\n"
718e3744 3149 "Configure peer-group\n")
3150{
d62a17ae 3151 VTY_DECLVAR_CONTEXT(bgp, bgp);
3152 int idx_word = 1;
3153 struct peer *peer;
3154 struct peer_group *group;
718e3744 3155
d62a17ae 3156 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3157 if (peer) {
3158 vty_out(vty, "%% Name conflict with interface: \n");
3159 return CMD_WARNING_CONFIG_FAILED;
3160 }
718e3744 3161
d62a17ae 3162 group = peer_group_get(bgp, argv[idx_word]->arg);
3163 if (!group) {
3164 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3165 return CMD_WARNING_CONFIG_FAILED;
3166 }
718e3744 3167
d62a17ae 3168 return CMD_SUCCESS;
718e3744 3169}
3170
3171DEFUN (no_neighbor,
3172 no_neighbor_cmd,
dab8cd00 3173 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3174 NO_STR
3175 NEIGHBOR_STR
3a2d747c
QY
3176 NEIGHBOR_ADDR_STR2
3177 "Specify a BGP neighbor\n"
3178 AS_STR
3179 "Internal BGP peer\n"
3180 "External BGP peer\n")
718e3744 3181{
d62a17ae 3182 VTY_DECLVAR_CONTEXT(bgp, bgp);
3183 int idx_peer = 2;
3184 int ret;
3185 union sockunion su;
3186 struct peer_group *group;
3187 struct peer *peer;
3188 struct peer *other;
3189
3190 ret = str2sockunion(argv[idx_peer]->arg, &su);
3191 if (ret < 0) {
3192 /* look up for neighbor by interface name config. */
3193 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3194 if (peer) {
3195 /* Request zebra to terminate IPv6 RAs on this
3196 * interface. */
3197 if (peer->ifp)
3198 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 3199 peer_notify_unconfig(peer);
d62a17ae 3200 peer_delete(peer);
3201 return CMD_SUCCESS;
3202 }
f14e6fdb 3203
d62a17ae 3204 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4e2786df
DA
3205 if (group) {
3206 peer_group_notify_unconfig(group);
d62a17ae 3207 peer_group_delete(group);
4e2786df 3208 } else {
d62a17ae 3209 vty_out(vty, "%% Create the peer-group first\n");
3210 return CMD_WARNING_CONFIG_FAILED;
3211 }
3212 } else {
3213 peer = peer_lookup(bgp, &su);
3214 if (peer) {
3215 if (peer_dynamic_neighbor(peer)) {
3216 vty_out(vty,
3217 "%% Operation not allowed on a dynamic neighbor\n");
3218 return CMD_WARNING_CONFIG_FAILED;
3219 }
3220
3221 other = peer->doppelganger;
4e2786df 3222 peer_notify_unconfig(peer);
d62a17ae 3223 peer_delete(peer);
4e2786df
DA
3224 if (other && other->status != Deleted) {
3225 peer_notify_unconfig(other);
d62a17ae 3226 peer_delete(other);
4e2786df 3227 }
d62a17ae 3228 }
1ff9a340 3229 }
718e3744 3230
d62a17ae 3231 return CMD_SUCCESS;
718e3744 3232}
3233
a80beece
DS
3234DEFUN (no_neighbor_interface_config,
3235 no_neighbor_interface_config_cmd,
d7b9898c 3236 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3237 NO_STR
3238 NEIGHBOR_STR
3239 "Interface name\n"
31500417
DW
3240 "Configure BGP on interface\n"
3241 "Enable BGP with v6 link-local only\n"
3242 "Member of the peer-group\n"
16cedbb0 3243 "Peer-group name\n"
3a2d747c
QY
3244 "Specify a BGP neighbor\n"
3245 AS_STR
3246 "Internal BGP peer\n"
3247 "External BGP peer\n")
a80beece 3248{
d62a17ae 3249 VTY_DECLVAR_CONTEXT(bgp, bgp);
3250 int idx_word = 2;
3251 struct peer *peer;
3252
3253 /* look up for neighbor by interface name config. */
3254 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3255 if (peer) {
3256 /* Request zebra to terminate IPv6 RAs on this interface. */
3257 if (peer->ifp)
3258 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 3259 peer_notify_unconfig(peer);
d62a17ae 3260 peer_delete(peer);
3261 } else {
3262 vty_out(vty, "%% Create the bgp interface first\n");
3263 return CMD_WARNING_CONFIG_FAILED;
3264 }
3265 return CMD_SUCCESS;
a80beece
DS
3266}
3267
718e3744 3268DEFUN (no_neighbor_peer_group,
3269 no_neighbor_peer_group_cmd,
3270 "no neighbor WORD peer-group",
3271 NO_STR
3272 NEIGHBOR_STR
3273 "Neighbor tag\n"
3274 "Configure peer-group\n")
3275{
d62a17ae 3276 VTY_DECLVAR_CONTEXT(bgp, bgp);
3277 int idx_word = 2;
3278 struct peer_group *group;
718e3744 3279
d62a17ae 3280 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4e2786df
DA
3281 if (group) {
3282 peer_group_notify_unconfig(group);
d62a17ae 3283 peer_group_delete(group);
4e2786df 3284 } else {
d62a17ae 3285 vty_out(vty, "%% Create the peer-group first\n");
3286 return CMD_WARNING_CONFIG_FAILED;
3287 }
3288 return CMD_SUCCESS;
718e3744 3289}
3290
a80beece
DS
3291DEFUN (no_neighbor_interface_peer_group_remote_as,
3292 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3293 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3294 NO_STR
3295 NEIGHBOR_STR
a80beece 3296 "Interface name or neighbor tag\n"
718e3744 3297 "Specify a BGP neighbor\n"
3a2d747c
QY
3298 AS_STR
3299 "Internal BGP peer\n"
3300 "External BGP peer\n")
718e3744 3301{
d62a17ae 3302 VTY_DECLVAR_CONTEXT(bgp, bgp);
3303 int idx_word = 2;
3304 struct peer_group *group;
3305 struct peer *peer;
3306
3307 /* look up for neighbor by interface name config. */
3308 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3309 if (peer) {
390485fd 3310 peer_as_change(peer, 0, AS_UNSPECIFIED);
d62a17ae 3311 return CMD_SUCCESS;
3312 }
3313
3314 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3315 if (group)
3316 peer_group_remote_as_delete(group);
3317 else {
3318 vty_out(vty, "%% Create the peer-group or interface first\n");
3319 return CMD_WARNING_CONFIG_FAILED;
3320 }
3321 return CMD_SUCCESS;
718e3744 3322}
6b0655a2 3323
718e3744 3324DEFUN (neighbor_local_as,
3325 neighbor_local_as_cmd,
9ccf14f7 3326 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3327 NEIGHBOR_STR
3328 NEIGHBOR_ADDR_STR2
3329 "Specify a local-as number\n"
3330 "AS number used as local AS\n")
3331{
d62a17ae 3332 int idx_peer = 1;
3333 int idx_number = 3;
3334 struct peer *peer;
3335 int ret;
3336 as_t as;
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 as = strtoul(argv[idx_number]->arg, NULL, 10);
3343 ret = peer_local_as_set(peer, as, 0, 0);
3344 return bgp_vty_return(vty, ret);
718e3744 3345}
3346
3347DEFUN (neighbor_local_as_no_prepend,
3348 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3349 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3350 NEIGHBOR_STR
3351 NEIGHBOR_ADDR_STR2
3352 "Specify a local-as number\n"
3353 "AS number used as local AS\n"
3354 "Do not prepend local-as to updates from ebgp peers\n")
3355{
d62a17ae 3356 int idx_peer = 1;
3357 int idx_number = 3;
3358 struct peer *peer;
3359 int ret;
3360 as_t as;
718e3744 3361
d62a17ae 3362 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3363 if (!peer)
3364 return CMD_WARNING_CONFIG_FAILED;
718e3744 3365
d62a17ae 3366 as = strtoul(argv[idx_number]->arg, NULL, 10);
3367 ret = peer_local_as_set(peer, as, 1, 0);
3368 return bgp_vty_return(vty, ret);
718e3744 3369}
3370
9d3f9705
AC
3371DEFUN (neighbor_local_as_no_prepend_replace_as,
3372 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3373 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3374 NEIGHBOR_STR
3375 NEIGHBOR_ADDR_STR2
3376 "Specify a local-as number\n"
3377 "AS number used as local AS\n"
3378 "Do not prepend local-as to updates from ebgp peers\n"
3379 "Do not prepend local-as to updates from ibgp peers\n")
3380{
d62a17ae 3381 int idx_peer = 1;
3382 int idx_number = 3;
3383 struct peer *peer;
3384 int ret;
3385 as_t as;
9d3f9705 3386
d62a17ae 3387 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3388 if (!peer)
3389 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3390
d62a17ae 3391 as = strtoul(argv[idx_number]->arg, NULL, 10);
3392 ret = peer_local_as_set(peer, as, 1, 1);
3393 return bgp_vty_return(vty, ret);
9d3f9705
AC
3394}
3395
718e3744 3396DEFUN (no_neighbor_local_as,
3397 no_neighbor_local_as_cmd,
a636c635 3398 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3399 NO_STR
3400 NEIGHBOR_STR
3401 NEIGHBOR_ADDR_STR2
a636c635
DW
3402 "Specify a local-as number\n"
3403 "AS number used as local AS\n"
3404 "Do not prepend local-as to updates from ebgp peers\n"
3405 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3406{
d62a17ae 3407 int idx_peer = 2;
3408 struct peer *peer;
3409 int ret;
718e3744 3410
d62a17ae 3411 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3412 if (!peer)
3413 return CMD_WARNING_CONFIG_FAILED;
718e3744 3414
d62a17ae 3415 ret = peer_local_as_unset(peer);
3416 return bgp_vty_return(vty, ret);
718e3744 3417}
3418
718e3744 3419
3f9c7369
DS
3420DEFUN (neighbor_solo,
3421 neighbor_solo_cmd,
9ccf14f7 3422 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3423 NEIGHBOR_STR
3424 NEIGHBOR_ADDR_STR2
3425 "Solo peer - part of its own update group\n")
3426{
d62a17ae 3427 int idx_peer = 1;
3428 struct peer *peer;
3429 int ret;
3f9c7369 3430
d62a17ae 3431 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3432 if (!peer)
3433 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3434
d62a17ae 3435 ret = update_group_adjust_soloness(peer, 1);
3436 return bgp_vty_return(vty, ret);
3f9c7369
DS
3437}
3438
3439DEFUN (no_neighbor_solo,
3440 no_neighbor_solo_cmd,
9ccf14f7 3441 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3442 NO_STR
3443 NEIGHBOR_STR
3444 NEIGHBOR_ADDR_STR2
3445 "Solo peer - part of its own update group\n")
3446{
d62a17ae 3447 int idx_peer = 2;
3448 struct peer *peer;
3449 int ret;
3f9c7369 3450
d62a17ae 3451 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3452 if (!peer)
3453 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3454
d62a17ae 3455 ret = update_group_adjust_soloness(peer, 0);
3456 return bgp_vty_return(vty, ret);
3f9c7369
DS
3457}
3458
0df7c91f
PJ
3459DEFUN (neighbor_password,
3460 neighbor_password_cmd,
9ccf14f7 3461 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3462 NEIGHBOR_STR
3463 NEIGHBOR_ADDR_STR2
3464 "Set a password\n"
3465 "The password\n")
3466{
d62a17ae 3467 int idx_peer = 1;
3468 int idx_line = 3;
3469 struct peer *peer;
3470 int ret;
0df7c91f 3471
d62a17ae 3472 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3473 if (!peer)
3474 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3475
d62a17ae 3476 ret = peer_password_set(peer, argv[idx_line]->arg);
3477 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3478}
3479
3480DEFUN (no_neighbor_password,
3481 no_neighbor_password_cmd,
a636c635 3482 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3483 NO_STR
3484 NEIGHBOR_STR
3485 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3486 "Set a password\n"
3487 "The password\n")
0df7c91f 3488{
d62a17ae 3489 int idx_peer = 2;
3490 struct peer *peer;
3491 int ret;
0df7c91f 3492
d62a17ae 3493 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3494 if (!peer)
3495 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3496
d62a17ae 3497 ret = peer_password_unset(peer);
3498 return bgp_vty_return(vty, ret);
0df7c91f 3499}
6b0655a2 3500
718e3744 3501DEFUN (neighbor_activate,
3502 neighbor_activate_cmd,
9ccf14f7 3503 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3504 NEIGHBOR_STR
3505 NEIGHBOR_ADDR_STR2
3506 "Enable the Address Family for this Neighbor\n")
3507{
d62a17ae 3508 int idx_peer = 1;
3509 int ret;
3510 struct peer *peer;
718e3744 3511
d62a17ae 3512 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3513 if (!peer)
3514 return CMD_WARNING_CONFIG_FAILED;
718e3744 3515
d62a17ae 3516 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3517 return bgp_vty_return(vty, ret);
718e3744 3518}
3519
d62a17ae 3520ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3521 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3522 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3523 "Enable the Address Family for this Neighbor\n")
596c17ba 3524
718e3744 3525DEFUN (no_neighbor_activate,
3526 no_neighbor_activate_cmd,
9ccf14f7 3527 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3528 NO_STR
3529 NEIGHBOR_STR
3530 NEIGHBOR_ADDR_STR2
3531 "Enable the Address Family for this Neighbor\n")
3532{
d62a17ae 3533 int idx_peer = 2;
3534 int ret;
3535 struct peer *peer;
718e3744 3536
d62a17ae 3537 /* Lookup peer. */
3538 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3539 if (!peer)
3540 return CMD_WARNING_CONFIG_FAILED;
718e3744 3541
d62a17ae 3542 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3543 return bgp_vty_return(vty, ret);
718e3744 3544}
6b0655a2 3545
d62a17ae 3546ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3547 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3548 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3549 "Enable the Address Family for this Neighbor\n")
596c17ba 3550
718e3744 3551DEFUN (neighbor_set_peer_group,
3552 neighbor_set_peer_group_cmd,
d7b9898c 3553 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 3554 NEIGHBOR_STR
a80beece 3555 NEIGHBOR_ADDR_STR2
718e3744 3556 "Member of the peer-group\n"
16cedbb0 3557 "Peer-group name\n")
718e3744 3558{
d62a17ae 3559 VTY_DECLVAR_CONTEXT(bgp, bgp);
3560 int idx_peer = 1;
3561 int idx_word = 3;
3562 int ret;
3563 as_t as;
3564 union sockunion su;
3565 struct peer *peer;
3566 struct peer_group *group;
3567
d62a17ae 3568 ret = str2sockunion(argv[idx_peer]->arg, &su);
3569 if (ret < 0) {
3570 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3571 if (!peer) {
3572 vty_out(vty, "%% Malformed address or name: %s\n",
3573 argv[idx_peer]->arg);
3574 return CMD_WARNING_CONFIG_FAILED;
3575 }
3576 } else {
3577 if (peer_address_self_check(bgp, &su)) {
3578 vty_out(vty,
3579 "%% Can not configure the local system as neighbor\n");
3580 return CMD_WARNING_CONFIG_FAILED;
3581 }
3582
3583 /* Disallow for dynamic neighbor. */
3584 peer = peer_lookup(bgp, &su);
3585 if (peer && peer_dynamic_neighbor(peer)) {
3586 vty_out(vty,
3587 "%% Operation not allowed on a dynamic neighbor\n");
3588 return CMD_WARNING_CONFIG_FAILED;
3589 }
3590 }
3591
3592 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3593 if (!group) {
3594 vty_out(vty, "%% Configure the peer-group first\n");
3595 return CMD_WARNING_CONFIG_FAILED;
3596 }
3597
3598 ret = peer_group_bind(bgp, &su, peer, group, &as);
3599
3600 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3601 vty_out(vty,
3602 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3603 as);
3604 return CMD_WARNING_CONFIG_FAILED;
3605 }
3606
3607 return bgp_vty_return(vty, ret);
3608}
3609
3610ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 3611 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 3612 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3613 "Member of the peer-group\n"
3614 "Peer-group name\n")
596c17ba 3615
718e3744 3616DEFUN (no_neighbor_set_peer_group,
3617 no_neighbor_set_peer_group_cmd,
d7b9898c 3618 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 3619 NO_STR
3620 NEIGHBOR_STR
a80beece 3621 NEIGHBOR_ADDR_STR2
718e3744 3622 "Member of the peer-group\n"
16cedbb0 3623 "Peer-group name\n")
718e3744 3624{
d62a17ae 3625 VTY_DECLVAR_CONTEXT(bgp, bgp);
3626 int idx_peer = 2;
3627 int idx_word = 4;
3628 int ret;
3629 struct peer *peer;
3630 struct peer_group *group;
3631
3632 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3633 if (!peer)
3634 return CMD_WARNING_CONFIG_FAILED;
3635
3636 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3637 if (!group) {
3638 vty_out(vty, "%% Configure the peer-group first\n");
3639 return CMD_WARNING_CONFIG_FAILED;
3640 }
718e3744 3641
4e2786df 3642 peer_notify_unconfig(peer);
827ed707 3643 ret = peer_delete(peer);
718e3744 3644
d62a17ae 3645 return bgp_vty_return(vty, ret);
718e3744 3646}
6b0655a2 3647
d62a17ae 3648ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 3649 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 3650 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3651 "Member of the peer-group\n"
3652 "Peer-group name\n")
596c17ba 3653
d62a17ae 3654static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3655 uint32_t flag, int set)
718e3744 3656{
d62a17ae 3657 int ret;
3658 struct peer *peer;
718e3744 3659
d62a17ae 3660 peer = peer_and_group_lookup_vty(vty, ip_str);
3661 if (!peer)
3662 return CMD_WARNING_CONFIG_FAILED;
718e3744 3663
7ebe625c
QY
3664 /*
3665 * If 'neighbor <interface>', then this is for directly connected peers,
3666 * we should not accept disable-connected-check.
3667 */
3668 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3669 vty_out(vty,
3670 "%s is directly connected peer, cannot accept disable-"
3671 "connected-check\n",
3672 ip_str);
3673 return CMD_WARNING_CONFIG_FAILED;
3674 }
3675
d62a17ae 3676 if (!set && flag == PEER_FLAG_SHUTDOWN)
3677 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3678
d62a17ae 3679 if (set)
3680 ret = peer_flag_set(peer, flag);
3681 else
3682 ret = peer_flag_unset(peer, flag);
718e3744 3683
d62a17ae 3684 return bgp_vty_return(vty, ret);
718e3744 3685}
3686
47cbc09b 3687static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3688{
d62a17ae 3689 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3690}
3691
d62a17ae 3692static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3693 uint32_t flag)
718e3744 3694{
d62a17ae 3695 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3696}
3697
3698/* neighbor passive. */
3699DEFUN (neighbor_passive,
3700 neighbor_passive_cmd,
9ccf14f7 3701 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3702 NEIGHBOR_STR
3703 NEIGHBOR_ADDR_STR2
3704 "Don't send open messages to this neighbor\n")
3705{
d62a17ae 3706 int idx_peer = 1;
3707 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3708}
3709
3710DEFUN (no_neighbor_passive,
3711 no_neighbor_passive_cmd,
9ccf14f7 3712 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3713 NO_STR
3714 NEIGHBOR_STR
3715 NEIGHBOR_ADDR_STR2
3716 "Don't send open messages to this neighbor\n")
3717{
d62a17ae 3718 int idx_peer = 2;
3719 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3720}
6b0655a2 3721
718e3744 3722/* neighbor shutdown. */
73d70fa6
DL
3723DEFUN (neighbor_shutdown_msg,
3724 neighbor_shutdown_msg_cmd,
3725 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3726 NEIGHBOR_STR
3727 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3728 "Administratively shut down this neighbor\n"
3729 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3730 "Shutdown message\n")
718e3744 3731{
d62a17ae 3732 int idx_peer = 1;
73d70fa6 3733
d62a17ae 3734 if (argc >= 5) {
3735 struct peer *peer =
3736 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3737 char *message;
73d70fa6 3738
d62a17ae 3739 if (!peer)
3740 return CMD_WARNING_CONFIG_FAILED;
3741 message = argv_concat(argv, argc, 4);
3742 peer_tx_shutdown_message_set(peer, message);
3743 XFREE(MTYPE_TMP, message);
3744 }
73d70fa6 3745
d62a17ae 3746 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3747}
3748
d62a17ae 3749ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3750 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3751 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3752 "Administratively shut down this neighbor\n")
73d70fa6
DL
3753
3754DEFUN (no_neighbor_shutdown_msg,
3755 no_neighbor_shutdown_msg_cmd,
3756 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3757 NO_STR
3758 NEIGHBOR_STR
3759 NEIGHBOR_ADDR_STR2
3760 "Administratively shut down this neighbor\n"
3761 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3762 "Shutdown message\n")
718e3744 3763{
d62a17ae 3764 int idx_peer = 2;
73d70fa6 3765
d62a17ae 3766 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3767 PEER_FLAG_SHUTDOWN);
718e3744 3768}
6b0655a2 3769
d62a17ae 3770ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3771 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3772 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3773 "Administratively shut down this neighbor\n")
73d70fa6 3774
718e3744 3775/* neighbor capability dynamic. */
3776DEFUN (neighbor_capability_dynamic,
3777 neighbor_capability_dynamic_cmd,
9ccf14f7 3778 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3779 NEIGHBOR_STR
3780 NEIGHBOR_ADDR_STR2
3781 "Advertise capability to the peer\n"
3782 "Advertise dynamic capability to this neighbor\n")
3783{
d62a17ae 3784 int idx_peer = 1;
3785 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3786 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3787}
3788
3789DEFUN (no_neighbor_capability_dynamic,
3790 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3791 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3792 NO_STR
3793 NEIGHBOR_STR
3794 NEIGHBOR_ADDR_STR2
3795 "Advertise capability to the peer\n"
3796 "Advertise dynamic capability to this neighbor\n")
3797{
d62a17ae 3798 int idx_peer = 2;
3799 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3800 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3801}
6b0655a2 3802
718e3744 3803/* neighbor dont-capability-negotiate */
3804DEFUN (neighbor_dont_capability_negotiate,
3805 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3806 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3807 NEIGHBOR_STR
3808 NEIGHBOR_ADDR_STR2
3809 "Do not perform capability negotiation\n")
3810{
d62a17ae 3811 int idx_peer = 1;
3812 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3813 PEER_FLAG_DONT_CAPABILITY);
718e3744 3814}
3815
3816DEFUN (no_neighbor_dont_capability_negotiate,
3817 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3818 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3819 NO_STR
3820 NEIGHBOR_STR
3821 NEIGHBOR_ADDR_STR2
3822 "Do not perform capability negotiation\n")
3823{
d62a17ae 3824 int idx_peer = 2;
3825 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3826 PEER_FLAG_DONT_CAPABILITY);
718e3744 3827}
6b0655a2 3828
8a92a8a0
DS
3829/* neighbor capability extended next hop encoding */
3830DEFUN (neighbor_capability_enhe,
3831 neighbor_capability_enhe_cmd,
9ccf14f7 3832 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3833 NEIGHBOR_STR
3834 NEIGHBOR_ADDR_STR2
3835 "Advertise capability to the peer\n"
3836 "Advertise extended next-hop capability to the peer\n")
3837{
d62a17ae 3838 int idx_peer = 1;
3839 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3840 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3841}
3842
3843DEFUN (no_neighbor_capability_enhe,
3844 no_neighbor_capability_enhe_cmd,
9ccf14f7 3845 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3846 NO_STR
3847 NEIGHBOR_STR
3848 NEIGHBOR_ADDR_STR2
3849 "Advertise capability to the peer\n"
3850 "Advertise extended next-hop capability to the peer\n")
3851{
d62a17ae 3852 int idx_peer = 2;
3853 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3854 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3855}
3856
d62a17ae 3857static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3858 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3859 int set)
718e3744 3860{
d62a17ae 3861 int ret;
3862 struct peer *peer;
718e3744 3863
d62a17ae 3864 peer = peer_and_group_lookup_vty(vty, peer_str);
3865 if (!peer)
3866 return CMD_WARNING_CONFIG_FAILED;
718e3744 3867
d62a17ae 3868 if (set)
3869 ret = peer_af_flag_set(peer, afi, safi, flag);
3870 else
3871 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3872
d62a17ae 3873 return bgp_vty_return(vty, ret);
718e3744 3874}
3875
d62a17ae 3876static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3877 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3878{
d62a17ae 3879 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3880}
3881
d62a17ae 3882static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3883 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3884{
d62a17ae 3885 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3886}
6b0655a2 3887
718e3744 3888/* neighbor capability orf prefix-list. */
3889DEFUN (neighbor_capability_orf_prefix,
3890 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3891 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3892 NEIGHBOR_STR
3893 NEIGHBOR_ADDR_STR2
3894 "Advertise capability to the peer\n"
3895 "Advertise ORF capability to the peer\n"
3896 "Advertise prefixlist ORF capability to this neighbor\n"
3897 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3898 "Capability to RECEIVE the ORF from this neighbor\n"
3899 "Capability to SEND the ORF to this neighbor\n")
3900{
d62a17ae 3901 int idx_peer = 1;
3902 int idx_send_recv = 5;
d7c0a89a 3903 uint16_t flag = 0;
d62a17ae 3904
3905 if (strmatch(argv[idx_send_recv]->text, "send"))
3906 flag = PEER_FLAG_ORF_PREFIX_SM;
3907 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3908 flag = PEER_FLAG_ORF_PREFIX_RM;
3909 else if (strmatch(argv[idx_send_recv]->text, "both"))
3910 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3911 else {
3912 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3913 return CMD_WARNING_CONFIG_FAILED;
3914 }
3915
3916 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3917 bgp_node_safi(vty), flag);
3918}
3919
3920ALIAS_HIDDEN(
3921 neighbor_capability_orf_prefix,
3922 neighbor_capability_orf_prefix_hidden_cmd,
3923 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3924 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3925 "Advertise capability to the peer\n"
3926 "Advertise ORF capability to the peer\n"
3927 "Advertise prefixlist ORF capability to this neighbor\n"
3928 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3929 "Capability to RECEIVE the ORF from this neighbor\n"
3930 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3931
718e3744 3932DEFUN (no_neighbor_capability_orf_prefix,
3933 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3934 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3935 NO_STR
3936 NEIGHBOR_STR
3937 NEIGHBOR_ADDR_STR2
3938 "Advertise capability to the peer\n"
3939 "Advertise ORF capability to the peer\n"
3940 "Advertise prefixlist ORF capability to this neighbor\n"
3941 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3942 "Capability to RECEIVE the ORF from this neighbor\n"
3943 "Capability to SEND the ORF to this neighbor\n")
3944{
d62a17ae 3945 int idx_peer = 2;
3946 int idx_send_recv = 6;
d7c0a89a 3947 uint16_t flag = 0;
d62a17ae 3948
3949 if (strmatch(argv[idx_send_recv]->text, "send"))
3950 flag = PEER_FLAG_ORF_PREFIX_SM;
3951 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3952 flag = PEER_FLAG_ORF_PREFIX_RM;
3953 else if (strmatch(argv[idx_send_recv]->text, "both"))
3954 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3955 else {
3956 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3957 return CMD_WARNING_CONFIG_FAILED;
3958 }
3959
3960 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3961 bgp_node_afi(vty), bgp_node_safi(vty),
3962 flag);
3963}
3964
3965ALIAS_HIDDEN(
3966 no_neighbor_capability_orf_prefix,
3967 no_neighbor_capability_orf_prefix_hidden_cmd,
3968 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3969 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3970 "Advertise capability to the peer\n"
3971 "Advertise ORF capability to the peer\n"
3972 "Advertise prefixlist ORF capability to this neighbor\n"
3973 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3974 "Capability to RECEIVE the ORF from this neighbor\n"
3975 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3976
718e3744 3977/* neighbor next-hop-self. */
3978DEFUN (neighbor_nexthop_self,
3979 neighbor_nexthop_self_cmd,
9ccf14f7 3980 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3981 NEIGHBOR_STR
3982 NEIGHBOR_ADDR_STR2
a538debe 3983 "Disable the next hop calculation for this neighbor\n")
718e3744 3984{
d62a17ae 3985 int idx_peer = 1;
3986 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3987 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3988}
9e7a53c1 3989
d62a17ae 3990ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3991 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3992 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3993 "Disable the next hop calculation for this neighbor\n")
596c17ba 3994
a538debe
DS
3995/* neighbor next-hop-self. */
3996DEFUN (neighbor_nexthop_self_force,
3997 neighbor_nexthop_self_force_cmd,
9ccf14f7 3998 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3999 NEIGHBOR_STR
4000 NEIGHBOR_ADDR_STR2
4001 "Disable the next hop calculation for this neighbor\n"
4002 "Set the next hop to self for reflected routes\n")
4003{
d62a17ae 4004 int idx_peer = 1;
4005 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4006 bgp_node_safi(vty),
4007 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 4008}
4009
d62a17ae 4010ALIAS_HIDDEN(neighbor_nexthop_self_force,
4011 neighbor_nexthop_self_force_hidden_cmd,
4012 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4013 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4014 "Disable the next hop calculation for this neighbor\n"
4015 "Set the next hop to self for reflected routes\n")
596c17ba 4016
1bc4e531
DA
4017ALIAS_HIDDEN(neighbor_nexthop_self_force,
4018 neighbor_nexthop_self_all_hidden_cmd,
4019 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4020 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4021 "Disable the next hop calculation for this neighbor\n"
4022 "Set the next hop to self for reflected routes\n")
4023
718e3744 4024DEFUN (no_neighbor_nexthop_self,
4025 no_neighbor_nexthop_self_cmd,
9ccf14f7 4026 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 4027 NO_STR
4028 NEIGHBOR_STR
4029 NEIGHBOR_ADDR_STR2
a538debe 4030 "Disable the next hop calculation for this neighbor\n")
718e3744 4031{
d62a17ae 4032 int idx_peer = 2;
4033 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4034 bgp_node_afi(vty), bgp_node_safi(vty),
4035 PEER_FLAG_NEXTHOP_SELF);
718e3744 4036}
6b0655a2 4037
d62a17ae 4038ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
4039 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4040 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4041 "Disable the next hop calculation for this neighbor\n")
596c17ba 4042
88b8ed8d 4043DEFUN (no_neighbor_nexthop_self_force,
a538debe 4044 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 4045 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
4046 NO_STR
4047 NEIGHBOR_STR
4048 NEIGHBOR_ADDR_STR2
4049 "Disable the next hop calculation for this neighbor\n"
4050 "Set the next hop to self for reflected routes\n")
88b8ed8d 4051{
d62a17ae 4052 int idx_peer = 2;
4053 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4054 bgp_node_afi(vty), bgp_node_safi(vty),
4055 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 4056}
a538debe 4057
d62a17ae 4058ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4059 no_neighbor_nexthop_self_force_hidden_cmd,
4060 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4061 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4062 "Disable the next hop calculation for this neighbor\n"
4063 "Set the next hop to self for reflected routes\n")
596c17ba 4064
1bc4e531
DA
4065ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4066 no_neighbor_nexthop_self_all_hidden_cmd,
4067 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4068 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4069 "Disable the next hop calculation for this neighbor\n"
4070 "Set the next hop to self for reflected routes\n")
4071
c7122e14
DS
4072/* neighbor as-override */
4073DEFUN (neighbor_as_override,
4074 neighbor_as_override_cmd,
9ccf14f7 4075 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4076 NEIGHBOR_STR
4077 NEIGHBOR_ADDR_STR2
4078 "Override ASNs in outbound updates if aspath equals remote-as\n")
4079{
d62a17ae 4080 int idx_peer = 1;
4081 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4082 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4083}
4084
d62a17ae 4085ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4086 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4087 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4088 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4089
c7122e14
DS
4090DEFUN (no_neighbor_as_override,
4091 no_neighbor_as_override_cmd,
9ccf14f7 4092 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4093 NO_STR
4094 NEIGHBOR_STR
4095 NEIGHBOR_ADDR_STR2
4096 "Override ASNs in outbound updates if aspath equals remote-as\n")
4097{
d62a17ae 4098 int idx_peer = 2;
4099 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4100 bgp_node_afi(vty), bgp_node_safi(vty),
4101 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4102}
4103
d62a17ae 4104ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4105 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4106 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4107 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4108
718e3744 4109/* neighbor remove-private-AS. */
4110DEFUN (neighbor_remove_private_as,
4111 neighbor_remove_private_as_cmd,
9ccf14f7 4112 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4113 NEIGHBOR_STR
4114 NEIGHBOR_ADDR_STR2
5000f21c 4115 "Remove private ASNs in outbound updates\n")
718e3744 4116{
d62a17ae 4117 int idx_peer = 1;
4118 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4119 bgp_node_safi(vty),
4120 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4121}
4122
d62a17ae 4123ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4124 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4125 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4126 "Remove private ASNs in outbound updates\n")
596c17ba 4127
5000f21c
DS
4128DEFUN (neighbor_remove_private_as_all,
4129 neighbor_remove_private_as_all_cmd,
9ccf14f7 4130 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4131 NEIGHBOR_STR
4132 NEIGHBOR_ADDR_STR2
4133 "Remove private ASNs in outbound updates\n"
efd7904e 4134 "Apply to all AS numbers\n")
5000f21c 4135{
d62a17ae 4136 int idx_peer = 1;
4137 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4138 bgp_node_safi(vty),
4139 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
4140}
4141
d62a17ae 4142ALIAS_HIDDEN(neighbor_remove_private_as_all,
4143 neighbor_remove_private_as_all_hidden_cmd,
4144 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4145 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4146 "Remove private ASNs in outbound updates\n"
4147 "Apply to all AS numbers")
596c17ba 4148
5000f21c
DS
4149DEFUN (neighbor_remove_private_as_replace_as,
4150 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4151 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4152 NEIGHBOR_STR
4153 NEIGHBOR_ADDR_STR2
4154 "Remove private ASNs in outbound updates\n"
4155 "Replace private ASNs with our ASN in outbound updates\n")
4156{
d62a17ae 4157 int idx_peer = 1;
4158 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4159 bgp_node_safi(vty),
4160 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
4161}
4162
d62a17ae 4163ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4164 neighbor_remove_private_as_replace_as_hidden_cmd,
4165 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4166 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4167 "Remove private ASNs in outbound updates\n"
4168 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4169
5000f21c
DS
4170DEFUN (neighbor_remove_private_as_all_replace_as,
4171 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4172 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4173 NEIGHBOR_STR
4174 NEIGHBOR_ADDR_STR2
4175 "Remove private ASNs in outbound updates\n"
16cedbb0 4176 "Apply to all AS numbers\n"
5000f21c
DS
4177 "Replace private ASNs with our ASN in outbound updates\n")
4178{
d62a17ae 4179 int idx_peer = 1;
4180 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4181 bgp_node_safi(vty),
4182 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4183}
4184
d62a17ae 4185ALIAS_HIDDEN(
4186 neighbor_remove_private_as_all_replace_as,
4187 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4188 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4189 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4190 "Remove private ASNs in outbound updates\n"
4191 "Apply to all AS numbers\n"
4192 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4193
718e3744 4194DEFUN (no_neighbor_remove_private_as,
4195 no_neighbor_remove_private_as_cmd,
9ccf14f7 4196 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4197 NO_STR
4198 NEIGHBOR_STR
4199 NEIGHBOR_ADDR_STR2
5000f21c 4200 "Remove private ASNs in outbound updates\n")
718e3744 4201{
d62a17ae 4202 int idx_peer = 2;
4203 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4204 bgp_node_afi(vty), bgp_node_safi(vty),
4205 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4206}
6b0655a2 4207
d62a17ae 4208ALIAS_HIDDEN(no_neighbor_remove_private_as,
4209 no_neighbor_remove_private_as_hidden_cmd,
4210 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4211 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4212 "Remove private ASNs in outbound updates\n")
596c17ba 4213
88b8ed8d 4214DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4215 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4216 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4217 NO_STR
4218 NEIGHBOR_STR
4219 NEIGHBOR_ADDR_STR2
4220 "Remove private ASNs in outbound updates\n"
16cedbb0 4221 "Apply to all AS numbers\n")
88b8ed8d 4222{
d62a17ae 4223 int idx_peer = 2;
4224 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4225 bgp_node_afi(vty), bgp_node_safi(vty),
4226 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4227}
5000f21c 4228
d62a17ae 4229ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4230 no_neighbor_remove_private_as_all_hidden_cmd,
4231 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4232 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4233 "Remove private ASNs in outbound updates\n"
4234 "Apply to all AS numbers\n")
596c17ba 4235
88b8ed8d 4236DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4237 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4238 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4239 NO_STR
4240 NEIGHBOR_STR
4241 NEIGHBOR_ADDR_STR2
4242 "Remove private ASNs in outbound updates\n"
4243 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4244{
d62a17ae 4245 int idx_peer = 2;
4246 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4247 bgp_node_afi(vty), bgp_node_safi(vty),
4248 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4249}
5000f21c 4250
d62a17ae 4251ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4252 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4253 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4254 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4255 "Remove private ASNs in outbound updates\n"
4256 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4257
88b8ed8d 4258DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4259 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4260 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4261 NO_STR
4262 NEIGHBOR_STR
4263 NEIGHBOR_ADDR_STR2
4264 "Remove private ASNs in outbound updates\n"
16cedbb0 4265 "Apply to all AS numbers\n"
5000f21c 4266 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4267{
d62a17ae 4268 int idx_peer = 2;
4269 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4270 bgp_node_afi(vty), bgp_node_safi(vty),
4271 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4272}
5000f21c 4273
d62a17ae 4274ALIAS_HIDDEN(
4275 no_neighbor_remove_private_as_all_replace_as,
4276 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4277 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4278 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4279 "Remove private ASNs in outbound updates\n"
4280 "Apply to all AS numbers\n"
4281 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4282
5000f21c 4283
718e3744 4284/* neighbor send-community. */
4285DEFUN (neighbor_send_community,
4286 neighbor_send_community_cmd,
9ccf14f7 4287 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4288 NEIGHBOR_STR
4289 NEIGHBOR_ADDR_STR2
4290 "Send Community attribute to this neighbor\n")
4291{
d62a17ae 4292 int idx_peer = 1;
27c05d4d 4293
d62a17ae 4294 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4295 bgp_node_safi(vty),
4296 PEER_FLAG_SEND_COMMUNITY);
718e3744 4297}
4298
d62a17ae 4299ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4300 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4301 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4302 "Send Community attribute to this neighbor\n")
596c17ba 4303
718e3744 4304DEFUN (no_neighbor_send_community,
4305 no_neighbor_send_community_cmd,
9ccf14f7 4306 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4307 NO_STR
4308 NEIGHBOR_STR
4309 NEIGHBOR_ADDR_STR2
4310 "Send Community attribute to this neighbor\n")
4311{
d62a17ae 4312 int idx_peer = 2;
27c05d4d 4313
d62a17ae 4314 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4315 bgp_node_afi(vty), bgp_node_safi(vty),
4316 PEER_FLAG_SEND_COMMUNITY);
718e3744 4317}
6b0655a2 4318
d62a17ae 4319ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4320 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4321 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4322 "Send Community attribute to this neighbor\n")
596c17ba 4323
718e3744 4324/* neighbor send-community extended. */
4325DEFUN (neighbor_send_community_type,
4326 neighbor_send_community_type_cmd,
57d187bc 4327 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4328 NEIGHBOR_STR
4329 NEIGHBOR_ADDR_STR2
4330 "Send Community attribute to this neighbor\n"
4331 "Send Standard and Extended Community attributes\n"
57d187bc 4332 "Send Standard, Large and Extended Community attributes\n"
718e3744 4333 "Send Extended Community attributes\n"
57d187bc
JS
4334 "Send Standard Community attributes\n"
4335 "Send Large Community attributes\n")
718e3744 4336{
27c05d4d 4337 int idx_peer = 1;
d7c0a89a 4338 uint32_t flag = 0;
27c05d4d 4339 const char *type = argv[argc - 1]->text;
d62a17ae 4340
27c05d4d 4341 if (strmatch(type, "standard")) {
d62a17ae 4342 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4343 } else if (strmatch(type, "extended")) {
d62a17ae 4344 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4345 } else if (strmatch(type, "large")) {
d62a17ae 4346 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4347 } else if (strmatch(type, "both")) {
d62a17ae 4348 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4349 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4350 } else { /* if (strmatch(type, "all")) */
d62a17ae 4351 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4352 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4353 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4354 }
4355
27c05d4d 4356 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4357 bgp_node_safi(vty), flag);
4358}
4359
4360ALIAS_HIDDEN(
4361 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4362 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4363 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4364 "Send Community attribute to this neighbor\n"
4365 "Send Standard and Extended Community attributes\n"
4366 "Send Standard, Large and Extended Community attributes\n"
4367 "Send Extended Community attributes\n"
4368 "Send Standard Community attributes\n"
4369 "Send Large Community attributes\n")
596c17ba 4370
718e3744 4371DEFUN (no_neighbor_send_community_type,
4372 no_neighbor_send_community_type_cmd,
57d187bc 4373 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4374 NO_STR
4375 NEIGHBOR_STR
4376 NEIGHBOR_ADDR_STR2
4377 "Send Community attribute to this neighbor\n"
4378 "Send Standard and Extended Community attributes\n"
57d187bc 4379 "Send Standard, Large and Extended Community attributes\n"
718e3744 4380 "Send Extended Community attributes\n"
57d187bc
JS
4381 "Send Standard Community attributes\n"
4382 "Send Large Community attributes\n")
718e3744 4383{
d62a17ae 4384 int idx_peer = 2;
27c05d4d 4385 uint32_t flag = 0;
d62a17ae 4386 const char *type = argv[argc - 1]->text;
4387
27c05d4d
PM
4388 if (strmatch(type, "standard")) {
4389 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4390 } else if (strmatch(type, "extended")) {
4391 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4392 } else if (strmatch(type, "large")) {
4393 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4394 } else if (strmatch(type, "both")) {
4395 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4396 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4397 } else { /* if (strmatch(type, "all")) */
4398 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4399 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4400 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4401 }
4402
4403 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4404 bgp_node_afi(vty), bgp_node_safi(vty),
4405 flag);
d62a17ae 4406}
4407
4408ALIAS_HIDDEN(
4409 no_neighbor_send_community_type,
4410 no_neighbor_send_community_type_hidden_cmd,
4411 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4412 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4413 "Send Community attribute to this neighbor\n"
4414 "Send Standard and Extended Community attributes\n"
4415 "Send Standard, Large and Extended Community attributes\n"
4416 "Send Extended Community attributes\n"
4417 "Send Standard Community attributes\n"
4418 "Send Large Community attributes\n")
596c17ba 4419
718e3744 4420/* neighbor soft-reconfig. */
4421DEFUN (neighbor_soft_reconfiguration,
4422 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4423 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4424 NEIGHBOR_STR
4425 NEIGHBOR_ADDR_STR2
4426 "Per neighbor soft reconfiguration\n"
4427 "Allow inbound soft reconfiguration for this neighbor\n")
4428{
d62a17ae 4429 int idx_peer = 1;
4430 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4431 bgp_node_safi(vty),
4432 PEER_FLAG_SOFT_RECONFIG);
718e3744 4433}
4434
d62a17ae 4435ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4436 neighbor_soft_reconfiguration_hidden_cmd,
4437 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4438 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4439 "Per neighbor soft reconfiguration\n"
4440 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4441
718e3744 4442DEFUN (no_neighbor_soft_reconfiguration,
4443 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4444 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4445 NO_STR
4446 NEIGHBOR_STR
4447 NEIGHBOR_ADDR_STR2
4448 "Per neighbor soft reconfiguration\n"
4449 "Allow inbound soft reconfiguration for this neighbor\n")
4450{
d62a17ae 4451 int idx_peer = 2;
4452 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4453 bgp_node_afi(vty), bgp_node_safi(vty),
4454 PEER_FLAG_SOFT_RECONFIG);
718e3744 4455}
6b0655a2 4456
d62a17ae 4457ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4458 no_neighbor_soft_reconfiguration_hidden_cmd,
4459 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4460 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4461 "Per neighbor soft reconfiguration\n"
4462 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4463
718e3744 4464DEFUN (neighbor_route_reflector_client,
4465 neighbor_route_reflector_client_cmd,
9ccf14f7 4466 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4467 NEIGHBOR_STR
4468 NEIGHBOR_ADDR_STR2
4469 "Configure a neighbor as Route Reflector client\n")
4470{
d62a17ae 4471 int idx_peer = 1;
4472 struct peer *peer;
718e3744 4473
4474
d62a17ae 4475 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4476 if (!peer)
4477 return CMD_WARNING_CONFIG_FAILED;
718e3744 4478
d62a17ae 4479 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4480 bgp_node_safi(vty),
4481 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4482}
4483
d62a17ae 4484ALIAS_HIDDEN(neighbor_route_reflector_client,
4485 neighbor_route_reflector_client_hidden_cmd,
4486 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4487 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4488 "Configure a neighbor as Route Reflector client\n")
596c17ba 4489
718e3744 4490DEFUN (no_neighbor_route_reflector_client,
4491 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4492 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4493 NO_STR
4494 NEIGHBOR_STR
4495 NEIGHBOR_ADDR_STR2
4496 "Configure a neighbor as Route Reflector client\n")
4497{
d62a17ae 4498 int idx_peer = 2;
4499 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4500 bgp_node_afi(vty), bgp_node_safi(vty),
4501 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4502}
6b0655a2 4503
d62a17ae 4504ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4505 no_neighbor_route_reflector_client_hidden_cmd,
4506 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4507 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4508 "Configure a neighbor as Route Reflector client\n")
596c17ba 4509
718e3744 4510/* neighbor route-server-client. */
4511DEFUN (neighbor_route_server_client,
4512 neighbor_route_server_client_cmd,
9ccf14f7 4513 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4514 NEIGHBOR_STR
4515 NEIGHBOR_ADDR_STR2
4516 "Configure a neighbor as Route Server client\n")
4517{
d62a17ae 4518 int idx_peer = 1;
4519 struct peer *peer;
2a3d5731 4520
d62a17ae 4521 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4522 if (!peer)
4523 return CMD_WARNING_CONFIG_FAILED;
4524 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4525 bgp_node_safi(vty),
4526 PEER_FLAG_RSERVER_CLIENT);
718e3744 4527}
4528
d62a17ae 4529ALIAS_HIDDEN(neighbor_route_server_client,
4530 neighbor_route_server_client_hidden_cmd,
4531 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4532 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4533 "Configure a neighbor as Route Server client\n")
596c17ba 4534
718e3744 4535DEFUN (no_neighbor_route_server_client,
4536 no_neighbor_route_server_client_cmd,
9ccf14f7 4537 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4538 NO_STR
4539 NEIGHBOR_STR
4540 NEIGHBOR_ADDR_STR2
4541 "Configure a neighbor as Route Server client\n")
fee0f4c6 4542{
d62a17ae 4543 int idx_peer = 2;
4544 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4545 bgp_node_afi(vty), bgp_node_safi(vty),
4546 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4547}
6b0655a2 4548
d62a17ae 4549ALIAS_HIDDEN(no_neighbor_route_server_client,
4550 no_neighbor_route_server_client_hidden_cmd,
4551 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4552 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4553 "Configure a neighbor as Route Server client\n")
596c17ba 4554
fee0f4c6 4555DEFUN (neighbor_nexthop_local_unchanged,
4556 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4557 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4558 NEIGHBOR_STR
4559 NEIGHBOR_ADDR_STR2
4560 "Configure treatment of outgoing link-local nexthop attribute\n"
4561 "Leave link-local nexthop unchanged for this peer\n")
4562{
d62a17ae 4563 int idx_peer = 1;
4564 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4565 bgp_node_safi(vty),
4566 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4567}
6b0655a2 4568
fee0f4c6 4569DEFUN (no_neighbor_nexthop_local_unchanged,
4570 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4571 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4572 NO_STR
4573 NEIGHBOR_STR
4574 NEIGHBOR_ADDR_STR2
4575 "Configure treatment of outgoing link-local-nexthop attribute\n"
4576 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4577{
d62a17ae 4578 int idx_peer = 2;
4579 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4580 bgp_node_afi(vty), bgp_node_safi(vty),
4581 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4582}
6b0655a2 4583
718e3744 4584DEFUN (neighbor_attr_unchanged,
4585 neighbor_attr_unchanged_cmd,
a8206004 4586 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4587 NEIGHBOR_STR
4588 NEIGHBOR_ADDR_STR2
4589 "BGP attribute is propagated unchanged to this neighbor\n"
4590 "As-path attribute\n"
4591 "Nexthop attribute\n"
a8206004 4592 "Med attribute\n")
718e3744 4593{
d62a17ae 4594 int idx = 0;
8eeb0335
DW
4595 char *peer_str = argv[1]->arg;
4596 struct peer *peer;
d7c0a89a 4597 uint16_t flags = 0;
8eeb0335
DW
4598 afi_t afi = bgp_node_afi(vty);
4599 safi_t safi = bgp_node_safi(vty);
4600
4601 peer = peer_and_group_lookup_vty(vty, peer_str);
4602 if (!peer)
4603 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4604
4605 if (argv_find(argv, argc, "as-path", &idx))
4606 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4607 idx = 0;
4608 if (argv_find(argv, argc, "next-hop", &idx))
4609 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4610 idx = 0;
4611 if (argv_find(argv, argc, "med", &idx))
4612 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4613
8eeb0335
DW
4614 /* no flags means all of them! */
4615 if (!flags) {
d62a17ae 4616 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4617 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4618 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4619 } else {
a4d82a8a
PZ
4620 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4621 && peer_af_flag_check(peer, afi, safi,
4622 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4623 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4624 PEER_FLAG_AS_PATH_UNCHANGED);
4625 }
4626
a4d82a8a
PZ
4627 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4628 && peer_af_flag_check(peer, afi, safi,
4629 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4630 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4631 PEER_FLAG_NEXTHOP_UNCHANGED);
4632 }
4633
a4d82a8a
PZ
4634 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4635 && peer_af_flag_check(peer, afi, safi,
4636 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4637 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4638 PEER_FLAG_MED_UNCHANGED);
4639 }
d62a17ae 4640 }
4641
8eeb0335 4642 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4643}
4644
4645ALIAS_HIDDEN(
4646 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4647 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4648 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4649 "BGP attribute is propagated unchanged to this neighbor\n"
4650 "As-path attribute\n"
4651 "Nexthop attribute\n"
4652 "Med attribute\n")
596c17ba 4653
718e3744 4654DEFUN (no_neighbor_attr_unchanged,
4655 no_neighbor_attr_unchanged_cmd,
a8206004 4656 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4657 NO_STR
718e3744 4658 NEIGHBOR_STR
4659 NEIGHBOR_ADDR_STR2
31500417
DW
4660 "BGP attribute is propagated unchanged to this neighbor\n"
4661 "As-path attribute\n"
40e718b5 4662 "Nexthop attribute\n"
a8206004 4663 "Med attribute\n")
718e3744 4664{
d62a17ae 4665 int idx = 0;
4666 char *peer = argv[2]->arg;
d7c0a89a 4667 uint16_t flags = 0;
d62a17ae 4668
4669 if (argv_find(argv, argc, "as-path", &idx))
4670 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4671 idx = 0;
4672 if (argv_find(argv, argc, "next-hop", &idx))
4673 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4674 idx = 0;
4675 if (argv_find(argv, argc, "med", &idx))
4676 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4677
4678 if (!flags) // no flags means all of them!
4679 {
4680 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4681 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4682 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4683 }
4684
4685 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4686 bgp_node_safi(vty), flags);
4687}
4688
4689ALIAS_HIDDEN(
4690 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4691 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4692 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4693 "BGP attribute is propagated unchanged to this neighbor\n"
4694 "As-path attribute\n"
4695 "Nexthop attribute\n"
4696 "Med attribute\n")
718e3744 4697
718e3744 4698/* EBGP multihop configuration. */
d62a17ae 4699static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4700 const char *ttl_str)
718e3744 4701{
d62a17ae 4702 struct peer *peer;
4703 unsigned int ttl;
718e3744 4704
d62a17ae 4705 peer = peer_and_group_lookup_vty(vty, ip_str);
4706 if (!peer)
4707 return CMD_WARNING_CONFIG_FAILED;
718e3744 4708
d62a17ae 4709 if (peer->conf_if)
4710 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4711
d62a17ae 4712 if (!ttl_str)
4713 ttl = MAXTTL;
4714 else
4715 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4716
d62a17ae 4717 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4718}
4719
d62a17ae 4720static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4721{
d62a17ae 4722 struct peer *peer;
718e3744 4723
d62a17ae 4724 peer = peer_and_group_lookup_vty(vty, ip_str);
4725 if (!peer)
4726 return CMD_WARNING_CONFIG_FAILED;
718e3744 4727
d62a17ae 4728 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4729}
4730
4731/* neighbor ebgp-multihop. */
4732DEFUN (neighbor_ebgp_multihop,
4733 neighbor_ebgp_multihop_cmd,
9ccf14f7 4734 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4735 NEIGHBOR_STR
4736 NEIGHBOR_ADDR_STR2
4737 "Allow EBGP neighbors not on directly connected networks\n")
4738{
d62a17ae 4739 int idx_peer = 1;
4740 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4741}
4742
4743DEFUN (neighbor_ebgp_multihop_ttl,
4744 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4745 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4746 NEIGHBOR_STR
4747 NEIGHBOR_ADDR_STR2
4748 "Allow EBGP neighbors not on directly connected networks\n"
4749 "maximum hop count\n")
4750{
d62a17ae 4751 int idx_peer = 1;
4752 int idx_number = 3;
4753 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4754 argv[idx_number]->arg);
718e3744 4755}
4756
4757DEFUN (no_neighbor_ebgp_multihop,
4758 no_neighbor_ebgp_multihop_cmd,
a636c635 4759 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4760 NO_STR
4761 NEIGHBOR_STR
4762 NEIGHBOR_ADDR_STR2
a636c635
DW
4763 "Allow EBGP neighbors not on directly connected networks\n"
4764 "maximum hop count\n")
718e3744 4765{
d62a17ae 4766 int idx_peer = 2;
4767 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4768}
4769
6b0655a2 4770
6ffd2079 4771/* disable-connected-check */
4772DEFUN (neighbor_disable_connected_check,
4773 neighbor_disable_connected_check_cmd,
7ebe625c 4774 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4775 NEIGHBOR_STR
7ebe625c 4776 NEIGHBOR_ADDR_STR2
a636c635
DW
4777 "one-hop away EBGP peer using loopback address\n"
4778 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4779{
d62a17ae 4780 int idx_peer = 1;
4781 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4782 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4783}
4784
4785DEFUN (no_neighbor_disable_connected_check,
4786 no_neighbor_disable_connected_check_cmd,
7ebe625c 4787 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4788 NO_STR
4789 NEIGHBOR_STR
7ebe625c 4790 NEIGHBOR_ADDR_STR2
a636c635
DW
4791 "one-hop away EBGP peer using loopback address\n"
4792 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4793{
d62a17ae 4794 int idx_peer = 2;
4795 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4796 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4797}
4798
47cbc09b
PM
4799
4800/* enforce-first-as */
4801DEFUN (neighbor_enforce_first_as,
4802 neighbor_enforce_first_as_cmd,
4803 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4804 NEIGHBOR_STR
4805 NEIGHBOR_ADDR_STR2
4806 "Enforce the first AS for EBGP routes\n")
4807{
4808 int idx_peer = 1;
4809
4810 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4811 PEER_FLAG_ENFORCE_FIRST_AS);
4812}
4813
4814DEFUN (no_neighbor_enforce_first_as,
4815 no_neighbor_enforce_first_as_cmd,
4816 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4817 NO_STR
4818 NEIGHBOR_STR
4819 NEIGHBOR_ADDR_STR2
4820 "Enforce the first AS for EBGP routes\n")
4821{
4822 int idx_peer = 2;
4823
4824 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4825 PEER_FLAG_ENFORCE_FIRST_AS);
4826}
4827
4828
718e3744 4829DEFUN (neighbor_description,
4830 neighbor_description_cmd,
e961923c 4831 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR2
4834 "Neighbor specific description\n"
4835 "Up to 80 characters describing this neighbor\n")
4836{
d62a17ae 4837 int idx_peer = 1;
4838 int idx_line = 3;
4839 struct peer *peer;
4840 char *str;
718e3744 4841
d62a17ae 4842 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4843 if (!peer)
4844 return CMD_WARNING_CONFIG_FAILED;
718e3744 4845
d62a17ae 4846 str = argv_concat(argv, argc, idx_line);
718e3744 4847
d62a17ae 4848 peer_description_set(peer, str);
718e3744 4849
d62a17ae 4850 XFREE(MTYPE_TMP, str);
718e3744 4851
d62a17ae 4852 return CMD_SUCCESS;
718e3744 4853}
4854
4855DEFUN (no_neighbor_description,
4856 no_neighbor_description_cmd,
a14810f4 4857 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4858 NO_STR
4859 NEIGHBOR_STR
4860 NEIGHBOR_ADDR_STR2
a14810f4 4861 "Neighbor specific description\n")
718e3744 4862{
d62a17ae 4863 int idx_peer = 2;
4864 struct peer *peer;
718e3744 4865
d62a17ae 4866 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4867 if (!peer)
4868 return CMD_WARNING_CONFIG_FAILED;
718e3744 4869
d62a17ae 4870 peer_description_unset(peer);
718e3744 4871
d62a17ae 4872 return CMD_SUCCESS;
718e3744 4873}
4874
a14810f4
PM
4875ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4876 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4877 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4878 "Neighbor specific description\n"
4879 "Up to 80 characters describing this neighbor\n")
6b0655a2 4880
718e3744 4881/* Neighbor update-source. */
d62a17ae 4882static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4883 const char *source_str)
4884{
4885 struct peer *peer;
4886 struct prefix p;
a14810f4 4887 union sockunion su;
d62a17ae 4888
4889 peer = peer_and_group_lookup_vty(vty, peer_str);
4890 if (!peer)
4891 return CMD_WARNING_CONFIG_FAILED;
4892
4893 if (peer->conf_if)
4894 return CMD_WARNING;
4895
4896 if (source_str) {
a14810f4 4897 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4898 peer_update_source_addr_set(peer, &su);
4899 else {
4900 if (str2prefix(source_str, &p)) {
4901 vty_out(vty,
4902 "%% Invalid update-source, remove prefix length \n");
4903 return CMD_WARNING_CONFIG_FAILED;
4904 } else
4905 peer_update_source_if_set(peer, source_str);
4906 }
4907 } else
4908 peer_update_source_unset(peer);
4909
4910 return CMD_SUCCESS;
4911}
4912
4913#define BGP_UPDATE_SOURCE_HELP_STR \
4914 "IPv4 address\n" \
4915 "IPv6 address\n" \
4916 "Interface name (requires zebra to be running)\n"
369688c0 4917
718e3744 4918DEFUN (neighbor_update_source,
4919 neighbor_update_source_cmd,
9ccf14f7 4920 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4921 NEIGHBOR_STR
4922 NEIGHBOR_ADDR_STR2
4923 "Source of routing updates\n"
369688c0 4924 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4925{
d62a17ae 4926 int idx_peer = 1;
4927 int idx_peer_2 = 3;
4928 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4929 argv[idx_peer_2]->arg);
718e3744 4930}
4931
4932DEFUN (no_neighbor_update_source,
4933 no_neighbor_update_source_cmd,
c7178fe7 4934 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4935 NO_STR
4936 NEIGHBOR_STR
4937 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4938 "Source of routing updates\n"
4939 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4940{
d62a17ae 4941 int idx_peer = 2;
4942 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4943}
6b0655a2 4944
d62a17ae 4945static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4946 afi_t afi, safi_t safi,
4947 const char *rmap, int set)
718e3744 4948{
d62a17ae 4949 int ret;
4950 struct peer *peer;
80912664 4951 struct route_map *route_map = NULL;
718e3744 4952
d62a17ae 4953 peer = peer_and_group_lookup_vty(vty, peer_str);
4954 if (!peer)
4955 return CMD_WARNING_CONFIG_FAILED;
718e3744 4956
1de27621 4957 if (set) {
80912664
DS
4958 if (rmap)
4959 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
4960 ret = peer_default_originate_set(peer, afi, safi,
4961 rmap, route_map);
4962 } else
d62a17ae 4963 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4964
d62a17ae 4965 return bgp_vty_return(vty, ret);
718e3744 4966}
4967
4968/* neighbor default-originate. */
4969DEFUN (neighbor_default_originate,
4970 neighbor_default_originate_cmd,
9ccf14f7 4971 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4972 NEIGHBOR_STR
4973 NEIGHBOR_ADDR_STR2
4974 "Originate default route to this neighbor\n")
4975{
d62a17ae 4976 int idx_peer = 1;
4977 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4978 bgp_node_afi(vty),
4979 bgp_node_safi(vty), NULL, 1);
718e3744 4980}
4981
d62a17ae 4982ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4983 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4984 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4985 "Originate default route to this neighbor\n")
596c17ba 4986
718e3744 4987DEFUN (neighbor_default_originate_rmap,
4988 neighbor_default_originate_rmap_cmd,
9ccf14f7 4989 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4990 NEIGHBOR_STR
4991 NEIGHBOR_ADDR_STR2
4992 "Originate default route to this neighbor\n"
4993 "Route-map to specify criteria to originate default\n"
4994 "route-map name\n")
4995{
d62a17ae 4996 int idx_peer = 1;
4997 int idx_word = 4;
4998 return peer_default_originate_set_vty(
4999 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5000 argv[idx_word]->arg, 1);
718e3744 5001}
5002
d62a17ae 5003ALIAS_HIDDEN(
5004 neighbor_default_originate_rmap,
5005 neighbor_default_originate_rmap_hidden_cmd,
5006 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
5007 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5008 "Originate default route to this neighbor\n"
5009 "Route-map to specify criteria to originate default\n"
5010 "route-map name\n")
596c17ba 5011
718e3744 5012DEFUN (no_neighbor_default_originate,
5013 no_neighbor_default_originate_cmd,
a636c635 5014 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 5015 NO_STR
5016 NEIGHBOR_STR
5017 NEIGHBOR_ADDR_STR2
a636c635
DW
5018 "Originate default route to this neighbor\n"
5019 "Route-map to specify criteria to originate default\n"
5020 "route-map name\n")
718e3744 5021{
d62a17ae 5022 int idx_peer = 2;
5023 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5024 bgp_node_afi(vty),
5025 bgp_node_safi(vty), NULL, 0);
718e3744 5026}
5027
d62a17ae 5028ALIAS_HIDDEN(
5029 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
5030 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5031 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5032 "Originate default route to this neighbor\n"
5033 "Route-map to specify criteria to originate default\n"
5034 "route-map name\n")
596c17ba 5035
6b0655a2 5036
718e3744 5037/* Set neighbor's BGP port. */
d62a17ae 5038static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
5039 const char *port_str)
5040{
5041 struct peer *peer;
d7c0a89a 5042 uint16_t port;
d62a17ae 5043 struct servent *sp;
5044
5045 peer = peer_lookup_vty(vty, ip_str);
5046 if (!peer)
5047 return CMD_WARNING_CONFIG_FAILED;
5048
5049 if (!port_str) {
5050 sp = getservbyname("bgp", "tcp");
5051 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5052 } else {
5053 port = strtoul(port_str, NULL, 10);
5054 }
718e3744 5055
d62a17ae 5056 peer_port_set(peer, port);
718e3744 5057
d62a17ae 5058 return CMD_SUCCESS;
718e3744 5059}
5060
f418446b 5061/* Set specified peer's BGP port. */
718e3744 5062DEFUN (neighbor_port,
5063 neighbor_port_cmd,
9ccf14f7 5064 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 5065 NEIGHBOR_STR
5066 NEIGHBOR_ADDR_STR
5067 "Neighbor's BGP port\n"
5068 "TCP port number\n")
5069{
d62a17ae 5070 int idx_ip = 1;
5071 int idx_number = 3;
5072 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5073 argv[idx_number]->arg);
718e3744 5074}
5075
5076DEFUN (no_neighbor_port,
5077 no_neighbor_port_cmd,
9ccf14f7 5078 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 5079 NO_STR
5080 NEIGHBOR_STR
5081 NEIGHBOR_ADDR_STR
8334fd5a
DW
5082 "Neighbor's BGP port\n"
5083 "TCP port number\n")
718e3744 5084{
d62a17ae 5085 int idx_ip = 2;
5086 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 5087}
5088
6b0655a2 5089
718e3744 5090/* neighbor weight. */
d62a17ae 5091static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5092 safi_t safi, const char *weight_str)
718e3744 5093{
d62a17ae 5094 int ret;
5095 struct peer *peer;
5096 unsigned long weight;
718e3744 5097
d62a17ae 5098 peer = peer_and_group_lookup_vty(vty, ip_str);
5099 if (!peer)
5100 return CMD_WARNING_CONFIG_FAILED;
718e3744 5101
d62a17ae 5102 weight = strtoul(weight_str, NULL, 10);
718e3744 5103
d62a17ae 5104 ret = peer_weight_set(peer, afi, safi, weight);
5105 return bgp_vty_return(vty, ret);
718e3744 5106}
5107
d62a17ae 5108static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5109 safi_t safi)
718e3744 5110{
d62a17ae 5111 int ret;
5112 struct peer *peer;
718e3744 5113
d62a17ae 5114 peer = peer_and_group_lookup_vty(vty, ip_str);
5115 if (!peer)
5116 return CMD_WARNING_CONFIG_FAILED;
718e3744 5117
d62a17ae 5118 ret = peer_weight_unset(peer, afi, safi);
5119 return bgp_vty_return(vty, ret);
718e3744 5120}
5121
5122DEFUN (neighbor_weight,
5123 neighbor_weight_cmd,
9ccf14f7 5124 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 5125 NEIGHBOR_STR
5126 NEIGHBOR_ADDR_STR2
5127 "Set default weight for routes from this neighbor\n"
5128 "default weight\n")
5129{
d62a17ae 5130 int idx_peer = 1;
5131 int idx_number = 3;
5132 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5133 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 5134}
5135
d62a17ae 5136ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5137 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5138 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5139 "Set default weight for routes from this neighbor\n"
5140 "default weight\n")
596c17ba 5141
718e3744 5142DEFUN (no_neighbor_weight,
5143 no_neighbor_weight_cmd,
9ccf14f7 5144 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5145 NO_STR
5146 NEIGHBOR_STR
5147 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5148 "Set default weight for routes from this neighbor\n"
5149 "default weight\n")
718e3744 5150{
d62a17ae 5151 int idx_peer = 2;
5152 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5153 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 5154}
5155
d62a17ae 5156ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5157 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5158 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5159 "Set default weight for routes from this neighbor\n"
5160 "default weight\n")
596c17ba 5161
6b0655a2 5162
718e3744 5163/* Override capability negotiation. */
5164DEFUN (neighbor_override_capability,
5165 neighbor_override_capability_cmd,
9ccf14f7 5166 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5167 NEIGHBOR_STR
5168 NEIGHBOR_ADDR_STR2
5169 "Override capability negotiation result\n")
5170{
d62a17ae 5171 int idx_peer = 1;
5172 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5173 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5174}
5175
5176DEFUN (no_neighbor_override_capability,
5177 no_neighbor_override_capability_cmd,
9ccf14f7 5178 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5179 NO_STR
5180 NEIGHBOR_STR
5181 NEIGHBOR_ADDR_STR2
5182 "Override capability negotiation result\n")
5183{
d62a17ae 5184 int idx_peer = 2;
5185 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5186 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5187}
6b0655a2 5188
718e3744 5189DEFUN (neighbor_strict_capability,
5190 neighbor_strict_capability_cmd,
9fb964de 5191 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5192 NEIGHBOR_STR
9fb964de 5193 NEIGHBOR_ADDR_STR2
718e3744 5194 "Strict capability negotiation match\n")
5195{
9fb964de
PM
5196 int idx_peer = 1;
5197
5198 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5199 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5200}
5201
5202DEFUN (no_neighbor_strict_capability,
5203 no_neighbor_strict_capability_cmd,
9fb964de 5204 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5205 NO_STR
5206 NEIGHBOR_STR
9fb964de 5207 NEIGHBOR_ADDR_STR2
718e3744 5208 "Strict capability negotiation match\n")
5209{
9fb964de
PM
5210 int idx_peer = 2;
5211
5212 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5213 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5214}
6b0655a2 5215
d62a17ae 5216static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5217 const char *keep_str, const char *hold_str)
718e3744 5218{
d62a17ae 5219 int ret;
5220 struct peer *peer;
d7c0a89a
QY
5221 uint32_t keepalive;
5222 uint32_t holdtime;
718e3744 5223
d62a17ae 5224 peer = peer_and_group_lookup_vty(vty, ip_str);
5225 if (!peer)
5226 return CMD_WARNING_CONFIG_FAILED;
718e3744 5227
d62a17ae 5228 keepalive = strtoul(keep_str, NULL, 10);
5229 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5230
d62a17ae 5231 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5232
d62a17ae 5233 return bgp_vty_return(vty, ret);
718e3744 5234}
6b0655a2 5235
d62a17ae 5236static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5237{
d62a17ae 5238 int ret;
5239 struct peer *peer;
718e3744 5240
d62a17ae 5241 peer = peer_and_group_lookup_vty(vty, ip_str);
5242 if (!peer)
5243 return CMD_WARNING_CONFIG_FAILED;
718e3744 5244
d62a17ae 5245 ret = peer_timers_unset(peer);
718e3744 5246
d62a17ae 5247 return bgp_vty_return(vty, ret);
718e3744 5248}
5249
5250DEFUN (neighbor_timers,
5251 neighbor_timers_cmd,
9ccf14f7 5252 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5253 NEIGHBOR_STR
5254 NEIGHBOR_ADDR_STR2
5255 "BGP per neighbor timers\n"
5256 "Keepalive interval\n"
5257 "Holdtime\n")
5258{
d62a17ae 5259 int idx_peer = 1;
5260 int idx_number = 3;
5261 int idx_number_2 = 4;
5262 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5263 argv[idx_number]->arg,
5264 argv[idx_number_2]->arg);
718e3744 5265}
5266
5267DEFUN (no_neighbor_timers,
5268 no_neighbor_timers_cmd,
9ccf14f7 5269 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5270 NO_STR
5271 NEIGHBOR_STR
5272 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5273 "BGP per neighbor timers\n"
5274 "Keepalive interval\n"
5275 "Holdtime\n")
718e3744 5276{
d62a17ae 5277 int idx_peer = 2;
5278 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5279}
6b0655a2 5280
813d4307 5281
d62a17ae 5282static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5283 const char *time_str)
718e3744 5284{
d62a17ae 5285 int ret;
5286 struct peer *peer;
d7c0a89a 5287 uint32_t connect;
718e3744 5288
d62a17ae 5289 peer = peer_and_group_lookup_vty(vty, ip_str);
5290 if (!peer)
5291 return CMD_WARNING_CONFIG_FAILED;
718e3744 5292
d62a17ae 5293 connect = strtoul(time_str, NULL, 10);
718e3744 5294
d62a17ae 5295 ret = peer_timers_connect_set(peer, connect);
718e3744 5296
d62a17ae 5297 return bgp_vty_return(vty, ret);
718e3744 5298}
5299
d62a17ae 5300static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5301{
d62a17ae 5302 int ret;
5303 struct peer *peer;
718e3744 5304
d62a17ae 5305 peer = peer_and_group_lookup_vty(vty, ip_str);
5306 if (!peer)
5307 return CMD_WARNING_CONFIG_FAILED;
718e3744 5308
d62a17ae 5309 ret = peer_timers_connect_unset(peer);
718e3744 5310
d62a17ae 5311 return bgp_vty_return(vty, ret);
718e3744 5312}
5313
5314DEFUN (neighbor_timers_connect,
5315 neighbor_timers_connect_cmd,
9ccf14f7 5316 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5317 NEIGHBOR_STR
966f821c 5318 NEIGHBOR_ADDR_STR2
718e3744 5319 "BGP per neighbor timers\n"
5320 "BGP connect timer\n"
5321 "Connect timer\n")
5322{
d62a17ae 5323 int idx_peer = 1;
5324 int idx_number = 4;
5325 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5326 argv[idx_number]->arg);
718e3744 5327}
5328
5329DEFUN (no_neighbor_timers_connect,
5330 no_neighbor_timers_connect_cmd,
9ccf14f7 5331 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5332 NO_STR
5333 NEIGHBOR_STR
966f821c 5334 NEIGHBOR_ADDR_STR2
718e3744 5335 "BGP per neighbor timers\n"
8334fd5a
DW
5336 "BGP connect timer\n"
5337 "Connect timer\n")
718e3744 5338{
d62a17ae 5339 int idx_peer = 2;
5340 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5341}
5342
6b0655a2 5343
d62a17ae 5344static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5345 const char *time_str, int set)
718e3744 5346{
d62a17ae 5347 int ret;
5348 struct peer *peer;
d7c0a89a 5349 uint32_t routeadv = 0;
718e3744 5350
d62a17ae 5351 peer = peer_and_group_lookup_vty(vty, ip_str);
5352 if (!peer)
5353 return CMD_WARNING_CONFIG_FAILED;
718e3744 5354
d62a17ae 5355 if (time_str)
5356 routeadv = strtoul(time_str, NULL, 10);
718e3744 5357
d62a17ae 5358 if (set)
5359 ret = peer_advertise_interval_set(peer, routeadv);
5360 else
5361 ret = peer_advertise_interval_unset(peer);
718e3744 5362
d62a17ae 5363 return bgp_vty_return(vty, ret);
718e3744 5364}
5365
5366DEFUN (neighbor_advertise_interval,
5367 neighbor_advertise_interval_cmd,
9ccf14f7 5368 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5369 NEIGHBOR_STR
966f821c 5370 NEIGHBOR_ADDR_STR2
718e3744 5371 "Minimum interval between sending BGP routing updates\n"
5372 "time in seconds\n")
5373{
d62a17ae 5374 int idx_peer = 1;
5375 int idx_number = 3;
5376 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5377 argv[idx_number]->arg, 1);
718e3744 5378}
5379
5380DEFUN (no_neighbor_advertise_interval,
5381 no_neighbor_advertise_interval_cmd,
9ccf14f7 5382 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5383 NO_STR
5384 NEIGHBOR_STR
966f821c 5385 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5386 "Minimum interval between sending BGP routing updates\n"
5387 "time in seconds\n")
718e3744 5388{
d62a17ae 5389 int idx_peer = 2;
5390 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5391}
5392
6b0655a2 5393
518f0eb1
DS
5394/* Time to wait before processing route-map updates */
5395DEFUN (bgp_set_route_map_delay_timer,
5396 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5397 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5398 SET_STR
5399 "BGP route-map delay timer\n"
5400 "Time in secs to wait before processing route-map changes\n"
f414725f 5401 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5402{
d62a17ae 5403 int idx_number = 3;
d7c0a89a 5404 uint32_t rmap_delay_timer;
d62a17ae 5405
5406 if (argv[idx_number]->arg) {
5407 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5408 bm->rmap_update_timer = rmap_delay_timer;
5409
5410 /* if the dynamic update handling is being disabled, and a timer
5411 * is
5412 * running, stop the timer and act as if the timer has already
5413 * fired.
5414 */
5415 if (!rmap_delay_timer && bm->t_rmap_update) {
5416 BGP_TIMER_OFF(bm->t_rmap_update);
5417 thread_execute(bm->master, bgp_route_map_update_timer,
5418 NULL, 0);
5419 }
5420 return CMD_SUCCESS;
5421 } else {
5422 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5423 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5424 }
518f0eb1
DS
5425}
5426
5427DEFUN (no_bgp_set_route_map_delay_timer,
5428 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5429 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5430 NO_STR
3a2d747c 5431 BGP_STR
518f0eb1 5432 "Default BGP route-map delay timer\n"
8334fd5a
DW
5433 "Reset to default time to wait for processing route-map changes\n"
5434 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5435{
518f0eb1 5436
d62a17ae 5437 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5438
d62a17ae 5439 return CMD_SUCCESS;
518f0eb1
DS
5440}
5441
f414725f 5442
718e3744 5443/* neighbor interface */
d62a17ae 5444static int peer_interface_vty(struct vty *vty, const char *ip_str,
5445 const char *str)
718e3744 5446{
d62a17ae 5447 struct peer *peer;
718e3744 5448
d62a17ae 5449 peer = peer_lookup_vty(vty, ip_str);
5450 if (!peer || peer->conf_if) {
5451 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5452 return CMD_WARNING_CONFIG_FAILED;
5453 }
718e3744 5454
d62a17ae 5455 if (str)
5456 peer_interface_set(peer, str);
5457 else
5458 peer_interface_unset(peer);
718e3744 5459
d62a17ae 5460 return CMD_SUCCESS;
718e3744 5461}
5462
5463DEFUN (neighbor_interface,
5464 neighbor_interface_cmd,
9ccf14f7 5465 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5466 NEIGHBOR_STR
5467 NEIGHBOR_ADDR_STR
5468 "Interface\n"
5469 "Interface name\n")
5470{
d62a17ae 5471 int idx_ip = 1;
5472 int idx_word = 3;
5473 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5474}
5475
5476DEFUN (no_neighbor_interface,
5477 no_neighbor_interface_cmd,
9ccf14f7 5478 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5479 NO_STR
5480 NEIGHBOR_STR
16cedbb0 5481 NEIGHBOR_ADDR_STR2
718e3744 5482 "Interface\n"
5483 "Interface name\n")
5484{
d62a17ae 5485 int idx_peer = 2;
5486 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5487}
6b0655a2 5488
718e3744 5489DEFUN (neighbor_distribute_list,
5490 neighbor_distribute_list_cmd,
9ccf14f7 5491 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5492 NEIGHBOR_STR
5493 NEIGHBOR_ADDR_STR2
5494 "Filter updates to/from this neighbor\n"
5495 "IP access-list number\n"
5496 "IP access-list number (expanded range)\n"
5497 "IP Access-list name\n"
5498 "Filter incoming updates\n"
5499 "Filter outgoing updates\n")
5500{
d62a17ae 5501 int idx_peer = 1;
5502 int idx_acl = 3;
5503 int direct, ret;
5504 struct peer *peer;
a8206004 5505
d62a17ae 5506 const char *pstr = argv[idx_peer]->arg;
5507 const char *acl = argv[idx_acl]->arg;
5508 const char *inout = argv[argc - 1]->text;
a8206004 5509
d62a17ae 5510 peer = peer_and_group_lookup_vty(vty, pstr);
5511 if (!peer)
5512 return CMD_WARNING_CONFIG_FAILED;
a8206004 5513
d62a17ae 5514 /* Check filter direction. */
5515 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5516 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5517 direct, acl);
a8206004 5518
d62a17ae 5519 return bgp_vty_return(vty, ret);
718e3744 5520}
5521
d62a17ae 5522ALIAS_HIDDEN(
5523 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5524 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5525 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5526 "Filter updates to/from this neighbor\n"
5527 "IP access-list number\n"
5528 "IP access-list number (expanded range)\n"
5529 "IP Access-list name\n"
5530 "Filter incoming updates\n"
5531 "Filter outgoing updates\n")
596c17ba 5532
718e3744 5533DEFUN (no_neighbor_distribute_list,
5534 no_neighbor_distribute_list_cmd,
9ccf14f7 5535 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5536 NO_STR
5537 NEIGHBOR_STR
5538 NEIGHBOR_ADDR_STR2
5539 "Filter updates to/from this neighbor\n"
5540 "IP access-list number\n"
5541 "IP access-list number (expanded range)\n"
5542 "IP Access-list name\n"
5543 "Filter incoming updates\n"
5544 "Filter outgoing updates\n")
5545{
d62a17ae 5546 int idx_peer = 2;
5547 int direct, ret;
5548 struct peer *peer;
a8206004 5549
d62a17ae 5550 const char *pstr = argv[idx_peer]->arg;
5551 const char *inout = argv[argc - 1]->text;
a8206004 5552
d62a17ae 5553 peer = peer_and_group_lookup_vty(vty, pstr);
5554 if (!peer)
5555 return CMD_WARNING_CONFIG_FAILED;
a8206004 5556
d62a17ae 5557 /* Check filter direction. */
5558 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5559 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5560 direct);
a8206004 5561
d62a17ae 5562 return bgp_vty_return(vty, ret);
718e3744 5563}
6b0655a2 5564
d62a17ae 5565ALIAS_HIDDEN(
5566 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5567 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5568 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5569 "Filter updates to/from this neighbor\n"
5570 "IP access-list number\n"
5571 "IP access-list number (expanded range)\n"
5572 "IP Access-list name\n"
5573 "Filter incoming updates\n"
5574 "Filter outgoing updates\n")
596c17ba 5575
718e3744 5576/* Set prefix list to the peer. */
d62a17ae 5577static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5578 afi_t afi, safi_t safi,
5579 const char *name_str,
5580 const char *direct_str)
718e3744 5581{
d62a17ae 5582 int ret;
d62a17ae 5583 int direct = FILTER_IN;
cf9ac8bf 5584 struct peer *peer;
718e3744 5585
d62a17ae 5586 peer = peer_and_group_lookup_vty(vty, ip_str);
5587 if (!peer)
5588 return CMD_WARNING_CONFIG_FAILED;
718e3744 5589
d62a17ae 5590 /* Check filter direction. */
5591 if (strncmp(direct_str, "i", 1) == 0)
5592 direct = FILTER_IN;
5593 else if (strncmp(direct_str, "o", 1) == 0)
5594 direct = FILTER_OUT;
718e3744 5595
d62a17ae 5596 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5597
d62a17ae 5598 return bgp_vty_return(vty, ret);
718e3744 5599}
5600
d62a17ae 5601static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5602 afi_t afi, safi_t safi,
5603 const char *direct_str)
718e3744 5604{
d62a17ae 5605 int ret;
5606 struct peer *peer;
5607 int direct = FILTER_IN;
718e3744 5608
d62a17ae 5609 peer = peer_and_group_lookup_vty(vty, ip_str);
5610 if (!peer)
5611 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5612
d62a17ae 5613 /* Check filter direction. */
5614 if (strncmp(direct_str, "i", 1) == 0)
5615 direct = FILTER_IN;
5616 else if (strncmp(direct_str, "o", 1) == 0)
5617 direct = FILTER_OUT;
718e3744 5618
d62a17ae 5619 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5620
d62a17ae 5621 return bgp_vty_return(vty, ret);
718e3744 5622}
5623
5624DEFUN (neighbor_prefix_list,
5625 neighbor_prefix_list_cmd,
9ccf14f7 5626 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5627 NEIGHBOR_STR
5628 NEIGHBOR_ADDR_STR2
5629 "Filter updates to/from this neighbor\n"
5630 "Name of a prefix list\n"
5631 "Filter incoming updates\n"
5632 "Filter outgoing updates\n")
5633{
d62a17ae 5634 int idx_peer = 1;
5635 int idx_word = 3;
5636 int idx_in_out = 4;
5637 return peer_prefix_list_set_vty(
5638 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5639 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5640}
5641
d62a17ae 5642ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5643 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5644 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5645 "Filter updates to/from this neighbor\n"
5646 "Name of a prefix list\n"
5647 "Filter incoming updates\n"
5648 "Filter outgoing updates\n")
596c17ba 5649
718e3744 5650DEFUN (no_neighbor_prefix_list,
5651 no_neighbor_prefix_list_cmd,
9ccf14f7 5652 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5653 NO_STR
5654 NEIGHBOR_STR
5655 NEIGHBOR_ADDR_STR2
5656 "Filter updates to/from this neighbor\n"
5657 "Name of a prefix list\n"
5658 "Filter incoming updates\n"
5659 "Filter outgoing updates\n")
5660{
d62a17ae 5661 int idx_peer = 2;
5662 int idx_in_out = 5;
5663 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5664 bgp_node_afi(vty), bgp_node_safi(vty),
5665 argv[idx_in_out]->arg);
718e3744 5666}
6b0655a2 5667
d62a17ae 5668ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5669 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5670 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5671 "Filter updates to/from this neighbor\n"
5672 "Name of a prefix list\n"
5673 "Filter incoming updates\n"
5674 "Filter outgoing updates\n")
596c17ba 5675
d62a17ae 5676static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5677 safi_t safi, const char *name_str,
5678 const char *direct_str)
718e3744 5679{
d62a17ae 5680 int ret;
5681 struct peer *peer;
5682 int direct = FILTER_IN;
718e3744 5683
d62a17ae 5684 peer = peer_and_group_lookup_vty(vty, ip_str);
5685 if (!peer)
5686 return CMD_WARNING_CONFIG_FAILED;
718e3744 5687
d62a17ae 5688 /* Check filter direction. */
5689 if (strncmp(direct_str, "i", 1) == 0)
5690 direct = FILTER_IN;
5691 else if (strncmp(direct_str, "o", 1) == 0)
5692 direct = FILTER_OUT;
718e3744 5693
d62a17ae 5694 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5695
d62a17ae 5696 return bgp_vty_return(vty, ret);
718e3744 5697}
5698
d62a17ae 5699static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5700 safi_t safi, const char *direct_str)
718e3744 5701{
d62a17ae 5702 int ret;
5703 struct peer *peer;
5704 int direct = FILTER_IN;
718e3744 5705
d62a17ae 5706 peer = peer_and_group_lookup_vty(vty, ip_str);
5707 if (!peer)
5708 return CMD_WARNING_CONFIG_FAILED;
718e3744 5709
d62a17ae 5710 /* Check filter direction. */
5711 if (strncmp(direct_str, "i", 1) == 0)
5712 direct = FILTER_IN;
5713 else if (strncmp(direct_str, "o", 1) == 0)
5714 direct = FILTER_OUT;
718e3744 5715
d62a17ae 5716 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5717
d62a17ae 5718 return bgp_vty_return(vty, ret);
718e3744 5719}
5720
5721DEFUN (neighbor_filter_list,
5722 neighbor_filter_list_cmd,
9ccf14f7 5723 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5724 NEIGHBOR_STR
5725 NEIGHBOR_ADDR_STR2
5726 "Establish BGP filters\n"
5727 "AS path access-list name\n"
5728 "Filter incoming routes\n"
5729 "Filter outgoing routes\n")
5730{
d62a17ae 5731 int idx_peer = 1;
5732 int idx_word = 3;
5733 int idx_in_out = 4;
5734 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5735 bgp_node_safi(vty), argv[idx_word]->arg,
5736 argv[idx_in_out]->arg);
718e3744 5737}
5738
d62a17ae 5739ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5740 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5741 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5742 "Establish BGP filters\n"
5743 "AS path access-list name\n"
5744 "Filter incoming routes\n"
5745 "Filter outgoing routes\n")
596c17ba 5746
718e3744 5747DEFUN (no_neighbor_filter_list,
5748 no_neighbor_filter_list_cmd,
9ccf14f7 5749 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5750 NO_STR
5751 NEIGHBOR_STR
5752 NEIGHBOR_ADDR_STR2
5753 "Establish BGP filters\n"
5754 "AS path access-list name\n"
5755 "Filter incoming routes\n"
5756 "Filter outgoing routes\n")
5757{
d62a17ae 5758 int idx_peer = 2;
5759 int idx_in_out = 5;
5760 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5761 bgp_node_afi(vty), bgp_node_safi(vty),
5762 argv[idx_in_out]->arg);
718e3744 5763}
6b0655a2 5764
d62a17ae 5765ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5766 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5767 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5768 "Establish BGP filters\n"
5769 "AS path access-list name\n"
5770 "Filter incoming routes\n"
5771 "Filter outgoing routes\n")
596c17ba 5772
718e3744 5773/* Set route-map to the peer. */
d62a17ae 5774static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5775 afi_t afi, safi_t safi, const char *name_str,
5776 const char *direct_str)
718e3744 5777{
d62a17ae 5778 int ret;
5779 struct peer *peer;
5780 int direct = RMAP_IN;
1de27621 5781 struct route_map *route_map;
718e3744 5782
d62a17ae 5783 peer = peer_and_group_lookup_vty(vty, ip_str);
5784 if (!peer)
5785 return CMD_WARNING_CONFIG_FAILED;
718e3744 5786
d62a17ae 5787 /* Check filter direction. */
5788 if (strncmp(direct_str, "in", 2) == 0)
5789 direct = RMAP_IN;
5790 else if (strncmp(direct_str, "o", 1) == 0)
5791 direct = RMAP_OUT;
718e3744 5792
1de27621
DA
5793 route_map = route_map_lookup_warn_noexist(vty, name_str);
5794 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 5795
d62a17ae 5796 return bgp_vty_return(vty, ret);
718e3744 5797}
5798
d62a17ae 5799static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5800 afi_t afi, safi_t safi,
5801 const char *direct_str)
718e3744 5802{
d62a17ae 5803 int ret;
5804 struct peer *peer;
5805 int direct = RMAP_IN;
718e3744 5806
d62a17ae 5807 peer = peer_and_group_lookup_vty(vty, ip_str);
5808 if (!peer)
5809 return CMD_WARNING_CONFIG_FAILED;
718e3744 5810
d62a17ae 5811 /* Check filter direction. */
5812 if (strncmp(direct_str, "in", 2) == 0)
5813 direct = RMAP_IN;
5814 else if (strncmp(direct_str, "o", 1) == 0)
5815 direct = RMAP_OUT;
718e3744 5816
d62a17ae 5817 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5818
d62a17ae 5819 return bgp_vty_return(vty, ret);
718e3744 5820}
5821
5822DEFUN (neighbor_route_map,
5823 neighbor_route_map_cmd,
9ccf14f7 5824 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5825 NEIGHBOR_STR
5826 NEIGHBOR_ADDR_STR2
5827 "Apply route map to neighbor\n"
5828 "Name of route map\n"
5829 "Apply map to incoming routes\n"
2a3d5731 5830 "Apply map to outbound routes\n")
718e3744 5831{
d62a17ae 5832 int idx_peer = 1;
5833 int idx_word = 3;
5834 int idx_in_out = 4;
5835 return peer_route_map_set_vty(
5836 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5837 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5838}
5839
d62a17ae 5840ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5841 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5842 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5843 "Apply route map to neighbor\n"
5844 "Name of route map\n"
5845 "Apply map to incoming routes\n"
5846 "Apply map to outbound routes\n")
596c17ba 5847
718e3744 5848DEFUN (no_neighbor_route_map,
5849 no_neighbor_route_map_cmd,
9ccf14f7 5850 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5851 NO_STR
5852 NEIGHBOR_STR
5853 NEIGHBOR_ADDR_STR2
5854 "Apply route map to neighbor\n"
5855 "Name of route map\n"
5856 "Apply map to incoming routes\n"
2a3d5731 5857 "Apply map to outbound routes\n")
718e3744 5858{
d62a17ae 5859 int idx_peer = 2;
5860 int idx_in_out = 5;
5861 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5862 bgp_node_afi(vty), bgp_node_safi(vty),
5863 argv[idx_in_out]->arg);
718e3744 5864}
6b0655a2 5865
d62a17ae 5866ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5867 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5868 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5869 "Apply route map to neighbor\n"
5870 "Name of route map\n"
5871 "Apply map to incoming routes\n"
5872 "Apply map to outbound routes\n")
596c17ba 5873
718e3744 5874/* Set unsuppress-map to the peer. */
d62a17ae 5875static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5876 afi_t afi, safi_t safi,
5877 const char *name_str)
718e3744 5878{
d62a17ae 5879 int ret;
5880 struct peer *peer;
1de27621 5881 struct route_map *route_map;
718e3744 5882
d62a17ae 5883 peer = peer_and_group_lookup_vty(vty, ip_str);
5884 if (!peer)
5885 return CMD_WARNING_CONFIG_FAILED;
718e3744 5886
1de27621
DA
5887 route_map = route_map_lookup_warn_noexist(vty, name_str);
5888 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 5889
d62a17ae 5890 return bgp_vty_return(vty, ret);
718e3744 5891}
5892
5893/* Unset route-map from the peer. */
d62a17ae 5894static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5895 afi_t afi, safi_t safi)
718e3744 5896{
d62a17ae 5897 int ret;
5898 struct peer *peer;
718e3744 5899
d62a17ae 5900 peer = peer_and_group_lookup_vty(vty, ip_str);
5901 if (!peer)
5902 return CMD_WARNING_CONFIG_FAILED;
718e3744 5903
d62a17ae 5904 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5905
d62a17ae 5906 return bgp_vty_return(vty, ret);
718e3744 5907}
5908
5909DEFUN (neighbor_unsuppress_map,
5910 neighbor_unsuppress_map_cmd,
9ccf14f7 5911 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5912 NEIGHBOR_STR
5913 NEIGHBOR_ADDR_STR2
5914 "Route-map to selectively unsuppress suppressed routes\n"
5915 "Name of route map\n")
5916{
d62a17ae 5917 int idx_peer = 1;
5918 int idx_word = 3;
5919 return peer_unsuppress_map_set_vty(
5920 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5921 argv[idx_word]->arg);
718e3744 5922}
5923
d62a17ae 5924ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5925 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5926 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5927 "Route-map to selectively unsuppress suppressed routes\n"
5928 "Name of route map\n")
596c17ba 5929
718e3744 5930DEFUN (no_neighbor_unsuppress_map,
5931 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5932 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5933 NO_STR
5934 NEIGHBOR_STR
5935 NEIGHBOR_ADDR_STR2
5936 "Route-map to selectively unsuppress suppressed routes\n"
5937 "Name of route map\n")
5938{
d62a17ae 5939 int idx_peer = 2;
5940 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5941 bgp_node_afi(vty),
5942 bgp_node_safi(vty));
718e3744 5943}
6b0655a2 5944
d62a17ae 5945ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5946 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5947 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5948 "Route-map to selectively unsuppress suppressed routes\n"
5949 "Name of route map\n")
596c17ba 5950
d62a17ae 5951static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5952 afi_t afi, safi_t safi,
5953 const char *num_str,
5954 const char *threshold_str, int warning,
5955 const char *restart_str)
718e3744 5956{
d62a17ae 5957 int ret;
5958 struct peer *peer;
d7c0a89a
QY
5959 uint32_t max;
5960 uint8_t threshold;
5961 uint16_t restart;
718e3744 5962
d62a17ae 5963 peer = peer_and_group_lookup_vty(vty, ip_str);
5964 if (!peer)
5965 return CMD_WARNING_CONFIG_FAILED;
718e3744 5966
d62a17ae 5967 max = strtoul(num_str, NULL, 10);
5968 if (threshold_str)
5969 threshold = atoi(threshold_str);
5970 else
5971 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5972
d62a17ae 5973 if (restart_str)
5974 restart = atoi(restart_str);
5975 else
5976 restart = 0;
0a486e5f 5977
d62a17ae 5978 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5979 restart);
718e3744 5980
d62a17ae 5981 return bgp_vty_return(vty, ret);
718e3744 5982}
5983
d62a17ae 5984static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5985 afi_t afi, safi_t safi)
718e3744 5986{
d62a17ae 5987 int ret;
5988 struct peer *peer;
718e3744 5989
d62a17ae 5990 peer = peer_and_group_lookup_vty(vty, ip_str);
5991 if (!peer)
5992 return CMD_WARNING_CONFIG_FAILED;
718e3744 5993
d62a17ae 5994 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5995
d62a17ae 5996 return bgp_vty_return(vty, ret);
718e3744 5997}
5998
5999/* Maximum number of prefix configuration. prefix count is different
6000 for each peer configuration. So this configuration can be set for
6001 each peer configuration. */
6002DEFUN (neighbor_maximum_prefix,
6003 neighbor_maximum_prefix_cmd,
9ccf14f7 6004 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 6005 NEIGHBOR_STR
6006 NEIGHBOR_ADDR_STR2
6007 "Maximum number of prefix accept from this peer\n"
6008 "maximum no. of prefix limit\n")
6009{
d62a17ae 6010 int idx_peer = 1;
6011 int idx_number = 3;
6012 return peer_maximum_prefix_set_vty(
6013 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6014 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 6015}
6016
d62a17ae 6017ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
6018 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
6019 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6020 "Maximum number of prefix accept from this peer\n"
6021 "maximum no. of prefix limit\n")
596c17ba 6022
e0701b79 6023DEFUN (neighbor_maximum_prefix_threshold,
6024 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 6025 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 6026 NEIGHBOR_STR
6027 NEIGHBOR_ADDR_STR2
6028 "Maximum number of prefix accept from this peer\n"
6029 "maximum no. of prefix limit\n"
6030 "Threshold value (%) at which to generate a warning msg\n")
6031{
d62a17ae 6032 int idx_peer = 1;
6033 int idx_number = 3;
6034 int idx_number_2 = 4;
6035 return peer_maximum_prefix_set_vty(
6036 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6037 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 6038}
e0701b79 6039
d62a17ae 6040ALIAS_HIDDEN(
6041 neighbor_maximum_prefix_threshold,
6042 neighbor_maximum_prefix_threshold_hidden_cmd,
6043 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6044 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6045 "Maximum number of prefix accept from this peer\n"
6046 "maximum no. of prefix limit\n"
6047 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 6048
718e3744 6049DEFUN (neighbor_maximum_prefix_warning,
6050 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 6051 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 6052 NEIGHBOR_STR
6053 NEIGHBOR_ADDR_STR2
6054 "Maximum number of prefix accept from this peer\n"
6055 "maximum no. of prefix limit\n"
6056 "Only give warning message when limit is exceeded\n")
6057{
d62a17ae 6058 int idx_peer = 1;
6059 int idx_number = 3;
6060 return peer_maximum_prefix_set_vty(
6061 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6062 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 6063}
6064
d62a17ae 6065ALIAS_HIDDEN(
6066 neighbor_maximum_prefix_warning,
6067 neighbor_maximum_prefix_warning_hidden_cmd,
6068 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6069 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6070 "Maximum number of prefix accept from this peer\n"
6071 "maximum no. of prefix limit\n"
6072 "Only give warning message when limit is exceeded\n")
596c17ba 6073
e0701b79 6074DEFUN (neighbor_maximum_prefix_threshold_warning,
6075 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 6076 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 6077 NEIGHBOR_STR
6078 NEIGHBOR_ADDR_STR2
6079 "Maximum number of prefix accept from this peer\n"
6080 "maximum no. of prefix limit\n"
6081 "Threshold value (%) at which to generate a warning msg\n"
6082 "Only give warning message when limit is exceeded\n")
6083{
d62a17ae 6084 int idx_peer = 1;
6085 int idx_number = 3;
6086 int idx_number_2 = 4;
6087 return peer_maximum_prefix_set_vty(
6088 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6089 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 6090}
6091
d62a17ae 6092ALIAS_HIDDEN(
6093 neighbor_maximum_prefix_threshold_warning,
6094 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6095 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6096 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6097 "Maximum number of prefix accept from this peer\n"
6098 "maximum no. of prefix limit\n"
6099 "Threshold value (%) at which to generate a warning msg\n"
6100 "Only give warning message when limit is exceeded\n")
596c17ba 6101
0a486e5f 6102DEFUN (neighbor_maximum_prefix_restart,
6103 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 6104 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 6105 NEIGHBOR_STR
6106 NEIGHBOR_ADDR_STR2
6107 "Maximum number of prefix accept from this peer\n"
6108 "maximum no. of prefix limit\n"
6109 "Restart bgp connection after limit is exceeded\n"
efd7904e 6110 "Restart interval in minutes\n")
0a486e5f 6111{
d62a17ae 6112 int idx_peer = 1;
6113 int idx_number = 3;
6114 int idx_number_2 = 5;
6115 return peer_maximum_prefix_set_vty(
6116 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6117 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 6118}
6119
d62a17ae 6120ALIAS_HIDDEN(
6121 neighbor_maximum_prefix_restart,
6122 neighbor_maximum_prefix_restart_hidden_cmd,
6123 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6124 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6125 "Maximum number of prefix accept from this peer\n"
6126 "maximum no. of prefix limit\n"
6127 "Restart bgp connection after limit is exceeded\n"
efd7904e 6128 "Restart interval in minutes\n")
596c17ba 6129
0a486e5f 6130DEFUN (neighbor_maximum_prefix_threshold_restart,
6131 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 6132 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 6133 NEIGHBOR_STR
6134 NEIGHBOR_ADDR_STR2
16cedbb0 6135 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 6136 "maximum no. of prefix limit\n"
6137 "Threshold value (%) at which to generate a warning msg\n"
6138 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6139 "Restart interval in minutes\n")
0a486e5f 6140{
d62a17ae 6141 int idx_peer = 1;
6142 int idx_number = 3;
6143 int idx_number_2 = 4;
6144 int idx_number_3 = 6;
6145 return peer_maximum_prefix_set_vty(
6146 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6147 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6148 argv[idx_number_3]->arg);
6149}
6150
6151ALIAS_HIDDEN(
6152 neighbor_maximum_prefix_threshold_restart,
6153 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6154 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6155 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6156 "Maximum number of prefixes to accept from this peer\n"
6157 "maximum no. of prefix limit\n"
6158 "Threshold value (%) at which to generate a warning msg\n"
6159 "Restart bgp connection after limit is exceeded\n"
6160 "Restart interval in minutes\n")
596c17ba 6161
718e3744 6162DEFUN (no_neighbor_maximum_prefix,
6163 no_neighbor_maximum_prefix_cmd,
d04c479d 6164 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 6165 NO_STR
6166 NEIGHBOR_STR
6167 NEIGHBOR_ADDR_STR2
16cedbb0 6168 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
6169 "maximum no. of prefix limit\n"
6170 "Threshold value (%) at which to generate a warning msg\n"
6171 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6172 "Restart interval in minutes\n"
31500417 6173 "Only give warning message when limit is exceeded\n")
718e3744 6174{
d62a17ae 6175 int idx_peer = 2;
6176 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6177 bgp_node_afi(vty),
6178 bgp_node_safi(vty));
718e3744 6179}
e52702f2 6180
d62a17ae 6181ALIAS_HIDDEN(
6182 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6183 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6184 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6185 "Maximum number of prefixes to accept from this peer\n"
6186 "maximum no. of prefix limit\n"
6187 "Threshold value (%) at which to generate a warning msg\n"
6188 "Restart bgp connection after limit is exceeded\n"
6189 "Restart interval in minutes\n"
6190 "Only give warning message when limit is exceeded\n")
596c17ba 6191
718e3744 6192
718e3744 6193/* "neighbor allowas-in" */
6194DEFUN (neighbor_allowas_in,
6195 neighbor_allowas_in_cmd,
fd8503f5 6196 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6197 NEIGHBOR_STR
6198 NEIGHBOR_ADDR_STR2
31500417 6199 "Accept as-path with my AS present in it\n"
f79f7a7b 6200 "Number of occurrences of AS number\n"
fd8503f5 6201 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6202{
d62a17ae 6203 int idx_peer = 1;
6204 int idx_number_origin = 3;
6205 int ret;
6206 int origin = 0;
6207 struct peer *peer;
6208 int allow_num = 0;
6209
6210 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6211 if (!peer)
6212 return CMD_WARNING_CONFIG_FAILED;
6213
6214 if (argc <= idx_number_origin)
6215 allow_num = 3;
6216 else {
6217 if (argv[idx_number_origin]->type == WORD_TKN)
6218 origin = 1;
6219 else
6220 allow_num = atoi(argv[idx_number_origin]->arg);
6221 }
6222
6223 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6224 allow_num, origin);
6225
6226 return bgp_vty_return(vty, ret);
6227}
6228
6229ALIAS_HIDDEN(
6230 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6231 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6232 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6233 "Accept as-path with my AS present in it\n"
f79f7a7b 6234 "Number of occurrences of AS number\n"
d62a17ae 6235 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6236
718e3744 6237DEFUN (no_neighbor_allowas_in,
6238 no_neighbor_allowas_in_cmd,
fd8503f5 6239 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6240 NO_STR
6241 NEIGHBOR_STR
6242 NEIGHBOR_ADDR_STR2
8334fd5a 6243 "allow local ASN appears in aspath attribute\n"
f79f7a7b 6244 "Number of occurrences of AS number\n"
fd8503f5 6245 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6246{
d62a17ae 6247 int idx_peer = 2;
6248 int ret;
6249 struct peer *peer;
718e3744 6250
d62a17ae 6251 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6252 if (!peer)
6253 return CMD_WARNING_CONFIG_FAILED;
718e3744 6254
d62a17ae 6255 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6256 bgp_node_safi(vty));
718e3744 6257
d62a17ae 6258 return bgp_vty_return(vty, ret);
718e3744 6259}
6b0655a2 6260
d62a17ae 6261ALIAS_HIDDEN(
6262 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6263 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6264 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6265 "allow local ASN appears in aspath attribute\n"
f79f7a7b 6266 "Number of occurrences of AS number\n"
d62a17ae 6267 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6268
fa411a21
NH
6269DEFUN (neighbor_ttl_security,
6270 neighbor_ttl_security_cmd,
7ebe625c 6271 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6272 NEIGHBOR_STR
7ebe625c 6273 NEIGHBOR_ADDR_STR2
16cedbb0 6274 "BGP ttl-security parameters\n"
d7fa34c1
QY
6275 "Specify the maximum number of hops to the BGP peer\n"
6276 "Number of hops to BGP peer\n")
fa411a21 6277{
d62a17ae 6278 int idx_peer = 1;
6279 int idx_number = 4;
6280 struct peer *peer;
6281 int gtsm_hops;
6282
6283 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6284 if (!peer)
6285 return CMD_WARNING_CONFIG_FAILED;
6286
6287 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6288
7ebe625c
QY
6289 /*
6290 * If 'neighbor swpX', then this is for directly connected peers,
6291 * we should not accept a ttl-security hops value greater than 1.
6292 */
6293 if (peer->conf_if && (gtsm_hops > 1)) {
6294 vty_out(vty,
6295 "%s is directly connected peer, hops cannot exceed 1\n",
6296 argv[idx_peer]->arg);
6297 return CMD_WARNING_CONFIG_FAILED;
6298 }
6299
d62a17ae 6300 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6301}
6302
6303DEFUN (no_neighbor_ttl_security,
6304 no_neighbor_ttl_security_cmd,
7ebe625c 6305 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6306 NO_STR
6307 NEIGHBOR_STR
7ebe625c 6308 NEIGHBOR_ADDR_STR2
16cedbb0 6309 "BGP ttl-security parameters\n"
3a2d747c
QY
6310 "Specify the maximum number of hops to the BGP peer\n"
6311 "Number of hops to BGP peer\n")
fa411a21 6312{
d62a17ae 6313 int idx_peer = 2;
6314 struct peer *peer;
fa411a21 6315
d62a17ae 6316 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6317 if (!peer)
6318 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6319
d62a17ae 6320 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6321}
6b0655a2 6322
adbac85e
DW
6323DEFUN (neighbor_addpath_tx_all_paths,
6324 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6325 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6326 NEIGHBOR_STR
6327 NEIGHBOR_ADDR_STR2
6328 "Use addpath to advertise all paths to a neighbor\n")
6329{
d62a17ae 6330 int idx_peer = 1;
6331 struct peer *peer;
adbac85e 6332
d62a17ae 6333 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6334 if (!peer)
6335 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6336
dcc68b5e
MS
6337 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6338 BGP_ADDPATH_ALL);
6339 return CMD_SUCCESS;
adbac85e
DW
6340}
6341
d62a17ae 6342ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6343 neighbor_addpath_tx_all_paths_hidden_cmd,
6344 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6345 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6346 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6347
adbac85e
DW
6348DEFUN (no_neighbor_addpath_tx_all_paths,
6349 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6350 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6351 NO_STR
6352 NEIGHBOR_STR
6353 NEIGHBOR_ADDR_STR2
6354 "Use addpath to advertise all paths to a neighbor\n")
6355{
d62a17ae 6356 int idx_peer = 2;
dcc68b5e
MS
6357 struct peer *peer;
6358
6359 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6360 if (!peer)
6361 return CMD_WARNING_CONFIG_FAILED;
6362
6363 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6364 != BGP_ADDPATH_ALL) {
6365 vty_out(vty,
6366 "%% Peer not currently configured to transmit all paths.");
6367 return CMD_WARNING_CONFIG_FAILED;
6368 }
6369
6370 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6371 BGP_ADDPATH_NONE);
6372
6373 return CMD_SUCCESS;
adbac85e
DW
6374}
6375
d62a17ae 6376ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6377 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6378 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6379 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6380 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6381
06370dac
DW
6382DEFUN (neighbor_addpath_tx_bestpath_per_as,
6383 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6384 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6385 NEIGHBOR_STR
6386 NEIGHBOR_ADDR_STR2
6387 "Use addpath to advertise the bestpath per each neighboring AS\n")
6388{
d62a17ae 6389 int idx_peer = 1;
6390 struct peer *peer;
06370dac 6391
d62a17ae 6392 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6393 if (!peer)
6394 return CMD_WARNING_CONFIG_FAILED;
06370dac 6395
dcc68b5e
MS
6396 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6397 BGP_ADDPATH_BEST_PER_AS);
6398
6399 return CMD_SUCCESS;
06370dac
DW
6400}
6401
d62a17ae 6402ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6403 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6404 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6405 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6406 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6407
06370dac
DW
6408DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6409 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6410 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6411 NO_STR
6412 NEIGHBOR_STR
6413 NEIGHBOR_ADDR_STR2
6414 "Use addpath to advertise the bestpath per each neighboring AS\n")
6415{
d62a17ae 6416 int idx_peer = 2;
dcc68b5e
MS
6417 struct peer *peer;
6418
6419 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6420 if (!peer)
6421 return CMD_WARNING_CONFIG_FAILED;
6422
6423 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6424 != BGP_ADDPATH_BEST_PER_AS) {
6425 vty_out(vty,
6426 "%% Peer not currently configured to transmit all best path per as.");
6427 return CMD_WARNING_CONFIG_FAILED;
6428 }
6429
6430 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6431 BGP_ADDPATH_NONE);
6432
6433 return CMD_SUCCESS;
06370dac
DW
6434}
6435
d62a17ae 6436ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6437 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6438 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6439 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6440 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6441
2b31007c
RZ
6442DEFPY(
6443 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
6444 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
6445 NEIGHBOR_STR
6446 NEIGHBOR_ADDR_STR2
6447 "Detect AS loops before sending to neighbor\n")
6448{
6449 struct peer *peer;
6450
6451 peer = peer_and_group_lookup_vty(vty, neighbor);
6452 if (!peer)
6453 return CMD_WARNING_CONFIG_FAILED;
6454
6455 peer->as_path_loop_detection = true;
6456
6457 return CMD_SUCCESS;
6458}
6459
6460DEFPY(
6461 no_neighbor_aspath_loop_detection,
6462 no_neighbor_aspath_loop_detection_cmd,
6463 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
6464 NO_STR
6465 NEIGHBOR_STR
6466 NEIGHBOR_ADDR_STR2
6467 "Detect AS loops before sending to neighbor\n")
6468{
6469 struct peer *peer;
6470
6471 peer = peer_and_group_lookup_vty(vty, neighbor);
6472 if (!peer)
6473 return CMD_WARNING_CONFIG_FAILED;
6474
6475 peer->as_path_loop_detection = false;
6476
6477 return CMD_SUCCESS;
6478}
6479
b9c7bc5a
PZ
6480static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6481 struct ecommunity **list)
ddb5b488 6482{
b9c7bc5a
PZ
6483 struct ecommunity *ecom = NULL;
6484 struct ecommunity *ecomadd;
ddb5b488 6485
b9c7bc5a 6486 for (; argc; --argc, ++argv) {
ddb5b488 6487
b9c7bc5a
PZ
6488 ecomadd = ecommunity_str2com(argv[0]->arg,
6489 ECOMMUNITY_ROUTE_TARGET, 0);
6490 if (!ecomadd) {
6491 vty_out(vty, "Malformed community-list value\n");
6492 if (ecom)
6493 ecommunity_free(&ecom);
6494 return CMD_WARNING_CONFIG_FAILED;
6495 }
ddb5b488 6496
b9c7bc5a
PZ
6497 if (ecom) {
6498 ecommunity_merge(ecom, ecomadd);
6499 ecommunity_free(&ecomadd);
6500 } else {
6501 ecom = ecomadd;
6502 }
6503 }
6504
6505 if (*list) {
6506 ecommunity_free(&*list);
ddb5b488 6507 }
b9c7bc5a
PZ
6508 *list = ecom;
6509
6510 return CMD_SUCCESS;
ddb5b488
PZ
6511}
6512
0ca70ba5
DS
6513/*
6514 * v2vimport is true if we are handling a `import vrf ...` command
6515 */
6516static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6517{
0ca70ba5
DS
6518 afi_t afi;
6519
ddb5b488 6520 switch (vty->node) {
b9c7bc5a 6521 case BGP_IPV4_NODE:
0ca70ba5
DS
6522 afi = AFI_IP;
6523 break;
b9c7bc5a 6524 case BGP_IPV6_NODE:
0ca70ba5
DS
6525 afi = AFI_IP6;
6526 break;
ddb5b488
PZ
6527 default:
6528 vty_out(vty,
b9c7bc5a 6529 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6530 return AFI_MAX;
ddb5b488 6531 }
69b07479 6532
0ca70ba5
DS
6533 if (!v2vimport) {
6534 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6535 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6536 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6537 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6538 vty_out(vty,
6539 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6540 return AFI_MAX;
6541 }
6542 } else {
6543 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6544 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6545 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6546 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6547 vty_out(vty,
6548 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6549 return AFI_MAX;
6550 }
6551 }
6552 return afi;
ddb5b488
PZ
6553}
6554
b9c7bc5a
PZ
6555DEFPY (af_rd_vpn_export,
6556 af_rd_vpn_export_cmd,
6557 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6558 NO_STR
ddb5b488 6559 "Specify route distinguisher\n"
b9c7bc5a
PZ
6560 "Between current address-family and vpn\n"
6561 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6562 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6563{
6564 VTY_DECLVAR_CONTEXT(bgp, bgp);
6565 struct prefix_rd prd;
6566 int ret;
ddb5b488 6567 afi_t afi;
b9c7bc5a
PZ
6568 int idx = 0;
6569 int yes = 1;
ddb5b488 6570
b9c7bc5a 6571 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6572 yes = 0;
b9c7bc5a
PZ
6573
6574 if (yes) {
6575 ret = str2prefix_rd(rd_str, &prd);
6576 if (!ret) {
6577 vty_out(vty, "%% Malformed rd\n");
6578 return CMD_WARNING_CONFIG_FAILED;
6579 }
ddb5b488
PZ
6580 }
6581
0ca70ba5 6582 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6583 if (afi == AFI_MAX)
6584 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6585
69b07479
DS
6586 /*
6587 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6588 */
6589 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6590 bgp_get_default(), bgp);
ddb5b488 6591
69b07479
DS
6592 if (yes) {
6593 bgp->vpn_policy[afi].tovpn_rd = prd;
6594 SET_FLAG(bgp->vpn_policy[afi].flags,
6595 BGP_VPN_POLICY_TOVPN_RD_SET);
6596 } else {
6597 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6598 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6599 }
6600
69b07479
DS
6601 /* post-change: re-export vpn routes */
6602 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6603 bgp_get_default(), bgp);
6604
ddb5b488
PZ
6605 return CMD_SUCCESS;
6606}
6607
b9c7bc5a
PZ
6608ALIAS (af_rd_vpn_export,
6609 af_no_rd_vpn_export_cmd,
6610 "no rd vpn export",
ddb5b488 6611 NO_STR
b9c7bc5a
PZ
6612 "Specify route distinguisher\n"
6613 "Between current address-family and vpn\n"
6614 "For routes leaked from current address-family to vpn\n")
ddb5b488 6615
b9c7bc5a
PZ
6616DEFPY (af_label_vpn_export,
6617 af_label_vpn_export_cmd,
e70e9f8e 6618 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6619 NO_STR
ddb5b488 6620 "label value for VRF\n"
b9c7bc5a
PZ
6621 "Between current address-family and vpn\n"
6622 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6623 "Label Value <0-1048575>\n"
6624 "Automatically assign a label\n")
ddb5b488
PZ
6625{
6626 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6627 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6628 afi_t afi;
b9c7bc5a
PZ
6629 int idx = 0;
6630 int yes = 1;
6631
6632 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6633 yes = 0;
ddb5b488 6634
21a16cc2
PZ
6635 /* If "no ...", squash trailing parameter */
6636 if (!yes)
6637 label_auto = NULL;
6638
e70e9f8e
PZ
6639 if (yes) {
6640 if (!label_auto)
6641 label = label_val; /* parser should force unsigned */
6642 }
ddb5b488 6643
0ca70ba5 6644 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6645 if (afi == AFI_MAX)
6646 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6647
e70e9f8e 6648
69b07479
DS
6649 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6650 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6651 /* no change */
6652 return CMD_SUCCESS;
e70e9f8e 6653
69b07479
DS
6654 /*
6655 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6656 */
6657 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6658 bgp_get_default(), bgp);
6659
6660 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6661 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6662
6663 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6664
6665 /*
6666 * label has previously been automatically
6667 * assigned by labelpool: release it
6668 *
6669 * NB if tovpn_label == MPLS_LABEL_NONE it
6670 * means the automatic assignment is in flight
6671 * and therefore the labelpool callback must
6672 * detect that the auto label is not needed.
6673 */
6674
6675 bgp_lp_release(LP_TYPE_VRF,
6676 &bgp->vpn_policy[afi],
6677 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6678 }
69b07479
DS
6679 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6680 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6681 }
ddb5b488 6682
69b07479
DS
6683 bgp->vpn_policy[afi].tovpn_label = label;
6684 if (label_auto) {
6685 SET_FLAG(bgp->vpn_policy[afi].flags,
6686 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6687 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6688 vpn_leak_label_callback);
ddb5b488
PZ
6689 }
6690
69b07479
DS
6691 /* post-change: re-export vpn routes */
6692 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6693 bgp_get_default(), bgp);
6694
ddb5b488
PZ
6695 return CMD_SUCCESS;
6696}
6697
b9c7bc5a
PZ
6698ALIAS (af_label_vpn_export,
6699 af_no_label_vpn_export_cmd,
6700 "no label vpn export",
6701 NO_STR
6702 "label value for VRF\n"
6703 "Between current address-family and vpn\n"
6704 "For routes leaked from current address-family to vpn\n")
ddb5b488 6705
b9c7bc5a
PZ
6706DEFPY (af_nexthop_vpn_export,
6707 af_nexthop_vpn_export_cmd,
6708 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6709 NO_STR
ddb5b488 6710 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6711 "Between current address-family and vpn\n"
6712 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6713 "IPv4 prefix\n"
6714 "IPv6 prefix\n")
6715{
6716 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6717 afi_t afi;
ddb5b488 6718 struct prefix p;
b9c7bc5a
PZ
6719 int idx = 0;
6720 int yes = 1;
ddb5b488 6721
b9c7bc5a 6722 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6723 yes = 0;
b9c7bc5a
PZ
6724
6725 if (yes) {
6726 if (!sockunion2hostprefix(nexthop_str, &p))
6727 return CMD_WARNING_CONFIG_FAILED;
6728 }
ddb5b488 6729
0ca70ba5 6730 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6731 if (afi == AFI_MAX)
6732 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6733
69b07479
DS
6734 /*
6735 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6736 */
6737 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6738 bgp_get_default(), bgp);
ddb5b488 6739
69b07479
DS
6740 if (yes) {
6741 bgp->vpn_policy[afi].tovpn_nexthop = p;
6742 SET_FLAG(bgp->vpn_policy[afi].flags,
6743 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6744 } else {
6745 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6746 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6747 }
6748
69b07479
DS
6749 /* post-change: re-export vpn routes */
6750 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6751 bgp_get_default(), bgp);
6752
ddb5b488
PZ
6753 return CMD_SUCCESS;
6754}
6755
b9c7bc5a
PZ
6756ALIAS (af_nexthop_vpn_export,
6757 af_no_nexthop_vpn_export_cmd,
6758 "no nexthop vpn export",
ddb5b488 6759 NO_STR
b9c7bc5a
PZ
6760 "Specify next hop to use for VRF advertised prefixes\n"
6761 "Between current address-family and vpn\n"
6762 "For routes leaked from current address-family to vpn\n")
ddb5b488 6763
b9c7bc5a 6764static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6765{
b9c7bc5a
PZ
6766 if (!strcmp(dstr, "import")) {
6767 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6768 } else if (!strcmp(dstr, "export")) {
6769 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6770 } else if (!strcmp(dstr, "both")) {
6771 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6772 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6773 } else {
6774 vty_out(vty, "%% direction parse error\n");
6775 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6776 }
ddb5b488
PZ
6777 return CMD_SUCCESS;
6778}
6779
b9c7bc5a
PZ
6780DEFPY (af_rt_vpn_imexport,
6781 af_rt_vpn_imexport_cmd,
6782 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6783 NO_STR
6784 "Specify route target list\n"
ddb5b488 6785 "Specify route target list\n"
b9c7bc5a
PZ
6786 "Between current address-family and vpn\n"
6787 "For routes leaked from vpn to current address-family: match any\n"
6788 "For routes leaked from current address-family to vpn: set\n"
6789 "both import: match any and export: set\n"
ddb5b488
PZ
6790 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6791{
6792 VTY_DECLVAR_CONTEXT(bgp, bgp);
6793 int ret;
6794 struct ecommunity *ecom = NULL;
6795 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6796 vpn_policy_direction_t dir;
6797 afi_t afi;
6798 int idx = 0;
b9c7bc5a 6799 int yes = 1;
ddb5b488 6800
b9c7bc5a 6801 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6802 yes = 0;
b9c7bc5a 6803
0ca70ba5 6804 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6805 if (afi == AFI_MAX)
6806 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6807
b9c7bc5a 6808 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6809 if (ret != CMD_SUCCESS)
6810 return ret;
6811
b9c7bc5a
PZ
6812 if (yes) {
6813 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6814 vty_out(vty, "%% Missing RTLIST\n");
6815 return CMD_WARNING_CONFIG_FAILED;
6816 }
6817 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6818 if (ret != CMD_SUCCESS) {
6819 return ret;
6820 }
ddb5b488
PZ
6821 }
6822
69b07479
DS
6823 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6824 if (!dodir[dir])
ddb5b488 6825 continue;
ddb5b488 6826
69b07479 6827 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6828
69b07479
DS
6829 if (yes) {
6830 if (bgp->vpn_policy[afi].rtlist[dir])
6831 ecommunity_free(
6832 &bgp->vpn_policy[afi].rtlist[dir]);
6833 bgp->vpn_policy[afi].rtlist[dir] =
6834 ecommunity_dup(ecom);
6835 } else {
6836 if (bgp->vpn_policy[afi].rtlist[dir])
6837 ecommunity_free(
6838 &bgp->vpn_policy[afi].rtlist[dir]);
6839 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6840 }
69b07479
DS
6841
6842 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6843 }
69b07479 6844
d555f3e9
PZ
6845 if (ecom)
6846 ecommunity_free(&ecom);
ddb5b488
PZ
6847
6848 return CMD_SUCCESS;
6849}
6850
b9c7bc5a
PZ
6851ALIAS (af_rt_vpn_imexport,
6852 af_no_rt_vpn_imexport_cmd,
6853 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6854 NO_STR
6855 "Specify route target list\n"
b9c7bc5a
PZ
6856 "Specify route target list\n"
6857 "Between current address-family and vpn\n"
6858 "For routes leaked from vpn to current address-family\n"
6859 "For routes leaked from current address-family to vpn\n"
6860 "both import and export\n")
6861
6862DEFPY (af_route_map_vpn_imexport,
6863 af_route_map_vpn_imexport_cmd,
6864/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6865 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6866 NO_STR
ddb5b488 6867 "Specify route map\n"
b9c7bc5a
PZ
6868 "Between current address-family and vpn\n"
6869 "For routes leaked from vpn to current address-family\n"
6870 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6871 "name of route-map\n")
6872{
6873 VTY_DECLVAR_CONTEXT(bgp, bgp);
6874 int ret;
6875 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6876 vpn_policy_direction_t dir;
6877 afi_t afi;
ddb5b488 6878 int idx = 0;
b9c7bc5a 6879 int yes = 1;
ddb5b488 6880
b9c7bc5a 6881 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6882 yes = 0;
b9c7bc5a 6883
0ca70ba5 6884 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6885 if (afi == AFI_MAX)
6886 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6887
b9c7bc5a 6888 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6889 if (ret != CMD_SUCCESS)
6890 return ret;
6891
69b07479
DS
6892 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6893 if (!dodir[dir])
ddb5b488 6894 continue;
ddb5b488 6895
69b07479 6896 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6897
69b07479
DS
6898 if (yes) {
6899 if (bgp->vpn_policy[afi].rmap_name[dir])
6900 XFREE(MTYPE_ROUTE_MAP_NAME,
6901 bgp->vpn_policy[afi].rmap_name[dir]);
6902 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6903 MTYPE_ROUTE_MAP_NAME, rmap_str);
6904 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6905 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6906 if (!bgp->vpn_policy[afi].rmap[dir])
6907 return CMD_SUCCESS;
6908 } else {
6909 if (bgp->vpn_policy[afi].rmap_name[dir])
6910 XFREE(MTYPE_ROUTE_MAP_NAME,
6911 bgp->vpn_policy[afi].rmap_name[dir]);
6912 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6913 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6914 }
69b07479
DS
6915
6916 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6917 }
6918
6919 return CMD_SUCCESS;
6920}
6921
b9c7bc5a
PZ
6922ALIAS (af_route_map_vpn_imexport,
6923 af_no_route_map_vpn_imexport_cmd,
6924 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6925 NO_STR
6926 "Specify route map\n"
b9c7bc5a
PZ
6927 "Between current address-family and vpn\n"
6928 "For routes leaked from vpn to current address-family\n"
6929 "For routes leaked from current address-family to vpn\n")
6930
bb4f6190
DS
6931DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6932 "[no] import vrf route-map RMAP$rmap_str",
6933 NO_STR
6934 "Import routes from another VRF\n"
6935 "Vrf routes being filtered\n"
6936 "Specify route map\n"
6937 "name of route-map\n")
6938{
6939 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6940 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6941 afi_t afi;
6942 int idx = 0;
6943 int yes = 1;
6944 struct bgp *bgp_default;
6945
6946 if (argv_find(argv, argc, "no", &idx))
6947 yes = 0;
6948
0ca70ba5 6949 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6950 if (afi == AFI_MAX)
6951 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6952
6953 bgp_default = bgp_get_default();
6954 if (!bgp_default) {
6955 int32_t ret;
6956 as_t as = bgp->as;
6957
6958 /* Auto-create assuming the same AS */
6959 ret = bgp_get(&bgp_default, &as, NULL,
6960 BGP_INSTANCE_TYPE_DEFAULT);
6961
6962 if (ret) {
6963 vty_out(vty,
6964 "VRF default is not configured as a bgp instance\n");
6965 return CMD_WARNING;
6966 }
6967 }
6968
69b07479 6969 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6970
69b07479
DS
6971 if (yes) {
6972 if (bgp->vpn_policy[afi].rmap_name[dir])
6973 XFREE(MTYPE_ROUTE_MAP_NAME,
6974 bgp->vpn_policy[afi].rmap_name[dir]);
6975 bgp->vpn_policy[afi].rmap_name[dir] =
6976 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6977 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6978 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6979 if (!bgp->vpn_policy[afi].rmap[dir])
6980 return CMD_SUCCESS;
6981 } else {
6982 if (bgp->vpn_policy[afi].rmap_name[dir])
6983 XFREE(MTYPE_ROUTE_MAP_NAME,
6984 bgp->vpn_policy[afi].rmap_name[dir]);
6985 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6986 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6987 }
6988
69b07479
DS
6989 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6990
bb4f6190
DS
6991 return CMD_SUCCESS;
6992}
6993
6994ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6995 "no import vrf route-map",
6996 NO_STR
6997 "Import routes from another VRF\n"
6998 "Vrf routes being filtered\n"
6999 "Specify route map\n")
7000
4d1b335c
DA
7001DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
7002 "[no] import vrf VIEWVRFNAME$import_name",
7003 NO_STR
7004 "Import routes from another VRF\n"
7005 "VRF to import from\n"
7006 "The name of the VRF\n")
12a844a5
DS
7007{
7008 VTY_DECLVAR_CONTEXT(bgp, bgp);
7009 struct listnode *node;
79ef8664
DS
7010 struct bgp *vrf_bgp, *bgp_default;
7011 int32_t ret = 0;
7012 as_t as = bgp->as;
12a844a5
DS
7013 bool remove = false;
7014 int32_t idx = 0;
7015 char *vname;
a8dadcf6 7016 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
7017 safi_t safi;
7018 afi_t afi;
7019
867f0cca 7020 if (import_name == NULL) {
7021 vty_out(vty, "%% Missing import name\n");
7022 return CMD_WARNING;
7023 }
7024
12a844a5
DS
7025 if (argv_find(argv, argc, "no", &idx))
7026 remove = true;
7027
0ca70ba5
DS
7028 afi = vpn_policy_getafi(vty, bgp, true);
7029 if (afi == AFI_MAX)
7030 return CMD_WARNING_CONFIG_FAILED;
7031
12a844a5
DS
7032 safi = bgp_node_safi(vty);
7033
25679caa 7034 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 7035 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
7036 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
7037 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
7038 remove ? "unimport" : "import", import_name);
7039 return CMD_WARNING;
7040 }
7041
79ef8664
DS
7042 bgp_default = bgp_get_default();
7043 if (!bgp_default) {
7044 /* Auto-create assuming the same AS */
7045 ret = bgp_get(&bgp_default, &as, NULL,
7046 BGP_INSTANCE_TYPE_DEFAULT);
7047
7048 if (ret) {
7049 vty_out(vty,
7050 "VRF default is not configured as a bgp instance\n");
7051 return CMD_WARNING;
7052 }
7053 }
7054
12a844a5
DS
7055 vrf_bgp = bgp_lookup_by_name(import_name);
7056 if (!vrf_bgp) {
5742e42b 7057 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
7058 vrf_bgp = bgp_default;
7059 else
0fb8d6e6
DS
7060 /* Auto-create assuming the same AS */
7061 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 7062
6e2c7fe6 7063 if (ret) {
020a3f60
DS
7064 vty_out(vty,
7065 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
7066 import_name);
7067 return CMD_WARNING;
7068 }
12a844a5
DS
7069 }
7070
12a844a5 7071 if (remove) {
44338987 7072 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 7073 } else {
44338987 7074 /* Already importing from "import_vrf"? */
12a844a5
DS
7075 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7076 vname)) {
7077 if (strcmp(vname, import_name) == 0)
7078 return CMD_WARNING;
7079 }
7080
44338987 7081 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
7082 }
7083
7084 return CMD_SUCCESS;
7085}
7086
b9c7bc5a
PZ
7087/* This command is valid only in a bgp vrf instance or the default instance */
7088DEFPY (bgp_imexport_vpn,
7089 bgp_imexport_vpn_cmd,
7090 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
7091 NO_STR
7092 "Import routes to this address-family\n"
7093 "Export routes from this address-family\n"
7094 "to/from default instance VPN RIB\n")
ddb5b488
PZ
7095{
7096 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7097 int previous_state;
ddb5b488 7098 afi_t afi;
b9c7bc5a 7099 safi_t safi;
ddb5b488 7100 int idx = 0;
b9c7bc5a
PZ
7101 int yes = 1;
7102 int flag;
7103 vpn_policy_direction_t dir;
ddb5b488 7104
b9c7bc5a 7105 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7106 yes = 0;
ddb5b488 7107
b9c7bc5a
PZ
7108 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7109 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 7110
b9c7bc5a
PZ
7111 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7112 return CMD_WARNING_CONFIG_FAILED;
7113 }
ddb5b488 7114
b9c7bc5a
PZ
7115 afi = bgp_node_afi(vty);
7116 safi = bgp_node_safi(vty);
7117 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7118 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7119 return CMD_WARNING_CONFIG_FAILED;
7120 }
ddb5b488 7121
b9c7bc5a
PZ
7122 if (!strcmp(direction_str, "import")) {
7123 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7124 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7125 } else if (!strcmp(direction_str, "export")) {
7126 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7127 dir = BGP_VPN_POLICY_DIR_TOVPN;
7128 } else {
7129 vty_out(vty, "%% unknown direction %s\n", direction_str);
7130 return CMD_WARNING_CONFIG_FAILED;
7131 }
7132
7133 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 7134
b9c7bc5a
PZ
7135 if (yes) {
7136 SET_FLAG(bgp->af_flags[afi][safi], flag);
7137 if (!previous_state) {
7138 /* trigger export current vrf */
ddb5b488
PZ
7139 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7140 }
b9c7bc5a
PZ
7141 } else {
7142 if (previous_state) {
7143 /* trigger un-export current vrf */
7144 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7145 }
7146 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
7147 }
7148
7149 return CMD_SUCCESS;
7150}
7151
301ad80a
PG
7152DEFPY (af_routetarget_import,
7153 af_routetarget_import_cmd,
7154 "[no] <rt|route-target> redirect import RTLIST...",
7155 NO_STR
7156 "Specify route target list\n"
7157 "Specify route target list\n"
7158 "Flow-spec redirect type route target\n"
7159 "Import routes to this address-family\n"
7160 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7161{
7162 VTY_DECLVAR_CONTEXT(bgp, bgp);
7163 int ret;
7164 struct ecommunity *ecom = NULL;
301ad80a
PG
7165 afi_t afi;
7166 int idx = 0;
7167 int yes = 1;
7168
7169 if (argv_find(argv, argc, "no", &idx))
7170 yes = 0;
7171
0ca70ba5 7172 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7173 if (afi == AFI_MAX)
7174 return CMD_WARNING_CONFIG_FAILED;
7175
301ad80a
PG
7176 if (yes) {
7177 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7178 vty_out(vty, "%% Missing RTLIST\n");
7179 return CMD_WARNING_CONFIG_FAILED;
7180 }
7181 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7182 if (ret != CMD_SUCCESS)
7183 return ret;
7184 }
69b07479
DS
7185
7186 if (yes) {
7187 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7188 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7189 .import_redirect_rtlist);
69b07479
DS
7190 bgp->vpn_policy[afi].import_redirect_rtlist =
7191 ecommunity_dup(ecom);
7192 } else {
7193 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7194 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7195 .import_redirect_rtlist);
69b07479 7196 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 7197 }
69b07479 7198
301ad80a
PG
7199 if (ecom)
7200 ecommunity_free(&ecom);
7201
7202 return CMD_SUCCESS;
7203}
7204
505e5056 7205DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 7206 address_family_ipv4_safi_cmd,
7207 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7208 "Enter Address Family command mode\n"
7209 "Address Family\n"
7210 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 7211{
f51bae9c 7212
d62a17ae 7213 if (argc == 3) {
2131d5cf 7214 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7215 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7216 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7217 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7218 && safi != SAFI_EVPN) {
31947174
MK
7219 vty_out(vty,
7220 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7221 return CMD_WARNING_CONFIG_FAILED;
7222 }
d62a17ae 7223 vty->node = bgp_node_type(AFI_IP, safi);
7224 } else
7225 vty->node = BGP_IPV4_NODE;
718e3744 7226
d62a17ae 7227 return CMD_SUCCESS;
718e3744 7228}
7229
505e5056 7230DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 7231 address_family_ipv6_safi_cmd,
7232 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7233 "Enter Address Family command mode\n"
7234 "Address Family\n"
7235 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 7236{
d62a17ae 7237 if (argc == 3) {
2131d5cf 7238 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7239 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7240 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7241 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7242 && safi != SAFI_EVPN) {
31947174
MK
7243 vty_out(vty,
7244 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7245 return CMD_WARNING_CONFIG_FAILED;
7246 }
d62a17ae 7247 vty->node = bgp_node_type(AFI_IP6, safi);
7248 } else
7249 vty->node = BGP_IPV6_NODE;
25ffbdc1 7250
d62a17ae 7251 return CMD_SUCCESS;
25ffbdc1 7252}
718e3744 7253
d6902373 7254#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7255DEFUN_NOSH (address_family_vpnv4,
718e3744 7256 address_family_vpnv4_cmd,
8334fd5a 7257 "address-family vpnv4 [unicast]",
718e3744 7258 "Enter Address Family command mode\n"
8c3deaae 7259 "Address Family\n"
3a2d747c 7260 "Address Family modifier\n")
718e3744 7261{
d62a17ae 7262 vty->node = BGP_VPNV4_NODE;
7263 return CMD_SUCCESS;
718e3744 7264}
7265
505e5056 7266DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7267 address_family_vpnv6_cmd,
8334fd5a 7268 "address-family vpnv6 [unicast]",
8ecd3266 7269 "Enter Address Family command mode\n"
8c3deaae 7270 "Address Family\n"
3a2d747c 7271 "Address Family modifier\n")
8ecd3266 7272{
d62a17ae 7273 vty->node = BGP_VPNV6_NODE;
7274 return CMD_SUCCESS;
8ecd3266 7275}
64e4a6c5 7276#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 7277
505e5056 7278DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7279 address_family_evpn_cmd,
7111c1a0 7280 "address-family l2vpn evpn",
4e0b7b6d 7281 "Enter Address Family command mode\n"
7111c1a0
QY
7282 "Address Family\n"
7283 "Address Family modifier\n")
4e0b7b6d 7284{
2131d5cf 7285 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7286 vty->node = BGP_EVPN_NODE;
7287 return CMD_SUCCESS;
4e0b7b6d
PG
7288}
7289
505e5056 7290DEFUN_NOSH (exit_address_family,
718e3744 7291 exit_address_family_cmd,
7292 "exit-address-family",
7293 "Exit from Address Family configuration mode\n")
7294{
d62a17ae 7295 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7296 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7297 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7298 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7299 || vty->node == BGP_EVPN_NODE
7300 || vty->node == BGP_FLOWSPECV4_NODE
7301 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7302 vty->node = BGP_NODE;
7303 return CMD_SUCCESS;
718e3744 7304}
6b0655a2 7305
8ad7271d 7306/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7307static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7308 const char *ip_str, afi_t afi, safi_t safi,
7309 struct prefix_rd *prd)
7310{
7311 int ret;
7312 struct prefix match;
7313 struct bgp_node *rn;
7314 struct bgp_node *rm;
7315 struct bgp *bgp;
7316 struct bgp_table *table;
7317 struct bgp_table *rib;
7318
7319 /* BGP structure lookup. */
7320 if (view_name) {
7321 bgp = bgp_lookup_by_name(view_name);
7322 if (bgp == NULL) {
7323 vty_out(vty, "%% Can't find BGP instance %s\n",
7324 view_name);
7325 return CMD_WARNING;
7326 }
7327 } else {
7328 bgp = bgp_get_default();
7329 if (bgp == NULL) {
7330 vty_out(vty, "%% No BGP process is configured\n");
7331 return CMD_WARNING;
7332 }
7333 }
7334
7335 /* Check IP address argument. */
7336 ret = str2prefix(ip_str, &match);
7337 if (!ret) {
7338 vty_out(vty, "%% address is malformed\n");
7339 return CMD_WARNING;
7340 }
7341
7342 match.family = afi2family(afi);
7343 rib = bgp->rib[afi][safi];
7344
7345 if (safi == SAFI_MPLS_VPN) {
7346 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7347 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7348 continue;
7349
67009e22
DS
7350 table = bgp_node_get_bgp_table_info(rn);
7351 if (table != NULL) {
7352
d62a17ae 7353 if ((rm = bgp_node_match(table, &match))
7354 != NULL) {
7355 if (rm->p.prefixlen
7356 == match.prefixlen) {
343cdb61 7357 SET_FLAG(rm->flags,
d62a17ae 7358 BGP_NODE_USER_CLEAR);
7359 bgp_process(bgp, rm, afi, safi);
7360 }
7361 bgp_unlock_node(rm);
7362 }
7363 }
7364 }
7365 } else {
7366 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7367 if (rn->p.prefixlen == match.prefixlen) {
7368 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7369 bgp_process(bgp, rn, afi, safi);
7370 }
7371 bgp_unlock_node(rn);
7372 }
7373 }
7374
7375 return CMD_SUCCESS;
8ad7271d
DS
7376}
7377
b09b5ae0 7378/* one clear bgp command to rule them all */
718e3744 7379DEFUN (clear_ip_bgp_all,
7380 clear_ip_bgp_all_cmd,
453c92f6 7381 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out>]",
718e3744 7382 CLEAR_STR
7383 IP_STR
7384 BGP_STR
838758ac 7385 BGP_INSTANCE_HELP_STR
510afcd6 7386 BGP_AFI_HELP_STR
fd5e7b70 7387 "Address Family\n"
510afcd6 7388 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 7389 "Address Family modifier\n"
b09b5ae0 7390 "Clear all peers\n"
453c92f6 7391 "BGP IPv4 neighbor to clear\n"
a80beece 7392 "BGP IPv6 neighbor to clear\n"
838758ac 7393 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7394 "Clear peers with the AS number\n"
7395 "Clear all external peers\n"
718e3744 7396 "Clear all members of peer-group\n"
b09b5ae0 7397 "BGP peer-group name\n"
b09b5ae0
DW
7398 BGP_SOFT_STR
7399 BGP_SOFT_IN_STR
b09b5ae0
DW
7400 BGP_SOFT_OUT_STR
7401 BGP_SOFT_IN_STR
7402 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7403 BGP_SOFT_OUT_STR)
718e3744 7404{
d62a17ae 7405 char *vrf = NULL;
7406
dc912615
DS
7407 afi_t afi = AFI_UNSPEC;
7408 safi_t safi = SAFI_UNSPEC;
d62a17ae 7409 enum clear_sort clr_sort = clear_peer;
7410 enum bgp_clear_type clr_type;
7411 char *clr_arg = NULL;
7412
7413 int idx = 0;
7414
7415 /* clear [ip] bgp */
7416 if (argv_find(argv, argc, "ip", &idx))
7417 afi = AFI_IP;
7418
9a8bdf1c
PG
7419 /* [<vrf> VIEWVRFNAME] */
7420 if (argv_find(argv, argc, "vrf", &idx)) {
7421 vrf = argv[idx + 1]->arg;
7422 idx += 2;
7423 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7424 vrf = NULL;
7425 } else if (argv_find(argv, argc, "view", &idx)) {
7426 /* [<view> VIEWVRFNAME] */
d62a17ae 7427 vrf = argv[idx + 1]->arg;
7428 idx += 2;
7429 }
d62a17ae 7430 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7431 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7432 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7433
d7b9898c 7434 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 7435 if (argv_find(argv, argc, "*", &idx)) {
7436 clr_sort = clear_all;
7437 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7438 clr_sort = clear_peer;
7439 clr_arg = argv[idx]->arg;
7440 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7441 clr_sort = clear_peer;
7442 clr_arg = argv[idx]->arg;
7443 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7444 clr_sort = clear_group;
7445 idx++;
7446 clr_arg = argv[idx]->arg;
d7b9898c 7447 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 7448 clr_sort = clear_peer;
7449 clr_arg = argv[idx]->arg;
8fa7d444
DS
7450 } else if (argv_find(argv, argc, "WORD", &idx)) {
7451 clr_sort = clear_peer;
7452 clr_arg = argv[idx]->arg;
d62a17ae 7453 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7454 clr_sort = clear_as;
7455 clr_arg = argv[idx]->arg;
7456 } else if (argv_find(argv, argc, "external", &idx)) {
7457 clr_sort = clear_external;
7458 }
7459
7460 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7461 if (argv_find(argv, argc, "soft", &idx)) {
7462 if (argv_find(argv, argc, "in", &idx)
7463 || argv_find(argv, argc, "out", &idx))
7464 clr_type = strmatch(argv[idx]->text, "in")
7465 ? BGP_CLEAR_SOFT_IN
7466 : BGP_CLEAR_SOFT_OUT;
7467 else
7468 clr_type = BGP_CLEAR_SOFT_BOTH;
7469 } else if (argv_find(argv, argc, "in", &idx)) {
7470 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7471 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7472 : BGP_CLEAR_SOFT_IN;
7473 } else if (argv_find(argv, argc, "out", &idx)) {
7474 clr_type = BGP_CLEAR_SOFT_OUT;
7475 } else
7476 clr_type = BGP_CLEAR_SOFT_NONE;
7477
7478 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7479}
01080f7c 7480
8ad7271d
DS
7481DEFUN (clear_ip_bgp_prefix,
7482 clear_ip_bgp_prefix_cmd,
18c57037 7483 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7484 CLEAR_STR
7485 IP_STR
7486 BGP_STR
838758ac 7487 BGP_INSTANCE_HELP_STR
8ad7271d 7488 "Clear bestpath and re-advertise\n"
0c7b1b01 7489 "IPv4 prefix\n")
8ad7271d 7490{
d62a17ae 7491 char *vrf = NULL;
7492 char *prefix = NULL;
8ad7271d 7493
d62a17ae 7494 int idx = 0;
01080f7c 7495
d62a17ae 7496 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
7497 if (argv_find(argv, argc, "vrf", &idx)) {
7498 vrf = argv[idx + 1]->arg;
7499 idx += 2;
7500 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7501 vrf = NULL;
7502 } else if (argv_find(argv, argc, "view", &idx)) {
7503 /* [<view> VIEWVRFNAME] */
7504 vrf = argv[idx + 1]->arg;
7505 idx += 2;
7506 }
0c7b1b01 7507
d62a17ae 7508 prefix = argv[argc - 1]->arg;
8ad7271d 7509
d62a17ae 7510 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7511}
8ad7271d 7512
b09b5ae0
DW
7513DEFUN (clear_bgp_ipv6_safi_prefix,
7514 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7515 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7516 CLEAR_STR
3a2d747c 7517 IP_STR
718e3744 7518 BGP_STR
8c3deaae 7519 "Address Family\n"
46f296b4 7520 BGP_SAFI_HELP_STR
b09b5ae0 7521 "Clear bestpath and re-advertise\n"
0c7b1b01 7522 "IPv6 prefix\n")
718e3744 7523{
9b475e76
PG
7524 int idx_safi = 0;
7525 int idx_ipv6_prefix = 0;
7526 safi_t safi = SAFI_UNICAST;
7527 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7528 argv[idx_ipv6_prefix]->arg : NULL;
7529
7530 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7531 return bgp_clear_prefix(
9b475e76
PG
7532 vty, NULL, prefix, AFI_IP6,
7533 safi, NULL);
838758ac 7534}
01080f7c 7535
b09b5ae0
DW
7536DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7537 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7538 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7539 CLEAR_STR
3a2d747c 7540 IP_STR
718e3744 7541 BGP_STR
838758ac 7542 BGP_INSTANCE_HELP_STR
8c3deaae 7543 "Address Family\n"
46f296b4 7544 BGP_SAFI_HELP_STR
b09b5ae0 7545 "Clear bestpath and re-advertise\n"
0c7b1b01 7546 "IPv6 prefix\n")
718e3744 7547{
9b475e76 7548 int idx_safi = 0;
9a8bdf1c 7549 int idx_vrfview = 0;
9b475e76
PG
7550 int idx_ipv6_prefix = 0;
7551 safi_t safi = SAFI_UNICAST;
7552 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7553 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 7554 char *vrfview = NULL;
9b475e76 7555
9a8bdf1c
PG
7556 /* [<view|vrf> VIEWVRFNAME] */
7557 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7558 vrfview = argv[idx_vrfview + 1]->arg;
7559 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7560 vrfview = NULL;
7561 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7562 /* [<view> VIEWVRFNAME] */
7563 vrfview = argv[idx_vrfview + 1]->arg;
7564 }
9b475e76
PG
7565 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7566
d62a17ae 7567 return bgp_clear_prefix(
9b475e76
PG
7568 vty, vrfview, prefix,
7569 AFI_IP6, safi, NULL);
718e3744 7570}
7571
b09b5ae0
DW
7572DEFUN (show_bgp_views,
7573 show_bgp_views_cmd,
d6e3c605 7574 "show [ip] bgp views",
b09b5ae0 7575 SHOW_STR
d6e3c605 7576 IP_STR
01080f7c 7577 BGP_STR
b09b5ae0 7578 "Show the defined BGP views\n")
01080f7c 7579{
d62a17ae 7580 struct list *inst = bm->bgp;
7581 struct listnode *node;
7582 struct bgp *bgp;
01080f7c 7583
d62a17ae 7584 vty_out(vty, "Defined BGP views:\n");
7585 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7586 /* Skip VRFs. */
7587 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7588 continue;
7589 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7590 bgp->as);
7591 }
e52702f2 7592
d62a17ae 7593 return CMD_SUCCESS;
e0081f70
ML
7594}
7595
8386ac43 7596DEFUN (show_bgp_vrfs,
7597 show_bgp_vrfs_cmd,
d6e3c605 7598 "show [ip] bgp vrfs [json]",
8386ac43 7599 SHOW_STR
d6e3c605 7600 IP_STR
8386ac43 7601 BGP_STR
7602 "Show BGP VRFs\n"
9973d184 7603 JSON_STR)
8386ac43 7604{
fe1dc5a3 7605 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7606 struct list *inst = bm->bgp;
7607 struct listnode *node;
7608 struct bgp *bgp;
9f049418 7609 bool uj = use_json(argc, argv);
d62a17ae 7610 json_object *json = NULL;
7611 json_object *json_vrfs = NULL;
7612 int count = 0;
d62a17ae 7613
d62a17ae 7614 if (uj) {
7615 json = json_object_new_object();
7616 json_vrfs = json_object_new_object();
7617 }
7618
7619 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7620 const char *name, *type;
7621 struct peer *peer;
7fe96307 7622 struct listnode *node2, *nnode2;
d62a17ae 7623 int peers_cfg, peers_estb;
7624 json_object *json_vrf = NULL;
d62a17ae 7625
7626 /* Skip Views. */
7627 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7628 continue;
7629
7630 count++;
efb4077a 7631 if (!uj && count == 1) {
fe1dc5a3 7632 vty_out(vty,
efb4077a 7633 "%4s %-5s %-16s %9s %10s %-37s\n",
a4d82a8a 7634 "Type", "Id", "routerId", "#PeersVfg",
efb4077a
CS
7635 "#PeersEstb", "Name");
7636 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
7637 "L3-VNI", "RouterMAC", "Interface");
7638 }
d62a17ae 7639
7640 peers_cfg = peers_estb = 0;
7641 if (uj)
7642 json_vrf = json_object_new_object();
7643
7644
7fe96307 7645 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 7646 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7647 continue;
7648 peers_cfg++;
7649 if (peer->status == Established)
7650 peers_estb++;
7651 }
7652
7653 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 7654 name = VRF_DEFAULT_NAME;
d62a17ae 7655 type = "DFLT";
7656 } else {
7657 name = bgp->name;
7658 type = "VRF";
7659 }
7660
a8bf7d9c 7661
d62a17ae 7662 if (uj) {
a4d82a8a
PZ
7663 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7664 ? -1
7665 : (int64_t)bgp->vrf_id;
d62a17ae 7666 json_object_string_add(json_vrf, "type", type);
7667 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7668 json_object_string_add(json_vrf, "routerId",
7669 inet_ntoa(bgp->router_id));
7670 json_object_int_add(json_vrf, "numConfiguredPeers",
7671 peers_cfg);
7672 json_object_int_add(json_vrf, "numEstablishedPeers",
7673 peers_estb);
7674
fe1dc5a3 7675 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7676 json_object_string_add(
7677 json_vrf, "rmac",
7678 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
7679 json_object_string_add(json_vrf, "interface",
7680 ifindex2ifname(bgp->l3vni_svi_ifindex,
7681 bgp->vrf_id));
d62a17ae 7682 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 7683 } else {
fe1dc5a3 7684 vty_out(vty,
efb4077a 7685 "%4s %-5d %-16s %-9u %-10u %-37s\n",
a4d82a8a
PZ
7686 type,
7687 bgp->vrf_id == VRF_UNKNOWN ? -1
7688 : (int)bgp->vrf_id,
7689 inet_ntoa(bgp->router_id), peers_cfg,
efb4077a
CS
7690 peers_estb, name);
7691 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
7692 bgp->l3vni,
7693 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
7694 ifindex2ifname(bgp->l3vni_svi_ifindex,
7695 bgp->vrf_id));
7696 }
d62a17ae 7697 }
7698
7699 if (uj) {
7700 json_object_object_add(json, "vrfs", json_vrfs);
7701
7702 json_object_int_add(json, "totalVrfs", count);
7703
996c9314
LB
7704 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7705 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7706 json_object_free(json);
7707 } else {
7708 if (count)
7709 vty_out(vty,
7710 "\nTotal number of VRFs (including default): %d\n",
7711 count);
7712 }
7713
7714 return CMD_SUCCESS;
8386ac43 7715}
7716
48ecf8f5
DS
7717DEFUN (show_bgp_mac_hash,
7718 show_bgp_mac_hash_cmd,
7719 "show bgp mac hash",
7720 SHOW_STR
7721 BGP_STR
7722 "Mac Address\n"
7723 "Mac Address database\n")
7724{
7725 bgp_mac_dump_table(vty);
7726
7727 return CMD_SUCCESS;
7728}
acf71666 7729
e3b78da8 7730static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 7731{
0291c246 7732 struct vty *vty = (struct vty *)args;
e3b78da8 7733 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 7734
60466a63 7735 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7736 tip->refcnt);
7737}
7738
7739static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7740{
7741 vty_out(vty, "self nexthop database:\n");
af97a18b 7742 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
7743
7744 vty_out(vty, "Tunnel-ip database:\n");
7745 hash_iterate(bgp->tip_hash,
e3b78da8 7746 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
7747 vty);
7748}
7749
15c81ca4
DS
7750DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7751 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7752 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7753 "martian next-hops\n"
7754 "martian next-hop database\n")
acf71666 7755{
0291c246 7756 struct bgp *bgp = NULL;
15c81ca4 7757 int idx = 0;
9a8bdf1c
PG
7758 char *name = NULL;
7759
7760 /* [<vrf> VIEWVRFNAME] */
7761 if (argv_find(argv, argc, "vrf", &idx)) {
7762 name = argv[idx + 1]->arg;
7763 if (name && strmatch(name, VRF_DEFAULT_NAME))
7764 name = NULL;
7765 } else if (argv_find(argv, argc, "view", &idx))
7766 /* [<view> VIEWVRFNAME] */
7767 name = argv[idx + 1]->arg;
7768 if (name)
7769 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
7770 else
7771 bgp = bgp_get_default();
acf71666 7772
acf71666
MK
7773 if (!bgp) {
7774 vty_out(vty, "%% No BGP process is configured\n");
7775 return CMD_WARNING;
7776 }
7777 bgp_show_martian_nexthops(vty, bgp);
7778
7779 return CMD_SUCCESS;
7780}
7781
f412b39a 7782DEFUN (show_bgp_memory,
4bf6a362 7783 show_bgp_memory_cmd,
7fa12b13 7784 "show [ip] bgp memory",
4bf6a362 7785 SHOW_STR
3a2d747c 7786 IP_STR
4bf6a362
PJ
7787 BGP_STR
7788 "Global BGP memory statistics\n")
7789{
d62a17ae 7790 char memstrbuf[MTYPE_MEMSTR_LEN];
7791 unsigned long count;
7792
7793 /* RIB related usage stats */
7794 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7795 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7796 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7797 count * sizeof(struct bgp_node)));
7798
7799 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7800 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7801 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 7802 count * sizeof(struct bgp_path_info)));
d62a17ae 7803 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7804 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7805 count,
4b7e6066
DS
7806 mtype_memstr(
7807 memstrbuf, sizeof(memstrbuf),
7808 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 7809
7810 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7811 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7812 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7813 count * sizeof(struct bgp_static)));
7814
7815 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7816 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7817 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7818 count * sizeof(struct bpacket)));
7819
7820 /* Adj-In/Out */
7821 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7822 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7823 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7824 count * sizeof(struct bgp_adj_in)));
7825 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7826 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7827 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7828 count * sizeof(struct bgp_adj_out)));
7829
7830 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7831 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7832 count,
7833 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7834 count * sizeof(struct bgp_nexthop_cache)));
7835
7836 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7837 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7838 count,
7839 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7840 count * sizeof(struct bgp_damp_info)));
7841
7842 /* Attributes */
7843 count = attr_count();
7844 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7845 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7846 count * sizeof(struct attr)));
7847
7848 if ((count = attr_unknown_count()))
7849 vty_out(vty, "%ld unknown attributes\n", count);
7850
7851 /* AS_PATH attributes */
7852 count = aspath_count();
7853 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7854 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7855 count * sizeof(struct aspath)));
7856
7857 count = mtype_stats_alloc(MTYPE_AS_SEG);
7858 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7859 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7860 count * sizeof(struct assegment)));
7861
7862 /* Other attributes */
7863 if ((count = community_count()))
7864 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7865 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7866 count * sizeof(struct community)));
d62a17ae 7867 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7868 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7869 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7870 count * sizeof(struct ecommunity)));
d62a17ae 7871 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7872 vty_out(vty,
7873 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7874 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7875 count * sizeof(struct lcommunity)));
d62a17ae 7876
7877 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7878 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7879 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7880 count * sizeof(struct cluster_list)));
7881
7882 /* Peer related usage */
7883 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7884 vty_out(vty, "%ld peers, using %s of memory\n", count,
7885 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7886 count * sizeof(struct peer)));
7887
7888 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7889 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7890 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7891 count * sizeof(struct peer_group)));
7892
7893 /* Other */
d62a17ae 7894 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7895 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7896 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7897 count * sizeof(regex_t)));
d62a17ae 7898 return CMD_SUCCESS;
4bf6a362 7899}
fee0f4c6 7900
57a9c8a8
DS
7901static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7902{
7903 json_object *bestpath = json_object_new_object();
7904
7905 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7906 json_object_string_add(bestpath, "asPath", "ignore");
7907
7908 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7909 json_object_string_add(bestpath, "asPath", "confed");
7910
7911 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7912 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7913 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7914 "as-set");
7915 else
a4d82a8a 7916 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7917 "true");
7918 } else
a4d82a8a 7919 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7920
7921 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7922 json_object_string_add(bestpath, "compareRouterId", "true");
7923 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7924 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7925 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7926 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7927 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7928 json_object_string_add(bestpath, "med",
7929 "missing-as-worst");
7930 else
7931 json_object_string_add(bestpath, "med", "true");
7932 }
7933
7934 json_object_object_add(json, "bestPath", bestpath);
7935}
7936
3577f1c5
DD
7937/* Print the error code/subcode for why the peer is down */
7938static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
7939 json_object *json_peer, bool use_json)
7940{
7941 const char *code_str;
7942 const char *subcode_str;
7943
7944 if (use_json) {
7945 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
7946 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
7947 char errorcodesubcode_hexstr[5];
7948 char errorcodesubcode_str[256];
7949
7950 code_str = bgp_notify_code_str(peer->notify.code);
7951 subcode_str = bgp_notify_subcode_str(
7952 peer->notify.code,
7953 peer->notify.subcode);
7954
7955 sprintf(errorcodesubcode_hexstr, "%02X%02X",
7956 peer->notify.code, peer->notify.subcode);
7957 json_object_string_add(json_peer,
7958 "lastErrorCodeSubcode",
7959 errorcodesubcode_hexstr);
7960 snprintf(errorcodesubcode_str, 255, "%s%s",
7961 code_str, subcode_str);
7962 json_object_string_add(json_peer,
7963 "lastNotificationReason",
7964 errorcodesubcode_str);
7965 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
7966 && peer->notify.code == BGP_NOTIFY_CEASE
7967 && (peer->notify.subcode
7968 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
7969 || peer->notify.subcode
7970 == BGP_NOTIFY_CEASE_ADMIN_RESET)
7971 && peer->notify.length) {
7972 char msgbuf[1024];
7973 const char *msg_str;
7974
7975 msg_str = bgp_notify_admin_message(
7976 msgbuf, sizeof(msgbuf),
7977 (uint8_t *)peer->notify.data,
7978 peer->notify.length);
7979 if (msg_str)
7980 json_object_string_add(
7981 json_peer,
7982 "lastShutdownDescription",
7983 msg_str);
7984 }
7985
c258527b 7986 }
3577f1c5
DD
7987 json_object_string_add(json_peer, "lastResetDueTo",
7988 peer_down_str[(int)peer->last_reset]);
05912a17
DD
7989 json_object_int_add(json_peer, "lastResetCode",
7990 peer->last_reset);
3577f1c5
DD
7991 } else {
7992 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
7993 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
7994 code_str = bgp_notify_code_str(peer->notify.code);
7995 subcode_str =
7996 bgp_notify_subcode_str(peer->notify.code,
7997 peer->notify.subcode);
7998 vty_out(vty, " Notification %s (%s%s)\n",
7999 peer->last_reset == PEER_DOWN_NOTIFY_SEND
8000 ? "sent"
8001 : "received",
8002 code_str, subcode_str);
8003 } else {
8004 vty_out(vty, " %s\n",
8005 peer_down_str[(int)peer->last_reset]);
8006 }
8007 }
8008}
8009
8010static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
8011 safi_t safi)
8012{
8013 return ((peer->status != Established) ||
8014 !peer->afc_recv[afi][safi]);
8015}
8016
8017static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
8018 struct peer *peer, json_object *json_peer,
8019 int max_neighbor_width, bool use_json)
8020{
8021 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8022 int len;
8023
8024 if (use_json) {
8025 if (peer_dynamic_neighbor(peer))
8026 json_object_boolean_true_add(json_peer,
8027 "dynamicPeer");
8028 if (peer->hostname)
8029 json_object_string_add(json_peer, "hostname",
8030 peer->hostname);
8031
8032 if (peer->domainname)
8033 json_object_string_add(json_peer, "domainname",
8034 peer->domainname);
8035 json_object_int_add(json_peer, "connectionsEstablished",
8036 peer->established);
8037 json_object_int_add(json_peer, "connectionsDropped",
8038 peer->dropped);
8039 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8040 use_json, json_peer);
8041 if (peer->status == Established)
8042 json_object_string_add(json_peer, "lastResetDueTo",
8043 "AFI/SAFI Not Negotiated");
8044 else
8045 bgp_show_peer_reset(NULL, peer, json_peer, true);
8046 } else {
8047 dn_flag[1] = '\0';
8048 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
8049 if (peer->hostname
8050 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8051 len = vty_out(vty, "%s%s(%s)", dn_flag,
8052 peer->hostname, peer->host);
8053 else
8054 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8055
8056 /* pad the neighbor column with spaces */
8057 if (len < max_neighbor_width)
8058 vty_out(vty, "%*s", max_neighbor_width - len,
8059 " ");
8060 vty_out(vty, "%7d %7d %8s", peer->established,
8061 peer->dropped,
8062 peer_uptime(peer->uptime, timebuf,
8063 BGP_UPTIME_LEN, 0, NULL));
8064 if (peer->status == Established)
8065 vty_out(vty, " AFI/SAFI Not Negotiated\n");
8066 else
8067 bgp_show_peer_reset(vty, peer, NULL,
8068 false);
8069 }
8070}
c258527b 8071
3577f1c5 8072
718e3744 8073/* Show BGP peer's summary information. */
d62a17ae 8074static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
3577f1c5 8075 bool show_failed, bool use_json)
d62a17ae 8076{
8077 struct peer *peer;
8078 struct listnode *node, *nnode;
8079 unsigned int count = 0, dn_count = 0;
8080 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8081 char neighbor_buf[VTY_BUFSIZ];
8082 int neighbor_col_default_width = 16;
3577f1c5 8083 int len, failed_count = 0;
d62a17ae 8084 int max_neighbor_width = 0;
8085 int pfx_rcd_safi;
3c13337d 8086 json_object *json = NULL;
d62a17ae 8087 json_object *json_peer = NULL;
8088 json_object *json_peers = NULL;
50e05855 8089 struct peer_af *paf;
d62a17ae 8090
8091 /* labeled-unicast routes are installed in the unicast table so in order
8092 * to
8093 * display the correct PfxRcd value we must look at SAFI_UNICAST
8094 */
3577f1c5 8095
d62a17ae 8096 if (safi == SAFI_LABELED_UNICAST)
8097 pfx_rcd_safi = SAFI_UNICAST;
8098 else
8099 pfx_rcd_safi = safi;
8100
8101 if (use_json) {
3c13337d 8102 json = json_object_new_object();
d62a17ae 8103 json_peers = json_object_new_object();
3577f1c5
DD
8104 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8105 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8106 continue;
8107
8108 if (peer->afc[afi][safi]) {
8109 /* See if we have at least a single failed peer */
8110 if (bgp_has_peer_failed(peer, afi, safi))
8111 failed_count++;
8112 count++;
8113 }
8114 if (peer_dynamic_neighbor(peer))
8115 dn_count++;
8116 }
c258527b 8117
d62a17ae 8118 } else {
8119 /* Loop over all neighbors that will be displayed to determine
8120 * how many
8121 * characters are needed for the Neighbor column
8122 */
8123 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8124 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8125 continue;
8126
8127 if (peer->afc[afi][safi]) {
8128 memset(dn_flag, '\0', sizeof(dn_flag));
8129 if (peer_dynamic_neighbor(peer))
8130 dn_flag[0] = '*';
8131
8132 if (peer->hostname
8133 && bgp_flag_check(bgp,
8134 BGP_FLAG_SHOW_HOSTNAME))
8135 sprintf(neighbor_buf, "%s%s(%s) ",
8136 dn_flag, peer->hostname,
8137 peer->host);
8138 else
8139 sprintf(neighbor_buf, "%s%s ", dn_flag,
8140 peer->host);
8141
8142 len = strlen(neighbor_buf);
8143
8144 if (len > max_neighbor_width)
8145 max_neighbor_width = len;
c258527b 8146
3577f1c5
DD
8147 /* See if we have at least a single failed peer */
8148 if (bgp_has_peer_failed(peer, afi, safi))
8149 failed_count++;
8150 count++;
d62a17ae 8151 }
8152 }
f933309e 8153
d62a17ae 8154 /* Originally we displayed the Neighbor column as 16
8155 * characters wide so make that the default
8156 */
8157 if (max_neighbor_width < neighbor_col_default_width)
8158 max_neighbor_width = neighbor_col_default_width;
8159 }
f933309e 8160
3577f1c5
DD
8161 if (show_failed && !failed_count) {
8162 if (use_json) {
8163 json_object_int_add(json, "failedPeersCount", 0);
8164 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 8165 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
8166
8167 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8168 json, JSON_C_TO_STRING_PRETTY));
8169 json_object_free(json);
8170 } else {
8171 vty_out(vty, "%% No failed BGP neighbors found\n");
8172 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8173 }
8174 return CMD_SUCCESS;
8175 }
c258527b 8176
3577f1c5 8177 count = 0; /* Reset the value as its used again */
d62a17ae 8178 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8179 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8180 continue;
8181
ea47320b
DL
8182 if (!peer->afc[afi][safi])
8183 continue;
d62a17ae 8184
ea47320b
DL
8185 if (!count) {
8186 unsigned long ents;
8187 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 8188 int64_t vrf_id_ui;
d62a17ae 8189
a4d82a8a
PZ
8190 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8191 ? -1
8192 : (int64_t)bgp->vrf_id;
ea47320b
DL
8193
8194 /* Usage summary and header */
8195 if (use_json) {
8196 json_object_string_add(
8197 json, "routerId",
8198 inet_ntoa(bgp->router_id));
60466a63
QY
8199 json_object_int_add(json, "as", bgp->as);
8200 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
8201 json_object_string_add(
8202 json, "vrfName",
8203 (bgp->inst_type
8204 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8205 ? VRF_DEFAULT_NAME
ea47320b
DL
8206 : bgp->name);
8207 } else {
8208 vty_out(vty,
8209 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 8210 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
8211 bgp->vrf_id == VRF_UNKNOWN
8212 ? -1
8213 : (int)bgp->vrf_id);
ea47320b
DL
8214 vty_out(vty, "\n");
8215 }
d62a17ae 8216
ea47320b 8217 if (bgp_update_delay_configured(bgp)) {
d62a17ae 8218 if (use_json) {
ea47320b 8219 json_object_int_add(
60466a63 8220 json, "updateDelayLimit",
ea47320b 8221 bgp->v_update_delay);
d62a17ae 8222
ea47320b
DL
8223 if (bgp->v_update_delay
8224 != bgp->v_establish_wait)
d62a17ae 8225 json_object_int_add(
8226 json,
ea47320b
DL
8227 "updateDelayEstablishWait",
8228 bgp->v_establish_wait);
d62a17ae 8229
60466a63 8230 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
8231 json_object_string_add(
8232 json,
8233 "updateDelayFirstNeighbor",
8234 bgp->update_delay_begin_time);
8235 json_object_boolean_true_add(
8236 json,
8237 "updateDelayInProgress");
8238 } else {
8239 if (bgp->update_delay_over) {
d62a17ae 8240 json_object_string_add(
8241 json,
8242 "updateDelayFirstNeighbor",
8243 bgp->update_delay_begin_time);
ea47320b 8244 json_object_string_add(
d62a17ae 8245 json,
ea47320b
DL
8246 "updateDelayBestpathResumed",
8247 bgp->update_delay_end_time);
8248 json_object_string_add(
d62a17ae 8249 json,
ea47320b
DL
8250 "updateDelayZebraUpdateResume",
8251 bgp->update_delay_zebra_resume_time);
8252 json_object_string_add(
8253 json,
8254 "updateDelayPeerUpdateResume",
8255 bgp->update_delay_peers_resume_time);
d62a17ae 8256 }
ea47320b
DL
8257 }
8258 } else {
8259 vty_out(vty,
8260 "Read-only mode update-delay limit: %d seconds\n",
8261 bgp->v_update_delay);
8262 if (bgp->v_update_delay
8263 != bgp->v_establish_wait)
d62a17ae 8264 vty_out(vty,
ea47320b
DL
8265 " Establish wait: %d seconds\n",
8266 bgp->v_establish_wait);
d62a17ae 8267
60466a63 8268 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
8269 vty_out(vty,
8270 " First neighbor established: %s\n",
8271 bgp->update_delay_begin_time);
8272 vty_out(vty,
8273 " Delay in progress\n");
8274 } else {
8275 if (bgp->update_delay_over) {
d62a17ae 8276 vty_out(vty,
8277 " First neighbor established: %s\n",
8278 bgp->update_delay_begin_time);
8279 vty_out(vty,
ea47320b
DL
8280 " Best-paths resumed: %s\n",
8281 bgp->update_delay_end_time);
8282 vty_out(vty,
8283 " zebra update resumed: %s\n",
8284 bgp->update_delay_zebra_resume_time);
8285 vty_out(vty,
8286 " peers update resumed: %s\n",
8287 bgp->update_delay_peers_resume_time);
d62a17ae 8288 }
8289 }
8290 }
ea47320b 8291 }
d62a17ae 8292
ea47320b
DL
8293 if (use_json) {
8294 if (bgp_maxmed_onstartup_configured(bgp)
8295 && bgp->maxmed_active)
8296 json_object_boolean_true_add(
60466a63 8297 json, "maxMedOnStartup");
ea47320b
DL
8298 if (bgp->v_maxmed_admin)
8299 json_object_boolean_true_add(
60466a63 8300 json, "maxMedAdministrative");
d62a17ae 8301
ea47320b
DL
8302 json_object_int_add(
8303 json, "tableVersion",
60466a63 8304 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 8305
60466a63
QY
8306 ents = bgp_table_count(bgp->rib[afi][safi]);
8307 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
8308 json_object_int_add(
8309 json, "ribMemory",
8310 ents * sizeof(struct bgp_node));
d62a17ae 8311
210ec2a0 8312 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
8313 json_object_int_add(json, "peerCount", ents);
8314 json_object_int_add(json, "peerMemory",
8315 ents * sizeof(struct peer));
d62a17ae 8316
ea47320b
DL
8317 if ((ents = listcount(bgp->group))) {
8318 json_object_int_add(
60466a63 8319 json, "peerGroupCount", ents);
ea47320b
DL
8320 json_object_int_add(
8321 json, "peerGroupMemory",
996c9314
LB
8322 ents * sizeof(struct
8323 peer_group));
ea47320b 8324 }
d62a17ae 8325
ea47320b
DL
8326 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8327 BGP_CONFIG_DAMPENING))
8328 json_object_boolean_true_add(
60466a63 8329 json, "dampeningEnabled");
ea47320b
DL
8330 } else {
8331 if (bgp_maxmed_onstartup_configured(bgp)
8332 && bgp->maxmed_active)
d62a17ae 8333 vty_out(vty,
ea47320b
DL
8334 "Max-med on-startup active\n");
8335 if (bgp->v_maxmed_admin)
d62a17ae 8336 vty_out(vty,
ea47320b 8337 "Max-med administrative active\n");
d62a17ae 8338
60466a63
QY
8339 vty_out(vty, "BGP table version %" PRIu64 "\n",
8340 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 8341
60466a63 8342 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
8343 vty_out(vty,
8344 "RIB entries %ld, using %s of memory\n",
8345 ents,
996c9314
LB
8346 mtype_memstr(memstrbuf,
8347 sizeof(memstrbuf),
8348 ents * sizeof(struct
8349 bgp_node)));
ea47320b
DL
8350
8351 /* Peer related usage */
210ec2a0 8352 ents = bgp->af_peer_count[afi][safi];
60466a63 8353 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
8354 ents,
8355 mtype_memstr(
60466a63
QY
8356 memstrbuf, sizeof(memstrbuf),
8357 ents * sizeof(struct peer)));
ea47320b
DL
8358
8359 if ((ents = listcount(bgp->group)))
d62a17ae 8360 vty_out(vty,
ea47320b 8361 "Peer groups %ld, using %s of memory\n",
d62a17ae 8362 ents,
8363 mtype_memstr(
8364 memstrbuf,
8365 sizeof(memstrbuf),
996c9314
LB
8366 ents * sizeof(struct
8367 peer_group)));
d62a17ae 8368
ea47320b
DL
8369 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8370 BGP_CONFIG_DAMPENING))
60466a63 8371 vty_out(vty, "Dampening enabled.\n");
ea47320b 8372 vty_out(vty, "\n");
d62a17ae 8373
ea47320b
DL
8374 /* Subtract 8 here because 'Neighbor' is
8375 * 8 characters */
8376 vty_out(vty, "Neighbor");
60466a63
QY
8377 vty_out(vty, "%*s", max_neighbor_width - 8,
8378 " ");
3577f1c5
DD
8379 if (show_failed)
8380 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
8381 else
8382 vty_out(vty,
ea47320b 8383 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 8384 }
ea47320b 8385 }
d62a17ae 8386
ea47320b 8387 count++;
3577f1c5
DD
8388 /* Works for both failed & successful cases */
8389 if (peer_dynamic_neighbor(peer))
8390 dn_count++;
d62a17ae 8391
ea47320b 8392 if (use_json) {
3577f1c5
DD
8393 json_peer = NULL;
8394
8395 if (show_failed &&
8396 bgp_has_peer_failed(peer, afi, safi)) {
8397 json_peer = json_object_new_object();
8398 bgp_show_failed_summary(vty, bgp, peer,
8399 json_peer, 0, use_json);
8400 } else if (!show_failed) {
8401 json_peer = json_object_new_object();
8402 if (peer_dynamic_neighbor(peer)) {
8403 json_object_boolean_true_add(json_peer,
8404 "dynamicPeer");
8405 }
d62a17ae 8406
3577f1c5
DD
8407 if (peer->hostname)
8408 json_object_string_add(json_peer, "hostname",
8409 peer->hostname);
8410
8411 if (peer->domainname)
8412 json_object_string_add(json_peer, "domainname",
8413 peer->domainname);
8414
8415 json_object_int_add(json_peer, "remoteAs", peer->as);
8416 json_object_int_add(json_peer, "version", 4);
8417 json_object_int_add(json_peer, "msgRcvd",
8418 PEER_TOTAL_RX(peer));
8419 json_object_int_add(json_peer, "msgSent",
8420 PEER_TOTAL_TX(peer));
8421
8422 json_object_int_add(json_peer, "tableVersion",
8423 peer->version[afi][safi]);
8424 json_object_int_add(json_peer, "outq",
8425 peer->obuf->count);
8426 json_object_int_add(json_peer, "inq", 0);
8427 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8428 use_json, json_peer);
8429
8430 /*
8431 * Adding "pfxRcd" field to match with the corresponding
8432 * CLI. "prefixReceivedCount" will be deprecated in
8433 * future.
8434 */
8435 json_object_int_add(json_peer, "prefixReceivedCount",
8436 peer->pcount[afi][pfx_rcd_safi]);
8437 json_object_int_add(json_peer, "pfxRcd",
8438 peer->pcount[afi][pfx_rcd_safi]);
8439
8440 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8441 if (paf && PAF_SUBGRP(paf))
8442 json_object_int_add(json_peer,
8443 "pfxSnt",
8444 (PAF_SUBGRP(paf))->scount);
8445 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8446 json_object_string_add(json_peer, "state",
8447 "Idle (Admin)");
8448 else if (peer->afc_recv[afi][safi])
8449 json_object_string_add(
8450 json_peer, "state",
8451 lookup_msg(bgp_status_msg, peer->status,
8452 NULL));
8453 else if (CHECK_FLAG(peer->sflags,
8454 PEER_STATUS_PREFIX_OVERFLOW))
8455 json_object_string_add(json_peer, "state",
8456 "Idle (PfxCt)");
8457 else
8458 json_object_string_add(
8459 json_peer, "state",
8460 lookup_msg(bgp_status_msg, peer->status,
8461 NULL));
200116db
DD
8462 json_object_int_add(json_peer, "connectionsEstablished",
8463 peer->established);
8464 json_object_int_add(json_peer, "connectionsDropped",
8465 peer->dropped);
b4e9dcba 8466 }
3577f1c5
DD
8467 /* Avoid creating empty peer dicts in JSON */
8468 if (json_peer == NULL)
8469 continue;
ea47320b
DL
8470
8471 if (peer->conf_if)
60466a63 8472 json_object_string_add(json_peer, "idType",
ea47320b
DL
8473 "interface");
8474 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
8475 json_object_string_add(json_peer, "idType",
8476 "ipv4");
ea47320b 8477 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
8478 json_object_string_add(json_peer, "idType",
8479 "ipv6");
ea47320b
DL
8480 json_object_object_add(json_peers, peer->host,
8481 json_peer);
8482 } else {
3577f1c5
DD
8483 if (show_failed &&
8484 bgp_has_peer_failed(peer, afi, safi)) {
8485 bgp_show_failed_summary(vty, bgp, peer, NULL,
8486 max_neighbor_width,
8487 use_json);
8488 } else if (!show_failed) {
8489 memset(dn_flag, '\0', sizeof(dn_flag));
8490 if (peer_dynamic_neighbor(peer)) {
8491 dn_flag[0] = '*';
8492 }
d62a17ae 8493
3577f1c5
DD
8494 if (peer->hostname
8495 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8496 len = vty_out(vty, "%s%s(%s)", dn_flag,
8497 peer->hostname, peer->host);
d62a17ae 8498 else
3577f1c5
DD
8499 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8500
8501 /* pad the neighbor column with spaces */
8502 if (len < max_neighbor_width)
8503 vty_out(vty, "%*s", max_neighbor_width - len,
8504 " ");
8505
8506 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8507 peer->as, PEER_TOTAL_RX(peer),
8508 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8509 0, peer->obuf->count,
8510 peer_uptime(peer->uptime, timebuf,
8511 BGP_UPTIME_LEN, 0, NULL));
8512
8513 if (peer->status == Established)
8514 if (peer->afc_recv[afi][safi])
a0a87037
DA
8515 vty_out(vty, " %12" PRIu32,
8516 peer->pcount
8517 [afi]
8518 [pfx_rcd_safi]);
3577f1c5
DD
8519 else
8520 vty_out(vty, " NoNeg");
8521 else {
8522 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8523 vty_out(vty, " Idle (Admin)");
8524 else if (CHECK_FLAG(
8525 peer->sflags,
8526 PEER_STATUS_PREFIX_OVERFLOW))
8527 vty_out(vty, " Idle (PfxCt)");
8528 else
8529 vty_out(vty, " %12s",
8530 lookup_msg(bgp_status_msg,
8531 peer->status, NULL));
8532 }
8533 vty_out(vty, "\n");
d62a17ae 8534 }
3577f1c5 8535
d62a17ae 8536 }
8537 }
f933309e 8538
d62a17ae 8539 if (use_json) {
8540 json_object_object_add(json, "peers", json_peers);
3577f1c5 8541 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 8542 json_object_int_add(json, "totalPeers", count);
8543 json_object_int_add(json, "dynamicPeers", dn_count);
8544
3577f1c5
DD
8545 if (!show_failed)
8546 bgp_show_bestpath_json(bgp, json);
57a9c8a8 8547
996c9314
LB
8548 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8549 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8550 json_object_free(json);
8551 } else {
8552 if (count)
8553 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8554 else {
d6ceaca3 8555 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 8556 get_afi_safi_str(afi, safi, false));
d62a17ae 8557 }
b05a1c8b 8558
d6ceaca3 8559 if (dn_count) {
d62a17ae 8560 vty_out(vty, "* - dynamic neighbor\n");
8561 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8562 dn_count, bgp->dynamic_neighbors_limit);
8563 }
8564 }
1ff9a340 8565
d62a17ae 8566 return CMD_SUCCESS;
718e3744 8567}
8568
d62a17ae 8569static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
3577f1c5 8570 int safi, bool show_failed, bool use_json)
d62a17ae 8571{
8572 int is_first = 1;
8573 int afi_wildcard = (afi == AFI_MAX);
8574 int safi_wildcard = (safi == SAFI_MAX);
8575 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 8576 bool nbr_output = false;
d62a17ae 8577
8578 if (use_json && is_wildcard)
8579 vty_out(vty, "{\n");
8580 if (afi_wildcard)
8581 afi = 1; /* AFI_IP */
8582 while (afi < AFI_MAX) {
8583 if (safi_wildcard)
8584 safi = 1; /* SAFI_UNICAST */
8585 while (safi < SAFI_MAX) {
318cac96 8586 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 8587 nbr_output = true;
f86897b9 8588
d62a17ae 8589 if (is_wildcard) {
8590 /*
8591 * So limit output to those afi/safi
8592 * pairs that
8593 * actualy have something interesting in
8594 * them
8595 */
8596 if (use_json) {
d62a17ae 8597 if (!is_first)
8598 vty_out(vty, ",\n");
8599 else
8600 is_first = 0;
8601
8602 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
8603 get_afi_safi_str(afi,
8604 safi,
8605 true));
d62a17ae 8606 } else {
8607 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
8608 get_afi_safi_str(afi,
8609 safi,
8610 false));
d62a17ae 8611 }
8612 }
3577f1c5
DD
8613 bgp_show_summary(vty, bgp, afi, safi, show_failed,
8614 use_json);
d62a17ae 8615 }
8616 safi++;
d62a17ae 8617 if (!safi_wildcard)
8618 safi = SAFI_MAX;
8619 }
8620 afi++;
ee851c8c 8621 if (!afi_wildcard)
d62a17ae 8622 afi = AFI_MAX;
8623 }
8624
8625 if (use_json && is_wildcard)
8626 vty_out(vty, "}\n");
ca61fd25
DS
8627 else if (!nbr_output) {
8628 if (use_json)
8629 vty_out(vty, "{}\n");
8630 else
8631 vty_out(vty, "%% No BGP neighbors found\n");
8632 }
d62a17ae 8633}
8634
8635static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5
DD
8636 safi_t safi, bool show_failed,
8637 bool use_json)
d62a17ae 8638{
8639 struct listnode *node, *nnode;
8640 struct bgp *bgp;
d62a17ae 8641 int is_first = 1;
9f049418 8642 bool nbr_output = false;
d62a17ae 8643
8644 if (use_json)
8645 vty_out(vty, "{\n");
8646
8647 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 8648 nbr_output = true;
d62a17ae 8649 if (use_json) {
d62a17ae 8650 if (!is_first)
8651 vty_out(vty, ",\n");
8652 else
8653 is_first = 0;
8654
8655 vty_out(vty, "\"%s\":",
8656 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8657 ? VRF_DEFAULT_NAME
d62a17ae 8658 : bgp->name);
8659 } else {
8660 vty_out(vty, "\nInstance %s:\n",
8661 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8662 ? VRF_DEFAULT_NAME
d62a17ae 8663 : bgp->name);
8664 }
3577f1c5
DD
8665 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8666 use_json);
d62a17ae 8667 }
8668
8669 if (use_json)
8670 vty_out(vty, "}\n");
9f049418
DS
8671 else if (!nbr_output)
8672 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 8673}
8674
8675int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
3577f1c5 8676 safi_t safi, bool show_failed, bool use_json)
d62a17ae 8677{
8678 struct bgp *bgp;
8679
8680 if (name) {
8681 if (strmatch(name, "all")) {
8682 bgp_show_all_instances_summary_vty(vty, afi, safi,
3577f1c5 8683 show_failed,
d62a17ae 8684 use_json);
8685 return CMD_SUCCESS;
8686 } else {
8687 bgp = bgp_lookup_by_name(name);
8688
8689 if (!bgp) {
8690 if (use_json)
8691 vty_out(vty, "{}\n");
8692 else
8693 vty_out(vty,
ca61fd25 8694 "%% BGP instance not found\n");
d62a17ae 8695 return CMD_WARNING;
8696 }
8697
f86897b9 8698 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
3577f1c5 8699 show_failed, use_json);
d62a17ae 8700 return CMD_SUCCESS;
8701 }
8702 }
8703
8704 bgp = bgp_get_default();
8705
8706 if (bgp)
3577f1c5
DD
8707 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8708 use_json);
9f049418 8709 else {
ca61fd25
DS
8710 if (use_json)
8711 vty_out(vty, "{}\n");
8712 else
8713 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
8714 return CMD_WARNING;
8715 }
d62a17ae 8716
8717 return CMD_SUCCESS;
4fb25c53
DW
8718}
8719
716b2d8a 8720/* `show [ip] bgp summary' commands. */
47fc97cc 8721DEFUN (show_ip_bgp_summary,
718e3744 8722 show_ip_bgp_summary_cmd,
3577f1c5 8723 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]",
718e3744 8724 SHOW_STR
8725 IP_STR
8726 BGP_STR
8386ac43 8727 BGP_INSTANCE_HELP_STR
46f296b4 8728 BGP_AFI_HELP_STR
dd6bd0f1 8729 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8730 "Summary of BGP neighbor status\n"
3577f1c5 8731 "Show only sessions not in Established state\n"
9973d184 8732 JSON_STR)
718e3744 8733{
d62a17ae 8734 char *vrf = NULL;
8735 afi_t afi = AFI_MAX;
8736 safi_t safi = SAFI_MAX;
3577f1c5 8737 bool show_failed = false;
d62a17ae 8738
8739 int idx = 0;
8740
8741 /* show [ip] bgp */
8742 if (argv_find(argv, argc, "ip", &idx))
8743 afi = AFI_IP;
9a8bdf1c
PG
8744 /* [<vrf> VIEWVRFNAME] */
8745 if (argv_find(argv, argc, "vrf", &idx)) {
8746 vrf = argv[idx + 1]->arg;
8747 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8748 vrf = NULL;
8749 } else if (argv_find(argv, argc, "view", &idx))
8750 /* [<view> VIEWVRFNAME] */
8751 vrf = argv[idx + 1]->arg;
d62a17ae 8752 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8753 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8754 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8755 }
8756
3577f1c5
DD
8757 if (argv_find(argv, argc, "failed", &idx))
8758 show_failed = true;
8759
9f049418 8760 bool uj = use_json(argc, argv);
d62a17ae 8761
3577f1c5 8762 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj);
d62a17ae 8763}
8764
5cb5f4d0 8765const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 8766{
5cb5f4d0
DD
8767 if (for_json)
8768 return get_afi_safi_json_str(afi, safi);
d62a17ae 8769 else
5cb5f4d0 8770 return get_afi_safi_vty_str(afi, safi);
27162734
LB
8771}
8772
718e3744 8773/* Show BGP peer's information. */
d1927ebe 8774enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
d62a17ae 8775
8776static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8777 afi_t afi, safi_t safi,
d7c0a89a
QY
8778 uint16_t adv_smcap, uint16_t adv_rmcap,
8779 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 8780 bool use_json, json_object *json_pref)
d62a17ae 8781{
8782 /* Send-Mode */
8783 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8784 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8785 if (use_json) {
8786 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8787 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8788 json_object_string_add(json_pref, "sendMode",
8789 "advertisedAndReceived");
8790 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8791 json_object_string_add(json_pref, "sendMode",
8792 "advertised");
8793 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8794 json_object_string_add(json_pref, "sendMode",
8795 "received");
8796 } else {
8797 vty_out(vty, " Send-mode: ");
8798 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8799 vty_out(vty, "advertised");
8800 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8801 vty_out(vty, "%sreceived",
8802 CHECK_FLAG(p->af_cap[afi][safi],
8803 adv_smcap)
8804 ? ", "
8805 : "");
8806 vty_out(vty, "\n");
8807 }
8808 }
8809
8810 /* Receive-Mode */
8811 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8812 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8813 if (use_json) {
8814 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8815 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8816 json_object_string_add(json_pref, "recvMode",
8817 "advertisedAndReceived");
8818 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8819 json_object_string_add(json_pref, "recvMode",
8820 "advertised");
8821 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8822 json_object_string_add(json_pref, "recvMode",
8823 "received");
8824 } else {
8825 vty_out(vty, " Receive-mode: ");
8826 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8827 vty_out(vty, "advertised");
8828 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8829 vty_out(vty, "%sreceived",
8830 CHECK_FLAG(p->af_cap[afi][safi],
8831 adv_rmcap)
8832 ? ", "
8833 : "");
8834 vty_out(vty, "\n");
8835 }
8836 }
8837}
8838
8839static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 8840 safi_t safi, bool use_json,
d62a17ae 8841 json_object *json_neigh)
8842{
0291c246
MK
8843 struct bgp_filter *filter;
8844 struct peer_af *paf;
8845 char orf_pfx_name[BUFSIZ];
8846 int orf_pfx_count;
8847 json_object *json_af = NULL;
8848 json_object *json_prefA = NULL;
8849 json_object *json_prefB = NULL;
8850 json_object *json_addr = NULL;
d62a17ae 8851
8852 if (use_json) {
8853 json_addr = json_object_new_object();
8854 json_af = json_object_new_object();
8855 filter = &p->filter[afi][safi];
8856
8857 if (peer_group_active(p))
8858 json_object_string_add(json_addr, "peerGroupMember",
8859 p->group->name);
8860
8861 paf = peer_af_find(p, afi, safi);
8862 if (paf && PAF_SUBGRP(paf)) {
8863 json_object_int_add(json_addr, "updateGroupId",
8864 PAF_UPDGRP(paf)->id);
8865 json_object_int_add(json_addr, "subGroupId",
8866 PAF_SUBGRP(paf)->id);
8867 json_object_int_add(json_addr, "packetQueueLength",
8868 bpacket_queue_virtual_length(paf));
8869 }
8870
8871 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8872 || CHECK_FLAG(p->af_cap[afi][safi],
8873 PEER_CAP_ORF_PREFIX_SM_RCV)
8874 || CHECK_FLAG(p->af_cap[afi][safi],
8875 PEER_CAP_ORF_PREFIX_RM_ADV)
8876 || CHECK_FLAG(p->af_cap[afi][safi],
8877 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8878 json_object_int_add(json_af, "orfType",
8879 ORF_TYPE_PREFIX);
8880 json_prefA = json_object_new_object();
8881 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8882 PEER_CAP_ORF_PREFIX_SM_ADV,
8883 PEER_CAP_ORF_PREFIX_RM_ADV,
8884 PEER_CAP_ORF_PREFIX_SM_RCV,
8885 PEER_CAP_ORF_PREFIX_RM_RCV,
8886 use_json, json_prefA);
8887 json_object_object_add(json_af, "orfPrefixList",
8888 json_prefA);
8889 }
8890
8891 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8892 || CHECK_FLAG(p->af_cap[afi][safi],
8893 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8894 || CHECK_FLAG(p->af_cap[afi][safi],
8895 PEER_CAP_ORF_PREFIX_RM_ADV)
8896 || CHECK_FLAG(p->af_cap[afi][safi],
8897 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8898 json_object_int_add(json_af, "orfOldType",
8899 ORF_TYPE_PREFIX_OLD);
8900 json_prefB = json_object_new_object();
8901 bgp_show_peer_afi_orf_cap(
8902 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8903 PEER_CAP_ORF_PREFIX_RM_ADV,
8904 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8905 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8906 json_prefB);
8907 json_object_object_add(json_af, "orfOldPrefixList",
8908 json_prefB);
8909 }
8910
8911 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8912 || CHECK_FLAG(p->af_cap[afi][safi],
8913 PEER_CAP_ORF_PREFIX_SM_RCV)
8914 || CHECK_FLAG(p->af_cap[afi][safi],
8915 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8916 || CHECK_FLAG(p->af_cap[afi][safi],
8917 PEER_CAP_ORF_PREFIX_RM_ADV)
8918 || CHECK_FLAG(p->af_cap[afi][safi],
8919 PEER_CAP_ORF_PREFIX_RM_RCV)
8920 || CHECK_FLAG(p->af_cap[afi][safi],
8921 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8922 json_object_object_add(json_addr, "afDependentCap",
8923 json_af);
8924 else
8925 json_object_free(json_af);
8926
8927 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8928 orf_pfx_count = prefix_bgp_show_prefix_list(
8929 NULL, afi, orf_pfx_name, use_json);
8930
8931 if (CHECK_FLAG(p->af_sflags[afi][safi],
8932 PEER_STATUS_ORF_PREFIX_SEND)
8933 || orf_pfx_count) {
8934 if (CHECK_FLAG(p->af_sflags[afi][safi],
8935 PEER_STATUS_ORF_PREFIX_SEND))
8936 json_object_boolean_true_add(json_neigh,
8937 "orfSent");
8938 if (orf_pfx_count)
8939 json_object_int_add(json_addr, "orfRecvCounter",
8940 orf_pfx_count);
8941 }
8942 if (CHECK_FLAG(p->af_sflags[afi][safi],
8943 PEER_STATUS_ORF_WAIT_REFRESH))
8944 json_object_string_add(
8945 json_addr, "orfFirstUpdate",
8946 "deferredUntilORFOrRouteRefreshRecvd");
8947
8948 if (CHECK_FLAG(p->af_flags[afi][safi],
8949 PEER_FLAG_REFLECTOR_CLIENT))
8950 json_object_boolean_true_add(json_addr,
8951 "routeReflectorClient");
8952 if (CHECK_FLAG(p->af_flags[afi][safi],
8953 PEER_FLAG_RSERVER_CLIENT))
8954 json_object_boolean_true_add(json_addr,
8955 "routeServerClient");
8956 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8957 json_object_boolean_true_add(json_addr,
8958 "inboundSoftConfigPermit");
8959
8960 if (CHECK_FLAG(p->af_flags[afi][safi],
8961 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8962 json_object_boolean_true_add(
8963 json_addr,
8964 "privateAsNumsAllReplacedInUpdatesToNbr");
8965 else if (CHECK_FLAG(p->af_flags[afi][safi],
8966 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8967 json_object_boolean_true_add(
8968 json_addr,
8969 "privateAsNumsReplacedInUpdatesToNbr");
8970 else if (CHECK_FLAG(p->af_flags[afi][safi],
8971 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8972 json_object_boolean_true_add(
8973 json_addr,
8974 "privateAsNumsAllRemovedInUpdatesToNbr");
8975 else if (CHECK_FLAG(p->af_flags[afi][safi],
8976 PEER_FLAG_REMOVE_PRIVATE_AS))
8977 json_object_boolean_true_add(
8978 json_addr,
8979 "privateAsNumsRemovedInUpdatesToNbr");
8980
dcc68b5e
MS
8981 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8982 json_object_boolean_true_add(
8983 json_addr,
8984 bgp_addpath_names(p->addpath_type[afi][safi])
8985 ->type_json_name);
d62a17ae 8986
8987 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8988 json_object_string_add(json_addr,
8989 "overrideASNsInOutboundUpdates",
8990 "ifAspathEqualRemoteAs");
8991
8992 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8993 || CHECK_FLAG(p->af_flags[afi][safi],
8994 PEER_FLAG_FORCE_NEXTHOP_SELF))
8995 json_object_boolean_true_add(json_addr,
8996 "routerAlwaysNextHop");
8997 if (CHECK_FLAG(p->af_flags[afi][safi],
8998 PEER_FLAG_AS_PATH_UNCHANGED))
8999 json_object_boolean_true_add(
9000 json_addr, "unchangedAsPathPropogatedToNbr");
9001 if (CHECK_FLAG(p->af_flags[afi][safi],
9002 PEER_FLAG_NEXTHOP_UNCHANGED))
9003 json_object_boolean_true_add(
9004 json_addr, "unchangedNextHopPropogatedToNbr");
9005 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9006 json_object_boolean_true_add(
9007 json_addr, "unchangedMedPropogatedToNbr");
9008 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9009 || CHECK_FLAG(p->af_flags[afi][safi],
9010 PEER_FLAG_SEND_EXT_COMMUNITY)) {
9011 if (CHECK_FLAG(p->af_flags[afi][safi],
9012 PEER_FLAG_SEND_COMMUNITY)
9013 && CHECK_FLAG(p->af_flags[afi][safi],
9014 PEER_FLAG_SEND_EXT_COMMUNITY))
9015 json_object_string_add(json_addr,
9016 "commAttriSentToNbr",
9017 "extendedAndStandard");
9018 else if (CHECK_FLAG(p->af_flags[afi][safi],
9019 PEER_FLAG_SEND_EXT_COMMUNITY))
9020 json_object_string_add(json_addr,
9021 "commAttriSentToNbr",
9022 "extended");
9023 else
9024 json_object_string_add(json_addr,
9025 "commAttriSentToNbr",
9026 "standard");
9027 }
9028 if (CHECK_FLAG(p->af_flags[afi][safi],
9029 PEER_FLAG_DEFAULT_ORIGINATE)) {
9030 if (p->default_rmap[afi][safi].name)
9031 json_object_string_add(
9032 json_addr, "defaultRouteMap",
9033 p->default_rmap[afi][safi].name);
9034
9035 if (paf && PAF_SUBGRP(paf)
9036 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9037 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9038 json_object_boolean_true_add(json_addr,
9039 "defaultSent");
9040 else
9041 json_object_boolean_true_add(json_addr,
9042 "defaultNotSent");
9043 }
9044
dff8f48d 9045 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 9046 if (is_evpn_enabled())
60466a63
QY
9047 json_object_boolean_true_add(
9048 json_addr, "advertiseAllVnis");
dff8f48d
MK
9049 }
9050
d62a17ae 9051 if (filter->plist[FILTER_IN].name
9052 || filter->dlist[FILTER_IN].name
9053 || filter->aslist[FILTER_IN].name
9054 || filter->map[RMAP_IN].name)
9055 json_object_boolean_true_add(json_addr,
9056 "inboundPathPolicyConfig");
9057 if (filter->plist[FILTER_OUT].name
9058 || filter->dlist[FILTER_OUT].name
9059 || filter->aslist[FILTER_OUT].name
9060 || filter->map[RMAP_OUT].name || filter->usmap.name)
9061 json_object_boolean_true_add(
9062 json_addr, "outboundPathPolicyConfig");
9063
9064 /* prefix-list */
9065 if (filter->plist[FILTER_IN].name)
9066 json_object_string_add(json_addr,
9067 "incomingUpdatePrefixFilterList",
9068 filter->plist[FILTER_IN].name);
9069 if (filter->plist[FILTER_OUT].name)
9070 json_object_string_add(json_addr,
9071 "outgoingUpdatePrefixFilterList",
9072 filter->plist[FILTER_OUT].name);
9073
9074 /* distribute-list */
9075 if (filter->dlist[FILTER_IN].name)
9076 json_object_string_add(
9077 json_addr, "incomingUpdateNetworkFilterList",
9078 filter->dlist[FILTER_IN].name);
9079 if (filter->dlist[FILTER_OUT].name)
9080 json_object_string_add(
9081 json_addr, "outgoingUpdateNetworkFilterList",
9082 filter->dlist[FILTER_OUT].name);
9083
9084 /* filter-list. */
9085 if (filter->aslist[FILTER_IN].name)
9086 json_object_string_add(json_addr,
9087 "incomingUpdateAsPathFilterList",
9088 filter->aslist[FILTER_IN].name);
9089 if (filter->aslist[FILTER_OUT].name)
9090 json_object_string_add(json_addr,
9091 "outgoingUpdateAsPathFilterList",
9092 filter->aslist[FILTER_OUT].name);
9093
9094 /* route-map. */
9095 if (filter->map[RMAP_IN].name)
9096 json_object_string_add(
9097 json_addr, "routeMapForIncomingAdvertisements",
9098 filter->map[RMAP_IN].name);
9099 if (filter->map[RMAP_OUT].name)
9100 json_object_string_add(
9101 json_addr, "routeMapForOutgoingAdvertisements",
9102 filter->map[RMAP_OUT].name);
9103
9dac9fc8
DA
9104 /* ebgp-requires-policy (inbound) */
9105 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9106 && !bgp_inbound_policy_exists(p, filter))
9107 json_object_string_add(
9108 json_addr, "inboundEbgpRequiresPolicy",
9109 "Inbound updates discarded due to missing policy");
9110
9111 /* ebgp-requires-policy (outbound) */
9112 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9113 && (!bgp_outbound_policy_exists(p, filter)))
9114 json_object_string_add(
9115 json_addr, "outboundEbgpRequiresPolicy",
9116 "Outbound updates discarded due to missing policy");
9117
d62a17ae 9118 /* unsuppress-map */
9119 if (filter->usmap.name)
9120 json_object_string_add(json_addr,
9121 "selectiveUnsuppressRouteMap",
9122 filter->usmap.name);
9123
9124 /* Receive prefix count */
9125 json_object_int_add(json_addr, "acceptedPrefixCounter",
9126 p->pcount[afi][safi]);
50e05855
AD
9127 if (paf && PAF_SUBGRP(paf))
9128 json_object_int_add(json_addr, "sentPrefixCounter",
9129 (PAF_SUBGRP(paf))->scount);
d62a17ae 9130
9131 /* Maximum prefix */
9132 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9133 json_object_int_add(json_addr, "prefixAllowedMax",
9134 p->pmax[afi][safi]);
9135 if (CHECK_FLAG(p->af_flags[afi][safi],
9136 PEER_FLAG_MAX_PREFIX_WARNING))
9137 json_object_boolean_true_add(
9138 json_addr, "prefixAllowedMaxWarning");
9139 json_object_int_add(json_addr,
9140 "prefixAllowedWarningThresh",
9141 p->pmax_threshold[afi][safi]);
9142 if (p->pmax_restart[afi][safi])
9143 json_object_int_add(
9144 json_addr,
9145 "prefixAllowedRestartIntervalMsecs",
9146 p->pmax_restart[afi][safi] * 60000);
9147 }
5cb5f4d0 9148 json_object_object_add(json_neigh, get_afi_safi_str(afi, safi, true),
d62a17ae 9149 json_addr);
9150
9151 } else {
9152 filter = &p->filter[afi][safi];
9153
9154 vty_out(vty, " For address family: %s\n",
5cb5f4d0 9155 get_afi_safi_str(afi, safi, false));
d62a17ae 9156
9157 if (peer_group_active(p))
9158 vty_out(vty, " %s peer-group member\n",
9159 p->group->name);
9160
9161 paf = peer_af_find(p, afi, safi);
9162 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
9163 vty_out(vty, " Update group %" PRIu64
9164 ", subgroup %" PRIu64 "\n",
d62a17ae 9165 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
9166 vty_out(vty, " Packet Queue length %d\n",
9167 bpacket_queue_virtual_length(paf));
9168 } else {
9169 vty_out(vty, " Not part of any update group\n");
9170 }
9171 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9172 || CHECK_FLAG(p->af_cap[afi][safi],
9173 PEER_CAP_ORF_PREFIX_SM_RCV)
9174 || CHECK_FLAG(p->af_cap[afi][safi],
9175 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9176 || CHECK_FLAG(p->af_cap[afi][safi],
9177 PEER_CAP_ORF_PREFIX_RM_ADV)
9178 || CHECK_FLAG(p->af_cap[afi][safi],
9179 PEER_CAP_ORF_PREFIX_RM_RCV)
9180 || CHECK_FLAG(p->af_cap[afi][safi],
9181 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
9182 vty_out(vty, " AF-dependant capabilities:\n");
9183
9184 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9185 || CHECK_FLAG(p->af_cap[afi][safi],
9186 PEER_CAP_ORF_PREFIX_SM_RCV)
9187 || CHECK_FLAG(p->af_cap[afi][safi],
9188 PEER_CAP_ORF_PREFIX_RM_ADV)
9189 || CHECK_FLAG(p->af_cap[afi][safi],
9190 PEER_CAP_ORF_PREFIX_RM_RCV)) {
9191 vty_out(vty,
9192 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9193 ORF_TYPE_PREFIX);
9194 bgp_show_peer_afi_orf_cap(
9195 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9196 PEER_CAP_ORF_PREFIX_RM_ADV,
9197 PEER_CAP_ORF_PREFIX_SM_RCV,
9198 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
9199 }
9200 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9201 || CHECK_FLAG(p->af_cap[afi][safi],
9202 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9203 || CHECK_FLAG(p->af_cap[afi][safi],
9204 PEER_CAP_ORF_PREFIX_RM_ADV)
9205 || CHECK_FLAG(p->af_cap[afi][safi],
9206 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
9207 vty_out(vty,
9208 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9209 ORF_TYPE_PREFIX_OLD);
9210 bgp_show_peer_afi_orf_cap(
9211 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9212 PEER_CAP_ORF_PREFIX_RM_ADV,
9213 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
9214 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
9215 }
9216
9217 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
9218 orf_pfx_count = prefix_bgp_show_prefix_list(
9219 NULL, afi, orf_pfx_name, use_json);
9220
9221 if (CHECK_FLAG(p->af_sflags[afi][safi],
9222 PEER_STATUS_ORF_PREFIX_SEND)
9223 || orf_pfx_count) {
9224 vty_out(vty, " Outbound Route Filter (ORF):");
9225 if (CHECK_FLAG(p->af_sflags[afi][safi],
9226 PEER_STATUS_ORF_PREFIX_SEND))
9227 vty_out(vty, " sent;");
9228 if (orf_pfx_count)
9229 vty_out(vty, " received (%d entries)",
9230 orf_pfx_count);
9231 vty_out(vty, "\n");
9232 }
9233 if (CHECK_FLAG(p->af_sflags[afi][safi],
9234 PEER_STATUS_ORF_WAIT_REFRESH))
9235 vty_out(vty,
9236 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
9237
9238 if (CHECK_FLAG(p->af_flags[afi][safi],
9239 PEER_FLAG_REFLECTOR_CLIENT))
9240 vty_out(vty, " Route-Reflector Client\n");
9241 if (CHECK_FLAG(p->af_flags[afi][safi],
9242 PEER_FLAG_RSERVER_CLIENT))
9243 vty_out(vty, " Route-Server Client\n");
9244 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9245 vty_out(vty,
9246 " Inbound soft reconfiguration allowed\n");
9247
9248 if (CHECK_FLAG(p->af_flags[afi][safi],
9249 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9250 vty_out(vty,
9251 " Private AS numbers (all) replaced in updates to this neighbor\n");
9252 else if (CHECK_FLAG(p->af_flags[afi][safi],
9253 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9254 vty_out(vty,
9255 " Private AS numbers replaced in updates to this neighbor\n");
9256 else if (CHECK_FLAG(p->af_flags[afi][safi],
9257 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9258 vty_out(vty,
9259 " Private AS numbers (all) removed in updates to this neighbor\n");
9260 else if (CHECK_FLAG(p->af_flags[afi][safi],
9261 PEER_FLAG_REMOVE_PRIVATE_AS))
9262 vty_out(vty,
9263 " Private AS numbers removed in updates to this neighbor\n");
9264
dcc68b5e
MS
9265 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9266 vty_out(vty, " %s\n",
9267 bgp_addpath_names(p->addpath_type[afi][safi])
9268 ->human_description);
d62a17ae 9269
9270 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9271 vty_out(vty,
9272 " Override ASNs in outbound updates if aspath equals remote-as\n");
9273
9274 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9275 || CHECK_FLAG(p->af_flags[afi][safi],
9276 PEER_FLAG_FORCE_NEXTHOP_SELF))
9277 vty_out(vty, " NEXT_HOP is always this router\n");
9278 if (CHECK_FLAG(p->af_flags[afi][safi],
9279 PEER_FLAG_AS_PATH_UNCHANGED))
9280 vty_out(vty,
9281 " AS_PATH is propagated unchanged to this neighbor\n");
9282 if (CHECK_FLAG(p->af_flags[afi][safi],
9283 PEER_FLAG_NEXTHOP_UNCHANGED))
9284 vty_out(vty,
9285 " NEXT_HOP is propagated unchanged to this neighbor\n");
9286 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9287 vty_out(vty,
9288 " MED is propagated unchanged to this neighbor\n");
9289 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9290 || CHECK_FLAG(p->af_flags[afi][safi],
9291 PEER_FLAG_SEND_EXT_COMMUNITY)
9292 || CHECK_FLAG(p->af_flags[afi][safi],
9293 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9294 vty_out(vty,
9295 " Community attribute sent to this neighbor");
9296 if (CHECK_FLAG(p->af_flags[afi][safi],
9297 PEER_FLAG_SEND_COMMUNITY)
9298 && CHECK_FLAG(p->af_flags[afi][safi],
9299 PEER_FLAG_SEND_EXT_COMMUNITY)
9300 && CHECK_FLAG(p->af_flags[afi][safi],
9301 PEER_FLAG_SEND_LARGE_COMMUNITY))
9302 vty_out(vty, "(all)\n");
9303 else if (CHECK_FLAG(p->af_flags[afi][safi],
9304 PEER_FLAG_SEND_LARGE_COMMUNITY))
9305 vty_out(vty, "(large)\n");
9306 else if (CHECK_FLAG(p->af_flags[afi][safi],
9307 PEER_FLAG_SEND_EXT_COMMUNITY))
9308 vty_out(vty, "(extended)\n");
9309 else
9310 vty_out(vty, "(standard)\n");
9311 }
9312 if (CHECK_FLAG(p->af_flags[afi][safi],
9313 PEER_FLAG_DEFAULT_ORIGINATE)) {
9314 vty_out(vty, " Default information originate,");
9315
9316 if (p->default_rmap[afi][safi].name)
9317 vty_out(vty, " default route-map %s%s,",
9318 p->default_rmap[afi][safi].map ? "*"
9319 : "",
9320 p->default_rmap[afi][safi].name);
9321 if (paf && PAF_SUBGRP(paf)
9322 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9323 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9324 vty_out(vty, " default sent\n");
9325 else
9326 vty_out(vty, " default not sent\n");
9327 }
9328
dff8f48d
MK
9329 /* advertise-vni-all */
9330 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 9331 if (is_evpn_enabled())
dff8f48d
MK
9332 vty_out(vty, " advertise-all-vni\n");
9333 }
9334
d62a17ae 9335 if (filter->plist[FILTER_IN].name
9336 || filter->dlist[FILTER_IN].name
9337 || filter->aslist[FILTER_IN].name
9338 || filter->map[RMAP_IN].name)
9339 vty_out(vty, " Inbound path policy configured\n");
9340 if (filter->plist[FILTER_OUT].name
9341 || filter->dlist[FILTER_OUT].name
9342 || filter->aslist[FILTER_OUT].name
9343 || filter->map[RMAP_OUT].name || filter->usmap.name)
9344 vty_out(vty, " Outbound path policy configured\n");
9345
9346 /* prefix-list */
9347 if (filter->plist[FILTER_IN].name)
9348 vty_out(vty,
9349 " Incoming update prefix filter list is %s%s\n",
9350 filter->plist[FILTER_IN].plist ? "*" : "",
9351 filter->plist[FILTER_IN].name);
9352 if (filter->plist[FILTER_OUT].name)
9353 vty_out(vty,
9354 " Outgoing update prefix filter list is %s%s\n",
9355 filter->plist[FILTER_OUT].plist ? "*" : "",
9356 filter->plist[FILTER_OUT].name);
9357
9358 /* distribute-list */
9359 if (filter->dlist[FILTER_IN].name)
9360 vty_out(vty,
9361 " Incoming update network filter list is %s%s\n",
9362 filter->dlist[FILTER_IN].alist ? "*" : "",
9363 filter->dlist[FILTER_IN].name);
9364 if (filter->dlist[FILTER_OUT].name)
9365 vty_out(vty,
9366 " Outgoing update network filter list is %s%s\n",
9367 filter->dlist[FILTER_OUT].alist ? "*" : "",
9368 filter->dlist[FILTER_OUT].name);
9369
9370 /* filter-list. */
9371 if (filter->aslist[FILTER_IN].name)
9372 vty_out(vty,
9373 " Incoming update AS path filter list is %s%s\n",
9374 filter->aslist[FILTER_IN].aslist ? "*" : "",
9375 filter->aslist[FILTER_IN].name);
9376 if (filter->aslist[FILTER_OUT].name)
9377 vty_out(vty,
9378 " Outgoing update AS path filter list is %s%s\n",
9379 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9380 filter->aslist[FILTER_OUT].name);
9381
9382 /* route-map. */
9383 if (filter->map[RMAP_IN].name)
9384 vty_out(vty,
9385 " Route map for incoming advertisements is %s%s\n",
9386 filter->map[RMAP_IN].map ? "*" : "",
9387 filter->map[RMAP_IN].name);
9388 if (filter->map[RMAP_OUT].name)
9389 vty_out(vty,
9390 " Route map for outgoing advertisements is %s%s\n",
9391 filter->map[RMAP_OUT].map ? "*" : "",
9392 filter->map[RMAP_OUT].name);
9393
9dac9fc8
DA
9394 /* ebgp-requires-policy (inbound) */
9395 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9396 && !bgp_inbound_policy_exists(p, filter))
9397 vty_out(vty,
9398 " Inbound updates discarded due to missing policy\n");
9399
9400 /* ebgp-requires-policy (outbound) */
9401 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9402 && !bgp_outbound_policy_exists(p, filter))
9403 vty_out(vty,
9404 " Outbound updates discarded due to missing policy\n");
9405
d62a17ae 9406 /* unsuppress-map */
9407 if (filter->usmap.name)
9408 vty_out(vty,
9409 " Route map for selective unsuppress is %s%s\n",
9410 filter->usmap.map ? "*" : "",
9411 filter->usmap.name);
9412
9413 /* Receive prefix count */
a0a87037
DA
9414 vty_out(vty, " %" PRIu32 " accepted prefixes\n",
9415 p->pcount[afi][safi]);
d62a17ae 9416
9417 /* Maximum prefix */
9418 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037
DA
9419 vty_out(vty,
9420 " Maximum prefixes allowed %" PRIu32 "%s\n",
d62a17ae 9421 p->pmax[afi][safi],
9422 CHECK_FLAG(p->af_flags[afi][safi],
9423 PEER_FLAG_MAX_PREFIX_WARNING)
9424 ? " (warning-only)"
9425 : "");
9426 vty_out(vty, " Threshold for warning message %d%%",
9427 p->pmax_threshold[afi][safi]);
9428 if (p->pmax_restart[afi][safi])
9429 vty_out(vty, ", restart interval %d min",
9430 p->pmax_restart[afi][safi]);
9431 vty_out(vty, "\n");
9432 }
9433
9434 vty_out(vty, "\n");
9435 }
9436}
9437
9f049418 9438static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 9439 json_object *json)
718e3744 9440{
d62a17ae 9441 struct bgp *bgp;
9442 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9443 char timebuf[BGP_UPTIME_LEN];
9444 char dn_flag[2];
d62a17ae 9445 afi_t afi;
9446 safi_t safi;
d7c0a89a
QY
9447 uint16_t i;
9448 uint8_t *msg;
d62a17ae 9449 json_object *json_neigh = NULL;
9450 time_t epoch_tbuf;
718e3744 9451
d62a17ae 9452 bgp = p->bgp;
9453
9454 if (use_json)
9455 json_neigh = json_object_new_object();
9456
9457 memset(dn_flag, '\0', sizeof(dn_flag));
9458 if (!p->conf_if && peer_dynamic_neighbor(p))
9459 dn_flag[0] = '*';
9460
9461 if (!use_json) {
9462 if (p->conf_if) /* Configured interface name. */
9463 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9464 BGP_PEER_SU_UNSPEC(p)
9465 ? "None"
9466 : sockunion2str(&p->su, buf,
9467 SU_ADDRSTRLEN));
9468 else /* Configured IP address. */
9469 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9470 p->host);
9471 }
9472
9473 if (use_json) {
9474 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9475 json_object_string_add(json_neigh, "bgpNeighborAddr",
9476 "none");
9477 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9478 json_object_string_add(
9479 json_neigh, "bgpNeighborAddr",
9480 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9481
9482 json_object_int_add(json_neigh, "remoteAs", p->as);
9483
9484 if (p->change_local_as)
9485 json_object_int_add(json_neigh, "localAs",
9486 p->change_local_as);
9487 else
9488 json_object_int_add(json_neigh, "localAs", p->local_as);
9489
9490 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9491 json_object_boolean_true_add(json_neigh,
9492 "localAsNoPrepend");
9493
9494 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9495 json_object_boolean_true_add(json_neigh,
9496 "localAsReplaceAs");
9497 } else {
9498 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9499 || (p->as_type == AS_INTERNAL))
9500 vty_out(vty, "remote AS %u, ", p->as);
9501 else
9502 vty_out(vty, "remote AS Unspecified, ");
9503 vty_out(vty, "local AS %u%s%s, ",
9504 p->change_local_as ? p->change_local_as : p->local_as,
9505 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9506 ? " no-prepend"
9507 : "",
9508 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9509 ? " replace-as"
9510 : "");
9511 }
faa16034
DS
9512 /* peer type internal or confed-internal */
9513 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 9514 if (use_json) {
9515 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9516 json_object_boolean_true_add(
9517 json_neigh, "nbrConfedInternalLink");
9518 else
9519 json_object_boolean_true_add(json_neigh,
9520 "nbrInternalLink");
9521 } else {
9522 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9523 vty_out(vty, "confed-internal link\n");
9524 else
9525 vty_out(vty, "internal link\n");
9526 }
faa16034
DS
9527 /* peer type external or confed-external */
9528 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 9529 if (use_json) {
9530 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9531 json_object_boolean_true_add(
9532 json_neigh, "nbrConfedExternalLink");
9533 else
9534 json_object_boolean_true_add(json_neigh,
9535 "nbrExternalLink");
9536 } else {
9537 if (bgp_confederation_peers_check(bgp, p->as))
9538 vty_out(vty, "confed-external link\n");
9539 else
9540 vty_out(vty, "external link\n");
9541 }
faa16034
DS
9542 } else {
9543 if (use_json)
9544 json_object_boolean_true_add(json_neigh,
9545 "nbrUnspecifiedLink");
9546 else
9547 vty_out(vty, "unspecified link\n");
d62a17ae 9548 }
9549
9550 /* Description. */
9551 if (p->desc) {
9552 if (use_json)
9553 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9554 else
9555 vty_out(vty, " Description: %s\n", p->desc);
9556 }
9557
9558 if (p->hostname) {
9559 if (use_json) {
9560 if (p->hostname)
9561 json_object_string_add(json_neigh, "hostname",
9562 p->hostname);
9563
9564 if (p->domainname)
9565 json_object_string_add(json_neigh, "domainname",
9566 p->domainname);
9567 } else {
9568 if (p->domainname && (p->domainname[0] != '\0'))
9569 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9570 p->domainname);
9571 else
9572 vty_out(vty, "Hostname: %s\n", p->hostname);
9573 }
9574 }
9575
9576 /* Peer-group */
9577 if (p->group) {
9578 if (use_json) {
9579 json_object_string_add(json_neigh, "peerGroup",
9580 p->group->name);
9581
9582 if (dn_flag[0]) {
9583 struct prefix prefix, *range = NULL;
9584
9585 sockunion2hostprefix(&(p->su), &prefix);
9586 range = peer_group_lookup_dynamic_neighbor_range(
9587 p->group, &prefix);
9588
9589 if (range) {
9590 prefix2str(range, buf1, sizeof(buf1));
9591 json_object_string_add(
9592 json_neigh,
9593 "peerSubnetRangeGroup", buf1);
9594 }
9595 }
9596 } else {
9597 vty_out(vty,
9598 " Member of peer-group %s for session parameters\n",
9599 p->group->name);
9600
9601 if (dn_flag[0]) {
9602 struct prefix prefix, *range = NULL;
9603
9604 sockunion2hostprefix(&(p->su), &prefix);
9605 range = peer_group_lookup_dynamic_neighbor_range(
9606 p->group, &prefix);
9607
9608 if (range) {
9609 prefix2str(range, buf1, sizeof(buf1));
9610 vty_out(vty,
9611 " Belongs to the subnet range group: %s\n",
9612 buf1);
9613 }
9614 }
9615 }
9616 }
9617
9618 if (use_json) {
9619 /* Administrative shutdown. */
9620 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9621 json_object_boolean_true_add(json_neigh,
9622 "adminShutDown");
9623
9624 /* BGP Version. */
9625 json_object_int_add(json_neigh, "bgpVersion", 4);
9626 json_object_string_add(
9627 json_neigh, "remoteRouterId",
9628 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
9629 json_object_string_add(
9630 json_neigh, "localRouterId",
9631 inet_ntop(AF_INET, &bgp->router_id, buf1,
9632 sizeof(buf1)));
d62a17ae 9633
9634 /* Confederation */
9635 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9636 && bgp_confederation_peers_check(bgp, p->as))
9637 json_object_boolean_true_add(json_neigh,
9638 "nbrCommonAdmin");
9639
9640 /* Status. */
9641 json_object_string_add(
9642 json_neigh, "bgpState",
9643 lookup_msg(bgp_status_msg, p->status, NULL));
9644
9645 if (p->status == Established) {
9646 time_t uptime;
d62a17ae 9647
9648 uptime = bgp_clock();
9649 uptime -= p->uptime;
d62a17ae 9650 epoch_tbuf = time(NULL) - uptime;
9651
bee57a7a 9652#if CONFDATE > 20200101
a4d82a8a
PZ
9653 CPP_NOTICE(
9654 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9655#endif
9656 /*
9657 * bgpTimerUp was miliseconds that was accurate
9658 * up to 1 day, then the value returned
9659 * became garbage. So in order to provide
9660 * some level of backwards compatability,
9661 * we still provde the data, but now
9662 * we are returning the correct value
9663 * and also adding a new bgpTimerUpMsec
9664 * which will allow us to deprecate
9665 * this eventually
9666 */
d62a17ae 9667 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9668 uptime * 1000);
d3c7efed
DS
9669 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9670 uptime * 1000);
d62a17ae 9671 json_object_string_add(json_neigh, "bgpTimerUpString",
9672 peer_uptime(p->uptime, timebuf,
9673 BGP_UPTIME_LEN, 0,
9674 NULL));
9675 json_object_int_add(json_neigh,
9676 "bgpTimerUpEstablishedEpoch",
9677 epoch_tbuf);
9678 }
9679
9680 else if (p->status == Active) {
9681 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9682 json_object_string_add(json_neigh, "bgpStateIs",
9683 "passive");
9684 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9685 json_object_string_add(json_neigh, "bgpStateIs",
9686 "passiveNSF");
9687 }
9688
9689 /* read timer */
9690 time_t uptime;
9691 struct tm *tm;
9692
9693 uptime = bgp_clock();
9694 uptime -= p->readtime;
9695 tm = gmtime(&uptime);
9696 json_object_int_add(json_neigh, "bgpTimerLastRead",
9697 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9698 + (tm->tm_hour * 3600000));
9699
9700 uptime = bgp_clock();
9701 uptime -= p->last_write;
9702 tm = gmtime(&uptime);
9703 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9704 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9705 + (tm->tm_hour * 3600000));
9706
9707 uptime = bgp_clock();
9708 uptime -= p->update_time;
9709 tm = gmtime(&uptime);
9710 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9711 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9712 + (tm->tm_hour * 3600000));
9713
9714 /* Configured timer values. */
9715 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9716 p->v_holdtime * 1000);
9717 json_object_int_add(json_neigh,
9718 "bgpTimerKeepAliveIntervalMsecs",
9719 p->v_keepalive * 1000);
b90a8e13 9720 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9721 json_object_int_add(json_neigh,
9722 "bgpTimerConfiguredHoldTimeMsecs",
9723 p->holdtime * 1000);
9724 json_object_int_add(
9725 json_neigh,
9726 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9727 p->keepalive * 1000);
d25e4efc 9728 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9729 || (bgp->default_keepalive
9730 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9731 json_object_int_add(json_neigh,
9732 "bgpTimerConfiguredHoldTimeMsecs",
9733 bgp->default_holdtime);
9734 json_object_int_add(
9735 json_neigh,
9736 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9737 bgp->default_keepalive);
d62a17ae 9738 }
9739 } else {
9740 /* Administrative shutdown. */
9741 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9742 vty_out(vty, " Administratively shut down\n");
9743
9744 /* BGP Version. */
9745 vty_out(vty, " BGP version 4");
0e38aeb4 9746 vty_out(vty, ", remote router ID %s",
d62a17ae 9747 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
9748 vty_out(vty, ", local router ID %s\n",
9749 inet_ntop(AF_INET, &bgp->router_id, buf1,
9750 sizeof(buf1)));
d62a17ae 9751
9752 /* Confederation */
9753 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9754 && bgp_confederation_peers_check(bgp, p->as))
9755 vty_out(vty,
9756 " Neighbor under common administration\n");
9757
9758 /* Status. */
9759 vty_out(vty, " BGP state = %s",
9760 lookup_msg(bgp_status_msg, p->status, NULL));
9761
9762 if (p->status == Established)
9763 vty_out(vty, ", up for %8s",
9764 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9765 0, NULL));
9766
9767 else if (p->status == Active) {
9768 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9769 vty_out(vty, " (passive)");
9770 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9771 vty_out(vty, " (NSF passive)");
9772 }
9773 vty_out(vty, "\n");
9774
9775 /* read timer */
9776 vty_out(vty, " Last read %s",
9777 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9778 NULL));
9779 vty_out(vty, ", Last write %s\n",
9780 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9781 NULL));
9782
9783 /* Configured timer values. */
9784 vty_out(vty,
9785 " Hold time is %d, keepalive interval is %d seconds\n",
9786 p->v_holdtime, p->v_keepalive);
b90a8e13 9787 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9788 vty_out(vty, " Configured hold time is %d",
9789 p->holdtime);
9790 vty_out(vty, ", keepalive interval is %d seconds\n",
9791 p->keepalive);
d25e4efc 9792 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9793 || (bgp->default_keepalive
9794 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9795 vty_out(vty, " Configured hold time is %d",
9796 bgp->default_holdtime);
9797 vty_out(vty, ", keepalive interval is %d seconds\n",
9798 bgp->default_keepalive);
d62a17ae 9799 }
9800 }
9801 /* Capability. */
9802 if (p->status == Established) {
9803 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9804 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9805 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9806 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9807 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9808 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9809 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9810 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9811 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9812 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9813 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9814 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9815 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9816 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9817 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9818 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9819 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9820 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9821 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9822 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9823 if (use_json) {
9824 json_object *json_cap = NULL;
9825
9826 json_cap = json_object_new_object();
9827
9828 /* AS4 */
9829 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9830 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9831 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9832 && CHECK_FLAG(p->cap,
9833 PEER_CAP_AS4_RCV))
9834 json_object_string_add(
9835 json_cap, "4byteAs",
9836 "advertisedAndReceived");
9837 else if (CHECK_FLAG(p->cap,
9838 PEER_CAP_AS4_ADV))
9839 json_object_string_add(
9840 json_cap, "4byteAs",
9841 "advertised");
9842 else if (CHECK_FLAG(p->cap,
9843 PEER_CAP_AS4_RCV))
9844 json_object_string_add(
9845 json_cap, "4byteAs",
9846 "received");
9847 }
9848
9849 /* AddPath */
9850 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9851 || CHECK_FLAG(p->cap,
9852 PEER_CAP_ADDPATH_ADV)) {
9853 json_object *json_add = NULL;
9854 const char *print_store;
9855
9856 json_add = json_object_new_object();
9857
05c7a1cc
QY
9858 FOREACH_AFI_SAFI (afi, safi) {
9859 json_object *json_sub = NULL;
9860 json_sub =
9861 json_object_new_object();
5cb5f4d0
DD
9862 print_store = get_afi_safi_str(
9863 afi, safi, true);
d62a17ae 9864
05c7a1cc
QY
9865 if (CHECK_FLAG(
9866 p->af_cap[afi]
9867 [safi],
9868 PEER_CAP_ADDPATH_AF_TX_ADV)
9869 || CHECK_FLAG(
9870 p->af_cap[afi]
9871 [safi],
9872 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9873 if (CHECK_FLAG(
9874 p->af_cap
9875 [afi]
9876 [safi],
9877 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9878 && CHECK_FLAG(
d62a17ae 9879 p->af_cap
9880 [afi]
9881 [safi],
05c7a1cc
QY
9882 PEER_CAP_ADDPATH_AF_TX_RCV))
9883 json_object_boolean_true_add(
9884 json_sub,
9885 "txAdvertisedAndReceived");
9886 else if (
9887 CHECK_FLAG(
9888 p->af_cap
9889 [afi]
9890 [safi],
9891 PEER_CAP_ADDPATH_AF_TX_ADV))
9892 json_object_boolean_true_add(
9893 json_sub,
9894 "txAdvertised");
9895 else if (
9896 CHECK_FLAG(
9897 p->af_cap
9898 [afi]
9899 [safi],
9900 PEER_CAP_ADDPATH_AF_TX_RCV))
9901 json_object_boolean_true_add(
9902 json_sub,
9903 "txReceived");
9904 }
d62a17ae 9905
05c7a1cc
QY
9906 if (CHECK_FLAG(
9907 p->af_cap[afi]
9908 [safi],
9909 PEER_CAP_ADDPATH_AF_RX_ADV)
9910 || CHECK_FLAG(
9911 p->af_cap[afi]
9912 [safi],
9913 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9914 if (CHECK_FLAG(
9915 p->af_cap
9916 [afi]
9917 [safi],
9918 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9919 && CHECK_FLAG(
d62a17ae 9920 p->af_cap
9921 [afi]
9922 [safi],
9923 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9924 json_object_boolean_true_add(
9925 json_sub,
9926 "rxAdvertisedAndReceived");
9927 else if (
9928 CHECK_FLAG(
9929 p->af_cap
9930 [afi]
9931 [safi],
9932 PEER_CAP_ADDPATH_AF_RX_ADV))
9933 json_object_boolean_true_add(
9934 json_sub,
9935 "rxAdvertised");
9936 else if (
9937 CHECK_FLAG(
9938 p->af_cap
9939 [afi]
9940 [safi],
9941 PEER_CAP_ADDPATH_AF_RX_RCV))
9942 json_object_boolean_true_add(
9943 json_sub,
9944 "rxReceived");
d62a17ae 9945 }
9946
05c7a1cc
QY
9947 if (CHECK_FLAG(
9948 p->af_cap[afi]
9949 [safi],
9950 PEER_CAP_ADDPATH_AF_TX_ADV)
9951 || CHECK_FLAG(
9952 p->af_cap[afi]
9953 [safi],
9954 PEER_CAP_ADDPATH_AF_TX_RCV)
9955 || CHECK_FLAG(
9956 p->af_cap[afi]
9957 [safi],
9958 PEER_CAP_ADDPATH_AF_RX_ADV)
9959 || CHECK_FLAG(
9960 p->af_cap[afi]
9961 [safi],
9962 PEER_CAP_ADDPATH_AF_RX_RCV))
9963 json_object_object_add(
9964 json_add,
9965 print_store,
9966 json_sub);
9967 else
9968 json_object_free(
9969 json_sub);
9970 }
9971
d62a17ae 9972 json_object_object_add(
9973 json_cap, "addPath", json_add);
9974 }
9975
9976 /* Dynamic */
9977 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9978 || CHECK_FLAG(p->cap,
9979 PEER_CAP_DYNAMIC_ADV)) {
9980 if (CHECK_FLAG(p->cap,
9981 PEER_CAP_DYNAMIC_ADV)
9982 && CHECK_FLAG(p->cap,
9983 PEER_CAP_DYNAMIC_RCV))
9984 json_object_string_add(
9985 json_cap, "dynamic",
9986 "advertisedAndReceived");
9987 else if (CHECK_FLAG(
9988 p->cap,
9989 PEER_CAP_DYNAMIC_ADV))
9990 json_object_string_add(
9991 json_cap, "dynamic",
9992 "advertised");
9993 else if (CHECK_FLAG(
9994 p->cap,
9995 PEER_CAP_DYNAMIC_RCV))
9996 json_object_string_add(
9997 json_cap, "dynamic",
9998 "received");
9999 }
10000
10001 /* Extended nexthop */
10002 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10003 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10004 json_object *json_nxt = NULL;
10005 const char *print_store;
10006
10007
10008 if (CHECK_FLAG(p->cap,
10009 PEER_CAP_ENHE_ADV)
10010 && CHECK_FLAG(p->cap,
10011 PEER_CAP_ENHE_RCV))
10012 json_object_string_add(
10013 json_cap,
10014 "extendedNexthop",
10015 "advertisedAndReceived");
10016 else if (CHECK_FLAG(p->cap,
10017 PEER_CAP_ENHE_ADV))
10018 json_object_string_add(
10019 json_cap,
10020 "extendedNexthop",
10021 "advertised");
10022 else if (CHECK_FLAG(p->cap,
10023 PEER_CAP_ENHE_RCV))
10024 json_object_string_add(
10025 json_cap,
10026 "extendedNexthop",
10027 "received");
10028
10029 if (CHECK_FLAG(p->cap,
10030 PEER_CAP_ENHE_RCV)) {
10031 json_nxt =
10032 json_object_new_object();
10033
10034 for (safi = SAFI_UNICAST;
10035 safi < SAFI_MAX; safi++) {
10036 if (CHECK_FLAG(
10037 p->af_cap
10038 [AFI_IP]
10039 [safi],
10040 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 10041 print_store = get_afi_safi_str(
d62a17ae 10042 AFI_IP,
5cb5f4d0 10043 safi, true);
d62a17ae 10044 json_object_string_add(
10045 json_nxt,
10046 print_store,
54f29523 10047 "recieved"); /* misspelled for compatibility */
d62a17ae 10048 }
10049 }
10050 json_object_object_add(
10051 json_cap,
10052 "extendedNexthopFamililesByPeer",
10053 json_nxt);
10054 }
10055 }
10056
10057 /* Route Refresh */
10058 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10059 || CHECK_FLAG(p->cap,
10060 PEER_CAP_REFRESH_NEW_RCV)
10061 || CHECK_FLAG(p->cap,
10062 PEER_CAP_REFRESH_OLD_RCV)) {
10063 if (CHECK_FLAG(p->cap,
10064 PEER_CAP_REFRESH_ADV)
10065 && (CHECK_FLAG(
10066 p->cap,
10067 PEER_CAP_REFRESH_NEW_RCV)
10068 || CHECK_FLAG(
10069 p->cap,
10070 PEER_CAP_REFRESH_OLD_RCV))) {
10071 if (CHECK_FLAG(
10072 p->cap,
10073 PEER_CAP_REFRESH_OLD_RCV)
10074 && CHECK_FLAG(
10075 p->cap,
10076 PEER_CAP_REFRESH_NEW_RCV))
10077 json_object_string_add(
10078 json_cap,
10079 "routeRefresh",
10080 "advertisedAndReceivedOldNew");
10081 else {
10082 if (CHECK_FLAG(
10083 p->cap,
10084 PEER_CAP_REFRESH_OLD_RCV))
10085 json_object_string_add(
10086 json_cap,
10087 "routeRefresh",
10088 "advertisedAndReceivedOld");
10089 else
10090 json_object_string_add(
10091 json_cap,
10092 "routeRefresh",
10093 "advertisedAndReceivedNew");
10094 }
10095 } else if (
10096 CHECK_FLAG(
10097 p->cap,
10098 PEER_CAP_REFRESH_ADV))
10099 json_object_string_add(
10100 json_cap,
10101 "routeRefresh",
10102 "advertised");
10103 else if (
10104 CHECK_FLAG(
10105 p->cap,
10106 PEER_CAP_REFRESH_NEW_RCV)
10107 || CHECK_FLAG(
10108 p->cap,
10109 PEER_CAP_REFRESH_OLD_RCV))
10110 json_object_string_add(
10111 json_cap,
10112 "routeRefresh",
10113 "received");
10114 }
10115
10116 /* Multiprotocol Extensions */
10117 json_object *json_multi = NULL;
10118 json_multi = json_object_new_object();
10119
05c7a1cc
QY
10120 FOREACH_AFI_SAFI (afi, safi) {
10121 if (p->afc_adv[afi][safi]
10122 || p->afc_recv[afi][safi]) {
10123 json_object *json_exten = NULL;
10124 json_exten =
10125 json_object_new_object();
10126
d62a17ae 10127 if (p->afc_adv[afi][safi]
05c7a1cc
QY
10128 && p->afc_recv[afi][safi])
10129 json_object_boolean_true_add(
10130 json_exten,
10131 "advertisedAndReceived");
10132 else if (p->afc_adv[afi][safi])
10133 json_object_boolean_true_add(
10134 json_exten,
10135 "advertised");
10136 else if (p->afc_recv[afi][safi])
10137 json_object_boolean_true_add(
10138 json_exten,
10139 "received");
d62a17ae 10140
05c7a1cc
QY
10141 json_object_object_add(
10142 json_multi,
5cb5f4d0
DD
10143 get_afi_safi_str(afi,
10144 safi,
10145 true),
05c7a1cc 10146 json_exten);
d62a17ae 10147 }
10148 }
10149 json_object_object_add(
10150 json_cap, "multiprotocolExtensions",
10151 json_multi);
10152
d77114b7 10153 /* Hostname capabilities */
60466a63 10154 json_object *json_hname = NULL;
d77114b7
MK
10155
10156 json_hname = json_object_new_object();
10157
10158 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10159 json_object_string_add(
60466a63
QY
10160 json_hname, "advHostName",
10161 bgp->peer_self->hostname
10162 ? bgp->peer_self
10163 ->hostname
d77114b7
MK
10164 : "n/a");
10165 json_object_string_add(
60466a63
QY
10166 json_hname, "advDomainName",
10167 bgp->peer_self->domainname
10168 ? bgp->peer_self
10169 ->domainname
d77114b7
MK
10170 : "n/a");
10171 }
10172
10173
10174 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10175 json_object_string_add(
60466a63
QY
10176 json_hname, "rcvHostName",
10177 p->hostname ? p->hostname
10178 : "n/a");
d77114b7 10179 json_object_string_add(
60466a63
QY
10180 json_hname, "rcvDomainName",
10181 p->domainname ? p->domainname
10182 : "n/a");
d77114b7
MK
10183 }
10184
60466a63 10185 json_object_object_add(json_cap, "hostName",
d77114b7
MK
10186 json_hname);
10187
d62a17ae 10188 /* Gracefull Restart */
10189 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10190 || CHECK_FLAG(p->cap,
10191 PEER_CAP_RESTART_ADV)) {
10192 if (CHECK_FLAG(p->cap,
10193 PEER_CAP_RESTART_ADV)
10194 && CHECK_FLAG(p->cap,
10195 PEER_CAP_RESTART_RCV))
10196 json_object_string_add(
10197 json_cap,
10198 "gracefulRestart",
10199 "advertisedAndReceived");
10200 else if (CHECK_FLAG(
10201 p->cap,
10202 PEER_CAP_RESTART_ADV))
10203 json_object_string_add(
10204 json_cap,
10205 "gracefulRestartCapability",
10206 "advertised");
10207 else if (CHECK_FLAG(
10208 p->cap,
10209 PEER_CAP_RESTART_RCV))
10210 json_object_string_add(
10211 json_cap,
10212 "gracefulRestartCapability",
10213 "received");
10214
10215 if (CHECK_FLAG(p->cap,
10216 PEER_CAP_RESTART_RCV)) {
10217 int restart_af_count = 0;
10218 json_object *json_restart =
10219 NULL;
10220 json_restart =
10221 json_object_new_object();
10222
10223 json_object_int_add(
10224 json_cap,
10225 "gracefulRestartRemoteTimerMsecs",
10226 p->v_gr_restart * 1000);
10227
05c7a1cc
QY
10228 FOREACH_AFI_SAFI (afi, safi) {
10229 if (CHECK_FLAG(
10230 p->af_cap
10231 [afi]
10232 [safi],
10233 PEER_CAP_RESTART_AF_RCV)) {
10234 json_object *
10235 json_sub =
10236 NULL;
10237 json_sub =
10238 json_object_new_object();
10239
d62a17ae 10240 if (CHECK_FLAG(
10241 p->af_cap
10242 [afi]
10243 [safi],
05c7a1cc
QY
10244 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10245 json_object_boolean_true_add(
10246 json_sub,
10247 "preserved");
10248 restart_af_count++;
10249 json_object_object_add(
10250 json_restart,
5cb5f4d0 10251 get_afi_safi_str(
05c7a1cc 10252 afi,
5cb5f4d0
DD
10253 safi,
10254 true),
05c7a1cc 10255 json_sub);
d62a17ae 10256 }
10257 }
10258 if (!restart_af_count) {
10259 json_object_string_add(
10260 json_cap,
10261 "addressFamiliesByPeer",
10262 "none");
10263 json_object_free(
10264 json_restart);
10265 } else
10266 json_object_object_add(
10267 json_cap,
10268 "addressFamiliesByPeer",
10269 json_restart);
10270 }
10271 }
10272 json_object_object_add(json_neigh,
10273 "neighborCapabilities",
10274 json_cap);
10275 } else {
10276 vty_out(vty, " Neighbor capabilities:\n");
10277
10278 /* AS4 */
10279 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10280 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10281 vty_out(vty, " 4 Byte AS:");
10282 if (CHECK_FLAG(p->cap,
10283 PEER_CAP_AS4_ADV))
10284 vty_out(vty, " advertised");
10285 if (CHECK_FLAG(p->cap,
10286 PEER_CAP_AS4_RCV))
10287 vty_out(vty, " %sreceived",
10288 CHECK_FLAG(
10289 p->cap,
10290 PEER_CAP_AS4_ADV)
10291 ? "and "
10292 : "");
10293 vty_out(vty, "\n");
10294 }
10295
10296 /* AddPath */
10297 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10298 || CHECK_FLAG(p->cap,
10299 PEER_CAP_ADDPATH_ADV)) {
10300 vty_out(vty, " AddPath:\n");
10301
05c7a1cc
QY
10302 FOREACH_AFI_SAFI (afi, safi) {
10303 if (CHECK_FLAG(
10304 p->af_cap[afi]
10305 [safi],
10306 PEER_CAP_ADDPATH_AF_TX_ADV)
10307 || CHECK_FLAG(
10308 p->af_cap[afi]
10309 [safi],
10310 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10311 vty_out(vty,
10312 " %s: TX ",
5cb5f4d0 10313 get_afi_safi_str(
05c7a1cc 10314 afi,
5cb5f4d0
DD
10315 safi,
10316 false));
05c7a1cc 10317
d62a17ae 10318 if (CHECK_FLAG(
10319 p->af_cap
10320 [afi]
10321 [safi],
05c7a1cc 10322 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 10323 vty_out(vty,
05c7a1cc 10324 "advertised %s",
5cb5f4d0 10325 get_afi_safi_str(
d62a17ae 10326 afi,
5cb5f4d0
DD
10327 safi,
10328 false));
d62a17ae 10329
05c7a1cc
QY
10330 if (CHECK_FLAG(
10331 p->af_cap
10332 [afi]
10333 [safi],
10334 PEER_CAP_ADDPATH_AF_TX_RCV))
10335 vty_out(vty,
10336 "%sreceived",
10337 CHECK_FLAG(
10338 p->af_cap
10339 [afi]
10340 [safi],
10341 PEER_CAP_ADDPATH_AF_TX_ADV)
10342 ? " and "
10343 : "");
d62a17ae 10344
05c7a1cc
QY
10345 vty_out(vty, "\n");
10346 }
d62a17ae 10347
05c7a1cc
QY
10348 if (CHECK_FLAG(
10349 p->af_cap[afi]
10350 [safi],
10351 PEER_CAP_ADDPATH_AF_RX_ADV)
10352 || CHECK_FLAG(
10353 p->af_cap[afi]
10354 [safi],
10355 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10356 vty_out(vty,
10357 " %s: RX ",
5cb5f4d0 10358 get_afi_safi_str(
05c7a1cc 10359 afi,
5cb5f4d0
DD
10360 safi,
10361 false));
d62a17ae 10362
10363 if (CHECK_FLAG(
10364 p->af_cap
10365 [afi]
10366 [safi],
05c7a1cc 10367 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 10368 vty_out(vty,
05c7a1cc 10369 "advertised %s",
5cb5f4d0 10370 get_afi_safi_str(
d62a17ae 10371 afi,
5cb5f4d0
DD
10372 safi,
10373 false));
d62a17ae 10374
05c7a1cc
QY
10375 if (CHECK_FLAG(
10376 p->af_cap
10377 [afi]
10378 [safi],
10379 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 10380 vty_out(vty,
05c7a1cc
QY
10381 "%sreceived",
10382 CHECK_FLAG(
10383 p->af_cap
10384 [afi]
10385 [safi],
10386 PEER_CAP_ADDPATH_AF_RX_ADV)
10387 ? " and "
10388 : "");
10389
10390 vty_out(vty, "\n");
d62a17ae 10391 }
05c7a1cc 10392 }
d62a17ae 10393 }
10394
10395 /* Dynamic */
10396 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10397 || CHECK_FLAG(p->cap,
10398 PEER_CAP_DYNAMIC_ADV)) {
10399 vty_out(vty, " Dynamic:");
10400 if (CHECK_FLAG(p->cap,
10401 PEER_CAP_DYNAMIC_ADV))
10402 vty_out(vty, " advertised");
10403 if (CHECK_FLAG(p->cap,
10404 PEER_CAP_DYNAMIC_RCV))
10405 vty_out(vty, " %sreceived",
10406 CHECK_FLAG(
10407 p->cap,
10408 PEER_CAP_DYNAMIC_ADV)
10409 ? "and "
10410 : "");
10411 vty_out(vty, "\n");
10412 }
10413
10414 /* Extended nexthop */
10415 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10416 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10417 vty_out(vty, " Extended nexthop:");
10418 if (CHECK_FLAG(p->cap,
10419 PEER_CAP_ENHE_ADV))
10420 vty_out(vty, " advertised");
10421 if (CHECK_FLAG(p->cap,
10422 PEER_CAP_ENHE_RCV))
10423 vty_out(vty, " %sreceived",
10424 CHECK_FLAG(
10425 p->cap,
10426 PEER_CAP_ENHE_ADV)
10427 ? "and "
10428 : "");
10429 vty_out(vty, "\n");
10430
10431 if (CHECK_FLAG(p->cap,
10432 PEER_CAP_ENHE_RCV)) {
10433 vty_out(vty,
10434 " Address families by peer:\n ");
10435 for (safi = SAFI_UNICAST;
10436 safi < SAFI_MAX; safi++)
10437 if (CHECK_FLAG(
10438 p->af_cap
10439 [AFI_IP]
10440 [safi],
10441 PEER_CAP_ENHE_AF_RCV))
10442 vty_out(vty,
10443 " %s\n",
5cb5f4d0 10444 get_afi_safi_str(
d62a17ae 10445 AFI_IP,
5cb5f4d0
DD
10446 safi,
10447 false));
d62a17ae 10448 }
10449 }
10450
10451 /* Route Refresh */
10452 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10453 || CHECK_FLAG(p->cap,
10454 PEER_CAP_REFRESH_NEW_RCV)
10455 || CHECK_FLAG(p->cap,
10456 PEER_CAP_REFRESH_OLD_RCV)) {
10457 vty_out(vty, " Route refresh:");
10458 if (CHECK_FLAG(p->cap,
10459 PEER_CAP_REFRESH_ADV))
10460 vty_out(vty, " advertised");
10461 if (CHECK_FLAG(p->cap,
10462 PEER_CAP_REFRESH_NEW_RCV)
10463 || CHECK_FLAG(
10464 p->cap,
10465 PEER_CAP_REFRESH_OLD_RCV))
10466 vty_out(vty, " %sreceived(%s)",
10467 CHECK_FLAG(
10468 p->cap,
10469 PEER_CAP_REFRESH_ADV)
10470 ? "and "
10471 : "",
10472 (CHECK_FLAG(
10473 p->cap,
10474 PEER_CAP_REFRESH_OLD_RCV)
10475 && CHECK_FLAG(
10476 p->cap,
10477 PEER_CAP_REFRESH_NEW_RCV))
10478 ? "old & new"
10479 : CHECK_FLAG(
10480 p->cap,
10481 PEER_CAP_REFRESH_OLD_RCV)
10482 ? "old"
10483 : "new");
10484
10485 vty_out(vty, "\n");
10486 }
10487
10488 /* Multiprotocol Extensions */
05c7a1cc
QY
10489 FOREACH_AFI_SAFI (afi, safi)
10490 if (p->afc_adv[afi][safi]
10491 || p->afc_recv[afi][safi]) {
10492 vty_out(vty,
10493 " Address Family %s:",
5cb5f4d0
DD
10494 get_afi_safi_str(
10495 afi,
10496 safi,
10497 false));
05c7a1cc 10498 if (p->afc_adv[afi][safi])
d62a17ae 10499 vty_out(vty,
05c7a1cc
QY
10500 " advertised");
10501 if (p->afc_recv[afi][safi])
10502 vty_out(vty,
10503 " %sreceived",
10504 p->afc_adv[afi]
10505 [safi]
10506 ? "and "
10507 : "");
10508 vty_out(vty, "\n");
10509 }
d62a17ae 10510
10511 /* Hostname capability */
60466a63 10512 vty_out(vty, " Hostname Capability:");
d77114b7
MK
10513
10514 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
10515 vty_out(vty,
10516 " advertised (name: %s,domain name: %s)",
60466a63
QY
10517 bgp->peer_self->hostname
10518 ? bgp->peer_self
10519 ->hostname
d77114b7 10520 : "n/a",
60466a63
QY
10521 bgp->peer_self->domainname
10522 ? bgp->peer_self
10523 ->domainname
d77114b7
MK
10524 : "n/a");
10525 } else {
10526 vty_out(vty, " not advertised");
d62a17ae 10527 }
10528
d77114b7 10529 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10530 vty_out(vty,
10531 " received (name: %s,domain name: %s)",
60466a63
QY
10532 p->hostname ? p->hostname
10533 : "n/a",
10534 p->domainname ? p->domainname
10535 : "n/a");
d77114b7
MK
10536 } else {
10537 vty_out(vty, " not received");
10538 }
10539
10540 vty_out(vty, "\n");
10541
d62a17ae 10542 /* Gracefull Restart */
10543 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10544 || CHECK_FLAG(p->cap,
10545 PEER_CAP_RESTART_ADV)) {
10546 vty_out(vty,
10547 " Graceful Restart Capabilty:");
10548 if (CHECK_FLAG(p->cap,
10549 PEER_CAP_RESTART_ADV))
10550 vty_out(vty, " advertised");
10551 if (CHECK_FLAG(p->cap,
10552 PEER_CAP_RESTART_RCV))
10553 vty_out(vty, " %sreceived",
10554 CHECK_FLAG(
10555 p->cap,
10556 PEER_CAP_RESTART_ADV)
10557 ? "and "
10558 : "");
10559 vty_out(vty, "\n");
10560
10561 if (CHECK_FLAG(p->cap,
10562 PEER_CAP_RESTART_RCV)) {
10563 int restart_af_count = 0;
10564
10565 vty_out(vty,
10566 " Remote Restart timer is %d seconds\n",
10567 p->v_gr_restart);
10568 vty_out(vty,
10569 " Address families by peer:\n ");
10570
05c7a1cc
QY
10571 FOREACH_AFI_SAFI (afi, safi)
10572 if (CHECK_FLAG(
10573 p->af_cap
10574 [afi]
10575 [safi],
10576 PEER_CAP_RESTART_AF_RCV)) {
10577 vty_out(vty,
10578 "%s%s(%s)",
10579 restart_af_count
10580 ? ", "
10581 : "",
5cb5f4d0 10582 get_afi_safi_str(
05c7a1cc 10583 afi,
5cb5f4d0
DD
10584 safi,
10585 false),
05c7a1cc
QY
10586 CHECK_FLAG(
10587 p->af_cap
10588 [afi]
10589 [safi],
10590 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10591 ? "preserved"
10592 : "not preserved");
10593 restart_af_count++;
10594 }
d62a17ae 10595 if (!restart_af_count)
10596 vty_out(vty, "none");
10597 vty_out(vty, "\n");
10598 }
10599 }
10600 }
10601 }
10602 }
10603
10604 /* graceful restart information */
10605 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10606 || p->t_gr_stale) {
10607 json_object *json_grace = NULL;
10608 json_object *json_grace_send = NULL;
10609 json_object *json_grace_recv = NULL;
10610 int eor_send_af_count = 0;
10611 int eor_receive_af_count = 0;
10612
10613 if (use_json) {
10614 json_grace = json_object_new_object();
10615 json_grace_send = json_object_new_object();
10616 json_grace_recv = json_object_new_object();
10617
10618 if (p->status == Established) {
05c7a1cc
QY
10619 FOREACH_AFI_SAFI (afi, safi) {
10620 if (CHECK_FLAG(p->af_sflags[afi][safi],
10621 PEER_STATUS_EOR_SEND)) {
10622 json_object_boolean_true_add(
10623 json_grace_send,
5cb5f4d0
DD
10624 get_afi_safi_str(afi,
10625 safi,
10626 true));
05c7a1cc 10627 eor_send_af_count++;
d62a17ae 10628 }
10629 }
05c7a1cc
QY
10630 FOREACH_AFI_SAFI (afi, safi) {
10631 if (CHECK_FLAG(
10632 p->af_sflags[afi][safi],
10633 PEER_STATUS_EOR_RECEIVED)) {
10634 json_object_boolean_true_add(
10635 json_grace_recv,
5cb5f4d0
DD
10636 get_afi_safi_str(afi,
10637 safi,
10638 true));
05c7a1cc 10639 eor_receive_af_count++;
d62a17ae 10640 }
10641 }
10642 }
10643
10644 json_object_object_add(json_grace, "endOfRibSend",
10645 json_grace_send);
10646 json_object_object_add(json_grace, "endOfRibRecv",
10647 json_grace_recv);
10648
10649 if (p->t_gr_restart)
10650 json_object_int_add(json_grace,
10651 "gracefulRestartTimerMsecs",
10652 thread_timer_remain_second(
10653 p->t_gr_restart)
10654 * 1000);
10655
10656 if (p->t_gr_stale)
10657 json_object_int_add(
10658 json_grace,
10659 "gracefulStalepathTimerMsecs",
10660 thread_timer_remain_second(
10661 p->t_gr_stale)
10662 * 1000);
10663
10664 json_object_object_add(
10665 json_neigh, "gracefulRestartInfo", json_grace);
10666 } else {
0437e105 10667 vty_out(vty, " Graceful restart information:\n");
d62a17ae 10668 if (p->status == Established) {
10669 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10670 FOREACH_AFI_SAFI (afi, safi) {
10671 if (CHECK_FLAG(p->af_sflags[afi][safi],
10672 PEER_STATUS_EOR_SEND)) {
10673 vty_out(vty, "%s%s",
10674 eor_send_af_count ? ", "
10675 : "",
5cb5f4d0
DD
10676 get_afi_safi_str(afi,
10677 safi,
10678 false));
05c7a1cc 10679 eor_send_af_count++;
d62a17ae 10680 }
10681 }
10682 vty_out(vty, "\n");
10683 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10684 FOREACH_AFI_SAFI (afi, safi) {
10685 if (CHECK_FLAG(
10686 p->af_sflags[afi][safi],
10687 PEER_STATUS_EOR_RECEIVED)) {
10688 vty_out(vty, "%s%s",
10689 eor_receive_af_count
10690 ? ", "
10691 : "",
5cb5f4d0
DD
10692 get_afi_safi_str(afi,
10693 safi,
10694 false));
05c7a1cc 10695 eor_receive_af_count++;
d62a17ae 10696 }
10697 }
10698 vty_out(vty, "\n");
10699 }
10700
10701 if (p->t_gr_restart)
10702 vty_out(vty,
10703 " The remaining time of restart timer is %ld\n",
10704 thread_timer_remain_second(
10705 p->t_gr_restart));
10706
10707 if (p->t_gr_stale)
10708 vty_out(vty,
10709 " The remaining time of stalepath timer is %ld\n",
10710 thread_timer_remain_second(
10711 p->t_gr_stale));
10712 }
10713 }
10714 if (use_json) {
10715 json_object *json_stat = NULL;
10716 json_stat = json_object_new_object();
10717 /* Packet counts. */
10718 json_object_int_add(json_stat, "depthInq", 0);
10719 json_object_int_add(json_stat, "depthOutq",
10720 (unsigned long)p->obuf->count);
0112e9e0
QY
10721 json_object_int_add(json_stat, "opensSent",
10722 atomic_load_explicit(&p->open_out,
10723 memory_order_relaxed));
10724 json_object_int_add(json_stat, "opensRecv",
10725 atomic_load_explicit(&p->open_in,
10726 memory_order_relaxed));
d62a17ae 10727 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10728 atomic_load_explicit(&p->notify_out,
10729 memory_order_relaxed));
d62a17ae 10730 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10731 atomic_load_explicit(&p->notify_in,
10732 memory_order_relaxed));
10733 json_object_int_add(json_stat, "updatesSent",
10734 atomic_load_explicit(&p->update_out,
10735 memory_order_relaxed));
10736 json_object_int_add(json_stat, "updatesRecv",
10737 atomic_load_explicit(&p->update_in,
10738 memory_order_relaxed));
d62a17ae 10739 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10740 atomic_load_explicit(&p->keepalive_out,
10741 memory_order_relaxed));
d62a17ae 10742 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10743 atomic_load_explicit(&p->keepalive_in,
10744 memory_order_relaxed));
d62a17ae 10745 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10746 atomic_load_explicit(&p->refresh_out,
10747 memory_order_relaxed));
d62a17ae 10748 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10749 atomic_load_explicit(&p->refresh_in,
10750 memory_order_relaxed));
d62a17ae 10751 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10752 atomic_load_explicit(&p->dynamic_cap_out,
10753 memory_order_relaxed));
d62a17ae 10754 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10755 atomic_load_explicit(&p->dynamic_cap_in,
10756 memory_order_relaxed));
10757 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10758 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10759 json_object_object_add(json_neigh, "messageStats", json_stat);
10760 } else {
10761 /* Packet counts. */
10762 vty_out(vty, " Message statistics:\n");
10763 vty_out(vty, " Inq depth is 0\n");
10764 vty_out(vty, " Outq depth is %lu\n",
10765 (unsigned long)p->obuf->count);
10766 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10767 vty_out(vty, " Opens: %10d %10d\n",
10768 atomic_load_explicit(&p->open_out,
10769 memory_order_relaxed),
10770 atomic_load_explicit(&p->open_in,
10771 memory_order_relaxed));
10772 vty_out(vty, " Notifications: %10d %10d\n",
10773 atomic_load_explicit(&p->notify_out,
10774 memory_order_relaxed),
10775 atomic_load_explicit(&p->notify_in,
10776 memory_order_relaxed));
10777 vty_out(vty, " Updates: %10d %10d\n",
10778 atomic_load_explicit(&p->update_out,
10779 memory_order_relaxed),
10780 atomic_load_explicit(&p->update_in,
10781 memory_order_relaxed));
10782 vty_out(vty, " Keepalives: %10d %10d\n",
10783 atomic_load_explicit(&p->keepalive_out,
10784 memory_order_relaxed),
10785 atomic_load_explicit(&p->keepalive_in,
10786 memory_order_relaxed));
10787 vty_out(vty, " Route Refresh: %10d %10d\n",
10788 atomic_load_explicit(&p->refresh_out,
10789 memory_order_relaxed),
10790 atomic_load_explicit(&p->refresh_in,
10791 memory_order_relaxed));
d62a17ae 10792 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10793 atomic_load_explicit(&p->dynamic_cap_out,
10794 memory_order_relaxed),
10795 atomic_load_explicit(&p->dynamic_cap_in,
10796 memory_order_relaxed));
10797 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10798 PEER_TOTAL_RX(p));
d62a17ae 10799 }
10800
10801 if (use_json) {
10802 /* advertisement-interval */
10803 json_object_int_add(json_neigh,
10804 "minBtwnAdvertisementRunsTimerMsecs",
10805 p->v_routeadv * 1000);
10806
10807 /* Update-source. */
10808 if (p->update_if || p->update_source) {
10809 if (p->update_if)
10810 json_object_string_add(json_neigh,
10811 "updateSource",
10812 p->update_if);
10813 else if (p->update_source)
10814 json_object_string_add(
10815 json_neigh, "updateSource",
10816 sockunion2str(p->update_source, buf1,
10817 SU_ADDRSTRLEN));
10818 }
10819 } else {
10820 /* advertisement-interval */
10821 vty_out(vty,
10822 " Minimum time between advertisement runs is %d seconds\n",
10823 p->v_routeadv);
10824
10825 /* Update-source. */
10826 if (p->update_if || p->update_source) {
10827 vty_out(vty, " Update source is ");
10828 if (p->update_if)
10829 vty_out(vty, "%s", p->update_if);
10830 else if (p->update_source)
10831 vty_out(vty, "%s",
10832 sockunion2str(p->update_source, buf1,
10833 SU_ADDRSTRLEN));
10834 vty_out(vty, "\n");
10835 }
10836
10837 vty_out(vty, "\n");
10838 }
10839
10840 /* Address Family Information */
10841 json_object *json_hold = NULL;
10842
10843 if (use_json)
10844 json_hold = json_object_new_object();
10845
05c7a1cc
QY
10846 FOREACH_AFI_SAFI (afi, safi)
10847 if (p->afc[afi][safi])
10848 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10849 json_hold);
d62a17ae 10850
10851 if (use_json) {
10852 json_object_object_add(json_neigh, "addressFamilyInfo",
10853 json_hold);
10854 json_object_int_add(json_neigh, "connectionsEstablished",
10855 p->established);
10856 json_object_int_add(json_neigh, "connectionsDropped",
10857 p->dropped);
10858 } else
10859 vty_out(vty, " Connections established %d; dropped %d\n",
10860 p->established, p->dropped);
10861
10862 if (!p->last_reset) {
10863 if (use_json)
10864 json_object_string_add(json_neigh, "lastReset",
10865 "never");
10866 else
10867 vty_out(vty, " Last reset never\n");
10868 } else {
10869 if (use_json) {
10870 time_t uptime;
10871 struct tm *tm;
10872
10873 uptime = bgp_clock();
10874 uptime -= p->resettime;
10875 tm = gmtime(&uptime);
10876 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10877 (tm->tm_sec * 1000)
10878 + (tm->tm_min * 60000)
10879 + (tm->tm_hour * 3600000));
3577f1c5 10880 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 10881 } else {
10882 vty_out(vty, " Last reset %s, ",
10883 peer_uptime(p->resettime, timebuf,
10884 BGP_UPTIME_LEN, 0, NULL));
10885
3577f1c5 10886 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 10887 if (p->last_reset_cause_size) {
10888 msg = p->last_reset_cause;
10889 vty_out(vty,
10890 " Message received that caused BGP to send a NOTIFICATION:\n ");
10891 for (i = 1; i <= p->last_reset_cause_size;
10892 i++) {
10893 vty_out(vty, "%02X", *msg++);
10894
10895 if (i != p->last_reset_cause_size) {
10896 if (i % 16 == 0) {
10897 vty_out(vty, "\n ");
10898 } else if (i % 4 == 0) {
10899 vty_out(vty, " ");
10900 }
10901 }
10902 }
10903 vty_out(vty, "\n");
10904 }
10905 }
10906 }
10907
10908 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10909 if (use_json)
10910 json_object_boolean_true_add(json_neigh,
10911 "prefixesConfigExceedMax");
10912 else
10913 vty_out(vty,
10914 " Peer had exceeded the max. no. of prefixes configured.\n");
10915
10916 if (p->t_pmax_restart) {
10917 if (use_json) {
10918 json_object_boolean_true_add(
10919 json_neigh, "reducePrefixNumFrom");
10920 json_object_int_add(json_neigh,
10921 "restartInTimerMsec",
10922 thread_timer_remain_second(
10923 p->t_pmax_restart)
10924 * 1000);
10925 } else
10926 vty_out(vty,
10927 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10928 p->host, thread_timer_remain_second(
10929 p->t_pmax_restart));
d62a17ae 10930 } else {
10931 if (use_json)
10932 json_object_boolean_true_add(
10933 json_neigh,
10934 "reducePrefixNumAndClearIpBgp");
10935 else
10936 vty_out(vty,
10937 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10938 p->host);
10939 }
10940 }
10941
10942 /* EBGP Multihop and GTSM */
10943 if (p->sort != BGP_PEER_IBGP) {
10944 if (use_json) {
10945 if (p->gtsm_hops > 0)
10946 json_object_int_add(json_neigh,
10947 "externalBgpNbrMaxHopsAway",
10948 p->gtsm_hops);
c8d6f0d6 10949 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 10950 json_object_int_add(json_neigh,
10951 "externalBgpNbrMaxHopsAway",
10952 p->ttl);
10953 } else {
10954 if (p->gtsm_hops > 0)
10955 vty_out(vty,
10956 " External BGP neighbor may be up to %d hops away.\n",
10957 p->gtsm_hops);
c8d6f0d6 10958 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 10959 vty_out(vty,
10960 " External BGP neighbor may be up to %d hops away.\n",
10961 p->ttl);
10962 }
10963 } else {
10964 if (p->gtsm_hops > 0) {
10965 if (use_json)
10966 json_object_int_add(json_neigh,
10967 "internalBgpNbrMaxHopsAway",
10968 p->gtsm_hops);
10969 else
10970 vty_out(vty,
10971 " Internal BGP neighbor may be up to %d hops away.\n",
10972 p->gtsm_hops);
10973 }
10974 }
10975
10976 /* Local address. */
10977 if (p->su_local) {
10978 if (use_json) {
10979 json_object_string_add(json_neigh, "hostLocal",
10980 sockunion2str(p->su_local, buf1,
10981 SU_ADDRSTRLEN));
10982 json_object_int_add(json_neigh, "portLocal",
10983 ntohs(p->su_local->sin.sin_port));
10984 } else
10985 vty_out(vty, "Local host: %s, Local port: %d\n",
10986 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10987 ntohs(p->su_local->sin.sin_port));
10988 }
10989
10990 /* Remote address. */
10991 if (p->su_remote) {
10992 if (use_json) {
10993 json_object_string_add(json_neigh, "hostForeign",
10994 sockunion2str(p->su_remote, buf1,
10995 SU_ADDRSTRLEN));
10996 json_object_int_add(json_neigh, "portForeign",
10997 ntohs(p->su_remote->sin.sin_port));
10998 } else
10999 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
11000 sockunion2str(p->su_remote, buf1,
11001 SU_ADDRSTRLEN),
11002 ntohs(p->su_remote->sin.sin_port));
11003 }
11004
11005 /* Nexthop display. */
11006 if (p->su_local) {
11007 if (use_json) {
11008 json_object_string_add(json_neigh, "nexthop",
11009 inet_ntop(AF_INET,
11010 &p->nexthop.v4, buf1,
11011 sizeof(buf1)));
11012 json_object_string_add(json_neigh, "nexthopGlobal",
11013 inet_ntop(AF_INET6,
11014 &p->nexthop.v6_global,
11015 buf1, sizeof(buf1)));
11016 json_object_string_add(json_neigh, "nexthopLocal",
11017 inet_ntop(AF_INET6,
11018 &p->nexthop.v6_local,
11019 buf1, sizeof(buf1)));
11020 if (p->shared_network)
11021 json_object_string_add(json_neigh,
11022 "bgpConnection",
11023 "sharedNetwork");
11024 else
11025 json_object_string_add(json_neigh,
11026 "bgpConnection",
11027 "nonSharedNetwork");
11028 } else {
11029 vty_out(vty, "Nexthop: %s\n",
11030 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
11031 sizeof(buf1)));
11032 vty_out(vty, "Nexthop global: %s\n",
11033 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
11034 sizeof(buf1)));
11035 vty_out(vty, "Nexthop local: %s\n",
11036 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
11037 sizeof(buf1)));
11038 vty_out(vty, "BGP connection: %s\n",
11039 p->shared_network ? "shared network"
11040 : "non shared network");
11041 }
11042 }
11043
11044 /* Timer information. */
11045 if (use_json) {
11046 json_object_int_add(json_neigh, "connectRetryTimer",
11047 p->v_connect);
11048 if (p->status == Established && p->rtt)
11049 json_object_int_add(json_neigh, "estimatedRttInMsecs",
11050 p->rtt);
11051 if (p->t_start)
11052 json_object_int_add(
11053 json_neigh, "nextStartTimerDueInMsecs",
11054 thread_timer_remain_second(p->t_start) * 1000);
11055 if (p->t_connect)
11056 json_object_int_add(
11057 json_neigh, "nextConnectTimerDueInMsecs",
11058 thread_timer_remain_second(p->t_connect)
11059 * 1000);
11060 if (p->t_routeadv) {
11061 json_object_int_add(json_neigh, "mraiInterval",
11062 p->v_routeadv);
11063 json_object_int_add(
11064 json_neigh, "mraiTimerExpireInMsecs",
11065 thread_timer_remain_second(p->t_routeadv)
11066 * 1000);
11067 }
11068 if (p->password)
11069 json_object_int_add(json_neigh, "authenticationEnabled",
11070 1);
11071
11072 if (p->t_read)
11073 json_object_string_add(json_neigh, "readThread", "on");
11074 else
11075 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
11076
11077 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 11078 json_object_string_add(json_neigh, "writeThread", "on");
11079 else
11080 json_object_string_add(json_neigh, "writeThread",
11081 "off");
11082 } else {
11083 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
11084 p->v_connect);
11085 if (p->status == Established && p->rtt)
11086 vty_out(vty, "Estimated round trip time: %d ms\n",
11087 p->rtt);
11088 if (p->t_start)
11089 vty_out(vty, "Next start timer due in %ld seconds\n",
11090 thread_timer_remain_second(p->t_start));
11091 if (p->t_connect)
11092 vty_out(vty, "Next connect timer due in %ld seconds\n",
11093 thread_timer_remain_second(p->t_connect));
11094 if (p->t_routeadv)
11095 vty_out(vty,
11096 "MRAI (interval %u) timer expires in %ld seconds\n",
11097 p->v_routeadv,
11098 thread_timer_remain_second(p->t_routeadv));
11099 if (p->password)
11100 vty_out(vty, "Peer Authentication Enabled\n");
11101
cac9e917 11102 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
11103 p->t_read ? "on" : "off",
11104 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
11105 ? "on"
cac9e917 11106 : "off", p->fd);
d62a17ae 11107 }
11108
11109 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
11110 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
11111 bgp_capability_vty_out(vty, p, use_json, json_neigh);
11112
11113 if (!use_json)
11114 vty_out(vty, "\n");
11115
11116 /* BFD information. */
11117 bgp_bfd_show_info(vty, p, use_json, json_neigh);
11118
11119 if (use_json) {
11120 if (p->conf_if) /* Configured interface name. */
11121 json_object_object_add(json, p->conf_if, json_neigh);
11122 else /* Configured IP address. */
11123 json_object_object_add(json, p->host, json_neigh);
11124 }
11125}
11126
11127static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
11128 enum show_type type, union sockunion *su,
9f049418 11129 const char *conf_if, bool use_json,
d62a17ae 11130 json_object *json)
11131{
11132 struct listnode *node, *nnode;
11133 struct peer *peer;
11134 int find = 0;
9f049418 11135 bool nbr_output = false;
d1927ebe
AS
11136 afi_t afi = AFI_MAX;
11137 safi_t safi = SAFI_MAX;
11138
11139 if (type == show_ipv4_peer || type == show_ipv4_all) {
11140 afi = AFI_IP;
11141 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
11142 afi = AFI_IP6;
11143 }
d62a17ae 11144
11145 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11146 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11147 continue;
11148
11149 switch (type) {
11150 case show_all:
11151 bgp_show_peer(vty, peer, use_json, json);
9f049418 11152 nbr_output = true;
d62a17ae 11153 break;
11154 case show_peer:
11155 if (conf_if) {
11156 if ((peer->conf_if
11157 && !strcmp(peer->conf_if, conf_if))
11158 || (peer->hostname
11159 && !strcmp(peer->hostname, conf_if))) {
11160 find = 1;
11161 bgp_show_peer(vty, peer, use_json,
11162 json);
11163 }
11164 } else {
11165 if (sockunion_same(&peer->su, su)) {
11166 find = 1;
11167 bgp_show_peer(vty, peer, use_json,
11168 json);
11169 }
11170 }
11171 break;
d1927ebe
AS
11172 case show_ipv4_peer:
11173 case show_ipv6_peer:
11174 FOREACH_SAFI (safi) {
11175 if (peer->afc[afi][safi]) {
11176 if (conf_if) {
11177 if ((peer->conf_if
11178 && !strcmp(peer->conf_if, conf_if))
11179 || (peer->hostname
11180 && !strcmp(peer->hostname, conf_if))) {
11181 find = 1;
11182 bgp_show_peer(vty, peer, use_json,
11183 json);
11184 break;
11185 }
11186 } else {
11187 if (sockunion_same(&peer->su, su)) {
11188 find = 1;
11189 bgp_show_peer(vty, peer, use_json,
11190 json);
11191 break;
11192 }
11193 }
11194 }
11195 }
11196 break;
11197 case show_ipv4_all:
11198 case show_ipv6_all:
11199 FOREACH_SAFI (safi) {
11200 if (peer->afc[afi][safi]) {
11201 bgp_show_peer(vty, peer, use_json, json);
11202 nbr_output = true;
11203 break;
11204 }
11205 }
11206 break;
d62a17ae 11207 }
11208 }
11209
d1927ebe
AS
11210 if ((type == show_peer || type == show_ipv4_peer ||
11211 type == show_ipv6_peer) && !find) {
d62a17ae 11212 if (use_json)
11213 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11214 else
88b7d255 11215 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 11216 }
11217
d1927ebe
AS
11218 if (type != show_peer && type != show_ipv4_peer &&
11219 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 11220 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 11221
d62a17ae 11222 if (use_json) {
996c9314
LB
11223 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11224 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 11225 } else {
11226 vty_out(vty, "\n");
11227 }
11228
11229 return CMD_SUCCESS;
11230}
11231
11232static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
11233 enum show_type type,
11234 const char *ip_str,
9f049418 11235 bool use_json)
d62a17ae 11236{
0291c246
MK
11237 struct listnode *node, *nnode;
11238 struct bgp *bgp;
71aedaa3 11239 union sockunion su;
0291c246 11240 json_object *json = NULL;
71aedaa3 11241 int ret, is_first = 1;
9f049418 11242 bool nbr_output = false;
d62a17ae 11243
11244 if (use_json)
11245 vty_out(vty, "{\n");
11246
11247 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11248 nbr_output = true;
d62a17ae 11249 if (use_json) {
11250 if (!(json = json_object_new_object())) {
af4c2728 11251 flog_err(
e50f7cfd 11252 EC_BGP_JSON_MEM_ERROR,
d62a17ae 11253 "Unable to allocate memory for JSON object");
11254 vty_out(vty,
11255 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11256 return;
11257 }
11258
11259 json_object_int_add(json, "vrfId",
11260 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
11261 ? -1
11262 : (int64_t)bgp->vrf_id);
d62a17ae 11263 json_object_string_add(
11264 json, "vrfName",
11265 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11266 ? VRF_DEFAULT_NAME
d62a17ae 11267 : bgp->name);
11268
11269 if (!is_first)
11270 vty_out(vty, ",\n");
11271 else
11272 is_first = 0;
11273
11274 vty_out(vty, "\"%s\":",
11275 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11276 ? VRF_DEFAULT_NAME
d62a17ae 11277 : bgp->name);
11278 } else {
11279 vty_out(vty, "\nInstance %s:\n",
11280 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11281 ? VRF_DEFAULT_NAME
d62a17ae 11282 : bgp->name);
11283 }
71aedaa3 11284
d1927ebe
AS
11285 if (type == show_peer || type == show_ipv4_peer ||
11286 type == show_ipv6_peer) {
71aedaa3
DS
11287 ret = str2sockunion(ip_str, &su);
11288 if (ret < 0)
11289 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11290 use_json, json);
11291 else
11292 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11293 use_json, json);
11294 } else {
d1927ebe 11295 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
11296 use_json, json);
11297 }
b77004d6 11298 json_object_free(json);
d62a17ae 11299 }
11300
01cbfd04 11301 if (use_json) {
d62a17ae 11302 vty_out(vty, "}\n");
01cbfd04
QY
11303 json_object_free(json);
11304 }
9f049418
DS
11305 else if (!nbr_output)
11306 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11307}
11308
11309static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11310 enum show_type type, const char *ip_str,
9f049418 11311 bool use_json)
d62a17ae 11312{
11313 int ret;
11314 struct bgp *bgp;
11315 union sockunion su;
11316 json_object *json = NULL;
11317
11318 if (name) {
11319 if (strmatch(name, "all")) {
71aedaa3
DS
11320 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11321 use_json);
d62a17ae 11322 return CMD_SUCCESS;
11323 } else {
11324 bgp = bgp_lookup_by_name(name);
11325 if (!bgp) {
11326 if (use_json) {
11327 json = json_object_new_object();
d62a17ae 11328 vty_out(vty, "%s\n",
11329 json_object_to_json_string_ext(
11330 json,
11331 JSON_C_TO_STRING_PRETTY));
11332 json_object_free(json);
11333 } else
11334 vty_out(vty,
9f049418 11335 "%% BGP instance not found\n");
d62a17ae 11336
11337 return CMD_WARNING;
11338 }
11339 }
11340 } else {
11341 bgp = bgp_get_default();
11342 }
11343
11344 if (bgp) {
11345 json = json_object_new_object();
11346 if (ip_str) {
11347 ret = str2sockunion(ip_str, &su);
11348 if (ret < 0)
11349 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11350 use_json, json);
11351 else
11352 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11353 use_json, json);
11354 } else {
11355 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11356 json);
11357 }
11358 json_object_free(json);
ca61fd25
DS
11359 } else {
11360 if (use_json)
11361 vty_out(vty, "{}\n");
11362 else
11363 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11364 }
11365
11366 return CMD_SUCCESS;
4fb25c53
DW
11367}
11368
716b2d8a 11369/* "show [ip] bgp neighbors" commands. */
718e3744 11370DEFUN (show_ip_bgp_neighbors,
11371 show_ip_bgp_neighbors_cmd,
24345e82 11372 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 11373 SHOW_STR
11374 IP_STR
11375 BGP_STR
f2a8972b 11376 BGP_INSTANCE_HELP_STR
8c3deaae
QY
11377 "Address Family\n"
11378 "Address Family\n"
718e3744 11379 "Detailed information on TCP and BGP neighbor connections\n"
11380 "Neighbor to display information about\n"
a80beece 11381 "Neighbor to display information about\n"
91d37724 11382 "Neighbor on BGP configured interface\n"
9973d184 11383 JSON_STR)
718e3744 11384{
d62a17ae 11385 char *vrf = NULL;
11386 char *sh_arg = NULL;
11387 enum show_type sh_type;
d1927ebe 11388 afi_t afi = AFI_MAX;
718e3744 11389
9f049418 11390 bool uj = use_json(argc, argv);
718e3744 11391
d62a17ae 11392 int idx = 0;
718e3744 11393
9a8bdf1c
PG
11394 /* [<vrf> VIEWVRFNAME] */
11395 if (argv_find(argv, argc, "vrf", &idx)) {
11396 vrf = argv[idx + 1]->arg;
11397 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11398 vrf = NULL;
11399 } else if (argv_find(argv, argc, "view", &idx))
11400 /* [<view> VIEWVRFNAME] */
d62a17ae 11401 vrf = argv[idx + 1]->arg;
718e3744 11402
d62a17ae 11403 idx++;
d1927ebe
AS
11404
11405 if (argv_find(argv, argc, "ipv4", &idx)) {
11406 sh_type = show_ipv4_all;
11407 afi = AFI_IP;
11408 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11409 sh_type = show_ipv6_all;
11410 afi = AFI_IP6;
11411 } else {
11412 sh_type = show_all;
11413 }
11414
d62a17ae 11415 if (argv_find(argv, argc, "A.B.C.D", &idx)
11416 || argv_find(argv, argc, "X:X::X:X", &idx)
11417 || argv_find(argv, argc, "WORD", &idx)) {
11418 sh_type = show_peer;
11419 sh_arg = argv[idx]->arg;
d1927ebe
AS
11420 }
11421
11422 if (sh_type == show_peer && afi == AFI_IP) {
11423 sh_type = show_ipv4_peer;
11424 } else if (sh_type == show_peer && afi == AFI_IP6) {
11425 sh_type = show_ipv6_peer;
11426 }
856ca177 11427
d62a17ae 11428 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 11429}
11430
716b2d8a 11431/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 11432 paths' and `show ip mbgp paths'. Those functions results are the
11433 same.*/
f412b39a 11434DEFUN (show_ip_bgp_paths,
718e3744 11435 show_ip_bgp_paths_cmd,
46f296b4 11436 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 11437 SHOW_STR
11438 IP_STR
11439 BGP_STR
46f296b4 11440 BGP_SAFI_HELP_STR
718e3744 11441 "Path information\n")
11442{
d62a17ae 11443 vty_out(vty, "Address Refcnt Path\n");
11444 aspath_print_all_vty(vty);
11445 return CMD_SUCCESS;
718e3744 11446}
11447
718e3744 11448#include "hash.h"
11449
e3b78da8 11450static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 11451 struct vty *vty)
718e3744 11452{
d62a17ae 11453 struct community *com;
718e3744 11454
e3b78da8 11455 com = (struct community *)bucket->data;
3f65c5b1 11456 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 11457 community_str(com, false));
718e3744 11458}
11459
11460/* Show BGP's community internal data. */
f412b39a 11461DEFUN (show_ip_bgp_community_info,
718e3744 11462 show_ip_bgp_community_info_cmd,
bec37ba5 11463 "show [ip] bgp community-info",
718e3744 11464 SHOW_STR
11465 IP_STR
11466 BGP_STR
11467 "List all bgp community information\n")
11468{
d62a17ae 11469 vty_out(vty, "Address Refcnt Community\n");
718e3744 11470
d62a17ae 11471 hash_iterate(community_hash(),
e3b78da8 11472 (void (*)(struct hash_bucket *,
d62a17ae 11473 void *))community_show_all_iterator,
11474 vty);
718e3744 11475
d62a17ae 11476 return CMD_SUCCESS;
718e3744 11477}
11478
e3b78da8 11479static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 11480 struct vty *vty)
57d187bc 11481{
d62a17ae 11482 struct lcommunity *lcom;
57d187bc 11483
e3b78da8 11484 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 11485 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 11486 lcommunity_str(lcom, false));
57d187bc
JS
11487}
11488
11489/* Show BGP's community internal data. */
11490DEFUN (show_ip_bgp_lcommunity_info,
11491 show_ip_bgp_lcommunity_info_cmd,
11492 "show ip bgp large-community-info",
11493 SHOW_STR
11494 IP_STR
11495 BGP_STR
11496 "List all bgp large-community information\n")
11497{
d62a17ae 11498 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 11499
d62a17ae 11500 hash_iterate(lcommunity_hash(),
e3b78da8 11501 (void (*)(struct hash_bucket *,
d62a17ae 11502 void *))lcommunity_show_all_iterator,
11503 vty);
57d187bc 11504
d62a17ae 11505 return CMD_SUCCESS;
57d187bc
JS
11506}
11507
11508
f412b39a 11509DEFUN (show_ip_bgp_attr_info,
718e3744 11510 show_ip_bgp_attr_info_cmd,
bec37ba5 11511 "show [ip] bgp attribute-info",
718e3744 11512 SHOW_STR
11513 IP_STR
11514 BGP_STR
11515 "List all bgp attribute information\n")
11516{
d62a17ae 11517 attr_show_all(vty);
11518 return CMD_SUCCESS;
718e3744 11519}
6b0655a2 11520
03915806
CS
11521static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11522 afi_t afi, safi_t safi,
11523 bool use_json, json_object *json)
53089bec 11524{
11525 struct bgp *bgp;
11526 struct listnode *node;
11527 char *vname;
11528 char buf1[INET6_ADDRSTRLEN];
11529 char *ecom_str;
11530 vpn_policy_direction_t dir;
11531
03915806 11532 if (json) {
b46dfd20
DS
11533 json_object *json_import_vrfs = NULL;
11534 json_object *json_export_vrfs = NULL;
11535
b46dfd20
DS
11536 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11537
53089bec 11538 if (!bgp) {
b46dfd20
DS
11539 vty_out(vty, "%s\n",
11540 json_object_to_json_string_ext(
11541 json,
11542 JSON_C_TO_STRING_PRETTY));
11543 json_object_free(json);
11544
53089bec 11545 return CMD_WARNING;
11546 }
b46dfd20 11547
94d4c685
DS
11548 /* Provide context for the block */
11549 json_object_string_add(json, "vrf", name ? name : "default");
11550 json_object_string_add(json, "afiSafi",
5cb5f4d0 11551 get_afi_safi_str(afi, safi, true));
94d4c685 11552
b46dfd20
DS
11553 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11554 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11555 json_object_string_add(json, "importFromVrfs", "none");
11556 json_object_string_add(json, "importRts", "none");
11557 } else {
6ce24e52
DS
11558 json_import_vrfs = json_object_new_array();
11559
b46dfd20
DS
11560 for (ALL_LIST_ELEMENTS_RO(
11561 bgp->vpn_policy[afi].import_vrf,
11562 node, vname))
11563 json_object_array_add(json_import_vrfs,
11564 json_object_new_string(vname));
11565
b20875ea
CS
11566 json_object_object_add(json, "importFromVrfs",
11567 json_import_vrfs);
b46dfd20 11568 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
11569 if (bgp->vpn_policy[afi].rtlist[dir]) {
11570 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11571 bgp->vpn_policy[afi].rtlist[dir],
11572 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
11573 json_object_string_add(json, "importRts",
11574 ecom_str);
11575 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11576 } else
11577 json_object_string_add(json, "importRts",
11578 "none");
b46dfd20
DS
11579 }
11580
11581 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11582 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11583 json_object_string_add(json, "exportToVrfs", "none");
11584 json_object_string_add(json, "routeDistinguisher",
11585 "none");
11586 json_object_string_add(json, "exportRts", "none");
11587 } else {
6ce24e52
DS
11588 json_export_vrfs = json_object_new_array();
11589
b46dfd20
DS
11590 for (ALL_LIST_ELEMENTS_RO(
11591 bgp->vpn_policy[afi].export_vrf,
11592 node, vname))
11593 json_object_array_add(json_export_vrfs,
11594 json_object_new_string(vname));
11595 json_object_object_add(json, "exportToVrfs",
11596 json_export_vrfs);
11597 json_object_string_add(json, "routeDistinguisher",
11598 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11599 buf1, RD_ADDRSTRLEN));
11600
11601 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
11602 if (bgp->vpn_policy[afi].rtlist[dir]) {
11603 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11604 bgp->vpn_policy[afi].rtlist[dir],
11605 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
11606 json_object_string_add(json, "exportRts",
11607 ecom_str);
11608 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11609 } else
11610 json_object_string_add(json, "exportRts",
11611 "none");
b46dfd20
DS
11612 }
11613
03915806
CS
11614 if (use_json) {
11615 vty_out(vty, "%s\n",
11616 json_object_to_json_string_ext(json,
b46dfd20 11617 JSON_C_TO_STRING_PRETTY));
03915806
CS
11618 json_object_free(json);
11619 }
53089bec 11620 } else {
b46dfd20
DS
11621 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11622
53089bec 11623 if (!bgp) {
b46dfd20 11624 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 11625 return CMD_WARNING;
11626 }
53089bec 11627
b46dfd20
DS
11628 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11629 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11630 vty_out(vty,
11631 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 11632 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
11633 else {
11634 vty_out(vty,
11635 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 11636 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
11637
11638 for (ALL_LIST_ELEMENTS_RO(
11639 bgp->vpn_policy[afi].import_vrf,
11640 node, vname))
11641 vty_out(vty, " %s\n", vname);
11642
11643 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
11644 ecom_str = NULL;
11645 if (bgp->vpn_policy[afi].rtlist[dir]) {
11646 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11647 bgp->vpn_policy[afi].rtlist[dir],
11648 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 11649 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 11650
b20875ea
CS
11651 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11652 } else
11653 vty_out(vty, "Import RT(s):\n");
53089bec 11654 }
53089bec 11655
b46dfd20
DS
11656 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11657 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11658 vty_out(vty,
11659 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 11660 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
11661 else {
11662 vty_out(vty,
04c9077f 11663 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 11664 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
11665
11666 for (ALL_LIST_ELEMENTS_RO(
11667 bgp->vpn_policy[afi].export_vrf,
11668 node, vname))
11669 vty_out(vty, " %s\n", vname);
11670
11671 vty_out(vty, "RD: %s\n",
11672 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11673 buf1, RD_ADDRSTRLEN));
11674
11675 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
11676 if (bgp->vpn_policy[afi].rtlist[dir]) {
11677 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11678 bgp->vpn_policy[afi].rtlist[dir],
11679 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
11680 vty_out(vty, "Export RT: %s\n", ecom_str);
11681 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11682 } else
11683 vty_out(vty, "Import RT(s):\n");
53089bec 11684 }
53089bec 11685 }
11686
11687 return CMD_SUCCESS;
11688}
11689
03915806
CS
11690static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11691 safi_t safi, bool use_json)
11692{
11693 struct listnode *node, *nnode;
11694 struct bgp *bgp;
11695 char *vrf_name = NULL;
11696 json_object *json = NULL;
11697 json_object *json_vrf = NULL;
11698 json_object *json_vrfs = NULL;
11699
11700 if (use_json) {
11701 json = json_object_new_object();
11702 json_vrfs = json_object_new_object();
11703 }
11704
11705 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11706
11707 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11708 vrf_name = bgp->name;
11709
11710 if (use_json) {
11711 json_vrf = json_object_new_object();
11712 } else {
11713 vty_out(vty, "\nInstance %s:\n",
11714 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11715 ? VRF_DEFAULT_NAME : bgp->name);
11716 }
11717 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11718 if (use_json) {
11719 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11720 json_object_object_add(json_vrfs,
11721 VRF_DEFAULT_NAME, json_vrf);
11722 else
11723 json_object_object_add(json_vrfs, vrf_name,
11724 json_vrf);
11725 }
11726 }
11727
11728 if (use_json) {
11729 json_object_object_add(json, "vrfs", json_vrfs);
11730 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11731 JSON_C_TO_STRING_PRETTY));
11732 json_object_free(json);
11733 }
11734
11735 return CMD_SUCCESS;
11736}
11737
53089bec 11738/* "show [ip] bgp route-leak" command. */
11739DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
11740 show_ip_bgp_route_leak_cmd,
11741 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
11742 SHOW_STR
11743 IP_STR
11744 BGP_STR
11745 BGP_INSTANCE_HELP_STR
11746 BGP_AFI_HELP_STR
11747 BGP_SAFI_HELP_STR
11748 "Route leaking information\n"
11749 JSON_STR)
53089bec 11750{
11751 char *vrf = NULL;
11752 afi_t afi = AFI_MAX;
11753 safi_t safi = SAFI_MAX;
11754
9f049418 11755 bool uj = use_json(argc, argv);
53089bec 11756 int idx = 0;
03915806 11757 json_object *json = NULL;
53089bec 11758
11759 /* show [ip] bgp */
11760 if (argv_find(argv, argc, "ip", &idx)) {
11761 afi = AFI_IP;
11762 safi = SAFI_UNICAST;
11763 }
11764 /* [vrf VIEWVRFNAME] */
11765 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11766 vty_out(vty,
11767 "%% This command is not applicable to BGP views\n");
53089bec 11768 return CMD_WARNING;
11769 }
11770
9a8bdf1c
PG
11771 if (argv_find(argv, argc, "vrf", &idx)) {
11772 vrf = argv[idx + 1]->arg;
11773 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11774 vrf = NULL;
11775 }
53089bec 11776 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11777 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11778 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11779 }
11780
11781 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11782 vty_out(vty,
11783 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11784 return CMD_WARNING;
11785 }
11786
03915806
CS
11787 if (vrf && strmatch(vrf, "all"))
11788 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11789
11790 if (uj)
11791 json = json_object_new_object();
11792
11793 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 11794}
11795
d62a17ae 11796static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11797 safi_t safi)
f186de26 11798{
d62a17ae 11799 struct listnode *node, *nnode;
11800 struct bgp *bgp;
f186de26 11801
d62a17ae 11802 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11803 vty_out(vty, "\nInstance %s:\n",
11804 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11805 ? VRF_DEFAULT_NAME
d62a17ae 11806 : bgp->name);
11807 update_group_show(bgp, afi, safi, vty, 0);
11808 }
f186de26 11809}
11810
d62a17ae 11811static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11812 int safi, uint64_t subgrp_id)
4fb25c53 11813{
d62a17ae 11814 struct bgp *bgp;
4fb25c53 11815
d62a17ae 11816 if (name) {
11817 if (strmatch(name, "all")) {
11818 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11819 return CMD_SUCCESS;
11820 } else {
11821 bgp = bgp_lookup_by_name(name);
11822 }
11823 } else {
11824 bgp = bgp_get_default();
11825 }
4fb25c53 11826
d62a17ae 11827 if (bgp)
11828 update_group_show(bgp, afi, safi, vty, subgrp_id);
11829 return CMD_SUCCESS;
4fb25c53
DW
11830}
11831
8fe8a7f6
DS
11832DEFUN (show_ip_bgp_updgrps,
11833 show_ip_bgp_updgrps_cmd,
c1a44e43 11834 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11835 SHOW_STR
11836 IP_STR
11837 BGP_STR
11838 BGP_INSTANCE_HELP_STR
c9e571b4 11839 BGP_AFI_HELP_STR
9bedbb1e 11840 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11841 "Detailed info about dynamic update groups\n"
11842 "Specific subgroup to display detailed info for\n")
8386ac43 11843{
d62a17ae 11844 char *vrf = NULL;
11845 afi_t afi = AFI_IP6;
11846 safi_t safi = SAFI_UNICAST;
11847 uint64_t subgrp_id = 0;
11848
11849 int idx = 0;
11850
11851 /* show [ip] bgp */
11852 if (argv_find(argv, argc, "ip", &idx))
11853 afi = AFI_IP;
9a8bdf1c
PG
11854 /* [<vrf> VIEWVRFNAME] */
11855 if (argv_find(argv, argc, "vrf", &idx)) {
11856 vrf = argv[idx + 1]->arg;
11857 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11858 vrf = NULL;
11859 } else if (argv_find(argv, argc, "view", &idx))
11860 /* [<view> VIEWVRFNAME] */
11861 vrf = argv[idx + 1]->arg;
d62a17ae 11862 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11863 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11864 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11865 }
5bf15956 11866
d62a17ae 11867 /* get subgroup id, if provided */
11868 idx = argc - 1;
11869 if (argv[idx]->type == VARIABLE_TKN)
11870 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11871
d62a17ae 11872 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11873}
11874
f186de26 11875DEFUN (show_bgp_instance_all_ipv6_updgrps,
11876 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11877 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11878 SHOW_STR
716b2d8a 11879 IP_STR
f186de26 11880 BGP_STR
11881 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11882 "Detailed info about dynamic update groups\n")
f186de26 11883{
d62a17ae 11884 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11885 return CMD_SUCCESS;
f186de26 11886}
11887
43d3f4fc
DS
11888DEFUN (show_bgp_l2vpn_evpn_updgrps,
11889 show_bgp_l2vpn_evpn_updgrps_cmd,
11890 "show [ip] bgp l2vpn evpn update-groups",
11891 SHOW_STR
11892 IP_STR
11893 BGP_STR
11894 "l2vpn address family\n"
11895 "evpn sub-address family\n"
11896 "Detailed info about dynamic update groups\n")
11897{
11898 char *vrf = NULL;
11899 uint64_t subgrp_id = 0;
11900
11901 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11902 return CMD_SUCCESS;
11903}
11904
5bf15956
DW
11905DEFUN (show_bgp_updgrps_stats,
11906 show_bgp_updgrps_stats_cmd,
716b2d8a 11907 "show [ip] bgp update-groups statistics",
3f9c7369 11908 SHOW_STR
716b2d8a 11909 IP_STR
3f9c7369 11910 BGP_STR
0c7b1b01 11911 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11912 "Statistics\n")
11913{
d62a17ae 11914 struct bgp *bgp;
3f9c7369 11915
d62a17ae 11916 bgp = bgp_get_default();
11917 if (bgp)
11918 update_group_show_stats(bgp, vty);
3f9c7369 11919
d62a17ae 11920 return CMD_SUCCESS;
3f9c7369
DS
11921}
11922
8386ac43 11923DEFUN (show_bgp_instance_updgrps_stats,
11924 show_bgp_instance_updgrps_stats_cmd,
18c57037 11925 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11926 SHOW_STR
716b2d8a 11927 IP_STR
8386ac43 11928 BGP_STR
11929 BGP_INSTANCE_HELP_STR
0c7b1b01 11930 "Detailed info about dynamic update groups\n"
8386ac43 11931 "Statistics\n")
11932{
d62a17ae 11933 int idx_word = 3;
11934 struct bgp *bgp;
8386ac43 11935
d62a17ae 11936 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11937 if (bgp)
11938 update_group_show_stats(bgp, vty);
8386ac43 11939
d62a17ae 11940 return CMD_SUCCESS;
8386ac43 11941}
11942
d62a17ae 11943static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11944 afi_t afi, safi_t safi,
11945 const char *what, uint64_t subgrp_id)
3f9c7369 11946{
d62a17ae 11947 struct bgp *bgp;
8386ac43 11948
d62a17ae 11949 if (name)
11950 bgp = bgp_lookup_by_name(name);
11951 else
11952 bgp = bgp_get_default();
8386ac43 11953
d62a17ae 11954 if (bgp) {
11955 if (!strcmp(what, "advertise-queue"))
11956 update_group_show_adj_queue(bgp, afi, safi, vty,
11957 subgrp_id);
11958 else if (!strcmp(what, "advertised-routes"))
11959 update_group_show_advertised(bgp, afi, safi, vty,
11960 subgrp_id);
11961 else if (!strcmp(what, "packet-queue"))
11962 update_group_show_packet_queue(bgp, afi, safi, vty,
11963 subgrp_id);
11964 }
3f9c7369
DS
11965}
11966
dc64bdec
QY
11967DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11968 show_ip_bgp_instance_updgrps_adj_s_cmd,
11969 "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",
11970 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11971 BGP_SAFI_HELP_STR
11972 "Detailed info about dynamic update groups\n"
11973 "Specific subgroup to display info for\n"
11974 "Advertisement queue\n"
11975 "Announced routes\n"
11976 "Packet queue\n")
3f9c7369 11977{
dc64bdec
QY
11978 uint64_t subgrp_id = 0;
11979 afi_t afiz;
11980 safi_t safiz;
11981 if (sgid)
11982 subgrp_id = strtoull(sgid, NULL, 10);
11983
11984 if (!ip && !afi)
11985 afiz = AFI_IP6;
11986 if (!ip && afi)
11987 afiz = bgp_vty_afi_from_str(afi);
11988 if (ip && !afi)
11989 afiz = AFI_IP;
11990 if (ip && afi) {
11991 afiz = bgp_vty_afi_from_str(afi);
11992 if (afiz != AFI_IP)
11993 vty_out(vty,
11994 "%% Cannot specify both 'ip' and 'ipv6'\n");
11995 return CMD_WARNING;
11996 }
d62a17ae 11997
dc64bdec 11998 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11999
dc64bdec 12000 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 12001 return CMD_SUCCESS;
12002}
12003
d62a17ae 12004static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
12005{
12006 struct listnode *node, *nnode;
12007 struct prefix *range;
12008 struct peer *conf;
12009 struct peer *peer;
12010 char buf[PREFIX2STR_BUFFER];
12011 afi_t afi;
12012 safi_t safi;
12013 const char *peer_status;
12014 const char *af_str;
12015 int lr_count;
12016 int dynamic;
12017 int af_cfgd;
12018
12019 conf = group->conf;
12020
12021 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
3b61f610
QY
12022 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
12023 group->name, conf->as);
d62a17ae 12024 } else if (conf->as_type == AS_INTERNAL) {
3b61f610
QY
12025 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
12026 group->name, group->bgp->as);
d62a17ae 12027 } else {
12028 vty_out(vty, "\nBGP peer-group %s\n", group->name);
12029 }
f14e6fdb 12030
d62a17ae 12031 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
12032 vty_out(vty, " Peer-group type is internal\n");
12033 else
12034 vty_out(vty, " Peer-group type is external\n");
12035
12036 /* Display AFs configured. */
12037 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
12038 FOREACH_AFI_SAFI (afi, safi) {
12039 if (conf->afc[afi][safi]) {
12040 af_cfgd = 1;
5cb5f4d0 12041 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 12042 }
05c7a1cc 12043 }
d62a17ae 12044 if (!af_cfgd)
12045 vty_out(vty, " none\n");
12046 else
12047 vty_out(vty, "\n");
12048
12049 /* Display listen ranges (for dynamic neighbors), if any */
12050 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
12051 if (afi == AFI_IP)
12052 af_str = "IPv4";
12053 else if (afi == AFI_IP6)
12054 af_str = "IPv6";
12055 else
12056 af_str = "???";
12057 lr_count = listcount(group->listen_range[afi]);
12058 if (lr_count) {
12059 vty_out(vty, " %d %s listen range(s)\n", lr_count,
12060 af_str);
12061
12062
12063 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
12064 nnode, range)) {
12065 prefix2str(range, buf, sizeof(buf));
12066 vty_out(vty, " %s\n", buf);
12067 }
12068 }
12069 }
f14e6fdb 12070
d62a17ae 12071 /* Display group members and their status */
12072 if (listcount(group->peer)) {
12073 vty_out(vty, " Peer-group members:\n");
12074 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
12075 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
12076 peer_status = "Idle (Admin)";
12077 else if (CHECK_FLAG(peer->sflags,
12078 PEER_STATUS_PREFIX_OVERFLOW))
12079 peer_status = "Idle (PfxCt)";
12080 else
12081 peer_status = lookup_msg(bgp_status_msg,
12082 peer->status, NULL);
12083
12084 dynamic = peer_dynamic_neighbor(peer);
12085 vty_out(vty, " %s %s %s \n", peer->host,
12086 dynamic ? "(dynamic)" : "", peer_status);
12087 }
12088 }
f14e6fdb 12089
d62a17ae 12090 return CMD_SUCCESS;
12091}
12092
ff9959b0
QY
12093static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
12094 const char *group_name)
d62a17ae 12095{
ff9959b0 12096 struct bgp *bgp;
d62a17ae 12097 struct listnode *node, *nnode;
12098 struct peer_group *group;
ff9959b0
QY
12099 bool found = false;
12100
12101 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12102
12103 if (!bgp) {
9f049418 12104 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
12105 return CMD_WARNING;
12106 }
d62a17ae 12107
12108 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
12109 if (group_name) {
12110 if (strmatch(group->name, group_name)) {
d62a17ae 12111 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
12112 found = true;
12113 break;
d62a17ae 12114 }
ff9959b0
QY
12115 } else {
12116 bgp_show_one_peer_group(vty, group);
d62a17ae 12117 }
f14e6fdb 12118 }
f14e6fdb 12119
ff9959b0 12120 if (group_name && !found)
d62a17ae 12121 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 12122
d62a17ae 12123 return CMD_SUCCESS;
f14e6fdb
DS
12124}
12125
f14e6fdb
DS
12126DEFUN (show_ip_bgp_peer_groups,
12127 show_ip_bgp_peer_groups_cmd,
18c57037 12128 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
12129 SHOW_STR
12130 IP_STR
12131 BGP_STR
8386ac43 12132 BGP_INSTANCE_HELP_STR
d6e3c605
QY
12133 "Detailed information on BGP peer groups\n"
12134 "Peer group name\n")
f14e6fdb 12135{
d62a17ae 12136 char *vrf, *pg;
d62a17ae 12137 int idx = 0;
f14e6fdb 12138
a4d82a8a
PZ
12139 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
12140 : NULL;
d62a17ae 12141 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 12142
ff9959b0 12143 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 12144}
3f9c7369 12145
d6e3c605 12146
718e3744 12147/* Redistribute VTY commands. */
12148
718e3744 12149DEFUN (bgp_redistribute_ipv4,
12150 bgp_redistribute_ipv4_cmd,
40d1cbfb 12151 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 12152 "Redistribute information from another routing protocol\n"
ab0181ee 12153 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 12154{
d62a17ae 12155 VTY_DECLVAR_CONTEXT(bgp, bgp);
12156 int idx_protocol = 1;
12157 int type;
718e3744 12158
d62a17ae 12159 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12160 if (type < 0) {
12161 vty_out(vty, "%% Invalid route type\n");
12162 return CMD_WARNING_CONFIG_FAILED;
12163 }
7f323236 12164
d62a17ae 12165 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12166 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 12167}
12168
d62a17ae 12169ALIAS_HIDDEN(
12170 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
12171 "redistribute " FRR_IP_REDIST_STR_BGPD,
12172 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 12173
718e3744 12174DEFUN (bgp_redistribute_ipv4_rmap,
12175 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 12176 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 12177 "Redistribute information from another routing protocol\n"
ab0181ee 12178 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12179 "Route map reference\n"
12180 "Pointer to route-map entries\n")
12181{
d62a17ae 12182 VTY_DECLVAR_CONTEXT(bgp, bgp);
12183 int idx_protocol = 1;
12184 int idx_word = 3;
12185 int type;
12186 struct bgp_redist *red;
e923dd62 12187 bool changed;
1de27621
DA
12188 struct route_map *route_map = route_map_lookup_warn_noexist(
12189 vty, argv[idx_word]->arg);
718e3744 12190
d62a17ae 12191 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12192 if (type < 0) {
12193 vty_out(vty, "%% Invalid route type\n");
12194 return CMD_WARNING_CONFIG_FAILED;
12195 }
718e3744 12196
d62a17ae 12197 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
12198 changed =
12199 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12200 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 12201}
12202
d62a17ae 12203ALIAS_HIDDEN(
12204 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12205 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12206 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12207 "Route map reference\n"
12208 "Pointer to route-map entries\n")
596c17ba 12209
718e3744 12210DEFUN (bgp_redistribute_ipv4_metric,
12211 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 12212 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12213 "Redistribute information from another routing protocol\n"
ab0181ee 12214 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12215 "Metric for redistributed routes\n"
12216 "Default metric\n")
12217{
d62a17ae 12218 VTY_DECLVAR_CONTEXT(bgp, bgp);
12219 int idx_protocol = 1;
12220 int idx_number = 3;
12221 int type;
d7c0a89a 12222 uint32_t metric;
d62a17ae 12223 struct bgp_redist *red;
e923dd62 12224 bool changed;
d62a17ae 12225
12226 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12227 if (type < 0) {
12228 vty_out(vty, "%% Invalid route type\n");
12229 return CMD_WARNING_CONFIG_FAILED;
12230 }
12231 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12232
12233 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12234 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12235 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12236}
12237
12238ALIAS_HIDDEN(
12239 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12240 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12241 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12242 "Metric for redistributed routes\n"
12243 "Default metric\n")
596c17ba 12244
718e3744 12245DEFUN (bgp_redistribute_ipv4_rmap_metric,
12246 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 12247 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12248 "Redistribute information from another routing protocol\n"
ab0181ee 12249 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12250 "Route map reference\n"
12251 "Pointer to route-map entries\n"
12252 "Metric for redistributed routes\n"
12253 "Default metric\n")
12254{
d62a17ae 12255 VTY_DECLVAR_CONTEXT(bgp, bgp);
12256 int idx_protocol = 1;
12257 int idx_word = 3;
12258 int idx_number = 5;
12259 int type;
d7c0a89a 12260 uint32_t metric;
d62a17ae 12261 struct bgp_redist *red;
e923dd62 12262 bool changed;
1de27621
DA
12263 struct route_map *route_map =
12264 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12265
12266 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12267 if (type < 0) {
12268 vty_out(vty, "%% Invalid route type\n");
12269 return CMD_WARNING_CONFIG_FAILED;
12270 }
12271 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12272
12273 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
12274 changed =
12275 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12276 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12277 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12278}
12279
12280ALIAS_HIDDEN(
12281 bgp_redistribute_ipv4_rmap_metric,
12282 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12283 "redistribute " FRR_IP_REDIST_STR_BGPD
12284 " route-map WORD metric (0-4294967295)",
12285 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12286 "Route map reference\n"
12287 "Pointer to route-map entries\n"
12288 "Metric for redistributed routes\n"
12289 "Default metric\n")
596c17ba 12290
718e3744 12291DEFUN (bgp_redistribute_ipv4_metric_rmap,
12292 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 12293 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12294 "Redistribute information from another routing protocol\n"
ab0181ee 12295 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12296 "Metric for redistributed routes\n"
12297 "Default metric\n"
12298 "Route map reference\n"
12299 "Pointer to route-map entries\n")
12300{
d62a17ae 12301 VTY_DECLVAR_CONTEXT(bgp, bgp);
12302 int idx_protocol = 1;
12303 int idx_number = 3;
12304 int idx_word = 5;
12305 int type;
d7c0a89a 12306 uint32_t metric;
d62a17ae 12307 struct bgp_redist *red;
e923dd62 12308 bool changed;
1de27621
DA
12309 struct route_map *route_map =
12310 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12311
12312 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12313 if (type < 0) {
12314 vty_out(vty, "%% Invalid route type\n");
12315 return CMD_WARNING_CONFIG_FAILED;
12316 }
12317 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12318
12319 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12320 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
12321 changed |=
12322 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12323 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12324}
12325
12326ALIAS_HIDDEN(
12327 bgp_redistribute_ipv4_metric_rmap,
12328 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12329 "redistribute " FRR_IP_REDIST_STR_BGPD
12330 " metric (0-4294967295) route-map WORD",
12331 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12332 "Metric for redistributed routes\n"
12333 "Default metric\n"
12334 "Route map reference\n"
12335 "Pointer to route-map entries\n")
596c17ba 12336
7c8ff89e
DS
12337DEFUN (bgp_redistribute_ipv4_ospf,
12338 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 12339 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
12340 "Redistribute information from another routing protocol\n"
12341 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12342 "Non-main Kernel Routing Table\n"
12343 "Instance ID/Table ID\n")
7c8ff89e 12344{
d62a17ae 12345 VTY_DECLVAR_CONTEXT(bgp, bgp);
12346 int idx_ospf_table = 1;
12347 int idx_number = 2;
d7c0a89a
QY
12348 unsigned short instance;
12349 unsigned short protocol;
7c8ff89e 12350
d62a17ae 12351 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 12352
d62a17ae 12353 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12354 protocol = ZEBRA_ROUTE_OSPF;
12355 else
12356 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 12357
d62a17ae 12358 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12359 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
12360}
12361
d62a17ae 12362ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12363 "redistribute <ospf|table> (1-65535)",
12364 "Redistribute information from another routing protocol\n"
12365 "Open Shortest Path First (OSPFv2)\n"
12366 "Non-main Kernel Routing Table\n"
12367 "Instance ID/Table ID\n")
596c17ba 12368
7c8ff89e
DS
12369DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12370 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 12371 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
12372 "Redistribute information from another routing protocol\n"
12373 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12374 "Non-main Kernel Routing Table\n"
12375 "Instance ID/Table ID\n"
7c8ff89e
DS
12376 "Route map reference\n"
12377 "Pointer to route-map entries\n")
12378{
d62a17ae 12379 VTY_DECLVAR_CONTEXT(bgp, bgp);
12380 int idx_ospf_table = 1;
12381 int idx_number = 2;
12382 int idx_word = 4;
12383 struct bgp_redist *red;
d7c0a89a 12384 unsigned short instance;
d62a17ae 12385 int protocol;
e923dd62 12386 bool changed;
1de27621
DA
12387 struct route_map *route_map =
12388 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12389
12390 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12391 protocol = ZEBRA_ROUTE_OSPF;
12392 else
12393 protocol = ZEBRA_ROUTE_TABLE;
12394
12395 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12396 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12397 changed =
12398 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12399 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12400}
12401
12402ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12403 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12404 "redistribute <ospf|table> (1-65535) route-map WORD",
12405 "Redistribute information from another routing protocol\n"
12406 "Open Shortest Path First (OSPFv2)\n"
12407 "Non-main Kernel Routing Table\n"
12408 "Instance ID/Table ID\n"
12409 "Route map reference\n"
12410 "Pointer to route-map entries\n")
596c17ba 12411
7c8ff89e
DS
12412DEFUN (bgp_redistribute_ipv4_ospf_metric,
12413 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 12414 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
12415 "Redistribute information from another routing protocol\n"
12416 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12417 "Non-main Kernel Routing Table\n"
12418 "Instance ID/Table ID\n"
7c8ff89e
DS
12419 "Metric for redistributed routes\n"
12420 "Default metric\n")
12421{
d62a17ae 12422 VTY_DECLVAR_CONTEXT(bgp, bgp);
12423 int idx_ospf_table = 1;
12424 int idx_number = 2;
12425 int idx_number_2 = 4;
d7c0a89a 12426 uint32_t metric;
d62a17ae 12427 struct bgp_redist *red;
d7c0a89a 12428 unsigned short instance;
d62a17ae 12429 int protocol;
e923dd62 12430 bool changed;
d62a17ae 12431
12432 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12433 protocol = ZEBRA_ROUTE_OSPF;
12434 else
12435 protocol = ZEBRA_ROUTE_TABLE;
12436
12437 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12438 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12439
12440 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12441 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12442 metric);
12443 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12444}
12445
12446ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12447 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12448 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12449 "Redistribute information from another routing protocol\n"
12450 "Open Shortest Path First (OSPFv2)\n"
12451 "Non-main Kernel Routing Table\n"
12452 "Instance ID/Table ID\n"
12453 "Metric for redistributed routes\n"
12454 "Default metric\n")
596c17ba 12455
7c8ff89e
DS
12456DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12457 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 12458 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
12459 "Redistribute information from another routing protocol\n"
12460 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12461 "Non-main Kernel Routing Table\n"
12462 "Instance ID/Table ID\n"
7c8ff89e
DS
12463 "Route map reference\n"
12464 "Pointer to route-map entries\n"
12465 "Metric for redistributed routes\n"
12466 "Default metric\n")
12467{
d62a17ae 12468 VTY_DECLVAR_CONTEXT(bgp, bgp);
12469 int idx_ospf_table = 1;
12470 int idx_number = 2;
12471 int idx_word = 4;
12472 int idx_number_2 = 6;
d7c0a89a 12473 uint32_t metric;
d62a17ae 12474 struct bgp_redist *red;
d7c0a89a 12475 unsigned short instance;
d62a17ae 12476 int protocol;
e923dd62 12477 bool changed;
1de27621
DA
12478 struct route_map *route_map =
12479 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12480
12481 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12482 protocol = ZEBRA_ROUTE_OSPF;
12483 else
12484 protocol = ZEBRA_ROUTE_TABLE;
12485
12486 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12487 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12488
12489 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12490 changed =
12491 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12492 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12493 metric);
12494 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12495}
12496
12497ALIAS_HIDDEN(
12498 bgp_redistribute_ipv4_ospf_rmap_metric,
12499 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12500 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12501 "Redistribute information from another routing protocol\n"
12502 "Open Shortest Path First (OSPFv2)\n"
12503 "Non-main Kernel Routing Table\n"
12504 "Instance ID/Table ID\n"
12505 "Route map reference\n"
12506 "Pointer to route-map entries\n"
12507 "Metric for redistributed routes\n"
12508 "Default metric\n")
596c17ba 12509
7c8ff89e
DS
12510DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12511 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 12512 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
12513 "Redistribute information from another routing protocol\n"
12514 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12515 "Non-main Kernel Routing Table\n"
12516 "Instance ID/Table ID\n"
7c8ff89e
DS
12517 "Metric for redistributed routes\n"
12518 "Default metric\n"
12519 "Route map reference\n"
12520 "Pointer to route-map entries\n")
12521{
d62a17ae 12522 VTY_DECLVAR_CONTEXT(bgp, bgp);
12523 int idx_ospf_table = 1;
12524 int idx_number = 2;
12525 int idx_number_2 = 4;
12526 int idx_word = 6;
d7c0a89a 12527 uint32_t metric;
d62a17ae 12528 struct bgp_redist *red;
d7c0a89a 12529 unsigned short instance;
d62a17ae 12530 int protocol;
e923dd62 12531 bool changed;
1de27621
DA
12532 struct route_map *route_map =
12533 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12534
12535 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12536 protocol = ZEBRA_ROUTE_OSPF;
12537 else
12538 protocol = ZEBRA_ROUTE_TABLE;
12539
12540 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12541 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12542
12543 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12544 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12545 metric);
1de27621
DA
12546 changed |=
12547 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12548 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12549}
12550
12551ALIAS_HIDDEN(
12552 bgp_redistribute_ipv4_ospf_metric_rmap,
12553 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12554 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12555 "Redistribute information from another routing protocol\n"
12556 "Open Shortest Path First (OSPFv2)\n"
12557 "Non-main Kernel Routing Table\n"
12558 "Instance ID/Table ID\n"
12559 "Metric for redistributed routes\n"
12560 "Default metric\n"
12561 "Route map reference\n"
12562 "Pointer to route-map entries\n")
596c17ba 12563
7c8ff89e
DS
12564DEFUN (no_bgp_redistribute_ipv4_ospf,
12565 no_bgp_redistribute_ipv4_ospf_cmd,
e27957c0 12566 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
7c8ff89e
DS
12567 NO_STR
12568 "Redistribute information from another routing protocol\n"
12569 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 12570 "Non-main Kernel Routing Table\n"
31500417
DW
12571 "Instance ID/Table ID\n"
12572 "Metric for redistributed routes\n"
12573 "Default metric\n"
12574 "Route map reference\n"
12575 "Pointer to route-map entries\n")
7c8ff89e 12576{
d62a17ae 12577 VTY_DECLVAR_CONTEXT(bgp, bgp);
12578 int idx_ospf_table = 2;
12579 int idx_number = 3;
d7c0a89a 12580 unsigned short instance;
d62a17ae 12581 int protocol;
12582
12583 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12584 protocol = ZEBRA_ROUTE_OSPF;
12585 else
12586 protocol = ZEBRA_ROUTE_TABLE;
12587
12588 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12589 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12590}
12591
12592ALIAS_HIDDEN(
12593 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 12594 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 12595 NO_STR
12596 "Redistribute information from another routing protocol\n"
12597 "Open Shortest Path First (OSPFv2)\n"
12598 "Non-main Kernel Routing Table\n"
12599 "Instance ID/Table ID\n"
12600 "Metric for redistributed routes\n"
12601 "Default metric\n"
12602 "Route map reference\n"
12603 "Pointer to route-map entries\n")
596c17ba 12604
718e3744 12605DEFUN (no_bgp_redistribute_ipv4,
12606 no_bgp_redistribute_ipv4_cmd,
e27957c0 12607 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 12608 NO_STR
12609 "Redistribute information from another routing protocol\n"
3b14d86e 12610 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
12611 "Metric for redistributed routes\n"
12612 "Default metric\n"
12613 "Route map reference\n"
12614 "Pointer to route-map entries\n")
718e3744 12615{
d62a17ae 12616 VTY_DECLVAR_CONTEXT(bgp, bgp);
12617 int idx_protocol = 2;
12618 int type;
12619
12620 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12621 if (type < 0) {
12622 vty_out(vty, "%% Invalid route type\n");
12623 return CMD_WARNING_CONFIG_FAILED;
12624 }
12625 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12626}
12627
12628ALIAS_HIDDEN(
12629 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12630 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 12631 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 12632 NO_STR
12633 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12634 "Metric for redistributed routes\n"
12635 "Default metric\n"
12636 "Route map reference\n"
12637 "Pointer to route-map entries\n")
596c17ba 12638
718e3744 12639DEFUN (bgp_redistribute_ipv6,
12640 bgp_redistribute_ipv6_cmd,
40d1cbfb 12641 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 12642 "Redistribute information from another routing protocol\n"
ab0181ee 12643 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 12644{
d62a17ae 12645 VTY_DECLVAR_CONTEXT(bgp, bgp);
12646 int idx_protocol = 1;
12647 int type;
718e3744 12648
d62a17ae 12649 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12650 if (type < 0) {
12651 vty_out(vty, "%% Invalid route type\n");
12652 return CMD_WARNING_CONFIG_FAILED;
12653 }
718e3744 12654
d62a17ae 12655 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12656 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 12657}
12658
12659DEFUN (bgp_redistribute_ipv6_rmap,
12660 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 12661 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 12662 "Redistribute information from another routing protocol\n"
ab0181ee 12663 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12664 "Route map reference\n"
12665 "Pointer to route-map entries\n")
12666{
d62a17ae 12667 VTY_DECLVAR_CONTEXT(bgp, bgp);
12668 int idx_protocol = 1;
12669 int idx_word = 3;
12670 int type;
12671 struct bgp_redist *red;
e923dd62 12672 bool changed;
1de27621
DA
12673 struct route_map *route_map =
12674 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 12675
d62a17ae 12676 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12677 if (type < 0) {
12678 vty_out(vty, "%% Invalid route type\n");
12679 return CMD_WARNING_CONFIG_FAILED;
12680 }
718e3744 12681
d62a17ae 12682 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12683 changed =
12684 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12685 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12686}
12687
12688DEFUN (bgp_redistribute_ipv6_metric,
12689 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 12690 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12691 "Redistribute information from another routing protocol\n"
ab0181ee 12692 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12693 "Metric for redistributed routes\n"
12694 "Default metric\n")
12695{
d62a17ae 12696 VTY_DECLVAR_CONTEXT(bgp, bgp);
12697 int idx_protocol = 1;
12698 int idx_number = 3;
12699 int type;
d7c0a89a 12700 uint32_t metric;
d62a17ae 12701 struct bgp_redist *red;
e923dd62 12702 bool changed;
d62a17ae 12703
12704 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12705 if (type < 0) {
12706 vty_out(vty, "%% Invalid route type\n");
12707 return CMD_WARNING_CONFIG_FAILED;
12708 }
12709 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12710
d62a17ae 12711 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12712 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12713 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12714}
12715
12716DEFUN (bgp_redistribute_ipv6_rmap_metric,
12717 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 12718 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12719 "Redistribute information from another routing protocol\n"
ab0181ee 12720 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12721 "Route map reference\n"
12722 "Pointer to route-map entries\n"
12723 "Metric for redistributed routes\n"
12724 "Default metric\n")
12725{
d62a17ae 12726 VTY_DECLVAR_CONTEXT(bgp, bgp);
12727 int idx_protocol = 1;
12728 int idx_word = 3;
12729 int idx_number = 5;
12730 int type;
d7c0a89a 12731 uint32_t metric;
d62a17ae 12732 struct bgp_redist *red;
e923dd62 12733 bool changed;
1de27621
DA
12734 struct route_map *route_map =
12735 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12736
12737 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12738 if (type < 0) {
12739 vty_out(vty, "%% Invalid route type\n");
12740 return CMD_WARNING_CONFIG_FAILED;
12741 }
12742 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12743
d62a17ae 12744 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12745 changed =
12746 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12747 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12748 metric);
12749 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12750}
12751
12752DEFUN (bgp_redistribute_ipv6_metric_rmap,
12753 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 12754 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12755 "Redistribute information from another routing protocol\n"
ab0181ee 12756 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12757 "Metric for redistributed routes\n"
12758 "Default metric\n"
12759 "Route map reference\n"
12760 "Pointer to route-map entries\n")
12761{
d62a17ae 12762 VTY_DECLVAR_CONTEXT(bgp, bgp);
12763 int idx_protocol = 1;
12764 int idx_number = 3;
12765 int idx_word = 5;
12766 int type;
d7c0a89a 12767 uint32_t metric;
d62a17ae 12768 struct bgp_redist *red;
e923dd62 12769 bool changed;
1de27621
DA
12770 struct route_map *route_map =
12771 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12772
12773 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12774 if (type < 0) {
12775 vty_out(vty, "%% Invalid route type\n");
12776 return CMD_WARNING_CONFIG_FAILED;
12777 }
12778 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12779
d62a17ae 12780 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12781 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12782 metric);
1de27621
DA
12783 changed |=
12784 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12785 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12786}
12787
12788DEFUN (no_bgp_redistribute_ipv6,
12789 no_bgp_redistribute_ipv6_cmd,
e27957c0 12790 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 12791 NO_STR
12792 "Redistribute information from another routing protocol\n"
3b14d86e 12793 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12794 "Metric for redistributed routes\n"
12795 "Default metric\n"
12796 "Route map reference\n"
12797 "Pointer to route-map entries\n")
718e3744 12798{
d62a17ae 12799 VTY_DECLVAR_CONTEXT(bgp, bgp);
12800 int idx_protocol = 2;
12801 int type;
718e3744 12802
d62a17ae 12803 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12804 if (type < 0) {
12805 vty_out(vty, "%% Invalid route type\n");
12806 return CMD_WARNING_CONFIG_FAILED;
12807 }
718e3744 12808
d62a17ae 12809 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12810}
12811
2b791107 12812void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12813 safi_t safi)
d62a17ae 12814{
12815 int i;
12816
12817 /* Unicast redistribution only. */
12818 if (safi != SAFI_UNICAST)
2b791107 12819 return;
d62a17ae 12820
12821 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12822 /* Redistribute BGP does not make sense. */
12823 if (i != ZEBRA_ROUTE_BGP) {
12824 struct list *red_list;
12825 struct listnode *node;
12826 struct bgp_redist *red;
12827
12828 red_list = bgp->redist[afi][i];
12829 if (!red_list)
12830 continue;
12831
12832 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12833 /* "redistribute" configuration. */
12834 vty_out(vty, " redistribute %s",
12835 zebra_route_string(i));
12836 if (red->instance)
12837 vty_out(vty, " %d", red->instance);
12838 if (red->redist_metric_flag)
12839 vty_out(vty, " metric %u",
12840 red->redist_metric);
12841 if (red->rmap.name)
12842 vty_out(vty, " route-map %s",
12843 red->rmap.name);
12844 vty_out(vty, "\n");
12845 }
12846 }
12847 }
718e3744 12848}
6b0655a2 12849
b9c7bc5a
PZ
12850/* This is part of the address-family block (unicast only) */
12851void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12852 afi_t afi)
12853{
b9c7bc5a 12854 int indent = 2;
ddb5b488 12855
8a066a70
PG
12856 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12857 if (listcount(bgp->vpn_policy[afi].import_vrf))
12858 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12859 bgp->vpn_policy[afi]
bb4f6190 12860 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
12861 else
12862 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12863 bgp->vpn_policy[afi]
12864 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12865 }
12a844a5
DS
12866 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12867 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12868 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12869 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12870 return;
12871
e70e9f8e
PZ
12872 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12873 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12874
12875 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12876
12877 } else {
12878 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12879 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12880 bgp->vpn_policy[afi].tovpn_label);
12881 }
ddb5b488
PZ
12882 }
12883 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12884 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12885 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12886 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12887 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12888 sizeof(buf)));
12889 }
12890 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12891 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12892
12893 char buf[PREFIX_STRLEN];
12894 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12895 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12896 sizeof(buf))) {
12897
b9c7bc5a
PZ
12898 vty_out(vty, "%*snexthop vpn export %s\n",
12899 indent, "", buf);
ddb5b488
PZ
12900 }
12901 }
12902 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12903 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12904 && ecommunity_cmp(
12905 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12906 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12907
12908 char *b = ecommunity_ecom2str(
12909 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12910 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12911 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12912 XFREE(MTYPE_ECOMMUNITY_STR, b);
12913 } else {
12914 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12915 char *b = ecommunity_ecom2str(
12916 bgp->vpn_policy[afi]
12917 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12918 ECOMMUNITY_FORMAT_ROUTE_MAP,
12919 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12920 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12921 XFREE(MTYPE_ECOMMUNITY_STR, b);
12922 }
12923 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12924 char *b = ecommunity_ecom2str(
12925 bgp->vpn_policy[afi]
12926 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12927 ECOMMUNITY_FORMAT_ROUTE_MAP,
12928 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12929 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12930 XFREE(MTYPE_ECOMMUNITY_STR, b);
12931 }
12932 }
bb4f6190
DS
12933
12934 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12935 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12936 bgp->vpn_policy[afi]
12937 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12938
301ad80a
PG
12939 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12940 char *b = ecommunity_ecom2str(
12941 bgp->vpn_policy[afi]
12942 .import_redirect_rtlist,
12943 ECOMMUNITY_FORMAT_ROUTE_MAP,
12944 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12945
301ad80a
PG
12946 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12947 XFREE(MTYPE_ECOMMUNITY_STR, b);
12948 }
ddb5b488
PZ
12949}
12950
12951
718e3744 12952/* BGP node structure. */
d62a17ae 12953static struct cmd_node bgp_node = {
9d303b37 12954 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12955};
12956
d62a17ae 12957static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12958 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12959};
12960
d62a17ae 12961static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12962 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12963};
12964
d62a17ae 12965static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12966 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12967};
12968
d62a17ae 12969static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12970 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12971};
12972
d62a17ae 12973static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12974 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12975};
12976
d62a17ae 12977static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12978 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12979};
12980
d62a17ae 12981static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12982 "%s(config-router-af)# ", 1};
6b0655a2 12983
d62a17ae 12984static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12985 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12986
d62a17ae 12987static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12988 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12989
d62a17ae 12990static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12991 "%s(config-router-af-vni)# ", 1};
90e60aa7 12992
7c40bf39 12993static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12994 "%s(config-router-af)# ", 1};
12995
12996static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12997 "%s(config-router-af-vpnv6)# ", 1};
12998
d62a17ae 12999static void community_list_vty(void);
1f8ae70b 13000
d62a17ae 13001static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 13002{
d62a17ae 13003 struct bgp *bgp;
13004 struct peer *peer;
d62a17ae 13005 struct listnode *lnbgp, *lnpeer;
b8a815e5 13006
d62a17ae 13007 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
13008 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
13009 /* only provide suggestions on the appropriate input
13010 * token type,
13011 * they'll otherwise show up multiple times */
13012 enum cmd_token_type match_type;
13013 char *name = peer->host;
d48ed3e0 13014
d62a17ae 13015 if (peer->conf_if) {
13016 match_type = VARIABLE_TKN;
13017 name = peer->conf_if;
13018 } else if (strchr(peer->host, ':'))
13019 match_type = IPV6_TKN;
13020 else
13021 match_type = IPV4_TKN;
d48ed3e0 13022
d62a17ae 13023 if (token->type != match_type)
13024 continue;
d48ed3e0 13025
d62a17ae 13026 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
13027 }
d62a17ae 13028 }
b8a815e5
DL
13029}
13030
13031static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 13032 {.varname = "neighbor", .completions = bgp_ac_neighbor},
13033 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 13034 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 13035 {.completions = NULL}};
13036
47a306a0
DS
13037static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
13038{
13039 struct bgp *bgp;
13040 struct peer_group *group;
13041 struct listnode *lnbgp, *lnpeer;
13042
13043 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
13044 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
13045 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
13046 group->name));
13047 }
13048}
13049
13050static const struct cmd_variable_handler bgp_var_peergroup[] = {
13051 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
13052 {.completions = NULL} };
13053
d62a17ae 13054void bgp_vty_init(void)
13055{
13056 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 13057 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 13058
13059 /* Install bgp top node. */
13060 install_node(&bgp_node, bgp_config_write);
13061 install_node(&bgp_ipv4_unicast_node, NULL);
13062 install_node(&bgp_ipv4_multicast_node, NULL);
13063 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
13064 install_node(&bgp_ipv6_unicast_node, NULL);
13065 install_node(&bgp_ipv6_multicast_node, NULL);
13066 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
13067 install_node(&bgp_vpnv4_node, NULL);
13068 install_node(&bgp_vpnv6_node, NULL);
13069 install_node(&bgp_evpn_node, NULL);
13070 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 13071 install_node(&bgp_flowspecv4_node, NULL);
13072 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 13073
13074 /* Install default VTY commands to new nodes. */
13075 install_default(BGP_NODE);
13076 install_default(BGP_IPV4_NODE);
13077 install_default(BGP_IPV4M_NODE);
13078 install_default(BGP_IPV4L_NODE);
13079 install_default(BGP_IPV6_NODE);
13080 install_default(BGP_IPV6M_NODE);
13081 install_default(BGP_IPV6L_NODE);
13082 install_default(BGP_VPNV4_NODE);
13083 install_default(BGP_VPNV6_NODE);
7c40bf39 13084 install_default(BGP_FLOWSPECV4_NODE);
13085 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 13086 install_default(BGP_EVPN_NODE);
13087 install_default(BGP_EVPN_VNI_NODE);
13088
8029b216
AK
13089 /* "bgp local-mac" hidden commands. */
13090 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
13091 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
13092
d62a17ae 13093 /* bgp route-map delay-timer commands. */
13094 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
13095 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13096
13097 /* Dummy commands (Currently not supported) */
13098 install_element(BGP_NODE, &no_synchronization_cmd);
13099 install_element(BGP_NODE, &no_auto_summary_cmd);
13100
13101 /* "router bgp" commands. */
13102 install_element(CONFIG_NODE, &router_bgp_cmd);
13103
13104 /* "no router bgp" commands. */
13105 install_element(CONFIG_NODE, &no_router_bgp_cmd);
13106
13107 /* "bgp router-id" commands. */
13108 install_element(BGP_NODE, &bgp_router_id_cmd);
13109 install_element(BGP_NODE, &no_bgp_router_id_cmd);
13110
13111 /* "bgp cluster-id" commands. */
13112 install_element(BGP_NODE, &bgp_cluster_id_cmd);
13113 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
13114
13115 /* "bgp confederation" commands. */
13116 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
13117 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
13118
13119 /* "bgp confederation peers" commands. */
13120 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
13121 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
13122
13123 /* bgp max-med command */
13124 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
13125 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
13126 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
13127 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
13128 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
13129
13130 /* bgp disable-ebgp-connected-nh-check */
13131 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
13132 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
13133
13134 /* bgp update-delay command */
13135 install_element(BGP_NODE, &bgp_update_delay_cmd);
13136 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
13137 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
13138
13139 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 13140 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 13141
13142 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
13143 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
13144
13145 /* "maximum-paths" commands. */
13146 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
13147 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
13148 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
13149 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
13150 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
13151 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
13152 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
13153 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
13154 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
13155 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
13156 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13157 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
13158 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
13159 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13160 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
13161
13162 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
13163 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
13164 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
13165 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13166 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
13167
13168 /* "timers bgp" commands. */
13169 install_element(BGP_NODE, &bgp_timers_cmd);
13170 install_element(BGP_NODE, &no_bgp_timers_cmd);
13171
13172 /* route-map delay-timer commands - per instance for backwards compat.
13173 */
13174 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
13175 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13176
13177 /* "bgp client-to-client reflection" commands */
13178 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
13179 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
13180
13181 /* "bgp always-compare-med" commands */
13182 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
13183 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
13184
9dac9fc8
DA
13185 /* bgp ebgp-requires-policy */
13186 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
13187 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
13188
fb29348a
DA
13189 /* bgp reject-as-sets */
13190 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
13191 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
13192
d62a17ae 13193 /* "bgp deterministic-med" commands */
13194 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
13195 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
13196
13197 /* "bgp graceful-restart" commands */
13198 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
13199 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
13200 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
13201 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
13202 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
13203 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
13204
13205 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
13206 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
13207
7f323236
DW
13208 /* "bgp graceful-shutdown" commands */
13209 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
13210 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13211
d62a17ae 13212 /* "bgp fast-external-failover" commands */
13213 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13214 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13215
d62a17ae 13216 /* "bgp bestpath compare-routerid" commands */
13217 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13218 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13219
13220 /* "bgp bestpath as-path ignore" commands */
13221 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13222 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13223
13224 /* "bgp bestpath as-path confed" commands */
13225 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13226 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13227
13228 /* "bgp bestpath as-path multipath-relax" commands */
13229 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13230 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13231
13232 /* "bgp log-neighbor-changes" commands */
13233 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13234 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13235
13236 /* "bgp bestpath med" commands */
13237 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13238 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13239
13240 /* "no bgp default ipv4-unicast" commands. */
13241 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13242 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13243
13244 /* "bgp network import-check" commands. */
13245 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13246 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13247 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13248
13249 /* "bgp default local-preference" commands. */
13250 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13251 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13252
13253 /* bgp default show-hostname */
13254 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13255 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13256
13257 /* "bgp default subgroup-pkt-queue-max" commands. */
13258 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13259 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13260
13261 /* bgp ibgp-allow-policy-mods command */
13262 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13263 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13264
13265 /* "bgp listen limit" commands. */
13266 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13267 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13268
13269 /* "bgp listen range" commands. */
13270 install_element(BGP_NODE, &bgp_listen_range_cmd);
13271 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13272
8175f54a 13273 /* "bgp default shutdown" command */
f26845f9
QY
13274 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13275
d62a17ae 13276 /* "neighbor remote-as" commands. */
13277 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13278 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13279 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13280 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13281 install_element(BGP_NODE,
13282 &neighbor_interface_v6only_config_remote_as_cmd);
13283 install_element(BGP_NODE, &no_neighbor_cmd);
13284 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13285
13286 /* "neighbor peer-group" commands. */
13287 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13288 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13289 install_element(BGP_NODE,
13290 &no_neighbor_interface_peer_group_remote_as_cmd);
13291
13292 /* "neighbor local-as" commands. */
13293 install_element(BGP_NODE, &neighbor_local_as_cmd);
13294 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13295 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13296 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13297
13298 /* "neighbor solo" commands. */
13299 install_element(BGP_NODE, &neighbor_solo_cmd);
13300 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13301
13302 /* "neighbor password" commands. */
13303 install_element(BGP_NODE, &neighbor_password_cmd);
13304 install_element(BGP_NODE, &no_neighbor_password_cmd);
13305
13306 /* "neighbor activate" commands. */
13307 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13308 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13309 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13310 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13311 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13312 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13313 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13314 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13315 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 13316 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13317 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 13318 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13319
13320 /* "no neighbor activate" commands. */
13321 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13322 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13323 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13324 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13325 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13326 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13327 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13328 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13329 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 13330 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13331 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 13332 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13333
13334 /* "neighbor peer-group" set commands. */
13335 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13336 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13337 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13338 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13339 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13340 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13341 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13342 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 13343 install_element(BGP_FLOWSPECV4_NODE,
13344 &neighbor_set_peer_group_hidden_cmd);
13345 install_element(BGP_FLOWSPECV6_NODE,
13346 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 13347
13348 /* "no neighbor peer-group unset" commands. */
13349 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13350 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13351 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13352 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13353 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13354 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13355 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13356 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 13357 install_element(BGP_FLOWSPECV4_NODE,
13358 &no_neighbor_set_peer_group_hidden_cmd);
13359 install_element(BGP_FLOWSPECV6_NODE,
13360 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 13361
13362 /* "neighbor softreconfiguration inbound" commands.*/
13363 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13364 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13365 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13366 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13367 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13368 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13369 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13370 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13371 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13372 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13373 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13374 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13375 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13376 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13377 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13378 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13379 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13380 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 13381 install_element(BGP_FLOWSPECV4_NODE,
13382 &neighbor_soft_reconfiguration_cmd);
13383 install_element(BGP_FLOWSPECV4_NODE,
13384 &no_neighbor_soft_reconfiguration_cmd);
13385 install_element(BGP_FLOWSPECV6_NODE,
13386 &neighbor_soft_reconfiguration_cmd);
13387 install_element(BGP_FLOWSPECV6_NODE,
13388 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
13389 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13390 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 13391
13392 /* "neighbor attribute-unchanged" commands. */
13393 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13394 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13395 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13396 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13397 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13398 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13399 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13400 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13401 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13402 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13403 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13404 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13405 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13406 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13407 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13408 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13409 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13410 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13411
13412 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13413 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13414
13415 /* "nexthop-local unchanged" commands */
13416 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13417 install_element(BGP_IPV6_NODE,
13418 &no_neighbor_nexthop_local_unchanged_cmd);
13419
13420 /* "neighbor next-hop-self" commands. */
13421 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13422 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13423 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13424 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13425 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13426 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13427 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13428 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13429 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13430 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13431 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13432 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13433 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13434 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13435 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13436 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13437 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13438 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
13439 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13440 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 13441
13442 /* "neighbor next-hop-self force" commands. */
13443 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13444 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
13445 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13446 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13447 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13448 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13449 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13450 install_element(BGP_IPV4_NODE,
13451 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13452 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13453 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13454 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13455 install_element(BGP_IPV4M_NODE,
13456 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13457 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13458 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13459 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13460 install_element(BGP_IPV4L_NODE,
13461 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13462 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13463 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13464 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13465 install_element(BGP_IPV6_NODE,
13466 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13467 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13468 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13469 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13470 install_element(BGP_IPV6M_NODE,
13471 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13472 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13473 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13474 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13475 install_element(BGP_IPV6L_NODE,
13476 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13477 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13478 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13479 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13480 install_element(BGP_VPNV4_NODE,
13481 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13482 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13483 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13484 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13485 install_element(BGP_VPNV6_NODE,
13486 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13487
13488 /* "neighbor as-override" commands. */
13489 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13490 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13491 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13492 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13493 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13494 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13495 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13496 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13497 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13498 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13499 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13500 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13501 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13502 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13503 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13504 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13505 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13506 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13507
13508 /* "neighbor remove-private-AS" commands. */
13509 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13510 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13511 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13512 install_element(BGP_NODE,
13513 &no_neighbor_remove_private_as_all_hidden_cmd);
13514 install_element(BGP_NODE,
13515 &neighbor_remove_private_as_replace_as_hidden_cmd);
13516 install_element(BGP_NODE,
13517 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13518 install_element(BGP_NODE,
13519 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13520 install_element(
13521 BGP_NODE,
13522 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13523 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13524 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13525 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13526 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13527 install_element(BGP_IPV4_NODE,
13528 &neighbor_remove_private_as_replace_as_cmd);
13529 install_element(BGP_IPV4_NODE,
13530 &no_neighbor_remove_private_as_replace_as_cmd);
13531 install_element(BGP_IPV4_NODE,
13532 &neighbor_remove_private_as_all_replace_as_cmd);
13533 install_element(BGP_IPV4_NODE,
13534 &no_neighbor_remove_private_as_all_replace_as_cmd);
13535 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13536 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13537 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13538 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13539 install_element(BGP_IPV4M_NODE,
13540 &neighbor_remove_private_as_replace_as_cmd);
13541 install_element(BGP_IPV4M_NODE,
13542 &no_neighbor_remove_private_as_replace_as_cmd);
13543 install_element(BGP_IPV4M_NODE,
13544 &neighbor_remove_private_as_all_replace_as_cmd);
13545 install_element(BGP_IPV4M_NODE,
13546 &no_neighbor_remove_private_as_all_replace_as_cmd);
13547 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13548 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13549 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13550 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13551 install_element(BGP_IPV4L_NODE,
13552 &neighbor_remove_private_as_replace_as_cmd);
13553 install_element(BGP_IPV4L_NODE,
13554 &no_neighbor_remove_private_as_replace_as_cmd);
13555 install_element(BGP_IPV4L_NODE,
13556 &neighbor_remove_private_as_all_replace_as_cmd);
13557 install_element(BGP_IPV4L_NODE,
13558 &no_neighbor_remove_private_as_all_replace_as_cmd);
13559 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13560 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13561 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13562 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13563 install_element(BGP_IPV6_NODE,
13564 &neighbor_remove_private_as_replace_as_cmd);
13565 install_element(BGP_IPV6_NODE,
13566 &no_neighbor_remove_private_as_replace_as_cmd);
13567 install_element(BGP_IPV6_NODE,
13568 &neighbor_remove_private_as_all_replace_as_cmd);
13569 install_element(BGP_IPV6_NODE,
13570 &no_neighbor_remove_private_as_all_replace_as_cmd);
13571 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13572 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13573 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13574 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13575 install_element(BGP_IPV6M_NODE,
13576 &neighbor_remove_private_as_replace_as_cmd);
13577 install_element(BGP_IPV6M_NODE,
13578 &no_neighbor_remove_private_as_replace_as_cmd);
13579 install_element(BGP_IPV6M_NODE,
13580 &neighbor_remove_private_as_all_replace_as_cmd);
13581 install_element(BGP_IPV6M_NODE,
13582 &no_neighbor_remove_private_as_all_replace_as_cmd);
13583 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13584 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13585 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13586 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13587 install_element(BGP_IPV6L_NODE,
13588 &neighbor_remove_private_as_replace_as_cmd);
13589 install_element(BGP_IPV6L_NODE,
13590 &no_neighbor_remove_private_as_replace_as_cmd);
13591 install_element(BGP_IPV6L_NODE,
13592 &neighbor_remove_private_as_all_replace_as_cmd);
13593 install_element(BGP_IPV6L_NODE,
13594 &no_neighbor_remove_private_as_all_replace_as_cmd);
13595 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13596 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13597 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13598 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13599 install_element(BGP_VPNV4_NODE,
13600 &neighbor_remove_private_as_replace_as_cmd);
13601 install_element(BGP_VPNV4_NODE,
13602 &no_neighbor_remove_private_as_replace_as_cmd);
13603 install_element(BGP_VPNV4_NODE,
13604 &neighbor_remove_private_as_all_replace_as_cmd);
13605 install_element(BGP_VPNV4_NODE,
13606 &no_neighbor_remove_private_as_all_replace_as_cmd);
13607 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13608 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13609 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13610 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13611 install_element(BGP_VPNV6_NODE,
13612 &neighbor_remove_private_as_replace_as_cmd);
13613 install_element(BGP_VPNV6_NODE,
13614 &no_neighbor_remove_private_as_replace_as_cmd);
13615 install_element(BGP_VPNV6_NODE,
13616 &neighbor_remove_private_as_all_replace_as_cmd);
13617 install_element(BGP_VPNV6_NODE,
13618 &no_neighbor_remove_private_as_all_replace_as_cmd);
13619
13620 /* "neighbor send-community" commands.*/
13621 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13622 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13623 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13624 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13625 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13626 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13627 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13628 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13629 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13630 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13631 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13632 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13633 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13634 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13635 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13636 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13637 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13638 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13639 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13640 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13641 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13642 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13643 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13644 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13645 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13646 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13647 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13648 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13649 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13650 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13651 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13652 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13653 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13654 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13655 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13656 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13657
13658 /* "neighbor route-reflector" commands.*/
13659 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13660 install_element(BGP_NODE,
13661 &no_neighbor_route_reflector_client_hidden_cmd);
13662 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13663 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13664 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13665 install_element(BGP_IPV4M_NODE,
13666 &no_neighbor_route_reflector_client_cmd);
13667 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13668 install_element(BGP_IPV4L_NODE,
13669 &no_neighbor_route_reflector_client_cmd);
13670 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13671 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13672 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13673 install_element(BGP_IPV6M_NODE,
13674 &no_neighbor_route_reflector_client_cmd);
13675 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13676 install_element(BGP_IPV6L_NODE,
13677 &no_neighbor_route_reflector_client_cmd);
13678 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13679 install_element(BGP_VPNV4_NODE,
13680 &no_neighbor_route_reflector_client_cmd);
13681 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13682 install_element(BGP_VPNV6_NODE,
13683 &no_neighbor_route_reflector_client_cmd);
7c40bf39 13684 install_element(BGP_FLOWSPECV4_NODE,
13685 &neighbor_route_reflector_client_cmd);
13686 install_element(BGP_FLOWSPECV4_NODE,
13687 &no_neighbor_route_reflector_client_cmd);
13688 install_element(BGP_FLOWSPECV6_NODE,
13689 &neighbor_route_reflector_client_cmd);
13690 install_element(BGP_FLOWSPECV6_NODE,
13691 &no_neighbor_route_reflector_client_cmd);
d62a17ae 13692 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13693 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13694
13695 /* "neighbor route-server" commands.*/
13696 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13697 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13698 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13699 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13700 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13701 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13702 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13703 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13704 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13705 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13706 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13707 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13708 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13709 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13710 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13711 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13712 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13713 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
13714 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13715 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 13716 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13717 install_element(BGP_FLOWSPECV4_NODE,
13718 &no_neighbor_route_server_client_cmd);
13719 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13720 install_element(BGP_FLOWSPECV6_NODE,
13721 &no_neighbor_route_server_client_cmd);
d62a17ae 13722
13723 /* "neighbor addpath-tx-all-paths" commands.*/
13724 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13725 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13726 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13727 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13728 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13729 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13730 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13731 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13732 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13733 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13734 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13735 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13736 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13737 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13738 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13739 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13740 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13741 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13742
13743 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13744 install_element(BGP_NODE,
13745 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13746 install_element(BGP_NODE,
13747 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13748 install_element(BGP_IPV4_NODE,
13749 &neighbor_addpath_tx_bestpath_per_as_cmd);
13750 install_element(BGP_IPV4_NODE,
13751 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13752 install_element(BGP_IPV4M_NODE,
13753 &neighbor_addpath_tx_bestpath_per_as_cmd);
13754 install_element(BGP_IPV4M_NODE,
13755 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13756 install_element(BGP_IPV4L_NODE,
13757 &neighbor_addpath_tx_bestpath_per_as_cmd);
13758 install_element(BGP_IPV4L_NODE,
13759 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13760 install_element(BGP_IPV6_NODE,
13761 &neighbor_addpath_tx_bestpath_per_as_cmd);
13762 install_element(BGP_IPV6_NODE,
13763 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13764 install_element(BGP_IPV6M_NODE,
13765 &neighbor_addpath_tx_bestpath_per_as_cmd);
13766 install_element(BGP_IPV6M_NODE,
13767 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13768 install_element(BGP_IPV6L_NODE,
13769 &neighbor_addpath_tx_bestpath_per_as_cmd);
13770 install_element(BGP_IPV6L_NODE,
13771 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13772 install_element(BGP_VPNV4_NODE,
13773 &neighbor_addpath_tx_bestpath_per_as_cmd);
13774 install_element(BGP_VPNV4_NODE,
13775 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13776 install_element(BGP_VPNV6_NODE,
13777 &neighbor_addpath_tx_bestpath_per_as_cmd);
13778 install_element(BGP_VPNV6_NODE,
13779 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13780
2b31007c
RZ
13781 /* "neighbor sender-as-path-loop-detection" commands. */
13782 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
13783 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
13784
d62a17ae 13785 /* "neighbor passive" commands. */
13786 install_element(BGP_NODE, &neighbor_passive_cmd);
13787 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13788
13789
13790 /* "neighbor shutdown" commands. */
13791 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13792 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13793 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13794 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13795
13796 /* "neighbor capability extended-nexthop" commands.*/
13797 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13798 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13799
13800 /* "neighbor capability orf prefix-list" commands.*/
13801 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13802 install_element(BGP_NODE,
13803 &no_neighbor_capability_orf_prefix_hidden_cmd);
13804 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13805 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13806 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13807 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13808 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13809 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13810 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13811 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13812 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13813 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13814 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13815 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13816
13817 /* "neighbor capability dynamic" commands.*/
13818 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13819 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13820
13821 /* "neighbor dont-capability-negotiate" commands. */
13822 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13823 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13824
13825 /* "neighbor ebgp-multihop" commands. */
13826 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13827 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13828 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13829
13830 /* "neighbor disable-connected-check" commands. */
13831 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13832 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13833
47cbc09b
PM
13834 /* "neighbor enforce-first-as" commands. */
13835 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13836 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13837
d62a17ae 13838 /* "neighbor description" commands. */
13839 install_element(BGP_NODE, &neighbor_description_cmd);
13840 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13841 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13842
13843 /* "neighbor update-source" commands. "*/
13844 install_element(BGP_NODE, &neighbor_update_source_cmd);
13845 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13846
13847 /* "neighbor default-originate" commands. */
13848 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13849 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13850 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13851 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13852 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13853 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13854 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13855 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13856 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13857 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13858 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13859 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13860 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13861 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13862 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13863 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13864 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13865 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13866 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13867 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13868 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13869
13870 /* "neighbor port" commands. */
13871 install_element(BGP_NODE, &neighbor_port_cmd);
13872 install_element(BGP_NODE, &no_neighbor_port_cmd);
13873
13874 /* "neighbor weight" commands. */
13875 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13876 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13877
13878 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13879 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13880 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13881 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13882 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13883 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13884 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13885 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13886 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13887 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13888 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13889 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13890 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13891 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13892 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13893 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13894
13895 /* "neighbor override-capability" commands. */
13896 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13897 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13898
13899 /* "neighbor strict-capability-match" commands. */
13900 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13901 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13902
13903 /* "neighbor timers" commands. */
13904 install_element(BGP_NODE, &neighbor_timers_cmd);
13905 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13906
13907 /* "neighbor timers connect" commands. */
13908 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13909 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13910
13911 /* "neighbor advertisement-interval" commands. */
13912 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13913 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13914
13915 /* "neighbor interface" commands. */
13916 install_element(BGP_NODE, &neighbor_interface_cmd);
13917 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13918
13919 /* "neighbor distribute" commands. */
13920 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13921 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13922 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13923 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13924 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13925 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13926 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13927 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13928 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13929 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13930 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13931 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13932 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13933 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13934 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13935 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13936 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13937 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13938
13939 /* "neighbor prefix-list" commands. */
13940 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13941 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13942 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13943 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13944 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13945 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13946 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13947 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13948 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13949 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13950 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13951 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13952 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13953 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13954 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13955 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13956 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13957 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13958 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13959 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13960 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13961 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13962
13963 /* "neighbor filter-list" commands. */
13964 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13965 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13966 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13967 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13968 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13969 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13970 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13971 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13972 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13973 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13974 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13975 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13976 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13977 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13978 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13979 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13980 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13981 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13982 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13983 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13984 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13985 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13986
13987 /* "neighbor route-map" commands. */
13988 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13989 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13990 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13991 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13992 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13993 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13994 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13995 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13996 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13997 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13998 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13999 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
14000 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
14001 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
14002 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
14003 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
14004 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
14005 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 14006 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
14007 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
14008 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
14009 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
14010 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
14011 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 14012
14013 /* "neighbor unsuppress-map" commands. */
14014 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
14015 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
14016 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
14017 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
14018 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
14019 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
14020 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
14021 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
14022 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
14023 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
14024 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
14025 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
14026 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
14027 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
14028 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
14029 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
14030 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
14031 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
14032
14033 /* "neighbor maximum-prefix" commands. */
14034 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
14035 install_element(BGP_NODE,
14036 &neighbor_maximum_prefix_threshold_hidden_cmd);
14037 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
14038 install_element(BGP_NODE,
14039 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
14040 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
14041 install_element(BGP_NODE,
14042 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
14043 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
14044 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
14045 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
14046 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
14047 install_element(BGP_IPV4_NODE,
14048 &neighbor_maximum_prefix_threshold_warning_cmd);
14049 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
14050 install_element(BGP_IPV4_NODE,
14051 &neighbor_maximum_prefix_threshold_restart_cmd);
14052 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
14053 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
14054 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
14055 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
14056 install_element(BGP_IPV4M_NODE,
14057 &neighbor_maximum_prefix_threshold_warning_cmd);
14058 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
14059 install_element(BGP_IPV4M_NODE,
14060 &neighbor_maximum_prefix_threshold_restart_cmd);
14061 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
14062 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
14063 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
14064 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
14065 install_element(BGP_IPV4L_NODE,
14066 &neighbor_maximum_prefix_threshold_warning_cmd);
14067 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
14068 install_element(BGP_IPV4L_NODE,
14069 &neighbor_maximum_prefix_threshold_restart_cmd);
14070 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
14071 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
14072 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
14073 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
14074 install_element(BGP_IPV6_NODE,
14075 &neighbor_maximum_prefix_threshold_warning_cmd);
14076 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
14077 install_element(BGP_IPV6_NODE,
14078 &neighbor_maximum_prefix_threshold_restart_cmd);
14079 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
14080 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
14081 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
14082 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
14083 install_element(BGP_IPV6M_NODE,
14084 &neighbor_maximum_prefix_threshold_warning_cmd);
14085 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
14086 install_element(BGP_IPV6M_NODE,
14087 &neighbor_maximum_prefix_threshold_restart_cmd);
14088 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
14089 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
14090 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
14091 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
14092 install_element(BGP_IPV6L_NODE,
14093 &neighbor_maximum_prefix_threshold_warning_cmd);
14094 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
14095 install_element(BGP_IPV6L_NODE,
14096 &neighbor_maximum_prefix_threshold_restart_cmd);
14097 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
14098 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
14099 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
14100 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
14101 install_element(BGP_VPNV4_NODE,
14102 &neighbor_maximum_prefix_threshold_warning_cmd);
14103 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
14104 install_element(BGP_VPNV4_NODE,
14105 &neighbor_maximum_prefix_threshold_restart_cmd);
14106 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
14107 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
14108 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
14109 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
14110 install_element(BGP_VPNV6_NODE,
14111 &neighbor_maximum_prefix_threshold_warning_cmd);
14112 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
14113 install_element(BGP_VPNV6_NODE,
14114 &neighbor_maximum_prefix_threshold_restart_cmd);
14115 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
14116
14117 /* "neighbor allowas-in" */
14118 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
14119 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
14120 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
14121 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
14122 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
14123 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
14124 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
14125 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
14126 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
14127 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
14128 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
14129 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
14130 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
14131 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
14132 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
14133 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
14134 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
14135 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
14136 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
14137 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
14138
14139 /* address-family commands. */
14140 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
14141 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 14142#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 14143 install_element(BGP_NODE, &address_family_vpnv4_cmd);
14144 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 14145#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 14146
d62a17ae 14147 install_element(BGP_NODE, &address_family_evpn_cmd);
14148
14149 /* "exit-address-family" command. */
14150 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
14151 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
14152 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
14153 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
14154 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
14155 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
14156 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
14157 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 14158 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
14159 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 14160 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
14161
14162 /* "clear ip bgp commands" */
14163 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
14164
14165 /* clear ip bgp prefix */
14166 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
14167 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
14168 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
14169
14170 /* "show [ip] bgp summary" commands. */
14171 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 14172 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 14173 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 14174 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 14175 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
14176 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 14177 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
14178
14179 /* "show [ip] bgp neighbors" commands. */
14180 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
14181
14182 /* "show [ip] bgp peer-group" commands. */
14183 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
14184
14185 /* "show [ip] bgp paths" commands. */
14186 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
14187
14188 /* "show [ip] bgp community" commands. */
14189 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
14190
14191 /* "show ip bgp large-community" commands. */
14192 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
14193 /* "show [ip] bgp attribute-info" commands. */
14194 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 14195 /* "show [ip] bgp route-leak" command */
14196 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 14197
14198 /* "redistribute" commands. */
14199 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
14200 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
14201 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
14202 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
14203 install_element(BGP_NODE,
14204 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
14205 install_element(BGP_NODE,
14206 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
14207 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
14208 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
14209 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
14210 install_element(BGP_NODE,
14211 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
14212 install_element(BGP_NODE,
14213 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
14214 install_element(BGP_NODE,
14215 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
14216 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
14217 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
14218 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
14219 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
14220 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
14221 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
14222 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
14223 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
14224 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
14225 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
14226 install_element(BGP_IPV4_NODE,
14227 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
14228 install_element(BGP_IPV4_NODE,
14229 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
14230 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
14231 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
14232 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
14233 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
14234 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
14235 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
14236
b9c7bc5a
PZ
14237 /* import|export vpn [route-map WORD] */
14238 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14239 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 14240
12a844a5
DS
14241 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14242 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14243
d62a17ae 14244 /* ttl_security commands */
14245 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14246 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14247
14248 /* "show [ip] bgp memory" commands. */
14249 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14250
acf71666
MK
14251 /* "show bgp martian next-hop" */
14252 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14253
48ecf8f5
DS
14254 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14255
d62a17ae 14256 /* "show [ip] bgp views" commands. */
14257 install_element(VIEW_NODE, &show_bgp_views_cmd);
14258
14259 /* "show [ip] bgp vrfs" commands. */
14260 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14261
14262 /* Community-list. */
14263 community_list_vty();
ddb5b488
PZ
14264
14265 /* vpn-policy commands */
b9c7bc5a
PZ
14266 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14267 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14268 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14269 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14270 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14271 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14272 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14273 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14274 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14275 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
14276 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14277 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 14278
301ad80a
PG
14279 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14280 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14281
b9c7bc5a
PZ
14282 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14283 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14284 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14285 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14286 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14287 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14288 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14289 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14290 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14291 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
14292 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14293 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 14294}
6b0655a2 14295
718e3744 14296#include "memory.h"
14297#include "bgp_regex.h"
14298#include "bgp_clist.h"
14299#include "bgp_ecommunity.h"
14300
14301/* VTY functions. */
14302
14303/* Direction value to string conversion. */
d62a17ae 14304static const char *community_direct_str(int direct)
14305{
14306 switch (direct) {
14307 case COMMUNITY_DENY:
14308 return "deny";
14309 case COMMUNITY_PERMIT:
14310 return "permit";
14311 default:
14312 return "unknown";
14313 }
718e3744 14314}
14315
14316/* Display error string. */
d62a17ae 14317static void community_list_perror(struct vty *vty, int ret)
14318{
14319 switch (ret) {
14320 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14321 vty_out(vty, "%% Can't find community-list\n");
14322 break;
14323 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14324 vty_out(vty, "%% Malformed community-list value\n");
14325 break;
14326 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14327 vty_out(vty,
14328 "%% Community name conflict, previously defined as standard community\n");
14329 break;
14330 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14331 vty_out(vty,
14332 "%% Community name conflict, previously defined as expanded community\n");
14333 break;
14334 }
718e3744 14335}
14336
5bf15956
DW
14337/* "community-list" keyword help string. */
14338#define COMMUNITY_LIST_STR "Add a community list entry\n"
14339
7336e101
SP
14340/*community-list standard */
14341DEFUN (community_list_standard,
14342 bgp_community_list_standard_cmd,
14343 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14344 BGP_STR
718e3744 14345 COMMUNITY_LIST_STR
14346 "Community list number (standard)\n"
5bf15956 14347 "Add an standard community-list entry\n"
718e3744 14348 "Community list name\n"
14349 "Specify community to reject\n"
14350 "Specify community to accept\n"
14351 COMMUNITY_VAL_STR)
14352{
d62a17ae 14353 char *cl_name_or_number = NULL;
14354 int direct = 0;
14355 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 14356 int idx = 0;
7336e101 14357
d62a17ae 14358 argv_find(argv, argc, "(1-99)", &idx);
14359 argv_find(argv, argc, "WORD", &idx);
14360 cl_name_or_number = argv[idx]->arg;
14361 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14362 : COMMUNITY_DENY;
14363 argv_find(argv, argc, "AA:NN", &idx);
14364 char *str = argv_concat(argv, argc, idx);
42f914d4 14365
d62a17ae 14366 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14367 style);
42f914d4 14368
d62a17ae 14369 XFREE(MTYPE_TMP, str);
42f914d4 14370
d62a17ae 14371 if (ret < 0) {
14372 /* Display error string. */
14373 community_list_perror(vty, ret);
14374 return CMD_WARNING_CONFIG_FAILED;
14375 }
42f914d4 14376
d62a17ae 14377 return CMD_SUCCESS;
718e3744 14378}
14379
7336e101
SP
14380DEFUN (no_community_list_standard_all,
14381 no_bgp_community_list_standard_all_cmd,
14382 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14383 NO_STR
14384 BGP_STR
14385 COMMUNITY_LIST_STR
14386 "Community list number (standard)\n"
14387 "Add an standard community-list entry\n"
14388 "Community list name\n"
14389 "Specify community to reject\n"
14390 "Specify community to accept\n"
14391 COMMUNITY_VAL_STR)
718e3744 14392{
d62a17ae 14393 char *cl_name_or_number = NULL;
174b5cb9 14394 char *str = NULL;
d62a17ae 14395 int direct = 0;
14396 int style = COMMUNITY_LIST_STANDARD;
42f914d4 14397
d62a17ae 14398 int idx = 0;
7336e101 14399
174b5cb9
DA
14400 argv_find(argv, argc, "permit", &idx);
14401 argv_find(argv, argc, "deny", &idx);
14402
14403 if (idx) {
14404 direct = argv_find(argv, argc, "permit", &idx)
14405 ? COMMUNITY_PERMIT
14406 : COMMUNITY_DENY;
14407
14408 idx = 0;
14409 argv_find(argv, argc, "AA:NN", &idx);
14410 str = argv_concat(argv, argc, idx);
14411 }
14412
14413 idx = 0;
d62a17ae 14414 argv_find(argv, argc, "(1-99)", &idx);
14415 argv_find(argv, argc, "WORD", &idx);
14416 cl_name_or_number = argv[idx]->arg;
42f914d4 14417
d62a17ae 14418 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14419 direct, style);
42f914d4 14420
d62a17ae 14421 XFREE(MTYPE_TMP, str);
daf9ddbb 14422
d62a17ae 14423 if (ret < 0) {
14424 community_list_perror(vty, ret);
14425 return CMD_WARNING_CONFIG_FAILED;
14426 }
42f914d4 14427
d62a17ae 14428 return CMD_SUCCESS;
718e3744 14429}
7336e101 14430
174b5cb9
DA
14431ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14432 "no bgp community-list <(1-99)|standard WORD>",
14433 NO_STR BGP_STR COMMUNITY_LIST_STR
14434 "Community list number (standard)\n"
14435 "Add an standard community-list entry\n"
14436 "Community list name\n")
14437
7336e101
SP
14438/*community-list expanded */
14439DEFUN (community_list_expanded_all,
14440 bgp_community_list_expanded_all_cmd,
14441 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14442 BGP_STR
14443 COMMUNITY_LIST_STR
718e3744 14444 "Community list number (expanded)\n"
5bf15956 14445 "Add an expanded community-list entry\n"
718e3744 14446 "Community list name\n"
14447 "Specify community to reject\n"
14448 "Specify community to accept\n"
14449 COMMUNITY_VAL_STR)
14450{
d62a17ae 14451 char *cl_name_or_number = NULL;
14452 int direct = 0;
14453 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14454
d62a17ae 14455 int idx = 0;
7b9a4750 14456
d62a17ae 14457 argv_find(argv, argc, "(100-500)", &idx);
14458 argv_find(argv, argc, "WORD", &idx);
14459 cl_name_or_number = argv[idx]->arg;
14460 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14461 : COMMUNITY_DENY;
14462 argv_find(argv, argc, "AA:NN", &idx);
14463 char *str = argv_concat(argv, argc, idx);
42f914d4 14464
d62a17ae 14465 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14466 style);
42f914d4 14467
d62a17ae 14468 XFREE(MTYPE_TMP, str);
42f914d4 14469
d62a17ae 14470 if (ret < 0) {
14471 /* Display error string. */
14472 community_list_perror(vty, ret);
14473 return CMD_WARNING_CONFIG_FAILED;
14474 }
42f914d4 14475
d62a17ae 14476 return CMD_SUCCESS;
718e3744 14477}
14478
7336e101
SP
14479DEFUN (no_community_list_expanded_all,
14480 no_bgp_community_list_expanded_all_cmd,
14481 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14482 NO_STR
14483 BGP_STR
14484 COMMUNITY_LIST_STR
14485 "Community list number (expanded)\n"
14486 "Add an expanded community-list entry\n"
14487 "Community list name\n"
14488 "Specify community to reject\n"
14489 "Specify community to accept\n"
14490 COMMUNITY_VAL_STR)
718e3744 14491{
d62a17ae 14492 char *cl_name_or_number = NULL;
174b5cb9 14493 char *str = NULL;
d62a17ae 14494 int direct = 0;
14495 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14496
d62a17ae 14497 int idx = 0;
174b5cb9
DA
14498
14499 argv_find(argv, argc, "permit", &idx);
14500 argv_find(argv, argc, "deny", &idx);
14501
14502 if (idx) {
14503 direct = argv_find(argv, argc, "permit", &idx)
14504 ? COMMUNITY_PERMIT
14505 : COMMUNITY_DENY;
14506
14507 idx = 0;
14508 argv_find(argv, argc, "AA:NN", &idx);
14509 str = argv_concat(argv, argc, idx);
7336e101 14510 }
174b5cb9
DA
14511
14512 idx = 0;
d62a17ae 14513 argv_find(argv, argc, "(100-500)", &idx);
14514 argv_find(argv, argc, "WORD", &idx);
14515 cl_name_or_number = argv[idx]->arg;
42f914d4 14516
d62a17ae 14517 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14518 direct, style);
42f914d4 14519
d62a17ae 14520 XFREE(MTYPE_TMP, str);
daf9ddbb 14521
d62a17ae 14522 if (ret < 0) {
14523 community_list_perror(vty, ret);
14524 return CMD_WARNING_CONFIG_FAILED;
14525 }
42f914d4 14526
d62a17ae 14527 return CMD_SUCCESS;
718e3744 14528}
14529
174b5cb9
DA
14530ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14531 "no bgp community-list <(100-500)|expanded WORD>",
14532 NO_STR IP_STR COMMUNITY_LIST_STR
14533 "Community list number (expanded)\n"
14534 "Add an expanded community-list entry\n"
14535 "Community list name\n")
14536
8d9b8ed9
PM
14537/* Return configuration string of community-list entry. */
14538static const char *community_list_config_str(struct community_entry *entry)
14539{
14540 const char *str;
14541
14542 if (entry->any)
14543 str = "";
14544 else {
14545 if (entry->style == COMMUNITY_LIST_STANDARD)
14546 str = community_str(entry->u.com, false);
14547 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14548 str = lcommunity_str(entry->u.lcom, false);
14549 else
14550 str = entry->config;
14551 }
14552 return str;
14553}
14554
d62a17ae 14555static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 14556{
d62a17ae 14557 struct community_entry *entry;
718e3744 14558
d62a17ae 14559 for (entry = list->head; entry; entry = entry->next) {
14560 if (entry == list->head) {
14561 if (all_digit(list->name))
14562 vty_out(vty, "Community %s list %s\n",
14563 entry->style == COMMUNITY_LIST_STANDARD
14564 ? "standard"
14565 : "(expanded) access",
14566 list->name);
14567 else
14568 vty_out(vty, "Named Community %s list %s\n",
14569 entry->style == COMMUNITY_LIST_STANDARD
14570 ? "standard"
14571 : "expanded",
14572 list->name);
14573 }
14574 if (entry->any)
14575 vty_out(vty, " %s\n",
14576 community_direct_str(entry->direct));
14577 else
14578 vty_out(vty, " %s %s\n",
14579 community_direct_str(entry->direct),
8d9b8ed9 14580 community_list_config_str(entry));
d62a17ae 14581 }
718e3744 14582}
14583
7336e101
SP
14584DEFUN (show_community_list,
14585 show_bgp_community_list_cmd,
14586 "show bgp community-list",
718e3744 14587 SHOW_STR
7336e101 14588 BGP_STR
718e3744 14589 "List community-list\n")
14590{
d62a17ae 14591 struct community_list *list;
14592 struct community_list_master *cm;
718e3744 14593
d62a17ae 14594 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14595 if (!cm)
14596 return CMD_SUCCESS;
718e3744 14597
d62a17ae 14598 for (list = cm->num.head; list; list = list->next)
14599 community_list_show(vty, list);
718e3744 14600
d62a17ae 14601 for (list = cm->str.head; list; list = list->next)
14602 community_list_show(vty, list);
718e3744 14603
d62a17ae 14604 return CMD_SUCCESS;
718e3744 14605}
14606
7336e101
SP
14607DEFUN (show_community_list_arg,
14608 show_bgp_community_list_arg_cmd,
960b69b9 14609 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
14610 SHOW_STR
14611 BGP_STR
718e3744 14612 "List community-list\n"
14613 "Community-list number\n"
960b69b9 14614 "Community-list name\n"
14615 "Detailed information on community-list\n")
718e3744 14616{
d62a17ae 14617 int idx_comm_list = 3;
14618 struct community_list *list;
718e3744 14619
e237b0d2 14620 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 14621 COMMUNITY_LIST_MASTER);
14622 if (!list) {
14623 vty_out(vty, "%% Can't find community-list\n");
14624 return CMD_WARNING;
14625 }
718e3744 14626
d62a17ae 14627 community_list_show(vty, list);
718e3744 14628
d62a17ae 14629 return CMD_SUCCESS;
718e3744 14630}
6b0655a2 14631
57d187bc
JS
14632/*
14633 * Large Community code.
14634 */
d62a17ae 14635static int lcommunity_list_set_vty(struct vty *vty, int argc,
14636 struct cmd_token **argv, int style,
14637 int reject_all_digit_name)
14638{
14639 int ret;
14640 int direct;
14641 char *str;
14642 int idx = 0;
14643 char *cl_name;
14644
14645 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14646 : COMMUNITY_DENY;
14647
14648 /* All digit name check. */
14649 idx = 0;
14650 argv_find(argv, argc, "WORD", &idx);
14651 argv_find(argv, argc, "(1-99)", &idx);
14652 argv_find(argv, argc, "(100-500)", &idx);
14653 cl_name = argv[idx]->arg;
14654 if (reject_all_digit_name && all_digit(cl_name)) {
14655 vty_out(vty, "%% Community name cannot have all digits\n");
14656 return CMD_WARNING_CONFIG_FAILED;
14657 }
14658
14659 idx = 0;
14660 argv_find(argv, argc, "AA:BB:CC", &idx);
14661 argv_find(argv, argc, "LINE", &idx);
14662 /* Concat community string argument. */
14663 if (idx)
14664 str = argv_concat(argv, argc, idx);
14665 else
14666 str = NULL;
14667
14668 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14669
14670 /* Free temporary community list string allocated by
14671 argv_concat(). */
0a22ddfb 14672 XFREE(MTYPE_TMP, str);
d62a17ae 14673
14674 if (ret < 0) {
14675 community_list_perror(vty, ret);
14676 return CMD_WARNING_CONFIG_FAILED;
14677 }
14678 return CMD_SUCCESS;
14679}
14680
14681static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14682 struct cmd_token **argv, int style)
14683{
14684 int ret;
14685 int direct = 0;
14686 char *str = NULL;
14687 int idx = 0;
14688
14689 argv_find(argv, argc, "permit", &idx);
14690 argv_find(argv, argc, "deny", &idx);
14691
14692 if (idx) {
14693 /* Check the list direct. */
14694 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14695 direct = COMMUNITY_PERMIT;
14696 else
14697 direct = COMMUNITY_DENY;
14698
14699 idx = 0;
14700 argv_find(argv, argc, "LINE", &idx);
14701 argv_find(argv, argc, "AA:AA:NN", &idx);
14702 /* Concat community string argument. */
14703 str = argv_concat(argv, argc, idx);
14704 }
14705
14706 idx = 0;
14707 argv_find(argv, argc, "(1-99)", &idx);
14708 argv_find(argv, argc, "(100-500)", &idx);
14709 argv_find(argv, argc, "WORD", &idx);
14710
14711 /* Unset community list. */
14712 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14713 style);
14714
14715 /* Free temporary community list string allocated by
14716 argv_concat(). */
0a22ddfb 14717 XFREE(MTYPE_TMP, str);
d62a17ae 14718
14719 if (ret < 0) {
14720 community_list_perror(vty, ret);
14721 return CMD_WARNING_CONFIG_FAILED;
14722 }
14723
14724 return CMD_SUCCESS;
57d187bc
JS
14725}
14726
14727/* "large-community-list" keyword help string. */
14728#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14729#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14730
7336e101
SP
14731DEFUN (lcommunity_list_standard,
14732 bgp_lcommunity_list_standard_cmd,
7336e101
SP
14733 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14734 BGP_STR
14735 LCOMMUNITY_LIST_STR
14736 "Large Community list number (standard)\n"
14737 "Specify large community to reject\n"
14738 "Specify large community to accept\n"
14739 LCOMMUNITY_VAL_STR)
52951b63 14740{
d62a17ae 14741 return lcommunity_list_set_vty(vty, argc, argv,
14742 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
14743}
14744
7336e101
SP
14745DEFUN (lcommunity_list_expanded,
14746 bgp_lcommunity_list_expanded_cmd,
14747 "bgp large-community-list (100-500) <deny|permit> LINE...",
14748 BGP_STR
14749 LCOMMUNITY_LIST_STR
14750 "Large Community list number (expanded)\n"
14751 "Specify large community to reject\n"
14752 "Specify large community to accept\n"
14753 "An ordered list as a regular-expression\n")
57d187bc 14754{
d62a17ae 14755 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14756 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
14757}
14758
7336e101
SP
14759DEFUN (lcommunity_list_name_standard,
14760 bgp_lcommunity_list_name_standard_cmd,
7336e101
SP
14761 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14762 BGP_STR
14763 LCOMMUNITY_LIST_STR
14764 "Specify standard large-community-list\n"
14765 "Large Community list name\n"
14766 "Specify large community to reject\n"
14767 "Specify large community to accept\n"
14768 LCOMMUNITY_VAL_STR)
52951b63 14769{
d62a17ae 14770 return lcommunity_list_set_vty(vty, argc, argv,
14771 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
14772}
14773
7336e101
SP
14774DEFUN (lcommunity_list_name_expanded,
14775 bgp_lcommunity_list_name_expanded_cmd,
14776 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14777 BGP_STR
14778 LCOMMUNITY_LIST_STR
14779 "Specify expanded large-community-list\n"
14780 "Large Community list name\n"
14781 "Specify large community to reject\n"
14782 "Specify large community to accept\n"
14783 "An ordered list as a regular-expression\n")
57d187bc 14784{
d62a17ae 14785 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14786 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
14787}
14788
7336e101
SP
14789DEFUN (no_lcommunity_list_standard_all,
14790 no_bgp_lcommunity_list_standard_all_cmd,
14791 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14792 NO_STR
14793 BGP_STR
14794 LCOMMUNITY_LIST_STR
14795 "Large Community list number (standard)\n"
14796 "Large Community list number (expanded)\n"
14797 "Large Community list name\n")
57d187bc 14798{
7336e101
SP
14799 return lcommunity_list_unset_vty(vty, argc, argv,
14800 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14801}
14802
7336e101
SP
14803DEFUN (no_lcommunity_list_name_expanded_all,
14804 no_bgp_lcommunity_list_name_expanded_all_cmd,
14805 "no bgp large-community-list expanded WORD",
14806 NO_STR
14807 BGP_STR
14808 LCOMMUNITY_LIST_STR
14809 "Specify expanded large-community-list\n"
14810 "Large Community list name\n")
57d187bc 14811{
d62a17ae 14812 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14813 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14814}
14815
7336e101
SP
14816DEFUN (no_lcommunity_list_standard,
14817 no_bgp_lcommunity_list_standard_cmd,
14818 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14819 NO_STR
14820 BGP_STR
14821 LCOMMUNITY_LIST_STR
14822 "Large Community list number (standard)\n"
14823 "Specify large community to reject\n"
14824 "Specify large community to accept\n"
14825 LCOMMUNITY_VAL_STR)
57d187bc 14826{
d62a17ae 14827 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14828 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14829}
14830
7336e101
SP
14831DEFUN (no_lcommunity_list_expanded,
14832 no_bgp_lcommunity_list_expanded_cmd,
14833 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14834 NO_STR
14835 BGP_STR
14836 LCOMMUNITY_LIST_STR
14837 "Large Community list number (expanded)\n"
14838 "Specify large community to reject\n"
14839 "Specify large community to accept\n"
14840 "An ordered list as a regular-expression\n")
57d187bc 14841{
d62a17ae 14842 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14843 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14844}
14845
7336e101
SP
14846DEFUN (no_lcommunity_list_name_standard,
14847 no_bgp_lcommunity_list_name_standard_cmd,
14848 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14849 NO_STR
14850 BGP_STR
14851 LCOMMUNITY_LIST_STR
14852 "Specify standard large-community-list\n"
14853 "Large Community list name\n"
14854 "Specify large community to reject\n"
14855 "Specify large community to accept\n"
14856 LCOMMUNITY_VAL_STR)
57d187bc 14857{
d62a17ae 14858 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14859 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14860}
14861
7336e101
SP
14862DEFUN (no_lcommunity_list_name_expanded,
14863 no_bgp_lcommunity_list_name_expanded_cmd,
14864 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14865 NO_STR
14866 BGP_STR
14867 LCOMMUNITY_LIST_STR
14868 "Specify expanded large-community-list\n"
14869 "Large community list name\n"
14870 "Specify large community to reject\n"
14871 "Specify large community to accept\n"
14872 "An ordered list as a regular-expression\n")
57d187bc 14873{
d62a17ae 14874 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14875 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14876}
14877
d62a17ae 14878static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14879{
14880 struct community_entry *entry;
14881
14882 for (entry = list->head; entry; entry = entry->next) {
14883 if (entry == list->head) {
14884 if (all_digit(list->name))
14885 vty_out(vty, "Large community %s list %s\n",
169b72c8 14886 entry->style ==
14887 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 14888 ? "standard"
14889 : "(expanded) access",
14890 list->name);
14891 else
14892 vty_out(vty,
14893 "Named large community %s list %s\n",
169b72c8 14894 entry->style ==
14895 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 14896 ? "standard"
14897 : "expanded",
14898 list->name);
14899 }
14900 if (entry->any)
14901 vty_out(vty, " %s\n",
14902 community_direct_str(entry->direct));
14903 else
14904 vty_out(vty, " %s %s\n",
14905 community_direct_str(entry->direct),
8d9b8ed9 14906 community_list_config_str(entry));
d62a17ae 14907 }
57d187bc
JS
14908}
14909
7336e101
SP
14910DEFUN (show_lcommunity_list,
14911 show_bgp_lcommunity_list_cmd,
14912 "show bgp large-community-list",
57d187bc 14913 SHOW_STR
7336e101 14914 BGP_STR
57d187bc
JS
14915 "List large-community list\n")
14916{
d62a17ae 14917 struct community_list *list;
14918 struct community_list_master *cm;
57d187bc 14919
d62a17ae 14920 cm = community_list_master_lookup(bgp_clist,
14921 LARGE_COMMUNITY_LIST_MASTER);
14922 if (!cm)
14923 return CMD_SUCCESS;
57d187bc 14924
d62a17ae 14925 for (list = cm->num.head; list; list = list->next)
14926 lcommunity_list_show(vty, list);
57d187bc 14927
d62a17ae 14928 for (list = cm->str.head; list; list = list->next)
14929 lcommunity_list_show(vty, list);
57d187bc 14930
d62a17ae 14931 return CMD_SUCCESS;
57d187bc
JS
14932}
14933
7336e101
SP
14934DEFUN (show_lcommunity_list_arg,
14935 show_bgp_lcommunity_list_arg_cmd,
960b69b9 14936 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
14937 SHOW_STR
14938 BGP_STR
57d187bc 14939 "List large-community list\n"
960b69b9 14940 "Large-community-list number\n"
14941 "Large-community-list name\n"
14942 "Detailed information on large-community-list\n")
57d187bc 14943{
d62a17ae 14944 struct community_list *list;
57d187bc 14945
e237b0d2 14946 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 14947 LARGE_COMMUNITY_LIST_MASTER);
14948 if (!list) {
960b69b9 14949 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 14950 return CMD_WARNING;
14951 }
57d187bc 14952
d62a17ae 14953 lcommunity_list_show(vty, list);
57d187bc 14954
d62a17ae 14955 return CMD_SUCCESS;
57d187bc
JS
14956}
14957
718e3744 14958/* "extcommunity-list" keyword help string. */
14959#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14960#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14961
7336e101
SP
14962DEFUN (extcommunity_list_standard,
14963 bgp_extcommunity_list_standard_cmd,
14964 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14965 BGP_STR
718e3744 14966 EXTCOMMUNITY_LIST_STR
14967 "Extended Community list number (standard)\n"
718e3744 14968 "Specify standard extcommunity-list\n"
5bf15956 14969 "Community list name\n"
718e3744 14970 "Specify community to reject\n"
14971 "Specify community to accept\n"
14972 EXTCOMMUNITY_VAL_STR)
14973{
d62a17ae 14974 int style = EXTCOMMUNITY_LIST_STANDARD;
14975 int direct = 0;
14976 char *cl_number_or_name = NULL;
42f914d4 14977
d62a17ae 14978 int idx = 0;
7b9a4750 14979
d62a17ae 14980 argv_find(argv, argc, "(1-99)", &idx);
14981 argv_find(argv, argc, "WORD", &idx);
14982 cl_number_or_name = argv[idx]->arg;
14983 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14984 : COMMUNITY_DENY;
14985 argv_find(argv, argc, "AA:NN", &idx);
14986 char *str = argv_concat(argv, argc, idx);
42f914d4 14987
d62a17ae 14988 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14989 direct, style);
42f914d4 14990
d62a17ae 14991 XFREE(MTYPE_TMP, str);
42f914d4 14992
d62a17ae 14993 if (ret < 0) {
14994 community_list_perror(vty, ret);
14995 return CMD_WARNING_CONFIG_FAILED;
14996 }
42f914d4 14997
d62a17ae 14998 return CMD_SUCCESS;
718e3744 14999}
15000
7336e101
SP
15001DEFUN (extcommunity_list_name_expanded,
15002 bgp_extcommunity_list_name_expanded_cmd,
15003 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15004 BGP_STR
15005 EXTCOMMUNITY_LIST_STR
5bf15956 15006 "Extended Community list number (expanded)\n"
718e3744 15007 "Specify expanded extcommunity-list\n"
15008 "Extended Community list name\n"
15009 "Specify community to reject\n"
15010 "Specify community to accept\n"
15011 "An ordered list as a regular-expression\n")
15012{
d62a17ae 15013 int style = EXTCOMMUNITY_LIST_EXPANDED;
15014 int direct = 0;
15015 char *cl_number_or_name = NULL;
d62a17ae 15016 int idx = 0;
7336e101 15017
d62a17ae 15018 argv_find(argv, argc, "(100-500)", &idx);
15019 argv_find(argv, argc, "WORD", &idx);
15020 cl_number_or_name = argv[idx]->arg;
15021 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15022 : COMMUNITY_DENY;
15023 argv_find(argv, argc, "LINE", &idx);
15024 char *str = argv_concat(argv, argc, idx);
42f914d4 15025
d62a17ae 15026 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15027 direct, style);
42f914d4 15028
d62a17ae 15029 XFREE(MTYPE_TMP, str);
42f914d4 15030
d62a17ae 15031 if (ret < 0) {
15032 community_list_perror(vty, ret);
15033 return CMD_WARNING_CONFIG_FAILED;
15034 }
42f914d4 15035
d62a17ae 15036 return CMD_SUCCESS;
718e3744 15037}
15038
7336e101
SP
15039DEFUN (no_extcommunity_list_standard_all,
15040 no_bgp_extcommunity_list_standard_all_cmd,
15041 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15042 NO_STR
15043 BGP_STR
15044 EXTCOMMUNITY_LIST_STR
813d4307 15045 "Extended Community list number (standard)\n"
718e3744 15046 "Specify standard extcommunity-list\n"
5bf15956 15047 "Community list name\n"
718e3744 15048 "Specify community to reject\n"
15049 "Specify community to accept\n"
15050 EXTCOMMUNITY_VAL_STR)
15051{
d62a17ae 15052 int style = EXTCOMMUNITY_LIST_STANDARD;
15053 int direct = 0;
15054 char *cl_number_or_name = NULL;
d4455c89 15055 char *str = NULL;
d62a17ae 15056 int idx = 0;
d4455c89 15057
d4455c89
DA
15058 argv_find(argv, argc, "permit", &idx);
15059 argv_find(argv, argc, "deny", &idx);
15060
15061 if (idx) {
15062 direct = argv_find(argv, argc, "permit", &idx)
15063 ? COMMUNITY_PERMIT
15064 : COMMUNITY_DENY;
15065
15066 idx = 0;
15067 argv_find(argv, argc, "AA:NN", &idx);
15068 str = argv_concat(argv, argc, idx);
15069 }
15070
15071 idx = 0;
d62a17ae 15072 argv_find(argv, argc, "(1-99)", &idx);
15073 argv_find(argv, argc, "WORD", &idx);
15074 cl_number_or_name = argv[idx]->arg;
42f914d4 15075
d62a17ae 15076 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15077 direct, style);
42f914d4 15078
d62a17ae 15079 XFREE(MTYPE_TMP, str);
42f914d4 15080
d62a17ae 15081 if (ret < 0) {
15082 community_list_perror(vty, ret);
15083 return CMD_WARNING_CONFIG_FAILED;
15084 }
42f914d4 15085
d62a17ae 15086 return CMD_SUCCESS;
718e3744 15087}
15088
d4455c89
DA
15089ALIAS(no_extcommunity_list_standard_all,
15090 no_bgp_extcommunity_list_standard_all_list_cmd,
15091 "no bgp extcommunity-list <(1-99)|standard WORD>",
15092 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15093 "Extended Community list number (standard)\n"
15094 "Specify standard extcommunity-list\n"
15095 "Community list name\n")
15096
7336e101
SP
15097DEFUN (no_extcommunity_list_expanded_all,
15098 no_bgp_extcommunity_list_expanded_all_cmd,
15099 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15100 NO_STR
15101 BGP_STR
15102 EXTCOMMUNITY_LIST_STR
718e3744 15103 "Extended Community list number (expanded)\n"
718e3744 15104 "Specify expanded extcommunity-list\n"
5bf15956 15105 "Extended Community list name\n"
718e3744 15106 "Specify community to reject\n"
15107 "Specify community to accept\n"
15108 "An ordered list as a regular-expression\n")
15109{
d62a17ae 15110 int style = EXTCOMMUNITY_LIST_EXPANDED;
15111 int direct = 0;
15112 char *cl_number_or_name = NULL;
d4455c89 15113 char *str = NULL;
d62a17ae 15114 int idx = 0;
d4455c89 15115
d4455c89
DA
15116 argv_find(argv, argc, "permit", &idx);
15117 argv_find(argv, argc, "deny", &idx);
15118
15119 if (idx) {
15120 direct = argv_find(argv, argc, "permit", &idx)
15121 ? COMMUNITY_PERMIT
15122 : COMMUNITY_DENY;
15123
15124 idx = 0;
15125 argv_find(argv, argc, "LINE", &idx);
15126 str = argv_concat(argv, argc, idx);
15127 }
15128
15129 idx = 0;
d62a17ae 15130 argv_find(argv, argc, "(100-500)", &idx);
15131 argv_find(argv, argc, "WORD", &idx);
15132 cl_number_or_name = argv[idx]->arg;
42f914d4 15133
d62a17ae 15134 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15135 direct, style);
42f914d4 15136
d62a17ae 15137 XFREE(MTYPE_TMP, str);
42f914d4 15138
d62a17ae 15139 if (ret < 0) {
15140 community_list_perror(vty, ret);
15141 return CMD_WARNING_CONFIG_FAILED;
15142 }
42f914d4 15143
d62a17ae 15144 return CMD_SUCCESS;
718e3744 15145}
15146
d4455c89
DA
15147ALIAS(no_extcommunity_list_expanded_all,
15148 no_bgp_extcommunity_list_expanded_all_list_cmd,
15149 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15150 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15151 "Extended Community list number (expanded)\n"
15152 "Specify expanded extcommunity-list\n"
15153 "Extended Community list name\n")
15154
d62a17ae 15155static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 15156{
d62a17ae 15157 struct community_entry *entry;
718e3744 15158
d62a17ae 15159 for (entry = list->head; entry; entry = entry->next) {
15160 if (entry == list->head) {
15161 if (all_digit(list->name))
15162 vty_out(vty, "Extended community %s list %s\n",
15163 entry->style == EXTCOMMUNITY_LIST_STANDARD
15164 ? "standard"
15165 : "(expanded) access",
15166 list->name);
15167 else
15168 vty_out(vty,
15169 "Named extended community %s list %s\n",
15170 entry->style == EXTCOMMUNITY_LIST_STANDARD
15171 ? "standard"
15172 : "expanded",
15173 list->name);
15174 }
15175 if (entry->any)
15176 vty_out(vty, " %s\n",
15177 community_direct_str(entry->direct));
15178 else
15179 vty_out(vty, " %s %s\n",
15180 community_direct_str(entry->direct),
8d9b8ed9 15181 community_list_config_str(entry));
d62a17ae 15182 }
718e3744 15183}
15184
7336e101
SP
15185DEFUN (show_extcommunity_list,
15186 show_bgp_extcommunity_list_cmd,
15187 "show bgp extcommunity-list",
718e3744 15188 SHOW_STR
7336e101 15189 BGP_STR
718e3744 15190 "List extended-community list\n")
15191{
d62a17ae 15192 struct community_list *list;
15193 struct community_list_master *cm;
718e3744 15194
d62a17ae 15195 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15196 if (!cm)
15197 return CMD_SUCCESS;
718e3744 15198
d62a17ae 15199 for (list = cm->num.head; list; list = list->next)
15200 extcommunity_list_show(vty, list);
718e3744 15201
d62a17ae 15202 for (list = cm->str.head; list; list = list->next)
15203 extcommunity_list_show(vty, list);
718e3744 15204
d62a17ae 15205 return CMD_SUCCESS;
718e3744 15206}
15207
7336e101
SP
15208DEFUN (show_extcommunity_list_arg,
15209 show_bgp_extcommunity_list_arg_cmd,
960b69b9 15210 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
15211 SHOW_STR
15212 BGP_STR
718e3744 15213 "List extended-community list\n"
15214 "Extcommunity-list number\n"
960b69b9 15215 "Extcommunity-list name\n"
15216 "Detailed information on extcommunity-list\n")
718e3744 15217{
d62a17ae 15218 int idx_comm_list = 3;
15219 struct community_list *list;
718e3744 15220
e237b0d2 15221 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 15222 EXTCOMMUNITY_LIST_MASTER);
15223 if (!list) {
15224 vty_out(vty, "%% Can't find extcommunity-list\n");
15225 return CMD_WARNING;
15226 }
718e3744 15227
d62a17ae 15228 extcommunity_list_show(vty, list);
718e3744 15229
d62a17ae 15230 return CMD_SUCCESS;
718e3744 15231}
6b0655a2 15232
718e3744 15233/* Display community-list and extcommunity-list configuration. */
d62a17ae 15234static int community_list_config_write(struct vty *vty)
15235{
15236 struct community_list *list;
15237 struct community_entry *entry;
15238 struct community_list_master *cm;
15239 int write = 0;
15240
15241 /* Community-list. */
15242 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15243
15244 for (list = cm->num.head; list; list = list->next)
15245 for (entry = list->head; entry; entry = entry->next) {
7336e101 15246 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
d62a17ae 15247 community_direct_str(entry->direct),
15248 community_list_config_str(entry));
15249 write++;
15250 }
15251 for (list = cm->str.head; list; list = list->next)
15252 for (entry = list->head; entry; entry = entry->next) {
7336e101 15253 vty_out(vty, "bgp community-list %s %s %s %s\n",
d62a17ae 15254 entry->style == COMMUNITY_LIST_STANDARD
15255 ? "standard"
15256 : "expanded",
15257 list->name, community_direct_str(entry->direct),
15258 community_list_config_str(entry));
15259 write++;
15260 }
15261
15262 /* Extcommunity-list. */
15263 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15264
15265 for (list = cm->num.head; list; list = list->next)
15266 for (entry = list->head; entry; entry = entry->next) {
7336e101 15267 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
d62a17ae 15268 list->name, community_direct_str(entry->direct),
15269 community_list_config_str(entry));
15270 write++;
15271 }
15272 for (list = cm->str.head; list; list = list->next)
15273 for (entry = list->head; entry; entry = entry->next) {
7336e101 15274 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
d62a17ae 15275 entry->style == EXTCOMMUNITY_LIST_STANDARD
15276 ? "standard"
15277 : "expanded",
15278 list->name, community_direct_str(entry->direct),
15279 community_list_config_str(entry));
15280 write++;
15281 }
15282
15283
15284 /* lcommunity-list. */
15285 cm = community_list_master_lookup(bgp_clist,
15286 LARGE_COMMUNITY_LIST_MASTER);
15287
15288 for (list = cm->num.head; list; list = list->next)
15289 for (entry = list->head; entry; entry = entry->next) {
7336e101 15290 vty_out(vty, "bgp large-community-list %s %s %s\n",
d62a17ae 15291 list->name, community_direct_str(entry->direct),
15292 community_list_config_str(entry));
15293 write++;
15294 }
15295 for (list = cm->str.head; list; list = list->next)
15296 for (entry = list->head; entry; entry = entry->next) {
7336e101 15297 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
d62a17ae 15298 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15299 ? "standard"
15300 : "expanded",
15301 list->name, community_direct_str(entry->direct),
15302 community_list_config_str(entry));
15303 write++;
15304 }
15305
15306 return write;
15307}
15308
15309static struct cmd_node community_list_node = {
15310 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 15311};
15312
d62a17ae 15313static void community_list_vty(void)
15314{
15315 install_node(&community_list_node, community_list_config_write);
15316
15317 /* Community-list. */
7336e101
SP
15318 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15319 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15320 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 15321 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 15322 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 15323 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
15324 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15325 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 15326
15327 /* Extcommunity-list. */
7336e101
SP
15328 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15329 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15330 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
15331 install_element(CONFIG_NODE,
15332 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 15333 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
15334 install_element(CONFIG_NODE,
15335 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
15336 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15337 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 15338
15339 /* Large Community List */
7336e101 15340 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
15341 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15342 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101
SP
15343 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15344 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15345 install_element(CONFIG_NODE,
15346 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15347 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15348 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15349 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15350 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15351 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15352 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 15353}