[ros-diffs] [cgutman] 45291: - Merge aicom-network-branch (still without the NDIS stuff) - Fixes some nasty bugs and hacks in our TCP implementation

cgutman at svn.reactos.org cgutman at svn.reactos.org
Thu Jan 28 01:24:00 CET 2010


Author: cgutman
Date: Thu Jan 28 01:24:00 2010
New Revision: 45291

URL: http://svn.reactos.org/svn/reactos?rev=45291&view=rev
Log:
 - Merge aicom-network-branch (still without the NDIS stuff)
 - Fixes some nasty bugs and hacks in our TCP implementation

Added:
    trunk/reactos/lib/drivers/oskittcp/include/osenv.h   (with props)
    trunk/reactos/lib/drivers/oskittcp/oskittcp/osenv.c   (with props)
Modified:
    trunk/reactos/lib/drivers/ip/transport/tcp/event.c
    trunk/reactos/lib/drivers/oskittcp/include/freebsd/src/sys/sys/malloc.h
    trunk/reactos/lib/drivers/oskittcp/include/freebsd/src/sys/sys/proc.h
    trunk/reactos/lib/drivers/oskittcp/oskittcp.rbuild
    trunk/reactos/lib/drivers/oskittcp/oskittcp/interface.c
    trunk/reactos/lib/drivers/oskittcp/oskittcp/ip_output.c
    trunk/reactos/lib/drivers/oskittcp/oskittcp/sleep.c
    trunk/reactos/lib/drivers/oskittcp/oskittcp/tcp_output.c
    trunk/reactos/lib/drivers/oskittcp/oskittcp/tcp_subr.c
    trunk/reactos/lib/drivers/oskittcp/oskittcp/uipc_mbuf.c

Modified: trunk/reactos/lib/drivers/ip/transport/tcp/event.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/tcp/event.c?rev=45291&r1=45290&r2=45291&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/ip/transport/tcp/event.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/transport/tcp/event.c [iso-8859-1] Thu Jan 28 01:24:00 2010
@@ -24,11 +24,14 @@
                NewState & SEL_ACCEPT  ? 'A' : 'a',
                NewState & SEL_WRITE   ? 'W' : 'w'));
 
+    /* If this socket is missing its socket context, that means that it
+     * has been created as a new connection in sonewconn but not accepted
+     * yet. We can safely ignore event notifications on these sockets.
+     * Once they are accepted, they will get a socket context and we will 
+     * be able to process them.
+     */
     if (!Connection)
