mirror of
https://github.com/yggdrasil-network/yggdrasil-go
synced 2024-11-09 23:20:26 +03:00
Don't use channels for ICMPv6 packets
This commit is contained in:
parent
fac4bf796e
commit
6571a8c300
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user