mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25: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
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue