]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - net/netfilter/ipvs/ip_vs_core.c
Merge remote-tracking branch 'ipsec/master'
[karo-tx-linux.git] / net / netfilter / ipvs / ip_vs_core.c
index b5f451f20f522dfd7cbe7d2f98cc2669b1743df9..1e24fff53e4b5eef8fab776b2e3dc93a3ae4545c 100644 (file)
@@ -112,7 +112,7 @@ static inline void
 ip_vs_in_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
 {
        struct ip_vs_dest *dest = cp->dest;
-       struct netns_ipvs *ipvs = net_ipvs(skb_net(skb));
+       struct netns_ipvs *ipvs = cp->ipvs;
 
        if (dest && (dest->flags & IP_VS_DEST_F_AVAILABLE)) {
                struct ip_vs_cpu_stats *s;
@@ -146,7 +146,7 @@ static inline void
 ip_vs_out_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
 {
        struct ip_vs_dest *dest = cp->dest;
-       struct netns_ipvs *ipvs = net_ipvs(skb_net(skb));
+       struct netns_ipvs *ipvs = cp->ipvs;
 
        if (dest && (dest->flags & IP_VS_DEST_F_AVAILABLE)) {
                struct ip_vs_cpu_stats *s;
@@ -469,7 +469,7 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
         */
        if ((!skb->dev || skb->dev->flags & IFF_LOOPBACK)) {
                iph->hdr_flags ^= IP_VS_HDR_INVERSE;
-               cp = pp->conn_in_get(svc->af, skb, iph);
+               cp = pp->conn_in_get(svc->ipvs, svc->af, skb, iph);
                iph->hdr_flags ^= IP_VS_HDR_INVERSE;
 
                if (cp) {
@@ -547,7 +547,6 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
        return cp;
 }
 
-#ifdef CONFIG_SYSCTL
 static inline int ip_vs_addr_is_unicast(struct net *net, int af,
                                        union nf_inet_addr *addr)
 {
@@ -557,7 +556,6 @@ static inline int ip_vs_addr_is_unicast(struct net *net, int af,
 #endif
        return (inet_addr_type(net, addr->ip) == RTN_UNICAST);
 }
-#endif
 
 /*
  *  Pass or drop the packet.
@@ -568,25 +566,18 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
                struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph)
 {
        __be16 _ports[2], *pptr, dport;
-#ifdef CONFIG_SYSCTL
-       struct net *net;
-       struct netns_ipvs *ipvs;
-#endif
+       struct netns_ipvs *ipvs = svc->ipvs;
+       struct net *net = ipvs->net;
 
        pptr = frag_safe_skb_hp(skb, iph->len, sizeof(_ports), _ports, iph);
        if (!pptr)
                return NF_DROP;
        dport = likely(!ip_vs_iph_inverse(iph)) ? pptr[1] : pptr[0];
 
-#ifdef CONFIG_SYSCTL
-       net = skb_net(skb);
-
-
        /* if it is fwmark-based service, the cache_bypass sysctl is up
           and the destination is a non-local unicast, then create
           a cache_bypass connection entry */
-       ipvs = net_ipvs(net);
-       if (ipvs->sysctl_cache_bypass && svc->fwmark &&
+       if (sysctl_cache_bypass(ipvs) && svc->fwmark &&
            !(iph->hdr_flags & (IP_VS_HDR_INVERSE | IP_VS_HDR_ICMP)) &&
            ip_vs_addr_is_unicast(net, svc->af, &iph->daddr)) {
                int ret;
@@ -624,7 +615,6 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
                ip_vs_conn_put(cp);
                return ret;
        }
-#endif
 
        /*
         * When the virtual ftp service is presented, packets destined
@@ -647,11 +637,8 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
         */
 #ifdef CONFIG_IP_VS_IPV6
        if (svc->af == AF_INET6) {
-               if (!skb->dev) {
-                       struct net *net_ = dev_net(skb_dst(skb)->dev);
-
-                       skb->dev = net_->loopback_dev;
-               }
+               if (!skb->dev)
+                       skb->dev = net->loopback_dev;
                icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
        } else
 #endif
@@ -662,15 +649,13 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
 
 #ifdef CONFIG_SYSCTL
 
-static int sysctl_snat_reroute(struct sk_buff *skb)
+static int sysctl_snat_reroute(struct netns_ipvs *ipvs)
 {
-       struct netns_ipvs *ipvs = net_ipvs(skb_net(skb));
        return ipvs->sysctl_snat_reroute;
 }
 
-static int sysctl_nat_icmp_send(struct net *net)
+static int sysctl_nat_icmp_send(struct netns_ipvs *ipvs)
 {
-       struct netns_ipvs *ipvs = net_ipvs(net);
        return ipvs->sysctl_nat_icmp_send;
 }
 
@@ -681,8 +666,8 @@ static int sysctl_expire_nodest_conn(struct netns_ipvs *ipvs)
 
 #else
 
-static int sysctl_snat_reroute(struct sk_buff *skb) { return 0; }
-static int sysctl_nat_icmp_send(struct net *net) { return 0; }
+static int sysctl_snat_reroute(struct netns_ipvs *ipvs) { return 0; }
+static int sysctl_nat_icmp_send(struct netns_ipvs *ipvs) { return 0; }
 static int sysctl_expire_nodest_conn(struct netns_ipvs *ipvs) { return 0; }
 
 #endif
@@ -701,12 +686,13 @@ static inline enum ip_defrag_users ip_vs_defrag_user(unsigned int hooknum)
        return IP_DEFRAG_VS_OUT;
 }
 
-static inline int ip_vs_gather_frags(struct sk_buff *skb, u_int32_t user)
+static inline int ip_vs_gather_frags(struct netns_ipvs *ipvs,
+                                    struct sk_buff *skb, u_int32_t user)
 {
        int err;
 
        local_bh_disable();
-       err = ip_defrag(skb, user);
+       err = ip_defrag(ipvs->net, skb, user);
        local_bh_enable();
        if (!err)
                ip_send_check(ip_hdr(skb));
@@ -714,10 +700,10 @@ static inline int ip_vs_gather_frags(struct sk_buff *skb, u_int32_t user)
        return err;
 }
 
-static int ip_vs_route_me_harder(int af, struct sk_buff *skb,
-                                unsigned int hooknum)
+static int ip_vs_route_me_harder(struct netns_ipvs *ipvs, int af,
+                                struct sk_buff *skb, unsigned int hooknum)
 {
-       if (!sysctl_snat_reroute(skb))
+       if (!sysctl_snat_reroute(ipvs))
                return 0;
        /* Reroute replies only to remote clients (FORWARD and LOCAL_OUT) */
        if (NF_INET_LOCAL_IN == hooknum)
@@ -727,12 +713,12 @@ static int ip_vs_route_me_harder(int af, struct sk_buff *skb,
                struct dst_entry *dst = skb_dst(skb);
 
                if (dst->dev && !(dst->dev->flags & IFF_LOOPBACK) &&
-                   ip6_route_me_harder(skb) != 0)
+                   ip6_route_me_harder(ipvs->net, skb) != 0)
                        return 1;
        } else
 #endif
                if (!(skb_rtable(skb)->rt_flags & RTCF_LOCAL) &&
-                   ip_route_me_harder(skb, RTN_LOCAL) != 0)
+                   ip_route_me_harder(ipvs->net, skb, RTN_LOCAL) != 0)
                        return 1;
 
        return 0;
@@ -885,7 +871,7 @@ static int handle_response_icmp(int af, struct sk_buff *skb,
 #endif
                ip_vs_nat_icmp(skb, pp, cp, 1);
 
-       if (ip_vs_route_me_harder(af, skb, hooknum))
+       if (ip_vs_route_me_harder(cp->ipvs, af, skb, hooknum))
                goto out;
 
        /* do the statistics and put it back */
@@ -909,8 +895,8 @@ out:
  *     Find any that might be relevant, check against existing connections.
  *     Currently handles error types - unreachable, quench, ttl exceeded.
  */
-static int ip_vs_out_icmp(struct sk_buff *skb, int *related,
-                         unsigned int hooknum)
+static int ip_vs_out_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb,
+                         int *related, unsigned int hooknum)
 {
        struct iphdr *iph;
        struct icmphdr  _icmph, *ic;
@@ -925,7 +911,7 @@ static int ip_vs_out_icmp(struct sk_buff *skb, int *related,
 
        /* reassemble IP fragments */
        if (ip_is_fragment(ip_hdr(skb))) {
-               if (ip_vs_gather_frags(skb, ip_vs_defrag_user(hooknum)))
+               if (ip_vs_gather_frags(ipvs, skb, ip_vs_defrag_user(hooknum)))
                        return NF_STOLEN;
        }
 
@@ -974,7 +960,7 @@ static int ip_vs_out_icmp(struct sk_buff *skb, int *related,
        ip_vs_fill_iph_skb_icmp(AF_INET, skb, offset, true, &ciph);
 
        /* The embedded headers contain source and dest in reverse order */
-       cp = pp->conn_out_get(AF_INET, skb, &ciph);
+       cp = pp->conn_out_get(ipvs, AF_INET, skb, &ciph);
        if (!cp)
                return NF_ACCEPT;
 
@@ -984,8 +970,9 @@ static int ip_vs_out_icmp(struct sk_buff *skb, int *related,
 }
 
 #ifdef CONFIG_IP_VS_IPV6
-static int ip_vs_out_icmp_v6(struct sk_buff *skb, int *related,
-                            unsigned int hooknum, struct ip_vs_iphdr *ipvsh)
+static int ip_vs_out_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,
+                            int *related,  unsigned int hooknum,
+                            struct ip_vs_iphdr *ipvsh)
 {
        struct icmp6hdr _icmph, *ic;
        struct ip_vs_iphdr ciph = {.flags = 0, .fragoffs = 0};/*Contained IP */
@@ -1029,7 +1016,7 @@ static int ip_vs_out_icmp_v6(struct sk_buff *skb, int *related,
                return NF_ACCEPT;
 
        /* The embedded headers contain source and dest in reverse order */
-       cp = pp->conn_out_get(AF_INET6, skb, &ciph);
+       cp = pp->conn_out_get(ipvs, AF_INET6, skb, &ciph);
        if (!cp)
                return NF_ACCEPT;
 
@@ -1155,7 +1142,7 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,
         * if it came from this machine itself.  So re-compute
         * the routing information.
         */
-       if (ip_vs_route_me_harder(af, skb, hooknum))
+       if (ip_vs_route_me_harder(cp->ipvs, af, skb, hooknum))
                goto drop;
 
        IP_VS_DBG_PKT(10, af, pp, skb, iph->off, "After SNAT");
@@ -1183,10 +1170,8 @@ drop:
  *     Check if outgoing packet belongs to the established ip_vs_conn.
  */
 static unsigned int
-ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)
+ip_vs_out(struct netns_ipvs *ipvs, unsigned int hooknum, struct sk_buff *skb, int af)
 {
-       struct net *net = NULL;
-       struct netns_ipvs *ipvs;
        struct ip_vs_iphdr iph;
        struct ip_vs_protocol *pp;
        struct ip_vs_proto_data *pd;
@@ -1211,8 +1196,6 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)
        if (unlikely(!skb_dst(skb)))
                return NF_ACCEPT;
 
-       net = skb_net(skb);
-       ipvs = net_ipvs(net);
        if (!ipvs->enable)
                return NF_ACCEPT;
 
@@ -1221,7 +1204,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)
        if (af == AF_INET6) {
                if (unlikely(iph.protocol == IPPROTO_ICMPV6)) {
                        int related;
-                       int verdict = ip_vs_out_icmp_v6(skb, &related,
+                       int verdict = ip_vs_out_icmp_v6(ipvs, skb, &related,
                                                        hooknum, &iph);
 
                        if (related)
@@ -1231,7 +1214,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)
 #endif
                if (unlikely(iph.protocol == IPPROTO_ICMP)) {
                        int related;
-                       int verdict = ip_vs_out_icmp(skb, &related, hooknum);
+                       int verdict = ip_vs_out_icmp(ipvs, skb, &related, hooknum);
 
                        if (related)
                                return verdict;
@@ -1247,7 +1230,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)
        if (af == AF_INET)
 #endif
                if (unlikely(ip_is_fragment(ip_hdr(skb)) && !pp->dont_defrag)) {
-                       if (ip_vs_gather_frags(skb,
+                       if (ip_vs_gather_frags(ipvs, skb,
                                               ip_vs_defrag_user(hooknum)))
                                return NF_STOLEN;
 
@@ -1257,11 +1240,11 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)
        /*
         * Check if the packet belongs to an existing entry
         */
-       cp = pp->conn_out_get(af, skb, &iph);
+       cp = pp->conn_out_get(ipvs, af, skb, &iph);
 
        if (likely(cp))
                return handle_response(af, skb, pd, cp, &iph, hooknum);
-       if (sysctl_nat_icmp_send(net) &&
+       if (sysctl_nat_icmp_send(ipvs) &&
            (pp->protocol == IPPROTO_TCP ||
             pp->protocol == IPPROTO_UDP ||
             pp->protocol == IPPROTO_SCTP)) {
@@ -1288,7 +1271,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)
 #ifdef CONFIG_IP_VS_IPV6
                                if (af == AF_INET6) {
                                        if (!skb->dev)
-                                               skb->dev = net->loopback_dev;
+                                               skb->dev = ipvs->net->loopback_dev;
                                        icmpv6_send(skb,
                                                    ICMPV6_DEST_UNREACH,
                                                    ICMPV6_PORT_UNREACH,
@@ -1316,7 +1299,7 @@ static unsigned int
 ip_vs_reply4(void *priv, struct sk_buff *skb,
             const struct nf_hook_state *state)
 {
-       return ip_vs_out(state->hook, skb, AF_INET);
+       return ip_vs_out(net_ipvs(state->net), state->hook, skb, AF_INET);
 }
 
 /*
@@ -1327,7 +1310,7 @@ static unsigned int
 ip_vs_local_reply4(void *priv, struct sk_buff *skb,
                   const struct nf_hook_state *state)
 {
-       return ip_vs_out(state->hook, skb, AF_INET);
+       return ip_vs_out(net_ipvs(state->net), state->hook, skb, AF_INET);
 }
 
 #ifdef CONFIG_IP_VS_IPV6
@@ -1341,7 +1324,7 @@ static unsigned int
 ip_vs_reply6(void *priv, struct sk_buff *skb,
             const struct nf_hook_state *state)
 {
-       return ip_vs_out(state->hook, skb, AF_INET6);
+       return ip_vs_out(net_ipvs(state->net), state->hook, skb, AF_INET6);
 }
 
 /*
@@ -1352,13 +1335,14 @@ static unsigned int
 ip_vs_local_reply6(void *priv, struct sk_buff *skb,
                   const struct nf_hook_state *state)
 {
-       return ip_vs_out(state->hook, skb, AF_INET6);
+       return ip_vs_out(net_ipvs(state->net), state->hook, skb, AF_INET6);
 }
 
 #endif
 
 static unsigned int
-ip_vs_try_to_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,
+ip_vs_try_to_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
+                     struct ip_vs_proto_data *pd,
                      int *verdict, struct ip_vs_conn **cpp,
                      struct ip_vs_iphdr *iph)
 {
@@ -1370,7 +1354,7 @@ ip_vs_try_to_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,
                 */
 
                /* Schedule and create new connection entry into cpp */
-               if (!pp->conn_schedule(af, skb, pd, verdict, cpp, iph))
+               if (!pp->conn_schedule(ipvs, af, skb, pd, verdict, cpp, iph))
                        return 0;
        }
 
@@ -1400,10 +1384,9 @@ ip_vs_try_to_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,
  *     Currently handles error types - unreachable, quench, ttl exceeded.
  */
 static int
-ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
+ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,
+             unsigned int hooknum)
 {
-       struct net *net = NULL;
-       struct netns_ipvs *ipvs;
        struct iphdr *iph;
        struct icmphdr  _icmph, *ic;
        struct iphdr    _ciph, *cih;    /* The ip header contained within the ICMP */
@@ -1418,7 +1401,7 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
 
        /* reassemble IP fragments */
        if (ip_is_fragment(ip_hdr(skb))) {
-               if (ip_vs_gather_frags(skb, ip_vs_defrag_user(hooknum)))
+               if (ip_vs_gather_frags(ipvs, skb, ip_vs_defrag_user(hooknum)))
                        return NF_STOLEN;
        }
 
@@ -1452,9 +1435,6 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
        if (cih == NULL)
                return NF_ACCEPT; /* The packet looks wrong, ignore */
 
-       net = skb_net(skb);
-       ipvs = net_ipvs(net);
-
        /* Special case for errors for IPIP packets */
        ipip = false;
        if (cih->protocol == IPPROTO_IPIP) {
@@ -1490,7 +1470,7 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
        /* The embedded headers contain source and dest in reverse order.
         * For IPIP this is error for request, not for reply.
         */
-       cp = pp->conn_in_get(AF_INET, skb, &ciph);
+       cp = pp->conn_in_get(ipvs, AF_INET, skb, &ciph);
 
        if (!cp) {
                int v;
@@ -1498,7 +1478,7 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
                if (!sysctl_schedule_icmp(ipvs))
                        return NF_ACCEPT;
 
-               if (!ip_vs_try_to_schedule(AF_INET, skb, pd, &v, &cp, &ciph))
+               if (!ip_vs_try_to_schedule(ipvs, AF_INET, skb, pd, &v, &cp, &ciph))
                        return v;
                new_cp = true;
        }
@@ -1532,7 +1512,7 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
                        skb_reset_network_header(skb);
                        IP_VS_DBG(12, "ICMP for IPIP %pI4->%pI4: mtu=%u\n",
                                &ip_hdr(skb)->saddr, &ip_hdr(skb)->daddr, mtu);
-                       ipv4_update_pmtu(skb, dev_net(skb->dev),
+                       ipv4_update_pmtu(skb, ipvs->net,
                                         mtu, 0, 0, 0, 0);
                        /* Client uses PMTUD? */
                        if (!(frag_off & htons(IP_DF)))
@@ -1587,11 +1567,10 @@ out:
 }
 
 #ifdef CONFIG_IP_VS_IPV6
-static int ip_vs_in_icmp_v6(struct sk_buff *skb, int *related,
-                           unsigned int hooknum, struct ip_vs_iphdr *iph)
+static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,
+                           int *related, unsigned int hooknum,
+                           struct ip_vs_iphdr *iph)
 {
-       struct net *net = NULL;
-       struct netns_ipvs *ipvs;
        struct icmp6hdr _icmph, *ic;
        struct ip_vs_iphdr ciph = {.flags = 0, .fragoffs = 0};/*Contained IP */
        struct ip_vs_conn *cp;
@@ -1631,8 +1610,6 @@ static int ip_vs_in_icmp_v6(struct sk_buff *skb, int *related,
        if (!ip_vs_fill_iph_skb_icmp(AF_INET6, skb, offset, true, &ciph))
                return NF_ACCEPT;
 
-       net = skb_net(skb);
-       ipvs = net_ipvs(net);
        pd = ip_vs_proto_data_get(ipvs, ciph.protocol);
        if (!pd)
                return NF_ACCEPT;
@@ -1648,7 +1625,7 @@ static int ip_vs_in_icmp_v6(struct sk_buff *skb, int *related,
        /* The embedded headers contain source and dest in reverse order
         * if not from localhost
         */
-       cp = pp->conn_in_get(AF_INET6, skb, &ciph);
+       cp = pp->conn_in_get(ipvs, AF_INET6, skb, &ciph);
 
        if (!cp) {
                int v;
@@ -1656,7 +1633,7 @@ static int ip_vs_in_icmp_v6(struct sk_buff *skb, int *related,
                if (!sysctl_schedule_icmp(ipvs))
                        return NF_ACCEPT;
 
-               if (!ip_vs_try_to_schedule(AF_INET6, skb, pd, &v, &cp, &ciph))
+               if (!ip_vs_try_to_schedule(ipvs, AF_INET6, skb, pd, &v, &cp, &ciph))
                        return v;
 
                new_cp = true;
@@ -1696,15 +1673,13 @@ out:
  *     and send it on its way...
  */
 static unsigned int
-ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
+ip_vs_in(struct netns_ipvs *ipvs, unsigned int hooknum, struct sk_buff *skb, int af)
 {
-       struct net *net;
        struct ip_vs_iphdr iph;
        struct ip_vs_protocol *pp;
        struct ip_vs_proto_data *pd;
        struct ip_vs_conn *cp;
        int ret, pkts;
-       struct netns_ipvs *ipvs;
        int conn_reuse_mode;
 
        /* Already marked as IPVS request or reply? */
@@ -1727,8 +1702,6 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
                return NF_ACCEPT;
        }
        /* ipvs enabled in this netns ? */
-       net = skb_net(skb);
-       ipvs = net_ipvs(net);
        if (unlikely(sysctl_backup_only(ipvs) || !ipvs->enable))
                return NF_ACCEPT;
 
@@ -1748,8 +1721,8 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
        if (af == AF_INET6) {
                if (unlikely(iph.protocol == IPPROTO_ICMPV6)) {
                        int related;
-                       int verdict = ip_vs_in_icmp_v6(skb, &related, hooknum,
-                                                      &iph);
+                       int verdict = ip_vs_in_icmp_v6(ipvs, skb, &related,
+                                                      hooknum, &iph);
 
                        if (related)
                                return verdict;
@@ -1758,7 +1731,8 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
 #endif
                if (unlikely(iph.protocol == IPPROTO_ICMP)) {
                        int related;
-                       int verdict = ip_vs_in_icmp(skb, &related, hooknum);
+                       int verdict = ip_vs_in_icmp(ipvs, skb, &related,
+                                                   hooknum);
 
                        if (related)
                                return verdict;
@@ -1780,7 +1754,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
        /*
         * Check if the packet belongs to an existing connection entry
         */
-       cp = pp->conn_in_get(af, skb, &iph);
+       cp = pp->conn_in_get(ipvs, af, skb, &iph);
 
        conn_reuse_mode = sysctl_conn_reuse_mode(ipvs);
        if (conn_reuse_mode && !iph.fragoffs &&
@@ -1797,7 +1771,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
        if (unlikely(!cp)) {
                int v;
 
-               if (!ip_vs_try_to_schedule(af, skb, pd, &v, &cp, &iph))
+               if (!ip_vs_try_to_schedule(ipvs, af, skb, pd, &v, &cp, &iph))
                        return v;
        }
 
@@ -1856,7 +1830,7 @@ static unsigned int
 ip_vs_remote_request4(void *priv, struct sk_buff *skb,
                      const struct nf_hook_state *state)
 {
-       return ip_vs_in(state->hook, skb, AF_INET);
+       return ip_vs_in(net_ipvs(state->net), state->hook, skb, AF_INET);
 }
 
 /*
@@ -1867,7 +1841,7 @@ static unsigned int
 ip_vs_local_request4(void *priv, struct sk_buff *skb,
                     const struct nf_hook_state *state)
 {
-       return ip_vs_in(state->hook, skb, AF_INET);
+       return ip_vs_in(net_ipvs(state->net), state->hook, skb, AF_INET);
 }
 
 #ifdef CONFIG_IP_VS_IPV6
@@ -1880,7 +1854,7 @@ static unsigned int
 ip_vs_remote_request6(void *priv, struct sk_buff *skb,
                      const struct nf_hook_state *state)
 {
-       return ip_vs_in(state->hook, skb, AF_INET6);
+       return ip_vs_in(net_ipvs(state->net), state->hook, skb, AF_INET6);
 }
 
 /*
@@ -1891,7 +1865,7 @@ static unsigned int
 ip_vs_local_request6(void *priv, struct sk_buff *skb,
                     const struct nf_hook_state *state)
 {
-       return ip_vs_in(state->hook, skb, AF_INET6);
+       return ip_vs_in(net_ipvs(state->net), state->hook, skb, AF_INET6);
 }
 
 #endif
@@ -1911,17 +1885,16 @@ ip_vs_forward_icmp(void *priv, struct sk_buff *skb,
                   const struct nf_hook_state *state)
 {
        int r;
-       struct netns_ipvs *ipvs;
+       struct netns_ipvs *ipvs = net_ipvs(state->net);
 
        if (ip_hdr(skb)->protocol != IPPROTO_ICMP)
                return NF_ACCEPT;
 
        /* ipvs enabled in this netns ? */
-       ipvs = net_ipvs(state->net);
        if (unlikely(sysctl_backup_only(ipvs) || !ipvs->enable))
                return NF_ACCEPT;
 
-       return ip_vs_in_icmp(skb, &r, state->hook);
+       return ip_vs_in_icmp(ipvs, skb, &r, state->hook);
 }
 
 #ifdef CONFIG_IP_VS_IPV6
@@ -1930,7 +1903,7 @@ ip_vs_forward_icmp_v6(void *priv, struct sk_buff *skb,
                      const struct nf_hook_state *state)
 {
        int r;
-       struct netns_ipvs *ipvs;
+       struct netns_ipvs *ipvs = net_ipvs(state->net);
        struct ip_vs_iphdr iphdr;
 
        ip_vs_fill_iph_skb(AF_INET6, skb, false, &iphdr);
@@ -1938,11 +1911,10 @@ ip_vs_forward_icmp_v6(void *priv, struct sk_buff *skb,
                return NF_ACCEPT;
 
        /* ipvs enabled in this netns ? */
-       ipvs = net_ipvs(state->net);
        if (unlikely(sysctl_backup_only(ipvs) || !ipvs->enable))
                return NF_ACCEPT;
 
-       return ip_vs_in_icmp_v6(skb, &r, state->hook, &iphdr);
+       return ip_vs_in_icmp_v6(ipvs, skb, &r, state->hook, &iphdr);
 }
 #endif
 
@@ -1951,7 +1923,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {
        /* After packet filtering, change source only for VS/NAT */
        {
                .hook           = ip_vs_reply4,
-               .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP_PRI_NAT_SRC - 2,
@@ -1961,7 +1932,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {
         * applied to IPVS. */
        {
                .hook           = ip_vs_remote_request4,
-               .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP_PRI_NAT_SRC - 1,
@@ -1969,7 +1939,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {
        /* Before ip_vs_in, change source only for VS/NAT */
        {
                .hook           = ip_vs_local_reply4,
-               .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_OUT,
                .priority       = NF_IP_PRI_NAT_DST + 1,
@@ -1977,7 +1946,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {
        /* After mangle, schedule and forward local requests */
        {
                .hook           = ip_vs_local_request4,
-               .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_OUT,
                .priority       = NF_IP_PRI_NAT_DST + 2,
@@ -1986,7 +1954,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {
         * destined for 0.0.0.0/0, which is for incoming IPVS connections */
        {
                .hook           = ip_vs_forward_icmp,
-               .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_FORWARD,
                .priority       = 99,
@@ -1994,7 +1961,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {
        /* After packet filtering, change source only for VS/NAT */
        {
                .hook           = ip_vs_reply4,
-               .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_FORWARD,
                .priority       = 100,
@@ -2003,7 +1969,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {
        /* After packet filtering, change source only for VS/NAT */
        {
                .hook           = ip_vs_reply6,
-               .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP6_PRI_NAT_SRC - 2,
@@ -2013,7 +1978,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {
         * applied to IPVS. */
        {
                .hook           = ip_vs_remote_request6,
-               .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP6_PRI_NAT_SRC - 1,
@@ -2021,7 +1985,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {
        /* Before ip_vs_in, change source only for VS/NAT */
        {
                .hook           = ip_vs_local_reply6,
-               .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_OUT,
                .priority       = NF_IP6_PRI_NAT_DST + 1,
@@ -2029,7 +1992,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {
        /* After mangle, schedule and forward local requests */
        {
                .hook           = ip_vs_local_request6,
-               .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_OUT,
                .priority       = NF_IP6_PRI_NAT_DST + 2,
@@ -2038,7 +2000,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {
         * destined for 0.0.0.0/0, which is for incoming IPVS connections */
        {
                .hook           = ip_vs_forward_icmp_v6,
-               .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_FORWARD,
                .priority       = 99,
@@ -2046,7 +2007,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {
        /* After packet filtering, change source only for VS/NAT */
        {
                .hook           = ip_vs_reply6,
-               .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_FORWARD,
                .priority       = 100,
@@ -2072,19 +2032,19 @@ static int __net_init __ip_vs_init(struct net *net)
        atomic_inc(&ipvs_netns_cnt);
        net->ipvs = ipvs;
 
-       if (ip_vs_estimator_net_init(net) < 0)
+       if (ip_vs_estimator_net_init(ipvs) < 0)
                goto estimator_fail;
 
        if (ip_vs_control_net_init(ipvs) < 0)
                goto control_fail;
 
-       if (ip_vs_protocol_net_init(net) < 0)
+       if (ip_vs_protocol_net_init(ipvs) < 0)
                goto protocol_fail;
 
-       if (ip_vs_app_net_init(net) < 0)
+       if (ip_vs_app_net_init(ipvs) < 0)
                goto app_fail;
 
-       if (ip_vs_conn_net_init(net) < 0)
+       if (ip_vs_conn_net_init(ipvs) < 0)
                goto conn_fail;
 
        if (ip_vs_sync_net_init(ipvs) < 0)
@@ -2098,15 +2058,15 @@ static int __net_init __ip_vs_init(struct net *net)
  */
 
 sync_fail:
-       ip_vs_conn_net_cleanup(net);
+       ip_vs_conn_net_cleanup(ipvs);
 conn_fail:
-       ip_vs_app_net_cleanup(net);
+       ip_vs_app_net_cleanup(ipvs);
 app_fail:
-       ip_vs_protocol_net_cleanup(net);
+       ip_vs_protocol_net_cleanup(ipvs);
 protocol_fail:
        ip_vs_control_net_cleanup(ipvs);
 control_fail:
-       ip_vs_estimator_net_cleanup(net);
+       ip_vs_estimator_net_cleanup(ipvs);
 estimator_fail:
        net->ipvs = NULL;
        return -ENOMEM;
@@ -2117,11 +2077,11 @@ static void __net_exit __ip_vs_cleanup(struct net *net)
        struct netns_ipvs *ipvs = net_ipvs(net);
 
        ip_vs_service_net_cleanup(ipvs);        /* ip_vs_flush() with locks */
-       ip_vs_conn_net_cleanup(net);
-       ip_vs_app_net_cleanup(net);
-       ip_vs_protocol_net_cleanup(net);
+       ip_vs_conn_net_cleanup(ipvs);
+       ip_vs_app_net_cleanup(ipvs);
+       ip_vs_protocol_net_cleanup(ipvs);
        ip_vs_control_net_cleanup(ipvs);
-       ip_vs_estimator_net_cleanup(net);
+       ip_vs_estimator_net_cleanup(ipvs);
        IP_VS_DBG(2, "ipvs netns %d released\n", ipvs->gen);
        net->ipvs = NULL;
 }