mirror of
https://github.com/torvalds/linux.git
synced 2024-11-18 18:11:56 +00:00
xfrm interface: store xfrmi contexts in a hash by if_id
xfrmi_lookup() is called on every packet. Using a single list for looking up if_id becomes a bottleneck when having many xfrm interfaces. Signed-off-by: Eyal Birger <eyal.birger@gmail.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
This commit is contained in:
parent
2749c69734
commit
e98e44562b
@ -49,20 +49,28 @@ static struct rtnl_link_ops xfrmi_link_ops __read_mostly;
|
|||||||
static unsigned int xfrmi_net_id __read_mostly;
|
static unsigned int xfrmi_net_id __read_mostly;
|
||||||
static const struct net_device_ops xfrmi_netdev_ops;
|
static const struct net_device_ops xfrmi_netdev_ops;
|
||||||
|
|
||||||
|
#define XFRMI_HASH_BITS 8
|
||||||
|
#define XFRMI_HASH_SIZE BIT(XFRMI_HASH_BITS)
|
||||||
|
|
||||||
struct xfrmi_net {
|
struct xfrmi_net {
|
||||||
/* lists for storing interfaces in use */
|
/* lists for storing interfaces in use */
|
||||||
struct xfrm_if __rcu *xfrmi[1];
|
struct xfrm_if __rcu *xfrmi[XFRMI_HASH_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
#define for_each_xfrmi_rcu(start, xi) \
|
#define for_each_xfrmi_rcu(start, xi) \
|
||||||
for (xi = rcu_dereference(start); xi; xi = rcu_dereference(xi->next))
|
for (xi = rcu_dereference(start); xi; xi = rcu_dereference(xi->next))
|
||||||
|
|
||||||
|
static u32 xfrmi_hash(u32 if_id)
|
||||||
|
{
|
||||||
|
return hash_32(if_id, XFRMI_HASH_BITS);
|
||||||
|
}
|
||||||
|
|
||||||
static struct xfrm_if *xfrmi_lookup(struct net *net, struct xfrm_state *x)
|
static struct xfrm_if *xfrmi_lookup(struct net *net, struct xfrm_state *x)
|
||||||
{
|
{
|
||||||
struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id);
|
struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id);
|
||||||
struct xfrm_if *xi;
|
struct xfrm_if *xi;
|
||||||
|
|
||||||
for_each_xfrmi_rcu(xfrmn->xfrmi[0], xi) {
|
for_each_xfrmi_rcu(xfrmn->xfrmi[xfrmi_hash(x->if_id)], xi) {
|
||||||
if (x->if_id == xi->p.if_id &&
|
if (x->if_id == xi->p.if_id &&
|
||||||
(xi->dev->flags & IFF_UP))
|
(xi->dev->flags & IFF_UP))
|
||||||
return xi;
|
return xi;
|
||||||
@ -107,7 +115,7 @@ static struct xfrm_if *xfrmi_decode_session(struct sk_buff *skb,
|
|||||||
|
|
||||||
static void xfrmi_link(struct xfrmi_net *xfrmn, struct xfrm_if *xi)
|
static void xfrmi_link(struct xfrmi_net *xfrmn, struct xfrm_if *xi)
|
||||||
{
|
{
|
||||||
struct xfrm_if __rcu **xip = &xfrmn->xfrmi[0];
|
struct xfrm_if __rcu **xip = &xfrmn->xfrmi[xfrmi_hash(xi->p.if_id)];
|
||||||
|
|
||||||
rcu_assign_pointer(xi->next , rtnl_dereference(*xip));
|
rcu_assign_pointer(xi->next , rtnl_dereference(*xip));
|
||||||
rcu_assign_pointer(*xip, xi);
|
rcu_assign_pointer(*xip, xi);
|
||||||
@ -118,7 +126,7 @@ static void xfrmi_unlink(struct xfrmi_net *xfrmn, struct xfrm_if *xi)
|
|||||||
struct xfrm_if __rcu **xip;
|
struct xfrm_if __rcu **xip;
|
||||||
struct xfrm_if *iter;
|
struct xfrm_if *iter;
|
||||||
|
|
||||||
for (xip = &xfrmn->xfrmi[0];
|
for (xip = &xfrmn->xfrmi[xfrmi_hash(xi->p.if_id)];
|
||||||
(iter = rtnl_dereference(*xip)) != NULL;
|
(iter = rtnl_dereference(*xip)) != NULL;
|
||||||
xip = &iter->next) {
|
xip = &iter->next) {
|
||||||
if (xi == iter) {
|
if (xi == iter) {
|
||||||
@ -162,7 +170,7 @@ static struct xfrm_if *xfrmi_locate(struct net *net, struct xfrm_if_parms *p)
|
|||||||
struct xfrm_if *xi;
|
struct xfrm_if *xi;
|
||||||
struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id);
|
struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id);
|
||||||
|
|
||||||
for (xip = &xfrmn->xfrmi[0];
|
for (xip = &xfrmn->xfrmi[xfrmi_hash(p->if_id)];
|
||||||
(xi = rtnl_dereference(*xip)) != NULL;
|
(xi = rtnl_dereference(*xip)) != NULL;
|
||||||
xip = &xi->next)
|
xip = &xi->next)
|
||||||
if (xi->p.if_id == p->if_id)
|
if (xi->p.if_id == p->if_id)
|
||||||
@ -761,11 +769,14 @@ static void __net_exit xfrmi_exit_batch_net(struct list_head *net_exit_list)
|
|||||||
struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id);
|
struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id);
|
||||||
struct xfrm_if __rcu **xip;
|
struct xfrm_if __rcu **xip;
|
||||||
struct xfrm_if *xi;
|
struct xfrm_if *xi;
|
||||||
|
int i;
|
||||||
|
|
||||||
for (xip = &xfrmn->xfrmi[0];
|
for (i = 0; i < XFRMI_HASH_SIZE; i++) {
|
||||||
(xi = rtnl_dereference(*xip)) != NULL;
|
for (xip = &xfrmn->xfrmi[i];
|
||||||
xip = &xi->next)
|
(xi = rtnl_dereference(*xip)) != NULL;
|
||||||
unregister_netdevice_queue(xi->dev, &list);
|
xip = &xi->next)
|
||||||
|
unregister_netdevice_queue(xi->dev, &list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
unregister_netdevice_many(&list);
|
unregister_netdevice_many(&list);
|
||||||
rtnl_unlock();
|
rtnl_unlock();
|
||||||
|
Loading…
Reference in New Issue
Block a user