Skip to content

Commit d83bd95

Browse files
Gerrit Renkerdavem330
authored andcommitted
[DCCP]: Check for unread data on close
This removes one FIXME with regard to close when there is still unread data. The mechanism is implemented similar to TCP: with regard to DCCP-specifics, a Reset with Code 2, "Aborted" is sent to the peer. This corresponds in part to RFC 4340, 8.1.1 and 8.1.5. Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk> Signed-off-by: Ian McDonald <ian.mcdonald@jandi.co.nz> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent dcfbc7e commit d83bd95

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎net/dccp/proto.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ void dccp_close(struct sock *sk, long timeout)
891891
{
892892
struct dccp_sock *dp = dccp_sk(sk);
893893
struct sk_buff *skb;
894+
u32 data_was_unread = 0;
894895
int state;
895896

896897
lock_sock(sk);
@@ -913,12 +914,17 @@ void dccp_close(struct sock *sk, long timeout)
913914
* descriptor close, not protocol-sourced closes, because the
914915
*reader process may not have drained the data yet!
915916
*/
916-
/* FIXME: check for unread data */
917917
while ((skb = __skb_dequeue(&sk->sk_receive_queue)) != NULL) {
918+
data_was_unread += skb->len;
918919
__kfree_skb(skb);
919920
}
920921

921-
if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) {
922+
if (data_was_unread) {
923+
/* Unread data was tossed, send an appropriate Reset Code */
924+
DCCP_WARN("DCCP: ABORT -- %u bytes unread\n", data_was_unread);
925+
dccp_send_reset(sk, DCCP_RESET_CODE_ABORTED);
926+
dccp_set_state(sk, DCCP_CLOSED);
927+
} else if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) {
922928
/* Check zero linger _after_ checking for unread data. */
923929
sk->sk_prot->disconnect(sk, 0);
924930
} else if (dccp_close_state(sk)) {

0 commit comments

Comments
 (0)