Skip to contentSkip to conversation

netfilter: nft_hash: support of symmetric hash

PATCH Applied Laura Garcia Liebana 2 participants 2 messages Feb 23, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 netfilter: nft_hash: support of symmetric hash

This patch provides symmetric hash support according to source ip address and port, and destination ip address and port.

For this purpose, the __skb_get_hash_symmetric() is used to identify the flow as it uses FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL flag by default.

The new attribute NFTA_HASH_TYPE has been included to support different types of hashing functions. Currently supported NFT_HASH_JENKINS through jhash and NFT_HASH_SYM through symhash.

The main difference between both types are:
- jhash requires an expression with sreg, symhash doesn't.
- symhash supports modulus and offset, but not seed.

Examples:

nft add rule ip nat prerouting ct mark set jhash ip saddr mod 2 nft add rule ip nat prerouting ct mark set symhash mod 2

---
 include/uapi/linux/netfilter/nf_tables.h | 13 +++++
 net/netfilter/nft_hash.c                 | 98 +++++++++++++++++++++++++++++++-
 2 files changed, 110 insertions(+), 1 deletion(-)
include/uapi/linux/netfilter/nf_tables.h +13 -0
index 7b730cab99bd..a444a63a9eee 100644
@@ -793,6 +793,17 @@ enum nft_rt_keys {
 };
 
 /**
+ * enum nft_hash_types - nf_tables hash expression types
+ *
+ * @NFT_HASH_JENKINS: Jenkins Hash
+ * @NFT_HASH_SYM: Symmetric Hash
+ */
+enum nft_hash_types {
+	NFT_HASH_JENKINS,
+	NFT_HASH_SYM,
+};
+
+/**
  * enum nft_hash_attributes - nf_tables hash expression netlink attributes
  *
  * @NFTA_HASH_SREG: source register (NLA_U32)
@@ -801,6 +812,7 @@ enum nft_rt_keys {
  * @NFTA_HASH_MODULUS: modulus value (NLA_U32)
  * @NFTA_HASH_SEED: seed value (NLA_U32)
  * @NFTA_HASH_OFFSET: add this offset value to hash result (NLA_U32)
+ * @NFTA_HASH_TYPE: hash operation (NLA_U32: nft_hash_types)
  */
 enum nft_hash_attributes {
 	NFTA_HASH_UNSPEC,
@@ -810,6 +822,7 @@ enum nft_hash_attributes {
 	NFTA_HASH_MODULUS,
 	NFTA_HASH_SEED,
 	NFTA_HASH_OFFSET,
+	NFTA_HASH_TYPE,
 	__NFTA_HASH_MAX,
 };
 #define NFTA_HASH_MAX	(__NFTA_HASH_MAX - 1)
net/netfilter/nft_hash.c +97 -1

130 lines not on this page · raw message

Signature · 1 line
2.11.0
#1 lore raw
url: https://github.com/0day-ci/linux/commits/Laura-Garcia-Liebana/netfilter-nft_hash-symhash-type-support/20170223-205609 config: i386-randconfig-x018-201708 (attached as .config) compiler: gcc-6…

Hi Laura,

[auto build test WARNING on v4.9-rc8]
[cannot apply to next-20170223]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Laura-Garcia-Liebana/netfilter-nft_hash-symhash-type-support/20170223-205609
config: i386-randconfig-x018-201708 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

net/netfilter/nft_hash.c: In function 'nft_symhash_eval':

>> net/netfilter/nft_hash.c:55:48: warning: passing argument 1 of '__skb_get_hash_symmetric' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     h = reciprocal_scale(__skb_get_hash_symmetric(skb), priv->modulus);
                                                   ^~~
   In file included from include/linux/netlink.h:6:0,
                    from net/netfilter/nft_hash.c:13:
   include/linux/skbuff.h:1090:5: note: expected 'struct sk_buff *' but argument is of type 'const struct sk_buff *'
    u32 __skb_get_hash_symmetric(struct sk_buff *skb);
        ^~~~~~~~~~~~~~~~~~~~~~~~

vim +55 net/netfilter/nft_hash.c

    39	}
    40	
    41	struct nft_symhash {
    42		enum nft_registers      dreg:8;
    43		u32			modulus;
    44		u32			offset;
    45	};
    46	
    47	static void nft_symhash_eval(const struct nft_expr *expr,
    48				     struct nft_regs *regs,
    49				     const struct nft_pktinfo *pkt)
    50	{
    51		struct nft_symhash *priv = nft_expr_priv(expr);
    52		const struct sk_buff *skb = pkt->skb;
    53		u32 h;
    54	
  > 55		h = reciprocal_scale(__skb_get_hash_symmetric(skb), priv->modulus);
    56	
    57		regs->data[priv->dreg] = h + priv->offset;
    58	}
    59	
    60	static const struct nla_policy nft_hash_policy[NFTA_HASH_MAX + 1] = {
    61		[NFTA_HASH_SREG]	= { .type = NLA_U32 },
    62		[NFTA_HASH_DREG]	= { .type = NLA_U32 },
    63		[NFTA_HASH_LEN]		= { .type = NLA_U32 },

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation