input.c 17 KB

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