From ebfd6822498965cdb9961ec1a986f0463de5c9c0 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Tue, 28 Jul 2009 14:17:35 +0200 Subject: add support for new set API and standalone sets Signed-off-by: Patrick McHardy --- include/expression.h | 20 +- include/linux/netfilter/nf_tables.h | 374 +++++++++++++++++++++++++++++++----- include/netlink.h | 16 ++ include/rule.h | 67 ++++++- 4 files changed, 421 insertions(+), 56 deletions(-) (limited to 'include') diff --git a/include/expression.h b/include/expression.h index 471033e7..88042846 100644 --- a/include/expression.h +++ b/include/expression.h @@ -26,6 +26,7 @@ * @EXPR_CONCAT: concatenation * @EXPR_LIST: list of expressions * @EXPR_SET: literal set + * @EXPR_SET_REF: set reference * @EXPR_MAPPING: a single mapping (key => value) * @EXPR_MAP: map operation (expr map { EXPR_MAPPING, ... }) * @EXPR_UNARY: byteorder conversion, generated during evaluation @@ -46,6 +47,7 @@ enum expr_types { EXPR_CONCAT, EXPR_LIST, EXPR_SET, + EXPR_SET_REF, EXPR_MAPPING, EXPR_MAP, EXPR_UNARY, @@ -82,6 +84,12 @@ enum ops { extern const char *expr_op_symbols[]; +enum symbol_types { + SYMBOL_VALUE, + SYMBOL_DEFINE, + SYMBOL_SET, +}; + /** * struct expr_ctx - type context for symbol parsing during evaluation * @@ -129,14 +137,12 @@ struct expr_ops { * @EXPR_F_CONSTANT: constant expression * @EXPR_F_SINGLETON: singleton (implies primary and constant) * @EXPR_F_INTERVAL_END: set member ends an open interval - * @SET_F_INTERVAL: set includes ranges and/or prefix expressions */ enum expr_flags { EXPR_F_PRIMARY = 0x1, EXPR_F_CONSTANT = 0x2, EXPR_F_SINGLETON = 0x4, EXPR_F_INTERVAL_END = 0x8, - SET_F_INTERVAL = 0x10, }; #include @@ -176,6 +182,7 @@ struct expr { /* EXPR_SYMBOL */ const struct scope *scope; const char *identifier; + enum symbol_types symtype; }; struct { /* EXPR_VERDICT */ @@ -195,6 +202,11 @@ struct expr { /* EXPR_CONCAT, EXPR_LIST, EXPR_SET */ struct list_head expressions; unsigned int size; + uint32_t set_flags; + }; + struct { + /* EXPR_SET_REF */ + struct set *set; }; struct { /* EXPR_UNARY */ @@ -285,6 +297,7 @@ extern struct expr *verdict_expr_alloc(const struct location *loc, int verdict, const char *chain); extern struct expr *symbol_expr_alloc(const struct location *loc, + enum symbol_types type, struct scope *scope, const char *identifier); static inline void symbol_expr_set_type(struct expr *expr, @@ -324,4 +337,7 @@ extern struct expr *mapping_expr_alloc(const struct location *loc, extern struct expr *map_expr_alloc(const struct location *loc, struct expr *arg, struct expr *list); +extern struct expr *set_ref_expr_alloc(const struct location *loc, + struct set *set); + #endif /* NFTABLES_EXPRESSION_H */ diff --git a/include/linux/netfilter/nf_tables.h b/include/linux/netfilter/nf_tables.h index 0309b9dc..1c230730 100644 --- a/include/linux/netfilter/nf_tables.h +++ b/include/linux/netfilter/nf_tables.h @@ -11,6 +11,17 @@ enum nft_registers { }; #define NFT_REG_MAX (__NFT_REG_MAX - 1) +/** + * enum nft_verdicts - nf_tables internal verdicts + * + * @NFT_CONTINUE: continue evaluation of the current rule + * @NFT_BREAK: terminate evaluation of the current rule + * @NFT_JUMP: push the current chain on the jump stack and jump to a chain + * @NFT_GOTO: jump to a chain without pushing the current chain on the jump stack + * @NFT_RETURN: return to the topmost chain on the jump stack + * + * The nf_tables verdicts share their numeric space with the netfilter verdicts. + */ enum nft_verdicts { NFT_CONTINUE = -1, NFT_BREAK = -2, @@ -29,9 +40,20 @@ enum nf_tables_msg_types { NFT_MSG_NEWRULE, NFT_MSG_GETRULE, NFT_MSG_DELRULE, + NFT_MSG_NEWSET, + NFT_MSG_GETSET, + NFT_MSG_DELSET, + NFT_MSG_NEWSETELEM, + NFT_MSG_GETSETELEM, + NFT_MSG_DELSETELEM, NFT_MSG_MAX, }; +/** + * enum nft_list_attributes - nf_tables generic list netlink attributes + * + * @NFTA_LIST_ELEM: list element (NLA_NESTED) + */ enum nft_list_attributes { NFTA_LIST_UNPEC, NFTA_LIST_ELEM, @@ -39,6 +61,12 @@ enum nft_list_attributes { }; #define NFTA_LIST_MAX (__NFTA_LIST_MAX - 1) +/** + * enum nft_hook_attributes - nf_tables netfilter hook netlink attributes + * + * @NFTA_HOOK_HOOKNUM: netfilter hook number (NLA_U32) + * @NFTA_HOOK_PRIORITY: netfilter hook priority (NLA_U32) + */ enum nft_hook_attributes { NFTA_HOOK_UNSPEC, NFTA_HOOK_HOOKNUM, @@ -47,6 +75,11 @@ enum nft_hook_attributes { }; #define NFTA_HOOK_MAX (__NFTA_HOOK_MAX - 1) +/** + * enum nft_table_attributes - nf_tables table netlink attributes + * + * @NFTA_TABLE_NAME: name of the table (NLA_STRING) + */ enum nft_table_attributes { NFTA_TABLE_UNSPEC, NFTA_TABLE_NAME, @@ -54,6 +87,13 @@ enum nft_table_attributes { }; #define NFTA_TABLE_MAX (__NFTA_TABLE_MAX - 1) +/** + * enum nft_chain_attributes - nf_tables chain netlink attributes + * + * @NFTA_CHAIN_TABLE: name of the table containing the chain (NLA_STRING) + * @NFTA_CHAIN_NAME: name of the chain (NLA_STRING) + * @NFTA_CHAIN_HOOK: hook specification for basechains (NLA_NESTED: nft_hook_attributes) + */ enum nft_chain_attributes { NFTA_CHAIN_UNSPEC, NFTA_CHAIN_TABLE, @@ -63,6 +103,14 @@ enum nft_chain_attributes { }; #define NFTA_CHAIN_MAX (__NFTA_CHAIN_MAX - 1) +/** + * enum nft_rule_attributes - nf_tables rule netlink attributes + * + * @NFTA_RULE_TABLE: name of the table containing the rule (NLA_STRING) + * @NFTA_RULE_CHAIN: name of the chain containing the rule (NLA_STRING) + * @NFTA_RULE_HANDLE: numeric handle of the rule (NLA_U16) + * @NFTA_RULE_EXPRESSIONS: list of expressions (NLA_NESTED: nft_expr_attributes) + */ enum nft_rule_attributes { NFTA_RULE_UNSPEC, NFTA_RULE_TABLE, @@ -73,6 +121,113 @@ enum nft_rule_attributes { }; #define NFTA_RULE_MAX (__NFTA_RULE_MAX - 1) +/** + * enum nft_set_flags - nf_tables set flags + * + * @NFT_SET_ANONYMOUS: name allocation, automatic cleanup on unlink + * @NFT_SET_CONSTANT: set contents may not change while bound + * @NFT_SET_INTERVAL: set contains intervals + * @NFT_SET_MAP: set is used as a dictionary + */ +enum nft_set_flags { + NFT_SET_ANONYMOUS = 0x1, + NFT_SET_CONSTANT = 0x2, + NFT_SET_INTERVAL = 0x4, + NFT_SET_MAP = 0x8, +}; + +/** + * enum nft_set_attributes - nf_tables set netlink attributes + * + * @NFTA_SET_TABLE: table name (NLA_STRING) + * @NFTA_SET_NAME: set name (NLA_STRING) + * @NFTA_SET_FLAGS: bitmask of enum nft_set_flags (NLA_U32) + * @NFTA_SET_KEY_TYPE: key data type, informational purpose only (NLA_U32) + * @NFTA_SET_KEY_LEN: key data length (NLA_U32) + * @NFTA_SET_DATA_TYPE: mapping data type (NLA_U32) + * @NFTA_SET_DATA_LEN: mapping data length (NLA_U32) + */ +enum nft_set_attributes { + NFTA_SET_UNSPEC, + NFTA_SET_TABLE, + NFTA_SET_NAME, + NFTA_SET_FLAGS, + NFTA_SET_KEY_TYPE, + NFTA_SET_KEY_LEN, + NFTA_SET_DATA_TYPE, + NFTA_SET_DATA_LEN, + __NFTA_SET_MAX +}; +#define NFTA_SET_MAX (__NFTA_SET_MAX - 1) + +/** + * enum nft_set_elem_flags - nf_tables set element flags + * + * @NFT_SET_ELEM_INTERVAL_END: element ends the previous interval + */ +enum nft_set_elem_flags { + NFT_SET_ELEM_INTERVAL_END = 0x1, +}; + +/** + * enum nft_set_elem_attributes - nf_tables set element netlink attributes + * + * @NFTA_SET_ELEM_KEY: key value (NLA_NESTED: nft_data) + * @NFTA_SET_ELEM_DATA: data value of mapping (NLA_NESTED: nft_data_attributes) + * @NFTA_SET_ELEM_FLAGS: bitmask of nft_set_elem_flags (NLA_U32) + */ +enum nft_set_elem_attributes { + NFTA_SET_ELEM_UNSPEC, + NFTA_SET_ELEM_KEY, + NFTA_SET_ELEM_DATA, + NFTA_SET_ELEM_FLAGS, + __NFTA_SET_ELEM_MAX +}; +#define NFTA_SET_ELEM_MAX (__NFTA_SET_ELEM_MAX - 1) + +/** + * enum nft_set_elem_list_attributes - nf_tables set element list netlink attributes + * + * @NFTA_SET_ELEM_LIST_TABLE: table of the set to be changed (NLA_STRING) + * @NFTA_SET_ELEM_LIST_SET: name of the set to be changed (NLA_STRING) + * @NFTA_SET_ELEM_LIST_ELEMENTS: list of set elements (NLA_NESTED: nft_set_elem_attributes) + */ +enum nft_set_elem_list_attributes { + NFTA_SET_ELEM_LIST_UNSPEC, + NFTA_SET_ELEM_LIST_TABLE, + NFTA_SET_ELEM_LIST_SET, + NFTA_SET_ELEM_LIST_ELEMENTS, + __NFTA_SET_ELEM_LIST_MAX +}; +#define NFTA_SET_ELEM_LIST_MAX (__NFTA_SET_ELEM_LIST_MAX - 1) + +/** + * enum nft_data_types - nf_tables data types + * + * @NFT_DATA_VALUE: generic data + * @NFT_DATA_VERDICT: netfilter verdict + * + * The type of data is usually determined by the kernel directly and is not + * explicitly specified by userspace. The only difference are sets, where + * userspace specifies the key and mapping data types. + * + * The values 0xffffff00-0xffffffff are reserved for internally used types. + * The remaining range can be freely used by userspace to encode types, all + * values are equivalent to NFT_DATA_VALUE. + */ +enum nft_data_types { + NFT_DATA_VALUE, + NFT_DATA_VERDICT = 0xffffff00U, +}; + +#define NFT_DATA_RESERVED_MASK 0xffffff00U + +/** + * enum nft_data_attributes - nf_tables data netlink attributes + * + * @NFTA_DATA_VALUE: generic data (NLA_BINARY) + * @NFTA_DATA_VERDICT: nf_tables verdict (NLA_NESTED: nft_verdict_attributes) + */ enum nft_data_attributes { NFTA_DATA_UNSPEC, NFTA_DATA_VALUE, @@ -81,6 +236,12 @@ enum nft_data_attributes { }; #define NFTA_DATA_MAX (__NFTA_DATA_MAX - 1) +/** + * enum nft_verdict_attributes - nf_tables verdict netlink attributes + * + * @NFTA_VERDICT_CODE: nf_tables verdict (NLA_U32: enum nft_verdicts) + * @NFTA_VERDICT_CHAIN: jump target chain name (NLA_STRING) + */ enum nft_verdict_attributes { NFTA_VERDICT_UNSPEC, NFTA_VERDICT_CODE, @@ -89,6 +250,12 @@ enum nft_verdict_attributes { }; #define NFTA_VERDICT_MAX (__NFTA_VERDICT_MAX - 1) +/** + * enum nft_expr_attributes - nf_tables expression netlink attributes + * + * @NFTA_EXPR_NAME: name of the expression type (NLA_STRING) + * @NFTA_EXPR_DATA: type specific data (NLA_NESTED) + */ enum nft_expr_attributes { NFTA_EXPR_UNSPEC, NFTA_EXPR_NAME, @@ -97,6 +264,12 @@ enum nft_expr_attributes { }; #define NFTA_EXPR_MAX (__NFTA_EXPR_MAX - 1) +/** + * enum nft_immediate_attributes - nf_tables immediate expression netlink attributes + * + * @NFTA_IMMEDIATE_DREG: destination register to load data into (NLA_U32) + * @NFTA_IMMEDIATE_DATA: data to load (NLA_NESTED: nft_data_attributes) + */ enum nft_immediate_attributes { NFTA_IMMEDIATE_UNSPEC, NFTA_IMMEDIATE_DREG, @@ -105,6 +278,27 @@ enum nft_immediate_attributes { }; #define NFTA_IMMEDIATE_MAX (__NFTA_IMMEDIATE_MAX - 1) +/** + * enum nft_bitwise_attributes - nf_tables bitwise expression netlink attributes + * + * @NFTA_BITWISE_SREG: source register (NLA_U32: nft_registers) + * @NFTA_BITWISE_DREG: destination register (NLA_U32: nft_registers) + * @NFTA_BITWISE_LEN: length of operands (NLA_U32) + * @NFTA_BITWISE_MASK: mask value (NLA_NESTED: nft_data_attributes) + * @NFTA_BITWISE_XOR: xor value (NLA_NESTED: nft_data_attributes) + * + * The bitwise expression performs the following operation: + * + * dreg = (sreg & mask) ^ xor + * + * which allow to express all bitwise operations: + * + * mask xor + * NOT: 1 1 + * OR: 0 x + * XOR: 1 x + * AND: x 0 + */ enum nft_bitwise_attributes { NFTA_BITWISE_UNSPEC, NFTA_BITWISE_SREG, @@ -141,6 +335,13 @@ enum nft_cmp_ops { NFT_CMP_GTE, }; +/** + * enum nft_cmp_attributes - nf_tables cmp expression netlink attributes + * + * @NFTA_CMP_SREG: source register of data to compare (NLA_U32: nft_registers) + * @NFTA_CMP_OP: cmp operation (NLA_U32: nft_cmp_ops) + * @NFTA_CMP_DATA: data to compare against (NLA_NESTED: nft_data_attributes) + */ enum nft_cmp_attributes { NFTA_CMP_UNSPEC, NFTA_CMP_SREG, @@ -150,65 +351,36 @@ enum nft_cmp_attributes { }; #define NFTA_CMP_MAX (__NFTA_CMP_MAX - 1) -enum nft_set_elem_flags { - NFT_SE_INTERVAL_END = 0x1, -}; - -enum nft_set_elem_attributes { - NFTA_SE_UNSPEC, - NFTA_SE_KEY, - NFTA_SE_DATA, - NFTA_SE_FLAGS, - __NFTA_SE_MAX -}; -#define NFTA_SE_MAX (__NFTA_SE_MAX - 1) - -enum nft_set_flags { - NFT_SET_INTERVAL = 0x1, - NFT_SET_MAP = 0x2, -}; - -enum nft_set_attributes { - NFTA_SET_UNSPEC, - NFTA_SET_FLAGS, - NFTA_SET_SREG, - NFTA_SET_DREG, - NFTA_SET_KLEN, - NFTA_SET_DLEN, - NFTA_SET_ELEMENTS, - __NFTA_SET_MAX -}; -#define NFTA_SET_MAX (__NFTA_SET_MAX - 1) - -enum nft_hash_flags { - NFT_HASH_MAP = 0x1, -}; - -enum nft_hash_elem_attributes { - NFTA_HE_UNSPEC, - NFTA_HE_KEY, - NFTA_HE_DATA, - __NFTA_HE_MAX -}; -#define NFTA_HE_MAX (__NFTA_HE_MAX - 1) - -enum nft_hash_attributes { - NFTA_HASH_UNSPEC, - NFTA_HASH_FLAGS, - NFTA_HASH_SREG, - NFTA_HASH_DREG, - NFTA_HASH_KLEN, - NFTA_HASH_ELEMENTS, - __NFTA_HASH_MAX -}; -#define NFTA_HASH_MAX (__NFTA_HASH_MAX - 1) - +enum nft_lookup_attributes { + NFTA_LOOKUP_UNSPEC, + NFTA_LOOKUP_SET, + NFTA_LOOKUP_SREG, + NFTA_LOOKUP_DREG, + __NFTA_LOOKUP_MAX +}; +#define NFTA_LOOKUP_MAX (__NFTA_LOOKUP_MAX - 1) + +/** + * enum nft_payload_bases - nf_tables payload expression offset bases + * + * @NFT_PAYLOAD_LL_HEADER: link layer header + * @NFT_PAYLOAD_NETWORK_HEADER: network header + * @NFT_PAYLOAD_TRANSPORT_HEADER: transport header + */ enum nft_payload_bases { NFT_PAYLOAD_LL_HEADER, NFT_PAYLOAD_NETWORK_HEADER, NFT_PAYLOAD_TRANSPORT_HEADER, }; +/** + * enum nft_payload_attributes - nf_tables payload expression netlink attributes + * + * @NFTA_PAYLOAD_DREG: destination register to load data into (NLA_U32: nft_registers) + * @NFTA_PAYLOAD_BASE: payload base (NLA_U32: nft_payload_bases) + * @NFTA_PAYLOAD_OFFSET: payload offset relative to base (NLA_U32) + * @NFTA_PAYLOAD_LEN: payload length (NLA_U32) + */ enum nft_payload_attributes { NFTA_PAYLOAD_UNSPEC, NFTA_PAYLOAD_DREG, @@ -229,6 +401,25 @@ enum nft_exthdr_attributes { }; #define NFTA_EXTHDR_MAX (__NFTA_EXTHDR_MAX - 1) +/** + * enum nft_meta_keys - nf_tables meta expression keys + * + * @NFT_META_LEN: packet length (skb->len) + * @NFT_META_PROTOCOL: packet ethertype protocol (skb->protocol), invalid in OUTPUT + * @NFT_META_PRIORITY: packet priority (skb->priority) + * @NFT_META_MARK: packet mark (skb->mark) + * @NFT_META_IIF: packet input interface index (dev->ifindex) + * @NFT_META_OIF: packet output interface index (dev->ifindex) + * @NFT_META_IIFNAME: packet input interface name (dev->name) + * @NFT_META_OIFNAME: packet output interface name (dev->name) + * @NFT_META_IIFTYPE: packet input interface type (dev->type) + * @NFT_META_OIFTYPE: packet output interface type (dev->type) + * @NFT_META_SKUID: originating socket UID (fsuid) + * @NFT_META_SKGID: originating socket GID (fsgid) + * @NFT_META_NFTRACE: packet nftrace bit + * @NFT_META_RTCLASSID: realm value of packet's route (skb->dst->tclassid) + * @NFT_META_SECMARK: packet secmark (skb->secmark) + */ enum nft_meta_keys { NFT_META_LEN, NFT_META_PROTOCOL, @@ -247,6 +438,12 @@ enum nft_meta_keys { NFT_META_SECMARK, }; +/** + * enum nft_meta_attributes - nf_tables meta expression netlink attributes + * + * @NFTA_META_DREG: destination register (NLA_U32) + * @NFTA_META_KEY: meta data item to load (NLA_U32: nft_meta_keys) + */ enum nft_meta_attributes { NFTA_META_UNSPEC, NFTA_META_DREG, @@ -255,6 +452,23 @@ enum nft_meta_attributes { }; #define NFTA_META_MAX (__NFTA_META_MAX - 1) +/** + * enum nft_ct_keys - nf_tables ct expression keys + * + * @NFT_CT_STATE: conntrack state (bitmask of enum ip_conntrack_info) + * @NFT_CT_DIRECTION: conntrack direction (enum ip_conntrack_dir) + * @NFT_CT_STATUS: conntrack status (bitmask of enum ip_conntrack_status) + * @NFT_CT_MARK: conntrack mark value + * @NFT_CT_SECMARK: conntrack secmark value + * @NFT_CT_EXPIRATION: relative conntrack expiration time in ms + * @NFT_CT_HELPER: connection tracking helper assigned to conntrack + * @NFT_CT_L3PROTOCOL: conntrack layer 3 protocol + * @NFT_CT_SRC: conntrack layer 3 protocol source (IPv4/IPv6 address) + * @NFT_CT_DST: conntrack layer 3 protocol destination (IPv4/IPv6 address) + * @NFT_CT_PROTOCOL: conntrack layer 4 protocol + * @NFT_CT_PROTO_SRC: conntrack layer 4 protocol source + * @NFT_CT_PROTO_DST: conntrack layer 4 protocol destination + */ enum nft_ct_keys { NFT_CT_STATE, NFT_CT_DIRECTION, @@ -271,6 +485,13 @@ enum nft_ct_keys { NFT_CT_PROTO_DST, }; +/** + * enum nft_ct_attributes - nf_tables ct expression netlink attributes + * + * @NFTA_CT_DREG: destination register (NLA_U32) + * @NFTA_CT_KEY: conntrack data item to load (NLA_U32: nft_ct_keys) + * @NFTA_CT_DIRECTION: direction in case of directional keys (NLA_U8) + */ enum nft_ct_attributes { NFTA_CT_UNSPEC, NFTA_CT_DREG, @@ -280,6 +501,12 @@ enum nft_ct_attributes { }; #define NFTA_CT_MAX (__NFTA_CT_MAX - 1) +/** + * enum nft_limit_attributes - nf_tables limit expression netlink attributes + * + * @NFTA_LIMIT_RATE: refill rate (NLA_U64) + * @NFTA_LIMIT_DEPTH: bucket depth (NLA_U64) + */ enum nft_limit_attributes { NFTA_LIMIT_UNSPEC, NFTA_LIMIT_RATE, @@ -288,6 +515,12 @@ enum nft_limit_attributes { }; #define NFTA_LIMIT_MAX (__NFTA_LIMIT_MAX - 1) +/** + * enum nft_counter_attributes - nf_tables counter expression netlink attributes + * + * @NFTA_COUNTER_BYTES: number of bytes (NLA_U64) + * @NFTA_COUNTER_PACKETS: number of packets (NLA_U64) + */ enum nft_counter_attributes { NFTA_COUNTER_UNSPEC, NFTA_COUNTER_BYTES, @@ -296,6 +529,14 @@ enum nft_counter_attributes { }; #define NFTA_COUNTER_MAX (__NFTA_COUNTER_MAX - 1) +/** + * enum nft_log_attributes - nf_tables log expression netlink attributes + * + * @NFTA_LOG_GROUP: netlink group to send messages to (NLA_U32) + * @NFTA_LOG_PREFIX: prefix to prepend to log messages (NLA_STRING) + * @NFTA_LOG_SNAPLEN: length of payload to include in netlink message (NLA_U32) + * @NFTA_LOG_QTHRESHOLD: queue threshold (NLA_U32) + */ enum nft_log_attributes { NFTA_LOG_UNSPEC, NFTA_LOG_GROUP, @@ -306,11 +547,23 @@ enum nft_log_attributes { }; #define NFTA_LOG_MAX (__NFTA_LOG_MAX - 1) +/** + * enum nft_reject_types - nf_tables reject expression reject types + * + * @NFT_REJECT_ICMP_UNREACH: reject using ICMP unreachable + * @NFT_REJECT_TCP_RST: reject using TCP RST + */ enum nft_reject_types { NFT_REJECT_ICMP_UNREACH, NFT_REJECT_TCP_RST, }; +/** + * enum nft_reject_attributes - nf_tables reject expression netlink attributes + * + * @NFTA_REJECT_TYPE: packet type to use (NLA_U32: nft_reject_types) + * @NFTA_REJECT_ICMP_CODE: ICMP code to use (NLA_U8) + */ enum nft_reject_attributes { NFTA_REJECT_UNSPEC, NFTA_REJECT_TYPE, @@ -319,11 +572,26 @@ enum nft_reject_attributes { }; #define NFTA_REJECT_MAX (__NFTA_REJECT_MAX - 1) +/** + * enum nft_nat_types - nf_tables nat expression NAT types + * + * @NFT_NAT_SNAT: source NAT + * @NFT_NAT_DNAT: destination NAT + */ enum nft_nat_types { NFT_NAT_SNAT, NFT_NAT_DNAT, }; +/** + * enum nft_nat_attributes - nf_tables nat expression netlink attributes + * + * @NFTA_NAT_TYPE: NAT type (NLA_U32: nft_nat_types) + * @NFTA_NAT_ADDR_MIN: source register of address range start (NLA_U32: nft_registers) + * @NFTA_NAT_ADDR_MAX: source register of address range end (NLA_U32: nft_registers) + * @NFTA_NAT_PROTO_MIN: source register of proto range start (NLA_U32: nft_registers) + * @NFTA_NAT_PROTO_MAX: source register of proto range end (NLA_U32: nft_registers) + */ enum nft_nat_attributes { NFTA_NAT_UNSPEC, NFTA_NAT_TYPE, diff --git a/include/netlink.h b/include/netlink.h index ec9a6142..22ef489c 100644 --- a/include/netlink.h +++ b/include/netlink.h @@ -16,10 +16,12 @@ * * @msgs: message queue * @list: list of parsed rules/chains/tables + * @set: current set */ struct netlink_ctx { struct list_head *msgs; struct list_head list; + struct set *set; }; extern void netlink_dump_object(struct nl_object *obj); @@ -28,6 +30,7 @@ extern struct nfnl_nft_table *alloc_nft_table(const struct handle *h); extern struct nfnl_nft_chain *alloc_nft_chain(const struct handle *h); extern struct nfnl_nft_rule *alloc_nft_rule(const struct handle *h); extern struct nfnl_nft_expr *alloc_nft_expr(int (*init)(struct nfnl_nft_expr *)); +extern struct nfnl_nft_set *alloc_nft_set(const struct handle *h); extern struct nfnl_nft_data *alloc_nft_data(const void *data, unsigned int len); extern struct nfnl_nft_data *netlink_gen_data(const struct expr *expr); @@ -68,4 +71,17 @@ extern int netlink_get_table(struct netlink_ctx *ctx, const struct handle *h); extern int netlink_list_table(struct netlink_ctx *ctx, const struct handle *h); extern int netlink_flush_table(struct netlink_ctx *ctx, const struct handle *h); +extern int netlink_add_set(struct netlink_ctx *ctx, const struct handle *h, + struct set *set); +extern int netlink_delete_set(struct netlink_ctx *ctx, const struct handle *h); +extern int netlink_list_sets(struct netlink_ctx *ctx, const struct handle *h); +extern int netlink_get_set(struct netlink_ctx *ctx, const struct handle *h); + +extern int netlink_add_setelems(struct netlink_ctx *ctx, const struct handle *h, + const struct expr *expr); +extern int netlink_delete_setelems(struct netlink_ctx *ctx, const struct handle *h, + const struct expr *expr); +extern int netlink_get_setelems(struct netlink_ctx *ctx, const struct handle *h, + struct set *set); + #endif /* NFTABLES_NETLINK_H */ diff --git a/include/rule.h b/include/rule.h index 01eeb210..97543072 100644 --- a/include/rule.h +++ b/include/rule.h @@ -6,17 +6,19 @@ #include /** - * struct handle - handle for tables, chains and rules + * struct handle - handle for tables, chains, rules and sets * * @family: protocol family * @table: table name * @chain: chain name (chains and rules only) + * @set: set name (sets only) * @handle: rule handle (rules only) */ struct handle { int family; const char *table; const char *chain; + const char *set; uint32_t handle; }; @@ -61,12 +63,14 @@ extern struct symbol *symbol_lookup(const struct scope *scope, * @list: list node * @handle: table handle * @chains: chains contained in the table + * @sets: sets contained in the table */ struct table { struct list_head list; struct handle handle; struct scope scope; struct list_head chains; + struct list_head sets; }; extern struct table *table_alloc(void); @@ -120,6 +124,53 @@ extern struct rule *rule_alloc(const struct location *loc, extern void rule_free(struct rule *rule); extern void rule_print(const struct rule *rule); +/** + * enum set_flags + * + * @SET_F_CONSTANT: Set content is constant + * @SET_F_INTERVAL: set includes ranges and/or prefix expressions + */ +enum set_flags { + SET_F_ANONYMOUS = 0x1, + SET_F_CONSTANT = 0x2, + SET_F_INTERVAL = 0x4, + SET_F_MAP = 0x8, +}; + +/** + * struct set - nftables set + * + * @list: table set list node + * @handle: set handle + * @location: location the set was defined/declared at + * @refcnt: reference count + * @flags: bitmask of set flags + * @keytype: key data type + * @keylen: key length + * @datatype: mapping data type + * @datalen: mapping data len + * @init: initializer + */ +struct set { + struct list_head list; + struct handle handle; + struct location location; + unsigned int refcnt; + uint32_t flags; + const struct datatype *keytype; + unsigned int keylen; + const struct datatype *datatype; + unsigned int datalen; + struct expr *init; +}; + +extern struct set *set_alloc(const struct location *loc); +extern struct set *set_get(struct set *set); +extern void set_free(struct set *set); +extern void set_add_hash(struct set *set, struct table *table); +extern struct set *set_lookup(const struct table *table, const char *name); +extern void set_print(const struct set *set); + /** * enum cmd_ops - command operations * @@ -141,12 +192,18 @@ enum cmd_ops { * enum cmd_obj - command objects * * @CMD_OBJ_INVALID: invalid + * @CMD_OBJ_SETELEM: set element(s) + * @CMD_OBJ_SET: set + * @CMD_OBJ_SETS: multiple sets * @CMD_OBJ_RULE: rule * @CMD_OBJ_CHAIN: chain * @CMD_OBJ_TABLE: table */ enum cmd_obj { CMD_OBJ_INVALID, + CMD_OBJ_SETELEM, + CMD_OBJ_SET, + CMD_OBJ_SETS, CMD_OBJ_RULE, CMD_OBJ_CHAIN, CMD_OBJ_TABLE, @@ -170,6 +227,8 @@ struct cmd { struct handle handle; union { void *data; + struct expr *expr; + struct set *set; struct rule *rule; struct chain *chain; struct table *table; @@ -187,12 +246,18 @@ extern void cmd_free(struct cmd *cmd); * struct eval_ctx - evaluation context * * @msgs: message queue + * @cmd: current command + * @table: current table + * @set: current set * @stmt: current statement * @ectx: expression context * @pctx: payload context */ struct eval_ctx { struct list_head *msgs; + struct cmd *cmd; + struct table *table; + struct set *set; struct stmt *stmt; struct expr_ctx ectx; struct payload_ctx pctx; -- cgit v1.2.3