ccid.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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_hc_{r,t}x_slab: memory pool for the receiver/sender half-connection
  29. * @ccid_hc_{r,t}x_obj_size: size of the receiver/sender half-connection socket
  30. *
  31. * @ccid_hc_{r,t}x_init: CCID-specific initialisation routine (before startup)
  32. * @ccid_hc_{r,t}x_exit: CCID-specific cleanup routine (before destruction)
  33. * @ccid_hc_rx_packet_recv: implements the HC-receiver side
  34. * @ccid_hc_{r,t}x_parse_options: parsing routine for CCID/HC-specific options
  35. * @ccid_hc_{r,t}x_insert_options: insert routine for CCID/HC-specific options
  36. * @ccid_hc_tx_packet_recv: implements feedback processing for the HC-sender
  37. * @ccid_hc_tx_send_packet: implements the sending part of the HC-sender
  38. * @ccid_hc_tx_packet_sent: does accounting for packets in flight by HC-sender
  39. * @ccid_hc_{r,t}x_get_info: INET_DIAG information for HC-receiver/sender
  40. * @ccid_hc_{r,t}x_getsockopt: socket options specific to HC-receiver/sender
  41. */
  42. struct ccid_operations {
  43. unsigned char ccid_id;
  44. __u32 ccid_ccmps;
  45. const char *ccid_name;
  46. struct kmem_cache *ccid_hc_rx_slab,
  47. *ccid_hc_tx_slab;
  48. __u32 ccid_hc_rx_obj_size,
  49. ccid_hc_tx_obj_size;
  50. /* Interface Routines */
  51. int (*ccid_hc_rx_init)(struct ccid *ccid, struct sock *sk);
  52. int (*ccid_hc_tx_init)(struct ccid *ccid, struct sock *sk);
  53. void (*ccid_hc_rx_exit)(struct sock *sk);
  54. void (*ccid_hc_tx_exit)(struct sock *sk);
  55. void (*ccid_hc_rx_packet_recv)(struct sock *sk,
  56. struct sk_buff *skb);
  57. int (*ccid_hc_rx_parse_options)(struct sock *sk,
  58. unsigned char option,
  59. unsigned char len, u16 idx,
  60. unsigned char* value);
  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,
  66. unsigned char option,
  67. unsigned char len, u16 idx,
  68. unsigned char* value);
  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. int more, 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. extern int ccid_initialize_builtins(void);
  91. extern 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. extern bool ccid_support_check(u8 const *ccid_array, u8 array_len);
  101. extern int ccid_get_builtin_ccids(u8 **ccid_array, u8 *array_len);
  102. extern int ccid_getsockopt_builtin_ccids(struct sock *sk, int len,
  103. char __user *, int __user *);
  104. extern 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. extern void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk);
  120. extern void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk);
  121. static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
  122. struct sk_buff *skb)
  123. {
  124. int rc = 0;
  125. if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
  126. rc = ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb);
  127. return rc;
  128. }
  129. static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk,
  130. int more, unsigned int len)
  131. {
  132. if (ccid->ccid_ops->ccid_hc_tx_packet_sent != NULL)
  133. ccid->ccid_ops->ccid_hc_tx_packet_sent(sk, more, len);
  134. }
  135. static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk,
  136. struct sk_buff *skb)
  137. {
  138. if (ccid->ccid_ops->ccid_hc_rx_packet_recv != NULL)
  139. ccid->ccid_ops->ccid_hc_rx_packet_recv(sk, skb);
  140. }
  141. static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk,
  142. struct sk_buff *skb)
  143. {
  144. if (ccid->ccid_ops->ccid_hc_tx_packet_recv != NULL)
  145. ccid->ccid_ops->ccid_hc_tx_packet_recv(sk, skb);
  146. }
  147. static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk,
  148. unsigned char option,
  149. unsigned char len, u16 idx,
  150. unsigned char* value)
  151. {
  152. int rc = 0;
  153. if (ccid->ccid_ops->ccid_hc_tx_parse_options != NULL)
  154. rc = ccid->ccid_ops->ccid_hc_tx_parse_options(sk, option, len, idx,
  155. value);
  156. return rc;
  157. }
  158. static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk,
  159. unsigned char option,
  160. unsigned char len, u16 idx,
  161. unsigned char* value)
  162. {
  163. int rc = 0;
  164. if (ccid->ccid_ops->ccid_hc_rx_parse_options != NULL)
  165. rc = ccid->ccid_ops->ccid_hc_rx_parse_options(sk, option, len, idx, value);
  166. return rc;
  167. }
  168. static inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk,
  169. struct sk_buff *skb)
  170. {
  171. if (ccid->ccid_ops->ccid_hc_rx_insert_options != NULL)
  172. return ccid->ccid_ops->ccid_hc_rx_insert_options(sk, skb);
  173. return 0;
  174. }
  175. static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk,
  176. struct tcp_info *info)
  177. {
  178. if (ccid->ccid_ops->ccid_hc_rx_get_info != NULL)
  179. ccid->ccid_ops->ccid_hc_rx_get_info(sk, info);
  180. }
  181. static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk,
  182. struct tcp_info *info)
  183. {
  184. if (ccid->ccid_ops->ccid_hc_tx_get_info != NULL)
  185. ccid->ccid_ops->ccid_hc_tx_get_info(sk, info);
  186. }
  187. static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
  188. const int optname, int len,
  189. u32 __user *optval, int __user *optlen)
  190. {
  191. int rc = -ENOPROTOOPT;
  192. if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
  193. rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len,
  194. optval, optlen);
  195. return rc;
  196. }
  197. static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
  198. const int optname, int len,
  199. u32 __user *optval, int __user *optlen)
  200. {
  201. int rc = -ENOPROTOOPT;
  202. if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
  203. rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len,
  204. optval, optlen);
  205. return rc;
  206. }
  207. #endif /* _CCID_H */