Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * net/dccp/feat.c |
| 3 | * |
| 4 | * An implementation of the DCCP protocol |
| 5 | * Andrea Bittau <a.bittau@cs.ucl.ac.uk> |
| 6 | * |
Gerrit Renker | 5cdae19 | 2007-12-13 12:41:46 -0200 | [diff] [blame] | 7 | * ASSUMPTIONS |
| 8 | * ----------- |
| 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. |
| 12 | * |
| 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. |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 17 | */ |
| 18 | |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 19 | #include <linux/module.h> |
| 20 | |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 21 | #include "ccid.h" |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 22 | #include "feat.h" |
| 23 | |
| 24 | #define DCCP_FEAT_SP_NOAGREE (-123) |
| 25 | |
Gerrit Renker | b4eec20 | 2008-09-04 07:30:19 +0200 | [diff] [blame^] | 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 | |
Gerrit Renker | 5c7c945 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 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) |
| 102 | { |
| 103 | fval->sp.len = len; |
| 104 | if (fval->sp.len > 0) { |
| 105 | fval->sp.vec = kmemdup(val, len, gfp_any()); |
| 106 | if (fval->sp.vec == NULL) { |
| 107 | fval->sp.len = 0; |
| 108 | return -ENOBUFS; |
| 109 | } |
| 110 | } |
| 111 | return 0; |
| 112 | } |
| 113 | |
Gerrit Renker | b4eec20 | 2008-09-04 07:30:19 +0200 | [diff] [blame^] | 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 | |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 153 | int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature, |
| 154 | u8 *val, u8 len, gfp_t gfp) |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 155 | { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 156 | struct dccp_opt_pend *opt; |
| 157 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 158 | dccp_feat_debug(type, feature, *val); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 159 | |
Gerrit Renker | dd6303d | 2007-12-13 12:40:40 -0200 | [diff] [blame] | 160 | if (len > 3) { |
Gerrit Renker | 59348b1 | 2006-11-20 18:39:23 -0200 | [diff] [blame] | 161 | DCCP_WARN("invalid length %d\n", len); |
Chris Wright | 1944317 | 2008-05-05 13:50:24 -0700 | [diff] [blame] | 162 | return -EINVAL; |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 163 | } |
| 164 | /* XXX add further sanity checks */ |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 165 | |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 166 | /* check if that feature is already being negotiated */ |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 167 | list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 168 | /* ok we found a negotiation for this option already */ |
| 169 | if (opt->dccpop_feat == feature && opt->dccpop_type == type) { |
| 170 | dccp_pr_debug("Replacing old\n"); |
| 171 | /* replace */ |
| 172 | BUG_ON(opt->dccpop_val == NULL); |
| 173 | kfree(opt->dccpop_val); |
| 174 | opt->dccpop_val = val; |
| 175 | opt->dccpop_len = len; |
| 176 | opt->dccpop_conf = 0; |
| 177 | return 0; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | /* negotiation for a new feature */ |
| 182 | opt = kmalloc(sizeof(*opt), gfp); |
| 183 | if (opt == NULL) |
| 184 | return -ENOMEM; |
| 185 | |
| 186 | opt->dccpop_type = type; |
| 187 | opt->dccpop_feat = feature; |
| 188 | opt->dccpop_len = len; |
| 189 | opt->dccpop_val = val; |
| 190 | opt->dccpop_conf = 0; |
| 191 | opt->dccpop_sc = NULL; |
| 192 | |
| 193 | BUG_ON(opt->dccpop_val == NULL); |
| 194 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 195 | list_add_tail(&opt->dccpop_node, &dmsk->dccpms_pending); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | EXPORT_SYMBOL_GPL(dccp_feat_change); |
| 200 | |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 201 | static int dccp_feat_update_ccid(struct sock *sk, u8 type, u8 new_ccid_nr) |
| 202 | { |
| 203 | struct dccp_sock *dp = dccp_sk(sk); |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 204 | struct dccp_minisock *dmsk = dccp_msk(sk); |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 205 | /* figure out if we are changing our CCID or the peer's */ |
| 206 | const int rx = type == DCCPO_CHANGE_R; |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 207 | const u8 ccid_nr = rx ? dmsk->dccpms_rx_ccid : dmsk->dccpms_tx_ccid; |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 208 | struct ccid *new_ccid; |
| 209 | |
| 210 | /* Check if nothing is being changed. */ |
| 211 | if (ccid_nr == new_ccid_nr) |
| 212 | return 0; |
| 213 | |
| 214 | new_ccid = ccid_new(new_ccid_nr, sk, rx, GFP_ATOMIC); |
| 215 | if (new_ccid == NULL) |
| 216 | return -ENOMEM; |
| 217 | |
| 218 | if (rx) { |
| 219 | ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk); |
| 220 | dp->dccps_hc_rx_ccid = new_ccid; |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 221 | dmsk->dccpms_rx_ccid = new_ccid_nr; |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 222 | } else { |
| 223 | ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk); |
| 224 | dp->dccps_hc_tx_ccid = new_ccid; |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 225 | dmsk->dccpms_tx_ccid = new_ccid_nr; |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 231 | static int dccp_feat_update(struct sock *sk, u8 type, u8 feat, u8 val) |
| 232 | { |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 233 | dccp_feat_debug(type, feat, val); |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 234 | |
| 235 | switch (feat) { |
| 236 | case DCCPF_CCID: |
| 237 | return dccp_feat_update_ccid(sk, type, val); |
| 238 | default: |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 239 | dccp_pr_debug("UNIMPLEMENTED: %s(%d, ...)\n", |
| 240 | dccp_feat_typename(type), feat); |
Andrea Bittau | 6ffd30f | 2006-03-20 19:22:37 -0800 | [diff] [blame] | 241 | break; |
| 242 | } |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | static int dccp_feat_reconcile(struct sock *sk, struct dccp_opt_pend *opt, |
| 247 | u8 *rpref, u8 rlen) |
| 248 | { |
| 249 | struct dccp_sock *dp = dccp_sk(sk); |
| 250 | u8 *spref, slen, *res = NULL; |
| 251 | int i, j, rc, agree = 1; |
| 252 | |
| 253 | BUG_ON(rpref == NULL); |
| 254 | |
| 255 | /* check if we are the black sheep */ |
| 256 | if (dp->dccps_role == DCCP_ROLE_CLIENT) { |
| 257 | spref = rpref; |
| 258 | slen = rlen; |
| 259 | rpref = opt->dccpop_val; |
| 260 | rlen = opt->dccpop_len; |
| 261 | } else { |
| 262 | spref = opt->dccpop_val; |
| 263 | slen = opt->dccpop_len; |
| 264 | } |
| 265 | /* |
| 266 | * Now we have server preference list in spref and client preference in |
| 267 | * rpref |
| 268 | */ |
| 269 | BUG_ON(spref == NULL); |
| 270 | BUG_ON(rpref == NULL); |
| 271 | |
| 272 | /* FIXME sanity check vals */ |
| 273 | |
| 274 | /* Are values in any order? XXX Lame "algorithm" here */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 275 | for (i = 0; i < slen; i++) { |
| 276 | for (j = 0; j < rlen; j++) { |
| 277 | if (spref[i] == rpref[j]) { |
| 278 | res = &spref[i]; |
| 279 | break; |
| 280 | } |
| 281 | } |
| 282 | if (res) |
| 283 | break; |
| 284 | } |
| 285 | |
| 286 | /* we didn't agree on anything */ |
| 287 | if (res == NULL) { |
| 288 | /* confirm previous value */ |
| 289 | switch (opt->dccpop_feat) { |
| 290 | case DCCPF_CCID: |
| 291 | /* XXX did i get this right? =P */ |
| 292 | if (opt->dccpop_type == DCCPO_CHANGE_L) |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 293 | res = &dccp_msk(sk)->dccpms_tx_ccid; |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 294 | else |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 295 | res = &dccp_msk(sk)->dccpms_rx_ccid; |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 296 | break; |
| 297 | |
| 298 | default: |
Gerrit Renker | 59348b1 | 2006-11-20 18:39:23 -0200 | [diff] [blame] | 299 | DCCP_BUG("Fell through, feat=%d", opt->dccpop_feat); |
| 300 | /* XXX implement res */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 301 | return -EFAULT; |
| 302 | } |
| 303 | |
| 304 | dccp_pr_debug("Don't agree... reconfirming %d\n", *res); |
| 305 | agree = 0; /* this is used for mandatory options... */ |
| 306 | } |
| 307 | |
| 308 | /* need to put result and our preference list */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 309 | rlen = 1 + opt->dccpop_len; |
| 310 | rpref = kmalloc(rlen, GFP_ATOMIC); |
| 311 | if (rpref == NULL) |
| 312 | return -ENOMEM; |
| 313 | |
| 314 | *rpref = *res; |
| 315 | memcpy(&rpref[1], opt->dccpop_val, opt->dccpop_len); |
| 316 | |
| 317 | /* put it in the "confirm queue" */ |
| 318 | if (opt->dccpop_sc == NULL) { |
| 319 | opt->dccpop_sc = kmalloc(sizeof(*opt->dccpop_sc), GFP_ATOMIC); |
| 320 | if (opt->dccpop_sc == NULL) { |
| 321 | kfree(rpref); |
| 322 | return -ENOMEM; |
| 323 | } |
| 324 | } else { |
| 325 | /* recycle the confirm slot */ |
| 326 | BUG_ON(opt->dccpop_sc->dccpoc_val == NULL); |
| 327 | kfree(opt->dccpop_sc->dccpoc_val); |
| 328 | dccp_pr_debug("recycling confirm slot\n"); |
| 329 | } |
| 330 | memset(opt->dccpop_sc, 0, sizeof(*opt->dccpop_sc)); |
| 331 | |
| 332 | opt->dccpop_sc->dccpoc_val = rpref; |
| 333 | opt->dccpop_sc->dccpoc_len = rlen; |
| 334 | |
| 335 | /* update the option on our side [we are about to send the confirm] */ |
| 336 | rc = dccp_feat_update(sk, opt->dccpop_type, opt->dccpop_feat, *res); |
| 337 | if (rc) { |
| 338 | kfree(opt->dccpop_sc->dccpoc_val); |
| 339 | kfree(opt->dccpop_sc); |
Randy Dunlap | 68907da | 2006-03-29 13:58:25 -0800 | [diff] [blame] | 340 | opt->dccpop_sc = NULL; |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 341 | return rc; |
| 342 | } |
| 343 | |
| 344 | dccp_pr_debug("Will confirm %d\n", *rpref); |
| 345 | |
| 346 | /* say we want to change to X but we just got a confirm X, suppress our |
| 347 | * change |
| 348 | */ |
| 349 | if (!opt->dccpop_conf) { |
| 350 | if (*opt->dccpop_val == *res) |
| 351 | opt->dccpop_conf = 1; |
| 352 | dccp_pr_debug("won't ask for change of same feature\n"); |
| 353 | } |
| 354 | |
| 355 | return agree ? 0 : DCCP_FEAT_SP_NOAGREE; /* used for mandatory opts */ |
| 356 | } |
| 357 | |
| 358 | static int dccp_feat_sp(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len) |
| 359 | { |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 360 | struct dccp_minisock *dmsk = dccp_msk(sk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 361 | struct dccp_opt_pend *opt; |
| 362 | int rc = 1; |
| 363 | u8 t; |
| 364 | |
| 365 | /* |
| 366 | * We received a CHANGE. We gotta match it against our own preference |
| 367 | * list. If we got a CHANGE_R it means it's a change for us, so we need |
| 368 | * to compare our CHANGE_L list. |
| 369 | */ |
| 370 | if (type == DCCPO_CHANGE_L) |
| 371 | t = DCCPO_CHANGE_R; |
| 372 | else |
| 373 | t = DCCPO_CHANGE_L; |
| 374 | |
| 375 | /* find our preference list for this feature */ |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 376 | list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 377 | if (opt->dccpop_type != t || opt->dccpop_feat != feature) |
| 378 | continue; |
| 379 | |
| 380 | /* find the winner from the two preference lists */ |
| 381 | rc = dccp_feat_reconcile(sk, opt, val, len); |
| 382 | break; |
| 383 | } |
| 384 | |
| 385 | /* We didn't deal with the change. This can happen if we have no |
| 386 | * preference list for the feature. In fact, it just shouldn't |
| 387 | * happen---if we understand a feature, we should have a preference list |
| 388 | * with at least the default value. |
| 389 | */ |
| 390 | BUG_ON(rc == 1); |
| 391 | |
| 392 | return rc; |
| 393 | } |
| 394 | |
| 395 | static int dccp_feat_nn(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len) |
| 396 | { |
| 397 | struct dccp_opt_pend *opt; |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 398 | struct dccp_minisock *dmsk = dccp_msk(sk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 399 | u8 *copy; |
| 400 | int rc; |
| 401 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 402 | /* NN features must be Change L (sec. 6.3.2) */ |
| 403 | if (type != DCCPO_CHANGE_L) { |
| 404 | dccp_pr_debug("received %s for NN feature %d\n", |
| 405 | dccp_feat_typename(type), feature); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 406 | return -EFAULT; |
| 407 | } |
| 408 | |
| 409 | /* XXX sanity check opt val */ |
| 410 | |
| 411 | /* copy option so we can confirm it */ |
| 412 | opt = kzalloc(sizeof(*opt), GFP_ATOMIC); |
| 413 | if (opt == NULL) |
| 414 | return -ENOMEM; |
| 415 | |
Arnaldo Carvalho de Melo | eed7341 | 2006-11-17 12:21:43 -0200 | [diff] [blame] | 416 | copy = kmemdup(val, len, GFP_ATOMIC); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 417 | if (copy == NULL) { |
| 418 | kfree(opt); |
| 419 | return -ENOMEM; |
| 420 | } |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 421 | |
| 422 | opt->dccpop_type = DCCPO_CONFIRM_R; /* NN can only confirm R */ |
| 423 | opt->dccpop_feat = feature; |
| 424 | opt->dccpop_val = copy; |
| 425 | opt->dccpop_len = len; |
| 426 | |
| 427 | /* change feature */ |
| 428 | rc = dccp_feat_update(sk, type, feature, *val); |
| 429 | if (rc) { |
| 430 | kfree(opt->dccpop_val); |
| 431 | kfree(opt); |
| 432 | return rc; |
| 433 | } |
| 434 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 435 | dccp_feat_debug(type, feature, *copy); |
| 436 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 437 | list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 438 | |
| 439 | return 0; |
| 440 | } |
| 441 | |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 442 | static void dccp_feat_empty_confirm(struct dccp_minisock *dmsk, |
| 443 | u8 type, u8 feature) |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 444 | { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 445 | /* XXX check if other confirms for that are queued and recycle slot */ |
| 446 | struct dccp_opt_pend *opt = kzalloc(sizeof(*opt), GFP_ATOMIC); |
| 447 | |
| 448 | if (opt == NULL) { |
| 449 | /* XXX what do we do? Ignoring should be fine. It's a change |
| 450 | * after all =P |
| 451 | */ |
| 452 | return; |
| 453 | } |
| 454 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 455 | switch (type) { |
Jesper Juhl | e576de8 | 2007-08-10 15:23:54 -0700 | [diff] [blame] | 456 | case DCCPO_CHANGE_L: |
| 457 | opt->dccpop_type = DCCPO_CONFIRM_R; |
| 458 | break; |
| 459 | case DCCPO_CHANGE_R: |
| 460 | opt->dccpop_type = DCCPO_CONFIRM_L; |
| 461 | break; |
| 462 | default: |
| 463 | DCCP_WARN("invalid type %d\n", type); |
| 464 | kfree(opt); |
| 465 | return; |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 466 | } |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 467 | opt->dccpop_feat = feature; |
Randy Dunlap | 68907da | 2006-03-29 13:58:25 -0800 | [diff] [blame] | 468 | opt->dccpop_val = NULL; |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 469 | opt->dccpop_len = 0; |
| 470 | |
| 471 | /* change feature */ |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 472 | dccp_pr_debug("Empty %s(%d)\n", dccp_feat_typename(type), feature); |
| 473 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 474 | list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | static void dccp_feat_flush_confirm(struct sock *sk) |
| 478 | { |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 479 | struct dccp_minisock *dmsk = dccp_msk(sk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 480 | /* Check if there is anything to confirm in the first place */ |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 481 | int yes = !list_empty(&dmsk->dccpms_conf); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 482 | |
| 483 | if (!yes) { |
| 484 | struct dccp_opt_pend *opt; |
| 485 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 486 | list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 487 | if (opt->dccpop_conf) { |
| 488 | yes = 1; |
| 489 | break; |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | if (!yes) |
| 495 | return; |
| 496 | |
| 497 | /* OK there is something to confirm... */ |
| 498 | /* XXX check if packet is in flight? Send delayed ack?? */ |
| 499 | if (sk->sk_state == DCCP_OPEN) |
| 500 | dccp_send_ack(sk); |
| 501 | } |
| 502 | |
| 503 | int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len) |
| 504 | { |
| 505 | int rc; |
| 506 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 507 | dccp_feat_debug(type, feature, *val); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 508 | |
| 509 | /* figure out if it's SP or NN feature */ |
| 510 | switch (feature) { |
| 511 | /* deal with SP features */ |
| 512 | case DCCPF_CCID: |
| 513 | rc = dccp_feat_sp(sk, type, feature, val, len); |
| 514 | break; |
| 515 | |
| 516 | /* deal with NN features */ |
| 517 | case DCCPF_ACK_RATIO: |
| 518 | rc = dccp_feat_nn(sk, type, feature, val, len); |
| 519 | break; |
| 520 | |
| 521 | /* XXX implement other features */ |
| 522 | default: |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 523 | dccp_pr_debug("UNIMPLEMENTED: not handling %s(%d, ...)\n", |
| 524 | dccp_feat_typename(type), feature); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 525 | rc = -EFAULT; |
| 526 | break; |
| 527 | } |
| 528 | |
| 529 | /* check if there were problems changing features */ |
| 530 | if (rc) { |
| 531 | /* If we don't agree on SP, we sent a confirm for old value. |
| 532 | * However we propagate rc to caller in case option was |
| 533 | * mandatory |
| 534 | */ |
| 535 | if (rc != DCCP_FEAT_SP_NOAGREE) |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 536 | dccp_feat_empty_confirm(dccp_msk(sk), type, feature); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /* generate the confirm [if required] */ |
| 540 | dccp_feat_flush_confirm(sk); |
| 541 | |
| 542 | return rc; |
| 543 | } |
| 544 | |
| 545 | EXPORT_SYMBOL_GPL(dccp_feat_change_recv); |
| 546 | |
| 547 | int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature, |
| 548 | u8 *val, u8 len) |
| 549 | { |
| 550 | u8 t; |
| 551 | struct dccp_opt_pend *opt; |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 552 | struct dccp_minisock *dmsk = dccp_msk(sk); |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 553 | int found = 0; |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 554 | int all_confirmed = 1; |
| 555 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 556 | dccp_feat_debug(type, feature, *val); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 557 | |
| 558 | /* locate our change request */ |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 559 | switch (type) { |
| 560 | case DCCPO_CONFIRM_L: t = DCCPO_CHANGE_R; break; |
| 561 | case DCCPO_CONFIRM_R: t = DCCPO_CHANGE_L; break; |
Arnaldo Carvalho de Melo | 8109b02 | 2006-12-10 16:01:18 -0200 | [diff] [blame] | 562 | default: DCCP_WARN("invalid type %d\n", type); |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 563 | return 1; |
| 564 | |
| 565 | } |
| 566 | /* XXX sanity check feature value */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 567 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 568 | list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 569 | if (!opt->dccpop_conf && opt->dccpop_type == t && |
| 570 | opt->dccpop_feat == feature) { |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 571 | found = 1; |
| 572 | dccp_pr_debug("feature %d found\n", opt->dccpop_feat); |
| 573 | |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 574 | /* XXX do sanity check */ |
| 575 | |
| 576 | opt->dccpop_conf = 1; |
| 577 | |
| 578 | /* We got a confirmation---change the option */ |
| 579 | dccp_feat_update(sk, opt->dccpop_type, |
| 580 | opt->dccpop_feat, *val); |
| 581 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 582 | /* XXX check the return value of dccp_feat_update */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 583 | break; |
| 584 | } |
| 585 | |
| 586 | if (!opt->dccpop_conf) |
| 587 | all_confirmed = 0; |
| 588 | } |
| 589 | |
| 590 | /* fix re-transmit timer */ |
| 591 | /* XXX gotta make sure that no option negotiation occurs during |
| 592 | * connection shutdown. Consider that the CLOSEREQ is sent and timer is |
| 593 | * on. if all options are confirmed it might kill timer which should |
| 594 | * remain alive until close is received. |
| 595 | */ |
| 596 | if (all_confirmed) { |
| 597 | dccp_pr_debug("clear feat negotiation timer %p\n", sk); |
| 598 | inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS); |
| 599 | } |
| 600 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 601 | if (!found) |
| 602 | dccp_pr_debug("%s(%d, ...) never requested\n", |
| 603 | dccp_feat_typename(type), feature); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 604 | return 0; |
| 605 | } |
| 606 | |
| 607 | EXPORT_SYMBOL_GPL(dccp_feat_confirm_recv); |
| 608 | |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 609 | void dccp_feat_clean(struct dccp_minisock *dmsk) |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 610 | { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 611 | struct dccp_opt_pend *opt, *next; |
| 612 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 613 | list_for_each_entry_safe(opt, next, &dmsk->dccpms_pending, |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 614 | dccpop_node) { |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 615 | BUG_ON(opt->dccpop_val == NULL); |
| 616 | kfree(opt->dccpop_val); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 617 | |
| 618 | if (opt->dccpop_sc != NULL) { |
| 619 | BUG_ON(opt->dccpop_sc->dccpoc_val == NULL); |
| 620 | kfree(opt->dccpop_sc->dccpoc_val); |
| 621 | kfree(opt->dccpop_sc); |
| 622 | } |
| 623 | |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 624 | kfree(opt); |
| 625 | } |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 626 | INIT_LIST_HEAD(&dmsk->dccpms_pending); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 627 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 628 | list_for_each_entry_safe(opt, next, &dmsk->dccpms_conf, dccpop_node) { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 629 | BUG_ON(opt == NULL); |
| 630 | if (opt->dccpop_val != NULL) |
| 631 | kfree(opt->dccpop_val); |
| 632 | kfree(opt); |
| 633 | } |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 634 | INIT_LIST_HEAD(&dmsk->dccpms_conf); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | EXPORT_SYMBOL_GPL(dccp_feat_clean); |
| 638 | |
| 639 | /* this is to be called only when a listening sock creates its child. It is |
| 640 | * assumed by the function---the confirm is not duplicated, but rather it is |
| 641 | * "passed on". |
| 642 | */ |
| 643 | int dccp_feat_clone(struct sock *oldsk, struct sock *newsk) |
| 644 | { |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 645 | struct dccp_minisock *olddmsk = dccp_msk(oldsk); |
| 646 | struct dccp_minisock *newdmsk = dccp_msk(newsk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 647 | struct dccp_opt_pend *opt; |
| 648 | int rc = 0; |
| 649 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 650 | INIT_LIST_HEAD(&newdmsk->dccpms_pending); |
| 651 | INIT_LIST_HEAD(&newdmsk->dccpms_conf); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 652 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 653 | list_for_each_entry(opt, &olddmsk->dccpms_pending, dccpop_node) { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 654 | struct dccp_opt_pend *newopt; |
| 655 | /* copy the value of the option */ |
Arnaldo Carvalho de Melo | eed7341 | 2006-11-17 12:21:43 -0200 | [diff] [blame] | 656 | u8 *val = kmemdup(opt->dccpop_val, opt->dccpop_len, GFP_ATOMIC); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 657 | |
| 658 | if (val == NULL) |
| 659 | goto out_clean; |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 660 | |
Arnaldo Carvalho de Melo | eed7341 | 2006-11-17 12:21:43 -0200 | [diff] [blame] | 661 | newopt = kmemdup(opt, sizeof(*newopt), GFP_ATOMIC); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 662 | if (newopt == NULL) { |
| 663 | kfree(val); |
| 664 | goto out_clean; |
| 665 | } |
| 666 | |
| 667 | /* insert the option */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 668 | newopt->dccpop_val = val; |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 669 | list_add_tail(&newopt->dccpop_node, &newdmsk->dccpms_pending); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 670 | |
| 671 | /* XXX what happens with backlogs and multiple connections at |
| 672 | * once... |
| 673 | */ |
| 674 | /* the master socket no longer needs to worry about confirms */ |
Randy Dunlap | 68907da | 2006-03-29 13:58:25 -0800 | [diff] [blame] | 675 | opt->dccpop_sc = NULL; /* it's not a memleak---new socket has it */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 676 | |
| 677 | /* reset state for a new socket */ |
| 678 | opt->dccpop_conf = 0; |
| 679 | } |
| 680 | |
| 681 | /* XXX not doing anything about the conf queue */ |
| 682 | |
| 683 | out: |
| 684 | return rc; |
| 685 | |
| 686 | out_clean: |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 687 | dccp_feat_clean(newdmsk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 688 | rc = -ENOMEM; |
| 689 | goto out; |
| 690 | } |
| 691 | |
| 692 | EXPORT_SYMBOL_GPL(dccp_feat_clone); |
| 693 | |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 694 | static int __dccp_feat_init(struct dccp_minisock *dmsk, u8 type, u8 feat, |
| 695 | u8 *val, u8 len) |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 696 | { |
| 697 | int rc = -ENOMEM; |
Arnaldo Carvalho de Melo | eed7341 | 2006-11-17 12:21:43 -0200 | [diff] [blame] | 698 | u8 *copy = kmemdup(val, len, GFP_KERNEL); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 699 | |
| 700 | if (copy != NULL) { |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 701 | rc = dccp_feat_change(dmsk, type, feat, copy, len, GFP_KERNEL); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 702 | if (rc) |
| 703 | kfree(copy); |
| 704 | } |
| 705 | return rc; |
| 706 | } |
| 707 | |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 708 | int dccp_feat_init(struct dccp_minisock *dmsk) |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 709 | { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 710 | int rc; |
| 711 | |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 712 | INIT_LIST_HEAD(&dmsk->dccpms_pending); |
| 713 | INIT_LIST_HEAD(&dmsk->dccpms_conf); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 714 | |
| 715 | /* CCID L */ |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 716 | rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_L, DCCPF_CCID, |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 717 | &dmsk->dccpms_tx_ccid, 1); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 718 | if (rc) |
| 719 | goto out; |
| 720 | |
| 721 | /* CCID R */ |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 722 | rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_R, DCCPF_CCID, |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 723 | &dmsk->dccpms_rx_ccid, 1); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 724 | if (rc) |
| 725 | goto out; |
| 726 | |
| 727 | /* Ack ratio */ |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 728 | rc = __dccp_feat_init(dmsk, DCCPO_CHANGE_L, DCCPF_ACK_RATIO, |
Arnaldo Carvalho de Melo | a4bf390 | 2006-03-20 22:50:58 -0800 | [diff] [blame] | 729 | &dmsk->dccpms_ack_ratio, 1); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 730 | out: |
| 731 | return rc; |
| 732 | } |
| 733 | |
| 734 | EXPORT_SYMBOL_GPL(dccp_feat_init); |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 735 | |
| 736 | #ifdef CONFIG_IP_DCCP_DEBUG |
| 737 | const char *dccp_feat_typename(const u8 type) |
| 738 | { |
| 739 | switch(type) { |
| 740 | case DCCPO_CHANGE_L: return("ChangeL"); |
| 741 | case DCCPO_CONFIRM_L: return("ConfirmL"); |
| 742 | case DCCPO_CHANGE_R: return("ChangeR"); |
| 743 | case DCCPO_CONFIRM_R: return("ConfirmR"); |
| 744 | /* the following case must not appear in feature negotation */ |
Arnaldo Carvalho de Melo | 8109b02 | 2006-12-10 16:01:18 -0200 | [diff] [blame] | 745 | default: dccp_pr_debug("unknown type %d [BUG!]\n", type); |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 746 | } |
| 747 | return NULL; |
| 748 | } |
| 749 | |
| 750 | EXPORT_SYMBOL_GPL(dccp_feat_typename); |
| 751 | |
| 752 | const char *dccp_feat_name(const u8 feat) |
| 753 | { |
| 754 | static const char *feature_names[] = { |
| 755 | [DCCPF_RESERVED] = "Reserved", |
| 756 | [DCCPF_CCID] = "CCID", |
| 757 | [DCCPF_SHORT_SEQNOS] = "Allow Short Seqnos", |
| 758 | [DCCPF_SEQUENCE_WINDOW] = "Sequence Window", |
| 759 | [DCCPF_ECN_INCAPABLE] = "ECN Incapable", |
| 760 | [DCCPF_ACK_RATIO] = "Ack Ratio", |
| 761 | [DCCPF_SEND_ACK_VECTOR] = "Send ACK Vector", |
| 762 | [DCCPF_SEND_NDP_COUNT] = "Send NDP Count", |
| 763 | [DCCPF_MIN_CSUM_COVER] = "Min. Csum Coverage", |
| 764 | [DCCPF_DATA_CHECKSUM] = "Send Data Checksum", |
| 765 | }; |
Gerrit Renker | dd6303d | 2007-12-13 12:40:40 -0200 | [diff] [blame] | 766 | if (feat > DCCPF_DATA_CHECKSUM && feat < DCCPF_MIN_CCID_SPECIFIC) |
| 767 | return feature_names[DCCPF_RESERVED]; |
| 768 | |
Gerrit Renker | b4eec20 | 2008-09-04 07:30:19 +0200 | [diff] [blame^] | 769 | if (feat == DCCPF_SEND_LEV_RATE) |
| 770 | return "Send Loss Event Rate"; |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 771 | if (feat >= DCCPF_MIN_CCID_SPECIFIC) |
| 772 | return "CCID-specific"; |
| 773 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 774 | return feature_names[feat]; |
| 775 | } |
| 776 | |
| 777 | EXPORT_SYMBOL_GPL(dccp_feat_name); |
| 778 | #endif /* CONFIG_IP_DCCP_DEBUG */ |