Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4681002pxf; Tue, 30 Mar 2021 14:14:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7F2FZBMXLrQmpt/Hs56YLqD5OxcF+JdbcHTSf8v1YieOP0leA+G5jnRsK28+SCh20n6nk X-Received: by 2002:a17:906:4055:: with SMTP id y21mr42903ejj.507.1617138849094; Tue, 30 Mar 2021 14:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617138849; cv=none; d=google.com; s=arc-20160816; b=oRcb6JmbSeXcwSVljiH5/j6BYZw6EyCsl5kD02PuNCNZbFzHOyy0oHK0lXCzppL9CM mpc2muaCyn9MnD4OVIIktPuqygnLoKbgoc5vuFWNswnbe+KrMj3onJ1mO2okqBa2rXTK yEhdwTI/SdkFDgIVALmvFqzkZZrqVJo1CAM1s5/N3rumRjlE2gvLhZDW4dRjVtjoWUOc lqytu06JPFWrV7NTeHKs4/xVftAiNAP+AvHCxdfFv8Q/v7au2CwB/cqqKT8XCrOUhP52 shOXJUZOxqDmDKkXjV7bMM9A25Fp1THBiTAwnAq6D6S4s+teJEgf0imZnchN7G7aEFna 7aBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=+d8bP069q3cX6KDAKElLY3IDtJwqKEIFpPeGaA7ygUI=; b=TvF8hxSjmS2Rue1VMiDJSYmI4Kfm7Alw6DCTGJtD5yxpCcXkJgyMkKbNuccUcogOO4 X9bMhMugjA0/KEqovF1Zx2372FEueUVh+klcPPmQseGHTbTIzY4APQ588AG1m9X22kHs CuK5s3dwpkX230XSzH/UKk1jbOgkhPjleOjVdf9d2+1FwPaNZvN7Xt+qkjqG5s8mRim0 c//U8wXfSkWB7azMYTYt2vp3pT14+7UELhfFBWB30TmtMKaQsXpMp6TW1FgkPwS9yqjr Fhy6Q7bVDbZTA2fZ4QAnoOuwnZvLPNRXrcJ1+dZ2V+VRhNHbjGzL6XF9iD8st20ChZkA gYaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ub2Qeqst; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h13si107762edt.586.2021.03.30.14.13.47; Tue, 30 Mar 2021 14:14:09 -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=@redhat.com header.s=mimecast20190719 header.b=Ub2Qeqst; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232606AbhC3VMK (ORCPT + 99 others); Tue, 30 Mar 2021 17:12:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26614 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232558AbhC3VLq (ORCPT ); Tue, 30 Mar 2021 17:11:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617138705; 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=+d8bP069q3cX6KDAKElLY3IDtJwqKEIFpPeGaA7ygUI=; b=Ub2QeqstTBgkHHb4YB71HZcPDcD1D8OBIHluROJwc0lTKlTT54iTTw6gcKuX7hBUKLwSis zmbbnOu+4CaddyRyR4gXbBXeOJQxLp4128tfsZbSBwyUzKnQdcpSYyB3kol2UWZxsD3SIp SzHw2sWv5u5LkjrjCNOqBKPmxPOkFa8= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-584-mR0uPigVPKG_wHar2ONrCQ-1; Tue, 30 Mar 2021 17:11:43 -0400 X-MC-Unique: mR0uPigVPKG_wHar2ONrCQ-1 Received: by mail-ej1-f70.google.com with SMTP id a22so7649749ejx.10 for ; Tue, 30 Mar 2021 14:11:42 -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=+d8bP069q3cX6KDAKElLY3IDtJwqKEIFpPeGaA7ygUI=; b=ZDBRiwB7KXkT5Hm7oXTM0lOP2GM/+ENOcK2JTMjgFFWiyTez5nYzSvRKKuGU0CkjZs Iyynv2BX3LqMqutqMvYi0l8yVctkMsElUootLy0cqv3LDmAdKoENXOm1ypdkSiHf8zgi HmSFclcsCD2w8QDlMr8MTdDQthjDnKo7DIirpSUP5mQb5d3EvKebveSDpcNN4xS/9Dv8 hXJ6aTvOiLjq7I+HQdAZbyzuJRdQCGc6gQQ8KMVWFA1CQwFF1X7RJbDrzdiMBqhnYhl7 ZYYhaT0PWMFcEZ2XeduehID8b0QIDQmHKegERuVSQDHOiu3qZx2k5vmItexdyAtCzuGh eQGA== X-Gm-Message-State: AOAM530GwZW6ZDejaR+vE/uSPczLII44/S3YWWK8+Omy1Nq15pweAvXv c6acsQk3ZeSCs3rHeGD9onDSCHv+ixd60J7Q3kwOp7TDx/KcJcpmXJbVy2a6ql+SxSAlXUSjsC0 fvzx0iwqKIDF38ENmLuK9eeD5 X-Received: by 2002:aa7:dd99:: with SMTP id g25mr35237435edv.230.1617138701930; Tue, 30 Mar 2021 14:11:41 -0700 (PDT) X-Received: by 2002:aa7:dd99:: with SMTP id g25mr35237420edv.230.1617138701731; Tue, 30 Mar 2021 14:11:41 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id r25sm129891edv.78.2021.03.30.14.11.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Mar 2021 14:11:41 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 8EB42180292; Tue, 30 Mar 2021 23:11:40 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Andrii Nakryiko , Kumar Kartikeya Dwivedi Cc: bpf , Jesper Dangaard Brouer , Alexei Starovoitov , Daniel Borkmann , 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: References: <20210325120020.236504-1-memxor@gmail.com> <20210325120020.236504-4-memxor@gmail.com> <20210328080648.oorx2no2j6zslejk@apollo> X-Clacks-Overhead: GNU Terry Pratchett Date: Tue, 30 Mar 2021 23:11:40 +0200 Message-ID: <87czvgqrcj.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Andrii Nakryiko writes: > 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? Hmm, that's not a bad idea, actually. An earlier version of the series did have only a single set of functions, but with way too many arguments, which is why we ended up agreeing to split them. But encapsulating the destination in a separate struct and combining it with some helper macros might just make this work! I like it! Kumar, WDYT? -Toke