Skip to content

Commit 92ec8b9

Browse files
Asbjørn Sloth TønnesenMartin KaFai Lau
Asbjørn Sloth Tønnesen
authored and
Martin KaFai Lau
committed
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: Asbjørn Sloth Tønnesen <[email protected]> Reviewed-by: Toke Høiland-Jørgensen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent 39e8111 commit 92ec8b9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tools/testing/selftests/bpf/prog_tests/flow_dissector.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ struct test tests[] = {
378378
.iph_inner.ihl = 5,
379379
.iph_inner.protocol = IPPROTO_TCP,
380380
.iph_inner.tot_len =
381-
__bpf_constant_htons(MAGIC_BYTES) -
382-
sizeof(struct iphdr),
381+
__bpf_constant_htons(MAGIC_BYTES -
382+
sizeof(struct iphdr)),
383383
.tcp.doff = 5,
384384
.tcp.source = 80,
385385
.tcp.dest = 8080,
@@ -407,8 +407,8 @@ struct test tests[] = {
407407
.iph_inner.ihl = 5,
408408
.iph_inner.protocol = IPPROTO_TCP,
409409
.iph_inner.tot_len =
410-
__bpf_constant_htons(MAGIC_BYTES) -
411-
sizeof(struct iphdr),
410+
__bpf_constant_htons(MAGIC_BYTES -
411+
sizeof(struct iphdr)),
412412
.tcp.doff = 5,
413413
.tcp.source = 80,
414414
.tcp.dest = 8080,
@@ -436,8 +436,8 @@ struct test tests[] = {
436436
.iph_inner.ihl = 5,
437437
.iph_inner.protocol = IPPROTO_TCP,
438438
.iph_inner.tot_len =
439-
__bpf_constant_htons(MAGIC_BYTES) -
440-
sizeof(struct iphdr),
439+
__bpf_constant_htons(MAGIC_BYTES -
440+
sizeof(struct iphdr)),
441441
.tcp.doff = 5,
442442
.tcp.source = 99,
443443
.tcp.dest = 9090,

0 commit comments

Comments
 (0)