mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-22 19:55:39 +00:00
Per-platform TUN defaults
This commit is contained in:
parent
bec898a326
commit
4917ea3dd2
@ -159,6 +159,20 @@ func (c *Core) DEBUG_getDHTSize() int {
|
||||
return total
|
||||
}
|
||||
|
||||
// TUN defaults
|
||||
|
||||
func (c *Core) DEBUG_GetTUNDefaultIfName() string {
|
||||
return getDefaults().defaultIfName
|
||||
}
|
||||
|
||||
func (c *Core) DEBUG_GetTUNDefaultIfMTU() int {
|
||||
return getDefaults().defaultIfMTU
|
||||
}
|
||||
|
||||
func (c *Core) DEBUG_GetTUNDefaultIfTAPMode() bool {
|
||||
return getDefaults().defaultIfTAPMode
|
||||
}
|
||||
|
||||
// udpInterface
|
||||
// FIXME udpInterface isn't exported
|
||||
// So debug functions need to work differently...
|
||||
|
@ -5,6 +5,8 @@ package yggdrasil
|
||||
import "os"
|
||||
import ethernet "github.com/songgao/packets/ethernet"
|
||||
|
||||
const DEFAULT_MTU = 65535
|
||||
|
||||
const IPv6_HEADER_LENGTH = 40
|
||||
const ETHER_HEADER_LENGTH = 14
|
||||
|
||||
@ -28,12 +30,15 @@ type tunDevice struct {
|
||||
}
|
||||
|
||||
type tunDefaultParameters struct {
|
||||
maxMTU int
|
||||
maximumIfMTU int
|
||||
defaultIfMTU int
|
||||
defaultIfName string
|
||||
defaultIfTAPMode bool
|
||||
}
|
||||
|
||||
func getMTUFromMax(mtu int) int {
|
||||
if mtu > defaultTUNParameters().maxMTU {
|
||||
return defaultTUNParameters().maxMTU
|
||||
func getSupportedMTU(mtu int) int {
|
||||
if mtu > getDefaults().maximumIfMTU {
|
||||
return getDefaults().maximumIfMTU
|
||||
}
|
||||
return mtu
|
||||
}
|
||||
|
@ -10,9 +10,12 @@ import "golang.org/x/sys/unix"
|
||||
|
||||
import water "github.com/neilalexander/water"
|
||||
|
||||
func defaultTUNParameters() tunDefaultParameters {
|
||||
func getDefaults() tunDefaultParameters {
|
||||
return tunDefaultParameters{
|
||||
maxMTU: 65535,
|
||||
maximumIfMTU: 65535,
|
||||
defaultIfMTU: DEFAULT_MTU,
|
||||
defaultIfName: "auto",
|
||||
defaultIfTAPMode: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +29,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
|
||||
panic(err)
|
||||
}
|
||||
tun.iface = iface
|
||||
tun.mtu = getMTUFromMax(mtu)
|
||||
tun.mtu = getSupportedMTU(mtu)
|
||||
return tun.setupAddress(addr)
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,12 @@ import "strings"
|
||||
|
||||
import water "github.com/neilalexander/water"
|
||||
|
||||
func defaultTUNParameters() tunDefaultParameters {
|
||||
func getDefaults() tunDefaultParameters {
|
||||
return tunDefaultParameters{
|
||||
maxMTU: 65535,
|
||||
maximumIfMTU: 65535,
|
||||
defaultIfMTU: DEFAULT_MTU,
|
||||
defaultIfName: "auto",
|
||||
defaultIfTAPMode: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +33,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
|
||||
panic(err)
|
||||
}
|
||||
tun.iface = iface
|
||||
tun.mtu = getMTUFromMax(mtu)
|
||||
tun.mtu = getSupportedMTU(mtu)
|
||||
return tun.setupAddress(addr)
|
||||
}
|
||||
|
||||
|
@ -15,9 +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 {
|
||||
func getDefaults() tunDefaultParameters {
|
||||
return tunDefaultParameters{
|
||||
maxMTU: 16384,
|
||||
maximumIfMTU: 16384,
|
||||
defaultIfMTU: DEFAULT_MTU,
|
||||
defaultIfName: "/dev/tap0",
|
||||
defaultIfTAPMode: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,7 +89,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
|
||||
panic(err)
|
||||
}
|
||||
tun.iface = iface
|
||||
tun.mtu = getMTUFromMax(mtu)
|
||||
tun.mtu = getSupportedMTU(mtu)
|
||||
return tun.setupAddress(addr)
|
||||
}
|
||||
|
||||
|
@ -7,9 +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 {
|
||||
func getDefaults() tunDefaultParameters {
|
||||
return tunDefaultParameters{
|
||||
maxMTU: 65535,
|
||||
maximumIfMTU: 65535,
|
||||
defaultIfMTU: DEFAULT_MTU,
|
||||
defaultIfName: "none",
|
||||
defaultIfTAPMode: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +28,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
|
||||
panic(err)
|
||||
}
|
||||
tun.iface = iface
|
||||
tun.mtu = getMTUFromMax(mtu)
|
||||
tun.mtu = getSupportedMTU(mtu)
|
||||
return tun.setupAddress(addr)
|
||||
}
|
||||
|
||||
|
@ -7,9 +7,12 @@ import "fmt"
|
||||
|
||||
// This is to catch Windows platforms
|
||||
|
||||
func defaultTUNParameters() tunDefaultParameters {
|
||||
func getDefaults() tunDefaultParameters {
|
||||
return tunDefaultParameters{
|
||||
maxMTU: 65535,
|
||||
maximumIfMTU: 65535,
|
||||
defaultIfMTU: DEFAULT_MTU,
|
||||
defaultIfName: "auto",
|
||||
defaultIfTAPMode: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,7 +50,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
|
||||
panic(err)
|
||||
}
|
||||
tun.iface = iface
|
||||
tun.mtu = getMTUFromMax(mtu)
|
||||
tun.mtu = getSupportedMTU(mtu)
|
||||
err = tun.setupMTU(tun.mtu)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
10
yggdrasil.go
10
yggdrasil.go
@ -117,13 +117,9 @@ func generateConfig() *nodeConfig {
|
||||
cfg.Peers = []string{}
|
||||
cfg.Multicast = true
|
||||
cfg.LinkLocal = ""
|
||||
cfg.IfName = "auto"
|
||||
cfg.IfMTU = 1280
|
||||
if runtime.GOOS == "windows" {
|
||||
cfg.IfTAPMode = true
|
||||
} else {
|
||||
cfg.IfTAPMode = false
|
||||
}
|
||||
cfg.IfName = core.DEBUG_GetTUNDefaultIfName()
|
||||
cfg.IfMTU = core.DEBUG_GetTUNDefaultIfMTU()
|
||||
cfg.IfTAPMode = core.DEBUG_GetTUNDefaultIfTAPMode()
|
||||
return &cfg
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user