Thread (17 messages) 17 messages, 3 authors, 2017-09-04

Re: EINVAL when using connect() for udp sockets

From: Eric Dumazet <hidden>
Date: 2017-03-24 23:19:23

On Fri, 2017-03-24 at 15:34 -0700, Cong Wang wrote:
quoted hunk ↗ jump to hunk
(Cc'ing Michael Kerrisk)

On Wed, Mar 22, 2017 at 10:18 PM, Eric Dumazet [off-list ref] wrote:
quoted
On Thu, 2017-03-23 at 13:22 +1100, Daurnimator wrote:
quoted
On 9 March 2017 at 14:10, Daurnimator [off-list ref] wrote:
quoted
When debugging https://github.com/daurnimator/lua-http/issues/73 which
uses https://github.com/wahern/dns we ran into an issue where modern
linux kernels return EINVAL if you try and re-use a udp socket.
The issue seems to occur if you go from a local destination ip to a
non-local one.
Did anyone get a chance to look into this issue?
I believe man page is not complete.

A disconnect is needed before another connect()
Is it? Making connect() reentrant is reasonable for connection-less
protocol like UDP, but I don't dig POSIX for the details. If so we need
something like below...
--- a/net/ipv4/datagram.c
+++ b/net/ipv4/datagram.c
@@ -40,7 +40,7 @@ int __ip4_datagram_connect(struct sock *sk, struct
sockaddr *uaddr, int addr_len
        sk_dst_reset(sk);

        oif = sk->sk_bound_dev_if;
-       saddr = inet->inet_saddr;
+       saddr = inet->inet_saddr = 0;
        if (ipv4_is_multicast(usin->sin_addr.s_addr)) {
                if (!oif)
                        oif = inet->mc_index;
Wont this break bind() ?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help