aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/inet_hashtables.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/inet_hashtables.h')
-rw-r--r--include/net/inet_hashtables.h56
1 files changed, 35 insertions, 21 deletions
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index b4491c9e2a5a..a9eb2eaf094e 100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -272,42 +272,56 @@ static inline int inet_iif(const struct sk_buff *skb)
272} 272}
273 273
274extern struct sock *__inet_lookup_listener(struct inet_hashinfo *hashinfo, 274extern struct sock *__inet_lookup_listener(struct inet_hashinfo *hashinfo,
275 const u32 daddr, 275 const __be32 daddr,
276 const unsigned short hnum, 276 const unsigned short hnum,
277 const int dif); 277 const int dif);
278 278
279static inline struct sock *inet_lookup_listener(struct inet_hashinfo *hashinfo, 279static inline struct sock *inet_lookup_listener(struct inet_hashinfo *hashinfo,
280 u32 daddr, u16 dport, int dif) 280 __be32 daddr, __be16 dport, int dif)
281{ 281{
282 return __inet_lookup_listener(hashinfo, daddr, ntohs(dport), dif); 282 return __inet_lookup_listener(hashinfo, daddr, ntohs(dport), dif);
283} 283}
284 284
285/* Socket demux engine toys. */ 285/* Socket demux engine toys. */
286/* What happens here is ugly; there's a pair of adjacent fields in
287 struct inet_sock; __be16 dport followed by __u16 num. We want to
288 search by pair, so we combine the keys into a single 32bit value
289 and compare with 32bit value read from &...->dport. Let's at least
290 make sure that it's not mixed with anything else...
291 On 64bit targets we combine comparisons with pair of adjacent __be32
292 fields in the same way.
293*/
294typedef __u32 __bitwise __portpair;
286#ifdef __BIG_ENDIAN 295#ifdef __BIG_ENDIAN
287#define INET_COMBINED_PORTS(__sport, __dport) \ 296#define INET_COMBINED_PORTS(__sport, __dport) \
288 (((__u32)(__sport) << 16) | (__u32)(__dport)) 297 ((__force __portpair)(((__force __u32)(__be16)(__sport) << 16) | (__u32)(__dport)))
289#else /* __LITTLE_ENDIAN */ 298#else /* __LITTLE_ENDIAN */
290#define INET_COMBINED_PORTS(__sport, __dport) \ 299#define INET_COMBINED_PORTS(__sport, __dport) \
291 (((__u32)(__dport) << 16) | (__u32)(__sport)) 300 ((__force __portpair)(((__u32)(__dport) << 16) | (__force __u32)(__be16)(__sport)))
292#endif 301#endif
293 302
294#if (BITS_PER_LONG == 64) 303#if (BITS_PER_LONG == 64)
304typedef __u64 __bitwise __addrpair;
295#ifdef __BIG_ENDIAN 305#ifdef __BIG_ENDIAN
296#define INET_ADDR_COOKIE(__name, __saddr, __daddr) \ 306#define INET_ADDR_COOKIE(__name, __saddr, __daddr) \
297 const __u64 __name = (((__u64)(__saddr)) << 32) | ((__u64)(__daddr)); 307 const __addrpair __name = (__force __addrpair) ( \
308 (((__force __u64)(__be32)(__saddr)) << 32) | \
309 ((__force __u64)(__be32)(__daddr)));
298#else /* __LITTLE_ENDIAN */ 310#else /* __LITTLE_ENDIAN */
299#define INET_ADDR_COOKIE(__name, __saddr, __daddr) \ 311#define INET_ADDR_COOKIE(__name, __saddr, __daddr) \
300 const __u64 __name = (((__u64)(__daddr)) << 32) | ((__u64)(__saddr)); 312 const __addrpair __name = (__force __addrpair) ( \
313 (((__force __u64)(__be32)(__daddr)) << 32) | \
314 ((__force __u64)(__be32)(__saddr)));
301#endif /* __BIG_ENDIAN */ 315#endif /* __BIG_ENDIAN */
302#define INET_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\ 316#define INET_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
303 (((__sk)->sk_hash == (__hash)) && \ 317 (((__sk)->sk_hash == (__hash)) && \
304 ((*((__u64 *)&(inet_sk(__sk)->daddr))) == (__cookie)) && \ 318 ((*((__addrpair *)&(inet_sk(__sk)->daddr))) == (__cookie)) && \
305 ((*((__u32 *)&(inet_sk(__sk)->dport))) == (__ports)) && \ 319 ((*((__portpair *)&(inet_sk(__sk)->dport))) == (__ports)) && \
306 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) 320 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
307#define INET_TW_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\ 321#define INET_TW_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
308 (((__sk)->sk_hash == (__hash)) && \ 322 (((__sk)->sk_hash == (__hash)) && \
309 ((*((__u64 *)&(inet_twsk(__sk)->tw_daddr))) == (__cookie)) && \ 323 ((*((__addrpair *)&(inet_twsk(__sk)->tw_daddr))) == (__cookie)) && \
310 ((*((__u32 *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \ 324 ((*((__portpair *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \
311 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) 325 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
312#else /* 32-bit arch */ 326#else /* 32-bit arch */
313#define INET_ADDR_COOKIE(__name, __saddr, __daddr) 327#define INET_ADDR_COOKIE(__name, __saddr, __daddr)
@@ -315,13 +329,13 @@ static inline struct sock *inet_lookup_listener(struct inet_hashinfo *hashinfo,
315 (((__sk)->sk_hash == (__hash)) && \ 329 (((__sk)->sk_hash == (__hash)) && \
316 (inet_sk(__sk)->daddr == (__saddr)) && \ 330 (inet_sk(__sk)->daddr == (__saddr)) && \
317 (inet_sk(__sk)->rcv_saddr == (__daddr)) && \ 331 (inet_sk(__sk)->rcv_saddr == (__daddr)) && \
318 ((*((__u32 *)&(inet_sk(__sk)->dport))) == (__ports)) && \ 332 ((*((__portpair *)&(inet_sk(__sk)->dport))) == (__ports)) && \
319 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) 333 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
320#define INET_TW_MATCH(__sk, __hash,__cookie, __saddr, __daddr, __ports, __dif) \ 334#define INET_TW_MATCH(__sk, __hash,__cookie, __saddr, __daddr, __ports, __dif) \
321 (((__sk)->sk_hash == (__hash)) && \ 335 (((__sk)->sk_hash == (__hash)) && \
322 (inet_twsk(__sk)->tw_daddr == (__saddr)) && \ 336 (inet_twsk(__sk)->tw_daddr == (__saddr)) && \
323 (inet_twsk(__sk)->tw_rcv_saddr == (__daddr)) && \ 337 (inet_twsk(__sk)->tw_rcv_saddr == (__daddr)) && \
324 ((*((__u32 *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \ 338 ((*((__portpair *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \
325 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) 339 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
326#endif /* 64-bit arch */ 340#endif /* 64-bit arch */
327 341
@@ -333,12 +347,12 @@ static inline struct sock *inet_lookup_listener(struct inet_hashinfo *hashinfo,
333 */ 347 */
334static inline struct sock * 348static inline struct sock *
335 __inet_lookup_established(struct inet_hashinfo *hashinfo, 349 __inet_lookup_established(struct inet_hashinfo *hashinfo,
336 const u32 saddr, const u16 sport, 350 const __be32 saddr, const __be16 sport,
337 const u32 daddr, const u16 hnum, 351 const __be32 daddr, const u16 hnum,
338 const int dif) 352 const int dif)
339{ 353{
340 INET_ADDR_COOKIE(acookie, saddr, daddr) 354 INET_ADDR_COOKIE(acookie, saddr, daddr)
341 const __u32 ports = INET_COMBINED_PORTS(sport, hnum); 355 const __portpair ports = INET_COMBINED_PORTS(sport, hnum);
342 struct sock *sk; 356 struct sock *sk;
343 const struct hlist_node *node; 357 const struct hlist_node *node;
344 /* Optimize here for direct hit, only listening connections can 358 /* Optimize here for direct hit, only listening connections can
@@ -370,8 +384,8 @@ hit:
370 384
371static inline struct sock * 385static inline struct sock *
372 inet_lookup_established(struct inet_hashinfo *hashinfo, 386 inet_lookup_established(struct inet_hashinfo *hashinfo,
373 const u32 saddr, const u16 sport, 387 const __be32 saddr, const __be16 sport,
374 const u32 daddr, const u16 dport, 388 const __be32 daddr, const __be16 dport,
375 const int dif) 389 const int dif)
376{ 390{
377 return __inet_lookup_established(hashinfo, saddr, sport, daddr, 391 return __inet_lookup_established(hashinfo, saddr, sport, daddr,
@@ -379,8 +393,8 @@ static inline struct sock *
379} 393}
380 394
381static inline struct sock *__inet_lookup(struct inet_hashinfo *hashinfo, 395static inline struct sock *__inet_lookup(struct inet_hashinfo *hashinfo,
382 const u32 saddr, const u16 sport, 396 const __be32 saddr, const __be16 sport,
383 const u32 daddr, const u16 dport, 397 const __be32 daddr, const __be16 dport,
384 const int dif) 398 const int dif)
385{ 399{
386 u16 hnum = ntohs(dport); 400 u16 hnum = ntohs(dport);
@@ -390,8 +404,8 @@ static inline struct sock *__inet_lookup(struct inet_hashinfo *hashinfo,
390} 404}
391 405
392static inline struct sock *inet_lookup(struct inet_hashinfo *hashinfo, 406static inline struct sock *inet_lookup(struct inet_hashinfo *hashinfo,
393 const u32 saddr, const u16 sport, 407 const __be32 saddr, const __be16 sport,
394 const u32 daddr, const u16 dport, 408 const __be32 daddr, const __be16 dport,
395 const int dif) 409 const int dif)
396{ 410{
397 struct sock *sk; 411 struct sock *sk;