зеркало из https://github.com/microsoft/hcsshim.git
Fix issue with mask length of gatway addresses that are out of the (#2305)
interface's subnet * See documentation at https://pkg.go.dev/net#ParseIP Signed-off-by: Kathryn Baldauf <kabaldau@microsoft.com>
This commit is contained in:
Родитель
1c29e9d8cc
Коммит
c65b7892d7
|
@ -237,7 +237,18 @@ func assignIPToLink(ctx context.Context,
|
|||
// unreachable error when adding this out-of-subnet gw route
|
||||
entry.Debugf("gw is outside of the subnet: Configure %s in %d with: %s/%d gw=%s\n",
|
||||
ifStr, nsPid, allocatedIP, prefixLen, gatewayIP)
|
||||
ml := len(gw) * 8
|
||||
|
||||
// net library's ParseIP call always returns an array of length 16, so we
|
||||
// need to first check if the address is IPv4 or IPv6 before calculating
|
||||
// the mask length. See https://pkg.go.dev/net#ParseIP.
|
||||
ml := 8
|
||||
if gw.To4() != nil {
|
||||
ml *= net.IPv4len
|
||||
} else if gw.To16() != nil {
|
||||
ml *= net.IPv6len
|
||||
} else {
|
||||
return fmt.Errorf("gw IP is neither IPv4 nor IPv6: %v", gw)
|
||||
}
|
||||
addr2 := &net.IPNet{
|
||||
IP: gw,
|
||||
Mask: net.CIDRMask(ml, ml)}
|
||||
|
|
Загрузка…
Ссылка в новой задаче