filter-limit.lua 1.76 KB
Newer Older
1
util = require('awall.util')
2 3 4 5
json = require('cjson')

res = {}

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
function add(limit_type, filter)

   for _, high_rate in ipairs{false, true} do

      local function add_limit(limit)
         for _, log in ipairs{false, true, 'none'} do
            for _, action in ipairs{false, 'pass'} do
               if not (high_rate and log and action) then
	          table.insert(
	             res,
	             util.update(
	                {
		           [limit_type..'-limit']=util.copy(limit),
		           log=log or nil,
		           action=action or nil
	                },
		        filter or {}
	             )
                  )
	       end
            end
         end
      end

30 31
      local count = high_rate and 150 or nil
      add_limit(count or 1)
32

33 34 35 36
      for _, interval in ipairs{false, 5} do
         for _, log in ipairs{true, false, 'none'} do
	    local limit = {count=count, interval=interval or nil}
	    if log ~= true then limit.log = log end
37

38
            add_limit(limit)
39

40
	    if not high_rate then
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
41 42
	       for _, name in ipairs{'A', 'C'} do
	          limit.name = name
43

Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
44 45
	          for _, addr in ipairs{false, 'dest'} do
	             limit.addr = addr or nil
46

Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
47 48
	             limit.update = nil
	             add_limit(limit)
49

Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
50 51 52
	             limit.update = false
	             add_limit(limit)
	          end
53
	       end
54
	    end
55 56 57 58 59
	 end
      end
   end
end

60
add('conn', {out='B'})
61 62 63
add('flow')
add('flow', {['in']='A', out='_fw', ['no-track']=true})

Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
64 65 66
for _, name in ipairs{'A', 'B', 'C', 'D'} do
   table.insert(res, {['update-limit']=name})
end
67

Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
68 69 70
for _, measure in ipairs{'conn', 'flow'} do
   for _, addr in ipairs{'src', 'dest'} do
      table.insert(
71
         res, {['update-limit']={name='A', measure=measure, addr=addr}}
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
72 73 74 75
      )
   end
end

76
print(json.encode{filter=res})