police.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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-2013 Thomas Graf <tgraf@suug.ch>
  10. */
  11. #include <netlink-private/netlink.h>
  12. #include <netlink-private/tc.h>
  13. #include <netlink/netlink.h>
  14. #include <netlink/utils.h>
  15. #include <netlink-private/route/tc-api.h>
  16. #include <netlink/route/classifier.h>
  17. #include <netlink/route/cls/police.h>
  18. /**
  19. * @name Policer Type
  20. * @{
  21. */
  22. static const struct trans_tbl police_types[] = {
  23. __ADD(TC_POLICE_UNSPEC,unspec)
  24. __ADD(TC_POLICE_OK,ok)
  25. __ADD(TC_POLICE_RECLASSIFY,reclassify)
  26. __ADD(TC_POLICE_SHOT,shot)
  27. #ifdef TC_POLICE_PIPE
  28. __ADD(TC_POLICE_PIPE,pipe)
  29. #endif
  30. };
  31. /**
  32. * Transform a policer type number into a character string (Reentrant).
  33. * @arg type policer type
  34. * @arg buf destination buffer
  35. * @arg len buffer length
  36. *
  37. * Transforms a policer type number into a character string and stores
  38. * it in the provided buffer.
  39. *
  40. * @return The destination buffer or the type encoded in hex if no match was found.
  41. */
  42. char * nl_police2str(int type, char *buf, size_t len)
  43. {
  44. return __type2str(type, buf, len, police_types,
  45. ARRAY_SIZE(police_types));
  46. }
  47. /**
  48. * Transform a character string into a policer type number
  49. * @arg name policer type name
  50. *
  51. * Transform the provided character string specifying a policer
  52. * type into the corresponding numeric value
  53. *
  54. * @return Policer type number or a negative value.
  55. */
  56. int nl_str2police(const char *name)
  57. {
  58. return __str2type(name, police_types, ARRAY_SIZE(police_types));
  59. }
  60. /** @} */