From: Thomas Haller Date: Mon, 9 Oct 2017 11:46:44 +0000 (+0200) Subject: nl: add "const" specifier for nla_policy argument of parse functions X-Git-Tag: libnl3_5_0~61 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b4802a17a7655bfeee3e9c06e649d30b96dbad3b;p=libnl nl: add "const" specifier for nla_policy argument of parse functions Adding const to a function argument is generally not an API break (at least, if the argument is a struct, like in this case). Usually we declare the policy as static variables. The user should be able to mark them as "const", so that the linker makes the policy array read-only. Adjust the API to allow for that. Signed-off-by: Thomas Haller --- diff --git a/include/netlink-private/tc.h b/include/netlink-private/tc.h index d0cb283..939cd18 100644 --- a/include/netlink-private/tc.h +++ b/include/netlink-private/tc.h @@ -35,7 +35,7 @@ extern "C" { #define TCA_ATTR_MAX TCA_ATTR_LINKTYPE extern int tca_parse(struct nlattr **, int, struct rtnl_tc *, - struct nla_policy *); + const struct nla_policy *); #define RTNL_TC_RTABLE_SIZE 256 diff --git a/include/netlink/attr.h b/include/netlink/attr.h index 2157fe1..da9eee4 100644 --- a/include/netlink/attr.h +++ b/include/netlink/attr.h @@ -89,7 +89,7 @@ extern int nla_len(const struct nlattr *); 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 *); + int, const struct nla_policy *); extern int nla_validate(const struct nlattr *, int, int, const struct nla_policy *); extern struct nlattr * nla_find(const struct nlattr *, int, int); @@ -145,7 +145,7 @@ extern struct nlattr * nla_nest_start(struct nl_msg *, int); extern int nla_nest_end(struct nl_msg *, struct nlattr *); extern void nla_nest_cancel(struct nl_msg *, const struct nlattr *); extern int nla_parse_nested(struct nlattr **, int, struct nlattr *, - struct nla_policy *); + const struct nla_policy *); extern int nla_is_nested(const struct nlattr *); /** diff --git a/include/netlink/genl/genl.h b/include/netlink/genl/genl.h index e455581..c4ac137 100644 --- a/include/netlink/genl/genl.h +++ b/include/netlink/genl/genl.h @@ -29,9 +29,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 struct genlmsghdr * genlmsg_hdr(struct nlmsghdr *); extern void * genlmsg_data(const struct genlmsghdr *); diff --git a/include/netlink/msg.h b/include/netlink/msg.h index 5aee97d..51d9aeb 100644 --- a/include/netlink/msg.h +++ b/include/netlink/msg.h @@ -66,10 +66,10 @@ extern int nlmsg_valid_hdr(const struct nlmsghdr *, int); 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 *); + int, const struct nla_policy *); extern struct nlattr * nlmsg_find_attr(struct nlmsghdr *, int, int); extern int nlmsg_validate(struct nlmsghdr *, int, int, - struct nla_policy *); + const struct nla_policy *); extern struct nl_msg * nlmsg_alloc(void); extern struct nl_msg * nlmsg_alloc_size(size_t); diff --git a/lib/attr.c b/lib/attr.c index 0dca3ec..b81e550 100644 --- a/lib/attr.c +++ b/lib/attr.c @@ -240,7 +240,7 @@ static int validate_nla(const 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; @@ -997,7 +997,7 @@ void nla_nest_cancel(struct nl_msg *msg, const struct nlattr *attr) * @return 0 on success or a negative error code. */ 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, nla_data(nla), nla_len(nla), policy); } diff --git a/lib/genl/genl.c b/lib/genl/genl.c index a663ad8..c79fd24 100644 --- a/lib/genl/genl.c +++ b/lib/genl/genl.c @@ -150,7 +150,7 @@ int genlmsg_valid_hdr(struct nlmsghdr *nlh, int hdrlen) * @return 0 on success or a negative error code. */ int genlmsg_validate(struct nlmsghdr *nlh, int hdrlen, int maxtype, - struct nla_policy *policy) + const struct nla_policy *policy) { struct genlmsghdr *ghdr; @@ -190,7 +190,7 @@ int genlmsg_validate(struct nlmsghdr *nlh, int hdrlen, int maxtype, * @return 0 on success or a negative error code. */ 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/lib/msg.c b/lib/msg.c index 3e27d4e..0a52340 100644 --- a/lib/msg.c +++ b/lib/msg.c @@ -212,7 +212,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; @@ -243,7 +243,7 @@ struct nlattr *nlmsg_find_attr(struct nlmsghdr *nlh, int hdrlen, int attrtype) * @arg policy validation policy */ int nlmsg_validate(struct nlmsghdr *nlh, int hdrlen, int maxtype, - struct nla_policy *policy) + const struct nla_policy *policy) { if (!nlmsg_valid_hdr(nlh, hdrlen)) return -NLE_MSG_TOOSHORT; diff --git a/lib/route/tc.c b/lib/route/tc.c index f5b23f0..5dc43e1 100644 --- a/lib/route/tc.c +++ b/lib/route/tc.c @@ -37,7 +37,7 @@ static struct nla_policy tc_policy[TCA_MAX+1] = { }; int tca_parse(struct nlattr **tb, int maxattr, struct rtnl_tc *g, - struct nla_policy *policy) + const struct nla_policy *policy) { if (g->ce_mask & TCA_ATTR_OPTS)