dscp_helper.c 1.4 KB

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