static void __xfrm_policy_link(struct xfrm_policy *pol, int dir)
 {
+       struct net *net = xp_net(pol);
        struct hlist_head *chain = policy_hash_bysel(&pol->selector,
                                                     pol->family, dir);
 
-       list_add(&pol->walk.all, &init_net.xfrm.policy_all);
+       list_add(&pol->walk.all, &net->xfrm.policy_all);
        hlist_add_head(&pol->bydst, chain);
-       hlist_add_head(&pol->byidx, init_net.xfrm.policy_byidx+idx_hash(pol->index));
-       init_net.xfrm.policy_count[dir]++;
+       hlist_add_head(&pol->byidx, net->xfrm.policy_byidx+idx_hash(pol->index));
+       net->xfrm.policy_count[dir]++;
        xfrm_pol_hold(pol);
 
-       if (xfrm_bydst_should_resize(&init_net, dir, NULL))
-               schedule_work(&init_net.xfrm.policy_hash_work);
+       if (xfrm_bydst_should_resize(net, dir, NULL))
+               schedule_work(&net->xfrm.policy_hash_work);
 }
 
 static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol,
                                                int dir)
 {
+       struct net *net = xp_net(pol);
+
        if (hlist_unhashed(&pol->bydst))
                return NULL;
 
        hlist_del(&pol->bydst);
        hlist_del(&pol->byidx);
        list_del(&pol->walk.all);
-       init_net.xfrm.policy_count[dir]--;
+       net->xfrm.policy_count[dir]--;
 
        return pol;
 }
 
 static void xfrm_timer_handler(unsigned long data)
 {
        struct xfrm_state *x = (struct xfrm_state*)data;
+       struct net *net = xs_net(x);
        unsigned long now = get_seconds();
        long next = LONG_MAX;
        int warn = 0;
 expired:
        if (x->km.state == XFRM_STATE_ACQ && x->id.spi == 0) {
                x->km.state = XFRM_STATE_EXPIRED;
-               wake_up(&init_net.xfrm.km_waitq);
+               wake_up(&net->xfrm.km_waitq);
                next = 2;
                goto resched;
        }
 
 void __xfrm_state_destroy(struct xfrm_state *x)
 {
+       struct net *net = xs_net(x);
+
        WARN_ON(x->km.state != XFRM_STATE_DEAD);
 
        spin_lock_bh(&xfrm_state_gc_lock);
-       hlist_add_head(&x->gclist, &init_net.xfrm.state_gc_list);
+       hlist_add_head(&x->gclist, &net->xfrm.state_gc_list);
        spin_unlock_bh(&xfrm_state_gc_lock);
-       schedule_work(&init_net.xfrm.state_gc_work);
+       schedule_work(&net->xfrm.state_gc_work);
 }
 EXPORT_SYMBOL(__xfrm_state_destroy);
 
 int __xfrm_state_delete(struct xfrm_state *x)
 {
+       struct net *net = xs_net(x);
        int err = -ESRCH;
 
        if (x->km.state != XFRM_STATE_DEAD) {
                hlist_del(&x->bysrc);
                if (x->id.spi)
                        hlist_del(&x->byspi);
-               init_net.xfrm.state_num--;
+               net->xfrm.state_num--;
                spin_unlock(&xfrm_state_lock);
 
                /* All xfrm_state objects are created by xfrm_state_alloc.
                                                  x->id.proto, family);
 }
 
-static void xfrm_hash_grow_check(int have_hash_collision)
+static void xfrm_hash_grow_check(struct net *net, int have_hash_collision)
 {
        if (have_hash_collision &&
-           (init_net.xfrm.state_hmask + 1) < xfrm_state_hashmax &&
-           init_net.xfrm.state_num > init_net.xfrm.state_hmask)
-               schedule_work(&init_net.xfrm.state_hash_work);
+           (net->xfrm.state_hmask + 1) < xfrm_state_hashmax &&
+           net->xfrm.state_num > net->xfrm.state_hmask)
+               schedule_work(&net->xfrm.state_hash_work);
 }
 
 struct xfrm_state *
                        x->timer.expires = jiffies + sysctl_xfrm_acq_expires*HZ;
                        add_timer(&x->timer);
                        init_net.xfrm.state_num++;
-                       xfrm_hash_grow_check(x->bydst.next != NULL);
+                       xfrm_hash_grow_check(&init_net, x->bydst.next != NULL);
                } else {
                        x->km.state = XFRM_STATE_DEAD;
                        to_put = x;
 
 static void __xfrm_state_insert(struct xfrm_state *x)
 {
+       struct net *net = xs_net(x);
        unsigned int h;
 
        x->genid = ++xfrm_state_genid;
 
-       list_add(&x->km.all, &init_net.xfrm.state_all);
+       list_add(&x->km.all, &net->xfrm.state_all);
 
-       h = xfrm_dst_hash(&init_net, &x->id.daddr, &x->props.saddr,
+       h = xfrm_dst_hash(net, &x->id.daddr, &x->props.saddr,
                          x->props.reqid, x->props.family);
-       hlist_add_head(&x->bydst, init_net.xfrm.state_bydst+h);
+       hlist_add_head(&x->bydst, net->xfrm.state_bydst+h);
 
-       h = xfrm_src_hash(&init_net, &x->id.daddr, &x->props.saddr, x->props.family);
-       hlist_add_head(&x->bysrc, init_net.xfrm.state_bysrc+h);
+       h = xfrm_src_hash(net, &x->id.daddr, &x->props.saddr, x->props.family);
+       hlist_add_head(&x->bysrc, net->xfrm.state_bysrc+h);
 
        if (x->id.spi) {
-               h = xfrm_spi_hash(&init_net, &x->id.daddr, x->id.spi, x->id.proto,
+               h = xfrm_spi_hash(net, &x->id.daddr, x->id.spi, x->id.proto,
                                  x->props.family);
 
-               hlist_add_head(&x->byspi, init_net.xfrm.state_byspi+h);
+               hlist_add_head(&x->byspi, net->xfrm.state_byspi+h);
        }
 
        mod_timer(&x->timer, jiffies + HZ);
        if (x->replay_maxage)
                mod_timer(&x->rtimer, jiffies + x->replay_maxage);
 
-       wake_up(&init_net.xfrm.km_waitq);
+       wake_up(&net->xfrm.km_waitq);
 
-       init_net.xfrm.state_num++;
+       net->xfrm.state_num++;
 
-       xfrm_hash_grow_check(x->bydst.next != NULL);
+       xfrm_hash_grow_check(net, x->bydst.next != NULL);
 }
 
 /* xfrm_state_lock is held */
 static void __xfrm_state_bump_genids(struct xfrm_state *xnew)
 {
+       struct net *net = xs_net(xnew);
        unsigned short family = xnew->props.family;
        u32 reqid = xnew->props.reqid;
        struct xfrm_state *x;
        struct hlist_node *entry;
        unsigned int h;
 
-       h = xfrm_dst_hash(&init_net, &xnew->id.daddr, &xnew->props.saddr, reqid, family);
-       hlist_for_each_entry(x, entry, init_net.xfrm.state_bydst+h, bydst) {
+       h = xfrm_dst_hash(net, &xnew->id.daddr, &xnew->props.saddr, reqid, family);
+       hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) {
                if (x->props.family     == family &&
                    x->props.reqid      == reqid &&
                    !xfrm_addr_cmp(&x->id.daddr, &xnew->id.daddr, family) &&
 
                init_net.xfrm.state_num++;
 
-               xfrm_hash_grow_check(x->bydst.next != NULL);
+               xfrm_hash_grow_check(&init_net, x->bydst.next != NULL);
        }
 
        return x;
 #ifdef CONFIG_XFRM_MIGRATE
 static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp)
 {
+       struct net *net = xs_net(orig);
        int err = -ENOMEM;
-       struct xfrm_state *x = xfrm_state_alloc(&init_net);
+       struct xfrm_state *x = xfrm_state_alloc(net);
        if (!x)
                goto error;
 
 
 void km_state_expired(struct xfrm_state *x, int hard, u32 pid)
 {
+       struct net *net = xs_net(x);
        struct km_event c;
 
        c.data.hard = hard;
        km_state_notify(x, &c);
 
        if (hard)
-               wake_up(&init_net.xfrm.km_waitq);
+               wake_up(&net->xfrm.km_waitq);
 }
 
 EXPORT_SYMBOL(km_state_expired);
 
 void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 pid)
 {
+       struct net *net = xp_net(pol);
        struct km_event c;
 
        c.data.hard = hard;
        km_policy_notify(pol, dir, &c);
 
        if (hard)
-               wake_up(&init_net.xfrm.km_waitq);
+               wake_up(&net->xfrm.km_waitq);
 }
 EXPORT_SYMBOL(km_policy_expired);