3 * Copyright 2009-2016, LabN Consulting, L.L.C.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
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
24 #include "lib/zebra.h"
25 #include "lib/prefix.h"
26 #include "lib/table.h"
28 #include "lib/memory.h"
29 #include "lib/routemap.h"
31 #include "lib/log_int.h"
32 #include "lib/linklist.h"
33 #include "lib/command.h"
35 #include "bgpd/bgpd.h"
36 #include "bgpd/bgp_ecommunity.h"
37 #include "bgpd/bgp_attr.h"
38 #include "bgpd/bgp_route.h"
39 #include "bgpd/bgp_mplsvpn.h"
41 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
42 #include "bgpd/rfapi/rfapi.h"
43 #include "bgpd/rfapi/rfapi_backend.h"
45 #include "bgpd/bgp_route.h"
46 #include "bgpd/bgp_aspath.h"
47 #include "bgpd/bgp_community.h"
48 #include "bgpd/bgp_vnc_types.h"
50 #include "bgpd/rfapi/rfapi_import.h"
51 #include "bgpd/rfapi/rfapi_private.h"
52 #include "bgpd/rfapi/rfapi_monitor.h"
53 #include "bgpd/rfapi/rfapi_rib.h"
54 #include "bgpd/rfapi/rfapi_vty.h"
55 #include "bgpd/rfapi/rfapi_ap.h"
56 #include "bgpd/rfapi/rfapi_encap_tlv.h"
57 #include "bgpd/rfapi/vnc_debug.h"
59 #define DEBUG_L2_EXTRA 0
60 #define DEBUG_SHOW_EXTRA 0
62 #define VNC_SHOW_STR "VNC information\n"
64 /* format related utilies */
67 #define FMT_MIN 60 /* seconds */
68 #define FMT_HOUR (60 * FMT_MIN)
69 #define FMT_DAY (24 * FMT_HOUR)
70 #define FMT_YEAR (365 * FMT_DAY)
73 rfapiFormatSeconds (uint32_t seconds
, char *buf
, size_t len
)
75 int year
, day
, hour
, min
;
77 if (seconds
>= FMT_YEAR
)
79 year
= seconds
/ FMT_YEAR
;
80 seconds
-= year
* FMT_YEAR
;
85 if (seconds
>= FMT_DAY
)
87 day
= seconds
/ FMT_DAY
;
88 seconds
-= day
* FMT_DAY
;
93 if (seconds
>= FMT_HOUR
)
95 hour
= seconds
/ FMT_HOUR
;
96 seconds
-= hour
* FMT_HOUR
;
101 if (seconds
>= FMT_MIN
)
103 min
= seconds
/ FMT_MIN
;
104 seconds
-= min
* FMT_MIN
;
111 snprintf (buf
, len
, "%dy%dd%dh", year
, day
, hour
);
115 snprintf (buf
, len
, "%dd%dh%dm", day
, hour
, min
);
119 snprintf (buf
, len
, "%02d:%02d:%02d", hour
, min
, seconds
);
126 rfapiFormatAge (time_t age
, char *buf
, size_t len
)
128 time_t now
, age_adjusted
;
130 now
= rfapi_time (NULL
);
131 age_adjusted
= now
- age
;
133 return rfapiFormatSeconds (age_adjusted
, buf
, len
);
138 * Reimplementation of quagga/lib/prefix.c function, but
139 * for RFAPI-style prefixes
142 rfapiRprefixApplyMask (struct rfapi_ip_prefix
*rprefix
)
148 static uint8_t maskbit
[] =
149 { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
151 switch (rprefix
->prefix
.addr_family
)
154 index
= rprefix
->length
/ 8;
157 pnt
= (uint8_t *) & rprefix
->prefix
.addr
.v4
;
158 offset
= rprefix
->length
% 8;
159 pnt
[index
] &= maskbit
[offset
];
167 index
= rprefix
->length
/ 8;
170 pnt
= (uint8_t *) & rprefix
->prefix
.addr
.v6
;
171 offset
= rprefix
->length
% 8;
172 pnt
[index
] &= maskbit
[offset
];
185 * translate a quagga prefix into a rfapi IP address. The
186 * prefix is REQUIRED to be 32 bits for IPv4 and 128 bits for IPv6
194 rfapiQprefix2Raddr (struct prefix
*qprefix
, struct rfapi_ip_addr
*raddr
)
196 memset (raddr
, 0, sizeof (struct rfapi_ip_addr
));
197 raddr
->addr_family
= qprefix
->family
;
198 switch (qprefix
->family
)
201 if (qprefix
->prefixlen
!= 32)
203 raddr
->addr
.v4
= qprefix
->u
.prefix4
;
206 if (qprefix
->prefixlen
!= 128)
208 raddr
->addr
.v6
= qprefix
->u
.prefix6
;
217 * Translate Quagga prefix to RFAPI prefix
219 /* rprefix->cost set to 0 */
221 rfapiQprefix2Rprefix (struct prefix
*qprefix
, struct rfapi_ip_prefix
*rprefix
)
223 memset (rprefix
, 0, sizeof (struct rfapi_ip_prefix
));
224 rprefix
->length
= qprefix
->prefixlen
;
225 rprefix
->prefix
.addr_family
= qprefix
->family
;
226 switch (qprefix
->family
)
229 rprefix
->prefix
.addr
.v4
= qprefix
->u
.prefix4
;
232 rprefix
->prefix
.addr
.v6
= qprefix
->u
.prefix6
;
240 rfapiRprefix2Qprefix (struct rfapi_ip_prefix
*rprefix
, struct prefix
*qprefix
)
242 memset (qprefix
, 0, sizeof (struct prefix
));
243 qprefix
->prefixlen
= rprefix
->length
;
244 qprefix
->family
= rprefix
->prefix
.addr_family
;
246 switch (rprefix
->prefix
.addr_family
)
249 qprefix
->u
.prefix4
= rprefix
->prefix
.addr
.v4
;
252 qprefix
->u
.prefix6
= rprefix
->prefix
.addr
.v6
;
261 * returns 1 if prefixes have same addr family, prefix len, and address
262 * Note that host bits matter in this comparison!
264 * For paralellism with quagga/lib/prefix.c. if we need a comparison
265 * where host bits are ignored, call that function rfapiRprefixCmp.
268 rfapiRprefixSame (struct rfapi_ip_prefix
*hp1
, struct rfapi_ip_prefix
*hp2
)
270 if (hp1
->prefix
.addr_family
!= hp2
->prefix
.addr_family
)
272 if (hp1
->length
!= hp2
->length
)
274 if (hp1
->prefix
.addr_family
== AF_INET
)
275 if (IPV4_ADDR_SAME (&hp1
->prefix
.addr
.v4
, &hp2
->prefix
.addr
.v4
))
277 if (hp1
->prefix
.addr_family
== AF_INET6
)
278 if (IPV6_ADDR_SAME (&hp1
->prefix
.addr
.v6
, &hp2
->prefix
.addr
.v6
))
284 rfapiRaddr2Qprefix (struct rfapi_ip_addr
*hia
, struct prefix
*pfx
)
286 memset (pfx
, 0, sizeof (struct prefix
));
287 pfx
->family
= hia
->addr_family
;
289 switch (hia
->addr_family
)
293 pfx
->u
.prefix4
= hia
->addr
.v4
;
296 pfx
->prefixlen
= 128;
297 pfx
->u
.prefix6
= hia
->addr
.v6
;
306 rfapiL2o2Qprefix (struct rfapi_l2address_option
*l2o
, struct prefix
*pfx
)
308 memset (pfx
, 0, sizeof (struct prefix
));
309 pfx
->family
= AF_ETHERNET
;
311 pfx
->u
.prefix_eth
= l2o
->macaddr
;
315 rfapiEthAddr2Str (const struct ethaddr
*ea
, char *buf
, int bufsize
)
317 return prefix_mac2str (ea
, buf
, bufsize
);
321 rfapiStr2EthAddr (const char *str
, struct ethaddr
*ea
)
326 if (sscanf (str
, "%2x:%2x:%2x:%2x:%2x:%2x",
327 a
+ 0, a
+ 1, a
+ 2, a
+ 3, a
+ 4, a
+ 5) != 6)
333 for (i
= 0; i
< 6; ++i
)
334 ea
->octet
[i
] = a
[i
] & 0xff;
340 rfapi_ntop (int af
, const void *src
, char *buf
, socklen_t size
)
342 if (af
== AF_ETHERNET
)
344 return rfapiEthAddr2Str ((const struct ethaddr
*) src
, buf
, size
);
347 return inet_ntop (af
, src
, buf
, size
);
351 rfapiDebugPrintf (void *dummy
, const char *format
, ...)
354 va_start (args
, format
);
355 vzlog (LOG_DEBUG
, format
, args
);
361 rfapiStdioPrintf (void *stream
, const char *format
, ...)
366 va_start (args
, format
);
368 switch ((uintptr_t) stream
)
380 vfprintf (file
, format
, args
);
385 /* Fake out for debug logging */
386 static struct vty vty_dummy_zlog
;
387 static struct vty vty_dummy_stdio
;
388 #define HVTYNL ((vty == &vty_dummy_zlog)? "": VTYNL)
391 str_vty_newline (struct vty
*vty
)
393 if (vty
== &vty_dummy_zlog
)
400 void *stream
, /* input */
401 int (**fp
) (void *, const char *, ...), /* output */
402 struct vty
**vty
, /* output */
403 void **outstream
, /* output */
404 const char **vty_newline
) /* output */
409 vty_dummy_zlog
.type
= VTY_SHELL
; /* for VTYNL */
410 *vty
= &vty_dummy_zlog
;
411 *fp
= (int (*)(void *, const char *,...)) rfapiDebugPrintf
;
413 *vty_newline
= str_vty_newline (*vty
);
414 return (vzlog_test (LOG_DEBUG
));
417 if (((uintptr_t) stream
== (uintptr_t) 1) ||
418 ((uintptr_t) stream
== (uintptr_t) 2))
421 vty_dummy_stdio
.type
= VTY_SHELL
; /* for VTYNL */
422 *vty
= &vty_dummy_stdio
;
423 *fp
= (int (*)(void *, const char *,...)) rfapiStdioPrintf
;
425 *vty_newline
= str_vty_newline (*vty
);
431 *vty
= stream
; /* VTYNL requires vty to be legit */
432 *fp
= (int (*)(void *, const char *,...)) vty_out
;
434 *vty_newline
= str_vty_newline (*vty
);
441 /* called from bgpd/bgp_vty.c'route_vty_out() */
443 rfapi_vty_out_vncinfo (
453 * Print, on an indented line:
454 * UN address [if VPN route and VNC UN addr subtlv]
460 if (safi
== SAFI_MPLS_VPN
)
462 struct prefix pfx_un
;
464 if (!rfapiGetVncTunnelUnAddr (bi
->attr
, &pfx_un
))
467 vty_out (vty
, "UN=%s", inet_ntop (pfx_un
.family
,
468 pfx_un
.u
.val
, buf
, BUFSIZ
));
472 if (bi
->attr
&& bi
->attr
->extra
&& bi
->attr
->extra
->ecommunity
)
474 s
= ecommunity_ecom2str (bi
->attr
->extra
->ecommunity
,
475 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
476 vty_out (vty
, " EC{%s}", s
);
477 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
480 if (bi
->extra
!= NULL
)
481 vty_out (vty
, " label=%u", decode_label (&bi
->extra
->label
));
483 if (!rfapiGetVncLifetime (bi
->attr
, &lifetime
))
485 vty_out (vty
, " life=%d", lifetime
);
488 vty_out (vty
, " type=%s, subtype=%d",
489 zebra_route_string (bi
->type
), bi
->sub_type
);
491 vty_out (vty
, "%s", HVTYNL
);
495 rfapiPrintAttrPtrs (void *stream
, struct attr
*attr
)
497 int (*fp
) (void *, const char *, ...);
500 const char *vty_newline
;
502 struct attr_extra
*ae
;
505 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
508 fp (out
, "Attr[%p]:%s", attr
, HVTYNL
);
513 inet_ntop (AF_INET
, &attr
->nexthop
, buf
, BUFSIZ
);
514 fp (out
, " nexthop=%s%s", buf
, HVTYNL
);
516 fp (out
, " aspath=%p, refcnt=%d%s", attr
->aspath
,
517 (attr
->aspath
? attr
->aspath
->refcnt
: 0), HVTYNL
);
518 fp (out
, " community=%p, refcnt=%d%s", attr
->community
,
519 (attr
->community
? attr
->community
->refcnt
: 0), HVTYNL
);
521 if ((ae
= attr
->extra
))
523 fp (out
, " ecommunity=%p, refcnt=%d%s", ae
->ecommunity
,
524 (ae
->ecommunity
? ae
->ecommunity
->refcnt
: 0), HVTYNL
);
525 fp (out
, " cluster=%p, refcnt=%d%s", ae
->cluster
,
526 (ae
->cluster
? ae
->cluster
->refcnt
: 0), HVTYNL
);
527 fp (out
, " transit=%p, refcnt=%d%s", ae
->transit
,
528 (ae
->transit
? ae
->transit
->refcnt
: 0), HVTYNL
);
533 * Print BI in an Import Table
536 rfapiPrintBi (void *stream
, struct bgp_info
*bi
)
541 int (*fp
) (void *, const char *, ...);
544 const char *vty_newline
;
550 struct ethaddr macaddr
;
551 struct rfapi_l2address_option l2o_buf
;
552 uint8_t l2hid
=0; /* valid if has_macaddr */
554 #define REMAIN (BUFSIZ - (p-line))
555 #define INCP {p += (r > REMAIN)? REMAIN: r;}
557 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
563 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
) && bi
->extra
564 && bi
->extra
->vnc
.import
.timer
)
566 struct thread
*t
= (struct thread
*) bi
->extra
->vnc
.import
.timer
;
567 r
= snprintf (p
, REMAIN
, " [%4lu] ", thread_timer_remain_second (t
));
573 r
= snprintf (p
, REMAIN
, " ");
579 /* TBD This valid only for SAFI_MPLS_VPN, but not for encap */
580 if (decode_rd_type(bi
->extra
->vnc
.import
.rd
.val
) == RD_TYPE_VNC_ETH
)
583 memcpy (macaddr
.octet
, bi
->extra
->vnc
.import
.rd
.val
+ 2, 6);
584 l2hid
= bi
->extra
->vnc
.import
.rd
.val
[1];
593 * RFP option sizes (they are opaque values)
594 * extended communities (RTs)
596 if (bi
->attr
&& bi
->attr
->extra
)
599 int printed_1st_gol
= 0;
600 struct bgp_attr_encap_subtlv
*pEncap
;
601 struct prefix pfx_un
;
602 int af
= BGP_MP_NEXTHOP_FAMILY (bi
->attr
->extra
->mp_nexthop_len
);
607 r
= snprintf (p
, REMAIN
, "%s", inet_ntop (AF_INET
,
608 &bi
->attr
->extra
->mp_nexthop_global_in
,
612 else if (af
== AF_INET6
)
614 r
= snprintf (p
, REMAIN
, "%s", inet_ntop (AF_INET6
,
615 &bi
->attr
->extra
->mp_nexthop_global
,
621 r
= snprintf (p
, REMAIN
, "?");
626 * VNC tunnel subtlv, if present, contains UN address
628 if (!rfapiGetVncTunnelUnAddr (bi
->attr
, &pfx_un
))
630 r
= snprintf (p
, REMAIN
, " un=%s", inet_ntop (pfx_un
.family
,
638 if (rfapiGetVncLifetime (bi
->attr
, &lifetime
))
640 r
= snprintf (p
, REMAIN
, " nolife");
645 if (lifetime
== 0xffffffff)
646 r
= snprintf (p
, REMAIN
, " %6s", "infini");
648 r
= snprintf (p
, REMAIN
, " %6u", lifetime
);
652 /* RFP option lengths */
653 for (pEncap
= bi
->attr
->extra
->vnc_subtlvs
; pEncap
;
654 pEncap
= pEncap
->next
)
657 if (pEncap
->type
== BGP_VNC_SUBTLV_TYPE_RFPOPTION
)
661 r
= snprintf (p
, REMAIN
, ",");
666 r
= snprintf (p
, REMAIN
, " "); /* leading space */
669 r
= snprintf (p
, REMAIN
, "%d", pEncap
->length
);
676 if (bi
->attr
->extra
->ecommunity
)
678 s
= ecommunity_ecom2str (bi
->attr
->extra
->ecommunity
,
679 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
680 r
= snprintf (p
, REMAIN
, " %s", s
);
682 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
687 r
= snprintf (p
, REMAIN
, " bi@%p", bi
);
690 r
= snprintf (p
, REMAIN
, " p@%p", bi
->peer
);
693 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
695 r
= snprintf (p
, REMAIN
, " HD=yes");
700 r
= snprintf (p
, REMAIN
, " HD=no");
709 r
= snprintf (p
, REMAIN
, " W=%d", bi
->attr
->extra
->weight
);
713 if (bi
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
715 r
= snprintf (p
, REMAIN
, " LP=%d", bi
->attr
->local_pref
);
720 r
= snprintf (p
, REMAIN
, " LP=unset");
726 snprintf (p
, REMAIN
, " %c:%u", zebra_route_char (bi
->type
), bi
->sub_type
);
729 fp (out
, "%s%s", line
, HVTYNL
);
733 fp (out
, " RD HID=%d ETH=%02x:%02x:%02x:%02x:%02x:%02x%s",
738 macaddr
.octet
[3], macaddr
.octet
[4], macaddr
.octet
[5], HVTYNL
);
741 if (!rfapiGetL2o (bi
->attr
, &l2o_buf
))
744 " L2O ETH=%02x:%02x:%02x:%02x:%02x:%02x LBL=%d LNI=%d LHI=%hhu%s",
745 l2o_buf
.macaddr
.octet
[0], l2o_buf
.macaddr
.octet
[1],
746 l2o_buf
.macaddr
.octet
[2], l2o_buf
.macaddr
.octet
[3],
747 l2o_buf
.macaddr
.octet
[4], l2o_buf
.macaddr
.octet
[5], l2o_buf
.label
,
748 l2o_buf
.logical_net_id
, l2o_buf
.local_nve_id
, HVTYNL
);
750 if (bi
->extra
&& bi
->extra
->vnc
.import
.aux_prefix
.family
)
755 sp
= rfapi_ntop (bi
->extra
->vnc
.import
.aux_prefix
.family
,
756 &bi
->extra
->vnc
.import
.aux_prefix
.u
.prefix
,
761 fp (out
, " IP: %s%s", sp
, HVTYNL
);
765 struct rfapi_un_option
*uo
= rfapi_encap_tlv_to_un_option (bi
->attr
);
768 rfapi_print_tunneltype_option (stream
, 8, &uo
->v
.tunnel
);
769 rfapi_un_options_free (uo
);
775 rfapiMonitorVpn2Str (struct rfapi_monitor_vpn
*m
, char *buf
, int size
)
777 char buf_pfx
[BUFSIZ
];
782 rfapiRfapiIpAddr2Str (&m
->rfd
->un_addr
, buf_vn
, BUFSIZ
);
783 rfapiRfapiIpAddr2Str (&m
->rfd
->vn_addr
, buf_un
, BUFSIZ
);
785 rc
= snprintf (buf
, size
,
786 "m=%p, next=%p, rfd=%p(vn=%s un=%s), p=%s/%d, node=%p",
787 m
, m
->next
, m
->rfd
, buf_vn
, buf_un
,
788 inet_ntop (m
->p
.family
, &m
->p
.u
.prefix
, buf_pfx
, BUFSIZ
),
789 m
->p
.prefixlen
, m
->node
);
797 rfapiDebugPrintMonitorVpn (void *stream
, struct rfapi_monitor_vpn
*m
)
801 int (*fp
) (void *, const char *, ...);
804 const char *vty_newline
;
806 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
809 rfapiMonitorVpn2Str (m
, buf
, BUFSIZ
);
810 fp (out
, " Mon %s%s", buf
, HVTYNL
);
814 rfapiDebugPrintMonitorEncap (void *stream
, struct rfapi_monitor_encap
*m
)
816 int (*fp
) (void *, const char *, ...);
819 const char *vty_newline
;
821 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
824 fp (out
, " Mon m=%p, next=%p, node=%p, bi=%p%s",
825 m
, m
->next
, m
->node
, m
->bi
, HVTYNL
);
829 rfapiShowItNode (void *stream
, struct route_node
*rn
)
834 int (*fp
) (void *, const char *, ...);
837 const char *vty_newline
;
839 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
842 fp (out
, "%s/%d @%p #%d%s",
843 rfapi_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
),
844 rn
->p
.prefixlen
, rn
, rn
->lock
, HVTYNL
);
846 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
848 rfapiPrintBi (stream
, bi
);
851 /* doesn't show montors */
855 rfapiShowImportTable (
858 struct route_table
*rt
,
861 struct route_node
*rn
;
864 int (*fp
) (void *, const char *, ...);
867 const char *vty_newline
;
869 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
872 fp (out
, "Import Table [%s]%s", label
, HVTYNL
);
874 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
878 if (rn
->p
.family
== AF_ETHERNET
)
880 rfapiEthAddr2Str (&rn
->p
.u
.prefix_eth
, buf
, BUFSIZ
);
884 inet_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
);
887 fp (out
, "%s/%d @%p #%d%s", buf
, rn
->p
.prefixlen
, rn
, rn
->lock
- 1, /* account for loop iterator locking */
890 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
892 rfapiPrintBi (stream
, bi
);
897 struct rfapi_monitor_vpn
*m
;
898 for (m
= RFAPI_MONITOR_VPN (rn
); m
; m
= m
->next
)
900 rfapiDebugPrintMonitorVpn (stream
, m
);
905 struct rfapi_monitor_encap
*m
;
906 for (m
= RFAPI_MONITOR_ENCAP (rn
); m
; m
= m
->next
)
908 rfapiDebugPrintMonitorEncap (stream
, m
);
915 rfapiShowVncQueries (void *stream
, struct prefix
*pfx_match
)
919 struct listnode
*node
;
920 struct rfapi_descriptor
*rfd
;
922 int (*fp
) (void *, const char *, ...);
925 const char *vty_newline
;
927 int printedheader
= 0;
930 int nves_with_queries
= 0;
931 int nves_displayed
= 0;
933 int queries_total
= 0;
934 int queries_displayed
= 0;
936 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
939 bgp
= bgp_get_default (); /* assume 1 instance for now */
942 vty_outln (vty
, "No BGP instance");
949 vty_outln (vty
, "No RFAPI instance");
953 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
956 struct route_node
*rn
;
957 int printedquerier
= 0;
962 if (rfd
->mon
|| (rfd
->mon_eth
&& skiplist_count (rfd
->mon_eth
)))
976 for (rn
= route_top (rfd
->mon
); rn
; rn
= route_next (rn
))
978 struct rfapi_monitor_vpn
*m
;
979 char buf_remain
[BUFSIZ
];
980 char buf_pfx
[BUFSIZ
];
989 if (pfx_match
&& !prefix_match (pfx_match
, &rn
->p
) &&
990 !prefix_match (&rn
->p
, pfx_match
))
998 fp (out
, "%s", VTYNL
);
999 fp (out
, "%-15s %-15s %-15s %-10s%s",
1000 "VN Address", "UN Address",
1001 "Target", "Remaining", VTYNL
);
1004 if (!printedquerier
)
1006 char buf_vn
[BUFSIZ
];
1007 char buf_un
[BUFSIZ
];
1009 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, buf_un
, BUFSIZ
);
1010 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, buf_vn
, BUFSIZ
);
1012 fp (out
, "%-15s %-15s", buf_vn
, buf_un
);
1018 fp (out
, "%-15s %-15s", "", "");
1022 rfapiFormatSeconds (thread_timer_remain_second (m
->timer
),
1023 buf_remain
, BUFSIZ
);
1025 fp (out
, " %-15s %-10s%s",
1026 inet_ntop (m
->p
.family
, &m
->p
.u
.prefix
, buf_pfx
, BUFSIZ
),
1034 if (rfd
->mon_eth
&& skiplist_count (rfd
->mon_eth
))
1039 struct rfapi_monitor_eth
*mon_eth
;
1043 skiplist_next (rfd
->mon_eth
, NULL
, (void **) &mon_eth
,
1046 skiplist_next (rfd
->mon_eth
, NULL
, (void **) &mon_eth
,
1050 char buf_remain
[BUFSIZ
];
1051 char buf_pfx
[BUFSIZ
];
1052 struct prefix pfx_mac
;
1056 vnc_zlog_debug_verbose ("%s: checking rfd=%p mon_eth=%p", __func__
, rfd
,
1059 memset ((void *) &pfx_mac
, 0, sizeof (struct prefix
));
1060 pfx_mac
.family
= AF_ETHERNET
;
1061 pfx_mac
.prefixlen
= 48;
1062 pfx_mac
.u
.prefix_eth
= mon_eth
->macaddr
;
1064 if (pfx_match
&& !prefix_match (pfx_match
, &pfx_mac
) &&
1065 !prefix_match (&pfx_mac
, pfx_match
))
1068 ++queries_displayed
;
1073 fp (out
, "%s", VTYNL
);
1074 fp (out
, "%-15s %-15s %-17s %10s %-10s%s",
1075 "VN Address", "UN Address",
1076 "Target", "LNI", "Remaining", VTYNL
);
1079 if (!printedquerier
)
1081 char buf_vn
[BUFSIZ
];
1082 char buf_un
[BUFSIZ
];
1084 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, buf_un
, BUFSIZ
);
1085 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, buf_vn
, BUFSIZ
);
1087 fp (out
, "%-15s %-15s", buf_vn
, buf_un
);
1093 fp (out
, "%-15s %-15s", "", "");
1097 rfapiFormatSeconds (thread_timer_remain_second
1098 (mon_eth
->timer
), buf_remain
, BUFSIZ
);
1100 fp (out
, " %-17s %10d %-10s%s",
1101 rfapi_ntop (pfx_mac
.family
, &pfx_mac
.u
.prefix
, buf_pfx
,
1102 BUFSIZ
), mon_eth
->logical_net_id
, buf_remain
,
1110 fp (out
, "%s", VTYNL
);
1111 fp (out
, "Displayed %d out of %d total queries%s",
1112 queries_displayed
, queries_total
, VTYNL
);
1118 rfapiPrintRemoteRegBi (
1121 struct route_node
*rn
,
1122 struct bgp_info
*bi
)
1124 int (*fp
) (void *, const char *, ...);
1127 const char *vty_newline
;
1128 struct prefix pfx_un
;
1129 struct prefix pfx_vn
;
1132 bgp_encap_types tun_type
;
1134 char buf_pfx
[BUFSIZ
];
1135 char buf_ntop
[BUFSIZ
];
1136 char buf_un
[BUFSIZ
];
1137 char buf_vn
[BUFSIZ
];
1138 char buf_lifetime
[BUFSIZ
];
1142 return 0; /* for debug log, print into buf & call output once */
1144 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1151 snprintf (buf_pfx
, BUFSIZ
, "%s/%d",
1152 rfapi_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf_ntop
, BUFSIZ
),
1154 buf_pfx
[BUFSIZ
- 1] = 0;
1161 if (!rfapiGetUnAddrOfVpnBi (bi
, &pfx_un
))
1163 snprintf (buf_un
, BUFSIZ
, "%s",
1164 inet_ntop (pfx_un
.family
, &pfx_un
.u
.prefix
, buf_ntop
,
1168 rfapiGetTunnelType(bi
->attr
,&tun_type
);
1173 rfapiNexthop2Prefix (bi
->attr
, &pfx_vn
);
1174 if (tun_type
== BGP_ENCAP_TYPE_MPLS
)
1176 /* MPLS carries un in nrli next hop (same as vn for IP tunnels) */
1177 snprintf (buf_un
, BUFSIZ
, "%s",
1178 inet_ntop (pfx_vn
.family
, &pfx_vn
.u
.prefix
, buf_ntop
, BUFSIZ
));
1181 u_int32_t l
= decode_label (&bi
->extra
->label
);
1182 snprintf (buf_vn
, BUFSIZ
, "Label: %d", l
);
1184 else /* should never happen */
1186 snprintf (buf_vn
, BUFSIZ
, "Label: N/A");
1191 snprintf (buf_vn
, BUFSIZ
, "%s",
1192 inet_ntop (pfx_vn
.family
, &pfx_vn
.u
.prefix
, buf_ntop
, BUFSIZ
));
1194 buf_vn
[BUFSIZ
- 1] = 0;
1195 buf_un
[BUFSIZ
- 1] = 0;
1198 * Cost is encoded in local_pref as (255-cost)
1199 * See rfapi_import.c'rfapiRouteInfo2NextHopEntry() for conversion
1204 uint32_t local_pref
;
1205 if (bi
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
1206 local_pref
= bi
->attr
->local_pref
;
1209 cost
= (local_pref
> 255) ? 0 : 255 - local_pref
;
1216 fp (out
, "%-20s ", buf_pfx
);
1217 fp (out
, "%-15s ", buf_vn
);
1218 fp (out
, "%-15s ", buf_un
);
1219 fp (out
, "%-4d ", cost
);
1222 /* NB rfapiGetVncLifetime sets infinite value when returning !0 */
1223 if (rfapiGetVncLifetime (bi
->attr
, &lifetime
) ||
1224 (lifetime
== RFAPI_INFINITE_LIFETIME
))
1227 fp (out
, "%-10s ", "infinite");
1231 time_t t_lifetime
= lifetime
;
1232 rfapiFormatSeconds (t_lifetime
, buf_lifetime
, BUFSIZ
);
1233 fp (out
, "%-10s ", buf_lifetime
);
1236 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
) &&
1237 bi
->extra
&& bi
->extra
->vnc
.import
.timer
)
1242 char buf_age
[BUFSIZ
];
1244 struct thread
*t
= (struct thread
*) bi
->extra
->vnc
.import
.timer
;
1245 remaining
= thread_timer_remain_second (t
);
1247 #if RFAPI_REGISTRATIONS_REPORT_AGE
1249 * Calculate when the timer started. Doing so here saves
1250 * us a timestamp field in "struct bgp_info".
1252 * See rfapi_import.c'rfapiBiStartWithdrawTimer() for the
1253 * original calculation.
1255 age
= rfapiGetHolddownFromLifetime (lifetime
, factor
) - remaining
;
1256 #else /* report remaining time */
1259 rfapiFormatSeconds (age
, buf_age
, BUFSIZ
);
1261 fp (out
, "%-10s ", buf_age
);
1264 else if (RFAPI_LOCAL_BI (bi
))
1267 char buf_age
[BUFSIZ
];
1269 if (bi
&& bi
->extra
&& bi
->extra
->vnc
.import
.create_time
)
1271 rfapiFormatAge (bi
->extra
->vnc
.import
.create_time
, buf_age
, BUFSIZ
);
1278 fp (out
, "%-10s ", buf_age
);
1280 fp (out
, "%s", HVTYNL
);
1282 if (rn
->p
.family
== AF_ETHERNET
)
1285 * If there is a corresponding IP address && != VN address,
1286 * print that on the next line
1289 if (bi
&& bi
->extra
&& bi
->extra
->vnc
.import
.aux_prefix
.family
)
1293 sp
= rfapi_ntop (bi
->extra
->vnc
.import
.aux_prefix
.family
,
1294 &bi
->extra
->vnc
.import
.aux_prefix
.u
.prefix
,
1296 buf_ntop
[BUFSIZ
- 1] = 0;
1298 if (sp
&& strcmp (buf_vn
, sp
) != 0)
1300 fp (out
, " IP: %s", sp
);
1306 if (tun_type
!= BGP_ENCAP_TYPE_MPLS
&& bi
->extra
)
1308 u_int32_t l
= decode_label (&bi
->extra
->label
);
1309 if (!MPLS_LABEL_IS_NULL (l
))
1311 fp (out
, " Label: %d", l
);
1317 fp (out
, "%s", HVTYNL
);
1323 rfapiShowRemoteRegistrationsIt (
1326 struct rfapi_import_table
*it
,
1327 struct prefix
*prefix_only
,
1328 int show_expiring
, /* either/or */
1331 int show_imported
, /* either/or */
1332 uint32_t *pLni
) /* AFI_L2VPN only */
1335 int printed_rtlist_hdr
= 0;
1337 int (*fp
) (void *, const char *, ...);
1340 const char *vty_newline
;
1344 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1347 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
)
1350 struct route_node
*rn
;
1352 if (!it
->imported_vpn
[afi
])
1355 for (rn
= route_top (it
->imported_vpn
[afi
]); rn
; rn
= route_next (rn
))
1358 struct bgp_info
*bi
;
1361 /* allow for wider or more narrow mask from user */
1363 !prefix_match (prefix_only
, &rn
->p
) &&
1364 !prefix_match (&rn
->p
, prefix_only
))
1369 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
1372 if (!show_local
&& RFAPI_LOCAL_BI (bi
))
1375 /* local route from RFP */
1379 if (!show_remote
&& !RFAPI_LOCAL_BI (bi
))
1386 if (show_expiring
&& !CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
1389 if (!show_expiring
&& CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
1392 if (bi
->type
== ZEBRA_ROUTE_BGP_DIRECT
||
1393 bi
->type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
)
1405 if (count_only
== 1)
1407 if (!printed_rtlist_hdr
)
1409 const char *agetype
= "";
1411 const char *type
= "";
1424 if (RFAPI_LOCAL_BI (bi
))
1435 s
= ecommunity_ecom2str (it
->rt_import_list
,
1436 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
1440 fp (out
, "%s[%s] L2VPN Network 0x%x (%u) RT={%s}",
1441 HVTYNL
, type
, *pLni
, (*pLni
& 0xfff), s
);
1445 fp (out
, "%s[%s] Prefix RT={%s}",
1448 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1450 if (it
->rfg
&& it
->rfg
->name
)
1452 fp (out
, " %s \"%s\"",
1453 (it
->rfg
->type
== RFAPI_GROUP_CFG_VRF
?
1454 "VRF" : "NVE group"),
1457 fp (out
, "%s", HVTYNL
);
1460 #if RFAPI_REGISTRATIONS_REPORT_AGE
1463 agetype
= "Remaining";
1466 else if (show_local
)
1471 printed_rtlist_hdr
= 1;
1473 fp (out
, "%-20s %-15s %-15s %4s %-10s %-10s%s",
1474 (pLni
? "L2 Address/IP" : "Prefix"),
1475 "VN Address", "UN Address", "Cost",
1476 "Lifetime", agetype
, HVTYNL
);
1478 printed
+= rfapiPrintRemoteRegBi (bgp
, stream
, rn
, bi
);
1486 const char *type
= "prefixes";
1490 type
= "imported prefixes";
1496 type
= "prefixes in holddown";
1500 if (show_local
&& !show_remote
)
1502 type
= "locally registered prefixes";
1504 else if (!show_local
&& show_remote
)
1506 type
= "remotely registered prefixes";
1511 fp (out
, "Displayed %d out of %d %s%s",
1512 printed
, total
, type
, HVTYNL
);
1513 #if DEBUG_SHOW_EXTRA
1514 fp(out
, "IT table above: it=%p%s", it
, HVTYNL
);
1523 * rfapiShowRemoteRegistrations
1525 * Similar to rfapiShowImportTable() above. This function
1526 * is mean to produce the "remote" portion of the output
1527 * of "show vnc registrations".
1530 rfapiShowRemoteRegistrations (
1532 struct prefix
*prefix_only
,
1540 struct rfapi_import_table
*it
;
1543 bgp
= bgp_get_default ();
1555 for (it
= h
->imports
; it
; it
= it
->next
)
1558 rfapiShowRemoteRegistrationsIt (bgp
, stream
, it
, prefix_only
,
1559 show_expiring
, show_local
,
1560 show_remote
, show_imported
, NULL
);
1565 void *cursor
= NULL
;
1567 uintptr_t lni_as_ptr
;
1572 skiplist_next (h
->import_mac
, (void **) &lni_as_ptr
, (void **) &it
,
1575 skiplist_next (h
->import_mac
, (void **) &lni_as_ptr
, (void **) &it
,
1579 if ((lni_as_ptr
& 0xffffffff) == lni_as_ptr
)
1581 lni
= (uint32_t) (lni_as_ptr
& 0xffffffff);
1586 rfapiShowRemoteRegistrationsIt (bgp
, stream
, it
, prefix_only
,
1587 show_expiring
, show_local
,
1588 show_remote
, show_imported
, pLni
);
1595 /*------------------------------------------
1596 * rfapiRfapiIpAddr2Str
1598 * UI helper: generate string from rfapi_ip_addr
1601 * a IP v4/v6 address
1604 * buf put string here
1605 * bufsize max space to write
1608 * NULL conversion failed
1609 * non-NULL pointer to buf
1610 --------------------------------------------*/
1612 rfapiRfapiIpAddr2Str (struct rfapi_ip_addr
*a
, char *buf
, int bufsize
)
1614 const char *rc
= NULL
;
1616 switch (a
->addr_family
)
1619 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v4
, buf
, bufsize
);
1622 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v6
, buf
, bufsize
);
1629 rfapiPrintRfapiIpAddr (void *stream
, struct rfapi_ip_addr
*a
)
1632 const char *rc
= NULL
;
1634 int (*fp
) (void *, const char *, ...);
1637 const char *vty_newline
;
1639 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1642 rc
= rfapiRfapiIpAddr2Str (a
, buf
, BUFSIZ
);
1645 fp (out
, "%s", buf
);
1649 rfapiRfapiIpPrefix2Str (struct rfapi_ip_prefix
*p
, char *buf
, int bufsize
)
1651 struct rfapi_ip_addr
*a
= &p
->prefix
;
1652 const char *rc
= NULL
;
1654 switch (a
->addr_family
)
1657 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v4
, buf
, bufsize
);
1660 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v6
, buf
, bufsize
);
1666 int alen
= strlen (buf
);
1667 int remaining
= bufsize
- alen
- 1;
1672 slen
= snprintf (buf
+ alen
, remaining
, "/%u", p
->length
);
1673 if (slen
< remaining
) /* see man page for snprintf(3) */
1682 rfapiPrintRfapiIpPrefix (void *stream
, struct rfapi_ip_prefix
*p
)
1687 int (*fp
) (void *, const char *, ...);
1690 const char *vty_newline
;
1692 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1695 rc
= rfapiRfapiIpPrefix2Str (p
, buf
, BUFSIZ
);
1698 fp (out
, "%s:%u", buf
, p
->cost
);
1704 rfapiPrintRd (struct vty
*vty
, struct prefix_rd
*prd
)
1709 prefix_rd2str (prd
, buf
, BUFSIZ
);
1710 buf
[BUFSIZ
- 1] = 0;
1711 vty_out (vty
, "%s", buf
);
1715 rfapiPrintAdvertisedInfo (
1717 struct rfapi_descriptor
*rfd
,
1721 afi_t afi
; /* of the VN address */
1722 struct bgp_node
*bn
;
1723 struct bgp_info
*bi
;
1724 uint8_t type
= ZEBRA_ROUTE_BGP
;
1727 struct prefix_rd prd0
;
1728 struct prefix_rd
*prd
;
1731 * Find the bgp_info in the RIB corresponding to this
1735 afi
= family2afi (p
->family
);
1736 assert (afi
== AFI_IP
|| afi
== AFI_IP6
);
1738 bgp
= bgp_get_default (); /* assume 1 instance for now */
1741 if (safi
== SAFI_ENCAP
)
1743 memset (&prd0
, 0, sizeof (prd0
));
1744 prd0
.family
= AF_UNSPEC
;
1745 prd0
.prefixlen
= 64;
1752 bn
= bgp_afi_node_get (bgp
->rib
[afi
][safi
], afi
, safi
, p
, prd
);
1754 vty_out (vty
, " bn=%p%s", bn
, HVTYNL
);
1756 for (bi
= bn
->info
; bi
; bi
= bi
->next
)
1758 if (bi
->peer
== rfd
->peer
&&
1760 bi
->sub_type
== BGP_ROUTE_RFP
&&
1761 bi
->extra
&& bi
->extra
->vnc
.export
.rfapi_handle
== (void *) rfd
)
1764 rfapiPrintBi (vty
, bi
);
1771 vty_out (vty
, " --?--%s", HVTYNL
);
1778 rfapiPrintDescriptor (struct vty
*vty
, struct rfapi_descriptor
*rfd
)
1780 /* pHD un-addr vn-addr pCB cookie rd lifetime */
1781 /* RT export list */
1782 /* RT import list */
1783 /* list of advertised prefixes */
1784 /* dump import table */
1790 struct rfapi_adb
*adb
;
1793 vty_out (vty
, "%-10p ", rfd
);
1794 rfapiPrintRfapiIpAddr (vty
, &rfd
->un_addr
);
1796 rfapiPrintRfapiIpAddr (vty
, &rfd
->vn_addr
);
1797 vty_out (vty
, " %p %p ", rfd
->response_cb
, rfd
->cookie
);
1798 rfapiPrintRd (vty
, &rfd
->rd
);
1799 vty_out (vty
, " %d", rfd
->response_lifetime
);
1800 vty_out (vty
, " %s", (rfd
->rfg
? rfd
->rfg
->name
: "<orphaned>"));
1801 vty_out (vty
, "%s", HVTYNL
);
1803 vty_out (vty
, " Peer %p #%d%s", rfd
->peer
, rfd
->peer
->lock
, HVTYNL
);
1805 /* export RT list */
1806 if (rfd
->rt_export_list
)
1809 ecommunity_ecom2str (rfd
->rt_export_list
,
1810 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
1811 vty_out (vty
, " Export %s%s", s
, HVTYNL
);
1812 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1816 vty_out (vty
, " Export (nil)%s", HVTYNL
);
1819 /* import RT list */
1820 if (rfd
->import_table
)
1822 s
= ecommunity_ecom2str (rfd
->import_table
->rt_import_list
,
1823 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
1824 vty_out (vty
, " Import %s%s", s
, HVTYNL
);
1825 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1829 vty_out (vty
, " Import (nil)%s", HVTYNL
);
1832 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
)
1836 family
= afi2family (afi
);
1842 skiplist_next (rfd
->advertised
.ipN_by_prefix
, NULL
, (void **) &adb
,
1845 skiplist_next (rfd
->advertised
.ipN_by_prefix
, NULL
, (void **) &adb
,
1849 /* group like family prefixes together in output */
1850 if (family
!= adb
->u
.s
.prefix_ip
.family
)
1853 prefix2str (&adb
->u
.s
.prefix_ip
, buf
, BUFSIZ
);
1854 buf
[BUFSIZ
- 1] = 0; /* guarantee NUL-terminated */
1856 vty_out (vty
, " Adv Pfx: %s%s", buf
, HVTYNL
);
1857 rfapiPrintAdvertisedInfo (vty
, rfd
, SAFI_MPLS_VPN
, &adb
->u
.s
.prefix_ip
);
1861 skiplist_next (rfd
->advertised
.ip0_by_ether
, NULL
, (void **) &adb
,
1864 skiplist_next (rfd
->advertised
.ip0_by_ether
, NULL
, (void **) &adb
,
1868 prefix2str (&adb
->u
.s
.prefix_eth
, buf
, BUFSIZ
);
1869 buf
[BUFSIZ
- 1] = 0; /* guarantee NUL-terminated */
1871 vty_out (vty
, " Adv Pfx: %s%s", buf
, HVTYNL
);
1873 /* TBD update the following function to print ethernet info */
1874 /* Also need to pass/use rd */
1875 rfapiPrintAdvertisedInfo (vty
, rfd
, SAFI_MPLS_VPN
, &adb
->u
.s
.prefix_ip
);
1877 vty_out (vty
, "%s", HVTYNL
);
1881 * test scripts rely on first line for each nve starting in 1st column,
1882 * leading whitespace for additional detail of that nve
1885 rfapiPrintMatchingDescriptors (struct vty
*vty
,
1886 struct prefix
*vn_prefix
,
1887 struct prefix
*un_prefix
)
1891 struct listnode
*ln
;
1892 struct rfapi_descriptor
*rfd
;
1895 bgp
= bgp_get_default (); /* assume 1 instance for now */
1902 for (ln
= listhead (&h
->descriptors
); ln
; ln
= listnextnode (ln
))
1904 rfd
= listgetdata (ln
);
1910 assert (!rfapiRaddr2Qprefix (&rfd
->vn_addr
, &pfx
));
1911 if (!prefix_match (vn_prefix
, &pfx
))
1917 assert (!rfapiRaddr2Qprefix (&rfd
->un_addr
, &pfx
));
1918 if (!prefix_match (un_prefix
, &pfx
))
1924 /* print column header */
1926 "%s %s %s %s %s %s %s %s%s",
1927 "descriptor", "un-addr", "vn-addr", "callback", "cookie",
1928 "RD", "lifetime", "group", HVTYNL
);
1930 rfapiPrintDescriptor (vty
, rfd
);
1937 * Parse an address and put into a struct prefix
1940 rfapiCliGetPrefixAddr (struct vty
*vty
, const char *str
, struct prefix
*p
)
1942 if (!str2prefix (str
, p
))
1944 vty_out (vty
, "Malformed address \"%s\"%s", str
, HVTYNL
);
1950 if (p
->prefixlen
!= 32)
1952 vty_out (vty
, "Not a host address: \"%s\"%s", str
, HVTYNL
);
1957 if (p
->prefixlen
!= 128)
1959 vty_out (vty
, "Not a host address: \"%s\"%s", str
, HVTYNL
);
1964 vty_out (vty
, "Invalid address \"%s\"%s", str
, HVTYNL
);
1971 rfapiCliGetRfapiIpAddr (
1974 struct rfapi_ip_addr
*hai
)
1979 rc
= rfapiCliGetPrefixAddr (vty
, str
, &pfx
);
1983 hai
->addr_family
= pfx
.family
;
1984 if (pfx
.family
== AF_INET
)
1985 hai
->addr
.v4
= pfx
.u
.prefix4
;
1987 hai
->addr
.v6
= pfx
.u
.prefix6
;
1993 * Note: this function does not flush vty output, so if it is called
1994 * with a stream pointing to a vty, the user will have to type something
1995 * before the callback output shows up
1998 rfapiPrintNhl (void *stream
, struct rfapi_next_hop_entry
*next_hops
)
2000 struct rfapi_next_hop_entry
*nh
;
2003 int (*fp
) (void *, const char *, ...);
2006 const char *vty_newline
;
2008 #define REMAIN (BUFSIZ - (p-line))
2009 #define INCP {p += (r > REMAIN)? REMAIN: r;}
2012 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
2015 for (nh
= next_hops
, count
= 1; nh
; nh
= nh
->next
, ++count
)
2022 r
= snprintf (p
, REMAIN
, "%3d pfx=", count
);
2025 if (rfapiRfapiIpPrefix2Str (&nh
->prefix
, p
, REMAIN
))
2027 /* it fit, so count length */
2037 r
= snprintf (p
, REMAIN
, ", un=");
2040 if (rfapiRfapiIpAddr2Str (&nh
->un_address
, p
, REMAIN
))
2042 /* it fit, so count length */
2052 r
= snprintf (p
, REMAIN
, ", vn=");
2055 if (rfapiRfapiIpAddr2Str (&nh
->vn_address
, p
, REMAIN
))
2057 /* it fit, so count length */
2068 line
[BUFSIZ
- 1] = 0;
2069 fp (out
, "%s%s", line
, HVTYNL
);
2076 struct rfapi_vn_option
*vo
;
2077 char offset
[] = " ";
2079 for (vo
= nh
->vn_options
; vo
; vo
= vo
->next
)
2085 case RFAPI_VN_OPTION_TYPE_L2ADDR
:
2086 rfapiEthAddr2Str (&vo
->v
.l2addr
.macaddr
, pbuf
,
2088 fp (out
, "%sL2 %s LBL=0x%06x NETID=0x%06x NVEID=%d%s",
2089 offset
, pbuf
, (vo
->v
.l2addr
.label
& 0x00ffffff),
2090 (vo
->v
.l2addr
.logical_net_id
& 0x00ffffff),
2091 vo
->v
.l2addr
.local_nve_id
, HVTYNL
);
2094 case RFAPI_VN_OPTION_TYPE_LOCAL_NEXTHOP
:
2095 prefix2str (&vo
->v
.local_nexthop
.addr
, pbuf
, sizeof (pbuf
));
2096 fp (out
, "%sLNH %s cost=%d%s",
2097 offset
, pbuf
, vo
->v
.local_nexthop
.cost
, HVTYNL
);
2101 fp (out
, "%svn option type %d (unknown)%s",
2102 offset
, vo
->type
, HVTYNL
);
2109 struct rfapi_un_option
*uo
;
2110 char offset
[] = " ";
2112 for (uo
= nh
->un_options
; uo
; uo
= uo
->next
)
2116 case RFAPI_UN_OPTION_TYPE_TUNNELTYPE
:
2117 rfapi_print_tunneltype_option (stream
, 8, &uo
->v
.tunnel
);
2120 fp (out
, "%sUN Option type %d%s",
2121 offset
, uo
->type
, vty_newline
);
2130 /***********************************************************************
2132 ***********************************************************************/
2135 * Add another nexthop to the NHL
2138 rfapiAddDeleteLocalRfpPrefix (
2139 struct rfapi_ip_addr
*un_addr
,
2140 struct rfapi_ip_addr
*vn_addr
,
2141 struct rfapi_ip_prefix
*rprefix
,
2143 uint32_t lifetime
, /* add only */
2144 struct rfapi_vn_option
*vn_options
,
2145 struct rfapi_next_hop_entry
**head
,
2146 struct rfapi_next_hop_entry
**tail
)
2148 struct rfapi_next_hop_entry
*new;
2154 new = XCALLOC (MTYPE_RFAPI_NEXTHOP
, sizeof (struct rfapi_next_hop_entry
));
2155 new->prefix
= *rprefix
;
2156 new->un_address
= *un_addr
;
2157 new->vn_address
= *vn_addr
;
2159 new->vn_options
= vn_options
;
2162 new->lifetime
= lifetime
;
2166 new->lifetime
= RFAPI_REMOVE_RESPONSE_LIFETIME
;
2170 (*tail
)->next
= new;
2182 struct cmd_token
*carg_prefix
,
2183 struct cmd_token
*carg_vn
,
2184 struct cmd_token
*carg_un
,
2185 struct cmd_token
*carg_cost
, /* optional */
2186 struct cmd_token
*carg_lifetime
, /* optional */
2187 struct cmd_token
*carg_macaddr
, /* optional */
2188 struct cmd_token
*carg_vni
, /* mac present=>mandatory Virtual Network ID */
2190 struct cmd_token
**argv
)
2192 const char *arg_prefix
= carg_prefix
? carg_prefix
->arg
: NULL
;
2193 const char *arg_vn
= carg_vn
? carg_vn
->arg
: NULL
;
2194 const char *arg_un
= carg_un
? carg_un
->arg
: NULL
;
2195 const char *arg_cost
= carg_cost
? carg_cost
->arg
: NULL
;
2196 const char *arg_lifetime
= carg_lifetime
? carg_lifetime
->arg
: NULL
;
2197 const char *arg_macaddr
= carg_macaddr
? carg_macaddr
->arg
: NULL
;
2198 const char *arg_vni
= carg_vni
? carg_vni
->arg
: NULL
;
2199 struct rfapi_ip_addr vn_address
;
2200 struct rfapi_ip_addr un_address
;
2202 struct rfapi_ip_prefix rpfx
;
2207 struct rfapi_vn_option optary
[10]; /* XXX must be big enough */
2208 struct rfapi_vn_option
*opt
= NULL
;
2211 int rc
= CMD_WARNING
;
2215 struct rfapi_cfg
*rfapi_cfg
;
2217 const char *arg_lnh
= NULL
;
2218 const char *arg_lnh_cost
= NULL
;
2220 bgp
= bgp_get_default (); /* assume 1 instance for now */
2224 vty_outln (vty
, "BGP not configured");
2229 rfapi_cfg
= bgp
->rfapi_cfg
;
2230 if (!h
|| !rfapi_cfg
)
2233 vty_outln (vty
, "RFAPI not configured");
2237 for (; argc
; --argc
, ++argv
)
2239 if (strmatch(argv
[0]->text
, "local-next-hop"))
2243 vty_outln (vty
,"local-next-hop specified more than once");
2248 vty_outln (vty
,"Missing parameter for local-next-hop");
2252 arg_lnh
= argv
[0]->arg
;
2254 if (strmatch(argv
[0]->text
, "local-cost"))
2258 vty_outln (vty
,"local-cost specified more than once");
2263 vty_outln (vty
,"Missing parameter for local-cost");
2267 arg_lnh_cost
= argv
[0]->arg
;
2271 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_vn
, &vn_address
)))
2273 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_un
, &un_address
)))
2276 /* arg_prefix is optional if mac address is given */
2277 if (arg_macaddr
&& !arg_prefix
)
2280 * fake up a 0/32 or 0/128 prefix
2282 switch (vn_address
.addr_family
)
2285 arg_prefix
= "0.0.0.0/32";
2288 arg_prefix
= "0::0/128";
2291 vty_outln (vty
,"Internal error, unknown VN address family");
2297 if (!str2prefix (arg_prefix
, &pfx
))
2299 vty_outln (vty
, "Malformed prefix \"%s\"",arg_prefix
);
2302 if (pfx
.family
!= AF_INET
2303 && pfx
.family
!= AF_INET6
)
2305 vty_outln (vty
, "prefix \"%s\" has invalid address family",
2311 memset (optary
, 0, sizeof (optary
));
2316 cost
= strtoul (arg_cost
, &endptr
, 10);
2317 if (*endptr
!= '\0' || cost
> 255)
2319 vty_outln (vty
, "%% Invalid %s value", "cost");
2330 if (!strcmp (arg_lifetime
, "infinite"))
2332 lifetime
= RFAPI_INFINITE_LIFETIME
;
2337 lifetime
= strtoul (arg_lifetime
, &endptr
, 10);
2338 if (*endptr
!= '\0')
2340 vty_outln (vty
, "%% Invalid %s value","lifetime");
2347 lifetime
= RFAPI_INFINITE_LIFETIME
; /* default infinite */
2355 "%% %s may only be specified with local-next-hop",
2360 lnh_cost
= strtoul (arg_lnh_cost
, &endptr
, 10);
2361 if (*endptr
!= '\0' || lnh_cost
> 255)
2363 vty_outln (vty
, "%% Invalid %s value","local-cost");
2376 vty_outln (vty
, "%% %s may only be specified with prefix",
2380 if ((rc
= rfapiCliGetPrefixAddr (vty
, arg_lnh
,
2381 &optary
[opt_next
].v
.
2382 local_nexthop
.addr
)))
2388 optary
[opt_next
].v
.local_nexthop
.cost
= lnh_cost
;
2389 optary
[opt_next
].type
= RFAPI_VN_OPTION_TYPE_LOCAL_NEXTHOP
;
2393 optary
[opt_next
- 1].next
= optary
+ opt_next
;
2402 if (arg_vni
&& !arg_macaddr
)
2404 vty_outln (vty
, "%% %s may only be specified with mac address",
2405 "virtual-network-identifier");
2414 "Missing \"vni\" parameter (mandatory with mac)");
2417 optary
[opt_next
].v
.l2addr
.logical_net_id
= strtoul(arg_vni
, NULL
,
2420 if ((rc
= rfapiStr2EthAddr (arg_macaddr
,
2421 &optary
[opt_next
].v
.l2addr
.macaddr
)))
2423 vty_outln (vty
, "Invalid %s value","mac address");
2426 /* TBD label, NVE ID */
2428 optary
[opt_next
].type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
2432 optary
[opt_next
- 1].next
= optary
+ opt_next
;
2441 vnc_zlog_debug_verbose
2442 ("%s: vn=%s, un=%s, prefix=%s, cost=%s, lifetime=%s, lnh=%s",
2443 __func__
, arg_vn
, arg_un
, arg_prefix
,
2444 (arg_cost
? arg_cost
: "NULL"),
2445 (arg_lifetime
? arg_lifetime
: "NULL"),
2446 (arg_lnh
? arg_lnh
: "NULL"));
2448 rfapiQprefix2Rprefix (&pfx
, &rpfx
);
2450 rpfx
.cost
= cost
& 255;
2452 /* look up rf descriptor, call open if it doesn't exist */
2454 rfapi_find_rfd (bgp
, &vn_address
, &un_address
,
2455 (struct rfapi_descriptor
**) &rfd
);
2460 struct rfapi_un_option uo
;
2463 * flag descriptor as provisionally opened for static route
2464 * registration so that we can fix up the other parameters
2465 * when the real open comes along
2467 memset (&uo
, 0, sizeof (uo
));
2468 uo
.type
= RFAPI_UN_OPTION_TYPE_PROVISIONAL
;
2470 rc
= rfapi_open (rfapi_get_rfp_start_val_by_bgp (bgp
), &vn_address
, &un_address
, &uo
, /* flags */
2471 NULL
, NULL
, /* no userdata */
2475 vty_outln (vty
, "Can't open session for this NVE: %s",
2476 rfapi_error_str(rc
));
2483 vty_outln (vty
, "Can't find session for this NVE: %s",
2484 rfapi_error_str(rc
));
2490 rfapi_register (rfd
, &rpfx
, lifetime
, NULL
, opt
, RFAPI_REGISTER_ADD
);
2493 struct rfapi_next_hop_entry
*head
= NULL
;
2494 struct rfapi_next_hop_entry
*tail
= NULL
;
2495 struct rfapi_vn_option
*vn_opt_new
;
2497 vnc_zlog_debug_verbose ("%s: rfapi_register succeeded, returning 0", __func__
);
2499 if (h
->rfp_methods
.local_cb
)
2501 struct rfapi_descriptor
*r
= (struct rfapi_descriptor
*) rfd
;
2502 vn_opt_new
= rfapi_vn_options_dup (opt
);
2504 rfapiAddDeleteLocalRfpPrefix (&r
->un_addr
, &r
->vn_addr
, &rpfx
,
2505 1, lifetime
, vn_opt_new
, &head
,
2509 h
->flags
|= RFAPI_INCALLBACK
;
2510 (*h
->rfp_methods
.local_cb
) (head
, r
->cookie
);
2511 h
->flags
&= ~RFAPI_INCALLBACK
;
2518 vnc_zlog_debug_verbose ("%s: rfapi_register failed", __func__
);
2519 vty_out (vty
, VTYNL
);
2520 vty_outln (vty
, "Registration failed.");
2522 "Confirm that either the VN or UN address matches a configured NVE group.");
2526 vnc_zlog_debug_verbose ("%s: fail, rc=%d", __func__
, rc
);
2530 /************************************************************************
2531 * Add prefix With LNH_OPTIONS...
2532 ************************************************************************/
2533 DEFUN (add_vnc_prefix_cost_life_lnh
,
2534 add_vnc_prefix_cost_life_lnh_cmd
,
2535 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> cost (0-255) lifetime (1-4294967295) LNH_OPTIONS...",
2536 "Add registration\n"
2538 "Add/modify prefix related information\n"
2541 "VN address of NVE\n"
2542 "VN IPv4 interface address\n"
2543 "VN IPv6 interface address\n"
2544 "UN address of NVE\n"
2545 "UN IPv4 interface address\n"
2546 "UN IPv6 interface address\n"
2547 "Administrative cost [default: 255]\n"
2548 "Administrative cost\n"
2549 "Registration lifetime [default: infinite]\n"
2550 "Lifetime value in seconds\n"
2551 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2553 /* pfx vn un cost life */
2554 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], argv
[11],
2556 NULL
, NULL
, argc
- 12, argv
+ 12);
2559 DEFUN (add_vnc_prefix_life_cost_lnh
,
2560 add_vnc_prefix_life_cost_lnh_cmd
,
2561 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> lifetime (1-4294967295) cost (0-255) LNH_OPTIONS...",
2562 "Add registration\n"
2564 "Add/modify prefix related information\n"
2567 "VN address of NVE\n"
2568 "VN IPv4 interface address\n"
2569 "VN IPv6 interface address\n"
2570 "UN address of NVE\n"
2571 "UN IPv4 interface address\n"
2572 "UN IPv6 interface address\n"
2573 "Registration lifetime [default: infinite]\n"
2574 "Lifetime value in seconds\n"
2575 "Administrative cost [default: 255]\n"
2576 "Administrative cost\n"
2577 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2579 /* pfx vn un cost life */
2580 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[11], argv
[9],
2582 NULL
, NULL
, argc
- 12, argv
+ 12);
2585 DEFUN (add_vnc_prefix_cost_lnh
,
2586 add_vnc_prefix_cost_lnh_cmd
,
2587 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> cost (0-255) LNH_OPTIONS...",
2588 "Add registration\n"
2590 "Add/modify prefix related information\n"
2593 "VN address of NVE\n"
2594 "VN IPv4 interface address\n"
2595 "VN IPv6 interface address\n"
2596 "UN address of NVE\n"
2597 "UN IPv4 interface address\n"
2598 "UN IPv6 interface address\n"
2599 "Administrative cost [default: 255]\n"
2600 "Administrative cost\n"
2601 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2603 /* pfx vn un cost life */
2604 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], NULL
,
2606 NULL
, NULL
, argc
- 10, argv
+ 10);
2609 DEFUN (add_vnc_prefix_life_lnh
,
2610 add_vnc_prefix_life_lnh_cmd
,
2611 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> lifetime (1-4294967295) LNH_OPTIONS...",
2612 "Add registration\n"
2614 "Add/modify prefix related information\n"
2617 "VN address of NVE\n"
2618 "VN IPv4 interface address\n"
2619 "VN IPv6 interface address\n"
2620 "UN address of NVE\n"
2621 "UN IPv4 interface address\n"
2622 "UN IPv6 interface address\n"
2623 "Registration lifetime [default: infinite]\n"
2624 "Lifetime value in seconds\n"
2625 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2627 /* pfx vn un cost life */
2628 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, argv
[9],
2630 NULL
, NULL
, argc
- 10, argv
+ 10);
2633 DEFUN (add_vnc_prefix_lnh
,
2634 add_vnc_prefix_lnh_cmd
,
2635 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> LNH_OPTIONS...",
2636 "Add registration\n"
2638 "Add/modify prefix related information\n"
2641 "VN address of NVE\n"
2642 "VN IPv4 interface address\n"
2643 "VN IPv6 interface address\n"
2644 "UN address of NVE\n"
2645 "UN IPv4 interface address\n"
2646 "UN IPv6 interface address\n"
2647 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2649 /* pfx vn un cost life */
2650 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, NULL
,
2652 NULL
, NULL
, argc
- 8, argv
+ 8);
2655 /************************************************************************
2656 * Add prefix Without LNH_OPTIONS...
2657 ************************************************************************/
2658 DEFUN (add_vnc_prefix_cost_life
,
2659 add_vnc_prefix_cost_life_cmd
,
2660 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> cost (0-255) lifetime (1-4294967295)",
2661 "Add registration\n"
2663 "Add/modify prefix related information\n"
2666 "VN address of NVE\n"
2667 "VN IPv4 interface address\n"
2668 "VN IPv6 interface address\n"
2669 "UN address of NVE\n"
2670 "UN IPv4 interface address\n"
2671 "UN IPv6 interface address\n"
2672 "Administrative cost [default: 255]\n"
2673 "Administrative cost\n"
2674 "Registration lifetime [default: infinite]\n"
2675 "Lifetime value in seconds\n"
2676 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2678 /* pfx vn un cost life */
2679 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], argv
[11],
2681 NULL
, NULL
, 0, NULL
);
2684 DEFUN (add_vnc_prefix_life_cost
,
2685 add_vnc_prefix_life_cost_cmd
,
2686 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> lifetime (1-4294967295) cost (0-255)",
2687 "Add registration\n"
2689 "Add/modify prefix related information\n"
2692 "VN address of NVE\n"
2693 "VN IPv4 interface address\n"
2694 "VN IPv6 interface address\n"
2695 "UN address of NVE\n"
2696 "UN IPv4 interface address\n"
2697 "UN IPv6 interface address\n"
2698 "Registration lifetime [default: infinite]\n"
2699 "Lifetime value in seconds\n"
2700 "Administrative cost [default: 255]\n"
2701 "Administrative cost\n"
2702 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2704 /* pfx vn un cost life */
2705 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[11], argv
[9],
2707 NULL
, NULL
, 0, NULL
);
2710 DEFUN (add_vnc_prefix_cost
,
2711 add_vnc_prefix_cost_cmd
,
2712 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> cost (0-255)",
2713 "Add registration\n"
2715 "Add/modify prefix related information\n"
2718 "VN address of NVE\n"
2719 "VN IPv4 interface address\n"
2720 "VN IPv6 interface address\n"
2721 "UN address of NVE\n"
2722 "UN IPv4 interface address\n"
2723 "UN IPv6 interface address\n"
2724 "Administrative cost [default: 255]\n"
2725 "Administrative cost\n"
2726 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2728 /* pfx vn un cost life */
2729 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], NULL
,
2731 NULL
, NULL
, 0, NULL
);
2734 DEFUN (add_vnc_prefix_life
,
2735 add_vnc_prefix_life_cmd
,
2736 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> lifetime (1-4294967295)",
2737 "Add registration\n"
2739 "Add/modify prefix related information\n"
2742 "VN address of NVE\n"
2743 "VN IPv4 interface address\n"
2744 "VN IPv6 interface address\n"
2745 "UN address of NVE\n"
2746 "UN IPv4 interface address\n"
2747 "UN IPv6 interface address\n"
2748 "Registration lifetime [default: infinite]\n"
2749 "Lifetime value in seconds\n"
2750 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2752 /* pfx vn un cost life */
2753 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, argv
[9],
2755 NULL
, NULL
, 0, NULL
);
2758 DEFUN (add_vnc_prefix
,
2760 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X>",
2761 "Add registration\n"
2763 "Add/modify prefix related information\n"
2766 "VN address of NVE\n"
2767 "VN IPv4 interface address\n"
2768 "VN IPv6 interface address\n"
2769 "UN address of NVE\n"
2770 "UN IPv4 interface address\n"
2771 "UN IPv6 interface address\n"
2772 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2774 /* pfx vn un cost life */
2775 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, NULL
,
2777 NULL
, NULL
, 0, NULL
);
2780 /************************************************************************
2781 * Mac address registrations
2782 ************************************************************************/
2783 DEFUN (add_vnc_mac_vni_prefix_cost_life
,
2784 add_vnc_mac_vni_prefix_cost_life_cmd
,
2785 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> prefix <A.B.C.D/M|X:X::X:X/M> cost (0-255) lifetime (1-4294967295)",
2786 "Add registration\n"
2788 "Add/modify mac address information\n"
2790 "Virtual Network Identifier follows\n"
2791 "Virtual Network Identifier\n"
2792 "VN address of NVE\n"
2793 "VN IPv4 interface address\n"
2794 "VN IPv6 interface address\n"
2795 "UN address of NVE\n"
2796 "UN IPv4 interface address\n"
2797 "UN IPv6 interface address\n"
2798 "Add/modify prefix related information\n"
2801 "Administrative cost [default: 255]\n"
2802 "Administrative cost\n"
2803 "Registration lifetime [default: infinite]\n"
2804 "Lifetime value in seconds\n")
2806 /* pfx vn un cost life */
2807 return register_add (vty
, argv
[11], argv
[7], argv
[9], argv
[13], argv
[15],
2809 argv
[3], argv
[5], 0, NULL
);
2813 DEFUN (add_vnc_mac_vni_prefix_life
,
2814 add_vnc_mac_vni_prefix_life_cmd
,
2815 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> prefix <A.B.C.D/M|X:X::X:X/M> lifetime (1-4294967295)",
2816 "Add registration\n"
2818 "Add/modify mac address information\n"
2820 "Virtual Network Identifier follows\n"
2821 "Virtual Network Identifier\n"
2822 "VN address of NVE\n"
2823 "VN IPv4 interface address\n"
2824 "VN IPv6 interface address\n"
2825 "UN address of NVE\n"
2826 "UN IPv4 interface address\n"
2827 "UN IPv6 interface address\n"
2828 "Add/modify prefix related information\n"
2831 "Registration lifetime [default: infinite]\n"
2832 "Lifetime value in seconds\n")
2834 /* pfx vn un cost life */
2835 return register_add (vty
, argv
[11], argv
[7], argv
[9], NULL
, argv
[13],
2837 argv
[3], argv
[5], 0, NULL
);
2840 DEFUN (add_vnc_mac_vni_prefix_cost
,
2841 add_vnc_mac_vni_prefix_cost_cmd
,
2842 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> prefix <A.B.C.D/M|X:X::X:X/M> cost (0-255)",
2843 "Add registration\n"
2845 "Add/modify mac address information\n"
2847 "Virtual Network Identifier follows\n"
2848 "Virtual Network Identifier\n"
2849 "VN address of NVE\n"
2850 "VN IPv4 interface address\n"
2851 "VN IPv6 interface address\n"
2852 "UN address of NVE\n"
2853 "UN IPv4 interface address\n"
2854 "UN IPv6 interface address\n"
2855 "Add/modify prefix related information\n"
2858 "Administrative cost [default: 255]\n" "Administrative cost\n")
2860 /* pfx vn un cost life */
2861 return register_add (vty
, argv
[11], argv
[7], argv
[9], argv
[13], NULL
,
2863 argv
[3], argv
[5], 0, NULL
);
2866 DEFUN (add_vnc_mac_vni_prefix
,
2867 add_vnc_mac_vni_prefix_cmd
,
2868 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> prefix <A.B.C.D/M|X:X::X:X/M>",
2869 "Add registration\n"
2871 "Add/modify mac address information\n"
2873 "Virtual Network Identifier follows\n"
2874 "Virtual Network Identifier\n"
2875 "VN address of NVE\n"
2876 "VN IPv4 interface address\n"
2877 "VN IPv6 interface address\n"
2878 "UN address of NVE\n"
2879 "UN IPv4 interface address\n"
2880 "UN IPv6 interface address\n"
2881 "Add/modify prefix related information\n"
2882 "IPv4 prefix\n" "IPv6 prefix\n")
2884 /* pfx vn un cost life */
2885 return register_add (vty
, argv
[11], argv
[7], argv
[9], NULL
, NULL
,
2887 argv
[3], argv
[5], 0, NULL
);
2890 DEFUN (add_vnc_mac_vni_cost_life
,
2891 add_vnc_mac_vni_cost_life_cmd
,
2892 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> cost (0-255) lifetime (1-4294967295)",
2893 "Add registration\n"
2895 "Add/modify mac address information\n"
2897 "Virtual Network Identifier follows\n"
2898 "Virtual Network Identifier\n"
2899 "VN address of NVE\n"
2900 "VN IPv4 interface address\n"
2901 "VN IPv6 interface address\n"
2902 "UN address of NVE\n"
2903 "UN IPv4 interface address\n"
2904 "UN IPv6 interface address\n"
2905 "Administrative cost [default: 255]\n"
2906 "Administrative cost\n"
2907 "Registration lifetime [default: infinite]\n"
2908 "Lifetime value in seconds\n")
2910 /* pfx vn un cost life */
2911 return register_add (vty
, NULL
, argv
[7], argv
[9], argv
[11], argv
[13],
2913 argv
[3], argv
[5], 0, NULL
);
2917 DEFUN (add_vnc_mac_vni_cost
,
2918 add_vnc_mac_vni_cost_cmd
,
2919 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> cost (0-255)",
2920 "Add registration\n"
2922 "Add/modify mac address information\n"
2924 "Virtual Network Identifier follows\n"
2925 "Virtual Network Identifier\n"
2926 "VN address of NVE\n"
2927 "VN IPv4 interface address\n"
2928 "VN IPv6 interface address\n"
2929 "UN address of NVE\n"
2930 "UN IPv4 interface address\n"
2931 "UN IPv6 interface address\n"
2932 "Administrative cost [default: 255]\n" "Administrative cost\n")
2934 /* pfx vn un cost life */
2935 return register_add (vty
, NULL
, argv
[7], argv
[9], argv
[11], NULL
,
2937 argv
[3], argv
[5], 0, NULL
);
2941 DEFUN (add_vnc_mac_vni_life
,
2942 add_vnc_mac_vni_life_cmd
,
2943 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> lifetime (1-4294967295)",
2944 "Add registration\n"
2946 "Add/modify mac address information\n"
2948 "Virtual Network Identifier follows\n"
2949 "Virtual Network Identifier\n"
2950 "VN address of NVE\n"
2951 "VN IPv4 interface address\n"
2952 "VN IPv6 interface address\n"
2953 "UN address of NVE\n"
2954 "UN IPv4 interface address\n"
2955 "UN IPv6 interface address\n"
2956 "Registration lifetime [default: infinite]\n"
2957 "Lifetime value in seconds\n")
2959 /* pfx vn un cost life */
2960 return register_add (vty
, NULL
, argv
[7], argv
[9], NULL
, argv
[11],
2962 argv
[3], argv
[5], 0, NULL
);
2966 DEFUN (add_vnc_mac_vni
,
2967 add_vnc_mac_vni_cmd
,
2968 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X>",
2969 "Add registration\n"
2971 "Add/modify mac address information\n"
2973 "Virtual Network Identifier follows\n"
2974 "Virtual Network Identifier\n"
2975 "VN address of NVE\n"
2976 "VN IPv4 interface address\n"
2977 "VN IPv6 interface address\n"
2978 "UN address of NVE\n"
2979 "UN IPv4 interface address\n" "UN IPv6 interface address\n")
2981 /* pfx vn un cost life */
2982 return register_add (vty
, NULL
, argv
[7], argv
[9], NULL
, NULL
,
2984 argv
[3], argv
[5], 0, NULL
);
2987 /************************************************************************
2989 ************************************************************************/
2991 struct rfapi_local_reg_delete_arg
2997 struct rfapi_ip_addr un_address
; /* AF==0: wildcard */
2998 struct rfapi_ip_addr vn_address
; /* AF==0: wildcard */
2999 struct prefix prefix
; /* AF==0: wildcard */
3000 struct prefix_rd rd
; /* plen!=64: wildcard */
3001 struct rfapi_nve_group_cfg
*rfg
; /* NULL: wildcard */
3003 struct rfapi_l2address_option_match l2o
;
3011 uint32_t query_count
;
3013 uint32_t failed_pfx_count
;
3016 struct skiplist
*nves
;
3018 uint32_t remote_active_nve_count
;
3019 uint32_t remote_active_pfx_count
;
3020 uint32_t remote_holddown_nve_count
;
3021 uint32_t remote_holddown_pfx_count
;
3026 struct rfapi_ip_addr vn
;
3027 struct rfapi_ip_addr un
;
3028 struct rfapi_descriptor
*rfd
;
3029 struct rfapi_local_reg_delete_arg
*cda
;
3033 nve_addr_free (void *hap
)
3035 ((struct nve_addr
*) hap
)->cda
->nve_count
+= 1;
3036 XFREE (MTYPE_RFAPI_NVE_ADDR
, hap
);
3040 nve_addr_cmp (void *k1
, void *k2
)
3042 struct nve_addr
*a
= (struct nve_addr
*) k1
;
3043 struct nve_addr
*b
= (struct nve_addr
*) k2
;
3050 if (a
->un
.addr_family
!= b
->un
.addr_family
)
3052 return (a
->un
.addr_family
- b
->un
.addr_family
);
3054 if (a
->vn
.addr_family
!= b
->vn
.addr_family
)
3056 return (a
->vn
.addr_family
- b
->vn
.addr_family
);
3058 if (a
->un
.addr_family
== AF_INET
)
3060 ret
= IPV4_ADDR_CMP (&a
->un
.addr
.v4
, &b
->un
.addr
.v4
);
3066 else if (a
->un
.addr_family
== AF_INET6
)
3068 ret
= IPV6_ADDR_CMP (&a
->un
.addr
.v6
, &b
->un
.addr
.v6
);
3078 if (a
->vn
.addr_family
== AF_INET
)
3080 ret
= IPV4_ADDR_CMP (&a
->vn
.addr
.v4
, &b
->vn
.addr
.v4
);
3084 else if (a
->vn
.addr_family
== AF_INET6
)
3086 ret
= IPV6_ADDR_CMP (&a
->vn
.addr
.v6
, &b
->vn
.addr
.v6
);
3100 parse_deleter_args (
3103 const char *arg_prefix
,
3106 const char *arg_l2addr
,
3107 const char *arg_vni
,
3109 struct rfapi_nve_group_cfg
*arg_rfg
,
3110 struct rfapi_local_reg_delete_arg
*rcdarg
)
3112 int rc
= CMD_WARNING
;
3114 memset (rcdarg
, 0, sizeof (struct rfapi_local_reg_delete_arg
));
3118 bgp
= bgp_get_default();
3120 rcdarg
->rfg
= arg_rfg
; /* may be NULL */
3122 if (arg_vn
&& strcmp (arg_vn
, "*"))
3124 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_vn
, &rcdarg
->vn_address
)))
3127 if (arg_un
&& strcmp (arg_un
, "*"))
3129 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_un
, &rcdarg
->un_address
)))
3132 if (arg_prefix
&& strcmp (arg_prefix
, "*"))
3135 if (!str2prefix (arg_prefix
, &rcdarg
->prefix
))
3137 vty_outln (vty
, "Malformed prefix \"%s\"", arg_prefix
);
3146 vty_outln (vty
, "Missing VNI");
3149 if (strcmp (arg_l2addr
, "*"))
3151 if ((rc
= rfapiStr2EthAddr (arg_l2addr
, &rcdarg
->l2o
.o
.macaddr
)))
3153 vty_outln (vty
, "Malformed L2 Address \"%s\"",
3157 rcdarg
->l2o
.flags
|= RFAPI_L2O_MACADDR
;
3159 if (strcmp (arg_vni
, "*"))
3161 rcdarg
->l2o
.o
.logical_net_id
= strtoul(arg_vni
, NULL
, 10);
3162 rcdarg
->l2o
.flags
|= RFAPI_L2O_LNI
;
3167 if (!str2prefix_rd (arg_rd
, &rcdarg
->rd
))
3169 vty_outln (vty
, "Malformed RD \"%s\"",
3179 parse_deleter_tokens (
3182 struct cmd_token
*carg_prefix
,
3183 struct cmd_token
*carg_vn
,
3184 struct cmd_token
*carg_un
,
3185 struct cmd_token
*carg_l2addr
,
3186 struct cmd_token
*carg_vni
,
3187 struct cmd_token
*carg_rd
,
3188 struct rfapi_nve_group_cfg
*arg_rfg
,
3189 struct rfapi_local_reg_delete_arg
*rcdarg
)
3191 const char *arg_prefix
= carg_prefix
? carg_prefix
->arg
: NULL
;
3192 const char *arg_vn
= carg_vn
? carg_vn
->arg
: NULL
;
3193 const char *arg_un
= carg_un
? carg_un
->arg
: NULL
;
3194 const char *arg_l2addr
= carg_l2addr
? carg_l2addr
->arg
: NULL
;
3195 const char *arg_vni
= carg_vni
? carg_vni
->arg
: NULL
;
3196 const char *arg_rd
= carg_rd
? carg_rd
->arg
: NULL
;
3197 return parse_deleter_args (vty
, bgp
,arg_prefix
, arg_vn
, arg_un
,
3198 arg_l2addr
, arg_vni
, arg_rd
,
3203 record_nve_in_cda_list (
3204 struct rfapi_local_reg_delete_arg
*cda
,
3205 struct rfapi_ip_addr
*un_address
,
3206 struct rfapi_ip_addr
*vn_address
,
3207 struct rfapi_descriptor
*rfd
)
3210 struct nve_addr
*hap
;
3212 memset (&ha
, 0, sizeof (ha
));
3213 ha
.un
= *un_address
;
3214 ha
.vn
= *vn_address
;
3218 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3220 if (skiplist_search (cda
->nves
, &ha
, (void *) &hap
))
3222 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3226 skiplist_insert (cda
->nves
, hap
, hap
);
3231 clear_vnc_responses (struct rfapi_local_reg_delete_arg
*cda
)
3234 struct rfapi_descriptor
*rfd
;
3235 int query_count
= 0;
3236 struct listnode
*node
;
3237 struct bgp
*bgp_default
= bgp_get_default ();
3239 if (cda
->vn_address
.addr_family
&& cda
->un_address
.addr_family
)
3245 (bgp_default
, &cda
->vn_address
, &cda
->un_address
, &rfd
))
3248 rfapiRibClear (rfd
);
3249 rfapi_query_done_all (rfd
, &query_count
);
3250 cda
->query_count
+= query_count
;
3253 * Track unique nves seen
3255 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3266 h
= bgp_default
->rfapi
;
3271 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3274 * match un, vn addresses of NVEs
3276 if (cda
->un_address
.addr_family
&&
3277 rfapi_ip_addr_cmp (&cda
->un_address
, &rfd
->un_addr
))
3281 if (cda
->vn_address
.addr_family
&&
3282 rfapi_ip_addr_cmp (&cda
->vn_address
, &rfd
->vn_addr
))
3287 rfapiRibClear (rfd
);
3289 rfapi_query_done_all (rfd
, &query_count
);
3290 cda
->query_count
+= query_count
;
3293 * Track unique nves seen
3295 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3300 * TBD need to count deleted prefixes and nves?
3302 * ENXIO BGP or VNC not configured
3305 rfapiDeleteLocalPrefixesByRFD (struct rfapi_local_reg_delete_arg
*cda
,
3306 struct rfapi_descriptor
*rfd
)
3308 struct rfapi_ip_addr
*pUn
; /* NULL = wildcard */
3309 struct rfapi_ip_addr
*pVn
; /* NULL = wildcard */
3310 struct prefix
*pPrefix
; /* NULL = wildcard */
3311 struct prefix_rd
*pPrd
; /* NULL = wildcard */
3313 struct rfapi_ip_prefix rprefix
;
3314 struct rfapi_next_hop_entry
*head
= NULL
;
3315 struct rfapi_next_hop_entry
*tail
= NULL
;
3318 vnc_zlog_debug_verbose ("%s: entry", __func__
);
3321 pUn
= (cda
->un_address
.addr_family
? &cda
->un_address
: NULL
);
3322 pVn
= (cda
->vn_address
.addr_family
? &cda
->vn_address
: NULL
);
3323 pPrefix
= (cda
->prefix
.family
? &cda
->prefix
: NULL
);
3324 pPrd
= (cda
->rd
.prefixlen
== 64 ? &cda
->rd
: NULL
);
3328 rfapiQprefix2Rprefix (pPrefix
, &rprefix
);
3331 do /* to preserve old code structure */
3333 struct rfapi
*h
=cda
->bgp
->rfapi
;;
3334 struct rfapi_adb
*adb
;
3336 int deleted_from_this_nve
;
3338 struct nve_addr
*hap
;
3341 vnc_zlog_debug_verbose ("%s: rfd=%p", __func__
, rfd
);
3345 * match un, vn addresses of NVEs
3347 if (pUn
&& (rfapi_ip_addr_cmp (pUn
, &rfd
->un_addr
)))
3349 if (pVn
&& (rfapi_ip_addr_cmp (pVn
, &rfd
->vn_addr
)))
3353 vnc_zlog_debug_verbose ("%s: un, vn match", __func__
);
3360 deleted_from_this_nve
= 0;
3363 struct skiplist
*sl
;
3364 struct rfapi_ip_prefix rp
;
3366 struct list
*adb_delete_list
;
3369 * The advertisements are stored in a skiplist. Withdrawing
3370 * the registration deletes the advertisement from the
3371 * skiplist, which we can't do while iterating over that
3372 * same skiplist using the current skiplist API.
3374 * Strategy: iterate over the skiplist and build another
3375 * list containing only the matching ADBs. Then delete
3376 * _everything_ in that second list (which can be done
3377 * using either skiplists or quagga linklists).
3379 adb_delete_list
= list_new ();
3382 * Advertised IP prefixes (not 0/32 or 0/128)
3384 sl
= rfd
->advertised
.ipN_by_prefix
;
3387 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3388 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3393 if (!prefix_same (pPrefix
, &adb
->u
.s
.prefix_ip
))
3396 vnc_zlog_debug_verbose ("%s: adb=%p, prefix doesn't match, skipping",
3404 if (memcmp(pPrd
->val
, adb
->u
.s
.prd
.val
, 8) != 0)
3407 vnc_zlog_debug_verbose ("%s: adb=%p, RD doesn't match, skipping",
3413 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3416 (cda
->l2o
.o
.macaddr
.octet
,
3417 adb
->u
.s
.prefix_eth
.u
.prefix_eth
.octet
, ETHER_ADDR_LEN
))
3420 vnc_zlog_debug_verbose ("%s: adb=%p, macaddr doesn't match, skipping",
3427 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3429 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3432 vnc_zlog_debug_verbose ("%s: adb=%p, LNI doesn't match, skipping",
3440 vnc_zlog_debug_verbose ("%s: ipN adding adb %p to delete list", __func__
,
3444 listnode_add (adb_delete_list
, adb
);
3447 struct listnode
*node
;
3449 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3451 int this_advertisement_prefix_count
;
3452 struct rfapi_vn_option optary
[3];
3453 struct rfapi_vn_option
*opt
= NULL
;
3456 this_advertisement_prefix_count
= 1;
3458 rfapiQprefix2Rprefix (&adb
->u
.s
.prefix_ip
, &rp
);
3460 memset (optary
, 0, sizeof (optary
));
3462 /* if mac addr present in advert, make l2o vn option */
3463 if (adb
->u
.s
.prefix_eth
.family
== AF_ETHERNET
)
3466 opt
->next
= &optary
[cur_opt
];
3467 opt
= &optary
[cur_opt
++];
3468 opt
->type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3469 opt
->v
.l2addr
.macaddr
= adb
->u
.s
.prefix_eth
.u
.prefix_eth
;
3470 ++this_advertisement_prefix_count
;
3473 * use saved RD value instead of trying to invert
3474 * complex RD computation in rfapi_register()
3477 opt
->next
= &optary
[cur_opt
];
3478 opt
= &optary
[cur_opt
++];
3479 opt
->type
= RFAPI_VN_OPTION_TYPE_INTERNAL_RD
;
3480 opt
->v
.internal_rd
= adb
->u
.s
.prd
;
3483 vnc_zlog_debug_verbose ("%s: ipN killing reg from adb %p ", __func__
, adb
);
3486 rc
= rfapi_register (rfd
, &rp
, 0, NULL
,
3487 (cur_opt
? optary
: NULL
), RFAPI_REGISTER_KILL
);
3490 cda
->pfx_count
+= this_advertisement_prefix_count
;
3491 cda
->reg_count
+= 1;
3492 deleted_from_this_nve
= 1;
3494 if (h
->rfp_methods
.local_cb
)
3496 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
, &rfd
->vn_addr
,
3497 &rp
, 0, 0, NULL
, &head
, &tail
);
3500 list_delete_all_node (adb_delete_list
);
3502 if (!(pPrefix
&& !RFAPI_0_PREFIX (pPrefix
)))
3507 * Caller didn't specify a prefix, or specified (0/32 or 0/128)
3511 * Advertised 0/32 and 0/128 (indexed by ethernet address)
3513 sl
= rfd
->advertised
.ip0_by_ether
;
3516 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3517 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3520 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3522 if (memcmp (cda
->l2o
.o
.macaddr
.octet
,
3523 adb
->u
.s
.prefix_eth
.u
.prefix_eth
.octet
,
3530 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3532 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3538 vnc_zlog_debug_verbose ("%s: ip0 adding adb %p to delete list",
3541 listnode_add (adb_delete_list
, adb
);
3545 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3548 struct rfapi_vn_option vn
;
3550 rfapiQprefix2Rprefix (&adb
->u
.s
.prefix_ip
, &rp
);
3552 memset (&vn
, 0, sizeof (vn
));
3553 vn
.type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3554 vn
.v
.l2addr
= adb
->l2o
;
3557 vnc_zlog_debug_verbose ("%s: ip0 killing reg from adb %p ",
3561 rc
= rfapi_register (rfd
, &rp
, 0, NULL
, &vn
,
3562 RFAPI_REGISTER_KILL
);
3565 cda
->pfx_count
+= 1;
3566 cda
->reg_count
+= 1;
3567 deleted_from_this_nve
= 1;
3569 if (h
->rfp_methods
.local_cb
)
3571 struct rfapi_vn_option
*vn_opt_new
;
3573 vn_opt_new
= rfapi_vn_options_dup (&vn
);
3574 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
,
3575 &rfd
->vn_addr
, &rp
, 0, 0,
3576 vn_opt_new
, &head
, &tail
);
3579 list_delete_all_node (adb_delete_list
);
3581 list_delete (adb_delete_list
);
3586 { /* should not be set if (NULL == rfapi_cfg->local_cb) */
3587 h
->flags
|= RFAPI_INCALLBACK
;
3588 (*h
->rfp_methods
.local_cb
) (head
, rfd
->cookie
);
3589 h
->flags
&= ~RFAPI_INCALLBACK
;
3593 if (deleted_from_this_nve
)
3596 * track unique NVEs seen
3598 memset (&ha
, 0, sizeof (ha
));
3599 ha
.un
= rfd
->un_addr
;
3600 ha
.vn
= rfd
->vn_addr
;
3603 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3604 if (skiplist_search (cda
->nves
, &ha
, (void **) &hap
))
3606 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3610 skiplist_insert (cda
->nves
, hap
, hap
);
3613 } while (0); /* to preserve old code structure */
3619 rfapiDeleteLocalPrefixes (struct rfapi_local_reg_delete_arg
*cda
)
3625 if (cda
->rfg
->rfd
) /* if not open, nothing to delete */
3626 rc
= rfapiDeleteLocalPrefixesByRFD (cda
, cda
->rfg
->rfd
);
3630 struct bgp
*bgp
= cda
->bgp
;
3632 struct rfapi_cfg
*rfapi_cfg
;
3634 struct listnode
*node
;
3635 struct rfapi_descriptor
*rfd
;
3639 rfapi_cfg
= bgp
->rfapi_cfg
;
3640 if (!h
|| !rfapi_cfg
)
3642 vnc_zlog_debug_verbose ("%s: starting descriptor loop", __func__
);
3643 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3645 rc
= rfapiDeleteLocalPrefixesByRFD (cda
, rfd
);
3654 * Deletes local and remote prefixes that match
3657 clear_vnc_prefix (struct rfapi_local_reg_delete_arg
*cda
)
3659 struct prefix pfx_un
;
3660 struct prefix pfx_vn
;
3662 struct prefix
*pUN
= NULL
;
3663 struct prefix
*pVN
= NULL
;
3664 struct prefix
*pPrefix
= NULL
;
3666 struct rfapi_import_table
*it
= NULL
;
3669 * Delete matching remote prefixes in holddown
3671 if (cda
->vn_address
.addr_family
)
3673 if (!rfapiRaddr2Qprefix (&cda
->vn_address
, &pfx_vn
))
3676 if (cda
->un_address
.addr_family
)
3678 if (!rfapiRaddr2Qprefix (&cda
->un_address
, &pfx_un
))
3681 if (cda
->prefix
.family
)
3683 pPrefix
= &cda
->prefix
;
3687 it
= cda
->rfg
->rfapi_import_table
;
3689 rfapiDeleteRemotePrefixes (pUN
, pVN
, pPrefix
, it
,
3690 0, 1, &cda
->remote_active_pfx_count
,
3691 &cda
->remote_active_nve_count
,
3692 &cda
->remote_holddown_pfx_count
,
3693 &cda
->remote_holddown_nve_count
);
3696 * Now do local prefixes
3698 rfapiDeleteLocalPrefixes (cda
);
3702 print_cleared_stats (struct rfapi_local_reg_delete_arg
*cda
)
3704 struct vty
*vty
= cda
->vty
; /* for benefit of VTYNL */
3706 /* Our special element-deleting function counts nves */
3709 skiplist_free (cda
->nves
);
3712 if (cda
->failed_pfx_count
)
3713 vty_outln (vty
, "Failed to delete %d prefixes",
3714 cda
->failed_pfx_count
);
3716 /* left as "prefixes" even in single case for ease of machine parsing */
3718 "[Local] Cleared %u registrations, %u prefixes, %u responses from %d NVEs",
3719 cda
->reg_count
, cda
->pfx_count
, cda
->query_count
,cda
->nve_count
);
3722 * We don't currently allow deletion of active remote prefixes from
3726 vty_outln (vty
, "[Holddown] Cleared %u prefixes from %u NVEs",
3727 cda
->remote_holddown_pfx_count
,cda
->remote_holddown_nve_count
);
3731 * Caller has already deleted registrations and queries for this/these
3732 * NVEs. Now we just have to close their descriptors.
3735 clear_vnc_nve_closer (struct rfapi_local_reg_delete_arg
*cda
)
3737 struct skiplist
*sl
= cda
->nves
; /* contains affected NVEs */
3738 struct nve_addr
*pKey
;
3739 struct nve_addr
*pValue
;
3740 void *cursor
= NULL
;
3746 for (rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
);
3748 rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
))
3753 ((struct rfapi_descriptor
*) pValue
->rfd
)->flags
|=
3754 RFAPI_HD_FLAG_CLOSING_ADMINISTRATIVELY
;
3755 rfapi_close (pValue
->rfd
);
3760 DEFUN (clear_vnc_nve_all
,
3761 clear_vnc_nve_all_cmd
,
3765 "Clear per NVE information\n"
3769 struct rfapi_local_reg_delete_arg cda
;
3772 if ((rc
= parse_deleter_args (vty
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
3777 clear_vnc_responses (&cda
);
3778 clear_vnc_prefix (&cda
);
3779 clear_vnc_nve_closer (&cda
);
3781 print_cleared_stats (&cda
);
3786 DEFUN (clear_vnc_nve_vn_un
,
3787 clear_vnc_nve_vn_un_cmd
,
3788 "clear vnc nve vn <*|A.B.C.D|X:X::X:X> un <*|A.B.C.D|X:X::X:X>",
3791 "Clear prefix registration information\n"
3792 "VN address of NVE\n"
3794 "VN IPv4 interface address\n"
3795 "VN IPv6 interface address\n"
3796 "UN address of NVE\n"
3797 "For all UN addresses\n"
3798 "UN IPv4 interface address\n"
3799 "UN IPv6 interface address\n")
3801 struct rfapi_local_reg_delete_arg cda
;
3805 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[4], argv
[6], NULL
, NULL
, NULL
, NULL
, &cda
)))
3810 clear_vnc_responses (&cda
);
3811 clear_vnc_prefix (&cda
);
3812 clear_vnc_nve_closer (&cda
);
3814 print_cleared_stats (&cda
);
3819 DEFUN (clear_vnc_nve_un_vn
,
3820 clear_vnc_nve_un_vn_cmd
,
3821 "clear vnc nve un <*|A.B.C.D|X:X::X:X> vn <*|A.B.C.D|X:X::X:X>",
3824 "Clear prefix registration information\n"
3825 "UN address of NVE\n"
3827 "UN IPv4 interface address\n"
3828 "UN IPv6 interface address\n"
3829 "VN address of NVE\n"
3831 "VN IPv4 interface address\n"
3832 "VN IPv6 interface address\n")
3834 struct rfapi_local_reg_delete_arg cda
;
3838 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[6], argv
[4], NULL
, NULL
, NULL
, NULL
, &cda
)))
3843 clear_vnc_responses (&cda
);
3844 clear_vnc_prefix (&cda
);
3845 clear_vnc_nve_closer (&cda
);
3847 print_cleared_stats (&cda
);
3852 DEFUN (clear_vnc_nve_vn
,
3853 clear_vnc_nve_vn_cmd
,
3854 "clear vnc nve vn <*|A.B.C.D|X:X::X:X>",
3857 "Clear prefix registration information\n"
3858 "VN address of NVE\n"
3860 "VN IPv4 interface address\n"
3861 "VN IPv6 interface address\n")
3863 struct rfapi_local_reg_delete_arg cda
;
3866 if ((rc
= parse_deleter_tokens (vty
, NULL
, NULL
, argv
[4], NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
3871 clear_vnc_responses (&cda
);
3872 clear_vnc_prefix (&cda
);
3873 clear_vnc_nve_closer (&cda
);
3875 print_cleared_stats (&cda
);
3879 DEFUN (clear_vnc_nve_un
,
3880 clear_vnc_nve_un_cmd
,
3881 "clear vnc nve un <*|A.B.C.D|X:X::X:X>",
3884 "Clear prefix registration information\n"
3885 "UN address of NVE\n"
3887 "UN IPv4 interface address\n"
3888 "UN IPv6 interface address\n")
3890 struct rfapi_local_reg_delete_arg cda
;
3893 if ((rc
= parse_deleter_tokens (vty
, NULL
, NULL
, NULL
, argv
[4], NULL
, NULL
, NULL
, NULL
, &cda
)))
3898 clear_vnc_responses (&cda
);
3899 clear_vnc_prefix (&cda
);
3900 clear_vnc_nve_closer (&cda
);
3902 print_cleared_stats (&cda
);
3906 /*-------------------------------------------------
3908 *-------------------------------------------------*/
3911 * This function is defined in this file (rather than in rfp_registration.c)
3912 * because here we have access to all the task handles.
3914 DEFUN (clear_vnc_prefix_vn_un
,
3915 clear_vnc_prefix_vn_un_cmd
,
3916 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> vn <*|A.B.C.D|X:X::X:X> un <*|A.B.C.D|X:X::X:X>",
3919 "Clear prefix registration information\n"
3923 "VN address of NVE\n"
3924 "All VN addresses\n"
3925 "VN IPv4 interface address\n"
3926 "VN IPv6 interface address\n"
3927 "UN address of NVE\n"
3928 "All UN addresses\n"
3929 "UN IPv4 interface address\n"
3930 "UN IPv6 interface address\n")
3932 struct rfapi_local_reg_delete_arg cda
;
3936 parse_deleter_tokens (vty
, NULL
, argv
[3], argv
[5], argv
[7], NULL
, NULL
, NULL
, NULL
, &cda
)))
3939 clear_vnc_prefix (&cda
);
3940 print_cleared_stats (&cda
);
3944 DEFUN (clear_vnc_prefix_un_vn
,
3945 clear_vnc_prefix_un_vn_cmd
,
3946 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> un <*|A.B.C.D|X:X::X:X> vn <*|A.B.C.D|X:X::X:X>",
3949 "Clear prefix registration information\n"
3953 "UN address of NVE\n"
3954 "All UN addresses\n"
3955 "UN IPv4 interface address\n"
3956 "UN IPv6 interface address\n"
3957 "VN address of NVE\n"
3958 "All VN addresses\n"
3959 "VN IPv4 interface address\n"
3960 "VN IPv6 interface address\n")
3962 struct rfapi_local_reg_delete_arg cda
;
3966 parse_deleter_tokens (vty
, NULL
, argv
[3], argv
[7], argv
[5], NULL
, NULL
, NULL
, NULL
, &cda
)))
3969 clear_vnc_prefix (&cda
);
3970 print_cleared_stats (&cda
);
3974 DEFUN (clear_vnc_prefix_un
,
3975 clear_vnc_prefix_un_cmd
,
3976 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> un <*|A.B.C.D|X:X::X:X>",
3979 "Clear prefix registration information\n"
3983 "UN address of NVE\n"
3984 "All UN addresses\n"
3985 "UN IPv4 interface address\n"
3986 "UN IPv6 interface address\n")
3988 struct rfapi_local_reg_delete_arg cda
;
3992 parse_deleter_tokens (vty
, NULL
, argv
[3], NULL
, argv
[5], NULL
, NULL
, NULL
, NULL
, &cda
)))
3995 clear_vnc_prefix (&cda
);
3996 print_cleared_stats (&cda
);
4000 DEFUN (clear_vnc_prefix_vn
,
4001 clear_vnc_prefix_vn_cmd
,
4002 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> vn <*|A.B.C.D|X:X::X:X>",
4005 "Clear prefix registration information\n"
4009 "UN address of NVE\n"
4010 "All VN addresses\n"
4011 "VN IPv4 interface address\n"
4012 "VN IPv6 interface address\n")
4014 struct rfapi_local_reg_delete_arg cda
;
4018 parse_deleter_tokens (vty
, NULL
, argv
[3], argv
[5], NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
4021 clear_vnc_prefix (&cda
);
4022 print_cleared_stats (&cda
);
4026 DEFUN (clear_vnc_prefix_all
,
4027 clear_vnc_prefix_all_cmd
,
4028 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> *",
4031 "Clear prefix registration information\n"
4037 struct rfapi_local_reg_delete_arg cda
;
4040 if ((rc
= parse_deleter_tokens (vty
, NULL
, argv
[3], NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
4043 clear_vnc_prefix (&cda
);
4044 print_cleared_stats (&cda
);
4048 /*-------------------------------------------------
4050 *-------------------------------------------------*/
4053 * This function is defined in this file (rather than in rfp_registration.c)
4054 * because here we have access to all the task handles.
4056 DEFUN (clear_vnc_mac_vn_un
,
4057 clear_vnc_mac_vn_un_cmd
,
4058 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> vn <*|A.B.C.D|X:X::X:X> un <*|A.B.C.D|X:X::X:X>",
4061 "Clear mac registration information\n"
4065 "Any virtual network identifier\n"
4066 "Virtual network identifier\n"
4067 "Virtual network identifier\n"
4068 "VN address of NVE\n"
4069 "All VN addresses\n"
4070 "VN IPv4 interface address\n"
4071 "VN IPv6 interface address\n"
4072 "UN address of NVE\n"
4073 "All UN addresses\n"
4074 "UN IPv4 interface address\n"
4075 "UN IPv6 interface address\n")
4077 struct rfapi_local_reg_delete_arg cda
;
4080 /* pfx vn un L2 VNI */
4082 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[7], argv
[9], argv
[3], argv
[5],
4086 clear_vnc_prefix (&cda
);
4087 print_cleared_stats (&cda
);
4091 DEFUN (clear_vnc_mac_un_vn
,
4092 clear_vnc_mac_un_vn_cmd
,
4093 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> un <*|A.B.C.D|X:X::X:X> vn <*|A.B.C.D|X:X::X:X>",
4096 "Clear mac registration information\n"
4100 "Any virtual network identifier\n"
4101 "Virtual network identifier\n"
4102 "UN address of NVE\n"
4103 "All UN addresses\n"
4104 "UN IPv4 interface address\n"
4105 "UN IPv6 interface address\n"
4106 "VN address of NVE\n"
4107 "All VN addresses\n"
4108 "VN IPv4 interface address\n"
4109 "VN IPv6 interface address\n")
4111 struct rfapi_local_reg_delete_arg cda
;
4114 /* pfx vn un L2 VNI */
4116 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[9], argv
[7], argv
[3], argv
[5],
4120 clear_vnc_prefix (&cda
);
4121 print_cleared_stats (&cda
);
4125 DEFUN (clear_vnc_mac_un
,
4126 clear_vnc_mac_un_cmd
,
4127 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> un <*|A.B.C.D|X:X::X:X>",
4130 "Clear mac registration information\n"
4134 "Any virtual network identifier\n"
4135 "Virtual network identifier\n"
4136 "UN address of NVE\n"
4137 "All UN addresses\n"
4138 "UN IPv4 interface address\n"
4139 "UN IPv6 interface address\n")
4141 struct rfapi_local_reg_delete_arg cda
;
4144 /* pfx vn un L2 VNI */
4146 parse_deleter_tokens (vty
, NULL
, NULL
, NULL
, argv
[7], argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4149 clear_vnc_prefix (&cda
);
4150 print_cleared_stats (&cda
);
4154 DEFUN (clear_vnc_mac_vn
,
4155 clear_vnc_mac_vn_cmd
,
4156 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> vn <*|A.B.C.D|X:X::X:X>",
4159 "Clear mac registration information\n"
4163 "Any virtual network identifier\n"
4164 "Virtual network identifier\n"
4165 "UN address of NVE\n"
4166 "All VN addresses\n"
4167 "VN IPv4 interface address\n"
4168 "VN IPv6 interface address\n")
4170 struct rfapi_local_reg_delete_arg cda
;
4173 /* pfx vn un L2 VNI */
4175 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[7], NULL
, argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4178 clear_vnc_prefix (&cda
);
4179 print_cleared_stats (&cda
);
4183 DEFUN (clear_vnc_mac_all
,
4184 clear_vnc_mac_all_cmd
,
4185 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> *",
4188 "Clear mac registration information\n"
4192 "Any virtual network identifier\n"
4193 "Virtual network identifier\n"
4196 struct rfapi_local_reg_delete_arg cda
;
4199 /* pfx vn un L2 VNI */
4201 parse_deleter_tokens (vty
, NULL
, NULL
, NULL
, NULL
, argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4204 clear_vnc_prefix (&cda
);
4205 print_cleared_stats (&cda
);
4209 /*-------------------------------------------------
4210 * Clear VNC MAC PREFIX
4211 *-------------------------------------------------*/
4213 DEFUN (clear_vnc_mac_vn_un_prefix
,
4214 clear_vnc_mac_vn_un_prefix_cmd
,
4215 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> vn <*|A.B.C.D|X:X::X:X> un <*|A.B.C.D|X:X::X:X> prefix <*|A.B.C.D/M|X:X::X:X/M>",
4218 "Clear mac registration information\n"
4222 "Any virtual network identifier\n"
4223 "Virtual network identifier\n"
4224 "VN address of NVE\n"
4225 "All VN addresses\n"
4226 "VN IPv4 interface address\n"
4227 "VN IPv6 interface address\n"
4228 "UN address of NVE\n"
4229 "All UN addresses\n"
4230 "UN IPv4 interface address\n"
4231 "UN IPv6 interface address\n"
4232 "Clear prefix registration information\n"
4237 struct rfapi_local_reg_delete_arg cda
;
4240 /* pfx vn un L2 VNI */
4242 parse_deleter_tokens (vty
, NULL
, argv
[11], argv
[7], argv
[9], argv
[3], argv
[5],
4246 clear_vnc_prefix (&cda
);
4247 print_cleared_stats (&cda
);
4251 DEFUN (clear_vnc_mac_un_vn_prefix
,
4252 clear_vnc_mac_un_vn_prefix_cmd
,
4253 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> un <*|A.B.C.D|X:X::X:X> vn <*|A.B.C.D|X:X::X:X> prefix <*|A.B.C.D/M|X:X::X:X/M> prefix <*|A.B.C.D/M|X:X::X:X/M>",
4256 "Clear mac registration information\n"
4260 "Any virtual network identifier\n"
4261 "Virtual network identifier\n"
4262 "UN address of NVE\n"
4263 "All UN addresses\n"
4264 "UN IPv4 interface address\n"
4265 "UN IPv6 interface address\n"
4266 "VN address of NVE\n"
4267 "All VN addresses\n"
4268 "VN IPv4 interface address\n"
4269 "VN IPv6 interface address\n"
4270 "Clear prefix registration information\n"
4274 "Clear prefix registration information\n"
4279 struct rfapi_local_reg_delete_arg cda
;
4282 /* pfx vn un L2 VNI */
4284 parse_deleter_tokens (vty
, NULL
, argv
[11], argv
[9], argv
[7], argv
[3], argv
[5],
4288 clear_vnc_prefix (&cda
);
4289 print_cleared_stats (&cda
);
4293 DEFUN (clear_vnc_mac_un_prefix
,
4294 clear_vnc_mac_un_prefix_cmd
,
4295 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> un <*|A.B.C.D|X:X::X:X> prefix <*|A.B.C.D/M|X:X::X:X/M>",
4298 "Clear mac registration information\n"
4302 "Any virtual network identifier\n"
4303 "Virtual network identifier\n"
4304 "UN address of NVE\n"
4305 "All UN addresses\n"
4306 "UN IPv4 interface address\n"
4307 "UN IPv6 interface address\n"
4308 "Clear prefix registration information\n"
4313 struct rfapi_local_reg_delete_arg cda
;
4316 /* pfx vn un L2 VNI */
4318 parse_deleter_tokens (vty
, NULL
, argv
[9], NULL
, argv
[7], argv
[3], argv
[5],
4322 clear_vnc_prefix (&cda
);
4323 print_cleared_stats (&cda
);
4327 DEFUN (clear_vnc_mac_vn_prefix
,
4328 clear_vnc_mac_vn_prefix_cmd
,
4329 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> vn <*|A.B.C.D|X:X::X:X> prefix <*|A.B.C.D/M|X:X::X:X/M>",
4332 "Clear mac registration information\n"
4336 "Any virtual network identifier\n"
4337 "Virtual network identifier\n"
4338 "UN address of NVE\n"
4339 "All VN addresses\n"
4340 "VN IPv4 interface address\n"
4341 "VN IPv6 interface address\n"
4342 "Clear prefix registration information\n"
4347 struct rfapi_local_reg_delete_arg cda
;
4350 /* pfx vn un L2 VNI */
4352 parse_deleter_tokens (vty
, NULL
, argv
[9], argv
[7], NULL
, argv
[3], argv
[5],
4356 clear_vnc_prefix (&cda
);
4357 print_cleared_stats (&cda
);
4361 DEFUN (clear_vnc_mac_all_prefix
,
4362 clear_vnc_mac_all_prefix_cmd
,
4363 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> prefix <*|A.B.C.D/M|X:X::X:X/M>",
4366 "Clear mac registration information\n"
4370 "Any virtual network identifier\n"
4371 "Virtual network identifier\n"
4372 "UN address of NVE\n"
4373 "All VN addresses\n"
4374 "VN IPv4 interface address\n"
4375 "VN IPv6 interface address\n")
4377 struct rfapi_local_reg_delete_arg cda
;
4380 /* pfx vn un L2 VNI */
4382 parse_deleter_tokens (vty
, NULL
, argv
[7], NULL
, NULL
, argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4385 clear_vnc_prefix (&cda
);
4386 print_cleared_stats (&cda
);
4390 /************************************************************************
4392 ************************************************************************/
4395 /* copied from rfp_vty.c */
4397 check_and_display_is_vnc_running (struct vty
*vty
)
4399 if (!bgp_rfapi_is_vnc_configured (NULL
))
4400 return 1; /* is running */
4405 "VNC is not configured. (There are no configured BGP VPN SAFI peers.)");
4407 return 0; /* not running */
4411 rfapi_vty_show_nve_summary (struct vty
*vty
, show_nve_summary_t show_type
)
4413 struct bgp
*bgp_default
= bgp_get_default ();
4415 int is_vnc_running
= !bgp_rfapi_is_vnc_configured (bgp_default
);
4417 int active_local_routes
;
4418 int active_remote_routes
;
4419 int holddown_remote_routes
;
4420 int imported_remote_routes
;
4425 h
= bgp_default
->rfapi
;
4430 /* don't show local info if not running RFP */
4431 if (is_vnc_running
|| show_type
== SHOW_NVE_SUMMARY_REGISTERED
)
4437 case SHOW_NVE_SUMMARY_ACTIVE_NVES
:
4438 vty_out (vty
, "%-24s ", "NVEs:");
4439 vty_out (vty
, "%-8s %-8u ", "Active:", h
->descriptors
.count
);
4440 vty_out (vty
, "%-8s %-8u ", "Maximum:", h
->stat
.max_descriptors
);
4441 vty_out (vty
, "%-8s %-8u", "Unknown:", h
->stat
.count_unknown_nves
);
4444 case SHOW_NVE_SUMMARY_REGISTERED
:
4446 * NB: With the introduction of L2 route support, we no
4447 * longer have a one-to-one correspondence between
4448 * locally-originated route advertisements and routes in
4449 * the import tables that have local origin. This
4450 * discrepancy arises because a single advertisement
4451 * may contain both an IP prefix and a MAC address.
4452 * Such an advertisement results in two import table
4453 * entries: one indexed by IP prefix, the other indexed
4456 * TBD: update computation and display of registration
4457 * statistics to reflect the underlying semantics.
4461 vty_out (vty
, "%-24s ", "Registrations:");
4462 vty_out (vty
, "%-8s %-8u ", "Active:",
4463 rfapiApCountAll (bgp_default
));
4464 vty_out (vty
, "%-8s %-8u ", "Failed:",
4465 h
->stat
.count_registrations_failed
);
4466 vty_out (vty
, "%-8s %-8u", "Total:",
4467 h
->stat
.count_registrations
);
4468 vty_out (vty
, VTYNL
);
4470 vty_out (vty
, "%-24s ", "Prefixes registered:");
4471 vty_out (vty
, VTYNL
);
4473 rfapiCountAllItRoutes (&active_local_routes
,
4474 &active_remote_routes
,
4475 &holddown_remote_routes
,
4476 &imported_remote_routes
);
4481 vty_out (vty
, " %-20s ", "Locally:");
4482 vty_out (vty
, "%-8s %-8u ", "Active:", active_local_routes
);
4483 vty_out (vty
, VTYNL
);
4487 vty_out (vty
, " %-20s ", "Remotely:");
4488 vty_out (vty
, "%-8s %-8u", "Active:", active_remote_routes
);
4489 vty_out (vty
, VTYNL
);
4490 vty_out (vty
, " %-20s ", "In Holddown:");
4491 vty_out (vty
, "%-8s %-8u", "Active:", holddown_remote_routes
);
4492 vty_out (vty
, VTYNL
);
4493 vty_out (vty
, " %-20s ", "Imported:");
4494 vty_out (vty
, "%-8s %-8u", "Active:", imported_remote_routes
);
4497 case SHOW_NVE_SUMMARY_QUERIES
:
4498 vty_out (vty
, "%-24s ", "Queries:");
4499 vty_out (vty
, "%-8s %-8u ", "Active:", rfapi_monitor_count (NULL
));
4500 vty_out (vty
, "%-8s %-8u ", "Failed:",
4501 h
->stat
.count_queries_failed
);
4502 vty_out (vty
, "%-8s %-8u", "Total:", h
->stat
.count_queries
);
4505 case SHOW_NVE_SUMMARY_RESPONSES
:
4506 rfapiRibShowResponsesSummary (vty
);
4511 vty_out (vty
, VTYNL
);
4516 vty_outln (vty
, "VNC is not configured.");
4523 struct prefix
*vn_prefix
,
4524 struct prefix
*un_prefix
)
4526 //struct hash *rfds;
4527 //struct rfp_rfapi_descriptor_param param;
4529 struct bgp
*bgp_default
= bgp_get_default ();
4531 struct listnode
*node
;
4532 struct rfapi_descriptor
*rfd
;
4541 h
= bgp_default
->rfapi
;
4546 rc
= rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4550 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4553 char vn_addr_buf
[INET6_ADDRSTRLEN
] =
4556 char un_addr_buf
[INET6_ADDRSTRLEN
] =
4565 assert (!rfapiRaddr2Qprefix (&rfd
->vn_addr
, &pfx
));
4566 if (!prefix_match (vn_prefix
, &pfx
))
4572 assert (!rfapiRaddr2Qprefix (&rfd
->un_addr
, &pfx
));
4573 if (!prefix_match (un_prefix
, &pfx
))
4577 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, vn_addr_buf
, INET6_ADDRSTRLEN
);
4578 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, un_addr_buf
, INET6_ADDRSTRLEN
);
4582 /* print out a header */
4584 " " "Active Next Hops");
4585 vty_outln (vty
, "%-15s %-15s %-5s %-5s %-6s %-6s %s",
4588 "Regis", "Resps", "Reach", "Remove", "Age");
4593 vty_outln (vty
, "%-15s %-15s %-5u %-5u %-6u %-6u %s",
4597 rfapi_monitor_count (rfd
),
4598 rfd
->stat_count_nh_reachable
,
4599 rfd
->stat_count_nh_removal
,
4600 rfapiFormatAge(rfd
->open_time
, age
, 10));
4603 if (printed
> 0 || vn_prefix
|| un_prefix
)
4604 vty_outln (vty
, "Displayed %d out of %d active NVEs",
4610 vty_outln (vty
, "VNC is not configured.");
4615 DEFUN (vnc_show_summary
,
4616 vnc_show_summary_cmd
,
4620 "Display VNC status summary\n")
4622 if (!check_and_display_is_vnc_running (vty
))
4624 bgp_rfapi_show_summary (bgp_get_default (), vty
);
4625 vty_out (vty
, VTYNL
);
4626 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4627 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4628 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_RESPONSES
);
4629 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4633 DEFUN (vnc_show_nves
,
4638 "List known NVEs\n")
4640 rfapi_show_nves (vty
, NULL
, NULL
);
4644 DEFUN (vnc_show_nves_ptct
,
4645 vnc_show_nves_ptct_cmd
,
4646 "show vnc nves <vn|un> <A.B.C.D|X:X::X:X>",
4650 "VN address of NVE\n"
4651 "UN address of NVE\n"
4652 "IPv4 interface address\n"
4653 "IPv6 interface address\n")
4657 if (!check_and_display_is_vnc_running (vty
))
4660 if (!str2prefix (argv
[4]->arg
, &pfx
))
4662 vty_outln (vty
, "Malformed address \"%s\"", argv
[4]->arg
);
4665 if (pfx
.family
!= AF_INET
&& pfx
.family
!= AF_INET6
)
4667 vty_outln (vty
, "Invalid address \"%s\"", argv
[4]->arg
);
4671 if (argv
[3]->arg
[0] == 'u')
4673 rfapi_show_nves (vty
, NULL
, &pfx
);
4677 rfapi_show_nves (vty
, &pfx
, NULL
);
4683 /* adapted from rfp_registration_cache_log() */
4685 rfapi_show_registrations (
4687 struct prefix
*restrict_to
,
4698 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4702 /* non-expiring, local */
4703 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 1, 0, 0);
4707 /* non-expiring, non-local */
4708 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 0);
4712 /* expiring, including local */
4713 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 1, 1, 1, 0);
4717 /* non-expiring, non-local */
4718 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 1);
4722 vty_out (vty
, VTYNL
);
4726 DEFUN (vnc_show_registrations_pfx
,
4727 vnc_show_registrations_pfx_cmd
,
4728 "show vnc registrations [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4731 "List active prefix registrations\n"
4732 "Limit output to a particular IPv4 prefix\n"
4733 "Limit output to a particular IPv6 prefix\n"
4734 "Limit output to a particular IPv6 address\n")
4737 struct prefix
*p_addr
= NULL
;
4741 if (!str2prefix (argv
[3]->arg
, &p
))
4743 vty_outln (vty
, "Invalid prefix: %s", argv
[3]->arg
);
4752 rfapi_show_registrations (vty
, p_addr
, 1, 1, 1, 1);
4756 DEFUN (vnc_show_registrations_some_pfx
,
4757 vnc_show_registrations_some_pfx_cmd
,
4758 "show vnc registrations <all|holddown|imported|local|remote> [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4761 "List active prefix registrations\n"
4762 "show all registrations\n"
4763 "show only registrations in holddown\n"
4764 "show only imported prefixes\n"
4765 "show only local registrations\n"
4766 "show only remote registrations\n"
4767 "Limit output to a particular prefix or address\n"
4768 "Limit output to a particular prefix or address\n"
4769 "Limit output to a particular prefix or address\n")
4772 struct prefix
*p_addr
= NULL
;
4775 int show_remote
= 0;
4776 int show_holddown
= 0;
4777 int show_imported
= 0;
4781 if (!str2prefix (argv
[4]->arg
, &p
))
4783 vty_outln (vty
, "Invalid prefix: %s", argv
[4]->arg
);
4791 switch (argv
[3]->arg
[0])
4817 rfapi_show_registrations (vty
, p_addr
,
4818 show_local
, show_remote
, show_holddown
,
4823 DEFUN (vnc_show_responses_pfx
,
4824 vnc_show_responses_pfx_cmd
,
4825 "show vnc responses [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4828 "List recent query responses\n"
4829 "Limit output to a particular IPv4 prefix\n"
4830 "Limit output to a particular IPv6 prefix\n"
4831 "Limit output to a particular IPv6 address\n" )
4834 struct prefix
*p_addr
= NULL
;
4838 if (!str2prefix (argv
[3]->arg
, &p
))
4840 vty_outln (vty
, "Invalid prefix: %s", argv
[3]->arg
);
4848 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4850 rfapiRibShowResponsesSummary (vty
);
4852 rfapiRibShowResponses (vty
, p_addr
, 0);
4853 rfapiRibShowResponses (vty
, p_addr
, 1);
4858 DEFUN (vnc_show_responses_some_pfx
,
4859 vnc_show_responses_some_pfx_cmd
,
4860 "show vnc responses <active|removed> [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4863 "List recent query responses\n"
4864 "show only active query responses\n"
4865 "show only removed query responses\n"
4866 "Limit output to a particular IPv4 prefix\n"
4867 "Limit output to a particular IPv6 prefix\n"
4868 "Limit output to a particular IPV6 address\n")
4871 struct prefix
*p_addr
= NULL
;
4873 int show_active
= 0;
4874 int show_removed
= 0;
4876 if (!check_and_display_is_vnc_running (vty
))
4881 if (!str2prefix (argv
[4]->arg
, &p
))
4883 vty_outln (vty
, "Invalid prefix: %s", argv
[4]->arg
);
4892 switch (argv
[3]->arg
[0])
4903 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4905 rfapiRibShowResponsesSummary (vty
);
4908 rfapiRibShowResponses (vty
, p_addr
, 0);
4910 rfapiRibShowResponses (vty
, p_addr
, 1);
4915 DEFUN (show_vnc_queries_pfx
,
4916 show_vnc_queries_pfx_cmd
,
4917 "show vnc queries [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4920 "List active queries\n"
4921 "Limit output to a particular IPv4 prefix or address\n"
4922 "Limit output to a particular IPv6 prefix\n"
4923 "Limit output to a particualr IPV6 address\n")
4926 struct prefix
*p
= NULL
;
4930 if (!str2prefix (argv
[3]->arg
, &pfx
))
4932 vty_outln (vty
, "Invalid prefix: %s", argv
[3]->arg
);
4938 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4940 return rfapiShowVncQueries (vty
, p
);
4943 DEFUN (vnc_clear_counters
,
4944 vnc_clear_counters_cmd
,
4945 "clear vnc counters",
4948 "Reset VNC counters\n")
4950 struct bgp
*bgp_default
= bgp_get_default ();
4952 struct listnode
*node
;
4953 struct rfapi_descriptor
*rfd
;
4958 h
= bgp_default
->rfapi
;
4964 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4966 rfd
->stat_count_nh_reachable
= 0;
4967 rfd
->stat_count_nh_removal
= 0;
4971 memset (&h
->stat
, 0, sizeof (h
->stat
));
4974 * 151122 per bug 103, set count_registrations = number active.
4975 * Do same for queries
4977 h
->stat
.count_registrations
= rfapiApCountAll (bgp_default
);
4978 h
->stat
.count_queries
= rfapi_monitor_count (NULL
);
4980 rfapiRibShowResponsesSummaryClear ();
4985 vty_outln (vty
, "VNC is not configured.");
4989 /************************************************************************
4990 * Add prefix with vrf
4992 * add [vrf <vrf-name>] prefix <prefix>
4993 * [rd <value>] [label <value>] [local-preference <0-4294967295>]
4994 ************************************************************************/
4996 vnc_add_vrf_prefix (struct vty
*vty
,
4997 const char *arg_vrf
,
4998 const char *arg_prefix
,
4999 const char *arg_rd
, /* optional */
5000 const char *arg_label
, /* optional */
5001 const char *arg_pref
) /* optional */
5004 struct rfapi_nve_group_cfg
*rfg
;
5006 struct rfapi_ip_prefix rpfx
;
5008 struct rfapi_vn_option optary
[3];
5009 struct rfapi_vn_option
*opt
= NULL
;
5012 bgp
= bgp_get_default (); /* assume main instance for now */
5015 vty_outln (vty
, "No BGP process is configured");
5018 if (!bgp
->rfapi
|| !bgp
->rfapi_cfg
)
5020 vty_outln (vty
, "VRF support not configured");
5024 rfg
= bgp_rfapi_cfg_match_byname (bgp
, arg_vrf
, RFAPI_GROUP_CFG_VRF
);
5028 vty_outln (vty
, "VRF \"%s\" appears not to be configured.",
5032 if (!rfg
->rt_export_list
|| !rfg
->rfapi_import_table
)
5034 vty_outln (vty
, "VRF \"%s\" is missing RT import/export RT configuration.",
5038 if (!rfg
->rd
.family
&& !arg_rd
)
5040 vty_outln (vty
, "VRF \"%s\" isn't configured with an RD, so RD must be provided.",
5044 if (rfg
->label
> MPLS_LABEL_MAX
&& !arg_label
)
5046 vty_outln (vty
, "VRF \"%s\" isn't configured with a default labels, so a label must be provided.",
5050 if (!str2prefix (arg_prefix
, &pfx
))
5052 vty_outln (vty
, "Malformed prefix \"%s\"",
5056 rfapiQprefix2Rprefix (&pfx
, &rpfx
);
5057 memset (optary
, 0, sizeof (optary
));
5061 opt
->next
= &optary
[cur_opt
];
5062 opt
= &optary
[cur_opt
++];
5063 opt
->type
= RFAPI_VN_OPTION_TYPE_INTERNAL_RD
;
5064 if (!str2prefix_rd (arg_rd
, &opt
->v
.internal_rd
))
5066 vty_outln (vty
, "Malformed RD \"%s\"",
5071 if (rfg
->label
<= MPLS_LABEL_MAX
|| arg_label
)
5073 struct rfapi_l2address_option
*l2o
;
5075 opt
->next
= &optary
[cur_opt
];
5076 opt
= &optary
[cur_opt
++];
5077 opt
->type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
5078 l2o
= &opt
->v
.l2addr
;
5082 label
= strtoul(arg_label
, NULL
, 10);
5086 l2o
->label
= rfg
->label
;
5090 char *endptr
= NULL
;
5091 pref
= strtoul (arg_pref
, &endptr
, 10);
5092 if (*endptr
!= '\0')
5094 vty_outln (vty
, "%% Invalid local-preference value \"%s\"",
5099 rpfx
.cost
= 255 - (pref
& 255) ;
5100 if (rfg
->rfd
== NULL
) /* need new rfapi_handle */
5102 /* based on rfapi_open */
5103 struct rfapi_descriptor
*rfd
;
5104 rfd
= XCALLOC (MTYPE_RFAPI_DESC
, sizeof (struct rfapi_descriptor
));
5107 /* leave most fields empty as will get from (dynamic) config when needed */
5108 rfd
->default_tunneltype_option
.type
= BGP_ENCAP_TYPE_MPLS
;
5110 if (rfg
->vn_prefix
.family
&&
5111 !CHECK_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
))
5113 rfapiQprefix2Raddr(&rfg
->vn_prefix
, &rfd
->vn_addr
);
5117 memset(&rfd
->vn_addr
, 0, sizeof(struct rfapi_ip_addr
));
5118 rfd
->vn_addr
.addr_family
= AF_INET
;
5119 rfd
->vn_addr
.addr
.v4
= bgp
->router_id
;
5121 rfd
->un_addr
= rfd
->vn_addr
; /* sigh, need something in UN for lookups */
5122 vnc_zlog_debug_verbose ("%s: Opening RFD for VRF %s",
5123 __func__
, rfg
->name
);
5124 rfapi_init_and_open(bgp
, rfd
, rfg
);
5127 if (!rfapi_register (rfg
->rfd
, &rpfx
, RFAPI_INFINITE_LIFETIME
, NULL
,
5128 (cur_opt
? optary
: NULL
), RFAPI_REGISTER_ADD
))
5130 struct rfapi_next_hop_entry
*head
= NULL
;
5131 struct rfapi_next_hop_entry
*tail
= NULL
;
5132 struct rfapi_vn_option
*vn_opt_new
;
5134 vnc_zlog_debug_verbose ("%s: rfapi_register succeeded", __func__
);
5136 if (bgp
->rfapi
->rfp_methods
.local_cb
)
5138 struct rfapi_descriptor
*r
= (struct rfapi_descriptor
*) rfg
->rfd
;
5139 vn_opt_new
= rfapi_vn_options_dup (opt
);
5141 rfapiAddDeleteLocalRfpPrefix (&r
->un_addr
, &r
->vn_addr
, &rpfx
,
5142 1, RFAPI_INFINITE_LIFETIME
,
5143 vn_opt_new
, &head
, &tail
);
5146 bgp
->rfapi
->flags
|= RFAPI_INCALLBACK
;
5147 (*bgp
->rfapi
->rfp_methods
.local_cb
) (head
, r
->cookie
);
5148 bgp
->rfapi
->flags
&= ~RFAPI_INCALLBACK
;
5152 vnc_zlog_debug_verbose ("%s completed, count=%d/%d", __func__
,
5153 rfg
->rfapi_import_table
->local_count
[AFI_IP
],
5154 rfg
->rfapi_import_table
->local_count
[AFI_IP6
]);
5158 vnc_zlog_debug_verbose ("%s: rfapi_register failed", __func__
);
5159 vty_outln (vty
, "Add failed.");
5163 DEFUN (add_vrf_prefix_rd_label_pref
,
5164 add_vrf_prefix_rd_label_pref_cmd
,
5165 "add vrf NAME prefix <A.B.C.D/M|X:X::X:X/M> [{rd ASN:nn_or_IP-address|label (0-1048575)|preference (0-4294967295)}]",
5169 "Add/modify prefix related information\n"
5172 "Override configured VRF Route Distinguisher\n"
5173 "<as-number>:<number> or <ip-address>:<number>\n"
5174 "Override configured VRF label\n"
5175 "Label Value <0-1048575>\n"
5176 "Set advertised local preference\n"
5177 "local preference (higher=more preferred)\n")
5179 char *arg_vrf
= argv
[2]->arg
;
5180 char *arg_prefix
= argv
[4]->arg
;
5181 char *arg_rd
= NULL
; /* optional */
5182 char *arg_label
= NULL
; /* optional */
5183 char *arg_pref
= NULL
; /* optional */
5185 argc
--; /* don't parse argument */
5186 while (pargc
< argc
)
5188 switch (argv
[pargc
++]->arg
[0])
5191 arg_rd
= argv
[pargc
]->arg
;
5194 arg_label
= argv
[pargc
]->arg
;
5197 arg_pref
= argv
[pargc
]->arg
;
5205 return vnc_add_vrf_prefix (vty
, arg_vrf
, arg_prefix
, arg_rd
, arg_label
, arg_pref
);
5208 /************************************************************************
5209 * del prefix with vrf
5211 * clear [vrf <vrf-name>] prefix <prefix> [rd <value>]
5212 ************************************************************************/
5214 rfapi_cfg_group_it_count(struct rfapi_nve_group_cfg
*rfg
)
5217 afi_t afi
= AFI_MAX
;
5220 count
+= rfg
->rfapi_import_table
->local_count
[afi
];
5226 clear_vnc_vrf_closer (struct rfapi_nve_group_cfg
*rfg
)
5228 struct rfapi_descriptor
*rfd
= rfg
->rfd
;
5233 /* check if IT is empty */
5235 afi
< AFI_MAX
&& rfg
->rfapi_import_table
->local_count
[afi
] == 0;
5240 vnc_zlog_debug_verbose ("%s: closing RFD for VRF %s",
5241 __func__
, rfg
->name
);
5247 vnc_zlog_debug_verbose ("%s: VRF %s afi=%d count=%d",
5248 __func__
, rfg
->name
, afi
,
5249 rfg
->rfapi_import_table
->local_count
[afi
]);
5254 vnc_clear_vrf (struct vty
*vty
,
5256 const char *arg_vrf
,
5257 const char *arg_prefix
, /* NULL = all */
5258 const char *arg_rd
) /* optional */
5260 struct rfapi_nve_group_cfg
*rfg
;
5261 struct rfapi_local_reg_delete_arg cda
;
5266 bgp
= bgp_get_default (); /* assume main instance for now */
5269 vty_outln (vty
, "No BGP process is configured");
5272 if (!bgp
->rfapi
|| !bgp
->rfapi_cfg
)
5274 vty_outln (vty
, "VRF support not configured");
5277 rfg
= bgp_rfapi_cfg_match_byname (bgp
, arg_vrf
, RFAPI_GROUP_CFG_VRF
);
5281 vty_outln (vty
, "VRF \"%s\" appears not to be configured.",
5285 rc
= parse_deleter_args (vty
, bgp
, arg_prefix
, NULL
, NULL
, NULL
, NULL
,
5287 if (rc
!= CMD_SUCCESS
) /* parse error */
5290 start_count
= rfapi_cfg_group_it_count(rfg
);
5291 clear_vnc_prefix (&cda
);
5292 clear_vnc_vrf_closer (rfg
);
5293 vty_outln (vty
, "Cleared %u out of %d prefixes.",
5294 cda
.pfx_count
, start_count
);
5298 DEFUN (clear_vrf_prefix_rd
,
5299 clear_vrf_prefix_rd_cmd
,
5300 "clear vrf NAME [prefix <A.B.C.D/M|X:X::X:X/M>] [rd ASN:nn_or_IP-address]",
5301 "Clear stored data\n"
5304 "Prefix related information\n"
5307 "Specific VRF Route Distinguisher\n"
5308 "<as-number>:<number> or <ip-address>:<number>\n")
5310 char *arg_vrf
= argv
[2]->arg
;
5311 char *arg_prefix
= NULL
; /* optional */
5312 char *arg_rd
= NULL
; /* optional */
5314 argc
--; /* don't check parameter */
5315 while (pargc
< argc
)
5317 switch (argv
[pargc
++]->arg
[0])
5320 arg_rd
= argv
[pargc
]->arg
;
5323 arg_prefix
= argv
[pargc
]->arg
;
5330 return vnc_clear_vrf (vty
, NULL
, arg_vrf
, arg_prefix
, arg_rd
);
5333 DEFUN (clear_vrf_all
,
5335 "clear vrf NAME all",
5336 "Clear stored data\n"
5341 char *arg_vrf
= argv
[2]->arg
;
5342 return vnc_clear_vrf (vty
, NULL
, arg_vrf
, NULL
, NULL
);
5345 void rfapi_vty_init ()
5347 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_lnh_cmd
);
5348 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_lnh_cmd
);
5349 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_lnh_cmd
);
5350 install_element (ENABLE_NODE
, &add_vnc_prefix_life_lnh_cmd
);
5351 install_element (ENABLE_NODE
, &add_vnc_prefix_lnh_cmd
);
5353 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_cmd
);
5354 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_cmd
);
5355 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_cmd
);
5356 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cmd
);
5357 install_element (ENABLE_NODE
, &add_vnc_prefix_cmd
);
5359 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_life_cmd
);
5360 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_life_cmd
);
5361 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_cmd
);
5362 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cmd
);
5363 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_life_cmd
);
5364 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_cmd
);
5365 install_element (ENABLE_NODE
, &add_vnc_mac_vni_life_cmd
);
5366 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cmd
);
5368 install_element (ENABLE_NODE
, &add_vrf_prefix_rd_label_pref_cmd
);
5370 install_element (ENABLE_NODE
, &clear_vnc_nve_all_cmd
);
5371 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_un_cmd
);
5372 install_element (ENABLE_NODE
, &clear_vnc_nve_un_vn_cmd
);
5373 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_cmd
);
5374 install_element (ENABLE_NODE
, &clear_vnc_nve_un_cmd
);
5376 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_un_cmd
);
5377 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_vn_cmd
);
5378 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_cmd
);
5379 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_cmd
);
5380 install_element (ENABLE_NODE
, &clear_vnc_prefix_all_cmd
);
5382 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_cmd
);
5383 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_cmd
);
5384 install_element (ENABLE_NODE
, &clear_vnc_mac_un_cmd
);
5385 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_cmd
);
5386 install_element (ENABLE_NODE
, &clear_vnc_mac_all_cmd
);
5388 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_prefix_cmd
);
5389 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_prefix_cmd
);
5390 install_element (ENABLE_NODE
, &clear_vnc_mac_un_prefix_cmd
);
5391 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_prefix_cmd
);
5392 install_element (ENABLE_NODE
, &clear_vnc_mac_all_prefix_cmd
);
5394 install_element (ENABLE_NODE
, &clear_vrf_prefix_rd_cmd
);
5395 install_element (ENABLE_NODE
, &clear_vrf_all_cmd
);
5397 install_element (ENABLE_NODE
, &vnc_clear_counters_cmd
);
5399 install_element (VIEW_NODE
, &vnc_show_summary_cmd
);
5400 install_element (VIEW_NODE
, &vnc_show_nves_cmd
);
5401 install_element (VIEW_NODE
, &vnc_show_nves_ptct_cmd
);
5403 install_element (VIEW_NODE
, &vnc_show_registrations_pfx_cmd
);
5404 install_element (VIEW_NODE
, &vnc_show_registrations_some_pfx_cmd
);
5405 install_element (VIEW_NODE
, &vnc_show_responses_pfx_cmd
);
5406 install_element (VIEW_NODE
, &vnc_show_responses_some_pfx_cmd
);
5407 install_element (VIEW_NODE
, &show_vnc_queries_pfx_cmd
);