]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - include/net/inet6_hashtables.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * INET An implementation of the TCP/IP protocol suite for the LINUX
4 * operating system. INET is implemented using the BSD Socket
5 * interface as the means of communication with the user level.
7 * Authors: Lotsa people, from code originally in tcp
10 #ifndef _INET6_HASHTABLES_H
11 #define _INET6_HASHTABLES_H
14 #if IS_ENABLED(CONFIG_IPV6)
15 #include <linux/in6.h>
16 #include <linux/ipv6.h>
17 #include <linux/types.h>
18 #include <linux/jhash.h>
20 #include <net/inet_sock.h>
23 #include <net/netns/hash.h>
27 static inline unsigned int __inet6_ehashfn(const u32 lhash
,
33 const u32 ports
= (((u32
)lport
) << 16) | (__force u32
)fport
;
34 return jhash_3words(lhash
, fhash
, ports
, initval
);
38 * Sockets in TCP_CLOSE state are _always_ taken out of the hash, so
39 * we need not check it for TCP lookups anymore, thanks Alexey. -DaveM
41 * The sockhash lock must be held as a reader here.
43 struct sock
*__inet6_lookup_established(struct net
*net
,
44 struct inet_hashinfo
*hashinfo
,
45 const struct in6_addr
*saddr
,
47 const struct in6_addr
*daddr
,
48 const u16 hnum
, const int dif
,
51 struct sock
*inet6_lookup_listener(struct net
*net
,
52 struct inet_hashinfo
*hashinfo
,
53 struct sk_buff
*skb
, int doff
,
54 const struct in6_addr
*saddr
,
56 const struct in6_addr
*daddr
,
57 const unsigned short hnum
,
58 const int dif
, const int sdif
);
60 static inline struct sock
*__inet6_lookup(struct net
*net
,
61 struct inet_hashinfo
*hashinfo
,
62 struct sk_buff
*skb
, int doff
,
63 const struct in6_addr
*saddr
,
65 const struct in6_addr
*daddr
,
67 const int dif
, const int sdif
,
70 struct sock
*sk
= __inet6_lookup_established(net
, hashinfo
, saddr
,
77 return inet6_lookup_listener(net
, hashinfo
, skb
, doff
, saddr
, sport
,
78 daddr
, hnum
, dif
, sdif
);
81 static inline struct sock
*__inet6_lookup_skb(struct inet_hashinfo
*hashinfo
,
82 struct sk_buff
*skb
, int doff
,
88 struct sock
*sk
= skb_steal_sock(skb
);
94 return __inet6_lookup(dev_net(skb_dst(skb
)->dev
), hashinfo
, skb
,
95 doff
, &ipv6_hdr(skb
)->saddr
, sport
,
96 &ipv6_hdr(skb
)->daddr
, ntohs(dport
),
97 iif
, sdif
, refcounted
);
100 struct sock
*inet6_lookup(struct net
*net
, struct inet_hashinfo
*hashinfo
,
101 struct sk_buff
*skb
, int doff
,
102 const struct in6_addr
*saddr
, const __be16 sport
,
103 const struct in6_addr
*daddr
, const __be16 dport
,
106 int inet6_hash(struct sock
*sk
);
107 #endif /* IS_ENABLED(CONFIG_IPV6) */
109 #define INET6_MATCH(__sk, __net, __saddr, __daddr, __ports, __dif, __sdif) \
110 (((__sk)->sk_portpair == (__ports)) && \
111 ((__sk)->sk_family == AF_INET6) && \
112 ipv6_addr_equal(&(__sk)->sk_v6_daddr, (__saddr)) && \
113 ipv6_addr_equal(&(__sk)->sk_v6_rcv_saddr, (__daddr)) && \
114 (((__sk)->sk_bound_dev_if == (__dif)) || \
115 ((__sk)->sk_bound_dev_if == (__sdif))) && \
116 net_eq(sock_net(__sk), (__net)))
118 #endif /* _INET6_HASHTABLES_H */