Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Feb 2007 01:20:52 GMT
From:      Paolo Pisati <piso@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 114084 for review
Message-ID:  <200702060120.l161Kq0P007994@repoman.freebsd.org>

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

Change 114084 by piso@piso_newluxor on 2007/02/06 01:19:53

	o introduce an opaque type (pkt_t) to avoid #ifdef _KERNEL ...
	  #else ... #endif all the function declarations.
	o update all the code to handled the switch from *mbuf to **mbuf.
	o XXX there're some printfs debug around.

Affected files ...

.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias.c#55 edit
.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias.h#14 edit
.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_db.c#23 edit
.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_local.h#21 edit
.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_proxy.c#20 edit

Differences ...

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

@@ -258,20 +258,20 @@
 /* Local prototypes */
 static int	IcmpAliasIn1(struct libalias *, struct ip *);
 static int	IcmpAliasIn2(struct libalias *, struct ip *);
-static int	IcmpAliasIn(struct libalias *, void *);
+static int	IcmpAliasIn(struct libalias *, pkt_t);
 
 static int	IcmpAliasOut1(struct libalias *, struct ip *, int create);
 static int	IcmpAliasOut2(struct libalias *, struct ip *);
-static int	IcmpAliasOut(struct libalias *, void *, int create);
+static int	IcmpAliasOut(struct libalias *, pkt_t, int create);
 
 static int	ProtoAliasIn(struct libalias *, struct ip *);
 static int	ProtoAliasOut(struct libalias *, struct ip *, int create);
 
-static int	UdpAliasIn(struct libalias *, void *);
-static int	UdpAliasOut(struct libalias *, void *, int create);
+static int	UdpAliasIn(struct libalias *, pkt_t);
+static int	UdpAliasOut(struct libalias *, pkt_t, int create);
 
-static int	TcpAliasIn(struct libalias *, void *);
-static int	TcpAliasOut(struct libalias *, void *, int, int create);
+static int	TcpAliasIn(struct libalias *, pkt_t);
+static int	TcpAliasOut(struct libalias *, pkt_t, int, int create);
 
 
 static int
@@ -420,7 +420,7 @@
 
 
 static int
