mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-23 12:15:39 +00:00
Fix adapter setup and no longer panics on packets shorter than IP header
This commit is contained in:
parent
0b494a8255
commit
0715e829c2
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user