Run gofmt -s -w .

This commit is contained in:
Neil Alexander 2018-01-04 22:37:51 +00:00
parent ae7b07ae6a
commit b3ebe76b59
45 changed files with 5037 additions and 4288 deletions

View file

@ -7,41 +7,45 @@ import water "github.com/songgao/water"
const IPv6_HEADER_LENGTH = 40
type tunDevice struct {
core *Core
send chan<- []byte
recv <-chan []byte
mtu int
iface *water.Interface
core *Core
send chan<- []byte
recv <-chan []byte
mtu int
iface *water.Interface
}
func (tun *tunDevice) init(core *Core) {
tun.core = core
tun.core = core
}
func (tun *tunDevice) write() error {
for {
data := <-tun.recv
if _, err := tun.iface.Write(data); err != nil { return err }
util_putBytes(data)
}
for {
data := <-tun.recv
if _, err := tun.iface.Write(data); err != nil {
return err
}
util_putBytes(data)
}
}
func (tun *tunDevice) read() error {
buf := make([]byte, tun.mtu)
for {
n, err := tun.iface.Read(buf)
if err != nil { return err }
if buf[0] & 0xf0 != 0x60 ||
n != 256*int(buf[4]) + int(buf[5]) + IPv6_HEADER_LENGTH {
// Either not an IPv6 packet or not the complete packet for some reason
//panic("Should not happen in testing")
continue
}
packet := append(util_getBytes(), buf[:n]...)
tun.send<-packet
}
buf := make([]byte, tun.mtu)
for {
n, err := tun.iface.Read(buf)
if err != nil {
return err
}
if buf[0]&0xf0 != 0x60 ||
n != 256*int(buf[4])+int(buf[5])+IPv6_HEADER_LENGTH {
// Either not an IPv6 packet or not the complete packet for some reason
//panic("Should not happen in testing")
continue
}
packet := append(util_getBytes(), buf[:n]...)
tun.send <- packet
}
}
func (tun *tunDevice) close() error {
return tun.iface.Close()
return tun.iface.Close()
}