aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/genl_magic_func.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/genl_magic_func.h')
-rw-r--r--include/linux/genl_magic_func.h49
1 files changed, 33 insertions, 16 deletions
diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
index c8c67239f616..e458282a3728 100644
--- a/include/linux/genl_magic_func.h
+++ b/include/linux/genl_magic_func.h
@@ -190,11 +190,12 @@ static struct nlattr *nested_attr_tb[128];
190 190
191#undef GENL_struct 191#undef GENL_struct
192#define GENL_struct(tag_name, tag_number, s_name, s_fields) \ 192#define GENL_struct(tag_name, tag_number, s_name, s_fields) \
193 /* static, potentially unused */ \ 193/* *_from_attrs functions are static, but potentially unused */ \
194int s_name ## _from_attrs(struct s_name *s, struct nlattr *tb[]) \ 194static int __ ## s_name ## _from_attrs(struct s_name *s, \
195 struct genl_info *info, bool exclude_invariants) \
195{ \ 196{ \
196 const int maxtype = ARRAY_SIZE(s_name ## _nl_policy)-1; \ 197 const int maxtype = ARRAY_SIZE(s_name ## _nl_policy)-1; \
197 struct nlattr *tla = tb[tag_number]; \ 198 struct nlattr *tla = info->attrs[tag_number]; \
198 struct nlattr **ntb = nested_attr_tb; \ 199 struct nlattr **ntb = nested_attr_tb; \
199 struct nlattr *nla; \ 200 struct nlattr *nla; \
200 int err; \ 201 int err; \
@@ -211,33 +212,49 @@ int s_name ## _from_attrs(struct s_name *s, struct nlattr *tb[]) \
211 \ 212 \
212 s_fields \ 213 s_fields \
213 return 0; \ 214 return 0; \
214} 215} __attribute__((unused)) \
216static int s_name ## _from_attrs(struct s_name *s, \
217 struct genl_info *info) \
218{ \
219 return __ ## s_name ## _from_attrs(s, info, false); \
220} __attribute__((unused)) \
221static int s_name ## _from_attrs_for_change(struct s_name *s, \
222 struct genl_info *info) \
223{ \
224 return __ ## s_name ## _from_attrs(s, info, true); \
225} __attribute__((unused)) \
215 226
216#undef __field 227#define __assign(attr_nr, attr_flag, name, nla_type, type, assignment...) \
217#define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put) \
218 nla = ntb[__nla_type(attr_nr)]; \ 228 nla = ntb[__nla_type(attr_nr)]; \
219 if (nla) { \ 229 if (nla) { \
220 if (s) \ 230 if (exclude_invariants && ((attr_flag) & GENLA_F_INVARIANT)) { \
221 s->name = __get(nla); \ 231 pr_info("<< must not change invariant attr: %s\n", #name); \
222 DPRINT_FIELD("<<", nla_type, name, s, nla); \ 232 return -EEXIST; \
233 } \
234 assignment; \
235 } else if (exclude_invariants && ((attr_flag) & GENLA_F_INVARIANT)) { \
236 /* attribute missing from payload, */ \
237 /* which was expected */ \
223 } else if ((attr_flag) & GENLA_F_REQUIRED) { \ 238 } else if ((attr_flag) & GENLA_F_REQUIRED) { \
224 pr_info("<< missing attr: %s\n", #name); \ 239 pr_info("<< missing attr: %s\n", #name); \
225 return -ENOMSG; \ 240 return -ENOMSG; \
226 } 241 }
227 242
243#undef __field
244#define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put) \
245 __assign(attr_nr, attr_flag, name, nla_type, type, \
246 if (s) \
247 s->name = __get(nla); \
248 DPRINT_FIELD("<<", nla_type, name, s, nla))
249
228/* validate_nla() already checked nla_len <= maxlen appropriately. */ 250/* validate_nla() already checked nla_len <= maxlen appropriately. */
229#undef __array 251#undef __array
230#define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, __get, __put) \ 252#define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, __get, __put) \
231 nla = ntb[__nla_type(attr_nr)]; \ 253 __assign(attr_nr, attr_flag, name, nla_type, type, \
232 if (nla) { \
233 if (s) \ 254 if (s) \
234 s->name ## _len = \ 255 s->name ## _len = \
235 __get(s->name, nla, maxlen); \ 256 __get(s->name, nla, maxlen); \
236 DPRINT_ARRAY("<<", nla_type, name, s, nla); \ 257 DPRINT_ARRAY("<<", nla_type, name, s, nla))
237 } else if ((attr_flag) & GENLA_F_REQUIRED) { \
238 pr_info("<< missing attr: %s\n", #name); \
239 return -ENOMSG; \
240 } \
241 258
242#include GENL_MAGIC_INCLUDE_FILE 259#include GENL_MAGIC_INCLUDE_FILE
243 260