mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-10 08:40:28 +00:00
Fix TAP support
This commit is contained in:
parent
b4513ca2e8
commit
2b44f5d2f6
@ -169,7 +169,6 @@ func (i *ICMPv6) UnmarshalPacket(datain []byte, datamac *[]byte) ([]byte, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send it back
|
// Send it back
|
||||||
return responsePacket, nil
|
return responsePacket, nil
|
||||||
} else {
|
} else {
|
||||||
@ -186,7 +185,7 @@ func (i *ICMPv6) UnmarshalPacket(datain []byte, datamac *[]byte) ([]byte, error)
|
|||||||
copy(addr[:], ipv6Header.Src[:])
|
copy(addr[:], ipv6Header.Src[:])
|
||||||
copy(target[:], datain[48:64])
|
copy(target[:], datain[48:64])
|
||||||
copy(mac[:], (*datamac)[:])
|
copy(mac[:], (*datamac)[:])
|
||||||
// i.tun.core.log.Printf("Learning peer MAC %x for %x\n", mac, target)
|
// fmt.Printf("Learning peer MAC %x for %x\n", mac, target)
|
||||||
neighbor := i.peermacs[target]
|
neighbor := i.peermacs[target]
|
||||||
neighbor.mac = mac
|
neighbor.mac = mac
|
||||||
neighbor.learned = true
|
neighbor.learned = true
|
||||||
|
@ -114,7 +114,6 @@ func (tun *TunAdapter) Init(config *config.NodeState, log *log.Logger, listener
|
|||||||
tun.dialer = dialer
|
tun.dialer = dialer
|
||||||
tun.addrToConn = make(map[address.Address]*yggdrasil.Conn)
|
tun.addrToConn = make(map[address.Address]*yggdrasil.Conn)
|
||||||
tun.subnetToConn = make(map[address.Subnet]*yggdrasil.Conn)
|
tun.subnetToConn = make(map[address.Subnet]*yggdrasil.Conn)
|
||||||
tun.icmpv6.Init(tun)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the setup process for the TUN/TAP adapter. If successful, starts the
|
// Start the setup process for the TUN/TAP adapter. If successful, starts the
|
||||||
@ -175,6 +174,7 @@ func (tun *TunAdapter) Start() error {
|
|||||||
}()
|
}()
|
||||||
go tun.handler()
|
go tun.handler()
|
||||||
go tun.ifaceReader()
|
go tun.ifaceReader()
|
||||||
|
tun.icmpv6.Init(tun)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,17 +328,20 @@ func (tun *TunAdapter) ifaceReader() error {
|
|||||||
}
|
}
|
||||||
// If it's a TAP adapter, update the buffer slice so that we no longer
|
// If it's a TAP adapter, update the buffer slice so that we no longer
|
||||||
// include the ethernet headers
|
// include the ethernet headers
|
||||||
|
offset := 0
|
||||||
if tun.iface.IsTAP() {
|
if tun.iface.IsTAP() {
|
||||||
bs = bs[tun_ETHER_HEADER_LENGTH:]
|
// Set our offset to beyond the ethernet headers
|
||||||
}
|
offset = tun_ETHER_HEADER_LENGTH
|
||||||
// If we detect an ICMP packet then hand it to the ICMPv6 module
|
// If we detect an ICMP packet then hand it to the ICMPv6 module
|
||||||
if bs[6] == 58 {
|
if bs[offset+6] == 58 {
|
||||||
if tun.iface.IsTAP() {
|
|
||||||
// Found an ICMPv6 packet
|
// Found an ICMPv6 packet
|
||||||
b := make([]byte, n)
|
b := make([]byte, n)
|
||||||
copy(b, bs)
|
copy(b, bs)
|
||||||
go tun.icmpv6.ParsePacket(b)
|
go tun.icmpv6.ParsePacket(b)
|
||||||
}
|
}
|
||||||
|
// Then offset the buffer so that we can now just treat it as an IP
|
||||||
|
// packet from now on
|
||||||
|
bs = bs[offset:]
|
||||||
}
|
}
|
||||||
// From the IP header, work out what our source and destination addresses
|
// From the IP header, work out what our source and destination addresses
|
||||||
// and node IDs are. We will need these in order to work out where to send
|
// and node IDs are. We will need these in order to work out where to send
|
||||||
@ -357,7 +360,7 @@ func (tun *TunAdapter) ifaceReader() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Check the packet size
|
// Check the packet size
|
||||||
if n != 256*int(bs[4])+int(bs[5])+tun_IPv6_HEADER_LENGTH {
|
if n != 256*int(bs[4])+int(bs[5])+offset+tun_IPv6_HEADER_LENGTH {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// IPv6 address
|
// IPv6 address
|
||||||
@ -371,7 +374,7 @@ func (tun *TunAdapter) ifaceReader() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Check the packet size
|
// Check the packet size
|
||||||
if bs[0]&0xf0 == 0x40 && n != 256*int(bs[2])+int(bs[3]) {
|
if n != 256*int(bs[2])+int(bs[3])+offset {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// IPv4 address
|
// IPv4 address
|
||||||
|
Loading…
Reference in New Issue
Block a user