Bug 13856 - sk_bound_dev_if should be set for a socket when using IP_MULITCAST_IF or IP_ADD_MEMBERSHIO
Summary: sk_bound_dev_if should be set for a socket when using IP_MULITCAST_IF or IP_A...
Status: CLOSED OBSOLETE
Alias: None
Product: Networking
Classification: Unclassified
Component: IPV4 (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: Stephen Hemminger
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-28 03:42 UTC by Ralph Dale-Jones
Modified: 2012-06-13 14:26 UTC (History)
2 users (show)

See Also:
Kernel Version: 2.6.27.7
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description Ralph Dale-Jones 2009-07-28 03:42:37 UTC
Currently there is no way to tell which interface a multicast packet arrived on except by using a raw socket and issuing the SO_BINDTODEVICE option which forces the sk_bound_dev_if for the socket to be set.  

Consider a multi-homed system where a service needs to listen for multicast SSDP messages on a number of interfaces.  The system needs to know which interface a search message came in on in order to respond with the correct URL.  

The service needs to join the multicast group on all interfaces.  It must bind on INADDR_ANY and then issue the IP_ADD_MEMBERSHIP call.  

1. If it uses one socket and joins on all interfaces it will receive mulitcast from all interfaces but cannot tell which interface the message came in on

2. It it uses a socket per interface each bound on INADDR_ANY and issues IP_MULTICAST_IF.  In this case any mulitcast socket, no matter what interface, will be forwarded to each socket because sk_bound_dev_if was not set (i.e. 0) - see net/ipv4/udp.c [ udp_v4_mcast_next ]

Suggested solution is to set sk_bound_dev_if when IP_MULTICAST_IF is issued.
Comment 1 Andrew Morton 2009-07-29 19:52:06 UTC
(switched to email.  Please respond via emailed reply-to-all, not via the
bugzilla web interface).

On Tue, 28 Jul 2009 03:42:38 GMT
bugzilla-daemon@bugzilla.kernel.org wrote:

> http://bugzilla.kernel.org/show_bug.cgi?id=13856
> 
>            Summary: sk_bound_dev_if should be set for a socket when using
>                     IP_MULITCAST_IF or IP_ADD_MEMBERSHIO
>            Product: Networking
>            Version: 2.5
>     Kernel Version: 2.6.27.7
>           Platform: All
>         OS/Version: Linux
>               Tree: Mainline
>             Status: NEW
>           Severity: normal
>           Priority: P1
>          Component: IPV4
>         AssignedTo: shemminger@linux-foundation.org
>         ReportedBy: manlidj@hotmail.com
>         Regression: No
> 
> 
> Currently there is no way to tell which interface a multicast packet arrived
> on
> except by using a raw socket and issuing the SO_BINDTODEVICE option which
> forces the sk_bound_dev_if for the socket to be set.  
> 
> Consider a multi-homed system where a service needs to listen for multicast
> SSDP messages on a number of interfaces.  The system needs to know which
> interface a search message came in on in order to respond with the correct
> URL. 
> 
> The service needs to join the multicast group on all interfaces.  It must
> bind
> on INADDR_ANY and then issue the IP_ADD_MEMBERSHIP call.  
> 
> 1. If it uses one socket and joins on all interfaces it will receive
> mulitcast
> from all interfaces but cannot tell which interface the message came in on
> 
> 2. It it uses a socket per interface each bound on INADDR_ANY and issues
> IP_MULTICAST_IF.  In this case any mulitcast socket, no matter what
> interface,
> will be forwarded to each socket because sk_bound_dev_if was not set (i.e. 0)
> -
> see net/ipv4/udp.c [ udp_v4_mcast_next ]
> 
> Suggested solution is to set sk_bound_dev_if when IP_MULTICAST_IF is issued.
>
Comment 2 Ralph Dale-Jones 2009-07-29 23:19:31 UTC
There is a way round this - to use the PKTINFO option which will return the interface id. of an incoming message.

However - I still think that this should be achievable through the IP_MULTICAST_IF or ADD_MEMBERSHIP option.

If Java is the development language PKTINFO can only be accessed via JNI.
Comment 3 John Dykstra 2009-07-30 00:52:01 UTC
>         ReportedBy: manlidj@hotmail.com

> > Currently there is no way to tell which interface a multicast packet
> arrived on
> > except by using a raw socket and issuing the SO_BINDTODEVICE option which
> > forces the sk_bound_dev_if for the socket to be set.  

I thought the IP_PKTINFO cmsg was the usual way to do this.

--
John
Comment 4 Ralph Dale-Jones 2009-07-30 01:31:11 UTC
Agree - but it is a pitfall for Application implementers.

For example:

Application A joins Mcast group 1 on interface 1 and is happily receiving traffic 

- then Application B joins the same group on a different interface which means that application A then starts receiving B's multicast as well.

I think ADD_MEMBERSHIP should specify the interface.

Note You need to log in before you can comment on or make changes to this bug.