1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Precalc/reuse some tables and values

This commit is contained in:
dmiller
2020-11-30 17:59:18 +00:00
parent d3ef26b229
commit c8fdcd80b5
3 changed files with 13 additions and 9 deletions

View File

@@ -108,7 +108,10 @@ function enc (p, hexExtend)
end end
local db32table_standard = setmetatable({}, {__index = function (t, k) error "invalid encoding: invalid character" end}) local db32metatable = {
__index = function (t, k) error "invalid encoding: invalid character" end
}
local db32table_standard = setmetatable({}, db32metatable)
do do
local r = {["="] = 0} local r = {["="] = 0}
for i, v in ipairs(b32standard) do for i, v in ipairs(b32standard) do
@@ -118,7 +121,7 @@ do
db32table_standard[i] = r[char(i)] db32table_standard[i] = r[char(i)]
end end
end end
local db32table_hex = setmetatable({}, {__index = function (t, k) error "invalid encoding: invalid character" end}) local db32table_hex = setmetatable({}, db32metatable)
do do
local r = {["="] = 0} local r = {["="] = 0}
for i, v in ipairs(b32hexExtend) do for i, v in ipairs(b32hexExtend) do

View File

@@ -62,6 +62,7 @@ DHCP6.OptionTypes = {
OPTION_CLIENT_FQDN = 0x27, OPTION_CLIENT_FQDN = 0x27,
} }
local DHCP6_EPOCH = os.time({year=2000, day=1, month=1, hour=0, min=0, sec=0})
-- DHCP6 options -- DHCP6 options
DHCP6.Option = { DHCP6.Option = {
@@ -110,7 +111,7 @@ DHCP6.Option = {
type = DHCP6.OptionTypes.OPTION_CLIENTID, type = DHCP6.OptionTypes.OPTION_CLIENTID,
duid = duid or 1, duid = duid or 1,
hwtype = hwtype or 1, hwtype = hwtype or 1,
time = time or os.time() - os.time({year=2000, day=1, month=1, hour=0, min=0, sec=0}), time = time or os.time() - DHCP6_EPOCH,
mac = mac, mac = mac,
} }
setmetatable(o, self) setmetatable(o, self)
@@ -131,7 +132,7 @@ DHCP6.Option = {
end end
opt.hwtype, opt.time = string.unpack(">I2I4", data, pos) opt.hwtype, opt.time = string.unpack(">I2I4", data, pos)
opt.mac = data:sub(pos) opt.mac = data:sub(pos)
opt.time = opt.time + os.time({year=2000, day=1, month=1, hour=0, min=0, sec=0}) opt.time = opt.time + DHCP6_EPOCH
return opt return opt
end, end,

View File

@@ -1034,19 +1034,19 @@ local function cmp_last_used (r1, r2)
return (r1.last_used or 0) < (r2.last_used or 0); return (r1.last_used or 0) < (r2.last_used or 0);
end end
local arg_max_cache_size = tonumber(stdnse.get_script_args({'http.max-cache-size', 'http-max-cache-size'}) or 1e6);
local function check_size (cache) local function check_size (cache)
local max_size = tonumber(stdnse.get_script_args({'http.max-cache-size', 'http-max-cache-size'}) or 1e6);
local size = cache.size; local size = cache.size;
if size > max_size then if size > arg_max_cache_size then
stdnse.debug1( stdnse.debug1(
"Current http cache size (%d bytes) exceeds max size of %d", "Current http cache size (%d bytes) exceeds max size of %d",
size, max_size); size, arg_max_cache_size);
table.sort(cache, cmp_last_used); table.sort(cache, cmp_last_used);
for i, record in ipairs(cache) do for i, record in ipairs(cache) do
if size <= max_size then break end if size <= arg_max_cache_size then break end
local result = record.result; local result = record.result;
if type(result.body) == "string" then if type(result.body) == "string" then
size = size - record.size; size = size - record.size;
@@ -1056,7 +1056,7 @@ local function check_size (cache)
cache.size = size; cache.size = size;
end end
stdnse.debug2("Final http cache size (%d bytes) of max size of %d", stdnse.debug2("Final http cache size (%d bytes) of max size of %d",
size, max_size); size, arg_max_cache_size);
return size; return size;
end end