Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net/dccp/ackvec.c |
| 3 | * |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 4 | * An implementation of Ack Vectors for the DCCP protocol |
| 5 | * Copyright (c) 2007 University of Aberdeen, Scotland, UK |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 6 | * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@ghostprotocols.net> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; version 2 of the License; |
| 11 | */ |
| 12 | |
| 13 | #include "ackvec.h" |
| 14 | #include "dccp.h" |
| 15 | |
Arnaldo Carvalho de Melo | 9b07ef5 | 2006-03-20 17:16:17 -0800 | [diff] [blame] | 16 | #include <linux/init.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/kernel.h> |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 19 | #include <linux/skbuff.h> |
Arnaldo Carvalho de Melo | 9b07ef5 | 2006-03-20 17:16:17 -0800 | [diff] [blame] | 20 | #include <linux/slab.h> |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 21 | |
| 22 | #include <net/sock.h> |
| 23 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 24 | static struct kmem_cache *dccp_ackvec_slab; |
| 25 | static struct kmem_cache *dccp_ackvec_record_slab; |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 26 | |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 27 | struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority) |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 28 | { |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 29 | struct dccp_ackvec *av = kmem_cache_zalloc(dccp_ackvec_slab, priority); |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 30 | |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 31 | if (av != NULL) { |
Gerrit Renker | b3d14bf | 2010-11-10 21:21:35 +0100 | [diff] [blame^] | 32 | av->av_buf_head = av->av_buf_tail = DCCPAV_MAX_ACKVEC_LEN - 1; |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 33 | INIT_LIST_HEAD(&av->av_records); |
| 34 | } |
| 35 | return av; |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 38 | static void dccp_ackvec_purge_records(struct dccp_ackvec *av) |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 39 | { |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 40 | struct dccp_ackvec_record *cur, *next; |
| 41 | |
| 42 | list_for_each_entry_safe(cur, next, &av->av_records, avr_node) |
| 43 | kmem_cache_free(dccp_ackvec_record_slab, cur); |
| 44 | INIT_LIST_HEAD(&av->av_records); |
| 45 | } |
| 46 | |
| 47 | void dccp_ackvec_free(struct dccp_ackvec *av) |
| 48 | { |
| 49 | if (likely(av != NULL)) { |
| 50 | dccp_ackvec_purge_records(av); |
| 51 | kmem_cache_free(dccp_ackvec_slab, av); |
| 52 | } |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Gerrit Renker | 7d87093 | 2010-11-10 21:21:02 +0100 | [diff] [blame] | 55 | /** |
| 56 | * dccp_ackvec_update_records - Record information about sent Ack Vectors |
| 57 | * @av: Ack Vector records to update |
| 58 | * @seqno: Sequence number of the packet carrying the Ack Vector just sent |
| 59 | * @nonce_sum: The sum of all buffer nonces contained in the Ack Vector |
| 60 | */ |
| 61 | int dccp_ackvec_update_records(struct dccp_ackvec *av, u64 seqno, u8 nonce_sum) |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 62 | { |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 63 | struct dccp_ackvec_record *avr; |
| 64 | |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 65 | avr = kmem_cache_alloc(dccp_ackvec_record_slab, GFP_ATOMIC); |
Arnaldo Carvalho de Melo | 2d0817d | 2006-03-20 22:32:06 -0800 | [diff] [blame] | 66 | if (avr == NULL) |
Gerrit Renker | 7d87093 | 2010-11-10 21:21:02 +0100 | [diff] [blame] | 67 | return -ENOBUFS; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 68 | |
Gerrit Renker | 7d87093 | 2010-11-10 21:21:02 +0100 | [diff] [blame] | 69 | avr->avr_ack_seqno = seqno; |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 70 | avr->avr_ack_ptr = av->av_buf_head; |
| 71 | avr->avr_ack_ackno = av->av_buf_ackno; |
Gerrit Renker | 7d87093 | 2010-11-10 21:21:02 +0100 | [diff] [blame] | 72 | avr->avr_ack_nonce = nonce_sum; |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 73 | avr->avr_ack_runlen = dccp_ackvec_runlen(av->av_buf + av->av_buf_head); |
Gerrit Renker | 7d87093 | 2010-11-10 21:21:02 +0100 | [diff] [blame] | 74 | /* |
Gerrit Renker | b3d14bf | 2010-11-10 21:21:35 +0100 | [diff] [blame^] | 75 | * When the buffer overflows, we keep no more than one record. This is |
| 76 | * the simplest way of disambiguating sender-Acks dating from before the |
| 77 | * overflow from sender-Acks which refer to after the overflow; a simple |
| 78 | * solution is preferable here since we are handling an exception. |
| 79 | */ |
| 80 | if (av->av_overflow) |
| 81 | dccp_ackvec_purge_records(av); |
| 82 | /* |
Gerrit Renker | 7d87093 | 2010-11-10 21:21:02 +0100 | [diff] [blame] | 83 | * Since GSS is incremented for each packet, the list is automatically |
| 84 | * arranged in descending order of @ack_seqno. |
| 85 | */ |
| 86 | list_add(&avr->avr_node, &av->av_records); |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 87 | |
Gerrit Renker | 7d87093 | 2010-11-10 21:21:02 +0100 | [diff] [blame] | 88 | dccp_pr_debug("Added Vector, ack_seqno=%llu, ack_ackno=%llu (rl=%u)\n", |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 89 | (unsigned long long)avr->avr_ack_seqno, |
Gerrit Renker | 7d87093 | 2010-11-10 21:21:02 +0100 | [diff] [blame] | 90 | (unsigned long long)avr->avr_ack_ackno, |
| 91 | avr->avr_ack_runlen); |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 92 | return 0; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 95 | /* |
Gerrit Renker | b3d14bf | 2010-11-10 21:21:35 +0100 | [diff] [blame^] | 96 | * Buffer index and length computation using modulo-buffersize arithmetic. |
| 97 | * Note that, as pointers move from right to left, head is `before' tail. |
| 98 | */ |
| 99 | static inline u16 __ackvec_idx_add(const u16 a, const u16 b) |
| 100 | { |
| 101 | return (a + b) % DCCPAV_MAX_ACKVEC_LEN; |
| 102 | } |
| 103 | |
| 104 | static inline u16 __ackvec_idx_sub(const u16 a, const u16 b) |
| 105 | { |
| 106 | return __ackvec_idx_add(a, DCCPAV_MAX_ACKVEC_LEN - b); |
| 107 | } |
| 108 | |
| 109 | u16 dccp_ackvec_buflen(const struct dccp_ackvec *av) |
| 110 | { |
| 111 | if (unlikely(av->av_overflow)) |
| 112 | return DCCPAV_MAX_ACKVEC_LEN; |
| 113 | return __ackvec_idx_sub(av->av_buf_tail, av->av_buf_head); |
| 114 | } |
| 115 | |
| 116 | /* |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 117 | * If several packets are missing, the HC-Receiver may prefer to enter multiple |
| 118 | * bytes with run length 0, rather than a single byte with a larger run length; |
| 119 | * this simplifies table updates if one of the missing packets arrives. |
| 120 | */ |
| 121 | static inline int dccp_ackvec_set_buf_head_state(struct dccp_ackvec *av, |
| 122 | const unsigned int packets, |
Arnaldo Carvalho de Melo | e4dfd44 | 2006-01-04 01:46:34 -0200 | [diff] [blame] | 123 | const unsigned char state) |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 124 | { |
Kulikov Vasiliy | 8e64159 | 2010-07-17 05:21:00 +0000 | [diff] [blame] | 125 | long gap; |
Kris Katterjohn | a8fc3d8 | 2006-01-17 13:03:54 -0800 | [diff] [blame] | 126 | long new_head; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 127 | |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 128 | if (av->av_vec_len + packets > DCCPAV_MAX_ACKVEC_LEN) |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 129 | return -ENOBUFS; |
| 130 | |
| 131 | gap = packets - 1; |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 132 | new_head = av->av_buf_head - packets; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 133 | |
| 134 | if (new_head < 0) { |
| 135 | if (gap > 0) { |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 136 | memset(av->av_buf, DCCPAV_NOT_RECEIVED, |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 137 | gap + new_head + 1); |
| 138 | gap = -new_head; |
| 139 | } |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 140 | new_head += DCCPAV_MAX_ACKVEC_LEN; |
Arnaldo Carvalho de Melo | 8109b02 | 2006-12-10 16:01:18 -0200 | [diff] [blame] | 141 | } |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 142 | |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 143 | av->av_buf_head = new_head; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 144 | |
| 145 | if (gap > 0) |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 146 | memset(av->av_buf + av->av_buf_head + 1, |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 147 | DCCPAV_NOT_RECEIVED, gap); |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 148 | |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 149 | av->av_buf[av->av_buf_head] = state; |
| 150 | av->av_vec_len += packets; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | /* |
Gerrit Renker | 0e64e94 | 2006-10-24 16:17:51 -0700 | [diff] [blame] | 155 | * Implements the RFC 4340, Appendix A |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 156 | */ |
| 157 | int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk, |
| 158 | const u64 ackno, const u8 state) |
| 159 | { |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 160 | u8 *cur_head = av->av_buf + av->av_buf_head, |
| 161 | *buf_end = av->av_buf + DCCPAV_MAX_ACKVEC_LEN; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 162 | /* |
| 163 | * Check at the right places if the buffer is full, if it is, tell the |
| 164 | * caller to start dropping packets till the HC-Sender acks our ACK |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 165 | * vectors, when we will free up space in av_buf. |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 166 | * |
| 167 | * We may well decide to do buffer compression, etc, but for now lets |
| 168 | * just drop. |
| 169 | * |
Gerrit Renker | 0e64e94 | 2006-10-24 16:17:51 -0700 | [diff] [blame] | 170 | * From Appendix A.1.1 (`New Packets'): |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 171 | * |
| 172 | * Of course, the circular buffer may overflow, either when the |
| 173 | * HC-Sender is sending data at a very high rate, when the |
| 174 | * HC-Receiver's acknowledgements are not reaching the HC-Sender, |
| 175 | * or when the HC-Sender is forgetting to acknowledge those acks |
| 176 | * (so the HC-Receiver is unable to clean up old state). In this |
| 177 | * case, the HC-Receiver should either compress the buffer (by |
| 178 | * increasing run lengths when possible), transfer its state to |
| 179 | * a larger buffer, or, as a last resort, drop all received |
| 180 | * packets, without processing them whatsoever, until its buffer |
| 181 | * shrinks again. |
| 182 | */ |
| 183 | |
| 184 | /* See if this is the first ackno being inserted */ |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 185 | if (av->av_vec_len == 0) { |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 186 | *cur_head = state; |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 187 | av->av_vec_len = 1; |
| 188 | } else if (after48(ackno, av->av_buf_ackno)) { |
| 189 | const u64 delta = dccp_delta_seqno(av->av_buf_ackno, ackno); |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | * Look if the state of this packet is the same as the |
| 193 | * previous ackno and if so if we can bump the head len. |
| 194 | */ |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 195 | if (delta == 1 && dccp_ackvec_state(cur_head) == state && |
| 196 | dccp_ackvec_runlen(cur_head) < DCCPAV_MAX_RUNLEN) |
| 197 | *cur_head += 1; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 198 | else if (dccp_ackvec_set_buf_head_state(av, delta, state)) |
| 199 | return -ENOBUFS; |
| 200 | } else { |
| 201 | /* |
| 202 | * A.1.2. Old Packets |
| 203 | * |
Gerrit Renker | 0e64e94 | 2006-10-24 16:17:51 -0700 | [diff] [blame] | 204 | * When a packet with Sequence Number S <= buf_ackno |
| 205 | * arrives, the HC-Receiver will scan the table for |
| 206 | * the byte corresponding to S. (Indexing structures |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 207 | * could reduce the complexity of this scan.) |
| 208 | */ |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 209 | u64 delta = dccp_delta_seqno(ackno, av->av_buf_ackno); |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 210 | |
| 211 | while (1) { |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 212 | const u8 len = dccp_ackvec_runlen(cur_head); |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 213 | /* |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 214 | * valid packets not yet in av_buf have a reserved |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 215 | * entry, with a len equal to 0. |
| 216 | */ |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 217 | if (*cur_head == DCCPAV_NOT_RECEIVED && delta == 0) { |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 218 | dccp_pr_debug("Found %llu reserved seat!\n", |
| 219 | (unsigned long long)ackno); |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 220 | *cur_head = state; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 221 | goto out; |
| 222 | } |
| 223 | /* len == 0 means one packet */ |
| 224 | if (delta < len + 1) |
| 225 | goto out_duplicate; |
| 226 | |
| 227 | delta -= len + 1; |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 228 | if (++cur_head == buf_end) |
| 229 | cur_head = av->av_buf; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 233 | av->av_buf_ackno = ackno; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 234 | out: |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 235 | return 0; |
| 236 | |
| 237 | out_duplicate: |
| 238 | /* Duplicate packet */ |
| 239 | dccp_pr_debug("Received a dup or already considered lost " |
| 240 | "packet: %llu\n", (unsigned long long)ackno); |
| 241 | return -EILSEQ; |
| 242 | } |
| 243 | |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 244 | static void dccp_ackvec_throw_record(struct dccp_ackvec *av, |
| 245 | struct dccp_ackvec_record *avr) |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 246 | { |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 247 | struct dccp_ackvec_record *next; |
| 248 | |
Andrea Bittau | 23d06e3 | 2006-09-19 13:04:54 -0700 | [diff] [blame] | 249 | /* sort out vector length */ |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 250 | if (av->av_buf_head <= avr->avr_ack_ptr) |
| 251 | av->av_vec_len = avr->avr_ack_ptr - av->av_buf_head; |
Andrea Bittau | 23d06e3 | 2006-09-19 13:04:54 -0700 | [diff] [blame] | 252 | else |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 253 | av->av_vec_len = DCCPAV_MAX_ACKVEC_LEN - 1 - |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 254 | av->av_buf_head + avr->avr_ack_ptr; |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 255 | |
| 256 | /* free records */ |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 257 | list_for_each_entry_safe_from(avr, next, &av->av_records, avr_node) { |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 258 | list_del(&avr->avr_node); |
| 259 | kmem_cache_free(dccp_ackvec_record_slab, avr); |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 260 | } |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av, struct sock *sk, |
| 264 | const u64 ackno) |
| 265 | { |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 266 | struct dccp_ackvec_record *avr; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 267 | |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 268 | /* |
| 269 | * If we traverse backwards, it should be faster when we have large |
| 270 | * windows. We will be receiving ACKs for stuff we sent a while back |
| 271 | * -sorbo. |
| 272 | */ |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 273 | list_for_each_entry_reverse(avr, &av->av_records, avr_node) { |
| 274 | if (ackno == avr->avr_ack_seqno) { |
Gerrit Renker | 09dbc38 | 2006-11-14 12:57:34 -0200 | [diff] [blame] | 275 | dccp_pr_debug("%s ACK packet 0, len=%d, ack_seqno=%llu, " |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 276 | "ack_ackno=%llu, ACKED!\n", |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 277 | dccp_role(sk), avr->avr_ack_runlen, |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 278 | (unsigned long long)avr->avr_ack_seqno, |
| 279 | (unsigned long long)avr->avr_ack_ackno); |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 280 | dccp_ackvec_throw_record(av, avr); |
| 281 | break; |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 282 | } else if (avr->avr_ack_seqno > ackno) |
Andrea Bittau | d23ca15 | 2006-11-14 13:19:45 -0200 | [diff] [blame] | 283 | break; /* old news */ |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
| 287 | static void dccp_ackvec_check_rcv_ackvector(struct dccp_ackvec *av, |
Andrea Bittau | bdf13d2 | 2006-11-24 13:02:42 -0200 | [diff] [blame] | 288 | struct sock *sk, u64 *ackno, |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 289 | const unsigned char len, |
| 290 | const unsigned char *vector) |
| 291 | { |
| 292 | unsigned char i; |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 293 | struct dccp_ackvec_record *avr; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 294 | |
| 295 | /* Check if we actually sent an ACK vector */ |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 296 | if (list_empty(&av->av_records)) |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 297 | return; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 298 | |
| 299 | i = len; |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 300 | /* |
| 301 | * XXX |
| 302 | * I think it might be more efficient to work backwards. See comment on |
| 303 | * rcv_ackno. -sorbo. |
| 304 | */ |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 305 | avr = list_entry(av->av_records.next, struct dccp_ackvec_record, avr_node); |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 306 | while (i--) { |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 307 | const u8 rl = dccp_ackvec_runlen(vector); |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 308 | u64 ackno_end_rl; |
| 309 | |
Andrea Bittau | bdf13d2 | 2006-11-24 13:02:42 -0200 | [diff] [blame] | 310 | dccp_set_seqno(&ackno_end_rl, *ackno - rl); |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 311 | |
| 312 | /* |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 313 | * If our AVR sequence number is greater than the ack, go |
| 314 | * forward in the AVR list until it is not so. |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 315 | */ |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 316 | list_for_each_entry_from(avr, &av->av_records, avr_node) { |
| 317 | if (!after48(avr->avr_ack_seqno, *ackno)) |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 318 | goto found; |
| 319 | } |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 320 | /* End of the av_records list, not found, exit */ |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 321 | break; |
| 322 | found: |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 323 | if (between48(avr->avr_ack_seqno, ackno_end_rl, *ackno)) { |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 324 | if (dccp_ackvec_state(vector) != DCCPAV_NOT_RECEIVED) { |
Gerrit Renker | 09dbc38 | 2006-11-14 12:57:34 -0200 | [diff] [blame] | 325 | dccp_pr_debug("%s ACK vector 0, len=%d, " |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 326 | "ack_seqno=%llu, ack_ackno=%llu, " |
| 327 | "ACKED!\n", |
Gerrit Renker | 09dbc38 | 2006-11-14 12:57:34 -0200 | [diff] [blame] | 328 | dccp_role(sk), len, |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 329 | (unsigned long long) |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 330 | avr->avr_ack_seqno, |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 331 | (unsigned long long) |
Gerrit Renker | a47c510 | 2007-12-30 04:19:31 -0800 | [diff] [blame] | 332 | avr->avr_ack_ackno); |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 333 | dccp_ackvec_throw_record(av, avr); |
Andrea Bittau | afec35e | 2006-06-11 20:58:33 -0700 | [diff] [blame] | 334 | break; |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 335 | } |
| 336 | /* |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 337 | * If it wasn't received, continue scanning... we might |
| 338 | * find another one. |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 339 | */ |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 340 | } |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 341 | |
Andrea Bittau | bdf13d2 | 2006-11-24 13:02:42 -0200 | [diff] [blame] | 342 | dccp_set_seqno(ackno, ackno_end_rl - 1); |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 343 | ++vector; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb, |
Andrea Bittau | bdf13d2 | 2006-11-24 13:02:42 -0200 | [diff] [blame] | 348 | u64 *ackno, const u8 opt, const u8 *value, const u8 len) |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 349 | { |
Gerrit Renker | b20a9c2 | 2008-11-23 16:02:31 -0800 | [diff] [blame] | 350 | if (len > DCCP_SINGLE_OPT_MAXLEN) |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 351 | return -1; |
| 352 | |
| 353 | /* dccp_ackvector_print(DCCP_SKB_CB(skb)->dccpd_ack_seq, value, len); */ |
| 354 | dccp_ackvec_check_rcv_ackvector(dccp_sk(sk)->dccps_hc_rx_ackvec, sk, |
Andrea Bittau | bdf13d2 | 2006-11-24 13:02:42 -0200 | [diff] [blame] | 355 | ackno, len, value); |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 356 | return 0; |
| 357 | } |
Arnaldo Carvalho de Melo | 9b07ef5 | 2006-03-20 17:16:17 -0800 | [diff] [blame] | 358 | |
Arnaldo Carvalho de Melo | 9b07ef5 | 2006-03-20 17:16:17 -0800 | [diff] [blame] | 359 | int __init dccp_ackvec_init(void) |
| 360 | { |
| 361 | dccp_ackvec_slab = kmem_cache_create("dccp_ackvec", |
| 362 | sizeof(struct dccp_ackvec), 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 363 | SLAB_HWCACHE_ALIGN, NULL); |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 364 | if (dccp_ackvec_slab == NULL) |
| 365 | goto out_err; |
| 366 | |
Gerrit Renker | f17a37c | 2010-11-10 21:20:07 +0100 | [diff] [blame] | 367 | dccp_ackvec_record_slab = kmem_cache_create("dccp_ackvec_record", |
| 368 | sizeof(struct dccp_ackvec_record), |
| 369 | 0, SLAB_HWCACHE_ALIGN, NULL); |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 370 | if (dccp_ackvec_record_slab == NULL) |
| 371 | goto out_destroy_slab; |
Arnaldo Carvalho de Melo | 9b07ef5 | 2006-03-20 17:16:17 -0800 | [diff] [blame] | 372 | |
| 373 | return 0; |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 374 | |
| 375 | out_destroy_slab: |
| 376 | kmem_cache_destroy(dccp_ackvec_slab); |
| 377 | dccp_ackvec_slab = NULL; |
| 378 | out_err: |
Gerrit Renker | 59348b1 | 2006-11-20 18:39:23 -0200 | [diff] [blame] | 379 | DCCP_CRIT("Unable to create Ack Vector slab cache"); |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 380 | return -ENOBUFS; |
Arnaldo Carvalho de Melo | 9b07ef5 | 2006-03-20 17:16:17 -0800 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | void dccp_ackvec_exit(void) |
| 384 | { |
| 385 | if (dccp_ackvec_slab != NULL) { |
| 386 | kmem_cache_destroy(dccp_ackvec_slab); |
| 387 | dccp_ackvec_slab = NULL; |
| 388 | } |
Andrea Bittau | 02bcf28 | 2006-03-20 17:19:55 -0800 | [diff] [blame] | 389 | if (dccp_ackvec_record_slab != NULL) { |
| 390 | kmem_cache_destroy(dccp_ackvec_record_slab); |
| 391 | dccp_ackvec_record_slab = NULL; |
| 392 | } |
Arnaldo Carvalho de Melo | 9b07ef5 | 2006-03-20 17:16:17 -0800 | [diff] [blame] | 393 | } |