tcp_minisocks.c (9e9fd65d1fa51d919d54d731be0e66492b5b6c5a) tcp_minisocks.c (46d3ceabd8d98ed0ad10f20c595ca784e34786c5)
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Implementation of the Transmission Control Protocol(TCP).
7 *
8 * Authors: Ross Biro

--- 35 unchanged lines hidden (view full) ---

44/* Short-time timewait calendar */
45
46 .twcal_hand = -1,
47 .twcal_timer = TIMER_INITIALIZER(inet_twdr_twcal_tick, 0,
48 (unsigned long)&tcp_death_row),
49};
50EXPORT_SYMBOL_GPL(tcp_death_row);
51
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Implementation of the Transmission Control Protocol(TCP).
7 *
8 * Authors: Ross Biro

--- 35 unchanged lines hidden (view full) ---

44/* Short-time timewait calendar */
45
46 .twcal_hand = -1,
47 .twcal_timer = TIMER_INITIALIZER(inet_twdr_twcal_tick, 0,
48 (unsigned long)&tcp_death_row),
49};
50EXPORT_SYMBOL_GPL(tcp_death_row);
51
52/* VJ's idea. Save last timestamp seen from this destination
53 * and hold it at least for normal timewait interval to use for duplicate
54 * segment detection in subsequent connections, before they enter synchronized
55 * state.
56 */
57
58static bool tcp_remember_stamp(struct sock *sk)
59{
60 const struct inet_connection_sock *icsk = inet_csk(sk);
61 struct tcp_sock *tp = tcp_sk(sk);
62 struct inet_peer *peer;
63 bool release_it;
64
65 peer = icsk->icsk_af_ops->get_peer(sk, &release_it);
66 if (peer) {
67 if ((s32)(peer->tcp_ts - tp->rx_opt.ts_recent) <= 0 ||
68 ((u32)get_seconds() - peer->tcp_ts_stamp > TCP_PAWS_MSL &&
69 peer->tcp_ts_stamp <= (u32)tp->rx_opt.ts_recent_stamp)) {
70 peer->tcp_ts_stamp = (u32)tp->rx_opt.ts_recent_stamp;
71 peer->tcp_ts = tp->rx_opt.ts_recent;
72 }
73 if (release_it)
74 inet_putpeer(peer);
75 return true;
76 }
77
78 return false;
79}
80
81static bool tcp_tw_remember_stamp(struct inet_timewait_sock *tw)
82{
83 struct sock *sk = (struct sock *) tw;
84 struct inet_peer *peer;
85
86 peer = twsk_getpeer(sk);
87 if (peer) {
88 const struct tcp_timewait_sock *tcptw = tcp_twsk(sk);
89
90 if ((s32)(peer->tcp_ts - tcptw->tw_ts_recent) <= 0 ||
91 ((u32)get_seconds() - peer->tcp_ts_stamp > TCP_PAWS_MSL &&
92 peer->tcp_ts_stamp <= (u32)tcptw->tw_ts_recent_stamp)) {
93 peer->tcp_ts_stamp = (u32)tcptw->tw_ts_recent_stamp;
94 peer->tcp_ts = tcptw->tw_ts_recent;
95 }
96 inet_putpeer(peer);
97 return true;
98 }
99 return false;
100}
101
102static bool tcp_in_window(u32 seq, u32 end_seq, u32 s_win, u32 e_win)
103{
104 if (seq == s_win)
105 return true;
106 if (after(end_seq, s_win) && before(seq, e_win))
107 return true;
108 return seq == e_win && seq == end_seq;
109}

--- 212 unchanged lines hidden (view full) ---

