Allow specific address to be specified
This commit is contained in:
parent
f8fc765936
commit
a52d693f56
|
@ -85,10 +85,11 @@ type network net.IPNet
|
||||||
|
|
||||||
// UnmarshalText parses the provided byte array into the network receiver
|
// UnmarshalText parses the provided byte array into the network receiver
|
||||||
func (n *network) UnmarshalText(data []byte) error {
|
func (n *network) UnmarshalText(data []byte) error {
|
||||||
_, ipnet, err := net.ParseCIDR(string(data))
|
ip, ipnet, err := net.ParseCIDR(string(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
ipnet.IP = ip
|
||||||
*n = network(*ipnet)
|
*n = network(*ipnet)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ func (s *State) assignOverlayAddr(ipnet *net.IPNet, name string) {
|
||||||
ip := make([]byte, len(ipnet.IP))
|
ip := make([]byte, len(ipnet.IP))
|
||||||
copy(ip, []byte(ipnet.IP))
|
copy(ip, []byte(ipnet.IP))
|
||||||
|
|
||||||
|
if ipnet.IP.Mask(ipnet.Mask).Equal(ipnet.IP) {
|
||||||
h := fnv.New128a()
|
h := fnv.New128a()
|
||||||
h.Write([]byte(name))
|
h.Write([]byte(name))
|
||||||
hb := h.Sum(nil)
|
hb := h.Sum(nil)
|
||||||
|
@ -71,6 +72,7 @@ func (s *State) assignOverlayAddr(ipnet *net.IPNet, name string) {
|
||||||
for i := 1; i <= (size-bits)/8; i++ {
|
for i := 1; i <= (size-bits)/8; i++ {
|
||||||
ip[len(ip)-i] = hb[len(hb)-i]
|
ip[len(ip)-i] = hb[len(hb)-i]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
s.OverlayAddr = net.IPNet{
|
s.OverlayAddr = net.IPNet{
|
||||||
IP: net.IP(ip),
|
IP: net.IP(ip),
|
||||||
|
|
Loading…
Reference in New Issue