input.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*
  2. * net/dccp/input.c
  3. *
  4. * An implementation of the DCCP protocol
  5. * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <linux/dccp.h>
  13. #include <linux/skbuff.h>
  14. #include <net/sock.h>
  15. #include "ackvec.h"
  16. #include "ccid.h"
  17. #include "dccp.h"
  18. static void dccp_fin(struct sock *sk, struct sk_buff *skb)
  19. {
  20. sk->sk_shutdown |= RCV_SHUTDOWN;
  21. sock_set_flag(sk, SOCK_DONE);
  22. __skb_pull(skb, dccp_hdr(skb)->dccph_doff * 4);
  23. __skb_queue_tail(&sk->sk_receive_queue, skb);
  24. skb_set_owner_r(skb, sk);
  25. sk->sk_data_ready(sk, 0);
  26. }
  27. static void dccp_rcv_close(struct sock *sk, struct sk_buff *skb)
  28. {
  29. dccp_send_reset(sk, DCCP_RESET_CODE_CLOSED);
  30. dccp_fin(sk, skb);
  31. dccp_set_state(sk, DCCP_CLOSED);
  32. sk_wake_async(sk, 1, POLL_HUP);
  33. }
  34. static void dccp_rcv_closereq(struct sock *sk, struct sk_buff *skb)
  35. {
  36. /*
  37. * Step 7: Check for unexpected packet types
  38. * If (S.is_server and P.type == CloseReq)
  39. * Send Sync packet acknowledging P.seqno
  40. * Drop packet and return
  41. */
  42. if (dccp_sk(sk)->dccps_role != DCCP_ROLE_CLIENT) {
  43. dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq, DCCP_PKT_SYNC);
  44. return;
  45. }
  46. if (sk->sk_state != DCCP_CLOSING)
  47. dccp_set_state(sk, DCCP_CLOSING);
  48. dccp_send_close(sk, 0);
  49. }
  50. static void dccp_event_ack_recv(struct sock *sk, struct sk_buff *skb)
  51. {
  52. struct dccp_sock *dp = dccp_sk(sk);
  53. if (dccp_msk(sk)->dccpms_send_ack_vector)
  54. dccp_ackvec_check_rcv_ackno(dp->dccps_hc_rx_ackvec, sk,
  55. DCCP_SKB_CB(skb)->dccpd_ack_seq);
  56. }
  57. static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb)
  58. {
  59. const struct dccp_hdr *dh = dccp_hdr(skb);
  60. struct dccp_sock *dp = dccp_sk(sk);
  61. u64 lswl, lawl, seqno = DCCP_SKB_CB(skb)->dccpd_seq,
  62. ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
  63. /*
  64. * Step 5: Prepare sequence numbers for Sync
  65. * If P.type == Sync or P.type == SyncAck,
  66. * If S.AWL <= P.ackno <= S.AWH and P.seqno >= S.SWL,
  67. * / * P is valid, so update sequence number variables
  68. * accordingly. After this update, P will pass the tests
  69. * in Step 6. A SyncAck is generated if necessary in
  70. * Step 15 * /
  71. * Update S.GSR, S.SWL, S.SWH
  72. * Otherwise,
  73. * Drop packet and return
  74. */
  75. if (dh->dccph_type == DCCP_PKT_SYNC ||
  76. dh->dccph_type == DCCP_PKT_SYNCACK) {
  77. if (between48(ackno, dp->dccps_awl, dp->dccps_awh) &&
  78. dccp_delta_seqno(dp->dccps_swl, seqno) >= 0)
  79. dccp_update_gsr(sk, seqno);
  80. else
  81. return -1;
  82. }
  83. /*
  84. * Step 6: Check sequence numbers
  85. * Let LSWL = S.SWL and LAWL = S.AWL
  86. * If P.type == CloseReq or P.type == Close or P.type == Reset,
  87. * LSWL := S.GSR + 1, LAWL := S.GAR
  88. * If LSWL <= P.seqno <= S.SWH
  89. * and (P.ackno does not exist or LAWL <= P.ackno <= S.AWH),
  90. * Update S.GSR, S.SWL, S.SWH
  91. * If P.type != Sync,
  92. * Update S.GAR
  93. */
  94. lswl = dp->dccps_swl;
  95. lawl = dp->dccps_awl;
  96. if (dh->dccph_type == DCCP_PKT_CLOSEREQ ||
  97. dh->dccph_type == DCCP_PKT_CLOSE ||
  98. dh->dccph_type == DCCP_PKT_RESET) {
  99. lswl = ADD48(dp->dccps_gsr, 1);
  100. lawl = dp->dccps_gar;
  101. }
  102. if (between48(seqno, lswl, dp->dccps_swh) &&
  103. (ackno == DCCP_PKT_WITHOUT_ACK_SEQ ||
  104. between48(ackno, lawl, dp->dccps_awh))) {
  105. dccp_update_gsr(sk, seqno);
  106. if (dh->dccph_type != DCCP_PKT_SYNC &&
  107. (ackno != DCCP_PKT_WITHOUT_ACK_SEQ))
  108. dp->dccps_gar = ackno;
  109. } else {
  110. DCCP_WARN("DCCP: Step 6 failed for %s packet, "
  111. "(LSWL(%llu) <= P.seqno(%llu) <= S.SWH(%llu)) and "
  112. "(P.ackno %s or LAWL(%llu) <= P.ackno(%llu) <= S.AWH(%llu), "
  113. "sending SYNC...\n", dccp_packet_name(dh->dccph_type),
  114. (unsigned long long) lswl, (unsigned long long) seqno,
  115. (unsigned long long) dp->dccps_swh,
  116. (ackno == DCCP_PKT_WITHOUT_ACK_SEQ) ? "doesn't exist"
  117. : "exists",
  118. (unsigned long long) lawl, (unsigned long long) ackno,
  119. (unsigned long long) dp->dccps_awh);
  120. /*
  121. * Step 6: Check sequence numbers
  122. * Otherwise,
  123. * If P.type == Reset,
  124. * Send Sync packet acknowledging S.GSR
  125. * Otherwise,
  126. * Send Sync packet acknowledging P.seqno
  127. * Drop packet and return
  128. */
  129. if (dh->dccph_type == DCCP_PKT_RESET)
  130. seqno = dp->dccps_gsr;
  131. dccp_send_sync(sk, seqno, DCCP_PKT_SYNC);
  132. return -1;
  133. }
  134. return 0;
  135. }
  136. static int __dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
  137. const struct dccp_hdr *dh, const unsigned len)
  138. {
  139. struct dccp_sock *dp = dccp_sk(sk);
  140. switch (dccp_hdr(skb)->dccph_type) {
  141. case DCCP_PKT_DATAACK:
  142. case DCCP_PKT_DATA:
  143. /*
  144. * FIXME: check if sk_receive_queue is full, schedule DATA_DROPPED
  145. * option if it is.
  146. */
  147. __skb_pull(skb, dh->dccph_doff * 4);
  148. __skb_queue_tail(&sk->sk_receive_queue, skb);
  149. skb_set_owner_r(skb, sk);
  150. sk->sk_data_ready(sk, 0);
  151. return 0;
  152. case DCCP_PKT_ACK:
  153. goto discard;
  154. case DCCP_PKT_RESET:
  155. /*
  156. * Step 9: Process Reset
  157. * If P.type == Reset,
  158. * Tear down connection
  159. * S.state := TIMEWAIT
  160. * Set TIMEWAIT timer
  161. * Drop packet and return
  162. */
  163. dccp_fin(sk, skb);
  164. dccp_time_wait(sk, DCCP_TIME_WAIT, 0);
  165. return 0;
  166. case DCCP_PKT_CLOSEREQ:
  167. dccp_rcv_closereq(sk, skb);
  168. goto discard;
  169. case DCCP_PKT_CLOSE:
  170. dccp_rcv_close(sk, skb);
  171. return 0;
  172. case DCCP_PKT_REQUEST:
  173. /* Step 7
  174. * or (S.is_server and P.type == Response)
  175. * or (S.is_client and P.type == Request)
  176. * or (S.state >= OPEN and P.type == Request
  177. * and P.seqno >= S.OSR)
  178. * or (S.state >= OPEN and P.type == Response
  179. * and P.seqno >= S.OSR)
  180. * or (S.state == RESPOND and P.type == Data),
  181. * Send Sync packet acknowledging P.seqno
  182. * Drop packet and return
  183. */
  184. if (dp->dccps_role != DCCP_ROLE_LISTEN)
  185. goto send_sync;
  186. goto check_seq;
  187. case DCCP_PKT_RESPONSE:
  188. if (dp->dccps_role != DCCP_ROLE_CLIENT)
  189. goto send_sync;
  190. check_seq:
  191. if (dccp_delta_seqno(dp->dccps_osr,
  192. DCCP_SKB_CB(skb)->dccpd_seq) >= 0) {
  193. send_sync:
  194. dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq,
  195. DCCP_PKT_SYNC);
  196. }
  197. break;
  198. case DCCP_PKT_SYNC:
  199. dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq,
  200. DCCP_PKT_SYNCACK);
  201. /*
  202. * From RFC 4340, sec. 5.7
  203. *
  204. * As with DCCP-Ack packets, DCCP-Sync and DCCP-SyncAck packets
  205. * MAY have non-zero-length application data areas, whose
  206. * contents receivers MUST ignore.
  207. */
  208. goto discard;
  209. }
  210. DCCP_INC_STATS_BH(DCCP_MIB_INERRS);
  211. discard:
  212. __kfree_skb(skb);
  213. return 0;
  214. }
  215. int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
  216. const struct dccp_hdr *dh, const unsigned len)
  217. {
  218. struct dccp_sock *dp = dccp_sk(sk);
  219. if (dccp_check_seqno(sk, skb))
  220. goto discard;
  221. if (dccp_parse_options(sk, skb))
  222. goto discard;
  223. if (DCCP_SKB_CB(skb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
  224. dccp_event_ack_recv(sk, skb);
  225. if (dccp_msk(sk)->dccpms_send_ack_vector &&
  226. dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
  227. DCCP_SKB_CB(skb)->dccpd_seq,
  228. DCCP_ACKVEC_STATE_RECEIVED))
  229. goto discard;
  230. ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb);
  231. ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb);
  232. return __dccp_rcv_established(sk, skb, dh, len);
  233. discard:
  234. __kfree_skb(skb);
  235. return 0;
  236. }
  237. EXPORT_SYMBOL_GPL(dccp_rcv_established);
  238. static int dccp_rcv_request_sent_state_process(struct sock *sk,
  239. struct sk_buff *skb,
  240. const struct dccp_hdr *dh,
  241. const unsigned len)
  242. {
  243. /*
  244. * Step 4: Prepare sequence numbers in REQUEST
  245. * If S.state == REQUEST,
  246. * If (P.type == Response or P.type == Reset)
  247. * and S.AWL <= P.ackno <= S.AWH,
  248. * / * Set sequence number variables corresponding to the
  249. * other endpoint, so P will pass the tests in Step 6 * /
  250. * Set S.GSR, S.ISR, S.SWL, S.SWH
  251. * / * Response processing continues in Step 10; Reset
  252. * processing continues in Step 9 * /
  253. */
  254. if (dh->dccph_type == DCCP_PKT_RESPONSE) {
  255. const struct inet_connection_sock *icsk = inet_csk(sk);
  256. struct dccp_sock *dp = dccp_sk(sk);
  257. long tstamp = dccp_timestamp();
  258. /* Stop the REQUEST timer */
  259. inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS);
  260. BUG_TRAP(sk->sk_send_head != NULL);
  261. __kfree_skb(sk->sk_send_head);
  262. sk->sk_send_head = NULL;
  263. if (!between48(DCCP_SKB_CB(skb)->dccpd_ack_seq,
  264. dp->dccps_awl, dp->dccps_awh)) {
  265. dccp_pr_debug("invalid ackno: S.AWL=%llu, "
  266. "P.ackno=%llu, S.AWH=%llu \n",
  267. (unsigned long long)dp->dccps_awl,
  268. (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq,
  269. (unsigned long long)dp->dccps_awh);
  270. goto out_invalid_packet;
  271. }
  272. if (dccp_parse_options(sk, skb))
  273. goto out_invalid_packet;
  274. /* Obtain usec RTT sample from SYN exchange (used by CCID 3) */
  275. if (likely(dp->dccps_options_received.dccpor_timestamp_echo))
  276. dp->dccps_syn_rtt = dccp_sample_rtt(sk, 10 * (tstamp -
  277. dp->dccps_options_received.dccpor_timestamp_echo));
  278. if (dccp_msk(sk)->dccpms_send_ack_vector &&
  279. dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
  280. DCCP_SKB_CB(skb)->dccpd_seq,
  281. DCCP_ACKVEC_STATE_RECEIVED))
  282. goto out_invalid_packet; /* FIXME: change error code */
  283. dp->dccps_isr = DCCP_SKB_CB(skb)->dccpd_seq;
  284. dccp_update_gsr(sk, dp->dccps_isr);
  285. /*
  286. * SWL and AWL are initially adjusted so that they are not less than
  287. * the initial Sequence Numbers received and sent, respectively:
  288. * SWL := max(GSR + 1 - floor(W/4), ISR),
  289. * AWL := max(GSS - W' + 1, ISS).
  290. * These adjustments MUST be applied only at the beginning of the
  291. * connection.
  292. *
  293. * AWL was adjusted in dccp_v4_connect -acme
  294. */
  295. dccp_set_seqno(&dp->dccps_swl,
  296. max48(dp->dccps_swl, dp->dccps_isr));
  297. dccp_sync_mss(sk, icsk->icsk_pmtu_cookie);
  298. /*
  299. * Step 10: Process REQUEST state (second part)
  300. * If S.state == REQUEST,
  301. * / * If we get here, P is a valid Response from the
  302. * server (see Step 4), and we should move to
  303. * PARTOPEN state. PARTOPEN means send an Ack,
  304. * don't send Data packets, retransmit Acks
  305. * periodically, and always include any Init Cookie
  306. * from the Response * /
  307. * S.state := PARTOPEN
  308. * Set PARTOPEN timer
  309. * Continue with S.state == PARTOPEN
  310. * / * Step 12 will send the Ack completing the
  311. * three-way handshake * /
  312. */
  313. dccp_set_state(sk, DCCP_PARTOPEN);
  314. /* Make sure socket is routed, for correct metrics. */
  315. icsk->icsk_af_ops->rebuild_header(sk);
  316. if (!sock_flag(sk, SOCK_DEAD)) {
  317. sk->sk_state_change(sk);
  318. sk_wake_async(sk, 0, POLL_OUT);
  319. }
  320. if (sk->sk_write_pending || icsk->icsk_ack.pingpong ||
  321. icsk->icsk_accept_queue.rskq_defer_accept) {
  322. /* Save one ACK. Data will be ready after
  323. * several ticks, if write_pending is set.
  324. *
  325. * It may be deleted, but with this feature tcpdumps
  326. * look so _wonderfully_ clever, that I was not able
  327. * to stand against the temptation 8) --ANK
  328. */
  329. /*
  330. * OK, in DCCP we can as well do a similar trick, its
  331. * even in the draft, but there is no need for us to
  332. * schedule an ack here, as dccp_sendmsg does this for
  333. * us, also stated in the draft. -acme
  334. */
  335. __kfree_skb(skb);
  336. return 0;
  337. }
  338. dccp_send_ack(sk);
  339. return -1;
  340. }
  341. out_invalid_packet:
  342. /* dccp_v4_do_rcv will send a reset */
  343. DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_PACKET_ERROR;
  344. return 1;
  345. }
  346. static int dccp_rcv_respond_partopen_state_process(struct sock *sk,
  347. struct sk_buff *skb,
  348. const struct dccp_hdr *dh,
  349. const unsigned len)
  350. {
  351. int queued = 0;
  352. switch (dh->dccph_type) {
  353. case DCCP_PKT_RESET:
  354. inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
  355. break;
  356. case DCCP_PKT_DATA:
  357. if (sk->sk_state == DCCP_RESPOND)
  358. break;
  359. case DCCP_PKT_DATAACK:
  360. case DCCP_PKT_ACK:
  361. /*
  362. * FIXME: we should be reseting the PARTOPEN (DELACK) timer
  363. * here but only if we haven't used the DELACK timer for
  364. * something else, like sending a delayed ack for a TIMESTAMP
  365. * echo, etc, for now were not clearing it, sending an extra
  366. * ACK when there is nothing else to do in DELACK is not a big
  367. * deal after all.
  368. */
  369. /* Stop the PARTOPEN timer */
  370. if (sk->sk_state == DCCP_PARTOPEN)
  371. inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
  372. dccp_sk(sk)->dccps_osr = DCCP_SKB_CB(skb)->dccpd_seq;
  373. dccp_set_state(sk, DCCP_OPEN);
  374. if (dh->dccph_type == DCCP_PKT_DATAACK ||
  375. dh->dccph_type == DCCP_PKT_DATA) {
  376. __dccp_rcv_established(sk, skb, dh, len);
  377. queued = 1; /* packet was queued
  378. (by __dccp_rcv_established) */
  379. }
  380. break;
  381. }
  382. return queued;
  383. }
  384. int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
  385. struct dccp_hdr *dh, unsigned len)
  386. {
  387. struct dccp_sock *dp = dccp_sk(sk);
  388. struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
  389. const int old_state = sk->sk_state;
  390. int queued = 0;
  391. /*
  392. * Step 3: Process LISTEN state
  393. *
  394. * If S.state == LISTEN,
  395. * If P.type == Request or P contains a valid Init Cookie option,
  396. * (* Must scan the packet's options to check for Init
  397. * Cookies. Only Init Cookies are processed here,
  398. * however; other options are processed in Step 8. This
  399. * scan need only be performed if the endpoint uses Init
  400. * Cookies *)
  401. * (* Generate a new socket and switch to that socket *)
  402. * Set S := new socket for this port pair
  403. * S.state = RESPOND
  404. * Choose S.ISS (initial seqno) or set from Init Cookies
  405. * Initialize S.GAR := S.ISS
  406. * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init
  407. * Cookies Continue with S.state == RESPOND
  408. * (* A Response packet will be generated in Step 11 *)
  409. * Otherwise,
  410. * Generate Reset(No Connection) unless P.type == Reset
  411. * Drop packet and return
  412. */
  413. if (sk->sk_state == DCCP_LISTEN) {
  414. if (dh->dccph_type == DCCP_PKT_REQUEST) {
  415. if (inet_csk(sk)->icsk_af_ops->conn_request(sk,
  416. skb) < 0)
  417. return 1;
  418. /* FIXME: do congestion control initialization */
  419. goto discard;
  420. }
  421. if (dh->dccph_type == DCCP_PKT_RESET)
  422. goto discard;
  423. /* Caller (dccp_v4_do_rcv) will send Reset */
  424. dcb->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION;
  425. return 1;
  426. }
  427. if (sk->sk_state != DCCP_REQUESTING) {
  428. if (dccp_check_seqno(sk, skb))
  429. goto discard;
  430. /*
  431. * Step 8: Process options and mark acknowledgeable
  432. */
  433. if (dccp_parse_options(sk, skb))
  434. goto discard;
  435. if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
  436. dccp_event_ack_recv(sk, skb);
  437. if (dccp_msk(sk)->dccpms_send_ack_vector &&
  438. dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
  439. DCCP_SKB_CB(skb)->dccpd_seq,
  440. DCCP_ACKVEC_STATE_RECEIVED))
  441. goto discard;
  442. ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb);
  443. ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb);
  444. }
  445. /*
  446. * Step 9: Process Reset
  447. * If P.type == Reset,
  448. * Tear down connection
  449. * S.state := TIMEWAIT
  450. * Set TIMEWAIT timer
  451. * Drop packet and return
  452. */
  453. if (dh->dccph_type == DCCP_PKT_RESET) {
  454. /*
  455. * Queue the equivalent of TCP fin so that dccp_recvmsg
  456. * exits the loop
  457. */
  458. dccp_fin(sk, skb);
  459. dccp_time_wait(sk, DCCP_TIME_WAIT, 0);
  460. return 0;
  461. /*
  462. * Step 7: Check for unexpected packet types
  463. * If (S.is_server and P.type == CloseReq)
  464. * or (S.is_server and P.type == Response)
  465. * or (S.is_client and P.type == Request)
  466. * or (S.state == RESPOND and P.type == Data),
  467. * Send Sync packet acknowledging P.seqno
  468. * Drop packet and return
  469. */
  470. } else if ((dp->dccps_role != DCCP_ROLE_CLIENT &&
  471. (dh->dccph_type == DCCP_PKT_RESPONSE ||
  472. dh->dccph_type == DCCP_PKT_CLOSEREQ)) ||
  473. (dp->dccps_role == DCCP_ROLE_CLIENT &&
  474. dh->dccph_type == DCCP_PKT_REQUEST) ||
  475. (sk->sk_state == DCCP_RESPOND &&
  476. dh->dccph_type == DCCP_PKT_DATA)) {
  477. dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNC);
  478. goto discard;
  479. } else if (dh->dccph_type == DCCP_PKT_CLOSEREQ) {
  480. dccp_rcv_closereq(sk, skb);
  481. goto discard;
  482. } else if (dh->dccph_type == DCCP_PKT_CLOSE) {
  483. dccp_rcv_close(sk, skb);
  484. return 0;
  485. }
  486. switch (sk->sk_state) {
  487. case DCCP_CLOSED:
  488. dcb->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION;
  489. return 1;
  490. case DCCP_REQUESTING:
  491. /* FIXME: do congestion control initialization */
  492. queued = dccp_rcv_request_sent_state_process(sk, skb, dh, len);
  493. if (queued >= 0)
  494. return queued;
  495. __kfree_skb(skb);
  496. return 0;
  497. case DCCP_RESPOND:
  498. case DCCP_PARTOPEN:
  499. queued = dccp_rcv_respond_partopen_state_process(sk, skb,
  500. dh, len);
  501. break;
  502. }
  503. if (dh->dccph_type == DCCP_PKT_ACK ||
  504. dh->dccph_type == DCCP_PKT_DATAACK) {
  505. switch (old_state) {
  506. case DCCP_PARTOPEN:
  507. sk->sk_state_change(sk);
  508. sk_wake_async(sk, 0, POLL_OUT);
  509. break;
  510. }
  511. } else if (unlikely(dh->dccph_type == DCCP_PKT_SYNC)) {
  512. dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNCACK);
  513. goto discard;
  514. }
  515. if (!queued) {
  516. discard:
  517. __kfree_skb(skb);
  518. }
  519. return 0;
  520. }
  521. EXPORT_SYMBOL_GPL(dccp_rcv_state_process);
  522. /**
  523. * dccp_sample_rtt - Validate and finalise computation of RTT sample
  524. * @delta: number of microseconds between packet and acknowledgment
  525. * The routine is kept generic to work in different contexts. It should be
  526. * called immediately when the ACK used for the RTT sample arrives.
  527. */
  528. u32 dccp_sample_rtt(struct sock *sk, long delta)
  529. {
  530. /* dccpor_elapsed_time is either zeroed out or set and > 0 */
  531. delta -= dccp_sk(sk)->dccps_options_received.dccpor_elapsed_time * 10;
  532. if (unlikely(delta <= 0)) {
  533. DCCP_WARN("unusable RTT sample %ld, using min\n", delta);
  534. return DCCP_SANE_RTT_MIN;
  535. }
  536. if (unlikely(delta > DCCP_SANE_RTT_MAX)) {
  537. DCCP_WARN("RTT sample %ld too large, using max\n", delta);
  538. return DCCP_SANE_RTT_MAX;
  539. }
  540. return delta;
  541. }
  542. EXPORT_SYMBOL_GPL(dccp_sample_rtt);