Re: Parsing TCP Header Options In XDP/BPF

Toke Høiland-Jørgensen <[email protected]>
Newsgroups org.kernel.vger.xdp-newbies
Message-ID <[email protected]>
Christian Deacon <[email protected]> writes:

> Hey and I apologize for the late reply!
>
>
> On 9/15/2021 11:19 PM, Rob Sherwood wrote:
>  > Definitely not an expert but no one has replied so I'll throw out my 
> guess :-)
>  >
>  > Check out https://lwn.net/Articles/794934/ for more info on 'bounded 
> loops', but my guess is that the verifier doesn't have enough context to 
> verify your loop is really bounded.
>  >
>  > One trick might be to convert your while loop to a for(;;) loop, 
> e.g., instead of :
>  >
>  > 
> https://github.com/gamemann/XDP-TCP-Header-Options/blob/master/src/xdp_prog.c#L81
>  > while ( optdata < 40) {... }
>  >
>  > you could try:
>  >
>  > for (optdata = 0; optdata < 40; optdata ++) { ... }
>  >
>  > I know from past attempts that just because it's obvious to humans 
> that there's not an infinite loop, it's not always obvious to the verifier.
>  >
>  > Hope that helps (and is correct!),
>  >
>  > - Rob
>  > .
>
> I did try a for loop before, but still ran into the same BPF verifier 
> error :( I tried adding checks to prevent an infinite loop along with 
> checks to make sure it doesn't go outside of ctx->data_end or below 
> ctx->data, but no change. Thank you!
>
> On 9/16/2021 5:32 AM, Toke Høiland-Jørgensen wrote:
>  > Christian Deacon <[email protected]> writes:
>  >
>  >> Hi everyone,
>  >>
>  >>
>  >> I wasn't sure whether to submit this under XDP's mailing list or BPF's.
>  >> However, since it's an XDP program, I figured I'd start here. The issue
>  >> has to do with the BPF verifier, though.
>  >>
>  >>
>  >> I am trying to parse TCP header options within XDP/BPF. In my case, I
>  >> want to locate the 'timestamps' option and read/write to the sender and
>  >> receive timestamps (the option's data, which is eight bytes in total I
>  >> believe).
>  >
>  > We're doing just this in the 'pping' utility, see code here:
>  > 
> https://github.com/xdp-project/bpf-examples/blob/master/pping/pping_kern.c#L83
>  >
>  > -Toke
>
> This code works great for me so far! Thank you!

Awesome! You're welcome :)

-Toke
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.