Skip to content

Commit 5690cd6

Browse files
Anurag Awasthiyadvr
authored andcommitted
server: fix the subnet overlap checking logic for tagged and untagged vlans when adding ipranges (#3430)
Fixes: #3114 When adding iprange for VLANs there are 3 cases - VLAN under consideration has a tag (like 101) VLAN under consideration has a tag but as a range (like 101-124) VLAN is untagged (i.e. id is "untagged") Before adding iprange we have to check for possible overlaps and throw exception. This needs to be done as follows - If VLAN Tag ID is numeric or a range we need to call UriUtils.checkVlanUriOverlapmethod which internally tries to expand the range as verifies if there are overlaps. If URI overlaps (i.e. there are overlapping VLAN tags) we then need to verify if the iprange being added overlaps with previously added ranges. If there are no overlapping tags we simply need to test for public networks being present in the VLAN. A Regression was introduced in 41fdb88#diff-6e2b61984e8fa2823bb47da3caafa4eeR3174 which caused comparing 'untagged' string as a numeric VLAN Tag range and and attempted expanding it to test overlap in UriUtils.checkVlanUriOverlap. To fix the bug in the issue, we need to handle the untagged case separately as it's non-numeric tag in code. For untagged VLANs and overlapping VLAN URIs we need to check for ipranges and gateways which happens naturally after this change. For tagged VLANs with non-overlapping URIs we need to check if there is a public network.
1 parent 38f97c6 commit 5690cd6

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3815,29 +3815,10 @@ public Vlan createVlanAndPublicIpRange(final long zoneId, final long networkId,
38153815
continue;
38163816
}
38173817
// from here, subnet overlaps
3818-
if (!UriUtils.checkVlanUriOverlap(
3818+
if (vlanId.toLowerCase().contains(Vlan.UNTAGGED) || UriUtils.checkVlanUriOverlap(
38193819
BroadcastDomainType.getValue(BroadcastDomainType.fromString(vlanId)),
38203820
BroadcastDomainType.getValue(BroadcastDomainType.fromString(vlan.getVlanTag())))) {
3821-
boolean overlapped = false;
3822-
if( network.getTrafficType() == TrafficType.Public ) {
3823-
overlapped = true;
3824-
} else {
3825-
final Long nwId = vlan.getNetworkId();
3826-
if ( nwId != null ) {
3827-
final Network nw = _networkModel.getNetwork(nwId);
3828-
if ( nw != null && nw.getTrafficType() == TrafficType.Public ) {
3829-
overlapped = true;
3830-
}
3831-
}
3832-
3833-
}
3834-
if ( overlapped ) {
3835-
throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag()
3836-
+ " in zone " + zone.getName()
3837-
+ " has overlapped with the subnet. Please specify a different gateway/netmask.");
3838-
}
3839-
} else {
3840-
3821+
// For untagged VLAN Id and overlapping URIs we need to expand and verify IP ranges
38413822
final String[] otherVlanIpRange = vlan.getIpRange().split("\\-");
38423823
final String otherVlanStartIP = otherVlanIpRange[0];
38433824
String otherVlanEndIP = null;
@@ -3854,9 +3835,29 @@ public Vlan createVlanAndPublicIpRange(final long zoneId, final long networkId,
38543835
if (!NetUtils.is31PrefixCidr(newCidr)) {
38553836
if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) {
38563837
throw new InvalidParameterValueException("The IP range already has IPs that overlap with the new range." +
3857-
" Please specify a different start IP/end IP.");
3838+
" Please specify a different start IP/end IP.");
38583839
}
38593840
}
3841+
} else {
3842+
// For tagged or non-overlapping URIs we need to ensure there is no Public traffic type
3843+
boolean overlapped = false;
3844+
if (network.getTrafficType() == TrafficType.Public) {
3845+
overlapped = true;
3846+
} else {
3847+
final Long nwId = vlan.getNetworkId();
3848+
if (nwId != null) {
3849+
final Network nw = _networkModel.getNetwork(nwId);
3850+
if (nw != null && nw.getTrafficType() == TrafficType.Public) {
3851+
overlapped = true;
3852+
}
3853+
}
3854+
3855+
}
3856+
if (overlapped) {
3857+
throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag()
3858+
+ " in zone " + zone.getName()
3859+
+ " has overlapped with the subnet. Please specify a different gateway/netmask.");
3860+
}
38603861
}
38613862
}
38623863
}

0 commit comments

Comments
 (0)