From 6fab0e9507d2a309b65cadb69e14d46366a23c2c Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 10 Nov 2018 18:33:52 +0000 Subject: [PATCH] Fix CKR (IPv4/IPv6) in TAP mode so frames sent to node MAC, base MAC/LL from node IPv6 address --- src/yggdrasil/icmpv6.go | 4 ++-- src/yggdrasil/tun.go | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/yggdrasil/icmpv6.go b/src/yggdrasil/icmpv6.go index c62475c5..957b192e 100644 --- a/src/yggdrasil/icmpv6.go +++ b/src/yggdrasil/icmpv6.go @@ -67,8 +67,8 @@ func (i *icmpv6) init(t *tunDevice) { i.mylladdr = net.IP{ 0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFE} - copy(i.mymac[1:], i.tun.core.boxPub[:]) - copy(i.mylladdr[9:], i.tun.core.boxPub[:]) + copy(i.mymac[:], i.tun.core.router.addr[:]) + copy(i.mylladdr[9:], i.tun.core.router.addr[1:]) } // Parses an incoming ICMPv6 packet. The packet provided may be either an diff --git a/src/yggdrasil/tun.go b/src/yggdrasil/tun.go index 55ddbd74..447ba617 100644 --- a/src/yggdrasil/tun.go +++ b/src/yggdrasil/tun.go @@ -3,6 +3,7 @@ package yggdrasil // This manages the tun driver to send/recv packets to/from applications import ( + "bytes" "errors" "time" "yggdrasil/defaults" @@ -110,6 +111,13 @@ func (tun *tunDevice) write() error { } var peermac macAddress var peerknown bool + if data[0]&0xf0 == 0x40 { + destAddr = tun.core.router.addr + } else if data[0]&0xf0 == 0x60 { + if !bytes.Equal(tun.core.router.addr[:16], destAddr[:16]) && !bytes.Equal(tun.core.router.subnet[:8], destAddr[:8]) { + destAddr = tun.core.router.addr + } + } if neighbor, ok := tun.icmpv6.peermacs[destAddr]; ok && neighbor.learned { peermac = neighbor.mac peerknown = true @@ -121,12 +129,19 @@ func (tun *tunDevice) write() error { sendndp(tun.core.router.addr) } if peerknown { + var proto ethernet.Ethertype + switch { + case data[0]&0xf0 == 0x60: + proto = ethernet.IPv6 + case data[0]&0xf0 == 0x40: + proto = ethernet.IPv4 + } var frame ethernet.Frame frame.Prepare( peermac[:6], // Destination MAC address tun.icmpv6.mymac[:6], // Source MAC address ethernet.NotTagged, // VLAN tagging - ethernet.IPv6, // Ethertype + proto, // Ethertype len(data)) // Payload length copy(frame[tun_ETHER_HEADER_LENGTH:], data[:]) if _, err := tun.iface.Write(frame); err != nil {