4 * An implementation of the DCCP protocol
5 * Andrea Bittau <a.bittau@cs.ucl.ac.uk>
9 * o Feature negotiation is coordinated with connection setup (as in TCP), wild
10 * changes of parameters of an established connection are not supported.
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.
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.
21 #include <linux/module.h>
26 #define DCCP_FEAT_SP_NOAGREE (-123)
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 */
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 * +--------------------------+----+-----+----+----+---------+-----------+
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 },
63 #define DCCP_FEAT_SUPPORTED_MAX ARRAY_SIZE(dccp_feat_table)
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.
69 static int dccp_feat_index(u8 feat_num)
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)
76 * Other features: add cases for new feature types here after adding
77 * them to the above table.
80 case DCCPF_SEND_LEV_RATE:
81 return DCCP_FEAT_SUPPORTED_MAX - 1;
86 static u8 dccp_feat_type(u8 feat_num)
88 int idx = dccp_feat_index(feat_num);
92 return dccp_feat_table[idx].reconciliation;
95 static int dccp_feat_default_value(u8 feat_num)
97 int idx = dccp_feat_index(feat_num);
99 return idx < 0 ? : dccp_feat_table[idx].default_value;
102 /* copy constructor, fval must not already contain allocated memory */
103 static int dccp_feat_clone_sp_val(dccp_feat_val *fval, u8 const *val, u8 len)
106 if (fval->sp.len > 0) {
107 fval->sp.vec = kmemdup(val, len, gfp_any());
108 if (fval->sp.vec == NULL) {
116 static void dccp_feat_val_destructor(u8 feat_num, dccp_feat_val *val)
118 if (unlikely(val == NULL))
120 if (dccp_feat_type(feat_num) == FEAT_SP)
122 memset(val, 0, sizeof(*val));
125 static struct dccp_feat_entry *
126 dccp_feat_clone_entry(struct dccp_feat_entry const *original)
128 struct dccp_feat_entry *new;
129 u8 type = dccp_feat_type(original->feat_num);
131 if (type == FEAT_UNKNOWN)
134 new = kmemdup(original, sizeof(struct dccp_feat_entry), gfp_any());
138 if (type == FEAT_SP && dccp_feat_clone_sp_val(&new->val,
139 original->val.sp.vec,
140 original->val.sp.len)) {
147 static void dccp_feat_entry_destructor(struct dccp_feat_entry *entry)
150 dccp_feat_val_destructor(entry->feat_num, &entry->val);
156 * List management functions
158 * Feature negotiation lists rely on and maintain the following invariants:
159 * - each feat_num in the list is known, i.e. we know its type and default value
160 * - each feat_num/is_local combination is unique (old entries are overwritten)
161 * - SP values are always freshly allocated
162 * - list is sorted in increasing order of feature number (faster lookup)
164 static struct dccp_feat_entry *dccp_feat_list_lookup(struct list_head *fn_list,
165 u8 feat_num, bool is_local)
167 struct dccp_feat_entry *entry;
169 list_for_each_entry(entry, fn_list, node)
170 if (entry->feat_num == feat_num && entry->is_local == is_local)
172 else if (entry->feat_num > feat_num)
178 * dccp_feat_entry_new - Central list update routine (called by all others)
179 * @head: list to add to
180 * @feat: feature number
181 * @local: whether the local (1) or remote feature with number @feat is meant
182 * This is the only constructor and serves to ensure the above invariants.
184 static struct dccp_feat_entry *
185 dccp_feat_entry_new(struct list_head *head, u8 feat, bool local)
187 struct dccp_feat_entry *entry;
189 list_for_each_entry(entry, head, node)
190 if (entry->feat_num == feat && entry->is_local == local) {
191 dccp_feat_val_destructor(entry->feat_num, &entry->val);
193 } else if (entry->feat_num > feat) {
198 entry = kmalloc(sizeof(*entry), gfp_any());
200 entry->feat_num = feat;
201 entry->is_local = local;
202 list_add_tail(&entry->node, head);
208 * dccp_feat_push_change - Add/overwrite a Change option in the list
209 * @fn_list: feature-negotiation list to update
210 * @feat: one of %dccp_feature_numbers
211 * @local: whether local (1) or remote (0) @feat_num is meant
212 * @needs_mandatory: whether to use Mandatory feature negotiation options
213 * @fval: pointer to NN/SP value to be inserted (will be copied)
215 static int dccp_feat_push_change(struct list_head *fn_list, u8 feat, u8 local,
216 u8 mandatory, dccp_feat_val *fval)
218 struct dccp_feat_entry *new = dccp_feat_entry_new(fn_list, feat, local);
223 new->feat_num = feat;
224 new->is_local = local;
225 new->state = FEAT_INITIALISING;
226 new->needs_confirm = 0;
227 new->empty_confirm = 0;
229 new->needs_mandatory = mandatory;
235 * dccp_feat_push_confirm - Add a Confirm entry to the FN list
236 * @fn_list: feature-negotiation list to add to
237 * @feat: one of %dccp_feature_numbers
238 * @local: whether local (1) or remote (0) @feat_num is being confirmed
239 * @fval: pointer to NN/SP value to be inserted or NULL
240 * Returns 0 on success, a Reset code for further processing otherwise.
242 static int dccp_feat_push_confirm(struct list_head *fn_list, u8 feat, u8 local,
245 struct dccp_feat_entry *new = dccp_feat_entry_new(fn_list, feat, local);
248 return DCCP_RESET_CODE_TOO_BUSY;
250 new->feat_num = feat;
251 new->is_local = local;
252 new->state = FEAT_STABLE; /* transition in 6.6.2 */
253 new->needs_confirm = 1;
254 new->empty_confirm = (fval == NULL);
255 new->val.nn = 0; /* zeroes the whole structure */
256 if (!new->empty_confirm)
258 new->needs_mandatory = 0;
263 static int dccp_push_empty_confirm(struct list_head *fn_list, u8 feat, u8 local)
265 return dccp_feat_push_confirm(fn_list, feat, local, NULL);
268 static inline void dccp_feat_list_pop(struct dccp_feat_entry *entry)
270 list_del(&entry->node);
271 dccp_feat_entry_destructor(entry);
274 void dccp_feat_list_purge(struct list_head *fn_list)
276 struct dccp_feat_entry *entry, *next;
278 list_for_each_entry_safe(entry, next, fn_list, node)
279 dccp_feat_entry_destructor(entry);
280 INIT_LIST_HEAD(fn_list);
282 EXPORT_SYMBOL_GPL(dccp_feat_list_purge);
284 /* generate @to as full clone of @from - @to must not contain any nodes */
285 int dccp_feat_clone_list(struct list_head const *from, struct list_head *to)
287 struct dccp_feat_entry *entry, *new;
290 list_for_each_entry(entry, from, node) {
291 new = dccp_feat_clone_entry(entry);
294 list_add_tail(&new->node, to);
299 dccp_feat_list_purge(to);
303 static u8 dccp_feat_is_valid_nn_val(u8 feat_num, u64 val)
306 case DCCPF_ACK_RATIO:
307 return val <= DCCPF_ACK_RATIO_MAX;
308 case DCCPF_SEQUENCE_WINDOW:
309 return val >= DCCPF_SEQ_WMIN && val <= DCCPF_SEQ_WMAX;
311 return 0; /* feature unknown - so we can't tell */
314 /* check that SP values are within the ranges defined in RFC 4340 */
315 static u8 dccp_feat_is_valid_sp_val(u8 feat_num, u8 val)
319 return val == DCCPC_CCID2 || val == DCCPC_CCID3;
320 /* Type-check Boolean feature values: */
321 case DCCPF_SHORT_SEQNOS:
322 case DCCPF_ECN_INCAPABLE:
323 case DCCPF_SEND_ACK_VECTOR:
324 case DCCPF_SEND_NDP_COUNT:
325 case DCCPF_DATA_CHECKSUM:
326 case DCCPF_SEND_LEV_RATE:
328 case DCCPF_MIN_CSUM_COVER:
331 return 0; /* feature unknown */
334 static u8 dccp_feat_sp_list_ok(u8 feat_num, u8 const *sp_list, u8 sp_len)
336 if (sp_list == NULL || sp_len < 1)
339 if (!dccp_feat_is_valid_sp_val(feat_num, *sp_list++))
345 * __feat_register_nn - Register new NN value on socket
346 * @fn: feature-negotiation list to register with
347 * @feat: an NN feature from %dccp_feature_numbers
348 * @mandatory: use Mandatory option if 1
349 * @nn_val: value to register (restricted to 4 bytes)
350 * Note that NN features are local by definition (RFC 4340, 6.3.2).
352 static int __feat_register_nn(struct list_head *fn, u8 feat,
353 u8 mandatory, u64 nn_val)
355 dccp_feat_val fval = { .nn = nn_val };
357 if (dccp_feat_type(feat) != FEAT_NN ||
358 !dccp_feat_is_valid_nn_val(feat, nn_val))
361 /* Don't bother with default values, they will be activated anyway. */
362 if (nn_val - (u64)dccp_feat_default_value(feat) == 0)
365 return dccp_feat_push_change(fn, feat, 1, mandatory, &fval);
369 * __feat_register_sp - Register new SP value/list on socket
370 * @fn: feature-negotiation list to register with
371 * @feat: an SP feature from %dccp_feature_numbers
372 * @is_local: whether the local (1) or the remote (0) @feat is meant
373 * @mandatory: use Mandatory option if 1
374 * @sp_val: SP value followed by optional preference list
375 * @sp_len: length of @sp_val in bytes
377 static int __feat_register_sp(struct list_head *fn, u8 feat, u8 is_local,
378 u8 mandatory, u8 const *sp_val, u8 sp_len)
382 if (dccp_feat_type(feat) != FEAT_SP ||
383 !dccp_feat_sp_list_ok(feat, sp_val, sp_len))
386 if (dccp_feat_clone_sp_val(&fval, sp_val, sp_len))
389 return dccp_feat_push_change(fn, feat, is_local, mandatory, &fval);
392 int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature,
393 u8 *val, u8 len, gfp_t gfp)
395 struct dccp_opt_pend *opt;
397 dccp_feat_debug(type, feature, *val);
400 DCCP_WARN("invalid length %d\n", len);
403 /* XXX add further sanity checks */
405 /* check if that feature is already being negotiated */
406 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
407 /* ok we found a negotiation for this option already */
408 if (opt->dccpop_feat == feature && opt->dccpop_type == type) {
409 dccp_pr_debug("Replacing old\n");
411 BUG_ON(opt->dccpop_val == NULL);
412 kfree(opt->dccpop_val);
413 opt->dccpop_val = val;
414 opt->dccpop_len = len;
415 opt->dccpop_conf = 0;
420 /* negotiation for a new feature */
421 opt = kmalloc(sizeof(*opt), gfp);
425 opt->dccpop_type = type;
426 opt->dccpop_feat = feature;
427 opt->dccpop_len = len;
428 opt->dccpop_val = val;
429 opt->dccpop_conf = 0;
430 opt->dccpop_sc = NULL;
432 BUG_ON(opt->dccpop_val == NULL);
434 list_add_tail(&opt->dccpop_node, &dmsk->dccpms_pending);
438 EXPORT_SYMBOL_GPL(dccp_feat_change);
440 static int dccp_feat_update_ccid(struct sock *sk, u8 type, u8 new_ccid_nr)
442 struct dccp_sock *dp = dccp_sk(sk);
443 struct dccp_minisock *dmsk = dccp_msk(sk);
444 /* figure out if we are changing our CCID or the peer's */
445 const int rx = type == DCCPO_CHANGE_R;
446 const u8 ccid_nr = rx ? dmsk->dccpms_rx_ccid : dmsk->dccpms_tx_ccid;
447 struct ccid *new_ccid;
449 /* Check if nothing is being changed. */
450 if (ccid_nr == new_ccid_nr)
453 new_ccid = ccid_new(new_ccid_nr, sk, rx, GFP_ATOMIC);
454 if (new_ccid == NULL)
458 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
459 dp->dccps_hc_rx_ccid = new_ccid;
460 dmsk->dccpms_rx_ccid = new_ccid_nr;
462 ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
463 dp->dccps_hc_tx_ccid = new_ccid;
464 dmsk->dccpms_tx_ccid = new_ccid_nr;
470 static int dccp_feat_update(struct sock *sk, u8 type, u8 feat, u8 val)
472 dccp_feat_debug(type, feat, val);
476 return dccp_feat_update_ccid(sk, type, val);
478 dccp_pr_debug("UNIMPLEMENTED: %s(%d, ...)\n",
479 dccp_feat_typename(type), feat);
485 static int dccp_feat_reconcile(struct sock *sk, struct dccp_opt_pend *opt,
488 struct dccp_sock *dp = dccp_sk(sk);
489 u8 *spref, slen, *res = NULL;
490 int i, j, rc, agree = 1;
492 BUG_ON(rpref == NULL);
494 /* check if we are the black sheep */
495 if (dp->dccps_role == DCCP_ROLE_CLIENT) {
498 rpref = opt->dccpop_val;
499 rlen = opt->dccpop_len;
501 spref = opt->dccpop_val;
502 slen = opt->dccpop_len;
505 * Now we have server preference list in spref and client preference in
508 BUG_ON(spref == NULL);
509 BUG_ON(rpref == NULL);
511 /* FIXME sanity check vals */
513 /* Are values in any order? XXX Lame "algorithm" here */
514 for (i = 0; i < slen; i++) {
515 for (j = 0; j < rlen; j++) {
516 if (spref[i] == rpref[j]) {
525 /* we didn't agree on anything */
527 /* confirm previous value */
528 switch (opt->dccpop_feat) {
530 /* XXX did i get this right? =P */
531 if (opt->dccpop_type == DCCPO_CHANGE_L)
532 res = &dccp_msk(sk)->dccpms_tx_ccid;
534 res = &dccp_msk(sk)->dccpms_rx_ccid;
538 DCCP_BUG("Fell through, feat=%d", opt->dccpop_feat);
539 /* XXX implement res */
543 dccp_pr_debug("Don't agree... reconfirming %d\n", *res);
544 agree = 0; /* this is used for mandatory options... */
547 /* need to put result and our preference list */
548 rlen = 1 + opt->dccpop_len;
549 rpref = kmalloc(rlen, GFP_ATOMIC);
554 memcpy(&rpref[1], opt->dccpop_val, opt->dccpop_len);
556 /* put it in the "confirm queue" */
557 if (opt->dccpop_sc == NULL) {
558 opt->dccpop_sc = kmalloc(sizeof(*opt->dccpop_sc), GFP_ATOMIC);
559 if (opt->dccpop_sc == NULL) {
564 /* recycle the confirm slot */
565 BUG_ON(opt->dccpop_sc->dccpoc_val == NULL);
566 kfree(opt->dccpop_sc->dccpoc_val);
567 dccp_pr_debug("recycling confirm slot\n");
569 memset(opt->dccpop_sc, 0, sizeof(*opt->dccpop_sc));
571 opt->dccpop_sc->dccpoc_val = rpref;
572 opt->dccpop_sc->dccpoc_len = rlen;
574 /* update the option on our side [we are about to send the confirm] */
575 rc = dccp_feat_update(sk, opt->dccpop_type, opt->dccpop_feat, *res);
577 kfree(opt->dccpop_sc->dccpoc_val);
578 kfree(opt->dccpop_sc);
579 opt->dccpop_sc = NULL;
583 dccp_pr_debug("Will confirm %d\n", *rpref);
585 /* say we want to change to X but we just got a confirm X, suppress our
588 if (!opt->dccpop_conf) {
589 if (*opt->dccpop_val == *res)
590 opt->dccpop_conf = 1;
591 dccp_pr_debug("won't ask for change of same feature\n");
594 return agree ? 0 : DCCP_FEAT_SP_NOAGREE; /* used for mandatory opts */
597 static int dccp_feat_sp(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
599 struct dccp_minisock *dmsk = dccp_msk(sk);
600 struct dccp_opt_pend *opt;
605 * We received a CHANGE. We gotta match it against our own preference
606 * list. If we got a CHANGE_R it means it's a change for us, so we need
607 * to compare our CHANGE_L list.
609 if (type == DCCPO_CHANGE_L)
614 /* find our preference list for this feature */
615 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
616 if (opt->dccpop_type != t || opt->dccpop_feat != feature)
619 /* find the winner from the two preference lists */
620 rc = dccp_feat_reconcile(sk, opt, val, len);
624 /* We didn't deal with the change. This can happen if we have no
625 * preference list for the feature. In fact, it just shouldn't
626 * happen---if we understand a feature, we should have a preference list
627 * with at least the default value.
634 static int dccp_feat_nn(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
636 struct dccp_opt_pend *opt;
637 struct dccp_minisock *dmsk = dccp_msk(sk);
641 /* NN features must be Change L (sec. 6.3.2) */
642 if (type != DCCPO_CHANGE_L) {
643 dccp_pr_debug("received %s for NN feature %d\n",
644 dccp_feat_typename(type), feature);
648 /* XXX sanity check opt val */
650 /* copy option so we can confirm it */
651 opt = kzalloc(sizeof(*opt), GFP_ATOMIC);
655 copy = kmemdup(val, len, GFP_ATOMIC);
661 opt->dccpop_type = DCCPO_CONFIRM_R; /* NN can only confirm R */
662 opt->dccpop_feat = feature;
663 opt->dccpop_val = copy;
664 opt->dccpop_len = len;
667 rc = dccp_feat_update(sk, type, feature, *val);
669 kfree(opt->dccpop_val);
674 dccp_feat_debug(type, feature, *copy);
676 list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf);
681 static void dccp_feat_empty_confirm(struct dccp_minisock *dmsk,
684 /* XXX check if other confirms for that are queued and recycle slot */
685 struct dccp_opt_pend *opt = kzalloc(sizeof(*opt), GFP_ATOMIC);
688 /* XXX what do we do? Ignoring should be fine. It's a change
696 opt->dccpop_type = DCCPO_CONFIRM_R;
699 opt->dccpop_type = DCCPO_CONFIRM_L;
702 DCCP_WARN("invalid type %d\n", type);
706 opt->dccpop_feat = feature;
707 opt->dccpop_val = NULL;
711 dccp_pr_debug("Empty %s(%d)\n", dccp_feat_typename(type), feature);
713 list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf);
716 static void dccp_feat_flush_confirm(struct sock *sk)
718 struct dccp_minisock *dmsk = dccp_msk(sk);
719 /* Check if there is anything to confirm in the first place */
720 int yes = !list_empty(&dmsk->dccpms_conf);
723 struct dccp_opt_pend *opt;
725 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
726 if (opt->dccpop_conf) {
736 /* OK there is something to confirm... */
737 /* XXX check if packet is in flight? Send delayed ack?? */
738 if (sk->sk_state == DCCP_OPEN)
742 int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
746 /* Ignore Change requests other than during connection setup */
747 if (sk->sk_state != DCCP_LISTEN && sk->sk_state != DCCP_REQUESTING)
749 dccp_feat_debug(type, feature, *val);
751 /* figure out if it's SP or NN feature */
753 /* deal with SP features */
755 rc = dccp_feat_sp(sk, type, feature, val, len);
758 /* deal with NN features */
759 case DCCPF_ACK_RATIO:
760 rc = dccp_feat_nn(sk, type, feature, val, len);
763 /* XXX implement other features */
765 dccp_pr_debug("UNIMPLEMENTED: not handling %s(%d, ...)\n",
766 dccp_feat_typename(type), feature);
771 /* check if there were problems changing features */
773 /* If we don't agree on SP, we sent a confirm for old value.
774 * However we propagate rc to caller in case option was
777 if (rc != DCCP_FEAT_SP_NOAGREE)
778 dccp_feat_empty_confirm(dccp_msk(sk), type, feature);
781 /* generate the confirm [if required] */
782 dccp_feat_flush_confirm(sk);
787 EXPORT_SYMBOL_GPL(dccp_feat_change_recv);
789 int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature,
793 struct dccp_opt_pend *opt;
794 struct dccp_minisock *dmsk = dccp_msk(sk);
796 int all_confirmed = 1;
798 /* Ignore Confirm options other than during connection setup */
799 if (sk->sk_state != DCCP_LISTEN && sk->sk_state != DCCP_REQUESTING)
801 dccp_feat_debug(type, feature, *val);
803 /* locate our change request */
805 case DCCPO_CONFIRM_L: t = DCCPO_CHANGE_R; break;
806 case DCCPO_CONFIRM_R: t = DCCPO_CHANGE_L; break;
807 default: DCCP_WARN("invalid type %d\n", type);
811 /* XXX sanity check feature value */
813 list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
814 if (!opt->dccpop_conf && opt->dccpop_type == t &&
815 opt->dccpop_feat == feature) {
817 dccp_pr_debug("feature %d found\n", opt->dccpop_feat);
819 /* XXX do sanity check */
821 opt->dccpop_conf = 1;
823 /* We got a confirmation---change the option */
824 dccp_feat_update(sk, opt->dccpop_type,
825 opt->dccpop_feat, *val);
827 /* XXX check the return value of dccp_feat_update */
831 if (!opt->dccpop_conf)
836 dccp_pr_debug("%s(%d, ...) never requested\n",
837 dccp_feat_typename(type), feature);
841 EXPORT_SYMBOL_GPL(dccp_feat_confirm_recv);
843 void dccp_feat_clean(struct dccp_minisock *dmsk)
845 struct dccp_opt_pend *opt, *next;
847 list_for_each_entry_safe(opt, next, &dmsk->dccpms_pending,
849 BUG_ON(opt->dccpop_val == NULL);
850 kfree(opt->dccpop_val);
852 if (opt->dccpop_sc != NULL) {
853 BUG_ON(opt->dccpop_sc->dccpoc_val == NULL);
854 kfree(opt->dccpop_sc->dccpoc_val);
855 kfree(opt->dccpop_sc);
860 INIT_LIST_HEAD(&dmsk->dccpms_pending);
862 list_for_each_entry_safe(opt, next, &dmsk->dccpms_conf, dccpop_node) {
864 if (opt->dccpop_val != NULL)
865 kfree(opt->dccpop_val);
868 INIT_LIST_HEAD(&dmsk->dccpms_conf);
871 EXPORT_SYMBOL_GPL(dccp_feat_clean);
873 /* this is to be called only when a listening sock creates its child. It is
874 * assumed by the function---the confirm is not duplicated, but rather it is
877 int dccp_feat_clone(struct sock *oldsk, struct sock *newsk)
879 struct dccp_minisock *olddmsk = dccp_msk(oldsk);
880 struct dccp_minisock *newdmsk = dccp_msk(newsk);
881 struct dccp_opt_pend *opt;
884 INIT_LIST_HEAD(&newdmsk->dccpms_pending);
885 INIT_LIST_HEAD(&newdmsk->dccpms_conf);
887 list_for_each_entry(opt, &olddmsk->dccpms_pending, dccpop_node) {
888 struct dccp_opt_pend *newopt;
889 /* copy the value of the option */
890 u8 *val = kmemdup(opt->dccpop_val, opt->dccpop_len, GFP_ATOMIC);
895 newopt = kmemdup(opt, sizeof(*newopt), GFP_ATOMIC);
896 if (newopt == NULL) {
901 /* insert the option */
902 newopt->dccpop_val = val;
903 list_add_tail(&newopt->dccpop_node, &newdmsk->dccpms_pending);
905 /* XXX what happens with backlogs and multiple connections at
908 /* the master socket no longer needs to worry about confirms */
909 opt->dccpop_sc = NULL; /* it's not a memleak---new socket has it */
911 /* reset state for a new socket */
912 opt->dccpop_conf = 0;
915 /* XXX not doing anything about the conf queue */
921 dccp_feat_clean(newdmsk);
926 EXPORT_SYMBOL_GPL(dccp_feat_clone);
928 int dccp_feat_init(struct sock *sk)
930 struct dccp_sock *dp = dccp_sk(sk);
931 struct dccp_minisock *dmsk = dccp_msk(sk);
934 INIT_LIST_HEAD(&dmsk->dccpms_pending); /* XXX no longer used */
935 INIT_LIST_HEAD(&dmsk->dccpms_conf); /* XXX no longer used */
938 rc = __feat_register_sp(&dp->dccps_featneg, DCCPF_CCID, 1, 0,
939 &dmsk->dccpms_tx_ccid, 1);
944 rc = __feat_register_sp(&dp->dccps_featneg, DCCPF_CCID, 0, 0,
945 &dmsk->dccpms_rx_ccid, 1);
950 rc = __feat_register_nn(&dp->dccps_featneg, DCCPF_ACK_RATIO, 0,
951 dmsk->dccpms_ack_ratio);
956 EXPORT_SYMBOL_GPL(dccp_feat_init);
958 #ifdef CONFIG_IP_DCCP_DEBUG
959 const char *dccp_feat_typename(const u8 type)
962 case DCCPO_CHANGE_L: return("ChangeL");
963 case DCCPO_CONFIRM_L: return("ConfirmL");
964 case DCCPO_CHANGE_R: return("ChangeR");
965 case DCCPO_CONFIRM_R: return("ConfirmR");
966 /* the following case must not appear in feature negotation */
967 default: dccp_pr_debug("unknown type %d [BUG!]\n", type);
972 EXPORT_SYMBOL_GPL(dccp_feat_typename);
974 const char *dccp_feat_name(const u8 feat)
976 static const char *feature_names[] = {
977 [DCCPF_RESERVED] = "Reserved",
978 [DCCPF_CCID] = "CCID",
979 [DCCPF_SHORT_SEQNOS] = "Allow Short Seqnos",
980 [DCCPF_SEQUENCE_WINDOW] = "Sequence Window",
981 [DCCPF_ECN_INCAPABLE] = "ECN Incapable",
982 [DCCPF_ACK_RATIO] = "Ack Ratio",
983 [DCCPF_SEND_ACK_VECTOR] = "Send ACK Vector",
984 [DCCPF_SEND_NDP_COUNT] = "Send NDP Count",
985 [DCCPF_MIN_CSUM_COVER] = "Min. Csum Coverage",
986 [DCCPF_DATA_CHECKSUM] = "Send Data Checksum",
988 if (feat > DCCPF_DATA_CHECKSUM && feat < DCCPF_MIN_CCID_SPECIFIC)
989 return feature_names[DCCPF_RESERVED];
991 if (feat == DCCPF_SEND_LEV_RATE)
992 return "Send Loss Event Rate";
993 if (feat >= DCCPF_MIN_CCID_SPECIFIC)
994 return "CCID-specific";
996 return feature_names[feat];
999 EXPORT_SYMBOL_GPL(dccp_feat_name);
1000 #endif /* CONFIG_IP_DCCP_DEBUG */