ttl.lua 818 Bytes
Newer Older
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
1 2 3 4 5 6 7 8 9 10 11 12
--[[
TTL adjustment module for Alpine Wall
Copyright (C) 2012-2016 Kaarle Ritvanen
See LICENSE file for license details
]]--


local model = require('awall.model')


local TTLRule = model.class(model.Rule)

13
function TTLRule:trulefilter(rule) return rule.family == 'inet' end
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

function TTLRule:table() return 'mangle' end

function TTLRule:target()
   if not self.ttl then self:error('TTL not specified') end

   if type(self.ttl) == 'string' then
      if self.ttl:sub(1, 1) == '+' then
         return 'TTL --ttl-inc '..self.ttl:sub(2, -1)
      else self.ttl = tonumber(self.ttl) end
   end
   if type(self.ttl) ~= 'number' then
      self:error('Invalid TTL specification')
   end

   return 'TTL --ttl-'..(self.ttl < 0 and 'dec' or 'set')..' '..
      math.abs(self.ttl)
end

return {export={ttl={class=TTLRule}}}