Calling Prefix.Usage() on a child prefixes with mask size 31 or 32 panics with "negative shift amount"
Closed this issue · 6 comments
antonprokopovich commented
Version: go-ipam v1.11.6
Here's the exact line that panics: https://github.com/metal-stack/go-ipam/blob/master/prefix.go#L642
The code to reproduce the issue:
package main
import (
"context"
"fmt"
goipam "github.com/metal-stack/go-ipam"
)
type Subnet struct {
cidr string
parentCidr string
}
var parentSubnets = []Subnet{
{
cidr: "192.168.0.0/24",
parentCidr: "",
},
}
var subnets = []Subnet{
{
cidr: "192.168.0.0/30",
parentCidr: "192.168.0.0/24",
},
}
var storage = map[string][]Subnet{
"parents": parentSubnets,
"children": subnets,
}
func main() {
ipam := goipam.New()
ctx := context.Background()
for _, parent := range storage["parents"] {
parPrefix, err := ipam.NewPrefix(ctx, parent.cidr)
if err != nil {
fmt.Println(err)
}
for _, child := range storage["children"] {
if child.parentCidr == parent.cidr {
chPrefix, err := ipam.AcquireSpecificChildPrefix(ctx, parent.cidr, child.cidr)
if err != nil {
fmt.Println(err)
}
// This call will panic
u := chPrefix.Usage()
_ = u
}
}
}
}
majst01 commented
Nice catch, do you mind creating a PR with a unit test showing this issue ?
antonprokopovich commented
@majst01 Will try to do it today and let you know when I finish
antonprokopovich commented
majst01 commented
Thanks, looking at it. Do you have a idea howto fix that ?
antonprokopovich commented
@majst01 Not yet but I will try to look into it later today