]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
zebra: Resolved nh change, inc refcnt by rt refcnt
[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
1924
718e3744 1925/* "bgp deterministic-med" configuration. */
1926DEFUN (bgp_deterministic_med,
1927 bgp_deterministic_med_cmd,
1928 "bgp deterministic-med",
1929 "BGP specific commands\n"
1930 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1931{
d62a17ae 1932 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1933
d62a17ae 1934 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1935 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1936 bgp_recalculate_all_bestpaths(bgp);
1937 }
7aafcaca 1938
d62a17ae 1939 return CMD_SUCCESS;
718e3744 1940}
1941
1942DEFUN (no_bgp_deterministic_med,
1943 no_bgp_deterministic_med_cmd,
1944 "no bgp deterministic-med",
1945 NO_STR
1946 "BGP specific commands\n"
1947 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1948{
d62a17ae 1949 VTY_DECLVAR_CONTEXT(bgp, bgp);
1950 int bestpath_per_as_used;
1951 afi_t afi;
1952 safi_t safi;
1953 struct peer *peer;
1954 struct listnode *node, *nnode;
1955
1956 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1957 bestpath_per_as_used = 0;
1958
1959 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 1960 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
1961 if (bgp_addpath_dmed_required(
1962 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
1963 bestpath_per_as_used = 1;
1964 break;
1965 }
d62a17ae 1966
1967 if (bestpath_per_as_used)
1968 break;
1969 }
1970
1971 if (bestpath_per_as_used) {
1972 vty_out(vty,
1973 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1974 return CMD_WARNING_CONFIG_FAILED;
1975 } else {
1976 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1977 bgp_recalculate_all_bestpaths(bgp);
1978 }
1979 }
1980
1981 return CMD_SUCCESS;
718e3744 1982}
538621f2 1983
1984/* "bgp graceful-restart" configuration. */
1985DEFUN (bgp_graceful_restart,
1986 bgp_graceful_restart_cmd,
1987 "bgp graceful-restart",
1988 "BGP specific commands\n"
1989 "Graceful restart capability parameters\n")
1990{
d62a17ae 1991 VTY_DECLVAR_CONTEXT(bgp, bgp);
1992 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1993 return CMD_SUCCESS;
538621f2 1994}
1995
1996DEFUN (no_bgp_graceful_restart,
1997 no_bgp_graceful_restart_cmd,
1998 "no bgp graceful-restart",
1999 NO_STR
2000 "BGP specific commands\n"
2001 "Graceful restart capability parameters\n")
2002{
d62a17ae 2003 VTY_DECLVAR_CONTEXT(bgp, bgp);
2004 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
2005 return CMD_SUCCESS;
538621f2 2006}
2007
93406d87 2008DEFUN (bgp_graceful_restart_stalepath_time,
2009 bgp_graceful_restart_stalepath_time_cmd,
c1779b7d 2010 "bgp graceful-restart stalepath-time (1-4095)",
93406d87 2011 "BGP specific commands\n"
2012 "Graceful restart capability parameters\n"
2013 "Set the max time to hold onto restarting peer's stale paths\n"
2014 "Delay value (seconds)\n")
2015{
d62a17ae 2016 VTY_DECLVAR_CONTEXT(bgp, bgp);
2017 int idx_number = 3;
d7c0a89a 2018 uint32_t stalepath;
93406d87 2019
d62a17ae 2020 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2021 bgp->stalepath_time = stalepath;
2022 return CMD_SUCCESS;
93406d87 2023}
2024
eb6f1b41
PG
2025DEFUN (bgp_graceful_restart_restart_time,
2026 bgp_graceful_restart_restart_time_cmd,
c72d0314 2027 "bgp graceful-restart restart-time (1-4095)",
eb6f1b41
PG
2028 "BGP specific commands\n"
2029 "Graceful restart capability parameters\n"
2030 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2031 "Delay value (seconds)\n")
2032{
d62a17ae 2033 VTY_DECLVAR_CONTEXT(bgp, bgp);
2034 int idx_number = 3;
d7c0a89a 2035 uint32_t restart;
eb6f1b41 2036
d62a17ae 2037 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2038 bgp->restart_time = restart;
2039 return CMD_SUCCESS;
eb6f1b41
PG
2040}
2041
93406d87 2042DEFUN (no_bgp_graceful_restart_stalepath_time,
2043 no_bgp_graceful_restart_stalepath_time_cmd,
c1779b7d 2044 "no bgp graceful-restart stalepath-time [(1-4095)]",
93406d87 2045 NO_STR
2046 "BGP specific commands\n"
2047 "Graceful restart capability parameters\n"
838758ac
DW
2048 "Set the max time to hold onto restarting peer's stale paths\n"
2049 "Delay value (seconds)\n")
93406d87 2050{
d62a17ae 2051 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2052
d62a17ae 2053 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2054 return CMD_SUCCESS;
93406d87 2055}
2056
eb6f1b41
PG
2057DEFUN (no_bgp_graceful_restart_restart_time,
2058 no_bgp_graceful_restart_restart_time_cmd,
c72d0314 2059 "no bgp graceful-restart restart-time [(1-4095)]",
eb6f1b41
PG
2060 NO_STR
2061 "BGP specific commands\n"
2062 "Graceful restart capability parameters\n"
838758ac
DW
2063 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2064 "Delay value (seconds)\n")
eb6f1b41 2065{
d62a17ae 2066 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2067
d62a17ae 2068 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2069 return CMD_SUCCESS;
eb6f1b41
PG
2070}
2071
43fc21b3
JC
2072DEFUN (bgp_graceful_restart_preserve_fw,
2073 bgp_graceful_restart_preserve_fw_cmd,
2074 "bgp graceful-restart preserve-fw-state",
2075 "BGP specific commands\n"
2076 "Graceful restart capability parameters\n"
2077 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2078{
d62a17ae 2079 VTY_DECLVAR_CONTEXT(bgp, bgp);
2080 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2081 return CMD_SUCCESS;
43fc21b3
JC
2082}
2083
2084DEFUN (no_bgp_graceful_restart_preserve_fw,
2085 no_bgp_graceful_restart_preserve_fw_cmd,
2086 "no bgp graceful-restart preserve-fw-state",
2087 NO_STR
2088 "BGP specific commands\n"
2089 "Graceful restart capability parameters\n"
2090 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2091{
d62a17ae 2092 VTY_DECLVAR_CONTEXT(bgp, bgp);
2093 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2094 return CMD_SUCCESS;
43fc21b3
JC
2095}
2096
7f323236
DW
2097/* "bgp graceful-shutdown" configuration */
2098DEFUN (bgp_graceful_shutdown,
2099 bgp_graceful_shutdown_cmd,
2100 "bgp graceful-shutdown",
2101 BGP_STR
2102 "Graceful shutdown parameters\n")
2103{
2104 VTY_DECLVAR_CONTEXT(bgp, bgp);
2105
2106 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2107 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2108 bgp_static_redo_import_check(bgp);
2109 bgp_redistribute_redo(bgp);
2110 bgp_clear_star_soft_out(vty, bgp->name);
2111 bgp_clear_star_soft_in(vty, bgp->name);
2112 }
2113
2114 return CMD_SUCCESS;
2115}
2116
2117DEFUN (no_bgp_graceful_shutdown,
2118 no_bgp_graceful_shutdown_cmd,
2119 "no bgp graceful-shutdown",
2120 NO_STR
2121 BGP_STR
2122 "Graceful shutdown parameters\n")
2123{
2124 VTY_DECLVAR_CONTEXT(bgp, bgp);
2125
2126 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2127 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2128 bgp_static_redo_import_check(bgp);
2129 bgp_redistribute_redo(bgp);
2130 bgp_clear_star_soft_out(vty, bgp->name);
2131 bgp_clear_star_soft_in(vty, bgp->name);
2132 }
2133
2134 return CMD_SUCCESS;
2135}
2136
718e3744 2137/* "bgp fast-external-failover" configuration. */
2138DEFUN (bgp_fast_external_failover,
2139 bgp_fast_external_failover_cmd,
2140 "bgp fast-external-failover",
2141 BGP_STR
2142 "Immediately reset session if a link to a directly connected external peer goes down\n")
2143{
d62a17ae 2144 VTY_DECLVAR_CONTEXT(bgp, bgp);
2145 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2146 return CMD_SUCCESS;
718e3744 2147}
2148
2149DEFUN (no_bgp_fast_external_failover,
2150 no_bgp_fast_external_failover_cmd,
2151 "no bgp fast-external-failover",
2152 NO_STR
2153 BGP_STR
2154 "Immediately reset session if a link to a directly connected external peer goes down\n")
2155{
d62a17ae 2156 VTY_DECLVAR_CONTEXT(bgp, bgp);
2157 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2158 return CMD_SUCCESS;
718e3744 2159}
6b0655a2 2160
718e3744 2161/* "bgp bestpath compare-routerid" configuration. */
2162DEFUN (bgp_bestpath_compare_router_id,
2163 bgp_bestpath_compare_router_id_cmd,
2164 "bgp bestpath compare-routerid",
2165 "BGP specific commands\n"
2166 "Change the default bestpath selection\n"
2167 "Compare router-id for identical EBGP paths\n")
2168{
d62a17ae 2169 VTY_DECLVAR_CONTEXT(bgp, bgp);
2170 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2171 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2172
d62a17ae 2173 return CMD_SUCCESS;
718e3744 2174}
2175
2176DEFUN (no_bgp_bestpath_compare_router_id,
2177 no_bgp_bestpath_compare_router_id_cmd,
2178 "no bgp bestpath compare-routerid",
2179 NO_STR
2180 "BGP specific commands\n"
2181 "Change the default bestpath selection\n"
2182 "Compare router-id for identical EBGP paths\n")
2183{
d62a17ae 2184 VTY_DECLVAR_CONTEXT(bgp, bgp);
2185 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2186 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2187
d62a17ae 2188 return CMD_SUCCESS;
718e3744 2189}
6b0655a2 2190
718e3744 2191/* "bgp bestpath as-path ignore" configuration. */
2192DEFUN (bgp_bestpath_aspath_ignore,
2193 bgp_bestpath_aspath_ignore_cmd,
2194 "bgp bestpath as-path ignore",
2195 "BGP specific commands\n"
2196 "Change the default bestpath selection\n"
2197 "AS-path attribute\n"
2198 "Ignore as-path length in selecting a route\n")
2199{
d62a17ae 2200 VTY_DECLVAR_CONTEXT(bgp, bgp);
2201 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2202 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2203
d62a17ae 2204 return CMD_SUCCESS;
718e3744 2205}
2206
2207DEFUN (no_bgp_bestpath_aspath_ignore,
2208 no_bgp_bestpath_aspath_ignore_cmd,
2209 "no bgp bestpath as-path ignore",
2210 NO_STR
2211 "BGP specific commands\n"
2212 "Change the default bestpath selection\n"
2213 "AS-path attribute\n"
2214 "Ignore as-path length in selecting a route\n")
2215{
d62a17ae 2216 VTY_DECLVAR_CONTEXT(bgp, bgp);
2217 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2218 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2219
d62a17ae 2220 return CMD_SUCCESS;
718e3744 2221}
6b0655a2 2222
6811845b 2223/* "bgp bestpath as-path confed" configuration. */
2224DEFUN (bgp_bestpath_aspath_confed,
2225 bgp_bestpath_aspath_confed_cmd,
2226 "bgp bestpath as-path confed",
2227 "BGP specific commands\n"
2228 "Change the default bestpath selection\n"
2229 "AS-path attribute\n"
2230 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2231{
d62a17ae 2232 VTY_DECLVAR_CONTEXT(bgp, bgp);
2233 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2234 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2235
d62a17ae 2236 return CMD_SUCCESS;
6811845b 2237}
2238
2239DEFUN (no_bgp_bestpath_aspath_confed,
2240 no_bgp_bestpath_aspath_confed_cmd,
2241 "no bgp bestpath as-path confed",
2242 NO_STR
2243 "BGP specific commands\n"
2244 "Change the default bestpath selection\n"
2245 "AS-path attribute\n"
2246 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2247{
d62a17ae 2248 VTY_DECLVAR_CONTEXT(bgp, bgp);
2249 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2250 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2251
d62a17ae 2252 return CMD_SUCCESS;
6811845b 2253}
6b0655a2 2254
2fdd455c
PM
2255/* "bgp bestpath as-path multipath-relax" configuration. */
2256DEFUN (bgp_bestpath_aspath_multipath_relax,
2257 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2258 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2259 "BGP specific commands\n"
2260 "Change the default bestpath selection\n"
2261 "AS-path attribute\n"
2262 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2263 "Generate an AS_SET\n"
16fc1eec
DS
2264 "Do not generate an AS_SET\n")
2265{
d62a17ae 2266 VTY_DECLVAR_CONTEXT(bgp, bgp);
2267 int idx = 0;
2268 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2269
d62a17ae 2270 /* no-as-set is now the default behavior so we can silently
2271 * ignore it */
2272 if (argv_find(argv, argc, "as-set", &idx))
2273 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2274 else
2275 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2276
d62a17ae 2277 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2278
d62a17ae 2279 return CMD_SUCCESS;
16fc1eec
DS
2280}
2281
219178b6
DW
2282DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2283 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2284 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2285 NO_STR
2286 "BGP specific commands\n"
2287 "Change the default bestpath selection\n"
2288 "AS-path attribute\n"
2289 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2290 "Generate an AS_SET\n"
16fc1eec
DS
2291 "Do not generate an AS_SET\n")
2292{
d62a17ae 2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
2294 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2295 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2296 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2297
d62a17ae 2298 return CMD_SUCCESS;
2fdd455c 2299}
6b0655a2 2300
848973c7 2301/* "bgp log-neighbor-changes" configuration. */
2302DEFUN (bgp_log_neighbor_changes,
2303 bgp_log_neighbor_changes_cmd,
2304 "bgp log-neighbor-changes",
2305 "BGP specific commands\n"
2306 "Log neighbor up/down and reset reason\n")
2307{
d62a17ae 2308 VTY_DECLVAR_CONTEXT(bgp, bgp);
2309 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2310 return CMD_SUCCESS;
848973c7 2311}
2312
2313DEFUN (no_bgp_log_neighbor_changes,
2314 no_bgp_log_neighbor_changes_cmd,
2315 "no bgp log-neighbor-changes",
2316 NO_STR
2317 "BGP specific commands\n"
2318 "Log neighbor up/down and reset reason\n")
2319{
d62a17ae 2320 VTY_DECLVAR_CONTEXT(bgp, bgp);
2321 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2322 return CMD_SUCCESS;
848973c7 2323}
6b0655a2 2324
718e3744 2325/* "bgp bestpath med" configuration. */
2326DEFUN (bgp_bestpath_med,
2327 bgp_bestpath_med_cmd,
2d8c1a4d 2328 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2329 "BGP specific commands\n"
2330 "Change the default bestpath selection\n"
2331 "MED attribute\n"
2332 "Compare MED among confederation paths\n"
838758ac
DW
2333 "Treat missing MED as the least preferred one\n"
2334 "Treat missing MED as the least preferred one\n"
2335 "Compare MED among confederation paths\n")
718e3744 2336{
d62a17ae 2337 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2338
d62a17ae 2339 int idx = 0;
2340 if (argv_find(argv, argc, "confed", &idx))
2341 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2342 idx = 0;
2343 if (argv_find(argv, argc, "missing-as-worst", &idx))
2344 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2345
d62a17ae 2346 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2347
d62a17ae 2348 return CMD_SUCCESS;
718e3744 2349}
2350
718e3744 2351DEFUN (no_bgp_bestpath_med,
2352 no_bgp_bestpath_med_cmd,
2d8c1a4d 2353 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2354 NO_STR
2355 "BGP specific commands\n"
2356 "Change the default bestpath selection\n"
2357 "MED attribute\n"
2358 "Compare MED among confederation paths\n"
3a2d747c
QY
2359 "Treat missing MED as the least preferred one\n"
2360 "Treat missing MED as the least preferred one\n"
2361 "Compare MED among confederation paths\n")
718e3744 2362{
d62a17ae 2363 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2364
d62a17ae 2365 int idx = 0;
2366 if (argv_find(argv, argc, "confed", &idx))
2367 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2368 idx = 0;
2369 if (argv_find(argv, argc, "missing-as-worst", &idx))
2370 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2371
d62a17ae 2372 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2373
d62a17ae 2374 return CMD_SUCCESS;
718e3744 2375}
2376
718e3744 2377/* "no bgp default ipv4-unicast". */
2378DEFUN (no_bgp_default_ipv4_unicast,
2379 no_bgp_default_ipv4_unicast_cmd,
2380 "no bgp default ipv4-unicast",
2381 NO_STR
2382 "BGP specific commands\n"
2383 "Configure BGP defaults\n"
2384 "Activate ipv4-unicast for a peer by default\n")
2385{
d62a17ae 2386 VTY_DECLVAR_CONTEXT(bgp, bgp);
2387 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2388 return CMD_SUCCESS;
718e3744 2389}
2390
2391DEFUN (bgp_default_ipv4_unicast,
2392 bgp_default_ipv4_unicast_cmd,
2393 "bgp default ipv4-unicast",
2394 "BGP specific commands\n"
2395 "Configure BGP defaults\n"
2396 "Activate ipv4-unicast for a peer by default\n")
2397{
d62a17ae 2398 VTY_DECLVAR_CONTEXT(bgp, bgp);
2399 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2400 return CMD_SUCCESS;
718e3744 2401}
6b0655a2 2402
04b6bdc0
DW
2403/* Display hostname in certain command outputs */
2404DEFUN (bgp_default_show_hostname,
2405 bgp_default_show_hostname_cmd,
2406 "bgp default show-hostname",
2407 "BGP specific commands\n"
2408 "Configure BGP defaults\n"
0437e105 2409 "Show hostname in certain command outputs\n")
04b6bdc0 2410{
d62a17ae 2411 VTY_DECLVAR_CONTEXT(bgp, bgp);
2412 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2413 return CMD_SUCCESS;
04b6bdc0
DW
2414}
2415
2416DEFUN (no_bgp_default_show_hostname,
2417 no_bgp_default_show_hostname_cmd,
2418 "no bgp default show-hostname",
2419 NO_STR
2420 "BGP specific commands\n"
2421 "Configure BGP defaults\n"
0437e105 2422 "Show hostname in certain command outputs\n")
04b6bdc0 2423{
d62a17ae 2424 VTY_DECLVAR_CONTEXT(bgp, bgp);
2425 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2426 return CMD_SUCCESS;
04b6bdc0
DW
2427}
2428
8233ef81 2429/* "bgp network import-check" configuration. */
718e3744 2430DEFUN (bgp_network_import_check,
2431 bgp_network_import_check_cmd,
5623e905 2432 "bgp network import-check",
718e3744 2433 "BGP specific commands\n"
2434 "BGP network command\n"
5623e905 2435 "Check BGP network route exists in IGP\n")
718e3744 2436{
d62a17ae 2437 VTY_DECLVAR_CONTEXT(bgp, bgp);
2438 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2439 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2440 bgp_static_redo_import_check(bgp);
2441 }
078430f6 2442
d62a17ae 2443 return CMD_SUCCESS;
718e3744 2444}
2445
d62a17ae 2446ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2447 "bgp network import-check exact",
2448 "BGP specific commands\n"
2449 "BGP network command\n"
2450 "Check BGP network route exists in IGP\n"
2451 "Match route precisely\n")
8233ef81 2452
718e3744 2453DEFUN (no_bgp_network_import_check,
2454 no_bgp_network_import_check_cmd,
5623e905 2455 "no bgp network import-check",
718e3744 2456 NO_STR
2457 "BGP specific commands\n"
2458 "BGP network command\n"
2459 "Check BGP network route exists in IGP\n")
2460{
d62a17ae 2461 VTY_DECLVAR_CONTEXT(bgp, bgp);
2462 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2463 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2464 bgp_static_redo_import_check(bgp);
2465 }
5623e905 2466
d62a17ae 2467 return CMD_SUCCESS;
718e3744 2468}
6b0655a2 2469
718e3744 2470DEFUN (bgp_default_local_preference,
2471 bgp_default_local_preference_cmd,
6147e2c6 2472 "bgp default local-preference (0-4294967295)",
718e3744 2473 "BGP specific commands\n"
2474 "Configure BGP defaults\n"
2475 "local preference (higher=more preferred)\n"
2476 "Configure default local preference value\n")
2477{
d62a17ae 2478 VTY_DECLVAR_CONTEXT(bgp, bgp);
2479 int idx_number = 3;
d7c0a89a 2480 uint32_t local_pref;
718e3744 2481
d62a17ae 2482 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2483
d62a17ae 2484 bgp_default_local_preference_set(bgp, local_pref);
2485 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2486
d62a17ae 2487 return CMD_SUCCESS;
718e3744 2488}
2489
2490DEFUN (no_bgp_default_local_preference,
2491 no_bgp_default_local_preference_cmd,
838758ac 2492 "no bgp default local-preference [(0-4294967295)]",
718e3744 2493 NO_STR
2494 "BGP specific commands\n"
2495 "Configure BGP defaults\n"
838758ac
DW
2496 "local preference (higher=more preferred)\n"
2497 "Configure default local preference value\n")
718e3744 2498{
d62a17ae 2499 VTY_DECLVAR_CONTEXT(bgp, bgp);
2500 bgp_default_local_preference_unset(bgp);
2501 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2502
d62a17ae 2503 return CMD_SUCCESS;
718e3744 2504}
2505
6b0655a2 2506
3f9c7369
DS
2507DEFUN (bgp_default_subgroup_pkt_queue_max,
2508 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2509 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2510 "BGP specific commands\n"
2511 "Configure BGP defaults\n"
2512 "subgroup-pkt-queue-max\n"
2513 "Configure subgroup packet queue max\n")
8bd9d948 2514{
d62a17ae 2515 VTY_DECLVAR_CONTEXT(bgp, bgp);
2516 int idx_number = 3;
d7c0a89a 2517 uint32_t max_size;
8bd9d948 2518
d62a17ae 2519 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2520
d62a17ae 2521 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2522
d62a17ae 2523 return CMD_SUCCESS;
3f9c7369
DS
2524}
2525
2526DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2527 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2528 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2529 NO_STR
2530 "BGP specific commands\n"
2531 "Configure BGP defaults\n"
838758ac
DW
2532 "subgroup-pkt-queue-max\n"
2533 "Configure subgroup packet queue max\n")
3f9c7369 2534{
d62a17ae 2535 VTY_DECLVAR_CONTEXT(bgp, bgp);
2536 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2537 return CMD_SUCCESS;
8bd9d948
DS
2538}
2539
813d4307 2540
8bd9d948
DS
2541DEFUN (bgp_rr_allow_outbound_policy,
2542 bgp_rr_allow_outbound_policy_cmd,
2543 "bgp route-reflector allow-outbound-policy",
2544 "BGP specific commands\n"
2545 "Allow modifications made by out route-map\n"
2546 "on ibgp neighbors\n")
2547{
d62a17ae 2548 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2549
d62a17ae 2550 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2551 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2552 update_group_announce_rrclients(bgp);
2553 bgp_clear_star_soft_out(vty, bgp->name);
2554 }
8bd9d948 2555
d62a17ae 2556 return CMD_SUCCESS;
8bd9d948
DS
2557}
2558
2559DEFUN (no_bgp_rr_allow_outbound_policy,
2560 no_bgp_rr_allow_outbound_policy_cmd,
2561 "no bgp route-reflector allow-outbound-policy",
2562 NO_STR
2563 "BGP specific commands\n"
2564 "Allow modifications made by out route-map\n"
2565 "on ibgp neighbors\n")
2566{
d62a17ae 2567 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2568
d62a17ae 2569 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2570 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2571 update_group_announce_rrclients(bgp);
2572 bgp_clear_star_soft_out(vty, bgp->name);
2573 }
8bd9d948 2574
d62a17ae 2575 return CMD_SUCCESS;
8bd9d948
DS
2576}
2577
f14e6fdb
DS
2578DEFUN (bgp_listen_limit,
2579 bgp_listen_limit_cmd,
9ccf14f7 2580 "bgp listen limit (1-5000)",
f14e6fdb
DS
2581 "BGP specific commands\n"
2582 "Configure BGP defaults\n"
2583 "maximum number of BGP Dynamic Neighbors that can be created\n"
2584 "Configure Dynamic Neighbors listen limit value\n")
2585{
d62a17ae 2586 VTY_DECLVAR_CONTEXT(bgp, bgp);
2587 int idx_number = 3;
2588 int listen_limit;
f14e6fdb 2589
d62a17ae 2590 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2591
d62a17ae 2592 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2593
d62a17ae 2594 return CMD_SUCCESS;
f14e6fdb
DS
2595}
2596
2597DEFUN (no_bgp_listen_limit,
2598 no_bgp_listen_limit_cmd,
838758ac 2599 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2600 "BGP specific commands\n"
2601 "Configure BGP defaults\n"
2602 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2603 "Configure Dynamic Neighbors listen limit value to default\n"
2604 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2605{
d62a17ae 2606 VTY_DECLVAR_CONTEXT(bgp, bgp);
2607 bgp_listen_limit_unset(bgp);
2608 return CMD_SUCCESS;
f14e6fdb
DS
2609}
2610
2611
20eb8864 2612/*
2613 * Check if this listen range is already configured. Check for exact
2614 * match or overlap based on input.
2615 */
d62a17ae 2616static struct peer_group *listen_range_exists(struct bgp *bgp,
2617 struct prefix *range, int exact)
2618{
2619 struct listnode *node, *nnode;
2620 struct listnode *node1, *nnode1;
2621 struct peer_group *group;
2622 struct prefix *lr;
2623 afi_t afi;
2624 int match;
2625
2626 afi = family2afi(range->family);
2627 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2628 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2629 lr)) {
2630 if (exact)
2631 match = prefix_same(range, lr);
2632 else
2633 match = (prefix_match(range, lr)
2634 || prefix_match(lr, range));
2635 if (match)
2636 return group;
2637 }
2638 }
2639
2640 return NULL;
20eb8864 2641}
2642
f14e6fdb
DS
2643DEFUN (bgp_listen_range,
2644 bgp_listen_range_cmd,
d7b9898c 2645 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 2646 "BGP specific commands\n"
d7fa34c1
QY
2647 "Configure BGP dynamic neighbors listen range\n"
2648 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2649 NEIGHBOR_ADDR_STR
2650 "Member of the peer-group\n"
2651 "Peer-group name\n")
f14e6fdb 2652{
d62a17ae 2653 VTY_DECLVAR_CONTEXT(bgp, bgp);
2654 struct prefix range;
2655 struct peer_group *group, *existing_group;
2656 afi_t afi;
2657 int ret;
2658 int idx = 0;
2659
2660 argv_find(argv, argc, "A.B.C.D/M", &idx);
2661 argv_find(argv, argc, "X:X::X:X/M", &idx);
2662 char *prefix = argv[idx]->arg;
d7b9898c 2663 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 2664 char *peergroup = argv[idx]->arg;
2665
2666 /* Convert IP prefix string to struct prefix. */
2667 ret = str2prefix(prefix, &range);
2668 if (!ret) {
2669 vty_out(vty, "%% Malformed listen range\n");
2670 return CMD_WARNING_CONFIG_FAILED;
2671 }
2672
2673 afi = family2afi(range.family);
2674
2675 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2676 vty_out(vty,
2677 "%% Malformed listen range (link-local address)\n");
2678 return CMD_WARNING_CONFIG_FAILED;
2679 }
2680
2681 apply_mask(&range);
2682
2683 /* Check if same listen range is already configured. */
2684 existing_group = listen_range_exists(bgp, &range, 1);
2685 if (existing_group) {
2686 if (strcmp(existing_group->name, peergroup) == 0)
2687 return CMD_SUCCESS;
2688 else {
2689 vty_out(vty,
2690 "%% Same listen range is attached to peer-group %s\n",
2691 existing_group->name);
2692 return CMD_WARNING_CONFIG_FAILED;
2693 }
2694 }
2695
2696 /* Check if an overlapping listen range exists. */
2697 if (listen_range_exists(bgp, &range, 0)) {
2698 vty_out(vty,
2699 "%% Listen range overlaps with existing listen range\n");
2700 return CMD_WARNING_CONFIG_FAILED;
2701 }
2702
2703 group = peer_group_lookup(bgp, peergroup);
2704 if (!group) {
2705 vty_out(vty, "%% Configure the peer-group first\n");
2706 return CMD_WARNING_CONFIG_FAILED;
2707 }
2708
2709 ret = peer_group_listen_range_add(group, &range);
2710 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2711}
2712
2713DEFUN (no_bgp_listen_range,
2714 no_bgp_listen_range_cmd,
d7b9898c 2715 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 2716 NO_STR
f14e6fdb 2717 "BGP specific commands\n"
d7fa34c1
QY
2718 "Unconfigure BGP dynamic neighbors listen range\n"
2719 "Unconfigure BGP dynamic neighbors listen range\n"
2720 NEIGHBOR_ADDR_STR
2721 "Member of the peer-group\n"
2722 "Peer-group name\n")
f14e6fdb 2723{
d62a17ae 2724 VTY_DECLVAR_CONTEXT(bgp, bgp);
2725 struct prefix range;
2726 struct peer_group *group;
2727 afi_t afi;
2728 int ret;
2729 int idx = 0;
2730
2731 argv_find(argv, argc, "A.B.C.D/M", &idx);
2732 argv_find(argv, argc, "X:X::X:X/M", &idx);
2733 char *prefix = argv[idx]->arg;
2734 argv_find(argv, argc, "WORD", &idx);
2735 char *peergroup = argv[idx]->arg;
2736
2737 /* Convert IP prefix string to struct prefix. */
2738 ret = str2prefix(prefix, &range);
2739 if (!ret) {
2740 vty_out(vty, "%% Malformed listen range\n");
2741 return CMD_WARNING_CONFIG_FAILED;
2742 }
2743
2744 afi = family2afi(range.family);
2745
2746 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2747 vty_out(vty,
2748 "%% Malformed listen range (link-local address)\n");
2749 return CMD_WARNING_CONFIG_FAILED;
2750 }
2751
2752 apply_mask(&range);
2753
2754 group = peer_group_lookup(bgp, peergroup);
2755 if (!group) {
2756 vty_out(vty, "%% Peer-group does not exist\n");
2757 return CMD_WARNING_CONFIG_FAILED;
2758 }
2759
2760 ret = peer_group_listen_range_del(group, &range);
2761 return bgp_vty_return(vty, ret);
2762}
2763
2b791107 2764void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2765{
2766 struct peer_group *group;
2767 struct listnode *node, *nnode, *rnode, *nrnode;
2768 struct prefix *range;
2769 afi_t afi;
2770 char buf[PREFIX2STR_BUFFER];
2771
2772 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2773 vty_out(vty, " bgp listen limit %d\n",
2774 bgp->dynamic_neighbors_limit);
2775
2776 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2777 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2778 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2779 nrnode, range)) {
2780 prefix2str(range, buf, sizeof(buf));
2781 vty_out(vty,
2782 " bgp listen range %s peer-group %s\n",
2783 buf, group->name);
2784 }
2785 }
2786 }
f14e6fdb
DS
2787}
2788
2789
907f92c8
DS
2790DEFUN (bgp_disable_connected_route_check,
2791 bgp_disable_connected_route_check_cmd,
2792 "bgp disable-ebgp-connected-route-check",
2793 "BGP specific commands\n"
2794 "Disable checking if nexthop is connected on ebgp sessions\n")
2795{
d62a17ae 2796 VTY_DECLVAR_CONTEXT(bgp, bgp);
2797 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2798 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2799
d62a17ae 2800 return CMD_SUCCESS;
907f92c8
DS
2801}
2802
2803DEFUN (no_bgp_disable_connected_route_check,
2804 no_bgp_disable_connected_route_check_cmd,
2805 "no bgp disable-ebgp-connected-route-check",
2806 NO_STR
2807 "BGP specific commands\n"
2808 "Disable checking if nexthop is connected on ebgp sessions\n")
2809{
d62a17ae 2810 VTY_DECLVAR_CONTEXT(bgp, bgp);
2811 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2812 bgp_clear_star_soft_in(vty, bgp->name);
2813
2814 return CMD_SUCCESS;
2815}
2816
2817
2818static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2819 const char *as_str, afi_t afi, safi_t safi)
2820{
2821 VTY_DECLVAR_CONTEXT(bgp, bgp);
2822 int ret;
2823 as_t as;
2824 int as_type = AS_SPECIFIED;
2825 union sockunion su;
2826
2827 if (as_str[0] == 'i') {
2828 as = 0;
2829 as_type = AS_INTERNAL;
2830 } else if (as_str[0] == 'e') {
2831 as = 0;
2832 as_type = AS_EXTERNAL;
2833 } else {
2834 /* Get AS number. */
2835 as = strtoul(as_str, NULL, 10);
2836 }
2837
390485fd 2838 /* If peer is peer group or interface peer, call proper function. */
d62a17ae 2839 ret = str2sockunion(peer_str, &su);
2840 if (ret < 0) {
390485fd
DS
2841 struct peer *peer;
2842
2843 /* Check if existing interface peer */
2844 peer = peer_lookup_by_conf_if(bgp, peer_str);
2845
d62a17ae 2846 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2847 safi);
390485fd
DS
2848
2849 /* if not interface peer, check peer-group settings */
2850 if (ret < 0 && !peer) {
d62a17ae 2851 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2852 if (ret < 0) {
2853 vty_out(vty,
390485fd 2854 "%% Create the peer-group or interface first\n");
d62a17ae 2855 return CMD_WARNING_CONFIG_FAILED;
2856 }
2857 return CMD_SUCCESS;
2858 }
2859 } else {
2860 if (peer_address_self_check(bgp, &su)) {
2861 vty_out(vty,
2862 "%% Can not configure the local system as neighbor\n");
2863 return CMD_WARNING_CONFIG_FAILED;
2864 }
2865 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2866 }
2867
2868 /* This peer belongs to peer group. */
2869 switch (ret) {
2870 case BGP_ERR_PEER_GROUP_MEMBER:
2871 vty_out(vty,
faa16034 2872 "%% Peer-group member cannot override remote-as of peer-group\n");
d62a17ae 2873 return CMD_WARNING_CONFIG_FAILED;
2874 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2875 vty_out(vty,
faa16034 2876 "%% Peer-group members must be all internal or all external\n");
d62a17ae 2877 return CMD_WARNING_CONFIG_FAILED;
2878 }
2879 return bgp_vty_return(vty, ret);
718e3744 2880}
2881
f26845f9
QY
2882DEFUN (bgp_default_shutdown,
2883 bgp_default_shutdown_cmd,
2884 "[no] bgp default shutdown",
2885 NO_STR
2886 BGP_STR
2887 "Configure BGP defaults\n"
b012cbe2 2888 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2889{
2890 VTY_DECLVAR_CONTEXT(bgp, bgp);
2891 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2892 return CMD_SUCCESS;
2893}
2894
718e3744 2895DEFUN (neighbor_remote_as,
2896 neighbor_remote_as_cmd,
3a2d747c 2897 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2898 NEIGHBOR_STR
2899 NEIGHBOR_ADDR_STR2
2900 "Specify a BGP neighbor\n"
d7fa34c1 2901 AS_STR
3a2d747c
QY
2902 "Internal BGP peer\n"
2903 "External BGP peer\n")
718e3744 2904{
d62a17ae 2905 int idx_peer = 1;
2906 int idx_remote_as = 3;
2907 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2908 argv[idx_remote_as]->arg, AFI_IP,
2909 SAFI_UNICAST);
2910}
2911
2912static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2913 afi_t afi, safi_t safi, int v6only,
2914 const char *peer_group_name,
2915 const char *as_str)
2916{
2917 VTY_DECLVAR_CONTEXT(bgp, bgp);
2918 as_t as = 0;
2919 int as_type = AS_UNSPECIFIED;
2920 struct peer *peer;
2921 struct peer_group *group;
2922 int ret = 0;
2923 union sockunion su;
2924
2925 group = peer_group_lookup(bgp, conf_if);
2926
2927 if (group) {
2928 vty_out(vty, "%% Name conflict with peer-group \n");
2929 return CMD_WARNING_CONFIG_FAILED;
2930 }
2931
2932 if (as_str) {
2933 if (as_str[0] == 'i') {
2934 as_type = AS_INTERNAL;
2935 } else if (as_str[0] == 'e') {
2936 as_type = AS_EXTERNAL;
2937 } else {
2938 /* Get AS number. */
2939 as = strtoul(as_str, NULL, 10);
2940 as_type = AS_SPECIFIED;
2941 }
2942 }
2943
2944 peer = peer_lookup_by_conf_if(bgp, conf_if);
2945 if (peer) {
2946 if (as_str)
cc4d4ce8 2947 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 2948 afi, safi);
2949 } else {
2950 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2951 && afi == AFI_IP && safi == SAFI_UNICAST)
2952 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2953 as_type, 0, 0, NULL);
2954 else
2955 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2956 as_type, afi, safi, NULL);
2957
2958 if (!peer) {
2959 vty_out(vty, "%% BGP failed to create peer\n");
2960 return CMD_WARNING_CONFIG_FAILED;
2961 }
2962
2963 if (v6only)
527de3dc 2964 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2965
2966 /* Request zebra to initiate IPv6 RAs on this interface. We do
2967 * this
2968 * any unnumbered peer in order to not worry about run-time
2969 * transitions
2970 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2971 * address
2972 * gets deleted later etc.)
2973 */
2974 if (peer->ifp)
2975 bgp_zebra_initiate_radv(bgp, peer);
2976 }
2977
2978 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2979 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2980 if (v6only)
527de3dc 2981 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2982 else
527de3dc 2983 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2984
2985 /* v6only flag changed. Reset bgp seesion */
2986 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2987 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2988 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2989 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2990 } else
2991 bgp_session_reset(peer);
2992 }
2993
9fb964de
PM
2994 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2995 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2996 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 2997 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 2998 }
d62a17ae 2999
3000 if (peer_group_name) {
3001 group = peer_group_lookup(bgp, peer_group_name);
3002 if (!group) {
3003 vty_out(vty, "%% Configure the peer-group first\n");
3004 return CMD_WARNING_CONFIG_FAILED;
3005 }
3006
3007 ret = peer_group_bind(bgp, &su, peer, group, &as);
3008 }
3009
3010 return bgp_vty_return(vty, ret);
a80beece
DS
3011}
3012
4c48cf63
DW
3013DEFUN (neighbor_interface_config,
3014 neighbor_interface_config_cmd,
d7b9898c 3015 "neighbor WORD interface [peer-group PGNAME]",
4c48cf63
DW
3016 NEIGHBOR_STR
3017 "Interface name or neighbor tag\n"
31500417
DW
3018 "Enable BGP on interface\n"
3019 "Member of the peer-group\n"
16cedbb0 3020 "Peer-group name\n")
4c48cf63 3021{
d62a17ae 3022 int idx_word = 1;
3023 int idx_peer_group_word = 4;
31500417 3024
d62a17ae 3025 if (argc > idx_peer_group_word)
3026 return peer_conf_interface_get(
3027 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3028 argv[idx_peer_group_word]->arg, NULL);
3029 else
3030 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3031 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
3032}
3033
4c48cf63
DW
3034DEFUN (neighbor_interface_config_v6only,
3035 neighbor_interface_config_v6only_cmd,
d7b9898c 3036 "neighbor WORD interface v6only [peer-group PGNAME]",
4c48cf63
DW
3037 NEIGHBOR_STR
3038 "Interface name or neighbor tag\n"
3039 "Enable BGP on interface\n"
31500417
DW
3040 "Enable BGP with v6 link-local only\n"
3041 "Member of the peer-group\n"
16cedbb0 3042 "Peer-group name\n")
4c48cf63 3043{
d62a17ae 3044 int idx_word = 1;
3045 int idx_peer_group_word = 5;
31500417 3046
d62a17ae 3047 if (argc > idx_peer_group_word)
3048 return peer_conf_interface_get(
3049 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3050 argv[idx_peer_group_word]->arg, NULL);
31500417 3051
d62a17ae 3052 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3053 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
3054}
3055
a80beece 3056
b3a39dc5
DD
3057DEFUN (neighbor_interface_config_remote_as,
3058 neighbor_interface_config_remote_as_cmd,
3a2d747c 3059 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3060 NEIGHBOR_STR
3061 "Interface name or neighbor tag\n"
3062 "Enable BGP on interface\n"
3a2d747c 3063 "Specify a BGP neighbor\n"
d7fa34c1 3064 AS_STR
3a2d747c
QY
3065 "Internal BGP peer\n"
3066 "External BGP peer\n")
b3a39dc5 3067{
d62a17ae 3068 int idx_word = 1;
3069 int idx_remote_as = 4;
3070 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3071 SAFI_UNICAST, 0, NULL,
3072 argv[idx_remote_as]->arg);
b3a39dc5
DD
3073}
3074
3075DEFUN (neighbor_interface_v6only_config_remote_as,
3076 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 3077 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3078 NEIGHBOR_STR
3079 "Interface name or neighbor tag\n"
3a2d747c 3080 "Enable BGP with v6 link-local only\n"
b3a39dc5 3081 "Enable BGP on interface\n"
3a2d747c 3082 "Specify a BGP neighbor\n"
d7fa34c1 3083 AS_STR
3a2d747c
QY
3084 "Internal BGP peer\n"
3085 "External BGP peer\n")
b3a39dc5 3086{
d62a17ae 3087 int idx_word = 1;
3088 int idx_remote_as = 5;
3089 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3090 SAFI_UNICAST, 1, NULL,
3091 argv[idx_remote_as]->arg);
b3a39dc5
DD
3092}
3093
718e3744 3094DEFUN (neighbor_peer_group,
3095 neighbor_peer_group_cmd,
3096 "neighbor WORD peer-group",
3097 NEIGHBOR_STR
a80beece 3098 "Interface name or neighbor tag\n"
718e3744 3099 "Configure peer-group\n")
3100{
d62a17ae 3101 VTY_DECLVAR_CONTEXT(bgp, bgp);
3102 int idx_word = 1;
3103 struct peer *peer;
3104 struct peer_group *group;
718e3744 3105
d62a17ae 3106 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3107 if (peer) {
3108 vty_out(vty, "%% Name conflict with interface: \n");
3109 return CMD_WARNING_CONFIG_FAILED;
3110 }
718e3744 3111
d62a17ae 3112 group = peer_group_get(bgp, argv[idx_word]->arg);
3113 if (!group) {
3114 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3115 return CMD_WARNING_CONFIG_FAILED;
3116 }
718e3744 3117
d62a17ae 3118 return CMD_SUCCESS;
718e3744 3119}
3120
3121DEFUN (no_neighbor,
3122 no_neighbor_cmd,
dab8cd00 3123 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3124 NO_STR
3125 NEIGHBOR_STR
3a2d747c
QY
3126 NEIGHBOR_ADDR_STR2
3127 "Specify a BGP neighbor\n"
3128 AS_STR
3129 "Internal BGP peer\n"
3130 "External BGP peer\n")
718e3744 3131{
d62a17ae 3132 VTY_DECLVAR_CONTEXT(bgp, bgp);
3133 int idx_peer = 2;
3134 int ret;
3135 union sockunion su;
3136 struct peer_group *group;
3137 struct peer *peer;
3138 struct peer *other;
3139
3140 ret = str2sockunion(argv[idx_peer]->arg, &su);
3141 if (ret < 0) {
3142 /* look up for neighbor by interface name config. */
3143 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3144 if (peer) {
3145 /* Request zebra to terminate IPv6 RAs on this
3146 * interface. */
3147 if (peer->ifp)
3148 bgp_zebra_terminate_radv(peer->bgp, peer);
3149 peer_delete(peer);
3150 return CMD_SUCCESS;
3151 }
f14e6fdb 3152
d62a17ae 3153 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3154 if (group)
3155 peer_group_delete(group);
3156 else {
3157 vty_out(vty, "%% Create the peer-group first\n");
3158 return CMD_WARNING_CONFIG_FAILED;
3159 }
3160 } else {
3161 peer = peer_lookup(bgp, &su);
3162 if (peer) {
3163 if (peer_dynamic_neighbor(peer)) {
3164 vty_out(vty,
3165 "%% Operation not allowed on a dynamic neighbor\n");
3166 return CMD_WARNING_CONFIG_FAILED;
3167 }
3168
3169 other = peer->doppelganger;
3170 peer_delete(peer);
3171 if (other && other->status != Deleted)
3172 peer_delete(other);
3173 }
1ff9a340 3174 }
718e3744 3175
d62a17ae 3176 return CMD_SUCCESS;
718e3744 3177}
3178
a80beece
DS
3179DEFUN (no_neighbor_interface_config,
3180 no_neighbor_interface_config_cmd,
d7b9898c 3181 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3182 NO_STR
3183 NEIGHBOR_STR
3184 "Interface name\n"
31500417
DW
3185 "Configure BGP on interface\n"
3186 "Enable BGP with v6 link-local only\n"
3187 "Member of the peer-group\n"
16cedbb0 3188 "Peer-group name\n"
3a2d747c
QY
3189 "Specify a BGP neighbor\n"
3190 AS_STR
3191 "Internal BGP peer\n"
3192 "External BGP peer\n")
a80beece 3193{
d62a17ae 3194 VTY_DECLVAR_CONTEXT(bgp, bgp);
3195 int idx_word = 2;
3196 struct peer *peer;
3197
3198 /* look up for neighbor by interface name config. */
3199 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3200 if (peer) {
3201 /* Request zebra to terminate IPv6 RAs on this interface. */
3202 if (peer->ifp)
3203 bgp_zebra_terminate_radv(peer->bgp, peer);
3204 peer_delete(peer);
3205 } else {
3206 vty_out(vty, "%% Create the bgp interface first\n");
3207 return CMD_WARNING_CONFIG_FAILED;
3208 }
3209 return CMD_SUCCESS;
a80beece
DS
3210}
3211
718e3744 3212DEFUN (no_neighbor_peer_group,
3213 no_neighbor_peer_group_cmd,
3214 "no neighbor WORD peer-group",
3215 NO_STR
3216 NEIGHBOR_STR
3217 "Neighbor tag\n"
3218 "Configure peer-group\n")
3219{
d62a17ae 3220 VTY_DECLVAR_CONTEXT(bgp, bgp);
3221 int idx_word = 2;
3222 struct peer_group *group;
718e3744 3223
d62a17ae 3224 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3225 if (group)
3226 peer_group_delete(group);
3227 else {
3228 vty_out(vty, "%% Create the peer-group first\n");
3229 return CMD_WARNING_CONFIG_FAILED;
3230 }
3231 return CMD_SUCCESS;
718e3744 3232}
3233
a80beece
DS
3234DEFUN (no_neighbor_interface_peer_group_remote_as,
3235 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3236 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3237 NO_STR
3238 NEIGHBOR_STR
a80beece 3239 "Interface name or neighbor tag\n"
718e3744 3240 "Specify a BGP neighbor\n"
3a2d747c
QY
3241 AS_STR
3242 "Internal BGP peer\n"
3243 "External BGP peer\n")
718e3744 3244{
d62a17ae 3245 VTY_DECLVAR_CONTEXT(bgp, bgp);
3246 int idx_word = 2;
3247 struct peer_group *group;
3248 struct peer *peer;
3249
3250 /* look up for neighbor by interface name config. */
3251 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3252 if (peer) {
390485fd 3253 peer_as_change(peer, 0, AS_UNSPECIFIED);
d62a17ae 3254 return CMD_SUCCESS;
3255 }
3256
3257 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3258 if (group)
3259 peer_group_remote_as_delete(group);
3260 else {
3261 vty_out(vty, "%% Create the peer-group or interface first\n");
3262 return CMD_WARNING_CONFIG_FAILED;
3263 }
3264 return CMD_SUCCESS;
718e3744 3265}
6b0655a2 3266
718e3744 3267DEFUN (neighbor_local_as,
3268 neighbor_local_as_cmd,
9ccf14f7 3269 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3270 NEIGHBOR_STR
3271 NEIGHBOR_ADDR_STR2
3272 "Specify a local-as number\n"
3273 "AS number used as local AS\n")
3274{
d62a17ae 3275 int idx_peer = 1;
3276 int idx_number = 3;
3277 struct peer *peer;
3278 int ret;
3279 as_t as;
718e3744 3280
d62a17ae 3281 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3282 if (!peer)
3283 return CMD_WARNING_CONFIG_FAILED;
718e3744 3284
d62a17ae 3285 as = strtoul(argv[idx_number]->arg, NULL, 10);
3286 ret = peer_local_as_set(peer, as, 0, 0);
3287 return bgp_vty_return(vty, ret);
718e3744 3288}
3289
3290DEFUN (neighbor_local_as_no_prepend,
3291 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3292 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3293 NEIGHBOR_STR
3294 NEIGHBOR_ADDR_STR2
3295 "Specify a local-as number\n"
3296 "AS number used as local AS\n"
3297 "Do not prepend local-as to updates from ebgp peers\n")
3298{
d62a17ae 3299 int idx_peer = 1;
3300 int idx_number = 3;
3301 struct peer *peer;
3302 int ret;
3303 as_t as;
718e3744 3304
d62a17ae 3305 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3306 if (!peer)
3307 return CMD_WARNING_CONFIG_FAILED;
718e3744 3308
d62a17ae 3309 as = strtoul(argv[idx_number]->arg, NULL, 10);
3310 ret = peer_local_as_set(peer, as, 1, 0);
3311 return bgp_vty_return(vty, ret);
718e3744 3312}
3313
9d3f9705
AC
3314DEFUN (neighbor_local_as_no_prepend_replace_as,
3315 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3316 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3317 NEIGHBOR_STR
3318 NEIGHBOR_ADDR_STR2
3319 "Specify a local-as number\n"
3320 "AS number used as local AS\n"
3321 "Do not prepend local-as to updates from ebgp peers\n"
3322 "Do not prepend local-as to updates from ibgp peers\n")
3323{
d62a17ae 3324 int idx_peer = 1;
3325 int idx_number = 3;
3326 struct peer *peer;
3327 int ret;
3328 as_t as;
9d3f9705 3329
d62a17ae 3330 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3331 if (!peer)
3332 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3333
d62a17ae 3334 as = strtoul(argv[idx_number]->arg, NULL, 10);
3335 ret = peer_local_as_set(peer, as, 1, 1);
3336 return bgp_vty_return(vty, ret);
9d3f9705
AC
3337}
3338
718e3744 3339DEFUN (no_neighbor_local_as,
3340 no_neighbor_local_as_cmd,
a636c635 3341 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3342 NO_STR
3343 NEIGHBOR_STR
3344 NEIGHBOR_ADDR_STR2
a636c635
DW
3345 "Specify a local-as number\n"
3346 "AS number used as local AS\n"
3347 "Do not prepend local-as to updates from ebgp peers\n"
3348 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3349{
d62a17ae 3350 int idx_peer = 2;
3351 struct peer *peer;
3352 int ret;
718e3744 3353
d62a17ae 3354 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3355 if (!peer)
3356 return CMD_WARNING_CONFIG_FAILED;
718e3744 3357
d62a17ae 3358 ret = peer_local_as_unset(peer);
3359 return bgp_vty_return(vty, ret);
718e3744 3360}
3361
718e3744 3362
3f9c7369
DS
3363DEFUN (neighbor_solo,
3364 neighbor_solo_cmd,
9ccf14f7 3365 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3366 NEIGHBOR_STR
3367 NEIGHBOR_ADDR_STR2
3368 "Solo peer - part of its own update group\n")
3369{
d62a17ae 3370 int idx_peer = 1;
3371 struct peer *peer;
3372 int ret;
3f9c7369 3373
d62a17ae 3374 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3375 if (!peer)
3376 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3377
d62a17ae 3378 ret = update_group_adjust_soloness(peer, 1);
3379 return bgp_vty_return(vty, ret);
3f9c7369
DS
3380}
3381
3382DEFUN (no_neighbor_solo,
3383 no_neighbor_solo_cmd,
9ccf14f7 3384 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3385 NO_STR
3386 NEIGHBOR_STR
3387 NEIGHBOR_ADDR_STR2
3388 "Solo peer - part of its own update group\n")
3389{
d62a17ae 3390 int idx_peer = 2;
3391 struct peer *peer;
3392 int ret;
3f9c7369 3393
d62a17ae 3394 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3395 if (!peer)
3396 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3397
d62a17ae 3398 ret = update_group_adjust_soloness(peer, 0);
3399 return bgp_vty_return(vty, ret);
3f9c7369
DS
3400}
3401
0df7c91f
PJ
3402DEFUN (neighbor_password,
3403 neighbor_password_cmd,
9ccf14f7 3404 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3405 NEIGHBOR_STR
3406 NEIGHBOR_ADDR_STR2
3407 "Set a password\n"
3408 "The password\n")
3409{
d62a17ae 3410 int idx_peer = 1;
3411 int idx_line = 3;
3412 struct peer *peer;
3413 int ret;
0df7c91f 3414
d62a17ae 3415 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3416 if (!peer)
3417 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3418
d62a17ae 3419 ret = peer_password_set(peer, argv[idx_line]->arg);
3420 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3421}
3422
3423DEFUN (no_neighbor_password,
3424 no_neighbor_password_cmd,
a636c635 3425 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3426 NO_STR
3427 NEIGHBOR_STR
3428 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3429 "Set a password\n"
3430 "The password\n")
0df7c91f 3431{
d62a17ae 3432 int idx_peer = 2;
3433 struct peer *peer;
3434 int ret;
0df7c91f 3435
d62a17ae 3436 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3437 if (!peer)
3438 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3439
d62a17ae 3440 ret = peer_password_unset(peer);
3441 return bgp_vty_return(vty, ret);
0df7c91f 3442}
6b0655a2 3443
718e3744 3444DEFUN (neighbor_activate,
3445 neighbor_activate_cmd,
9ccf14f7 3446 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3447 NEIGHBOR_STR
3448 NEIGHBOR_ADDR_STR2
3449 "Enable the Address Family for this Neighbor\n")
3450{
d62a17ae 3451 int idx_peer = 1;
3452 int ret;
3453 struct peer *peer;
718e3744 3454
d62a17ae 3455 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3456 if (!peer)
3457 return CMD_WARNING_CONFIG_FAILED;
718e3744 3458
d62a17ae 3459 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3460 return bgp_vty_return(vty, ret);
718e3744 3461}
3462
d62a17ae 3463ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3464 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3465 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3466 "Enable the Address Family for this Neighbor\n")
596c17ba 3467
718e3744 3468DEFUN (no_neighbor_activate,
3469 no_neighbor_activate_cmd,
9ccf14f7 3470 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3471 NO_STR
3472 NEIGHBOR_STR
3473 NEIGHBOR_ADDR_STR2
3474 "Enable the Address Family for this Neighbor\n")
3475{
d62a17ae 3476 int idx_peer = 2;
3477 int ret;
3478 struct peer *peer;
718e3744 3479
d62a17ae 3480 /* Lookup peer. */
3481 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3482 if (!peer)
3483 return CMD_WARNING_CONFIG_FAILED;
718e3744 3484
d62a17ae 3485 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3486 return bgp_vty_return(vty, ret);
718e3744 3487}
6b0655a2 3488
d62a17ae 3489ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3490 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3491 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3492 "Enable the Address Family for this Neighbor\n")
596c17ba 3493
718e3744 3494DEFUN (neighbor_set_peer_group,
3495 neighbor_set_peer_group_cmd,
d7b9898c 3496 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 3497 NEIGHBOR_STR
a80beece 3498 NEIGHBOR_ADDR_STR2
718e3744 3499 "Member of the peer-group\n"
16cedbb0 3500 "Peer-group name\n")
718e3744 3501{
d62a17ae 3502 VTY_DECLVAR_CONTEXT(bgp, bgp);
3503 int idx_peer = 1;
3504 int idx_word = 3;
3505 int ret;
3506 as_t as;
3507 union sockunion su;
3508 struct peer *peer;
3509 struct peer_group *group;
3510
d62a17ae 3511 ret = str2sockunion(argv[idx_peer]->arg, &su);
3512 if (ret < 0) {
3513 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3514 if (!peer) {
3515 vty_out(vty, "%% Malformed address or name: %s\n",
3516 argv[idx_peer]->arg);
3517 return CMD_WARNING_CONFIG_FAILED;
3518 }
3519 } else {
3520 if (peer_address_self_check(bgp, &su)) {
3521 vty_out(vty,
3522 "%% Can not configure the local system as neighbor\n");
3523 return CMD_WARNING_CONFIG_FAILED;
3524 }
3525
3526 /* Disallow for dynamic neighbor. */
3527 peer = peer_lookup(bgp, &su);
3528 if (peer && peer_dynamic_neighbor(peer)) {
3529 vty_out(vty,
3530 "%% Operation not allowed on a dynamic neighbor\n");
3531 return CMD_WARNING_CONFIG_FAILED;
3532 }
3533 }
3534
3535 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3536 if (!group) {
3537 vty_out(vty, "%% Configure the peer-group first\n");
3538 return CMD_WARNING_CONFIG_FAILED;
3539 }
3540
3541 ret = peer_group_bind(bgp, &su, peer, group, &as);
3542
3543 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3544 vty_out(vty,
3545 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3546 as);
3547 return CMD_WARNING_CONFIG_FAILED;
3548 }
3549
3550 return bgp_vty_return(vty, ret);
3551}
3552
3553ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 3554 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 3555 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3556 "Member of the peer-group\n"
3557 "Peer-group name\n")
596c17ba 3558
718e3744 3559DEFUN (no_neighbor_set_peer_group,
3560 no_neighbor_set_peer_group_cmd,
d7b9898c 3561 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 3562 NO_STR
3563 NEIGHBOR_STR
a80beece 3564 NEIGHBOR_ADDR_STR2
718e3744 3565 "Member of the peer-group\n"
16cedbb0 3566 "Peer-group name\n")
718e3744 3567{
d62a17ae 3568 VTY_DECLVAR_CONTEXT(bgp, bgp);
3569 int idx_peer = 2;
3570 int idx_word = 4;
3571 int ret;
3572 struct peer *peer;
3573 struct peer_group *group;
3574
3575 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3576 if (!peer)
3577 return CMD_WARNING_CONFIG_FAILED;
3578
3579 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3580 if (!group) {
3581 vty_out(vty, "%% Configure the peer-group first\n");
3582 return CMD_WARNING_CONFIG_FAILED;
3583 }
718e3744 3584
827ed707 3585 ret = peer_delete(peer);
718e3744 3586
d62a17ae 3587 return bgp_vty_return(vty, ret);
718e3744 3588}
6b0655a2 3589
d62a17ae 3590ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 3591 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 3592 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3593 "Member of the peer-group\n"
3594 "Peer-group name\n")
596c17ba 3595
d62a17ae 3596static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3597 uint32_t flag, int set)
718e3744 3598{
d62a17ae 3599 int ret;
3600 struct peer *peer;
718e3744 3601
d62a17ae 3602 peer = peer_and_group_lookup_vty(vty, ip_str);
3603 if (!peer)
3604 return CMD_WARNING_CONFIG_FAILED;
718e3744 3605
7ebe625c
QY
3606 /*
3607 * If 'neighbor <interface>', then this is for directly connected peers,
3608 * we should not accept disable-connected-check.
3609 */
3610 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3611 vty_out(vty,
3612 "%s is directly connected peer, cannot accept disable-"
3613 "connected-check\n",
3614 ip_str);
3615 return CMD_WARNING_CONFIG_FAILED;
3616 }
3617
d62a17ae 3618 if (!set && flag == PEER_FLAG_SHUTDOWN)
3619 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3620
d62a17ae 3621 if (set)
3622 ret = peer_flag_set(peer, flag);
3623 else
3624 ret = peer_flag_unset(peer, flag);
718e3744 3625
d62a17ae 3626 return bgp_vty_return(vty, ret);
718e3744 3627}
3628
47cbc09b 3629static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3630{
d62a17ae 3631 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3632}
3633
d62a17ae 3634static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3635 uint32_t flag)
718e3744 3636{
d62a17ae 3637 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3638}
3639
3640/* neighbor passive. */
3641DEFUN (neighbor_passive,
3642 neighbor_passive_cmd,
9ccf14f7 3643 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3644 NEIGHBOR_STR
3645 NEIGHBOR_ADDR_STR2
3646 "Don't send open messages to this neighbor\n")
3647{
d62a17ae 3648 int idx_peer = 1;
3649 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3650}
3651
3652DEFUN (no_neighbor_passive,
3653 no_neighbor_passive_cmd,
9ccf14f7 3654 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3655 NO_STR
3656 NEIGHBOR_STR
3657 NEIGHBOR_ADDR_STR2
3658 "Don't send open messages to this neighbor\n")
3659{
d62a17ae 3660 int idx_peer = 2;
3661 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3662}
6b0655a2 3663
718e3744 3664/* neighbor shutdown. */
73d70fa6
DL
3665DEFUN (neighbor_shutdown_msg,
3666 neighbor_shutdown_msg_cmd,
3667 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3668 NEIGHBOR_STR
3669 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3670 "Administratively shut down this neighbor\n"
3671 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3672 "Shutdown message\n")
718e3744 3673{
d62a17ae 3674 int idx_peer = 1;
73d70fa6 3675
d62a17ae 3676 if (argc >= 5) {
3677 struct peer *peer =
3678 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3679 char *message;
73d70fa6 3680
d62a17ae 3681 if (!peer)
3682 return CMD_WARNING_CONFIG_FAILED;
3683 message = argv_concat(argv, argc, 4);
3684 peer_tx_shutdown_message_set(peer, message);
3685 XFREE(MTYPE_TMP, message);
3686 }
73d70fa6 3687
d62a17ae 3688 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3689}
3690
d62a17ae 3691ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3692 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3693 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3694 "Administratively shut down this neighbor\n")
73d70fa6
DL
3695
3696DEFUN (no_neighbor_shutdown_msg,
3697 no_neighbor_shutdown_msg_cmd,
3698 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3699 NO_STR
3700 NEIGHBOR_STR
3701 NEIGHBOR_ADDR_STR2
3702 "Administratively shut down this neighbor\n"
3703 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3704 "Shutdown message\n")
718e3744 3705{
d62a17ae 3706 int idx_peer = 2;
73d70fa6 3707
d62a17ae 3708 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3709 PEER_FLAG_SHUTDOWN);
718e3744 3710}
6b0655a2 3711
d62a17ae 3712ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3713 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3714 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3715 "Administratively shut down this neighbor\n")
73d70fa6 3716
718e3744 3717/* neighbor capability dynamic. */
3718DEFUN (neighbor_capability_dynamic,
3719 neighbor_capability_dynamic_cmd,
9ccf14f7 3720 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3721 NEIGHBOR_STR
3722 NEIGHBOR_ADDR_STR2
3723 "Advertise capability to the peer\n"
3724 "Advertise dynamic capability to this neighbor\n")
3725{
d62a17ae 3726 int idx_peer = 1;
3727 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3728 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3729}
3730
3731DEFUN (no_neighbor_capability_dynamic,
3732 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3733 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3734 NO_STR
3735 NEIGHBOR_STR
3736 NEIGHBOR_ADDR_STR2
3737 "Advertise capability to the peer\n"
3738 "Advertise dynamic capability to this neighbor\n")
3739{
d62a17ae 3740 int idx_peer = 2;
3741 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3742 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3743}
6b0655a2 3744
718e3744 3745/* neighbor dont-capability-negotiate */
3746DEFUN (neighbor_dont_capability_negotiate,
3747 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3748 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3749 NEIGHBOR_STR
3750 NEIGHBOR_ADDR_STR2
3751 "Do not perform capability negotiation\n")
3752{
d62a17ae 3753 int idx_peer = 1;
3754 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3755 PEER_FLAG_DONT_CAPABILITY);
718e3744 3756}
3757
3758DEFUN (no_neighbor_dont_capability_negotiate,
3759 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3760 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3761 NO_STR
3762 NEIGHBOR_STR
3763 NEIGHBOR_ADDR_STR2
3764 "Do not perform capability negotiation\n")
3765{
d62a17ae 3766 int idx_peer = 2;
3767 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3768 PEER_FLAG_DONT_CAPABILITY);
718e3744 3769}
6b0655a2 3770
8a92a8a0
DS
3771/* neighbor capability extended next hop encoding */
3772DEFUN (neighbor_capability_enhe,
3773 neighbor_capability_enhe_cmd,
9ccf14f7 3774 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3775 NEIGHBOR_STR
3776 NEIGHBOR_ADDR_STR2
3777 "Advertise capability to the peer\n"
3778 "Advertise extended next-hop capability to the peer\n")
3779{
d62a17ae 3780 int idx_peer = 1;
3781 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3782 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3783}
3784
3785DEFUN (no_neighbor_capability_enhe,
3786 no_neighbor_capability_enhe_cmd,
9ccf14f7 3787 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3788 NO_STR
3789 NEIGHBOR_STR
3790 NEIGHBOR_ADDR_STR2
3791 "Advertise capability to the peer\n"
3792 "Advertise extended next-hop capability to the peer\n")
3793{
d62a17ae 3794 int idx_peer = 2;
3795 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3796 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3797}
3798
d62a17ae 3799static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3800 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3801 int set)
718e3744 3802{
d62a17ae 3803 int ret;
3804 struct peer *peer;
718e3744 3805
d62a17ae 3806 peer = peer_and_group_lookup_vty(vty, peer_str);
3807 if (!peer)
3808 return CMD_WARNING_CONFIG_FAILED;
718e3744 3809
d62a17ae 3810 if (set)
3811 ret = peer_af_flag_set(peer, afi, safi, flag);
3812 else
3813 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3814
d62a17ae 3815 return bgp_vty_return(vty, ret);
718e3744 3816}
3817
d62a17ae 3818static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3819 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3820{
d62a17ae 3821 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3822}
3823
d62a17ae 3824static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3825 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3826{
d62a17ae 3827 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3828}
6b0655a2 3829
718e3744 3830/* neighbor capability orf prefix-list. */
3831DEFUN (neighbor_capability_orf_prefix,
3832 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3833 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3834 NEIGHBOR_STR
3835 NEIGHBOR_ADDR_STR2
3836 "Advertise capability to the peer\n"
3837 "Advertise ORF capability to the peer\n"
3838 "Advertise prefixlist ORF capability to this neighbor\n"
3839 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3840 "Capability to RECEIVE the ORF from this neighbor\n"
3841 "Capability to SEND the ORF to this neighbor\n")
3842{
d62a17ae 3843 int idx_peer = 1;
3844 int idx_send_recv = 5;
d7c0a89a 3845 uint16_t flag = 0;
d62a17ae 3846
3847 if (strmatch(argv[idx_send_recv]->text, "send"))
3848 flag = PEER_FLAG_ORF_PREFIX_SM;
3849 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3850 flag = PEER_FLAG_ORF_PREFIX_RM;
3851 else if (strmatch(argv[idx_send_recv]->text, "both"))
3852 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3853 else {
3854 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3855 return CMD_WARNING_CONFIG_FAILED;
3856 }
3857
3858 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3859 bgp_node_safi(vty), flag);
3860}
3861
3862ALIAS_HIDDEN(
3863 neighbor_capability_orf_prefix,
3864 neighbor_capability_orf_prefix_hidden_cmd,
3865 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3866 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3867 "Advertise capability to the peer\n"
3868 "Advertise ORF capability to the peer\n"
3869 "Advertise prefixlist ORF capability to this neighbor\n"
3870 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3871 "Capability to RECEIVE the ORF from this neighbor\n"
3872 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3873
718e3744 3874DEFUN (no_neighbor_capability_orf_prefix,
3875 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3876 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3877 NO_STR
3878 NEIGHBOR_STR
3879 NEIGHBOR_ADDR_STR2
3880 "Advertise capability to the peer\n"
3881 "Advertise ORF capability to the peer\n"
3882 "Advertise prefixlist ORF capability to this neighbor\n"
3883 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3884 "Capability to RECEIVE the ORF from this neighbor\n"
3885 "Capability to SEND the ORF to this neighbor\n")
3886{
d62a17ae 3887 int idx_peer = 2;
3888 int idx_send_recv = 6;
d7c0a89a 3889 uint16_t flag = 0;
d62a17ae 3890
3891 if (strmatch(argv[idx_send_recv]->text, "send"))
3892 flag = PEER_FLAG_ORF_PREFIX_SM;
3893 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3894 flag = PEER_FLAG_ORF_PREFIX_RM;
3895 else if (strmatch(argv[idx_send_recv]->text, "both"))
3896 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3897 else {
3898 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3899 return CMD_WARNING_CONFIG_FAILED;
3900 }
3901
3902 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3903 bgp_node_afi(vty), bgp_node_safi(vty),
3904 flag);
3905}
3906
3907ALIAS_HIDDEN(
3908 no_neighbor_capability_orf_prefix,
3909 no_neighbor_capability_orf_prefix_hidden_cmd,
3910 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3911 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3912 "Advertise capability to the peer\n"
3913 "Advertise ORF capability to the peer\n"
3914 "Advertise prefixlist ORF capability to this neighbor\n"
3915 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3916 "Capability to RECEIVE the ORF from this neighbor\n"
3917 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3918
718e3744 3919/* neighbor next-hop-self. */
3920DEFUN (neighbor_nexthop_self,
3921 neighbor_nexthop_self_cmd,
9ccf14f7 3922 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3923 NEIGHBOR_STR
3924 NEIGHBOR_ADDR_STR2
a538debe 3925 "Disable the next hop calculation for this neighbor\n")
718e3744 3926{
d62a17ae 3927 int idx_peer = 1;
3928 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3929 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3930}
9e7a53c1 3931
d62a17ae 3932ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3933 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3934 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3935 "Disable the next hop calculation for this neighbor\n")
596c17ba 3936
a538debe
DS
3937/* neighbor next-hop-self. */
3938DEFUN (neighbor_nexthop_self_force,
3939 neighbor_nexthop_self_force_cmd,
9ccf14f7 3940 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3941 NEIGHBOR_STR
3942 NEIGHBOR_ADDR_STR2
3943 "Disable the next hop calculation for this neighbor\n"
3944 "Set the next hop to self for reflected routes\n")
3945{
d62a17ae 3946 int idx_peer = 1;
3947 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3948 bgp_node_safi(vty),
3949 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3950}
3951
d62a17ae 3952ALIAS_HIDDEN(neighbor_nexthop_self_force,
3953 neighbor_nexthop_self_force_hidden_cmd,
3954 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3955 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3956 "Disable the next hop calculation for this neighbor\n"
3957 "Set the next hop to self for reflected routes\n")
596c17ba 3958
1bc4e531
DA
3959ALIAS_HIDDEN(neighbor_nexthop_self_force,
3960 neighbor_nexthop_self_all_hidden_cmd,
3961 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3962 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3963 "Disable the next hop calculation for this neighbor\n"
3964 "Set the next hop to self for reflected routes\n")
3965
718e3744 3966DEFUN (no_neighbor_nexthop_self,
3967 no_neighbor_nexthop_self_cmd,
9ccf14f7 3968 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3969 NO_STR
3970 NEIGHBOR_STR
3971 NEIGHBOR_ADDR_STR2
a538debe 3972 "Disable the next hop calculation for this neighbor\n")
718e3744 3973{
d62a17ae 3974 int idx_peer = 2;
3975 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3976 bgp_node_afi(vty), bgp_node_safi(vty),
3977 PEER_FLAG_NEXTHOP_SELF);
718e3744 3978}
6b0655a2 3979
d62a17ae 3980ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3981 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3982 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3983 "Disable the next hop calculation for this neighbor\n")
596c17ba 3984
88b8ed8d 3985DEFUN (no_neighbor_nexthop_self_force,
a538debe 3986 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3987 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3988 NO_STR
3989 NEIGHBOR_STR
3990 NEIGHBOR_ADDR_STR2
3991 "Disable the next hop calculation for this neighbor\n"
3992 "Set the next hop to self for reflected routes\n")
88b8ed8d 3993{
d62a17ae 3994 int idx_peer = 2;
3995 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3996 bgp_node_afi(vty), bgp_node_safi(vty),
3997 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3998}
a538debe 3999
d62a17ae 4000ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4001 no_neighbor_nexthop_self_force_hidden_cmd,
4002 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4003 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4004 "Disable the next hop calculation for this neighbor\n"
4005 "Set the next hop to self for reflected routes\n")
596c17ba 4006
1bc4e531
DA
4007ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4008 no_neighbor_nexthop_self_all_hidden_cmd,
4009 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4010 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4011 "Disable the next hop calculation for this neighbor\n"
4012 "Set the next hop to self for reflected routes\n")
4013
c7122e14
DS
4014/* neighbor as-override */
4015DEFUN (neighbor_as_override,
4016 neighbor_as_override_cmd,
9ccf14f7 4017 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4018 NEIGHBOR_STR
4019 NEIGHBOR_ADDR_STR2
4020 "Override ASNs in outbound updates if aspath equals remote-as\n")
4021{
d62a17ae 4022 int idx_peer = 1;
4023 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4024 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4025}
4026
d62a17ae 4027ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4028 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4029 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4030 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4031
c7122e14
DS
4032DEFUN (no_neighbor_as_override,
4033 no_neighbor_as_override_cmd,
9ccf14f7 4034 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4035 NO_STR
4036 NEIGHBOR_STR
4037 NEIGHBOR_ADDR_STR2
4038 "Override ASNs in outbound updates if aspath equals remote-as\n")
4039{
d62a17ae 4040 int idx_peer = 2;
4041 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4042 bgp_node_afi(vty), bgp_node_safi(vty),
4043 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4044}
4045
d62a17ae 4046ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4047 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4048 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4049 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4050
718e3744 4051/* neighbor remove-private-AS. */
4052DEFUN (neighbor_remove_private_as,
4053 neighbor_remove_private_as_cmd,
9ccf14f7 4054 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4055 NEIGHBOR_STR
4056 NEIGHBOR_ADDR_STR2
5000f21c 4057 "Remove private ASNs in outbound updates\n")
718e3744 4058{
d62a17ae 4059 int idx_peer = 1;
4060 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4061 bgp_node_safi(vty),
4062 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4063}
4064
d62a17ae 4065ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4066 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4067 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4068 "Remove private ASNs in outbound updates\n")
596c17ba 4069
5000f21c
DS
4070DEFUN (neighbor_remove_private_as_all,
4071 neighbor_remove_private_as_all_cmd,
9ccf14f7 4072 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4073 NEIGHBOR_STR
4074 NEIGHBOR_ADDR_STR2
4075 "Remove private ASNs in outbound updates\n"
efd7904e 4076 "Apply to all AS numbers\n")
5000f21c 4077{
d62a17ae 4078 int idx_peer = 1;
4079 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4080 bgp_node_safi(vty),
4081 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
4082}
4083
d62a17ae 4084ALIAS_HIDDEN(neighbor_remove_private_as_all,
4085 neighbor_remove_private_as_all_hidden_cmd,
4086 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4087 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4088 "Remove private ASNs in outbound updates\n"
4089 "Apply to all AS numbers")
596c17ba 4090
5000f21c
DS
4091DEFUN (neighbor_remove_private_as_replace_as,
4092 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4093 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4094 NEIGHBOR_STR
4095 NEIGHBOR_ADDR_STR2
4096 "Remove private ASNs in outbound updates\n"
4097 "Replace private ASNs with our ASN in outbound updates\n")
4098{
d62a17ae 4099 int idx_peer = 1;
4100 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4101 bgp_node_safi(vty),
4102 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
4103}
4104
d62a17ae 4105ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4106 neighbor_remove_private_as_replace_as_hidden_cmd,
4107 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4108 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4109 "Remove private ASNs in outbound updates\n"
4110 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4111
5000f21c
DS
4112DEFUN (neighbor_remove_private_as_all_replace_as,
4113 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4114 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4115 NEIGHBOR_STR
4116 NEIGHBOR_ADDR_STR2
4117 "Remove private ASNs in outbound updates\n"
16cedbb0 4118 "Apply to all AS numbers\n"
5000f21c
DS
4119 "Replace private ASNs with our ASN in outbound updates\n")
4120{
d62a17ae 4121 int idx_peer = 1;
4122 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4123 bgp_node_safi(vty),
4124 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4125}
4126
d62a17ae 4127ALIAS_HIDDEN(
4128 neighbor_remove_private_as_all_replace_as,
4129 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4130 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4131 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4132 "Remove private ASNs in outbound updates\n"
4133 "Apply to all AS numbers\n"
4134 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4135
718e3744 4136DEFUN (no_neighbor_remove_private_as,
4137 no_neighbor_remove_private_as_cmd,
9ccf14f7 4138 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4139 NO_STR
4140 NEIGHBOR_STR
4141 NEIGHBOR_ADDR_STR2
5000f21c 4142 "Remove private ASNs in outbound updates\n")
718e3744 4143{
d62a17ae 4144 int idx_peer = 2;
4145 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4146 bgp_node_afi(vty), bgp_node_safi(vty),
4147 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4148}
6b0655a2 4149
d62a17ae 4150ALIAS_HIDDEN(no_neighbor_remove_private_as,
4151 no_neighbor_remove_private_as_hidden_cmd,
4152 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4153 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4154 "Remove private ASNs in outbound updates\n")
596c17ba 4155
88b8ed8d 4156DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4157 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4158 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4159 NO_STR
4160 NEIGHBOR_STR
4161 NEIGHBOR_ADDR_STR2
4162 "Remove private ASNs in outbound updates\n"
16cedbb0 4163 "Apply to all AS numbers\n")
88b8ed8d 4164{
d62a17ae 4165 int idx_peer = 2;
4166 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4167 bgp_node_afi(vty), bgp_node_safi(vty),
4168 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4169}
5000f21c 4170
d62a17ae 4171ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4172 no_neighbor_remove_private_as_all_hidden_cmd,
4173 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4174 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4175 "Remove private ASNs in outbound updates\n"
4176 "Apply to all AS numbers\n")
596c17ba 4177
88b8ed8d 4178DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4179 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4180 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4181 NO_STR
4182 NEIGHBOR_STR
4183 NEIGHBOR_ADDR_STR2
4184 "Remove private ASNs in outbound updates\n"
4185 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4186{
d62a17ae 4187 int idx_peer = 2;
4188 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4189 bgp_node_afi(vty), bgp_node_safi(vty),
4190 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4191}
5000f21c 4192
d62a17ae 4193ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4194 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4195 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4196 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4197 "Remove private ASNs in outbound updates\n"
4198 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4199
88b8ed8d 4200DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4201 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4202 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4203 NO_STR
4204 NEIGHBOR_STR
4205 NEIGHBOR_ADDR_STR2
4206 "Remove private ASNs in outbound updates\n"
16cedbb0 4207 "Apply to all AS numbers\n"
5000f21c 4208 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4209{
d62a17ae 4210 int idx_peer = 2;
4211 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4212 bgp_node_afi(vty), bgp_node_safi(vty),
4213 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4214}
5000f21c 4215
d62a17ae 4216ALIAS_HIDDEN(
4217 no_neighbor_remove_private_as_all_replace_as,
4218 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4219 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4220 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4221 "Remove private ASNs in outbound updates\n"
4222 "Apply to all AS numbers\n"
4223 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4224
5000f21c 4225
718e3744 4226/* neighbor send-community. */
4227DEFUN (neighbor_send_community,
4228 neighbor_send_community_cmd,
9ccf14f7 4229 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4230 NEIGHBOR_STR
4231 NEIGHBOR_ADDR_STR2
4232 "Send Community attribute to this neighbor\n")
4233{
d62a17ae 4234 int idx_peer = 1;
27c05d4d 4235
d62a17ae 4236 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4237 bgp_node_safi(vty),
4238 PEER_FLAG_SEND_COMMUNITY);
718e3744 4239}
4240
d62a17ae 4241ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4242 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4243 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4244 "Send Community attribute to this neighbor\n")
596c17ba 4245
718e3744 4246DEFUN (no_neighbor_send_community,
4247 no_neighbor_send_community_cmd,
9ccf14f7 4248 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4249 NO_STR
4250 NEIGHBOR_STR
4251 NEIGHBOR_ADDR_STR2
4252 "Send Community attribute to this neighbor\n")
4253{
d62a17ae 4254 int idx_peer = 2;
27c05d4d 4255
d62a17ae 4256 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4257 bgp_node_afi(vty), bgp_node_safi(vty),
4258 PEER_FLAG_SEND_COMMUNITY);
718e3744 4259}
6b0655a2 4260
d62a17ae 4261ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4262 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4263 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4264 "Send Community attribute to this neighbor\n")
596c17ba 4265
718e3744 4266/* neighbor send-community extended. */
4267DEFUN (neighbor_send_community_type,
4268 neighbor_send_community_type_cmd,
57d187bc 4269 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4270 NEIGHBOR_STR
4271 NEIGHBOR_ADDR_STR2
4272 "Send Community attribute to this neighbor\n"
4273 "Send Standard and Extended Community attributes\n"
57d187bc 4274 "Send Standard, Large and Extended Community attributes\n"
718e3744 4275 "Send Extended Community attributes\n"
57d187bc
JS
4276 "Send Standard Community attributes\n"
4277 "Send Large Community attributes\n")
718e3744 4278{
27c05d4d 4279 int idx_peer = 1;
d7c0a89a 4280 uint32_t flag = 0;
27c05d4d 4281 const char *type = argv[argc - 1]->text;
d62a17ae 4282
27c05d4d 4283 if (strmatch(type, "standard")) {
d62a17ae 4284 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4285 } else if (strmatch(type, "extended")) {
d62a17ae 4286 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4287 } else if (strmatch(type, "large")) {
d62a17ae 4288 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4289 } else if (strmatch(type, "both")) {
d62a17ae 4290 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4291 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4292 } else { /* if (strmatch(type, "all")) */
d62a17ae 4293 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4294 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4295 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4296 }
4297
27c05d4d 4298 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4299 bgp_node_safi(vty), flag);
4300}
4301
4302ALIAS_HIDDEN(
4303 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4304 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4305 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4306 "Send Community attribute to this neighbor\n"
4307 "Send Standard and Extended Community attributes\n"
4308 "Send Standard, Large and Extended Community attributes\n"
4309 "Send Extended Community attributes\n"
4310 "Send Standard Community attributes\n"
4311 "Send Large Community attributes\n")
596c17ba 4312
718e3744 4313DEFUN (no_neighbor_send_community_type,
4314 no_neighbor_send_community_type_cmd,
57d187bc 4315 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4316 NO_STR
4317 NEIGHBOR_STR
4318 NEIGHBOR_ADDR_STR2
4319 "Send Community attribute to this neighbor\n"
4320 "Send Standard and Extended Community attributes\n"
57d187bc 4321 "Send Standard, Large and Extended Community attributes\n"
718e3744 4322 "Send Extended Community attributes\n"
57d187bc
JS
4323 "Send Standard Community attributes\n"
4324 "Send Large Community attributes\n")
718e3744 4325{
d62a17ae 4326 int idx_peer = 2;
27c05d4d 4327 uint32_t flag = 0;
d62a17ae 4328 const char *type = argv[argc - 1]->text;
4329
27c05d4d
PM
4330 if (strmatch(type, "standard")) {
4331 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4332 } else if (strmatch(type, "extended")) {
4333 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4334 } else if (strmatch(type, "large")) {
4335 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4336 } else if (strmatch(type, "both")) {
4337 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4338 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4339 } else { /* if (strmatch(type, "all")) */
4340 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4341 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4342 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4343 }
4344
4345 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4346 bgp_node_afi(vty), bgp_node_safi(vty),
4347 flag);
d62a17ae 4348}
4349
4350ALIAS_HIDDEN(
4351 no_neighbor_send_community_type,
4352 no_neighbor_send_community_type_hidden_cmd,
4353 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4354 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4355 "Send Community attribute to this neighbor\n"
4356 "Send Standard and Extended Community attributes\n"
4357 "Send Standard, Large and Extended Community attributes\n"
4358 "Send Extended Community attributes\n"
4359 "Send Standard Community attributes\n"
4360 "Send Large Community attributes\n")
596c17ba 4361
718e3744 4362/* neighbor soft-reconfig. */
4363DEFUN (neighbor_soft_reconfiguration,
4364 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4365 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4366 NEIGHBOR_STR
4367 NEIGHBOR_ADDR_STR2
4368 "Per neighbor soft reconfiguration\n"
4369 "Allow inbound soft reconfiguration for this neighbor\n")
4370{
d62a17ae 4371 int idx_peer = 1;
4372 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4373 bgp_node_safi(vty),
4374 PEER_FLAG_SOFT_RECONFIG);
718e3744 4375}
4376
d62a17ae 4377ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4378 neighbor_soft_reconfiguration_hidden_cmd,
4379 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4380 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4381 "Per neighbor soft reconfiguration\n"
4382 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4383
718e3744 4384DEFUN (no_neighbor_soft_reconfiguration,
4385 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4386 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4387 NO_STR
4388 NEIGHBOR_STR
4389 NEIGHBOR_ADDR_STR2
4390 "Per neighbor soft reconfiguration\n"
4391 "Allow inbound soft reconfiguration for this neighbor\n")
4392{
d62a17ae 4393 int idx_peer = 2;
4394 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4395 bgp_node_afi(vty), bgp_node_safi(vty),
4396 PEER_FLAG_SOFT_RECONFIG);
718e3744 4397}
6b0655a2 4398
d62a17ae 4399ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4400 no_neighbor_soft_reconfiguration_hidden_cmd,
4401 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4402 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4403 "Per neighbor soft reconfiguration\n"
4404 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4405
718e3744 4406DEFUN (neighbor_route_reflector_client,
4407 neighbor_route_reflector_client_cmd,
9ccf14f7 4408 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4409 NEIGHBOR_STR
4410 NEIGHBOR_ADDR_STR2
4411 "Configure a neighbor as Route Reflector client\n")
4412{
d62a17ae 4413 int idx_peer = 1;
4414 struct peer *peer;
718e3744 4415
4416
d62a17ae 4417 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4418 if (!peer)
4419 return CMD_WARNING_CONFIG_FAILED;
718e3744 4420
d62a17ae 4421 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4422 bgp_node_safi(vty),
4423 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4424}
4425
d62a17ae 4426ALIAS_HIDDEN(neighbor_route_reflector_client,
4427 neighbor_route_reflector_client_hidden_cmd,
4428 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4429 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4430 "Configure a neighbor as Route Reflector client\n")
596c17ba 4431
718e3744 4432DEFUN (no_neighbor_route_reflector_client,
4433 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4434 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4435 NO_STR
4436 NEIGHBOR_STR
4437 NEIGHBOR_ADDR_STR2
4438 "Configure a neighbor as Route Reflector client\n")
4439{
d62a17ae 4440 int idx_peer = 2;
4441 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4442 bgp_node_afi(vty), bgp_node_safi(vty),
4443 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4444}
6b0655a2 4445
d62a17ae 4446ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4447 no_neighbor_route_reflector_client_hidden_cmd,
4448 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4449 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4450 "Configure a neighbor as Route Reflector client\n")
596c17ba 4451
718e3744 4452/* neighbor route-server-client. */
4453DEFUN (neighbor_route_server_client,
4454 neighbor_route_server_client_cmd,
9ccf14f7 4455 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4456 NEIGHBOR_STR
4457 NEIGHBOR_ADDR_STR2
4458 "Configure a neighbor as Route Server client\n")
4459{
d62a17ae 4460 int idx_peer = 1;
4461 struct peer *peer;
2a3d5731 4462
d62a17ae 4463 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4464 if (!peer)
4465 return CMD_WARNING_CONFIG_FAILED;
4466 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4467 bgp_node_safi(vty),
4468 PEER_FLAG_RSERVER_CLIENT);
718e3744 4469}
4470
d62a17ae 4471ALIAS_HIDDEN(neighbor_route_server_client,
4472 neighbor_route_server_client_hidden_cmd,
4473 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4474 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4475 "Configure a neighbor as Route Server client\n")
596c17ba 4476
718e3744 4477DEFUN (no_neighbor_route_server_client,
4478 no_neighbor_route_server_client_cmd,
9ccf14f7 4479 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4480 NO_STR
4481 NEIGHBOR_STR
4482 NEIGHBOR_ADDR_STR2
4483 "Configure a neighbor as Route Server client\n")
fee0f4c6 4484{
d62a17ae 4485 int idx_peer = 2;
4486 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4487 bgp_node_afi(vty), bgp_node_safi(vty),
4488 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4489}
6b0655a2 4490
d62a17ae 4491ALIAS_HIDDEN(no_neighbor_route_server_client,
4492 no_neighbor_route_server_client_hidden_cmd,
4493 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4494 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4495 "Configure a neighbor as Route Server client\n")
596c17ba 4496
fee0f4c6 4497DEFUN (neighbor_nexthop_local_unchanged,
4498 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4499 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4500 NEIGHBOR_STR
4501 NEIGHBOR_ADDR_STR2
4502 "Configure treatment of outgoing link-local nexthop attribute\n"
4503 "Leave link-local nexthop unchanged for this peer\n")
4504{
d62a17ae 4505 int idx_peer = 1;
4506 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4507 bgp_node_safi(vty),
4508 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4509}
6b0655a2 4510
fee0f4c6 4511DEFUN (no_neighbor_nexthop_local_unchanged,
4512 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4513 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4514 NO_STR
4515 NEIGHBOR_STR
4516 NEIGHBOR_ADDR_STR2
4517 "Configure treatment of outgoing link-local-nexthop attribute\n"
4518 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4519{
d62a17ae 4520 int idx_peer = 2;
4521 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4522 bgp_node_afi(vty), bgp_node_safi(vty),
4523 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4524}
6b0655a2 4525
718e3744 4526DEFUN (neighbor_attr_unchanged,
4527 neighbor_attr_unchanged_cmd,
a8206004 4528 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4529 NEIGHBOR_STR
4530 NEIGHBOR_ADDR_STR2
4531 "BGP attribute is propagated unchanged to this neighbor\n"
4532 "As-path attribute\n"
4533 "Nexthop attribute\n"
a8206004 4534 "Med attribute\n")
718e3744 4535{
d62a17ae 4536 int idx = 0;
8eeb0335
DW
4537 char *peer_str = argv[1]->arg;
4538 struct peer *peer;
d7c0a89a 4539 uint16_t flags = 0;
8eeb0335
DW
4540 afi_t afi = bgp_node_afi(vty);
4541 safi_t safi = bgp_node_safi(vty);
4542
4543 peer = peer_and_group_lookup_vty(vty, peer_str);
4544 if (!peer)
4545 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4546
4547 if (argv_find(argv, argc, "as-path", &idx))
4548 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4549 idx = 0;
4550 if (argv_find(argv, argc, "next-hop", &idx))
4551 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4552 idx = 0;
4553 if (argv_find(argv, argc, "med", &idx))
4554 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4555
8eeb0335
DW
4556 /* no flags means all of them! */
4557 if (!flags) {
d62a17ae 4558 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4559 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4560 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4561 } else {
a4d82a8a
PZ
4562 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4563 && peer_af_flag_check(peer, afi, safi,
4564 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4565 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4566 PEER_FLAG_AS_PATH_UNCHANGED);
4567 }
4568
a4d82a8a
PZ
4569 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4570 && peer_af_flag_check(peer, afi, safi,
4571 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4572 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4573 PEER_FLAG_NEXTHOP_UNCHANGED);
4574 }
4575
a4d82a8a
PZ
4576 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4577 && peer_af_flag_check(peer, afi, safi,
4578 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4579 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4580 PEER_FLAG_MED_UNCHANGED);
4581 }
d62a17ae 4582 }
4583
8eeb0335 4584 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4585}
4586
4587ALIAS_HIDDEN(
4588 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4589 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4590 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4591 "BGP attribute is propagated unchanged to this neighbor\n"
4592 "As-path attribute\n"
4593 "Nexthop attribute\n"
4594 "Med attribute\n")
596c17ba 4595
718e3744 4596DEFUN (no_neighbor_attr_unchanged,
4597 no_neighbor_attr_unchanged_cmd,
a8206004 4598 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4599 NO_STR
718e3744 4600 NEIGHBOR_STR
4601 NEIGHBOR_ADDR_STR2
31500417
DW
4602 "BGP attribute is propagated unchanged to this neighbor\n"
4603 "As-path attribute\n"
40e718b5 4604 "Nexthop attribute\n"
a8206004 4605 "Med attribute\n")
718e3744 4606{
d62a17ae 4607 int idx = 0;
4608 char *peer = argv[2]->arg;
d7c0a89a 4609 uint16_t flags = 0;
d62a17ae 4610
4611 if (argv_find(argv, argc, "as-path", &idx))
4612 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4613 idx = 0;
4614 if (argv_find(argv, argc, "next-hop", &idx))
4615 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4616 idx = 0;
4617 if (argv_find(argv, argc, "med", &idx))
4618 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4619
4620 if (!flags) // no flags means all of them!
4621 {
4622 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4623 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4624 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4625 }
4626
4627 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4628 bgp_node_safi(vty), flags);
4629}
4630
4631ALIAS_HIDDEN(
4632 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4633 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4634 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4635 "BGP attribute is propagated unchanged to this neighbor\n"
4636 "As-path attribute\n"
4637 "Nexthop attribute\n"
4638 "Med attribute\n")
718e3744 4639
718e3744 4640/* EBGP multihop configuration. */
d62a17ae 4641static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4642 const char *ttl_str)
718e3744 4643{
d62a17ae 4644 struct peer *peer;
4645 unsigned int ttl;
718e3744 4646
d62a17ae 4647 peer = peer_and_group_lookup_vty(vty, ip_str);
4648 if (!peer)
4649 return CMD_WARNING_CONFIG_FAILED;
718e3744 4650
d62a17ae 4651 if (peer->conf_if)
4652 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4653
d62a17ae 4654 if (!ttl_str)
4655 ttl = MAXTTL;
4656 else
4657 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4658
d62a17ae 4659 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4660}
4661
d62a17ae 4662static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4663{
d62a17ae 4664 struct peer *peer;
718e3744 4665
d62a17ae 4666 peer = peer_and_group_lookup_vty(vty, ip_str);
4667 if (!peer)
4668 return CMD_WARNING_CONFIG_FAILED;
718e3744 4669
d62a17ae 4670 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4671}
4672
4673/* neighbor ebgp-multihop. */
4674DEFUN (neighbor_ebgp_multihop,
4675 neighbor_ebgp_multihop_cmd,
9ccf14f7 4676 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4677 NEIGHBOR_STR
4678 NEIGHBOR_ADDR_STR2
4679 "Allow EBGP neighbors not on directly connected networks\n")
4680{
d62a17ae 4681 int idx_peer = 1;
4682 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4683}
4684
4685DEFUN (neighbor_ebgp_multihop_ttl,
4686 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4687 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4688 NEIGHBOR_STR
4689 NEIGHBOR_ADDR_STR2
4690 "Allow EBGP neighbors not on directly connected networks\n"
4691 "maximum hop count\n")
4692{
d62a17ae 4693 int idx_peer = 1;
4694 int idx_number = 3;
4695 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4696 argv[idx_number]->arg);
718e3744 4697}
4698
4699DEFUN (no_neighbor_ebgp_multihop,
4700 no_neighbor_ebgp_multihop_cmd,
a636c635 4701 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4702 NO_STR
4703 NEIGHBOR_STR
4704 NEIGHBOR_ADDR_STR2
a636c635
DW
4705 "Allow EBGP neighbors not on directly connected networks\n"
4706 "maximum hop count\n")
718e3744 4707{
d62a17ae 4708 int idx_peer = 2;
4709 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4710}
4711
6b0655a2 4712
6ffd2079 4713/* disable-connected-check */
4714DEFUN (neighbor_disable_connected_check,
4715 neighbor_disable_connected_check_cmd,
7ebe625c 4716 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4717 NEIGHBOR_STR
7ebe625c 4718 NEIGHBOR_ADDR_STR2
a636c635
DW
4719 "one-hop away EBGP peer using loopback address\n"
4720 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4721{
d62a17ae 4722 int idx_peer = 1;
4723 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4724 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4725}
4726
4727DEFUN (no_neighbor_disable_connected_check,
4728 no_neighbor_disable_connected_check_cmd,
7ebe625c 4729 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4730 NO_STR
4731 NEIGHBOR_STR
7ebe625c 4732 NEIGHBOR_ADDR_STR2
a636c635
DW
4733 "one-hop away EBGP peer using loopback address\n"
4734 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4735{
d62a17ae 4736 int idx_peer = 2;
4737 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4738 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4739}
4740
47cbc09b
PM
4741
4742/* enforce-first-as */
4743DEFUN (neighbor_enforce_first_as,
4744 neighbor_enforce_first_as_cmd,
4745 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4746 NEIGHBOR_STR
4747 NEIGHBOR_ADDR_STR2
4748 "Enforce the first AS for EBGP routes\n")
4749{
4750 int idx_peer = 1;
4751
4752 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4753 PEER_FLAG_ENFORCE_FIRST_AS);
4754}
4755
4756DEFUN (no_neighbor_enforce_first_as,
4757 no_neighbor_enforce_first_as_cmd,
4758 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4759 NO_STR
4760 NEIGHBOR_STR
4761 NEIGHBOR_ADDR_STR2
4762 "Enforce the first AS for EBGP routes\n")
4763{
4764 int idx_peer = 2;
4765
4766 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4767 PEER_FLAG_ENFORCE_FIRST_AS);
4768}
4769
4770
718e3744 4771DEFUN (neighbor_description,
4772 neighbor_description_cmd,
e961923c 4773 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4774 NEIGHBOR_STR
4775 NEIGHBOR_ADDR_STR2
4776 "Neighbor specific description\n"
4777 "Up to 80 characters describing this neighbor\n")
4778{
d62a17ae 4779 int idx_peer = 1;
4780 int idx_line = 3;
4781 struct peer *peer;
4782 char *str;
718e3744 4783
d62a17ae 4784 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4785 if (!peer)
4786 return CMD_WARNING_CONFIG_FAILED;
718e3744 4787
d62a17ae 4788 str = argv_concat(argv, argc, idx_line);
718e3744 4789
d62a17ae 4790 peer_description_set(peer, str);
718e3744 4791
d62a17ae 4792 XFREE(MTYPE_TMP, str);
718e3744 4793
d62a17ae 4794 return CMD_SUCCESS;
718e3744 4795}
4796
4797DEFUN (no_neighbor_description,
4798 no_neighbor_description_cmd,
a14810f4 4799 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4800 NO_STR
4801 NEIGHBOR_STR
4802 NEIGHBOR_ADDR_STR2
a14810f4 4803 "Neighbor specific description\n")
718e3744 4804{
d62a17ae 4805 int idx_peer = 2;
4806 struct peer *peer;
718e3744 4807
d62a17ae 4808 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4809 if (!peer)
4810 return CMD_WARNING_CONFIG_FAILED;
718e3744 4811
d62a17ae 4812 peer_description_unset(peer);
718e3744 4813
d62a17ae 4814 return CMD_SUCCESS;
718e3744 4815}
4816
a14810f4
PM
4817ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4818 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4819 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4820 "Neighbor specific description\n"
4821 "Up to 80 characters describing this neighbor\n")
6b0655a2 4822
718e3744 4823/* Neighbor update-source. */
d62a17ae 4824static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4825 const char *source_str)
4826{
4827 struct peer *peer;
4828 struct prefix p;
a14810f4 4829 union sockunion su;
d62a17ae 4830
4831 peer = peer_and_group_lookup_vty(vty, peer_str);
4832 if (!peer)
4833 return CMD_WARNING_CONFIG_FAILED;
4834
4835 if (peer->conf_if)
4836 return CMD_WARNING;
4837
4838 if (source_str) {
a14810f4 4839 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4840 peer_update_source_addr_set(peer, &su);
4841 else {
4842 if (str2prefix(source_str, &p)) {
4843 vty_out(vty,
4844 "%% Invalid update-source, remove prefix length \n");
4845 return CMD_WARNING_CONFIG_FAILED;
4846 } else
4847 peer_update_source_if_set(peer, source_str);
4848 }
4849 } else
4850 peer_update_source_unset(peer);
4851
4852 return CMD_SUCCESS;
4853}
4854
4855#define BGP_UPDATE_SOURCE_HELP_STR \
4856 "IPv4 address\n" \
4857 "IPv6 address\n" \
4858 "Interface name (requires zebra to be running)\n"
369688c0 4859
718e3744 4860DEFUN (neighbor_update_source,
4861 neighbor_update_source_cmd,
9ccf14f7 4862 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4863 NEIGHBOR_STR
4864 NEIGHBOR_ADDR_STR2
4865 "Source of routing updates\n"
369688c0 4866 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4867{
d62a17ae 4868 int idx_peer = 1;
4869 int idx_peer_2 = 3;
4870 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4871 argv[idx_peer_2]->arg);
718e3744 4872}
4873
4874DEFUN (no_neighbor_update_source,
4875 no_neighbor_update_source_cmd,
c7178fe7 4876 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4877 NO_STR
4878 NEIGHBOR_STR
4879 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4880 "Source of routing updates\n"
4881 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4882{
d62a17ae 4883 int idx_peer = 2;
4884 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4885}
6b0655a2 4886
d62a17ae 4887static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4888 afi_t afi, safi_t safi,
4889 const char *rmap, int set)
718e3744 4890{
d62a17ae 4891 int ret;
4892 struct peer *peer;
80912664 4893 struct route_map *route_map = NULL;
718e3744 4894
d62a17ae 4895 peer = peer_and_group_lookup_vty(vty, peer_str);
4896 if (!peer)
4897 return CMD_WARNING_CONFIG_FAILED;
718e3744 4898
1de27621 4899 if (set) {
80912664
DS
4900 if (rmap)
4901 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
4902 ret = peer_default_originate_set(peer, afi, safi,
4903 rmap, route_map);
4904 } else
d62a17ae 4905 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4906
d62a17ae 4907 return bgp_vty_return(vty, ret);
718e3744 4908}
4909
4910/* neighbor default-originate. */
4911DEFUN (neighbor_default_originate,
4912 neighbor_default_originate_cmd,
9ccf14f7 4913 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4914 NEIGHBOR_STR
4915 NEIGHBOR_ADDR_STR2
4916 "Originate default route to this neighbor\n")
4917{
d62a17ae 4918 int idx_peer = 1;
4919 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4920 bgp_node_afi(vty),
4921 bgp_node_safi(vty), NULL, 1);
718e3744 4922}
4923
d62a17ae 4924ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4925 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4926 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4927 "Originate default route to this neighbor\n")
596c17ba 4928
718e3744 4929DEFUN (neighbor_default_originate_rmap,
4930 neighbor_default_originate_rmap_cmd,
9ccf14f7 4931 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4932 NEIGHBOR_STR
4933 NEIGHBOR_ADDR_STR2
4934 "Originate default route to this neighbor\n"
4935 "Route-map to specify criteria to originate default\n"
4936 "route-map name\n")
4937{
d62a17ae 4938 int idx_peer = 1;
4939 int idx_word = 4;
4940 return peer_default_originate_set_vty(
4941 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4942 argv[idx_word]->arg, 1);
718e3744 4943}
4944
d62a17ae 4945ALIAS_HIDDEN(
4946 neighbor_default_originate_rmap,
4947 neighbor_default_originate_rmap_hidden_cmd,
4948 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4949 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4950 "Originate default route to this neighbor\n"
4951 "Route-map to specify criteria to originate default\n"
4952 "route-map name\n")
596c17ba 4953
718e3744 4954DEFUN (no_neighbor_default_originate,
4955 no_neighbor_default_originate_cmd,
a636c635 4956 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4957 NO_STR
4958 NEIGHBOR_STR
4959 NEIGHBOR_ADDR_STR2
a636c635
DW
4960 "Originate default route to this neighbor\n"
4961 "Route-map to specify criteria to originate default\n"
4962 "route-map name\n")
718e3744 4963{
d62a17ae 4964 int idx_peer = 2;
4965 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4966 bgp_node_afi(vty),
4967 bgp_node_safi(vty), NULL, 0);
718e3744 4968}
4969
d62a17ae 4970ALIAS_HIDDEN(
4971 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4972 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4973 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4974 "Originate default route to this neighbor\n"
4975 "Route-map to specify criteria to originate default\n"
4976 "route-map name\n")
596c17ba 4977
6b0655a2 4978
718e3744 4979/* Set neighbor's BGP port. */
d62a17ae 4980static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4981 const char *port_str)
4982{
4983 struct peer *peer;
d7c0a89a 4984 uint16_t port;
d62a17ae 4985 struct servent *sp;
4986
4987 peer = peer_lookup_vty(vty, ip_str);
4988 if (!peer)
4989 return CMD_WARNING_CONFIG_FAILED;
4990
4991 if (!port_str) {
4992 sp = getservbyname("bgp", "tcp");
4993 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4994 } else {
4995 port = strtoul(port_str, NULL, 10);
4996 }
718e3744 4997
d62a17ae 4998 peer_port_set(peer, port);
718e3744 4999
d62a17ae 5000 return CMD_SUCCESS;
718e3744 5001}
5002
f418446b 5003/* Set specified peer's BGP port. */
718e3744 5004DEFUN (neighbor_port,
5005 neighbor_port_cmd,
9ccf14f7 5006 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 5007 NEIGHBOR_STR
5008 NEIGHBOR_ADDR_STR
5009 "Neighbor's BGP port\n"
5010 "TCP port number\n")
5011{
d62a17ae 5012 int idx_ip = 1;
5013 int idx_number = 3;
5014 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5015 argv[idx_number]->arg);
718e3744 5016}
5017
5018DEFUN (no_neighbor_port,
5019 no_neighbor_port_cmd,
9ccf14f7 5020 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 5021 NO_STR
5022 NEIGHBOR_STR
5023 NEIGHBOR_ADDR_STR
8334fd5a
DW
5024 "Neighbor's BGP port\n"
5025 "TCP port number\n")
718e3744 5026{
d62a17ae 5027 int idx_ip = 2;
5028 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 5029}
5030
6b0655a2 5031
718e3744 5032/* neighbor weight. */
d62a17ae 5033static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5034 safi_t safi, const char *weight_str)
718e3744 5035{
d62a17ae 5036 int ret;
5037 struct peer *peer;
5038 unsigned long weight;
718e3744 5039
d62a17ae 5040 peer = peer_and_group_lookup_vty(vty, ip_str);
5041 if (!peer)
5042 return CMD_WARNING_CONFIG_FAILED;
718e3744 5043
d62a17ae 5044 weight = strtoul(weight_str, NULL, 10);
718e3744 5045
d62a17ae 5046 ret = peer_weight_set(peer, afi, safi, weight);
5047 return bgp_vty_return(vty, ret);
718e3744 5048}
5049
d62a17ae 5050static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5051 safi_t safi)
718e3744 5052{
d62a17ae 5053 int ret;
5054 struct peer *peer;
718e3744 5055
d62a17ae 5056 peer = peer_and_group_lookup_vty(vty, ip_str);
5057 if (!peer)
5058 return CMD_WARNING_CONFIG_FAILED;
718e3744 5059
d62a17ae 5060 ret = peer_weight_unset(peer, afi, safi);
5061 return bgp_vty_return(vty, ret);
718e3744 5062}
5063
5064DEFUN (neighbor_weight,
5065 neighbor_weight_cmd,
9ccf14f7 5066 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 5067 NEIGHBOR_STR
5068 NEIGHBOR_ADDR_STR2
5069 "Set default weight for routes from this neighbor\n"
5070 "default weight\n")
5071{
d62a17ae 5072 int idx_peer = 1;
5073 int idx_number = 3;
5074 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5075 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 5076}
5077
d62a17ae 5078ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5079 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5080 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5081 "Set default weight for routes from this neighbor\n"
5082 "default weight\n")
596c17ba 5083
718e3744 5084DEFUN (no_neighbor_weight,
5085 no_neighbor_weight_cmd,
9ccf14f7 5086 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5087 NO_STR
5088 NEIGHBOR_STR
5089 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5090 "Set default weight for routes from this neighbor\n"
5091 "default weight\n")
718e3744 5092{
d62a17ae 5093 int idx_peer = 2;
5094 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5095 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 5096}
5097
d62a17ae 5098ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5099 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5100 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5101 "Set default weight for routes from this neighbor\n"
5102 "default weight\n")
596c17ba 5103
6b0655a2 5104
718e3744 5105/* Override capability negotiation. */
5106DEFUN (neighbor_override_capability,
5107 neighbor_override_capability_cmd,
9ccf14f7 5108 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5109 NEIGHBOR_STR
5110 NEIGHBOR_ADDR_STR2
5111 "Override capability negotiation result\n")
5112{
d62a17ae 5113 int idx_peer = 1;
5114 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5115 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5116}
5117
5118DEFUN (no_neighbor_override_capability,
5119 no_neighbor_override_capability_cmd,
9ccf14f7 5120 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5121 NO_STR
5122 NEIGHBOR_STR
5123 NEIGHBOR_ADDR_STR2
5124 "Override capability negotiation result\n")
5125{
d62a17ae 5126 int idx_peer = 2;
5127 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5128 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5129}
6b0655a2 5130
718e3744 5131DEFUN (neighbor_strict_capability,
5132 neighbor_strict_capability_cmd,
9fb964de 5133 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5134 NEIGHBOR_STR
9fb964de 5135 NEIGHBOR_ADDR_STR2
718e3744 5136 "Strict capability negotiation match\n")
5137{
9fb964de
PM
5138 int idx_peer = 1;
5139
5140 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5141 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5142}
5143
5144DEFUN (no_neighbor_strict_capability,
5145 no_neighbor_strict_capability_cmd,
9fb964de 5146 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5147 NO_STR
5148 NEIGHBOR_STR
9fb964de 5149 NEIGHBOR_ADDR_STR2
718e3744 5150 "Strict capability negotiation match\n")
5151{
9fb964de
PM
5152 int idx_peer = 2;
5153
5154 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5155 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5156}
6b0655a2 5157
d62a17ae 5158static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5159 const char *keep_str, const char *hold_str)
718e3744 5160{
d62a17ae 5161 int ret;
5162 struct peer *peer;
d7c0a89a
QY
5163 uint32_t keepalive;
5164 uint32_t holdtime;
718e3744 5165
d62a17ae 5166 peer = peer_and_group_lookup_vty(vty, ip_str);
5167 if (!peer)
5168 return CMD_WARNING_CONFIG_FAILED;
718e3744 5169
d62a17ae 5170 keepalive = strtoul(keep_str, NULL, 10);
5171 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5172
d62a17ae 5173 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5174
d62a17ae 5175 return bgp_vty_return(vty, ret);
718e3744 5176}
6b0655a2 5177
d62a17ae 5178static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5179{
d62a17ae 5180 int ret;
5181 struct peer *peer;
718e3744 5182
d62a17ae 5183 peer = peer_and_group_lookup_vty(vty, ip_str);
5184 if (!peer)
5185 return CMD_WARNING_CONFIG_FAILED;
718e3744 5186
d62a17ae 5187 ret = peer_timers_unset(peer);
718e3744 5188
d62a17ae 5189 return bgp_vty_return(vty, ret);
718e3744 5190}
5191
5192DEFUN (neighbor_timers,
5193 neighbor_timers_cmd,
9ccf14f7 5194 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5195 NEIGHBOR_STR
5196 NEIGHBOR_ADDR_STR2
5197 "BGP per neighbor timers\n"
5198 "Keepalive interval\n"
5199 "Holdtime\n")
5200{
d62a17ae 5201 int idx_peer = 1;
5202 int idx_number = 3;
5203 int idx_number_2 = 4;
5204 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5205 argv[idx_number]->arg,
5206 argv[idx_number_2]->arg);
718e3744 5207}
5208
5209DEFUN (no_neighbor_timers,
5210 no_neighbor_timers_cmd,
9ccf14f7 5211 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5212 NO_STR
5213 NEIGHBOR_STR
5214 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5215 "BGP per neighbor timers\n"
5216 "Keepalive interval\n"
5217 "Holdtime\n")
718e3744 5218{
d62a17ae 5219 int idx_peer = 2;
5220 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5221}
6b0655a2 5222
813d4307 5223
d62a17ae 5224static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5225 const char *time_str)
718e3744 5226{
d62a17ae 5227 int ret;
5228 struct peer *peer;
d7c0a89a 5229 uint32_t connect;
718e3744 5230
d62a17ae 5231 peer = peer_and_group_lookup_vty(vty, ip_str);
5232 if (!peer)
5233 return CMD_WARNING_CONFIG_FAILED;
718e3744 5234
d62a17ae 5235 connect = strtoul(time_str, NULL, 10);
718e3744 5236
d62a17ae 5237 ret = peer_timers_connect_set(peer, connect);
718e3744 5238
d62a17ae 5239 return bgp_vty_return(vty, ret);
718e3744 5240}
5241
d62a17ae 5242static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5243{
d62a17ae 5244 int ret;
5245 struct peer *peer;
718e3744 5246
d62a17ae 5247 peer = peer_and_group_lookup_vty(vty, ip_str);
5248 if (!peer)
5249 return CMD_WARNING_CONFIG_FAILED;
718e3744 5250
d62a17ae 5251 ret = peer_timers_connect_unset(peer);
718e3744 5252
d62a17ae 5253 return bgp_vty_return(vty, ret);
718e3744 5254}
5255
5256DEFUN (neighbor_timers_connect,
5257 neighbor_timers_connect_cmd,
9ccf14f7 5258 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5259 NEIGHBOR_STR
966f821c 5260 NEIGHBOR_ADDR_STR2
718e3744 5261 "BGP per neighbor timers\n"
5262 "BGP connect timer\n"
5263 "Connect timer\n")
5264{
d62a17ae 5265 int idx_peer = 1;
5266 int idx_number = 4;
5267 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5268 argv[idx_number]->arg);
718e3744 5269}
5270
5271DEFUN (no_neighbor_timers_connect,
5272 no_neighbor_timers_connect_cmd,
9ccf14f7 5273 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5274 NO_STR
5275 NEIGHBOR_STR
966f821c 5276 NEIGHBOR_ADDR_STR2
718e3744 5277 "BGP per neighbor timers\n"
8334fd5a
DW
5278 "BGP connect timer\n"
5279 "Connect timer\n")
718e3744 5280{
d62a17ae 5281 int idx_peer = 2;
5282 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5283}
5284
6b0655a2 5285
d62a17ae 5286static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5287 const char *time_str, int set)
718e3744 5288{
d62a17ae 5289 int ret;
5290 struct peer *peer;
d7c0a89a 5291 uint32_t routeadv = 0;
718e3744 5292
d62a17ae 5293 peer = peer_and_group_lookup_vty(vty, ip_str);
5294 if (!peer)
5295 return CMD_WARNING_CONFIG_FAILED;
718e3744 5296
d62a17ae 5297 if (time_str)
5298 routeadv = strtoul(time_str, NULL, 10);
718e3744 5299
d62a17ae 5300 if (set)
5301 ret = peer_advertise_interval_set(peer, routeadv);
5302 else
5303 ret = peer_advertise_interval_unset(peer);
718e3744 5304
d62a17ae 5305 return bgp_vty_return(vty, ret);
718e3744 5306}
5307
5308DEFUN (neighbor_advertise_interval,
5309 neighbor_advertise_interval_cmd,
9ccf14f7 5310 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5311 NEIGHBOR_STR
966f821c 5312 NEIGHBOR_ADDR_STR2
718e3744 5313 "Minimum interval between sending BGP routing updates\n"
5314 "time in seconds\n")
5315{
d62a17ae 5316 int idx_peer = 1;
5317 int idx_number = 3;
5318 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5319 argv[idx_number]->arg, 1);
718e3744 5320}
5321
5322DEFUN (no_neighbor_advertise_interval,
5323 no_neighbor_advertise_interval_cmd,
9ccf14f7 5324 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5325 NO_STR
5326 NEIGHBOR_STR
966f821c 5327 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5328 "Minimum interval between sending BGP routing updates\n"
5329 "time in seconds\n")
718e3744 5330{
d62a17ae 5331 int idx_peer = 2;
5332 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5333}
5334
6b0655a2 5335
518f0eb1
DS
5336/* Time to wait before processing route-map updates */
5337DEFUN (bgp_set_route_map_delay_timer,
5338 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5339 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5340 SET_STR
5341 "BGP route-map delay timer\n"
5342 "Time in secs to wait before processing route-map changes\n"
f414725f 5343 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5344{
d62a17ae 5345 int idx_number = 3;
d7c0a89a 5346 uint32_t rmap_delay_timer;
d62a17ae 5347
5348 if (argv[idx_number]->arg) {
5349 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5350 bm->rmap_update_timer = rmap_delay_timer;
5351
5352 /* if the dynamic update handling is being disabled, and a timer
5353 * is
5354 * running, stop the timer and act as if the timer has already
5355 * fired.
5356 */
5357 if (!rmap_delay_timer && bm->t_rmap_update) {
5358 BGP_TIMER_OFF(bm->t_rmap_update);
5359 thread_execute(bm->master, bgp_route_map_update_timer,
5360 NULL, 0);
5361 }
5362 return CMD_SUCCESS;
5363 } else {
5364 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5365 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5366 }
518f0eb1
DS
5367}
5368
5369DEFUN (no_bgp_set_route_map_delay_timer,
5370 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5371 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5372 NO_STR
3a2d747c 5373 BGP_STR
518f0eb1 5374 "Default BGP route-map delay timer\n"
8334fd5a
DW
5375 "Reset to default time to wait for processing route-map changes\n"
5376 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5377{
518f0eb1 5378
d62a17ae 5379 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5380
d62a17ae 5381 return CMD_SUCCESS;
518f0eb1
DS
5382}
5383
f414725f 5384
718e3744 5385/* neighbor interface */
d62a17ae 5386static int peer_interface_vty(struct vty *vty, const char *ip_str,
5387 const char *str)
718e3744 5388{
d62a17ae 5389 struct peer *peer;
718e3744 5390
d62a17ae 5391 peer = peer_lookup_vty(vty, ip_str);
5392 if (!peer || peer->conf_if) {
5393 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5394 return CMD_WARNING_CONFIG_FAILED;
5395 }
718e3744 5396
d62a17ae 5397 if (str)
5398 peer_interface_set(peer, str);
5399 else
5400 peer_interface_unset(peer);
718e3744 5401
d62a17ae 5402 return CMD_SUCCESS;
718e3744 5403}
5404
5405DEFUN (neighbor_interface,
5406 neighbor_interface_cmd,
9ccf14f7 5407 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5408 NEIGHBOR_STR
5409 NEIGHBOR_ADDR_STR
5410 "Interface\n"
5411 "Interface name\n")
5412{
d62a17ae 5413 int idx_ip = 1;
5414 int idx_word = 3;
5415 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5416}
5417
5418DEFUN (no_neighbor_interface,
5419 no_neighbor_interface_cmd,
9ccf14f7 5420 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5421 NO_STR
5422 NEIGHBOR_STR
16cedbb0 5423 NEIGHBOR_ADDR_STR2
718e3744 5424 "Interface\n"
5425 "Interface name\n")
5426{
d62a17ae 5427 int idx_peer = 2;
5428 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5429}
6b0655a2 5430
718e3744 5431DEFUN (neighbor_distribute_list,
5432 neighbor_distribute_list_cmd,
9ccf14f7 5433 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5434 NEIGHBOR_STR
5435 NEIGHBOR_ADDR_STR2
5436 "Filter updates to/from this neighbor\n"
5437 "IP access-list number\n"
5438 "IP access-list number (expanded range)\n"
5439 "IP Access-list name\n"
5440 "Filter incoming updates\n"
5441 "Filter outgoing updates\n")
5442{
d62a17ae 5443 int idx_peer = 1;
5444 int idx_acl = 3;
5445 int direct, ret;
5446 struct peer *peer;
a8206004 5447
d62a17ae 5448 const char *pstr = argv[idx_peer]->arg;
5449 const char *acl = argv[idx_acl]->arg;
5450 const char *inout = argv[argc - 1]->text;
a8206004 5451
d62a17ae 5452 peer = peer_and_group_lookup_vty(vty, pstr);
5453 if (!peer)
5454 return CMD_WARNING_CONFIG_FAILED;
a8206004 5455
d62a17ae 5456 /* Check filter direction. */
5457 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5458 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5459 direct, acl);
a8206004 5460
d62a17ae 5461 return bgp_vty_return(vty, ret);
718e3744 5462}
5463
d62a17ae 5464ALIAS_HIDDEN(
5465 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5466 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5467 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5468 "Filter updates to/from this neighbor\n"
5469 "IP access-list number\n"
5470 "IP access-list number (expanded range)\n"
5471 "IP Access-list name\n"
5472 "Filter incoming updates\n"
5473 "Filter outgoing updates\n")
596c17ba 5474
718e3744 5475DEFUN (no_neighbor_distribute_list,
5476 no_neighbor_distribute_list_cmd,
9ccf14f7 5477 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5478 NO_STR
5479 NEIGHBOR_STR
5480 NEIGHBOR_ADDR_STR2
5481 "Filter updates to/from this neighbor\n"
5482 "IP access-list number\n"
5483 "IP access-list number (expanded range)\n"
5484 "IP Access-list name\n"
5485 "Filter incoming updates\n"
5486 "Filter outgoing updates\n")
5487{
d62a17ae 5488 int idx_peer = 2;
5489 int direct, ret;
5490 struct peer *peer;
a8206004 5491
d62a17ae 5492 const char *pstr = argv[idx_peer]->arg;
5493 const char *inout = argv[argc - 1]->text;
a8206004 5494
d62a17ae 5495 peer = peer_and_group_lookup_vty(vty, pstr);
5496 if (!peer)
5497 return CMD_WARNING_CONFIG_FAILED;
a8206004 5498
d62a17ae 5499 /* Check filter direction. */
5500 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5501 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5502 direct);
a8206004 5503
d62a17ae 5504 return bgp_vty_return(vty, ret);
718e3744 5505}
6b0655a2 5506
d62a17ae 5507ALIAS_HIDDEN(
5508 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5509 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5510 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5511 "Filter updates to/from this neighbor\n"
5512 "IP access-list number\n"
5513 "IP access-list number (expanded range)\n"
5514 "IP Access-list name\n"
5515 "Filter incoming updates\n"
5516 "Filter outgoing updates\n")
596c17ba 5517
718e3744 5518/* Set prefix list to the peer. */
d62a17ae 5519static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5520 afi_t afi, safi_t safi,
5521 const char *name_str,
5522 const char *direct_str)
718e3744 5523{
d62a17ae 5524 int ret;
d62a17ae 5525 int direct = FILTER_IN;
cf9ac8bf 5526 struct peer *peer;
718e3744 5527
d62a17ae 5528 peer = peer_and_group_lookup_vty(vty, ip_str);
5529 if (!peer)
5530 return CMD_WARNING_CONFIG_FAILED;
718e3744 5531
d62a17ae 5532 /* Check filter direction. */
5533 if (strncmp(direct_str, "i", 1) == 0)
5534 direct = FILTER_IN;
5535 else if (strncmp(direct_str, "o", 1) == 0)
5536 direct = FILTER_OUT;
718e3744 5537
d62a17ae 5538 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5539
d62a17ae 5540 return bgp_vty_return(vty, ret);
718e3744 5541}
5542
d62a17ae 5543static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5544 afi_t afi, safi_t safi,
5545 const char *direct_str)
718e3744 5546{
d62a17ae 5547 int ret;
5548 struct peer *peer;
5549 int direct = FILTER_IN;
718e3744 5550
d62a17ae 5551 peer = peer_and_group_lookup_vty(vty, ip_str);
5552 if (!peer)
5553 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5554
d62a17ae 5555 /* Check filter direction. */
5556 if (strncmp(direct_str, "i", 1) == 0)
5557 direct = FILTER_IN;
5558 else if (strncmp(direct_str, "o", 1) == 0)
5559 direct = FILTER_OUT;
718e3744 5560
d62a17ae 5561 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5562
d62a17ae 5563 return bgp_vty_return(vty, ret);
718e3744 5564}
5565
5566DEFUN (neighbor_prefix_list,
5567 neighbor_prefix_list_cmd,
9ccf14f7 5568 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5569 NEIGHBOR_STR
5570 NEIGHBOR_ADDR_STR2
5571 "Filter updates to/from this neighbor\n"
5572 "Name of a prefix list\n"
5573 "Filter incoming updates\n"
5574 "Filter outgoing updates\n")
5575{
d62a17ae 5576 int idx_peer = 1;
5577 int idx_word = 3;
5578 int idx_in_out = 4;
5579 return peer_prefix_list_set_vty(
5580 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5581 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5582}
5583
d62a17ae 5584ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5585 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5586 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5587 "Filter updates to/from this neighbor\n"
5588 "Name of a prefix list\n"
5589 "Filter incoming updates\n"
5590 "Filter outgoing updates\n")
596c17ba 5591
718e3744 5592DEFUN (no_neighbor_prefix_list,
5593 no_neighbor_prefix_list_cmd,
9ccf14f7 5594 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5595 NO_STR
5596 NEIGHBOR_STR
5597 NEIGHBOR_ADDR_STR2
5598 "Filter updates to/from this neighbor\n"
5599 "Name of a prefix list\n"
5600 "Filter incoming updates\n"
5601 "Filter outgoing updates\n")
5602{
d62a17ae 5603 int idx_peer = 2;
5604 int idx_in_out = 5;
5605 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5606 bgp_node_afi(vty), bgp_node_safi(vty),
5607 argv[idx_in_out]->arg);
718e3744 5608}
6b0655a2 5609
d62a17ae 5610ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5611 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5612 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5613 "Filter updates to/from this neighbor\n"
5614 "Name of a prefix list\n"
5615 "Filter incoming updates\n"
5616 "Filter outgoing updates\n")
596c17ba 5617
d62a17ae 5618static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5619 safi_t safi, const char *name_str,
5620 const char *direct_str)
718e3744 5621{
d62a17ae 5622 int ret;
5623 struct peer *peer;
5624 int direct = FILTER_IN;
718e3744 5625
d62a17ae 5626 peer = peer_and_group_lookup_vty(vty, ip_str);
5627 if (!peer)
5628 return CMD_WARNING_CONFIG_FAILED;
718e3744 5629
d62a17ae 5630 /* Check filter direction. */
5631 if (strncmp(direct_str, "i", 1) == 0)
5632 direct = FILTER_IN;
5633 else if (strncmp(direct_str, "o", 1) == 0)
5634 direct = FILTER_OUT;
718e3744 5635
d62a17ae 5636 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5637
d62a17ae 5638 return bgp_vty_return(vty, ret);
718e3744 5639}
5640
d62a17ae 5641static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5642 safi_t safi, const char *direct_str)
718e3744 5643{
d62a17ae 5644 int ret;
5645 struct peer *peer;
5646 int direct = FILTER_IN;
718e3744 5647
d62a17ae 5648 peer = peer_and_group_lookup_vty(vty, ip_str);
5649 if (!peer)
5650 return CMD_WARNING_CONFIG_FAILED;
718e3744 5651
d62a17ae 5652 /* Check filter direction. */
5653 if (strncmp(direct_str, "i", 1) == 0)
5654 direct = FILTER_IN;
5655 else if (strncmp(direct_str, "o", 1) == 0)
5656 direct = FILTER_OUT;
718e3744 5657
d62a17ae 5658 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5659
d62a17ae 5660 return bgp_vty_return(vty, ret);
718e3744 5661}
5662
5663DEFUN (neighbor_filter_list,
5664 neighbor_filter_list_cmd,
9ccf14f7 5665 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5666 NEIGHBOR_STR
5667 NEIGHBOR_ADDR_STR2
5668 "Establish BGP filters\n"
5669 "AS path access-list name\n"
5670 "Filter incoming routes\n"
5671 "Filter outgoing routes\n")
5672{
d62a17ae 5673 int idx_peer = 1;
5674 int idx_word = 3;
5675 int idx_in_out = 4;
5676 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5677 bgp_node_safi(vty), argv[idx_word]->arg,
5678 argv[idx_in_out]->arg);
718e3744 5679}
5680
d62a17ae 5681ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5682 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5683 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5684 "Establish BGP filters\n"
5685 "AS path access-list name\n"
5686 "Filter incoming routes\n"
5687 "Filter outgoing routes\n")
596c17ba 5688
718e3744 5689DEFUN (no_neighbor_filter_list,
5690 no_neighbor_filter_list_cmd,
9ccf14f7 5691 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5692 NO_STR
5693 NEIGHBOR_STR
5694 NEIGHBOR_ADDR_STR2
5695 "Establish BGP filters\n"
5696 "AS path access-list name\n"
5697 "Filter incoming routes\n"
5698 "Filter outgoing routes\n")
5699{
d62a17ae 5700 int idx_peer = 2;
5701 int idx_in_out = 5;
5702 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5703 bgp_node_afi(vty), bgp_node_safi(vty),
5704 argv[idx_in_out]->arg);
718e3744 5705}
6b0655a2 5706
d62a17ae 5707ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5708 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5709 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5710 "Establish BGP filters\n"
5711 "AS path access-list name\n"
5712 "Filter incoming routes\n"
5713 "Filter outgoing routes\n")
596c17ba 5714
718e3744 5715/* Set route-map to the peer. */
d62a17ae 5716static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5717 afi_t afi, safi_t safi, const char *name_str,
5718 const char *direct_str)
718e3744 5719{
d62a17ae 5720 int ret;
5721 struct peer *peer;
5722 int direct = RMAP_IN;
1de27621 5723 struct route_map *route_map;
718e3744 5724
d62a17ae 5725 peer = peer_and_group_lookup_vty(vty, ip_str);
5726 if (!peer)
5727 return CMD_WARNING_CONFIG_FAILED;
718e3744 5728
d62a17ae 5729 /* Check filter direction. */
5730 if (strncmp(direct_str, "in", 2) == 0)
5731 direct = RMAP_IN;
5732 else if (strncmp(direct_str, "o", 1) == 0)
5733 direct = RMAP_OUT;
718e3744 5734
1de27621
DA
5735 route_map = route_map_lookup_warn_noexist(vty, name_str);
5736 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 5737
d62a17ae 5738 return bgp_vty_return(vty, ret);
718e3744 5739}
5740
d62a17ae 5741static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5742 afi_t afi, safi_t safi,
5743 const char *direct_str)
718e3744 5744{
d62a17ae 5745 int ret;
5746 struct peer *peer;
5747 int direct = RMAP_IN;
718e3744 5748
d62a17ae 5749 peer = peer_and_group_lookup_vty(vty, ip_str);
5750 if (!peer)
5751 return CMD_WARNING_CONFIG_FAILED;
718e3744 5752
d62a17ae 5753 /* Check filter direction. */
5754 if (strncmp(direct_str, "in", 2) == 0)
5755 direct = RMAP_IN;
5756 else if (strncmp(direct_str, "o", 1) == 0)
5757 direct = RMAP_OUT;
718e3744 5758
d62a17ae 5759 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5760
d62a17ae 5761 return bgp_vty_return(vty, ret);
718e3744 5762}
5763
5764DEFUN (neighbor_route_map,
5765 neighbor_route_map_cmd,
9ccf14f7 5766 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5767 NEIGHBOR_STR
5768 NEIGHBOR_ADDR_STR2
5769 "Apply route map to neighbor\n"
5770 "Name of route map\n"
5771 "Apply map to incoming routes\n"
2a3d5731 5772 "Apply map to outbound routes\n")
718e3744 5773{
d62a17ae 5774 int idx_peer = 1;
5775 int idx_word = 3;
5776 int idx_in_out = 4;
5777 return peer_route_map_set_vty(
5778 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5779 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5780}
5781
d62a17ae 5782ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5783 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5784 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5785 "Apply route map to neighbor\n"
5786 "Name of route map\n"
5787 "Apply map to incoming routes\n"
5788 "Apply map to outbound routes\n")
596c17ba 5789
718e3744 5790DEFUN (no_neighbor_route_map,
5791 no_neighbor_route_map_cmd,
9ccf14f7 5792 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5793 NO_STR
5794 NEIGHBOR_STR
5795 NEIGHBOR_ADDR_STR2
5796 "Apply route map to neighbor\n"
5797 "Name of route map\n"
5798 "Apply map to incoming routes\n"
2a3d5731 5799 "Apply map to outbound routes\n")
718e3744 5800{
d62a17ae 5801 int idx_peer = 2;
5802 int idx_in_out = 5;
5803 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5804 bgp_node_afi(vty), bgp_node_safi(vty),
5805 argv[idx_in_out]->arg);
718e3744 5806}
6b0655a2 5807
d62a17ae 5808ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5809 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5810 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5811 "Apply route map to neighbor\n"
5812 "Name of route map\n"
5813 "Apply map to incoming routes\n"
5814 "Apply map to outbound routes\n")
596c17ba 5815
718e3744 5816/* Set unsuppress-map to the peer. */
d62a17ae 5817static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5818 afi_t afi, safi_t safi,
5819 const char *name_str)
718e3744 5820{
d62a17ae 5821 int ret;
5822 struct peer *peer;
1de27621 5823 struct route_map *route_map;
718e3744 5824
d62a17ae 5825 peer = peer_and_group_lookup_vty(vty, ip_str);
5826 if (!peer)
5827 return CMD_WARNING_CONFIG_FAILED;
718e3744 5828
1de27621
DA
5829 route_map = route_map_lookup_warn_noexist(vty, name_str);
5830 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 5831
d62a17ae 5832 return bgp_vty_return(vty, ret);
718e3744 5833}
5834
5835/* Unset route-map from the peer. */
d62a17ae 5836static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5837 afi_t afi, safi_t safi)
718e3744 5838{
d62a17ae 5839 int ret;
5840 struct peer *peer;
718e3744 5841
d62a17ae 5842 peer = peer_and_group_lookup_vty(vty, ip_str);
5843 if (!peer)
5844 return CMD_WARNING_CONFIG_FAILED;
718e3744 5845
d62a17ae 5846 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5847
d62a17ae 5848 return bgp_vty_return(vty, ret);
718e3744 5849}
5850
5851DEFUN (neighbor_unsuppress_map,
5852 neighbor_unsuppress_map_cmd,
9ccf14f7 5853 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5854 NEIGHBOR_STR
5855 NEIGHBOR_ADDR_STR2
5856 "Route-map to selectively unsuppress suppressed routes\n"
5857 "Name of route map\n")
5858{
d62a17ae 5859 int idx_peer = 1;
5860 int idx_word = 3;
5861 return peer_unsuppress_map_set_vty(
5862 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5863 argv[idx_word]->arg);
718e3744 5864}
5865
d62a17ae 5866ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5867 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5868 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5869 "Route-map to selectively unsuppress suppressed routes\n"
5870 "Name of route map\n")
596c17ba 5871
718e3744 5872DEFUN (no_neighbor_unsuppress_map,
5873 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5874 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5875 NO_STR
5876 NEIGHBOR_STR
5877 NEIGHBOR_ADDR_STR2
5878 "Route-map to selectively unsuppress suppressed routes\n"
5879 "Name of route map\n")
5880{
d62a17ae 5881 int idx_peer = 2;
5882 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5883 bgp_node_afi(vty),
5884 bgp_node_safi(vty));
718e3744 5885}
6b0655a2 5886
d62a17ae 5887ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5888 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5889 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5890 "Route-map to selectively unsuppress suppressed routes\n"
5891 "Name of route map\n")
596c17ba 5892
d62a17ae 5893static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5894 afi_t afi, safi_t safi,
5895 const char *num_str,
5896 const char *threshold_str, int warning,
5897 const char *restart_str)
718e3744 5898{
d62a17ae 5899 int ret;
5900 struct peer *peer;
d7c0a89a
QY
5901 uint32_t max;
5902 uint8_t threshold;
5903 uint16_t restart;
718e3744 5904
d62a17ae 5905 peer = peer_and_group_lookup_vty(vty, ip_str);
5906 if (!peer)
5907 return CMD_WARNING_CONFIG_FAILED;
718e3744 5908
d62a17ae 5909 max = strtoul(num_str, NULL, 10);
5910 if (threshold_str)
5911 threshold = atoi(threshold_str);
5912 else
5913 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5914
d62a17ae 5915 if (restart_str)
5916 restart = atoi(restart_str);
5917 else
5918 restart = 0;
0a486e5f 5919
d62a17ae 5920 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5921 restart);
718e3744 5922
d62a17ae 5923 return bgp_vty_return(vty, ret);
718e3744 5924}
5925
d62a17ae 5926static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5927 afi_t afi, safi_t safi)
718e3744 5928{
d62a17ae 5929 int ret;
5930 struct peer *peer;
718e3744 5931
d62a17ae 5932 peer = peer_and_group_lookup_vty(vty, ip_str);
5933 if (!peer)
5934 return CMD_WARNING_CONFIG_FAILED;
718e3744 5935
d62a17ae 5936 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5937
d62a17ae 5938 return bgp_vty_return(vty, ret);
718e3744 5939}
5940
5941/* Maximum number of prefix configuration. prefix count is different
5942 for each peer configuration. So this configuration can be set for
5943 each peer configuration. */
5944DEFUN (neighbor_maximum_prefix,
5945 neighbor_maximum_prefix_cmd,
9ccf14f7 5946 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5947 NEIGHBOR_STR
5948 NEIGHBOR_ADDR_STR2
5949 "Maximum number of prefix accept from this peer\n"
5950 "maximum no. of prefix limit\n")
5951{
d62a17ae 5952 int idx_peer = 1;
5953 int idx_number = 3;
5954 return peer_maximum_prefix_set_vty(
5955 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5956 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5957}
5958
d62a17ae 5959ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5960 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5961 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5962 "Maximum number of prefix accept from this peer\n"
5963 "maximum no. of prefix limit\n")
596c17ba 5964
e0701b79 5965DEFUN (neighbor_maximum_prefix_threshold,
5966 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5967 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5968 NEIGHBOR_STR
5969 NEIGHBOR_ADDR_STR2
5970 "Maximum number of prefix accept from this peer\n"
5971 "maximum no. of prefix limit\n"
5972 "Threshold value (%) at which to generate a warning msg\n")
5973{
d62a17ae 5974 int idx_peer = 1;
5975 int idx_number = 3;
5976 int idx_number_2 = 4;
5977 return peer_maximum_prefix_set_vty(
5978 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5979 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5980}
e0701b79 5981
d62a17ae 5982ALIAS_HIDDEN(
5983 neighbor_maximum_prefix_threshold,
5984 neighbor_maximum_prefix_threshold_hidden_cmd,
5985 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5986 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5987 "Maximum number of prefix accept from this peer\n"
5988 "maximum no. of prefix limit\n"
5989 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5990
718e3744 5991DEFUN (neighbor_maximum_prefix_warning,
5992 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5993 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5994 NEIGHBOR_STR
5995 NEIGHBOR_ADDR_STR2
5996 "Maximum number of prefix accept from this peer\n"
5997 "maximum no. of prefix limit\n"
5998 "Only give warning message when limit is exceeded\n")
5999{
d62a17ae 6000 int idx_peer = 1;
6001 int idx_number = 3;
6002 return peer_maximum_prefix_set_vty(
6003 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6004 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 6005}
6006
d62a17ae 6007ALIAS_HIDDEN(
6008 neighbor_maximum_prefix_warning,
6009 neighbor_maximum_prefix_warning_hidden_cmd,
6010 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6011 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6012 "Maximum number of prefix accept from this peer\n"
6013 "maximum no. of prefix limit\n"
6014 "Only give warning message when limit is exceeded\n")
596c17ba 6015
e0701b79 6016DEFUN (neighbor_maximum_prefix_threshold_warning,
6017 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 6018 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 6019 NEIGHBOR_STR
6020 NEIGHBOR_ADDR_STR2
6021 "Maximum number of prefix accept from this peer\n"
6022 "maximum no. of prefix limit\n"
6023 "Threshold value (%) at which to generate a warning msg\n"
6024 "Only give warning message when limit is exceeded\n")
6025{
d62a17ae 6026 int idx_peer = 1;
6027 int idx_number = 3;
6028 int idx_number_2 = 4;
6029 return peer_maximum_prefix_set_vty(
6030 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6031 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 6032}
6033
d62a17ae 6034ALIAS_HIDDEN(
6035 neighbor_maximum_prefix_threshold_warning,
6036 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6037 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6038 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6039 "Maximum number of prefix accept from this peer\n"
6040 "maximum no. of prefix limit\n"
6041 "Threshold value (%) at which to generate a warning msg\n"
6042 "Only give warning message when limit is exceeded\n")
596c17ba 6043
0a486e5f 6044DEFUN (neighbor_maximum_prefix_restart,
6045 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 6046 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 6047 NEIGHBOR_STR
6048 NEIGHBOR_ADDR_STR2
6049 "Maximum number of prefix accept from this peer\n"
6050 "maximum no. of prefix limit\n"
6051 "Restart bgp connection after limit is exceeded\n"
efd7904e 6052 "Restart interval in minutes\n")
0a486e5f 6053{
d62a17ae 6054 int idx_peer = 1;
6055 int idx_number = 3;
6056 int idx_number_2 = 5;
6057 return peer_maximum_prefix_set_vty(
6058 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6059 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 6060}
6061
d62a17ae 6062ALIAS_HIDDEN(
6063 neighbor_maximum_prefix_restart,
6064 neighbor_maximum_prefix_restart_hidden_cmd,
6065 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6066 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6067 "Maximum number of prefix accept from this peer\n"
6068 "maximum no. of prefix limit\n"
6069 "Restart bgp connection after limit is exceeded\n"
efd7904e 6070 "Restart interval in minutes\n")
596c17ba 6071
0a486e5f 6072DEFUN (neighbor_maximum_prefix_threshold_restart,
6073 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 6074 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 6075 NEIGHBOR_STR
6076 NEIGHBOR_ADDR_STR2
16cedbb0 6077 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 6078 "maximum no. of prefix limit\n"
6079 "Threshold value (%) at which to generate a warning msg\n"
6080 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6081 "Restart interval in minutes\n")
0a486e5f 6082{
d62a17ae 6083 int idx_peer = 1;
6084 int idx_number = 3;
6085 int idx_number_2 = 4;
6086 int idx_number_3 = 6;
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, 0,
6090 argv[idx_number_3]->arg);
6091}
6092
6093ALIAS_HIDDEN(
6094 neighbor_maximum_prefix_threshold_restart,
6095 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6096 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6097 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6098 "Maximum number of prefixes to accept from this peer\n"
6099 "maximum no. of prefix limit\n"
6100 "Threshold value (%) at which to generate a warning msg\n"
6101 "Restart bgp connection after limit is exceeded\n"
6102 "Restart interval in minutes\n")
596c17ba 6103
718e3744 6104DEFUN (no_neighbor_maximum_prefix,
6105 no_neighbor_maximum_prefix_cmd,
d04c479d 6106 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 6107 NO_STR
6108 NEIGHBOR_STR
6109 NEIGHBOR_ADDR_STR2
16cedbb0 6110 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
6111 "maximum no. of prefix limit\n"
6112 "Threshold value (%) at which to generate a warning msg\n"
6113 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6114 "Restart interval in minutes\n"
31500417 6115 "Only give warning message when limit is exceeded\n")
718e3744 6116{
d62a17ae 6117 int idx_peer = 2;
6118 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6119 bgp_node_afi(vty),
6120 bgp_node_safi(vty));
718e3744 6121}
e52702f2 6122
d62a17ae 6123ALIAS_HIDDEN(
6124 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6125 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6126 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6127 "Maximum number of prefixes to accept from this peer\n"
6128 "maximum no. of prefix limit\n"
6129 "Threshold value (%) at which to generate a warning msg\n"
6130 "Restart bgp connection after limit is exceeded\n"
6131 "Restart interval in minutes\n"
6132 "Only give warning message when limit is exceeded\n")
596c17ba 6133
718e3744 6134
718e3744 6135/* "neighbor allowas-in" */
6136DEFUN (neighbor_allowas_in,
6137 neighbor_allowas_in_cmd,
fd8503f5 6138 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6139 NEIGHBOR_STR
6140 NEIGHBOR_ADDR_STR2
31500417 6141 "Accept as-path with my AS present in it\n"
f79f7a7b 6142 "Number of occurrences of AS number\n"
fd8503f5 6143 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6144{
d62a17ae 6145 int idx_peer = 1;
6146 int idx_number_origin = 3;
6147 int ret;
6148 int origin = 0;
6149 struct peer *peer;
6150 int allow_num = 0;
6151
6152 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6153 if (!peer)
6154 return CMD_WARNING_CONFIG_FAILED;
6155
6156 if (argc <= idx_number_origin)
6157 allow_num = 3;
6158 else {
6159 if (argv[idx_number_origin]->type == WORD_TKN)
6160 origin = 1;
6161 else
6162 allow_num = atoi(argv[idx_number_origin]->arg);
6163 }
6164
6165 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6166 allow_num, origin);
6167
6168 return bgp_vty_return(vty, ret);
6169}
6170
6171ALIAS_HIDDEN(
6172 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6173 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6174 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6175 "Accept as-path with my AS present in it\n"
f79f7a7b 6176 "Number of occurrences of AS number\n"
d62a17ae 6177 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6178
718e3744 6179DEFUN (no_neighbor_allowas_in,
6180 no_neighbor_allowas_in_cmd,
fd8503f5 6181 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6182 NO_STR
6183 NEIGHBOR_STR
6184 NEIGHBOR_ADDR_STR2
8334fd5a 6185 "allow local ASN appears in aspath attribute\n"
f79f7a7b 6186 "Number of occurrences of AS number\n"
fd8503f5 6187 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6188{
d62a17ae 6189 int idx_peer = 2;
6190 int ret;
6191 struct peer *peer;
718e3744 6192
d62a17ae 6193 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6194 if (!peer)
6195 return CMD_WARNING_CONFIG_FAILED;
718e3744 6196
d62a17ae 6197 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6198 bgp_node_safi(vty));
718e3744 6199
d62a17ae 6200 return bgp_vty_return(vty, ret);
718e3744 6201}
6b0655a2 6202
d62a17ae 6203ALIAS_HIDDEN(
6204 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6205 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6206 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6207 "allow local ASN appears in aspath attribute\n"
f79f7a7b 6208 "Number of occurrences of AS number\n"
d62a17ae 6209 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6210
fa411a21
NH
6211DEFUN (neighbor_ttl_security,
6212 neighbor_ttl_security_cmd,
7ebe625c 6213 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6214 NEIGHBOR_STR
7ebe625c 6215 NEIGHBOR_ADDR_STR2
16cedbb0 6216 "BGP ttl-security parameters\n"
d7fa34c1
QY
6217 "Specify the maximum number of hops to the BGP peer\n"
6218 "Number of hops to BGP peer\n")
fa411a21 6219{
d62a17ae 6220 int idx_peer = 1;
6221 int idx_number = 4;
6222 struct peer *peer;
6223 int gtsm_hops;
6224
6225 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6226 if (!peer)
6227 return CMD_WARNING_CONFIG_FAILED;
6228
6229 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6230
7ebe625c
QY
6231 /*
6232 * If 'neighbor swpX', then this is for directly connected peers,
6233 * we should not accept a ttl-security hops value greater than 1.
6234 */
6235 if (peer->conf_if && (gtsm_hops > 1)) {
6236 vty_out(vty,
6237 "%s is directly connected peer, hops cannot exceed 1\n",
6238 argv[idx_peer]->arg);
6239 return CMD_WARNING_CONFIG_FAILED;
6240 }
6241
d62a17ae 6242 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6243}
6244
6245DEFUN (no_neighbor_ttl_security,
6246 no_neighbor_ttl_security_cmd,
7ebe625c 6247 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6248 NO_STR
6249 NEIGHBOR_STR
7ebe625c 6250 NEIGHBOR_ADDR_STR2
16cedbb0 6251 "BGP ttl-security parameters\n"
3a2d747c
QY
6252 "Specify the maximum number of hops to the BGP peer\n"
6253 "Number of hops to BGP peer\n")
fa411a21 6254{
d62a17ae 6255 int idx_peer = 2;
6256 struct peer *peer;
fa411a21 6257
d62a17ae 6258 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6259 if (!peer)
6260 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6261
d62a17ae 6262 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6263}
6b0655a2 6264
adbac85e
DW
6265DEFUN (neighbor_addpath_tx_all_paths,
6266 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6267 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6268 NEIGHBOR_STR
6269 NEIGHBOR_ADDR_STR2
6270 "Use addpath to advertise all paths to a neighbor\n")
6271{
d62a17ae 6272 int idx_peer = 1;
6273 struct peer *peer;
adbac85e 6274
d62a17ae 6275 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6276 if (!peer)
6277 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6278
dcc68b5e
MS
6279 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6280 BGP_ADDPATH_ALL);
6281 return CMD_SUCCESS;
adbac85e
DW
6282}
6283
d62a17ae 6284ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6285 neighbor_addpath_tx_all_paths_hidden_cmd,
6286 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6287 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6288 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6289
adbac85e
DW
6290DEFUN (no_neighbor_addpath_tx_all_paths,
6291 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6292 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6293 NO_STR
6294 NEIGHBOR_STR
6295 NEIGHBOR_ADDR_STR2
6296 "Use addpath to advertise all paths to a neighbor\n")
6297{
d62a17ae 6298 int idx_peer = 2;
dcc68b5e
MS
6299 struct peer *peer;
6300
6301 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6302 if (!peer)
6303 return CMD_WARNING_CONFIG_FAILED;
6304
6305 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6306 != BGP_ADDPATH_ALL) {
6307 vty_out(vty,
6308 "%% Peer not currently configured to transmit all paths.");
6309 return CMD_WARNING_CONFIG_FAILED;
6310 }
6311
6312 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6313 BGP_ADDPATH_NONE);
6314
6315 return CMD_SUCCESS;
adbac85e
DW
6316}
6317
d62a17ae 6318ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6319 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6320 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6321 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6322 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6323
06370dac
DW
6324DEFUN (neighbor_addpath_tx_bestpath_per_as,
6325 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6326 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6327 NEIGHBOR_STR
6328 NEIGHBOR_ADDR_STR2
6329 "Use addpath to advertise the bestpath per each neighboring AS\n")
6330{
d62a17ae 6331 int idx_peer = 1;
6332 struct peer *peer;
06370dac 6333
d62a17ae 6334 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6335 if (!peer)
6336 return CMD_WARNING_CONFIG_FAILED;
06370dac 6337
dcc68b5e
MS
6338 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6339 BGP_ADDPATH_BEST_PER_AS);
6340
6341 return CMD_SUCCESS;
06370dac
DW
6342}
6343
d62a17ae 6344ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6345 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6346 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6347 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6348 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6349
06370dac
DW
6350DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6351 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6352 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6353 NO_STR
6354 NEIGHBOR_STR
6355 NEIGHBOR_ADDR_STR2
6356 "Use addpath to advertise the bestpath per each neighboring AS\n")
6357{
d62a17ae 6358 int idx_peer = 2;
dcc68b5e
MS
6359 struct peer *peer;
6360
6361 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6362 if (!peer)
6363 return CMD_WARNING_CONFIG_FAILED;
6364
6365 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6366 != BGP_ADDPATH_BEST_PER_AS) {
6367 vty_out(vty,
6368 "%% Peer not currently configured to transmit all best path per as.");
6369 return CMD_WARNING_CONFIG_FAILED;
6370 }
6371
6372 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6373 BGP_ADDPATH_NONE);
6374
6375 return CMD_SUCCESS;
06370dac
DW
6376}
6377
d62a17ae 6378ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6379 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6380 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6381 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6382 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6383
b9c7bc5a
PZ
6384static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6385 struct ecommunity **list)
ddb5b488 6386{
b9c7bc5a
PZ
6387 struct ecommunity *ecom = NULL;
6388 struct ecommunity *ecomadd;
ddb5b488 6389
b9c7bc5a 6390 for (; argc; --argc, ++argv) {
ddb5b488 6391
b9c7bc5a
PZ
6392 ecomadd = ecommunity_str2com(argv[0]->arg,
6393 ECOMMUNITY_ROUTE_TARGET, 0);
6394 if (!ecomadd) {
6395 vty_out(vty, "Malformed community-list value\n");
6396 if (ecom)
6397 ecommunity_free(&ecom);
6398 return CMD_WARNING_CONFIG_FAILED;
6399 }
ddb5b488 6400
b9c7bc5a
PZ
6401 if (ecom) {
6402 ecommunity_merge(ecom, ecomadd);
6403 ecommunity_free(&ecomadd);
6404 } else {
6405 ecom = ecomadd;
6406 }
6407 }
6408
6409 if (*list) {
6410 ecommunity_free(&*list);
ddb5b488 6411 }
b9c7bc5a
PZ
6412 *list = ecom;
6413
6414 return CMD_SUCCESS;
ddb5b488
PZ
6415}
6416
0ca70ba5
DS
6417/*
6418 * v2vimport is true if we are handling a `import vrf ...` command
6419 */
6420static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6421{
0ca70ba5
DS
6422 afi_t afi;
6423
ddb5b488 6424 switch (vty->node) {
b9c7bc5a 6425 case BGP_IPV4_NODE:
0ca70ba5
DS
6426 afi = AFI_IP;
6427 break;
b9c7bc5a 6428 case BGP_IPV6_NODE:
0ca70ba5
DS
6429 afi = AFI_IP6;
6430 break;
ddb5b488
PZ
6431 default:
6432 vty_out(vty,
b9c7bc5a 6433 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6434 return AFI_MAX;
ddb5b488 6435 }
69b07479 6436
0ca70ba5
DS
6437 if (!v2vimport) {
6438 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6439 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6440 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6441 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6442 vty_out(vty,
6443 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6444 return AFI_MAX;
6445 }
6446 } else {
6447 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6448 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6449 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6450 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6451 vty_out(vty,
6452 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6453 return AFI_MAX;
6454 }
6455 }
6456 return afi;
ddb5b488
PZ
6457}
6458
b9c7bc5a
PZ
6459DEFPY (af_rd_vpn_export,
6460 af_rd_vpn_export_cmd,
6461 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6462 NO_STR
ddb5b488 6463 "Specify route distinguisher\n"
b9c7bc5a
PZ
6464 "Between current address-family and vpn\n"
6465 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6466 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6467{
6468 VTY_DECLVAR_CONTEXT(bgp, bgp);
6469 struct prefix_rd prd;
6470 int ret;
ddb5b488 6471 afi_t afi;
b9c7bc5a
PZ
6472 int idx = 0;
6473 int yes = 1;
ddb5b488 6474
b9c7bc5a 6475 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6476 yes = 0;
b9c7bc5a
PZ
6477
6478 if (yes) {
6479 ret = str2prefix_rd(rd_str, &prd);
6480 if (!ret) {
6481 vty_out(vty, "%% Malformed rd\n");
6482 return CMD_WARNING_CONFIG_FAILED;
6483 }
ddb5b488
PZ
6484 }
6485
0ca70ba5 6486 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6487 if (afi == AFI_MAX)
6488 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6489
69b07479
DS
6490 /*
6491 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6492 */
6493 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6494 bgp_get_default(), bgp);
ddb5b488 6495
69b07479
DS
6496 if (yes) {
6497 bgp->vpn_policy[afi].tovpn_rd = prd;
6498 SET_FLAG(bgp->vpn_policy[afi].flags,
6499 BGP_VPN_POLICY_TOVPN_RD_SET);
6500 } else {
6501 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6502 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6503 }
6504
69b07479
DS
6505 /* post-change: re-export vpn routes */
6506 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6507 bgp_get_default(), bgp);
6508
ddb5b488
PZ
6509 return CMD_SUCCESS;
6510}
6511
b9c7bc5a
PZ
6512ALIAS (af_rd_vpn_export,
6513 af_no_rd_vpn_export_cmd,
6514 "no rd vpn export",
ddb5b488 6515 NO_STR
b9c7bc5a
PZ
6516 "Specify route distinguisher\n"
6517 "Between current address-family and vpn\n"
6518 "For routes leaked from current address-family to vpn\n")
ddb5b488 6519
b9c7bc5a
PZ
6520DEFPY (af_label_vpn_export,
6521 af_label_vpn_export_cmd,
e70e9f8e 6522 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6523 NO_STR
ddb5b488 6524 "label value for VRF\n"
b9c7bc5a
PZ
6525 "Between current address-family and vpn\n"
6526 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6527 "Label Value <0-1048575>\n"
6528 "Automatically assign a label\n")
ddb5b488
PZ
6529{
6530 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6531 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6532 afi_t afi;
b9c7bc5a
PZ
6533 int idx = 0;
6534 int yes = 1;
6535
6536 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6537 yes = 0;
ddb5b488 6538
21a16cc2
PZ
6539 /* If "no ...", squash trailing parameter */
6540 if (!yes)
6541 label_auto = NULL;
6542
e70e9f8e
PZ
6543 if (yes) {
6544 if (!label_auto)
6545 label = label_val; /* parser should force unsigned */
6546 }
ddb5b488 6547
0ca70ba5 6548 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6549 if (afi == AFI_MAX)
6550 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6551
e70e9f8e 6552
69b07479
DS
6553 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6554 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6555 /* no change */
6556 return CMD_SUCCESS;
e70e9f8e 6557
69b07479
DS
6558 /*
6559 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6560 */
6561 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6562 bgp_get_default(), bgp);
6563
6564 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6565 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6566
6567 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6568
6569 /*
6570 * label has previously been automatically
6571 * assigned by labelpool: release it
6572 *
6573 * NB if tovpn_label == MPLS_LABEL_NONE it
6574 * means the automatic assignment is in flight
6575 * and therefore the labelpool callback must
6576 * detect that the auto label is not needed.
6577 */
6578
6579 bgp_lp_release(LP_TYPE_VRF,
6580 &bgp->vpn_policy[afi],
6581 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6582 }
69b07479
DS
6583 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6584 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6585 }
ddb5b488 6586
69b07479
DS
6587 bgp->vpn_policy[afi].tovpn_label = label;
6588 if (label_auto) {
6589 SET_FLAG(bgp->vpn_policy[afi].flags,
6590 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6591 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6592 vpn_leak_label_callback);
ddb5b488
PZ
6593 }
6594
69b07479
DS
6595 /* post-change: re-export vpn routes */
6596 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6597 bgp_get_default(), bgp);
6598
ddb5b488
PZ
6599 return CMD_SUCCESS;
6600}
6601
b9c7bc5a
PZ
6602ALIAS (af_label_vpn_export,
6603 af_no_label_vpn_export_cmd,
6604 "no label vpn export",
6605 NO_STR
6606 "label value for VRF\n"
6607 "Between current address-family and vpn\n"
6608 "For routes leaked from current address-family to vpn\n")
ddb5b488 6609
b9c7bc5a
PZ
6610DEFPY (af_nexthop_vpn_export,
6611 af_nexthop_vpn_export_cmd,
6612 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6613 NO_STR
ddb5b488 6614 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6615 "Between current address-family and vpn\n"
6616 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6617 "IPv4 prefix\n"
6618 "IPv6 prefix\n")
6619{
6620 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6621 afi_t afi;
ddb5b488 6622 struct prefix p;
b9c7bc5a
PZ
6623 int idx = 0;
6624 int yes = 1;
ddb5b488 6625
b9c7bc5a 6626 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6627 yes = 0;
b9c7bc5a
PZ
6628
6629 if (yes) {
6630 if (!sockunion2hostprefix(nexthop_str, &p))
6631 return CMD_WARNING_CONFIG_FAILED;
6632 }
ddb5b488 6633
0ca70ba5 6634 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6635 if (afi == AFI_MAX)
6636 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6637
69b07479
DS
6638 /*
6639 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6640 */
6641 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6642 bgp_get_default(), bgp);
ddb5b488 6643
69b07479
DS
6644 if (yes) {
6645 bgp->vpn_policy[afi].tovpn_nexthop = p;
6646 SET_FLAG(bgp->vpn_policy[afi].flags,
6647 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6648 } else {
6649 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6650 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6651 }
6652
69b07479
DS
6653 /* post-change: re-export vpn routes */
6654 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6655 bgp_get_default(), bgp);
6656
ddb5b488
PZ
6657 return CMD_SUCCESS;
6658}
6659
b9c7bc5a
PZ
6660ALIAS (af_nexthop_vpn_export,
6661 af_no_nexthop_vpn_export_cmd,
6662 "no nexthop vpn export",
ddb5b488 6663 NO_STR
b9c7bc5a
PZ
6664 "Specify next hop to use for VRF advertised prefixes\n"
6665 "Between current address-family and vpn\n"
6666 "For routes leaked from current address-family to vpn\n")
ddb5b488 6667
b9c7bc5a 6668static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6669{
b9c7bc5a
PZ
6670 if (!strcmp(dstr, "import")) {
6671 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6672 } else if (!strcmp(dstr, "export")) {
6673 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6674 } else if (!strcmp(dstr, "both")) {
6675 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6676 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6677 } else {
6678 vty_out(vty, "%% direction parse error\n");
6679 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6680 }
ddb5b488
PZ
6681 return CMD_SUCCESS;
6682}
6683
b9c7bc5a
PZ
6684DEFPY (af_rt_vpn_imexport,
6685 af_rt_vpn_imexport_cmd,
6686 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6687 NO_STR
6688 "Specify route target list\n"
ddb5b488 6689 "Specify route target list\n"
b9c7bc5a
PZ
6690 "Between current address-family and vpn\n"
6691 "For routes leaked from vpn to current address-family: match any\n"
6692 "For routes leaked from current address-family to vpn: set\n"
6693 "both import: match any and export: set\n"
ddb5b488
PZ
6694 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6695{
6696 VTY_DECLVAR_CONTEXT(bgp, bgp);
6697 int ret;
6698 struct ecommunity *ecom = NULL;
6699 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6700 vpn_policy_direction_t dir;
6701 afi_t afi;
6702 int idx = 0;
b9c7bc5a 6703 int yes = 1;
ddb5b488 6704
b9c7bc5a 6705 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6706 yes = 0;
b9c7bc5a 6707
0ca70ba5 6708 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6709 if (afi == AFI_MAX)
6710 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6711
b9c7bc5a 6712 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6713 if (ret != CMD_SUCCESS)
6714 return ret;
6715
b9c7bc5a
PZ
6716 if (yes) {
6717 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6718 vty_out(vty, "%% Missing RTLIST\n");
6719 return CMD_WARNING_CONFIG_FAILED;
6720 }
6721 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6722 if (ret != CMD_SUCCESS) {
6723 return ret;
6724 }
ddb5b488
PZ
6725 }
6726
69b07479
DS
6727 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6728 if (!dodir[dir])
ddb5b488 6729 continue;
ddb5b488 6730
69b07479 6731 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6732
69b07479
DS
6733 if (yes) {
6734 if (bgp->vpn_policy[afi].rtlist[dir])
6735 ecommunity_free(
6736 &bgp->vpn_policy[afi].rtlist[dir]);
6737 bgp->vpn_policy[afi].rtlist[dir] =
6738 ecommunity_dup(ecom);
6739 } else {
6740 if (bgp->vpn_policy[afi].rtlist[dir])
6741 ecommunity_free(
6742 &bgp->vpn_policy[afi].rtlist[dir]);
6743 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6744 }
69b07479
DS
6745
6746 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6747 }
69b07479 6748
d555f3e9
PZ
6749 if (ecom)
6750 ecommunity_free(&ecom);
ddb5b488
PZ
6751
6752 return CMD_SUCCESS;
6753}
6754
b9c7bc5a
PZ
6755ALIAS (af_rt_vpn_imexport,
6756 af_no_rt_vpn_imexport_cmd,
6757 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6758 NO_STR
6759 "Specify route target list\n"
b9c7bc5a
PZ
6760 "Specify route target list\n"
6761 "Between current address-family and vpn\n"
6762 "For routes leaked from vpn to current address-family\n"
6763 "For routes leaked from current address-family to vpn\n"
6764 "both import and export\n")
6765
6766DEFPY (af_route_map_vpn_imexport,
6767 af_route_map_vpn_imexport_cmd,
6768/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6769 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6770 NO_STR
ddb5b488 6771 "Specify route map\n"
b9c7bc5a
PZ
6772 "Between current address-family and vpn\n"
6773 "For routes leaked from vpn to current address-family\n"
6774 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6775 "name of route-map\n")
6776{
6777 VTY_DECLVAR_CONTEXT(bgp, bgp);
6778 int ret;
6779 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6780 vpn_policy_direction_t dir;
6781 afi_t afi;
ddb5b488 6782 int idx = 0;
b9c7bc5a 6783 int yes = 1;
ddb5b488 6784
b9c7bc5a 6785 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6786 yes = 0;
b9c7bc5a 6787
0ca70ba5 6788 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6789 if (afi == AFI_MAX)
6790 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6791
b9c7bc5a 6792 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6793 if (ret != CMD_SUCCESS)
6794 return ret;
6795
69b07479
DS
6796 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6797 if (!dodir[dir])
ddb5b488 6798 continue;
ddb5b488 6799
69b07479 6800 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6801
69b07479
DS
6802 if (yes) {
6803 if (bgp->vpn_policy[afi].rmap_name[dir])
6804 XFREE(MTYPE_ROUTE_MAP_NAME,
6805 bgp->vpn_policy[afi].rmap_name[dir]);
6806 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6807 MTYPE_ROUTE_MAP_NAME, rmap_str);
6808 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6809 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6810 if (!bgp->vpn_policy[afi].rmap[dir])
6811 return CMD_SUCCESS;
6812 } else {
6813 if (bgp->vpn_policy[afi].rmap_name[dir])
6814 XFREE(MTYPE_ROUTE_MAP_NAME,
6815 bgp->vpn_policy[afi].rmap_name[dir]);
6816 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6817 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6818 }
69b07479
DS
6819
6820 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6821 }
6822
6823 return CMD_SUCCESS;
6824}
6825
b9c7bc5a
PZ
6826ALIAS (af_route_map_vpn_imexport,
6827 af_no_route_map_vpn_imexport_cmd,
6828 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6829 NO_STR
6830 "Specify route map\n"
b9c7bc5a
PZ
6831 "Between current address-family and vpn\n"
6832 "For routes leaked from vpn to current address-family\n"
6833 "For routes leaked from current address-family to vpn\n")
6834
bb4f6190
DS
6835DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6836 "[no] import vrf route-map RMAP$rmap_str",
6837 NO_STR
6838 "Import routes from another VRF\n"
6839 "Vrf routes being filtered\n"
6840 "Specify route map\n"
6841 "name of route-map\n")
6842{
6843 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6844 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6845 afi_t afi;
6846 int idx = 0;
6847 int yes = 1;
6848 struct bgp *bgp_default;
6849
6850 if (argv_find(argv, argc, "no", &idx))
6851 yes = 0;
6852
0ca70ba5 6853 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6854 if (afi == AFI_MAX)
6855 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6856
6857 bgp_default = bgp_get_default();
6858 if (!bgp_default) {
6859 int32_t ret;
6860 as_t as = bgp->as;
6861
6862 /* Auto-create assuming the same AS */
6863 ret = bgp_get(&bgp_default, &as, NULL,
6864 BGP_INSTANCE_TYPE_DEFAULT);
6865
6866 if (ret) {
6867 vty_out(vty,
6868 "VRF default is not configured as a bgp instance\n");
6869 return CMD_WARNING;
6870 }
6871 }
6872
69b07479 6873 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6874
69b07479
DS
6875 if (yes) {
6876 if (bgp->vpn_policy[afi].rmap_name[dir])
6877 XFREE(MTYPE_ROUTE_MAP_NAME,
6878 bgp->vpn_policy[afi].rmap_name[dir]);
6879 bgp->vpn_policy[afi].rmap_name[dir] =
6880 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6881 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6882 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6883 if (!bgp->vpn_policy[afi].rmap[dir])
6884 return CMD_SUCCESS;
6885 } else {
6886 if (bgp->vpn_policy[afi].rmap_name[dir])
6887 XFREE(MTYPE_ROUTE_MAP_NAME,
6888 bgp->vpn_policy[afi].rmap_name[dir]);
6889 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6890 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6891 }
6892
69b07479
DS
6893 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6894
bb4f6190
DS
6895 return CMD_SUCCESS;
6896}
6897
6898ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6899 "no import vrf route-map",
6900 NO_STR
6901 "Import routes from another VRF\n"
6902 "Vrf routes being filtered\n"
6903 "Specify route map\n")
6904
4d1b335c
DA
6905DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6906 "[no] import vrf VIEWVRFNAME$import_name",
6907 NO_STR
6908 "Import routes from another VRF\n"
6909 "VRF to import from\n"
6910 "The name of the VRF\n")
12a844a5
DS
6911{
6912 VTY_DECLVAR_CONTEXT(bgp, bgp);
6913 struct listnode *node;
79ef8664
DS
6914 struct bgp *vrf_bgp, *bgp_default;
6915 int32_t ret = 0;
6916 as_t as = bgp->as;
12a844a5
DS
6917 bool remove = false;
6918 int32_t idx = 0;
6919 char *vname;
a8dadcf6 6920 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6921 safi_t safi;
6922 afi_t afi;
6923
867f0cca 6924 if (import_name == NULL) {
6925 vty_out(vty, "%% Missing import name\n");
6926 return CMD_WARNING;
6927 }
6928
12a844a5
DS
6929 if (argv_find(argv, argc, "no", &idx))
6930 remove = true;
6931
0ca70ba5
DS
6932 afi = vpn_policy_getafi(vty, bgp, true);
6933 if (afi == AFI_MAX)
6934 return CMD_WARNING_CONFIG_FAILED;
6935
12a844a5
DS
6936 safi = bgp_node_safi(vty);
6937
25679caa 6938 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 6939 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
6940 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6941 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6942 remove ? "unimport" : "import", import_name);
6943 return CMD_WARNING;
6944 }
6945
79ef8664
DS
6946 bgp_default = bgp_get_default();
6947 if (!bgp_default) {
6948 /* Auto-create assuming the same AS */
6949 ret = bgp_get(&bgp_default, &as, NULL,
6950 BGP_INSTANCE_TYPE_DEFAULT);
6951
6952 if (ret) {
6953 vty_out(vty,
6954 "VRF default is not configured as a bgp instance\n");
6955 return CMD_WARNING;
6956 }
6957 }
6958
12a844a5
DS
6959 vrf_bgp = bgp_lookup_by_name(import_name);
6960 if (!vrf_bgp) {
5742e42b 6961 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
6962 vrf_bgp = bgp_default;
6963 else
0fb8d6e6
DS
6964 /* Auto-create assuming the same AS */
6965 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6966
6e2c7fe6 6967 if (ret) {
020a3f60
DS
6968 vty_out(vty,
6969 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6970 import_name);
6971 return CMD_WARNING;
6972 }
12a844a5
DS
6973 }
6974
12a844a5 6975 if (remove) {
44338987 6976 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6977 } else {
44338987 6978 /* Already importing from "import_vrf"? */
12a844a5
DS
6979 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6980 vname)) {
6981 if (strcmp(vname, import_name) == 0)
6982 return CMD_WARNING;
6983 }
6984
44338987 6985 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6986 }
6987
6988 return CMD_SUCCESS;
6989}
6990
b9c7bc5a
PZ
6991/* This command is valid only in a bgp vrf instance or the default instance */
6992DEFPY (bgp_imexport_vpn,
6993 bgp_imexport_vpn_cmd,
6994 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6995 NO_STR
6996 "Import routes to this address-family\n"
6997 "Export routes from this address-family\n"
6998 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6999{
7000 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7001 int previous_state;
ddb5b488 7002 afi_t afi;
b9c7bc5a 7003 safi_t safi;
ddb5b488 7004 int idx = 0;
b9c7bc5a
PZ
7005 int yes = 1;
7006 int flag;
7007 vpn_policy_direction_t dir;
ddb5b488 7008
b9c7bc5a 7009 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7010 yes = 0;
ddb5b488 7011
b9c7bc5a
PZ
7012 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7013 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 7014
b9c7bc5a
PZ
7015 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7016 return CMD_WARNING_CONFIG_FAILED;
7017 }
ddb5b488 7018
b9c7bc5a
PZ
7019 afi = bgp_node_afi(vty);
7020 safi = bgp_node_safi(vty);
7021 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7022 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7023 return CMD_WARNING_CONFIG_FAILED;
7024 }
ddb5b488 7025
b9c7bc5a
PZ
7026 if (!strcmp(direction_str, "import")) {
7027 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7028 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7029 } else if (!strcmp(direction_str, "export")) {
7030 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7031 dir = BGP_VPN_POLICY_DIR_TOVPN;
7032 } else {
7033 vty_out(vty, "%% unknown direction %s\n", direction_str);
7034 return CMD_WARNING_CONFIG_FAILED;
7035 }
7036
7037 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 7038
b9c7bc5a
PZ
7039 if (yes) {
7040 SET_FLAG(bgp->af_flags[afi][safi], flag);
7041 if (!previous_state) {
7042 /* trigger export current vrf */
ddb5b488
PZ
7043 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7044 }
b9c7bc5a
PZ
7045 } else {
7046 if (previous_state) {
7047 /* trigger un-export current vrf */
7048 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7049 }
7050 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
7051 }
7052
7053 return CMD_SUCCESS;
7054}
7055
301ad80a
PG
7056DEFPY (af_routetarget_import,
7057 af_routetarget_import_cmd,
7058 "[no] <rt|route-target> redirect import RTLIST...",
7059 NO_STR
7060 "Specify route target list\n"
7061 "Specify route target list\n"
7062 "Flow-spec redirect type route target\n"
7063 "Import routes to this address-family\n"
7064 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7065{
7066 VTY_DECLVAR_CONTEXT(bgp, bgp);
7067 int ret;
7068 struct ecommunity *ecom = NULL;
301ad80a
PG
7069 afi_t afi;
7070 int idx = 0;
7071 int yes = 1;
7072
7073 if (argv_find(argv, argc, "no", &idx))
7074 yes = 0;
7075
0ca70ba5 7076 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7077 if (afi == AFI_MAX)
7078 return CMD_WARNING_CONFIG_FAILED;
7079
301ad80a
PG
7080 if (yes) {
7081 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7082 vty_out(vty, "%% Missing RTLIST\n");
7083 return CMD_WARNING_CONFIG_FAILED;
7084 }
7085 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7086 if (ret != CMD_SUCCESS)
7087 return ret;
7088 }
69b07479
DS
7089
7090 if (yes) {
7091 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7092 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7093 .import_redirect_rtlist);
69b07479
DS
7094 bgp->vpn_policy[afi].import_redirect_rtlist =
7095 ecommunity_dup(ecom);
7096 } else {
7097 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7098 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7099 .import_redirect_rtlist);
69b07479 7100 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 7101 }
69b07479 7102
301ad80a
PG
7103 if (ecom)
7104 ecommunity_free(&ecom);
7105
7106 return CMD_SUCCESS;
7107}
7108
505e5056 7109DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 7110 address_family_ipv4_safi_cmd,
7111 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7112 "Enter Address Family command mode\n"
7113 "Address Family\n"
7114 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 7115{
f51bae9c 7116
d62a17ae 7117 if (argc == 3) {
2131d5cf 7118 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7119 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7120 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7121 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7122 && safi != SAFI_EVPN) {
31947174
MK
7123 vty_out(vty,
7124 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7125 return CMD_WARNING_CONFIG_FAILED;
7126 }
d62a17ae 7127 vty->node = bgp_node_type(AFI_IP, safi);
7128 } else
7129 vty->node = BGP_IPV4_NODE;
718e3744 7130
d62a17ae 7131 return CMD_SUCCESS;
718e3744 7132}
7133
505e5056 7134DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 7135 address_family_ipv6_safi_cmd,
7136 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7137 "Enter Address Family command mode\n"
7138 "Address Family\n"
7139 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 7140{
d62a17ae 7141 if (argc == 3) {
2131d5cf 7142 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7143 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7144 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7145 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7146 && safi != SAFI_EVPN) {
31947174
MK
7147 vty_out(vty,
7148 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7149 return CMD_WARNING_CONFIG_FAILED;
7150 }
d62a17ae 7151 vty->node = bgp_node_type(AFI_IP6, safi);
7152 } else
7153 vty->node = BGP_IPV6_NODE;
25ffbdc1 7154
d62a17ae 7155 return CMD_SUCCESS;
25ffbdc1 7156}
718e3744 7157
d6902373 7158#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7159DEFUN_NOSH (address_family_vpnv4,
718e3744 7160 address_family_vpnv4_cmd,
8334fd5a 7161 "address-family vpnv4 [unicast]",
718e3744 7162 "Enter Address Family command mode\n"
8c3deaae 7163 "Address Family\n"
3a2d747c 7164 "Address Family modifier\n")
718e3744 7165{
d62a17ae 7166 vty->node = BGP_VPNV4_NODE;
7167 return CMD_SUCCESS;
718e3744 7168}
7169
505e5056 7170DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7171 address_family_vpnv6_cmd,
8334fd5a 7172 "address-family vpnv6 [unicast]",
8ecd3266 7173 "Enter Address Family command mode\n"
8c3deaae 7174 "Address Family\n"
3a2d747c 7175 "Address Family modifier\n")
8ecd3266 7176{
d62a17ae 7177 vty->node = BGP_VPNV6_NODE;
7178 return CMD_SUCCESS;
8ecd3266 7179}
64e4a6c5 7180#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 7181
505e5056 7182DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7183 address_family_evpn_cmd,
7111c1a0 7184 "address-family l2vpn evpn",
4e0b7b6d 7185 "Enter Address Family command mode\n"
7111c1a0
QY
7186 "Address Family\n"
7187 "Address Family modifier\n")
4e0b7b6d 7188{
2131d5cf 7189 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7190 vty->node = BGP_EVPN_NODE;
7191 return CMD_SUCCESS;
4e0b7b6d
PG
7192}
7193
505e5056 7194DEFUN_NOSH (exit_address_family,
718e3744 7195 exit_address_family_cmd,
7196 "exit-address-family",
7197 "Exit from Address Family configuration mode\n")
7198{
d62a17ae 7199 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7200 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7201 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7202 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7203 || vty->node == BGP_EVPN_NODE
7204 || vty->node == BGP_FLOWSPECV4_NODE
7205 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7206 vty->node = BGP_NODE;
7207 return CMD_SUCCESS;
718e3744 7208}
6b0655a2 7209
8ad7271d 7210/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7211static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7212 const char *ip_str, afi_t afi, safi_t safi,
7213 struct prefix_rd *prd)
7214{
7215 int ret;
7216 struct prefix match;
7217 struct bgp_node *rn;
7218 struct bgp_node *rm;
7219 struct bgp *bgp;
7220 struct bgp_table *table;
7221 struct bgp_table *rib;
7222
7223 /* BGP structure lookup. */
7224 if (view_name) {
7225 bgp = bgp_lookup_by_name(view_name);
7226 if (bgp == NULL) {
7227 vty_out(vty, "%% Can't find BGP instance %s\n",
7228 view_name);
7229 return CMD_WARNING;
7230 }
7231 } else {
7232 bgp = bgp_get_default();
7233 if (bgp == NULL) {
7234 vty_out(vty, "%% No BGP process is configured\n");
7235 return CMD_WARNING;
7236 }
7237 }
7238
7239 /* Check IP address argument. */
7240 ret = str2prefix(ip_str, &match);
7241 if (!ret) {
7242 vty_out(vty, "%% address is malformed\n");
7243 return CMD_WARNING;
7244 }
7245
7246 match.family = afi2family(afi);
7247 rib = bgp->rib[afi][safi];
7248
7249 if (safi == SAFI_MPLS_VPN) {
7250 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7251 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7252 continue;
7253
67009e22
DS
7254 table = bgp_node_get_bgp_table_info(rn);
7255 if (table != NULL) {
7256
d62a17ae 7257 if ((rm = bgp_node_match(table, &match))
7258 != NULL) {
7259 if (rm->p.prefixlen
7260 == match.prefixlen) {
343cdb61 7261 SET_FLAG(rm->flags,
d62a17ae 7262 BGP_NODE_USER_CLEAR);
7263 bgp_process(bgp, rm, afi, safi);
7264 }
7265 bgp_unlock_node(rm);
7266 }
7267 }
7268 }
7269 } else {
7270 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7271 if (rn->p.prefixlen == match.prefixlen) {
7272 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7273 bgp_process(bgp, rn, afi, safi);
7274 }
7275 bgp_unlock_node(rn);
7276 }
7277 }
7278
7279 return CMD_SUCCESS;
8ad7271d
DS
7280}
7281
b09b5ae0 7282/* one clear bgp command to rule them all */
718e3744 7283DEFUN (clear_ip_bgp_all,
7284 clear_ip_bgp_all_cmd,
d7b9898c 7285 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out>]",
718e3744 7286 CLEAR_STR
7287 IP_STR
7288 BGP_STR
838758ac 7289 BGP_INSTANCE_HELP_STR
510afcd6 7290 BGP_AFI_HELP_STR
fd5e7b70 7291 "Address Family\n"
510afcd6 7292 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 7293 "Address Family modifier\n"
b09b5ae0
DW
7294 "Clear all peers\n"
7295 "BGP neighbor address to clear\n"
a80beece 7296 "BGP IPv6 neighbor to clear\n"
838758ac 7297 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7298 "Clear peers with the AS number\n"
7299 "Clear all external peers\n"
718e3744 7300 "Clear all members of peer-group\n"
b09b5ae0 7301 "BGP peer-group name\n"
b09b5ae0
DW
7302 BGP_SOFT_STR
7303 BGP_SOFT_IN_STR
b09b5ae0
DW
7304 BGP_SOFT_OUT_STR
7305 BGP_SOFT_IN_STR
7306 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7307 BGP_SOFT_OUT_STR)
718e3744 7308{
d62a17ae 7309 char *vrf = NULL;
7310
dc912615
DS
7311 afi_t afi = AFI_UNSPEC;
7312 safi_t safi = SAFI_UNSPEC;
d62a17ae 7313 enum clear_sort clr_sort = clear_peer;
7314 enum bgp_clear_type clr_type;
7315 char *clr_arg = NULL;
7316
7317 int idx = 0;
7318
7319 /* clear [ip] bgp */
7320 if (argv_find(argv, argc, "ip", &idx))
7321 afi = AFI_IP;
7322
9a8bdf1c
PG
7323 /* [<vrf> VIEWVRFNAME] */
7324 if (argv_find(argv, argc, "vrf", &idx)) {
7325 vrf = argv[idx + 1]->arg;
7326 idx += 2;
7327 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7328 vrf = NULL;
7329 } else if (argv_find(argv, argc, "view", &idx)) {
7330 /* [<view> VIEWVRFNAME] */
d62a17ae 7331 vrf = argv[idx + 1]->arg;
7332 idx += 2;
7333 }
d62a17ae 7334 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7335 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7336 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7337
d7b9898c 7338 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 7339 if (argv_find(argv, argc, "*", &idx)) {
7340 clr_sort = clear_all;
7341 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7342 clr_sort = clear_peer;
7343 clr_arg = argv[idx]->arg;
7344 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7345 clr_sort = clear_peer;
7346 clr_arg = argv[idx]->arg;
7347 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7348 clr_sort = clear_group;
7349 idx++;
7350 clr_arg = argv[idx]->arg;
d7b9898c 7351 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 7352 clr_sort = clear_peer;
7353 clr_arg = argv[idx]->arg;
8fa7d444
DS
7354 } else if (argv_find(argv, argc, "WORD", &idx)) {
7355 clr_sort = clear_peer;
7356 clr_arg = argv[idx]->arg;
d62a17ae 7357 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7358 clr_sort = clear_as;
7359 clr_arg = argv[idx]->arg;
7360 } else if (argv_find(argv, argc, "external", &idx)) {
7361 clr_sort = clear_external;
7362 }
7363
7364 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7365 if (argv_find(argv, argc, "soft", &idx)) {
7366 if (argv_find(argv, argc, "in", &idx)
7367 || argv_find(argv, argc, "out", &idx))
7368 clr_type = strmatch(argv[idx]->text, "in")
7369 ? BGP_CLEAR_SOFT_IN
7370 : BGP_CLEAR_SOFT_OUT;
7371 else
7372 clr_type = BGP_CLEAR_SOFT_BOTH;
7373 } else if (argv_find(argv, argc, "in", &idx)) {
7374 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7375 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7376 : BGP_CLEAR_SOFT_IN;
7377 } else if (argv_find(argv, argc, "out", &idx)) {
7378 clr_type = BGP_CLEAR_SOFT_OUT;
7379 } else
7380 clr_type = BGP_CLEAR_SOFT_NONE;
7381
7382 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7383}
01080f7c 7384
8ad7271d
DS
7385DEFUN (clear_ip_bgp_prefix,
7386 clear_ip_bgp_prefix_cmd,
18c57037 7387 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7388 CLEAR_STR
7389 IP_STR
7390 BGP_STR
838758ac 7391 BGP_INSTANCE_HELP_STR
8ad7271d 7392 "Clear bestpath and re-advertise\n"
0c7b1b01 7393 "IPv4 prefix\n")
8ad7271d 7394{
d62a17ae 7395 char *vrf = NULL;
7396 char *prefix = NULL;
8ad7271d 7397
d62a17ae 7398 int idx = 0;
01080f7c 7399
d62a17ae 7400 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
7401 if (argv_find(argv, argc, "vrf", &idx)) {
7402 vrf = argv[idx + 1]->arg;
7403 idx += 2;
7404 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7405 vrf = NULL;
7406 } else if (argv_find(argv, argc, "view", &idx)) {
7407 /* [<view> VIEWVRFNAME] */
7408 vrf = argv[idx + 1]->arg;
7409 idx += 2;
7410 }
0c7b1b01 7411
d62a17ae 7412 prefix = argv[argc - 1]->arg;
8ad7271d 7413
d62a17ae 7414 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7415}
8ad7271d 7416
b09b5ae0
DW
7417DEFUN (clear_bgp_ipv6_safi_prefix,
7418 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7419 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7420 CLEAR_STR
3a2d747c 7421 IP_STR
718e3744 7422 BGP_STR
8c3deaae 7423 "Address Family\n"
46f296b4 7424 BGP_SAFI_HELP_STR
b09b5ae0 7425 "Clear bestpath and re-advertise\n"
0c7b1b01 7426 "IPv6 prefix\n")
718e3744 7427{
9b475e76
PG
7428 int idx_safi = 0;
7429 int idx_ipv6_prefix = 0;
7430 safi_t safi = SAFI_UNICAST;
7431 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7432 argv[idx_ipv6_prefix]->arg : NULL;
7433
7434 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7435 return bgp_clear_prefix(
9b475e76
PG
7436 vty, NULL, prefix, AFI_IP6,
7437 safi, NULL);
838758ac 7438}
01080f7c 7439
b09b5ae0
DW
7440DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7441 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7442 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7443 CLEAR_STR
3a2d747c 7444 IP_STR
718e3744 7445 BGP_STR
838758ac 7446 BGP_INSTANCE_HELP_STR
8c3deaae 7447 "Address Family\n"
46f296b4 7448 BGP_SAFI_HELP_STR
b09b5ae0 7449 "Clear bestpath and re-advertise\n"
0c7b1b01 7450 "IPv6 prefix\n")
718e3744 7451{
9b475e76 7452 int idx_safi = 0;
9a8bdf1c 7453 int idx_vrfview = 0;
9b475e76
PG
7454 int idx_ipv6_prefix = 0;
7455 safi_t safi = SAFI_UNICAST;
7456 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7457 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 7458 char *vrfview = NULL;
9b475e76 7459
9a8bdf1c
PG
7460 /* [<view|vrf> VIEWVRFNAME] */
7461 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7462 vrfview = argv[idx_vrfview + 1]->arg;
7463 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7464 vrfview = NULL;
7465 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7466 /* [<view> VIEWVRFNAME] */
7467 vrfview = argv[idx_vrfview + 1]->arg;
7468 }
9b475e76
PG
7469 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7470
d62a17ae 7471 return bgp_clear_prefix(
9b475e76
PG
7472 vty, vrfview, prefix,
7473 AFI_IP6, safi, NULL);
718e3744 7474}
7475
b09b5ae0
DW
7476DEFUN (show_bgp_views,
7477 show_bgp_views_cmd,
d6e3c605 7478 "show [ip] bgp views",
b09b5ae0 7479 SHOW_STR
d6e3c605 7480 IP_STR
01080f7c 7481 BGP_STR
b09b5ae0 7482 "Show the defined BGP views\n")
01080f7c 7483{
d62a17ae 7484 struct list *inst = bm->bgp;
7485 struct listnode *node;
7486 struct bgp *bgp;
01080f7c 7487
d62a17ae 7488 vty_out(vty, "Defined BGP views:\n");
7489 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7490 /* Skip VRFs. */
7491 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7492 continue;
7493 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7494 bgp->as);
7495 }
e52702f2 7496
d62a17ae 7497 return CMD_SUCCESS;
e0081f70
ML
7498}
7499
8386ac43 7500DEFUN (show_bgp_vrfs,
7501 show_bgp_vrfs_cmd,
d6e3c605 7502 "show [ip] bgp vrfs [json]",
8386ac43 7503 SHOW_STR
d6e3c605 7504 IP_STR
8386ac43 7505 BGP_STR
7506 "Show BGP VRFs\n"
9973d184 7507 JSON_STR)
8386ac43 7508{
fe1dc5a3 7509 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7510 struct list *inst = bm->bgp;
7511 struct listnode *node;
7512 struct bgp *bgp;
9f049418 7513 bool uj = use_json(argc, argv);
d62a17ae 7514 json_object *json = NULL;
7515 json_object *json_vrfs = NULL;
7516 int count = 0;
d62a17ae 7517
d62a17ae 7518 if (uj) {
7519 json = json_object_new_object();
7520 json_vrfs = json_object_new_object();
7521 }
7522
7523 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7524 const char *name, *type;
7525 struct peer *peer;
7fe96307 7526 struct listnode *node2, *nnode2;
d62a17ae 7527 int peers_cfg, peers_estb;
7528 json_object *json_vrf = NULL;
d62a17ae 7529
7530 /* Skip Views. */
7531 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7532 continue;
7533
7534 count++;
efb4077a 7535 if (!uj && count == 1) {
fe1dc5a3 7536 vty_out(vty,
efb4077a 7537 "%4s %-5s %-16s %9s %10s %-37s\n",
a4d82a8a 7538 "Type", "Id", "routerId", "#PeersVfg",
efb4077a
CS
7539 "#PeersEstb", "Name");
7540 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
7541 "L3-VNI", "RouterMAC", "Interface");
7542 }
d62a17ae 7543
7544 peers_cfg = peers_estb = 0;
7545 if (uj)
7546 json_vrf = json_object_new_object();
7547
7548
7fe96307 7549 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 7550 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7551 continue;
7552 peers_cfg++;
7553 if (peer->status == Established)
7554 peers_estb++;
7555 }
7556
7557 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 7558 name = VRF_DEFAULT_NAME;
d62a17ae 7559 type = "DFLT";
7560 } else {
7561 name = bgp->name;
7562 type = "VRF";
7563 }
7564
a8bf7d9c 7565
d62a17ae 7566 if (uj) {
a4d82a8a
PZ
7567 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7568 ? -1
7569 : (int64_t)bgp->vrf_id;
d62a17ae 7570 json_object_string_add(json_vrf, "type", type);
7571 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7572 json_object_string_add(json_vrf, "routerId",
7573 inet_ntoa(bgp->router_id));
7574 json_object_int_add(json_vrf, "numConfiguredPeers",
7575 peers_cfg);
7576 json_object_int_add(json_vrf, "numEstablishedPeers",
7577 peers_estb);
7578
fe1dc5a3 7579 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7580 json_object_string_add(
7581 json_vrf, "rmac",
7582 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
7583 json_object_string_add(json_vrf, "interface",
7584 ifindex2ifname(bgp->l3vni_svi_ifindex,
7585 bgp->vrf_id));
d62a17ae 7586 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 7587 } else {
fe1dc5a3 7588 vty_out(vty,
efb4077a 7589 "%4s %-5d %-16s %-9u %-10u %-37s\n",
a4d82a8a
PZ
7590 type,
7591 bgp->vrf_id == VRF_UNKNOWN ? -1
7592 : (int)bgp->vrf_id,
7593 inet_ntoa(bgp->router_id), peers_cfg,
efb4077a
CS
7594 peers_estb, name);
7595 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
7596 bgp->l3vni,
7597 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
7598 ifindex2ifname(bgp->l3vni_svi_ifindex,
7599 bgp->vrf_id));
7600 }
d62a17ae 7601 }
7602
7603 if (uj) {
7604 json_object_object_add(json, "vrfs", json_vrfs);
7605
7606 json_object_int_add(json, "totalVrfs", count);
7607
996c9314
LB
7608 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7609 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7610 json_object_free(json);
7611 } else {
7612 if (count)
7613 vty_out(vty,
7614 "\nTotal number of VRFs (including default): %d\n",
7615 count);
7616 }
7617
7618 return CMD_SUCCESS;
8386ac43 7619}
7620
48ecf8f5
DS
7621DEFUN (show_bgp_mac_hash,
7622 show_bgp_mac_hash_cmd,
7623 "show bgp mac hash",
7624 SHOW_STR
7625 BGP_STR
7626 "Mac Address\n"
7627 "Mac Address database\n")
7628{
7629 bgp_mac_dump_table(vty);
7630
7631 return CMD_SUCCESS;
7632}
acf71666 7633
e3b78da8 7634static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 7635{
0291c246 7636 struct vty *vty = (struct vty *)args;
e3b78da8 7637 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 7638
60466a63 7639 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7640 tip->refcnt);
7641}
7642
7643static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7644{
7645 vty_out(vty, "self nexthop database:\n");
af97a18b 7646 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
7647
7648 vty_out(vty, "Tunnel-ip database:\n");
7649 hash_iterate(bgp->tip_hash,
e3b78da8 7650 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
7651 vty);
7652}
7653
15c81ca4
DS
7654DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7655 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7656 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7657 "martian next-hops\n"
7658 "martian next-hop database\n")
acf71666 7659{
0291c246 7660 struct bgp *bgp = NULL;
15c81ca4 7661 int idx = 0;
9a8bdf1c
PG
7662 char *name = NULL;
7663
7664 /* [<vrf> VIEWVRFNAME] */
7665 if (argv_find(argv, argc, "vrf", &idx)) {
7666 name = argv[idx + 1]->arg;
7667 if (name && strmatch(name, VRF_DEFAULT_NAME))
7668 name = NULL;
7669 } else if (argv_find(argv, argc, "view", &idx))
7670 /* [<view> VIEWVRFNAME] */
7671 name = argv[idx + 1]->arg;
7672 if (name)
7673 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
7674 else
7675 bgp = bgp_get_default();
acf71666 7676
acf71666
MK
7677 if (!bgp) {
7678 vty_out(vty, "%% No BGP process is configured\n");
7679 return CMD_WARNING;
7680 }
7681 bgp_show_martian_nexthops(vty, bgp);
7682
7683 return CMD_SUCCESS;
7684}
7685
f412b39a 7686DEFUN (show_bgp_memory,
4bf6a362 7687 show_bgp_memory_cmd,
7fa12b13 7688 "show [ip] bgp memory",
4bf6a362 7689 SHOW_STR
3a2d747c 7690 IP_STR
4bf6a362
PJ
7691 BGP_STR
7692 "Global BGP memory statistics\n")
7693{
d62a17ae 7694 char memstrbuf[MTYPE_MEMSTR_LEN];
7695 unsigned long count;
7696
7697 /* RIB related usage stats */
7698 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7699 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7700 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7701 count * sizeof(struct bgp_node)));
7702
7703 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7704 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7705 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 7706 count * sizeof(struct bgp_path_info)));
d62a17ae 7707 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7708 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7709 count,
4b7e6066
DS
7710 mtype_memstr(
7711 memstrbuf, sizeof(memstrbuf),
7712 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 7713
7714 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7715 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7716 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7717 count * sizeof(struct bgp_static)));
7718
7719 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7720 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7721 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7722 count * sizeof(struct bpacket)));
7723
7724 /* Adj-In/Out */
7725 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7726 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7727 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7728 count * sizeof(struct bgp_adj_in)));
7729 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7730 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7731 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7732 count * sizeof(struct bgp_adj_out)));
7733
7734 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7735 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7736 count,
7737 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7738 count * sizeof(struct bgp_nexthop_cache)));
7739
7740 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7741 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7742 count,
7743 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7744 count * sizeof(struct bgp_damp_info)));
7745
7746 /* Attributes */
7747 count = attr_count();
7748 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7749 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7750 count * sizeof(struct attr)));
7751
7752 if ((count = attr_unknown_count()))
7753 vty_out(vty, "%ld unknown attributes\n", count);
7754
7755 /* AS_PATH attributes */
7756 count = aspath_count();
7757 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7758 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7759 count * sizeof(struct aspath)));
7760
7761 count = mtype_stats_alloc(MTYPE_AS_SEG);
7762 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7763 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7764 count * sizeof(struct assegment)));
7765
7766 /* Other attributes */
7767 if ((count = community_count()))
7768 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7769 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7770 count * sizeof(struct community)));
d62a17ae 7771 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7772 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7773 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7774 count * sizeof(struct ecommunity)));
d62a17ae 7775 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7776 vty_out(vty,
7777 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7778 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7779 count * sizeof(struct lcommunity)));
d62a17ae 7780
7781 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7782 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7783 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7784 count * sizeof(struct cluster_list)));
7785
7786 /* Peer related usage */
7787 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7788 vty_out(vty, "%ld peers, using %s of memory\n", count,
7789 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7790 count * sizeof(struct peer)));
7791
7792 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7793 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7794 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7795 count * sizeof(struct peer_group)));
7796
7797 /* Other */
d62a17ae 7798 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7799 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7800 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7801 count * sizeof(regex_t)));
d62a17ae 7802 return CMD_SUCCESS;
4bf6a362 7803}
fee0f4c6 7804
57a9c8a8
DS
7805static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7806{
7807 json_object *bestpath = json_object_new_object();
7808
7809 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7810 json_object_string_add(bestpath, "asPath", "ignore");
7811
7812 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7813 json_object_string_add(bestpath, "asPath", "confed");
7814
7815 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7816 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7817 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7818 "as-set");
7819 else
a4d82a8a 7820 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7821 "true");
7822 } else
a4d82a8a 7823 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7824
7825 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7826 json_object_string_add(bestpath, "compareRouterId", "true");
7827 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7828 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7829 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7830 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7831 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7832 json_object_string_add(bestpath, "med",
7833 "missing-as-worst");
7834 else
7835 json_object_string_add(bestpath, "med", "true");
7836 }
7837
7838 json_object_object_add(json, "bestPath", bestpath);
7839}
7840
3577f1c5
DD
7841/* Print the error code/subcode for why the peer is down */
7842static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
7843 json_object *json_peer, bool use_json)
7844{
7845 const char *code_str;
7846 const char *subcode_str;
7847
7848 if (use_json) {
7849 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
7850 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
7851 char errorcodesubcode_hexstr[5];
7852 char errorcodesubcode_str[256];
7853
7854 code_str = bgp_notify_code_str(peer->notify.code);
7855 subcode_str = bgp_notify_subcode_str(
7856 peer->notify.code,
7857 peer->notify.subcode);
7858
7859 sprintf(errorcodesubcode_hexstr, "%02X%02X",
7860 peer->notify.code, peer->notify.subcode);
7861 json_object_string_add(json_peer,
7862 "lastErrorCodeSubcode",
7863 errorcodesubcode_hexstr);
7864 snprintf(errorcodesubcode_str, 255, "%s%s",
7865 code_str, subcode_str);
7866 json_object_string_add(json_peer,
7867 "lastNotificationReason",
7868 errorcodesubcode_str);
7869 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
7870 && peer->notify.code == BGP_NOTIFY_CEASE
7871 && (peer->notify.subcode
7872 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
7873 || peer->notify.subcode
7874 == BGP_NOTIFY_CEASE_ADMIN_RESET)
7875 && peer->notify.length) {
7876 char msgbuf[1024];
7877 const char *msg_str;
7878
7879 msg_str = bgp_notify_admin_message(
7880 msgbuf, sizeof(msgbuf),
7881 (uint8_t *)peer->notify.data,
7882 peer->notify.length);
7883 if (msg_str)
7884 json_object_string_add(
7885 json_peer,
7886 "lastShutdownDescription",
7887 msg_str);
7888 }
7889
c258527b 7890 }
3577f1c5
DD
7891 json_object_string_add(json_peer, "lastResetDueTo",
7892 peer_down_str[(int)peer->last_reset]);
05912a17
DD
7893 json_object_int_add(json_peer, "lastResetCode",
7894 peer->last_reset);
3577f1c5
DD
7895 } else {
7896 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
7897 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
7898 code_str = bgp_notify_code_str(peer->notify.code);
7899 subcode_str =
7900 bgp_notify_subcode_str(peer->notify.code,
7901 peer->notify.subcode);
7902 vty_out(vty, " Notification %s (%s%s)\n",
7903 peer->last_reset == PEER_DOWN_NOTIFY_SEND
7904 ? "sent"
7905 : "received",
7906 code_str, subcode_str);
7907 } else {
7908 vty_out(vty, " %s\n",
7909 peer_down_str[(int)peer->last_reset]);
7910 }
7911 }
7912}
7913
7914static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
7915 safi_t safi)
7916{
7917 return ((peer->status != Established) ||
7918 !peer->afc_recv[afi][safi]);
7919}
7920
7921static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
7922 struct peer *peer, json_object *json_peer,
7923 int max_neighbor_width, bool use_json)
7924{
7925 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7926 int len;
7927
7928 if (use_json) {
7929 if (peer_dynamic_neighbor(peer))
7930 json_object_boolean_true_add(json_peer,
7931 "dynamicPeer");
7932 if (peer->hostname)
7933 json_object_string_add(json_peer, "hostname",
7934 peer->hostname);
7935
7936 if (peer->domainname)
7937 json_object_string_add(json_peer, "domainname",
7938 peer->domainname);
7939 json_object_int_add(json_peer, "connectionsEstablished",
7940 peer->established);
7941 json_object_int_add(json_peer, "connectionsDropped",
7942 peer->dropped);
7943 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7944 use_json, json_peer);
7945 if (peer->status == Established)
7946 json_object_string_add(json_peer, "lastResetDueTo",
7947 "AFI/SAFI Not Negotiated");
7948 else
7949 bgp_show_peer_reset(NULL, peer, json_peer, true);
7950 } else {
7951 dn_flag[1] = '\0';
7952 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
7953 if (peer->hostname
7954 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7955 len = vty_out(vty, "%s%s(%s)", dn_flag,
7956 peer->hostname, peer->host);
7957 else
7958 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7959
7960 /* pad the neighbor column with spaces */
7961 if (len < max_neighbor_width)
7962 vty_out(vty, "%*s", max_neighbor_width - len,
7963 " ");
7964 vty_out(vty, "%7d %7d %8s", peer->established,
7965 peer->dropped,
7966 peer_uptime(peer->uptime, timebuf,
7967 BGP_UPTIME_LEN, 0, NULL));
7968 if (peer->status == Established)
7969 vty_out(vty, " AFI/SAFI Not Negotiated\n");
7970 else
7971 bgp_show_peer_reset(vty, peer, NULL,
7972 false);
7973 }
7974}
c258527b 7975
3577f1c5 7976
718e3744 7977/* Show BGP peer's summary information. */
d62a17ae 7978static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
3577f1c5 7979 bool show_failed, bool use_json)
d62a17ae 7980{
7981 struct peer *peer;
7982 struct listnode *node, *nnode;
7983 unsigned int count = 0, dn_count = 0;
7984 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7985 char neighbor_buf[VTY_BUFSIZ];
7986 int neighbor_col_default_width = 16;
3577f1c5 7987 int len, failed_count = 0;
d62a17ae 7988 int max_neighbor_width = 0;
7989 int pfx_rcd_safi;
3c13337d 7990 json_object *json = NULL;
d62a17ae 7991 json_object *json_peer = NULL;
7992 json_object *json_peers = NULL;
50e05855 7993 struct peer_af *paf;
d62a17ae 7994
7995 /* labeled-unicast routes are installed in the unicast table so in order
7996 * to
7997 * display the correct PfxRcd value we must look at SAFI_UNICAST
7998 */
3577f1c5 7999
d62a17ae 8000 if (safi == SAFI_LABELED_UNICAST)
8001 pfx_rcd_safi = SAFI_UNICAST;
8002 else
8003 pfx_rcd_safi = safi;
8004
8005 if (use_json) {
3c13337d 8006 json = json_object_new_object();
d62a17ae 8007 json_peers = json_object_new_object();
3577f1c5
DD
8008 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8009 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8010 continue;
8011
8012 if (peer->afc[afi][safi]) {
8013 /* See if we have at least a single failed peer */
8014 if (bgp_has_peer_failed(peer, afi, safi))
8015 failed_count++;
8016 count++;
8017 }
8018 if (peer_dynamic_neighbor(peer))
8019 dn_count++;
8020 }
c258527b 8021
d62a17ae 8022 } else {
8023 /* Loop over all neighbors that will be displayed to determine
8024 * how many
8025 * characters are needed for the Neighbor column
8026 */
8027 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8028 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8029 continue;
8030
8031 if (peer->afc[afi][safi]) {
8032 memset(dn_flag, '\0', sizeof(dn_flag));
8033 if (peer_dynamic_neighbor(peer))
8034 dn_flag[0] = '*';
8035
8036 if (peer->hostname
8037 && bgp_flag_check(bgp,
8038 BGP_FLAG_SHOW_HOSTNAME))
8039 sprintf(neighbor_buf, "%s%s(%s) ",
8040 dn_flag, peer->hostname,
8041 peer->host);
8042 else
8043 sprintf(neighbor_buf, "%s%s ", dn_flag,
8044 peer->host);
8045
8046 len = strlen(neighbor_buf);
8047
8048 if (len > max_neighbor_width)
8049 max_neighbor_width = len;
c258527b 8050
3577f1c5
DD
8051 /* See if we have at least a single failed peer */
8052 if (bgp_has_peer_failed(peer, afi, safi))
8053 failed_count++;
8054 count++;
d62a17ae 8055 }
8056 }
f933309e 8057
d62a17ae 8058 /* Originally we displayed the Neighbor column as 16
8059 * characters wide so make that the default
8060 */
8061 if (max_neighbor_width < neighbor_col_default_width)
8062 max_neighbor_width = neighbor_col_default_width;
8063 }
f933309e 8064
3577f1c5
DD
8065 if (show_failed && !failed_count) {
8066 if (use_json) {
8067 json_object_int_add(json, "failedPeersCount", 0);
8068 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 8069 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
8070
8071 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8072 json, JSON_C_TO_STRING_PRETTY));
8073 json_object_free(json);
8074 } else {
8075 vty_out(vty, "%% No failed BGP neighbors found\n");
8076 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8077 }
8078 return CMD_SUCCESS;
8079 }
c258527b 8080
3577f1c5 8081 count = 0; /* Reset the value as its used again */
d62a17ae 8082 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8083 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8084 continue;
8085
ea47320b
DL
8086 if (!peer->afc[afi][safi])
8087 continue;
d62a17ae 8088
ea47320b
DL
8089 if (!count) {
8090 unsigned long ents;
8091 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 8092 int64_t vrf_id_ui;
d62a17ae 8093
a4d82a8a
PZ
8094 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8095 ? -1
8096 : (int64_t)bgp->vrf_id;
ea47320b
DL
8097
8098 /* Usage summary and header */
8099 if (use_json) {
8100 json_object_string_add(
8101 json, "routerId",
8102 inet_ntoa(bgp->router_id));
60466a63
QY
8103 json_object_int_add(json, "as", bgp->as);
8104 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
8105 json_object_string_add(
8106 json, "vrfName",
8107 (bgp->inst_type
8108 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8109 ? VRF_DEFAULT_NAME
ea47320b
DL
8110 : bgp->name);
8111 } else {
8112 vty_out(vty,
8113 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 8114 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
8115 bgp->vrf_id == VRF_UNKNOWN
8116 ? -1
8117 : (int)bgp->vrf_id);
ea47320b
DL
8118 vty_out(vty, "\n");
8119 }
d62a17ae 8120
ea47320b 8121 if (bgp_update_delay_configured(bgp)) {
d62a17ae 8122 if (use_json) {
ea47320b 8123 json_object_int_add(
60466a63 8124 json, "updateDelayLimit",
ea47320b 8125 bgp->v_update_delay);
d62a17ae 8126
ea47320b
DL
8127 if (bgp->v_update_delay
8128 != bgp->v_establish_wait)
d62a17ae 8129 json_object_int_add(
8130 json,
ea47320b
DL
8131 "updateDelayEstablishWait",
8132 bgp->v_establish_wait);
d62a17ae 8133
60466a63 8134 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
8135 json_object_string_add(
8136 json,
8137 "updateDelayFirstNeighbor",
8138 bgp->update_delay_begin_time);
8139 json_object_boolean_true_add(
8140 json,
8141 "updateDelayInProgress");
8142 } else {
8143 if (bgp->update_delay_over) {
d62a17ae 8144 json_object_string_add(
8145 json,
8146 "updateDelayFirstNeighbor",
8147 bgp->update_delay_begin_time);
ea47320b 8148 json_object_string_add(
d62a17ae 8149 json,
ea47320b
DL
8150 "updateDelayBestpathResumed",
8151 bgp->update_delay_end_time);
8152 json_object_string_add(
d62a17ae 8153 json,
ea47320b
DL
8154 "updateDelayZebraUpdateResume",
8155 bgp->update_delay_zebra_resume_time);
8156 json_object_string_add(
8157 json,
8158 "updateDelayPeerUpdateResume",
8159 bgp->update_delay_peers_resume_time);
d62a17ae 8160 }
ea47320b
DL
8161 }
8162 } else {
8163 vty_out(vty,
8164 "Read-only mode update-delay limit: %d seconds\n",
8165 bgp->v_update_delay);
8166 if (bgp->v_update_delay
8167 != bgp->v_establish_wait)
d62a17ae 8168 vty_out(vty,
ea47320b
DL
8169 " Establish wait: %d seconds\n",
8170 bgp->v_establish_wait);
d62a17ae 8171
60466a63 8172 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
8173 vty_out(vty,
8174 " First neighbor established: %s\n",
8175 bgp->update_delay_begin_time);
8176 vty_out(vty,
8177 " Delay in progress\n");
8178 } else {
8179 if (bgp->update_delay_over) {
d62a17ae 8180 vty_out(vty,
8181 " First neighbor established: %s\n",
8182 bgp->update_delay_begin_time);
8183 vty_out(vty,
ea47320b
DL
8184 " Best-paths resumed: %s\n",
8185 bgp->update_delay_end_time);
8186 vty_out(vty,
8187 " zebra update resumed: %s\n",
8188 bgp->update_delay_zebra_resume_time);
8189 vty_out(vty,
8190 " peers update resumed: %s\n",
8191 bgp->update_delay_peers_resume_time);
d62a17ae 8192 }
8193 }
8194 }
ea47320b 8195 }
d62a17ae 8196
ea47320b
DL
8197 if (use_json) {
8198 if (bgp_maxmed_onstartup_configured(bgp)
8199 && bgp->maxmed_active)
8200 json_object_boolean_true_add(
60466a63 8201 json, "maxMedOnStartup");
ea47320b
DL
8202 if (bgp->v_maxmed_admin)
8203 json_object_boolean_true_add(
60466a63 8204 json, "maxMedAdministrative");
d62a17ae 8205
ea47320b
DL
8206 json_object_int_add(
8207 json, "tableVersion",
60466a63 8208 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 8209
60466a63
QY
8210 ents = bgp_table_count(bgp->rib[afi][safi]);
8211 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
8212 json_object_int_add(
8213 json, "ribMemory",
8214 ents * sizeof(struct bgp_node));
d62a17ae 8215
210ec2a0 8216 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
8217 json_object_int_add(json, "peerCount", ents);
8218 json_object_int_add(json, "peerMemory",
8219 ents * sizeof(struct peer));
d62a17ae 8220
ea47320b
DL
8221 if ((ents = listcount(bgp->group))) {
8222 json_object_int_add(
60466a63 8223 json, "peerGroupCount", ents);
ea47320b
DL
8224 json_object_int_add(
8225 json, "peerGroupMemory",
996c9314
LB
8226 ents * sizeof(struct
8227 peer_group));
ea47320b 8228 }
d62a17ae 8229
ea47320b
DL
8230 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8231 BGP_CONFIG_DAMPENING))
8232 json_object_boolean_true_add(
60466a63 8233 json, "dampeningEnabled");
ea47320b
DL
8234 } else {
8235 if (bgp_maxmed_onstartup_configured(bgp)
8236 && bgp->maxmed_active)
d62a17ae 8237 vty_out(vty,
ea47320b
DL
8238 "Max-med on-startup active\n");
8239 if (bgp->v_maxmed_admin)
d62a17ae 8240 vty_out(vty,
ea47320b 8241 "Max-med administrative active\n");
d62a17ae 8242
60466a63
QY
8243 vty_out(vty, "BGP table version %" PRIu64 "\n",
8244 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 8245
60466a63 8246 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
8247 vty_out(vty,
8248 "RIB entries %ld, using %s of memory\n",
8249 ents,
996c9314
LB
8250 mtype_memstr(memstrbuf,
8251 sizeof(memstrbuf),
8252 ents * sizeof(struct
8253 bgp_node)));
ea47320b
DL
8254
8255 /* Peer related usage */
210ec2a0 8256 ents = bgp->af_peer_count[afi][safi];
60466a63 8257 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
8258 ents,
8259 mtype_memstr(
60466a63
QY
8260 memstrbuf, sizeof(memstrbuf),
8261 ents * sizeof(struct peer)));
ea47320b
DL
8262
8263 if ((ents = listcount(bgp->group)))
d62a17ae 8264 vty_out(vty,
ea47320b 8265 "Peer groups %ld, using %s of memory\n",
d62a17ae 8266 ents,
8267 mtype_memstr(
8268 memstrbuf,
8269 sizeof(memstrbuf),
996c9314
LB
8270 ents * sizeof(struct
8271 peer_group)));
d62a17ae 8272
ea47320b
DL
8273 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8274 BGP_CONFIG_DAMPENING))
60466a63 8275 vty_out(vty, "Dampening enabled.\n");
ea47320b 8276 vty_out(vty, "\n");
d62a17ae 8277
ea47320b
DL
8278 /* Subtract 8 here because 'Neighbor' is
8279 * 8 characters */
8280 vty_out(vty, "Neighbor");
60466a63
QY
8281 vty_out(vty, "%*s", max_neighbor_width - 8,
8282 " ");
3577f1c5
DD
8283 if (show_failed)
8284 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
8285 else
8286 vty_out(vty,
ea47320b 8287 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 8288 }
ea47320b 8289 }
d62a17ae 8290
ea47320b 8291 count++;
3577f1c5
DD
8292 /* Works for both failed & successful cases */
8293 if (peer_dynamic_neighbor(peer))
8294 dn_count++;
d62a17ae 8295
ea47320b 8296 if (use_json) {
3577f1c5
DD
8297 json_peer = NULL;
8298
8299 if (show_failed &&
8300 bgp_has_peer_failed(peer, afi, safi)) {
8301 json_peer = json_object_new_object();
8302 bgp_show_failed_summary(vty, bgp, peer,
8303 json_peer, 0, use_json);
8304 } else if (!show_failed) {
8305 json_peer = json_object_new_object();
8306 if (peer_dynamic_neighbor(peer)) {
8307 json_object_boolean_true_add(json_peer,
8308 "dynamicPeer");
8309 }
d62a17ae 8310
3577f1c5
DD
8311 if (peer->hostname)
8312 json_object_string_add(json_peer, "hostname",
8313 peer->hostname);
8314
8315 if (peer->domainname)
8316 json_object_string_add(json_peer, "domainname",
8317 peer->domainname);
8318
8319 json_object_int_add(json_peer, "remoteAs", peer->as);
8320 json_object_int_add(json_peer, "version", 4);
8321 json_object_int_add(json_peer, "msgRcvd",
8322 PEER_TOTAL_RX(peer));
8323 json_object_int_add(json_peer, "msgSent",
8324 PEER_TOTAL_TX(peer));
8325
8326 json_object_int_add(json_peer, "tableVersion",
8327 peer->version[afi][safi]);
8328 json_object_int_add(json_peer, "outq",
8329 peer->obuf->count);
8330 json_object_int_add(json_peer, "inq", 0);
8331 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8332 use_json, json_peer);
8333
8334 /*
8335 * Adding "pfxRcd" field to match with the corresponding
8336 * CLI. "prefixReceivedCount" will be deprecated in
8337 * future.
8338 */
8339 json_object_int_add(json_peer, "prefixReceivedCount",
8340 peer->pcount[afi][pfx_rcd_safi]);
8341 json_object_int_add(json_peer, "pfxRcd",
8342 peer->pcount[afi][pfx_rcd_safi]);
8343
8344 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8345 if (paf && PAF_SUBGRP(paf))
8346 json_object_int_add(json_peer,
8347 "pfxSnt",
8348 (PAF_SUBGRP(paf))->scount);
8349 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8350 json_object_string_add(json_peer, "state",
8351 "Idle (Admin)");
8352 else if (peer->afc_recv[afi][safi])
8353 json_object_string_add(
8354 json_peer, "state",
8355 lookup_msg(bgp_status_msg, peer->status,
8356 NULL));
8357 else if (CHECK_FLAG(peer->sflags,
8358 PEER_STATUS_PREFIX_OVERFLOW))
8359 json_object_string_add(json_peer, "state",
8360 "Idle (PfxCt)");
8361 else
8362 json_object_string_add(
8363 json_peer, "state",
8364 lookup_msg(bgp_status_msg, peer->status,
8365 NULL));
200116db
DD
8366 json_object_int_add(json_peer, "connectionsEstablished",
8367 peer->established);
8368 json_object_int_add(json_peer, "connectionsDropped",
8369 peer->dropped);
b4e9dcba 8370 }
3577f1c5
DD
8371 /* Avoid creating empty peer dicts in JSON */
8372 if (json_peer == NULL)
8373 continue;
ea47320b
DL
8374
8375 if (peer->conf_if)
60466a63 8376 json_object_string_add(json_peer, "idType",
ea47320b
DL
8377 "interface");
8378 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
8379 json_object_string_add(json_peer, "idType",
8380 "ipv4");
ea47320b 8381 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
8382 json_object_string_add(json_peer, "idType",
8383 "ipv6");
ea47320b
DL
8384 json_object_object_add(json_peers, peer->host,
8385 json_peer);
8386 } else {
3577f1c5
DD
8387 if (show_failed &&
8388 bgp_has_peer_failed(peer, afi, safi)) {
8389 bgp_show_failed_summary(vty, bgp, peer, NULL,
8390 max_neighbor_width,
8391 use_json);
8392 } else if (!show_failed) {
8393 memset(dn_flag, '\0', sizeof(dn_flag));
8394 if (peer_dynamic_neighbor(peer)) {
8395 dn_flag[0] = '*';
8396 }
d62a17ae 8397
3577f1c5
DD
8398 if (peer->hostname
8399 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8400 len = vty_out(vty, "%s%s(%s)", dn_flag,
8401 peer->hostname, peer->host);
d62a17ae 8402 else
3577f1c5
DD
8403 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8404
8405 /* pad the neighbor column with spaces */
8406 if (len < max_neighbor_width)
8407 vty_out(vty, "%*s", max_neighbor_width - len,
8408 " ");
8409
8410 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8411 peer->as, PEER_TOTAL_RX(peer),
8412 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8413 0, peer->obuf->count,
8414 peer_uptime(peer->uptime, timebuf,
8415 BGP_UPTIME_LEN, 0, NULL));
8416
8417 if (peer->status == Established)
8418 if (peer->afc_recv[afi][safi])
a0a87037
DA
8419 vty_out(vty, " %12" PRIu32,
8420 peer->pcount
8421 [afi]
8422 [pfx_rcd_safi]);
3577f1c5
DD
8423 else
8424 vty_out(vty, " NoNeg");
8425 else {
8426 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8427 vty_out(vty, " Idle (Admin)");
8428 else if (CHECK_FLAG(
8429 peer->sflags,
8430 PEER_STATUS_PREFIX_OVERFLOW))
8431 vty_out(vty, " Idle (PfxCt)");
8432 else
8433 vty_out(vty, " %12s",
8434 lookup_msg(bgp_status_msg,
8435 peer->status, NULL));
8436 }
8437 vty_out(vty, "\n");
d62a17ae 8438 }
3577f1c5 8439
d62a17ae 8440 }
8441 }
f933309e 8442
d62a17ae 8443 if (use_json) {
8444 json_object_object_add(json, "peers", json_peers);
3577f1c5 8445 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 8446 json_object_int_add(json, "totalPeers", count);
8447 json_object_int_add(json, "dynamicPeers", dn_count);
8448
3577f1c5
DD
8449 if (!show_failed)
8450 bgp_show_bestpath_json(bgp, json);
57a9c8a8 8451
996c9314
LB
8452 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8453 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8454 json_object_free(json);
8455 } else {
8456 if (count)
8457 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8458 else {
d6ceaca3 8459 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 8460 get_afi_safi_str(afi, safi, false));
d62a17ae 8461 }
b05a1c8b 8462
d6ceaca3 8463 if (dn_count) {
d62a17ae 8464 vty_out(vty, "* - dynamic neighbor\n");
8465 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8466 dn_count, bgp->dynamic_neighbors_limit);
8467 }
8468 }
1ff9a340 8469
d62a17ae 8470 return CMD_SUCCESS;
718e3744 8471}
8472
d62a17ae 8473static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
3577f1c5 8474 int safi, bool show_failed, bool use_json)
d62a17ae 8475{
8476 int is_first = 1;
8477 int afi_wildcard = (afi == AFI_MAX);
8478 int safi_wildcard = (safi == SAFI_MAX);
8479 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 8480 bool nbr_output = false;
d62a17ae 8481
8482 if (use_json && is_wildcard)
8483 vty_out(vty, "{\n");
8484 if (afi_wildcard)
8485 afi = 1; /* AFI_IP */
8486 while (afi < AFI_MAX) {
8487 if (safi_wildcard)
8488 safi = 1; /* SAFI_UNICAST */
8489 while (safi < SAFI_MAX) {
318cac96 8490 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 8491 nbr_output = true;
f86897b9 8492
d62a17ae 8493 if (is_wildcard) {
8494 /*
8495 * So limit output to those afi/safi
8496 * pairs that
8497 * actualy have something interesting in
8498 * them
8499 */
8500 if (use_json) {
d62a17ae 8501 if (!is_first)
8502 vty_out(vty, ",\n");
8503 else
8504 is_first = 0;
8505
8506 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
8507 get_afi_safi_str(afi,
8508 safi,
8509 true));
d62a17ae 8510 } else {
8511 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
8512 get_afi_safi_str(afi,
8513 safi,
8514 false));
d62a17ae 8515 }
8516 }
3577f1c5
DD
8517 bgp_show_summary(vty, bgp, afi, safi, show_failed,
8518 use_json);
d62a17ae 8519 }
8520 safi++;
d62a17ae 8521 if (!safi_wildcard)
8522 safi = SAFI_MAX;
8523 }
8524 afi++;
ee851c8c 8525 if (!afi_wildcard)
d62a17ae 8526 afi = AFI_MAX;
8527 }
8528
8529 if (use_json && is_wildcard)
8530 vty_out(vty, "}\n");
ca61fd25
DS
8531 else if (!nbr_output) {
8532 if (use_json)
8533 vty_out(vty, "{}\n");
8534 else
8535 vty_out(vty, "%% No BGP neighbors found\n");
8536 }
d62a17ae 8537}
8538
8539static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5
DD
8540 safi_t safi, bool show_failed,
8541 bool use_json)
d62a17ae 8542{
8543 struct listnode *node, *nnode;
8544 struct bgp *bgp;
d62a17ae 8545 int is_first = 1;
9f049418 8546 bool nbr_output = false;
d62a17ae 8547
8548 if (use_json)
8549 vty_out(vty, "{\n");
8550
8551 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 8552 nbr_output = true;
d62a17ae 8553 if (use_json) {
d62a17ae 8554 if (!is_first)
8555 vty_out(vty, ",\n");
8556 else
8557 is_first = 0;
8558
8559 vty_out(vty, "\"%s\":",
8560 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8561 ? VRF_DEFAULT_NAME
d62a17ae 8562 : bgp->name);
8563 } else {
8564 vty_out(vty, "\nInstance %s:\n",
8565 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8566 ? VRF_DEFAULT_NAME
d62a17ae 8567 : bgp->name);
8568 }
3577f1c5
DD
8569 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8570 use_json);
d62a17ae 8571 }
8572
8573 if (use_json)
8574 vty_out(vty, "}\n");
9f049418
DS
8575 else if (!nbr_output)
8576 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 8577}
8578
8579int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
3577f1c5 8580 safi_t safi, bool show_failed, bool use_json)
d62a17ae 8581{
8582 struct bgp *bgp;
8583
8584 if (name) {
8585 if (strmatch(name, "all")) {
8586 bgp_show_all_instances_summary_vty(vty, afi, safi,
3577f1c5 8587 show_failed,
d62a17ae 8588 use_json);
8589 return CMD_SUCCESS;
8590 } else {
8591 bgp = bgp_lookup_by_name(name);
8592
8593 if (!bgp) {
8594 if (use_json)
8595 vty_out(vty, "{}\n");
8596 else
8597 vty_out(vty,
ca61fd25 8598 "%% BGP instance not found\n");
d62a17ae 8599 return CMD_WARNING;
8600 }
8601
f86897b9 8602 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
3577f1c5 8603 show_failed, use_json);
d62a17ae 8604 return CMD_SUCCESS;
8605 }
8606 }
8607
8608 bgp = bgp_get_default();
8609
8610 if (bgp)
3577f1c5
DD
8611 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8612 use_json);
9f049418 8613 else {
ca61fd25
DS
8614 if (use_json)
8615 vty_out(vty, "{}\n");
8616 else
8617 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
8618 return CMD_WARNING;
8619 }
d62a17ae 8620
8621 return CMD_SUCCESS;
4fb25c53
DW
8622}
8623
716b2d8a 8624/* `show [ip] bgp summary' commands. */
47fc97cc 8625DEFUN (show_ip_bgp_summary,
718e3744 8626 show_ip_bgp_summary_cmd,
3577f1c5 8627 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]",
718e3744 8628 SHOW_STR
8629 IP_STR
8630 BGP_STR
8386ac43 8631 BGP_INSTANCE_HELP_STR
46f296b4 8632 BGP_AFI_HELP_STR
dd6bd0f1 8633 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8634 "Summary of BGP neighbor status\n"
3577f1c5 8635 "Show only sessions not in Established state\n"
9973d184 8636 JSON_STR)
718e3744 8637{
d62a17ae 8638 char *vrf = NULL;
8639 afi_t afi = AFI_MAX;
8640 safi_t safi = SAFI_MAX;
3577f1c5 8641 bool show_failed = false;
d62a17ae 8642
8643 int idx = 0;
8644
8645 /* show [ip] bgp */
8646 if (argv_find(argv, argc, "ip", &idx))
8647 afi = AFI_IP;
9a8bdf1c
PG
8648 /* [<vrf> VIEWVRFNAME] */
8649 if (argv_find(argv, argc, "vrf", &idx)) {
8650 vrf = argv[idx + 1]->arg;
8651 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8652 vrf = NULL;
8653 } else if (argv_find(argv, argc, "view", &idx))
8654 /* [<view> VIEWVRFNAME] */
8655 vrf = argv[idx + 1]->arg;
d62a17ae 8656 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8657 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8658 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8659 }
8660
3577f1c5
DD
8661 if (argv_find(argv, argc, "failed", &idx))
8662 show_failed = true;
8663
9f049418 8664 bool uj = use_json(argc, argv);
d62a17ae 8665
3577f1c5 8666 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj);
d62a17ae 8667}
8668
5cb5f4d0 8669const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 8670{
5cb5f4d0
DD
8671 if (for_json)
8672 return get_afi_safi_json_str(afi, safi);
d62a17ae 8673 else
5cb5f4d0 8674 return get_afi_safi_vty_str(afi, safi);
27162734
LB
8675}
8676
718e3744 8677/* Show BGP peer's information. */
d1927ebe 8678enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
d62a17ae 8679
8680static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8681 afi_t afi, safi_t safi,
d7c0a89a
QY
8682 uint16_t adv_smcap, uint16_t adv_rmcap,
8683 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 8684 bool use_json, json_object *json_pref)
d62a17ae 8685{
8686 /* Send-Mode */
8687 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8688 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8689 if (use_json) {
8690 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8691 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8692 json_object_string_add(json_pref, "sendMode",
8693 "advertisedAndReceived");
8694 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8695 json_object_string_add(json_pref, "sendMode",
8696 "advertised");
8697 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8698 json_object_string_add(json_pref, "sendMode",
8699 "received");
8700 } else {
8701 vty_out(vty, " Send-mode: ");
8702 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8703 vty_out(vty, "advertised");
8704 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8705 vty_out(vty, "%sreceived",
8706 CHECK_FLAG(p->af_cap[afi][safi],
8707 adv_smcap)
8708 ? ", "
8709 : "");
8710 vty_out(vty, "\n");
8711 }
8712 }
8713
8714 /* Receive-Mode */
8715 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8716 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8717 if (use_json) {
8718 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8719 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8720 json_object_string_add(json_pref, "recvMode",
8721 "advertisedAndReceived");
8722 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8723 json_object_string_add(json_pref, "recvMode",
8724 "advertised");
8725 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8726 json_object_string_add(json_pref, "recvMode",
8727 "received");
8728 } else {
8729 vty_out(vty, " Receive-mode: ");
8730 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8731 vty_out(vty, "advertised");
8732 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8733 vty_out(vty, "%sreceived",
8734 CHECK_FLAG(p->af_cap[afi][safi],
8735 adv_rmcap)
8736 ? ", "
8737 : "");
8738 vty_out(vty, "\n");
8739 }
8740 }
8741}
8742
8743static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 8744 safi_t safi, bool use_json,
d62a17ae 8745 json_object *json_neigh)
8746{
0291c246
MK
8747 struct bgp_filter *filter;
8748 struct peer_af *paf;
8749 char orf_pfx_name[BUFSIZ];
8750 int orf_pfx_count;
8751 json_object *json_af = NULL;
8752 json_object *json_prefA = NULL;
8753 json_object *json_prefB = NULL;
8754 json_object *json_addr = NULL;
d62a17ae 8755
8756 if (use_json) {
8757 json_addr = json_object_new_object();
8758 json_af = json_object_new_object();
8759 filter = &p->filter[afi][safi];
8760
8761 if (peer_group_active(p))
8762 json_object_string_add(json_addr, "peerGroupMember",
8763 p->group->name);
8764
8765 paf = peer_af_find(p, afi, safi);
8766 if (paf && PAF_SUBGRP(paf)) {
8767 json_object_int_add(json_addr, "updateGroupId",
8768 PAF_UPDGRP(paf)->id);
8769 json_object_int_add(json_addr, "subGroupId",
8770 PAF_SUBGRP(paf)->id);
8771 json_object_int_add(json_addr, "packetQueueLength",
8772 bpacket_queue_virtual_length(paf));
8773 }
8774
8775 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8776 || CHECK_FLAG(p->af_cap[afi][safi],
8777 PEER_CAP_ORF_PREFIX_SM_RCV)
8778 || CHECK_FLAG(p->af_cap[afi][safi],
8779 PEER_CAP_ORF_PREFIX_RM_ADV)
8780 || CHECK_FLAG(p->af_cap[afi][safi],
8781 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8782 json_object_int_add(json_af, "orfType",
8783 ORF_TYPE_PREFIX);
8784 json_prefA = json_object_new_object();
8785 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8786 PEER_CAP_ORF_PREFIX_SM_ADV,
8787 PEER_CAP_ORF_PREFIX_RM_ADV,
8788 PEER_CAP_ORF_PREFIX_SM_RCV,
8789 PEER_CAP_ORF_PREFIX_RM_RCV,
8790 use_json, json_prefA);
8791 json_object_object_add(json_af, "orfPrefixList",
8792 json_prefA);
8793 }
8794
8795 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8796 || CHECK_FLAG(p->af_cap[afi][safi],
8797 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8798 || CHECK_FLAG(p->af_cap[afi][safi],
8799 PEER_CAP_ORF_PREFIX_RM_ADV)
8800 || CHECK_FLAG(p->af_cap[afi][safi],
8801 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8802 json_object_int_add(json_af, "orfOldType",
8803 ORF_TYPE_PREFIX_OLD);
8804 json_prefB = json_object_new_object();
8805 bgp_show_peer_afi_orf_cap(
8806 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8807 PEER_CAP_ORF_PREFIX_RM_ADV,
8808 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8809 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8810 json_prefB);
8811 json_object_object_add(json_af, "orfOldPrefixList",
8812 json_prefB);
8813 }
8814
8815 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8816 || CHECK_FLAG(p->af_cap[afi][safi],
8817 PEER_CAP_ORF_PREFIX_SM_RCV)
8818 || CHECK_FLAG(p->af_cap[afi][safi],
8819 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8820 || CHECK_FLAG(p->af_cap[afi][safi],
8821 PEER_CAP_ORF_PREFIX_RM_ADV)
8822 || CHECK_FLAG(p->af_cap[afi][safi],
8823 PEER_CAP_ORF_PREFIX_RM_RCV)
8824 || CHECK_FLAG(p->af_cap[afi][safi],
8825 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8826 json_object_object_add(json_addr, "afDependentCap",
8827 json_af);
8828 else
8829 json_object_free(json_af);
8830
8831 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8832 orf_pfx_count = prefix_bgp_show_prefix_list(
8833 NULL, afi, orf_pfx_name, use_json);
8834
8835 if (CHECK_FLAG(p->af_sflags[afi][safi],
8836 PEER_STATUS_ORF_PREFIX_SEND)
8837 || orf_pfx_count) {
8838 if (CHECK_FLAG(p->af_sflags[afi][safi],
8839 PEER_STATUS_ORF_PREFIX_SEND))
8840 json_object_boolean_true_add(json_neigh,
8841 "orfSent");
8842 if (orf_pfx_count)
8843 json_object_int_add(json_addr, "orfRecvCounter",
8844 orf_pfx_count);
8845 }
8846 if (CHECK_FLAG(p->af_sflags[afi][safi],
8847 PEER_STATUS_ORF_WAIT_REFRESH))
8848 json_object_string_add(
8849 json_addr, "orfFirstUpdate",
8850 "deferredUntilORFOrRouteRefreshRecvd");
8851
8852 if (CHECK_FLAG(p->af_flags[afi][safi],
8853 PEER_FLAG_REFLECTOR_CLIENT))
8854 json_object_boolean_true_add(json_addr,
8855 "routeReflectorClient");
8856 if (CHECK_FLAG(p->af_flags[afi][safi],
8857 PEER_FLAG_RSERVER_CLIENT))
8858 json_object_boolean_true_add(json_addr,
8859 "routeServerClient");
8860 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8861 json_object_boolean_true_add(json_addr,
8862 "inboundSoftConfigPermit");
8863
8864 if (CHECK_FLAG(p->af_flags[afi][safi],
8865 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8866 json_object_boolean_true_add(
8867 json_addr,
8868 "privateAsNumsAllReplacedInUpdatesToNbr");
8869 else if (CHECK_FLAG(p->af_flags[afi][safi],
8870 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8871 json_object_boolean_true_add(
8872 json_addr,
8873 "privateAsNumsReplacedInUpdatesToNbr");
8874 else if (CHECK_FLAG(p->af_flags[afi][safi],
8875 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8876 json_object_boolean_true_add(
8877 json_addr,
8878 "privateAsNumsAllRemovedInUpdatesToNbr");
8879 else if (CHECK_FLAG(p->af_flags[afi][safi],
8880 PEER_FLAG_REMOVE_PRIVATE_AS))
8881 json_object_boolean_true_add(
8882 json_addr,
8883 "privateAsNumsRemovedInUpdatesToNbr");
8884
dcc68b5e
MS
8885 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8886 json_object_boolean_true_add(
8887 json_addr,
8888 bgp_addpath_names(p->addpath_type[afi][safi])
8889 ->type_json_name);
d62a17ae 8890
8891 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8892 json_object_string_add(json_addr,
8893 "overrideASNsInOutboundUpdates",
8894 "ifAspathEqualRemoteAs");
8895
8896 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8897 || CHECK_FLAG(p->af_flags[afi][safi],
8898 PEER_FLAG_FORCE_NEXTHOP_SELF))
8899 json_object_boolean_true_add(json_addr,
8900 "routerAlwaysNextHop");
8901 if (CHECK_FLAG(p->af_flags[afi][safi],
8902 PEER_FLAG_AS_PATH_UNCHANGED))
8903 json_object_boolean_true_add(
8904 json_addr, "unchangedAsPathPropogatedToNbr");
8905 if (CHECK_FLAG(p->af_flags[afi][safi],
8906 PEER_FLAG_NEXTHOP_UNCHANGED))
8907 json_object_boolean_true_add(
8908 json_addr, "unchangedNextHopPropogatedToNbr");
8909 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8910 json_object_boolean_true_add(
8911 json_addr, "unchangedMedPropogatedToNbr");
8912 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8913 || CHECK_FLAG(p->af_flags[afi][safi],
8914 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8915 if (CHECK_FLAG(p->af_flags[afi][safi],
8916 PEER_FLAG_SEND_COMMUNITY)
8917 && CHECK_FLAG(p->af_flags[afi][safi],
8918 PEER_FLAG_SEND_EXT_COMMUNITY))
8919 json_object_string_add(json_addr,
8920 "commAttriSentToNbr",
8921 "extendedAndStandard");
8922 else if (CHECK_FLAG(p->af_flags[afi][safi],
8923 PEER_FLAG_SEND_EXT_COMMUNITY))
8924 json_object_string_add(json_addr,
8925 "commAttriSentToNbr",
8926 "extended");
8927 else
8928 json_object_string_add(json_addr,
8929 "commAttriSentToNbr",
8930 "standard");
8931 }
8932 if (CHECK_FLAG(p->af_flags[afi][safi],
8933 PEER_FLAG_DEFAULT_ORIGINATE)) {
8934 if (p->default_rmap[afi][safi].name)
8935 json_object_string_add(
8936 json_addr, "defaultRouteMap",
8937 p->default_rmap[afi][safi].name);
8938
8939 if (paf && PAF_SUBGRP(paf)
8940 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8941 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8942 json_object_boolean_true_add(json_addr,
8943 "defaultSent");
8944 else
8945 json_object_boolean_true_add(json_addr,
8946 "defaultNotSent");
8947 }
8948
dff8f48d 8949 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8950 if (is_evpn_enabled())
60466a63
QY
8951 json_object_boolean_true_add(
8952 json_addr, "advertiseAllVnis");
dff8f48d
MK
8953 }
8954
d62a17ae 8955 if (filter->plist[FILTER_IN].name
8956 || filter->dlist[FILTER_IN].name
8957 || filter->aslist[FILTER_IN].name
8958 || filter->map[RMAP_IN].name)
8959 json_object_boolean_true_add(json_addr,
8960 "inboundPathPolicyConfig");
8961 if (filter->plist[FILTER_OUT].name
8962 || filter->dlist[FILTER_OUT].name
8963 || filter->aslist[FILTER_OUT].name
8964 || filter->map[RMAP_OUT].name || filter->usmap.name)
8965 json_object_boolean_true_add(
8966 json_addr, "outboundPathPolicyConfig");
8967
8968 /* prefix-list */
8969 if (filter->plist[FILTER_IN].name)
8970 json_object_string_add(json_addr,
8971 "incomingUpdatePrefixFilterList",
8972 filter->plist[FILTER_IN].name);
8973 if (filter->plist[FILTER_OUT].name)
8974 json_object_string_add(json_addr,
8975 "outgoingUpdatePrefixFilterList",
8976 filter->plist[FILTER_OUT].name);
8977
8978 /* distribute-list */
8979 if (filter->dlist[FILTER_IN].name)
8980 json_object_string_add(
8981 json_addr, "incomingUpdateNetworkFilterList",
8982 filter->dlist[FILTER_IN].name);
8983 if (filter->dlist[FILTER_OUT].name)
8984 json_object_string_add(
8985 json_addr, "outgoingUpdateNetworkFilterList",
8986 filter->dlist[FILTER_OUT].name);
8987
8988 /* filter-list. */
8989 if (filter->aslist[FILTER_IN].name)
8990 json_object_string_add(json_addr,
8991 "incomingUpdateAsPathFilterList",
8992 filter->aslist[FILTER_IN].name);
8993 if (filter->aslist[FILTER_OUT].name)
8994 json_object_string_add(json_addr,
8995 "outgoingUpdateAsPathFilterList",
8996 filter->aslist[FILTER_OUT].name);
8997
8998 /* route-map. */
8999 if (filter->map[RMAP_IN].name)
9000 json_object_string_add(
9001 json_addr, "routeMapForIncomingAdvertisements",
9002 filter->map[RMAP_IN].name);
9003 if (filter->map[RMAP_OUT].name)
9004 json_object_string_add(
9005 json_addr, "routeMapForOutgoingAdvertisements",
9006 filter->map[RMAP_OUT].name);
9007
9dac9fc8
DA
9008 /* ebgp-requires-policy (inbound) */
9009 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9010 && !bgp_inbound_policy_exists(p, filter))
9011 json_object_string_add(
9012 json_addr, "inboundEbgpRequiresPolicy",
9013 "Inbound updates discarded due to missing policy");
9014
9015 /* ebgp-requires-policy (outbound) */
9016 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9017 && (!bgp_outbound_policy_exists(p, filter)))
9018 json_object_string_add(
9019 json_addr, "outboundEbgpRequiresPolicy",
9020 "Outbound updates discarded due to missing policy");
9021
d62a17ae 9022 /* unsuppress-map */
9023 if (filter->usmap.name)
9024 json_object_string_add(json_addr,
9025 "selectiveUnsuppressRouteMap",
9026 filter->usmap.name);
9027
9028 /* Receive prefix count */
9029 json_object_int_add(json_addr, "acceptedPrefixCounter",
9030 p->pcount[afi][safi]);
50e05855
AD
9031 if (paf && PAF_SUBGRP(paf))
9032 json_object_int_add(json_addr, "sentPrefixCounter",
9033 (PAF_SUBGRP(paf))->scount);
d62a17ae 9034
9035 /* Maximum prefix */
9036 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9037 json_object_int_add(json_addr, "prefixAllowedMax",
9038 p->pmax[afi][safi]);
9039 if (CHECK_FLAG(p->af_flags[afi][safi],
9040 PEER_FLAG_MAX_PREFIX_WARNING))
9041 json_object_boolean_true_add(
9042 json_addr, "prefixAllowedMaxWarning");
9043 json_object_int_add(json_addr,
9044 "prefixAllowedWarningThresh",
9045 p->pmax_threshold[afi][safi]);
9046 if (p->pmax_restart[afi][safi])
9047 json_object_int_add(
9048 json_addr,
9049 "prefixAllowedRestartIntervalMsecs",
9050 p->pmax_restart[afi][safi] * 60000);
9051 }
5cb5f4d0 9052 json_object_object_add(json_neigh, get_afi_safi_str(afi, safi, true),
d62a17ae 9053 json_addr);
9054
9055 } else {
9056 filter = &p->filter[afi][safi];
9057
9058 vty_out(vty, " For address family: %s\n",
5cb5f4d0 9059 get_afi_safi_str(afi, safi, false));
d62a17ae 9060
9061 if (peer_group_active(p))
9062 vty_out(vty, " %s peer-group member\n",
9063 p->group->name);
9064
9065 paf = peer_af_find(p, afi, safi);
9066 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
9067 vty_out(vty, " Update group %" PRIu64
9068 ", subgroup %" PRIu64 "\n",
d62a17ae 9069 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
9070 vty_out(vty, " Packet Queue length %d\n",
9071 bpacket_queue_virtual_length(paf));
9072 } else {
9073 vty_out(vty, " Not part of any update group\n");
9074 }
9075 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9076 || CHECK_FLAG(p->af_cap[afi][safi],
9077 PEER_CAP_ORF_PREFIX_SM_RCV)
9078 || CHECK_FLAG(p->af_cap[afi][safi],
9079 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9080 || CHECK_FLAG(p->af_cap[afi][safi],
9081 PEER_CAP_ORF_PREFIX_RM_ADV)
9082 || CHECK_FLAG(p->af_cap[afi][safi],
9083 PEER_CAP_ORF_PREFIX_RM_RCV)
9084 || CHECK_FLAG(p->af_cap[afi][safi],
9085 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
9086 vty_out(vty, " AF-dependant capabilities:\n");
9087
9088 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9089 || CHECK_FLAG(p->af_cap[afi][safi],
9090 PEER_CAP_ORF_PREFIX_SM_RCV)
9091 || CHECK_FLAG(p->af_cap[afi][safi],
9092 PEER_CAP_ORF_PREFIX_RM_ADV)
9093 || CHECK_FLAG(p->af_cap[afi][safi],
9094 PEER_CAP_ORF_PREFIX_RM_RCV)) {
9095 vty_out(vty,
9096 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9097 ORF_TYPE_PREFIX);
9098 bgp_show_peer_afi_orf_cap(
9099 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9100 PEER_CAP_ORF_PREFIX_RM_ADV,
9101 PEER_CAP_ORF_PREFIX_SM_RCV,
9102 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
9103 }
9104 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9105 || CHECK_FLAG(p->af_cap[afi][safi],
9106 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9107 || CHECK_FLAG(p->af_cap[afi][safi],
9108 PEER_CAP_ORF_PREFIX_RM_ADV)
9109 || CHECK_FLAG(p->af_cap[afi][safi],
9110 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
9111 vty_out(vty,
9112 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9113 ORF_TYPE_PREFIX_OLD);
9114 bgp_show_peer_afi_orf_cap(
9115 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9116 PEER_CAP_ORF_PREFIX_RM_ADV,
9117 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
9118 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
9119 }
9120
9121 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
9122 orf_pfx_count = prefix_bgp_show_prefix_list(
9123 NULL, afi, orf_pfx_name, use_json);
9124
9125 if (CHECK_FLAG(p->af_sflags[afi][safi],
9126 PEER_STATUS_ORF_PREFIX_SEND)
9127 || orf_pfx_count) {
9128 vty_out(vty, " Outbound Route Filter (ORF):");
9129 if (CHECK_FLAG(p->af_sflags[afi][safi],
9130 PEER_STATUS_ORF_PREFIX_SEND))
9131 vty_out(vty, " sent;");
9132 if (orf_pfx_count)
9133 vty_out(vty, " received (%d entries)",
9134 orf_pfx_count);
9135 vty_out(vty, "\n");
9136 }
9137 if (CHECK_FLAG(p->af_sflags[afi][safi],
9138 PEER_STATUS_ORF_WAIT_REFRESH))
9139 vty_out(vty,
9140 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
9141
9142 if (CHECK_FLAG(p->af_flags[afi][safi],
9143 PEER_FLAG_REFLECTOR_CLIENT))
9144 vty_out(vty, " Route-Reflector Client\n");
9145 if (CHECK_FLAG(p->af_flags[afi][safi],
9146 PEER_FLAG_RSERVER_CLIENT))
9147 vty_out(vty, " Route-Server Client\n");
9148 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9149 vty_out(vty,
9150 " Inbound soft reconfiguration allowed\n");
9151
9152 if (CHECK_FLAG(p->af_flags[afi][safi],
9153 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9154 vty_out(vty,
9155 " Private AS numbers (all) replaced in updates to this neighbor\n");
9156 else if (CHECK_FLAG(p->af_flags[afi][safi],
9157 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9158 vty_out(vty,
9159 " Private AS numbers replaced in updates to this neighbor\n");
9160 else if (CHECK_FLAG(p->af_flags[afi][safi],
9161 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9162 vty_out(vty,
9163 " Private AS numbers (all) removed in updates to this neighbor\n");
9164 else if (CHECK_FLAG(p->af_flags[afi][safi],
9165 PEER_FLAG_REMOVE_PRIVATE_AS))
9166 vty_out(vty,
9167 " Private AS numbers removed in updates to this neighbor\n");
9168
dcc68b5e
MS
9169 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9170 vty_out(vty, " %s\n",
9171 bgp_addpath_names(p->addpath_type[afi][safi])
9172 ->human_description);
d62a17ae 9173
9174 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9175 vty_out(vty,
9176 " Override ASNs in outbound updates if aspath equals remote-as\n");
9177
9178 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9179 || CHECK_FLAG(p->af_flags[afi][safi],
9180 PEER_FLAG_FORCE_NEXTHOP_SELF))
9181 vty_out(vty, " NEXT_HOP is always this router\n");
9182 if (CHECK_FLAG(p->af_flags[afi][safi],
9183 PEER_FLAG_AS_PATH_UNCHANGED))
9184 vty_out(vty,
9185 " AS_PATH is propagated unchanged to this neighbor\n");
9186 if (CHECK_FLAG(p->af_flags[afi][safi],
9187 PEER_FLAG_NEXTHOP_UNCHANGED))
9188 vty_out(vty,
9189 " NEXT_HOP is propagated unchanged to this neighbor\n");
9190 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9191 vty_out(vty,
9192 " MED is propagated unchanged to this neighbor\n");
9193 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9194 || CHECK_FLAG(p->af_flags[afi][safi],
9195 PEER_FLAG_SEND_EXT_COMMUNITY)
9196 || CHECK_FLAG(p->af_flags[afi][safi],
9197 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9198 vty_out(vty,
9199 " Community attribute sent to this neighbor");
9200 if (CHECK_FLAG(p->af_flags[afi][safi],
9201 PEER_FLAG_SEND_COMMUNITY)
9202 && CHECK_FLAG(p->af_flags[afi][safi],
9203 PEER_FLAG_SEND_EXT_COMMUNITY)
9204 && CHECK_FLAG(p->af_flags[afi][safi],
9205 PEER_FLAG_SEND_LARGE_COMMUNITY))
9206 vty_out(vty, "(all)\n");
9207 else if (CHECK_FLAG(p->af_flags[afi][safi],
9208 PEER_FLAG_SEND_LARGE_COMMUNITY))
9209 vty_out(vty, "(large)\n");
9210 else if (CHECK_FLAG(p->af_flags[afi][safi],
9211 PEER_FLAG_SEND_EXT_COMMUNITY))
9212 vty_out(vty, "(extended)\n");
9213 else
9214 vty_out(vty, "(standard)\n");
9215 }
9216 if (CHECK_FLAG(p->af_flags[afi][safi],
9217 PEER_FLAG_DEFAULT_ORIGINATE)) {
9218 vty_out(vty, " Default information originate,");
9219
9220 if (p->default_rmap[afi][safi].name)
9221 vty_out(vty, " default route-map %s%s,",
9222 p->default_rmap[afi][safi].map ? "*"
9223 : "",
9224 p->default_rmap[afi][safi].name);
9225 if (paf && PAF_SUBGRP(paf)
9226 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9227 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9228 vty_out(vty, " default sent\n");
9229 else
9230 vty_out(vty, " default not sent\n");
9231 }
9232
dff8f48d
MK
9233 /* advertise-vni-all */
9234 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 9235 if (is_evpn_enabled())
dff8f48d
MK
9236 vty_out(vty, " advertise-all-vni\n");
9237 }
9238
d62a17ae 9239 if (filter->plist[FILTER_IN].name
9240 || filter->dlist[FILTER_IN].name
9241 || filter->aslist[FILTER_IN].name
9242 || filter->map[RMAP_IN].name)
9243 vty_out(vty, " Inbound path policy configured\n");
9244 if (filter->plist[FILTER_OUT].name
9245 || filter->dlist[FILTER_OUT].name
9246 || filter->aslist[FILTER_OUT].name
9247 || filter->map[RMAP_OUT].name || filter->usmap.name)
9248 vty_out(vty, " Outbound path policy configured\n");
9249
9250 /* prefix-list */
9251 if (filter->plist[FILTER_IN].name)
9252 vty_out(vty,
9253 " Incoming update prefix filter list is %s%s\n",
9254 filter->plist[FILTER_IN].plist ? "*" : "",
9255 filter->plist[FILTER_IN].name);
9256 if (filter->plist[FILTER_OUT].name)
9257 vty_out(vty,
9258 " Outgoing update prefix filter list is %s%s\n",
9259 filter->plist[FILTER_OUT].plist ? "*" : "",
9260 filter->plist[FILTER_OUT].name);
9261
9262 /* distribute-list */
9263 if (filter->dlist[FILTER_IN].name)
9264 vty_out(vty,
9265 " Incoming update network filter list is %s%s\n",
9266 filter->dlist[FILTER_IN].alist ? "*" : "",
9267 filter->dlist[FILTER_IN].name);
9268 if (filter->dlist[FILTER_OUT].name)
9269 vty_out(vty,
9270 " Outgoing update network filter list is %s%s\n",
9271 filter->dlist[FILTER_OUT].alist ? "*" : "",
9272 filter->dlist[FILTER_OUT].name);
9273
9274 /* filter-list. */
9275 if (filter->aslist[FILTER_IN].name)
9276 vty_out(vty,
9277 " Incoming update AS path filter list is %s%s\n",
9278 filter->aslist[FILTER_IN].aslist ? "*" : "",
9279 filter->aslist[FILTER_IN].name);
9280 if (filter->aslist[FILTER_OUT].name)
9281 vty_out(vty,
9282 " Outgoing update AS path filter list is %s%s\n",
9283 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9284 filter->aslist[FILTER_OUT].name);
9285
9286 /* route-map. */
9287 if (filter->map[RMAP_IN].name)
9288 vty_out(vty,
9289 " Route map for incoming advertisements is %s%s\n",
9290 filter->map[RMAP_IN].map ? "*" : "",
9291 filter->map[RMAP_IN].name);
9292 if (filter->map[RMAP_OUT].name)
9293 vty_out(vty,
9294 " Route map for outgoing advertisements is %s%s\n",
9295 filter->map[RMAP_OUT].map ? "*" : "",
9296 filter->map[RMAP_OUT].name);
9297
9dac9fc8
DA
9298 /* ebgp-requires-policy (inbound) */
9299 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9300 && !bgp_inbound_policy_exists(p, filter))
9301 vty_out(vty,
9302 " Inbound updates discarded due to missing policy\n");
9303
9304 /* ebgp-requires-policy (outbound) */
9305 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9306 && !bgp_outbound_policy_exists(p, filter))
9307 vty_out(vty,
9308 " Outbound updates discarded due to missing policy\n");
9309
d62a17ae 9310 /* unsuppress-map */
9311 if (filter->usmap.name)
9312 vty_out(vty,
9313 " Route map for selective unsuppress is %s%s\n",
9314 filter->usmap.map ? "*" : "",
9315 filter->usmap.name);
9316
9317 /* Receive prefix count */
a0a87037
DA
9318 vty_out(vty, " %" PRIu32 " accepted prefixes\n",
9319 p->pcount[afi][safi]);
d62a17ae 9320
9321 /* Maximum prefix */
9322 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037
DA
9323 vty_out(vty,
9324 " Maximum prefixes allowed %" PRIu32 "%s\n",
d62a17ae 9325 p->pmax[afi][safi],
9326 CHECK_FLAG(p->af_flags[afi][safi],
9327 PEER_FLAG_MAX_PREFIX_WARNING)
9328 ? " (warning-only)"
9329 : "");
9330 vty_out(vty, " Threshold for warning message %d%%",
9331 p->pmax_threshold[afi][safi]);
9332 if (p->pmax_restart[afi][safi])
9333 vty_out(vty, ", restart interval %d min",
9334 p->pmax_restart[afi][safi]);
9335 vty_out(vty, "\n");
9336 }
9337
9338 vty_out(vty, "\n");
9339 }
9340}
9341
9f049418 9342static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 9343 json_object *json)
718e3744 9344{
d62a17ae 9345 struct bgp *bgp;
9346 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9347 char timebuf[BGP_UPTIME_LEN];
9348 char dn_flag[2];
d62a17ae 9349 afi_t afi;
9350 safi_t safi;
d7c0a89a
QY
9351 uint16_t i;
9352 uint8_t *msg;
d62a17ae 9353 json_object *json_neigh = NULL;
9354 time_t epoch_tbuf;
718e3744 9355
d62a17ae 9356 bgp = p->bgp;
9357
9358 if (use_json)
9359 json_neigh = json_object_new_object();
9360
9361 memset(dn_flag, '\0', sizeof(dn_flag));
9362 if (!p->conf_if && peer_dynamic_neighbor(p))
9363 dn_flag[0] = '*';
9364
9365 if (!use_json) {
9366 if (p->conf_if) /* Configured interface name. */
9367 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9368 BGP_PEER_SU_UNSPEC(p)
9369 ? "None"
9370 : sockunion2str(&p->su, buf,
9371 SU_ADDRSTRLEN));
9372 else /* Configured IP address. */
9373 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9374 p->host);
9375 }
9376
9377 if (use_json) {
9378 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9379 json_object_string_add(json_neigh, "bgpNeighborAddr",
9380 "none");
9381 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9382 json_object_string_add(
9383 json_neigh, "bgpNeighborAddr",
9384 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9385
9386 json_object_int_add(json_neigh, "remoteAs", p->as);
9387
9388 if (p->change_local_as)
9389 json_object_int_add(json_neigh, "localAs",
9390 p->change_local_as);
9391 else
9392 json_object_int_add(json_neigh, "localAs", p->local_as);
9393
9394 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9395 json_object_boolean_true_add(json_neigh,
9396 "localAsNoPrepend");
9397
9398 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9399 json_object_boolean_true_add(json_neigh,
9400 "localAsReplaceAs");
9401 } else {
9402 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9403 || (p->as_type == AS_INTERNAL))
9404 vty_out(vty, "remote AS %u, ", p->as);
9405 else
9406 vty_out(vty, "remote AS Unspecified, ");
9407 vty_out(vty, "local AS %u%s%s, ",
9408 p->change_local_as ? p->change_local_as : p->local_as,
9409 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9410 ? " no-prepend"
9411 : "",
9412 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9413 ? " replace-as"
9414 : "");
9415 }
faa16034
DS
9416 /* peer type internal or confed-internal */
9417 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 9418 if (use_json) {
9419 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9420 json_object_boolean_true_add(
9421 json_neigh, "nbrConfedInternalLink");
9422 else
9423 json_object_boolean_true_add(json_neigh,
9424 "nbrInternalLink");
9425 } else {
9426 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9427 vty_out(vty, "confed-internal link\n");
9428 else
9429 vty_out(vty, "internal link\n");
9430 }
faa16034
DS
9431 /* peer type external or confed-external */
9432 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 9433 if (use_json) {
9434 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9435 json_object_boolean_true_add(
9436 json_neigh, "nbrConfedExternalLink");
9437 else
9438 json_object_boolean_true_add(json_neigh,
9439 "nbrExternalLink");
9440 } else {
9441 if (bgp_confederation_peers_check(bgp, p->as))
9442 vty_out(vty, "confed-external link\n");
9443 else
9444 vty_out(vty, "external link\n");
9445 }
faa16034
DS
9446 } else {
9447 if (use_json)
9448 json_object_boolean_true_add(json_neigh,
9449 "nbrUnspecifiedLink");
9450 else
9451 vty_out(vty, "unspecified link\n");
d62a17ae 9452 }
9453
9454 /* Description. */
9455 if (p->desc) {
9456 if (use_json)
9457 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9458 else
9459 vty_out(vty, " Description: %s\n", p->desc);
9460 }
9461
9462 if (p->hostname) {
9463 if (use_json) {
9464 if (p->hostname)
9465 json_object_string_add(json_neigh, "hostname",
9466 p->hostname);
9467
9468 if (p->domainname)
9469 json_object_string_add(json_neigh, "domainname",
9470 p->domainname);
9471 } else {
9472 if (p->domainname && (p->domainname[0] != '\0'))
9473 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9474 p->domainname);
9475 else
9476 vty_out(vty, "Hostname: %s\n", p->hostname);
9477 }
9478 }
9479
9480 /* Peer-group */
9481 if (p->group) {
9482 if (use_json) {
9483 json_object_string_add(json_neigh, "peerGroup",
9484 p->group->name);
9485
9486 if (dn_flag[0]) {
9487 struct prefix prefix, *range = NULL;
9488
9489 sockunion2hostprefix(&(p->su), &prefix);
9490 range = peer_group_lookup_dynamic_neighbor_range(
9491 p->group, &prefix);
9492
9493 if (range) {
9494 prefix2str(range, buf1, sizeof(buf1));
9495 json_object_string_add(
9496 json_neigh,
9497 "peerSubnetRangeGroup", buf1);
9498 }
9499 }
9500 } else {
9501 vty_out(vty,
9502 " Member of peer-group %s for session parameters\n",
9503 p->group->name);
9504
9505 if (dn_flag[0]) {
9506 struct prefix prefix, *range = NULL;
9507
9508 sockunion2hostprefix(&(p->su), &prefix);
9509 range = peer_group_lookup_dynamic_neighbor_range(
9510 p->group, &prefix);
9511
9512 if (range) {
9513 prefix2str(range, buf1, sizeof(buf1));
9514 vty_out(vty,
9515 " Belongs to the subnet range group: %s\n",
9516 buf1);
9517 }
9518 }
9519 }
9520 }
9521
9522 if (use_json) {
9523 /* Administrative shutdown. */
9524 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9525 json_object_boolean_true_add(json_neigh,
9526 "adminShutDown");
9527
9528 /* BGP Version. */
9529 json_object_int_add(json_neigh, "bgpVersion", 4);
9530 json_object_string_add(
9531 json_neigh, "remoteRouterId",
9532 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
9533 json_object_string_add(
9534 json_neigh, "localRouterId",
9535 inet_ntop(AF_INET, &bgp->router_id, buf1,
9536 sizeof(buf1)));
d62a17ae 9537
9538 /* Confederation */
9539 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9540 && bgp_confederation_peers_check(bgp, p->as))
9541 json_object_boolean_true_add(json_neigh,
9542 "nbrCommonAdmin");
9543
9544 /* Status. */
9545 json_object_string_add(
9546 json_neigh, "bgpState",
9547 lookup_msg(bgp_status_msg, p->status, NULL));
9548
9549 if (p->status == Established) {
9550 time_t uptime;
d62a17ae 9551
9552 uptime = bgp_clock();
9553 uptime -= p->uptime;
d62a17ae 9554 epoch_tbuf = time(NULL) - uptime;
9555
bee57a7a 9556#if CONFDATE > 20200101
a4d82a8a
PZ
9557 CPP_NOTICE(
9558 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9559#endif
9560 /*
9561 * bgpTimerUp was miliseconds that was accurate
9562 * up to 1 day, then the value returned
9563 * became garbage. So in order to provide
9564 * some level of backwards compatability,
9565 * we still provde the data, but now
9566 * we are returning the correct value
9567 * and also adding a new bgpTimerUpMsec
9568 * which will allow us to deprecate
9569 * this eventually
9570 */
d62a17ae 9571 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9572 uptime * 1000);
d3c7efed
DS
9573 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9574 uptime * 1000);
d62a17ae 9575 json_object_string_add(json_neigh, "bgpTimerUpString",
9576 peer_uptime(p->uptime, timebuf,
9577 BGP_UPTIME_LEN, 0,
9578 NULL));
9579 json_object_int_add(json_neigh,
9580 "bgpTimerUpEstablishedEpoch",
9581 epoch_tbuf);
9582 }
9583
9584 else if (p->status == Active) {
9585 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9586 json_object_string_add(json_neigh, "bgpStateIs",
9587 "passive");
9588 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9589 json_object_string_add(json_neigh, "bgpStateIs",
9590 "passiveNSF");
9591 }
9592
9593 /* read timer */
9594 time_t uptime;
9595 struct tm *tm;
9596
9597 uptime = bgp_clock();
9598 uptime -= p->readtime;
9599 tm = gmtime(&uptime);
9600 json_object_int_add(json_neigh, "bgpTimerLastRead",
9601 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9602 + (tm->tm_hour * 3600000));
9603
9604 uptime = bgp_clock();
9605 uptime -= p->last_write;
9606 tm = gmtime(&uptime);
9607 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9608 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9609 + (tm->tm_hour * 3600000));
9610
9611 uptime = bgp_clock();
9612 uptime -= p->update_time;
9613 tm = gmtime(&uptime);
9614 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9615 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9616 + (tm->tm_hour * 3600000));
9617
9618 /* Configured timer values. */
9619 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9620 p->v_holdtime * 1000);
9621 json_object_int_add(json_neigh,
9622 "bgpTimerKeepAliveIntervalMsecs",
9623 p->v_keepalive * 1000);
b90a8e13 9624 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9625 json_object_int_add(json_neigh,
9626 "bgpTimerConfiguredHoldTimeMsecs",
9627 p->holdtime * 1000);
9628 json_object_int_add(
9629 json_neigh,
9630 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9631 p->keepalive * 1000);
d25e4efc 9632 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9633 || (bgp->default_keepalive
9634 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9635 json_object_int_add(json_neigh,
9636 "bgpTimerConfiguredHoldTimeMsecs",
9637 bgp->default_holdtime);
9638 json_object_int_add(
9639 json_neigh,
9640 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9641 bgp->default_keepalive);
d62a17ae 9642 }
9643 } else {
9644 /* Administrative shutdown. */
9645 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9646 vty_out(vty, " Administratively shut down\n");
9647
9648 /* BGP Version. */
9649 vty_out(vty, " BGP version 4");
0e38aeb4 9650 vty_out(vty, ", remote router ID %s",
d62a17ae 9651 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
9652 vty_out(vty, ", local router ID %s\n",
9653 inet_ntop(AF_INET, &bgp->router_id, buf1,
9654 sizeof(buf1)));
d62a17ae 9655
9656 /* Confederation */
9657 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9658 && bgp_confederation_peers_check(bgp, p->as))
9659 vty_out(vty,
9660 " Neighbor under common administration\n");
9661
9662 /* Status. */
9663 vty_out(vty, " BGP state = %s",
9664 lookup_msg(bgp_status_msg, p->status, NULL));
9665
9666 if (p->status == Established)
9667 vty_out(vty, ", up for %8s",
9668 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9669 0, NULL));
9670
9671 else if (p->status == Active) {
9672 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9673 vty_out(vty, " (passive)");
9674 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9675 vty_out(vty, " (NSF passive)");
9676 }
9677 vty_out(vty, "\n");
9678
9679 /* read timer */
9680 vty_out(vty, " Last read %s",
9681 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9682 NULL));
9683 vty_out(vty, ", Last write %s\n",
9684 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9685 NULL));
9686
9687 /* Configured timer values. */
9688 vty_out(vty,
9689 " Hold time is %d, keepalive interval is %d seconds\n",
9690 p->v_holdtime, p->v_keepalive);
b90a8e13 9691 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9692 vty_out(vty, " Configured hold time is %d",
9693 p->holdtime);
9694 vty_out(vty, ", keepalive interval is %d seconds\n",
9695 p->keepalive);
d25e4efc 9696 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9697 || (bgp->default_keepalive
9698 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9699 vty_out(vty, " Configured hold time is %d",
9700 bgp->default_holdtime);
9701 vty_out(vty, ", keepalive interval is %d seconds\n",
9702 bgp->default_keepalive);
d62a17ae 9703 }
9704 }
9705 /* Capability. */
9706 if (p->status == Established) {
9707 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9708 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9709 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9710 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9711 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9712 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9713 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9714 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9715 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9716 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9717 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9718 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9719 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9720 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9721 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9722 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9723 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9724 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9725 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9726 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9727 if (use_json) {
9728 json_object *json_cap = NULL;
9729
9730 json_cap = json_object_new_object();
9731
9732 /* AS4 */
9733 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9734 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9735 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9736 && CHECK_FLAG(p->cap,
9737 PEER_CAP_AS4_RCV))
9738 json_object_string_add(
9739 json_cap, "4byteAs",
9740 "advertisedAndReceived");
9741 else if (CHECK_FLAG(p->cap,
9742 PEER_CAP_AS4_ADV))
9743 json_object_string_add(
9744 json_cap, "4byteAs",
9745 "advertised");
9746 else if (CHECK_FLAG(p->cap,
9747 PEER_CAP_AS4_RCV))
9748 json_object_string_add(
9749 json_cap, "4byteAs",
9750 "received");
9751 }
9752
9753 /* AddPath */
9754 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9755 || CHECK_FLAG(p->cap,
9756 PEER_CAP_ADDPATH_ADV)) {
9757 json_object *json_add = NULL;
9758 const char *print_store;
9759
9760 json_add = json_object_new_object();
9761
05c7a1cc
QY
9762 FOREACH_AFI_SAFI (afi, safi) {
9763 json_object *json_sub = NULL;
9764 json_sub =
9765 json_object_new_object();
5cb5f4d0
DD
9766 print_store = get_afi_safi_str(
9767 afi, safi, true);
d62a17ae 9768
05c7a1cc
QY
9769 if (CHECK_FLAG(
9770 p->af_cap[afi]
9771 [safi],
9772 PEER_CAP_ADDPATH_AF_TX_ADV)
9773 || CHECK_FLAG(
9774 p->af_cap[afi]
9775 [safi],
9776 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9777 if (CHECK_FLAG(
9778 p->af_cap
9779 [afi]
9780 [safi],
9781 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9782 && CHECK_FLAG(
d62a17ae 9783 p->af_cap
9784 [afi]
9785 [safi],
05c7a1cc
QY
9786 PEER_CAP_ADDPATH_AF_TX_RCV))
9787 json_object_boolean_true_add(
9788 json_sub,
9789 "txAdvertisedAndReceived");
9790 else if (
9791 CHECK_FLAG(
9792 p->af_cap
9793 [afi]
9794 [safi],
9795 PEER_CAP_ADDPATH_AF_TX_ADV))
9796 json_object_boolean_true_add(
9797 json_sub,
9798 "txAdvertised");
9799 else if (
9800 CHECK_FLAG(
9801 p->af_cap
9802 [afi]
9803 [safi],
9804 PEER_CAP_ADDPATH_AF_TX_RCV))
9805 json_object_boolean_true_add(
9806 json_sub,
9807 "txReceived");
9808 }
d62a17ae 9809
05c7a1cc
QY
9810 if (CHECK_FLAG(
9811 p->af_cap[afi]
9812 [safi],
9813 PEER_CAP_ADDPATH_AF_RX_ADV)
9814 || CHECK_FLAG(
9815 p->af_cap[afi]
9816 [safi],
9817 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9818 if (CHECK_FLAG(
9819 p->af_cap
9820 [afi]
9821 [safi],
9822 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9823 && CHECK_FLAG(
d62a17ae 9824 p->af_cap
9825 [afi]
9826 [safi],
9827 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9828 json_object_boolean_true_add(
9829 json_sub,
9830 "rxAdvertisedAndReceived");
9831 else if (
9832 CHECK_FLAG(
9833 p->af_cap
9834 [afi]
9835 [safi],
9836 PEER_CAP_ADDPATH_AF_RX_ADV))
9837 json_object_boolean_true_add(
9838 json_sub,
9839 "rxAdvertised");
9840 else if (
9841 CHECK_FLAG(
9842 p->af_cap
9843 [afi]
9844 [safi],
9845 PEER_CAP_ADDPATH_AF_RX_RCV))
9846 json_object_boolean_true_add(
9847 json_sub,
9848 "rxReceived");
d62a17ae 9849 }
9850
05c7a1cc
QY
9851 if (CHECK_FLAG(
9852 p->af_cap[afi]
9853 [safi],
9854 PEER_CAP_ADDPATH_AF_TX_ADV)
9855 || CHECK_FLAG(
9856 p->af_cap[afi]
9857 [safi],
9858 PEER_CAP_ADDPATH_AF_TX_RCV)
9859 || CHECK_FLAG(
9860 p->af_cap[afi]
9861 [safi],
9862 PEER_CAP_ADDPATH_AF_RX_ADV)
9863 || CHECK_FLAG(
9864 p->af_cap[afi]
9865 [safi],
9866 PEER_CAP_ADDPATH_AF_RX_RCV))
9867 json_object_object_add(
9868 json_add,
9869 print_store,
9870 json_sub);
9871 else
9872 json_object_free(
9873 json_sub);
9874 }
9875
d62a17ae 9876 json_object_object_add(
9877 json_cap, "addPath", json_add);
9878 }
9879
9880 /* Dynamic */
9881 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9882 || CHECK_FLAG(p->cap,
9883 PEER_CAP_DYNAMIC_ADV)) {
9884 if (CHECK_FLAG(p->cap,
9885 PEER_CAP_DYNAMIC_ADV)
9886 && CHECK_FLAG(p->cap,
9887 PEER_CAP_DYNAMIC_RCV))
9888 json_object_string_add(
9889 json_cap, "dynamic",
9890 "advertisedAndReceived");
9891 else if (CHECK_FLAG(
9892 p->cap,
9893 PEER_CAP_DYNAMIC_ADV))
9894 json_object_string_add(
9895 json_cap, "dynamic",
9896 "advertised");
9897 else if (CHECK_FLAG(
9898 p->cap,
9899 PEER_CAP_DYNAMIC_RCV))
9900 json_object_string_add(
9901 json_cap, "dynamic",
9902 "received");
9903 }
9904
9905 /* Extended nexthop */
9906 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9907 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9908 json_object *json_nxt = NULL;
9909 const char *print_store;
9910
9911
9912 if (CHECK_FLAG(p->cap,
9913 PEER_CAP_ENHE_ADV)
9914 && CHECK_FLAG(p->cap,
9915 PEER_CAP_ENHE_RCV))
9916 json_object_string_add(
9917 json_cap,
9918 "extendedNexthop",
9919 "advertisedAndReceived");
9920 else if (CHECK_FLAG(p->cap,
9921 PEER_CAP_ENHE_ADV))
9922 json_object_string_add(
9923 json_cap,
9924 "extendedNexthop",
9925 "advertised");
9926 else if (CHECK_FLAG(p->cap,
9927 PEER_CAP_ENHE_RCV))
9928 json_object_string_add(
9929 json_cap,
9930 "extendedNexthop",
9931 "received");
9932
9933 if (CHECK_FLAG(p->cap,
9934 PEER_CAP_ENHE_RCV)) {
9935 json_nxt =
9936 json_object_new_object();
9937
9938 for (safi = SAFI_UNICAST;
9939 safi < SAFI_MAX; safi++) {
9940 if (CHECK_FLAG(
9941 p->af_cap
9942 [AFI_IP]
9943 [safi],
9944 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 9945 print_store = get_afi_safi_str(
d62a17ae 9946 AFI_IP,
5cb5f4d0 9947 safi, true);
d62a17ae 9948 json_object_string_add(
9949 json_nxt,
9950 print_store,
54f29523 9951 "recieved"); /* misspelled for compatibility */
d62a17ae 9952 }
9953 }
9954 json_object_object_add(
9955 json_cap,
9956 "extendedNexthopFamililesByPeer",
9957 json_nxt);
9958 }
9959 }
9960
9961 /* Route Refresh */
9962 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9963 || CHECK_FLAG(p->cap,
9964 PEER_CAP_REFRESH_NEW_RCV)
9965 || CHECK_FLAG(p->cap,
9966 PEER_CAP_REFRESH_OLD_RCV)) {
9967 if (CHECK_FLAG(p->cap,
9968 PEER_CAP_REFRESH_ADV)
9969 && (CHECK_FLAG(
9970 p->cap,
9971 PEER_CAP_REFRESH_NEW_RCV)
9972 || CHECK_FLAG(
9973 p->cap,
9974 PEER_CAP_REFRESH_OLD_RCV))) {
9975 if (CHECK_FLAG(
9976 p->cap,
9977 PEER_CAP_REFRESH_OLD_RCV)
9978 && CHECK_FLAG(
9979 p->cap,
9980 PEER_CAP_REFRESH_NEW_RCV))
9981 json_object_string_add(
9982 json_cap,
9983 "routeRefresh",
9984 "advertisedAndReceivedOldNew");
9985 else {
9986 if (CHECK_FLAG(
9987 p->cap,
9988 PEER_CAP_REFRESH_OLD_RCV))
9989 json_object_string_add(
9990 json_cap,
9991 "routeRefresh",
9992 "advertisedAndReceivedOld");
9993 else
9994 json_object_string_add(
9995 json_cap,
9996 "routeRefresh",
9997 "advertisedAndReceivedNew");
9998 }
9999 } else if (
10000 CHECK_FLAG(
10001 p->cap,
10002 PEER_CAP_REFRESH_ADV))
10003 json_object_string_add(
10004 json_cap,
10005 "routeRefresh",
10006 "advertised");
10007 else if (
10008 CHECK_FLAG(
10009 p->cap,
10010 PEER_CAP_REFRESH_NEW_RCV)
10011 || CHECK_FLAG(
10012 p->cap,
10013 PEER_CAP_REFRESH_OLD_RCV))
10014 json_object_string_add(
10015 json_cap,
10016 "routeRefresh",
10017 "received");
10018 }
10019
10020 /* Multiprotocol Extensions */
10021 json_object *json_multi = NULL;
10022 json_multi = json_object_new_object();
10023
05c7a1cc
QY
10024 FOREACH_AFI_SAFI (afi, safi) {
10025 if (p->afc_adv[afi][safi]
10026 || p->afc_recv[afi][safi]) {
10027 json_object *json_exten = NULL;
10028 json_exten =
10029 json_object_new_object();
10030
d62a17ae 10031 if (p->afc_adv[afi][safi]
05c7a1cc
QY
10032 && p->afc_recv[afi][safi])
10033 json_object_boolean_true_add(
10034 json_exten,
10035 "advertisedAndReceived");
10036 else if (p->afc_adv[afi][safi])
10037 json_object_boolean_true_add(
10038 json_exten,
10039 "advertised");
10040 else if (p->afc_recv[afi][safi])
10041 json_object_boolean_true_add(
10042 json_exten,
10043 "received");
d62a17ae 10044
05c7a1cc
QY
10045 json_object_object_add(
10046 json_multi,
5cb5f4d0
DD
10047 get_afi_safi_str(afi,
10048 safi,
10049 true),
05c7a1cc 10050 json_exten);
d62a17ae 10051 }
10052 }
10053 json_object_object_add(
10054 json_cap, "multiprotocolExtensions",
10055 json_multi);
10056
d77114b7 10057 /* Hostname capabilities */
60466a63 10058 json_object *json_hname = NULL;
d77114b7
MK
10059
10060 json_hname = json_object_new_object();
10061
10062 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10063 json_object_string_add(
60466a63
QY
10064 json_hname, "advHostName",
10065 bgp->peer_self->hostname
10066 ? bgp->peer_self
10067 ->hostname
d77114b7
MK
10068 : "n/a");
10069 json_object_string_add(
60466a63
QY
10070 json_hname, "advDomainName",
10071 bgp->peer_self->domainname
10072 ? bgp->peer_self
10073 ->domainname
d77114b7
MK
10074 : "n/a");
10075 }
10076
10077
10078 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10079 json_object_string_add(
60466a63
QY
10080 json_hname, "rcvHostName",
10081 p->hostname ? p->hostname
10082 : "n/a");
d77114b7 10083 json_object_string_add(
60466a63
QY
10084 json_hname, "rcvDomainName",
10085 p->domainname ? p->domainname
10086 : "n/a");
d77114b7
MK
10087 }
10088
60466a63 10089 json_object_object_add(json_cap, "hostName",
d77114b7
MK
10090 json_hname);
10091
d62a17ae 10092 /* Gracefull Restart */
10093 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10094 || CHECK_FLAG(p->cap,
10095 PEER_CAP_RESTART_ADV)) {
10096 if (CHECK_FLAG(p->cap,
10097 PEER_CAP_RESTART_ADV)
10098 && CHECK_FLAG(p->cap,
10099 PEER_CAP_RESTART_RCV))
10100 json_object_string_add(
10101 json_cap,
10102 "gracefulRestart",
10103 "advertisedAndReceived");
10104 else if (CHECK_FLAG(
10105 p->cap,
10106 PEER_CAP_RESTART_ADV))
10107 json_object_string_add(
10108 json_cap,
10109 "gracefulRestartCapability",
10110 "advertised");
10111 else if (CHECK_FLAG(
10112 p->cap,
10113 PEER_CAP_RESTART_RCV))
10114 json_object_string_add(
10115 json_cap,
10116 "gracefulRestartCapability",
10117 "received");
10118
10119 if (CHECK_FLAG(p->cap,
10120 PEER_CAP_RESTART_RCV)) {
10121 int restart_af_count = 0;
10122 json_object *json_restart =
10123 NULL;
10124 json_restart =
10125 json_object_new_object();
10126
10127 json_object_int_add(
10128 json_cap,
10129 "gracefulRestartRemoteTimerMsecs",
10130 p->v_gr_restart * 1000);
10131
05c7a1cc
QY
10132 FOREACH_AFI_SAFI (afi, safi) {
10133 if (CHECK_FLAG(
10134 p->af_cap
10135 [afi]
10136 [safi],
10137 PEER_CAP_RESTART_AF_RCV)) {
10138 json_object *
10139 json_sub =
10140 NULL;
10141 json_sub =
10142 json_object_new_object();
10143
d62a17ae 10144 if (CHECK_FLAG(
10145 p->af_cap
10146 [afi]
10147 [safi],
05c7a1cc
QY
10148 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10149 json_object_boolean_true_add(
10150 json_sub,
10151 "preserved");
10152 restart_af_count++;
10153 json_object_object_add(
10154 json_restart,
5cb5f4d0 10155 get_afi_safi_str(
05c7a1cc 10156 afi,
5cb5f4d0
DD
10157 safi,
10158 true),
05c7a1cc 10159 json_sub);
d62a17ae 10160 }
10161 }
10162 if (!restart_af_count) {
10163 json_object_string_add(
10164 json_cap,
10165 "addressFamiliesByPeer",
10166 "none");
10167 json_object_free(
10168 json_restart);
10169 } else
10170 json_object_object_add(
10171 json_cap,
10172 "addressFamiliesByPeer",
10173 json_restart);
10174 }
10175 }
10176 json_object_object_add(json_neigh,
10177 "neighborCapabilities",
10178 json_cap);
10179 } else {
10180 vty_out(vty, " Neighbor capabilities:\n");
10181
10182 /* AS4 */
10183 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10184 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10185 vty_out(vty, " 4 Byte AS:");
10186 if (CHECK_FLAG(p->cap,
10187 PEER_CAP_AS4_ADV))
10188 vty_out(vty, " advertised");
10189 if (CHECK_FLAG(p->cap,
10190 PEER_CAP_AS4_RCV))
10191 vty_out(vty, " %sreceived",
10192 CHECK_FLAG(
10193 p->cap,
10194 PEER_CAP_AS4_ADV)
10195 ? "and "
10196 : "");
10197 vty_out(vty, "\n");
10198 }
10199
10200 /* AddPath */
10201 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10202 || CHECK_FLAG(p->cap,
10203 PEER_CAP_ADDPATH_ADV)) {
10204 vty_out(vty, " AddPath:\n");
10205
05c7a1cc
QY
10206 FOREACH_AFI_SAFI (afi, safi) {
10207 if (CHECK_FLAG(
10208 p->af_cap[afi]
10209 [safi],
10210 PEER_CAP_ADDPATH_AF_TX_ADV)
10211 || CHECK_FLAG(
10212 p->af_cap[afi]
10213 [safi],
10214 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10215 vty_out(vty,
10216 " %s: TX ",
5cb5f4d0 10217 get_afi_safi_str(
05c7a1cc 10218 afi,
5cb5f4d0
DD
10219 safi,
10220 false));
05c7a1cc 10221
d62a17ae 10222 if (CHECK_FLAG(
10223 p->af_cap
10224 [afi]
10225 [safi],
05c7a1cc 10226 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 10227 vty_out(vty,
05c7a1cc 10228 "advertised %s",
5cb5f4d0 10229 get_afi_safi_str(
d62a17ae 10230 afi,
5cb5f4d0
DD
10231 safi,
10232 false));
d62a17ae 10233
05c7a1cc
QY
10234 if (CHECK_FLAG(
10235 p->af_cap
10236 [afi]
10237 [safi],
10238 PEER_CAP_ADDPATH_AF_TX_RCV))
10239 vty_out(vty,
10240 "%sreceived",
10241 CHECK_FLAG(
10242 p->af_cap
10243 [afi]
10244 [safi],
10245 PEER_CAP_ADDPATH_AF_TX_ADV)
10246 ? " and "
10247 : "");
d62a17ae 10248
05c7a1cc
QY
10249 vty_out(vty, "\n");
10250 }
d62a17ae 10251
05c7a1cc
QY
10252 if (CHECK_FLAG(
10253 p->af_cap[afi]
10254 [safi],
10255 PEER_CAP_ADDPATH_AF_RX_ADV)
10256 || CHECK_FLAG(
10257 p->af_cap[afi]
10258 [safi],
10259 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10260 vty_out(vty,
10261 " %s: RX ",
5cb5f4d0 10262 get_afi_safi_str(
05c7a1cc 10263 afi,
5cb5f4d0
DD
10264 safi,
10265 false));
d62a17ae 10266
10267 if (CHECK_FLAG(
10268 p->af_cap
10269 [afi]
10270 [safi],
05c7a1cc 10271 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 10272 vty_out(vty,
05c7a1cc 10273 "advertised %s",
5cb5f4d0 10274 get_afi_safi_str(
d62a17ae 10275 afi,
5cb5f4d0
DD
10276 safi,
10277 false));
d62a17ae 10278
05c7a1cc
QY
10279 if (CHECK_FLAG(
10280 p->af_cap
10281 [afi]
10282 [safi],
10283 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 10284 vty_out(vty,
05c7a1cc
QY
10285 "%sreceived",
10286 CHECK_FLAG(
10287 p->af_cap
10288 [afi]
10289 [safi],
10290 PEER_CAP_ADDPATH_AF_RX_ADV)
10291 ? " and "
10292 : "");
10293
10294 vty_out(vty, "\n");
d62a17ae 10295 }
05c7a1cc 10296 }
d62a17ae 10297 }
10298
10299 /* Dynamic */
10300 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10301 || CHECK_FLAG(p->cap,
10302 PEER_CAP_DYNAMIC_ADV)) {
10303 vty_out(vty, " Dynamic:");
10304 if (CHECK_FLAG(p->cap,
10305 PEER_CAP_DYNAMIC_ADV))
10306 vty_out(vty, " advertised");
10307 if (CHECK_FLAG(p->cap,
10308 PEER_CAP_DYNAMIC_RCV))
10309 vty_out(vty, " %sreceived",
10310 CHECK_FLAG(
10311 p->cap,
10312 PEER_CAP_DYNAMIC_ADV)
10313 ? "and "
10314 : "");
10315 vty_out(vty, "\n");
10316 }
10317
10318 /* Extended nexthop */
10319 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10320 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10321 vty_out(vty, " Extended nexthop:");
10322 if (CHECK_FLAG(p->cap,
10323 PEER_CAP_ENHE_ADV))
10324 vty_out(vty, " advertised");
10325 if (CHECK_FLAG(p->cap,
10326 PEER_CAP_ENHE_RCV))
10327 vty_out(vty, " %sreceived",
10328 CHECK_FLAG(
10329 p->cap,
10330 PEER_CAP_ENHE_ADV)
10331 ? "and "
10332 : "");
10333 vty_out(vty, "\n");
10334
10335 if (CHECK_FLAG(p->cap,
10336 PEER_CAP_ENHE_RCV)) {
10337 vty_out(vty,
10338 " Address families by peer:\n ");
10339 for (safi = SAFI_UNICAST;
10340 safi < SAFI_MAX; safi++)
10341 if (CHECK_FLAG(
10342 p->af_cap
10343 [AFI_IP]
10344 [safi],
10345 PEER_CAP_ENHE_AF_RCV))
10346 vty_out(vty,
10347 " %s\n",
5cb5f4d0 10348 get_afi_safi_str(
d62a17ae 10349 AFI_IP,
5cb5f4d0
DD
10350 safi,
10351 false));
d62a17ae 10352 }
10353 }
10354
10355 /* Route Refresh */
10356 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10357 || CHECK_FLAG(p->cap,
10358 PEER_CAP_REFRESH_NEW_RCV)
10359 || CHECK_FLAG(p->cap,
10360 PEER_CAP_REFRESH_OLD_RCV)) {
10361 vty_out(vty, " Route refresh:");
10362 if (CHECK_FLAG(p->cap,
10363 PEER_CAP_REFRESH_ADV))
10364 vty_out(vty, " advertised");
10365 if (CHECK_FLAG(p->cap,
10366 PEER_CAP_REFRESH_NEW_RCV)
10367 || CHECK_FLAG(
10368 p->cap,
10369 PEER_CAP_REFRESH_OLD_RCV))
10370 vty_out(vty, " %sreceived(%s)",
10371 CHECK_FLAG(
10372 p->cap,
10373 PEER_CAP_REFRESH_ADV)
10374 ? "and "
10375 : "",
10376 (CHECK_FLAG(
10377 p->cap,
10378 PEER_CAP_REFRESH_OLD_RCV)
10379 && CHECK_FLAG(
10380 p->cap,
10381 PEER_CAP_REFRESH_NEW_RCV))
10382 ? "old & new"
10383 : CHECK_FLAG(
10384 p->cap,
10385 PEER_CAP_REFRESH_OLD_RCV)
10386 ? "old"
10387 : "new");
10388
10389 vty_out(vty, "\n");
10390 }
10391
10392 /* Multiprotocol Extensions */
05c7a1cc
QY
10393 FOREACH_AFI_SAFI (afi, safi)
10394 if (p->afc_adv[afi][safi]
10395 || p->afc_recv[afi][safi]) {
10396 vty_out(vty,
10397 " Address Family %s:",
5cb5f4d0
DD
10398 get_afi_safi_str(
10399 afi,
10400 safi,
10401 false));
05c7a1cc 10402 if (p->afc_adv[afi][safi])
d62a17ae 10403 vty_out(vty,
05c7a1cc
QY
10404 " advertised");
10405 if (p->afc_recv[afi][safi])
10406 vty_out(vty,
10407 " %sreceived",
10408 p->afc_adv[afi]
10409 [safi]
10410 ? "and "
10411 : "");
10412 vty_out(vty, "\n");
10413 }
d62a17ae 10414
10415 /* Hostname capability */
60466a63 10416 vty_out(vty, " Hostname Capability:");
d77114b7
MK
10417
10418 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
10419 vty_out(vty,
10420 " advertised (name: %s,domain name: %s)",
60466a63
QY
10421 bgp->peer_self->hostname
10422 ? bgp->peer_self
10423 ->hostname
d77114b7 10424 : "n/a",
60466a63
QY
10425 bgp->peer_self->domainname
10426 ? bgp->peer_self
10427 ->domainname
d77114b7
MK
10428 : "n/a");
10429 } else {
10430 vty_out(vty, " not advertised");
d62a17ae 10431 }
10432
d77114b7 10433 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10434 vty_out(vty,
10435 " received (name: %s,domain name: %s)",
60466a63
QY
10436 p->hostname ? p->hostname
10437 : "n/a",
10438 p->domainname ? p->domainname
10439 : "n/a");
d77114b7
MK
10440 } else {
10441 vty_out(vty, " not received");
10442 }
10443
10444 vty_out(vty, "\n");
10445
d62a17ae 10446 /* Gracefull Restart */
10447 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10448 || CHECK_FLAG(p->cap,
10449 PEER_CAP_RESTART_ADV)) {
10450 vty_out(vty,
10451 " Graceful Restart Capabilty:");
10452 if (CHECK_FLAG(p->cap,
10453 PEER_CAP_RESTART_ADV))
10454 vty_out(vty, " advertised");
10455 if (CHECK_FLAG(p->cap,
10456 PEER_CAP_RESTART_RCV))
10457 vty_out(vty, " %sreceived",
10458 CHECK_FLAG(
10459 p->cap,
10460 PEER_CAP_RESTART_ADV)
10461 ? "and "
10462 : "");
10463 vty_out(vty, "\n");
10464
10465 if (CHECK_FLAG(p->cap,
10466 PEER_CAP_RESTART_RCV)) {
10467 int restart_af_count = 0;
10468
10469 vty_out(vty,
10470 " Remote Restart timer is %d seconds\n",
10471 p->v_gr_restart);
10472 vty_out(vty,
10473 " Address families by peer:\n ");
10474
05c7a1cc
QY
10475 FOREACH_AFI_SAFI (afi, safi)
10476 if (CHECK_FLAG(
10477 p->af_cap
10478 [afi]
10479 [safi],
10480 PEER_CAP_RESTART_AF_RCV)) {
10481 vty_out(vty,
10482 "%s%s(%s)",
10483 restart_af_count
10484 ? ", "
10485 : "",
5cb5f4d0 10486 get_afi_safi_str(
05c7a1cc 10487 afi,
5cb5f4d0
DD
10488 safi,
10489 false),
05c7a1cc
QY
10490 CHECK_FLAG(
10491 p->af_cap
10492 [afi]
10493 [safi],
10494 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10495 ? "preserved"
10496 : "not preserved");
10497 restart_af_count++;
10498 }
d62a17ae 10499 if (!restart_af_count)
10500 vty_out(vty, "none");
10501 vty_out(vty, "\n");
10502 }
10503 }
10504 }
10505 }
10506 }
10507
10508 /* graceful restart information */
10509 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10510 || p->t_gr_stale) {
10511 json_object *json_grace = NULL;
10512 json_object *json_grace_send = NULL;
10513 json_object *json_grace_recv = NULL;
10514 int eor_send_af_count = 0;
10515 int eor_receive_af_count = 0;
10516
10517 if (use_json) {
10518 json_grace = json_object_new_object();
10519 json_grace_send = json_object_new_object();
10520 json_grace_recv = json_object_new_object();
10521
10522 if (p->status == Established) {
05c7a1cc
QY
10523 FOREACH_AFI_SAFI (afi, safi) {
10524 if (CHECK_FLAG(p->af_sflags[afi][safi],
10525 PEER_STATUS_EOR_SEND)) {
10526 json_object_boolean_true_add(
10527 json_grace_send,
5cb5f4d0
DD
10528 get_afi_safi_str(afi,
10529 safi,
10530 true));
05c7a1cc 10531 eor_send_af_count++;
d62a17ae 10532 }
10533 }
05c7a1cc
QY
10534 FOREACH_AFI_SAFI (afi, safi) {
10535 if (CHECK_FLAG(
10536 p->af_sflags[afi][safi],
10537 PEER_STATUS_EOR_RECEIVED)) {
10538 json_object_boolean_true_add(
10539 json_grace_recv,
5cb5f4d0
DD
10540 get_afi_safi_str(afi,
10541 safi,
10542 true));
05c7a1cc 10543 eor_receive_af_count++;
d62a17ae 10544 }
10545 }
10546 }
10547
10548 json_object_object_add(json_grace, "endOfRibSend",
10549 json_grace_send);
10550 json_object_object_add(json_grace, "endOfRibRecv",
10551 json_grace_recv);
10552
10553 if (p->t_gr_restart)
10554 json_object_int_add(json_grace,
10555 "gracefulRestartTimerMsecs",
10556 thread_timer_remain_second(
10557 p->t_gr_restart)
10558 * 1000);
10559
10560 if (p->t_gr_stale)
10561 json_object_int_add(
10562 json_grace,
10563 "gracefulStalepathTimerMsecs",
10564 thread_timer_remain_second(
10565 p->t_gr_stale)
10566 * 1000);
10567
10568 json_object_object_add(
10569 json_neigh, "gracefulRestartInfo", json_grace);
10570 } else {
0437e105 10571 vty_out(vty, " Graceful restart information:\n");
d62a17ae 10572 if (p->status == Established) {
10573 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10574 FOREACH_AFI_SAFI (afi, safi) {
10575 if (CHECK_FLAG(p->af_sflags[afi][safi],
10576 PEER_STATUS_EOR_SEND)) {
10577 vty_out(vty, "%s%s",
10578 eor_send_af_count ? ", "
10579 : "",
5cb5f4d0
DD
10580 get_afi_safi_str(afi,
10581 safi,
10582 false));
05c7a1cc 10583 eor_send_af_count++;
d62a17ae 10584 }
10585 }
10586 vty_out(vty, "\n");
10587 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10588 FOREACH_AFI_SAFI (afi, safi) {
10589 if (CHECK_FLAG(
10590 p->af_sflags[afi][safi],
10591 PEER_STATUS_EOR_RECEIVED)) {
10592 vty_out(vty, "%s%s",
10593 eor_receive_af_count
10594 ? ", "
10595 : "",
5cb5f4d0
DD
10596 get_afi_safi_str(afi,
10597 safi,
10598 false));
05c7a1cc 10599 eor_receive_af_count++;
d62a17ae 10600 }
10601 }
10602 vty_out(vty, "\n");
10603 }
10604
10605 if (p->t_gr_restart)
10606 vty_out(vty,
10607 " The remaining time of restart timer is %ld\n",
10608 thread_timer_remain_second(
10609 p->t_gr_restart));
10610
10611 if (p->t_gr_stale)
10612 vty_out(vty,
10613 " The remaining time of stalepath timer is %ld\n",
10614 thread_timer_remain_second(
10615 p->t_gr_stale));
10616 }
10617 }
10618 if (use_json) {
10619 json_object *json_stat = NULL;
10620 json_stat = json_object_new_object();
10621 /* Packet counts. */
10622 json_object_int_add(json_stat, "depthInq", 0);
10623 json_object_int_add(json_stat, "depthOutq",
10624 (unsigned long)p->obuf->count);
0112e9e0
QY
10625 json_object_int_add(json_stat, "opensSent",
10626 atomic_load_explicit(&p->open_out,
10627 memory_order_relaxed));
10628 json_object_int_add(json_stat, "opensRecv",
10629 atomic_load_explicit(&p->open_in,
10630 memory_order_relaxed));
d62a17ae 10631 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10632 atomic_load_explicit(&p->notify_out,
10633 memory_order_relaxed));
d62a17ae 10634 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10635 atomic_load_explicit(&p->notify_in,
10636 memory_order_relaxed));
10637 json_object_int_add(json_stat, "updatesSent",
10638 atomic_load_explicit(&p->update_out,
10639 memory_order_relaxed));
10640 json_object_int_add(json_stat, "updatesRecv",
10641 atomic_load_explicit(&p->update_in,
10642 memory_order_relaxed));
d62a17ae 10643 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10644 atomic_load_explicit(&p->keepalive_out,
10645 memory_order_relaxed));
d62a17ae 10646 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10647 atomic_load_explicit(&p->keepalive_in,
10648 memory_order_relaxed));
d62a17ae 10649 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10650 atomic_load_explicit(&p->refresh_out,
10651 memory_order_relaxed));
d62a17ae 10652 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10653 atomic_load_explicit(&p->refresh_in,
10654 memory_order_relaxed));
d62a17ae 10655 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10656 atomic_load_explicit(&p->dynamic_cap_out,
10657 memory_order_relaxed));
d62a17ae 10658 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10659 atomic_load_explicit(&p->dynamic_cap_in,
10660 memory_order_relaxed));
10661 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10662 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10663 json_object_object_add(json_neigh, "messageStats", json_stat);
10664 } else {
10665 /* Packet counts. */
10666 vty_out(vty, " Message statistics:\n");
10667 vty_out(vty, " Inq depth is 0\n");
10668 vty_out(vty, " Outq depth is %lu\n",
10669 (unsigned long)p->obuf->count);
10670 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10671 vty_out(vty, " Opens: %10d %10d\n",
10672 atomic_load_explicit(&p->open_out,
10673 memory_order_relaxed),
10674 atomic_load_explicit(&p->open_in,
10675 memory_order_relaxed));
10676 vty_out(vty, " Notifications: %10d %10d\n",
10677 atomic_load_explicit(&p->notify_out,
10678 memory_order_relaxed),
10679 atomic_load_explicit(&p->notify_in,
10680 memory_order_relaxed));
10681 vty_out(vty, " Updates: %10d %10d\n",
10682 atomic_load_explicit(&p->update_out,
10683 memory_order_relaxed),
10684 atomic_load_explicit(&p->update_in,
10685 memory_order_relaxed));
10686 vty_out(vty, " Keepalives: %10d %10d\n",
10687 atomic_load_explicit(&p->keepalive_out,
10688 memory_order_relaxed),
10689 atomic_load_explicit(&p->keepalive_in,
10690 memory_order_relaxed));
10691 vty_out(vty, " Route Refresh: %10d %10d\n",
10692 atomic_load_explicit(&p->refresh_out,
10693 memory_order_relaxed),
10694 atomic_load_explicit(&p->refresh_in,
10695 memory_order_relaxed));
d62a17ae 10696 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10697 atomic_load_explicit(&p->dynamic_cap_out,
10698 memory_order_relaxed),
10699 atomic_load_explicit(&p->dynamic_cap_in,
10700 memory_order_relaxed));
10701 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10702 PEER_TOTAL_RX(p));
d62a17ae 10703 }
10704
10705 if (use_json) {
10706 /* advertisement-interval */
10707 json_object_int_add(json_neigh,
10708 "minBtwnAdvertisementRunsTimerMsecs",
10709 p->v_routeadv * 1000);
10710
10711 /* Update-source. */
10712 if (p->update_if || p->update_source) {
10713 if (p->update_if)
10714 json_object_string_add(json_neigh,
10715 "updateSource",
10716 p->update_if);
10717 else if (p->update_source)
10718 json_object_string_add(
10719 json_neigh, "updateSource",
10720 sockunion2str(p->update_source, buf1,
10721 SU_ADDRSTRLEN));
10722 }
10723 } else {
10724 /* advertisement-interval */
10725 vty_out(vty,
10726 " Minimum time between advertisement runs is %d seconds\n",
10727 p->v_routeadv);
10728
10729 /* Update-source. */
10730 if (p->update_if || p->update_source) {
10731 vty_out(vty, " Update source is ");
10732 if (p->update_if)
10733 vty_out(vty, "%s", p->update_if);
10734 else if (p->update_source)
10735 vty_out(vty, "%s",
10736 sockunion2str(p->update_source, buf1,
10737 SU_ADDRSTRLEN));
10738 vty_out(vty, "\n");
10739 }
10740
10741 vty_out(vty, "\n");
10742 }
10743
10744 /* Address Family Information */
10745 json_object *json_hold = NULL;
10746
10747 if (use_json)
10748 json_hold = json_object_new_object();
10749
05c7a1cc
QY
10750 FOREACH_AFI_SAFI (afi, safi)
10751 if (p->afc[afi][safi])
10752 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10753 json_hold);
d62a17ae 10754
10755 if (use_json) {
10756 json_object_object_add(json_neigh, "addressFamilyInfo",
10757 json_hold);
10758 json_object_int_add(json_neigh, "connectionsEstablished",
10759 p->established);
10760 json_object_int_add(json_neigh, "connectionsDropped",
10761 p->dropped);
10762 } else
10763 vty_out(vty, " Connections established %d; dropped %d\n",
10764 p->established, p->dropped);
10765
10766 if (!p->last_reset) {
10767 if (use_json)
10768 json_object_string_add(json_neigh, "lastReset",
10769 "never");
10770 else
10771 vty_out(vty, " Last reset never\n");
10772 } else {
10773 if (use_json) {
10774 time_t uptime;
10775 struct tm *tm;
10776
10777 uptime = bgp_clock();
10778 uptime -= p->resettime;
10779 tm = gmtime(&uptime);
10780 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10781 (tm->tm_sec * 1000)
10782 + (tm->tm_min * 60000)
10783 + (tm->tm_hour * 3600000));
3577f1c5 10784 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 10785 } else {
10786 vty_out(vty, " Last reset %s, ",
10787 peer_uptime(p->resettime, timebuf,
10788 BGP_UPTIME_LEN, 0, NULL));
10789
3577f1c5 10790 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 10791 if (p->last_reset_cause_size) {
10792 msg = p->last_reset_cause;
10793 vty_out(vty,
10794 " Message received that caused BGP to send a NOTIFICATION:\n ");
10795 for (i = 1; i <= p->last_reset_cause_size;
10796 i++) {
10797 vty_out(vty, "%02X", *msg++);
10798
10799 if (i != p->last_reset_cause_size) {
10800 if (i % 16 == 0) {
10801 vty_out(vty, "\n ");
10802 } else if (i % 4 == 0) {
10803 vty_out(vty, " ");
10804 }
10805 }
10806 }
10807 vty_out(vty, "\n");
10808 }
10809 }
10810 }
10811
10812 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10813 if (use_json)
10814 json_object_boolean_true_add(json_neigh,
10815 "prefixesConfigExceedMax");
10816 else
10817 vty_out(vty,
10818 " Peer had exceeded the max. no. of prefixes configured.\n");
10819
10820 if (p->t_pmax_restart) {
10821 if (use_json) {
10822 json_object_boolean_true_add(
10823 json_neigh, "reducePrefixNumFrom");
10824 json_object_int_add(json_neigh,
10825 "restartInTimerMsec",
10826 thread_timer_remain_second(
10827 p->t_pmax_restart)
10828 * 1000);
10829 } else
10830 vty_out(vty,
10831 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10832 p->host, thread_timer_remain_second(
10833 p->t_pmax_restart));
d62a17ae 10834 } else {
10835 if (use_json)
10836 json_object_boolean_true_add(
10837 json_neigh,
10838 "reducePrefixNumAndClearIpBgp");
10839 else
10840 vty_out(vty,
10841 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10842 p->host);
10843 }
10844 }
10845
10846 /* EBGP Multihop and GTSM */
10847 if (p->sort != BGP_PEER_IBGP) {
10848 if (use_json) {
10849 if (p->gtsm_hops > 0)
10850 json_object_int_add(json_neigh,
10851 "externalBgpNbrMaxHopsAway",
10852 p->gtsm_hops);
10853 else if (p->ttl > 1)
10854 json_object_int_add(json_neigh,
10855 "externalBgpNbrMaxHopsAway",
10856 p->ttl);
10857 } else {
10858 if (p->gtsm_hops > 0)
10859 vty_out(vty,
10860 " External BGP neighbor may be up to %d hops away.\n",
10861 p->gtsm_hops);
10862 else if (p->ttl > 1)
10863 vty_out(vty,
10864 " External BGP neighbor may be up to %d hops away.\n",
10865 p->ttl);
10866 }
10867 } else {
10868 if (p->gtsm_hops > 0) {
10869 if (use_json)
10870 json_object_int_add(json_neigh,
10871 "internalBgpNbrMaxHopsAway",
10872 p->gtsm_hops);
10873 else
10874 vty_out(vty,
10875 " Internal BGP neighbor may be up to %d hops away.\n",
10876 p->gtsm_hops);
10877 }
10878 }
10879
10880 /* Local address. */
10881 if (p->su_local) {
10882 if (use_json) {
10883 json_object_string_add(json_neigh, "hostLocal",
10884 sockunion2str(p->su_local, buf1,
10885 SU_ADDRSTRLEN));
10886 json_object_int_add(json_neigh, "portLocal",
10887 ntohs(p->su_local->sin.sin_port));
10888 } else
10889 vty_out(vty, "Local host: %s, Local port: %d\n",
10890 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10891 ntohs(p->su_local->sin.sin_port));
10892 }
10893
10894 /* Remote address. */
10895 if (p->su_remote) {
10896 if (use_json) {
10897 json_object_string_add(json_neigh, "hostForeign",
10898 sockunion2str(p->su_remote, buf1,
10899 SU_ADDRSTRLEN));
10900 json_object_int_add(json_neigh, "portForeign",
10901 ntohs(p->su_remote->sin.sin_port));
10902 } else
10903 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10904 sockunion2str(p->su_remote, buf1,
10905 SU_ADDRSTRLEN),
10906 ntohs(p->su_remote->sin.sin_port));
10907 }
10908
10909 /* Nexthop display. */
10910 if (p->su_local) {
10911 if (use_json) {
10912 json_object_string_add(json_neigh, "nexthop",
10913 inet_ntop(AF_INET,
10914 &p->nexthop.v4, buf1,
10915 sizeof(buf1)));
10916 json_object_string_add(json_neigh, "nexthopGlobal",
10917 inet_ntop(AF_INET6,
10918 &p->nexthop.v6_global,
10919 buf1, sizeof(buf1)));
10920 json_object_string_add(json_neigh, "nexthopLocal",
10921 inet_ntop(AF_INET6,
10922 &p->nexthop.v6_local,
10923 buf1, sizeof(buf1)));
10924 if (p->shared_network)
10925 json_object_string_add(json_neigh,
10926 "bgpConnection",
10927 "sharedNetwork");
10928 else
10929 json_object_string_add(json_neigh,
10930 "bgpConnection",
10931 "nonSharedNetwork");
10932 } else {
10933 vty_out(vty, "Nexthop: %s\n",
10934 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10935 sizeof(buf1)));
10936 vty_out(vty, "Nexthop global: %s\n",
10937 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10938 sizeof(buf1)));
10939 vty_out(vty, "Nexthop local: %s\n",
10940 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10941 sizeof(buf1)));
10942 vty_out(vty, "BGP connection: %s\n",
10943 p->shared_network ? "shared network"
10944 : "non shared network");
10945 }
10946 }
10947
10948 /* Timer information. */
10949 if (use_json) {
10950 json_object_int_add(json_neigh, "connectRetryTimer",
10951 p->v_connect);
10952 if (p->status == Established && p->rtt)
10953 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10954 p->rtt);
10955 if (p->t_start)
10956 json_object_int_add(
10957 json_neigh, "nextStartTimerDueInMsecs",
10958 thread_timer_remain_second(p->t_start) * 1000);
10959 if (p->t_connect)
10960 json_object_int_add(
10961 json_neigh, "nextConnectTimerDueInMsecs",
10962 thread_timer_remain_second(p->t_connect)
10963 * 1000);
10964 if (p->t_routeadv) {
10965 json_object_int_add(json_neigh, "mraiInterval",
10966 p->v_routeadv);
10967 json_object_int_add(
10968 json_neigh, "mraiTimerExpireInMsecs",
10969 thread_timer_remain_second(p->t_routeadv)
10970 * 1000);
10971 }
10972 if (p->password)
10973 json_object_int_add(json_neigh, "authenticationEnabled",
10974 1);
10975
10976 if (p->t_read)
10977 json_object_string_add(json_neigh, "readThread", "on");
10978 else
10979 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10980
10981 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10982 json_object_string_add(json_neigh, "writeThread", "on");
10983 else
10984 json_object_string_add(json_neigh, "writeThread",
10985 "off");
10986 } else {
10987 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10988 p->v_connect);
10989 if (p->status == Established && p->rtt)
10990 vty_out(vty, "Estimated round trip time: %d ms\n",
10991 p->rtt);
10992 if (p->t_start)
10993 vty_out(vty, "Next start timer due in %ld seconds\n",
10994 thread_timer_remain_second(p->t_start));
10995 if (p->t_connect)
10996 vty_out(vty, "Next connect timer due in %ld seconds\n",
10997 thread_timer_remain_second(p->t_connect));
10998 if (p->t_routeadv)
10999 vty_out(vty,
11000 "MRAI (interval %u) timer expires in %ld seconds\n",
11001 p->v_routeadv,
11002 thread_timer_remain_second(p->t_routeadv));
11003 if (p->password)
11004 vty_out(vty, "Peer Authentication Enabled\n");
11005
cac9e917 11006 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
11007 p->t_read ? "on" : "off",
11008 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
11009 ? "on"
cac9e917 11010 : "off", p->fd);
d62a17ae 11011 }
11012
11013 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
11014 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
11015 bgp_capability_vty_out(vty, p, use_json, json_neigh);
11016
11017 if (!use_json)
11018 vty_out(vty, "\n");
11019
11020 /* BFD information. */
11021 bgp_bfd_show_info(vty, p, use_json, json_neigh);
11022
11023 if (use_json) {
11024 if (p->conf_if) /* Configured interface name. */
11025 json_object_object_add(json, p->conf_if, json_neigh);
11026 else /* Configured IP address. */
11027 json_object_object_add(json, p->host, json_neigh);
11028 }
11029}
11030
11031static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
11032 enum show_type type, union sockunion *su,
9f049418 11033 const char *conf_if, bool use_json,
d62a17ae 11034 json_object *json)
11035{
11036 struct listnode *node, *nnode;
11037 struct peer *peer;
11038 int find = 0;
9f049418 11039 bool nbr_output = false;
d1927ebe
AS
11040 afi_t afi = AFI_MAX;
11041 safi_t safi = SAFI_MAX;
11042
11043 if (type == show_ipv4_peer || type == show_ipv4_all) {
11044 afi = AFI_IP;
11045 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
11046 afi = AFI_IP6;
11047 }
d62a17ae 11048
11049 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11050 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11051 continue;
11052
11053 switch (type) {
11054 case show_all:
11055 bgp_show_peer(vty, peer, use_json, json);
9f049418 11056 nbr_output = true;
d62a17ae 11057 break;
11058 case show_peer:
11059 if (conf_if) {
11060 if ((peer->conf_if
11061 && !strcmp(peer->conf_if, conf_if))
11062 || (peer->hostname
11063 && !strcmp(peer->hostname, conf_if))) {
11064 find = 1;
11065 bgp_show_peer(vty, peer, use_json,
11066 json);
11067 }
11068 } else {
11069 if (sockunion_same(&peer->su, su)) {
11070 find = 1;
11071 bgp_show_peer(vty, peer, use_json,
11072 json);
11073 }
11074 }
11075 break;
d1927ebe
AS
11076 case show_ipv4_peer:
11077 case show_ipv6_peer:
11078 FOREACH_SAFI (safi) {
11079 if (peer->afc[afi][safi]) {
11080 if (conf_if) {
11081 if ((peer->conf_if
11082 && !strcmp(peer->conf_if, conf_if))
11083 || (peer->hostname
11084 && !strcmp(peer->hostname, conf_if))) {
11085 find = 1;
11086 bgp_show_peer(vty, peer, use_json,
11087 json);
11088 break;
11089 }
11090 } else {
11091 if (sockunion_same(&peer->su, su)) {
11092 find = 1;
11093 bgp_show_peer(vty, peer, use_json,
11094 json);
11095 break;
11096 }
11097 }
11098 }
11099 }
11100 break;
11101 case show_ipv4_all:
11102 case show_ipv6_all:
11103 FOREACH_SAFI (safi) {
11104 if (peer->afc[afi][safi]) {
11105 bgp_show_peer(vty, peer, use_json, json);
11106 nbr_output = true;
11107 break;
11108 }
11109 }
11110 break;
d62a17ae 11111 }
11112 }
11113
d1927ebe
AS
11114 if ((type == show_peer || type == show_ipv4_peer ||
11115 type == show_ipv6_peer) && !find) {
d62a17ae 11116 if (use_json)
11117 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11118 else
88b7d255 11119 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 11120 }
11121
d1927ebe
AS
11122 if (type != show_peer && type != show_ipv4_peer &&
11123 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 11124 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 11125
d62a17ae 11126 if (use_json) {
996c9314
LB
11127 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11128 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 11129 } else {
11130 vty_out(vty, "\n");
11131 }
11132
11133 return CMD_SUCCESS;
11134}
11135
11136static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
11137 enum show_type type,
11138 const char *ip_str,
9f049418 11139 bool use_json)
d62a17ae 11140{
0291c246
MK
11141 struct listnode *node, *nnode;
11142 struct bgp *bgp;
71aedaa3 11143 union sockunion su;
0291c246 11144 json_object *json = NULL;
71aedaa3 11145 int ret, is_first = 1;
9f049418 11146 bool nbr_output = false;
d62a17ae 11147
11148 if (use_json)
11149 vty_out(vty, "{\n");
11150
11151 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11152 nbr_output = true;
d62a17ae 11153 if (use_json) {
11154 if (!(json = json_object_new_object())) {
af4c2728 11155 flog_err(
e50f7cfd 11156 EC_BGP_JSON_MEM_ERROR,
d62a17ae 11157 "Unable to allocate memory for JSON object");
11158 vty_out(vty,
11159 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11160 return;
11161 }
11162
11163 json_object_int_add(json, "vrfId",
11164 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
11165 ? -1
11166 : (int64_t)bgp->vrf_id);
d62a17ae 11167 json_object_string_add(
11168 json, "vrfName",
11169 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11170 ? VRF_DEFAULT_NAME
d62a17ae 11171 : bgp->name);
11172
11173 if (!is_first)
11174 vty_out(vty, ",\n");
11175 else
11176 is_first = 0;
11177
11178 vty_out(vty, "\"%s\":",
11179 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11180 ? VRF_DEFAULT_NAME
d62a17ae 11181 : bgp->name);
11182 } else {
11183 vty_out(vty, "\nInstance %s:\n",
11184 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11185 ? VRF_DEFAULT_NAME
d62a17ae 11186 : bgp->name);
11187 }
71aedaa3 11188
d1927ebe
AS
11189 if (type == show_peer || type == show_ipv4_peer ||
11190 type == show_ipv6_peer) {
71aedaa3
DS
11191 ret = str2sockunion(ip_str, &su);
11192 if (ret < 0)
11193 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11194 use_json, json);
11195 else
11196 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11197 use_json, json);
11198 } else {
d1927ebe 11199 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
11200 use_json, json);
11201 }
b77004d6 11202 json_object_free(json);
d62a17ae 11203 }
11204
01cbfd04 11205 if (use_json) {
d62a17ae 11206 vty_out(vty, "}\n");
01cbfd04
QY
11207 json_object_free(json);
11208 }
9f049418
DS
11209 else if (!nbr_output)
11210 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11211}
11212
11213static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11214 enum show_type type, const char *ip_str,
9f049418 11215 bool use_json)
d62a17ae 11216{
11217 int ret;
11218 struct bgp *bgp;
11219 union sockunion su;
11220 json_object *json = NULL;
11221
11222 if (name) {
11223 if (strmatch(name, "all")) {
71aedaa3
DS
11224 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11225 use_json);
d62a17ae 11226 return CMD_SUCCESS;
11227 } else {
11228 bgp = bgp_lookup_by_name(name);
11229 if (!bgp) {
11230 if (use_json) {
11231 json = json_object_new_object();
d62a17ae 11232 vty_out(vty, "%s\n",
11233 json_object_to_json_string_ext(
11234 json,
11235 JSON_C_TO_STRING_PRETTY));
11236 json_object_free(json);
11237 } else
11238 vty_out(vty,
9f049418 11239 "%% BGP instance not found\n");
d62a17ae 11240
11241 return CMD_WARNING;
11242 }
11243 }
11244 } else {
11245 bgp = bgp_get_default();
11246 }
11247
11248 if (bgp) {
11249 json = json_object_new_object();
11250 if (ip_str) {
11251 ret = str2sockunion(ip_str, &su);
11252 if (ret < 0)
11253 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11254 use_json, json);
11255 else
11256 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11257 use_json, json);
11258 } else {
11259 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11260 json);
11261 }
11262 json_object_free(json);
ca61fd25
DS
11263 } else {
11264 if (use_json)
11265 vty_out(vty, "{}\n");
11266 else
11267 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11268 }
11269
11270 return CMD_SUCCESS;
4fb25c53
DW
11271}
11272
716b2d8a 11273/* "show [ip] bgp neighbors" commands. */
718e3744 11274DEFUN (show_ip_bgp_neighbors,
11275 show_ip_bgp_neighbors_cmd,
24345e82 11276 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 11277 SHOW_STR
11278 IP_STR
11279 BGP_STR
f2a8972b 11280 BGP_INSTANCE_HELP_STR
8c3deaae
QY
11281 "Address Family\n"
11282 "Address Family\n"
718e3744 11283 "Detailed information on TCP and BGP neighbor connections\n"
11284 "Neighbor to display information about\n"
a80beece 11285 "Neighbor to display information about\n"
91d37724 11286 "Neighbor on BGP configured interface\n"
9973d184 11287 JSON_STR)
718e3744 11288{
d62a17ae 11289 char *vrf = NULL;
11290 char *sh_arg = NULL;
11291 enum show_type sh_type;
d1927ebe 11292 afi_t afi = AFI_MAX;
718e3744 11293
9f049418 11294 bool uj = use_json(argc, argv);
718e3744 11295
d62a17ae 11296 int idx = 0;
718e3744 11297
9a8bdf1c
PG
11298 /* [<vrf> VIEWVRFNAME] */
11299 if (argv_find(argv, argc, "vrf", &idx)) {
11300 vrf = argv[idx + 1]->arg;
11301 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11302 vrf = NULL;
11303 } else if (argv_find(argv, argc, "view", &idx))
11304 /* [<view> VIEWVRFNAME] */
d62a17ae 11305 vrf = argv[idx + 1]->arg;
718e3744 11306
d62a17ae 11307 idx++;
d1927ebe
AS
11308
11309 if (argv_find(argv, argc, "ipv4", &idx)) {
11310 sh_type = show_ipv4_all;
11311 afi = AFI_IP;
11312 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11313 sh_type = show_ipv6_all;
11314 afi = AFI_IP6;
11315 } else {
11316 sh_type = show_all;
11317 }
11318
d62a17ae 11319 if (argv_find(argv, argc, "A.B.C.D", &idx)
11320 || argv_find(argv, argc, "X:X::X:X", &idx)
11321 || argv_find(argv, argc, "WORD", &idx)) {
11322 sh_type = show_peer;
11323 sh_arg = argv[idx]->arg;
d1927ebe
AS
11324 }
11325
11326 if (sh_type == show_peer && afi == AFI_IP) {
11327 sh_type = show_ipv4_peer;
11328 } else if (sh_type == show_peer && afi == AFI_IP6) {
11329 sh_type = show_ipv6_peer;
11330 }
856ca177 11331
d62a17ae 11332 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 11333}
11334
716b2d8a 11335/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 11336 paths' and `show ip mbgp paths'. Those functions results are the
11337 same.*/
f412b39a 11338DEFUN (show_ip_bgp_paths,
718e3744 11339 show_ip_bgp_paths_cmd,
46f296b4 11340 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 11341 SHOW_STR
11342 IP_STR
11343 BGP_STR
46f296b4 11344 BGP_SAFI_HELP_STR
718e3744 11345 "Path information\n")
11346{
d62a17ae 11347 vty_out(vty, "Address Refcnt Path\n");
11348 aspath_print_all_vty(vty);
11349 return CMD_SUCCESS;
718e3744 11350}
11351
718e3744 11352#include "hash.h"
11353
e3b78da8 11354static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 11355 struct vty *vty)
718e3744 11356{
d62a17ae 11357 struct community *com;
718e3744 11358
e3b78da8 11359 com = (struct community *)bucket->data;
3f65c5b1 11360 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 11361 community_str(com, false));
718e3744 11362}
11363
11364/* Show BGP's community internal data. */
f412b39a 11365DEFUN (show_ip_bgp_community_info,
718e3744 11366 show_ip_bgp_community_info_cmd,
bec37ba5 11367 "show [ip] bgp community-info",
718e3744 11368 SHOW_STR
11369 IP_STR
11370 BGP_STR
11371 "List all bgp community information\n")
11372{
d62a17ae 11373 vty_out(vty, "Address Refcnt Community\n");
718e3744 11374
d62a17ae 11375 hash_iterate(community_hash(),
e3b78da8 11376 (void (*)(struct hash_bucket *,
d62a17ae 11377 void *))community_show_all_iterator,
11378 vty);
718e3744 11379
d62a17ae 11380 return CMD_SUCCESS;
718e3744 11381}
11382
e3b78da8 11383static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 11384 struct vty *vty)
57d187bc 11385{
d62a17ae 11386 struct lcommunity *lcom;
57d187bc 11387
e3b78da8 11388 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 11389 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 11390 lcommunity_str(lcom, false));
57d187bc
JS
11391}
11392
11393/* Show BGP's community internal data. */
11394DEFUN (show_ip_bgp_lcommunity_info,
11395 show_ip_bgp_lcommunity_info_cmd,
11396 "show ip bgp large-community-info",
11397 SHOW_STR
11398 IP_STR
11399 BGP_STR
11400 "List all bgp large-community information\n")
11401{
d62a17ae 11402 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 11403
d62a17ae 11404 hash_iterate(lcommunity_hash(),
e3b78da8 11405 (void (*)(struct hash_bucket *,
d62a17ae 11406 void *))lcommunity_show_all_iterator,
11407 vty);
57d187bc 11408
d62a17ae 11409 return CMD_SUCCESS;
57d187bc
JS
11410}
11411
11412
f412b39a 11413DEFUN (show_ip_bgp_attr_info,
718e3744 11414 show_ip_bgp_attr_info_cmd,
bec37ba5 11415 "show [ip] bgp attribute-info",
718e3744 11416 SHOW_STR
11417 IP_STR
11418 BGP_STR
11419 "List all bgp attribute information\n")
11420{
d62a17ae 11421 attr_show_all(vty);
11422 return CMD_SUCCESS;
718e3744 11423}
6b0655a2 11424
03915806
CS
11425static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11426 afi_t afi, safi_t safi,
11427 bool use_json, json_object *json)
53089bec 11428{
11429 struct bgp *bgp;
11430 struct listnode *node;
11431 char *vname;
11432 char buf1[INET6_ADDRSTRLEN];
11433 char *ecom_str;
11434 vpn_policy_direction_t dir;
11435
03915806 11436 if (json) {
b46dfd20
DS
11437 json_object *json_import_vrfs = NULL;
11438 json_object *json_export_vrfs = NULL;
11439
b46dfd20
DS
11440 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11441
53089bec 11442 if (!bgp) {
b46dfd20
DS
11443 vty_out(vty, "%s\n",
11444 json_object_to_json_string_ext(
11445 json,
11446 JSON_C_TO_STRING_PRETTY));
11447 json_object_free(json);
11448
53089bec 11449 return CMD_WARNING;
11450 }
b46dfd20 11451
94d4c685
DS
11452 /* Provide context for the block */
11453 json_object_string_add(json, "vrf", name ? name : "default");
11454 json_object_string_add(json, "afiSafi",
5cb5f4d0 11455 get_afi_safi_str(afi, safi, true));
94d4c685 11456
b46dfd20
DS
11457 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11458 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11459 json_object_string_add(json, "importFromVrfs", "none");
11460 json_object_string_add(json, "importRts", "none");
11461 } else {
6ce24e52
DS
11462 json_import_vrfs = json_object_new_array();
11463
b46dfd20
DS
11464 for (ALL_LIST_ELEMENTS_RO(
11465 bgp->vpn_policy[afi].import_vrf,
11466 node, vname))
11467 json_object_array_add(json_import_vrfs,
11468 json_object_new_string(vname));
11469
b20875ea
CS
11470 json_object_object_add(json, "importFromVrfs",
11471 json_import_vrfs);
b46dfd20 11472 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
11473 if (bgp->vpn_policy[afi].rtlist[dir]) {
11474 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11475 bgp->vpn_policy[afi].rtlist[dir],
11476 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
11477 json_object_string_add(json, "importRts",
11478 ecom_str);
11479 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11480 } else
11481 json_object_string_add(json, "importRts",
11482 "none");
b46dfd20
DS
11483 }
11484
11485 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11486 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11487 json_object_string_add(json, "exportToVrfs", "none");
11488 json_object_string_add(json, "routeDistinguisher",
11489 "none");
11490 json_object_string_add(json, "exportRts", "none");
11491 } else {
6ce24e52
DS
11492 json_export_vrfs = json_object_new_array();
11493
b46dfd20
DS
11494 for (ALL_LIST_ELEMENTS_RO(
11495 bgp->vpn_policy[afi].export_vrf,
11496 node, vname))
11497 json_object_array_add(json_export_vrfs,
11498 json_object_new_string(vname));
11499 json_object_object_add(json, "exportToVrfs",
11500 json_export_vrfs);
11501 json_object_string_add(json, "routeDistinguisher",
11502 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11503 buf1, RD_ADDRSTRLEN));
11504
11505 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
11506 if (bgp->vpn_policy[afi].rtlist[dir]) {
11507 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11508 bgp->vpn_policy[afi].rtlist[dir],
11509 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
11510 json_object_string_add(json, "exportRts",
11511 ecom_str);
11512 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11513 } else
11514 json_object_string_add(json, "exportRts",
11515 "none");
b46dfd20
DS
11516 }
11517
03915806
CS
11518 if (use_json) {
11519 vty_out(vty, "%s\n",
11520 json_object_to_json_string_ext(json,
b46dfd20 11521 JSON_C_TO_STRING_PRETTY));
03915806
CS
11522 json_object_free(json);
11523 }
53089bec 11524 } else {
b46dfd20
DS
11525 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11526
53089bec 11527 if (!bgp) {
b46dfd20 11528 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 11529 return CMD_WARNING;
11530 }
53089bec 11531
b46dfd20
DS
11532 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11533 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11534 vty_out(vty,
11535 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 11536 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
11537 else {
11538 vty_out(vty,
11539 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 11540 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
11541
11542 for (ALL_LIST_ELEMENTS_RO(
11543 bgp->vpn_policy[afi].import_vrf,
11544 node, vname))
11545 vty_out(vty, " %s\n", vname);
11546
11547 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
11548 ecom_str = NULL;
11549 if (bgp->vpn_policy[afi].rtlist[dir]) {
11550 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11551 bgp->vpn_policy[afi].rtlist[dir],
11552 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 11553 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 11554
b20875ea
CS
11555 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11556 } else
11557 vty_out(vty, "Import RT(s):\n");
53089bec 11558 }
53089bec 11559
b46dfd20
DS
11560 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11561 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11562 vty_out(vty,
11563 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 11564 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
11565 else {
11566 vty_out(vty,
04c9077f 11567 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 11568 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
11569
11570 for (ALL_LIST_ELEMENTS_RO(
11571 bgp->vpn_policy[afi].export_vrf,
11572 node, vname))
11573 vty_out(vty, " %s\n", vname);
11574
11575 vty_out(vty, "RD: %s\n",
11576 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11577 buf1, RD_ADDRSTRLEN));
11578
11579 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
11580 if (bgp->vpn_policy[afi].rtlist[dir]) {
11581 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11582 bgp->vpn_policy[afi].rtlist[dir],
11583 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
11584 vty_out(vty, "Export RT: %s\n", ecom_str);
11585 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11586 } else
11587 vty_out(vty, "Import RT(s):\n");
53089bec 11588 }
53089bec 11589 }
11590
11591 return CMD_SUCCESS;
11592}
11593
03915806
CS
11594static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11595 safi_t safi, bool use_json)
11596{
11597 struct listnode *node, *nnode;
11598 struct bgp *bgp;
11599 char *vrf_name = NULL;
11600 json_object *json = NULL;
11601 json_object *json_vrf = NULL;
11602 json_object *json_vrfs = NULL;
11603
11604 if (use_json) {
11605 json = json_object_new_object();
11606 json_vrfs = json_object_new_object();
11607 }
11608
11609 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11610
11611 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11612 vrf_name = bgp->name;
11613
11614 if (use_json) {
11615 json_vrf = json_object_new_object();
11616 } else {
11617 vty_out(vty, "\nInstance %s:\n",
11618 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11619 ? VRF_DEFAULT_NAME : bgp->name);
11620 }
11621 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11622 if (use_json) {
11623 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11624 json_object_object_add(json_vrfs,
11625 VRF_DEFAULT_NAME, json_vrf);
11626 else
11627 json_object_object_add(json_vrfs, vrf_name,
11628 json_vrf);
11629 }
11630 }
11631
11632 if (use_json) {
11633 json_object_object_add(json, "vrfs", json_vrfs);
11634 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11635 JSON_C_TO_STRING_PRETTY));
11636 json_object_free(json);
11637 }
11638
11639 return CMD_SUCCESS;
11640}
11641
53089bec 11642/* "show [ip] bgp route-leak" command. */
11643DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
11644 show_ip_bgp_route_leak_cmd,
11645 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
11646 SHOW_STR
11647 IP_STR
11648 BGP_STR
11649 BGP_INSTANCE_HELP_STR
11650 BGP_AFI_HELP_STR
11651 BGP_SAFI_HELP_STR
11652 "Route leaking information\n"
11653 JSON_STR)
53089bec 11654{
11655 char *vrf = NULL;
11656 afi_t afi = AFI_MAX;
11657 safi_t safi = SAFI_MAX;
11658
9f049418 11659 bool uj = use_json(argc, argv);
53089bec 11660 int idx = 0;
03915806 11661 json_object *json = NULL;
53089bec 11662
11663 /* show [ip] bgp */
11664 if (argv_find(argv, argc, "ip", &idx)) {
11665 afi = AFI_IP;
11666 safi = SAFI_UNICAST;
11667 }
11668 /* [vrf VIEWVRFNAME] */
11669 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11670 vty_out(vty,
11671 "%% This command is not applicable to BGP views\n");
53089bec 11672 return CMD_WARNING;
11673 }
11674
9a8bdf1c
PG
11675 if (argv_find(argv, argc, "vrf", &idx)) {
11676 vrf = argv[idx + 1]->arg;
11677 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11678 vrf = NULL;
11679 }
53089bec 11680 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11681 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11682 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11683 }
11684
11685 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11686 vty_out(vty,
11687 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11688 return CMD_WARNING;
11689 }
11690
03915806
CS
11691 if (vrf && strmatch(vrf, "all"))
11692 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11693
11694 if (uj)
11695 json = json_object_new_object();
11696
11697 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 11698}
11699
d62a17ae 11700static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11701 safi_t safi)
f186de26 11702{
d62a17ae 11703 struct listnode *node, *nnode;
11704 struct bgp *bgp;
f186de26 11705
d62a17ae 11706 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11707 vty_out(vty, "\nInstance %s:\n",
11708 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11709 ? VRF_DEFAULT_NAME
d62a17ae 11710 : bgp->name);
11711 update_group_show(bgp, afi, safi, vty, 0);
11712 }
f186de26 11713}
11714
d62a17ae 11715static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11716 int safi, uint64_t subgrp_id)
4fb25c53 11717{
d62a17ae 11718 struct bgp *bgp;
4fb25c53 11719
d62a17ae 11720 if (name) {
11721 if (strmatch(name, "all")) {
11722 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11723 return CMD_SUCCESS;
11724 } else {
11725 bgp = bgp_lookup_by_name(name);
11726 }
11727 } else {
11728 bgp = bgp_get_default();
11729 }
4fb25c53 11730
d62a17ae 11731 if (bgp)
11732 update_group_show(bgp, afi, safi, vty, subgrp_id);
11733 return CMD_SUCCESS;
4fb25c53
DW
11734}
11735
8fe8a7f6
DS
11736DEFUN (show_ip_bgp_updgrps,
11737 show_ip_bgp_updgrps_cmd,
c1a44e43 11738 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11739 SHOW_STR
11740 IP_STR
11741 BGP_STR
11742 BGP_INSTANCE_HELP_STR
c9e571b4 11743 BGP_AFI_HELP_STR
9bedbb1e 11744 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11745 "Detailed info about dynamic update groups\n"
11746 "Specific subgroup to display detailed info for\n")
8386ac43 11747{
d62a17ae 11748 char *vrf = NULL;
11749 afi_t afi = AFI_IP6;
11750 safi_t safi = SAFI_UNICAST;
11751 uint64_t subgrp_id = 0;
11752
11753 int idx = 0;
11754
11755 /* show [ip] bgp */
11756 if (argv_find(argv, argc, "ip", &idx))
11757 afi = AFI_IP;
9a8bdf1c
PG
11758 /* [<vrf> VIEWVRFNAME] */
11759 if (argv_find(argv, argc, "vrf", &idx)) {
11760 vrf = argv[idx + 1]->arg;
11761 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11762 vrf = NULL;
11763 } else if (argv_find(argv, argc, "view", &idx))
11764 /* [<view> VIEWVRFNAME] */
11765 vrf = argv[idx + 1]->arg;
d62a17ae 11766 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11767 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11768 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11769 }
5bf15956 11770
d62a17ae 11771 /* get subgroup id, if provided */
11772 idx = argc - 1;
11773 if (argv[idx]->type == VARIABLE_TKN)
11774 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11775
d62a17ae 11776 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11777}
11778
f186de26 11779DEFUN (show_bgp_instance_all_ipv6_updgrps,
11780 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11781 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11782 SHOW_STR
716b2d8a 11783 IP_STR
f186de26 11784 BGP_STR
11785 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11786 "Detailed info about dynamic update groups\n")
f186de26 11787{
d62a17ae 11788 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11789 return CMD_SUCCESS;
f186de26 11790}
11791
43d3f4fc
DS
11792DEFUN (show_bgp_l2vpn_evpn_updgrps,
11793 show_bgp_l2vpn_evpn_updgrps_cmd,
11794 "show [ip] bgp l2vpn evpn update-groups",
11795 SHOW_STR
11796 IP_STR
11797 BGP_STR
11798 "l2vpn address family\n"
11799 "evpn sub-address family\n"
11800 "Detailed info about dynamic update groups\n")
11801{
11802 char *vrf = NULL;
11803 uint64_t subgrp_id = 0;
11804
11805 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11806 return CMD_SUCCESS;
11807}
11808
5bf15956
DW
11809DEFUN (show_bgp_updgrps_stats,
11810 show_bgp_updgrps_stats_cmd,
716b2d8a 11811 "show [ip] bgp update-groups statistics",
3f9c7369 11812 SHOW_STR
716b2d8a 11813 IP_STR
3f9c7369 11814 BGP_STR
0c7b1b01 11815 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11816 "Statistics\n")
11817{
d62a17ae 11818 struct bgp *bgp;
3f9c7369 11819
d62a17ae 11820 bgp = bgp_get_default();
11821 if (bgp)
11822 update_group_show_stats(bgp, vty);
3f9c7369 11823
d62a17ae 11824 return CMD_SUCCESS;
3f9c7369
DS
11825}
11826
8386ac43 11827DEFUN (show_bgp_instance_updgrps_stats,
11828 show_bgp_instance_updgrps_stats_cmd,
18c57037 11829 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11830 SHOW_STR
716b2d8a 11831 IP_STR
8386ac43 11832 BGP_STR
11833 BGP_INSTANCE_HELP_STR
0c7b1b01 11834 "Detailed info about dynamic update groups\n"
8386ac43 11835 "Statistics\n")
11836{
d62a17ae 11837 int idx_word = 3;
11838 struct bgp *bgp;
8386ac43 11839
d62a17ae 11840 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11841 if (bgp)
11842 update_group_show_stats(bgp, vty);
8386ac43 11843
d62a17ae 11844 return CMD_SUCCESS;
8386ac43 11845}
11846
d62a17ae 11847static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11848 afi_t afi, safi_t safi,
11849 const char *what, uint64_t subgrp_id)
3f9c7369 11850{
d62a17ae 11851 struct bgp *bgp;
8386ac43 11852
d62a17ae 11853 if (name)
11854 bgp = bgp_lookup_by_name(name);
11855 else
11856 bgp = bgp_get_default();
8386ac43 11857
d62a17ae 11858 if (bgp) {
11859 if (!strcmp(what, "advertise-queue"))
11860 update_group_show_adj_queue(bgp, afi, safi, vty,
11861 subgrp_id);
11862 else if (!strcmp(what, "advertised-routes"))
11863 update_group_show_advertised(bgp, afi, safi, vty,
11864 subgrp_id);
11865 else if (!strcmp(what, "packet-queue"))
11866 update_group_show_packet_queue(bgp, afi, safi, vty,
11867 subgrp_id);
11868 }
3f9c7369
DS
11869}
11870
dc64bdec
QY
11871DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11872 show_ip_bgp_instance_updgrps_adj_s_cmd,
11873 "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",
11874 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11875 BGP_SAFI_HELP_STR
11876 "Detailed info about dynamic update groups\n"
11877 "Specific subgroup to display info for\n"
11878 "Advertisement queue\n"
11879 "Announced routes\n"
11880 "Packet queue\n")
3f9c7369 11881{
dc64bdec
QY
11882 uint64_t subgrp_id = 0;
11883 afi_t afiz;
11884 safi_t safiz;
11885 if (sgid)
11886 subgrp_id = strtoull(sgid, NULL, 10);
11887
11888 if (!ip && !afi)
11889 afiz = AFI_IP6;
11890 if (!ip && afi)
11891 afiz = bgp_vty_afi_from_str(afi);
11892 if (ip && !afi)
11893 afiz = AFI_IP;
11894 if (ip && afi) {
11895 afiz = bgp_vty_afi_from_str(afi);
11896 if (afiz != AFI_IP)
11897 vty_out(vty,
11898 "%% Cannot specify both 'ip' and 'ipv6'\n");
11899 return CMD_WARNING;
11900 }
d62a17ae 11901
dc64bdec 11902 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11903
dc64bdec 11904 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11905 return CMD_SUCCESS;
11906}
11907
d62a17ae 11908static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11909{
11910 struct listnode *node, *nnode;
11911 struct prefix *range;
11912 struct peer *conf;
11913 struct peer *peer;
11914 char buf[PREFIX2STR_BUFFER];
11915 afi_t afi;
11916 safi_t safi;
11917 const char *peer_status;
11918 const char *af_str;
11919 int lr_count;
11920 int dynamic;
11921 int af_cfgd;
11922
11923 conf = group->conf;
11924
11925 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
3b61f610
QY
11926 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11927 group->name, conf->as);
d62a17ae 11928 } else if (conf->as_type == AS_INTERNAL) {
3b61f610
QY
11929 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11930 group->name, group->bgp->as);
d62a17ae 11931 } else {
11932 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11933 }
f14e6fdb 11934
d62a17ae 11935 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11936 vty_out(vty, " Peer-group type is internal\n");
11937 else
11938 vty_out(vty, " Peer-group type is external\n");
11939
11940 /* Display AFs configured. */
11941 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11942 FOREACH_AFI_SAFI (afi, safi) {
11943 if (conf->afc[afi][safi]) {
11944 af_cfgd = 1;
5cb5f4d0 11945 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 11946 }
05c7a1cc 11947 }
d62a17ae 11948 if (!af_cfgd)
11949 vty_out(vty, " none\n");
11950 else
11951 vty_out(vty, "\n");
11952
11953 /* Display listen ranges (for dynamic neighbors), if any */
11954 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11955 if (afi == AFI_IP)
11956 af_str = "IPv4";
11957 else if (afi == AFI_IP6)
11958 af_str = "IPv6";
11959 else
11960 af_str = "???";
11961 lr_count = listcount(group->listen_range[afi]);
11962 if (lr_count) {
11963 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11964 af_str);
11965
11966
11967 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11968 nnode, range)) {
11969 prefix2str(range, buf, sizeof(buf));
11970 vty_out(vty, " %s\n", buf);
11971 }
11972 }
11973 }
f14e6fdb 11974
d62a17ae 11975 /* Display group members and their status */
11976 if (listcount(group->peer)) {
11977 vty_out(vty, " Peer-group members:\n");
11978 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11979 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11980 peer_status = "Idle (Admin)";
11981 else if (CHECK_FLAG(peer->sflags,
11982 PEER_STATUS_PREFIX_OVERFLOW))
11983 peer_status = "Idle (PfxCt)";
11984 else
11985 peer_status = lookup_msg(bgp_status_msg,
11986 peer->status, NULL);
11987
11988 dynamic = peer_dynamic_neighbor(peer);
11989 vty_out(vty, " %s %s %s \n", peer->host,
11990 dynamic ? "(dynamic)" : "", peer_status);
11991 }
11992 }
f14e6fdb 11993
d62a17ae 11994 return CMD_SUCCESS;
11995}
11996
ff9959b0
QY
11997static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11998 const char *group_name)
d62a17ae 11999{
ff9959b0 12000 struct bgp *bgp;
d62a17ae 12001 struct listnode *node, *nnode;
12002 struct peer_group *group;
ff9959b0
QY
12003 bool found = false;
12004
12005 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12006
12007 if (!bgp) {
9f049418 12008 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
12009 return CMD_WARNING;
12010 }
d62a17ae 12011
12012 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
12013 if (group_name) {
12014 if (strmatch(group->name, group_name)) {
d62a17ae 12015 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
12016 found = true;
12017 break;
d62a17ae 12018 }
ff9959b0
QY
12019 } else {
12020 bgp_show_one_peer_group(vty, group);
d62a17ae 12021 }
f14e6fdb 12022 }
f14e6fdb 12023
ff9959b0 12024 if (group_name && !found)
d62a17ae 12025 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 12026
d62a17ae 12027 return CMD_SUCCESS;
f14e6fdb
DS
12028}
12029
f14e6fdb
DS
12030DEFUN (show_ip_bgp_peer_groups,
12031 show_ip_bgp_peer_groups_cmd,
18c57037 12032 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
12033 SHOW_STR
12034 IP_STR
12035 BGP_STR
8386ac43 12036 BGP_INSTANCE_HELP_STR
d6e3c605
QY
12037 "Detailed information on BGP peer groups\n"
12038 "Peer group name\n")
f14e6fdb 12039{
d62a17ae 12040 char *vrf, *pg;
d62a17ae 12041 int idx = 0;
f14e6fdb 12042
a4d82a8a
PZ
12043 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
12044 : NULL;
d62a17ae 12045 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 12046
ff9959b0 12047 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 12048}
3f9c7369 12049
d6e3c605 12050
718e3744 12051/* Redistribute VTY commands. */
12052
718e3744 12053DEFUN (bgp_redistribute_ipv4,
12054 bgp_redistribute_ipv4_cmd,
40d1cbfb 12055 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 12056 "Redistribute information from another routing protocol\n"
ab0181ee 12057 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 12058{
d62a17ae 12059 VTY_DECLVAR_CONTEXT(bgp, bgp);
12060 int idx_protocol = 1;
12061 int type;
718e3744 12062
d62a17ae 12063 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12064 if (type < 0) {
12065 vty_out(vty, "%% Invalid route type\n");
12066 return CMD_WARNING_CONFIG_FAILED;
12067 }
7f323236 12068
d62a17ae 12069 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12070 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 12071}
12072
d62a17ae 12073ALIAS_HIDDEN(
12074 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
12075 "redistribute " FRR_IP_REDIST_STR_BGPD,
12076 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 12077
718e3744 12078DEFUN (bgp_redistribute_ipv4_rmap,
12079 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 12080 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 12081 "Redistribute information from another routing protocol\n"
ab0181ee 12082 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12083 "Route map reference\n"
12084 "Pointer to route-map entries\n")
12085{
d62a17ae 12086 VTY_DECLVAR_CONTEXT(bgp, bgp);
12087 int idx_protocol = 1;
12088 int idx_word = 3;
12089 int type;
12090 struct bgp_redist *red;
e923dd62 12091 bool changed;
1de27621
DA
12092 struct route_map *route_map = route_map_lookup_warn_noexist(
12093 vty, argv[idx_word]->arg);
718e3744 12094
d62a17ae 12095 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12096 if (type < 0) {
12097 vty_out(vty, "%% Invalid route type\n");
12098 return CMD_WARNING_CONFIG_FAILED;
12099 }
718e3744 12100
d62a17ae 12101 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
12102 changed =
12103 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12104 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 12105}
12106
d62a17ae 12107ALIAS_HIDDEN(
12108 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12109 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12110 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12111 "Route map reference\n"
12112 "Pointer to route-map entries\n")
596c17ba 12113
718e3744 12114DEFUN (bgp_redistribute_ipv4_metric,
12115 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 12116 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12117 "Redistribute information from another routing protocol\n"
ab0181ee 12118 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12119 "Metric for redistributed routes\n"
12120 "Default metric\n")
12121{
d62a17ae 12122 VTY_DECLVAR_CONTEXT(bgp, bgp);
12123 int idx_protocol = 1;
12124 int idx_number = 3;
12125 int type;
d7c0a89a 12126 uint32_t metric;
d62a17ae 12127 struct bgp_redist *red;
e923dd62 12128 bool changed;
d62a17ae 12129
12130 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12131 if (type < 0) {
12132 vty_out(vty, "%% Invalid route type\n");
12133 return CMD_WARNING_CONFIG_FAILED;
12134 }
12135 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12136
12137 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12138 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12139 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12140}
12141
12142ALIAS_HIDDEN(
12143 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12144 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12145 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12146 "Metric for redistributed routes\n"
12147 "Default metric\n")
596c17ba 12148
718e3744 12149DEFUN (bgp_redistribute_ipv4_rmap_metric,
12150 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 12151 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12152 "Redistribute information from another routing protocol\n"
ab0181ee 12153 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12154 "Route map reference\n"
12155 "Pointer to route-map entries\n"
12156 "Metric for redistributed routes\n"
12157 "Default metric\n")
12158{
d62a17ae 12159 VTY_DECLVAR_CONTEXT(bgp, bgp);
12160 int idx_protocol = 1;
12161 int idx_word = 3;
12162 int idx_number = 5;
12163 int type;
d7c0a89a 12164 uint32_t metric;
d62a17ae 12165 struct bgp_redist *red;
e923dd62 12166 bool changed;
1de27621
DA
12167 struct route_map *route_map =
12168 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12169
12170 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12171 if (type < 0) {
12172 vty_out(vty, "%% Invalid route type\n");
12173 return CMD_WARNING_CONFIG_FAILED;
12174 }
12175 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12176
12177 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
12178 changed =
12179 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12180 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12181 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12182}
12183
12184ALIAS_HIDDEN(
12185 bgp_redistribute_ipv4_rmap_metric,
12186 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12187 "redistribute " FRR_IP_REDIST_STR_BGPD
12188 " route-map WORD metric (0-4294967295)",
12189 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12190 "Route map reference\n"
12191 "Pointer to route-map entries\n"
12192 "Metric for redistributed routes\n"
12193 "Default metric\n")
596c17ba 12194
718e3744 12195DEFUN (bgp_redistribute_ipv4_metric_rmap,
12196 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 12197 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12198 "Redistribute information from another routing protocol\n"
ab0181ee 12199 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12200 "Metric for redistributed routes\n"
12201 "Default metric\n"
12202 "Route map reference\n"
12203 "Pointer to route-map entries\n")
12204{
d62a17ae 12205 VTY_DECLVAR_CONTEXT(bgp, bgp);
12206 int idx_protocol = 1;
12207 int idx_number = 3;
12208 int idx_word = 5;
12209 int type;
d7c0a89a 12210 uint32_t metric;
d62a17ae 12211 struct bgp_redist *red;
e923dd62 12212 bool changed;
1de27621
DA
12213 struct route_map *route_map =
12214 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12215
12216 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12217 if (type < 0) {
12218 vty_out(vty, "%% Invalid route type\n");
12219 return CMD_WARNING_CONFIG_FAILED;
12220 }
12221 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12222
12223 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12224 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
12225 changed |=
12226 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12227 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12228}
12229
12230ALIAS_HIDDEN(
12231 bgp_redistribute_ipv4_metric_rmap,
12232 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12233 "redistribute " FRR_IP_REDIST_STR_BGPD
12234 " metric (0-4294967295) route-map WORD",
12235 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12236 "Metric for redistributed routes\n"
12237 "Default metric\n"
12238 "Route map reference\n"
12239 "Pointer to route-map entries\n")
596c17ba 12240
7c8ff89e
DS
12241DEFUN (bgp_redistribute_ipv4_ospf,
12242 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 12243 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
12244 "Redistribute information from another routing protocol\n"
12245 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12246 "Non-main Kernel Routing Table\n"
12247 "Instance ID/Table ID\n")
7c8ff89e 12248{
d62a17ae 12249 VTY_DECLVAR_CONTEXT(bgp, bgp);
12250 int idx_ospf_table = 1;
12251 int idx_number = 2;
d7c0a89a
QY
12252 unsigned short instance;
12253 unsigned short protocol;
7c8ff89e 12254
d62a17ae 12255 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 12256
d62a17ae 12257 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12258 protocol = ZEBRA_ROUTE_OSPF;
12259 else
12260 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 12261
d62a17ae 12262 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12263 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
12264}
12265
d62a17ae 12266ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12267 "redistribute <ospf|table> (1-65535)",
12268 "Redistribute information from another routing protocol\n"
12269 "Open Shortest Path First (OSPFv2)\n"
12270 "Non-main Kernel Routing Table\n"
12271 "Instance ID/Table ID\n")
596c17ba 12272
7c8ff89e
DS
12273DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12274 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 12275 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
12276 "Redistribute information from another routing protocol\n"
12277 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12278 "Non-main Kernel Routing Table\n"
12279 "Instance ID/Table ID\n"
7c8ff89e
DS
12280 "Route map reference\n"
12281 "Pointer to route-map entries\n")
12282{
d62a17ae 12283 VTY_DECLVAR_CONTEXT(bgp, bgp);
12284 int idx_ospf_table = 1;
12285 int idx_number = 2;
12286 int idx_word = 4;
12287 struct bgp_redist *red;
d7c0a89a 12288 unsigned short instance;
d62a17ae 12289 int protocol;
e923dd62 12290 bool changed;
1de27621
DA
12291 struct route_map *route_map =
12292 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12293
12294 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12295 protocol = ZEBRA_ROUTE_OSPF;
12296 else
12297 protocol = ZEBRA_ROUTE_TABLE;
12298
12299 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12300 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12301 changed =
12302 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12303 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12304}
12305
12306ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12307 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12308 "redistribute <ospf|table> (1-65535) route-map WORD",
12309 "Redistribute information from another routing protocol\n"
12310 "Open Shortest Path First (OSPFv2)\n"
12311 "Non-main Kernel Routing Table\n"
12312 "Instance ID/Table ID\n"
12313 "Route map reference\n"
12314 "Pointer to route-map entries\n")
596c17ba 12315
7c8ff89e
DS
12316DEFUN (bgp_redistribute_ipv4_ospf_metric,
12317 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 12318 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
12319 "Redistribute information from another routing protocol\n"
12320 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12321 "Non-main Kernel Routing Table\n"
12322 "Instance ID/Table ID\n"
7c8ff89e
DS
12323 "Metric for redistributed routes\n"
12324 "Default metric\n")
12325{
d62a17ae 12326 VTY_DECLVAR_CONTEXT(bgp, bgp);
12327 int idx_ospf_table = 1;
12328 int idx_number = 2;
12329 int idx_number_2 = 4;
d7c0a89a 12330 uint32_t metric;
d62a17ae 12331 struct bgp_redist *red;
d7c0a89a 12332 unsigned short instance;
d62a17ae 12333 int protocol;
e923dd62 12334 bool changed;
d62a17ae 12335
12336 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12337 protocol = ZEBRA_ROUTE_OSPF;
12338 else
12339 protocol = ZEBRA_ROUTE_TABLE;
12340
12341 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12342 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12343
12344 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12345 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12346 metric);
12347 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12348}
12349
12350ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12351 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12352 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12353 "Redistribute information from another routing protocol\n"
12354 "Open Shortest Path First (OSPFv2)\n"
12355 "Non-main Kernel Routing Table\n"
12356 "Instance ID/Table ID\n"
12357 "Metric for redistributed routes\n"
12358 "Default metric\n")
596c17ba 12359
7c8ff89e
DS
12360DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12361 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 12362 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
12363 "Redistribute information from another routing protocol\n"
12364 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12365 "Non-main Kernel Routing Table\n"
12366 "Instance ID/Table ID\n"
7c8ff89e
DS
12367 "Route map reference\n"
12368 "Pointer to route-map entries\n"
12369 "Metric for redistributed routes\n"
12370 "Default metric\n")
12371{
d62a17ae 12372 VTY_DECLVAR_CONTEXT(bgp, bgp);
12373 int idx_ospf_table = 1;
12374 int idx_number = 2;
12375 int idx_word = 4;
12376 int idx_number_2 = 6;
d7c0a89a 12377 uint32_t metric;
d62a17ae 12378 struct bgp_redist *red;
d7c0a89a 12379 unsigned short instance;
d62a17ae 12380 int protocol;
e923dd62 12381 bool changed;
1de27621
DA
12382 struct route_map *route_map =
12383 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12384
12385 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12386 protocol = ZEBRA_ROUTE_OSPF;
12387 else
12388 protocol = ZEBRA_ROUTE_TABLE;
12389
12390 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12391 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12392
12393 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12394 changed =
12395 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12396 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12397 metric);
12398 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12399}
12400
12401ALIAS_HIDDEN(
12402 bgp_redistribute_ipv4_ospf_rmap_metric,
12403 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12404 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
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"
12411 "Metric for redistributed routes\n"
12412 "Default metric\n")
596c17ba 12413
7c8ff89e
DS
12414DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12415 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 12416 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
12417 "Redistribute information from another routing protocol\n"
12418 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12419 "Non-main Kernel Routing Table\n"
12420 "Instance ID/Table ID\n"
7c8ff89e
DS
12421 "Metric for redistributed routes\n"
12422 "Default metric\n"
12423 "Route map reference\n"
12424 "Pointer to route-map entries\n")
12425{
d62a17ae 12426 VTY_DECLVAR_CONTEXT(bgp, bgp);
12427 int idx_ospf_table = 1;
12428 int idx_number = 2;
12429 int idx_number_2 = 4;
12430 int idx_word = 6;
d7c0a89a 12431 uint32_t metric;
d62a17ae 12432 struct bgp_redist *red;
d7c0a89a 12433 unsigned short instance;
d62a17ae 12434 int protocol;
e923dd62 12435 bool changed;
1de27621
DA
12436 struct route_map *route_map =
12437 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12438
12439 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12440 protocol = ZEBRA_ROUTE_OSPF;
12441 else
12442 protocol = ZEBRA_ROUTE_TABLE;
12443
12444 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12445 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12446
12447 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12448 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12449 metric);
1de27621
DA
12450 changed |=
12451 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12452 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12453}
12454
12455ALIAS_HIDDEN(
12456 bgp_redistribute_ipv4_ospf_metric_rmap,
12457 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12458 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12459 "Redistribute information from another routing protocol\n"
12460 "Open Shortest Path First (OSPFv2)\n"
12461 "Non-main Kernel Routing Table\n"
12462 "Instance ID/Table ID\n"
12463 "Metric for redistributed routes\n"
12464 "Default metric\n"
12465 "Route map reference\n"
12466 "Pointer to route-map entries\n")
596c17ba 12467
7c8ff89e
DS
12468DEFUN (no_bgp_redistribute_ipv4_ospf,
12469 no_bgp_redistribute_ipv4_ospf_cmd,
e27957c0 12470 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
7c8ff89e
DS
12471 NO_STR
12472 "Redistribute information from another routing protocol\n"
12473 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 12474 "Non-main Kernel Routing Table\n"
31500417
DW
12475 "Instance ID/Table ID\n"
12476 "Metric for redistributed routes\n"
12477 "Default metric\n"
12478 "Route map reference\n"
12479 "Pointer to route-map entries\n")
7c8ff89e 12480{
d62a17ae 12481 VTY_DECLVAR_CONTEXT(bgp, bgp);
12482 int idx_ospf_table = 2;
12483 int idx_number = 3;
d7c0a89a 12484 unsigned short instance;
d62a17ae 12485 int protocol;
12486
12487 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12488 protocol = ZEBRA_ROUTE_OSPF;
12489 else
12490 protocol = ZEBRA_ROUTE_TABLE;
12491
12492 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12493 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12494}
12495
12496ALIAS_HIDDEN(
12497 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 12498 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 12499 NO_STR
12500 "Redistribute information from another routing protocol\n"
12501 "Open Shortest Path First (OSPFv2)\n"
12502 "Non-main Kernel Routing Table\n"
12503 "Instance ID/Table ID\n"
12504 "Metric for redistributed routes\n"
12505 "Default metric\n"
12506 "Route map reference\n"
12507 "Pointer to route-map entries\n")
596c17ba 12508
718e3744 12509DEFUN (no_bgp_redistribute_ipv4,
12510 no_bgp_redistribute_ipv4_cmd,
e27957c0 12511 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 12512 NO_STR
12513 "Redistribute information from another routing protocol\n"
3b14d86e 12514 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
12515 "Metric for redistributed routes\n"
12516 "Default metric\n"
12517 "Route map reference\n"
12518 "Pointer to route-map entries\n")
718e3744 12519{
d62a17ae 12520 VTY_DECLVAR_CONTEXT(bgp, bgp);
12521 int idx_protocol = 2;
12522 int type;
12523
12524 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12525 if (type < 0) {
12526 vty_out(vty, "%% Invalid route type\n");
12527 return CMD_WARNING_CONFIG_FAILED;
12528 }
12529 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12530}
12531
12532ALIAS_HIDDEN(
12533 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12534 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 12535 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 12536 NO_STR
12537 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12538 "Metric for redistributed routes\n"
12539 "Default metric\n"
12540 "Route map reference\n"
12541 "Pointer to route-map entries\n")
596c17ba 12542
718e3744 12543DEFUN (bgp_redistribute_ipv6,
12544 bgp_redistribute_ipv6_cmd,
40d1cbfb 12545 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 12546 "Redistribute information from another routing protocol\n"
ab0181ee 12547 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 12548{
d62a17ae 12549 VTY_DECLVAR_CONTEXT(bgp, bgp);
12550 int idx_protocol = 1;
12551 int type;
718e3744 12552
d62a17ae 12553 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12554 if (type < 0) {
12555 vty_out(vty, "%% Invalid route type\n");
12556 return CMD_WARNING_CONFIG_FAILED;
12557 }
718e3744 12558
d62a17ae 12559 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12560 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 12561}
12562
12563DEFUN (bgp_redistribute_ipv6_rmap,
12564 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 12565 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 12566 "Redistribute information from another routing protocol\n"
ab0181ee 12567 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12568 "Route map reference\n"
12569 "Pointer to route-map entries\n")
12570{
d62a17ae 12571 VTY_DECLVAR_CONTEXT(bgp, bgp);
12572 int idx_protocol = 1;
12573 int idx_word = 3;
12574 int type;
12575 struct bgp_redist *red;
e923dd62 12576 bool changed;
1de27621
DA
12577 struct route_map *route_map =
12578 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 12579
d62a17ae 12580 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12581 if (type < 0) {
12582 vty_out(vty, "%% Invalid route type\n");
12583 return CMD_WARNING_CONFIG_FAILED;
12584 }
718e3744 12585
d62a17ae 12586 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12587 changed =
12588 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12589 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12590}
12591
12592DEFUN (bgp_redistribute_ipv6_metric,
12593 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 12594 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12595 "Redistribute information from another routing protocol\n"
ab0181ee 12596 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12597 "Metric for redistributed routes\n"
12598 "Default metric\n")
12599{
d62a17ae 12600 VTY_DECLVAR_CONTEXT(bgp, bgp);
12601 int idx_protocol = 1;
12602 int idx_number = 3;
12603 int type;
d7c0a89a 12604 uint32_t metric;
d62a17ae 12605 struct bgp_redist *red;
e923dd62 12606 bool changed;
d62a17ae 12607
12608 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12609 if (type < 0) {
12610 vty_out(vty, "%% Invalid route type\n");
12611 return CMD_WARNING_CONFIG_FAILED;
12612 }
12613 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12614
d62a17ae 12615 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12616 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12617 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12618}
12619
12620DEFUN (bgp_redistribute_ipv6_rmap_metric,
12621 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 12622 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12623 "Redistribute information from another routing protocol\n"
ab0181ee 12624 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12625 "Route map reference\n"
12626 "Pointer to route-map entries\n"
12627 "Metric for redistributed routes\n"
12628 "Default metric\n")
12629{
d62a17ae 12630 VTY_DECLVAR_CONTEXT(bgp, bgp);
12631 int idx_protocol = 1;
12632 int idx_word = 3;
12633 int idx_number = 5;
12634 int type;
d7c0a89a 12635 uint32_t metric;
d62a17ae 12636 struct bgp_redist *red;
e923dd62 12637 bool changed;
1de27621
DA
12638 struct route_map *route_map =
12639 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12640
12641 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12642 if (type < 0) {
12643 vty_out(vty, "%% Invalid route type\n");
12644 return CMD_WARNING_CONFIG_FAILED;
12645 }
12646 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12647
d62a17ae 12648 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12649 changed =
12650 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12651 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12652 metric);
12653 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12654}
12655
12656DEFUN (bgp_redistribute_ipv6_metric_rmap,
12657 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 12658 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12659 "Redistribute information from another routing protocol\n"
ab0181ee 12660 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12661 "Metric for redistributed routes\n"
12662 "Default metric\n"
12663 "Route map reference\n"
12664 "Pointer to route-map entries\n")
12665{
d62a17ae 12666 VTY_DECLVAR_CONTEXT(bgp, bgp);
12667 int idx_protocol = 1;
12668 int idx_number = 3;
12669 int idx_word = 5;
12670 int type;
d7c0a89a 12671 uint32_t metric;
d62a17ae 12672 struct bgp_redist *red;
e923dd62 12673 bool changed;
1de27621
DA
12674 struct route_map *route_map =
12675 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12676
12677 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12678 if (type < 0) {
12679 vty_out(vty, "%% Invalid route type\n");
12680 return CMD_WARNING_CONFIG_FAILED;
12681 }
12682 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12683
d62a17ae 12684 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12685 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12686 metric);
1de27621
DA
12687 changed |=
12688 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12689 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12690}
12691
12692DEFUN (no_bgp_redistribute_ipv6,
12693 no_bgp_redistribute_ipv6_cmd,
e27957c0 12694 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 12695 NO_STR
12696 "Redistribute information from another routing protocol\n"
3b14d86e 12697 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12698 "Metric for redistributed routes\n"
12699 "Default metric\n"
12700 "Route map reference\n"
12701 "Pointer to route-map entries\n")
718e3744 12702{
d62a17ae 12703 VTY_DECLVAR_CONTEXT(bgp, bgp);
12704 int idx_protocol = 2;
12705 int type;
718e3744 12706
d62a17ae 12707 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12708 if (type < 0) {
12709 vty_out(vty, "%% Invalid route type\n");
12710 return CMD_WARNING_CONFIG_FAILED;
12711 }
718e3744 12712
d62a17ae 12713 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12714}
12715
2b791107 12716void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12717 safi_t safi)
d62a17ae 12718{
12719 int i;
12720
12721 /* Unicast redistribution only. */
12722 if (safi != SAFI_UNICAST)
2b791107 12723 return;
d62a17ae 12724
12725 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12726 /* Redistribute BGP does not make sense. */
12727 if (i != ZEBRA_ROUTE_BGP) {
12728 struct list *red_list;
12729 struct listnode *node;
12730 struct bgp_redist *red;
12731
12732 red_list = bgp->redist[afi][i];
12733 if (!red_list)
12734 continue;
12735
12736 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12737 /* "redistribute" configuration. */
12738 vty_out(vty, " redistribute %s",
12739 zebra_route_string(i));
12740 if (red->instance)
12741 vty_out(vty, " %d", red->instance);
12742 if (red->redist_metric_flag)
12743 vty_out(vty, " metric %u",
12744 red->redist_metric);
12745 if (red->rmap.name)
12746 vty_out(vty, " route-map %s",
12747 red->rmap.name);
12748 vty_out(vty, "\n");
12749 }
12750 }
12751 }
718e3744 12752}
6b0655a2 12753
b9c7bc5a
PZ
12754/* This is part of the address-family block (unicast only) */
12755void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12756 afi_t afi)
12757{
b9c7bc5a 12758 int indent = 2;
ddb5b488 12759
8a066a70
PG
12760 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12761 if (listcount(bgp->vpn_policy[afi].import_vrf))
12762 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12763 bgp->vpn_policy[afi]
bb4f6190 12764 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
12765 else
12766 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12767 bgp->vpn_policy[afi]
12768 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12769 }
12a844a5
DS
12770 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12771 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12772 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12773 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12774 return;
12775
e70e9f8e
PZ
12776 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12777 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12778
12779 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12780
12781 } else {
12782 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12783 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12784 bgp->vpn_policy[afi].tovpn_label);
12785 }
ddb5b488
PZ
12786 }
12787 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12788 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12789 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12790 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12791 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12792 sizeof(buf)));
12793 }
12794 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12795 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12796
12797 char buf[PREFIX_STRLEN];
12798 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12799 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12800 sizeof(buf))) {
12801
b9c7bc5a
PZ
12802 vty_out(vty, "%*snexthop vpn export %s\n",
12803 indent, "", buf);
ddb5b488
PZ
12804 }
12805 }
12806 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12807 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12808 && ecommunity_cmp(
12809 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12810 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12811
12812 char *b = ecommunity_ecom2str(
12813 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12814 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12815 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12816 XFREE(MTYPE_ECOMMUNITY_STR, b);
12817 } else {
12818 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12819 char *b = ecommunity_ecom2str(
12820 bgp->vpn_policy[afi]
12821 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12822 ECOMMUNITY_FORMAT_ROUTE_MAP,
12823 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12824 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12825 XFREE(MTYPE_ECOMMUNITY_STR, b);
12826 }
12827 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12828 char *b = ecommunity_ecom2str(
12829 bgp->vpn_policy[afi]
12830 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12831 ECOMMUNITY_FORMAT_ROUTE_MAP,
12832 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12833 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12834 XFREE(MTYPE_ECOMMUNITY_STR, b);
12835 }
12836 }
bb4f6190
DS
12837
12838 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12839 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12840 bgp->vpn_policy[afi]
12841 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12842
301ad80a
PG
12843 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12844 char *b = ecommunity_ecom2str(
12845 bgp->vpn_policy[afi]
12846 .import_redirect_rtlist,
12847 ECOMMUNITY_FORMAT_ROUTE_MAP,
12848 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12849
301ad80a
PG
12850 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12851 XFREE(MTYPE_ECOMMUNITY_STR, b);
12852 }
ddb5b488
PZ
12853}
12854
12855
718e3744 12856/* BGP node structure. */
d62a17ae 12857static struct cmd_node bgp_node = {
9d303b37 12858 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12859};
12860
d62a17ae 12861static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12862 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12863};
12864
d62a17ae 12865static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12866 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12867};
12868
d62a17ae 12869static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12870 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12871};
12872
d62a17ae 12873static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12874 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12875};
12876
d62a17ae 12877static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12878 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12879};
12880
d62a17ae 12881static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12882 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12883};
12884
d62a17ae 12885static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12886 "%s(config-router-af)# ", 1};
6b0655a2 12887
d62a17ae 12888static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12889 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12890
d62a17ae 12891static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12892 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12893
d62a17ae 12894static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12895 "%s(config-router-af-vni)# ", 1};
90e60aa7 12896
7c40bf39 12897static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12898 "%s(config-router-af)# ", 1};
12899
12900static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12901 "%s(config-router-af-vpnv6)# ", 1};
12902
d62a17ae 12903static void community_list_vty(void);
1f8ae70b 12904
d62a17ae 12905static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12906{
d62a17ae 12907 struct bgp *bgp;
12908 struct peer *peer;
d62a17ae 12909 struct listnode *lnbgp, *lnpeer;
b8a815e5 12910
d62a17ae 12911 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12912 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12913 /* only provide suggestions on the appropriate input
12914 * token type,
12915 * they'll otherwise show up multiple times */
12916 enum cmd_token_type match_type;
12917 char *name = peer->host;
d48ed3e0 12918
d62a17ae 12919 if (peer->conf_if) {
12920 match_type = VARIABLE_TKN;
12921 name = peer->conf_if;
12922 } else if (strchr(peer->host, ':'))
12923 match_type = IPV6_TKN;
12924 else
12925 match_type = IPV4_TKN;
d48ed3e0 12926
d62a17ae 12927 if (token->type != match_type)
12928 continue;
d48ed3e0 12929
d62a17ae 12930 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12931 }
d62a17ae 12932 }
b8a815e5
DL
12933}
12934
12935static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12936 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12937 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12938 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12939 {.completions = NULL}};
12940
47a306a0
DS
12941static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12942{
12943 struct bgp *bgp;
12944 struct peer_group *group;
12945 struct listnode *lnbgp, *lnpeer;
12946
12947 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12948 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12949 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12950 group->name));
12951 }
12952}
12953
12954static const struct cmd_variable_handler bgp_var_peergroup[] = {
12955 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12956 {.completions = NULL} };
12957
d62a17ae 12958void bgp_vty_init(void)
12959{
12960 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12961 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12962
12963 /* Install bgp top node. */
12964 install_node(&bgp_node, bgp_config_write);
12965 install_node(&bgp_ipv4_unicast_node, NULL);
12966 install_node(&bgp_ipv4_multicast_node, NULL);
12967 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12968 install_node(&bgp_ipv6_unicast_node, NULL);
12969 install_node(&bgp_ipv6_multicast_node, NULL);
12970 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12971 install_node(&bgp_vpnv4_node, NULL);
12972 install_node(&bgp_vpnv6_node, NULL);
12973 install_node(&bgp_evpn_node, NULL);
12974 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12975 install_node(&bgp_flowspecv4_node, NULL);
12976 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12977
12978 /* Install default VTY commands to new nodes. */
12979 install_default(BGP_NODE);
12980 install_default(BGP_IPV4_NODE);
12981 install_default(BGP_IPV4M_NODE);
12982 install_default(BGP_IPV4L_NODE);
12983 install_default(BGP_IPV6_NODE);
12984 install_default(BGP_IPV6M_NODE);
12985 install_default(BGP_IPV6L_NODE);
12986 install_default(BGP_VPNV4_NODE);
12987 install_default(BGP_VPNV6_NODE);
7c40bf39 12988 install_default(BGP_FLOWSPECV4_NODE);
12989 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12990 install_default(BGP_EVPN_NODE);
12991 install_default(BGP_EVPN_VNI_NODE);
12992
8029b216
AK
12993 /* "bgp local-mac" hidden commands. */
12994 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12995 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12996
d62a17ae 12997 /* bgp route-map delay-timer commands. */
12998 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12999 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13000
13001 /* Dummy commands (Currently not supported) */
13002 install_element(BGP_NODE, &no_synchronization_cmd);
13003 install_element(BGP_NODE, &no_auto_summary_cmd);
13004
13005 /* "router bgp" commands. */
13006 install_element(CONFIG_NODE, &router_bgp_cmd);
13007
13008 /* "no router bgp" commands. */
13009 install_element(CONFIG_NODE, &no_router_bgp_cmd);
13010
13011 /* "bgp router-id" commands. */
13012 install_element(BGP_NODE, &bgp_router_id_cmd);
13013 install_element(BGP_NODE, &no_bgp_router_id_cmd);
13014
13015 /* "bgp cluster-id" commands. */
13016 install_element(BGP_NODE, &bgp_cluster_id_cmd);
13017 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
13018
13019 /* "bgp confederation" commands. */
13020 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
13021 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
13022
13023 /* "bgp confederation peers" commands. */
13024 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
13025 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
13026
13027 /* bgp max-med command */
13028 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
13029 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
13030 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
13031 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
13032 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
13033
13034 /* bgp disable-ebgp-connected-nh-check */
13035 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
13036 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
13037
13038 /* bgp update-delay command */
13039 install_element(BGP_NODE, &bgp_update_delay_cmd);
13040 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
13041 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
13042
13043 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 13044 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 13045
13046 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
13047 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
13048
13049 /* "maximum-paths" commands. */
13050 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
13051 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
13052 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
13053 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
13054 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
13055 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
13056 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
13057 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
13058 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
13059 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
13060 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13061 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
13062 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
13063 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13064 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
13065
13066 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
13067 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
13068 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
13069 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13070 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
13071
13072 /* "timers bgp" commands. */
13073 install_element(BGP_NODE, &bgp_timers_cmd);
13074 install_element(BGP_NODE, &no_bgp_timers_cmd);
13075
13076 /* route-map delay-timer commands - per instance for backwards compat.
13077 */
13078 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
13079 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13080
13081 /* "bgp client-to-client reflection" commands */
13082 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
13083 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
13084
13085 /* "bgp always-compare-med" commands */
13086 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
13087 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
13088
9dac9fc8
DA
13089 /* bgp ebgp-requires-policy */
13090 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
13091 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
13092
d62a17ae 13093 /* "bgp deterministic-med" commands */
13094 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
13095 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
13096
13097 /* "bgp graceful-restart" commands */
13098 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
13099 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
13100 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
13101 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
13102 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
13103 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
13104
13105 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
13106 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
13107
7f323236
DW
13108 /* "bgp graceful-shutdown" commands */
13109 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
13110 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13111
d62a17ae 13112 /* "bgp fast-external-failover" commands */
13113 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13114 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13115
d62a17ae 13116 /* "bgp bestpath compare-routerid" commands */
13117 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13118 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13119
13120 /* "bgp bestpath as-path ignore" commands */
13121 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13122 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13123
13124 /* "bgp bestpath as-path confed" commands */
13125 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13126 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13127
13128 /* "bgp bestpath as-path multipath-relax" commands */
13129 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13130 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13131
13132 /* "bgp log-neighbor-changes" commands */
13133 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13134 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13135
13136 /* "bgp bestpath med" commands */
13137 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13138 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13139
13140 /* "no bgp default ipv4-unicast" commands. */
13141 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13142 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13143
13144 /* "bgp network import-check" commands. */
13145 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13146 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13147 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13148
13149 /* "bgp default local-preference" commands. */
13150 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13151 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13152
13153 /* bgp default show-hostname */
13154 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13155 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13156
13157 /* "bgp default subgroup-pkt-queue-max" commands. */
13158 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13159 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13160
13161 /* bgp ibgp-allow-policy-mods command */
13162 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13163 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13164
13165 /* "bgp listen limit" commands. */
13166 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13167 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13168
13169 /* "bgp listen range" commands. */
13170 install_element(BGP_NODE, &bgp_listen_range_cmd);
13171 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13172
8175f54a 13173 /* "bgp default shutdown" command */
f26845f9
QY
13174 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13175
d62a17ae 13176 /* "neighbor remote-as" commands. */
13177 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13178 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13179 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13180 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13181 install_element(BGP_NODE,
13182 &neighbor_interface_v6only_config_remote_as_cmd);
13183 install_element(BGP_NODE, &no_neighbor_cmd);
13184 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13185
13186 /* "neighbor peer-group" commands. */
13187 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13188 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13189 install_element(BGP_NODE,
13190 &no_neighbor_interface_peer_group_remote_as_cmd);
13191
13192 /* "neighbor local-as" commands. */
13193 install_element(BGP_NODE, &neighbor_local_as_cmd);
13194 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13195 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13196 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13197
13198 /* "neighbor solo" commands. */
13199 install_element(BGP_NODE, &neighbor_solo_cmd);
13200 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13201
13202 /* "neighbor password" commands. */
13203 install_element(BGP_NODE, &neighbor_password_cmd);
13204 install_element(BGP_NODE, &no_neighbor_password_cmd);
13205
13206 /* "neighbor activate" commands. */
13207 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13208 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13209 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13210 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13211 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13212 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13213 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13214 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13215 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 13216 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13217 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 13218 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13219
13220 /* "no neighbor activate" commands. */
13221 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13222 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13223 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13224 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13225 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13226 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13227 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13228 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13229 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 13230 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13231 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 13232 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13233
13234 /* "neighbor peer-group" set commands. */
13235 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13236 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13237 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13238 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13239 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13240 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13241 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13242 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 13243 install_element(BGP_FLOWSPECV4_NODE,
13244 &neighbor_set_peer_group_hidden_cmd);
13245 install_element(BGP_FLOWSPECV6_NODE,
13246 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 13247
13248 /* "no neighbor peer-group unset" commands. */
13249 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13250 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13251 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13252 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13253 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13254 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13255 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13256 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 13257 install_element(BGP_FLOWSPECV4_NODE,
13258 &no_neighbor_set_peer_group_hidden_cmd);
13259 install_element(BGP_FLOWSPECV6_NODE,
13260 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 13261
13262 /* "neighbor softreconfiguration inbound" commands.*/
13263 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13264 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13265 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13266 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13267 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13268 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13269 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13270 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13271 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13272 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13273 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13274 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13275 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13276 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13277 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13278 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13279 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13280 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 13281 install_element(BGP_FLOWSPECV4_NODE,
13282 &neighbor_soft_reconfiguration_cmd);
13283 install_element(BGP_FLOWSPECV4_NODE,
13284 &no_neighbor_soft_reconfiguration_cmd);
13285 install_element(BGP_FLOWSPECV6_NODE,
13286 &neighbor_soft_reconfiguration_cmd);
13287 install_element(BGP_FLOWSPECV6_NODE,
13288 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
13289 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13290 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 13291
13292 /* "neighbor attribute-unchanged" commands. */
13293 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13294 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13295 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13296 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13297 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13298 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13299 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13300 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13301 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13302 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13303 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13304 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13305 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13306 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13307 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13308 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13309 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13310 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13311
13312 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13313 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13314
13315 /* "nexthop-local unchanged" commands */
13316 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13317 install_element(BGP_IPV6_NODE,
13318 &no_neighbor_nexthop_local_unchanged_cmd);
13319
13320 /* "neighbor next-hop-self" commands. */
13321 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13322 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13323 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13324 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13325 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13326 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13327 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13328 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13329 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13330 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13331 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13332 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13333 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13334 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13335 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13336 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13337 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13338 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
13339 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13340 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 13341
13342 /* "neighbor next-hop-self force" commands. */
13343 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13344 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
13345 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13346 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13347 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13348 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13349 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13350 install_element(BGP_IPV4_NODE,
13351 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13352 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13353 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13354 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13355 install_element(BGP_IPV4M_NODE,
13356 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13357 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13358 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13359 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13360 install_element(BGP_IPV4L_NODE,
13361 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13362 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13363 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13364 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13365 install_element(BGP_IPV6_NODE,
13366 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13367 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13368 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13369 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13370 install_element(BGP_IPV6M_NODE,
13371 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13372 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13373 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13374 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13375 install_element(BGP_IPV6L_NODE,
13376 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13377 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13378 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13379 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13380 install_element(BGP_VPNV4_NODE,
13381 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13382 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13383 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13384 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13385 install_element(BGP_VPNV6_NODE,
13386 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13387
13388 /* "neighbor as-override" commands. */
13389 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13390 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13391 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13392 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13393 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13394 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13395 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13396 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13397 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13398 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13399 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13400 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13401 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13402 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13403 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13404 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13405 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13406 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13407
13408 /* "neighbor remove-private-AS" commands. */
13409 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13410 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13411 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13412 install_element(BGP_NODE,
13413 &no_neighbor_remove_private_as_all_hidden_cmd);
13414 install_element(BGP_NODE,
13415 &neighbor_remove_private_as_replace_as_hidden_cmd);
13416 install_element(BGP_NODE,
13417 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13418 install_element(BGP_NODE,
13419 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13420 install_element(
13421 BGP_NODE,
13422 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13423 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13424 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13425 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13426 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13427 install_element(BGP_IPV4_NODE,
13428 &neighbor_remove_private_as_replace_as_cmd);
13429 install_element(BGP_IPV4_NODE,
13430 &no_neighbor_remove_private_as_replace_as_cmd);
13431 install_element(BGP_IPV4_NODE,
13432 &neighbor_remove_private_as_all_replace_as_cmd);
13433 install_element(BGP_IPV4_NODE,
13434 &no_neighbor_remove_private_as_all_replace_as_cmd);
13435 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13436 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13437 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13438 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13439 install_element(BGP_IPV4M_NODE,
13440 &neighbor_remove_private_as_replace_as_cmd);
13441 install_element(BGP_IPV4M_NODE,
13442 &no_neighbor_remove_private_as_replace_as_cmd);
13443 install_element(BGP_IPV4M_NODE,
13444 &neighbor_remove_private_as_all_replace_as_cmd);
13445 install_element(BGP_IPV4M_NODE,
13446 &no_neighbor_remove_private_as_all_replace_as_cmd);
13447 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13448 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13449 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13450 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13451 install_element(BGP_IPV4L_NODE,
13452 &neighbor_remove_private_as_replace_as_cmd);
13453 install_element(BGP_IPV4L_NODE,
13454 &no_neighbor_remove_private_as_replace_as_cmd);
13455 install_element(BGP_IPV4L_NODE,
13456 &neighbor_remove_private_as_all_replace_as_cmd);
13457 install_element(BGP_IPV4L_NODE,
13458 &no_neighbor_remove_private_as_all_replace_as_cmd);
13459 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13460 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13461 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13462 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13463 install_element(BGP_IPV6_NODE,
13464 &neighbor_remove_private_as_replace_as_cmd);
13465 install_element(BGP_IPV6_NODE,
13466 &no_neighbor_remove_private_as_replace_as_cmd);
13467 install_element(BGP_IPV6_NODE,
13468 &neighbor_remove_private_as_all_replace_as_cmd);
13469 install_element(BGP_IPV6_NODE,
13470 &no_neighbor_remove_private_as_all_replace_as_cmd);
13471 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13472 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13473 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13474 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13475 install_element(BGP_IPV6M_NODE,
13476 &neighbor_remove_private_as_replace_as_cmd);
13477 install_element(BGP_IPV6M_NODE,
13478 &no_neighbor_remove_private_as_replace_as_cmd);
13479 install_element(BGP_IPV6M_NODE,
13480 &neighbor_remove_private_as_all_replace_as_cmd);
13481 install_element(BGP_IPV6M_NODE,
13482 &no_neighbor_remove_private_as_all_replace_as_cmd);
13483 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13484 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13485 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13486 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13487 install_element(BGP_IPV6L_NODE,
13488 &neighbor_remove_private_as_replace_as_cmd);
13489 install_element(BGP_IPV6L_NODE,
13490 &no_neighbor_remove_private_as_replace_as_cmd);
13491 install_element(BGP_IPV6L_NODE,
13492 &neighbor_remove_private_as_all_replace_as_cmd);
13493 install_element(BGP_IPV6L_NODE,
13494 &no_neighbor_remove_private_as_all_replace_as_cmd);
13495 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13496 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13497 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13498 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13499 install_element(BGP_VPNV4_NODE,
13500 &neighbor_remove_private_as_replace_as_cmd);
13501 install_element(BGP_VPNV4_NODE,
13502 &no_neighbor_remove_private_as_replace_as_cmd);
13503 install_element(BGP_VPNV4_NODE,
13504 &neighbor_remove_private_as_all_replace_as_cmd);
13505 install_element(BGP_VPNV4_NODE,
13506 &no_neighbor_remove_private_as_all_replace_as_cmd);
13507 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13508 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13509 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13510 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13511 install_element(BGP_VPNV6_NODE,
13512 &neighbor_remove_private_as_replace_as_cmd);
13513 install_element(BGP_VPNV6_NODE,
13514 &no_neighbor_remove_private_as_replace_as_cmd);
13515 install_element(BGP_VPNV6_NODE,
13516 &neighbor_remove_private_as_all_replace_as_cmd);
13517 install_element(BGP_VPNV6_NODE,
13518 &no_neighbor_remove_private_as_all_replace_as_cmd);
13519
13520 /* "neighbor send-community" commands.*/
13521 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13522 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13523 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13524 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13525 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13526 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13527 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13528 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13529 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13530 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13531 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13532 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13533 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13534 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13535 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13536 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13537 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13538 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13539 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13540 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13541 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13542 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13543 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13544 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13545 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13546 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13547 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13548 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13549 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13550 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13551 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13552 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13553 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13554 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13555 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13556 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13557
13558 /* "neighbor route-reflector" commands.*/
13559 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13560 install_element(BGP_NODE,
13561 &no_neighbor_route_reflector_client_hidden_cmd);
13562 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13563 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13564 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13565 install_element(BGP_IPV4M_NODE,
13566 &no_neighbor_route_reflector_client_cmd);
13567 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13568 install_element(BGP_IPV4L_NODE,
13569 &no_neighbor_route_reflector_client_cmd);
13570 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13571 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13572 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13573 install_element(BGP_IPV6M_NODE,
13574 &no_neighbor_route_reflector_client_cmd);
13575 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13576 install_element(BGP_IPV6L_NODE,
13577 &no_neighbor_route_reflector_client_cmd);
13578 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13579 install_element(BGP_VPNV4_NODE,
13580 &no_neighbor_route_reflector_client_cmd);
13581 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13582 install_element(BGP_VPNV6_NODE,
13583 &no_neighbor_route_reflector_client_cmd);
7c40bf39 13584 install_element(BGP_FLOWSPECV4_NODE,
13585 &neighbor_route_reflector_client_cmd);
13586 install_element(BGP_FLOWSPECV4_NODE,
13587 &no_neighbor_route_reflector_client_cmd);
13588 install_element(BGP_FLOWSPECV6_NODE,
13589 &neighbor_route_reflector_client_cmd);
13590 install_element(BGP_FLOWSPECV6_NODE,
13591 &no_neighbor_route_reflector_client_cmd);
d62a17ae 13592 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13593 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13594
13595 /* "neighbor route-server" commands.*/
13596 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13597 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13598 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13599 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13600 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13601 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13602 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13603 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13604 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13605 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13606 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13607 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13608 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13609 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13610 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13611 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13612 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13613 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
13614 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13615 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 13616 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13617 install_element(BGP_FLOWSPECV4_NODE,
13618 &no_neighbor_route_server_client_cmd);
13619 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13620 install_element(BGP_FLOWSPECV6_NODE,
13621 &no_neighbor_route_server_client_cmd);
d62a17ae 13622
13623 /* "neighbor addpath-tx-all-paths" commands.*/
13624 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13625 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13626 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13627 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13628 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13629 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13630 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13631 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13632 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13633 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13634 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13635 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13636 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13637 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13638 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13639 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13640 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13641 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13642
13643 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13644 install_element(BGP_NODE,
13645 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13646 install_element(BGP_NODE,
13647 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13648 install_element(BGP_IPV4_NODE,
13649 &neighbor_addpath_tx_bestpath_per_as_cmd);
13650 install_element(BGP_IPV4_NODE,
13651 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13652 install_element(BGP_IPV4M_NODE,
13653 &neighbor_addpath_tx_bestpath_per_as_cmd);
13654 install_element(BGP_IPV4M_NODE,
13655 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13656 install_element(BGP_IPV4L_NODE,
13657 &neighbor_addpath_tx_bestpath_per_as_cmd);
13658 install_element(BGP_IPV4L_NODE,
13659 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13660 install_element(BGP_IPV6_NODE,
13661 &neighbor_addpath_tx_bestpath_per_as_cmd);
13662 install_element(BGP_IPV6_NODE,
13663 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13664 install_element(BGP_IPV6M_NODE,
13665 &neighbor_addpath_tx_bestpath_per_as_cmd);
13666 install_element(BGP_IPV6M_NODE,
13667 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13668 install_element(BGP_IPV6L_NODE,
13669 &neighbor_addpath_tx_bestpath_per_as_cmd);
13670 install_element(BGP_IPV6L_NODE,
13671 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13672 install_element(BGP_VPNV4_NODE,
13673 &neighbor_addpath_tx_bestpath_per_as_cmd);
13674 install_element(BGP_VPNV4_NODE,
13675 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13676 install_element(BGP_VPNV6_NODE,
13677 &neighbor_addpath_tx_bestpath_per_as_cmd);
13678 install_element(BGP_VPNV6_NODE,
13679 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13680
13681 /* "neighbor passive" commands. */
13682 install_element(BGP_NODE, &neighbor_passive_cmd);
13683 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13684
13685
13686 /* "neighbor shutdown" commands. */
13687 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13688 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13689 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13690 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13691
13692 /* "neighbor capability extended-nexthop" commands.*/
13693 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13694 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13695
13696 /* "neighbor capability orf prefix-list" commands.*/
13697 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13698 install_element(BGP_NODE,
13699 &no_neighbor_capability_orf_prefix_hidden_cmd);
13700 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13701 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13702 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13703 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13704 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13705 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13706 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13707 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13708 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13709 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13710 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13711 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13712
13713 /* "neighbor capability dynamic" commands.*/
13714 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13715 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13716
13717 /* "neighbor dont-capability-negotiate" commands. */
13718 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13719 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13720
13721 /* "neighbor ebgp-multihop" commands. */
13722 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13723 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13724 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13725
13726 /* "neighbor disable-connected-check" commands. */
13727 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13728 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13729
47cbc09b
PM
13730 /* "neighbor enforce-first-as" commands. */
13731 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13732 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13733
d62a17ae 13734 /* "neighbor description" commands. */
13735 install_element(BGP_NODE, &neighbor_description_cmd);
13736 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13737 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13738
13739 /* "neighbor update-source" commands. "*/
13740 install_element(BGP_NODE, &neighbor_update_source_cmd);
13741 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13742
13743 /* "neighbor default-originate" commands. */
13744 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13745 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13746 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13747 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13748 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13749 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13750 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13751 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13752 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13753 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13754 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13755 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13756 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13757 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13758 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13759 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13760 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13761 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13762 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13763 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13764 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13765
13766 /* "neighbor port" commands. */
13767 install_element(BGP_NODE, &neighbor_port_cmd);
13768 install_element(BGP_NODE, &no_neighbor_port_cmd);
13769
13770 /* "neighbor weight" commands. */
13771 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13772 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13773
13774 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13775 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13776 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13777 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13778 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13779 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13780 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13781 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13782 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13783 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13784 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13785 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13786 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13787 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13788 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13789 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13790
13791 /* "neighbor override-capability" commands. */
13792 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13793 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13794
13795 /* "neighbor strict-capability-match" commands. */
13796 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13797 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13798
13799 /* "neighbor timers" commands. */
13800 install_element(BGP_NODE, &neighbor_timers_cmd);
13801 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13802
13803 /* "neighbor timers connect" commands. */
13804 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13805 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13806
13807 /* "neighbor advertisement-interval" commands. */
13808 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13809 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13810
13811 /* "neighbor interface" commands. */
13812 install_element(BGP_NODE, &neighbor_interface_cmd);
13813 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13814
13815 /* "neighbor distribute" commands. */
13816 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13817 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13818 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13819 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13820 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13821 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13822 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13823 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13824 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13825 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13826 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13827 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13828 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13829 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13830 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13831 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13832 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13833 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13834
13835 /* "neighbor prefix-list" commands. */
13836 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13837 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13838 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13839 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13840 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13841 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13842 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13843 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13844 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13845 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13846 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13847 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13848 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13849 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13850 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13851 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13852 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13853 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13854 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13855 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13856 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13857 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13858
13859 /* "neighbor filter-list" commands. */
13860 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13861 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13862 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13863 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13864 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13865 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13866 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13867 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13868 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13869 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13870 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13871 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13872 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13873 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13874 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13875 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13876 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13877 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13878 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13879 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13880 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13881 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13882
13883 /* "neighbor route-map" commands. */
13884 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13885 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13886 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13887 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13888 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13889 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13890 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13891 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13892 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13893 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13894 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13895 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13896 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13897 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13898 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13899 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13900 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13901 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13902 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13903 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13904 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13905 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13906 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13907 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13908
13909 /* "neighbor unsuppress-map" commands. */
13910 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13911 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13912 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13913 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13914 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13915 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13916 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13917 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13918 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13919 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13920 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13921 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13922 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13923 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13924 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13925 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13926 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13927 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13928
13929 /* "neighbor maximum-prefix" commands. */
13930 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13931 install_element(BGP_NODE,
13932 &neighbor_maximum_prefix_threshold_hidden_cmd);
13933 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13934 install_element(BGP_NODE,
13935 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13936 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13937 install_element(BGP_NODE,
13938 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13939 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13940 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13941 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13942 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13943 install_element(BGP_IPV4_NODE,
13944 &neighbor_maximum_prefix_threshold_warning_cmd);
13945 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13946 install_element(BGP_IPV4_NODE,
13947 &neighbor_maximum_prefix_threshold_restart_cmd);
13948 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13949 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13950 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13951 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13952 install_element(BGP_IPV4M_NODE,
13953 &neighbor_maximum_prefix_threshold_warning_cmd);
13954 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13955 install_element(BGP_IPV4M_NODE,
13956 &neighbor_maximum_prefix_threshold_restart_cmd);
13957 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13958 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13959 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13960 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13961 install_element(BGP_IPV4L_NODE,
13962 &neighbor_maximum_prefix_threshold_warning_cmd);
13963 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13964 install_element(BGP_IPV4L_NODE,
13965 &neighbor_maximum_prefix_threshold_restart_cmd);
13966 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13967 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13968 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13969 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13970 install_element(BGP_IPV6_NODE,
13971 &neighbor_maximum_prefix_threshold_warning_cmd);
13972 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13973 install_element(BGP_IPV6_NODE,
13974 &neighbor_maximum_prefix_threshold_restart_cmd);
13975 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13976 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13977 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13978 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13979 install_element(BGP_IPV6M_NODE,
13980 &neighbor_maximum_prefix_threshold_warning_cmd);
13981 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13982 install_element(BGP_IPV6M_NODE,
13983 &neighbor_maximum_prefix_threshold_restart_cmd);
13984 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13985 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13986 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13987 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13988 install_element(BGP_IPV6L_NODE,
13989 &neighbor_maximum_prefix_threshold_warning_cmd);
13990 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13991 install_element(BGP_IPV6L_NODE,
13992 &neighbor_maximum_prefix_threshold_restart_cmd);
13993 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13994 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13995 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13996 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13997 install_element(BGP_VPNV4_NODE,
13998 &neighbor_maximum_prefix_threshold_warning_cmd);
13999 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
14000 install_element(BGP_VPNV4_NODE,
14001 &neighbor_maximum_prefix_threshold_restart_cmd);
14002 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
14003 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
14004 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
14005 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
14006 install_element(BGP_VPNV6_NODE,
14007 &neighbor_maximum_prefix_threshold_warning_cmd);
14008 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
14009 install_element(BGP_VPNV6_NODE,
14010 &neighbor_maximum_prefix_threshold_restart_cmd);
14011 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
14012
14013 /* "neighbor allowas-in" */
14014 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
14015 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
14016 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
14017 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
14018 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
14019 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
14020 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
14021 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
14022 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
14023 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
14024 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
14025 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
14026 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
14027 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
14028 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
14029 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
14030 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
14031 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
14032 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
14033 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
14034
14035 /* address-family commands. */
14036 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
14037 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 14038#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 14039 install_element(BGP_NODE, &address_family_vpnv4_cmd);
14040 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 14041#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 14042
d62a17ae 14043 install_element(BGP_NODE, &address_family_evpn_cmd);
14044
14045 /* "exit-address-family" command. */
14046 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
14047 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
14048 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
14049 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
14050 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
14051 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
14052 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
14053 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 14054 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
14055 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 14056 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
14057
14058 /* "clear ip bgp commands" */
14059 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
14060
14061 /* clear ip bgp prefix */
14062 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
14063 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
14064 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
14065
14066 /* "show [ip] bgp summary" commands. */
14067 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 14068 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 14069 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 14070 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 14071 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
14072 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 14073 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
14074
14075 /* "show [ip] bgp neighbors" commands. */
14076 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
14077
14078 /* "show [ip] bgp peer-group" commands. */
14079 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
14080
14081 /* "show [ip] bgp paths" commands. */
14082 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
14083
14084 /* "show [ip] bgp community" commands. */
14085 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
14086
14087 /* "show ip bgp large-community" commands. */
14088 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
14089 /* "show [ip] bgp attribute-info" commands. */
14090 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 14091 /* "show [ip] bgp route-leak" command */
14092 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 14093
14094 /* "redistribute" commands. */
14095 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
14096 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
14097 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
14098 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
14099 install_element(BGP_NODE,
14100 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
14101 install_element(BGP_NODE,
14102 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
14103 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
14104 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
14105 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
14106 install_element(BGP_NODE,
14107 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
14108 install_element(BGP_NODE,
14109 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
14110 install_element(BGP_NODE,
14111 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
14112 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
14113 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
14114 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
14115 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
14116 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
14117 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
14118 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
14119 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
14120 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
14121 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
14122 install_element(BGP_IPV4_NODE,
14123 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
14124 install_element(BGP_IPV4_NODE,
14125 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
14126 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
14127 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
14128 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
14129 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
14130 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
14131 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
14132
b9c7bc5a
PZ
14133 /* import|export vpn [route-map WORD] */
14134 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14135 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 14136
12a844a5
DS
14137 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14138 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14139
d62a17ae 14140 /* ttl_security commands */
14141 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14142 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14143
14144 /* "show [ip] bgp memory" commands. */
14145 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14146
acf71666
MK
14147 /* "show bgp martian next-hop" */
14148 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14149
48ecf8f5
DS
14150 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14151
d62a17ae 14152 /* "show [ip] bgp views" commands. */
14153 install_element(VIEW_NODE, &show_bgp_views_cmd);
14154
14155 /* "show [ip] bgp vrfs" commands. */
14156 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14157
14158 /* Community-list. */
14159 community_list_vty();
ddb5b488
PZ
14160
14161 /* vpn-policy commands */
b9c7bc5a
PZ
14162 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14163 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14164 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14165 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14166 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14167 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14168 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14169 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14170 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14171 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
14172 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14173 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 14174
301ad80a
PG
14175 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14176 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14177
b9c7bc5a
PZ
14178 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14179 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14180 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14181 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14182 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14183 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14184 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14185 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14186 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14187 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
14188 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14189 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 14190}
6b0655a2 14191
718e3744 14192#include "memory.h"
14193#include "bgp_regex.h"
14194#include "bgp_clist.h"
14195#include "bgp_ecommunity.h"
14196
14197/* VTY functions. */
14198
14199/* Direction value to string conversion. */
d62a17ae 14200static const char *community_direct_str(int direct)
14201{
14202 switch (direct) {
14203 case COMMUNITY_DENY:
14204 return "deny";
14205 case COMMUNITY_PERMIT:
14206 return "permit";
14207 default:
14208 return "unknown";
14209 }
718e3744 14210}
14211
14212/* Display error string. */
d62a17ae 14213static void community_list_perror(struct vty *vty, int ret)
14214{
14215 switch (ret) {
14216 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14217 vty_out(vty, "%% Can't find community-list\n");
14218 break;
14219 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14220 vty_out(vty, "%% Malformed community-list value\n");
14221 break;
14222 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14223 vty_out(vty,
14224 "%% Community name conflict, previously defined as standard community\n");
14225 break;
14226 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14227 vty_out(vty,
14228 "%% Community name conflict, previously defined as expanded community\n");
14229 break;
14230 }
718e3744 14231}
14232
5bf15956
DW
14233/* "community-list" keyword help string. */
14234#define COMMUNITY_LIST_STR "Add a community list entry\n"
14235
7336e101
SP
14236/*community-list standard */
14237DEFUN (community_list_standard,
14238 bgp_community_list_standard_cmd,
14239 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14240 BGP_STR
718e3744 14241 COMMUNITY_LIST_STR
14242 "Community list number (standard)\n"
5bf15956 14243 "Add an standard community-list entry\n"
718e3744 14244 "Community list name\n"
14245 "Specify community to reject\n"
14246 "Specify community to accept\n"
14247 COMMUNITY_VAL_STR)
14248{
d62a17ae 14249 char *cl_name_or_number = NULL;
14250 int direct = 0;
14251 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 14252 int idx = 0;
7336e101 14253
d62a17ae 14254 argv_find(argv, argc, "(1-99)", &idx);
14255 argv_find(argv, argc, "WORD", &idx);
14256 cl_name_or_number = argv[idx]->arg;
14257 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14258 : COMMUNITY_DENY;
14259 argv_find(argv, argc, "AA:NN", &idx);
14260 char *str = argv_concat(argv, argc, idx);
42f914d4 14261
d62a17ae 14262 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14263 style);
42f914d4 14264
d62a17ae 14265 XFREE(MTYPE_TMP, str);
42f914d4 14266
d62a17ae 14267 if (ret < 0) {
14268 /* Display error string. */
14269 community_list_perror(vty, ret);
14270 return CMD_WARNING_CONFIG_FAILED;
14271 }
42f914d4 14272
d62a17ae 14273 return CMD_SUCCESS;
718e3744 14274}
14275
7336e101
SP
14276DEFUN (no_community_list_standard_all,
14277 no_bgp_community_list_standard_all_cmd,
14278 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14279 NO_STR
14280 BGP_STR
14281 COMMUNITY_LIST_STR
14282 "Community list number (standard)\n"
14283 "Add an standard community-list entry\n"
14284 "Community list name\n"
14285 "Specify community to reject\n"
14286 "Specify community to accept\n"
14287 COMMUNITY_VAL_STR)
718e3744 14288{
d62a17ae 14289 char *cl_name_or_number = NULL;
174b5cb9 14290 char *str = NULL;
d62a17ae 14291 int direct = 0;
14292 int style = COMMUNITY_LIST_STANDARD;
42f914d4 14293
d62a17ae 14294 int idx = 0;
7336e101 14295
174b5cb9
DA
14296 argv_find(argv, argc, "permit", &idx);
14297 argv_find(argv, argc, "deny", &idx);
14298
14299 if (idx) {
14300 direct = argv_find(argv, argc, "permit", &idx)
14301 ? COMMUNITY_PERMIT
14302 : COMMUNITY_DENY;
14303
14304 idx = 0;
14305 argv_find(argv, argc, "AA:NN", &idx);
14306 str = argv_concat(argv, argc, idx);
14307 }
14308
14309 idx = 0;
d62a17ae 14310 argv_find(argv, argc, "(1-99)", &idx);
14311 argv_find(argv, argc, "WORD", &idx);
14312 cl_name_or_number = argv[idx]->arg;
42f914d4 14313
d62a17ae 14314 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14315 direct, style);
42f914d4 14316
d62a17ae 14317 XFREE(MTYPE_TMP, str);
daf9ddbb 14318
d62a17ae 14319 if (ret < 0) {
14320 community_list_perror(vty, ret);
14321 return CMD_WARNING_CONFIG_FAILED;
14322 }
42f914d4 14323
d62a17ae 14324 return CMD_SUCCESS;
718e3744 14325}
7336e101 14326
174b5cb9
DA
14327ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14328 "no bgp community-list <(1-99)|standard WORD>",
14329 NO_STR BGP_STR COMMUNITY_LIST_STR
14330 "Community list number (standard)\n"
14331 "Add an standard community-list entry\n"
14332 "Community list name\n")
14333
7336e101
SP
14334/*community-list expanded */
14335DEFUN (community_list_expanded_all,
14336 bgp_community_list_expanded_all_cmd,
14337 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14338 BGP_STR
14339 COMMUNITY_LIST_STR
718e3744 14340 "Community list number (expanded)\n"
5bf15956 14341 "Add an expanded community-list entry\n"
718e3744 14342 "Community list name\n"
14343 "Specify community to reject\n"
14344 "Specify community to accept\n"
14345 COMMUNITY_VAL_STR)
14346{
d62a17ae 14347 char *cl_name_or_number = NULL;
14348 int direct = 0;
14349 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14350
d62a17ae 14351 int idx = 0;
7b9a4750 14352
d62a17ae 14353 argv_find(argv, argc, "(100-500)", &idx);
14354 argv_find(argv, argc, "WORD", &idx);
14355 cl_name_or_number = argv[idx]->arg;
14356 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14357 : COMMUNITY_DENY;
14358 argv_find(argv, argc, "AA:NN", &idx);
14359 char *str = argv_concat(argv, argc, idx);
42f914d4 14360
d62a17ae 14361 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14362 style);
42f914d4 14363
d62a17ae 14364 XFREE(MTYPE_TMP, str);
42f914d4 14365
d62a17ae 14366 if (ret < 0) {
14367 /* Display error string. */
14368 community_list_perror(vty, ret);
14369 return CMD_WARNING_CONFIG_FAILED;
14370 }
42f914d4 14371
d62a17ae 14372 return CMD_SUCCESS;
718e3744 14373}
14374
7336e101
SP
14375DEFUN (no_community_list_expanded_all,
14376 no_bgp_community_list_expanded_all_cmd,
14377 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14378 NO_STR
14379 BGP_STR
14380 COMMUNITY_LIST_STR
14381 "Community list number (expanded)\n"
14382 "Add an expanded community-list entry\n"
14383 "Community list name\n"
14384 "Specify community to reject\n"
14385 "Specify community to accept\n"
14386 COMMUNITY_VAL_STR)
718e3744 14387{
d62a17ae 14388 char *cl_name_or_number = NULL;
174b5cb9 14389 char *str = NULL;
d62a17ae 14390 int direct = 0;
14391 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14392
d62a17ae 14393 int idx = 0;
174b5cb9
DA
14394
14395 argv_find(argv, argc, "permit", &idx);
14396 argv_find(argv, argc, "deny", &idx);
14397
14398 if (idx) {
14399 direct = argv_find(argv, argc, "permit", &idx)
14400 ? COMMUNITY_PERMIT
14401 : COMMUNITY_DENY;
14402
14403 idx = 0;
14404 argv_find(argv, argc, "AA:NN", &idx);
14405 str = argv_concat(argv, argc, idx);
7336e101 14406 }
174b5cb9
DA
14407
14408 idx = 0;
d62a17ae 14409 argv_find(argv, argc, "(100-500)", &idx);
14410 argv_find(argv, argc, "WORD", &idx);
14411 cl_name_or_number = argv[idx]->arg;
42f914d4 14412
d62a17ae 14413 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14414 direct, style);
42f914d4 14415
d62a17ae 14416 XFREE(MTYPE_TMP, str);
daf9ddbb 14417
d62a17ae 14418 if (ret < 0) {
14419 community_list_perror(vty, ret);
14420 return CMD_WARNING_CONFIG_FAILED;
14421 }
42f914d4 14422
d62a17ae 14423 return CMD_SUCCESS;
718e3744 14424}
14425
174b5cb9
DA
14426ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14427 "no bgp community-list <(100-500)|expanded WORD>",
14428 NO_STR IP_STR COMMUNITY_LIST_STR
14429 "Community list number (expanded)\n"
14430 "Add an expanded community-list entry\n"
14431 "Community list name\n")
14432
8d9b8ed9
PM
14433/* Return configuration string of community-list entry. */
14434static const char *community_list_config_str(struct community_entry *entry)
14435{
14436 const char *str;
14437
14438 if (entry->any)
14439 str = "";
14440 else {
14441 if (entry->style == COMMUNITY_LIST_STANDARD)
14442 str = community_str(entry->u.com, false);
14443 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14444 str = lcommunity_str(entry->u.lcom, false);
14445 else
14446 str = entry->config;
14447 }
14448 return str;
14449}
14450
d62a17ae 14451static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 14452{
d62a17ae 14453 struct community_entry *entry;
718e3744 14454
d62a17ae 14455 for (entry = list->head; entry; entry = entry->next) {
14456 if (entry == list->head) {
14457 if (all_digit(list->name))
14458 vty_out(vty, "Community %s list %s\n",
14459 entry->style == COMMUNITY_LIST_STANDARD
14460 ? "standard"
14461 : "(expanded) access",
14462 list->name);
14463 else
14464 vty_out(vty, "Named Community %s list %s\n",
14465 entry->style == COMMUNITY_LIST_STANDARD
14466 ? "standard"
14467 : "expanded",
14468 list->name);
14469 }
14470 if (entry->any)
14471 vty_out(vty, " %s\n",
14472 community_direct_str(entry->direct));
14473 else
14474 vty_out(vty, " %s %s\n",
14475 community_direct_str(entry->direct),
8d9b8ed9 14476 community_list_config_str(entry));
d62a17ae 14477 }
718e3744 14478}
14479
7336e101
SP
14480DEFUN (show_community_list,
14481 show_bgp_community_list_cmd,
14482 "show bgp community-list",
718e3744 14483 SHOW_STR
7336e101 14484 BGP_STR
718e3744 14485 "List community-list\n")
14486{
d62a17ae 14487 struct community_list *list;
14488 struct community_list_master *cm;
718e3744 14489
d62a17ae 14490 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14491 if (!cm)
14492 return CMD_SUCCESS;
718e3744 14493
d62a17ae 14494 for (list = cm->num.head; list; list = list->next)
14495 community_list_show(vty, list);
718e3744 14496
d62a17ae 14497 for (list = cm->str.head; list; list = list->next)
14498 community_list_show(vty, list);
718e3744 14499
d62a17ae 14500 return CMD_SUCCESS;
718e3744 14501}
14502
7336e101
SP
14503DEFUN (show_community_list_arg,
14504 show_bgp_community_list_arg_cmd,
960b69b9 14505 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
14506 SHOW_STR
14507 BGP_STR
718e3744 14508 "List community-list\n"
14509 "Community-list number\n"
960b69b9 14510 "Community-list name\n"
14511 "Detailed information on community-list\n")
718e3744 14512{
d62a17ae 14513 int idx_comm_list = 3;
14514 struct community_list *list;
718e3744 14515
e237b0d2 14516 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 14517 COMMUNITY_LIST_MASTER);
14518 if (!list) {
14519 vty_out(vty, "%% Can't find community-list\n");
14520 return CMD_WARNING;
14521 }
718e3744 14522
d62a17ae 14523 community_list_show(vty, list);
718e3744 14524
d62a17ae 14525 return CMD_SUCCESS;
718e3744 14526}
6b0655a2 14527
57d187bc
JS
14528/*
14529 * Large Community code.
14530 */
d62a17ae 14531static int lcommunity_list_set_vty(struct vty *vty, int argc,
14532 struct cmd_token **argv, int style,
14533 int reject_all_digit_name)
14534{
14535 int ret;
14536 int direct;
14537 char *str;
14538 int idx = 0;
14539 char *cl_name;
14540
14541 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14542 : COMMUNITY_DENY;
14543
14544 /* All digit name check. */
14545 idx = 0;
14546 argv_find(argv, argc, "WORD", &idx);
14547 argv_find(argv, argc, "(1-99)", &idx);
14548 argv_find(argv, argc, "(100-500)", &idx);
14549 cl_name = argv[idx]->arg;
14550 if (reject_all_digit_name && all_digit(cl_name)) {
14551 vty_out(vty, "%% Community name cannot have all digits\n");
14552 return CMD_WARNING_CONFIG_FAILED;
14553 }
14554
14555 idx = 0;
14556 argv_find(argv, argc, "AA:BB:CC", &idx);
14557 argv_find(argv, argc, "LINE", &idx);
14558 /* Concat community string argument. */
14559 if (idx)
14560 str = argv_concat(argv, argc, idx);
14561 else
14562 str = NULL;
14563
14564 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14565
14566 /* Free temporary community list string allocated by
14567 argv_concat(). */
0a22ddfb 14568 XFREE(MTYPE_TMP, str);
d62a17ae 14569
14570 if (ret < 0) {
14571 community_list_perror(vty, ret);
14572 return CMD_WARNING_CONFIG_FAILED;
14573 }
14574 return CMD_SUCCESS;
14575}
14576
14577static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14578 struct cmd_token **argv, int style)
14579{
14580 int ret;
14581 int direct = 0;
14582 char *str = NULL;
14583 int idx = 0;
14584
14585 argv_find(argv, argc, "permit", &idx);
14586 argv_find(argv, argc, "deny", &idx);
14587
14588 if (idx) {
14589 /* Check the list direct. */
14590 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14591 direct = COMMUNITY_PERMIT;
14592 else
14593 direct = COMMUNITY_DENY;
14594
14595 idx = 0;
14596 argv_find(argv, argc, "LINE", &idx);
14597 argv_find(argv, argc, "AA:AA:NN", &idx);
14598 /* Concat community string argument. */
14599 str = argv_concat(argv, argc, idx);
14600 }
14601
14602 idx = 0;
14603 argv_find(argv, argc, "(1-99)", &idx);
14604 argv_find(argv, argc, "(100-500)", &idx);
14605 argv_find(argv, argc, "WORD", &idx);
14606
14607 /* Unset community list. */
14608 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14609 style);
14610
14611 /* Free temporary community list string allocated by
14612 argv_concat(). */
0a22ddfb 14613 XFREE(MTYPE_TMP, str);
d62a17ae 14614
14615 if (ret < 0) {
14616 community_list_perror(vty, ret);
14617 return CMD_WARNING_CONFIG_FAILED;
14618 }
14619
14620 return CMD_SUCCESS;
57d187bc
JS
14621}
14622
14623/* "large-community-list" keyword help string. */
14624#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14625#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14626
7336e101
SP
14627DEFUN (lcommunity_list_standard,
14628 bgp_lcommunity_list_standard_cmd,
7336e101
SP
14629 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14630 BGP_STR
14631 LCOMMUNITY_LIST_STR
14632 "Large Community list number (standard)\n"
14633 "Specify large community to reject\n"
14634 "Specify large community to accept\n"
14635 LCOMMUNITY_VAL_STR)
52951b63 14636{
d62a17ae 14637 return lcommunity_list_set_vty(vty, argc, argv,
14638 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
14639}
14640
7336e101
SP
14641DEFUN (lcommunity_list_expanded,
14642 bgp_lcommunity_list_expanded_cmd,
14643 "bgp large-community-list (100-500) <deny|permit> LINE...",
14644 BGP_STR
14645 LCOMMUNITY_LIST_STR
14646 "Large Community list number (expanded)\n"
14647 "Specify large community to reject\n"
14648 "Specify large community to accept\n"
14649 "An ordered list as a regular-expression\n")
57d187bc 14650{
d62a17ae 14651 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14652 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
14653}
14654
7336e101
SP
14655DEFUN (lcommunity_list_name_standard,
14656 bgp_lcommunity_list_name_standard_cmd,
7336e101
SP
14657 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14658 BGP_STR
14659 LCOMMUNITY_LIST_STR
14660 "Specify standard large-community-list\n"
14661 "Large Community list name\n"
14662 "Specify large community to reject\n"
14663 "Specify large community to accept\n"
14664 LCOMMUNITY_VAL_STR)
52951b63 14665{
d62a17ae 14666 return lcommunity_list_set_vty(vty, argc, argv,
14667 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
14668}
14669
7336e101
SP
14670DEFUN (lcommunity_list_name_expanded,
14671 bgp_lcommunity_list_name_expanded_cmd,
14672 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14673 BGP_STR
14674 LCOMMUNITY_LIST_STR
14675 "Specify expanded large-community-list\n"
14676 "Large Community list name\n"
14677 "Specify large community to reject\n"
14678 "Specify large community to accept\n"
14679 "An ordered list as a regular-expression\n")
57d187bc 14680{
d62a17ae 14681 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14682 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
14683}
14684
7336e101
SP
14685DEFUN (no_lcommunity_list_standard_all,
14686 no_bgp_lcommunity_list_standard_all_cmd,
14687 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14688 NO_STR
14689 BGP_STR
14690 LCOMMUNITY_LIST_STR
14691 "Large Community list number (standard)\n"
14692 "Large Community list number (expanded)\n"
14693 "Large Community list name\n")
57d187bc 14694{
7336e101
SP
14695 return lcommunity_list_unset_vty(vty, argc, argv,
14696 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14697}
14698
7336e101
SP
14699DEFUN (no_lcommunity_list_name_expanded_all,
14700 no_bgp_lcommunity_list_name_expanded_all_cmd,
14701 "no bgp large-community-list expanded WORD",
14702 NO_STR
14703 BGP_STR
14704 LCOMMUNITY_LIST_STR
14705 "Specify expanded large-community-list\n"
14706 "Large Community list name\n")
57d187bc 14707{
d62a17ae 14708 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14709 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14710}
14711
7336e101
SP
14712DEFUN (no_lcommunity_list_standard,
14713 no_bgp_lcommunity_list_standard_cmd,
14714 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14715 NO_STR
14716 BGP_STR
14717 LCOMMUNITY_LIST_STR
14718 "Large Community list number (standard)\n"
14719 "Specify large community to reject\n"
14720 "Specify large community to accept\n"
14721 LCOMMUNITY_VAL_STR)
57d187bc 14722{
d62a17ae 14723 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14724 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14725}
14726
7336e101
SP
14727DEFUN (no_lcommunity_list_expanded,
14728 no_bgp_lcommunity_list_expanded_cmd,
14729 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14730 NO_STR
14731 BGP_STR
14732 LCOMMUNITY_LIST_STR
14733 "Large Community list number (expanded)\n"
14734 "Specify large community to reject\n"
14735 "Specify large community to accept\n"
14736 "An ordered list as a regular-expression\n")
57d187bc 14737{
d62a17ae 14738 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14739 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14740}
14741
7336e101
SP
14742DEFUN (no_lcommunity_list_name_standard,
14743 no_bgp_lcommunity_list_name_standard_cmd,
14744 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14745 NO_STR
14746 BGP_STR
14747 LCOMMUNITY_LIST_STR
14748 "Specify standard large-community-list\n"
14749 "Large Community list name\n"
14750 "Specify large community to reject\n"
14751 "Specify large community to accept\n"
14752 LCOMMUNITY_VAL_STR)
57d187bc 14753{
d62a17ae 14754 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14755 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14756}
14757
7336e101
SP
14758DEFUN (no_lcommunity_list_name_expanded,
14759 no_bgp_lcommunity_list_name_expanded_cmd,
14760 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14761 NO_STR
14762 BGP_STR
14763 LCOMMUNITY_LIST_STR
14764 "Specify expanded 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 "An ordered list as a regular-expression\n")
57d187bc 14769{
d62a17ae 14770 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14771 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14772}
14773
d62a17ae 14774static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14775{
14776 struct community_entry *entry;
14777
14778 for (entry = list->head; entry; entry = entry->next) {
14779 if (entry == list->head) {
14780 if (all_digit(list->name))
14781 vty_out(vty, "Large community %s list %s\n",
169b72c8 14782 entry->style ==
14783 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 14784 ? "standard"
14785 : "(expanded) access",
14786 list->name);
14787 else
14788 vty_out(vty,
14789 "Named large community %s list %s\n",
169b72c8 14790 entry->style ==
14791 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 14792 ? "standard"
14793 : "expanded",
14794 list->name);
14795 }
14796 if (entry->any)
14797 vty_out(vty, " %s\n",
14798 community_direct_str(entry->direct));
14799 else
14800 vty_out(vty, " %s %s\n",
14801 community_direct_str(entry->direct),
8d9b8ed9 14802 community_list_config_str(entry));
d62a17ae 14803 }
57d187bc
JS
14804}
14805
7336e101
SP
14806DEFUN (show_lcommunity_list,
14807 show_bgp_lcommunity_list_cmd,
14808 "show bgp large-community-list",
57d187bc 14809 SHOW_STR
7336e101 14810 BGP_STR
57d187bc
JS
14811 "List large-community list\n")
14812{
d62a17ae 14813 struct community_list *list;
14814 struct community_list_master *cm;
57d187bc 14815
d62a17ae 14816 cm = community_list_master_lookup(bgp_clist,
14817 LARGE_COMMUNITY_LIST_MASTER);
14818 if (!cm)
14819 return CMD_SUCCESS;
57d187bc 14820
d62a17ae 14821 for (list = cm->num.head; list; list = list->next)
14822 lcommunity_list_show(vty, list);
57d187bc 14823
d62a17ae 14824 for (list = cm->str.head; list; list = list->next)
14825 lcommunity_list_show(vty, list);
57d187bc 14826
d62a17ae 14827 return CMD_SUCCESS;
57d187bc
JS
14828}
14829
7336e101
SP
14830DEFUN (show_lcommunity_list_arg,
14831 show_bgp_lcommunity_list_arg_cmd,
960b69b9 14832 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
14833 SHOW_STR
14834 BGP_STR
57d187bc 14835 "List large-community list\n"
960b69b9 14836 "Large-community-list number\n"
14837 "Large-community-list name\n"
14838 "Detailed information on large-community-list\n")
57d187bc 14839{
d62a17ae 14840 struct community_list *list;
57d187bc 14841
e237b0d2 14842 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 14843 LARGE_COMMUNITY_LIST_MASTER);
14844 if (!list) {
960b69b9 14845 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 14846 return CMD_WARNING;
14847 }
57d187bc 14848
d62a17ae 14849 lcommunity_list_show(vty, list);
57d187bc 14850
d62a17ae 14851 return CMD_SUCCESS;
57d187bc
JS
14852}
14853
718e3744 14854/* "extcommunity-list" keyword help string. */
14855#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14856#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14857
7336e101
SP
14858DEFUN (extcommunity_list_standard,
14859 bgp_extcommunity_list_standard_cmd,
14860 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14861 BGP_STR
718e3744 14862 EXTCOMMUNITY_LIST_STR
14863 "Extended Community list number (standard)\n"
718e3744 14864 "Specify standard extcommunity-list\n"
5bf15956 14865 "Community list name\n"
718e3744 14866 "Specify community to reject\n"
14867 "Specify community to accept\n"
14868 EXTCOMMUNITY_VAL_STR)
14869{
d62a17ae 14870 int style = EXTCOMMUNITY_LIST_STANDARD;
14871 int direct = 0;
14872 char *cl_number_or_name = NULL;
42f914d4 14873
d62a17ae 14874 int idx = 0;
7b9a4750 14875
d62a17ae 14876 argv_find(argv, argc, "(1-99)", &idx);
14877 argv_find(argv, argc, "WORD", &idx);
14878 cl_number_or_name = argv[idx]->arg;
14879 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14880 : COMMUNITY_DENY;
14881 argv_find(argv, argc, "AA:NN", &idx);
14882 char *str = argv_concat(argv, argc, idx);
42f914d4 14883
d62a17ae 14884 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14885 direct, style);
42f914d4 14886
d62a17ae 14887 XFREE(MTYPE_TMP, str);
42f914d4 14888
d62a17ae 14889 if (ret < 0) {
14890 community_list_perror(vty, ret);
14891 return CMD_WARNING_CONFIG_FAILED;
14892 }
42f914d4 14893
d62a17ae 14894 return CMD_SUCCESS;
718e3744 14895}
14896
7336e101
SP
14897DEFUN (extcommunity_list_name_expanded,
14898 bgp_extcommunity_list_name_expanded_cmd,
14899 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14900 BGP_STR
14901 EXTCOMMUNITY_LIST_STR
5bf15956 14902 "Extended Community list number (expanded)\n"
718e3744 14903 "Specify expanded extcommunity-list\n"
14904 "Extended Community list name\n"
14905 "Specify community to reject\n"
14906 "Specify community to accept\n"
14907 "An ordered list as a regular-expression\n")
14908{
d62a17ae 14909 int style = EXTCOMMUNITY_LIST_EXPANDED;
14910 int direct = 0;
14911 char *cl_number_or_name = NULL;
d62a17ae 14912 int idx = 0;
7336e101 14913
d62a17ae 14914 argv_find(argv, argc, "(100-500)", &idx);
14915 argv_find(argv, argc, "WORD", &idx);
14916 cl_number_or_name = argv[idx]->arg;
14917 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14918 : COMMUNITY_DENY;
14919 argv_find(argv, argc, "LINE", &idx);
14920 char *str = argv_concat(argv, argc, idx);
42f914d4 14921
d62a17ae 14922 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14923 direct, style);
42f914d4 14924
d62a17ae 14925 XFREE(MTYPE_TMP, str);
42f914d4 14926
d62a17ae 14927 if (ret < 0) {
14928 community_list_perror(vty, ret);
14929 return CMD_WARNING_CONFIG_FAILED;
14930 }
42f914d4 14931
d62a17ae 14932 return CMD_SUCCESS;
718e3744 14933}
14934
7336e101
SP
14935DEFUN (no_extcommunity_list_standard_all,
14936 no_bgp_extcommunity_list_standard_all_cmd,
14937 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14938 NO_STR
14939 BGP_STR
14940 EXTCOMMUNITY_LIST_STR
813d4307 14941 "Extended Community list number (standard)\n"
718e3744 14942 "Specify standard extcommunity-list\n"
5bf15956 14943 "Community list name\n"
718e3744 14944 "Specify community to reject\n"
14945 "Specify community to accept\n"
14946 EXTCOMMUNITY_VAL_STR)
14947{
d62a17ae 14948 int style = EXTCOMMUNITY_LIST_STANDARD;
14949 int direct = 0;
14950 char *cl_number_or_name = NULL;
d4455c89 14951 char *str = NULL;
d62a17ae 14952 int idx = 0;
d4455c89 14953
d4455c89
DA
14954 argv_find(argv, argc, "permit", &idx);
14955 argv_find(argv, argc, "deny", &idx);
14956
14957 if (idx) {
14958 direct = argv_find(argv, argc, "permit", &idx)
14959 ? COMMUNITY_PERMIT
14960 : COMMUNITY_DENY;
14961
14962 idx = 0;
14963 argv_find(argv, argc, "AA:NN", &idx);
14964 str = argv_concat(argv, argc, idx);
14965 }
14966
14967 idx = 0;
d62a17ae 14968 argv_find(argv, argc, "(1-99)", &idx);
14969 argv_find(argv, argc, "WORD", &idx);
14970 cl_number_or_name = argv[idx]->arg;
42f914d4 14971
d62a17ae 14972 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14973 direct, style);
42f914d4 14974
d62a17ae 14975 XFREE(MTYPE_TMP, str);
42f914d4 14976
d62a17ae 14977 if (ret < 0) {
14978 community_list_perror(vty, ret);
14979 return CMD_WARNING_CONFIG_FAILED;
14980 }
42f914d4 14981
d62a17ae 14982 return CMD_SUCCESS;
718e3744 14983}
14984
d4455c89
DA
14985ALIAS(no_extcommunity_list_standard_all,
14986 no_bgp_extcommunity_list_standard_all_list_cmd,
14987 "no bgp extcommunity-list <(1-99)|standard WORD>",
14988 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
14989 "Extended Community list number (standard)\n"
14990 "Specify standard extcommunity-list\n"
14991 "Community list name\n")
14992
7336e101
SP
14993DEFUN (no_extcommunity_list_expanded_all,
14994 no_bgp_extcommunity_list_expanded_all_cmd,
14995 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14996 NO_STR
14997 BGP_STR
14998 EXTCOMMUNITY_LIST_STR
718e3744 14999 "Extended Community list number (expanded)\n"
718e3744 15000 "Specify expanded extcommunity-list\n"
5bf15956 15001 "Extended Community list name\n"
718e3744 15002 "Specify community to reject\n"
15003 "Specify community to accept\n"
15004 "An ordered list as a regular-expression\n")
15005{
d62a17ae 15006 int style = EXTCOMMUNITY_LIST_EXPANDED;
15007 int direct = 0;
15008 char *cl_number_or_name = NULL;
d4455c89 15009 char *str = NULL;
d62a17ae 15010 int idx = 0;
d4455c89 15011
d4455c89
DA
15012 argv_find(argv, argc, "permit", &idx);
15013 argv_find(argv, argc, "deny", &idx);
15014
15015 if (idx) {
15016 direct = argv_find(argv, argc, "permit", &idx)
15017 ? COMMUNITY_PERMIT
15018 : COMMUNITY_DENY;
15019
15020 idx = 0;
15021 argv_find(argv, argc, "LINE", &idx);
15022 str = argv_concat(argv, argc, idx);
15023 }
15024
15025 idx = 0;
d62a17ae 15026 argv_find(argv, argc, "(100-500)", &idx);
15027 argv_find(argv, argc, "WORD", &idx);
15028 cl_number_or_name = argv[idx]->arg;
42f914d4 15029
d62a17ae 15030 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15031 direct, style);
42f914d4 15032
d62a17ae 15033 XFREE(MTYPE_TMP, str);
42f914d4 15034
d62a17ae 15035 if (ret < 0) {
15036 community_list_perror(vty, ret);
15037 return CMD_WARNING_CONFIG_FAILED;
15038 }
42f914d4 15039
d62a17ae 15040 return CMD_SUCCESS;
718e3744 15041}
15042
d4455c89
DA
15043ALIAS(no_extcommunity_list_expanded_all,
15044 no_bgp_extcommunity_list_expanded_all_list_cmd,
15045 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15046 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15047 "Extended Community list number (expanded)\n"
15048 "Specify expanded extcommunity-list\n"
15049 "Extended Community list name\n")
15050
d62a17ae 15051static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 15052{
d62a17ae 15053 struct community_entry *entry;
718e3744 15054
d62a17ae 15055 for (entry = list->head; entry; entry = entry->next) {
15056 if (entry == list->head) {
15057 if (all_digit(list->name))
15058 vty_out(vty, "Extended community %s list %s\n",
15059 entry->style == EXTCOMMUNITY_LIST_STANDARD
15060 ? "standard"
15061 : "(expanded) access",
15062 list->name);
15063 else
15064 vty_out(vty,
15065 "Named extended community %s list %s\n",
15066 entry->style == EXTCOMMUNITY_LIST_STANDARD
15067 ? "standard"
15068 : "expanded",
15069 list->name);
15070 }
15071 if (entry->any)
15072 vty_out(vty, " %s\n",
15073 community_direct_str(entry->direct));
15074 else
15075 vty_out(vty, " %s %s\n",
15076 community_direct_str(entry->direct),
8d9b8ed9 15077 community_list_config_str(entry));
d62a17ae 15078 }
718e3744 15079}
15080
7336e101
SP
15081DEFUN (show_extcommunity_list,
15082 show_bgp_extcommunity_list_cmd,
15083 "show bgp extcommunity-list",
718e3744 15084 SHOW_STR
7336e101 15085 BGP_STR
718e3744 15086 "List extended-community list\n")
15087{
d62a17ae 15088 struct community_list *list;
15089 struct community_list_master *cm;
718e3744 15090
d62a17ae 15091 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15092 if (!cm)
15093 return CMD_SUCCESS;
718e3744 15094
d62a17ae 15095 for (list = cm->num.head; list; list = list->next)
15096 extcommunity_list_show(vty, list);
718e3744 15097
d62a17ae 15098 for (list = cm->str.head; list; list = list->next)
15099 extcommunity_list_show(vty, list);
718e3744 15100
d62a17ae 15101 return CMD_SUCCESS;
718e3744 15102}
15103
7336e101
SP
15104DEFUN (show_extcommunity_list_arg,
15105 show_bgp_extcommunity_list_arg_cmd,
960b69b9 15106 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
15107 SHOW_STR
15108 BGP_STR
718e3744 15109 "List extended-community list\n"
15110 "Extcommunity-list number\n"
960b69b9 15111 "Extcommunity-list name\n"
15112 "Detailed information on extcommunity-list\n")
718e3744 15113{
d62a17ae 15114 int idx_comm_list = 3;
15115 struct community_list *list;
718e3744 15116
e237b0d2 15117 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 15118 EXTCOMMUNITY_LIST_MASTER);
15119 if (!list) {
15120 vty_out(vty, "%% Can't find extcommunity-list\n");
15121 return CMD_WARNING;
15122 }
718e3744 15123
d62a17ae 15124 extcommunity_list_show(vty, list);
718e3744 15125
d62a17ae 15126 return CMD_SUCCESS;
718e3744 15127}
6b0655a2 15128
718e3744 15129/* Display community-list and extcommunity-list configuration. */
d62a17ae 15130static int community_list_config_write(struct vty *vty)
15131{
15132 struct community_list *list;
15133 struct community_entry *entry;
15134 struct community_list_master *cm;
15135 int write = 0;
15136
15137 /* Community-list. */
15138 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15139
15140 for (list = cm->num.head; list; list = list->next)
15141 for (entry = list->head; entry; entry = entry->next) {
7336e101 15142 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
d62a17ae 15143 community_direct_str(entry->direct),
15144 community_list_config_str(entry));
15145 write++;
15146 }
15147 for (list = cm->str.head; list; list = list->next)
15148 for (entry = list->head; entry; entry = entry->next) {
7336e101 15149 vty_out(vty, "bgp community-list %s %s %s %s\n",
d62a17ae 15150 entry->style == COMMUNITY_LIST_STANDARD
15151 ? "standard"
15152 : "expanded",
15153 list->name, community_direct_str(entry->direct),
15154 community_list_config_str(entry));
15155 write++;
15156 }
15157
15158 /* Extcommunity-list. */
15159 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15160
15161 for (list = cm->num.head; list; list = list->next)
15162 for (entry = list->head; entry; entry = entry->next) {
7336e101 15163 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
d62a17ae 15164 list->name, community_direct_str(entry->direct),
15165 community_list_config_str(entry));
15166 write++;
15167 }
15168 for (list = cm->str.head; list; list = list->next)
15169 for (entry = list->head; entry; entry = entry->next) {
7336e101 15170 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
d62a17ae 15171 entry->style == EXTCOMMUNITY_LIST_STANDARD
15172 ? "standard"
15173 : "expanded",
15174 list->name, community_direct_str(entry->direct),
15175 community_list_config_str(entry));
15176 write++;
15177 }
15178
15179
15180 /* lcommunity-list. */
15181 cm = community_list_master_lookup(bgp_clist,
15182 LARGE_COMMUNITY_LIST_MASTER);
15183
15184 for (list = cm->num.head; list; list = list->next)
15185 for (entry = list->head; entry; entry = entry->next) {
7336e101 15186 vty_out(vty, "bgp large-community-list %s %s %s\n",
d62a17ae 15187 list->name, community_direct_str(entry->direct),
15188 community_list_config_str(entry));
15189 write++;
15190 }
15191 for (list = cm->str.head; list; list = list->next)
15192 for (entry = list->head; entry; entry = entry->next) {
7336e101 15193 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
d62a17ae 15194 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15195 ? "standard"
15196 : "expanded",
15197 list->name, community_direct_str(entry->direct),
15198 community_list_config_str(entry));
15199 write++;
15200 }
15201
15202 return write;
15203}
15204
15205static struct cmd_node community_list_node = {
15206 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 15207};
15208
d62a17ae 15209static void community_list_vty(void)
15210{
15211 install_node(&community_list_node, community_list_config_write);
15212
15213 /* Community-list. */
7336e101
SP
15214 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15215 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15216 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 15217 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 15218 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 15219 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
15220 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15221 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 15222
15223 /* Extcommunity-list. */
7336e101
SP
15224 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15225 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15226 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
15227 install_element(CONFIG_NODE,
15228 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 15229 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
15230 install_element(CONFIG_NODE,
15231 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
15232 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15233 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 15234
15235 /* Large Community List */
7336e101 15236 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
15237 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15238 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101
SP
15239 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15240 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15241 install_element(CONFIG_NODE,
15242 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15243 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15244 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15245 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15246 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15247 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15248 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 15249}