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 /* generate @to as full clone of @from - @to must not contain any nodes */
283 int dccp_feat_clone_list(struct list_head
const *from
, struct list_head
*to
)
285 struct dccp_feat_entry
*entry
, *new;
288 list_for_each_entry(entry
, from
, node
) {
289 new = dccp_feat_clone_entry(entry
);
292 list_add_tail(&new->node
, to
);
297 dccp_feat_list_purge(to
);
301 int dccp_feat_change(struct dccp_minisock
*dmsk
, u8 type
, u8 feature
,
302 u8
*val
, u8 len
, gfp_t gfp
)
304 struct dccp_opt_pend
*opt
;
306 dccp_feat_debug(type
, feature
, *val
);
309 DCCP_WARN("invalid length %d\n", len
);
312 /* XXX add further sanity checks */
314 /* check if that feature is already being negotiated */
315 list_for_each_entry(opt
, &dmsk
->dccpms_pending
, dccpop_node
) {
316 /* ok we found a negotiation for this option already */
317 if (opt
->dccpop_feat
== feature
&& opt
->dccpop_type
== type
) {
318 dccp_pr_debug("Replacing old\n");
320 BUG_ON(opt
->dccpop_val
== NULL
);
321 kfree(opt
->dccpop_val
);
322 opt
->dccpop_val
= val
;
323 opt
->dccpop_len
= len
;
324 opt
->dccpop_conf
= 0;
329 /* negotiation for a new feature */
330 opt
= kmalloc(sizeof(*opt
), gfp
);
334 opt
->dccpop_type
= type
;
335 opt
->dccpop_feat
= feature
;
336 opt
->dccpop_len
= len
;
337 opt
->dccpop_val
= val
;
338 opt
->dccpop_conf
= 0;
339 opt
->dccpop_sc
= NULL
;
341 BUG_ON(opt
->dccpop_val
== NULL
);
343 list_add_tail(&opt
->dccpop_node
, &dmsk
->dccpms_pending
);
347 EXPORT_SYMBOL_GPL(dccp_feat_change
);
349 static int dccp_feat_update_ccid(struct sock
*sk
, u8 type
, u8 new_ccid_nr
)
351 struct dccp_sock
*dp
= dccp_sk(sk
);
352 struct dccp_minisock
*dmsk
= dccp_msk(sk
);
353 /* figure out if we are changing our CCID or the peer's */
354 const int rx
= type
== DCCPO_CHANGE_R
;
355 const u8 ccid_nr
= rx
? dmsk
->dccpms_rx_ccid
: dmsk
->dccpms_tx_ccid
;
356 struct ccid
*new_ccid
;
358 /* Check if nothing is being changed. */
359 if (ccid_nr
== new_ccid_nr
)
362 new_ccid
= ccid_new(new_ccid_nr
, sk
, rx
, GFP_ATOMIC
);
363 if (new_ccid
== NULL
)
367 ccid_hc_rx_delete(dp
->dccps_hc_rx_ccid
, sk
);
368 dp
->dccps_hc_rx_ccid
= new_ccid
;
369 dmsk
->dccpms_rx_ccid
= new_ccid_nr
;
371 ccid_hc_tx_delete(dp
->dccps_hc_tx_ccid
, sk
);
372 dp
->dccps_hc_tx_ccid
= new_ccid
;
373 dmsk
->dccpms_tx_ccid
= new_ccid_nr
;
379 static int dccp_feat_update(struct sock
*sk
, u8 type
, u8 feat
, u8 val
)
381 dccp_feat_debug(type
, feat
, val
);
385 return dccp_feat_update_ccid(sk
, type
, val
);
387 dccp_pr_debug("UNIMPLEMENTED: %s(%d, ...)\n",
388 dccp_feat_typename(type
), feat
);
394 static int dccp_feat_reconcile(struct sock
*sk
, struct dccp_opt_pend
*opt
,
397 struct dccp_sock
*dp
= dccp_sk(sk
);
398 u8
*spref
, slen
, *res
= NULL
;
399 int i
, j
, rc
, agree
= 1;
401 BUG_ON(rpref
== NULL
);
403 /* check if we are the black sheep */
404 if (dp
->dccps_role
== DCCP_ROLE_CLIENT
) {
407 rpref
= opt
->dccpop_val
;
408 rlen
= opt
->dccpop_len
;
410 spref
= opt
->dccpop_val
;
411 slen
= opt
->dccpop_len
;
414 * Now we have server preference list in spref and client preference in
417 BUG_ON(spref
== NULL
);
418 BUG_ON(rpref
== NULL
);
420 /* FIXME sanity check vals */
422 /* Are values in any order? XXX Lame "algorithm" here */
423 for (i
= 0; i
< slen
; i
++) {
424 for (j
= 0; j
< rlen
; j
++) {
425 if (spref
[i
] == rpref
[j
]) {
434 /* we didn't agree on anything */
436 /* confirm previous value */
437 switch (opt
->dccpop_feat
) {
439 /* XXX did i get this right? =P */
440 if (opt
->dccpop_type
== DCCPO_CHANGE_L
)
441 res
= &dccp_msk(sk
)->dccpms_tx_ccid
;
443 res
= &dccp_msk(sk
)->dccpms_rx_ccid
;
447 DCCP_BUG("Fell through, feat=%d", opt
->dccpop_feat
);
448 /* XXX implement res */
452 dccp_pr_debug("Don't agree... reconfirming %d\n", *res
);
453 agree
= 0; /* this is used for mandatory options... */
456 /* need to put result and our preference list */
457 rlen
= 1 + opt
->dccpop_len
;
458 rpref
= kmalloc(rlen
, GFP_ATOMIC
);
463 memcpy(&rpref
[1], opt
->dccpop_val
, opt
->dccpop_len
);
465 /* put it in the "confirm queue" */
466 if (opt
->dccpop_sc
== NULL
) {
467 opt
->dccpop_sc
= kmalloc(sizeof(*opt
->dccpop_sc
), GFP_ATOMIC
);
468 if (opt
->dccpop_sc
== NULL
) {
473 /* recycle the confirm slot */
474 BUG_ON(opt
->dccpop_sc
->dccpoc_val
== NULL
);
475 kfree(opt
->dccpop_sc
->dccpoc_val
);
476 dccp_pr_debug("recycling confirm slot\n");
478 memset(opt
->dccpop_sc
, 0, sizeof(*opt
->dccpop_sc
));
480 opt
->dccpop_sc
->dccpoc_val
= rpref
;
481 opt
->dccpop_sc
->dccpoc_len
= rlen
;
483 /* update the option on our side [we are about to send the confirm] */
484 rc
= dccp_feat_update(sk
, opt
->dccpop_type
, opt
->dccpop_feat
, *res
);
486 kfree(opt
->dccpop_sc
->dccpoc_val
);
487 kfree(opt
->dccpop_sc
);
488 opt
->dccpop_sc
= NULL
;
492 dccp_pr_debug("Will confirm %d\n", *rpref
);
494 /* say we want to change to X but we just got a confirm X, suppress our
497 if (!opt
->dccpop_conf
) {
498 if (*opt
->dccpop_val
== *res
)
499 opt
->dccpop_conf
= 1;
500 dccp_pr_debug("won't ask for change of same feature\n");
503 return agree
? 0 : DCCP_FEAT_SP_NOAGREE
; /* used for mandatory opts */
506 static int dccp_feat_sp(struct sock
*sk
, u8 type
, u8 feature
, u8
*val
, u8 len
)
508 struct dccp_minisock
*dmsk
= dccp_msk(sk
);
509 struct dccp_opt_pend
*opt
;
514 * We received a CHANGE. We gotta match it against our own preference
515 * list. If we got a CHANGE_R it means it's a change for us, so we need
516 * to compare our CHANGE_L list.
518 if (type
== DCCPO_CHANGE_L
)
523 /* find our preference list for this feature */
524 list_for_each_entry(opt
, &dmsk
->dccpms_pending
, dccpop_node
) {
525 if (opt
->dccpop_type
!= t
|| opt
->dccpop_feat
!= feature
)
528 /* find the winner from the two preference lists */
529 rc
= dccp_feat_reconcile(sk
, opt
, val
, len
);
533 /* We didn't deal with the change. This can happen if we have no
534 * preference list for the feature. In fact, it just shouldn't
535 * happen---if we understand a feature, we should have a preference list
536 * with at least the default value.
543 static int dccp_feat_nn(struct sock
*sk
, u8 type
, u8 feature
, u8
*val
, u8 len
)
545 struct dccp_opt_pend
*opt
;
546 struct dccp_minisock
*dmsk
= dccp_msk(sk
);
550 /* NN features must be Change L (sec. 6.3.2) */
551 if (type
!= DCCPO_CHANGE_L
) {
552 dccp_pr_debug("received %s for NN feature %d\n",
553 dccp_feat_typename(type
), feature
);
557 /* XXX sanity check opt val */
559 /* copy option so we can confirm it */
560 opt
= kzalloc(sizeof(*opt
), GFP_ATOMIC
);
564 copy
= kmemdup(val
, len
, GFP_ATOMIC
);
570 opt
->dccpop_type
= DCCPO_CONFIRM_R
; /* NN can only confirm R */
571 opt
->dccpop_feat
= feature
;
572 opt
->dccpop_val
= copy
;
573 opt
->dccpop_len
= len
;
576 rc
= dccp_feat_update(sk
, type
, feature
, *val
);
578 kfree(opt
->dccpop_val
);
583 dccp_feat_debug(type
, feature
, *copy
);
585 list_add_tail(&opt
->dccpop_node
, &dmsk
->dccpms_conf
);
590 static void dccp_feat_empty_confirm(struct dccp_minisock
*dmsk
,
593 /* XXX check if other confirms for that are queued and recycle slot */
594 struct dccp_opt_pend
*opt
= kzalloc(sizeof(*opt
), GFP_ATOMIC
);
597 /* XXX what do we do? Ignoring should be fine. It's a change
605 opt
->dccpop_type
= DCCPO_CONFIRM_R
;
608 opt
->dccpop_type
= DCCPO_CONFIRM_L
;
611 DCCP_WARN("invalid type %d\n", type
);
615 opt
->dccpop_feat
= feature
;
616 opt
->dccpop_val
= NULL
;
620 dccp_pr_debug("Empty %s(%d)\n", dccp_feat_typename(type
), feature
);
622 list_add_tail(&opt
->dccpop_node
, &dmsk
->dccpms_conf
);
625 static void dccp_feat_flush_confirm(struct sock
*sk
)
627 struct dccp_minisock
*dmsk
= dccp_msk(sk
);
628 /* Check if there is anything to confirm in the first place */
629 int yes
= !list_empty(&dmsk
->dccpms_conf
);
632 struct dccp_opt_pend
*opt
;
634 list_for_each_entry(opt
, &dmsk
->dccpms_pending
, dccpop_node
) {
635 if (opt
->dccpop_conf
) {
645 /* OK there is something to confirm... */
646 /* XXX check if packet is in flight? Send delayed ack?? */
647 if (sk
->sk_state
== DCCP_OPEN
)
651 int dccp_feat_change_recv(struct sock
*sk
, u8 type
, u8 feature
, u8
*val
, u8 len
)
655 dccp_feat_debug(type
, feature
, *val
);
657 /* figure out if it's SP or NN feature */
659 /* deal with SP features */
661 rc
= dccp_feat_sp(sk
, type
, feature
, val
, len
);
664 /* deal with NN features */
665 case DCCPF_ACK_RATIO
:
666 rc
= dccp_feat_nn(sk
, type
, feature
, val
, len
);
669 /* XXX implement other features */
671 dccp_pr_debug("UNIMPLEMENTED: not handling %s(%d, ...)\n",
672 dccp_feat_typename(type
), feature
);
677 /* check if there were problems changing features */
679 /* If we don't agree on SP, we sent a confirm for old value.
680 * However we propagate rc to caller in case option was
683 if (rc
!= DCCP_FEAT_SP_NOAGREE
)
684 dccp_feat_empty_confirm(dccp_msk(sk
), type
, feature
);
687 /* generate the confirm [if required] */
688 dccp_feat_flush_confirm(sk
);
693 EXPORT_SYMBOL_GPL(dccp_feat_change_recv
);
695 int dccp_feat_confirm_recv(struct sock
*sk
, u8 type
, u8 feature
,
699 struct dccp_opt_pend
*opt
;
700 struct dccp_minisock
*dmsk
= dccp_msk(sk
);
702 int all_confirmed
= 1;
704 dccp_feat_debug(type
, feature
, *val
);
706 /* locate our change request */
708 case DCCPO_CONFIRM_L
: t
= DCCPO_CHANGE_R
; break;
709 case DCCPO_CONFIRM_R
: t
= DCCPO_CHANGE_L
; break;
710 default: DCCP_WARN("invalid type %d\n", type
);
714 /* XXX sanity check feature value */
716 list_for_each_entry(opt
, &dmsk
->dccpms_pending
, dccpop_node
) {
717 if (!opt
->dccpop_conf
&& opt
->dccpop_type
== t
&&
718 opt
->dccpop_feat
== feature
) {
720 dccp_pr_debug("feature %d found\n", opt
->dccpop_feat
);
722 /* XXX do sanity check */
724 opt
->dccpop_conf
= 1;
726 /* We got a confirmation---change the option */
727 dccp_feat_update(sk
, opt
->dccpop_type
,
728 opt
->dccpop_feat
, *val
);
730 /* XXX check the return value of dccp_feat_update */
734 if (!opt
->dccpop_conf
)
738 /* fix re-transmit timer */
739 /* XXX gotta make sure that no option negotiation occurs during
740 * connection shutdown. Consider that the CLOSEREQ is sent and timer is
741 * on. if all options are confirmed it might kill timer which should
742 * remain alive until close is received.
745 dccp_pr_debug("clear feat negotiation timer %p\n", sk
);
746 inet_csk_clear_xmit_timer(sk
, ICSK_TIME_RETRANS
);
750 dccp_pr_debug("%s(%d, ...) never requested\n",
751 dccp_feat_typename(type
), feature
);
755 EXPORT_SYMBOL_GPL(dccp_feat_confirm_recv
);
757 void dccp_feat_clean(struct dccp_minisock
*dmsk
)
759 struct dccp_opt_pend
*opt
, *next
;
761 list_for_each_entry_safe(opt
, next
, &dmsk
->dccpms_pending
,
763 BUG_ON(opt
->dccpop_val
== NULL
);
764 kfree(opt
->dccpop_val
);
766 if (opt
->dccpop_sc
!= NULL
) {
767 BUG_ON(opt
->dccpop_sc
->dccpoc_val
== NULL
);
768 kfree(opt
->dccpop_sc
->dccpoc_val
);
769 kfree(opt
->dccpop_sc
);
774 INIT_LIST_HEAD(&dmsk
->dccpms_pending
);
776 list_for_each_entry_safe(opt
, next
, &dmsk
->dccpms_conf
, dccpop_node
) {
778 if (opt
->dccpop_val
!= NULL
)
779 kfree(opt
->dccpop_val
);
782 INIT_LIST_HEAD(&dmsk
->dccpms_conf
);
785 EXPORT_SYMBOL_GPL(dccp_feat_clean
);
787 /* this is to be called only when a listening sock creates its child. It is
788 * assumed by the function---the confirm is not duplicated, but rather it is
791 int dccp_feat_clone(struct sock
*oldsk
, struct sock
*newsk
)
793 struct dccp_minisock
*olddmsk
= dccp_msk(oldsk
);
794 struct dccp_minisock
*newdmsk
= dccp_msk(newsk
);
795 struct dccp_opt_pend
*opt
;
798 INIT_LIST_HEAD(&newdmsk
->dccpms_pending
);
799 INIT_LIST_HEAD(&newdmsk
->dccpms_conf
);
801 list_for_each_entry(opt
, &olddmsk
->dccpms_pending
, dccpop_node
) {
802 struct dccp_opt_pend
*newopt
;
803 /* copy the value of the option */
804 u8
*val
= kmemdup(opt
->dccpop_val
, opt
->dccpop_len
, GFP_ATOMIC
);
809 newopt
= kmemdup(opt
, sizeof(*newopt
), GFP_ATOMIC
);
810 if (newopt
== NULL
) {
815 /* insert the option */
816 newopt
->dccpop_val
= val
;
817 list_add_tail(&newopt
->dccpop_node
, &newdmsk
->dccpms_pending
);
819 /* XXX what happens with backlogs and multiple connections at
822 /* the master socket no longer needs to worry about confirms */
823 opt
->dccpop_sc
= NULL
; /* it's not a memleak---new socket has it */
825 /* reset state for a new socket */
826 opt
->dccpop_conf
= 0;
829 /* XXX not doing anything about the conf queue */
835 dccp_feat_clean(newdmsk
);
840 EXPORT_SYMBOL_GPL(dccp_feat_clone
);
842 static int __dccp_feat_init(struct dccp_minisock
*dmsk
, u8 type
, u8 feat
,
846 u8
*copy
= kmemdup(val
, len
, GFP_KERNEL
);
849 rc
= dccp_feat_change(dmsk
, type
, feat
, copy
, len
, GFP_KERNEL
);
856 int dccp_feat_init(struct dccp_minisock
*dmsk
)
860 INIT_LIST_HEAD(&dmsk
->dccpms_pending
);
861 INIT_LIST_HEAD(&dmsk
->dccpms_conf
);
864 rc
= __dccp_feat_init(dmsk
, DCCPO_CHANGE_L
, DCCPF_CCID
,
865 &dmsk
->dccpms_tx_ccid
, 1);
870 rc
= __dccp_feat_init(dmsk
, DCCPO_CHANGE_R
, DCCPF_CCID
,
871 &dmsk
->dccpms_rx_ccid
, 1);
876 rc
= __dccp_feat_init(dmsk
, DCCPO_CHANGE_L
, DCCPF_ACK_RATIO
,
877 &dmsk
->dccpms_ack_ratio
, 1);
882 EXPORT_SYMBOL_GPL(dccp_feat_init
);
884 #ifdef CONFIG_IP_DCCP_DEBUG
885 const char *dccp_feat_typename(const u8 type
)
888 case DCCPO_CHANGE_L
: return("ChangeL");
889 case DCCPO_CONFIRM_L
: return("ConfirmL");
890 case DCCPO_CHANGE_R
: return("ChangeR");
891 case DCCPO_CONFIRM_R
: return("ConfirmR");
892 /* the following case must not appear in feature negotation */
893 default: dccp_pr_debug("unknown type %d [BUG!]\n", type
);
898 EXPORT_SYMBOL_GPL(dccp_feat_typename
);
900 const char *dccp_feat_name(const u8 feat
)
902 static const char *feature_names
[] = {
903 [DCCPF_RESERVED
] = "Reserved",
904 [DCCPF_CCID
] = "CCID",
905 [DCCPF_SHORT_SEQNOS
] = "Allow Short Seqnos",
906 [DCCPF_SEQUENCE_WINDOW
] = "Sequence Window",
907 [DCCPF_ECN_INCAPABLE
] = "ECN Incapable",
908 [DCCPF_ACK_RATIO
] = "Ack Ratio",
909 [DCCPF_SEND_ACK_VECTOR
] = "Send ACK Vector",
910 [DCCPF_SEND_NDP_COUNT
] = "Send NDP Count",
911 [DCCPF_MIN_CSUM_COVER
] = "Min. Csum Coverage",
912 [DCCPF_DATA_CHECKSUM
] = "Send Data Checksum",
914 if (feat
> DCCPF_DATA_CHECKSUM
&& feat
< DCCPF_MIN_CCID_SPECIFIC
)
915 return feature_names
[DCCPF_RESERVED
];
917 if (feat
== DCCPF_SEND_LEV_RATE
)
918 return "Send Loss Event Rate";
919 if (feat
>= DCCPF_MIN_CCID_SPECIFIC
)
920 return "CCID-specific";
922 return feature_names
[feat
];
925 EXPORT_SYMBOL_GPL(dccp_feat_name
);
926 #endif /* CONFIG_IP_DCCP_DEBUG */