[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r20694: {torvm} Bugfix for flyspray 1054, network interface monitoring. Use (in torvm/trunk/build: kamikaze/patches win32 win32/src/torvm-w32)



Author: coderman
Date: 2009-09-29 07:20:30 -0400 (Tue, 29 Sep 2009)
New Revision: 20694

Modified:
   torvm/trunk/build/kamikaze/patches/001-kamikaze-tor-package.patch
   torvm/trunk/build/win32/Makefile
   torvm/trunk/build/win32/src/torvm-w32/torvm.c
   torvm/trunk/build/win32/src/torvm-w32/torvm.h
Log:
Bugfix for flyspray 1054, network interface monitoring. Use Tor geoip file for ISO image.

Modified: torvm/trunk/build/kamikaze/patches/001-kamikaze-tor-package.patch
===================================================================
--- torvm/trunk/build/kamikaze/patches/001-kamikaze-tor-package.patch	2009-09-29 11:15:21 UTC (rev 20693)
+++ torvm/trunk/build/kamikaze/patches/001-kamikaze-tor-package.patch	2009-09-29 11:20:30 UTC (rev 20694)
@@ -314,7 +314,7 @@
 +
 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-09-13 04:52:02.896241715 +0000
++++ b/package/tor/files/tor.init	2009-09-20 12:24:45.820231100 +0000
 @@ -0,0 +1,144 @@
 +#!/bin/sh 
 +# make sure we check the system bin dirs
@@ -488,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-13 04:44:54.320990051 +0000
-@@ -0,0 +1,293 @@
++++ b/package/tor/files/torvminit	2009-09-20 12:23:57.918088545 +0000
+@@ -0,0 +1,294 @@
 +#!/bin/sh
 +# Copyright (C) 2008-2009  The Tor Project, Inc.
 +# See LICENSE file for rights and terms.
@@ -518,7 +518,6 @@
 +ARGS="_ $ARGS _"
 +
 +syslogd >/dev/null 2>&1
-+klogd -c 1 >/dev/null 2>&1
 +
 +clear;echo
 +d "Initializing ..."
@@ -662,6 +661,8 @@
 +
 +echo $ARGS | grep ' DEBUGINIT ' >/dev/null 2>&1
 +if [ $? -eq 0 ]; then
++  klogd -c 1 >/dev/null 2>&1
++  vmr_logdrop
 +  echo 'tty1::askfirst:/bin/ash --login' >> /etc/inittab
 +  echo 'tty2::askfirst:/bin/ash --login' >> /etc/inittab
 +  echo 'tty3::askfirst:/bin/ash --login' >> /etc/inittab
@@ -691,9 +692,9 @@
 +  ifconfig eth0 $IP netmask $MASK up
 +  ifconfig eth0 mtu $MTU
 +  route add default gw $GW
-+  vmr_fwdsetup eth0
++  vmr_fwdsetup eth0 
 +  if [ ! -z $PRIVINTF ]; then
-+    vmr_fwdadd $PRIVINTF
++    vmr_fwdadd $PRIVINTF $PRIVIP
 +  fi
 +  echo $ARGS | grep ' ISDHCP ' >/dev/null 2>&1
 +  if [ $? -eq 0 ]; then
@@ -713,7 +714,7 @@
 +  ifconfig eth0 mtu $MTU
 +  vmr_fwdsetup eth0
 +  if [ ! -z $PRIVINTF ]; then
-+    vmr_fwdadd $PRIVINTF
++    vmr_fwdadd $PRIVINTF $PRIVIP
 +  fi
 +  vmr_opendhcp eth0
 +
@@ -785,8 +786,8 @@
 +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-13 02:12:57.544230377 +0000
-@@ -0,0 +1,206 @@
++++ b/package/tor/files/vmrouter.sh	2009-09-20 12:20:24.704230793 +0000
+@@ -0,0 +1,210 @@
 +#!/bin/sh
 +# Utility script for Tor VM routing
 +# Source or run directly.
@@ -880,7 +881,9 @@
 +  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 -j $cli_postnat_tbl >>$LOG_TO 2>&1
++}
 +
