PERFORCE change 114561 for review

Paolo Pisati piso at FreeBSD.org
Thu Feb 15 15:33:37 UTC 2007


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

Change 114561 by piso at piso_newluxor on 2007/02/15 15:33:28

	o Teach mbuf to skinny.
	o Axe an useless var.

Affected files ...

.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_skinny.c#13 edit

Differences ...

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

@@ -63,7 +63,7 @@
 	if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL)
 		return (-1);
 	if (la->skinnyPort != 0 && (ntohs(*ah->sport) == la->skinnyPort ||
-				    ntohs(*ah->dport) == la->skinnyPort))
+	    ntohs(*ah->dport) == la->skinnyPort))
 		return (0);
 	return (-1);
 }
@@ -305,10 +305,13 @@
 	size_t hlen, tlen, dlen;
 	struct ip *pip;
 	struct tcphdr *tc;
-	u_int32_t msgId, t, len, lip;
+	u_int32_t msgId, len, lip;
 	struct skinny_header *sd;
 	size_t orig_len, skinny_hdr_len = sizeof(struct skinny_header);
 	ConvDirection direction;
+#ifdef _KERNEL
+	struct mbuf *m, *tmp_m;
+#endif
 
 	PULLUP_TCPHDR(pip, ptr);
 	if (pip == NULL)
@@ -318,8 +321,16 @@
 	tlen = ntohs(pip->ip_len);
 	dlen = tlen - hlen;
 
-	// XXX broken
+#ifdef _KERNEL
+	m = m_split(*ptr, hlen, M_TRYWAIT);
+	*ptr = m_pullup(*ptr, hlen);
+	pip = mtod(*ptr, struct ip *);
+	tc = (struct tcphdr *)ip_next(pip);
+	m = m_pullup(m, sizeof(struct skinny_header));
+	sd = mtod(m, struct skinny_header *);
+#else
 	sd = (struct skinny_header *)tcp_next(tc);
+#endif
 
 	/*
 	 * XXX This direction is reserved for future use.  I still need to
@@ -335,7 +346,7 @@
 		fprintf(stderr,
 		    "PacketAlias/Skinny: Invalid port number, not a Skinny packet\n");
 #endif
-		return;
+		goto getout;
 	}
 
 	orig_len = dlen;
@@ -349,14 +360,23 @@
 	while (dlen >= skinny_hdr_len) {
 		len = (sd->len);
 		msgId = (sd->msgId);
-		t = len;
 
-		if (t > orig_len || t > dlen) {
+#ifdef _KERNEL
+		/* 
+		 * After this pullup, we'll have a contiguos Skinny Packet 
+		 * Header + len of data.
+		 */
+		m = m_pullup(m, skinny_hdr_len + len);
+		if (m == NULL)
+			goto getout;
+		sd = mtod(m, struct skinny_header *);
+#endif
+		if (len > orig_len || len > dlen) {
 #ifdef LIBALIAS_DEBUG
 			fprintf(stderr,
 			    "PacketAlias/Skinny: Not a skinny packet, invalid length \n");
 #endif
-			return;
+			goto getout;
 		}
 		switch (msgId) {
 		case REG_MSG: {
@@ -367,7 +387,7 @@
 				fprintf(stderr,
 				    "PacketAlias/Skinny: Not a skinny packet, bad registration message\n");
 #endif
-				return;
+				goto getout;
 			}
 			reg_mesg = (struct RegisterMessage *)&sd->msgId;
 #ifdef LIBALIAS_DEBUG
@@ -385,7 +405,7 @@
 				fprintf(stderr,
 				    "PacketAlias/Skinny: Not a skinny packet, port message\n");
 #endif
-				return;
+				goto getout;
 			}
 #ifdef LIBALIAS_DEBUG
 			fprintf(stderr,
@@ -403,7 +423,7 @@
 				fprintf(stderr,
 				    "PacketAlias/Skinny: Not a skinny packet, packet,OpnRcvChnAckMsg\n");
 #endif
-				return;
+				goto getout;
 			}
 #ifdef LIBALIAS_DEBUG
 			fprintf(stderr,
@@ -421,7 +441,7 @@
 				fprintf(stderr,
 				    "PacketAlias/Skinny: Not a skinny packet,StartMediaTx Message\n");
 #endif
-				return;
+				goto getout;
 			}
 #ifdef LIBALIAS_DEBUG
 			fprintf(stderr,
@@ -436,6 +456,19 @@
 		}
 		/* Place the pointer at the next message in the packet. */
 		dlen -= len + (skinny_hdr_len - sizeof(msgId));
+#ifdef _KERNEL
+		/* Trim from the beginning of mbuf the data we already used */
+		tmp_m = m_split(m, skinny_hdr_len + len, M_TRYWAIT);
+		m_cat(*ptr, m);
+		m = tmp_m;
+		sd = mtod(m, struct skinny_header *);
+#else
 		sd = (struct skinny_header *)(((char *)&sd->msgId) + len);
+#endif		
 	}
+getout:
+#ifdef _KERNEL
+	m_cat(*ptr, m);
+#endif
+	return;
 }


More information about the p4-projects mailing list