[or-cvs] r20570: {torvm} Various networking improvements, add kqemu accelerator as op (in torvm/trunk/build: kamikaze/patches win32 win32/files win32/patches win32/src/torvm-w32)

coderman at seul.org coderman at seul.org
Tue Sep 15 05:40:47 UTC 2009


Author: coderman
Date: 2009-09-15 01:40:47 -0400 (Tue, 15 Sep 2009)
New Revision: 20570

Added:
   torvm/trunk/build/win32/patches/kqemu-gcc-asm.patch
Modified:
   torvm/trunk/build/kamikaze/patches/001-kamikaze-tor-package.patch
   torvm/trunk/build/win32/Makefile
   torvm/trunk/build/win32/files/buildall.sh
   torvm/trunk/build/win32/files/install.bat
   torvm/trunk/build/win32/patches/qemu-winpcap.patch
   torvm/trunk/build/win32/src/torvm-w32/apicommon.c
   torvm/trunk/build/win32/src/torvm-w32/torvm.c
Log:
Various networking improvements, add kqemu accelerator as optional component, minor win32 build script fixes.

Modified: torvm/trunk/build/kamikaze/patches/001-kamikaze-tor-package.patch
===================================================================
--- torvm/trunk/build/kamikaze/patches/001-kamikaze-tor-package.patch	2009-09-15 01:31:42 UTC (rev 20569)
+++ torvm/trunk/build/kamikaze/patches/001-kamikaze-tor-package.patch	2009-09-15 05:40:47 UTC (rev 20570)
@@ -314,8 +314,8 @@
 +
 diff -Naur a/package/tor/files/tor.init b/package/tor/files/tor.init
 --- a/package/tor/files/tor.init	1970-01-01 00:00:00.000000000 +0000
-+++ b/package/tor/files/tor.init	2009-08-19 00:59:09.853905297 +0000
-@@ -0,0 +1,150 @@
++++ b/package/tor/files/tor.init	2009-09-13 04:52:02.896241715 +0000
+@@ -0,0 +1,144 @@
 +#!/bin/sh 
 +# make sure we check the system bin dirs
 +export PATH=/usr/sbin:/sbin:$PATH
@@ -394,11 +394,8 @@
 +		echo "GeoIPFile $GEOIP_F" >> $CONF_F; \
 +	fi; \
 +	chown $RUN_USER:$RUN_GROUP $CONF_F ; \
-+        vmr_fwdadd $TOR_INT
-+        vmr_opentcp $TOR_INTF $MYIP $CTLPORT
-+        vmr_opentcp $TOR_INTF $MYIP $TOR_TRANSPORT
-+        vmr_openudp $TOR_INTF $MYIP $TOR_DNSPORT
 +	vmr_closetcp $TOR_INTF $MYIP $TOR_SOCKSPORT
++	vmr_opentcp $TOR_INTF $MYIP $CTLPORT
 +	if [ "$FOLLOWTOR" = "1" ]; then \
 +	  nohup /etc/init.d/tor dofollow >/dev/null 2>&1 & \
 +        else \
@@ -406,11 +403,8 @@
 +	fi; 
 +
 +elif [ "$1" = "stop" ]; then
-+	vmr_closeudp $TOR_INTF $MYIP $TOR_DNSPORT
-+	vmr_closetcp $TOR_INTF $MYIP $TOR_TRANSPORT
 +	vmr_closetcp $TOR_INTF $MYIP $TOR_SOCKSPORT
 +	vmr_closetcp $TOR_INTF $MYIP $CTLPORT
-+        vmr_fwddel $TOR_INT
 +	killall tor
 +
 +elif [ "$1" = "restart" ]; then
@@ -494,8 +488,8 @@
 +TransListenAddress 0.0.0.0
 diff -Naur a/package/tor/files/torvminit b/package/tor/files/torvminit
 --- a/package/tor/files/torvminit	1970-01-01 00:00:00.000000000 +0000
-+++ b/package/tor/files/torvminit	2009-09-05 23:17:14.921449320 +0000
-@@ -0,0 +1,285 @@
++++ b/package/tor/files/torvminit	2009-09-13 04:44:54.320990051 +0000
+@@ -0,0 +1,293 @@
 +#!/bin/sh
 +# Copyright (C) 2008-2009  The Tor Project, Inc.
 +# See LICENSE file for rights and terms.
@@ -524,7 +518,7 @@
 +ARGS="_ $ARGS _"
 +
 +syslogd >/dev/null 2>&1
-+# do we need it? klogd -c 1 >/dev/null 2>&1
++klogd -c 1 >/dev/null 2>&1
 +
 +clear;echo
 +d "Initializing ..."
@@ -636,8 +630,8 @@
 +
 +[ -f /etc/sysctl.conf ] && sysctl -p >&-
 +
++ifconfig lo 127.0.0.1 netmask 255.0.0.0 up
 +vmr_init
-+ifconfig lo 127.0.0.1 netmask 255.0.0.0 up
 +
 +# XXX need a good way to set this flexibly...
 +TZ='PST8PDT,M3.2.0/2,M11.1.0/2'
@@ -662,6 +656,8 @@
 +grep $PRIVINTF: /proc/net/dev >/dev/null 2>&1
 +if [ $? -eq 0 ]; then
 +  ifconfig $PRIVINTF $PRIVIP netmask 255.255.255.252 up
++else
++  unset PRIVINTF
 +fi
 +
 +echo $ARGS | grep ' DEBUGINIT ' >/dev/null 2>&1
@@ -675,22 +671,6 @@
 +  echo 'tty1::respawn:/etc/init.d/tor status' >> /etc/inittab
 +fi
 +
-+# set any static ARP entries before DHCP / interface up
-+done=0
-+cidx=1
-+while [ $done -eq 0 ]; do
-+  echo $ARGS | grep " ARPENT${cidx}" >/dev/null 2>&1
-+  if [ $? -eq 0 ]; then
-+    CENT=`echo $ARGS | sed "s/.* ARPENT${cidx}=//" | sed 's/ .*//' | sed 's/[^0-9a-fA-F:.-]//g'`
-+    CMAC=`echo $CENT | sed 's/-.*//'`
-+    CIP=`echo $CENT | sed 's/.*-//'`
-+    vmr_setarp eth0 $CIP $CMAC
-+  else
-+    done=1
-+  fi
-+  cidx=`expr $cidx + 1`
-+done
-+
 +# if we're passed IP/routing info then do network pivot, otherwise just use dhcp
 +netup=0
 +echo $ARGS | grep ' IP=' >/dev/null 2>&1
@@ -712,6 +692,9 @@
 +  ifconfig eth0 mtu $MTU
 +  route add default gw $GW
 +  vmr_fwdsetup eth0
++  if [ ! -z $PRIVINTF ]; then
++    vmr_fwdadd $PRIVINTF
++  fi
 +  echo $ARGS | grep ' ISDHCP ' >/dev/null 2>&1
 +  if [ $? -eq 0 ]; then
 +    vmr_opendhcp eth0
