shithub: riscv

Download patch

ref: 27ca3c1b0c109cb15fb3aa2baa152eaf9dc2eba3
parent: c78384333ec9f0b819ba3a1fa508b89576a6eff6
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Nov 20 11:47:04 EST 2022

snoopy: fix ipv6 option header parsing, add MLD messages to icmp6

--- a/sys/src/cmd/ip/snoopy/icmp6.c
+++ b/sys/src/cmd/ip/snoopy/icmp6.c
@@ -49,6 +49,9 @@
 	AddrMaskReply   = 18,
 	EchoRequestV6	= 128,
 	EchoReplyV6	= 129,
+	McastQuery	= 130,
+	McastReport	= 131,
+	McastDone	= 132,
 	RouterSolicit	= 133,
 	RouterAdvert	= 134,
 	NbrSolicit	= 135,
@@ -84,6 +87,9 @@
 [AddrMaskReply]		"AddrMaskReply",
 [EchoRequestV6]		"EchoRequestV6",
 [EchoReplyV6]		"EchoReplyV6",
+[McastQuery]		"McastQuery",
+[McastReport]		"McastReport",
+[McastDone]		"McastDone",
 [RouterSolicit]		"RouterSolicit",
 [RouterAdvert]		"RouterAdvert",
 [NbrSolicit]		"NbrSolicit",
@@ -421,6 +427,12 @@
 	case InfoReply:
 		break;
 
+	case McastQuery:
+	case McastReport:
+	case McastDone:
+		m->ps += 20;
+		p = seprint(p, e, " delay=%d unused=%.4x mcast=%I", NetS(a), NetS(a+2), a+4);
+		break;
 	}
 	m->p = p;
 	return 0;
--- a/sys/src/cmd/ip/snoopy/ip6.c
+++ b/sys/src/cmd/ip/snoopy/ip6.c
@@ -161,28 +161,28 @@
 }
 
 static int
-v6hdrlen(Hdr *h)
+v6hdrlen(Hdr *h, int *nexthdr)
 {
 	int plen, len = IP6HDR;
 	int pktlen = IP6HDR + NetS(h->length);
-	uchar nexthdr = h->proto;
 	uchar *pkt = (uchar*) h;
 
 	pkt += len;
 	plen = len;
 
-	while (nexthdr == HBH_HDR || nexthdr == ROUT_HDR ||
-	    nexthdr == FRAG_HDR || nexthdr == DEST_HDR) {
-		if (nexthdr == FRAG_HDR)
+	*nexthdr = h->proto;
+	while (*nexthdr == HBH_HDR || *nexthdr == ROUT_HDR ||
+	    *nexthdr == FRAG_HDR || *nexthdr == DEST_HDR) {
+		if (*nexthdr == FRAG_HDR)
 			len = FRAG_HSZ;
 		else
-			len = ((int)*(pkt+1) + 1) * 8;
+			len = ((int)pkt[1] + 1) * 8;
 
 		if (plen + len > pktlen)
 			return -1;
 
+		*nexthdr = *pkt;
 		pkt += len;
-		nexthdr = *pkt;
 		plen += len;
 	}
 	return plen;
@@ -192,7 +192,7 @@
 p_filter(Filter *f, Msg *m)
 {
 	Hdr *h;
-	int hlen;
+	int hlen, proto;
 
 	if(m->pe - m->ps < IP6HDR)
 		return 0;
@@ -199,7 +199,7 @@
 
 	h = (Hdr*)m->ps;
 
-	if ((hlen = v6hdrlen(h)) < 0)
+	if ((hlen = v6hdrlen(h, &proto)) < 0)
 		return 0;
 	else
 		m->ps += hlen;
@@ -212,7 +212,7 @@
 		return memcmp(h->src, f->a, IPaddrlen) == 0 ||
 			memcmp(h->dst, f->a, IPaddrlen) == 0;
 	case Ot:
-		return h->proto == f->ulv;
+		return proto == f->ulv;
 	}
 	return 0;
 }
@@ -224,7 +224,7 @@
 	uchar *pkt = m->ps;
 	Hdr *h = (Hdr *)pkt;
 	int pktlen = IP6HDR + NetS(h->length);
-	uchar nexthdr = h->proto;
+	int nexthdr = h->proto;
 
 	pkt += len;
 	plen = len;
@@ -253,11 +253,13 @@
 			m->pr = &dump;
 			return -1;
 		}
+		nexthdr = *pkt;
 		plen += len;
 		pkt += len;
-		nexthdr = *pkt;
 	}
 
+	demux(p_mux, nexthdr, nexthdr, m, &dump);
+
 	m->ps = pkt;
 	return 1;
 }
@@ -271,8 +273,6 @@
 	if(m->pe - m->ps < IP6HDR)
 		return -1;
 	h = (Hdr*)m->ps;
-
-	demux(p_mux, h->proto, h->proto, m, &dump);
 
 	/* truncate the message if there's extra */
 	len = NetS(h->length) + IP6HDR;