PERFORCE change 114456 for review

Paolo Pisati piso at FreeBSD.org
Tue Feb 13 16:16:21 UTC 2007


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

Change 114456 by piso at piso_newluxor on 2007/02/13 16:15:24

	Make irc module (almost) groks mbuf: unfortunately, using a normal mbuf
	was too much of a pain with the current code, so i had to resort to a
	contiguous buffer of memory.

Affected files ...

.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_irc.c#19 edit

Differences ...

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

@@ -170,6 +170,9 @@
 	struct ip *pip;
 	struct tcphdr *tc;
 	int i;			/* Iterator through the source */
+#ifdef _KERNEL
+	char mpkt[65536];
+#endif
 
 /* Calculate data length of TCP packet */
 	PULLUP_TCPHDR(pip, ptr);
@@ -188,9 +191,34 @@
 		return;
 
 /* Place string pointer at beginning of data */
-	// XXX broken
+#ifdef _KERNEL
+	/* 	   
+	 * XXX first we copy the entire mbuf chain content (minus ip+tcp hdr)
+	 * into a contiguos buffer of memory and later, when we've finished
+	 * to operate on the buffer, we copy back buffer's content into
+	 * the mbuf.
+	 * In case the copy operations are too expensive, we could avoid
+	 * one using the mbuf as the contiguos buffer of memory:
+	 *
+	 * o pkt < MHLEN:       pullup the entire pkt in the mbuf data sect
+	 * o MHLEN < pkt < 2k:  use a normal mbuf cluster
+	 * o 2k < pkt < 4k:     use a 4k mbuf cluster (jumbo)
+	 * o 4k < pkt < 9k:     use a 9k mbuf cluster (jumbo9)
+	 * o 9k < pkt < 16k:    use a 16k mbuf cluster (jumbo16)
+	 * o pkt > 16k:         use mpkt buffer (worst case)
+	 *
+	 * WATCH OUT: pkt could grow, so beware of boundaries in case
+	 * an mbuf/mbuf cluster is used, check maxsize.
+	 */
+
+	// XXX so far only the worst case is implemented...
+	m_copydata(*ptr, hlen, m_length(*ptr, NULL), mpkt);
+	sptr = mpkt;
+	maxsize = 65536; /* size of mpkt */
+#else
 	sptr = (char *)pip;
 	sptr += hlen;
+#endif
 	maxsize -= hlen;	/* We're interested in maximum size of
 				 * data, not packet */
 
@@ -433,6 +461,9 @@
 lPACKET_DONE:
 		iCopy = iCopy > maxsize - copyat ? maxsize - copyat : iCopy;
 		memcpy(sptr + copyat, newpacket, iCopy);
+#ifdef _KERNEL
+		m_copyback(*ptr, hlen, iCopy + copyat, sptr);
+#endif
 
 /* Save information regarding modified seq and ack numbers */
 		{


More information about the p4-projects mailing list