diff options
Diffstat (limited to 'net/dccp/ccids/ccid2.c')
-rw-r--r-- | net/dccp/ccids/ccid2.c | 109 |
1 files changed, 87 insertions, 22 deletions
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c index fadecd20d75b..0462040fc818 100644 --- a/net/dccp/ccids/ccid2.c +++ b/net/dccp/ccids/ccid2.c | |||
@@ -153,17 +153,93 @@ out: | |||
153 | sock_put(sk); | 153 | sock_put(sk); |
154 | } | 154 | } |
155 | 155 | ||
156 | /* | ||
157 | * Congestion window validation (RFC 2861). | ||
158 | */ | ||
159 | static int ccid2_do_cwv = 1; | ||
160 | module_param(ccid2_do_cwv, bool, 0644); | ||
161 | MODULE_PARM_DESC(ccid2_do_cwv, "Perform RFC2861 Congestion Window Validation"); | ||
162 | |||
163 | /** | ||
164 | * ccid2_update_used_window - Track how much of cwnd is actually used | ||
165 | * This is done in addition to CWV. The sender needs to have an idea of how many | ||
166 | * packets may be in flight, to set the local Sequence Window value accordingly | ||
167 | * (RFC 4340, 7.5.2). The CWV mechanism is exploited to keep track of the | ||
168 | * maximum-used window. We use an EWMA low-pass filter to filter out noise. | ||
169 | */ | ||
170 | static void ccid2_update_used_window(struct ccid2_hc_tx_sock *hc, u32 new_wnd) | ||
171 | { | ||
172 | hc->tx_expected_wnd = (3 * hc->tx_expected_wnd + new_wnd) / 4; | ||
173 | } | ||
174 | |||
175 | /* This borrows the code of tcp_cwnd_application_limited() */ | ||
176 | static void ccid2_cwnd_application_limited(struct sock *sk, const u32 now) | ||
177 | { | ||
178 | struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk); | ||
179 | /* don't reduce cwnd below the initial window (IW) */ | ||
180 | u32 init_win = rfc3390_bytes_to_packets(dccp_sk(sk)->dccps_mss_cache), | ||
181 | win_used = max(hc->tx_cwnd_used, init_win); | ||
182 | |||
183 | if (win_used < hc->tx_cwnd) { | ||
184 | hc->tx_ssthresh = max(hc->tx_ssthresh, | ||
185 | (hc->tx_cwnd >> 1) + (hc->tx_cwnd >> 2)); | ||
186 | hc->tx_cwnd = (hc->tx_cwnd + win_used) >> 1; | ||
187 | } | ||
188 | hc->tx_cwnd_used = 0; | ||
189 | hc->tx_cwnd_stamp = now; | ||
190 | } | ||
191 | |||
192 | /* This borrows the code of tcp_cwnd_restart() */ | ||
193 | static void ccid2_cwnd_restart(struct sock *sk, const u32 now) | ||
194 | { | ||
195 | struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk); | ||
196 | u32 cwnd = hc->tx_cwnd, restart_cwnd, | ||
197 | iwnd = rfc3390_bytes_to_packets(dccp_sk(sk)->dccps_mss_cache); | ||
198 | |||
199 | hc->tx_ssthresh = max(hc->tx_ssthresh, (cwnd >> 1) + (cwnd >> 2)); | ||
200 | |||
201 | /* don't reduce cwnd below the initial window (IW) */ | ||
202 | restart_cwnd = min(cwnd, iwnd); | ||
203 | cwnd >>= (now - hc->tx_lsndtime) / hc->tx_rto; | ||
204 | hc->tx_cwnd = max(cwnd, restart_cwnd); | ||
205 | |||
206 | hc->tx_cwnd_stamp = now; | ||
207 | hc->tx_cwnd_used = 0; | ||
208 | } | ||
209 | |||
156 | static void ccid2_hc_tx_packet_sent(struct sock *sk, unsigned int len) | 210 | static void ccid2_hc_tx_packet_sent(struct sock *sk, unsigned int len) |
157 | { | 211 | { |
158 | struct dccp_sock *dp = dccp_sk(sk); | 212 | struct dccp_sock *dp = dccp_sk(sk); |
159 | struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk); | 213 | struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk); |
214 | const u32 now = ccid2_time_stamp; | ||
160 | struct ccid2_seq *next; | 215 | struct ccid2_seq *next; |
161 | 216 | ||
162 | hc->tx_pipe++; | 217 | /* slow-start after idle periods (RFC 2581, RFC 2861) */ |
218 | if (ccid2_do_cwv && !hc->tx_pipe && | ||
219 | (s32)(now - hc->tx_lsndtime) >= hc->tx_rto) | ||
220 | ccid2_cwnd_restart(sk, now); | ||
221 | |||
222 | hc->tx_lsndtime = now; | ||
223 | hc->tx_pipe += 1; | ||
224 | |||
225 | /* see whether cwnd was fully used (RFC 2861), update expected window */ | ||
226 | if (ccid2_cwnd_network_limited(hc)) { | ||
227 | ccid2_update_used_window(hc, hc->tx_cwnd); | ||
228 | hc->tx_cwnd_used = 0; | ||
229 | hc->tx_cwnd_stamp = now; | ||
230 | } else { | ||
231 | if (hc->tx_pipe > hc->tx_cwnd_used) | ||
232 | hc->tx_cwnd_used = hc->tx_pipe; | ||
233 | |||
234 | ccid2_update_used_window(hc, hc->tx_cwnd_used); | ||
235 | |||
236 | if (ccid2_do_cwv && (s32)(now - hc->tx_cwnd_stamp) >= hc->tx_rto) | ||
237 | ccid2_cwnd_application_limited(sk, now); | ||
238 | } | ||
163 | 239 | ||
164 | hc->tx_seqh->ccid2s_seq = dp->dccps_gss; | 240 | hc->tx_seqh->ccid2s_seq = dp->dccps_gss; |
165 | hc->tx_seqh->ccid2s_acked = 0; | 241 | hc->tx_seqh->ccid2s_acked = 0; |
166 | hc->tx_seqh->ccid2s_sent = ccid2_time_stamp; | 242 | hc->tx_seqh->ccid2s_sent = now; |
167 | 243 | ||
168 | next = hc->tx_seqh->ccid2s_next; | 244 | next = hc->tx_seqh->ccid2s_next; |
169 | /* check if we need to alloc more space */ | 245 | /* check if we need to alloc more space */ |
@@ -583,15 +659,6 @@ done: | |||
583 | dccp_ackvec_parsed_cleanup(&hc->tx_av_chunks); | 659 | dccp_ackvec_parsed_cleanup(&hc->tx_av_chunks); |
584 | } | 660 | } |
585 | 661 | ||
586 | /* | ||
587 | * Convert RFC 3390 larger initial window into an equivalent number of packets. | ||
588 | * This is based on the numbers specified in RFC 5681, 3.1. | ||
589 | */ | ||
590 | static inline u32 rfc3390_bytes_to_packets(const u32 smss) | ||
591 | { | ||
592 | return smss <= 1095 ? 4 : (smss > 2190 ? 2 : 3); | ||
593 | } | ||
594 | |||
595 | static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk) | 662 | static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk) |
596 | { | 663 | { |
597 | struct ccid2_hc_tx_sock *hc = ccid_priv(ccid); | 664 | struct ccid2_hc_tx_sock *hc = ccid_priv(ccid); |
@@ -603,6 +670,7 @@ static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk) | |||
603 | 670 | ||
604 | /* Use larger initial windows (RFC 4341, section 5). */ | 671 | /* Use larger initial windows (RFC 4341, section 5). */ |
605 | hc->tx_cwnd = rfc3390_bytes_to_packets(dp->dccps_mss_cache); | 672 | hc->tx_cwnd = rfc3390_bytes_to_packets(dp->dccps_mss_cache); |
673 | hc->tx_expected_wnd = hc->tx_cwnd; | ||
606 | 674 | ||
607 | /* Make sure that Ack Ratio is enabled and within bounds. */ | 675 | /* Make sure that Ack Ratio is enabled and within bounds. */ |
608 | max_ratio = DIV_ROUND_UP(hc->tx_cwnd, 2); | 676 | max_ratio = DIV_ROUND_UP(hc->tx_cwnd, 2); |
@@ -615,7 +683,8 @@ static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk) | |||
615 | 683 | ||
616 | hc->tx_rto = DCCP_TIMEOUT_INIT; | 684 | hc->tx_rto = DCCP_TIMEOUT_INIT; |
617 | hc->tx_rpdupack = -1; | 685 | hc->tx_rpdupack = -1; |
618 | hc->tx_last_cong = ccid2_time_stamp; | 686 | hc->tx_last_cong = hc->tx_lsndtime = hc->tx_cwnd_stamp = ccid2_time_stamp; |
687 | hc->tx_cwnd_used = 0; | ||
619 | setup_timer(&hc->tx_rtotimer, ccid2_hc_tx_rto_expire, | 688 | setup_timer(&hc->tx_rtotimer, ccid2_hc_tx_rto_expire, |
620 | (unsigned long)sk); | 689 | (unsigned long)sk); |
621 | INIT_LIST_HEAD(&hc->tx_av_chunks); | 690 | INIT_LIST_HEAD(&hc->tx_av_chunks); |
@@ -636,18 +705,14 @@ static void ccid2_hc_tx_exit(struct sock *sk) | |||
636 | 705 | ||
637 | static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) | 706 | static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) |
638 | { | 707 | { |
639 | const struct dccp_sock *dp = dccp_sk(sk); | ||
640 | struct ccid2_hc_rx_sock *hc = ccid2_hc_rx_sk(sk); | 708 | struct ccid2_hc_rx_sock *hc = ccid2_hc_rx_sk(sk); |
641 | 709 | ||
642 | switch (DCCP_SKB_CB(skb)->dccpd_type) { | 710 | if (!dccp_data_packet(skb)) |
643 | case DCCP_PKT_DATA: | 711 | return; |
644 | case DCCP_PKT_DATAACK: | 712 | |
645 | hc->rx_data++; | 713 | if (++hc->rx_num_data_pkts >= dccp_sk(sk)->dccps_r_ack_ratio) { |
646 | if (hc->rx_data >= dp->dccps_r_ack_ratio) { | 714 | dccp_send_ack(sk); |
647 | dccp_send_ack(sk); | 715 | hc->rx_num_data_pkts = 0; |
648 | hc->rx_data = 0; | ||
649 | } | ||
650 | break; | ||
651 | } | 716 | } |
652 | } | 717 | } |
653 | 718 | ||