From patchwork Thu Dec 10 21:53:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 342646 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF72EC2BBCF for ; Thu, 10 Dec 2020 23:08:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C2472332A for ; Thu, 10 Dec 2020 23:08:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394173AbgLJWbW (ORCPT ); Thu, 10 Dec 2020 17:31:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60677 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405145AbgLJW2a (ORCPT ); Thu, 10 Dec 2020 17:28:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607639223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0i8bXJYeqHWVQ3kqT+YAvemEqycrW60WPjZl2fOfz/o=; b=XYoFVMwh3kGTBYP6ezt2pCyQKVBYxGLAYeUwnyDPWzWXVrEdpEuyt0/sJipuaqaSi94RJR F0hPI1MSipO6vqQlov1bFbc9Jkp/BGpvOcbmXdIeJYHn6qWlCENRbzJ/jrRCp1mfxVvP6d dvdup9l6SVlpsPEJpen7bbTZeUsgP10= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-565-QDoUKpJVM5uRUmKEAH0JPA-1; Thu, 10 Dec 2020 16:53:41 -0500 X-MC-Unique: QDoUKpJVM5uRUmKEAH0JPA-1 Received: by mail-wr1-f70.google.com with SMTP id o12so2422538wrq.13 for ; Thu, 10 Dec 2020 13:53:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0i8bXJYeqHWVQ3kqT+YAvemEqycrW60WPjZl2fOfz/o=; b=LwkuMhVX2pxIRASNWYG0JZ5kxyGM60P0oF0O9wuBYgNq5PS41FqzdsHEaVCuE7ttXK jVZBPFMTx43stDYoUWgNjh8w2vNp/GIRzCgH5lYCb40u/Vu3EiYiH1DTQdN011KuEezB rpDcxDtqCJDCqymcsoCVGAqKbNlIX/1RpKn+3ijlESIQM5XUyeMS5dlodb4LA4fT1CEz 5P/A8+x8CeUtA2hDszj7f1uZCV1pKDGa9oGTj/hFI3Y2Vx7d5z2U1CQLHsco4u+mNHpO +xQYBwH6VxNVQ257+zZu2xHg9Yjm/ov0KhYwnQJJMeEN0qXfkozs75CtnzPUGuOKrS3W yRkg== X-Gm-Message-State: AOAM531gjD1tWFAJceUDDhvfATo+YtQAXYxNZG22IWJ6DvNlGa+RjjPX Dz08vqMOryisZirAO7WOUmmNjVCB9gZXc0+TAG+U9r0TWTw6BgPq6UnNyStoa67HeXC5AF4SAD+ CI/HETE9AQyjqmJ7Y X-Received: by 2002:a5d:40ce:: with SMTP id b14mr10292856wrq.350.1607637220061; Thu, 10 Dec 2020 13:53:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1f3NIbAKDDoulfDKrPujtjmk6g5/Bkjd068CwxcRzGW07As4/PzNGkqbQC2y53LJkuG4eMg== X-Received: by 2002:a5d:40ce:: with SMTP id b14mr10292842wrq.350.1607637219899; Thu, 10 Dec 2020 13:53:39 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id s13sm10859535wrt.80.2020.12.10.13.53.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 13:53:39 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id D1426180070; Thu, 10 Dec 2020 22:53:38 +0100 (CET) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Jonathan Morton , Pete Heist Subject: [PATCH net-next v2] inet_ecn: Use csum16_add() helper for IP_ECN_set_* helpers Date: Thu, 10 Dec 2020 22:53:31 +0100 Message-Id: <20201210215331.141767-1-toke@redhat.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Jakub pointed out that the IP_ECN_set* helpers basically open-code csum16_add(), so let's switch them over to using the helper instead. v2: - Use __be16 for check_add stack variable in IP_ECN_set_ce() (kbot) Reported-by: Jakub Kicinski Tested-by: Jonathan Morton Tested-by: Pete Heist Signed-off-by: Toke Høiland-Jørgensen --- include/net/inet_ecn.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/include/net/inet_ecn.h b/include/net/inet_ecn.h index 563457fec557..d916a458aceb 100644 --- a/include/net/inet_ecn.h +++ b/include/net/inet_ecn.h @@ -8,6 +8,7 @@ #include #include +#include enum { INET_ECN_NOT_ECT = 0, @@ -75,8 +76,8 @@ static inline void INET_ECN_dontxmit(struct sock *sk) static inline int IP_ECN_set_ce(struct iphdr *iph) { - u32 check = (__force u32)iph->check; u32 ecn = (iph->tos + 1) & INET_ECN_MASK; + __be16 check_add; /* * After the last operation we have (in binary): @@ -93,23 +94,19 @@ static inline int IP_ECN_set_ce(struct iphdr *iph) * INET_ECN_ECT_1 => check += htons(0xFFFD) * INET_ECN_ECT_0 => check += htons(0xFFFE) */ - check += (__force u16)htons(0xFFFB) + (__force u16)htons(ecn); + check_add = htons(0xFFFB) + htons(ecn); - iph->check = (__force __sum16)(check + (check>=0xFFFF)); + iph->check = csum16_add(iph->check, check_add); iph->tos |= INET_ECN_CE; return 1; } static inline int IP_ECN_set_ect1(struct iphdr *iph) { - u32 check = (__force u32)iph->check; - if ((iph->tos & INET_ECN_MASK) != INET_ECN_ECT_0) return 0; - check += (__force u16)htons(0x1); - - iph->check = (__force __sum16)(check + (check>=0xFFFF)); + iph->check = csum16_add(iph->check, htons(0x1)); iph->tos ^= INET_ECN_MASK; return 1; }