Commit 9704add7 authored by Marek Vavruša's avatar Marek Vavruša Committed by Marek Vavruša

lua/bpf: support for NET_OFF for dissector

the packet can now use indirect addressing mode
using NET_OFF to read from network protocol off

it has convenience dissectors for IPv4 and IPv6,
that can be used like:

```
local net = pkt.net_off
if net.ver == 4 then
    local ip = net.ip
else
    local ip6 = net.ip6
end
```
parent f762df56
...@@ -78,6 +78,9 @@ struct bpf { ...@@ -78,6 +78,9 @@ struct bpf {
static const int F_USER_STACK = 1 << 8; static const int F_USER_STACK = 1 << 8;
static const int F_FAST_STACK_CMP = 1 << 9; static const int F_FAST_STACK_CMP = 1 << 9;
static const int F_REUSE_STACKID = 1 << 10; static const int F_REUSE_STACKID = 1 << 10;
/* special offsets for ancillary data */
static const int NET_OFF = -0x100000;
static const int LL_OFF = -0x200000;
}; };
/* eBPF commands */ /* eBPF commands */
struct bpf_cmd { struct bpf_cmd {
......
...@@ -35,6 +35,10 @@ struct sk_buff { ...@@ -35,6 +35,10 @@ struct sk_buff {
uint32_t tc_classid; uint32_t tc_classid;
}; };
struct net_off_t {
uint8_t ver:4;
} __attribute__((packed));
struct eth_t { struct eth_t {
uint8_t dst[6]; uint8_t dst[6];
uint8_t src[6]; uint8_t src[6];
...@@ -275,12 +279,23 @@ M.udp = function (...) return dissector(ffi.typeof('struct udp_t'), ...) end ...@@ -275,12 +279,23 @@ M.udp = function (...) return dissector(ffi.typeof('struct udp_t'), ...) end
M.tcp = function (...) return dissector(ffi.typeof('struct tcp_t'), ...) end M.tcp = function (...) return dissector(ffi.typeof('struct tcp_t'), ...) end
M.vxlan = function (...) return dissector(ffi.typeof('struct vxlan_t'), ...) end M.vxlan = function (...) return dissector(ffi.typeof('struct vxlan_t'), ...) end
M.data = function (...) return dissector(ffi.typeof('uint8_t'), ...) end M.data = function (...) return dissector(ffi.typeof('uint8_t'), ...) end
M.net_off = function (...) return dissector(ffi.typeof('struct net_off_t'), ...) end
-- Metatables -- Metatables
ffi.metatype(ffi.typeof('struct eth_t'), { ffi.metatype(ffi.typeof('struct eth_t'), {
__index = { __index = {
ip = skip_eth, ip = skip_eth,
ip6 = skip_eth, ip6 = skip_eth,
net_off = function (e, dst)
next_skip(e, dst, BPF.NET_OFF)
end,
}
})
ffi.metatype(ffi.typeof('struct net_off_t'), {
__index = {
ip = function () end,
ip6 = function () end,
} }
}) })
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment