public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 1/3] netlink: Sequence numbers are actually 32 bits wide
Date: Tue,  7 Nov 2023 13:28:31 +0100	[thread overview]
Message-ID: <20231107122833.1673498-2-sbrivio@redhat.com> (raw)
In-Reply-To: <20231107122833.1673498-1-sbrivio@redhat.com>

Harmless, as we use sequence numbers monotonically anyway, but now
clang-tidy reports:

/home/sbrivio/passt/netlink.c:155:7: error: format specifies type 'unsigned short' but the argument has type '__u32' (aka 'unsigned int') [clang-diagnostic-format,-warnings-as-errors]
                    nh->nlmsg_seq, seq);
                    ^
/home/sbrivio/passt/log.h:26:7: note: expanded from macro 'die'
                err(__VA_ARGS__);                                       \
                    ^~~~~~~~~~~
/home/sbrivio/passt/log.h:19:34: note: expanded from macro 'err'
                                        ^~~~~~~~~~~
Suppressed 222820 warnings (222816 in non-user code, 4 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
1 warning treated as error
make: *** [Makefile:255: clang-tidy] Error 1

Fixes: 9d4ab98d538f ("netlink: Add nl_do() helper for simple operations with error checking")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 netlink.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/netlink.c b/netlink.c
index 768c6fd..6cc04a0 100644
--- a/netlink.c
+++ b/netlink.c
@@ -113,7 +113,7 @@ fail:
  *
  * Return: sequence number of request on success, terminates on error
  */
-static uint16_t nl_send(int s, void *req, uint16_t type,
+static uint32_t nl_send(int s, void *req, uint16_t type,
 		       uint16_t flags, ssize_t len)
 {
 	struct nlmsghdr *nh;
@@ -146,12 +146,12 @@ static uint16_t nl_send(int s, void *req, uint16_t type,
  *         > 0 @n if there are more responses to request @seq
  *     terminates if sequence numbers are out of sync
  */
-static int nl_status(const struct nlmsghdr *nh, ssize_t n, uint16_t seq)
+static int nl_status(const struct nlmsghdr *nh, ssize_t n, uint32_t seq)
 {
 	ASSERT(NLMSG_OK(nh, n));
 
 	if (nh->nlmsg_seq != seq)
-		die("netlink: Unexpected sequence number (%hu != %hu)",
+		die("netlink: Unexpected sequence number (%u != %u)",
 		    nh->nlmsg_seq, seq);
 
 	if (nh->nlmsg_type == NLMSG_DONE) {
@@ -229,7 +229,7 @@ static int nl_do(int s, void *req, uint16_t type, uint16_t flags, ssize_t len)
 	struct nlmsghdr *nh;
 	char buf[NLBUFSIZ];
 	ssize_t status;
-	uint16_t seq;
+	uint32_t seq;
 
 	seq = nl_send(s, req, type, flags, len);
 	nl_foreach(nh, status, s, buf, seq)
@@ -259,7 +259,7 @@ unsigned int nl_get_ext_if(int s, sa_family_t af)
 	struct rtattr *rta;
 	char buf[NLBUFSIZ];
 	ssize_t status;
-	uint16_t seq;
+	uint32_t seq;
 	size_t na;
 
 	seq = nl_send(s, &req, RTM_GETROUTE, NLM_F_DUMP, sizeof(req));
@@ -313,7 +313,7 @@ int nl_route_get_def(int s, unsigned int ifi, sa_family_t af, void *gw)
 	bool found = false;
 	char buf[NLBUFSIZ];
 	ssize_t status;
-	uint16_t seq;
+	uint32_t seq;
 
 	seq = nl_send(s, &req, RTM_GETROUTE, NLM_F_DUMP, sizeof(req));
 	nl_foreach_oftype(nh, status, s, buf, seq, RTM_NEWROUTE) {
@@ -438,7 +438,7 @@ int nl_route_dup(int s_src, unsigned int ifi_src,
 	unsigned dup_routes = 0;
 	struct nlmsghdr *nh;
 	char buf[NLBUFSIZ];
-	uint16_t seq;
+	uint32_t seq;
 	unsigned i;
 
 	seq = nl_send(s_src, &req, RTM_GETROUTE, NLM_F_DUMP, sizeof(req));
@@ -550,7 +550,7 @@ int nl_addr_get(int s, unsigned int ifi, sa_family_t af,
 	struct nlmsghdr *nh;
 	char buf[NLBUFSIZ];
 	ssize_t status;
-	uint16_t seq;
+	uint32_t seq;
 
 	seq = nl_send(s, &req, RTM_GETADDR, NLM_F_DUMP, sizeof(req));
 	nl_foreach_oftype(nh, status, s, buf, seq, RTM_NEWADDR) {
@@ -674,7 +674,7 @@ int nl_addr_dup(int s_src, unsigned int ifi_src,
 	char buf[NLBUFSIZ];
 	struct nlmsghdr *nh;
 	ssize_t status;
-	uint16_t seq;
+	uint32_t seq;
 	int rc = 0;
 
 	seq = nl_send(s_src, &req, RTM_GETADDR, NLM_F_DUMP, sizeof(req));
@@ -729,7 +729,7 @@ int nl_link_get_mac(int s, unsigned int ifi, void *mac)
 	struct nlmsghdr *nh;
 	char buf[NLBUFSIZ];
 	ssize_t status;
-	uint16_t seq;
+	uint32_t seq;
 
 	seq = nl_send(s, &req, RTM_GETLINK, 0, sizeof(req));
 	nl_foreach_oftype(nh, status, s, buf, seq, RTM_NEWLINK) {
-- 
@@ -113,7 +113,7 @@ fail:
  *
  * Return: sequence number of request on success, terminates on error
  */
-static uint16_t nl_send(int s, void *req, uint16_t type,
+static uint32_t nl_send(int s, void *req, uint16_t type,
 		       uint16_t flags, ssize_t len)
 {
 	struct nlmsghdr *nh;
@@ -146,12 +146,12 @@ static uint16_t nl_send(int s, void *req, uint16_t type,
  *         > 0 @n if there are more responses to request @seq
  *     terminates if sequence numbers are out of sync
  */
-static int nl_status(const struct nlmsghdr *nh, ssize_t n, uint16_t seq)
+static int nl_status(const struct nlmsghdr *nh, ssize_t n, uint32_t seq)
 {
 	ASSERT(NLMSG_OK(nh, n));
 
 	if (nh->nlmsg_seq != seq)
-		die("netlink: Unexpected sequence number (%hu != %hu)",
+		die("netlink: Unexpected sequence number (%u != %u)",
 		    nh->nlmsg_seq, seq);
 
 	if (nh->nlmsg_type == NLMSG_DONE) {
@@ -229,7 +229,7 @@ static int nl_do(int s, void *req, uint16_t type, uint16_t flags, ssize_t len)
 	struct nlmsghdr *nh;
 	char buf[NLBUFSIZ];
 	ssize_t status;
-	uint16_t seq;
+	uint32_t seq;
 
 	seq = nl_send(s, req, type, flags, len);
 	nl_foreach(nh, status, s, buf, seq)
@@ -259,7 +259,7 @@ unsigned int nl_get_ext_if(int s, sa_family_t af)
 	struct rtattr *rta;
 	char buf[NLBUFSIZ];
 	ssize_t status;
-	uint16_t seq;
+	uint32_t seq;
 	size_t na;
 
 	seq = nl_send(s, &req, RTM_GETROUTE, NLM_F_DUMP, sizeof(req));
@@ -313,7 +313,7 @@ int nl_route_get_def(int s, unsigned int ifi, sa_family_t af, void *gw)
 	bool found = false;
 	char buf[NLBUFSIZ];
 	ssize_t status;
-	uint16_t seq;
+	uint32_t seq;
 
 	seq = nl_send(s, &req, RTM_GETROUTE, NLM_F_DUMP, sizeof(req));
 	nl_foreach_oftype(nh, status, s, buf, seq, RTM_NEWROUTE) {
@@ -438,7 +438,7 @@ int nl_route_dup(int s_src, unsigned int ifi_src,
 	unsigned dup_routes = 0;
 	struct nlmsghdr *nh;
 	char buf[NLBUFSIZ];
-	uint16_t seq;
+	uint32_t seq;
 	unsigned i;
 
 	seq = nl_send(s_src, &req, RTM_GETROUTE, NLM_F_DUMP, sizeof(req));
@@ -550,7 +550,7 @@ int nl_addr_get(int s, unsigned int ifi, sa_family_t af,
 	struct nlmsghdr *nh;
 	char buf[NLBUFSIZ];
 	ssize_t status;
-	uint16_t seq;
+	uint32_t seq;
 
 	seq = nl_send(s, &req, RTM_GETADDR, NLM_F_DUMP, sizeof(req));
 	nl_foreach_oftype(nh, status, s, buf, seq, RTM_NEWADDR) {
@@ -674,7 +674,7 @@ int nl_addr_dup(int s_src, unsigned int ifi_src,
 	char buf[NLBUFSIZ];
 	struct nlmsghdr *nh;
 	ssize_t status;
-	uint16_t seq;
+	uint32_t seq;
 	int rc = 0;
 
 	seq = nl_send(s_src, &req, RTM_GETADDR, NLM_F_DUMP, sizeof(req));
@@ -729,7 +729,7 @@ int nl_link_get_mac(int s, unsigned int ifi, void *mac)
 	struct nlmsghdr *nh;
 	char buf[NLBUFSIZ];
 	ssize_t status;
-	uint16_t seq;
+	uint32_t seq;
 
 	seq = nl_send(s, &req, RTM_GETLINK, 0, sizeof(req));
 	nl_foreach_oftype(nh, status, s, buf, seq, RTM_NEWLINK) {
-- 
2.39.2


  reply	other threads:[~2023-11-07 12:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 12:28 [PATCH 0/3] Minimal fixes for issues reported by static checkers Stefano Brivio
2023-11-07 12:28 ` Stefano Brivio [this message]
2023-11-07 23:32   ` [PATCH 1/3] netlink: Sequence numbers are actually 32 bits wide David Gibson
2023-11-07 12:28 ` [PATCH 2/3] port_fwd: Don't try to read bound ports from invalid file handles Stefano Brivio
2023-11-07 12:28 ` [PATCH 3/3] log: Match implicit va_start() with va_end() in vlogmsg() Stefano Brivio
2023-11-07 23:31   ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231107122833.1673498-2-sbrivio@redhat.com \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).