PERFORCE change 114253 for review

Paolo Pisati piso at FreeBSD.org
Thu Feb 8 18:17:05 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=114253

Change 114253 by piso at piso_newluxor on 2007/02/08 18:16:27

	Convert the cu_seeme module to (almost)use mbuf.

Affected files ...

.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_cuseeme.c#16 edit

Differences ...

==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_cuseeme.c#16 (text+ko) ====

@@ -187,7 +187,9 @@
 		struct cu_header *cu;
 		struct alias_link *cu_lnk;
 
-		// XXX broken
+		PULLUP_SIZE(pip, ptr, (pip->ip_hl << 2) + ntohs(ud->uh_ulen) + 
+		    sizeof(struct cu_header));
+		ud = ip_next(pip);
 		cu = udp_next(ud);
 		if (cu->addr)
 			cu->addr = (u_int32_t) GetAliasAddress(lnk).s_addr;
@@ -212,29 +214,56 @@
 	struct oc_header *oc;
 	struct client_info *ci;
 	char *end;
-	int i;
+	int i, client_count, ci_count, s;
+#ifdef _KERNEL
+	int off;
+	struct mbuf *m;
+#endif
 
 	(void)la;
-	PULLUP_UDPHDR(pip, ptr);
+	PULLUP_IPHDR(pip, ptr);
+	s = (pip->ip_hl << 2) + sizeof(struct udphdr) + 
+	    sizeof(struct oc_header) + sizeof(struct client_info);
+	PULLUP_SIZE(pip, ptr, s);
 	if (pip == NULL)
 		return;
 	alias_addr.s_addr = pip->ip_dst.s_addr;
 	ud = ip_next(pip);
-	// XXX broken
 	cu = udp_next(ud);
 	oc = (struct oc_header *)(cu + 1);
 	ci = (struct client_info *)(oc + 1);
 	end = (char *)ud + ntohs(ud->uh_ulen);
+	client_count = oc->client_count;
+	ci_count = (ntohs(ud->uh_ulen) - sizeof(struct udphdr) - 
+	    sizeof(struct cu_header) - sizeof(struct oc_header)) / 
+	    sizeof(struct client_info);
 
 	if ((char *)oc <= end) {
 		if (cu->dest_addr)
 			cu->dest_addr = (u_int32_t) original_addr.s_addr;
 		if (ntohs(cu->data_type) == 101)
 			/* Find and change our address */
-			for (i = 0; (char *)(ci + 1) <= end && i < oc->client_count; i++, ci++)
+			for (i = 0; i < ci_count && i < client_count; i++) {
+#ifdef _KERNEL
+				m = m_getptr(*ptr, s, &off);
+				// XXX to avoid crossing mbuf boundary with
+				// XXX off + sizeof(struct client_info) i should
+				// XXX m_split(m, off, M_TRYWAIT) first and
+				// XXX m_pullup(m, sizeof(struct client_info)),
+				// XXX and m_cat() later but I'm worried about 
+				// XXX performance...
+				m = m_pullup(m, off + sizeof(struct client_info));
+				s += sizeof(struct client_info);
+				ci = mtod(m, struct client_info *);
+				ci = (struct client_info *)&(((char *)ci)[off]);
+#endif
 				if (ci->address == (u_int32_t) alias_addr.s_addr) {
 					ci->address = (u_int32_t) original_addr.s_addr;
 					break;
 				}
+#ifndef _KERNEL
+				ci++;
+#endif
+			}
 	}
 }


More information about the p4-projects mailing list