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