Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 6385
b: refs/heads/master
c: 1bc0986
h: refs/heads/master
i:
  6383: 95d3b89
v: v3
  • Loading branch information
Ian McDonald authored and David S. Miller committed Aug 29, 2005
1 parent 29c59ea commit 5f35dd0
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 42 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: bf0ff9e578ba7dd8331005f00ad7310122011f43
refs/heads/master: 1bc0986957b63a2fbbc46ab95d3d1d72830bda83
2 changes: 1 addition & 1 deletion trunk/include/linux/dccp.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ struct dccp_sock {
__u64 dccps_gsr;
__u64 dccps_gar;
unsigned long dccps_service;
unsigned long dccps_timestamp_time;
struct timeval dccps_timestamp_time;
__u32 dccps_timestamp_echo;
__u32 dccps_avg_packet_size;
unsigned long dccps_ndp_count;
Expand Down
12 changes: 2 additions & 10 deletions trunk/net/dccp/ccids/ccid3.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* net/dccp/ccids/ccid3.c
*
* Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand.
* Copyright (c) 2005 Ian McDonald <iam4@cs.waikato.ac.nz>
*
* An implementation of the DCCP protocol
*
* This code has been developed by the University of Waikato WAND
* research group. For further information please see http://www.wand.net.nz/
* or e-mail Ian McDonald - iam4@cs.waikato.ac.nz
*
* This code also uses code from Lulea University, rereleased as GPL by its
* authors:
Expand Down Expand Up @@ -174,14 +174,6 @@ static inline void timeval_fix(struct timeval *tv)
}
}

/* returns the difference in usecs between timeval passed in and current time */
static inline u32 now_delta(struct timeval tv) {
struct timeval now;

do_gettimeofday(&now);
return ((now.tv_sec-tv.tv_sec)*1000000+now.tv_usec-tv.tv_usec);
}

#define CALCX_ARRSIZE 500

