PATCH for Multicast bug in RAW IP sockets 2.4.0

PATCH for Multicast bug in RAW IP sockets 2.4.0

Post by Mark Clayto » Sat, 03 Mar 2001 22:10:04

In ipv4 a call to the setsockopt() function with the optname set to
IP_ADD_MEMBERSHIP and a raw ip socket adds the socket to the multicast
group specified by the user. As a result the tcpip stack code does the
ip_setsockopt(_,_,IP_ADD_MEMBERSHIP,_,_) calls ip_mc_join_group(sock,_)
function, which adds a multicast entry to the sock->protinfo.af_inet.mc_list
and then adds a multicast entry to the bound device (if any) with a call
to the ip_mc_inc_group() function.

When remote multicast packets that belong to the multicast group we just
joined are received, the routing code recognizes the packets as multicast
packet going to a local receiver, but the __raw_v4_lookup() function only
examines the main sock address (sock->rcv_saddr) and totally forgets that
this raw sock can a member of multiple multicast groups.

The following patch fixes the problem:

---[ PATCH STARTS ]--------------------------------------------------------

--- linux-2.4.2/net/ipv4/raw.c  Fri Feb  9 14:29:44 2001

 #include <linux/inet.h>
 #include <linux/netdevice.h>
 #include <linux/mroute.h>
+#include <linux/igmp.h>
 #include <net/ip.h>
 #include <net/protocol.h>

                   !(s->rcv_saddr && s->rcv_saddr != laddr)       &&
                   !(s->bound_dev_if && s->bound_dev_if != dif))
                        break; /* gotcha */
+               if (LOCAL_MCAST(laddr)) {
+                   struct ip_mc_socklist *iml;
+                   struct ip_mreqn *imr;
+                   for (iml=sk->protinfo.af_inet.mc_list; iml; iml=iml->next) {
+                     imr = &(iml->multi);
+                     if ((imr->imr_multiaddr.s_addr == laddr) && !(imr->imr_ifindex && imr->imr_ifindex != dif))
+                               return s;
+                   }
+               }
        return s;

---[ PATCH ENDS ]-----------------------------------------------------------

Note: the same problem exists for UDP sockets also.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at
Please read the FAQ at


1. Linux Raw Socket for IP Multicast


I am trying to implement an application, wherein the application would
like to receive any-and-all packets sent to a particular multicast group
I am using Linux (2.4) Redhat.  I want the application to receive UDP
packets multicast to the address, as well as PGM packets, as well as
any packet (with any other protocol) over IP.  Also, in case of UDP, it
preferable that the application do not have apriori knowledge about the
UDP port number.

Unfortunately, Linux does not allow opening a raw socket for proto =

Any ideas as to how I can do this?

Ideally, I would like to do this without causing too much stress to the
kernel (i.e. it would be preferrable, not to use command-line ipchain

Also, the multicast-address is dynamic, i.e. application gets this
address using
some other application level signalling protocol, so I cannot use any
linux command-line command.

I'll take reply-posts through the newsgroup.

Thanks a bunch!
 -- arun

2. MOZART Sound Card: Failed attempts with /dev/mixer

3. raw IP and raw ICMP socket???

4. DNS/BIND/NAMED setup question

5. Sending multicast packet on a raw socket

6. sharing internet connection arund the house

7. multicast using tcp/ip sockets

8. How to duplicate packets changing MAC address...

9. Bug in sendto() causes OOPS when using RAW sockets

10. Multicast using socket bound to IP looback address

11. IP Checksum in Raw Sockets

12. Incorrect IP header data in RAW Sockets

13. IP_HDRINCL Option for raw IP sockets