All of lore.kernel.org
 help / color / mirror / Atom feed
* UDP packets arriving on wrong sockets
@ 2018-08-02  9:05 Andrew Cann
  2018-08-02 13:20 ` Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Cann @ 2018-08-02  9:05 UTC (permalink / raw)
  To: netdev

[-- Attachment #1: Type: text/plain, Size: 1538 bytes --]

Hi, 

I posted this on stackoverflow yesterday but I'm reposting it here since it got
no response. Original post: https://stackoverflow.com/questions/51630337/udp-packets-arriving-on-wrong-sockets-on-linux

I have two UDP sockets bound to the same address and connected to addresses A
and B. I have two more UDP sockets bound to A and B and not connected.

This is what my /proc/net/udp looks like (trimmed for readability):

      sl  local_address rem_address
     3937: 0100007F:DD9C 0300007F:9910
     3937: 0100007F:DD9C 0200007F:907D
    16962: 0200007F:907D 00000000:0000
    19157: 0300007F:9910 00000000:0000

According to connect(2): "If the socket sockfd is of type SOCK_DGRAM, then addr
is the address to which datagrams are sent by default, *and the only address
from which datagrams are received*."

For some reason, my connected sockets are receiving packets that were destined
for each other. eg: The UDP socket connected to A sends a message to A, A then
sends a reply back. The UDP socket connected to B sends a message to B, B then
sends a reply back. But the reply from A arrives at the socket connected to B
and the reply from B arrives at the socket connected to A.

Why on earth would this be happening? Note that it happens randomly - sometimes
the replies arrive at the correct sockets and sometimes they don't. Is there
any way to prevent this or any situation under which connect() is supposed to
not work?

Any help explaining this would be hugely appreciated :)

 - Andrew


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-08-03 17:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-02  9:05 UDP packets arriving on wrong sockets Andrew Cann
2018-08-02 13:20 ` Eric Dumazet
2018-08-02 13:35   ` Eric Dumazet
2018-08-02 15:21   ` Willem de Bruijn
2018-08-02 15:28     ` Eric Dumazet
2018-08-03  4:19     ` Andrew Cann
2018-08-03 14:20       ` Willem de Bruijn
2018-08-03 15:20         ` Andrew Cann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.