From patchwork Sun Jun 25 20:47:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hauke Mehrtens X-Patchwork-Id: 1799569 X-Patchwork-Delegate: hauke@hauke-m.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=TXtb3taF; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=hauke-m.de header.i=@hauke-m.de header.a=rsa-sha256 header.s=MBO0001 header.b=QCXS8Zi7; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qq35r42cKz20ZP for ; Mon, 26 Jun 2023 06:50:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Fj+hR0a3G3bQCxGpi81dHQnH/2UnZfHVl4Q5OeFWpRs=; b=TXtb3taFUEFXpq WVkka7Ta9yPbCbyIWMMCwxSN5BWYHFhFi1vMyYgluCnmL2kwPvZSUA/RWBF/CpjTiE/6uQ5WceG/q M1SOAiIfx8jTZElOvxIQxCZRvjkyZSwQdkvKqezxdPA3h86Q1wSb6lSKTPvzAUUf9QlTFqVUyZuqv O426XALkN7TKLN83XeYoYXPytassON+FrGX/qMQdJKGkC+EwEaH98OFvIX2PKvqSjfT+jxjhG9fE5 pfiTSMK0lKbo7zet5xXrtyNatzxS+RCV33BnMVFITfnZO1jF7OeWKCkzl62s/rsQQymmCJHrprwMp ft/hVbYBuThx8WKnYA2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qDWeT-008gLd-21; Sun, 25 Jun 2023 20:48:05 +0000 Received: from mout-p-201.mailbox.org ([80.241.56.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qDWeP-008gJz-1D for openwrt-devel@lists.openwrt.org; Sun, 25 Jun 2023 20:48:04 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4Qq32f2ykwz9sRn; Sun, 25 Jun 2023 22:47:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hauke-m.de; s=MBO0001; t=1687726074; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=rQ+3UGHcYKVsw7yVKU0LiHyDX5ZVbBM162fftSNwy6I=; b=QCXS8Zi7pxjf9E30X81JxJRbN0oqUCx5NwvvE4CzWXRZMpdwGFx3N2X9kF4ex6FNDY1J3b 4q4oH5SM6NMGARagCt+kV+zAbA6ufwnbKt5P2xZGFQdMfIoHGeecl8rANwz7u/MSzOP57S 1yp7LtTGYdw/i2ixq1SiVs0sU77CJq99DwtmgUzfGKDIzpj6raa9T2wiHALH7hSGTGio37 sdlEcFx8iRsNuYSCcy35i3BFY2w4RbUClRVqkB9qeUkk/GNEhA923HcvkfDRGVqCSvtROQ USaZzBYFfPyeg9K8p+RIUqqInA69Ze7b4SK0LLjuzzsKv0vCzUg9dyt87Rr3ZQ== From: Hauke Mehrtens To: openwrt-devel@lists.openwrt.org Cc: Hauke Mehrtens Subject: [PATCH] Make struct nla_policy and struct nlattr const Date: Sun, 25 Jun 2023 22:47:34 +0200 Message-Id: <20230625204734.3569832-1-hauke@hauke-m.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4Qq32f2ykwz9sRn X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230625_134801_565874_F38757FB X-CRM114-Status: GOOD ( 12.41 ) X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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 ++-- incl [...] Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.171 listed in list.dnswl.org] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org 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) * * @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); } diff --git a/include/netlink/genl/genl.h b/include/netlink/genl/genl.h index 3f3340c..389d2aa 100644 --- a/include/netlink/genl/genl.h +++ b/include/netlink/genl/genl.h @@ -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); diff --git a/include/netlink/msg.h b/include/netlink/msg.h index b3e2b0b..f034691 100644 --- a/include/netlink/msg.h +++ b/include/netlink/msg.h @@ -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); diff --git a/msg.c b/msg.c index 5992e38..d2872c6 100644 --- a/msg.c +++ b/msg.c @@ -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;