family.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * netlink/genl/family.h Generic Netlink Family
  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. #ifndef NETLINK_GENL_FAMILY_H_
  12. #define NETLINK_GENL_FAMILY_H_
  13. #include <netlink/netlink.h>
  14. #include <netlink/cache.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /** @cond SKIP */
  19. #define FAMILY_ATTR_ID 0x01
  20. #define FAMILY_ATTR_NAME 0x02
  21. #define FAMILY_ATTR_VERSION 0x04
  22. #define FAMILY_ATTR_HDRSIZE 0x08
  23. #define FAMILY_ATTR_MAXATTR 0x10
  24. #define FAMILY_ATTR_OPS 0x20
  25. struct genl_family
  26. {
  27. NLHDR_COMMON
  28. uint16_t gf_id;
  29. char gf_name[GENL_NAMSIZ];
  30. uint32_t gf_version;
  31. uint32_t gf_hdrsize;
  32. uint32_t gf_maxattr;
  33. struct nl_list_head gf_ops;
  34. struct nl_list_head gf_mc_grps;
  35. };
  36. extern struct genl_family * genl_family_alloc(void);
  37. extern void genl_family_put(struct genl_family *);
  38. extern int genl_family_add_op(struct genl_family *,
  39. int, int);
  40. extern int genl_family_add_grp(struct genl_family *,
  41. uint32_t , const char *);
  42. /**
  43. * @name Attributes
  44. * @{
  45. */
  46. static inline unsigned int genl_family_get_id(struct genl_family *family)
  47. {
  48. if (family->ce_mask & FAMILY_ATTR_ID)
  49. return family->gf_id;
  50. else
  51. return 0;
  52. }
  53. static inline void genl_family_set_id(struct genl_family *family, unsigned int id)
  54. {
  55. family->gf_id = id;
  56. family->ce_mask |= FAMILY_ATTR_ID;
  57. }
  58. static inline char *genl_family_get_name(struct genl_family *family)
  59. {
  60. if (family->ce_mask & FAMILY_ATTR_NAME)
  61. return family->gf_name;
  62. else
  63. return NULL;
  64. }
  65. static inline void genl_family_set_name(struct genl_family *family, const char *name)
  66. {
  67. strncpy(family->gf_name, name, GENL_NAMSIZ-1);
  68. family->gf_name[GENL_NAMSIZ - 1] = '\0';
  69. family->ce_mask |= FAMILY_ATTR_NAME;
  70. }
  71. static inline uint8_t genl_family_get_version(struct genl_family *family)
  72. {
  73. if (family->ce_mask & FAMILY_ATTR_VERSION)
  74. return family->gf_version;
  75. else
  76. return 0;
  77. }
  78. static inline void genl_family_set_version(struct genl_family *family, uint8_t version)
  79. {
  80. family->gf_version = version;
  81. family->ce_mask |= FAMILY_ATTR_VERSION;
  82. }
  83. static inline uint32_t genl_family_get_hdrsize(struct genl_family *family)
  84. {
  85. if (family->ce_mask & FAMILY_ATTR_HDRSIZE)
  86. return family->gf_hdrsize;
  87. else
  88. return 0;
  89. }
  90. static inline void genl_family_set_hdrsize(struct genl_family *family, uint32_t hdrsize)
  91. {
  92. family->gf_hdrsize = hdrsize;
  93. family->ce_mask |= FAMILY_ATTR_HDRSIZE;
  94. }
  95. static inline uint32_t genl_family_get_maxattr(struct genl_family *family)
  96. {
  97. if (family->ce_mask & FAMILY_ATTR_MAXATTR)
  98. return family->gf_maxattr;
  99. else
  100. return 0;
  101. }
  102. static inline void genl_family_set_maxattr(struct genl_family *family, uint32_t maxattr)
  103. {
  104. family->gf_maxattr = maxattr;
  105. family->ce_mask |= FAMILY_ATTR_MAXATTR;
  106. }
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif