@@ -1029,22 +1029,42 @@ private void checkSharedNetworkCidrOverlap(Long zoneId, long physicalNetworkId,
10291029 }
10301030 }
10311031
1032- private void validateRouterIps (String routerIp , String routerIpv6 , String startIp , String endIp , String startIpv6 , String endIpv6 ) {
1032+ private void validateRouterIps (String routerIp , String routerIpv6 , String startIp , String endIp , String gateway ,
1033+ String netmask , String startIpv6 , String endIpv6 , String ip6Cidr ) {
10331034 if (isNotBlank (routerIp )) {
1035+ if (startIp != null && endIp == null ) {
1036+ endIp = startIp ;
1037+ }
10341038 if (!NetUtils .isValidIp4 (routerIp )) {
10351039 throw new CloudRuntimeException ("Router IPv4 IP provided is of incorrect format" );
10361040 }
1037- if (!NetUtils .isIpInRange (routerIp , startIp , endIp )) {
1038- throw new CloudRuntimeException ("Router IPv4 IP provided is not within the specified range: " + startIp + " - " + endIp );
1041+ if (isNotBlank (startIp ) && isNotBlank (endIp )) {
1042+ if (!NetUtils .isIpInRange (routerIp , startIp , endIp )) {
1043+ throw new CloudRuntimeException ("Router IPv4 IP provided is not within the specified range: " + startIp + " - " + endIp );
1044+ }
1045+ } else {
1046+ String cidr = NetUtils .ipAndNetMaskToCidr (gateway , netmask );
1047+ if (!NetUtils .isIpWithInCidrRange (routerIp , cidr )) {
1048+ throw new CloudRuntimeException ("Router IP provided in not within the network range" );
1049+ }
10391050 }
10401051 }
10411052 if (isNotBlank (routerIpv6 )) {
1042- String ipv6Range = startIpv6 + "-" + endIpv6 ;
1053+ if (startIpv6 != null && endIpv6 == null ) {
1054+ endIpv6 = startIpv6 ;
1055+ }
10431056 if (!NetUtils .isValidIp6 (routerIpv6 )) {
1044- throw new CloudRuntimeException ("Router IPv6 IP provided is of incorrect format" );
1057+ throw new CloudRuntimeException ("Router IPv6 address provided is of incorrect format" );
10451058 }
1046- if (!NetUtils .isIp6InRange (routerIpv6 , ipv6Range )) {
1047- throw new CloudRuntimeException ("Router IPv6 IP provided is not within the specified range: " + startIpv6 + " - " + endIpv6 );
1059+ if (isNotBlank (startIpv6 ) && isNotBlank (endIpv6 )) {
1060+ String ipv6Range = startIpv6 + "-" + endIpv6 ;
1061+ if (!NetUtils .isIp6InRange (routerIpv6 , ipv6Range )) {
1062+ throw new CloudRuntimeException ("Router IPv6 address provided is not within the specified range: " + startIpv6 + " - " + endIpv6 );
1063+ }
1064+ } else {
1065+ if (!NetUtils .isIp6InNetwork (routerIpv6 , ip6Cidr )) {
1066+ throw new CloudRuntimeException ("Router IPv6 address provided is not with the network range" );
1067+ }
10481068 }
10491069 }
10501070 }
@@ -1183,7 +1203,6 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
11831203 throw new InvalidParameterValueException ("Virtual Router is not a supported provider for the Shared network, hence router ip should not be provided" );
11841204 }
11851205
1186- validateRouterIps (routerIp , routerIpv6 , startIP , endIP , startIPv6 , endIPv6 );
11871206 // Check if the network is domain specific
11881207 if (aclType == ACLType .Domain ) {
11891208 // only Admin can create domain with aclType=Domain
@@ -1313,6 +1332,8 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
13131332 }
13141333 }
13151334
1335+ validateRouterIps (routerIp , routerIpv6 , startIP , endIP , gateway , netmask , startIPv6 , endIPv6 , ip6Cidr );
1336+
13161337 if (isNotBlank (isolatedPvlan ) && (zone .getNetworkType () != NetworkType .Advanced || ntwkOff .getGuestType () == GuestType .Isolated )) {
13171338 throw new InvalidParameterValueException ("Can only support create Private VLAN network with advanced shared or L2 network!" );
13181339 }
0 commit comments