1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include "../dccp.h"
23#include "ccid3.h"
24
25#include <asm/unaligned.h>
26
27#ifdef CONFIG_IP_DCCP_CCID3_DEBUG
28static bool ccid3_debug;
29#define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a)
30#else
31#define ccid3_pr_debug(format, a...)
32#endif
33
34
35
36
37#ifdef CONFIG_IP_DCCP_CCID3_DEBUG
38static const char *ccid3_tx_state_name(enum ccid3_hc_tx_states state)
39{
40 static const char *const ccid3_state_names[] = {
41 [TFRC_SSTATE_NO_SENT] = "NO_SENT",
42 [TFRC_SSTATE_NO_FBACK] = "NO_FBACK",
43 [TFRC_SSTATE_FBACK] = "FBACK",
44 };
45
46 return ccid3_state_names[state];
47}
48#endif
49
50static void ccid3_hc_tx_set_state(struct sock *sk,
51 enum ccid3_hc_tx_states state)
52{
53 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
54 enum ccid3_hc_tx_states oldstate = hc->tx_state;
55
56 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
57 dccp_role(sk), sk, ccid3_tx_state_name(oldstate),
58 ccid3_tx_state_name(state));
59 WARN_ON(state == oldstate);
60 hc->tx_state = state;
61}
62
63
64
65
66
67
68
69
70
71
72static inline u64 rfc3390_initial_rate(struct sock *sk)
73{
74 const struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
75 const __u32 w_init = clamp_t(__u32, 4380U, 2 * hc->tx_s, 4 * hc->tx_s);
76
77 return scaled_div(w_init << 6, hc->tx_rtt);
78}
79
80
81
82
83
84static void ccid3_update_send_interval(struct ccid3_hc_tx_sock *hc)
85{
86 hc->tx_t_ipi = scaled_div32(((u64)hc->tx_s) << 6, hc->tx_x);
87
88 DCCP_BUG_ON(hc->tx_t_ipi == 0);
89 ccid3_pr_debug("t_ipi=%u, s=%u, X=%u\n", hc->tx_t_ipi,
90 hc->tx_s, (unsigned int)(hc->tx_x >> 6));
91}
92
93static u32 ccid3_hc_tx_idle_rtt(struct ccid3_hc_tx_sock *hc, ktime_t now)
94{
95 u32 delta = ktime_us_delta(now, hc->tx_t_last_win_count);
96
97 return delta / hc->tx_rtt;
98}
99
100
101
102
103
104
105
106
107
108
109
110
111static void ccid3_hc_tx_update_x(struct sock *sk, ktime_t *stamp)
112{
113 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
114 __u64 min_rate = 2 * hc->tx_x_recv;
115 const __u64 old_x = hc->tx_x;
116 ktime_t now = stamp ? *stamp : ktime_get_real();
117
118
119
120
121
122
123
124 if (ccid3_hc_tx_idle_rtt(hc, now) >= 2) {
125 min_rate = rfc3390_initial_rate(sk);
126 min_rate = max(min_rate, 2 * hc->tx_x_recv);
127 }
128
129 if (hc->tx_p > 0) {
130
131 hc->tx_x = min(((__u64)hc->tx_x_calc) << 6, min_rate);
132 hc->tx_x = max(hc->tx_x, (((__u64)hc->tx_s) << 6) / TFRC_T_MBI);
133
134 } else if (ktime_us_delta(now, hc->tx_t_ld) - (s64)hc->tx_rtt >= 0) {
135
136 hc->tx_x = min(2 * hc->tx_x, min_rate);
137 hc->tx_x = max(hc->tx_x,
138 scaled_div(((__u64)hc->tx_s) << 6, hc->tx_rtt));
139 hc->tx_t_ld = now;
140 }
141
142 if (hc->tx_x != old_x) {
143 ccid3_pr_debug("X_prev=%u, X_now=%u, X_calc=%u, "
144 "X_recv=%u\n", (unsigned int)(old_x >> 6),
145 (unsigned int)(hc->tx_x >> 6), hc->tx_x_calc,
146 (unsigned int)(hc->tx_x_recv >> 6));
147
148 ccid3_update_send_interval(hc);
149 }
150}
151
152
153
154
155
156
157
158static inline void ccid3_hc_tx_update_s(struct ccid3_hc_tx_sock *hc, int len)
159{
160 const u16 old_s = hc->tx_s;
161
162 hc->tx_s = tfrc_ewma(hc->tx_s, len, 9);
163
164 if (hc->tx_s != old_s)
165 ccid3_update_send_interval(hc);
166}
167
168
169
170
171
172static inline void ccid3_hc_tx_update_win_count(struct ccid3_hc_tx_sock *hc,
173 ktime_t now)
174{
175 u32 delta = ktime_us_delta(now, hc->tx_t_last_win_count),
176 quarter_rtts = (4 * delta) / hc->tx_rtt;
177
178 if (quarter_rtts > 0) {
179 hc->tx_t_last_win_count = now;
180 hc->tx_last_win_count += min(quarter_rtts, 5U);
181 hc->tx_last_win_count &= 0xF;
182 }
183}
184
185static void ccid3_hc_tx_no_feedback_timer(struct timer_list *t)
186{
187 struct ccid3_hc_tx_sock *hc = from_timer(hc, t, tx_no_feedback_timer);
188 struct sock *sk = hc->sk;
189 unsigned long t_nfb = USEC_PER_SEC / 5;
190
191 bh_lock_sock(sk);
192 if (sock_owned_by_user(sk)) {
193
194
195 goto restart_timer;
196 }
197
198 ccid3_pr_debug("%s(%p, state=%s) - entry\n", dccp_role(sk), sk,
199 ccid3_tx_state_name(hc->tx_state));
200
201
202 if ((1 << sk->sk_state) & ~(DCCPF_OPEN | DCCPF_PARTOPEN))
203 goto out;
204
205
206 if (hc->tx_state == TFRC_SSTATE_FBACK)
207 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK);
208
209
210
211
212
213 if (hc->tx_t_rto == 0 || hc->tx_p == 0) {
214
215
216 hc->tx_x = max(hc->tx_x / 2,
217 (((__u64)hc->tx_s) << 6) / TFRC_T_MBI);
218 ccid3_update_send_interval(hc);
219 } else {
220
221
222
223
224
225
226
227
228
229
230 if (hc->tx_x_calc > (hc->tx_x_recv >> 5))
231 hc->tx_x_recv =
232 max(hc->tx_x_recv / 2,
233 (((__u64)hc->tx_s) << 6) / (2*TFRC_T_MBI));
234 else {
235 hc->tx_x_recv = hc->tx_x_calc;
236 hc->tx_x_recv <<= 4;
237 }
238 ccid3_hc_tx_update_x(sk, NULL);
239 }
240 ccid3_pr_debug("Reduced X to %llu/64 bytes/sec\n",
241 (unsigned long long)hc->tx_x);
242
243
244
245
246
247 if (unlikely(hc->tx_t_rto == 0))
248 t_nfb = TFRC_INITIAL_TIMEOUT;
249 else
250 t_nfb = max(hc->tx_t_rto, 2 * hc->tx_t_ipi);
251
252restart_timer:
253 sk_reset_timer(sk, &hc->tx_no_feedback_timer,
254 jiffies + usecs_to_jiffies(t_nfb));
255out:
256 bh_unlock_sock(sk);
257 sock_put(sk);
258}
259
260
261
262
263
264
265
266
267static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
268{
269 struct dccp_sock *dp = dccp_sk(sk);
270 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
271 ktime_t now = ktime_get_real();
272 s64 delay;
273
274
275
276
277
278
279 if (unlikely(skb->len == 0))
280 return -EBADMSG;
281
282 if (hc->tx_state == TFRC_SSTATE_NO_SENT) {
283 sk_reset_timer(sk, &hc->tx_no_feedback_timer, (jiffies +
284 usecs_to_jiffies(TFRC_INITIAL_TIMEOUT)));
285 hc->tx_last_win_count = 0;
286 hc->tx_t_last_win_count = now;
287
288
289 hc->tx_t_nom = now;
290
291 hc->tx_s = skb->len;
292
293
294
295
296
297
298 if (dp->dccps_syn_rtt) {
299 ccid3_pr_debug("SYN RTT = %uus\n", dp->dccps_syn_rtt);
300 hc->tx_rtt = dp->dccps_syn_rtt;
301 hc->tx_x = rfc3390_initial_rate(sk);
302 hc->tx_t_ld = now;
303 } else {
304
305
306
307
308
309
310 hc->tx_rtt = DCCP_FALLBACK_RTT;
311 hc->tx_x = hc->tx_s;
312 hc->tx_x <<= 6;
313 }
314 ccid3_update_send_interval(hc);
315
316 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK);
317
318 } else {
319 delay = ktime_us_delta(hc->tx_t_nom, now);
320 ccid3_pr_debug("delay=%ld\n", (long)delay);
321
322
323
324
325
326
327
328
329 if (delay >= TFRC_T_DELTA)
330 return (u32)delay / USEC_PER_MSEC;
331
332 ccid3_hc_tx_update_win_count(hc, now);
333 }
334
335
336 dp->dccps_hc_tx_insert_options = 1;
337 DCCP_SKB_CB(skb)->dccpd_ccval = hc->tx_last_win_count;
338
339
340 hc->tx_t_nom = ktime_add_us(hc->tx_t_nom, hc->tx_t_ipi);
341 return CCID_PACKET_SEND_AT_ONCE;
342}
343
344static void ccid3_hc_tx_packet_sent(struct sock *sk, unsigned int len)
345{
346 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
347
348 ccid3_hc_tx_update_s(hc, len);
349
350 if (tfrc_tx_hist_add(&hc->tx_hist, dccp_sk(sk)->dccps_gss))
351 DCCP_CRIT("packet history - out of memory!");
352}
353
354static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
355{
356 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
357 struct tfrc_tx_hist_entry *acked;
358 ktime_t now;
359 unsigned long t_nfb;
360 u32 r_sample;
361
362
363 if (!(DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK ||
364 DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK))
365 return;
366
367
368
369
370
371
372
373
374 acked = tfrc_tx_hist_find_entry(hc->tx_hist, dccp_hdr_ack_seq(skb));
375 if (acked == NULL)
376 return;
377
378 tfrc_tx_hist_purge(&acked->next);
379
380
381 now = ktime_get_real();
382 r_sample = dccp_sample_rtt(sk, ktime_us_delta(now, acked->stamp));
383 hc->tx_rtt = tfrc_ewma(hc->tx_rtt, r_sample, 9);
384
385
386
387
388 if (hc->tx_state == TFRC_SSTATE_NO_FBACK) {
389 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK);
390
391 if (hc->tx_t_rto == 0) {
392
393
394
395 hc->tx_x = rfc3390_initial_rate(sk);
396 hc->tx_t_ld = now;
397
398 ccid3_update_send_interval(hc);
399
400 goto done_computing_x;
401 } else if (hc->tx_p == 0) {
402
403
404
405 goto done_computing_x;
406 }
407 }
408
409
410 if (hc->tx_p > 0)
411 hc->tx_x_calc = tfrc_calc_x(hc->tx_s, hc->tx_rtt, hc->tx_p);
412 ccid3_hc_tx_update_x(sk, &now);
413
414done_computing_x:
415 ccid3_pr_debug("%s(%p), RTT=%uus (sample=%uus), s=%u, "
416 "p=%u, X_calc=%u, X_recv=%u, X=%u\n",
417 dccp_role(sk), sk, hc->tx_rtt, r_sample,
418 hc->tx_s, hc->tx_p, hc->tx_x_calc,
419 (unsigned int)(hc->tx_x_recv >> 6),
420 (unsigned int)(hc->tx_x >> 6));
421
422
423 sk_stop_timer(sk, &hc->tx_no_feedback_timer);
424
425
426
427
428
429 sk->sk_write_space(sk);
430
431
432
433
434
435
436 hc->tx_t_rto = max_t(u32, 4 * hc->tx_rtt,
437 USEC_PER_SEC/HZ * tcp_rto_min(sk));
438
439
440
441
442 t_nfb = max(hc->tx_t_rto, 2 * hc->tx_t_ipi);
443
444 ccid3_pr_debug("%s(%p), Scheduled no feedback timer to "
445 "expire in %lu jiffies (%luus)\n",
446 dccp_role(sk), sk, usecs_to_jiffies(t_nfb), t_nfb);
447
448 sk_reset_timer(sk, &hc->tx_no_feedback_timer,
449 jiffies + usecs_to_jiffies(t_nfb));
450}
451
452static int ccid3_hc_tx_parse_options(struct sock *sk, u8 packet_type,
453 u8 option, u8 *optval, u8 optlen)
454{
455 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
456 __be32 opt_val;
457
458 switch (option) {
459 case TFRC_OPT_RECEIVE_RATE:
460 case TFRC_OPT_LOSS_EVENT_RATE:
461
462 if (packet_type == DCCP_PKT_DATA)
463 break;
464 if (unlikely(optlen != 4)) {
465 DCCP_WARN("%s(%p), invalid len %d for %u\n",
466 dccp_role(sk), sk, optlen, option);
467 return -EINVAL;
468 }
469 opt_val = ntohl(get_unaligned((__be32 *)optval));
470
471 if (option == TFRC_OPT_RECEIVE_RATE) {
472
473 hc->tx_x_recv = opt_val;
474 hc->tx_x_recv <<= 6;
475
476 ccid3_pr_debug("%s(%p), RECEIVE_RATE=%u\n",
477 dccp_role(sk), sk, opt_val);
478 } else {
479
480 hc->tx_p = tfrc_invert_loss_event_rate(opt_val);
481
482 ccid3_pr_debug("%s(%p), LOSS_EVENT_RATE=%u\n",
483 dccp_role(sk), sk, opt_val);
484 }
485 }
486 return 0;
487}
488
489static int ccid3_hc_tx_init(struct ccid *ccid, struct sock *sk)
490{
491 struct ccid3_hc_tx_sock *hc = ccid_priv(ccid);
492
493 hc->tx_state = TFRC_SSTATE_NO_SENT;
494 hc->tx_hist = NULL;
495 hc->sk = sk;
496 timer_setup(&hc->tx_no_feedback_timer,
497 ccid3_hc_tx_no_feedback_timer, 0);
498 return 0;
499}
500
501static void ccid3_hc_tx_exit(struct sock *sk)
502{
503 struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
504
505 sk_stop_timer(sk, &hc->tx_no_feedback_timer);
506 tfrc_tx_hist_purge(&hc->tx_hist);
507}
508
509static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info)
510{
511 info->tcpi_rto = ccid3_hc_tx_sk(sk)->tx_t_rto;
512 info->tcpi_rtt = ccid3_hc_tx_sk(sk)->tx_rtt;
513}
514
515static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len,
516 u32 __user *optval, int __user *optlen)
517{
518 const struct ccid3_hc_tx_sock *hc = ccid3_hc_tx_sk(sk);
519 struct tfrc_tx_info tfrc;
520 const void *val;
521
522 switch (optname) {
523 case DCCP_SOCKOPT_CCID_TX_INFO:
524 if (len < sizeof(tfrc))
525 return -EINVAL;
526 memset(&tfrc, 0, sizeof(tfrc));
527 tfrc.tfrctx_x = hc->tx_x;
528 tfrc.tfrctx_x_recv = hc->tx_x_recv;
529 tfrc.tfrctx_x_calc = hc->tx_x_calc;
530 tfrc.tfrctx_rtt = hc->tx_rtt;
531 tfrc.tfrctx_p = hc->tx_p;
532 tfrc.tfrctx_rto = hc->tx_t_rto;
533 tfrc.tfrctx_ipi = hc->tx_t_ipi;
534 len = sizeof(tfrc);
535 val = &tfrc;
536 break;
537 default:
538 return -ENOPROTOOPT;
539 }
540
541 if (put_user(len, optlen) || copy_to_user(optval, val, len))
542 return -EFAULT;
543
544 return 0;
545}
546
547
548
549
550
551
552enum ccid3_fback_type {
553 CCID3_FBACK_NONE = 0,
554 CCID3_FBACK_INITIAL,
555 CCID3_FBACK_PERIODIC,
556 CCID3_FBACK_PARAM_CHANGE
557};
558
559#ifdef CONFIG_IP_DCCP_CCID3_DEBUG
560static const char *ccid3_rx_state_name(enum ccid3_hc_rx_states state)
561{
562 static const char *const ccid3_rx_state_names[] = {
563 [TFRC_RSTATE_NO_DATA] = "NO_DATA",
564 [TFRC_RSTATE_DATA] = "DATA",
565 };
566
567 return ccid3_rx_state_names[state];
568}
569#endif
570
571static void ccid3_hc_rx_set_state(struct sock *sk,
572 enum ccid3_hc_rx_states state)
573{
574 struct ccid3_hc_rx_sock *hc = ccid3_hc_rx_sk(sk);
575 enum ccid3_hc_rx_states oldstate = hc->rx_state;
576
577 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
578 dccp_role(sk), sk, ccid3_rx_state_name(oldstate),
579 ccid3_rx_state_name(state));
580 WARN_ON(state == oldstate);
581 hc->rx_state = state;
582}
583
584static void ccid3_hc_rx_send_feedback(struct sock *sk,
585 const struct sk_buff *skb,
586 enum ccid3_fback_type fbtype)
587{
588 struct ccid3_hc_rx_sock *hc = ccid3_hc_rx_sk(sk);
589 struct dccp_sock *dp = dccp_sk(sk);
590 ktime_t now = ktime_get();
591 s64 delta = 0;
592
593 switch (fbtype) {
594 case CCID3_FBACK_INITIAL:
595 hc->rx_x_recv = 0;
596 hc->rx_pinv = ~0U;
597 break;
598 case CCID3_FBACK_PARAM_CHANGE:
599
600
601
602
603
604
605
606
607
608
609 if (hc->rx_x_recv > 0)
610 break;
611
612 case CCID3_FBACK_PERIODIC:
613 delta = ktime_us_delta(now, hc->rx_tstamp_last_feedback);
614 if (delta <= 0)
615 delta = 1;
616 hc->rx_x_recv = scaled_div32(hc->rx_bytes_recv, delta);
617 break;
618 default:
619 return;
620 }
621
622 ccid3_pr_debug("Interval %lldusec, X_recv=%u, 1/p=%u\n", delta,
623 hc->rx_x_recv, hc->rx_pinv);
624
625 hc->rx_tstamp_last_feedback = now;
626 hc->rx_last_counter = dccp_hdr(skb)->dccph_ccval;
627 hc->rx_bytes_recv = 0;
628
629 dp->dccps_hc_rx_insert_options = 1;
630 dccp_send_ack(sk);
631}
632
633static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
634{
635 const struct ccid3_hc_rx_sock *hc = ccid3_hc_rx_sk(sk);
636 __be32 x_recv, pinv;
637
638 if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN))
639 return 0;
640
641 if (dccp_packet_without_ack(skb))
642 return 0;
643
644 x_recv = htonl(hc->rx_x_recv);
645 pinv = htonl(hc->rx_pinv);
646
647 if (dccp_insert_option(skb, TFRC_OPT_LOSS_EVENT_RATE,
648 &pinv, sizeof(pinv)) ||
649 dccp_insert_option(skb, TFRC_OPT_RECEIVE_RATE,
650 &x_recv, sizeof(x_recv)))
651 return -1;
652
653 return 0;
654}
655
656
657
658
659
660
661
662
663
664
665
666static u32 ccid3_first_li(struct sock *sk)
667{
668 struct ccid3_hc_rx_sock *hc = ccid3_hc_rx_sk(sk);
669 u32 x_recv, p;
670 s64 delta;
671 u64 fval;
672
673 if (hc->rx_rtt == 0) {
674 DCCP_WARN("No RTT estimate available, using fallback RTT\n");
675 hc->rx_rtt = DCCP_FALLBACK_RTT;
676 }
677
678 delta = ktime_us_delta(ktime_get(), hc->rx_tstamp_last_feedback);
679 if (delta <= 0)
680 delta = 1;
681 x_recv = scaled_div32(hc->rx_bytes_recv, delta);
682 if (x_recv == 0) {
683 DCCP_WARN("X_recv==0\n");
684 if (hc->rx_x_recv == 0) {
685 DCCP_BUG("stored value of X_recv is zero");
686 return ~0U;
687 }
688 x_recv = hc->rx_x_recv;
689 }
690
691 fval = scaled_div(hc->rx_s, hc->rx_rtt);
692 fval = scaled_div32(fval, x_recv);
693 p = tfrc_calc_x_reverse_lookup(fval);
694
695 ccid3_pr_debug("%s(%p), receive rate=%u bytes/s, implied "
696 "loss rate=%u\n", dccp_role(sk), sk, x_recv, p);
697
698 return p == 0 ? ~0U : scaled_div(1, p);
699}
700
701static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
702{
703 struct ccid3_hc_rx_sock *hc = ccid3_hc_rx_sk(sk);
704 enum ccid3_fback_type do_feedback = CCID3_FBACK_NONE;
705 const u64 ndp = dccp_sk(sk)->dccps_options_received.dccpor_ndp;
706 const bool is_data_packet = dccp_data_packet(skb);
707
708 if (unlikely(hc->rx_state == TFRC_RSTATE_NO_DATA)) {
709 if (is_data_packet) {
710 const u32 payload = skb->len - dccp_hdr(skb)->dccph_doff * 4;
711 do_feedback = CCID3_FBACK_INITIAL;
712 ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA);
713 hc->rx_s = payload;
714
715
716
717
718
719 }
720 goto update_records;
721 }
722
723 if (tfrc_rx_hist_duplicate(&hc->rx_hist, skb))
724 return;
725
726 if (is_data_packet) {
727 const u32 payload = skb->len - dccp_hdr(skb)->dccph_doff * 4;
728
729
730
731 hc->rx_s = tfrc_ewma(hc->rx_s, payload, 9);
732 hc->rx_bytes_recv += payload;
733 }
734
735
736
737
738 if (tfrc_rx_handle_loss(&hc->rx_hist, &hc->rx_li_hist,
739 skb, ndp, ccid3_first_li, sk)) {
740 do_feedback = CCID3_FBACK_PARAM_CHANGE;
741 goto done_receiving;
742 }
743
744 if (tfrc_rx_hist_loss_pending(&hc->rx_hist))
745 return;
746
747
748
749
750 if (unlikely(!is_data_packet))
751 goto update_records;
752
753 if (!tfrc_lh_is_initialised(&hc->rx_li_hist)) {
754 const u32 sample = tfrc_rx_hist_sample_rtt(&hc->rx_hist, skb);
755
756
757
758
759
760 if (sample != 0)
761 hc->rx_rtt = tfrc_ewma(hc->rx_rtt, sample, 9);
762
763 } else if (tfrc_lh_update_i_mean(&hc->rx_li_hist, skb)) {
764
765
766
767
768 do_feedback = CCID3_FBACK_PARAM_CHANGE;
769 }
770
771
772
773
774 if (SUB16(dccp_hdr(skb)->dccph_ccval, hc->rx_last_counter) > 3)
775 do_feedback = CCID3_FBACK_PERIODIC;
776
777update_records:
778 tfrc_rx_hist_add_packet(&hc->rx_hist, skb, ndp);
779
780done_receiving:
781 if (do_feedback)
782 ccid3_hc_rx_send_feedback(sk, skb, do_feedback);
783}
784
785static int ccid3_hc_rx_init(struct ccid *ccid, struct sock *sk)
786{
787 struct ccid3_hc_rx_sock *hc = ccid_priv(ccid);
788
789 hc->rx_state = TFRC_RSTATE_NO_DATA;
790 tfrc_lh_init(&hc->rx_li_hist);
791 return tfrc_rx_hist_alloc(&hc->rx_hist);
792}
793
794static void ccid3_hc_rx_exit(struct sock *sk)
795{
796 struct ccid3_hc_rx_sock *hc = ccid3_hc_rx_sk(sk);
797
798 tfrc_rx_hist_purge(&hc->rx_hist);
799 tfrc_lh_cleanup(&hc->rx_li_hist);
800}
801
802static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
803{
804 info->tcpi_ca_state = ccid3_hc_rx_sk(sk)->rx_state;
805 info->tcpi_options |= TCPI_OPT_TIMESTAMPS;
806 info->tcpi_rcv_rtt = ccid3_hc_rx_sk(sk)->rx_rtt;
807}
808
809static int ccid3_hc_rx_getsockopt(struct sock *sk, const int optname, int len,
810 u32 __user *optval, int __user *optlen)
811{
812 const struct ccid3_hc_rx_sock *hc = ccid3_hc_rx_sk(sk);
813 struct tfrc_rx_info rx_info;
814 const void *val;
815
816 switch (optname) {
817 case DCCP_SOCKOPT_CCID_RX_INFO:
818 if (len < sizeof(rx_info))
819 return -EINVAL;
820 rx_info.tfrcrx_x_recv = hc->rx_x_recv;
821 rx_info.tfrcrx_rtt = hc->rx_rtt;
822 rx_info.tfrcrx_p = tfrc_invert_loss_event_rate(hc->rx_pinv);
823 len = sizeof(rx_info);
824 val = &rx_info;
825 break;
826 default:
827 return -ENOPROTOOPT;
828 }
829
830 if (put_user(len, optlen) || copy_to_user(optval, val, len))
831 return -EFAULT;
832
833 return 0;
834}
835
836struct ccid_operations ccid3_ops = {
837 .ccid_id = DCCPC_CCID3,
838 .ccid_name = "TCP-Friendly Rate Control",
839 .ccid_hc_tx_obj_size = sizeof(struct ccid3_hc_tx_sock),
840 .ccid_hc_tx_init = ccid3_hc_tx_init,
841 .ccid_hc_tx_exit = ccid3_hc_tx_exit,
842 .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet,
843 .ccid_hc_tx_packet_sent = ccid3_hc_tx_packet_sent,
844 .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv,
845 .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options,
846 .ccid_hc_rx_obj_size = sizeof(struct ccid3_hc_rx_sock),
847 .ccid_hc_rx_init = ccid3_hc_rx_init,
848 .ccid_hc_rx_exit = ccid3_hc_rx_exit,
849 .ccid_hc_rx_insert_options = ccid3_hc_rx_insert_options,
850 .ccid_hc_rx_packet_recv = ccid3_hc_rx_packet_recv,
851 .ccid_hc_rx_get_info = ccid3_hc_rx_get_info,
852 .ccid_hc_tx_get_info = ccid3_hc_tx_get_info,
853 .ccid_hc_rx_getsockopt = ccid3_hc_rx_getsockopt,
854 .ccid_hc_tx_getsockopt = ccid3_hc_tx_getsockopt,
855};
856
857#ifdef CONFIG_IP_DCCP_CCID3_DEBUG
858module_param(ccid3_debug, bool, 0644);
859MODULE_PARM_DESC(ccid3_debug, "Enable CCID-3 debug messages");
860#endif
861