[PATCH] resolv_test.c: also cope with CONNREFUSED errors returned by recvfrom

Florian Weimer fweimer@redhat.com
Mon Sep 25 08:35:00 GMT 2017


On 09/25/2017 10:30 AM, Samuel Thibault wrote:
> Florian Weimer, on lun. 25 sept. 2017 10:20:46 +0200, wrote:
>> On 09/25/2017 09:38 AM, Samuel Thibault wrote:
>>> Florian Weimer, on lun. 25 sept. 2017 09:31:02 +0200, wrote:
>>>> On 09/10/2017 04:38 PM, Samuel Thibault wrote:
>>>>> +  if (length < 0)
>>>>> +    {
>>>>> +      /* The other end had closed the socket, and we are notified only now. */
>>>>> +      TEST_VERIFY_EXIT (errno == ECONNREFUSED);
>>>>> +      return true;
>>>>> +    }
>>>>
>>>> Sorry for not replying sooner.
>>>>
>>>> This UDP socket is unconnected.  If asynchronous error notifications are
>>>> received on it, this is arguably a TCP/IP stack bug.
>>>
>>> Reception of "port unreachable" icmp packets can be asynchronous with
>>> UDP too.
>>
>> Stevens says that this can happen on connected sockets only.  Both TCPv2 and
>> UNIX Network Programming have detailed explanations.  I can summarize those
>> if you don't have access.
>>
>> The only quoted exception is Linux, but the kernel behavior changed around
>> 2.4.0.
> 
> Running Linux 4.13
> 
> $ strace nc localhost 12345 -u
> ...
> sendmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="kljsdf\n", iov_len=7}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 7
> select(5, [3 4], [], NULL, NULL)        = 1 (in [3])
> recvmsg(3, {msg_namelen=0}, 0)          = -1 ECONNREFUSED (Connection refused)
> 
> Samuel

Surely this is a connected socket, otherwise the sendmsg call would fail 
due to the lack of an address to send the datagram to.

This entire discussion is specific to unconnected sockets, where the 
application has no way to match error responses to sent packets (unless 
IP_RECVERR is set and the information is received as ancillary data).

Thanks,
Florian



More information about the Libc-alpha mailing list