Skip to content

Commit 9dc950d

Browse files
committed
netstack: return err from Writes on invalid fd
1 parent 520e439 commit 9dc950d

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
@@ -53,9 +53,6 @@ var _ FdSwapper = (*linkFdSwap)(nil)
5353
// placeholder FD for whenever existing FD wrapped in struct fds is closed.
5454
const invalidfd int = -1
5555

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

@@ -503,10 +500,7 @@ func (e *endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error)
503500

504501
if fd == invalidfd {
505502
log.E("ns: tun(-1): WritePackets (to tun): fd invalid (pkts: %d)", pkts.Len())
506-
if errorOnInvalidFD {
507-
return 0, &tcpip.ErrNoSuchFile{}
508-
}
509-
return 0, nil
503+
return 0, &tcpip.ErrNoSuchFile{}
510504
}
511505

512506
batch := make([]unix.Iovec, 0, batchSz)
@@ -635,10 +629,7 @@ func (e *endpoint) InjectOutbound(dest tcpip.Address, packet *buffer.View) tcpip
635629

636630
if !f.ok() {
637631
log.E("ns: tun(%d): inject-outbound (to tun) to dst(%v): endpoint not attached", fd, dest)
638-
if errorOnInvalidFD {
639-
return &tcpip.ErrUnknownDevice{}
640-
}
641-
return nil // nothing to do
632+
return &tcpip.ErrUnknownDevice{}
642633
}
643634

644635
b := packet.AsSlice()

0 commit comments

Comments
 (0)