@@ -729,6 +712,9 @@
 +  ifconfig eth0 hw ether $MAC
 +  ifconfig eth0 mtu $MTU
 +  vmr_fwdsetup eth0
++  if [ ! -z $PRIVINTF ]; then
++    vmr_fwdadd $PRIVINTF
++  fi
 +  vmr_opendhcp eth0
 +
 +  dn "Trying to get DHCP lease ..."
@@ -753,6 +739,22 @@
 +  d "Check your DHCP server or configure one manually with ifconfig."
 +  d "Remember to start Tor via /etc/init.d/tor start when ready."
 +else
++  # set any static ARP entries AFTER DHCP / interface up
++  done=0
++  cidx=1
++  while [ $done -eq 0 ]; do
++    echo $ARGS | grep " ARPENT${cidx}" >/dev/null 2>&1
++    if [ $? -eq 0 ]; then
++      CENT=`echo $ARGS | sed "s/.* ARPENT${cidx}=//" | sed 's/ .*//' | sed 's/[^0-9a-fA-F:.-]//g'`
++      CMAC=`echo $CENT | sed 's/-.*//'`
++      CIP=`echo $CENT | sed 's/.*-//'`
++      vmr_setarp eth0 $CIP $CMAC
++      cidx=`expr $cidx + 1`
++    else
++      done=1
++    fi
++  done
++
 +  echo $ARGS | grep ' CALLHDDINIT=' >/dev/null 2>&1
 +  if [ $? -eq 0 ]; then
 +    HDDINITF=`echo $ARGS | sed 's/.* CALLHDDINIT=//' | sed 's/ .*//'`
@@ -760,7 +762,7 @@
 +      HDDINITF="/home/tor/${HDDINITF}"
 +    else
 +      if [ ! -f "${HDDINITF}" ]; then
-+        HDDINITF="/proc/self/exists_not"
++        unset HDDINITF
 +      fi
 +    fi
 +    if [ -f "${HDDINITF}" ]; then
@@ -783,31 +785,49 @@
 +fi
 diff -Naur a/package/tor/files/vmrouter.sh b/package/tor/files/vmrouter.sh
 --- a/package/tor/files/vmrouter.sh	1970-01-01 00:00:00.000000000 +0000
-+++ b/package/tor/files/vmrouter.sh	2009-09-06 00:49:21.396238259 +0000
-@@ -0,0 +1,174 @@
++++ b/package/tor/files/vmrouter.sh	2009-09-13 02:12:57.544230377 +0000
+@@ -0,0 +1,206 @@
 +#!/bin/sh
 +# Utility script for Tor VM routing
 +# Source or run directly.
 +
-+export FAIL=99
-+# XXX: right now we don't track error output.
-+
-+CLIENT_BLOCK_TCP_PORTS="445 139 138 137 53 25"
-+TOR_TRANSPORT=9095
-+TOR_DNSPORT=9093
-+LOG_TO=/var/log/vmrouter.log
++if [ -z $CLIENT_BLOCK_TCP_PORTS ]; then
++  CLIENT_BLOCK_TCP_PORTS="445 139 138 137 53 25"
++fi
++if [ -z $TOR_TRANSPORT ]; then
++  TOR_TRANSPORT=9095
++fi
++if [ -z $TOR_DNSPORT ]; then
++  TOR_DNSPORT=9093
++fi
++if [ -z $LOG_TO ]; then
++  LOG_TO=/var/log/vmrouter.log
++fi
 +if [ -z $DOLOG ]; then
 +  export DOLOG=1
 +fi
 +if [ $DOLOG -eq 0 ]; then
 +  LOG_TO=/dev/null
 +fi
++# user defined targets
++if [ -z $trap_tbl ]; then
++  trap_tbl="TRAP"
++fi
++if [ -z $host_filt_tbl ]; then
++  host_filt_tbl="HOSTIN"
++fi
++if [ -z $cli_filt_tbl ]; then
++  cli_filt_tbl="CLIIN"
++fi
++if [ -z $cli_prenat_tbl ]; then
++  cli_prenat_tbl="CLIPRE"
++fi
++if [ -z $cli_postnat_tbl ]; then
++  cli_postnat_tbl="CLIPOST"
++fi
 +
