| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 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 <xtables.h> | 
|  | 15 |  | 
|  | 16 |  | 
|  | 17 | static const struct ds_class | 
|  | 18 | { | 
|  | 19 | const char *name; | 
|  | 20 | unsigned int dscp; | 
|  | 21 | } ds_classes[] = | 
|  | 22 | { | 
|  | 23 | { "CS0", 0x00 }, | 
|  | 24 | { "CS1", 0x08 }, | 
|  | 25 | { "CS2", 0x10 }, | 
|  | 26 | { "CS3", 0x18 }, | 
|  | 27 | { "CS4", 0x20 }, | 
|  | 28 | { "CS5", 0x28 }, | 
|  | 29 | { "CS6", 0x30 }, | 
|  | 30 | { "CS7", 0x38 }, | 
|  | 31 | { "BE", 0x00 }, | 
|  | 32 | { "AF11", 0x0a }, | 
|  | 33 | { "AF12", 0x0c }, | 
|  | 34 | { "AF13", 0x0e }, | 
|  | 35 | { "AF21", 0x12 }, | 
|  | 36 | { "AF22", 0x14 }, | 
|  | 37 | { "AF23", 0x16 }, | 
|  | 38 | { "AF31", 0x1a }, | 
|  | 39 | { "AF32", 0x1c }, | 
|  | 40 | { "AF33", 0x1e }, | 
|  | 41 | { "AF41", 0x22 }, | 
|  | 42 | { "AF42", 0x24 }, | 
|  | 43 | { "AF43", 0x26 }, | 
|  | 44 | { "EF", 0x2e } | 
|  | 45 | }; | 
|  | 46 |  | 
|  | 47 |  | 
|  | 48 |  | 
|  | 49 | static unsigned int | 
|  | 50 | class_to_dscp(const char *name) | 
|  | 51 | { | 
|  | 52 | unsigned int i; | 
|  | 53 |  | 
|  | 54 | for (i = 0; i < sizeof(ds_classes) / sizeof(struct ds_class); i++) { | 
|  | 55 | if (!strncasecmp(name, ds_classes[i].name, | 
|  | 56 | strlen(ds_classes[i].name))) | 
|  | 57 | return ds_classes[i].dscp; | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | xtables_error(PARAMETER_PROBLEM, | 
|  | 61 | "Invalid DSCP value `%s'\n", name); | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 |  | 
|  | 65 | #if 0 | 
|  | 66 | static const char * | 
|  | 67 | dscp_to_name(unsigned int dscp) | 
|  | 68 | { | 
|  | 69 | int i; | 
|  | 70 |  | 
|  | 71 | for (i = 0; i < sizeof(ds_classes) / sizeof(struct ds_class); i++) { | 
|  | 72 | if (dscp == ds_classes[i].dscp) | 
|  | 73 | return ds_classes[i].name; | 
|  | 74 | } | 
|  | 75 |  | 
|  | 76 |  | 
|  | 77 | xtables_error(PARAMETER_PROBLEM, | 
|  | 78 | "Invalid DSCP value `%d'\n", dscp); | 
|  | 79 | } | 
|  | 80 | #endif | 
|  | 81 |  |