5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 20:00:27 +00:00

Clean up some exported constants

This commit is contained in:
Neil Alexander 2018-05-27 23:31:34 +01:00
parent a9e61d0d37
commit 460a22c063
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
5 changed files with 40 additions and 39 deletions

View File

@ -456,3 +456,28 @@ func DEBUG_simLinkPeers(p, q *peer) {
func (c *Core) DEBUG_simFixMTU() { func (c *Core) DEBUG_simFixMTU() {
c.tun.mtu = 65535 c.tun.mtu = 65535
} }
////////////////////////////////////////////////////////////////////////////////
func Util_testAddrIDMask() {
for idx := 0; idx < 16; idx++ {
var orig NodeID
orig[8] = 42
for bidx := 0; bidx < idx; bidx++ {
orig[bidx/8] |= (0x80 >> uint8(bidx%8))
}
addr := address_addrForNodeID(&orig)
nid, mask := addr.getNodeIDandMask()
for b := 0; b < len(mask); b++ {
nid[b] &= mask[b]
orig[b] &= mask[b]
}
if *nid != orig {
fmt.Println(orig)
fmt.Println(*addr)
fmt.Println(*nid)
fmt.Println(*mask)
panic(idx)
}
}
}

View File

@ -12,7 +12,7 @@ import "errors"
type macAddress [6]byte type macAddress [6]byte
const ETHER = 14 const len_ETHER = 14
type icmpv6 struct { type icmpv6 struct {
tun *tunDevice tun *tunDevice
@ -79,13 +79,13 @@ func (i *icmpv6) parse_packet_tap(datain []byte) ([]byte, error) {
} }
// Hand over to parse_packet_tun to interpret the IPv6 packet // Hand over to parse_packet_tun to interpret the IPv6 packet
ipv6packet, err := i.parse_packet_tun(datain[ETHER:]) ipv6packet, err := i.parse_packet_tun(datain[len_ETHER:])
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Create the response buffer // Create the response buffer
dataout := make([]byte, ETHER+ipv6.HeaderLen+32) dataout := make([]byte, len_ETHER+ipv6.HeaderLen+32)
// Populate the response ethernet headers // Populate the response ethernet headers
copy(dataout[:6], datain[6:12]) copy(dataout[:6], datain[6:12])
@ -93,7 +93,7 @@ func (i *icmpv6) parse_packet_tap(datain []byte) ([]byte, error) {
binary.BigEndian.PutUint16(dataout[12:14], uint16(0x86DD)) binary.BigEndian.PutUint16(dataout[12:14], uint16(0x86DD))
// Copy the returned packet to our response ethernet frame // Copy the returned packet to our response ethernet frame
copy(dataout[ETHER:], ipv6packet) copy(dataout[len_ETHER:], ipv6packet)
return dataout, nil return dataout, nil
} }
@ -157,7 +157,7 @@ func (i *icmpv6) create_icmpv6_tap(dstmac macAddress, dst net.IP, src net.IP, mt
} }
// Create the response buffer // Create the response buffer
dataout := make([]byte, ETHER+len(ipv6packet)) dataout := make([]byte, len_ETHER+len(ipv6packet))
// Populate the response ethernet headers // Populate the response ethernet headers
copy(dataout[:6], dstmac[:6]) copy(dataout[:6], dstmac[:6])
@ -165,7 +165,7 @@ func (i *icmpv6) create_icmpv6_tap(dstmac macAddress, dst net.IP, src net.IP, mt
binary.BigEndian.PutUint16(dataout[12:14], uint16(0x86DD)) binary.BigEndian.PutUint16(dataout[12:14], uint16(0x86DD))
// Copy the returned packet to our response ethernet frame // Copy the returned packet to our response ethernet frame
copy(dataout[ETHER:], ipv6packet) copy(dataout[len_ETHER:], ipv6packet)
return dataout, nil return dataout, nil
} }

View File

@ -5,8 +5,8 @@ package yggdrasil
import "github.com/songgao/packets/ethernet" import "github.com/songgao/packets/ethernet"
import "github.com/yggdrasil-network/water" import "github.com/yggdrasil-network/water"
const IPv6_HEADER_LENGTH = 40 const tun_IPv6_HEADER_LENGTH = 40
const ETHER_HEADER_LENGTH = 14 const tun_ETHER_HEADER_LENGTH = 14
type tunDevice struct { type tunDevice struct {
core *Core core *Core
@ -59,7 +59,7 @@ func (tun *tunDevice) write() error {
ethernet.NotTagged, // VLAN tagging ethernet.NotTagged, // VLAN tagging
ethernet.IPv6, // Ethertype ethernet.IPv6, // Ethertype
len(data)) // Payload length len(data)) // Payload length
copy(frame[ETHER_HEADER_LENGTH:], data[:]) copy(frame[tun_ETHER_HEADER_LENGTH:], data[:])
if _, err := tun.iface.Write(frame); err != nil { if _, err := tun.iface.Write(frame); err != nil {
panic(err) panic(err)
} }
@ -75,7 +75,7 @@ func (tun *tunDevice) write() error {
func (tun *tunDevice) read() error { func (tun *tunDevice) read() error {
mtu := tun.mtu mtu := tun.mtu
if tun.iface.IsTAP() { if tun.iface.IsTAP() {
mtu += ETHER_HEADER_LENGTH mtu += tun_ETHER_HEADER_LENGTH
} }
buf := make([]byte, mtu) buf := make([]byte, mtu)
for { for {
@ -86,10 +86,10 @@ func (tun *tunDevice) read() error {
} }
o := 0 o := 0
if tun.iface.IsTAP() { if tun.iface.IsTAP() {
o = ETHER_HEADER_LENGTH o = tun_ETHER_HEADER_LENGTH
} }
if buf[o]&0xf0 != 0x60 || if buf[o]&0xf0 != 0x60 ||
n != 256*int(buf[o+4])+int(buf[o+5])+IPv6_HEADER_LENGTH+o { n != 256*int(buf[o+4])+int(buf[o+5])+tun_IPv6_HEADER_LENGTH+o {
// Either not an IPv6 packet or not the complete packet for some reason // Either not an IPv6 packet or not the complete packet for some reason
//panic("Should not happen in testing") //panic("Should not happen in testing")
continue continue

View File

@ -33,7 +33,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
return tun.setupAddress(addr) return tun.setupAddress(addr)
} }
const SIOCAIFADDR_IN6 = 2155899162 const darwin_SIOCAIFADDR_IN6 = 2155899162
type in6_addrlifetime struct { type in6_addrlifetime struct {
ia6t_expire float64 ia6t_expire float64
@ -103,9 +103,9 @@ func (tun *tunDevice) setupAddress(addr string) error {
tun.core.log.Printf("Interface IPv6: %s", addr) tun.core.log.Printf("Interface IPv6: %s", addr)
tun.core.log.Printf("Interface MTU: %d", ir.ifru_mtu) tun.core.log.Printf("Interface MTU: %d", ir.ifru_mtu)
if _, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(SIOCAIFADDR_IN6), uintptr(unsafe.Pointer(&ar))); errno != 0 { if _, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(darwin_SIOCAIFADDR_IN6), uintptr(unsafe.Pointer(&ar))); errno != 0 {
err = errno err = errno
tun.core.log.Printf("Error in SIOCAIFADDR_IN6: %v", errno) tun.core.log.Printf("Error in darwin_SIOCAIFADDR_IN6: %v", errno)
return err return err
} }

View File

@ -2,34 +2,10 @@ package yggdrasil
// These are misc. utility functions that didn't really fit anywhere else // These are misc. utility functions that didn't really fit anywhere else
import "fmt"
import "runtime" import "runtime"
//import "sync" //import "sync"
func Util_testAddrIDMask() {
for idx := 0; idx < 16; idx++ {
var orig NodeID
orig[8] = 42
for bidx := 0; bidx < idx; bidx++ {
orig[bidx/8] |= (0x80 >> uint8(bidx%8))
}
addr := address_addrForNodeID(&orig)
nid, mask := addr.getNodeIDandMask()
for b := 0; b < len(mask); b++ {
nid[b] &= mask[b]
orig[b] &= mask[b]
}
if *nid != orig {
fmt.Println(orig)
fmt.Println(*addr)
fmt.Println(*nid)
fmt.Println(*mask)
panic(idx)
}
}
}
func util_yield() { func util_yield() {
runtime.Gosched() runtime.Gosched()
} }