Skip to content

Commit

Permalink
Merge pull request #84 from Igalia/low-icmp6
Browse files Browse the repository at this point in the history
Implement 'icmp6'
  • Loading branch information
kbara committed Nov 17, 2014
2 parents f430f91 + 25df994 commit 986dd87
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 11 deletions.
6 changes: 5 additions & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ EXAMPLES = \
ip-proto-sctp.md \
decnet-src-10.15.md \
decnet-host-10.15.md \
l1.md
l1.md \
icmp6.md

PFLUA = \
../src/pf.lua \
Expand Down Expand Up @@ -135,3 +136,6 @@ decnet-host-10.15.md:

l1.md:
../tools/dump-markdown "l1" > $@.tmp && mv $@.tmp $@

icmp6.md:
../tools/dump-markdown "icmp6" > $@.tmp && mv $@.tmp $@
68 changes: 68 additions & 0 deletions doc/icmp6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# icmp6


## BPF

```
000: A = P[12:2]
001: if (A == 34525) goto 2 else goto 8
002: A = P[20:1]
003: if (A == 58) goto 7 else goto 4
004: if (A == 44) goto 5 else goto 8
005: A = P[54:1]
006: if (A == 58) goto 7 else goto 8
007: return 65535
008: return 0
```


## BPF cross-compiled to Lua

```
return function (P, length)
local A = 0
if 14 > length then return 0 end
A = bit.bor(bit.lshift(P[12], 8), P[12+1])
if not (A==34525) then goto L7 end
if 21 > length then return 0 end
A = P[20]
if (A==58) then goto L6 end
if not (A==44) then goto L7 end
if 55 > length then return 0 end
A = P[54]
if not (A==58) then goto L7 end
::L6::
do return 65535 end
::L7::
do return 0 end
error("end of bpf")
end
```


## Direct pflang compilation

```
return function(P,length)
if not (length >= 54) then do return false end end
do
local v1 = ffi.cast("uint16_t*", P+12)[0]
if not (v1 == 56710) then do return false end end
do
local v2 = P[20]
if v2 == 58 then do return true end end
do
if not (length >= 55) then do return false end end
do
if not (v2 == 44) then do return false end end
do
local v3 = P[54]
do return v3 == 58 end
end
end
end
end
end
end
```

23 changes: 13 additions & 10 deletions src/pf/expand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ local ether_min_payloads = {

-- IP protocols
local PROTO_ICMP = 1 -- 0x1
local PROTO_ICMP6 = 58 -- 0x3a
local PROTO_TCP = 6 -- 0x6
local PROTO_UDP = 17 -- 0x11
local PROTO_SCTP = 132 -- 0x84
Expand Down Expand Up @@ -405,16 +406,17 @@ local function expand_ip_protochain(expr)
end

local ip_protos = {
icmp = PROTO_ICMP,
igmp = PROTO_IGMP,
igrp = PROTO_IGRP,
pim = PROTO_PIM,
ah = PROTO_AH,
esp = PROTO_ESP,
vrrp = PROTO_VRRP,
udp = PROTO_UDP,
tcp = PROTO_TCP,
sctp = PROTO_SCTP,
icmp = PROTO_ICMP,
icmp6 = PROTO_ICMP6,
igmp = PROTO_IGMP,
igrp = PROTO_IGRP,
pim = PROTO_PIM,
ah = PROTO_AH,
esp = PROTO_ESP,
vrrp = PROTO_VRRP,
udp = PROTO_UDP,
tcp = PROTO_TCP,
sctp = PROTO_SCTP,
}

local function expand_ip4_proto(expr)
Expand Down Expand Up @@ -859,6 +861,7 @@ local primitive_expanders = {
udp_src_portrange = expand_udp_src_portrange,
udp_dst_portrange = expand_udp_dst_portrange,
icmp = function(expr) return has_ip_protocol(PROTO_ICMP) end,
icmp6 = function(expr) return has_ipv6_protocol(PROTO_ICMP6) end,
igmp = function(expr) return has_ip_protocol(PROTO_IGMP) end,
igrp = function(expr) return has_ip_protocol(PROTO_IGRP) end,
pim = function(expr) return has_ip_protocol(PROTO_PIM) end,
Expand Down
1 change: 1 addition & 0 deletions src/pf/parse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ local primitives = {
tcp = table_parser(tcp_or_udp_types, nullary()),
udp = table_parser(tcp_or_udp_types, nullary()),
icmp = nullary(),
icmp6 = nullary(),
igmp = nullary(),
igrp = nullary(),
pim = nullary(),
Expand Down

0 comments on commit 986dd87

Please sign in to comment.