mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-27 12:05:23 +00:00
Merge pull request #12 from neilalexander/iftapmode
Add configuration option for TAP mode
This commit is contained in:
commit
38567fffef
@ -205,14 +205,14 @@ func (c *Core) DEBUG_getAddr() *address {
|
|||||||
return address_addrForNodeID(&c.dht.nodeID)
|
return address_addrForNodeID(&c.dht.nodeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Core) DEBUG_startTun(ifname string) {
|
func (c *Core) DEBUG_startTun(ifname string, iftapmode bool) {
|
||||||
c.DEBUG_startTunWithMTU(ifname, 1280)
|
c.DEBUG_startTunWithMTU(ifname, iftapmode, 1280)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Core) DEBUG_startTunWithMTU(ifname string, mtu int) {
|
func (c *Core) DEBUG_startTunWithMTU(ifname string, iftapmode bool, mtu int) {
|
||||||
addr := c.DEBUG_getAddr()
|
addr := c.DEBUG_getAddr()
|
||||||
straddr := fmt.Sprintf("%s/%v", net.IP(addr[:]).String(), 8*len(address_prefix))
|
straddr := fmt.Sprintf("%s/%v", net.IP(addr[:]).String(), 8*len(address_prefix))
|
||||||
err := c.tun.setup(ifname, straddr, mtu)
|
err := c.tun.setup(ifname, iftapmode, straddr, mtu)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,10 @@ import "golang.org/x/sys/unix"
|
|||||||
|
|
||||||
import water "github.com/songgao/water"
|
import water "github.com/songgao/water"
|
||||||
|
|
||||||
func (tun *tunDevice) setup(ifname string, addr string, mtu int) error {
|
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")
|
||||||
|
}
|
||||||
config := water.Config{DeviceType: water.TUN}
|
config := water.Config{DeviceType: water.TUN}
|
||||||
iface, err := water.New(config)
|
iface, err := water.New(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -9,8 +9,13 @@ import "strings"
|
|||||||
|
|
||||||
import water "github.com/songgao/water"
|
import water "github.com/songgao/water"
|
||||||
|
|
||||||
func (tun *tunDevice) setup(ifname string, addr string, mtu int) error {
|
func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int) error {
|
||||||
config := water.Config{DeviceType: water.TUN}
|
var config water.Config
|
||||||
|
if iftapmode {
|
||||||
|
config = water.Config{DeviceType: water.TAP}
|
||||||
|
} else {
|
||||||
|
config = water.Config{DeviceType: water.TUN}
|
||||||
|
}
|
||||||
if ifname != "" && ifname != "auto" {
|
if ifname != "" && ifname != "auto" {
|
||||||
config.Name = ifname
|
config.Name = ifname
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,13 @@ import water "github.com/songgao/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 (tun *tunDevice) setup(ifname string, addr string, mtu int) error {
|
func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int) error {
|
||||||
config := water.Config{DeviceType: water.TUN}
|
var config water.Config
|
||||||
|
if iftapmode {
|
||||||
|
config = water.Config{DeviceType: water.TAP}
|
||||||
|
} else {
|
||||||
|
config = water.Config{DeviceType: water.TUN}
|
||||||
|
}
|
||||||
iface, err := water.New(config)
|
iface, err := water.New(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -7,7 +7,10 @@ import "fmt"
|
|||||||
|
|
||||||
// This is to catch Windows platforms
|
// This is to catch Windows platforms
|
||||||
|
|
||||||
func (tun *tunDevice) setup(ifname string, addr string, mtu int) error {
|
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")
|
||||||
|
}
|
||||||
config := water.Config{DeviceType: water.TAP}
|
config := water.Config{DeviceType: water.TAP}
|
||||||
config.PlatformSpecificParams.ComponentID = "tap0901"
|
config.PlatformSpecificParams.ComponentID = "tap0901"
|
||||||
config.PlatformSpecificParams.Network = "169.254.0.1/32"
|
config.PlatformSpecificParams.Network = "169.254.0.1/32"
|
||||||
|
10
yggdrasil.go
10
yggdrasil.go
@ -39,6 +39,7 @@ type nodeConfig struct {
|
|||||||
Multicast bool
|
Multicast bool
|
||||||
LinkLocal string
|
LinkLocal string
|
||||||
IfName string
|
IfName string
|
||||||
|
IfTAPMode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type node struct {
|
type node struct {
|
||||||
@ -104,7 +105,7 @@ func generateConfig() *nodeConfig {
|
|||||||
spub, spriv := core.DEBUG_newSigKeys()
|
spub, spriv := core.DEBUG_newSigKeys()
|
||||||
cfg := nodeConfig{}
|
cfg := nodeConfig{}
|
||||||
cfg.Listen = "[::]:0"
|
cfg.Listen = "[::]:0"
|
||||||
cfg.AdminListen = "localhost:9001"
|
cfg.AdminListen = "[::1]:9001"
|
||||||
cfg.BoxPub = hex.EncodeToString(bpub[:])
|
cfg.BoxPub = hex.EncodeToString(bpub[:])
|
||||||
cfg.BoxPriv = hex.EncodeToString(bpriv[:])
|
cfg.BoxPriv = hex.EncodeToString(bpriv[:])
|
||||||
cfg.SigPub = hex.EncodeToString(spub[:])
|
cfg.SigPub = hex.EncodeToString(spub[:])
|
||||||
@ -113,6 +114,11 @@ func generateConfig() *nodeConfig {
|
|||||||
cfg.Multicast = true
|
cfg.Multicast = true
|
||||||
cfg.LinkLocal = ""
|
cfg.LinkLocal = ""
|
||||||
cfg.IfName = "auto"
|
cfg.IfName = "auto"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
cfg.IfTAPMode = true
|
||||||
|
} else {
|
||||||
|
cfg.IfTAPMode = false
|
||||||
|
}
|
||||||
return &cfg
|
return &cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +264,7 @@ func main() {
|
|||||||
n.init(cfg, logger)
|
n.init(cfg, logger)
|
||||||
logger.Println("Starting tun...")
|
logger.Println("Starting tun...")
|
||||||
//n.core.DEBUG_startTun(cfg.IfName) // 1280, the smallest supported MTU
|
//n.core.DEBUG_startTun(cfg.IfName) // 1280, the smallest supported MTU
|
||||||
n.core.DEBUG_startTunWithMTU(cfg.IfName, 65535) // Largest supported MTU
|
n.core.DEBUG_startTunWithMTU(cfg.IfName, cfg.IfTAPMode, 65535) // Largest supported MTU
|
||||||
defer func() {
|
defer func() {
|
||||||
logger.Println("Closing...")
|
logger.Println("Closing...")
|
||||||
n.core.DEBUG_stopTun()
|
n.core.DEBUG_stopTun()
|
||||||
|
Loading…
Reference in New Issue
Block a user