ccid.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. /* maximum value for a CCID (RFC 4340, 19.5) */
  21. #define CCID_MAX 255
  22. #define CCID_SLAB_NAME_LENGTH 32
  23. struct tcp_info;
  24. /**
  25. * struct ccid_operations - Interface to Congestion-Control Infrastructure
  26. *
  27. * @ccid_id: numerical CCID ID (up to %CCID_MAX, cf. table 5 in RFC 4340, 10.)
  28. * @ccid_ccmps: the CCMPS including network/transport headers (0 when disabled)
  29. * @ccid_name: alphabetical identifier string for @ccid_id
  30. * @ccid_hc_{r,t}x_slab: memory pool for the receiver/sender half-connection
  31. * @ccid_hc_{r,t}x_obj_size: size of the receiver/sender half-connection socket
  32. *
  33. * @ccid_hc_{r,t}x_init: CCID-specific initialisation routine (before startup)
  34. * @ccid_hc_{r,t}x_exit: CCID-specific cleanup routine (before destruction)
  35. * @ccid_hc_rx_packet_recv: implements the HC-receiver side
  36. * @ccid_hc_{r,t}x_parse_options: parsing routine for CCID/HC-specific options
  37. * @ccid_hc_{r,t}x_insert_options: insert routine for CCID/HC-specific options
  38. * @ccid_hc_tx_packet_recv: implements feedback processing for the HC-sender
  39. * @ccid_hc_tx_send_packet: implements the sending part of the HC-sender
  40. * @ccid_hc_tx_packet_sent: does accounting for packets in flight by HC-sender
  41. * @ccid_hc_{r,t}x_get_info: INET_DIAG information for HC-receiver/sender
  42. * @ccid_hc_{r,t}x_getsockopt: socket options specific to HC-receiver/sender
  43. */
  44. struct ccid_operations {
  45. unsigned char ccid_id;
  46. __u32 ccid_ccmps;
  47. const char *ccid_name;
  48. struct kmem_cache *ccid_hc_rx_slab,
  49. *ccid_hc_tx_slab;
  50. char ccid_hc_rx_slab_name[CCID_SLAB_NAME_LENGTH];
  51. char ccid_hc_tx_slab_name[CCID_SLAB_NAME_LENGTH];
  52. __u32 ccid_hc_rx_obj_size,
  53. ccid_hc_tx_obj_size;
  54. /* Interface Routines */
  55. int (*ccid_hc_rx_init)(struct ccid *ccid, struct sock *sk);
  56. int (*ccid_hc_tx_init)(struct ccid *ccid, struct sock *sk);
  57. void (*ccid_hc_rx_exit)(struct sock *sk);
  58. void (*ccid_hc_tx_exit)(struct sock *sk);
  59. void (*ccid_hc_rx_packet_recv)(struct sock *sk,
  60. struct sk_buff *skb);
  61. int (*ccid_hc_rx_parse_options)(struct sock *sk, u8 pkt,
  62. u8 opt, u8 *val, u8 len);
  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, u8 pkt,
  68. u8 opt, u8 *val, u8 len);
  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. 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. 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, 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. /**
  148. * ccid_hc_tx_parse_options - Parse CCID-specific options sent by the receiver
  149. * @pkt: type of packet that @opt appears on (RFC 4340, 5.1)
  150. * @opt: the CCID-specific option type (RFC 4340, 5.8 and 10.3)
  151. * @val: value of @opt
  152. * @len: length of @val in bytes
  153. */
  154. static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk,
  155. u8 pkt, u8 opt, u8 *val, u8 len)
  156. {
  157. if (ccid->ccid_ops->ccid_hc_tx_parse_options == NULL)
  158. return 0;
  159. return ccid->ccid_ops->ccid_hc_tx_parse_options(sk, pkt, opt, val, len);
  160. }
  161. /**
  162. * ccid_hc_rx_parse_options - Parse CCID-specific options sent by the sender
  163. * Arguments are analogous to ccid_hc_tx_parse_options()
  164. */
  165. static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk,
  166. u8 pkt, u8 opt, u8 *val, u8 len)
  167. {
  168. if (ccid->ccid_ops->ccid_hc_rx_parse_options == NULL)
  169. return 0;
  170. return ccid->ccid_ops->ccid_hc_rx_parse_options(sk, pkt, opt, val, len);
  171. }
  172. static inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk,
  173. struct sk_buff *skb)
  174. {
  175. if (ccid->ccid_ops->ccid_hc_rx_insert_options != NULL)
  176. return ccid->ccid_ops->ccid_hc_rx_insert_options(sk, skb);
  177. return 0;
  178. }
  179. static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk,
  180. struct tcp_info *info)
  181. {
  182. if (ccid->ccid_ops->ccid_hc_rx_get_info != NULL)
  183. ccid->ccid_ops->ccid_hc_rx_get_info(sk, info);
  184. }
  185. static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk,
  186. struct tcp_info *info)
  187. {
  188. if (ccid->ccid_ops->ccid_hc_tx_get_info != NULL)
  189. ccid->ccid_ops->ccid_hc_tx_get_info(sk, info);
  190. }
  191. static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
  192. const int optname, int len,
  193. u32 __user *optval, int __user *optlen)
  194. {
  195. int rc = -ENOPROTOOPT;
  196. if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
  197. rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len,
  198. optval, optlen);
  199. return rc;
  200. }
  201. static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
  202. const int optname, int len,
  203. u32 __user *optval, int __user *optlen)
  204. {
  205. int rc = -ENOPROTOOPT;
  206. if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
  207. rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len,
  208. optval, optlen);
  209. return rc;
  210. }
  211. #endif /* _CCID_H */