aboutsummaryrefslogtreecommitdiffstats
path: root/net/dccp/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/dccp/input.c')
-rw-r--r--net/dccp/input.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/net/dccp/input.c b/net/dccp/input.c
index a1900157e2d7..bd578c87b2e7 100644
--- a/net/dccp/input.c
+++ b/net/dccp/input.c
@@ -577,3 +577,43 @@ discard:
577} 577}
578 578
579EXPORT_SYMBOL_GPL(dccp_rcv_state_process); 579EXPORT_SYMBOL_GPL(dccp_rcv_state_process);
580
581/**
582 * dccp_sample_rtt - Sample RTT from packet exchange
583 *
584 * @sk: connected dccp_sock
585 * @t_recv: receive timestamp of packet with timestamp echo
586 * @t_hist: packet history timestamp or NULL
587 */
588u32 dccp_sample_rtt(struct sock *sk, struct timeval *t_recv,
589 struct timeval *t_hist)
590{
591 struct dccp_sock *dp = dccp_sk(sk);
592 struct dccp_options_received *or = &dp->dccps_options_received;
593 suseconds_t delta;
594
595 if (t_hist == NULL) {
596 if (!or->dccpor_timestamp_echo) {
597 DCCP_WARN("packet without timestamp echo\n");
598 return DCCP_SANE_RTT_MAX;
599 }
600 timeval_sub_usecs(t_recv, or->dccpor_timestamp_echo * 10);
601 delta = timeval_usecs(t_recv);
602 } else
603 delta = timeval_delta(t_recv, t_hist);
604
605 delta -= or->dccpor_elapsed_time * 10; /* either set or 0 */
606
607 if (unlikely(delta <= 0)) {
608 DCCP_WARN("unusable RTT sample %ld, using min\n", (long)delta);
609 return DCCP_SANE_RTT_MIN;
610 }
611 if (unlikely(delta - (suseconds_t)DCCP_SANE_RTT_MAX > 0)) {
612 DCCP_WARN("RTT sample %ld too large, using max\n", (long)delta);
613 return DCCP_SANE_RTT_MAX;
614 }
615
616 return delta;
617}
618
619EXPORT_SYMBOL_GPL(dccp_sample_rtt);