Skip to content

Commit 2eebe24

Browse files
fixup! Add javascript challenge sample
1 parent b6ca132 commit 2eebe24

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

samples/bpf/checkcookie.lua

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,17 @@ local function ip2int(ip)
1717
return (oct4 << 24) + (oct3 << 16) + (oct2 << 8) + oct1
1818
end
1919

20-
function loadcookieport(ip, port, cookie)
21-
local ip = ip2int(ip)
22-
23-
if not cookies[ip] then
24-
cookies[ip] = {}
25-
end
26-
27-
cookies[ip][port] = cookie
28-
end
29-
3020
function loadcookie(ip, cookie)
3121
cookies[ip2int(ip)] = cookie
3222
end
3323

34-
function checkcookieport(pkt, ip, port)
35-
local cookiepkt = tonumber(string.match(tostring(pkt), "Cookie:%s__xdp=(.-)\r\n"))
36-
if not cookies[ip] then
37-
return true
38-
end
24+
function checkcookie(pkt, ip)
25+
local pattern = 'Cookie:%s*=__xdp=(%d+)%s*'
26+
local cookiepkt = tonumber(string.match(tostring(pkt), pattern))
3927

40-
if not cookies[ip][port] then
28+
if not cookies[ip] then
4129
return true
4230
end
4331

44-
return cookies[ip][port] == cookiepkt and true or false
45-
end
46-
47-
function checkcookie(pkt, ip)
48-
local cookiepkt = tonumber(string.match(tostring(pkt), "Cookie:%s__xdp=(.-)\r\n"))
49-
5032
return cookies[ip] == cookiepkt and true or false
5133
end

0 commit comments

Comments
 (0)