]>
Commit | Line | Data |
---|---|---|
afe00251 AB |
1 | /* |
2 | * net/dccp/feat.c | |
3 | * | |
4 | * An implementation of the DCCP protocol | |
5 | * Andrea Bittau <a.bittau@cs.ucl.ac.uk> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU General Public License | |
9 | * as published by the Free Software Foundation; either version | |
10 | * 2 of the License, or (at your option) any later version. | |
11 | */ | |
12 | ||
afe00251 AB |
13 | #include <linux/module.h> |
14 | ||
6ffd30fb | 15 | #include "ccid.h" |
afe00251 AB |
16 | #include "feat.h" |
17 | ||
18 | #define DCCP_FEAT_SP_NOAGREE (-123) | |
19 | ||
8ca0d17b ACM |
20 | int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature, |
21 | u8 *val, u8 len, gfp_t gfp) | |
afe00251 | 22 | { |
afe00251 AB |
23 | struct dccp_opt_pend *opt; |
24 | ||
c02fdc0e | 25 | dccp_feat_debug(type, feature, *val); |
afe00251 | 26 | |
dd6303df | 27 | if (len > 3) { |
59348b19 | 28 | DCCP_WARN("invalid length %d\n", len); |
c02fdc0e GR |
29 | return 1; |
30 | } | |
31 | /* XXX add further sanity checks */ | |
6ffd30fb | 32 | |
afe00251 | 33 | /* check if that feature is already being negotiated */ |
a4bf3902 | 34 | list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { |
afe00251 AB |
35 | /* ok we found a negotiation for this option already */ |
36 | if (opt->dccpop_feat == feature && opt->dccpop_type == type) { | |
37 | dccp_pr_debug("Replacing old\n"); | |
38 | /* replace */ | |
39 | BUG_ON(opt->dccpop_val == NULL); | |
40 | kfree(opt->dccpop_val); | |
41 | opt->dccpop_val = val; | |
42 | opt->dccpop_len = len; | |
43 | opt->dccpop_conf = 0; | |
44 | return 0; | |
45 | } | |
46 | } | |
47 | ||
48 | /* negotiation for a new feature */ | |
49 | opt = kmalloc(sizeof(*opt), gfp); | |
50 | if (opt == NULL) | |
51 | return -ENOMEM; | |
52 | ||
53 | opt->dccpop_type = type; | |
54 | opt->dccpop_feat = feature; | |
55 | opt->dccpop_len = len; | |
56 | opt->dccpop_val = val; | |
57 | opt->dccpop_conf = 0; | |
58 | opt->dccpop_sc = NULL; | |
59 | ||
60 | BUG_ON(opt->dccpop_val == NULL); | |
61 | ||
a4bf3902 | 62 | list_add_tail(&opt->dccpop_node, &dmsk->dccpms_pending); |
afe00251 AB |
63 | return 0; |
64 | } | |
65 | ||
66 | EXPORT_SYMBOL_GPL(dccp_feat_change); | |
67 | ||
6ffd30fb AB |
68 | static int dccp_feat_update_ccid(struct sock *sk, u8 type, u8 new_ccid_nr) |
69 | { | |
70 | struct dccp_sock *dp = dccp_sk(sk); | |
a4bf3902 | 71 | struct dccp_minisock *dmsk = dccp_msk(sk); |
6ffd30fb AB |
72 | /* figure out if we are changing our CCID or the peer's */ |
73 | const int rx = type == DCCPO_CHANGE_R; | |
a4bf3902 | 74 | const u8 ccid_nr = rx ? dmsk->dccpms_rx_ccid : dmsk->dccpms_tx_ccid; |
6ffd30fb AB |
75 | struct ccid *new_ccid; |
76 | ||
77 | /* Check if nothing is being changed. */ | |
78 | if (ccid_nr == new_ccid_nr) | |
79 | return 0; | |
80 | ||
81 | new_ccid = ccid_new(new_ccid_nr, sk, rx, GFP_ATOMIC); | |
82 | if (new_ccid == NULL) | |
83 | return -ENOMEM; | |
84 | ||
85 | if (rx) { | |
86 | ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk); | |
87 | dp->dccps_hc_rx_ccid = new_ccid; | |
a4bf3902 | 88 | dmsk->dccpms_rx_ccid = new_ccid_nr; |
6ffd30fb AB |
89 | } else { |
90 | ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk); | |
91 | dp->dccps_hc_tx_ccid = new_ccid; | |
a4bf3902 | 92 | dmsk->dccpms_tx_ccid = new_ccid_nr; |
6ffd30fb AB |
93 | } |
94 | ||
95 | return 0; | |
96 | } | |
97 | ||
afe00251 AB |
98 | /* XXX taking only u8 vals */ |
99 | static int dccp_feat_update(struct sock *sk, u8 type, u8 feat, u8 val) | |
100 | { | |
c02fdc0e | 101 | dccp_feat_debug(type, feat, val); |
6ffd30fb AB |
102 | |
103 | switch (feat) { | |
104 | case DCCPF_CCID: | |
105 | return dccp_feat_update_ccid(sk, type, val); | |
106 | default: | |
c02fdc0e GR |
107 | dccp_pr_debug("UNIMPLEMENTED: %s(%d, ...)\n", |
108 | dccp_feat_typename(type), feat); | |
6ffd30fb AB |
109 | break; |
110 | } | |
afe00251 AB |
111 | return 0; |
112 | } | |
113 | ||
114 | static int dccp_feat_reconcile(struct sock *sk, struct dccp_opt_pend *opt, | |
115 | u8 *rpref, u8 rlen) | |
116 | { | |
117 | struct dccp_sock *dp = dccp_sk(sk); | |
118 | u8 *spref, slen, *res = NULL; | |
119 | int i, j, rc, agree = 1; | |
120 | ||
121 | BUG_ON(rpref == NULL); | |
122 | ||
123 | /* check if we are the black sheep */ | |
124 | if (dp->dccps_role == DCCP_ROLE_CLIENT) { | |
125 | spref = rpref; | |
126 | slen = rlen; | |
127 | rpref = opt->dccpop_val; | |
128 | rlen = opt->dccpop_len; | |
129 | } else { | |
130 | spref = opt->dccpop_val; | |
131 | slen = opt->dccpop_len; | |
132 | } | |
133 | /* | |
134 | * Now we have server preference list in spref and client preference in | |
135 | * rpref | |
136 | */ | |
137 | BUG_ON(spref == NULL); | |
138 | BUG_ON(rpref == NULL); | |
139 | ||
140 | /* FIXME sanity check vals */ | |
141 | ||
142 | /* Are values in any order? XXX Lame "algorithm" here */ | |
143 | /* XXX assume values are 1 byte */ | |
144 | for (i = 0; i < slen; i++) { | |
145 | for (j = 0; j < rlen; j++) { | |
146 | if (spref[i] == rpref[j]) { | |
147 | res = &spref[i]; | |
148 | break; | |
149 | } | |
150 | } | |
151 | if (res) | |
152 | break; | |
153 | } | |
154 | ||
155 | /* we didn't agree on anything */ | |
156 | if (res == NULL) { | |
157 | /* confirm previous value */ | |
158 | switch (opt->dccpop_feat) { | |
159 | case DCCPF_CCID: | |
160 | /* XXX did i get this right? =P */ | |
161 | if (opt->dccpop_type == DCCPO_CHANGE_L) | |
a4bf3902 | 162 | res = &dccp_msk(sk)->dccpms_tx_ccid; |
afe00251 | 163 | else |
a4bf3902 | 164 | res = &dccp_msk(sk)->dccpms_rx_ccid; |
afe00251 AB |
165 | break; |
166 | ||
167 | default: | |
59348b19 GR |
168 | DCCP_BUG("Fell through, feat=%d", opt->dccpop_feat); |
169 | /* XXX implement res */ | |
afe00251 AB |
170 | return -EFAULT; |
171 | } | |
172 | ||
173 | dccp_pr_debug("Don't agree... reconfirming %d\n", *res); | |
174 | agree = 0; /* this is used for mandatory options... */ | |
175 | } | |
176 | ||
177 | /* need to put result and our preference list */ | |
178 | /* XXX assume 1 byte vals */ | |
179 | rlen = 1 + opt->dccpop_len; | |
180 | rpref = kmalloc(rlen, GFP_ATOMIC); | |
181 | if (rpref == NULL) | |
182 | return -ENOMEM; | |
183 | ||
184 | *rpref = *res; | |
185 | memcpy(&rpref[1], opt->dccpop_val, opt->dccpop_len); | |
186 | ||
187 | /* put it in the "confirm queue" */ | |
188 | if (opt->dccpop_sc == NULL) { | |
189 | opt->dccpop_sc = kmalloc(sizeof(*opt->dccpop_sc), GFP_ATOMIC); | |
190 | if (opt->dccpop_sc == NULL) { | |
191 | kfree(rpref); | |
192 | return -ENOMEM; | |
193 | } | |
194 | } else { | |
195 | /* recycle the confirm slot */ | |
196 | BUG_ON(opt->dccpop_sc->dccpoc_val == NULL); | |
197 | kfree(opt->dccpop_sc->dccpoc_val); | |
198 | dccp_pr_debug("recycling confirm slot\n"); | |
199 | } | |
200 | memset(opt->dccpop_sc, 0, sizeof(*opt->dccpop_sc)); | |
201 | ||
202 | opt->dccpop_sc->dccpoc_val = rpref; | |
203 | opt->dccpop_sc->dccpoc_len = rlen; | |
204 | ||
205 | /* update the option on our side [we are about to send the confirm] */ | |
206 | rc = dccp_feat_update(sk, opt->dccpop_type, opt->dccpop_feat, *res); | |
207 | if (rc) { | |
208 | kfree(opt->dccpop_sc->dccpoc_val); | |
209 | kfree(opt->dccpop_sc); | |
68907dad | 210 | opt->dccpop_sc = NULL; |
afe00251 AB |
211 | return rc; |
212 | } | |
213 | ||
214 | dccp_pr_debug("Will confirm %d\n", *rpref); | |
215 | ||
216 | /* say we want to change to X but we just got a confirm X, suppress our | |
217 | * change | |
218 | */ | |
219 | if (!opt->dccpop_conf) { | |
220 | if (*opt->dccpop_val == *res) | |
221 | opt->dccpop_conf = 1; | |
222 | dccp_pr_debug("won't ask for change of same feature\n"); | |
223 | } | |
224 | ||
225 | return agree ? 0 : DCCP_FEAT_SP_NOAGREE; /* used for mandatory opts */ | |
226 | } | |
227 | ||
228 | static int dccp_feat_sp(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len) | |
229 | { | |
a4bf3902 | 230 | struct dccp_minisock *dmsk = dccp_msk(sk); |
afe00251 AB |
231 | struct dccp_opt_pend *opt; |
232 | int rc = 1; | |
233 | u8 t; | |
234 | ||
235 | /* | |
236 | * We received a CHANGE. We gotta match it against our own preference | |
237 | * list. If we got a CHANGE_R it means it's a change for us, so we need | |
238 | * to compare our CHANGE_L list. | |
239 | */ | |
240 | if (type == DCCPO_CHANGE_L) | |
241 | t = DCCPO_CHANGE_R; | |
242 | else | |
243 | t = DCCPO_CHANGE_L; | |
244 | ||
245 | /* find our preference list for this feature */ | |
a4bf3902 | 246 | list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { |
afe00251 AB |
247 | if (opt->dccpop_type != t || opt->dccpop_feat != feature) |
248 | continue; | |
249 | ||
250 | /* find the winner from the two preference lists */ | |
251 | rc = dccp_feat_reconcile(sk, opt, val, len); | |
252 | break; | |
253 | } | |
254 | ||
255 | /* We didn't deal with the change. This can happen if we have no | |
256 | * preference list for the feature. In fact, it just shouldn't | |
257 | * happen---if we understand a feature, we should have a preference list | |
258 | * with at least the default value. | |
259 | */ | |
260 | BUG_ON(rc == 1); | |
261 | ||
262 | return rc; | |
263 | } | |
264 | ||
265 | static int dccp_feat_nn(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len) | |
266 | { | |
267 | struct dccp_opt_pend *opt; | |
a4bf3902 | 268 | struct dccp_minisock *dmsk = dccp_msk(sk); |
afe00251 AB |
269 | u8 *copy; |
270 | int rc; | |
271 | ||
c02fdc0e GR |
272 | /* NN features must be Change L (sec. 6.3.2) */ |
273 | if (type != DCCPO_CHANGE_L) { | |
274 | dccp_pr_debug("received %s for NN feature %d\n", | |
275 | dccp_feat_typename(type), feature); | |
afe00251 AB |
276 | return -EFAULT; |
277 | } | |
278 | ||
279 | /* XXX sanity check opt val */ | |
280 | ||
281 | /* copy option so we can confirm it */ | |
282 | opt = kzalloc(sizeof(*opt), GFP_ATOMIC); | |
283 | if (opt == NULL) | |
284 | return -ENOMEM; | |
285 | ||
eed73417 | 286 | copy = kmemdup(val, len, GFP_ATOMIC); |
afe00251 AB |
287 | if (copy == NULL) { |
288 | kfree(opt); | |
289 | return -ENOMEM; | |
290 | } | |
afe00251 AB |
291 | |
292 | opt->dccpop_type = DCCPO_CONFIRM_R; /* NN can only confirm R */ | |
293 | opt->dccpop_feat = feature; | |
294 | opt->dccpop_val = copy; | |
295 | opt->dccpop_len = len; | |
296 | ||
297 | /* change feature */ | |
298 | rc = dccp_feat_update(sk, type, feature, *val); | |
299 | if (rc) { | |
300 | kfree(opt->dccpop_val); | |
301 | kfree(opt); | |
302 | return rc; | |
303 | } | |
304 | ||
c02fdc0e GR |
305 | dccp_feat_debug(type, feature, *copy); |
306 | ||
a4bf3902 | 307 | list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf); |
afe00251 AB |
308 | |
309 | return 0; | |
310 | } | |
311 | ||
8ca0d17b ACM |
312 | static void dccp_feat_empty_confirm(struct dccp_minisock *dmsk, |
313 | u8 type, u8 feature) | |
afe00251 | 314 | { |
afe00251 AB |
315 | /* XXX check if other confirms for that are queued and recycle slot */ |
316 | struct dccp_opt_pend *opt = kzalloc(sizeof(*opt), GFP_ATOMIC); | |
317 | ||
318 | if (opt == NULL) { | |
319 | /* XXX what do we do? Ignoring should be fine. It's a change | |
320 | * after all =P | |
321 | */ | |
322 | return; | |
323 | } | |
324 | ||
c02fdc0e | 325 | switch (type) { |
e576de82 JJ |
326 | case DCCPO_CHANGE_L: |
327 | opt->dccpop_type = DCCPO_CONFIRM_R; | |
328 | break; | |
329 | case DCCPO_CHANGE_R: | |
330 | opt->dccpop_type = DCCPO_CONFIRM_L; | |
331 | break; | |
332 | default: | |
333 | DCCP_WARN("invalid type %d\n", type); | |
334 | kfree(opt); | |
335 | return; | |
c02fdc0e | 336 | } |
afe00251 | 337 | opt->dccpop_feat = feature; |
68907dad | 338 | opt->dccpop_val = NULL; |
afe00251 AB |
339 | opt->dccpop_len = 0; |
340 | ||
341 | /* change feature */ | |
c02fdc0e GR |
342 | dccp_pr_debug("Empty %s(%d)\n", dccp_feat_typename(type), feature); |
343 | ||
a4bf3902 | 344 | list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf); |
afe00251 AB |
345 | } |
346 | ||
347 | static void dccp_feat_flush_confirm(struct sock *sk) | |
348 | { | |
a4bf3902 | 349 | struct dccp_minisock *dmsk = dccp_msk(sk); |
afe00251 | 350 | /* Check if there is anything to confirm in the first place */ |
a4bf3902 | 351 | int yes = !list_empty(&dmsk->dccpms_conf); |
afe00251 AB |
352 | |
353 | if (!yes) { | |
354 | struct dccp_opt_pend *opt; | |
355 | ||
a4bf3902 | 356 | list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { |
afe00251 AB |
357 | if (opt->dccpop_conf) { |
358 | yes = 1; | |
359 | break; | |
360 | } | |
361 | } | |
362 | } | |
363 | ||
364 | if (!yes) | |
365 | return; | |
366 | ||
367 | /* OK there is something to confirm... */ | |
368 | /* XXX check if packet is in flight? Send delayed ack?? */ | |
369 | if (sk->sk_state == DCCP_OPEN) | |
370 | dccp_send_ack(sk); | |
371 | } | |
372 | ||
373 | int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len) | |
374 | { | |
375 | int rc; | |
376 | ||
c02fdc0e | 377 | dccp_feat_debug(type, feature, *val); |
afe00251 AB |
378 | |
379 | /* figure out if it's SP or NN feature */ | |
380 | switch (feature) { | |
381 | /* deal with SP features */ | |
382 | case DCCPF_CCID: | |
383 | rc = dccp_feat_sp(sk, type, feature, val, len); | |
384 | break; | |
385 | ||
386 | /* deal with NN features */ | |
387 | case DCCPF_ACK_RATIO: | |
388 | rc = dccp_feat_nn(sk, type, feature, val, len); | |
389 | break; | |
390 | ||
391 | /* XXX implement other features */ | |
392 | default: | |
c02fdc0e GR |
393 | dccp_pr_debug("UNIMPLEMENTED: not handling %s(%d, ...)\n", |
394 | dccp_feat_typename(type), feature); | |
afe00251 AB |
395 | rc = -EFAULT; |
396 | break; | |
397 | } | |
398 | ||
399 | /* check if there were problems changing features */ | |
400 | if (rc) { | |
401 | /* If we don't agree on SP, we sent a confirm for old value. | |
402 | * However we propagate rc to caller in case option was | |
403 | * mandatory | |
404 | */ | |
405 | if (rc != DCCP_FEAT_SP_NOAGREE) | |
8ca0d17b | 406 | dccp_feat_empty_confirm(dccp_msk(sk), type, feature); |
afe00251 AB |
407 | } |
408 | ||
409 | /* generate the confirm [if required] */ | |
410 | dccp_feat_flush_confirm(sk); | |
411 | ||
412 | return rc; | |
413 | } | |
414 | ||
415 | EXPORT_SYMBOL_GPL(dccp_feat_change_recv); | |
416 | ||
417 | int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature, | |
418 | u8 *val, u8 len) | |
419 | { | |
420 | u8 t; | |
421 | struct dccp_opt_pend *opt; | |
a4bf3902 | 422 | struct dccp_minisock *dmsk = dccp_msk(sk); |
c02fdc0e | 423 | int found = 0; |
afe00251 AB |
424 | int all_confirmed = 1; |
425 | ||
c02fdc0e | 426 | dccp_feat_debug(type, feature, *val); |
afe00251 AB |
427 | |
428 | /* locate our change request */ | |
c02fdc0e GR |
429 | switch (type) { |
430 | case DCCPO_CONFIRM_L: t = DCCPO_CHANGE_R; break; | |
431 | case DCCPO_CONFIRM_R: t = DCCPO_CHANGE_L; break; | |
8109b02b | 432 | default: DCCP_WARN("invalid type %d\n", type); |
c02fdc0e GR |
433 | return 1; |
434 | ||
435 | } | |
436 | /* XXX sanity check feature value */ | |
afe00251 | 437 | |
a4bf3902 | 438 | list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { |
afe00251 AB |
439 | if (!opt->dccpop_conf && opt->dccpop_type == t && |
440 | opt->dccpop_feat == feature) { | |
c02fdc0e GR |
441 | found = 1; |
442 | dccp_pr_debug("feature %d found\n", opt->dccpop_feat); | |
443 | ||
afe00251 AB |
444 | /* XXX do sanity check */ |
445 | ||
446 | opt->dccpop_conf = 1; | |
447 | ||
448 | /* We got a confirmation---change the option */ | |
449 | dccp_feat_update(sk, opt->dccpop_type, | |
450 | opt->dccpop_feat, *val); | |
451 | ||
c02fdc0e | 452 | /* XXX check the return value of dccp_feat_update */ |
afe00251 AB |
453 | break; |
454 | } | |
455 | ||
456 | if (!opt->dccpop_conf) | |
457 | all_confirmed = 0; | |
458 | } | |
459 | ||
460 | /* fix re-transmit timer */ | |
461 | /* XXX gotta make sure that no option negotiation occurs during | |
462 | * connection shutdown. Consider that the CLOSEREQ is sent and timer is | |
463 | * on. if all options are confirmed it might kill timer which should | |
464 | * remain alive until close is received. | |
465 | */ | |
466 | if (all_confirmed) { | |
467 | dccp_pr_debug("clear feat negotiation timer %p\n", sk); | |
468 | inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS); | |
469 | } | |
470 | ||
c02fdc0e GR |
471 | if (!found) |
472 | dccp_pr_debug("%s(%d, ...) never requested\n", | |
473 | dccp_feat_typename(type), feature); | |
afe00251 AB |
474 | return 0; |
475 | } | |
476 | ||
477 | EXPORT_SYMBOL_GPL(dccp_feat_confirm_recv); | |
478 | ||
8ca0d17b | 479 | void dccp_feat_clean(struct dccp_minisock *dmsk) |
afe00251 | 480 | { |
afe00251 AB |
481 | struct dccp_opt_pend *opt, *next; |
482 | ||
a4bf3902 | 483 | list_for_each_entry_safe(opt, next, &dmsk->dccpms_pending, |
afe00251 | 484 | dccpop_node) { |
c9eaf173 YH |
485 | BUG_ON(opt->dccpop_val == NULL); |
486 | kfree(opt->dccpop_val); | |
afe00251 AB |
487 | |
488 | if (opt->dccpop_sc != NULL) { | |
489 | BUG_ON(opt->dccpop_sc->dccpoc_val == NULL); | |
490 | kfree(opt->dccpop_sc->dccpoc_val); | |
491 | kfree(opt->dccpop_sc); | |
492 | } | |
493 | ||
c9eaf173 YH |
494 | kfree(opt); |
495 | } | |
a4bf3902 | 496 | INIT_LIST_HEAD(&dmsk->dccpms_pending); |
afe00251 | 497 | |
a4bf3902 | 498 | list_for_each_entry_safe(opt, next, &dmsk->dccpms_conf, dccpop_node) { |
afe00251 AB |
499 | BUG_ON(opt == NULL); |
500 | if (opt->dccpop_val != NULL) | |
501 | kfree(opt->dccpop_val); | |
502 | kfree(opt); | |
503 | } | |
a4bf3902 | 504 | INIT_LIST_HEAD(&dmsk->dccpms_conf); |
afe00251 AB |
505 | } |
506 | ||
507 | EXPORT_SYMBOL_GPL(dccp_feat_clean); | |
508 | ||
509 | /* this is to be called only when a listening sock creates its child. It is | |
510 | * assumed by the function---the confirm is not duplicated, but rather it is | |
511 | * "passed on". | |
512 | */ | |
513 | int dccp_feat_clone(struct sock *oldsk, struct sock *newsk) | |
514 | { | |
a4bf3902 ACM |
515 | struct dccp_minisock *olddmsk = dccp_msk(oldsk); |
516 | struct dccp_minisock *newdmsk = dccp_msk(newsk); | |
afe00251 AB |
517 | struct dccp_opt_pend *opt; |
518 | int rc = 0; | |
519 | ||
a4bf3902 ACM |
520 | INIT_LIST_HEAD(&newdmsk->dccpms_pending); |
521 | INIT_LIST_HEAD(&newdmsk->dccpms_conf); | |
afe00251 | 522 | |
a4bf3902 | 523 | list_for_each_entry(opt, &olddmsk->dccpms_pending, dccpop_node) { |
afe00251 AB |
524 | struct dccp_opt_pend *newopt; |
525 | /* copy the value of the option */ | |
eed73417 | 526 | u8 *val = kmemdup(opt->dccpop_val, opt->dccpop_len, GFP_ATOMIC); |
afe00251 AB |
527 | |
528 | if (val == NULL) | |
529 | goto out_clean; | |
afe00251 | 530 | |
eed73417 | 531 | newopt = kmemdup(opt, sizeof(*newopt), GFP_ATOMIC); |
afe00251 AB |
532 | if (newopt == NULL) { |
533 | kfree(val); | |
534 | goto out_clean; | |
535 | } | |
536 | ||
537 | /* insert the option */ | |
afe00251 | 538 | newopt->dccpop_val = val; |
a4bf3902 | 539 | list_add_tail(&newopt->dccpop_node, &newdmsk->dccpms_pending); |
afe00251 AB |
540 | |
541 | /* XXX what happens with backlogs and multiple connections at | |
542 | * once... | |
543 | */ | |
544 | /* the master socket no longer needs to worry about confirms */ | |
68907dad | 545 | opt->dccpop_sc = NULL; /* it's not a memleak---new socket has it */ |
afe00251 AB |
546 | |
547 | /* reset state for a new socket */ | |
548 | opt->dccpop_conf = 0; | |
549 | } | |
550 | ||
551 | /* XXX not doing anything about the conf queue */ | |
552 | ||
553 | out: | |
554 | return rc; | |
555 | ||
556 | out_clean: | |
8ca0d17b | 557 | dccp_feat_clean(newdmsk); |
afe00251 AB |
558 | rc = -ENOMEM; |
559 | goto out; | |
560 | } | |
561 | ||
562 | EXPORT_SYMBOL_GPL(dccp_feat_clone); | |
563 | ||
8ca0d17b ACM |
564 | static int __dccp_feat_init(struct dccp_minisock *dmsk, u8 type, u8 feat, |
565 | u8 *val, u8 len) | |
afe00251 AB |
566 | { |
567 | int rc = -ENOMEM; | |
eed73417 | 568 | u8 *copy = kmemdup(val, len, GFP_KERNEL); |
afe00251 AB |
569 | |
570 | if (copy != NULL) { | |
8ca0d17b | 571 | rc = dccp_feat_change(dmsk, type, feat, copy, len, GFP_KERNEL); |
afe00251 AB |
572 | if (rc) |
573 | kfree(copy); | |
574 | } | |
575 | return rc; | |
576 | } | |
577 | ||
8ca0d17b | 578 | int dccp_feat_init(struct dccp_minisock *dmsk) |
afe00251 | 579 | { |
afe00251 AB |
580 | int rc; |
581 | ||
a4bf3902 ACM |
582 | INIT_LIST_HEAD(&dmsk->dccpms_pending); |
583 | INIT_LIST_HEAD(&dmsk->dccpms_conf); | |
afe00251 AB |
584 | |
585 | /* CCID L */ | |
8ca0d17b | 586 | rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_L, DCCPF_CCID, |
a4bf3902 | 587 | &dmsk->dccpms_tx_ccid, 1); |
afe00251 AB |
588 | if (rc) |
589 | goto out; | |
590 | ||
591 | /* CCID R */ | |
8ca0d17b | 592 | rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_R, DCCPF_CCID, |
a4bf3902 | 593 | &dmsk->dccpms_rx_ccid, 1); |
afe00251 AB |
594 | if (rc) |
595 | goto out; | |
596 | ||
597 | /* Ack ratio */ | |
8ca0d17b | 598 | rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_L, DCCPF_ACK_RATIO, |
a4bf3902 | 599 | &dmsk->dccpms_ack_ratio, 1); |
afe00251 AB |
600 | out: |
601 | return rc; | |
602 | } | |
603 | ||
604 | EXPORT_SYMBOL_GPL(dccp_feat_init); | |
c02fdc0e GR |
605 | |
606 | #ifdef CONFIG_IP_DCCP_DEBUG | |
607 | const char *dccp_feat_typename(const u8 type) | |
608 | { | |
609 | switch(type) { | |
610 | case DCCPO_CHANGE_L: return("ChangeL"); | |
611 | case DCCPO_CONFIRM_L: return("ConfirmL"); | |
612 | case DCCPO_CHANGE_R: return("ChangeR"); | |
613 | case DCCPO_CONFIRM_R: return("ConfirmR"); | |
614 | /* the following case must not appear in feature negotation */ | |
8109b02b | 615 | default: dccp_pr_debug("unknown type %d [BUG!]\n", type); |
c02fdc0e GR |
616 | } |
617 | return NULL; | |
618 | } | |
619 | ||
620 | EXPORT_SYMBOL_GPL(dccp_feat_typename); | |
621 | ||
622 | const char *dccp_feat_name(const u8 feat) | |
623 | { | |
624 | static const char *feature_names[] = { | |
625 | [DCCPF_RESERVED] = "Reserved", | |
626 | [DCCPF_CCID] = "CCID", | |
627 | [DCCPF_SHORT_SEQNOS] = "Allow Short Seqnos", | |
628 | [DCCPF_SEQUENCE_WINDOW] = "Sequence Window", | |
629 | [DCCPF_ECN_INCAPABLE] = "ECN Incapable", | |
630 | [DCCPF_ACK_RATIO] = "Ack Ratio", | |
631 | [DCCPF_SEND_ACK_VECTOR] = "Send ACK Vector", | |
632 | [DCCPF_SEND_NDP_COUNT] = "Send NDP Count", | |
633 | [DCCPF_MIN_CSUM_COVER] = "Min. Csum Coverage", | |
634 | [DCCPF_DATA_CHECKSUM] = "Send Data Checksum", | |
635 | }; | |
dd6303df GR |
636 | if (feat > DCCPF_DATA_CHECKSUM && feat < DCCPF_MIN_CCID_SPECIFIC) |
637 | return feature_names[DCCPF_RESERVED]; | |
638 | ||
c02fdc0e GR |
639 | if (feat >= DCCPF_MIN_CCID_SPECIFIC) |
640 | return "CCID-specific"; | |
641 | ||
c02fdc0e GR |
642 | return feature_names[feat]; |
643 | } | |
644 | ||
645 | EXPORT_SYMBOL_GPL(dccp_feat_name); | |
646 | #endif /* CONFIG_IP_DCCP_DEBUG */ |