dccp.h 13 KB

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