input.c 17 KB

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