From 59f577df561657ae062d7573137a2d9637bf9cfc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 21 Jun 2022 22:01:24 +0200 Subject: [PATCH] platform/netlink: add const modifier to netlink header pointers They are not supposed to be modified. --- src/libnm-platform/nm-linux-platform.c | 20 ++++++++++---------- src/libnm-platform/nm-netlink.c | 2 +- src/libnm-platform/nm-netlink.h | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libnm-platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c index e7f773cd8..3c7f38174 100644 --- a/src/libnm-platform/nm-linux-platform.c +++ b/src/libnm-platform/nm-linux-platform.c @@ -2924,10 +2924,10 @@ _nmp_link_address_set(NMPLinkAddress *dst, const struct nlattr *nla) /* Copied and heavily modified from libnl3's link_msg_parser(). */ static NMPObject * -_new_from_nl_link(NMPlatform *platform, - const NMPCache *cache, - struct nlmsghdr *nlh, - gboolean id_only) +_new_from_nl_link(NMPlatform *platform, + const NMPCache *cache, + const struct nlmsghdr *nlh, + gboolean id_only) { static const struct nla_policy policy[] = { [IFLA_IFNAME] = {.type = NLA_STRING, .maxlen = IFNAMSIZ}, @@ -3275,7 +3275,7 @@ _new_from_nl_link(NMPlatform *platform, /* Copied and heavily modified from libnl3's addr_msg_parser(). */ static NMPObject * -_new_from_nl_addr(struct nlmsghdr *nlh, gboolean id_only) +_new_from_nl_addr(const struct nlmsghdr *nlh, gboolean id_only) { static const struct nla_policy policy[] = { [IFA_LABEL] = {.type = NLA_STRING, .maxlen = IFNAMSIZ}, @@ -3390,7 +3390,7 @@ _new_from_nl_addr(struct nlmsghdr *nlh, gboolean id_only) /* Copied and heavily modified from libnl3's rtnl_route_parse() and parse_multipath(). */ static NMPObject * -_new_from_nl_route(struct nlmsghdr *nlh, gboolean id_only, ParseNlmsgIter *parse_nlmsg_iter) +_new_from_nl_route(const struct nlmsghdr *nlh, gboolean id_only, ParseNlmsgIter *parse_nlmsg_iter) { static const struct nla_policy policy[] = { [RTA_TABLE] = {.type = NLA_U32}, @@ -3698,7 +3698,7 @@ rta_multipath_done: } static NMPObject * -_new_from_nl_routing_rule(struct nlmsghdr *nlh, gboolean id_only) +_new_from_nl_routing_rule(const struct nlmsghdr *nlh, gboolean id_only) { static const struct nla_policy policy[] = { [FRA_UNSPEC] = {}, @@ -3974,7 +3974,7 @@ psched_tick_to_time(NMPlatform *platform, guint32 tick) } static NMPObject * -_new_from_nl_qdisc(NMPlatform *platform, struct nlmsghdr *nlh, gboolean id_only) +_new_from_nl_qdisc(NMPlatform *platform, const struct nlmsghdr *nlh, gboolean id_only) { static const struct nla_policy policy[] = { [TCA_KIND] = {.type = NLA_STRING}, @@ -4087,7 +4087,7 @@ _new_from_nl_qdisc(NMPlatform *platform, struct nlmsghdr *nlh, gboolean id_only) } static NMPObject * -_new_from_nl_tfilter(NMPlatform *platform, struct nlmsghdr *nlh, gboolean id_only) +_new_from_nl_tfilter(NMPlatform *platform, const struct nlmsghdr *nlh, gboolean id_only) { static const struct nla_policy policy[] = { [TCA_KIND] = {.type = NLA_STRING}, @@ -4138,7 +4138,7 @@ nmp_object_new_from_nl(NMPlatform *platform, gboolean id_only, ParseNlmsgIter *parse_nlmsg_iter) { - struct nlmsghdr *msghdr; + const struct nlmsghdr *msghdr; if (nlmsg_get_proto(msg) != NETLINK_ROUTE) return NULL; diff --git a/src/libnm-platform/nm-netlink.c b/src/libnm-platform/nm-netlink.c index 1760628d2..03064bdcd 100644 --- a/src/libnm-platform/nm-netlink.c +++ b/src/libnm-platform/nm-netlink.c @@ -402,7 +402,7 @@ nlmsg_append(struct nl_msg *n, const void *data, size_t len, int pad) /*****************************************************************************/ int -nlmsg_parse(struct nlmsghdr *nlh, +nlmsg_parse(const struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, diff --git a/src/libnm-platform/nm-netlink.h b/src/libnm-platform/nm-netlink.h index 08fd63bfc..4f68742f1 100644 --- a/src/libnm-platform/nm-netlink.h +++ b/src/libnm-platform/nm-netlink.h @@ -465,7 +465,7 @@ nlmsg_find_attr(struct nlmsghdr *nlh, int hdrlen, int attrtype) return nla_find(nlmsg_attrdata(nlh, hdrlen), nlmsg_attrlen(nlh, hdrlen), attrtype); } -int nlmsg_parse(struct nlmsghdr *nlh, +int nlmsg_parse(const struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype,