From: Munkyu Im Date: Wed, 13 May 2015 10:01:40 +0000 (+0900) Subject: net: fix listing network interface X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a95a80527ead38fccb4da415990bf7eea11aacfb;p=sdk%2Femulator%2Femulator-manager.git net: fix listing network interface If a network interface is bound to bridged network interface, cannot list it with NetworkInterface.getNetworkInterfaces(); Change-Id: I49585bda2750c8c13220a5c050da5b88b93a20dd Signed-off-by: Munkyu Im --- diff --git a/common-project/src/org/tizen/emulator/manager/tool/TapUtil.java b/common-project/src/org/tizen/emulator/manager/tool/TapUtil.java index c5d228a..56f4c41 100644 --- a/common-project/src/org/tizen/emulator/manager/tool/TapUtil.java +++ b/common-project/src/org/tizen/emulator/manager/tool/TapUtil.java @@ -64,6 +64,7 @@ import com.sun.jna.platform.win32.WinReg.HKEYByReference; public class TapUtil { + private static String BRIDGE_NAME = "bridge1"; public static String getDevconPath(String platformVersion) { return FilePathResources.getEmulatorBinPath(platformVersion) + File.separator + "devcon.exe"; @@ -937,18 +938,19 @@ public class TapUtil { public static String getBridgeIpAddr(String tapName) { String ipAddr = null; - if (EmulatorManager.isLinux()) - try { - InterfaceAddress ifAddr = getInterfaceIpInfo(getBridgeFromDevice(tapName)); - if (ifAddr != null) - ipAddr = ifAddr.getAddress().getHostAddress(); - } catch (VMWorkerException e) { - EMLogger.getLogger().warning( - (new StringBuilder()) - .append("Failed to get bridge ip address. ") - .append(e.getMessage()).toString()); + if (EmulatorManager.isLinux()) { + InterfaceAddress ifAddr = getInterfaceIpInfo(tapName); + if (ifAddr != null) { + EMLogger.getLogger().info("get " + tapName + "'s IP"); + ipAddr = ifAddr.getAddress().getHostAddress(); + } else { + EMLogger.getLogger().info("get bridge's IP"); + InterfaceAddress ifAddrBridge = getInterfaceIpInfo(BRIDGE_NAME); + if (ifAddrBridge != null) { + ipAddr = ifAddrBridge.getAddress().getHostAddress(); + } } - else if (EmulatorManager.isWin() && isTapInBridge(tapName)) { + } else if (EmulatorManager.isWin() && isTapInBridge(tapName)) { HKEY key = getInterfaceTcpipKey(getBridgeId()); if (key != null) { try { diff --git a/common-project/src/org/tizen/emulator/manager/ui/dialog/TapDeviceDialogForLinux.java b/common-project/src/org/tizen/emulator/manager/ui/dialog/TapDeviceDialogForLinux.java index 098e15e..1e948a0 100644 --- a/common-project/src/org/tizen/emulator/manager/ui/dialog/TapDeviceDialogForLinux.java +++ b/common-project/src/org/tizen/emulator/manager/ui/dialog/TapDeviceDialogForLinux.java @@ -28,10 +28,8 @@ package org.tizen.emulator.manager.ui.dialog; -import java.net.NetworkInterface; -import java.net.SocketException; import java.util.ArrayList; -import java.util.Enumeration; +import java.util.Arrays; import java.util.List; import org.eclipse.swt.SWT; @@ -61,40 +59,26 @@ import org.tizen.emulator.manager.resources.PatchImageResources; import org.tizen.emulator.manager.tool.TapUtil; import org.tizen.emulator.manager.ui.MainDialog; import org.tizen.emulator.manager.ui.widgets.ImageLabel; -import org.tizen.emulator.manager.vms.helper.VMWorkerException; +import org.tizen.emulator.manager.vms.helper.HelperClass; +import org.tizen.emulator.manager.vms.helper.ProcessResult; public class TapDeviceDialogForLinux { - public static ArrayList getInterfaceList() { - ArrayList result = new ArrayList(); - - // Get intereface list - ArrayList ifList = new ArrayList(); - Enumeration interfaces; - try { - interfaces = NetworkInterface.getNetworkInterfaces(); - if (interfaces != null) { - while (interfaces.hasMoreElements()) { - NetworkInterface current = interfaces.nextElement(); - - if (!current.isUp() || current.isLoopback() - || current.isVirtual()) - continue; - ifList.add(current.getName()); - } + public static List getInterfaceList() { + List result = new ArrayList(); + //FIXME: support only ethX for base network + List cmd = Arrays.asList("/bin/sh", "-c", "/bin/ls /sys/class/net | /bin/grep eth"); + ProcessResult res = HelperClass.runProcess(cmd); + if (res.isSuccess() == false) { + EMLogger.getLogger().warning( + "Get tap list fail. Command returns fail:" + "cmd : " + + cmd.toString() + ", return : " + + res.getExitValue()); + return null; + } else { + for (String line : res.getStdOutMsg()) { + result.add(line.trim()); } - // Except bridges in list - List brList = TapUtil.getBridgeList(); - for (String str : ifList) { - if (!brList.contains(str)) { - result.add(str); - } - } - } catch (SocketException e) { - EMLogger.getLogger().warning(e.getMessage()); - } catch (VMWorkerException e) { - EMLogger.getLogger().warning(e.getMessage()); } - return result; } } diff --git a/common-project/src/org/tizen/emulator/manager/vms/option/NetworkOption.java b/common-project/src/org/tizen/emulator/manager/vms/option/NetworkOption.java index 8ba5b53..dd66658 100644 --- a/common-project/src/org/tizen/emulator/manager/vms/option/NetworkOption.java +++ b/common-project/src/org/tizen/emulator/manager/vms/option/NetworkOption.java @@ -50,8 +50,7 @@ public class NetworkOption extends Option { throws VMWorkerException { boolean isBridge = property.getPropertyValue() .getAdvancedOptionValue(ItemName.NET_CONNECT_TYPE) - .equals("Bridge") - && (EmulatorManager.isLinux() || EmulatorManager.isWin()); + .equals("Bridge"); // Qemu MAC argument config.addVariable(VAR_MAC, getMacAddr(isBridge, property)); @@ -67,9 +66,15 @@ public class NetworkOption extends Option { // Qemu net argument if (isBridge) { - String tapName = property.getPropertyValue() - .getAdvancedOptionValue(ItemName.NET_TAP_DEVICE); - config.addQemuOption("-net", "tap,ifname=" + tapName + ",script=no,downscript=no"); + if (EmulatorManager.isWin()) { + String tapName = property.getPropertyValue() + .getAdvancedOptionValue(ItemName.NET_TAP_DEVICE); + config.addQemuOption("-net", "tap,ifname=" + tapName + + ",script=no,downscript=no"); + } else { + config.addQemuOption("-net", + "tap,script=/etc/emulator-ifup.sh,downscript=no"); + } } } @@ -167,10 +172,9 @@ public class NetworkOption extends Option { public void checkArgument(VMProperty property) throws VMLauncherException { boolean isBridge = property.getPropertyValue() .getAdvancedOptionValue(ItemName.NET_CONNECT_TYPE) - .equals("Bridge") - && (EmulatorManager.isLinux() || EmulatorManager.isWin()); + .equals("Bridge"); - if (isBridge) { + if (isBridge && EmulatorManager.isWin()) { String tapName = property.getPropertyValue() .getAdvancedOptionValue(ItemName.NET_TAP_DEVICE); if (TapUtil.nameNotExist(tapName))