ccid.h 6.0 KB

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