netfilter: nf_tables: add range expression
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: nf_tables: add range expression
Inverse ranges != [a,b] are not currently possible because rules are composites of && operations, and we need to express this:
data < a || data > b
This patch adds a new range expression. Positive ranges can be already through two cmp expressions:
cmp(sreg, data, >=) cmp(sreg, data, <=)
This new range expression provides an alternative way to express this.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/net/netfilter/nf_tables_core.h | 3 + include/uapi/linux/netfilter/nf_tables.h | 29 +++++++ net/netfilter/Makefile | 3 +- net/netfilter/nf_tables_core.c | 7 +- net/netfilter/nft_range.c | 138 +++++++++++++++++++++++++++++++ 5 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 net/netfilter/nft_range.c
include/net/netfilter/nf_tables_core.h +3 -0
@@ -28,6 +28,9 @@ extern const struct nft_expr_ops nft_cmp_fast_ops;int nft_cmp_module_init (void );void nft_cmp_module_exit (void ); +int nft_range_module_init (void ); +void nft_range_module_exit (void ); +int nft_lookup_module_init (void );void nft_lookup_module_exit (void );
include/uapi/linux/netfilter/nf_tables.h +29 -0
@@ -546,6 +546,35 @@ enum nft_cmp_attributes { };#define NFTA_CMP_MAX (__NFTA_CMP_MAX - 1) +/** +* enum nft_range_ops - nf_tables range operator +* +* @NFT_RANGE_EQ: equal +* @NFT_RANGE_NEQ: not equal +*/ +enum nft_range_ops { +NFT_RANGE_EQ , +NFT_RANGE_NEQ , +}; + +/** +* enum nft_range_attributes - nf_tables range expression netlink attributes +* +* @NFTA_RANGE_SREG: source register of data to compare (NLA_U32: nft_registers) +* @NFTA_RANGE_OP: cmp operation (NLA_U32: nft_cmp_ops) +* @NFTA_RANGE_FROM_DATA: data range from (NLA_NESTED: nft_data_attributes) +* @NFTA_RANGE_TO_DATA: data range to (NLA_NESTED: nft_data_attributes) +*/ +enum nft_range_attributes { +NFTA_RANGE_UNSPEC , +NFTA_RANGE_SREG , +NFTA_RANGE_OP , +NFTA_RANGE_FROM_DATA , +NFTA_RANGE_TO_DATA , + __NFTA_RANGE_MAX +}; +#define NFTA_RANGE_MAX (__NFTA_RANGE_MAX - 1) +enum nft_lookup_flags {NFT_LOOKUP_F_INV = (1 <<0 ), };
net/netfilter/Makefile +2 -1
@@ -71,8 +71,9 @@ obj-$(CONFIG_NF_DUP_NETDEV) += nf_dup_netdev.o # nf_tables nf_tables-objs += nf_tables_core.o nf_tables_api.o nf_tables_trace.o -nf_tables-objs += nft_immediate.o nft_cmp.o nft_lookup.o nft_dynset.o +nf_tables-objs += nft_immediate.o nft_cmp.o nft_range.o nf_tables-objs += nft_bitwise.o nft_byteorder.o nft_payload.o +nf_tables-objs += nft_lookup.o nft_dynset.o obj-$(CONFIG_NF_TABLES) += nf_tables.o obj-$(CONFIG_NF_TABLES_INET) += nf_tables_inet.o
net/netfilter/nf_tables_core.c +6 -1
@@ -263,8 +263,13 @@ int __init nf_tables_core_module_init(void)if (err <0 ) goto err7; -return 0 ; + err =nft_range_module_init (); +if (err <0 ) + goto err8; +return 0 ; +err8: +nft_dynset_module_exit (); err7:nft_payload_module_exit (); err6:
net/netfilter/nft_range.c new file +138 -0
138 lines not on this page · raw message
Signature · 1 line
2.1.4