aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Engelhardt <jengelh@medozas.de>2010-11-16 12:52:32 -0500
committerDavid S. Miller <davem@davemloft.net>2010-11-16 12:52:32 -0500
commit3654654f7aa79a37dde130afb7409c55b11807e7 (patch)
tree4e65c0d211a6cc748509b7f3b2da7c45b05d3266
parent9d82ca98f71fd686ef2f3017c5e3e6a4871b6e46 (diff)
netlink: let nlmsg and nla functions take pointer-to-const args
The changed functions do not modify the NL messages and/or attributes at all. They should use const (similar to strchr), so that callers which have a const nlmsg/nlattr around can make use of them without casting. While at it, constify a data array. Signed-off-by: Jan Engelhardt <jengelh@medozas.de> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/netlink.h21
-rw-r--r--lib/nlattr.c22
2 files changed, 24 insertions, 19 deletions
diff --git a/include/net/netlink.h b/include/net/netlink.h
index 9801c55de5d6..373f1a900cf4 100644
--- a/include/net/netlink.h
+++ b/include/net/netlink.h
@@ -225,13 +225,15 @@ extern int nlmsg_notify(struct sock *sk, struct sk_buff *skb,
225 u32 pid, unsigned int group, int report, 225 u32 pid, unsigned int group, int report,
226 gfp_t flags); 226 gfp_t flags);
227 227
228extern int nla_validate(struct nlattr *head, int len, int maxtype, 228extern int nla_validate(const struct nlattr *head,
229 int len, int maxtype,
229 const struct nla_policy *policy); 230 const struct nla_policy *policy);
230extern int nla_parse(struct nlattr *tb[], int maxtype, 231extern int nla_parse(struct nlattr **tb, int maxtype,
231 struct nlattr *head, int len, 232 const struct nlattr *head, int len,
232 const struct nla_policy *policy); 233 const struct nla_policy *policy);
233extern int nla_policy_len(const struct nla_policy *, int); 234extern int nla_policy_len(const struct nla_policy *, int);
234extern struct nlattr * nla_find(struct nlattr *head, int len, int attrtype); 235extern struct nlattr * nla_find(const struct nlattr *head,
236 int len, int attrtype);
235extern size_t nla_strlcpy(char *dst, const struct nlattr *nla, 237extern size_t nla_strlcpy(char *dst, const struct nlattr *nla,
236 size_t dstsize); 238 size_t dstsize);
237extern int nla_memcpy(void *dest, const struct nlattr *src, int count); 239extern int nla_memcpy(void *dest, const struct nlattr *src, int count);
@@ -346,7 +348,8 @@ static inline int nlmsg_ok(const struct nlmsghdr *nlh, int remaining)
346 * Returns the next netlink message in the message stream and 348 * Returns the next netlink message in the message stream and
347 * decrements remaining by the size of the current message. 349 * decrements remaining by the size of the current message.
348 */ 350 */
349static inline struct nlmsghdr *nlmsg_next(struct nlmsghdr *nlh, int *remaining) 351static inline struct nlmsghdr *
352nlmsg_next(const struct nlmsghdr *nlh, int *remaining)
350{ 353{
351 int totlen = NLMSG_ALIGN(nlh->nlmsg_len); 354 int totlen = NLMSG_ALIGN(nlh->nlmsg_len);
352 355
@@ -398,7 +401,8 @@ static inline struct nlattr *nlmsg_find_attr(const struct nlmsghdr *nlh,
398 * @maxtype: maximum attribute type to be expected 401 * @maxtype: maximum attribute type to be expected
399 * @policy: validation policy 402 * @policy: validation policy
400 */ 403 */
401static inline int nlmsg_validate(struct nlmsghdr *nlh, int hdrlen, int maxtype, 404static inline int nlmsg_validate(const struct nlmsghdr *nlh,
405 int hdrlen, int maxtype,
402 const struct nla_policy *policy) 406 const struct nla_policy *policy)
403{ 407{
404 if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen)) 408 if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen))
@@ -727,7 +731,8 @@ static inline struct nlattr *nla_next(const struct nlattr *nla, int *remaining)
727 * 731 *
728 * Returns the first attribute which matches the specified type. 732 * Returns the first attribute which matches the specified type.
729 */ 733 */
730static inline struct nlattr *nla_find_nested(struct nlattr *nla, int attrtype) 734static inline struct nlattr *
735nla_find_nested(const struct nlattr *nla, int attrtype)
731{ 736{
732 return nla_find(nla_data(nla), nla_len(nla), attrtype); 737 return nla_find(nla_data(nla), nla_len(nla), attrtype);
733} 738}
@@ -1032,7 +1037,7 @@ static inline void nla_nest_cancel(struct sk_buff *skb, struct nlattr *start)
1032 * 1037 *
1033 * Returns 0 on success or a negative error code. 1038 * Returns 0 on success or a negative error code.
1034 */ 1039 */
1035static inline int nla_validate_nested(struct nlattr *start, int maxtype, 1040static inline int nla_validate_nested(const struct nlattr *start, int maxtype,
1036 const struct nla_policy *policy) 1041 const struct nla_policy *policy)
1037{ 1042{
1038 return nla_validate(nla_data(start), nla_len(start), maxtype, policy); 1043 return nla_validate(nla_data(start), nla_len(start), maxtype, policy);
diff --git a/lib/nlattr.c b/lib/nlattr.c
index c4706eb98d3d..00e8a02681a6 100644
--- a/lib/nlattr.c
+++ b/lib/nlattr.c
@@ -15,7 +15,7 @@
15#include <linux/types.h> 15#include <linux/types.h>
16#include <net/netlink.h> 16#include <net/netlink.h>
17 17
18static u16 nla_attr_minlen[NLA_TYPE_MAX+1] __read_mostly = { 18static const u16 nla_attr_minlen[NLA_TYPE_MAX+1] = {
19 [NLA_U8] = sizeof(u8), 19 [NLA_U8] = sizeof(u8),
20 [NLA_U16] = sizeof(u16), 20 [NLA_U16] = sizeof(u16),
21 [NLA_U32] = sizeof(u32), 21 [NLA_U32] = sizeof(u32),
@@ -23,7 +23,7 @@ static u16 nla_attr_minlen[NLA_TYPE_MAX+1] __read_mostly = {
23 [NLA_NESTED] = NLA_HDRLEN, 23 [NLA_NESTED] = NLA_HDRLEN,
24}; 24};
25 25
26static int validate_nla(struct nlattr *nla, int maxtype, 26static int validate_nla(const 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;
@@ -115,10 +115,10 @@ static int validate_nla(struct nlattr *nla, int maxtype,
115 * 115 *
116 * Returns 0 on success or a negative error code. 116 * Returns 0 on success or a negative error code.
117 */ 117 */
118int nla_validate(struct nlattr *head, int len, int maxtype, 118int nla_validate(const struct nlattr *head, int len, int maxtype,
119 const struct nla_policy *policy) 119 const struct nla_policy *policy)
120{ 120{
121 struct nlattr *nla; 121 const struct nlattr *nla;
122 int rem, err; 122 int rem, err;
123 123
124 nla_for_each_attr(nla, head, len, rem) { 124 nla_for_each_attr(nla, head, len, rem) {
@@ -173,10 +173,10 @@ nla_policy_len(const struct nla_policy *p, int n)
173 * 173 *
174 * Returns 0 on success or a negative error code. 174 * Returns 0 on success or a negative error code.
175 */ 175 */
176int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len, 176int nla_parse(struct nlattr **tb, int maxtype, const struct nlattr *head,
177 const struct nla_policy *policy) 177 int len, const struct nla_policy *policy)
178{ 178{
179 struct nlattr *nla; 179 const struct nlattr *nla;
180 int rem, err; 180 int rem, err;
181 181
182 memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1)); 182 memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1));
@@ -191,7 +191,7 @@ int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len,
191 goto errout; 191 goto errout;
192 } 192 }
193 193
194 tb[type] = nla; 194 tb[type] = (struct nlattr *)nla;
195 } 195 }
196 } 196 }
197 197
@@ -212,14 +212,14 @@ errout:
212 * 212 *
213 * Returns the first attribute in the stream matching the specified type. 213 * Returns the first attribute in the stream matching the specified type.
214 */ 214 */
215struct nlattr *nla_find(struct nlattr *head, int len, int attrtype) 215struct nlattr *nla_find(const struct nlattr *head, int len, int attrtype)
216{ 216{
217 struct nlattr *nla; 217 const struct nlattr *nla;
218 int rem; 218 int rem;
219 219
220 nla_for_each_attr(nla, head, len, rem) 220 nla_for_each_attr(nla, head, len, rem)
221 if (nla_type(nla) == attrtype) 221 if (nla_type(nla) == attrtype)
222 return nla; 222 return (struct nlattr *)nla;
223 223
224 return NULL; 224 return NULL;
225} 225}