ccid2.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (c) 2005 Andrea Bittau <[email protected]>
  4. */
  5. #ifndef _DCCP_CCID2_H_
  6. #define _DCCP_CCID2_H_
  7. #include <linux/timer.h>
  8. #include <linux/types.h>
  9. #include "../ccid.h"
  10. #include "../dccp.h"
  11. /*
  12. * CCID-2 timestamping faces the same issues as TCP timestamping.
  13. * Hence we reuse/share as much of the code as possible.
  14. */
  15. #define ccid2_jiffies32 ((u32)jiffies)
  16. /* NUMDUPACK parameter from RFC 4341, p. 6 */
  17. #define NUMDUPACK 3
  18. struct ccid2_seq {
  19. u64 ccid2s_seq;
  20. u32 ccid2s_sent;
  21. int ccid2s_acked;
  22. struct ccid2_seq *ccid2s_prev;
  23. struct ccid2_seq *ccid2s_next;
  24. };
  25. #define CCID2_SEQBUF_LEN 1024
  26. #define CCID2_SEQBUF_MAX 128
  27. /*
  28. * Multiple of congestion window to keep the sequence window at
  29. * (RFC 4340 7.5.2)
  30. */
  31. #define CCID2_WIN_CHANGE_FACTOR 5
  32. /**
  33. * struct ccid2_hc_tx_sock - CCID2 TX half connection
  34. * @tx_{cwnd,ssthresh,pipe}: as per RFC 4341, section 5
  35. * @tx_packets_acked: Ack counter for deriving cwnd growth (RFC 3465)
  36. * @tx_srtt: smoothed RTT estimate, scaled by 2^3
  37. * @tx_mdev: smoothed RTT variation, scaled by 2^2
  38. * @tx_mdev_max: maximum of @mdev during one flight
  39. * @tx_rttvar: moving average/maximum of @mdev_max
  40. * @tx_rto: RTO value deriving from SRTT and RTTVAR (RFC 2988)
  41. * @tx_rtt_seq: to decay RTTVAR at most once per flight
  42. * @tx_cwnd_used: actually used cwnd, W_used of RFC 2861
  43. * @tx_expected_wnd: moving average of @tx_cwnd_used
  44. * @tx_cwnd_stamp: to track idle periods in CWV
  45. * @tx_lsndtime: last time (in jiffies) a data packet was sent
  46. * @tx_rpseq: last consecutive seqno
  47. * @tx_rpdupack: dupacks since rpseq
  48. * @tx_av_chunks: list of Ack Vectors received on current skb
  49. */
  50. struct ccid2_hc_tx_sock {
  51. u32 tx_cwnd;
  52. u32 tx_ssthresh;
  53. u32 tx_pipe;
  54. u32 tx_packets_acked;
  55. struct ccid2_seq *tx_seqbuf[CCID2_SEQBUF_MAX];
  56. int tx_seqbufc;
  57. struct ccid2_seq *tx_seqh;
  58. struct ccid2_seq *tx_seqt;
  59. /* RTT measurement: variables/principles are the same as in TCP */
  60. u32 tx_srtt,
  61. tx_mdev,
  62. tx_mdev_max,
  63. tx_rttvar,
  64. tx_rto;
  65. u64 tx_rtt_seq:48;
  66. struct timer_list tx_rtotimer;
  67. struct sock *sk;
  68. /* Congestion Window validation (optional, RFC 2861) */
  69. u32 tx_cwnd_used,
  70. tx_expected_wnd,
  71. tx_cwnd_stamp,
  72. tx_lsndtime;
  73. u64 tx_rpseq;
  74. int tx_rpdupack;
  75. u32 tx_last_cong;
  76. u64 tx_high_ack;
  77. struct list_head tx_av_chunks;
  78. };
  79. static inline bool ccid2_cwnd_network_limited(struct ccid2_hc_tx_sock *hc)
  80. {
  81. return hc->tx_pipe >= hc->tx_cwnd;
  82. }
  83. /*
  84. * Convert RFC 3390 larger initial window into an equivalent number of packets.
  85. * This is based on the numbers specified in RFC 5681, 3.1.
  86. */
  87. static inline u32 rfc3390_bytes_to_packets(const u32 smss)
  88. {
  89. return smss <= 1095 ? 4 : (smss > 2190 ? 2 : 3);
  90. }
  91. /**
  92. * struct ccid2_hc_rx_sock - Receiving end of CCID-2 half-connection
  93. * @rx_num_data_pkts: number of data packets received since last feedback
  94. */
  95. struct ccid2_hc_rx_sock {
  96. u32 rx_num_data_pkts;
  97. };
  98. static inline struct ccid2_hc_tx_sock *ccid2_hc_tx_sk(const struct sock *sk)
  99. {
  100. return ccid_priv(dccp_sk(sk)->dccps_hc_tx_ccid);
  101. }
  102. static inline struct ccid2_hc_rx_sock *ccid2_hc_rx_sk(const struct sock *sk)
  103. {
  104. return ccid_priv(dccp_sk(sk)->dccps_hc_rx_ccid);
  105. }
  106. #endif /* _DCCP_CCID2_H_ */