Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: David Miller <davem@davemloft.net>
Cc: brian.haley@hp.com, ole@ans.pl, netdev@vger.kernel.org
Subject: Re: [PATCH] inet: dont set inet_rcv_saddr in connect()
Date: Wed, 08 Sep 2010 16:27:02 +0200	[thread overview]
Message-ID: <1283956022.2748.56.camel@edumazet-laptop> (raw)
In-Reply-To: <1283925171.2634.838.camel@edumazet-laptop>

Le mercredi 08 septembre 2010 à 07:52 +0200, Eric Dumazet a écrit :
> Le mardi 07 septembre 2010 à 22:36 -0700, David Miller a écrit :
> > From: Eric Dumazet <eric.dumazet@gmail.com>
> > Date: Wed, 08 Sep 2010 06:57:37 +0200
> > 
> > >    Document that connect() also sets local address, and that before
> > > doing a second connect() to change remote address, its mandatory to
> > > first issue a connect(AF_UNSPEC) to clear local address (if not locked
> > > by a prior bind() call)
> > 
> > For connectionless sockets, the application may connect() as many
> > times as it wishes to change the remote address.  The local address
> > remains set if it were set before such a re-associating connect().
> > 
> > It need only issue a connect(AF_UNSPEC) to make the socket have no
> > remote association, and as you state this operation will also wipe out
> > any local address settings not created by a bind() call.
> > 
> > And nicely our man pages are very clear about this :-) as is BSD and
> > Steven's volume 2.
> > 
> > This has been legal for decades, so we have to keep working this way.
> 
> Yes, its also buggy, if 2nd remote address is not reachable on same interface.
> Even if we try a connect(AF_UNSPEC), the local address stay as is :
> 
> after bind(port 5555) local addr=0x0:5555 
> after connect(123) local addr=0x7f000001:5555 remote addr=0x7f000001:123 
> Could not connect, errno=22
> after connect(AF_UNSPEC) local addr=0x7f000001:5555 
> connect: Invalid argument
> 

I run the program on FreeBSD 8.1, and this OS
does change the source address at connect() time.
It also change it each time connect() is called, not only once.

fd = socket()
connect(fd, "127.0.0.1:ntp")
system("netstat -p udp | grep udp")
connect(fd, "192.168.20.110:ntp")
system("netstat -p udp | grep udp")

->

udp4  0  0 127.0.0.1.35974       127.0.0.1.ntp

udp4  0  0 192.168.20.80.35974   192.168.20.110.ntp

while on Linux we refuse the second connect() -> EINVAL
(Because no route can be found from 127.0.0.1 to 192.168.20.110)




  parent reply	other threads:[~2010-09-08 14:27 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-06 17:11 2.6.34: Problem with UDP traffic on lo + poll(?) Krzysztof Oledzki
2010-09-06 19:42 ` Eric Dumazet
2010-09-06 19:55   ` Krzysztof Olędzki
2010-09-06 20:29     ` Eric Dumazet
2010-09-06 20:44       ` Krzysztof Olędzki
2010-09-06 20:48         ` Krzysztof Olędzki
2010-09-07 15:37           ` Krzysztof Olędzki
2010-09-07 16:36             ` Eric Dumazet
2010-09-07 19:20               ` Krzysztof Olędzki
2010-09-07 19:26               ` Eric Dumazet
2010-09-07 19:59                 ` David Miller
2010-09-07 21:35                   ` [PATCH] inet: dont set inet_rcv_saddr in connect() Eric Dumazet
2010-09-07 21:52                     ` Krzysztof Olędzki
2010-09-08  2:16                       ` David Miller
2010-09-08  4:13                         ` Eric Dumazet
2010-09-08  2:34                     ` Brian Haley
2010-09-08  3:34                       ` David Miller
2010-09-08  4:42                         ` Eric Dumazet
2010-09-08  5:51                           ` David Miller
2010-09-08  4:57                       ` Eric Dumazet
2010-09-08  5:36                         ` David Miller
2010-09-08  5:52                           ` Eric Dumazet
2010-09-08 10:10                             ` [PATCH] udp: add rehash on connect() Eric Dumazet
2010-09-08 15:06                               ` Krzysztof Olędzki
2010-09-08 15:17                                 ` Eric Dumazet
2010-09-08 15:29                                   ` Krzysztof Olędzki
2010-09-08 15:08                               ` [PATCH v2] " Eric Dumazet
2010-09-08 16:52                                 ` Krzysztof Olędzki
2010-09-09  4:39                                   ` David Miller
2010-09-08 14:27                             ` Eric Dumazet [this message]
2010-09-07 21:28                 ` 2.6.34: Problem with UDP traffic on lo + poll(?) Krzysztof Olędzki
2010-09-07 21:39                   ` Eric Dumazet
2010-09-07 21:51                     ` Krzysztof Olędzki
2010-09-08  4:12                       ` Eric Dumazet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1283956022.2748.56.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=brian.haley@hp.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=ole@ans.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox