Q: UDP Broadcast, Sockets, Dual NICs, Single Cable

Q: UDP Broadcast, Sockets, Dual NICs, Single Cable

Post by Jack Da » Fri, 17 Dec 2010 12:14:14



HI, I have a system with dual NICs - eth0 and eth1. eth0 is live (has
an IP address and a cable from it's RJ45 jack into the wall). eth0 is
not 'live' (no IP address, and no cable).

So I have an application that opens 2 UDP sockets, one on eth0 and the
other on eth1. It then sits awaiting for broadcast messages from
clients. When it gets one, we process it. Here's what's strange: When
a broadcast messages comes in, we also get the message on the socket
associated with eth1 (the NIC with no IP address and no cable).

Are UDP broadcast message known to behave in this way? Could this be a
bug in the Linux IP stack?  A but on our application?

Any feedback appreciated.

Thanks.

 
 
 

Q: UDP Broadcast, Sockets, Dual NICs, Single Cable

Post by Tauno Voipi » Fri, 17 Dec 2010 16:03:47



Quote:

> HI, I have a system with dual NICs - eth0 and eth1. eth0 is live (has
> an IP address and a cable from it's RJ45 jack into the wall). eth0 is
> not 'live' (no IP address, and no cable).

> So I have an application that opens 2 UDP sockets, one on eth0 and the
> other on eth1. It then sits awaiting for broadcast messages from
> clients. When it gets one, we process it. Here's what's strange: When
> a broadcast messages comes in, we also get the message on the socket
> associated with eth1 (the NIC with no IP address and no cable).

> Are UDP broadcast message known to behave in this way? Could this be a
> bug in the Linux IP stack?  A but on our application?

> Any feedback appreciated.

How do you associate a socket with an interface?

--

Tauno Voipio
tauno voipio (at) iki fi

 
 
 

Q: UDP Broadcast, Sockets, Dual NICs, Single Cable

Post by Jorgen Grah » Fri, 17 Dec 2010 20:41:38




>> HI, I have a system with dual NICs - eth0 and eth1. eth0 is live (has
>> an IP address and a cable from it's RJ45 jack into the wall). eth0 is
>> not 'live' (no IP address, and no cable).

>> So I have an application that opens 2 UDP sockets, one on eth0 and the
>> other on eth1. It then sits awaiting for broadcast messages from
>> clients. When it gets one, we process it. Here's what's strange: When
>> a broadcast messages comes in, we also get the message on the socket
>> associated with eth1 (the NIC with no IP address and no cable).

>> Are UDP broadcast message known to behave in this way? Could this be a
>> bug in the Linux IP stack?  A but on our application?

>> Any feedback appreciated.

> How do you associate a socket with an interface?

Bind to its IP address, I suppose. But his eth0 interface isn't even
configured for IP and has no IP address ... so yes, it would be
interesting to know.  Perhaps they aren't UDP sockets after all?

/Jorgen

--

\X/     snipabacken.se>   O  o   .

 
 
 

Q: UDP Broadcast, Sockets, Dual NICs, Single Cable

Post by Richard Kettlewel » Fri, 17 Dec 2010 20:57:41





>>> HI, I have a system with dual NICs - eth0 and eth1. eth0 is live (has
>>> an IP address and a cable from it's RJ45 jack into the wall). eth0 is
>>> not 'live' (no IP address, and no cable).

>>> So I have an application that opens 2 UDP sockets, one on eth0 and the
>>> other on eth1. It then sits awaiting for broadcast messages from
>>> clients. When it gets one, we process it. Here's what's strange: When
>>> a broadcast messages comes in, we also get the message on the socket
>>> associated with eth1 (the NIC with no IP address and no cable).

>>> Are UDP broadcast message known to behave in this way? Could this be a
>>> bug in the Linux IP stack?  A but on our application?

>>> Any feedback appreciated.

>> How do you associate a socket with an interface?

> Bind to its IP address, I suppose. But his eth0 interface isn't even
> configured for IP and has no IP address ... so yes, it would be
> interesting to know.  Perhaps they aren't UDP sockets after all?

SO_BINDTODEVICE?

--
http://www.greenend.org.uk/rjk/

 
 
 

Q: UDP Broadcast, Sockets, Dual NICs, Single Cable

Post by Jorgen Grah » Sat, 18 Dec 2010 00:13:36






>>>> HI, I have a system with dual NICs - eth0 and eth1. eth0 is live (has
>>>> an IP address and a cable from it's RJ45 jack into the wall). eth0 is
>>>> not 'live' (no IP address, and no cable).

>>>> So I have an application that opens 2 UDP sockets, one on eth0 and the
>>>> other on eth1. It then sits awaiting for broadcast messages from
>>>> clients. When it gets one, we process it. Here's what's strange: When
>>>> a broadcast messages comes in, we also get the message on the socket
>>>> associated with eth1 (the NIC with no IP address and no cable).

>>>> Are UDP broadcast message known to behave in this way? Could this be a
>>>> bug in the Linux IP stack?  A but on our application?

>>>> Any feedback appreciated.

>>> How do you associate a socket with an interface?

>> Bind to its IP address, I suppose. But his eth0 interface isn't even
>> configured for IP and has no IP address ... so yes, it would be
>> interesting to know.  Perhaps they aren't UDP sockets after all?

> SO_BINDTODEVICE?

As documented in socket(7). Ah, yes, that seems likely.

/Jorgen

--

\X/     snipabacken.se>   O  o   .

 
 
 

Q: UDP Broadcast, Sockets, Dual NICs, Single Cable

Post by Jack Da » Sat, 18 Dec 2010 06:17:15






> >>> HI, I have a system with dual NICs - eth0 and eth1. eth0 is live (has
> >>> an IP address and a cable from it's RJ45 jack into the wall). eth0 is
> >>> not 'live' (no IP address, and no cable).

> >>> So I have an application that opens 2 UDP sockets, one on eth0 and the
> >>> other on eth1. It then sits awaiting for broadcast messages from
> >>> clients. When it gets one, we process it. Here's what's strange: When
> >>> a broadcast messages comes in, we also get the message on the socket
> >>> associated with eth1 (the NIC with no IP address and no cable).

> >>> Are UDP broadcast message known to behave in this way? Could this be a
> >>> bug in the Linux IP stack? ?A but on our application?

> >>> Any feedback appreciated.

> >> How do you associate a socket with an interface?

> > Bind to its IP address, I suppose. But his eth0 interface isn't even
> > configured for IP and has no IP address ... so yes, it would be
> > interesting to know. ?Perhaps they aren't UDP sockets after all?

> SO_BINDTODEVICE?

> --http://www.greenend.org.uk/rjk/

Yes, it is a BINDTODEVICE socket:

                                        if
(setsockopt(servers[n].getSocketFD(), SOL_SOCKET,
                                            SO_BINDTODEVICE, (char
*)&interface, sizeof (interface)) < 0) {

So is this the right behavior for a socket that is bound to an
interface which has no IP address nor cable plugged into it's RJ45
jack, should this particular socket get UDP Broadcast message that
eminate from the different NIC within the system?

 
 
 

Q: UDP Broadcast, Sockets, Dual NICs, Single Cable

Post by Richard Kettlewel » Sat, 18 Dec 2010 08:31:44



> Yes, it is a BINDTODEVICE socket:

>                                         if
> (setsockopt(servers[n].getSocketFD(), SOL_SOCKET,
>                                             SO_BINDTODEVICE, (char
> *)&interface, sizeof (interface)) < 0) {

> So is this the right behavior for a socket that is bound to an
> interface which has no IP address nor cable plugged into it's RJ45
> jack, should this particular socket get UDP Broadcast message that
> eminate from the different NIC within the system?

It does sound wrong to me.

After some experimentation, I can't get an unconfigured interface to
return any packets at all, i.e. I can't reproduce the behavior you
describe.

Just a thought: can you verify that you're definitely passing a
nontrivial interface name?  (strace -esetsockopt may help.)  If you're
accidentally passing a null string then setsockopt() will succeed but
you won't get the device-specific bind.

My somewhat hacky test code:
http://www.chiark.greenend.org.uk/ucgi/~richardk/git/udptest.git/

--
http://www.greenend.org.uk/rjk/

 
 
 

Q: UDP Broadcast, Sockets, Dual NICs, Single Cable

Post by Richard Kettlewel » Sat, 18 Dec 2010 08:37:45



> Just a thought: can you verify that you're definitely passing a
> nontrivial interface name?  (strace -esetsockopt may help.)  If you're

"strace -etrace=setsockopt", rather.

Quote:> accidentally passing a null string then setsockopt() will succeed but
> you won't get the device-specific bind.

--
http://www.greenend.org.uk/rjk/
 
 
 

1. Dual NIC or Single NIC for cable modem connection?

Hello,

I'm going to have cable modem installed in my home private network.
Right now, I'm using PPP dialup to serve the rest of the machine at home
by IP Masq. I want to know what is the best way (in terms of security)
to go for the configuration 'cos I heard that IP Aliasing can be used
without installing extra network adapter in the server. On the other
side, people have opinion that it would be security problem if do it in
single NIC... Please feel free to tell your opinion. Thanks.

Kelvin

  vcard.vcf
< 1K Download

2. What files are needed to patch from 1.1.18 to 1.1.49

3. UDP server: single socket or multiple socket?

4. SunSoft Vis. WorkShop for C++ - Help please.

5. udp broadcast on more than one nic's

6. sendmail program

7. Socket Programming - Broadcasting with UDP

8. TNT 2 F86free Config file

9. Broadcast UDP Datagram socket

10. UDP sockets- broadcast function on ethernet

11. Broadcast UDP Datagram Socket

12. broadcast & udp-socket

13. raw sockets and UDP broadcast : a strange phenomenon