Sat Jun 20 17:29:31 2009 UTC ()
Follow exactly the recommendation of draft-ietf-tcpm-tcpsecure-11.txt:
Don't check gainst the last ack received, but the expected sequence number.
This makes RST handling independent of delayed ACK. From Joanne M Mikkelson.


(christos)
diff -r1.295 -r1.296 src/sys/netinet/tcp_input.c

cvs diff -r1.295 -r1.296 src/sys/netinet/tcp_input.c (expand / switch to unified diff)

--- src/sys/netinet/tcp_input.c 2009/03/18 16:00:22 1.295
+++ src/sys/netinet/tcp_input.c 2009/06/20 17:29:31 1.296
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tcp_input.c,v 1.295 2009/03/18 16:00:22 cegger Exp $ */ 1/* $NetBSD: tcp_input.c,v 1.296 2009/06/20 17:29:31 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -135,27 +135,27 @@ @@ -135,27 +135,27 @@
135 */ 135 */
136 136
137/* 137/*
138 * TODO list for SYN cache stuff: 138 * TODO list for SYN cache stuff:
139 * 139 *
140 * Find room for a "state" field, which is needed to keep a 140 * Find room for a "state" field, which is needed to keep a
141 * compressed state for TIME_WAIT TCBs. It's been noted already 141 * compressed state for TIME_WAIT TCBs. It's been noted already
142 * that this is fairly important for very high-volume web and 142 * that this is fairly important for very high-volume web and
143 * mail servers, which use a large number of short-lived 143 * mail servers, which use a large number of short-lived
144 * connections. 144 * connections.
145 */ 145 */
146 146
147#include <sys/cdefs.h> 147#include <sys/cdefs.h>
148__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.295 2009/03/18 16:00:22 cegger Exp $"); 148__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.296 2009/06/20 17:29:31 christos Exp $");
149 149
150#include "opt_inet.h" 150#include "opt_inet.h"
151#include "opt_ipsec.h" 151#include "opt_ipsec.h"
152#include "opt_inet_csum.h" 152#include "opt_inet_csum.h"
153#include "opt_tcp_debug.h" 153#include "opt_tcp_debug.h"
154 154
155#include <sys/param.h> 155#include <sys/param.h>
156#include <sys/systm.h> 156#include <sys/systm.h>
157#include <sys/malloc.h> 157#include <sys/malloc.h>
158#include <sys/mbuf.h> 158#include <sys/mbuf.h>
159#include <sys/protosw.h> 159#include <sys/protosw.h>
160#include <sys/socket.h> 160#include <sys/socket.h>
161#include <sys/socketvar.h> 161#include <sys/socketvar.h>
@@ -2094,27 +2094,27 @@ after_listen: @@ -2094,27 +2094,27 @@ after_listen:
2094 tiflags &= ~(TH_FIN|TH_RST); 2094 tiflags &= ~(TH_FIN|TH_RST);
2095 /* 2095 /*
2096 * Send an ACK to resynchronize and drop any data. 2096 * Send an ACK to resynchronize and drop any data.
2097 * But keep on processing for RST or ACK. 2097 * But keep on processing for RST or ACK.
2098 */ 2098 */
2099 tp->t_flags |= TF_ACKNOW; 2099 tp->t_flags |= TF_ACKNOW;
2100 todrop = tlen; 2100 todrop = tlen;
2101 dupseg = true; 2101 dupseg = true;
2102 tcps = TCP_STAT_GETREF(); 2102 tcps = TCP_STAT_GETREF();
2103 tcps[TCP_STAT_RCVDUPPACK]++; 2103 tcps[TCP_STAT_RCVDUPPACK]++;
2104 tcps[TCP_STAT_RCVDUPBYTE] += todrop; 2104 tcps[TCP_STAT_RCVDUPBYTE] += todrop;
2105 TCP_STAT_PUTREF(); 2105 TCP_STAT_PUTREF();
2106 } else if ((tiflags & TH_RST) && 2106 } else if ((tiflags & TH_RST) &&
2107 th->th_seq != tp->last_ack_sent) { 2107 th->th_seq != tp->rcv_nxt) {
2108 /* 2108 /*
2109 * Test for reset before adjusting the sequence 2109 * Test for reset before adjusting the sequence
2110 * number for overlapping data. 2110 * number for overlapping data.
2111 */ 2111 */
2112 goto dropafterack_ratelim; 2112 goto dropafterack_ratelim;
2113 } else { 2113 } else {
2114 tcps = TCP_STAT_GETREF(); 2114 tcps = TCP_STAT_GETREF();
2115 tcps[TCP_STAT_RCVPARTDUPPACK]++; 2115 tcps[TCP_STAT_RCVPARTDUPPACK]++;
2116 tcps[TCP_STAT_RCVPARTDUPBYTE] += todrop; 2116 tcps[TCP_STAT_RCVPARTDUPBYTE] += todrop;
2117 TCP_STAT_PUTREF(); 2117 TCP_STAT_PUTREF();
2118 } 2118 }
2119 tcp_new_dsack(tp, th->th_seq, todrop); 2119 tcp_new_dsack(tp, th->th_seq, todrop);
2120 hdroptlen += todrop; /*drop from head afterwards*/ 2120 hdroptlen += todrop; /*drop from head afterwards*/
@@ -2220,27 +2220,27 @@ after_listen: @@ -2220,27 +2220,27 @@ after_listen:
2220 } 2220 }
2221 2221
2222 /* 2222 /*
2223 * If the RST bit is set examine the state: 2223 * If the RST bit is set examine the state:
2224 * SYN_RECEIVED STATE: 2224 * SYN_RECEIVED STATE:
2225 * If passive open, return to LISTEN state. 2225 * If passive open, return to LISTEN state.
2226 * If active open, inform user that connection was refused. 2226 * If active open, inform user that connection was refused.
2227 * ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES: 2227 * ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES:
2228 * Inform user that connection was reset, and close tcb. 2228 * Inform user that connection was reset, and close tcb.
2229 * CLOSING, LAST_ACK, TIME_WAIT STATES 2229 * CLOSING, LAST_ACK, TIME_WAIT STATES
2230 * Close the tcb. 2230 * Close the tcb.
2231 */ 2231 */
2232 if (tiflags & TH_RST) { 2232 if (tiflags & TH_RST) {
2233 if (th->th_seq != tp->last_ack_sent) 2233 if (th->th_seq != tp->rcv_nxt)
2234 goto dropafterack_ratelim; 2234 goto dropafterack_ratelim;
2235 2235
2236 switch (tp->t_state) { 2236 switch (tp->t_state) {
2237 case TCPS_SYN_RECEIVED: 2237 case TCPS_SYN_RECEIVED:
2238 so->so_error = ECONNREFUSED; 2238 so->so_error = ECONNREFUSED;
2239 goto close; 2239 goto close;
2240 2240
2241 case TCPS_ESTABLISHED: 2241 case TCPS_ESTABLISHED:
2242 case TCPS_FIN_WAIT_1: 2242 case TCPS_FIN_WAIT_1:
2243 case TCPS_FIN_WAIT_2: 2243 case TCPS_FIN_WAIT_2:
2244 case TCPS_CLOSE_WAIT: 2244 case TCPS_CLOSE_WAIT:
2245 so->so_error = ECONNRESET; 2245 so->so_error = ECONNRESET;
2246 close: 2246 close: