Make struct nla_policy and struct nlattr const
[project/libnl-tiny.git] / include / netlink / attr.h
index 28fac87c41322d4cc179d862992f3d5b6885981a..994af4a00f4e6d7bec08d809a2e3e7739a4f1710 100644 (file)
@@ -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);
 }