Skip to content

Commit 1b28ea1

Browse files
network: fix dhcp/password/metadata issues on shared networks with multiple subnets (apache#5013)
* apache#4943: apply iptables for password and metadata * apache#4943: fix wrong ip alias * apache#4943: revert previous change and add ip_aliases Co-authored-by: Wei Zhou <weizhouapache@gmail.com>
1 parent aa28954 commit 1b28ea1

5 files changed

Lines changed: 24 additions & 16 deletions

File tree

engine/components-api/src/main/java/com/cloud/network/IpAddressManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ PublicIp assignDedicateIpAddress(Account owner, Long guestNtwkId, Long vpcId, lo
185185
IpAddress allocateIp(Account ipOwner, boolean isSystem, Account caller, long callerId, DataCenter zone, Boolean displayIp, String ipaddress)
186186
throws ConcurrentOperationException, ResourceAllocationException, InsufficientAddressCapacityException;
187187

188-
PublicIp assignPublicIpAddressFromVlans(long dcId, Long podId, Account owner, VlanType type, List<Long> vlanDbIds, Long networkId, String requestedIp, boolean isSystem)
188+
PublicIp assignPublicIpAddressFromVlans(long dcId, Long podId, Account owner, VlanType type, List<Long> vlanDbIds, Long networkId, String requestedIp, String requestedGateway, boolean isSystem)
189189
throws InsufficientAddressCapacityException;
190190

191191
PublicIp getAvailablePublicIpAddressFromVlans(long dcId, Long podId, Account owner, VlanType type, List<Long> vlanDbIds, Long networkId, String requestedIp, boolean isSystem)
@@ -219,6 +219,7 @@ List<IPAddressVO> listAvailablePublicIps(final long dcId,
219219
final boolean assign,
220220
final boolean allocate,
221221
final String requestedIp,
222+
final String requestedGateway,
222223
final boolean isSystem,
223224
final Long vpcId,
224225
final Boolean displayIp,

server/src/main/java/com/cloud/network/IpAddressManagerImpl.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ public boolean configure(String name, Map<String, Object> params) {
476476
SearchBuilder<VlanVO> vlanSearch = _vlanDao.createSearchBuilder();
477477
vlanSearch.and("type", vlanSearch.entity().getVlanType(), Op.EQ);
478478
vlanSearch.and("networkId", vlanSearch.entity().getNetworkId(), Op.EQ);
479+
vlanSearch.and("vlanGateway", vlanSearch.entity().getVlanGateway(), Op.EQ);
479480
AssignIpAddressSearch.join("vlan", vlanSearch, vlanSearch.entity().getId(), AssignIpAddressSearch.entity().getVlanId(), JoinType.INNER);
480481
AssignIpAddressSearch.done();
481482

@@ -487,6 +488,7 @@ public boolean configure(String name, Map<String, Object> params) {
487488
SearchBuilder<VlanVO> podVlanSearch = _vlanDao.createSearchBuilder();
488489
podVlanSearch.and("type", podVlanSearch.entity().getVlanType(), Op.EQ);
489490
podVlanSearch.and("networkId", podVlanSearch.entity().getNetworkId(), Op.EQ);
491+
podVlanSearch.and("vlanGateway", podVlanSearch.entity().getVlanGateway(), Op.EQ);
490492
SearchBuilder<PodVlanMapVO> podVlanMapSB = _podVlanMapDao.createSearchBuilder();
491493
podVlanMapSB.and("podId", podVlanMapSB.entity().getPodId(), Op.EQ);
492494
AssignIpAddressFromPodVlanSearch.join("podVlanMapSB", podVlanMapSB, podVlanMapSB.entity().getVlanDbId(), AssignIpAddressFromPodVlanSearch.entity().getVlanId(),
@@ -755,34 +757,34 @@ public Boolean doInTransaction(TransactionStatus status) {
755757
@Override
756758
public PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isSystem, boolean forSystemVms)
757759
throws InsufficientAddressCapacityException {
758-
return fetchNewPublicIp(dcId, podId, null, owner, type, networkId, false, true, requestedIp, isSystem, null, null, forSystemVms);
760+
return fetchNewPublicIp(dcId, podId, null, owner, type, networkId, false, true, requestedIp, null, isSystem, null, null, forSystemVms);
759761
}
760762

761763
@Override
762-
public PublicIp assignPublicIpAddressFromVlans(long dcId, Long podId, Account owner, VlanType type, List<Long> vlanDbIds, Long networkId, String requestedIp, boolean isSystem)
764+
public PublicIp assignPublicIpAddressFromVlans(long dcId, Long podId, Account owner, VlanType type, List<Long> vlanDbIds, Long networkId, String requestedIp, String requestedGateway, boolean isSystem)
763765
throws InsufficientAddressCapacityException {
764-
return fetchNewPublicIp(dcId, podId, vlanDbIds, owner, type, networkId, false, true, requestedIp, isSystem, null, null, false);
766+
return fetchNewPublicIp(dcId, podId, vlanDbIds, owner, type, networkId, false, true, requestedIp, requestedGateway, isSystem, null, null, false);
765767
}
766768

767769
@Override
768770
public PublicIp getAvailablePublicIpAddressFromVlans(long dcId, Long podId, Account owner, VlanType type, List<Long> vlanDbIds, Long networkId, String requestedIp, boolean isSystem)
769771
throws InsufficientAddressCapacityException {
770-
return fetchNewPublicIp(dcId, podId, vlanDbIds, owner, type, networkId, false, false, false, requestedIp, isSystem, null, null, false);
772+
return fetchNewPublicIp(dcId, podId, vlanDbIds, owner, type, networkId, false, false, false, requestedIp, null, isSystem, null, null, false);
771773
}
772774

773775
@DB
774776
public PublicIp fetchNewPublicIp(final long dcId, final Long podId, final List<Long> vlanDbIds, final Account owner, final VlanType vlanUse, final Long guestNetworkId,
775-
final boolean sourceNat, final boolean allocate, final String requestedIp, final boolean isSystem, final Long vpcId, final Boolean displayIp, final boolean forSystemVms)
777+
final boolean sourceNat, final boolean allocate, final String requestedIp, final String requestedGateway, final boolean isSystem, final Long vpcId, final Boolean displayIp, final boolean forSystemVms)
776778
throws InsufficientAddressCapacityException {
777779
return fetchNewPublicIp(dcId, podId, vlanDbIds, owner, vlanUse, guestNetworkId,
778-
sourceNat, true, allocate, requestedIp, isSystem, vpcId, displayIp, forSystemVms);
780+
sourceNat, true, allocate, requestedIp, requestedGateway, isSystem, vpcId, displayIp, forSystemVms);
779781
}
780782

781783
@DB
782784
public PublicIp fetchNewPublicIp(final long dcId, final Long podId, final List<Long> vlanDbIds, final Account owner, final VlanType vlanUse, final Long guestNetworkId,
783-
final boolean sourceNat, final boolean assign, final boolean allocate, final String requestedIp, final boolean isSystem, final Long vpcId, final Boolean displayIp, final boolean forSystemVms)
785+
final boolean sourceNat, final boolean assign, final boolean allocate, final String requestedIp, final String requestedGateway, final boolean isSystem, final Long vpcId, final Boolean displayIp, final boolean forSystemVms)
784786
throws InsufficientAddressCapacityException {
785-
List<IPAddressVO> addrs = listAvailablePublicIps(dcId, podId, vlanDbIds, owner, vlanUse, guestNetworkId, sourceNat, assign, allocate, requestedIp, isSystem, vpcId, displayIp, forSystemVms, true);
787+
List<IPAddressVO> addrs = listAvailablePublicIps(dcId, podId, vlanDbIds, owner, vlanUse, guestNetworkId, sourceNat, assign, allocate, requestedIp, requestedGateway, isSystem, vpcId, displayIp, forSystemVms, true);
786788
IPAddressVO addr = addrs.get(0);
787789
if (vlanUse == VlanType.VirtualNetwork) {
788790
_firewallMgr.addSystemFirewallRules(addr, owner);
@@ -793,7 +795,7 @@ public PublicIp fetchNewPublicIp(final long dcId, final Long podId, final List<L
793795

794796
@Override
795797
public List<IPAddressVO> listAvailablePublicIps(final long dcId, final Long podId, final List<Long> vlanDbIds, final Account owner, final VlanType vlanUse, final Long guestNetworkId,
796-
final boolean sourceNat, final boolean assign, final boolean allocate, final String requestedIp, final boolean isSystem,
798+
final boolean sourceNat, final boolean assign, final boolean allocate, final String requestedIp, final String requestedGateway, final boolean isSystem,
797799
final Long vpcId, final Boolean displayIp, final boolean forSystemVms, final boolean lockOneRow) throws InsufficientAddressCapacityException {
798800
return Transaction.execute(new TransactionCallbackWithException<List<IPAddressVO>, InsufficientAddressCapacityException>() {
799801
@Override
@@ -864,6 +866,10 @@ public List<IPAddressVO> doInTransaction(TransactionStatus status) throws Insuff
864866
sc.setJoinParameters("vlan", "networkId", guestNetworkId);
865867
errorMessage.append(", network id=" + guestNetworkId);
866868
}
869+
if (requestedGateway != null) {
870+
sc.setJoinParameters("vlan", "vlanGateway", requestedGateway);
871+
errorMessage.append(", requested gateway=" + requestedGateway);
872+
}
867873
sc.setJoinParameters("vlan", "type", vlanUse);
868874

869875
if (requestedIp != null) {
@@ -1023,7 +1029,7 @@ public PublicIp doInTransaction(TransactionStatus status) throws InsufficientAdd
10231029
VpcVO vpc = _vpcDao.findById(vpcId);
10241030
displayIp = vpc.isDisplay();
10251031
}
1026-
return fetchNewPublicIp(dcId, null, null, owner, VlanType.VirtualNetwork, guestNtwkId, isSourceNat, true, null, false, vpcId, displayIp, false);
1032+
return fetchNewPublicIp(dcId, null, null, owner, VlanType.VirtualNetwork, guestNtwkId, isSourceNat, true, null, null, false, vpcId, displayIp, false);
10271033
}
10281034
});
10291035
if (ip.getState() != State.Allocated) {
@@ -1219,7 +1225,7 @@ public IpAddress allocateIp(final Account ipOwner, final boolean isSystem, Accou
12191225
ip = Transaction.execute(new TransactionCallbackWithException<PublicIp, InsufficientAddressCapacityException>() {
12201226
@Override
12211227
public PublicIp doInTransaction(TransactionStatus status) throws InsufficientAddressCapacityException {
1222-
PublicIp ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, null, false, assign, ipaddress, isSystem, null, displayIp, false);
1228+
PublicIp ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, null, false, assign, ipaddress, null, isSystem, null, displayIp, false);
12231229

12241230
if (ip == null) {
12251231
InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zone

server/src/main/java/com/cloud/network/rules/DhcpSubNetRules.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter
123123
IpAddressManager ipAddrMgr = visitor.getVirtualNetworkApplianceFactory().getIpAddrMgr();
124124
if (dc.getNetworkType() == NetworkType.Basic) {
125125
routerPublicIP = ipAddrMgr.assignPublicIpAddressFromVlans(_router.getDataCenterId(), vm.getPodIdToDeployIn(), caller, Vlan.VlanType.DirectAttached,
126-
vlanDbIdList, _nic.getNetworkId(), null, false);
126+
vlanDbIdList, _nic.getNetworkId(), null, _nic.getIPv4Gateway(), false);
127127
} else {
128128
routerPublicIP = ipAddrMgr.assignPublicIpAddressFromVlans(_router.getDataCenterId(), null, caller, Vlan.VlanType.DirectAttached, vlanDbIdList,
129-
_nic.getNetworkId(), null, false);
129+
_nic.getNetworkId(), null, _nic.getIPv4Gateway(), false);
130130
}
131131

132132
_routerAliasIp = routerPublicIP.getAddress().addr();
@@ -171,4 +171,4 @@ public NicIpAliasVO getNicAlias() {
171171
public String getRouterAliasIp() {
172172
return _routerAliasIp;
173173
}
174-
}
174+
}

server/src/main/java/com/cloud/server/ManagementServerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ public Pair<List<? extends IpAddress>, Integer> searchForIPAddresses(final ListP
21782178
long dcId = dc.getId();
21792179
try {
21802180
freeAddrs.addAll(_ipAddressMgr.listAvailablePublicIps(dcId, null, vlanDbIds, owner, VlanType.VirtualNetwork, associatedNetworkId,
2181-
false, false, false, null, false, cmd.getVpcId(), cmd.isDisplay(), false, false)); // Free
2181+
false, false, false, null, null, false, cmd.getVpcId(), cmd.isDisplay(), false, false)); // Free
21822182
} catch (InsufficientAddressCapacityException e) {
21832183
s_logger.warn("no free address is found in zone " + dcId);
21842184
}

systemvm/debian/opt/cloud/bin/configure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ def main(argv):
10701070
config.address().process()
10711071

10721072
databag_map = OrderedDict([("guest_network", {"process_iptables": True, "executor": []}),
1073+
("ip_aliases", {"process_iptables": True, "executor": []}),
10731074
("vm_password", {"process_iptables": False, "executor": [CsPassword("vmpassword", config)]}),
10741075
("vm_metadata", {"process_iptables": False, "executor": [CsVmMetadata('vmdata', config)]}),
10751076
("network_acl", {"process_iptables": True, "executor": []}),

0 commit comments

Comments
 (0)