Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4699032pxf; Tue, 30 Mar 2021 14:51:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxAsWfuXUJjF2So0Px/6bqFadS6eWM+kz05+7KaFtXH8GFMnbaTDXFatvgBnXc+ervXg2Y X-Received: by 2002:a17:906:a51:: with SMTP id x17mr218183ejf.25.1617141104985; Tue, 30 Mar 2021 14:51:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617141104; cv=none; d=google.com; s=arc-20160816; b=rSlk1LbQLy1ER21BcHRVK7cRPc2gLIF4VMBVFaOEX8hNszOoho+r/hfHBZ9q1DJO65 CXlkYXWQq0uQCu5EfOTrtkeWMSOY1GLJvcfokHCGisa8v/RCZAFtZH0dqeyuxiS+qv/G 874t9tbOnZguUB3yUEhywA+6ZRLNXUqhH4MnUxr1DNi59d73S2xFemnOnVZgotB4ZY20 X09imWHPqtb1AqISPsyz0SGxmLv0TaO3AvffO4KEHUeiI1KPAp9n49AUiaf3hoL2OGd4 cirJWRV8D/gmjvuajzzPe6eT8FhpL3BeZp3HOz6TIot4xrDbB0cfzZ6jcU8RGB1zrbJN S7Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=I2nB+h7pskMnjP1hlLE1GEwTNkMs1FenrL9DEQ+0Vro=; b=ObpwCKuxQB6gXX8AEj+RV5Svni0CotSHnEwq2MUq8QiZrl3dCgC3bcEuG5DD6rrvQ1 LopmeqEyGjIsO9R+BaE6St2QO+i4h9iD/aR51OrMN/Bf7xshtJ0N3kgH9J6YDs0nfvzS Ulb9g0+uo21EhGepIW9YN5NGYN5azCD1MwoxZ2ZApah+anIaz9/8OP41YPHXJ2qpwlDL 4AE+oyyASkmtzNGhCJNuVZgv0cB4FHwFg6lOC4uMKx6iw3ZWcnnlPtvxASAELf0Is1TN uYsXAViP/LSVVBQeAHdrpjXs+ZJtyITOz3It2qCKODP0HejAWXHJfNMW9StT2RWMPhym lnFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o13si89037ejb.114.2021.03.30.14.51.22; Tue, 30 Mar 2021 14:51:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232793AbhC3Vq5 (ORCPT + 99 others); Tue, 30 Mar 2021 17:46:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232838AbhC3Vq4 (ORCPT ); Tue, 30 Mar 2021 17:46:56 -0400 X-Greylist: delayed 1226 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 30 Mar 2021 14:46:56 PDT Received: from www62.your-server.de (www62.your-server.de [IPv6:2a01:4f8:d0a:276a::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DEE3C061574; Tue, 30 Mar 2021 14:46:56 -0700 (PDT) Received: from sslproxy02.your-server.de ([78.47.166.47]) by www62.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1lRLrw-000CEQ-PW; Tue, 30 Mar 2021 23:25:48 +0200 Received: from [85.7.101.30] (helo=pc-6.home) by sslproxy02.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lRLrw-000KZf-CJ; Tue, 30 Mar 2021 23:25:48 +0200 Subject: Re: [PATCH bpf-next 3/5] libbpf: add low level TC-BPF API To: Andrii Nakryiko , Kumar Kartikeya Dwivedi Cc: bpf , Jesper Dangaard Brouer , =?UTF-8?Q?Toke_H=c3=b8iland-J=c3=b8rgensen?= , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Shuah Khan , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , Peter Zijlstra , open list , Networking , "open list:KERNEL SELFTEST FRAMEWORK" References: <20210325120020.236504-1-memxor@gmail.com> <20210325120020.236504-4-memxor@gmail.com> <20210328080648.oorx2no2j6zslejk@apollo> From: Daniel Borkmann Message-ID: <48b99ccc-8ef6-4ba9-00f9-d7e71ae4fb5d@iogearbox.net> Date: Tue, 30 Mar 2021 23:25:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.102.4/26125/Tue Mar 30 13:11:47 2021) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/30/21 10:39 PM, Andrii Nakryiko wrote: > On Sun, Mar 28, 2021 at 1:11 AM Kumar Kartikeya Dwivedi > wrote: >> On Sun, Mar 28, 2021 at 10:12:40AM IST, Andrii Nakryiko wrote: >>> Is there some succinct but complete enough documentation/tutorial/etc >>> that I can reasonably read to understand kernel APIs provided by TC >>> (w.r.t. BPF, of course). I'm trying to wrap my head around this and >>> whether API makes sense or not. Please share links, if you have some. >> >> Hi Andrii, >> >> Unfortunately for the kernel API part, I couldn't find any when I was working >> on this. So I had to read the iproute2 tc code (tc_filter.c, f_bpf.c, >> m_action.c, m_bpf.c) and the kernel side bits (cls_api.c, cls_bpf.c, act_api.c, >> act_bpf.c) to grok anything I didn't understand. There's also similar code in >> libnl (lib/route/{act,cls}.c). >> >> Other than that, these resources were useful (perhaps you already went through >> some/all of them): >> >> https://docs.cilium.io/en/latest/bpf/#tc-traffic-control >> https://qmonnet.github.io/whirl-offload/2020/04/11/tc-bpf-direct-action/ >> tc(8), and tc-bpf(8) man pages >> >> I hope this is helpful! > > Thanks! I'll take a look. Sorry, I'm a bit behind with all the stuff, > trying to catch up. > > I was just wondering if it would be more natural instead of having > _dev _block variants and having to specify __u32 ifindex, __u32 > parent_id, __u32 protocol, to have some struct specifying TC > "destination"? Maybe not, but I thought I'd bring this up early. So > you'd have just bpf_tc_cls_attach(), and you'd so something like > > bpf_tc_cls_attach(prog_fd, TC_DEV(ifindex, parent_id, protocol)) > > or > > bpf_tc_cls_attach(prog_fd, TC_BLOCK(block_idx, protocol)) > > ? Or it's taking it too far? > > But even if not, I think detaching can be unified between _dev and > _block, can't it? Do we even need the _block variant? I would rather prefer to take the chance and make it as simple as possible, and only iff really needed extend with other APIs, for example: bpf_tc_attach(prog_fd, ifindex, {INGRESS,EGRESS}); Internally, this will create the sch_clsact qdisc & cls_bpf filter instance iff not present yet, and attach to a default prio 1 handle 1, and _always_ in direct-action mode. This is /as simple as it gets/ and we don't need to bother users with more complex tc/cls_bpf internals unless desired. For example, extended APIs could add prio/parent so that multi-prog can be attached to a single cls_bpf instance, but even that could be a second step, imho. Thanks, Daniel