const u16 hnum, const int dif,
                                        const int sdif);
 
+typedef u32 (inet6_ehashfn_t)(const struct net *net,
+                              const struct in6_addr *laddr, const u16 lport,
+                              const struct in6_addr *faddr, const __be16 fport);
+
+inet6_ehashfn_t inet6_ehashfn;
+
+INDIRECT_CALLABLE_DECLARE(inet6_ehashfn_t udp6_ehashfn);
+
 struct sock *inet6_lookup_reuseport(struct net *net, struct sock *sk,
                                    struct sk_buff *skb, int doff,
                                    const struct in6_addr *saddr,
                                    __be16 sport,
                                    const struct in6_addr *daddr,
-                                   unsigned short hnum);
+                                   unsigned short hnum,
+                                   inet6_ehashfn_t *ehashfn);
 
 struct sock *inet6_lookup_listener(struct net *net,
                                   struct inet_hashinfo *hashinfo,
 
                                       const __be32 daddr, const u16 hnum,
                                       const int dif, const int sdif);
 
+typedef u32 (inet_ehashfn_t)(const struct net *net,
+                             const __be32 laddr, const __u16 lport,
+                             const __be32 faddr, const __be16 fport);
+
+inet_ehashfn_t inet_ehashfn;
+
+INDIRECT_CALLABLE_DECLARE(inet_ehashfn_t udp_ehashfn);
+
 struct sock *inet_lookup_reuseport(struct net *net, struct sock *sk,
                                   struct sk_buff *skb, int doff,
                                   __be32 saddr, __be16 sport,
-                                  __be32 daddr, unsigned short hnum);
+                                  __be32 daddr, unsigned short hnum,
+                                  inet_ehashfn_t *ehashfn);
 
 static inline struct sock *
        inet_lookup_established(struct net *net, struct inet_hashinfo *hashinfo,
                             refcounted);
 }
 
