ccid.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. struct ccid {
  23. unsigned char ccid_id;
  24. const char *ccid_name;
  25. struct module *ccid_owner;
  26. int (*ccid_init)(struct sock *sk);
  27. void (*ccid_exit)(struct sock *sk);
  28. int (*ccid_hc_rx_init)(struct sock *sk);
  29. int (*ccid_hc_tx_init)(struct sock *sk);
  30. void (*ccid_hc_rx_exit)(struct sock *sk);
  31. void (*ccid_hc_tx_exit)(struct sock *sk);
  32. void (*ccid_hc_rx_packet_recv)(struct sock *sk,
  33. struct sk_buff *skb);
  34. int (*ccid_hc_rx_parse_options)(struct sock *sk,
  35. unsigned char option,
  36. unsigned char len, u16 idx,
  37. unsigned char* value);
  38. void (*ccid_hc_rx_insert_options)(struct sock *sk,
  39. struct sk_buff *skb);
  40. void (*ccid_hc_tx_insert_options)(struct sock *sk,
  41. struct sk_buff *skb);
  42. void (*ccid_hc_tx_packet_recv)(struct sock *sk,
  43. struct sk_buff *skb);
  44. int (*ccid_hc_tx_parse_options)(struct sock *sk,
  45. unsigned char option,
  46. unsigned char len, u16 idx,
  47. unsigned char* value);
  48. int (*ccid_hc_tx_send_packet)(struct sock *sk,
  49. struct sk_buff *skb, int len);
  50. void (*ccid_hc_tx_packet_sent)(struct sock *sk, int more,
  51. int len);
  52. void (*ccid_hc_rx_get_info)(struct sock *sk,
  53. struct tcp_info *info);
  54. void (*ccid_hc_tx_get_info)(struct sock *sk,
  55. struct tcp_info *info);
  56. int (*ccid_hc_rx_getsockopt)(struct sock *sk,
  57. const int optname, int len,
  58. u32 __user *optval,
  59. int __user *optlen);
  60. int (*ccid_hc_tx_getsockopt)(struct sock *sk,
  61. const int optname, int len,
  62. u32 __user *optval,
  63. int __user *optlen);
  64. };
  65. extern int ccid_register(struct ccid *ccid);
  66. extern int ccid_unregister(struct ccid *ccid);
  67. extern struct ccid *ccid_init(unsigned char id, struct sock *sk);
  68. extern void ccid_exit(struct ccid *ccid, struct sock *sk);
  69. static inline void __ccid_get(struct ccid *ccid)
  70. {
  71. __module_get(ccid->ccid_owner);
  72. }
  73. static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
  74. struct sk_buff *skb, int len)
  75. {
  76. int rc = 0;
  77. if (ccid->ccid_hc_tx_send_packet != NULL)
  78. rc = ccid->ccid_hc_tx_send_packet(sk, skb, len);
  79. return rc;
  80. }
  81. static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk,
  82. int more, int len)
  83. {
  84. if (ccid->ccid_hc_tx_packet_sent != NULL)
  85. ccid->ccid_hc_tx_packet_sent(sk, more, len);
  86. }
  87. static inline int ccid_hc_rx_init(struct ccid *ccid, struct sock *sk)
  88. {
  89. int rc = 0;
  90. if (ccid->ccid_hc_rx_init != NULL)
  91. rc = ccid->ccid_hc_rx_init(sk);
  92. return rc;
  93. }
  94. static inline int ccid_hc_tx_init(struct ccid *ccid, struct sock *sk)
  95. {
  96. int rc = 0;
  97. if (ccid->ccid_hc_tx_init != NULL)
  98. rc = ccid->ccid_hc_tx_init(sk);
  99. return rc;
  100. }
  101. static inline void ccid_hc_rx_exit(struct ccid *ccid, struct sock *sk)
  102. {
  103. if (ccid != NULL && ccid->ccid_hc_rx_exit != NULL &&
  104. dccp_sk(sk)->dccps_hc_rx_ccid_private != NULL)
  105. ccid->ccid_hc_rx_exit(sk);
  106. }
  107. static inline void ccid_hc_tx_exit(struct ccid *ccid, struct sock *sk)
  108. {
  109. if (ccid != NULL && ccid->ccid_hc_tx_exit != NULL &&
  110. dccp_sk(sk)->dccps_hc_tx_ccid_private != NULL)
  111. ccid->ccid_hc_tx_exit(sk);
  112. }
  113. static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk,
  114. struct sk_buff *skb)
  115. {
  116. if (ccid->ccid_hc_rx_packet_recv != NULL)
  117. ccid->ccid_hc_rx_packet_recv(sk, skb);
  118. }
  119. static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk,
  120. struct sk_buff *skb)
  121. {
  122. if (ccid->ccid_hc_tx_packet_recv != NULL)
  123. ccid->ccid_hc_tx_packet_recv(sk, skb);
  124. }
  125. static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk,
  126. unsigned char option,
  127. unsigned char len, u16 idx,
  128. unsigned char* value)
  129. {
  130. int rc = 0;
  131. if (ccid->ccid_hc_tx_parse_options != NULL)
  132. rc = ccid->ccid_hc_tx_parse_options(sk, option, len, idx,
  133. value);
  134. return rc;
  135. }
  136. static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk,
  137. unsigned char option,
  138. unsigned char len, u16 idx,
  139. unsigned char* value)
  140. {
  141. int rc = 0;
  142. if (ccid->ccid_hc_rx_parse_options != NULL)
  143. rc = ccid->ccid_hc_rx_parse_options(sk, option, len, idx, value);
  144. return rc;
  145. }
  146. static inline void ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk,
  147. struct sk_buff *skb)
  148. {
  149. if (ccid->ccid_hc_tx_insert_options != NULL)
  150. ccid->ccid_hc_tx_insert_options(sk, skb);
  151. }
  152. static inline void ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk,
  153. struct sk_buff *skb)
  154. {
  155. if (ccid->ccid_hc_rx_insert_options != NULL)
  156. ccid->ccid_hc_rx_insert_options(sk, skb);
  157. }
  158. static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk,
  159. struct tcp_info *info)
  160. {
  161. if (ccid->ccid_hc_rx_get_info != NULL)
  162. ccid->ccid_hc_rx_get_info(sk, info);
  163. }
  164. static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk,
  165. struct tcp_info *info)
  166. {
  167. if (ccid->ccid_hc_tx_get_info != NULL)
  168. ccid->ccid_hc_tx_get_info(sk, info);
  169. }
  170. static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
  171. const int optname, int len,
  172. u32 __user *optval, int __user *optlen)
  173. {
  174. int rc = -ENOPROTOOPT;
  175. if (ccid->ccid_hc_rx_getsockopt != NULL)
  176. rc = ccid->ccid_hc_rx_getsockopt(sk, optname, len,
  177. optval, optlen);
  178. return rc;
  179. }
  180. static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
  181. const int optname, int len,
  182. u32 __user *optval, int __user *optlen)
  183. {
  184. int rc = -ENOPROTOOPT;
  185. if (ccid->ccid_hc_tx_getsockopt != NULL)
  186. rc = ccid->ccid_hc_tx_getsockopt(sk, optname, len,
  187. optval, optlen);
  188. return rc;
  189. }
  190. #endif /* _CCID_H */