Skip to content

Calling Prefix.Usage() on a child prefixes with mask size 31 or 32 panics with "negative shift amount" #112

@antonprokopovich

Description

@antonprokopovich

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
			}
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions