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