#define CALCX_SPLIT 50000
Expand Down Expand Up @@ -1110,7 +1102,7 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
struct ccid3_options_received *opt_recv;
struct dccp_tx_hist_entry *packet;
unsigned long next_tmout;
u16 t_elapsed;
u32 t_elapsed;
u32 pinv;
u32 x_recv;
u32 r_sample;
Expand Down
19 changes: 17 additions & 2 deletions trunk/net/dccp/dccp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* net/dccp/dccp.h
*
* An implementation of the DCCP protocol
* Arnaldo Carvalho de Melo <acme@conectiva.com.br>
* Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
* Copyright (c) 2005 Ian McDonald <iam4@cs.waikato.ac.nz>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -404,6 +405,7 @@ extern struct socket *dccp_ctl_socket;
* @dccpap_ack_nonce - the one-bit sum of the ECN Nonces for all State 0.
*
* @dccpap_buf_len - circular buffer length
* @dccpap_time - the time in usecs
* @dccpap_buf - circular buffer of acknowledgeable packets
*/
struct dccp_ackpkts {
Expand All @@ -416,7 +418,7 @@ struct dccp_ackpkts {
unsigned int dccpap_buf_vector_len;
unsigned int dccpap_ack_vector_len;
unsigned int dccpap_buf_len;
unsigned long dccpap_time;
struct timeval dccpap_time;
u8 dccpap_buf_nonce;
u8 dccpap_ack_nonce;
u8 dccpap_buf[0];
Expand All @@ -430,6 +432,19 @@ extern int dccp_ackpkts_add(struct dccp_ackpkts *ap, u64 ackno, u8 state);
extern void dccp_ackpkts_check_rcv_ackno(struct dccp_ackpkts *ap,
struct sock *sk, u64 ackno);

/*
* Returns the difference in usecs between timeval
* passed in and current time
*/
static inline u32 now_delta(struct timeval tv)
{
struct timeval now;

do_gettimeofday(&now);
return (now.tv_sec - tv.tv_sec) * USEC_PER_SEC +
(now.tv_usec - tv.tv_usec);
}

#ifdef CONFIG_IP_DCCP_DEBUG
extern void dccp_ackvector_print(const u64 ackno,
const unsigned char *vector, int len);
Expand Down
87 changes: 59 additions & 28 deletions trunk/net/dccp/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* net/dccp/options.c
*
* An implementation of the DCCP protocol
* Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
* Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
* Copyright (c) 2005 Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
* Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
* Copyright (c) 2005 Ian McDonald <iam4@cs.waikato.ac.nz>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -138,44 +139,53 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
opt_recv->dccpor_timestamp = ntohl(*(u32 *)value);

dp->dccps_timestamp_echo = opt_recv->dccpor_timestamp;
dp->dccps_timestamp_time = jiffies;
do_gettimeofday(&dp->dccps_timestamp_time);

dccp_pr_debug("%sTIMESTAMP=%u, ackno=%llu\n",
debug_prefix, opt_recv->dccpor_timestamp,
(unsigned long long)
DCCP_SKB_CB(skb)->dccpd_ack_seq);
break;
case DCCPO_TIMESTAMP_ECHO:
if (len < 4 || len > 8)
if (len != 4 && len != 6 && len != 8)
goto out_invalid_option;

opt_recv->dccpor_timestamp_echo = ntohl(*(u32 *)value);

dccp_pr_debug("%sTIMESTAMP_ECHO=%u, len=%d, ackno=%llu, "
"diff=%u\n",
dccp_pr_debug("%sTIMESTAMP_ECHO=%u, len=%d, ackno=%llu, ",
debug_prefix,
opt_recv->dccpor_timestamp_echo,
len + 2,
(unsigned long long)
DCCP_SKB_CB(skb)->dccpd_ack_seq,
(tcp_time_stamp -
opt_recv->dccpor_timestamp_echo));

opt_recv->dccpor_elapsed_time =
dccp_decode_value_var(value + 4,
len - 4);
dccp_pr_debug("%sTIMESTAMP_ECHO ELAPSED_TIME=%d\n",
DCCP_SKB_CB(skb)->dccpd_ack_seq);

if (len > 4) {
if (len == 6)
opt_recv->dccpor_elapsed_time =
ntohs(*(u16 *)(value + 4));
else
opt_recv->dccpor_elapsed_time =
ntohl(*(u32 *)(value + 4));

dccp_pr_debug("%sTIMESTAMP_ECHO ELAPSED_TIME=%d\n",
debug_prefix,
opt_recv->dccpor_elapsed_time);
}
break;
case DCCPO_ELAPSED_TIME:
if (len > 4)
if (len != 2 && len != 4)
goto out_invalid_option;

if (pkt_type == DCCP_PKT_DATA)
continue;
opt_recv->dccpor_elapsed_time =
dccp_decode_value_var(value, len);

if (len == 2)
opt_recv->dccpor_elapsed_time =
ntohs(*(u16 *)value);
else
opt_recv->dccpor_elapsed_time =
ntohl(*(u32 *)value);

dccp_pr_debug("%sELAPSED_TIME=%d\n", debug_prefix,
opt_recv->dccpor_elapsed_time);
break;
Expand Down Expand Up @@ -309,8 +319,7 @@ void dccp_insert_option_elapsed_time(struct sock *sk,
const int len = 2 + elapsed_time_len;
unsigned char *to;

/* If elapsed_time == 0... */
if (elapsed_time_len == 2)
if (elapsed_time_len == 0)
return;

if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN) {
Expand All @@ -325,7 +334,13 @@ void dccp_insert_option_elapsed_time(struct sock *sk,
*to++ = DCCPO_ELAPSED_TIME;
*to++ = len;

dccp_encode_value_var(elapsed_time, to, elapsed_time_len);
if (elapsed_time_len == 2) {
const u16 var16 = htons((u16)elapsed_time);
memcpy(to, &var16, 2);
} else {
const u32 var32 = htonl(elapsed_time);
memcpy(to, &var32, 4);
}

dccp_pr_debug("%sELAPSED_TIME=%u, len=%d, seqno=%llu\n",
debug_prefix, elapsed_time,
Expand All @@ -344,7 +359,7 @@ static void dccp_insert_option_ack_vector(struct sock *sk, struct sk_buff *skb)
#endif
struct dccp_ackpkts *ap = dp->dccps_hc_rx_ackpkts;
int len = ap->dccpap_buf_vector_len + 2;
const u32 elapsed_time = jiffies_to_usecs(jiffies - ap->dccpap_time) / 10;
const u32 elapsed_time = now_delta(ap->dccpap_time) / 10;
unsigned char *to, *from;

if (elapsed_time != 0)
Expand Down Expand Up @@ -414,7 +429,15 @@ static void dccp_insert_option_ack_vector(struct sock *sk, struct sk_buff *skb)
static inline void dccp_insert_option_timestamp(struct sock *sk,
struct sk_buff *skb)
{
const u32 now = htonl(tcp_time_stamp);
struct timeval tv;
u32 now;

do_gettimeofday(&tv);
now = (tv.tv_sec * USEC_PER_SEC + tv.tv_usec) / 10;
/* yes this will overflow but that is the point as we want a
* 10 usec 32 bit timer which mean it wraps every 11.9 hours */

now = htonl(now);
dccp_insert_option(sk, skb, DCCPO_TIMESTAMP, &now, sizeof(now));
}

Expand All @@ -427,8 +450,7 @@ static void dccp_insert_option_timestamp_echo(struct sock *sk,
"CLIENT TX opt: " : "server TX opt: ";
#endif
u32 tstamp_echo;
const u32 elapsed_time = jiffies_to_usecs(jiffies -
dp->dccps_timestamp_time) / 10;
const u32 elapsed_time = now_delta(dp->dccps_timestamp_time) / 10;
const int elapsed_time_len = dccp_elapsed_time_len(elapsed_time);
const int len = 6 + elapsed_time_len;
unsigned char *to;
Expand All @@ -448,15 +470,23 @@ static void dccp_insert_option_timestamp_echo(struct sock *sk,
tstamp_echo = htonl(dp->dccps_timestamp_echo);
memcpy(to, &tstamp_echo, 4);
to += 4;
dccp_encode_value_var(elapsed_time, to, elapsed_time_len);

if (elapsed_time_len == 2) {
const u16 var16 = htons((u16)elapsed_time);
memcpy(to, &var16, 2);
} else if (elapsed_time_len == 4) {
const u32 var32 = htonl(elapsed_time);
memcpy(to, &var32, 4);
}

dccp_pr_debug("%sTIMESTAMP_ECHO=%u, len=%d, seqno=%llu\n",
debug_prefix, dp->dccps_timestamp_echo,
len,
(unsigned long long) DCCP_SKB_CB(skb)->dccpd_seq);

dp->dccps_timestamp_echo = 0;
dp->dccps_timestamp_time = 0;
dp->dccps_timestamp_time.tv_sec = 0;
dp->dccps_timestamp_time.tv_usec = 0;
}

void dccp_insert_options(struct sock *sk, struct sk_buff *skb)
Expand Down Expand Up @@ -514,7 +544,8 @@ struct dccp_ackpkts *dccp_ackpkts_alloc(const unsigned int len,
ap->dccpap_ack_seqno = DCCP_MAX_SEQNO + 1;
ap->dccpap_buf_nonce = ap->dccpap_buf_nonce = 0;
ap->dccpap_ack_ptr = 0;
ap->dccpap_time = 0;
ap->dccpap_time.tv_sec = 0;
ap->dccpap_time.tv_usec = 0;
ap->dccpap_buf_vector_len = ap->dccpap_ack_vector_len = 0;
}

Expand Down Expand Up @@ -665,7 +696,7 @@ int dccp_ackpkts_add(struct dccp_ackpkts *ap, u64 ackno, u8 state)
}

ap->dccpap_buf_ackno = ackno;
ap->dccpap_time = jiffies;
do_gettimeofday(&ap->dccpap_time);
out:
dccp_pr_debug("");
dccp_ackpkts_print(ap);
Expand Down

0 comments on commit 5f35dd0

Please sign in to comment.