dccp.h
上传用户:szlgq88
上传日期:2009-04-28
资源大小:48287k
文件大小:13k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. #ifndef _LINUX_DCCP_H
  2. #define _LINUX_DCCP_H
  3. #include <linux/types.h>
  4. #include <asm/byteorder.h>
  5. /**
  6.  * struct dccp_hdr - generic part of DCCP packet header
  7.  *
  8.  * @dccph_sport - Relevant port on the endpoint that sent this packet
  9.  * @dccph_dport - Relevant port on the other endpoint
  10.  * @dccph_doff - Data Offset from the start of the DCCP header, in 32-bit words
  11.  * @dccph_ccval - Used by the HC-Sender CCID
  12.  * @dccph_cscov - Parts of the packet that are covered by the Checksum field
  13.  * @dccph_checksum - Internet checksum, depends on dccph_cscov
  14.  * @dccph_x - 0 = 24 bit sequence number, 1 = 48
  15.  * @dccph_type - packet type, see DCCP_PKT_ prefixed macros
  16.  * @dccph_seq - sequence number high or low order 24 bits, depends on dccph_x
  17.  */
  18. struct dccp_hdr {
  19. __u16 dccph_sport,
  20. dccph_dport;
  21. __u8 dccph_doff;
  22. #if defined(__LITTLE_ENDIAN_BITFIELD)
  23. __u8 dccph_cscov:4,
  24. dccph_ccval:4;
  25. #elif defined(__BIG_ENDIAN_BITFIELD)
  26. __u8 dccph_ccval:4,
  27. dccph_cscov:4;
  28. #else
  29. #error  "Adjust your <asm/byteorder.h> defines"
  30. #endif
  31. __u16 dccph_checksum;
  32. #if defined(__LITTLE_ENDIAN_BITFIELD)
  33. __u32 dccph_x:1,
  34. dccph_type:4,
  35. dccph_reserved:3,
  36. dccph_seq:24;
  37. #elif defined(__BIG_ENDIAN_BITFIELD)
  38. __u32 dccph_reserved:3,
  39. dccph_type:4,
  40. dccph_x:1,
  41. dccph_seq:24;
  42. #else
  43. #error  "Adjust your <asm/byteorder.h> defines"
  44. #endif
  45. };
  46. /**
  47.  * struct dccp_hdr_ext - the low bits of a 48 bit seq packet
  48.  *
  49.  * @dccph_seq_low - low 24 bits of a 48 bit seq packet
  50.  */
  51. struct dccp_hdr_ext {
  52. __u32 dccph_seq_low;
  53. };
  54. /**
  55.  * struct dccp_hdr_request - Conection initiation request header
  56.  *
  57.  * @dccph_req_service - Service to which the client app wants to connect
  58.  * @dccph_req_options - list of options (must be a multiple of 32 bits
  59.  */
  60. struct dccp_hdr_request {
  61. __u32 dccph_req_service;
  62. };
  63. /**
  64.  * struct dccp_hdr_ack_bits - acknowledgment bits common to most packets
  65.  *
  66.  * @dccph_resp_ack_nr_high - 48 bit ack number high order bits, contains GSR
  67.  * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR
  68.  */
  69. struct dccp_hdr_ack_bits {
  70. __u32 dccph_reserved1:8,
  71. dccph_ack_nr_high:24;
  72. __u32 dccph_ack_nr_low;
  73. };
  74. /**
  75.  * struct dccp_hdr_response - Conection initiation response header
  76.  *
  77.  * @dccph_resp_ack_nr_high - 48 bit ack number high order bits, contains GSR
  78.  * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR
  79.  * @dccph_resp_service - Echoes the Service Code on a received DCCP-Request
  80.  * @dccph_resp_options - list of options (must be a multiple of 32 bits
  81.  */
  82. struct dccp_hdr_response {
  83. struct dccp_hdr_ack_bits dccph_resp_ack;
  84. __u32 dccph_resp_service;
  85. };
  86. /**
  87.  * struct dccp_hdr_reset - Unconditionally shut down a connection
  88.  *
  89.  * @dccph_reset_service - Echoes the Service Code on a received DCCP-Request
  90.  * @dccph_reset_options - list of options (must be a multiple of 32 bits
  91.  */
  92. struct dccp_hdr_reset {
  93. struct dccp_hdr_ack_bits dccph_reset_ack;
  94. __u8 dccph_reset_code,
  95. dccph_reset_data[3];
  96. };
  97. enum dccp_pkt_type {
  98. DCCP_PKT_REQUEST = 0,
  99. DCCP_PKT_RESPONSE,
  100. DCCP_PKT_DATA,
  101. DCCP_PKT_ACK,
  102. DCCP_PKT_DATAACK,
  103. DCCP_PKT_CLOSEREQ,
  104. DCCP_PKT_CLOSE,
  105. DCCP_PKT_RESET,
  106. DCCP_PKT_SYNC,
  107. DCCP_PKT_SYNCACK,
  108. DCCP_PKT_INVALID,
  109. };
  110. #define DCCP_NR_PKT_TYPES DCCP_PKT_INVALID
  111. static inline unsigned int dccp_packet_hdr_len(const __u8 type)
  112. {
  113. if (type == DCCP_PKT_DATA)
  114. return 0;
  115. if (type == DCCP_PKT_DATAACK ||
  116.     type == DCCP_PKT_ACK ||
  117.     type == DCCP_PKT_SYNC ||
  118.     type == DCCP_PKT_SYNCACK ||
  119.     type == DCCP_PKT_CLOSE ||
  120.     type == DCCP_PKT_CLOSEREQ)
  121. return sizeof(struct dccp_hdr_ack_bits);
  122. if (type == DCCP_PKT_REQUEST)
  123. return sizeof(struct dccp_hdr_request);
  124. if (type == DCCP_PKT_RESPONSE)
  125. return sizeof(struct dccp_hdr_response);
  126. return sizeof(struct dccp_hdr_reset);
  127. }
  128. enum dccp_reset_codes {
  129. DCCP_RESET_CODE_UNSPECIFIED = 0,
  130. DCCP_RESET_CODE_CLOSED,
  131. DCCP_RESET_CODE_ABORTED,
  132. DCCP_RESET_CODE_NO_CONNECTION,
  133. DCCP_RESET_CODE_PACKET_ERROR,
  134. DCCP_RESET_CODE_OPTION_ERROR,
  135. DCCP_RESET_CODE_MANDATORY_ERROR,
  136. DCCP_RESET_CODE_CONNECTION_REFUSED,
  137. DCCP_RESET_CODE_BAD_SERVICE_CODE,
  138. DCCP_RESET_CODE_TOO_BUSY,
  139. DCCP_RESET_CODE_BAD_INIT_COOKIE,
  140. DCCP_RESET_CODE_AGGRESSION_PENALTY,
  141. };
  142. /* DCCP options */
  143. enum {
  144. DCCPO_PADDING = 0,
  145. DCCPO_MANDATORY = 1,
  146. DCCPO_MIN_RESERVED = 3,
  147. DCCPO_MAX_RESERVED = 31,
  148. DCCPO_NDP_COUNT = 37,
  149. DCCPO_ACK_VECTOR_0 = 38,
  150. DCCPO_ACK_VECTOR_1 = 39,
  151. DCCPO_TIMESTAMP = 41,
  152. DCCPO_TIMESTAMP_ECHO = 42,
  153. DCCPO_ELAPSED_TIME = 43,
  154. DCCPO_MAX = 45,
  155. DCCPO_MIN_CCID_SPECIFIC = 128,
  156. DCCPO_MAX_CCID_SPECIFIC = 255,
  157. };
  158. /* DCCP features */
  159. enum {
  160. DCCPF_RESERVED = 0,
  161. DCCPF_SEQUENCE_WINDOW = 3,
  162. DCCPF_SEND_ACK_VECTOR = 6,
  163. DCCPF_SEND_NDP_COUNT = 7,
  164. /* 10-127 reserved */
  165. DCCPF_MIN_CCID_SPECIFIC = 128,
  166. DCCPF_MAX_CCID_SPECIFIC = 255,
  167. };
  168. /* DCCP socket options */
  169. #define DCCP_SOCKOPT_PACKET_SIZE 1
  170. #define DCCP_SOCKOPT_SERVICE 2
  171. #define DCCP_SOCKOPT_CCID_RX_INFO 128
  172. #define DCCP_SOCKOPT_CCID_TX_INFO 192
  173. #define DCCP_SERVICE_LIST_MAX_LEN      32
  174. #ifdef __KERNEL__
  175. #include <linux/in.h>
  176. #include <linux/list.h>
  177. #include <linux/uio.h>
  178. #include <linux/workqueue.h>
  179. #include <net/inet_connection_sock.h>
  180. #include <net/inet_timewait_sock.h>
  181. #include <net/sock.h>
  182. #include <net/tcp_states.h>
  183. #include <net/tcp.h>
  184. enum dccp_state {
  185. DCCP_OPEN = TCP_ESTABLISHED,
  186. DCCP_REQUESTING = TCP_SYN_SENT,
  187. DCCP_PARTOPEN = TCP_FIN_WAIT1, /* FIXME:
  188.     This mapping is horrible, but TCP has
  189.     no matching state for DCCP_PARTOPEN,
  190.     as TCP_SYN_RECV is already used by
  191.     DCCP_RESPOND, why don't stop using TCP
  192.     mapping of states? OK, now we don't use
  193.     sk_stream_sendmsg anymore, so doesn't
  194.     seem to exist any reason for us to
  195.     do the TCP mapping here */
  196. DCCP_LISTEN = TCP_LISTEN,
  197. DCCP_RESPOND = TCP_SYN_RECV,
  198. DCCP_CLOSING = TCP_CLOSING,
  199. DCCP_TIME_WAIT = TCP_TIME_WAIT,
  200. DCCP_CLOSED = TCP_CLOSE,
  201. DCCP_MAX_STATES = TCP_MAX_STATES,
  202. };
  203. #define DCCP_STATE_MASK 0xf
  204. #define DCCP_ACTION_FIN (1<<7)
  205. enum {
  206. DCCPF_OPEN  = TCPF_ESTABLISHED,
  207. DCCPF_REQUESTING = TCPF_SYN_SENT,
  208. DCCPF_PARTOPEN  = TCPF_FIN_WAIT1,
  209. DCCPF_LISTEN  = TCPF_LISTEN,
  210. DCCPF_RESPOND  = TCPF_SYN_RECV,
  211. DCCPF_CLOSING  = TCPF_CLOSING,
  212. DCCPF_TIME_WAIT  = TCPF_TIME_WAIT,
  213. DCCPF_CLOSED  = TCPF_CLOSE,
  214. };
  215. static inline struct dccp_hdr *dccp_hdr(const struct sk_buff *skb)
  216. {
  217. return (struct dccp_hdr *)skb->h.raw;
  218. }
  219. static inline struct dccp_hdr_ext *dccp_hdrx(const struct sk_buff *skb)
  220. {
  221. return (struct dccp_hdr_ext *)(skb->h.raw + sizeof(struct dccp_hdr));
  222. }
  223. static inline unsigned int __dccp_basic_hdr_len(const struct dccp_hdr *dh)
  224. {
  225. return sizeof(*dh) + (dh->dccph_x ? sizeof(struct dccp_hdr_ext) : 0);
  226. }
  227. static inline unsigned int dccp_basic_hdr_len(const struct sk_buff *skb)
  228. {
  229. const struct dccp_hdr *dh = dccp_hdr(skb);
  230. return __dccp_basic_hdr_len(dh);
  231. }
  232. static inline __u64 dccp_hdr_seq(const struct sk_buff *skb)
  233. {
  234. const struct dccp_hdr *dh = dccp_hdr(skb);
  235. #if defined(__LITTLE_ENDIAN_BITFIELD)
  236. __u64 seq_nr = ntohl(dh->dccph_seq << 8);
  237. #elif defined(__BIG_ENDIAN_BITFIELD)
  238. __u64 seq_nr = ntohl(dh->dccph_seq);
  239. #else
  240. #error  "Adjust your <asm/byteorder.h> defines"
  241. #endif
  242. if (dh->dccph_x != 0)
  243. seq_nr = (seq_nr << 32) + ntohl(dccp_hdrx(skb)->dccph_seq_low);
  244. return seq_nr;
  245. }
  246. static inline struct dccp_hdr_request *dccp_hdr_request(struct sk_buff *skb)
  247. {
  248. return (struct dccp_hdr_request *)(skb->h.raw + dccp_basic_hdr_len(skb));
  249. }
  250. static inline struct dccp_hdr_ack_bits *dccp_hdr_ack_bits(const struct sk_buff *skb)
  251. {
  252. return (struct dccp_hdr_ack_bits *)(skb->h.raw + dccp_basic_hdr_len(skb));
  253. }
  254. static inline u64 dccp_hdr_ack_seq(const struct sk_buff *skb)
  255. {
  256. const struct dccp_hdr_ack_bits *dhack = dccp_hdr_ack_bits(skb);
  257. #if defined(__LITTLE_ENDIAN_BITFIELD)
  258. return (((u64)ntohl(dhack->dccph_ack_nr_high << 8)) << 32) + ntohl(dhack->dccph_ack_nr_low);
  259. #elif defined(__BIG_ENDIAN_BITFIELD)
  260. return (((u64)ntohl(dhack->dccph_ack_nr_high)) << 32) + ntohl(dhack->dccph_ack_nr_low);
  261. #else
  262. #error  "Adjust your <asm/byteorder.h> defines"
  263. #endif
  264. }
  265. static inline struct dccp_hdr_response *dccp_hdr_response(struct sk_buff *skb)
  266. {
  267. return (struct dccp_hdr_response *)(skb->h.raw + dccp_basic_hdr_len(skb));
  268. }
  269. static inline struct dccp_hdr_reset *dccp_hdr_reset(struct sk_buff *skb)
  270. {
  271. return (struct dccp_hdr_reset *)(skb->h.raw + dccp_basic_hdr_len(skb));
  272. }
  273. static inline unsigned int __dccp_hdr_len(const struct dccp_hdr *dh)
  274. {
  275. return __dccp_basic_hdr_len(dh) +
  276.        dccp_packet_hdr_len(dh->dccph_type);
  277. }
  278. static inline unsigned int dccp_hdr_len(const struct sk_buff *skb)
  279. {
  280. return __dccp_hdr_len(dccp_hdr(skb));
  281. }
  282. /* initial values for each feature */
  283. #define DCCPF_INITIAL_SEQUENCE_WINDOW 100
  284. /* FIXME: for now we're using CCID 3 (TFRC) */
  285. #define DCCPF_INITIAL_CCID 3
  286. #define DCCPF_INITIAL_SEND_ACK_VECTOR 0
  287. /* FIXME: for now we're default to 1 but it should really be 0 */
  288. #define DCCPF_INITIAL_SEND_NDP_COUNT 1
  289. #define DCCP_NDP_LIMIT 0xFFFFFF
  290. /**
  291.   * struct dccp_options - option values for a DCCP connection
  292.   * @dccpo_sequence_window - Sequence Window Feature (section 7.5.2)
  293.   * @dccpo_ccid - Congestion Control Id (CCID) (section 10)
  294.   * @dccpo_send_ack_vector - Send Ack Vector Feature (section 11.5)
  295.   * @dccpo_send_ndp_count - Send NDP Count Feature (7.7.2)
  296.   */
  297. struct dccp_options {
  298. __u64 dccpo_sequence_window;
  299. __u8 dccpo_rx_ccid;
  300. __u8 dccpo_tx_ccid;
  301. __u8 dccpo_send_ack_vector;
  302. __u8 dccpo_send_ndp_count;
  303. };
  304. extern void __dccp_options_init(struct dccp_options *dccpo);
  305. extern void dccp_options_init(struct dccp_options *dccpo);
  306. extern int dccp_parse_options(struct sock *sk, struct sk_buff *skb);
  307. struct dccp_request_sock {
  308. struct inet_request_sock dreq_inet_rsk;
  309. __u64  dreq_iss;
  310. __u64  dreq_isr;
  311. __u32  dreq_service;
  312. };
  313. static inline struct dccp_request_sock *dccp_rsk(const struct request_sock *req)
  314. {
  315. return (struct dccp_request_sock *)req;
  316. }
  317. extern struct inet_timewait_death_row dccp_death_row;
  318. struct dccp_options_received {
  319. u32 dccpor_ndp; /* only 24 bits */
  320. u32 dccpor_timestamp;
  321. u32 dccpor_timestamp_echo;
  322. u32 dccpor_elapsed_time;
  323. };
  324. struct ccid;
  325. enum dccp_role {
  326. DCCP_ROLE_UNDEFINED,
  327. DCCP_ROLE_LISTEN,
  328. DCCP_ROLE_CLIENT,
  329. DCCP_ROLE_SERVER,
  330. };
  331. struct dccp_service_list {
  332. __u32 dccpsl_nr;
  333. __u32 dccpsl_list[0];
  334. };
  335. #define DCCP_SERVICE_INVALID_VALUE htonl((__u32)-1)
  336. static inline int dccp_list_has_service(const struct dccp_service_list *sl,
  337. const u32 service)
  338. {
  339. if (likely(sl != NULL)) {
  340. u32 i = sl->dccpsl_nr;
  341. while (i--)
  342. if (sl->dccpsl_list[i] == service)
  343. return 1; 
  344. }
  345. return 0;
  346. }
  347. struct dccp_ackvec;
  348. /**
  349.  * struct dccp_sock - DCCP socket state
  350.  *
  351.  * @dccps_swl - sequence number window low
  352.  * @dccps_swh - sequence number window high
  353.  * @dccps_awl - acknowledgement number window low
  354.  * @dccps_awh - acknowledgement number window high
  355.  * @dccps_iss - initial sequence number sent
  356.  * @dccps_isr - initial sequence number received
  357.  * @dccps_osr - first OPEN sequence number received
  358.  * @dccps_gss - greatest sequence number sent
  359.  * @dccps_gsr - greatest valid sequence number received
  360.  * @dccps_gar - greatest valid ack number received on a non-Sync; initialized to %dccps_iss
  361.  * @dccps_timestamp_time - time of latest TIMESTAMP option
  362.  * @dccps_timestamp_echo - latest timestamp received on a TIMESTAMP option
  363.  * @dccps_ext_header_len - network protocol overhead (IP/IPv6 options)
  364.  * @dccps_pmtu_cookie - Last pmtu seen by socket
  365.  * @dccps_packet_size - Set thru setsockopt
  366.  * @dccps_role - Role of this sock, one of %dccp_role
  367.  * @dccps_ndp_count - number of Non Data Packets since last data packet
  368.  * @dccps_hc_rx_ackvec - rx half connection ack vector
  369.  */
  370. struct dccp_sock {
  371. /* inet_connection_sock has to be the first member of dccp_sock */
  372. struct inet_connection_sock dccps_inet_connection;
  373. __u64 dccps_swl;
  374. __u64 dccps_swh;
  375. __u64 dccps_awl;
  376. __u64 dccps_awh;
  377. __u64 dccps_iss;
  378. __u64 dccps_isr;
  379. __u64 dccps_osr;
  380. __u64 dccps_gss;
  381. __u64 dccps_gsr;
  382. __u64 dccps_gar;
  383. __u32 dccps_service;
  384. struct dccp_service_list *dccps_service_list;
  385. struct timeval dccps_timestamp_time;
  386. __u32 dccps_timestamp_echo;
  387. __u32 dccps_packet_size;
  388. unsigned long dccps_ndp_count;
  389. __u16 dccps_ext_header_len;
  390. __u32 dccps_pmtu_cookie;
  391. __u32 dccps_mss_cache;
  392. struct dccp_options dccps_options;
  393. struct dccp_ackvec *dccps_hc_rx_ackvec;
  394. void *dccps_hc_rx_ccid_private;
  395. void *dccps_hc_tx_ccid_private;
  396. struct ccid *dccps_hc_rx_ccid;
  397. struct ccid *dccps_hc_tx_ccid;
  398. struct dccp_options_received dccps_options_received;
  399. struct timeval dccps_epoch;
  400. enum dccp_role dccps_role:2;
  401. __u8 dccps_hc_rx_insert_options:1;
  402. __u8 dccps_hc_tx_insert_options:1;
  403. };
  404.  
  405. static inline struct dccp_sock *dccp_sk(const struct sock *sk)
  406. {
  407. return (struct dccp_sock *)sk;
  408. }
  409. static inline int dccp_service_not_initialized(const struct sock *sk)
  410. {
  411. return dccp_sk(sk)->dccps_service == DCCP_SERVICE_INVALID_VALUE;
  412. }
  413. static inline const char *dccp_role(const struct sock *sk)
  414. {
  415. switch (dccp_sk(sk)->dccps_role) {
  416. case DCCP_ROLE_UNDEFINED: return "undefined";
  417. case DCCP_ROLE_LISTEN:   return "listen";
  418. case DCCP_ROLE_SERVER:   return "server";
  419. case DCCP_ROLE_CLIENT:   return "client";
  420. }
  421. return NULL;
  422. }
  423. #endif /* __KERNEL__ */
  424. #endif /* _LINUX_DCCP_H */