++vmr_logdrop() {
 +  # log default drop targets
 +  iptables -t filter -A INPUT -j LOG >>$LOG_TO 2>&1
 +  iptables -t filter -A FORWARD -j LOG >>$LOG_TO 2>&1
@@ -913,6 +916,7 @@
 +  if [ -z $1 ]; then
 +    return $FAIL
 +  fi
++  iptables -t nat -A $cli_prenat_tbl -i "$1" -p tcp -d "$2" -j ACCEPT >>$LOG_TO 2>&1
 +  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
@@ -929,6 +933,7 @@
 +  if [ -z $1 ]; then
 +    return $FAIL
 +  fi
++  iptables -t nat -D $cli_prenat_tbl -i "$1" -p tcp -d "$2" -j ACCEPT >>$LOG_TO 2>&1
 +  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

Modified: torvm/trunk/build/win32/Makefile
===================================================================
--- torvm/trunk/build/win32/Makefile	2009-09-29 11:15:21 UTC (rev 20693)
+++ torvm/trunk/build/win32/Makefile	2009-09-29 11:20:30 UTC (rev 20694)
@@ -266,10 +266,6 @@
 TORSRC_GIT=git://git.torproject.org/git/tor
 TORSRC_VER=5308eceef3e7287f77d7b10065c9f8341c5dd75b
 
-GEOIP_F=ip-to-country.csv.zip
-GEOIP_URL=http://ip-to-country.webhosting.info/downloads/$(GEOIP_F)
-GEOIP_SUM=cb5234a10504ba2b243fb5b8f59693245ca952d42883cb3191c3287839cc1c1f
-
 TORBUTTON_NAME=torbutton-latest
 TORBUTTON_TGZ=$(TORBUTTON_NAME).tar.gz
 TORBUTTON_SVN=https://tor-svn.freehaven.net/svn/torbutton/
@@ -292,7 +288,7 @@
 
 CACHE_URL_BASE=http://data.peertech.org/pkgcache
 
-TOOLSPKGNAMES=ZLIB GZIP BZIP2 LIBARCH BINUTILS GCCORE GPP MINGWRUN MINGWUTIL MAKE W32API MSYSCORE LIBTOOL MINIRES MSYSZLIB MSYSCRYPT MSYSSSL MSYSSSH AMAKE ACONF PERL NSIS WIX WIXSRC TORBUTTON_XPI GEOIP
+TOOLSPKGNAMES=ZLIB GZIP BZIP2 LIBARCH BINUTILS GCCORE GPP MINGWRUN MINGWUTIL MAKE W32API MSYSCORE LIBTOOL MINIRES MSYSZLIB MSYSCRYPT MSYSSSL MSYSSSH AMAKE ACONF PERL NSIS WIX WIXSRC TORBUTTON_XPI
 SRCPKGNAMES=ZLIBSRC PTHREADS LIBEVENT CMAKE QT SSLSRC GROFF PYTHON PY2EXE GNURX POLIPO SDL WPCAPSRC QEMU KQEMU OVPN BITTORRENT BTPATCH
 ALLPKGNAMES=$(TOOLSPKGNAMES) $(SRCPKGNAMES)
 
@@ -439,11 +435,9 @@
 		( cd $(TORBUTTON_NAME); $(SHELL) makexpi.sh ; ); \
 		mv $(TORBUTTON_NAME)/pkg/*.xpi $(ISODIR)/dl/src/torbutton.xpi ; rm -rf $(TORBUTTON_NAME); \
 	fi; \
-	if [ -f $(WDLDIR)/$(GEOIP_F) ]; then \
-		echo "--- Creating Tor GEOIP file from $(GEOIP_F) source ..."; \
-		$(UNZIP) $(WDLDIR)/$(GEOIP_F) -d tmp; cat tmp/*.csv | cut -d, -f1-3 | sed 's/"//g' > $(ISODIR)/add/GEOIP.TXT; \
-		mkisofs -hide-rr-moved -pad -l -o $(ISODIR)/add/geoip.iso -J $(ISODIR)/add/GEOIP.TXT ; rm -rf tmp; \
-	fi; \
+	echo "--- Creating Tor GEOIP file Tor source ..."; \
+	cat $(SDLDIR)/$(TORSRC_NAME)/src/config/geoip > $(ISODIR)/add/GEOIP.TXT; \
+	mkisofs -hide-rr-moved -pad -l -o $(ISODIR)/add/geoip.iso -J $(ISODIR)/add/GEOIP.TXT ; \
 	echo "--- Creating source archives from win32 tree ..."; \
 	( cd src && tar zcf ../$(ISODIR)/dl/src/torvm-w32.tgz torvm-w32 ); \
 	( cd src && tar zcf ../$(ISODIR)/dl/src/pkg.tgz pkg ); \

Modified: torvm/trunk/build/win32/src/torvm-w32/torvm.c
===================================================================
--- torvm/trunk/build/win32/src/torvm-w32/torvm.c	2009-09-29 11:15:21 UTC (rev 20693)
+++ torvm/trunk/build/win32/src/torvm-w32/torvm.c	2009-09-29 11:20:30 UTC (rev 20694)
@@ -1152,18 +1152,38 @@
         if (getmacaddr (ce->guid, &(ce->macaddr))) {
           linfo ("Interface %s => %s  mac(%s)", name_data, enum_name, ce->macaddr);
         }
+        snprintf(tcpip_string,
+                 sizeof(tcpip_string),
+                 "%s\\%s",
+                 TCPIP_INTF_KEY, enum_name);
+        status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+                              tcpip_string,
+                              0,
+                              KEY_READ,   
+                              &tkey);
+        len = sizeof (name_data);
+        status = RegQueryValueEx(tkey,
+                                 "DhcpDNS",
+                                 NULL,
+                                 &name_type,
+                                 name_data,
+                                 &len);
+        if (status == ERROR_SUCCESS) {
+          ce->dns1 = strdup(name_data);
+        }
+        len = sizeof (name_data);
+        status = RegQueryValueEx(tkey,
+                                 "DhcpWINS",
+                                 NULL,
+                                 &name_type,
+                                 name_data,
+                                 &len);
+        if (status == ERROR_SUCCESS) {
+          ce->dns2 = strdup(name_data);
+        } 
         if (isconnected (ce->guid)) {
           linfo ("Interface %s (%s) is currently connected.", ce->name, ce->macaddr);
           ce->isactive = TRUE;
-          snprintf(tcpip_string,
-                   sizeof(tcpip_string),
-                   "%s\\%s",
-                   TCPIP_INTF_KEY, enum_name);
-          status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-                                tcpip_string,
-                                0,
-                                KEY_READ,   
-                                &tkey);
           if (status == ERROR_SUCCESS) {
             len = sizeof (BOOL);
             status = RegQueryValueEx(tkey,
@@ -1627,8 +1647,7 @@
   return TRUE;
 }
 
-BOOL spawnprocess (PROCESS_INFORMATION * pi,
-                   const TCHAR *cmdline)
+BOOL spawnvmprocess (PROCESS_INFORMATION * pi)
 {
   STARTUPINFO si;
   SECURITY_ATTRIBUTES sattr;
@@ -1686,7 +1705,8 @@
   ZeroMemory( &si, sizeof(si) );
   si.cb = sizeof(si);
   ZeroMemory( &pi, sizeof(pi) );
-  
+ 
+  ldebug ("Entering runvidalia thrmain");
   if (!buildfpath(PATH_FQ, VMDIR_LIB, NULL, "defvidalia.conf", &vcfgtmp)) {
     lerror ("Unable to build path for default vidalia config file."); 
     goto cleanup;
@@ -1803,6 +1823,7 @@
   si.cb = sizeof(si);
   ZeroMemory( &pi, sizeof(pi) );
 
+  ldebug ("Entering runpolipo thrmain");
   if (!buildsyspath(SYSDIR_LCLPROGRAMS, "Vidalia", &dir)) {
     lerror ("Unable to build path for Vidalia programs dir."); 
     goto cleanup;
@@ -1904,6 +1925,86 @@
   return retval;
 }
 
+/* true if same, false if differ in any ip routing relevant manner */
+BOOL equivconns (struct s_rconnelem *a,
+                 struct s_rconnelem *b)
+{
+  if (strcmp(a->guid, b->guid) == 0) {
+    /* Check if any of IP, netmask, gateway, dhcpserver, dns1, or dns2 differ. */
+    if ( strcmp(a->ipaddr, b->ipaddr) ||
+         strcmp(a->netmask, b->netmask) ||
+         strcmp(a->gateway, b->gateway) ||
+         strcmp(a->dhcpsvr, b->dhcpsvr) ||
+         strcmp(a->dns1, b->dns1) ||
+         strcmp(a->dns2, b->dns2) ) {
+      return FALSE;
+    }
+    return TRUE;
+  }
+  return FALSE;
+}
+
+DWORD WINAPI runnetmon (LPVOID arg)
+{
+  t_ctx *ctx = (t_ctx *)arg;
+  DWORD retval = 0;
+  OVERLAPPED overlap;
+  DWORD errorval;
+  DWORD delay = 1000;
+  DWORD numintf;
+  HANDLE hand = NULL;
+  struct s_rconnelem *connlist = NULL;
+  struct s_rconnelem *ce = NULL;
+  struct s_rconnelem *tapconn = NULL;
+  struct s_rconnelem *brconn = NULL;
+  tapconn = ctx->tapconn;
+  brconn = ctx->brconn;
+
+  ldebug ("Entering runnetmon thrmain");
+
+  overlap.hEvent = WSACreateEvent();
+  while (ctx->running) {
+    errorval = NotifyAddrChange(&hand, &overlap);
+    if (errorval != NO_ERROR) {
+      if (WSAGetLastError() != WSA_IO_PENDING) {
+        ldebug("NotifyAddrChange error...%d\n", WSAGetLastError());                       
+      }
+      Sleep(delay);
+    }
+    else {
+      if ( WaitForSingleObject(overlap.hEvent, delay) == WAIT_OBJECT_0 ) {
+        ldebug("IP Address table changed");
+        ce = NULL;
+        numintf = loadnetinfo(&connlist);
+        if (numintf > 0) {
+          ce = connlist;
+          while (ce && ce->istortap != TRUE) {
+            if (strcmp(ce->guid, tapconn->guid) == 0) {
+              if (equivconns(ce, tapconn) == FALSE) {
+                linfo("Tap connection modified, resetting to correct values.");
+                configtap();
+                cleararpcache();
+                flushdns();
+              }
+            }
+            if (strcmp(ce->guid, brconn->guid) == 0) {
+              if (equivconns(ce, brconn) == FALSE) {
+                linfo("Bridge connection modified, resetting to correct values.");
+                configbridge();
+                cleararpcache();
+                flushdns();
+              }
+            }
+            ce = ce->next;
+          }
+        }
+      }
+    }
+  }
+  
+  return retval;
+}
+
 BOOL launchtorvm (PROCESS_INFORMATION * pi,
                   char *  bridgeintf,
                   char *  macaddr,
@@ -1919,7 +2020,7 @@
   LPTSTR dir = NULL;
   LPTSTR iso = NULL;
   LPTSTR isoarg = NULL;
-  LPTSTR drvtype = "virtio"; /* ide, virtio, scsi, etc. */
+  LPTSTR drvtype = "ide"; /* 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; */
@@ -1937,25 +2038,28 @@
     lerror ("Unable to build path for qemu program.");
     return FALSE;
   }
+/*
   if (!buildfpath(PATH_FQ, VMDIR_LIB, NULL, "geoip.iso", &iso)) {
     lerror ("Unable to build path for GeoIP data iso.");
     iso = NULL;
   }
-
+*/
   ZeroMemory( &si, sizeof(si) );
   ZeroMemory( &sattr, sizeof(sattr) );
   ZeroMemory( pi, sizeof(PROCESS_INFORMATION) );
   si.cb = sizeof(si);
-/*  sattr.nLength = sizeof(SECURITY_ATTRIBUTES);
+  sattr.nLength = sizeof(SECURITY_ATTRIBUTES);
   sattr.bInheritHandle = TRUE;
-  sattr.lpSecurityDescriptor = NULL; */
+  sattr.lpSecurityDescriptor = NULL;
   cmd = malloc(CMDMAX);
+/*
   if (iso) {
     isoarg = malloc(CMDMAX);
     snprintf (isoarg, CMDMAX -1,
               "-hdc \"%s\" ",
               iso);
   }
+*/
   ldebug ("Qemu invocation with cmdline: %s and iso path: %s", cmdline, iso ? iso : "");
   if (tapname) {
     snprintf (cmd, CMDMAX -1,
@@ -1982,10 +2086,16 @@
   }
   ldebug ("Launching Qemu with cmd: %s", cmd);
 
-/*
   pipesz = strlen(cmdline);
   CreatePipe(&stdin_rd, &stdin_wr, &sattr, pipesz);
-  SetHandleInformation(stdin_wr, HANDLE_FLAG_INHERIT, 0);
+  SetHandleInformation(stdin_rd, HANDLE_FLAG_INHERIT, 1);
+  SetHandleInformation(stdin_wr, HANDLE_FLAG_INHERIT, 1);
+  si.hStdInput = stdin_rd;
+  stdout_h = GetStdHandle(STD_OUTPUT_HANDLE);
+  SetHandleInformation(stdout_h, HANDLE_FLAG_INHERIT, 1);
+  si.hStdError = stdout_h;
+  si.hStdOutput = stdout_h;
+  si.dwFlags |= STARTF_USESTDHANDLES;
 
   if (! WriteFile(stdin_wr, cmdline, strlen(cmdline), &numwritten, NULL)) {
     lerror ("Failed to write kernel command line to stdin handle.  Error code: %d", GetLastError());
@@ -1994,13 +2104,6 @@
     ldebug ("Wrote %d bytes of cmdline len %d to qemu stdin pipe.", numwritten, strlen(cmdline));
   }
 
-  stdout_h = GetStdHandle(STD_OUTPUT_HANDLE);
-
-  si.hStdError = stdout_h;
-  si.hStdOutput = stdout_h;
-  si.hStdInput = stdin_rd;
-  si.dwFlags |= STARTF_USESTDHANDLES;
-*/
   if( !CreateProcess(NULL,
                      cmd,
                      NULL,
@@ -2524,6 +2627,9 @@
     while (tapconn && tapconn->istortap != TRUE) {
       tapconn = tapconn->next;
     }
+    if (tapconn->istortap) {
+      ctx->tapconn = tapconn;
+    }
 
     dispmsg(" - Configuring network settings");
     if (!installtornpf()) {
@@ -2568,6 +2674,7 @@
       lerror ("Unable to find network interface with a default route.");
       goto shutdown;
     }
+    ctx->brconn = ce;
   }
 
   if (!ctx->vmnop) {
@@ -2581,7 +2688,7 @@
   dispmsg(" - Launching QEMU virtual machine");
   PROCESS_INFORMATION pi;
   if (ctx->vmnop) {
-    if (! spawnprocess(&pi, "qemu.exe")) {
+    if (! spawnvmprocess(&pi)) {
       lerror ("Unable to launch default Qemu instance.");
     }
     /* This mode does nothing but run Qemu with the kernel and virtual disk.
@@ -2600,7 +2707,8 @@
 
   /* need to delay long enough to allow qemu to start and open tap device */
   if (tapconn) {
-    while ( taptimeout-- && isrunning(&pi) && (! isconnected(tapconn->guid)) ) {
+    while ( (taptimeout > 0) && isrunning(&pi) && (! isconnected(tapconn->guid)) ) {
+      taptimeout--;
       ldebug ("Waiting for tap adapter to be connected...");
       Sleep (1000);
     }
@@ -2616,6 +2724,9 @@
     dispmsg ("Network tap device failed to connect to Tor VM.");
     goto shutdown;
   }
+  if (!createthr(&runnetmon, ctx, FALSE)) {
+    lerror("Failed to start netmon thread.");
+  }
   /* XXX: Why does the tap device hang here on a bad start? */
   if (! configtap()) {
     lerror ("Unable to configure tap device.");
@@ -2638,7 +2749,7 @@
   if (ctx->bundle) {
     dispmsg(" - Waiting for Tor control port to open");
     /* try to confirm control port is up before launching vidalia... */
-    int i = 10;
+    int i = 30;
     while ( (!tryconnect(TOR_TAP_VMIP, 9051)) && (i > 0) ) {
       ldebug("Control port connect attempt failed, trying again... [%d left]", i);
       Sleep(1000);

Modified: torvm/trunk/build/win32/src/torvm-w32/torvm.h
===================================================================
--- torvm/trunk/build/win32/src/torvm-w32/torvm.h	2009-09-29 11:15:21 UTC (rev 20693)
+++ torvm/trunk/build/win32/src/torvm-w32/torvm.h	2009-09-29 11:20:30 UTC (rev 20694)
@@ -25,6 +25,8 @@
   LPTSTR  dhcpsvr;
   LPTSTR  svrmacaddr;
   LPTSTR  dhcpname;
+  LPTSTR  dns1;
+  LPTSTR  dns2;
   LPTSTR  driver;
   struct s_rconnelem * next;
 } t_rconnelem;
@@ -39,6 +41,8 @@
   HANDLE        insthnd;
   LPTSTR        netcfgfile;
   LPTSTR        fwcfgfile;
+  struct s_rconnelem * tapconn;
+  struct s_rconnelem * brconn;
 } t_ctx;
 
 #define TORVM_INSTNAME "{1c6870d3-235d-4fb7-828d-25d7f05e2e76}"