0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <linux/module.h>
0023 #include <linux/gfp.h>
0024 #include <net/tcp.h>
0025
0026 static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)
0027 {
0028 struct inet_connection_sock *icsk = inet_csk(sk);
0029 u32 elapsed, start_ts;
0030 s32 remaining;
0031
0032 start_ts = tcp_sk(sk)->retrans_stamp;
0033 if (!icsk->icsk_user_timeout)
0034 return icsk->icsk_rto;
0035 elapsed = tcp_time_stamp(tcp_sk(sk)) - start_ts;
0036 remaining = icsk->icsk_user_timeout - elapsed;
0037 if (remaining <= 0)
0038 return 1;
0039
0040 return min_t(u32, icsk->icsk_rto, msecs_to_jiffies(remaining));
0041 }
0042
0043 u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when)
0044 {
0045 struct inet_connection_sock *icsk = inet_csk(sk);
0046 u32 remaining;
0047 s32 elapsed;
0048
0049 if (!icsk->icsk_user_timeout || !icsk->icsk_probes_tstamp)
0050 return when;
0051
0052 elapsed = tcp_jiffies32 - icsk->icsk_probes_tstamp;
0053 if (unlikely(elapsed < 0))
0054 elapsed = 0;
0055 remaining = msecs_to_jiffies(icsk->icsk_user_timeout) - elapsed;
0056 remaining = max_t(u32, remaining, TCP_TIMEOUT_MIN);
0057
0058 return min_t(u32, remaining, when);
0059 }
0060
0061
0062
0063
0064
0065
0066
0067
0068 static void tcp_write_err(struct sock *sk)
0069 {
0070 sk->sk_err = sk->sk_err_soft ? : ETIMEDOUT;
0071 sk_error_report(sk);
0072
0073 tcp_write_queue_purge(sk);
0074 tcp_done(sk);
0075 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONTIMEOUT);
0076 }
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102 static int tcp_out_of_resources(struct sock *sk, bool do_reset)
0103 {
0104 struct tcp_sock *tp = tcp_sk(sk);
0105 int shift = 0;
0106
0107
0108
0109 if ((s32)(tcp_jiffies32 - tp->lsndtime) > 2*TCP_RTO_MAX || !do_reset)
0110 shift++;
0111
0112
0113 if (sk->sk_err_soft)
0114 shift++;
0115
0116 if (tcp_check_oom(sk, shift)) {
0117
0118
0119 if ((s32)(tcp_jiffies32 - tp->lsndtime) <= TCP_TIMEWAIT_LEN ||
0120
0121 (!tp->snd_wnd && !tp->packets_out))
0122 do_reset = true;
0123 if (do_reset)
0124 tcp_send_active_reset(sk, GFP_ATOMIC);
0125 tcp_done(sk);
0126 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY);
0127 return 1;
0128 }
0129
0130 if (!check_net(sock_net(sk))) {
0131
0132 tcp_done(sk);
0133 return 1;
0134 }
0135
0136 return 0;
0137 }
0138
0139
0140
0141
0142
0143
0144 static int tcp_orphan_retries(struct sock *sk, bool alive)
0145 {
0146 int retries = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_orphan_retries);
0147
0148
0149 if (sk->sk_err_soft && !alive)
0150 retries = 0;
0151
0152
0153
0154
0155 if (retries == 0 && alive)
0156 retries = 8;
0157 return retries;
0158 }
0159
0160 static void tcp_mtu_probing(struct inet_connection_sock *icsk, struct sock *sk)
0161 {
0162 const struct net *net = sock_net(sk);
0163 int mss;
0164
0165
0166 if (!READ_ONCE(net->ipv4.sysctl_tcp_mtu_probing))
0167 return;
0168
0169 if (!icsk->icsk_mtup.enabled) {
0170 icsk->icsk_mtup.enabled = 1;
0171 icsk->icsk_mtup.probe_timestamp = tcp_jiffies32;
0172 } else {
0173 mss = tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_low) >> 1;
0174 mss = min(READ_ONCE(net->ipv4.sysctl_tcp_base_mss), mss);
0175 mss = max(mss, READ_ONCE(net->ipv4.sysctl_tcp_mtu_probe_floor));
0176 mss = max(mss, READ_ONCE(net->ipv4.sysctl_tcp_min_snd_mss));
0177 icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, mss);
0178 }
0179 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
0180 }
0181
0182 static unsigned int tcp_model_timeout(struct sock *sk,
0183 unsigned int boundary,
0184 unsigned int rto_base)
0185 {
0186 unsigned int linear_backoff_thresh, timeout;
0187
0188 linear_backoff_thresh = ilog2(TCP_RTO_MAX / rto_base);
0189 if (boundary <= linear_backoff_thresh)
0190 timeout = ((2 << boundary) - 1) * rto_base;
0191 else
0192 timeout = ((2 << linear_backoff_thresh) - 1) * rto_base +
0193 (boundary - linear_backoff_thresh) * TCP_RTO_MAX;
0194 return jiffies_to_msecs(timeout);
0195 }
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209 static bool retransmits_timed_out(struct sock *sk,
0210 unsigned int boundary,
0211 unsigned int timeout)
0212 {
0213 unsigned int start_ts;
0214
0215 if (!inet_csk(sk)->icsk_retransmits)
0216 return false;
0217
0218 start_ts = tcp_sk(sk)->retrans_stamp;
0219 if (likely(timeout == 0)) {
0220 unsigned int rto_base = TCP_RTO_MIN;
0221
0222 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))
0223 rto_base = tcp_timeout_init(sk);
0224 timeout = tcp_model_timeout(sk, boundary, rto_base);
0225 }
0226
0227 return (s32)(tcp_time_stamp(tcp_sk(sk)) - start_ts - timeout) >= 0;
0228 }
0229
0230
0231 static int tcp_write_timeout(struct sock *sk)
0232 {
0233 struct inet_connection_sock *icsk = inet_csk(sk);
0234 struct tcp_sock *tp = tcp_sk(sk);
0235 struct net *net = sock_net(sk);
0236 bool expired = false, do_reset;
0237 int retry_until;
0238
0239 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
0240 if (icsk->icsk_retransmits)
0241 __dst_negative_advice(sk);
0242 retry_until = icsk->icsk_syn_retries ? :
0243 READ_ONCE(net->ipv4.sysctl_tcp_syn_retries);
0244 expired = icsk->icsk_retransmits >= retry_until;
0245 } else {
0246 if (retransmits_timed_out(sk, READ_ONCE(net->ipv4.sysctl_tcp_retries1), 0)) {
0247
0248 tcp_mtu_probing(icsk, sk);
0249
0250 __dst_negative_advice(sk);
0251 }
0252
0253 retry_until = READ_ONCE(net->ipv4.sysctl_tcp_retries2);
0254 if (sock_flag(sk, SOCK_DEAD)) {
0255 const bool alive = icsk->icsk_rto < TCP_RTO_MAX;
0256
0257 retry_until = tcp_orphan_retries(sk, alive);
0258 do_reset = alive ||
0259 !retransmits_timed_out(sk, retry_until, 0);
0260
0261 if (tcp_out_of_resources(sk, do_reset))
0262 return 1;
0263 }
0264 }
0265 if (!expired)
0266 expired = retransmits_timed_out(sk, retry_until,
0267 icsk->icsk_user_timeout);
0268 tcp_fastopen_active_detect_blackhole(sk, expired);
0269
0270 if (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RTO_CB_FLAG))
0271 tcp_call_bpf_3arg(sk, BPF_SOCK_OPS_RTO_CB,
0272 icsk->icsk_retransmits,
0273 icsk->icsk_rto, (int)expired);
0274
0275 if (expired) {
0276
0277 tcp_write_err(sk);
0278 return 1;
0279 }
0280
0281 if (sk_rethink_txhash(sk)) {
0282 tp->timeout_rehash++;
0283 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPTIMEOUTREHASH);
0284 }
0285
0286 return 0;
0287 }
0288
0289
0290 void tcp_delack_timer_handler(struct sock *sk)
0291 {
0292 struct inet_connection_sock *icsk = inet_csk(sk);
0293
0294 if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
0295 !(icsk->icsk_ack.pending & ICSK_ACK_TIMER))
0296 return;
0297
0298 if (time_after(icsk->icsk_ack.timeout, jiffies)) {
0299 sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout);
0300 return;
0301 }
0302 icsk->icsk_ack.pending &= ~ICSK_ACK_TIMER;
0303
0304 if (inet_csk_ack_scheduled(sk)) {
0305 if (!inet_csk_in_pingpong_mode(sk)) {
0306
0307 icsk->icsk_ack.ato = min(icsk->icsk_ack.ato << 1, icsk->icsk_rto);
0308 } else {
0309
0310
0311
0312 inet_csk_exit_pingpong_mode(sk);
0313 icsk->icsk_ack.ato = TCP_ATO_MIN;
0314 }
0315 tcp_mstamp_refresh(tcp_sk(sk));
0316 tcp_send_ack(sk);
0317 __NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKS);
0318 }
0319 }
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331 static void tcp_delack_timer(struct timer_list *t)
0332 {
0333 struct inet_connection_sock *icsk =
0334 from_timer(icsk, t, icsk_delack_timer);
0335 struct sock *sk = &icsk->icsk_inet.sk;
0336
0337 bh_lock_sock(sk);
0338 if (!sock_owned_by_user(sk)) {
0339 tcp_delack_timer_handler(sk);
0340 } else {
0341 __NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKLOCKED);
0342
0343 if (!test_and_set_bit(TCP_DELACK_TIMER_DEFERRED, &sk->sk_tsq_flags))
0344 sock_hold(sk);
0345 }
0346 bh_unlock_sock(sk);
0347 sock_put(sk);
0348 }
0349
0350 static void tcp_probe_timer(struct sock *sk)
0351 {
0352 struct inet_connection_sock *icsk = inet_csk(sk);
0353 struct sk_buff *skb = tcp_send_head(sk);
0354 struct tcp_sock *tp = tcp_sk(sk);
0355 int max_probes;
0356
0357 if (tp->packets_out || !skb) {
0358 icsk->icsk_probes_out = 0;
0359 icsk->icsk_probes_tstamp = 0;
0360 return;
0361 }
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371 if (!icsk->icsk_probes_tstamp)
0372 icsk->icsk_probes_tstamp = tcp_jiffies32;
0373 else if (icsk->icsk_user_timeout &&
0374 (s32)(tcp_jiffies32 - icsk->icsk_probes_tstamp) >=
0375 msecs_to_jiffies(icsk->icsk_user_timeout))
0376 goto abort;
0377
0378 max_probes = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_retries2);
0379 if (sock_flag(sk, SOCK_DEAD)) {
0380 const bool alive = inet_csk_rto_backoff(icsk, TCP_RTO_MAX) < TCP_RTO_MAX;
0381
0382 max_probes = tcp_orphan_retries(sk, alive);
0383 if (!alive && icsk->icsk_backoff >= max_probes)
0384 goto abort;
0385 if (tcp_out_of_resources(sk, true))
0386 return;
0387 }
0388
0389 if (icsk->icsk_probes_out >= max_probes) {
0390 abort: tcp_write_err(sk);
0391 } else {
0392
0393 tcp_send_probe0(sk);
0394 }
0395 }
0396
0397
0398
0399
0400
0401 static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req)
0402 {
0403 struct inet_connection_sock *icsk = inet_csk(sk);
0404 struct tcp_sock *tp = tcp_sk(sk);
0405 int max_retries;
0406
0407 req->rsk_ops->syn_ack_timeout(req);
0408
0409
0410 max_retries = icsk->icsk_syn_retries ? :
0411 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_synack_retries) + 1;
0412
0413 if (req->num_timeout >= max_retries) {
0414 tcp_write_err(sk);
0415 return;
0416 }
0417
0418 if (icsk->icsk_retransmits == 1)
0419 tcp_enter_loss(sk);
0420
0421
0422
0423
0424
0425 inet_rtx_syn_ack(sk, req);
0426 req->num_timeout++;
0427 icsk->icsk_retransmits++;
0428 if (!tp->retrans_stamp)
0429 tp->retrans_stamp = tcp_time_stamp(tp);
0430 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
0431 TCP_TIMEOUT_INIT << req->num_timeout, TCP_RTO_MAX);
0432 }
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446 void tcp_retransmit_timer(struct sock *sk)
0447 {
0448 struct tcp_sock *tp = tcp_sk(sk);
0449 struct net *net = sock_net(sk);
0450 struct inet_connection_sock *icsk = inet_csk(sk);
0451 struct request_sock *req;
0452 struct sk_buff *skb;
0453
0454 req = rcu_dereference_protected(tp->fastopen_rsk,
0455 lockdep_sock_is_held(sk));
0456 if (req) {
0457 WARN_ON_ONCE(sk->sk_state != TCP_SYN_RECV &&
0458 sk->sk_state != TCP_FIN_WAIT1);
0459 tcp_fastopen_synack_timer(sk, req);
0460
0461
0462
0463 return;
0464 }
0465
0466 if (!tp->packets_out)
0467 return;
0468
0469 skb = tcp_rtx_queue_head(sk);
0470 if (WARN_ON_ONCE(!skb))
0471 return;
0472
0473 tp->tlp_high_seq = 0;
0474
0475 if (!tp->snd_wnd && !sock_flag(sk, SOCK_DEAD) &&
0476 !((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))) {
0477
0478
0479
0480
0481
0482 struct inet_sock *inet = inet_sk(sk);
0483 if (sk->sk_family == AF_INET) {
0484 net_dbg_ratelimited("Peer %pI4:%u/%u unexpectedly shrunk window %u:%u (repaired)\n",
0485 &inet->inet_daddr,
0486 ntohs(inet->inet_dport),
0487 inet->inet_num,
0488 tp->snd_una, tp->snd_nxt);
0489 }
0490 #if IS_ENABLED(CONFIG_IPV6)
0491 else if (sk->sk_family == AF_INET6) {
0492 net_dbg_ratelimited("Peer %pI6:%u/%u unexpectedly shrunk window %u:%u (repaired)\n",
0493 &sk->sk_v6_daddr,
0494 ntohs(inet->inet_dport),
0495 inet->inet_num,
0496 tp->snd_una, tp->snd_nxt);
0497 }
0498 #endif
0499 if (tcp_jiffies32 - tp->rcv_tstamp > TCP_RTO_MAX) {
0500 tcp_write_err(sk);
0501 goto out;
0502 }
0503 tcp_enter_loss(sk);
0504 tcp_retransmit_skb(sk, skb, 1);
0505 __sk_dst_reset(sk);
0506 goto out_reset_timer;
0507 }
0508
0509 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPTIMEOUTS);
0510 if (tcp_write_timeout(sk))
0511 goto out;
0512
0513 if (icsk->icsk_retransmits == 0) {
0514 int mib_idx = 0;
0515
0516 if (icsk->icsk_ca_state == TCP_CA_Recovery) {
0517 if (tcp_is_sack(tp))
0518 mib_idx = LINUX_MIB_TCPSACKRECOVERYFAIL;
0519 else
0520 mib_idx = LINUX_MIB_TCPRENORECOVERYFAIL;
0521 } else if (icsk->icsk_ca_state == TCP_CA_Loss) {
0522 mib_idx = LINUX_MIB_TCPLOSSFAILURES;
0523 } else if ((icsk->icsk_ca_state == TCP_CA_Disorder) ||
0524 tp->sacked_out) {
0525 if (tcp_is_sack(tp))
0526 mib_idx = LINUX_MIB_TCPSACKFAILURES;
0527 else
0528 mib_idx = LINUX_MIB_TCPRENOFAILURES;
0529 }
0530 if (mib_idx)
0531 __NET_INC_STATS(sock_net(sk), mib_idx);
0532 }
0533
0534 tcp_enter_loss(sk);
0535
0536 icsk->icsk_retransmits++;
0537 if (tcp_retransmit_skb(sk, tcp_rtx_queue_head(sk), 1) > 0) {
0538
0539
0540
0541 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
0542 TCP_RESOURCE_PROBE_INTERVAL,
0543 TCP_RTO_MAX);
0544 goto out;
0545 }
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561
0562 icsk->icsk_backoff++;
0563
0564 out_reset_timer:
0565
0566
0567
0568
0569
0570
0571
0572
0573
0574 if (sk->sk_state == TCP_ESTABLISHED &&
0575 (tp->thin_lto || READ_ONCE(net->ipv4.sysctl_tcp_thin_linear_timeouts)) &&
0576 tcp_stream_is_thin(tp) &&
0577 icsk->icsk_retransmits <= TCP_THIN_LINEAR_RETRIES) {
0578 icsk->icsk_backoff = 0;
0579 icsk->icsk_rto = min(__tcp_set_rto(tp), TCP_RTO_MAX);
0580 } else {
0581
0582 icsk->icsk_rto = min(icsk->icsk_rto << 1, TCP_RTO_MAX);
0583 }
0584 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
0585 tcp_clamp_rto_to_user_timeout(sk), TCP_RTO_MAX);
0586 if (retransmits_timed_out(sk, READ_ONCE(net->ipv4.sysctl_tcp_retries1) + 1, 0))
0587 __sk_dst_reset(sk);
0588
0589 out:;
0590 }
0591
0592
0593
0594 void tcp_write_timer_handler(struct sock *sk)
0595 {
0596 struct inet_connection_sock *icsk = inet_csk(sk);
0597 int event;
0598
0599 if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
0600 !icsk->icsk_pending)
0601 return;
0602
0603 if (time_after(icsk->icsk_timeout, jiffies)) {
0604 sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout);
0605 return;
0606 }
0607
0608 tcp_mstamp_refresh(tcp_sk(sk));
0609 event = icsk->icsk_pending;
0610
0611 switch (event) {
0612 case ICSK_TIME_REO_TIMEOUT:
0613 tcp_rack_reo_timeout(sk);
0614 break;
0615 case ICSK_TIME_LOSS_PROBE:
0616 tcp_send_loss_probe(sk);
0617 break;
0618 case ICSK_TIME_RETRANS:
0619 icsk->icsk_pending = 0;
0620 tcp_retransmit_timer(sk);
0621 break;
0622 case ICSK_TIME_PROBE0:
0623 icsk->icsk_pending = 0;
0624 tcp_probe_timer(sk);
0625 break;
0626 }
0627 }
0628
0629 static void tcp_write_timer(struct timer_list *t)
0630 {
0631 struct inet_connection_sock *icsk =
0632 from_timer(icsk, t, icsk_retransmit_timer);
0633 struct sock *sk = &icsk->icsk_inet.sk;
0634
0635 bh_lock_sock(sk);
0636 if (!sock_owned_by_user(sk)) {
0637 tcp_write_timer_handler(sk);
0638 } else {
0639
0640 if (!test_and_set_bit(TCP_WRITE_TIMER_DEFERRED, &sk->sk_tsq_flags))
0641 sock_hold(sk);
0642 }
0643 bh_unlock_sock(sk);
0644 sock_put(sk);
0645 }
0646
0647 void tcp_syn_ack_timeout(const struct request_sock *req)
0648 {
0649 struct net *net = read_pnet(&inet_rsk(req)->ireq_net);
0650
0651 __NET_INC_STATS(net, LINUX_MIB_TCPTIMEOUTS);
0652 }
0653 EXPORT_SYMBOL(tcp_syn_ack_timeout);
0654
0655 void tcp_set_keepalive(struct sock *sk, int val)
0656 {
0657 if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))
0658 return;
0659
0660 if (val && !sock_flag(sk, SOCK_KEEPOPEN))
0661 inet_csk_reset_keepalive_timer(sk, keepalive_time_when(tcp_sk(sk)));
0662 else if (!val)
0663 inet_csk_delete_keepalive_timer(sk);
0664 }
0665 EXPORT_SYMBOL_GPL(tcp_set_keepalive);
0666
0667
0668 static void tcp_keepalive_timer (struct timer_list *t)
0669 {
0670 struct sock *sk = from_timer(sk, t, sk_timer);
0671 struct inet_connection_sock *icsk = inet_csk(sk);
0672 struct tcp_sock *tp = tcp_sk(sk);
0673 u32 elapsed;
0674
0675
0676 bh_lock_sock(sk);
0677 if (sock_owned_by_user(sk)) {
0678
0679 inet_csk_reset_keepalive_timer (sk, HZ/20);
0680 goto out;
0681 }
0682
0683 if (sk->sk_state == TCP_LISTEN) {
0684 pr_err("Hmm... keepalive on a LISTEN ???\n");
0685 goto out;
0686 }
0687
0688 tcp_mstamp_refresh(tp);
0689 if (sk->sk_state == TCP_FIN_WAIT2 && sock_flag(sk, SOCK_DEAD)) {
0690 if (tp->linger2 >= 0) {
0691 const int tmo = tcp_fin_time(sk) - TCP_TIMEWAIT_LEN;
0692
0693 if (tmo > 0) {
0694 tcp_time_wait(sk, TCP_FIN_WAIT2, tmo);
0695 goto out;
0696 }
0697 }
0698 tcp_send_active_reset(sk, GFP_ATOMIC);
0699 goto death;
0700 }
0701
0702 if (!sock_flag(sk, SOCK_KEEPOPEN) ||
0703 ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)))
0704 goto out;
0705
0706 elapsed = keepalive_time_when(tp);
0707
0708
0709 if (tp->packets_out || !tcp_write_queue_empty(sk))
0710 goto resched;
0711
0712 elapsed = keepalive_time_elapsed(tp);
0713
0714 if (elapsed >= keepalive_time_when(tp)) {
0715
0716
0717
0718 if ((icsk->icsk_user_timeout != 0 &&
0719 elapsed >= msecs_to_jiffies(icsk->icsk_user_timeout) &&
0720 icsk->icsk_probes_out > 0) ||
0721 (icsk->icsk_user_timeout == 0 &&
0722 icsk->icsk_probes_out >= keepalive_probes(tp))) {
0723 tcp_send_active_reset(sk, GFP_ATOMIC);
0724 tcp_write_err(sk);
0725 goto out;
0726 }
0727 if (tcp_write_wakeup(sk, LINUX_MIB_TCPKEEPALIVE) <= 0) {
0728 icsk->icsk_probes_out++;
0729 elapsed = keepalive_intvl_when(tp);
0730 } else {
0731
0732
0733
0734 elapsed = TCP_RESOURCE_PROBE_INTERVAL;
0735 }
0736 } else {
0737
0738 elapsed = keepalive_time_when(tp) - elapsed;
0739 }
0740
0741 resched:
0742 inet_csk_reset_keepalive_timer (sk, elapsed);
0743 goto out;
0744
0745 death:
0746 tcp_done(sk);
0747
0748 out:
0749 bh_unlock_sock(sk);
0750 sock_put(sk);
0751 }
0752
0753 static enum hrtimer_restart tcp_compressed_ack_kick(struct hrtimer *timer)
0754 {
0755 struct tcp_sock *tp = container_of(timer, struct tcp_sock, compressed_ack_timer);
0756 struct sock *sk = (struct sock *)tp;
0757
0758 bh_lock_sock(sk);
0759 if (!sock_owned_by_user(sk)) {
0760 if (tp->compressed_ack) {
0761
0762
0763
0764
0765 tp->compressed_ack--;
0766 tcp_send_ack(sk);
0767 }
0768 } else {
0769 if (!test_and_set_bit(TCP_DELACK_TIMER_DEFERRED,
0770 &sk->sk_tsq_flags))
0771 sock_hold(sk);
0772 }
0773 bh_unlock_sock(sk);
0774
0775 sock_put(sk);
0776
0777 return HRTIMER_NORESTART;
0778 }
0779
0780 void tcp_init_xmit_timers(struct sock *sk)
0781 {
0782 inet_csk_init_xmit_timers(sk, &tcp_write_timer, &tcp_delack_timer,
0783 &tcp_keepalive_timer);
0784 hrtimer_init(&tcp_sk(sk)->pacing_timer, CLOCK_MONOTONIC,
0785 HRTIMER_MODE_ABS_PINNED_SOFT);
0786 tcp_sk(sk)->pacing_timer.function = tcp_pace_kick;
0787
0788 hrtimer_init(&tcp_sk(sk)->compressed_ack_timer, CLOCK_MONOTONIC,
0789 HRTIMER_MODE_REL_PINNED_SOFT);
0790 tcp_sk(sk)->compressed_ack_timer.function = tcp_compressed_ack_kick;
0791 }