5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-09-19 16:09:36 +00:00

start a reader to disard traffic if the tun is disabled

This commit is contained in:
Arceliar 2021-05-15 16:44:56 -05:00
parent f61507238e
commit dfca87ba80

View File

@ -138,6 +138,15 @@ func (tun *TunAdapter) _start() error {
addr := fmt.Sprintf("%s/%d", net.IP(tun.addr[:]).String(), 8*len(address.GetPrefix())-1)
if current.IfName == "none" || current.IfName == "dummy" {
tun.log.Debugln("Not starting TUN as ifname is none or dummy")
go func() {
bs := make([]byte, tun.core.PacketConn.MTU())
for {
// Dump traffic to nowhere
if _, _, err := tun.core.PacketConn.ReadFrom(bs); err != nil {
return
}
}
}()
return nil
}
mtu := current.IfMTU