From 3f73632cc3cb496a8e63087e7b4053e88976c2de Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Tue, 9 Nov 2021 23:56:58 +0100 Subject: WIP fix Attach --- tun/netstack/tun.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tun/netstack/tun.go b/tun/netstack/tun.go index 8e3ce4b..233cf27 100644 --- a/tun/netstack/tun.go +++ b/tun/netstack/tun.go @@ -48,13 +48,19 @@ type Net struct { } func (e *endpoint) Attach(dispatcher stack.NetworkDispatcher) { - if dispatcher == nil { - (*netTun)(e).events <- tun.EventUp - } else { - (*netTun)(e).events <- tun.EventDown + var event tun.Event + + if e.dispatcher == nil && dispatcher != nil { + event = tun.EventUp + } else if e.dispatcher != nil && dispatcher == nil { + event = tun.EventDown } e.dispatcher = dispatcher + + if event > 0 { + (*netTun)(e).events <- event + } } func (e *endpoint) IsAttached() bool { -- cgit v1.2.3