api.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * netlink-private/route/link/api.h Link Modules 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-2013 Thomas Graf <tgraf@suug.ch>
  10. */
  11. #ifndef NETLINK_LINK_API_H_
  12. #define NETLINK_LINK_API_H_
  13. #include <netlink/netlink.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /**
  18. * @ingroup link_api
  19. *
  20. * Available operations to modules implementing a link info type.
  21. */
  22. struct rtnl_link_info_ops
  23. {
  24. /** Name of link info type, must match name on kernel side */
  25. char * io_name;
  26. /** Reference count, DO NOT MODIFY */
  27. int io_refcnt;
  28. /** Called to assign an info type to a link.
  29. * Has to allocate enough resources to hold attributes. Can
  30. * use link->l_info to store a pointer. */
  31. int (*io_alloc)(struct rtnl_link *);
  32. /** Called to parse the link info attribute.
  33. * Must parse the attribute and assign all values to the link.
  34. */
  35. int (*io_parse)(struct rtnl_link *,
  36. struct nlattr *,
  37. struct nlattr *);
  38. /** Called when the link object is dumped.
  39. * Must dump the info type specific attributes. */
  40. void (*io_dump[NL_DUMP_MAX+1])(struct rtnl_link *,
  41. struct nl_dump_params *);
  42. /** Called when a link object is cloned.
  43. * Must clone all info type specific attributes. */
  44. int (*io_clone)(struct rtnl_link *, struct rtnl_link *);
  45. /** Called when construction a link netlink message.
  46. * Must append all info type specific attributes to the message. */
  47. int (*io_put_attrs)(struct nl_msg *, struct rtnl_link *);
  48. /** Called to release all resources previously allocated
  49. * in either io_alloc() or io_parse(). */
  50. void (*io_free)(struct rtnl_link *);
  51. struct nl_list_head io_list;
  52. };
  53. extern struct rtnl_link_info_ops *rtnl_link_info_ops_lookup(const char *);
  54. extern void rtnl_link_info_ops_put(struct rtnl_link_info_ops *);
  55. extern int rtnl_link_register_info(struct rtnl_link_info_ops *);
  56. extern int rtnl_link_unregister_info(struct rtnl_link_info_ops *);
  57. /**
  58. * @ingroup link_api
  59. *
  60. * Available operations to modules implementing a link address family.
  61. */
  62. struct rtnl_link_af_ops
  63. {
  64. /** The address family this operations set implements */
  65. const unsigned int ao_family;
  66. /** Number of users of this operations, DO NOT MODIFY. */
  67. int ao_refcnt;
  68. /** Validation policy for IFLA_PROTINFO attribute. This pointer
  69. * can be set to a nla_policy structure describing the minimal
  70. * requirements the attribute must meet. Failure of meeting these
  71. * requirements will result in a parsing error. */
  72. const struct nla_policy *ao_protinfo_policy;
  73. /** Called after address family has been assigned to link. Must
  74. * allocate data buffer to hold address family specific data and
  75. * store it in link->l_af_data. */
  76. void * (*ao_alloc)(struct rtnl_link *);
  77. /** Called when the link is cloned, must allocate a clone of the
  78. * address family specific buffer and return it. */
  79. void * (*ao_clone)(struct rtnl_link *, void *);
  80. /** Called when the link gets freed. Must free all allocated data */
  81. void (*ao_free)(struct rtnl_link *, void *);
  82. /** Called if a IFLA_PROTINFO attribute needs to be parsed. Typically
  83. * stores the parsed data in the address family specific buffer. */
  84. int (*ao_parse_protinfo)(struct rtnl_link *,
  85. struct nlattr *, void *);
  86. /** Called if a IFLA_AF_SPEC attribute needs to be parsed. Typically
  87. * stores the parsed data in the address family specific buffer. */
  88. int (*ao_parse_af)(struct rtnl_link *,
  89. struct nlattr *, void *);
  90. /** Called if a link message is sent to the kernel. Must append the
  91. * link address family specific attributes to the message. */
  92. int (*ao_fill_af)(struct rtnl_link *,
  93. struct nl_msg *msg, void *);
  94. /** Dump address family specific link attributes */
  95. void (*ao_dump[NL_DUMP_MAX+1])(struct rtnl_link *,
  96. struct nl_dump_params *,
  97. void *);
  98. /** Comparison function
  99. *
  100. * Will be called when two links are compared for their af data. It
  101. * takes two link objects in question, an object specific bitmask
  102. * defining which attributes should be compared and flags to control
  103. * the behaviour
  104. *
  105. * The function must return a bitmask with the relevant bit set for
  106. * each attribute that mismatches
  107. */
  108. int (*ao_compare)(struct rtnl_link *,
  109. struct rtnl_link *, int, uint32_t, int);
  110. };
  111. extern struct rtnl_link_af_ops *rtnl_link_af_ops_lookup(unsigned int);
  112. extern void rtnl_link_af_ops_put(struct rtnl_link_af_ops *);
  113. extern void * rtnl_link_af_alloc(struct rtnl_link *,
  114. const struct rtnl_link_af_ops *);
  115. extern void * rtnl_link_af_data(const struct rtnl_link *,
  116. const struct rtnl_link_af_ops *);
  117. extern int rtnl_link_af_register(struct rtnl_link_af_ops *);
  118. extern int rtnl_link_af_unregister(struct rtnl_link_af_ops *);
  119. extern int rtnl_link_af_data_compare(struct rtnl_link *a,
  120. struct rtnl_link *b,
  121. int family);
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #endif