mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	Clean up some exported constants
This commit is contained in:
		
							parent
							
								
									a9e61d0d37
								
							
						
					
					
						commit
						460a22c063
					
				
					 5 changed files with 40 additions and 39 deletions
				
			
		| 
						 | 
				
			
			@ -456,3 +456,28 @@ func DEBUG_simLinkPeers(p, q *peer) {
 | 
			
		|||
func (c *Core) DEBUG_simFixMTU() {
 | 
			
		||||
	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)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,7 +12,7 @@ import "errors"
 | 
			
		|||
 | 
			
		||||
type macAddress [6]byte
 | 
			
		||||
 | 
			
		||||
const ETHER = 14
 | 
			
		||||
const len_ETHER = 14
 | 
			
		||||
 | 
			
		||||
type icmpv6 struct {
 | 
			
		||||
	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
 | 
			
		||||
	ipv6packet, err := i.parse_packet_tun(datain[ETHER:])
 | 
			
		||||
	ipv6packet, err := i.parse_packet_tun(datain[len_ETHER:])
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Create the response buffer
 | 
			
		||||
	dataout := make([]byte, ETHER+ipv6.HeaderLen+32)
 | 
			
		||||
	dataout := make([]byte, len_ETHER+ipv6.HeaderLen+32)
 | 
			
		||||
 | 
			
		||||
	// Populate the response ethernet headers
 | 
			
		||||
	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))
 | 
			
		||||
 | 
			
		||||
	// Copy the returned packet to our response ethernet frame
 | 
			
		||||
	copy(dataout[ETHER:], ipv6packet)
 | 
			
		||||
	copy(dataout[len_ETHER:], ipv6packet)
 | 
			
		||||
	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
 | 
			
		||||
	dataout := make([]byte, ETHER+len(ipv6packet))
 | 
			
		||||
	dataout := make([]byte, len_ETHER+len(ipv6packet))
 | 
			
		||||
 | 
			
		||||
	// Populate the response ethernet headers
 | 
			
		||||
	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))
 | 
			
		||||
 | 
			
		||||
	// Copy the returned packet to our response ethernet frame
 | 
			
		||||
	copy(dataout[ETHER:], ipv6packet)
 | 
			
		||||
	copy(dataout[len_ETHER:], ipv6packet)
 | 
			
		||||
	return dataout, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,8 +5,8 @@ package yggdrasil
 | 
			
		|||
import "github.com/songgao/packets/ethernet"
 | 
			
		||||
import "github.com/yggdrasil-network/water"
 | 
			
		||||
 | 
			
		||||
const IPv6_HEADER_LENGTH = 40
 | 
			
		||||
const ETHER_HEADER_LENGTH = 14
 | 
			
		||||
const tun_IPv6_HEADER_LENGTH = 40
 | 
			
		||||
const tun_ETHER_HEADER_LENGTH = 14
 | 
			
		||||
 | 
			
		||||
type tunDevice struct {
 | 
			
		||||
	core   *Core
 | 
			
		||||
| 
						 | 
				
			
			@ -59,7 +59,7 @@ func (tun *tunDevice) write() error {
 | 
			
		|||
				ethernet.NotTagged,     // VLAN tagging
 | 
			
		||||
				ethernet.IPv6,          // Ethertype
 | 
			
		||||
				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 {
 | 
			
		||||
				panic(err)
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			@ -75,7 +75,7 @@ func (tun *tunDevice) write() error {
 | 
			
		|||
func (tun *tunDevice) read() error {
 | 
			
		||||
	mtu := tun.mtu
 | 
			
		||||
	if tun.iface.IsTAP() {
 | 
			
		||||
		mtu += ETHER_HEADER_LENGTH
 | 
			
		||||
		mtu += tun_ETHER_HEADER_LENGTH
 | 
			
		||||
	}
 | 
			
		||||
	buf := make([]byte, mtu)
 | 
			
		||||
	for {
 | 
			
		||||
| 
						 | 
				
			
			@ -86,10 +86,10 @@ func (tun *tunDevice) read() error {
 | 
			
		|||
		}
 | 
			
		||||
		o := 0
 | 
			
		||||
		if tun.iface.IsTAP() {
 | 
			
		||||
			o = ETHER_HEADER_LENGTH
 | 
			
		||||
			o = tun_ETHER_HEADER_LENGTH
 | 
			
		||||
		}
 | 
			
		||||
		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
 | 
			
		||||
			//panic("Should not happen in testing")
 | 
			
		||||
			continue
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,7 +33,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
 | 
			
		|||
	return tun.setupAddress(addr)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const SIOCAIFADDR_IN6 = 2155899162
 | 
			
		||||
const darwin_SIOCAIFADDR_IN6 = 2155899162
 | 
			
		||||
 | 
			
		||||
type in6_addrlifetime struct {
 | 
			
		||||
	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 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
 | 
			
		||||
		tun.core.log.Printf("Error in SIOCAIFADDR_IN6: %v", errno)
 | 
			
		||||
		tun.core.log.Printf("Error in darwin_SIOCAIFADDR_IN6: %v", errno)
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,34 +2,10 @@ package yggdrasil
 | 
			
		|||
 | 
			
		||||
// These are misc. utility functions that didn't really fit anywhere else
 | 
			
		||||
 | 
			
		||||
import "fmt"
 | 
			
		||||
import "runtime"
 | 
			
		||||
 | 
			
		||||
//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() {
 | 
			
		||||
	runtime.Gosched()
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue