net: diag: support SOCK_DESTROY for UDP sockets
Subsystems (3)
PATCH v2 1/1 net: diag: support SOCK_DESTROY for UDP sockets
This implements SOCK_DESTROY for UDP sockets similar to what was done for TCP with commit c1e64e298b8ca ("net: diag: Support destroying TCP sockets.") A process with a UDP socket targeted for destroy is awakened and recvmsg fails with ECONNABORTED.
---
v2
- changed socket lookup to __udp{4,6}_lib_lookup
include/net/udp.h | 1 + net/ipv4/udp.c | 17 +++++++++++++++++ net/ipv4/udp_diag.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/ipv6/udp.c | 1 + 4 files changed, 74 insertions(+)
include/net/udp.h +1 -0
@@ -251,6 +251,7 @@ int udp_get_port(struct sock *sk, unsigned short snum,int (*saddr_cmp)(const struct sock *, const struct sock *));void udp_err (struct sk_buff *,u32 ); +int udp_abort (struct sock *sk,int err);int udp_sendmsg (struct sock *sk,struct msghdr *msg,size_t len);int udp_push_pending_frames (struct sock *sk);void udp_flush_pending_frames (struct sock *sk);
net/ipv4/udp.c +17 -0
@@ -2192,6 +2192,22 @@ unsigned int udp_poll(struct file *file, struct socket *sock, poll_table *wait) }EXPORT_SYMBOL (udp_poll); +int udp_abort (struct sock *sk,int err) +{ +lock_sock (sk); + + sk->sk_err = err; + sk->sk_error_report (sk); +udp_disconnect (sk,0 ); + +release_sock (sk); + +sock_put (sk); + +return 0 ; +} +EXPORT_SYMBOL_GPL (udp_abort); +struct proto udp_prot = { .name ="UDP" , .owner =THIS_MODULE ,
@@ -2223,6 +2239,7 @@ struct proto udp_prot = { .compat_getsockopt = compat_udp_getsockopt, #endif .clear_sk = sk_prot_clear_portaddr_nulls, + .diag_destroy = udp_abort, };EXPORT_SYMBOL (udp_prot);
net/ipv4/udp_diag.c +55 -0
73 lines not on this page · raw message
net/ipv6/udp.c +1 -0
@@ -1467,6 +1467,7 @@ struct proto udpv6_prot = { .compat_getsockopt = compat_udpv6_getsockopt, #endif .clear_sk = udp_v6_clear_sk, + .diag_destroy = udp_abort, }; static struct inet_protosw udpv6_protosw = {
Signature · 1 line
2.1.4
Quoted 10 lines · David Ahern
This implements
SOCK_DESTROYfor UDP sockets similar to what was done for TCP with commitc1e64e298b8ca("net: diag: Support destroying TCP sockets.") A process with a UDP socket targeted for destroy is awakened and recvmsg fails with ECONNABORTED.Signed-off-by David Ahern <[email protected]>---
v2
- changed socket lookup to __udp{4,6}_lib_lookup
Quoted 5 lines
include/net/udp.h | 1 + net/ipv4/udp.c | 17 +++++++++++++++++ net/ipv4/udp_diag.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/ipv6/udp.c | 1 + 4 files changed, 74 insertions(+)
Hi David
It seems you forgot the sock_diag_check_cookie() call, but other than that this patch looks fine.
Thanks.
Quoted 6 lines · Eric Dumazet
Hi David
It seems you forgot the
sock_diag_check_cookie()call, but other than that this patch looks fine.Thanks.
indeed. will fix tomorrow and re-send. Thanks for the review.