To avoid unnecessary complications with passing netns around.
* set once, very early after allocating
* once set, never changes
For a while create every xfrm_state in init_net.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
 /* Full description of state of transformer. */
 struct xfrm_state
 {
+#ifdef CONFIG_NET_NS
+       struct net              *xs_net;
+#endif
        union {
                struct hlist_node       gclist;
                struct hlist_node       bydst;
        void                    *data;
 };
 
+static inline struct net *xs_net(struct xfrm_state *x)
+{
+       return read_pnet(&x->xs_net);
+}
+
 /* xflags - make enum if more show up */
 #define XFRM_TIME_DEFER        1
 
 extern int xfrm_state_walk(struct xfrm_state_walk *walk,
                           int (*func)(struct xfrm_state *, int, void*), void *);
 extern void xfrm_state_walk_done(struct xfrm_state_walk *walk);
-extern struct xfrm_state *xfrm_state_alloc(void);
+extern struct xfrm_state *xfrm_state_alloc(struct net *net);
 extern struct xfrm_state *xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr, 
                                          struct flowi *fl, struct xfrm_tmpl *tmpl,
                                          struct xfrm_policy *pol, int *err,
 
 {
        struct xfrm_state *t;
 
-       t = xfrm_state_alloc();
+       t = xfrm_state_alloc(&init_net);
        if (t == NULL)
                goto out;
 
 
 {
        struct xfrm_state *t = NULL;
 
-       t = xfrm_state_alloc();
+       t = xfrm_state_alloc(&init_net);
        if (!t)
                goto out;
 
 
             (key->sadb_key_bits+7) / 8 > key->sadb_key_len * sizeof(uint64_t)))
                return ERR_PTR(-EINVAL);
 
-       x = xfrm_state_alloc();
+       x = xfrm_state_alloc(&init_net);
        if (x == NULL)
                return ERR_PTR(-ENOBUFS);
 
 
 
 static void xfrm_replay_timer_handler(unsigned long data);
 
-struct xfrm_state *xfrm_state_alloc(void)
+struct xfrm_state *xfrm_state_alloc(struct net *net)
 {
        struct xfrm_state *x;
 
        x = kzalloc(sizeof(struct xfrm_state), GFP_ATOMIC);
 
        if (x) {
+               write_pnet(&x->xs_net, net);
                atomic_set(&x->refcnt, 1);
                atomic_set(&x->tunnel_users, 0);
                INIT_LIST_HEAD(&x->km.all);
                        error = -EEXIST;
                        goto out;
                }
-               x = xfrm_state_alloc();
+               x = xfrm_state_alloc(&init_net);
                if (x == NULL) {
                        error = -ENOMEM;
                        goto out;
        if (!create)
                return NULL;
 
-       x = xfrm_state_alloc();
+       x = xfrm_state_alloc(&init_net);
        if (likely(x)) {
                switch (family) {
                case AF_INET:
 static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp)
 {
        int err = -ENOMEM;
-       struct xfrm_state *x = xfrm_state_alloc();
+       struct xfrm_state *x = xfrm_state_alloc(&init_net);
        if (!x)
                goto error;
 
 
                                               struct nlattr **attrs,
                                               int *errp)
 {
-       struct xfrm_state *x = xfrm_state_alloc();
+       struct xfrm_state *x = xfrm_state_alloc(&init_net);
        int err = -ENOMEM;
 
        if (!x)
        struct nlattr *rt = attrs[XFRMA_TMPL];
 
        struct xfrm_user_acquire *ua = nlmsg_data(nlh);
-       struct xfrm_state *x = xfrm_state_alloc();
+       struct xfrm_state *x = xfrm_state_alloc(&init_net);
        int err = -ENOMEM;
 
        if (!x)