From owner-freebsd-net@FreeBSD.ORG Thu Nov 14 18:20:01 2013 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id AFFA33EE for ; Thu, 14 Nov 2013 18:20:01 +0000 (UTC) Received: from st11p05mm-asmtp003.mac.com (st11p05mm-asmtp003.mac.com [17.172.108.248]) by mx1.freebsd.org (Postfix) with ESMTP id 8A7F9225E for ; Thu, 14 Nov 2013 18:20:01 +0000 (UTC) Received: from [17.198.13.205] (unknown [17.198.13.205]) by st11p05mm-asmtp003.mac.com (Oracle Communications Messaging Server 7u4-27.08(7.0.4.27.7) 64bit (built Aug 22 2013)) with ESMTPSA id <0MW900600MX3G670@st11p05mm-asmtp003.mac.com> for freebsd-net@freebsd.org; Thu, 14 Nov 2013 18:19:53 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.10.8794,1.0.14,0.0.0000 definitions=2013-11-14_07:2013-11-13,2013-11-14,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1308280000 definitions=main-1311140118 Content-type: text/plain; charset=us-ascii MIME-version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: Question regarding RST packet and the tcp stack From: Charles Swiger In-reply-to: Date: Thu, 14 Nov 2013 10:19:51 -0800 Content-transfer-encoding: quoted-printable Message-id: References: To: Andrew Schmidt X-Mailer: Apple Mail (2.1510) Cc: "freebsd-net@freebsd.org" X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Nov 2013 18:20:01 -0000 On Nov 14, 2013, at 5:35 AM, Andrew Schmidt = wrote: > The OS on the host receives the following packets in order for that = socket: >=20 > Data packet (6 bytes) > FIN packet > RST packet >=20 > At this point the application (host) tries to read from the socket. = On windows, this causes a "the os has closed the connection" exception = and doesn't let you read those 6 bytes. >=20 > On Linux, those 6 bytes can be read. Yes, that's correct behavior (assuming the data received fits within the = open window). > I've looked over the TCP rfc: = http://www.rfc-editor.org/rfc/rfc1122.txt . The TCP RFC is: http://www.ietf.org/rfc/rfc793.txt > But it's not clear what should happen to 6 bytes once a RST packet = arrives. >=20 > Does anyone know what the correct behaviour is? Or point me to = freebsd's tcp stack code? See section 3.5 of RFC 793: "3.5. Closing a Connection CLOSE is an operation meaning "I have no more data to send." The notion of closing a full-duplex connection is subject to ambiguous interpretation, of course, since it may not be obvious how to treat the receiving side of the connection. We have chosen to treat CLOSE in a simplex fashion. The user who CLOSEs may continue to RECEIVE until he is told that the other side has CLOSED also. Thus, a program could initiate several SENDs followed by a CLOSE, and then continue to RECEIVE until signaled that a RECEIVE failed because the other side has CLOSED. We assume that the TCP will signal a user, even if no RECEIVEs are outstanding, that the other side has closed, so the user can terminate his side gracefully. A TCP will reliably deliver all buffers SENT before the connection was CLOSED so a user who expects no data in return need only wait to hear the connection was CLOSED successfully to know that all his data was received at the destination TCP. Users must keep reading connections they close for sending until the TCP says no more data." Regards, --=20 -Chuck