police.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * lib/route/cls/police.c Policer
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation version 2.1
  7. * of the License.
  8. *
  9. * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
  10. */
  11. #include <netlink-local.h>
  12. #include <netlink-tc.h>
  13. #include <netlink/netlink.h>
  14. #include <netlink/utils.h>
  15. #include <netlink/route/tc.h>
  16. #include <netlink/route/classifier.h>
  17. #include <netlink/route/classifier-modules.h>
  18. #include <netlink/route/cls/police.h>
  19. /**
  20. * @name Policer Type
  21. * @{
  22. */
  23. static struct trans_tbl police_types[] = {
  24. __ADD(TC_POLICE_UNSPEC,unspec)
  25. __ADD(TC_POLICE_OK,ok)
  26. __ADD(TC_POLICE_RECLASSIFY,reclassify)
  27. __ADD(TC_POLICE_SHOT,shot)
  28. #ifdef TC_POLICE_PIPE
  29. __ADD(TC_POLICE_PIPE,pipe)
  30. #endif
  31. };
  32. /**
  33. * Transform a policer type number into a character string (Reentrant).
  34. * @arg type policer type
  35. * @arg buf destination buffer
  36. * @arg len buffer length
  37. *
  38. * Transforms a policer type number into a character string and stores
  39. * it in the provided buffer.
  40. *
  41. * @return The destination buffer or the type encoded in hex if no match was found.
  42. */
  43. char * nl_police2str(int type, char *buf, size_t len)
  44. {
  45. return __type2str(type, buf, len, police_types,
  46. ARRAY_SIZE(police_types));
  47. }
  48. /**
  49. * Transform a character string into a policer type number
  50. * @arg name policer type name
  51. *
  52. * Transform the provided character string specifying a policer
  53. * type into the corresponding numeric value
  54. *
  55. * @return Policer type number or a negative value.
  56. */
  57. int nl_str2police(const char *name)
  58. {
  59. return __str2type(name, police_types, ARRAY_SIZE(police_types));
  60. }
  61. /** @} */