From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Christian Deacon <gamemann@gflclan.com>, xdp-newbies@vger.kernel.org
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Subject: Re: XDP Software Issue - Payload Matching
Date: Wed, 13 May 2020 16:42:25 +0200 [thread overview]
Message-ID: <874ksjuca6.fsf@toke.dk> (raw)
In-Reply-To: <edbf300d-a687-7652-d702-d58be09fd541@gflclan.com>
Christian Deacon <gamemann@gflclan.com> writes:
> Hey Toke,
>
> Thank you for your response!
>
> Unfortunately, I still haven't been able to get the for loop to work
> properly. I've also noticed if I use `iph->ihl * 4` when initializing
> the `byte` pointer, it produces the following error:
>
> ```
> R5 !read_ok
> processed 732 insns (limit 1000000) max_states_per_insn 4 total_states
> 16 peak_states 16 mark_read 10
> ```
>
> It seems I need to use a static size such as `sizeof(struct iphdr)`.
> Though, not all packets would have an IP header length of 20 bytes. I've
> tried performing checks with the length as well:
>
> ```
> uint8_t len = iph->ihl * 4;
>
> if (len < 20)
> {
> return XDP_DROP;
> }
> else if (len > 36)
> {
> return XDP_DROP;
> }
>
> // Setting len to 20 or any other value works fine.
> // len = 20;
>
> uint8_t *byte = data + sizeof(struct ethhdr) + len + l4headerLen;
> ```
>
> However, no luck. I'm not sure what I can do to make BPF believe this is
> safe.
Hmm, maybe have a look at Jesper's experiments with getting to the end
of the packet:
https://github.com/xdp-project/xdp-tutorial/pull/123
https://github.com/xdp-project/xdp-tutorial/pull/124
Not sure if he ended up concluding anything definite about what the best
technique is :)
> I was also wondering about the following:
>
> > Use a matching algorithm that doesn't require looping through the
> packet byte-by-byte as you're doing now. For instance, you could have a
> hash map that uses the payload you're trying to match as the key with an
> appropriate chunk size.
>
> Do you know of any BPF Helper/kernel functions that can hash the
> payload? I looked at the BPF Helpers function list, but wasn't able to
> find anything for XDP sadly. I would like to attempt to implement
> something like this to see if I can avoid for loops since they aren't
> working well with BPF from what I've seen.
No, there's no direct hashing helper for XDP. I just meant that you
could use the (chunk of) the payload directly as a key in a hashmap.
Something like:
struct hash_key {
u8 payload[CHUNK_SIZE];
}
int xdp_main(ctx) {
struct hash_key lookup_key = {};
int *verdict;
[...]
memcpy(&lookup_key, ctx->data, CHUNK_SIZE);
verdict = bpf_map_lookup_elem(&lookup_key, ...);
if (verdict)
do_something_with(*verdict);
}
(You'd still need to convince the verifier that the memcpy from packet
data is safe, of course).
-Toke
next prev parent reply other threads:[~2020-05-13 14:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-08 13:57 XDP Software Issue - Payload Matching Christian Deacon
2020-05-11 10:41 ` Toke Høiland-Jørgensen
2020-05-11 18:40 ` Christian Deacon
2020-05-12 14:28 ` Toke Høiland-Jørgensen
2020-05-13 13:25 ` Christian Deacon
2020-05-13 14:42 ` Toke Høiland-Jørgensen [this message]
2020-05-22 14:49 ` Christian Deacon
2020-05-22 15:12 ` Toke Høiland-Jørgensen
2020-07-14 15:58 ` Christian Deacon
2020-07-14 20:48 ` Toke Høiland-Jørgensen
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=874ksjuca6.fsf@toke.dk \
--to=toke@redhat.com \
--cc=brouer@redhat.com \
--cc=gamemann@gflclan.com \
--cc=xdp-newbies@vger.kernel.org \
/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.