-+trap_tbl="TRAP"
-+host_filt_tbl="HOSTIN"
-+cli_filt_tbl="CLIIN"
-+cli_prenat_tbl="CLIPRE"
-+cli_postnat_tbl="CLIPOST"
++export FAIL=99
++# XXX: right now we don't track error output.
 +
 +vmr_trapon() {
 +  if [ $DOLOG -eq 1 ]; then echo "vmr_trapon:">>$LOG_TO 2>&1; fi
@@ -818,6 +838,7 @@
 +vmr_trapoff() {
 +  if [ $DOLOG -eq 1 ]; then echo "vmr_trapoff:">>$LOG_TO 2>&1; fi
 +  iptables -t filter --flush $trap_tbl >>$LOG_TO 2>&1
++  iptables -t filter -I $trap_tbl -j RETURN >>$LOG_TO 2>&1
 +}
 +
 +vmr_init() {
@@ -829,33 +850,36 @@
 +  iptables -t nat --flush POSTROUTING >>$LOG_TO 2>&1
 +
 +  # default policy drop
-+  #iptables -t filter -P INPUT DROP >>$LOG_TO 2>&1
-+  #iptables -t filter -P FORWARD DROP >>$LOG_TO 2>&1
-+  #iptables -t filter -P OUTPUT DROP >>$LOG_TO 2>&1
-+  iptables -t filter -P INPUT ACCEPT >>$LOG_TO 2>&1
-+  iptables -t filter -P FORWARD ACCEPT >>$LOG_TO 2>&1
-+  iptables -t filter -P OUTPUT ACCEPT >>$LOG_TO 2>&1
++  iptables -t filter -P INPUT DROP >>$LOG_TO 2>&1
++  iptables -t filter -P FORWARD DROP >>$LOG_TO 2>&1
++  iptables -t filter -P OUTPUT DROP >>$LOG_TO 2>&1
 +
 +  # trap table is the global on/off switch for traffic
 +  # use a trap table so that tarpit or drop can be set
 +  # as atomic op across input/forward/output.
 +  iptables -t filter -N $trap_tbl >>$LOG_TO 2>&1
-+  iptables -t filter -I INPUT -g $trap_tbl >>$LOG_TO 2>&1
-+  iptables -t filter -I FORWARD -g $trap_tbl >>$LOG_TO 2>&1
-+  iptables -t filter -I OUTPUT -g $trap_tbl >>$LOG_TO 2>&1
++  iptables -t filter -A $trap_tbl -j RETURN >>$LOG_TO 2>&1
++  iptables -t filter -I INPUT -j $trap_tbl >>$LOG_TO 2>&1
++  iptables -t filter -I FORWARD -j $trap_tbl >>$LOG_TO 2>&1
++  iptables -t filter -I OUTPUT -j $trap_tbl >>$LOG_TO 2>&1
 +
++  # loopback device is exempt from filtering
++  iptables -t filter -I INPUT -i lo -j ACCEPT >>$LOG_TO 2>&1
++  iptables -t filter -I OUTPUT -o lo -j ACCEPT >>$LOG_TO 2>&1
++
 +  # host filter traffic things to/from the VM
 +  iptables -t filter -N $host_filt_tbl >>$LOG_TO 2>&1
-+  iptables -t filter -A INPUT -g $host_filt_tbl >>$LOG_TO 2>&1
++  iptables -t filter -A INPUT -j $host_filt_tbl >>$LOG_TO 2>&1
 +  iptables -t filter -A $host_filt_tbl -j RETURN >>$LOG_TO 2>&1
 +
 +  # client tables for routed traffic
 +  iptables -t filter -N $cli_filt_tbl >>$LOG_TO 2>&1
-+  iptables -t filter -A FORWARD -g $cli_filt_tbl >>$LOG_TO 2>&1
++  iptables -t filter -A $cli_filt_tbl -j RETURN >>$LOG_TO 2>&1
++  iptables -t filter -A FORWARD -j $cli_filt_tbl >>$LOG_TO 2>&1
 +  iptables -t nat -N $cli_prenat_tbl >>$LOG_TO 2>&1
-+  iptables -t nat -A PREROUTING -g $cli_prenat_tbl >>$LOG_TO 2>&1
++  iptables -t nat -A PREROUTING -j $cli_prenat_tbl >>$LOG_TO 2>&1
 +  iptables -t nat -N $cli_postnat_tbl >>$LOG_TO 2>&1
-+  iptables -t nat -A POSTROUTING -g $cli_postnat_tbl >>$LOG_TO 2>&1
++  iptables -t nat -A POSTROUTING -j $cli_postnat_tbl >>$LOG_TO 2>&1
 +
 +  # log default drop targets
 +  iptables -t filter -A INPUT -j LOG >>$LOG_TO 2>&1
@@ -875,10 +899,12 @@
 +  for PORTNUM in $CLIENT_BLOCK_TCP_PORTS; do
 +    iptables -t filter -I $cli_filt_tbl -p tcp --dport $PORTNUM -j DROP >>$LOG_TO 2>&1
 +  done
-+  iptables -t filter -A $cli_filt_tbl -j RETURN >>$LOG_TO 2>&1
 +  iptables -t nat -I $cli_postnat_tbl -o "$1" -j MASQUERADE >>$LOG_TO 2>&1
-+  iptables -t filter -A OUTPUT -o "$1" -j ACCEPT >>$LOG_TO 2>&1
 +  iptables -t filter -I $host_filt_tbl -i "$1" -m state --state ESTABLISHED,RELATED -j ACCEPT >>$LOG_TO 2>&1
++  iptables -t filter -I OUTPUT -o "$1" -j ACCEPT >>$LOG_TO 2>&1
++  # reset the trap target at top of chain
++  iptables -t filter -D OUTPUT -j $trap_tbl >>$LOG_TO 2>&1
++  iptables -t filter -I OUTPUT -j $trap_tbl >>$LOG_TO 2>&1
 +}
 +
 +vmr_fwdadd() {
@@ -889,6 +915,12 @@
 +  fi
 +  iptables -t nat -A $cli_prenat_tbl -i "$1" -p tcp -j REDIRECT --to $TOR_TRANSPORT >>$LOG_TO 2>&1
 +  iptables -t nat -A $cli_prenat_tbl -i "$1" -p udp --dport 53 -j REDIRECT --to $TOR_DNSPORT >>$LOG_TO 2>&1
++  iptables -t nat -A $cli_prenat_tbl -i "$1" -p udp -j DROP >>$LOG_TO 2>&1
++  iptables -t filter -I $host_filt_tbl -i "$1" -p udp ! --dport $TOR_DNSPORT -j DROP >>$LOG_TO 2>&1
++  iptables -t filter -I OUTPUT -o "$1" -j ACCEPT >>$LOG_TO 2>&1
++  # reset the trap target at top of chain
++  iptables -t filter -D OUTPUT -j $trap_tbl >>$LOG_TO 2>&1
++  iptables -t filter -I OUTPUT -j $trap_tbl >>$LOG_TO 2>&1
 +}
 +
 +vmr_fwddel() {
@@ -899,6 +931,8 @@
 +  fi
 +  iptables -t nat -D $cli_prenat_tbl -i "$1" -p tcp -j REDIRECT --to $TOR_TRANSPORT >>$LOG_TO 2>&1
 +  iptables -t nat -D $cli_prenat_tbl -i "$1" -p udp --dport 53 -j REDIRECT --to $TOR_DNSPORT >>$LOG_TO 2>&1
++  iptables -t nat -D $cli_prenat_tbl -i "$1" -p udp -j DROP >>$LOG_TO 2>&1
++  iptables -t filter -D OUTPUT -o "$1" -j ACCEPT >>$LOG_TO 2>&1
 +}
 +
 +vmr_opendhcp() {

Modified: torvm/trunk/build/win32/Makefile
===================================================================
--- torvm/trunk/build/win32/Makefile	2009-09-15 01:31:42 UTC (rev 20569)
+++ torvm/trunk/build/win32/Makefile	2009-09-15 05:40:47 UTC (rev 20570)
@@ -192,10 +192,16 @@
 WPCAPSRC_URL=http://www.winpcap.org/install/bin/$(WPCAPSRC_F)
 WPCAPSRC_SUM=9e147ff344141da0ac76e71c31be7a8036ccba6030adfe208f27a97b793a9299
 
-QEMU_F=qemu-0.10.5.tar.gz
+QEMU_VER=0.10.5
+QEMU_F=qemu-$(QEMU_VER).tar.gz
 QEMU_URL=http://download.savannah.gnu.org/releases/qemu/$(QEMU_F)
 QEMU_SUM=d54f268f5545dd182d96c1b09e79af58efaf2e51695efd1331d560a552d657c1
 
+KQEMU_VER=1.4.0pre1
+KQEMU_F=kqemu-$(KQEMU_VER).tar.gz
+KQEMU_URL=http://www.qemu.org/$(KQEMU_F)
+KQEMU_SUM=bac3e84eae1c867b06cd06ed2bcf563ba8304bd4e5a900880c2abe61b9aab491
+
 OVPN_F=openvpn-2.1_rc15.tar.gz
 OVPN_URL=http://openvpn.net/release/$(OVPN_F)
 OVPN_SUM=66cfe347da6ab29ae39c80527714079cdb5699fdf453f7e031dd2ec0172d13a5
@@ -272,7 +278,7 @@
 
 CACHE_URL_BASE=http://data.peertech.org/pkgcache
 
-ALLPKGNAMES=ZLIB GZIP BZIP2 LIBARCH BINUTILS GCCORE GPP MINGWRUN MINGWUTIL MAKE W32API MSYSCORE LIBTOOL MINIRES MSYSZLIB MSYSCRYPT MSYSSSL MSYSSSH ZLIBSRC PTHREADS LIBEVENT AMAKE ACONF PERL GROFF CMAKE QT NSIS SSLSRC PYTHON PY2EXE WIX WIXSRC GNURX POLIPO SDL WPCAPSRC QEMU TORBUTTON_XPI OVPN GEOIP BITTORRENT BTPATCH
+ALLPKGNAMES=ZLIB GZIP BZIP2 LIBARCH BINUTILS GCCORE GPP MINGWRUN MINGWUTIL MAKE W32API MSYSCORE LIBTOOL MINIRES MSYSZLIB MSYSCRYPT MSYSSSL MSYSSSH ZLIBSRC PTHREADS LIBEVENT AMAKE ACONF PERL GROFF CMAKE QT NSIS SSLSRC PYTHON PY2EXE WIX WIXSRC GNURX POLIPO SDL WPCAPSRC QEMU KQEMU TORBUTTON_XPI OVPN GEOIP BITTORRENT BTPATCH
 
 # adjust if we're dealing with non source, zip or tar archives for a package
 SEVNZIP_OPT_DL=
@@ -293,6 +299,16 @@
 
 $(foreach pkgname,$(ALLPKGNAMES),$(eval $(call DOWNLOAD_exp,$(pkgname))))
 
+PKGENVFILE=pkgenv.sh
+PKGENVSETUP:=echo
+define PKGENV_exp
+_CPKG_F:=$$($(1)_F)
+_CPKG_VER:=$$($(1)_VER)
+PKGENVSETUP:=$(PKGENVSETUP) ; echo $(1)_F=$(_CPKG_F) ; echo $(1)_VER=$(_CPKG_VER)
+endef
+
+$(foreach pkgname,$(ALLPKGNAMES),$(eval $(call PKGENV_exp,$(pkgname))))
+
 # now for primary targets...
 downloads: $(ALLPKGNAMES)
 
@@ -321,7 +337,7 @@
 	if [ -e ../kamikaze/x86-vm/bin/openwrt-x86-vmlinuz ]; then \
 		cp ../kamikaze/x86-vm/bin/openwrt-x86-vmlinuz $(ISODIR)/add/vmlinuz; \
 	fi; \
-	if [ -e $(BUILD_SCP_IDF) ]; then \
+	if [ -e "$(BUILD_SCP_IDF)" ]; then \
 		mkdir $(ISODIR)/ssh; \
 		cp "$(BUILD_SCP_IDF)" $(ISODIR)/ssh/; \
 		echo "$(BUILD_SCP_USER)" > $(ISODIR)/ssh/user; \
@@ -337,6 +353,7 @@
 	fi; \
 	echo "export SEVNZIP_INST=$(SEVNZIP_INST)" >> $(ISODIR)/bldopts; \
 	echo "export SEVNZIP_PKG=$(SEVNZIP_OPT_PKG)" >> $(ISODIR)/bldopts; \
+	$(SHELL) -c "$(PKGENVSETUP)" > $(ISODIR)/dl/src/$(PKGENVFILE) ; chmod +x $(ISODIR)/dl/src/$(PKGENVFILE); \
 	echo "--- Copying packages for ISO image file system ..."; \
 	cp files/autorun.inf files/install.bat $(ISODIR)/; \
 	cp files/*.vbs $(ISODIR)/bin/; \
@@ -346,8 +363,8 @@
 	cp files/prefs.js $(ISODIR)/add/; \
 	gzip -d $(ISODIR)/add/hdd.img.gz; \
 	cp files/fstab $(ISODIR)/bin/; \
-	cp files/buildall.sh $(ISODIR)/dl/src; \
-	cp patches/* $(ISODIR)/dl/src; \
+	cp files/buildall.sh $(ISODIR)/dl/src/; \
+	cp patches/* $(ISODIR)/dl/src/; \
 	cp -a $(addprefix $(WDLDIR)/,$(ALLPKGFILES)) $(ISODIR)/dl/; \
 	tar zxf $(WDLDIR)/$(MINGWRUN_F) bin; mv bin/* $(ISODIR)/bin/;rmdir bin; \
 	$(UNZIP) $(WDLDIR)/$(LIBARCH_F) -d $(ISODIR)/ bin/bsdtar.exe bin/libarchive2.dll; \
@@ -356,6 +373,7 @@
 	$(UNZIP) $(WDLDIR)/$(BZIP2_F) -d $(ISODIR)/; \
 	mv $(ISODIR)/dl/$(PTHREADS_F) $(ISODIR)/dl/src/; \
 	mv $(ISODIR)/dl/$(QEMU_F) $(ISODIR)/dl/src/; \
+	mv $(ISODIR)/dl/$(KQEMU_F) $(ISODIR)/dl/src/; \
 	mv $(ISODIR)/dl/$(GROFF_F) $(ISODIR)/dl/src/; \
 	mv $(ISODIR)/dl/$(CMAKE_F) $(ISODIR)/dl/src/; \
 	mv $(ISODIR)/dl/$(SSLSRC_F) $(ISODIR)/dl/src/; \

Modified: torvm/trunk/build/win32/files/buildall.sh
===================================================================
--- torvm/trunk/build/win32/files/buildall.sh	2009-09-15 01:31:42 UTC (rev 20569)
+++ torvm/trunk/build/win32/files/buildall.sh	2009-09-15 05:40:47 UTC (rev 20570)
@@ -8,6 +8,10 @@
   export CC=gcc
   export DEF_CONF_BUILD="--build=i686-pc-mingw32"
 
+  if [ -f /src/pkgenv.sh ]; then
+    source /src/pkgenv.sh
+  fi
+
   export KERNEL_IMAGE=/src/add/vmlinuz
   export VMHDD_IMAGE=/src/add/hdd.img
   export GEOIP_IMAGE=/src/add/geoip.iso
@@ -118,6 +122,8 @@
   export QEMU_DIR="qemu-${QEMU_VER}"
   export QEMU_FILE="${QEMU_DIR}.tar.gz"
 
+  export KQEMU_DIR="kqemu-${KQEMU_VER}"
+
   export CMAKE_VER="2.6.2"
   export CMAKE_DIR="cmake-${CMAKE_VER}"
   export CMAKE_FILE="cmake-${CMAKE_VER}.tar.gz"
@@ -554,7 +560,6 @@
     --enable-uname-release="Tor VM" \
     --disable-werror \
     --disable-system \
-    --disable-kqemu \
     --disable-vnc-tls \
     --disable-bluez \
     --extra-cflags="-I. -I.. -I/src/$ZLIB_DIR -I/usr/include -I/usr/local/include $WPCAP_INCLUDE -I/src/pthreads-w32 -I/usr/include/SDL" \
@@ -579,6 +584,32 @@
 fi
 
 
+if [[ "$KQEMU_BUILT" != "yes" ]]; then
+  echo "Building kqemu accelerator ..."
+  cd /usr/src
+  KQEMU_DIR="kqemu-${KQEMU_VER}"
+  tar zxf $KQEMU_F
+  cd $KQEMU_DIR
+  if [ -f ../kqemu-gcc-asm.patch ]; then
+    echo "Patching KQemu sources ..."
+    patch -p1 < ../kqemu-gcc-asm.patch
+    if (( $? != 0 )); then
+      echo "ERROR: KQemu patch failed." >&2
+      exit 1
+    fi
+  fi
+  make
+  if (( $? != 0 )); then
+    echo "ERROR: kqemu build failed." >&2
+    exit 1
+  fi
+  cp kqemu.inf $libdir/
+  cp kqemu.sys $libdir/
+  cp LICENSE $licensedir/KQemu-LICENSE.txt
+
+  pkgbuilt KQEMU_BUILT
+fi
+
 if [[ "$W32CTL_BUILT" != "yes" ]]; then
   echo "Building torvm-w32 controller ..."
   cd /usr/src

Modified: torvm/trunk/build/win32/files/install.bat
===================================================================
--- torvm/trunk/build/win32/files/install.bat	2009-09-15 01:31:42 UTC (rev 20569)
+++ torvm/trunk/build/win32/files/install.bat	2009-09-15 05:40:47 UTC (rev 20570)
@@ -18,6 +18,7 @@
 cd %DDIR%
 md bin
 cd /d %ISODRV%
+copy pkgenv.sh %DDRV%%DDIR%\
 cd bin
 copy *.* %DDRV%%DDIR%\bin\
 cd /d %DDRV%

Added: torvm/trunk/build/win32/patches/kqemu-gcc-asm.patch
===================================================================
--- torvm/trunk/build/win32/patches/kqemu-gcc-asm.patch	                        (rev 0)
+++ torvm/trunk/build/win32/patches/kqemu-gcc-asm.patch	2009-09-15 05:40:47 UTC (rev 20570)
@@ -0,0 +1,208 @@
+diff -Naur a/Makefile.winnt b/Makefile.winnt
+--- a/Makefile.winnt	2008-05-30 20:33:34.000000000 +0000
++++ b/Makefile.winnt	2009-09-14 08:14:37.668235490 +0000
+@@ -3,7 +3,7 @@
+ # (c) Filip Navara
+ #
+ OBJECTS = kqemu-win32.o kqemu-mod-i386-win32.o
+-CROSS_PREFIX=i386-mingw32-
++CROSS_PREFIX=
+ 
+ TARGET = kqemu.sys
+ 
+diff -Naur a/common/Makefile b/common/Makefile
+--- a/common/Makefile	2008-05-30 20:33:34.000000000 +0000
++++ b/common/Makefile	2009-09-14 08:16:15.736238552 +0000
+@@ -32,8 +32,8 @@
+ MON_LD=ld
+ ifdef CONFIG_WIN32
+ TARGET=../kqemu-mod-$(ARCH)-win32.o
+-CC=i386-mingw32-gcc
+-LD=i386-mingw32-ld
++CC=gcc
++LD=ld
+ else
+ TARGET=../kqemu-mod-$(ARCH).o
+ CC=gcc
+diff -Naur a/common/i386/monitor_asm.S b/common/i386/monitor_asm.S
+--- a/common/i386/monitor_asm.S	2008-05-30 20:33:34.000000000 +0000
++++ b/common/i386/monitor_asm.S	2009-09-14 07:53:57.128241570 +0000
+@@ -151,9 +151,8 @@
+         jmp *%eax
+                         
+ #define SEG_EXCEPTION(label) \
+-    .section "seg_ex_table", "a" ; \
+-    .long label ; \
+-    .previous
++    .section seg_ex_table, "a" ; \
++    .long label
+ 
+ #ifdef USE_SEG_GP        
+ /* %ebx contains the kqemu_state pointer, %eax the selector, 
+diff -Naur a/common/interp.c b/common/interp.c
+--- a/common/interp.c	2008-05-30 20:33:34.000000000 +0000
++++ b/common/interp.c	2009-09-14 08:04:29.252231223 +0000
+@@ -2456,7 +2456,7 @@
+ #endif
+  next_byte:
+     /* XXX: more precise test */
+-    if (unlikely((pc - (unsigned long)&_start) < MONITOR_MEM_SIZE))
++    if (unlikely((pc - (unsigned long)&start) < MONITOR_MEM_SIZE))
+         raise_exception(s, KQEMU_RET_SOFTMMU);
+     b = ldub_mem_fast(s, pc + s->cpu_state.segs[R_CS].base);
+     pc++;
+@@ -4912,7 +4912,7 @@
+             if (mod == 3 || !(s->cpuid_features & CPUID_FXSR))
+                 goto illegal_op;
+             addr = get_modrm(s, modrm);
+-            if (unlikely((addr - ((unsigned long)&_start - 511)) < 
++            if (unlikely((addr - ((unsigned long)&start - 511)) < 
+                          (MONITOR_MEM_SIZE + 511)))
+                 raise_exception(s, KQEMU_RET_SOFTMMU);
+ #ifdef __x86_64__
+@@ -4934,7 +4934,7 @@
+             if (mod == 3 || !(s->cpuid_features & CPUID_FXSR))
+                 goto illegal_op;
+             addr = get_modrm(s, modrm);
+-            if (unlikely((addr - ((unsigned long)&_start - 511)) < 
++            if (unlikely((addr - ((unsigned long)&start - 511)) < 
+                          (MONITOR_MEM_SIZE + 511)))
+                 raise_exception(s, KQEMU_RET_SOFTMMU);
+ #ifdef __x86_64__
+diff -Naur a/common/kqemu_int.h b/common/kqemu_int.h
+--- a/common/kqemu_int.h	2008-05-30 20:33:34.000000000 +0000
++++ b/common/kqemu_int.h	2009-09-14 08:07:17.832239015 +0000
+@@ -1057,22 +1057,20 @@
+ 
+ #ifdef __x86_64__
+ #define MMU_EXCEPTION(label) \
+-    ".section \"mmu_ex_table\", \"a\"\n"\
+-    ".quad " #label "\n"\
+-    ".previous\n"
++    ".section mmu_ex_table, \"a\"\n"\
++    ".quad " #label "\n"
+ #else
+ #define MMU_EXCEPTION(label) \
+-    ".section \"mmu_ex_table\", \"a\"\n"\
+-    ".long " #label "\n"\
+-    ".previous\n"
++    ".section mmu_ex_table, \"a\"\n"\
++    ".long " #label "\n"
+ #endif
+ 
+-extern char _start;
++extern char start;
+ 
+ static inline uint32_t ldub_mem(struct kqemu_state *s, unsigned long addr)
+ {
+     uint32_t res;
+-    if (unlikely((addr - (unsigned long)&_start) < MONITOR_MEM_SIZE))
++    if (unlikely((addr - (unsigned long)&start) < MONITOR_MEM_SIZE))
+         raise_exception(s, KQEMU_RET_SOFTMMU);
+     asm volatile("1:\n"
+                  "movzbl %1, %0\n" 
+@@ -1085,7 +1083,7 @@
+ static inline uint32_t lduw_mem(struct kqemu_state *s, unsigned long addr)
+ {
+     uint32_t res;
+-    if (unlikely((addr - ((unsigned long)&_start - 1)) < 
++    if (unlikely((addr - ((unsigned long)&start - 1)) < 
+                  (MONITOR_MEM_SIZE + 1)))
+         raise_exception(s, KQEMU_RET_SOFTMMU);
+     asm volatile("1:\n"
+@@ -1099,7 +1097,7 @@
+ static inline uint32_t ldl_mem(struct kqemu_state *s, unsigned long addr)
+ {
+     uint32_t res;
+-    if (unlikely((addr - ((unsigned long)&_start - 3)) < 
++    if (unlikely((addr - ((unsigned long)&start - 3)) < 
+                  (MONITOR_MEM_SIZE + 3)))
+         raise_exception(s, KQEMU_RET_SOFTMMU);
+     asm volatile("1:\n"
+@@ -1114,7 +1112,7 @@
+ static inline uint64_t ldq_mem(struct kqemu_state *s, unsigned long addr)
+ {
+     uint64_t res;
+-    if (unlikely((addr - ((unsigned long)&_start - 7)) < 
++    if (unlikely((addr - ((unsigned long)&start - 7)) < 
+                  (MONITOR_MEM_SIZE + 7)))
+         raise_exception(s, KQEMU_RET_SOFTMMU);
+     asm volatile("1:\n"
+@@ -1161,7 +1159,7 @@
+ 
+ static inline void stb_mem(struct kqemu_state *s, unsigned long addr, uint32_t val)
+ {
+-    if (unlikely((addr - (unsigned long)&_start) < MONITOR_MEM_SIZE))
++    if (unlikely((addr - (unsigned long)&start) < MONITOR_MEM_SIZE))
+         raise_exception(s, KQEMU_RET_SOFTMMU);
+     asm volatile("1:\n"
+                  "movb %b0, %1\n" 
+@@ -1172,7 +1170,7 @@
+ 
+ static inline void stw_mem(struct kqemu_state *s, unsigned long addr, uint32_t val)
+ {
+-    if (unlikely((addr - ((unsigned long)&_start - 1)) < 
++    if (unlikely((addr - ((unsigned long)&start - 1)) < 
+                  (MONITOR_MEM_SIZE + 1)))
+         raise_exception(s, KQEMU_RET_SOFTMMU);
+     asm volatile("1:\n"
+@@ -1184,7 +1182,7 @@
+ 
+ static inline void stl_mem(struct kqemu_state *s, unsigned long addr, uint32_t val)
+ {
+-    if (unlikely((addr - ((unsigned long)&_start - 3)) < 
++    if (unlikely((addr - ((unsigned long)&start - 3)) < 
+                  (MONITOR_MEM_SIZE + 3)))
+         raise_exception(s, KQEMU_RET_SOFTMMU);
+     asm volatile("1:\n"
+@@ -1197,7 +1195,7 @@
+ #if defined (__x86_64__)
+ static inline void stq_mem(struct kqemu_state *s, unsigned long addr, uint64_t val)
+ {
+-    if (unlikely((addr - ((unsigned long)&_start - 7)) < 
++    if (unlikely((addr - ((unsigned long)&start - 7)) < 
+                  (MONITOR_MEM_SIZE + 7)))
+         raise_exception(s, KQEMU_RET_SOFTMMU);
+     asm volatile("1:\n"
+@@ -1220,14 +1218,12 @@
+ 
+ #ifdef __x86_64__
+ #define SEG_EXCEPTION(label) \
+-    ".section \"seg_ex_table\", \"a\"\n"\
+-    ".quad " #label "\n"\
+-    ".previous\n"
++    ".section seg_ex_table, \"a\"\n"\
++    ".quad " #label "\n"
+ #else
+ #define SEG_EXCEPTION(label) \
+-    ".section \"seg_ex_table\", \"a\"\n"\
+-    ".long " #label "\n"\
+-    ".previous\n"
++    ".section seg_ex_table, \"a\"\n"\
++    ".long " #label "\n"
+ #endif
+ 
+ static inline unsigned long compute_eflags_user(struct kqemu_state *s, 
+diff -Naur a/common/monitor.c b/common/monitor.c
+--- a/common/monitor.c	2008-05-30 20:33:34.000000000 +0000
++++ b/common/monitor.c	2009-09-14 08:13:22.708246052 +0000
+@@ -1486,8 +1486,8 @@
+     }
+ }
+ 
+-extern unsigned long __start_seg_ex_table;
+-extern unsigned long __stop_seg_ex_table;
++extern unsigned long _start_seg_ex_table;
++extern unsigned long _stop_seg_ex_table;
+ 
+ static void handle_mon_exception(struct kqemu_state *s, 
+                                  struct kqemu_exception_regs *regs,
+@@ -1496,7 +1496,7 @@
+     unsigned long pc, *p;
+     
+     pc = regs->eip;
+-    for(p = &__start_seg_ex_table; p != &__stop_seg_ex_table; p++) {
++    for(p = &_start_seg_ex_table; p != &_stop_seg_ex_table; p++) {
+         if (*p == pc) goto found;
+     }
+     monitor_panic_regs(s, regs, 

Modified: torvm/trunk/build/win32/patches/qemu-winpcap.patch
===================================================================
--- torvm/trunk/build/win32/patches/qemu-winpcap.patch	2009-09-15 01:31:42 UTC (rev 20569)
+++ torvm/trunk/build/win32/patches/qemu-winpcap.patch	2009-09-15 05:40:47 UTC (rev 20570)
@@ -116,8 +116,8 @@
  typedef struct __sFILE FILE;
 diff -Naur a/net.c b/net.c
 --- a/net.c	2009-05-20 20:46:59.000000000 +0000
-+++ b/net.c	2009-08-20 05:13:47.981451257 +0000
-@@ -1043,6 +1043,261 @@
++++ b/net.c	2009-09-14 06:18:23.292244586 +0000
+@@ -1043,6 +1043,262 @@
  
  #endif /* !_WIN32 */
  
@@ -310,7 +310,7 @@
 +
 +void eth_callback(u_char *user, const struct pcap_pkthdr *phdr, const u_char *pdata)
 +{
-+    if(phdr->len<1501)
++    if(phdr->len)
 +    {
 +        qemu_send_packet(pcap_vc, pdata, phdr->len);
 +    }
@@ -319,11 +319,12 @@
 +/* bad winpcap api only sets these when remote-pcap is enabled. */
 +#define PCAP_OPENFLAG_PROMISCUOUS 1
 +#define PCAP_OPENFLAG_NOCAPTURE_LOCAL 8
-+#define PCAP_READ_TIMEOUT 15
++/* #define PCAP_READ_TIMEOUT 15  use no timeout for faster responsiveness. */
++#define PCAP_READ_TIMEOUT 1
 +
 +int eth_open(char* name)
 +{
-+    const int bufsz = 1520;
++    const int bufsz = 65535;
 +    char errbuf[PCAP_ERRBUF_SIZE];
 +    char* msg;
 +
@@ -363,15 +364,15 @@
 +        pthread_create (&dev->reader_thread, &attr, _pcap_send, (void *)dev);
 +        pthread_attr_destroy(&attr);
 +    }
-+#else /* !defined (USE_READER_THREAD */
++#else /* !defined (USE_READER_THREAD) */
 +#ifdef USE_SETNONBLOCK
 +    /* set ethernet device non-blocking so pcap_dispatch() doesn't hang */
-+    if (pcap_setnonblock (dev->pcaphandle, 1, errbuf) == -1) {
++    if (pcap_setnonblock (pcaphandle, 1, errbuf) == -1) {
 +        msg = "Eth: Failed to set non-blocking: %s\r\n";
 +        printf (msg, errbuf);
 +    }
 +#endif
-+#endif /* !defined (USE_READER_THREAD */
++#endif /* !defined (USE_READER_THREAD) */
 +    return 0;
 +}
 +#endif //CONFIG_PCAP
@@ -379,7 +380,7 @@
  #if defined(CONFIG_VDE)
  typedef struct VDEState {
      VLANClientState *vc;
-@@ -1752,6 +2007,14 @@
+@@ -1752,6 +2008,14 @@
          }
      } else
  #endif
@@ -394,7 +395,7 @@
      if (!strcmp(device, "socket")) {
          if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {
              int fd;
-@@ -1828,6 +2091,9 @@
+@@ -1828,6 +2092,9 @@
  #ifdef CONFIG_VDE
                                         ,"vde"
  #endif

Modified: torvm/trunk/build/win32/src/torvm-w32/apicommon.c
===================================================================
--- torvm/trunk/build/win32/src/torvm-w32/apicommon.c	2009-09-15 01:31:42 UTC (rev 20569)
+++ torvm/trunk/build/win32/src/torvm-w32/apicommon.c	2009-09-15 05:40:47 UTC (rev 20570)
@@ -301,7 +301,8 @@
   HANDLE stdout_rd;
   HANDLE stdout_wr;
   DWORD exitcode;
-  DWORD opts = CREATE_NEW_PROCESS_GROUP;
+  /* Make sure interface configuration and other tasks operate quickly. */
+  DWORD opts = CREATE_NEW_PROCESS_GROUP | HIGH_PRIORITY_CLASS;
   DWORD bufsz, numread;
   CHAR * buff = NULL;
    
@@ -346,7 +347,7 @@
   buff = malloc(bufsz);
   while ( GetExitCodeProcess(pi.hProcess, &exitcode) && (exitcode == STILL_ACTIVE) ) {
     while (ReadFile(stdout_rd, buff, bufsz-1, &numread, NULL) && (numread > 0)) {
-      buff[bufsz-1] = 0;
+      buff[numread] = 0;
       ldebug ("runcommand output: %s", buff);
     }
     Sleep (500);

Modified: torvm/trunk/build/win32/src/torvm-w32/torvm.c
===================================================================
--- torvm/trunk/build/win32/src/torvm-w32/torvm.c	2009-09-15 01:31:42 UTC (rev 20569)
+++ torvm/trunk/build/win32/src/torvm-w32/torvm.c	2009-09-15 05:40:47 UTC (rev 20570)
@@ -233,6 +233,7 @@
     WriteFile(hnd, msg, strlen(msg), NULL, NULL);
     msg = "\r\n";
     WriteFile(hnd, msg, strlen(msg), NULL, NULL);
+    FlushFileBuffers(hnd);
   }
 }
 
@@ -632,7 +633,6 @@
 
 BOOL savenetconfig(void)
 {
-#define READSIZE 4096
   HANDLE fh = NULL;
   HANDLE stdin_rd = NULL;
   HANDLE stdin_wr = NULL;
@@ -721,8 +721,8 @@
   CloseHandle(stdin_rd);
   CloseHandle(stdin_wr);
 
-  buff = malloc(READSIZE);
-  while (ReadFile(stdout_rd, buff, READSIZE, &numread, NULL) && (numread > 0)) {
+  buff = malloc(CMDMAX);
+  while (ReadFile(stdout_rd, buff, CMDMAX, &numread, NULL) && (numread > 0)) {
     WriteFile(fh, buff, numread, &numwritten, NULL);
     ldebug ("Read %d bytes from net dump and wrote %d to save file.", numread, numwritten);
   }
@@ -740,13 +740,20 @@
 
 BOOL restorenetconfig(void)
 {
+  HANDLE stdin_rd = NULL;
+  HANDLE stdin_wr = NULL;
+  HANDLE stdout_rd = NULL;
+  HANDLE stdout_wr = NULL;
   STARTUPINFO si;
   PROCESS_INFORMATION pi;
+  SECURITY_ATTRIBUTES sattr;
   LPTSTR cmd = NULL;
   LPTSTR dir = NULL;
   LPTSTR savepath = NULL;
   DWORD exitcode;
   DWORD opts = 0;
+  DWORD numread;
+  CHAR * buff = NULL;
 
   if (getosversion() >= OS_VISTA) {
     cmd = "\"netsh.exe\" advfirewall import \"" TOR_VM_STATE "\\firewall.wfw\"";
@@ -765,9 +772,23 @@
 
   ZeroMemory( &pi, sizeof(pi) );
   ZeroMemory( &si, sizeof(si) );
+  ZeroMemory( &sattr, sizeof(sattr) );
   si.cb = sizeof(si);
+  sattr.nLength = sizeof(SECURITY_ATTRIBUTES);
+  sattr.bInheritHandle = TRUE;
   cmd = "\"netsh.exe\" exec netcfg.save";
 
+  CreatePipe(&stdout_rd, &stdout_wr, &sattr, 0);
+  SetHandleInformation(stdout_rd, HANDLE_FLAG_INHERIT, 0);
+
+  CreatePipe(&stdin_rd, &stdin_wr, &sattr, 0);
+  SetHandleInformation(stdin_wr, HANDLE_FLAG_INHERIT, 0);
+
+  si.hStdError = stdout_wr;
+  si.hStdOutput = stdout_wr;
+  si.hStdInput = stdin_rd;
+  si.dwFlags |= STARTF_USESTDHANDLES;
+
   if( !CreateProcess(NULL,
                      cmd,
                      NULL,   // process handle no inherit
@@ -781,10 +802,21 @@
     lerror ("Failed to launch process.  Error code: %d", GetLastError());
   }
 
+  CloseHandle(stdout_wr);
+  CloseHandle(stdin_rd);
+  CloseHandle(stdin_wr);
+
+  buff = malloc(CMDMAX);
   while ( GetExitCodeProcess(pi.hProcess, &exitcode) && (exitcode == STILL_ACTIVE) ) {
+    while (ReadFile(stdout_rd, buff, CMDMAX-1, &numread, NULL) && (numread > 0)) {
+      buff[numread] = 0;
+      ldebug("Restore net config cmd stdout: %s", buff);
+    }
     Sleep (500);
   }
 
+  free(buff);
+  CloseHandle(stdout_rd);
   CloseHandle(pi.hThread);
   CloseHandle(pi.hProcess);
 
@@ -1619,7 +1651,7 @@
   TCHAR *cmd = malloc(CMDMAX);
   /* TODO: clean this up once the msys path munging works.  kernel and hdd need to be unixy paths */
   snprintf (cmd, CMDMAX -1,
-            "\"%s\" -L . -no-reboot -kernel ../lib/vmlinuz -append \"loglevel=9 NOINIT\" -drive file=../state/hdd.img,if=virtio -m %d -sdl -vga std", qemubin, QEMU_DEF_MEM);
+            "\"%s\" -L . -no-kqemu -clock dynticks -no-reboot -kernel ../lib/vmlinuz -append \"loglevel=9 NOINIT\" -drive file=../state/hdd.img,if=virtio -m %d -sdl -vga std", qemubin, QEMU_DEF_MEM);
   ldebug ("Launching Qemu with cmd: %s", cmd);
   if( !CreateProcess(NULL,
                      cmd,
@@ -1836,7 +1868,7 @@
           && (exitcode == STILL_ACTIVE)
           && (ctx->running) ) {
       while (ReadFile(stdout_rd, buff, bufsz-1, &numread, NULL) && (numread > 0)) {
-        buff[bufsz-1] = 0;
+        buff[numread] = 0;
         ldebug ("polipo std output: %s", buff);
       }
       Sleep (500);
@@ -1887,10 +1919,12 @@
   LPTSTR dir = NULL;
   LPTSTR iso = NULL;
   LPTSTR isoarg = NULL;
+  LPTSTR drvtype = "virtio"; /* ide, virtio, scsi, etc. */
   /* If Tor VM Qemu instance is not below normal prio, performance of host suffers. */
   /* DWORD opts = CREATE_NEW_PROCESS_GROUP | BELOW_NORMAL_PRIORITY_CLASS; */
   /* DWORD opts = CREATE_NEW_PROCESS_GROUP | HIGH_PRIORITY_CLASS; */
-  DWORD opts = CREATE_NEW_PROCESS_GROUP | ABOVE_NORMAL_PRIORITY_CLASS;
+  /* DWORD opts = CREATE_NEW_PROCESS_GROUP | ABOVE_NORMAL_PRIORITY_CLASS; */
+  DWORD opts = CREATE_NEW_PROCESS_GROUP;
   DWORD numwritten;
   DWORD pipesz;
   LPTSTR qemubin = NULL;
@@ -1925,9 +1959,10 @@
   ldebug ("Qemu invocation with cmdline: %s and iso path: %s", cmdline, iso ? iso : "");
   if (tapname) {
     snprintf (cmd, CMDMAX -1,
-              "\"%s\" -name \"Tor VM \" -L . -no-reboot -kernel ../lib/vmlinuz -append \"%s\" -drive file=../state/hdd.img,if=virtio %s-m %d -sdl -vga std -net nic,model=virtio,macaddr=%s -net pcap,devicename=\"%s\" -net nic,model=virtio -net tap,ifname=\"%s\"",
+              "\"%s\" -name \"Tor VM\" -L . -no-kqemu -clock dynticks -no-reboot -kernel ../lib/vmlinuz -append \"%s\" -drive file=../state/hdd.img,if=%s %s-m %d -sdl -vga std -net nic,model=virtio,macaddr=%s -net pcap,devicename=\"%s\" -net nic,model=virtio -net tap,ifname=\"%s\"",
 	      qemubin,
               cmdline,
+              drvtype,
               iso ? isoarg : "",
               QEMU_DEF_MEM,
               macaddr,
@@ -1936,9 +1971,10 @@
   }
   else {
     snprintf (cmd, CMDMAX -1,
-              "\"%s\" -name \"Tor VM \" -L . -no-reboot -kernel ../lib/vmlinuz -append \"%s\" -drive file=../state/hdd.img,if=virtio %s-m %d -sdl -vga std -net nic,model=virtio,macaddr=%s -net pcap,devicename=\"%s\"",
+              "\"%s\" -name \"Tor VM\" -L . -no-kqemu -clock dynticks -no-reboot -kernel ../lib/vmlinuz -append \"%s\" -drive file=../state/hdd.img,if=%s %s-m %d -sdl -vga std -net nic,model=virtio,macaddr=%s -net pcap,devicename=\"%s\"",
 	      qemubin,
               cmdline,
+              drvtype,
               iso ? isoarg : "",
               QEMU_DEF_MEM,
               macaddr,
@@ -2506,12 +2542,6 @@
         lerror ("Unable to disable windows firewall.");
       }
     }
-    if (! cleararpcache()) {
-      lerror ("Unable to clear arp cache.");
-    }
-    if (! flushdns()) {
-      lerror ("Unable to flush cached DNS entries.");
-    }
   }
 
   /* all invocations past this point need a virtual disk at minimum */
@@ -2582,13 +2612,22 @@
     goto shutdown;
   }
   if (! isconnected(tapconn->guid)) {
-    lerror ("Network tap device is not connected to VM.");
+    lerror ("Network tap device failed to connect to Tor VM.");
+    dispmsg ("Network tap device failed to connect to Tor VM.");
     goto shutdown;
   }
+  /* XXX: Why does the tap device hang here on a bad start? */
   if (! configtap()) {
     lerror ("Unable to configure tap device.");
+    dispmsg ("Unable to configure tap device.");
     goto shutdown;
   }
+  if (! cleararpcache()) {
+    lerror ("Unable to clear arp cache.");
+  }
+  if (! flushdns()) {
+    lerror ("Unable to flush cached DNS entries.");
+  }
 
   /* XXX: temp hack - in bundle mode launch Vidalia with a custom config
    * for the 10.x tap control port and externally managed Tor instance.
@@ -2649,6 +2688,11 @@
   }
 
   if (isrunning(&pi)) {
+    /* XXX: One more flush to clear cached negative lookups before boostrap? */
+    if (! flushdns()) {
+      lerror ("Unable to flush cached DNS entries.");
+    }
+
     dispmsg("");
     dispmsg("GOOD! Tor VM is running.");
     dispmsg(" - Waiting for VM to exit ...");



More information about the tor-commits mailing list