-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from Igalia/low-icmp6
Implement 'icmp6'
- Loading branch information
Showing
4 changed files
with
87 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters