Skip to content

Commit c02fdc0

Browse files
Gerrit RenkerDavid S. Miller
authored andcommitted
[DCCP]: Make feature negotiation more readable
This patch replaces cryptic feature negotiation messages of type Oct 31 15:42:20 kernel: dccp_feat_change: feat change type=32 feat=1 Oct 31 15:42:21 kernel: dccp_feat_change: feat change type=34 feat=1 Oct 31 15:42:21 kernel: dccp_feat_change: feat change type=32 feat=5 into ones of type: Nov 2 13:54:45 kernel: dccp_feat_change: ChangeL(CCID (1), 3) Nov 2 13:54:45 kernel: dccp_feat_change: ChangeR(CCID (1), 3) Nov 2 13:54:45 kernel: dccp_feat_change: ChangeL(Ack Ratio (5), 2) Also, * completed the feature number list wrt RFC 4340 sec. 6.4 * annotating which ones have been implemented so far * implemented rudimentary sanity checking in feat.c (FIXMEs) * some minor fixes Commiter note: uninlined dccp_feat_name and dccp_feat_typename, for consistency with dccp_{state,packet}_name, that, BTW, should be compiled only if CONFIG_IP_DCCP_DEBUG is selected, leaving this to another cset tho. Also shortened dccp_feat_negotiation_debug to dccp_feat_debug. Signed-off-by: Gerrit Renker <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 6a128e0 commit c02fdc0

File tree

4 files changed

+145
-41
lines changed

4 files changed

+145
-41
lines changed

include/linux/dccp.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,21 @@ enum {
175175
DCCPC_CCID3 = 3,
176176
};
177177

