mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 04:51:38 +00:00
Don't allow exceeding maximum MTU for a given platform
This commit is contained in:
parent
7c0102e43d
commit
bec898a326
@ -27,6 +27,17 @@ type tunDevice struct {
|
||||
iface tunInterface
|
||||
}
|
||||
|
||||
type tunDefaultParameters struct {
|
||||
maxMTU int
|
||||
}
|
||||
|
||||
func getMTUFromMax(mtu int) int {
|
||||
if mtu > defaultTUNParameters().maxMTU {
|
||||
return defaultTUNParameters().maxMTU
|
||||
}
|
||||
return mtu
|
||||
}
|
||||
|
||||
func (tun *tunDevice) init(core *Core) {
|
||||
tun.core = core
|
||||
tun.icmpv6.init(tun)
|
||||
|
@ -10,6 +10,12 @@ import "golang.org/x/sys/unix"
|
||||
|
||||
import water "github.com/neilalexander/water"
|
||||
|
||||
func defaultTUNParameters() tunDefaultParameters {
|
||||
return tunDefaultParameters{
|
||||
maxMTU: 65535,
|
||||
}
|
||||
}
|
||||
|
||||
func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int) error {
|
||||
if iftapmode {
|
||||
tun.core.log.Printf("TAP mode is not supported on this platform, defaulting to TUN")
|
||||
@ -20,7 +26,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
|
||||
panic(err)
|
||||
}
|
||||
tun.iface = iface
|
||||
tun.mtu = mtu
|
||||
tun.mtu = getMTUFromMax(mtu)
|
||||
return tun.setupAddress(addr)
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,12 @@ import "strings"
|
||||
|
||||
import water "github.com/neilalexander/water"
|
||||
|
||||
func defaultTUNParameters() tunDefaultParameters {
|
||||
return tunDefaultParameters{
|
||||
maxMTU: 65535,
|
||||
}
|
||||
}
|
||||
|
||||
func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int) error {
|
||||
var config water.Config
|
||||
if iftapmode {
|
||||
@ -24,7 +30,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
|
||||
panic(err)
|
||||
}
|
||||
tun.iface = iface
|
||||
tun.mtu = mtu //1280 // Lets default to the smallest thing allowed for now
|
||||
tun.mtu = getMTUFromMax(mtu)
|
||||
return tun.setupAddress(addr)
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,12 @@ import water "github.com/neilalexander/water"
|
||||
// to disable the PI header when in TUN mode, so we need to modify the read/
|
||||
// writes to handle those first four bytes
|
||||
|
||||
func defaultTUNParameters() tunDefaultParameters {
|
||||
return tunDefaultParameters{
|
||||
maxMTU: 16384,
|
||||
}
|
||||
}
|
||||
|
||||
// Warning! When porting this to other BSDs, the tuninfo struct can appear with
|
||||
// the fields in a different order, and the consts below might also have
|
||||
// different values
|
||||
@ -80,7 +86,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
|
||||
panic(err)
|
||||
}
|
||||
tun.iface = iface
|
||||
tun.mtu = mtu //1280 // Lets default to the smallest thing allowed for now
|
||||
tun.mtu = getMTUFromMax(mtu)
|
||||
return tun.setupAddress(addr)
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,12 @@ import water "github.com/neilalexander/water"
|
||||
// This is to catch unsupported platforms
|
||||
// If your platform supports tun devices, you could try configuring it manually
|
||||
|
||||
func defaultTUNParameters() tunDefaultParameters {
|
||||
return tunDefaultParameters{
|
||||
maxMTU: 65535,
|
||||
}
|
||||
}
|
||||
|
||||
func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int) error {
|
||||
var config water.Config
|
||||
if iftapmode {
|
||||
@ -19,7 +25,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
|
||||
panic(err)
|
||||
}
|
||||
tun.iface = iface
|
||||
tun.mtu = mtu //1280 // Lets default to the smallest thing allowed for now
|
||||
tun.mtu = getMTUFromMax(mtu)
|
||||
return tun.setupAddress(addr)
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,12 @@ import "fmt"
|
||||
|
||||
// This is to catch Windows platforms
|
||||
|
||||
func defaultTUNParameters() tunDefaultParameters {
|
||||
return tunDefaultParameters{
|
||||
maxMTU: 65535,
|
||||
}
|
||||
}
|
||||
|
||||
func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int) error {
|
||||
if !iftapmode {
|
||||
tun.core.log.Printf("TUN mode is not supported on this platform, defaulting to TAP")
|
||||
@ -41,7 +47,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
|
||||
panic(err)
|
||||
}
|
||||
tun.iface = iface
|
||||
tun.mtu = mtu
|
||||
tun.mtu = getMTUFromMax(mtu)
|
||||
err = tun.setupMTU(tun.mtu)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Loading…
Reference in New Issue
Block a user