fix address/prefix code, platform specific parts still need testing

This commit is contained in:
Arceliar 2018-06-14 07:58:07 -05:00
parent 330175889e
commit e7fca66655
3 changed files with 7 additions and 6 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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