Skip to content

Commit

Permalink
[IPSEC]: Add xfrm_init_state
Browse files Browse the repository at this point in the history
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: Herbert Xu <herbert@gondor.apana.org.au>
Acked-by: James Morris <jmorris@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
herbertx authored and davem330 committed Jun 20, 2005
1 parent 3f7a87d commit 72cb696
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 40 deletions.
3 changes: 2 additions & 1 deletion include/net/xfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ struct xfrm_type
struct module *owner;
__u8 proto;

int (*init_state)(struct xfrm_state *x, void *args);
int (*init_state)(struct xfrm_state *x);
void (*destructor)(struct xfrm_state *);
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);
Expand Down Expand Up @@ -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 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_init_state(struct xfrm_state *x);
extern int xfrm4_rcv(struct sk_buff *skb);
extern int xfrm4_output(struct sk_buff *skb);
extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler);
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/ah4.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
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 xfrm_algo_desc *aalg_desc;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/esp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ static void esp_destroy(struct xfrm_state *x)
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;

Expand Down
11 changes: 3 additions & 8 deletions net/ipv4/ipcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,10 @@ static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x)
t->props.mode = 1;
t->props.saddr.a4 = x->props.saddr.a4;
t->props.flags = x->props.flags;

t->type = xfrm_get_type(IPPROTO_IPIP, t->props.family);
if (t->type == NULL)
goto error;

if (t->type->init_state(t, NULL))

if (xfrm_init_state(t))
goto error;

t->km.state = XFRM_STATE_VALID;
atomic_set(&t->tunnel_users, 1);
out:
return t;
Expand Down Expand Up @@ -422,7 +417,7 @@ static void ipcomp_destroy(struct xfrm_state *x)
kfree(ipcd);
}

static int ipcomp_init_state(struct xfrm_state *x, void *args)
static int ipcomp_init_state(struct xfrm_state *x)
{
int err;
struct ipcomp_data *ipcd;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/xfrm4_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static void ipip_err(struct sk_buff *skb, u32 info)
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)
return -EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/ah6.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static void ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
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 xfrm_algo_desc *aalg_desc;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/esp6.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ static void esp6_destroy(struct xfrm_state *x)
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;

Expand Down
9 changes: 2 additions & 7 deletions net/ipv6/ipcomp6.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,9 @@ static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x)
t->props.mode = 1;
memcpy(t->props.saddr.a6, x->props.saddr.a6, sizeof(struct in6_addr));

t->type = xfrm_get_type(IPPROTO_IPV6, t->props.family);
if (t->type == NULL)
if (xfrm_init_state(t))
goto error;

if (t->type->init_state(t, NULL))
goto error;

t->km.state = XFRM_STATE_VALID;
atomic_set(&t->tunnel_users, 1);

out:
Expand Down Expand Up @@ -420,7 +415,7 @@ static void ipcomp6_destroy(struct xfrm_state *x)
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;
struct ipcomp_data *ipcd;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/xfrm6_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ static void xfrm6_tunnel_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
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)
return -EINVAL;
Expand Down
12 changes: 3 additions & 9 deletions net/key/af_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -1096,17 +1096,11 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct sadb_msg *hdr,
}
}

x->type = xfrm_get_type(proto, x->props.family);
if (x->type == NULL) {
err = -ENOPROTOOPT;
goto out;
}
if (x->type->init_state(x, NULL)) {
err = -EINVAL;
err = xfrm_init_state(x);
if (err)
goto out;
}

x->km.seq = hdr->sadb_msg_seq;
x->km.state = XFRM_STATE_VALID;
return x;

out:
Expand Down
1 change: 0 additions & 1 deletion net/xfrm/xfrm_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
xfrm_policy_put_afinfo(afinfo);
return type;
}
EXPORT_SYMBOL(xfrm_get_type);

int xfrm_dst_lookup(struct xfrm_dst **dst, struct flowi *fl,
unsigned short family)
Expand Down
21 changes: 21 additions & 0 deletions net/xfrm/xfrm_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,27 @@ int xfrm_state_mtu(struct xfrm_state *x, int 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)
{
Expand Down
9 changes: 1 addition & 8 deletions net/xfrm/xfrm_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])))
goto error;

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, NULL);
err = xfrm_init_state(x);
if (err)
goto error;

x->curlft.add_time = (unsigned long) xtime.tv_sec;
x->km.state = XFRM_STATE_VALID;
x->km.seq = p->seq;

return x;
Expand Down

0 comments on commit 72cb696

Please sign in to comment.