diff options
-rw-r--r-- | include/linux/netlink.h | 14 | ||||
-rw-r--r-- | include/net/netlink.h | 9 | ||||
-rw-r--r-- | net/ipv4/fib_frontend.c | 2 | ||||
-rw-r--r-- | net/ipv4/fib_semantics.c | 2 | ||||
-rw-r--r-- | net/ipv6/route.c | 2 | ||||
-rw-r--r-- | net/netlabel/netlabel_cipso_v4.c | 14 | ||||
-rw-r--r-- | net/netlink/attr.c | 10 |
7 files changed, 38 insertions, 15 deletions
diff --git a/include/linux/netlink.h b/include/linux/netlink.h index d2843ae4a83a..e638256ce472 100644 --- a/include/linux/netlink.h +++ b/include/linux/netlink.h | |||
@@ -131,6 +131,20 @@ struct nlattr | |||
131 | __u16 nla_type; | 131 | __u16 nla_type; |
132 | }; | 132 | }; |
133 | 133 | ||
134 | /* | ||
135 | * nla_type (16 bits) | ||
136 | * +---+---+-------------------------------+ | ||
137 | * | N | O | Attribute Type | | ||
138 | * +---+---+-------------------------------+ | ||
139 | * N := Carries nested attributes | ||
140 | * O := Payload stored in network byte order | ||
141 | * | ||
142 | * Note: The N and O flag are mutually exclusive. | ||
143 | */ | ||
144 | #define NLA_F_NESTED (1 << 15) | ||
145 | #define NLA_F_NET_BYTEORDER (1 << 14) | ||
146 | #define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER) | ||
147 | |||
134 | #define NLA_ALIGNTO 4 | 148 | #define NLA_ALIGNTO 4 |
135 | #define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1)) | 149 | #define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1)) |
136 | #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr))) | 150 | #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr))) |
diff --git a/include/net/netlink.h b/include/net/netlink.h index d7b824be5422..695e613a207b 100644 --- a/include/net/netlink.h +++ b/include/net/netlink.h | |||
@@ -667,6 +667,15 @@ static inline int nla_padlen(int payload) | |||
667 | } | 667 | } |
668 | 668 | ||
669 | /** | 669 | /** |
670 | * nla_type - attribute type | ||
671 | * @nla: netlink attribute | ||
672 | */ | ||
673 | static inline int nla_type(const struct nlattr *nla) | ||
674 | { | ||
675 | return nla->nla_type & NLA_TYPE_MASK; | ||
676 | } | ||
677 | |||
678 | /** | ||
670 | * nla_data - head of payload | 679 | * nla_data - head of payload |
671 | * @nla: netlink attribute | 680 | * @nla: netlink attribute |
672 | */ | 681 | */ |
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index df17aab193b4..f823ca34cb12 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c | |||
@@ -487,7 +487,7 @@ static int rtm_to_fib_config(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
487 | } | 487 | } |
488 | 488 | ||
489 | nlmsg_for_each_attr(attr, nlh, sizeof(struct rtmsg), remaining) { | 489 | nlmsg_for_each_attr(attr, nlh, sizeof(struct rtmsg), remaining) { |
490 | switch (attr->nla_type) { | 490 | switch (nla_type(attr)) { |
491 | case RTA_DST: | 491 | case RTA_DST: |
492 | cfg->fc_dst = nla_get_be32(attr); | 492 | cfg->fc_dst = nla_get_be32(attr); |
493 | break; | 493 | break; |
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index d30fb68d5f4e..1351a2617dce 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c | |||
@@ -743,7 +743,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg) | |||
743 | int remaining; | 743 | int remaining; |
744 | 744 | ||
745 | nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) { | 745 | nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) { |
746 | int type = nla->nla_type; | 746 | int type = nla_type(nla); |
747 | 747 | ||
748 | if (type) { | 748 | if (type) { |
749 | if (type > RTAX_MAX) | 749 | if (type > RTAX_MAX) |
diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 5bdd9d4010fe..104070e92cea 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c | |||
@@ -1279,7 +1279,7 @@ install_route: | |||
1279 | int remaining; | 1279 | int remaining; |
1280 | 1280 | ||
1281 | nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) { | 1281 | nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) { |
1282 | int type = nla->nla_type; | 1282 | int type = nla_type(nla); |
1283 | 1283 | ||
1284 | if (type) { | 1284 | if (type) { |
1285 | if (type > RTAX_MAX) { | 1285 | if (type > RTAX_MAX) { |
diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c index c060e3f991f1..ba0ca8d3f77d 100644 --- a/net/netlabel/netlabel_cipso_v4.c +++ b/net/netlabel/netlabel_cipso_v4.c | |||
@@ -130,7 +130,7 @@ static int netlbl_cipsov4_add_common(struct genl_info *info, | |||
130 | return -EINVAL; | 130 | return -EINVAL; |
131 | 131 | ||
132 | nla_for_each_nested(nla, info->attrs[NLBL_CIPSOV4_A_TAGLST], nla_rem) | 132 | nla_for_each_nested(nla, info->attrs[NLBL_CIPSOV4_A_TAGLST], nla_rem) |
133 | if (nla->nla_type == NLBL_CIPSOV4_A_TAG) { | 133 | if (nla_type(nla) == NLBL_CIPSOV4_A_TAG) { |
134 | if (iter >= CIPSO_V4_TAG_MAXCNT) | 134 | if (iter >= CIPSO_V4_TAG_MAXCNT) |
135 | return -EINVAL; | 135 | return -EINVAL; |
136 | doi_def->tags[iter++] = nla_get_u8(nla); | 136 | doi_def->tags[iter++] = nla_get_u8(nla); |
@@ -192,13 +192,13 @@ static int netlbl_cipsov4_add_std(struct genl_info *info) | |||
192 | nla_for_each_nested(nla_a, | 192 | nla_for_each_nested(nla_a, |
193 | info->attrs[NLBL_CIPSOV4_A_MLSLVLLST], | 193 | info->attrs[NLBL_CIPSOV4_A_MLSLVLLST], |
194 | nla_a_rem) | 194 | nla_a_rem) |
195 | if (nla_a->nla_type == NLBL_CIPSOV4_A_MLSLVL) { | 195 | if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSLVL) { |
196 | if (nla_validate_nested(nla_a, | 196 | if (nla_validate_nested(nla_a, |
197 | NLBL_CIPSOV4_A_MAX, | 197 | NLBL_CIPSOV4_A_MAX, |
198 | netlbl_cipsov4_genl_policy) != 0) | 198 | netlbl_cipsov4_genl_policy) != 0) |
199 | goto add_std_failure; | 199 | goto add_std_failure; |
200 | nla_for_each_nested(nla_b, nla_a, nla_b_rem) | 200 | nla_for_each_nested(nla_b, nla_a, nla_b_rem) |
201 | switch (nla_b->nla_type) { | 201 | switch (nla_type(nla_b)) { |
202 | case NLBL_CIPSOV4_A_MLSLVLLOC: | 202 | case NLBL_CIPSOV4_A_MLSLVLLOC: |
203 | if (nla_get_u32(nla_b) > | 203 | if (nla_get_u32(nla_b) > |
204 | CIPSO_V4_MAX_LOC_LVLS) | 204 | CIPSO_V4_MAX_LOC_LVLS) |
@@ -240,7 +240,7 @@ static int netlbl_cipsov4_add_std(struct genl_info *info) | |||
240 | nla_for_each_nested(nla_a, | 240 | nla_for_each_nested(nla_a, |
241 | info->attrs[NLBL_CIPSOV4_A_MLSLVLLST], | 241 | info->attrs[NLBL_CIPSOV4_A_MLSLVLLST], |
242 | nla_a_rem) | 242 | nla_a_rem) |
243 | if (nla_a->nla_type == NLBL_CIPSOV4_A_MLSLVL) { | 243 | if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSLVL) { |
244 | struct nlattr *lvl_loc; | 244 | struct nlattr *lvl_loc; |
245 | struct nlattr *lvl_rem; | 245 | struct nlattr *lvl_rem; |
246 | 246 | ||
@@ -265,13 +265,13 @@ static int netlbl_cipsov4_add_std(struct genl_info *info) | |||
265 | nla_for_each_nested(nla_a, | 265 | nla_for_each_nested(nla_a, |
266 | info->attrs[NLBL_CIPSOV4_A_MLSCATLST], | 266 | info->attrs[NLBL_CIPSOV4_A_MLSCATLST], |
267 | nla_a_rem) | 267 | nla_a_rem) |
268 | if (nla_a->nla_type == NLBL_CIPSOV4_A_MLSCAT) { | 268 | if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSCAT) { |
269 | if (nla_validate_nested(nla_a, | 269 | if (nla_validate_nested(nla_a, |
270 | NLBL_CIPSOV4_A_MAX, | 270 | NLBL_CIPSOV4_A_MAX, |
271 | netlbl_cipsov4_genl_policy) != 0) | 271 | netlbl_cipsov4_genl_policy) != 0) |
272 | goto add_std_failure; | 272 | goto add_std_failure; |
273 | nla_for_each_nested(nla_b, nla_a, nla_b_rem) | 273 | nla_for_each_nested(nla_b, nla_a, nla_b_rem) |
274 | switch (nla_b->nla_type) { | 274 | switch (nla_type(nla_b)) { |
275 | case NLBL_CIPSOV4_A_MLSCATLOC: | 275 | case NLBL_CIPSOV4_A_MLSCATLOC: |
276 | if (nla_get_u32(nla_b) > | 276 | if (nla_get_u32(nla_b) > |
277 | CIPSO_V4_MAX_LOC_CATS) | 277 | CIPSO_V4_MAX_LOC_CATS) |
@@ -315,7 +315,7 @@ static int netlbl_cipsov4_add_std(struct genl_info *info) | |||
315 | nla_for_each_nested(nla_a, | 315 | nla_for_each_nested(nla_a, |
316 | info->attrs[NLBL_CIPSOV4_A_MLSCATLST], | 316 | info->attrs[NLBL_CIPSOV4_A_MLSCATLST], |
317 | nla_a_rem) | 317 | nla_a_rem) |
318 | if (nla_a->nla_type == NLBL_CIPSOV4_A_MLSCAT) { | 318 | if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSCAT) { |
319 | struct nlattr *cat_loc; | 319 | struct nlattr *cat_loc; |
320 | struct nlattr *cat_rem; | 320 | struct nlattr *cat_rem; |
321 | 321 | ||
diff --git a/net/netlink/attr.c b/net/netlink/attr.c index e4d7bed99c2e..ec39d12c2423 100644 --- a/net/netlink/attr.c +++ b/net/netlink/attr.c | |||
@@ -27,12 +27,12 @@ static int validate_nla(struct nlattr *nla, int maxtype, | |||
27 | const struct nla_policy *policy) | 27 | const struct nla_policy *policy) |
28 | { | 28 | { |
29 | const struct nla_policy *pt; | 29 | const struct nla_policy *pt; |
30 | int minlen = 0, attrlen = nla_len(nla); | 30 | int minlen = 0, attrlen = nla_len(nla), type = nla_type(nla); |
31 | 31 | ||
32 | if (nla->nla_type <= 0 || nla->nla_type > maxtype) | 32 | if (type <= 0 || type > maxtype) |
33 | return 0; | 33 | return 0; |
34 | 34 | ||
35 | pt = &policy[nla->nla_type]; | 35 | pt = &policy[type]; |
36 | 36 | ||
37 | BUG_ON(pt->type > NLA_TYPE_MAX); | 37 | BUG_ON(pt->type > NLA_TYPE_MAX); |
38 | 38 | ||
@@ -149,7 +149,7 @@ int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len, | |||
149 | memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1)); | 149 | memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1)); |
150 | 150 | ||
151 | nla_for_each_attr(nla, head, len, rem) { | 151 | nla_for_each_attr(nla, head, len, rem) { |
152 | u16 type = nla->nla_type; | 152 | u16 type = nla_type(nla); |
153 | 153 | ||
154 | if (type > 0 && type <= maxtype) { | 154 | if (type > 0 && type <= maxtype) { |
155 | if (policy) { | 155 | if (policy) { |
@@ -185,7 +185,7 @@ struct nlattr *nla_find(struct nlattr *head, int len, int attrtype) | |||
185 | int rem; | 185 | int rem; |
186 | 186 | ||
187 | nla_for_each_attr(nla, head, len, rem) | 187 | nla_for_each_attr(nla, head, len, rem) |
188 | if (nla->nla_type == attrtype) | 188 | if (nla_type(nla) == attrtype) |
189 | return nla; | 189 | return nla; |
190 | 190 | ||
191 | return NULL; | 191 | return NULL; |