input.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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/config.h>
  13. #include <linux/dccp.h>
  14. #include <linux/skbuff.h>
  15. #include <net/sock.h>
  16. #include "ackvec.h"
  17. #include "ccid.h"
  18. #include "dccp.h"
  19. static void dccp_fin(struct sock *sk, struct sk_buff *skb)
  20. {
  21. sk->sk_shutdown |= RCV_SHUTDOWN;
  22. sock_set_flag(sk, SOCK_DONE);
  23. __skb_pull(skb, dccp_hdr(skb)->dccph_doff * 4);
  24. __skb_queue_tail(&sk->sk_receive_queue, skb);
  25. skb_set_owner_r(skb, sk);
  26. sk->sk_data_ready(sk, 0);
  27. }
  28. static void dccp_rcv_close(struct sock *sk, struct sk_buff *skb)
  29. {
  30. dccp_v4_send_reset(sk, DCCP_RESET_CODE_CLOSED);
  31. dccp_fin(sk, skb);
  32. dccp_set_state(sk, DCCP_CLOSED);
  33. sk_wake_async(sk, 1, POLL_HUP);
  34. }
  35. static void dccp_rcv_closereq(struct sock *sk, struct sk_buff *skb)
  36. {
  37. /*
  38. * Step 7: Check for unexpected packet types
  39. * If (S.is_server and P.type == CloseReq)
  40. * Send Sync packet acknowledging P.seqno
  41. * Drop packet and return
  42. */
  43. if (dccp_sk(sk)->dccps_role != DCCP_ROLE_CLIENT) {
  44. dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq, DCCP_PKT_SYNC);
  45. return;
  46. }
  47. if (sk->sk_state != DCCP_CLOSING)
  48. dccp_set_state(sk, DCCP_CLOSING);
  49. dccp_send_close(sk, 0);
  50. }
  51. static inline void dccp_event_ack_recv(struct sock *sk, struct sk_buff *skb)
  52. {
  53. struct dccp_sock *dp = dccp_sk(sk);
  54. if (dp->dccps_options.dccpo_send_ack_vector)
  55. dccp_ackvec_check_rcv_ackno(dp->dccps_hc_rx_ackvec, sk,
  56. DCCP_SKB_CB(skb)->dccpd_ack_seq);
  57. }
  58. static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb)
  59. {
  60. const struct dccp_hdr *dh = dccp_hdr(skb);
  61. struct dccp_sock *dp = dccp_sk(sk);
  62. u64 lswl, lawl;
  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(DCCP_SKB_CB(skb)->dccpd_ack_seq,
  78. dp->dccps_awl, dp->dccps_awh) &&
  79. !before48(DCCP_SKB_CB(skb)->dccpd_seq, dp->dccps_swl))
  80. dccp_update_gsr(sk, DCCP_SKB_CB(skb)->dccpd_seq);
  81. else
  82. return -1;
  83. }
  84. /*
  85. * Step 6: Check sequence numbers
  86. * Let LSWL = S.SWL and LAWL = S.AWL
  87. * If P.type == CloseReq or P.type == Close or P.type == Reset,
  88. * LSWL := S.GSR + 1, LAWL := S.GAR
  89. * If LSWL <= P.seqno <= S.SWH
  90. * and (P.ackno does not exist or LAWL <= P.ackno <= S.AWH),
  91. * Update S.GSR, S.SWL, S.SWH
  92. * If P.type != Sync,
  93. * Update S.GAR
  94. * Otherwise,
  95. * Send Sync packet acknowledging P.seqno
  96. * Drop packet and return
  97. */
  98. lswl = dp->dccps_swl;
  99. lawl = dp->dccps_awl;
  100. if (dh->dccph_type == DCCP_PKT_CLOSEREQ ||
  101. dh->dccph_type == DCCP_PKT_CLOSE ||
  102. dh->dccph_type == DCCP_PKT_RESET) {
  103. lswl = dp->dccps_gsr;
  104. dccp_inc_seqno(&lswl);
  105. lawl = dp->dccps_gar;
  106. }
  107. if (between48(DCCP_SKB_CB(skb)->dccpd_seq, lswl, dp->dccps_swh) &&
  108. (DCCP_SKB_CB(skb)->dccpd_ack_seq == DCCP_PKT_WITHOUT_ACK_SEQ ||
  109. between48(DCCP_SKB_CB(skb)->dccpd_ack_seq,
  110. lawl, dp->dccps_awh))) {
  111. dccp_update_gsr(sk, DCCP_SKB_CB(skb)->dccpd_seq);
  112. if (dh->dccph_type != DCCP_PKT_SYNC &&
  113. (DCCP_SKB_CB(skb)->dccpd_ack_seq !=
  114. DCCP_PKT_WITHOUT_ACK_SEQ))
  115. dp->dccps_gar = DCCP_SKB_CB(skb)->dccpd_ack_seq;
  116. } else {
  117. LIMIT_NETDEBUG(KERN_WARNING "DCCP: Step 6 failed for %s packet, "
  118. "(LSWL(%llu) <= P.seqno(%llu) <= S.SWH(%llu)) and "
  119. "(P.ackno %s or LAWL(%llu) <= P.ackno(%llu) <= S.AWH(%llu), "
  120. "sending SYNC...\n",
  121. dccp_packet_name(dh->dccph_type),
  122. (unsigned long long) lswl,
  123. (unsigned long long)
  124. DCCP_SKB_CB(skb)->dccpd_seq,
  125. (unsigned long long) dp->dccps_swh,
  126. (DCCP_SKB_CB(skb)->dccpd_ack_seq ==
  127. DCCP_PKT_WITHOUT_ACK_SEQ) ? "doesn't exist" : "exists",
  128. (unsigned long long) lawl,
  129. (unsigned long long)
  130. DCCP_SKB_CB(skb)->dccpd_ack_seq,
  131. (unsigned long long) dp->dccps_awh);
  132. dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq, DCCP_PKT_SYNC);
  133. return -1;
  134. }
  135. return 0;
  136. }
  137. static inline int __dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
  138. const struct dccp_hdr *dh,
  139. const unsigned len)
  140. {
  141. struct dccp_sock *dp = dccp_sk(sk);
  142. switch (dccp_hdr(skb)->dccph_type) {
  143. case DCCP_PKT_DATAACK:
  144. case DCCP_PKT_DATA:
  145. /*
  146. * FIXME: check if sk_receive_queue is full, schedule DATA_DROPPED
  147. * option if it is.
  148. */
  149. __skb_pull(skb, dh->dccph_doff * 4);
  150. __skb_queue_tail(&sk->sk_receive_queue, skb);
  151. skb_set_owner_r(skb, sk);
  152. sk->sk_data_ready(sk, 0);
  153. return 0;
  154. case DCCP_PKT_ACK:
  155. goto discard;
  156. case DCCP_PKT_RESET:
  157. /*
  158. * Step 9: Process Reset
  159. * If P.type == Reset,
  160. * Tear down connection
  161. * S.state := TIMEWAIT
  162. * Set TIMEWAIT timer
  163. * Drop packet and return
  164. */
  165. dccp_fin(sk, skb);
  166. dccp_time_wait(sk, DCCP_TIME_WAIT, 0);
  167. return 0;
  168. case DCCP_PKT_CLOSEREQ:
  169. dccp_rcv_closereq(sk, skb);
  170. goto discard;
  171. case DCCP_PKT_CLOSE:
  172. dccp_rcv_close(sk, skb);
  173. return 0;
  174. case DCCP_PKT_REQUEST:
  175. /* Step 7
  176. * or (S.is_server and P.type == Response)
  177. * or (S.is_client and P.type == Request)
  178. * or (S.state >= OPEN and P.type == Request
  179. * and P.seqno >= S.OSR)
  180. * or (S.state >= OPEN and P.type == Response
  181. * and P.seqno >= S.OSR)
  182. * or (S.state == RESPOND and P.type == Data),
  183. * Send Sync packet acknowledging P.seqno
  184. * Drop packet and return
  185. */
  186. if (dp->dccps_role != DCCP_ROLE_LISTEN)
  187. goto send_sync;
  188. goto check_seq;
  189. case DCCP_PKT_RESPONSE:
  190. if (dp->dccps_role != DCCP_ROLE_CLIENT)
  191. goto send_sync;
  192. check_seq:
  193. if (!before48(DCCP_SKB_CB(skb)->dccpd_seq, dp->dccps_osr)) {
  194. send_sync:
  195. dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq,
  196. DCCP_PKT_SYNC);
  197. }
  198. break;
  199. case DCCP_PKT_SYNC:
  200. dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq,
  201. DCCP_PKT_SYNCACK);
  202. /*
  203. * From the draft:
  204. *
  205. * As with DCCP-Ack packets, DCCP-Sync and DCCP-SyncAck packets
  206. * MAY have non-zero-length application data areas, whose
  207. * contents * receivers MUST ignore.
  208. */
  209. goto discard;
  210. }
  211. DCCP_INC_STATS_BH(DCCP_MIB_INERRS);
  212. discard:
  213. __kfree_skb(skb);
  214. return 0;
  215. }
  216. int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
  217. const struct dccp_hdr *dh, const unsigned len)
  218. {
  219. struct dccp_sock *dp = dccp_sk(sk);
  220. if (dccp_check_seqno(sk, skb))
  221. goto discard;
  222. if (dccp_parse_options(sk, skb))
  223. goto discard;
  224. if (DCCP_SKB_CB(skb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
  225. dccp_event_ack_recv(sk, skb);
  226. if (dp->dccps_options.dccpo_send_ack_vector &&
  227. dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
  228. DCCP_SKB_CB(skb)->dccpd_seq,
  229. DCCP_ACKVEC_STATE_RECEIVED))
  230. goto discard;
  231. ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb);
  232. ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb);
  233. return __dccp_rcv_established(sk, skb, dh, len);
  234. discard:
  235. __kfree_skb(skb);
  236. return 0;
  237. }
  238. EXPORT_SYMBOL_GPL(dccp_rcv_established);
  239. static int dccp_rcv_request_sent_state_process(struct sock *sk,
  240. struct sk_buff *skb,
  241. const struct dccp_hdr *dh,
  242. const unsigned len)
  243. {
  244. /*
  245. * Step 4: Prepare sequence numbers in REQUEST
  246. * If S.state == REQUEST,
  247. * If (P.type == Response or P.type == Reset)
  248. * and S.AWL <= P.ackno <= S.AWH,
  249. * / * Set sequence number variables corresponding to the
  250. * other endpoint, so P will pass the tests in Step 6 * /
  251. * Set S.GSR, S.ISR, S.SWL, S.SWH
  252. * / * Response processing continues in Step 10; Reset
  253. * processing continues in Step 9 * /
  254. */
  255. if (dh->dccph_type == DCCP_PKT_RESPONSE) {
  256. const struct inet_connection_sock *icsk = inet_csk(sk);
  257. struct dccp_sock *dp = dccp_sk(sk);
  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 (dp->dccps_options.dccpo_send_ack_vector &&
  273. dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
  274. DCCP_SKB_CB(skb)->dccpd_seq,
  275. DCCP_ACKVEC_STATE_RECEIVED))
  276. goto out_invalid_packet; /* FIXME: change error code */
  277. dp->dccps_isr = DCCP_SKB_CB(skb)->dccpd_seq;
  278. dccp_update_gsr(sk, dp->dccps_isr);
  279. /*
  280. * SWL and AWL are initially adjusted so that they are not less than
  281. * the initial Sequence Numbers received and sent, respectively:
  282. * SWL := max(GSR + 1 - floor(W/4), ISR),
  283. * AWL := max(GSS - W' + 1, ISS).
  284. * These adjustments MUST be applied only at the beginning of the
  285. * connection.
  286. *
  287. * AWL was adjusted in dccp_v4_connect -acme
  288. */
  289. dccp_set_seqno(&dp->dccps_swl,
  290. max48(dp->dccps_swl, dp->dccps_isr));
  291. if (ccid_hc_rx_init(dp->dccps_hc_rx_ccid, sk) != 0 ||
  292. ccid_hc_tx_init(dp->dccps_hc_tx_ccid, sk) != 0) {
  293. ccid_hc_rx_exit(dp->dccps_hc_rx_ccid, sk);
  294. ccid_hc_tx_exit(dp->dccps_hc_tx_ccid, sk);
  295. /* FIXME: send appropriate RESET code */
  296. goto out_invalid_packet;
  297. }
  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. * (Continuing from dccp_v4_do_rcv and dccp_v6_do_rcv)
  395. *
  396. * If S.state == LISTEN,
  397. * If P.type == Request or P contains a valid Init Cookie
  398. * option,
  399. * * Must scan the packet's options to check for an Init
  400. * Cookie. Only the Init Cookie is processed here,
  401. * however; other options are processed in Step 8. This
  402. * scan need only be performed if the endpoint uses Init
  403. * Cookies *
  404. * * Generate a new socket and switch to that socket *
  405. * Set S := new socket for this port pair
  406. * S.state = RESPOND
  407. * Choose S.ISS (initial seqno) or set from Init Cookie
  408. * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookie
  409. * Continue with S.state == RESPOND
  410. * * A Response packet will be generated in Step 11 *
  411. * Otherwise,
  412. * Generate Reset(No Connection) unless P.type == Reset
  413. * Drop packet and return
  414. *
  415. * NOTE: the check for the packet types is done in
  416. * dccp_rcv_state_process
  417. */
  418. if (sk->sk_state == DCCP_LISTEN) {
  419. if (dh->dccph_type == DCCP_PKT_REQUEST) {
  420. if (inet_csk(sk)->icsk_af_ops->conn_request(sk,
  421. skb) < 0)
  422. return 1;
  423. /* FIXME: do congestion control initialization */
  424. goto discard;
  425. }
  426. if (dh->dccph_type == DCCP_PKT_RESET)
  427. goto discard;
  428. /* Caller (dccp_v4_do_rcv) will send Reset */
  429. dcb->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION;
  430. return 1;
  431. }
  432. if (sk->sk_state != DCCP_REQUESTING) {
  433. if (dccp_check_seqno(sk, skb))
  434. goto discard;
  435. /*
  436. * Step 8: Process options and mark acknowledgeable
  437. */
  438. if (dccp_parse_options(sk, skb))
  439. goto discard;
  440. if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
  441. dccp_event_ack_recv(sk, skb);
  442. if (dp->dccps_options.dccpo_send_ack_vector &&
  443. dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
  444. DCCP_SKB_CB(skb)->dccpd_seq,
  445. DCCP_ACKVEC_STATE_RECEIVED))
  446. goto discard;
  447. ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb);
  448. ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb);
  449. }
  450. /*
  451. * Step 9: Process Reset
  452. * If P.type == Reset,
  453. * Tear down connection
  454. * S.state := TIMEWAIT
  455. * Set TIMEWAIT timer
  456. * Drop packet and return
  457. */
  458. if (dh->dccph_type == DCCP_PKT_RESET) {
  459. /*
  460. * Queue the equivalent of TCP fin so that dccp_recvmsg
  461. * exits the loop
  462. */
  463. dccp_fin(sk, skb);
  464. dccp_time_wait(sk, DCCP_TIME_WAIT, 0);
  465. return 0;
  466. /*
  467. * Step 7: Check for unexpected packet types
  468. * If (S.is_server and P.type == CloseReq)
  469. * or (S.is_server and P.type == Response)
  470. * or (S.is_client and P.type == Request)
  471. * or (S.state == RESPOND and P.type == Data),
  472. * Send Sync packet acknowledging P.seqno
  473. * Drop packet and return
  474. */
  475. } else if ((dp->dccps_role != DCCP_ROLE_CLIENT &&
  476. (dh->dccph_type == DCCP_PKT_RESPONSE ||
  477. dh->dccph_type == DCCP_PKT_CLOSEREQ)) ||
  478. (dp->dccps_role == DCCP_ROLE_CLIENT &&
  479. dh->dccph_type == DCCP_PKT_REQUEST) ||
  480. (sk->sk_state == DCCP_RESPOND &&
  481. dh->dccph_type == DCCP_PKT_DATA)) {
  482. dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNC);
  483. goto discard;
  484. } else if (dh->dccph_type == DCCP_PKT_CLOSEREQ) {
  485. dccp_rcv_closereq(sk, skb);
  486. goto discard;
  487. } else if (dh->dccph_type == DCCP_PKT_CLOSE) {
  488. dccp_rcv_close(sk, skb);
  489. return 0;
  490. }
  491. if (unlikely(dh->dccph_type == DCCP_PKT_SYNC)) {
  492. dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNCACK);
  493. goto discard;
  494. }
  495. switch (sk->sk_state) {
  496. case DCCP_CLOSED:
  497. dcb->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION;
  498. return 1;
  499. case DCCP_REQUESTING:
  500. /* FIXME: do congestion control initialization */
  501. queued = dccp_rcv_request_sent_state_process(sk, skb, dh, len);
  502. if (queued >= 0)
  503. return queued;
  504. __kfree_skb(skb);
  505. return 0;
  506. case DCCP_RESPOND:
  507. case DCCP_PARTOPEN:
  508. queued = dccp_rcv_respond_partopen_state_process(sk, skb,
  509. dh, len);
  510. break;
  511. }
  512. if (dh->dccph_type == DCCP_PKT_ACK ||
  513. dh->dccph_type == DCCP_PKT_DATAACK) {
  514. switch (old_state) {
  515. case DCCP_PARTOPEN:
  516. sk->sk_state_change(sk);
  517. sk_wake_async(sk, 0, POLL_OUT);
  518. break;
  519. }
  520. }
  521. if (!queued) {
  522. discard:
  523. __kfree_skb(skb);
  524. }
  525. return 0;
  526. }
  527. EXPORT_SYMBOL_GPL(dccp_rcv_state_process);