pull request (net-next): ipsec-next 2014-09-25
Subsystems (3)
Steffen Klassert
maintainer1) Remove useless hash_resize_mutex in xfrm_hash_resize(). This mutex is used only there, but xfrm_hash_resize() can't be called concurrently at all. From Ying Xue.
2) Extend policy hashing to prefixed policies based on prefix lenght thresholds. From Christophe Gouault.
3) Make the policy hash table thresholds configurable via netlink. From Christophe Gouault.
4) Remove the maximum authentication length for AH. This was needed to limit stack usage. We switched already to allocate space, so no need to keep the limit. From Herbert Xu.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit a3d1214688d5259a200414def4d38f1e4531febd:
neigh: document gc_thresh2 (2014-08-25 17:37:10 -0700)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git master
for you to fetch changes up to 689f1c9de2abbd76fda224d12cea5f43568a4335:
ipsec: Remove obsolete MAX_AH_AUTH_LEN (2014-09-18 10:54:36 +0200)
----------------------------------------------------------------
Christophe Gouault (2):
xfrm: hash prefixed policies based on preflen thresholds
xfrm: configure policy hash table thresholds by netlink
Herbert Xu (1):
ipsec: Remove obsolete MAX_AH_AUTH_LEN
Ying Xue (1):
xfrm: remove useless hash_resize_mutex locks
include/net/ah.h | 3 - include/net/netns/xfrm.h | 14 +++++ include/net/xfrm.h | 1 + include/uapi/linux/xfrm.h | 7 +++ net/ipv4/ah4.c | 2 - net/ipv6/ah6.c | 2 - net/xfrm/xfrm_hash.h | 76 +++++++++++++++++++++---- net/xfrm/xfrm_policy.c | 140 ++++++++++++++++++++++++++++++++++++++++++++-- net/xfrm/xfrm_state.c | 13 +---- net/xfrm/xfrm_user.c | 83 +++++++++++++++++++++++++-- 10 files changed, 303 insertions(+), 38 deletions(-)
Steffen Klassert
maintainerPATCH 1/4 xfrm: remove useless hash_resize_mutex locks
From: Ying Xue <[email protected]>
In xfrm_state.c, hash_resize_mutex is defined as a local variable and only used in xfrm_hash_resize() which is declared as a work handler of xfrm.state_hash_work. But when the xfrm.state_hash_work work is put in the global workqueue(system_wq) with schedule_work(), the work will be really inserted in the global workqueue if it was not already queued, otherwise, it is still left in the same position on the the global workqueue. This means the xfrm_hash_resize() work handler is only executed once at any time no matter how many times its work is scheduled, that is, xfrm_hash_resize() is not called concurrently at all, so hash_resize_mutex is redundant for us.
--- net/xfrm/xfrm_state.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
net/xfrm/xfrm_state.c +3 -10
@@ -97,8 +97,6 @@ static unsigned long xfrm_hash_new_size(unsigned int state_hmask)return ((state_hmask +1 ) <<1 ) *sizeof (struct hlist_head ); } -static DEFINE_MUTEX (hash_resize_mutex); -static void xfrm_hash_resize (struct work_struct *work) { struct net *net = container_of(work, struct net, xfrm.state_hash_work);
@@ -107,22 +105,20 @@ static void xfrm_hash_resize(struct work_struct *work)unsigned int nhashmask, ohashmask;int i; -mutex_lock (&hash_resize_mutex); - nsize =xfrm_hash_new_size (net->xfrm.state_hmask); ndst =xfrm_hash_alloc (nsize);if (!ndst) - goto out_unlock; +return ; nsrc =xfrm_hash_alloc (nsize);if (!nsrc) {xfrm_hash_free (ndst, nsize); - goto out_unlock; +return ; } nspi =xfrm_hash_alloc (nsize);if (!nspi) {xfrm_hash_free (ndst, nsize);xfrm_hash_free (nsrc, nsize); - goto out_unlock; +return ; }spin_lock_bh (&net->xfrm.xfrm_state_lock);
@@ -148,9 +144,6 @@ static void xfrm_hash_resize(struct work_struct *work)xfrm_hash_free (odst, osize);xfrm_hash_free (osrc, osize);xfrm_hash_free (ospi, osize); - -out_unlock: -mutex_unlock (&hash_resize_mutex); }static DEFINE_SPINLOCK (xfrm_state_afinfo_lock);
Signature · 1 line
1.9.1
Steffen Klassert
maintainerPATCH 2/4 xfrm: hash prefixed policies based on preflen thresholds
In reply to Steffen KlassertFrom: Christophe Gouault <[email protected]>
The idea is an extension of the current policy hashing.
Today only non-prefixed policies are stored in a hash table. This patch relaxes the constraints, and hashes policies whose prefix lengths are greater or equal to a configurable threshold.
Each hash table (one per direction) maintains its own set of IPv4 and IPv6 thresholds (dbits4, sbits4, dbits6, sbits6), by default (32, 32, 128, 128).
Example, if the output hash table is configured with values (16, 24, 56, 64):
ip xfrm policy add dir out src 10.22.0.0/20 dst 10.24.1.0/24 ... => hashed ip xfrm policy add dir out src 10.22.0.0/16 dst 10.24.1.1/32 ... => hashed ip xfrm policy add dir out src 10.22.0.0/16 dst 10.24.0.0/16 ... => unhashed
ip xfrm policy add dir out \
src 3ffe:304:124:2200::/60 dst 3ffe:304:124:2401::/64 ... => hashed
ip xfrm policy add dir out \
src 3ffe:304:124:2200::/56 dst 3ffe:304:124:2401::2/128 ... => hashed
ip xfrm policy add dir out \
src 3ffe:304:124:2200::/56 dst 3ffe:304:124:2400::/56 ... => unhashedThe high order bits of the addresses (up to the threshold) are used to compute the hash key.
--- include/net/netns/xfrm.h | 4 +++ net/xfrm/xfrm_hash.h | 76 +++++++++++++++++++++++++++++++++++++++++------- net/xfrm/xfrm_policy.c | 53 +++++++++++++++++++++++++++++---- 3 files changed, 117 insertions(+), 16 deletions(-)
include/net/netns/xfrm.h +4 -0
@@ -13,6 +13,10 @@ struct ctl_table_header;struct xfrm_policy_hash {struct hlist_head *table;unsigned int hmask; +u8 dbits4; +u8 sbits4; +u8 dbits6; +u8 sbits6; };struct netns_xfrm {
net/xfrm/xfrm_hash.h +66 -10
121 lines not on this page · raw message
net/xfrm/xfrm_policy.c +47 -6
97 lines not on this page · raw message
Signature · 1 line
1.9.1
Steffen Klassert
maintainerPATCH 3/4 xfrm: configure policy hash table thresholds by netlink
In reply to Steffen KlassertFrom: Christophe Gouault <[email protected]>
Enable to specify local and remote prefix length thresholds for the policy hash table via a netlink XFRM_MSG_NEWSPDINFO message.
prefix length thresholds are specified by XFRMA_SPD_IPV4_HTHRESH and XFRMA_SPD_IPV6_HTHRESH optional attributes (struct xfrmu_spdhthresh).
example:
struct xfrmu_spdhthresh thresh4 = {
.lbits = 0;
.rbits = 24;
};
struct xfrmu_spdhthresh thresh6 = {
.lbits = 0;
.rbits = 56;
};
struct nlmsghdr *hdr;
struct nl_msg *msg;
msg = nlmsg_alloc();
hdr = nlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, XFRMA_SPD_IPV4_HTHRESH, sizeof(__u32), NLM_F_REQUEST);
nla_put(msg, XFRMA_SPD_IPV4_HTHRESH, sizeof(thresh4), &thresh4);
nla_put(msg, XFRMA_SPD_IPV6_HTHRESH, sizeof(thresh6), &thresh6);
nla_send_auto(sk, msg);The numbers are the policy selector minimum prefix lengths to put a policy in the hash table.
- lbits is the local threshold (source address for out policies, destination address for in and fwd policies).
- rbits is the remote threshold (destination address for out policies, source address for in and fwd policies).
The default values are:
XFRMA_SPD_IPV4_HTHRESH: 32 32XFRMA_SPD_IPV6_HTHRESH: 128 128
Dynamic re-building of the SPD is performed when the thresholds values are changed.
The current thresholds can be read via a XFRM_MSG_GETSPDINFO request:
the kernel replies to XFRM_MSG_GETSPDINFO requests by an XFRM_MSG_NEWSPDINFO message, with both attributes XFRMA_SPD_IPV4_HTHRESH and XFRMA_SPD_IPV6_HTHRESH.
--- include/net/netns/xfrm.h | 10 ++++++ include/net/xfrm.h | 1 + include/uapi/linux/xfrm.h | 7 ++++ net/xfrm/xfrm_policy.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++ net/xfrm/xfrm_user.c | 80 +++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 182 insertions(+), 3 deletions(-)
include/net/netns/xfrm.h +10 -0
@@ -19,6 +19,15 @@ struct xfrm_policy_hash {u8 sbits6; }; +struct xfrm_policy_hthresh { +struct work_struct work; +seqlock_t lock; +u8 lbits4; +u8 rbits4; +u8 lbits6; +u8 rbits6; +}; +struct netns_xfrm {struct list_head state_all;/*
@@ -45,6 +54,7 @@ struct netns_xfrm {struct xfrm_policy_hash policy_bydst[XFRM_POLICY_MAX *2 ];unsigned int policy_count[XFRM_POLICY_MAX *2 ];struct work_struct policy_hash_work; +struct xfrm_policy_hthresh policy_hthresh;struct sock *nlsk;
include/net/xfrm.h +1 -0
@@ -1591,6 +1591,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark,struct xfrm_policy *xfrm_policy_byid (struct net *net,u32 mark,u8 ,int dir,u32 id,int delete,int *err);int xfrm_policy_flush (struct net *net,u8 type,bool task_valid); +void xfrm_policy_hash_rebuild (struct net *net);u32 xfrm_get_acqseq (void );int verify_spi_info (u8 proto,u32 min,u32 max);int xfrm_alloc_spi (struct xfrm_state *x,u32 minspi,u32 maxspi);
include/uapi/linux/xfrm.h +7 -0
@@ -328,6 +328,8 @@ enum xfrm_spdattr_type_t {XFRMA_SPD_UNSPEC ,XFRMA_SPD_INFO ,XFRMA_SPD_HINFO , +XFRMA_SPD_IPV4_HTHRESH , +XFRMA_SPD_IPV6_HTHRESH , __XFRMA_SPD_MAX#define XFRMA_SPD_MAX (__XFRMA_SPD_MAX - 1)
@@ -347,6 +349,11 @@ struct xfrmu_spdhinfo {__u32 spdhmcnt; }; +struct xfrmu_spdhthresh { +__u8 lbits; +__u8 rbits; +}; +struct xfrm_usersa_info {struct xfrm_selector sel;struct xfrm_id id;
net/xfrm/xfrm_policy.c +87 -0
102 lines not on this page · raw message
net/xfrm/xfrm_user.c +77 -3
138 lines not on this page · raw message
Signature · 1 line
1.9.1
Steffen Klassert
maintainerPATCH 4/4 ipsec: Remove obsolete MAX_AH_AUTH_LEN
In reply to Steffen KlassertFrom: Herbert Xu <[email protected]>
While tracking down the MAX_AH_AUTH_LEN crash in an old kernel I thought that this limit was rather arbitrary and we should just get rid of it.
In fact it seems that we've already done all the work needed to remove it apart from actually removing it. This limit was there in order to limit stack usage. Since we've already switched over to allocating scratch space using kmalloc, there is no longer any need to limit the authentication length.
This patch kills all references to it, including the BUG_ONs that led me here.
--- include/net/ah.h | 3 --- net/ipv4/ah4.c | 2 -- net/ipv6/ah6.c | 2 -- net/xfrm/xfrm_user.c | 3 +-- 4 files changed, 1 insertion(+), 9 deletions(-)
include/net/ah.h +0 -3
@@ -3,9 +3,6 @@#include <linux/skbuff.h> -/* This is the maximum truncated ICV length that we know of. */ -#define MAX_AH_AUTH_LEN 64 -struct crypto_ahash ;struct ah_data {
net/ipv4/ah4.c +0 -2
@@ -505,8 +505,6 @@ static int ah_init_state(struct xfrm_state *x) ahp->icv_full_len = aalg_desc->uinfo.auth.icv_fullbits/8 ; ahp->icv_trunc_len = x->aalg->alg_trunc_len/8 ; -BUG_ON (ahp->icv_trunc_len >MAX_AH_AUTH_LEN ); -if (x->props.flags &XFRM_STATE_ALIGN4 ) x->props.header_len =XFRM_ALIGN4 (sizeof (struct ip_auth_hdr ) + ahp->icv_trunc_len);
net/ipv6/ah6.c +0 -2
@@ -713,8 +713,6 @@ static int ah6_init_state(struct xfrm_state *x) ahp->icv_full_len = aalg_desc->uinfo.auth.icv_fullbits/8 ; ahp->icv_trunc_len = x->aalg->alg_trunc_len/8 ; -BUG_ON (ahp->icv_trunc_len >MAX_AH_AUTH_LEN ); - x->props.header_len =XFRM_ALIGN8 (sizeof (struct ip_auth_hdr ) + ahp->icv_trunc_len);switch (x->props.mode) {
net/xfrm/xfrm_user.c +1 -2
@@ -333,8 +333,7 @@ static int attach_auth_trunc(struct xfrm_algo_auth **algpp, u8 *props, algo =xfrm_aalg_get_byname (ualg->alg_name,1 );if (!algo)return -ENOSYS ; -if ((ualg->alg_trunc_len /8 ) >MAX_AH_AUTH_LEN || - ualg->alg_trunc_len > algo->uinfo.auth.icv_fullbits) +if (ualg->alg_trunc_len > algo->uinfo.auth.icv_fullbits)return -EINVAL ; *props = algo->desc.sadb_alg_id;
Signature · 1 line
1.9.1
David Miller
maintainerFrom: Steffen Klassert <[email protected]>
Date: Thu, 25 Sep 2014 11:10:21 +0200
Quoted 7 lines
1) Remove useless
hash_resize_mutexinxfrm_hash_resize(). This mutex is used only there, butxfrm_hash_resize()can't be called concurrently at all. From Ying Xue.2) Extend policy hashing to prefixed policies based on prefix lenght thresholds. From Christophe Gouault.
Quoted 7 lines
3) Make the policy hash table thresholds configurable via netlink. From Christophe Gouault.
4) Remove the maximum authentication length for AH. This was needed to limit stack usage. We switched already to allocate space, so no need to keep the limit. From Herbert Xu.
Pulled, thanks a lot Steffen.