comparison mod_dnsbl/mod_dnsbl.lua @ 6493:ccbba57cacb5

mod_dnsbl: Optimize by reducing method calls (thanks Zash)
author Matthew Wild <mwild1@gmail.com>
date Tue, 24 Mar 2026 20:54:04 +0000
parents b82fceda0abc
children 1213145e27fc
comparison
equal deleted inserted replaced
6492:b82fceda0abc 6493:ccbba57cacb5
97 local mod_flags = module:depends("flags"); 97 local mod_flags = module:depends("flags");
98 98
99 local function reverse(ip, suffix) 99 local function reverse(ip, suffix)
100 if ip.proto == "IPv4" then 100 if ip.proto == "IPv4" then
101 local query_string = ip.packed; 101 local query_string = ip.packed;
102 return ("%d.%d.%d.%d.%s"):format( 102 local a, b, c, d = query_string:byte(1, 4);
103 query_string:byte(4, 4), 103 return ("%d.%d.%d.%d.%s"):format(d, c, b, a, suffix);
104 query_string:byte(3, 3),
105 query_string:byte(2, 2),
106 query_string:byte(1, 1),
107 suffix
108 );
109 elseif ip.proto == "IPv6" then 104 elseif ip.proto == "IPv6" then
110 return hex.encode(ip.packed):reverse():gsub("%x", "%1.")..suffix; 105 return hex.encode(ip.packed):reverse():gsub("%x", "%1.")..suffix;
111 end 106 end
112 end 107 end
113 108