Page MenuHomeFreeBSD

Check so_error early in sendfile() call
ClosedPublic

Authored by jason_eggnet.com on Oct 3 2017, 2:45 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 14, 10:05 PM
Unknown Object (File)
Thu, Nov 14, 11:17 AM
Unknown Object (File)
Nov 11 2024, 11:51 PM
Unknown Object (File)
Nov 11 2024, 2:42 AM
Unknown Object (File)
Nov 10 2024, 10:02 PM
Unknown Object (File)
Nov 10 2024, 3:21 AM
Unknown Object (File)
Nov 10 2024, 2:35 AM
Unknown Object (File)
Nov 8 2024, 6:31 AM
Subscribers
None

Details

Summary

Prior to this patch, if a connection was reset
by the remote end, sendfile() would just report
ENOTCONN instead of ECONNRESET.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Using packetdrill with this https://github.com/nplab/packetdrill/pull/137

This review fixes the following behavior:

# ./packetdrill/gtests/net/packetdrill/packetdrill -v sendfile_rst.pkt
inbound injected packet:  0.100038 S 0:0(0) win 65535 <mss 1460,sackOK,eol,eol>
outbound sniffed packet:  0.100145 S. 29914850:29914850(0) ack 1 win 65535 <mss 1460,sackOK,eol,eol>
inbound injected packet:  0.150243 . 1:1(0) ack 29914851 win 65535
inbound injected packet:  0.250286 R 1:1(0) win 65535
sendfile_rst.pkt:11: runtime error in sendfile call: Expected errno 54 (Connection reset by peer) but got 57 (Socket is not connected)
# cat sendfile_rst.pkt
 0.000 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+0.000 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+0.000 bind(3, ..., ...) = 0
+0.000 listen(3, 3) = 0
+0.100 < S  0:0(0) win 65535 <mss 1460,sackOK,eol,eol>
+0.000 > S. 0:0(0) ack 1 win 65535 <mss 1460,sackOK,eol,eol>
+0.050 < . 1:1(0) ack 1 win 65535
+0.050 accept(3, ..., ...) = 4
+0.050 < R 1:1(0) ack 1 win 65535
+0.050 open("testfile", O_RDONLY) = 5
+0.050 sendfile(5, 4, 0, 0, {headers(0)=[], trailers(0)=[]}, [0], 0) = -1 ECONNRESET (Connection reset by peer)
+0.050 close(4) = 0

After the patch:

# ./packetdrill/gtests/net/packetdrill/packetdrill -v sendfilerst.pkt
inbound injected packet:  0.100370 S 0:0(0) win 65535 <mss 1460,sackOK,eol,eol>
outbound sniffed packet:  0.100907 S. 3047891798:3047891798(0) ack 1 win 65535 <mss 1460,sackOK,eol,eol>
inbound injected packet:  0.151481 . 1:1(0) ack 3047891799 win 65535
inbound injected packet:  0.252850 R 1:1(0) win 65535
This revision is now accepted and ready to land.Oct 6 2017, 8:09 PM
This revision was automatically updated to reflect the committed changes.