mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
WIP moving IP-specific checks from tuntap to core
This commit is contained in:
parent
bb66851c2b
commit
1147ee1934
9 changed files with 339 additions and 220 deletions
|
@ -189,41 +189,3 @@ func (tun *TunAdapter) _stop() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (tun *TunAdapter) oobHandler(fromKey, toKey ed25519.PublicKey, data []byte) {
|
||||
if len(data) != 1+ed25519.SignatureSize {
|
||||
return
|
||||
}
|
||||
sig := data[1:]
|
||||
switch data[0] {
|
||||
case typeKeyLookup:
|
||||
snet := *address.SubnetForKey(toKey)
|
||||
if snet == tun.subnet && ed25519.Verify(fromKey, toKey[:], sig) {
|
||||
// This is looking for at least our subnet (possibly our address)
|
||||
// Send a response
|
||||
tun.sendKeyResponse(fromKey)
|
||||
}
|
||||
case typeKeyResponse:
|
||||
// TODO keep a list of something to match against...
|
||||
// Ignore the response if it doesn't match anything of interest...
|
||||
if ed25519.Verify(fromKey, toKey[:], sig) {
|
||||
tun.store.update(fromKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (tun *TunAdapter) sendKeyLookup(partial ed25519.PublicKey) {
|
||||
sig := ed25519.Sign(tun.core.PrivateKey(), partial[:])
|
||||
bs := append([]byte{typeKeyLookup}, sig...)
|
||||
_ = tun.core.SendOutOfBand(partial, bs)
|
||||
}
|
||||
|
||||
func (tun *TunAdapter) sendKeyResponse(dest ed25519.PublicKey) {
|
||||
sig := ed25519.Sign(tun.core.PrivateKey(), dest[:])
|
||||
bs := append([]byte{typeKeyResponse}, sig...)
|
||||
_ = tun.core.SendOutOfBand(dest, bs)
|
||||
}
|
||||
|
||||
func (tun *TunAdapter) maxSessionMTU() uint64 {
|
||||
const sessionTypeOverhead = 1
|
||||
return tun.core.MTU() - sessionTypeOverhead
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue