mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 08:20:28 +00:00
Use uint64 for MTU for forward-compatibility
This commit is contained in:
parent
2d01386d6e
commit
416eadbcff
@ -250,7 +250,6 @@ func (a *AdminSocket) handleRequest(conn net.Conn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
j, _ := json.Marshal(resp)
|
|
||||||
if err = encoder.Encode(resp); err != nil {
|
if err = encoder.Encode(resp); err != nil {
|
||||||
a.log.Debugln("Encode error:", err)
|
a.log.Debugln("Encode error:", err)
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ type NodeConfig struct {
|
|||||||
PrivateKey string `comment:"Your private signing key. DO NOT share this with anyone!"`
|
PrivateKey string `comment:"Your private signing key. DO NOT share this with anyone!"`
|
||||||
LinkLocalTCPPort uint16 `comment:"The port number to be used for the link-local TCP listeners for the\nconfigured MulticastInterfaces. This option does not affect listeners\nspecified in the Listen option. Unless you plan to firewall link-local\ntraffic, it is best to leave this as the default value of 0. This\noption cannot currently be changed by reloading config during runtime."`
|
LinkLocalTCPPort uint16 `comment:"The port number to be used for the link-local TCP listeners for the\nconfigured MulticastInterfaces. This option does not affect listeners\nspecified in the Listen option. Unless you plan to firewall link-local\ntraffic, it is best to leave this as the default value of 0. This\noption cannot currently be changed by reloading config during runtime."`
|
||||||
IfName string `comment:"Local network interface name for TUN adapter, or \"auto\" to select\nan interface automatically, or \"none\" to run without TUN."`
|
IfName string `comment:"Local network interface name for TUN adapter, or \"auto\" to select\nan interface automatically, or \"none\" to run without TUN."`
|
||||||
IfMTU uint16 `comment:"Maximum Transmission Unit (MTU) size for your local TUN interface.\nDefault is the largest supported size for your platform. The lowest\npossible value is 1280."`
|
IfMTU uint64 `comment:"Maximum Transmission Unit (MTU) size for your local TUN interface.\nDefault is the largest supported size for your platform. The lowest\npossible value is 1280."`
|
||||||
SessionFirewall SessionFirewall `comment:"The session firewall controls who can send/receive network traffic\nto/from. This is useful if you want to protect this node without\nresorting to using a real firewall. This does not affect traffic\nbeing routed via this node to somewhere else. Rules are prioritised as\nfollows: blacklist, whitelist, always allow outgoing, direct, remote."`
|
SessionFirewall SessionFirewall `comment:"The session firewall controls who can send/receive network traffic\nto/from. This is useful if you want to protect this node without\nresorting to using a real firewall. This does not affect traffic\nbeing routed via this node to somewhere else. Rules are prioritised as\nfollows: blacklist, whitelist, always allow outgoing, direct, remote."`
|
||||||
NodeInfoPrivacy bool `comment:"By default, nodeinfo contains some defaults including the platform,\narchitecture and Yggdrasil version. These can help when surveying\nthe network and diagnosing network routing problems. Enabling\nnodeinfo privacy prevents this, so that only items specified in\n\"NodeInfo\" are sent back if specified."`
|
NodeInfoPrivacy bool `comment:"By default, nodeinfo contains some defaults including the platform,\narchitecture and Yggdrasil version. These can help when surveying\nthe network and diagnosing network routing problems. Enabling\nnodeinfo privacy prevents this, so that only items specified in\n\"NodeInfo\" are sent back if specified."`
|
||||||
NodeInfo map[string]interface{} `comment:"Optional node info. This must be a { \"key\": \"value\", ... } map\nor set as null. This is entirely optional but, if set, is visible\nto the whole network on request."`
|
NodeInfo map[string]interface{} `comment:"Optional node info. This must be a { \"key\": \"value\", ... } map\nor set as null. This is entirely optional but, if set, is visible\nto the whole network on request."`
|
||||||
|
@ -14,7 +14,7 @@ type platformDefaultParameters struct {
|
|||||||
DefaultMulticastInterfaces []string
|
DefaultMulticastInterfaces []string
|
||||||
|
|
||||||
// TUN/TAP
|
// TUN/TAP
|
||||||
MaximumIfMTU uint16
|
MaximumIfMTU uint64
|
||||||
DefaultIfMTU uint16
|
DefaultIfMTU uint64
|
||||||
DefaultIfName string
|
DefaultIfName string
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type GetTUNRequest struct{}
|
type GetTUNRequest struct{}
|
||||||
type GetTUNResponse map[string]uint16
|
type GetTUNResponse map[string]uint64
|
||||||
|
|
||||||
func (t *TunAdapter) getTUNHandler(req *GetTUNRequest, res *GetTUNResponse) error {
|
func (t *TunAdapter) getTUNHandler(req *GetTUNRequest, res *GetTUNResponse) error {
|
||||||
res = &GetTUNResponse{
|
res = &GetTUNResponse{
|
||||||
|
@ -39,7 +39,7 @@ type TunAdapter struct {
|
|||||||
log *log.Logger
|
log *log.Logger
|
||||||
addr address.Address
|
addr address.Address
|
||||||
subnet address.Subnet
|
subnet address.Subnet
|
||||||
mtu uint16
|
mtu uint64
|
||||||
iface tun.Device
|
iface tun.Device
|
||||||
phony.Inbox // Currently only used for _handlePacket from the reader, TODO: all the stuff that currently needs a mutex below
|
phony.Inbox // Currently only used for _handlePacket from the reader, TODO: all the stuff that currently needs a mutex below
|
||||||
//mutex sync.RWMutex // Protects the below
|
//mutex sync.RWMutex // Protects the below
|
||||||
@ -55,7 +55,7 @@ func (tun *TunAdapter) SetSessionGatekeeper(gatekeeper func(pubkey ed25519.Publi
|
|||||||
|
|
||||||
// Gets the maximum supported MTU for the platform based on the defaults in
|
// Gets the maximum supported MTU for the platform based on the defaults in
|
||||||
// defaults.GetDefaults().
|
// defaults.GetDefaults().
|
||||||
func getSupportedMTU(mtu uint16) uint16 {
|
func getSupportedMTU(mtu uint64) uint64 {
|
||||||
if mtu < 1280 {
|
if mtu < 1280 {
|
||||||
return 1280
|
return 1280
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ func (tun *TunAdapter) Name() string {
|
|||||||
// MTU gets the adapter's MTU. This can range between 1280 and 65535, although
|
// MTU gets the adapter's MTU. This can range between 1280 and 65535, although
|
||||||
// the maximum value is determined by your platform. The returned value will
|
// the maximum value is determined by your platform. The returned value will
|
||||||
// never exceed that of MaximumMTU().
|
// never exceed that of MaximumMTU().
|
||||||
func (tun *TunAdapter) MTU() uint16 {
|
func (tun *TunAdapter) MTU() uint64 {
|
||||||
return getSupportedMTU(tun.mtu)
|
return getSupportedMTU(tun.mtu)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,14 +88,14 @@ func DefaultName() string {
|
|||||||
|
|
||||||
// DefaultMTU gets the default TUN interface MTU for your platform. This can
|
// DefaultMTU gets the default TUN interface MTU for your platform. This can
|
||||||
// be as high as MaximumMTU(), depending on platform, but is never lower than 1280.
|
// be as high as MaximumMTU(), depending on platform, but is never lower than 1280.
|
||||||
func DefaultMTU() uint16 {
|
func DefaultMTU() uint64 {
|
||||||
return defaults.GetDefaults().DefaultIfMTU
|
return defaults.GetDefaults().DefaultIfMTU
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaximumMTU returns the maximum supported TUN interface MTU for your
|
// MaximumMTU returns the maximum supported TUN interface MTU for your
|
||||||
// platform. This can be as high as 65535, depending on platform, but is never
|
// platform. This can be as high as 65535, depending on platform, but is never
|
||||||
// lower than 1280.
|
// lower than 1280.
|
||||||
func MaximumMTU() uint16 {
|
func MaximumMTU() uint64 {
|
||||||
return defaults.GetDefaults().MaximumIfMTU
|
return defaults.GetDefaults().MaximumIfMTU
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ func (tun *TunAdapter) _start() error {
|
|||||||
}
|
}
|
||||||
mtu := current.IfMTU
|
mtu := current.IfMTU
|
||||||
if tun.core.MTU() < uint64(mtu) {
|
if tun.core.MTU() < uint64(mtu) {
|
||||||
mtu = uint16(tun.core.MTU())
|
mtu = tun.core.MTU()
|
||||||
}
|
}
|
||||||
if err := tun.setup(current.IfName, addr, mtu); err != nil {
|
if err := tun.setup(current.IfName, addr, mtu); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -73,14 +73,14 @@ type in6_ifreq_lifetime struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Configures the TUN adapter with the correct IPv6 address and MTU.
|
// Configures the TUN adapter with the correct IPv6 address and MTU.
|
||||||
func (tun *TunAdapter) setup(ifname string, addr string, mtu MTU) error {
|
func (tun *TunAdapter) setup(ifname string, addr string, mtu uint64) error {
|
||||||
iface, err := wgtun.CreateTUN(ifname, int(mtu))
|
iface, err := wgtun.CreateTUN(ifname, int(mtu))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
if mtu, err := iface.MTU(); err == nil {
|
if mtu, err := iface.MTU(); err == nil {
|
||||||
tun.mtu = getSupportedMTU(MTU(mtu))
|
tun.mtu = getSupportedMTU(uint64(mtu))
|
||||||
} else {
|
} else {
|
||||||
tun.mtu = 0
|
tun.mtu = 0
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Configures the "utun" adapter with the correct IPv6 address and MTU.
|
// Configures the "utun" adapter with the correct IPv6 address and MTU.
|
||||||
func (tun *TunAdapter) setup(ifname string, addr string, mtu uint16) error {
|
func (tun *TunAdapter) setup(ifname string, addr string, mtu uint64) error {
|
||||||
if ifname == "auto" {
|
if ifname == "auto" {
|
||||||
ifname = "utun"
|
ifname = "utun"
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ func (tun *TunAdapter) setup(ifname string, addr string, mtu uint16) error {
|
|||||||
}
|
}
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
if m, err := iface.MTU(); err == nil {
|
if m, err := iface.MTU(); err == nil {
|
||||||
tun.mtu = getSupportedMTU(uint16(m))
|
tun.mtu = getSupportedMTU(uint64(m))
|
||||||
} else {
|
} else {
|
||||||
tun.mtu = 0
|
tun.mtu = 0
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Configures the TUN adapter with the correct IPv6 address and MTU.
|
// Configures the TUN adapter with the correct IPv6 address and MTU.
|
||||||
func (tun *TunAdapter) setup(ifname string, addr string, mtu MTU) error {
|
func (tun *TunAdapter) setup(ifname string, addr string, mtu uint64) error {
|
||||||
if ifname == "auto" {
|
if ifname == "auto" {
|
||||||
ifname = "\000"
|
ifname = "\000"
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@ func (tun *TunAdapter) setup(ifname string, addr string, mtu MTU) error {
|
|||||||
}
|
}
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
if mtu, err := iface.MTU(); err == nil {
|
if mtu, err := iface.MTU(); err == nil {
|
||||||
tun.mtu = getSupportedMTU(MTU(mtu))
|
tun.mtu = getSupportedMTU(uint64(mtu))
|
||||||
} else {
|
} else {
|
||||||
tun.mtu = 0
|
tun.mtu = 0
|
||||||
}
|
}
|
||||||
|
@ -10,14 +10,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Configures the TUN adapter with the correct IPv6 address and MTU.
|
// Configures the TUN adapter with the correct IPv6 address and MTU.
|
||||||
func (tun *TunAdapter) setup(ifname string, addr string, mtu int) error {
|
func (tun *TunAdapter) setup(ifname string, addr string, mtu uint64) error {
|
||||||
iface, err := wgtun.CreateTUN(ifname, mtu)
|
iface, err := wgtun.CreateTUN(ifname, mtu)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
if mtu, err := iface.MTU(); err == nil {
|
if mtu, err := iface.MTU(); err == nil {
|
||||||
tun.mtu = getSupportedMTU(mtu)
|
tun.mtu = getSupportedMTU(uint64(mtu))
|
||||||
} else {
|
} else {
|
||||||
tun.mtu = 0
|
tun.mtu = 0
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
// This is to catch Windows platforms
|
// This is to catch Windows platforms
|
||||||
|
|
||||||
// Configures the TUN adapter with the correct IPv6 address and MTU.
|
// Configures the TUN adapter with the correct IPv6 address and MTU.
|
||||||
func (tun *TunAdapter) setup(ifname string, addr string, mtu MTU) error {
|
func (tun *TunAdapter) setup(ifname string, addr string, mtu uint64) error {
|
||||||
if ifname == "auto" {
|
if ifname == "auto" {
|
||||||
ifname = defaults.GetDefaults().DefaultIfName
|
ifname = defaults.GetDefaults().DefaultIfName
|
||||||
}
|
}
|
||||||
@ -43,14 +43,14 @@ func (tun *TunAdapter) setup(ifname string, addr string, mtu MTU) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if mtu, err := iface.MTU(); err == nil {
|
if mtu, err := iface.MTU(); err == nil {
|
||||||
tun.mtu = MTU(mtu)
|
tun.mtu = uint64(mtu)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the MTU of the TAP adapter.
|
// Sets the MTU of the TAP adapter.
|
||||||
func (tun *TunAdapter) setupMTU(mtu MTU) error {
|
func (tun *TunAdapter) setupMTU(mtu uint64) error {
|
||||||
if tun.iface == nil || tun.Name() == "" {
|
if tun.iface == nil || tun.Name() == "" {
|
||||||
return errors.New("Can't configure MTU as TUN adapter is not present")
|
return errors.New("Can't configure MTU as TUN adapter is not present")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user