input.c 17 KB

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