bug 9605: exclude virtual interfaces when searching for cidrs

This commit is contained in:
Kelven Yang 2011-04-26 17:52:23 -07:00
parent 1bd0496bd0
commit b8d9513309
2 changed files with 10 additions and 9 deletions

View File

@ -985,7 +985,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask());
}
buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask());
if (nic.isDefaultNic()) {
buf.append(" gateway=").append(nic.getGateway());
}

View File

@ -116,14 +116,16 @@ public class NetUtils {
List<String> cidrList = new ArrayList<String>();
try {
for(NetworkInterface ifc : IteratorUtil.enumerationAsIterable(NetworkInterface.getNetworkInterfaces())) {
for (InterfaceAddress address : ifc.getInterfaceAddresses()) {
InetAddress addr = address.getAddress();
int prefixLength = address.getNetworkPrefixLength();
if(prefixLength < 32 && prefixLength > 0) {
String ip = ipFromInetAddress(addr);
cidrList.add(ipAndNetMaskToCidr(ip, getCidrNetmask(prefixLength)));
}
}
if(ifc.isUp() && !ifc.isVirtual() && !ifc.isLoopback()) {
for (InterfaceAddress address : ifc.getInterfaceAddresses()) {
InetAddress addr = address.getAddress();
int prefixLength = address.getNetworkPrefixLength();
if(prefixLength < 32 && prefixLength > 0) {
String ip = ipFromInetAddress(addr);
cidrList.add(ipAndNetMaskToCidr(ip, getCidrNetmask(prefixLength)));
}
}
}
}
} catch(SocketException e) {
s_logger.warn("UnknownHostException in getLocalCidrs().", e);