From mboxrd@z Thu Jan 1 00:00:00 1970 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=-0.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS 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 2E538C43381 for ; Tue, 19 Feb 2019 18:30:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E8F232147C for ; Tue, 19 Feb 2019 18:30:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="e7pU/Gxr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727054AbfBSSaV (ORCPT ); Tue, 19 Feb 2019 13:30:21 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:43639 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726321AbfBSSaV (ORCPT ); Tue, 19 Feb 2019 13:30:21 -0500 Received: by mail-pl1-f195.google.com with SMTP id m10so1163101plt.10 for ; Tue, 19 Feb 2019 10:30:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=nO4Z29dufr6RCm0oGvCZwRo6QJwppuymZ5HaK97/piQ=; b=e7pU/GxrprvYZri9+B5zY/hbCR5TWHRHon9EMJ/bUSqEU+Et5oqO3ItIXUWCFMMqnf AEEHRwG4ge+9tNcvtnaJj3aPxmFlXmq9x3/RruSnZFa07mMlCgeO8iIY3DlgqtEDTSzV qcbYn3jUdQak1yQzz+If0hYxrPciIJe1Ecm1wCtPAwFWt6M6HHS/9EVEsUVUSjuqx9qe ClZqUl/2kGG43snHtblcKFZdRIrmlhekn5z/VYzboJUE3aHARBBFowWkuIQVCh7NIRE8 LR2YkzrGI00DYTAPt8oPQTver5bHj3N0NPUvIaD56EN5JTkAI6EHyu9+qAsfNp8P6gZY rVPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=nO4Z29dufr6RCm0oGvCZwRo6QJwppuymZ5HaK97/piQ=; b=sBEkHEz73pKZdCoX7iu4JPlkfxEogA/KXI7Uiz833sbxtdM9MQ+sPqRXwspMXl2tc6 3WJOw5zjUDisVB07GVIGlQd25dw+w/NTMOdfgMDSG5DTbtFWMKcwVNio2aamb3b03EI7 j5rZHCfbmElTt71eAZrRlGXc3dYG5f3x4efw6jowgduVKkDjEP10PddlA4VbqWgerUtB zNPKQZplCOYBKBNLraej++hkJg340AKtAYO27iMb7+v3m76YG/fC7KKkgzsgK8H/cqkj ilqfZDqn0Z/GLbqagUHDgnCOIiMOls1os3Ee4dlc+PC6U6K1Gsu6737ZyINKhTsqH7GM gY/Q== X-Gm-Message-State: AHQUAuZuitMxOV9FIquDHw8gAtu9c8EJEQE6C4pZ8zo/VzTKg9JOfD6J 6XicZ+ijFPf7vFVbvDEjVs/pXuLD X-Google-Smtp-Source: AHgI3IZs6pGcVaXUwFbFFvcy9Jb3N52Ny2u3ICkbdGPI2KVmXedM7bmSOIZRKuw/fAvo9MO5IkopmA== X-Received: by 2002:a17:902:758f:: with SMTP id j15mr5184593pll.66.1550601020820; Tue, 19 Feb 2019 10:30:20 -0800 (PST) Received: from ?IPv6:2620:15c:2c1:200:55c7:81e6:c7d8:94b? ([2620:15c:2c1:200:55c7:81e6:c7d8:94b]) by smtp.gmail.com with ESMTPSA id z6sm7780682pgo.31.2019.02.19.10.30.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 10:30:19 -0800 (PST) Subject: Re: [PATCH bpf-next 3/9] bpf: add bpf helper bpf_skb_set_ecn To: brakmo , netdev Cc: Martin Lau , Alexei Starovoitov References: <20190219053832.2086706-1-brakmo@fb.com> From: Eric Dumazet Message-ID: <318b6330-555f-224c-f4f5-5c635a78c99e@gmail.com> Date: Tue, 19 Feb 2019 10:30:19 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190219053832.2086706-1-brakmo@fb.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 02/18/2019 09:38 PM, brakmo wrote: > This patch adds a new bpf helper BPF_FUNC_skb_set_ecn > "int bpf_skb_set_Ecn(struct sk_buff *skb)". It is added to > BPF_PROG_TYPE_CGROUP_SKB typed bpf_prog which currently can > be attached to the ingress and egress path. This type of > bpf_prog cannot modify the skb directly. > > This helper is used to set the ECN bits (2) of the IPv6 or IPv4 > header in skb. It can be used by a bpf_prog to manage egress > network bandwdith limit per cgroupv2 by inducing an ECN > response in the TCP sender (when the packet is ECN enabled). > This works best when using DCTCP. > + > +BPF_CALL_2(bpf_skb_set_ecn, struct sk_buff *, skb, u32, val) > +{ > + struct ipv6hdr *ip6h = ipv6_hdr(skb); > + > + if ((val & ~0x3) != 0) > + return -EINVAL; > + > + if (ip6h->version == 6) { > + ip6h->flow_lbl[0] = (ip6h->flow_lbl[0] & ~0x30) | (val << 4); > + return 0; > + } else if (ip6h->version == 4) { > + struct iphdr *ip4h = (struct iphdr *)ip6h; > + > + ip4h->tos = (ip4h->tos & ~0x3) | val; Why is not the IPv4 checksum recomputed here ? If you leave this task to the caller, this should be documented. These hard coded constants are not really nice. Why not simply using INET_ECN_set_ce() which is IPv4/IPv6 ready ? Do you really need to set anything else than CE ?