4 #include <linux/xfrm.h>
5 #include <linux/socket.h>
7 static inline unsigned int __xfrm4_addr_hash(xfrm_address_t
*addr
)
9 return ntohl(addr
->a4
);
12 static inline unsigned int __xfrm6_addr_hash(xfrm_address_t
*addr
)
14 return ntohl(addr
->a6
[2] ^ addr
->a6
[3]);
17 static inline unsigned int __xfrm4_daddr_saddr_hash(xfrm_address_t
*daddr
, xfrm_address_t
*saddr
)
19 u32 sum
= (__force u32
)daddr
->a4
+ (__force u32
)saddr
->a4
;
20 return ntohl((__force __be32
)sum
);
23 static inline unsigned int __xfrm6_daddr_saddr_hash(xfrm_address_t
*daddr
, xfrm_address_t
*saddr
)
25 return ntohl(daddr
->a6
[2] ^ daddr
->a6
[3] ^
26 saddr
->a6
[2] ^ saddr
->a6
[3]);
29 static inline unsigned int __xfrm_dst_hash(xfrm_address_t
*daddr
, xfrm_address_t
*saddr
,
30 u32 reqid
, unsigned short family
,
33 unsigned int h
= family
^ reqid
;
36 h
^= __xfrm4_daddr_saddr_hash(daddr
, saddr
);
39 h
^= __xfrm6_daddr_saddr_hash(daddr
, saddr
);
42 return (h
^ (h
>> 16)) & hmask
;
45 static inline unsigned __xfrm_src_hash(xfrm_address_t
*daddr
,
46 xfrm_address_t
*saddr
,
47 unsigned short family
,
50 unsigned int h
= family
;
53 h
^= __xfrm4_daddr_saddr_hash(daddr
, saddr
);
56 h
^= __xfrm6_daddr_saddr_hash(daddr
, saddr
);
59 return (h
^ (h
>> 16)) & hmask
;
62 static inline unsigned int
63 __xfrm_spi_hash(xfrm_address_t
*daddr
, __be32 spi
, u8 proto
, unsigned short family
,
66 unsigned int h
= (__force u32
)spi
^ proto
;
69 h
^= __xfrm4_addr_hash(daddr
);
72 h
^= __xfrm6_addr_hash(daddr
);
75 return (h
^ (h
>> 10) ^ (h
>> 20)) & hmask
;
78 static inline unsigned int __idx_hash(u32 index
, unsigned int hmask
)
80 return (index
^ (index
>> 8)) & hmask
;
83 static inline unsigned int __sel_hash(struct xfrm_selector
*sel
, unsigned short family
, unsigned int hmask
)
85 xfrm_address_t
*daddr
= &sel
->daddr
;
86 xfrm_address_t
*saddr
= &sel
->saddr
;
91 if (sel
->prefixlen_d
!= 32 ||
92 sel
->prefixlen_s
!= 32)
95 h
= __xfrm4_daddr_saddr_hash(daddr
, saddr
);
99 if (sel
->prefixlen_d
!= 128 ||
100 sel
->prefixlen_s
!= 128)
103 h
= __xfrm6_daddr_saddr_hash(daddr
, saddr
);
110 static inline unsigned int __addr_hash(xfrm_address_t
*daddr
, xfrm_address_t
*saddr
, unsigned short family
, unsigned int hmask
)
116 h
= __xfrm4_daddr_saddr_hash(daddr
, saddr
);
120 h
= __xfrm6_daddr_saddr_hash(daddr
, saddr
);
127 extern struct hlist_head
*xfrm_hash_alloc(unsigned int sz
);
128 extern void xfrm_hash_free(struct hlist_head
*n
, unsigned int sz
);
130 #endif /* _XFRM_HASH_H */