Skip to content

Commit

Permalink
WIP: fix tun/tap
Browse files Browse the repository at this point in the history
  • Loading branch information
rizhansas committed Sep 16, 2014
1 parent 2eb279c commit 75a397f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions BasiliskII/src/Unix/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ dnl Check that the host supports TUN/TAP devices
AC_CACHE_CHECK([whether TUN/TAP is supported],
ac_cv_tun_tap_support, [
AC_TRY_COMPILE([
#include <sys/socket.h>
#include <string.h>
#if defined(HAVE_LINUX_IF_H) && defined(HAVE_LINUX_IF_TUN_H)
#include <linux/if.h>
#include <linux/if_tun.h>
Expand Down
26 changes: 17 additions & 9 deletions BasiliskII/src/Unix/ether_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
using std::map;
#endif

#define DEBUG 0
#include "debug.h"

#define STATISTICS 0
Expand Down Expand Up @@ -207,17 +206,23 @@ static bool execute_network_script(const char *action)
int pid = fork();
if (pid >= 0) {
if (pid == 0) {
char *args[4];
char *args[4];
args[0] = (char *)net_if_script;
args[1] = net_if_name;
args[2] = (char *)action;
args[3] = NULL;
execv(net_if_script, args);
exit(1);
}
int status;
while (waitpid(pid, &status, 0) != pid);
return WIFEXITED(status) && WEXITSTATUS(status) == 0;
exit(0);
}
int status;
while (waitpid(pid, &status, 0) != pid);
int result1 = WIFEXITED(status);
int result2 = (WEXITSTATUS(status) == 0);
D(bug("WIFEXITED(status): %d\n", result1));
D(bug("(WEXITSTATUS(status) == 0): %d\n", result2));
D(bug("status: (%d), WEXITSTATUS(status): (%d)\n" , status, WEXITSTATUS(status)));
return result1 && result2;
/*return WIFEXITED(status) && WEXITSTATUS(status) == 0;*/
}

return false;
Expand Down Expand Up @@ -324,9 +329,11 @@ bool ether_init(void)
WarningAlert(str);
goto open_error;
}
D(bug("wait for hacking\n"));
char command=getchar();

// Get network config script file path
net_if_script = PrefsFindString("etherconfig");
net_if_script = PrefsFindString("etherconfig");
if (net_if_script == NULL)
net_if_script = ETHERCONFIG_FILE_NAME;

Expand All @@ -336,7 +343,8 @@ bool ether_init(void)
WarningAlert(str);
goto open_error;
}
net_if_name = strdup(ifr.ifr_name);
net_if_name = strdup(ifr.ifr_name);
D(bug("Bring up tun device %s by script.\n", net_if_name));
if (!execute_network_script("up")) {
sprintf(str, GetString(STR_TUN_TAP_CONFIG_WARN), "script execute error");
WarningAlert(str);
Expand Down
4 changes: 2 additions & 2 deletions BasiliskII/src/Unix/tunconfig
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ $IPTABLES -L -n -t nat > /dev/null || exit 1
#########################################################

{
$IPTABLES -t nat -D POSTROUTING -s $TUN_NET -d ! $TUN_NET -j MASQUERADE
$IPTABLES -t nat -D POSTROUTING -s $TUN_NET ! -d $TUN_NET -j MASQUERADE
} >& /dev/null

#########################################################
Expand All @@ -96,7 +96,7 @@ $IPTABLES -L -n -t nat > /dev/null || exit 1
$IFCONFIG $TUN_DEV $TUN_HOST

# masquerade the tun network
$IPTABLES -t nat -A POSTROUTING -s $TUN_NET -d ! $TUN_NET -j MASQUERADE
$IPTABLES -t nat -A POSTROUTING -s $TUN_NET ! -d $TUN_NET -j MASQUERADE
}

exit 0

0 comments on commit 75a397f

Please sign in to comment.