mirror of
https://github.com/yggdrasil-network/yggdrasil-go
synced 2024-11-10 15:30:34 +03:00
Fix couple of issues with MTU calculations
This commit is contained in:
parent
ec46b217da
commit
9fca3640f9
@ -170,22 +170,17 @@ func (tun *TunAdapter) _start() error {
|
|||||||
nodeID := crypto.GetNodeID(&boxPub)
|
nodeID := crypto.GetNodeID(&boxPub)
|
||||||
tun.addr = *address.AddrForNodeID(nodeID)
|
tun.addr = *address.AddrForNodeID(nodeID)
|
||||||
tun.subnet = *address.SubnetForNodeID(nodeID)
|
tun.subnet = *address.SubnetForNodeID(nodeID)
|
||||||
tun.mtu = current.IfMTU
|
|
||||||
ifname := current.IfName
|
|
||||||
iftapmode := current.IfTAPMode
|
|
||||||
addr := fmt.Sprintf("%s/%d", net.IP(tun.addr[:]).String(), 8*len(address.GetPrefix())-1)
|
addr := fmt.Sprintf("%s/%d", net.IP(tun.addr[:]).String(), 8*len(address.GetPrefix())-1)
|
||||||
if ifname != "none" {
|
if current.IfName == "none" || current.IfName == "dummy" {
|
||||||
if err := tun.setup(ifname, iftapmode, addr, tun.mtu); err != nil {
|
tun.log.Debugln("Not starting TUN/TAP as ifname is none or dummy")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err := tun.setup(current.IfName, current.IfTAPMode, addr, current.IfMTU); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if tun.MTU() != current.IfMTU {
|
if tun.MTU() != current.IfMTU {
|
||||||
tun.log.Warnf("Warning: Interface MTU %d automatically adjusted to %d (supported range is 1280-%d)", current.IfMTU, tun.MTU(), MaximumMTU(tun.IsTAP()))
|
tun.log.Warnf("Warning: Interface MTU %d automatically adjusted to %d (supported range is 1280-%d)", current.IfMTU, tun.MTU(), MaximumMTU(tun.IsTAP()))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if ifname == "none" || ifname == "dummy" {
|
|
||||||
tun.log.Debugln("Not starting TUN/TAP as ifname is none or dummy")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
tun.isOpen = true
|
tun.isOpen = true
|
||||||
go tun.handler()
|
go tun.handler()
|
||||||
tun.reader.Act(nil, tun.reader._read) // Start the reader
|
tun.reader.Act(nil, tun.reader._read) // Start the reader
|
||||||
|
@ -27,14 +27,6 @@ func (tun *TunAdapter) setup(ifname string, iftapmode bool, addr string, mtu int
|
|||||||
}
|
}
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
tun.mtu = getSupportedMTU(mtu, iftapmode)
|
tun.mtu = getSupportedMTU(mtu, iftapmode)
|
||||||
// The following check is specific to Linux, as the TAP driver only supports
|
|
||||||
// an MTU of 65535-14 to make room for the ethernet headers. This makes sure
|
|
||||||
// that the MTU gets rounded down to 65521 instead of causing a panic.
|
|
||||||
if iftapmode {
|
|
||||||
if tun.mtu > 65535-tun_ETHER_HEADER_LENGTH {
|
|
||||||
tun.mtu = 65535 - tun_ETHER_HEADER_LENGTH
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Friendly output
|
// Friendly output
|
||||||
tun.log.Infof("Interface name: %s", tun.iface.Name())
|
tun.log.Infof("Interface name: %s", tun.iface.Name())
|
||||||
tun.log.Infof("Interface IPv6: %s", addr)
|
tun.log.Infof("Interface IPv6: %s", addr)
|
||||||
|
Loading…
Reference in New Issue
Block a user