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

Fix adapter setup and no longer panics on packets shorter than IP header

This commit is contained in:
Neil Alexander 2019-03-28 09:12:00 +00:00
parent 0b494a8255
commit 0715e829c2
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
3 changed files with 18 additions and 7 deletions

View File

@ -93,7 +93,7 @@ func (i *ICMPv6) ParsePacket(datain []byte) {
}
// Write the packet to TUN/TAP
i.tun.Send <- response
i.tun.iface.Write(response)
}
// Unwraps the ethernet headers of an incoming ICMPv6 packet and hands off

View File

@ -107,13 +107,20 @@ func (tun *TunAdapter) Start(a address.Address, s address.Subnet) error {
}
}
if ifname == "none" || ifname == "dummy" {
tun.log.Debugln("Not starting TUN/TAP as ifname is none or dummy")
return nil
}
tun.mutex.Lock()
tun.isOpen = true
tun.mutex.Unlock()
go func() { tun.log.Errorln("WARNING: tun.read() exited with error:", tun.Read()) }()
go func() { tun.log.Errorln("WARNING: tun.write() exited with error:", tun.Write()) }()
go func() {
tun.log.Debugln("Starting TUN/TAP reader goroutine")
tun.log.Errorln("WARNING: tun.read() exited with error:", tun.Read())
}()
go func() {
tun.log.Debugln("Starting TUN/TAP writer goroutine")
tun.log.Errorln("WARNING: tun.write() exited with error:", tun.Write())
}()
if iftapmode {
go func() {
for {
@ -147,12 +154,16 @@ func (tun *TunAdapter) Write() error {
var destAddr address.Address
if data[0]&0xf0 == 0x60 {
if len(data) < 40 {
panic("Tried to send a packet shorter than an IPv6 header...")
//panic("Tried to send a packet shorter than an IPv6 header...")
util.PutBytes(data)
continue
}
copy(destAddr[:16], data[24:])
} else if data[0]&0xf0 == 0x40 {
if len(data) < 20 {
panic("Tried to send a packet shorter than an IPv4 header...")
//panic("Tried to send a packet shorter than an IPv4 header...")
util.PutBytes(data)
continue
}
copy(destAddr[:4], data[16:])
} else {
@ -255,7 +266,6 @@ func (tun *TunAdapter) Read() error {
if !open {
return nil
} else {
// panic(err)
return err
}
}

View File

@ -29,7 +29,8 @@ type adapterImplementation interface {
}
// Initialises the adapter.
func (adapter Adapter) Init(config *config.NodeState, log *log.Logger, send chan<- []byte, recv <-chan []byte) {
func (adapter *Adapter) Init(config *config.NodeState, log *log.Logger, send chan<- []byte, recv <-chan []byte) {
log.Traceln("Adapter setup - given channels:", send, recv)
adapter.Send = send
adapter.Recv = recv
adapter.Reconfigure = make(chan chan error, 1)