Commit 72cb6962 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller

[IPSEC]: Add xfrm_init_state

This patch adds xfrm_init_state which is simply a wrapper that calls
xfrm_get_type and subsequently x->type->init_state.  It also gets rid
of the unused args argument.

Abstracting it out allows us to add common initialisation code, e.g.,
to set family-specific flags.

The add_time setting in xfrm_user.c was deleted because it's already
set by xfrm_state_alloc.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Acked-by: default avatarJames Morris <jmorris@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3f7a87d2
...@@ -225,7 +225,7 @@ struct xfrm_type ...@@ -225,7 +225,7 @@ struct xfrm_type
struct module *owner; struct module *owner;
__u8 proto; __u8 proto;
int (*init_state)(struct xfrm_state *x, void *args); int (*init_state)(struct xfrm_state *x);
void (*destructor)(struct xfrm_state *); void (*destructor)(struct xfrm_state *);
int (*input)(struct xfrm_state *, struct xfrm_decap_state *, struct sk_buff *skb); int (*input)(struct xfrm_state *, struct xfrm_decap_state *, struct sk_buff *skb);
int (*post_input)(struct xfrm_state *, struct xfrm_decap_state *, struct sk_buff *skb); int (*post_input)(struct xfrm_state *, struct xfrm_decap_state *, struct sk_buff *skb);
...@@ -839,6 +839,7 @@ extern int xfrm_replay_check(struct xfrm_state *x, u32 seq); ...@@ -839,6 +839,7 @@ extern int xfrm_replay_check(struct xfrm_state *x, u32 seq);
extern void xfrm_replay_advance(struct xfrm_state *x, u32 seq); extern void xfrm_replay_advance(struct xfrm_state *x, u32 seq);
extern int xfrm_state_check(struct xfrm_state *x, struct sk_buff *skb); extern int xfrm_state_check(struct xfrm_state *x, struct sk_buff *skb);
extern int xfrm_state_mtu(struct xfrm_state *x, int mtu); extern int xfrm_state_mtu(struct xfrm_state *x, int mtu);
extern int xfrm_init_state(struct xfrm_state *x);
extern int xfrm4_rcv(struct sk_buff *skb); extern int xfrm4_rcv(struct sk_buff *skb);
extern int xfrm4_output(struct sk_buff *skb); extern int xfrm4_output(struct sk_buff *skb);
extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler); extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler);
......
...@@ -200,7 +200,7 @@ static void ah4_err(struct sk_buff *skb, u32 info) ...@@ -200,7 +200,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
xfrm_state_put(x); xfrm_state_put(x);
} }
static int ah_init_state(struct xfrm_state *x, void *args) static int ah_init_state(struct xfrm_state *x)
{ {
struct ah_data *ahp = NULL; struct ah_data *ahp = NULL;
struct xfrm_algo_desc *aalg_desc; struct xfrm_algo_desc *aalg_desc;
......
...@@ -362,7 +362,7 @@ static void esp_destroy(struct xfrm_state *x) ...@@ -362,7 +362,7 @@ static void esp_destroy(struct xfrm_state *x)
kfree(esp); kfree(esp);
} }
static int esp_init_state(struct xfrm_state *x, void *args) static int esp_init_state(struct xfrm_state *x)
{ {
struct esp_data *esp = NULL; struct esp_data *esp = NULL;
......
...@@ -236,15 +236,10 @@ static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x) ...@@ -236,15 +236,10 @@ static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x)
t->props.mode = 1; t->props.mode = 1;
t->props.saddr.a4 = x->props.saddr.a4; t->props.saddr.a4 = x->props.saddr.a4;
t->props.flags = x->props.flags; t->props.flags = x->props.flags;
t->type = xfrm_get_type(IPPROTO_IPIP, t->props.family); if (xfrm_init_state(t))
if (t->type == NULL)
goto error;
if (t->type->init_state(t, NULL))
goto error; goto error;
t->km.state = XFRM_STATE_VALID;
atomic_set(&t->tunnel_users, 1); atomic_set(&t->tunnel_users, 1);
out: out:
return t; return t;
...@@ -422,7 +417,7 @@ static void ipcomp_destroy(struct xfrm_state *x) ...@@ -422,7 +417,7 @@ static void ipcomp_destroy(struct xfrm_state *x)
kfree(ipcd); kfree(ipcd);
} }
static int ipcomp_init_state(struct xfrm_state *x, void *args) static int ipcomp_init_state(struct xfrm_state *x)
{ {
int err; int err;
struct ipcomp_data *ipcd; struct ipcomp_data *ipcd;
......
...@@ -84,7 +84,7 @@ static void ipip_err(struct sk_buff *skb, u32 info) ...@@ -84,7 +84,7 @@ static void ipip_err(struct sk_buff *skb, u32 info)
handler->err_handler(skb, &arg); handler->err_handler(skb, &arg);
} }
static int ipip_init_state(struct xfrm_state *x, void *args) static int ipip_init_state(struct xfrm_state *x)
{ {
if (!x->props.mode) if (!x->props.mode)
return -EINVAL; return -EINVAL;
......
...@@ -339,7 +339,7 @@ static void ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, ...@@ -339,7 +339,7 @@ static void ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
xfrm_state_put(x); xfrm_state_put(x);
} }
static int ah6_init_state(struct xfrm_state *x, void *args) static int ah6_init_state(struct xfrm_state *x)
{ {
struct ah_data *ahp = NULL; struct ah_data *ahp = NULL;
struct xfrm_algo_desc *aalg_desc; struct xfrm_algo_desc *aalg_desc;
......
...@@ -296,7 +296,7 @@ static void esp6_destroy(struct xfrm_state *x) ...@@ -296,7 +296,7 @@ static void esp6_destroy(struct xfrm_state *x)
kfree(esp); kfree(esp);
} }
static int esp6_init_state(struct xfrm_state *x, void *args) static int esp6_init_state(struct xfrm_state *x)
{ {
struct esp_data *esp = NULL; struct esp_data *esp = NULL;
......
...@@ -234,14 +234,9 @@ static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x) ...@@ -234,14 +234,9 @@ static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x)
t->props.mode = 1; t->props.mode = 1;
memcpy(t->props.saddr.a6, x->props.saddr.a6, sizeof(struct in6_addr)); memcpy(t->props.saddr.a6, x->props.saddr.a6, sizeof(struct in6_addr));
t->type = xfrm_get_type(IPPROTO_IPV6, t->props.family); if (xfrm_init_state(t))
if (t->type == NULL)
goto error; goto error;
if (t->type->init_state(t, NULL))
goto error;
t->km.state = XFRM_STATE_VALID;
atomic_set(&t->tunnel_users, 1); atomic_set(&t->tunnel_users, 1);
out: out:
...@@ -420,7 +415,7 @@ static void ipcomp6_destroy(struct xfrm_state *x) ...@@ -420,7 +415,7 @@ static void ipcomp6_destroy(struct xfrm_state *x)
xfrm6_tunnel_free_spi((xfrm_address_t *)&x->props.saddr); xfrm6_tunnel_free_spi((xfrm_address_t *)&x->props.saddr);
} }
static int ipcomp6_init_state(struct xfrm_state *x, void *args) static int ipcomp6_init_state(struct xfrm_state *x)
{ {
int err; int err;
struct ipcomp_data *ipcd; struct ipcomp_data *ipcd;
......
...@@ -466,7 +466,7 @@ static void xfrm6_tunnel_err(struct sk_buff *skb, struct inet6_skb_parm *opt, ...@@ -466,7 +466,7 @@ static void xfrm6_tunnel_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
return; return;
} }
static int xfrm6_tunnel_init_state(struct xfrm_state *x, void *args) static int xfrm6_tunnel_init_state(struct xfrm_state *x)
{ {
if (!x->props.mode) if (!x->props.mode)
return -EINVAL; return -EINVAL;
......
...@@ -1096,17 +1096,11 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct sadb_msg *hdr, ...@@ -1096,17 +1096,11 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct sadb_msg *hdr,
} }
} }
x->type = xfrm_get_type(proto, x->props.family); err = xfrm_init_state(x);
if (x->type == NULL) { if (err)
err = -ENOPROTOOPT;
goto out;
}
if (x->type->init_state(x, NULL)) {
err = -EINVAL;
goto out; goto out;
}
x->km.seq = hdr->sadb_msg_seq; x->km.seq = hdr->sadb_msg_seq;
x->km.state = XFRM_STATE_VALID;
return x; return x;
out: out:
......
...@@ -118,7 +118,6 @@ struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family) ...@@ -118,7 +118,6 @@ struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
xfrm_policy_put_afinfo(afinfo); xfrm_policy_put_afinfo(afinfo);
return type; return type;
} }
EXPORT_SYMBOL(xfrm_get_type);
int xfrm_dst_lookup(struct xfrm_dst **dst, struct flowi *fl, int xfrm_dst_lookup(struct xfrm_dst **dst, struct flowi *fl,
unsigned short family) unsigned short family)
......
...@@ -1055,6 +1055,27 @@ int xfrm_state_mtu(struct xfrm_state *x, int mtu) ...@@ -1055,6 +1055,27 @@ int xfrm_state_mtu(struct xfrm_state *x, int mtu)
} }
EXPORT_SYMBOL(xfrm_state_mtu); EXPORT_SYMBOL(xfrm_state_mtu);
int xfrm_init_state(struct xfrm_state *x)
{
int err;
err = -ENOENT;
x->type = xfrm_get_type(x->id.proto, x->props.family);
if (x->type == NULL)
goto error;
err = x->type->init_state(x);
if (err)
goto error;
x->km.state = XFRM_STATE_VALID;
error:
return err;
}
EXPORT_SYMBOL(xfrm_init_state);
void __init xfrm_state_init(void) void __init xfrm_state_init(void)
{ {
......
...@@ -249,17 +249,10 @@ static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p, ...@@ -249,17 +249,10 @@ static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p,
if ((err = attach_encap_tmpl(&x->encap, xfrma[XFRMA_ENCAP-1]))) if ((err = attach_encap_tmpl(&x->encap, xfrma[XFRMA_ENCAP-1])))
goto error; goto error;
err = -ENOENT; err = xfrm_init_state(x);
x->type = xfrm_get_type(x->id.proto, x->props.family);
if (x->type == NULL)
goto error;
err = x->type->init_state(x, NULL);
if (err) if (err)
goto error; goto error;
x->curlft.add_time = (unsigned long) xtime.tv_sec;
x->km.state = XFRM_STATE_VALID;
x->km.seq = p->seq; x->km.seq = p->seq;
return x; return x;
......
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