ccid.h 8.7 KB

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