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)
Fri, Apr 19, 1:01 PM
Unknown Object (File)
Jan 14 2024, 10:13 AM
Unknown Object (File)
Dec 20 2023, 3:51 AM
Unknown Object (File)
Dec 10 2023, 9:30 AM
Unknown Object (File)
Dec 10 2023, 1:31 AM
Unknown Object (File)
Oct 10 2023, 5:51 PM
Unknown Object (File)
Sep 20 2023, 6:26 AM
Unknown Object (File)
Aug 15 2023, 3:56 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.