[CCID3]: Use function for RTT sampling
[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);
e92ae93a 71 u64 lswl, lawl;
7c657876
ACM
72
73 /*
74 * Step 5: Prepare sequence numbers for Sync
75 * If P.type == Sync or P.type == SyncAck,
76 * If S.AWL <= P.ackno <= S.AWH and P.seqno >= S.SWL,
77 * / * P is valid, so update sequence number variables
78 * accordingly. After this update, P will pass the tests
79 * in Step 6. A SyncAck is generated if necessary in
80 * Step 15 * /
81 * Update S.GSR, S.SWL, S.SWH
82 * Otherwise,
83 * Drop packet and return
84 */
8109b02b 85 if (dh->dccph_type == DCCP_PKT_SYNC ||
7c657876 86 dh->dccph_type == DCCP_PKT_SYNCACK) {
7690af3f
ACM
87 if (between48(DCCP_SKB_CB(skb)->dccpd_ack_seq,
88 dp->dccps_awl, dp->dccps_awh) &&
8d13bf9a
GR
89 dccp_delta_seqno(dp->dccps_swl,
90 DCCP_SKB_CB(skb)->dccpd_seq) >= 0)
7c657876
ACM
91 dccp_update_gsr(sk, DCCP_SKB_CB(skb)->dccpd_seq);
92 else
93 return -1;
e92ae93a 94 }
c9eaf173 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 {
59348b19
GR
132 DCCP_WARN("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", dccp_packet_name(dh->dccph_type),
136 (unsigned long long) lswl,
137 (unsigned long long) DCCP_SKB_CB(skb)->dccpd_seq,
138 (unsigned long long) dp->dccps_swh,
139 (DCCP_SKB_CB(skb)->dccpd_ack_seq ==
c9eaf173 140 DCCP_PKT_WITHOUT_ACK_SEQ) ? "doesn't exist" : "exists",
59348b19
GR
141 (unsigned long long) lawl,
142 (unsigned long long) DCCP_SKB_CB(skb)->dccpd_ack_seq,
143 (unsigned long long) dp->dccps_awh);
e92ae93a 144 dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq, DCCP_PKT_SYNC);
7c657876
ACM
145 return -1;
146 }
147
148 return 0;
149}
150
c25a18ba
ACM
151static int __dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
152 const struct dccp_hdr *dh, const unsigned len)
7c657876
ACM
153{
154 struct dccp_sock *dp = dccp_sk(sk);
155
7c657876
ACM
156 switch (dccp_hdr(skb)->dccph_type) {
157 case DCCP_PKT_DATAACK:
158 case DCCP_PKT_DATA:
159 /*
7690af3f
ACM
160 * FIXME: check if sk_receive_queue is full, schedule DATA_DROPPED
161 * option if it is.
7c657876
ACM
162 */
163 __skb_pull(skb, dh->dccph_doff * 4);
164 __skb_queue_tail(&sk->sk_receive_queue, skb);
165 skb_set_owner_r(skb, sk);
166 sk->sk_data_ready(sk, 0);
167 return 0;
168 case DCCP_PKT_ACK:
169 goto discard;
170 case DCCP_PKT_RESET:
171 /*
172 * Step 9: Process Reset
173 * If P.type == Reset,
174 * Tear down connection
175 * S.state := TIMEWAIT
176 * Set TIMEWAIT timer
177 * Drop packet and return
178 */
179 dccp_fin(sk, skb);
180 dccp_time_wait(sk, DCCP_TIME_WAIT, 0);
181 return 0;
182 case DCCP_PKT_CLOSEREQ:
183 dccp_rcv_closereq(sk, skb);
184 goto discard;
185 case DCCP_PKT_CLOSE:
186 dccp_rcv_close(sk, skb);
187 return 0;
188 case DCCP_PKT_REQUEST:
8109b02b
ACM
189 /* Step 7
190 * or (S.is_server and P.type == Response)
7c657876
ACM
191 * or (S.is_client and P.type == Request)
192 * or (S.state >= OPEN and P.type == Request
193 * and P.seqno >= S.OSR)
194 * or (S.state >= OPEN and P.type == Response
195 * and P.seqno >= S.OSR)
196 * or (S.state == RESPOND and P.type == Data),
197 * Send Sync packet acknowledging P.seqno
198 * Drop packet and return
199 */
200 if (dp->dccps_role != DCCP_ROLE_LISTEN)
201 goto send_sync;
202 goto check_seq;
203 case DCCP_PKT_RESPONSE:
204 if (dp->dccps_role != DCCP_ROLE_CLIENT)
205 goto send_sync;
206check_seq:
8d13bf9a
GR
207 if (dccp_delta_seqno(dp->dccps_osr,
208 DCCP_SKB_CB(skb)->dccpd_seq) >= 0) {
7c657876 209send_sync:
e92ae93a
ACM
210 dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq,
211 DCCP_PKT_SYNC);
7c657876
ACM
212 }
213 break;
e92ae93a
ACM
214 case DCCP_PKT_SYNC:
215 dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq,
216 DCCP_PKT_SYNCACK);
217 /*
0e64e94e 218 * From RFC 4340, sec. 5.7
e92ae93a
ACM
219 *
220 * As with DCCP-Ack packets, DCCP-Sync and DCCP-SyncAck packets
221 * MAY have non-zero-length application data areas, whose
0e64e94e 222 * contents receivers MUST ignore.
e92ae93a
ACM
223 */
224 goto discard;
7c657876
ACM
225 }
226
227 DCCP_INC_STATS_BH(DCCP_MIB_INERRS);
228discard:
229 __kfree_skb(skb);
230 return 0;
231}
232
709dd3aa
AB
233int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
234 const struct dccp_hdr *dh, const unsigned len)
235{
236 struct dccp_sock *dp = dccp_sk(sk);
237
238 if (dccp_check_seqno(sk, skb))
239 goto discard;
240
241 if (dccp_parse_options(sk, skb))
242 goto discard;
243
244 if (DCCP_SKB_CB(skb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
245 dccp_event_ack_recv(sk, skb);
246
a4bf3902 247 if (dccp_msk(sk)->dccpms_send_ack_vector &&
709dd3aa
AB
248 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
249 DCCP_SKB_CB(skb)->dccpd_seq,
250 DCCP_ACKVEC_STATE_RECEIVED))
251 goto discard;
252
151a9931
GR
253 ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb);
254 ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb);
709dd3aa
AB
255
256 return __dccp_rcv_established(sk, skb, dh, len);
257discard:
258 __kfree_skb(skb);
259 return 0;
260}
261
f21e68ca
ACM
262EXPORT_SYMBOL_GPL(dccp_rcv_established);
263
7c657876
ACM
264static int dccp_rcv_request_sent_state_process(struct sock *sk,
265 struct sk_buff *skb,
266 const struct dccp_hdr *dh,
267 const unsigned len)
268{
8109b02b 269 /*
7c657876
ACM
270 * Step 4: Prepare sequence numbers in REQUEST
271 * If S.state == REQUEST,
272 * If (P.type == Response or P.type == Reset)
273 * and S.AWL <= P.ackno <= S.AWH,
274 * / * Set sequence number variables corresponding to the
275 * other endpoint, so P will pass the tests in Step 6 * /
276 * Set S.GSR, S.ISR, S.SWL, S.SWH
277 * / * Response processing continues in Step 10; Reset
278 * processing continues in Step 9 * /
279 */
280 if (dh->dccph_type == DCCP_PKT_RESPONSE) {
281 const struct inet_connection_sock *icsk = inet_csk(sk);
282 struct dccp_sock *dp = dccp_sk(sk);
283
284 /* Stop the REQUEST timer */
285 inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS);
286 BUG_TRAP(sk->sk_send_head != NULL);
287 __kfree_skb(sk->sk_send_head);
288 sk->sk_send_head = NULL;
289
7690af3f
ACM
290 if (!between48(DCCP_SKB_CB(skb)->dccpd_ack_seq,
291 dp->dccps_awl, dp->dccps_awh)) {
292 dccp_pr_debug("invalid ackno: S.AWL=%llu, "
293 "P.ackno=%llu, S.AWH=%llu \n",
294 (unsigned long long)dp->dccps_awl,
295 (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq,
296 (unsigned long long)dp->dccps_awh);
7c657876
ACM
297 goto out_invalid_packet;
298 }
9e377202 299
afe00251
AB
300 if (dccp_parse_options(sk, skb))
301 goto out_invalid_packet;
302
c9eaf173
YH
303 if (dccp_msk(sk)->dccpms_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 323
d83d8461 324 dccp_sync_mss(sk, icsk->icsk_pmtu_cookie);
7c657876
ACM
325
326 /*
327 * Step 10: Process REQUEST state (second part)
328 * If S.state == REQUEST,
7690af3f
ACM
329 * / * If we get here, P is a valid Response from the
330 * server (see Step 4), and we should move to
331 * PARTOPEN state. PARTOPEN means send an Ack,
332 * don't send Data packets, retransmit Acks
333 * periodically, and always include any Init Cookie
334 * from the Response * /
7c657876
ACM
335 * S.state := PARTOPEN
336 * Set PARTOPEN timer
8109b02b 337 * Continue with S.state == PARTOPEN
7690af3f
ACM
338 * / * Step 12 will send the Ack completing the
339 * three-way handshake * /
7c657876
ACM
340 */
341 dccp_set_state(sk, DCCP_PARTOPEN);
342
343 /* Make sure socket is routed, for correct metrics. */
57cca05a 344 icsk->icsk_af_ops->rebuild_header(sk);
7c657876
ACM
345
346 if (!sock_flag(sk, SOCK_DEAD)) {
347 sk->sk_state_change(sk);
348 sk_wake_async(sk, 0, POLL_OUT);
349 }
350
351 if (sk->sk_write_pending || icsk->icsk_ack.pingpong ||
352 icsk->icsk_accept_queue.rskq_defer_accept) {
353 /* Save one ACK. Data will be ready after
354 * several ticks, if write_pending is set.
355 *
356 * It may be deleted, but with this feature tcpdumps
357 * look so _wonderfully_ clever, that I was not able
358 * to stand against the temptation 8) --ANK
359 */
360 /*
361 * OK, in DCCP we can as well do a similar trick, its
362 * even in the draft, but there is no need for us to
363 * schedule an ack here, as dccp_sendmsg does this for
364 * us, also stated in the draft. -acme
365 */
366 __kfree_skb(skb);
367 return 0;
8109b02b 368 }
7c657876
ACM
369 dccp_send_ack(sk);
370 return -1;
371 }
372
373out_invalid_packet:
0c10c5d9
ACM
374 /* dccp_v4_do_rcv will send a reset */
375 DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_PACKET_ERROR;
8109b02b 376 return 1;
7c657876
ACM
377}
378
379static int dccp_rcv_respond_partopen_state_process(struct sock *sk,
380 struct sk_buff *skb,
381 const struct dccp_hdr *dh,
382 const unsigned len)
383{
384 int queued = 0;
385
386 switch (dh->dccph_type) {
387 case DCCP_PKT_RESET:
388 inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
389 break;
2a9bc9bb
ACM
390 case DCCP_PKT_DATA:
391 if (sk->sk_state == DCCP_RESPOND)
392 break;
7c657876
ACM
393 case DCCP_PKT_DATAACK:
394 case DCCP_PKT_ACK:
395 /*
7690af3f
ACM
396 * FIXME: we should be reseting the PARTOPEN (DELACK) timer
397 * here but only if we haven't used the DELACK timer for
398 * something else, like sending a delayed ack for a TIMESTAMP
399 * echo, etc, for now were not clearing it, sending an extra
400 * ACK when there is nothing else to do in DELACK is not a big
401 * deal after all.
7c657876
ACM
402 */
403
404 /* Stop the PARTOPEN timer */
405 if (sk->sk_state == DCCP_PARTOPEN)
406 inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
407
408 dccp_sk(sk)->dccps_osr = DCCP_SKB_CB(skb)->dccpd_seq;
409 dccp_set_state(sk, DCCP_OPEN);
410
2a9bc9bb
ACM
411 if (dh->dccph_type == DCCP_PKT_DATAACK ||
412 dh->dccph_type == DCCP_PKT_DATA) {
709dd3aa 413 __dccp_rcv_established(sk, skb, dh, len);
7690af3f 414 queued = 1; /* packet was queued
709dd3aa 415 (by __dccp_rcv_established) */
7c657876
ACM
416 }
417 break;
418 }
419
420 return queued;
421}
422
423int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
424 struct dccp_hdr *dh, unsigned len)
425{
426 struct dccp_sock *dp = dccp_sk(sk);
0c10c5d9 427 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
7c657876
ACM
428 const int old_state = sk->sk_state;
429 int queued = 0;
430
8649b0d4
ACM
431 /*
432 * Step 3: Process LISTEN state
8649b0d4
ACM
433 *
434 * If S.state == LISTEN,
d83ca5ac
GR
435 * If P.type == Request or P contains a valid Init Cookie option,
436 * (* Must scan the packet's options to check for Init
437 * Cookies. Only Init Cookies are processed here,
438 * however; other options are processed in Step 8. This
439 * scan need only be performed if the endpoint uses Init
440 * Cookies *)
441 * (* Generate a new socket and switch to that socket *)
442 * Set S := new socket for this port pair
443 * S.state = RESPOND
444 * Choose S.ISS (initial seqno) or set from Init Cookies
445 * Initialize S.GAR := S.ISS
446 * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init
447 * Cookies Continue with S.state == RESPOND
448 * (* A Response packet will be generated in Step 11 *)
449 * Otherwise,
450 * Generate Reset(No Connection) unless P.type == Reset
451 * Drop packet and return
8649b0d4
ACM
452 */
453 if (sk->sk_state == DCCP_LISTEN) {
454 if (dh->dccph_type == DCCP_PKT_REQUEST) {
57cca05a
ACM
455 if (inet_csk(sk)->icsk_af_ops->conn_request(sk,
456 skb) < 0)
8649b0d4
ACM
457 return 1;
458
459 /* FIXME: do congestion control initialization */
460 goto discard;
461 }
462 if (dh->dccph_type == DCCP_PKT_RESET)
463 goto discard;
464
0c10c5d9
ACM
465 /* Caller (dccp_v4_do_rcv) will send Reset */
466 dcb->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION;
8649b0d4
ACM
467 return 1;
468 }
469
470 if (sk->sk_state != DCCP_REQUESTING) {
7c657876
ACM
471 if (dccp_check_seqno(sk, skb))
472 goto discard;
473
474 /*
475 * Step 8: Process options and mark acknowledgeable
476 */
477 if (dccp_parse_options(sk, skb))
478 goto discard;
479
0c10c5d9 480 if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
7c657876
ACM
481 dccp_event_ack_recv(sk, skb);
482
8109b02b 483 if (dccp_msk(sk)->dccpms_send_ack_vector &&
ae31c339 484 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
8109b02b
ACM
485 DCCP_SKB_CB(skb)->dccpd_seq,
486 DCCP_ACKVEC_STATE_RECEIVED))
487 goto discard;
e84a9f5e 488
151a9931
GR
489 ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb);
490 ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb);
7c657876
ACM
491 }
492
493 /*
494 * Step 9: Process Reset
495 * If P.type == Reset,
496 * Tear down connection
497 * S.state := TIMEWAIT
498 * Set TIMEWAIT timer
499 * Drop packet and return
500 */
501 if (dh->dccph_type == DCCP_PKT_RESET) {
7690af3f
ACM
502 /*
503 * Queue the equivalent of TCP fin so that dccp_recvmsg
504 * exits the loop
505 */
7c657876
ACM
506 dccp_fin(sk, skb);
507 dccp_time_wait(sk, DCCP_TIME_WAIT, 0);
508 return 0;
509 /*
510 * Step 7: Check for unexpected packet types
511 * If (S.is_server and P.type == CloseReq)
512 * or (S.is_server and P.type == Response)
513 * or (S.is_client and P.type == Request)
514 * or (S.state == RESPOND and P.type == Data),
515 * Send Sync packet acknowledging P.seqno
516 * Drop packet and return
517 */
518 } else if ((dp->dccps_role != DCCP_ROLE_CLIENT &&
7690af3f
ACM
519 (dh->dccph_type == DCCP_PKT_RESPONSE ||
520 dh->dccph_type == DCCP_PKT_CLOSEREQ)) ||
7c657876
ACM
521 (dp->dccps_role == DCCP_ROLE_CLIENT &&
522 dh->dccph_type == DCCP_PKT_REQUEST) ||
7690af3f
ACM
523 (sk->sk_state == DCCP_RESPOND &&
524 dh->dccph_type == DCCP_PKT_DATA)) {
0c10c5d9 525 dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNC);
7c657876 526 goto discard;
7ad07e7c
ACM
527 } else if (dh->dccph_type == DCCP_PKT_CLOSEREQ) {
528 dccp_rcv_closereq(sk, skb);
529 goto discard;
530 } else if (dh->dccph_type == DCCP_PKT_CLOSE) {
531 dccp_rcv_close(sk, skb);
532 return 0;
7c657876
ACM
533 }
534
2b80230a 535 if (unlikely(dh->dccph_type == DCCP_PKT_SYNC)) {
0c10c5d9 536 dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNCACK);
2b80230a
ACM
537 goto discard;
538 }
539
7c657876
ACM
540 switch (sk->sk_state) {
541 case DCCP_CLOSED:
0c10c5d9 542 dcb->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION;
7c657876
ACM
543 return 1;
544
7c657876
ACM
545 case DCCP_REQUESTING:
546 /* FIXME: do congestion control initialization */
547
548 queued = dccp_rcv_request_sent_state_process(sk, skb, dh, len);
549 if (queued >= 0)
550 return queued;
551
552 __kfree_skb(skb);
553 return 0;
554
555 case DCCP_RESPOND:
556 case DCCP_PARTOPEN:
7690af3f
ACM
557 queued = dccp_rcv_respond_partopen_state_process(sk, skb,
558 dh, len);
7c657876
ACM
559 break;
560 }
561
7690af3f
ACM
562 if (dh->dccph_type == DCCP_PKT_ACK ||
563 dh->dccph_type == DCCP_PKT_DATAACK) {
7c657876
ACM
564 switch (old_state) {
565 case DCCP_PARTOPEN:
566 sk->sk_state_change(sk);
567 sk_wake_async(sk, 0, POLL_OUT);
568 break;
569 }
570 }
571
8109b02b 572 if (!queued) {
7c657876
ACM
573discard:
574 __kfree_skb(skb);
575 }
576 return 0;
577}
f21e68ca
ACM
578
579EXPORT_SYMBOL_GPL(dccp_rcv_state_process);
4712a792
GR
580
581/**
582 * dccp_sample_rtt - Sample RTT from packet exchange
583 *
584 * @sk: connected dccp_sock
585 * @t_recv: receive timestamp of packet with timestamp echo
586 * @t_hist: packet history timestamp or NULL
587 */
588u32 dccp_sample_rtt(struct sock *sk, struct timeval *t_recv,
589 struct timeval *t_hist)
590{
591 struct dccp_sock *dp = dccp_sk(sk);
592 struct dccp_options_received *or = &dp->dccps_options_received;
593 suseconds_t delta;
594
595 if (t_hist == NULL) {
596 if (!or->dccpor_timestamp_echo) {
597 DCCP_WARN("packet without timestamp echo\n");
598 return DCCP_SANE_RTT_MAX;
599 }
600 timeval_sub_usecs(t_recv, or->dccpor_timestamp_echo * 10);
601 delta = timeval_usecs(t_recv);
602 } else
603 delta = timeval_delta(t_recv, t_hist);
604
605 delta -= or->dccpor_elapsed_time * 10; /* either set or 0 */
606
607 if (unlikely(delta <= 0)) {
608 DCCP_WARN("unusable RTT sample %ld, using min\n", (long)delta);
609 return DCCP_SANE_RTT_MIN;
610 }
611 if (unlikely(delta - (suseconds_t)DCCP_SANE_RTT_MAX > 0)) {
612 DCCP_WARN("RTT sample %ld too large, using max\n", (long)delta);
613 return DCCP_SANE_RTT_MAX;
614 }
615
616 return delta;
617}
618
619EXPORT_SYMBOL_GPL(dccp_sample_rtt);
This page took 0.2333 seconds and 5 git commands to generate.