* [PATCH net-next 1/3] {IPv4,xfrm} Add Extended Sequence Number (ESN) support for AH egress part
2014-01-08 8:53 [PATCH net-next 0/3] {IPv4,xfrm} Add ESN support for AH Fan Du
@ 2014-01-08 8:53 ` Fan Du
2014-01-08 8:53 ` [PATCH net-next 2/3] {IPv4,xfrm} Add Extended Sequence Number (ESN) support for AH ingress part Fan Du
2014-01-08 8:53 ` [PATCH net-next 3/3] xfrm: Don't prohibit AH from using ESN feature Fan Du
2 siblings, 0 replies; 6+ messages in thread
From: Fan Du @ 2014-01-08 8:53 UTC (permalink / raw)
To: steffen.klassert; +Cc: davem, netdev
This patch add esn support for AH output stage by attaching upper 32bits
sequence number right after packet payload as specified by RFC 4302.
Then the ICV value will guard upper 32bits sequence number as well when
packet going out.
Signed-off-by: Fan Du <fan.du@windriver.com>
---
net/ipv4/ah4.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
index 7179026..a7fac03 100644
--- a/net/ipv4/ah4.c
+++ b/net/ipv4/ah4.c
@@ -12,6 +12,7 @@
#include <linux/scatterlist.h>
#include <net/icmp.h>
#include <net/protocol.h>
+#include <crypto/scatterwalk.h>
struct ah_skb_cb {
struct xfrm_skb_cb xfrm;
@@ -155,6 +156,10 @@ static int ah_output(struct xfrm_state *x, struct sk_buff *skb)
struct iphdr *iph, *top_iph;
struct ip_auth_hdr *ah;
struct ah_data *ahp;
+ int seqhi_len = 0;
+ __be32 *seqhi;
+ int sglists = 0;
+ struct scatterlist *seqhisg;
ahp = x->data;
ahash = ahp->ahash;
@@ -167,14 +172,19 @@ static int ah_output(struct xfrm_state *x, struct sk_buff *skb)
ah = ip_auth_hdr(skb);
ihl = ip_hdrlen(skb);
+ if (x->props.flags & XFRM_STATE_ESN) {
+ sglists = 1;
+ seqhi_len = sizeof(*seqhi);
+ }
err = -ENOMEM;
- iph = ah_alloc_tmp(ahash, nfrags, ihl);
+ iph = ah_alloc_tmp(ahash, nfrags + sglists, ihl + seqhi_len);
if (!iph)
goto out;
-
- icv = ah_tmp_icv(ahash, iph, ihl);
+ seqhi = (__be32 *)((char *)iph + ihl);
+ icv = ah_tmp_icv(ahash, seqhi, seqhi_len);
req = ah_tmp_req(ahash, icv);
sg = ah_req_sg(ahash, req);
+ seqhisg = sg + nfrags;
memset(ah->auth_data, 0, ahp->icv_trunc_len);
@@ -213,7 +223,14 @@ static int ah_output(struct xfrm_state *x, struct sk_buff *skb)
sg_init_table(sg, nfrags);
skb_to_sgvec(skb, sg, 0, skb->len);
- ahash_request_set_crypt(req, sg, icv, skb->len);
+ if ((x->props.flags & XFRM_STATE_ESN)) {
+ sg_unmark_end(&sg[nfrags - 1]);
+ /* Attach seqhi sg right after packet payload */
+ *seqhi = htonl(XFRM_SKB_CB(skb)->seq.output.hi);
+ sg_init_table(seqhisg, sglists);
+ sg_set_buf(seqhisg, seqhi, seqhi_len);
+ }
+ ahash_request_set_crypt(req, sg, icv, skb->len + seqhi_len);
ahash_request_set_callback(req, 0, ah_output_done, skb);
AH_SKB_CB(skb)->tmp = iph;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next 2/3] {IPv4,xfrm} Add Extended Sequence Number (ESN) support for AH ingress part
2014-01-08 8:53 [PATCH net-next 0/3] {IPv4,xfrm} Add ESN support for AH Fan Du
2014-01-08 8:53 ` [PATCH net-next 1/3] {IPv4,xfrm} Add Extended Sequence Number (ESN) support for AH egress part Fan Du
@ 2014-01-08 8:53 ` Fan Du
2014-01-08 8:53 ` [PATCH net-next 3/3] xfrm: Don't prohibit AH from using ESN feature Fan Du
2 siblings, 0 replies; 6+ messages in thread
From: Fan Du @ 2014-01-08 8:53 UTC (permalink / raw)
To: steffen.klassert; +Cc: davem, netdev
This patch add esn support for AH input stage by attaching upper 32bits
sequence number right after packet payload as specified by RFC 4302.
Then the ICV value will guard upper 32bits sequence number as well when
packet getting in.
Signed-off-by: Fan Du <fan.du@windriver.com>
---
net/ipv4/ah4.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
index a7fac03..169d9a5 100644
--- a/net/ipv4/ah4.c
+++ b/net/ipv4/ah4.c
@@ -312,6 +312,10 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
struct ip_auth_hdr *ah;
struct ah_data *ahp;
int err = -ENOMEM;
+ int seqhi_len = 0;
+ __be32 *seqhi;
+ int sglists = 0;
+ struct scatterlist *seqhisg;
if (!pskb_may_pull(skb, sizeof(*ah)))
goto out;
@@ -352,14 +356,21 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
iph = ip_hdr(skb);
ihl = ip_hdrlen(skb);
- work_iph = ah_alloc_tmp(ahash, nfrags, ihl + ahp->icv_trunc_len);
+ if (x->props.flags & XFRM_STATE_ESN) {
+ sglists = 1;
+ seqhi_len = sizeof(*seqhi);
+ }
+
+ work_iph = ah_alloc_tmp(ahash, nfrags + sglists, ihl + ahp->icv_trunc_len + seqhi_len);
if (!work_iph)
goto out;
- auth_data = ah_tmp_auth(work_iph, ihl);
+ seqhi = (__be32 *)((char *)work_iph + ihl);
+ auth_data = ah_tmp_auth(seqhi, seqhi_len);
icv = ah_tmp_icv(ahash, auth_data, ahp->icv_trunc_len);
req = ah_tmp_req(ahash, icv);
sg = ah_req_sg(ahash, req);
+ seqhisg = sg + nfrags;
memcpy(work_iph, iph, ihl);
memcpy(auth_data, ah->auth_data, ahp->icv_trunc_len);
@@ -381,7 +392,14 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
sg_init_table(sg, nfrags);
skb_to_sgvec(skb, sg, 0, skb->len);
- ahash_request_set_crypt(req, sg, icv, skb->len);
+ if ((x->props.flags & XFRM_STATE_ESN)) {
+ sg_unmark_end(&sg[nfrags - 1]);
+ /* Attach seqhi sg right after packet payload */
+ *seqhi = htonl(XFRM_SKB_CB(skb)->seq.output.hi);
+ sg_init_table(seqhisg, sglists);
+ sg_set_buf(seqhisg, seqhi, seqhi_len);
+ }
+ ahash_request_set_crypt(req, sg, icv, skb->len + seqhi_len);
ahash_request_set_callback(req, 0, ah_input_done, skb);
AH_SKB_CB(skb)->tmp = work_iph;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next 3/3] xfrm: Don't prohibit AH from using ESN feature
2014-01-08 8:53 [PATCH net-next 0/3] {IPv4,xfrm} Add ESN support for AH Fan Du
2014-01-08 8:53 ` [PATCH net-next 1/3] {IPv4,xfrm} Add Extended Sequence Number (ESN) support for AH egress part Fan Du
2014-01-08 8:53 ` [PATCH net-next 2/3] {IPv4,xfrm} Add Extended Sequence Number (ESN) support for AH ingress part Fan Du
@ 2014-01-08 8:53 ` Fan Du
2014-01-09 10:50 ` Steffen Klassert
2 siblings, 1 reply; 6+ messages in thread
From: Fan Du @ 2014-01-08 8:53 UTC (permalink / raw)
To: steffen.klassert; +Cc: davem, netdev
Clear checking when user try to use ESN through netlink keymgr for AH.
Signed-off-by: Fan Du <fan.du@windriver.com>
---
net/xfrm/xfrm_user.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 97681a3..f362a78 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -141,10 +141,6 @@ static inline int verify_replay(struct xfrm_usersa_info *p,
if (!rt)
return 0;
-
- if (p->id.proto != IPPROTO_ESP)
- return -EINVAL;
-
if (p->replay_window != 0)
return -EINVAL;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 3/3] xfrm: Don't prohibit AH from using ESN feature
2014-01-08 8:53 ` [PATCH net-next 3/3] xfrm: Don't prohibit AH from using ESN feature Fan Du
@ 2014-01-09 10:50 ` Steffen Klassert
2014-01-09 11:09 ` Fan Du
0 siblings, 1 reply; 6+ messages in thread
From: Steffen Klassert @ 2014-01-09 10:50 UTC (permalink / raw)
To: Fan Du; +Cc: davem, netdev
On Wed, Jan 08, 2014 at 04:53:12PM +0800, Fan Du wrote:
> Clear checking when user try to use ESN through netlink keymgr for AH.
>
> Signed-off-by: Fan Du <fan.du@windriver.com>
> ---
> net/xfrm/xfrm_user.c | 4 ----
> 1 file changed, 4 deletions(-)
>
> diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
> index 97681a3..f362a78 100644
> --- a/net/xfrm/xfrm_user.c
> +++ b/net/xfrm/xfrm_user.c
> @@ -141,10 +141,6 @@ static inline int verify_replay(struct xfrm_usersa_info *p,
>
> if (!rt)
> return 0;
> -
> - if (p->id.proto != IPPROTO_ESP)
> - return -EINVAL;
> -
You can not change this as long as AH for ipv6 does not
support ESN. Please provide the ipv6 side too.
Also, simply removing this check is wrong in any case.
You have to make sure that we catch if someone tries
to insert an ESN state for other unsupported protocols,
like ipcomp.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 3/3] xfrm: Don't prohibit AH from using ESN feature
2014-01-09 10:50 ` Steffen Klassert
@ 2014-01-09 11:09 ` Fan Du
0 siblings, 0 replies; 6+ messages in thread
From: Fan Du @ 2014-01-09 11:09 UTC (permalink / raw)
To: Steffen Klassert; +Cc: davem, netdev
On 2014年01月09日 18:50, Steffen Klassert wrote:
> On Wed, Jan 08, 2014 at 04:53:12PM +0800, Fan Du wrote:
>> Clear checking when user try to use ESN through netlink keymgr for AH.
>>
>> Signed-off-by: Fan Du<fan.du@windriver.com>
>> ---
>> net/xfrm/xfrm_user.c | 4 ----
>> 1 file changed, 4 deletions(-)
>>
>> diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
>> index 97681a3..f362a78 100644
>> --- a/net/xfrm/xfrm_user.c
>> +++ b/net/xfrm/xfrm_user.c
>> @@ -141,10 +141,6 @@ static inline int verify_replay(struct xfrm_usersa_info *p,
>>
>> if (!rt)
>> return 0;
>> -
>> - if (p->id.proto != IPPROTO_ESP)
>> - return -EINVAL;
>> -
>
> You can not change this as long as AH for ipv6 does not
> support ESN. Please provide the ipv6 side too.
>
> Also, simply removing this check is wrong in any case.
> You have to make sure that we catch if someone tries
> to insert an ESN state for other unsupported protocols,
> like ipcomp.
>
Sure, will add IPv6 support soon :)
--
浮沉随浪只记今朝笑
--fan
^ permalink raw reply [flat|nested] 6+ messages in thread