allow for multiple traffic types inside the session at the tuntap level, only implement typeSessionTraffic for now

This commit is contained in:
Arceliar 2021-05-16 13:01:54 -05:00
parent dfca87ba80
commit 2c7b22db92
3 changed files with 38 additions and 10 deletions

View file

@ -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)
}