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