Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IP version field and hop limit in keyed IPv6 tunnel app #223

Merged
merged 1 commit into from
Aug 11, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/apps/keyed_ipv6_tunnel/tunnel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down