From: Munkyu Im Date: Mon, 2 Mar 2015 09:33:30 +0000 (+0900) Subject: net: Support bridged network on macosx X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1c994ff166ad0b242746d5e17922ed6af074e338;p=sdk%2Femulator%2Fqemu.git net: Support bridged network on macosx Emulator is able to use bridged network now. supported only wired network(en0) currently. Change-Id: I0157f61aac01fe42655b01eb12d98ffbe9b1cfc5 Signed-off-by: Munkyu Im --- diff --git a/net/tap.c b/net/tap.c index 7bd199cec6..53057ec047 100644 --- 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) { diff --git a/package/emulator-qemu-common.install.macos-64 b/package/emulator-qemu-common.install.macos-64 index 306e593245..dea8b06e3f 100755 --- a/package/emulator-qemu-common.install.macos-64 +++ b/package/emulator-qemu-common.install.macos-64 @@ -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 diff --git a/tizen/src/Makefile b/tizen/src/Makefile index 38152bebef..921124a0ca 100644 --- a/tizen/src/Makefile +++ b/tizen/src/Makefile @@ -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 index 0000000000..2a0ed718fa --- /dev/null +++ b/tizen/src/scripts/emulator-ifup.sh @@ -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 diff --git a/tizen/src/util/check_net_darwin.c b/tizen/src/util/check_net_darwin.c index 14f0a586ab..fd8a6b7f81 100644 --- a/tizen/src/util/check_net_darwin.c +++ b/tizen/src/util/check_net_darwin.c @@ -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);