summaryrefslogtreecommitdiffstats
path: root/src/vnet/ipsec/ipsec_tun.h
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2020-05-24 16:17:50 +0000
committerNeale Ranns <nranns@cisco.com>2020-10-05 09:06:36 +0000
commit7b4e52f88fdfd7b785a2741d3b61050040d8561d (patch)
treef80271d2f297c99b15fb1a25141cd4be4357e07f /src/vnet/ipsec/ipsec_tun.h
parent149fd3fbd069a5f7be86e68472578ee7af229cb6 (diff)
ipsec: Use bihash for tunnel lookup
Type: improvement Change-Id: I0c82722dfce990345fe6eeecdb335678543367e0 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/ipsec/ipsec_tun.h')
-rw-r--r--src/vnet/ipsec/ipsec_tun.h91
1 files changed, 59 insertions, 32 deletions
diff --git a/src/vnet/ipsec/ipsec_tun.h b/src/vnet/ipsec/ipsec_tun.h
index c5fbe59f2b6..0d911a2876c 100644
--- a/src/vnet/ipsec/ipsec_tun.h
+++ b/src/vnet/ipsec/ipsec_tun.h
@@ -17,35 +17,72 @@
#include <vnet/ipsec/ipsec.h>
-/* *INDENT-OFF* */
-typedef CLIB_PACKED(struct {
+/**
+ * result of a lookup in the protection bihash
+ */
+typedef struct ipsec_tun_lkup_result_t_
+{
+ union
+ {
+ struct
+ {
+ u32 tun_index;
+ u32 sa_index;
+ };
+ u64 as_u64;
+ };
+} ipsec_tun_lkup_result_t;
+
+typedef struct ipsec4_tunnel_kv_t
+{
/*
* Key fields: remote ip and spi on incoming packet
* all fields in NET byte order
*/
- union {
- struct {
- ip4_address_t remote_ip;
- u32 spi;
- };
- u64 as_u64;
- };
-}) ipsec4_tunnel_key_t;
-/* *INDENT-ON* */
+ u64 key;
+ ipsec_tun_lkup_result_t value;
+} __clib_packed ipsec4_tunnel_kv_t;
+
+STATIC_ASSERT_SIZEOF (ipsec4_tunnel_kv_t, sizeof (clib_bihash_kv_8_8_t));
+STATIC_ASSERT_OFFSET_OF (ipsec4_tunnel_kv_t, value,
+ STRUCT_OFFSET_OF (clib_bihash_kv_8_8_t, value));
+
+static inline void
+ipsec4_tunnel_mk_key (ipsec4_tunnel_kv_t * k,
+ const ip4_address_t * ip, u32 spi)
+{
+ k->key = (((u64) ip->as_u32) << 32 | spi);
+}
+
+static inline void
+ipsec4_tunnel_extract_key (const ipsec4_tunnel_kv_t * k,
+ ip4_address_t * ip, u32 * spi)
+{
+ *spi = (u32) k->key;
+ (*ip).as_u32 = k->key >> 32;
+}
-/* *INDENT-OFF* */
-typedef CLIB_PACKED(struct {
+typedef struct ipsec6_tunnel_kv_t_
+{
/*
* Key fields: remote ip and spi on incoming packet
* all fields in NET byte order
*/
- ip6_address_t remote_ip;
- u32 spi;
-}) ipsec6_tunnel_key_t;
-/* *INDENT-ON* */
+ struct
+ {
+ ip6_address_t remote_ip;
+ u32 spi;
+ u32 __pad;
+ } key;
+ ipsec_tun_lkup_result_t value;
+} __clib_packed ipsec6_tunnel_kv_t;
-extern u8 *format_ipsec4_tunnel_key (u8 * s, va_list * args);
-extern u8 *format_ipsec6_tunnel_key (u8 * s, va_list * args);
+STATIC_ASSERT_SIZEOF (ipsec6_tunnel_kv_t, sizeof (clib_bihash_kv_24_8_t));
+STATIC_ASSERT_OFFSET_OF (ipsec6_tunnel_kv_t, value,
+ STRUCT_OFFSET_OF (clib_bihash_kv_24_8_t, value));
+
+extern u8 *format_ipsec4_tunnel_kv (u8 * s, va_list * args);
+extern u8 *format_ipsec6_tunnel_kv (u8 * s, va_list * args);
#define foreach_ipsec_protect_flags \
_(L2, 1, "l2") \
@@ -136,6 +173,9 @@ extern u8 *format_ipsec_tun_protect_index (u8 * s, va_list * args);
extern void ipsec_tun_register_nodes (ip_address_family_t af);
extern void ipsec_tun_unregister_nodes (ip_address_family_t af);
+extern void ipsec_tun_table_init (ip_address_family_t af,
+ uword table_size, u32 n_buckets);
+
// FIXME
extern vlib_node_registration_t ipsec4_tun_input_node;
extern vlib_node_registration_t ipsec6_tun_input_node;
@@ -145,19 +185,6 @@ extern vlib_node_registration_t ipsec6_tun_input_node;
*/
extern ipsec_tun_protect_t *ipsec_tun_protect_pool;
-typedef struct ipsec_tun_lkup_result_t_
-{
- union
- {
- struct
- {
- u32 tun_index;
- u32 sa_index;
- };
- u64 as_u64;
- };
-} ipsec_tun_lkup_result_t;
-
always_inline ipsec_tun_protect_t *
ipsec_tun_protect_get (u32 index)
{