netfilter: nft_cmp: optimize comparison for up to 16-bytes
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: nft_cmp: optimize comparison for up to 16-bytes
Allow up to 16-byte comparisons with the cmp fast version. Use two 64-bit words and calculate the mask representing the bits to be compared. Make sure the comparison is 64-bit aligned and avoid out-of-bound memory access.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/net/netfilter/nf_tables_core.h | 4 +-- net/netfilter/nf_tables_core.c | 6 +++- net/netfilter/nft_cmp.c | 48 +++++++++++++++++--------- 3 files changed, 38 insertions(+), 20 deletions(-)
include/net/netfilter/nf_tables_core.h +2 -2
@@ -35,8 +35,8 @@ struct nft_bitwise_fast_expr { };struct nft_cmp_fast_expr { -u32 data; -u32 mask; +struct nft_data data; +struct nft_data mask;u8 sreg;u8 len;bool inv;
net/netfilter/nf_tables_core.c +5 -1
@@ -61,8 +61,12 @@ static void nft_cmp_fast_eval(const struct nft_expr *expr, struct nft_regs *regs) {const struct nft_cmp_fast_expr *priv =nft_expr_priv (expr); +const u64 *reg_data = (const u64 *)®s->data[priv->sreg]; +const u64 *mask = (const u64 *)&priv->mask; +const u64 *data = (const u64 *)&priv->data; -if (((regs->data[priv->sreg] & priv->mask) == priv->data) ^ priv->inv) +if (((reg_data[0 ] & mask[0 ]) == data[0 ] && + ((reg_data[1 ] & mask[1 ]) == data[1 ])) ^ priv->inv)return ; regs->verdict.code =NFT_BREAK ; }
net/netfilter/nft_cmp.c +31 -17
107 lines not on this page · raw message
Signature · 1 line
2.30.2