1/*
2 * DiffServ classname <-> DiffServ codepoint mapping functions.
3 *
4 * The latest list of the mappings can be found at:
5 * <http://www.iana.org/assignments/dscp-registry>
6 *
7 * This code is released under the GNU GPL v2, 1991
8 *
9 * Author: Iain Barnes
10 */
11
12#include <stdio.h>
13#include <string.h>
14#include <iptables_common.h>
15
16
17
18static struct ds_class
19{
20	const char *name;
21	unsigned int dscp;
22} ds_classes[] =
23{
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 }
46};
47
48
49
50static unsigned int
51class_to_dscp(const char *name)
52{
53	int i;
54
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;
59	}
60
61	exit_error(PARAMETER_PROBLEM,
62			"Invalid DSCP value `%s'\n", name);
63}
64