diff options
-rw-r--r-- | include/linux/dccp.h | 9 | ||||
-rw-r--r-- | net/dccp/feat.c | 115 |
2 files changed, 120 insertions, 4 deletions
diff --git a/include/linux/dccp.h b/include/linux/dccp.h index 6080449fbec9..3978aff197d9 100644 --- a/include/linux/dccp.h +++ b/include/linux/dccp.h | |||
@@ -176,19 +176,20 @@ enum { | |||
176 | }; | 176 | }; |
177 | 177 | ||
178 | /* DCCP features (RFC 4340 section 6.4) */ | 178 | /* DCCP features (RFC 4340 section 6.4) */ |
179 | enum { | 179 | enum dccp_feature_numbers { |
180 | DCCPF_RESERVED = 0, | 180 | DCCPF_RESERVED = 0, |
181 | DCCPF_CCID = 1, | 181 | DCCPF_CCID = 1, |
182 | DCCPF_SHORT_SEQNOS = 2, /* XXX: not yet implemented */ | 182 | DCCPF_SHORT_SEQNOS = 2, |
183 | DCCPF_SEQUENCE_WINDOW = 3, | 183 | DCCPF_SEQUENCE_WINDOW = 3, |
184 | DCCPF_ECN_INCAPABLE = 4, /* XXX: not yet implemented */ | 184 | DCCPF_ECN_INCAPABLE = 4, |
185 | DCCPF_ACK_RATIO = 5, | 185 | DCCPF_ACK_RATIO = 5, |
186 | DCCPF_SEND_ACK_VECTOR = 6, | 186 | DCCPF_SEND_ACK_VECTOR = 6, |
187 | DCCPF_SEND_NDP_COUNT = 7, | 187 | DCCPF_SEND_NDP_COUNT = 7, |
188 | DCCPF_MIN_CSUM_COVER = 8, | 188 | DCCPF_MIN_CSUM_COVER = 8, |
189 | DCCPF_DATA_CHECKSUM = 9, /* XXX: not yet implemented */ | 189 | DCCPF_DATA_CHECKSUM = 9, |
190 | /* 10-127 reserved */ | 190 | /* 10-127 reserved */ |
191 | DCCPF_MIN_CCID_SPECIFIC = 128, | 191 | DCCPF_MIN_CCID_SPECIFIC = 128, |
192 | DCCPF_SEND_LEV_RATE = 192, /* RFC 4342, sec. 8.4 */ | ||
192 | DCCPF_MAX_CCID_SPECIFIC = 255, | 193 | DCCPF_MAX_CCID_SPECIFIC = 255, |
193 | }; | 194 | }; |
194 | 195 | ||
diff --git a/net/dccp/feat.c b/net/dccp/feat.c index 94a81b8e5efb..d7468f70544d 100644 --- a/net/dccp/feat.c +++ b/net/dccp/feat.c | |||
@@ -23,6 +23,80 @@ | |||
23 | 23 | ||
24 | #define DCCP_FEAT_SP_NOAGREE (-123) | 24 | #define DCCP_FEAT_SP_NOAGREE (-123) |
25 | 25 | ||
26 | static const struct { | ||
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 */ | ||
31 | /* | ||
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 | * +--------------------------+----+-----+----+----+---------+-----------+ | ||
48 | */ | ||
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 }, | ||
60 | }; | ||
61 | #define DCCP_FEAT_SUPPORTED_MAX ARRAY_SIZE(dccp_feat_table) | ||
62 | |||
63 | /** | ||
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. | ||
66 | */ | ||
67 | static int dccp_feat_index(u8 feat_num) | ||
68 | { | ||
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) | ||
71 | return feat_num - 1; | ||
72 | |||
73 | /* | ||
74 | * Other features: add cases for new feature types here after adding | ||
75 | * them to the above table. | ||
76 | */ | ||
77 | switch (feat_num) { | ||
78 | case DCCPF_SEND_LEV_RATE: | ||
79 | return DCCP_FEAT_SUPPORTED_MAX - 1; | ||
80 | } | ||
81 | return -1; | ||
82 | } | ||
83 | |||
84 | static u8 dccp_feat_type(u8 feat_num) | ||
85 | { | ||
86 | int idx = dccp_feat_index(feat_num); | ||
87 | |||
88 | if (idx < 0) | ||
89 | return FEAT_UNKNOWN; | ||
90 | return dccp_feat_table[idx].reconciliation; | ||
91 | } | ||
92 | |||
93 | static int dccp_feat_default_value(u8 feat_num) | ||
94 | { | ||
95 | int idx = dccp_feat_index(feat_num); | ||
96 | |||
97 | return idx < 0 ? : dccp_feat_table[idx].default_value; | ||
98 | } | ||
99 | |||
26 | /* copy constructor, fval must not already contain allocated memory */ | 100 | /* copy constructor, fval must not already contain allocated memory */ |
27 | static int dccp_feat_clone_sp_val(dccp_feat_val *fval, u8 const *val, u8 len) | 101 | static int dccp_feat_clone_sp_val(dccp_feat_val *fval, u8 const *val, u8 len) |
28 | { | 102 | { |
@@ -37,6 +111,45 @@ static int dccp_feat_clone_sp_val(dccp_feat_val *fval, u8 const *val, u8 len) | |||
37 | return 0; | 111 | return 0; |
38 | } | 112 | } |
39 | 113 | ||
114 | static void dccp_feat_val_destructor(u8 feat_num, dccp_feat_val *val) | ||
115 | { | ||
116 | if (unlikely(val == NULL)) | ||
117 | return; | ||
118 | if (dccp_feat_type(feat_num) == FEAT_SP) | ||
119 | kfree(val->sp.vec); | ||
120 | memset(val, 0, sizeof(*val)); | ||
121 | } | ||
122 | |||
123 | static struct dccp_feat_entry * | ||
124 | dccp_feat_clone_entry(struct dccp_feat_entry const *original) | ||
125 | { | ||
126 | struct dccp_feat_entry *new; | ||
127 | u8 type = dccp_feat_type(original->feat_num); | ||
128 | |||
129 | if (type == FEAT_UNKNOWN) | ||
130 | return NULL; | ||
131 | |||
132 | new = kmemdup(original, sizeof(struct dccp_feat_entry), gfp_any()); | ||
133 | if (new == NULL) | ||
134 | return NULL; | ||
135 | |||
136 | if (type == FEAT_SP && dccp_feat_clone_sp_val(&new->val, | ||
137 | original->val.sp.vec, | ||
138 | original->val.sp.len)) { | ||
139 | kfree(new); | ||
140 | return NULL; | ||
141 | } | ||
142 | return new; | ||
143 | } | ||
144 | |||
145 | static void dccp_feat_entry_destructor(struct dccp_feat_entry *entry) | ||
146 | { | ||
147 | if (entry != NULL) { | ||
148 | dccp_feat_val_destructor(entry->feat_num, &entry->val); | ||
149 | kfree(entry); | ||
150 | } | ||
151 | } | ||
152 | |||
40 | int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature, | 153 | int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature, |
41 | u8 *val, u8 len, gfp_t gfp) | 154 | u8 *val, u8 len, gfp_t gfp) |
42 | { | 155 | { |
@@ -653,6 +766,8 @@ const char *dccp_feat_name(const u8 feat) | |||
653 | if (feat > DCCPF_DATA_CHECKSUM && feat < DCCPF_MIN_CCID_SPECIFIC) | 766 | if (feat > DCCPF_DATA_CHECKSUM && feat < DCCPF_MIN_CCID_SPECIFIC) |
654 | return feature_names[DCCPF_RESERVED]; | 767 | return feature_names[DCCPF_RESERVED]; |
655 | 768 | ||
769 | if (feat == DCCPF_SEND_LEV_RATE) | ||
770 | return "Send Loss Event Rate"; | ||
656 | if (feat >= DCCPF_MIN_CCID_SPECIFIC) | 771 | if (feat >= DCCPF_MIN_CCID_SPECIFIC) |
657 | return "CCID-specific"; | 772 | return "CCID-specific"; |
658 | 773 | ||