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>
struct xfrm_state_afinfo *afinfo;
struct module *owner;
- unsigned int encap;
- int flags;
+ u8 encap;
+ u8 family;
+ u8 flags;
};
/* Flags for xfrm_mode. */
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)
{
.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);
.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);
.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);
.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);
.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);
.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);
.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);
}
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;
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;
}
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(family);
- if (unlikely(afinfo == NULL))
- return -EAFNOSUPPORT;
+ afinfo = xfrm_state_get_afinfo(mode->family);
+ if (WARN_ON_ONCE(!afinfo))
+ return;
- 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);