[CCID3]: Reflow to mostly fit under 80 columns

No code changes.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Arnaldo Carvalho de Melo 2005-08-27 03:51:58 -03:00 committed by David S. Miller
parent d6809c12b3
commit 1f2333aea3

View file

@ -142,14 +142,16 @@ static const char *ccid3_tx_state_name(enum ccid3_hc_tx_states state)
} }
#endif #endif
static inline void ccid3_hc_tx_set_state(struct sock *sk, enum ccid3_hc_tx_states state) static inline void ccid3_hc_tx_set_state(struct sock *sk,
enum ccid3_hc_tx_states state)
{ {
struct dccp_sock *dp = dccp_sk(sk); struct dccp_sock *dp = dccp_sk(sk);
struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state; enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state;
ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
dccp_role(sk), sk, ccid3_tx_state_name(oldstate), ccid3_tx_state_name(state)); dccp_role(sk), sk, ccid3_tx_state_name(oldstate),
ccid3_tx_state_name(state));
WARN_ON(state == oldstate); WARN_ON(state == oldstate);
hctx->ccid3hctx_state = state; hctx->ccid3hctx_state = state;
} }
@ -785,7 +787,8 @@ static inline void ccid3_calc_new_t_ipi(struct ccid3_hc_tx_sock *hctx)
/* Calculate new delta by delta = min(t_ipi / 2, t_gran / 2) */ /* Calculate new delta by delta = min(t_ipi / 2, t_gran / 2) */
static inline void ccid3_calc_new_delta(struct ccid3_hc_tx_sock *hctx) static inline void ccid3_calc_new_delta(struct ccid3_hc_tx_sock *hctx)
{ {
hctx->ccid3hctx_delta = min_t(u32, hctx->ccid3hctx_t_ipi / 2, TFRC_OPSYS_HALF_TIME_GRAN); hctx->ccid3hctx_delta = min_t(u32, hctx->ccid3hctx_t_ipi / 2,
TFRC_OPSYS_HALF_TIME_GRAN);
} }
@ -804,20 +807,25 @@ static void ccid3_hc_tx_update_x(struct sock *sk)
struct dccp_sock *dp = dccp_sk(sk); struct dccp_sock *dp = dccp_sk(sk);
struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
if (hctx->ccid3hctx_p >= TFRC_SMALLEST_P) { /* to avoid large error in calcX */ /* To avoid large error in calcX */
if (hctx->ccid3hctx_p >= TFRC_SMALLEST_P) {
hctx->ccid3hctx_x_calc = ccid3_calc_x(hctx->ccid3hctx_s, hctx->ccid3hctx_x_calc = ccid3_calc_x(hctx->ccid3hctx_s,
hctx->ccid3hctx_rtt, hctx->ccid3hctx_rtt,
hctx->ccid3hctx_p); hctx->ccid3hctx_p);
hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_calc, 2 * hctx->ccid3hctx_x_recv), hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_calc,
hctx->ccid3hctx_s / TFRC_MAX_BACK_OFF_TIME); 2 * hctx->ccid3hctx_x_recv),
(hctx->ccid3hctx_s /
TFRC_MAX_BACK_OFF_TIME));
} else if (now_delta(hctx->ccid3hctx_t_ld) >= hctx->ccid3hctx_rtt) { } else if (now_delta(hctx->ccid3hctx_t_ld) >= hctx->ccid3hctx_rtt) {
u32 rtt = hctx->ccid3hctx_rtt; u32 rtt = hctx->ccid3hctx_rtt;
if (rtt < 10) { if (rtt < 10) {
rtt = 10; rtt = 10;
} /* avoid divide by zero below */ } /* avoid divide by zero below */
hctx->ccid3hctx_x = max_t(u32, min_t(u32, 2 * hctx->ccid3hctx_x_recv, 2 * hctx->ccid3hctx_x), hctx->ccid3hctx_x = max_t(u32, min_t(u32, 2 * hctx->ccid3hctx_x_recv,
(hctx->ccid3hctx_s * 100000) / (rtt / 10)); 2 * hctx->ccid3hctx_x),
((hctx->ccid3hctx_s * 100000) /
(rtt / 10)));
/* Using 100000 and 10 to avoid 32 bit overflow for jumbo frames */ /* Using 100000 and 10 to avoid 32 bit overflow for jumbo frames */
do_gettimeofday(&hctx->ccid3hctx_t_ld); do_gettimeofday(&hctx->ccid3hctx_t_ld);
} }
@ -840,7 +848,8 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
if (sock_owned_by_user(sk)) { if (sock_owned_by_user(sk)) {
/* Try again later. */ /* Try again later. */
/* XXX: set some sensible MIB */ /* XXX: set some sensible MIB */
sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, jiffies + HZ / 5); sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
jiffies + HZ / 5);
goto out; goto out;
} }
@ -858,27 +867,38 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
case TFRC_SSTATE_NO_FBACK: case TFRC_SSTATE_NO_FBACK:
/* Halve send rate */ /* Halve send rate */
hctx->ccid3hctx_x /= 2; hctx->ccid3hctx_x /= 2;
if (hctx->ccid3hctx_x < (hctx->ccid3hctx_s / TFRC_MAX_BACK_OFF_TIME)) if (hctx->ccid3hctx_x <
hctx->ccid3hctx_x = hctx->ccid3hctx_s / TFRC_MAX_BACK_OFF_TIME; (hctx->ccid3hctx_s / TFRC_MAX_BACK_OFF_TIME))
hctx->ccid3hctx_x = (hctx->ccid3hctx_s /
TFRC_MAX_BACK_OFF_TIME);
ccid3_pr_debug("%s, sk=%p, state=%s, updated tx rate to %d bytes/s\n", ccid3_pr_debug("%s, sk=%p, state=%s, updated tx rate to %d "
dccp_role(sk), sk, ccid3_tx_state_name(hctx->ccid3hctx_state), "bytes/s\n",
dccp_role(sk), sk,
ccid3_tx_state_name(hctx->ccid3hctx_state),
hctx->ccid3hctx_x); hctx->ccid3hctx_x);
next_tmout = max_t(u32, 2 * (hctx->ccid3hctx_s * 100000) next_tmout = max_t(u32, 2 * (hctx->ccid3hctx_s * 100000) / (hctx->ccid3hctx_x / 10),
/ (hctx->ccid3hctx_x / 10), TFRC_INITIAL_TIMEOUT); TFRC_INITIAL_TIMEOUT);
/* do above maths with 100000 and 10 to prevent overflow on 32 bit */ /* do above maths with 100000 and 10 to prevent overflow on 32 bit */
/* FIXME - not sure above calculation is correct. See section 5 of CCID3 11 /*
* should adjust tx_t_ipi and double that to achieve it really */ * FIXME - not sure above calculation is correct. See section
* 5 of CCID3 11 should adjust tx_t_ipi and double that to
* achieve it really
*/
break; break;
case TFRC_SSTATE_FBACK: case TFRC_SSTATE_FBACK:
/* Check if IDLE since last timeout and recv rate is less than 4 packets per RTT */ /*
* Check if IDLE since last timeout and recv rate is less than
* 4 packets per RTT
*/
rtt = hctx->ccid3hctx_rtt; rtt = hctx->ccid3hctx_rtt;
if (rtt < 10) if (rtt < 10)
rtt = 10; rtt = 10;
/* stop divide by zero below */ /* stop divide by zero below */
if (!hctx->ccid3hctx_idle || (hctx->ccid3hctx_x_recv >= if (!hctx->ccid3hctx_idle ||
4 * (hctx->ccid3hctx_s * 100000) / (rtt / 10))) { (hctx->ccid3hctx_x_recv >= 4 * (hctx->ccid3hctx_s * 100000) / (rtt / 10))) {
ccid3_pr_debug("%s, sk=%p, state=%s, not idle\n", dccp_role(sk), sk, ccid3_pr_debug("%s, sk=%p, state=%s, not idle\n",
dccp_role(sk), sk,
ccid3_tx_state_name(hctx->ccid3hctx_state)); ccid3_tx_state_name(hctx->ccid3hctx_state));
/* Halve sending rate */ /* Halve sending rate */
@ -887,7 +907,8 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
* Else * Else
* X_recv = X_calc / 4; * X_recv = X_calc / 4;
*/ */
BUG_ON(hctx->ccid3hctx_p >= TFRC_SMALLEST_P && hctx->ccid3hctx_x_calc == 0); BUG_ON(hctx->ccid3hctx_p >= TFRC_SMALLEST_P &&
hctx->ccid3hctx_x_calc == 0);
/* check also if p is zero -> x_calc is infinity? */ /* check also if p is zero -> x_calc is infinity? */
if (hctx->ccid3hctx_p < TFRC_SMALLEST_P || if (hctx->ccid3hctx_p < TFRC_SMALLEST_P ||
@ -916,7 +937,7 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
} }
sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
jiffies + max_t(u32, 1, usecs_to_jiffies(next_tmout))); jiffies + max_t(u32, 1, usecs_to_jiffies(next_tmout)));
hctx->ccid3hctx_idle = 1; hctx->ccid3hctx_idle = 1;
out: out:
bh_unlock_sock(sk); bh_unlock_sock(sk);
@ -933,24 +954,27 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
long delay; long delay;
int rc = -ENOTCONN; int rc = -ENOTCONN;
// ccid3_pr_debug("%s, sk=%p, skb=%p, len=%d\n", dccp_role(sk), sk, skb, len); /* Check if pure ACK or Terminating*/
/* /*
* check if pure ACK or Terminating */ * XXX: We only call this function for DATA and DATAACK, on, these
/* XXX: We only call this function for DATA and DATAACK, on, these packets can have * packets can have zero length, but why the comment about "pure ACK"?
* zero length, but why the comment about "pure ACK"?
*/ */
if (hctx == NULL || len == 0 || hctx->ccid3hctx_state == TFRC_SSTATE_TERM) if (hctx == NULL || len == 0 ||
hctx->ccid3hctx_state == TFRC_SSTATE_TERM)
goto out; goto out;
/* See if last packet allocated was not sent */ /* See if last packet allocated was not sent */
new_packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist); new_packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist);
if (new_packet == NULL || new_packet->dccphtx_sent) { if (new_packet == NULL || new_packet->dccphtx_sent) {
new_packet = dccp_tx_hist_entry_new(ccid3_tx_hist, SLAB_ATOMIC); new_packet = dccp_tx_hist_entry_new(ccid3_tx_hist,
SLAB_ATOMIC);
rc = -ENOBUFS; rc = -ENOBUFS;
if (new_packet == NULL) { if (new_packet == NULL) {
ccid3_pr_debug("%s, sk=%p, not enough mem to add " ccid3_pr_debug("%s, sk=%p, not enough mem to add "
"to history, send refused\n", dccp_role(sk), sk); "to history, send refused\n",
dccp_role(sk), sk);
goto out; goto out;
} }
@ -961,12 +985,13 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
switch (hctx->ccid3hctx_state) { switch (hctx->ccid3hctx_state) {
case TFRC_SSTATE_NO_SENT: case TFRC_SSTATE_NO_SENT:
ccid3_pr_debug("%s, sk=%p, first packet(%llu)\n", dccp_role(sk), sk, ccid3_pr_debug("%s, sk=%p, first packet(%llu)\n",
dp->dccps_gss); dccp_role(sk), sk, dp->dccps_gss);
hctx->ccid3hctx_no_feedback_timer.function = ccid3_hc_tx_no_feedback_timer; hctx->ccid3hctx_no_feedback_timer.function = ccid3_hc_tx_no_feedback_timer;
hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk; hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk;
sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, jiffies + usecs_to_jiffies(TFRC_INITIAL_TIMEOUT)); sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
jiffies + usecs_to_jiffies(TFRC_INITIAL_TIMEOUT));
hctx->ccid3hctx_last_win_count = 0; hctx->ccid3hctx_last_win_count = 0;
hctx->ccid3hctx_t_last_win_count = now; hctx->ccid3hctx_t_last_win_count = now;
ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK);
@ -981,7 +1006,7 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
break; break;
case TFRC_SSTATE_NO_FBACK: case TFRC_SSTATE_NO_FBACK:
case TFRC_SSTATE_FBACK: case TFRC_SSTATE_FBACK:
delay = (now_delta(hctx->ccid3hctx_t_nom) - hctx->ccid3hctx_delta); delay = now_delta(hctx->ccid3hctx_t_nom) - hctx->ccid3hctx_delta;
ccid3_pr_debug("send_packet delay=%ld\n", delay); ccid3_pr_debug("send_packet delay=%ld\n", delay);
delay /= -1000; delay /= -1000;
/* divide by -1000 is to convert to ms and get sign right */ /* divide by -1000 is to convert to ms and get sign right */
@ -1027,41 +1052,35 @@ static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len)
packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist); packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist);
if (packet == NULL) { if (packet == NULL) {
printk(KERN_CRIT "%s: packet doesn't exists in history!\n", __FUNCTION__); printk(KERN_CRIT "%s: packet doesn't exists in "
"history!\n", __FUNCTION__);
return; return;
} }
if (packet->dccphtx_sent) { if (packet->dccphtx_sent) {
printk(KERN_CRIT "%s: no unsent packet in history!\n", __FUNCTION__); printk(KERN_CRIT "%s: no unsent packet in history!\n",
__FUNCTION__);
return; return;
} }
packet->dccphtx_tstamp = now; packet->dccphtx_tstamp = now;
packet->dccphtx_seqno = dp->dccps_gss; packet->dccphtx_seqno = dp->dccps_gss;
#if 0
ccid3_pr_debug("%s, sk=%p, seqno=%llu inserted!\n",
dccp_role(sk), sk, packet->dccphtx_seqno);
#endif
/* /*
* Check if win_count have changed */ * Check if win_count have changed
/* COMPLIANCE_BEGIN * Algorithm in "8.1. Window Counter Valuer" in
* Algorithm in "8.1. Window Counter Valuer" in draft-ietf-dccp-ccid3-11.txt * draft-ietf-dccp-ccid3-11.txt
*/ */
quarter_rtt = now_delta(hctx->ccid3hctx_t_last_win_count) / (hctx->ccid3hctx_rtt / 4); quarter_rtt = now_delta(hctx->ccid3hctx_t_last_win_count) /
(hctx->ccid3hctx_rtt / 4);
if (quarter_rtt > 0) { if (quarter_rtt > 0) {
hctx->ccid3hctx_t_last_win_count = now; hctx->ccid3hctx_t_last_win_count = now;
hctx->ccid3hctx_last_win_count = (hctx->ccid3hctx_last_win_count + hctx->ccid3hctx_last_win_count = (hctx->ccid3hctx_last_win_count +
min_t(unsigned long, quarter_rtt, 5)) % 16; min_t(unsigned long, quarter_rtt, 5)) % 16;
ccid3_pr_debug("%s, sk=%p, window changed from %u to %u!\n", ccid3_pr_debug("%s, sk=%p, window changed from "
"%u to %u!\n",
dccp_role(sk), sk, dccp_role(sk), sk,
packet->dccphtx_ccval, packet->dccphtx_ccval,
hctx->ccid3hctx_last_win_count); hctx->ccid3hctx_last_win_count);
} }
/* COMPLIANCE_END */
#if 0
ccid3_pr_debug("%s, sk=%p, packet sent (%llu,%u)\n",
dccp_role(sk), sk,
packet->dccphtx_seqno,
packet->dccphtx_ccval);
#endif
hctx->ccid3hctx_idle = 0; hctx->ccid3hctx_idle = 0;
packet->dccphtx_rtt = hctx->ccid3hctx_rtt; packet->dccphtx_rtt = hctx->ccid3hctx_rtt;
packet->dccphtx_sent = 1; packet->dccphtx_sent = 1;
@ -1073,7 +1092,8 @@ static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len)
case TFRC_SSTATE_NO_SENT: case TFRC_SSTATE_NO_SENT:
/* if first wasn't pure ack */ /* if first wasn't pure ack */
if (len != 0) if (len != 0)
printk(KERN_CRIT "%s: %s, First packet sent is noted as a data packet\n", printk(KERN_CRIT "%s: %s, First packet sent is noted "
"as a data packet\n",
__FUNCTION__, dccp_role(sk)); __FUNCTION__, dccp_role(sk));
return; return;
case TFRC_SSTATE_NO_FBACK: case TFRC_SSTATE_NO_FBACK:
@ -1105,16 +1125,13 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
u32 pinv; u32 pinv;
u32 x_recv; u32 x_recv;
u32 r_sample; u32 r_sample;
#if 0
ccid3_pr_debug("%s, sk=%p(%s), skb=%p(%s)\n",
dccp_role(sk), sk, dccp_state_name(sk->sk_state),
skb, dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type));
#endif
if (hctx == NULL) if (hctx == NULL)
return; return;
if (hctx->ccid3hctx_state == TFRC_SSTATE_TERM) { if (hctx->ccid3hctx_state == TFRC_SSTATE_TERM) {
ccid3_pr_debug("%s, sk=%p, received a packet when terminating!\n", dccp_role(sk), sk); ccid3_pr_debug("%s, sk=%p, received a packet when "
"terminating!\n", dccp_role(sk), sk);
return; return;
} }
@ -1141,8 +1158,10 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
packet = dccp_tx_hist_find_entry(&hctx->ccid3hctx_hist, packet = dccp_tx_hist_find_entry(&hctx->ccid3hctx_hist,
DCCP_SKB_CB(skb)->dccpd_ack_seq); DCCP_SKB_CB(skb)->dccpd_ack_seq);
if (packet == NULL) { if (packet == NULL) {
ccid3_pr_debug("%s, sk=%p, seqno %llu(%s) does't exist in history!\n", ccid3_pr_debug("%s, sk=%p, seqno %llu(%s) does't "
dccp_role(sk), sk, DCCP_SKB_CB(skb)->dccpd_ack_seq, "exist in history!\n",
dccp_role(sk), sk,
DCCP_SKB_CB(skb)->dccpd_ack_seq,
dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type));
return; return;
} }
@ -1164,7 +1183,8 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK); ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK);
hctx->ccid3hctx_rtt = r_sample; hctx->ccid3hctx_rtt = r_sample;
} else } else
hctx->ccid3hctx_rtt = (hctx->ccid3hctx_rtt * 9) / 10 + r_sample / 10; hctx->ccid3hctx_rtt = (hctx->ccid3hctx_rtt * 9) / 10 +
r_sample / 10;
/* /*
* XXX: this is to avoid a division by zero in ccid3_hc_tx_packet_sent * XXX: this is to avoid a division by zero in ccid3_hc_tx_packet_sent
@ -1173,17 +1193,16 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
if (hctx->ccid3hctx_rtt < 4) if (hctx->ccid3hctx_rtt < 4)
hctx->ccid3hctx_rtt = 4; hctx->ccid3hctx_rtt = 4;
ccid3_pr_debug("%s, sk=%p, New RTT estimate=%uus, r_sample=%us\n", ccid3_pr_debug("%s, sk=%p, New RTT estimate=%uus, "
dccp_role(sk), sk, "r_sample=%us\n", dccp_role(sk), sk,
hctx->ccid3hctx_rtt, hctx->ccid3hctx_rtt, r_sample);
r_sample);
/* Update timeout interval */ /* Update timeout interval */
hctx->ccid3hctx_t_rto = max_t(u32, 4 * hctx->ccid3hctx_rtt, hctx->ccid3hctx_t_rto = max_t(u32, 4 * hctx->ccid3hctx_rtt,
USEC_PER_SEC); USEC_PER_SEC);
/* Update receive rate */ /* Update receive rate */
hctx->ccid3hctx_x_recv = x_recv; /* x_recv in bytes per second */ hctx->ccid3hctx_x_recv = x_recv;/* X_recv in bytes per sec */
/* Update loss event rate */ /* Update loss event rate */
if (pinv == ~0 || pinv == 0) if (pinv == ~0 || pinv == 0)
@ -1193,7 +1212,8 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
if (hctx->ccid3hctx_p < TFRC_SMALLEST_P) { if (hctx->ccid3hctx_p < TFRC_SMALLEST_P) {
hctx->ccid3hctx_p = TFRC_SMALLEST_P; hctx->ccid3hctx_p = TFRC_SMALLEST_P;
ccid3_pr_debug("%s, sk=%p, Smallest p used!\n", dccp_role(sk), sk); ccid3_pr_debug("%s, sk=%p, Smallest p used!\n",
dccp_role(sk), sk);
} }
} }
@ -1220,22 +1240,27 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
&hctx->ccid3hctx_hist, packet); &hctx->ccid3hctx_hist, packet);
if (hctx->ccid3hctx_x < 10) { if (hctx->ccid3hctx_x < 10) {
ccid3_pr_debug("ccid3_hc_tx_packet_recv hctx->ccid3hctx_x < 10\n"); ccid3_pr_debug("ccid3_hc_tx_packet_recv hctx_x < 10\n");
hctx->ccid3hctx_x = 10; hctx->ccid3hctx_x = 10;
} }
/* to prevent divide by zero below */ /* to prevent divide by zero below */
/* Schedule no feedback timer to expire in max(4 * R, 2 * s / X) */ /*
* Schedule no feedback timer to expire in
* max(4 * R, 2 * s / X)
*/
next_tmout = max(hctx->ccid3hctx_t_rto, next_tmout = max(hctx->ccid3hctx_t_rto,
(2 * (hctx->ccid3hctx_s * 100000) / (2 * (hctx->ccid3hctx_s * 100000) /
(hctx->ccid3hctx_x / 10))); (hctx->ccid3hctx_x / 10)));
/* maths with 100000 and 10 is to prevent overflow with 32 bit */ /* maths with 100000 and 10 is to prevent overflow with 32 bit */
ccid3_pr_debug("%s, sk=%p, Scheduled no feedback timer to expire in %lu jiffies (%luus)\n", ccid3_pr_debug("%s, sk=%p, Scheduled no feedback timer to "
dccp_role(sk), sk, usecs_to_jiffies(next_tmout), next_tmout); "expire in %lu jiffies (%luus)\n",
dccp_role(sk), sk,
usecs_to_jiffies(next_tmout), next_tmout);
sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
jiffies + max_t(u32,1,usecs_to_jiffies(next_tmout))); jiffies + max_t(u32, 1, usecs_to_jiffies(next_tmout)));
/* set idle flag */ /* set idle flag */
hctx->ccid3hctx_idle = 1; hctx->ccid3hctx_idle = 1;
@ -1253,14 +1278,16 @@ static void ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb)
const struct dccp_sock *dp = dccp_sk(sk); const struct dccp_sock *dp = dccp_sk(sk);
struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
if (hctx == NULL || !(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)) if (hctx == NULL || !(sk->sk_state == DCCP_OPEN ||
sk->sk_state == DCCP_PARTOPEN))
return; return;
DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count; DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count;
} }
static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option, static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
unsigned char len, u16 idx, unsigned char *value) unsigned char len, u16 idx,
unsigned char *value)
{ {
int rc = 0; int rc = 0;
struct dccp_sock *dp = dccp_sk(sk); struct dccp_sock *dp = dccp_sk(sk);
@ -1283,7 +1310,8 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
switch (option) { switch (option) {
case TFRC_OPT_LOSS_EVENT_RATE: case TFRC_OPT_LOSS_EVENT_RATE:
if (len != 4) { if (len != 4) {
ccid3_pr_debug("%s, sk=%p, invalid len for TFRC_OPT_LOSS_EVENT_RATE\n", ccid3_pr_debug("%s, sk=%p, invalid len for "
"TFRC_OPT_LOSS_EVENT_RATE\n",
dccp_role(sk), sk); dccp_role(sk), sk);
rc = -EINVAL; rc = -EINVAL;
} else { } else {
@ -1303,7 +1331,8 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
break; break;
case TFRC_OPT_RECEIVE_RATE: case TFRC_OPT_RECEIVE_RATE:
if (len != 4) { if (len != 4) {
ccid3_pr_debug("%s, sk=%p, invalid len for TFRC_OPT_RECEIVE_RATE\n", ccid3_pr_debug("%s, sk=%p, invalid len for "
"TFRC_OPT_RECEIVE_RATE\n",
dccp_role(sk), sk); dccp_role(sk), sk);
rc = -EINVAL; rc = -EINVAL;
} else { } else {
@ -1325,7 +1354,8 @@ static int ccid3_hc_tx_init(struct sock *sk)
ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
hctx = dp->dccps_hc_tx_ccid_private = kmalloc(sizeof(*hctx), gfp_any()); hctx = dp->dccps_hc_tx_ccid_private = kmalloc(sizeof(*hctx),
gfp_any());
if (hctx == NULL) if (hctx == NULL)
return -ENOMEM; return -ENOMEM;
@ -1337,8 +1367,10 @@ static int ccid3_hc_tx_init(struct sock *sk)
else else
hctx->ccid3hctx_s = TFRC_STD_PACKET_SIZE; hctx->ccid3hctx_s = TFRC_STD_PACKET_SIZE;
hctx->ccid3hctx_x = hctx->ccid3hctx_s; /* set transmission rate to 1 packet per second */ /* Set transmission rate to 1 packet per second */
hctx->ccid3hctx_rtt = 4; /* See ccid3_hc_tx_packet_sent win_count calculatation */ hctx->ccid3hctx_x = hctx->ccid3hctx_s;
/* See ccid3_hc_tx_packet_sent win_count calculatation */
hctx->ccid3hctx_rtt = 4;
hctx->ccid3hctx_t_rto = USEC_PER_SEC; hctx->ccid3hctx_t_rto = USEC_PER_SEC;
hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT; hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT;
INIT_LIST_HEAD(&hctx->ccid3hctx_hist); INIT_LIST_HEAD(&hctx->ccid3hctx_hist);
@ -1389,14 +1421,16 @@ static const char *ccid3_rx_state_name(enum ccid3_hc_rx_states state)
} }
#endif #endif
static inline void ccid3_hc_rx_set_state(struct sock *sk, enum ccid3_hc_rx_states state) static inline void ccid3_hc_rx_set_state(struct sock *sk,
enum ccid3_hc_rx_states state)
{ {
struct dccp_sock *dp = dccp_sk(sk); struct dccp_sock *dp = dccp_sk(sk);
struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state; enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state;
ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
dccp_role(sk), sk, ccid3_rx_state_name(oldstate), ccid3_rx_state_name(state)); dccp_role(sk), sk, ccid3_rx_state_name(oldstate),
ccid3_rx_state_name(state));
WARN_ON(state == oldstate); WARN_ON(state == oldstate);
hcrx->ccid3hcrx_state = state; hcrx->ccid3hcrx_state = state;
} }
@ -1434,9 +1468,12 @@ static int ccid3_hc_rx_add_hist(struct sock *sk,
num_later++; num_later++;
if (num_later == TFRC_RECV_NUM_LATE_LOSS) { if (num_later == TFRC_RECV_NUM_LATE_LOSS) {
dccp_rx_hist_entry_delete(ccid3_rx_hist, packet); dccp_rx_hist_entry_delete(ccid3_rx_hist,
ccid3_pr_debug("%s, sk=%p, packet(%llu) already lost!\n", packet);
dccp_role(sk), sk, seqno); ccid3_pr_debug("%s, sk=%p, packet"
"(%llu) already lost!\n",
dccp_role(sk), sk,
seqno);
return 1; return 1;
} }
} }
@ -1444,12 +1481,18 @@ static int ccid3_hc_rx_add_hist(struct sock *sk,
if (num_later < TFRC_RECV_NUM_LATE_LOSS) if (num_later < TFRC_RECV_NUM_LATE_LOSS)
dccp_rx_hist_add_entry(&hcrx->ccid3hcrx_hist, dccp_rx_hist_add_entry(&hcrx->ccid3hcrx_hist,
packet); packet);
/* FIXME: else what? should we destroy the packet like above? */ /*
* FIXME: else what? should we destroy the packet
* like above?
*/
} }
} }
trim_history: trim_history:
/* Trim history (remove all packets after the NUM_LATE_LOSS + 1 data packets) */ /*
* Trim history (remove all packets after the NUM_LATE_LOSS + 1
* data packets)
*/
num_later = TFRC_RECV_NUM_LATE_LOSS + 1; num_later = TFRC_RECV_NUM_LATE_LOSS + 1;
if (!list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) { if (!list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) {
@ -1489,15 +1532,18 @@ trim_history:
if (tmp < 0) if (tmp < 0)
tmp += TFRC_WIN_COUNT_LIMIT; tmp += TFRC_WIN_COUNT_LIMIT;
if (tmp > TFRC_WIN_COUNT_PER_RTT + 1) { if (tmp > TFRC_WIN_COUNT_PER_RTT + 1) {
/* we have found a packet older than one rtt /*
* remove the rest */ * We have found a packet older
* than one rtt remove the rest
*/
step = 3; step = 3;
} else /* OK, find next data packet */ } else /* OK, find next data packet */
num_later = 1; num_later = 1;
break; break;
case 3: case 3:
list_del_init(&entry->dccphrx_node); list_del_init(&entry->dccphrx_node);
dccp_rx_hist_entry_delete(ccid3_rx_hist, entry); dccp_rx_hist_entry_delete(ccid3_rx_hist,
entry);
break; break;
} }
} else if (dccp_rx_hist_entry_data_packet(entry)) } else if (dccp_rx_hist_entry_data_packet(entry))
@ -1564,7 +1610,8 @@ static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
u32 x_recv, pinv; u32 x_recv, pinv;
struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
if (hcrx == NULL || !(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)) if (hcrx == NULL || !(sk->sk_state == DCCP_OPEN ||
sk->sk_state == DCCP_PARTOPEN))
return; return;
DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_last_counter; DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_last_counter;
@ -1658,13 +1705,15 @@ static u32 ccid3_hc_rx_calc_first_li(struct sock *sk)
} }
if (step == 0) { if (step == 0) {
printk(KERN_CRIT "%s: %s, sk=%p, packet history contains no data packets!\n", printk(KERN_CRIT "%s: %s, sk=%p, packet history contains no "
"data packets!\n",
__FUNCTION__, dccp_role(sk), sk); __FUNCTION__, dccp_role(sk), sk);
return ~0; return ~0;
} }
if (interval == 0) { if (interval == 0) {
ccid3_pr_debug("%s, sk=%p, Could not find a win_count interval > 0. Defaulting to 1\n", ccid3_pr_debug("%s, sk=%p, Could not find a win_count "
"interval > 0. Defaulting to 1\n",
dccp_role(sk), sk); dccp_role(sk), sk);
interval = 1; interval = 1;
} }
@ -1688,8 +1737,8 @@ found:
fval = (hcrx->ccid3hcrx_s * 100000) / tmp2; fval = (hcrx->ccid3hcrx_s * 100000) / tmp2;
/* do not alter order above or you will get overflow on 32 bit */ /* do not alter order above or you will get overflow on 32 bit */
p = calcx_reverse_lookup(fval); p = calcx_reverse_lookup(fval);
ccid3_pr_debug("%s, sk=%p, receive rate=%u bytes/s, implied loss rate=%u\n",\ ccid3_pr_debug("%s, sk=%p, receive rate=%u bytes/s, implied "
dccp_role(sk), sk, x_recv, p); "loss rate=%u\n", dccp_role(sk), sk, x_recv, p);
if (p == 0) if (p == 0)
return ~0; return ~0;
@ -1704,25 +1753,31 @@ static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss)
struct ccid3_loss_interval_hist_entry *li_entry; struct ccid3_loss_interval_hist_entry *li_entry;
if (seq_loss != DCCP_MAX_SEQNO + 1) { if (seq_loss != DCCP_MAX_SEQNO + 1) {
ccid3_pr_debug("%s, sk=%p, seq_loss=%llu, win_loss=%u, packet loss detected\n", ccid3_pr_debug("%s, sk=%p, seq_loss=%llu, win_loss=%u, "
"packet loss detected\n",
dccp_role(sk), sk, seq_loss, win_loss); dccp_role(sk), sk, seq_loss, win_loss);
if (list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) { if (list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) {
struct ccid3_loss_interval_hist_entry *li_tail = NULL; struct ccid3_loss_interval_hist_entry *li_tail = NULL;
int i; int i;
ccid3_pr_debug("%s, sk=%p, first loss event detected, creating history\n", dccp_role(sk), sk); ccid3_pr_debug("%s, sk=%p, first loss event detected, "
"creating history\n",
dccp_role(sk), sk);
for (i = 0; i <= TFRC_RECV_IVAL_F_LENGTH; ++i) { for (i = 0; i <= TFRC_RECV_IVAL_F_LENGTH; ++i) {
li_entry = ccid3_loss_interval_hist_entry_new(SLAB_ATOMIC); li_entry = ccid3_loss_interval_hist_entry_new(SLAB_ATOMIC);
if (li_entry == NULL) { if (li_entry == NULL) {
ccid3_loss_interval_history_delete(&hcrx->ccid3hcrx_loss_interval_hist); ccid3_loss_interval_history_delete(&hcrx->ccid3hcrx_loss_interval_hist);
ccid3_pr_debug("%s, sk=%p, not enough mem for creating history\n", ccid3_pr_debug("%s, sk=%p, not enough "
"mem for creating "
"history\n",
dccp_role(sk), sk); dccp_role(sk), sk);
return; return;
} }
if (li_tail == NULL) if (li_tail == NULL)
li_tail = li_entry; li_tail = li_entry;
list_add(&li_entry->ccid3lih_node, &hcrx->ccid3hcrx_loss_interval_hist); list_add(&li_entry->ccid3lih_node,
&hcrx->ccid3hcrx_loss_interval_hist);
} }
li_entry->ccid3lih_seqno = seq_loss; li_entry->ccid3lih_seqno = seq_loss;
@ -1772,11 +1827,13 @@ static void ccid3_hc_rx_detect_loss(struct sock *sk)
if (list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) { if (list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) {
/* no loss event have occured yet */ /* no loss event have occured yet */
ccid3_pr_debug("%s, sk=%p, TODO: find a lost data " ccid3_pr_debug("%s, sk=%p, TODO: find a lost data "
"packet by comparing to initial seqno\n", "packet by comparing to initial "
"seqno\n",
dccp_role(sk), sk); dccp_role(sk), sk);
goto out_update_li; goto out_update_li;
} else { } else {
pr_info("%s: %s, sk=%p, ERROR! Less than 4 data packets in history", pr_info("%s: %s, sk=%p, ERROR! Less than 4 data "
"packets in history",
__FUNCTION__, dccp_role(sk), sk); __FUNCTION__, dccp_role(sk), sk);
return; return;
} }
@ -1831,7 +1888,9 @@ static u32 ccid3_hc_rx_calc_i_mean(struct sock *sk)
u32 i_tot1 = 0; u32 i_tot1 = 0;
u32 w_tot = 0; u32 w_tot = 0;
list_for_each_entry_safe(li_entry, li_next, &hcrx->ccid3hcrx_loss_interval_hist, ccid3lih_node) { list_for_each_entry_safe(li_entry, li_next,
&hcrx->ccid3hcrx_loss_interval_hist,
ccid3lih_node) {
if (i < TFRC_RECV_IVAL_F_LENGTH) { if (i < TFRC_RECV_IVAL_F_LENGTH) {
i_tot0 += li_entry->ccid3lih_interval * ccid3_hc_rx_w[i]; i_tot0 += li_entry->ccid3lih_interval * ccid3_hc_rx_w[i];
w_tot += ccid3_hc_rx_w[i]; w_tot += ccid3_hc_rx_w[i];
@ -1845,7 +1904,8 @@ static u32 ccid3_hc_rx_calc_i_mean(struct sock *sk)
} }
if (i != TFRC_RECV_IVAL_F_LENGTH) { if (i != TFRC_RECV_IVAL_F_LENGTH) {
pr_info("%s: %s, sk=%p, ERROR! Missing entry in interval history!\n", pr_info("%s: %s, sk=%p, ERROR! Missing entry in "
"interval history!\n",
__FUNCTION__, dccp_role(sk), sk); __FUNCTION__, dccp_role(sk), sk);
return 0; return 0;
} }
@ -1870,11 +1930,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
u8 win_count; u8 win_count;
u32 p_prev; u32 p_prev;
int ins; int ins;
#if 0
ccid3_pr_debug("%s, sk=%p(%s), skb=%p(%s)\n",
dccp_role(sk), sk, dccp_state_name(sk->sk_state),
skb, dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type));
#endif
if (hcrx == NULL) if (hcrx == NULL)
return; return;
@ -1913,7 +1969,8 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
packet = dccp_rx_hist_entry_new(ccid3_rx_hist, opt_recv->dccpor_ndp, packet = dccp_rx_hist_entry_new(ccid3_rx_hist, opt_recv->dccpor_ndp,
skb, SLAB_ATOMIC); skb, SLAB_ATOMIC);
if (packet == NULL) { if (packet == NULL) {
ccid3_pr_debug("%s, sk=%p, Not enough mem to add rx packet to history (consider it lost)!", ccid3_pr_debug("%s, sk=%p, Not enough mem to add rx packet "
"to history (consider it lost)!",
dccp_role(sk), sk); dccp_role(sk), sk);
return; return;
} }
@ -1927,13 +1984,16 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
switch (hcrx->ccid3hcrx_state) { switch (hcrx->ccid3hcrx_state) {
case TFRC_RSTATE_NO_DATA: case TFRC_RSTATE_NO_DATA:
ccid3_pr_debug("%s, sk=%p(%s), skb=%p, sending initial feedback\n", ccid3_pr_debug("%s, sk=%p(%s), skb=%p, sending initial "
dccp_role(sk), sk, dccp_state_name(sk->sk_state), skb); "feedback\n",
dccp_role(sk), sk,
dccp_state_name(sk->sk_state), skb);
ccid3_hc_rx_send_feedback(sk); ccid3_hc_rx_send_feedback(sk);
ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA); ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA);
return; return;
case TFRC_RSTATE_DATA: case TFRC_RSTATE_DATA:
hcrx->ccid3hcrx_bytes_recv += skb->len - dccp_hdr(skb)->dccph_doff * 4; hcrx->ccid3hcrx_bytes_recv += skb->len -
dccp_hdr(skb)->dccph_doff * 4;
if (ins == 0) { if (ins == 0) {
if (now_delta(hcrx->ccid3hcrx_tstamp_last_ack) >= if (now_delta(hcrx->ccid3hcrx_tstamp_last_ack) >=
hcrx->ccid3hcrx_rtt) { hcrx->ccid3hcrx_rtt) {
@ -1975,7 +2035,8 @@ static int ccid3_hc_rx_init(struct sock *sk)
ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
hcrx = dp->dccps_hc_rx_ccid_private = kmalloc(sizeof(*hcrx), gfp_any()); hcrx = dp->dccps_hc_rx_ccid_private = kmalloc(sizeof(*hcrx),
gfp_any());
if (hcrx == NULL) if (hcrx == NULL)
return -ENOMEM; return -ENOMEM;
@ -2135,7 +2196,8 @@ static __exit void ccid3_module_exit(void)
} }
module_exit(ccid3_module_exit); module_exit(ccid3_module_exit);
MODULE_AUTHOR("Ian McDonald <iam4@cs.waikato.ac.nz> & Arnaldo Carvalho de Melo <acme@ghostprotocols.net>"); MODULE_AUTHOR("Ian McDonald <iam4@cs.waikato.ac.nz>, "
"Arnaldo Carvalho de Melo <acme@ghostprotocols.net>");
MODULE_DESCRIPTION("DCCP TFRC CCID3 CCID"); MODULE_DESCRIPTION("DCCP TFRC CCID3 CCID");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_ALIAS("net-dccp-ccid-3"); MODULE_ALIAS("net-dccp-ccid-3");