Igalia / pflua

Packet filtering in Lua
Other
313 stars 39 forks source link

Give names to numeric literals #158

Closed kbara closed 9 years ago

kbara commented 9 years ago

Some numeric literals are scattered throughout expand.lua, which makes it trickier to understand/maintain/modify, etc. It would be fantastic if the literals were given meaningful names, so it was more obvious what protocols they were from and an idea of their semantics.

In general, lines like { '=', { '[ether]', 14, 1 }, PROTO_STP } } are a bit nicer than { '=', { '[ether]', 14, 4 }, 2863268608 }; with the 14 replaced by a name, they'd be better yet.

Examples:

   if proto > 1500 then return { '=', { '[ether]', 12, 2 }, proto } end
            { '<=', {'[ether]', 12, 2}, 1500 },
            { '=', { '[ether]', 14, 1}, proto } }
local function has_ipv6_protocol(proto)
            { '=', { '[ip6]', 6, 1 }, proto },
              { '=', { '[ip6]', 6, 1 }, 44 },
              { '=', { '[ip6]', 40, 1 }, proto } } }
local function expand_ip6_broadcast(expr)
   return { '=', { '[ip]', 16, 1 }, 224 }
kbara commented 9 years ago

Thank you.