| About Subscribe Categories Archives |
Patrick McHardy's blogTue, 02 Sep 2008nftables part II
A lot has happened since my last posting about nftables, so here's an update with the current status. I unfortunately failed to reach my goal of being able to replace my iptables based firewall by the end of August, but I'm getting close :) New kernel modulesI've added a few new kernel modules for missing functionality:
Payload expressionsI've added tons of new payload descriptions, it now supports:
OptimizationsConstant foldingConstant folding is now implemented, propagation of operations to the constant size is still missing. Adjacent payload load mergingI've added a first rule level optimization, adjacent payload expression merging. When payload expressions refer to consecutive header fields, we can merge the load operation
So far the expressions are mindlessly merged together, without regard to maximum size, alignment or whatever. The size must of course be taken into account since the kernel data types are fixed. Alignment currently doesn't matter, but I'm planning to optimize small, aligned data loads in the kernel, either by overloading the evaluation function or just special-casing. Providing the ability to overload operations probably would be useful for other common case optimizations. Value range trackingThis is not fully finished yet, but will allow two nice things when it is. The purpose is to track constraints of dynamic expressions when operations are applied to them. For instance, its easy to see that the expression "ip daddr & 0xf" can only take the values 0x0-0xf. More generally, we can track constraints bitwise and use them to determine the possible input range for lookups in dynamic sets and use that to choose the optimal representation. It can also be used to determine ineffective matches, but it only works on each expression separately and thus is just a subset of ineffective rule detection. Type checks and error reportingExpressions are fully checked for type compatiblity now. This includes sets, maps and concatenations.
Open problemsThere have been more changes, but I'll write about those another time. There are of course also a lot of open problems, mostly nothing too complicated, but also a few tricky ones. Match expression parsing
So far, all header expressions except addresses are treated as numerical values.
So you can't say "tcp flags SYN/SYN,ACK", but have to specify it numerically. This
needs to be fixed of course. The main problem is that both sides of a match expressions
are constructed through separate productions, for example the rule for a relational
expression is:
relational_expr : expr relational_op exprThe LHS expression might be a payload expression and the RHS a constant to compare. When parsing the RHS, we don't have the necessary context to accept special tokens related to the LHS. The reason for specifing the grammar like this is that dynamic expression can not only occur in matches, but also as arguments to targets or f.i. mappings. There are basically two possibilities to fix this that I can think of.
Again, match expression parsingAnother problem resulting from the fact that we don't have any context once an expression is parsed is that multiple related matches are cumbersome to specify. I've actually been cheating in my examples and shown the syntax as it should be, not as it currently is. For example you can't write "tcp sport 1024: dport 22", but have to write "tcp" twice to provide the necessary context: "tcp sport 1024: tcp dport 22". The only way I see that might *possibly* work (while keeping bison) is to do some YYBACKUP look-ahead token manipulation. Not too appealing either ... |