lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] [lwip] lwip under Linux 2.4


From: Jose Vasconcellos
Subject: [lwip-users] [lwip] lwip under Linux 2.4
Date: Wed, 08 Jan 2003 22:09:00 -0000

--=-9z9ISCQIvGJEFALlmSMe
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hello!

I've got some good news: I managed to get lwip to work under Linux 2.4.
There are several issues here:

1. Access to the tap device requires specifying tap via ioctl.

2. Thread race condition in sys_thread_new. The problem here is that
pthread_create will invoke the newly created thread before it returns
from the pthread_create call. This is a problem because the pthread
variable is not set which causes the function current_thread to abort.
The fix is to make sure the thread->pthread variable is set before
the thread starts.

After these changes, simhost seems to run: it responds to pings and
can serve web pages. Note that you must run simhost from gdb otherwise
it crashes. Looks like there are a few more bugs lurking around.

BONUS: I include a Jamfile to build the system. I find it much faster
and reliable than make.

Jose Vasconcellos


--=-9z9ISCQIvGJEFALlmSMe
Content-Disposition: attachment; filename=lwip-sys_arch.c
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; charset=ISO-8859-1

*** lwip-0.5.0/src/arch/unix/sys_arch.c Wed Dec 12 05:00:57 2001
--- lwip-new/src/arch/unix/sys_arch.c   Sat Dec 22 23:18:50 2001
***************
*** 109,124 ****
    abort();
  }
  /*-----------------------------------------------------------------------=
------------*/
  void
  sys_thread_new(void (* function)(void *arg), void *arg)
  {
    struct sys_thread *thread;
    thread =3D malloc(sizeof(struct sys_thread));
    thread->next =3D threads;
    thread->timeouts.next =3D NULL;
    threads =3D thread;
 =20
!   if(pthread_create(&(thread->pthread), NULL, (void *(*)(void *))function=
, arg) !=3D 0) {
      perror("sys_thread_new: pthread_create");
      abort();
    }
--- 109,147 ----
    abort();
  }
  /*-----------------------------------------------------------------------=
------------*/
+ struct thread_start_param {
+   struct sys_thread *thread;
+   void (* function)(void *);
+   void *arg;
+ };
+=20
+ static void *
+ thread_start(void *arg)
+ {
+   struct thread_start_param *tp =3D arg;
+   tp->thread->pthread =3D pthread_self();
+   tp->function(tp->arg);
+   return NULL;
+ }
+=20
  void
  sys_thread_new(void (* function)(void *arg), void *arg)
  {
    struct sys_thread *thread;
+   struct thread_start_param thread_param;
+=20
    thread =3D malloc(sizeof(struct sys_thread));
    thread->next =3D threads;
    thread->timeouts.next =3D NULL;
+   thread->timeouts.next =3D NULL;
+   thread->pthread =3D 0;
    threads =3D thread;
 =20
!   thread_param.function =3D function;
!   thread_param.arg =3D arg;
!   thread_param.thread =3D thread;
!=20
!   if(pthread_create(&(thread->pthread), NULL, thread_start, &thread_param=
) !=3D 0) {
      perror("sys_thread_new: pthread_create");
      abort();
    }
***************
*** 218,226 ****
     =20
      sys_arch_sem_wait(mbox->mutex, 0);
    }
-   DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p msg %p\n", mbox, *msg));
   =20
    if(msg !=3D NULL) {
      *msg =3D mbox->msgs[mbox->first];
    }
   =20
--- 241,249 ----
     =20
      sys_arch_sem_wait(mbox->mutex, 0);
    }
   =20
    if(msg !=3D NULL) {
+     DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p msg %p\n", mbox, *msg));
      *msg =3D mbox->msgs[mbox->first];
    }
   =20

--=-9z9ISCQIvGJEFALlmSMe
Content-Disposition: attachment; filename=lwip-tapif.c
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; charset=ISO-8859-1

*** lwip-0.5.0/src/arch/unix/netif/tapif.c      Wed Dec 12 05:02:27 2001
--- lwip-new/src/arch/unix/netif/tapif.c        Sat Dec 22 23:11:12 2001
***************
*** 53,58 ****
--- 53,67 ----
 =20
  #include "netif/arp.h"
 =20
