mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-12-24 00:37:49 +00:00
allow for multiple traffic types inside the session at the tuntap level, only implement typeSessionTraffic for now
This commit is contained in:
parent
dfca87ba80
commit
2c7b22db92
@ -50,6 +50,8 @@ func (tun *TunAdapter) read() {
|
||||
if srcAddr != tun.addr && srcSubnet != tun.subnet {
|
||||
continue // Wrong soruce address
|
||||
}
|
||||
bs = buf[begin-1 : end]
|
||||
bs[0] = typeSessionTraffic
|
||||
if dstAddr.IsValid() {
|
||||
tun.store.sendToAddress(dstAddr, bs)
|
||||
} else if dstSubnet.IsValid() {
|
||||
@ -61,12 +63,24 @@ func (tun *TunAdapter) read() {
|
||||
func (tun *TunAdapter) write() {
|
||||
var buf [TUN_OFFSET_BYTES + 65535]byte
|
||||
for {
|
||||
bs := buf[TUN_OFFSET_BYTES:]
|
||||
bs := buf[TUN_OFFSET_BYTES-1:]
|
||||
n, from, err := tun.core.ReadFrom(bs)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
bs = bs[:n]
|
||||
if n == 0 {
|
||||
continue
|
||||
}
|
||||
switch bs[0] {
|
||||
case typeSessionTraffic:
|
||||
// This is what we want to handle here
|
||||
default:
|
||||
continue
|
||||
}
|
||||
bs = bs[1:n]
|
||||
if len(bs) == 0 {
|
||||
continue
|
||||
}
|
||||
if bs[0]&0xf0 != 0x60 {
|
||||
continue // not IPv6
|
||||
}
|
||||
@ -99,7 +113,7 @@ func (tun *TunAdapter) write() {
|
||||
if srcAddr != info.address && srcSubnet != info.subnet {
|
||||
continue // bad remote address/subnet
|
||||
}
|
||||
bs = buf[:TUN_OFFSET_BYTES+n]
|
||||
bs = buf[:TUN_OFFSET_BYTES+len(bs)]
|
||||
n, err = tun.iface.Write(bs, TUN_OFFSET_BYTES)
|
||||
if err != nil {
|
||||
tun.Act(nil, func() {
|
||||
|
@ -150,8 +150,8 @@ func (tun *TunAdapter) _start() error {
|
||||
return nil
|
||||
}
|
||||
mtu := current.IfMTU
|
||||
if tun.core.MTU() < uint64(mtu) {
|
||||
mtu = MTU(tun.core.MTU())
|
||||
if tun.maxSessionMTU() < mtu {
|
||||
mtu = tun.maxSessionMTU()
|
||||
}
|
||||
if err := tun.setup(current.IfName, addr, mtu); err != nil {
|
||||
return err
|
||||
@ -216,11 +216,6 @@ func (tun *TunAdapter) oobHandler(fromKey, toKey ed25519.PublicKey, data []byte)
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
typeKeyLookup = 1
|
||||
typeKeyResponse = 2
|
||||
)
|
||||
|
||||
func (tun *TunAdapter) sendKeyLookup(partial ed25519.PublicKey) {
|
||||
sig := ed25519.Sign(tun.core.PrivateKey(), partial[:])
|
||||
bs := append([]byte{typeKeyLookup}, sig...)
|
||||
@ -232,3 +227,8 @@ func (tun *TunAdapter) sendKeyResponse(dest ed25519.PublicKey) {
|
||||
bs := append([]byte{typeKeyResponse}, sig...)
|
||||
tun.core.SendOutOfBand(dest, bs)
|
||||
}
|
||||
|
||||
func (tun *TunAdapter) maxSessionMTU() MTU {
|
||||
const sessionTypeOverhead = 1
|
||||
return MTU(tun.core.MTU() - sessionTypeOverhead)
|
||||
}
|
||||
|
14
src/tuntap/types.go
Normal file
14
src/tuntap/types.go
Normal file
@ -0,0 +1,14 @@
|
||||
package tuntap
|
||||
|
||||
// Out-of-band packet types
|
||||
const (
|
||||
typeKeyDummy = iota
|
||||
typeKeyLookup
|
||||
typeKeyResponse
|
||||
)
|
||||
|
||||
// In-band packet types
|
||||
const (
|
||||
typeSessionDummy = iota
|
||||
typeSessionTraffic
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user