-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-udp.lua
164 lines (109 loc) · 3.43 KB
/
test-udp.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
dofile"setup.lua"
test("+udp", function()
local n = net.init()
local datat = {payload="xxx"}
local udpt = {spo="xxx"}
local ipt = {src="1.2.3.4", dst="5.6.7.8", protocol=17, options="AAA"}
local etht = {src="01:02:03:01:02:03", dst="04:05:06:04:05:06"}
local pkt = "0405060405060102030102030800".. -- eth
"4600001b000000004011e77d0102030405060708"..
h"AAA".."00".. -- ipo, padded
"787878" -- payload
local dtag = n:data(datat)
local itag = n:ipv4(ipt)
local etag = n:eth(etht)
local b = n:block()
dump(n)
assert(pkt == h(b), h(b))
n:clear()
ipt.payload = datat.payload
local itag = n:ipv4(ipt)
local etag = n:eth(etht)
local b = n:block()
dump(n)
print("i", pkt)
print("o", h(b))
assert(pkt == h(b), h(b))
n:clear()
local pkt = "0405060405060102030102030800".. -- eth
"450000170000000040116ac30102030405060708"..
"787878" -- payload
ipt.options = nil
local itag = n:ipv4(ipt)
local etag = n:eth(etht)
local b = n:block()
dump(n)
print("i", pkt)
print("o", h(b))
assert(pkt == h(b), h(b))
n:clear()
local pkt = "0405060405060102030102030800".. -- eth
"450000140000000040116ac60102030405060708"
ipt.options = nil
ipt.payload = nil
local itag = n:ipv4(ipt)
local etag = n:eth(etht)
local b = n:block()
dump(n)
print("i", pkt)
print("o", h(b))
assert(pkt == h(b), h(b))
local pkt = "0405060405060102030102030800".. -- eth
"46000018000000004011e7800102030405060708"..
h"AAA".."00" -- ipo, padded
ipt.options = "AAA"
ipt.ptag = itag
assert(itag == n:ipv4(ipt))
local b = n:block()
dump(n)
print("i", pkt)
print("o", h(b))
assert(pkt == h(b), h(b))
local pkt = "0405060405060102030102030800".. -- eth
"4600001b000000004011e77d0102030405060708"..
h"AAA".."00".. -- ipo, padded
"787878" -- payload
ipt.payload = "xxx"
assert(itag == n:ipv4(ipt))
local b = n:block()
dump(n)
print("i", pkt)
print("o", h(b))
assert(pkt == h(b), h(b))
local pkt = "0405060405060102030102030800".. -- eth
"4500001a0000000040116ac00102030405060708"..
"787878" -- payload
ipt.options = nil
assert(itag == n:ipv4(ipt))
local b = n:block()
dump(n)
print("i", pkt)
print("o", h(b))
assert(pkt == h(b), h(b))
end)
test("+ipv4, replace eth with ipv4", function()
local n = net.init()
local eth = n:eth{src="01:02:03:04:05:01", dst="01:02:03:04:05:02"}
local ok,emsg=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, emsg)
print("successfully failed", emsg)
end)
test("+ipv4 w/options mutation", function()
local n = net.init()
local ptag = 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"}
dump(n, 14+24)
n:ipv4{src="1.2.3.1", dst="1.2.3.2", protocol=2, len=20+4, options="BB", ptag=ptag}
dump(n, 14+24)
n:ipv4{src="1.2.3.1", dst="1.2.3.2", protocol=2, len=20+0, ptag=ptag}
dump(n, 14+20)
n:ipv4{src="1.2.3.1", dst="1.2.3.2", protocol=2, len=20+8, options="DDDDD", ptag=ptag}
dump(n, 14+28)
end)
test("-ipv4 with invalid ptag", function()
local n = net.init()
assert(not pcall(
n.ipv4, n, {src="1.2.3.1", dst="1.2.3.2", protocol=2, len=20+8, options="DDDDD", ptag=999}
)
)
end)