From patchwork Wed May 9 22:35:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Poirier X-Patchwork-Id: 158054 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 714C2B6F62 for ; Thu, 10 May 2012 08:36:20 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932299Ab2EIWgD (ORCPT ); Wed, 9 May 2012 18:36:03 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:52840 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750846Ab2EIWgA (ORCPT ); Wed, 9 May 2012 18:36:00 -0400 Received: by yenm10 with SMTP id m10so848213yen.19 for ; Wed, 09 May 2012 15:36:00 -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; bh=kwvbcHCk0WTFf+xFZ/HO29cQ40npy0OOWblxC7alnK8=; b=F2OvadCF1mfqChp/4AWjluDVWq45Nm3dxBp+XD2x+jUN90L6I6AhKSJ1fE+uOIgrsG wLR8k3meiTKatIrY93GUxj+XFkebB8b02KovxyHZkrwaQEOEDEHuU7M+ND4Lps2yHLgt ecvVzZzlbkReMgBIPGoM2Wp3Y4rECcVbiYUyJHuTDEQTJeWhkHkzjMzjjPfUTCi3kn/w /oLWIXdIYwYxjx5tk1Uw6TrZ1k5TOlgYkPcvU6oOXabQ6Q4Jw9bhm19Pj6j9x2FEj+AK KkQCFilRv2FgSdjuibRs4ZPDT29FAgqFonKolcI3NbZC99kCkh/3Ub32Yz1nmNw8HfkH 2YSw== Received: by 10.50.169.7 with SMTP id aa7mr2439664igc.52.1336602959883; Wed, 09 May 2012 15:35:59 -0700 (PDT) Received: from localhost.localdomain (modemcable118.38-22-96.mc.videotron.ca. [96.22.38.118]) by mx.google.com with ESMTPS id gf4sm11909654igb.14.2012.05.09.15.35.58 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 09 May 2012 15:35:59 -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] xfrm: take iphdr size into account for esp payload size calculation Date: Wed, 9 May 2012 18:35:52 -0400 Message-Id: <1336602952-10479-1-git-send-email-bpoirier@suse.de> X-Mailer: git-send-email 1.7.7 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 (eg. 1499 leads to FRAGFAILS) and suboptimal frames for others (eg. 1500, where the addition of padding in the esp header can be avoided). 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 --- 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, 3 insertions(+), 21 deletions(-) diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index 89a47b3..60f2738 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c @@ -459,28 +459,10 @@ 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); - - 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); - break; - } - - return mtu - 2; + return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) - + sizeof(struct iphdr)) & ~(align - 1)) + (sizeof(struct + iphdr) - 2); } static void esp4_err(struct sk_buff *skb, u32 info)