[IPSEC]: Add xfrm_state_afinfo->init_flags
authorHerbert Xu <herbert@gondor.apana.org.au>
Mon, 20 Jun 2005 20:19:41 +0000 (13:19 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 20 Jun 2005 20:19:41 +0000 (13:19 -0700)
This patch adds the xfrm_state_afinfo->init_flags hook which allows
each address family to perform any common initialisation that does
not require a corresponding destructor call.

It will be used subsequently to set the XFRM_STATE_NOPMTUDISC flag
in IPv4.

It also fixes up the error codes returned by xfrm_init_state.

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>
include/net/xfrm.h
net/xfrm/xfrm_state.c

index 77bfdde440f8735508676f59f2d9b08a238a090e..029522a4cedab6c3f5ef61f56ce61cb5fe4714e4 100644 (file)
@@ -204,6 +204,7 @@ struct xfrm_state_afinfo {
        rwlock_t                lock;
        struct list_head        *state_bydst;
        struct list_head        *state_byspi;
+       int                     (*init_flags)(struct xfrm_state *x);
        void                    (*init_tempsel)(struct xfrm_state *x, struct flowi *fl,
                                                struct xfrm_tmpl *tmpl,
                                                xfrm_address_t *daddr, xfrm_address_t *saddr);
index 1845b73d69f93dbedc347ba354cef07f15bce211..9d206c282cf193a9867ff3b2c0078a683588a066 100644 (file)
@@ -1058,10 +1058,26 @@ EXPORT_SYMBOL(xfrm_state_mtu);
 
 int xfrm_init_state(struct xfrm_state *x)
 {
+       struct xfrm_state_afinfo *afinfo;
+       int family = x->props.family;
        int err;
 
-       err = -ENOENT;
-       x->type = xfrm_get_type(x->id.proto, x->props.family);
+       err = -EAFNOSUPPORT;
+       afinfo = xfrm_state_get_afinfo(family);
+       if (!afinfo)
+               goto error;
+
+       err = 0;
+       if (afinfo->init_flags)
+               err = afinfo->init_flags(x);
+
+       xfrm_state_put_afinfo(afinfo);
+
+       if (err)
+               goto error;
+
+       err = -EPROTONOSUPPORT;
+       x->type = xfrm_get_type(x->id.proto, family);
        if (x->type == NULL)
                goto error;