From 1b1b776097b1a888198844490a29c449f1c1910e Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 10 Nov 2018 22:39:15 -0600 Subject: [PATCH] fix crash when starting in tun mode --- src/yggdrasil/tun.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/yggdrasil/tun.go b/src/yggdrasil/tun.go index 447ba617..4b3617c0 100644 --- a/src/yggdrasil/tun.go +++ b/src/yggdrasil/tun.go @@ -51,21 +51,23 @@ func (tun *tunDevice) start(ifname string, iftapmode bool, addr string, mtu int) } go func() { panic(tun.read()) }() go func() { panic(tun.write()) }() - go func() { - for { - if _, ok := tun.icmpv6.peermacs[tun.core.router.addr]; ok { - break + if iftapmode { + go func() { + for { + if _, ok := tun.icmpv6.peermacs[tun.core.router.addr]; ok { + break + } + request, err := tun.icmpv6.create_ndp_tap(tun.core.router.addr) + if err != nil { + panic(err) + } + if _, err := tun.iface.Write(request); err != nil { + panic(err) + } + time.Sleep(time.Second) } - request, err := tun.icmpv6.create_ndp_tap(tun.core.router.addr) - if err != nil { - panic(err) - } - if _, err := tun.iface.Write(request); err != nil { - panic(err) - } - time.Sleep(time.Second) - } - }() + }() + } return nil }