netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Toke Høiland-Jørgensen" <toke@kernel.org>
To: "Asbjørn Sloth Tønnesen" <ast@fiberby.net>, bpf@vger.kernel.org
Cc: "Asbjørn Sloth Tønnesen" <ast@fiberby.net>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"KP Singh" <kpsingh@kernel.org>,
	"Stanislav Fomichev" <sdf@fomichev.me>,
	"Hao Luo" <haoluo@google.com>, "Jiri Olsa" <jolsa@kernel.org>,
	"Mykola Lysenko" <mykolal@fb.com>,
	"Shuah Khan" <shuah@kernel.org>,
	"Tushar Vyavahare" <tushar.vyavahare@intel.com>,
	"Magnus Karlsson" <magnus.karlsson@intel.com>,
	"Willem de Bruijn" <willemb@google.com>,
	netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next] selftests/bpf: Avoid subtraction after htons() in ipip tests
Date: Thu, 08 Aug 2024 11:24:25 +0200	[thread overview]
Message-ID: <87sevfpdti.fsf@toke.dk> (raw)
In-Reply-To: <20240808075906.1849564-1-ast@fiberby.net>

Asbjørn Sloth Tønnesen <ast@fiberby.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@fiberby.net>

Reviewed-by: Toke Høiland-Jørgensen <toke@kernel.org>

  reply	other threads:[~2024-08-08  9:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-08  7:59 [PATCH bpf-next] selftests/bpf: Avoid subtraction after htons() in ipip tests Asbjørn Sloth Tønnesen
2024-08-08  9:24 ` Toke Høiland-Jørgensen [this message]
2024-08-14  1:15   ` Martin KaFai Lau

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=87sevfpdti.fsf@toke.dk \
    --to=toke@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@fiberby.net \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=magnus.karlsson@intel.com \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tushar.vyavahare@intel.com \
    --cc=willemb@google.com \
    --cc=yonghong.song@linux.dev \
    /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;
as well as URLs for NNTP newsgroup(s).