ccid.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. int more, 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. static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
  118. struct sk_buff *skb)
  119. {
  120. int rc = 0;
  121. if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
  122. rc = ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb);
  123. return rc;
  124. }
  125. static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk,
  126. int more, unsigned int len)
  127. {
  128. if (ccid->ccid_ops->ccid_hc_tx_packet_sent != NULL)
  129. ccid->ccid_ops->ccid_hc_tx_packet_sent(sk, more, len);
  130. }
  131. static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk,
  132. struct sk_buff *skb)
  133. {
  134. if (ccid->ccid_ops->ccid_hc_rx_packet_recv != NULL)
  135. ccid->ccid_ops->ccid_hc_rx_packet_recv(sk, skb);
  136. }
  137. static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk,
  138. struct sk_buff *skb)
  139. {
  140. if (ccid->ccid_ops->ccid_hc_tx_packet_recv != NULL)
  141. ccid->ccid_ops->ccid_hc_tx_packet_recv(sk, skb);
  142. }
  143. /**
  144. * ccid_hc_tx_parse_options - Parse CCID-specific options sent by the receiver
  145. * @pkt: type of packet that @opt appears on (RFC 4340, 5.1)
  146. * @opt: the CCID-specific option type (RFC 4340, 5.8 and 10.3)
  147. * @val: value of @opt
  148. * @len: length of @val in bytes
  149. */
  150. static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk,
  151. u8 pkt, u8 opt, u8 *val, u8 len)
  152. {
  153. if (ccid->ccid_ops->ccid_hc_tx_parse_options == NULL)
  154. return 0;
  155. return ccid->ccid_ops->ccid_hc_tx_parse_options(sk, pkt, opt, val, len);
  156. }
  157. /**
  158. * ccid_hc_rx_parse_options - Parse CCID-specific options sent by the sender
  159. * Arguments are analogous to ccid_hc_tx_parse_options()
  160. */
  161. static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk,
  162. u8 pkt, u8 opt, u8 *val, u8 len)
  163. {
  164. if (ccid->ccid_ops->ccid_hc_rx_parse_options == NULL)
  165. return 0;
  166. return ccid->ccid_ops->ccid_hc_rx_parse_options(sk, pkt, opt, val, len);
  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 */