Skip to content

Commit de0575d

Browse files
committed
netstack: return err from Writes on invalid fd
1 parent 994f58c commit de0575d

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

@@ -505,10 +502,7 @@ func (e *endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error)
505502

506503
if fd == invalidfd {
507504
log.E("ns: tun(-1): WritePackets (to tun): fd invalid (pkts: %d)", pkts.Len())
508-
if errorOnInvalidFD {
509-
return 0, &tcpip.ErrNoSuchFile{}
510-
}
511-
return 0, nil
505+
return 0, &tcpip.ErrNoSuchFile{}
512506
}
513507

514508
batch := make([]unix.Iovec, 0, batchSz)
@@ -637,10 +631,7 @@ func (e *endpoint) InjectOutbound(dest tcpip.Address, packet *buffer.View) tcpip
637631

638632
if !f.ok() {
639633
log.E("ns: tun(%d): inject-outbound (to tun) to dst(%v): endpoint not attached", fd, dest)
640-
if errorOnInvalidFD {
641-
return &tcpip.ErrUnknownDevice{}
642-
}
643-
return nil // nothing to do
634+
return &tcpip.ErrUnknownDevice{}
644635
}
645636

646637
b := packet.AsSlice()

0 commit comments

Comments
 (0)