Unexpected multicast IPv4 socket behavior

Fredrik Lindberg fli at shapeshifter.se
Sat Jan 12 03:23:38 PST 2008


Hi

I find the following socket behavior a bit unexpected. Multicast from
an IPv4 socket (with IP_MULTICAST_IF set) with its source address bound
to INADDR_ANY only works if there is a default route defined, otherwise
send() returns ENETUNREACH.

Default route set, src INADDR_ANY : Works
Default route set, src bind() to interface address : Works
No default route, src INADDR_ANY : Returns ENETUNREACH
No default route, src bind() to interface address : Works

In all cases IP_MULTICAST_IF was set to the outgoing interface and
IP_ADD_MEMBERSHIP was properly called. IGMP membership reports
were seen on the link in all cases.

I believe the cause of this (unless this is the expected behavior?)
is in in_pcbconnect_setup() (netinet/in_pcb.c) [1].
The check for a multicast destination address is run after the attempt
to get the source address by finding a directly connected interface,
this check also returns ENETUNREACH if it fails (which it does for the
destination 224.0.0.0/24 if no default route is set).

Moving the multicast check before the directly connected check solves
this (or any other combinations that makes sure that the
IN_MULTICAST() check is executed).

I've attached a test case and a patch to illustrate it, comments?


Fredrik Lindberg



[1] http://fxr.watson.org/fxr/source/netinet/in_pcb.c#L610


-------------- next part --------------
A non-text attachment was scrubbed...
Name: in_pcb.c-multicast.patch
Type: text/x-patch
Size: 1820 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-net/attachments/20080112/c3730b9f/in_pcb.c-multicast.bin


More information about the freebsd-net mailing list