Commit f7456642 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

tcp: add tcp_ld_RTO_revert() helper

RFC 6069 logic has been implemented for IPv4 only so far,
right in the middle of tcp_v4_err() and was error prone.

Move this code to one helper, to make tcp_v4_err() more
readable and to eventually expand RFC 6069 to IPv6 in
the future.

Also perform sock_owned_by_user() check a bit sooner.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Acked-by: default avatarNeal Cardwell <ncardwell@google.com>
Tested-by: default avatarNeal Cardwell <ncardwell@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d6a3511b
...@@ -403,6 +403,45 @@ void tcp_req_err(struct sock *sk, u32 seq, bool abort) ...@@ -403,6 +403,45 @@ void tcp_req_err(struct sock *sk, u32 seq, bool abort)
} }
EXPORT_SYMBOL(tcp_req_err); EXPORT_SYMBOL(tcp_req_err);
/* TCP-LD (RFC 6069) logic */
static void tcp_ld_RTO_revert(struct sock *sk, u32 seq)
{
struct inet_connection_sock *icsk = inet_csk(sk);
struct tcp_sock *tp = tcp_sk(sk);
struct sk_buff *skb;
s32 remaining;
u32 delta_us;
if (sock_owned_by_user(sk))
return;
if (seq != tp->snd_una || !icsk->icsk_retransmits ||
!icsk->icsk_backoff)
return;
skb = tcp_rtx_queue_head(sk);
if (WARN_ON_ONCE(!skb))
return;
icsk->icsk_backoff--;
icsk->icsk_rto = tp->srtt_us ? __tcp_set_rto(tp) : TCP_TIMEOUT_INIT;
icsk->icsk_rto = inet_csk_rto_backoff(icsk, TCP_RTO_MAX);
tcp_mstamp_refresh(tp);
delta_us = (u32)(tp->tcp_mstamp - tcp_skb_timestamp_us(skb));
remaining = icsk->icsk_rto - usecs_to_jiffies(delta_us);
if (remaining > 0) {
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
remaining, TCP_RTO_MAX);
} else {
/* RTO revert clocked out retransmission.
* Will retransmit now.
*/
tcp_retransmit_timer(sk);
}
}
/* /*
* This routine is called by the ICMP module when it gets some * This routine is called by the ICMP module when it gets some
* sort of error condition. If err < 0 then the socket should * sort of error condition. If err < 0 then the socket should
...@@ -423,17 +462,13 @@ int tcp_v4_err(struct sk_buff *icmp_skb, u32 info) ...@@ -423,17 +462,13 @@ int tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
{ {
const struct iphdr *iph = (const struct iphdr *)icmp_skb->data; const struct iphdr *iph = (const struct iphdr *)icmp_skb->data;
struct tcphdr *th = (struct tcphdr *)(icmp_skb->data + (iph->ihl << 2)); struct tcphdr *th = (struct tcphdr *)(icmp_skb->data + (iph->ihl << 2));
struct inet_connection_sock *icsk;
struct tcp_sock *tp; struct tcp_sock *tp;
struct inet_sock *inet; struct inet_sock *inet;
const int type = icmp_hdr(icmp_skb)->type; const int type = icmp_hdr(icmp_skb)->type;
const int code = icmp_hdr(icmp_skb)->code; const int code = icmp_hdr(icmp_skb)->code;
struct sock *sk; struct sock *sk;
struct sk_buff *skb;
struct request_sock *fastopen; struct request_sock *fastopen;
u32 seq, snd_una; u32 seq, snd_una;
s32 remaining;
u32 delta_us;
int err; int err;
struct net *net = dev_net(icmp_skb->dev); struct net *net = dev_net(icmp_skb->dev);
...@@ -476,7 +511,6 @@ int tcp_v4_err(struct sk_buff *icmp_skb, u32 info) ...@@ -476,7 +511,6 @@ int tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
goto out; goto out;
} }
icsk = inet_csk(sk);
tp = tcp_sk(sk); tp = tcp_sk(sk);
/* XXX (TFO) - tp->snd_una should be ISN (tcp_create_openreq_child() */ /* XXX (TFO) - tp->snd_una should be ISN (tcp_create_openreq_child() */
fastopen = rcu_dereference(tp->fastopen_rsk); fastopen = rcu_dereference(tp->fastopen_rsk);
...@@ -521,41 +555,12 @@ int tcp_v4_err(struct sk_buff *icmp_skb, u32 info) ...@@ -521,41 +555,12 @@ int tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
} }
err = icmp_err_convert[code].errno; err = icmp_err_convert[code].errno;
/* check if icmp_skb allows revert of backoff /* check if this ICMP message allows revert of backoff.
* (see draft-zimmermann-tcp-lcd) */ * (see RFC 6069)
if (code != ICMP_NET_UNREACH && code != ICMP_HOST_UNREACH) */
break; if (!fastopen &&
if (seq != tp->snd_una || !icsk->icsk_retransmits || (code == ICMP_NET_UNREACH || code == ICMP_HOST_UNREACH))
!icsk->icsk_backoff || fastopen) tcp_ld_RTO_revert(sk, seq);
break;
if (sock_owned_by_user(sk))
break;
skb = tcp_rtx_queue_head(sk);
if (WARN_ON_ONCE(!skb))
break;
icsk->icsk_backoff--;
icsk->icsk_rto = tp->srtt_us ? __tcp_set_rto(tp) :
TCP_TIMEOUT_INIT;
icsk->icsk_rto = inet_csk_rto_backoff(icsk, TCP_RTO_MAX);
tcp_mstamp_refresh(tp);
delta_us = (u32)(tp->tcp_mstamp - tcp_skb_timestamp_us(skb));
remaining = icsk->icsk_rto -
usecs_to_jiffies(delta_us);
if (remaining > 0) {
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
remaining, TCP_RTO_MAX);
} else {
/* RTO revert clocked out retransmission.
* Will retransmit now */
tcp_retransmit_timer(sk);
}
break; break;
case ICMP_TIME_EXCEEDED: case ICMP_TIME_EXCEEDED:
err = EHOSTUNREACH; err = EHOSTUNREACH;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment