From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 0D1775A0272; Tue, 7 Nov 2023 13:28:33 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 1/3] netlink: Sequence numbers are actually 32 bits wide Date: Tue, 7 Nov 2023 13:28:31 +0100 Message-Id: <20231107122833.1673498-2-sbrivio@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231107122833.1673498-1-sbrivio@redhat.com> References: <20231107122833.1673498-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: EJXRUSXQWBQIR4OMRGFZMIUCFAVOTBC7 X-Message-ID-Hash: EJXRUSXQWBQIR4OMRGFZMIUCFAVOTBC7 X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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) { -- 2.39.2