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