178-
/* DCCP features */
179-
enum {
180-
DCCPF_RESERVED = 0,
181-
DCCPF_CCID = 1,
182-
DCCPF_SEQUENCE_WINDOW = 3,
183-
DCCPF_ACK_RATIO = 5,
184-
DCCPF_SEND_ACK_VECTOR = 6,
185-
DCCPF_SEND_NDP_COUNT = 7,
178+
/* DCCP features (RFC 4340 section 6.4) */
179+
enum {
180+
DCCPF_RESERVED = 0,
181+
DCCPF_CCID = 1,
182+
DCCPF_SHORT_SEQNOS = 2, /* XXX: not yet implemented */
183+
DCCPF_SEQUENCE_WINDOW = 3,
184+
DCCPF_ECN_INCAPABLE = 4, /* XXX: not yet implemented */
185+
DCCPF_ACK_RATIO = 5,
186+
DCCPF_SEND_ACK_VECTOR = 6,
187+
DCCPF_SEND_NDP_COUNT = 7,
186188
DCCPF_MIN_CSUM_COVER = 8,
187-
/* 10-127 reserved */
188-
DCCPF_MIN_CCID_SPECIFIC = 128,
189-
DCCPF_MAX_CCID_SPECIFIC = 255,
189+
DCCPF_DATA_CHECKSUM = 9, /* XXX: not yet implemented */
190+
/* 10-127 reserved */
191+
DCCPF_MIN_CCID_SPECIFIC = 128,
192+
DCCPF_MAX_CCID_SPECIFIC = 255,
190193
};
191194

192195
/* this structure is argument to DCCP_SOCKOPT_CHANGE_X */

net/dccp/feat.c

Lines changed: 89 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include <linux/module.h>
1414

15-
#include "dccp.h"
1615
#include "ccid.h"
1716
#include "feat.h"
1817

@@ -23,9 +22,17 @@ int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature,
2322
{
2423
struct dccp_opt_pend *opt;
2524

26-
dccp_pr_debug("feat change type=%d feat=%d\n", type, feature);
25+
dccp_feat_debug(type, feature, *val);
2726

28-
/* XXX sanity check feat change request */
27+
if (!dccp_feat_is_valid_type(type)) {
28+
pr_info("option type %d invalid in negotiation\n", type);
29+
return 1;
30+
}
31+
if (!dccp_feat_is_valid_length(type, feature, len)) {
32+
pr_info("invalid length %d\n", len);
33+
return 1;
34+
}
35+
/* XXX add further sanity checks */
2936

3037
/* check if that feature is already being negotiated */
3138
list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
@@ -95,14 +102,14 @@ static int dccp_feat_update_ccid(struct sock *sk, u8 type, u8 new_ccid_nr)
95102
/* XXX taking only u8 vals */
96103
static int dccp_feat_update(struct sock *sk, u8 type, u8 feat, u8 val)
97104
{
98-
dccp_pr_debug("changing [%d] feat %d to %d\n", type, feat, val);
105+
dccp_feat_debug(type, feat, val);
99106

100107
switch (feat) {
101108
case DCCPF_CCID:
102109
return dccp_feat_update_ccid(sk, type, val);
103110
default:
104-
dccp_pr_debug("IMPLEMENT changing [%d] feat %d to %d\n",
105-
type, feat, val);
111+
dccp_pr_debug("UNIMPLEMENTED: %s(%d, ...)\n",
112+
dccp_feat_typename(type), feat);
106113
break;
107114
}
108115
return 0;
@@ -265,10 +272,10 @@ static int dccp_feat_nn(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
265272
u8 *copy;
266273
int rc;
267274

268-
/* NN features must be change L */
269-
if (type == DCCPO_CHANGE_R) {
270-
dccp_pr_debug("received CHANGE_R %d for NN feat %d\n",
271-
type, feature);
275+
/* NN features must be Change L (sec. 6.3.2) */
276+
if (type != DCCPO_CHANGE_L) {
277+
dccp_pr_debug("received %s for NN feature %d\n",
278+
dccp_feat_typename(type), feature);
272279
return -EFAULT;
273280
}
274281

@@ -299,7 +306,8 @@ static int dccp_feat_nn(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
299306
return rc;
300307
}
301308

302-
dccp_pr_debug("Confirming NN feature %d (val=%d)\n", feature, *copy);
309+
dccp_feat_debug(type, feature, *copy);
310+
303311
list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf);
304312

305313
return 0;
@@ -318,14 +326,19 @@ static void dccp_feat_empty_confirm(struct dccp_minisock *dmsk,
318326
return;
319327
}
320328

321-
opt->dccpop_type = type == DCCPO_CHANGE_L ? DCCPO_CONFIRM_R :
322-
DCCPO_CONFIRM_L;
329+
switch (type) {
330+
case DCCPO_CHANGE_L: opt->dccpop_type = DCCPO_CONFIRM_R; break;
331+
case DCCPO_CHANGE_R: opt->dccpop_type = DCCPO_CONFIRM_L; break;
332+
default: pr_info("invalid type %d\n", type); return;
333+
334+
}
323335
opt->dccpop_feat = feature;
324336
opt->dccpop_val = NULL;
325337
opt->dccpop_len = 0;
326338

327339
/* change feature */
328-
dccp_pr_debug("Empty confirm feature %d type %d\n", feature, type);
340+
dccp_pr_debug("Empty %s(%d)\n", dccp_feat_typename(type), feature);
341+
329342
list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf);
330343
}
331344

@@ -359,7 +372,7 @@ int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
359372
{
360373
int rc;
361374

362-
dccp_pr_debug("got feat change type=%d feat=%d\n", type, feature);
375+
dccp_feat_debug(type, feature, *val);
363376

364377
/* figure out if it's SP or NN feature */
365378
switch (feature) {
@@ -375,6 +388,8 @@ int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
375388

376389
/* XXX implement other features */
377390
default:
391+
dccp_pr_debug("UNIMPLEMENTED: not handling %s(%d, ...)\n",
392+
dccp_feat_typename(type), feature);
378393
rc = -EFAULT;
379394
break;
380395
}
@@ -403,20 +418,27 @@ int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature,
403418
u8 t;
404419
struct dccp_opt_pend *opt;
405420
struct dccp_minisock *dmsk = dccp_msk(sk);
406-
int rc = 1;
421+
int found = 0;
407422
int all_confirmed = 1;
408423

409-
dccp_pr_debug("got feat confirm type=%d feat=%d\n", type, feature);
410-
411-
/* XXX sanity check type & feat */
424+
dccp_feat_debug(type, feature, *val);
412425

413426
/* locate our change request */
414-
t = type == DCCPO_CONFIRM_L ? DCCPO_CHANGE_R : DCCPO_CHANGE_L;
427+
switch (type) {
428+
case DCCPO_CONFIRM_L: t = DCCPO_CHANGE_R; break;
429+
case DCCPO_CONFIRM_R: t = DCCPO_CHANGE_L; break;
430+
default: pr_info("invalid type %d\n", type);
431+
return 1;
432+
433+
}
434+
/* XXX sanity check feature value */
415435

416436
list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
417437
if (!opt->dccpop_conf && opt->dccpop_type == t &&
418438
opt->dccpop_feat == feature) {
419-
/* we found it */
439+
found = 1;
440+
dccp_pr_debug("feature %d found\n", opt->dccpop_feat);
441+
420442
/* XXX do sanity check */
421443

422444
opt->dccpop_conf = 1;
@@ -425,9 +447,7 @@ int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature,
425447
dccp_feat_update(sk, opt->dccpop_type,
426448
opt->dccpop_feat, *val);
427449

428-
dccp_pr_debug("feat %d type %d confirmed %d\n",
429-
feature, type, *val);
430-
rc = 0;
450+
/* XXX check the return value of dccp_feat_update */
431451
break;
432452
}
433453

@@ -446,9 +466,9 @@ int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature,
446466
inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS);
447467
}
448468

449-
if (rc)
450-
dccp_pr_debug("feat %d type %d never requested\n",
451-
feature, type);
469+
if (!found)
470+
dccp_pr_debug("%s(%d, ...) never requested\n",
471+
dccp_feat_typename(type), feature);
452472
return 0;
453473
}
454474

