net: Support bridged network on macosx 96/36096/15
authorMunkyu Im <munkyu.im@samsung.com>
Mon, 2 Mar 2015 09:33:30 +0000 (18:33 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 12 Mar 2015 08:21:01 +0000 (01:21 -0700)
Emulator is able to use bridged network now.
supported only wired network(en0) currently.

Change-Id: I0157f61aac01fe42655b01eb12d98ffbe9b1cfc5
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
net/tap.c
package/emulator-qemu-common.install.macos-64
tizen/src/Makefile
tizen/src/scripts/emulator-ifup.sh [new file with mode: 0755]
tizen/src/util/check_net_darwin.c

index 7bd199cec63d87a5bbdfbef6b6510bd611aa8c34..53057ec0470c2bed0d1288aceb653a4b8d8e3e7b 100644 (file)
--- a/net/tap.c
+++ b/net/tap.c
@@ -47,6 +47,7 @@
 #include "tizen/src/emul_state.h"
 #endif
 
+#include "tizen/src/emul_state.h"
 typedef struct TAPState {
     NetClientState nc;
     int fd;
@@ -362,7 +363,13 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
 static int launch_script(const char *setup_script, const char *ifname, int fd)
 {
     int pid, status;
+#if defined(CONFIG_DARWIN) && defined(CONFIG_MARU)
+    char *args[5];
+    const gchar* cocoasudo_path = g_strdup_printf("%scocoasudo", get_bin_path());
+    const char* message = "--prompt=Emulator needs privileged mode to setup bridged network.";
+#else
     char *args[3];
+#endif
     char **parg;
 
     /* try to launch network script */
@@ -376,10 +383,18 @@ static int launch_script(const char *setup_script, const char *ifname, int fd)
             }
         }
         parg = args;
+#if defined(CONFIG_DARWIN) && defined(CONFIG_MARU)
+        *parg++ = (char *)cocoasudo_path;
+        *parg++ = (char *)message;
+#endif
         *parg++ = (char *)setup_script;
         *parg++ = (char *)ifname;
         *parg = NULL;
+#if defined(CONFIG_DARWIN) && defined(CONFIG_MARU)
+        execv(cocoasudo_path, args);
+#else
         execv(setup_script, args);
+#endif
         _exit(1);
     } else if (pid > 0) {
         while (waitpid(pid, &status, 0) != pid) {
index 306e5932456528591fca933101dbbe96049824f4..dea8b06e3fd140663319eae703ef577382464038 100755 (executable)
@@ -2,20 +2,40 @@
 
 TIZEN_SDK_INSTALL_PATH=`echo $INSTALLED_PATH`
 OLD_SHMMAXSIZE=`sysctl -n kern.sysv.shmmax`
-COCOASUDOPATH="./cocoasudo"
 SYSCTL_FILE=sysctl.conf
 TMP_DIR=~/.installmanager
 TIZEN_BIN_PATH=$TIZEN_SDK_INSTALL_PATH/tools/emulator/bin
-#TIZEN_BIN_PATH=./
 TMP_FILE=$TMP_DIR/setshmmax.sh
+TMP_INSTALL_TAP_FILE=$TMP_DIR/install-tap.sh
 NEW_SHMMAXSIZE=83886080
-
 if [ -z $TIZEN_SDK_INSTALL_PATH ]
 then
    echo "There is no TIZEN_SDK_PATH ENV" >> /tmp/emulator.log
 #   exit 2;
 fi
 
+function install_tap {
+    echo 'make new install-tap.sh file'
+
+    if [ ! -d $TMP_DIR ]
+    then
+            mkdir $TMP_DIR
+    fi
+    cat << 'EOF' >> $TMP_INSTALL_TAP_FILE
+#!/bin/sh
+mkdir -p /Library/Extensions
+cp -pR tap.kext /Library/Extensions/
+chown -R root:wheel /Library/Extensions/tap.kext
+mkdir -p /Library/LaunchDaemons
+cp /Library/Extensions/tap.kext/Contents/net.sf.tuntaposx.tap.plist /Library/LaunchDaemons
+/sbin/kextload /Library/Extensions/tap.kext
+EOF
+    /bin/chmod +x $TMP_INSTALL_TAP_FILE
+    echo 'launch install-tap.sh'
+    $TIZEN_BIN_PATH/cocoasudo "--prompt=Installing tun/tap driver requires that you type your password." sh -x $TMP_INSTALL_TAP_FILE
+    rm -f $TMP_INSTALL_TAP_FILE
+}
+
 function remove_tmp_file {
     if [ -e $TMP_FILE ]
     then
@@ -24,7 +44,7 @@ function remove_tmp_file {
     fi
 }
 
-function remove_sysctl_file { 
+function remove_sysctl_file {
     if [ -e $TMP_DIR/$SYSCTL_FILE ]
     then
         echo 'delete ~/tmp/sysctl.conf'
@@ -50,7 +70,7 @@ function makesysctl {
 
 }
 
-if [ $OLD_SHMMAXSIZE -lt $NEW_SHMMAXSIZE ] 
+if [ $OLD_SHMMAXSIZE -lt $NEW_SHMMAXSIZE ]
 then
        if [ -e /etc/$SYSCTL_FILE ]
        then
@@ -67,18 +87,17 @@ then
                    echo "cp -f $TMP_DIR/$SYSCTL_FILE /etc/." >> $TMP_FILE
                    echo "sysctl -w kern.sysv.shmmax=$NEW_SHMMAXSIZE" >> $TMP_FILE
                    chmod +x $TMP_FILE
-                   $TIZEN_BIN_PATH/cocoasudo "--prompt=Make a new /etc/sysctl.conf file requires that you type your password." sh -x $TMP_FILE 
+                   $TIZEN_BIN_PATH/cocoasudo "--prompt=Make a new /etc/sysctl.conf file requires that you type your password." sh -x $TMP_FILE
        fi
 fi
 
 remove_tmp_file;
 remove_sysctl_file;
-
+install_tap;
 CURRENT_SHMMAXSIZE=`sysctl -n kern.sysv.shmmax`
 
 if [ ! $OLD_SHMMAXSIZE -eq $CURRENT_SHMMAXSIZE ]
 then
-               
        echo 'need reboot'
        exit 99
 fi
index 38152bebefad3d242d12c1f0f1367b764a6d2e6c..921124a0ca485d0bd25b79b4ab67d3d3827566f5 100644 (file)
@@ -199,6 +199,7 @@ endif
 # give a title name for sdb terminal.
 ifdef CONFIG_DARWIN
        cp -pP scripts/sdbscript $(EMUL_DIR)/bin
+       cp -pP scripts/emulator-ifup.sh $(EMUL_DIR)/bin
 endif
 
 # use shared memory for display framebuffer
diff --git a/tizen/src/scripts/emulator-ifup.sh b/tizen/src/scripts/emulator-ifup.sh
new file mode 100755 (executable)
index 0000000..2a0ed71
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh -x
+BRIDGE=bridge1
+TAP=$1
+BASE=en0
+
+#get base network information
+IP=`ipconfig getifaddr $BASE`
+NETMASK=`ifconfig $BASE | grep "inet " | awk '{print $4}'`
+GW=`netstat -rn | grep ^default | awk '{print $2}'`
+
+#create bridge interface
+CHECK_BR=`ifconfig | grep ^bridge1:`
+if [ "$CHECK_BR" = "" ]
+then
+    ifconfig $BRIDGE create
+fi
+
+#add base network and tap device to bridge
+ifconfig $BRIDGE addm $BASE
+ifconfig $BRIDGE addm $TAP
+ifconfig $BRIDGE up
+
+#set IP of base network to bridge
+ifconfig $BASE delete $IP
+ifconfig $BRIDGE $IP netmask $NETMASK
+
+#change network interface of default gateway
+NET=`netstat -rn | grep ^default | awk '{print $6}'`
+if [ $NET != $BRIDGE ];then
+route change default $GW
+fi
index 14f0a586ab1e66e48ad3512316cd39a9522cb61a..fd8a6b7f81ffd91597a27c3e973bdcb2b87aeb5f 100644 (file)
@@ -206,7 +206,7 @@ void get_host_interface_all_os(void)
 void get_host_bridge_os(void)
 {
     if (access(PATH_IFCONFIG, F_OK) != -1) {
-        system("/sbin/ifconfig br-tizen-vm-1");
+        system("/sbin/ifconfig bridge1");
     } else {
         fprintf(stderr, "ifconfig does not exist!\n");
         exit(1);