diff options
author | Andreas Gruenbacher <agruen@linbit.com> | 2011-06-09 11:52:12 -0400 |
---|---|---|
committer | Philipp Reisner <philipp.reisner@linbit.com> | 2012-11-08 10:57:45 -0500 |
commit | 7c3063cc6f0e75cdf312f5f318f9a4c02e460397 (patch) | |
tree | ed54e6066aed1994577e20fc6d635d856627cbab /include | |
parent | 789c1b626cb490acb36cf481b45040b324f60fde (diff) |
drbd: Also need to check for DRBD_GENLA_F_MANDATORY flags before nla_find_nested()
This is done by introducing drbd_nla_find_nested() which handles the flag
before calling nla_find_nested().
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/drbd_genl.h | 2 | ||||
-rw-r--r-- | include/linux/genl_magic_func.h | 37 |
2 files changed, 1 insertions, 38 deletions
diff --git a/include/linux/drbd_genl.h b/include/linux/drbd_genl.h index 47ef324b69db..0c2102c05384 100644 --- a/include/linux/drbd_genl.h +++ b/include/linux/drbd_genl.h | |||
@@ -96,7 +96,7 @@ GENL_struct(DRBD_NLA_CFG_REPLY, 1, drbd_cfg_reply, | |||
96 | * and the volume id within the resource. */ | 96 | * and the volume id within the resource. */ |
97 | GENL_struct(DRBD_NLA_CFG_CONTEXT, 2, drbd_cfg_context, | 97 | GENL_struct(DRBD_NLA_CFG_CONTEXT, 2, drbd_cfg_context, |
98 | __u32_field(1, DRBD_GENLA_F_MANDATORY, ctx_volume) | 98 | __u32_field(1, DRBD_GENLA_F_MANDATORY, ctx_volume) |
99 | __str_field(2, DRBD_GENLA_F_MANDATORY, ctx_conn_name, 128) | 99 | __str_field(2, DRBD_GENLA_F_MANDATORY, ctx_resource_name, 128) |
100 | ) | 100 | ) |
101 | 101 | ||
102 | GENL_struct(DRBD_NLA_DISK_CONF, 3, disk_conf, | 102 | GENL_struct(DRBD_NLA_DISK_CONF, 3, disk_conf, |
diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h index 357f2ad403b1..0b8a88e2e83e 100644 --- a/include/linux/genl_magic_func.h +++ b/include/linux/genl_magic_func.h | |||
@@ -142,43 +142,6 @@ static struct nlattr *nested_attr_tb[128]; | |||
142 | #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) | 142 | #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) |
143 | #endif | 143 | #endif |
144 | 144 | ||
145 | static inline int drbd_nla_check_mandatory(int maxtype, struct nlattr *nla) | ||
146 | { | ||
147 | struct nlattr *head = nla_data(nla); | ||
148 | int len = nla_len(nla); | ||
149 | int rem; | ||
150 | |||
151 | /* | ||
152 | * validate_nla (called from nla_parse_nested) ignores attributes | ||
153 | * beyond maxtype, and does not understand the DRBD_GENLA_F_MANDATORY flag. | ||
154 | * In order to have it validate attributes with the DRBD_GENLA_F_MANDATORY | ||
155 | * flag set also, check and remove that flag before calling | ||
156 | * nla_parse_nested. | ||
157 | */ | ||
158 | |||
159 | nla_for_each_attr(nla, head, len, rem) { | ||
160 | if (nla->nla_type & DRBD_GENLA_F_MANDATORY) { | ||
161 | nla->nla_type &= ~DRBD_GENLA_F_MANDATORY; | ||
162 | if (nla_type(nla) > maxtype) | ||
163 | return -EOPNOTSUPP; | ||
164 | } | ||
165 | } | ||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | static inline int drbd_nla_parse_nested(struct nlattr *tb[], int maxtype, | ||
170 | struct nlattr *nla, | ||
171 | const struct nla_policy *policy) | ||
172 | { | ||
173 | int err; | ||
174 | |||
175 | err = drbd_nla_check_mandatory(maxtype, nla); | ||
176 | if (!err) | ||
177 | err = nla_parse_nested(tb, maxtype, nla, policy); | ||
178 | |||
179 | return err; | ||
180 | } | ||
181 | |||
182 | #undef GENL_struct | 145 | #undef GENL_struct |
183 | #define GENL_struct(tag_name, tag_number, s_name, s_fields) \ | 146 | #define GENL_struct(tag_name, tag_number, s_name, s_fields) \ |
184 | /* *_from_attrs functions are static, but potentially unused */ \ | 147 | /* *_from_attrs functions are static, but potentially unused */ \ |