Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated lua bindings, they are a mess, but at least they are here.
- Loading branch information
1 parent
4d6d155
commit 96bc726
Showing
11 changed files
with
1,997 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.so |
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 |
---|---|---|
@@ -1,6 +1,147 @@ | ||
#!/usr/bin/env lua | ||
#!/usr/bin/env lua5.1 | ||
|
||
dofile"test-misc.lua" | ||
dofile"test-ipv4.lua" | ||
dofile"test-decode.lua" | ||
require"net" | ||
require"netutil" | ||
|
||
hex_dump = h | ||
|
||
local function check_ipv4() | ||
local n = net.init("link", "eth0") | ||
n:ipv4{src="1.2.3.1", dst="1.2.3.2", protocol=2, len=20+4, options="AAAA"} | ||
n:eth{src="01:02:03:04:05:01", dst="01:02:03:04:05:02"} | ||
|
||
--ok=pcall(n.ipv4, n, {src="1.2.3.1", dst="1.2.3.2", protocol=2, len=20+4, options="AAAA"}) | ||
--assert(not ok, "net:ipv4 fails to detect incorrect usage of IPv4 options") | ||
end | ||
|
||
local function check_ptag() | ||
local n = net.init("link", "eth0") | ||
eth = n:eth{src="01:02:03:04:05:01", dst="01:02:03:04:05:02"} | ||
ok=pcall(n.ipv4, n, {src="1.2.3.1", dst="1.2.3.2", protocol=2, len=20+4, options="AAAA", ptag = eth}) | ||
assert(not ok, "net:ipv4 fails to detect specifying a ptag when creating IPv4 options") | ||
end | ||
|
||
local function check_first() | ||
local n = net.init("link", "eth0") | ||
ok=pcall(n.ipv4, n, {src="1.2.3.1", dst="1.2.3.2", protocol=2, len=20+4, options="AAAA"}) | ||
eth = n:eth{src="01:02:03:04:05:01", dst="01:02:03:04:05:02"} | ||
assert(ok, "net:ipv4 fails to construct ipv4 options correctly") | ||
end | ||
|
||
n = net.init("link", "eth0") | ||
|
||
print(q(net.pton("01:02:03:04:05:06"))) | ||
print(q(net.pton("1.2.3.4"))) | ||
print(q(net.pton("::1"))) | ||
|
||
n:udp{src=3, dst=5, payload="XXX"} | ||
ipv4 = n:ipv4{src="1.2.3.1", dst="1.2.3.2", protocol=17, len=20+8+3} | ||
n:eth{src="01:02:03:04:05:01", dst="01:02:03:04:05:02"} | ||
|
||
print(n:dump()) | ||
|
||
n:write() | ||
|
||
b1 = n:block() | ||
print(#b1, q(b1)) | ||
|
||
n:ipv4{src="1.2.3.1", dst="1.2.3.2", protocol=17, len=20+8+3, ptag=ipv4} | ||
|
||
--print(q({src="1.2.3.1", dst="1.2.3.2", protocol=17, len=20+8+3, ptag=ipv4})) | ||
|
||
print(n:dump()) | ||
|
||
b2 = n:block() | ||
|
||
print("b1=", q(b1)) | ||
print("b2=", q(b2)) | ||
|
||
assert(b1 == b2) | ||
|
||
check_ipv4() | ||
check_ptag() | ||
check_first() | ||
|
||
do | ||
print"\n\n# decode ipv4" | ||
|
||
local n = net.init("raw4", "eth0") | ||
|
||
n:udp{src=1, dst=2, payload=" "} | ||
n:ipv4{src="1.2.3.1", dst="1.2.3.2", protocol=17, len=20+4, options="AAAA"} | ||
|
||
local b0 = n:block() | ||
|
||
print"= constructed:" | ||
print(n:dump()) | ||
hex_dump(b0) | ||
|
||
n:clear() | ||
print(n:dump()) | ||
|
||
print"= decoded:" | ||
assert(n:decode_ipv4(b0)) | ||
|
||
local ip1 = n:block(n:tag_below()) | ||
local b1 = n:block() | ||
print(n:dump()) | ||
hex_dump(b1) | ||
print"" | ||
|
||
assert(b0 == b1) | ||
|
||
local bot = assert(n:tag_below()) | ||
local top = assert(n:tag_above()) | ||
|
||
print("bot", bot, "top", top) | ||
assert(bot == 3) | ||
assert(n:tag_below(bot) == nil) | ||
assert(n:tag_above(bot) == 2) | ||
|
||
assert(top == 1) | ||
assert(n:tag_above(top) == nil) | ||
assert(n:tag_below(top) == 2) | ||
|
||
assert(n:tag_type(bot) == "ipv4", n:tag_type(bot)) | ||
assert(n:tag_type(top) == "udp", n:tag_type(top)) | ||
|
||
udpt = n:get_udp() | ||
udpt.payload = "\0" | ||
assert(udpt.ptag == top) | ||
assert(n:udp(udpt)) | ||
|
||
local b2 = n:block() | ||
print(n:dump()) | ||
hex_dump(b2) | ||
|
||
-- everything up to the checksum should be the same | ||
assert(b1:sub(1, 20+4+6) == b2:sub(1, 20+4+6)) | ||
assert(b1:sub(20+4+7, 20+4+8) ~= b2:sub(20+4+7, 20+4+8)) | ||
|
||
assert(#n:block(n:tag_above()) == (8+1)) | ||
assert(n:block(n:tag_below()) == ip1) | ||
|
||
print"+pass" | ||
end | ||
|
||
do | ||
print"\n\n# pblock dump" | ||
|
||
local n = net.init("raw4", "eth0") | ||
|
||
n:udp{src=1, dst=2, payload=" "} | ||
n:ipv4{src="1.2.3.1", dst="1.2.3.2", protocol=17, len=20+4, options="AAAA"} | ||
|
||
local ptag = n:tag_above() | ||
while ptag do | ||
--print("ptag", ptag) | ||
local pblock = n:pblock(ptag) | ||
local buf = pblock.buf | ||
pblock.buf = nil | ||
print(pblock, h(buf)) | ||
ptag = pblock.next | ||
end | ||
end | ||
|
||
dofile"recoding-test" | ||
|
Oops, something went wrong.