Commit 92ec8b93 authored by Asbjørn Sloth Tønnesen's avatar Asbjørn Sloth Tønnesen Committed by Martin KaFai Lau
Browse files

selftests/bpf: Avoid subtraction after htons() in ipip tests



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.

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: default avatarAsbjørn Sloth Tønnesen <ast@fiberby.net>
Reviewed-by: default avatarToke Høiland-Jørgensen <toke@kernel.org>
Link: https://lore.kernel.org/r/20240808075906.1849564-1-ast@fiberby.net


Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent 39e8111c
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment