mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 19:56:18 +00:00
netns xfrm: add struct xfrm_state::xs_net
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>
This commit is contained in:
parent
d62ddc21b6
commit
673c09be45
6 changed files with 19 additions and 10 deletions
|
@ -130,6 +130,9 @@ struct xfrm_state_walk {
|
||||||
/* Full description of state of transformer. */
|
/* Full description of state of transformer. */
|
||||||
struct xfrm_state
|
struct xfrm_state
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_NET_NS
|
||||||
|
struct net *xs_net;
|
||||||
|
#endif
|
||||||
union {
|
union {
|
||||||
struct hlist_node gclist;
|
struct hlist_node gclist;
|
||||||
struct hlist_node bydst;
|
struct hlist_node bydst;
|
||||||
|
@ -223,6 +226,11 @@ struct xfrm_state
|
||||||
void *data;
|
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 */
|
/* xflags - make enum if more show up */
|
||||||
#define XFRM_TIME_DEFER 1
|
#define XFRM_TIME_DEFER 1
|
||||||
|
|
||||||
|
@ -1296,7 +1304,7 @@ extern void xfrm_state_walk_init(struct xfrm_state_walk *walk, u8 proto);
|
||||||
extern int xfrm_state_walk(struct xfrm_state_walk *walk,
|
extern int xfrm_state_walk(struct xfrm_state_walk *walk,
|
||||||
int (*func)(struct xfrm_state *, int, void*), void *);
|
int (*func)(struct xfrm_state *, int, void*), void *);
|
||||||
extern void xfrm_state_walk_done(struct xfrm_state_walk *walk);
|
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,
|
extern struct xfrm_state *xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
|
||||||
struct flowi *fl, struct xfrm_tmpl *tmpl,
|
struct flowi *fl, struct xfrm_tmpl *tmpl,
|
||||||
struct xfrm_policy *pol, int *err,
|
struct xfrm_policy *pol, int *err,
|
||||||
|
|
|
@ -49,7 +49,7 @@ static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x)
|
||||||
{
|
{
|
||||||
struct xfrm_state *t;
|
struct xfrm_state *t;
|
||||||
|
|
||||||
t = xfrm_state_alloc();
|
t = xfrm_state_alloc(&init_net);
|
||||||
if (t == NULL)
|
if (t == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x)
|
||||||
{
|
{
|
||||||
struct xfrm_state *t = NULL;
|
struct xfrm_state *t = NULL;
|
||||||
|
|
||||||
t = xfrm_state_alloc();
|
t = xfrm_state_alloc(&init_net);
|
||||||
if (!t)
|
if (!t)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
@ -1122,7 +1122,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct sadb_msg *hdr,
|
||||||
(key->sadb_key_bits+7) / 8 > key->sadb_key_len * sizeof(uint64_t)))
|
(key->sadb_key_bits+7) / 8 > key->sadb_key_len * sizeof(uint64_t)))
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
|
|
||||||
x = xfrm_state_alloc();
|
x = xfrm_state_alloc(&init_net);
|
||||||
if (x == NULL)
|
if (x == NULL)
|
||||||
return ERR_PTR(-ENOBUFS);
|
return ERR_PTR(-ENOBUFS);
|
||||||
|
|
||||||
|
|
|
@ -504,13 +504,14 @@ out:
|
||||||
|
|
||||||
static void xfrm_replay_timer_handler(unsigned long data);
|
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;
|
struct xfrm_state *x;
|
||||||
|
|
||||||
x = kzalloc(sizeof(struct xfrm_state), GFP_ATOMIC);
|
x = kzalloc(sizeof(struct xfrm_state), GFP_ATOMIC);
|
||||||
|
|
||||||
if (x) {
|
if (x) {
|
||||||
|
write_pnet(&x->xs_net, net);
|
||||||
atomic_set(&x->refcnt, 1);
|
atomic_set(&x->refcnt, 1);
|
||||||
atomic_set(&x->tunnel_users, 0);
|
atomic_set(&x->tunnel_users, 0);
|
||||||
INIT_LIST_HEAD(&x->km.all);
|
INIT_LIST_HEAD(&x->km.all);
|
||||||
|
@ -835,7 +836,7 @@ xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
|
||||||
error = -EEXIST;
|
error = -EEXIST;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
x = xfrm_state_alloc();
|
x = xfrm_state_alloc(&init_net);
|
||||||
if (x == NULL) {
|
if (x == NULL) {
|
||||||
error = -ENOMEM;
|
error = -ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -1017,7 +1018,7 @@ static struct xfrm_state *__find_acq_core(unsigned short family, u8 mode, u32 re
|
||||||
if (!create)
|
if (!create)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
x = xfrm_state_alloc();
|
x = xfrm_state_alloc(&init_net);
|
||||||
if (likely(x)) {
|
if (likely(x)) {
|
||||||
switch (family) {
|
switch (family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
|
@ -1125,7 +1126,7 @@ EXPORT_SYMBOL(xfrm_state_add);
|
||||||
static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp)
|
static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp)
|
||||||
{
|
{
|
||||||
int err = -ENOMEM;
|
int err = -ENOMEM;
|
||||||
struct xfrm_state *x = xfrm_state_alloc();
|
struct xfrm_state *x = xfrm_state_alloc(&init_net);
|
||||||
if (!x)
|
if (!x)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
|
|
@ -320,7 +320,7 @@ static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p,
|
||||||
struct nlattr **attrs,
|
struct nlattr **attrs,
|
||||||
int *errp)
|
int *errp)
|
||||||
{
|
{
|
||||||
struct xfrm_state *x = xfrm_state_alloc();
|
struct xfrm_state *x = xfrm_state_alloc(&init_net);
|
||||||
int err = -ENOMEM;
|
int err = -ENOMEM;
|
||||||
|
|
||||||
if (!x)
|
if (!x)
|
||||||
|
@ -1663,7 +1663,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh,
|
||||||
struct nlattr *rt = attrs[XFRMA_TMPL];
|
struct nlattr *rt = attrs[XFRMA_TMPL];
|
||||||
|
|
||||||
struct xfrm_user_acquire *ua = nlmsg_data(nlh);
|
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;
|
int err = -ENOMEM;
|
||||||
|
|
||||||
if (!x)
|
if (!x)
|
||||||
|
|
Loading…
Reference in a new issue