4 * An implementation of the DCCP protocol
5 * Andrea Bittau <a.bittau@cs.ucl.ac.uk>
9 * o All currently known SP features have 1-byte quantities. If in the future
10 * extensions of RFCs 4340..42 define features with item lengths larger than
11 * one byte, a feature-specific extension of the code will be required.
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
19 #include <linux/module.h>
24 #define DCCP_FEAT_SP_NOAGREE (-123)
27 u8 feat_num
; /* DCCPF_xxx */
28 enum dccp_feat_type rxtx
; /* RX or TX */
29 enum dccp_feat_type reconciliation
; /* SP or NN */
30 u8 default_value
; /* as in 6.4 */
32 * Lookup table for location and type of features (from RFC 4340/4342)
33 * +--------------------------+----+-----+----+----+---------+-----------+
34 * | Feature | Location | Reconc. | Initial | Section |
35 * | | RX | TX | SP | NN | Value | Reference |
36 * +--------------------------+----+-----+----+----+---------+-----------+
37 * | DCCPF_CCID | | X | X | | 2 | 10 |
38 * | DCCPF_SHORT_SEQNOS | | X | X | | 0 | 7.6.1 |
39 * | DCCPF_SEQUENCE_WINDOW | | X | | X | 100 | 7.5.2 |
40 * | DCCPF_ECN_INCAPABLE | X | | X | | 0 | 12.1 |
41 * | DCCPF_ACK_RATIO | | X | | X | 2 | 11.3 |
42 * | DCCPF_SEND_ACK_VECTOR | X | | X | | 0 | 11.5 |
43 * | DCCPF_SEND_NDP_COUNT | | X | X | | 0 | 7.7.2 |
44 * | DCCPF_MIN_CSUM_COVER | X | | X | | 0 | 9.2.1 |
45 * | DCCPF_DATA_CHECKSUM | X | | X | | 0 | 9.3.1 |
46 * | DCCPF_SEND_LEV_RATE | X | | X | | 0 | 4342/8.4 |
47 * +--------------------------+----+-----+----+----+---------+-----------+
49 } dccp_feat_table
[] = {
50 { DCCPF_CCID
, FEAT_AT_TX
, FEAT_SP
, 2 },
51 { DCCPF_SHORT_SEQNOS
, FEAT_AT_TX
, FEAT_SP
, 0 },
52 { DCCPF_SEQUENCE_WINDOW
, FEAT_AT_TX
, FEAT_NN
, 100 },
53 { DCCPF_ECN_INCAPABLE
, FEAT_AT_RX
, FEAT_SP
, 0 },
54 { DCCPF_ACK_RATIO
, FEAT_AT_TX
, FEAT_NN
, 2 },
55 { DCCPF_SEND_ACK_VECTOR
, FEAT_AT_RX
, FEAT_SP
, 0 },
56 { DCCPF_SEND_NDP_COUNT
, FEAT_AT_TX
, FEAT_SP
, 0 },
57 { DCCPF_MIN_CSUM_COVER
, FEAT_AT_RX
, FEAT_SP
, 0 },
58 { DCCPF_DATA_CHECKSUM
, FEAT_AT_RX
, FEAT_SP
, 0 },
59 { DCCPF_SEND_LEV_RATE
, FEAT_AT_RX
, FEAT_SP
, 0 },
61 #define DCCP_FEAT_SUPPORTED_MAX ARRAY_SIZE(dccp_feat_table)
64 * dccp_feat_index - Hash function to map feature number into array position
65 * Returns consecutive array index or -1 if the feature is not understood.
67 static int dccp_feat_index(u8 feat_num
)
69 /* The first 9 entries are occupied by the types from RFC 4340, 6.4 */
70 if (feat_num
> DCCPF_RESERVED
&& feat_num
<= DCCPF_DATA_CHECKSUM
)
74 * Other features: add cases for new feature types here after adding
75 * them to the above table.
78 case DCCPF_SEND_LEV_RATE
:
79 return DCCP_FEAT_SUPPORTED_MAX
- 1;
84 static u8
dccp_feat_type(u8 feat_num
)
86 int idx
= dccp_feat_index(feat_num
);
90 return dccp_feat_table
[idx
].reconciliation
;
93 static int dccp_feat_default_value(u8 feat_num
)
95 int idx
= dccp_feat_index(feat_num
);
97 return idx
< 0 ? : dccp_feat_table
[idx
].default_value
;
100 /* copy constructor, fval must not already contain allocated memory */
101 static int dccp_feat_clone_sp_val(dccp_feat_val
*fval
, u8
const *val
, u8 len
)
104 if (fval
->sp
.len
> 0) {
105 fval
->sp
.vec
= kmemdup(val
, len
, gfp_any());
106 if (fval
->sp
.vec
== NULL
) {
114 static void dccp_feat_val_destructor(u8 feat_num
, dccp_feat_val
*val
)
116 if (unlikely(val
== NULL
))
118 if (dccp_feat_type(feat_num
) == FEAT_SP
)
120 memset(val
, 0, sizeof(*val
));
123 static struct dccp_feat_entry
*
124 dccp_feat_clone_entry(struct dccp_feat_entry
const *original
)
126 struct dccp_feat_entry
*new;
127 u8 type
= dccp_feat_type(original
->feat_num
);
129 if (type
== FEAT_UNKNOWN
)
132 new = kmemdup(original
, sizeof(struct dccp_feat_entry
), gfp_any());
136 if (type
== FEAT_SP
&& dccp_feat_clone_sp_val(&new->val
,
137 original
->val
.sp
.vec
,
138 original
->val
.sp
.len
)) {
145 static void dccp_feat_entry_destructor(struct dccp_feat_entry
*entry
)
148 dccp_feat_val_destructor(entry
->feat_num
, &entry
->val
);
154 * List management functions
156 * Feature negotiation lists rely on and maintain the following invariants:
157 * - each feat_num in the list is known, i.e. we know its type and default value
158 * - each feat_num/is_local combination is unique (old entries are overwritten)
159 * - SP values are always freshly allocated
160 * - list is sorted in increasing order of feature number (faster lookup)
162 static struct dccp_feat_entry
*dccp_feat_list_lookup(struct list_head
*fn_list
,
163 u8 feat_num
, bool is_local
)
165 struct dccp_feat_entry
*entry
;
167 list_for_each_entry(entry
, fn_list
, node
)
168 if (entry
->feat_num
== feat_num
&& entry
->is_local
== is_local
)
170 else if (entry
->feat_num
> feat_num
)
176 * dccp_feat_entry_new - Central list update routine (called by all others)
177 * @head: list to add to
178 * @feat: feature number
179 * @local: whether the local (1) or remote feature with number @feat is meant
180 * This is the only constructor and serves to ensure the above invariants.
182 static struct dccp_feat_entry
*
183 dccp_feat_entry_new(struct list_head
*head
, u8 feat
, bool local
)
185 struct dccp_feat_entry
*entry
;
187 list_for_each_entry(entry
, head
, node
)
188 if (entry
->feat_num
== feat
&& entry
->is_local
== local
) {
189 dccp_feat_val_destructor(entry
->feat_num
, &entry
->val
);
191 } else if (entry
->feat_num
> feat
) {
196 entry
= kmalloc(sizeof(*entry
), gfp_any());
198 entry
->feat_num
= feat
;
199 entry
->is_local
= local
;
200 list_add_tail(&entry
->node
, head
);
206 * dccp_feat_push_change - Add/overwrite a Change option in the list
207 * @fn_list: feature-negotiation list to update
208 * @feat: one of %dccp_feature_numbers
209 * @local: whether local (1) or remote (0) @feat_num is meant
210 * @needs_mandatory: whether to use Mandatory feature negotiation options
211 * @fval: pointer to NN/SP value to be inserted (will be copied)
213 static int dccp_feat_push_change(struct list_head
*fn_list
, u8 feat
, u8 local
,
214 u8 mandatory
, dccp_feat_val
*fval
)
216 struct dccp_feat_entry
*new = dccp_feat_entry_new(fn_list
, feat
, local
);
221 new->feat_num
= feat
;
222 new->is_local
= local
;
223 new->state
= FEAT_INITIALISING
;
224 new->needs_confirm
= 0;
225 new->empty_confirm
= 0;
227 new->needs_mandatory
= mandatory
;
233 * dccp_feat_push_confirm - Add a Confirm entry to the FN list
234 * @fn_list: feature-negotiation list to add to
235 * @feat: one of %dccp_feature_numbers
236 * @local: whether local (1) or remote (0) @feat_num is being confirmed
237 * @fval: pointer to NN/SP value to be inserted or NULL
238 * Returns 0 on success, a Reset code for further processing otherwise.
240 static int dccp_feat_push_confirm(struct list_head
*fn_list
, u8 feat
, u8 local
,
243 struct dccp_feat_entry
*new = dccp_feat_entry_new(fn_list
, feat
, local
);
246 return DCCP_RESET_CODE_TOO_BUSY
;
248 new->feat_num
= feat
;
249 new->is_local
= local
;
250 new->state
= FEAT_STABLE
; /* transition in 6.6.2 */
251 new->needs_confirm
= 1;
252 new->empty_confirm
= (fval
== NULL
);
253 new->val
.nn
= 0; /* zeroes the whole structure */
254 if (!new->empty_confirm
)
256 new->needs_mandatory
= 0;
261 static int dccp_push_empty_confirm(struct list_head
*fn_list
, u8 feat
, u8 local
)
263 return dccp_feat_push_confirm(fn_list
, feat
, local
, NULL
);
266 static inline void dccp_feat_list_pop(struct dccp_feat_entry
*entry
)
268 list_del(&entry
->node
);
269 dccp_feat_entry_destructor(entry
);
272 void dccp_feat_list_purge(struct list_head
*fn_list
)
274 struct dccp_feat_entry
*entry
, *next
;
276 list_for_each_entry_safe(entry
, next
, fn_list
, node
)
277 dccp_feat_entry_destructor(entry
);
278 INIT_LIST_HEAD(fn_list
);
280 EXPORT_SYMBOL_GPL(dccp_feat_list_purge
);
282 int dccp_feat_change(struct dccp_minisock
*dmsk
, u8 type
, u8 feature
,
283 u8
*val
, u8 len
, gfp_t gfp
)
285 struct dccp_opt_pend
*opt
;
287 dccp_feat_debug(type
, feature
, *val
);
290 DCCP_WARN("invalid length %d\n", len
);
293 /* XXX add further sanity checks */
295 /* check if that feature is already being negotiated */
296 list_for_each_entry(opt
, &dmsk
->dccpms_pending
, dccpop_node
) {
297 /* ok we found a negotiation for this option already */
298 if (opt
->dccpop_feat
== feature
&& opt
->dccpop_type
== type
) {
299 dccp_pr_debug("Replacing old\n");
301 BUG_ON(opt
->dccpop_val
== NULL
);
302 kfree(opt
->dccpop_val
);
303 opt
->dccpop_val
= val
;
304 opt
->dccpop_len
= len
;
305 opt
->dccpop_conf
= 0;
310 /* negotiation for a new feature */
311 opt
= kmalloc(sizeof(*opt
), gfp
);
315 opt
->dccpop_type
= type
;
316 opt
->dccpop_feat
= feature
;
317 opt
->dccpop_len
= len
;
318 opt
->dccpop_val
= val
;
319 opt
->dccpop_conf
= 0;
320 opt
->dccpop_sc
= NULL
;
322 BUG_ON(opt
->dccpop_val
== NULL
);
324 list_add_tail(&opt
->dccpop_node
, &dmsk
->dccpms_pending
);
328 EXPORT_SYMBOL_GPL(dccp_feat_change
);
330 static int dccp_feat_update_ccid(struct sock
*sk
, u8 type
, u8 new_ccid_nr
)
332 struct dccp_sock
*dp
= dccp_sk(sk
);
333 struct dccp_minisock
*dmsk
= dccp_msk(sk
);
334 /* figure out if we are changing our CCID or the peer's */
335 const int rx
= type
== DCCPO_CHANGE_R
;
336 const u8 ccid_nr
= rx
? dmsk
->dccpms_rx_ccid
: dmsk
->dccpms_tx_ccid
;
337 struct ccid
*new_ccid
;
339 /* Check if nothing is being changed. */
340 if (ccid_nr
== new_ccid_nr
)
343 new_ccid
= ccid_new(new_ccid_nr
, sk
, rx
, GFP_ATOMIC
);
344 if (new_ccid
== NULL
)
348 ccid_hc_rx_delete(dp
->dccps_hc_rx_ccid
, sk
);
349 dp
->dccps_hc_rx_ccid
= new_ccid
;
350 dmsk
->dccpms_rx_ccid
= new_ccid_nr
;
352 ccid_hc_tx_delete(dp
->dccps_hc_tx_ccid
, sk
);
353 dp
->dccps_hc_tx_ccid
= new_ccid
;
354 dmsk
->dccpms_tx_ccid
= new_ccid_nr
;
360 static int dccp_feat_update(struct sock
*sk
, u8 type
, u8 feat
, u8 val
)
362 dccp_feat_debug(type
, feat
, val
);
366 return dccp_feat_update_ccid(sk
, type
, val
);
368 dccp_pr_debug("UNIMPLEMENTED: %s(%d, ...)\n",
369 dccp_feat_typename(type
), feat
);
375 static int dccp_feat_reconcile(struct sock
*sk
, struct dccp_opt_pend
*opt
,
378 struct dccp_sock
*dp
= dccp_sk(sk
);
379 u8
*spref
, slen
, *res
= NULL
;
380 int i
, j
, rc
, agree
= 1;
382 BUG_ON(rpref
== NULL
);
384 /* check if we are the black sheep */
385 if (dp
->dccps_role
== DCCP_ROLE_CLIENT
) {
388 rpref
= opt
->dccpop_val
;
389 rlen
= opt
->dccpop_len
;
391 spref
= opt
->dccpop_val
;
392 slen
= opt
->dccpop_len
;
395 * Now we have server preference list in spref and client preference in
398 BUG_ON(spref
== NULL
);
399 BUG_ON(rpref
== NULL
);
401 /* FIXME sanity check vals */
403 /* Are values in any order? XXX Lame "algorithm" here */
404 for (i
= 0; i
< slen
; i
++) {
405 for (j
= 0; j
< rlen
; j
++) {
406 if (spref
[i
] == rpref
[j
]) {
415 /* we didn't agree on anything */
417 /* confirm previous value */
418 switch (opt
->dccpop_feat
) {
420 /* XXX did i get this right? =P */
421 if (opt
->dccpop_type
== DCCPO_CHANGE_L
)
422 res
= &dccp_msk(sk
)->dccpms_tx_ccid
;
424 res
= &dccp_msk(sk
)->dccpms_rx_ccid
;
428 DCCP_BUG("Fell through, feat=%d", opt
->dccpop_feat
);
429 /* XXX implement res */
433 dccp_pr_debug("Don't agree... reconfirming %d\n", *res
);
434 agree
= 0; /* this is used for mandatory options... */
437 /* need to put result and our preference list */
438 rlen
= 1 + opt
->dccpop_len
;
439 rpref
= kmalloc(rlen
, GFP_ATOMIC
);
444 memcpy(&rpref
[1], opt
->dccpop_val
, opt
->dccpop_len
);
446 /* put it in the "confirm queue" */
447 if (opt
->dccpop_sc
== NULL
) {
448 opt
->dccpop_sc
= kmalloc(sizeof(*opt
->dccpop_sc
), GFP_ATOMIC
);
449 if (opt
->dccpop_sc
== NULL
) {
454 /* recycle the confirm slot */
455 BUG_ON(opt
->dccpop_sc
->dccpoc_val
== NULL
);
456 kfree(opt
->dccpop_sc
->dccpoc_val
);
457 dccp_pr_debug("recycling confirm slot\n");
459 memset(opt
->dccpop_sc
, 0, sizeof(*opt
->dccpop_sc
));
461 opt
->dccpop_sc
->dccpoc_val
= rpref
;
462 opt
->dccpop_sc
->dccpoc_len
= rlen
;
464 /* update the option on our side [we are about to send the confirm] */
465 rc
= dccp_feat_update(sk
, opt
->dccpop_type
, opt
->dccpop_feat
, *res
);
467 kfree(opt
->dccpop_sc
->dccpoc_val
);
468 kfree(opt
->dccpop_sc
);
469 opt
->dccpop_sc
= NULL
;
473 dccp_pr_debug("Will confirm %d\n", *rpref
);
475 /* say we want to change to X but we just got a confirm X, suppress our
478 if (!opt
->dccpop_conf
) {
479 if (*opt
->dccpop_val
== *res
)
480 opt
->dccpop_conf
= 1;
481 dccp_pr_debug("won't ask for change of same feature\n");
484 return agree
? 0 : DCCP_FEAT_SP_NOAGREE
; /* used for mandatory opts */
487 static int dccp_feat_sp(struct sock
*sk
, u8 type
, u8 feature
, u8
*val
, u8 len
)
489 struct dccp_minisock
*dmsk
= dccp_msk(sk
);
490 struct dccp_opt_pend
*opt
;
495 * We received a CHANGE. We gotta match it against our own preference
496 * list. If we got a CHANGE_R it means it's a change for us, so we need
497 * to compare our CHANGE_L list.
499 if (type
== DCCPO_CHANGE_L
)
504 /* find our preference list for this feature */
505 list_for_each_entry(opt
, &dmsk
->dccpms_pending
, dccpop_node
) {
506 if (opt
->dccpop_type
!= t
|| opt
->dccpop_feat
!= feature
)
509 /* find the winner from the two preference lists */
510 rc
= dccp_feat_reconcile(sk
, opt
, val
, len
);
514 /* We didn't deal with the change. This can happen if we have no
515 * preference list for the feature. In fact, it just shouldn't
516 * happen---if we understand a feature, we should have a preference list
517 * with at least the default value.
524 static int dccp_feat_nn(struct sock
*sk
, u8 type
, u8 feature
, u8
*val
, u8 len
)
526 struct dccp_opt_pend
*opt
;
527 struct dccp_minisock
*dmsk
= dccp_msk(sk
);
531 /* NN features must be Change L (sec. 6.3.2) */
532 if (type
!= DCCPO_CHANGE_L
) {
533 dccp_pr_debug("received %s for NN feature %d\n",
534 dccp_feat_typename(type
), feature
);
538 /* XXX sanity check opt val */
540 /* copy option so we can confirm it */
541 opt
= kzalloc(sizeof(*opt
), GFP_ATOMIC
);
545 copy
= kmemdup(val
, len
, GFP_ATOMIC
);
551 opt
->dccpop_type
= DCCPO_CONFIRM_R
; /* NN can only confirm R */
552 opt
->dccpop_feat
= feature
;
553 opt
->dccpop_val
= copy
;
554 opt
->dccpop_len
= len
;
557 rc
= dccp_feat_update(sk
, type
, feature
, *val
);
559 kfree(opt
->dccpop_val
);
564 dccp_feat_debug(type
, feature
, *copy
);
566 list_add_tail(&opt
->dccpop_node
, &dmsk
->dccpms_conf
);
571 static void dccp_feat_empty_confirm(struct dccp_minisock
*dmsk
,
574 /* XXX check if other confirms for that are queued and recycle slot */
575 struct dccp_opt_pend
*opt
= kzalloc(sizeof(*opt
), GFP_ATOMIC
);
578 /* XXX what do we do? Ignoring should be fine. It's a change
586 opt
->dccpop_type
= DCCPO_CONFIRM_R
;
589 opt
->dccpop_type
= DCCPO_CONFIRM_L
;
592 DCCP_WARN("invalid type %d\n", type
);
596 opt
->dccpop_feat
= feature
;
597 opt
->dccpop_val
= NULL
;
601 dccp_pr_debug("Empty %s(%d)\n", dccp_feat_typename(type
), feature
);
603 list_add_tail(&opt
->dccpop_node
, &dmsk
->dccpms_conf
);
606 static void dccp_feat_flush_confirm(struct sock
*sk
)
608 struct dccp_minisock
*dmsk
= dccp_msk(sk
);
609 /* Check if there is anything to confirm in the first place */
610 int yes
= !list_empty(&dmsk
->dccpms_conf
);
613 struct dccp_opt_pend
*opt
;
615 list_for_each_entry(opt
, &dmsk
->dccpms_pending
, dccpop_node
) {
616 if (opt
->dccpop_conf
) {
626 /* OK there is something to confirm... */
627 /* XXX check if packet is in flight? Send delayed ack?? */
628 if (sk
->sk_state
== DCCP_OPEN
)
632 int dccp_feat_change_recv(struct sock
*sk
, u8 type
, u8 feature
, u8
*val
, u8 len
)
636 dccp_feat_debug(type
, feature
, *val
);
638 /* figure out if it's SP or NN feature */
640 /* deal with SP features */
642 rc
= dccp_feat_sp(sk
, type
, feature
, val
, len
);
645 /* deal with NN features */
646 case DCCPF_ACK_RATIO
:
647 rc
= dccp_feat_nn(sk
, type
, feature
, val
, len
);
650 /* XXX implement other features */
652 dccp_pr_debug("UNIMPLEMENTED: not handling %s(%d, ...)\n",
653 dccp_feat_typename(type
), feature
);
658 /* check if there were problems changing features */
660 /* If we don't agree on SP, we sent a confirm for old value.
661 * However we propagate rc to caller in case option was
664 if (rc
!= DCCP_FEAT_SP_NOAGREE
)
665 dccp_feat_empty_confirm(dccp_msk(sk
), type
, feature
);
668 /* generate the confirm [if required] */
669 dccp_feat_flush_confirm(sk
);
674 EXPORT_SYMBOL_GPL(dccp_feat_change_recv
);
676 int dccp_feat_confirm_recv(struct sock
*sk
, u8 type
, u8 feature
,
680 struct dccp_opt_pend
*opt
;
681 struct dccp_minisock
*dmsk
= dccp_msk(sk
);
683 int all_confirmed
= 1;
685 dccp_feat_debug(type
, feature
, *val
);
687 /* locate our change request */
689 case DCCPO_CONFIRM_L
: t
= DCCPO_CHANGE_R
; break;
690 case DCCPO_CONFIRM_R
: t
= DCCPO_CHANGE_L
; break;
691 default: DCCP_WARN("invalid type %d\n", type
);
695 /* XXX sanity check feature value */
697 list_for_each_entry(opt
, &dmsk
->dccpms_pending
, dccpop_node
) {
698 if (!opt
->dccpop_conf
&& opt
->dccpop_type
== t
&&
699 opt
->dccpop_feat
== feature
) {
701 dccp_pr_debug("feature %d found\n", opt
->dccpop_feat
);
703 /* XXX do sanity check */
705 opt
->dccpop_conf
= 1;
707 /* We got a confirmation---change the option */
708 dccp_feat_update(sk
, opt
->dccpop_type
,
709 opt
->dccpop_feat
, *val
);
711 /* XXX check the return value of dccp_feat_update */
715 if (!opt
->dccpop_conf
)
719 /* fix re-transmit timer */
720 /* XXX gotta make sure that no option negotiation occurs during
721 * connection shutdown. Consider that the CLOSEREQ is sent and timer is
722 * on. if all options are confirmed it might kill timer which should
723 * remain alive until close is received.
726 dccp_pr_debug("clear feat negotiation timer %p\n", sk
);
727 inet_csk_clear_xmit_timer(sk
, ICSK_TIME_RETRANS
);
731 dccp_pr_debug("%s(%d, ...) never requested\n",
732 dccp_feat_typename(type
), feature
);
736 EXPORT_SYMBOL_GPL(dccp_feat_confirm_recv
);
738 void dccp_feat_clean(struct dccp_minisock
*dmsk
)
740 struct dccp_opt_pend
*opt
, *next
;
742 list_for_each_entry_safe(opt
, next
, &dmsk
->dccpms_pending
,
744 BUG_ON(opt
->dccpop_val
== NULL
);
745 kfree(opt
->dccpop_val
);
747 if (opt
->dccpop_sc
!= NULL
) {
748 BUG_ON(opt
->dccpop_sc
->dccpoc_val
== NULL
);
749 kfree(opt
->dccpop_sc
->dccpoc_val
);
750 kfree(opt
->dccpop_sc
);
755 INIT_LIST_HEAD(&dmsk
->dccpms_pending
);
757 list_for_each_entry_safe(opt
, next
, &dmsk
->dccpms_conf
, dccpop_node
) {
759 if (opt
->dccpop_val
!= NULL
)
760 kfree(opt
->dccpop_val
);
763 INIT_LIST_HEAD(&dmsk
->dccpms_conf
);
766 EXPORT_SYMBOL_GPL(dccp_feat_clean
);
768 /* this is to be called only when a listening sock creates its child. It is
769 * assumed by the function---the confirm is not duplicated, but rather it is
772 int dccp_feat_clone(struct sock
*oldsk
, struct sock
*newsk
)
774 struct dccp_minisock
*olddmsk
= dccp_msk(oldsk
);
775 struct dccp_minisock
*newdmsk
= dccp_msk(newsk
);
776 struct dccp_opt_pend
*opt
;
779 INIT_LIST_HEAD(&newdmsk
->dccpms_pending
);
780 INIT_LIST_HEAD(&newdmsk
->dccpms_conf
);
782 list_for_each_entry(opt
, &olddmsk
->dccpms_pending
, dccpop_node
) {
783 struct dccp_opt_pend
*newopt
;
784 /* copy the value of the option */
785 u8
*val
= kmemdup(opt
->dccpop_val
, opt
->dccpop_len
, GFP_ATOMIC
);
790 newopt
= kmemdup(opt
, sizeof(*newopt
), GFP_ATOMIC
);
791 if (newopt
== NULL
) {
796 /* insert the option */
797 newopt
->dccpop_val
= val
;
798 list_add_tail(&newopt
->dccpop_node
, &newdmsk
->dccpms_pending
);
800 /* XXX what happens with backlogs and multiple connections at
803 /* the master socket no longer needs to worry about confirms */
804 opt
->dccpop_sc
= NULL
; /* it's not a memleak---new socket has it */
806 /* reset state for a new socket */
807 opt
->dccpop_conf
= 0;
810 /* XXX not doing anything about the conf queue */
816 dccp_feat_clean(newdmsk
);
821 EXPORT_SYMBOL_GPL(dccp_feat_clone
);
823 static int __dccp_feat_init(struct dccp_minisock
*dmsk
, u8 type
, u8 feat
,
827 u8
*copy
= kmemdup(val
, len
, GFP_KERNEL
);
830 rc
= dccp_feat_change(dmsk
, type
, feat
, copy
, len
, GFP_KERNEL
);
837 int dccp_feat_init(struct dccp_minisock
*dmsk
)
841 INIT_LIST_HEAD(&dmsk
->dccpms_pending
);
842 INIT_LIST_HEAD(&dmsk
->dccpms_conf
);
845 rc
= __dccp_feat_init(dmsk
, DCCPO_CHANGE_L
, DCCPF_CCID
,
846 &dmsk
->dccpms_tx_ccid
, 1);
851 rc
= __dccp_feat_init(dmsk
, DCCPO_CHANGE_R
, DCCPF_CCID
,
852 &dmsk
->dccpms_rx_ccid
, 1);
857 rc
= __dccp_feat_init(dmsk
, DCCPO_CHANGE_L
, DCCPF_ACK_RATIO
,
858 &dmsk
->dccpms_ack_ratio
, 1);
863 EXPORT_SYMBOL_GPL(dccp_feat_init
);
865 #ifdef CONFIG_IP_DCCP_DEBUG
866 const char *dccp_feat_typename(const u8 type
)
869 case DCCPO_CHANGE_L
: return("ChangeL");
870 case DCCPO_CONFIRM_L
: return("ConfirmL");
871 case DCCPO_CHANGE_R
: return("ChangeR");
872 case DCCPO_CONFIRM_R
: return("ConfirmR");
873 /* the following case must not appear in feature negotation */
874 default: dccp_pr_debug("unknown type %d [BUG!]\n", type
);
879 EXPORT_SYMBOL_GPL(dccp_feat_typename
);
881 const char *dccp_feat_name(const u8 feat
)
883 static const char *feature_names
[] = {
884 [DCCPF_RESERVED
] = "Reserved",
885 [DCCPF_CCID
] = "CCID",
886 [DCCPF_SHORT_SEQNOS
] = "Allow Short Seqnos",
887 [DCCPF_SEQUENCE_WINDOW
] = "Sequence Window",
888 [DCCPF_ECN_INCAPABLE
] = "ECN Incapable",
889 [DCCPF_ACK_RATIO
] = "Ack Ratio",
890 [DCCPF_SEND_ACK_VECTOR
] = "Send ACK Vector",
891 [DCCPF_SEND_NDP_COUNT
] = "Send NDP Count",
892 [DCCPF_MIN_CSUM_COVER
] = "Min. Csum Coverage",
893 [DCCPF_DATA_CHECKSUM
] = "Send Data Checksum",
895 if (feat
> DCCPF_DATA_CHECKSUM
&& feat
< DCCPF_MIN_CCID_SPECIFIC
)
896 return feature_names
[DCCPF_RESERVED
];
898 if (feat
== DCCPF_SEND_LEV_RATE
)
899 return "Send Loss Event Rate";
900 if (feat
>= DCCPF_MIN_CCID_SPECIFIC
)
901 return "CCID-specific";
903 return feature_names
[feat
];
906 EXPORT_SYMBOL_GPL(dccp_feat_name
);
907 #endif /* CONFIG_IP_DCCP_DEBUG */