0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _INET6_HASHTABLES_H
0011 #define _INET6_HASHTABLES_H
0012
0013
0014 #if IS_ENABLED(CONFIG_IPV6)
0015 #include <linux/in6.h>
0016 #include <linux/ipv6.h>
0017 #include <linux/types.h>
0018 #include <linux/jhash.h>
0019
0020 #include <net/inet_sock.h>
0021
0022 #include <net/ipv6.h>
0023 #include <net/netns/hash.h>
0024
0025 struct inet_hashinfo;
0026
0027 static inline unsigned int __inet6_ehashfn(const u32 lhash,
0028 const u16 lport,
0029 const u32 fhash,
0030 const __be16 fport,
0031 const u32 initval)
0032 {
0033 const u32 ports = (((u32)lport) << 16) | (__force u32)fport;
0034 return jhash_3words(lhash, fhash, ports, initval);
0035 }
0036
0037
0038
0039
0040
0041
0042
0043 struct sock *__inet6_lookup_established(struct net *net,
0044 struct inet_hashinfo *hashinfo,
0045 const struct in6_addr *saddr,
0046 const __be16 sport,
0047 const struct in6_addr *daddr,
0048 const u16 hnum, const int dif,
0049 const int sdif);
0050
0051 struct sock *inet6_lookup_listener(struct net *net,
0052 struct inet_hashinfo *hashinfo,
0053 struct sk_buff *skb, int doff,
0054 const struct in6_addr *saddr,
0055 const __be16 sport,
0056 const struct in6_addr *daddr,
0057 const unsigned short hnum,
0058 const int dif, const int sdif);
0059
0060 static inline struct sock *__inet6_lookup(struct net *net,
0061 struct inet_hashinfo *hashinfo,
0062 struct sk_buff *skb, int doff,
0063 const struct in6_addr *saddr,
0064 const __be16 sport,
0065 const struct in6_addr *daddr,
0066 const u16 hnum,
0067 const int dif, const int sdif,
0068 bool *refcounted)
0069 {
0070 struct sock *sk = __inet6_lookup_established(net, hashinfo, saddr,
0071 sport, daddr, hnum,
0072 dif, sdif);
0073 *refcounted = true;
0074 if (sk)
0075 return sk;
0076 *refcounted = false;
0077 return inet6_lookup_listener(net, hashinfo, skb, doff, saddr, sport,
0078 daddr, hnum, dif, sdif);
0079 }
0080
0081 static inline struct sock *__inet6_lookup_skb(struct inet_hashinfo *hashinfo,
0082 struct sk_buff *skb, int doff,
0083 const __be16 sport,
0084 const __be16 dport,
0085 int iif, int sdif,
0086 bool *refcounted)
0087 {
0088 struct sock *sk = skb_steal_sock(skb, refcounted);
0089
0090 if (sk)
0091 return sk;
0092
0093 return __inet6_lookup(dev_net(skb_dst(skb)->dev), hashinfo, skb,
0094 doff, &ipv6_hdr(skb)->saddr, sport,
0095 &ipv6_hdr(skb)->daddr, ntohs(dport),
0096 iif, sdif, refcounted);
0097 }
0098
0099 struct sock *inet6_lookup(struct net *net, struct inet_hashinfo *hashinfo,
0100 struct sk_buff *skb, int doff,
0101 const struct in6_addr *saddr, const __be16 sport,
0102 const struct in6_addr *daddr, const __be16 dport,
0103 const int dif);
0104
0105 int inet6_hash(struct sock *sk);
0106
0107 static inline bool inet6_match(struct net *net, const struct sock *sk,
0108 const struct in6_addr *saddr,
0109 const struct in6_addr *daddr,
0110 const __portpair ports,
0111 const int dif, const int sdif)
0112 {
0113 if (!net_eq(sock_net(sk), net) ||
0114 sk->sk_family != AF_INET6 ||
0115 sk->sk_portpair != ports ||
0116 !ipv6_addr_equal(&sk->sk_v6_daddr, saddr) ||
0117 !ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
0118 return false;
0119
0120
0121 return inet_sk_bound_dev_eq(net, READ_ONCE(sk->sk_bound_dev_if), dif,
0122 sdif);
0123 }
0124 #endif
0125
0126 #endif