From patchwork Fri Jan 25 21:09:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jean-Michel DILLY X-Patchwork-Id: 215869 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 9CDA32C0093 for ; Sat, 26 Jan 2013 08:09:46 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751705Ab3AYVJp (ORCPT ); Fri, 25 Jan 2013 16:09:45 -0500 Received: from mail.dillydally.fr ([87.98.128.188]:44329 "EHLO mail.dillydally.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751448Ab3AYVJo convert rfc822-to-8bit (ORCPT ); Fri, 25 Jan 2013 16:09:44 -0500 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.dillydally.fr (Postfix) with ESMTP id E246D800D5; Fri, 25 Jan 2013 22:09:39 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at dilly.me Received: from mail.dillydally.fr ([127.0.0.1]) by localhost (mail.dillydally.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vUIoICXgbWBi; Fri, 25 Jan 2013 22:09:39 +0100 (CET) Received: from [192.168.0.87] (nancy.dillydally.fr [109.190.61.4]) by mail.dillydally.fr (Postfix) with ESMTPSA id 2AC24800D3; Fri, 25 Jan 2013 22:09:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dilly.me; s=mail; t=1359148179; bh=wAxQyakFF95iT01V4ENFciVx4my/Ve5t8HK+LsBZQgE=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date: Content-Transfer-Encoding:Message-Id:References:To; b=OYXBDhkfrumWm75SyTviCh4nYINH31kfQ31ULtGRjLVGHbcacHpoSyegBlCU9Kp6y mhmjLxBY7TsOzORppQ6mER6yDIyOquLwWUPrnvLSJWhKw/2jr3hDqz9ZajiiUI6HT4 1stVsdIIRWhcuqiwQ0izQenInP5yZVNgR7FkRyBI= Mime-Version: 1.0 (Apple Message framework v1283) Subject: Re: [PATCH] netfilter: fix IPv6 NTP checksum calculation From: Jean-Michel DILLY In-Reply-To: <20130124224924.GH8541@breakpoint.cc> Date: Fri, 25 Jan 2013 22:09:41 +0100 Message-Id: References: <06023CFA-4D28-43B3-8C7F-B8223F3390DD@dilly.me> <20130124224924.GH8541@breakpoint.cc> To: Florian Westphal , netfilter-devel@vger.kernel.org X-Mailer: Apple Mail (2.1283) Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Hi, Here is the signed-off patch. Signed-off-by: Jean-Michel DILLY --- Le 24 janv. 2013 à 23:49, Florian Westphal a écrit : > Jean-Michel DILLY wrote: >> Hi all, >> This patch doesn't work as expected. I tried with few IP and each time 0x0100 were missing. csum_add seems buggy too. >> I have reimplemented csum16s functions with the Ulrich's fix. It seems to work now. >> I'm a noob, so I guess someone will propose a better patch for this. > > We can't use csum_add after all, patch looks correct. > > Can you re-send with proper Signoff? > > [ carry detection breaks on overflow, e.g. a==1 and b=0xffff yields > 0 for csum_add (65536 < 1) and 1 for csum16_add (0 < 1) ] > -- > To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/ip6t_NPT.c b/linux-3.8-rc4/net/ipv6/netfilter/ip6t_NPT.c index 787748b..29ef720 100644 --- a/ip6t_NPT.c +++ b/linux-3.8-rc4/net/ipv6/netfilter/ip6t_NPT.c @@ -14,24 +14,44 @@ #include #include +static __sum16 csum16_add(__sum16 a, __sum16 b) +{ + __u16 result; + + result = (__force __u16) a + (__force __u16) b; + result += result < (__force __u16)b; + + + return (__force __sum16) result; +} + +static __sum16 csum16_complement(__sum16 a) +{ + return (__force __sum16)(0xffff - (__force u16)a); +} + +static __sum16 csum16_sub(__sum16 a, __sum16 b) +{ + return csum16_add(a, csum16_complement(b)); +} static int ip6t_npt_checkentry(const struct xt_tgchk_param *par) { struct ip6t_npt_tginfo *npt = par->targinfo; - __wsum src_sum = 0, dst_sum = 0; + __sum16 src_sum = 0, dst_sum = 0; unsigned int i; if (npt->src_pfx_len > 64 || npt->dst_pfx_len > 64) return -EINVAL; for (i = 0; i < ARRAY_SIZE(npt->src_pfx.in6.s6_addr16); i++) { - src_sum = csum_add(src_sum, - (__force __wsum)npt->src_pfx.in6.s6_addr16[i]); - dst_sum = csum_add(dst_sum, - (__force __wsum)npt->dst_pfx.in6.s6_addr16[i]); + src_sum = csum16_add(src_sum, + (__force __sum16)npt->src_pfx.in6.s6_addr16[i]); + dst_sum = csum16_add(dst_sum, + (__force __sum16)npt->dst_pfx.in6.s6_addr16[i]); } - npt->adjustment = (__force __sum16) csum_sub(src_sum, dst_sum); + npt->adjustment = csum16_sub(src_sum, dst_sum); return 0; } @@ -67,8 +87,8 @@ static bool ip6t_npt_map_pfx(const struct ip6t_npt_tginfo *npt, return false; } - sum = (__force __sum16) csum_add((__force __wsum)addr->s6_addr16[idx], - npt->adjustment); + sum = csum16_add((__force __sum16)addr->s6_addr16[idx], + npt->adjustment); if (sum == CSUM_MANGLED_0) sum = 0; *(__force __sum16 *)&addr->s6_addr16[idx] = sum;