-u32 inet6_ehashfn(const struct net *net,
-                 const struct in6_addr *laddr, const u16 lport,
-                 const struct in6_addr *faddr, const __be16 fport);
-
 static inline void sk_daddr_set(struct sock *sk, __be32 addr)
 {
        sk->sk_daddr = addr; /* alias of inet_daddr */
 
 #include <net/tcp.h>
 #include <net/sock_reuseport.h>
 
-static u32 inet_ehashfn(const struct net *net, const __be32 laddr,
-                       const __u16 lport, const __be32 faddr,
-                       const __be16 fport)
+u32 inet_ehashfn(const struct net *net, const __be32 laddr,
+                const __u16 lport, const __be32 faddr,
+                const __be16 fport)
 {
        static u32 inet_ehash_secret __read_mostly;
 
        return __inet_ehashfn(laddr, lport, faddr, fport,
                              inet_ehash_secret + net_hash_mix(net));
 }
+EXPORT_SYMBOL_GPL(inet_ehashfn);
 
 /* This function handles inet_sock, but also timewait and request sockets
  * for IPv4/IPv6.
        return score;
 }
 
+INDIRECT_CALLABLE_DECLARE(inet_ehashfn_t udp_ehashfn);
+
 struct sock *inet_lookup_reuseport(struct net *net, struct sock *sk,
                                   struct sk_buff *skb, int doff,
                                   __be32 saddr, __be16 sport,
-                                  __be32 daddr, unsigned short hnum)
+                                  __be32 daddr, unsigned short hnum,
+                                  inet_ehashfn_t *ehashfn)
 {
        struct sock *reuse_sk = NULL;
        u32 phash;
 
        if (sk->sk_reuseport) {
-               phash = inet_ehashfn(net, daddr, hnum, saddr, sport);
+               phash = INDIRECT_CALL_2(ehashfn, udp_ehashfn, inet_ehashfn,
+                                       net, daddr, hnum, saddr, sport);
                reuse_sk = reuseport_select_sock(sk, phash, skb, doff);
        }
        return reuse_sk;
                score = compute_score(sk, net, hnum, daddr, dif, sdif);
                if (score > hiscore) {
                        result = inet_lookup_reuseport(net, sk, skb, doff,
-                                                      saddr, sport, daddr, hnum);
+                                                      saddr, sport, daddr, hnum, inet_ehashfn);
                        if (result)
                                return result;
 
        if (no_reuseport || IS_ERR_OR_NULL(sk))
                return sk;
 
-       reuse_sk = inet_lookup_reuseport(net, sk, skb, doff, saddr, sport, daddr, hnum);
+       reuse_sk = inet_lookup_reuseport(net, sk, skb, doff, saddr, sport, daddr, hnum,
+                                        inet_ehashfn);
        if (reuse_sk)
                sk = reuse_sk;
        return sk;
 
        return score;
 }
 
-static u32 udp_ehashfn(const struct net *net, const __be32 laddr,
-                      const __u16 lport, const __be32 faddr,
-                      const __be16 fport)
+INDIRECT_CALLABLE_SCOPE
+u32 udp_ehashfn(const struct net *net, const __be32 laddr, const __u16 lport,
+               const __be32 faddr, const __be16 fport)
 {
        static u32 udp_ehash_secret __read_mostly;
 
                              udp_ehash_secret + net_hash_mix(net));
 }
 
-static struct sock *lookup_reuseport(struct net *net, struct sock *sk,
-                                    struct sk_buff *skb,
-                                    __be32 saddr, __be16 sport,
-                                    __be32 daddr, unsigned short hnum)
-{
-       struct sock *reuse_sk = NULL;
-       u32 hash;
-
-       if (sk->sk_reuseport && sk->sk_state != TCP_ESTABLISHED) {
-               hash = udp_ehashfn(net, daddr, hnum, saddr, sport);
-               reuse_sk = reuseport_select_sock(sk, hash, skb,
-                                                sizeof(struct udphdr));
-       }
-       return reuse_sk;
-}
-
 /* called with rcu_read_lock() */
 static struct sock *udp4_lib_lookup2(struct net *net,
                                     __be32 saddr, __be16 sport,
                                      daddr, hnum, dif, sdif);
                if (score > badness) {
                        badness = score;
-                       result = lookup_reuseport(net, sk, skb, saddr, sport, daddr, hnum);
+
+                       if (sk->sk_state == TCP_ESTABLISHED) {
+                               result = sk;
+                               continue;
+                       }
+
+                       result = inet_lookup_reuseport(net, sk, skb, sizeof(struct udphdr),
+                                                      saddr, sport, daddr, hnum, udp_ehashfn);
                        if (!result) {
                                result = sk;
                                continue;
        if (no_reuseport || IS_ERR_OR_NULL(sk))
                return sk;
 
-       reuse_sk = lookup_reuseport(net, sk, skb, saddr, sport, daddr, hnum);
+       reuse_sk = inet_lookup_reuseport(net, sk, skb, sizeof(struct udphdr),
+                                        saddr, sport, daddr, hnum, udp_ehashfn);
        if (reuse_sk)
                sk = reuse_sk;
        return sk;
 
        return __inet6_ehashfn(lhash, lport, fhash, fport,
                               inet6_ehash_secret + net_hash_mix(net));
 }
+EXPORT_SYMBOL_GPL(inet6_ehashfn);
 
 /*
  * Sockets in TCP_CLOSE state are _always_ taken out of the hash, so
        return score;
 }
 
+INDIRECT_CALLABLE_DECLARE(inet6_ehashfn_t udp6_ehashfn);
+
 struct sock *inet6_lookup_reuseport(struct net *net, struct sock *sk,
                                    struct sk_buff *skb, int doff,
                                    const struct in6_addr *saddr,
                                    __be16 sport,
                                    const struct in6_addr *daddr,
-                                   unsigned short hnum)
+                                   unsigned short hnum,
+                                   inet6_ehashfn_t *ehashfn)
 {
        struct sock *reuse_sk = NULL;
        u32 phash;
 
        if (sk->sk_reuseport) {
-               phash = inet6_ehashfn(net, daddr, hnum, saddr, sport);
+               phash = INDIRECT_CALL_INET(ehashfn, udp6_ehashfn, inet6_ehashfn,
+                                          net, daddr, hnum, saddr, sport);
                reuse_sk = reuseport_select_sock(sk, phash, skb, doff);
        }
        return reuse_sk;
                score = compute_score(sk, net, hnum, daddr, dif, sdif);
                if (score > hiscore) {
                        result = inet6_lookup_reuseport(net, sk, skb, doff,
-                                                       saddr, sport, daddr, hnum);
+                                                       saddr, sport, daddr, hnum, inet6_ehashfn);
                        if (result)
                                return result;
 
        if (no_reuseport || IS_ERR_OR_NULL(sk))
                return sk;
 
-       reuse_sk = inet6_lookup_reuseport(net, sk, skb, doff, saddr, sport, daddr, hnum);
+       reuse_sk = inet6_lookup_reuseport(net, sk, skb, doff,
+                                         saddr, sport, daddr, hnum, inet6_ehashfn);
        if (reuse_sk)
                sk = reuse_sk;
        return sk;
 
        return 0;
 }
 
-static u32 udp6_ehashfn(const struct net *net,
-                       const struct in6_addr *laddr,
-                       const u16 lport,
-                       const struct in6_addr *faddr,
-                       const __be16 fport)
+INDIRECT_CALLABLE_SCOPE
+u32 udp6_ehashfn(const struct net *net,
+                const struct in6_addr *laddr,
+                const u16 lport,
+                const struct in6_addr *faddr,
+                const __be16 fport)
 {
        static u32 udp6_ehash_secret __read_mostly;
        static u32 udp_ipv6_hash_secret __read_mostly;
        return score;
 }
 
-static struct sock *lookup_reuseport(struct net *net, struct sock *sk,
-                                    struct sk_buff *skb,
-                                    const struct in6_addr *saddr,
-                                    __be16 sport,
-                                    const struct in6_addr *daddr,
-                                    unsigned int hnum)
-{
-       struct sock *reuse_sk = NULL;
-       u32 hash;
-
-       if (sk->sk_reuseport && sk->sk_state != TCP_ESTABLISHED) {
-               hash = udp6_ehashfn(net, daddr, hnum, saddr, sport);
-               reuse_sk = reuseport_select_sock(sk, hash, skb,
-                                                sizeof(struct udphdr));
-       }
-       return reuse_sk;
-}
-
 /* called with rcu_read_lock() */
 static struct sock *udp6_lib_lookup2(struct net *net,
                const struct in6_addr *saddr, __be16 sport,
                                      daddr, hnum, dif, sdif);
                if (score > badness) {
                        badness = score;
-                       result = lookup_reuseport(net, sk, skb, saddr, sport, daddr, hnum);
+
+                       if (sk->sk_state == TCP_ESTABLISHED) {
+                               result = sk;
+                               continue;
+                       }
+
+                       result = inet6_lookup_reuseport(net, sk, skb, sizeof(struct udphdr),
+                                                       saddr, sport, daddr, hnum, udp6_ehashfn);
                        if (!result) {
                                result = sk;
                                continue;
        if (no_reuseport || IS_ERR_OR_NULL(sk))
                return sk;
 
-       reuse_sk = lookup_reuseport(net, sk, skb, saddr, sport, daddr, hnum);
+       reuse_sk = inet6_lookup_reuseport(net, sk, skb, sizeof(struct udphdr),
+                                         saddr, sport, daddr, hnum, udp6_ehashfn);
        if (reuse_sk)
                sk = reuse_sk;
        return sk;