]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #2382 from opensourcerouting/remove_preprocessor_check
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
718e3744 25#include "prefix.h"
26#include "plist.h"
27#include "buffer.h"
28#include "linklist.h"
29#include "stream.h"
30#include "thread.h"
31#include "log.h"
3b8b1855 32#include "memory.h"
fc7948fa 33#include "memory_vty.h"
4bf6a362 34#include "hash.h"
3f9c7369 35#include "queue.h"
039f3a34 36#include "filter.h"
718e3744 37
38#include "bgpd/bgpd.h"
4bf6a362 39#include "bgpd/bgp_advertise.h"
718e3744 40#include "bgpd/bgp_attr.h"
41#include "bgpd/bgp_aspath.h"
42#include "bgpd/bgp_community.h"
4bf6a362 43#include "bgpd/bgp_ecommunity.h"
57d187bc 44#include "bgpd/bgp_lcommunity.h"
4bf6a362 45#include "bgpd/bgp_damp.h"
718e3744 46#include "bgpd/bgp_debug.h"
e0701b79 47#include "bgpd/bgp_fsm.h"
4bf6a362 48#include "bgpd/bgp_nexthop.h"
718e3744 49#include "bgpd/bgp_open.h"
4bf6a362 50#include "bgpd/bgp_regex.h"
718e3744 51#include "bgpd/bgp_route.h"
c016b6c7 52#include "bgpd/bgp_mplsvpn.h"
718e3744 53#include "bgpd/bgp_zebra.h"
fee0f4c6 54#include "bgpd/bgp_table.h"
94f2b392 55#include "bgpd/bgp_vty.h"
165b5fff 56#include "bgpd/bgp_mpath.h"
cb1faec9 57#include "bgpd/bgp_packet.h"
3f9c7369 58#include "bgpd/bgp_updgrp.h"
c43ed2e4 59#include "bgpd/bgp_bfd.h"
555e09d4 60#include "bgpd/bgp_io.h"
94c2f693 61#include "bgpd/bgp_evpn.h"
718e3744 62
d62a17ae 63static struct peer_group *listen_range_exists(struct bgp *bgp,
64 struct prefix *range, int exact);
65
66static enum node_type bgp_node_type(afi_t afi, safi_t safi)
67{
68 switch (afi) {
69 case AFI_IP:
70 switch (safi) {
71 case SAFI_UNICAST:
72 return BGP_IPV4_NODE;
73 break;
74 case SAFI_MULTICAST:
75 return BGP_IPV4M_NODE;
76 break;
77 case SAFI_LABELED_UNICAST:
78 return BGP_IPV4L_NODE;
79 break;
80 case SAFI_MPLS_VPN:
81 return BGP_VPNV4_NODE;
82 break;
7c40bf39 83 case SAFI_FLOWSPEC:
84 return BGP_FLOWSPECV4_NODE;
5c525538
RW
85 default:
86 /* not expected */
87 return BGP_IPV4_NODE;
88 break;
d62a17ae 89 }
90 break;
91 case AFI_IP6:
92 switch (safi) {
93 case SAFI_UNICAST:
94 return BGP_IPV6_NODE;
95 break;
96 case SAFI_MULTICAST:
97 return BGP_IPV6M_NODE;
98 break;
99 case SAFI_LABELED_UNICAST:
100 return BGP_IPV6L_NODE;
101 break;
102 case SAFI_MPLS_VPN:
103 return BGP_VPNV6_NODE;
104 break;
7c40bf39 105 case SAFI_FLOWSPEC:
106 return BGP_FLOWSPECV6_NODE;
5c525538
RW
107 default:
108 /* not expected */
109 return BGP_IPV4_NODE;
110 break;
d62a17ae 111 }
112 break;
113 case AFI_L2VPN:
114 return BGP_EVPN_NODE;
115 break;
116 case AFI_MAX:
117 // We should never be here but to clarify the switch statement..
118 return BGP_IPV4_NODE;
119 break;
120 }
121
122 // Impossible to happen
123 return BGP_IPV4_NODE;
f51bae9c 124}
20eb8864 125
718e3744 126/* Utility function to get address family from current node. */
d62a17ae 127afi_t bgp_node_afi(struct vty *vty)
128{
129 afi_t afi;
130 switch (vty->node) {
131 case BGP_IPV6_NODE:
132 case BGP_IPV6M_NODE:
133 case BGP_IPV6L_NODE:
134 case BGP_VPNV6_NODE:
7c40bf39 135 case BGP_FLOWSPECV6_NODE:
d62a17ae 136 afi = AFI_IP6;
137 break;
138 case BGP_EVPN_NODE:
139 afi = AFI_L2VPN;
140 break;
141 default:
142 afi = AFI_IP;
143 break;
144 }
145 return afi;
718e3744 146}
147
148/* Utility function to get subsequent address family from current
149 node. */
d62a17ae 150safi_t bgp_node_safi(struct vty *vty)
151{
152 safi_t safi;
153 switch (vty->node) {
154 case BGP_VPNV4_NODE:
155 case BGP_VPNV6_NODE:
156 safi = SAFI_MPLS_VPN;
157 break;
158 case BGP_IPV4M_NODE:
159 case BGP_IPV6M_NODE:
160 safi = SAFI_MULTICAST;
161 break;
162 case BGP_EVPN_NODE:
163 safi = SAFI_EVPN;
164 break;
165 case BGP_IPV4L_NODE:
166 case BGP_IPV6L_NODE:
167 safi = SAFI_LABELED_UNICAST;
168 break;
7c40bf39 169 case BGP_FLOWSPECV4_NODE:
170 case BGP_FLOWSPECV6_NODE:
171 safi = SAFI_FLOWSPEC;
172 break;
d62a17ae 173 default:
174 safi = SAFI_UNICAST;
175 break;
176 }
177 return safi;
718e3744 178}
179
55f91488
QY
180/**
181 * Converts an AFI in string form to afi_t
182 *
183 * @param afi string, one of
184 * - "ipv4"
185 * - "ipv6"
186 * @return the corresponding afi_t
187 */
d62a17ae 188afi_t bgp_vty_afi_from_str(const char *afi_str)
189{
190 afi_t afi = AFI_MAX; /* unknown */
191 if (strmatch(afi_str, "ipv4"))
192 afi = AFI_IP;
193 else if (strmatch(afi_str, "ipv6"))
194 afi = AFI_IP6;
195 return afi;
196}
197
198int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
199 afi_t *afi)
200{
201 int ret = 0;
202 if (argv_find(argv, argc, "ipv4", index)) {
203 ret = 1;
204 if (afi)
205 *afi = AFI_IP;
206 } else if (argv_find(argv, argc, "ipv6", index)) {
207 ret = 1;
208 if (afi)
209 *afi = AFI_IP6;
210 }
211 return ret;
46f296b4
LB
212}
213
375a2e67 214/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 215safi_t bgp_vty_safi_from_str(const char *safi_str)
216{
217 safi_t safi = SAFI_MAX; /* unknown */
218 if (strmatch(safi_str, "multicast"))
219 safi = SAFI_MULTICAST;
220 else if (strmatch(safi_str, "unicast"))
221 safi = SAFI_UNICAST;
222 else if (strmatch(safi_str, "vpn"))
223 safi = SAFI_MPLS_VPN;
224 else if (strmatch(safi_str, "labeled-unicast"))
225 safi = SAFI_LABELED_UNICAST;
7c40bf39 226 else if (strmatch(safi_str, "flowspec"))
227 safi = SAFI_FLOWSPEC;
d62a17ae 228 return safi;
229}
230
231int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
232 safi_t *safi)
233{
234 int ret = 0;
235 if (argv_find(argv, argc, "unicast", index)) {
236 ret = 1;
237 if (safi)
238 *safi = SAFI_UNICAST;
239 } else if (argv_find(argv, argc, "multicast", index)) {
240 ret = 1;
241 if (safi)
242 *safi = SAFI_MULTICAST;
243 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
244 ret = 1;
245 if (safi)
246 *safi = SAFI_LABELED_UNICAST;
247 } else if (argv_find(argv, argc, "vpn", index)) {
248 ret = 1;
249 if (safi)
250 *safi = SAFI_MPLS_VPN;
7c40bf39 251 } else if (argv_find(argv, argc, "flowspec", index)) {
252 ret = 1;
253 if (safi)
254 *safi = SAFI_FLOWSPEC;
d62a17ae 255 }
256 return ret;
46f296b4
LB
257}
258
7eeee51e 259/*
f212a857 260 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 261 *
f212a857
DS
262 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
263 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
264 * to appropriate values for the calling function. This is to allow the
265 * calling function to make decisions appropriate for the show command
266 * that is being parsed.
267 *
268 * The show commands are generally of the form:
d62a17ae 269 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
270 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
271 *
272 * Since we use argv_find if the show command in particular doesn't have:
273 * [ip]
18c57037 274 * [<view|vrf> VIEWVRFNAME]
375a2e67 275 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
276 * The command parsing should still be ok.
277 *
278 * vty -> The vty for the command so we can output some useful data in
279 * the event of a parse error in the vrf.
280 * argv -> The command tokens
281 * argc -> How many command tokens we have
d62a17ae 282 * idx -> The current place in the command, generally should be 0 for this
283 * function
7eeee51e
DS
284 * afi -> The parsed afi if it was included in the show command, returned here
285 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 286 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
287 *
288 * The function returns the correct location in the parse tree for the
289 * last token found.
0e37c258
DS
290 *
291 * Returns 0 for failure to parse correctly, else the idx position of where
292 * it found the last token.
7eeee51e 293 */
d62a17ae 294int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
295 struct cmd_token **argv, int argc,
296 int *idx, afi_t *afi, safi_t *safi,
297 struct bgp **bgp)
298{
299 char *vrf_name = NULL;
300
301 assert(afi);
302 assert(safi);
303 assert(bgp);
304
305 if (argv_find(argv, argc, "ip", idx))
306 *afi = AFI_IP;
307
308 if (argv_find(argv, argc, "view", idx)
309 || argv_find(argv, argc, "vrf", idx)) {
310 vrf_name = argv[*idx + 1]->arg;
311
312 if (strmatch(vrf_name, "all"))
313 *bgp = NULL;
314 else {
315 *bgp = bgp_lookup_by_name(vrf_name);
316 if (!*bgp) {
317 vty_out(vty,
318 "View/Vrf specified is unknown: %s\n",
319 vrf_name);
320 *idx = 0;
321 return 0;
322 }
323 }
324 } else {
325 *bgp = bgp_get_default();
326 if (!*bgp) {
327 vty_out(vty, "Unable to find default BGP instance\n");
328 *idx = 0;
329 return 0;
330 }
331 }
332
333 if (argv_find_and_parse_afi(argv, argc, idx, afi))
334 argv_find_and_parse_safi(argv, argc, idx, safi);
335
336 *idx += 1;
337 return *idx;
338}
339
340static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
341{
342 struct interface *ifp = NULL;
343
344 if (su->sa.sa_family == AF_INET)
345 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
346 else if (su->sa.sa_family == AF_INET6)
347 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
348 su->sin6.sin6_scope_id,
349 bgp->vrf_id);
350
351 if (ifp)
352 return 1;
353
354 return 0;
718e3744 355}
356
357/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
358/* This is used only for configuration, so disallow if attempted on
359 * a dynamic neighbor.
360 */
d62a17ae 361static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
362{
363 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
364 int ret;
365 union sockunion su;
366 struct peer *peer;
367
368 if (!bgp) {
369 return NULL;
370 }
371
372 ret = str2sockunion(ip_str, &su);
373 if (ret < 0) {
374 peer = peer_lookup_by_conf_if(bgp, ip_str);
375 if (!peer) {
376 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
377 == NULL) {
378 vty_out(vty,
379 "%% Malformed address or name: %s\n",
380 ip_str);
381 return NULL;
382 }
383 }
384 } else {
385 peer = peer_lookup(bgp, &su);
386 if (!peer) {
387 vty_out(vty,
388 "%% Specify remote-as or peer-group commands first\n");
389 return NULL;
390 }
391 if (peer_dynamic_neighbor(peer)) {
392 vty_out(vty,
393 "%% Operation not allowed on a dynamic neighbor\n");
394 return NULL;
395 }
396 }
397 return peer;
718e3744 398}
399
400/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
401/* This is used only for configuration, so disallow if attempted on
402 * a dynamic neighbor.
403 */
d62a17ae 404struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
405{
406 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
407 int ret;
408 union sockunion su;
409 struct peer *peer = NULL;
410 struct peer_group *group = NULL;
411
412 if (!bgp) {
413 return NULL;
414 }
415
416 ret = str2sockunion(peer_str, &su);
417 if (ret == 0) {
418 /* IP address, locate peer. */
419 peer = peer_lookup(bgp, &su);
420 } else {
421 /* Not IP, could match either peer configured on interface or a
422 * group. */
423 peer = peer_lookup_by_conf_if(bgp, peer_str);
424 if (!peer)
425 group = peer_group_lookup(bgp, peer_str);
426 }
427
428 if (peer) {
429 if (peer_dynamic_neighbor(peer)) {
430 vty_out(vty,
431 "%% Operation not allowed on a dynamic neighbor\n");
432 return NULL;
433 }
434
435 return peer;
436 }
437
438 if (group)
439 return group->conf;
440
441 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
442
443 return NULL;
444}
445
446int bgp_vty_return(struct vty *vty, int ret)
447{
448 const char *str = NULL;
449
450 switch (ret) {
451 case BGP_ERR_INVALID_VALUE:
452 str = "Invalid value";
453 break;
454 case BGP_ERR_INVALID_FLAG:
455 str = "Invalid flag";
456 break;
457 case BGP_ERR_PEER_GROUP_SHUTDOWN:
458 str = "Peer-group has been shutdown. Activate the peer-group first";
459 break;
460 case BGP_ERR_PEER_FLAG_CONFLICT:
461 str = "Can't set override-capability and strict-capability-match at the same time";
462 break;
463 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
464 str = "Specify remote-as or peer-group remote AS first";
465 break;
466 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
467 str = "Cannot change the peer-group. Deconfigure first";
468 break;
469 case BGP_ERR_PEER_GROUP_MISMATCH:
470 str = "Peer is not a member of this peer-group";
471 break;
472 case BGP_ERR_PEER_FILTER_CONFLICT:
473 str = "Prefix/distribute list can not co-exist";
474 break;
475 case BGP_ERR_NOT_INTERNAL_PEER:
476 str = "Invalid command. Not an internal neighbor";
477 break;
478 case BGP_ERR_REMOVE_PRIVATE_AS:
479 str = "remove-private-AS cannot be configured for IBGP peers";
480 break;
481 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
482 str = "Local-AS allowed only for EBGP peers";
483 break;
484 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
485 str = "Cannot have local-as same as BGP AS number";
486 break;
487 case BGP_ERR_TCPSIG_FAILED:
488 str = "Error while applying TCP-Sig to session(s)";
489 break;
490 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
491 str = "ebgp-multihop and ttl-security cannot be configured together";
492 break;
493 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
494 str = "ttl-security only allowed for EBGP peers";
495 break;
496 case BGP_ERR_AS_OVERRIDE:
497 str = "as-override cannot be configured for IBGP peers";
498 break;
499 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
500 str = "Invalid limit for number of dynamic neighbors";
501 break;
502 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
503 str = "Dynamic neighbor listen range already exists";
504 break;
505 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
506 str = "Operation not allowed on a dynamic neighbor";
507 break;
508 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
509 str = "Operation not allowed on a directly connected neighbor";
510 break;
511 case BGP_ERR_PEER_SAFI_CONFLICT:
512 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
513 break;
514 }
515 if (str) {
516 vty_out(vty, "%% %s\n", str);
517 return CMD_WARNING_CONFIG_FAILED;
518 }
519 return CMD_SUCCESS;
718e3744 520}
521
7aafcaca 522/* BGP clear sort. */
d62a17ae 523enum clear_sort {
524 clear_all,
525 clear_peer,
526 clear_group,
527 clear_external,
528 clear_as
7aafcaca
DS
529};
530
d62a17ae 531static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
532 safi_t safi, int error)
533{
534 switch (error) {
535 case BGP_ERR_AF_UNCONFIGURED:
536 vty_out(vty,
537 "%%BGP: Enable %s address family for the neighbor %s\n",
538 afi_safi_print(afi, safi), peer->host);
539 break;
540 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
541 vty_out(vty,
542 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
543 peer->host);
544 break;
545 default:
546 break;
547 }
7aafcaca
DS
548}
549
550/* `clear ip bgp' functions. */
d62a17ae 551static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
552 enum clear_sort sort, enum bgp_clear_type stype,
553 const char *arg)
554{
555 int ret;
3ae8bfa5 556 bool found = false;
d62a17ae 557 struct peer *peer;
558 struct listnode *node, *nnode;
559
560 /* Clear all neighbors. */
561 /*
562 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
563 * nodes on the BGP instance as that may get freed if it is a
564 * doppelganger
d62a17ae 565 */
566 if (sort == clear_all) {
567 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
3ae8bfa5
PM
568 if (!peer->afc[afi][safi])
569 continue;
570
d62a17ae 571 if (stype == BGP_CLEAR_SOFT_NONE)
572 ret = peer_clear(peer, &nnode);
d62a17ae 573 else
3ae8bfa5 574 ret = peer_clear_soft(peer, afi, safi, stype);
d62a17ae 575
576 if (ret < 0)
577 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
578 else
579 found = true;
04b6bdc0 580 }
d62a17ae 581
582 /* This is to apply read-only mode on this clear. */
583 if (stype == BGP_CLEAR_SOFT_NONE)
584 bgp->update_delay_over = 0;
585
3ae8bfa5
PM
586 if (!found)
587 vty_out(vty, "%%BGP: No %s peer configured",
588 afi_safi_print(afi, safi));
589
d62a17ae 590 return CMD_SUCCESS;
7aafcaca
DS
591 }
592
3ae8bfa5 593 /* Clear specified neighbor. */
d62a17ae 594 if (sort == clear_peer) {
595 union sockunion su;
d62a17ae 596
597 /* Make sockunion for lookup. */
598 ret = str2sockunion(arg, &su);
599 if (ret < 0) {
600 peer = peer_lookup_by_conf_if(bgp, arg);
601 if (!peer) {
602 peer = peer_lookup_by_hostname(bgp, arg);
603 if (!peer) {
604 vty_out(vty,
605 "Malformed address or name: %s\n",
606 arg);
607 return CMD_WARNING;
608 }
609 }
610 } else {
611 peer = peer_lookup(bgp, &su);
612 if (!peer) {
613 vty_out(vty,
614 "%%BGP: Unknown neighbor - \"%s\"\n",
615 arg);
616 return CMD_WARNING;
617 }
618 }
7aafcaca 619
3ae8bfa5
PM
620 if (!peer->afc[afi][safi])
621 ret = BGP_ERR_AF_UNCONFIGURED;
622 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 623 ret = peer_clear(peer, NULL);
624 else
625 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 626
d62a17ae 627 if (ret < 0)
628 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 629
d62a17ae 630 return CMD_SUCCESS;
7aafcaca 631 }
7aafcaca 632
3ae8bfa5 633 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 634 if (sort == clear_group) {
635 struct peer_group *group;
7aafcaca 636
d62a17ae 637 group = peer_group_lookup(bgp, arg);
638 if (!group) {
639 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
640 return CMD_WARNING;
641 }
642
643 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
d62a17ae 644 if (!peer->afc[afi][safi])
645 continue;
646
3ae8bfa5
PM
647 if (stype == BGP_CLEAR_SOFT_NONE)
648 ret = peer_clear(peer, NULL);
649 else
650 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 651
d62a17ae 652 if (ret < 0)
653 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
654 else
655 found = true;
d62a17ae 656 }
3ae8bfa5
PM
657
658 if (!found)
659 vty_out(vty,
660 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
661 afi_safi_print(afi, safi), arg);
662
d62a17ae 663 return CMD_SUCCESS;
7aafcaca 664 }
7aafcaca 665
3ae8bfa5 666 /* Clear all external (eBGP) neighbors. */
d62a17ae 667 if (sort == clear_external) {
668 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
669 if (peer->sort == BGP_PEER_IBGP)
670 continue;
7aafcaca 671
3ae8bfa5
PM
672 if (!peer->afc[afi][safi])
673 continue;
674
d62a17ae 675 if (stype == BGP_CLEAR_SOFT_NONE)
676 ret = peer_clear(peer, &nnode);
677 else
678 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 679
d62a17ae 680 if (ret < 0)
681 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
682 else
683 found = true;
d62a17ae 684 }
3ae8bfa5
PM
685
686 if (!found)
687 vty_out(vty,
688 "%%BGP: No external %s peer is configured\n",
689 afi_safi_print(afi, safi));
690
d62a17ae 691 return CMD_SUCCESS;
692 }
693
3ae8bfa5 694 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 695 if (sort == clear_as) {
3ae8bfa5 696 as_t as = strtoul(arg, NULL, 10);
d62a17ae 697
698 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
699 if (peer->as != as)
700 continue;
701
3ae8bfa5
PM
702 if (!peer->afc[afi][safi])
703 ret = BGP_ERR_AF_UNCONFIGURED;
704 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 705 ret = peer_clear(peer, &nnode);
706 else
707 ret = peer_clear_soft(peer, afi, safi, stype);
708
709 if (ret < 0)
710 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
711 else
712 found = true;
d62a17ae 713 }
3ae8bfa5
PM
714
715 if (!found)
d62a17ae 716 vty_out(vty,
3ae8bfa5
PM
717 "%%BGP: No %s peer is configured with AS %s\n",
718 afi_safi_print(afi, safi), arg);
719
d62a17ae 720 return CMD_SUCCESS;
721 }
722
723 return CMD_SUCCESS;
724}
725
726static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
727 safi_t safi, enum clear_sort sort,
728 enum bgp_clear_type stype, const char *arg)
729{
730 struct bgp *bgp;
731
732 /* BGP structure lookup. */
733 if (name) {
734 bgp = bgp_lookup_by_name(name);
735 if (bgp == NULL) {
736 vty_out(vty, "Can't find BGP instance %s\n", name);
737 return CMD_WARNING;
738 }
739 } else {
740 bgp = bgp_get_default();
741 if (bgp == NULL) {
742 vty_out(vty, "No BGP process is configured\n");
743 return CMD_WARNING;
744 }
745 }
746
747 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
748}
749
750/* clear soft inbound */
d62a17ae 751static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 752{
d62a17ae 753 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
754 BGP_CLEAR_SOFT_IN, NULL);
755 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
756 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
757}
758
759/* clear soft outbound */
d62a17ae 760static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 761{
d62a17ae 762 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
763 BGP_CLEAR_SOFT_OUT, NULL);
764 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
765 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
766}
767
768
f787d7a0 769#ifndef VTYSH_EXTRACT_PL
2e4c2296 770#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
771#endif
772
718e3744 773/* BGP global configuration. */
1cc40660
DS
774#if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
775CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
776CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
777#endif
778DEFUN_HIDDEN (bgp_multiple_instance_func,
779 bgp_multiple_instance_cmd,
780 "bgp multiple-instance",
781 BGP_STR
782 "Enable bgp multiple instance\n")
718e3744 783{
d62a17ae 784 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
785 return CMD_SUCCESS;
718e3744 786}
787
1cc40660 788DEFUN_HIDDEN (no_bgp_multiple_instance,
718e3744 789 no_bgp_multiple_instance_cmd,
790 "no bgp multiple-instance",
791 NO_STR
792 BGP_STR
793 "BGP multiple instance\n")
794{
d62a17ae 795 int ret;
718e3744 796
1cc40660
DS
797 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
798 vty_out(vty, "if you are using this please let the developers know\n");
799 zlog_warn("Deprecated option: `bgp multiple-instance` being used");
d62a17ae 800 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
801 if (ret < 0) {
802 vty_out(vty, "%% There are more than two BGP instances\n");
803 return CMD_WARNING_CONFIG_FAILED;
804 }
805 return CMD_SUCCESS;
718e3744 806}
807
798467a2
DS
808#if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
809CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
810CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
811#endif
812DEFUN_HIDDEN (bgp_config_type,
813 bgp_config_type_cmd,
814 "bgp config-type <cisco|zebra>",
815 BGP_STR
816 "Configuration type\n"
817 "cisco\n"
818 "zebra\n")
718e3744 819{
d62a17ae 820 int idx = 0;
798467a2
DS
821 if (argv_find(argv, argc, "cisco", &idx)) {
822 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
823 vty_out(vty, "if you are using this please let the developers know!\n");
824 zlog_warn("Deprecated option: `bgp config-type cisco` being used");
d62a17ae 825 bgp_option_set(BGP_OPT_CONFIG_CISCO);
798467a2 826 } else
d62a17ae 827 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 828
d62a17ae 829 return CMD_SUCCESS;
718e3744 830}
831
798467a2
DS
832DEFUN_HIDDEN (no_bgp_config_type,
833 no_bgp_config_type_cmd,
834 "no bgp config-type [<cisco|zebra>]",
835 NO_STR
836 BGP_STR
837 "Display configuration type\n"
838 "cisco\n"
839 "zebra\n")
718e3744 840{
d62a17ae 841 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
842 return CMD_SUCCESS;
718e3744 843}
844
813d4307 845
718e3744 846DEFUN (no_synchronization,
847 no_synchronization_cmd,
848 "no synchronization",
849 NO_STR
850 "Perform IGP synchronization\n")
851{
d62a17ae 852 return CMD_SUCCESS;
718e3744 853}
854
855DEFUN (no_auto_summary,
856 no_auto_summary_cmd,
857 "no auto-summary",
858 NO_STR
859 "Enable automatic network number summarization\n")
860{
d62a17ae 861 return CMD_SUCCESS;
718e3744 862}
3d515fd9 863
718e3744 864/* "router bgp" commands. */
505e5056 865DEFUN_NOSH (router_bgp,
f412b39a 866 router_bgp_cmd,
18c57037 867 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 868 ROUTER_STR
869 BGP_STR
31500417
DW
870 AS_STR
871 BGP_INSTANCE_HELP_STR)
718e3744 872{
d62a17ae 873 int idx_asn = 2;
874 int idx_view_vrf = 3;
875 int idx_vrf = 4;
876 int ret;
877 as_t as;
878 struct bgp *bgp;
879 const char *name = NULL;
880 enum bgp_instance_type inst_type;
881
882 // "router bgp" without an ASN
883 if (argc == 2) {
884 // Pending: Make VRF option available for ASN less config
885 bgp = bgp_get_default();
886
887 if (bgp == NULL) {
888 vty_out(vty, "%% No BGP process is configured\n");
889 return CMD_WARNING_CONFIG_FAILED;
890 }
891
892 if (listcount(bm->bgp) > 1) {
996c9314 893 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 894 return CMD_WARNING_CONFIG_FAILED;
895 }
896 }
897
898 // "router bgp X"
899 else {
900 as = strtoul(argv[idx_asn]->arg, NULL, 10);
901
902 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
903 if (argc > 3) {
904 name = argv[idx_vrf]->arg;
905
906 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
907 inst_type = BGP_INSTANCE_TYPE_VRF;
908 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
909 inst_type = BGP_INSTANCE_TYPE_VIEW;
910 }
911
912 ret = bgp_get(&bgp, &as, name, inst_type);
913 switch (ret) {
914 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
915 vty_out(vty,
916 "Please specify 'bgp multiple-instance' first\n");
917 return CMD_WARNING_CONFIG_FAILED;
918 case BGP_ERR_AS_MISMATCH:
919 vty_out(vty, "BGP is already running; AS is %u\n", as);
920 return CMD_WARNING_CONFIG_FAILED;
921 case BGP_ERR_INSTANCE_MISMATCH:
922 vty_out(vty,
923 "BGP instance name and AS number mismatch\n");
924 vty_out(vty,
925 "BGP instance is already running; AS is %u\n",
926 as);
927 return CMD_WARNING_CONFIG_FAILED;
928 }
929
930 /* Pending: handle when user tries to change a view to vrf n vv.
931 */
932 }
933
0b5131c9
MK
934 /* unset the auto created flag as the user config is now present */
935 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 936 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
937
938 return CMD_SUCCESS;
718e3744 939}
940
718e3744 941/* "no router bgp" commands. */
942DEFUN (no_router_bgp,
943 no_router_bgp_cmd,
18c57037 944 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 945 NO_STR
946 ROUTER_STR
947 BGP_STR
31500417
DW
948 AS_STR
949 BGP_INSTANCE_HELP_STR)
718e3744 950{
d62a17ae 951 int idx_asn = 3;
952 int idx_vrf = 5;
953 as_t as;
954 struct bgp *bgp;
955 const char *name = NULL;
718e3744 956
d62a17ae 957 // "no router bgp" without an ASN
958 if (argc == 3) {
959 // Pending: Make VRF option available for ASN less config
960 bgp = bgp_get_default();
718e3744 961
d62a17ae 962 if (bgp == NULL) {
963 vty_out(vty, "%% No BGP process is configured\n");
964 return CMD_WARNING_CONFIG_FAILED;
965 }
7fb21a9f 966
d62a17ae 967 if (listcount(bm->bgp) > 1) {
996c9314 968 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 969 return CMD_WARNING_CONFIG_FAILED;
970 }
0b5131c9
MK
971
972 if (bgp->l3vni) {
973 vty_out(vty, "%% Please unconfigure l3vni %u",
974 bgp->l3vni);
975 return CMD_WARNING_CONFIG_FAILED;
976 }
d62a17ae 977 } else {
978 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 979
d62a17ae 980 if (argc > 4)
981 name = argv[idx_vrf]->arg;
7fb21a9f 982
d62a17ae 983 /* Lookup bgp structure. */
984 bgp = bgp_lookup(as, name);
985 if (!bgp) {
986 vty_out(vty, "%% Can't find BGP instance\n");
987 return CMD_WARNING_CONFIG_FAILED;
988 }
0b5131c9
MK
989
990 if (bgp->l3vni) {
991 vty_out(vty, "%% Please unconfigure l3vni %u",
992 bgp->l3vni);
993 return CMD_WARNING_CONFIG_FAILED;
994 }
d62a17ae 995 }
718e3744 996
d62a17ae 997 bgp_delete(bgp);
718e3744 998
d62a17ae 999 return CMD_SUCCESS;
718e3744 1000}
1001
6b0655a2 1002
718e3744 1003/* BGP router-id. */
1004
f787d7a0 1005DEFPY (bgp_router_id,
718e3744 1006 bgp_router_id_cmd,
1007 "bgp router-id A.B.C.D",
1008 BGP_STR
1009 "Override configured router identifier\n"
1010 "Manually configured router identifier\n")
1011{
d62a17ae 1012 VTY_DECLVAR_CONTEXT(bgp, bgp);
1013 bgp_router_id_static_set(bgp, router_id);
1014 return CMD_SUCCESS;
718e3744 1015}
1016
f787d7a0 1017DEFPY (no_bgp_router_id,
718e3744 1018 no_bgp_router_id_cmd,
31500417 1019 "no bgp router-id [A.B.C.D]",
718e3744 1020 NO_STR
1021 BGP_STR
31500417
DW
1022 "Override configured router identifier\n"
1023 "Manually configured router identifier\n")
718e3744 1024{
d62a17ae 1025 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1026
d62a17ae 1027 if (router_id_str) {
1028 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1029 vty_out(vty, "%% BGP router-id doesn't match\n");
1030 return CMD_WARNING_CONFIG_FAILED;
1031 }
e018c7cc 1032 }
718e3744 1033
d62a17ae 1034 router_id.s_addr = 0;
1035 bgp_router_id_static_set(bgp, router_id);
718e3744 1036
d62a17ae 1037 return CMD_SUCCESS;
718e3744 1038}
1039
6b0655a2 1040
718e3744 1041/* BGP Cluster ID. */
718e3744 1042DEFUN (bgp_cluster_id,
1043 bgp_cluster_id_cmd,
838758ac 1044 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1045 BGP_STR
1046 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1047 "Route-Reflector Cluster-id in IP address format\n"
1048 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1049{
d62a17ae 1050 VTY_DECLVAR_CONTEXT(bgp, bgp);
1051 int idx_ipv4 = 2;
1052 int ret;
1053 struct in_addr cluster;
718e3744 1054
d62a17ae 1055 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1056 if (!ret) {
1057 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1058 return CMD_WARNING_CONFIG_FAILED;
1059 }
718e3744 1060
d62a17ae 1061 bgp_cluster_id_set(bgp, &cluster);
1062 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1063
d62a17ae 1064 return CMD_SUCCESS;
718e3744 1065}
1066
718e3744 1067DEFUN (no_bgp_cluster_id,
1068 no_bgp_cluster_id_cmd,
c7178fe7 1069 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1070 NO_STR
1071 BGP_STR
838758ac
DW
1072 "Configure Route-Reflector Cluster-id\n"
1073 "Route-Reflector Cluster-id in IP address format\n"
1074 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1075{
d62a17ae 1076 VTY_DECLVAR_CONTEXT(bgp, bgp);
1077 bgp_cluster_id_unset(bgp);
1078 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1079
d62a17ae 1080 return CMD_SUCCESS;
718e3744 1081}
1082
718e3744 1083DEFUN (bgp_confederation_identifier,
1084 bgp_confederation_identifier_cmd,
9ccf14f7 1085 "bgp confederation identifier (1-4294967295)",
718e3744 1086 "BGP specific commands\n"
1087 "AS confederation parameters\n"
1088 "AS number\n"
1089 "Set routing domain confederation AS\n")
1090{
d62a17ae 1091 VTY_DECLVAR_CONTEXT(bgp, bgp);
1092 int idx_number = 3;
1093 as_t as;
718e3744 1094
d62a17ae 1095 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1096
d62a17ae 1097 bgp_confederation_id_set(bgp, as);
718e3744 1098
d62a17ae 1099 return CMD_SUCCESS;
718e3744 1100}
1101
1102DEFUN (no_bgp_confederation_identifier,
1103 no_bgp_confederation_identifier_cmd,
838758ac 1104 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1105 NO_STR
1106 "BGP specific commands\n"
1107 "AS confederation parameters\n"
3a2d747c
QY
1108 "AS number\n"
1109 "Set routing domain confederation AS\n")
718e3744 1110{
d62a17ae 1111 VTY_DECLVAR_CONTEXT(bgp, bgp);
1112 bgp_confederation_id_unset(bgp);
718e3744 1113
d62a17ae 1114 return CMD_SUCCESS;
718e3744 1115}
1116
718e3744 1117DEFUN (bgp_confederation_peers,
1118 bgp_confederation_peers_cmd,
12dcf78e 1119 "bgp confederation peers (1-4294967295)...",
718e3744 1120 "BGP specific commands\n"
1121 "AS confederation parameters\n"
1122 "Peer ASs in BGP confederation\n"
1123 AS_STR)
1124{
d62a17ae 1125 VTY_DECLVAR_CONTEXT(bgp, bgp);
1126 int idx_asn = 3;
1127 as_t as;
1128 int i;
718e3744 1129
d62a17ae 1130 for (i = idx_asn; i < argc; i++) {
1131 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1132
d62a17ae 1133 if (bgp->as == as) {
1134 vty_out(vty,
1135 "%% Local member-AS not allowed in confed peer list\n");
1136 continue;
1137 }
718e3744 1138
d62a17ae 1139 bgp_confederation_peers_add(bgp, as);
1140 }
1141 return CMD_SUCCESS;
718e3744 1142}
1143
1144DEFUN (no_bgp_confederation_peers,
1145 no_bgp_confederation_peers_cmd,
e83a9414 1146 "no bgp confederation peers (1-4294967295)...",
718e3744 1147 NO_STR
1148 "BGP specific commands\n"
1149 "AS confederation parameters\n"
1150 "Peer ASs in BGP confederation\n"
1151 AS_STR)
1152{
d62a17ae 1153 VTY_DECLVAR_CONTEXT(bgp, bgp);
1154 int idx_asn = 4;
1155 as_t as;
1156 int i;
718e3744 1157
d62a17ae 1158 for (i = idx_asn; i < argc; i++) {
1159 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1160
d62a17ae 1161 bgp_confederation_peers_remove(bgp, as);
1162 }
1163 return CMD_SUCCESS;
718e3744 1164}
6b0655a2 1165
5e242b0d
DS
1166/**
1167 * Central routine for maximum-paths configuration.
1168 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1169 * @set: 1 for setting values, 0 for removing the max-paths config.
1170 */
d62a17ae 1171static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1172 const char *mpaths, uint16_t options,
d62a17ae 1173 int set)
1174{
1175 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1176 uint16_t maxpaths = 0;
d62a17ae 1177 int ret;
1178 afi_t afi;
1179 safi_t safi;
1180
1181 afi = bgp_node_afi(vty);
1182 safi = bgp_node_safi(vty);
1183
1184 if (set) {
1185 maxpaths = strtol(mpaths, NULL, 10);
1186 if (maxpaths > multipath_num) {
1187 vty_out(vty,
1188 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1189 maxpaths, multipath_num);
1190 return CMD_WARNING_CONFIG_FAILED;
1191 }
1192 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1193 options);
1194 } else
1195 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1196
1197 if (ret < 0) {
1198 vty_out(vty,
1199 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1200 (set == 1) ? "" : "un",
1201 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1202 maxpaths, afi, safi);
1203 return CMD_WARNING_CONFIG_FAILED;
1204 }
1205
1206 bgp_recalculate_all_bestpaths(bgp);
1207
1208 return CMD_SUCCESS;
165b5fff
JB
1209}
1210
abc920f8
DS
1211DEFUN (bgp_maxmed_admin,
1212 bgp_maxmed_admin_cmd,
1213 "bgp max-med administrative ",
1214 BGP_STR
1215 "Advertise routes with max-med\n"
1216 "Administratively applied, for an indefinite period\n")
1217{
d62a17ae 1218 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1219
d62a17ae 1220 bgp->v_maxmed_admin = 1;
1221 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1222
d62a17ae 1223 bgp_maxmed_update(bgp);
abc920f8 1224
d62a17ae 1225 return CMD_SUCCESS;
abc920f8
DS
1226}
1227
1228DEFUN (bgp_maxmed_admin_medv,
1229 bgp_maxmed_admin_medv_cmd,
4668a151 1230 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1231 BGP_STR
1232 "Advertise routes with max-med\n"
1233 "Administratively applied, for an indefinite period\n"
1234 "Max MED value to be used\n")
1235{
d62a17ae 1236 VTY_DECLVAR_CONTEXT(bgp, bgp);
1237 int idx_number = 3;
abc920f8 1238
d62a17ae 1239 bgp->v_maxmed_admin = 1;
1240 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1241
d62a17ae 1242 bgp_maxmed_update(bgp);
abc920f8 1243
d62a17ae 1244 return CMD_SUCCESS;
abc920f8
DS
1245}
1246
1247DEFUN (no_bgp_maxmed_admin,
1248 no_bgp_maxmed_admin_cmd,
4668a151 1249 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1250 NO_STR
1251 BGP_STR
1252 "Advertise routes with max-med\n"
838758ac
DW
1253 "Administratively applied, for an indefinite period\n"
1254 "Max MED value to be used\n")
abc920f8 1255{
d62a17ae 1256 VTY_DECLVAR_CONTEXT(bgp, bgp);
1257 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1258 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1259 bgp_maxmed_update(bgp);
abc920f8 1260
d62a17ae 1261 return CMD_SUCCESS;
abc920f8
DS
1262}
1263
abc920f8
DS
1264DEFUN (bgp_maxmed_onstartup,
1265 bgp_maxmed_onstartup_cmd,
4668a151 1266 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1267 BGP_STR
1268 "Advertise routes with max-med\n"
1269 "Effective on a startup\n"
1270 "Time (seconds) period for max-med\n"
1271 "Max MED value to be used\n")
1272{
d62a17ae 1273 VTY_DECLVAR_CONTEXT(bgp, bgp);
1274 int idx = 0;
4668a151 1275
d62a17ae 1276 argv_find(argv, argc, "(5-86400)", &idx);
1277 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1278 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1279 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1280 else
1281 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1282
d62a17ae 1283 bgp_maxmed_update(bgp);
abc920f8 1284
d62a17ae 1285 return CMD_SUCCESS;
abc920f8
DS
1286}
1287
1288DEFUN (no_bgp_maxmed_onstartup,
1289 no_bgp_maxmed_onstartup_cmd,
4668a151 1290 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1291 NO_STR
1292 BGP_STR
1293 "Advertise routes with max-med\n"
838758ac
DW
1294 "Effective on a startup\n"
1295 "Time (seconds) period for max-med\n"
1296 "Max MED value to be used\n")
abc920f8 1297{
d62a17ae 1298 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1299
d62a17ae 1300 /* Cancel max-med onstartup if its on */
1301 if (bgp->t_maxmed_onstartup) {
1302 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1303 bgp->maxmed_onstartup_over = 1;
1304 }
abc920f8 1305
d62a17ae 1306 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1307 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1308
d62a17ae 1309 bgp_maxmed_update(bgp);
abc920f8 1310
d62a17ae 1311 return CMD_SUCCESS;
abc920f8
DS
1312}
1313
d62a17ae 1314static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1315 const char *wait)
f188f2c4 1316{
d62a17ae 1317 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1318 uint16_t update_delay;
1319 uint16_t establish_wait;
f188f2c4 1320
d62a17ae 1321 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1322
d62a17ae 1323 if (!wait) /* update-delay <delay> */
1324 {
1325 bgp->v_update_delay = update_delay;
1326 bgp->v_establish_wait = bgp->v_update_delay;
1327 return CMD_SUCCESS;
1328 }
f188f2c4 1329
d62a17ae 1330 /* update-delay <delay> <establish-wait> */
1331 establish_wait = atoi(wait);
1332 if (update_delay < establish_wait) {
1333 vty_out(vty,
1334 "%%Failed: update-delay less than the establish-wait!\n");
1335 return CMD_WARNING_CONFIG_FAILED;
1336 }
f188f2c4 1337
d62a17ae 1338 bgp->v_update_delay = update_delay;
1339 bgp->v_establish_wait = establish_wait;
f188f2c4 1340
d62a17ae 1341 return CMD_SUCCESS;
f188f2c4
DS
1342}
1343
d62a17ae 1344static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1345{
d62a17ae 1346 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1347
d62a17ae 1348 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1349 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1350
d62a17ae 1351 return CMD_SUCCESS;
f188f2c4
DS
1352}
1353
2b791107 1354void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1355{
d62a17ae 1356 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1357 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1358 if (bgp->v_update_delay != bgp->v_establish_wait)
1359 vty_out(vty, " %d", bgp->v_establish_wait);
1360 vty_out(vty, "\n");
1361 }
f188f2c4
DS
1362}
1363
1364
1365/* Update-delay configuration */
1366DEFUN (bgp_update_delay,
1367 bgp_update_delay_cmd,
6147e2c6 1368 "update-delay (0-3600)",
f188f2c4
DS
1369 "Force initial delay for best-path and updates\n"
1370 "Seconds\n")
1371{
d62a17ae 1372 int idx_number = 1;
1373 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1374}
1375
1376DEFUN (bgp_update_delay_establish_wait,
1377 bgp_update_delay_establish_wait_cmd,
6147e2c6 1378 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1379 "Force initial delay for best-path and updates\n"
1380 "Seconds\n"
f188f2c4
DS
1381 "Seconds\n")
1382{
d62a17ae 1383 int idx_number = 1;
1384 int idx_number_2 = 2;
1385 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1386 argv[idx_number_2]->arg);
f188f2c4
DS
1387}
1388
1389/* Update-delay deconfiguration */
1390DEFUN (no_bgp_update_delay,
1391 no_bgp_update_delay_cmd,
838758ac
DW
1392 "no update-delay [(0-3600) [(1-3600)]]",
1393 NO_STR
f188f2c4 1394 "Force initial delay for best-path and updates\n"
838758ac 1395 "Seconds\n"
7111c1a0 1396 "Seconds\n")
f188f2c4 1397{
d62a17ae 1398 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1399}
1400
5e242b0d 1401
d62a17ae 1402static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1403 char set)
cb1faec9 1404{
d62a17ae 1405 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1406
555e09d4
QY
1407 if (set) {
1408 uint32_t quanta = strtoul(num, NULL, 10);
1409 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1410 memory_order_relaxed);
1411 } else {
1412 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1413 memory_order_relaxed);
1414 }
1415
1416 return CMD_SUCCESS;
1417}
1418
1419static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1420 char set)
1421{
1422 VTY_DECLVAR_CONTEXT(bgp, bgp);
1423
1424 if (set) {
1425 uint32_t quanta = strtoul(num, NULL, 10);
1426 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1427 memory_order_relaxed);
1428 } else {
1429 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1430 memory_order_relaxed);
1431 }
cb1faec9 1432
d62a17ae 1433 return CMD_SUCCESS;
cb1faec9
DS
1434}
1435
2b791107 1436void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1437{
555e09d4
QY
1438 uint32_t quanta =
1439 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1440 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1441 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1442}
1443
555e09d4
QY
1444void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1445{
1446 uint32_t quanta =
1447 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1448 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1449 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1450}
cb1faec9 1451
555e09d4 1452/* Packet quanta configuration */
cb1faec9
DS
1453DEFUN (bgp_wpkt_quanta,
1454 bgp_wpkt_quanta_cmd,
555e09d4 1455 "write-quanta (1-10)",
cb1faec9
DS
1456 "How many packets to write to peer socket per run\n"
1457 "Number of packets\n")
1458{
d62a17ae 1459 int idx_number = 1;
1460 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1461}
1462
cb1faec9
DS
1463DEFUN (no_bgp_wpkt_quanta,
1464 no_bgp_wpkt_quanta_cmd,
555e09d4 1465 "no write-quanta (1-10)",
d7fa34c1 1466 NO_STR
555e09d4 1467 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1468 "Number of packets\n")
1469{
d62a17ae 1470 int idx_number = 2;
1471 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1472}
1473
555e09d4
QY
1474DEFUN (bgp_rpkt_quanta,
1475 bgp_rpkt_quanta_cmd,
1476 "read-quanta (1-10)",
1477 "How many packets to read from peer socket per I/O cycle\n"
1478 "Number of packets\n")
1479{
1480 int idx_number = 1;
1481 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1482}
1483
1484DEFUN (no_bgp_rpkt_quanta,
1485 no_bgp_rpkt_quanta_cmd,
1486 "no read-quanta (1-10)",
1487 NO_STR
1488 "How many packets to read from peer socket per I/O cycle\n"
1489 "Number of packets\n")
1490{
1491 int idx_number = 2;
1492 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1493}
1494
2b791107 1495void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1496{
37a333fe 1497 if (!bgp->heuristic_coalesce)
d62a17ae 1498 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1499}
1500
1501
1502DEFUN (bgp_coalesce_time,
1503 bgp_coalesce_time_cmd,
6147e2c6 1504 "coalesce-time (0-4294967295)",
3f9c7369
DS
1505 "Subgroup coalesce timer\n"
1506 "Subgroup coalesce timer value (in ms)\n")
1507{
d62a17ae 1508 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1509
d62a17ae 1510 int idx = 0;
1511 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1512 bgp->heuristic_coalesce = false;
d62a17ae 1513 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1514 return CMD_SUCCESS;
3f9c7369
DS
1515}
1516
1517DEFUN (no_bgp_coalesce_time,
1518 no_bgp_coalesce_time_cmd,
6147e2c6 1519 "no coalesce-time (0-4294967295)",
3a2d747c 1520 NO_STR
3f9c7369
DS
1521 "Subgroup coalesce timer\n"
1522 "Subgroup coalesce timer value (in ms)\n")
1523{
d62a17ae 1524 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1525
37a333fe 1526 bgp->heuristic_coalesce = true;
d62a17ae 1527 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1528 return CMD_SUCCESS;
3f9c7369
DS
1529}
1530
5e242b0d
DS
1531/* Maximum-paths configuration */
1532DEFUN (bgp_maxpaths,
1533 bgp_maxpaths_cmd,
6319fd63 1534 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1535 "Forward packets over multiple paths\n"
1536 "Number of paths\n")
1537{
d62a17ae 1538 int idx_number = 1;
1539 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1540 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1541}
1542
d62a17ae 1543ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1544 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1545 "Forward packets over multiple paths\n"
1546 "Number of paths\n")
596c17ba 1547
165b5fff
JB
1548DEFUN (bgp_maxpaths_ibgp,
1549 bgp_maxpaths_ibgp_cmd,
6319fd63 1550 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1551 "Forward packets over multiple paths\n"
1552 "iBGP-multipath\n"
1553 "Number of paths\n")
1554{
d62a17ae 1555 int idx_number = 2;
1556 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1557 argv[idx_number]->arg, 0, 1);
5e242b0d 1558}
165b5fff 1559
d62a17ae 1560ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1561 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1562 "Forward packets over multiple paths\n"
1563 "iBGP-multipath\n"
1564 "Number of paths\n")
596c17ba 1565
5e242b0d
DS
1566DEFUN (bgp_maxpaths_ibgp_cluster,
1567 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1568 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1569 "Forward packets over multiple paths\n"
1570 "iBGP-multipath\n"
1571 "Number of paths\n"
1572 "Match the cluster length\n")
1573{
d62a17ae 1574 int idx_number = 2;
1575 return bgp_maxpaths_config_vty(
1576 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1577 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1578}
1579
d62a17ae 1580ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1581 "maximum-paths ibgp " CMD_RANGE_STR(
1582 1, MULTIPATH_NUM) " equal-cluster-length",
1583 "Forward packets over multiple paths\n"
1584 "iBGP-multipath\n"
1585 "Number of paths\n"
1586 "Match the cluster length\n")
596c17ba 1587
165b5fff
JB
1588DEFUN (no_bgp_maxpaths,
1589 no_bgp_maxpaths_cmd,
6319fd63 1590 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1591 NO_STR
1592 "Forward packets over multiple paths\n"
1593 "Number of paths\n")
1594{
d62a17ae 1595 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1596}
1597
d62a17ae 1598ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1599 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1600 "Forward packets over multiple paths\n"
1601 "Number of paths\n")
596c17ba 1602
165b5fff
JB
1603DEFUN (no_bgp_maxpaths_ibgp,
1604 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1605 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1606 NO_STR
1607 "Forward packets over multiple paths\n"
1608 "iBGP-multipath\n"
838758ac
DW
1609 "Number of paths\n"
1610 "Match the cluster length\n")
165b5fff 1611{
d62a17ae 1612 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1613}
1614
d62a17ae 1615ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1616 "no maximum-paths ibgp [" CMD_RANGE_STR(
1617 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1618 NO_STR
1619 "Forward packets over multiple paths\n"
1620 "iBGP-multipath\n"
1621 "Number of paths\n"
1622 "Match the cluster length\n")
596c17ba 1623
2b791107 1624void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1625 safi_t safi)
165b5fff 1626{
d62a17ae 1627 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1628 vty_out(vty, " maximum-paths %d\n",
1629 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1630 }
165b5fff 1631
d62a17ae 1632 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1633 vty_out(vty, " maximum-paths ibgp %d",
1634 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1635 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1636 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1637 vty_out(vty, " equal-cluster-length");
1638 vty_out(vty, "\n");
1639 }
165b5fff 1640}
6b0655a2 1641
718e3744 1642/* BGP timers. */
1643
1644DEFUN (bgp_timers,
1645 bgp_timers_cmd,
6147e2c6 1646 "timers bgp (0-65535) (0-65535)",
718e3744 1647 "Adjust routing timers\n"
1648 "BGP timers\n"
1649 "Keepalive interval\n"
1650 "Holdtime\n")
1651{
d62a17ae 1652 VTY_DECLVAR_CONTEXT(bgp, bgp);
1653 int idx_number = 2;
1654 int idx_number_2 = 3;
1655 unsigned long keepalive = 0;
1656 unsigned long holdtime = 0;
718e3744 1657
d62a17ae 1658 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1659 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1660
d62a17ae 1661 /* Holdtime value check. */
1662 if (holdtime < 3 && holdtime != 0) {
1663 vty_out(vty,
1664 "%% hold time value must be either 0 or greater than 3\n");
1665 return CMD_WARNING_CONFIG_FAILED;
1666 }
718e3744 1667
d62a17ae 1668 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1669
d62a17ae 1670 return CMD_SUCCESS;
718e3744 1671}
1672
1673DEFUN (no_bgp_timers,
1674 no_bgp_timers_cmd,
838758ac 1675 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1676 NO_STR
1677 "Adjust routing timers\n"
838758ac
DW
1678 "BGP timers\n"
1679 "Keepalive interval\n"
1680 "Holdtime\n")
718e3744 1681{
d62a17ae 1682 VTY_DECLVAR_CONTEXT(bgp, bgp);
1683 bgp_timers_unset(bgp);
718e3744 1684
d62a17ae 1685 return CMD_SUCCESS;
718e3744 1686}
1687
6b0655a2 1688
718e3744 1689DEFUN (bgp_client_to_client_reflection,
1690 bgp_client_to_client_reflection_cmd,
1691 "bgp client-to-client reflection",
1692 "BGP specific commands\n"
1693 "Configure client to client route reflection\n"
1694 "reflection of routes allowed\n")
1695{
d62a17ae 1696 VTY_DECLVAR_CONTEXT(bgp, bgp);
1697 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1698 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1699
d62a17ae 1700 return CMD_SUCCESS;
718e3744 1701}
1702
1703DEFUN (no_bgp_client_to_client_reflection,
1704 no_bgp_client_to_client_reflection_cmd,
1705 "no bgp client-to-client reflection",
1706 NO_STR
1707 "BGP specific commands\n"
1708 "Configure client to client route reflection\n"
1709 "reflection of routes allowed\n")
1710{
d62a17ae 1711 VTY_DECLVAR_CONTEXT(bgp, bgp);
1712 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1713 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1714
d62a17ae 1715 return CMD_SUCCESS;
718e3744 1716}
1717
1718/* "bgp always-compare-med" configuration. */
1719DEFUN (bgp_always_compare_med,
1720 bgp_always_compare_med_cmd,
1721 "bgp always-compare-med",
1722 "BGP specific commands\n"
1723 "Allow comparing MED from different neighbors\n")
1724{
d62a17ae 1725 VTY_DECLVAR_CONTEXT(bgp, bgp);
1726 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1727 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1728
d62a17ae 1729 return CMD_SUCCESS;
718e3744 1730}
1731
1732DEFUN (no_bgp_always_compare_med,
1733 no_bgp_always_compare_med_cmd,
1734 "no bgp always-compare-med",
1735 NO_STR
1736 "BGP specific commands\n"
1737 "Allow comparing MED from different neighbors\n")
1738{
d62a17ae 1739 VTY_DECLVAR_CONTEXT(bgp, bgp);
1740 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1741 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1742
d62a17ae 1743 return CMD_SUCCESS;
718e3744 1744}
6b0655a2 1745
718e3744 1746/* "bgp deterministic-med" configuration. */
1747DEFUN (bgp_deterministic_med,
1748 bgp_deterministic_med_cmd,
1749 "bgp deterministic-med",
1750 "BGP specific commands\n"
1751 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1752{
d62a17ae 1753 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1754
d62a17ae 1755 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1756 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1757 bgp_recalculate_all_bestpaths(bgp);
1758 }
7aafcaca 1759
d62a17ae 1760 return CMD_SUCCESS;
718e3744 1761}
1762
1763DEFUN (no_bgp_deterministic_med,
1764 no_bgp_deterministic_med_cmd,
1765 "no bgp deterministic-med",
1766 NO_STR
1767 "BGP specific commands\n"
1768 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1769{
d62a17ae 1770 VTY_DECLVAR_CONTEXT(bgp, bgp);
1771 int bestpath_per_as_used;
1772 afi_t afi;
1773 safi_t safi;
1774 struct peer *peer;
1775 struct listnode *node, *nnode;
1776
1777 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1778 bestpath_per_as_used = 0;
1779
1780 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc
QY
1781 FOREACH_AFI_SAFI (afi, safi)
1782 if (CHECK_FLAG(
1783 peer->af_flags[afi][safi],
1784 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1785 bestpath_per_as_used = 1;
1786 break;
1787 }
d62a17ae 1788
1789 if (bestpath_per_as_used)
1790 break;
1791 }
1792
1793 if (bestpath_per_as_used) {
1794 vty_out(vty,
1795 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1796 return CMD_WARNING_CONFIG_FAILED;
1797 } else {
1798 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1799 bgp_recalculate_all_bestpaths(bgp);
1800 }
1801 }
1802
1803 return CMD_SUCCESS;
718e3744 1804}
538621f2 1805
1806/* "bgp graceful-restart" configuration. */
1807DEFUN (bgp_graceful_restart,
1808 bgp_graceful_restart_cmd,
1809 "bgp graceful-restart",
1810 "BGP specific commands\n"
1811 "Graceful restart capability parameters\n")
1812{
d62a17ae 1813 VTY_DECLVAR_CONTEXT(bgp, bgp);
1814 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1815 return CMD_SUCCESS;
538621f2 1816}
1817
1818DEFUN (no_bgp_graceful_restart,
1819 no_bgp_graceful_restart_cmd,
1820 "no bgp graceful-restart",
1821 NO_STR
1822 "BGP specific commands\n"
1823 "Graceful restart capability parameters\n")
1824{
d62a17ae 1825 VTY_DECLVAR_CONTEXT(bgp, bgp);
1826 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1827 return CMD_SUCCESS;
538621f2 1828}
1829
93406d87 1830DEFUN (bgp_graceful_restart_stalepath_time,
1831 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1832 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1833 "BGP specific commands\n"
1834 "Graceful restart capability parameters\n"
1835 "Set the max time to hold onto restarting peer's stale paths\n"
1836 "Delay value (seconds)\n")
1837{
d62a17ae 1838 VTY_DECLVAR_CONTEXT(bgp, bgp);
1839 int idx_number = 3;
d7c0a89a 1840 uint32_t stalepath;
93406d87 1841
d62a17ae 1842 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1843 bgp->stalepath_time = stalepath;
1844 return CMD_SUCCESS;
93406d87 1845}
1846
eb6f1b41
PG
1847DEFUN (bgp_graceful_restart_restart_time,
1848 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1849 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1850 "BGP specific commands\n"
1851 "Graceful restart capability parameters\n"
1852 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1853 "Delay value (seconds)\n")
1854{
d62a17ae 1855 VTY_DECLVAR_CONTEXT(bgp, bgp);
1856 int idx_number = 3;
d7c0a89a 1857 uint32_t restart;
eb6f1b41 1858
d62a17ae 1859 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1860 bgp->restart_time = restart;
1861 return CMD_SUCCESS;
eb6f1b41
PG
1862}
1863
93406d87 1864DEFUN (no_bgp_graceful_restart_stalepath_time,
1865 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1866 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1867 NO_STR
1868 "BGP specific commands\n"
1869 "Graceful restart capability parameters\n"
838758ac
DW
1870 "Set the max time to hold onto restarting peer's stale paths\n"
1871 "Delay value (seconds)\n")
93406d87 1872{
d62a17ae 1873 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1874
d62a17ae 1875 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1876 return CMD_SUCCESS;
93406d87 1877}
1878
eb6f1b41
PG
1879DEFUN (no_bgp_graceful_restart_restart_time,
1880 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1881 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1882 NO_STR
1883 "BGP specific commands\n"
1884 "Graceful restart capability parameters\n"
838758ac
DW
1885 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1886 "Delay value (seconds)\n")
eb6f1b41 1887{
d62a17ae 1888 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1889
d62a17ae 1890 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1891 return CMD_SUCCESS;
eb6f1b41
PG
1892}
1893
43fc21b3
JC
1894DEFUN (bgp_graceful_restart_preserve_fw,
1895 bgp_graceful_restart_preserve_fw_cmd,
1896 "bgp graceful-restart preserve-fw-state",
1897 "BGP specific commands\n"
1898 "Graceful restart capability parameters\n"
1899 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1900{
d62a17ae 1901 VTY_DECLVAR_CONTEXT(bgp, bgp);
1902 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1903 return CMD_SUCCESS;
43fc21b3
JC
1904}
1905
1906DEFUN (no_bgp_graceful_restart_preserve_fw,
1907 no_bgp_graceful_restart_preserve_fw_cmd,
1908 "no bgp graceful-restart preserve-fw-state",
1909 NO_STR
1910 "BGP specific commands\n"
1911 "Graceful restart capability parameters\n"
1912 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1913{
d62a17ae 1914 VTY_DECLVAR_CONTEXT(bgp, bgp);
1915 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1916 return CMD_SUCCESS;
43fc21b3
JC
1917}
1918
7f323236
DW
1919static void bgp_redistribute_redo(struct bgp *bgp)
1920{
1921 afi_t afi;
1922 int i;
1923 struct list *red_list;
1924 struct listnode *node;
1925 struct bgp_redist *red;
1926
a4d82a8a
PZ
1927 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1928 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 1929
a4d82a8a
PZ
1930 red_list = bgp->redist[afi][i];
1931 if (!red_list)
1932 continue;
7f323236 1933
a4d82a8a 1934 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
1935 bgp_redistribute_resend(bgp, afi, i,
1936 red->instance);
1937 }
1938 }
1939 }
1940}
1941
1942/* "bgp graceful-shutdown" configuration */
1943DEFUN (bgp_graceful_shutdown,
1944 bgp_graceful_shutdown_cmd,
1945 "bgp graceful-shutdown",
1946 BGP_STR
1947 "Graceful shutdown parameters\n")
1948{
1949 VTY_DECLVAR_CONTEXT(bgp, bgp);
1950
1951 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1952 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1953 bgp_static_redo_import_check(bgp);
1954 bgp_redistribute_redo(bgp);
1955 bgp_clear_star_soft_out(vty, bgp->name);
1956 bgp_clear_star_soft_in(vty, bgp->name);
1957 }
1958
1959 return CMD_SUCCESS;
1960}
1961
1962DEFUN (no_bgp_graceful_shutdown,
1963 no_bgp_graceful_shutdown_cmd,
1964 "no bgp graceful-shutdown",
1965 NO_STR
1966 BGP_STR
1967 "Graceful shutdown parameters\n")
1968{
1969 VTY_DECLVAR_CONTEXT(bgp, bgp);
1970
1971 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1972 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1973 bgp_static_redo_import_check(bgp);
1974 bgp_redistribute_redo(bgp);
1975 bgp_clear_star_soft_out(vty, bgp->name);
1976 bgp_clear_star_soft_in(vty, bgp->name);
1977 }
1978
1979 return CMD_SUCCESS;
1980}
1981
718e3744 1982/* "bgp fast-external-failover" configuration. */
1983DEFUN (bgp_fast_external_failover,
1984 bgp_fast_external_failover_cmd,
1985 "bgp fast-external-failover",
1986 BGP_STR
1987 "Immediately reset session if a link to a directly connected external peer goes down\n")
1988{
d62a17ae 1989 VTY_DECLVAR_CONTEXT(bgp, bgp);
1990 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1991 return CMD_SUCCESS;
718e3744 1992}
1993
1994DEFUN (no_bgp_fast_external_failover,
1995 no_bgp_fast_external_failover_cmd,
1996 "no bgp fast-external-failover",
1997 NO_STR
1998 BGP_STR
1999 "Immediately reset session if a link to a directly connected external peer goes down\n")
2000{
d62a17ae 2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
2002 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2003 return CMD_SUCCESS;
718e3744 2004}
6b0655a2 2005
718e3744 2006/* "bgp enforce-first-as" configuration. */
47cbc09b
PM
2007#if defined(VERSION_TYPE_DEV) && CONFDATE > 20180517
2008CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2009#endif
2010
2011DEFUN_DEPRECATED (bgp_enforce_first_as,
718e3744 2012 bgp_enforce_first_as_cmd,
2013 "bgp enforce-first-as",
2014 BGP_STR
2015 "Enforce the first AS for EBGP routes\n")
2016{
d62a17ae 2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
2018 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
7aafcaca 2019
d62a17ae 2020 return CMD_SUCCESS;
718e3744 2021}
2022
47cbc09b 2023DEFUN_DEPRECATED (no_bgp_enforce_first_as,
718e3744 2024 no_bgp_enforce_first_as_cmd,
2025 "no bgp enforce-first-as",
2026 NO_STR
2027 BGP_STR
2028 "Enforce the first AS for EBGP routes\n")
2029{
d62a17ae 2030 VTY_DECLVAR_CONTEXT(bgp, bgp);
2031 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
7aafcaca 2032
d62a17ae 2033 return CMD_SUCCESS;
718e3744 2034}
6b0655a2 2035
718e3744 2036/* "bgp bestpath compare-routerid" configuration. */
2037DEFUN (bgp_bestpath_compare_router_id,
2038 bgp_bestpath_compare_router_id_cmd,
2039 "bgp bestpath compare-routerid",
2040 "BGP specific commands\n"
2041 "Change the default bestpath selection\n"
2042 "Compare router-id for identical EBGP paths\n")
2043{
d62a17ae 2044 VTY_DECLVAR_CONTEXT(bgp, bgp);
2045 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2046 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2047
d62a17ae 2048 return CMD_SUCCESS;
718e3744 2049}
2050
2051DEFUN (no_bgp_bestpath_compare_router_id,
2052 no_bgp_bestpath_compare_router_id_cmd,
2053 "no bgp bestpath compare-routerid",
2054 NO_STR
2055 "BGP specific commands\n"
2056 "Change the default bestpath selection\n"
2057 "Compare router-id for identical EBGP paths\n")
2058{
d62a17ae 2059 VTY_DECLVAR_CONTEXT(bgp, bgp);
2060 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2061 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2062
d62a17ae 2063 return CMD_SUCCESS;
718e3744 2064}
6b0655a2 2065
718e3744 2066/* "bgp bestpath as-path ignore" configuration. */
2067DEFUN (bgp_bestpath_aspath_ignore,
2068 bgp_bestpath_aspath_ignore_cmd,
2069 "bgp bestpath as-path ignore",
2070 "BGP specific commands\n"
2071 "Change the default bestpath selection\n"
2072 "AS-path attribute\n"
2073 "Ignore as-path length in selecting a route\n")
2074{
d62a17ae 2075 VTY_DECLVAR_CONTEXT(bgp, bgp);
2076 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2077 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2078
d62a17ae 2079 return CMD_SUCCESS;
718e3744 2080}
2081
2082DEFUN (no_bgp_bestpath_aspath_ignore,
2083 no_bgp_bestpath_aspath_ignore_cmd,
2084 "no bgp bestpath as-path ignore",
2085 NO_STR
2086 "BGP specific commands\n"
2087 "Change the default bestpath selection\n"
2088 "AS-path attribute\n"
2089 "Ignore as-path length in selecting a route\n")
2090{
d62a17ae 2091 VTY_DECLVAR_CONTEXT(bgp, bgp);
2092 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2093 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2094
d62a17ae 2095 return CMD_SUCCESS;
718e3744 2096}
6b0655a2 2097
6811845b 2098/* "bgp bestpath as-path confed" configuration. */
2099DEFUN (bgp_bestpath_aspath_confed,
2100 bgp_bestpath_aspath_confed_cmd,
2101 "bgp bestpath as-path confed",
2102 "BGP specific commands\n"
2103 "Change the default bestpath selection\n"
2104 "AS-path attribute\n"
2105 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2106{
d62a17ae 2107 VTY_DECLVAR_CONTEXT(bgp, bgp);
2108 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2109 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2110
d62a17ae 2111 return CMD_SUCCESS;
6811845b 2112}
2113
2114DEFUN (no_bgp_bestpath_aspath_confed,
2115 no_bgp_bestpath_aspath_confed_cmd,
2116 "no bgp bestpath as-path confed",
2117 NO_STR
2118 "BGP specific commands\n"
2119 "Change the default bestpath selection\n"
2120 "AS-path attribute\n"
2121 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2122{
d62a17ae 2123 VTY_DECLVAR_CONTEXT(bgp, bgp);
2124 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2125 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2126
d62a17ae 2127 return CMD_SUCCESS;
6811845b 2128}
6b0655a2 2129
2fdd455c
PM
2130/* "bgp bestpath as-path multipath-relax" configuration. */
2131DEFUN (bgp_bestpath_aspath_multipath_relax,
2132 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2133 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2134 "BGP specific commands\n"
2135 "Change the default bestpath selection\n"
2136 "AS-path attribute\n"
2137 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2138 "Generate an AS_SET\n"
16fc1eec
DS
2139 "Do not generate an AS_SET\n")
2140{
d62a17ae 2141 VTY_DECLVAR_CONTEXT(bgp, bgp);
2142 int idx = 0;
2143 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2144
d62a17ae 2145 /* no-as-set is now the default behavior so we can silently
2146 * ignore it */
2147 if (argv_find(argv, argc, "as-set", &idx))
2148 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2149 else
2150 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2151
d62a17ae 2152 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2153
d62a17ae 2154 return CMD_SUCCESS;
16fc1eec
DS
2155}
2156
219178b6
DW
2157DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2158 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2159 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2160 NO_STR
2161 "BGP specific commands\n"
2162 "Change the default bestpath selection\n"
2163 "AS-path attribute\n"
2164 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2165 "Generate an AS_SET\n"
16fc1eec
DS
2166 "Do not generate an AS_SET\n")
2167{
d62a17ae 2168 VTY_DECLVAR_CONTEXT(bgp, bgp);
2169 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2170 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2171 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2172
d62a17ae 2173 return CMD_SUCCESS;
2fdd455c 2174}
6b0655a2 2175
848973c7 2176/* "bgp log-neighbor-changes" configuration. */
2177DEFUN (bgp_log_neighbor_changes,
2178 bgp_log_neighbor_changes_cmd,
2179 "bgp log-neighbor-changes",
2180 "BGP specific commands\n"
2181 "Log neighbor up/down and reset reason\n")
2182{
d62a17ae 2183 VTY_DECLVAR_CONTEXT(bgp, bgp);
2184 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2185 return CMD_SUCCESS;
848973c7 2186}
2187
2188DEFUN (no_bgp_log_neighbor_changes,
2189 no_bgp_log_neighbor_changes_cmd,
2190 "no bgp log-neighbor-changes",
2191 NO_STR
2192 "BGP specific commands\n"
2193 "Log neighbor up/down and reset reason\n")
2194{
d62a17ae 2195 VTY_DECLVAR_CONTEXT(bgp, bgp);
2196 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2197 return CMD_SUCCESS;
848973c7 2198}
6b0655a2 2199
718e3744 2200/* "bgp bestpath med" configuration. */
2201DEFUN (bgp_bestpath_med,
2202 bgp_bestpath_med_cmd,
2d8c1a4d 2203 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2204 "BGP specific commands\n"
2205 "Change the default bestpath selection\n"
2206 "MED attribute\n"
2207 "Compare MED among confederation paths\n"
838758ac
DW
2208 "Treat missing MED as the least preferred one\n"
2209 "Treat missing MED as the least preferred one\n"
2210 "Compare MED among confederation paths\n")
718e3744 2211{
d62a17ae 2212 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2213
d62a17ae 2214 int idx = 0;
2215 if (argv_find(argv, argc, "confed", &idx))
2216 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2217 idx = 0;
2218 if (argv_find(argv, argc, "missing-as-worst", &idx))
2219 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2220
d62a17ae 2221 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2222
d62a17ae 2223 return CMD_SUCCESS;
718e3744 2224}
2225
718e3744 2226DEFUN (no_bgp_bestpath_med,
2227 no_bgp_bestpath_med_cmd,
2d8c1a4d 2228 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2229 NO_STR
2230 "BGP specific commands\n"
2231 "Change the default bestpath selection\n"
2232 "MED attribute\n"
2233 "Compare MED among confederation paths\n"
3a2d747c
QY
2234 "Treat missing MED as the least preferred one\n"
2235 "Treat missing MED as the least preferred one\n"
2236 "Compare MED among confederation paths\n")
718e3744 2237{
d62a17ae 2238 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2239
d62a17ae 2240 int idx = 0;
2241 if (argv_find(argv, argc, "confed", &idx))
2242 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2243 idx = 0;
2244 if (argv_find(argv, argc, "missing-as-worst", &idx))
2245 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2246
d62a17ae 2247 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2248
d62a17ae 2249 return CMD_SUCCESS;
718e3744 2250}
2251
718e3744 2252/* "no bgp default ipv4-unicast". */
2253DEFUN (no_bgp_default_ipv4_unicast,
2254 no_bgp_default_ipv4_unicast_cmd,
2255 "no bgp default ipv4-unicast",
2256 NO_STR
2257 "BGP specific commands\n"
2258 "Configure BGP defaults\n"
2259 "Activate ipv4-unicast for a peer by default\n")
2260{
d62a17ae 2261 VTY_DECLVAR_CONTEXT(bgp, bgp);
2262 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2263 return CMD_SUCCESS;
718e3744 2264}
2265
2266DEFUN (bgp_default_ipv4_unicast,
2267 bgp_default_ipv4_unicast_cmd,
2268 "bgp default ipv4-unicast",
2269 "BGP specific commands\n"
2270 "Configure BGP defaults\n"
2271 "Activate ipv4-unicast for a peer by default\n")
2272{
d62a17ae 2273 VTY_DECLVAR_CONTEXT(bgp, bgp);
2274 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2275 return CMD_SUCCESS;
718e3744 2276}
6b0655a2 2277
04b6bdc0
DW
2278/* Display hostname in certain command outputs */
2279DEFUN (bgp_default_show_hostname,
2280 bgp_default_show_hostname_cmd,
2281 "bgp default show-hostname",
2282 "BGP specific commands\n"
2283 "Configure BGP defaults\n"
2284 "Show hostname in certain command ouputs\n")
2285{
d62a17ae 2286 VTY_DECLVAR_CONTEXT(bgp, bgp);
2287 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2288 return CMD_SUCCESS;
04b6bdc0
DW
2289}
2290
2291DEFUN (no_bgp_default_show_hostname,
2292 no_bgp_default_show_hostname_cmd,
2293 "no bgp default show-hostname",
2294 NO_STR
2295 "BGP specific commands\n"
2296 "Configure BGP defaults\n"
2297 "Show hostname in certain command ouputs\n")
2298{
d62a17ae 2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2301 return CMD_SUCCESS;
04b6bdc0
DW
2302}
2303
8233ef81 2304/* "bgp network import-check" configuration. */
718e3744 2305DEFUN (bgp_network_import_check,
2306 bgp_network_import_check_cmd,
5623e905 2307 "bgp network import-check",
718e3744 2308 "BGP specific commands\n"
2309 "BGP network command\n"
5623e905 2310 "Check BGP network route exists in IGP\n")
718e3744 2311{
d62a17ae 2312 VTY_DECLVAR_CONTEXT(bgp, bgp);
2313 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2314 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2315 bgp_static_redo_import_check(bgp);
2316 }
078430f6 2317
d62a17ae 2318 return CMD_SUCCESS;
718e3744 2319}
2320
d62a17ae 2321ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2322 "bgp network import-check exact",
2323 "BGP specific commands\n"
2324 "BGP network command\n"
2325 "Check BGP network route exists in IGP\n"
2326 "Match route precisely\n")
8233ef81 2327
718e3744 2328DEFUN (no_bgp_network_import_check,
2329 no_bgp_network_import_check_cmd,
5623e905 2330 "no bgp network import-check",
718e3744 2331 NO_STR
2332 "BGP specific commands\n"
2333 "BGP network command\n"
2334 "Check BGP network route exists in IGP\n")
2335{
d62a17ae 2336 VTY_DECLVAR_CONTEXT(bgp, bgp);
2337 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2338 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2339 bgp_static_redo_import_check(bgp);
2340 }
5623e905 2341
d62a17ae 2342 return CMD_SUCCESS;
718e3744 2343}
6b0655a2 2344
718e3744 2345DEFUN (bgp_default_local_preference,
2346 bgp_default_local_preference_cmd,
6147e2c6 2347 "bgp default local-preference (0-4294967295)",
718e3744 2348 "BGP specific commands\n"
2349 "Configure BGP defaults\n"
2350 "local preference (higher=more preferred)\n"
2351 "Configure default local preference value\n")
2352{
d62a17ae 2353 VTY_DECLVAR_CONTEXT(bgp, bgp);
2354 int idx_number = 3;
d7c0a89a 2355 uint32_t local_pref;
718e3744 2356
d62a17ae 2357 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2358
d62a17ae 2359 bgp_default_local_preference_set(bgp, local_pref);
2360 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2361
d62a17ae 2362 return CMD_SUCCESS;
718e3744 2363}
2364
2365DEFUN (no_bgp_default_local_preference,
2366 no_bgp_default_local_preference_cmd,
838758ac 2367 "no bgp default local-preference [(0-4294967295)]",
718e3744 2368 NO_STR
2369 "BGP specific commands\n"
2370 "Configure BGP defaults\n"
838758ac
DW
2371 "local preference (higher=more preferred)\n"
2372 "Configure default local preference value\n")
718e3744 2373{
d62a17ae 2374 VTY_DECLVAR_CONTEXT(bgp, bgp);
2375 bgp_default_local_preference_unset(bgp);
2376 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2377
d62a17ae 2378 return CMD_SUCCESS;
718e3744 2379}
2380
6b0655a2 2381
3f9c7369
DS
2382DEFUN (bgp_default_subgroup_pkt_queue_max,
2383 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2384 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2385 "BGP specific commands\n"
2386 "Configure BGP defaults\n"
2387 "subgroup-pkt-queue-max\n"
2388 "Configure subgroup packet queue max\n")
8bd9d948 2389{
d62a17ae 2390 VTY_DECLVAR_CONTEXT(bgp, bgp);
2391 int idx_number = 3;
d7c0a89a 2392 uint32_t max_size;
8bd9d948 2393
d62a17ae 2394 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2395
d62a17ae 2396 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2397
d62a17ae 2398 return CMD_SUCCESS;
3f9c7369
DS
2399}
2400
2401DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2402 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2403 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2404 NO_STR
2405 "BGP specific commands\n"
2406 "Configure BGP defaults\n"
838758ac
DW
2407 "subgroup-pkt-queue-max\n"
2408 "Configure subgroup packet queue max\n")
3f9c7369 2409{
d62a17ae 2410 VTY_DECLVAR_CONTEXT(bgp, bgp);
2411 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2412 return CMD_SUCCESS;
8bd9d948
DS
2413}
2414
813d4307 2415
8bd9d948
DS
2416DEFUN (bgp_rr_allow_outbound_policy,
2417 bgp_rr_allow_outbound_policy_cmd,
2418 "bgp route-reflector allow-outbound-policy",
2419 "BGP specific commands\n"
2420 "Allow modifications made by out route-map\n"
2421 "on ibgp neighbors\n")
2422{
d62a17ae 2423 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2424
d62a17ae 2425 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2426 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2427 update_group_announce_rrclients(bgp);
2428 bgp_clear_star_soft_out(vty, bgp->name);
2429 }
8bd9d948 2430
d62a17ae 2431 return CMD_SUCCESS;
8bd9d948
DS
2432}
2433
2434DEFUN (no_bgp_rr_allow_outbound_policy,
2435 no_bgp_rr_allow_outbound_policy_cmd,
2436 "no bgp route-reflector allow-outbound-policy",
2437 NO_STR
2438 "BGP specific commands\n"
2439 "Allow modifications made by out route-map\n"
2440 "on ibgp neighbors\n")
2441{
d62a17ae 2442 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2443
d62a17ae 2444 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2445 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2446 update_group_announce_rrclients(bgp);
2447 bgp_clear_star_soft_out(vty, bgp->name);
2448 }
8bd9d948 2449
d62a17ae 2450 return CMD_SUCCESS;
8bd9d948
DS
2451}
2452
f14e6fdb
DS
2453DEFUN (bgp_listen_limit,
2454 bgp_listen_limit_cmd,
9ccf14f7 2455 "bgp listen limit (1-5000)",
f14e6fdb
DS
2456 "BGP specific commands\n"
2457 "Configure BGP defaults\n"
2458 "maximum number of BGP Dynamic Neighbors that can be created\n"
2459 "Configure Dynamic Neighbors listen limit value\n")
2460{
d62a17ae 2461 VTY_DECLVAR_CONTEXT(bgp, bgp);
2462 int idx_number = 3;
2463 int listen_limit;
f14e6fdb 2464
d62a17ae 2465 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2466
d62a17ae 2467 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2468
d62a17ae 2469 return CMD_SUCCESS;
f14e6fdb
DS
2470}
2471
2472DEFUN (no_bgp_listen_limit,
2473 no_bgp_listen_limit_cmd,
838758ac 2474 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2475 "BGP specific commands\n"
2476 "Configure BGP defaults\n"
2477 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2478 "Configure Dynamic Neighbors listen limit value to default\n"
2479 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2480{
d62a17ae 2481 VTY_DECLVAR_CONTEXT(bgp, bgp);
2482 bgp_listen_limit_unset(bgp);
2483 return CMD_SUCCESS;
f14e6fdb
DS
2484}
2485
2486
20eb8864 2487/*
2488 * Check if this listen range is already configured. Check for exact
2489 * match or overlap based on input.
2490 */
d62a17ae 2491static struct peer_group *listen_range_exists(struct bgp *bgp,
2492 struct prefix *range, int exact)
2493{
2494 struct listnode *node, *nnode;
2495 struct listnode *node1, *nnode1;
2496 struct peer_group *group;
2497 struct prefix *lr;
2498 afi_t afi;
2499 int match;
2500
2501 afi = family2afi(range->family);
2502 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2503 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2504 lr)) {
2505 if (exact)
2506 match = prefix_same(range, lr);
2507 else
2508 match = (prefix_match(range, lr)
2509 || prefix_match(lr, range));
2510 if (match)
2511 return group;
2512 }
2513 }
2514
2515 return NULL;
20eb8864 2516}
2517
f14e6fdb
DS
2518DEFUN (bgp_listen_range,
2519 bgp_listen_range_cmd,
9ccf14f7 2520 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2521 "BGP specific commands\n"
d7fa34c1
QY
2522 "Configure BGP dynamic neighbors listen range\n"
2523 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2524 NEIGHBOR_ADDR_STR
2525 "Member of the peer-group\n"
2526 "Peer-group name\n")
f14e6fdb 2527{
d62a17ae 2528 VTY_DECLVAR_CONTEXT(bgp, bgp);
2529 struct prefix range;
2530 struct peer_group *group, *existing_group;
2531 afi_t afi;
2532 int ret;
2533 int idx = 0;
2534
2535 argv_find(argv, argc, "A.B.C.D/M", &idx);
2536 argv_find(argv, argc, "X:X::X:X/M", &idx);
2537 char *prefix = argv[idx]->arg;
2538 argv_find(argv, argc, "WORD", &idx);
2539 char *peergroup = argv[idx]->arg;
2540
2541 /* Convert IP prefix string to struct prefix. */
2542 ret = str2prefix(prefix, &range);
2543 if (!ret) {
2544 vty_out(vty, "%% Malformed listen range\n");
2545 return CMD_WARNING_CONFIG_FAILED;
2546 }
2547
2548 afi = family2afi(range.family);
2549
2550 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2551 vty_out(vty,
2552 "%% Malformed listen range (link-local address)\n");
2553 return CMD_WARNING_CONFIG_FAILED;
2554 }
2555
2556 apply_mask(&range);
2557
2558 /* Check if same listen range is already configured. */
2559 existing_group = listen_range_exists(bgp, &range, 1);
2560 if (existing_group) {
2561 if (strcmp(existing_group->name, peergroup) == 0)
2562 return CMD_SUCCESS;
2563 else {
2564 vty_out(vty,
2565 "%% Same listen range is attached to peer-group %s\n",
2566 existing_group->name);
2567 return CMD_WARNING_CONFIG_FAILED;
2568 }
2569 }
2570
2571 /* Check if an overlapping listen range exists. */
2572 if (listen_range_exists(bgp, &range, 0)) {
2573 vty_out(vty,
2574 "%% Listen range overlaps with existing listen range\n");
2575 return CMD_WARNING_CONFIG_FAILED;
2576 }
2577
2578 group = peer_group_lookup(bgp, peergroup);
2579 if (!group) {
2580 vty_out(vty, "%% Configure the peer-group first\n");
2581 return CMD_WARNING_CONFIG_FAILED;
2582 }
2583
2584 ret = peer_group_listen_range_add(group, &range);
2585 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2586}
2587
2588DEFUN (no_bgp_listen_range,
2589 no_bgp_listen_range_cmd,
d7fa34c1
QY
2590 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2591 NO_STR
f14e6fdb 2592 "BGP specific commands\n"
d7fa34c1
QY
2593 "Unconfigure BGP dynamic neighbors listen range\n"
2594 "Unconfigure BGP dynamic neighbors listen range\n"
2595 NEIGHBOR_ADDR_STR
2596 "Member of the peer-group\n"
2597 "Peer-group name\n")
f14e6fdb 2598{
d62a17ae 2599 VTY_DECLVAR_CONTEXT(bgp, bgp);
2600 struct prefix range;
2601 struct peer_group *group;
2602 afi_t afi;
2603 int ret;
2604 int idx = 0;
2605
2606 argv_find(argv, argc, "A.B.C.D/M", &idx);
2607 argv_find(argv, argc, "X:X::X:X/M", &idx);
2608 char *prefix = argv[idx]->arg;
2609 argv_find(argv, argc, "WORD", &idx);
2610 char *peergroup = argv[idx]->arg;
2611
2612 /* Convert IP prefix string to struct prefix. */
2613 ret = str2prefix(prefix, &range);
2614 if (!ret) {
2615 vty_out(vty, "%% Malformed listen range\n");
2616 return CMD_WARNING_CONFIG_FAILED;
2617 }
2618
2619 afi = family2afi(range.family);
2620
2621 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2622 vty_out(vty,
2623 "%% Malformed listen range (link-local address)\n");
2624 return CMD_WARNING_CONFIG_FAILED;
2625 }
2626
2627 apply_mask(&range);
2628
2629 group = peer_group_lookup(bgp, peergroup);
2630 if (!group) {
2631 vty_out(vty, "%% Peer-group does not exist\n");
2632 return CMD_WARNING_CONFIG_FAILED;
2633 }
2634
2635 ret = peer_group_listen_range_del(group, &range);
2636 return bgp_vty_return(vty, ret);
2637}
2638
2b791107 2639void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2640{
2641 struct peer_group *group;
2642 struct listnode *node, *nnode, *rnode, *nrnode;
2643 struct prefix *range;
2644 afi_t afi;
2645 char buf[PREFIX2STR_BUFFER];
2646
2647 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2648 vty_out(vty, " bgp listen limit %d\n",
2649 bgp->dynamic_neighbors_limit);
2650
2651 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2652 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2653 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2654 nrnode, range)) {
2655 prefix2str(range, buf, sizeof(buf));
2656 vty_out(vty,
2657 " bgp listen range %s peer-group %s\n",
2658 buf, group->name);
2659 }
2660 }
2661 }
f14e6fdb
DS
2662}
2663
2664
907f92c8
DS
2665DEFUN (bgp_disable_connected_route_check,
2666 bgp_disable_connected_route_check_cmd,
2667 "bgp disable-ebgp-connected-route-check",
2668 "BGP specific commands\n"
2669 "Disable checking if nexthop is connected on ebgp sessions\n")
2670{
d62a17ae 2671 VTY_DECLVAR_CONTEXT(bgp, bgp);
2672 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2673 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2674
d62a17ae 2675 return CMD_SUCCESS;
907f92c8
DS
2676}
2677
2678DEFUN (no_bgp_disable_connected_route_check,
2679 no_bgp_disable_connected_route_check_cmd,
2680 "no bgp disable-ebgp-connected-route-check",
2681 NO_STR
2682 "BGP specific commands\n"
2683 "Disable checking if nexthop is connected on ebgp sessions\n")
2684{
d62a17ae 2685 VTY_DECLVAR_CONTEXT(bgp, bgp);
2686 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2687 bgp_clear_star_soft_in(vty, bgp->name);
2688
2689 return CMD_SUCCESS;
2690}
2691
2692
2693static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2694 const char *as_str, afi_t afi, safi_t safi)
2695{
2696 VTY_DECLVAR_CONTEXT(bgp, bgp);
2697 int ret;
2698 as_t as;
2699 int as_type = AS_SPECIFIED;
2700 union sockunion su;
2701
2702 if (as_str[0] == 'i') {
2703 as = 0;
2704 as_type = AS_INTERNAL;
2705 } else if (as_str[0] == 'e') {
2706 as = 0;
2707 as_type = AS_EXTERNAL;
2708 } else {
2709 /* Get AS number. */
2710 as = strtoul(as_str, NULL, 10);
2711 }
2712
2713 /* If peer is peer group, call proper function. */
2714 ret = str2sockunion(peer_str, &su);
2715 if (ret < 0) {
2716 /* Check for peer by interface */
2717 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2718 safi);
2719 if (ret < 0) {
2720 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2721 if (ret < 0) {
2722 vty_out(vty,
2723 "%% Create the peer-group or interface first\n");
2724 return CMD_WARNING_CONFIG_FAILED;
2725 }
2726 return CMD_SUCCESS;
2727 }
2728 } else {
2729 if (peer_address_self_check(bgp, &su)) {
2730 vty_out(vty,
2731 "%% Can not configure the local system as neighbor\n");
2732 return CMD_WARNING_CONFIG_FAILED;
2733 }
2734 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2735 }
2736
2737 /* This peer belongs to peer group. */
2738 switch (ret) {
2739 case BGP_ERR_PEER_GROUP_MEMBER:
2740 vty_out(vty,
2741 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2742 as);
2743 return CMD_WARNING_CONFIG_FAILED;
2744 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2745 vty_out(vty,
2746 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2747 as, as_str);
2748 return CMD_WARNING_CONFIG_FAILED;
2749 }
2750 return bgp_vty_return(vty, ret);
718e3744 2751}
2752
f26845f9
QY
2753DEFUN (bgp_default_shutdown,
2754 bgp_default_shutdown_cmd,
2755 "[no] bgp default shutdown",
2756 NO_STR
2757 BGP_STR
2758 "Configure BGP defaults\n"
b012cbe2 2759 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2760{
2761 VTY_DECLVAR_CONTEXT(bgp, bgp);
2762 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2763 return CMD_SUCCESS;
2764}
2765
718e3744 2766DEFUN (neighbor_remote_as,
2767 neighbor_remote_as_cmd,
3a2d747c 2768 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2769 NEIGHBOR_STR
2770 NEIGHBOR_ADDR_STR2
2771 "Specify a BGP neighbor\n"
d7fa34c1 2772 AS_STR
3a2d747c
QY
2773 "Internal BGP peer\n"
2774 "External BGP peer\n")
718e3744 2775{
d62a17ae 2776 int idx_peer = 1;
2777 int idx_remote_as = 3;
2778 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2779 argv[idx_remote_as]->arg, AFI_IP,
2780 SAFI_UNICAST);
2781}
2782
2783static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2784 afi_t afi, safi_t safi, int v6only,
2785 const char *peer_group_name,
2786 const char *as_str)
2787{
2788 VTY_DECLVAR_CONTEXT(bgp, bgp);
2789 as_t as = 0;
2790 int as_type = AS_UNSPECIFIED;
2791 struct peer *peer;
2792 struct peer_group *group;
2793 int ret = 0;
2794 union sockunion su;
2795
2796 group = peer_group_lookup(bgp, conf_if);
2797
2798 if (group) {
2799 vty_out(vty, "%% Name conflict with peer-group \n");
2800 return CMD_WARNING_CONFIG_FAILED;
2801 }
2802
2803 if (as_str) {
2804 if (as_str[0] == 'i') {
2805 as_type = AS_INTERNAL;
2806 } else if (as_str[0] == 'e') {
2807 as_type = AS_EXTERNAL;
2808 } else {
2809 /* Get AS number. */
2810 as = strtoul(as_str, NULL, 10);
2811 as_type = AS_SPECIFIED;
2812 }
2813 }
2814
2815 peer = peer_lookup_by_conf_if(bgp, conf_if);
2816 if (peer) {
2817 if (as_str)
2818 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2819 afi, safi);
2820 } else {
2821 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2822 && afi == AFI_IP && safi == SAFI_UNICAST)
2823 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2824 as_type, 0, 0, NULL);
2825 else
2826 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2827 as_type, afi, safi, NULL);
2828
2829 if (!peer) {
2830 vty_out(vty, "%% BGP failed to create peer\n");
2831 return CMD_WARNING_CONFIG_FAILED;
2832 }
2833
2834 if (v6only)
2835 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2836
2837 /* Request zebra to initiate IPv6 RAs on this interface. We do
2838 * this
2839 * any unnumbered peer in order to not worry about run-time
2840 * transitions
2841 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2842 * address
2843 * gets deleted later etc.)
2844 */
2845 if (peer->ifp)
2846 bgp_zebra_initiate_radv(bgp, peer);
2847 }
2848
2849 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2850 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2851 if (v6only)
2852 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2853 else
2854 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2855
2856 /* v6only flag changed. Reset bgp seesion */
2857 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2858 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2859 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2860 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2861 } else
2862 bgp_session_reset(peer);
2863 }
2864
2865 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2866 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2867
2868 if (peer_group_name) {
2869 group = peer_group_lookup(bgp, peer_group_name);
2870 if (!group) {
2871 vty_out(vty, "%% Configure the peer-group first\n");
2872 return CMD_WARNING_CONFIG_FAILED;
2873 }
2874
2875 ret = peer_group_bind(bgp, &su, peer, group, &as);
2876 }
2877
2878 return bgp_vty_return(vty, ret);
a80beece
DS
2879}
2880
4c48cf63
DW
2881DEFUN (neighbor_interface_config,
2882 neighbor_interface_config_cmd,
31500417 2883 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2884 NEIGHBOR_STR
2885 "Interface name or neighbor tag\n"
31500417
DW
2886 "Enable BGP on interface\n"
2887 "Member of the peer-group\n"
16cedbb0 2888 "Peer-group name\n")
4c48cf63 2889{
d62a17ae 2890 int idx_word = 1;
2891 int idx_peer_group_word = 4;
31500417 2892
d62a17ae 2893 if (argc > idx_peer_group_word)
2894 return peer_conf_interface_get(
2895 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2896 argv[idx_peer_group_word]->arg, NULL);
2897 else
2898 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2899 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2900}
2901
4c48cf63
DW
2902DEFUN (neighbor_interface_config_v6only,
2903 neighbor_interface_config_v6only_cmd,
31500417 2904 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2905 NEIGHBOR_STR
2906 "Interface name or neighbor tag\n"
2907 "Enable BGP on interface\n"
31500417
DW
2908 "Enable BGP with v6 link-local only\n"
2909 "Member of the peer-group\n"
16cedbb0 2910 "Peer-group name\n")
4c48cf63 2911{
d62a17ae 2912 int idx_word = 1;
2913 int idx_peer_group_word = 5;
31500417 2914
d62a17ae 2915 if (argc > idx_peer_group_word)
2916 return peer_conf_interface_get(
2917 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2918 argv[idx_peer_group_word]->arg, NULL);
31500417 2919
d62a17ae 2920 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2921 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2922}
2923
a80beece 2924
b3a39dc5
DD
2925DEFUN (neighbor_interface_config_remote_as,
2926 neighbor_interface_config_remote_as_cmd,
3a2d747c 2927 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2928 NEIGHBOR_STR
2929 "Interface name or neighbor tag\n"
2930 "Enable BGP on interface\n"
3a2d747c 2931 "Specify a BGP neighbor\n"
d7fa34c1 2932 AS_STR
3a2d747c
QY
2933 "Internal BGP peer\n"
2934 "External BGP peer\n")
b3a39dc5 2935{
d62a17ae 2936 int idx_word = 1;
2937 int idx_remote_as = 4;
2938 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2939 SAFI_UNICAST, 0, NULL,
2940 argv[idx_remote_as]->arg);
b3a39dc5
DD
2941}
2942
2943DEFUN (neighbor_interface_v6only_config_remote_as,
2944 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2945 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2946 NEIGHBOR_STR
2947 "Interface name or neighbor tag\n"
3a2d747c 2948 "Enable BGP with v6 link-local only\n"
b3a39dc5 2949 "Enable BGP on interface\n"
3a2d747c 2950 "Specify a BGP neighbor\n"
d7fa34c1 2951 AS_STR
3a2d747c
QY
2952 "Internal BGP peer\n"
2953 "External BGP peer\n")
b3a39dc5 2954{
d62a17ae 2955 int idx_word = 1;
2956 int idx_remote_as = 5;
2957 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2958 SAFI_UNICAST, 1, NULL,
2959 argv[idx_remote_as]->arg);
b3a39dc5
DD
2960}
2961
718e3744 2962DEFUN (neighbor_peer_group,
2963 neighbor_peer_group_cmd,
2964 "neighbor WORD peer-group",
2965 NEIGHBOR_STR
a80beece 2966 "Interface name or neighbor tag\n"
718e3744 2967 "Configure peer-group\n")
2968{
d62a17ae 2969 VTY_DECLVAR_CONTEXT(bgp, bgp);
2970 int idx_word = 1;
2971 struct peer *peer;
2972 struct peer_group *group;
718e3744 2973
d62a17ae 2974 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2975 if (peer) {
2976 vty_out(vty, "%% Name conflict with interface: \n");
2977 return CMD_WARNING_CONFIG_FAILED;
2978 }
718e3744 2979
d62a17ae 2980 group = peer_group_get(bgp, argv[idx_word]->arg);
2981 if (!group) {
2982 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2983 return CMD_WARNING_CONFIG_FAILED;
2984 }
718e3744 2985
d62a17ae 2986 return CMD_SUCCESS;
718e3744 2987}
2988
2989DEFUN (no_neighbor,
2990 no_neighbor_cmd,
dab8cd00 2991 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 2992 NO_STR
2993 NEIGHBOR_STR
3a2d747c
QY
2994 NEIGHBOR_ADDR_STR2
2995 "Specify a BGP neighbor\n"
2996 AS_STR
2997 "Internal BGP peer\n"
2998 "External BGP peer\n")
718e3744 2999{
d62a17ae 3000 VTY_DECLVAR_CONTEXT(bgp, bgp);
3001 int idx_peer = 2;
3002 int ret;
3003 union sockunion su;
3004 struct peer_group *group;
3005 struct peer *peer;
3006 struct peer *other;
3007
3008 ret = str2sockunion(argv[idx_peer]->arg, &su);
3009 if (ret < 0) {
3010 /* look up for neighbor by interface name config. */
3011 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3012 if (peer) {
3013 /* Request zebra to terminate IPv6 RAs on this
3014 * interface. */
3015 if (peer->ifp)
3016 bgp_zebra_terminate_radv(peer->bgp, peer);
3017 peer_delete(peer);
3018 return CMD_SUCCESS;
3019 }
f14e6fdb 3020
d62a17ae 3021 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3022 if (group)
3023 peer_group_delete(group);
3024 else {
3025 vty_out(vty, "%% Create the peer-group first\n");
3026 return CMD_WARNING_CONFIG_FAILED;
3027 }
3028 } else {
3029 peer = peer_lookup(bgp, &su);
3030 if (peer) {
3031 if (peer_dynamic_neighbor(peer)) {
3032 vty_out(vty,
3033 "%% Operation not allowed on a dynamic neighbor\n");
3034 return CMD_WARNING_CONFIG_FAILED;
3035 }
3036
3037 other = peer->doppelganger;
3038 peer_delete(peer);
3039 if (other && other->status != Deleted)
3040 peer_delete(other);
3041 }
1ff9a340 3042 }
718e3744 3043
d62a17ae 3044 return CMD_SUCCESS;
718e3744 3045}
3046
a80beece
DS
3047DEFUN (no_neighbor_interface_config,
3048 no_neighbor_interface_config_cmd,
31500417 3049 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3050 NO_STR
3051 NEIGHBOR_STR
3052 "Interface name\n"
31500417
DW
3053 "Configure BGP on interface\n"
3054 "Enable BGP with v6 link-local only\n"
3055 "Member of the peer-group\n"
16cedbb0 3056 "Peer-group name\n"
3a2d747c
QY
3057 "Specify a BGP neighbor\n"
3058 AS_STR
3059 "Internal BGP peer\n"
3060 "External BGP peer\n")
a80beece 3061{
d62a17ae 3062 VTY_DECLVAR_CONTEXT(bgp, bgp);
3063 int idx_word = 2;
3064 struct peer *peer;
3065
3066 /* look up for neighbor by interface name config. */
3067 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3068 if (peer) {
3069 /* Request zebra to terminate IPv6 RAs on this interface. */
3070 if (peer->ifp)
3071 bgp_zebra_terminate_radv(peer->bgp, peer);
3072 peer_delete(peer);
3073 } else {
3074 vty_out(vty, "%% Create the bgp interface first\n");
3075 return CMD_WARNING_CONFIG_FAILED;
3076 }
3077 return CMD_SUCCESS;
a80beece
DS
3078}
3079
718e3744 3080DEFUN (no_neighbor_peer_group,
3081 no_neighbor_peer_group_cmd,
3082 "no neighbor WORD peer-group",
3083 NO_STR
3084 NEIGHBOR_STR
3085 "Neighbor tag\n"
3086 "Configure peer-group\n")
3087{
d62a17ae 3088 VTY_DECLVAR_CONTEXT(bgp, bgp);
3089 int idx_word = 2;
3090 struct peer_group *group;
718e3744 3091
d62a17ae 3092 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3093 if (group)
3094 peer_group_delete(group);
3095 else {
3096 vty_out(vty, "%% Create the peer-group first\n");
3097 return CMD_WARNING_CONFIG_FAILED;
3098 }
3099 return CMD_SUCCESS;
718e3744 3100}
3101
a80beece
DS
3102DEFUN (no_neighbor_interface_peer_group_remote_as,
3103 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3104 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3105 NO_STR
3106 NEIGHBOR_STR
a80beece 3107 "Interface name or neighbor tag\n"
718e3744 3108 "Specify a BGP neighbor\n"
3a2d747c
QY
3109 AS_STR
3110 "Internal BGP peer\n"
3111 "External BGP peer\n")
718e3744 3112{
d62a17ae 3113 VTY_DECLVAR_CONTEXT(bgp, bgp);
3114 int idx_word = 2;
3115 struct peer_group *group;
3116 struct peer *peer;
3117
3118 /* look up for neighbor by interface name config. */
3119 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3120 if (peer) {
3121 peer_as_change(peer, 0, AS_SPECIFIED);
3122 return CMD_SUCCESS;
3123 }
3124
3125 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3126 if (group)
3127 peer_group_remote_as_delete(group);
3128 else {
3129 vty_out(vty, "%% Create the peer-group or interface first\n");
3130 return CMD_WARNING_CONFIG_FAILED;
3131 }
3132 return CMD_SUCCESS;
718e3744 3133}
6b0655a2 3134
718e3744 3135DEFUN (neighbor_local_as,
3136 neighbor_local_as_cmd,
9ccf14f7 3137 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3138 NEIGHBOR_STR
3139 NEIGHBOR_ADDR_STR2
3140 "Specify a local-as number\n"
3141 "AS number used as local AS\n")
3142{
d62a17ae 3143 int idx_peer = 1;
3144 int idx_number = 3;
3145 struct peer *peer;
3146 int ret;
3147 as_t as;
718e3744 3148
d62a17ae 3149 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3150 if (!peer)
3151 return CMD_WARNING_CONFIG_FAILED;
718e3744 3152
d62a17ae 3153 as = strtoul(argv[idx_number]->arg, NULL, 10);
3154 ret = peer_local_as_set(peer, as, 0, 0);
3155 return bgp_vty_return(vty, ret);
718e3744 3156}
3157
3158DEFUN (neighbor_local_as_no_prepend,
3159 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3160 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3161 NEIGHBOR_STR
3162 NEIGHBOR_ADDR_STR2
3163 "Specify a local-as number\n"
3164 "AS number used as local AS\n"
3165 "Do not prepend local-as to updates from ebgp peers\n")
3166{
d62a17ae 3167 int idx_peer = 1;
3168 int idx_number = 3;
3169 struct peer *peer;
3170 int ret;
3171 as_t as;
718e3744 3172
d62a17ae 3173 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3174 if (!peer)
3175 return CMD_WARNING_CONFIG_FAILED;
718e3744 3176
d62a17ae 3177 as = strtoul(argv[idx_number]->arg, NULL, 10);
3178 ret = peer_local_as_set(peer, as, 1, 0);
3179 return bgp_vty_return(vty, ret);
718e3744 3180}
3181
9d3f9705
AC
3182DEFUN (neighbor_local_as_no_prepend_replace_as,
3183 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3184 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3185 NEIGHBOR_STR
3186 NEIGHBOR_ADDR_STR2
3187 "Specify a local-as number\n"
3188 "AS number used as local AS\n"
3189 "Do not prepend local-as to updates from ebgp peers\n"
3190 "Do not prepend local-as to updates from ibgp peers\n")
3191{
d62a17ae 3192 int idx_peer = 1;
3193 int idx_number = 3;
3194 struct peer *peer;
3195 int ret;
3196 as_t as;
9d3f9705 3197
d62a17ae 3198 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3199 if (!peer)
3200 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3201
d62a17ae 3202 as = strtoul(argv[idx_number]->arg, NULL, 10);
3203 ret = peer_local_as_set(peer, as, 1, 1);
3204 return bgp_vty_return(vty, ret);
9d3f9705
AC
3205}
3206
718e3744 3207DEFUN (no_neighbor_local_as,
3208 no_neighbor_local_as_cmd,
a636c635 3209 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3210 NO_STR
3211 NEIGHBOR_STR
3212 NEIGHBOR_ADDR_STR2
a636c635
DW
3213 "Specify a local-as number\n"
3214 "AS number used as local AS\n"
3215 "Do not prepend local-as to updates from ebgp peers\n"
3216 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3217{
d62a17ae 3218 int idx_peer = 2;
3219 struct peer *peer;
3220 int ret;
718e3744 3221
d62a17ae 3222 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3223 if (!peer)
3224 return CMD_WARNING_CONFIG_FAILED;
718e3744 3225
d62a17ae 3226 ret = peer_local_as_unset(peer);
3227 return bgp_vty_return(vty, ret);
718e3744 3228}
3229
718e3744 3230
3f9c7369
DS
3231DEFUN (neighbor_solo,
3232 neighbor_solo_cmd,
9ccf14f7 3233 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3234 NEIGHBOR_STR
3235 NEIGHBOR_ADDR_STR2
3236 "Solo peer - part of its own update group\n")
3237{
d62a17ae 3238 int idx_peer = 1;
3239 struct peer *peer;
3240 int ret;
3f9c7369 3241
d62a17ae 3242 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3243 if (!peer)
3244 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3245
d62a17ae 3246 ret = update_group_adjust_soloness(peer, 1);
3247 return bgp_vty_return(vty, ret);
3f9c7369
DS
3248}
3249
3250DEFUN (no_neighbor_solo,
3251 no_neighbor_solo_cmd,
9ccf14f7 3252 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3253 NO_STR
3254 NEIGHBOR_STR
3255 NEIGHBOR_ADDR_STR2
3256 "Solo peer - part of its own update group\n")
3257{
d62a17ae 3258 int idx_peer = 2;
3259 struct peer *peer;
3260 int ret;
3f9c7369 3261
d62a17ae 3262 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3263 if (!peer)
3264 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3265
d62a17ae 3266 ret = update_group_adjust_soloness(peer, 0);
3267 return bgp_vty_return(vty, ret);
3f9c7369
DS
3268}
3269
0df7c91f
PJ
3270DEFUN (neighbor_password,
3271 neighbor_password_cmd,
9ccf14f7 3272 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3273 NEIGHBOR_STR
3274 NEIGHBOR_ADDR_STR2
3275 "Set a password\n"
3276 "The password\n")
3277{
d62a17ae 3278 int idx_peer = 1;
3279 int idx_line = 3;
3280 struct peer *peer;
3281 int ret;
0df7c91f 3282
d62a17ae 3283 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3284 if (!peer)
3285 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3286
d62a17ae 3287 ret = peer_password_set(peer, argv[idx_line]->arg);
3288 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3289}
3290
3291DEFUN (no_neighbor_password,
3292 no_neighbor_password_cmd,
a636c635 3293 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3294 NO_STR
3295 NEIGHBOR_STR
3296 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3297 "Set a password\n"
3298 "The password\n")
0df7c91f 3299{
d62a17ae 3300 int idx_peer = 2;
3301 struct peer *peer;
3302 int ret;
0df7c91f 3303
d62a17ae 3304 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3305 if (!peer)
3306 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3307
d62a17ae 3308 ret = peer_password_unset(peer);
3309 return bgp_vty_return(vty, ret);
0df7c91f 3310}
6b0655a2 3311
718e3744 3312DEFUN (neighbor_activate,
3313 neighbor_activate_cmd,
9ccf14f7 3314 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3315 NEIGHBOR_STR
3316 NEIGHBOR_ADDR_STR2
3317 "Enable the Address Family for this Neighbor\n")
3318{
d62a17ae 3319 int idx_peer = 1;
3320 int ret;
3321 struct peer *peer;
718e3744 3322
d62a17ae 3323 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3324 if (!peer)
3325 return CMD_WARNING_CONFIG_FAILED;
718e3744 3326
d62a17ae 3327 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3328 return bgp_vty_return(vty, ret);
718e3744 3329}
3330
d62a17ae 3331ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3332 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3333 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3334 "Enable the Address Family for this Neighbor\n")
596c17ba 3335
718e3744 3336DEFUN (no_neighbor_activate,
3337 no_neighbor_activate_cmd,
9ccf14f7 3338 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3339 NO_STR
3340 NEIGHBOR_STR
3341 NEIGHBOR_ADDR_STR2
3342 "Enable the Address Family for this Neighbor\n")
3343{
d62a17ae 3344 int idx_peer = 2;
3345 int ret;
3346 struct peer *peer;
718e3744 3347
d62a17ae 3348 /* Lookup peer. */
3349 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3350 if (!peer)
3351 return CMD_WARNING_CONFIG_FAILED;
718e3744 3352
d62a17ae 3353 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3354 return bgp_vty_return(vty, ret);
718e3744 3355}
6b0655a2 3356
d62a17ae 3357ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3358 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3359 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3360 "Enable the Address Family for this Neighbor\n")
596c17ba 3361
718e3744 3362DEFUN (neighbor_set_peer_group,
3363 neighbor_set_peer_group_cmd,
9ccf14f7 3364 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3365 NEIGHBOR_STR
a80beece 3366 NEIGHBOR_ADDR_STR2
718e3744 3367 "Member of the peer-group\n"
16cedbb0 3368 "Peer-group name\n")
718e3744 3369{
d62a17ae 3370 VTY_DECLVAR_CONTEXT(bgp, bgp);
3371 int idx_peer = 1;
3372 int idx_word = 3;
3373 int ret;
3374 as_t as;
3375 union sockunion su;
3376 struct peer *peer;
3377 struct peer_group *group;
3378
3379 peer = NULL;
3380
3381 ret = str2sockunion(argv[idx_peer]->arg, &su);
3382 if (ret < 0) {
3383 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3384 if (!peer) {
3385 vty_out(vty, "%% Malformed address or name: %s\n",
3386 argv[idx_peer]->arg);
3387 return CMD_WARNING_CONFIG_FAILED;
3388 }
3389 } else {
3390 if (peer_address_self_check(bgp, &su)) {
3391 vty_out(vty,
3392 "%% Can not configure the local system as neighbor\n");
3393 return CMD_WARNING_CONFIG_FAILED;
3394 }
3395
3396 /* Disallow for dynamic neighbor. */
3397 peer = peer_lookup(bgp, &su);
3398 if (peer && peer_dynamic_neighbor(peer)) {
3399 vty_out(vty,
3400 "%% Operation not allowed on a dynamic neighbor\n");
3401 return CMD_WARNING_CONFIG_FAILED;
3402 }
3403 }
3404
3405 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3406 if (!group) {
3407 vty_out(vty, "%% Configure the peer-group first\n");
3408 return CMD_WARNING_CONFIG_FAILED;
3409 }
3410
3411 ret = peer_group_bind(bgp, &su, peer, group, &as);
3412
3413 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3414 vty_out(vty,
3415 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3416 as);
3417 return CMD_WARNING_CONFIG_FAILED;
3418 }
3419
3420 return bgp_vty_return(vty, ret);
3421}
3422
3423ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3424 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3425 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3426 "Member of the peer-group\n"
3427 "Peer-group name\n")
596c17ba 3428
718e3744 3429DEFUN (no_neighbor_set_peer_group,
3430 no_neighbor_set_peer_group_cmd,
9ccf14f7 3431 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3432 NO_STR
3433 NEIGHBOR_STR
a80beece 3434 NEIGHBOR_ADDR_STR2
718e3744 3435 "Member of the peer-group\n"
16cedbb0 3436 "Peer-group name\n")
718e3744 3437{
d62a17ae 3438 VTY_DECLVAR_CONTEXT(bgp, bgp);
3439 int idx_peer = 2;
3440 int idx_word = 4;
3441 int ret;
3442 struct peer *peer;
3443 struct peer_group *group;
3444
3445 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3446 if (!peer)
3447 return CMD_WARNING_CONFIG_FAILED;
3448
3449 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3450 if (!group) {
3451 vty_out(vty, "%% Configure the peer-group first\n");
3452 return CMD_WARNING_CONFIG_FAILED;
3453 }
718e3744 3454
827ed707 3455 ret = peer_delete(peer);
718e3744 3456
d62a17ae 3457 return bgp_vty_return(vty, ret);
718e3744 3458}
6b0655a2 3459
d62a17ae 3460ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3461 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3462 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3463 "Member of the peer-group\n"
3464 "Peer-group name\n")
596c17ba 3465
d62a17ae 3466static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3467 uint32_t flag, int set)
718e3744 3468{
d62a17ae 3469 int ret;
3470 struct peer *peer;
718e3744 3471
d62a17ae 3472 peer = peer_and_group_lookup_vty(vty, ip_str);
3473 if (!peer)
3474 return CMD_WARNING_CONFIG_FAILED;
718e3744 3475
7ebe625c
QY
3476 /*
3477 * If 'neighbor <interface>', then this is for directly connected peers,
3478 * we should not accept disable-connected-check.
3479 */
3480 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3481 vty_out(vty,
3482 "%s is directly connected peer, cannot accept disable-"
3483 "connected-check\n",
3484 ip_str);
3485 return CMD_WARNING_CONFIG_FAILED;
3486 }
3487
d62a17ae 3488 if (!set && flag == PEER_FLAG_SHUTDOWN)
3489 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3490
d62a17ae 3491 if (set)
3492 ret = peer_flag_set(peer, flag);
3493 else
3494 ret = peer_flag_unset(peer, flag);
718e3744 3495
d62a17ae 3496 return bgp_vty_return(vty, ret);
718e3744 3497}
3498
47cbc09b 3499static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3500{
d62a17ae 3501 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3502}
3503
d62a17ae 3504static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3505 uint32_t flag)
718e3744 3506{
d62a17ae 3507 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3508}
3509
3510/* neighbor passive. */
3511DEFUN (neighbor_passive,
3512 neighbor_passive_cmd,
9ccf14f7 3513 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3514 NEIGHBOR_STR
3515 NEIGHBOR_ADDR_STR2
3516 "Don't send open messages to this neighbor\n")
3517{
d62a17ae 3518 int idx_peer = 1;
3519 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3520}
3521
3522DEFUN (no_neighbor_passive,
3523 no_neighbor_passive_cmd,
9ccf14f7 3524 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3525 NO_STR
3526 NEIGHBOR_STR
3527 NEIGHBOR_ADDR_STR2
3528 "Don't send open messages to this neighbor\n")
3529{
d62a17ae 3530 int idx_peer = 2;
3531 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3532}
6b0655a2 3533
718e3744 3534/* neighbor shutdown. */
73d70fa6
DL
3535DEFUN (neighbor_shutdown_msg,
3536 neighbor_shutdown_msg_cmd,
3537 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3538 NEIGHBOR_STR
3539 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3540 "Administratively shut down this neighbor\n"
3541 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3542 "Shutdown message\n")
718e3744 3543{
d62a17ae 3544 int idx_peer = 1;
73d70fa6 3545
d62a17ae 3546 if (argc >= 5) {
3547 struct peer *peer =
3548 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3549 char *message;
73d70fa6 3550
d62a17ae 3551 if (!peer)
3552 return CMD_WARNING_CONFIG_FAILED;
3553 message = argv_concat(argv, argc, 4);
3554 peer_tx_shutdown_message_set(peer, message);
3555 XFREE(MTYPE_TMP, message);
3556 }
73d70fa6 3557
d62a17ae 3558 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3559}
3560
d62a17ae 3561ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3562 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3563 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3564 "Administratively shut down this neighbor\n")
73d70fa6
DL
3565
3566DEFUN (no_neighbor_shutdown_msg,
3567 no_neighbor_shutdown_msg_cmd,
3568 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3569 NO_STR
3570 NEIGHBOR_STR
3571 NEIGHBOR_ADDR_STR2
3572 "Administratively shut down this neighbor\n"
3573 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3574 "Shutdown message\n")
718e3744 3575{
d62a17ae 3576 int idx_peer = 2;
73d70fa6 3577
d62a17ae 3578 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3579 PEER_FLAG_SHUTDOWN);
718e3744 3580}
6b0655a2 3581
d62a17ae 3582ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3583 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3584 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3585 "Administratively shut down this neighbor\n")
73d70fa6 3586
718e3744 3587/* neighbor capability dynamic. */
3588DEFUN (neighbor_capability_dynamic,
3589 neighbor_capability_dynamic_cmd,
9ccf14f7 3590 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3591 NEIGHBOR_STR
3592 NEIGHBOR_ADDR_STR2
3593 "Advertise capability to the peer\n"
3594 "Advertise dynamic capability to this neighbor\n")
3595{
d62a17ae 3596 int idx_peer = 1;
3597 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3598 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3599}
3600
3601DEFUN (no_neighbor_capability_dynamic,
3602 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3603 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3604 NO_STR
3605 NEIGHBOR_STR
3606 NEIGHBOR_ADDR_STR2
3607 "Advertise capability to the peer\n"
3608 "Advertise dynamic capability to this neighbor\n")
3609{
d62a17ae 3610 int idx_peer = 2;
3611 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3612 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3613}
6b0655a2 3614
718e3744 3615/* neighbor dont-capability-negotiate */
3616DEFUN (neighbor_dont_capability_negotiate,
3617 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3618 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3619 NEIGHBOR_STR
3620 NEIGHBOR_ADDR_STR2
3621 "Do not perform capability negotiation\n")
3622{
d62a17ae 3623 int idx_peer = 1;
3624 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3625 PEER_FLAG_DONT_CAPABILITY);
718e3744 3626}
3627
3628DEFUN (no_neighbor_dont_capability_negotiate,
3629 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3630 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3631 NO_STR
3632 NEIGHBOR_STR
3633 NEIGHBOR_ADDR_STR2
3634 "Do not perform capability negotiation\n")
3635{
d62a17ae 3636 int idx_peer = 2;
3637 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3638 PEER_FLAG_DONT_CAPABILITY);
718e3744 3639}
6b0655a2 3640
8a92a8a0
DS
3641/* neighbor capability extended next hop encoding */
3642DEFUN (neighbor_capability_enhe,
3643 neighbor_capability_enhe_cmd,
9ccf14f7 3644 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3645 NEIGHBOR_STR
3646 NEIGHBOR_ADDR_STR2
3647 "Advertise capability to the peer\n"
3648 "Advertise extended next-hop capability to the peer\n")
3649{
d62a17ae 3650 int idx_peer = 1;
3651 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3652 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3653}
3654
3655DEFUN (no_neighbor_capability_enhe,
3656 no_neighbor_capability_enhe_cmd,
9ccf14f7 3657 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3658 NO_STR
3659 NEIGHBOR_STR
3660 NEIGHBOR_ADDR_STR2
3661 "Advertise capability to the peer\n"
3662 "Advertise extended next-hop capability to the peer\n")
3663{
d62a17ae 3664 int idx_peer = 2;
3665 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3666 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3667}
3668
d62a17ae 3669static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3670 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3671 int set)
718e3744 3672{
d62a17ae 3673 int ret;
3674 struct peer *peer;
718e3744 3675
d62a17ae 3676 peer = peer_and_group_lookup_vty(vty, peer_str);
3677 if (!peer)
3678 return CMD_WARNING_CONFIG_FAILED;
718e3744 3679
d62a17ae 3680 if (set)
3681 ret = peer_af_flag_set(peer, afi, safi, flag);
3682 else
3683 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3684
d62a17ae 3685 return bgp_vty_return(vty, ret);
718e3744 3686}
3687
d62a17ae 3688static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3689 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3690{
d62a17ae 3691 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3692}
3693
d62a17ae 3694static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3695 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3696{
d62a17ae 3697 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3698}
6b0655a2 3699
718e3744 3700/* neighbor capability orf prefix-list. */
3701DEFUN (neighbor_capability_orf_prefix,
3702 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3703 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3704 NEIGHBOR_STR
3705 NEIGHBOR_ADDR_STR2
3706 "Advertise capability to the peer\n"
3707 "Advertise ORF capability to the peer\n"
3708 "Advertise prefixlist ORF capability to this neighbor\n"
3709 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3710 "Capability to RECEIVE the ORF from this neighbor\n"
3711 "Capability to SEND the ORF to this neighbor\n")
3712{
d62a17ae 3713 int idx_peer = 1;
3714 int idx_send_recv = 5;
d7c0a89a 3715 uint16_t flag = 0;
d62a17ae 3716
3717 if (strmatch(argv[idx_send_recv]->text, "send"))
3718 flag = PEER_FLAG_ORF_PREFIX_SM;
3719 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3720 flag = PEER_FLAG_ORF_PREFIX_RM;
3721 else if (strmatch(argv[idx_send_recv]->text, "both"))
3722 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3723 else {
3724 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3725 return CMD_WARNING_CONFIG_FAILED;
3726 }
3727
3728 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3729 bgp_node_safi(vty), flag);
3730}
3731
3732ALIAS_HIDDEN(
3733 neighbor_capability_orf_prefix,
3734 neighbor_capability_orf_prefix_hidden_cmd,
3735 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3736 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3737 "Advertise capability to the peer\n"
3738 "Advertise ORF capability to the peer\n"
3739 "Advertise prefixlist ORF capability to this neighbor\n"
3740 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3741 "Capability to RECEIVE the ORF from this neighbor\n"
3742 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3743
718e3744 3744DEFUN (no_neighbor_capability_orf_prefix,
3745 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3746 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3747 NO_STR
3748 NEIGHBOR_STR
3749 NEIGHBOR_ADDR_STR2
3750 "Advertise capability to the peer\n"
3751 "Advertise ORF capability to the peer\n"
3752 "Advertise prefixlist ORF capability to this neighbor\n"
3753 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3754 "Capability to RECEIVE the ORF from this neighbor\n"
3755 "Capability to SEND the ORF to this neighbor\n")
3756{
d62a17ae 3757 int idx_peer = 2;
3758 int idx_send_recv = 6;
d7c0a89a 3759 uint16_t flag = 0;
d62a17ae 3760
3761 if (strmatch(argv[idx_send_recv]->text, "send"))
3762 flag = PEER_FLAG_ORF_PREFIX_SM;
3763 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3764 flag = PEER_FLAG_ORF_PREFIX_RM;
3765 else if (strmatch(argv[idx_send_recv]->text, "both"))
3766 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3767 else {
3768 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3769 return CMD_WARNING_CONFIG_FAILED;
3770 }
3771
3772 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3773 bgp_node_afi(vty), bgp_node_safi(vty),
3774 flag);
3775}
3776
3777ALIAS_HIDDEN(
3778 no_neighbor_capability_orf_prefix,
3779 no_neighbor_capability_orf_prefix_hidden_cmd,
3780 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3781 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3782 "Advertise capability to the peer\n"
3783 "Advertise ORF capability to the peer\n"
3784 "Advertise prefixlist ORF capability to this neighbor\n"
3785 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3786 "Capability to RECEIVE the ORF from this neighbor\n"
3787 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3788
718e3744 3789/* neighbor next-hop-self. */
3790DEFUN (neighbor_nexthop_self,
3791 neighbor_nexthop_self_cmd,
9ccf14f7 3792 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3793 NEIGHBOR_STR
3794 NEIGHBOR_ADDR_STR2
a538debe 3795 "Disable the next hop calculation for this neighbor\n")
718e3744 3796{
d62a17ae 3797 int idx_peer = 1;
3798 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3799 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3800}
9e7a53c1 3801
d62a17ae 3802ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3803 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3804 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3805 "Disable the next hop calculation for this neighbor\n")
596c17ba 3806
a538debe
DS
3807/* neighbor next-hop-self. */
3808DEFUN (neighbor_nexthop_self_force,
3809 neighbor_nexthop_self_force_cmd,
9ccf14f7 3810 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3811 NEIGHBOR_STR
3812 NEIGHBOR_ADDR_STR2
3813 "Disable the next hop calculation for this neighbor\n"
3814 "Set the next hop to self for reflected routes\n")
3815{
d62a17ae 3816 int idx_peer = 1;
3817 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3818 bgp_node_safi(vty),
3819 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3820}
3821
d62a17ae 3822ALIAS_HIDDEN(neighbor_nexthop_self_force,
3823 neighbor_nexthop_self_force_hidden_cmd,
3824 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3825 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3826 "Disable the next hop calculation for this neighbor\n"
3827 "Set the next hop to self for reflected routes\n")
596c17ba 3828
718e3744 3829DEFUN (no_neighbor_nexthop_self,
3830 no_neighbor_nexthop_self_cmd,
9ccf14f7 3831 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3832 NO_STR
3833 NEIGHBOR_STR
3834 NEIGHBOR_ADDR_STR2
a538debe 3835 "Disable the next hop calculation for this neighbor\n")
718e3744 3836{
d62a17ae 3837 int idx_peer = 2;
3838 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3839 bgp_node_afi(vty), bgp_node_safi(vty),
3840 PEER_FLAG_NEXTHOP_SELF);
718e3744 3841}
6b0655a2 3842
d62a17ae 3843ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3844 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3845 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3846 "Disable the next hop calculation for this neighbor\n")
596c17ba 3847
88b8ed8d 3848DEFUN (no_neighbor_nexthop_self_force,
a538debe 3849 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3850 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3851 NO_STR
3852 NEIGHBOR_STR
3853 NEIGHBOR_ADDR_STR2
3854 "Disable the next hop calculation for this neighbor\n"
3855 "Set the next hop to self for reflected routes\n")
88b8ed8d 3856{
d62a17ae 3857 int idx_peer = 2;
3858 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3859 bgp_node_afi(vty), bgp_node_safi(vty),
3860 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3861}
a538debe 3862
d62a17ae 3863ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3864 no_neighbor_nexthop_self_force_hidden_cmd,
3865 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3866 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3867 "Disable the next hop calculation for this neighbor\n"
3868 "Set the next hop to self for reflected routes\n")
596c17ba 3869
c7122e14
DS
3870/* neighbor as-override */
3871DEFUN (neighbor_as_override,
3872 neighbor_as_override_cmd,
9ccf14f7 3873 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3874 NEIGHBOR_STR
3875 NEIGHBOR_ADDR_STR2
3876 "Override ASNs in outbound updates if aspath equals remote-as\n")
3877{
d62a17ae 3878 int idx_peer = 1;
3879 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3880 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3881}
3882
d62a17ae 3883ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3884 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3885 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3886 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3887
c7122e14
DS
3888DEFUN (no_neighbor_as_override,
3889 no_neighbor_as_override_cmd,
9ccf14f7 3890 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3891 NO_STR
3892 NEIGHBOR_STR
3893 NEIGHBOR_ADDR_STR2
3894 "Override ASNs in outbound updates if aspath equals remote-as\n")
3895{
d62a17ae 3896 int idx_peer = 2;
3897 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3898 bgp_node_afi(vty), bgp_node_safi(vty),
3899 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3900}
3901
d62a17ae 3902ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3903 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3904 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3905 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3906
718e3744 3907/* neighbor remove-private-AS. */
3908DEFUN (neighbor_remove_private_as,
3909 neighbor_remove_private_as_cmd,
9ccf14f7 3910 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3911 NEIGHBOR_STR
3912 NEIGHBOR_ADDR_STR2
5000f21c 3913 "Remove private ASNs in outbound updates\n")
718e3744 3914{
d62a17ae 3915 int idx_peer = 1;
3916 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3917 bgp_node_safi(vty),
3918 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3919}
3920
d62a17ae 3921ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3922 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3923 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3924 "Remove private ASNs in outbound updates\n")
596c17ba 3925
5000f21c
DS
3926DEFUN (neighbor_remove_private_as_all,
3927 neighbor_remove_private_as_all_cmd,
9ccf14f7 3928 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3929 NEIGHBOR_STR
3930 NEIGHBOR_ADDR_STR2
3931 "Remove private ASNs in outbound updates\n"
efd7904e 3932 "Apply to all AS numbers\n")
5000f21c 3933{
d62a17ae 3934 int idx_peer = 1;
3935 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3936 bgp_node_safi(vty),
3937 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3938}
3939
d62a17ae 3940ALIAS_HIDDEN(neighbor_remove_private_as_all,
3941 neighbor_remove_private_as_all_hidden_cmd,
3942 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3943 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3944 "Remove private ASNs in outbound updates\n"
3945 "Apply to all AS numbers")
596c17ba 3946
5000f21c
DS
3947DEFUN (neighbor_remove_private_as_replace_as,
3948 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3949 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3950 NEIGHBOR_STR
3951 NEIGHBOR_ADDR_STR2
3952 "Remove private ASNs in outbound updates\n"
3953 "Replace private ASNs with our ASN in outbound updates\n")
3954{
d62a17ae 3955 int idx_peer = 1;
3956 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3957 bgp_node_safi(vty),
3958 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3959}
3960
d62a17ae 3961ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3962 neighbor_remove_private_as_replace_as_hidden_cmd,
3963 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3964 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3965 "Remove private ASNs in outbound updates\n"
3966 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3967
5000f21c
DS
3968DEFUN (neighbor_remove_private_as_all_replace_as,
3969 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3970 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3971 NEIGHBOR_STR
3972 NEIGHBOR_ADDR_STR2
3973 "Remove private ASNs in outbound updates\n"
16cedbb0 3974 "Apply to all AS numbers\n"
5000f21c
DS
3975 "Replace private ASNs with our ASN in outbound updates\n")
3976{
d62a17ae 3977 int idx_peer = 1;
3978 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3979 bgp_node_safi(vty),
3980 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3981}
3982
d62a17ae 3983ALIAS_HIDDEN(
3984 neighbor_remove_private_as_all_replace_as,
3985 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3986 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3987 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3988 "Remove private ASNs in outbound updates\n"
3989 "Apply to all AS numbers\n"
3990 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3991
718e3744 3992DEFUN (no_neighbor_remove_private_as,
3993 no_neighbor_remove_private_as_cmd,
9ccf14f7 3994 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3995 NO_STR
3996 NEIGHBOR_STR
3997 NEIGHBOR_ADDR_STR2
5000f21c 3998 "Remove private ASNs in outbound updates\n")
718e3744 3999{
d62a17ae 4000 int idx_peer = 2;
4001 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4002 bgp_node_afi(vty), bgp_node_safi(vty),
4003 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4004}
6b0655a2 4005
d62a17ae 4006ALIAS_HIDDEN(no_neighbor_remove_private_as,
4007 no_neighbor_remove_private_as_hidden_cmd,
4008 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4009 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4010 "Remove private ASNs in outbound updates\n")
596c17ba 4011
88b8ed8d 4012DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4013 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4014 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4015 NO_STR
4016 NEIGHBOR_STR
4017 NEIGHBOR_ADDR_STR2
4018 "Remove private ASNs in outbound updates\n"
16cedbb0 4019 "Apply to all AS numbers\n")
88b8ed8d 4020{
d62a17ae 4021 int idx_peer = 2;
4022 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4023 bgp_node_afi(vty), bgp_node_safi(vty),
4024 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4025}
5000f21c 4026
d62a17ae 4027ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4028 no_neighbor_remove_private_as_all_hidden_cmd,
4029 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4030 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4031 "Remove private ASNs in outbound updates\n"
4032 "Apply to all AS numbers\n")
596c17ba 4033
88b8ed8d 4034DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4035 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4036 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4037 NO_STR
4038 NEIGHBOR_STR
4039 NEIGHBOR_ADDR_STR2
4040 "Remove private ASNs in outbound updates\n"
4041 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4042{
d62a17ae 4043 int idx_peer = 2;
4044 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4045 bgp_node_afi(vty), bgp_node_safi(vty),
4046 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4047}
5000f21c 4048
d62a17ae 4049ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4050 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4051 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4052 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4053 "Remove private ASNs in outbound updates\n"
4054 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4055
88b8ed8d 4056DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4057 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4058 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4059 NO_STR
4060 NEIGHBOR_STR
4061 NEIGHBOR_ADDR_STR2
4062 "Remove private ASNs in outbound updates\n"
16cedbb0 4063 "Apply to all AS numbers\n"
5000f21c 4064 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4065{
d62a17ae 4066 int idx_peer = 2;
4067 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4068 bgp_node_afi(vty), bgp_node_safi(vty),
4069 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4070}
5000f21c 4071
d62a17ae 4072ALIAS_HIDDEN(
4073 no_neighbor_remove_private_as_all_replace_as,
4074 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4075 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4076 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4077 "Remove private ASNs in outbound updates\n"
4078 "Apply to all AS numbers\n"
4079 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4080
5000f21c 4081
718e3744 4082/* neighbor send-community. */
4083DEFUN (neighbor_send_community,
4084 neighbor_send_community_cmd,
9ccf14f7 4085 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4086 NEIGHBOR_STR
4087 NEIGHBOR_ADDR_STR2
4088 "Send Community attribute to this neighbor\n")
4089{
d62a17ae 4090 int idx_peer = 1;
27c05d4d 4091
d62a17ae 4092 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4093 bgp_node_safi(vty),
4094 PEER_FLAG_SEND_COMMUNITY);
718e3744 4095}
4096
d62a17ae 4097ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4098 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4099 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4100 "Send Community attribute to this neighbor\n")
596c17ba 4101
718e3744 4102DEFUN (no_neighbor_send_community,
4103 no_neighbor_send_community_cmd,
9ccf14f7 4104 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4105 NO_STR
4106 NEIGHBOR_STR
4107 NEIGHBOR_ADDR_STR2
4108 "Send Community attribute to this neighbor\n")
4109{
d62a17ae 4110 int idx_peer = 2;
27c05d4d 4111
d62a17ae 4112 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4113 bgp_node_afi(vty), bgp_node_safi(vty),
4114 PEER_FLAG_SEND_COMMUNITY);
718e3744 4115}
6b0655a2 4116
d62a17ae 4117ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4118 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4119 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4120 "Send Community attribute to this neighbor\n")
596c17ba 4121
718e3744 4122/* neighbor send-community extended. */
4123DEFUN (neighbor_send_community_type,
4124 neighbor_send_community_type_cmd,
57d187bc 4125 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4126 NEIGHBOR_STR
4127 NEIGHBOR_ADDR_STR2
4128 "Send Community attribute to this neighbor\n"
4129 "Send Standard and Extended Community attributes\n"
57d187bc 4130 "Send Standard, Large and Extended Community attributes\n"
718e3744 4131 "Send Extended Community attributes\n"
57d187bc
JS
4132 "Send Standard Community attributes\n"
4133 "Send Large Community attributes\n")
718e3744 4134{
27c05d4d 4135 int idx_peer = 1;
d7c0a89a 4136 uint32_t flag = 0;
27c05d4d 4137 const char *type = argv[argc - 1]->text;
d62a17ae 4138
27c05d4d 4139 if (strmatch(type, "standard")) {
d62a17ae 4140 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4141 } else if (strmatch(type, "extended")) {
d62a17ae 4142 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4143 } else if (strmatch(type, "large")) {
d62a17ae 4144 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4145 } else if (strmatch(type, "both")) {
d62a17ae 4146 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4147 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4148 } else { /* if (strmatch(type, "all")) */
d62a17ae 4149 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4150 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4151 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4152 }
4153
27c05d4d 4154 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4155 bgp_node_safi(vty), flag);
4156}
4157
4158ALIAS_HIDDEN(
4159 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4160 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4161 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4162 "Send Community attribute to this neighbor\n"
4163 "Send Standard and Extended Community attributes\n"
4164 "Send Standard, Large and Extended Community attributes\n"
4165 "Send Extended Community attributes\n"
4166 "Send Standard Community attributes\n"
4167 "Send Large Community attributes\n")
596c17ba 4168
718e3744 4169DEFUN (no_neighbor_send_community_type,
4170 no_neighbor_send_community_type_cmd,
57d187bc 4171 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4172 NO_STR
4173 NEIGHBOR_STR
4174 NEIGHBOR_ADDR_STR2
4175 "Send Community attribute to this neighbor\n"
4176 "Send Standard and Extended Community attributes\n"
57d187bc 4177 "Send Standard, Large and Extended Community attributes\n"
718e3744 4178 "Send Extended Community attributes\n"
57d187bc
JS
4179 "Send Standard Community attributes\n"
4180 "Send Large Community attributes\n")
718e3744 4181{
d62a17ae 4182 int idx_peer = 2;
27c05d4d 4183 uint32_t flag = 0;
d62a17ae 4184 const char *type = argv[argc - 1]->text;
4185
27c05d4d
PM
4186 if (strmatch(type, "standard")) {
4187 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4188 } else if (strmatch(type, "extended")) {
4189 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4190 } else if (strmatch(type, "large")) {
4191 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4192 } else if (strmatch(type, "both")) {
4193 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4194 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4195 } else { /* if (strmatch(type, "all")) */
4196 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4197 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4198 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4199 }
4200
4201 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4202 bgp_node_afi(vty), bgp_node_safi(vty),
4203 flag);
d62a17ae 4204}
4205
4206ALIAS_HIDDEN(
4207 no_neighbor_send_community_type,
4208 no_neighbor_send_community_type_hidden_cmd,
4209 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4210 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4211 "Send Community attribute to this neighbor\n"
4212 "Send Standard and Extended Community attributes\n"
4213 "Send Standard, Large and Extended Community attributes\n"
4214 "Send Extended Community attributes\n"
4215 "Send Standard Community attributes\n"
4216 "Send Large Community attributes\n")
596c17ba 4217
718e3744 4218/* neighbor soft-reconfig. */
4219DEFUN (neighbor_soft_reconfiguration,
4220 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4221 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4222 NEIGHBOR_STR
4223 NEIGHBOR_ADDR_STR2
4224 "Per neighbor soft reconfiguration\n"
4225 "Allow inbound soft reconfiguration for this neighbor\n")
4226{
d62a17ae 4227 int idx_peer = 1;
4228 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4229 bgp_node_safi(vty),
4230 PEER_FLAG_SOFT_RECONFIG);
718e3744 4231}
4232
d62a17ae 4233ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4234 neighbor_soft_reconfiguration_hidden_cmd,
4235 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4236 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4237 "Per neighbor soft reconfiguration\n"
4238 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4239
718e3744 4240DEFUN (no_neighbor_soft_reconfiguration,
4241 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4242 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4243 NO_STR
4244 NEIGHBOR_STR
4245 NEIGHBOR_ADDR_STR2
4246 "Per neighbor soft reconfiguration\n"
4247 "Allow inbound soft reconfiguration for this neighbor\n")
4248{
d62a17ae 4249 int idx_peer = 2;
4250 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4251 bgp_node_afi(vty), bgp_node_safi(vty),
4252 PEER_FLAG_SOFT_RECONFIG);
718e3744 4253}
6b0655a2 4254
d62a17ae 4255ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4256 no_neighbor_soft_reconfiguration_hidden_cmd,
4257 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4258 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4259 "Per neighbor soft reconfiguration\n"
4260 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4261
718e3744 4262DEFUN (neighbor_route_reflector_client,
4263 neighbor_route_reflector_client_cmd,
9ccf14f7 4264 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4265 NEIGHBOR_STR
4266 NEIGHBOR_ADDR_STR2
4267 "Configure a neighbor as Route Reflector client\n")
4268{
d62a17ae 4269 int idx_peer = 1;
4270 struct peer *peer;
718e3744 4271
4272
d62a17ae 4273 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4274 if (!peer)
4275 return CMD_WARNING_CONFIG_FAILED;
718e3744 4276
d62a17ae 4277 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4278 bgp_node_safi(vty),
4279 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4280}
4281
d62a17ae 4282ALIAS_HIDDEN(neighbor_route_reflector_client,
4283 neighbor_route_reflector_client_hidden_cmd,
4284 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4285 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4286 "Configure a neighbor as Route Reflector client\n")
596c17ba 4287
718e3744 4288DEFUN (no_neighbor_route_reflector_client,
4289 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4290 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4291 NO_STR
4292 NEIGHBOR_STR
4293 NEIGHBOR_ADDR_STR2
4294 "Configure a neighbor as Route Reflector client\n")
4295{
d62a17ae 4296 int idx_peer = 2;
4297 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4298 bgp_node_afi(vty), bgp_node_safi(vty),
4299 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4300}
6b0655a2 4301
d62a17ae 4302ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4303 no_neighbor_route_reflector_client_hidden_cmd,
4304 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4305 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4306 "Configure a neighbor as Route Reflector client\n")
596c17ba 4307
718e3744 4308/* neighbor route-server-client. */
4309DEFUN (neighbor_route_server_client,
4310 neighbor_route_server_client_cmd,
9ccf14f7 4311 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4312 NEIGHBOR_STR
4313 NEIGHBOR_ADDR_STR2
4314 "Configure a neighbor as Route Server client\n")
4315{
d62a17ae 4316 int idx_peer = 1;
4317 struct peer *peer;
2a3d5731 4318
d62a17ae 4319 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4320 if (!peer)
4321 return CMD_WARNING_CONFIG_FAILED;
4322 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4323 bgp_node_safi(vty),
4324 PEER_FLAG_RSERVER_CLIENT);
718e3744 4325}
4326
d62a17ae 4327ALIAS_HIDDEN(neighbor_route_server_client,
4328 neighbor_route_server_client_hidden_cmd,
4329 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4330 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4331 "Configure a neighbor as Route Server client\n")
596c17ba 4332
718e3744 4333DEFUN (no_neighbor_route_server_client,
4334 no_neighbor_route_server_client_cmd,
9ccf14f7 4335 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4336 NO_STR
4337 NEIGHBOR_STR
4338 NEIGHBOR_ADDR_STR2
4339 "Configure a neighbor as Route Server client\n")
fee0f4c6 4340{
d62a17ae 4341 int idx_peer = 2;
4342 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4343 bgp_node_afi(vty), bgp_node_safi(vty),
4344 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4345}
6b0655a2 4346
d62a17ae 4347ALIAS_HIDDEN(no_neighbor_route_server_client,
4348 no_neighbor_route_server_client_hidden_cmd,
4349 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4350 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4351 "Configure a neighbor as Route Server client\n")
596c17ba 4352
fee0f4c6 4353DEFUN (neighbor_nexthop_local_unchanged,
4354 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4355 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4356 NEIGHBOR_STR
4357 NEIGHBOR_ADDR_STR2
4358 "Configure treatment of outgoing link-local nexthop attribute\n"
4359 "Leave link-local nexthop unchanged for this peer\n")
4360{
d62a17ae 4361 int idx_peer = 1;
4362 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4363 bgp_node_safi(vty),
4364 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4365}
6b0655a2 4366
fee0f4c6 4367DEFUN (no_neighbor_nexthop_local_unchanged,
4368 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4369 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4370 NO_STR
4371 NEIGHBOR_STR
4372 NEIGHBOR_ADDR_STR2
4373 "Configure treatment of outgoing link-local-nexthop attribute\n"
4374 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4375{
d62a17ae 4376 int idx_peer = 2;
4377 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4378 bgp_node_afi(vty), bgp_node_safi(vty),
4379 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4380}
6b0655a2 4381
718e3744 4382DEFUN (neighbor_attr_unchanged,
4383 neighbor_attr_unchanged_cmd,
a8206004 4384 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4385 NEIGHBOR_STR
4386 NEIGHBOR_ADDR_STR2
4387 "BGP attribute is propagated unchanged to this neighbor\n"
4388 "As-path attribute\n"
4389 "Nexthop attribute\n"
a8206004 4390 "Med attribute\n")
718e3744 4391{
d62a17ae 4392 int idx = 0;
8eeb0335
DW
4393 char *peer_str = argv[1]->arg;
4394 struct peer *peer;
d7c0a89a 4395 uint16_t flags = 0;
8eeb0335
DW
4396 afi_t afi = bgp_node_afi(vty);
4397 safi_t safi = bgp_node_safi(vty);
4398
4399 peer = peer_and_group_lookup_vty(vty, peer_str);
4400 if (!peer)
4401 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4402
4403 if (argv_find(argv, argc, "as-path", &idx))
4404 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4405 idx = 0;
4406 if (argv_find(argv, argc, "next-hop", &idx))
4407 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4408 idx = 0;
4409 if (argv_find(argv, argc, "med", &idx))
4410 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4411
8eeb0335
DW
4412 /* no flags means all of them! */
4413 if (!flags) {
d62a17ae 4414 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4415 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4416 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4417 } else {
a4d82a8a
PZ
4418 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4419 && peer_af_flag_check(peer, afi, safi,
4420 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4421 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4422 PEER_FLAG_AS_PATH_UNCHANGED);
4423 }
4424
a4d82a8a
PZ
4425 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4426 && peer_af_flag_check(peer, afi, safi,
4427 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4428 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4429 PEER_FLAG_NEXTHOP_UNCHANGED);
4430 }
4431
a4d82a8a
PZ
4432 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4433 && peer_af_flag_check(peer, afi, safi,
4434 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4435 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4436 PEER_FLAG_MED_UNCHANGED);
4437 }
d62a17ae 4438 }
4439
8eeb0335 4440 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4441}
4442
4443ALIAS_HIDDEN(
4444 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4445 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4446 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4447 "BGP attribute is propagated unchanged to this neighbor\n"
4448 "As-path attribute\n"
4449 "Nexthop attribute\n"
4450 "Med attribute\n")
596c17ba 4451
718e3744 4452DEFUN (no_neighbor_attr_unchanged,
4453 no_neighbor_attr_unchanged_cmd,
a8206004 4454 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4455 NO_STR
718e3744 4456 NEIGHBOR_STR
4457 NEIGHBOR_ADDR_STR2
31500417
DW
4458 "BGP attribute is propagated unchanged to this neighbor\n"
4459 "As-path attribute\n"
40e718b5 4460 "Nexthop attribute\n"
a8206004 4461 "Med attribute\n")
718e3744 4462{
d62a17ae 4463 int idx = 0;
4464 char *peer = argv[2]->arg;
d7c0a89a 4465 uint16_t flags = 0;
d62a17ae 4466
4467 if (argv_find(argv, argc, "as-path", &idx))
4468 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4469 idx = 0;
4470 if (argv_find(argv, argc, "next-hop", &idx))
4471 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4472 idx = 0;
4473 if (argv_find(argv, argc, "med", &idx))
4474 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4475
4476 if (!flags) // no flags means all of them!
4477 {
4478 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4479 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4480 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4481 }
4482
4483 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4484 bgp_node_safi(vty), flags);
4485}
4486
4487ALIAS_HIDDEN(
4488 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4489 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4490 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4491 "BGP attribute is propagated unchanged to this neighbor\n"
4492 "As-path attribute\n"
4493 "Nexthop attribute\n"
4494 "Med attribute\n")
718e3744 4495
718e3744 4496/* EBGP multihop configuration. */
d62a17ae 4497static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4498 const char *ttl_str)
718e3744 4499{
d62a17ae 4500 struct peer *peer;
4501 unsigned int ttl;
718e3744 4502
d62a17ae 4503 peer = peer_and_group_lookup_vty(vty, ip_str);
4504 if (!peer)
4505 return CMD_WARNING_CONFIG_FAILED;
718e3744 4506
d62a17ae 4507 if (peer->conf_if)
4508 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4509
d62a17ae 4510 if (!ttl_str)
4511 ttl = MAXTTL;
4512 else
4513 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4514
d62a17ae 4515 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4516}
4517
d62a17ae 4518static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4519{
d62a17ae 4520 struct peer *peer;
718e3744 4521
d62a17ae 4522 peer = peer_and_group_lookup_vty(vty, ip_str);
4523 if (!peer)
4524 return CMD_WARNING_CONFIG_FAILED;
718e3744 4525
d62a17ae 4526 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4527}
4528
4529/* neighbor ebgp-multihop. */
4530DEFUN (neighbor_ebgp_multihop,
4531 neighbor_ebgp_multihop_cmd,
9ccf14f7 4532 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4533 NEIGHBOR_STR
4534 NEIGHBOR_ADDR_STR2
4535 "Allow EBGP neighbors not on directly connected networks\n")
4536{
d62a17ae 4537 int idx_peer = 1;
4538 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4539}
4540
4541DEFUN (neighbor_ebgp_multihop_ttl,
4542 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4543 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4544 NEIGHBOR_STR
4545 NEIGHBOR_ADDR_STR2
4546 "Allow EBGP neighbors not on directly connected networks\n"
4547 "maximum hop count\n")
4548{
d62a17ae 4549 int idx_peer = 1;
4550 int idx_number = 3;
4551 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4552 argv[idx_number]->arg);
718e3744 4553}
4554
4555DEFUN (no_neighbor_ebgp_multihop,
4556 no_neighbor_ebgp_multihop_cmd,
a636c635 4557 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4558 NO_STR
4559 NEIGHBOR_STR
4560 NEIGHBOR_ADDR_STR2
a636c635
DW
4561 "Allow EBGP neighbors not on directly connected networks\n"
4562 "maximum hop count\n")
718e3744 4563{
d62a17ae 4564 int idx_peer = 2;
4565 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4566}
4567
6b0655a2 4568
6ffd2079 4569/* disable-connected-check */
4570DEFUN (neighbor_disable_connected_check,
4571 neighbor_disable_connected_check_cmd,
7ebe625c 4572 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4573 NEIGHBOR_STR
7ebe625c 4574 NEIGHBOR_ADDR_STR2
a636c635
DW
4575 "one-hop away EBGP peer using loopback address\n"
4576 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4577{
d62a17ae 4578 int idx_peer = 1;
4579 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4580 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4581}
4582
4583DEFUN (no_neighbor_disable_connected_check,
4584 no_neighbor_disable_connected_check_cmd,
7ebe625c 4585 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4586 NO_STR
4587 NEIGHBOR_STR
7ebe625c 4588 NEIGHBOR_ADDR_STR2
a636c635
DW
4589 "one-hop away EBGP peer using loopback address\n"
4590 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4591{
d62a17ae 4592 int idx_peer = 2;
4593 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4594 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4595}
4596
47cbc09b
PM
4597
4598/* enforce-first-as */
4599DEFUN (neighbor_enforce_first_as,
4600 neighbor_enforce_first_as_cmd,
4601 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4602 NEIGHBOR_STR
4603 NEIGHBOR_ADDR_STR2
4604 "Enforce the first AS for EBGP routes\n")
4605{
4606 int idx_peer = 1;
4607
4608 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4609 PEER_FLAG_ENFORCE_FIRST_AS);
4610}
4611
4612DEFUN (no_neighbor_enforce_first_as,
4613 no_neighbor_enforce_first_as_cmd,
4614 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4615 NO_STR
4616 NEIGHBOR_STR
4617 NEIGHBOR_ADDR_STR2
4618 "Enforce the first AS for EBGP routes\n")
4619{
4620 int idx_peer = 2;
4621
4622 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4623 PEER_FLAG_ENFORCE_FIRST_AS);
4624}
4625
4626
718e3744 4627DEFUN (neighbor_description,
4628 neighbor_description_cmd,
e961923c 4629 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4630 NEIGHBOR_STR
4631 NEIGHBOR_ADDR_STR2
4632 "Neighbor specific description\n"
4633 "Up to 80 characters describing this neighbor\n")
4634{
d62a17ae 4635 int idx_peer = 1;
4636 int idx_line = 3;
4637 struct peer *peer;
4638 char *str;
718e3744 4639
d62a17ae 4640 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4641 if (!peer)
4642 return CMD_WARNING_CONFIG_FAILED;
718e3744 4643
d62a17ae 4644 str = argv_concat(argv, argc, idx_line);
718e3744 4645
d62a17ae 4646 peer_description_set(peer, str);
718e3744 4647
d62a17ae 4648 XFREE(MTYPE_TMP, str);
718e3744 4649
d62a17ae 4650 return CMD_SUCCESS;
718e3744 4651}
4652
4653DEFUN (no_neighbor_description,
4654 no_neighbor_description_cmd,
a636c635 4655 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
718e3744 4656 NO_STR
4657 NEIGHBOR_STR
4658 NEIGHBOR_ADDR_STR2
a636c635
DW
4659 "Neighbor specific description\n"
4660 "Up to 80 characters describing this neighbor\n")
718e3744 4661{
d62a17ae 4662 int idx_peer = 2;
4663 struct peer *peer;
718e3744 4664
d62a17ae 4665 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4666 if (!peer)
4667 return CMD_WARNING_CONFIG_FAILED;
718e3744 4668
d62a17ae 4669 peer_description_unset(peer);
718e3744 4670
d62a17ae 4671 return CMD_SUCCESS;
718e3744 4672}
4673
6b0655a2 4674
718e3744 4675/* Neighbor update-source. */
d62a17ae 4676static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4677 const char *source_str)
4678{
4679 struct peer *peer;
4680 struct prefix p;
4681
4682 peer = peer_and_group_lookup_vty(vty, peer_str);
4683 if (!peer)
4684 return CMD_WARNING_CONFIG_FAILED;
4685
4686 if (peer->conf_if)
4687 return CMD_WARNING;
4688
4689 if (source_str) {
4690 union sockunion su;
4691 int ret = str2sockunion(source_str, &su);
4692
4693 if (ret == 0)
4694 peer_update_source_addr_set(peer, &su);
4695 else {
4696 if (str2prefix(source_str, &p)) {
4697 vty_out(vty,
4698 "%% Invalid update-source, remove prefix length \n");
4699 return CMD_WARNING_CONFIG_FAILED;
4700 } else
4701 peer_update_source_if_set(peer, source_str);
4702 }
4703 } else
4704 peer_update_source_unset(peer);
4705
4706 return CMD_SUCCESS;
4707}
4708
4709#define BGP_UPDATE_SOURCE_HELP_STR \
4710 "IPv4 address\n" \
4711 "IPv6 address\n" \
4712 "Interface name (requires zebra to be running)\n"
369688c0 4713
718e3744 4714DEFUN (neighbor_update_source,
4715 neighbor_update_source_cmd,
9ccf14f7 4716 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4717 NEIGHBOR_STR
4718 NEIGHBOR_ADDR_STR2
4719 "Source of routing updates\n"
369688c0 4720 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4721{
d62a17ae 4722 int idx_peer = 1;
4723 int idx_peer_2 = 3;
4724 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4725 argv[idx_peer_2]->arg);
718e3744 4726}
4727
4728DEFUN (no_neighbor_update_source,
4729 no_neighbor_update_source_cmd,
c7178fe7 4730 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4731 NO_STR
4732 NEIGHBOR_STR
4733 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4734 "Source of routing updates\n"
4735 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4736{
d62a17ae 4737 int idx_peer = 2;
4738 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4739}
6b0655a2 4740
d62a17ae 4741static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4742 afi_t afi, safi_t safi,
4743 const char *rmap, int set)
718e3744 4744{
d62a17ae 4745 int ret;
4746 struct peer *peer;
718e3744 4747
d62a17ae 4748 peer = peer_and_group_lookup_vty(vty, peer_str);
4749 if (!peer)
4750 return CMD_WARNING_CONFIG_FAILED;
718e3744 4751
d62a17ae 4752 if (set)
4753 ret = peer_default_originate_set(peer, afi, safi, rmap);
4754 else
4755 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4756
d62a17ae 4757 return bgp_vty_return(vty, ret);
718e3744 4758}
4759
4760/* neighbor default-originate. */
4761DEFUN (neighbor_default_originate,
4762 neighbor_default_originate_cmd,
9ccf14f7 4763 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4764 NEIGHBOR_STR
4765 NEIGHBOR_ADDR_STR2
4766 "Originate default route to this neighbor\n")
4767{
d62a17ae 4768 int idx_peer = 1;
4769 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4770 bgp_node_afi(vty),
4771 bgp_node_safi(vty), NULL, 1);
718e3744 4772}
4773
d62a17ae 4774ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4775 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4776 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4777 "Originate default route to this neighbor\n")
596c17ba 4778
718e3744 4779DEFUN (neighbor_default_originate_rmap,
4780 neighbor_default_originate_rmap_cmd,
9ccf14f7 4781 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4782 NEIGHBOR_STR
4783 NEIGHBOR_ADDR_STR2
4784 "Originate default route to this neighbor\n"
4785 "Route-map to specify criteria to originate default\n"
4786 "route-map name\n")
4787{
d62a17ae 4788 int idx_peer = 1;
4789 int idx_word = 4;
4790 return peer_default_originate_set_vty(
4791 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4792 argv[idx_word]->arg, 1);
718e3744 4793}
4794
d62a17ae 4795ALIAS_HIDDEN(
4796 neighbor_default_originate_rmap,
4797 neighbor_default_originate_rmap_hidden_cmd,
4798 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4799 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4800 "Originate default route to this neighbor\n"
4801 "Route-map to specify criteria to originate default\n"
4802 "route-map name\n")
596c17ba 4803
718e3744 4804DEFUN (no_neighbor_default_originate,
4805 no_neighbor_default_originate_cmd,
a636c635 4806 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4807 NO_STR
4808 NEIGHBOR_STR
4809 NEIGHBOR_ADDR_STR2
a636c635
DW
4810 "Originate default route to this neighbor\n"
4811 "Route-map to specify criteria to originate default\n"
4812 "route-map name\n")
718e3744 4813{
d62a17ae 4814 int idx_peer = 2;
4815 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4816 bgp_node_afi(vty),
4817 bgp_node_safi(vty), NULL, 0);
718e3744 4818}
4819
d62a17ae 4820ALIAS_HIDDEN(
4821 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4822 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4823 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4824 "Originate default route to this neighbor\n"
4825 "Route-map to specify criteria to originate default\n"
4826 "route-map name\n")
596c17ba 4827
6b0655a2 4828
718e3744 4829/* Set neighbor's BGP port. */
d62a17ae 4830static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4831 const char *port_str)
4832{
4833 struct peer *peer;
d7c0a89a 4834 uint16_t port;
d62a17ae 4835 struct servent *sp;
4836
4837 peer = peer_lookup_vty(vty, ip_str);
4838 if (!peer)
4839 return CMD_WARNING_CONFIG_FAILED;
4840
4841 if (!port_str) {
4842 sp = getservbyname("bgp", "tcp");
4843 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4844 } else {
4845 port = strtoul(port_str, NULL, 10);
4846 }
718e3744 4847
d62a17ae 4848 peer_port_set(peer, port);
718e3744 4849
d62a17ae 4850 return CMD_SUCCESS;
718e3744 4851}
4852
f418446b 4853/* Set specified peer's BGP port. */
718e3744 4854DEFUN (neighbor_port,
4855 neighbor_port_cmd,
9ccf14f7 4856 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4857 NEIGHBOR_STR
4858 NEIGHBOR_ADDR_STR
4859 "Neighbor's BGP port\n"
4860 "TCP port number\n")
4861{
d62a17ae 4862 int idx_ip = 1;
4863 int idx_number = 3;
4864 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4865 argv[idx_number]->arg);
718e3744 4866}
4867
4868DEFUN (no_neighbor_port,
4869 no_neighbor_port_cmd,
9ccf14f7 4870 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4871 NO_STR
4872 NEIGHBOR_STR
4873 NEIGHBOR_ADDR_STR
8334fd5a
DW
4874 "Neighbor's BGP port\n"
4875 "TCP port number\n")
718e3744 4876{
d62a17ae 4877 int idx_ip = 2;
4878 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4879}
4880
6b0655a2 4881
718e3744 4882/* neighbor weight. */
d62a17ae 4883static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4884 safi_t safi, const char *weight_str)
718e3744 4885{
d62a17ae 4886 int ret;
4887 struct peer *peer;
4888 unsigned long weight;
718e3744 4889
d62a17ae 4890 peer = peer_and_group_lookup_vty(vty, ip_str);
4891 if (!peer)
4892 return CMD_WARNING_CONFIG_FAILED;
718e3744 4893
d62a17ae 4894 weight = strtoul(weight_str, NULL, 10);
718e3744 4895
d62a17ae 4896 ret = peer_weight_set(peer, afi, safi, weight);
4897 return bgp_vty_return(vty, ret);
718e3744 4898}
4899
d62a17ae 4900static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4901 safi_t safi)
718e3744 4902{
d62a17ae 4903 int ret;
4904 struct peer *peer;
718e3744 4905
d62a17ae 4906 peer = peer_and_group_lookup_vty(vty, ip_str);
4907 if (!peer)
4908 return CMD_WARNING_CONFIG_FAILED;
718e3744 4909
d62a17ae 4910 ret = peer_weight_unset(peer, afi, safi);
4911 return bgp_vty_return(vty, ret);
718e3744 4912}
4913
4914DEFUN (neighbor_weight,
4915 neighbor_weight_cmd,
9ccf14f7 4916 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4917 NEIGHBOR_STR
4918 NEIGHBOR_ADDR_STR2
4919 "Set default weight for routes from this neighbor\n"
4920 "default weight\n")
4921{
d62a17ae 4922 int idx_peer = 1;
4923 int idx_number = 3;
4924 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4925 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4926}
4927
d62a17ae 4928ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4929 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4930 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4931 "Set default weight for routes from this neighbor\n"
4932 "default weight\n")
596c17ba 4933
718e3744 4934DEFUN (no_neighbor_weight,
4935 no_neighbor_weight_cmd,
9ccf14f7 4936 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4937 NO_STR
4938 NEIGHBOR_STR
4939 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4940 "Set default weight for routes from this neighbor\n"
4941 "default weight\n")
718e3744 4942{
d62a17ae 4943 int idx_peer = 2;
4944 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4945 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4946}
4947
d62a17ae 4948ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4949 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4950 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4951 "Set default weight for routes from this neighbor\n"
4952 "default weight\n")
596c17ba 4953
6b0655a2 4954
718e3744 4955/* Override capability negotiation. */
4956DEFUN (neighbor_override_capability,
4957 neighbor_override_capability_cmd,
9ccf14f7 4958 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4959 NEIGHBOR_STR
4960 NEIGHBOR_ADDR_STR2
4961 "Override capability negotiation result\n")
4962{
d62a17ae 4963 int idx_peer = 1;
4964 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4965 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4966}
4967
4968DEFUN (no_neighbor_override_capability,
4969 no_neighbor_override_capability_cmd,
9ccf14f7 4970 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4971 NO_STR
4972 NEIGHBOR_STR
4973 NEIGHBOR_ADDR_STR2
4974 "Override capability negotiation result\n")
4975{
d62a17ae 4976 int idx_peer = 2;
4977 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4978 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4979}
6b0655a2 4980
718e3744 4981DEFUN (neighbor_strict_capability,
4982 neighbor_strict_capability_cmd,
9ccf14f7 4983 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4984 NEIGHBOR_STR
4985 NEIGHBOR_ADDR_STR
4986 "Strict capability negotiation match\n")
4987{
d62a17ae 4988 int idx_ip = 1;
4989 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4990 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4991}
4992
4993DEFUN (no_neighbor_strict_capability,
4994 no_neighbor_strict_capability_cmd,
9ccf14f7 4995 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4996 NO_STR
4997 NEIGHBOR_STR
4998 NEIGHBOR_ADDR_STR
4999 "Strict capability negotiation match\n")
5000{
d62a17ae 5001 int idx_ip = 2;
5002 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
5003 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5004}
6b0655a2 5005
d62a17ae 5006static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5007 const char *keep_str, const char *hold_str)
718e3744 5008{
d62a17ae 5009 int ret;
5010 struct peer *peer;
d7c0a89a
QY
5011 uint32_t keepalive;
5012 uint32_t holdtime;
718e3744 5013
d62a17ae 5014 peer = peer_and_group_lookup_vty(vty, ip_str);
5015 if (!peer)
5016 return CMD_WARNING_CONFIG_FAILED;
718e3744 5017
d62a17ae 5018 keepalive = strtoul(keep_str, NULL, 10);
5019 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5020
d62a17ae 5021 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5022
d62a17ae 5023 return bgp_vty_return(vty, ret);
718e3744 5024}
6b0655a2 5025
d62a17ae 5026static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5027{
d62a17ae 5028 int ret;
5029 struct peer *peer;
718e3744 5030
d62a17ae 5031 peer = peer_and_group_lookup_vty(vty, ip_str);
5032 if (!peer)
5033 return CMD_WARNING_CONFIG_FAILED;
718e3744 5034
d62a17ae 5035 ret = peer_timers_unset(peer);
718e3744 5036
d62a17ae 5037 return bgp_vty_return(vty, ret);
718e3744 5038}
5039
5040DEFUN (neighbor_timers,
5041 neighbor_timers_cmd,
9ccf14f7 5042 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5043 NEIGHBOR_STR
5044 NEIGHBOR_ADDR_STR2
5045 "BGP per neighbor timers\n"
5046 "Keepalive interval\n"
5047 "Holdtime\n")
5048{
d62a17ae 5049 int idx_peer = 1;
5050 int idx_number = 3;
5051 int idx_number_2 = 4;
5052 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5053 argv[idx_number]->arg,
5054 argv[idx_number_2]->arg);
718e3744 5055}
5056
5057DEFUN (no_neighbor_timers,
5058 no_neighbor_timers_cmd,
9ccf14f7 5059 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5060 NO_STR
5061 NEIGHBOR_STR
5062 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5063 "BGP per neighbor timers\n"
5064 "Keepalive interval\n"
5065 "Holdtime\n")
718e3744 5066{
d62a17ae 5067 int idx_peer = 2;
5068 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5069}
6b0655a2 5070
813d4307 5071
d62a17ae 5072static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5073 const char *time_str)
718e3744 5074{
d62a17ae 5075 int ret;
5076 struct peer *peer;
d7c0a89a 5077 uint32_t connect;
718e3744 5078
d62a17ae 5079 peer = peer_and_group_lookup_vty(vty, ip_str);
5080 if (!peer)
5081 return CMD_WARNING_CONFIG_FAILED;
718e3744 5082
d62a17ae 5083 connect = strtoul(time_str, NULL, 10);
718e3744 5084
d62a17ae 5085 ret = peer_timers_connect_set(peer, connect);
718e3744 5086
d62a17ae 5087 return bgp_vty_return(vty, ret);
718e3744 5088}
5089
d62a17ae 5090static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5091{
d62a17ae 5092 int ret;
5093 struct peer *peer;
718e3744 5094
d62a17ae 5095 peer = peer_and_group_lookup_vty(vty, ip_str);
5096 if (!peer)
5097 return CMD_WARNING_CONFIG_FAILED;
718e3744 5098
d62a17ae 5099 ret = peer_timers_connect_unset(peer);
718e3744 5100
d62a17ae 5101 return bgp_vty_return(vty, ret);
718e3744 5102}
5103
5104DEFUN (neighbor_timers_connect,
5105 neighbor_timers_connect_cmd,
9ccf14f7 5106 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5107 NEIGHBOR_STR
966f821c 5108 NEIGHBOR_ADDR_STR2
718e3744 5109 "BGP per neighbor timers\n"
5110 "BGP connect timer\n"
5111 "Connect timer\n")
5112{
d62a17ae 5113 int idx_peer = 1;
5114 int idx_number = 4;
5115 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5116 argv[idx_number]->arg);
718e3744 5117}
5118
5119DEFUN (no_neighbor_timers_connect,
5120 no_neighbor_timers_connect_cmd,
9ccf14f7 5121 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5122 NO_STR
5123 NEIGHBOR_STR
966f821c 5124 NEIGHBOR_ADDR_STR2
718e3744 5125 "BGP per neighbor timers\n"
8334fd5a
DW
5126 "BGP connect timer\n"
5127 "Connect timer\n")
718e3744 5128{
d62a17ae 5129 int idx_peer = 2;
5130 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5131}
5132
6b0655a2 5133
d62a17ae 5134static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5135 const char *time_str, int set)
718e3744 5136{
d62a17ae 5137 int ret;
5138 struct peer *peer;
d7c0a89a 5139 uint32_t routeadv = 0;
718e3744 5140
d62a17ae 5141 peer = peer_and_group_lookup_vty(vty, ip_str);
5142 if (!peer)
5143 return CMD_WARNING_CONFIG_FAILED;
718e3744 5144
d62a17ae 5145 if (time_str)
5146 routeadv = strtoul(time_str, NULL, 10);
718e3744 5147
d62a17ae 5148 if (set)
5149 ret = peer_advertise_interval_set(peer, routeadv);
5150 else
5151 ret = peer_advertise_interval_unset(peer);
718e3744 5152
d62a17ae 5153 return bgp_vty_return(vty, ret);
718e3744 5154}
5155
5156DEFUN (neighbor_advertise_interval,
5157 neighbor_advertise_interval_cmd,
9ccf14f7 5158 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5159 NEIGHBOR_STR
966f821c 5160 NEIGHBOR_ADDR_STR2
718e3744 5161 "Minimum interval between sending BGP routing updates\n"
5162 "time in seconds\n")
5163{
d62a17ae 5164 int idx_peer = 1;
5165 int idx_number = 3;
5166 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5167 argv[idx_number]->arg, 1);
718e3744 5168}
5169
5170DEFUN (no_neighbor_advertise_interval,
5171 no_neighbor_advertise_interval_cmd,
9ccf14f7 5172 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5173 NO_STR
5174 NEIGHBOR_STR
966f821c 5175 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5176 "Minimum interval between sending BGP routing updates\n"
5177 "time in seconds\n")
718e3744 5178{
d62a17ae 5179 int idx_peer = 2;
5180 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5181}
5182
6b0655a2 5183
518f0eb1
DS
5184/* Time to wait before processing route-map updates */
5185DEFUN (bgp_set_route_map_delay_timer,
5186 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5187 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5188 SET_STR
5189 "BGP route-map delay timer\n"
5190 "Time in secs to wait before processing route-map changes\n"
f414725f 5191 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5192{
d62a17ae 5193 int idx_number = 3;
d7c0a89a 5194 uint32_t rmap_delay_timer;
d62a17ae 5195
5196 if (argv[idx_number]->arg) {
5197 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5198 bm->rmap_update_timer = rmap_delay_timer;
5199
5200 /* if the dynamic update handling is being disabled, and a timer
5201 * is
5202 * running, stop the timer and act as if the timer has already
5203 * fired.
5204 */
5205 if (!rmap_delay_timer && bm->t_rmap_update) {
5206 BGP_TIMER_OFF(bm->t_rmap_update);
5207 thread_execute(bm->master, bgp_route_map_update_timer,
5208 NULL, 0);
5209 }
5210 return CMD_SUCCESS;
5211 } else {
5212 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5213 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5214 }
518f0eb1
DS
5215}
5216
5217DEFUN (no_bgp_set_route_map_delay_timer,
5218 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5219 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5220 NO_STR
3a2d747c 5221 BGP_STR
518f0eb1 5222 "Default BGP route-map delay timer\n"
8334fd5a
DW
5223 "Reset to default time to wait for processing route-map changes\n"
5224 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5225{
518f0eb1 5226
d62a17ae 5227 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5228
d62a17ae 5229 return CMD_SUCCESS;
518f0eb1
DS
5230}
5231
f414725f 5232
718e3744 5233/* neighbor interface */
d62a17ae 5234static int peer_interface_vty(struct vty *vty, const char *ip_str,
5235 const char *str)
718e3744 5236{
d62a17ae 5237 struct peer *peer;
718e3744 5238
d62a17ae 5239 peer = peer_lookup_vty(vty, ip_str);
5240 if (!peer || peer->conf_if) {
5241 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5242 return CMD_WARNING_CONFIG_FAILED;
5243 }
718e3744 5244
d62a17ae 5245 if (str)
5246 peer_interface_set(peer, str);
5247 else
5248 peer_interface_unset(peer);
718e3744 5249
d62a17ae 5250 return CMD_SUCCESS;
718e3744 5251}
5252
5253DEFUN (neighbor_interface,
5254 neighbor_interface_cmd,
9ccf14f7 5255 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5256 NEIGHBOR_STR
5257 NEIGHBOR_ADDR_STR
5258 "Interface\n"
5259 "Interface name\n")
5260{
d62a17ae 5261 int idx_ip = 1;
5262 int idx_word = 3;
5263 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5264}
5265
5266DEFUN (no_neighbor_interface,
5267 no_neighbor_interface_cmd,
9ccf14f7 5268 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5269 NO_STR
5270 NEIGHBOR_STR
16cedbb0 5271 NEIGHBOR_ADDR_STR2
718e3744 5272 "Interface\n"
5273 "Interface name\n")
5274{
d62a17ae 5275 int idx_peer = 2;
5276 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5277}
6b0655a2 5278
718e3744 5279DEFUN (neighbor_distribute_list,
5280 neighbor_distribute_list_cmd,
9ccf14f7 5281 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5282 NEIGHBOR_STR
5283 NEIGHBOR_ADDR_STR2
5284 "Filter updates to/from this neighbor\n"
5285 "IP access-list number\n"
5286 "IP access-list number (expanded range)\n"
5287 "IP Access-list name\n"
5288 "Filter incoming updates\n"
5289 "Filter outgoing updates\n")
5290{
d62a17ae 5291 int idx_peer = 1;
5292 int idx_acl = 3;
5293 int direct, ret;
5294 struct peer *peer;
a8206004 5295
d62a17ae 5296 const char *pstr = argv[idx_peer]->arg;
5297 const char *acl = argv[idx_acl]->arg;
5298 const char *inout = argv[argc - 1]->text;
a8206004 5299
d62a17ae 5300 peer = peer_and_group_lookup_vty(vty, pstr);
5301 if (!peer)
5302 return CMD_WARNING_CONFIG_FAILED;
a8206004 5303
d62a17ae 5304 /* Check filter direction. */
5305 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5306 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5307 direct, acl);
a8206004 5308
d62a17ae 5309 return bgp_vty_return(vty, ret);
718e3744 5310}
5311
d62a17ae 5312ALIAS_HIDDEN(
5313 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5314 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5315 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5316 "Filter updates to/from this neighbor\n"
5317 "IP access-list number\n"
5318 "IP access-list number (expanded range)\n"
5319 "IP Access-list name\n"
5320 "Filter incoming updates\n"
5321 "Filter outgoing updates\n")
596c17ba 5322
718e3744 5323DEFUN (no_neighbor_distribute_list,
5324 no_neighbor_distribute_list_cmd,
9ccf14f7 5325 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5326 NO_STR
5327 NEIGHBOR_STR
5328 NEIGHBOR_ADDR_STR2
5329 "Filter updates to/from this neighbor\n"
5330 "IP access-list number\n"
5331 "IP access-list number (expanded range)\n"
5332 "IP Access-list name\n"
5333 "Filter incoming updates\n"
5334 "Filter outgoing updates\n")
5335{
d62a17ae 5336 int idx_peer = 2;
5337 int direct, ret;
5338 struct peer *peer;
a8206004 5339
d62a17ae 5340 const char *pstr = argv[idx_peer]->arg;
5341 const char *inout = argv[argc - 1]->text;
a8206004 5342
d62a17ae 5343 peer = peer_and_group_lookup_vty(vty, pstr);
5344 if (!peer)
5345 return CMD_WARNING_CONFIG_FAILED;
a8206004 5346
d62a17ae 5347 /* Check filter direction. */
5348 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5349 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5350 direct);
a8206004 5351
d62a17ae 5352 return bgp_vty_return(vty, ret);
718e3744 5353}
6b0655a2 5354
d62a17ae 5355ALIAS_HIDDEN(
5356 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5357 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5358 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5359 "Filter updates to/from this neighbor\n"
5360 "IP access-list number\n"
5361 "IP access-list number (expanded range)\n"
5362 "IP Access-list name\n"
5363 "Filter incoming updates\n"
5364 "Filter outgoing updates\n")
596c17ba 5365
718e3744 5366/* Set prefix list to the peer. */
d62a17ae 5367static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5368 afi_t afi, safi_t safi,
5369 const char *name_str,
5370 const char *direct_str)
718e3744 5371{
d62a17ae 5372 int ret;
d62a17ae 5373 int direct = FILTER_IN;
cf9ac8bf 5374 struct peer *peer;
718e3744 5375
d62a17ae 5376 peer = peer_and_group_lookup_vty(vty, ip_str);
5377 if (!peer)
5378 return CMD_WARNING_CONFIG_FAILED;
718e3744 5379
d62a17ae 5380 /* Check filter direction. */
5381 if (strncmp(direct_str, "i", 1) == 0)
5382 direct = FILTER_IN;
5383 else if (strncmp(direct_str, "o", 1) == 0)
5384 direct = FILTER_OUT;
718e3744 5385
d62a17ae 5386 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5387
d62a17ae 5388 return bgp_vty_return(vty, ret);
718e3744 5389}
5390
d62a17ae 5391static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5392 afi_t afi, safi_t safi,
5393 const char *direct_str)
718e3744 5394{
d62a17ae 5395 int ret;
5396 struct peer *peer;
5397 int direct = FILTER_IN;
718e3744 5398
d62a17ae 5399 peer = peer_and_group_lookup_vty(vty, ip_str);
5400 if (!peer)
5401 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5402
d62a17ae 5403 /* Check filter direction. */
5404 if (strncmp(direct_str, "i", 1) == 0)
5405 direct = FILTER_IN;
5406 else if (strncmp(direct_str, "o", 1) == 0)
5407 direct = FILTER_OUT;
718e3744 5408
d62a17ae 5409 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5410
d62a17ae 5411 return bgp_vty_return(vty, ret);
718e3744 5412}
5413
5414DEFUN (neighbor_prefix_list,
5415 neighbor_prefix_list_cmd,
9ccf14f7 5416 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5417 NEIGHBOR_STR
5418 NEIGHBOR_ADDR_STR2
5419 "Filter updates to/from this neighbor\n"
5420 "Name of a prefix list\n"
5421 "Filter incoming updates\n"
5422 "Filter outgoing updates\n")
5423{
d62a17ae 5424 int idx_peer = 1;
5425 int idx_word = 3;
5426 int idx_in_out = 4;
5427 return peer_prefix_list_set_vty(
5428 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5429 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5430}
5431
d62a17ae 5432ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5433 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5434 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5435 "Filter updates to/from this neighbor\n"
5436 "Name of a prefix list\n"
5437 "Filter incoming updates\n"
5438 "Filter outgoing updates\n")
596c17ba 5439
718e3744 5440DEFUN (no_neighbor_prefix_list,
5441 no_neighbor_prefix_list_cmd,
9ccf14f7 5442 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5443 NO_STR
5444 NEIGHBOR_STR
5445 NEIGHBOR_ADDR_STR2
5446 "Filter updates to/from this neighbor\n"
5447 "Name of a prefix list\n"
5448 "Filter incoming updates\n"
5449 "Filter outgoing updates\n")
5450{
d62a17ae 5451 int idx_peer = 2;
5452 int idx_in_out = 5;
5453 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5454 bgp_node_afi(vty), bgp_node_safi(vty),
5455 argv[idx_in_out]->arg);
718e3744 5456}
6b0655a2 5457
d62a17ae 5458ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5459 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5460 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5461 "Filter updates to/from this neighbor\n"
5462 "Name of a prefix list\n"
5463 "Filter incoming updates\n"
5464 "Filter outgoing updates\n")
596c17ba 5465
d62a17ae 5466static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5467 safi_t safi, const char *name_str,
5468 const char *direct_str)
718e3744 5469{
d62a17ae 5470 int ret;
5471 struct peer *peer;
5472 int direct = FILTER_IN;
718e3744 5473
d62a17ae 5474 peer = peer_and_group_lookup_vty(vty, ip_str);
5475 if (!peer)
5476 return CMD_WARNING_CONFIG_FAILED;
718e3744 5477
d62a17ae 5478 /* Check filter direction. */
5479 if (strncmp(direct_str, "i", 1) == 0)
5480 direct = FILTER_IN;
5481 else if (strncmp(direct_str, "o", 1) == 0)
5482 direct = FILTER_OUT;
718e3744 5483
d62a17ae 5484 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5485
d62a17ae 5486 return bgp_vty_return(vty, ret);
718e3744 5487}
5488
d62a17ae 5489static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5490 safi_t safi, const char *direct_str)
718e3744 5491{
d62a17ae 5492 int ret;
5493 struct peer *peer;
5494 int direct = FILTER_IN;
718e3744 5495
d62a17ae 5496 peer = peer_and_group_lookup_vty(vty, ip_str);
5497 if (!peer)
5498 return CMD_WARNING_CONFIG_FAILED;
718e3744 5499
d62a17ae 5500 /* Check filter direction. */
5501 if (strncmp(direct_str, "i", 1) == 0)
5502 direct = FILTER_IN;
5503 else if (strncmp(direct_str, "o", 1) == 0)
5504 direct = FILTER_OUT;
718e3744 5505
d62a17ae 5506 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5507
d62a17ae 5508 return bgp_vty_return(vty, ret);
718e3744 5509}
5510
5511DEFUN (neighbor_filter_list,
5512 neighbor_filter_list_cmd,
9ccf14f7 5513 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5514 NEIGHBOR_STR
5515 NEIGHBOR_ADDR_STR2
5516 "Establish BGP filters\n"
5517 "AS path access-list name\n"
5518 "Filter incoming routes\n"
5519 "Filter outgoing routes\n")
5520{
d62a17ae 5521 int idx_peer = 1;
5522 int idx_word = 3;
5523 int idx_in_out = 4;
5524 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5525 bgp_node_safi(vty), argv[idx_word]->arg,
5526 argv[idx_in_out]->arg);
718e3744 5527}
5528
d62a17ae 5529ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5530 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5531 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5532 "Establish BGP filters\n"
5533 "AS path access-list name\n"
5534 "Filter incoming routes\n"
5535 "Filter outgoing routes\n")
596c17ba 5536
718e3744 5537DEFUN (no_neighbor_filter_list,
5538 no_neighbor_filter_list_cmd,
9ccf14f7 5539 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5540 NO_STR
5541 NEIGHBOR_STR
5542 NEIGHBOR_ADDR_STR2
5543 "Establish BGP filters\n"
5544 "AS path access-list name\n"
5545 "Filter incoming routes\n"
5546 "Filter outgoing routes\n")
5547{
d62a17ae 5548 int idx_peer = 2;
5549 int idx_in_out = 5;
5550 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5551 bgp_node_afi(vty), bgp_node_safi(vty),
5552 argv[idx_in_out]->arg);
718e3744 5553}
6b0655a2 5554
d62a17ae 5555ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5556 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5557 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5558 "Establish BGP filters\n"
5559 "AS path access-list name\n"
5560 "Filter incoming routes\n"
5561 "Filter outgoing routes\n")
596c17ba 5562
718e3744 5563/* Set route-map to the peer. */
d62a17ae 5564static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5565 afi_t afi, safi_t safi, const char *name_str,
5566 const char *direct_str)
718e3744 5567{
d62a17ae 5568 int ret;
5569 struct peer *peer;
5570 int direct = RMAP_IN;
718e3744 5571
d62a17ae 5572 peer = peer_and_group_lookup_vty(vty, ip_str);
5573 if (!peer)
5574 return CMD_WARNING_CONFIG_FAILED;
718e3744 5575
d62a17ae 5576 /* Check filter direction. */
5577 if (strncmp(direct_str, "in", 2) == 0)
5578 direct = RMAP_IN;
5579 else if (strncmp(direct_str, "o", 1) == 0)
5580 direct = RMAP_OUT;
718e3744 5581
d62a17ae 5582 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5583
d62a17ae 5584 return bgp_vty_return(vty, ret);
718e3744 5585}
5586
d62a17ae 5587static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5588 afi_t afi, safi_t safi,
5589 const char *direct_str)
718e3744 5590{
d62a17ae 5591 int ret;
5592 struct peer *peer;
5593 int direct = RMAP_IN;
718e3744 5594
d62a17ae 5595 peer = peer_and_group_lookup_vty(vty, ip_str);
5596 if (!peer)
5597 return CMD_WARNING_CONFIG_FAILED;
718e3744 5598
d62a17ae 5599 /* Check filter direction. */
5600 if (strncmp(direct_str, "in", 2) == 0)
5601 direct = RMAP_IN;
5602 else if (strncmp(direct_str, "o", 1) == 0)
5603 direct = RMAP_OUT;
718e3744 5604
d62a17ae 5605 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5606
d62a17ae 5607 return bgp_vty_return(vty, ret);
718e3744 5608}
5609
5610DEFUN (neighbor_route_map,
5611 neighbor_route_map_cmd,
9ccf14f7 5612 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5613 NEIGHBOR_STR
5614 NEIGHBOR_ADDR_STR2
5615 "Apply route map to neighbor\n"
5616 "Name of route map\n"
5617 "Apply map to incoming routes\n"
2a3d5731 5618 "Apply map to outbound routes\n")
718e3744 5619{
d62a17ae 5620 int idx_peer = 1;
5621 int idx_word = 3;
5622 int idx_in_out = 4;
5623 return peer_route_map_set_vty(
5624 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5625 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5626}
5627
d62a17ae 5628ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5629 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5630 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5631 "Apply route map to neighbor\n"
5632 "Name of route map\n"
5633 "Apply map to incoming routes\n"
5634 "Apply map to outbound routes\n")
596c17ba 5635
718e3744 5636DEFUN (no_neighbor_route_map,
5637 no_neighbor_route_map_cmd,
9ccf14f7 5638 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5639 NO_STR
5640 NEIGHBOR_STR
5641 NEIGHBOR_ADDR_STR2
5642 "Apply route map to neighbor\n"
5643 "Name of route map\n"
5644 "Apply map to incoming routes\n"
2a3d5731 5645 "Apply map to outbound routes\n")
718e3744 5646{
d62a17ae 5647 int idx_peer = 2;
5648 int idx_in_out = 5;
5649 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5650 bgp_node_afi(vty), bgp_node_safi(vty),
5651 argv[idx_in_out]->arg);
718e3744 5652}
6b0655a2 5653
d62a17ae 5654ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5655 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5656 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5657 "Apply route map to neighbor\n"
5658 "Name of route map\n"
5659 "Apply map to incoming routes\n"
5660 "Apply map to outbound routes\n")
596c17ba 5661
718e3744 5662/* Set unsuppress-map to the peer. */
d62a17ae 5663static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5664 afi_t afi, safi_t safi,
5665 const char *name_str)
718e3744 5666{
d62a17ae 5667 int ret;
5668 struct peer *peer;
718e3744 5669
d62a17ae 5670 peer = peer_and_group_lookup_vty(vty, ip_str);
5671 if (!peer)
5672 return CMD_WARNING_CONFIG_FAILED;
718e3744 5673
d62a17ae 5674 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5675
d62a17ae 5676 return bgp_vty_return(vty, ret);
718e3744 5677}
5678
5679/* Unset route-map from the peer. */
d62a17ae 5680static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5681 afi_t afi, safi_t safi)
718e3744 5682{
d62a17ae 5683 int ret;
5684 struct peer *peer;
718e3744 5685
d62a17ae 5686 peer = peer_and_group_lookup_vty(vty, ip_str);
5687 if (!peer)
5688 return CMD_WARNING_CONFIG_FAILED;
718e3744 5689
d62a17ae 5690 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5691
d62a17ae 5692 return bgp_vty_return(vty, ret);
718e3744 5693}
5694
5695DEFUN (neighbor_unsuppress_map,
5696 neighbor_unsuppress_map_cmd,
9ccf14f7 5697 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5698 NEIGHBOR_STR
5699 NEIGHBOR_ADDR_STR2
5700 "Route-map to selectively unsuppress suppressed routes\n"
5701 "Name of route map\n")
5702{
d62a17ae 5703 int idx_peer = 1;
5704 int idx_word = 3;
5705 return peer_unsuppress_map_set_vty(
5706 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5707 argv[idx_word]->arg);
718e3744 5708}
5709
d62a17ae 5710ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5711 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5712 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5713 "Route-map to selectively unsuppress suppressed routes\n"
5714 "Name of route map\n")
596c17ba 5715
718e3744 5716DEFUN (no_neighbor_unsuppress_map,
5717 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5718 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5719 NO_STR
5720 NEIGHBOR_STR
5721 NEIGHBOR_ADDR_STR2
5722 "Route-map to selectively unsuppress suppressed routes\n"
5723 "Name of route map\n")
5724{
d62a17ae 5725 int idx_peer = 2;
5726 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5727 bgp_node_afi(vty),
5728 bgp_node_safi(vty));
718e3744 5729}
6b0655a2 5730
d62a17ae 5731ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5732 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5733 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5734 "Route-map to selectively unsuppress suppressed routes\n"
5735 "Name of route map\n")
596c17ba 5736
d62a17ae 5737static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5738 afi_t afi, safi_t safi,
5739 const char *num_str,
5740 const char *threshold_str, int warning,
5741 const char *restart_str)
718e3744 5742{
d62a17ae 5743 int ret;
5744 struct peer *peer;
d7c0a89a
QY
5745 uint32_t max;
5746 uint8_t threshold;
5747 uint16_t restart;
718e3744 5748
d62a17ae 5749 peer = peer_and_group_lookup_vty(vty, ip_str);
5750 if (!peer)
5751 return CMD_WARNING_CONFIG_FAILED;
718e3744 5752
d62a17ae 5753 max = strtoul(num_str, NULL, 10);
5754 if (threshold_str)
5755 threshold = atoi(threshold_str);
5756 else
5757 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5758
d62a17ae 5759 if (restart_str)
5760 restart = atoi(restart_str);
5761 else
5762 restart = 0;
0a486e5f 5763
d62a17ae 5764 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5765 restart);
718e3744 5766
d62a17ae 5767 return bgp_vty_return(vty, ret);
718e3744 5768}
5769
d62a17ae 5770static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5771 afi_t afi, safi_t safi)
718e3744 5772{
d62a17ae 5773 int ret;
5774 struct peer *peer;
718e3744 5775
d62a17ae 5776 peer = peer_and_group_lookup_vty(vty, ip_str);
5777 if (!peer)
5778 return CMD_WARNING_CONFIG_FAILED;
718e3744 5779
d62a17ae 5780 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5781
d62a17ae 5782 return bgp_vty_return(vty, ret);
718e3744 5783}
5784
5785/* Maximum number of prefix configuration. prefix count is different
5786 for each peer configuration. So this configuration can be set for
5787 each peer configuration. */
5788DEFUN (neighbor_maximum_prefix,
5789 neighbor_maximum_prefix_cmd,
9ccf14f7 5790 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5791 NEIGHBOR_STR
5792 NEIGHBOR_ADDR_STR2
5793 "Maximum number of prefix accept from this peer\n"
5794 "maximum no. of prefix limit\n")
5795{
d62a17ae 5796 int idx_peer = 1;
5797 int idx_number = 3;
5798 return peer_maximum_prefix_set_vty(
5799 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5800 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5801}
5802
d62a17ae 5803ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5804 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5805 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5806 "Maximum number of prefix accept from this peer\n"
5807 "maximum no. of prefix limit\n")
596c17ba 5808
e0701b79 5809DEFUN (neighbor_maximum_prefix_threshold,
5810 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5811 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5812 NEIGHBOR_STR
5813 NEIGHBOR_ADDR_STR2
5814 "Maximum number of prefix accept from this peer\n"
5815 "maximum no. of prefix limit\n"
5816 "Threshold value (%) at which to generate a warning msg\n")
5817{
d62a17ae 5818 int idx_peer = 1;
5819 int idx_number = 3;
5820 int idx_number_2 = 4;
5821 return peer_maximum_prefix_set_vty(
5822 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5823 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5824}
e0701b79 5825
d62a17ae 5826ALIAS_HIDDEN(
5827 neighbor_maximum_prefix_threshold,
5828 neighbor_maximum_prefix_threshold_hidden_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5831 "Maximum number of prefix accept from this peer\n"
5832 "maximum no. of prefix limit\n"
5833 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5834
718e3744 5835DEFUN (neighbor_maximum_prefix_warning,
5836 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5837 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5838 NEIGHBOR_STR
5839 NEIGHBOR_ADDR_STR2
5840 "Maximum number of prefix accept from this peer\n"
5841 "maximum no. of prefix limit\n"
5842 "Only give warning message when limit is exceeded\n")
5843{
d62a17ae 5844 int idx_peer = 1;
5845 int idx_number = 3;
5846 return peer_maximum_prefix_set_vty(
5847 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5848 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5849}
5850
d62a17ae 5851ALIAS_HIDDEN(
5852 neighbor_maximum_prefix_warning,
5853 neighbor_maximum_prefix_warning_hidden_cmd,
5854 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5855 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5856 "Maximum number of prefix accept from this peer\n"
5857 "maximum no. of prefix limit\n"
5858 "Only give warning message when limit is exceeded\n")
596c17ba 5859
e0701b79 5860DEFUN (neighbor_maximum_prefix_threshold_warning,
5861 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5862 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5863 NEIGHBOR_STR
5864 NEIGHBOR_ADDR_STR2
5865 "Maximum number of prefix accept from this peer\n"
5866 "maximum no. of prefix limit\n"
5867 "Threshold value (%) at which to generate a warning msg\n"
5868 "Only give warning message when limit is exceeded\n")
5869{
d62a17ae 5870 int idx_peer = 1;
5871 int idx_number = 3;
5872 int idx_number_2 = 4;
5873 return peer_maximum_prefix_set_vty(
5874 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5875 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5876}
5877
d62a17ae 5878ALIAS_HIDDEN(
5879 neighbor_maximum_prefix_threshold_warning,
5880 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5881 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5882 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5883 "Maximum number of prefix accept from this peer\n"
5884 "maximum no. of prefix limit\n"
5885 "Threshold value (%) at which to generate a warning msg\n"
5886 "Only give warning message when limit is exceeded\n")
596c17ba 5887
0a486e5f 5888DEFUN (neighbor_maximum_prefix_restart,
5889 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5890 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5891 NEIGHBOR_STR
5892 NEIGHBOR_ADDR_STR2
5893 "Maximum number of prefix accept from this peer\n"
5894 "maximum no. of prefix limit\n"
5895 "Restart bgp connection after limit is exceeded\n"
efd7904e 5896 "Restart interval in minutes\n")
0a486e5f 5897{
d62a17ae 5898 int idx_peer = 1;
5899 int idx_number = 3;
5900 int idx_number_2 = 5;
5901 return peer_maximum_prefix_set_vty(
5902 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5903 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5904}
5905
d62a17ae 5906ALIAS_HIDDEN(
5907 neighbor_maximum_prefix_restart,
5908 neighbor_maximum_prefix_restart_hidden_cmd,
5909 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5910 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5911 "Maximum number of prefix accept from this peer\n"
5912 "maximum no. of prefix limit\n"
5913 "Restart bgp connection after limit is exceeded\n"
efd7904e 5914 "Restart interval in minutes\n")
596c17ba 5915
0a486e5f 5916DEFUN (neighbor_maximum_prefix_threshold_restart,
5917 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5918 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5919 NEIGHBOR_STR
5920 NEIGHBOR_ADDR_STR2
16cedbb0 5921 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5922 "maximum no. of prefix limit\n"
5923 "Threshold value (%) at which to generate a warning msg\n"
5924 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5925 "Restart interval in minutes\n")
0a486e5f 5926{
d62a17ae 5927 int idx_peer = 1;
5928 int idx_number = 3;
5929 int idx_number_2 = 4;
5930 int idx_number_3 = 6;
5931 return peer_maximum_prefix_set_vty(
5932 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5933 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5934 argv[idx_number_3]->arg);
5935}
5936
5937ALIAS_HIDDEN(
5938 neighbor_maximum_prefix_threshold_restart,
5939 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5940 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5941 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5942 "Maximum number of prefixes to accept from this peer\n"
5943 "maximum no. of prefix limit\n"
5944 "Threshold value (%) at which to generate a warning msg\n"
5945 "Restart bgp connection after limit is exceeded\n"
5946 "Restart interval in minutes\n")
596c17ba 5947
718e3744 5948DEFUN (no_neighbor_maximum_prefix,
5949 no_neighbor_maximum_prefix_cmd,
d04c479d 5950 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5951 NO_STR
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
16cedbb0 5954 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5955 "maximum no. of prefix limit\n"
5956 "Threshold value (%) at which to generate a warning msg\n"
5957 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5958 "Restart interval in minutes\n"
31500417 5959 "Only give warning message when limit is exceeded\n")
718e3744 5960{
d62a17ae 5961 int idx_peer = 2;
5962 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5963 bgp_node_afi(vty),
5964 bgp_node_safi(vty));
718e3744 5965}
e52702f2 5966
d62a17ae 5967ALIAS_HIDDEN(
5968 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5969 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5970 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5971 "Maximum number of prefixes to accept from this peer\n"
5972 "maximum no. of prefix limit\n"
5973 "Threshold value (%) at which to generate a warning msg\n"
5974 "Restart bgp connection after limit is exceeded\n"
5975 "Restart interval in minutes\n"
5976 "Only give warning message when limit is exceeded\n")
596c17ba 5977
718e3744 5978
718e3744 5979/* "neighbor allowas-in" */
5980DEFUN (neighbor_allowas_in,
5981 neighbor_allowas_in_cmd,
fd8503f5 5982 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5983 NEIGHBOR_STR
5984 NEIGHBOR_ADDR_STR2
31500417 5985 "Accept as-path with my AS present in it\n"
fd8503f5
QY
5986 "Number of occurances of AS number\n"
5987 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5988{
d62a17ae 5989 int idx_peer = 1;
5990 int idx_number_origin = 3;
5991 int ret;
5992 int origin = 0;
5993 struct peer *peer;
5994 int allow_num = 0;
5995
5996 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5997 if (!peer)
5998 return CMD_WARNING_CONFIG_FAILED;
5999
6000 if (argc <= idx_number_origin)
6001 allow_num = 3;
6002 else {
6003 if (argv[idx_number_origin]->type == WORD_TKN)
6004 origin = 1;
6005 else
6006 allow_num = atoi(argv[idx_number_origin]->arg);
6007 }
6008
6009 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6010 allow_num, origin);
6011
6012 return bgp_vty_return(vty, ret);
6013}
6014
6015ALIAS_HIDDEN(
6016 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6017 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6018 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6019 "Accept as-path with my AS present in it\n"
6020 "Number of occurances of AS number\n"
6021 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6022
718e3744 6023DEFUN (no_neighbor_allowas_in,
6024 no_neighbor_allowas_in_cmd,
fd8503f5 6025 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6026 NO_STR
6027 NEIGHBOR_STR
6028 NEIGHBOR_ADDR_STR2
8334fd5a 6029 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
6030 "Number of occurances of AS number\n"
6031 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6032{
d62a17ae 6033 int idx_peer = 2;
6034 int ret;
6035 struct peer *peer;
718e3744 6036
d62a17ae 6037 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6038 if (!peer)
6039 return CMD_WARNING_CONFIG_FAILED;
718e3744 6040
d62a17ae 6041 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6042 bgp_node_safi(vty));
718e3744 6043
d62a17ae 6044 return bgp_vty_return(vty, ret);
718e3744 6045}
6b0655a2 6046
d62a17ae 6047ALIAS_HIDDEN(
6048 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6049 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6050 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6051 "allow local ASN appears in aspath attribute\n"
6052 "Number of occurances of AS number\n"
6053 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6054
fa411a21
NH
6055DEFUN (neighbor_ttl_security,
6056 neighbor_ttl_security_cmd,
7ebe625c 6057 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6058 NEIGHBOR_STR
7ebe625c 6059 NEIGHBOR_ADDR_STR2
16cedbb0 6060 "BGP ttl-security parameters\n"
d7fa34c1
QY
6061 "Specify the maximum number of hops to the BGP peer\n"
6062 "Number of hops to BGP peer\n")
fa411a21 6063{
d62a17ae 6064 int idx_peer = 1;
6065 int idx_number = 4;
6066 struct peer *peer;
6067 int gtsm_hops;
6068
6069 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6070 if (!peer)
6071 return CMD_WARNING_CONFIG_FAILED;
6072
6073 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6074
7ebe625c
QY
6075 /*
6076 * If 'neighbor swpX', then this is for directly connected peers,
6077 * we should not accept a ttl-security hops value greater than 1.
6078 */
6079 if (peer->conf_if && (gtsm_hops > 1)) {
6080 vty_out(vty,
6081 "%s is directly connected peer, hops cannot exceed 1\n",
6082 argv[idx_peer]->arg);
6083 return CMD_WARNING_CONFIG_FAILED;
6084 }
6085
d62a17ae 6086 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6087}
6088
6089DEFUN (no_neighbor_ttl_security,
6090 no_neighbor_ttl_security_cmd,
7ebe625c 6091 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6092 NO_STR
6093 NEIGHBOR_STR
7ebe625c 6094 NEIGHBOR_ADDR_STR2
16cedbb0 6095 "BGP ttl-security parameters\n"
3a2d747c
QY
6096 "Specify the maximum number of hops to the BGP peer\n"
6097 "Number of hops to BGP peer\n")
fa411a21 6098{
d62a17ae 6099 int idx_peer = 2;
6100 struct peer *peer;
fa411a21 6101
d62a17ae 6102 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6103 if (!peer)
6104 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6105
d62a17ae 6106 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6107}
6b0655a2 6108
adbac85e
DW
6109DEFUN (neighbor_addpath_tx_all_paths,
6110 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6111 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6112 NEIGHBOR_STR
6113 NEIGHBOR_ADDR_STR2
6114 "Use addpath to advertise all paths to a neighbor\n")
6115{
d62a17ae 6116 int idx_peer = 1;
6117 struct peer *peer;
adbac85e 6118
d62a17ae 6119 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6120 if (!peer)
6121 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6122
d62a17ae 6123 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6124 bgp_node_safi(vty),
6125 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6126}
6127
d62a17ae 6128ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6129 neighbor_addpath_tx_all_paths_hidden_cmd,
6130 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6131 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6132 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6133
adbac85e
DW
6134DEFUN (no_neighbor_addpath_tx_all_paths,
6135 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6136 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6137 NO_STR
6138 NEIGHBOR_STR
6139 NEIGHBOR_ADDR_STR2
6140 "Use addpath to advertise all paths to a neighbor\n")
6141{
d62a17ae 6142 int idx_peer = 2;
6143 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6144 bgp_node_afi(vty), bgp_node_safi(vty),
6145 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6146}
6147
d62a17ae 6148ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6149 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6150 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6152 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6153
06370dac
DW
6154DEFUN (neighbor_addpath_tx_bestpath_per_as,
6155 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6156 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6157 NEIGHBOR_STR
6158 NEIGHBOR_ADDR_STR2
6159 "Use addpath to advertise the bestpath per each neighboring AS\n")
6160{
d62a17ae 6161 int idx_peer = 1;
6162 struct peer *peer;
06370dac 6163
d62a17ae 6164 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6165 if (!peer)
6166 return CMD_WARNING_CONFIG_FAILED;
06370dac 6167
d62a17ae 6168 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6169 bgp_node_safi(vty),
6170 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6171}
6172
d62a17ae 6173ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6174 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6175 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6176 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6177 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6178
06370dac
DW
6179DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6180 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6181 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6182 NO_STR
6183 NEIGHBOR_STR
6184 NEIGHBOR_ADDR_STR2
6185 "Use addpath to advertise the bestpath per each neighboring AS\n")
6186{
d62a17ae 6187 int idx_peer = 2;
6188 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6189 bgp_node_afi(vty), bgp_node_safi(vty),
6190 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6191}
6192
d62a17ae 6193ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6194 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6195 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6196 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6197 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6198
b9c7bc5a
PZ
6199static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6200 struct ecommunity **list)
ddb5b488 6201{
b9c7bc5a
PZ
6202 struct ecommunity *ecom = NULL;
6203 struct ecommunity *ecomadd;
ddb5b488 6204
b9c7bc5a 6205 for (; argc; --argc, ++argv) {
ddb5b488 6206
b9c7bc5a
PZ
6207 ecomadd = ecommunity_str2com(argv[0]->arg,
6208 ECOMMUNITY_ROUTE_TARGET, 0);
6209 if (!ecomadd) {
6210 vty_out(vty, "Malformed community-list value\n");
6211 if (ecom)
6212 ecommunity_free(&ecom);
6213 return CMD_WARNING_CONFIG_FAILED;
6214 }
ddb5b488 6215
b9c7bc5a
PZ
6216 if (ecom) {
6217 ecommunity_merge(ecom, ecomadd);
6218 ecommunity_free(&ecomadd);
6219 } else {
6220 ecom = ecomadd;
6221 }
6222 }
6223
6224 if (*list) {
6225 ecommunity_free(&*list);
ddb5b488 6226 }
b9c7bc5a
PZ
6227 *list = ecom;
6228
6229 return CMD_SUCCESS;
ddb5b488
PZ
6230}
6231
0ca70ba5
DS
6232/*
6233 * v2vimport is true if we are handling a `import vrf ...` command
6234 */
6235static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6236{
0ca70ba5
DS
6237 afi_t afi;
6238
ddb5b488 6239 switch (vty->node) {
b9c7bc5a 6240 case BGP_IPV4_NODE:
0ca70ba5
DS
6241 afi = AFI_IP;
6242 break;
b9c7bc5a 6243 case BGP_IPV6_NODE:
0ca70ba5
DS
6244 afi = AFI_IP6;
6245 break;
ddb5b488
PZ
6246 default:
6247 vty_out(vty,
b9c7bc5a 6248 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6249 return AFI_MAX;
ddb5b488 6250 }
69b07479 6251
0ca70ba5
DS
6252 if (!v2vimport) {
6253 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6254 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6255 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6256 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6257 vty_out(vty,
6258 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6259 return AFI_MAX;
6260 }
6261 } else {
6262 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6263 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6264 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6265 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6266 vty_out(vty,
6267 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6268 return AFI_MAX;
6269 }
6270 }
6271 return afi;
ddb5b488
PZ
6272}
6273
b9c7bc5a
PZ
6274DEFPY (af_rd_vpn_export,
6275 af_rd_vpn_export_cmd,
6276 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6277 NO_STR
ddb5b488 6278 "Specify route distinguisher\n"
b9c7bc5a
PZ
6279 "Between current address-family and vpn\n"
6280 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6281 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6282{
6283 VTY_DECLVAR_CONTEXT(bgp, bgp);
6284 struct prefix_rd prd;
6285 int ret;
ddb5b488 6286 afi_t afi;
b9c7bc5a
PZ
6287 int idx = 0;
6288 int yes = 1;
ddb5b488 6289
b9c7bc5a 6290 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6291 yes = 0;
b9c7bc5a
PZ
6292
6293 if (yes) {
6294 ret = str2prefix_rd(rd_str, &prd);
6295 if (!ret) {
6296 vty_out(vty, "%% Malformed rd\n");
6297 return CMD_WARNING_CONFIG_FAILED;
6298 }
ddb5b488
PZ
6299 }
6300
0ca70ba5 6301 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6302 if (afi == AFI_MAX)
6303 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6304
69b07479
DS
6305 /*
6306 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6307 */
6308 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6309 bgp_get_default(), bgp);
ddb5b488 6310
69b07479
DS
6311 if (yes) {
6312 bgp->vpn_policy[afi].tovpn_rd = prd;
6313 SET_FLAG(bgp->vpn_policy[afi].flags,
6314 BGP_VPN_POLICY_TOVPN_RD_SET);
6315 } else {
6316 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6317 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6318 }
6319
69b07479
DS
6320 /* post-change: re-export vpn routes */
6321 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6322 bgp_get_default(), bgp);
6323
ddb5b488
PZ
6324 return CMD_SUCCESS;
6325}
6326
b9c7bc5a
PZ
6327ALIAS (af_rd_vpn_export,
6328 af_no_rd_vpn_export_cmd,
6329 "no rd vpn export",
ddb5b488 6330 NO_STR
b9c7bc5a
PZ
6331 "Specify route distinguisher\n"
6332 "Between current address-family and vpn\n"
6333 "For routes leaked from current address-family to vpn\n")
ddb5b488 6334
b9c7bc5a
PZ
6335DEFPY (af_label_vpn_export,
6336 af_label_vpn_export_cmd,
e70e9f8e 6337 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6338 NO_STR
ddb5b488 6339 "label value for VRF\n"
b9c7bc5a
PZ
6340 "Between current address-family and vpn\n"
6341 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6342 "Label Value <0-1048575>\n"
6343 "Automatically assign a label\n")
ddb5b488
PZ
6344{
6345 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6346 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6347 afi_t afi;
b9c7bc5a
PZ
6348 int idx = 0;
6349 int yes = 1;
6350
6351 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6352 yes = 0;
ddb5b488 6353
21a16cc2
PZ
6354 /* If "no ...", squash trailing parameter */
6355 if (!yes)
6356 label_auto = NULL;
6357
e70e9f8e
PZ
6358 if (yes) {
6359 if (!label_auto)
6360 label = label_val; /* parser should force unsigned */
6361 }
ddb5b488 6362
0ca70ba5 6363 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6364 if (afi == AFI_MAX)
6365 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6366
e70e9f8e 6367
69b07479
DS
6368 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6369 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6370 /* no change */
6371 return CMD_SUCCESS;
e70e9f8e 6372
69b07479
DS
6373 /*
6374 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6375 */
6376 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6377 bgp_get_default(), bgp);
6378
6379 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6380 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6381
6382 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6383
6384 /*
6385 * label has previously been automatically
6386 * assigned by labelpool: release it
6387 *
6388 * NB if tovpn_label == MPLS_LABEL_NONE it
6389 * means the automatic assignment is in flight
6390 * and therefore the labelpool callback must
6391 * detect that the auto label is not needed.
6392 */
6393
6394 bgp_lp_release(LP_TYPE_VRF,
6395 &bgp->vpn_policy[afi],
6396 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6397 }
69b07479
DS
6398 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6399 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6400 }
ddb5b488 6401
69b07479
DS
6402 bgp->vpn_policy[afi].tovpn_label = label;
6403 if (label_auto) {
6404 SET_FLAG(bgp->vpn_policy[afi].flags,
6405 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6406 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6407 vpn_leak_label_callback);
ddb5b488
PZ
6408 }
6409
69b07479
DS
6410 /* post-change: re-export vpn routes */
6411 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6412 bgp_get_default(), bgp);
6413
ddb5b488
PZ
6414 return CMD_SUCCESS;
6415}
6416
b9c7bc5a
PZ
6417ALIAS (af_label_vpn_export,
6418 af_no_label_vpn_export_cmd,
6419 "no label vpn export",
6420 NO_STR
6421 "label value for VRF\n"
6422 "Between current address-family and vpn\n"
6423 "For routes leaked from current address-family to vpn\n")
ddb5b488 6424
b9c7bc5a
PZ
6425DEFPY (af_nexthop_vpn_export,
6426 af_nexthop_vpn_export_cmd,
6427 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6428 NO_STR
ddb5b488 6429 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6430 "Between current address-family and vpn\n"
6431 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6432 "IPv4 prefix\n"
6433 "IPv6 prefix\n")
6434{
6435 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6436 afi_t afi;
ddb5b488 6437 struct prefix p;
b9c7bc5a
PZ
6438 int idx = 0;
6439 int yes = 1;
ddb5b488 6440
b9c7bc5a 6441 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6442 yes = 0;
b9c7bc5a
PZ
6443
6444 if (yes) {
6445 if (!sockunion2hostprefix(nexthop_str, &p))
6446 return CMD_WARNING_CONFIG_FAILED;
6447 }
ddb5b488 6448
0ca70ba5 6449 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6450 if (afi == AFI_MAX)
6451 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6452
69b07479
DS
6453 /*
6454 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6455 */
6456 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6457 bgp_get_default(), bgp);
ddb5b488 6458
69b07479
DS
6459 if (yes) {
6460 bgp->vpn_policy[afi].tovpn_nexthop = p;
6461 SET_FLAG(bgp->vpn_policy[afi].flags,
6462 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6463 } else {
6464 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6465 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6466 }
6467
69b07479
DS
6468 /* post-change: re-export vpn routes */
6469 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6470 bgp_get_default(), bgp);
6471
ddb5b488
PZ
6472 return CMD_SUCCESS;
6473}
6474
b9c7bc5a
PZ
6475ALIAS (af_nexthop_vpn_export,
6476 af_no_nexthop_vpn_export_cmd,
6477 "no nexthop vpn export",
ddb5b488 6478 NO_STR
b9c7bc5a
PZ
6479 "Specify next hop to use for VRF advertised prefixes\n"
6480 "Between current address-family and vpn\n"
6481 "For routes leaked from current address-family to vpn\n")
ddb5b488 6482
b9c7bc5a 6483static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6484{
b9c7bc5a
PZ
6485 if (!strcmp(dstr, "import")) {
6486 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6487 } else if (!strcmp(dstr, "export")) {
6488 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6489 } else if (!strcmp(dstr, "both")) {
6490 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6491 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6492 } else {
6493 vty_out(vty, "%% direction parse error\n");
6494 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6495 }
ddb5b488
PZ
6496 return CMD_SUCCESS;
6497}
6498
b9c7bc5a
PZ
6499DEFPY (af_rt_vpn_imexport,
6500 af_rt_vpn_imexport_cmd,
6501 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6502 NO_STR
6503 "Specify route target list\n"
ddb5b488 6504 "Specify route target list\n"
b9c7bc5a
PZ
6505 "Between current address-family and vpn\n"
6506 "For routes leaked from vpn to current address-family: match any\n"
6507 "For routes leaked from current address-family to vpn: set\n"
6508 "both import: match any and export: set\n"
ddb5b488
PZ
6509 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6510{
6511 VTY_DECLVAR_CONTEXT(bgp, bgp);
6512 int ret;
6513 struct ecommunity *ecom = NULL;
6514 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6515 vpn_policy_direction_t dir;
6516 afi_t afi;
6517 int idx = 0;
b9c7bc5a 6518 int yes = 1;
ddb5b488 6519
b9c7bc5a 6520 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6521 yes = 0;
b9c7bc5a 6522
0ca70ba5 6523 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6524 if (afi == AFI_MAX)
6525 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6526
b9c7bc5a 6527 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6528 if (ret != CMD_SUCCESS)
6529 return ret;
6530
b9c7bc5a
PZ
6531 if (yes) {
6532 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6533 vty_out(vty, "%% Missing RTLIST\n");
6534 return CMD_WARNING_CONFIG_FAILED;
6535 }
6536 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6537 if (ret != CMD_SUCCESS) {
6538 return ret;
6539 }
ddb5b488
PZ
6540 }
6541
69b07479
DS
6542 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6543 if (!dodir[dir])
ddb5b488 6544 continue;
ddb5b488 6545
69b07479 6546 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6547
69b07479
DS
6548 if (yes) {
6549 if (bgp->vpn_policy[afi].rtlist[dir])
6550 ecommunity_free(
6551 &bgp->vpn_policy[afi].rtlist[dir]);
6552 bgp->vpn_policy[afi].rtlist[dir] =
6553 ecommunity_dup(ecom);
6554 } else {
6555 if (bgp->vpn_policy[afi].rtlist[dir])
6556 ecommunity_free(
6557 &bgp->vpn_policy[afi].rtlist[dir]);
6558 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6559 }
69b07479
DS
6560
6561 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6562 }
69b07479 6563
d555f3e9
PZ
6564 if (ecom)
6565 ecommunity_free(&ecom);
ddb5b488
PZ
6566
6567 return CMD_SUCCESS;
6568}
6569
b9c7bc5a
PZ
6570ALIAS (af_rt_vpn_imexport,
6571 af_no_rt_vpn_imexport_cmd,
6572 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6573 NO_STR
6574 "Specify route target list\n"
b9c7bc5a
PZ
6575 "Specify route target list\n"
6576 "Between current address-family and vpn\n"
6577 "For routes leaked from vpn to current address-family\n"
6578 "For routes leaked from current address-family to vpn\n"
6579 "both import and export\n")
6580
6581DEFPY (af_route_map_vpn_imexport,
6582 af_route_map_vpn_imexport_cmd,
6583/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6584 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6585 NO_STR
ddb5b488 6586 "Specify route map\n"
b9c7bc5a
PZ
6587 "Between current address-family and vpn\n"
6588 "For routes leaked from vpn to current address-family\n"
6589 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6590 "name of route-map\n")
6591{
6592 VTY_DECLVAR_CONTEXT(bgp, bgp);
6593 int ret;
6594 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6595 vpn_policy_direction_t dir;
6596 afi_t afi;
ddb5b488 6597 int idx = 0;
b9c7bc5a 6598 int yes = 1;
ddb5b488 6599
b9c7bc5a 6600 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6601 yes = 0;
b9c7bc5a 6602
0ca70ba5 6603 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6604 if (afi == AFI_MAX)
6605 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6606
b9c7bc5a 6607 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6608 if (ret != CMD_SUCCESS)
6609 return ret;
6610
69b07479
DS
6611 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6612 if (!dodir[dir])
ddb5b488 6613 continue;
ddb5b488 6614
69b07479 6615 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6616
69b07479
DS
6617 if (yes) {
6618 if (bgp->vpn_policy[afi].rmap_name[dir])
6619 XFREE(MTYPE_ROUTE_MAP_NAME,
6620 bgp->vpn_policy[afi].rmap_name[dir]);
6621 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6622 MTYPE_ROUTE_MAP_NAME, rmap_str);
6623 bgp->vpn_policy[afi].rmap[dir] =
6624 route_map_lookup_by_name(rmap_str);
6625 if (!bgp->vpn_policy[afi].rmap[dir])
6626 return CMD_SUCCESS;
6627 } else {
6628 if (bgp->vpn_policy[afi].rmap_name[dir])
6629 XFREE(MTYPE_ROUTE_MAP_NAME,
6630 bgp->vpn_policy[afi].rmap_name[dir]);
6631 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6632 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6633 }
69b07479
DS
6634
6635 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6636 }
6637
6638 return CMD_SUCCESS;
6639}
6640
b9c7bc5a
PZ
6641ALIAS (af_route_map_vpn_imexport,
6642 af_no_route_map_vpn_imexport_cmd,
6643 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6644 NO_STR
6645 "Specify route map\n"
b9c7bc5a
PZ
6646 "Between current address-family and vpn\n"
6647 "For routes leaked from vpn to current address-family\n"
6648 "For routes leaked from current address-family to vpn\n")
6649
bb4f6190
DS
6650DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6651 "[no] import vrf route-map RMAP$rmap_str",
6652 NO_STR
6653 "Import routes from another VRF\n"
6654 "Vrf routes being filtered\n"
6655 "Specify route map\n"
6656 "name of route-map\n")
6657{
6658 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6659 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6660 afi_t afi;
6661 int idx = 0;
6662 int yes = 1;
6663 struct bgp *bgp_default;
6664
6665 if (argv_find(argv, argc, "no", &idx))
6666 yes = 0;
6667
0ca70ba5 6668 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6669 if (afi == AFI_MAX)
6670 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6671
6672 bgp_default = bgp_get_default();
6673 if (!bgp_default) {
6674 int32_t ret;
6675 as_t as = bgp->as;
6676
6677 /* Auto-create assuming the same AS */
6678 ret = bgp_get(&bgp_default, &as, NULL,
6679 BGP_INSTANCE_TYPE_DEFAULT);
6680
6681 if (ret) {
6682 vty_out(vty,
6683 "VRF default is not configured as a bgp instance\n");
6684 return CMD_WARNING;
6685 }
6686 }
6687
69b07479 6688 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6689
69b07479
DS
6690 if (yes) {
6691 if (bgp->vpn_policy[afi].rmap_name[dir])
6692 XFREE(MTYPE_ROUTE_MAP_NAME,
6693 bgp->vpn_policy[afi].rmap_name[dir]);
6694 bgp->vpn_policy[afi].rmap_name[dir] =
6695 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6696 bgp->vpn_policy[afi].rmap[dir] =
6697 route_map_lookup_by_name(rmap_str);
6698 if (!bgp->vpn_policy[afi].rmap[dir])
6699 return CMD_SUCCESS;
6700 } else {
6701 if (bgp->vpn_policy[afi].rmap_name[dir])
6702 XFREE(MTYPE_ROUTE_MAP_NAME,
6703 bgp->vpn_policy[afi].rmap_name[dir]);
6704 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6705 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6706 }
6707
69b07479
DS
6708 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6709
bb4f6190
DS
6710 return CMD_SUCCESS;
6711}
6712
6713ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6714 "no import vrf route-map",
6715 NO_STR
6716 "Import routes from another VRF\n"
6717 "Vrf routes being filtered\n"
6718 "Specify route map\n")
6719
12a844a5
DS
6720DEFPY (bgp_imexport_vrf,
6721 bgp_imexport_vrf_cmd,
6722 "[no] import vrf NAME$import_name",
6723 NO_STR
6724 "Import routes from another VRF\n"
6725 "VRF to import from\n"
6726 "The name of the VRF\n")
6727{
6728 VTY_DECLVAR_CONTEXT(bgp, bgp);
6729 struct listnode *node;
79ef8664
DS
6730 struct bgp *vrf_bgp, *bgp_default;
6731 int32_t ret = 0;
6732 as_t as = bgp->as;
12a844a5
DS
6733 bool remove = false;
6734 int32_t idx = 0;
6735 char *vname;
a8dadcf6 6736 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6737 safi_t safi;
6738 afi_t afi;
6739
6740 if (argv_find(argv, argc, "no", &idx))
6741 remove = true;
6742
0ca70ba5
DS
6743 afi = vpn_policy_getafi(vty, bgp, true);
6744 if (afi == AFI_MAX)
6745 return CMD_WARNING_CONFIG_FAILED;
6746
12a844a5
DS
6747 safi = bgp_node_safi(vty);
6748
25679caa
DS
6749 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6750 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6751 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6752 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6753 remove ? "unimport" : "import", import_name);
6754 return CMD_WARNING;
6755 }
6756
79ef8664
DS
6757 bgp_default = bgp_get_default();
6758 if (!bgp_default) {
6759 /* Auto-create assuming the same AS */
6760 ret = bgp_get(&bgp_default, &as, NULL,
6761 BGP_INSTANCE_TYPE_DEFAULT);
6762
6763 if (ret) {
6764 vty_out(vty,
6765 "VRF default is not configured as a bgp instance\n");
6766 return CMD_WARNING;
6767 }
6768 }
6769
12a844a5
DS
6770 vrf_bgp = bgp_lookup_by_name(import_name);
6771 if (!vrf_bgp) {
79ef8664
DS
6772 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6773 vrf_bgp = bgp_default;
6774 else
0fb8d6e6
DS
6775 /* Auto-create assuming the same AS */
6776 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6777
6e2c7fe6 6778 if (ret) {
020a3f60
DS
6779 vty_out(vty,
6780 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6781 import_name);
6782 return CMD_WARNING;
6783 }
12a844a5
DS
6784 }
6785
12a844a5 6786 if (remove) {
44338987 6787 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6788 } else {
44338987 6789 /* Already importing from "import_vrf"? */
12a844a5
DS
6790 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6791 vname)) {
6792 if (strcmp(vname, import_name) == 0)
6793 return CMD_WARNING;
6794 }
6795
44338987 6796 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6797 }
6798
6799 return CMD_SUCCESS;
6800}
6801
b9c7bc5a
PZ
6802/* This command is valid only in a bgp vrf instance or the default instance */
6803DEFPY (bgp_imexport_vpn,
6804 bgp_imexport_vpn_cmd,
6805 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6806 NO_STR
6807 "Import routes to this address-family\n"
6808 "Export routes from this address-family\n"
6809 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6810{
6811 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6812 int previous_state;
ddb5b488 6813 afi_t afi;
b9c7bc5a 6814 safi_t safi;
ddb5b488 6815 int idx = 0;
b9c7bc5a
PZ
6816 int yes = 1;
6817 int flag;
6818 vpn_policy_direction_t dir;
ddb5b488 6819
b9c7bc5a 6820 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6821 yes = 0;
ddb5b488 6822
b9c7bc5a
PZ
6823 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6824 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6825
b9c7bc5a
PZ
6826 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6827 return CMD_WARNING_CONFIG_FAILED;
6828 }
ddb5b488 6829
b9c7bc5a
PZ
6830 afi = bgp_node_afi(vty);
6831 safi = bgp_node_safi(vty);
6832 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6833 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6834 return CMD_WARNING_CONFIG_FAILED;
6835 }
ddb5b488 6836
b9c7bc5a
PZ
6837 if (!strcmp(direction_str, "import")) {
6838 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6839 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6840 } else if (!strcmp(direction_str, "export")) {
6841 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6842 dir = BGP_VPN_POLICY_DIR_TOVPN;
6843 } else {
6844 vty_out(vty, "%% unknown direction %s\n", direction_str);
6845 return CMD_WARNING_CONFIG_FAILED;
6846 }
6847
6848 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 6849
b9c7bc5a
PZ
6850 if (yes) {
6851 SET_FLAG(bgp->af_flags[afi][safi], flag);
6852 if (!previous_state) {
6853 /* trigger export current vrf */
ddb5b488
PZ
6854 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6855 }
b9c7bc5a
PZ
6856 } else {
6857 if (previous_state) {
6858 /* trigger un-export current vrf */
6859 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6860 }
6861 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
6862 }
6863
6864 return CMD_SUCCESS;
6865}
6866
301ad80a
PG
6867DEFPY (af_routetarget_import,
6868 af_routetarget_import_cmd,
6869 "[no] <rt|route-target> redirect import RTLIST...",
6870 NO_STR
6871 "Specify route target list\n"
6872 "Specify route target list\n"
6873 "Flow-spec redirect type route target\n"
6874 "Import routes to this address-family\n"
6875 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6876{
6877 VTY_DECLVAR_CONTEXT(bgp, bgp);
6878 int ret;
6879 struct ecommunity *ecom = NULL;
301ad80a
PG
6880 afi_t afi;
6881 int idx = 0;
6882 int yes = 1;
6883
6884 if (argv_find(argv, argc, "no", &idx))
6885 yes = 0;
6886
0ca70ba5 6887 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6888 if (afi == AFI_MAX)
6889 return CMD_WARNING_CONFIG_FAILED;
6890
301ad80a
PG
6891 if (yes) {
6892 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6893 vty_out(vty, "%% Missing RTLIST\n");
6894 return CMD_WARNING_CONFIG_FAILED;
6895 }
6896 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6897 if (ret != CMD_SUCCESS)
6898 return ret;
6899 }
69b07479
DS
6900
6901 if (yes) {
6902 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6903 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6904 .import_redirect_rtlist);
69b07479
DS
6905 bgp->vpn_policy[afi].import_redirect_rtlist =
6906 ecommunity_dup(ecom);
6907 } else {
6908 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6909 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6910 .import_redirect_rtlist);
69b07479 6911 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 6912 }
69b07479 6913
301ad80a
PG
6914 if (ecom)
6915 ecommunity_free(&ecom);
6916
6917 return CMD_SUCCESS;
6918}
6919
505e5056 6920DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 6921 address_family_ipv4_safi_cmd,
6922 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6923 "Enter Address Family command mode\n"
6924 "Address Family\n"
6925 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6926{
f51bae9c 6927
d62a17ae 6928 if (argc == 3) {
2131d5cf 6929 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6930 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6931 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6932 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6933 && safi != SAFI_EVPN) {
31947174
MK
6934 vty_out(vty,
6935 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6936 return CMD_WARNING_CONFIG_FAILED;
6937 }
d62a17ae 6938 vty->node = bgp_node_type(AFI_IP, safi);
6939 } else
6940 vty->node = BGP_IPV4_NODE;
718e3744 6941
d62a17ae 6942 return CMD_SUCCESS;
718e3744 6943}
6944
505e5056 6945DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 6946 address_family_ipv6_safi_cmd,
6947 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6948 "Enter Address Family command mode\n"
6949 "Address Family\n"
6950 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6951{
d62a17ae 6952 if (argc == 3) {
2131d5cf 6953 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6954 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6955 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6956 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6957 && safi != SAFI_EVPN) {
31947174
MK
6958 vty_out(vty,
6959 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6960 return CMD_WARNING_CONFIG_FAILED;
6961 }
d62a17ae 6962 vty->node = bgp_node_type(AFI_IP6, safi);
6963 } else
6964 vty->node = BGP_IPV6_NODE;
25ffbdc1 6965
d62a17ae 6966 return CMD_SUCCESS;
25ffbdc1 6967}
718e3744 6968
d6902373 6969#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6970DEFUN_NOSH (address_family_vpnv4,
718e3744 6971 address_family_vpnv4_cmd,
8334fd5a 6972 "address-family vpnv4 [unicast]",
718e3744 6973 "Enter Address Family command mode\n"
8c3deaae 6974 "Address Family\n"
3a2d747c 6975 "Address Family modifier\n")
718e3744 6976{
d62a17ae 6977 vty->node = BGP_VPNV4_NODE;
6978 return CMD_SUCCESS;
718e3744 6979}
6980
505e5056 6981DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6982 address_family_vpnv6_cmd,
8334fd5a 6983 "address-family vpnv6 [unicast]",
8ecd3266 6984 "Enter Address Family command mode\n"
8c3deaae 6985 "Address Family\n"
3a2d747c 6986 "Address Family modifier\n")
8ecd3266 6987{
d62a17ae 6988 vty->node = BGP_VPNV6_NODE;
6989 return CMD_SUCCESS;
8ecd3266 6990}
c016b6c7 6991#endif
d6902373 6992
505e5056 6993DEFUN_NOSH (address_family_evpn,
4e0b7b6d 6994 address_family_evpn_cmd,
7111c1a0 6995 "address-family l2vpn evpn",
4e0b7b6d 6996 "Enter Address Family command mode\n"
7111c1a0
QY
6997 "Address Family\n"
6998 "Address Family modifier\n")
4e0b7b6d 6999{
2131d5cf 7000 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7001 vty->node = BGP_EVPN_NODE;
7002 return CMD_SUCCESS;
4e0b7b6d
PG
7003}
7004
505e5056 7005DEFUN_NOSH (exit_address_family,
718e3744 7006 exit_address_family_cmd,
7007 "exit-address-family",
7008 "Exit from Address Family configuration mode\n")
7009{
d62a17ae 7010 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7011 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7012 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7013 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7014 || vty->node == BGP_EVPN_NODE
7015 || vty->node == BGP_FLOWSPECV4_NODE
7016 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7017 vty->node = BGP_NODE;
7018 return CMD_SUCCESS;
718e3744 7019}
6b0655a2 7020
8ad7271d 7021/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7022static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7023 const char *ip_str, afi_t afi, safi_t safi,
7024 struct prefix_rd *prd)
7025{
7026 int ret;
7027 struct prefix match;
7028 struct bgp_node *rn;
7029 struct bgp_node *rm;
7030 struct bgp *bgp;
7031 struct bgp_table *table;
7032 struct bgp_table *rib;
7033
7034 /* BGP structure lookup. */
7035 if (view_name) {
7036 bgp = bgp_lookup_by_name(view_name);
7037 if (bgp == NULL) {
7038 vty_out(vty, "%% Can't find BGP instance %s\n",
7039 view_name);
7040 return CMD_WARNING;
7041 }
7042 } else {
7043 bgp = bgp_get_default();
7044 if (bgp == NULL) {
7045 vty_out(vty, "%% No BGP process is configured\n");
7046 return CMD_WARNING;
7047 }
7048 }
7049
7050 /* Check IP address argument. */
7051 ret = str2prefix(ip_str, &match);
7052 if (!ret) {
7053 vty_out(vty, "%% address is malformed\n");
7054 return CMD_WARNING;
7055 }
7056
7057 match.family = afi2family(afi);
7058 rib = bgp->rib[afi][safi];
7059
7060 if (safi == SAFI_MPLS_VPN) {
7061 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7062 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7063 continue;
7064
7065 if ((table = rn->info) != NULL) {
7066 if ((rm = bgp_node_match(table, &match))
7067 != NULL) {
7068 if (rm->p.prefixlen
7069 == match.prefixlen) {
7070 SET_FLAG(rn->flags,
7071 BGP_NODE_USER_CLEAR);
7072 bgp_process(bgp, rm, afi, safi);
7073 }
7074 bgp_unlock_node(rm);
7075 }
7076 }
7077 }
7078 } else {
7079 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7080 if (rn->p.prefixlen == match.prefixlen) {
7081 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7082 bgp_process(bgp, rn, afi, safi);
7083 }
7084 bgp_unlock_node(rn);
7085 }
7086 }
7087
7088 return CMD_SUCCESS;
8ad7271d
DS
7089}
7090
b09b5ae0 7091/* one clear bgp command to rule them all */
718e3744 7092DEFUN (clear_ip_bgp_all,
7093 clear_ip_bgp_all_cmd,
c1a44e43 7094 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
718e3744 7095 CLEAR_STR
7096 IP_STR
7097 BGP_STR
838758ac 7098 BGP_INSTANCE_HELP_STR
510afcd6
DS
7099 BGP_AFI_HELP_STR
7100 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
7101 "Clear all peers\n"
7102 "BGP neighbor address to clear\n"
a80beece 7103 "BGP IPv6 neighbor to clear\n"
838758ac 7104 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7105 "Clear peers with the AS number\n"
7106 "Clear all external peers\n"
718e3744 7107 "Clear all members of peer-group\n"
b09b5ae0 7108 "BGP peer-group name\n"
b09b5ae0
DW
7109 BGP_SOFT_STR
7110 BGP_SOFT_IN_STR
b09b5ae0
DW
7111 BGP_SOFT_OUT_STR
7112 BGP_SOFT_IN_STR
7113 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7114 BGP_SOFT_OUT_STR)
718e3744 7115{
d62a17ae 7116 char *vrf = NULL;
7117
7118 afi_t afi = AFI_IP6;
7119 safi_t safi = SAFI_UNICAST;
7120 enum clear_sort clr_sort = clear_peer;
7121 enum bgp_clear_type clr_type;
7122 char *clr_arg = NULL;
7123
7124 int idx = 0;
7125
7126 /* clear [ip] bgp */
7127 if (argv_find(argv, argc, "ip", &idx))
7128 afi = AFI_IP;
7129
7130 /* [<view|vrf> VIEWVRFNAME] */
7131 if (argv_find(argv, argc, "view", &idx)
7132 || argv_find(argv, argc, "vrf", &idx)) {
7133 vrf = argv[idx + 1]->arg;
7134 idx += 2;
7135 }
7136
7137 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7138 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7139 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7140
7141 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7142 if (argv_find(argv, argc, "*", &idx)) {
7143 clr_sort = clear_all;
7144 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7145 clr_sort = clear_peer;
7146 clr_arg = argv[idx]->arg;
7147 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7148 clr_sort = clear_peer;
7149 clr_arg = argv[idx]->arg;
7150 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7151 clr_sort = clear_group;
7152 idx++;
7153 clr_arg = argv[idx]->arg;
7154 } else if (argv_find(argv, argc, "WORD", &idx)) {
7155 clr_sort = clear_peer;
7156 clr_arg = argv[idx]->arg;
7157 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7158 clr_sort = clear_as;
7159 clr_arg = argv[idx]->arg;
7160 } else if (argv_find(argv, argc, "external", &idx)) {
7161 clr_sort = clear_external;
7162 }
7163
7164 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7165 if (argv_find(argv, argc, "soft", &idx)) {
7166 if (argv_find(argv, argc, "in", &idx)
7167 || argv_find(argv, argc, "out", &idx))
7168 clr_type = strmatch(argv[idx]->text, "in")
7169 ? BGP_CLEAR_SOFT_IN
7170 : BGP_CLEAR_SOFT_OUT;
7171 else
7172 clr_type = BGP_CLEAR_SOFT_BOTH;
7173 } else if (argv_find(argv, argc, "in", &idx)) {
7174 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7175 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7176 : BGP_CLEAR_SOFT_IN;
7177 } else if (argv_find(argv, argc, "out", &idx)) {
7178 clr_type = BGP_CLEAR_SOFT_OUT;
7179 } else
7180 clr_type = BGP_CLEAR_SOFT_NONE;
7181
7182 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7183}
01080f7c 7184
8ad7271d
DS
7185DEFUN (clear_ip_bgp_prefix,
7186 clear_ip_bgp_prefix_cmd,
18c57037 7187 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7188 CLEAR_STR
7189 IP_STR
7190 BGP_STR
838758ac 7191 BGP_INSTANCE_HELP_STR
8ad7271d 7192 "Clear bestpath and re-advertise\n"
0c7b1b01 7193 "IPv4 prefix\n")
8ad7271d 7194{
d62a17ae 7195 char *vrf = NULL;
7196 char *prefix = NULL;
8ad7271d 7197
d62a17ae 7198 int idx = 0;
01080f7c 7199
d62a17ae 7200 /* [<view|vrf> VIEWVRFNAME] */
1d35f218 7201 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
d62a17ae 7202 vrf = argv[idx]->arg;
0c7b1b01 7203
d62a17ae 7204 prefix = argv[argc - 1]->arg;
8ad7271d 7205
d62a17ae 7206 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7207}
8ad7271d 7208
b09b5ae0
DW
7209DEFUN (clear_bgp_ipv6_safi_prefix,
7210 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7211 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7212 CLEAR_STR
3a2d747c 7213 IP_STR
718e3744 7214 BGP_STR
8c3deaae 7215 "Address Family\n"
46f296b4 7216 BGP_SAFI_HELP_STR
b09b5ae0 7217 "Clear bestpath and re-advertise\n"
0c7b1b01 7218 "IPv6 prefix\n")
718e3744 7219{
9b475e76
PG
7220 int idx_safi = 0;
7221 int idx_ipv6_prefix = 0;
7222 safi_t safi = SAFI_UNICAST;
7223 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7224 argv[idx_ipv6_prefix]->arg : NULL;
7225
7226 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7227 return bgp_clear_prefix(
9b475e76
PG
7228 vty, NULL, prefix, AFI_IP6,
7229 safi, NULL);
838758ac 7230}
01080f7c 7231
b09b5ae0
DW
7232DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7233 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7234 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7235 CLEAR_STR
3a2d747c 7236 IP_STR
718e3744 7237 BGP_STR
838758ac 7238 BGP_INSTANCE_HELP_STR
8c3deaae 7239 "Address Family\n"
46f296b4 7240 BGP_SAFI_HELP_STR
b09b5ae0 7241 "Clear bestpath and re-advertise\n"
0c7b1b01 7242 "IPv6 prefix\n")
718e3744 7243{
d62a17ae 7244 int idx_word = 3;
9b475e76
PG
7245 int idx_safi = 0;
7246 int idx_ipv6_prefix = 0;
7247 safi_t safi = SAFI_UNICAST;
7248 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7249 argv[idx_ipv6_prefix]->arg : NULL;
7250 /* [<view|vrf> VIEWVRFNAME] */
7251 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7252 argv[idx_word]->arg : NULL;
7253
7254 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7255
d62a17ae 7256 return bgp_clear_prefix(
9b475e76
PG
7257 vty, vrfview, prefix,
7258 AFI_IP6, safi, NULL);
718e3744 7259}
7260
b09b5ae0
DW
7261DEFUN (show_bgp_views,
7262 show_bgp_views_cmd,
d6e3c605 7263 "show [ip] bgp views",
b09b5ae0 7264 SHOW_STR
d6e3c605 7265 IP_STR
01080f7c 7266 BGP_STR
b09b5ae0 7267 "Show the defined BGP views\n")
01080f7c 7268{
d62a17ae 7269 struct list *inst = bm->bgp;
7270 struct listnode *node;
7271 struct bgp *bgp;
01080f7c 7272
d62a17ae 7273 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7274 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7275 return CMD_WARNING;
7276 }
e52702f2 7277
d62a17ae 7278 vty_out(vty, "Defined BGP views:\n");
7279 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7280 /* Skip VRFs. */
7281 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7282 continue;
7283 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7284 bgp->as);
7285 }
e52702f2 7286
d62a17ae 7287 return CMD_SUCCESS;
e0081f70
ML
7288}
7289
8386ac43 7290DEFUN (show_bgp_vrfs,
7291 show_bgp_vrfs_cmd,
d6e3c605 7292 "show [ip] bgp vrfs [json]",
8386ac43 7293 SHOW_STR
d6e3c605 7294 IP_STR
8386ac43 7295 BGP_STR
7296 "Show BGP VRFs\n"
9973d184 7297 JSON_STR)
8386ac43 7298{
fe1dc5a3 7299 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7300 struct list *inst = bm->bgp;
7301 struct listnode *node;
7302 struct bgp *bgp;
d7c0a89a 7303 uint8_t uj = use_json(argc, argv);
d62a17ae 7304 json_object *json = NULL;
7305 json_object *json_vrfs = NULL;
7306 int count = 0;
d62a17ae 7307
7308 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7309 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7310 return CMD_WARNING;
7311 }
7312
7313 if (uj) {
7314 json = json_object_new_object();
7315 json_vrfs = json_object_new_object();
7316 }
7317
7318 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7319 const char *name, *type;
7320 struct peer *peer;
7321 struct listnode *node, *nnode;
7322 int peers_cfg, peers_estb;
7323 json_object *json_vrf = NULL;
d62a17ae 7324
7325 /* Skip Views. */
7326 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7327 continue;
7328
7329 count++;
7330 if (!uj && count == 1)
fe1dc5a3
MK
7331 vty_out(vty,
7332 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7333 "Type", "Id", "routerId", "#PeersVfg",
7334 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7335
7336 peers_cfg = peers_estb = 0;
7337 if (uj)
7338 json_vrf = json_object_new_object();
7339
7340
7341 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7342 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7343 continue;
7344 peers_cfg++;
7345 if (peer->status == Established)
7346 peers_estb++;
7347 }
7348
7349 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7350 name = "Default";
7351 type = "DFLT";
7352 } else {
7353 name = bgp->name;
7354 type = "VRF";
7355 }
7356
a8bf7d9c 7357
d62a17ae 7358 if (uj) {
a4d82a8a
PZ
7359 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7360 ? -1
7361 : (int64_t)bgp->vrf_id;
d62a17ae 7362 json_object_string_add(json_vrf, "type", type);
7363 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7364 json_object_string_add(json_vrf, "routerId",
7365 inet_ntoa(bgp->router_id));
7366 json_object_int_add(json_vrf, "numConfiguredPeers",
7367 peers_cfg);
7368 json_object_int_add(json_vrf, "numEstablishedPeers",
7369 peers_estb);
7370
fe1dc5a3 7371 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7372 json_object_string_add(
7373 json_vrf, "rmac",
7374 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7375 json_object_object_add(json_vrfs, name, json_vrf);
7376 } else
fe1dc5a3
MK
7377 vty_out(vty,
7378 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7379 type,
7380 bgp->vrf_id == VRF_UNKNOWN ? -1
7381 : (int)bgp->vrf_id,
7382 inet_ntoa(bgp->router_id), peers_cfg,
7383 peers_estb, name, bgp->l3vni,
fe1dc5a3 7384 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7385 }
7386
7387 if (uj) {
7388 json_object_object_add(json, "vrfs", json_vrfs);
7389
7390 json_object_int_add(json, "totalVrfs", count);
7391
996c9314
LB
7392 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7393 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7394 json_object_free(json);
7395 } else {
7396 if (count)
7397 vty_out(vty,
7398 "\nTotal number of VRFs (including default): %d\n",
7399 count);
7400 }
7401
7402 return CMD_SUCCESS;
8386ac43 7403}
7404
acf71666
MK
7405static void show_address_entry(struct hash_backet *backet, void *args)
7406{
60466a63
QY
7407 struct vty *vty = (struct vty *)args;
7408 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 7409
60466a63 7410 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
7411 addr->refcnt);
7412}
7413
7414static void show_tip_entry(struct hash_backet *backet, void *args)
7415{
0291c246 7416 struct vty *vty = (struct vty *)args;
60466a63 7417 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7418
60466a63 7419 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7420 tip->refcnt);
7421}
7422
7423static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7424{
7425 vty_out(vty, "self nexthop database:\n");
7426 hash_iterate(bgp->address_hash,
7427 (void (*)(struct hash_backet *, void *))show_address_entry,
7428 vty);
7429
7430 vty_out(vty, "Tunnel-ip database:\n");
7431 hash_iterate(bgp->tip_hash,
7432 (void (*)(struct hash_backet *, void *))show_tip_entry,
7433 vty);
7434}
7435
15c81ca4
DS
7436DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7437 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7438 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7439 "martian next-hops\n"
7440 "martian next-hop database\n")
acf71666 7441{
0291c246 7442 struct bgp *bgp = NULL;
15c81ca4
DS
7443 int idx = 0;
7444
7445 if (argv_find(argv, argc, "view", &idx)
7446 || argv_find(argv, argc, "vrf", &idx))
7447 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7448 else
7449 bgp = bgp_get_default();
acf71666 7450
acf71666
MK
7451 if (!bgp) {
7452 vty_out(vty, "%% No BGP process is configured\n");
7453 return CMD_WARNING;
7454 }
7455 bgp_show_martian_nexthops(vty, bgp);
7456
7457 return CMD_SUCCESS;
7458}
7459
f412b39a 7460DEFUN (show_bgp_memory,
4bf6a362 7461 show_bgp_memory_cmd,
7fa12b13 7462 "show [ip] bgp memory",
4bf6a362 7463 SHOW_STR
3a2d747c 7464 IP_STR
4bf6a362
PJ
7465 BGP_STR
7466 "Global BGP memory statistics\n")
7467{
d62a17ae 7468 char memstrbuf[MTYPE_MEMSTR_LEN];
7469 unsigned long count;
7470
7471 /* RIB related usage stats */
7472 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7473 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7474 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7475 count * sizeof(struct bgp_node)));
7476
7477 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7478 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7479 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7480 count * sizeof(struct bgp_info)));
7481 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7482 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7483 count,
7484 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7485 count * sizeof(struct bgp_info_extra)));
7486
7487 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7488 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7489 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7490 count * sizeof(struct bgp_static)));
7491
7492 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7493 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7494 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7495 count * sizeof(struct bpacket)));
7496
7497 /* Adj-In/Out */
7498 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7499 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7500 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7501 count * sizeof(struct bgp_adj_in)));
7502 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7503 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7504 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7505 count * sizeof(struct bgp_adj_out)));
7506
7507 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7508 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7509 count,
7510 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7511 count * sizeof(struct bgp_nexthop_cache)));
7512
7513 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7514 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7515 count,
7516 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7517 count * sizeof(struct bgp_damp_info)));
7518
7519 /* Attributes */
7520 count = attr_count();
7521 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7522 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7523 count * sizeof(struct attr)));
7524
7525 if ((count = attr_unknown_count()))
7526 vty_out(vty, "%ld unknown attributes\n", count);
7527
7528 /* AS_PATH attributes */
7529 count = aspath_count();
7530 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7531 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7532 count * sizeof(struct aspath)));
7533
7534 count = mtype_stats_alloc(MTYPE_AS_SEG);
7535 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7536 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7537 count * sizeof(struct assegment)));
7538
7539 /* Other attributes */
7540 if ((count = community_count()))
7541 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7542 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7543 count * sizeof(struct community)));
d62a17ae 7544 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7545 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7546 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7547 count * sizeof(struct ecommunity)));
d62a17ae 7548 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7549 vty_out(vty,
7550 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7551 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7552 count * sizeof(struct lcommunity)));
d62a17ae 7553
7554 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7555 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7556 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7557 count * sizeof(struct cluster_list)));
7558
7559 /* Peer related usage */
7560 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7561 vty_out(vty, "%ld peers, using %s of memory\n", count,
7562 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7563 count * sizeof(struct peer)));
7564
7565 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7566 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7567 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7568 count * sizeof(struct peer_group)));
7569
7570 /* Other */
7571 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7572 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7573 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7574 count * sizeof(struct hash)));
7575 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7576 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7577 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7578 count * sizeof(struct hash_backet)));
7579 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7580 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7581 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7582 count * sizeof(regex_t)));
d62a17ae 7583 return CMD_SUCCESS;
4bf6a362 7584}
fee0f4c6 7585
57a9c8a8
DS
7586static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7587{
7588 json_object *bestpath = json_object_new_object();
7589
7590 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7591 json_object_string_add(bestpath, "asPath", "ignore");
7592
7593 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7594 json_object_string_add(bestpath, "asPath", "confed");
7595
7596 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7597 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7598 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7599 "as-set");
7600 else
a4d82a8a 7601 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7602 "true");
7603 } else
a4d82a8a 7604 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7605
7606 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7607 json_object_string_add(bestpath, "compareRouterId", "true");
7608 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7609 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7610 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7611 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7612 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7613 json_object_string_add(bestpath, "med",
7614 "missing-as-worst");
7615 else
7616 json_object_string_add(bestpath, "med", "true");
7617 }
7618
7619 json_object_object_add(json, "bestPath", bestpath);
7620}
7621
718e3744 7622/* Show BGP peer's summary information. */
d62a17ae 7623static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
d7c0a89a 7624 uint8_t use_json, json_object *json)
d62a17ae 7625{
7626 struct peer *peer;
7627 struct listnode *node, *nnode;
7628 unsigned int count = 0, dn_count = 0;
7629 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7630 char neighbor_buf[VTY_BUFSIZ];
7631 int neighbor_col_default_width = 16;
7632 int len;
7633 int max_neighbor_width = 0;
7634 int pfx_rcd_safi;
7635 json_object *json_peer = NULL;
7636 json_object *json_peers = NULL;
7637
7638 /* labeled-unicast routes are installed in the unicast table so in order
7639 * to
7640 * display the correct PfxRcd value we must look at SAFI_UNICAST
7641 */
7642 if (safi == SAFI_LABELED_UNICAST)
7643 pfx_rcd_safi = SAFI_UNICAST;
7644 else
7645 pfx_rcd_safi = safi;
7646
7647 if (use_json) {
7648 if (json == NULL)
7649 json = json_object_new_object();
7650
7651 json_peers = json_object_new_object();
7652 } else {
7653 /* Loop over all neighbors that will be displayed to determine
7654 * how many
7655 * characters are needed for the Neighbor column
7656 */
7657 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7658 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7659 continue;
7660
7661 if (peer->afc[afi][safi]) {
7662 memset(dn_flag, '\0', sizeof(dn_flag));
7663 if (peer_dynamic_neighbor(peer))
7664 dn_flag[0] = '*';
7665
7666 if (peer->hostname
7667 && bgp_flag_check(bgp,
7668 BGP_FLAG_SHOW_HOSTNAME))
7669 sprintf(neighbor_buf, "%s%s(%s) ",
7670 dn_flag, peer->hostname,
7671 peer->host);
7672 else
7673 sprintf(neighbor_buf, "%s%s ", dn_flag,
7674 peer->host);
7675
7676 len = strlen(neighbor_buf);
7677
7678 if (len > max_neighbor_width)
7679 max_neighbor_width = len;
7680 }
7681 }
f933309e 7682
d62a17ae 7683 /* Originally we displayed the Neighbor column as 16
7684 * characters wide so make that the default
7685 */
7686 if (max_neighbor_width < neighbor_col_default_width)
7687 max_neighbor_width = neighbor_col_default_width;
7688 }
f933309e 7689
d62a17ae 7690 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7691 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7692 continue;
7693
ea47320b
DL
7694 if (!peer->afc[afi][safi])
7695 continue;
d62a17ae 7696
ea47320b
DL
7697 if (!count) {
7698 unsigned long ents;
7699 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7700 int64_t vrf_id_ui;
d62a17ae 7701
a4d82a8a
PZ
7702 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7703 ? -1
7704 : (int64_t)bgp->vrf_id;
ea47320b
DL
7705
7706 /* Usage summary and header */
7707 if (use_json) {
7708 json_object_string_add(
7709 json, "routerId",
7710 inet_ntoa(bgp->router_id));
60466a63
QY
7711 json_object_int_add(json, "as", bgp->as);
7712 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7713 json_object_string_add(
7714 json, "vrfName",
7715 (bgp->inst_type
7716 == BGP_INSTANCE_TYPE_DEFAULT)
7717 ? "Default"
7718 : bgp->name);
7719 } else {
7720 vty_out(vty,
7721 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7722 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7723 bgp->vrf_id == VRF_UNKNOWN
7724 ? -1
7725 : (int)bgp->vrf_id);
ea47320b
DL
7726 vty_out(vty, "\n");
7727 }
d62a17ae 7728
ea47320b 7729 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7730 if (use_json) {
ea47320b 7731 json_object_int_add(
60466a63 7732 json, "updateDelayLimit",
ea47320b 7733 bgp->v_update_delay);
d62a17ae 7734
ea47320b
DL
7735 if (bgp->v_update_delay
7736 != bgp->v_establish_wait)
d62a17ae 7737 json_object_int_add(
7738 json,
ea47320b
DL
7739 "updateDelayEstablishWait",
7740 bgp->v_establish_wait);
d62a17ae 7741
60466a63 7742 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7743 json_object_string_add(
7744 json,
7745 "updateDelayFirstNeighbor",
7746 bgp->update_delay_begin_time);
7747 json_object_boolean_true_add(
7748 json,
7749 "updateDelayInProgress");
7750 } else {
7751 if (bgp->update_delay_over) {
d62a17ae 7752 json_object_string_add(
7753 json,
7754 "updateDelayFirstNeighbor",
7755 bgp->update_delay_begin_time);
ea47320b 7756 json_object_string_add(
d62a17ae 7757 json,
ea47320b
DL
7758 "updateDelayBestpathResumed",
7759 bgp->update_delay_end_time);
7760 json_object_string_add(
d62a17ae 7761 json,
ea47320b
DL
7762 "updateDelayZebraUpdateResume",
7763 bgp->update_delay_zebra_resume_time);
7764 json_object_string_add(
7765 json,
7766 "updateDelayPeerUpdateResume",
7767 bgp->update_delay_peers_resume_time);
d62a17ae 7768 }
ea47320b
DL
7769 }
7770 } else {
7771 vty_out(vty,
7772 "Read-only mode update-delay limit: %d seconds\n",
7773 bgp->v_update_delay);
7774 if (bgp->v_update_delay
7775 != bgp->v_establish_wait)
d62a17ae 7776 vty_out(vty,
ea47320b
DL
7777 " Establish wait: %d seconds\n",
7778 bgp->v_establish_wait);
d62a17ae 7779
60466a63 7780 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7781 vty_out(vty,
7782 " First neighbor established: %s\n",
7783 bgp->update_delay_begin_time);
7784 vty_out(vty,
7785 " Delay in progress\n");
7786 } else {
7787 if (bgp->update_delay_over) {
d62a17ae 7788 vty_out(vty,
7789 " First neighbor established: %s\n",
7790 bgp->update_delay_begin_time);
7791 vty_out(vty,
ea47320b
DL
7792 " Best-paths resumed: %s\n",
7793 bgp->update_delay_end_time);
7794 vty_out(vty,
7795 " zebra update resumed: %s\n",
7796 bgp->update_delay_zebra_resume_time);
7797 vty_out(vty,
7798 " peers update resumed: %s\n",
7799 bgp->update_delay_peers_resume_time);
d62a17ae 7800 }
7801 }
7802 }
ea47320b 7803 }
d62a17ae 7804
ea47320b
DL
7805 if (use_json) {
7806 if (bgp_maxmed_onstartup_configured(bgp)
7807 && bgp->maxmed_active)
7808 json_object_boolean_true_add(
60466a63 7809 json, "maxMedOnStartup");
ea47320b
DL
7810 if (bgp->v_maxmed_admin)
7811 json_object_boolean_true_add(
60466a63 7812 json, "maxMedAdministrative");
d62a17ae 7813
ea47320b
DL
7814 json_object_int_add(
7815 json, "tableVersion",
60466a63 7816 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7817
60466a63
QY
7818 ents = bgp_table_count(bgp->rib[afi][safi]);
7819 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7820 json_object_int_add(
7821 json, "ribMemory",
7822 ents * sizeof(struct bgp_node));
d62a17ae 7823
ea47320b 7824 ents = listcount(bgp->peer);
60466a63
QY
7825 json_object_int_add(json, "peerCount", ents);
7826 json_object_int_add(json, "peerMemory",
7827 ents * sizeof(struct peer));
d62a17ae 7828
ea47320b
DL
7829 if ((ents = listcount(bgp->group))) {
7830 json_object_int_add(
60466a63 7831 json, "peerGroupCount", ents);
ea47320b
DL
7832 json_object_int_add(
7833 json, "peerGroupMemory",
996c9314
LB
7834 ents * sizeof(struct
7835 peer_group));
ea47320b 7836 }
d62a17ae 7837
ea47320b
DL
7838 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7839 BGP_CONFIG_DAMPENING))
7840 json_object_boolean_true_add(
60466a63 7841 json, "dampeningEnabled");
ea47320b
DL
7842 } else {
7843 if (bgp_maxmed_onstartup_configured(bgp)
7844 && bgp->maxmed_active)
d62a17ae 7845 vty_out(vty,
ea47320b
DL
7846 "Max-med on-startup active\n");
7847 if (bgp->v_maxmed_admin)
d62a17ae 7848 vty_out(vty,
ea47320b 7849 "Max-med administrative active\n");
d62a17ae 7850
60466a63
QY
7851 vty_out(vty, "BGP table version %" PRIu64 "\n",
7852 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 7853
60466a63 7854 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
7855 vty_out(vty,
7856 "RIB entries %ld, using %s of memory\n",
7857 ents,
996c9314
LB
7858 mtype_memstr(memstrbuf,
7859 sizeof(memstrbuf),
7860 ents * sizeof(struct
7861 bgp_node)));
ea47320b
DL
7862
7863 /* Peer related usage */
7864 ents = listcount(bgp->peer);
60466a63 7865 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7866 ents,
7867 mtype_memstr(
60466a63
QY
7868 memstrbuf, sizeof(memstrbuf),
7869 ents * sizeof(struct peer)));
ea47320b
DL
7870
7871 if ((ents = listcount(bgp->group)))
d62a17ae 7872 vty_out(vty,
ea47320b 7873 "Peer groups %ld, using %s of memory\n",
d62a17ae 7874 ents,
7875 mtype_memstr(
7876 memstrbuf,
7877 sizeof(memstrbuf),
996c9314
LB
7878 ents * sizeof(struct
7879 peer_group)));
d62a17ae 7880
ea47320b
DL
7881 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7882 BGP_CONFIG_DAMPENING))
60466a63 7883 vty_out(vty, "Dampening enabled.\n");
ea47320b 7884 vty_out(vty, "\n");
d62a17ae 7885
ea47320b
DL
7886 /* Subtract 8 here because 'Neighbor' is
7887 * 8 characters */
7888 vty_out(vty, "Neighbor");
60466a63
QY
7889 vty_out(vty, "%*s", max_neighbor_width - 8,
7890 " ");
ea47320b
DL
7891 vty_out(vty,
7892 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7893 }
ea47320b 7894 }
d62a17ae 7895
ea47320b 7896 count++;
d62a17ae 7897
ea47320b
DL
7898 if (use_json) {
7899 json_peer = json_object_new_object();
d62a17ae 7900
ea47320b 7901 if (peer_dynamic_neighbor(peer))
60466a63
QY
7902 json_object_boolean_true_add(json_peer,
7903 "dynamicPeer");
d62a17ae 7904
ea47320b 7905 if (peer->hostname)
60466a63 7906 json_object_string_add(json_peer, "hostname",
ea47320b 7907 peer->hostname);
d62a17ae 7908
ea47320b 7909 if (peer->domainname)
60466a63
QY
7910 json_object_string_add(json_peer, "domainname",
7911 peer->domainname);
d62a17ae 7912
60466a63 7913 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7914 json_object_int_add(json_peer, "version", 4);
60466a63 7915 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 7916 PEER_TOTAL_RX(peer));
60466a63 7917 json_object_int_add(json_peer, "msgSent",
0112e9e0 7918 PEER_TOTAL_TX(peer));
ea47320b
DL
7919
7920 json_object_int_add(json_peer, "tableVersion",
7921 peer->version[afi][safi]);
7922 json_object_int_add(json_peer, "outq",
7923 peer->obuf->count);
7924 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7925 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7926 use_json, json_peer);
7927 json_object_int_add(json_peer, "prefixReceivedCount",
7928 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 7929
ea47320b 7930 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7931 json_object_string_add(json_peer, "state",
ea47320b 7932 "Idle (Admin)");
60466a63
QY
7933 else if (CHECK_FLAG(peer->sflags,
7934 PEER_STATUS_PREFIX_OVERFLOW))
7935 json_object_string_add(json_peer, "state",
ea47320b
DL
7936 "Idle (PfxCt)");
7937 else
7938 json_object_string_add(
7939 json_peer, "state",
60466a63
QY
7940 lookup_msg(bgp_status_msg, peer->status,
7941 NULL));
ea47320b
DL
7942
7943 if (peer->conf_if)
60466a63 7944 json_object_string_add(json_peer, "idType",
ea47320b
DL
7945 "interface");
7946 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
7947 json_object_string_add(json_peer, "idType",
7948 "ipv4");
ea47320b 7949 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
7950 json_object_string_add(json_peer, "idType",
7951 "ipv6");
d62a17ae 7952
ea47320b
DL
7953 json_object_object_add(json_peers, peer->host,
7954 json_peer);
7955 } else {
7956 memset(dn_flag, '\0', sizeof(dn_flag));
7957 if (peer_dynamic_neighbor(peer)) {
7958 dn_count++;
7959 dn_flag[0] = '*';
7960 }
d62a17ae 7961
ea47320b 7962 if (peer->hostname
60466a63 7963 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 7964 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 7965 peer->hostname, peer->host);
ea47320b 7966 else
60466a63 7967 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
7968
7969 /* pad the neighbor column with spaces */
7970 if (len < max_neighbor_width)
60466a63
QY
7971 vty_out(vty, "%*s", max_neighbor_width - len,
7972 " ");
ea47320b 7973
86a55b99 7974 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
7975 peer->as, PEER_TOTAL_RX(peer),
7976 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7977 0, peer->obuf->count,
d62a17ae 7978 peer_uptime(peer->uptime, timebuf,
ea47320b 7979 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 7980
ea47320b 7981 if (peer->status == Established)
95077abf
DW
7982 if (peer->afc_recv[afi][pfx_rcd_safi])
7983 vty_out(vty, " %12ld",
a4d82a8a
PZ
7984 peer->pcount[afi]
7985 [pfx_rcd_safi]);
95077abf
DW
7986 else
7987 vty_out(vty, " NoNeg");
ea47320b 7988 else {
60466a63 7989 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 7990 vty_out(vty, " Idle (Admin)");
60466a63
QY
7991 else if (CHECK_FLAG(
7992 peer->sflags,
7993 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 7994 vty_out(vty, " Idle (PfxCt)");
d62a17ae 7995 else
ea47320b 7996 vty_out(vty, " %12s",
60466a63
QY
7997 lookup_msg(bgp_status_msg,
7998 peer->status, NULL));
d62a17ae 7999 }
ea47320b 8000 vty_out(vty, "\n");
d62a17ae 8001 }
8002 }
f933309e 8003
d62a17ae 8004 if (use_json) {
8005 json_object_object_add(json, "peers", json_peers);
8006
8007 json_object_int_add(json, "totalPeers", count);
8008 json_object_int_add(json, "dynamicPeers", dn_count);
8009
57a9c8a8
DS
8010 bgp_show_bestpath_json(bgp, json);
8011
996c9314
LB
8012 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8013 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8014 json_object_free(json);
8015 } else {
8016 if (count)
8017 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8018 else {
8019 if (use_json)
8020 vty_out(vty,
8021 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
8022 afi_safi_print(afi, safi));
8023 else
8024 vty_out(vty, "No %s neighbor is configured\n",
8025 afi_safi_print(afi, safi));
8026 }
b05a1c8b 8027
d62a17ae 8028 if (dn_count && !use_json) {
8029 vty_out(vty, "* - dynamic neighbor\n");
8030 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8031 dn_count, bgp->dynamic_neighbors_limit);
8032 }
8033 }
1ff9a340 8034
d62a17ae 8035 return CMD_SUCCESS;
718e3744 8036}
8037
d62a17ae 8038static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
d7c0a89a 8039 int safi, uint8_t use_json,
d62a17ae 8040 json_object *json)
8041{
8042 int is_first = 1;
8043 int afi_wildcard = (afi == AFI_MAX);
8044 int safi_wildcard = (safi == SAFI_MAX);
8045 int is_wildcard = (afi_wildcard || safi_wildcard);
8046 bool json_output = false;
8047
8048 if (use_json && is_wildcard)
8049 vty_out(vty, "{\n");
8050 if (afi_wildcard)
8051 afi = 1; /* AFI_IP */
8052 while (afi < AFI_MAX) {
8053 if (safi_wildcard)
8054 safi = 1; /* SAFI_UNICAST */
8055 while (safi < SAFI_MAX) {
318cac96 8056 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
d62a17ae 8057 json_output = true;
8058 if (is_wildcard) {
8059 /*
8060 * So limit output to those afi/safi
8061 * pairs that
8062 * actualy have something interesting in
8063 * them
8064 */
8065 if (use_json) {
8066 json = json_object_new_object();
8067
8068 if (!is_first)
8069 vty_out(vty, ",\n");
8070 else
8071 is_first = 0;
8072
8073 vty_out(vty, "\"%s\":",
8074 afi_safi_json(afi,
8075 safi));
8076 } else {
8077 vty_out(vty, "\n%s Summary:\n",
8078 afi_safi_print(afi,
8079 safi));
8080 }
8081 }
8082 bgp_show_summary(vty, bgp, afi, safi, use_json,
8083 json);
8084 }
8085 safi++;
d62a17ae 8086 if (!safi_wildcard)
8087 safi = SAFI_MAX;
8088 }
8089 afi++;
ee851c8c 8090 if (!afi_wildcard)
d62a17ae 8091 afi = AFI_MAX;
8092 }
8093
8094 if (use_json && is_wildcard)
8095 vty_out(vty, "}\n");
8096 else if (use_json && !json_output)
8097 vty_out(vty, "{}\n");
8098}
8099
8100static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
d7c0a89a 8101 safi_t safi, uint8_t use_json)
d62a17ae 8102{
8103 struct listnode *node, *nnode;
8104 struct bgp *bgp;
8105 json_object *json = NULL;
8106 int is_first = 1;
8107
8108 if (use_json)
8109 vty_out(vty, "{\n");
8110
8111 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8112 if (use_json) {
8113 json = json_object_new_object();
8114
8115 if (!is_first)
8116 vty_out(vty, ",\n");
8117 else
8118 is_first = 0;
8119
8120 vty_out(vty, "\"%s\":",
8121 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8122 ? "Default"
8123 : bgp->name);
8124 } else {
8125 vty_out(vty, "\nInstance %s:\n",
8126 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8127 ? "Default"
8128 : bgp->name);
8129 }
8130 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8131 }
8132
8133 if (use_json)
8134 vty_out(vty, "}\n");
8135}
8136
8137int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
d7c0a89a 8138 safi_t safi, uint8_t use_json)
d62a17ae 8139{
8140 struct bgp *bgp;
8141
8142 if (name) {
8143 if (strmatch(name, "all")) {
8144 bgp_show_all_instances_summary_vty(vty, afi, safi,
8145 use_json);
8146 return CMD_SUCCESS;
8147 } else {
8148 bgp = bgp_lookup_by_name(name);
8149
8150 if (!bgp) {
8151 if (use_json)
8152 vty_out(vty, "{}\n");
8153 else
8154 vty_out(vty,
8155 "%% No such BGP instance exist\n");
8156 return CMD_WARNING;
8157 }
8158
8159 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8160 NULL);
8161 return CMD_SUCCESS;
8162 }
8163 }
8164
8165 bgp = bgp_get_default();
8166
8167 if (bgp)
8168 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8169
8170 return CMD_SUCCESS;
4fb25c53
DW
8171}
8172
716b2d8a 8173/* `show [ip] bgp summary' commands. */
47fc97cc 8174DEFUN (show_ip_bgp_summary,
718e3744 8175 show_ip_bgp_summary_cmd,
dd6bd0f1 8176 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8177 SHOW_STR
8178 IP_STR
8179 BGP_STR
8386ac43 8180 BGP_INSTANCE_HELP_STR
46f296b4 8181 BGP_AFI_HELP_STR
dd6bd0f1 8182 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8183 "Summary of BGP neighbor status\n"
9973d184 8184 JSON_STR)
718e3744 8185{
d62a17ae 8186 char *vrf = NULL;
8187 afi_t afi = AFI_MAX;
8188 safi_t safi = SAFI_MAX;
8189
8190 int idx = 0;
8191
8192 /* show [ip] bgp */
8193 if (argv_find(argv, argc, "ip", &idx))
8194 afi = AFI_IP;
8195 /* [<view|vrf> VIEWVRFNAME] */
8196 if (argv_find(argv, argc, "view", &idx)
8197 || argv_find(argv, argc, "vrf", &idx))
8198 vrf = argv[++idx]->arg;
8199 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8200 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8201 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8202 }
8203
8204 int uj = use_json(argc, argv);
8205
8206 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8207}
8208
8209const char *afi_safi_print(afi_t afi, safi_t safi)
8210{
8211 if (afi == AFI_IP && safi == SAFI_UNICAST)
8212 return "IPv4 Unicast";
8213 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8214 return "IPv4 Multicast";
8215 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8216 return "IPv4 Labeled Unicast";
8217 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8218 return "IPv4 VPN";
8219 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8220 return "IPv4 Encap";
7c40bf39 8221 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8222 return "IPv4 Flowspec";
d62a17ae 8223 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8224 return "IPv6 Unicast";
8225 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8226 return "IPv6 Multicast";
8227 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8228 return "IPv6 Labeled Unicast";
8229 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8230 return "IPv6 VPN";
8231 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8232 return "IPv6 Encap";
7c40bf39 8233 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8234 return "IPv6 Flowspec";
d62a17ae 8235 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8236 return "L2VPN EVPN";
8237 else
8238 return "Unknown";
538621f2 8239}
8240
b9f77ec8
DS
8241/*
8242 * Please note that we have intentionally camelCased
8243 * the return strings here. So if you want
8244 * to use this function, please ensure you
8245 * are doing this within json output
8246 */
d62a17ae 8247const char *afi_safi_json(afi_t afi, safi_t safi)
8248{
8249 if (afi == AFI_IP && safi == SAFI_UNICAST)
8250 return "ipv4Unicast";
8251 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8252 return "ipv4Multicast";
8253 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8254 return "ipv4LabeledUnicast";
8255 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8256 return "ipv4Vpn";
8257 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8258 return "ipv4Encap";
7c40bf39 8259 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8260 return "ipv4Flowspec";
d62a17ae 8261 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8262 return "ipv6Unicast";
8263 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8264 return "ipv6Multicast";
8265 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8266 return "ipv6LabeledUnicast";
8267 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8268 return "ipv6Vpn";
8269 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8270 return "ipv6Encap";
7c40bf39 8271 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8272 return "ipv6Flowspec";
d62a17ae 8273 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8274 return "l2VpnEvpn";
8275 else
8276 return "Unknown";
27162734
LB
8277}
8278
718e3744 8279/* Show BGP peer's information. */
d62a17ae 8280enum show_type { show_all, show_peer };
8281
8282static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8283 afi_t afi, safi_t safi,
d7c0a89a
QY
8284 uint16_t adv_smcap, uint16_t adv_rmcap,
8285 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8286 uint8_t use_json, json_object *json_pref)
d62a17ae 8287{
8288 /* Send-Mode */
8289 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8290 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8291 if (use_json) {
8292 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8293 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8294 json_object_string_add(json_pref, "sendMode",
8295 "advertisedAndReceived");
8296 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8297 json_object_string_add(json_pref, "sendMode",
8298 "advertised");
8299 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8300 json_object_string_add(json_pref, "sendMode",
8301 "received");
8302 } else {
8303 vty_out(vty, " Send-mode: ");
8304 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8305 vty_out(vty, "advertised");
8306 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8307 vty_out(vty, "%sreceived",
8308 CHECK_FLAG(p->af_cap[afi][safi],
8309 adv_smcap)
8310 ? ", "
8311 : "");
8312 vty_out(vty, "\n");
8313 }
8314 }
8315
8316 /* Receive-Mode */
8317 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8318 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8319 if (use_json) {
8320 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8321 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8322 json_object_string_add(json_pref, "recvMode",
8323 "advertisedAndReceived");
8324 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8325 json_object_string_add(json_pref, "recvMode",
8326 "advertised");
8327 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8328 json_object_string_add(json_pref, "recvMode",
8329 "received");
8330 } else {
8331 vty_out(vty, " Receive-mode: ");
8332 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8333 vty_out(vty, "advertised");
8334 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8335 vty_out(vty, "%sreceived",
8336 CHECK_FLAG(p->af_cap[afi][safi],
8337 adv_rmcap)
8338 ? ", "
8339 : "");
8340 vty_out(vty, "\n");
8341 }
8342 }
8343}
8344
8345static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
d7c0a89a 8346 safi_t safi, uint8_t use_json,
d62a17ae 8347 json_object *json_neigh)
8348{
0291c246
MK
8349 struct bgp_filter *filter;
8350 struct peer_af *paf;
8351 char orf_pfx_name[BUFSIZ];
8352 int orf_pfx_count;
8353 json_object *json_af = NULL;
8354 json_object *json_prefA = NULL;
8355 json_object *json_prefB = NULL;
8356 json_object *json_addr = NULL;
d62a17ae 8357
8358 if (use_json) {
8359 json_addr = json_object_new_object();
8360 json_af = json_object_new_object();
8361 filter = &p->filter[afi][safi];
8362
8363 if (peer_group_active(p))
8364 json_object_string_add(json_addr, "peerGroupMember",
8365 p->group->name);
8366
8367 paf = peer_af_find(p, afi, safi);
8368 if (paf && PAF_SUBGRP(paf)) {
8369 json_object_int_add(json_addr, "updateGroupId",
8370 PAF_UPDGRP(paf)->id);
8371 json_object_int_add(json_addr, "subGroupId",
8372 PAF_SUBGRP(paf)->id);
8373 json_object_int_add(json_addr, "packetQueueLength",
8374 bpacket_queue_virtual_length(paf));
8375 }
8376
8377 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8378 || CHECK_FLAG(p->af_cap[afi][safi],
8379 PEER_CAP_ORF_PREFIX_SM_RCV)
8380 || CHECK_FLAG(p->af_cap[afi][safi],
8381 PEER_CAP_ORF_PREFIX_RM_ADV)
8382 || CHECK_FLAG(p->af_cap[afi][safi],
8383 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8384 json_object_int_add(json_af, "orfType",
8385 ORF_TYPE_PREFIX);
8386 json_prefA = json_object_new_object();
8387 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8388 PEER_CAP_ORF_PREFIX_SM_ADV,
8389 PEER_CAP_ORF_PREFIX_RM_ADV,
8390 PEER_CAP_ORF_PREFIX_SM_RCV,
8391 PEER_CAP_ORF_PREFIX_RM_RCV,
8392 use_json, json_prefA);
8393 json_object_object_add(json_af, "orfPrefixList",
8394 json_prefA);
8395 }
8396
8397 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8398 || CHECK_FLAG(p->af_cap[afi][safi],
8399 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8400 || CHECK_FLAG(p->af_cap[afi][safi],
8401 PEER_CAP_ORF_PREFIX_RM_ADV)
8402 || CHECK_FLAG(p->af_cap[afi][safi],
8403 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8404 json_object_int_add(json_af, "orfOldType",
8405 ORF_TYPE_PREFIX_OLD);
8406 json_prefB = json_object_new_object();
8407 bgp_show_peer_afi_orf_cap(
8408 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8409 PEER_CAP_ORF_PREFIX_RM_ADV,
8410 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8411 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8412 json_prefB);
8413 json_object_object_add(json_af, "orfOldPrefixList",
8414 json_prefB);
8415 }
8416
8417 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8418 || CHECK_FLAG(p->af_cap[afi][safi],
8419 PEER_CAP_ORF_PREFIX_SM_RCV)
8420 || CHECK_FLAG(p->af_cap[afi][safi],
8421 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8422 || CHECK_FLAG(p->af_cap[afi][safi],
8423 PEER_CAP_ORF_PREFIX_RM_ADV)
8424 || CHECK_FLAG(p->af_cap[afi][safi],
8425 PEER_CAP_ORF_PREFIX_RM_RCV)
8426 || CHECK_FLAG(p->af_cap[afi][safi],
8427 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8428 json_object_object_add(json_addr, "afDependentCap",
8429 json_af);
8430 else
8431 json_object_free(json_af);
8432
8433 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8434 orf_pfx_count = prefix_bgp_show_prefix_list(
8435 NULL, afi, orf_pfx_name, use_json);
8436
8437 if (CHECK_FLAG(p->af_sflags[afi][safi],
8438 PEER_STATUS_ORF_PREFIX_SEND)
8439 || orf_pfx_count) {
8440 if (CHECK_FLAG(p->af_sflags[afi][safi],
8441 PEER_STATUS_ORF_PREFIX_SEND))
8442 json_object_boolean_true_add(json_neigh,
8443 "orfSent");
8444 if (orf_pfx_count)
8445 json_object_int_add(json_addr, "orfRecvCounter",
8446 orf_pfx_count);
8447 }
8448 if (CHECK_FLAG(p->af_sflags[afi][safi],
8449 PEER_STATUS_ORF_WAIT_REFRESH))
8450 json_object_string_add(
8451 json_addr, "orfFirstUpdate",
8452 "deferredUntilORFOrRouteRefreshRecvd");
8453
8454 if (CHECK_FLAG(p->af_flags[afi][safi],
8455 PEER_FLAG_REFLECTOR_CLIENT))
8456 json_object_boolean_true_add(json_addr,
8457 "routeReflectorClient");
8458 if (CHECK_FLAG(p->af_flags[afi][safi],
8459 PEER_FLAG_RSERVER_CLIENT))
8460 json_object_boolean_true_add(json_addr,
8461 "routeServerClient");
8462 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8463 json_object_boolean_true_add(json_addr,
8464 "inboundSoftConfigPermit");
8465
8466 if (CHECK_FLAG(p->af_flags[afi][safi],
8467 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8468 json_object_boolean_true_add(
8469 json_addr,
8470 "privateAsNumsAllReplacedInUpdatesToNbr");
8471 else if (CHECK_FLAG(p->af_flags[afi][safi],
8472 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8473 json_object_boolean_true_add(
8474 json_addr,
8475 "privateAsNumsReplacedInUpdatesToNbr");
8476 else if (CHECK_FLAG(p->af_flags[afi][safi],
8477 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8478 json_object_boolean_true_add(
8479 json_addr,
8480 "privateAsNumsAllRemovedInUpdatesToNbr");
8481 else if (CHECK_FLAG(p->af_flags[afi][safi],
8482 PEER_FLAG_REMOVE_PRIVATE_AS))
8483 json_object_boolean_true_add(
8484 json_addr,
8485 "privateAsNumsRemovedInUpdatesToNbr");
8486
8487 if (CHECK_FLAG(p->af_flags[afi][safi],
8488 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8489 json_object_boolean_true_add(json_addr,
8490 "addpathTxAllPaths");
8491
8492 if (CHECK_FLAG(p->af_flags[afi][safi],
8493 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8494 json_object_boolean_true_add(json_addr,
8495 "addpathTxBestpathPerAS");
8496
8497 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8498 json_object_string_add(json_addr,
8499 "overrideASNsInOutboundUpdates",
8500 "ifAspathEqualRemoteAs");
8501
8502 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8503 || CHECK_FLAG(p->af_flags[afi][safi],
8504 PEER_FLAG_FORCE_NEXTHOP_SELF))
8505 json_object_boolean_true_add(json_addr,
8506 "routerAlwaysNextHop");
8507 if (CHECK_FLAG(p->af_flags[afi][safi],
8508 PEER_FLAG_AS_PATH_UNCHANGED))
8509 json_object_boolean_true_add(
8510 json_addr, "unchangedAsPathPropogatedToNbr");
8511 if (CHECK_FLAG(p->af_flags[afi][safi],
8512 PEER_FLAG_NEXTHOP_UNCHANGED))
8513 json_object_boolean_true_add(
8514 json_addr, "unchangedNextHopPropogatedToNbr");
8515 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8516 json_object_boolean_true_add(
8517 json_addr, "unchangedMedPropogatedToNbr");
8518 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8519 || CHECK_FLAG(p->af_flags[afi][safi],
8520 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8521 if (CHECK_FLAG(p->af_flags[afi][safi],
8522 PEER_FLAG_SEND_COMMUNITY)
8523 && CHECK_FLAG(p->af_flags[afi][safi],
8524 PEER_FLAG_SEND_EXT_COMMUNITY))
8525 json_object_string_add(json_addr,
8526 "commAttriSentToNbr",
8527 "extendedAndStandard");
8528 else if (CHECK_FLAG(p->af_flags[afi][safi],
8529 PEER_FLAG_SEND_EXT_COMMUNITY))
8530 json_object_string_add(json_addr,
8531 "commAttriSentToNbr",
8532 "extended");
8533 else
8534 json_object_string_add(json_addr,
8535 "commAttriSentToNbr",
8536 "standard");
8537 }
8538 if (CHECK_FLAG(p->af_flags[afi][safi],
8539 PEER_FLAG_DEFAULT_ORIGINATE)) {
8540 if (p->default_rmap[afi][safi].name)
8541 json_object_string_add(
8542 json_addr, "defaultRouteMap",
8543 p->default_rmap[afi][safi].name);
8544
8545 if (paf && PAF_SUBGRP(paf)
8546 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8547 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8548 json_object_boolean_true_add(json_addr,
8549 "defaultSent");
8550 else
8551 json_object_boolean_true_add(json_addr,
8552 "defaultNotSent");
8553 }
8554
dff8f48d 8555 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8556 if (is_evpn_enabled())
60466a63
QY
8557 json_object_boolean_true_add(
8558 json_addr, "advertiseAllVnis");
dff8f48d
MK
8559 }
8560
d62a17ae 8561 if (filter->plist[FILTER_IN].name
8562 || filter->dlist[FILTER_IN].name
8563 || filter->aslist[FILTER_IN].name
8564 || filter->map[RMAP_IN].name)
8565 json_object_boolean_true_add(json_addr,
8566 "inboundPathPolicyConfig");
8567 if (filter->plist[FILTER_OUT].name
8568 || filter->dlist[FILTER_OUT].name
8569 || filter->aslist[FILTER_OUT].name
8570 || filter->map[RMAP_OUT].name || filter->usmap.name)
8571 json_object_boolean_true_add(
8572 json_addr, "outboundPathPolicyConfig");
8573
8574 /* prefix-list */
8575 if (filter->plist[FILTER_IN].name)
8576 json_object_string_add(json_addr,
8577 "incomingUpdatePrefixFilterList",
8578 filter->plist[FILTER_IN].name);
8579 if (filter->plist[FILTER_OUT].name)
8580 json_object_string_add(json_addr,
8581 "outgoingUpdatePrefixFilterList",
8582 filter->plist[FILTER_OUT].name);
8583
8584 /* distribute-list */
8585 if (filter->dlist[FILTER_IN].name)
8586 json_object_string_add(
8587 json_addr, "incomingUpdateNetworkFilterList",
8588 filter->dlist[FILTER_IN].name);
8589 if (filter->dlist[FILTER_OUT].name)
8590 json_object_string_add(
8591 json_addr, "outgoingUpdateNetworkFilterList",
8592 filter->dlist[FILTER_OUT].name);
8593
8594 /* filter-list. */
8595 if (filter->aslist[FILTER_IN].name)
8596 json_object_string_add(json_addr,
8597 "incomingUpdateAsPathFilterList",
8598 filter->aslist[FILTER_IN].name);
8599 if (filter->aslist[FILTER_OUT].name)
8600 json_object_string_add(json_addr,
8601 "outgoingUpdateAsPathFilterList",
8602 filter->aslist[FILTER_OUT].name);
8603
8604 /* route-map. */
8605 if (filter->map[RMAP_IN].name)
8606 json_object_string_add(
8607 json_addr, "routeMapForIncomingAdvertisements",
8608 filter->map[RMAP_IN].name);
8609 if (filter->map[RMAP_OUT].name)
8610 json_object_string_add(
8611 json_addr, "routeMapForOutgoingAdvertisements",
8612 filter->map[RMAP_OUT].name);
8613
8614 /* unsuppress-map */
8615 if (filter->usmap.name)
8616 json_object_string_add(json_addr,
8617 "selectiveUnsuppressRouteMap",
8618 filter->usmap.name);
8619
8620 /* Receive prefix count */
8621 json_object_int_add(json_addr, "acceptedPrefixCounter",
8622 p->pcount[afi][safi]);
8623
8624 /* Maximum prefix */
8625 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8626 json_object_int_add(json_addr, "prefixAllowedMax",
8627 p->pmax[afi][safi]);
8628 if (CHECK_FLAG(p->af_flags[afi][safi],
8629 PEER_FLAG_MAX_PREFIX_WARNING))
8630 json_object_boolean_true_add(
8631 json_addr, "prefixAllowedMaxWarning");
8632 json_object_int_add(json_addr,
8633 "prefixAllowedWarningThresh",
8634 p->pmax_threshold[afi][safi]);
8635 if (p->pmax_restart[afi][safi])
8636 json_object_int_add(
8637 json_addr,
8638 "prefixAllowedRestartIntervalMsecs",
8639 p->pmax_restart[afi][safi] * 60000);
8640 }
8641 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8642 json_addr);
8643
8644 } else {
8645 filter = &p->filter[afi][safi];
8646
8647 vty_out(vty, " For address family: %s\n",
8648 afi_safi_print(afi, safi));
8649
8650 if (peer_group_active(p))
8651 vty_out(vty, " %s peer-group member\n",
8652 p->group->name);
8653
8654 paf = peer_af_find(p, afi, safi);
8655 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8656 vty_out(vty, " Update group %" PRIu64
8657 ", subgroup %" PRIu64 "\n",
d62a17ae 8658 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8659 vty_out(vty, " Packet Queue length %d\n",
8660 bpacket_queue_virtual_length(paf));
8661 } else {
8662 vty_out(vty, " Not part of any update group\n");
8663 }
8664 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8665 || CHECK_FLAG(p->af_cap[afi][safi],
8666 PEER_CAP_ORF_PREFIX_SM_RCV)
8667 || CHECK_FLAG(p->af_cap[afi][safi],
8668 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8669 || CHECK_FLAG(p->af_cap[afi][safi],
8670 PEER_CAP_ORF_PREFIX_RM_ADV)
8671 || CHECK_FLAG(p->af_cap[afi][safi],
8672 PEER_CAP_ORF_PREFIX_RM_RCV)
8673 || CHECK_FLAG(p->af_cap[afi][safi],
8674 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8675 vty_out(vty, " AF-dependant capabilities:\n");
8676
8677 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8678 || CHECK_FLAG(p->af_cap[afi][safi],
8679 PEER_CAP_ORF_PREFIX_SM_RCV)
8680 || CHECK_FLAG(p->af_cap[afi][safi],
8681 PEER_CAP_ORF_PREFIX_RM_ADV)
8682 || CHECK_FLAG(p->af_cap[afi][safi],
8683 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8684 vty_out(vty,
8685 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8686 ORF_TYPE_PREFIX);
8687 bgp_show_peer_afi_orf_cap(
8688 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8689 PEER_CAP_ORF_PREFIX_RM_ADV,
8690 PEER_CAP_ORF_PREFIX_SM_RCV,
8691 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8692 }
8693 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8694 || CHECK_FLAG(p->af_cap[afi][safi],
8695 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8696 || CHECK_FLAG(p->af_cap[afi][safi],
8697 PEER_CAP_ORF_PREFIX_RM_ADV)
8698 || CHECK_FLAG(p->af_cap[afi][safi],
8699 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8700 vty_out(vty,
8701 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8702 ORF_TYPE_PREFIX_OLD);
8703 bgp_show_peer_afi_orf_cap(
8704 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8705 PEER_CAP_ORF_PREFIX_RM_ADV,
8706 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8707 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8708 }
8709
8710 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8711 orf_pfx_count = prefix_bgp_show_prefix_list(
8712 NULL, afi, orf_pfx_name, use_json);
8713
8714 if (CHECK_FLAG(p->af_sflags[afi][safi],
8715 PEER_STATUS_ORF_PREFIX_SEND)
8716 || orf_pfx_count) {
8717 vty_out(vty, " Outbound Route Filter (ORF):");
8718 if (CHECK_FLAG(p->af_sflags[afi][safi],
8719 PEER_STATUS_ORF_PREFIX_SEND))
8720 vty_out(vty, " sent;");
8721 if (orf_pfx_count)
8722 vty_out(vty, " received (%d entries)",
8723 orf_pfx_count);
8724 vty_out(vty, "\n");
8725 }
8726 if (CHECK_FLAG(p->af_sflags[afi][safi],
8727 PEER_STATUS_ORF_WAIT_REFRESH))
8728 vty_out(vty,
8729 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8730
8731 if (CHECK_FLAG(p->af_flags[afi][safi],
8732 PEER_FLAG_REFLECTOR_CLIENT))
8733 vty_out(vty, " Route-Reflector Client\n");
8734 if (CHECK_FLAG(p->af_flags[afi][safi],
8735 PEER_FLAG_RSERVER_CLIENT))
8736 vty_out(vty, " Route-Server Client\n");
8737 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8738 vty_out(vty,
8739 " Inbound soft reconfiguration allowed\n");
8740
8741 if (CHECK_FLAG(p->af_flags[afi][safi],
8742 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8743 vty_out(vty,
8744 " Private AS numbers (all) replaced in updates to this neighbor\n");
8745 else if (CHECK_FLAG(p->af_flags[afi][safi],
8746 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8747 vty_out(vty,
8748 " Private AS numbers replaced in updates to this neighbor\n");
8749 else if (CHECK_FLAG(p->af_flags[afi][safi],
8750 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8751 vty_out(vty,
8752 " Private AS numbers (all) removed in updates to this neighbor\n");
8753 else if (CHECK_FLAG(p->af_flags[afi][safi],
8754 PEER_FLAG_REMOVE_PRIVATE_AS))
8755 vty_out(vty,
8756 " Private AS numbers removed in updates to this neighbor\n");
8757
8758 if (CHECK_FLAG(p->af_flags[afi][safi],
8759 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8760 vty_out(vty, " Advertise all paths via addpath\n");
8761
8762 if (CHECK_FLAG(p->af_flags[afi][safi],
8763 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8764 vty_out(vty,
8765 " Advertise bestpath per AS via addpath\n");
8766
8767 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8768 vty_out(vty,
8769 " Override ASNs in outbound updates if aspath equals remote-as\n");
8770
8771 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8772 || CHECK_FLAG(p->af_flags[afi][safi],
8773 PEER_FLAG_FORCE_NEXTHOP_SELF))
8774 vty_out(vty, " NEXT_HOP is always this router\n");
8775 if (CHECK_FLAG(p->af_flags[afi][safi],
8776 PEER_FLAG_AS_PATH_UNCHANGED))
8777 vty_out(vty,
8778 " AS_PATH is propagated unchanged to this neighbor\n");
8779 if (CHECK_FLAG(p->af_flags[afi][safi],
8780 PEER_FLAG_NEXTHOP_UNCHANGED))
8781 vty_out(vty,
8782 " NEXT_HOP is propagated unchanged to this neighbor\n");
8783 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8784 vty_out(vty,
8785 " MED is propagated unchanged to this neighbor\n");
8786 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8787 || CHECK_FLAG(p->af_flags[afi][safi],
8788 PEER_FLAG_SEND_EXT_COMMUNITY)
8789 || CHECK_FLAG(p->af_flags[afi][safi],
8790 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8791 vty_out(vty,
8792 " Community attribute sent to this neighbor");
8793 if (CHECK_FLAG(p->af_flags[afi][safi],
8794 PEER_FLAG_SEND_COMMUNITY)
8795 && CHECK_FLAG(p->af_flags[afi][safi],
8796 PEER_FLAG_SEND_EXT_COMMUNITY)
8797 && CHECK_FLAG(p->af_flags[afi][safi],
8798 PEER_FLAG_SEND_LARGE_COMMUNITY))
8799 vty_out(vty, "(all)\n");
8800 else if (CHECK_FLAG(p->af_flags[afi][safi],
8801 PEER_FLAG_SEND_LARGE_COMMUNITY))
8802 vty_out(vty, "(large)\n");
8803 else if (CHECK_FLAG(p->af_flags[afi][safi],
8804 PEER_FLAG_SEND_EXT_COMMUNITY))
8805 vty_out(vty, "(extended)\n");
8806 else
8807 vty_out(vty, "(standard)\n");
8808 }
8809 if (CHECK_FLAG(p->af_flags[afi][safi],
8810 PEER_FLAG_DEFAULT_ORIGINATE)) {
8811 vty_out(vty, " Default information originate,");
8812
8813 if (p->default_rmap[afi][safi].name)
8814 vty_out(vty, " default route-map %s%s,",
8815 p->default_rmap[afi][safi].map ? "*"
8816 : "",
8817 p->default_rmap[afi][safi].name);
8818 if (paf && PAF_SUBGRP(paf)
8819 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8820 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8821 vty_out(vty, " default sent\n");
8822 else
8823 vty_out(vty, " default not sent\n");
8824 }
8825
dff8f48d
MK
8826 /* advertise-vni-all */
8827 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8828 if (is_evpn_enabled())
dff8f48d
MK
8829 vty_out(vty, " advertise-all-vni\n");
8830 }
8831
d62a17ae 8832 if (filter->plist[FILTER_IN].name
8833 || filter->dlist[FILTER_IN].name
8834 || filter->aslist[FILTER_IN].name
8835 || filter->map[RMAP_IN].name)
8836 vty_out(vty, " Inbound path policy configured\n");
8837 if (filter->plist[FILTER_OUT].name
8838 || filter->dlist[FILTER_OUT].name
8839 || filter->aslist[FILTER_OUT].name
8840 || filter->map[RMAP_OUT].name || filter->usmap.name)
8841 vty_out(vty, " Outbound path policy configured\n");
8842
8843 /* prefix-list */
8844 if (filter->plist[FILTER_IN].name)
8845 vty_out(vty,
8846 " Incoming update prefix filter list is %s%s\n",
8847 filter->plist[FILTER_IN].plist ? "*" : "",
8848 filter->plist[FILTER_IN].name);
8849 if (filter->plist[FILTER_OUT].name)
8850 vty_out(vty,
8851 " Outgoing update prefix filter list is %s%s\n",
8852 filter->plist[FILTER_OUT].plist ? "*" : "",
8853 filter->plist[FILTER_OUT].name);
8854
8855 /* distribute-list */
8856 if (filter->dlist[FILTER_IN].name)
8857 vty_out(vty,
8858 " Incoming update network filter list is %s%s\n",
8859 filter->dlist[FILTER_IN].alist ? "*" : "",
8860 filter->dlist[FILTER_IN].name);
8861 if (filter->dlist[FILTER_OUT].name)
8862 vty_out(vty,
8863 " Outgoing update network filter list is %s%s\n",
8864 filter->dlist[FILTER_OUT].alist ? "*" : "",
8865 filter->dlist[FILTER_OUT].name);
8866
8867 /* filter-list. */
8868 if (filter->aslist[FILTER_IN].name)
8869 vty_out(vty,
8870 " Incoming update AS path filter list is %s%s\n",
8871 filter->aslist[FILTER_IN].aslist ? "*" : "",
8872 filter->aslist[FILTER_IN].name);
8873 if (filter->aslist[FILTER_OUT].name)
8874 vty_out(vty,
8875 " Outgoing update AS path filter list is %s%s\n",
8876 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8877 filter->aslist[FILTER_OUT].name);
8878
8879 /* route-map. */
8880 if (filter->map[RMAP_IN].name)
8881 vty_out(vty,
8882 " Route map for incoming advertisements is %s%s\n",
8883 filter->map[RMAP_IN].map ? "*" : "",
8884 filter->map[RMAP_IN].name);
8885 if (filter->map[RMAP_OUT].name)
8886 vty_out(vty,
8887 " Route map for outgoing advertisements is %s%s\n",
8888 filter->map[RMAP_OUT].map ? "*" : "",
8889 filter->map[RMAP_OUT].name);
8890
8891 /* unsuppress-map */
8892 if (filter->usmap.name)
8893 vty_out(vty,
8894 " Route map for selective unsuppress is %s%s\n",
8895 filter->usmap.map ? "*" : "",
8896 filter->usmap.name);
8897
8898 /* Receive prefix count */
8899 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8900
8901 /* Maximum prefix */
8902 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8903 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8904 p->pmax[afi][safi],
8905 CHECK_FLAG(p->af_flags[afi][safi],
8906 PEER_FLAG_MAX_PREFIX_WARNING)
8907 ? " (warning-only)"
8908 : "");
8909 vty_out(vty, " Threshold for warning message %d%%",
8910 p->pmax_threshold[afi][safi]);
8911 if (p->pmax_restart[afi][safi])
8912 vty_out(vty, ", restart interval %d min",
8913 p->pmax_restart[afi][safi]);
8914 vty_out(vty, "\n");
8915 }
8916
8917 vty_out(vty, "\n");
8918 }
8919}
8920
d7c0a89a 8921static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
d62a17ae 8922 json_object *json)
718e3744 8923{
d62a17ae 8924 struct bgp *bgp;
8925 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8926 char timebuf[BGP_UPTIME_LEN];
8927 char dn_flag[2];
8928 const char *subcode_str;
8929 const char *code_str;
8930 afi_t afi;
8931 safi_t safi;
d7c0a89a
QY
8932 uint16_t i;
8933 uint8_t *msg;
d62a17ae 8934 json_object *json_neigh = NULL;
8935 time_t epoch_tbuf;
718e3744 8936
d62a17ae 8937 bgp = p->bgp;
8938
8939 if (use_json)
8940 json_neigh = json_object_new_object();
8941
8942 memset(dn_flag, '\0', sizeof(dn_flag));
8943 if (!p->conf_if && peer_dynamic_neighbor(p))
8944 dn_flag[0] = '*';
8945
8946 if (!use_json) {
8947 if (p->conf_if) /* Configured interface name. */
8948 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8949 BGP_PEER_SU_UNSPEC(p)
8950 ? "None"
8951 : sockunion2str(&p->su, buf,
8952 SU_ADDRSTRLEN));
8953 else /* Configured IP address. */
8954 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8955 p->host);
8956 }
8957
8958 if (use_json) {
8959 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8960 json_object_string_add(json_neigh, "bgpNeighborAddr",
8961 "none");
8962 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8963 json_object_string_add(
8964 json_neigh, "bgpNeighborAddr",
8965 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8966
8967 json_object_int_add(json_neigh, "remoteAs", p->as);
8968
8969 if (p->change_local_as)
8970 json_object_int_add(json_neigh, "localAs",
8971 p->change_local_as);
8972 else
8973 json_object_int_add(json_neigh, "localAs", p->local_as);
8974
8975 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8976 json_object_boolean_true_add(json_neigh,
8977 "localAsNoPrepend");
8978
8979 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8980 json_object_boolean_true_add(json_neigh,
8981 "localAsReplaceAs");
8982 } else {
8983 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8984 || (p->as_type == AS_INTERNAL))
8985 vty_out(vty, "remote AS %u, ", p->as);
8986 else
8987 vty_out(vty, "remote AS Unspecified, ");
8988 vty_out(vty, "local AS %u%s%s, ",
8989 p->change_local_as ? p->change_local_as : p->local_as,
8990 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8991 ? " no-prepend"
8992 : "",
8993 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8994 ? " replace-as"
8995 : "");
8996 }
8997 /* peer type internal, external, confed-internal or confed-external */
8998 if (p->as == p->local_as) {
8999 if (use_json) {
9000 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9001 json_object_boolean_true_add(
9002 json_neigh, "nbrConfedInternalLink");
9003 else
9004 json_object_boolean_true_add(json_neigh,
9005 "nbrInternalLink");
9006 } else {
9007 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9008 vty_out(vty, "confed-internal link\n");
9009 else
9010 vty_out(vty, "internal link\n");
9011 }
9012 } else {
9013 if (use_json) {
9014 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9015 json_object_boolean_true_add(
9016 json_neigh, "nbrConfedExternalLink");
9017 else
9018 json_object_boolean_true_add(json_neigh,
9019 "nbrExternalLink");
9020 } else {
9021 if (bgp_confederation_peers_check(bgp, p->as))
9022 vty_out(vty, "confed-external link\n");
9023 else
9024 vty_out(vty, "external link\n");
9025 }
9026 }
9027
9028 /* Description. */
9029 if (p->desc) {
9030 if (use_json)
9031 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9032 else
9033 vty_out(vty, " Description: %s\n", p->desc);
9034 }
9035
9036 if (p->hostname) {
9037 if (use_json) {
9038 if (p->hostname)
9039 json_object_string_add(json_neigh, "hostname",
9040 p->hostname);
9041
9042 if (p->domainname)
9043 json_object_string_add(json_neigh, "domainname",
9044 p->domainname);
9045 } else {
9046 if (p->domainname && (p->domainname[0] != '\0'))
9047 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9048 p->domainname);
9049 else
9050 vty_out(vty, "Hostname: %s\n", p->hostname);
9051 }
9052 }
9053
9054 /* Peer-group */
9055 if (p->group) {
9056 if (use_json) {
9057 json_object_string_add(json_neigh, "peerGroup",
9058 p->group->name);
9059
9060 if (dn_flag[0]) {
9061 struct prefix prefix, *range = NULL;
9062
9063 sockunion2hostprefix(&(p->su), &prefix);
9064 range = peer_group_lookup_dynamic_neighbor_range(
9065 p->group, &prefix);
9066
9067 if (range) {
9068 prefix2str(range, buf1, sizeof(buf1));
9069 json_object_string_add(
9070 json_neigh,
9071 "peerSubnetRangeGroup", buf1);
9072 }
9073 }
9074 } else {
9075 vty_out(vty,
9076 " Member of peer-group %s for session parameters\n",
9077 p->group->name);
9078
9079 if (dn_flag[0]) {
9080 struct prefix prefix, *range = NULL;
9081
9082 sockunion2hostprefix(&(p->su), &prefix);
9083 range = peer_group_lookup_dynamic_neighbor_range(
9084 p->group, &prefix);
9085
9086 if (range) {
9087 prefix2str(range, buf1, sizeof(buf1));
9088 vty_out(vty,
9089 " Belongs to the subnet range group: %s\n",
9090 buf1);
9091 }
9092 }
9093 }
9094 }
9095
9096 if (use_json) {
9097 /* Administrative shutdown. */
9098 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9099 json_object_boolean_true_add(json_neigh,
9100 "adminShutDown");
9101
9102 /* BGP Version. */
9103 json_object_int_add(json_neigh, "bgpVersion", 4);
9104 json_object_string_add(
9105 json_neigh, "remoteRouterId",
9106 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9107
9108 /* Confederation */
9109 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9110 && bgp_confederation_peers_check(bgp, p->as))
9111 json_object_boolean_true_add(json_neigh,
9112 "nbrCommonAdmin");
9113
9114 /* Status. */
9115 json_object_string_add(
9116 json_neigh, "bgpState",
9117 lookup_msg(bgp_status_msg, p->status, NULL));
9118
9119 if (p->status == Established) {
9120 time_t uptime;
d62a17ae 9121
9122 uptime = bgp_clock();
9123 uptime -= p->uptime;
d62a17ae 9124 epoch_tbuf = time(NULL) - uptime;
9125
e24be241 9126#if defined(VERSION_TYPE_DEV) && CONFDATE > 20200101
a4d82a8a
PZ
9127 CPP_NOTICE(
9128 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9129#endif
9130 /*
9131 * bgpTimerUp was miliseconds that was accurate
9132 * up to 1 day, then the value returned
9133 * became garbage. So in order to provide
9134 * some level of backwards compatability,
9135 * we still provde the data, but now
9136 * we are returning the correct value
9137 * and also adding a new bgpTimerUpMsec
9138 * which will allow us to deprecate
9139 * this eventually
9140 */
d62a17ae 9141 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9142 uptime * 1000);
d3c7efed
DS
9143 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9144 uptime * 1000);
d62a17ae 9145 json_object_string_add(json_neigh, "bgpTimerUpString",
9146 peer_uptime(p->uptime, timebuf,
9147 BGP_UPTIME_LEN, 0,
9148 NULL));
9149 json_object_int_add(json_neigh,
9150 "bgpTimerUpEstablishedEpoch",
9151 epoch_tbuf);
9152 }
9153
9154 else if (p->status == Active) {
9155 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9156 json_object_string_add(json_neigh, "bgpStateIs",
9157 "passive");
9158 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9159 json_object_string_add(json_neigh, "bgpStateIs",
9160 "passiveNSF");
9161 }
9162
9163 /* read timer */
9164 time_t uptime;
9165 struct tm *tm;
9166
9167 uptime = bgp_clock();
9168 uptime -= p->readtime;
9169 tm = gmtime(&uptime);
9170 json_object_int_add(json_neigh, "bgpTimerLastRead",
9171 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9172 + (tm->tm_hour * 3600000));
9173
9174 uptime = bgp_clock();
9175 uptime -= p->last_write;
9176 tm = gmtime(&uptime);
9177 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9178 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9179 + (tm->tm_hour * 3600000));
9180
9181 uptime = bgp_clock();
9182 uptime -= p->update_time;
9183 tm = gmtime(&uptime);
9184 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9185 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9186 + (tm->tm_hour * 3600000));
9187
9188 /* Configured timer values. */
9189 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9190 p->v_holdtime * 1000);
9191 json_object_int_add(json_neigh,
9192 "bgpTimerKeepAliveIntervalMsecs",
9193 p->v_keepalive * 1000);
9194
d25e4efc 9195 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 9196 json_object_int_add(json_neigh,
9197 "bgpTimerConfiguredHoldTimeMsecs",
9198 p->holdtime * 1000);
9199 json_object_int_add(
9200 json_neigh,
9201 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9202 p->keepalive * 1000);
d25e4efc 9203 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9204 || (bgp->default_keepalive
9205 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9206 json_object_int_add(json_neigh,
9207 "bgpTimerConfiguredHoldTimeMsecs",
9208 bgp->default_holdtime);
9209 json_object_int_add(
9210 json_neigh,
9211 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9212 bgp->default_keepalive);
d62a17ae 9213 }
9214 } else {
9215 /* Administrative shutdown. */
9216 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9217 vty_out(vty, " Administratively shut down\n");
9218
9219 /* BGP Version. */
9220 vty_out(vty, " BGP version 4");
9221 vty_out(vty, ", remote router ID %s\n",
9222 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9223
9224 /* Confederation */
9225 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9226 && bgp_confederation_peers_check(bgp, p->as))
9227 vty_out(vty,
9228 " Neighbor under common administration\n");
9229
9230 /* Status. */
9231 vty_out(vty, " BGP state = %s",
9232 lookup_msg(bgp_status_msg, p->status, NULL));
9233
9234 if (p->status == Established)
9235 vty_out(vty, ", up for %8s",
9236 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9237 0, NULL));
9238
9239 else if (p->status == Active) {
9240 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9241 vty_out(vty, " (passive)");
9242 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9243 vty_out(vty, " (NSF passive)");
9244 }
9245 vty_out(vty, "\n");
9246
9247 /* read timer */
9248 vty_out(vty, " Last read %s",
9249 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9250 NULL));
9251 vty_out(vty, ", Last write %s\n",
9252 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9253 NULL));
9254
9255 /* Configured timer values. */
9256 vty_out(vty,
9257 " Hold time is %d, keepalive interval is %d seconds\n",
9258 p->v_holdtime, p->v_keepalive);
d25e4efc 9259 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 9260 vty_out(vty, " Configured hold time is %d",
9261 p->holdtime);
9262 vty_out(vty, ", keepalive interval is %d seconds\n",
9263 p->keepalive);
d25e4efc 9264 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9265 || (bgp->default_keepalive
9266 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9267 vty_out(vty, " Configured hold time is %d",
9268 bgp->default_holdtime);
9269 vty_out(vty, ", keepalive interval is %d seconds\n",
9270 bgp->default_keepalive);
d62a17ae 9271 }
9272 }
9273 /* Capability. */
9274 if (p->status == Established) {
9275 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9276 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9277 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9278 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9279 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9280 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9281 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9282 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9283 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9284 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9285 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9286 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9287 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9288 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9289 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9290 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9291 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9292 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9293 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9294 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9295 if (use_json) {
9296 json_object *json_cap = NULL;
9297
9298 json_cap = json_object_new_object();
9299
9300 /* AS4 */
9301 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9302 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9303 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9304 && CHECK_FLAG(p->cap,
9305 PEER_CAP_AS4_RCV))
9306 json_object_string_add(
9307 json_cap, "4byteAs",
9308 "advertisedAndReceived");
9309 else if (CHECK_FLAG(p->cap,
9310 PEER_CAP_AS4_ADV))
9311 json_object_string_add(
9312 json_cap, "4byteAs",
9313 "advertised");
9314 else if (CHECK_FLAG(p->cap,
9315 PEER_CAP_AS4_RCV))
9316 json_object_string_add(
9317 json_cap, "4byteAs",
9318 "received");
9319 }
9320
9321 /* AddPath */
9322 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9323 || CHECK_FLAG(p->cap,
9324 PEER_CAP_ADDPATH_ADV)) {
9325 json_object *json_add = NULL;
9326 const char *print_store;
9327
9328 json_add = json_object_new_object();
9329
05c7a1cc
QY
9330 FOREACH_AFI_SAFI (afi, safi) {
9331 json_object *json_sub = NULL;
9332 json_sub =
9333 json_object_new_object();
9334 print_store = afi_safi_print(
9335 afi, safi);
d62a17ae 9336
05c7a1cc
QY
9337 if (CHECK_FLAG(
9338 p->af_cap[afi]
9339 [safi],
9340 PEER_CAP_ADDPATH_AF_TX_ADV)
9341 || CHECK_FLAG(
9342 p->af_cap[afi]
9343 [safi],
9344 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9345 if (CHECK_FLAG(
9346 p->af_cap
9347 [afi]
9348 [safi],
9349 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9350 && CHECK_FLAG(
d62a17ae 9351 p->af_cap
9352 [afi]
9353 [safi],
05c7a1cc
QY
9354 PEER_CAP_ADDPATH_AF_TX_RCV))
9355 json_object_boolean_true_add(
9356 json_sub,
9357 "txAdvertisedAndReceived");
9358 else if (
9359 CHECK_FLAG(
9360 p->af_cap
9361 [afi]
9362 [safi],
9363 PEER_CAP_ADDPATH_AF_TX_ADV))
9364 json_object_boolean_true_add(
9365 json_sub,
9366 "txAdvertised");
9367 else if (
9368 CHECK_FLAG(
9369 p->af_cap
9370 [afi]
9371 [safi],
9372 PEER_CAP_ADDPATH_AF_TX_RCV))
9373 json_object_boolean_true_add(
9374 json_sub,
9375 "txReceived");
9376 }
d62a17ae 9377
05c7a1cc
QY
9378 if (CHECK_FLAG(
9379 p->af_cap[afi]
9380 [safi],
9381 PEER_CAP_ADDPATH_AF_RX_ADV)
9382 || CHECK_FLAG(
9383 p->af_cap[afi]
9384 [safi],
9385 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9386 if (CHECK_FLAG(
9387 p->af_cap
9388 [afi]
9389 [safi],
9390 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9391 && CHECK_FLAG(
d62a17ae 9392 p->af_cap
9393 [afi]
9394 [safi],
9395 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9396 json_object_boolean_true_add(
9397 json_sub,
9398 "rxAdvertisedAndReceived");
9399 else if (
9400 CHECK_FLAG(
9401 p->af_cap
9402 [afi]
9403 [safi],
9404 PEER_CAP_ADDPATH_AF_RX_ADV))
9405 json_object_boolean_true_add(
9406 json_sub,
9407 "rxAdvertised");
9408 else if (
9409 CHECK_FLAG(
9410 p->af_cap
9411 [afi]
9412 [safi],
9413 PEER_CAP_ADDPATH_AF_RX_RCV))
9414 json_object_boolean_true_add(
9415 json_sub,
9416 "rxReceived");
d62a17ae 9417 }
9418
05c7a1cc
QY
9419 if (CHECK_FLAG(
9420 p->af_cap[afi]
9421 [safi],
9422 PEER_CAP_ADDPATH_AF_TX_ADV)
9423 || CHECK_FLAG(
9424 p->af_cap[afi]
9425 [safi],
9426 PEER_CAP_ADDPATH_AF_TX_RCV)
9427 || CHECK_FLAG(
9428 p->af_cap[afi]
9429 [safi],
9430 PEER_CAP_ADDPATH_AF_RX_ADV)
9431 || CHECK_FLAG(
9432 p->af_cap[afi]
9433 [safi],
9434 PEER_CAP_ADDPATH_AF_RX_RCV))
9435 json_object_object_add(
9436 json_add,
9437 print_store,
9438 json_sub);
9439 else
9440 json_object_free(
9441 json_sub);
9442 }
9443
d62a17ae 9444 json_object_object_add(
9445 json_cap, "addPath", json_add);
9446 }
9447
9448 /* Dynamic */
9449 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9450 || CHECK_FLAG(p->cap,
9451 PEER_CAP_DYNAMIC_ADV)) {
9452 if (CHECK_FLAG(p->cap,
9453 PEER_CAP_DYNAMIC_ADV)
9454 && CHECK_FLAG(p->cap,
9455 PEER_CAP_DYNAMIC_RCV))
9456 json_object_string_add(
9457 json_cap, "dynamic",
9458 "advertisedAndReceived");
9459 else if (CHECK_FLAG(
9460 p->cap,
9461 PEER_CAP_DYNAMIC_ADV))
9462 json_object_string_add(
9463 json_cap, "dynamic",
9464 "advertised");
9465 else if (CHECK_FLAG(
9466 p->cap,
9467 PEER_CAP_DYNAMIC_RCV))
9468 json_object_string_add(
9469 json_cap, "dynamic",
9470 "received");
9471 }
9472
9473 /* Extended nexthop */
9474 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9475 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9476 json_object *json_nxt = NULL;
9477 const char *print_store;
9478
9479
9480 if (CHECK_FLAG(p->cap,
9481 PEER_CAP_ENHE_ADV)
9482 && CHECK_FLAG(p->cap,
9483 PEER_CAP_ENHE_RCV))
9484 json_object_string_add(
9485 json_cap,
9486 "extendedNexthop",
9487 "advertisedAndReceived");
9488 else if (CHECK_FLAG(p->cap,
9489 PEER_CAP_ENHE_ADV))
9490 json_object_string_add(
9491 json_cap,
9492 "extendedNexthop",
9493 "advertised");
9494 else if (CHECK_FLAG(p->cap,
9495 PEER_CAP_ENHE_RCV))
9496 json_object_string_add(
9497 json_cap,
9498 "extendedNexthop",
9499 "received");
9500
9501 if (CHECK_FLAG(p->cap,
9502 PEER_CAP_ENHE_RCV)) {
9503 json_nxt =
9504 json_object_new_object();
9505
9506 for (safi = SAFI_UNICAST;
9507 safi < SAFI_MAX; safi++) {
9508 if (CHECK_FLAG(
9509 p->af_cap
9510 [AFI_IP]
9511 [safi],
9512 PEER_CAP_ENHE_AF_RCV)) {
9513 print_store = afi_safi_print(
9514 AFI_IP,
9515 safi);
9516 json_object_string_add(
9517 json_nxt,
9518 print_store,
9519 "recieved");
9520 }
9521 }
9522 json_object_object_add(
9523 json_cap,
9524 "extendedNexthopFamililesByPeer",
9525 json_nxt);
9526 }
9527 }
9528
9529 /* Route Refresh */
9530 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9531 || CHECK_FLAG(p->cap,
9532 PEER_CAP_REFRESH_NEW_RCV)
9533 || CHECK_FLAG(p->cap,
9534 PEER_CAP_REFRESH_OLD_RCV)) {
9535 if (CHECK_FLAG(p->cap,
9536 PEER_CAP_REFRESH_ADV)
9537 && (CHECK_FLAG(
9538 p->cap,
9539 PEER_CAP_REFRESH_NEW_RCV)
9540 || CHECK_FLAG(
9541 p->cap,
9542 PEER_CAP_REFRESH_OLD_RCV))) {
9543 if (CHECK_FLAG(
9544 p->cap,
9545 PEER_CAP_REFRESH_OLD_RCV)
9546 && CHECK_FLAG(
9547 p->cap,
9548 PEER_CAP_REFRESH_NEW_RCV))
9549 json_object_string_add(
9550 json_cap,
9551 "routeRefresh",
9552 "advertisedAndReceivedOldNew");
9553 else {
9554 if (CHECK_FLAG(
9555 p->cap,
9556 PEER_CAP_REFRESH_OLD_RCV))
9557 json_object_string_add(
9558 json_cap,
9559 "routeRefresh",
9560 "advertisedAndReceivedOld");
9561 else
9562 json_object_string_add(
9563 json_cap,
9564 "routeRefresh",
9565 "advertisedAndReceivedNew");
9566 }
9567 } else if (
9568 CHECK_FLAG(
9569 p->cap,
9570 PEER_CAP_REFRESH_ADV))
9571 json_object_string_add(
9572 json_cap,
9573 "routeRefresh",
9574 "advertised");
9575 else if (
9576 CHECK_FLAG(
9577 p->cap,
9578 PEER_CAP_REFRESH_NEW_RCV)
9579 || CHECK_FLAG(
9580 p->cap,
9581 PEER_CAP_REFRESH_OLD_RCV))
9582 json_object_string_add(
9583 json_cap,
9584 "routeRefresh",
9585 "received");
9586 }
9587
9588 /* Multiprotocol Extensions */
9589 json_object *json_multi = NULL;
9590 json_multi = json_object_new_object();
9591
05c7a1cc
QY
9592 FOREACH_AFI_SAFI (afi, safi) {
9593 if (p->afc_adv[afi][safi]
9594 || p->afc_recv[afi][safi]) {
9595 json_object *json_exten = NULL;
9596 json_exten =
9597 json_object_new_object();
9598
d62a17ae 9599 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9600 && p->afc_recv[afi][safi])
9601 json_object_boolean_true_add(
9602 json_exten,
9603 "advertisedAndReceived");
9604 else if (p->afc_adv[afi][safi])
9605 json_object_boolean_true_add(
9606 json_exten,
9607 "advertised");
9608 else if (p->afc_recv[afi][safi])
9609 json_object_boolean_true_add(
9610 json_exten,
9611 "received");
d62a17ae 9612
05c7a1cc
QY
9613 json_object_object_add(
9614 json_multi,
9615 afi_safi_print(afi,
9616 safi),
9617 json_exten);
d62a17ae 9618 }
9619 }
9620 json_object_object_add(
9621 json_cap, "multiprotocolExtensions",
9622 json_multi);
9623
d77114b7 9624 /* Hostname capabilities */
60466a63 9625 json_object *json_hname = NULL;
d77114b7
MK
9626
9627 json_hname = json_object_new_object();
9628
9629 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9630 json_object_string_add(
60466a63
QY
9631 json_hname, "advHostName",
9632 bgp->peer_self->hostname
9633 ? bgp->peer_self
9634 ->hostname
d77114b7
MK
9635 : "n/a");
9636 json_object_string_add(
60466a63
QY
9637 json_hname, "advDomainName",
9638 bgp->peer_self->domainname
9639 ? bgp->peer_self
9640 ->domainname
d77114b7
MK
9641 : "n/a");
9642 }
9643
9644
9645 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9646 json_object_string_add(
60466a63
QY
9647 json_hname, "rcvHostName",
9648 p->hostname ? p->hostname
9649 : "n/a");
d77114b7 9650 json_object_string_add(
60466a63
QY
9651 json_hname, "rcvDomainName",
9652 p->domainname ? p->domainname
9653 : "n/a");
d77114b7
MK
9654 }
9655
60466a63 9656 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9657 json_hname);
9658
d62a17ae 9659 /* Gracefull Restart */
9660 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9661 || CHECK_FLAG(p->cap,
9662 PEER_CAP_RESTART_ADV)) {
9663 if (CHECK_FLAG(p->cap,
9664 PEER_CAP_RESTART_ADV)
9665 && CHECK_FLAG(p->cap,
9666 PEER_CAP_RESTART_RCV))
9667 json_object_string_add(
9668 json_cap,
9669 "gracefulRestart",
9670 "advertisedAndReceived");
9671 else if (CHECK_FLAG(
9672 p->cap,
9673 PEER_CAP_RESTART_ADV))
9674 json_object_string_add(
9675 json_cap,
9676 "gracefulRestartCapability",
9677 "advertised");
9678 else if (CHECK_FLAG(
9679 p->cap,
9680 PEER_CAP_RESTART_RCV))
9681 json_object_string_add(
9682 json_cap,
9683 "gracefulRestartCapability",
9684 "received");
9685
9686 if (CHECK_FLAG(p->cap,
9687 PEER_CAP_RESTART_RCV)) {
9688 int restart_af_count = 0;
9689 json_object *json_restart =
9690 NULL;
9691 json_restart =
9692 json_object_new_object();
9693
9694 json_object_int_add(
9695 json_cap,
9696 "gracefulRestartRemoteTimerMsecs",
9697 p->v_gr_restart * 1000);
9698
05c7a1cc
QY
9699 FOREACH_AFI_SAFI (afi, safi) {
9700 if (CHECK_FLAG(
9701 p->af_cap
9702 [afi]
9703 [safi],
9704 PEER_CAP_RESTART_AF_RCV)) {
9705 json_object *
9706 json_sub =
9707 NULL;
9708 json_sub =
9709 json_object_new_object();
9710
d62a17ae 9711 if (CHECK_FLAG(
9712 p->af_cap
9713 [afi]
9714 [safi],
05c7a1cc
QY
9715 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9716 json_object_boolean_true_add(
9717 json_sub,
9718 "preserved");
9719 restart_af_count++;
9720 json_object_object_add(
9721 json_restart,
9722 afi_safi_print(
9723 afi,
9724 safi),
9725 json_sub);
d62a17ae 9726 }
9727 }
9728 if (!restart_af_count) {
9729 json_object_string_add(
9730 json_cap,
9731 "addressFamiliesByPeer",
9732 "none");
9733 json_object_free(
9734 json_restart);
9735 } else
9736 json_object_object_add(
9737 json_cap,
9738 "addressFamiliesByPeer",
9739 json_restart);
9740 }
9741 }
9742 json_object_object_add(json_neigh,
9743 "neighborCapabilities",
9744 json_cap);
9745 } else {
9746 vty_out(vty, " Neighbor capabilities:\n");
9747
9748 /* AS4 */
9749 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9750 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9751 vty_out(vty, " 4 Byte AS:");
9752 if (CHECK_FLAG(p->cap,
9753 PEER_CAP_AS4_ADV))
9754 vty_out(vty, " advertised");
9755 if (CHECK_FLAG(p->cap,
9756 PEER_CAP_AS4_RCV))
9757 vty_out(vty, " %sreceived",
9758 CHECK_FLAG(
9759 p->cap,
9760 PEER_CAP_AS4_ADV)
9761 ? "and "
9762 : "");
9763 vty_out(vty, "\n");
9764 }
9765
9766 /* AddPath */
9767 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9768 || CHECK_FLAG(p->cap,
9769 PEER_CAP_ADDPATH_ADV)) {
9770 vty_out(vty, " AddPath:\n");
9771
05c7a1cc
QY
9772 FOREACH_AFI_SAFI (afi, safi) {
9773 if (CHECK_FLAG(
9774 p->af_cap[afi]
9775 [safi],
9776 PEER_CAP_ADDPATH_AF_TX_ADV)
9777 || CHECK_FLAG(
9778 p->af_cap[afi]
9779 [safi],
9780 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9781 vty_out(vty,
9782 " %s: TX ",
9783 afi_safi_print(
9784 afi,
9785 safi));
9786
d62a17ae 9787 if (CHECK_FLAG(
9788 p->af_cap
9789 [afi]
9790 [safi],
05c7a1cc 9791 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 9792 vty_out(vty,
05c7a1cc 9793 "advertised %s",
d62a17ae 9794 afi_safi_print(
9795 afi,
9796 safi));
9797
05c7a1cc
QY
9798 if (CHECK_FLAG(
9799 p->af_cap
9800 [afi]
9801 [safi],
9802 PEER_CAP_ADDPATH_AF_TX_RCV))
9803 vty_out(vty,
9804 "%sreceived",
9805 CHECK_FLAG(
9806 p->af_cap
9807 [afi]
9808 [safi],
9809 PEER_CAP_ADDPATH_AF_TX_ADV)
9810 ? " and "
9811 : "");
d62a17ae 9812
05c7a1cc
QY
9813 vty_out(vty, "\n");
9814 }
d62a17ae 9815
05c7a1cc
QY
9816 if (CHECK_FLAG(
9817 p->af_cap[afi]
9818 [safi],
9819 PEER_CAP_ADDPATH_AF_RX_ADV)
9820 || CHECK_FLAG(
9821 p->af_cap[afi]
9822 [safi],
9823 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9824 vty_out(vty,
9825 " %s: RX ",
9826 afi_safi_print(
9827 afi,
9828 safi));
d62a17ae 9829
9830 if (CHECK_FLAG(
9831 p->af_cap
9832 [afi]
9833 [safi],
05c7a1cc 9834 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 9835 vty_out(vty,
05c7a1cc 9836 "advertised %s",
d62a17ae 9837 afi_safi_print(
9838 afi,
9839 safi));
9840
05c7a1cc
QY
9841 if (CHECK_FLAG(
9842 p->af_cap
9843 [afi]
9844 [safi],
9845 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 9846 vty_out(vty,
05c7a1cc
QY
9847 "%sreceived",
9848 CHECK_FLAG(
9849 p->af_cap
9850 [afi]
9851 [safi],
9852 PEER_CAP_ADDPATH_AF_RX_ADV)
9853 ? " and "
9854 : "");
9855
9856 vty_out(vty, "\n");
d62a17ae 9857 }
05c7a1cc 9858 }
d62a17ae 9859 }
9860
9861 /* Dynamic */
9862 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9863 || CHECK_FLAG(p->cap,
9864 PEER_CAP_DYNAMIC_ADV)) {
9865 vty_out(vty, " Dynamic:");
9866 if (CHECK_FLAG(p->cap,
9867 PEER_CAP_DYNAMIC_ADV))
9868 vty_out(vty, " advertised");
9869 if (CHECK_FLAG(p->cap,
9870 PEER_CAP_DYNAMIC_RCV))
9871 vty_out(vty, " %sreceived",
9872 CHECK_FLAG(
9873 p->cap,
9874 PEER_CAP_DYNAMIC_ADV)
9875 ? "and "
9876 : "");
9877 vty_out(vty, "\n");
9878 }
9879
9880 /* Extended nexthop */
9881 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9882 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9883 vty_out(vty, " Extended nexthop:");
9884 if (CHECK_FLAG(p->cap,
9885 PEER_CAP_ENHE_ADV))
9886 vty_out(vty, " advertised");
9887 if (CHECK_FLAG(p->cap,
9888 PEER_CAP_ENHE_RCV))
9889 vty_out(vty, " %sreceived",
9890 CHECK_FLAG(
9891 p->cap,
9892 PEER_CAP_ENHE_ADV)
9893 ? "and "
9894 : "");
9895 vty_out(vty, "\n");
9896
9897 if (CHECK_FLAG(p->cap,
9898 PEER_CAP_ENHE_RCV)) {
9899 vty_out(vty,
9900 " Address families by peer:\n ");
9901 for (safi = SAFI_UNICAST;
9902 safi < SAFI_MAX; safi++)
9903 if (CHECK_FLAG(
9904 p->af_cap
9905 [AFI_IP]
9906 [safi],
9907 PEER_CAP_ENHE_AF_RCV))
9908 vty_out(vty,
9909 " %s\n",
9910 afi_safi_print(
9911 AFI_IP,
9912 safi));
9913 }
9914 }
9915
9916 /* Route Refresh */
9917 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9918 || CHECK_FLAG(p->cap,
9919 PEER_CAP_REFRESH_NEW_RCV)
9920 || CHECK_FLAG(p->cap,
9921 PEER_CAP_REFRESH_OLD_RCV)) {
9922 vty_out(vty, " Route refresh:");
9923 if (CHECK_FLAG(p->cap,
9924 PEER_CAP_REFRESH_ADV))
9925 vty_out(vty, " advertised");
9926 if (CHECK_FLAG(p->cap,
9927 PEER_CAP_REFRESH_NEW_RCV)
9928 || CHECK_FLAG(
9929 p->cap,
9930 PEER_CAP_REFRESH_OLD_RCV))
9931 vty_out(vty, " %sreceived(%s)",
9932 CHECK_FLAG(
9933 p->cap,
9934 PEER_CAP_REFRESH_ADV)
9935 ? "and "
9936 : "",
9937 (CHECK_FLAG(
9938 p->cap,
9939 PEER_CAP_REFRESH_OLD_RCV)
9940 && CHECK_FLAG(
9941 p->cap,
9942 PEER_CAP_REFRESH_NEW_RCV))
9943 ? "old & new"
9944 : CHECK_FLAG(
9945 p->cap,
9946 PEER_CAP_REFRESH_OLD_RCV)
9947 ? "old"
9948 : "new");
9949
9950 vty_out(vty, "\n");
9951 }
9952
9953 /* Multiprotocol Extensions */
05c7a1cc
QY
9954 FOREACH_AFI_SAFI (afi, safi)
9955 if (p->afc_adv[afi][safi]
9956 || p->afc_recv[afi][safi]) {
9957 vty_out(vty,
9958 " Address Family %s:",
9959 afi_safi_print(afi,
9960 safi));
9961 if (p->afc_adv[afi][safi])
d62a17ae 9962 vty_out(vty,
05c7a1cc
QY
9963 " advertised");
9964 if (p->afc_recv[afi][safi])
9965 vty_out(vty,
9966 " %sreceived",
9967 p->afc_adv[afi]
9968 [safi]
9969 ? "and "
9970 : "");
9971 vty_out(vty, "\n");
9972 }
d62a17ae 9973
9974 /* Hostname capability */
60466a63 9975 vty_out(vty, " Hostname Capability:");
d77114b7
MK
9976
9977 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
9978 vty_out(vty,
9979 " advertised (name: %s,domain name: %s)",
60466a63
QY
9980 bgp->peer_self->hostname
9981 ? bgp->peer_self
9982 ->hostname
d77114b7 9983 : "n/a",
60466a63
QY
9984 bgp->peer_self->domainname
9985 ? bgp->peer_self
9986 ->domainname
d77114b7
MK
9987 : "n/a");
9988 } else {
9989 vty_out(vty, " not advertised");
d62a17ae 9990 }
9991
d77114b7 9992 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
9993 vty_out(vty,
9994 " received (name: %s,domain name: %s)",
60466a63
QY
9995 p->hostname ? p->hostname
9996 : "n/a",
9997 p->domainname ? p->domainname
9998 : "n/a");
d77114b7
MK
9999 } else {
10000 vty_out(vty, " not received");
10001 }
10002
10003 vty_out(vty, "\n");
10004
d62a17ae 10005 /* Gracefull Restart */
10006 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10007 || CHECK_FLAG(p->cap,
10008 PEER_CAP_RESTART_ADV)) {
10009 vty_out(vty,
10010 " Graceful Restart Capabilty:");
10011 if (CHECK_FLAG(p->cap,
10012 PEER_CAP_RESTART_ADV))
10013 vty_out(vty, " advertised");
10014 if (CHECK_FLAG(p->cap,
10015 PEER_CAP_RESTART_RCV))
10016 vty_out(vty, " %sreceived",
10017 CHECK_FLAG(
10018 p->cap,
10019 PEER_CAP_RESTART_ADV)
10020 ? "and "
10021 : "");
10022 vty_out(vty, "\n");
10023
10024 if (CHECK_FLAG(p->cap,
10025 PEER_CAP_RESTART_RCV)) {
10026 int restart_af_count = 0;
10027
10028 vty_out(vty,
10029 " Remote Restart timer is %d seconds\n",
10030 p->v_gr_restart);
10031 vty_out(vty,
10032 " Address families by peer:\n ");
10033
05c7a1cc
QY
10034 FOREACH_AFI_SAFI (afi, safi)
10035 if (CHECK_FLAG(
10036 p->af_cap
10037 [afi]
10038 [safi],
10039 PEER_CAP_RESTART_AF_RCV)) {
10040 vty_out(vty,
10041 "%s%s(%s)",
10042 restart_af_count
10043 ? ", "
10044 : "",
10045 afi_safi_print(
10046 afi,
10047 safi),
10048 CHECK_FLAG(
10049 p->af_cap
10050 [afi]
10051 [safi],
10052 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10053 ? "preserved"
10054 : "not preserved");
10055 restart_af_count++;
10056 }
d62a17ae 10057 if (!restart_af_count)
10058 vty_out(vty, "none");
10059 vty_out(vty, "\n");
10060 }
10061 }
10062 }
10063 }
10064 }
10065
10066 /* graceful restart information */
10067 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10068 || p->t_gr_stale) {
10069 json_object *json_grace = NULL;
10070 json_object *json_grace_send = NULL;
10071 json_object *json_grace_recv = NULL;
10072 int eor_send_af_count = 0;
10073 int eor_receive_af_count = 0;
10074
10075 if (use_json) {
10076 json_grace = json_object_new_object();
10077 json_grace_send = json_object_new_object();
10078 json_grace_recv = json_object_new_object();
10079
10080 if (p->status == Established) {
05c7a1cc
QY
10081 FOREACH_AFI_SAFI (afi, safi) {
10082 if (CHECK_FLAG(p->af_sflags[afi][safi],
10083 PEER_STATUS_EOR_SEND)) {
10084 json_object_boolean_true_add(
10085 json_grace_send,
10086 afi_safi_print(afi,
10087 safi));
10088 eor_send_af_count++;
d62a17ae 10089 }
10090 }
05c7a1cc
QY
10091 FOREACH_AFI_SAFI (afi, safi) {
10092 if (CHECK_FLAG(
10093 p->af_sflags[afi][safi],
10094 PEER_STATUS_EOR_RECEIVED)) {
10095 json_object_boolean_true_add(
10096 json_grace_recv,
10097 afi_safi_print(afi,
10098 safi));
10099 eor_receive_af_count++;
d62a17ae 10100 }
10101 }
10102 }
10103
10104 json_object_object_add(json_grace, "endOfRibSend",
10105 json_grace_send);
10106 json_object_object_add(json_grace, "endOfRibRecv",
10107 json_grace_recv);
10108
10109 if (p->t_gr_restart)
10110 json_object_int_add(json_grace,
10111 "gracefulRestartTimerMsecs",
10112 thread_timer_remain_second(
10113 p->t_gr_restart)
10114 * 1000);
10115
10116 if (p->t_gr_stale)
10117 json_object_int_add(
10118 json_grace,
10119 "gracefulStalepathTimerMsecs",
10120 thread_timer_remain_second(
10121 p->t_gr_stale)
10122 * 1000);
10123
10124 json_object_object_add(
10125 json_neigh, "gracefulRestartInfo", json_grace);
10126 } else {
10127 vty_out(vty, " Graceful restart informations:\n");
10128 if (p->status == Established) {
10129 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10130 FOREACH_AFI_SAFI (afi, safi) {
10131 if (CHECK_FLAG(p->af_sflags[afi][safi],
10132 PEER_STATUS_EOR_SEND)) {
10133 vty_out(vty, "%s%s",
10134 eor_send_af_count ? ", "
10135 : "",
10136 afi_safi_print(afi,
10137 safi));
10138 eor_send_af_count++;
d62a17ae 10139 }
10140 }
10141 vty_out(vty, "\n");
10142 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10143 FOREACH_AFI_SAFI (afi, safi) {
10144 if (CHECK_FLAG(
10145 p->af_sflags[afi][safi],
10146 PEER_STATUS_EOR_RECEIVED)) {
10147 vty_out(vty, "%s%s",
10148 eor_receive_af_count
10149 ? ", "
10150 : "",
10151 afi_safi_print(afi,
10152 safi));
10153 eor_receive_af_count++;
d62a17ae 10154 }
10155 }
10156 vty_out(vty, "\n");
10157 }
10158
10159 if (p->t_gr_restart)
10160 vty_out(vty,
10161 " The remaining time of restart timer is %ld\n",
10162 thread_timer_remain_second(
10163 p->t_gr_restart));
10164
10165 if (p->t_gr_stale)
10166 vty_out(vty,
10167 " The remaining time of stalepath timer is %ld\n",
10168 thread_timer_remain_second(
10169 p->t_gr_stale));
10170 }
10171 }
10172 if (use_json) {
10173 json_object *json_stat = NULL;
10174 json_stat = json_object_new_object();
10175 /* Packet counts. */
10176 json_object_int_add(json_stat, "depthInq", 0);
10177 json_object_int_add(json_stat, "depthOutq",
10178 (unsigned long)p->obuf->count);
0112e9e0
QY
10179 json_object_int_add(json_stat, "opensSent",
10180 atomic_load_explicit(&p->open_out,
10181 memory_order_relaxed));
10182 json_object_int_add(json_stat, "opensRecv",
10183 atomic_load_explicit(&p->open_in,
10184 memory_order_relaxed));
d62a17ae 10185 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10186 atomic_load_explicit(&p->notify_out,
10187 memory_order_relaxed));
d62a17ae 10188 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10189 atomic_load_explicit(&p->notify_in,
10190 memory_order_relaxed));
10191 json_object_int_add(json_stat, "updatesSent",
10192 atomic_load_explicit(&p->update_out,
10193 memory_order_relaxed));
10194 json_object_int_add(json_stat, "updatesRecv",
10195 atomic_load_explicit(&p->update_in,
10196 memory_order_relaxed));
d62a17ae 10197 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10198 atomic_load_explicit(&p->keepalive_out,
10199 memory_order_relaxed));
d62a17ae 10200 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10201 atomic_load_explicit(&p->keepalive_in,
10202 memory_order_relaxed));
d62a17ae 10203 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10204 atomic_load_explicit(&p->refresh_out,
10205 memory_order_relaxed));
d62a17ae 10206 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10207 atomic_load_explicit(&p->refresh_in,
10208 memory_order_relaxed));
d62a17ae 10209 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10210 atomic_load_explicit(&p->dynamic_cap_out,
10211 memory_order_relaxed));
d62a17ae 10212 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10213 atomic_load_explicit(&p->dynamic_cap_in,
10214 memory_order_relaxed));
10215 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10216 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10217 json_object_object_add(json_neigh, "messageStats", json_stat);
10218 } else {
10219 /* Packet counts. */
10220 vty_out(vty, " Message statistics:\n");
10221 vty_out(vty, " Inq depth is 0\n");
10222 vty_out(vty, " Outq depth is %lu\n",
10223 (unsigned long)p->obuf->count);
10224 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10225 vty_out(vty, " Opens: %10d %10d\n",
10226 atomic_load_explicit(&p->open_out,
10227 memory_order_relaxed),
10228 atomic_load_explicit(&p->open_in,
10229 memory_order_relaxed));
10230 vty_out(vty, " Notifications: %10d %10d\n",
10231 atomic_load_explicit(&p->notify_out,
10232 memory_order_relaxed),
10233 atomic_load_explicit(&p->notify_in,
10234 memory_order_relaxed));
10235 vty_out(vty, " Updates: %10d %10d\n",
10236 atomic_load_explicit(&p->update_out,
10237 memory_order_relaxed),
10238 atomic_load_explicit(&p->update_in,
10239 memory_order_relaxed));
10240 vty_out(vty, " Keepalives: %10d %10d\n",
10241 atomic_load_explicit(&p->keepalive_out,
10242 memory_order_relaxed),
10243 atomic_load_explicit(&p->keepalive_in,
10244 memory_order_relaxed));
10245 vty_out(vty, " Route Refresh: %10d %10d\n",
10246 atomic_load_explicit(&p->refresh_out,
10247 memory_order_relaxed),
10248 atomic_load_explicit(&p->refresh_in,
10249 memory_order_relaxed));
d62a17ae 10250 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10251 atomic_load_explicit(&p->dynamic_cap_out,
10252 memory_order_relaxed),
10253 atomic_load_explicit(&p->dynamic_cap_in,
10254 memory_order_relaxed));
10255 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10256 PEER_TOTAL_RX(p));
d62a17ae 10257 }
10258
10259 if (use_json) {
10260 /* advertisement-interval */
10261 json_object_int_add(json_neigh,
10262 "minBtwnAdvertisementRunsTimerMsecs",
10263 p->v_routeadv * 1000);
10264
10265 /* Update-source. */
10266 if (p->update_if || p->update_source) {
10267 if (p->update_if)
10268 json_object_string_add(json_neigh,
10269 "updateSource",
10270 p->update_if);
10271 else if (p->update_source)
10272 json_object_string_add(
10273 json_neigh, "updateSource",
10274 sockunion2str(p->update_source, buf1,
10275 SU_ADDRSTRLEN));
10276 }
10277 } else {
10278 /* advertisement-interval */
10279 vty_out(vty,
10280 " Minimum time between advertisement runs is %d seconds\n",
10281 p->v_routeadv);
10282
10283 /* Update-source. */
10284 if (p->update_if || p->update_source) {
10285 vty_out(vty, " Update source is ");
10286 if (p->update_if)
10287 vty_out(vty, "%s", p->update_if);
10288 else if (p->update_source)
10289 vty_out(vty, "%s",
10290 sockunion2str(p->update_source, buf1,
10291 SU_ADDRSTRLEN));
10292 vty_out(vty, "\n");
10293 }
10294
10295 vty_out(vty, "\n");
10296 }
10297
10298 /* Address Family Information */
10299 json_object *json_hold = NULL;
10300
10301 if (use_json)
10302 json_hold = json_object_new_object();
10303
05c7a1cc
QY
10304 FOREACH_AFI_SAFI (afi, safi)
10305 if (p->afc[afi][safi])
10306 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10307 json_hold);
d62a17ae 10308
10309 if (use_json) {
10310 json_object_object_add(json_neigh, "addressFamilyInfo",
10311 json_hold);
10312 json_object_int_add(json_neigh, "connectionsEstablished",
10313 p->established);
10314 json_object_int_add(json_neigh, "connectionsDropped",
10315 p->dropped);
10316 } else
10317 vty_out(vty, " Connections established %d; dropped %d\n",
10318 p->established, p->dropped);
10319
10320 if (!p->last_reset) {
10321 if (use_json)
10322 json_object_string_add(json_neigh, "lastReset",
10323 "never");
10324 else
10325 vty_out(vty, " Last reset never\n");
10326 } else {
10327 if (use_json) {
10328 time_t uptime;
10329 struct tm *tm;
10330
10331 uptime = bgp_clock();
10332 uptime -= p->resettime;
10333 tm = gmtime(&uptime);
10334 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10335 (tm->tm_sec * 1000)
10336 + (tm->tm_min * 60000)
10337 + (tm->tm_hour * 3600000));
10338 json_object_string_add(
10339 json_neigh, "lastResetDueTo",
10340 peer_down_str[(int)p->last_reset]);
10341 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10342 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10343 char errorcodesubcode_hexstr[5];
10344 char errorcodesubcode_str[256];
10345
10346 code_str = bgp_notify_code_str(p->notify.code);
10347 subcode_str = bgp_notify_subcode_str(
10348 p->notify.code, p->notify.subcode);
10349
10350 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10351 p->notify.code, p->notify.subcode);
10352 json_object_string_add(json_neigh,
10353 "lastErrorCodeSubcode",
10354 errorcodesubcode_hexstr);
10355 snprintf(errorcodesubcode_str, 255, "%s%s",
10356 code_str, subcode_str);
10357 json_object_string_add(json_neigh,
10358 "lastNotificationReason",
10359 errorcodesubcode_str);
10360 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10361 && p->notify.code == BGP_NOTIFY_CEASE
10362 && (p->notify.subcode
10363 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10364 || p->notify.subcode
10365 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10366 && p->notify.length) {
10367 char msgbuf[1024];
10368 const char *msg_str;
10369
10370 msg_str = bgp_notify_admin_message(
10371 msgbuf, sizeof(msgbuf),
d7c0a89a 10372 (uint8_t *)p->notify.data,
d62a17ae 10373 p->notify.length);
10374 if (msg_str)
10375 json_object_string_add(
10376 json_neigh,
10377 "lastShutdownDescription",
10378 msg_str);
10379 }
10380 }
10381 } else {
10382 vty_out(vty, " Last reset %s, ",
10383 peer_uptime(p->resettime, timebuf,
10384 BGP_UPTIME_LEN, 0, NULL));
10385
10386 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10387 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10388 code_str = bgp_notify_code_str(p->notify.code);
10389 subcode_str = bgp_notify_subcode_str(
10390 p->notify.code, p->notify.subcode);
10391 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10392 p->last_reset == PEER_DOWN_NOTIFY_SEND
10393 ? "sent"
10394 : "received",
10395 code_str, subcode_str);
10396 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10397 && p->notify.code == BGP_NOTIFY_CEASE
10398 && (p->notify.subcode
10399 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10400 || p->notify.subcode
10401 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10402 && p->notify.length) {
10403 char msgbuf[1024];
10404 const char *msg_str;
10405
10406 msg_str = bgp_notify_admin_message(
10407 msgbuf, sizeof(msgbuf),
d7c0a89a 10408 (uint8_t *)p->notify.data,
d62a17ae 10409 p->notify.length);
10410 if (msg_str)
10411 vty_out(vty,
10412 " Message: \"%s\"\n",
10413 msg_str);
10414 }
10415 } else {
10416 vty_out(vty, "due to %s\n",
10417 peer_down_str[(int)p->last_reset]);
10418 }
10419
10420 if (p->last_reset_cause_size) {
10421 msg = p->last_reset_cause;
10422 vty_out(vty,
10423 " Message received that caused BGP to send a NOTIFICATION:\n ");
10424 for (i = 1; i <= p->last_reset_cause_size;
10425 i++) {
10426 vty_out(vty, "%02X", *msg++);
10427
10428 if (i != p->last_reset_cause_size) {
10429 if (i % 16 == 0) {
10430 vty_out(vty, "\n ");
10431 } else if (i % 4 == 0) {
10432 vty_out(vty, " ");
10433 }
10434 }
10435 }
10436 vty_out(vty, "\n");
10437 }
10438 }
10439 }
10440
10441 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10442 if (use_json)
10443 json_object_boolean_true_add(json_neigh,
10444 "prefixesConfigExceedMax");
10445 else
10446 vty_out(vty,
10447 " Peer had exceeded the max. no. of prefixes configured.\n");
10448
10449 if (p->t_pmax_restart) {
10450 if (use_json) {
10451 json_object_boolean_true_add(
10452 json_neigh, "reducePrefixNumFrom");
10453 json_object_int_add(json_neigh,
10454 "restartInTimerMsec",
10455 thread_timer_remain_second(
10456 p->t_pmax_restart)
10457 * 1000);
10458 } else
10459 vty_out(vty,
10460 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10461 p->host, thread_timer_remain_second(
10462 p->t_pmax_restart));
d62a17ae 10463 } else {
10464 if (use_json)
10465 json_object_boolean_true_add(
10466 json_neigh,
10467 "reducePrefixNumAndClearIpBgp");
10468 else
10469 vty_out(vty,
10470 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10471 p->host);
10472 }
10473 }
10474
10475 /* EBGP Multihop and GTSM */
10476 if (p->sort != BGP_PEER_IBGP) {
10477 if (use_json) {
10478 if (p->gtsm_hops > 0)
10479 json_object_int_add(json_neigh,
10480 "externalBgpNbrMaxHopsAway",
10481 p->gtsm_hops);
10482 else if (p->ttl > 1)
10483 json_object_int_add(json_neigh,
10484 "externalBgpNbrMaxHopsAway",
10485 p->ttl);
10486 } else {
10487 if (p->gtsm_hops > 0)
10488 vty_out(vty,
10489 " External BGP neighbor may be up to %d hops away.\n",
10490 p->gtsm_hops);
10491 else if (p->ttl > 1)
10492 vty_out(vty,
10493 " External BGP neighbor may be up to %d hops away.\n",
10494 p->ttl);
10495 }
10496 } else {
10497 if (p->gtsm_hops > 0) {
10498 if (use_json)
10499 json_object_int_add(json_neigh,
10500 "internalBgpNbrMaxHopsAway",
10501 p->gtsm_hops);
10502 else
10503 vty_out(vty,
10504 " Internal BGP neighbor may be up to %d hops away.\n",
10505 p->gtsm_hops);
10506 }
10507 }
10508
10509 /* Local address. */
10510 if (p->su_local) {
10511 if (use_json) {
10512 json_object_string_add(json_neigh, "hostLocal",
10513 sockunion2str(p->su_local, buf1,
10514 SU_ADDRSTRLEN));
10515 json_object_int_add(json_neigh, "portLocal",
10516 ntohs(p->su_local->sin.sin_port));
10517 } else
10518 vty_out(vty, "Local host: %s, Local port: %d\n",
10519 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10520 ntohs(p->su_local->sin.sin_port));
10521 }
10522
10523 /* Remote address. */
10524 if (p->su_remote) {
10525 if (use_json) {
10526 json_object_string_add(json_neigh, "hostForeign",
10527 sockunion2str(p->su_remote, buf1,
10528 SU_ADDRSTRLEN));
10529 json_object_int_add(json_neigh, "portForeign",
10530 ntohs(p->su_remote->sin.sin_port));
10531 } else
10532 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10533 sockunion2str(p->su_remote, buf1,
10534 SU_ADDRSTRLEN),
10535 ntohs(p->su_remote->sin.sin_port));
10536 }
10537
10538 /* Nexthop display. */
10539 if (p->su_local) {
10540 if (use_json) {
10541 json_object_string_add(json_neigh, "nexthop",
10542 inet_ntop(AF_INET,
10543 &p->nexthop.v4, buf1,
10544 sizeof(buf1)));
10545 json_object_string_add(json_neigh, "nexthopGlobal",
10546 inet_ntop(AF_INET6,
10547 &p->nexthop.v6_global,
10548 buf1, sizeof(buf1)));
10549 json_object_string_add(json_neigh, "nexthopLocal",
10550 inet_ntop(AF_INET6,
10551 &p->nexthop.v6_local,
10552 buf1, sizeof(buf1)));
10553 if (p->shared_network)
10554 json_object_string_add(json_neigh,
10555 "bgpConnection",
10556 "sharedNetwork");
10557 else
10558 json_object_string_add(json_neigh,
10559 "bgpConnection",
10560 "nonSharedNetwork");
10561 } else {
10562 vty_out(vty, "Nexthop: %s\n",
10563 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10564 sizeof(buf1)));
10565 vty_out(vty, "Nexthop global: %s\n",
10566 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10567 sizeof(buf1)));
10568 vty_out(vty, "Nexthop local: %s\n",
10569 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10570 sizeof(buf1)));
10571 vty_out(vty, "BGP connection: %s\n",
10572 p->shared_network ? "shared network"
10573 : "non shared network");
10574 }
10575 }
10576
10577 /* Timer information. */
10578 if (use_json) {
10579 json_object_int_add(json_neigh, "connectRetryTimer",
10580 p->v_connect);
10581 if (p->status == Established && p->rtt)
10582 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10583 p->rtt);
10584 if (p->t_start)
10585 json_object_int_add(
10586 json_neigh, "nextStartTimerDueInMsecs",
10587 thread_timer_remain_second(p->t_start) * 1000);
10588 if (p->t_connect)
10589 json_object_int_add(
10590 json_neigh, "nextConnectTimerDueInMsecs",
10591 thread_timer_remain_second(p->t_connect)
10592 * 1000);
10593 if (p->t_routeadv) {
10594 json_object_int_add(json_neigh, "mraiInterval",
10595 p->v_routeadv);
10596 json_object_int_add(
10597 json_neigh, "mraiTimerExpireInMsecs",
10598 thread_timer_remain_second(p->t_routeadv)
10599 * 1000);
10600 }
10601 if (p->password)
10602 json_object_int_add(json_neigh, "authenticationEnabled",
10603 1);
10604
10605 if (p->t_read)
10606 json_object_string_add(json_neigh, "readThread", "on");
10607 else
10608 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10609
10610 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10611 json_object_string_add(json_neigh, "writeThread", "on");
10612 else
10613 json_object_string_add(json_neigh, "writeThread",
10614 "off");
10615 } else {
10616 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10617 p->v_connect);
10618 if (p->status == Established && p->rtt)
10619 vty_out(vty, "Estimated round trip time: %d ms\n",
10620 p->rtt);
10621 if (p->t_start)
10622 vty_out(vty, "Next start timer due in %ld seconds\n",
10623 thread_timer_remain_second(p->t_start));
10624 if (p->t_connect)
10625 vty_out(vty, "Next connect timer due in %ld seconds\n",
10626 thread_timer_remain_second(p->t_connect));
10627 if (p->t_routeadv)
10628 vty_out(vty,
10629 "MRAI (interval %u) timer expires in %ld seconds\n",
10630 p->v_routeadv,
10631 thread_timer_remain_second(p->t_routeadv));
10632 if (p->password)
10633 vty_out(vty, "Peer Authentication Enabled\n");
10634
10635 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10636 p->t_read ? "on" : "off",
10637 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10638 ? "on"
10639 : "off");
d62a17ae 10640 }
10641
10642 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10643 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10644 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10645
10646 if (!use_json)
10647 vty_out(vty, "\n");
10648
10649 /* BFD information. */
10650 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10651
10652 if (use_json) {
10653 if (p->conf_if) /* Configured interface name. */
10654 json_object_object_add(json, p->conf_if, json_neigh);
10655 else /* Configured IP address. */
10656 json_object_object_add(json, p->host, json_neigh);
10657 }
10658}
10659
10660static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10661 enum show_type type, union sockunion *su,
d7c0a89a 10662 const char *conf_if, uint8_t use_json,
d62a17ae 10663 json_object *json)
10664{
10665 struct listnode *node, *nnode;
10666 struct peer *peer;
10667 int find = 0;
10668
10669 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10670 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10671 continue;
10672
10673 switch (type) {
10674 case show_all:
10675 bgp_show_peer(vty, peer, use_json, json);
10676 break;
10677 case show_peer:
10678 if (conf_if) {
10679 if ((peer->conf_if
10680 && !strcmp(peer->conf_if, conf_if))
10681 || (peer->hostname
10682 && !strcmp(peer->hostname, conf_if))) {
10683 find = 1;
10684 bgp_show_peer(vty, peer, use_json,
10685 json);
10686 }
10687 } else {
10688 if (sockunion_same(&peer->su, su)) {
10689 find = 1;
10690 bgp_show_peer(vty, peer, use_json,
10691 json);
10692 }
10693 }
10694 break;
10695 }
10696 }
10697
10698 if (type == show_peer && !find) {
10699 if (use_json)
10700 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10701 else
88b7d255 10702 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 10703 }
10704
10705 if (use_json) {
996c9314
LB
10706 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10707 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10708 json_object_free(json);
10709 } else {
10710 vty_out(vty, "\n");
10711 }
10712
10713 return CMD_SUCCESS;
10714}
10715
10716static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10717 enum show_type type,
10718 const char *ip_str,
d7c0a89a 10719 uint8_t use_json)
d62a17ae 10720{
0291c246
MK
10721 struct listnode *node, *nnode;
10722 struct bgp *bgp;
71aedaa3 10723 union sockunion su;
0291c246 10724 json_object *json = NULL;
71aedaa3 10725 int ret, is_first = 1;
d62a17ae 10726
10727 if (use_json)
10728 vty_out(vty, "{\n");
10729
10730 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10731 if (use_json) {
10732 if (!(json = json_object_new_object())) {
10733 zlog_err(
10734 "Unable to allocate memory for JSON object");
10735 vty_out(vty,
10736 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10737 return;
10738 }
10739
10740 json_object_int_add(json, "vrfId",
10741 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10742 ? -1
10743 : (int64_t)bgp->vrf_id);
d62a17ae 10744 json_object_string_add(
10745 json, "vrfName",
10746 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10747 ? "Default"
10748 : bgp->name);
10749
10750 if (!is_first)
10751 vty_out(vty, ",\n");
10752 else
10753 is_first = 0;
10754
10755 vty_out(vty, "\"%s\":",
10756 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10757 ? "Default"
10758 : bgp->name);
10759 } else {
10760 vty_out(vty, "\nInstance %s:\n",
10761 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10762 ? "Default"
10763 : bgp->name);
10764 }
71aedaa3
DS
10765
10766 if (type == show_peer) {
10767 ret = str2sockunion(ip_str, &su);
10768 if (ret < 0)
10769 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10770 use_json, json);
10771 else
10772 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10773 use_json, json);
10774 } else {
10775 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10776 use_json, json);
10777 }
d62a17ae 10778 }
10779
10780 if (use_json)
10781 vty_out(vty, "}\n");
10782}
10783
10784static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10785 enum show_type type, const char *ip_str,
d7c0a89a 10786 uint8_t use_json)
d62a17ae 10787{
10788 int ret;
10789 struct bgp *bgp;
10790 union sockunion su;
10791 json_object *json = NULL;
10792
10793 if (name) {
10794 if (strmatch(name, "all")) {
71aedaa3
DS
10795 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10796 use_json);
d62a17ae 10797 return CMD_SUCCESS;
10798 } else {
10799 bgp = bgp_lookup_by_name(name);
10800 if (!bgp) {
10801 if (use_json) {
10802 json = json_object_new_object();
10803 json_object_boolean_true_add(
10804 json, "bgpNoSuchInstance");
10805 vty_out(vty, "%s\n",
10806 json_object_to_json_string_ext(
10807 json,
10808 JSON_C_TO_STRING_PRETTY));
10809 json_object_free(json);
10810 } else
10811 vty_out(vty,
10812 "%% No such BGP instance exist\n");
10813
10814 return CMD_WARNING;
10815 }
10816 }
10817 } else {
10818 bgp = bgp_get_default();
10819 }
10820
10821 if (bgp) {
10822 json = json_object_new_object();
10823 if (ip_str) {
10824 ret = str2sockunion(ip_str, &su);
10825 if (ret < 0)
10826 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10827 use_json, json);
10828 else
10829 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10830 use_json, json);
10831 } else {
10832 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10833 json);
10834 }
10835 json_object_free(json);
10836 }
10837
10838 return CMD_SUCCESS;
4fb25c53
DW
10839}
10840
716b2d8a 10841/* "show [ip] bgp neighbors" commands. */
718e3744 10842DEFUN (show_ip_bgp_neighbors,
10843 show_ip_bgp_neighbors_cmd,
24345e82 10844 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 10845 SHOW_STR
10846 IP_STR
10847 BGP_STR
f2a8972b 10848 BGP_INSTANCE_HELP_STR
8c3deaae
QY
10849 "Address Family\n"
10850 "Address Family\n"
718e3744 10851 "Detailed information on TCP and BGP neighbor connections\n"
10852 "Neighbor to display information about\n"
a80beece 10853 "Neighbor to display information about\n"
91d37724 10854 "Neighbor on BGP configured interface\n"
9973d184 10855 JSON_STR)
718e3744 10856{
d62a17ae 10857 char *vrf = NULL;
10858 char *sh_arg = NULL;
10859 enum show_type sh_type;
718e3744 10860
d7c0a89a 10861 uint8_t uj = use_json(argc, argv);
718e3744 10862
d62a17ae 10863 int idx = 0;
718e3744 10864
d62a17ae 10865 if (argv_find(argv, argc, "view", &idx)
10866 || argv_find(argv, argc, "vrf", &idx))
10867 vrf = argv[idx + 1]->arg;
718e3744 10868
d62a17ae 10869 idx++;
10870 if (argv_find(argv, argc, "A.B.C.D", &idx)
10871 || argv_find(argv, argc, "X:X::X:X", &idx)
10872 || argv_find(argv, argc, "WORD", &idx)) {
10873 sh_type = show_peer;
10874 sh_arg = argv[idx]->arg;
10875 } else
10876 sh_type = show_all;
856ca177 10877
d62a17ae 10878 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10879}
10880
716b2d8a 10881/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10882 paths' and `show ip mbgp paths'. Those functions results are the
10883 same.*/
f412b39a 10884DEFUN (show_ip_bgp_paths,
718e3744 10885 show_ip_bgp_paths_cmd,
46f296b4 10886 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10887 SHOW_STR
10888 IP_STR
10889 BGP_STR
46f296b4 10890 BGP_SAFI_HELP_STR
718e3744 10891 "Path information\n")
10892{
d62a17ae 10893 vty_out(vty, "Address Refcnt Path\n");
10894 aspath_print_all_vty(vty);
10895 return CMD_SUCCESS;
718e3744 10896}
10897
718e3744 10898#include "hash.h"
10899
d62a17ae 10900static void community_show_all_iterator(struct hash_backet *backet,
10901 struct vty *vty)
718e3744 10902{
d62a17ae 10903 struct community *com;
718e3744 10904
d62a17ae 10905 com = (struct community *)backet->data;
3f65c5b1 10906 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 10907 community_str(com, false));
718e3744 10908}
10909
10910/* Show BGP's community internal data. */
f412b39a 10911DEFUN (show_ip_bgp_community_info,
718e3744 10912 show_ip_bgp_community_info_cmd,
bec37ba5 10913 "show [ip] bgp community-info",
718e3744 10914 SHOW_STR
10915 IP_STR
10916 BGP_STR
10917 "List all bgp community information\n")
10918{
d62a17ae 10919 vty_out(vty, "Address Refcnt Community\n");
718e3744 10920
d62a17ae 10921 hash_iterate(community_hash(),
10922 (void (*)(struct hash_backet *,
10923 void *))community_show_all_iterator,
10924 vty);
718e3744 10925
d62a17ae 10926 return CMD_SUCCESS;
718e3744 10927}
10928
d62a17ae 10929static void lcommunity_show_all_iterator(struct hash_backet *backet,
10930 struct vty *vty)
57d187bc 10931{
d62a17ae 10932 struct lcommunity *lcom;
57d187bc 10933
d62a17ae 10934 lcom = (struct lcommunity *)backet->data;
3f65c5b1 10935 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 10936 lcommunity_str(lcom, false));
57d187bc
JS
10937}
10938
10939/* Show BGP's community internal data. */
10940DEFUN (show_ip_bgp_lcommunity_info,
10941 show_ip_bgp_lcommunity_info_cmd,
10942 "show ip bgp large-community-info",
10943 SHOW_STR
10944 IP_STR
10945 BGP_STR
10946 "List all bgp large-community information\n")
10947{
d62a17ae 10948 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 10949
d62a17ae 10950 hash_iterate(lcommunity_hash(),
10951 (void (*)(struct hash_backet *,
10952 void *))lcommunity_show_all_iterator,
10953 vty);
57d187bc 10954
d62a17ae 10955 return CMD_SUCCESS;
57d187bc
JS
10956}
10957
10958
f412b39a 10959DEFUN (show_ip_bgp_attr_info,
718e3744 10960 show_ip_bgp_attr_info_cmd,
bec37ba5 10961 "show [ip] bgp attribute-info",
718e3744 10962 SHOW_STR
10963 IP_STR
10964 BGP_STR
10965 "List all bgp attribute information\n")
10966{
d62a17ae 10967 attr_show_all(vty);
10968 return CMD_SUCCESS;
718e3744 10969}
6b0655a2 10970
53089bec 10971static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10972 afi_t afi, safi_t safi)
10973{
10974 struct bgp *bgp;
10975 struct listnode *node;
10976 char *vname;
10977 char buf1[INET6_ADDRSTRLEN];
10978 char *ecom_str;
10979 vpn_policy_direction_t dir;
10980
10981 if (name) {
10982 bgp = bgp_lookup_by_name(name);
10983 if (!bgp) {
10984 vty_out(vty, "%% No such BGP instance exist\n");
10985 return CMD_WARNING;
10986 }
10987 } else {
10988 bgp = bgp_get_default();
10989 if (!bgp) {
020a3f60
DS
10990 vty_out(vty,
10991 "%% Default BGP instance does not exist\n");
53089bec 10992 return CMD_WARNING;
10993 }
10994 }
10995
10996 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10997 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
020a3f60
DS
10998 vty_out(vty,
10999 "This VRF is not importing %s routes from any other VRF\n",
53089bec 11000 afi_safi_print(afi, safi));
11001 } else {
020a3f60
DS
11002 vty_out(vty,
11003 "This VRF is importing %s routes from the following VRFs:\n",
53089bec 11004 afi_safi_print(afi, safi));
11005 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
11006 vname)) {
11007 vty_out(vty, " %s\n", vname);
11008 }
11009 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11010 ecom_str = ecommunity_ecom2str(
11011 bgp->vpn_policy[afi].rtlist[dir],
11012 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11013 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11014 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11015 }
11016
11017 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11018 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
020a3f60
DS
11019 vty_out(vty,
11020 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11021 afi_safi_print(afi, safi));
11022 } else {
020a3f60
DS
11023 vty_out(vty,
11024 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11025 afi_safi_print(afi, safi));
11026 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
11027 vname)) {
11028 vty_out(vty, " %s\n", vname);
11029 }
11030 vty_out(vty, "RD: %s\n",
11031 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11032 buf1, RD_ADDRSTRLEN));
11033 dir = BGP_VPN_POLICY_DIR_TOVPN;
11034 ecom_str = ecommunity_ecom2str(
11035 bgp->vpn_policy[afi].rtlist[dir],
11036 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11037 vty_out(vty, "Emport RT: %s\n", ecom_str);
11038 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11039 }
11040
11041 return CMD_SUCCESS;
11042}
11043
11044/* "show [ip] bgp route-leak" command. */
11045DEFUN (show_ip_bgp_route_leak,
11046 show_ip_bgp_route_leak_cmd,
11047 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
11048 SHOW_STR
11049 IP_STR
11050 BGP_STR
11051 BGP_INSTANCE_HELP_STR
11052 BGP_AFI_HELP_STR
11053 BGP_SAFI_HELP_STR
11054 "Route leaking information\n")
11055{
11056 char *vrf = NULL;
11057 afi_t afi = AFI_MAX;
11058 safi_t safi = SAFI_MAX;
11059
11060 int idx = 0;
11061
11062 /* show [ip] bgp */
11063 if (argv_find(argv, argc, "ip", &idx)) {
11064 afi = AFI_IP;
11065 safi = SAFI_UNICAST;
11066 }
11067 /* [vrf VIEWVRFNAME] */
11068 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11069 vty_out(vty,
11070 "%% This command is not applicable to BGP views\n");
53089bec 11071 return CMD_WARNING;
11072 }
11073
11074 if (argv_find(argv, argc, "vrf", &idx))
11075 vrf = argv[++idx]->arg;
11076 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11077 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11078 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11079 }
11080
11081 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11082 vty_out(vty,
11083 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11084 return CMD_WARNING;
11085 }
11086
11087 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11088}
11089
d62a17ae 11090static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11091 safi_t safi)
f186de26 11092{
d62a17ae 11093 struct listnode *node, *nnode;
11094 struct bgp *bgp;
f186de26 11095
d62a17ae 11096 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11097 vty_out(vty, "\nInstance %s:\n",
11098 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11099 ? "Default"
11100 : bgp->name);
11101 update_group_show(bgp, afi, safi, vty, 0);
11102 }
f186de26 11103}
11104
d62a17ae 11105static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11106 int safi, uint64_t subgrp_id)
4fb25c53 11107{
d62a17ae 11108 struct bgp *bgp;
4fb25c53 11109
d62a17ae 11110 if (name) {
11111 if (strmatch(name, "all")) {
11112 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11113 return CMD_SUCCESS;
11114 } else {
11115 bgp = bgp_lookup_by_name(name);
11116 }
11117 } else {
11118 bgp = bgp_get_default();
11119 }
4fb25c53 11120
d62a17ae 11121 if (bgp)
11122 update_group_show(bgp, afi, safi, vty, subgrp_id);
11123 return CMD_SUCCESS;
4fb25c53
DW
11124}
11125
8fe8a7f6
DS
11126DEFUN (show_ip_bgp_updgrps,
11127 show_ip_bgp_updgrps_cmd,
c1a44e43 11128 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11129 SHOW_STR
11130 IP_STR
11131 BGP_STR
11132 BGP_INSTANCE_HELP_STR
c9e571b4 11133 BGP_AFI_HELP_STR
9bedbb1e 11134 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11135 "Detailed info about dynamic update groups\n"
11136 "Specific subgroup to display detailed info for\n")
8386ac43 11137{
d62a17ae 11138 char *vrf = NULL;
11139 afi_t afi = AFI_IP6;
11140 safi_t safi = SAFI_UNICAST;
11141 uint64_t subgrp_id = 0;
11142
11143 int idx = 0;
11144
11145 /* show [ip] bgp */
11146 if (argv_find(argv, argc, "ip", &idx))
11147 afi = AFI_IP;
11148 /* [<view|vrf> VIEWVRFNAME] */
11149 if (argv_find(argv, argc, "view", &idx)
11150 || argv_find(argv, argc, "vrf", &idx))
11151 vrf = argv[++idx]->arg;
11152 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11153 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11154 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11155 }
5bf15956 11156
d62a17ae 11157 /* get subgroup id, if provided */
11158 idx = argc - 1;
11159 if (argv[idx]->type == VARIABLE_TKN)
11160 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11161
d62a17ae 11162 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11163}
11164
f186de26 11165DEFUN (show_bgp_instance_all_ipv6_updgrps,
11166 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11167 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11168 SHOW_STR
716b2d8a 11169 IP_STR
f186de26 11170 BGP_STR
11171 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11172 "Detailed info about dynamic update groups\n")
f186de26 11173{
d62a17ae 11174 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11175 return CMD_SUCCESS;
f186de26 11176}
11177
5bf15956
DW
11178DEFUN (show_bgp_updgrps_stats,
11179 show_bgp_updgrps_stats_cmd,
716b2d8a 11180 "show [ip] bgp update-groups statistics",
3f9c7369 11181 SHOW_STR
716b2d8a 11182 IP_STR
3f9c7369 11183 BGP_STR
0c7b1b01 11184 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11185 "Statistics\n")
11186{
d62a17ae 11187 struct bgp *bgp;
3f9c7369 11188
d62a17ae 11189 bgp = bgp_get_default();
11190 if (bgp)
11191 update_group_show_stats(bgp, vty);
3f9c7369 11192
d62a17ae 11193 return CMD_SUCCESS;
3f9c7369
DS
11194}
11195
8386ac43 11196DEFUN (show_bgp_instance_updgrps_stats,
11197 show_bgp_instance_updgrps_stats_cmd,
18c57037 11198 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11199 SHOW_STR
716b2d8a 11200 IP_STR
8386ac43 11201 BGP_STR
11202 BGP_INSTANCE_HELP_STR
0c7b1b01 11203 "Detailed info about dynamic update groups\n"
8386ac43 11204 "Statistics\n")
11205{
d62a17ae 11206 int idx_word = 3;
11207 struct bgp *bgp;
8386ac43 11208
d62a17ae 11209 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11210 if (bgp)
11211 update_group_show_stats(bgp, vty);
8386ac43 11212
d62a17ae 11213 return CMD_SUCCESS;
8386ac43 11214}
11215
d62a17ae 11216static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11217 afi_t afi, safi_t safi,
11218 const char *what, uint64_t subgrp_id)
3f9c7369 11219{
d62a17ae 11220 struct bgp *bgp;
8386ac43 11221
d62a17ae 11222 if (name)
11223 bgp = bgp_lookup_by_name(name);
11224 else
11225 bgp = bgp_get_default();
8386ac43 11226
d62a17ae 11227 if (bgp) {
11228 if (!strcmp(what, "advertise-queue"))
11229 update_group_show_adj_queue(bgp, afi, safi, vty,
11230 subgrp_id);
11231 else if (!strcmp(what, "advertised-routes"))
11232 update_group_show_advertised(bgp, afi, safi, vty,
11233 subgrp_id);
11234 else if (!strcmp(what, "packet-queue"))
11235 update_group_show_packet_queue(bgp, afi, safi, vty,
11236 subgrp_id);
11237 }
3f9c7369
DS
11238}
11239
dc64bdec
QY
11240DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11241 show_ip_bgp_instance_updgrps_adj_s_cmd,
11242 "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",
11243 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11244 BGP_SAFI_HELP_STR
11245 "Detailed info about dynamic update groups\n"
11246 "Specific subgroup to display info for\n"
11247 "Advertisement queue\n"
11248 "Announced routes\n"
11249 "Packet queue\n")
3f9c7369 11250{
dc64bdec
QY
11251 uint64_t subgrp_id = 0;
11252 afi_t afiz;
11253 safi_t safiz;
11254 if (sgid)
11255 subgrp_id = strtoull(sgid, NULL, 10);
11256
11257 if (!ip && !afi)
11258 afiz = AFI_IP6;
11259 if (!ip && afi)
11260 afiz = bgp_vty_afi_from_str(afi);
11261 if (ip && !afi)
11262 afiz = AFI_IP;
11263 if (ip && afi) {
11264 afiz = bgp_vty_afi_from_str(afi);
11265 if (afiz != AFI_IP)
11266 vty_out(vty,
11267 "%% Cannot specify both 'ip' and 'ipv6'\n");
11268 return CMD_WARNING;
11269 }
d62a17ae 11270
dc64bdec 11271 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11272
dc64bdec 11273 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11274 return CMD_SUCCESS;
11275}
11276
d62a17ae 11277static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11278{
11279 struct listnode *node, *nnode;
11280 struct prefix *range;
11281 struct peer *conf;
11282 struct peer *peer;
11283 char buf[PREFIX2STR_BUFFER];
11284 afi_t afi;
11285 safi_t safi;
11286 const char *peer_status;
11287 const char *af_str;
11288 int lr_count;
11289 int dynamic;
11290 int af_cfgd;
11291
11292 conf = group->conf;
11293
11294 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11295 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11296 conf->as);
11297 } else if (conf->as_type == AS_INTERNAL) {
11298 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11299 group->bgp->as);
11300 } else {
11301 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11302 }
f14e6fdb 11303
d62a17ae 11304 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11305 vty_out(vty, " Peer-group type is internal\n");
11306 else
11307 vty_out(vty, " Peer-group type is external\n");
11308
11309 /* Display AFs configured. */
11310 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11311 FOREACH_AFI_SAFI (afi, safi) {
11312 if (conf->afc[afi][safi]) {
11313 af_cfgd = 1;
11314 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11315 }
05c7a1cc 11316 }
d62a17ae 11317 if (!af_cfgd)
11318 vty_out(vty, " none\n");
11319 else
11320 vty_out(vty, "\n");
11321
11322 /* Display listen ranges (for dynamic neighbors), if any */
11323 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11324 if (afi == AFI_IP)
11325 af_str = "IPv4";
11326 else if (afi == AFI_IP6)
11327 af_str = "IPv6";
11328 else
11329 af_str = "???";
11330 lr_count = listcount(group->listen_range[afi]);
11331 if (lr_count) {
11332 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11333 af_str);
11334
11335
11336 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11337 nnode, range)) {
11338 prefix2str(range, buf, sizeof(buf));
11339 vty_out(vty, " %s\n", buf);
11340 }
11341 }
11342 }
f14e6fdb 11343
d62a17ae 11344 /* Display group members and their status */
11345 if (listcount(group->peer)) {
11346 vty_out(vty, " Peer-group members:\n");
11347 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11348 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11349 peer_status = "Idle (Admin)";
11350 else if (CHECK_FLAG(peer->sflags,
11351 PEER_STATUS_PREFIX_OVERFLOW))
11352 peer_status = "Idle (PfxCt)";
11353 else
11354 peer_status = lookup_msg(bgp_status_msg,
11355 peer->status, NULL);
11356
11357 dynamic = peer_dynamic_neighbor(peer);
11358 vty_out(vty, " %s %s %s \n", peer->host,
11359 dynamic ? "(dynamic)" : "", peer_status);
11360 }
11361 }
f14e6fdb 11362
d62a17ae 11363 return CMD_SUCCESS;
11364}
11365
ff9959b0
QY
11366static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11367 const char *group_name)
d62a17ae 11368{
ff9959b0 11369 struct bgp *bgp;
d62a17ae 11370 struct listnode *node, *nnode;
11371 struct peer_group *group;
ff9959b0
QY
11372 bool found = false;
11373
11374 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11375
11376 if (!bgp) {
11377 vty_out(vty, "%% No such BGP instance exists\n");
11378 return CMD_WARNING;
11379 }
d62a17ae 11380
11381 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11382 if (group_name) {
11383 if (strmatch(group->name, group_name)) {
d62a17ae 11384 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11385 found = true;
11386 break;
d62a17ae 11387 }
ff9959b0
QY
11388 } else {
11389 bgp_show_one_peer_group(vty, group);
d62a17ae 11390 }
f14e6fdb 11391 }
f14e6fdb 11392
ff9959b0 11393 if (group_name && !found)
d62a17ae 11394 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11395
d62a17ae 11396 return CMD_SUCCESS;
f14e6fdb
DS
11397}
11398
f14e6fdb
DS
11399DEFUN (show_ip_bgp_peer_groups,
11400 show_ip_bgp_peer_groups_cmd,
18c57037 11401 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11402 SHOW_STR
11403 IP_STR
11404 BGP_STR
8386ac43 11405 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11406 "Detailed information on BGP peer groups\n"
11407 "Peer group name\n")
f14e6fdb 11408{
d62a17ae 11409 char *vrf, *pg;
11410 vrf = pg = NULL;
11411 int idx = 0;
f14e6fdb 11412
a4d82a8a
PZ
11413 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11414 : NULL;
d62a17ae 11415 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11416
ff9959b0 11417 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11418}
3f9c7369 11419
d6e3c605 11420
718e3744 11421/* Redistribute VTY commands. */
11422
718e3744 11423DEFUN (bgp_redistribute_ipv4,
11424 bgp_redistribute_ipv4_cmd,
40d1cbfb 11425 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11426 "Redistribute information from another routing protocol\n"
ab0181ee 11427 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11428{
d62a17ae 11429 VTY_DECLVAR_CONTEXT(bgp, bgp);
11430 int idx_protocol = 1;
11431 int type;
718e3744 11432
d62a17ae 11433 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11434 if (type < 0) {
11435 vty_out(vty, "%% Invalid route type\n");
11436 return CMD_WARNING_CONFIG_FAILED;
11437 }
7f323236 11438
d62a17ae 11439 bgp_redist_add(bgp, AFI_IP, type, 0);
11440 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11441}
11442
d62a17ae 11443ALIAS_HIDDEN(
11444 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11445 "redistribute " FRR_IP_REDIST_STR_BGPD,
11446 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11447
718e3744 11448DEFUN (bgp_redistribute_ipv4_rmap,
11449 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11450 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11451 "Redistribute information from another routing protocol\n"
ab0181ee 11452 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11453 "Route map reference\n"
11454 "Pointer to route-map entries\n")
11455{
d62a17ae 11456 VTY_DECLVAR_CONTEXT(bgp, bgp);
11457 int idx_protocol = 1;
11458 int idx_word = 3;
11459 int type;
11460 struct bgp_redist *red;
718e3744 11461
d62a17ae 11462 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11463 if (type < 0) {
11464 vty_out(vty, "%% Invalid route type\n");
11465 return CMD_WARNING_CONFIG_FAILED;
11466 }
718e3744 11467
d62a17ae 11468 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11469 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11470 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11471}
11472
d62a17ae 11473ALIAS_HIDDEN(
11474 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11475 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11476 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11477 "Route map reference\n"
11478 "Pointer to route-map entries\n")
596c17ba 11479
718e3744 11480DEFUN (bgp_redistribute_ipv4_metric,
11481 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11482 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11483 "Redistribute information from another routing protocol\n"
ab0181ee 11484 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11485 "Metric for redistributed routes\n"
11486 "Default metric\n")
11487{
d62a17ae 11488 VTY_DECLVAR_CONTEXT(bgp, bgp);
11489 int idx_protocol = 1;
11490 int idx_number = 3;
11491 int type;
d7c0a89a 11492 uint32_t metric;
d62a17ae 11493 struct bgp_redist *red;
11494
11495 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11496 if (type < 0) {
11497 vty_out(vty, "%% Invalid route type\n");
11498 return CMD_WARNING_CONFIG_FAILED;
11499 }
11500 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11501
11502 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11503 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11504 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11505}
11506
11507ALIAS_HIDDEN(
11508 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11509 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11510 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11511 "Metric for redistributed routes\n"
11512 "Default metric\n")
596c17ba 11513
718e3744 11514DEFUN (bgp_redistribute_ipv4_rmap_metric,
11515 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11516 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11517 "Redistribute information from another routing protocol\n"
ab0181ee 11518 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11519 "Route map reference\n"
11520 "Pointer to route-map entries\n"
11521 "Metric for redistributed routes\n"
11522 "Default metric\n")
11523{
d62a17ae 11524 VTY_DECLVAR_CONTEXT(bgp, bgp);
11525 int idx_protocol = 1;
11526 int idx_word = 3;
11527 int idx_number = 5;
11528 int type;
d7c0a89a 11529 uint32_t metric;
d62a17ae 11530 struct bgp_redist *red;
11531
11532 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11533 if (type < 0) {
11534 vty_out(vty, "%% Invalid route type\n");
11535 return CMD_WARNING_CONFIG_FAILED;
11536 }
11537 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11538
11539 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11540 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11541 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11542 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11543}
11544
11545ALIAS_HIDDEN(
11546 bgp_redistribute_ipv4_rmap_metric,
11547 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11548 "redistribute " FRR_IP_REDIST_STR_BGPD
11549 " route-map WORD metric (0-4294967295)",
11550 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11551 "Route map reference\n"
11552 "Pointer to route-map entries\n"
11553 "Metric for redistributed routes\n"
11554 "Default metric\n")
596c17ba 11555
718e3744 11556DEFUN (bgp_redistribute_ipv4_metric_rmap,
11557 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11558 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11559 "Redistribute information from another routing protocol\n"
ab0181ee 11560 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11561 "Metric for redistributed routes\n"
11562 "Default metric\n"
11563 "Route map reference\n"
11564 "Pointer to route-map entries\n")
11565{
d62a17ae 11566 VTY_DECLVAR_CONTEXT(bgp, bgp);
11567 int idx_protocol = 1;
11568 int idx_number = 3;
11569 int idx_word = 5;
11570 int type;
d7c0a89a 11571 uint32_t metric;
d62a17ae 11572 struct bgp_redist *red;
11573
11574 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11575 if (type < 0) {
11576 vty_out(vty, "%% Invalid route type\n");
11577 return CMD_WARNING_CONFIG_FAILED;
11578 }
11579 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11580
11581 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11582 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11583 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11584 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11585}
11586
11587ALIAS_HIDDEN(
11588 bgp_redistribute_ipv4_metric_rmap,
11589 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11590 "redistribute " FRR_IP_REDIST_STR_BGPD
11591 " metric (0-4294967295) route-map WORD",
11592 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11593 "Metric for redistributed routes\n"
11594 "Default metric\n"
11595 "Route map reference\n"
11596 "Pointer to route-map entries\n")
596c17ba 11597
7c8ff89e
DS
11598DEFUN (bgp_redistribute_ipv4_ospf,
11599 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11600 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11601 "Redistribute information from another routing protocol\n"
11602 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11603 "Non-main Kernel Routing Table\n"
11604 "Instance ID/Table ID\n")
7c8ff89e 11605{
d62a17ae 11606 VTY_DECLVAR_CONTEXT(bgp, bgp);
11607 int idx_ospf_table = 1;
11608 int idx_number = 2;
d7c0a89a
QY
11609 unsigned short instance;
11610 unsigned short protocol;
7c8ff89e 11611
d62a17ae 11612 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11613
d62a17ae 11614 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11615 protocol = ZEBRA_ROUTE_OSPF;
11616 else
11617 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11618
d62a17ae 11619 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11620 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
11621}
11622
d62a17ae 11623ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11624 "redistribute <ospf|table> (1-65535)",
11625 "Redistribute information from another routing protocol\n"
11626 "Open Shortest Path First (OSPFv2)\n"
11627 "Non-main Kernel Routing Table\n"
11628 "Instance ID/Table ID\n")
596c17ba 11629
7c8ff89e
DS
11630DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11631 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11632 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11633 "Redistribute information from another routing protocol\n"
11634 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11635 "Non-main Kernel Routing Table\n"
11636 "Instance ID/Table ID\n"
7c8ff89e
DS
11637 "Route map reference\n"
11638 "Pointer to route-map entries\n")
11639{
d62a17ae 11640 VTY_DECLVAR_CONTEXT(bgp, bgp);
11641 int idx_ospf_table = 1;
11642 int idx_number = 2;
11643 int idx_word = 4;
11644 struct bgp_redist *red;
d7c0a89a 11645 unsigned short instance;
d62a17ae 11646 int protocol;
11647
11648 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11649 protocol = ZEBRA_ROUTE_OSPF;
11650 else
11651 protocol = ZEBRA_ROUTE_TABLE;
11652
11653 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11654 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11655 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11656 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11657}
11658
11659ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11660 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11661 "redistribute <ospf|table> (1-65535) route-map WORD",
11662 "Redistribute information from another routing protocol\n"
11663 "Open Shortest Path First (OSPFv2)\n"
11664 "Non-main Kernel Routing Table\n"
11665 "Instance ID/Table ID\n"
11666 "Route map reference\n"
11667 "Pointer to route-map entries\n")
596c17ba 11668
7c8ff89e
DS
11669DEFUN (bgp_redistribute_ipv4_ospf_metric,
11670 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 11671 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
11672 "Redistribute information from another routing protocol\n"
11673 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11674 "Non-main Kernel Routing Table\n"
11675 "Instance ID/Table ID\n"
7c8ff89e
DS
11676 "Metric for redistributed routes\n"
11677 "Default metric\n")
11678{
d62a17ae 11679 VTY_DECLVAR_CONTEXT(bgp, bgp);
11680 int idx_ospf_table = 1;
11681 int idx_number = 2;
11682 int idx_number_2 = 4;
d7c0a89a 11683 uint32_t metric;
d62a17ae 11684 struct bgp_redist *red;
d7c0a89a 11685 unsigned short instance;
d62a17ae 11686 int protocol;
11687
11688 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11689 protocol = ZEBRA_ROUTE_OSPF;
11690 else
11691 protocol = ZEBRA_ROUTE_TABLE;
11692
11693 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11694 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11695
11696 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11697 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11698 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11699}
11700
11701ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11702 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11703 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11704 "Redistribute information from another routing protocol\n"
11705 "Open Shortest Path First (OSPFv2)\n"
11706 "Non-main Kernel Routing Table\n"
11707 "Instance ID/Table ID\n"
11708 "Metric for redistributed routes\n"
11709 "Default metric\n")
596c17ba 11710
7c8ff89e
DS
11711DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11712 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 11713 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
11714 "Redistribute information from another routing protocol\n"
11715 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11716 "Non-main Kernel Routing Table\n"
11717 "Instance ID/Table ID\n"
7c8ff89e
DS
11718 "Route map reference\n"
11719 "Pointer to route-map entries\n"
11720 "Metric for redistributed routes\n"
11721 "Default metric\n")
11722{
d62a17ae 11723 VTY_DECLVAR_CONTEXT(bgp, bgp);
11724 int idx_ospf_table = 1;
11725 int idx_number = 2;
11726 int idx_word = 4;
11727 int idx_number_2 = 6;
d7c0a89a 11728 uint32_t metric;
d62a17ae 11729 struct bgp_redist *red;
d7c0a89a 11730 unsigned short instance;
d62a17ae 11731 int protocol;
11732
11733 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11734 protocol = ZEBRA_ROUTE_OSPF;
11735 else
11736 protocol = ZEBRA_ROUTE_TABLE;
11737
11738 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11739 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11740
11741 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11742 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11743 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11744 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11745}
11746
11747ALIAS_HIDDEN(
11748 bgp_redistribute_ipv4_ospf_rmap_metric,
11749 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11750 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11751 "Redistribute information from another routing protocol\n"
11752 "Open Shortest Path First (OSPFv2)\n"
11753 "Non-main Kernel Routing Table\n"
11754 "Instance ID/Table ID\n"
11755 "Route map reference\n"
11756 "Pointer to route-map entries\n"
11757 "Metric for redistributed routes\n"
11758 "Default metric\n")
596c17ba 11759
7c8ff89e
DS
11760DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11761 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 11762 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
11763 "Redistribute information from another routing protocol\n"
11764 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11765 "Non-main Kernel Routing Table\n"
11766 "Instance ID/Table ID\n"
7c8ff89e
DS
11767 "Metric for redistributed routes\n"
11768 "Default metric\n"
11769 "Route map reference\n"
11770 "Pointer to route-map entries\n")
11771{
d62a17ae 11772 VTY_DECLVAR_CONTEXT(bgp, bgp);
11773 int idx_ospf_table = 1;
11774 int idx_number = 2;
11775 int idx_number_2 = 4;
11776 int idx_word = 6;
d7c0a89a 11777 uint32_t metric;
d62a17ae 11778 struct bgp_redist *red;
d7c0a89a 11779 unsigned short instance;
d62a17ae 11780 int protocol;
11781
11782 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11783 protocol = ZEBRA_ROUTE_OSPF;
11784 else
11785 protocol = ZEBRA_ROUTE_TABLE;
11786
11787 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11788 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11789
11790 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11791 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11792 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11793 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11794}
11795
11796ALIAS_HIDDEN(
11797 bgp_redistribute_ipv4_ospf_metric_rmap,
11798 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11799 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11800 "Redistribute information from another routing protocol\n"
11801 "Open Shortest Path First (OSPFv2)\n"
11802 "Non-main Kernel Routing Table\n"
11803 "Instance ID/Table ID\n"
11804 "Metric for redistributed routes\n"
11805 "Default metric\n"
11806 "Route map reference\n"
11807 "Pointer to route-map entries\n")
596c17ba 11808
7c8ff89e
DS
11809DEFUN (no_bgp_redistribute_ipv4_ospf,
11810 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 11811 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
11812 NO_STR
11813 "Redistribute information from another routing protocol\n"
11814 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 11815 "Non-main Kernel Routing Table\n"
31500417
DW
11816 "Instance ID/Table ID\n"
11817 "Metric for redistributed routes\n"
11818 "Default metric\n"
11819 "Route map reference\n"
11820 "Pointer to route-map entries\n")
7c8ff89e 11821{
d62a17ae 11822 VTY_DECLVAR_CONTEXT(bgp, bgp);
11823 int idx_ospf_table = 2;
11824 int idx_number = 3;
d7c0a89a 11825 unsigned short instance;
d62a17ae 11826 int protocol;
11827
11828 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11829 protocol = ZEBRA_ROUTE_OSPF;
11830 else
11831 protocol = ZEBRA_ROUTE_TABLE;
11832
11833 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11834 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11835}
11836
11837ALIAS_HIDDEN(
11838 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11839 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11840 NO_STR
11841 "Redistribute information from another routing protocol\n"
11842 "Open Shortest Path First (OSPFv2)\n"
11843 "Non-main Kernel Routing Table\n"
11844 "Instance ID/Table ID\n"
11845 "Metric for redistributed routes\n"
11846 "Default metric\n"
11847 "Route map reference\n"
11848 "Pointer to route-map entries\n")
596c17ba 11849
718e3744 11850DEFUN (no_bgp_redistribute_ipv4,
11851 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 11852 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11853 NO_STR
11854 "Redistribute information from another routing protocol\n"
3b14d86e 11855 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
11856 "Metric for redistributed routes\n"
11857 "Default metric\n"
11858 "Route map reference\n"
11859 "Pointer to route-map entries\n")
718e3744 11860{
d62a17ae 11861 VTY_DECLVAR_CONTEXT(bgp, bgp);
11862 int idx_protocol = 2;
11863 int type;
11864
11865 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11866 if (type < 0) {
11867 vty_out(vty, "%% Invalid route type\n");
11868 return CMD_WARNING_CONFIG_FAILED;
11869 }
11870 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11871}
11872
11873ALIAS_HIDDEN(
11874 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11875 "no redistribute " FRR_IP_REDIST_STR_BGPD
11876 " [metric (0-4294967295)] [route-map WORD]",
11877 NO_STR
11878 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11879 "Metric for redistributed routes\n"
11880 "Default metric\n"
11881 "Route map reference\n"
11882 "Pointer to route-map entries\n")
596c17ba 11883
718e3744 11884DEFUN (bgp_redistribute_ipv6,
11885 bgp_redistribute_ipv6_cmd,
40d1cbfb 11886 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11887 "Redistribute information from another routing protocol\n"
ab0181ee 11888 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11889{
d62a17ae 11890 VTY_DECLVAR_CONTEXT(bgp, bgp);
11891 int idx_protocol = 1;
11892 int type;
718e3744 11893
d62a17ae 11894 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11895 if (type < 0) {
11896 vty_out(vty, "%% Invalid route type\n");
11897 return CMD_WARNING_CONFIG_FAILED;
11898 }
718e3744 11899
d62a17ae 11900 bgp_redist_add(bgp, AFI_IP6, type, 0);
11901 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11902}
11903
11904DEFUN (bgp_redistribute_ipv6_rmap,
11905 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11906 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11907 "Redistribute information from another routing protocol\n"
ab0181ee 11908 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11909 "Route map reference\n"
11910 "Pointer to route-map entries\n")
11911{
d62a17ae 11912 VTY_DECLVAR_CONTEXT(bgp, bgp);
11913 int idx_protocol = 1;
11914 int idx_word = 3;
11915 int type;
11916 struct bgp_redist *red;
718e3744 11917
d62a17ae 11918 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11919 if (type < 0) {
11920 vty_out(vty, "%% Invalid route type\n");
11921 return CMD_WARNING_CONFIG_FAILED;
11922 }
718e3744 11923
d62a17ae 11924 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11925 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11926 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11927}
11928
11929DEFUN (bgp_redistribute_ipv6_metric,
11930 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11931 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11932 "Redistribute information from another routing protocol\n"
ab0181ee 11933 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11934 "Metric for redistributed routes\n"
11935 "Default metric\n")
11936{
d62a17ae 11937 VTY_DECLVAR_CONTEXT(bgp, bgp);
11938 int idx_protocol = 1;
11939 int idx_number = 3;
11940 int type;
d7c0a89a 11941 uint32_t metric;
d62a17ae 11942 struct bgp_redist *red;
11943
11944 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11945 if (type < 0) {
11946 vty_out(vty, "%% Invalid route type\n");
11947 return CMD_WARNING_CONFIG_FAILED;
11948 }
11949 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11950
d62a17ae 11951 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11952 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11953 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11954}
11955
11956DEFUN (bgp_redistribute_ipv6_rmap_metric,
11957 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11958 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11959 "Redistribute information from another routing protocol\n"
ab0181ee 11960 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11961 "Route map reference\n"
11962 "Pointer to route-map entries\n"
11963 "Metric for redistributed routes\n"
11964 "Default metric\n")
11965{
d62a17ae 11966 VTY_DECLVAR_CONTEXT(bgp, bgp);
11967 int idx_protocol = 1;
11968 int idx_word = 3;
11969 int idx_number = 5;
11970 int type;
d7c0a89a 11971 uint32_t metric;
d62a17ae 11972 struct bgp_redist *red;
11973
11974 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11975 if (type < 0) {
11976 vty_out(vty, "%% Invalid route type\n");
11977 return CMD_WARNING_CONFIG_FAILED;
11978 }
11979 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11980
d62a17ae 11981 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11982 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11983 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11984 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11985}
11986
11987DEFUN (bgp_redistribute_ipv6_metric_rmap,
11988 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11989 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11990 "Redistribute information from another routing protocol\n"
ab0181ee 11991 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11992 "Metric for redistributed routes\n"
11993 "Default metric\n"
11994 "Route map reference\n"
11995 "Pointer to route-map entries\n")
11996{
d62a17ae 11997 VTY_DECLVAR_CONTEXT(bgp, bgp);
11998 int idx_protocol = 1;
11999 int idx_number = 3;
12000 int idx_word = 5;
12001 int type;
d7c0a89a 12002 uint32_t metric;
d62a17ae 12003 struct bgp_redist *red;
12004
12005 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12006 if (type < 0) {
12007 vty_out(vty, "%% Invalid route type\n");
12008 return CMD_WARNING_CONFIG_FAILED;
12009 }
12010 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12011
d62a17ae 12012 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12013 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
12014 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12015 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 12016}
12017
12018DEFUN (no_bgp_redistribute_ipv6,
12019 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 12020 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12021 NO_STR
12022 "Redistribute information from another routing protocol\n"
3b14d86e 12023 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12024 "Metric for redistributed routes\n"
12025 "Default metric\n"
12026 "Route map reference\n"
12027 "Pointer to route-map entries\n")
718e3744 12028{
d62a17ae 12029 VTY_DECLVAR_CONTEXT(bgp, bgp);
12030 int idx_protocol = 2;
12031 int type;
718e3744 12032
d62a17ae 12033 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12034 if (type < 0) {
12035 vty_out(vty, "%% Invalid route type\n");
12036 return CMD_WARNING_CONFIG_FAILED;
12037 }
718e3744 12038
d62a17ae 12039 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12040}
12041
2b791107 12042void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12043 safi_t safi)
d62a17ae 12044{
12045 int i;
12046
12047 /* Unicast redistribution only. */
12048 if (safi != SAFI_UNICAST)
2b791107 12049 return;
d62a17ae 12050
12051 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12052 /* Redistribute BGP does not make sense. */
12053 if (i != ZEBRA_ROUTE_BGP) {
12054 struct list *red_list;
12055 struct listnode *node;
12056 struct bgp_redist *red;
12057
12058 red_list = bgp->redist[afi][i];
12059 if (!red_list)
12060 continue;
12061
12062 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12063 /* "redistribute" configuration. */
12064 vty_out(vty, " redistribute %s",
12065 zebra_route_string(i));
12066 if (red->instance)
12067 vty_out(vty, " %d", red->instance);
12068 if (red->redist_metric_flag)
12069 vty_out(vty, " metric %u",
12070 red->redist_metric);
12071 if (red->rmap.name)
12072 vty_out(vty, " route-map %s",
12073 red->rmap.name);
12074 vty_out(vty, "\n");
12075 }
12076 }
12077 }
718e3744 12078}
6b0655a2 12079
b9c7bc5a
PZ
12080/* This is part of the address-family block (unicast only) */
12081void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12082 afi_t afi)
12083{
b9c7bc5a 12084 int indent = 2;
ddb5b488 12085
bb4f6190
DS
12086 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12087 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12088 bgp->vpn_policy[afi]
12089 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12090
12a844a5
DS
12091 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12092 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12093 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12094 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12095 return;
12096
e70e9f8e
PZ
12097 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12098 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12099
12100 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12101
12102 } else {
12103 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12104 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12105 bgp->vpn_policy[afi].tovpn_label);
12106 }
ddb5b488
PZ
12107 }
12108 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12109 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12110 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12111 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12112 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12113 sizeof(buf)));
12114 }
12115 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12116 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12117
12118 char buf[PREFIX_STRLEN];
12119 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12120 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12121 sizeof(buf))) {
12122
b9c7bc5a
PZ
12123 vty_out(vty, "%*snexthop vpn export %s\n",
12124 indent, "", buf);
ddb5b488
PZ
12125 }
12126 }
12127 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12128 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12129 && ecommunity_cmp(
12130 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12131 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12132
12133 char *b = ecommunity_ecom2str(
12134 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12135 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12136 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12137 XFREE(MTYPE_ECOMMUNITY_STR, b);
12138 } else {
12139 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12140 char *b = ecommunity_ecom2str(
12141 bgp->vpn_policy[afi]
12142 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12143 ECOMMUNITY_FORMAT_ROUTE_MAP,
12144 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12145 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12146 XFREE(MTYPE_ECOMMUNITY_STR, b);
12147 }
12148 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12149 char *b = ecommunity_ecom2str(
12150 bgp->vpn_policy[afi]
12151 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12152 ECOMMUNITY_FORMAT_ROUTE_MAP,
12153 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12154 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12155 XFREE(MTYPE_ECOMMUNITY_STR, b);
12156 }
12157 }
bb4f6190
DS
12158
12159 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12160 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12161 bgp->vpn_policy[afi]
12162 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12163
301ad80a
PG
12164 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12165 char *b = ecommunity_ecom2str(
12166 bgp->vpn_policy[afi]
12167 .import_redirect_rtlist,
12168 ECOMMUNITY_FORMAT_ROUTE_MAP,
12169 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12170
301ad80a
PG
12171 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12172 XFREE(MTYPE_ECOMMUNITY_STR, b);
12173 }
ddb5b488
PZ
12174}
12175
12176
718e3744 12177/* BGP node structure. */
d62a17ae 12178static struct cmd_node bgp_node = {
9d303b37 12179 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12180};
12181
d62a17ae 12182static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12183 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12184};
12185
d62a17ae 12186static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12187 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12188};
12189
d62a17ae 12190static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12191 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12192};
12193
d62a17ae 12194static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12195 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12196};
12197
d62a17ae 12198static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12199 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12200};
12201
d62a17ae 12202static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12203 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12204};
12205
d62a17ae 12206static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12207 "%s(config-router-af)# ", 1};
6b0655a2 12208
d62a17ae 12209static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12210 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12211
d62a17ae 12212static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12213 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12214
d62a17ae 12215static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12216 "%s(config-router-af-vni)# ", 1};
90e60aa7 12217
7c40bf39 12218static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12219 "%s(config-router-af)# ", 1};
12220
12221static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12222 "%s(config-router-af-vpnv6)# ", 1};
12223
d62a17ae 12224static void community_list_vty(void);
1f8ae70b 12225
d62a17ae 12226static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12227{
d62a17ae 12228 struct bgp *bgp;
12229 struct peer *peer;
d62a17ae 12230 struct listnode *lnbgp, *lnpeer;
b8a815e5 12231
d62a17ae 12232 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12233 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12234 /* only provide suggestions on the appropriate input
12235 * token type,
12236 * they'll otherwise show up multiple times */
12237 enum cmd_token_type match_type;
12238 char *name = peer->host;
d48ed3e0 12239
d62a17ae 12240 if (peer->conf_if) {
12241 match_type = VARIABLE_TKN;
12242 name = peer->conf_if;
12243 } else if (strchr(peer->host, ':'))
12244 match_type = IPV6_TKN;
12245 else
12246 match_type = IPV4_TKN;
d48ed3e0 12247
d62a17ae 12248 if (token->type != match_type)
12249 continue;
d48ed3e0 12250
d62a17ae 12251 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12252 }
d62a17ae 12253 }
b8a815e5
DL
12254}
12255
12256static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12257 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12258 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12259 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12260 {.completions = NULL}};
12261
47a306a0
DS
12262static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12263{
12264 struct bgp *bgp;
12265 struct peer_group *group;
12266 struct listnode *lnbgp, *lnpeer;
12267
12268 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12269 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12270 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12271 group->name));
12272 }
12273}
12274
12275static const struct cmd_variable_handler bgp_var_peergroup[] = {
12276 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12277 {.completions = NULL} };
12278
d62a17ae 12279void bgp_vty_init(void)
12280{
12281 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12282 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12283
12284 /* Install bgp top node. */
12285 install_node(&bgp_node, bgp_config_write);
12286 install_node(&bgp_ipv4_unicast_node, NULL);
12287 install_node(&bgp_ipv4_multicast_node, NULL);
12288 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12289 install_node(&bgp_ipv6_unicast_node, NULL);
12290 install_node(&bgp_ipv6_multicast_node, NULL);
12291 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12292 install_node(&bgp_vpnv4_node, NULL);
12293 install_node(&bgp_vpnv6_node, NULL);
12294 install_node(&bgp_evpn_node, NULL);
12295 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12296 install_node(&bgp_flowspecv4_node, NULL);
12297 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12298
12299 /* Install default VTY commands to new nodes. */
12300 install_default(BGP_NODE);
12301 install_default(BGP_IPV4_NODE);
12302 install_default(BGP_IPV4M_NODE);
12303 install_default(BGP_IPV4L_NODE);
12304 install_default(BGP_IPV6_NODE);
12305 install_default(BGP_IPV6M_NODE);
12306 install_default(BGP_IPV6L_NODE);
12307 install_default(BGP_VPNV4_NODE);
12308 install_default(BGP_VPNV6_NODE);
7c40bf39 12309 install_default(BGP_FLOWSPECV4_NODE);
12310 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12311 install_default(BGP_EVPN_NODE);
12312 install_default(BGP_EVPN_VNI_NODE);
12313
12314 /* "bgp multiple-instance" commands. */
12315 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12316 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12317
12318 /* "bgp config-type" commands. */
12319 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12320 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12321
12322 /* bgp route-map delay-timer commands. */
12323 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12324 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12325
12326 /* Dummy commands (Currently not supported) */
12327 install_element(BGP_NODE, &no_synchronization_cmd);
12328 install_element(BGP_NODE, &no_auto_summary_cmd);
12329
12330 /* "router bgp" commands. */
12331 install_element(CONFIG_NODE, &router_bgp_cmd);
12332
12333 /* "no router bgp" commands. */
12334 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12335
12336 /* "bgp router-id" commands. */
12337 install_element(BGP_NODE, &bgp_router_id_cmd);
12338 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12339
12340 /* "bgp cluster-id" commands. */
12341 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12342 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12343
12344 /* "bgp confederation" commands. */
12345 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12346 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12347
12348 /* "bgp confederation peers" commands. */
12349 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12350 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12351
12352 /* bgp max-med command */
12353 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12354 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12355 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12356 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12357 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12358
12359 /* bgp disable-ebgp-connected-nh-check */
12360 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12361 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12362
12363 /* bgp update-delay command */
12364 install_element(BGP_NODE, &bgp_update_delay_cmd);
12365 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12366 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12367
12368 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12369 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12370 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12371 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12372
12373 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12374 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12375
12376 /* "maximum-paths" commands. */
12377 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12378 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12379 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12380 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12381 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12382 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12383 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12384 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12385 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12386 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12387 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12388 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12389 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12390 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12391 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12392
12393 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12394 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12395 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12396 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12397 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12398
12399 /* "timers bgp" commands. */
12400 install_element(BGP_NODE, &bgp_timers_cmd);
12401 install_element(BGP_NODE, &no_bgp_timers_cmd);
12402
12403 /* route-map delay-timer commands - per instance for backwards compat.
12404 */
12405 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12406 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12407
12408 /* "bgp client-to-client reflection" commands */
12409 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12410 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12411
12412 /* "bgp always-compare-med" commands */
12413 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12414 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12415
12416 /* "bgp deterministic-med" commands */
12417 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12418 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12419
12420 /* "bgp graceful-restart" commands */
12421 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12422 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12423 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12424 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12425 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12426 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12427
12428 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12429 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12430
7f323236
DW
12431 /* "bgp graceful-shutdown" commands */
12432 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12433 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12434
d62a17ae 12435 /* "bgp fast-external-failover" commands */
12436 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12437 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12438
12439 /* "bgp enforce-first-as" commands */
12440 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12441 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
12442
12443 /* "bgp bestpath compare-routerid" commands */
12444 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12445 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12446
12447 /* "bgp bestpath as-path ignore" commands */
12448 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12449 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12450
12451 /* "bgp bestpath as-path confed" commands */
12452 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12453 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12454
12455 /* "bgp bestpath as-path multipath-relax" commands */
12456 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12457 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12458
12459 /* "bgp log-neighbor-changes" commands */
12460 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12461 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12462
12463 /* "bgp bestpath med" commands */
12464 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12465 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12466
12467 /* "no bgp default ipv4-unicast" commands. */
12468 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12469 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12470
12471 /* "bgp network import-check" commands. */
12472 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12473 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12474 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12475
12476 /* "bgp default local-preference" commands. */
12477 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12478 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12479
12480 /* bgp default show-hostname */
12481 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12482 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12483
12484 /* "bgp default subgroup-pkt-queue-max" commands. */
12485 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12486 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12487
12488 /* bgp ibgp-allow-policy-mods command */
12489 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12490 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12491
12492 /* "bgp listen limit" commands. */
12493 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12494 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12495
12496 /* "bgp listen range" commands. */
12497 install_element(BGP_NODE, &bgp_listen_range_cmd);
12498 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12499
8175f54a 12500 /* "bgp default shutdown" command */
f26845f9
QY
12501 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12502
d62a17ae 12503 /* "neighbor remote-as" commands. */
12504 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12505 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12506 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12507 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12508 install_element(BGP_NODE,
12509 &neighbor_interface_v6only_config_remote_as_cmd);
12510 install_element(BGP_NODE, &no_neighbor_cmd);
12511 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12512
12513 /* "neighbor peer-group" commands. */
12514 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12515 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12516 install_element(BGP_NODE,
12517 &no_neighbor_interface_peer_group_remote_as_cmd);
12518
12519 /* "neighbor local-as" commands. */
12520 install_element(BGP_NODE, &neighbor_local_as_cmd);
12521 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12522 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12523 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12524
12525 /* "neighbor solo" commands. */
12526 install_element(BGP_NODE, &neighbor_solo_cmd);
12527 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12528
12529 /* "neighbor password" commands. */
12530 install_element(BGP_NODE, &neighbor_password_cmd);
12531 install_element(BGP_NODE, &no_neighbor_password_cmd);
12532
12533 /* "neighbor activate" commands. */
12534 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12535 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12536 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12537 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12538 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12539 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12540 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12541 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12542 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 12543 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12544 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 12545 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12546
12547 /* "no neighbor activate" commands. */
12548 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12549 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12550 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12551 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12552 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12553 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12554 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12555 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12556 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 12557 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12558 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 12559 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12560
12561 /* "neighbor peer-group" set commands. */
12562 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12563 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12564 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12565 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12566 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12567 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12568 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12569 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 12570 install_element(BGP_FLOWSPECV4_NODE,
12571 &neighbor_set_peer_group_hidden_cmd);
12572 install_element(BGP_FLOWSPECV6_NODE,
12573 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 12574
12575 /* "no neighbor peer-group unset" commands. */
12576 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12577 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12578 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12579 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12580 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12581 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12582 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12583 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 12584 install_element(BGP_FLOWSPECV4_NODE,
12585 &no_neighbor_set_peer_group_hidden_cmd);
12586 install_element(BGP_FLOWSPECV6_NODE,
12587 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 12588
12589 /* "neighbor softreconfiguration inbound" commands.*/
12590 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12591 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12592 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12593 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12594 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12595 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12596 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12597 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12598 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12599 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12600 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12601 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12602 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12603 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12604 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12605 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12606 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12607 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 12608 install_element(BGP_FLOWSPECV4_NODE,
12609 &neighbor_soft_reconfiguration_cmd);
12610 install_element(BGP_FLOWSPECV4_NODE,
12611 &no_neighbor_soft_reconfiguration_cmd);
12612 install_element(BGP_FLOWSPECV6_NODE,
12613 &neighbor_soft_reconfiguration_cmd);
12614 install_element(BGP_FLOWSPECV6_NODE,
12615 &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 12616
12617 /* "neighbor attribute-unchanged" commands. */
12618 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12619 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12620 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12621 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12622 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12623 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12624 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12625 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12626 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12627 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12628 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12629 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12630 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12631 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12632 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12633 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12634 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12635 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12636
12637 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12638 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12639
12640 /* "nexthop-local unchanged" commands */
12641 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12642 install_element(BGP_IPV6_NODE,
12643 &no_neighbor_nexthop_local_unchanged_cmd);
12644
12645 /* "neighbor next-hop-self" commands. */
12646 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12647 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12648 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12649 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12650 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12651 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12652 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12653 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12654 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12655 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12656 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12657 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12658 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12659 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12660 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12661 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12662 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12663 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
12664 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12665 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 12666
12667 /* "neighbor next-hop-self force" commands. */
12668 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12669 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12670 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12671 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12672 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12673 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12674 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12675 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12676 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12677 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12678 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12679 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12680 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12681 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12682 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12683 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12684 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12685 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12686
12687 /* "neighbor as-override" commands. */
12688 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12689 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12690 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12691 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12692 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12693 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12694 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12695 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12696 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12697 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12698 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12699 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12700 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12701 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12702 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12703 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12704 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12705 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12706
12707 /* "neighbor remove-private-AS" commands. */
12708 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12709 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12710 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12711 install_element(BGP_NODE,
12712 &no_neighbor_remove_private_as_all_hidden_cmd);
12713 install_element(BGP_NODE,
12714 &neighbor_remove_private_as_replace_as_hidden_cmd);
12715 install_element(BGP_NODE,
12716 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12717 install_element(BGP_NODE,
12718 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12719 install_element(
12720 BGP_NODE,
12721 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12722 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12723 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12724 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12725 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12726 install_element(BGP_IPV4_NODE,
12727 &neighbor_remove_private_as_replace_as_cmd);
12728 install_element(BGP_IPV4_NODE,
12729 &no_neighbor_remove_private_as_replace_as_cmd);
12730 install_element(BGP_IPV4_NODE,
12731 &neighbor_remove_private_as_all_replace_as_cmd);
12732 install_element(BGP_IPV4_NODE,
12733 &no_neighbor_remove_private_as_all_replace_as_cmd);
12734 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12735 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12736 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12737 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12738 install_element(BGP_IPV4M_NODE,
12739 &neighbor_remove_private_as_replace_as_cmd);
12740 install_element(BGP_IPV4M_NODE,
12741 &no_neighbor_remove_private_as_replace_as_cmd);
12742 install_element(BGP_IPV4M_NODE,
12743 &neighbor_remove_private_as_all_replace_as_cmd);
12744 install_element(BGP_IPV4M_NODE,
12745 &no_neighbor_remove_private_as_all_replace_as_cmd);
12746 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12747 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12748 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12749 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12750 install_element(BGP_IPV4L_NODE,
12751 &neighbor_remove_private_as_replace_as_cmd);
12752 install_element(BGP_IPV4L_NODE,
12753 &no_neighbor_remove_private_as_replace_as_cmd);
12754 install_element(BGP_IPV4L_NODE,
12755 &neighbor_remove_private_as_all_replace_as_cmd);
12756 install_element(BGP_IPV4L_NODE,
12757 &no_neighbor_remove_private_as_all_replace_as_cmd);
12758 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12759 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12760 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12761 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12762 install_element(BGP_IPV6_NODE,
12763 &neighbor_remove_private_as_replace_as_cmd);
12764 install_element(BGP_IPV6_NODE,
12765 &no_neighbor_remove_private_as_replace_as_cmd);
12766 install_element(BGP_IPV6_NODE,
12767 &neighbor_remove_private_as_all_replace_as_cmd);
12768 install_element(BGP_IPV6_NODE,
12769 &no_neighbor_remove_private_as_all_replace_as_cmd);
12770 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12771 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12772 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12773 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12774 install_element(BGP_IPV6M_NODE,
12775 &neighbor_remove_private_as_replace_as_cmd);
12776 install_element(BGP_IPV6M_NODE,
12777 &no_neighbor_remove_private_as_replace_as_cmd);
12778 install_element(BGP_IPV6M_NODE,
12779 &neighbor_remove_private_as_all_replace_as_cmd);
12780 install_element(BGP_IPV6M_NODE,
12781 &no_neighbor_remove_private_as_all_replace_as_cmd);
12782 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12783 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12784 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12785 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12786 install_element(BGP_IPV6L_NODE,
12787 &neighbor_remove_private_as_replace_as_cmd);
12788 install_element(BGP_IPV6L_NODE,
12789 &no_neighbor_remove_private_as_replace_as_cmd);
12790 install_element(BGP_IPV6L_NODE,
12791 &neighbor_remove_private_as_all_replace_as_cmd);
12792 install_element(BGP_IPV6L_NODE,
12793 &no_neighbor_remove_private_as_all_replace_as_cmd);
12794 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12795 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12796 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12797 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12798 install_element(BGP_VPNV4_NODE,
12799 &neighbor_remove_private_as_replace_as_cmd);
12800 install_element(BGP_VPNV4_NODE,
12801 &no_neighbor_remove_private_as_replace_as_cmd);
12802 install_element(BGP_VPNV4_NODE,
12803 &neighbor_remove_private_as_all_replace_as_cmd);
12804 install_element(BGP_VPNV4_NODE,
12805 &no_neighbor_remove_private_as_all_replace_as_cmd);
12806 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12807 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12808 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12809 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12810 install_element(BGP_VPNV6_NODE,
12811 &neighbor_remove_private_as_replace_as_cmd);
12812 install_element(BGP_VPNV6_NODE,
12813 &no_neighbor_remove_private_as_replace_as_cmd);
12814 install_element(BGP_VPNV6_NODE,
12815 &neighbor_remove_private_as_all_replace_as_cmd);
12816 install_element(BGP_VPNV6_NODE,
12817 &no_neighbor_remove_private_as_all_replace_as_cmd);
12818
12819 /* "neighbor send-community" commands.*/
12820 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12821 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12822 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12823 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12824 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12825 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12826 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12827 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12828 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12829 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12830 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12831 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12832 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12833 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12834 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12835 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12836 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12837 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12838 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12839 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12840 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12841 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12842 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12843 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12844 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12845 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12846 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12847 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12848 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12849 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12850 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12851 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12852 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12853 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12854 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12855 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12856
12857 /* "neighbor route-reflector" commands.*/
12858 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12859 install_element(BGP_NODE,
12860 &no_neighbor_route_reflector_client_hidden_cmd);
12861 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12862 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12863 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12864 install_element(BGP_IPV4M_NODE,
12865 &no_neighbor_route_reflector_client_cmd);
12866 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12867 install_element(BGP_IPV4L_NODE,
12868 &no_neighbor_route_reflector_client_cmd);
12869 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12870 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12871 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12872 install_element(BGP_IPV6M_NODE,
12873 &no_neighbor_route_reflector_client_cmd);
12874 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12875 install_element(BGP_IPV6L_NODE,
12876 &no_neighbor_route_reflector_client_cmd);
12877 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12878 install_element(BGP_VPNV4_NODE,
12879 &no_neighbor_route_reflector_client_cmd);
12880 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12881 install_element(BGP_VPNV6_NODE,
12882 &no_neighbor_route_reflector_client_cmd);
7c40bf39 12883 install_element(BGP_FLOWSPECV4_NODE,
12884 &neighbor_route_reflector_client_cmd);
12885 install_element(BGP_FLOWSPECV4_NODE,
12886 &no_neighbor_route_reflector_client_cmd);
12887 install_element(BGP_FLOWSPECV6_NODE,
12888 &neighbor_route_reflector_client_cmd);
12889 install_element(BGP_FLOWSPECV6_NODE,
12890 &no_neighbor_route_reflector_client_cmd);
d62a17ae 12891 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12892 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12893
12894 /* "neighbor route-server" commands.*/
12895 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12896 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12897 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12898 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12899 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12900 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12901 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12902 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12903 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12904 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12905 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12906 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12907 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12908 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12909 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12910 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12911 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12912 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 12913 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12914 install_element(BGP_FLOWSPECV4_NODE,
12915 &no_neighbor_route_server_client_cmd);
12916 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12917 install_element(BGP_FLOWSPECV6_NODE,
12918 &no_neighbor_route_server_client_cmd);
d62a17ae 12919
12920 /* "neighbor addpath-tx-all-paths" commands.*/
12921 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12922 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12923 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12924 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12925 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12926 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12927 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12928 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12929 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12930 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12931 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12932 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12933 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12934 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12935 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12936 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12937 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12938 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12939
12940 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12941 install_element(BGP_NODE,
12942 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12943 install_element(BGP_NODE,
12944 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12945 install_element(BGP_IPV4_NODE,
12946 &neighbor_addpath_tx_bestpath_per_as_cmd);
12947 install_element(BGP_IPV4_NODE,
12948 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12949 install_element(BGP_IPV4M_NODE,
12950 &neighbor_addpath_tx_bestpath_per_as_cmd);
12951 install_element(BGP_IPV4M_NODE,
12952 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12953 install_element(BGP_IPV4L_NODE,
12954 &neighbor_addpath_tx_bestpath_per_as_cmd);
12955 install_element(BGP_IPV4L_NODE,
12956 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12957 install_element(BGP_IPV6_NODE,
12958 &neighbor_addpath_tx_bestpath_per_as_cmd);
12959 install_element(BGP_IPV6_NODE,
12960 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12961 install_element(BGP_IPV6M_NODE,
12962 &neighbor_addpath_tx_bestpath_per_as_cmd);
12963 install_element(BGP_IPV6M_NODE,
12964 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12965 install_element(BGP_IPV6L_NODE,
12966 &neighbor_addpath_tx_bestpath_per_as_cmd);
12967 install_element(BGP_IPV6L_NODE,
12968 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12969 install_element(BGP_VPNV4_NODE,
12970 &neighbor_addpath_tx_bestpath_per_as_cmd);
12971 install_element(BGP_VPNV4_NODE,
12972 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12973 install_element(BGP_VPNV6_NODE,
12974 &neighbor_addpath_tx_bestpath_per_as_cmd);
12975 install_element(BGP_VPNV6_NODE,
12976 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12977
12978 /* "neighbor passive" commands. */
12979 install_element(BGP_NODE, &neighbor_passive_cmd);
12980 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12981
12982
12983 /* "neighbor shutdown" commands. */
12984 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12985 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12986 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12987 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12988
12989 /* "neighbor capability extended-nexthop" commands.*/
12990 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12991 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12992
12993 /* "neighbor capability orf prefix-list" commands.*/
12994 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12995 install_element(BGP_NODE,
12996 &no_neighbor_capability_orf_prefix_hidden_cmd);
12997 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12998 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12999 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13000 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13001 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13002 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13003 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13004 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13005 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13006 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13007 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13008 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13009
13010 /* "neighbor capability dynamic" commands.*/
13011 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13012 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13013
13014 /* "neighbor dont-capability-negotiate" commands. */
13015 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13016 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13017
13018 /* "neighbor ebgp-multihop" commands. */
13019 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13020 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13021 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13022
13023 /* "neighbor disable-connected-check" commands. */
13024 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13025 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13026
47cbc09b
PM
13027 /* "neighbor enforce-first-as" commands. */
13028 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13029 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13030
d62a17ae 13031 /* "neighbor description" commands. */
13032 install_element(BGP_NODE, &neighbor_description_cmd);
13033 install_element(BGP_NODE, &no_neighbor_description_cmd);
13034
13035 /* "neighbor update-source" commands. "*/
13036 install_element(BGP_NODE, &neighbor_update_source_cmd);
13037 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13038
13039 /* "neighbor default-originate" commands. */
13040 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13041 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13042 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13043 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13044 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13045 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13046 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13047 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13048 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13049 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13050 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13051 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13052 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13053 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13054 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13055 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13056 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13057 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13058 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13059 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13060 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13061
13062 /* "neighbor port" commands. */
13063 install_element(BGP_NODE, &neighbor_port_cmd);
13064 install_element(BGP_NODE, &no_neighbor_port_cmd);
13065
13066 /* "neighbor weight" commands. */
13067 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13068 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13069
13070 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13071 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13072 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13073 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13074 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13075 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13076 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13077 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13078 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13079 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13080 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13081 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13082 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13083 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13084 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13085 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13086
13087 /* "neighbor override-capability" commands. */
13088 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13089 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13090
13091 /* "neighbor strict-capability-match" commands. */
13092 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13093 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13094
13095 /* "neighbor timers" commands. */
13096 install_element(BGP_NODE, &neighbor_timers_cmd);
13097 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13098
13099 /* "neighbor timers connect" commands. */
13100 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13101 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13102
13103 /* "neighbor advertisement-interval" commands. */
13104 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13105 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13106
13107 /* "neighbor interface" commands. */
13108 install_element(BGP_NODE, &neighbor_interface_cmd);
13109 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13110
13111 /* "neighbor distribute" commands. */
13112 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13113 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13114 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13115 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13116 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13117 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13118 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13119 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13120 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13121 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13122 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13123 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13124 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13125 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13126 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13127 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13128 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13129 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13130
13131 /* "neighbor prefix-list" commands. */
13132 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13133 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13134 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13135 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13136 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13137 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13138 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13139 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13140 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13141 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13142 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13143 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13144 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13145 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13146 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13147 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13148 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13149 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13150 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13151 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13152 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13153 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13154
13155 /* "neighbor filter-list" commands. */
13156 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13157 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13158 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13159 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13160 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13161 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13162 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13163 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13164 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13165 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13166 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13167 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13168 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13169 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13170 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13171 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13172 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13173 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13174 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13175 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13176 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13177 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13178
13179 /* "neighbor route-map" commands. */
13180 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13181 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13182 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13183 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13184 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13185 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13186 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13187 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13188 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13189 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13190 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13191 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13192 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13193 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13194 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13195 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13196 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13197 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13198 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13199 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13200 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13201 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13202 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13203 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13204
13205 /* "neighbor unsuppress-map" commands. */
13206 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13207 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13208 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13209 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13210 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13211 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13212 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13213 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13214 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13215 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13216 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13217 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13218 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13219 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13220 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13221 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13222 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13223 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13224
13225 /* "neighbor maximum-prefix" commands. */
13226 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13227 install_element(BGP_NODE,
13228 &neighbor_maximum_prefix_threshold_hidden_cmd);
13229 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13230 install_element(BGP_NODE,
13231 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13232 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13233 install_element(BGP_NODE,
13234 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13235 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13236 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13237 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13238 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13239 install_element(BGP_IPV4_NODE,
13240 &neighbor_maximum_prefix_threshold_warning_cmd);
13241 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13242 install_element(BGP_IPV4_NODE,
13243 &neighbor_maximum_prefix_threshold_restart_cmd);
13244 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13245 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13246 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13247 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13248 install_element(BGP_IPV4M_NODE,
13249 &neighbor_maximum_prefix_threshold_warning_cmd);
13250 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13251 install_element(BGP_IPV4M_NODE,
13252 &neighbor_maximum_prefix_threshold_restart_cmd);
13253 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13254 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13255 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13256 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13257 install_element(BGP_IPV4L_NODE,
13258 &neighbor_maximum_prefix_threshold_warning_cmd);
13259 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13260 install_element(BGP_IPV4L_NODE,
13261 &neighbor_maximum_prefix_threshold_restart_cmd);
13262 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13263 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13264 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13265 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13266 install_element(BGP_IPV6_NODE,
13267 &neighbor_maximum_prefix_threshold_warning_cmd);
13268 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13269 install_element(BGP_IPV6_NODE,
13270 &neighbor_maximum_prefix_threshold_restart_cmd);
13271 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13272 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13273 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13274 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13275 install_element(BGP_IPV6M_NODE,
13276 &neighbor_maximum_prefix_threshold_warning_cmd);
13277 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13278 install_element(BGP_IPV6M_NODE,
13279 &neighbor_maximum_prefix_threshold_restart_cmd);
13280 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13281 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13282 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13283 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13284 install_element(BGP_IPV6L_NODE,
13285 &neighbor_maximum_prefix_threshold_warning_cmd);
13286 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13287 install_element(BGP_IPV6L_NODE,
13288 &neighbor_maximum_prefix_threshold_restart_cmd);
13289 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13290 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13291 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13292 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13293 install_element(BGP_VPNV4_NODE,
13294 &neighbor_maximum_prefix_threshold_warning_cmd);
13295 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13296 install_element(BGP_VPNV4_NODE,
13297 &neighbor_maximum_prefix_threshold_restart_cmd);
13298 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13299 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13300 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13301 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13302 install_element(BGP_VPNV6_NODE,
13303 &neighbor_maximum_prefix_threshold_warning_cmd);
13304 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13305 install_element(BGP_VPNV6_NODE,
13306 &neighbor_maximum_prefix_threshold_restart_cmd);
13307 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13308
13309 /* "neighbor allowas-in" */
13310 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13311 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13312 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13313 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13314 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13315 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13316 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13317 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13318 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13319 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13320 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13321 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13322 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13323 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13324 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13325 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13326 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13327 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13328 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13329 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13330
13331 /* address-family commands. */
13332 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13333 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13334#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13335 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13336 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13337#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13338
d62a17ae 13339 install_element(BGP_NODE, &address_family_evpn_cmd);
13340
13341 /* "exit-address-family" command. */
13342 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13343 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13344 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13345 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13346 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13347 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13348 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13349 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13350 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13351 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13352 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13353
13354 /* "clear ip bgp commands" */
13355 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13356
13357 /* clear ip bgp prefix */
13358 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13359 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13360 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13361
13362 /* "show [ip] bgp summary" commands. */
13363 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
d62a17ae 13364 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13365 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13366 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13367 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13368 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13369
13370 /* "show [ip] bgp neighbors" commands. */
13371 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13372
13373 /* "show [ip] bgp peer-group" commands. */
13374 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13375
13376 /* "show [ip] bgp paths" commands. */
13377 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13378
13379 /* "show [ip] bgp community" commands. */
13380 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13381
13382 /* "show ip bgp large-community" commands. */
13383 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13384 /* "show [ip] bgp attribute-info" commands. */
13385 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13386 /* "show [ip] bgp route-leak" command */
13387 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13388
13389 /* "redistribute" commands. */
13390 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13391 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13392 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13393 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13394 install_element(BGP_NODE,
13395 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13396 install_element(BGP_NODE,
13397 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13398 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13399 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13400 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13401 install_element(BGP_NODE,
13402 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13403 install_element(BGP_NODE,
13404 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13405 install_element(BGP_NODE,
13406 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13407 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13408 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13409 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13410 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13411 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13412 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13413 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13414 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13415 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13416 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13417 install_element(BGP_IPV4_NODE,
13418 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13419 install_element(BGP_IPV4_NODE,
13420 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13421 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13422 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13423 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13424 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13425 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13426 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13427
b9c7bc5a
PZ
13428 /* import|export vpn [route-map WORD] */
13429 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13430 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13431
12a844a5
DS
13432 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13433 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13434
d62a17ae 13435 /* ttl_security commands */
13436 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13437 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13438
13439 /* "show [ip] bgp memory" commands. */
13440 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13441
acf71666
MK
13442 /* "show bgp martian next-hop" */
13443 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13444
d62a17ae 13445 /* "show [ip] bgp views" commands. */
13446 install_element(VIEW_NODE, &show_bgp_views_cmd);
13447
13448 /* "show [ip] bgp vrfs" commands. */
13449 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13450
13451 /* Community-list. */
13452 community_list_vty();
ddb5b488
PZ
13453
13454 /* vpn-policy commands */
b9c7bc5a
PZ
13455 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13456 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13457 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13458 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13459 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13460 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13461 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13462 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13463 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13464 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
13465 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13466 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 13467
301ad80a
PG
13468 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13469 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13470
b9c7bc5a
PZ
13471 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13472 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13473 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13474 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13475 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13476 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13477 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13478 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13479 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13480 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
13481 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13482 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 13483}
6b0655a2 13484
718e3744 13485#include "memory.h"
13486#include "bgp_regex.h"
13487#include "bgp_clist.h"
13488#include "bgp_ecommunity.h"
13489
13490/* VTY functions. */
13491
13492/* Direction value to string conversion. */
d62a17ae 13493static const char *community_direct_str(int direct)
13494{
13495 switch (direct) {
13496 case COMMUNITY_DENY:
13497 return "deny";
13498 case COMMUNITY_PERMIT:
13499 return "permit";
13500 default:
13501 return "unknown";
13502 }
718e3744 13503}
13504
13505/* Display error string. */
d62a17ae 13506static void community_list_perror(struct vty *vty, int ret)
13507{
13508 switch (ret) {
13509 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13510 vty_out(vty, "%% Can't find community-list\n");
13511 break;
13512 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13513 vty_out(vty, "%% Malformed community-list value\n");
13514 break;
13515 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13516 vty_out(vty,
13517 "%% Community name conflict, previously defined as standard community\n");
13518 break;
13519 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13520 vty_out(vty,
13521 "%% Community name conflict, previously defined as expanded community\n");
13522 break;
13523 }
718e3744 13524}
13525
5bf15956
DW
13526/* "community-list" keyword help string. */
13527#define COMMUNITY_LIST_STR "Add a community list entry\n"
13528
5bf15956 13529/* ip community-list standard */
718e3744 13530DEFUN (ip_community_list_standard,
13531 ip_community_list_standard_cmd,
e961923c 13532 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13533 IP_STR
13534 COMMUNITY_LIST_STR
13535 "Community list number (standard)\n"
5bf15956 13536 "Add an standard community-list entry\n"
718e3744 13537 "Community list name\n"
13538 "Specify community to reject\n"
13539 "Specify community to accept\n"
13540 COMMUNITY_VAL_STR)
13541{
d62a17ae 13542 char *cl_name_or_number = NULL;
13543 int direct = 0;
13544 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13545
d62a17ae 13546 int idx = 0;
13547 argv_find(argv, argc, "(1-99)", &idx);
13548 argv_find(argv, argc, "WORD", &idx);
13549 cl_name_or_number = argv[idx]->arg;
13550 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13551 : COMMUNITY_DENY;
13552 argv_find(argv, argc, "AA:NN", &idx);
13553 char *str = argv_concat(argv, argc, idx);
42f914d4 13554
d62a17ae 13555 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13556 style);
42f914d4 13557
d62a17ae 13558 XFREE(MTYPE_TMP, str);
42f914d4 13559
d62a17ae 13560 if (ret < 0) {
13561 /* Display error string. */
13562 community_list_perror(vty, ret);
13563 return CMD_WARNING_CONFIG_FAILED;
13564 }
42f914d4 13565
d62a17ae 13566 return CMD_SUCCESS;
718e3744 13567}
13568
fee6e4e4 13569DEFUN (no_ip_community_list_standard_all,
13570 no_ip_community_list_standard_all_cmd,
e961923c 13571 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13572 NO_STR
13573 IP_STR
13574 COMMUNITY_LIST_STR
13575 "Community list number (standard)\n"
5bf15956
DW
13576 "Add an standard community-list entry\n"
13577 "Community list name\n"
718e3744 13578 "Specify community to reject\n"
13579 "Specify community to accept\n"
13580 COMMUNITY_VAL_STR)
13581{
d62a17ae 13582 char *cl_name_or_number = NULL;
13583 int direct = 0;
13584 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13585
d62a17ae 13586 int idx = 0;
13587 argv_find(argv, argc, "(1-99)", &idx);
13588 argv_find(argv, argc, "WORD", &idx);
13589 cl_name_or_number = argv[idx]->arg;
13590 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13591 : COMMUNITY_DENY;
13592 argv_find(argv, argc, "AA:NN", &idx);
13593 char *str = argv_concat(argv, argc, idx);
42f914d4 13594
d62a17ae 13595 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13596 direct, style);
42f914d4 13597
d62a17ae 13598 XFREE(MTYPE_TMP, str);
daf9ddbb 13599
d62a17ae 13600 if (ret < 0) {
13601 community_list_perror(vty, ret);
13602 return CMD_WARNING_CONFIG_FAILED;
13603 }
42f914d4 13604
d62a17ae 13605 return CMD_SUCCESS;
718e3744 13606}
13607
5bf15956
DW
13608/* ip community-list expanded */
13609DEFUN (ip_community_list_expanded_all,
13610 ip_community_list_expanded_all_cmd,
42f914d4 13611 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13612 IP_STR
13613 COMMUNITY_LIST_STR
13614 "Community list number (expanded)\n"
5bf15956 13615 "Add an expanded community-list entry\n"
718e3744 13616 "Community list name\n"
13617 "Specify community to reject\n"
13618 "Specify community to accept\n"
13619 COMMUNITY_VAL_STR)
13620{
d62a17ae 13621 char *cl_name_or_number = NULL;
13622 int direct = 0;
13623 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13624
d62a17ae 13625 int idx = 0;
13626 argv_find(argv, argc, "(100-500)", &idx);
13627 argv_find(argv, argc, "WORD", &idx);
13628 cl_name_or_number = argv[idx]->arg;
13629 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13630 : COMMUNITY_DENY;
13631 argv_find(argv, argc, "AA:NN", &idx);
13632 char *str = argv_concat(argv, argc, idx);
42f914d4 13633
d62a17ae 13634 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13635 style);
42f914d4 13636
d62a17ae 13637 XFREE(MTYPE_TMP, str);
42f914d4 13638
d62a17ae 13639 if (ret < 0) {
13640 /* Display error string. */
13641 community_list_perror(vty, ret);
13642 return CMD_WARNING_CONFIG_FAILED;
13643 }
42f914d4 13644
d62a17ae 13645 return CMD_SUCCESS;
718e3744 13646}
13647
5bf15956
DW
13648DEFUN (no_ip_community_list_expanded_all,
13649 no_ip_community_list_expanded_all_cmd,
42f914d4 13650 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13651 NO_STR
13652 IP_STR
13653 COMMUNITY_LIST_STR
5bf15956
DW
13654 "Community list number (expanded)\n"
13655 "Add an expanded community-list entry\n"
718e3744 13656 "Community list name\n"
13657 "Specify community to reject\n"
13658 "Specify community to accept\n"
5bf15956 13659 COMMUNITY_VAL_STR)
718e3744 13660{
d62a17ae 13661 char *cl_name_or_number = NULL;
13662 int direct = 0;
13663 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13664
d62a17ae 13665 int idx = 0;
13666 argv_find(argv, argc, "(100-500)", &idx);
13667 argv_find(argv, argc, "WORD", &idx);
13668 cl_name_or_number = argv[idx]->arg;
13669 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13670 : COMMUNITY_DENY;
13671 argv_find(argv, argc, "AA:NN", &idx);
13672 char *str = argv_concat(argv, argc, idx);
42f914d4 13673
d62a17ae 13674 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13675 direct, style);
42f914d4 13676
d62a17ae 13677 XFREE(MTYPE_TMP, str);
daf9ddbb 13678
d62a17ae 13679 if (ret < 0) {
13680 community_list_perror(vty, ret);
13681 return CMD_WARNING_CONFIG_FAILED;
13682 }
42f914d4 13683
d62a17ae 13684 return CMD_SUCCESS;
718e3744 13685}
13686
8d9b8ed9
PM
13687/* Return configuration string of community-list entry. */
13688static const char *community_list_config_str(struct community_entry *entry)
13689{
13690 const char *str;
13691
13692 if (entry->any)
13693 str = "";
13694 else {
13695 if (entry->style == COMMUNITY_LIST_STANDARD)
13696 str = community_str(entry->u.com, false);
13697 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13698 str = lcommunity_str(entry->u.lcom, false);
13699 else
13700 str = entry->config;
13701 }
13702 return str;
13703}
13704
d62a17ae 13705static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 13706{
d62a17ae 13707 struct community_entry *entry;
718e3744 13708
d62a17ae 13709 for (entry = list->head; entry; entry = entry->next) {
13710 if (entry == list->head) {
13711 if (all_digit(list->name))
13712 vty_out(vty, "Community %s list %s\n",
13713 entry->style == COMMUNITY_LIST_STANDARD
13714 ? "standard"
13715 : "(expanded) access",
13716 list->name);
13717 else
13718 vty_out(vty, "Named Community %s list %s\n",
13719 entry->style == COMMUNITY_LIST_STANDARD
13720 ? "standard"
13721 : "expanded",
13722 list->name);
13723 }
13724 if (entry->any)
13725 vty_out(vty, " %s\n",
13726 community_direct_str(entry->direct));
13727 else
13728 vty_out(vty, " %s %s\n",
13729 community_direct_str(entry->direct),
8d9b8ed9 13730 community_list_config_str(entry));
d62a17ae 13731 }
718e3744 13732}
13733
13734DEFUN (show_ip_community_list,
13735 show_ip_community_list_cmd,
13736 "show ip community-list",
13737 SHOW_STR
13738 IP_STR
13739 "List community-list\n")
13740{
d62a17ae 13741 struct community_list *list;
13742 struct community_list_master *cm;
718e3744 13743
d62a17ae 13744 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13745 if (!cm)
13746 return CMD_SUCCESS;
718e3744 13747
d62a17ae 13748 for (list = cm->num.head; list; list = list->next)
13749 community_list_show(vty, list);
718e3744 13750
d62a17ae 13751 for (list = cm->str.head; list; list = list->next)
13752 community_list_show(vty, list);
718e3744 13753
d62a17ae 13754 return CMD_SUCCESS;
718e3744 13755}
13756
13757DEFUN (show_ip_community_list_arg,
13758 show_ip_community_list_arg_cmd,
6147e2c6 13759 "show ip community-list <(1-500)|WORD>",
718e3744 13760 SHOW_STR
13761 IP_STR
13762 "List community-list\n"
13763 "Community-list number\n"
13764 "Community-list name\n")
13765{
d62a17ae 13766 int idx_comm_list = 3;
13767 struct community_list *list;
718e3744 13768
d62a17ae 13769 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13770 COMMUNITY_LIST_MASTER);
13771 if (!list) {
13772 vty_out(vty, "%% Can't find community-list\n");
13773 return CMD_WARNING;
13774 }
718e3744 13775
d62a17ae 13776 community_list_show(vty, list);
718e3744 13777
d62a17ae 13778 return CMD_SUCCESS;
718e3744 13779}
6b0655a2 13780
57d187bc
JS
13781/*
13782 * Large Community code.
13783 */
d62a17ae 13784static int lcommunity_list_set_vty(struct vty *vty, int argc,
13785 struct cmd_token **argv, int style,
13786 int reject_all_digit_name)
13787{
13788 int ret;
13789 int direct;
13790 char *str;
13791 int idx = 0;
13792 char *cl_name;
13793
13794 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13795 : COMMUNITY_DENY;
13796
13797 /* All digit name check. */
13798 idx = 0;
13799 argv_find(argv, argc, "WORD", &idx);
13800 argv_find(argv, argc, "(1-99)", &idx);
13801 argv_find(argv, argc, "(100-500)", &idx);
13802 cl_name = argv[idx]->arg;
13803 if (reject_all_digit_name && all_digit(cl_name)) {
13804 vty_out(vty, "%% Community name cannot have all digits\n");
13805 return CMD_WARNING_CONFIG_FAILED;
13806 }
13807
13808 idx = 0;
13809 argv_find(argv, argc, "AA:BB:CC", &idx);
13810 argv_find(argv, argc, "LINE", &idx);
13811 /* Concat community string argument. */
13812 if (idx)
13813 str = argv_concat(argv, argc, idx);
13814 else
13815 str = NULL;
13816
13817 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13818
13819 /* Free temporary community list string allocated by
13820 argv_concat(). */
13821 if (str)
13822 XFREE(MTYPE_TMP, str);
13823
13824 if (ret < 0) {
13825 community_list_perror(vty, ret);
13826 return CMD_WARNING_CONFIG_FAILED;
13827 }
13828 return CMD_SUCCESS;
13829}
13830
13831static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13832 struct cmd_token **argv, int style)
13833{
13834 int ret;
13835 int direct = 0;
13836 char *str = NULL;
13837 int idx = 0;
13838
13839 argv_find(argv, argc, "permit", &idx);
13840 argv_find(argv, argc, "deny", &idx);
13841
13842 if (idx) {
13843 /* Check the list direct. */
13844 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13845 direct = COMMUNITY_PERMIT;
13846 else
13847 direct = COMMUNITY_DENY;
13848
13849 idx = 0;
13850 argv_find(argv, argc, "LINE", &idx);
13851 argv_find(argv, argc, "AA:AA:NN", &idx);
13852 /* Concat community string argument. */
13853 str = argv_concat(argv, argc, idx);
13854 }
13855
13856 idx = 0;
13857 argv_find(argv, argc, "(1-99)", &idx);
13858 argv_find(argv, argc, "(100-500)", &idx);
13859 argv_find(argv, argc, "WORD", &idx);
13860
13861 /* Unset community list. */
13862 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13863 style);
13864
13865 /* Free temporary community list string allocated by
13866 argv_concat(). */
13867 if (str)
13868 XFREE(MTYPE_TMP, str);
13869
13870 if (ret < 0) {
13871 community_list_perror(vty, ret);
13872 return CMD_WARNING_CONFIG_FAILED;
13873 }
13874
13875 return CMD_SUCCESS;
57d187bc
JS
13876}
13877
13878/* "large-community-list" keyword help string. */
13879#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13880#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13881
13882DEFUN (ip_lcommunity_list_standard,
13883 ip_lcommunity_list_standard_cmd,
52951b63
DS
13884 "ip large-community-list (1-99) <deny|permit>",
13885 IP_STR
13886 LCOMMUNITY_LIST_STR
13887 "Large Community list number (standard)\n"
13888 "Specify large community to reject\n"
7111c1a0 13889 "Specify large community to accept\n")
52951b63 13890{
d62a17ae 13891 return lcommunity_list_set_vty(vty, argc, argv,
13892 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
13893}
13894
13895DEFUN (ip_lcommunity_list_standard1,
13896 ip_lcommunity_list_standard1_cmd,
13897 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
13898 IP_STR
13899 LCOMMUNITY_LIST_STR
13900 "Large Community list number (standard)\n"
13901 "Specify large community to reject\n"
13902 "Specify large community to accept\n"
13903 LCOMMUNITY_VAL_STR)
13904{
d62a17ae 13905 return lcommunity_list_set_vty(vty, argc, argv,
13906 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
13907}
13908
13909DEFUN (ip_lcommunity_list_expanded,
13910 ip_lcommunity_list_expanded_cmd,
13911 "ip large-community-list (100-500) <deny|permit> LINE...",
13912 IP_STR
13913 LCOMMUNITY_LIST_STR
13914 "Large Community list number (expanded)\n"
13915 "Specify large community to reject\n"
13916 "Specify large community to accept\n"
13917 "An ordered list as a regular-expression\n")
13918{
d62a17ae 13919 return lcommunity_list_set_vty(vty, argc, argv,
13920 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
13921}
13922
13923DEFUN (ip_lcommunity_list_name_standard,
13924 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
13925 "ip large-community-list standard WORD <deny|permit>",
13926 IP_STR
13927 LCOMMUNITY_LIST_STR
13928 "Specify standard large-community-list\n"
13929 "Large Community list name\n"
13930 "Specify large community to reject\n"
13931 "Specify large community to accept\n")
13932{
d62a17ae 13933 return lcommunity_list_set_vty(vty, argc, argv,
13934 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
13935}
13936
13937DEFUN (ip_lcommunity_list_name_standard1,
13938 ip_lcommunity_list_name_standard1_cmd,
13939 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
13940 IP_STR
13941 LCOMMUNITY_LIST_STR
13942 "Specify standard large-community-list\n"
13943 "Large Community list name\n"
13944 "Specify large community to reject\n"
13945 "Specify large community to accept\n"
13946 LCOMMUNITY_VAL_STR)
13947{
d62a17ae 13948 return lcommunity_list_set_vty(vty, argc, argv,
13949 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
13950}
13951
13952DEFUN (ip_lcommunity_list_name_expanded,
13953 ip_lcommunity_list_name_expanded_cmd,
13954 "ip large-community-list expanded WORD <deny|permit> LINE...",
13955 IP_STR
13956 LCOMMUNITY_LIST_STR
13957 "Specify expanded large-community-list\n"
13958 "Large Community list name\n"
13959 "Specify large community to reject\n"
13960 "Specify large community to accept\n"
13961 "An ordered list as a regular-expression\n")
13962{
d62a17ae 13963 return lcommunity_list_set_vty(vty, argc, argv,
13964 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
13965}
13966
13967DEFUN (no_ip_lcommunity_list_standard_all,
13968 no_ip_lcommunity_list_standard_all_cmd,
13969 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13970 NO_STR
13971 IP_STR
13972 LCOMMUNITY_LIST_STR
13973 "Large Community list number (standard)\n"
13974 "Large Community list number (expanded)\n"
13975 "Large Community list name\n")
13976{
d62a17ae 13977 return lcommunity_list_unset_vty(vty, argc, argv,
13978 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13979}
13980
13981DEFUN (no_ip_lcommunity_list_name_expanded_all,
13982 no_ip_lcommunity_list_name_expanded_all_cmd,
13983 "no ip large-community-list expanded WORD",
13984 NO_STR
13985 IP_STR
13986 LCOMMUNITY_LIST_STR
13987 "Specify expanded large-community-list\n"
13988 "Large Community list name\n")
13989{
d62a17ae 13990 return lcommunity_list_unset_vty(vty, argc, argv,
13991 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13992}
13993
13994DEFUN (no_ip_lcommunity_list_standard,
13995 no_ip_lcommunity_list_standard_cmd,
13996 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13997 NO_STR
13998 IP_STR
13999 LCOMMUNITY_LIST_STR
14000 "Large Community list number (standard)\n"
14001 "Specify large community to reject\n"
14002 "Specify large community to accept\n"
14003 LCOMMUNITY_VAL_STR)
14004{
d62a17ae 14005 return lcommunity_list_unset_vty(vty, argc, argv,
14006 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14007}
14008
14009DEFUN (no_ip_lcommunity_list_expanded,
14010 no_ip_lcommunity_list_expanded_cmd,
14011 "no ip large-community-list (100-500) <deny|permit> LINE...",
14012 NO_STR
14013 IP_STR
14014 LCOMMUNITY_LIST_STR
14015 "Large Community list number (expanded)\n"
14016 "Specify large community to reject\n"
14017 "Specify large community to accept\n"
14018 "An ordered list as a regular-expression\n")
14019{
d62a17ae 14020 return lcommunity_list_unset_vty(vty, argc, argv,
14021 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14022}
14023
14024DEFUN (no_ip_lcommunity_list_name_standard,
14025 no_ip_lcommunity_list_name_standard_cmd,
14026 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14027 NO_STR
14028 IP_STR
14029 LCOMMUNITY_LIST_STR
14030 "Specify standard large-community-list\n"
14031 "Large Community list name\n"
14032 "Specify large community to reject\n"
14033 "Specify large community to accept\n"
14034 LCOMMUNITY_VAL_STR)
14035{
d62a17ae 14036 return lcommunity_list_unset_vty(vty, argc, argv,
14037 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14038}
14039
14040DEFUN (no_ip_lcommunity_list_name_expanded,
14041 no_ip_lcommunity_list_name_expanded_cmd,
14042 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14043 NO_STR
14044 IP_STR
14045 LCOMMUNITY_LIST_STR
14046 "Specify expanded large-community-list\n"
14047 "Large community list name\n"
14048 "Specify large community to reject\n"
14049 "Specify large community to accept\n"
14050 "An ordered list as a regular-expression\n")
14051{
d62a17ae 14052 return lcommunity_list_unset_vty(vty, argc, argv,
14053 LARGE_COMMUNITY_LIST_EXPANDED);
14054}
14055
14056static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14057{
14058 struct community_entry *entry;
14059
14060 for (entry = list->head; entry; entry = entry->next) {
14061 if (entry == list->head) {
14062 if (all_digit(list->name))
14063 vty_out(vty, "Large community %s list %s\n",
14064 entry->style == EXTCOMMUNITY_LIST_STANDARD
14065 ? "standard"
14066 : "(expanded) access",
14067 list->name);
14068 else
14069 vty_out(vty,
14070 "Named large community %s list %s\n",
14071 entry->style == EXTCOMMUNITY_LIST_STANDARD
14072 ? "standard"
14073 : "expanded",
14074 list->name);
14075 }
14076 if (entry->any)
14077 vty_out(vty, " %s\n",
14078 community_direct_str(entry->direct));
14079 else
14080 vty_out(vty, " %s %s\n",
14081 community_direct_str(entry->direct),
8d9b8ed9 14082 community_list_config_str(entry));
d62a17ae 14083 }
57d187bc
JS
14084}
14085
14086DEFUN (show_ip_lcommunity_list,
14087 show_ip_lcommunity_list_cmd,
14088 "show ip large-community-list",
14089 SHOW_STR
14090 IP_STR
14091 "List large-community list\n")
14092{
d62a17ae 14093 struct community_list *list;
14094 struct community_list_master *cm;
57d187bc 14095
d62a17ae 14096 cm = community_list_master_lookup(bgp_clist,
14097 LARGE_COMMUNITY_LIST_MASTER);
14098 if (!cm)
14099 return CMD_SUCCESS;
57d187bc 14100
d62a17ae 14101 for (list = cm->num.head; list; list = list->next)
14102 lcommunity_list_show(vty, list);
57d187bc 14103
d62a17ae 14104 for (list = cm->str.head; list; list = list->next)
14105 lcommunity_list_show(vty, list);
57d187bc 14106
d62a17ae 14107 return CMD_SUCCESS;
57d187bc
JS
14108}
14109
14110DEFUN (show_ip_lcommunity_list_arg,
14111 show_ip_lcommunity_list_arg_cmd,
14112 "show ip large-community-list <(1-500)|WORD>",
14113 SHOW_STR
14114 IP_STR
14115 "List large-community list\n"
14116 "large-community-list number\n"
14117 "large-community-list name\n")
14118{
d62a17ae 14119 struct community_list *list;
57d187bc 14120
d62a17ae 14121 list = community_list_lookup(bgp_clist, argv[3]->arg,
14122 LARGE_COMMUNITY_LIST_MASTER);
14123 if (!list) {
14124 vty_out(vty, "%% Can't find extcommunity-list\n");
14125 return CMD_WARNING;
14126 }
57d187bc 14127
d62a17ae 14128 lcommunity_list_show(vty, list);
57d187bc 14129
d62a17ae 14130 return CMD_SUCCESS;
57d187bc
JS
14131}
14132
718e3744 14133/* "extcommunity-list" keyword help string. */
14134#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14135#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14136
14137DEFUN (ip_extcommunity_list_standard,
14138 ip_extcommunity_list_standard_cmd,
e961923c 14139 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14140 IP_STR
14141 EXTCOMMUNITY_LIST_STR
14142 "Extended Community list number (standard)\n"
718e3744 14143 "Specify standard extcommunity-list\n"
5bf15956 14144 "Community list name\n"
718e3744 14145 "Specify community to reject\n"
14146 "Specify community to accept\n"
14147 EXTCOMMUNITY_VAL_STR)
14148{
d62a17ae 14149 int style = EXTCOMMUNITY_LIST_STANDARD;
14150 int direct = 0;
14151 char *cl_number_or_name = NULL;
42f914d4 14152
d62a17ae 14153 int idx = 0;
14154 argv_find(argv, argc, "(1-99)", &idx);
14155 argv_find(argv, argc, "WORD", &idx);
14156 cl_number_or_name = argv[idx]->arg;
14157 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14158 : COMMUNITY_DENY;
14159 argv_find(argv, argc, "AA:NN", &idx);
14160 char *str = argv_concat(argv, argc, idx);
42f914d4 14161
d62a17ae 14162 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14163 direct, style);
42f914d4 14164
d62a17ae 14165 XFREE(MTYPE_TMP, str);
42f914d4 14166
d62a17ae 14167 if (ret < 0) {
14168 community_list_perror(vty, ret);
14169 return CMD_WARNING_CONFIG_FAILED;
14170 }
42f914d4 14171
d62a17ae 14172 return CMD_SUCCESS;
718e3744 14173}
14174
718e3744 14175DEFUN (ip_extcommunity_list_name_expanded,
14176 ip_extcommunity_list_name_expanded_cmd,
e961923c 14177 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14178 IP_STR
14179 EXTCOMMUNITY_LIST_STR
5bf15956 14180 "Extended Community list number (expanded)\n"
718e3744 14181 "Specify expanded extcommunity-list\n"
14182 "Extended Community list name\n"
14183 "Specify community to reject\n"
14184 "Specify community to accept\n"
14185 "An ordered list as a regular-expression\n")
14186{
d62a17ae 14187 int style = EXTCOMMUNITY_LIST_EXPANDED;
14188 int direct = 0;
14189 char *cl_number_or_name = NULL;
42f914d4 14190
d62a17ae 14191 int idx = 0;
14192 argv_find(argv, argc, "(100-500)", &idx);
14193 argv_find(argv, argc, "WORD", &idx);
14194 cl_number_or_name = argv[idx]->arg;
14195 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14196 : COMMUNITY_DENY;
14197 argv_find(argv, argc, "LINE", &idx);
14198 char *str = argv_concat(argv, argc, idx);
42f914d4 14199
d62a17ae 14200 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14201 direct, style);
42f914d4 14202
d62a17ae 14203 XFREE(MTYPE_TMP, str);
42f914d4 14204
d62a17ae 14205 if (ret < 0) {
14206 community_list_perror(vty, ret);
14207 return CMD_WARNING_CONFIG_FAILED;
14208 }
42f914d4 14209
d62a17ae 14210 return CMD_SUCCESS;
718e3744 14211}
14212
fee6e4e4 14213DEFUN (no_ip_extcommunity_list_standard_all,
14214 no_ip_extcommunity_list_standard_all_cmd,
e961923c 14215 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
14216 NO_STR
14217 IP_STR
14218 EXTCOMMUNITY_LIST_STR
14219 "Extended Community list number (standard)\n"
718e3744 14220 "Specify standard extcommunity-list\n"
5bf15956 14221 "Community list name\n"
718e3744 14222 "Specify community to reject\n"
14223 "Specify community to accept\n"
14224 EXTCOMMUNITY_VAL_STR)
14225{
d62a17ae 14226 int style = EXTCOMMUNITY_LIST_STANDARD;
14227 int direct = 0;
14228 char *cl_number_or_name = NULL;
42f914d4 14229
d62a17ae 14230 int idx = 0;
14231 argv_find(argv, argc, "(1-99)", &idx);
14232 argv_find(argv, argc, "WORD", &idx);
14233 cl_number_or_name = argv[idx]->arg;
14234 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14235 : COMMUNITY_DENY;
14236 argv_find(argv, argc, "AA:NN", &idx);
14237 char *str = argv_concat(argv, argc, idx);
42f914d4 14238
d62a17ae 14239 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14240 direct, style);
42f914d4 14241
d62a17ae 14242 XFREE(MTYPE_TMP, str);
42f914d4 14243
d62a17ae 14244 if (ret < 0) {
14245 community_list_perror(vty, ret);
14246 return CMD_WARNING_CONFIG_FAILED;
14247 }
42f914d4 14248
d62a17ae 14249 return CMD_SUCCESS;
718e3744 14250}
14251
5bf15956
DW
14252DEFUN (no_ip_extcommunity_list_expanded_all,
14253 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 14254 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14255 NO_STR
14256 IP_STR
14257 EXTCOMMUNITY_LIST_STR
14258 "Extended Community list number (expanded)\n"
718e3744 14259 "Specify expanded extcommunity-list\n"
5bf15956 14260 "Extended Community list name\n"
718e3744 14261 "Specify community to reject\n"
14262 "Specify community to accept\n"
14263 "An ordered list as a regular-expression\n")
14264{
d62a17ae 14265 int style = EXTCOMMUNITY_LIST_EXPANDED;
14266 int direct = 0;
14267 char *cl_number_or_name = NULL;
42f914d4 14268
d62a17ae 14269 int idx = 0;
14270 argv_find(argv, argc, "(100-500)", &idx);
14271 argv_find(argv, argc, "WORD", &idx);
14272 cl_number_or_name = argv[idx]->arg;
14273 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14274 : COMMUNITY_DENY;
14275 argv_find(argv, argc, "LINE", &idx);
14276 char *str = argv_concat(argv, argc, idx);
42f914d4 14277
d62a17ae 14278 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14279 direct, style);
42f914d4 14280
d62a17ae 14281 XFREE(MTYPE_TMP, str);
42f914d4 14282
d62a17ae 14283 if (ret < 0) {
14284 community_list_perror(vty, ret);
14285 return CMD_WARNING_CONFIG_FAILED;
14286 }
42f914d4 14287
d62a17ae 14288 return CMD_SUCCESS;
718e3744 14289}
14290
d62a17ae 14291static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 14292{
d62a17ae 14293 struct community_entry *entry;
718e3744 14294
d62a17ae 14295 for (entry = list->head; entry; entry = entry->next) {
14296 if (entry == list->head) {
14297 if (all_digit(list->name))
14298 vty_out(vty, "Extended community %s list %s\n",
14299 entry->style == EXTCOMMUNITY_LIST_STANDARD
14300 ? "standard"
14301 : "(expanded) access",
14302 list->name);
14303 else
14304 vty_out(vty,
14305 "Named extended community %s list %s\n",
14306 entry->style == EXTCOMMUNITY_LIST_STANDARD
14307 ? "standard"
14308 : "expanded",
14309 list->name);
14310 }
14311 if (entry->any)
14312 vty_out(vty, " %s\n",
14313 community_direct_str(entry->direct));
14314 else
14315 vty_out(vty, " %s %s\n",
14316 community_direct_str(entry->direct),
8d9b8ed9 14317 community_list_config_str(entry));
d62a17ae 14318 }
718e3744 14319}
14320
14321DEFUN (show_ip_extcommunity_list,
14322 show_ip_extcommunity_list_cmd,
14323 "show ip extcommunity-list",
14324 SHOW_STR
14325 IP_STR
14326 "List extended-community list\n")
14327{
d62a17ae 14328 struct community_list *list;
14329 struct community_list_master *cm;
718e3744 14330
d62a17ae 14331 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14332 if (!cm)
14333 return CMD_SUCCESS;
718e3744 14334
d62a17ae 14335 for (list = cm->num.head; list; list = list->next)
14336 extcommunity_list_show(vty, list);
718e3744 14337
d62a17ae 14338 for (list = cm->str.head; list; list = list->next)
14339 extcommunity_list_show(vty, list);
718e3744 14340
d62a17ae 14341 return CMD_SUCCESS;
718e3744 14342}
14343
14344DEFUN (show_ip_extcommunity_list_arg,
14345 show_ip_extcommunity_list_arg_cmd,
6147e2c6 14346 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 14347 SHOW_STR
14348 IP_STR
14349 "List extended-community list\n"
14350 "Extcommunity-list number\n"
14351 "Extcommunity-list name\n")
14352{
d62a17ae 14353 int idx_comm_list = 3;
14354 struct community_list *list;
718e3744 14355
d62a17ae 14356 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14357 EXTCOMMUNITY_LIST_MASTER);
14358 if (!list) {
14359 vty_out(vty, "%% Can't find extcommunity-list\n");
14360 return CMD_WARNING;
14361 }
718e3744 14362
d62a17ae 14363 extcommunity_list_show(vty, list);
718e3744 14364
d62a17ae 14365 return CMD_SUCCESS;
718e3744 14366}
6b0655a2 14367
718e3744 14368/* Display community-list and extcommunity-list configuration. */
d62a17ae 14369static int community_list_config_write(struct vty *vty)
14370{
14371 struct community_list *list;
14372 struct community_entry *entry;
14373 struct community_list_master *cm;
14374 int write = 0;
14375
14376 /* Community-list. */
14377 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14378
14379 for (list = cm->num.head; list; list = list->next)
14380 for (entry = list->head; entry; entry = entry->next) {
14381 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14382 community_direct_str(entry->direct),
14383 community_list_config_str(entry));
14384 write++;
14385 }
14386 for (list = cm->str.head; list; list = list->next)
14387 for (entry = list->head; entry; entry = entry->next) {
14388 vty_out(vty, "ip community-list %s %s %s %s\n",
14389 entry->style == COMMUNITY_LIST_STANDARD
14390 ? "standard"
14391 : "expanded",
14392 list->name, community_direct_str(entry->direct),
14393 community_list_config_str(entry));
14394 write++;
14395 }
14396
14397 /* Extcommunity-list. */
14398 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14399
14400 for (list = cm->num.head; list; list = list->next)
14401 for (entry = list->head; entry; entry = entry->next) {
14402 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14403 list->name, community_direct_str(entry->direct),
14404 community_list_config_str(entry));
14405 write++;
14406 }
14407 for (list = cm->str.head; list; list = list->next)
14408 for (entry = list->head; entry; entry = entry->next) {
14409 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14410 entry->style == EXTCOMMUNITY_LIST_STANDARD
14411 ? "standard"
14412 : "expanded",
14413 list->name, community_direct_str(entry->direct),
14414 community_list_config_str(entry));
14415 write++;
14416 }
14417
14418
14419 /* lcommunity-list. */
14420 cm = community_list_master_lookup(bgp_clist,
14421 LARGE_COMMUNITY_LIST_MASTER);
14422
14423 for (list = cm->num.head; list; list = list->next)
14424 for (entry = list->head; entry; entry = entry->next) {
14425 vty_out(vty, "ip large-community-list %s %s %s\n",
14426 list->name, community_direct_str(entry->direct),
14427 community_list_config_str(entry));
14428 write++;
14429 }
14430 for (list = cm->str.head; list; list = list->next)
14431 for (entry = list->head; entry; entry = entry->next) {
14432 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14433 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14434 ? "standard"
14435 : "expanded",
14436 list->name, community_direct_str(entry->direct),
14437 community_list_config_str(entry));
14438 write++;
14439 }
14440
14441 return write;
14442}
14443
14444static struct cmd_node community_list_node = {
14445 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 14446};
14447
d62a17ae 14448static void community_list_vty(void)
14449{
14450 install_node(&community_list_node, community_list_config_write);
14451
14452 /* Community-list. */
14453 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14454 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14455 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14456 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14457 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14458 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14459
14460 /* Extcommunity-list. */
14461 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14462 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14463 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14464 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14465 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14466 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14467
14468 /* Large Community List */
14469 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14470 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14471 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14472 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14473 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14474 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14475 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14476 install_element(CONFIG_NODE,
14477 &no_ip_lcommunity_list_name_expanded_all_cmd);
14478 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14479 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14480 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14481 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14482 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14483 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 14484}