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