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