mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-27 12:05:23 +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
|
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
|
// udpInterface
|
||||||
// FIXME udpInterface isn't exported
|
// FIXME udpInterface isn't exported
|
||||||
// So debug functions need to work differently...
|
// So debug functions need to work differently...
|
||||||
|
@ -5,6 +5,8 @@ package yggdrasil
|
|||||||
import "os"
|
import "os"
|
||||||
import ethernet "github.com/songgao/packets/ethernet"
|
import ethernet "github.com/songgao/packets/ethernet"
|
||||||
|
|
||||||
|
const DEFAULT_MTU = 65535
|
||||||
|
|
||||||
const IPv6_HEADER_LENGTH = 40
|
const IPv6_HEADER_LENGTH = 40
|
||||||
const ETHER_HEADER_LENGTH = 14
|
const ETHER_HEADER_LENGTH = 14
|
||||||
|
|
||||||
@ -28,12 +30,15 @@ type tunDevice struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type tunDefaultParameters struct {
|
type tunDefaultParameters struct {
|
||||||
maxMTU int
|
maximumIfMTU int
|
||||||
|
defaultIfMTU int
|
||||||
|
defaultIfName string
|
||||||
|
defaultIfTAPMode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMTUFromMax(mtu int) int {
|
func getSupportedMTU(mtu int) int {
|
||||||
if mtu > defaultTUNParameters().maxMTU {
|
if mtu > getDefaults().maximumIfMTU {
|
||||||
return defaultTUNParameters().maxMTU
|
return getDefaults().maximumIfMTU
|
||||||
}
|
}
|
||||||
return mtu
|
return mtu
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,12 @@ import "golang.org/x/sys/unix"
|
|||||||
|
|
||||||
import water "github.com/neilalexander/water"
|
import water "github.com/neilalexander/water"
|
||||||
|
|
||||||
func defaultTUNParameters() tunDefaultParameters {
|
func getDefaults() tunDefaultParameters {
|
||||||
return 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)
|
panic(err)
|
||||||
}
|
}
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
tun.mtu = getMTUFromMax(mtu)
|
tun.mtu = getSupportedMTU(mtu)
|
||||||
return tun.setupAddress(addr)
|
return tun.setupAddress(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,9 +9,12 @@ import "strings"
|
|||||||
|
|
||||||
import water "github.com/neilalexander/water"
|
import water "github.com/neilalexander/water"
|
||||||
|
|
||||||
func defaultTUNParameters() tunDefaultParameters {
|
func getDefaults() tunDefaultParameters {
|
||||||
return 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)
|
panic(err)
|
||||||
}
|
}
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
tun.mtu = getMTUFromMax(mtu)
|
tun.mtu = getSupportedMTU(mtu)
|
||||||
return tun.setupAddress(addr)
|
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/
|
// to disable the PI header when in TUN mode, so we need to modify the read/
|
||||||
// writes to handle those first four bytes
|
// writes to handle those first four bytes
|
||||||
|
|
||||||
func defaultTUNParameters() tunDefaultParameters {
|
func getDefaults() tunDefaultParameters {
|
||||||
return 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)
|
panic(err)
|
||||||
}
|
}
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
tun.mtu = getMTUFromMax(mtu)
|
tun.mtu = getSupportedMTU(mtu)
|
||||||
return tun.setupAddress(addr)
|
return tun.setupAddress(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,12 @@ import water "github.com/neilalexander/water"
|
|||||||
// This is to catch unsupported platforms
|
// This is to catch unsupported platforms
|
||||||
// If your platform supports tun devices, you could try configuring it manually
|
// If your platform supports tun devices, you could try configuring it manually
|
||||||
|
|
||||||
func defaultTUNParameters() tunDefaultParameters {
|
func getDefaults() tunDefaultParameters {
|
||||||
return 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)
|
panic(err)
|
||||||
}
|
}
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
tun.mtu = getMTUFromMax(mtu)
|
tun.mtu = getSupportedMTU(mtu)
|
||||||
return tun.setupAddress(addr)
|
return tun.setupAddress(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,12 @@ import "fmt"
|
|||||||
|
|
||||||
// This is to catch Windows platforms
|
// This is to catch Windows platforms
|
||||||
|
|
||||||
func defaultTUNParameters() tunDefaultParameters {
|
func getDefaults() tunDefaultParameters {
|
||||||
return 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)
|
panic(err)
|
||||||
}
|
}
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
tun.mtu = getMTUFromMax(mtu)
|
tun.mtu = getSupportedMTU(mtu)
|
||||||
err = tun.setupMTU(tun.mtu)
|
err = tun.setupMTU(tun.mtu)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
10
yggdrasil.go
10
yggdrasil.go
@ -117,13 +117,9 @@ func generateConfig() *nodeConfig {
|
|||||||
cfg.Peers = []string{}
|
cfg.Peers = []string{}
|
||||||
cfg.Multicast = true
|
cfg.Multicast = true
|
||||||
cfg.LinkLocal = ""
|
cfg.LinkLocal = ""
|
||||||
cfg.IfName = "auto"
|
cfg.IfName = core.DEBUG_GetTUNDefaultIfName()
|
||||||
cfg.IfMTU = 1280
|
cfg.IfMTU = core.DEBUG_GetTUNDefaultIfMTU()
|
||||||
if runtime.GOOS == "windows" {
|
cfg.IfTAPMode = core.DEBUG_GetTUNDefaultIfTAPMode()
|
||||||
cfg.IfTAPMode = true
|
|
||||||
} else {
|
|
||||||
cfg.IfTAPMode = false
|
|
||||||
}
|
|
||||||
return &cfg
|
return &cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user