filter-limit.lua 1.67 KB
Newer Older
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
1
update = require('awall.util').update
2 3 4 5 6 7
json = require('cjson')

res = {}

function add(limit_type, base)
   for _, count in ipairs{1, 30} do
8
      for _, limit in ipairs{
9 10 11 12
         count,
	 {count=count},
	 {count=count, log=false},
	 {count=count, log='none'}
13
      } do
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
14 15 16
         for _, name in ipairs{
            false, type(limit) == 'table' and count == 1 and 'foo' or nil
         } do
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
	    for _, addr in ipairs{false, name and 'dest' or nil} do
	       for _, no_update in ipairs{false, name or nil} do
	          local upd
	          if no_update then upd = false end
                  for _, log in ipairs{false, true, 'none'} do
                     for _, action in ipairs{false, 'pass'} do
	                if not (count == 30 and log and action) then
	                   table.insert(
	                      res,
		              update(
		                 {
		                    [limit_type..'-limit']=type(limit) == 'table' and update(
			               {
				          name=name or nil,
					  addr=addr or nil,
					  update=upd
				       },
				       limit
		                    ) or limit,
		                    log=log or nil,
		                    action=action or nil
		                 },
		                 base or {}
		              )
                           )
		        end
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
43
		     end
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
44
	          end
45 46
               end
	    end
47 48 49 50 51
	 end
      end
   end
end

52
add('conn', {out='B'})
53 54 55
add('flow')
add('flow', {['in']='A', out='_fw', ['no-track']=true})

Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
56 57 58 59 60 61 62 63
for _, measure in ipairs{'conn', 'flow'} do
   for _, addr in ipairs{'src', 'dest'} do
      table.insert(
         res, {['update-limit']={name='foo', measure=measure, addr=addr}}
      )
   end
end

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