diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2008-11-25 20:17:47 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-11-25 20:17:47 -0500 |
commit | b754a4fd8f58d245c9b5e92914cce09c4309cb67 (patch) | |
tree | b4b98f60c8be664723106a6ef91cdab669c29657 /net | |
parent | d320bbb306f2085892bc958781e8fcaf5d491589 (diff) |
netns xfrm: per-netns xfrm_state_byspi hash
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/xfrm/xfrm_state.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c index 52d828bdf3d7..66ca1ef7f8eb 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c | |||
@@ -44,7 +44,6 @@ u32 sysctl_xfrm_acq_expires __read_mostly = 30; | |||
44 | 44 | ||
45 | static DEFINE_SPINLOCK(xfrm_state_lock); | 45 | static DEFINE_SPINLOCK(xfrm_state_lock); |
46 | 46 | ||
47 | static struct hlist_head *xfrm_state_byspi __read_mostly; | ||
48 | static unsigned int xfrm_state_hmask __read_mostly; | 47 | static unsigned int xfrm_state_hmask __read_mostly; |
49 | static unsigned int xfrm_state_hashmax __read_mostly = 1 * 1024 * 1024; | 48 | static unsigned int xfrm_state_hashmax __read_mostly = 1 * 1024 * 1024; |
50 | static unsigned int xfrm_state_num; | 49 | static unsigned int xfrm_state_num; |
@@ -154,12 +153,12 @@ static void xfrm_hash_resize(struct work_struct *__unused) | |||
154 | 153 | ||
155 | odst = init_net.xfrm.state_bydst; | 154 | odst = init_net.xfrm.state_bydst; |
156 | osrc = init_net.xfrm.state_bysrc; | 155 | osrc = init_net.xfrm.state_bysrc; |
157 | ospi = xfrm_state_byspi; | 156 | ospi = init_net.xfrm.state_byspi; |
158 | ohashmask = xfrm_state_hmask; | 157 | ohashmask = xfrm_state_hmask; |
159 | 158 | ||
160 | init_net.xfrm.state_bydst = ndst; | 159 | init_net.xfrm.state_bydst = ndst; |
161 | init_net.xfrm.state_bysrc = nsrc; | 160 | init_net.xfrm.state_bysrc = nsrc; |
162 | xfrm_state_byspi = nspi; | 161 | init_net.xfrm.state_byspi = nspi; |
163 | xfrm_state_hmask = nhashmask; | 162 | xfrm_state_hmask = nhashmask; |
164 | 163 | ||
165 | spin_unlock_bh(&xfrm_state_lock); | 164 | spin_unlock_bh(&xfrm_state_lock); |
@@ -679,7 +678,7 @@ static struct xfrm_state *__xfrm_state_lookup(xfrm_address_t *daddr, __be32 spi, | |||
679 | struct xfrm_state *x; | 678 | struct xfrm_state *x; |
680 | struct hlist_node *entry; | 679 | struct hlist_node *entry; |
681 | 680 | ||
682 | hlist_for_each_entry(x, entry, xfrm_state_byspi+h, byspi) { | 681 | hlist_for_each_entry(x, entry, init_net.xfrm.state_byspi+h, byspi) { |
683 | if (x->props.family != family || | 682 | if (x->props.family != family || |
684 | x->id.spi != spi || | 683 | x->id.spi != spi || |
685 | x->id.proto != proto) | 684 | x->id.proto != proto) |
@@ -852,7 +851,7 @@ xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr, | |||
852 | hlist_add_head(&x->bysrc, init_net.xfrm.state_bysrc+h); | 851 | hlist_add_head(&x->bysrc, init_net.xfrm.state_bysrc+h); |
853 | if (x->id.spi) { | 852 | if (x->id.spi) { |
854 | h = xfrm_spi_hash(&x->id.daddr, x->id.spi, x->id.proto, family); | 853 | h = xfrm_spi_hash(&x->id.daddr, x->id.spi, x->id.proto, family); |
855 | hlist_add_head(&x->byspi, xfrm_state_byspi+h); | 854 | hlist_add_head(&x->byspi, init_net.xfrm.state_byspi+h); |
856 | } | 855 | } |
857 | x->lft.hard_add_expires_seconds = sysctl_xfrm_acq_expires; | 856 | x->lft.hard_add_expires_seconds = sysctl_xfrm_acq_expires; |
858 | x->timer.expires = jiffies + sysctl_xfrm_acq_expires*HZ; | 857 | x->timer.expires = jiffies + sysctl_xfrm_acq_expires*HZ; |
@@ -928,7 +927,7 @@ static void __xfrm_state_insert(struct xfrm_state *x) | |||
928 | h = xfrm_spi_hash(&x->id.daddr, x->id.spi, x->id.proto, | 927 | h = xfrm_spi_hash(&x->id.daddr, x->id.spi, x->id.proto, |
929 | x->props.family); | 928 | x->props.family); |
930 | 929 | ||
931 | hlist_add_head(&x->byspi, xfrm_state_byspi+h); | 930 | hlist_add_head(&x->byspi, init_net.xfrm.state_byspi+h); |
932 | } | 931 | } |
933 | 932 | ||
934 | mod_timer(&x->timer, jiffies + HZ); | 933 | mod_timer(&x->timer, jiffies + HZ); |
@@ -1524,7 +1523,7 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high) | |||
1524 | if (x->id.spi) { | 1523 | if (x->id.spi) { |
1525 | spin_lock_bh(&xfrm_state_lock); | 1524 | spin_lock_bh(&xfrm_state_lock); |
1526 | h = xfrm_spi_hash(&x->id.daddr, x->id.spi, x->id.proto, x->props.family); | 1525 | h = xfrm_spi_hash(&x->id.daddr, x->id.spi, x->id.proto, x->props.family); |
1527 | hlist_add_head(&x->byspi, xfrm_state_byspi+h); | 1526 | hlist_add_head(&x->byspi, init_net.xfrm.state_byspi+h); |
1528 | spin_unlock_bh(&xfrm_state_lock); | 1527 | spin_unlock_bh(&xfrm_state_lock); |
1529 | 1528 | ||
1530 | err = 0; | 1529 | err = 0; |
@@ -2086,12 +2085,16 @@ int __net_init xfrm_state_init(struct net *net) | |||
2086 | net->xfrm.state_bysrc = xfrm_hash_alloc(sz); | 2085 | net->xfrm.state_bysrc = xfrm_hash_alloc(sz); |
2087 | if (!net->xfrm.state_bysrc) | 2086 | if (!net->xfrm.state_bysrc) |
2088 | goto out_bysrc; | 2087 | goto out_bysrc; |
2089 | xfrm_state_byspi = xfrm_hash_alloc(sz); | 2088 | net->xfrm.state_byspi = xfrm_hash_alloc(sz); |
2089 | if (!net->xfrm.state_byspi) | ||
2090 | goto out_byspi; | ||
2090 | xfrm_state_hmask = ((sz / sizeof(struct hlist_head)) - 1); | 2091 | xfrm_state_hmask = ((sz / sizeof(struct hlist_head)) - 1); |
2091 | 2092 | ||
2092 | INIT_WORK(&xfrm_state_gc_work, xfrm_state_gc_task); | 2093 | INIT_WORK(&xfrm_state_gc_work, xfrm_state_gc_task); |
2093 | return 0; | 2094 | return 0; |
2094 | 2095 | ||
2096 | out_byspi: | ||
2097 | xfrm_hash_free(net->xfrm.state_bysrc, sz); | ||
2095 | out_bysrc: | 2098 | out_bysrc: |
2096 | xfrm_hash_free(net->xfrm.state_bydst, sz); | 2099 | xfrm_hash_free(net->xfrm.state_bydst, sz); |
2097 | out_bydst: | 2100 | out_bydst: |
@@ -2105,6 +2108,8 @@ void xfrm_state_fini(struct net *net) | |||
2105 | WARN_ON(!list_empty(&net->xfrm.state_all)); | 2108 | WARN_ON(!list_empty(&net->xfrm.state_all)); |
2106 | 2109 | ||
2107 | sz = (xfrm_state_hmask + 1) * sizeof(struct hlist_head); | 2110 | sz = (xfrm_state_hmask + 1) * sizeof(struct hlist_head); |
2111 | WARN_ON(!hlist_empty(net->xfrm.state_byspi)); | ||
2112 | xfrm_hash_free(net->xfrm.state_byspi, sz); | ||
2108 | WARN_ON(!hlist_empty(net->xfrm.state_bysrc)); | 2113 | WARN_ON(!hlist_empty(net->xfrm.state_bysrc)); |
2109 | xfrm_hash_free(net->xfrm.state_bysrc, sz); | 2114 | xfrm_hash_free(net->xfrm.state_bysrc, sz); |
2110 | WARN_ON(!hlist_empty(net->xfrm.state_bydst)); | 2115 | WARN_ON(!hlist_empty(net->xfrm.state_bydst)); |