dccp.h 12 KB

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