cls_api.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * lib/route/cls_api.c Classifier Module API
  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. /**
  12. * @ingroup cls
  13. * @defgroup cls_api Classifier Modules
  14. * @{
  15. */
  16. #include <netlink-local.h>
  17. #include <netlink-tc.h>
  18. #include <netlink/netlink.h>
  19. #include <netlink/utils.h>
  20. #include <netlink/route/tc.h>
  21. #include <netlink/route/classifier.h>
  22. #include <netlink/route/classifier-modules.h>
  23. #include <netlink/route/link.h>
  24. static struct rtnl_cls_ops *cls_ops_list;
  25. /**
  26. * @name Classifier Module API
  27. * @{
  28. */
  29. /**
  30. * Register a classifier module
  31. * @arg cops classifier module operations
  32. */
  33. int rtnl_cls_register(struct rtnl_cls_ops *cops)
  34. {
  35. struct rtnl_cls_ops *o, **op;
  36. if (!cops->co_kind)
  37. BUG();
  38. for (op = &cls_ops_list; (o = *op) != NULL; op = &o->co_next)
  39. if (!strcasecmp(cops->co_kind, o->co_kind))
  40. return nl_errno(EEXIST);
  41. cops->co_next = NULL;
  42. *op = cops;
  43. return 0;
  44. }
  45. /**
  46. * Unregister a classifier module
  47. * @arg cops classifier module operations
  48. */
  49. int rtnl_cls_unregister(struct rtnl_cls_ops *cops)
  50. {
  51. struct rtnl_cls_ops *o, **op;
  52. for (op = &cls_ops_list; (o = *op) != NULL; op = &o->co_next)
  53. if (!strcasecmp(cops->co_kind, o->co_kind))
  54. break;
  55. if (!o)
  56. return nl_errno(ENOENT);
  57. *op = cops->co_next;
  58. return 0;
  59. }
  60. struct rtnl_cls_ops *__rtnl_cls_lookup_ops(const char *kind)
  61. {
  62. struct rtnl_cls_ops *cops;
  63. for (cops = cls_ops_list; cops; cops = cops->co_next)
  64. if (!strcmp(kind, cops->co_kind))
  65. return cops;
  66. return NULL;
  67. }
  68. /**
  69. * Lookup classifier operations for a classifier object
  70. * @arg cls Classifier object.
  71. *
  72. * @return Classifier operations or NULL if not found.
  73. */
  74. struct rtnl_cls_ops *rtnl_cls_lookup_ops(struct rtnl_cls *cls)
  75. {
  76. if (!cls->c_ops)
  77. cls->c_ops = __rtnl_cls_lookup_ops(cls->c_kind);
  78. return cls->c_ops;
  79. }
  80. /** @} */
  81. /** @} */