--- Makefile.mk 2001/11/20 16:16:36 1.1 +++ Makefile.mk 2001/11/20 16:17:17 @@ -1,5 +1,5 @@ # KLH10 Makefile. -# $Id: Makefile.mk,v 1.1 2001/11/20 16:16:36 paul Exp paul $ +# $Id: Makefile.mk,v 2.5 2001/11/19 12:10:25 klh Exp $ # # Copyright ) 1992, 1993, 2001 Kenneth L. Harrenstien # All Rights Reserved @@ -302,7 +302,7 @@ -DKLH10_DEV_DPRPXX=1 \ -DKLH10_DEV_DPIMP=1 \ -DKLH10_SIMP=0 \ - -DKLH10_NET_TUN=SYS_FREEBSD \ + -DKLH10_NET_TUN=1 \ -DKLH10_MEM_SHARED=1 \ $(TINTFLAGS) \ $(DINTFLAGS) \ --- osdnet.c 2001/11/20 16:21:35 1.1 +++ osdnet.c 2001/11/20 20:30:10 @@ -1,6 +1,6 @@ /* OSDNET.C - OS Dependent Network facilities */ -/* $Id: osdnet.c,v 1.1 2001/11/20 16:21:35 paul Exp paul $ +/* $Id: osdnet.c,v 2.6 2001/11/19 10:32:34 klh Exp $ */ /* Copyright ) 1999, 2001 Kenneth L. Harrenstien ** All Rights Reserved @@ -17,9 +17,6 @@ */ /* * $Log: osdnet.c,v $ - * Revision 1.1 2001/11/20 16:21:35 paul - * Initial revision - * * Revision 2.6 2001/11/19 10:32:34 klh * Solaris port fixups. * @@ -36,6 +33,7 @@ */ #include /* For basic Unix syscalls */ +#include /* The possible configuration macro definitions, with defaults: */ @@ -48,7 +46,7 @@ #endif #ifdef RCSID - RCSID(osdnet_c,"$Id: osdnet.c,v 1.1 2001/11/20 16:21:35 paul Exp paul $") + RCSID(osdnet_c,"$Id: osdnet.c,v 2.6 2001/11/19 10:32:34 klh Exp $") #endif /* Local predeclarations */ @@ -1559,13 +1557,71 @@ */ +static int +run(char *program, ...) +{ + va_list args; + char *argv[9]; + int argc = 0; + int pid; + int status; + + argv[argc++] = program; + va_start(args, program); + while ((argv[argc++] = va_arg(args, char *)) != NULL) + ; + va_end(args); + + pid = fork(); + if (pid < 0) { + return 0; + } + else if (pid > 0) { + waitpid(pid, &status, 0); + if (status != 0) + return 0; + } + else { + execv(program, argv); + exit(1); /* bletch */ + } + return 1; +} + +static int +tun_alloc(char *dev) +{ + struct ifreq ifr; + int fd, err; + + fd = open(dev, O_RDWR); + if (fd < 0) + return fd; + + memset(&ifr, 0, sizeof(ifr)); + + /* Flags: IFF_TUN - TUN device (no Ethernet headers) + * IFF_TAP - TAP device + * IFF_NO_PI - Do not provide packet information + */ + ifr.ifr_flags = IFF_TUN | IFF_NO_PI; + + err = ioctl(fd, TUNSETIFF, (void *) &ifr); + if (err < 0) { + close(fd); + return err; + } + strcpy(dev, ifr.ifr_name); + return fd; +} + int osn_pfinit(register struct osnpf *osnpf, void *arg) { int allowextern = TRUE; /* For now, always try for external access */ int fd; - char tunname[sizeof "/dev/tun000"]; - char *ifnam = tunname + sizeof("/dev/")-1; + char tunname[33]; + char *ifnam; int i = -1; char ipb1[OSN_IPSTRSIZ]; char ipb2[OSN_IPSTRSIZ]; @@ -1597,13 +1653,24 @@ if (DP_DBGFLG) dbprint("Opening TUN device"); +#if CENV_SYS_FREEBSD do { sprintf(tunname, "/dev/tun%d", ++i); } while ((fd = open(tunname, O_RDWR)) < 0 && errno == EBUSY); - +#else + run("/sbin/modprobe", "tun", NULL); + strcpy(tunname, "/dev/misc/net/tun"); + fd = tun_alloc(tunname); +#endif if (fd < 0) esfatal(1, "Couldn't open tunnel device %s", tunname); + ifnam = strrchr(tunname, '/'); + if (ifnam == NULL) + ifnam = tunname; + else + ifnam++; + if (DP_DBGFLG) dbprintln("Opened %s, configuring for local %s, remote %s", ifnam, @@ -1626,17 +1693,18 @@ It should probably match the same network as the local address, especially if planning to connect from other machines. */ -#if 0 /* Hacky method */ +#if !CENV_SYS_FREEBSD /* Hacky method */ { - char cmdbuff[128]; - int res; - sprintf(cmdbuff, "ifconfig %s %s %s up", - ifnam, - ip_adrsprint(ipb1, (unsigned char *)&iplocal), - ip_adrsprint(ipb2, (unsigned char *)&ipremote)); - - if ((res = system(cmdbuff)) != 0) { - esfatal(1, "osn_pfinit: ifconfig failed to initialize tunnel device?"); + int res = run("/sbin/ifconfig", + ifnam, + ip_adrsprint(ipb1, (unsigned char *)&iplocal), + "pointopoint", + ip_adrsprint(ipb2, (unsigned char *)&ipremote), + NULL); + + if (!res) { + esfatal(1, "osn_pfinit: ifconfig failed to initialize device %s?", + ifnam); } } #else --- osdnet.h 2001/11/20 17:15:28 1.1 +++ osdnet.h 2001/11/20 17:15:36 @@ -1,6 +1,6 @@ /* OSDNET.H - OS Dependent Network definitions */ -/* $Id: osdnet.h,v 1.1 2001/11/20 17:15:28 paul Exp paul $ +/* $Id: osdnet.h,v 2.5 2001/11/19 10:34:01 klh Exp $ */ /* Copyright ) 1999, 2001 Kenneth L. Harrenstien ** All Rights Reserved @@ -17,9 +17,6 @@ */ /* * $Log: osdnet.h,v $ - * Revision 1.1 2001/11/20 17:15:28 paul - * Initial revision - * * Revision 2.5 2001/11/19 10:34:01 klh * Solaris port fixups. Removed conflicting ether/arp includes. * @@ -36,7 +33,7 @@ #define OSDNET_INCLUDED 1 #ifdef RCSID - RCSID(osdnet_h,"$Id: osdnet.h,v 1.1 2001/11/20 17:15:28 paul Exp paul $") + RCSID(osdnet_h,"$Id: osdnet.h,v 2.5 2001/11/19 10:34:01 klh Exp $") #endif #include "klh10.h" /* Ensure have config params */ @@ -148,6 +145,11 @@ # include # include # include /* The L2 protocols */ +# endif + +#elif KLH10_NET_TUN +# if CENV_SYS_LINUX +# include # endif #endif --- vmtape.c 2002/01/12 16:47:42 1.1 +++ vmtape.c 2002/01/12 16:48:35 @@ -696,13 +696,11 @@ /* Now verify filenames don't already exist */ if (cfn && (cf = fopen(cfn, "r"))) { - fclose(cf); vmterror(t, "Tape control file \"%.256s\" already exists", cfn); goto badret; } if (df = fopen(dfn, "rb")) { - fclose(df); vmterror(t, "Tape data file \"%.256s\" already exists", dfn); goto badret; } @@ -714,8 +712,6 @@ goto badret; } if (!(df = fopen(dfn, "w+b"))) { - fclose(df); - if (cfn) fclose(cf); vmterror(t, "Cannot create tape data file \"%.256s\": %.80s", dfn, os_strerror(errno)); goto badret;