From 6571a8c300e97cd4e583f23a6a8df7fc32b6c78f Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 12 Feb 2018 20:00:55 +0000 Subject: [PATCH] Don't use channels for ICMPv6 packets --- src/yggdrasil/icmpv6.go | 42 ++++++++++++++--------------------------- src/yggdrasil/tun.go | 7 ++++++- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/yggdrasil/icmpv6.go b/src/yggdrasil/icmpv6.go index 85d4595..483902b 100644 --- a/src/yggdrasil/icmpv6.go +++ b/src/yggdrasil/icmpv6.go @@ -6,7 +6,6 @@ package yggdrasil import "golang.org/x/net/icmp" import "encoding/binary" -import "errors" import "unsafe" // TODO investigate if this can be done without resorting to unsafe type macAddress [6]byte @@ -21,7 +20,6 @@ type icmpv6 struct { peerlladdr ipv6Address mymac macAddress mylladdr ipv6Address - recv chan []byte } type etherHeader struct { @@ -76,39 +74,27 @@ type icmpv6Frame struct { func (i *icmpv6) init(t *tunDevice) { i.tun = t - i.recv = make(chan []byte) copy(i.mymac[:], []byte{0x02, 0x00, 0x00, 0x00, 0x00, 0x02}) copy(i.mylladdr[:], []byte{ 0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFE}) - go i.listen() } -func (i *icmpv6) listen() { - for { - datain := <-i.recv +func (i *icmpv6) parse_packet(datain []byte) { + var response []byte + var err error - if i.tun.iface.IsTAP() { - // TAP mode - response, err := i.parse_packet_tap(datain) - if err != nil { - i.tun.core.log.Printf("Error from icmpv6.parse_packet_tap: %v", err) - continue - } - if response != nil { - i.tun.iface.Write(response) - } - } else { - // TUN mode - response, err := i.parse_packet_tun(datain) - if err != nil { - i.tun.core.log.Printf("Error from icmpv6.parse_packet_tun: %v", err) - continue - } - if response != nil { - i.tun.iface.Write(response) - } - } + if i.tun.iface.IsTAP() { + response, err = i.parse_packet_tap(datain) + } else { + response, err = i.parse_packet_tun(datain) + } + if err != nil { + i.tun.core.log.Printf("ICMPv6 error: %v", err) + return + } + if response != nil { + i.tun.iface.Write(response) } } diff --git a/src/yggdrasil/tun.go b/src/yggdrasil/tun.go index b1d96d9..dc2c673 100644 --- a/src/yggdrasil/tun.go +++ b/src/yggdrasil/tun.go @@ -79,7 +79,12 @@ func (tun *tunDevice) read() error { // Found an ICMPv6 packet b := make([]byte, n) copy(b, buf) - tun.icmpv6.recv <- b + // tun.icmpv6.recv <- b + if tun.iface.IsTAP() { + go tun.icmpv6.parse_packet_tap(b) + } else { + go tun.icmpv6.parse_packet_tun(b) + } } packet := append(util_getBytes(), buf[o:n]...) tun.send <- packet