[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1283956022.2748.56.camel@edumazet-laptop>
Date: Wed, 08 Sep 2010 16:27:02 +0200
From: Eric Dumazet <eric.dumazet@...il.com>
To: David Miller <davem@...emloft.net>
Cc: brian.haley@...com, ole@....pl, netdev@...r.kernel.org
Subject: Re: [PATCH] inet: dont set inet_rcv_saddr in connect()
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@...il.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)
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists