This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

synthetic target ethernet driver & ethertap


This patch should allow the code to build even with 2.2.x kernels,
albeit with reduced functionality.

Bart

Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/eth/synth/ecosynth/current/ChangeLog,v
retrieving revision 1.2
diff -u -u -r1.2 ChangeLog
--- ChangeLog	22 Sep 2002 19:20:46 -0000	1.2
+++ ChangeLog	25 Sep 2002 19:47:25 -0000
@@ -1,3 +1,8 @@
+2002-09-25  Bart Veer  <bartv@ecoscentric.com>
+
+	* host/configure.in, host/rawether.c, doc/syntheth.sgml: 
+	Only support the tap device if running a recent Linux kernel
+
 2002-09-22  Bart Veer  <bartv@ecoscentric.com>
 
 	* host/configure.in:
Index: configure.in
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/eth/synth/ecosynth/current/host/configure.in,v
retrieving revision 1.2
diff -u -u -r1.2 configure.in
--- configure.in	22 Sep 2002 19:21:13 -0000	1.2
+++ configure.in	25 Sep 2002 19:50:22 -0000
@@ -62,6 +62,9 @@
     i[[34567]]86-*-linux-gnu* ) SUPPORTED="yes";;
     * ) SUPPORTED="no"
 esac
+if test "${SUPPORTED}" = "no" ; then
+    AC_MSG_WARN([Synthetic target ethernet support is only available on x86 Linux hosts])
+fi   
 
 if test "${SUPPORTED}" = "yes" ; then
     AC_PROG_CC
@@ -71,6 +74,17 @@
     ECOS_PROG_MSVC
     ECOS_PROG_STANDARD_COMPILER_FLAGS
     ECOS_PACKAGE_DIRS
+
+    dnl Old kernels may not have tun/tap support. rawether can
+    dnl still operate via a spare ethernet interface.
+    AC_CHECK_HEADERS("linux/if_tun.h",TAP_SUPPORTED="yes",TAP_SUPPORTED="no")
+    if test "${TAP_SUPPORTED}" = "no" ; then
+        AC_MSG_WARN([No <linux/if_tun.h> header, ethertap support disabled.])
+    fi
+fi
+
+if test "${SUPPORTED}" = "no" ; then
+    AC_MSG_WARN([The synthetic ethernet support cannot be built on this platform.])
 fi
 
 AM_CONDITIONAL(SUPPORTED, test "${SUPPORTED}" = "yes")
Index: rawether.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/eth/synth/ecosynth/current/host/rawether.c,v
retrieving revision 1.1
diff -u -u -r1.1 rawether.c
--- rawether.c	15 Sep 2002 17:49:21 -0000	1.1
+++ rawether.c	25 Sep 2002 19:51:13 -0000
@@ -63,7 +63,9 @@
 #include <netinet/if_ether.h>
 #include <linux/if_packet.h>
 #include <linux/if_ether.h>
-#include <linux/if_tun.h>
+#ifdef HAVE_LINUX_IF_TUN_H
+# include <linux/if_tun.h>
+#endif
 
 // The protocol between host and target is defined by a private
 // target-side header.
@@ -98,6 +100,14 @@
 static unsigned char tx_buffer[MTU];
 static unsigned char rx_buffer[MTU+4];
 
+// Indirect to get to the actual implementation functions.
+static void (*tx_fn)(unsigned char*, int);
+static void (*rx_fn)(void);
+static void (*start_fn)(int);
+static void (*stop_fn)(void);
+static void (*multicast_fn)(int);
+
+
 // ----------------------------------------------------------------------------
 // A utility buffer for messages.
 #define MSG_SIZE 256
