Comparison

mod_firewall/definitions.lib.lua @ 999:197af8440ffb

mod_firewall: Make defining objects generic (currently zones and rate limits), so more can easily be added. Also a syntax change... definition lines must begin with %
author Matthew Wild <mwild1@gmail.com>
date Tue, 07 May 2013 10:33:49 +0100
child 1863:92602cfac751
comparison
equal deleted inserted replaced
998:6fdcebbd2284 999:197af8440ffb
1
2 local definition_handlers = {};
3
4 local new_throttle = require "util.throttle".create;
5
6 function definition_handlers.ZONE(zone_name, zone_members)
7 local zone_member_list = {};
8 for member in zone_members:gmatch("[^, ]+") do
9 zone_member_list[#zone_member_list+1] = member;
10 end
11 return set.new(zone_member_list)._items;
12 end
13
14 function definition_handlers.RATE(name, line)
15 local rate = assert(tonumber(line:match("([%d.]+)")), "Unable to parse rate");
16 local burst = tonumber(line:match("%(%s*burst%s+([%d.]+)%s*%)")) or 1;
17 return new_throttle(rate*burst, burst);
18 end
19
20 return definition_handlers;