diff options
author | Gerrit Renker <gerrit@erg.abdn.ac.uk> | 2007-03-20 14:23:18 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-04-26 01:27:00 -0400 |
commit | 4712a792ee661921374c163eb6a4d06e33fd305f (patch) | |
tree | 0c5ecf7973a195bff36101904417bb7b90fd18aa /net/dccp/input.c | |
parent | 0c150efb280986db7958cf2a559b91d826241e59 (diff) |
[DCCP]: Provide function for RTT sampling
A recurring problem, in particular in the CCID code, is that RTT samples
from packets with timestamp echo and elapsed time options need to be taken.
This service is provided via a new function dccp_sample_rtt in this patch.
Furthermore, to protect against `insane' RTT samples, the sampled value
is bounded between 100 microseconds and 4 seconds - for which u32 is sufficient.
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Ian McDonald <ian.mcdonald@jandi.co.nz>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dccp/input.c')
-rw-r--r-- | net/dccp/input.c | 40 |
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 | ||
579 | EXPORT_SYMBOL_GPL(dccp_rcv_state_process); | 579 | EXPORT_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 | */ | ||
588 | u32 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 | |||
619 | EXPORT_SYMBOL_GPL(dccp_sample_rtt); | ||