-    {
-        //ASSERT(FALSE);
         return 0;
-    }
 
     TI_DbgPrint(DEBUG_TCP,("Called: NewState %x (Conn %x) (Change %x)\n",
                NewState, Connection,

Modified: trunk/reactos/lib/drivers/oskittcp/include/freebsd/src/sys/sys/malloc.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/oskittcp/include/freebsd/src/sys/sys/malloc.h?rev=45291&r1=45290&r2=45291&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/oskittcp/include/freebsd/src/sys/sys/malloc.h [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/oskittcp/include/freebsd/src/sys/sys/malloc.h [iso-8859-1] Thu Jan 28 01:24:00 2010
@@ -36,7 +36,7 @@
 #ifndef _SYS_MALLOC_H_
 #define	_SYS_MALLOC_H_
 
-#ifndef OSKIT
+#if !defined(OSKIT) || defined(__REACTOS__)
 #define KMEMSTATS
 #endif
 
@@ -288,7 +288,6 @@
 #define	MALLOC(space, cast, size, type, flags) \
 	(space) = (cast)fbsd_malloc((u_long)(size), __FILE__, __LINE__, type, flags)
 #define FREE(addr, type) fbsd_free((caddr_t)(addr), __FILE__, __LINE__, type)
-
 #else /* do not collect statistics */
 #define	MALLOC(space, cast, size, type, flags) { \
 	register struct kmembuckets *kbp = &bucket[BUCKETINDX(size)]; \

Modified: trunk/reactos/lib/drivers/oskittcp/include/freebsd/src/sys/sys/proc.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/oskittcp/include/freebsd/src/sys/sys/proc.h?rev=45291&r1=45290&r2=45291&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/oskittcp/include/freebsd/src/sys/sys/proc.h [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/oskittcp/include/freebsd/src/sys/sys/proc.h [iso-8859-1] Thu Jan 28 01:24:00 2010
@@ -65,7 +65,11 @@
 #include <sys/socketvar.h>
 
 #ifdef OSKIT
+#ifndef __REACTOS__
 #include <oskit/dev/dev.h>
+#else
+#include <osenv.h>
+#endif
 #endif
 
 /*

Added: trunk/reactos/lib/drivers/oskittcp/include/osenv.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/oskittcp/include/osenv.h?rev=45291&view=auto
==============================================================================
--- trunk/reactos/lib/drivers/oskittcp/include/osenv.h (added)
+++ trunk/reactos/lib/drivers/oskittcp/include/osenv.h [iso-8859-1] Thu Jan 28 01:24:00 2010
@@ -1,0 +1,14 @@
+#ifndef OSENV_H
+#define OSENV_H
+
+static __inline void osenv_intr_enable(void) {}
+static __inline void osenv_intr_disable(void) {}
+
+void oskit_bufio_addref(void *buf);
+void oskit_bufio_release(void *buf);
+void* oskit_bufio_create(int len);
+void oskit_bufio_map(void *srcbuf, void**dstbuf, int off, int len);
+
+#define osenv_sleeprec_t void*
+
+#endif

Propchange: trunk/reactos/lib/drivers/oskittcp/include/osenv.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/reactos/lib/drivers/oskittcp/oskittcp.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/oskittcp/oskittcp.rbuild?rev=45291&r1=45290&r2=45291&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/oskittcp/oskittcp.rbuild [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/oskittcp/oskittcp.rbuild [iso-8859-1] Thu Jan 28 01:24:00 2010
@@ -3,6 +3,7 @@
 <module name="oskittcp" type="staticlibrary">
 	<define name="__NTDRIVER__"/>
 	<define name="KERNEL"/>
+	<define name="OSKIT"/>
 	<include base="oskittcp">include/freebsd</include>
 	<include base="oskittcp">include/freebsd/sys/include</include>
 	<include base="oskittcp">include/freebsd/src/sys</include>
@@ -22,6 +23,7 @@
 		<file>ip_output.c</file>
 		<file>kern_clock.c</file>
 		<file>kern_subr.c</file>
+		<file>osenv.c</file>
 		<file>param.c</file>
 		<file>radix.c</file>
 		<file>random.c</file>

Modified: trunk/reactos/lib/drivers/oskittcp/oskittcp/interface.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/oskittcp/oskittcp/interface.c?rev=45291&r1=45290&r2=45291&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/oskittcp/oskittcp/interface.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/oskittcp/oskittcp/interface.c [iso-8859-1] Thu Jan 28 01:24:00 2010
@@ -48,8 +48,6 @@
 void InitOskitTCP() {
     OS_DbgPrint(OSK_MID_TRACE,("Init Called\n"));
     KeInitializeSpinLock(&OSKLock);
-    OS_DbgPrint(OSK_MID_TRACE,("MB Init\n"));
-    mbinit();
     OS_DbgPrint(OSK_MID_TRACE,("Rawip Init\n"));
     rip_init();
     raw_init();
@@ -403,7 +401,7 @@
 
 	so->so_state |= SS_NBIO | SS_ISCONNECTED;
         so->so_q = so->so_q0 = NULL;
-        so->so_qlen = 0;
+        so->so_qlen = so->so_q0len = 0;
         so->so_head = 0;
         so->so_connection = context;
 

Modified: trunk/reactos/lib/drivers/oskittcp/oskittcp/ip_output.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/oskittcp/oskittcp/ip_output.c?rev=45291&r1=45290&r2=45291&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/oskittcp/oskittcp/ip_output.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/oskittcp/oskittcp/ip_output.c [iso-8859-1] Thu Jan 28 01:24:00 2010
@@ -393,6 +393,7 @@
 		error = OtcpEvent.PacketSend( OtcpEvent.ClientData,
 					      (OSK_PCHAR)new_m->m_data, new_m->m_len );
 		m_free( new_m );
+		m_freem( m );
 		goto done;
 	    }
 #else
@@ -532,6 +533,7 @@
 	    error = OtcpEvent.PacketSend( OtcpEvent.ClientData,
 					  (OSK_PCHAR)new_m->m_data, new_m->m_len );
 	    m_free( new_m );
+	    m_freem( m );
 	}
 
 	OS_DbgPrint(OSK_MID_TRACE,("Error from upper layer: %d\n", error));

Added: trunk/reactos/lib/drivers/oskittcp/oskittcp/osenv.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/oskittcp/oskittcp/osenv.c?rev=45291&view=auto
==============================================================================
--- trunk/reactos/lib/drivers/oskittcp/oskittcp/osenv.c (added)
+++ trunk/reactos/lib/drivers/oskittcp/oskittcp/osenv.c [iso-8859-1] Thu Jan 28 01:24:00 2010
@@ -1,0 +1,45 @@
+#include "oskittcp.h"
+
+unsigned oskit_freebsd_cpl;
+
+/* We have to store a reference count somewhere so we
+ * don't free a buffer being referenced in another mbuf.
+ * I just decided to add an extra char to the beginning of
+ * the buffer and store the reference count there. I doubt the ref count
+ * will ever even get close to 0xFF so we should be ok. Remember that
+ * only one thread can ever be inside oskit due to OSKLock so this should
+ * be safe.
+ */
+
+void oskit_bufio_addref(void *buf)
+{
+   unsigned char* fullbuf = ((unsigned char*)buf) - sizeof(char);
+
+#if DBG
+   if (fullbuf[0] == 0xFF)
+       panic("oskit_bufio_addref: ref count overflow");
+#endif
+
+   fullbuf[0]++;
+}
+void oskit_bufio_release(void *buf)
+{
+   unsigned char* fullbuf = ((unsigned char*)buf) - sizeof(char);
+
+   if (--fullbuf[0] == 0)
+       free(fullbuf, 0);
+}
+void* oskit_bufio_create(int len)
+{
+   unsigned char* fullbuf = malloc(len + sizeof(char), __FILE__, __LINE__);
+   if (fullbuf == NULL)
+       return NULL;
+
+   fullbuf[0] = 1;
+
+   return (void*)(fullbuf + sizeof(char));
+}
+void oskit_bufio_map(void *srcbuf, void**dstbuf, int off, int len)
+{
+   *dstbuf = srcbuf;
+}

Propchange: trunk/reactos/lib/drivers/oskittcp/oskittcp/osenv.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/reactos/lib/drivers/oskittcp/oskittcp/sleep.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/oskittcp/oskittcp/sleep.c?rev=45291&r1=45290&r2=45291&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/oskittcp/oskittcp/sleep.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/oskittcp/oskittcp/sleep.c [iso-8859-1] Thu Jan 28 01:24:00 2010
@@ -91,53 +91,3 @@
 	/* Start a clock we can use for timeouts */
 }
 
-
-extern	unsigned bio_imask;	/* group of interrupts masked with splbio() */
-extern	unsigned cpl;		/* current priority level mask */
-extern	volatile unsigned idelayed;	/* interrupts to become pending */
-extern	volatile unsigned ipending;	/* active interrupts masked by cpl */
-extern	unsigned net_imask;	/* group of interrupts masked with splimp() */
-extern	unsigned stat_imask;	/* interrupts masked with splstatclock() */
-extern	unsigned tty_imask;	/* group of interrupts masked with spltty() */
-
-/*
- * ipending has to be volatile so that it is read every time it is accessed
- * in splx() and spl0(), but we don't want it to be read nonatomically when
- * it is changed.  Pretending that ipending is a plain int happens to give
- * suitable atomic code for "ipending |= constant;".
- */
-#define	setdelayed()	(*(unsigned *)&ipending |= loadandclear(&idelayed))
-#define	setsoftast()	(*(unsigned *)&ipending |= SWI_AST_PENDING)
-#define	setsoftclock()	(*(unsigned *)&ipending |= SWI_CLOCK_PENDING)
-#define	setsoftnet()	(*(unsigned *)&ipending |= SWI_NET_PENDING)
-#define	setsofttty()	(*(unsigned *)&ipending |= SWI_TTY_PENDING)
-
-#define	schedsofttty()	(*(unsigned *)&idelayed |= SWI_TTY_PENDING)
-
-#define	GENSPL(name, set_cpl) \
-static __inline int name(void)			\
-{						\
-	unsigned x;				\
-						\
-	__asm __volatile("" : : : "memory");	\
-	x = cpl;				\
-	set_cpl;				\
-	return (x);				\
-}
-
-void splz(void) {
-    OS_DbgPrint(OSK_MID_TRACE,("Called SPLZ\n"));
-}
-
-/*
- * functions to save and restore the current cpl
- */
-void save_cpl(unsigned *x)
-{
-    *x = cpl;
-}
-
-void restore_cpl(unsigned x)
-{
-    cpl = x;
-}

Modified: trunk/reactos/lib/drivers/oskittcp/oskittcp/tcp_output.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/oskittcp/oskittcp/tcp_output.c?rev=45291&r1=45290&r2=45291&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/oskittcp/oskittcp/tcp_output.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/oskittcp/oskittcp/tcp_output.c [iso-8859-1] Thu Jan 28 01:24:00 2010
@@ -708,38 +708,8 @@
 		((struct ip *)ti)->ip_off |= IP_DF;
 	}
 #endif
-        /*
-         * XXX: It seems that osktittcp expects that packets are
-         * synchronously processed. The current implementation feeds
-         * oskittcp with the packets asynchronously. That's not a
-         * problem normally when the packets are transfered over
-         * network, but it starts to be a problem when it comes to
-         * loopback packets.
-         * The ACK bits are set in tcp_input which calls tcp_output and
-         * expects them to be cleared before further processing.
-         * Instead tcp_output calls ip_output which produces a packet
-         * and ends up in tcp_input and we're stuck in infinite loop.
-         * Normally the flags are masked out at the end of this function
-         * and the incomming packets are processed then, but since
-         * currently the loopback packet is delivered during the
-         * ip_output call, the function end is never reached...
-         */
-#ifdef __REACTOS__
-	tp->t_flags &= ~(TF_ACKNOW|TF_DELACK);
-#endif
 	error = ip_output(m, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route,
 			  so->so_options & SO_DONTROUTE, 0);
-#ifdef __REACTOS__
-	/* We allocated m, so we are responsible for freeing it. If the mbuf
-           contains a pointer to an external datablock, we (or rather, m_copy)
-           didn't allocate it but pointed it to the data to send. So we have
-           to cheat a little bit and keep M_FREE from freeing the external
-           data block */
-	while (NULL != m) {
-	    m->m_flags &= ~M_EXT;
-	    m = m_free(m);
-	}
-#endif
     }
 	if (error) {
 out:

Modified: trunk/reactos/lib/drivers/oskittcp/oskittcp/tcp_subr.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/oskittcp/oskittcp/tcp_subr.c?rev=45291&r1=45290&r2=45291&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/oskittcp/oskittcp/tcp_subr.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/oskittcp/oskittcp/tcp_subr.c [iso-8859-1] Thu Jan 28 01:24:00 2010
@@ -163,7 +163,6 @@
 	tcp_seq ack, seq;
 	int flags;
 {
-	struct mbuf *n;
 	register int tlen;
 	int win = 0;
 	struct route *ro = 0;
@@ -222,18 +221,6 @@
 		tcp_trace(TA_OUTPUT, 0, tp, ti, 0);
 #endif
 	(void) ip_output(m, NULL, ro, 0, NULL);
-#ifdef __REACTOS__
-	/* We allocated m, so we are responsible for freeing it. If the mbuf
-           contains a pointer to an external datablock, we (or rather, m_copy)
-           didn't allocate it but pointed it to the data to send. So we have
-           to cheat a little bit and keep M_FREE from freeing the external
-           data block */
-	while (NULL != m) {
-	    m->m_flags &= ~M_EXT;
-	    MFREE(m, n);
-	    m = n;
-	}
-#endif
 }
 
 /*

Modified: trunk/reactos/lib/drivers/oskittcp/oskittcp/uipc_mbuf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/oskittcp/oskittcp/uipc_mbuf.c?rev=45291&r1=45290&r2=45291&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/oskittcp/oskittcp/uipc_mbuf.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/oskittcp/oskittcp/uipc_mbuf.c [iso-8859-1] Thu Jan 28 01:24:00 2010
@@ -663,7 +663,7 @@
 	return (n);
 }
 
-#ifndef OSKIT
+#if !defined(OSKIT) || defined(__REACTOS__)
 /* currently not OS Kit approved, and shouldn't be needed in the first place */
 
 /*




More information about the Ros-diffs mailing list