K2.6 patches and update.
[tomato.git] / release / src / router / iptables / extensions / libipt_dscp_helper.c
blob31adb6cd632c8425c41cb1dd619402b6e057b165
1 /*
2 * DiffServ classname <-> DiffServ codepoint mapping functions.
4 * The latest list of the mappings can be found at:
5 * <http://www.iana.org/assignments/dscp-registry>
7 * This code is released under the GNU GPL v2, 1991
8 *
9 * Author: Iain Barnes
12 #include <stdio.h>
13 #include <string.h>
14 #include <iptables_common.h>
18 static struct ds_class
20 const char *name;
21 unsigned int dscp;
22 } ds_classes[] =
24 { "CS0", 0x00 },
25 { "CS1", 0x08 },
26 { "CS2", 0x10 },
27 { "CS3", 0x18 },
28 { "CS4", 0x20 },
29 { "CS5", 0x28 },
30 { "CS6", 0x30 },
31 { "CS7", 0x38 },
32 { "BE", 0x00 },
33 { "AF11", 0x0a },
34 { "AF12", 0x0c },
35 { "AF13", 0x0e },
36 { "AF21", 0x12 },
37 { "AF22", 0x14 },
38 { "AF23", 0x16 },
39 { "AF31", 0x1a },
40 { "AF32", 0x1c },
41 { "AF33", 0x1e },
42 { "AF41", 0x22 },
43 { "AF42", 0x24 },
44 { "AF43", 0x26 },
45 { "EF", 0x2e }
50 static unsigned int
51 class_to_dscp(const char *name)
53 int i;
55 for (i = 0; i < sizeof(ds_classes) / sizeof(struct ds_class); i++) {
56 if (!strncasecmp(name, ds_classes[i].name,
57 strlen(ds_classes[i].name)))
58 return ds_classes[i].dscp;
61 exit_error(PARAMETER_PROBLEM,
62 "Invalid DSCP value `%s'\n", name);
66 #if 0
67 static const char *
68 dscp_to_name(unsigned int dscp)
70 int i;
72 for (i = 0; i < sizeof(ds_classes) / sizeof(struct ds_class); i++) {
73 if (dscp == ds_classes[i].dscp)
74 return ds_classes[i].name;
78 exit_error(PARAMETER_PROBLEM,
79 "Invalid DSCP value `%d'\n", dscp);
81 #endif