mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 04:50:29 +00:00
Merge pull request #13 from neilalexander/exchangemtu
Include endpoint MTU in session pings
This commit is contained in:
commit
f6bdbda5c3
@ -223,6 +223,7 @@ func (a *admin) getData_getSessions() []admin_nodeInfo {
|
||||
info := admin_nodeInfo{
|
||||
{"IP", net.IP(sinfo.theirAddr[:]).String()},
|
||||
{"coords", fmt.Sprint(sinfo.coords)},
|
||||
{"MTU", fmt.Sprint(sinfo.getMTU())},
|
||||
}
|
||||
infos = append(infos, info)
|
||||
}
|
||||
|
@ -145,6 +145,10 @@ func (r *router) sendPacket(bs []byte) {
|
||||
fallthrough
|
||||
//default: go func() { sinfo.send<-bs }()
|
||||
default:
|
||||
if len(bs) > int(sinfo.getMTU()) {
|
||||
// TODO: Send ICMPv6 Packet Too Big back to the TUN/TAP adapter
|
||||
sinfo.core.log.Printf("Packet length %d exceeds session MTU %d", len(bs), sinfo.getMTU())
|
||||
}
|
||||
select {
|
||||
case sinfo.send <- bs:
|
||||
default:
|
||||
|
@ -19,6 +19,8 @@ type sessionInfo struct {
|
||||
myHandle handle
|
||||
theirNonce boxNonce
|
||||
myNonce boxNonce
|
||||
theirMTU uint16
|
||||
myMTU uint16
|
||||
time time.Time // Time we last received a packet
|
||||
coords []byte // coords of destination
|
||||
packet []byte // a buffered packet, sent immediately on ping/pong
|
||||
@ -36,6 +38,7 @@ type sessionPing struct {
|
||||
coords []byte
|
||||
tstamp int64 // unix time, but the only real requirement is that it increases
|
||||
isPong bool
|
||||
mtu uint16
|
||||
}
|
||||
|
||||
// Returns true if the session was updated, false otherwise
|
||||
@ -56,6 +59,9 @@ func (s *sessionInfo) update(p *sessionPing) bool {
|
||||
s.theirNonce = boxNonce{}
|
||||
s.nonceMask = 0
|
||||
}
|
||||
if p.mtu >= 1280 {
|
||||
s.theirMTU = p.mtu
|
||||
}
|
||||
s.coords = append([]byte{}, p.coords...)
|
||||
s.time = time.Now()
|
||||
s.tstamp = p.tstamp
|
||||
@ -144,6 +150,8 @@ func (ss *sessions) createSession(theirPermKey *boxPubKey) *sessionInfo {
|
||||
sinfo.mySesPub = *pub
|
||||
sinfo.mySesPriv = *priv
|
||||
sinfo.myNonce = *newBoxNonce()
|
||||
sinfo.theirMTU = 1280
|
||||
sinfo.myMTU = uint16(ss.core.tun.mtu)
|
||||
higher := false
|
||||
for idx := range ss.core.boxPub {
|
||||
if ss.core.boxPub[idx] > sinfo.theirPermPub[idx] {
|
||||
@ -201,6 +209,7 @@ func (ss *sessions) getPing(sinfo *sessionInfo) sessionPing {
|
||||
sendSesPub: sinfo.mySesPub,
|
||||
tstamp: time.Now().Unix(),
|
||||
coords: coords,
|
||||
mtu: sinfo.myMTU,
|
||||
}
|
||||
sinfo.myNonce.update()
|
||||
return ref
|
||||
@ -289,6 +298,13 @@ func (n *boxNonce) minus(m *boxNonce) int64 {
|
||||
return diff
|
||||
}
|
||||
|
||||
func (sinfo *sessionInfo) getMTU() uint16 {
|
||||
if sinfo.theirMTU < sinfo.myMTU {
|
||||
return sinfo.theirMTU
|
||||
}
|
||||
return sinfo.myMTU
|
||||
}
|
||||
|
||||
func (sinfo *sessionInfo) nonceIsOK(theirNonce *boxNonce) bool {
|
||||
// The bitmask is to allow for some non-duplicate out-of-order packets
|
||||
diff := theirNonce.minus(&sinfo.theirNonce)
|
||||
|
@ -429,12 +429,14 @@ func (p *sessionPing) encode() []byte {
|
||||
bs = append(bs, wire_encode_uint64(wire_intToUint(p.tstamp))...)
|
||||
coords := wire_encode_coords(p.coords)
|
||||
bs = append(bs, coords...)
|
||||
bs = append(bs, wire_encode_uint64(uint64(p.mtu))...)
|
||||
return bs
|
||||
}
|
||||
|
||||
func (p *sessionPing) decode(bs []byte) bool {
|
||||
var pType uint64
|
||||
var tstamp uint64
|
||||
var mtu uint64
|
||||
switch {
|
||||
case !wire_chop_uint64(&pType, &bs):
|
||||
return false
|
||||
@ -449,11 +451,14 @@ func (p *sessionPing) decode(bs []byte) bool {
|
||||
return false
|
||||
case !wire_chop_coords(&p.coords, &bs):
|
||||
return false
|
||||
case !wire_chop_uint64(&mtu, &bs):
|
||||
mtu = 1280
|
||||
}
|
||||
p.tstamp = wire_intFromUint(tstamp)
|
||||
if pType == wire_SessionPong {
|
||||
p.isPong = true
|
||||
}
|
||||
p.mtu = uint16(mtu)
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ type nodeConfig struct {
|
||||
LinkLocal string
|
||||
IfName string
|
||||
IfTAPMode bool
|
||||
IfMTU int
|
||||
}
|
||||
|
||||
type node struct {
|
||||
@ -114,6 +115,7 @@ func generateConfig() *nodeConfig {
|
||||
cfg.Multicast = true
|
||||
cfg.LinkLocal = ""
|
||||
cfg.IfName = "auto"
|
||||
cfg.IfMTU = 65535
|
||||
if runtime.GOOS == "windows" {
|
||||
cfg.IfTAPMode = true
|
||||
} else {
|
||||
@ -264,7 +266,7 @@ func main() {
|
||||
n.init(cfg, logger)
|
||||
logger.Println("Starting tun...")
|
||||
//n.core.DEBUG_startTun(cfg.IfName) // 1280, the smallest supported MTU
|
||||
n.core.DEBUG_startTunWithMTU(cfg.IfName, cfg.IfTAPMode, 65535) // Largest supported MTU
|
||||
n.core.DEBUG_startTunWithMTU(cfg.IfName, cfg.IfTAPMode, cfg.IfMTU) // Largest supported MTU
|
||||
defer func() {
|
||||
logger.Println("Closing...")
|
||||
n.core.DEBUG_stopTun()
|
||||
|
Loading…
Reference in New Issue
Block a user