[IPSEC]: Store afinfo pointer in xfrm_mode
It is convenient to have a pointer from xfrm_state to address-specific functions such as the output function for a family. Currently the address-specific policy code calls out to the xfrm state code to get those pointers when we could get it in an easier way via the state itself. This patch adds an xfrm_state_afinfo to xfrm_mode (since they're address-specific) and changes the policy code to use it. I've also added an owner field to do reference counting on the module providing the afinfo even though it isn't strictly necessary today since IPv6 can't be unloaded yet. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
1bfcb10f67
commit
17c2a42a24
|
@ -253,7 +253,8 @@ extern void km_state_expired(struct xfrm_state *x, int hard, u32 pid);
|
||||||
extern int __xfrm_state_delete(struct xfrm_state *x);
|
extern int __xfrm_state_delete(struct xfrm_state *x);
|
||||||
|
|
||||||
struct xfrm_state_afinfo {
|
struct xfrm_state_afinfo {
|
||||||
unsigned short family;
|
unsigned int family;
|
||||||
|
struct module *owner;
|
||||||
struct xfrm_type *type_map[IPPROTO_MAX];
|
struct xfrm_type *type_map[IPPROTO_MAX];
|
||||||
struct xfrm_mode *mode_map[XFRM_MODE_MAX];
|
struct xfrm_mode *mode_map[XFRM_MODE_MAX];
|
||||||
int (*init_flags)(struct xfrm_state *x);
|
int (*init_flags)(struct xfrm_state *x);
|
||||||
|
@ -267,8 +268,6 @@ struct xfrm_state_afinfo {
|
||||||
|
|
||||||
extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
|
extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
|
||||||
extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
|
extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
|
||||||
extern struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned short family);
|
|
||||||
extern void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo);
|
|
||||||
|
|
||||||
extern void xfrm_state_delete_tunnel(struct xfrm_state *x);
|
extern void xfrm_state_delete_tunnel(struct xfrm_state *x);
|
||||||
|
|
||||||
|
@ -312,6 +311,7 @@ struct xfrm_mode {
|
||||||
*/
|
*/
|
||||||
int (*output)(struct xfrm_state *x,struct sk_buff *skb);
|
int (*output)(struct xfrm_state *x,struct sk_buff *skb);
|
||||||
|
|
||||||
|
struct xfrm_state_afinfo *afinfo;
|
||||||
struct module *owner;
|
struct module *owner;
|
||||||
unsigned int encap;
|
unsigned int encap;
|
||||||
int flags;
|
int flags;
|
||||||
|
|
|
@ -151,7 +151,6 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
|
||||||
i = 0;
|
i = 0;
|
||||||
for (; dst_prev != &rt->u.dst; dst_prev = dst_prev->child) {
|
for (; dst_prev != &rt->u.dst; dst_prev = dst_prev->child) {
|
||||||
struct xfrm_dst *x = (struct xfrm_dst*)dst_prev;
|
struct xfrm_dst *x = (struct xfrm_dst*)dst_prev;
|
||||||
struct xfrm_state_afinfo *afinfo;
|
|
||||||
x->u.rt.fl = *fl;
|
x->u.rt.fl = *fl;
|
||||||
|
|
||||||
dst_prev->xfrm = xfrm[i++];
|
dst_prev->xfrm = xfrm[i++];
|
||||||
|
@ -169,17 +168,7 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
|
||||||
/* Copy neighbout for reachability confirmation */
|
/* Copy neighbout for reachability confirmation */
|
||||||
dst_prev->neighbour = neigh_clone(rt->u.dst.neighbour);
|
dst_prev->neighbour = neigh_clone(rt->u.dst.neighbour);
|
||||||
dst_prev->input = rt->u.dst.input;
|
dst_prev->input = rt->u.dst.input;
|
||||||
/* XXX: When IPv6 module can be unloaded, we should manage reference
|
dst_prev->output = dst_prev->xfrm->mode->afinfo->output;
|
||||||
* to xfrm6_output in afinfo->output. Miyazawa
|
|
||||||
* */
|
|
||||||
afinfo = xfrm_state_get_afinfo(dst_prev->xfrm->props.family);
|
|
||||||
if (!afinfo) {
|
|
||||||
dst = *dst_p;
|
|
||||||
err = -EAFNOSUPPORT;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
dst_prev->output = afinfo->output;
|
|
||||||
xfrm_state_put_afinfo(afinfo);
|
|
||||||
if (dst_prev->xfrm->props.family == AF_INET && rt->peer)
|
if (dst_prev->xfrm->props.family == AF_INET && rt->peer)
|
||||||
atomic_inc(&rt->peer->refcnt);
|
atomic_inc(&rt->peer->refcnt);
|
||||||
x->u.rt.peer = rt->peer;
|
x->u.rt.peer = rt->peer;
|
||||||
|
|
|
@ -49,6 +49,7 @@ __xfrm4_init_tempsel(struct xfrm_state *x, struct flowi *fl,
|
||||||
|
|
||||||
static struct xfrm_state_afinfo xfrm4_state_afinfo = {
|
static struct xfrm_state_afinfo xfrm4_state_afinfo = {
|
||||||
.family = AF_INET,
|
.family = AF_INET,
|
||||||
|
.owner = THIS_MODULE,
|
||||||
.init_flags = xfrm4_init_flags,
|
.init_flags = xfrm4_init_flags,
|
||||||
.init_tempsel = __xfrm4_init_tempsel,
|
.init_tempsel = __xfrm4_init_tempsel,
|
||||||
.output = xfrm4_output,
|
.output = xfrm4_output,
|
||||||
|
|
|
@ -214,7 +214,6 @@ __xfrm6_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
|
||||||
i = 0;
|
i = 0;
|
||||||
for (; dst_prev != &rt->u.dst; dst_prev = dst_prev->child) {
|
for (; dst_prev != &rt->u.dst; dst_prev = dst_prev->child) {
|
||||||
struct xfrm_dst *x = (struct xfrm_dst*)dst_prev;
|
struct xfrm_dst *x = (struct xfrm_dst*)dst_prev;
|
||||||
struct xfrm_state_afinfo *afinfo;
|
|
||||||
|
|
||||||
dst_prev->xfrm = xfrm[i++];
|
dst_prev->xfrm = xfrm[i++];
|
||||||
dst_prev->dev = rt->u.dst.dev;
|
dst_prev->dev = rt->u.dst.dev;
|
||||||
|
@ -231,18 +230,7 @@ __xfrm6_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
|
||||||
/* Copy neighbour for reachability confirmation */
|
/* Copy neighbour for reachability confirmation */
|
||||||
dst_prev->neighbour = neigh_clone(rt->u.dst.neighbour);
|
dst_prev->neighbour = neigh_clone(rt->u.dst.neighbour);
|
||||||
dst_prev->input = rt->u.dst.input;
|
dst_prev->input = rt->u.dst.input;
|
||||||
/* XXX: When IPv4 is implemented as module and can be unloaded,
|
dst_prev->output = dst_prev->xfrm->mode->afinfo->output;
|
||||||
* we should manage reference to xfrm4_output in afinfo->output.
|
|
||||||
* Miyazawa
|
|
||||||
*/
|
|
||||||
afinfo = xfrm_state_get_afinfo(dst_prev->xfrm->props.family);
|
|
||||||
if (!afinfo) {
|
|
||||||
dst = *dst_p;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
dst_prev->output = afinfo->output;
|
|
||||||
xfrm_state_put_afinfo(afinfo);
|
|
||||||
/* Sheit... I remember I did this right. Apparently,
|
/* Sheit... I remember I did this right. Apparently,
|
||||||
* it was magically lost, so this code needs audit */
|
* it was magically lost, so this code needs audit */
|
||||||
x->u.rt6.rt6i_flags = rt0->rt6i_flags&(RTCF_BROADCAST|RTCF_MULTICAST|RTCF_LOCAL);
|
x->u.rt6.rt6i_flags = rt0->rt6i_flags&(RTCF_BROADCAST|RTCF_MULTICAST|RTCF_LOCAL);
|
||||||
|
|
|
@ -170,6 +170,7 @@ __xfrm6_tmpl_sort(struct xfrm_tmpl **dst, struct xfrm_tmpl **src, int n)
|
||||||
|
|
||||||
static struct xfrm_state_afinfo xfrm6_state_afinfo = {
|
static struct xfrm_state_afinfo xfrm6_state_afinfo = {
|
||||||
.family = AF_INET6,
|
.family = AF_INET6,
|
||||||
|
.owner = THIS_MODULE,
|
||||||
.init_tempsel = __xfrm6_init_tempsel,
|
.init_tempsel = __xfrm6_init_tempsel,
|
||||||
.tmpl_sort = __xfrm6_tmpl_sort,
|
.tmpl_sort = __xfrm6_tmpl_sort,
|
||||||
.state_sort = __xfrm6_state_sort,
|
.state_sort = __xfrm6_state_sort,
|
||||||
|
|
|
@ -57,6 +57,9 @@ static unsigned int xfrm_state_hashmax __read_mostly = 1 * 1024 * 1024;
|
||||||
static unsigned int xfrm_state_num;
|
static unsigned int xfrm_state_num;
|
||||||
static unsigned int xfrm_state_genid;
|
static unsigned int xfrm_state_genid;
|
||||||
|
|
||||||
|
static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family);
|
||||||
|
static void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo);
|
||||||
|
|
||||||
static inline unsigned int xfrm_dst_hash(xfrm_address_t *daddr,
|
static inline unsigned int xfrm_dst_hash(xfrm_address_t *daddr,
|
||||||
xfrm_address_t *saddr,
|
xfrm_address_t *saddr,
|
||||||
u32 reqid,
|
u32 reqid,
|
||||||
|
@ -289,11 +292,18 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
|
||||||
|
|
||||||
err = -EEXIST;
|
err = -EEXIST;
|
||||||
modemap = afinfo->mode_map;
|
modemap = afinfo->mode_map;
|
||||||
if (likely(modemap[mode->encap] == NULL)) {
|
if (modemap[mode->encap])
|
||||||
modemap[mode->encap] = mode;
|
goto out;
|
||||||
err = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
err = -ENOENT;
|
||||||
|
if (!try_module_get(afinfo->owner))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
mode->afinfo = afinfo;
|
||||||
|
modemap[mode->encap] = mode;
|
||||||
|
err = 0;
|
||||||
|
|
||||||
|
out:
|
||||||
xfrm_state_unlock_afinfo(afinfo);
|
xfrm_state_unlock_afinfo(afinfo);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -316,6 +326,7 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
|
||||||
modemap = afinfo->mode_map;
|
modemap = afinfo->mode_map;
|
||||||
if (likely(modemap[mode->encap] == mode)) {
|
if (likely(modemap[mode->encap] == mode)) {
|
||||||
modemap[mode->encap] = NULL;
|
modemap[mode->encap] = NULL;
|
||||||
|
module_put(mode->afinfo->owner);
|
||||||
err = 0;
|
err = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1869,7 +1880,7 @@ int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(xfrm_state_unregister_afinfo);
|
EXPORT_SYMBOL(xfrm_state_unregister_afinfo);
|
||||||
|
|
||||||
struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned short family)
|
static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family)
|
||||||
{
|
{
|
||||||
struct xfrm_state_afinfo *afinfo;
|
struct xfrm_state_afinfo *afinfo;
|
||||||
if (unlikely(family >= NPROTO))
|
if (unlikely(family >= NPROTO))
|
||||||
|
@ -1881,14 +1892,11 @@ struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned short family)
|
||||||
return afinfo;
|
return afinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo)
|
static void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo)
|
||||||
{
|
{
|
||||||
read_unlock(&xfrm_state_afinfo_lock);
|
read_unlock(&xfrm_state_afinfo_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_SYMBOL(xfrm_state_get_afinfo);
|
|
||||||
EXPORT_SYMBOL(xfrm_state_put_afinfo);
|
|
||||||
|
|
||||||
/* Temporarily located here until net/xfrm/xfrm_tunnel.c is created */
|
/* Temporarily located here until net/xfrm/xfrm_tunnel.c is created */
|
||||||
void xfrm_state_delete_tunnel(struct xfrm_state *x)
|
void xfrm_state_delete_tunnel(struct xfrm_state *x)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue