containernetworking / plugins

Some reference and example networking plugins, maintained by the CNI team.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug report: bad NextIP of "0.0.0.1"

mars1024 opened this issue · comments

When I use

plugins/pkg/ip/cidr.go

Lines 23 to 26 in 7e9ada5

func NextIP(ip net.IP) net.IP {
i := ipToInt(ip)
return intToIP(i.Add(i, big.NewInt(1)))
}
to get next IP of address "0.0.0.1", I got an illegal result [2] but not an expected one [0,0,0,2].

This is because intToIP does not obey the byte length of IPv4(4)/IPv6(16) when first byte is 0.

plugins/pkg/ip/cidr.go

Lines 51 to 53 in 7e9ada5

func intToIP(i *big.Int) net.IP {
return net.IP(i.Bytes())
}

This bug will happen when first byte is 0 no matter family is IPv4 or IPv6.

Fixed by #782

/close