5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-12-23 12:15:39 +00:00

Fix starting TUN read/write

This commit is contained in:
Neil Alexander 2018-05-27 22:35:30 +01:00
parent 4c115de633
commit 35173e2388
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
2 changed files with 15 additions and 6 deletions

View File

@ -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
}

View File

@ -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