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