4 * Feature negotiation for the DCCP protocol (RFC 4340, section 6)
6 * Copyright (c) 2008 The University of Aberdeen, Scotland, UK
7 * Copyright (c) 2008 Gerrit Renker <gerrit@erg.abdn.ac.uk>
8 * Rewrote from scratch, some bits from earlier code by
9 * Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
14 * o Feature negotiation is coordinated with connection setup (as in TCP), wild
15 * changes of parameters of an established connection are not supported.
16 * o Changing NN values (Ack Ratio only) is supported in state OPEN/PARTOPEN.
17 * o All currently known SP features have 1-byte quantities. If in the future
18 * extensions of RFCs 4340..42 define features with item lengths larger than
19 * one byte, a feature-specific extension of the code will be required.
21 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU General Public License
23 * as published by the Free Software Foundation; either version
24 * 2 of the License, or (at your option) any later version.
26 #include <linux/module.h>
30 /* feature-specific sysctls - initialised to the defaults from RFC 4340, 6.4 */
31 unsigned long sysctl_dccp_sequence_window __read_mostly
= 100;
32 int sysctl_dccp_rx_ccid __read_mostly
= 2,
33 sysctl_dccp_tx_ccid __read_mostly
= 2;
36 * Feature activation handlers.
38 * These all use an u64 argument, to provide enough room for NN/SP features. At
39 * this stage the negotiated values have been checked to be within their range.
41 static int dccp_hdlr_ccid(struct sock
*sk
, u64 ccid
, bool rx
)
43 struct dccp_sock
*dp
= dccp_sk(sk
);
44 struct ccid
*new_ccid
= ccid_new(ccid
, sk
, rx
, gfp_any());
50 ccid_hc_rx_delete(dp
->dccps_hc_rx_ccid
, sk
);
51 dp
->dccps_hc_rx_ccid
= new_ccid
;
53 ccid_hc_tx_delete(dp
->dccps_hc_tx_ccid
, sk
);
54 dp
->dccps_hc_tx_ccid
= new_ccid
;
59 static int dccp_hdlr_seq_win(struct sock
*sk
, u64 seq_win
, bool rx
)
61 struct dccp_sock
*dp
= dccp_sk(sk
);
64 dp
->dccps_r_seq_win
= seq_win
;
65 /* propagate changes to update SWL/SWH */
66 dccp_update_gsr(sk
, dp
->dccps_gsr
);
68 dp
->dccps_l_seq_win
= seq_win
;
69 /* propagate changes to update AWL */
70 dccp_update_gss(sk
, dp
->dccps_gss
);
75 static int dccp_hdlr_ack_ratio(struct sock
*sk
, u64 ratio
, bool rx
)
78 dccp_sk(sk
)->dccps_r_ack_ratio
= ratio
;
80 dccp_sk(sk
)->dccps_l_ack_ratio
= ratio
;
84 static int dccp_hdlr_ackvec(struct sock
*sk
, u64 enable
, bool rx
)
86 struct dccp_sock
*dp
= dccp_sk(sk
);
89 if (enable
&& dp
->dccps_hc_rx_ackvec
== NULL
) {
90 dp
->dccps_hc_rx_ackvec
= dccp_ackvec_alloc(gfp_any());
91 if (dp
->dccps_hc_rx_ackvec
== NULL
)
94 dccp_ackvec_free(dp
->dccps_hc_rx_ackvec
);
95 dp
->dccps_hc_rx_ackvec
= NULL
;
101 static int dccp_hdlr_ndp(struct sock
*sk
, u64 enable
, bool rx
)
104 dccp_sk(sk
)->dccps_send_ndp_count
= (enable
> 0);
109 * Minimum Checksum Coverage is located at the RX side (9.2.1). This means that
110 * `rx' holds when the sending peer informs about his partial coverage via a
111 * ChangeR() option. In the other case, we are the sender and the receiver
112 * announces its coverage via ChangeL() options. The policy here is to honour
113 * such communication by enabling the corresponding partial coverage - but only
114 * if it has not been set manually before; the warning here means that all
115 * packets will be dropped.
117 static int dccp_hdlr_min_cscov(struct sock
*sk
, u64 cscov
, bool rx
)
119 struct dccp_sock
*dp
= dccp_sk(sk
);
122 dp
->dccps_pcrlen
= cscov
;
124 if (dp
->dccps_pcslen
== 0)
125 dp
->dccps_pcslen
= cscov
;
126 else if (cscov
> dp
->dccps_pcslen
)
127 DCCP_WARN("CsCov %u too small, peer requires >= %u\n",
128 dp
->dccps_pcslen
, (u8
)cscov
);
133 static const struct {
134 u8 feat_num
; /* DCCPF_xxx */
135 enum dccp_feat_type rxtx
; /* RX or TX */
136 enum dccp_feat_type reconciliation
; /* SP or NN */
137 u8 default_value
; /* as in 6.4 */
138 int (*activation_hdlr
)(struct sock
*sk
, u64 val
, bool rx
);
140 * Lookup table for location and type of features (from RFC 4340/4342)
141 * +--------------------------+----+-----+----+----+---------+-----------+
142 * | Feature | Location | Reconc. | Initial | Section |
143 * | | RX | TX | SP | NN | Value | Reference |
144 * +--------------------------+----+-----+----+----+---------+-----------+
145 * | DCCPF_CCID | | X | X | | 2 | 10 |
146 * | DCCPF_SHORT_SEQNOS | | X | X | | 0 | 7.6.1 |
147 * | DCCPF_SEQUENCE_WINDOW | | X | | X | 100 | 7.5.2 |
148 * | DCCPF_ECN_INCAPABLE | X | | X | | 0 | 12.1 |
149 * | DCCPF_ACK_RATIO | | X | | X | 2 | 11.3 |
150 * | DCCPF_SEND_ACK_VECTOR | X | | X | | 0 | 11.5 |
151 * | DCCPF_SEND_NDP_COUNT | | X | X | | 0 | 7.7.2 |
152 * | DCCPF_MIN_CSUM_COVER | X | | X | | 0 | 9.2.1 |
153 * | DCCPF_DATA_CHECKSUM | X | | X | | 0 | 9.3.1 |
154 * | DCCPF_SEND_LEV_RATE | X | | X | | 0 | 4342/8.4 |
155 * +--------------------------+----+-----+----+----+---------+-----------+
157 } dccp_feat_table
[] = {
158 { DCCPF_CCID
, FEAT_AT_TX
, FEAT_SP
, 2, dccp_hdlr_ccid
},
159 { DCCPF_SHORT_SEQNOS
, FEAT_AT_TX
, FEAT_SP
, 0, NULL
},
160 { DCCPF_SEQUENCE_WINDOW
, FEAT_AT_TX
, FEAT_NN
, 100, dccp_hdlr_seq_win
},
161 { DCCPF_ECN_INCAPABLE
, FEAT_AT_RX
, FEAT_SP
, 0, NULL
},
162 { DCCPF_ACK_RATIO
, FEAT_AT_TX
, FEAT_NN
, 2, dccp_hdlr_ack_ratio
},
163 { DCCPF_SEND_ACK_VECTOR
, FEAT_AT_RX
, FEAT_SP
, 0, dccp_hdlr_ackvec
},
164 { DCCPF_SEND_NDP_COUNT
, FEAT_AT_TX
, FEAT_SP
, 0, dccp_hdlr_ndp
},
165 { DCCPF_MIN_CSUM_COVER
, FEAT_AT_RX
, FEAT_SP
, 0, dccp_hdlr_min_cscov
},
166 { DCCPF_DATA_CHECKSUM
, FEAT_AT_RX
, FEAT_SP
, 0, NULL
},
167 { DCCPF_SEND_LEV_RATE
, FEAT_AT_RX
, FEAT_SP
, 0, NULL
},
169 #define DCCP_FEAT_SUPPORTED_MAX ARRAY_SIZE(dccp_feat_table)
172 * dccp_feat_index - Hash function to map feature number into array position
173 * Returns consecutive array index or -1 if the feature is not understood.
175 static int dccp_feat_index(u8 feat_num
)
177 /* The first 9 entries are occupied by the types from RFC 4340, 6.4 */
178 if (feat_num
> DCCPF_RESERVED
&& feat_num
<= DCCPF_DATA_CHECKSUM
)
182 * Other features: add cases for new feature types here after adding
183 * them to the above table.
186 case DCCPF_SEND_LEV_RATE
:
187 return DCCP_FEAT_SUPPORTED_MAX
- 1;
192 static u8
dccp_feat_type(u8 feat_num
)
194 int idx
= dccp_feat_index(feat_num
);
198 return dccp_feat_table
[idx
].reconciliation
;
201 static int dccp_feat_default_value(u8 feat_num
)
203 int idx
= dccp_feat_index(feat_num
);
205 return idx
< 0 ? : dccp_feat_table
[idx
].default_value
;
209 * Debugging and verbose-printing section
211 static const char *dccp_feat_fname(const u8 feat
)
213 static const char *feature_names
[] = {
214 [DCCPF_RESERVED
] = "Reserved",
215 [DCCPF_CCID
] = "CCID",
216 [DCCPF_SHORT_SEQNOS
] = "Allow Short Seqnos",
217 [DCCPF_SEQUENCE_WINDOW
] = "Sequence Window",
218 [DCCPF_ECN_INCAPABLE
] = "ECN Incapable",
219 [DCCPF_ACK_RATIO
] = "Ack Ratio",
220 [DCCPF_SEND_ACK_VECTOR
] = "Send ACK Vector",
221 [DCCPF_SEND_NDP_COUNT
] = "Send NDP Count",
222 [DCCPF_MIN_CSUM_COVER
] = "Min. Csum Coverage",
223 [DCCPF_DATA_CHECKSUM
] = "Send Data Checksum",
225 if (feat
> DCCPF_DATA_CHECKSUM
&& feat
< DCCPF_MIN_CCID_SPECIFIC
)
226 return feature_names
[DCCPF_RESERVED
];
228 if (feat
== DCCPF_SEND_LEV_RATE
)
229 return "Send Loss Event Rate";
230 if (feat
>= DCCPF_MIN_CCID_SPECIFIC
)
231 return "CCID-specific";
233 return feature_names
[feat
];
236 static const char *dccp_feat_sname
[] = { "DEFAULT", "INITIALISING", "CHANGING",
237 "UNSTABLE", "STABLE" };
239 #ifdef CONFIG_IP_DCCP_DEBUG
240 static const char *dccp_feat_oname(const u8 opt
)
243 case DCCPO_CHANGE_L
: return "Change_L";
244 case DCCPO_CONFIRM_L
: return "Confirm_L";
245 case DCCPO_CHANGE_R
: return "Change_R";
246 case DCCPO_CONFIRM_R
: return "Confirm_R";
251 static void dccp_feat_printval(u8 feat_num
, dccp_feat_val
const *val
)
253 u8 i
, type
= dccp_feat_type(feat_num
);
255 if (val
== NULL
|| (type
== FEAT_SP
&& val
->sp
.vec
== NULL
))
256 dccp_pr_debug_cat("(NULL)");
257 else if (type
== FEAT_SP
)
258 for (i
= 0; i
< val
->sp
.len
; i
++)
259 dccp_pr_debug_cat("%s%u", i
? " " : "", val
->sp
.vec
[i
]);
260 else if (type
== FEAT_NN
)
261 dccp_pr_debug_cat("%llu", (unsigned long long)val
->nn
);
263 dccp_pr_debug_cat("unknown type %u", type
);
266 static void dccp_feat_printvals(u8 feat_num
, u8
*list
, u8 len
)
268 u8 type
= dccp_feat_type(feat_num
);
269 dccp_feat_val fval
= { .sp
.vec
= list
, .sp
.len
= len
};
272 fval
.nn
= dccp_decode_value_var(list
, len
);
273 dccp_feat_printval(feat_num
, &fval
);
276 static void dccp_feat_print_entry(struct dccp_feat_entry
const *entry
)
278 dccp_debug(" * %s %s = ", entry
->is_local
? "local" : "remote",
279 dccp_feat_fname(entry
->feat_num
));
280 dccp_feat_printval(entry
->feat_num
, &entry
->val
);
281 dccp_pr_debug_cat(", state=%s %s\n", dccp_feat_sname
[entry
->state
],
282 entry
->needs_confirm
? "(Confirm pending)" : "");
285 #define dccp_feat_print_opt(opt, feat, val, len, mandatory) do { \
286 dccp_pr_debug("%s(%s, ", dccp_feat_oname(opt), dccp_feat_fname(feat));\
287 dccp_feat_printvals(feat, val, len); \
288 dccp_pr_debug_cat(") %s\n", mandatory ? "!" : ""); } while (0)
290 #define dccp_feat_print_fnlist(fn_list) { \
291 const struct dccp_feat_entry *___entry; \
293 dccp_pr_debug("List Dump:\n"); \
294 list_for_each_entry(___entry, fn_list, node) \
295 dccp_feat_print_entry(___entry); \
297 #else /* ! CONFIG_IP_DCCP_DEBUG */
298 #define dccp_feat_print_opt(opt, feat, val, len, mandatory)
299 #define dccp_feat_print_fnlist(fn_list)
302 static int __dccp_feat_activate(struct sock
*sk
, const int idx
,
303 const bool is_local
, dccp_feat_val
const *fval
)
308 if (idx
< 0 || idx
>= DCCP_FEAT_SUPPORTED_MAX
)
310 if (dccp_feat_table
[idx
].activation_hdlr
== NULL
)
314 val
= dccp_feat_table
[idx
].default_value
;
315 } else if (dccp_feat_table
[idx
].reconciliation
== FEAT_SP
) {
316 if (fval
->sp
.vec
== NULL
) {
318 * This can happen when an empty Confirm is sent
319 * for an SP (i.e. known) feature. In this case
320 * we would be using the default anyway.
322 DCCP_CRIT("Feature #%d undefined: using default", idx
);
323 val
= dccp_feat_table
[idx
].default_value
;
325 val
= fval
->sp
.vec
[0];
331 /* Location is RX if this is a local-RX or remote-TX feature */
332 rx
= (is_local
== (dccp_feat_table
[idx
].rxtx
== FEAT_AT_RX
));
334 dccp_debug(" -> activating %s %s, %sval=%llu\n", rx
? "RX" : "TX",
335 dccp_feat_fname(dccp_feat_table
[idx
].feat_num
),
336 fval
? "" : "default ", (unsigned long long)val
);
338 return dccp_feat_table
[idx
].activation_hdlr(sk
, val
, rx
);
342 * dccp_feat_activate - Activate feature value on socket
343 * @sk: fully connected DCCP socket (after handshake is complete)
344 * @feat_num: feature to activate, one of %dccp_feature_numbers
345 * @local: whether local (1) or remote (0) @feat_num is meant
346 * @fval: the value (SP or NN) to activate, or NULL to use the default value
347 * For general use this function is preferable over __dccp_feat_activate().
349 static int dccp_feat_activate(struct sock
*sk
, u8 feat_num
, bool local
,
350 dccp_feat_val
const *fval
)
352 return __dccp_feat_activate(sk
, dccp_feat_index(feat_num
), local
, fval
);
355 /* Test for "Req'd" feature (RFC 4340, 6.4) */
356 static inline int dccp_feat_must_be_understood(u8 feat_num
)
358 return feat_num
== DCCPF_CCID
|| feat_num
== DCCPF_SHORT_SEQNOS
||
359 feat_num
== DCCPF_SEQUENCE_WINDOW
;
362 /* copy constructor, fval must not already contain allocated memory */
363 static int dccp_feat_clone_sp_val(dccp_feat_val
*fval
, u8
const *val
, u8 len
)
366 if (fval
->sp
.len
> 0) {
367 fval
->sp
.vec
= kmemdup(val
, len
, gfp_any());
368 if (fval
->sp
.vec
== NULL
) {
376 static void dccp_feat_val_destructor(u8 feat_num
, dccp_feat_val
*val
)
378 if (unlikely(val
== NULL
))
380 if (dccp_feat_type(feat_num
) == FEAT_SP
)
382 memset(val
, 0, sizeof(*val
));
385 static struct dccp_feat_entry
*
386 dccp_feat_clone_entry(struct dccp_feat_entry
const *original
)
388 struct dccp_feat_entry
*new;
389 u8 type
= dccp_feat_type(original
->feat_num
);
391 if (type
== FEAT_UNKNOWN
)
394 new = kmemdup(original
, sizeof(struct dccp_feat_entry
), gfp_any());
398 if (type
== FEAT_SP
&& dccp_feat_clone_sp_val(&new->val
,
399 original
->val
.sp
.vec
,
400 original
->val
.sp
.len
)) {
407 static void dccp_feat_entry_destructor(struct dccp_feat_entry
*entry
)
410 dccp_feat_val_destructor(entry
->feat_num
, &entry
->val
);
416 * List management functions
418 * Feature negotiation lists rely on and maintain the following invariants:
419 * - each feat_num in the list is known, i.e. we know its type and default value
420 * - each feat_num/is_local combination is unique (old entries are overwritten)
421 * - SP values are always freshly allocated
422 * - list is sorted in increasing order of feature number (faster lookup)
424 static struct dccp_feat_entry
*dccp_feat_list_lookup(struct list_head
*fn_list
,
425 u8 feat_num
, bool is_local
)
427 struct dccp_feat_entry
*entry
;
429 list_for_each_entry(entry
, fn_list
, node
)
430 if (entry
->feat_num
== feat_num
&& entry
->is_local
== is_local
)
432 else if (entry
->feat_num
> feat_num
)
438 * dccp_feat_entry_new - Central list update routine (called by all others)
439 * @head: list to add to
440 * @feat: feature number
441 * @local: whether the local (1) or remote feature with number @feat is meant
442 * This is the only constructor and serves to ensure the above invariants.
444 static struct dccp_feat_entry
*
445 dccp_feat_entry_new(struct list_head
*head
, u8 feat
, bool local
)
447 struct dccp_feat_entry
*entry
;
449 list_for_each_entry(entry
, head
, node
)
450 if (entry
->feat_num
== feat
&& entry
->is_local
== local
) {
451 dccp_feat_val_destructor(entry
->feat_num
, &entry
->val
);
453 } else if (entry
->feat_num
> feat
) {
458 entry
= kmalloc(sizeof(*entry
), gfp_any());
460 entry
->feat_num
= feat
;
461 entry
->is_local
= local
;
462 list_add_tail(&entry
->node
, head
);
468 * dccp_feat_push_change - Add/overwrite a Change option in the list
469 * @fn_list: feature-negotiation list to update
470 * @feat: one of %dccp_feature_numbers
471 * @local: whether local (1) or remote (0) @feat_num is meant
472 * @needs_mandatory: whether to use Mandatory feature negotiation options
473 * @fval: pointer to NN/SP value to be inserted (will be copied)
475 static int dccp_feat_push_change(struct list_head
*fn_list
, u8 feat
, u8 local
,
476 u8 mandatory
, dccp_feat_val
*fval
)
478 struct dccp_feat_entry
*new = dccp_feat_entry_new(fn_list
, feat
, local
);
483 new->feat_num
= feat
;
484 new->is_local
= local
;
485 new->state
= FEAT_INITIALISING
;
486 new->needs_confirm
= 0;
487 new->empty_confirm
= 0;
489 new->needs_mandatory
= mandatory
;
495 * dccp_feat_push_confirm - Add a Confirm entry to the FN list
496 * @fn_list: feature-negotiation list to add to
497 * @feat: one of %dccp_feature_numbers
498 * @local: whether local (1) or remote (0) @feat_num is being confirmed
499 * @fval: pointer to NN/SP value to be inserted or NULL
500 * Returns 0 on success, a Reset code for further processing otherwise.
502 static int dccp_feat_push_confirm(struct list_head
*fn_list
, u8 feat
, u8 local
,
505 struct dccp_feat_entry
*new = dccp_feat_entry_new(fn_list
, feat
, local
);
508 return DCCP_RESET_CODE_TOO_BUSY
;
510 new->feat_num
= feat
;
511 new->is_local
= local
;
512 new->state
= FEAT_STABLE
; /* transition in 6.6.2 */
513 new->needs_confirm
= 1;
514 new->empty_confirm
= (fval
== NULL
);
515 new->val
.nn
= 0; /* zeroes the whole structure */
516 if (!new->empty_confirm
)
518 new->needs_mandatory
= 0;
523 static int dccp_push_empty_confirm(struct list_head
*fn_list
, u8 feat
, u8 local
)
525 return dccp_feat_push_confirm(fn_list
, feat
, local
, NULL
);
528 static inline void dccp_feat_list_pop(struct dccp_feat_entry
*entry
)
530 list_del(&entry
->node
);
531 dccp_feat_entry_destructor(entry
);
534 void dccp_feat_list_purge(struct list_head
*fn_list
)
536 struct dccp_feat_entry
*entry
, *next
;
538 list_for_each_entry_safe(entry
, next
, fn_list
, node
)
539 dccp_feat_entry_destructor(entry
);
540 INIT_LIST_HEAD(fn_list
);
542 EXPORT_SYMBOL_GPL(dccp_feat_list_purge
);
544 /* generate @to as full clone of @from - @to must not contain any nodes */
545 int dccp_feat_clone_list(struct list_head
const *from
, struct list_head
*to
)
547 struct dccp_feat_entry
*entry
, *new;
550 list_for_each_entry(entry
, from
, node
) {
551 new = dccp_feat_clone_entry(entry
);
554 list_add_tail(&new->node
, to
);
559 dccp_feat_list_purge(to
);
564 * dccp_feat_valid_nn_length - Enforce length constraints on NN options
565 * Length is between 0 and %DCCP_OPTVAL_MAXLEN. Used for outgoing packets only,
566 * incoming options are accepted as long as their values are valid.
568 static u8
dccp_feat_valid_nn_length(u8 feat_num
)
570 if (feat_num
== DCCPF_ACK_RATIO
) /* RFC 4340, 11.3 and 6.6.8 */
572 if (feat_num
== DCCPF_SEQUENCE_WINDOW
) /* RFC 4340, 7.5.2 and 6.5 */
577 static u8
dccp_feat_is_valid_nn_val(u8 feat_num
, u64 val
)
580 case DCCPF_ACK_RATIO
:
581 return val
<= DCCPF_ACK_RATIO_MAX
;
582 case DCCPF_SEQUENCE_WINDOW
:
583 return val
>= DCCPF_SEQ_WMIN
&& val
<= DCCPF_SEQ_WMAX
;
585 return 0; /* feature unknown - so we can't tell */
588 /* check that SP values are within the ranges defined in RFC 4340 */
589 static u8
dccp_feat_is_valid_sp_val(u8 feat_num
, u8 val
)
593 return val
== DCCPC_CCID2
|| val
== DCCPC_CCID3
;
594 /* Type-check Boolean feature values: */
595 case DCCPF_SHORT_SEQNOS
:
596 case DCCPF_ECN_INCAPABLE
:
597 case DCCPF_SEND_ACK_VECTOR
:
598 case DCCPF_SEND_NDP_COUNT
:
599 case DCCPF_DATA_CHECKSUM
:
600 case DCCPF_SEND_LEV_RATE
:
602 case DCCPF_MIN_CSUM_COVER
:
605 return 0; /* feature unknown */
608 static u8
dccp_feat_sp_list_ok(u8 feat_num
, u8
const *sp_list
, u8 sp_len
)
610 if (sp_list
== NULL
|| sp_len
< 1)
613 if (!dccp_feat_is_valid_sp_val(feat_num
, *sp_list
++))
619 * dccp_feat_insert_opts - Generate FN options from current list state
620 * @skb: next sk_buff to be sent to the peer
621 * @dp: for client during handshake and general negotiation
622 * @dreq: used by the server only (all Changes/Confirms in LISTEN/RESPOND)
624 int dccp_feat_insert_opts(struct dccp_sock
*dp
, struct dccp_request_sock
*dreq
,
627 struct list_head
*fn
= dreq
? &dreq
->dreq_featneg
: &dp
->dccps_featneg
;
628 struct dccp_feat_entry
*pos
, *next
;
629 u8 opt
, type
, len
, *ptr
, nn_in_nbo
[DCCP_OPTVAL_MAXLEN
];
632 /* put entries into @skb in the order they appear in the list */
633 list_for_each_entry_safe_reverse(pos
, next
, fn
, node
) {
634 opt
= dccp_feat_genopt(pos
);
635 type
= dccp_feat_type(pos
->feat_num
);
638 if (pos
->empty_confirm
) {
642 if (type
== FEAT_SP
) {
643 len
= pos
->val
.sp
.len
;
644 ptr
= pos
->val
.sp
.vec
;
645 rpt
= pos
->needs_confirm
;
646 } else if (type
== FEAT_NN
) {
647 len
= dccp_feat_valid_nn_length(pos
->feat_num
);
649 dccp_encode_value_var(pos
->val
.nn
, ptr
, len
);
651 DCCP_BUG("unknown feature %u", pos
->feat_num
);
655 dccp_feat_print_opt(opt
, pos
->feat_num
, ptr
, len
, 0);
657 if (dccp_insert_fn_opt(skb
, opt
, pos
->feat_num
, ptr
, len
, rpt
))
659 if (pos
->needs_mandatory
&& dccp_insert_option_mandatory(skb
))
662 * Enter CHANGING after transmitting the Change option (6.6.2).
664 if (pos
->state
== FEAT_INITIALISING
)
665 pos
->state
= FEAT_CHANGING
;
671 * __feat_register_nn - Register new NN value on socket
672 * @fn: feature-negotiation list to register with
673 * @feat: an NN feature from %dccp_feature_numbers
674 * @mandatory: use Mandatory option if 1
675 * @nn_val: value to register (restricted to 4 bytes)
676 * Note that NN features are local by definition (RFC 4340, 6.3.2).
678 static int __feat_register_nn(struct list_head
*fn
, u8 feat
,
679 u8 mandatory
, u64 nn_val
)
681 dccp_feat_val fval
= { .nn
= nn_val
};
683 if (dccp_feat_type(feat
) != FEAT_NN
||
684 !dccp_feat_is_valid_nn_val(feat
, nn_val
))
687 /* Don't bother with default values, they will be activated anyway. */
688 if (nn_val
- (u64
)dccp_feat_default_value(feat
) == 0)
691 return dccp_feat_push_change(fn
, feat
, 1, mandatory
, &fval
);
695 * __feat_register_sp - Register new SP value/list on socket
696 * @fn: feature-negotiation list to register with
697 * @feat: an SP feature from %dccp_feature_numbers
698 * @is_local: whether the local (1) or the remote (0) @feat is meant
699 * @mandatory: use Mandatory option if 1
700 * @sp_val: SP value followed by optional preference list
701 * @sp_len: length of @sp_val in bytes
703 static int __feat_register_sp(struct list_head
*fn
, u8 feat
, u8 is_local
,
704 u8 mandatory
, u8
const *sp_val
, u8 sp_len
)
708 if (dccp_feat_type(feat
) != FEAT_SP
||
709 !dccp_feat_sp_list_ok(feat
, sp_val
, sp_len
))
712 /* Avoid negotiating alien CCIDs by only advertising supported ones */
713 if (feat
== DCCPF_CCID
&& !ccid_support_check(sp_val
, sp_len
))
716 if (dccp_feat_clone_sp_val(&fval
, sp_val
, sp_len
))
719 return dccp_feat_push_change(fn
, feat
, is_local
, mandatory
, &fval
);
723 * dccp_feat_register_sp - Register requests to change SP feature values
724 * @sk: client or listening socket
725 * @feat: one of %dccp_feature_numbers
726 * @is_local: whether the local (1) or remote (0) @feat is meant
727 * @list: array of preferred values, in descending order of preference
728 * @len: length of @list in bytes
730 int dccp_feat_register_sp(struct sock
*sk
, u8 feat
, u8 is_local
,
731 u8
const *list
, u8 len
)
732 { /* any changes must be registered before establishing the connection */
733 if (sk
->sk_state
!= DCCP_CLOSED
)
735 if (dccp_feat_type(feat
) != FEAT_SP
)
737 return __feat_register_sp(&dccp_sk(sk
)->dccps_featneg
, feat
, is_local
,
741 /* Analogous to dccp_feat_register_sp(), but for non-negotiable values */
742 int dccp_feat_register_nn(struct sock
*sk
, u8 feat
, u64 val
)
744 /* any changes must be registered before establishing the connection */
745 if (sk
->sk_state
!= DCCP_CLOSED
)
747 if (dccp_feat_type(feat
) != FEAT_NN
)
749 return __feat_register_nn(&dccp_sk(sk
)->dccps_featneg
, feat
, 0, val
);
753 * dccp_feat_signal_nn_change - Update NN values for an established connection
754 * @sk: DCCP socket of an established connection
755 * @feat: NN feature number from %dccp_feature_numbers
756 * @nn_val: the new value to use
757 * This function is used to communicate NN updates out-of-band. The difference
758 * to feature negotiation during connection setup is that values are activated
759 * immediately after validation, i.e. we don't wait for the Confirm: either the
760 * value is accepted by the peer (and then the waiting is futile), or it is not
761 * (Reset or empty Confirm). We don't accept empty Confirms - transmitted values
762 * are validated, and the peer "MUST accept any valid value" (RFC 4340, 6.3.2).
764 int dccp_feat_signal_nn_change(struct sock
*sk
, u8 feat
, u64 nn_val
)
766 struct list_head
*fn
= &dccp_sk(sk
)->dccps_featneg
;
767 dccp_feat_val fval
= { .nn
= nn_val
};
768 struct dccp_feat_entry
*entry
;
770 if (sk
->sk_state
!= DCCP_OPEN
&& sk
->sk_state
!= DCCP_PARTOPEN
)
773 if (dccp_feat_type(feat
) != FEAT_NN
||
774 !dccp_feat_is_valid_nn_val(feat
, nn_val
))
777 entry
= dccp_feat_list_lookup(fn
, feat
, 1);
779 dccp_pr_debug("Ignoring %llu, entry %llu exists in state %s\n",
780 (unsigned long long)nn_val
,
781 (unsigned long long)entry
->val
.nn
,
782 dccp_feat_sname
[entry
->state
]);
786 if (dccp_feat_activate(sk
, feat
, 1, &fval
))
789 inet_csk_schedule_ack(sk
);
790 return dccp_feat_push_change(fn
, feat
, 1, 0, &fval
);
792 EXPORT_SYMBOL_GPL(dccp_feat_signal_nn_change
);
795 * Tracking features whose value depend on the choice of CCID
797 * This is designed with an extension in mind so that a list walk could be done
798 * before activating any features. However, the existing framework was found to
799 * work satisfactorily up until now, the automatic verification is left open.
800 * When adding new CCIDs, add a corresponding dependency table here.
802 static const struct ccid_dependency
*dccp_feat_ccid_deps(u8 ccid
, bool is_local
)
804 static const struct ccid_dependency ccid2_dependencies
[2][2] = {
806 * CCID2 mandates Ack Vectors (RFC 4341, 4.): as CCID is a TX
807 * feature and Send Ack Vector is an RX feature, `is_local'
808 * needs to be reversed.
810 { /* Dependencies of the receiver-side (remote) CCID2 */
812 .dependent_feat
= DCCPF_SEND_ACK_VECTOR
,
814 .is_mandatory
= true,
819 { /* Dependencies of the sender-side (local) CCID2 */
821 .dependent_feat
= DCCPF_SEND_ACK_VECTOR
,
823 .is_mandatory
= true,
829 static const struct ccid_dependency ccid3_dependencies
[2][5] = {
831 * Dependencies of the receiver-side CCID3
833 { /* locally disable Ack Vectors */
834 .dependent_feat
= DCCPF_SEND_ACK_VECTOR
,
836 .is_mandatory
= false,
839 { /* see below why Send Loss Event Rate is on */
840 .dependent_feat
= DCCPF_SEND_LEV_RATE
,
842 .is_mandatory
= true,
845 { /* NDP Count is needed as per RFC 4342, 6.1.1 */
846 .dependent_feat
= DCCPF_SEND_NDP_COUNT
,
848 .is_mandatory
= true,
854 * CCID3 at the TX side: we request that the HC-receiver
855 * will not send Ack Vectors (they will be ignored, so
856 * Mandatory is not set); we enable Send Loss Event Rate
857 * (Mandatory since the implementation does not support
858 * the Loss Intervals option of RFC 4342, 8.6).
859 * The last two options are for peer's information only.
862 .dependent_feat
= DCCPF_SEND_ACK_VECTOR
,
864 .is_mandatory
= false,
868 .dependent_feat
= DCCPF_SEND_LEV_RATE
,
870 .is_mandatory
= true,
873 { /* this CCID does not support Ack Ratio */
874 .dependent_feat
= DCCPF_ACK_RATIO
,
876 .is_mandatory
= false,
879 { /* tell receiver we are sending NDP counts */
880 .dependent_feat
= DCCPF_SEND_NDP_COUNT
,
882 .is_mandatory
= false,
890 return ccid2_dependencies
[is_local
];
892 return ccid3_dependencies
[is_local
];
899 * dccp_feat_propagate_ccid - Resolve dependencies of features on choice of CCID
900 * @fn: feature-negotiation list to update
901 * @id: CCID number to track
902 * @is_local: whether TX CCID (1) or RX CCID (0) is meant
903 * This function needs to be called after registering all other features.
905 static int dccp_feat_propagate_ccid(struct list_head
*fn
, u8 id
, bool is_local
)
907 const struct ccid_dependency
*table
= dccp_feat_ccid_deps(id
, is_local
);
908 int i
, rc
= (table
== NULL
);
910 for (i
= 0; rc
== 0 && table
[i
].dependent_feat
!= DCCPF_RESERVED
; i
++)
911 if (dccp_feat_type(table
[i
].dependent_feat
) == FEAT_SP
)
912 rc
= __feat_register_sp(fn
, table
[i
].dependent_feat
,
914 table
[i
].is_mandatory
,
917 rc
= __feat_register_nn(fn
, table
[i
].dependent_feat
,
918 table
[i
].is_mandatory
,
924 * dccp_feat_finalise_settings - Finalise settings before starting negotiation
925 * @dp: client or listening socket (settings will be inherited)
926 * This is called after all registrations (socket initialisation, sysctls, and
927 * sockopt calls), and before sending the first packet containing Change options
928 * (ie. client-Request or server-Response), to ensure internal consistency.
930 int dccp_feat_finalise_settings(struct dccp_sock
*dp
)
932 struct list_head
*fn
= &dp
->dccps_featneg
;
933 struct dccp_feat_entry
*entry
;
934 int i
= 2, ccids
[2] = { -1, -1 };
938 * 1) not useful to propagate CCID settings if this host advertises more
939 * than one CCID: the choice of CCID may still change - if this is
940 * the client, or if this is the server and the client sends
941 * singleton CCID values.
942 * 2) since is that propagate_ccid changes the list, we defer changing
943 * the sorted list until after the traversal.
945 list_for_each_entry(entry
, fn
, node
)
946 if (entry
->feat_num
== DCCPF_CCID
&& entry
->val
.sp
.len
== 1)
947 ccids
[entry
->is_local
] = entry
->val
.sp
.vec
[0];
949 if (ccids
[i
] > 0 && dccp_feat_propagate_ccid(fn
, ccids
[i
], i
))
951 dccp_feat_print_fnlist(fn
);
956 * dccp_feat_server_ccid_dependencies - Resolve CCID-dependent features
957 * It is the server which resolves the dependencies once the CCID has been
958 * fully negotiated. If no CCID has been negotiated, it uses the default CCID.
960 int dccp_feat_server_ccid_dependencies(struct dccp_request_sock
*dreq
)
962 struct list_head
*fn
= &dreq
->dreq_featneg
;
963 struct dccp_feat_entry
*entry
;
966 for (is_local
= 0; is_local
<= 1; is_local
++) {
967 entry
= dccp_feat_list_lookup(fn
, DCCPF_CCID
, is_local
);
969 if (entry
!= NULL
&& !entry
->empty_confirm
)
970 ccid
= entry
->val
.sp
.vec
[0];
972 ccid
= dccp_feat_default_value(DCCPF_CCID
);
974 if (dccp_feat_propagate_ccid(fn
, ccid
, is_local
))
980 /* Select the first entry in @servlist that also occurs in @clilist (6.3.1) */
981 static int dccp_feat_preflist_match(u8
*servlist
, u8 slen
, u8
*clilist
, u8 clen
)
985 for (s
= 0; s
< slen
; s
++)
986 for (c
= 0; c
< clen
; c
++)
987 if (servlist
[s
] == clilist
[c
])
993 * dccp_feat_prefer - Move preferred entry to the start of array
994 * Reorder the @array_len elements in @array so that @preferred_value comes
995 * first. Returns >0 to indicate that @preferred_value does occur in @array.
997 static u8
dccp_feat_prefer(u8 preferred_value
, u8
*array
, u8 array_len
)
999 u8 i
, does_occur
= 0;
1001 if (array
!= NULL
) {
1002 for (i
= 0; i
< array_len
; i
++)
1003 if (array
[i
] == preferred_value
) {
1004 array
[i
] = array
[0];
1008 array
[0] = preferred_value
;
1014 * dccp_feat_reconcile - Reconcile SP preference lists
1015 * @fval: SP list to reconcile into
1016 * @arr: received SP preference list
1017 * @len: length of @arr in bytes
1018 * @is_server: whether this side is the server (and @fv is the server's list)
1019 * @reorder: whether to reorder the list in @fv after reconciling with @arr
1020 * When successful, > 0 is returned and the reconciled list is in @fval.
1021 * A value of 0 means that negotiation failed (no shared entry).
1023 static int dccp_feat_reconcile(dccp_feat_val
*fv
, u8
*arr
, u8 len
,
1024 bool is_server
, bool reorder
)
1028 if (!fv
->sp
.vec
|| !arr
) {
1029 DCCP_CRIT("NULL feature value or array");
1034 rc
= dccp_feat_preflist_match(fv
->sp
.vec
, fv
->sp
.len
, arr
, len
);
1036 rc
= dccp_feat_preflist_match(arr
, len
, fv
->sp
.vec
, fv
->sp
.len
);
1044 * Reorder list: used for activating features and in dccp_insert_fn_opt.
1046 return dccp_feat_prefer(rc
, fv
->sp
.vec
, fv
->sp
.len
);
1050 * dccp_feat_change_recv - Process incoming ChangeL/R options
1051 * @fn: feature-negotiation list to update
1052 * @is_mandatory: whether the Change was preceded by a Mandatory option
1053 * @opt: %DCCPO_CHANGE_L or %DCCPO_CHANGE_R
1054 * @feat: one of %dccp_feature_numbers
1055 * @val: NN value or SP value/preference list
1056 * @len: length of @val in bytes
1057 * @server: whether this node is the server (1) or the client (0)
1059 static u8
dccp_feat_change_recv(struct list_head
*fn
, u8 is_mandatory
, u8 opt
,
1060 u8 feat
, u8
*val
, u8 len
, const bool server
)
1062 u8 defval
, type
= dccp_feat_type(feat
);
1063 const bool local
= (opt
== DCCPO_CHANGE_R
);
1064 struct dccp_feat_entry
*entry
;
1067 if (len
== 0 || type
== FEAT_UNKNOWN
) /* 6.1 and 6.6.8 */
1068 goto unknown_feature_or_value
;
1070 dccp_feat_print_opt(opt
, feat
, val
, len
, is_mandatory
);
1073 * Negotiation of NN features: Change R is invalid, so there is no
1074 * simultaneous negotiation; hence we do not look up in the list.
1076 if (type
== FEAT_NN
) {
1077 if (local
|| len
> sizeof(fval
.nn
))
1078 goto unknown_feature_or_value
;
1080 /* 6.3.2: "The feature remote MUST accept any valid value..." */
1081 fval
.nn
= dccp_decode_value_var(val
, len
);
1082 if (!dccp_feat_is_valid_nn_val(feat
, fval
.nn
))
1083 goto unknown_feature_or_value
;
1085 return dccp_feat_push_confirm(fn
, feat
, local
, &fval
);
1089 * Unidirectional/simultaneous negotiation of SP features (6.3.1)
1091 entry
= dccp_feat_list_lookup(fn
, feat
, local
);
1092 if (entry
== NULL
) {
1094 * No particular preferences have been registered. We deal with
1095 * this situation by assuming that all valid values are equally
1096 * acceptable, and apply the following checks:
1097 * - if the peer's list is a singleton, we accept a valid value;
1098 * - if we are the server, we first try to see if the peer (the
1099 * client) advertises the default value. If yes, we use it,
1100 * otherwise we accept the preferred value;
1101 * - else if we are the client, we use the first list element.
1103 if (dccp_feat_clone_sp_val(&fval
, val
, 1))
1104 return DCCP_RESET_CODE_TOO_BUSY
;
1106 if (len
> 1 && server
) {
1107 defval
= dccp_feat_default_value(feat
);
1108 if (dccp_feat_preflist_match(&defval
, 1, val
, len
) > -1)
1109 fval
.sp
.vec
[0] = defval
;
1110 } else if (!dccp_feat_is_valid_sp_val(feat
, fval
.sp
.vec
[0])) {
1112 goto unknown_feature_or_value
;
1115 /* Treat unsupported CCIDs like invalid values */
1116 if (feat
== DCCPF_CCID
&& !ccid_support_check(fval
.sp
.vec
, 1)) {
1118 goto not_valid_or_not_known
;
1121 return dccp_feat_push_confirm(fn
, feat
, local
, &fval
);
1123 } else if (entry
->state
== FEAT_UNSTABLE
) { /* 6.6.2 */
1127 if (dccp_feat_reconcile(&entry
->val
, val
, len
, server
, true)) {
1128 entry
->empty_confirm
= 0;
1129 } else if (is_mandatory
) {
1130 return DCCP_RESET_CODE_MANDATORY_ERROR
;
1131 } else if (entry
->state
== FEAT_INITIALISING
) {
1133 * Failed simultaneous negotiation (server only): try to `save'
1134 * the connection by checking whether entry contains the default
1135 * value for @feat. If yes, send an empty Confirm to signal that
1136 * the received Change was not understood - which implies using
1137 * the default value.
1138 * If this also fails, we use Reset as the last resort.
1141 defval
= dccp_feat_default_value(feat
);
1142 if (!dccp_feat_reconcile(&entry
->val
, &defval
, 1, server
, true))
1143 return DCCP_RESET_CODE_OPTION_ERROR
;
1144 entry
->empty_confirm
= 1;
1146 entry
->needs_confirm
= 1;
1147 entry
->needs_mandatory
= 0;
1148 entry
->state
= FEAT_STABLE
;
1151 unknown_feature_or_value
:
1153 return dccp_push_empty_confirm(fn
, feat
, local
);
1155 not_valid_or_not_known
:
1156 return is_mandatory
? DCCP_RESET_CODE_MANDATORY_ERROR
1157 : DCCP_RESET_CODE_OPTION_ERROR
;
1161 * dccp_feat_confirm_recv - Process received Confirm options
1162 * @fn: feature-negotiation list to update
1163 * @is_mandatory: whether @opt was preceded by a Mandatory option
1164 * @opt: %DCCPO_CONFIRM_L or %DCCPO_CONFIRM_R
1165 * @feat: one of %dccp_feature_numbers
1166 * @val: NN value or SP value/preference list
1167 * @len: length of @val in bytes
1168 * @server: whether this node is server (1) or client (0)
1170 static u8
dccp_feat_confirm_recv(struct list_head
*fn
, u8 is_mandatory
, u8 opt
,
1171 u8 feat
, u8
*val
, u8 len
, const bool server
)
1173 u8
*plist
, plen
, type
= dccp_feat_type(feat
);
1174 const bool local
= (opt
== DCCPO_CONFIRM_R
);
1175 struct dccp_feat_entry
*entry
= dccp_feat_list_lookup(fn
, feat
, local
);
1177 dccp_feat_print_opt(opt
, feat
, val
, len
, is_mandatory
);
1179 if (entry
== NULL
) { /* nothing queued: ignore or handle error */
1180 if (is_mandatory
&& type
== FEAT_UNKNOWN
)
1181 return DCCP_RESET_CODE_MANDATORY_ERROR
;
1183 if (!local
&& type
== FEAT_NN
) /* 6.3.2 */
1184 goto confirmation_failed
;
1188 if (entry
->state
!= FEAT_CHANGING
) /* 6.6.2 */
1192 if (dccp_feat_must_be_understood(feat
)) /* 6.6.7 */
1193 goto confirmation_failed
;
1195 * Empty Confirm during connection setup: this means reverting
1196 * to the `old' value, which in this case is the default. Since
1197 * we handle default values automatically when no other values
1198 * have been set, we revert to the old value by removing this
1199 * entry from the list.
1201 dccp_feat_list_pop(entry
);
1205 if (type
== FEAT_NN
) {
1206 if (len
> sizeof(entry
->val
.nn
))
1207 goto confirmation_failed
;
1209 if (entry
->val
.nn
== dccp_decode_value_var(val
, len
))
1210 goto confirmation_succeeded
;
1212 DCCP_WARN("Bogus Confirm for non-existing value\n");
1213 goto confirmation_failed
;
1217 * Parsing SP Confirms: the first element of @val is the preferred
1218 * SP value which the peer confirms, the remainder depends on @len.
1219 * Note that only the confirmed value need to be a valid SP value.
1221 if (!dccp_feat_is_valid_sp_val(feat
, *val
))
1222 goto confirmation_failed
;
1224 if (len
== 1) { /* peer didn't supply a preference list */
1227 } else { /* preferred value + preference list */
1232 /* Check whether the peer got the reconciliation right (6.6.8) */
1233 if (dccp_feat_reconcile(&entry
->val
, plist
, plen
, server
, 0) != *val
) {
1234 DCCP_WARN("Confirm selected the wrong value %u\n", *val
);
1235 return DCCP_RESET_CODE_OPTION_ERROR
;
1237 entry
->val
.sp
.vec
[0] = *val
;
1239 confirmation_succeeded
:
1240 entry
->state
= FEAT_STABLE
;
1243 confirmation_failed
:
1244 DCCP_WARN("Confirmation failed\n");
1245 return is_mandatory
? DCCP_RESET_CODE_MANDATORY_ERROR
1246 : DCCP_RESET_CODE_OPTION_ERROR
;
1250 * dccp_feat_parse_options - Process Feature-Negotiation Options
1251 * @sk: for general use and used by the client during connection setup
1252 * @dreq: used by the server during connection setup
1253 * @mandatory: whether @opt was preceded by a Mandatory option
1254 * @opt: %DCCPO_CHANGE_L | %DCCPO_CHANGE_R | %DCCPO_CONFIRM_L | %DCCPO_CONFIRM_R
1255 * @feat: one of %dccp_feature_numbers
1256 * @val: value contents of @opt
1257 * @len: length of @val in bytes
1258 * Returns 0 on success, a Reset code for ending the connection otherwise.
1260 int dccp_feat_parse_options(struct sock
*sk
, struct dccp_request_sock
*dreq
,
1261 u8 mandatory
, u8 opt
, u8 feat
, u8
*val
, u8 len
)
1263 struct dccp_sock
*dp
= dccp_sk(sk
);
1264 struct list_head
*fn
= dreq
? &dreq
->dreq_featneg
: &dp
->dccps_featneg
;
1265 bool server
= false;
1267 switch (sk
->sk_state
) {
1269 * Negotiation during connection setup
1272 server
= true; /* fall through */
1273 case DCCP_REQUESTING
:
1275 case DCCPO_CHANGE_L
:
1276 case DCCPO_CHANGE_R
:
1277 return dccp_feat_change_recv(fn
, mandatory
, opt
, feat
,
1279 case DCCPO_CONFIRM_R
:
1280 case DCCPO_CONFIRM_L
:
1281 return dccp_feat_confirm_recv(fn
, mandatory
, opt
, feat
,
1285 return 0; /* ignore FN options in all other states */
1289 * dccp_feat_init - Seed feature negotiation with host-specific defaults
1290 * This initialises global defaults, depending on the value of the sysctls.
1291 * These can later be overridden by registering changes via setsockopt calls.
1292 * The last link in the chain is finalise_settings, to make sure that between
1293 * here and the start of actual feature negotiation no inconsistencies enter.
1295 * All features not appearing below use either defaults or are otherwise
1296 * later adjusted through dccp_feat_finalise_settings().
1298 int dccp_feat_init(struct sock
*sk
)
1300 struct list_head
*fn
= &dccp_sk(sk
)->dccps_featneg
;
1308 /* Non-negotiable (NN) features */
1309 rc
= __feat_register_nn(fn
, DCCPF_SEQUENCE_WINDOW
, 0,
1310 sysctl_dccp_sequence_window
);
1314 /* Server-priority (SP) features */
1316 /* Advertise that short seqnos are not supported (7.6.1) */
1317 rc
= __feat_register_sp(fn
, DCCPF_SHORT_SEQNOS
, true, true, &off
, 1);
1321 /* RFC 4340 12.1: "If a DCCP is not ECN capable, ..." */
1322 rc
= __feat_register_sp(fn
, DCCPF_ECN_INCAPABLE
, true, true, &on
, 1);
1327 * We advertise the available list of CCIDs and reorder according to
1328 * preferences, to avoid failure resulting from negotiating different
1329 * singleton values (which always leads to failure).
1330 * These settings can still (later) be overridden via sockopts.
1332 if (ccid_get_builtin_ccids(&tx
.val
, &tx
.len
) ||
1333 ccid_get_builtin_ccids(&rx
.val
, &rx
.len
))
1336 /* Pre-load all CCID modules that are going to be advertised */
1338 if (ccid_request_modules(tx
.val
, tx
.len
))
1339 goto free_ccid_lists
;
1341 if (!dccp_feat_prefer(sysctl_dccp_tx_ccid
, tx
.val
, tx
.len
) ||
1342 !dccp_feat_prefer(sysctl_dccp_rx_ccid
, rx
.val
, rx
.len
))
1343 goto free_ccid_lists
;
1345 rc
= __feat_register_sp(fn
, DCCPF_CCID
, true, false, tx
.val
, tx
.len
);
1347 goto free_ccid_lists
;
1349 rc
= __feat_register_sp(fn
, DCCPF_CCID
, false, false, rx
.val
, rx
.len
);
1357 int dccp_feat_activate_values(struct sock
*sk
, struct list_head
*fn_list
)
1359 struct dccp_sock
*dp
= dccp_sk(sk
);
1360 struct dccp_feat_entry
*cur
, *next
;
1362 dccp_feat_val
*fvals
[DCCP_FEAT_SUPPORTED_MAX
][2] = {
1363 [0 ... DCCP_FEAT_SUPPORTED_MAX
-1] = { NULL
, NULL
}
1366 list_for_each_entry(cur
, fn_list
, node
) {
1368 * An empty Confirm means that either an unknown feature type
1369 * or an invalid value was present. In the first case there is
1370 * nothing to activate, in the other the default value is used.
1372 if (cur
->empty_confirm
)
1375 idx
= dccp_feat_index(cur
->feat_num
);
1377 DCCP_BUG("Unknown feature %u", cur
->feat_num
);
1378 goto activation_failed
;
1380 if (cur
->state
!= FEAT_STABLE
) {
1381 DCCP_CRIT("Negotiation of %s %s failed in state %s",
1382 cur
->is_local
? "local" : "remote",
1383 dccp_feat_fname(cur
->feat_num
),
1384 dccp_feat_sname
[cur
->state
]);
1385 goto activation_failed
;
1387 fvals
[idx
][cur
->is_local
] = &cur
->val
;
1391 * Activate in decreasing order of index, so that the CCIDs are always
1392 * activated as the last feature. This avoids the case where a CCID
1393 * relies on the initialisation of one or more features that it depends
1394 * on (e.g. Send NDP Count, Send Ack Vector, and Ack Ratio features).
1396 for (idx
= DCCP_FEAT_SUPPORTED_MAX
; --idx
>= 0;)
1397 if (__dccp_feat_activate(sk
, idx
, 0, fvals
[idx
][0]) ||
1398 __dccp_feat_activate(sk
, idx
, 1, fvals
[idx
][1])) {
1399 DCCP_CRIT("Could not activate %d", idx
);
1400 goto activation_failed
;
1403 /* Clean up Change options which have been confirmed already */
1404 list_for_each_entry_safe(cur
, next
, fn_list
, node
)
1405 if (!cur
->needs_confirm
)
1406 dccp_feat_list_pop(cur
);
1408 dccp_pr_debug("Activation OK\n");
1413 * We clean up everything that may have been allocated, since
1414 * it is difficult to track at which stage negotiation failed.
1415 * This is ok, since all allocation functions below are robust
1416 * against NULL arguments.
1418 ccid_hc_rx_delete(dp
->dccps_hc_rx_ccid
, sk
);
1419 ccid_hc_tx_delete(dp
->dccps_hc_tx_ccid
, sk
);
1420 dp
->dccps_hc_rx_ccid
= dp
->dccps_hc_tx_ccid
= NULL
;
1421 dccp_ackvec_free(dp
->dccps_hc_rx_ackvec
);
1422 dp
->dccps_hc_rx_ackvec
= NULL
;