xfrm: place af number into xfrm_mode struct

This will be useful to know if we're supposed to decode ipv4 or ipv6.

While at it, make the unregister function return void, all module_exit
functions did just BUG(); there is never a point in doing error checks
if there is no way to handle such error.

Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
This commit is contained in:
Florian Westphal 2019-03-29 21:16:22 +01:00 committed by Steffen Klassert
parent f981c57ffd
commit b262a69582
9 changed files with 32 additions and 52 deletions

View file

@ -482,8 +482,9 @@ struct xfrm_mode {
struct xfrm_state_afinfo *afinfo;
struct module *owner;
unsigned int encap;
int flags;
u8 encap;
u8 family;
u8 flags;
};
/* Flags for xfrm_mode. */
@ -491,8 +492,8 @@ enum {
XFRM_MODE_FLAG_TUNNEL = 1,
};
int xfrm_register_mode(struct xfrm_mode *mode, int family);
int xfrm_unregister_mode(struct xfrm_mode *mode, int family);
int xfrm_register_mode(struct xfrm_mode *mode);
void xfrm_unregister_mode(struct xfrm_mode *mode);
static inline int xfrm_af2proto(unsigned int family)
{

View file

@ -134,19 +134,17 @@ static struct xfrm_mode xfrm4_beet_mode = {
.owner = THIS_MODULE,
.encap = XFRM_MODE_BEET,
.flags = XFRM_MODE_FLAG_TUNNEL,
.family = AF_INET,
};
static int __init xfrm4_beet_init(void)
{
return xfrm_register_mode(&xfrm4_beet_mode, AF_INET);
return xfrm_register_mode(&xfrm4_beet_mode);
}
static void __exit xfrm4_beet_exit(void)
{
int err;
err = xfrm_unregister_mode(&xfrm4_beet_mode, AF_INET);
BUG_ON(err);
xfrm_unregister_mode(&xfrm4_beet_mode);
}
module_init(xfrm4_beet_init);

View file

@ -93,19 +93,17 @@ static struct xfrm_mode xfrm4_transport_mode = {
.xmit = xfrm4_transport_xmit,
.owner = THIS_MODULE,
.encap = XFRM_MODE_TRANSPORT,
.family = AF_INET,
};
static int __init xfrm4_transport_init(void)
{
return xfrm_register_mode(&xfrm4_transport_mode, AF_INET);
return xfrm_register_mode(&xfrm4_transport_mode);
}
static void __exit xfrm4_transport_exit(void)
{
int err;
err = xfrm_unregister_mode(&xfrm4_transport_mode, AF_INET);
BUG_ON(err);
xfrm_unregister_mode(&xfrm4_transport_mode);
}
module_init(xfrm4_transport_init);

View file

@ -131,19 +131,17 @@ static struct xfrm_mode xfrm4_tunnel_mode = {
.owner = THIS_MODULE,
.encap = XFRM_MODE_TUNNEL,
.flags = XFRM_MODE_FLAG_TUNNEL,
.family = AF_INET,
};
static int __init xfrm4_mode_tunnel_init(void)
{
return xfrm_register_mode(&xfrm4_tunnel_mode, AF_INET);
return xfrm_register_mode(&xfrm4_tunnel_mode);
}
static void __exit xfrm4_mode_tunnel_exit(void)
{
int err;
err = xfrm_unregister_mode(&xfrm4_tunnel_mode, AF_INET);
BUG_ON(err);
xfrm_unregister_mode(&xfrm4_tunnel_mode);
}
module_init(xfrm4_mode_tunnel_init);

View file

@ -110,19 +110,17 @@ static struct xfrm_mode xfrm6_beet_mode = {
.owner = THIS_MODULE,
.encap = XFRM_MODE_BEET,
.flags = XFRM_MODE_FLAG_TUNNEL,
.family = AF_INET6,
};
static int __init xfrm6_beet_init(void)
{
return xfrm_register_mode(&xfrm6_beet_mode, AF_INET6);
return xfrm_register_mode(&xfrm6_beet_mode);
}
static void __exit xfrm6_beet_exit(void)
{
int err;
err = xfrm_unregister_mode(&xfrm6_beet_mode, AF_INET6);
BUG_ON(err);
xfrm_unregister_mode(&xfrm6_beet_mode);
}
module_init(xfrm6_beet_init);

View file

@ -64,19 +64,17 @@ static struct xfrm_mode xfrm6_ro_mode = {
.output = xfrm6_ro_output,
.owner = THIS_MODULE,
.encap = XFRM_MODE_ROUTEOPTIMIZATION,
.family = AF_INET6,
};
static int __init xfrm6_ro_init(void)
{
return xfrm_register_mode(&xfrm6_ro_mode, AF_INET6);
return xfrm_register_mode(&xfrm6_ro_mode);
}
static void __exit xfrm6_ro_exit(void)
{
int err;
err = xfrm_unregister_mode(&xfrm6_ro_mode, AF_INET6);
BUG_ON(err);
xfrm_unregister_mode(&xfrm6_ro_mode);
}
module_init(xfrm6_ro_init);

View file

@ -100,19 +100,17 @@ static struct xfrm_mode xfrm6_transport_mode = {
.xmit = xfrm6_transport_xmit,
.owner = THIS_MODULE,
.encap = XFRM_MODE_TRANSPORT,
.family = AF_INET6,
};
static int __init xfrm6_transport_init(void)
{
return xfrm_register_mode(&xfrm6_transport_mode, AF_INET6);
return xfrm_register_mode(&xfrm6_transport_mode);
}
static void __exit xfrm6_transport_exit(void)
{
int err;
err = xfrm_unregister_mode(&xfrm6_transport_mode, AF_INET6);
BUG_ON(err);
xfrm_unregister_mode(&xfrm6_transport_mode);
}
module_init(xfrm6_transport_init);

View file

@ -130,19 +130,17 @@ static struct xfrm_mode xfrm6_tunnel_mode = {
.owner = THIS_MODULE,
.encap = XFRM_MODE_TUNNEL,
.flags = XFRM_MODE_FLAG_TUNNEL,
.family = AF_INET6,
};
static int __init xfrm6_mode_tunnel_init(void)
{
return xfrm_register_mode(&xfrm6_tunnel_mode, AF_INET6);
return xfrm_register_mode(&xfrm6_tunnel_mode);
}
static void __exit xfrm6_mode_tunnel_exit(void)
{
int err;
err = xfrm_unregister_mode(&xfrm6_tunnel_mode, AF_INET6);
BUG_ON(err);
xfrm_unregister_mode(&xfrm6_tunnel_mode);
}
module_init(xfrm6_mode_tunnel_init);

View file

@ -331,7 +331,7 @@ static void xfrm_put_type_offload(const struct xfrm_type_offload *type)
}
static DEFINE_SPINLOCK(xfrm_mode_lock);
int xfrm_register_mode(struct xfrm_mode *mode, int family)
int xfrm_register_mode(struct xfrm_mode *mode)
{
struct xfrm_state_afinfo *afinfo;
struct xfrm_mode **modemap;
@ -340,7 +340,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
if (unlikely(mode->encap >= XFRM_MODE_MAX))
return -EINVAL;
afinfo = xfrm_state_get_afinfo(family);
afinfo = xfrm_state_get_afinfo(mode->family);
if (unlikely(afinfo == NULL))
return -EAFNOSUPPORT;
@ -365,31 +365,24 @@ out:
}
EXPORT_SYMBOL(xfrm_register_mode);
int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
void xfrm_unregister_mode(struct xfrm_mode *mode)
{
struct xfrm_state_afinfo *afinfo;
struct xfrm_mode **modemap;
int err;
if (unlikely(mode->encap >= XFRM_MODE_MAX))
return -EINVAL;
afinfo = xfrm_state_get_afinfo(mode->family);
if (WARN_ON_ONCE(!afinfo))
return;
afinfo = xfrm_state_get_afinfo(family);
if (unlikely(afinfo == NULL))
return -EAFNOSUPPORT;
err = -ENOENT;
modemap = afinfo->mode_map;
spin_lock_bh(&xfrm_mode_lock);
if (likely(modemap[mode->encap] == mode)) {
modemap[mode->encap] = NULL;
module_put(mode->afinfo->owner);
err = 0;
}
spin_unlock_bh(&xfrm_mode_lock);
rcu_read_unlock();
return err;
}
EXPORT_SYMBOL(xfrm_unregister_mode);