netfilter: nft_hash: support of symmetric hash
Subsystems (2)
PATCH v3 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
By default, jenkins hash will be used if no hash type is provided for compatibility reasons.
---
v2:
- Avoid warning due to 'const' from symhash eval skb
v3:
- Set jhash as default ops, according to Liping and Pablo
suggestions.
include/uapi/linux/netfilter/nf_tables.h | 13 +++++ net/netfilter/nft_hash.c | 99 +++++++++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 1 deletion(-)
include/uapi/linux/netfilter/nf_tables.h +13 -0
@@ -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 +98 -1
131 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerQuoted 15 lines · Laura Garcia Liebana
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 usesFLOW_DISSECTOR_F_STOP_AT_FLOW_LABELflag by default.The new attribute
NFTA_HASH_TYPEhas been included to support different types of hashing functions. Currently supportedNFT_HASH_JENKINSthrough jhash andNFT_HASH_SYMthrough 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.
Quoted 7 lines
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
By default, jenkins hash will be used if no hash type is provided for compatibility reasons.
Also applied, thanks Laura.