Subject: SIOCADDMULTI for unicast broken

From: jamal <[email-masked]>
Date: Fri, 3 Jan 2003 16:46:40 -0500 (EST)

Some programs require ability to accept packets destined to certain
MAC addresses (in addition to their own).
Example Jerome Ettienes vrrpd (http://w3.arobas.net/~jetienne/vrrpd/)

The trick is to add unicast addresses via SIOCADDMULTI and accept those
packets when they make their way up the stack.
I think this used to work, no? Donald, any history/comments behind
this?
Patch attahced, not very well tested but looks safe.

cheers,
jamal

--- net/ethernet/eth.c	2003/01/03 18:20:49	1.1
+++ net/ethernet/eth.c	2003/01/03 18:22:05
@@ -148,6 +148,30 @@
 	return 0;
 }
 
+void check_mcast_list(struct sk_buff *skb, struct net_device *dev)
+{
+	struct dev_mc_list *dmi;
+	struct ethhdr *eth;
+			        
+	if (skb->pkt_type != PACKET_OTHERHOST)
+		return;
+
+	eth = skb->mac.ethernet;
+
+	/* may not be necessary to bh_lock - fix later - JHS */
+	spin_lock_bh(&dev->xmit_lock);
+
+	for (dmi = dev->mc_list; dmi != NULL; dmi = dmi->next) {
+		if (memcmp(dmi->dmi_addr, eth->h_dest, dev->addr_len) == 0
+		    && dmi->dmi_addrlen == dev->addr_len) { 
+			skb->pkt_type = PACKET_HOST;
+				break;
+		}
+	}
+
+	spin_unlock_bh(&dev->xmit_lock);
+}
+
 
 /*
  *	Determine the packet's protocol ID. The rule here is that we 
@@ -182,8 +206,14 @@
 	 
 	else if(1 /*dev->flags&IFF_PROMISC*/)
 	{
-		if(memcmp(eth->h_dest,dev->dev_addr, ETH_ALEN))
-			skb->pkt_type=PACKET_OTHERHOST;
+		if(memcmp(eth->h_dest,dev->dev_addr, ETH_ALEN)) {
+			skb->pkt_type = PACKET_OTHERHOST;
+			/* we override PACKET_OTHERHOST if MAC appears
+			 * in our mcast list allows to have several 
+			 * allowed MACs for receives added via 
+			 * SIOCADDMULTI on the device*/
+			check_mcast_list(skb,dev);
+		}
 	}
 	
 	if (ntohs(eth->h_proto) >= 1536)