Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4750099pxf; Tue, 30 Mar 2021 16:35:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcgU6lN2MD0FaR+1Ln/ZECD8k7CNMWb8X+hmE6L9sXRWwV+9tY5BRfFeMeLkytjvZ/080V X-Received: by 2002:a17:907:78d9:: with SMTP id kv25mr589100ejc.415.1617147321449; Tue, 30 Mar 2021 16:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617147321; cv=none; d=google.com; s=arc-20160816; b=KRwyHwjTGdJF/NsAD3VAWe67fItAX1Y1D7Ya6y+sv+lX58ksYj3EilArt2XCVTav8y MAiTu0S/ziGlde9Hpz/sNkUeTRoZMjh9kbwpsIyoJz0eh96xSIpzd8jpZAih9yXVdoSo mybJyqBbENX6vbdUDSKbWqbvgVGO6H7xilqcnHIHlE6HkqDnhdwyDELyH1F8CdQg8MMC Ksyzw/i6a9/yOvPDsvYiRIEwlkpUYPplrJCKqHuLa2CQ9TpuQzT68zjmr1YEkDQNpF9Q vOQbAQXbQ3EFysDdhe5xRVc3ibAsaTQcCoNRjdFmGdtv+7Fx68X7/6NSTojTex6v9Xpe Nfdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=q86N4Ipee4cOuOSoKuuXES9jQCxRaJsXucpi8+zhcjo=; b=ohtMx0JXitGaIzEm08f55zd90GYxHDCaMLTdEiDQnFJ1JZNlSdvwvBqBfoRkKO8qO8 M2EBjBJJX2IBWiLDxgmOMt3vf8iMeLq00OWJfrwPnUAmysin+4kpMpEIrbMbM4cS85T7 wjIPpEuG72f7ic+DqC6oU9TWleh8Bu189KHA+CDdK+D8j7EqGo9PVhZRhxtTyXcRHUUg 0vb47Um2Ernd0NNdFV1ejs8WDzWaASka4pSCgA/ugVySqx3gTUvWhA4oSMthqySFdfni 9SctXhxQnm56S1IvgsOI2SDmia1KqVf4IqAq/7128acEao8NQ+Z4DoFHBRWPsY2/Jvnl +LBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UqW8IjHc; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bm7si410091edb.188.2021.03.30.16.34.58; Tue, 30 Mar 2021 16:35:21 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UqW8IjHc; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232997AbhC3XbO (ORCPT + 99 others); Tue, 30 Mar 2021 19:31:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232900AbhC3Xaw (ORCPT ); Tue, 30 Mar 2021 19:30:52 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 991FEC061574; Tue, 30 Mar 2021 16:30:51 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id o10so26300228lfb.9; Tue, 30 Mar 2021 16:30:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=q86N4Ipee4cOuOSoKuuXES9jQCxRaJsXucpi8+zhcjo=; b=UqW8IjHcBTTLNRmgHR+MOJeglKm86mIssPm6cD9TIaSfxP3tdkcHPSA806Ouu2l3tc aK72v0JGn69nOQ6cFT1F/P0SaKdi3DzhcGp+fnXUgh3NAjmm4Fw2OisCR35jFdw4IsvM NSLMRwQgjftceRcbzHQ097DzPQcqflhDjzn4FyGQvmFo/NwANywgUJX3iePCMajaIUSY yLJ02Zy+sUz6tfWxIpXE5wLe+Y0uBUjEXlJgys0wAe1WpiKmL/cGaS84XXlS/AmgPeMZ IzJbwbl9hBbmvS7aBw5FlCcAc/gGT3lyRq5+QC/Q+c3CpijTdUu709l1ter0u1Hr3eoQ MOFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=q86N4Ipee4cOuOSoKuuXES9jQCxRaJsXucpi8+zhcjo=; b=WD4kihME6ZvL76JIBxfqp2LiB89L+BGxsIRk1C73ewfncFKjbLgX3QSynQ0prnWlr7 kCBAxq4Z75JXVfaI7B15gY2BHDQ+Nojx7QMZncF2otfnpLF2AE926sLGucO3904c3Su5 1dD5POGZQeXcFsP6u4CiCY8DCf6F+L22XRGSudu0XNmgJrxSrDOs4+9azIC+M8xOhtdx qNG47zJDOVMTExUijWci+PKO7pfzRtb2Ie3DlHW4KJHJV/4TzSq0wvtTFkPnxphgPciG SfX8o3+po/mXZuzoDRbhbgNszGa32avZOKgg8oLHvvpG1O6vdYkoedPR1vCelR70NiHU Qc3Q== X-Gm-Message-State: AOAM530APQTnlbhNfFAyXLO13uBrj8BpppzVKBlAPC8F+I03DUNFPUtB kKuokNPWUzVty8PqMeC2BDx7ir+MO7KwBjGCoS0= X-Received: by 2002:ac2:5ec2:: with SMTP id d2mr382924lfq.214.1617147049905; Tue, 30 Mar 2021 16:30:49 -0700 (PDT) MIME-Version: 1.0 References: <20210325120020.236504-1-memxor@gmail.com> <20210325120020.236504-4-memxor@gmail.com> <20210328080648.oorx2no2j6zslejk@apollo> <48b99ccc-8ef6-4ba9-00f9-d7e71ae4fb5d@iogearbox.net> In-Reply-To: <48b99ccc-8ef6-4ba9-00f9-d7e71ae4fb5d@iogearbox.net> From: Alexei Starovoitov Date: Tue, 30 Mar 2021 16:30:38 -0700 Message-ID: Subject: Re: [PATCH bpf-next 3/5] libbpf: add low level TC-BPF API To: Daniel Borkmann Cc: Andrii Nakryiko , Kumar Kartikeya Dwivedi , bpf , Jesper Dangaard Brouer , =?UTF-8?B?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2Vu?= , 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" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 30, 2021 at 2:26 PM Daniel Borkmann wrote: > > 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. +1 to support sched_cls in direct-action mode only.