From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: "Cristian Morales Vega (cmorve)" <cmorve@cisco.com>,
"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Subject: Re: [QUESTION] BPF_SK_SKB_STREAM_PARSER cannot observe strparser orig_offset?
Date: Tue, 12 May 2026 10:05:14 +0800 [thread overview]
Message-ID: <e6c1463a-c2de-4cf6-8036-d38a945f9363@linux.dev> (raw)
In-Reply-To: <SA1PR11MB6848CE0D74476DA27BCA6091C0382@SA1PR11MB6848.namprd11.prod.outlook.com>
On 5/12/26 12:18 AM, Cristian Morales Vega (cmorve) wrote:
>>> On 5/11/26 10:49 PM, Cristian Morales Vega (cmorve) wrote:
>>> I am trying to use BPF_SK_SKB_STREAM_VERDICT in an old kernel (I don't have control over the version), so I need to also use BPF_SK_SKB_STREAM_PARSER. I though to just do "return skb->len;" in it, as a no-op, since I don't really have an use for the parser.
>> Since v5.18 BPF_SK_SKB_STREAM_VERDICT can be used without
>> BPF_SK_SKB_STREAM_PARSER.
>>
>> Which kernel version you use now?
> I think it's since 5.10? But I have to make it run on a big range of kernel versions, right now I'm looking at a 5.4.213 system.
>
>
>>> So far so good. But I can see that, from time to time, __strp_recv() receives a non-zero orig_offset as "first skb" (i.e. strp->skb_head is null). In such a case, I should not be returning skb->len but "skb->len - orig_offset" (i.e. orig_len), right? Otherwise I would enter
>>>
>>> extra = (ssize_t)(stm->accum_len + cand_len) -
>>> stm->strp.full_len;
>>>
>>> if (extra < 0) {
>>> /* Message not complete yet. */
>>>
>>> But AFAICT BPF_SK_SKB_STREAM_PARSER doesn't have access to that offset. It seems it had it until e0dc3b93bd7bcff8c3813d1df43e0908499c7cf0 (which was backported), but not any more?
>>>
>> Is my understanding correct? If not, what am I missing? And, if yes, there is any solution?
>>
>>
>> If you just return skb->len only in your parser , the 'issue' should not
>> happen.
> But if the parser returns skb->len, even in a modern system (in theory, I'm struggling to reproduce getting orig_offset != 0 in any system I can properly debug). Let's say orig_skb->len is 1500, orig_offset 1000 and orig_len 500.
I think non-zero orig_offset only happens when __tcp_read_sock
is mid-skb and recv_actor returns an error after consuming part
of the data -- next call comes back with orig_offset != 0.
> - cand_len will be set to 500 here ->https://github.com/torvalds/linux/blob/master/net/strparser/strparser.c#L186
> - len will be set to 1500 here -> https://github.com/torvalds/linux/blob/master/net/strparser/strparser.c#L221
> - stm->strp.full_len will be set to 1500 here -> https://github.com/torvalds/linux/blob/master/net/strparser/strparser.c#L258
> - extra will be set to 0 + 500 - 1500 = -1000 here -> https://github.com/torvalds/linux/blob/master/net/strparser/strparser.c#L261
>
> So it will enter "/* Message not complete yet. */" inside "if (extra < 0)", no?
To your earlier point: yes, what you really want is the skb
offset, especially for protocol framing. That scenario is real
and can be worked around using a map to carry state across
parser invocations.
But none of this fires as long as your parser keeps returning
skb->len.
prev parent reply other threads:[~2026-05-12 2:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 14:49 [QUESTION] BPF_SK_SKB_STREAM_PARSER cannot observe strparser orig_offset? Cristian Morales Vega (cmorve)
2026-05-11 15:53 ` Jiayuan Chen
2026-05-11 16:18 ` Cristian Morales Vega (cmorve)
2026-05-12 2:05 ` Jiayuan Chen [this message]
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=e6c1463a-c2de-4cf6-8036-d38a945f9363@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=bpf@vger.kernel.org \
--cc=cmorve@cisco.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox