1
2#ifndef GENL_MAGIC_STRUCT_H
3#define GENL_MAGIC_STRUCT_H
4
5#ifndef GENL_MAGIC_FAMILY
6# error "you need to define GENL_MAGIC_FAMILY before inclusion"
7#endif
8
9#ifndef GENL_MAGIC_VERSION
10# error "you need to define GENL_MAGIC_VERSION before inclusion"
11#endif
12
13#ifndef GENL_MAGIC_INCLUDE_FILE
14# error "you need to define GENL_MAGIC_INCLUDE_FILE before inclusion"
15#endif
16
17#include <linux/genetlink.h>
18#include <linux/types.h>
19
20#define CONCAT__(a,b) a ## b
21#define CONCAT_(a,b) CONCAT__(a,b)
22
23extern int CONCAT_(GENL_MAGIC_FAMILY, _genl_register)(void);
24extern void CONCAT_(GENL_MAGIC_FAMILY, _genl_unregister)(void);
25
26
27
28
29
30
31
32
33
34
35
36
37
38#define DRBD_GENLA_F_MANDATORY (1 << 14)
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53#define DRBD_F_REQUIRED (1 << 0)
54#define DRBD_F_SENSITIVE (1 << 1)
55#define DRBD_F_INVARIANT (1 << 2)
56
57#define __nla_type(x) ((__u16)((x) & NLA_TYPE_MASK & ~DRBD_GENLA_F_MANDATORY))
58
59
60
61
62
63
64
65
66static inline int nla_put_u64_0pad(struct sk_buff *skb, int attrtype, u64 value)
67{
68 return nla_put_64bit(skb, attrtype, sizeof(u64), &value, 0);
69}
70
71
72#define __flg_field(attr_nr, attr_flag, name) \
73 __field(attr_nr, attr_flag, name, NLA_U8, char, \
74 nla_get_u8, nla_put_u8, false)
75#define __u8_field(attr_nr, attr_flag, name) \
76 __field(attr_nr, attr_flag, name, NLA_U8, unsigned char, \
77 nla_get_u8, nla_put_u8, false)
78#define __u16_field(attr_nr, attr_flag, name) \
79 __field(attr_nr, attr_flag, name, NLA_U16, __u16, \
80 nla_get_u16, nla_put_u16, false)
81#define __u32_field(attr_nr, attr_flag, name) \
82 __field(attr_nr, attr_flag, name, NLA_U32, __u32, \
83 nla_get_u32, nla_put_u32, false)
84#define __s32_field(attr_nr, attr_flag, name) \
85 __field(attr_nr, attr_flag, name, NLA_U32, __s32, \
86 nla_get_u32, nla_put_u32, true)
87#define __u64_field(attr_nr, attr_flag, name) \
88 __field(attr_nr, attr_flag, name, NLA_U64, __u64, \
89 nla_get_u64, nla_put_u64_0pad, false)
90#define __str_field(attr_nr, attr_flag, name, maxlen) \
91 __array(attr_nr, attr_flag, name, NLA_NUL_STRING, char, maxlen, \
92 nla_strlcpy, nla_put, false)
93#define __bin_field(attr_nr, attr_flag, name, maxlen) \
94 __array(attr_nr, attr_flag, name, NLA_BINARY, char, maxlen, \
95 nla_memcpy, nla_put, false)
96
97
98#define __flg_field_def(attr_nr, attr_flag, name, default) \
99 __flg_field(attr_nr, attr_flag, name)
100#define __u32_field_def(attr_nr, attr_flag, name, default) \
101 __u32_field(attr_nr, attr_flag, name)
102#define __s32_field_def(attr_nr, attr_flag, name, default) \
103 __s32_field(attr_nr, attr_flag, name)
104#define __str_field_def(attr_nr, attr_flag, name, maxlen) \
105 __str_field(attr_nr, attr_flag, name, maxlen)
106
107#define GENL_op_init(args...) args
108#define GENL_doit(handler) \
109 .doit = handler, \
110 .flags = GENL_ADMIN_PERM,
111#define GENL_dumpit(handler) \
112 .dumpit = handler, \
113 .flags = GENL_ADMIN_PERM,
114
115
116
117
118
119
120
121
122#undef GENL_struct
123#define GENL_struct(tag_name, tag_number, s_name, s_fields)
124
125#undef GENL_mc_group
126#define GENL_mc_group(group)
127
128#undef GENL_notification
129#define GENL_notification(op_name, op_num, mcast_group, tla_list) \
130 op_name = op_num,
131
132#undef GENL_op
133#define GENL_op(op_name, op_num, handler, tla_list) \
134 op_name = op_num,
135
136enum {
137#include GENL_MAGIC_INCLUDE_FILE
138};
139
140#undef GENL_notification
141#define GENL_notification(op_name, op_num, mcast_group, tla_list)
142
143#undef GENL_op
144#define GENL_op(op_name, op_num, handler, attr_list)
145
146#undef GENL_struct
147#define GENL_struct(tag_name, tag_number, s_name, s_fields) \
148 tag_name = tag_number,
149
150enum {
151#include GENL_MAGIC_INCLUDE_FILE
152};
153
154#undef GENL_struct
155#define GENL_struct(tag_name, tag_number, s_name, s_fields) \
156enum { \
157 s_fields \
158};
159
160#undef __field
161#define __field(attr_nr, attr_flag, name, nla_type, type, \
162 __get, __put, __is_signed) \
163 T_ ## name = (__u16)(attr_nr | ((attr_flag) & DRBD_GENLA_F_MANDATORY)),
164
165#undef __array
166#define __array(attr_nr, attr_flag, name, nla_type, type, \
167 maxlen, __get, __put, __is_signed) \
168 T_ ## name = (__u16)(attr_nr | ((attr_flag) & DRBD_GENLA_F_MANDATORY)),
169
170#include GENL_MAGIC_INCLUDE_FILE
171
172
173
174
175
176
177
178
179#undef GENL_struct
180#define GENL_struct(tag_name, tag_number, s_name, s_fields)
181
182#undef GENL_op
183#define GENL_op(op_name, op_num, handler, attr_list) \
184 case op_name:
185
186#undef GENL_notification
187#define GENL_notification(op_name, op_num, mcast_group, tla_list) \
188 case op_name:
189
190static inline void ct_assert_unique_operations(void)
191{
192 switch (0) {
193#include GENL_MAGIC_INCLUDE_FILE
194 ;
195 }
196}
197
198#undef GENL_op
199#define GENL_op(op_name, op_num, handler, attr_list)
200
201#undef GENL_notification
202#define GENL_notification(op_name, op_num, mcast_group, tla_list)
203
204#undef GENL_struct
205#define GENL_struct(tag_name, tag_number, s_name, s_fields) \
206 case tag_number:
207
208static inline void ct_assert_unique_top_level_attributes(void)
209{
210 switch (0) {
211#include GENL_MAGIC_INCLUDE_FILE
212 ;
213 }
214}
215
216#undef GENL_struct
217#define GENL_struct(tag_name, tag_number, s_name, s_fields) \
218static inline void ct_assert_unique_ ## s_name ## _attributes(void) \
219{ \
220 switch (0) { \
221 s_fields \
222 ; \
223 } \
224}
225
226#undef __field
227#define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \
228 __is_signed) \
229 case attr_nr:
230
231#undef __array
232#define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \
233 __get, __put, __is_signed) \
234 case attr_nr:
235
236#include GENL_MAGIC_INCLUDE_FILE
237
238
239
240
241
242
243
244
245
246#undef GENL_struct
247#define GENL_struct(tag_name, tag_number, s_name, s_fields) \
248struct s_name { s_fields };
249
250#undef __field
251#define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \
252 __is_signed) \
253 type name;
254
255#undef __array
256#define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \
257 __get, __put, __is_signed) \
258 type name[maxlen]; \
259 __u32 name ## _len;
260
261#include GENL_MAGIC_INCLUDE_FILE
262
263#undef GENL_struct
264#define GENL_struct(tag_name, tag_number, s_name, s_fields) \
265enum { \
266 s_fields \
267};
268
269#undef __field
270#define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \
271 is_signed) \
272 F_ ## name ## _IS_SIGNED = is_signed,
273
274#undef __array
275#define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \
276 __get, __put, is_signed) \
277 F_ ## name ## _IS_SIGNED = is_signed,
278
279#include GENL_MAGIC_INCLUDE_FILE
280
281
282#endif
283
284