Allow specific address to be specified

This commit is contained in:
kaiyou 2020-06-22 18:02:45 +02:00
parent f8fc765936
commit a52d693f56
2 changed files with 9 additions and 6 deletions

View File

@ -85,10 +85,11 @@ type network net.IPNet
// UnmarshalText parses the provided byte array into the network receiver
func (n *network) UnmarshalText(data []byte) error {
_, ipnet, err := net.ParseCIDR(string(data))
ip, ipnet, err := net.ParseCIDR(string(data))
if err != nil {
return err
}
ipnet.IP = ip
*n = network(*ipnet)
return nil
}

View File

@ -64,12 +64,14 @@ func (s *State) assignOverlayAddr(ipnet *net.IPNet, name string) {
ip := make([]byte, len(ipnet.IP))
copy(ip, []byte(ipnet.IP))
h := fnv.New128a()
h.Write([]byte(name))
hb := h.Sum(nil)
if ipnet.IP.Mask(ipnet.Mask).Equal(ipnet.IP) {
h := fnv.New128a()
h.Write([]byte(name))
hb := h.Sum(nil)
for i := 1; i <= (size-bits)/8; i++ {
ip[len(ip)-i] = hb[len(hb)-i]
for i := 1; i <= (size-bits)/8; i++ {
ip[len(ip)-i] = hb[len(hb)-i]
}
}
s.OverlayAddr = net.IPNet{