4 #include <linux/xfrm.h>
5 #include <linux/socket.h>
7 static inline unsigned int __xfrm4_addr_hash(const xfrm_address_t
*addr
)
9 return ntohl(addr
->a4
);
12 static inline unsigned int __xfrm6_addr_hash(const xfrm_address_t
*addr
)
14 return ntohl(addr
->a6
[2] ^ addr
->a6
[3]);
17 static inline unsigned int __xfrm4_daddr_saddr_hash(const xfrm_address_t
*daddr
,
18 const xfrm_address_t
*saddr
)
20 u32 sum
= (__force u32
)daddr
->a4
+ (__force u32
)saddr
->a4
;
21 return ntohl((__force __be32
)sum
);
24 static inline unsigned int __xfrm6_daddr_saddr_hash(const xfrm_address_t
*daddr
,
25 const xfrm_address_t
*saddr
)
27 return ntohl(daddr
->a6
[2] ^ daddr
->a6
[3] ^
28 saddr
->a6
[2] ^ saddr
->a6
[3]);
31 static inline unsigned int __xfrm_dst_hash(const xfrm_address_t
*daddr
,
32 const xfrm_address_t
*saddr
,
33 u32 reqid
, unsigned short family
,
36 unsigned int h
= family
^ reqid
;
39 h
^= __xfrm4_daddr_saddr_hash(daddr
, saddr
);
42 h
^= __xfrm6_daddr_saddr_hash(daddr
, saddr
);
45 return (h
^ (h
>> 16)) & hmask
;
48 static inline unsigned int __xfrm_src_hash(const xfrm_address_t
*daddr
,
49 const xfrm_address_t
*saddr
,
50 unsigned short family
,
53 unsigned int h
= family
;
56 h
^= __xfrm4_daddr_saddr_hash(daddr
, saddr
);
59 h
^= __xfrm6_daddr_saddr_hash(daddr
, saddr
);
62 return (h
^ (h
>> 16)) & hmask
;
65 static inline unsigned int
66 __xfrm_spi_hash(const xfrm_address_t
*daddr
, __be32 spi
, u8 proto
,
67 unsigned short family
, unsigned int hmask
)
69 unsigned int h
= (__force u32
)spi
^ proto
;
72 h
^= __xfrm4_addr_hash(daddr
);
75 h
^= __xfrm6_addr_hash(daddr
);
78 return (h
^ (h
>> 10) ^ (h
>> 20)) & hmask
;
81 static inline unsigned int __idx_hash(u32 index
, unsigned int hmask
)
83 return (index
^ (index
>> 8)) & hmask
;
86 static inline unsigned int __sel_hash(const struct xfrm_selector
*sel
,
87 unsigned short family
, unsigned int hmask
)
89 const xfrm_address_t
*daddr
= &sel
->daddr
;
90 const xfrm_address_t
*saddr
= &sel
->saddr
;
95 if (sel
->prefixlen_d
!= 32 ||
96 sel
->prefixlen_s
!= 32)
99 h
= __xfrm4_daddr_saddr_hash(daddr
, saddr
);
103 if (sel
->prefixlen_d
!= 128 ||
104 sel
->prefixlen_s
!= 128)
107 h
= __xfrm6_daddr_saddr_hash(daddr
, saddr
);
114 static inline unsigned int __addr_hash(const xfrm_address_t
*daddr
,
115 const xfrm_address_t
*saddr
,
116 unsigned short family
, unsigned int hmask
)
122 h
= __xfrm4_daddr_saddr_hash(daddr
, saddr
);
126 h
= __xfrm6_daddr_saddr_hash(daddr
, saddr
);
133 extern struct hlist_head
*xfrm_hash_alloc(unsigned int sz
);
134 extern void xfrm_hash_free(struct hlist_head
*n
, unsigned int sz
);
136 #endif /* _XFRM_HASH_H */