qdisc_api.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * lib/route/qdisc_api.c Queueing Discipline 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 qdisc
  13. * @defgroup qdisc_api Queueing Discipline 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/link.h>
  21. #include <netlink/route/tc.h>
  22. #include <netlink/route/qdisc.h>
  23. #include <netlink/route/class.h>
  24. #include <netlink/route/classifier.h>
  25. #include <netlink/route/qdisc-modules.h>
  26. static struct rtnl_qdisc_ops *qdisc_ops_list;
  27. /**
  28. * @name Module API
  29. * @{
  30. */
  31. /**
  32. * Register a qdisc module
  33. * @arg qops qdisc module operations
  34. */
  35. int rtnl_qdisc_register(struct rtnl_qdisc_ops *qops)
  36. {
  37. struct rtnl_qdisc_ops *o, **op;
  38. if (!qops->qo_kind[0])
  39. BUG();
  40. for (op = &qdisc_ops_list; (o = *op) != NULL; op = &o->qo_next)
  41. if (!strcasecmp(qops->qo_kind, o->qo_kind))
  42. return nl_errno(EEXIST);
  43. qops->qo_next = NULL;
  44. *op = qops;
  45. return 0;
  46. }
  47. /**
  48. * Unregister a qdisc module
  49. * @arg qops qdisc module operations
  50. */
  51. int rtnl_qdisc_unregister(struct rtnl_qdisc_ops *qops)
  52. {
  53. struct rtnl_qdisc_ops *o, **op;
  54. for (op = &qdisc_ops_list; (o = *op) != NULL; op = &o->qo_next)
  55. if (!strcasecmp(qops->qo_kind, o->qo_kind))
  56. break;
  57. if (!o)
  58. return nl_errno(ENOENT);
  59. *op = qops->qo_next;
  60. return 0;
  61. }
  62. struct rtnl_qdisc_ops *__rtnl_qdisc_lookup_ops(const char *kind)
  63. {
  64. struct rtnl_qdisc_ops *qops;
  65. for (qops = qdisc_ops_list; qops; qops = qops->qo_next)
  66. if (!strcmp(kind, qops->qo_kind))
  67. return qops;
  68. return NULL;
  69. }
  70. struct rtnl_qdisc_ops *rtnl_qdisc_lookup_ops(struct rtnl_qdisc *qdisc)
  71. {
  72. if (!qdisc->q_ops)
  73. qdisc->q_ops = __rtnl_qdisc_lookup_ops(qdisc->q_kind);
  74. return qdisc->q_ops;
  75. }
  76. /** @} */
  77. /** @} */