mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-20 21:51:05 +00:00
xfrm: Introduce xfrm_input_afinfo to access the the callbacks properly
IPv6 can be build as a module, so we need mechanism to access the address family dependent callback functions properly. Therefore we introduce xfrm_input_afinfo, similar to that what we have for the address family dependent part of policies and states. Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
This commit is contained in:
parent
870a2df4ca
commit
2f32b51b60
4 changed files with 99 additions and 13 deletions
|
@ -16,6 +16,81 @@
|
|||
|
||||
static struct kmem_cache *secpath_cachep __read_mostly;
|
||||
|
||||
static DEFINE_SPINLOCK(xfrm_input_afinfo_lock);
|
||||
static struct xfrm_input_afinfo __rcu *xfrm_input_afinfo[NPROTO];
|
||||
|
||||
int xfrm_input_register_afinfo(struct xfrm_input_afinfo *afinfo)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
if (unlikely(afinfo == NULL))
|
||||
return -EINVAL;
|
||||
if (unlikely(afinfo->family >= NPROTO))
|
||||
return -EAFNOSUPPORT;
|
||||
spin_lock_bh(&xfrm_input_afinfo_lock);
|
||||
if (unlikely(xfrm_input_afinfo[afinfo->family] != NULL))
|
||||
err = -ENOBUFS;
|
||||
else
|
||||
rcu_assign_pointer(xfrm_input_afinfo[afinfo->family], afinfo);
|
||||
spin_unlock_bh(&xfrm_input_afinfo_lock);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(xfrm_input_register_afinfo);
|
||||
|
||||
int xfrm_input_unregister_afinfo(struct xfrm_input_afinfo *afinfo)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
if (unlikely(afinfo == NULL))
|
||||
return -EINVAL;
|
||||
if (unlikely(afinfo->family >= NPROTO))
|
||||
return -EAFNOSUPPORT;
|
||||
spin_lock_bh(&xfrm_input_afinfo_lock);
|
||||
if (likely(xfrm_input_afinfo[afinfo->family] != NULL)) {
|
||||
if (unlikely(xfrm_input_afinfo[afinfo->family] != afinfo))
|
||||
err = -EINVAL;
|
||||
else
|
||||
RCU_INIT_POINTER(xfrm_input_afinfo[afinfo->family], NULL);
|
||||
}
|
||||
spin_unlock_bh(&xfrm_input_afinfo_lock);
|
||||
synchronize_rcu();
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(xfrm_input_unregister_afinfo);
|
||||
|
||||
static struct xfrm_input_afinfo *xfrm_input_get_afinfo(unsigned int family)
|
||||
{
|
||||
struct xfrm_input_afinfo *afinfo;
|
||||
|
||||
if (unlikely(family >= NPROTO))
|
||||
return NULL;
|
||||
rcu_read_lock();
|
||||
afinfo = rcu_dereference(xfrm_input_afinfo[family]);
|
||||
if (unlikely(!afinfo))
|
||||
rcu_read_unlock();
|
||||
return afinfo;
|
||||
}
|
||||
|
||||
static void xfrm_input_put_afinfo(struct xfrm_input_afinfo *afinfo)
|
||||
{
|
||||
rcu_read_unlock();
|
||||
}
|
||||
|
||||
static int xfrm_rcv_cb(struct sk_buff *skb, unsigned int family, u8 protocol,
|
||||
int err)
|
||||
{
|
||||
int ret;
|
||||
struct xfrm_input_afinfo *afinfo = xfrm_input_get_afinfo(family);
|
||||
|
||||
if (!afinfo)
|
||||
return -EAFNOSUPPORT;
|
||||
|
||||
ret = afinfo->callback(skb, protocol, err);
|
||||
xfrm_input_put_afinfo(afinfo);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void __secpath_destroy(struct sec_path *sp)
|
||||
{
|
||||
int i;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue