Skip to content

Commit d72f8a6

Browse files
author
Sheng Yang
committed
Add new global configuration option to enable user specify guest OS DHCP policy
This is improvement of: commit 1ca493e Author: Sheng Yang <sheng.yang@cloud.com> Date: Wed Feb 29 17:43:50 2012 -0800 bug 14042: Don't set dhcp:router option on DHCP server for non-default network on CentOS/RHEL The old solution only works on CentOS/RHEL, this one would enable the ability to more guest OS, and enable user to choose what policy should be for each guest os type.
1 parent 53e6825 commit d72f8a6

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎server/src/com/cloud/configuration/Config.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public enum Config {
105105

106106
SecurityGroupDefaultAdding("Network", ManagementServer.class, Boolean.class, "network.securitygroups.defaultadding", "true", "If true, the user VM would be added to the default security group by default", null),
107107

108+
GuestOSNeedGatewayOnNonDefaultNetwork("Network", NetworkManager.class, String.class, "network.dhcp.nondefaultnetwork.setgateway.guestos", "Windows", "The guest OS's name start with this fields would result in DHCP server response gateway information even when the network it's on is not default network. Names are separated by comma.", null),
109+
108110
//VPN
109111
RemoteAccessVpnPskLength("Network", AgentManager.class, Integer.class, "remote.access.vpn.psk.length", "24", "The length of the ipsec preshared key (minimum 8, maximum 256)", null),
110112
RemoteAccessVpnClientIpRange("Network", AgentManager.class, String.class, "remote.access.vpn.client.iprange", "10.1.2.1-10.1.2.8", "The range of ips to be allocated to remote access vpn clients. The first ip in the range is used by the VPN server", null),
@@ -293,6 +295,7 @@ public enum Config {
293295
VmOpCleanupWait("Advanced", ManagementServer.class, Long.class, "vm.op.cleanup.wait", "3600", "Time (in seconds) to wait before cleanuping up any vm work items", "Seconds"),
294296
VmOpCancelInterval("Advanced", ManagementServer.class, Long.class, "vm.op.cancel.interval", "3600", "Time (in seconds) to wait before cancelling a operation", "Seconds"),
295297

298+
296299
DefaultPageSize("Advanced", ManagementServer.class, Long.class, "default.page.size", "500", "Default page size for API list* commands", null),
297300

298301
TaskCleanupRetryInterval("Advanced", ManagementServer.class, Integer.class, "task.cleanup.retry.interval", "600", "Time (in seconds) to wait before retrying cleanup of tasks if the cleanup failed previously. 0 means to never retry.", "Seconds"),

‎server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
341341
int _routerCheckInterval = 30;
342342
protected ServiceOfferingVO _offering;
343343
private String _dnsBasicZoneUpdates = "all";
344+
private Set<String> _guestOSNeedGatewayOnNonDefaultNetwork = new HashSet<String>();
344345

345346
private boolean _disable_rp_filter = false;
346347
int _routerExtraPublicNics = 2;
@@ -592,6 +593,14 @@ public boolean configure(final String name, final Map<String, Object> params) th
592593

593594
_routerExtraPublicNics = NumbersUtil.parseInt(_configDao.getValue(Config.RouterExtraPublicNics.key()), 2);
594595

596+
String guestOSString = configs.get("network.dhcp.nondefaultnetwork.setgateway.guestos");
597+
if (guestOSString != null) {
598+
String[] guestOSList = guestOSString.split(",");
599+
for (String os : guestOSList) {
600+
_guestOSNeedGatewayOnNonDefaultNetwork.add(os);
601+
}
602+
}
603+
595604
String value = configs.get("start.retry");
596605
_retry = NumbersUtil.parseInt(value, 2);
597606

@@ -2931,14 +2940,22 @@ private void createDhcpEntryCommand(VirtualRouter router, UserVm vm, NicVO nic,
29312940
DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), vm.getHostName());
29322941
DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn());
29332942
String gatewayIp = findGatewayIp(vm.getId());
2943+
boolean needGateway = true;
29342944
if (!gatewayIp.equals(nic.getGateway())) {
2945+
needGateway = false;
29352946
GuestOSVO guestOS = _guestOSDao.findById(vm.getGuestOSId());
2936-
// Don't set dhcp:router option for non-default nic on CentOS/RHEL, because they would set routing on wrong interface
2937-
// This is tricky, we may need to update this when we have more information on various OS's behavior
2938-
if (guestOS.getDisplayName().startsWith("CentOS") || guestOS.getDisplayName().startsWith("Red Hat Enterprise")) {
2939-
gatewayIp = "0.0.0.0";
2947+
// Do set dhcp:router option for non-default nic on certain OS(including Windows), and leave other OS unset.
2948+
// Because some OS(e.g. CentOS) would set routing on wrong interface
2949+
for (String name : _guestOSNeedGatewayOnNonDefaultNetwork) {
2950+
if (guestOS.getDisplayName().startsWith(name)) {
2951+
needGateway = true;
2952+
break;
2953+
}
29402954
}
29412955
}
2956+
if (!needGateway) {
2957+
gatewayIp = "0.0.0.0";
2958+
}
29422959
dhcpCommand.setDefaultRouter(gatewayIp);
29432960
dhcpCommand.setDefaultDns(findDefaultDnsIp(vm.getId()));
29442961

‎setup/db/db/schema-40to41.sql‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121

2222

2323
ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `eip_associate_public_ip` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if public IP is associated with user VM creation by default when EIP service is enabled.' AFTER `elastic_ip_service`;
24+
25+
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network','DEFAULT','NetworkManager','network.dhcp.nondefaultnetwork.setgateway.guestos','Windows','The guest OS\'s name start with this fields would result in DHCP server response gateway information even when the network it\'s on is not default network. Names are separated by comma.');

0 commit comments

Comments
 (0)