-IcmpAliasIn(struct libalias *la, void *ptr)
+IcmpAliasIn(struct libalias *la, pkt_t ptr)
 {
 	int iresult;
 	struct ip *pip;
@@ -609,7 +609,7 @@
 
 
 static int
-IcmpAliasOut(struct libalias *la, void *ptr, int create)
+IcmpAliasOut(struct libalias *la, pkt_t ptr, int create)
 {
 	int iresult;
 	struct icmp *ic;
@@ -721,7 +721,7 @@
 
 
 static int
-UdpAliasIn(struct libalias *la, void *ptr)
+UdpAliasIn(struct libalias *la, pkt_t ptr)
 {
 	struct ip *pip;
 	struct udphdr *ud;
@@ -791,7 +791,7 @@
 }
 
 static int
-UdpAliasOut(struct libalias *la, void *ptr, int create)
+UdpAliasOut(struct libalias *la, pkt_t ptr, int create)
 {
 	struct ip *pip;
 	struct udphdr *ud;
@@ -858,7 +858,7 @@
 
 
 static int
-TcpAliasIn(struct libalias *la, void *ptr)
+TcpAliasIn(struct libalias *la, pkt_t ptr)
 {
 	struct ip *pip;
 	struct tcphdr *tc;
@@ -983,7 +983,7 @@
 }
 
 static int
-TcpAliasOut(struct libalias *la, void *ptr, int maxpacketsize, int create)
+TcpAliasOut(struct libalias *la, pkt_t ptr, int maxpacketsize, int create)
 {
 	int proxy_type, error;
 	u_short dest_port, src_port;
@@ -1179,11 +1179,7 @@
 
 
 int
-#ifdef _KERNEL
-LibAliasSaveFragment(struct libalias *la, struct mbuf *ptr)
-#else
-LibAliasSaveFragment(struct libalias *la, char *ptr)
-#endif
+LibAliasSaveFragment(struct libalias *la, pkt_t ptr)
 {
 	int iresult;
 	struct alias_link *lnk;
@@ -1207,11 +1203,10 @@
 
 #ifdef _KERNEL
 struct mbuf    *
-LibAliasGetFragment(struct libalias *la, struct mbuf *ptr)
 #else
-char           *
-LibAliasGetFragment(struct libalias *la, char *ptr)
+char *
 #endif
+LibAliasGetFragment(struct libalias *la, pkt_t ptr)
 {
 	struct alias_link *lnk;
 #ifdef _KERNEL
@@ -1239,19 +1234,13 @@
 	return (fptr);
 }
 
-#ifdef _KERNEL
 void
-LibAliasFragmentIn(struct libalias *la, struct mbuf *ptr, 
-    struct mbuf *ptr_fragment)
-#else
-void
-LibAliasFragmentIn(struct libalias *la, char *ptr,	/* Points to correctly
+LibAliasFragmentIn(struct libalias *la, pkt_t ptr,	/* Points to correctly
 							 * de-aliased header
 							 * fragment */
-    char *ptr_fragment		/* Points to fragment which must be
+    pkt_t ptr_fragment		/* Points to fragment which must be
 				 * de-aliased   */
 )
-#endif
 {
 	struct ip *pip;
 	struct ip *fpip;
@@ -1276,18 +1265,14 @@
 
 /* Local prototypes */
 static int
-LibAliasOutLocked(struct libalias *la, void *ptr,
+LibAliasOutLocked(struct libalias *la, pkt_t ptr,
 		  int maxpacketsize, int create);
 static int
-LibAliasInLocked(struct libalias *la, void *ptr,
+LibAliasInLocked(struct libalias *la, pkt_t ptr,
 		  int maxpacketsize);
 
 int
-#ifdef _KERNEL
-LibAliasIn(struct libalias *la, struct mbuf *ptr, int maxpacketsize)
-#else
-LibAliasIn(struct libalias *la, char *ptr, int maxpacketsize)
-#endif
+LibAliasIn(struct libalias *la, pkt_t ptr, int maxpacketsize)
 {
 	int res;
 
@@ -1298,7 +1283,7 @@
 }
 
 static int
-LibAliasInLocked(struct libalias *la, void *ptr, int maxpacketsize)
+LibAliasInLocked(struct libalias *la, pkt_t ptr, int maxpacketsize)
 {
 	struct in_addr alias_addr;
 	struct ip *pip;
@@ -1329,7 +1314,9 @@
 			iresult = IcmpAliasIn(la, ptr);
 			break;
 		case IPPROTO_UDP:
+			printf("bef UdpAliasIn: %u\n", iresult);
 			iresult = UdpAliasIn(la, ptr);
+			printf("aft UdpAliasIn: %u\n", iresult);
 			break;
 		case IPPROTO_TCP:
 			iresult = TcpAliasIn(la, ptr);
@@ -1396,11 +1383,7 @@
 #define UNREG_ADDR_C_UPPER 0xc0a8ffff
 
 int
-#ifdef _KERNEL
-LibAliasOut(struct libalias *la, struct mbuf *ptr, int maxpacketsize)
-#else
-LibAliasOut(struct libalias *la, char *ptr, int maxpacketsize)
-#endif
+LibAliasOut(struct libalias *la, pkt_t ptr, int maxpacketsize)
 {
 	int res;
 
@@ -1411,11 +1394,7 @@
 }
 
 int
-#ifdef _KERNEL
-LibAliasOutTry(struct libalias *la, struct mbuf *ptr, int maxpacketsize, int create)
-#else
-LibAliasOutTry(struct libalias *la, char *ptr, int maxpacketsize, int create)
-#endif
+LibAliasOutTry(struct libalias *la, pkt_t ptr, int maxpacketsize, int create)
 {
 	int res;
 
@@ -1426,7 +1405,7 @@
 }
 
 static int
-LibAliasOutLocked(struct libalias *la, void *ptr,	/* valid IP packet */
+LibAliasOutLocked(struct libalias *la, pkt_t ptr,	/* valid IP packet */
     int maxpacketsize,		/* How much the packet data may grow (FTP
 				 * and IRC inline changes) */
     int create                  /* Create new entries ? */
@@ -1441,18 +1420,23 @@
 		la->packetAliasMode &= ~PKT_ALIAS_REVERSE;
 		iresult = LibAliasInLocked(la, ptr, maxpacketsize);
 		la->packetAliasMode |= PKT_ALIAS_REVERSE;
+		printf("PKT_ALIAS_REVERSE\n");
 		goto getout;
 	}
 	HouseKeeping(la);
 	ClearCheckNewLink(la);
 	PULLUP_IPHDR(pip, ptr);
-	if (pip == NULL)
+	if (pip == NULL) {
+		printf("failed PULLUP_IPHDR\n");
 		goto getout;
+	}
 
 	/* Defense against mangled packets */
 	if (ntohs(pip->ip_len) > maxpacketsize
-	    || (pip->ip_hl << 2) > maxpacketsize)
+	    || (pip->ip_hl << 2) > maxpacketsize) {
+		printf("mangled pkt\n");
 		goto getout;
+	}
 
 	addr_save = GetDefaultAliasAddress(la);
 	if (la->packetAliasMode & PKT_ALIAS_UNREGISTERED_ONLY) {
@@ -1480,9 +1464,11 @@
 			iresult = IcmpAliasOut(la, ptr, create);
 			break;
 		case IPPROTO_UDP:
+			printf("bef UdpAliasOut: %u\n", iresult);
 			iresult = UdpAliasOut(la, ptr, create);
+			printf("aft UdpAliasOut: %u\n", iresult);
 			break;
-			case IPPROTO_TCP:
+		case IPPROTO_TCP:
 			iresult = TcpAliasOut(la, ptr, maxpacketsize, create);
 			break;
  		case IPPROTO_GRE: {
@@ -1519,15 +1505,9 @@
 }
 
 int
-#ifdef _KERNEL
-LibAliasUnaliasOut(struct libalias *la, struct mbuf *ptr,	/* valid IP packet */
+LibAliasUnaliasOut(struct libalias *la, pkt_t ptr,	/* valid IP packet */
     int maxpacketsize		/* for error checking */
 )
-#else
-LibAliasUnaliasOut(struct libalias *la, char *ptr,	/* valid IP packet */
-    int maxpacketsize		/* for error checking */
-)
-#endif
 {
 	struct ip *pip;
 	struct icmp *ic;

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

@@ -146,10 +146,10 @@
 
 /* Packet Handling functions. */
 #ifdef _KERNEL
-int		LibAliasIn (struct libalias *, struct mbuf *_ptr, int _maxpacketsize);
-int		LibAliasOut(struct libalias *, struct mbuf *_ptr, int _maxpacketsize);
-int		LibAliasOutTry(struct libalias *, struct mbuf *_ptr, int _maxpacketsize, int _create);
-int		LibAliasUnaliasOut(struct libalias *, struct mbuf *_ptr, int _maxpacketsize);
+int		LibAliasIn (struct libalias *, struct mbuf **_ptr, int _maxpacketsize);
+int		LibAliasOut(struct libalias *, struct mbuf **_ptr, int _maxpacketsize);
+int		LibAliasOutTry(struct libalias *, struct mbuf **_ptr, int _maxpacketsize, int _create);
+int		LibAliasUnaliasOut(struct libalias *, struct mbuf **_ptr, int _maxpacketsize);
 #else
 int		LibAliasIn (struct libalias *, char *_ptr, int _maxpacketsize);
 int		LibAliasOut(struct libalias *, char *_ptr, int _maxpacketsize);
@@ -179,10 +179,10 @@
 
 /* Fragment Handling functions. */
 #ifdef _KERNEL
-void		LibAliasFragmentIn(struct libalias *, struct mbuf *_ptr, 
-    struct mbuf *_ptr_fragment);
-struct mbuf     *LibAliasGetFragment(struct libalias *, struct mbuf *_ptr);
-int		LibAliasSaveFragment(struct libalias *, struct mbuf *_ptr);
+void		LibAliasFragmentIn(struct libalias *, struct mbuf **_ptr, 
+    struct mbuf **_ptr_fragment);
+struct mbuf     *LibAliasGetFragment(struct libalias *, struct mbuf **_ptr);
+int		LibAliasSaveFragment(struct libalias *, struct mbuf **_ptr);
 #else
 void		LibAliasFragmentIn(struct libalias *, char *_ptr, char *_ptr_fragment);
 char           *LibAliasGetFragment(struct libalias *, char *_ptr);

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

@@ -1819,14 +1819,16 @@
 
 void
 #ifdef _KERNEL
-SetFragmentPtr(struct alias_link *lnk, struct mbuf *fptr)
+SetFragmentPtr(struct alias_link *lnk, struct mbuf **fptr)
+{
+	lnk->data.frag_ptr = *fptr;
+}
 #else
 SetFragmentPtr(struct alias_link *lnk, char *fptr)
-#endif
 {
 	lnk->data.frag_ptr = fptr;
 }
-
+#endif
 
 void
 #ifdef _KERNEL

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

@@ -177,52 +177,54 @@
 #endif
 
 #ifdef _KERNEL
+typedef struct mbuf ** pkt_t;
 
 #define PULLUP_IPHDR(pip, ptr) do {             \
-	ptr = m_pullup((ptr), sizeof(struct ip)); \
-        (pip) = mtod((struct mbuf *)ptr, struct ip *);           \
+	*ptr = m_pullup((*ptr), sizeof(struct ip)); \
+        (pip) = mtod(*ptr, struct ip *);           \
 } while (0)
 
 #define PULLUP_UDPHDR(pip, ptr) do {            \
-	pip = mtod((struct mbuf *)ptr, struct ip *);             \
-	ptr = m_pullup((ptr), (pip->ip_hl << 2) + sizeof(struct udphdr)); \
-	(pip) = mtod((struct mbuf *)ptr, struct ip *);           \
+	pip = mtod(*ptr, struct ip *);             \
+	*ptr = m_pullup((*ptr), (pip->ip_hl << 2) + sizeof(struct udphdr)); \
+	(pip) = mtod(*ptr, struct ip *);           \
 } while (0)
 
 #define PULLUP_TCPHDR(pip, ptr) do {            \
-	pip = mtod((struct mbuf *)ptr, struct ip *);             \
-	ptr = m_pullup((ptr), (pip->ip_hl << 2) + sizeof(struct tcphdr)); \
-	(pip) = mtod((struct mbuf *)ptr, struct ip *);           \
+	pip = mtod(*ptr, struct ip *);             \
+	*ptr = m_pullup((*ptr), (pip->ip_hl << 2) + sizeof(struct tcphdr)); \
+	(pip) = mtod(*ptr, struct ip *);           \
 } while (0)
 
 #define PULLUP_ICMPHDR(pip, ptr) do {           \
-	pip = mtod((struct mbuf *)ptr, struct ip *);           \
-	ptr = m_pullup((ptr), (pip->ip_hl << 2) + sizeof(struct icmp)); \
-	(pip) = mtod((struct mbuf *)ptr, struct ip *);           \
+	pip = mtod(*ptr, struct ip *);           \
+	*ptr = m_pullup((*ptr), (pip->ip_hl << 2) + sizeof(struct icmp)); \
+	(pip) = mtod(*ptr, struct ip *);           \
 } while (0)
 
 #define PULLUP_ICMPIP64(pip, ptr, ic) do {      \
         int s;                                  \
-	pip = mtod((struct mbuf *)ptr, struct ip *);             \
+	pip = mtod(*ptr, struct ip *);             \
         s = (pip->ip_hl << 2) + sizeof(struct icmp) + \
             (ic->icmp_ip.ip_hl << 2) - sizeof(struct ip) + 8; \
-	ptr = m_pullup((ptr), s);                 \
-	(pip) = mtod((struct mbuf *)ptr, struct ip *);           \
+	*ptr = m_pullup((*ptr), s);                 \
+	(pip) = mtod(*ptr, struct ip *);           \
 } while (0)
 
 #define PULLUP_IPTCPHDR(pip, ptr) do {          \
-	ptr = m_pullup((ptr), sizeof(struct ip)); \
-        (pip) = mtod((struct mbuf *)ptr, struct ip *);           \
-        ptr = m_pullup((ptr), (pip->ip_hl << 2) + sizeof(struct tcphdr)); \
-	(pip) = mtod((struct mbuf *)ptr, struct ip *);           \
+	*ptr = m_pullup((*ptr), sizeof(struct ip)); \
+        (pip) = mtod(*ptr, struct ip *);           \
+        *ptr = m_pullup((*ptr), (pip->ip_hl << 2) + sizeof(struct tcphdr)); \
+	(pip) = mtod(*ptr, struct ip *);           \
 } while (0)
+#else
+typedef char * pkt_t;
 
-#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_UDPHDR(pip, ptr) pip = (struct ip *)ptr
+#define PULLUP_TCPHDR(pip, ptr) pip = (struct ip *)ptr
 #define PULLUP_ICMPHDR(pip, ptr) pip = (struct ip *)ptr
-#define PULLUP_ICMPIP64(pip, ptr, ic) pip = ptr
+#define PULLUP_ICMPIP64(pip, ptr, ic) pip = (struct ip *)ptr
 #define PULLUP_IPTCPHDR(pip, ptr) pip = (struct ip *)ptr
 #endif
 
@@ -328,7 +330,7 @@
 void		SetFragmentAddr(struct alias_link *_lnk, struct in_addr _src_addr);
 #ifdef _KERNEL
 void		GetFragmentPtr(struct alias_link *_lnk, struct mbuf **_fptr);
-void		SetFragmentPtr(struct alias_link *_lnk, struct mbuf *fptr);
+void		SetFragmentPtr(struct alias_link *_lnk, struct mbuf **fptr);
 #else
 void		GetFragmentPtr(struct alias_link *_lnk, char **_fptr);
 void		SetFragmentPtr(struct alias_link *_lnk, char *fptr);
@@ -381,7 +383,7 @@
 ProxyCheck(struct libalias *la, struct ip *_pip, struct in_addr *_proxy_server_addr,
     u_short * _proxy_server_port, u_short dst_port);
 void
-ProxyModify(struct libalias *la, struct alias_link *_lnk, void *_pip,
+ProxyModify(struct libalias *la, struct alias_link *_lnk, pkt_t,
     int _maxpacketsize, int _proxy_type, u_short src_port);
 
 enum alias_tcp_state {

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

@@ -146,8 +146,8 @@
 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 *, void *, int);
-static void	ProxyEncodeIpHeader(void *, u_short sport);
+static void	ProxyEncodeTcpStream(struct alias_link *, pkt_t, int);
+static void	ProxyEncodeIpHeader(pkt_t, u_short sport);
 
 #ifdef	_KERNEL
 static int
@@ -392,7 +392,7 @@
 
 static void
 ProxyEncodeTcpStream(struct alias_link *lnk,
-    void *ptr,
+    pkt_t ptr,
     int maxpacketsize)
 {
 	int slen;
@@ -449,11 +449,11 @@
 		if (dlen == 0)
 			return;
 #ifdef _KERNEL
-		m = m_split(ptr, hlen, M_TRYWAIT);
+		m = m_split(*ptr, hlen, M_TRYWAIT);
 		if (m == NULL)
 			return;
-		m_copyback(ptr, hlen, slen, buffer);
-		m_cat(ptr, m);
+		m_copyback(*ptr, hlen, slen, buffer);
+		m_cat(*ptr, m);
 #else
 		p = (char *)pip;
 		p += hlen;
@@ -499,7 +499,7 @@
 }
 
 static void
-ProxyEncodeIpHeader(void *_ptr, u_short sport)
+ProxyEncodeIpHeader(pkt_t _ptr, u_short sport)
 {
 	struct ip *pip;
 #define OPTION_LEN_BYTES  8
@@ -542,11 +542,11 @@
 #ifdef _KERNEL		
 		// XXX - here i assume after an m_split() there's always enough
 		// XXX - space to append option[] to _ptr
-		m = m_split(_ptr, 20, M_TRYWAIT);
+		m = m_split(*_ptr, 20, M_TRYWAIT);
 		if (m == NULL)
 			return;
-		m_copyback(_ptr, 20, 8, option);
-		m_cat(_ptr, m);
+		m_copyback(*_ptr, 20, 8, option);
+		m_cat(*_ptr, m);
 #else
 		memcpy(ptr, option, 8);
 #endif
@@ -567,7 +567,7 @@
 		for (i = 0; i < OPTION_LEN_INT16; i++)
 			accumulate -= *(sptr++);
 #ifdef _KERNEL
-		sptr = mtod((struct mbuf *)_ptr, u_short *);
+		sptr = mtod(*_ptr, u_short *);
 #else
 		sptr = (u_short *) pip;
 #endif
@@ -642,7 +642,7 @@
 }
 
 void
-ProxyModify(struct libalias *la, struct alias_link *lnk, void *ptr,
+ProxyModify(struct libalias *la, struct alias_link *lnk, pkt_t ptr,
     int maxpacketsize, int proxy_type, u_short src_port)
 {
 



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