blob: 9a724ff2a6228607c044564a3cad74a1387c41ab [file] [log] [blame]
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -07001/*
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
13#include <linux/config.h>
14#include <linux/dccp.h>
15#include <linux/skbuff.h>
16
17#include <net/sock.h>
18
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070019#include "ackvec.h"
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070020#include "ccid.h"
21#include "dccp.h"
22
23static void dccp_fin(struct sock *sk, struct sk_buff *skb)
24{
25 sk->sk_shutdown |= RCV_SHUTDOWN;
26 sock_set_flag(sk, SOCK_DONE);
27 __skb_pull(skb, dccp_hdr(skb)->dccph_doff * 4);
28 __skb_queue_tail(&sk->sk_receive_queue, skb);
29 skb_set_owner_r(skb, sk);
30 sk->sk_data_ready(sk, 0);
31}
32
33static void dccp_rcv_close(struct sock *sk, struct sk_buff *skb)
34{
Arnaldo Carvalho de Melo7ad07e72005-08-23 21:50:06 -070035 dccp_v4_send_reset(sk, DCCP_RESET_CODE_CLOSED);
36 dccp_fin(sk, skb);
37 dccp_set_state(sk, DCCP_CLOSED);
Arnaldo Carvalho de Melo331968b2005-08-23 21:54:23 -070038 sk_wake_async(sk, 1, POLL_HUP);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070039}
40
41static void dccp_rcv_closereq(struct sock *sk, struct sk_buff *skb)
42{
43 /*
44 * Step 7: Check for unexpected packet types
45 * If (S.is_server and P.type == CloseReq)
46 * Send Sync packet acknowledging P.seqno
47 * Drop packet and return
48 */
49 if (dccp_sk(sk)->dccps_role != DCCP_ROLE_CLIENT) {
Arnaldo Carvalho de Meloe92ae932005-08-17 03:10:59 -030050 dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq, DCCP_PKT_SYNC);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070051 return;
52 }
53
Arnaldo Carvalho de Melo811265b2005-09-13 19:03:15 -030054 if (sk->sk_state != DCCP_CLOSING)
55 dccp_set_state(sk, DCCP_CLOSING);
Arnaldo Carvalho de Melo7ad07e72005-08-23 21:50:06 -070056 dccp_send_close(sk, 0);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070057}
58
59static inline void dccp_event_ack_recv(struct sock *sk, struct sk_buff *skb)
60{
61 struct dccp_sock *dp = dccp_sk(sk);
62
63 if (dp->dccps_options.dccpo_send_ack_vector)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070064 dccp_ackvec_check_rcv_ackno(dp->dccps_hc_rx_ackvec, sk,
65 DCCP_SKB_CB(skb)->dccpd_ack_seq);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070066}
67
68static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb)
69{
70 const struct dccp_hdr *dh = dccp_hdr(skb);
71 struct dccp_sock *dp = dccp_sk(sk);
Arnaldo Carvalho de Meloe92ae932005-08-17 03:10:59 -030072 u64 lswl, lawl;
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070073
74 /*
75 * Step 5: Prepare sequence numbers for Sync
76 * If P.type == Sync or P.type == SyncAck,
77 * If S.AWL <= P.ackno <= S.AWH and P.seqno >= S.SWL,
78 * / * P is valid, so update sequence number variables
79 * accordingly. After this update, P will pass the tests
80 * in Step 6. A SyncAck is generated if necessary in
81 * Step 15 * /
82 * Update S.GSR, S.SWL, S.SWH
83 * Otherwise,
84 * Drop packet and return
85 */
86 if (dh->dccph_type == DCCP_PKT_SYNC ||
87 dh->dccph_type == DCCP_PKT_SYNCACK) {
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -030088 if (between48(DCCP_SKB_CB(skb)->dccpd_ack_seq,
89 dp->dccps_awl, dp->dccps_awh) &&
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070090 !before48(DCCP_SKB_CB(skb)->dccpd_seq, dp->dccps_swl))
91 dccp_update_gsr(sk, DCCP_SKB_CB(skb)->dccpd_seq);
92 else
93 return -1;
Arnaldo Carvalho de Meloe92ae932005-08-17 03:10:59 -030094 }
95
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070096 /*
97 * Step 6: Check sequence numbers
98 * Let LSWL = S.SWL and LAWL = S.AWL
99 * If P.type == CloseReq or P.type == Close or P.type == Reset,
100 * LSWL := S.GSR + 1, LAWL := S.GAR
101 * If LSWL <= P.seqno <= S.SWH
102 * and (P.ackno does not exist or LAWL <= P.ackno <= S.AWH),
103 * Update S.GSR, S.SWL, S.SWH
104 * If P.type != Sync,
105 * Update S.GAR
106 * Otherwise,
107 * Send Sync packet acknowledging P.seqno
108 * Drop packet and return
109 */
Arnaldo Carvalho de Meloe92ae932005-08-17 03:10:59 -0300110 lswl = dp->dccps_swl;
111 lawl = dp->dccps_awl;
112
113 if (dh->dccph_type == DCCP_PKT_CLOSEREQ ||
Arnaldo Carvalho de Meloc59eab42005-08-18 21:12:02 -0300114 dh->dccph_type == DCCP_PKT_CLOSE ||
115 dh->dccph_type == DCCP_PKT_RESET) {
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700116 lswl = dp->dccps_gsr;
117 dccp_inc_seqno(&lswl);
118 lawl = dp->dccps_gar;
119 }
120
121 if (between48(DCCP_SKB_CB(skb)->dccpd_seq, lswl, dp->dccps_swh) &&
122 (DCCP_SKB_CB(skb)->dccpd_ack_seq == DCCP_PKT_WITHOUT_ACK_SEQ ||
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300123 between48(DCCP_SKB_CB(skb)->dccpd_ack_seq,
124 lawl, dp->dccps_awh))) {
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700125 dccp_update_gsr(sk, DCCP_SKB_CB(skb)->dccpd_seq);
126
127 if (dh->dccph_type != DCCP_PKT_SYNC &&
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300128 (DCCP_SKB_CB(skb)->dccpd_ack_seq !=
129 DCCP_PKT_WITHOUT_ACK_SEQ))
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700130 dp->dccps_gar = DCCP_SKB_CB(skb)->dccpd_ack_seq;
131 } else {
Arnaldo Carvalho de Meloa3054d42005-08-21 05:35:18 -0300132 LIMIT_NETDEBUG(KERN_WARNING "DCCP: Step 6 failed for %s packet, "
133 "(LSWL(%llu) <= P.seqno(%llu) <= S.SWH(%llu)) and "
134 "(P.ackno %s or LAWL(%llu) <= P.ackno(%llu) <= S.AWH(%llu), "
135 "sending SYNC...\n",
136 dccp_packet_name(dh->dccph_type),
David S. Miller58e45132005-08-21 23:46:01 -0700137 (unsigned long long) lswl,
138 (unsigned long long)
139 DCCP_SKB_CB(skb)->dccpd_seq,
140 (unsigned long long) dp->dccps_swh,
Arnaldo Carvalho de Meloa3054d42005-08-21 05:35:18 -0300141 (DCCP_SKB_CB(skb)->dccpd_ack_seq ==
142 DCCP_PKT_WITHOUT_ACK_SEQ) ? "doesn't exist" : "exists",
David S. Miller58e45132005-08-21 23:46:01 -0700143 (unsigned long long) lawl,
144 (unsigned long long)
145 DCCP_SKB_CB(skb)->dccpd_ack_seq,
146 (unsigned long long) dp->dccps_awh);
Arnaldo Carvalho de Meloe92ae932005-08-17 03:10:59 -0300147 dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq, DCCP_PKT_SYNC);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700148 return -1;
149 }
150
151 return 0;
152}
153
154int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
155 const struct dccp_hdr *dh, const unsigned len)
156{
157 struct dccp_sock *dp = dccp_sk(sk);
158
159 if (dccp_check_seqno(sk, skb))
160 goto discard;
161
162 if (dccp_parse_options(sk, skb))
163 goto discard;
164
165 if (DCCP_SKB_CB(skb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
166 dccp_event_ack_recv(sk, skb);
167
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700168 if (dp->dccps_options.dccpo_send_ack_vector &&
169 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
170 DCCP_SKB_CB(skb)->dccpd_seq,
171 DCCP_ACKVEC_STATE_RECEIVED))
172 goto discard;
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700173
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
177 switch (dccp_hdr(skb)->dccph_type) {
178 case DCCP_PKT_DATAACK:
179 case DCCP_PKT_DATA:
180 /*
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300181 * FIXME: check if sk_receive_queue is full, schedule DATA_DROPPED
182 * option if it is.
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700183 */
184 __skb_pull(skb, dh->dccph_doff * 4);
185 __skb_queue_tail(&sk->sk_receive_queue, skb);
186 skb_set_owner_r(skb, sk);
187 sk->sk_data_ready(sk, 0);
188 return 0;
189 case DCCP_PKT_ACK:
190 goto discard;
191 case DCCP_PKT_RESET:
192 /*
193 * Step 9: Process Reset
194 * If P.type == Reset,
195 * Tear down connection
196 * S.state := TIMEWAIT
197 * Set TIMEWAIT timer
198 * Drop packet and return
199 */
200 dccp_fin(sk, skb);
201 dccp_time_wait(sk, DCCP_TIME_WAIT, 0);
202 return 0;
203 case DCCP_PKT_CLOSEREQ:
204 dccp_rcv_closereq(sk, skb);
205 goto discard;
206 case DCCP_PKT_CLOSE:
207 dccp_rcv_close(sk, skb);
208 return 0;
209 case DCCP_PKT_REQUEST:
210 /* Step 7
211 * or (S.is_server and P.type == Response)
212 * or (S.is_client and P.type == Request)
213 * or (S.state >= OPEN and P.type == Request
214 * and P.seqno >= S.OSR)
215 * or (S.state >= OPEN and P.type == Response
216 * and P.seqno >= S.OSR)
217 * or (S.state == RESPOND and P.type == Data),
218 * Send Sync packet acknowledging P.seqno
219 * Drop packet and return
220 */
221 if (dp->dccps_role != DCCP_ROLE_LISTEN)
222 goto send_sync;
223 goto check_seq;
224 case DCCP_PKT_RESPONSE:
225 if (dp->dccps_role != DCCP_ROLE_CLIENT)
226 goto send_sync;
227check_seq:
228 if (!before48(DCCP_SKB_CB(skb)->dccpd_seq, dp->dccps_osr)) {
229send_sync:
Arnaldo Carvalho de Meloe92ae932005-08-17 03:10:59 -0300230 dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq,
231 DCCP_PKT_SYNC);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700232 }
233 break;
Arnaldo Carvalho de Meloe92ae932005-08-17 03:10:59 -0300234 case DCCP_PKT_SYNC:
235 dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq,
236 DCCP_PKT_SYNCACK);
237 /*
238 * From the draft:
239 *
240 * As with DCCP-Ack packets, DCCP-Sync and DCCP-SyncAck packets
241 * MAY have non-zero-length application data areas, whose
242 * contents * receivers MUST ignore.
243 */
244 goto discard;
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700245 }
246
247 DCCP_INC_STATS_BH(DCCP_MIB_INERRS);
248discard:
249 __kfree_skb(skb);
250 return 0;
251}
252
Arnaldo Carvalho de Melof21e68c2005-12-13 23:24:16 -0800253EXPORT_SYMBOL_GPL(dccp_rcv_established);
254
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700255static int dccp_rcv_request_sent_state_process(struct sock *sk,
256 struct sk_buff *skb,
257 const struct dccp_hdr *dh,
258 const unsigned len)
259{
260 /*
261 * Step 4: Prepare sequence numbers in REQUEST
262 * If S.state == REQUEST,
263 * If (P.type == Response or P.type == Reset)
264 * and S.AWL <= P.ackno <= S.AWH,
265 * / * Set sequence number variables corresponding to the
266 * other endpoint, so P will pass the tests in Step 6 * /
267 * Set S.GSR, S.ISR, S.SWL, S.SWH
268 * / * Response processing continues in Step 10; Reset
269 * processing continues in Step 9 * /
270 */
271 if (dh->dccph_type == DCCP_PKT_RESPONSE) {
272 const struct inet_connection_sock *icsk = inet_csk(sk);
273 struct dccp_sock *dp = dccp_sk(sk);
274
275 /* Stop the REQUEST timer */
276 inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS);
277 BUG_TRAP(sk->sk_send_head != NULL);
278 __kfree_skb(sk->sk_send_head);
279 sk->sk_send_head = NULL;
280
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300281 if (!between48(DCCP_SKB_CB(skb)->dccpd_ack_seq,
282 dp->dccps_awl, dp->dccps_awh)) {
283 dccp_pr_debug("invalid ackno: S.AWL=%llu, "
284 "P.ackno=%llu, S.AWH=%llu \n",
285 (unsigned long long)dp->dccps_awl,
286 (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq,
287 (unsigned long long)dp->dccps_awh);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700288 goto out_invalid_packet;
289 }
290
291 dp->dccps_isr = DCCP_SKB_CB(skb)->dccpd_seq;
Arnaldo Carvalho de Melo03ace392005-08-21 05:36:45 -0300292 dccp_update_gsr(sk, dp->dccps_isr);
293 /*
294 * SWL and AWL are initially adjusted so that they are not less than
295 * the initial Sequence Numbers received and sent, respectively:
296 * SWL := max(GSR + 1 - floor(W/4), ISR),
297 * AWL := max(GSS - W' + 1, ISS).
298 * These adjustments MUST be applied only at the beginning of the
299 * connection.
300 *
301 * AWL was adjusted in dccp_v4_connect -acme
302 */
303 dccp_set_seqno(&dp->dccps_swl,
304 max48(dp->dccps_swl, dp->dccps_isr));
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700305
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
314 dccp_sync_mss(sk, dp->dccps_pmtu_cookie);
315
316 /*
317 * Step 10: Process REQUEST state (second part)
318 * If S.state == REQUEST,
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300319 * / * If we get here, P is a valid Response from the
320 * server (see Step 4), and we should move to
321 * PARTOPEN state. PARTOPEN means send an Ack,
322 * don't send Data packets, retransmit Acks
323 * periodically, and always include any Init Cookie
324 * from the Response * /
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700325 * S.state := PARTOPEN
326 * Set PARTOPEN timer
327 * Continue with S.state == PARTOPEN
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300328 * / * Step 12 will send the Ack completing the
329 * three-way handshake * /
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700330 */
331 dccp_set_state(sk, DCCP_PARTOPEN);
332
333 /* Make sure socket is routed, for correct metrics. */
Arnaldo Carvalho de Melo57cca052005-12-13 23:16:16 -0800334 icsk->icsk_af_ops->rebuild_header(sk);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700335
336 if (!sock_flag(sk, SOCK_DEAD)) {
337 sk->sk_state_change(sk);
338 sk_wake_async(sk, 0, POLL_OUT);
339 }
340
341 if (sk->sk_write_pending || icsk->icsk_ack.pingpong ||
342 icsk->icsk_accept_queue.rskq_defer_accept) {
343 /* Save one ACK. Data will be ready after
344 * several ticks, if write_pending is set.
345 *
346 * It may be deleted, but with this feature tcpdumps
347 * look so _wonderfully_ clever, that I was not able
348 * to stand against the temptation 8) --ANK
349 */
350 /*
351 * OK, in DCCP we can as well do a similar trick, its
352 * even in the draft, but there is no need for us to
353 * schedule an ack here, as dccp_sendmsg does this for
354 * us, also stated in the draft. -acme
355 */
356 __kfree_skb(skb);
357 return 0;
358 }
359 dccp_send_ack(sk);
360 return -1;
361 }
362
363out_invalid_packet:
Arnaldo Carvalho de Melo0c10c5d2005-09-16 16:58:33 -0700364 /* dccp_v4_do_rcv will send a reset */
365 DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_PACKET_ERROR;
366 return 1;
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700367}
368
369static int dccp_rcv_respond_partopen_state_process(struct sock *sk,
370 struct sk_buff *skb,
371 const struct dccp_hdr *dh,
372 const unsigned len)
373{
374 int queued = 0;
375
376 switch (dh->dccph_type) {
377 case DCCP_PKT_RESET:
378 inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
379 break;
Arnaldo Carvalho de Melo2a9bc9b2005-10-10 21:25:00 -0700380 case DCCP_PKT_DATA:
381 if (sk->sk_state == DCCP_RESPOND)
382 break;
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700383 case DCCP_PKT_DATAACK:
384 case DCCP_PKT_ACK:
385 /*
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300386 * FIXME: we should be reseting the PARTOPEN (DELACK) timer
387 * here but only if we haven't used the DELACK timer for
388 * something else, like sending a delayed ack for a TIMESTAMP
389 * echo, etc, for now were not clearing it, sending an extra
390 * ACK when there is nothing else to do in DELACK is not a big
391 * deal after all.
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700392 */
393
394 /* Stop the PARTOPEN timer */
395 if (sk->sk_state == DCCP_PARTOPEN)
396 inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
397
398 dccp_sk(sk)->dccps_osr = DCCP_SKB_CB(skb)->dccpd_seq;
399 dccp_set_state(sk, DCCP_OPEN);
400
Arnaldo Carvalho de Melo2a9bc9b2005-10-10 21:25:00 -0700401 if (dh->dccph_type == DCCP_PKT_DATAACK ||
402 dh->dccph_type == DCCP_PKT_DATA) {
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700403 dccp_rcv_established(sk, skb, dh, len);
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300404 queued = 1; /* packet was queued
405 (by dccp_rcv_established) */
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700406 }
407 break;
408 }
409
410 return queued;
411}
412
413int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
414 struct dccp_hdr *dh, unsigned len)
415{
416 struct dccp_sock *dp = dccp_sk(sk);
Arnaldo Carvalho de Melo0c10c5d2005-09-16 16:58:33 -0700417 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700418 const int old_state = sk->sk_state;
419 int queued = 0;
420
Arnaldo Carvalho de Melo8649b0d2005-08-13 20:36:01 -0300421 /*
422 * Step 3: Process LISTEN state
423 * (Continuing from dccp_v4_do_rcv and dccp_v6_do_rcv)
424 *
425 * If S.state == LISTEN,
426 * If P.type == Request or P contains a valid Init Cookie
427 * option,
428 * * Must scan the packet's options to check for an Init
429 * Cookie. Only the Init Cookie is processed here,
430 * however; other options are processed in Step 8. This
431 * scan need only be performed if the endpoint uses Init
432 * Cookies *
433 * * Generate a new socket and switch to that socket *
434 * Set S := new socket for this port pair
435 * S.state = RESPOND
436 * Choose S.ISS (initial seqno) or set from Init Cookie
437 * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookie
438 * Continue with S.state == RESPOND
439 * * A Response packet will be generated in Step 11 *
440 * Otherwise,
441 * Generate Reset(No Connection) unless P.type == Reset
442 * Drop packet and return
443 *
444 * NOTE: the check for the packet types is done in
445 * dccp_rcv_state_process
446 */
447 if (sk->sk_state == DCCP_LISTEN) {
448 if (dh->dccph_type == DCCP_PKT_REQUEST) {
Arnaldo Carvalho de Melo57cca052005-12-13 23:16:16 -0800449 if (inet_csk(sk)->icsk_af_ops->conn_request(sk,
450 skb) < 0)
Arnaldo Carvalho de Melo8649b0d2005-08-13 20:36:01 -0300451 return 1;
452
453 /* FIXME: do congestion control initialization */
454 goto discard;
455 }
456 if (dh->dccph_type == DCCP_PKT_RESET)
457 goto discard;
458
Arnaldo Carvalho de Melo0c10c5d2005-09-16 16:58:33 -0700459 /* Caller (dccp_v4_do_rcv) will send Reset */
460 dcb->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION;
Arnaldo Carvalho de Melo8649b0d2005-08-13 20:36:01 -0300461 return 1;
462 }
463
464 if (sk->sk_state != DCCP_REQUESTING) {
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700465 if (dccp_check_seqno(sk, skb))
466 goto discard;
467
468 /*
469 * Step 8: Process options and mark acknowledgeable
470 */
471 if (dccp_parse_options(sk, skb))
472 goto discard;
473
Arnaldo Carvalho de Melo0c10c5d2005-09-16 16:58:33 -0700474 if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700475 dccp_event_ack_recv(sk, skb);
476
477 ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb);
478 ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb);
479
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700480 if (dp->dccps_options.dccpo_send_ack_vector &&
481 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
482 DCCP_SKB_CB(skb)->dccpd_seq,
483 DCCP_ACKVEC_STATE_RECEIVED))
484 goto discard;
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700485 }
486
487 /*
488 * Step 9: Process Reset
489 * If P.type == Reset,
490 * Tear down connection
491 * S.state := TIMEWAIT
492 * Set TIMEWAIT timer
493 * Drop packet and return
494 */
495 if (dh->dccph_type == DCCP_PKT_RESET) {
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300496 /*
497 * Queue the equivalent of TCP fin so that dccp_recvmsg
498 * exits the loop
499 */
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700500 dccp_fin(sk, skb);
501 dccp_time_wait(sk, DCCP_TIME_WAIT, 0);
502 return 0;
503 /*
504 * Step 7: Check for unexpected packet types
505 * If (S.is_server and P.type == CloseReq)
506 * or (S.is_server and P.type == Response)
507 * or (S.is_client and P.type == Request)
508 * or (S.state == RESPOND and P.type == Data),
509 * Send Sync packet acknowledging P.seqno
510 * Drop packet and return
511 */
512 } else if ((dp->dccps_role != DCCP_ROLE_CLIENT &&
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300513 (dh->dccph_type == DCCP_PKT_RESPONSE ||
514 dh->dccph_type == DCCP_PKT_CLOSEREQ)) ||
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700515 (dp->dccps_role == DCCP_ROLE_CLIENT &&
516 dh->dccph_type == DCCP_PKT_REQUEST) ||
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300517 (sk->sk_state == DCCP_RESPOND &&
518 dh->dccph_type == DCCP_PKT_DATA)) {
Arnaldo Carvalho de Melo0c10c5d2005-09-16 16:58:33 -0700519 dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNC);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700520 goto discard;
Arnaldo Carvalho de Melo7ad07e72005-08-23 21:50:06 -0700521 } else if (dh->dccph_type == DCCP_PKT_CLOSEREQ) {
522 dccp_rcv_closereq(sk, skb);
523 goto discard;
524 } else if (dh->dccph_type == DCCP_PKT_CLOSE) {
525 dccp_rcv_close(sk, skb);
526 return 0;
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700527 }
528
Arnaldo Carvalho de Melo2b802302005-09-13 19:05:08 -0300529 if (unlikely(dh->dccph_type == DCCP_PKT_SYNC)) {
Arnaldo Carvalho de Melo0c10c5d2005-09-16 16:58:33 -0700530 dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNCACK);
Arnaldo Carvalho de Melo2b802302005-09-13 19:05:08 -0300531 goto discard;
532 }
533
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700534 switch (sk->sk_state) {
535 case DCCP_CLOSED:
Arnaldo Carvalho de Melo0c10c5d2005-09-16 16:58:33 -0700536 dcb->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION;
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700537 return 1;
538
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700539 case DCCP_REQUESTING:
540 /* FIXME: do congestion control initialization */
541
542 queued = dccp_rcv_request_sent_state_process(sk, skb, dh, len);
543 if (queued >= 0)
544 return queued;
545
546 __kfree_skb(skb);
547 return 0;
548
549 case DCCP_RESPOND:
550 case DCCP_PARTOPEN:
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300551 queued = dccp_rcv_respond_partopen_state_process(sk, skb,
552 dh, len);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700553 break;
554 }
555
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300556 if (dh->dccph_type == DCCP_PKT_ACK ||
557 dh->dccph_type == DCCP_PKT_DATAACK) {
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700558 switch (old_state) {
559 case DCCP_PARTOPEN:
560 sk->sk_state_change(sk);
561 sk_wake_async(sk, 0, POLL_OUT);
562 break;
563 }
564 }
565
566 if (!queued) {
567discard:
568 __kfree_skb(skb);
569 }
570 return 0;
571}
Arnaldo Carvalho de Melof21e68c2005-12-13 23:24:16 -0800572
573EXPORT_SYMBOL_GPL(dccp_rcv_state_process);