From 35173e23884f00244c201665bfdf16098e9618e7 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 27 May 2018 22:35:30 +0100 Subject: [PATCH] Fix starting TUN read/write --- src/yggdrasil/core.go | 12 ++++++------ src/yggdrasil/tun.go | 9 +++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/yggdrasil/core.go b/src/yggdrasil/core.go index 27e4e0ab..9fee3743 100644 --- a/src/yggdrasil/core.go +++ b/src/yggdrasil/core.go @@ -122,12 +122,6 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error { return err } - ip := net.IP(c.router.addr[:]).String() - if err := c.tun.setup(nc.IfName, nc.IfTAPMode, fmt.Sprintf("%s/8", ip), nc.IfMTU); err != nil { - c.log.Println("Failed to start TUN/TAP") - return err - } - if err := c.admin.start(); err != nil { c.log.Println("Failed to start admin socket") return err @@ -138,6 +132,12 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error { return err } + ip := net.IP(c.router.addr[:]).String() + if err := c.tun.start(nc.IfName, nc.IfTAPMode, fmt.Sprintf("%s/8", ip), nc.IfMTU); err != nil { + c.log.Println("Failed to start TUN/TAP") + return err + } + c.log.Println("Startup complete") return nil } diff --git a/src/yggdrasil/tun.go b/src/yggdrasil/tun.go index 5f5e50a0..f6a56e43 100644 --- a/src/yggdrasil/tun.go +++ b/src/yggdrasil/tun.go @@ -36,6 +36,15 @@ func (tun *tunDevice) init(core *Core) { tun.icmpv6.init(tun) } +func (tun *tunDevice) start(ifname string, iftapmode bool, addr string, mtu int) error { + if err := tun.setup(ifname, iftapmode, addr, mtu); err != nil { + return err + } + go func() { panic(tun.read()) }() + go func() { panic(tun.write()) }() + return nil +} + func (tun *tunDevice) write() error { for { data := <-tun.recv