net: diag: support SOCK_DESTROY for UDP sockets
Subsystems (3)
PATCH v4 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.
---
v4
- added support for v4 mapped addresses and return EINVAL for unknown protocol to be consistent with TCP as noted by Lorenzo
- changed locking to have udp_abort call sock_put
v3
- add missing sock_diag_check_cookie check after socket lookup per Eric'c comment
v2
- changed socket lookup to __udp{4,6}_lib_lookup
include/net/udp.h | 1 + net/ipv4/udp.c | 15 ++++++++++ net/ipv4/udp_diag.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/ipv6/udp.c | 1 + 4 files changed, 96 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 +15 -0
@@ -2193,6 +2193,20 @@ 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); + +return 0 ; +} +EXPORT_SYMBOL_GPL (udp_abort); +struct proto udp_prot = { .name ="UDP" , .owner =THIS_MODULE ,
@@ -2224,6 +2238,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 +79 -0
97 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
From: David Ahern <[email protected]>
Date: Tue, 23 Aug 2016 21:06:33 -0700
Quoted 6 lines
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]>
Applied.