ccid.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #ifndef _CCID_H
  2. #define _CCID_H
  3. /*
  4. * net/dccp/ccid.h
  5. *
  6. * An implementation of the DCCP protocol
  7. * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  8. *
  9. * CCID infrastructure
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <net/sock.h>
  16. #include <linux/compiler.h>
  17. #include <linux/dccp.h>
  18. #include <linux/list.h>
  19. #include <linux/module.h>
  20. /* maximum value for a CCID (RFC 4340, 19.5) */
  21. #define CCID_MAX 255
  22. #define CCID_SLAB_NAME_LENGTH 32
  23. struct tcp_info;
  24. /**
  25. * struct ccid_operations - Interface to Congestion-Control Infrastructure
  26. *
  27. * @ccid_id: numerical CCID ID (up to %CCID_MAX, cf. table 5 in RFC 4340, 10.)
  28. * @ccid_ccmps: the CCMPS including network/transport headers (0 when disabled)
  29. * @ccid_name: alphabetical identifier string for @ccid_id
  30. * @ccid_hc_{r,t}x_slab: memory pool for the receiver/sender half-connection
  31. * @ccid_hc_{r,t}x_obj_size: size of the receiver/sender half-connection socket
  32. *
  33. * @ccid_hc_{r,t}x_init: CCID-specific initialisation routine (before startup)
  34. * @ccid_hc_{r,t}x_exit: CCID-specific cleanup routine (before destruction)
  35. * @ccid_hc_rx_packet_recv: implements the HC-receiver side
  36. * @ccid_hc_{r,t}x_parse_options: parsing routine for CCID/HC-specific options
  37. * @ccid_hc_{r,t}x_insert_options: insert routine for CCID/HC-specific options
  38. * @ccid_hc_tx_packet_recv: implements feedback processing for the HC-sender
  39. * @ccid_hc_tx_send_packet: implements the sending part of the HC-sender
  40. * @ccid_hc_tx_packet_sent: does accounting for packets in flight by HC-sender
  41. * @ccid_hc_{r,t}x_get_info: INET_DIAG information for HC-receiver/sender
  42. * @ccid_hc_{r,t}x_getsockopt: socket options specific to HC-receiver/sender
  43. */
  44. struct ccid_operations {
  45. unsigned char ccid_id;
  46. __u32 ccid_ccmps;
  47. const char *ccid_name;
  48. struct kmem_cache *ccid_hc_rx_slab,
  49. *ccid_hc_tx_slab;
  50. char ccid_hc_rx_slab_name[CCID_SLAB_NAME_LENGTH];
  51. char ccid_hc_tx_slab_name[CCID_SLAB_NAME_LENGTH];
  52. __u32 ccid_hc_rx_obj_size,
  53. ccid_hc_tx_obj_size;
  54. /* Interface Routines */
  55. int (*ccid_hc_rx_init)(struct ccid *ccid, struct sock *sk);
  56. int (*ccid_hc_tx_init)(struct ccid *ccid, struct sock *sk);
  57. void (*ccid_hc_rx_exit)(struct sock *sk);
  58. void (*ccid_hc_tx_exit)(struct sock *sk);
  59. void (*ccid_hc_rx_packet_recv)(struct sock *sk,
  60. struct sk_buff *skb);
  61. int (*ccid_hc_rx_parse_options)(struct sock *sk, u8 pkt,
  62. u8 opt, u8 *val, u8 len);
  63. int (*ccid_hc_rx_insert_options)(struct sock *sk,
  64. struct sk_buff *skb);
  65. void (*ccid_hc_tx_packet_recv)(struct sock *sk,
  66. struct sk_buff *skb);
  67. int (*ccid_hc_tx_parse_options)(struct sock *sk, u8 pkt,
  68. u8 opt, u8 *val, u8 len);
  69. int (*ccid_hc_tx_send_packet)(struct sock *sk,
  70. struct sk_buff *skb);
  71. void (*ccid_hc_tx_packet_sent)(struct sock *sk,
  72. unsigned int len);
  73. void (*ccid_hc_rx_get_info)(struct sock *sk,
  74. struct tcp_info *info);
  75. void (*ccid_hc_tx_get_info)(struct sock *sk,
  76. struct tcp_info *info);
  77. int (*ccid_hc_rx_getsockopt)(struct sock *sk,
  78. const int optname, int len,
  79. u32 __user *optval,
  80. int __user *optlen);
  81. int (*ccid_hc_tx_getsockopt)(struct sock *sk,
  82. const int optname, int len,
  83. u32 __user *optval,
  84. int __user *optlen);
  85. };
  86. extern struct ccid_operations ccid2_ops;
  87. #ifdef CONFIG_IP_DCCP_CCID3
  88. extern struct ccid_operations ccid3_ops;
  89. #endif
  90. int ccid_initialize_builtins(void);
  91. void ccid_cleanup_builtins(void);
  92. struct ccid {
  93. struct ccid_operations *ccid_ops;
  94. char ccid_priv[0];
  95. };
  96. static inline void *ccid_priv(const struct ccid *ccid)
  97. {
  98. return (void *)ccid->ccid_priv;
  99. }
  100. bool ccid_support_check(u8 const *ccid_array, u8 array_len);
  101. int ccid_get_builtin_ccids(u8 **ccid_array, u8 *array_len);
  102. int ccid_getsockopt_builtin_ccids(struct sock *sk, int len,
  103. char __user *, int __user *);
  104. struct ccid *ccid_new(const u8 id, struct sock *sk, bool rx);
  105. static inline int ccid_get_current_rx_ccid(struct dccp_sock *dp)
  106. {
  107. struct ccid *ccid = dp->dccps_hc_rx_ccid;
  108. if (ccid == NULL || ccid->ccid_ops == NULL)
  109. return -1;
  110. return ccid->ccid_ops->ccid_id;
  111. }
  112. static inline int ccid_get_current_tx_ccid(struct dccp_sock *dp)
  113. {
  114. struct ccid *ccid = dp->dccps_hc_tx_ccid;
  115. if (ccid == NULL || ccid->ccid_ops == NULL)
  116. return -1;
  117. return ccid->ccid_ops->ccid_id;
  118. }
  119. void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk);
  120. void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk);
  121. /*
  122. * Congestion control of queued data packets via CCID decision.
  123. *
  124. * The TX CCID performs its congestion-control by indicating whether and when a
  125. * queued packet may be sent, using the return code of ccid_hc_tx_send_packet().
  126. * The following modes are supported via the symbolic constants below:
  127. * - timer-based pacing (CCID returns a delay value in milliseconds);
  128. * - autonomous dequeueing (CCID internally schedules dccps_xmitlet).
  129. */
  130. enum ccid_dequeueing_decision {
  131. CCID_PACKET_SEND_AT_ONCE = 0x00000, /* "green light": no delay */
  132. CCID_PACKET_DELAY_MAX = 0x0FFFF, /* maximum delay in msecs */
  133. CCID_PACKET_DELAY = 0x10000, /* CCID msec-delay mode */
  134. CCID_PACKET_WILL_DEQUEUE_LATER = 0x20000, /* CCID autonomous mode */
  135. CCID_PACKET_ERR = 0xF0000, /* error condition */
  136. };
  137. static inline int ccid_packet_dequeue_eval(const int return_code)
  138. {
  139. if (return_code < 0)
  140. return CCID_PACKET_ERR;
  141. if (return_code == 0)
  142. return CCID_PACKET_SEND_AT_ONCE;
  143. if (return_code <= CCID_PACKET_DELAY_MAX)
  144. return CCID_PACKET_DELAY;
  145. return return_code;
  146. }
  147. static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
  148. struct sk_buff *skb)
  149. {
  150. if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
  151. return ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb);
  152. return CCID_PACKET_SEND_AT_ONCE;
  153. }
  154. static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk,
  155. unsigned int len)
  156. {
  157. if (ccid->ccid_ops->ccid_hc_tx_packet_sent != NULL)
  158. ccid->ccid_ops->ccid_hc_tx_packet_sent(sk, len);
  159. }
  160. static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk,
  161. struct sk_buff *skb)
  162. {
  163. if (ccid->ccid_ops->ccid_hc_rx_packet_recv != NULL)
  164. ccid->ccid_ops->ccid_hc_rx_packet_recv(sk, skb);
  165. }
  166. static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk,
  167. struct sk_buff *skb)
  168. {
  169. if (ccid->ccid_ops->ccid_hc_tx_packet_recv != NULL)
  170. ccid->ccid_ops->ccid_hc_tx_packet_recv(sk, skb);
  171. }
  172. /**
  173. * ccid_hc_tx_parse_options - Parse CCID-specific options sent by the receiver
  174. * @pkt: type of packet that @opt appears on (RFC 4340, 5.1)
  175. * @opt: the CCID-specific option type (RFC 4340, 5.8 and 10.3)
  176. * @val: value of @opt
  177. * @len: length of @val in bytes
  178. */
  179. static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk,
  180. u8 pkt, u8 opt, u8 *val, u8 len)
  181. {
  182. if (!ccid || !ccid->ccid_ops->ccid_hc_tx_parse_options)
  183. return 0;
  184. return ccid->ccid_ops->ccid_hc_tx_parse_options(sk, pkt, opt, val, len);
  185. }
  186. /**
  187. * ccid_hc_rx_parse_options - Parse CCID-specific options sent by the sender
  188. * Arguments are analogous to ccid_hc_tx_parse_options()
  189. */
  190. static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk,
  191. u8 pkt, u8 opt, u8 *val, u8 len)
  192. {
  193. if (!ccid || !ccid->ccid_ops->ccid_hc_rx_parse_options)
  194. return 0;
  195. return ccid->ccid_ops->ccid_hc_rx_parse_options(sk, pkt, opt, val, len);
  196. }
  197. static inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk,
  198. struct sk_buff *skb)
  199. {
  200. if (ccid->ccid_ops->ccid_hc_rx_insert_options != NULL)
  201. return ccid->ccid_ops->ccid_hc_rx_insert_options(sk, skb);
  202. return 0;
  203. }
  204. static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk,
  205. struct tcp_info *info)
  206. {
  207. if (ccid->ccid_ops->ccid_hc_rx_get_info != NULL)
  208. ccid->ccid_ops->ccid_hc_rx_get_info(sk, info);
  209. }
  210. static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk,
  211. struct tcp_info *info)
  212. {
  213. if (ccid->ccid_ops->ccid_hc_tx_get_info != NULL)
  214. ccid->ccid_ops->ccid_hc_tx_get_info(sk, info);
  215. }
  216. static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
  217. const int optname, int len,
  218. u32 __user *optval, int __user *optlen)
  219. {
  220. int rc = -ENOPROTOOPT;
  221. if (ccid != NULL && ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
  222. rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len,
  223. optval, optlen);
  224. return rc;
  225. }
  226. static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
  227. const int optname, int len,
  228. u32 __user *optval, int __user *optlen)
  229. {
  230. int rc = -ENOPROTOOPT;
  231. if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
  232. rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len,
  233. optval, optlen);
  234. return rc;
  235. }
  236. #endif /* _CCID_H */