Skip to contentSkip to conversation

multicast mroute

PATCH In review Riccardo Scarsi 2 participants 2 messages Jun 13, 2004 – Jun 15, 2004

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

PATCH 1/1 multicast mroute

This patch permits to add a multicast routing rule in the kernel that specify an entire subnet for the multicast packets and not anly a specific source address.

include/linux/mroute.h +4 -0
@@ -25,6 +25,7 @@
 #define MRT_VERSION	(MRT_BASE+6)	/* Get the kernel multicast version	*/
 #define MRT_ASSERT	(MRT_BASE+7)	/* Activate PIM assert mode		*/
 #define MRT_PIM		(MRT_BASE+8)	/* enable PIM code	*/
+#define MRT_ADD_MFC_NM	(MRT_BASE+9)	/* Add a multicast forwarding entry	*/
 
 #define SIOCGETVIFCNT	SIOCPROTOPRIVATE	/* IP protocol privates */
 #define SIOCGETSGCNT	(SIOCPROTOPRIVATE+1)
@@ -78,6 +79,8 @@
 	unsigned int mfcc_byte_cnt;
 	unsigned int mfcc_wrong_if;
 	int	     mfcc_expire;
+	struct in_addr mfcc_origin_netmask;	/* Netmask of the origin 
+						of mcast	*/
 };
 
 /* 
@@ -169,6 +172,7 @@
 			unsigned char ttls[MAXVIFS];	/* TTL thresholds		*/
 		} res;
 	} mfc_un;
+	__u32 mfc_origin_netmask;			/* Netmask of source of packet 		*/
 };
 
 #define MFC_STATIC		1
net/ipv4/ipmr.c +16 -1
@@ -450,6 +450,18 @@
 	return 0;
 }
 
+static struct mfc_cache *ipmr_cache_find_netmask(__u32 origin, __u32 mcastgrp)
+{
+	int line=MFC_HASH(mcastgrp,origin);
+	struct mfc_cache *c;
+
+	for (c=mfc_cache_array[line]; c; c = c->next) {
+		if ((c->mfc_origin & c->mfc_origin_netmask)==(origin & c->mfc_origin_netmask) && c->mfc_mcastgrp==mcastgrp)
+			break;
+	}
+	return c;
+}
+
 static struct mfc_cache *ipmr_cache_find(__u32 origin, __u32 mcastgrp)
 {
 	int line=MFC_HASH(mcastgrp,origin);
@@ -901,6 +913,7 @@
 		 *	Manipulate the forwarding caches. These live
 		 *	in a sort of kernel/user symbiosis.
 		 */
+		case MRT_ADD_MFC_NM:
 		case MRT_ADD_MFC:
 		case MRT_DEL_MFC:
 			if(optlen!=sizeof(mfc))
@@ -908,6 +921,8 @@
 			if (copy_from_user(&mfc,optval, sizeof(mfc)))
 				return -EFAULT;
 			rtnl_lock();
+			if (optname==MRT_ADD_MFC)
+				mfc.mfcc_origin_netmask.s_addr = 0xffffffff;
 			if (optname==MRT_DEL_MFC)
 				ret = ipmr_mfc_delete(&mfc);
 			else
@@ -1336,7 +1351,7 @@
 	}
 
 	read_lock(&mrt_lock);
-	cache = ipmr_cache_find(skb->nh.iph->saddr, skb->nh.iph->daddr);
+	cache = ipmr_cache_find_netmask(skb->nh.iph->saddr, skb->nh.iph->daddr);
 
 	/*
 	 *	No usable cache entry
#1 lore raw

You can't just blindly change the size of a userland exported structure. This will break existing applications.