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 | |
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')
-rw-r--r-- | net/dccp/dccp.h | 10 | ||||
-rw-r--r-- | net/dccp/input.c | 40 |
2 files changed, 48 insertions, 2 deletions
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h index 292f18ef4f61..d8ad27bfe01a 100644 --- a/net/dccp/dccp.h +++ b/net/dccp/dccp.h | |||
@@ -71,11 +71,15 @@ extern void dccp_time_wait(struct sock *sk, int state, int timeo); | |||
71 | /* RFC 1122, 4.2.3.1 initial RTO value */ | 71 | /* RFC 1122, 4.2.3.1 initial RTO value */ |
72 | #define DCCP_TIMEOUT_INIT ((unsigned)(3 * HZ)) | 72 | #define DCCP_TIMEOUT_INIT ((unsigned)(3 * HZ)) |
73 | 73 | ||
74 | #define DCCP_RTO_MAX ((unsigned)(120 * HZ)) /* FIXME: using TCP value */ | ||
75 | |||
76 | /* bounds for sampled RTT values from packet exchanges (in usec) */ | ||
77 | #define DCCP_SANE_RTT_MIN 100 | ||
78 | #define DCCP_SANE_RTT_MAX (4 * USEC_PER_SEC) | ||
79 | |||
74 | /* Maximal interval between probes for local resources. */ | 80 | /* Maximal interval between probes for local resources. */ |
75 | #define DCCP_RESOURCE_PROBE_INTERVAL ((unsigned)(HZ / 2U)) | 81 | #define DCCP_RESOURCE_PROBE_INTERVAL ((unsigned)(HZ / 2U)) |
76 | 82 | ||
77 | #define DCCP_RTO_MAX ((unsigned)(120 * HZ)) /* FIXME: using TCP value */ | ||
78 | |||
79 | /* sysctl variables for DCCP */ | 83 | /* sysctl variables for DCCP */ |
80 | extern int sysctl_dccp_request_retries; | 84 | extern int sysctl_dccp_request_retries; |
81 | extern int sysctl_dccp_retries1; | 85 | extern int sysctl_dccp_retries1; |
@@ -292,6 +296,8 @@ extern int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, | |||
292 | extern int dccp_send_reset(struct sock *sk, enum dccp_reset_codes code); | 296 | extern int dccp_send_reset(struct sock *sk, enum dccp_reset_codes code); |
293 | extern void dccp_send_close(struct sock *sk, const int active); | 297 | extern void dccp_send_close(struct sock *sk, const int active); |
294 | extern int dccp_invalid_packet(struct sk_buff *skb); | 298 | extern int dccp_invalid_packet(struct sk_buff *skb); |
299 | extern u32 dccp_sample_rtt(struct sock *sk, struct timeval *t_recv, | ||
300 | struct timeval *t_history); | ||
295 | 301 | ||
296 | static inline int dccp_bad_service_code(const struct sock *sk, | 302 | static inline int dccp_bad_service_code(const struct sock *sk, |
297 | const __be32 service) | 303 | const __be32 service) |
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); | ||