Commit 0331b1f3 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by David S. Miller

netns xfrm: add struct xfrm_policy::xp_net

Again, to avoid complications with passing netns when not necessary.
Again, ->xp_net is set-once field, once set it never changes.
Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 50a30657
...@@ -475,6 +475,9 @@ struct xfrm_policy_walk { ...@@ -475,6 +475,9 @@ struct xfrm_policy_walk {
struct xfrm_policy struct xfrm_policy
{ {
#ifdef CONFIG_NET_NS
struct net *xp_net;
#endif
struct hlist_node bydst; struct hlist_node bydst;
struct hlist_node byidx; struct hlist_node byidx;
...@@ -499,6 +502,11 @@ struct xfrm_policy ...@@ -499,6 +502,11 @@ struct xfrm_policy
struct xfrm_tmpl xfrm_vec[XFRM_MAX_DEPTH]; struct xfrm_tmpl xfrm_vec[XFRM_MAX_DEPTH];
}; };
static inline struct net *xp_net(struct xfrm_policy *xp)
{
return read_pnet(&xp->xp_net);
}
struct xfrm_kmaddress { struct xfrm_kmaddress {
xfrm_address_t local; xfrm_address_t local;
xfrm_address_t remote; xfrm_address_t remote;
...@@ -1425,7 +1433,7 @@ static inline int xfrm4_udp_encap_rcv(struct sock *sk, struct sk_buff *skb) ...@@ -1425,7 +1433,7 @@ static inline int xfrm4_udp_encap_rcv(struct sock *sk, struct sk_buff *skb)
} }
#endif #endif
struct xfrm_policy *xfrm_policy_alloc(gfp_t gfp); struct xfrm_policy *xfrm_policy_alloc(struct net *net, gfp_t gfp);
extern void xfrm_policy_walk_init(struct xfrm_policy_walk *walk, u8 type); extern void xfrm_policy_walk_init(struct xfrm_policy_walk *walk, u8 type);
extern int xfrm_policy_walk(struct xfrm_policy_walk *walk, extern int xfrm_policy_walk(struct xfrm_policy_walk *walk,
......
...@@ -2174,7 +2174,7 @@ static int pfkey_spdadd(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h ...@@ -2174,7 +2174,7 @@ static int pfkey_spdadd(struct sock *sk, struct sk_buff *skb, struct sadb_msg *h
if (!pol->sadb_x_policy_dir || pol->sadb_x_policy_dir >= IPSEC_DIR_MAX) if (!pol->sadb_x_policy_dir || pol->sadb_x_policy_dir >= IPSEC_DIR_MAX)
return -EINVAL; return -EINVAL;
xp = xfrm_policy_alloc(GFP_KERNEL); xp = xfrm_policy_alloc(&init_net, GFP_KERNEL);
if (xp == NULL) if (xp == NULL)
return -ENOBUFS; return -ENOBUFS;
...@@ -3141,7 +3141,7 @@ static struct xfrm_policy *pfkey_compile_policy(struct sock *sk, int opt, ...@@ -3141,7 +3141,7 @@ static struct xfrm_policy *pfkey_compile_policy(struct sock *sk, int opt,
(!pol->sadb_x_policy_dir || pol->sadb_x_policy_dir > IPSEC_DIR_OUTBOUND)) (!pol->sadb_x_policy_dir || pol->sadb_x_policy_dir > IPSEC_DIR_OUTBOUND))
return NULL; return NULL;
xp = xfrm_policy_alloc(GFP_ATOMIC); xp = xfrm_policy_alloc(&init_net, GFP_ATOMIC);
if (xp == NULL) { if (xp == NULL) {
*dir = -ENOBUFS; *dir = -ENOBUFS;
return NULL; return NULL;
......
...@@ -228,13 +228,14 @@ static void xfrm_policy_timer(unsigned long data) ...@@ -228,13 +228,14 @@ static void xfrm_policy_timer(unsigned long data)
* SPD calls. * SPD calls.
*/ */
struct xfrm_policy *xfrm_policy_alloc(gfp_t gfp) struct xfrm_policy *xfrm_policy_alloc(struct net *net, gfp_t gfp)
{ {
struct xfrm_policy *policy; struct xfrm_policy *policy;
policy = kzalloc(sizeof(struct xfrm_policy), gfp); policy = kzalloc(sizeof(struct xfrm_policy), gfp);
if (policy) { if (policy) {
write_pnet(&policy->xp_net, net);
INIT_LIST_HEAD(&policy->walk.all); INIT_LIST_HEAD(&policy->walk.all);
INIT_HLIST_NODE(&policy->bydst); INIT_HLIST_NODE(&policy->bydst);
INIT_HLIST_NODE(&policy->byidx); INIT_HLIST_NODE(&policy->byidx);
...@@ -1153,7 +1154,7 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol) ...@@ -1153,7 +1154,7 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol)
static struct xfrm_policy *clone_policy(struct xfrm_policy *old, int dir) static struct xfrm_policy *clone_policy(struct xfrm_policy *old, int dir)
{ {
struct xfrm_policy *newp = xfrm_policy_alloc(GFP_ATOMIC); struct xfrm_policy *newp = xfrm_policy_alloc(xp_net(old), GFP_ATOMIC);
if (newp) { if (newp) {
newp->selector = old->selector; newp->selector = old->selector;
......
...@@ -1080,7 +1080,7 @@ static void copy_to_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy_i ...@@ -1080,7 +1080,7 @@ static void copy_to_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy_i
static struct xfrm_policy *xfrm_policy_construct(struct xfrm_userpolicy_info *p, struct nlattr **attrs, int *errp) static struct xfrm_policy *xfrm_policy_construct(struct xfrm_userpolicy_info *p, struct nlattr **attrs, int *errp)
{ {
struct xfrm_policy *xp = xfrm_policy_alloc(GFP_KERNEL); struct xfrm_policy *xp = xfrm_policy_alloc(&init_net, GFP_KERNEL);
int err; int err;
if (!xp) { if (!xp) {
...@@ -2291,7 +2291,7 @@ static struct xfrm_policy *xfrm_compile_policy(struct sock *sk, int opt, ...@@ -2291,7 +2291,7 @@ static struct xfrm_policy *xfrm_compile_policy(struct sock *sk, int opt,
if (p->dir > XFRM_POLICY_OUT) if (p->dir > XFRM_POLICY_OUT)
return NULL; return NULL;
xp = xfrm_policy_alloc(GFP_KERNEL); xp = xfrm_policy_alloc(&init_net, GFP_KERNEL);
if (xp == NULL) { if (xp == NULL) {
*dir = -ENOBUFS; *dir = -ENOBUFS;
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment