Index: ChangeLog =================================================================== RCS file: /cvsroot/pearpc/pearpc/ChangeLog,v retrieving revision 1.76 diff -u -u -r1.76 ChangeLog --- ChangeLog 8 Sep 2004 10:14:23 -0000 1.76 +++ ChangeLog 10 Sep 2004 21:03:41 -0000 @@ -4,6 +4,7 @@ version 0.4pre (not yet released): - CPU: stfiwx implemented - config: "ppc_start_fullscreen" for starting in fullscreen mode + - POSIX: allow bridging of tun device version 0.3.1 (released 5. September 2004): - JITC_X86: increased translation cache size Index: scripts/ifppc_down =================================================================== RCS file: /cvsroot/pearpc/pearpc/scripts/ifppc_down,v retrieving revision 1.2 diff -u -u -r1.2 ifppc_down --- scripts/ifppc_down 7 May 2004 22:11:52 -0000 1.2 +++ scripts/ifppc_down 10 Sep 2004 21:03:41 -0000 @@ -3,4 +3,19 @@ # IT SHOULD BE OWNED BY ROOT. # ONLY ROOT SHOULD HAVE WRITE-ACCESS TO THIS FILE. # -/sbin/ifconfig ppc down + +. ./scripts/settings + +if [ $BRIDGE ]; then + rm $PPC_INTERFACE.active + brctl delif $BRIDGE_INTERFACE $PPC_INTERFACE + if [ `ls -l *.active | wc -l` == 0 ]; then + # If this is the last ppc interface, down the whole bridge + ifconfig $BRIDGE_INTERFACE down + brctl delbr $BRIDGE_INTERFACE + ifconfig $HOST_INTERFACE $HOST_IP netmask $HOST_NETMASK up + route add -net default gw $HOST_DEFAULT_ROUTER + fi +else +/sbin/ifconfig $PPC_INTERFACE down +fi Index: scripts/ifppc_up =================================================================== RCS file: /cvsroot/pearpc/pearpc/scripts/ifppc_up,v retrieving revision 1.3 diff -u -u -r1.3 ifppc_up --- scripts/ifppc_up 8 May 2004 00:41:06 -0000 1.3 +++ scripts/ifppc_up 10 Sep 2004 21:03:41 -0000 @@ -4,9 +4,29 @@ # ONLY ROOT SHOULD HAVE WRITE-ACCESS TO THIS FILE. # echo UID=$UID -PPC_NETMASK="255.255.255.0" -PPC_HOST_IP="192.168.1.80" -PPC_CLIENT_IP="192.168.1.1" -/sbin/ifconfig ppc $PPC_HOST_IP netmask $PPC_NETMASK up &&\ -/sbin/iptables -t nat -s $PPC_CLIENT_IP -A POSTROUTING -j MASQUERADE &&\ -echo 1 > /proc/sys/net/ipv4/ip_forward + +. ./scripts/settings + +if [ $BRIDGE ]; then + touch $PPC_INTERFACE.active + ifconfig $BRIDGE_INTERFACE 1>/dev/null 2>&1 + if [ $? != 0 ]; then + ifconfig $HOST_INTERFACE 0.0.0.0 + ifconfig $PPC_INTERFACE 0.0.0.0 + brctl addbr $BRIDGE_INTERFACE + brctl addif $BRIDGE_INTERFACE $HOST_INTERFACE + brctl addif $BRIDGE_INTERFACE $PPC_INTERFACE + ifconfig $BRIDGE_INTERFACE $HOST_IP netmask $HOST_NETMASK up + route add -net default gw $HOST_DEFAULT_ROUTER + else + ifconfig $PPC_INTERFACE 0.0.0.0 + brctl addif $BRIDGE_INTERFACE $PPC_INTERFACE + fi +else + PPC_NETMASK="255.255.255.0" + PPC_HOST_IP="192.168.1.80" + PPC_CLIENT_IP="192.168.1.1" + /sbin/ifconfig $PPC_INTERFACE $PPC_HOST_IP netmask $PPC_NETMASK up &&\ + /sbin/iptables -t nat -s $PPC_CLIENT_IP -A POSTROUTING -j MASQUERADE &&\ + echo 1 > /proc/sys/net/ipv4/ip_forward +fi Index: src/system/osapi/posix/sysethtun.cc =================================================================== RCS file: /cvsroot/pearpc/pearpc/src/system/osapi/posix/sysethtun.cc,v retrieving revision 1.5 diff -u -u -r1.5 sysethtun.cc --- src/system/osapi/posix/sysethtun.cc 14 Aug 2004 16:17:59 -0000 1.5 +++ src/system/osapi/posix/sysethtun.cc 10 Sep 2004 21:03:41 -0000 @@ -106,7 +106,7 @@ } // FIXME: How shall we configure networking??? This thing can only be a temporary solution -virtual int execIFConfigScript(const char *arg) +virtual int execIFConfigScript(const char *action, const char *interface) { //sleep(1000000); int pid = fork(); @@ -114,11 +114,12 @@ printf("fork = %d, 0x%08x\n", pid, errno); if (pid == 0) { const char *progname; - if (strcmp(arg, "up") == 0) { + if (strcmp(action, "up") == 0) { progname = upScript(); } else { progname = downScript(); } + setenv("PPC_INTERFACE", interface,0); printf("executing '%s' ...\n" "********************************************************************************\n", progname); execl(progname, progname, 0); @@ -166,12 +167,36 @@ #include class LinuxLikeEthTunDevice: public UnixEthTunDevice { -const char *mIfName; +char *mIfName; public: -LinuxLikeEthTunDevice(const char *netif_name) +LinuxLikeEthTunDevice(const char *netif_prefix) : UnixEthTunDevice() { - mIfName = netif_name; + /* We will allocate the next available interface name */ + int max_ifname = strlen(netif_prefix)+3; + mIfName = (char *)::malloc(max_ifname); + mIfName[0] = 0; + int counter; + char command[100]; + for (counter = 1; counter < 11; counter++) { + ht_snprintf(command, sizeof comand, "ifconfig %s%d 1>/dev/null 2>&1", netif_prefix, counter); + int ret = system(command); + /* OK, if I don't output something in the next line, I get a SIGSEV + /* So my guess it that system() is non blocking and + /* I actually need to wait() for it. But I don't know how yet */ + printf("Scanning interfaces\n"); + if (WEXITSTATUS(ret)) { + ht_snprintf(mIfName, max_ifname, "%s%d", netif_prefix, counter); + printf("mIfName = %s\n", mIfName); + break; + } + } + // FIXME: What if we don't find an interface name? +} + +virtual ~LinuxLikeEthTunDevice() +{ + free(mIfName); } int initDevice() @@ -201,7 +226,7 @@ ::ioctl(mFD, TUNSETNOCSUM, 1); /* Configure device */ - if (execIFConfigScript("up")) { + if (execIFConfigScript("up", mIfName)) { ::close(mFD); throw new MsgException("error executing ifconfig."); } @@ -211,7 +236,7 @@ int shutdownDevice() { /* tear down the device */ - execIFConfigScript("down"); + execIFConfigScript("down", mIfName); ::close(mFD); return 0; } @@ -232,8 +257,8 @@ class LinuxEthTunDevice: public LinuxLikeEthTunDevice { public: -LinuxEthTunDevice(const char *netif_name) -: LinuxLikeEthTunDevice(netif_name) +LinuxEthTunDevice(const char *netif_prefix) +: LinuxLikeEthTunDevice(netif_prefix) { }