Skip to content

Commit

Permalink
fixup! Add javascript challenge sample
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorNogueiraRio committed Aug 11, 2020
1 parent b6ca132 commit 2eebe24
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions samples/bpf/checkcookie.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,17 @@ local function ip2int(ip)
return (oct4 << 24) + (oct3 << 16) + (oct2 << 8) + oct1
end

function loadcookieport(ip, port, cookie)
local ip = ip2int(ip)

if not cookies[ip] then
cookies[ip] = {}
end

cookies[ip][port] = cookie
end

function loadcookie(ip, cookie)
cookies[ip2int(ip)] = cookie
end

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

if not cookies[ip][port] then
if not cookies[ip] then
return true
end

return cookies[ip][port] == cookiepkt and true or false
end

function checkcookie(pkt, ip)
local cookiepkt = tonumber(string.match(tostring(pkt), "Cookie:%s__xdp=(.-)\r\n"))

return cookies[ip] == cookiepkt and true or false
end

0 comments on commit 2eebe24

Please sign in to comment.