Don't use channels for ICMPv6 packets

This commit is contained in:
Neil Alexander 2018-02-12 20:00:55 +00:00
parent fac4bf796e
commit 6571a8c300
2 changed files with 20 additions and 29 deletions

View File

@ -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,41 +74,29 @@ 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)
}
response, err = i.parse_packet_tap(datain)
} else {
// TUN mode
response, err := i.parse_packet_tun(datain)
response, err = i.parse_packet_tun(datain)
}
if err != nil {
i.tun.core.log.Printf("Error from icmpv6.parse_packet_tun: %v", err)
continue
i.tun.core.log.Printf("ICMPv6 error: %v", err)
return
}
if response != nil {
i.tun.iface.Write(response)
}
}
}
}
func (i *icmpv6) parse_packet_tap(datain []byte) ([]byte, error) {
// Set up

View File

@ -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