mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-23 12:15:39 +00:00
Accept exchanging an MTU of 0 to signify that TUN/TAP is disabled, don't send traffic to a node in that case
This commit is contained in:
parent
ec371af84f
commit
ca96bbf014
@ -280,6 +280,17 @@ func (a *admin) startTunWithMTU(ifname string, iftapmode bool, ifmtu int) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// If we have open sessions then we need to notify them
|
||||
// that our MTU has now changed
|
||||
for _, sinfo := range a.core.sessions.sinfos {
|
||||
if ifname == "none" {
|
||||
sinfo.myMTU = 0
|
||||
} else {
|
||||
sinfo.myMTU = uint16(ifmtu)
|
||||
}
|
||||
a.core.sessions.sendPingPong(sinfo, false)
|
||||
}
|
||||
// Aaaaand... go!
|
||||
go a.core.tun.read()
|
||||
}
|
||||
go a.core.tun.write()
|
||||
|
@ -164,6 +164,31 @@ func (r *router) sendPacket(bs []byte) {
|
||||
}
|
||||
fallthrough // Also send the packet
|
||||
default:
|
||||
// Drop packets if the session MTU is 0 - this means that one or other
|
||||
// side probably has their TUN adapter disabled
|
||||
if sinfo.getMTU() == 0 {
|
||||
// Get the size of the oversized payload, up to a max of 900 bytes
|
||||
window := 900
|
||||
if len(bs) < window {
|
||||
window = len(bs)
|
||||
}
|
||||
|
||||
// Create the Destination Unreachable response
|
||||
ptb := &icmp.DstUnreach{
|
||||
Data: bs[:window],
|
||||
}
|
||||
|
||||
// Create the ICMPv6 response from it
|
||||
icmpv6Buf, err := r.core.tun.icmpv6.create_icmpv6_tun(
|
||||
bs[8:24], bs[24:40],
|
||||
ipv6.ICMPTypeDestinationUnreachable, 1, ptb)
|
||||
if err == nil {
|
||||
r.recv <- icmpv6Buf
|
||||
}
|
||||
|
||||
// Don't continue - drop the packet
|
||||
return
|
||||
}
|
||||
// Generate an ICMPv6 Packet Too Big for packets larger than session MTU
|
||||
if len(bs) > int(sinfo.getMTU()) {
|
||||
// Get the size of the oversized payload, up to a max of 900 bytes
|
||||
|
@ -65,7 +65,7 @@ func (s *sessionInfo) update(p *sessionPing) bool {
|
||||
s.theirNonce = boxNonce{}
|
||||
s.nonceMask = 0
|
||||
}
|
||||
if p.mtu >= 1280 {
|
||||
if p.mtu >= 1280 || p.mtu == 0 {
|
||||
s.theirMTU = p.mtu
|
||||
}
|
||||
s.coords = append([]byte{}, p.coords...)
|
||||
@ -313,6 +313,9 @@ func (n *boxNonce) minus(m *boxNonce) int64 {
|
||||
}
|
||||
|
||||
func (sinfo *sessionInfo) getMTU() uint16 {
|
||||
if sinfo.theirMTU == 0 || sinfo.myMTU == 0 {
|
||||
return 0
|
||||
}
|
||||
if sinfo.theirMTU < sinfo.myMTU {
|
||||
return sinfo.theirMTU
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user