Skip to content

Commit be1b2b4

Browse files
authored
Merge pull request #1300 from zoran-rilak-msft/master
Fix the boundary crossing check
2 parents 022c74d + 370587b commit be1b2b4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/attachVPNGateway.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,12 @@ function CalculateNextAddressPrefix {
164164
}
165165
$startIPAddress += 1
166166
# if crossing a block boundary, round to the next possible start for the given suffix size
167-
if (($startIPAddress -shr $prefixLength) -ne 0) {
168-
$suffixLength = 32 - $prefixLength
169-
$startIPAddress = (($startIPAddress -shr $suffixLength) + 1) -shl $suffixLength
167+
$suffixLength = 32 - $prefixLength
168+
$mask = (1 -shl $suffixLength) - 1
169+
if (($startIPAddress -band $mask) -ne $startIPAddress) {
170+
$x = $startIPAddress -shr $suffixLength
171+
$x += 1
172+
$startIPAddress = $x -shl $suffixLength
170173
}
171174
# convert and return
172175
$addressPrefixResult = (ConvertUInt32ToIPAddress $startIPAddress) + "/" + $prefixLength

0 commit comments

Comments
 (0)