From: Martin KaFai Lau <martin.lau@linux.dev>
To: Aditi Ghag <aditi.ghag@isovalent.com>
Cc: kafai@fb.com, sdf@google.com, edumazet@google.com,
bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH v3 bpf-next 4/5] [RFC] udp: Fix destroying UDP listening sockets
Date: Tue, 21 Mar 2023 17:29:02 -0700 [thread overview]
Message-ID: <8d8f605d-f722-8a91-4dcf-2017cad40f7b@linux.dev> (raw)
In-Reply-To: <20230321184541.1857363-5-aditi.ghag@isovalent.com>
On 3/21/23 11:45 AM, Aditi Ghag wrote:
> Previously, UDP listening sockets that bind'ed to a port
> weren't getting properly destroyed via udp_abort.
> Specifically, the sockets were left in the UDP hash table with
> unset source port.
> Fix the issue by unconditionally unhashing and resetting source
> port for sockets that are getting destroyed. This would mean
> that in case of sockets listening on wildcarded address and
> on a specific address with a common port, users would have to
> explicitly select the socket(s) they intend to destroy.
>
> Signed-off-by: Aditi Ghag <aditi.ghag@isovalent.com>
> ---
> net/ipv4/udp.c | 21 ++++++++++++++++++++-
> 1 file changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> index 02d357713838..a495ac88fcee 100644
> --- a/net/ipv4/udp.c
> +++ b/net/ipv4/udp.c
> @@ -1965,6 +1965,25 @@ int udp_pre_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
> }
> EXPORT_SYMBOL(udp_pre_connect);
>
> +int __udp_disconnect_with_abort(struct sock *sk)
> +{
> + struct inet_sock *inet = inet_sk(sk);
> +
> + sk->sk_state = TCP_CLOSE;
> + inet->inet_daddr = 0;
> + inet->inet_dport = 0;
> + sock_rps_reset_rxhash(sk);
> + sk->sk_bound_dev_if = 0;
> + inet_reset_saddr(sk);
> + inet->inet_sport = 0;
> + sk_dst_reset(sk);
> + /* (TBD) In case of sockets listening on wildcard and specific address
> + * with a common port, socket will be removed from {hash, hash2} table.
> + */
> + sk->sk_prot->unhash(sk);
hmm... not sure if I understand the use case. The idea is to enforce the user
space to bind() again when it gets error from read(fd) because the source
ip/port needs to change when sending to another dst IP/port? Does it have a
usage example in the selftests?
> + return 0;
> +}
> +
> int __udp_disconnect(struct sock *sk, int flags)
> {
> struct inet_sock *inet = inet_sk(sk);
> @@ -2937,7 +2956,7 @@ int udp_abort(struct sock *sk, int err)
>
> sk->sk_err = err;
> sk_error_report(sk);
> - __udp_disconnect(sk, 0);
> + __udp_disconnect_with_abort(sk);
>
> out:
> if (!has_current_bpf_ctx())
next prev parent reply other threads:[~2023-03-22 0:29 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 18:45 [PATCH v3 bpf-next 0/5] bpf-next: Add socket destroy capability Aditi Ghag
2023-03-21 18:45 ` [PATCH v3 bpf-next 1/5] bpf: Implement batching in UDP iterator Aditi Ghag
2023-03-21 18:45 ` [PATCH v3 bpf-next 2/5] bpf: Add bpf_sock_destroy kfunc Aditi Ghag
2023-03-21 21:02 ` Stanislav Fomichev
2023-03-23 20:02 ` Aditi Ghag
2023-03-23 21:45 ` Stanislav Fomichev
2023-03-21 23:43 ` Martin KaFai Lau
2023-03-22 0:00 ` Aditi Ghag
2023-03-22 0:36 ` Martin KaFai Lau
2023-03-21 18:45 ` [PATCH v3 bpf-next 3/5] [RFC] net: Skip taking lock in BPF context Aditi Ghag
2023-03-21 21:31 ` Stanislav Fomichev
2023-03-21 21:37 ` Aditi Ghag
2023-03-21 21:41 ` Eric Dumazet
2023-03-21 21:43 ` Aditi Ghag
2023-03-21 23:39 ` Aditi Ghag
2023-03-22 0:02 ` Martin KaFai Lau
2023-03-21 18:45 ` [PATCH v3 bpf-next 4/5] [RFC] udp: Fix destroying UDP listening sockets Aditi Ghag
2023-03-22 0:29 ` Martin KaFai Lau [this message]
2023-03-22 0:59 ` Aditi Ghag
2023-03-22 22:55 ` Martin KaFai Lau
2023-03-23 0:32 ` Aditi Ghag
2023-03-23 1:08 ` Martin KaFai Lau
2023-03-23 1:35 ` Aditi Ghag
2023-03-23 6:14 ` Aditi Ghag
2023-03-21 18:45 ` [PATCH 5/5] selftests/bpf: Add tests for bpf_sock_destroy Aditi Ghag
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=8d8f605d-f722-8a91-4dcf-2017cad40f7b@linux.dev \
--to=martin.lau@linux.dev \
--cc=aditi.ghag@isovalent.com \
--cc=bpf@vger.kernel.org \
--cc=edumazet@google.com \
--cc=kafai@fb.com \
--cc=sdf@google.com \
/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