}
}
}
private void createDhcpEntryCommand(VirtualRouter router, UserVm vm, NicVO nic, Commands cmds) {
DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), vm.getHostName(), nic.getIp6Address());
DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
String gatewayIp = findGatewayIp(vm.getId());
boolean needGateway = true;
if (gatewayIp != null && !gatewayIp.equals(nic.getGateway())) {
needGateway = false;
GuestOSVO guestOS = _guestOSDao.findById(vm.getGuestOSId());
// Do set dhcp:router option for non-default nic on certain OS(including Windows), and leave other OS unset.
// Because some OS(e.g. CentOS) would set routing on wrong interface
for (String name : _guestOSNeedGatewayOnNonDefaultNetwork) {
if (guestOS.getDisplayName().startsWith(name)) {
needGateway = true;
break;
}
}
}
if (!needGateway) {
gatewayIp = "0.0.0.0";
}
dhcpCommand.setDefaultRouter(gatewayIp);
dhcpCommand.setIp6Gateway(nic.getIp6Gateway());
dhcpCommand.setDefaultDns(findDefaultDnsIp(vm.getId()));
dhcpCommand.setDuid(NetUtils.getDuidLL(nic.getMacAddress()));
dhcpCommand.setDefault(nic.isDefaultNic());
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(nic.getNetworkId(), router.getId()));
dhcpCommand.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
cmds.addCommand("dhcp", dhcpCommand);
}