Skip to content

Commit d45f5c3

Browse files
committed
netstack: return err from Writes on invalid fd
1 parent a5e2b57 commit d45f5c3

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

intra/netstack/fdbased.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ var _ FdSwapper = (*linkFdSwap)(nil)
5454
// placeholder FD for whenever existing FD wrapped in struct fds is closed.
5555
const invalidfd int = -1
5656

57-
// Should WritePackets return NoSuchFile error if the fd is invalid?
58-
const errorOnInvalidFD = false
59-
6057
// wrapttl is the time to wait for the dispatcher to wrap up (close a previous FD).
6158
const waitttl = wrapttl
6259

@@ -513,10 +510,7 @@ func (e *endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error)
513510

514511
if fd == invalidfd {
515512
log.E("ns: tun(-1): WritePackets (to tun): fd invalid (pkts: %d)", pkts.Len())
516-
if errorOnInvalidFD {
517-
return 0, &tcpip.ErrNoSuchFile{}
518-
}
519-
return 0, nil
513+
return 0, &tcpip.ErrNoSuchFile{}
520514
}
521515

522516
batch := make([]unix.Iovec, 0, batchSz)
@@ -645,10 +639,7 @@ func (e *endpoint) InjectOutbound(dest tcpip.Address, packet *buffer.View) tcpip
645639

646640
if !f.ok() {
647641
log.E("ns: tun(%d): inject-outbound (to tun) to dst(%v): endpoint not attached", fd, dest)
648-
if errorOnInvalidFD {
649-
return &tcpip.ErrUnknownDevice{}
650-
}
651-
return nil // nothing to do
642+
return &tcpip.ErrUnknownDevice{}
652643
}
653644

654645
b := packet.AsSlice()

0 commit comments

Comments
 (0)