ccid.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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(unsigned char id, struct sock *sk, int rx,
  105. gfp_t gfp);
  106. static inline int ccid_get_current_rx_ccid(struct dccp_sock *dp)
  107. {
  108. struct ccid *ccid = dp->dccps_hc_rx_ccid;
  109. if (ccid == NULL || ccid->ccid_ops == NULL)
  110. return -1;
  111. return ccid->ccid_ops->ccid_id;
  112. }
  113. static inline int ccid_get_current_tx_ccid(struct dccp_sock *dp)
  114. {
  115. struct ccid *ccid = dp->dccps_hc_tx_ccid;
  116. if (ccid == NULL || ccid->ccid_ops == NULL)
  117. return -1;
  118. return ccid->ccid_ops->ccid_id;
  119. }
  120. extern void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk);
  121. extern void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk);
  122. static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
  123. struct sk_buff *skb)
  124. {
  125. int rc = 0;
  126. if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
  127. rc = ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb);
  128. return rc;
  129. }
  130. static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk,
  131. int more, unsigned int len)
  132. {
  133. if (ccid->ccid_ops->ccid_hc_tx_packet_sent != NULL)
  134. ccid->ccid_ops->ccid_hc_tx_packet_sent(sk, more, len);
  135. }
  136. static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk,
  137. struct sk_buff *skb)
  138. {
  139. if (ccid->ccid_ops->ccid_hc_rx_packet_recv != NULL)
  140. ccid->ccid_ops->ccid_hc_rx_packet_recv(sk, skb);
  141. }
  142. static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk,
  143. struct sk_buff *skb)
  144. {
  145. if (ccid->ccid_ops->ccid_hc_tx_packet_recv != NULL)
  146. ccid->ccid_ops->ccid_hc_tx_packet_recv(sk, skb);
  147. }
  148. static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk,
  149. unsigned char option,
  150. unsigned char len, u16 idx,
  151. unsigned char* value)
  152. {
  153. int rc = 0;
  154. if (ccid->ccid_ops->ccid_hc_tx_parse_options != NULL)
  155. rc = ccid->ccid_ops->ccid_hc_tx_parse_options(sk, option, len, idx,
  156. value);
  157. return rc;
  158. }
  159. static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk,
  160. unsigned char option,
  161. unsigned char len, u16 idx,
  162. unsigned char* value)
  163. {
  164. int rc = 0;
  165. if (ccid->ccid_ops->ccid_hc_rx_parse_options != NULL)
  166. rc = ccid->ccid_ops->ccid_hc_rx_parse_options(sk, option, len, idx, value);
  167. return rc;
  168. }
  169. static inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk,
  170. struct sk_buff *skb)
  171. {
  172. if (ccid->ccid_ops->ccid_hc_rx_insert_options != NULL)
  173. return ccid->ccid_ops->ccid_hc_rx_insert_options(sk, skb);
  174. return 0;
  175. }
  176. static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk,
  177. struct tcp_info *info)
  178. {
  179. if (ccid->ccid_ops->ccid_hc_rx_get_info != NULL)
  180. ccid->ccid_ops->ccid_hc_rx_get_info(sk, info);
  181. }
  182. static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk,
  183. struct tcp_info *info)
  184. {
  185. if (ccid->ccid_ops->ccid_hc_tx_get_info != NULL)
  186. ccid->ccid_ops->ccid_hc_tx_get_info(sk, info);
  187. }
  188. static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
  189. const int optname, int len,
  190. u32 __user *optval, int __user *optlen)
  191. {
  192. int rc = -ENOPROTOOPT;
  193. if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
  194. rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len,
  195. optval, optlen);
  196. return rc;
  197. }
  198. static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
  199. const int optname, int len,
  200. u32 __user *optval, int __user *optlen)
  201. {
  202. int rc = -ENOPROTOOPT;
  203. if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
  204. rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len,
  205. optval, optlen);
  206. return rc;
  207. }
  208. #endif /* _CCID_H */