input.c 17 KB

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