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=-5.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 C7D93C433E0 for ; Wed, 31 Mar 2021 09:52:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9717B619BC for ; Wed, 31 Mar 2021 09:52:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234375AbhCaJwL (ORCPT ); Wed, 31 Mar 2021 05:52:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52155 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234790AbhCaJvu (ORCPT ); Wed, 31 Mar 2021 05:51:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617184310; 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: in-reply-to:in-reply-to:references:references; bh=gSVEMu/gb4JEhF05TMYdAdHmEbbEjzD0QedOu+4cT4M=; b=iq4imOGbJkT/ZJ4ecr7xH9/z4je/W83CfNMXwBfR87oUT5Z3zE7MTPWnEFGmUaToi0ti52 qoiZZ8xIaLkTnVbYmSHB+nN9EoIjayRwc+j1buB3G2iOkfSz9qtOg+yZgpLQG4cYTnTfZj gqHhtW7Rff43Q2oOefGYu9/bl9Ea2wU= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-174-y3kd65b0Mi6pRj-cKc1Q4g-1; Wed, 31 Mar 2021 05:51:48 -0400 X-MC-Unique: y3kd65b0Mi6pRj-cKc1Q4g-1 Received: by mail-ed1-f71.google.com with SMTP id bm8so830428edb.4 for ; Wed, 31 Mar 2021 02:51:48 -0700 (PDT) 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:in-reply-to:references:date :message-id:mime-version; bh=gSVEMu/gb4JEhF05TMYdAdHmEbbEjzD0QedOu+4cT4M=; b=LZKwD2T4fujZ9M5eqjoVWYO1wLknnoI/g01hRJmKJrsw8yEY1EMJ05kMQKXTJxoSoI XFnAZXz8ZNvpjPWu/ORjM4kd7rjdnK9GekV4uhFpBXNpI9sz5eC1nFha5xsWWblRWPRB c/kJgGultoU3GwmyYhilfezYUETRrYdaQKkq+IM5Q2BmzbJLndlyZ9wZE8Ik87ANdqIS PxuhgYPiqIpebJF1PA+j7tmNZ0agVWvv4BLhp8ghpqW3WPMrDYq+nWiASXap54D9C3aM jzE8ena+hwUoa+QXlihvFkMMdPCB4pwBODslNeRZykwUrnjCUl1/h31fiyJGxqSzMj3A +lag== X-Gm-Message-State: AOAM531HNAUCDTuzUgKpnftNwGmfLEOaOlEb5EX10KWVBQLTayoJXEUf JWKOH10eobeoSlh9rNpapC2U8XcQ4mhSfiPPKU1xu+UWPYVQLI5D21eEzf0mAfHT3hTQPV+8oAX 4sEzp5p0y50F4 X-Received: by 2002:aa7:d954:: with SMTP id l20mr2610475eds.1.1617184306908; Wed, 31 Mar 2021 02:51:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzylwo4hPWcYcmlE62zpzxVfApqIEMleAceptnhOdFIA9MPn6oGC4nNnvquLFXWM5B7Cncu4w== X-Received: by 2002:aa7:d954:: with SMTP id l20mr2610446eds.1.1617184306509; Wed, 31 Mar 2021 02:51:46 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id h17sm1123457eds.26.2021.03.31.02.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Mar 2021 02:51:46 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 5FCE6181B24; Wed, 31 Mar 2021 11:51:45 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Daniel Borkmann , Andrii Nakryiko , Kumar Kartikeya Dwivedi Cc: bpf , Jesper Dangaard Brouer , 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" Subject: Re: [PATCH bpf-next 3/5] libbpf: add low level TC-BPF API In-Reply-To: <48b99ccc-8ef6-4ba9-00f9-d7e71ae4fb5d@iogearbox.net> References: <20210325120020.236504-1-memxor@gmail.com> <20210325120020.236504-4-memxor@gmail.com> <20210328080648.oorx2no2j6zslejk@apollo> <48b99ccc-8ef6-4ba9-00f9-d7e71ae4fb5d@iogearbox.net> X-Clacks-Overhead: GNU Terry Pratchett Date: Wed, 31 Mar 2021 11:51:45 +0200 Message-ID: <878s63r6q6.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Daniel Borkmann writes: > 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. While I'm all for simplifying where possible, the question becomes at what level? I.e., we initially figured we'd expose (most of) the netlink API in the low-level API (patch 3 in the series) and then have the bpf_program__* level API be the simple "just attach" one... We could simplify the low-level one further, of course, for instance by getting rid of the block stuff entirely, but I don't see much value in leaving out the support for prio/parent in the bpf_tc_cls_* - we'd have to make the API extensible so it could be added later anyway, so why not just include it from the get-go (especially as Kumar has already written the code?) -Toke