tun: fix crash when ForceMTU is called after close

Close closes the events channel, resulting in a panic from send on
closed channel.

Reported-By: Brad Fitzpatrick <brad@tailscale.com>
Link: https://github.com/tailscale/tailscale/issues/9555
Signed-off-by: James Tucker <james@tailscale.com>
This commit is contained in:
James Tucker 2023-09-27 14:52:21 -07:00
parent 202a3401e7
commit 2f6748dc88
No known key found for this signature in database

View file

@ -127,6 +127,9 @@ func (tun *NativeTun) MTU() (int, error) {
// TODO: This is a temporary hack. We really need to be monitoring the interface in real time and adapting to MTU changes. // TODO: This is a temporary hack. We really need to be monitoring the interface in real time and adapting to MTU changes.
func (tun *NativeTun) ForceMTU(mtu int) { func (tun *NativeTun) ForceMTU(mtu int) {
if tun.close.Load() {
return
}
update := tun.forcedMTU != mtu update := tun.forcedMTU != mtu
tun.forcedMTU = mtu tun.forcedMTU = mtu
if update { if update {