@@ -304,6 +314,12 @@
 {
     struct sockaddr_ll  addr;
     struct ifreq        request;
+
+    tx_fn           = &real_handle_tx;
+    rx_fn           = &real_handle_rx;
+    start_fn        = &real_handle_start;
+    stop_fn         = &real_handle_stop;
+    multicast_fn    = &real_handle_multiall;
     
     if (strlen(devname) >= IFNAMSIZ) {
         snprintf(msg, MSG_SIZE, "Invalid real network device name \"%s\", too long.\n", devname);
@@ -402,6 +418,10 @@
 // The Linux kernel will invent a MAC address for its interface. An
 // additional one is needed for eCos. This is either invented or
 // specified in the target definition file.
+//
+// Old Linux kernels may not have the required support. This is detected
+// by an autoconf test for <linux/if_tun.h>
+#ifdef HAVE_LINUX_IF_TUN_H
 
 static void
 tap_handle_tx(unsigned char* buffer, int size)
@@ -500,11 +520,18 @@
 {
 }
 
-static void tap_init(int argc, char** argv)
+static void
+tap_init(int argc, char** argv)
 {
     char* devname   = NULL;
     struct ifreq    ifr;
 
+    tx_fn           = &tap_handle_tx;
+    rx_fn           = &tap_handle_rx;
+    start_fn        = &tap_handle_start;
+    stop_fn         = &tap_handle_stop;
+    multicast_fn    = &tap_handle_multiall;
+    
     // Which device? By default let the system pick one, but the user
     // can override this.
     if (0 != argc) {
@@ -561,6 +588,14 @@
     
     // All done.
 }
+#else
+static void
+tap_init(int argc, char** argv)
+{
+    snprintf(msg, MSG_SIZE, "Ethertap support was not available when the host-side support was built\n");
+    report_error(msg);
+}
+#endif  // HAVE_LINUX_IF_TUN_H
 
 // ----------------------------------------------------------------------------
 // Receive a single request from ecosynth. This consists of a four-byte
@@ -640,40 +675,24 @@
                 exit(1);
             }
 
-            if (real_ether) {
-                real_handle_tx(tx_buffer, size);
-            } else if (ethertap) {
-                tap_handle_tx(tx_buffer, size);
-            }
+            (*tx_fn)(tx_buffer, size);
             break;
         }
       case SYNTH_ETH_START:
         {
-            if (real_ether) {
-                real_handle_start(arg);
-            } else if (ethertap) {
-                tap_handle_start(arg);
-            }
+            (*start_fn)(arg);
             break;
         }
 
       case SYNTH_ETH_STOP:
         {
-            if (real_ether) {
-                real_handle_stop();
-            } else if (ethertap) {
-                tap_handle_stop();
-            }
+            (*stop_fn)();
             break;
         }
 
       case SYNTH_ETH_MULTIALL:
         {
-            if (real_ether) {
-                real_handle_multiall(arg);
-            } else if (ethertap) {
-                tap_handle_multiall(arg);
-            }
+            (*multicast_fn)(arg);
             break;
         }
 
@@ -713,11 +732,7 @@
         if (FD_ISSET(0, &read_set)) {
             handle_ecosynth_request();
         } else if (FD_ISSET(ether_fd, &read_set)) {
-            if (real_ether) {
-                real_handle_rx();
-            } else {
-                tap_handle_rx();
-            }
+            (*rx_fn)();
         }
     }
 }
Index: syntheth.sgml
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/eth/synth/ecosynth/current/doc/syntheth.sgml,v
retrieving revision 1.1
diff -u -u -r1.1 syntheth.sgml
--- syntheth.sgml	15 Sep 2002 17:48:57 -0000	1.1
+++ syntheth.sgml	25 Sep 2002 19:49:12 -0000
@@ -237,6 +237,14 @@
 or a module <filename>tun.o</filename> then the appropriate kernel
 documentation should be consulted, for example
 <filename>/usr/src/linux-2.4/Documentation/networking/tuntap.txt</filename>.
+If you are using an old Linux kernel then the ethertap functionality
+may be missing completely. When the <command>rawether</command>
+program is configured and built, the <command>configure</command>
+script will check for a file <filename
+class="headerfile">/usr/include/linux/if_tun.h</filename>. If that
+file is missing then <command>rawether</command> will be built without
+ethertap functionality, and only real ethernet interfaces will be
+supported.
     </para>
     <para>
 The target definition file is used to map eCos network devices on to


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]