mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Fix CKR (IPv4/IPv6) in TAP mode so frames sent to node MAC, base MAC/LL from node IPv6 address
This commit is contained in:
		
							parent
							
								
									adc32fe92f
								
							
						
					
					
						commit
						6fab0e9507
					
				
					 2 changed files with 18 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue