From: Mark-Andre H. <ho...@in...> - 2000-09-26 16:11:11
|
Hi Jeff, On 09:39 Tue, 26 Sep, Jeff Dike wrote: > Sure. Pretty it up and send it in. Okay, it's attached below. I tried to keep these changes very small, which resulted in a rather stupid kludge. (I've marked it with comments.) UML with the debian 2.2 is running fine with 2.4.0-test7 as a host system but not with -test8. Don't know what the trouble is. > What's the tun device, anyway? Is it something new or is it the 2.4 > replacement for the tap device or something? It's a replacement for the old ethertap device which is replaced by the `Universal TUN/TAP device driver support'. From the help page: When a program opens /dev/net/tun, the driver creates and registers a corresponding net device tunX or tapX. After the program closed above devices, the driver will automatically delete tunXX or tapXX device and all routes corresponding to it. Bye, Mark diff -ruP uml-net-tools/Makefile uml-net-tools.new/Makefile --- uml-net-tools/Makefile Mon Jul 24 20:45:32 2000 +++ uml-net-tools.new/Makefile Tue Sep 26 16:10:59 2000 @@ -5,10 +5,13 @@ all: um_eth_net_util um_eth_net_set um_eth_net_phy.o: um_eth_net_phy.c um_eth_net.h -um_eth_net_tap.o: um_eth_net_tap.c um_eth_net.h -um_eth_net_util.o: um_eth_net_util.c um_eth_net.h +um_eth_net_tap.o: um_eth_net_tap.c um_eth_net.h config.h +um_eth_net_util.o: um_eth_net_util.c um_eth_net.h config.h um_eth_net_set.o: um_eth_net_set.c um_eth_net.h +config.h: makeconf.sh + sh makeconf.sh > config.h + um_eth_net_util: $(UTIL_OBJS) gcc $(CFLAGS) -o $@ $(UTIL_OBJS) @@ -19,4 +22,4 @@ cd .. ; tar --exclude=CVS -zcf um_eth_net-0.005.tar.gz net/ clean: - rm -rf um_eth_net_util um_eth_net_set *.o core *~ + rm -rf um_eth_net_util um_eth_net_set config.h *.o core *~ diff -ruP uml-net-tools/makeconf.sh uml-net-tools.new/makeconf.sh --- uml-net-tools/makeconf.sh Thu Jan 1 01:00:00 1970 +++ uml-net-tools.new/makeconf.sh Tue Sep 26 16:13:02 2000 @@ -0,0 +1,10 @@ +#!/bin/sh + +cat << EOF +/* Generated automatically by makeconf.sh */ + +EOF + +if test -f /usr/include/linux/if_tun.h ; then + echo "#define HAS_UNIVERSAL_TUNTAP 1" +fi diff -ruP uml-net-tools/um_eth_net.h uml-net-tools.new/um_eth_net.h --- uml-net-tools/um_eth_net.h Mon Jul 24 20:42:47 2000 +++ uml-net-tools.new/um_eth_net.h Tue Sep 26 16:26:37 2000 @@ -29,6 +29,6 @@ extern int packet_output(int, unsigned char *, int); extern int socket_phy_setup(char *); -extern int socket_tap_setup(char *); +extern int socket_tap_setup(char *, int *); #endif diff -ruP uml-net-tools/um_eth_net_tap.c uml-net-tools.new/um_eth_net_tap.c --- uml-net-tools/um_eth_net_tap.c Mon Jul 24 20:42:47 2000 +++ uml-net-tools.new/um_eth_net_tap.c Tue Sep 26 17:50:36 2000 @@ -5,19 +5,44 @@ #include <fcntl.h> #include <errno.h> #include "um_eth_net.h" +#include "config.h" -int socket_tap_setup(char *name) { +#ifdef HAS_UNIVERSAL_TUNTAP +#include <unistd.h> +#include <sys/ioctl.h> +#include <net/if.h> +#include <linux/if_tun.h> +#endif + +int socket_tap_setup(char *name, int *headsize) { char nbuf[16]; int retval = -EINVAL; int new_fd; - if(!strncmp(name,"tap",3)) { - sprintf(nbuf,"/dev/%s",name); - if((new_fd = open(nbuf,O_RDWR|O_NONBLOCK)) < 0) { - perror(nbuf); - } else { - retval = new_fd; + if(strncmp(name,"tap",3)) + return retval; + +#ifdef HAS_UNIVERSAL_TUNTAP + if((new_fd = open("/dev/net/tun",O_RDWR)) >= 0) { + struct ifreq ifr; + memset(&ifr,0,sizeof(ifr)); + ifr.ifr_flags = IFF_TAP | IFF_NO_PI; + if(ioctl(new_fd,TUNSETIFF,(void *)&ifr) < 0) { + perror("/dev/net/tun"); + close(new_fd); + return retval; } + *headsize = 0; + return new_fd; + } +#endif + + sprintf(nbuf,"/dev/%s",name); + if((new_fd = open(nbuf,O_RDWR|O_NONBLOCK)) < 0) { + perror(nbuf); + } else { + *headsize = 2; + return new_fd; } return retval; diff -ruP uml-net-tools/um_eth_net_util.c uml-net-tools.new/um_eth_net_util.c --- uml-net-tools/um_eth_net_util.c Mon Jul 24 20:42:47 2000 +++ uml-net-tools.new/um_eth_net_util.c Tue Sep 26 16:33:09 2000 @@ -109,9 +109,20 @@ exit(-1); } for(in=1;in<argc;in+=2) { - if((new_fd = socket_tap_setup(argv[in])) > 0) { + int headsize; + if((new_fd = socket_tap_setup(argv[in], &headsize)) > 0) { fprintf(stderr,"TAP: %s\n",argv[in]); - type = SOCKET_TAP; + /* this is a dirty kludge to avoid a lot of changes: */ + switch(headsize) { + case 0: + type = SOCKET_PHY; break; + case 2: + type = SOCKET_TAP; break; + default: + fprintf(stderr, "unknown header size before tap packet\n"); + exit(EXIT_FAILURE); + } + /* end of kludge */ } else if((new_fd = socket_phy_setup(argv[in])) > 0) { fprintf(stderr,"PHY: %s\n",argv[in]); type = SOCKET_PHY; -- mar...@in... software engineer innominate AG server appliances networking people tel: +49.30.308806-19 fax: -77 http://innominate.de |