ackvec.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #ifndef _ACKVEC_H
  2. #define _ACKVEC_H
  3. /*
  4. * net/dccp/ackvec.h
  5. *
  6. * An implementation of Ack Vectors for the DCCP protocol
  7. * Copyright (c) 2007 University of Aberdeen, Scotland, UK
  8. * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@mandriva.com>
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/dccp.h>
  14. #include <linux/compiler.h>
  15. #include <linux/list.h>
  16. #include <linux/types.h>
  17. /*
  18. * Ack Vector buffer space is static, in multiples of %DCCP_SINGLE_OPT_MAXLEN,
  19. * the maximum size of a single Ack Vector. Setting %DCCPAV_NUM_ACKVECS to 1
  20. * will be sufficient for most cases of low Ack Ratios, using a value of 2 gives
  21. * more headroom if Ack Ratio is higher or when the sender acknowledges slowly.
  22. */
  23. #define DCCPAV_NUM_ACKVECS 2
  24. #define DCCPAV_MAX_ACKVEC_LEN (DCCP_SINGLE_OPT_MAXLEN * DCCPAV_NUM_ACKVECS)
  25. /* Estimated minimum average Ack Vector length - used for updating MPS */
  26. #define DCCPAV_MIN_OPTLEN 16
  27. enum dccp_ackvec_states {
  28. DCCPAV_RECEIVED = 0x00,
  29. DCCPAV_ECN_MARKED = 0x40,
  30. DCCPAV_RESERVED = 0x80,
  31. DCCPAV_NOT_RECEIVED = 0xC0
  32. };
  33. #define DCCPAV_MAX_RUNLEN 0x3F
  34. static inline u8 dccp_ackvec_runlen(const u8 *cell)
  35. {
  36. return *cell & DCCPAV_MAX_RUNLEN;
  37. }
  38. static inline u8 dccp_ackvec_state(const u8 *cell)
  39. {
  40. return *cell & ~DCCPAV_MAX_RUNLEN;
  41. }
  42. /** struct dccp_ackvec - Ack Vector main data structure
  43. *
  44. * This implements a fixed-size circular buffer within an array and is largely
  45. * based on Appendix A of RFC 4340.
  46. *
  47. * @av_buf: circular buffer storage area
  48. * @av_buf_head: head index; begin of live portion in @av_buf
  49. * @av_buf_tail: tail index; first index _after_ the live portion in @av_buf
  50. * @av_buf_ackno: highest seqno of acknowledgeable packet recorded in @av_buf
  51. * @av_buf_nonce: ECN nonce sums, each covering subsequent segments of up to
  52. * %DCCP_SINGLE_OPT_MAXLEN cells in the live portion of @av_buf
  53. * @av_records: list of %dccp_ackvec_record (Ack Vectors sent previously)
  54. * @av_veclen: length of the live portion of @av_buf
  55. */
  56. struct dccp_ackvec {
  57. u8 av_buf[DCCPAV_MAX_ACKVEC_LEN];
  58. u16 av_buf_head;
  59. u16 av_buf_tail;
  60. u64 av_buf_ackno:48;
  61. bool av_buf_nonce[DCCPAV_NUM_ACKVECS];
  62. struct list_head av_records;
  63. u16 av_vec_len;
  64. };
  65. /** struct dccp_ackvec_record - Records information about sent Ack Vectors
  66. *
  67. * These list entries define the additional information which the HC-Receiver
  68. * keeps about recently-sent Ack Vectors; again refer to RFC 4340, Appendix A.
  69. *
  70. * @avr_node: the list node in @av_records
  71. * @avr_ack_seqno: sequence number of the packet the Ack Vector was sent on
  72. * @avr_ack_ackno: the Ack number that this record/Ack Vector refers to
  73. * @avr_ack_ptr: pointer into @av_buf where this record starts
  74. * @avr_ack_runlen: run length of @avr_ack_ptr at the time of sending
  75. * @avr_ack_nonce: the sum of @av_buf_nonce's at the time this record was sent
  76. *
  77. * The list as a whole is sorted in descending order by @avr_ack_seqno.
  78. */
  79. struct dccp_ackvec_record {
  80. struct list_head avr_node;
  81. u64 avr_ack_seqno:48;
  82. u64 avr_ack_ackno:48;
  83. u16 avr_ack_ptr;
  84. u8 avr_ack_runlen;
  85. u8 avr_ack_nonce:1;
  86. };
  87. struct sock;
  88. struct sk_buff;
  89. #ifdef CONFIG_IP_DCCP_ACKVEC
  90. extern int dccp_ackvec_init(void);
  91. extern void dccp_ackvec_exit(void);
  92. extern struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority);
  93. extern void dccp_ackvec_free(struct dccp_ackvec *av);
  94. extern int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
  95. const u64 ackno, const u8 state);
  96. extern void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av,
  97. struct sock *sk, const u64 ackno);
  98. extern int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
  99. u64 *ackno, const u8 opt,
  100. const u8 *value, const u8 len);
  101. extern int dccp_ackvec_update_records(struct dccp_ackvec *av, u64 seq, u8 sum);
  102. static inline int dccp_ackvec_pending(const struct dccp_ackvec *av)
  103. {
  104. return av->av_vec_len;
  105. }
  106. #else /* CONFIG_IP_DCCP_ACKVEC */
  107. static inline int dccp_ackvec_init(void)
  108. {
  109. return 0;
  110. }
  111. static inline void dccp_ackvec_exit(void)
  112. {
  113. }
  114. static inline struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority)
  115. {
  116. return NULL;
  117. }
  118. static inline void dccp_ackvec_free(struct dccp_ackvec *av)
  119. {
  120. }
  121. static inline int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
  122. const u64 ackno, const u8 state)
  123. {
  124. return -1;
  125. }
  126. static inline void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av,
  127. struct sock *sk, const u64 ackno)
  128. {
  129. }
  130. static inline int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
  131. const u64 *ackno, const u8 opt,
  132. const u8 *value, const u8 len)
  133. {
  134. return -1;
  135. }
  136. static inline int dccp_ackvec_update_records(struct dccp_ackvec *av, u64 seq, u8 nonce)
  137. {
  138. return -1;
  139. }
  140. static inline int dccp_ackvec_pending(const struct dccp_ackvec *av)
  141. {
  142. return 0;
  143. }
  144. #endif /* CONFIG_IP_DCCP_ACKVEC */
  145. #endif /* _ACKVEC_H */