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