diff options
author | Andreas Gruenbacher <agruen@linbit.com> | 2011-05-17 07:29:46 -0400 |
---|---|---|
committer | Philipp Reisner <philipp.reisner@linbit.com> | 2012-11-08 10:55:55 -0500 |
commit | 509100e6012db92f4af3796436b450447c6c8268 (patch) | |
tree | 161f5b29974425fac4fe3e865fbea438b91c2511 | |
parent | 309f0b70ab789bf85c5f5f32dbc466d42f024747 (diff) |
drbd: Output signed / unsigned netlink fields correctly
Note: All input values are still treated as signed; unsigned long long values
are still broken.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
-rw-r--r-- | include/linux/genl_magic_func.h | 23 | ||||
-rw-r--r-- | include/linux/genl_magic_struct.h | 52 |
2 files changed, 53 insertions, 22 deletions
diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h index 94e839aafae3..2ae16126c6a4 100644 --- a/include/linux/genl_magic_func.h +++ b/include/linux/genl_magic_func.h | |||
@@ -78,12 +78,13 @@ static struct nla_policy s_name ## _nl_policy[] __read_mostly = \ | |||
78 | { s_fields }; | 78 | { s_fields }; |
79 | 79 | ||
80 | #undef __field | 80 | #undef __field |
81 | #define __field(attr_nr, attr_flag, name, nla_type, _type, __get, __put) \ | 81 | #define __field(attr_nr, attr_flag, name, nla_type, _type, __get, \ |
82 | __put, __is_signed) \ | ||
82 | [__nla_type(attr_nr)] = { .type = nla_type }, | 83 | [__nla_type(attr_nr)] = { .type = nla_type }, |
83 | 84 | ||
84 | #undef __array | 85 | #undef __array |
85 | #define __array(attr_nr, attr_flag, name, nla_type, _type, maxlen, \ | 86 | #define __array(attr_nr, attr_flag, name, nla_type, _type, maxlen, \ |
86 | __get, __put) \ | 87 | __get, __put, __is_signed) \ |
87 | [__nla_type(attr_nr)] = { .type = nla_type, \ | 88 | [__nla_type(attr_nr)] = { .type = nla_type, \ |
88 | .len = maxlen - (nla_type == NLA_NUL_STRING) }, | 89 | .len = maxlen - (nla_type == NLA_NUL_STRING) }, |
89 | 90 | ||
@@ -241,7 +242,8 @@ static int s_name ## _from_attrs_for_change(struct s_name *s, \ | |||
241 | } | 242 | } |
242 | 243 | ||
243 | #undef __field | 244 | #undef __field |
244 | #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put) \ | 245 | #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \ |
246 | __is_signed) \ | ||
245 | __assign(attr_nr, attr_flag, name, nla_type, type, \ | 247 | __assign(attr_nr, attr_flag, name, nla_type, type, \ |
246 | if (s) \ | 248 | if (s) \ |
247 | s->name = __get(nla); \ | 249 | s->name = __get(nla); \ |
@@ -249,7 +251,8 @@ static int s_name ## _from_attrs_for_change(struct s_name *s, \ | |||
249 | 251 | ||
250 | /* validate_nla() already checked nla_len <= maxlen appropriately. */ | 252 | /* validate_nla() already checked nla_len <= maxlen appropriately. */ |
251 | #undef __array | 253 | #undef __array |
252 | #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, __get, __put) \ | 254 | #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \ |
255 | __get, __put, __is_signed) \ | ||
253 | __assign(attr_nr, attr_flag, name, nla_type, type, \ | 256 | __assign(attr_nr, attr_flag, name, nla_type, type, \ |
254 | if (s) \ | 257 | if (s) \ |
255 | s->name ## _len = \ | 258 | s->name ## _len = \ |
@@ -410,14 +413,16 @@ static inline int s_name ## _to_unpriv_skb(struct sk_buff *skb, \ | |||
410 | 413 | ||
411 | 414 | ||
412 | #undef __field | 415 | #undef __field |
413 | #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put) \ | 416 | #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \ |
417 | __is_signed) \ | ||
414 | if (!exclude_sensitive || !((attr_flag) & GENLA_F_SENSITIVE)) { \ | 418 | if (!exclude_sensitive || !((attr_flag) & GENLA_F_SENSITIVE)) { \ |
415 | DPRINT_FIELD(">>", nla_type, name, s, NULL); \ | 419 | DPRINT_FIELD(">>", nla_type, name, s, NULL); \ |
416 | __put(skb, attr_nr, s->name); \ | 420 | __put(skb, attr_nr, s->name); \ |
417 | } | 421 | } |
418 | 422 | ||
419 | #undef __array | 423 | #undef __array |
420 | #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, __get, __put) \ | 424 | #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \ |
425 | __get, __put, __is_signed) \ | ||
421 | if (!exclude_sensitive || !((attr_flag) & GENLA_F_SENSITIVE)) { \ | 426 | if (!exclude_sensitive || !((attr_flag) & GENLA_F_SENSITIVE)) { \ |
422 | DPRINT_ARRAY(">>",nla_type, name, s, NULL); \ | 427 | DPRINT_ARRAY(">>",nla_type, name, s, NULL); \ |
423 | __put(skb, attr_nr, min_t(int, maxlen, \ | 428 | __put(skb, attr_nr, min_t(int, maxlen, \ |
@@ -431,9 +436,11 @@ static inline int s_name ## _to_unpriv_skb(struct sk_buff *skb, \ | |||
431 | /* Functions for initializing structs to default values. */ | 436 | /* Functions for initializing structs to default values. */ |
432 | 437 | ||
433 | #undef __field | 438 | #undef __field |
434 | #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put) | 439 | #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \ |
440 | __is_signed) | ||
435 | #undef __array | 441 | #undef __array |
436 | #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, __get, __put) | 442 | #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \ |
443 | __get, __put, __is_signed) | ||
437 | #undef __u32_field_def | 444 | #undef __u32_field_def |
438 | #define __u32_field_def(attr_nr, attr_flag, name, default) \ | 445 | #define __u32_field_def(attr_nr, attr_flag, name, default) \ |
439 | x->name = default; | 446 | x->name = default; |
diff --git a/include/linux/genl_magic_struct.h b/include/linux/genl_magic_struct.h index 0fca21fd1af5..ba911da84d9f 100644 --- a/include/linux/genl_magic_struct.h +++ b/include/linux/genl_magic_struct.h | |||
@@ -87,28 +87,28 @@ enum { | |||
87 | /* possible field types */ | 87 | /* possible field types */ |
88 | #define __flg_field(attr_nr, attr_flag, name) \ | 88 | #define __flg_field(attr_nr, attr_flag, name) \ |
89 | __field(attr_nr, attr_flag, name, NLA_U8, char, \ | 89 | __field(attr_nr, attr_flag, name, NLA_U8, char, \ |
90 | nla_get_u8, NLA_PUT_U8) | 90 | nla_get_u8, NLA_PUT_U8, false) |
91 | #define __u8_field(attr_nr, attr_flag, name) \ | 91 | #define __u8_field(attr_nr, attr_flag, name) \ |
92 | __field(attr_nr, attr_flag, name, NLA_U8, unsigned char, \ | 92 | __field(attr_nr, attr_flag, name, NLA_U8, unsigned char, \ |
93 | nla_get_u8, NLA_PUT_U8) | 93 | nla_get_u8, NLA_PUT_U8, false) |
94 | #define __u16_field(attr_nr, attr_flag, name) \ | 94 | #define __u16_field(attr_nr, attr_flag, name) \ |
95 | __field(attr_nr, attr_flag, name, NLA_U16, __u16, \ | 95 | __field(attr_nr, attr_flag, name, NLA_U16, __u16, \ |
96 | nla_get_u16, NLA_PUT_U16) | 96 | nla_get_u16, NLA_PUT_U16, false) |
97 | #define __u32_field(attr_nr, attr_flag, name) \ | 97 | #define __u32_field(attr_nr, attr_flag, name) \ |
98 | __field(attr_nr, attr_flag, name, NLA_U32, __u32, \ | 98 | __field(attr_nr, attr_flag, name, NLA_U32, __u32, \ |
99 | nla_get_u32, NLA_PUT_U32) | 99 | nla_get_u32, NLA_PUT_U32, false) |
100 | #define __s32_field(attr_nr, attr_flag, name) \ | 100 | #define __s32_field(attr_nr, attr_flag, name) \ |
101 | __field(attr_nr, attr_flag, name, NLA_U32, __s32, \ | 101 | __field(attr_nr, attr_flag, name, NLA_U32, __s32, \ |
102 | nla_get_u32, NLA_PUT_U32) | 102 | nla_get_u32, NLA_PUT_U32, true) |
103 | #define __u64_field(attr_nr, attr_flag, name) \ | 103 | #define __u64_field(attr_nr, attr_flag, name) \ |
104 | __field(attr_nr, attr_flag, name, NLA_U64, __u64, \ | 104 | __field(attr_nr, attr_flag, name, NLA_U64, __u64, \ |
105 | nla_get_u64, NLA_PUT_U64) | 105 | nla_get_u64, NLA_PUT_U64, false) |
106 | #define __str_field(attr_nr, attr_flag, name, maxlen) \ | 106 | #define __str_field(attr_nr, attr_flag, name, maxlen) \ |
107 | __array(attr_nr, attr_flag, name, NLA_NUL_STRING, char, maxlen, \ | 107 | __array(attr_nr, attr_flag, name, NLA_NUL_STRING, char, maxlen, \ |
108 | nla_strlcpy, NLA_PUT) | 108 | nla_strlcpy, NLA_PUT, false) |
109 | #define __bin_field(attr_nr, attr_flag, name, maxlen) \ | 109 | #define __bin_field(attr_nr, attr_flag, name, maxlen) \ |
110 | __array(attr_nr, attr_flag, name, NLA_BINARY, char, maxlen, \ | 110 | __array(attr_nr, attr_flag, name, NLA_BINARY, char, maxlen, \ |
111 | nla_memcpy, NLA_PUT) | 111 | nla_memcpy, NLA_PUT, false) |
112 | 112 | ||
113 | /* fields with default values */ | 113 | /* fields with default values */ |
114 | #define __flg_field_def(attr_nr, attr_flag, name, default) \ | 114 | #define __flg_field_def(attr_nr, attr_flag, name, default) \ |
@@ -174,11 +174,13 @@ enum { \ | |||
174 | }; | 174 | }; |
175 | 175 | ||
176 | #undef __field | 176 | #undef __field |
177 | #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put) \ | 177 | #define __field(attr_nr, attr_flag, name, nla_type, type, \ |
178 | __get, __put, __is_signed) \ | ||
178 | T_ ## name = (__u16)(attr_nr | attr_flag), | 179 | T_ ## name = (__u16)(attr_nr | attr_flag), |
179 | 180 | ||
180 | #undef __array | 181 | #undef __array |
181 | #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, __get, __put) \ | 182 | #define __array(attr_nr, attr_flag, name, nla_type, type, \ |
183 | maxlen, __get, __put, __is_signed) \ | ||
182 | T_ ## name = (__u16)(attr_nr | attr_flag), | 184 | T_ ## name = (__u16)(attr_nr | attr_flag), |
183 | 185 | ||
184 | #include GENL_MAGIC_INCLUDE_FILE | 186 | #include GENL_MAGIC_INCLUDE_FILE |
@@ -238,11 +240,13 @@ static inline void ct_assert_unique_ ## s_name ## _attributes(void) \ | |||
238 | } | 240 | } |
239 | 241 | ||
240 | #undef __field | 242 | #undef __field |
241 | #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put) \ | 243 | #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \ |
244 | __is_signed) \ | ||
242 | case attr_nr: | 245 | case attr_nr: |
243 | 246 | ||
244 | #undef __array | 247 | #undef __array |
245 | #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, __get, __put) \ | 248 | #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \ |
249 | __get, __put, __is_signed) \ | ||
246 | case attr_nr: | 250 | case attr_nr: |
247 | 251 | ||
248 | #include GENL_MAGIC_INCLUDE_FILE | 252 | #include GENL_MAGIC_INCLUDE_FILE |
@@ -260,16 +264,36 @@ static inline void ct_assert_unique_ ## s_name ## _attributes(void) \ | |||
260 | struct s_name { s_fields }; | 264 | struct s_name { s_fields }; |
261 | 265 | ||
262 | #undef __field | 266 | #undef __field |
263 | #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put) \ | 267 | #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \ |
268 | __is_signed) \ | ||
264 | type name; | 269 | type name; |
265 | 270 | ||
266 | #undef __array | 271 | #undef __array |
267 | #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, __get, __put) \ | 272 | #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \ |
273 | __get, __put, __is_signed) \ | ||
268 | type name[maxlen]; \ | 274 | type name[maxlen]; \ |
269 | __u32 name ## _len; | 275 | __u32 name ## _len; |
270 | 276 | ||
271 | #include GENL_MAGIC_INCLUDE_FILE | 277 | #include GENL_MAGIC_INCLUDE_FILE |
272 | 278 | ||
279 | #undef GENL_struct | ||
280 | #define GENL_struct(tag_name, tag_number, s_name, s_fields) \ | ||
281 | enum { \ | ||
282 | s_fields \ | ||
283 | }; | ||
284 | |||
285 | #undef __field | ||
286 | #define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \ | ||
287 | is_signed) \ | ||
288 | F_ ## name ## _IS_SIGNED = is_signed, | ||
289 | |||
290 | #undef __array | ||
291 | #define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \ | ||
292 | __get, __put, is_signed) \ | ||
293 | F_ ## name ## _IS_SIGNED = is_signed, | ||
294 | |||
295 | #include GENL_MAGIC_INCLUDE_FILE | ||
296 | |||
273 | /* }}}1 */ | 297 | /* }}}1 */ |
274 | #endif /* GENL_MAGIC_STRUCT_H */ | 298 | #endif /* GENL_MAGIC_STRUCT_H */ |
275 | /* vim: set foldmethod=marker nofoldenable : */ | 299 | /* vim: set foldmethod=marker nofoldenable : */ |