@@ -583,3 +603,45 @@ int dccp_feat_init(struct dccp_minisock *dmsk)
583603
}
584604

585605
EXPORT_SYMBOL_GPL(dccp_feat_init);
606+
607+
#ifdef CONFIG_IP_DCCP_DEBUG
608+
const char *dccp_feat_typename(const u8 type)
609+
{
610+
switch(type) {
611+
case DCCPO_CHANGE_L: return("ChangeL");
612+
case DCCPO_CONFIRM_L: return("ConfirmL");
613+
case DCCPO_CHANGE_R: return("ChangeR");
614+
case DCCPO_CONFIRM_R: return("ConfirmR");
615+
/* the following case must not appear in feature negotation */
616+
default: dccp_pr_debug("unknown type %d [BUG!]\n", type);
617+
}
618+
return NULL;
619+
}
620+
621+
EXPORT_SYMBOL_GPL(dccp_feat_typename);
622+
623+
const char *dccp_feat_name(const u8 feat)
624+
{
625+
static const char *feature_names[] = {
626+
[DCCPF_RESERVED] = "Reserved",
627+
[DCCPF_CCID] = "CCID",
628+
[DCCPF_SHORT_SEQNOS] = "Allow Short Seqnos",
629+
[DCCPF_SEQUENCE_WINDOW] = "Sequence Window",
630+
[DCCPF_ECN_INCAPABLE] = "ECN Incapable",
631+
[DCCPF_ACK_RATIO] = "Ack Ratio",
632+
[DCCPF_SEND_ACK_VECTOR] = "Send ACK Vector",
633+
[DCCPF_SEND_NDP_COUNT] = "Send NDP Count",
634+
[DCCPF_MIN_CSUM_COVER] = "Min. Csum Coverage",
635+
[DCCPF_DATA_CHECKSUM] = "Send Data Checksum",
636+
};
637+
if (feat >= DCCPF_MIN_CCID_SPECIFIC)
638+
return "CCID-specific";
639+
640+
if (dccp_feat_is_reserved(feat))
641+
return feature_names[DCCPF_RESERVED];
642+
643+
return feature_names[feat];
644+
}
645+
646+
EXPORT_SYMBOL_GPL(dccp_feat_name);
647+
#endif /* CONFIG_IP_DCCP_DEBUG */

net/dccp/feat.h

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,46 @@
1212
*/
1313

1414
#include <linux/types.h>
15+
#include "dccp.h"
1516

16-
struct sock;
17-
struct dccp_minisock;
17+
static inline int dccp_feat_is_valid_length(u8 type, u8 feature, u8 len)
18+
{
19+
/* sec. 6.1: Confirm has at least length 3,
20+
* sec. 6.2: Change has at least length 4 */
21+
if (len < 3)
22+
return 1;
23+
if (len < 4 && (type == DCCPO_CHANGE_L || type == DCCPO_CHANGE_R))
24+
return 1;
25+
/* XXX: add per-feature length validation (sec. 6.6.8) */
26+
return 0;
27+
}
28+
29+
static inline int dccp_feat_is_reserved(const u8 feat)
30+
{
31+
return (feat > DCCPF_DATA_CHECKSUM &&
32+
feat < DCCPF_MIN_CCID_SPECIFIC) ||
33+
feat == DCCPF_RESERVED;
34+
}
35+
36+
/* feature negotiation knows only these four option types (RFC 4340, sec. 6) */
37+
static inline int dccp_feat_is_valid_type(const u8 optnum)
38+
{
39+
return optnum >= DCCPO_CHANGE_L && optnum <= DCCPO_CONFIRM_R;
40+
41+
}
42+
43+
#ifdef CONFIG_IP_DCCP_DEBUG
44+
extern const char *dccp_feat_typename(const u8 type);
45+
extern const char *dccp_feat_name(const u8 feat);
46+
47+
static inline void dccp_feat_debug(const u8 type, const u8 feat, const u8 val)
48+
{
49+
dccp_pr_debug("%s(%s (%d), %d)\n", dccp_feat_typename(type),
50+
dccp_feat_name(feat), feat, val);
51+
}
52+
#else
53+
#define dccp_feat_debug(type, feat, val)
54+
#endif /* CONFIG_IP_DCCP_DEBUG */
1855

1956
extern int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature,
2057
u8 *val, u8 len, gfp_t gfp);

net/dccp/options.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,10 @@ static int dccp_insert_feat_opt(struct sk_buff *skb, u8 type, u8 feat,
465465

466466
if (len)
467467
memcpy(to, val, len);
468-
dccp_pr_debug("option %d feat %d len %d\n", type, feat, len);
469468

469+
dccp_pr_debug("%s(%s (%d), ...), length %d\n",
470+
dccp_feat_typename(type),
471+
dccp_feat_name(feat), feat, len);
470472
return 0;
471473
}
472474

0 commit comments

Comments
 (0)