Skip to content

Commit

Permalink
Merge pull request #1 from NordSecurity/LLT-5312_add_logging_when_rea…
Browse files Browse the repository at this point in the history
…d_from_tun_failure_happens

[LLT-5312] Add more logging when read from tun failure happens
  • Loading branch information
Jauler authored Jun 18, 2024
2 parents 590352b + a6b3ebe commit 71426c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 1 addition & 4 deletions device/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/binary"
"errors"
"net"
"os"
"sync"
"time"

Expand Down Expand Up @@ -310,9 +309,7 @@ func (device *Device) RoutineReadFromTUN() {
continue
}
if !device.isClosed() {
if !errors.Is(readErr, os.ErrClosed) {
device.log.Errorf("Failed to read packet from TUN device: %v", readErr)
}
device.log.Errorf("Failed to read packet from TUN device: %v", readErr)
go device.Close()
}
return
Expand Down
6 changes: 3 additions & 3 deletions tun/tun_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ func (tun *NativeTun) Read(bufs [][]byte, sizes []int, offset int) (int, error)
defer tun.running.Done()
retry:
if tun.close.Load() {
return 0, os.ErrClosed
return 0, errors.New("Tunnel is being shutdown at the startup of reading of packets")
}
start := nanotime()
shouldSpin := tun.rate.current.Load() >= spinloopRateThreshold && uint64(start-tun.rate.nextStartTime.Load()) <= rateMeasurementGranularity*2
for {
if tun.close.Load() {
return 0, os.ErrClosed
return 0, errors.New("Tunnel is being shutdown while reading packets")
}
packet, err := tun.session.ReceivePacket()
switch err {
Expand All @@ -173,7 +173,7 @@ retry:
procyield(1)
continue
case windows.ERROR_HANDLE_EOF:
return 0, os.ErrClosed
return 0, errors.New("Driver indicated EOF while reading from tunnel")
case windows.ERROR_INVALID_DATA:
return 0, errors.New("Send ring corrupt")
}
Expand Down

0 comments on commit 71426c4

Please sign in to comment.