From e77c7c63f97078515053f7da1307e4313fa988b0 Mon Sep 17 00:00:00 2001 From: Alexander Gall Date: Thu, 3 Jul 2014 10:34:57 +0200 Subject: [PATCH] Fix IP version field and hop limit in keyed IPv6 tunnel app The IP version field was set incorrectly. The default hop limit was changed from 0 to 64 and made configurable. --- src/apps/keyed_ipv6_tunnel/tunnel.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/apps/keyed_ipv6_tunnel/tunnel.lua b/src/apps/keyed_ipv6_tunnel/tunnel.lua index 92c2c33757..d549a96f3f 100644 --- a/src/apps/keyed_ipv6_tunnel/tunnel.lua +++ b/src/apps/keyed_ipv6_tunnel/tunnel.lua @@ -64,6 +64,7 @@ local NEXT_HEADER_OFFSET = local SESSION_ID_OFFSET = ffi.offsetof(header_struct_ctype, 'session_id') local FLOW_ID_OFFSET = ffi.offsetof(header_struct_ctype, 'flow_id') +local HOP_LIMIT_OFFSET = ffi.offsetof(header_struct_ctype, 'hop_limit') local SESSION_COOKIE_SIZE = 12 -- 32 bit session and 64 bit cookie @@ -84,8 +85,9 @@ local function prepare_header_template () -- Ver. Set to 0x6 to indicate IPv6. -- version is 4 first bits at this offset -- no problem to set others 4 bits to zeros - it is already zeros - header_template[FLOW_ID_OFFSET] = 0x06 + header_template[FLOW_ID_OFFSET] = 0x60 + header_template[HOP_LIMIT_OFFSET] = 64 header_template[NEXT_HEADER_OFFSET] = L2TPV3_NEXT_HEADER -- For cases where both tunnel endpoints support one-stage resolution @@ -110,6 +112,7 @@ function SimpleKeyedTunnel:new (confstring) -- optional fields: -- local_session, unsigned number, must fit to uint32_t -- default_gateway_MAC, useful for testing + -- hop_limit, override default hop limit 64 assert( type(config.local_cookie) == "string" and #config.local_cookie == 8, @@ -153,6 +156,12 @@ function SimpleKeyedTunnel:new (confstring) ffi.copy(header + DST_MAC_OFFSET, mac.bytes, 6) end + if config.hop_limit then + assert(type(config.hop_limit) == 'number' and + config.hop_limit <= 255, "invalid hop limit") + header[HOP_LIMIT_OFFSET] = config.hop_limit + end + local o = { header = header,