mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-23 10:05:17 +00:00
Add support for specifying tun device name
This commit is contained in:
parent
e5d526881d
commit
1c799b305d
@ -196,14 +196,14 @@ func (c *Core) DEBUG_getAddr() *address {
|
|||||||
return address_addrForNodeID(&c.dht.nodeID)
|
return address_addrForNodeID(&c.dht.nodeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Core) DEBUG_startTun() {
|
func (c *Core) DEBUG_startTun(ifname string) {
|
||||||
c.DEBUG_startTunWithMTU(1280)
|
c.DEBUG_startTunWithMTU(ifname, 1280)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Core) DEBUG_startTunWithMTU(mtu int) {
|
func (c *Core) DEBUG_startTunWithMTU(ifname string, 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(straddr, mtu)
|
err := c.tun.setup(ifname, straddr, mtu)
|
||||||
if err != nil { panic(err) }
|
if err != nil { panic(err) }
|
||||||
go c.tun.read()
|
go c.tun.read()
|
||||||
go c.tun.write()
|
go c.tun.write()
|
||||||
|
@ -18,8 +18,10 @@ func (tun *tunDevice) init(core *Core) {
|
|||||||
tun.core = core
|
tun.core = core
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tun *tunDevice) setup(addr string, mtu int) error {
|
func (tun *tunDevice) setup(ifname string, addr string, mtu int) error {
|
||||||
iface, err := water.New(water.Config{ DeviceType: water.TUN })
|
config := water.Config{ DeviceType: water.TUN }
|
||||||
|
if ifname != "" && ifname != "auto" { config.Name = ifname }
|
||||||
|
iface, err := water.New(config)
|
||||||
if err != nil { panic(err) }
|
if err != nil { panic(err) }
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
tun.mtu = mtu //1280 // Lets default to the smallest thing allowed for now
|
tun.mtu = mtu //1280 // Lets default to the smallest thing allowed for now
|
||||||
|
@ -35,6 +35,7 @@ type nodeConfig struct {
|
|||||||
SigPub string
|
SigPub string
|
||||||
SigPriv string
|
SigPriv string
|
||||||
Multicast bool
|
Multicast bool
|
||||||
|
IfName string
|
||||||
}
|
}
|
||||||
|
|
||||||
type node struct {
|
type node struct {
|
||||||
@ -80,6 +81,7 @@ func generateConfig() *nodeConfig {
|
|||||||
cfg.SigPriv = hex.EncodeToString(spriv[:])
|
cfg.SigPriv = hex.EncodeToString(spriv[:])
|
||||||
cfg.Peers = []string{}
|
cfg.Peers = []string{}
|
||||||
cfg.Multicast = true
|
cfg.Multicast = true
|
||||||
|
cfg.IfName = "auto"
|
||||||
return &cfg
|
return &cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,8 +184,8 @@ func main() {
|
|||||||
n := node{}
|
n := node{}
|
||||||
n.init(cfg, logger)
|
n.init(cfg, logger)
|
||||||
logger.Println("Starting tun...")
|
logger.Println("Starting tun...")
|
||||||
n.core.DEBUG_startTun() // 1280, the smallest supported MTU
|
n.core.DEBUG_startTun(cfg.IfName) // 1280, the smallest supported MTU
|
||||||
//n.core.DEBUG_startTunWithMTU(65535) // Largest supported MTU
|
//n.core.DEBUG_startTunWithMTU(cfg.IfName, 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