1 #ifndef GENL_MAGIC_STRUCT_H
2 #define GENL_MAGIC_STRUCT_H
4 #ifndef GENL_MAGIC_FAMILY
5 # error "you need to define GENL_MAGIC_FAMILY before inclusion"
8 #ifndef GENL_MAGIC_VERSION
9 # error "you need to define GENL_MAGIC_VERSION before inclusion"
12 #ifndef GENL_MAGIC_INCLUDE_FILE
13 # error "you need to define GENL_MAGIC_INCLUDE_FILE before inclusion"
16 #include <linux/genetlink.h>
17 #include <linux/types.h>
19 #define CONCAT__(a,b) a ## b
20 #define CONCAT_(a,b) CONCAT__(a,b)
22 extern int CONCAT_(GENL_MAGIC_FAMILY, _genl_register)(void);
23 extern void CONCAT_(GENL_MAGIC_FAMILY, _genl_unregister)(void);
26 * Extension of genl attribute validation policies {{{2
30 * @DRBD_GENLA_F_MANDATORY: By default, netlink ignores attributes it does not
31 * know about. This flag can be set in nlattr->nla_type to indicate that this
32 * attribute must not be ignored.
34 * We check and remove this flag in drbd_nla_check_mandatory() before
35 * validating the attribute types and lengths via nla_parse_nested().
37 #define DRBD_GENLA_F_MANDATORY (1 << 14)
40 * Flags specific to drbd and not visible at the netlink layer, used in
41 * <struct>_from_attrs and <struct>_to_skb:
43 * @DRBD_F_REQUIRED: Attribute is required; a request without this attribute is
46 * @DRBD_F_SENSITIVE: Attribute includes sensitive information and must not be
47 * included in unpriviledged get requests or broadcasts.
49 * @DRBD_F_INVARIANT: Attribute is set when an object is initially created, but
50 * cannot subsequently be changed.
52 #define DRBD_F_REQUIRED (1 << 0)
53 #define DRBD_F_SENSITIVE (1 << 1)
54 #define DRBD_F_INVARIANT (1 << 2)
56 #define __nla_type(x) ((__u16)((x) & NLA_TYPE_MASK & ~DRBD_GENLA_F_MANDATORY))
60 * multi-include macro expansion magic starts here
63 /* MAGIC helpers {{{2 */
65 static inline int nla_put_u64_0pad(struct sk_buff *skb, int attrtype, u64 value)
67 return nla_put_64bit(skb, attrtype, sizeof(u64), &value, 0);
70 /* possible field types */
71 #define __flg_field(attr_nr, attr_flag, name) \
72 __field(attr_nr, attr_flag, name, NLA_U8, char, \
73 nla_get_u8, nla_put_u8, false)
74 #define __u8_field(attr_nr, attr_flag, name) \
75 __field(attr_nr, attr_flag, name, NLA_U8, unsigned char, \
76 nla_get_u8, nla_put_u8, false)
77 #define __u16_field(attr_nr, attr_flag, name) \
78 __field(attr_nr, attr_flag, name, NLA_U16, __u16, \
79 nla_get_u16, nla_put_u16, false)
80 #define __u32_field(attr_nr, attr_flag, name) \
81 __field(attr_nr, attr_flag, name, NLA_U32, __u32, \
82 nla_get_u32, nla_put_u32, false)
83 #define __s32_field(attr_nr, attr_flag, name) \
84 __field(attr_nr, attr_flag, name, NLA_U32, __s32, \
85 nla_get_u32, nla_put_u32, true)
86 #define __u64_field(attr_nr, attr_flag, name) \
87 __field(attr_nr, attr_flag, name, NLA_U64, __u64, \
88 nla_get_u64, nla_put_u64_0pad, false)
89 #define __str_field(attr_nr, attr_flag, name, maxlen) \
90 __array(attr_nr, attr_flag, name, NLA_NUL_STRING, char, maxlen, \
91 nla_strlcpy, nla_put, false)
92 #define __bin_field(attr_nr, attr_flag, name, maxlen) \
93 __array(attr_nr, attr_flag, name, NLA_BINARY, char, maxlen, \
94 nla_memcpy, nla_put, false)
96 /* fields with default values */
97 #define __flg_field_def(attr_nr, attr_flag, name, default) \
98 __flg_field(attr_nr, attr_flag, name)
99 #define __u32_field_def(attr_nr, attr_flag, name, default) \
100 __u32_field(attr_nr, attr_flag, name)
101 #define __s32_field_def(attr_nr, attr_flag, name, default) \
102 __s32_field(attr_nr, attr_flag, name)
103 #define __str_field_def(attr_nr, attr_flag, name, maxlen) \
104 __str_field(attr_nr, attr_flag, name, maxlen)
106 #define GENL_op_init(args...) args
107 #define GENL_doit(handler) \
109 .flags = GENL_ADMIN_PERM,
110 #define GENL_dumpit(handler) \
112 .flags = GENL_ADMIN_PERM,
115 * Magic: define the enum symbols for genl_ops
116 * Magic: define the enum symbols for top level attributes
117 * Magic: define the enum symbols for nested attributes
122 #define GENL_struct(tag_name, tag_number, s_name, s_fields)
125 #define GENL_mc_group(group)
127 #undef GENL_notification
128 #define GENL_notification(op_name, op_num, mcast_group, tla_list) \
132 #define GENL_op(op_name, op_num, handler, tla_list) \
136 #include GENL_MAGIC_INCLUDE_FILE
139 #undef GENL_notification
140 #define GENL_notification(op_name, op_num, mcast_group, tla_list)
143 #define GENL_op(op_name, op_num, handler, attr_list)
146 #define GENL_struct(tag_name, tag_number, s_name, s_fields) \
147 tag_name = tag_number,
150 #include GENL_MAGIC_INCLUDE_FILE
154 #define GENL_struct(tag_name, tag_number, s_name, s_fields) \
160 #define __field(attr_nr, attr_flag, name, nla_type, type, \
161 __get, __put, __is_signed) \
162 T_ ## name = (__u16)(attr_nr | ((attr_flag) & DRBD_GENLA_F_MANDATORY)),
165 #define __array(attr_nr, attr_flag, name, nla_type, type, \
166 maxlen, __get, __put, __is_signed) \
167 T_ ## name = (__u16)(attr_nr | ((attr_flag) & DRBD_GENLA_F_MANDATORY)),
169 #include GENL_MAGIC_INCLUDE_FILE
172 * Magic: compile time assert unique numbers for operations
173 * Magic: -"- unique numbers for top level attributes
174 * Magic: -"- unique numbers for nested attributes
179 #define GENL_struct(tag_name, tag_number, s_name, s_fields)
182 #define GENL_op(op_name, op_num, handler, attr_list) \
185 #undef GENL_notification
186 #define GENL_notification(op_name, op_num, mcast_group, tla_list) \
189 static inline void ct_assert_unique_operations(void)
192 #include GENL_MAGIC_INCLUDE_FILE
199 #define GENL_op(op_name, op_num, handler, attr_list)
201 #undef GENL_notification
202 #define GENL_notification(op_name, op_num, mcast_group, tla_list)
205 #define GENL_struct(tag_name, tag_number, s_name, s_fields) \
208 static inline void ct_assert_unique_top_level_attributes(void)
211 #include GENL_MAGIC_INCLUDE_FILE
218 #define GENL_struct(tag_name, tag_number, s_name, s_fields) \
219 static inline void ct_assert_unique_ ## s_name ## _attributes(void) \
229 #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \
234 #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \
235 __get, __put, __is_signed) \
238 #include GENL_MAGIC_INCLUDE_FILE
241 * Magic: declare structs
249 #define GENL_struct(tag_name, tag_number, s_name, s_fields) \
250 struct s_name { s_fields };
253 #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \
258 #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \
259 __get, __put, __is_signed) \
263 #include GENL_MAGIC_INCLUDE_FILE
266 #define GENL_struct(tag_name, tag_number, s_name, s_fields) \
272 #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \
274 F_ ## name ## _IS_SIGNED = is_signed,
277 #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \
278 __get, __put, is_signed) \
279 F_ ## name ## _IS_SIGNED = is_signed,
281 #include GENL_MAGIC_INCLUDE_FILE
284 #endif /* GENL_MAGIC_STRUCT_H */
285 /* vim: set foldmethod=marker nofoldenable : */