dccp: Fixes for TFRC/CCID-3 loss detection
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): fixes_for_ccid3_loss_detection
cover dccp: Fixes for TFRC/CCID-3 loss detection
Hi Dave,
can you please have a look at this set of fixes. These address errors which recently have been found in the TFRC loss detection:
Patch #1: Fixes an error appearing throughout the TFRC loss detection code. Patch #2: Updates the NDP count option to 6 bytes (code was limited to 3). Patch #3: Fixes a bug in CCID-3 loss detection (causing false positives). Patch #4: Fixes an error in computing the most recent loss interval.
Following your recent suggestions, each patch addresses a single issue only, and if a patch contains additional (small) changes, these are remarked in the changelog.
Can you please consider pulling from
git://eden-feed-erg.abdn.ac.uk/net-2.6 (subtree `master')
At your discretion, since none of the bugs is severe, the set is also on
git://eden-feed-erg.abdn.ac.uk/net-next-2.6 (subtree `master')
Both trees have been freshly cloned from today, all patches have been thoroughly tested. Tests are encouraging - recovery from loss is now much faster.
Thank you.
(The online documentation for the loss detection has also been updated:
http://www.erg.abdn.ac.uk/users/gerrit/dccp/notes/\
ccid3/ccid3_packet_reception/loss_detection/loss_detection_algorithm_notes.txt)
PATCH 1/4 dccp ccid-3: Fix error in loss detection
The TFRC loss detection code used the wrong loss condition (RFC 4340, 7.7.1):
* the difference between sequence numbers s1 and s2 instead of
* the number of packets missing between s1 and s2 (one less than the distance).
Since this condition appears in many places of the code, it has been put into a separate function, dccp_loss_free().
Further changes:
----------------
* tidied up incorrect typing (it was using `int' for u64/s64 types);
* optimised conditional statements for common case of non-reordered packets;
* rewrote comments/documentation to match the changes.
--- net/dccp/ccids/lib/packet_history.c | 73 +++++++++++++--------------------- net/dccp/dccp.h | 15 +++++++ 2 files changed, 43 insertions(+), 45 deletions(-)
net/dccp/dccp.h +15 -0
@@ -153,6 +153,21 @@ static inline u64 max48(const u64 seq1, const u64 seq2)return after48 (seq1, seq2) ? seq1 : seq2; } +/** +* dccp_loss_free - Evaluates condition for data loss from RFC 4340, 7.7.1 +* @s1: start sequence number +* @s2: end sequence number +* @ndp: NDP count on packet with sequence number @s2 +* Returns true if the sequence range s1...s2 has no data loss. +*/ +static inline bool dccp_loss_free (const u64 s1,const u64 s2,const u64 ndp) +{ +s64 delta =dccp_delta_seqno (s1, s2); + +BUG_TRAP (delta >=0 ); +return (u64 )delta <= ndp +1 ; +} +enum {DCCP_MIB_NUM =0 ,DCCP_MIB_ACTIVEOPENS ,/* ActiveOpens */
net/dccp/ccids/lib/packet_history.c +28 -45
146 lines not on this page · raw message
PATCH 2/4 dccp: Upgrade NDP count from 3 to 6 bytes
RFC 4340, 7.7 specifies up to 6 bytes for the NDP Count option, whereas the code is limited to up to 3 bytes. This seems to be a relict of an earlier draft version and is brought up to date by the patch.
--- include/linux/dccp.h | 6 ++---- net/dccp/ccids/ccid3.c | 2 +- net/dccp/ccids/lib/packet_history.c | 6 +++--- net/dccp/ccids/lib/packet_history.h | 6 +++--- net/dccp/options.c | 14 ++++++++------ 5 files changed, 17 insertions(+), 17 deletions(-)
net/dccp/ccids/lib/packet_history.h +3 -3
@@ -64,7 +64,7 @@ struct tfrc_rx_hist_entry { u64 tfrchrx_seqno:48, tfrchrx_ccval:4, tfrchrx_type:4; -u32 tfrchrx_ndp;/* In fact it is from 8 to 24 bits */ + u64 tfrchrx_ndp:48;ktime_t tfrchrx_tstamp; };
@@ -145,14 +145,14 @@ static inline int tfrc_rx_hist_new_loss_indicated(struct tfrc_rx_hist *h, }extern void tfrc_rx_hist_add_packet (struct tfrc_rx_hist *h, -const struct sk_buff *skb,const u32 ndp); +const struct sk_buff *skb,const u64 ndp);extern int tfrc_rx_hist_duplicate (struct tfrc_rx_hist *h,struct sk_buff *skb);struct tfrc_loss_hist ;extern int tfrc_rx_handle_loss (struct tfrc_rx_hist *h,struct tfrc_loss_hist *lh, -struct sk_buff *skb,u32 ndp, +struct sk_buff *skb,const u64 ndp,u32 (*first_li)(struct sock *sk),struct sock *sk); extern u32 tfrc_rx_hist_sample_rtt(struct tfrc_rx_hist *h,
include/linux/dccp.h +2 -4
@@ -364,8 +364,6 @@ static inline unsigned int dccp_hdr_len(const struct sk_buff *skb)/* FIXME: for now we're default to 1 but it should really be 0 */ #define DCCPF_INITIAL_SEND_NDP_COUNT 1 -#define DCCP_NDP_LIMIT 0xFFFFFF -/** * struct dccp_minisock - Minimal DCCP connection representation *
@@ -437,7 +435,7 @@ extern int dccp_parse_options(struct sock *sk, struct dccp_request_sock *dreq, struct sk_buff *skb);struct dccp_options_received { -u32 dccpor_ndp;/* only 24 bits */ +u64 dccpor_ndp:48 ;u32 dccpor_timestamp;u32 dccpor_timestamp_echo;u32 dccpor_elapsed_time;
@@ -533,7 +531,7 @@ struct dccp_sock {__u16 dccps_r_ack_ratio;__u16 dccps_pcslen;__u16 dccps_pcrlen; -unsigned long dccps_ndp_count; + __u64 dccps_ndp_count:48;unsigned long dccps_rate_last;struct dccp_minisock dccps_minisock;struct dccp_ackvec *dccps_hc_rx_ackvec;
net/dccp/ccids/ccid3.c +1 -1
@@ -794,7 +794,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) {struct ccid3_hc_rx_sock *hcrx =ccid3_hc_rx_sk (sk);enum ccid3_fback_type do_feedback =CCID3_FBACK_NONE ; -const u32 ndp =dccp_sk (sk)->dccps_options_received.dccpor_ndp; +const u64 ndp =dccp_sk (sk)->dccps_options_received.dccpor_ndp;const bool is_data_packet =dccp_data_packet (skb);if (unlikely (hcrx->ccid3hcrx_state =TFRC_RSTATE_NO_DATA )) {
net/dccp/ccids/lib/packet_history.c +3 -3
@@ -153,7 +153,7 @@ void tfrc_rx_packet_history_exit(void)static inline void tfrc_rx_hist_entry_from_skb (struct tfrc_rx_hist_entry *entry,const struct sk_buff *skb, -const u32 ndp) +const u64 ndp) {const struct dccp_hdr *dh =dccp_hdr (skb);
@@ -166,7 +166,7 @@ static inline void tfrc_rx_hist_entry_from_skb(struct tfrc_rx_hist_entry *entry,void tfrc_rx_hist_add_packet (struct tfrc_rx_hist *h,const struct sk_buff *skb, -const u32 ndp) +const u64 ndp) {struct tfrc_rx_hist_entry *entry =tfrc_rx_hist_last_rcv (h);
@@ -356,7 +356,7 @@ static void __three_after_loss(struct tfrc_rx_hist *h)*/ int tfrc_rx_handle_loss (struct tfrc_rx_hist *h,struct tfrc_loss_hist *lh, -struct sk_buff *skb,u32 ndp, +struct sk_buff *skb,const u64 ndp,u32 (*calc_first_li)(struct sock *),struct sock *sk) {int is_new_loss =0 ;
net/dccp/options.c +8 -6
@@ -124,12 +124,12 @@ int dccp_parse_options(struct sock *sk, struct dccp_request_sock *dreq, mandatory =1 ;break ;case DCCPO_NDP_COUNT : -if (len >3 ) +if (len >6 ) goto out_invalid_option; opt_recv->dccpor_ndp =dccp_decode_value_var (value, len); -dccp_pr_debug ("%s rx opt: NDP count=%d\n" ,dccp_role (sk), - opt_recv->dccpor_ndp); +dccp_pr_debug ("%s opt: NDP count=%llu\n" ,dccp_role (sk), + (unsigned long long )opt_recv->dccpor_ndp);break ;case DCCPO_CHANGE_L :/* fall through */
@@ -307,9 +307,11 @@ static void dccp_encode_value_var(const u32 value, unsigned char *to, *to++ = (value &0xFF ); } -static inline int dccp_ndp_len (const int ndp) +static inline u8 dccp_ndp_len (const u64 ndp) { -return likely (ndp <=0xFF ) ?1 : ndp <=0xFFFF ?2 :3 ; +if (likely (ndp <=0xFF )) +return 1 ; +return likely (ndp <=USHORT_MAX ) ?2 : (ndp <=UINT_MAX ?4 :6 ); } int dccp_insert_option(struct sock *sk, struct sk_buff *skb,
@@ -336,7 +338,7 @@ EXPORT_SYMBOL_GPL(dccp_insert_option);static int dccp_insert_option_ndp (struct sock *sk,struct sk_buff *skb) {struct dccp_sock *dp =dccp_sk (sk); -int ndp = dp->dccps_ndp_count; +u64 ndp = dp->dccps_ndp_count;if (dccp_non_data_packet (skb)) ++dp->dccps_ndp_count;
PATCH 3/4 dccp ccid-3: Fix a loss detection bug
This fixes a bug in the logic of the TFRC loss detection:
* new_loss_indicated() should not be called while a loss is pending;
* but the code allows this;
* thus, for two subsequent gaps in the sequence space, when loss_count has not yet reached NDUPACK=3, the loss_count is falsely reduced to 1.
To avoid further and similar problems, all loss handling and loss detection is now done inside tfrc_rx_hist_handle_loss(), using an appropriate routine to track new losses.
Further changes:
----------------
* added a reminder that no RX history operations should be performed when rx_handle_loss() has identified a (new) loss, since the function takes care of packet reordering during loss detection;
* made tfrc_rx_hist_loss_pending() bool (thanks to an earlier suggestion by Arnaldo);
* removed unused functions.
--- net/dccp/ccids/ccid3.c | 12 +++++------- net/dccp/ccids/lib/packet_history.c | 24 ++++++++++++++++++++---- net/dccp/ccids/lib/packet_history.h | 24 ++---------------------- 3 files changed, 27 insertions(+), 33 deletions(-)
net/dccp/ccids/ccid3.c +5 -7
@@ -825,18 +825,16 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) }/* -* Handle pending losses and otherwise check for new loss +* Perform loss detection and handle pending losses */ -if (tfrc_rx_hist_loss_pending (&hcrx->ccid3hcrx_hist) && -tfrc_rx_handle_loss (&hcrx->ccid3hcrx_hist, - &hcrx->ccid3hcrx_li_hist, - skb, ndp, ccid3_first_li, sk) ) { +if (tfrc_rx_handle_loss (&hcrx->ccid3hcrx_hist, &hcrx->ccid3hcrx_li_hist, + skb, ndp, ccid3_first_li, sk)) { do_feedback =CCID3_FBACK_PARAM_CHANGE ; goto done_receiving; } -if (tfrc_rx_hist_new_loss_indicated (&hcrx->ccid3hcrx_hist, skb, ndp)) - goto update_records; +if (tfrc_rx_hist_loss_pending (&hcrx->ccid3hcrx_hist)) +return ;/* done receiving */ /* * Handle data packets: RTT sampling and monitoring p
net/dccp/ccids/lib/packet_history.c +20 -4
@@ -206,10 +206,21 @@ static void tfrc_rx_hist_swap(struct tfrc_rx_hist *h, const u8 a, const u8 b)* * In the descriptions, `Si' refers to the sequence number of entry number i, * whose NDP count is `Ni' (lower case is used for variables). -* Note: All __after_loss functions expect that a test against duplicates has -* been performed already: the seqno of the skb must not be less than the -* seqno of loss_prev; and it must not equal that of any valid hist_entry. +* Note: All __xxx_loss functions expect that a test against duplicates has been +* performed already: the seqno of the skb must not be less than the seqno +* of loss_prev; and it must not equal that of any valid history entry. */ +static void __do_track_loss (struct tfrc_rx_hist *h,struct sk_buff *skb,u64 n1) +{ +u64 s0 =tfrc_rx_hist_loss_prev (h)->tfrchrx_seqno, + s1 =DCCP_SKB_CB (skb)->dccpd_seq; + +if (!dccp_loss_free (s0, s1, n1)) {/* gap between S0 and S1 */ + h->loss_count =1 ; +tfrc_rx_hist_entry_from_skb (tfrc_rx_hist_entry (h,1 ), skb, n1); + } +} +static void __one_after_loss (struct tfrc_rx_hist *h,struct sk_buff *skb,u32 n2) { u64 s0 = tfrc_rx_hist_loss_prev(h)->tfrchrx_seqno,
@@ -353,6 +364,9 @@ static void __three_after_loss(struct tfrc_rx_hist *h)* Chooses action according to pending loss, updates LI database when a new * loss was detected, and does required post-processing. Returns 1 when caller * should send feedback, 0 otherwise. +* Since it also takes care of reordering during loss detection and updates the +* records accordingly, the caller should not perform any more RX history +* operations when loss_count is greater than 0 after calling this function. */ int tfrc_rx_handle_loss(struct tfrc_rx_hist *h, struct tfrc_loss_hist *lh,
@@ -361,7 +375,9 @@ int tfrc_rx_handle_loss(struct tfrc_rx_hist *h, {int is_new_loss =0 ; -if (h->loss_count =1 ) { +if (h->loss_count =0 ) { +__do_track_loss (h, skb, ndp); + }else if (h->loss_count =1 ) {__one_after_loss (h, skb, ndp); }else if (h->loss_count !=2 ) {DCCP_BUG ("invalid loss_count %d" , h->loss_count);
net/dccp/ccids/lib/packet_history.h +2 -22
@@ -118,30 +118,10 @@ static inline struct tfrc_rx_hist_entry *return h->ring[h->loss_start]; } -/* initialise loss detection and disable RTT sampling */ -static inline void tfrc_rx_hist_loss_indicated (struct tfrc_rx_hist *h) -{ - h->loss_count =1 ; -} -/* indicate whether previously a packet was detected missing */ -static inline int tfrc_rx_hist_loss_pending (const struct tfrc_rx_hist *h) -{ -return h->loss_count; -} - -/* any data packets missing between last reception and skb ? */ -static inline int tfrc_rx_hist_new_loss_indicated (struct tfrc_rx_hist *h, -const struct sk_buff *skb, -u32 ndp) +static inline bool tfrc_rx_hist_loss_pending (const struct tfrc_rx_hist *h) { -int delta =dccp_delta_seqno (tfrc_rx_hist_last_rcv (h)->tfrchrx_seqno, -DCCP_SKB_CB (skb)->dccpd_seq); - -if (delta >1 && ndp < delta) -tfrc_rx_hist_loss_indicated (h); - -return tfrc_rx_hist_loss_pending (h); +return h->loss_count >0 ; } extern void tfrc_rx_hist_add_packet(struct tfrc_rx_hist *h,
PATCH 4/4 dccp ccid-3: Length of loss intervals
This corrects an error in the computation of the open loss interval I_0:
* the interval length is (highest_seqno - start_seqno) + 1
* and not (highest_seqno - start_seqno).
This condition was not fully clear in RFC 3448, but reflects the current revision state of rfc3448bis and is also consistent with RFC 4340, 6.1.1.
Further changes:
----------------
* variable renamed due to line length constraints;
* explicit typecast to `s64' to avoid implicit signed/unsigned casting.
--- net/dccp/ccids/lib/loss_interval.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
net/dccp/ccids/lib/loss_interval.c +5 -5
@@ -90,14 +90,14 @@ u8 tfrc_lh_update_i_mean(struct tfrc_loss_hist *lh, struct sk_buff *skb) {struct tfrc_loss_interval *cur =tfrc_lh_peek (lh);u32 old_i_mean = lh->i_mean; -s64 length; +s64 len;if (cur =NULL )/* not initialised */ return 0 ; - length =dccp_delta_seqno (cur->li_seqno,DCCP_SKB_CB (skb)->dccpd_seq); + len =dccp_delta_seqno (cur->li_seqno,DCCP_SKB_CB (skb)->dccpd_seq) +1 ; -if (length - cur->li_length <=0 )/* duplicate or reordered */ +if (len - (s64 )cur->li_length <=0 )/* duplicate or reordered */ return 0 ;if (SUB16 (dccp_hdr (skb)->dccph_ccval, cur->li_ccval) >4 )
@@ -114,7 +114,7 @@ u8 tfrc_lh_update_i_mean(struct tfrc_loss_hist *lh, struct sk_buff *skb)if (tfrc_lh_length (lh) =1 )/* due to RFC 3448, 6.3.1 */ return 0 ; - cur->li_length = length; + cur->li_length = len;tfrc_lh_calc_i_mean (lh);return (lh->i_mean < old_i_mean);
@@ -159,7 +159,7 @@ int tfrc_lh_interval_add(struct tfrc_loss_hist *lh, struct tfrc_rx_hist *rh,else { cur->li_length =dccp_delta_seqno (cur->li_seqno, new->li_seqno); new->li_length =dccp_delta_seqno (new->li_seqno, -tfrc_rx_hist_last_rcv (rh)->tfrchrx_seqno); +tfrc_rx_hist_last_rcv (rh)->tfrchrx_seqno) +1 ;if (lh->counter > (2 *LIH_SIZE )) lh->counter -=LIH_SIZE ;
A message that is not in the archive (sent off-list or not yet received): [email protected]
David Miller
maintainerFrom: Gerrit Renker <[email protected]>
Date: Sat, 12 Jul 2008 16:02:13 +0100
Quoted 5 lines
| git://eden-feed-erg.abdn.ac.uk/net-2.6 (subtree `master')
| git://eden-feed-erg.abdn.ac.uk/net-next-2.6 (subtree `master')
|
Typo: git://eden-feed.erg.abdn.ac.uk/net-...
^Pulled and pushed back out to net-next-2.6, thanks Gerrit.