summaryrefslogtreecommitdiffstats
path: root/src/vnet/session/transport.h
diff options
context:
space:
mode:
authorClement Durand <clement.durand@polytechnique.edu>2017-05-04 08:33:55 +0200
committerFlorin Coras <florin.coras@gmail.com>2017-05-04 15:43:06 +0000
commitda7567c022676374e7e50ff44c12ba0825e0cb38 (patch)
treeb7c7925763a3a7484fd67d65ea45087d8a44f087 /src/vnet/session/transport.h
parent68c74fc71bc19b44b39601e5ab3d79d35cd5007b (diff)
Fixes and improvements in session hashtable keys
Fix in v6 keys : * The copy of the keys was only partial A few suggestions are applied in this commit : * Since there are not so many unused fields, we avoid to memset 0 and prefer setting the unused fields to 0. * By using a cast, it seems painless to avoid allocating a structure for the keys creation. Change-Id: Iaee6f036f2a979cceaeb297d98ce6c307a5ac029 Signed-off-by: Clement Durand <clement.durand@polytechnique.edu>
Diffstat (limited to 'src/vnet/session/transport.h')
-rw-r--r--src/vnet/session/transport.h88
1 files changed, 35 insertions, 53 deletions
diff --git a/src/vnet/session/transport.h b/src/vnet/session/transport.h
index 7ea7af1589b..e5f788bee08 100644
--- a/src/vnet/session/transport.h
+++ b/src/vnet/session/transport.h
@@ -128,7 +128,7 @@ typedef CLIB_PACKED (struct {
u16 src_port;
u16 dst_port;
u32 proto;
- u8 unused_for_now[8];
+ u64 unused;
};
u64 as_u64[6];
};
@@ -142,17 +142,14 @@ always_inline void
make_v4_ss_kv (session_kv4_t * kv, ip4_address_t * lcl, ip4_address_t * rmt,
u16 lcl_port, u16 rmt_port, u8 proto)
{
- v4_connection_key_t key;
- memset (&key, 0, sizeof (v4_connection_key_t));
+ v4_connection_key_t *key = (v4_connection_key_t *) kv->key;
- key.src.as_u32 = lcl->as_u32;
- key.dst.as_u32 = rmt->as_u32;
- key.src_port = lcl_port;
- key.dst_port = rmt_port;
- key.proto = proto;
+ key->src.as_u32 = lcl->as_u32;
+ key->dst.as_u32 = rmt->as_u32;
+ key->src_port = lcl_port;
+ key->dst_port = rmt_port;
+ key->proto = proto;
- kv->key[0] = key.as_u64[0];
- kv->key[1] = key.as_u64[1];
kv->value = ~0ULL;
}
@@ -160,17 +157,14 @@ always_inline void
make_v4_listener_kv (session_kv4_t * kv, ip4_address_t * lcl, u16 lcl_port,
u8 proto)
{
- v4_connection_key_t key;
- memset (&key, 0, sizeof (v4_connection_key_t));
+ v4_connection_key_t *key = (v4_connection_key_t *) kv->key;
- key.src.as_u32 = lcl->as_u32;
- key.dst.as_u32 = 0;
- key.src_port = lcl_port;
- key.dst_port = 0;
- key.proto = proto;
+ key->src.as_u32 = lcl->as_u32;
+ key->dst.as_u32 = 0;
+ key->src_port = lcl_port;
+ key->dst_port = 0;
+ key->proto = proto;
- kv->key[0] = key.as_u64[0];
- kv->key[1] = key.as_u64[1];
kv->value = ~0ULL;
}
@@ -185,23 +179,17 @@ always_inline void
make_v6_ss_kv (session_kv6_t * kv, ip6_address_t * lcl, ip6_address_t * rmt,
u16 lcl_port, u16 rmt_port, u8 proto)
{
- v6_connection_key_t key;
- memset (&key, 0, sizeof (v6_connection_key_t));
-
- key.src.as_u64[0] = lcl->as_u64[0];
- key.src.as_u64[1] = lcl->as_u64[1];
- key.dst.as_u64[0] = rmt->as_u64[0];
- key.dst.as_u64[1] = rmt->as_u64[1];
- key.src_port = lcl_port;
- key.dst_port = rmt_port;
- key.proto = proto;
-
- kv->key[0] = key.as_u64[0];
- kv->key[1] = key.as_u64[1];
- kv->key[2] = 0;
- kv->key[3] = 0;
- kv->key[4] = 0;
- kv->key[5] = 0;
+ v6_connection_key_t *key = (v6_connection_key_t *) kv->key;
+
+ key->src.as_u64[0] = lcl->as_u64[0];
+ key->src.as_u64[1] = lcl->as_u64[1];
+ key->dst.as_u64[0] = rmt->as_u64[0];
+ key->dst.as_u64[1] = rmt->as_u64[1];
+ key->src_port = lcl_port;
+ key->dst_port = rmt_port;
+ key->proto = proto;
+ key->unused = 0;
+
kv->value = ~0ULL;
}
@@ -209,23 +197,17 @@ always_inline void
make_v6_listener_kv (session_kv6_t * kv, ip6_address_t * lcl, u16 lcl_port,
u8 proto)
{
- v6_connection_key_t key;
- memset (&key, 0, sizeof (v6_connection_key_t));
-
- key.src.as_u64[0] = lcl->as_u64[0];
- key.src.as_u64[1] = lcl->as_u64[1];
- key.dst.as_u64[0] = 0;
- key.dst.as_u64[1] = 0;
- key.src_port = lcl_port;
- key.dst_port = 0;
- key.proto = proto;
-
- kv->key[0] = key.as_u64[0];
- kv->key[1] = key.as_u64[1];
- kv->key[2] = 0;
- kv->key[3] = 0;
- kv->key[4] = 0;
- kv->key[5] = 0;
+ v6_connection_key_t *key = (v6_connection_key_t *) kv->key;
+
+ key->src.as_u64[0] = lcl->as_u64[0];
+ key->src.as_u64[1] = lcl->as_u64[1];
+ key->dst.as_u64[0] = 0;
+ key->dst.as_u64[1] = 0;
+ key->src_port = lcl_port;
+ key->dst_port = 0;
+ key->proto = proto;
+ key->unused = 0;
+
kv->value = ~0ULL;
}