Remove ndp.go and add icmpv6.go

This commit is contained in:
Neil Alexander 2018-02-12 18:19:31 +00:00
parent 38567fffef
commit be0d6feeba
3 changed files with 221 additions and 180 deletions

View file

@ -17,17 +17,17 @@ type tunInterface interface {
}
type tunDevice struct {
core *Core
ndp ndp
send chan<- []byte
recv <-chan []byte
mtu int
iface tunInterface
core *Core
icmpv6 icmpv6
send chan<- []byte
recv <-chan []byte
mtu int
iface tunInterface
}
func (tun *tunDevice) init(core *Core) {
tun.core = core
tun.ndp.init(tun)
tun.icmpv6.init(tun)
}
func (tun *tunDevice) write() error {
@ -36,11 +36,11 @@ func (tun *tunDevice) write() error {
if tun.iface.IsTAP() {
var frame ethernet.Frame
frame.Prepare(
tun.ndp.peermac[:6], // Destination MAC address
tun.ndp.mymac[:6], // Source MAC address
ethernet.NotTagged, // VLAN tagging
ethernet.IPv6, // Ethertype
len(data)) // Payload length
tun.icmpv6.peermac[:6], // Destination MAC address
tun.icmpv6.mymac[:6], // Source MAC address
ethernet.NotTagged, // VLAN tagging
ethernet.IPv6, // Ethertype
len(data)) // Payload length
copy(frame[ETHER_HEADER_LENGTH:], data[:])
if _, err := tun.iface.Write(frame); err != nil {
panic(err)
@ -68,9 +68,6 @@ func (tun *tunDevice) read() error {
o := 0
if tun.iface.IsTAP() {
o = ETHER_HEADER_LENGTH
b := make([]byte, n)
copy(b, buf)
tun.ndp.recv <- b
}
if buf[o]&0xf0 != 0x60 ||
n != 256*int(buf[o+4])+int(buf[o+5])+IPv6_HEADER_LENGTH+o {
@ -78,6 +75,12 @@ func (tun *tunDevice) read() error {
//panic("Should not happen in testing")
continue
}
if buf[o+6] == 58 {
// Found an ICMPv6 packet
b := make([]byte, n)
copy(b, buf)
tun.icmpv6.recv <- b
}
packet := append(util_getBytes(), buf[o:n]...)
tun.send <- packet
}