History

netfilter: nft_dynset: dynamic stateful expression instantiation

Support instantiating stateful expressions based on a template that are associated with dynamically created set entries. The expressions are evaluated when adding or updating the set element. This allows to maintain per flow state using the existing set infrastructure and expression types, with arbitrary definitions of a flow. Usage is currently restricted to anonymous sets, meaning only a single binding can exist, since the desired semantics of multiple independant bindings haven't been defined so far. Examples (userspace syntax is still WIP): 1. Limit the rate of new SSH connections per host, similar to iptables hashlimit: flow ip saddr timeout 60s \ limit 10/second \ accept 2. Account network traffic between each set of /24 networks: flow ip saddr & 255.255.255.0 . ip daddr & 255.255.255.0 \ counter 3. Account traffic to each host per user: flow skuid . ip daddr \ counter 4. Account traffic for each combination of source address and TCP flags: flow ip saddr . tcp flags \ counter The resulting set content after a Xmas-scan look like this: { 192.168.122.1 . fin | psh | urg : counter packets 1001 bytes 40040, 192.168.122.1 . ack : counter packets 74 bytes 3848, 192.168.122.1 . psh | ack : counter packets 35 bytes 3144 }

Patrick McHardy committed 11 years ago

Commit 3e135cd1 parent 7c6c6e92 files · +52 −4Browse files

Showing the changes to include/uapi (1 of 2 files). Show all

Unified · Split

include/uapi/linux/netfilter/nf_tables.h+2−0
@@ -567,6 +567,7 @@ enum nft_dynset_ops { · 566 unmodified lines
567567 * @NFTA_DYNSET_SREG_KEY: source register of the key (NLA_U32)
568568 * @NFTA_DYNSET_SREG_DATA: source register of the data (NLA_U32)
569569 * @NFTA_DYNSET_TIMEOUT: timeout value for the new element (NLA_U64)
570+ * @NFTA_DYNSET_EXPR: expression (NLA_NESTED: nft_expr_attributes)
570571 */
571572 enum nft_dynset_attributes {
572573 NFTA_DYNSET_UNSPEC,
@@ -576,6 +577,7 @@ enum nft_dynset_attributes { · 3 unmodified lines
576577 NFTA_DYNSET_SREG_KEY,
577578 NFTA_DYNSET_SREG_DATA,
578579 NFTA_DYNSET_TIMEOUT,
580+ NFTA_DYNSET_EXPR,
579581 __NFTA_DYNSET_MAX,
580582 };
581583 #define NFTA_DYNSET_MAX (__NFTA_DYNSET_MAX - 1)