Commit | Line | Data |
---|---|---|
7c657876 ACM |
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 | ||
13 | #include <linux/config.h> | |
14 | #include <linux/dccp.h> | |
15 | #include <linux/skbuff.h> | |
16 | ||
17 | #include <net/sock.h> | |
18 | ||
ae31c339 | 19 | #include "ackvec.h" |
7c657876 ACM |
20 | #include "ccid.h" |
21 | #include "dccp.h" | |
22 | ||
23 | static 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 | ||
33 | static void dccp_rcv_close(struct sock *sk, struct sk_buff *skb) | |
34 | { | |
7ad07e7c ACM |
35 | dccp_v4_send_reset(sk, DCCP_RESET_CODE_CLOSED); |
36 | dccp_fin(sk, skb); | |
37 | dccp_set_state(sk, DCCP_CLOSED); | |
331968bd | 38 | sk_wake_async(sk, 1, POLL_HUP); |
7c657876 ACM |
39 | } |
40 | ||
41 | static 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) { | |
e92ae93a | 50 | dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq, DCCP_PKT_SYNC); |
7c657876 ACM |
51 | return; |
52 | } | |
53 | ||
811265b8 ACM |
54 | if (sk->sk_state != DCCP_CLOSING) |
55 | dccp_set_state(sk, DCCP_CLOSING); | |
7ad07e7c | 56 | dccp_send_close(sk, 0); |
7c657876 ACM |
57 | } |
58 | ||
59 | static 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) | |
ae31c339 ACM |
64 | dccp_ackvec_check_rcv_ackno(dp->dccps_hc_rx_ackvec, sk, |
65 | DCCP_SKB_CB(skb)->dccpd_ack_seq); | |
7c657876 ACM |
66 | } |
67 | ||
68 | static 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); | |
e92ae93a | 72 | u64 lswl, lawl; |
7c657876 ACM |
73 | |
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) { | |
7690af3f ACM |
88 | if (between48(DCCP_SKB_CB(skb)->dccpd_ack_seq, |
89 | dp->dccps_awl, dp->dccps_awh) && | |
7c657876 ACM |
90 | !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; | |
e92ae93a ACM |
94 | } |
95 | ||
7c657876 ACM |
96 | /* |
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 | */ | |
e92ae93a ACM |
110 | lswl = dp->dccps_swl; |
111 | lawl = dp->dccps_awl; | |
112 | ||
113 | if (dh->dccph_type == DCCP_PKT_CLOSEREQ || | |
c59eab46 ACM |
114 | dh->dccph_type == DCCP_PKT_CLOSE || |
115 | dh->dccph_type == DCCP_PKT_RESET) { | |
7c657876 ACM |
116 | 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 || | |
7690af3f ACM |
123 | between48(DCCP_SKB_CB(skb)->dccpd_ack_seq, |
124 | lawl, dp->dccps_awh))) { | |
7c657876 ACM |
125 | dccp_update_gsr(sk, DCCP_SKB_CB(skb)->dccpd_seq); |
126 | ||
127 | if (dh->dccph_type != DCCP_PKT_SYNC && | |
7690af3f ACM |
128 | (DCCP_SKB_CB(skb)->dccpd_ack_seq != |
129 | DCCP_PKT_WITHOUT_ACK_SEQ)) | |
7c657876 ACM |
130 | dp->dccps_gar = DCCP_SKB_CB(skb)->dccpd_ack_seq; |
131 | } else { | |
a3054d48 ACM |
132 | 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), | |
58e45131 DM |
137 | (unsigned long long) lswl, |
138 | (unsigned long long) | |
139 | DCCP_SKB_CB(skb)->dccpd_seq, | |
140 | (unsigned long long) dp->dccps_swh, | |
a3054d48 ACM |
141 | (DCCP_SKB_CB(skb)->dccpd_ack_seq == |
142 | DCCP_PKT_WITHOUT_ACK_SEQ) ? "doesn't exist" : "exists", | |
58e45131 DM |
143 | (unsigned long long) lawl, |
144 | (unsigned long long) | |
145 | DCCP_SKB_CB(skb)->dccpd_ack_seq, | |
146 | (unsigned long long) dp->dccps_awh); | |
e92ae93a | 147 | dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq, DCCP_PKT_SYNC); |
7c657876 ACM |
148 | return -1; |
149 | } | |
150 | ||
151 | return 0; | |
152 | } | |
153 | ||
709dd3aa AB |
154 | static inline int __dccp_rcv_established(struct sock *sk, struct sk_buff *skb, |
155 | const struct dccp_hdr *dh, | |
156 | const unsigned len) | |
7c657876 ACM |
157 | { |
158 | struct dccp_sock *dp = dccp_sk(sk); | |
159 | ||
7c657876 ACM |
160 | switch (dccp_hdr(skb)->dccph_type) { |
161 | case DCCP_PKT_DATAACK: | |
162 | case DCCP_PKT_DATA: | |
163 | /* | |
7690af3f ACM |
164 | * FIXME: check if sk_receive_queue is full, schedule DATA_DROPPED |
165 | * option if it is. | |
7c657876 ACM |
166 | */ |
167 | __skb_pull(skb, dh->dccph_doff * 4); | |
168 | __skb_queue_tail(&sk->sk_receive_queue, skb); | |
169 | skb_set_owner_r(skb, sk); | |
170 | sk->sk_data_ready(sk, 0); | |
171 | return 0; | |
172 | case DCCP_PKT_ACK: | |
173 | goto discard; | |
174 | case DCCP_PKT_RESET: | |
175 | /* | |
176 | * Step 9: Process Reset | |
177 | * If P.type == Reset, | |
178 | * Tear down connection | |
179 | * S.state := TIMEWAIT | |
180 | * Set TIMEWAIT timer | |
181 | * Drop packet and return | |
182 | */ | |
183 | dccp_fin(sk, skb); | |
184 | dccp_time_wait(sk, DCCP_TIME_WAIT, 0); | |
185 | return 0; | |
186 | case DCCP_PKT_CLOSEREQ: | |
187 | dccp_rcv_closereq(sk, skb); | |
188 | goto discard; | |
189 | case DCCP_PKT_CLOSE: | |
190 | dccp_rcv_close(sk, skb); | |
191 | return 0; | |
192 | case DCCP_PKT_REQUEST: | |
193 | /* Step 7 | |
194 | * or (S.is_server and P.type == Response) | |
195 | * or (S.is_client and P.type == Request) | |
196 | * or (S.state >= OPEN and P.type == Request | |
197 | * and P.seqno >= S.OSR) | |
198 | * or (S.state >= OPEN and P.type == Response | |
199 | * and P.seqno >= S.OSR) | |
200 | * or (S.state == RESPOND and P.type == Data), | |
201 | * Send Sync packet acknowledging P.seqno | |
202 | * Drop packet and return | |
203 | */ | |
204 | if (dp->dccps_role != DCCP_ROLE_LISTEN) | |
205 | goto send_sync; | |
206 | goto check_seq; | |
207 | case DCCP_PKT_RESPONSE: | |
208 | if (dp->dccps_role != DCCP_ROLE_CLIENT) | |
209 | goto send_sync; | |
210 | check_seq: | |
211 | if (!before48(DCCP_SKB_CB(skb)->dccpd_seq, dp->dccps_osr)) { | |
212 | send_sync: | |
e92ae93a ACM |
213 | dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq, |
214 | DCCP_PKT_SYNC); | |
7c657876 ACM |
215 | } |
216 | break; | |
e92ae93a ACM |
217 | case DCCP_PKT_SYNC: |
218 | dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq, | |
219 | DCCP_PKT_SYNCACK); | |
220 | /* | |
221 | * From the draft: | |
222 | * | |
223 | * As with DCCP-Ack packets, DCCP-Sync and DCCP-SyncAck packets | |
224 | * MAY have non-zero-length application data areas, whose | |
225 | * contents * receivers MUST ignore. | |
226 | */ | |
227 | goto discard; | |
7c657876 ACM |
228 | } |
229 | ||
230 | DCCP_INC_STATS_BH(DCCP_MIB_INERRS); | |
231 | discard: | |
232 | __kfree_skb(skb); | |
233 | return 0; | |
234 | } | |
235 | ||
709dd3aa AB |
236 | int dccp_rcv_established(struct sock *sk, struct sk_buff *skb, |
237 | const struct dccp_hdr *dh, const unsigned len) | |
238 | { | |
239 | struct dccp_sock *dp = dccp_sk(sk); | |
240 | ||
241 | if (dccp_check_seqno(sk, skb)) | |
242 | goto discard; | |
243 | ||
244 | if (dccp_parse_options(sk, skb)) | |
245 | goto discard; | |
246 | ||
247 | if (DCCP_SKB_CB(skb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ) | |
248 | dccp_event_ack_recv(sk, skb); | |
249 | ||
250 | if (dp->dccps_options.dccpo_send_ack_vector && | |
251 | dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, | |
252 | DCCP_SKB_CB(skb)->dccpd_seq, | |
253 | DCCP_ACKVEC_STATE_RECEIVED)) | |
254 | goto discard; | |
255 | ||
256 | ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb); | |
257 | ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb); | |
258 | ||
259 | return __dccp_rcv_established(sk, skb, dh, len); | |
260 | discard: | |
261 | __kfree_skb(skb); | |
262 | return 0; | |
263 | } | |
264 | ||
f21e68ca ACM |
265 | EXPORT_SYMBOL_GPL(dccp_rcv_established); |
266 | ||
7c657876 ACM |
267 | static int dccp_rcv_request_sent_state_process(struct sock *sk, |
268 | struct sk_buff *skb, | |
269 | const struct dccp_hdr *dh, | |
270 | const unsigned len) | |
271 | { | |
272 | /* | |
273 | * Step 4: Prepare sequence numbers in REQUEST | |
274 | * If S.state == REQUEST, | |
275 | * If (P.type == Response or P.type == Reset) | |
276 | * and S.AWL <= P.ackno <= S.AWH, | |
277 | * / * Set sequence number variables corresponding to the | |
278 | * other endpoint, so P will pass the tests in Step 6 * / | |
279 | * Set S.GSR, S.ISR, S.SWL, S.SWH | |
280 | * / * Response processing continues in Step 10; Reset | |
281 | * processing continues in Step 9 * / | |
282 | */ | |
283 | if (dh->dccph_type == DCCP_PKT_RESPONSE) { | |
284 | const struct inet_connection_sock *icsk = inet_csk(sk); | |
285 | struct dccp_sock *dp = dccp_sk(sk); | |
286 | ||
287 | /* Stop the REQUEST timer */ | |
288 | inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS); | |
289 | BUG_TRAP(sk->sk_send_head != NULL); | |
290 | __kfree_skb(sk->sk_send_head); | |
291 | sk->sk_send_head = NULL; | |
292 | ||
7690af3f ACM |
293 | if (!between48(DCCP_SKB_CB(skb)->dccpd_ack_seq, |
294 | dp->dccps_awl, dp->dccps_awh)) { | |
295 | dccp_pr_debug("invalid ackno: S.AWL=%llu, " | |
296 | "P.ackno=%llu, S.AWH=%llu \n", | |
297 | (unsigned long long)dp->dccps_awl, | |
298 | (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq, | |
299 | (unsigned long long)dp->dccps_awh); | |
7c657876 ACM |
300 | goto out_invalid_packet; |
301 | } | |
9e377202 AB |
302 | |
303 | if (dp->dccps_options.dccpo_send_ack_vector && | |
304 | dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, | |
305 | DCCP_SKB_CB(skb)->dccpd_seq, | |
306 | DCCP_ACKVEC_STATE_RECEIVED)) | |
307 | goto out_invalid_packet; /* FIXME: change error code */ | |
7c657876 ACM |
308 | |
309 | dp->dccps_isr = DCCP_SKB_CB(skb)->dccpd_seq; | |
03ace394 ACM |
310 | dccp_update_gsr(sk, dp->dccps_isr); |
311 | /* | |
312 | * SWL and AWL are initially adjusted so that they are not less than | |
313 | * the initial Sequence Numbers received and sent, respectively: | |
314 | * SWL := max(GSR + 1 - floor(W/4), ISR), | |
315 | * AWL := max(GSS - W' + 1, ISS). | |
316 | * These adjustments MUST be applied only at the beginning of the | |
317 | * connection. | |
318 | * | |
319 | * AWL was adjusted in dccp_v4_connect -acme | |
320 | */ | |
321 | dccp_set_seqno(&dp->dccps_swl, | |
322 | max48(dp->dccps_swl, dp->dccps_isr)); | |
7c657876 ACM |
323 | |
324 | if (ccid_hc_rx_init(dp->dccps_hc_rx_ccid, sk) != 0 || | |
325 | ccid_hc_tx_init(dp->dccps_hc_tx_ccid, sk) != 0) { | |
326 | ccid_hc_rx_exit(dp->dccps_hc_rx_ccid, sk); | |
327 | ccid_hc_tx_exit(dp->dccps_hc_tx_ccid, sk); | |
328 | /* FIXME: send appropriate RESET code */ | |
329 | goto out_invalid_packet; | |
330 | } | |
331 | ||
d83d8461 | 332 | dccp_sync_mss(sk, icsk->icsk_pmtu_cookie); |
7c657876 ACM |
333 | |
334 | /* | |
335 | * Step 10: Process REQUEST state (second part) | |
336 | * If S.state == REQUEST, | |
7690af3f ACM |
337 | * / * If we get here, P is a valid Response from the |
338 | * server (see Step 4), and we should move to | |
339 | * PARTOPEN state. PARTOPEN means send an Ack, | |
340 | * don't send Data packets, retransmit Acks | |
341 | * periodically, and always include any Init Cookie | |
342 | * from the Response * / | |
7c657876 ACM |
343 | * S.state := PARTOPEN |
344 | * Set PARTOPEN timer | |
345 | * Continue with S.state == PARTOPEN | |
7690af3f ACM |
346 | * / * Step 12 will send the Ack completing the |
347 | * three-way handshake * / | |
7c657876 ACM |
348 | */ |
349 | dccp_set_state(sk, DCCP_PARTOPEN); | |
350 | ||
351 | /* Make sure socket is routed, for correct metrics. */ | |
57cca05a | 352 | icsk->icsk_af_ops->rebuild_header(sk); |
7c657876 ACM |
353 | |
354 | if (!sock_flag(sk, SOCK_DEAD)) { | |
355 | sk->sk_state_change(sk); | |
356 | sk_wake_async(sk, 0, POLL_OUT); | |
357 | } | |
358 | ||
359 | if (sk->sk_write_pending || icsk->icsk_ack.pingpong || | |
360 | icsk->icsk_accept_queue.rskq_defer_accept) { | |
361 | /* Save one ACK. Data will be ready after | |
362 | * several ticks, if write_pending is set. | |
363 | * | |
364 | * It may be deleted, but with this feature tcpdumps | |
365 | * look so _wonderfully_ clever, that I was not able | |
366 | * to stand against the temptation 8) --ANK | |
367 | */ | |
368 | /* | |
369 | * OK, in DCCP we can as well do a similar trick, its | |
370 | * even in the draft, but there is no need for us to | |
371 | * schedule an ack here, as dccp_sendmsg does this for | |
372 | * us, also stated in the draft. -acme | |
373 | */ | |
374 | __kfree_skb(skb); | |
375 | return 0; | |
376 | } | |
377 | dccp_send_ack(sk); | |
378 | return -1; | |
379 | } | |
380 | ||
381 | out_invalid_packet: | |
0c10c5d9 ACM |
382 | /* dccp_v4_do_rcv will send a reset */ |
383 | DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_PACKET_ERROR; | |
384 | return 1; | |
7c657876 ACM |
385 | } |
386 | ||
387 | static int dccp_rcv_respond_partopen_state_process(struct sock *sk, | |
388 | struct sk_buff *skb, | |
389 | const struct dccp_hdr *dh, | |
390 | const unsigned len) | |
391 | { | |
392 | int queued = 0; | |
393 | ||
394 | switch (dh->dccph_type) { | |
395 | case DCCP_PKT_RESET: | |
396 | inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK); | |
397 | break; | |
2a9bc9bb ACM |
398 | case DCCP_PKT_DATA: |
399 | if (sk->sk_state == DCCP_RESPOND) | |
400 | break; | |
7c657876 ACM |
401 | case DCCP_PKT_DATAACK: |
402 | case DCCP_PKT_ACK: | |
403 | /* | |
7690af3f ACM |
404 | * FIXME: we should be reseting the PARTOPEN (DELACK) timer |
405 | * here but only if we haven't used the DELACK timer for | |
406 | * something else, like sending a delayed ack for a TIMESTAMP | |
407 | * echo, etc, for now were not clearing it, sending an extra | |
408 | * ACK when there is nothing else to do in DELACK is not a big | |
409 | * deal after all. | |
7c657876 ACM |
410 | */ |
411 | ||
412 | /* Stop the PARTOPEN timer */ | |
413 | if (sk->sk_state == DCCP_PARTOPEN) | |
414 | inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK); | |
415 | ||
416 | dccp_sk(sk)->dccps_osr = DCCP_SKB_CB(skb)->dccpd_seq; | |
417 | dccp_set_state(sk, DCCP_OPEN); | |
418 | ||
2a9bc9bb ACM |
419 | if (dh->dccph_type == DCCP_PKT_DATAACK || |
420 | dh->dccph_type == DCCP_PKT_DATA) { | |
709dd3aa | 421 | __dccp_rcv_established(sk, skb, dh, len); |
7690af3f | 422 | queued = 1; /* packet was queued |
709dd3aa | 423 | (by __dccp_rcv_established) */ |
7c657876 ACM |
424 | } |
425 | break; | |
426 | } | |
427 | ||
428 | return queued; | |
429 | } | |
430 | ||
431 | int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb, | |
432 | struct dccp_hdr *dh, unsigned len) | |
433 | { | |
434 | struct dccp_sock *dp = dccp_sk(sk); | |
0c10c5d9 | 435 | struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); |
7c657876 ACM |
436 | const int old_state = sk->sk_state; |
437 | int queued = 0; | |
438 | ||
8649b0d4 ACM |
439 | /* |
440 | * Step 3: Process LISTEN state | |
441 | * (Continuing from dccp_v4_do_rcv and dccp_v6_do_rcv) | |
442 | * | |
443 | * If S.state == LISTEN, | |
444 | * If P.type == Request or P contains a valid Init Cookie | |
445 | * option, | |
446 | * * Must scan the packet's options to check for an Init | |
447 | * Cookie. Only the Init Cookie is processed here, | |
448 | * however; other options are processed in Step 8. This | |
449 | * scan need only be performed if the endpoint uses Init | |
450 | * Cookies * | |
451 | * * Generate a new socket and switch to that socket * | |
452 | * Set S := new socket for this port pair | |
453 | * S.state = RESPOND | |
454 | * Choose S.ISS (initial seqno) or set from Init Cookie | |
455 | * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookie | |
456 | * Continue with S.state == RESPOND | |
457 | * * A Response packet will be generated in Step 11 * | |
458 | * Otherwise, | |
459 | * Generate Reset(No Connection) unless P.type == Reset | |
460 | * Drop packet and return | |
461 | * | |
462 | * NOTE: the check for the packet types is done in | |
463 | * dccp_rcv_state_process | |
464 | */ | |
465 | if (sk->sk_state == DCCP_LISTEN) { | |
466 | if (dh->dccph_type == DCCP_PKT_REQUEST) { | |
57cca05a ACM |
467 | if (inet_csk(sk)->icsk_af_ops->conn_request(sk, |
468 | skb) < 0) | |
8649b0d4 ACM |
469 | return 1; |
470 | ||
471 | /* FIXME: do congestion control initialization */ | |
472 | goto discard; | |
473 | } | |
474 | if (dh->dccph_type == DCCP_PKT_RESET) | |
475 | goto discard; | |
476 | ||
0c10c5d9 ACM |
477 | /* Caller (dccp_v4_do_rcv) will send Reset */ |
478 | dcb->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION; | |
8649b0d4 ACM |
479 | return 1; |
480 | } | |
481 | ||
482 | if (sk->sk_state != DCCP_REQUESTING) { | |
7c657876 ACM |
483 | if (dccp_check_seqno(sk, skb)) |
484 | goto discard; | |
485 | ||
486 | /* | |
487 | * Step 8: Process options and mark acknowledgeable | |
488 | */ | |
489 | if (dccp_parse_options(sk, skb)) | |
490 | goto discard; | |
491 | ||
0c10c5d9 | 492 | if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ) |
7c657876 ACM |
493 | dccp_event_ack_recv(sk, skb); |
494 | ||
ae31c339 ACM |
495 | if (dp->dccps_options.dccpo_send_ack_vector && |
496 | dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, | |
497 | DCCP_SKB_CB(skb)->dccpd_seq, | |
498 | DCCP_ACKVEC_STATE_RECEIVED)) | |
499 | goto discard; | |
e84a9f5e AB |
500 | |
501 | ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb); | |
502 | ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb); | |
7c657876 ACM |
503 | } |
504 | ||
505 | /* | |
506 | * Step 9: Process Reset | |
507 | * If P.type == Reset, | |
508 | * Tear down connection | |
509 | * S.state := TIMEWAIT | |
510 | * Set TIMEWAIT timer | |
511 | * Drop packet and return | |
512 | */ | |
513 | if (dh->dccph_type == DCCP_PKT_RESET) { | |
7690af3f ACM |
514 | /* |
515 | * Queue the equivalent of TCP fin so that dccp_recvmsg | |
516 | * exits the loop | |
517 | */ | |
7c657876 ACM |
518 | dccp_fin(sk, skb); |
519 | dccp_time_wait(sk, DCCP_TIME_WAIT, 0); | |
520 | return 0; | |
521 | /* | |
522 | * Step 7: Check for unexpected packet types | |
523 | * If (S.is_server and P.type == CloseReq) | |
524 | * or (S.is_server and P.type == Response) | |
525 | * or (S.is_client and P.type == Request) | |
526 | * or (S.state == RESPOND and P.type == Data), | |
527 | * Send Sync packet acknowledging P.seqno | |
528 | * Drop packet and return | |
529 | */ | |
530 | } else if ((dp->dccps_role != DCCP_ROLE_CLIENT && | |
7690af3f ACM |
531 | (dh->dccph_type == DCCP_PKT_RESPONSE || |
532 | dh->dccph_type == DCCP_PKT_CLOSEREQ)) || | |
7c657876 ACM |
533 | (dp->dccps_role == DCCP_ROLE_CLIENT && |
534 | dh->dccph_type == DCCP_PKT_REQUEST) || | |
7690af3f ACM |
535 | (sk->sk_state == DCCP_RESPOND && |
536 | dh->dccph_type == DCCP_PKT_DATA)) { | |
0c10c5d9 | 537 | dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNC); |
7c657876 | 538 | goto discard; |
7ad07e7c ACM |
539 | } else if (dh->dccph_type == DCCP_PKT_CLOSEREQ) { |
540 | dccp_rcv_closereq(sk, skb); | |
541 | goto discard; | |
542 | } else if (dh->dccph_type == DCCP_PKT_CLOSE) { | |
543 | dccp_rcv_close(sk, skb); | |
544 | return 0; | |
7c657876 ACM |
545 | } |
546 | ||
2b80230a | 547 | if (unlikely(dh->dccph_type == DCCP_PKT_SYNC)) { |
0c10c5d9 | 548 | dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNCACK); |
2b80230a ACM |
549 | goto discard; |
550 | } | |
551 | ||
7c657876 ACM |
552 | switch (sk->sk_state) { |
553 | case DCCP_CLOSED: | |
0c10c5d9 | 554 | dcb->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION; |
7c657876 ACM |
555 | return 1; |
556 | ||
7c657876 ACM |
557 | case DCCP_REQUESTING: |
558 | /* FIXME: do congestion control initialization */ | |
559 | ||
560 | queued = dccp_rcv_request_sent_state_process(sk, skb, dh, len); | |
561 | if (queued >= 0) | |
562 | return queued; | |
563 | ||
564 | __kfree_skb(skb); | |
565 | return 0; | |
566 | ||
567 | case DCCP_RESPOND: | |
568 | case DCCP_PARTOPEN: | |
7690af3f ACM |
569 | queued = dccp_rcv_respond_partopen_state_process(sk, skb, |
570 | dh, len); | |
7c657876 ACM |
571 | break; |
572 | } | |
573 | ||
7690af3f ACM |
574 | if (dh->dccph_type == DCCP_PKT_ACK || |
575 | dh->dccph_type == DCCP_PKT_DATAACK) { | |
7c657876 ACM |
576 | switch (old_state) { |
577 | case DCCP_PARTOPEN: | |
578 | sk->sk_state_change(sk); | |
579 | sk_wake_async(sk, 0, POLL_OUT); | |
580 | break; | |
581 | } | |
582 | } | |
583 | ||
584 | if (!queued) { | |
585 | discard: | |
586 | __kfree_skb(skb); | |
587 | } | |
588 | return 0; | |
589 | } | |
f21e68ca ACM |
590 | |
591 | EXPORT_SYMBOL_GPL(dccp_rcv_state_process); |