+ #ifdef LINUX24
+ #include <sys/ioctl.h>
+ #include <linux/if.h>
+ #include <linux/if_tun.h>
+ #define DEVTAP "/dev/net/tun"
+ #else
+ #define DEVTAP "/dev/tap0"
+ #endif
+=20
  #define IFNAME0 't'
  #define IFNAME1 'p'
 =20
***************
*** 89,100 ****
 =20
    /* Do whatever else is needed to initialize interface. */
   =20
!   tapif->fd =3D open("/dev/tap0", O_RDWR);
    DEBUGF(TAPIF_DEBUG, ("tapif_init: fd %d\n", tapif->fd));
    if(tapif->fd =3D=3D -1) {
      perror("tapif_init");
      exit(1);
    }
    snprintf(buf, sizeof(buf), "ifconfig tap0 inet %d.%d.%d.%d",
             ip4_addr1(&(netif->gw)),
             ip4_addr2(&(netif->gw)),
--- 98,122 ----
 =20
    /* Do whatever else is needed to initialize interface. */
   =20
!   tapif->fd =3D open(DEVTAP, O_RDWR);
    DEBUGF(TAPIF_DEBUG, ("tapif_init: fd %d\n", tapif->fd));
    if(tapif->fd =3D=3D -1) {
      perror("tapif_init");
      exit(1);
    }
+=20
+ #ifdef LINUX24
+   {
+     struct ifreq ifr;
+     memset(&ifr, 0, sizeof(ifr));
+     ifr.ifr_flags =3D IFF_TAP|IFF_NO_PI;
+     if (ioctl(tapif->fd, TUNSETIFF, (void *) &ifr) < 0) {
+       perror(buf);
+       exit(1);
+     }
+   }
+ #endif
+=20
    snprintf(buf, sizeof(buf), "ifconfig tap0 inet %d.%d.%d.%d",
             ip4_addr1(&(netif->gw)),
             ip4_addr2(&(netif->gw)),

--=-9z9ISCQIvGJEFALlmSMe
Content-Disposition: attachment; filename=Jamfile
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1

#################
# for use with Jam - http://www.perforce.com/jam/jam.html

TOP =3D ../.. ;

CCFLAGS +=3D -g -Wall -DIPv4  -fpack-struct -pthread ;
CCFLAGS +=3D -DLWIP_DEBUG ;
CCFLAGS +=3D -DLINUX24 ;
LINKFLAGS +=3D -pthread ;

SEARCH_SOURCE +=3D $(TOP)/src/include
        $(TOP)/src/arch/unix/include
        $(TOP)/src/arch/unix
        $(TOP)/src/arch/unix/netif
        $(TOP)/src/api
        $(TOP)/src/netif
        $(TOP)/src/core
        $(TOP)/src/core/ipv4
        $(TOP)/src/include/ipv4
        $(TOP)/proj/unixsim/apps . ;

LOCATE_TARGET =3D bin ;

#################

Main simhost : simhost.c ;
LinkLibraries simhost : liblwip4unix liblwip4 ;
#Main simrouter : simrouter.c ;
#LinkLibraries simrouter : liblwip4 liblwip4unix ;
#Main simnode : simnode.c ;
#LinkLibraries simnode : liblwip4 liblwip4unix ;

Library liblwip4unix :=20
        # $(TOP)/src/arch/unix
        perf.c sys_arch.c
        # $(TOP)/src/arch/unix/netif
        delif.c list.c sioslipif.c tapif.c tunif.c unixif.c
        # $(TOP)/proj/unixsim/apps
        fs.c httpd.c udpecho.c tcpecho.c shell.c
        ;

Library liblwip4 :
        # $(TOP)/src/api
        api_lib.c api_msg.c err.c tcpip.c
        # $(TOP)/src/netif
        loopif.c tcpdump.c arp.c
#       ethernetif.c
        # $(TOP)/src/core
        mem.c memp.c netif.c pbuf.c stats.c sys.c
        tcp.c tcp_input.c tcp_output.c udp.c
        # $(TOP)/src/core/ipv4
        icmp.c ip.c inet.c
        ;

#################

--=-9z9ISCQIvGJEFALlmSMe--

[This message was sent through the lwip discussion list.]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]