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