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

Implement operator 'sctp' #141

Merged
merged 2 commits into from
Mar 11, 2015
Merged
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
6 changes: 5 additions & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ EXAMPLES = \
decnet-src-10.15.md \
decnet-host-10.15.md \
l1.md \
icmp6.md
icmp6.md \
sctp.md

PFLUA = \
../src/pf.lua \
Expand Down Expand Up @@ -157,3 +158,6 @@ l1.md: $(PFLUA)

icmp6.md: $(PFLUA)
../tools/dump-markdown "icmp6" > $@.tmp && mv $@.tmp $@

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


## BPF

```
000: A = P[12:2]
001: if (A == 34525) goto 2 else goto 7
002: A = P[20:1]
003: if (A == 132) goto 10 else goto 4
004: if (A == 44) goto 5 else goto 11
005: A = P[54:1]
006: if (A == 132) goto 10 else goto 11
007: if (A == 2048) goto 8 else goto 11
008: A = P[23:1]
009: if (A == 132) goto 10 else goto 11
010: return 65535
011: return 0
```


## BPF cross-compiled to Lua

```
return function (P, length)
local A = 0
if 14 > length then return false end
A = bit.bor(bit.lshift(P[12], 8), P[12+1])
if not (A==34525) then goto L6 end
if 21 > length then return false end
A = P[20]
if (A==132) then goto L9 end
if not (A==44) then goto L10 end
if 55 > length then return false end
A = P[54]
if (A==132) then goto L9 end
goto L10
::L6::
if not (A==2048) then goto L10 end
if 24 > length then return false end
A = P[23]
if not (A==132) then goto L10 end
::L9::
do return true end
::L10::
do return false end
error("end of bpf")
end
```


## Direct pflang compilation

```
local cast = require("ffi").cast
return function(P,length)
if length < 34 then return false end
local var1 = cast("uint16_t*", P+12)[0]
if var1 == 8 then
return P[23] == 132
end
if length < 54 then return false end
if var1 ~= 56710 then return false end
local var4 = P[20]
if var4 == 132 then return true end
if length < 55 then return false end
if var4 ~= 44 then return false end
return P[54] == 132
end

```

1 change: 1 addition & 0 deletions src/pf/expand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ local primitive_expanders = {
ah = function(expr) return has_ip_protocol(PROTO_AH) end,
esp = function(expr) return has_ip_protocol(PROTO_ESP) end,
vrrp = function(expr) return has_ip_protocol(PROTO_VRRP) end,
sctp = function(expr) return has_ip_protocol(PROTO_SCTP) end,
protochain = expand_ip_protochain,
arp = expand_arp,
arp_host = expand_arp_host,
Expand Down
1 change: 1 addition & 0 deletions src/pf/parse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ local primitives = {
ah = nullary(),
esp = nullary(),
vrrp = nullary(),
sctp = nullary(),
protochain = unary(parse_proto_arg),
arp = table_parser(arp_types, nullary()),
rarp = table_parser(rarp_types, nullary()),
Expand Down