ccid.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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,
  60. unsigned char option,
  61. unsigned char len, u16 idx,
  62. unsigned char* value);
  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,
  68. unsigned char option,
  69. unsigned char len, u16 idx,
  70. unsigned char* value);
  71. int (*ccid_hc_tx_send_packet)(struct sock *sk,
  72. struct sk_buff *skb);
  73. void (*ccid_hc_tx_packet_sent)(struct sock *sk,
  74. int more, unsigned int len);
  75. void (*ccid_hc_rx_get_info)(struct sock *sk,
  76. struct tcp_info *info);
  77. void (*ccid_hc_tx_get_info)(struct sock *sk,
  78. struct tcp_info *info);
  79. int (*ccid_hc_rx_getsockopt)(struct sock *sk,
  80. const int optname, int len,
  81. u32 __user *optval,
  82. int __user *optlen);
  83. int (*ccid_hc_tx_getsockopt)(struct sock *sk,
  84. const int optname, int len,
  85. u32 __user *optval,
  86. int __user *optlen);
  87. };
  88. extern int ccid_register(struct ccid_operations *ccid_ops);
  89. extern int ccid_unregister(struct ccid_operations *ccid_ops);
  90. struct ccid {
  91. struct ccid_operations *ccid_ops;
  92. char ccid_priv[0];
  93. };
  94. static inline void *ccid_priv(const struct ccid *ccid)
  95. {
  96. return (void *)ccid->ccid_priv;
  97. }
  98. extern bool ccid_support_check(u8 const *ccid_array, u8 array_len);
  99. extern int ccid_get_builtin_ccids(u8 **ccid_array, u8 *array_len);
  100. extern int ccid_getsockopt_builtin_ccids(struct sock *sk, int len,
  101. char __user *, int __user *);
  102. extern struct ccid *ccid_new(unsigned char id, struct sock *sk, int rx,
  103. gfp_t gfp);
  104. static inline int ccid_get_current_rx_ccid(struct dccp_sock *dp)
  105. {
  106. struct ccid *ccid = dp->dccps_hc_rx_ccid;
  107. if (ccid == NULL || ccid->ccid_ops == NULL)
  108. return -1;
  109. return ccid->ccid_ops->ccid_id;
  110. }
  111. static inline int ccid_get_current_tx_ccid(struct dccp_sock *dp)
  112. {
  113. struct ccid *ccid = dp->dccps_hc_tx_ccid;
  114. if (ccid == NULL || ccid->ccid_ops == NULL)
  115. return -1;
  116. return ccid->ccid_ops->ccid_id;
  117. }
  118. extern void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk);
  119. extern void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk);
  120. static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
  121. struct sk_buff *skb)
  122. {
  123. int rc = 0;
  124. if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
  125. rc = ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb);
  126. return rc;
  127. }
  128. static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk,
  129. int more, unsigned int len)
  130. {
  131. if (ccid->ccid_ops->ccid_hc_tx_packet_sent != NULL)
  132. ccid->ccid_ops->ccid_hc_tx_packet_sent(sk, more, len);
  133. }
  134. static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk,
  135. struct sk_buff *skb)
  136. {
  137. if (ccid->ccid_ops->ccid_hc_rx_packet_recv != NULL)
  138. ccid->ccid_ops->ccid_hc_rx_packet_recv(sk, skb);
  139. }
  140. static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk,
  141. struct sk_buff *skb)
  142. {
  143. if (ccid->ccid_ops->ccid_hc_tx_packet_recv != NULL)
  144. ccid->ccid_ops->ccid_hc_tx_packet_recv(sk, skb);
  145. }
  146. static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk,
  147. unsigned char option,
  148. unsigned char len, u16 idx,
  149. unsigned char* value)
  150. {
  151. int rc = 0;
  152. if (ccid->ccid_ops->ccid_hc_tx_parse_options != NULL)
  153. rc = ccid->ccid_ops->ccid_hc_tx_parse_options(sk, option, len, idx,
  154. value);
  155. return rc;
  156. }
  157. static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk,
  158. unsigned char option,
  159. unsigned char len, u16 idx,
  160. unsigned char* value)
  161. {
  162. int rc = 0;
  163. if (ccid->ccid_ops->ccid_hc_rx_parse_options != NULL)
  164. rc = ccid->ccid_ops->ccid_hc_rx_parse_options(sk, option, len, idx, value);
  165. return rc;
  166. }
  167. static inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk,
  168. struct sk_buff *skb)
  169. {
  170. if (ccid->ccid_ops->ccid_hc_rx_insert_options != NULL)
  171. return ccid->ccid_ops->ccid_hc_rx_insert_options(sk, skb);
  172. return 0;
  173. }
  174. static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk,
  175. struct tcp_info *info)
  176. {
  177. if (ccid->ccid_ops->ccid_hc_rx_get_info != NULL)
  178. ccid->ccid_ops->ccid_hc_rx_get_info(sk, info);
  179. }
  180. static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk,
  181. struct tcp_info *info)
  182. {
  183. if (ccid->ccid_ops->ccid_hc_tx_get_info != NULL)
  184. ccid->ccid_ops->ccid_hc_tx_get_info(sk, info);
  185. }
  186. static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
  187. const int optname, int len,
  188. u32 __user *optval, int __user *optlen)
  189. {
  190. int rc = -ENOPROTOOPT;
  191. if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
  192. rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len,
  193. optval, optlen);
  194. return rc;
  195. }
  196. static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
  197. const int optname, int len,
  198. u32 __user *optval, int __user *optlen)
  199. {
  200. int rc = -ENOPROTOOPT;
  201. if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
  202. rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len,
  203. optval, optlen);
  204. return rc;
  205. }
  206. #endif /* _CCID_H */