From b34c3eee2bf5cb05a6f47c0ed9e318632c8dc534 Mon Sep 17 00:00:00 2001 From: Luke Gorrie Date: Mon, 22 Feb 2016 13:06:18 +0000 Subject: [PATCH 1/3] engine: Set shm path to "app/$name" Set the shared memory path (shm.path) to a private namespace for each app with prefix "app/$name". This means that apps can create shm objects such as counters and by default these will appear in a local namespace for that app. --- src/core/app.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/app.lua b/src/core/app.lua index 35a5305631..099fc3125a 100644 --- a/src/core/app.lua +++ b/src/core/app.lua @@ -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") @@ -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) @@ -75,6 +78,7 @@ local function with_restart (app, method) else method(app) end + shm.path = oldshm end -- Restart dead apps. @@ -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))) @@ -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 From c8169686dca3190074fd778c29258fb7c6228c54 Mon Sep 17 00:00:00 2001 From: Luke Gorrie Date: Mon, 22 Feb 2016 13:08:27 +0000 Subject: [PATCH 2/3] keyed_ipv6_tunnel: Add counters for packet drops This change introduces new counters for each instance of the keyed_ipv6_tunnel app: drop_bad_length drop_bad_protocol drop_bad_cookie drop_bad_remote_address These counters are externally visible as shm objects on the filesystem: /var/run/snabb/$pid/app/$appname/$counter --- src/apps/keyed_ipv6_tunnel/tunnel.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/apps/keyed_ipv6_tunnel/tunnel.lua b/src/apps/keyed_ipv6_tunnel/tunnel.lua index 9bf92eafa5..846f44a9fe 100644 --- a/src/apps/keyed_ipv6_tunnel/tunnel.lua +++ b/src/apps/keyed_ipv6_tunnel/tunnel.lua @@ -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") @@ -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}) @@ -196,15 +203,18 @@ 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 @@ -212,6 +222,7 @@ function SimpleKeyedTunnel:push() 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 @@ -219,6 +230,7 @@ function SimpleKeyedTunnel:push() 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 From 8bd582129b8d74f909a6efbc5b0c8f760a81536a Mon Sep 17 00:00:00 2001 From: Luke Gorrie Date: Mon, 22 Feb 2016 13:45:52 +0000 Subject: [PATCH 3/3] apps/ipv6/README: Document keyed_ipv6_counters I am not sure for exactly which historical reason the README is located so far away from the source code but this seems like the place :-) --- src/apps/ipv6/README.md | 24 ++++++++++++++++++++++++ src/apps/ipv6/README.md.src | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/apps/ipv6/README.md b/src/apps/ipv6/README.md index 3de0003190..489fcdb732 100644 --- a/src/apps/ipv6/README.md +++ b/src/apps/ipv6/README.md @@ -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. + + diff --git a/src/apps/ipv6/README.md.src b/src/apps/ipv6/README.md.src index 2ecdec57f1..9cd64c9cc3 100644 --- a/src/apps/ipv6/README.md.src +++ b/src/apps/ipv6/README.md.src @@ -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. + +