@@ -443,10 +443,10 @@ static uint16_t nla_attr_minlen[NLA_TYPE_MAX+1] = {
[NLA_S64] = sizeof(int64_t),
};
-static int validate_nla(struct nlattr *nla, int maxtype,
- struct nla_policy *policy)
+static int validate_nla(const struct nlattr *nla, int maxtype,
+ const struct nla_policy *policy)
{
- struct nla_policy *pt;
+ const struct nla_policy *pt;
int minlen = 0, type = nla_type(nla);
if (type <= 0 || type > maxtype)
@@ -500,7 +500,7 @@ static int validate_nla(struct nlattr *nla, int maxtype,
* @return 0 on success or a negative error code.
*/
int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len,
- struct nla_policy *policy)
+ const struct nla_policy *policy)
{
struct nlattr *nla;
int rem, err;
@@ -552,10 +552,10 @@ errout:
*
* @return 0 on success or a negative error code.
*/
-int nla_validate(struct nlattr *head, int len, int maxtype,
- struct nla_policy *policy)
+int nla_validate(const struct nlattr *head, int len, int maxtype,
+ const struct nla_policy *policy)
{
- struct nlattr *nla;
+ const struct nlattr *nla;
int rem, err;
nla_for_each_attr(nla, head, len, rem) {
@@ -158,7 +158,7 @@ int genlmsg_valid_hdr(struct nlmsghdr *nlh, int hdrlen)
}
int genlmsg_validate(struct nlmsghdr *nlh, int hdrlen, int maxtype,
- struct nla_policy *policy)
+ const struct nla_policy *policy)
{
struct genlmsghdr *ghdr;
@@ -171,7 +171,7 @@ int genlmsg_validate(struct nlmsghdr *nlh, int hdrlen, int maxtype,
}
int genlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[],
- int maxtype, struct nla_policy *policy)
+ int maxtype, const struct nla_policy *policy)
{
struct genlmsghdr *ghdr;
@@ -80,9 +80,9 @@ struct nla_policy {
extern int nla_ok(const struct nlattr *, int);
extern struct nlattr * nla_next(const struct nlattr *, int *);
extern int nla_parse(struct nlattr **, int, struct nlattr *,
- int, struct nla_policy *);
-extern int nla_validate(struct nlattr *, int, int,
- struct nla_policy *);
+ int, const struct nla_policy *);
+extern int nla_validate(const struct nlattr *, int, int,
+ const struct nla_policy *);
extern struct nlattr * nla_find(struct nlattr *, int, int);
/* Unspecific attribute */
@@ -202,7 +202,7 @@ static inline int nla_len(const struct nlattr *nla)
*
* @return The number of bytes copied to dest.
*/
-static inline int nla_memcpy(void *dest, struct nlattr *src, int count)
+static inline int nla_memcpy(void *dest, const struct nlattr *src, int count)
{
int minlen;
@@ -275,9 +275,9 @@ static inline int nla_put_s8(struct nl_msg *msg, int attrtype, int8_t value)
*
* @return Payload as 8 bit integer.
*/
-static inline int8_t nla_get_s8(struct nlattr *nla)
+static inline int8_t nla_get_s8(const struct nlattr *nla)
{
- return *(int8_t *) nla_data(nla);
+ return *(const int8_t *) nla_data(nla);
}
/**
@@ -300,9 +300,9 @@ static inline int nla_put_u8(struct nl_msg *msg, int attrtype, uint8_t value)
*
* @return Payload as 8 bit integer.
*/
-static inline uint8_t nla_get_u8(struct nlattr *nla)
+static inline uint8_t nla_get_u8(const struct nlattr *nla)
{
- return *(uint8_t *) nla_data(nla);
+ return *(const uint8_t *) nla_data(nla);
}
/**
@@ -325,9 +325,9 @@ static inline int nla_put_s16(struct nl_msg *msg, int attrtype, int16_t value)
*
* @return Payload as 16 bit integer.
*/
-static inline int16_t nla_get_s16(struct nlattr *nla)
+static inline int16_t nla_get_s16(const struct nlattr *nla)
{
- return *(int16_t *) nla_data(nla);
+ return *(const int16_t *) nla_data(nla);
}
/**
@@ -350,9 +350,9 @@ static inline int nla_put_u16(struct nl_msg *msg, int attrtype, uint16_t value)
*
* @return Payload as 16 bit integer.
*/
-static inline uint16_t nla_get_u16(struct nlattr *nla)
+static inline uint16_t nla_get_u16(const struct nlattr *nla)
{
- return *(uint16_t *) nla_data(nla);
+ return *(const uint16_t *) nla_data(nla);
}
/**
@@ -375,9 +375,9 @@ static inline int nla_put_s32(struct nl_msg *msg, int attrtype, int32_t value)
*
* @return Payload as 32 bit integer.
*/
-static inline int32_t nla_get_s32(struct nlattr *nla)
+static inline int32_t nla_get_s32(const struct nlattr *nla)
{
- return *(int32_t *) nla_data(nla);
+ return *(const int32_t *) nla_data(nla);
}
/**
@@ -400,9 +400,9 @@ static inline int nla_put_u32(struct nl_msg *msg, int attrtype, uint32_t value)
*
* @return Payload as 32 bit integer.
*/
-static inline uint32_t nla_get_u32(struct nlattr *nla)
+static inline uint32_t nla_get_u32(const struct nlattr *nla)
{
- return *(uint32_t *) nla_data(nla);
+ return *(const uint32_t *) nla_data(nla);
}
/**
@@ -425,7 +425,7 @@ static inline int nla_put_s64(struct nl_msg *msg, int attrtype, int64_t value)
*
* @return Payload as 64 bit integer.
*/
-static inline int64_t nla_get_s64(struct nlattr *nla)
+static inline int64_t nla_get_s64(const struct nlattr *nla)
{
int64_t tmp;
@@ -454,7 +454,7 @@ static inline int nla_put_u64(struct nl_msg *msg, int attrtype, uint64_t value)
*
* @return Payload as 64 bit integer.
*/
-static inline uint64_t nla_get_u64(struct nlattr *nla)
+static inline uint64_t nla_get_u64(const struct nlattr *nla)
{
uint64_t tmp;
@@ -483,12 +483,12 @@ static inline int nla_put_string(struct nl_msg *msg, int attrtype, const char *s
*
* @return Pointer to attribute payload.
*/
-static inline char *nla_get_string(struct nlattr *nla)
+static inline char *nla_get_string(const struct nlattr *nla)
{
return (char *) nla_data(nla);
}
-static inline char *nla_strdup(struct nlattr *nla)
+static inline char *nla_strdup(const struct nlattr *nla)
{
return strdup(nla_get_string(nla));
}
@@ -518,7 +518,7 @@ static inline int nla_put_flag(struct nl_msg *msg, int attrtype)
*
* @return True if flag is set, otherwise false.
*/
-static inline int nla_get_flag(struct nlattr *nla)
+static inline int nla_get_flag(const struct nlattr *nla)
{
return !!nla;
}
@@ -546,7 +546,7 @@ static inline int nla_put_msecs(struct nl_msg *n, int attrtype, unsigned long ms
*
* @return the number of milliseconds.
*/
-static inline unsigned long nla_get_msecs(struct nlattr *nla)
+static inline unsigned long nla_get_msecs(const struct nlattr *nla)
{
return nla_get_u64(nla);
}
@@ -564,7 +564,7 @@ static inline unsigned long nla_get_msecs(struct nlattr *nla)
* @see nla_put
* @return 0 on success or a negative error code.
*/
-static inline int nla_put_nested(struct nl_msg *msg, int attrtype, struct nl_msg *nested)
+static inline int nla_put_nested(struct nl_msg *msg, int attrtype, const struct nl_msg *nested)
{
return nla_put(msg, attrtype, nlmsg_len(nested->nm_nlh),
nlmsg_data(nested->nm_nlh));
@@ -617,7 +617,7 @@ static inline int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
* @return 0 on success or a negative error code.
*/
static inline int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla,
- struct nla_policy *policy)
+ const struct nla_policy *policy)
{
return nla_parse(tb, maxtype, (struct nlattr *)nla_data(nla), nla_len(nla), policy);
}
@@ -30,9 +30,9 @@ extern void * genlmsg_put(struct nl_msg *, uint32_t, uint32_t,
extern int genlmsg_valid_hdr(struct nlmsghdr *, int);
extern int genlmsg_validate(struct nlmsghdr *, int, int,
- struct nla_policy *);
+ const struct nla_policy *);
extern int genlmsg_parse(struct nlmsghdr *, int, struct nlattr **,
- int, struct nla_policy *);
+ int, const struct nla_policy *);
extern void * genlmsg_data(const struct genlmsghdr *);
extern int genlmsg_len(const struct genlmsghdr *);
extern struct nlattr * genlmsg_attrdata(const struct genlmsghdr *, int);
@@ -64,9 +64,9 @@ struct ucred;
extern int nlmsg_ok(const struct nlmsghdr *, int);
extern struct nlmsghdr * nlmsg_next(struct nlmsghdr *, int *);
extern int nlmsg_parse(struct nlmsghdr *, int, struct nlattr **,
- int, struct nla_policy *);
-extern int nlmsg_validate(struct nlmsghdr *, int, int,
- struct nla_policy *);
+ int, const struct nla_policy *);
+extern int nlmsg_validate(const struct nlmsghdr *, int, int,
+ const struct nla_policy *);
extern struct nl_msg * nlmsg_alloc(void);
extern struct nl_msg * nlmsg_alloc_size(size_t);
@@ -222,7 +222,7 @@ struct nlmsghdr *nlmsg_next(struct nlmsghdr *nlh, int *remaining)
* See nla_parse()
*/
int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[],
- int maxtype, struct nla_policy *policy)
+ int maxtype, const struct nla_policy *policy)
{
if (!nlmsg_valid_hdr(nlh, hdrlen))
return -NLE_MSG_TOOSHORT;
@@ -238,8 +238,8 @@ int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[],
* @arg maxtype maximum attribute type to be expected
* @arg policy validation policy
*/
-int nlmsg_validate(struct nlmsghdr *nlh, int hdrlen, int maxtype,
- struct nla_policy *policy)
+int nlmsg_validate(const struct nlmsghdr *nlh, int hdrlen, int maxtype,
+ const struct nla_policy *policy)
{
if (!nlmsg_valid_hdr(nlh, hdrlen))
return -NLE_MSG_TOOSHORT;
Make the struct nla_policy and the struct nlattr const in many places like it is done in full libnl. This bringe our libnl-tiny closer to the upstream version. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> --- attr.c | 14 +++++------ genl.c | 4 ++-- include/netlink/attr.h | 48 ++++++++++++++++++------------------- include/netlink/genl/genl.h | 4 ++-- include/netlink/msg.h | 6 ++--- msg.c | 6 ++--- 6 files changed, 41 insertions(+), 41 deletions(-)