From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cann Subject: UDP packets arriving on wrong sockets Date: Thu, 2 Aug 2018 05:05:05 -0400 Message-ID: <20180802090505.GA29624@canndrew.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="envbJBWh7q8WU6mo" To: netdev@vger.kernel.org Return-path: Received: from canndrew.org ([199.167.29.165]:41146 "EHLO canndrew.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726238AbeHBLbq (ORCPT ); Thu, 2 Aug 2018 07:31:46 -0400 Received: from shum by canndrew.org with local (Exim 4.84_2) (envelope-from ) id 1fl9Xd-0007iv-OD for netdev@vger.kernel.org; Thu, 02 Aug 2018 05:05:05 -0400 Content-Disposition: inline Sender: netdev-owner@vger.kernel.org List-ID: --envbJBWh7q8WU6mo Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi,=20 I posted this on stackoverflow yesterday but I'm reposting it here since it= got no response. Original post: https://stackoverflow.com/questions/51630337/ud= p-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 =66rom which datagrams are received*." For some reason, my connected sockets are receiving packets that were desti= ned for each other. eg: The UDP socket connected to A sends a message to A, A t= hen sends a reply back. The UDP socket connected to B sends a message to B, B t= hen 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 - somet= imes 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 --envbJBWh7q8WU6mo Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJbYslBAAoJEJQq94U5BTTOoyQP/3G1iQoDd9TeAHgLTrT/KK1F 9dsxxGkf5VAoezMAbNSbpG93Vo9xpqBRg7DPbDSbcKxE/uUI7M2M1tpDhS3bFBO6 WPHFr5MTSbPGXUGhoTc4o7SXDtMKFT0jXJJ5MtT7GqffVyU23utSKTdmRiP/lUIm ZOIXQ/I+AEBOoL27nVcPyeHz5V2nBOob/kHF7mB/zKUOJctwMWqBTh4uySbHBojA FP5mU35KWwKyjiTvo8oxIdXi+QYV2kojnclmMeGOIlh95OZK9xeBfeemLiPBlPVL G811K13ftvBjWBvEnxx9PgjcJ3zeBxGlIcOrjaFIm/VbVhqDVqW9M3tnXAjfgGJc /EVClj19HVMXdrbM8SCDFgyMKkTpE4uXU+J2zCOZzlFL5DwiB+vLCZtv8HFzmwl1 EJAd5M2+jTYoRgrP9H0hNCnlHjBnz8N14ojqdWssArPPA8IvwOIq/N+Rzh7pM/Nn BG0r2BX+UYCkonzDJuDbgyR61oqaS0HR5a7aA45e+80ie1IokgrRajfIfEMlksGS OnNFpp6vlCEXSh9p+KIc/kcQ4feU18UsGtqGLQH+aKev8ZYo4wOlV+4aMvhBecRA bPI+4Dh1nSf0YfR1cqU4Y0RCI0uuxSlQowySAQmudFbhiFNkQVXW8VzynXDsuiXh jDK9geO6HpNmzPN269l4 =kwcC -----END PGP SIGNATURE----- --envbJBWh7q8WU6mo--