All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org, pablo@netfilter.org, kadlec@netfilter.org,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, netfilter-devel@vger.kernel.org,
	netdev@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
	martin.lau@linux.dev, eddyz87@gmail.com,
	lorenzo.bianconi@redhat.com, toke@redhat.com, fw@strlen.de,
	hawk@kernel.org, horms@kernel.org, donhunte@redhat.com,
	memxor@gmail.com
Subject: Re: [PATCH v5 bpf-next 2/3] netfilter: add bpf_xdp_flow_lookup kfunc
Date: Sat, 29 Jun 2024 21:57:53 +0200	[thread overview]
Message-ID: <ZoBnQZPfyCuyn1tG@lore-desk> (raw)
In-Reply-To: <48b18dc0-19bd-441e-5054-4bd545cd1561@iogearbox.net>

[-- Attachment #1: Type: text/plain, Size: 2663 bytes --]

> On 6/14/24 5:40 PM, Lorenzo Bianconi wrote:
> [...]
> > +enum {
> > +	NF_BPF_FLOWTABLE_OPTS_SZ = 4,
> > +};
> > +
> > +__diag_push();
> > +__diag_ignore_all("-Wmissing-prototypes",
> > +		  "Global functions as their definitions will be in nf_flow_table BTF");
> 
> nit: __bpf_kfunc_start_defs();

ack, I will fix it in v6.

> 
> > +static struct flow_offload_tuple_rhash *
> > +bpf_xdp_flow_tuple_lookup(struct net_device *dev,
> > +			  struct flow_offload_tuple *tuple, __be16 proto)
> > +{
> > +	struct flow_offload_tuple_rhash *tuplehash;
> > +	struct nf_flowtable *nf_flow_table;
> > +	struct flow_offload *nf_flow;
> > +
> > +	nf_flow_table = nf_flowtable_by_dev(dev);
> > +	if (!nf_flow_table)
> > +		return ERR_PTR(-ENOENT);
> > +
> > +	tuplehash = flow_offload_lookup(nf_flow_table, tuple);
> > +	if (!tuplehash)
> > +		return ERR_PTR(-ENOENT);
> > +
> > +	nf_flow = container_of(tuplehash, struct flow_offload,
> > +			       tuplehash[tuplehash->tuple.dir]);
> > +	flow_offload_refresh(nf_flow_table, nf_flow, false);
> > +
> > +	return tuplehash;
> > +}
> > +
> > +__bpf_kfunc struct flow_offload_tuple_rhash *
> > +bpf_xdp_flow_lookup(struct xdp_md *ctx, struct bpf_fib_lookup *fib_tuple,
> > +		    struct bpf_flowtable_opts *opts, u32 opts_len)
> > +{
> > +	struct xdp_buff *xdp = (struct xdp_buff *)ctx;
> > +	struct flow_offload_tuple tuple = {
> > +		.iifidx = fib_tuple->ifindex,
> > +		.l3proto = fib_tuple->family,
> > +		.l4proto = fib_tuple->l4_protocol,
> > +		.src_port = fib_tuple->sport,
> > +		.dst_port = fib_tuple->dport,
> > +	};
> > +	struct flow_offload_tuple_rhash *tuplehash;
> > +	__be16 proto;
> > +
> > +	if (opts_len != NF_BPF_FLOWTABLE_OPTS_SZ) {
> > +		opts->error = -EINVAL;
> > +		return NULL;
> > +	}
> > +
> > +	switch (fib_tuple->family) {
> > +	case AF_INET:
> > +		tuple.src_v4.s_addr = fib_tuple->ipv4_src;
> > +		tuple.dst_v4.s_addr = fib_tuple->ipv4_dst;
> > +		proto = htons(ETH_P_IP);
> > +		break;
> > +	case AF_INET6:
> > +		tuple.src_v6 = *(struct in6_addr *)&fib_tuple->ipv6_src;
> > +		tuple.dst_v6 = *(struct in6_addr *)&fib_tuple->ipv6_dst;
> > +		proto = htons(ETH_P_IPV6);
> > +		break;
> > +	default:
> > +		opts->error = -EAFNOSUPPORT;
> > +		return NULL;
> > +	}
> > +
> > +	tuplehash = bpf_xdp_flow_tuple_lookup(xdp->rxq->dev, &tuple, proto);
> > +	if (IS_ERR(tuplehash)) {
> > +		opts->error = PTR_ERR(tuplehash);
> > +		return NULL;
> > +	}
> > +
> > +	return tuplehash;
> > +}
> > +
> > +__diag_pop()
> 
> __bpf_kfunc_end_defs();

ack, I will fix it in v6.

Regards,
Lorenzo

> 
> Otherwise LGTM!

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2024-06-29 19:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-14 15:40 [PATCH v5 bpf-next 0/3] netfilter: Add the capability to offload flowtable in XDP layer Lorenzo Bianconi
2024-06-14 15:40 ` [PATCH v5 bpf-next 1/3] netfilter: nf_tables: add flowtable map for xdp offload Lorenzo Bianconi
2024-06-28 21:19   ` Daniel Borkmann
2024-06-29 22:06     ` Lorenzo Bianconi
2024-06-14 15:40 ` [PATCH v5 bpf-next 2/3] netfilter: add bpf_xdp_flow_lookup kfunc Lorenzo Bianconi
2024-06-28 21:21   ` Daniel Borkmann
2024-06-29 19:57     ` Lorenzo Bianconi [this message]
2024-06-14 15:40 ` [PATCH v5 bpf-next 3/3] selftests/bpf: Add selftest for " Lorenzo Bianconi
2024-06-28 21:29   ` Daniel Borkmann
2024-06-29 20:11     ` Lorenzo Bianconi
2024-07-01  8:07       ` Daniel Borkmann
2024-06-28 19:56 ` [PATCH v5 bpf-next 0/3] netfilter: Add the capability to offload flowtable in XDP layer Lorenzo Bianconi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZoBnQZPfyCuyn1tG@lore-desk \
    --to=lorenzo@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=donhunte@redhat.com \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=kadlec@netfilter.org \
    --cc=kuba@kernel.org \
    --cc=lorenzo.bianconi@redhat.com \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=toke@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.