322 recycle_ok = tcp_remember_stamp(sk);
323
324 if (tcp_death_row.tw_count < tcp_death_row.sysctl_max_tw_buckets)
325 tw = inet_twsk_alloc(sk, state);
326
327 if (tw != NULL) {
328 struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
329 const int rto = (icsk->icsk_rto << 2) - (icsk->icsk_rto >> 1);
52static bool tcp_in_window(u32 seq, u32 end_seq, u32 s_win, u32 e_win)
53{
54 if (seq == s_win)
55 return true;
56 if (after(end_seq, s_win) && before(seq, e_win))
57 return true;
58 return seq == e_win && seq == end_seq;
59}

--- 212 unchanged lines hidden (view full) ---

272 recycle_ok = tcp_remember_stamp(sk);
273
274 if (tcp_death_row.tw_count < tcp_death_row.sysctl_max_tw_buckets)
275 tw = inet_twsk_alloc(sk, state);
276
277 if (tw != NULL) {
278 struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
279 const int rto = (icsk->icsk_rto << 2) - (icsk->icsk_rto >> 1);
280 struct inet_sock *inet = inet_sk(sk);
330
281
331 tw->tw_transparent = inet_sk(sk)->transparent;
282 tw->tw_transparent = inet->transparent;
332 tw->tw_rcv_wscale = tp->rx_opt.rcv_wscale;
333 tcptw->tw_rcv_nxt = tp->rcv_nxt;
334 tcptw->tw_snd_nxt = tp->snd_nxt;
335 tcptw->tw_rcv_wnd = tcp_receive_window(tp);
336 tcptw->tw_ts_recent = tp->rx_opt.ts_recent;
337 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
338
339#if IS_ENABLED(CONFIG_IPV6)

--- 58 unchanged lines hidden (view full) ---

398 tcp_update_metrics(sk);
399 tcp_done(sk);
400}
401
402void tcp_twsk_destructor(struct sock *sk)
403{
404#ifdef CONFIG_TCP_MD5SIG
405 struct tcp_timewait_sock *twsk = tcp_twsk(sk);
283 tw->tw_rcv_wscale = tp->rx_opt.rcv_wscale;
284 tcptw->tw_rcv_nxt = tp->rcv_nxt;
285 tcptw->tw_snd_nxt = tp->snd_nxt;
286 tcptw->tw_rcv_wnd = tcp_receive_window(tp);
287 tcptw->tw_ts_recent = tp->rx_opt.ts_recent;
288 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
289
290#if IS_ENABLED(CONFIG_IPV6)

--- 58 unchanged lines hidden (view full) ---

349 tcp_update_metrics(sk);
350 tcp_done(sk);
351}
352
353void tcp_twsk_destructor(struct sock *sk)
354{
355#ifdef CONFIG_TCP_MD5SIG
356 struct tcp_timewait_sock *twsk = tcp_twsk(sk);
357
406 if (twsk->tw_md5_key) {
407 tcp_free_md5sig_pool();
408 kfree_rcu(twsk->tw_md5_key, rcu);
409 }
410#endif
411}
412EXPORT_SYMBOL_GPL(tcp_twsk_destructor);
413

--- 16 unchanged lines hidden (view full) ---

430 if (newsk != NULL) {
431 const struct inet_request_sock *ireq = inet_rsk(req);
432 struct tcp_request_sock *treq = tcp_rsk(req);
433 struct inet_connection_sock *newicsk = inet_csk(newsk);
434 struct tcp_sock *newtp = tcp_sk(newsk);
435 struct tcp_sock *oldtp = tcp_sk(sk);
436 struct tcp_cookie_values *oldcvp = oldtp->cookie_values;
437
358 if (twsk->tw_md5_key) {
359 tcp_free_md5sig_pool();
360 kfree_rcu(twsk->tw_md5_key, rcu);
361 }
362#endif
363}
364EXPORT_SYMBOL_GPL(tcp_twsk_destructor);
365

--- 16 unchanged lines hidden (view full) ---

382 if (newsk != NULL) {
383 const struct inet_request_sock *ireq = inet_rsk(req);
384 struct tcp_request_sock *treq = tcp_rsk(req);
385 struct inet_connection_sock *newicsk = inet_csk(newsk);
386 struct tcp_sock *newtp = tcp_sk(newsk);
387 struct tcp_sock *oldtp = tcp_sk(sk);
388 struct tcp_cookie_values *oldcvp = oldtp->cookie_values;
389
390 newsk->sk_rx_dst = dst_clone(skb_dst(skb));
391
438 /* TCP Cookie Transactions require space for the cookie pair,
439 * as it differs for each connection. There is no need to
440 * copy any s_data_payload stored at the original socket.
441 * Failure will prevent resuming the connection.
442 *
443 * Presumed copied, in order of appearance:
444 * cookie_in_always, cookie_out_never
445 */

--- 19 unchanged lines hidden (view full) ---

465 newtp->rcv_wup = newtp->copied_seq =
466 newtp->rcv_nxt = treq->rcv_isn + 1;
467
468 newtp->snd_sml = newtp->snd_una =
469 newtp->snd_nxt = newtp->snd_up =
470 treq->snt_isn + 1 + tcp_s_data_size(oldtp);
471
472 tcp_prequeue_init(newtp);
392 /* TCP Cookie Transactions require space for the cookie pair,
393 * as it differs for each connection. There is no need to
394 * copy any s_data_payload stored at the original socket.
395 * Failure will prevent resuming the connection.
396 *
397 * Presumed copied, in order of appearance:
398 * cookie_in_always, cookie_out_never
399 */

--- 19 unchanged lines hidden (view full) ---

419 newtp->rcv_wup = newtp->copied_seq =
420 newtp->rcv_nxt = treq->rcv_isn + 1;
421
422 newtp->snd_sml = newtp->snd_una =
423 newtp->snd_nxt = newtp->snd_up =
424 treq->snt_isn + 1 + tcp_s_data_size(oldtp);
425
426 tcp_prequeue_init(newtp);
427 INIT_LIST_HEAD(&newtp->tsq_node);
473
474 tcp_init_wl(newtp, treq->rcv_isn);
475
476 newtp->srtt = 0;
477 newtp->mdev = TCP_TIMEOUT_INIT;
478 newicsk->icsk_rto = TCP_TIMEOUT_INIT;
479
480 newtp->packets_out = 0;

--- 315 unchanged lines hidden ---
428
429 tcp_init_wl(newtp, treq->rcv_isn);
430
431 newtp->srtt = 0;
432 newtp->mdev = TCP_TIMEOUT_INIT;
433 newicsk->icsk_rto = TCP_TIMEOUT_INIT;
434
435 newtp->packets_out = 0;

--- 315 unchanged lines hidden ---