mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 16:31:41 +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
|
// 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
|
// 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" {
|
if ifname == "none" || ifname == "dummy" {
|
||||||
|
tun.log.Debugln("Not starting TUN/TAP as ifname is none or dummy")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
tun.mutex.Lock()
|
tun.mutex.Lock()
|
||||||
tun.isOpen = true
|
tun.isOpen = true
|
||||||
tun.mutex.Unlock()
|
tun.mutex.Unlock()
|
||||||
go func() { tun.log.Errorln("WARNING: tun.read() exited with error:", tun.Read()) }()
|
go func() {
|
||||||
go func() { tun.log.Errorln("WARNING: tun.write() exited with error:", tun.Write()) }()
|
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 {
|
if iftapmode {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@ -147,12 +154,16 @@ func (tun *TunAdapter) Write() error {
|
|||||||
var destAddr address.Address
|
var destAddr address.Address
|
||||||
if data[0]&0xf0 == 0x60 {
|
if data[0]&0xf0 == 0x60 {
|
||||||
if len(data) < 40 {
|
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:])
|
copy(destAddr[:16], data[24:])
|
||||||
} else if data[0]&0xf0 == 0x40 {
|
} else if data[0]&0xf0 == 0x40 {
|
||||||
if len(data) < 20 {
|
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:])
|
copy(destAddr[:4], data[16:])
|
||||||
} else {
|
} else {
|
||||||
@ -255,7 +266,6 @@ func (tun *TunAdapter) Read() error {
|
|||||||
if !open {
|
if !open {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
// panic(err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,8 @@ type adapterImplementation interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialises the adapter.
|
// 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.Send = send
|
||||||
adapter.Recv = recv
|
adapter.Recv = recv
|
||||||
adapter.Reconfigure = make(chan chan error, 1)
|
adapter.Reconfigure = make(chan chan error, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user