git: 9front

Download patch

ref: 35f9e78c92246c3538f8da030067ff346f0375d8
parent: 8101cf6b604f3cfca7a98b7efdaf8b3182281e00
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue May 28 14:16:44 EDT 2024

devip: don't send and ignore MLD messages for invalid multicast groups

RFC2710 states that MLD messages should never
be sent for scope 0 and 1 mcast addresses
as well as FF02::1.

--- a/sys/src/9/ip/igmp.c
+++ b/sys/src/9/ip/igmp.c
@@ -128,6 +128,25 @@
 	ipoput4(f, bp, nil, 1, DFLTTOS, nil);	/* TTL of 1 */
 }
 
+static int
+mldvalidgroup(uchar *group)
+{
+	if(ipismulticast(group) != V6)
+		return 0;
+
+	/*
+	 * MLD messages are never sent for multicast addresses
+	 * whos scope is 0 (reserved) or 1 (node-local).
+	 * MLD messages ARE sent for multicast addresses whose
+	 * scope is 2 (link-local) ... except all-nodes address.
+	 */
+	if((group[1] & 0xF) < Link_local_scop
+	|| ipcmp(group, v6allnodesL) == 0)
+		return 0;
+
+	return 1;
+}
+
 static void
 mldsendreport(Fs *f, uchar *src, uchar *dst, uchar *group, int done)
 {
@@ -137,6 +156,9 @@
 	if(!islinklocal(src))
 		return;
 
+	if(!mldvalidgroup(group))
+		return;
+
 	bp = allocb(sizeof(mldhbhopt)+MLDPKTSZ);
 	bp->wp += sizeof(mldhbhopt)+MLDPKTSZ;
 	bp->rp += sizeof(mldhbhopt);
@@ -358,8 +380,7 @@
 	hnputs(p->ploadlen, MLDPKTSZ-IP6HDR);
 	if(ptclcsum(bp, 0, MLDPKTSZ))
 		goto error;
-
-	if(ipcmp(p->group, IPnoaddr) != 0 && ipismulticast(p->group) != V6)
+	if(ipcmp(p->group, IPnoaddr) != 0 && !mldvalidgroup(p->group))
 		goto error;
 
 	switch(p->type){
--