Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Feb 2007 16:38:56 GMT
From:      Paolo Pisati <piso@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 114002 for review
Message-ID:  <200702041638.l14GculD034168@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=114002

Change 114002 by piso@piso_newluxor on 2007/02/04 16:37:59

	Teach mbuf to ProxyEncodeTcpStream().

Affected files ...

.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias.c#54 edit
.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_local.h#19 edit
.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_proxy.c#19 edit

Differences ...

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

@@ -1054,10 +1054,11 @@
 		if (proxy_type != 0) {
 			SetProxyPort(lnk, dest_port);
 			SetProxyAddress(lnk, dest_address);
-			// XXX broken
 			ProxyModify(la, lnk, ptr, maxpacketsize, proxy_type, 
 			    src_port);
-			// XXX m_pullup()
+			PULLUP_IPTCPHDR(pip, ptr);
+			if (pip == NULL)
+				return (PKT_ALIAS_IGNORED);
 			tc = (struct tcphdr *)ip_next(pip);
 		}
 /* Get alias address and port */

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

@@ -215,12 +215,21 @@
 	(pip) = mtod(m, struct ip *);           \
 } while (0)
 
+#define PULLUP_IPTCPHDR(pip, ptr) do {          \
+        struct mbuf *m;                         \
+	m = m_pullup((ptr), sizeof(struct ip)); \
+        (pip) = mtod(m, struct ip *);           \
+        m = m_pullup((ptr), (pip->ip_hl << 2) + sizeof(struct tcphdr)); \
+	(pip) = mtod(m, struct ip *);           \
+} while (0)
+
 #else
 #define PULLUP_IPHDR(pip, ptr) pip = (struct ip *)ptr
 #define PULLUP_UDPHDR(pip, ptr) pip = ptr
 #define PULLUP_TCPHDR(pip, ptr) pip = ptr
 #define PULLUP_ICMPHDR(pip, ptr) pip = (struct ip *)ptr
 #define PULLUP_ICMPIP64(pip, ptr, ic) pip = ptr
+#define PULLUP_IPTCPHDR(pip, ptr) pip = (struct ip *)ptr
 #endif
 
 /*

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

@@ -146,7 +146,7 @@
 static void	RuleAdd(struct libalias *la, struct proxy_entry *);
 static void	RuleDelete(struct proxy_entry *);
 static int	RuleNumberDelete(struct libalias *la, int);
-static void	ProxyEncodeTcpStream(struct alias_link *, struct ip *, int);
+static void	ProxyEncodeTcpStream(struct alias_link *, void *, int);
 static void	ProxyEncodeIpHeader(void *, u_short sport);
 
 #ifdef	_KERNEL
@@ -392,13 +392,17 @@
 
 static void
 ProxyEncodeTcpStream(struct alias_link *lnk,
-    struct ip *pip,
+    void *ptr,
     int maxpacketsize)
 {
 	int slen;
 	char buffer[40];
+	struct ip *pip;
 	struct tcphdr *tc;
 
+	PULLUP_TCPHDR(pip, ptr);
+	if (pip == NULL)
+		return;
 /* Compute pointer to tcp header */
 	tc = (struct tcphdr *)ip_next(pip);
 
@@ -431,7 +435,11 @@
 	{
 		int dlen;
 		int hlen;
+#ifdef _KERNEL
+		struct mbuf *m;
+#else
 		u_char *p;
+#endif
 
 		hlen = (pip->ip_hl + tc->th_off) << 2;
 		dlen = ntohs(pip->ip_len) - hlen;
@@ -440,14 +448,25 @@
 
 		if (dlen == 0)
 			return;
-
+#ifdef _KERNEL
+		m = m_split(ptr, hlen, M_TRYWAIT);
+		if (m == NULL)
+			return;
+		m_copyback(ptr, hlen, slen, buffer);
+		m_cat(ptr, m);
+#else
 		p = (char *)pip;
 		p += hlen;
 
 		bcopy(p, p + slen, dlen);
 		memcpy(p, buffer, slen);
+#endif
 	}
 
+	PULLUP_IPTCPHDR(pip, ptr);
+	if (pip == NULL)
+		return;
+
 /* Save information about modfied sequence number */
 	{
 		int delta;
@@ -626,7 +645,6 @@
 ProxyModify(struct libalias *la, struct alias_link *lnk, void *ptr,
     int maxpacketsize, int proxy_type, u_short src_port)
 {
-	struct ip *pip;
 
 	LIBALIAS_LOCK_ASSERT(la);
 	(void)la;
@@ -637,8 +655,7 @@
 		break;
 
 	case PROXY_TYPE_ENCODE_TCPSTREAM:
-		PULLUP_IPHDR(pip, ptr);
-		ProxyEncodeTcpStream(lnk, pip, maxpacketsize);
+		ProxyEncodeTcpStream(lnk, ptr, maxpacketsize);
 		break;
 	}
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200702041638.l14GculD034168>