netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Maxim Mikityanskiy <maximmi@nvidia.com>
Cc: bpf <bpf@vger.kernel.org>, "Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	Networking <netdev@vger.kernel.org>,
	"Tariq Toukan" <tariqt@nvidia.com>,
	"Martin KaFai Lau" <kafai@fb.com>,
	"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"KP Singh" <kpsingh@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Eric Dumazet" <edumazet@google.com>,
	"Hideaki YOSHIFUJI" <yoshfuji@linux-ipv6.org>,
	"David Ahern" <dsahern@kernel.org>,
	"Shuah Khan" <shuah@kernel.org>,
	"Jesper Dangaard Brouer" <hawk@kernel.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Joe Stringer" <joe@cilium.io>,
	"Florent Revest" <revest@chromium.org>,
	"open list:KERNEL SELFTEST FRAMEWORK"
	<linux-kselftest@vger.kernel.org>,
	"Toke Høiland-Jørgensen" <toke@toke.dk>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Florian Westphal" <fw@strlen.de>,
	pabeni@redhat.com
Subject: Re: [PATCH bpf-next v9 3/5] bpf: Add helpers to issue and check SYN cookies in XDP
Date: Fri, 6 May 2022 14:19:23 -0700	[thread overview]
Message-ID: <CAEf4BzYDfNuF4QL37ZLjR5--zimpycZsjzXhq6ao79_05+OOiA@mail.gmail.com> (raw)
In-Reply-To: <20220503171437.666326-4-maximmi@nvidia.com>

