input.c 18 KB

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