Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * net/dccp/feat.c |
| 3 | * |
| 4 | * An implementation of the DCCP protocol |
| 5 | * Andrea Bittau <a.bittau@cs.ucl.ac.uk> |
| 6 | * |
Gerrit Renker | 5cdae19 | 2007-12-13 12:41:46 -0200 | [diff] [blame] | 7 | * ASSUMPTIONS |
| 8 | * ----------- |
Gerrit Renker | 5591d28 | 2008-09-04 07:30:19 +0200 | [diff] [blame^] | 9 | * o Feature negotiation is coordinated with connection setup (as in TCP), wild |
| 10 | * changes of parameters of an established connection are not supported. |
Gerrit Renker | 5cdae19 | 2007-12-13 12:41:46 -0200 | [diff] [blame] | 11 | * o All currently known SP features have 1-byte quantities. If in the future |
| 12 | * extensions of RFCs 4340..42 define features with item lengths larger than |
| 13 | * one byte, a feature-specific extension of the code will be required. |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation; either version |
| 18 | * 2 of the License, or (at your option) any later version. |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 23 | #include "ccid.h" |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 24 | #include "feat.h" |
| 25 | |
| 26 | #define DCCP_FEAT_SP_NOAGREE (-123) |
| 27 | |
Gerrit Renker | b4eec20 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 28 | static const struct { |
| 29 | u8 feat_num; /* DCCPF_xxx */ |
| 30 | enum dccp_feat_type rxtx; /* RX or TX */ |
| 31 | enum dccp_feat_type reconciliation; /* SP or NN */ |
| 32 | u8 default_value; /* as in 6.4 */ |
| 33 | /* |
| 34 | * Lookup table for location and type of features (from RFC 4340/4342) |
| 35 | * +--------------------------+----+-----+----+----+---------+-----------+ |
| 36 | * | Feature | Location | Reconc. | Initial | Section | |
| 37 | * | | RX | TX | SP | NN | Value | Reference | |
| 38 | * +--------------------------+----+-----+----+----+---------+-----------+ |
| 39 | * | DCCPF_CCID | | X | X | | 2 | 10 | |
| 40 | * | DCCPF_SHORT_SEQNOS | | X | X | | 0 | 7.6.1 | |
| 41 | * | DCCPF_SEQUENCE_WINDOW | | X | | X | 100 | 7.5.2 | |
| 42 | * | DCCPF_ECN_INCAPABLE | X | | X | | 0 | 12.1 | |
| 43 | * | DCCPF_ACK_RATIO | | X | | X | 2 | 11.3 | |
| 44 | * | DCCPF_SEND_ACK_VECTOR | X | | X | | 0 | 11.5 | |
| 45 | * | DCCPF_SEND_NDP_COUNT | | X | X | | 0 | 7.7.2 | |
| 46 | * | DCCPF_MIN_CSUM_COVER | X | | X | | 0 | 9.2.1 | |
| 47 | * | DCCPF_DATA_CHECKSUM | X | | X | | 0 | 9.3.1 | |
| 48 | * | DCCPF_SEND_LEV_RATE | X | | X | | 0 | 4342/8.4 | |
| 49 | * +--------------------------+----+-----+----+----+---------+-----------+ |
| 50 | */ |
| 51 | } dccp_feat_table[] = { |
| 52 | { DCCPF_CCID, FEAT_AT_TX, FEAT_SP, 2 }, |
| 53 | { DCCPF_SHORT_SEQNOS, FEAT_AT_TX, FEAT_SP, 0 }, |
| 54 | { DCCPF_SEQUENCE_WINDOW, FEAT_AT_TX, FEAT_NN, 100 }, |
| 55 | { DCCPF_ECN_INCAPABLE, FEAT_AT_RX, FEAT_SP, 0 }, |
| 56 | { DCCPF_ACK_RATIO, FEAT_AT_TX, FEAT_NN, 2 }, |
| 57 | { DCCPF_SEND_ACK_VECTOR, FEAT_AT_RX, FEAT_SP, 0 }, |
| 58 | { DCCPF_SEND_NDP_COUNT, FEAT_AT_TX, FEAT_SP, 0 }, |
| 59 | { DCCPF_MIN_CSUM_COVER, FEAT_AT_RX, FEAT_SP, 0 }, |
| 60 | { DCCPF_DATA_CHECKSUM, FEAT_AT_RX, FEAT_SP, 0 }, |
| 61 | { DCCPF_SEND_LEV_RATE, FEAT_AT_RX, FEAT_SP, 0 }, |
| 62 | }; |
| 63 | #define DCCP_FEAT_SUPPORTED_MAX ARRAY_SIZE(dccp_feat_table) |
| 64 | |
| 65 | /** |
| 66 | * dccp_feat_index - Hash function to map feature number into array position |
| 67 | * Returns consecutive array index or -1 if the feature is not understood. |
| 68 | */ |
| 69 | static int dccp_feat_index(u8 feat_num) |
| 70 | { |
| 71 | /* The first 9 entries are occupied by the types from RFC 4340, 6.4 */ |
| 72 | if (feat_num > DCCPF_RESERVED && feat_num <= DCCPF_DATA_CHECKSUM) |
| 73 | return feat_num - 1; |
| 74 | |
| 75 | /* |
| 76 | * Other features: add cases for new feature types here after adding |
| 77 | * them to the above table. |
| 78 | */ |
| 79 | switch (feat_num) { |
| 80 | case DCCPF_SEND_LEV_RATE: |
| 81 | return DCCP_FEAT_SUPPORTED_MAX - 1; |
| 82 | } |
| 83 | return -1; |
| 84 | } |
| 85 | |
| 86 | static u8 dccp_feat_type(u8 feat_num) |
| 87 | { |
| 88 | int idx = dccp_feat_index(feat_num); |
| 89 | |
| 90 | if (idx < 0) |
| 91 | return FEAT_UNKNOWN; |
| 92 | return dccp_feat_table[idx].reconciliation; |
| 93 | } |
| 94 | |
| 95 | static int dccp_feat_default_value(u8 feat_num) |
| 96 | { |
| 97 | int idx = dccp_feat_index(feat_num); |
| 98 | |
| 99 | return idx < 0 ? : dccp_feat_table[idx].default_value; |
| 100 | } |
| 101 | |
Gerrit Renker | 5c7c945 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 102 | /* copy constructor, fval must not already contain allocated memory */ |
| 103 | static int dccp_feat_clone_sp_val(dccp_feat_val *fval, u8 const *val, u8 len) |
| 104 | { |
| 105 | fval->sp.len = len; |
| 106 | if (fval->sp.len > 0) { |
| 107 | fval->sp.vec = kmemdup(val, len, gfp_any()); |
| 108 | if (fval->sp.vec == NULL) { |
| 109 | fval->sp.len = 0; |
| 110 | return -ENOBUFS; |
| 111 | } |
| 112 | } |
| 113 | return 0; |
| 114 | } |
| 115 | |
Gerrit Renker | b4eec20 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 116 | static void dccp_feat_val_destructor(u8 feat_num, dccp_feat_val *val) |
| 117 | { |
| 118 | if (unlikely(val == NULL)) |
| 119 | return; |
| 120 | if (dccp_feat_type(feat_num) == FEAT_SP) |
| 121 | kfree(val->sp.vec); |
| 122 | memset(val, 0, sizeof(*val)); |
| 123 | } |
| 124 | |
| 125 | static struct dccp_feat_entry * |
| 126 | dccp_feat_clone_entry(struct dccp_feat_entry const *original) |
| 127 | { |
| 128 | struct dccp_feat_entry *new; |
| 129 | u8 type = dccp_feat_type(original->feat_num); |
| 130 | |
| 131 | if (type == FEAT_UNKNOWN) |
| 132 | return NULL; |
| 133 | |
| 134 | new = kmemdup(original, sizeof(struct dccp_feat_entry), gfp_any()); |
| 135 | if (new == NULL) |
| 136 | return NULL; |
| 137 | |
| 138 | if (type == FEAT_SP && dccp_feat_clone_sp_val(&new->val, |
| 139 | original->val.sp.vec, |
| 140 | original->val.sp.len)) { |
| 141 | kfree(new); |
| 142 | return NULL; |
| 143 | } |
| 144 | return new; |
| 145 | } |
| 146 | |
| 147 | static void dccp_feat_entry_destructor(struct dccp_feat_entry *entry) |
| 148 | { |
| 149 | if (entry != NULL) { |
| 150 | dccp_feat_val_destructor(entry->feat_num, &entry->val); |
| 151 | kfree(entry); |
| 152 | } |
| 153 | } |
| 154 | |
Gerrit Renker | 3001fc0 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 155 | /* |
| 156 | * List management functions |
| 157 | * |
| 158 | * Feature negotiation lists rely on and maintain the following invariants: |
| 159 | * - each feat_num in the list is known, i.e. we know its type and default value |
| 160 | * - each feat_num/is_local combination is unique (old entries are overwritten) |
| 161 | * - SP values are always freshly allocated |
| 162 | * - list is sorted in increasing order of feature number (faster lookup) |
| 163 | */ |
| 164 | static struct dccp_feat_entry *dccp_feat_list_lookup(struct list_head *fn_list, |
| 165 | u8 feat_num, bool is_local) |
| 166 | { |
| 167 | struct dccp_feat_entry *entry; |
| 168 | |
| 169 | list_for_each_entry(entry, fn_list, node) |
| 170 | if (entry->feat_num == feat_num && entry->is_local == is_local) |
| 171 | return entry; |
| 172 | else if (entry->feat_num > feat_num) |
| 173 | break; |
| 174 | return NULL; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * dccp_feat_entry_new - Central list update routine (called by all others) |
| 179 | * @head: list to add to |
| 180 | * @feat: feature number |
| 181 | * @local: whether the local (1) or remote feature with number @feat is meant |
| 182 | * This is the only constructor and serves to ensure the above invariants. |
| 183 | */ |
| 184 | static struct dccp_feat_entry * |
| 185 | dccp_feat_entry_new(struct list_head *head, u8 feat, bool local) |
| 186 | { |
| 187 | struct dccp_feat_entry *entry; |
| 188 | |
| 189 | list_for_each_entry(entry, head, node) |
| 190 | if (entry->feat_num == feat && entry->is_local == local) { |
| 191 | dccp_feat_val_destructor(entry->feat_num, &entry->val); |
| 192 | return entry; |
| 193 | } else if (entry->feat_num > feat) { |
| 194 | head = &entry->node; |
| 195 | break; |
| 196 | } |
| 197 | |
| 198 | entry = kmalloc(sizeof(*entry), gfp_any()); |
| 199 | if (entry != NULL) { |
| 200 | entry->feat_num = feat; |
| 201 | entry->is_local = local; |
| 202 | list_add_tail(&entry->node, head); |
| 203 | } |
| 204 | return entry; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * dccp_feat_push_change - Add/overwrite a Change option in the list |
| 209 | * @fn_list: feature-negotiation list to update |
| 210 | * @feat: one of %dccp_feature_numbers |
| 211 | * @local: whether local (1) or remote (0) @feat_num is meant |
| 212 | * @needs_mandatory: whether to use Mandatory feature negotiation options |
| 213 | * @fval: pointer to NN/SP value to be inserted (will be copied) |
| 214 | */ |
| 215 | static int dccp_feat_push_change(struct list_head *fn_list, u8 feat, u8 local, |
| 216 | u8 mandatory, dccp_feat_val *fval) |
| 217 | { |
| 218 | struct dccp_feat_entry *new = dccp_feat_entry_new(fn_list, feat, local); |
| 219 | |
| 220 | if (new == NULL) |
| 221 | return -ENOMEM; |
| 222 | |
| 223 | new->feat_num = feat; |
| 224 | new->is_local = local; |
| 225 | new->state = FEAT_INITIALISING; |
| 226 | new->needs_confirm = 0; |
| 227 | new->empty_confirm = 0; |
| 228 | new->val = *fval; |
| 229 | new->needs_mandatory = mandatory; |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * dccp_feat_push_confirm - Add a Confirm entry to the FN list |
| 236 | * @fn_list: feature-negotiation list to add to |
| 237 | * @feat: one of %dccp_feature_numbers |
| 238 | * @local: whether local (1) or remote (0) @feat_num is being confirmed |
| 239 | * @fval: pointer to NN/SP value to be inserted or NULL |
| 240 | * Returns 0 on success, a Reset code for further processing otherwise. |
| 241 | */ |
| 242 | static int dccp_feat_push_confirm(struct list_head *fn_list, u8 feat, u8 local, |
| 243 | dccp_feat_val *fval) |
| 244 | { |
| 245 | struct dccp_feat_entry *new = dccp_feat_entry_new(fn_list, feat, local); |
| 246 | |
| 247 | if (new == NULL) |
| 248 | return DCCP_RESET_CODE_TOO_BUSY; |
| 249 | |
| 250 | new->feat_num = feat; |
| 251 | new->is_local = local; |
| 252 | new->state = FEAT_STABLE; /* transition in 6.6.2 */ |
| 253 | new->needs_confirm = 1; |
| 254 | new->empty_confirm = (fval == NULL); |
| 255 | new->val.nn = 0; /* zeroes the whole structure */ |
| 256 | if (!new->empty_confirm) |
| 257 | new->val = *fval; |
| 258 | new->needs_mandatory = 0; |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | static int dccp_push_empty_confirm(struct list_head *fn_list, u8 feat, u8 local) |
| 264 | { |
| 265 | return dccp_feat_push_confirm(fn_list, feat, local, NULL); |
| 266 | } |
| 267 | |
| 268 | static inline void dccp_feat_list_pop(struct dccp_feat_entry *entry) |
| 269 | { |
| 270 | list_del(&entry->node); |
| 271 | dccp_feat_entry_destructor(entry); |
| 272 | } |
| 273 | |
| 274 | void dccp_feat_list_purge(struct list_head *fn_list) |
| 275 | { |
| 276 | struct dccp_feat_entry *entry, *next; |
| 277 | |
| 278 | list_for_each_entry_safe(entry, next, fn_list, node) |
| 279 | dccp_feat_entry_destructor(entry); |
| 280 | INIT_LIST_HEAD(fn_list); |
| 281 | } |
| 282 | EXPORT_SYMBOL_GPL(dccp_feat_list_purge); |
| 283 | |
Gerrit Renker | 828755c | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 284 | /* generate @to as full clone of @from - @to must not contain any nodes */ |
| 285 | int dccp_feat_clone_list(struct list_head const *from, struct list_head *to) |
| 286 | { |
| 287 | struct dccp_feat_entry *entry, *new; |
| 288 | |
| 289 | INIT_LIST_HEAD(to); |
| 290 | list_for_each_entry(entry, from, node) { |
| 291 | new = dccp_feat_clone_entry(entry); |
| 292 | if (new == NULL) |
| 293 | goto cloning_failed; |
| 294 | list_add_tail(&new->node, to); |
| 295 | } |
| 296 | return 0; |
| 297 | |
| 298 | cloning_failed: |
| 299 | dccp_feat_list_purge(to); |
| 300 | return -ENOMEM; |
| 301 | } |
| 302 | |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 303 | int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature, |
| 304 | u8 *val, u8 len, gfp_t gfp) |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 305 | { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 306 | struct dccp_opt_pend *opt; |
| 307 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 308 | dccp_feat_debug(type, feature, *val); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 309 | |
Gerrit Renker | dd6303d | 2007-12-13 12:40:40 -0200 | [diff] [blame] | 310 | if (len > 3) { |
Gerrit Renker | 59348b1 | 2006-11-20 18:39:23 -0200 | [diff] [blame] | 311 | DCCP_WARN("invalid length %d\n", len); |
Chris Wright | 1944317 | 2008-05-05 13:50:24 -0700 | [diff] [blame] | 312 | return -EINVAL; |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 313 | } |
| 314 | /* XXX add further sanity checks */ |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 315 | |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 316 | /* check if that feature is already being negotiated */ |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 317 | list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 318 | /* ok we found a negotiation for this option already */ |
| 319 | if (opt->dccpop_feat == feature && opt->dccpop_type == type) { |
| 320 | dccp_pr_debug("Replacing old\n"); |
| 321 | /* replace */ |
| 322 | BUG_ON(opt->dccpop_val == NULL); |
| 323 | kfree(opt->dccpop_val); |
| 324 | opt->dccpop_val = val; |
| 325 | opt->dccpop_len = len; |
| 326 | opt->dccpop_conf = 0; |
| 327 | return 0; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /* negotiation for a new feature */ |
| 332 | opt = kmalloc(sizeof(*opt), gfp); |
| 333 | if (opt == NULL) |
| 334 | return -ENOMEM; |
| 335 | |
| 336 | opt->dccpop_type = type; |
| 337 | opt->dccpop_feat = feature; |
| 338 | opt->dccpop_len = len; |
| 339 | opt->dccpop_val = val; |
| 340 | opt->dccpop_conf = 0; |
| 341 | opt->dccpop_sc = NULL; |
| 342 | |
| 343 | BUG_ON(opt->dccpop_val == NULL); |
| 344 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 345 | list_add_tail(&opt->dccpop_node, &dmsk->dccpms_pending); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | EXPORT_SYMBOL_GPL(dccp_feat_change); |
| 350 | |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 351 | static int dccp_feat_update_ccid(struct sock *sk, u8 type, u8 new_ccid_nr) |
| 352 | { |
| 353 | struct dccp_sock *dp = dccp_sk(sk); |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 354 | struct dccp_minisock *dmsk = dccp_msk(sk); |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 355 | /* figure out if we are changing our CCID or the peer's */ |
| 356 | const int rx = type == DCCPO_CHANGE_R; |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 357 | const u8 ccid_nr = rx ? dmsk->dccpms_rx_ccid : dmsk->dccpms_tx_ccid; |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 358 | struct ccid *new_ccid; |
| 359 | |
| 360 | /* Check if nothing is being changed. */ |
| 361 | if (ccid_nr == new_ccid_nr) |
| 362 | return 0; |
| 363 | |
| 364 | new_ccid = ccid_new(new_ccid_nr, sk, rx, GFP_ATOMIC); |
| 365 | if (new_ccid == NULL) |
| 366 | return -ENOMEM; |
| 367 | |
| 368 | if (rx) { |
| 369 | ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk); |
| 370 | dp->dccps_hc_rx_ccid = new_ccid; |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 371 | dmsk->dccpms_rx_ccid = new_ccid_nr; |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 372 | } else { |
| 373 | ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk); |
| 374 | dp->dccps_hc_tx_ccid = new_ccid; |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 375 | dmsk->dccpms_tx_ccid = new_ccid_nr; |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | return 0; |
| 379 | } |
| 380 | |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 381 | static int dccp_feat_update(struct sock *sk, u8 type, u8 feat, u8 val) |
| 382 | { |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 383 | dccp_feat_debug(type, feat, val); |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 384 | |
| 385 | switch (feat) { |
| 386 | case DCCPF_CCID: |
| 387 | return dccp_feat_update_ccid(sk, type, val); |
| 388 | default: |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 389 | dccp_pr_debug("UNIMPLEMENTED: %s(%d, ...)\n", |
| 390 | dccp_feat_typename(type), feat); |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 391 | break; |
| 392 | } |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | static int dccp_feat_reconcile(struct sock *sk, struct dccp_opt_pend *opt, |
| 397 | u8 *rpref, u8 rlen) |
| 398 | { |
| 399 | struct dccp_sock *dp = dccp_sk(sk); |
| 400 | u8 *spref, slen, *res = NULL; |
| 401 | int i, j, rc, agree = 1; |
| 402 | |
| 403 | BUG_ON(rpref == NULL); |
| 404 | |
| 405 | /* check if we are the black sheep */ |
| 406 | if (dp->dccps_role == DCCP_ROLE_CLIENT) { |
| 407 | spref = rpref; |
| 408 | slen = rlen; |
| 409 | rpref = opt->dccpop_val; |
| 410 | rlen = opt->dccpop_len; |
| 411 | } else { |
| 412 | spref = opt->dccpop_val; |
| 413 | slen = opt->dccpop_len; |
| 414 | } |
| 415 | /* |
| 416 | * Now we have server preference list in spref and client preference in |
| 417 | * rpref |
| 418 | */ |
| 419 | BUG_ON(spref == NULL); |
| 420 | BUG_ON(rpref == NULL); |
| 421 | |
| 422 | /* FIXME sanity check vals */ |
| 423 | |
| 424 | /* Are values in any order? XXX Lame "algorithm" here */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 425 | for (i = 0; i < slen; i++) { |
| 426 | for (j = 0; j < rlen; j++) { |
| 427 | if (spref[i] == rpref[j]) { |
| 428 | res = &spref[i]; |
| 429 | break; |
| 430 | } |
| 431 | } |
| 432 | if (res) |
| 433 | break; |
| 434 | } |
| 435 | |
| 436 | /* we didn't agree on anything */ |
| 437 | if (res == NULL) { |
| 438 | /* confirm previous value */ |
| 439 | switch (opt->dccpop_feat) { |
| 440 | case DCCPF_CCID: |
| 441 | /* XXX did i get this right? =P */ |
| 442 | if (opt->dccpop_type == DCCPO_CHANGE_L) |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 443 | res = &dccp_msk(sk)->dccpms_tx_ccid; |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 444 | else |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 445 | res = &dccp_msk(sk)->dccpms_rx_ccid; |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 446 | break; |
| 447 | |
| 448 | default: |
Gerrit Renker | 59348b1 | 2006-11-20 18:39:23 -0200 | [diff] [blame] | 449 | DCCP_BUG("Fell through, feat=%d", opt->dccpop_feat); |
| 450 | /* XXX implement res */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 451 | return -EFAULT; |
| 452 | } |
| 453 | |
| 454 | dccp_pr_debug("Don't agree... reconfirming %d\n", *res); |
| 455 | agree = 0; /* this is used for mandatory options... */ |
| 456 | } |
| 457 | |
| 458 | /* need to put result and our preference list */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 459 | rlen = 1 + opt->dccpop_len; |
| 460 | rpref = kmalloc(rlen, GFP_ATOMIC); |
| 461 | if (rpref == NULL) |
| 462 | return -ENOMEM; |
| 463 | |
| 464 | *rpref = *res; |
| 465 | memcpy(&rpref[1], opt->dccpop_val, opt->dccpop_len); |
| 466 | |
| 467 | /* put it in the "confirm queue" */ |
| 468 | if (opt->dccpop_sc == NULL) { |
| 469 | opt->dccpop_sc = kmalloc(sizeof(*opt->dccpop_sc), GFP_ATOMIC); |
| 470 | if (opt->dccpop_sc == NULL) { |
| 471 | kfree(rpref); |
| 472 | return -ENOMEM; |
| 473 | } |
| 474 | } else { |
| 475 | /* recycle the confirm slot */ |
| 476 | BUG_ON(opt->dccpop_sc->dccpoc_val == NULL); |
| 477 | kfree(opt->dccpop_sc->dccpoc_val); |
| 478 | dccp_pr_debug("recycling confirm slot\n"); |
| 479 | } |
| 480 | memset(opt->dccpop_sc, 0, sizeof(*opt->dccpop_sc)); |
| 481 | |
| 482 | opt->dccpop_sc->dccpoc_val = rpref; |
| 483 | opt->dccpop_sc->dccpoc_len = rlen; |
| 484 | |
| 485 | /* update the option on our side [we are about to send the confirm] */ |
| 486 | rc = dccp_feat_update(sk, opt->dccpop_type, opt->dccpop_feat, *res); |
| 487 | if (rc) { |
| 488 | kfree(opt->dccpop_sc->dccpoc_val); |
| 489 | kfree(opt->dccpop_sc); |
Randy Dunlap | 68907da | 2006-03-29 13:58:25 -0800 | [diff] [blame] | 490 | opt->dccpop_sc = NULL; |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 491 | return rc; |
| 492 | } |
| 493 | |
| 494 | dccp_pr_debug("Will confirm %d\n", *rpref); |
| 495 | |
| 496 | /* say we want to change to X but we just got a confirm X, suppress our |
| 497 | * change |
| 498 | */ |
| 499 | if (!opt->dccpop_conf) { |
| 500 | if (*opt->dccpop_val == *res) |
| 501 | opt->dccpop_conf = 1; |
| 502 | dccp_pr_debug("won't ask for change of same feature\n"); |
| 503 | } |
| 504 | |
| 505 | return agree ? 0 : DCCP_FEAT_SP_NOAGREE; /* used for mandatory opts */ |
| 506 | } |
| 507 | |
| 508 | static int dccp_feat_sp(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len) |
| 509 | { |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 510 | struct dccp_minisock *dmsk = dccp_msk(sk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 511 | struct dccp_opt_pend *opt; |
| 512 | int rc = 1; |
| 513 | u8 t; |
| 514 | |
| 515 | /* |
| 516 | * We received a CHANGE. We gotta match it against our own preference |
| 517 | * list. If we got a CHANGE_R it means it's a change for us, so we need |
| 518 | * to compare our CHANGE_L list. |
| 519 | */ |
| 520 | if (type == DCCPO_CHANGE_L) |
| 521 | t = DCCPO_CHANGE_R; |
| 522 | else |
| 523 | t = DCCPO_CHANGE_L; |
| 524 | |
| 525 | /* find our preference list for this feature */ |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 526 | list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 527 | if (opt->dccpop_type != t || opt->dccpop_feat != feature) |
| 528 | continue; |
| 529 | |
| 530 | /* find the winner from the two preference lists */ |
| 531 | rc = dccp_feat_reconcile(sk, opt, val, len); |
| 532 | break; |
| 533 | } |
| 534 | |
| 535 | /* We didn't deal with the change. This can happen if we have no |
| 536 | * preference list for the feature. In fact, it just shouldn't |
| 537 | * happen---if we understand a feature, we should have a preference list |
| 538 | * with at least the default value. |
| 539 | */ |
| 540 | BUG_ON(rc == 1); |
| 541 | |
| 542 | return rc; |
| 543 | } |
| 544 | |
| 545 | static int dccp_feat_nn(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len) |
| 546 | { |
| 547 | struct dccp_opt_pend *opt; |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 548 | struct dccp_minisock *dmsk = dccp_msk(sk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 549 | u8 *copy; |
| 550 | int rc; |
| 551 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 552 | /* NN features must be Change L (sec. 6.3.2) */ |
| 553 | if (type != DCCPO_CHANGE_L) { |
| 554 | dccp_pr_debug("received %s for NN feature %d\n", |
| 555 | dccp_feat_typename(type), feature); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 556 | return -EFAULT; |
| 557 | } |
| 558 | |
| 559 | /* XXX sanity check opt val */ |
| 560 | |
| 561 | /* copy option so we can confirm it */ |
| 562 | opt = kzalloc(sizeof(*opt), GFP_ATOMIC); |
| 563 | if (opt == NULL) |
| 564 | return -ENOMEM; |
| 565 | |
Arnaldo Carvalho de Melo | eed7341 | 2006-11-17 12:21:43 -0200 | [diff] [blame] | 566 | copy = kmemdup(val, len, GFP_ATOMIC); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 567 | if (copy == NULL) { |
| 568 | kfree(opt); |
| 569 | return -ENOMEM; |
| 570 | } |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 571 | |
| 572 | opt->dccpop_type = DCCPO_CONFIRM_R; /* NN can only confirm R */ |
| 573 | opt->dccpop_feat = feature; |
| 574 | opt->dccpop_val = copy; |
| 575 | opt->dccpop_len = len; |
| 576 | |
| 577 | /* change feature */ |
| 578 | rc = dccp_feat_update(sk, type, feature, *val); |
| 579 | if (rc) { |
| 580 | kfree(opt->dccpop_val); |
| 581 | kfree(opt); |
| 582 | return rc; |
| 583 | } |
| 584 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 585 | dccp_feat_debug(type, feature, *copy); |
| 586 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 587 | list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 588 | |
| 589 | return 0; |
| 590 | } |
| 591 | |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 592 | static void dccp_feat_empty_confirm(struct dccp_minisock *dmsk, |
| 593 | u8 type, u8 feature) |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 594 | { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 595 | /* XXX check if other confirms for that are queued and recycle slot */ |
| 596 | struct dccp_opt_pend *opt = kzalloc(sizeof(*opt), GFP_ATOMIC); |
| 597 | |
| 598 | if (opt == NULL) { |
| 599 | /* XXX what do we do? Ignoring should be fine. It's a change |
| 600 | * after all =P |
| 601 | */ |
| 602 | return; |
| 603 | } |
| 604 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 605 | switch (type) { |
Jesper Juhl | e576de8 | 2007-08-10 15:23:54 -0700 | [diff] [blame] | 606 | case DCCPO_CHANGE_L: |
| 607 | opt->dccpop_type = DCCPO_CONFIRM_R; |
| 608 | break; |
| 609 | case DCCPO_CHANGE_R: |
| 610 | opt->dccpop_type = DCCPO_CONFIRM_L; |
| 611 | break; |
| 612 | default: |
| 613 | DCCP_WARN("invalid type %d\n", type); |
| 614 | kfree(opt); |
| 615 | return; |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 616 | } |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 617 | opt->dccpop_feat = feature; |
Randy Dunlap | 68907da | 2006-03-29 13:58:25 -0800 | [diff] [blame] | 618 | opt->dccpop_val = NULL; |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 619 | opt->dccpop_len = 0; |
| 620 | |
| 621 | /* change feature */ |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 622 | dccp_pr_debug("Empty %s(%d)\n", dccp_feat_typename(type), feature); |
| 623 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 624 | list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | static void dccp_feat_flush_confirm(struct sock *sk) |
| 628 | { |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 629 | struct dccp_minisock *dmsk = dccp_msk(sk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 630 | /* Check if there is anything to confirm in the first place */ |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 631 | int yes = !list_empty(&dmsk->dccpms_conf); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 632 | |
| 633 | if (!yes) { |
| 634 | struct dccp_opt_pend *opt; |
| 635 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 636 | list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 637 | if (opt->dccpop_conf) { |
| 638 | yes = 1; |
| 639 | break; |
| 640 | } |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | if (!yes) |
| 645 | return; |
| 646 | |
| 647 | /* OK there is something to confirm... */ |
| 648 | /* XXX check if packet is in flight? Send delayed ack?? */ |
| 649 | if (sk->sk_state == DCCP_OPEN) |
| 650 | dccp_send_ack(sk); |
| 651 | } |
| 652 | |
| 653 | int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len) |
| 654 | { |
| 655 | int rc; |
| 656 | |
Gerrit Renker | 5591d28 | 2008-09-04 07:30:19 +0200 | [diff] [blame^] | 657 | /* Ignore Change requests other than during connection setup */ |
| 658 | if (sk->sk_state != DCCP_LISTEN && sk->sk_state != DCCP_REQUESTING) |
| 659 | return 0; |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 660 | dccp_feat_debug(type, feature, *val); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 661 | |
| 662 | /* figure out if it's SP or NN feature */ |
| 663 | switch (feature) { |
| 664 | /* deal with SP features */ |
| 665 | case DCCPF_CCID: |
| 666 | rc = dccp_feat_sp(sk, type, feature, val, len); |
| 667 | break; |
| 668 | |
| 669 | /* deal with NN features */ |
| 670 | case DCCPF_ACK_RATIO: |
| 671 | rc = dccp_feat_nn(sk, type, feature, val, len); |
| 672 | break; |
| 673 | |
| 674 | /* XXX implement other features */ |
| 675 | default: |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 676 | dccp_pr_debug("UNIMPLEMENTED: not handling %s(%d, ...)\n", |
| 677 | dccp_feat_typename(type), feature); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 678 | rc = -EFAULT; |
| 679 | break; |
| 680 | } |
| 681 | |
| 682 | /* check if there were problems changing features */ |
| 683 | if (rc) { |
| 684 | /* If we don't agree on SP, we sent a confirm for old value. |
| 685 | * However we propagate rc to caller in case option was |
| 686 | * mandatory |
| 687 | */ |
| 688 | if (rc != DCCP_FEAT_SP_NOAGREE) |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 689 | dccp_feat_empty_confirm(dccp_msk(sk), type, feature); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /* generate the confirm [if required] */ |
| 693 | dccp_feat_flush_confirm(sk); |
| 694 | |
| 695 | return rc; |
| 696 | } |
| 697 | |
| 698 | EXPORT_SYMBOL_GPL(dccp_feat_change_recv); |
| 699 | |
| 700 | int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature, |
| 701 | u8 *val, u8 len) |
| 702 | { |
| 703 | u8 t; |
| 704 | struct dccp_opt_pend *opt; |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 705 | struct dccp_minisock *dmsk = dccp_msk(sk); |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 706 | int found = 0; |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 707 | int all_confirmed = 1; |
| 708 | |
Gerrit Renker | 5591d28 | 2008-09-04 07:30:19 +0200 | [diff] [blame^] | 709 | /* Ignore Confirm options other than during connection setup */ |
| 710 | if (sk->sk_state != DCCP_LISTEN && sk->sk_state != DCCP_REQUESTING) |
| 711 | return 0; |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 712 | dccp_feat_debug(type, feature, *val); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 713 | |
| 714 | /* locate our change request */ |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 715 | switch (type) { |
| 716 | case DCCPO_CONFIRM_L: t = DCCPO_CHANGE_R; break; |
| 717 | case DCCPO_CONFIRM_R: t = DCCPO_CHANGE_L; break; |
Arnaldo Carvalho de Melo | 8109b02 | 2006-12-10 16:01:18 -0200 | [diff] [blame] | 718 | default: DCCP_WARN("invalid type %d\n", type); |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 719 | return 1; |
| 720 | |
| 721 | } |
| 722 | /* XXX sanity check feature value */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 723 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 724 | list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 725 | if (!opt->dccpop_conf && opt->dccpop_type == t && |
| 726 | opt->dccpop_feat == feature) { |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 727 | found = 1; |
| 728 | dccp_pr_debug("feature %d found\n", opt->dccpop_feat); |
| 729 | |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 730 | /* XXX do sanity check */ |
| 731 | |
| 732 | opt->dccpop_conf = 1; |
| 733 | |
| 734 | /* We got a confirmation---change the option */ |
| 735 | dccp_feat_update(sk, opt->dccpop_type, |
| 736 | opt->dccpop_feat, *val); |
| 737 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 738 | /* XXX check the return value of dccp_feat_update */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 739 | break; |
| 740 | } |
| 741 | |
| 742 | if (!opt->dccpop_conf) |
| 743 | all_confirmed = 0; |
| 744 | } |
| 745 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 746 | if (!found) |
| 747 | dccp_pr_debug("%s(%d, ...) never requested\n", |
| 748 | dccp_feat_typename(type), feature); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 749 | return 0; |
| 750 | } |
| 751 | |
| 752 | EXPORT_SYMBOL_GPL(dccp_feat_confirm_recv); |
| 753 | |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 754 | void dccp_feat_clean(struct dccp_minisock *dmsk) |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 755 | { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 756 | struct dccp_opt_pend *opt, *next; |
| 757 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 758 | list_for_each_entry_safe(opt, next, &dmsk->dccpms_pending, |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 759 | dccpop_node) { |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 760 | BUG_ON(opt->dccpop_val == NULL); |
| 761 | kfree(opt->dccpop_val); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 762 | |
| 763 | if (opt->dccpop_sc != NULL) { |
| 764 | BUG_ON(opt->dccpop_sc->dccpoc_val == NULL); |
| 765 | kfree(opt->dccpop_sc->dccpoc_val); |
| 766 | kfree(opt->dccpop_sc); |
| 767 | } |
| 768 | |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 769 | kfree(opt); |
| 770 | } |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 771 | INIT_LIST_HEAD(&dmsk->dccpms_pending); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 772 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 773 | list_for_each_entry_safe(opt, next, &dmsk->dccpms_conf, dccpop_node) { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 774 | BUG_ON(opt == NULL); |
| 775 | if (opt->dccpop_val != NULL) |
| 776 | kfree(opt->dccpop_val); |
| 777 | kfree(opt); |
| 778 | } |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 779 | INIT_LIST_HEAD(&dmsk->dccpms_conf); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | EXPORT_SYMBOL_GPL(dccp_feat_clean); |
| 783 | |
| 784 | /* this is to be called only when a listening sock creates its child. It is |
| 785 | * assumed by the function---the confirm is not duplicated, but rather it is |
| 786 | * "passed on". |
| 787 | */ |
| 788 | int dccp_feat_clone(struct sock *oldsk, struct sock *newsk) |
| 789 | { |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 790 | struct dccp_minisock *olddmsk = dccp_msk(oldsk); |
| 791 | struct dccp_minisock *newdmsk = dccp_msk(newsk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 792 | struct dccp_opt_pend *opt; |
| 793 | int rc = 0; |
| 794 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 795 | INIT_LIST_HEAD(&newdmsk->dccpms_pending); |
| 796 | INIT_LIST_HEAD(&newdmsk->dccpms_conf); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 797 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 798 | list_for_each_entry(opt, &olddmsk->dccpms_pending, dccpop_node) { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 799 | struct dccp_opt_pend *newopt; |
| 800 | /* copy the value of the option */ |
Arnaldo Carvalho de Melo | eed7341 | 2006-11-17 12:21:43 -0200 | [diff] [blame] | 801 | u8 *val = kmemdup(opt->dccpop_val, opt->dccpop_len, GFP_ATOMIC); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 802 | |
| 803 | if (val == NULL) |
| 804 | goto out_clean; |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 805 | |
Arnaldo Carvalho de Melo | eed7341 | 2006-11-17 12:21:43 -0200 | [diff] [blame] | 806 | newopt = kmemdup(opt, sizeof(*newopt), GFP_ATOMIC); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 807 | if (newopt == NULL) { |
| 808 | kfree(val); |
| 809 | goto out_clean; |
| 810 | } |
| 811 | |
| 812 | /* insert the option */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 813 | newopt->dccpop_val = val; |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 814 | list_add_tail(&newopt->dccpop_node, &newdmsk->dccpms_pending); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 815 | |
| 816 | /* XXX what happens with backlogs and multiple connections at |
| 817 | * once... |
| 818 | */ |
| 819 | /* the master socket no longer needs to worry about confirms */ |
Randy Dunlap | 68907da | 2006-03-29 13:58:25 -0800 | [diff] [blame] | 820 | opt->dccpop_sc = NULL; /* it's not a memleak---new socket has it */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 821 | |
| 822 | /* reset state for a new socket */ |
| 823 | opt->dccpop_conf = 0; |
| 824 | } |
| 825 | |
| 826 | /* XXX not doing anything about the conf queue */ |
| 827 | |
| 828 | out: |
| 829 | return rc; |
| 830 | |
| 831 | out_clean: |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 832 | dccp_feat_clean(newdmsk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 833 | rc = -ENOMEM; |
| 834 | goto out; |
| 835 | } |
| 836 | |
| 837 | EXPORT_SYMBOL_GPL(dccp_feat_clone); |
| 838 | |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 839 | static int __dccp_feat_init(struct dccp_minisock *dmsk, u8 type, u8 feat, |
| 840 | u8 *val, u8 len) |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 841 | { |
| 842 | int rc = -ENOMEM; |
Arnaldo Carvalho de Melo | eed7341 | 2006-11-17 12:21:43 -0200 | [diff] [blame] | 843 | u8 *copy = kmemdup(val, len, GFP_KERNEL); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 844 | |
| 845 | if (copy != NULL) { |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 846 | rc = dccp_feat_change(dmsk, type, feat, copy, len, GFP_KERNEL); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 847 | if (rc) |
| 848 | kfree(copy); |
| 849 | } |
| 850 | return rc; |
| 851 | } |
| 852 | |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 853 | int dccp_feat_init(struct dccp_minisock *dmsk) |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 854 | { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 855 | int rc; |
| 856 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 857 | INIT_LIST_HEAD(&dmsk->dccpms_pending); |
| 858 | INIT_LIST_HEAD(&dmsk->dccpms_conf); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 859 | |
| 860 | /* CCID L */ |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 861 | rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_L, DCCPF_CCID, |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 862 | &dmsk->dccpms_tx_ccid, 1); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 863 | if (rc) |
| 864 | goto out; |
| 865 | |
| 866 | /* CCID R */ |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 867 | rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_R, DCCPF_CCID, |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 868 | &dmsk->dccpms_rx_ccid, 1); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 869 | if (rc) |
| 870 | goto out; |
| 871 | |
| 872 | /* Ack ratio */ |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 873 | rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_L, DCCPF_ACK_RATIO, |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 874 | &dmsk->dccpms_ack_ratio, 1); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 875 | out: |
| 876 | return rc; |
| 877 | } |
| 878 | |
| 879 | EXPORT_SYMBOL_GPL(dccp_feat_init); |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 880 | |
| 881 | #ifdef CONFIG_IP_DCCP_DEBUG |
| 882 | const char *dccp_feat_typename(const u8 type) |
| 883 | { |
| 884 | switch(type) { |
| 885 | case DCCPO_CHANGE_L: return("ChangeL"); |
| 886 | case DCCPO_CONFIRM_L: return("ConfirmL"); |
| 887 | case DCCPO_CHANGE_R: return("ChangeR"); |
| 888 | case DCCPO_CONFIRM_R: return("ConfirmR"); |
| 889 | /* the following case must not appear in feature negotation */ |
Arnaldo Carvalho de Melo | 8109b02 | 2006-12-10 16:01:18 -0200 | [diff] [blame] | 890 | default: dccp_pr_debug("unknown type %d [BUG!]\n", type); |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 891 | } |
| 892 | return NULL; |
| 893 | } |
| 894 | |
| 895 | EXPORT_SYMBOL_GPL(dccp_feat_typename); |
| 896 | |
| 897 | const char *dccp_feat_name(const u8 feat) |
| 898 | { |
| 899 | static const char *feature_names[] = { |
| 900 | [DCCPF_RESERVED] = "Reserved", |
| 901 | [DCCPF_CCID] = "CCID", |
| 902 | [DCCPF_SHORT_SEQNOS] = "Allow Short Seqnos", |
| 903 | [DCCPF_SEQUENCE_WINDOW] = "Sequence Window", |
| 904 | [DCCPF_ECN_INCAPABLE] = "ECN Incapable", |
| 905 | [DCCPF_ACK_RATIO] = "Ack Ratio", |
| 906 | [DCCPF_SEND_ACK_VECTOR] = "Send ACK Vector", |
| 907 | [DCCPF_SEND_NDP_COUNT] = "Send NDP Count", |
| 908 | [DCCPF_MIN_CSUM_COVER] = "Min. Csum Coverage", |
| 909 | [DCCPF_DATA_CHECKSUM] = "Send Data Checksum", |
| 910 | }; |
Gerrit Renker | dd6303d | 2007-12-13 12:40:40 -0200 | [diff] [blame] | 911 | if (feat > DCCPF_DATA_CHECKSUM && feat < DCCPF_MIN_CCID_SPECIFIC) |
| 912 | return feature_names[DCCPF_RESERVED]; |
| 913 | |
Gerrit Renker | b4eec20 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 914 | if (feat == DCCPF_SEND_LEV_RATE) |
| 915 | return "Send Loss Event Rate"; |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 916 | if (feat >= DCCPF_MIN_CCID_SPECIFIC) |
| 917 | return "CCID-specific"; |
| 918 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 919 | return feature_names[feat]; |
| 920 | } |
| 921 | |
| 922 | EXPORT_SYMBOL_GPL(dccp_feat_name); |
| 923 | #endif /* CONFIG_IP_DCCP_DEBUG */ |