From patchwork Fri May 11 01:07:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Poirier X-Patchwork-Id: 158416 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3AB1AB6FB4 for ; Fri, 11 May 2012 11:07:57 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757532Ab2EKBHk (ORCPT ); Thu, 10 May 2012 21:07:40 -0400 Received: from mail-yw0-f46.google.com ([209.85.213.46]:40252 "EHLO mail-yw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755909Ab2EKBHi (ORCPT ); Thu, 10 May 2012 21:07:38 -0400 Received: by yhmm54 with SMTP id m54so2120490yhm.19 for ; Thu, 10 May 2012 18:07:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=V6GQiq2f7Y8AQoXCD7CYCjNJUClQNsn0JTY4lLe7jjw=; b=ppTk6tAquMLdLTC1EdNv/ICtbXs2F8CiVurjZLEQGC2aJOl/mFdNM+Jr/O0HEiE051 UH5lRRYBeDKhEbfYAAeP4CM8IOHxp9P0AQyV8rVw49q1zKhfiVpNi/bCLWHYBbx71Oky 99slgfMoKV2h8ftiRgWtpuvkpsNTEO9HXwVgNGE7yMw3oPnoM5NVUml5XjjjGqFqvEg4 xH3f3tacNXROPKTSvAR+devtx0fa0z2c80unB3g5qi+ZKhbW0sNe5yURV/idBaXW94Q5 zVKxjreUPwKdmn15wkozqcVhmgxBufSienCV8rE8zfz9CNf1825LwXggcJu1oE3Wf4KF CfnQ== Received: by 10.50.94.200 with SMTP id de8mr586677igb.21.1336698457293; Thu, 10 May 2012 18:07:37 -0700 (PDT) Received: from localhost.localdomain (modemcable118.38-22-96.mc.videotron.ca. [96.22.38.118]) by mx.google.com with ESMTPS id vp3sm3780101igb.3.2012.05.10.18.07.35 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 10 May 2012 18:07:36 -0700 (PDT) From: Benjamin Poirier To: netdev@vger.kernel.org Cc: "David S. Miller" , Alexey Kuznetsov , James Morris , Hideaki YOSHIFUJI , Patrick McHardy , linux-kernel@vger.kernel.org Subject: [PATCH v2] xfrm: take iphdr size into account for esp payload size calculation Date: Thu, 10 May 2012 21:07:22 -0400 Message-Id: <1336698442-25148-1-git-send-email-bpoirier@suse.de> X-Mailer: git-send-email 1.7.7 In-Reply-To: <20120511010249.GA23584@d2.synalogic.ca> References: <20120511010249.GA23584@d2.synalogic.ca> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Corrects the function that determines the esp payload size. The calculations done in esp4_get_mtu lead to overlength frames in transport mode for certain mtu values and suboptimal frames for others. According to what is done, mainly in esp_output(), net_header_len aka sizeof(struct iphdr) must be taken into account before doing the alignment calculation. Signed-off-by: Benjamin Poirier --- Changes since v1: * introduce l3_adj to preserve the same returned value as before for tunnel mode For example, with md5 AH and 3des ESP (transport mode): mtu = 1499 leads to FRAGFAILS mtu = 1500 the addition of padding in the esp header could be avoided Tested with * transport mode E * transport mode EA * transport mode E + ah * tunnel mode E Not tested with BEET, but it should be the same as transport mode draft-nikander-esp-beet-mode-03.txt Section 5.2: "The wire packet format is identical to the ESP transport mode" --- net/ipv4/esp4.c | 24 +++++++++--------------- 1 files changed, 9 insertions(+), 15 deletions(-) diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index 89a47b3..b2503f6 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c @@ -459,28 +459,22 @@ static u32 esp4_get_mtu(struct xfrm_state *x, int mtu) struct esp_data *esp = x->data; u32 blksize = ALIGN(crypto_aead_blocksize(esp->aead), 4); u32 align = max_t(u32, blksize, esp->padlen); - u32 rem; - - mtu -= x->props.header_len + crypto_aead_authsize(esp->aead); - rem = mtu & (align - 1); - mtu &= ~(align - 1); + unsigned int l3_adj; switch (x->props.mode) { - case XFRM_MODE_TUNNEL: - break; - default: case XFRM_MODE_TRANSPORT: - /* The worst case */ - mtu -= blksize - 4; - mtu += min_t(u32, blksize - 4, rem); - break; case XFRM_MODE_BEET: - /* The worst case. */ - mtu += min_t(u32, IPV4_BEET_PHMAXLEN, rem); + l3_adj = sizeof(struct iphdr); break; + case XFRM_MODE_TUNNEL: + l3_adj = 0; + break; + default: + BUG(); } - return mtu - 2; + return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) - + l3_adj) & ~(align - 1)) + (l3_adj - 2); } static void esp4_err(struct sk_buff *skb, u32 info)