On Tue, May 3, 2022 at 10:15 AM Maxim Mikityanskiy <maximmi@nvidia.com> wrote:
>
> The new helpers bpf_tcp_raw_{gen,check}_syncookie_ipv{4,6} allow an XDP
> program to generate SYN cookies in response to TCP SYN packets and to
> check those cookies upon receiving the first ACK packet (the final
> packet of the TCP handshake).
>
> Unlike bpf_tcp_{gen,check}_syncookie these new helpers don't need a
> listening socket on the local machine, which allows to use them together
> with synproxy to accelerate SYN cookie generation.
>
> Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com>
> Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
> ---
>  include/net/tcp.h              |   1 +
>  include/uapi/linux/bpf.h       |  78 ++++++++++++++++++++++
>  net/core/filter.c              | 118 +++++++++++++++++++++++++++++++++
>  net/ipv4/tcp_input.c           |   3 +-
>  scripts/bpf_doc.py             |   4 ++
>  tools/include/uapi/linux/bpf.h |  78 ++++++++++++++++++++++
>  6 files changed, 281 insertions(+), 1 deletion(-)
>
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 94a52ad1101c..45aafc28ce00 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -432,6 +432,7 @@ u16 tcp_v4_get_syncookie(struct sock *sk, struct iphdr *iph,
>                          struct tcphdr *th, u32 *cookie);
>  u16 tcp_v6_get_syncookie(struct sock *sk, struct ipv6hdr *iph,
>                          struct tcphdr *th, u32 *cookie);
> +u16 tcp_parse_mss_option(const struct tcphdr *th, u16 user_mss);
>  u16 tcp_get_syncookie_mss(struct request_sock_ops *rsk_ops,
>                           const struct tcp_request_sock_ops *af_ops,
>                           struct sock *sk, struct tcphdr *th);
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 4dd9e34f2a60..5e611d898302 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -5156,6 +5156,80 @@ union bpf_attr {
>   *             if not NULL, is a reference which must be released using its
>   *             corresponding release function, or moved into a BPF map before
>   *             program exit.
> + *
> + * s64 bpf_tcp_raw_gen_syncookie_ipv4(struct iphdr *iph, struct tcphdr *th, u32 th_len)
> + *     Description
> + *             Try to issue a SYN cookie for the packet with corresponding
> + *             IPv4/TCP headers, *iph* and *th*, without depending on a
> + *             listening socket.
> + *
> + *             *iph* points to the IPv4 header.
> + *
> + *             *th* points to the start of the TCP header, while *th_len*
> + *             contains the length of the TCP header (at least
> + *             **sizeof**\ (**struct tcphdr**)).
> + *     Return
> + *             On success, lower 32 bits hold the generated SYN cookie in
> + *             followed by 16 bits which hold the MSS value for that cookie,
> + *             and the top 16 bits are unused.
> + *
> + *             On failure, the returned value is one of the following:
> + *
> + *             **-EINVAL** if *th_len* is invalid.
> + *
> + * s64 bpf_tcp_raw_gen_syncookie_ipv6(struct ipv6hdr *iph, struct tcphdr *th, u32 th_len)
> + *     Description
> + *             Try to issue a SYN cookie for the packet with corresponding
> + *             IPv6/TCP headers, *iph* and *th*, without depending on a
> + *             listening socket.
> + *
> + *             *iph* points to the IPv6 header.
> + *
> + *             *th* points to the start of the TCP header, while *th_len*
> + *             contains the length of the TCP header (at least
> + *             **sizeof**\ (**struct tcphdr**)).
> + *     Return
> + *             On success, lower 32 bits hold the generated SYN cookie in
> + *             followed by 16 bits which hold the MSS value for that cookie,
> + *             and the top 16 bits are unused.
> + *
> + *             On failure, the returned value is one of the following:
> + *
> + *             **-EINVAL** if *th_len* is invalid.
> + *
> + *             **-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
> + *
> + * int bpf_tcp_raw_check_syncookie_ipv4(struct iphdr *iph, struct tcphdr *th)

Note that all existing helpers that just return error or 0 on success
return long. Please use long for consistency.

> + *     Description
> + *             Check whether *iph* and *th* contain a valid SYN cookie ACK
> + *             without depending on a listening socket.
> + *
> + *             *iph* points to the IPv4 header.
> + *
> + *             *th* points to the TCP header.
> + *     Return
> + *             0 if *iph* and *th* are a valid SYN cookie ACK.
> + *
> + *             On failure, the returned value is one of the following:
> + *
> + *             **-EACCES** if the SYN cookie is not valid.
> + *
> + * int bpf_tcp_raw_check_syncookie_ipv6(struct ipv6hdr *iph, struct tcphdr *th)

same

> + *     Description
> + *             Check whether *iph* and *th* contain a valid SYN cookie ACK
> + *             without depending on a listening socket.
> + *
> + *             *iph* points to the IPv6 header.
> + *
> + *             *th* points to the TCP header.
> + *     Return
> + *             0 if *iph* and *th* are a valid SYN cookie ACK.
> + *
> + *             On failure, the returned value is one of the following:
> + *
> + *             **-EACCES** if the SYN cookie is not valid.
> + *
> + *             **-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.

[...]

  reply	other threads:[~2022-05-06 21:19 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-03 17:14 [PATCH bpf-next v9 0/5] New BPF helpers to accelerate synproxy Maxim Mikityanskiy
2022-05-03 17:14 ` [PATCH bpf-next v9 1/5] bpf: Fix documentation of th_len in bpf_tcp_{gen,check}_syncookie Maxim Mikityanskiy
2022-05-03 17:14 ` [PATCH bpf-next v9 2/5] bpf: Allow helpers to accept pointers with a fixed size Maxim Mikityanskiy
2022-05-06 21:12   ` Andrii Nakryiko
2022-05-03 17:14 ` [PATCH bpf-next v9 3/5] bpf: Add helpers to issue and check SYN cookies in XDP Maxim Mikityanskiy
2022-05-06 21:19   ` Andrii Nakryiko [this message]
2022-05-10 19:20     ` Maxim Mikityanskiy
2022-05-11  0:03       ` Andrii Nakryiko
2022-05-03 17:14 ` [PATCH bpf-next v9 4/5] bpf: Add selftests for raw syncookie helpers Maxim Mikityanskiy
2022-05-06 21:34   ` Andrii Nakryiko
2022-05-10 19:21     ` Maxim Mikityanskiy
2022-05-11  0:10       ` Andrii Nakryiko
2022-05-11 11:48         ` Maxim Mikityanskiy
2022-05-03 17:14 ` [PATCH bpf-next v9 5/5] bpf: Allow the new syncookie helpers to work with SKBs Maxim Mikityanskiy
2022-05-06 21:39   ` Andrii Nakryiko
2022-05-06 21:51 ` [PATCH bpf-next v9 0/5] New BPF helpers to accelerate synproxy Andrii Nakryiko
2022-05-10 19:21   ` Maxim Mikityanskiy
2022-05-10 23:59     ` Andrii Nakryiko
2022-05-11 11:48       ` Maxim Mikityanskiy
2022-05-16 17:17         ` Maxim Mikityanskiy
2022-05-18 13:43           ` Maxim Mikityanskiy
2022-05-19  4:42             ` Andrii Nakryiko

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=CAEf4BzYDfNuF4QL37ZLjR5--zimpycZsjzXhq6ao79_05+OOiA@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=hawk@kernel.org \
    --cc=joe@cilium.io \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=maximmi@nvidia.com \
    --cc=memxor@gmail.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=revest@chromium.org \
    --cc=shuah@kernel.org \
    --cc=songliubraving@fb.com \
    --cc=tariqt@nvidia.com \
    --cc=toke@toke.dk \
    --cc=yhs@fb.com \
    --cc=yoshfuji@linux-ipv6.org \
    /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).