aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/dccp/dccp.h10
-rw-r--r--net/dccp/input.c40
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 */
80extern int sysctl_dccp_request_retries; 84extern int sysctl_dccp_request_retries;
81extern int sysctl_dccp_retries1; 85extern int sysctl_dccp_retries1;
@@ -292,6 +296,8 @@ extern int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr,
292extern int dccp_send_reset(struct sock *sk, enum dccp_reset_codes code); 296extern int dccp_send_reset(struct sock *sk, enum dccp_reset_codes code);
293extern void dccp_send_close(struct sock *sk, const int active); 297extern void dccp_send_close(struct sock *sk, const int active);
294extern int dccp_invalid_packet(struct sk_buff *skb); 298extern int dccp_invalid_packet(struct sk_buff *skb);
299extern u32 dccp_sample_rtt(struct sock *sk, struct timeval *t_recv,
300 struct timeval *t_history);
295 301
296static inline int dccp_bad_service_code(const struct sock *sk, 302static 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
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);