netdev
[Top] [All Lists]

Re: UDP sockets bound to ANY send answers with wrong src ip address

To: Denis Vlasenko <vda@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: UDP sockets bound to ANY send answers with wrong src ip address
From: Martijn van Oosterhout <kleptog@xxxxxxxxx>
Date: Wed, 9 Jun 2004 22:20:30 +1000
Cc: netdev@xxxxxxxxxxx, linux-net@xxxxxxxxxxxxxxx, davem@xxxxxxxxxx, yoshfuji@xxxxxxxxxxxxxx, pekkas@xxxxxxxxxx, jmorris@xxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx
In-reply-to: <200406091425.39324.vda@port.imtp.ilyichevsk.odessa.ua>
References: <200406091425.39324.vda@port.imtp.ilyichevsk.odessa.ua>
Reply-to: Martijn van Oosterhout <kleptog@xxxxxxxxx>
Sender: netdev-bounce@xxxxxxxxxxx
User-agent: Mutt/1.3.28i
On Wed, Jun 09, 2004 at 02:25:39PM +0300, Denis Vlasenko wrote:
> I observe that UDP sockets listening on ANY
> send response packets with ip addr derived from
> ip address of interface which is used to send 'em
> instead of using dst ip address of client's packet.
> 
> I was bitten by this with DNS and NTP.

This is the responsibility of the program. Unless the UDP packet is
bound to a particular address, or the program specifies an IP, the
kernel will pick one. For this reason both the BIND and NTP daemons
open a socket for each interface so they can control this. netstat on
my machine shows:

udp        0      0 192.168.1.225:123       0.0.0.0:*                           
udp        0      0 127.0.0.1:123           0.0.0.0:*                           
udp        0      0 0.0.0.0:123             0.0.0.0:*                        

for the NTP server. The DNS has similar machanism. Remember, UDP
doesn't involve connections, so there is no concept of "replying" to a
packet, the program has to manage that itself.

In your example, if you tell netcat which address to bind to, it will
work.

Hope this helps,
-- 
Martijn van Oosterhout   <kleptog@xxxxxxxxx>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment: pgpQdqTiY1W83.pgp
Description: PGP signature

<Prev in Thread] Current Thread [Next in Thread>