diff --git a/config.go b/config.go index 4eb2846..9245cf0 100644 --- a/config.go +++ b/config.go @@ -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 } diff --git a/wg/wireguard.go b/wg/wireguard.go index d3fe47d..321e04a 100644 --- a/wg/wireguard.go +++ b/wg/wireguard.go @@ -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{