* Move a TCP connection into TIME_WAIT state. * tcbinfo is locked. * inp is locked, and is unlocked before returning. */
| 226 | * inp is locked, and is unlocked before returning. |
| 227 | */ |
| 228 | void |
| 229 | tcp_twstart(struct tcpcb *tp) |
| 230 | { |
| 231 | struct tcptw twlocal, *tw; |
| 232 | struct inpcb *inp = tp->t_inpcb; |
| 233 | struct socket *so; |
| 234 | uint32_t recwin; |
| 235 | bool acknow, local; |
| 236 | #ifdef INET6 |
| 237 | bool isipv6 = inp->inp_inc.inc_flags & INC_ISIPV6; |
| 238 | #endif |
| 239 | |
| 240 | NET_EPOCH_ASSERT(); |
| 241 | INP_WLOCK_ASSERT(inp); |
| 242 | |
| 243 | /* A dropped inp should never transition to TIME_WAIT state. */ |
| 244 | KASSERT((inp->inp_flags & INP_DROPPED) == 0, ("tcp_twstart: " |
| 245 | "(inp->inp_flags & INP_DROPPED) != 0")); |
| 246 | |
| 247 | if (V_nolocaltimewait) { |
| 248 | #ifdef INET6 |
| 249 | if (isipv6) |
| 250 | local = in6_localaddr(&inp->in6p_faddr); |
| 251 | else |
| 252 | #endif |
| 253 | #ifdef INET |
| 254 | local = in_localip(inp->inp_faddr); |
| 255 | #else |
| 256 | local = false; |
| 257 | #endif |
| 258 | } else |
| 259 | local = false; |
| 260 | |
| 261 | /* |
| 262 | * For use only by DTrace. We do not reference the state |
| 263 | * after this point so modifying it in place is not a problem. |
| 264 | */ |
| 265 | tcp_state_change(tp, TCPS_TIME_WAIT); |
| 266 | |
| 267 | if (local) |
| 268 | tw = &twlocal; |
| 269 | else |
| 270 | tw = uma_zalloc(V_tcptw_zone, M_NOWAIT); |
| 271 | if (tw == NULL) { |
| 272 | /* |
| 273 | * Reached limit on total number of TIMEWAIT connections |
| 274 | * allowed. Remove a connection from TIMEWAIT queue in LRU |
| 275 | * fashion to make room for this connection. |
| 276 | * |
| 277 | * XXX: Check if it possible to always have enough room |
| 278 | * in advance based on guarantees provided by uma_zalloc(). |
| 279 | */ |
| 280 | tw = tcp_tw_2msl_scan(1); |
| 281 | if (tw == NULL) { |
| 282 | tp = tcp_close(tp); |
| 283 | if (tp != NULL) |
| 284 | INP_WUNLOCK(inp); |
| 285 | return; |
no test coverage detected