Skip to contentSkip to conversation

af_packet: Teach to listen for multiple unicast addresses.

PATCH In review Eric W. Biederman 2 participants 2 messages May 20, 2009 – May 21, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 af_packet: Teach to listen for multiple unicast addresses.

The the PACKET_ADD_MEMBERSHIP and the PACKET_DROP_MEMBERSHIP setsockopt calls for af_packet already has all of the infrastructure needed to subscribe to multiple mac addresses. All that is missing is a flag to say that the address we want to listen on is a unicast address.

So introduce PACKET_MR_UNICAST and wire it up to dev_unicast_add and dev_unicast_delete.

Additionally I noticed that errors from dev_mc_add were not propagated from packet_dev_mc so fix that.

---
 include/linux/if_packet.h |    1 +
 net/packet/af_packet.c    |   10 ++++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
include/linux/if_packet.h +1 -0
index 18db066..ed26d4f 100644
@@ -135,5 +135,6 @@ struct packet_mreq
 #define PACKET_MR_MULTICAST	0
 #define PACKET_MR_PROMISC	1
 #define PACKET_MR_ALLMULTI	2
+#define PACKET_MR_UNICAST	3
 
 #endif
net/packet/af_packet.c +8 -2
index 1fc4a78..2abaf83 100644
@@ -1254,9 +1254,9 @@ static int packet_dev_mc(struct net_device *dev, struct packet_mclist *i,
 	switch (i->type) {
 	case PACKET_MR_MULTICAST:
 		if (what > 0)
-			dev_mc_add(dev, i->addr, i->alen, 0);
+			return dev_mc_add(dev, i->addr, i->alen, 0);
 		else
-			dev_mc_delete(dev, i->addr, i->alen, 0);
+			return dev_mc_delete(dev, i->addr, i->alen, 0);
 		break;
 	case PACKET_MR_PROMISC:
 		return dev_set_promiscuity(dev, what);
@@ -1264,6 +1264,12 @@ static int packet_dev_mc(struct net_device *dev, struct packet_mclist *i,
 	case PACKET_MR_ALLMULTI:
 		return dev_set_allmulti(dev, what);
 		break;
+	case PACKET_MR_UNICAST:
+		if (what > 0)
+			return dev_unicast_add(dev, i->addr, i->alen);
+		else
+			return dev_unicast_delete(dev, i->addr, i->alen);
+		break;
 	default:;
 	}
 	return 0;
Signature · 1 line
1.6.0.6
maintainer
#1 lore raw

From: [email protected] (Eric W. Biederman)
Date: Tue, 19 May 2009 21:27:17 -0700

Quoted 6 lines

The the PACKET_ADD_MEMBERSHIP and the PACKET_DROP_MEMBERSHIP setsockopt calls for af_packet already has all of the infrastructure needed to subscribe to multiple mac addresses. All that is missing is a flag to say that the address we want to listen on is a unicast address.

Quoted 7 lines

So introduce PACKET_MR_UNICAST and wire it up to dev_unicast_add and dev_unicast_delete.

Additionally I noticed that errors from dev_mc_add were not propagated from packet_dev_mc so fix that.

Looks good, applied to net-next-2.6