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

[wip] Ipv6 tunnel diagnostics #767

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions src/apps/ipv6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,27 @@ the L2TPv3 header will be overwritten with this value.

*Optional*. Destination MAC as a string. Not required if overwritten by
an app such as `nd_light`.

### Counters

— Key **drop_bad_length**

Ingress packets dropped due to invalid length (packet too short).

— Key **drop_bad_protocol**

Ingress packets dropped due to unrecognized IPv6 protocol ID.

— Key **drop_bad_cookie**

Ingress packets dropped due to wrong cookie value.

— Key **drop_bad_remote_address**

Ingress packets dropped due to wrong remote IPv6 endpoint address.

— Key **drop_bad_local_address**

Ingress packets dropped due to wrong local IPv6 endpoint address.


24 changes: 24 additions & 0 deletions src/apps/ipv6/README.md.src
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,27 @@ the L2TPv3 header will be overwritten with this value.

*Optional*. Destination MAC as a string. Not required if overwritten by
an app such as `nd_light`.

### Counters

— Key **drop_bad_length**

Ingress packets dropped due to invalid length (packet too short).

— Key **drop_bad_protocol**

Ingress packets dropped due to unrecognized IPv6 protocol ID.

— Key **drop_bad_cookie**

Ingress packets dropped due to wrong cookie value.

— Key **drop_bad_remote_address**

Ingress packets dropped due to wrong remote IPv6 endpoint address.

— Key **drop_bad_local_address**

Ingress packets dropped due to wrong local IPv6 endpoint address.


14 changes: 13 additions & 1 deletion src/apps/keyed_ipv6_tunnel/tunnel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local link = require("core.link")
local lib = require("core.lib")
local packet = require("core.packet")
local config = require("core.config")
local counter = require("core.counter")

local macaddress = require("lib.macaddress")

Expand Down Expand Up @@ -166,7 +167,13 @@ function SimpleKeyedTunnel:new (arg)
header = header,
remote_address = remote_address,
local_address = local_address,
remote_cookie = remote_cookie[0]
remote_cookie = remote_cookie[0],
-- Counters:
drop_bad_length = counter.open('drop_bad_length'),
drop_bad_protocol = counter.open('drop_bad_protocol'),
drop_bad_cookie = counter.open('drop_bad_cookie'),
drop_bad_remote_address = counter.open('drop_bad_remote_address'),
drop_bad_local_address = counter.open('drop_bad_local_address')
}

return setmetatable(o, {__index = SimpleKeyedTunnel})
Expand Down Expand Up @@ -196,29 +203,34 @@ function SimpleKeyedTunnel:push()
local drop = true
repeat
if p.length < HEADER_SIZE then
counter.add(self.drop_bad_length)
break
end
local next_header = ffi.cast(next_header_ctype, p.data + NEXT_HEADER_OFFSET)
if next_header[0] ~= L2TPV3_NEXT_HEADER then
counter.add(self.drop_bad_protocol)
break
end

local cookie = ffi.cast(pcookie_ctype, p.data + COOKIE_OFFSET)
if cookie[0] ~= self.remote_cookie then
counter.add(self.drop_bad_cookie)
break
end

local remote_address = ffi.cast(paddress_ctype, p.data + SRC_IP_OFFSET)
if remote_address[0] ~= self.remote_address[0] or
remote_address[1] ~= self.remote_address[1]
then
counter.add(self.drop_bad_remote_address)
break
end

local local_address = ffi.cast(paddress_ctype, p.data + DST_IP_OFFSET)
if local_address[0] ~= self.local_address[0] or
local_address[1] ~= self.local_address[1]
then
counter.add(self.drop_bad_local_address)
break
end

Expand Down
9 changes: 9 additions & 0 deletions src/core/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local lib = require("core.lib")
local link = require("core.link")
local config = require("core.config")
local timer = require("core.timer")
local shm = require("core.shm")
local counter = require("core.counter")
local zone = require("jit.zone")
local ffi = require("ffi")
Expand Down Expand Up @@ -65,6 +66,8 @@ end
-- Run app:methodname() in protected mode (pcall). If it throws an
-- error app will be marked as dead and restarted eventually.
local function with_restart (app, method)
local oldshm = shm.path
shm.path = app.shmpath
if use_restart then
-- Run fn in protected mode using pcall.
local status, err = pcall(method, app)
Expand All @@ -75,6 +78,7 @@ local function with_restart (app, method)
else
method(app)
end
shm.path = oldshm
end

-- Restart dead apps.
Expand Down Expand Up @@ -162,7 +166,11 @@ function apply_config_actions (actions, conf)
function ops.start (name)
local class = conf.apps[name].class
local arg = conf.apps[name].arg
local shmpath, shmorig = "app/"..name, shm.path
shm.path = shmpath
local app = class:new(arg)
shm.path = shmorig
local shmpath = "app/"..name
if type(app) ~= 'table' then
error(("bad return value from app '%s' start() method: %s"):format(
name, tostring(app)))
Expand All @@ -171,6 +179,7 @@ function apply_config_actions (actions, conf)
app.appname = name
app.output = {}
app.input = {}
app.shmpath = shmpath
new_app_table[name] = app
table.insert(new_app_array, app)
app_name_to_index[name] = #new_app_array
Expand Down