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
---
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(-)
diff --git a/attr.c b/attr.c
index fd10b25..2c1d354 100644
--- a/attr.c
+++ b/attr.c
@@ -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) {
diff --git a/genl.c b/genl.c
index f1df3f0..d5a14e5 100644
--- a/genl.c
+++ b/genl.c
@@ -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;
diff --git a/include/netlink/attr.h b/include/netlink/attr.h
index 28fac87..994af4a 100644
--- a/include/netlink/attr.h
+++ b/include/netlink/attr.h
@@ -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)
*
*