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 return ntohl(daddr
->a4
^ saddr
->a4
);
22 static inline unsigned int __xfrm6_daddr_saddr_hash(xfrm_address_t
*daddr
, xfrm_address_t
*saddr
)
24 return ntohl(daddr
->a6
[2] ^ daddr
->a6
[3] ^
25 saddr
->a6
[2] ^ saddr
->a6
[3]);
28 static inline unsigned int __xfrm_dst_hash(xfrm_address_t
*daddr
, xfrm_address_t
*saddr
,
29 u32 reqid
, unsigned short family
,
32 unsigned int h
= family
^ reqid
;
35 h
^= __xfrm4_daddr_saddr_hash(daddr
, saddr
);
38 h
^= __xfrm6_daddr_saddr_hash(daddr
, saddr
);
41 return (h
^ (h
>> 16)) & hmask
;
44 static inline unsigned __xfrm_src_hash(xfrm_address_t
*saddr
,
45 unsigned short family
,
48 unsigned int h
= family
;
51 h
^= __xfrm4_addr_hash(saddr
);
54 h
^= __xfrm6_addr_hash(saddr
);
57 return (h
^ (h
>> 16)) & hmask
;
60 static inline unsigned int
61 __xfrm_spi_hash(xfrm_address_t
*daddr
, u32 spi
, u8 proto
, unsigned short family
,
64 unsigned int h
= spi
^ proto
;
67 h
^= __xfrm4_addr_hash(daddr
);
70 h
^= __xfrm6_addr_hash(daddr
);
73 return (h
^ (h
>> 10) ^ (h
>> 20)) & hmask
;
76 static inline unsigned int __idx_hash(u32 index
, unsigned int hmask
)
78 return (index
^ (index
>> 8)) & hmask
;
81 static inline unsigned int __sel_hash(struct xfrm_selector
*sel
, unsigned short family
, unsigned int hmask
)
83 xfrm_address_t
*daddr
= &sel
->daddr
;
84 xfrm_address_t
*saddr
= &sel
->saddr
;
89 if (sel
->prefixlen_d
!= 32 ||
90 sel
->prefixlen_s
!= 32)
93 h
= __xfrm4_daddr_saddr_hash(daddr
, saddr
);
97 if (sel
->prefixlen_d
!= 128 ||
98 sel
->prefixlen_s
!= 128)
101 h
= __xfrm6_daddr_saddr_hash(daddr
, saddr
);
108 static inline unsigned int __addr_hash(xfrm_address_t
*daddr
, xfrm_address_t
*saddr
, unsigned short family
, unsigned int hmask
)
114 h
= __xfrm4_daddr_saddr_hash(daddr
, saddr
);
118 h
= __xfrm6_daddr_saddr_hash(daddr
, saddr
);
125 extern struct hlist_head
*xfrm_hash_alloc(unsigned int sz
);
126 extern void xfrm_hash_free(struct hlist_head
*n
, unsigned int sz
);
128 #endif /* _XFRM_HASH_H */