ackvec.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #ifndef _ACKVEC_H
  2. #define _ACKVEC_H
  3. /*
  4. * net/dccp/ackvec.h
  5. *
  6. * An implementation of the DCCP protocol
  7. * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@mandriva.com>
  8. *
  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/compiler.h>
  14. #include <linux/list.h>
  15. #include <linux/time.h>
  16. #include <linux/types.h>
  17. /* Read about the ECN nonce to see why it is 253 */
  18. #define DCCP_MAX_ACKVEC_OPT_LEN 253
  19. /* We can spread an ack vector across multiple options */
  20. #define DCCP_MAX_ACKVEC_LEN (DCCP_MAX_ACKVEC_OPT_LEN * 2)
  21. #define DCCP_ACKVEC_STATE_RECEIVED 0
  22. #define DCCP_ACKVEC_STATE_ECN_MARKED (1 << 6)
  23. #define DCCP_ACKVEC_STATE_NOT_RECEIVED (3 << 6)
  24. #define DCCP_ACKVEC_STATE_MASK 0xC0 /* 11000000 */
  25. #define DCCP_ACKVEC_LEN_MASK 0x3F /* 00111111 */
  26. /** struct dccp_ackvec - ack vector
  27. *
  28. * This data structure is the one defined in RFC 4340, Appendix A.
  29. *
  30. * @dccpav_buf_head - circular buffer head
  31. * @dccpav_buf_tail - circular buffer tail
  32. * @dccpav_buf_ackno - ack # of the most recent packet acknowledgeable in the
  33. * buffer (i.e. %dccpav_buf_head)
  34. * @dccpav_buf_nonce - the one-bit sum of the ECN Nonces on all packets acked
  35. * by the buffer with State 0
  36. *
  37. * Additionally, the HC-Receiver must keep some information about the
  38. * Ack Vectors it has recently sent. For each packet sent carrying an
  39. * Ack Vector, it remembers four variables:
  40. *
  41. * @dccpav_records - list of dccp_ackvec_record
  42. * @dccpav_ack_nonce - the one-bit sum of the ECN Nonces for all State 0.
  43. *
  44. * @dccpav_time - the time in usecs
  45. * @dccpav_buf - circular buffer of acknowledgeable packets
  46. */
  47. struct dccp_ackvec {
  48. u64 dccpav_buf_ackno;
  49. struct list_head dccpav_records;
  50. struct timeval dccpav_time;
  51. u16 dccpav_buf_head;
  52. u16 dccpav_vec_len;
  53. u8 dccpav_buf_nonce;
  54. u8 dccpav_ack_nonce;
  55. u8 dccpav_buf[DCCP_MAX_ACKVEC_LEN];
  56. };
  57. /** struct dccp_ackvec_record - ack vector record
  58. *
  59. * ACK vector record as defined in Appendix A of spec.
  60. *
  61. * The list is sorted by dccpavr_ack_seqno
  62. *
  63. * @dccpavr_node - node in dccpav_records
  64. * @dccpavr_ack_seqno - sequence number of the packet this record was sent on
  65. * @dccpavr_ack_ackno - sequence number being acknowledged
  66. * @dccpavr_ack_ptr - pointer into dccpav_buf where this record starts
  67. * @dccpavr_ack_nonce - dccpav_ack_nonce at the time this record was sent
  68. * @dccpavr_sent_len - lenght of the record in dccpav_buf
  69. */
  70. struct dccp_ackvec_record {
  71. struct list_head dccpavr_node;
  72. u64 dccpavr_ack_seqno;
  73. u64 dccpavr_ack_ackno;
  74. u16 dccpavr_ack_ptr;
  75. u16 dccpavr_sent_len;
  76. u8 dccpavr_ack_nonce;
  77. };
  78. struct sock;
  79. struct sk_buff;
  80. #ifdef CONFIG_IP_DCCP_ACKVEC
  81. extern int dccp_ackvec_init(void);
  82. extern void dccp_ackvec_exit(void);
  83. extern struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority);
  84. extern void dccp_ackvec_free(struct dccp_ackvec *av);
  85. extern int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
  86. const u64 ackno, const u8 state);
  87. extern void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av,
  88. struct sock *sk, const u64 ackno);
  89. extern int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
  90. u64 *ackno, const u8 opt,
  91. const u8 *value, const u8 len);
  92. extern int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb);
  93. static inline int dccp_ackvec_pending(const struct dccp_ackvec *av)
  94. {
  95. return av->dccpav_vec_len;
  96. }
  97. #else /* CONFIG_IP_DCCP_ACKVEC */
  98. static inline int dccp_ackvec_init(void)
  99. {
  100. return 0;
  101. }
  102. static inline void dccp_ackvec_exit(void)
  103. {
  104. }
  105. static inline struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority)
  106. {
  107. return NULL;
  108. }
  109. static inline void dccp_ackvec_free(struct dccp_ackvec *av)
  110. {
  111. }
  112. static inline int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
  113. const u64 ackno, const u8 state)
  114. {
  115. return -1;
  116. }
  117. static inline void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av,
  118. struct sock *sk, const u64 ackno)
  119. {
  120. }
  121. static inline int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
  122. const u64 *ackno, const u8 opt,
  123. const u8 *value, const u8 len)
  124. {
  125. return -1;
  126. }
  127. static inline int dccp_insert_option_ackvec(const struct sock *sk,
  128. const struct sk_buff *skb)
  129. {
  130. return -1;
  131. }
  132. static inline int dccp_ackvec_pending(const struct dccp_ackvec *av)
  133. {
  134. return 0;
  135. }
  136. #endif /* CONFIG_IP_DCCP_ACKVEC */
  137. #endif /* _ACKVEC_H */