From e7fca666554cddb3f7104d920c59c98cdb79ca7f Mon Sep 17 00:00:00 2001 From: Arceliar Date: Thu, 14 Jun 2018 07:58:07 -0500 Subject: [PATCH] fix address/prefix code, platform specific parts still need testing --- src/yggdrasil/address.go | 9 +++++---- src/yggdrasil/core.go | 2 +- src/yggdrasil/icmpv6.go | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/yggdrasil/address.go b/src/yggdrasil/address.go index a499edfa..dd2c410a 100644 --- a/src/yggdrasil/address.go +++ b/src/yggdrasil/address.go @@ -19,17 +19,18 @@ func (a *address) isValid() bool { return false } } - return (*a)[len(address_prefix)-1]&0x80 == 0 + return true } // isValid returns true if a prefix falls within the range usable by the network. func (s *subnet) isValid() bool { - for idx := range address_prefix { + l := len(address_prefix) + for idx := range address_prefix[:l-1] { if (*s)[idx] != address_prefix[idx] { return false } } - return (*s)[len(address_prefix)-1]&0x80 != 0 + return (*s)[l-1] == address_prefix[l-1]|0x01 } // address_addrForNodeID takes a *NodeID as an argument and returns an *address. @@ -83,7 +84,7 @@ func address_subnetForNodeID(nid *NodeID) *subnet { addr := *address_addrForNodeID(nid) var snet subnet copy(snet[:], addr[:]) - snet[len(address_prefix)-1] |= 0x80 + snet[len(address_prefix)-1] |= 0x01 return &snet } diff --git a/src/yggdrasil/core.go b/src/yggdrasil/core.go index e1da6fee..bd7fecec 100644 --- a/src/yggdrasil/core.go +++ b/src/yggdrasil/core.go @@ -117,7 +117,7 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error { } ip := net.IP(c.router.addr[:]).String() - if err := c.tun.start(nc.IfName, nc.IfTAPMode, fmt.Sprintf("%s/8", ip), nc.IfMTU); err != nil { + if err := c.tun.start(nc.IfName, nc.IfTAPMode, fmt.Sprintf("%s/%d", ip, 8*len(address_prefix)-1), nc.IfMTU); err != nil { c.log.Println("Failed to start TUN/TAP") return err } diff --git a/src/yggdrasil/icmpv6.go b/src/yggdrasil/icmpv6.go index 1eb1c67c..0491f880 100644 --- a/src/yggdrasil/icmpv6.go +++ b/src/yggdrasil/icmpv6.go @@ -252,7 +252,7 @@ func (i *icmpv6) handle_ndp(in []byte) ([]byte, error) { case source.isValid(): case snet.isValid(): default: - return nil, errors.New("Not an NDP for fd00::/8") + return nil, errors.New("Not an NDP for 0200::/7") } // Create our NDP message body response