diff options
author | Holger Eitzenberger <holger@eitzenberger.org> | 2009-03-25 13:26:30 -0400 |
---|---|---|
committer | Patrick McHardy <kaber@trash.net> | 2009-03-25 13:26:30 -0400 |
commit | e487eb99cf9381a4f8254fa01747a85818da612b (patch) | |
tree | 2381e552d88063982bea03a16db942ebcc295fc2 | |
parent | d0dba7255b541f1651a88e75ebdb20dd45509c2f (diff) |
netlink: add nla_policy_len()
It calculates the max. length of a Netlink policy, which is usefull
for allocating Netlink buffers roughly the size of the actual
message.
Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>
Signed-off-by: Patrick McHardy <kaber@trash.net>
-rw-r--r-- | include/net/netlink.h | 1 | ||||
-rw-r--r-- | net/netlink/attr.c | 27 |
2 files changed, 28 insertions, 0 deletions
diff --git a/include/net/netlink.h b/include/net/netlink.h index 8a6150a3f4c7..eddb50289d6d 100644 --- a/include/net/netlink.h +++ b/include/net/netlink.h | |||
@@ -230,6 +230,7 @@ extern int nla_validate(struct nlattr *head, int len, int maxtype, | |||
230 | extern int nla_parse(struct nlattr *tb[], int maxtype, | 230 | extern int nla_parse(struct nlattr *tb[], int maxtype, |
231 | struct nlattr *head, int len, | 231 | struct nlattr *head, int len, |
232 | const struct nla_policy *policy); | 232 | const struct nla_policy *policy); |
233 | extern int nla_policy_len(const struct nla_policy *, int); | ||
233 | extern struct nlattr * nla_find(struct nlattr *head, int len, int attrtype); | 234 | extern struct nlattr * nla_find(struct nlattr *head, int len, int attrtype); |
234 | extern size_t nla_strlcpy(char *dst, const struct nlattr *nla, | 235 | extern size_t nla_strlcpy(char *dst, const struct nlattr *nla, |
235 | size_t dstsize); | 236 | size_t dstsize); |
diff --git a/net/netlink/attr.c b/net/netlink/attr.c index 56c3ce7fe29a..ae32c573df00 100644 --- a/net/netlink/attr.c +++ b/net/netlink/attr.c | |||
@@ -133,6 +133,32 @@ errout: | |||
133 | } | 133 | } |
134 | 134 | ||
135 | /** | 135 | /** |
136 | * nla_policy_len - Determin the max. length of a policy | ||
137 | * @policy: policy to use | ||
138 | * @n: number of policies | ||
139 | * | ||
140 | * Determines the max. length of the policy. It is currently used | ||
141 | * to allocated Netlink buffers roughly the size of the actual | ||
142 | * message. | ||
143 | * | ||
144 | * Returns 0 on success or a negative error code. | ||
145 | */ | ||
146 | int | ||
147 | nla_policy_len(const struct nla_policy *p, int n) | ||
148 | { | ||
149 | int i, len = 0; | ||
150 | |||
151 | for (i = 0; i < n; i++) { | ||
152 | if (p->len) | ||
153 | len += nla_total_size(p->len); | ||
154 | else if (nla_attr_minlen[p->type]) | ||
155 | len += nla_total_size(nla_attr_minlen[p->type]); | ||
156 | } | ||
157 | |||
158 | return len; | ||
159 | } | ||
160 | |||
161 | /** | ||
136 | * nla_parse - Parse a stream of attributes into a tb buffer | 162 | * nla_parse - Parse a stream of attributes into a tb buffer |
137 | * @tb: destination array with maxtype+1 elements | 163 | * @tb: destination array with maxtype+1 elements |
138 | * @maxtype: maximum attribute type to be expected | 164 | * @maxtype: maximum attribute type to be expected |
@@ -456,6 +482,7 @@ int nla_append(struct sk_buff *skb, int attrlen, const void *data) | |||
456 | } | 482 | } |
457 | 483 | ||
458 | EXPORT_SYMBOL(nla_validate); | 484 | EXPORT_SYMBOL(nla_validate); |
485 | EXPORT_SYMBOL(nla_policy_len); | ||
459 | EXPORT_SYMBOL(nla_parse); | 486 | EXPORT_SYMBOL(nla_parse); |
460 | EXPORT_SYMBOL(nla_find); | 487 | EXPORT_SYMBOL(nla_find); |
461 | EXPORT_SYMBOL(nla_strlcpy); | 488 | EXPORT_SYMBOL(nla_strlcpy); |