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=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED 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 30D70C43381 for ; Sat, 23 Feb 2019 01:14:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0591C2070D for ; Sat, 23 Feb 2019 01:14:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727007AbfBWBO3 (ORCPT ); Fri, 22 Feb 2019 20:14:29 -0500 Received: from www62.your-server.de ([213.133.104.62]:38222 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbfBWBO3 (ORCPT ); Fri, 22 Feb 2019 20:14:29 -0500 Received: from [78.46.172.3] (helo=sslproxy06.your-server.de) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1gxLtb-0005l4-91; Sat, 23 Feb 2019 02:14:27 +0100 Received: from [178.197.248.36] (helo=linux.home) by sslproxy06.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1gxLtb-000XFF-3W; Sat, 23 Feb 2019 02:14:27 +0100 Subject: Re: [PATCH v2 bpf-next 4/9] bpf: add bpf helper bpf_skb_ecn_set_ce To: brakmo , netdev Cc: Martin Lau , Alexei Starovoitov , Eric Dumazet , Kernel Team References: <20190223010703.678070-1-brakmo@fb.com> <20190223010703.678070-5-brakmo@fb.com> From: Daniel Borkmann Message-ID: Date: Sat, 23 Feb 2019 02:14:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20190223010703.678070-5-brakmo@fb.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.2/25368/Fri Feb 22 11:32:58 2019) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 02/23/2019 02:06 AM, brakmo wrote: > This patch adds a new bpf helper BPF_FUNC_skb_ecn_set_ce > "int bpf_skb_ecn_set_ce(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. The helper is needed > because his type of bpf_prog cannot modify the skb directly. > > This helper is used to set the ECN field of ECN capable IP packets to ce > (congestion encountered) in the IPv6 or IPv4 header of the skb. It can be > used by a bpf_prog to manage egress or ingress network bandwdith limit > per cgroupv2 by inducing an ECN response in the TCP sender. > This works best when using DCTCP. > > Signed-off-by: Lawrence Brakmo > --- > include/uapi/linux/bpf.h | 10 +++++++++- > net/core/filter.c | 14 ++++++++++++++ > 2 files changed, 23 insertions(+), 1 deletion(-) > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > index 95b5058fa945..fc646f3eaf9b 100644 > --- a/include/uapi/linux/bpf.h > +++ b/include/uapi/linux/bpf.h > @@ -2365,6 +2365,13 @@ union bpf_attr { > * Make a tcp_sock enter CWR state. > * Return > * 0 on success, or a negative error in case of failure. > + * > + * int bpf_skb_ecn_set_ce(struct sk_buf *skb) > + * Description > + * Sets ECN of IP header to ce (congestion encountered) if > + * current value is ect (ECN capable). Works with IPv6 and IPv4. > + * Return > + * 1 if set, 0 if not set. > */ > #define __BPF_FUNC_MAPPER(FN) \ > FN(unspec), \ > @@ -2464,7 +2471,8 @@ union bpf_attr { > FN(spin_unlock), \ > FN(sk_fullsock), \ > FN(tcp_sock), \ > - FN(tcp_enter_cwr), > + FN(tcp_enter_cwr), \ > + FN(skb_ecn_set_ce), > > /* integer value in 'imm' field of BPF_CALL instruction selects which helper > * function eBPF program intends to call > diff --git a/net/core/filter.c b/net/core/filter.c > index ca57ef25279c..955369c6ed30 100644 > --- a/net/core/filter.c > +++ b/net/core/filter.c > @@ -5444,6 +5444,18 @@ static const struct bpf_func_proto bpf_tcp_enter_cwr_proto = { > .ret_type = RET_INTEGER, > .arg1_type = ARG_PTR_TO_TCP_SOCK, > }; > + > +BPF_CALL_1(bpf_skb_ecn_set_ce, struct sk_buff *, skb) > +{ > + return INET_ECN_set_ce(skb); Hm, but as mentioned last time, don't we have to ensure here that skb is writable (aka skb->data private to us before writing into it)? > +} > + > +static const struct bpf_func_proto bpf_skb_ecn_set_ce_proto = { > + .func = bpf_skb_ecn_set_ce, > + .gpl_only = false, > + .ret_type = RET_INTEGER, > + .arg1_type = ARG_PTR_TO_CTX, > +}; > #endif /* CONFIG_INET */ > > bool bpf_helper_changes_pkt_data(void *func) > @@ -5610,6 +5622,8 @@ cg_skb_func_proto(enum bpf_func_id func_id, struct bpf_prog *prog) > } else { > return NULL; > } > + case BPF_FUNC_skb_ecn_set_ce: > + return &bpf_skb_ecn_set_ce_proto; > #endif > default: > return sk_filter_func_proto(func_id, prog); > Thanks, Daniel