[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <77a5dbd2-7792-486c-b161-76e2262b67a7@linux.dev>
Date: Tue, 13 Aug 2024 18:15:54 -0700
From: Martin KaFai Lau <martin.lau@...ux.dev>
To: Asbjørn Sloth Tønnesen <ast@...erby.net>,
Toke Høiland-Jørgensen <toke@...nel.org>
Cc: bpf@...r.kernel.org, Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>, Andrii Nakryiko <andrii@...nel.org>,
Eduard Zingerman <eddyz87@...il.com>, Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>, KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>, Mykola Lysenko <mykolal@...com>,
Shuah Khan <shuah@...nel.org>, Tushar Vyavahare
<tushar.vyavahare@...el.com>, Magnus Karlsson <magnus.karlsson@...el.com>,
Willem de Bruijn <willemb@...gle.com>, netdev@...r.kernel.org,
linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH bpf-next] selftests/bpf: Avoid subtraction after htons()
in ipip tests
On 8/8/24 2:24 AM, Toke Høiland-Jørgensen wrote:
> Asbjørn Sloth Tønnesen <ast@...erby.net> writes:
>
>> On little-endian systems, doing subtraction after htons()
>> leads to interesting results:
>>
>> Given:
>> MAGIC_BYTES = 123 = 0x007B aka. in big endian: 0x7B00 = 31488
>> sizeof(struct iphdr) = 20
>>
>> Before this patch:
>> __bpf_constant_htons(MAGIC_BYTES) - sizeof(struct iphdr) = 0x7AEC
>> 0x7AEC = htons(0xEC7A) = htons(60538)
>>
>> So these were outer IP packets with a total length of 123 bytes,
>> containing an inner IP packet with a total length of 60538 bytes.
>
> It's just using bag of holding technology!
>
>> After this patch:
>> __bpf_constant_htons(MAGIC_BYTES - sizeof(struct iphdr)) = htons(103)
>>
>> Now these packets are outer IP packets with a total length of 123 bytes,
>> containing an inner IP packet with a total length of 103 bytes.
>>
>> Signed-off-by: Asbjørn Sloth Tønnesen <ast@...erby.net>
>
> Reviewed-by: Toke Høiland-Jørgensen <toke@...nel.org>
Applied to bpf-next/net. Thanks.
Powered by blists - more mailing lists