v2: - In 1/3, use %zi as format specifier for to_write in tcp_splice_sock_handler() - Drop 3/4, David will deal with CONN_IDX() separately Stefano Brivio (3): treewide: Use 'z' length modifier for size_t/ssize_t conversions packet: Offset plus length is not always uint32_t, but it's always size_t port_fwd, util: Include additional headers to fix build with musl netlink.c | 2 +- packet.c | 14 +++++++------- pcap.c | 4 ++-- port_fwd.c | 2 ++ tap.c | 12 ++++++------ tcp.c | 3 ++- tcp_splice.c | 8 ++++---- util.h | 1 + 8 files changed, 25 insertions(+), 21 deletions(-) -- 2.39.2
Types size_t and ssize_t are not necessarily long, it depends on the architecture. Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com> --- netlink.c | 2 +- packet.c | 14 +++++++------- pcap.c | 4 ++-- tap.c | 12 ++++++------ tcp.c | 3 ++- tcp_splice.c | 8 ++++---- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/netlink.c b/netlink.c index 6cc04a0..379d46e 100644 --- a/netlink.c +++ b/netlink.c @@ -130,7 +130,7 @@ static uint32_t nl_send(int s, void *req, uint16_t type, if (n < 0) die("netlink: Failed to send(): %s", strerror(errno)); else if (n < len) - die("netlink: Short send (%lu of %lu bytes)", n, len); + die("netlink: Short send (%zd of %zd bytes)", n, len); return nh->nlmsg_seq; } diff --git a/packet.c b/packet.c index 9589824..12ac76b 100644 --- a/packet.c +++ b/packet.c @@ -36,7 +36,7 @@ void packet_add_do(struct pool *p, size_t len, const char *start, size_t idx = p->count; if (idx >= p->size) { - trace("add packet index %lu to pool with size %lu, %s:%i", + trace("add packet index %zu to pool with size %zu, %s:%i", idx, p->size, func, line); return; } @@ -48,14 +48,14 @@ void packet_add_do(struct pool *p, size_t len, const char *start, } if (start + len > p->buf + p->buf_size) { - trace("add packet start %p, length: %lu, buffer end %p, %s:%i", + trace("add packet start %p, length: %zu, buffer end %p, %s:%i", (void *)start, len, (void *)(p->buf + p->buf_size), func, line); return; } if (len > UINT16_MAX) { - trace("add packet length %lu, %s:%i", len, func, line); + trace("add packet length %zu, %s:%i", len, func, line); return; } @@ -90,7 +90,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, { if (idx >= p->size || idx >= p->count) { if (func) { - trace("packet %lu from pool size: %lu, count: %lu, " + trace("packet %zu from pool size: %zu, count: %zu, " "%s:%i", idx, p->size, p->count, func, line); } return NULL; @@ -98,7 +98,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, if (len > UINT16_MAX || len + offset > UINT32_MAX) { if (func) { - trace("packet data length %lu, offset %lu, %s:%i", + trace("packet data length %zu, offset %zu, %s:%i", len, offset, func, line); } return NULL; @@ -106,7 +106,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, if (p->pkt[idx].offset + len + offset > p->buf_size) { if (func) { - trace("packet offset plus length %lu from size %lu, " + trace("packet offset plus length %lu from size %zu, " "%s:%i", p->pkt[idx].offset + len + offset, p->buf_size, func, line); } @@ -115,7 +115,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, if (len + offset > p->pkt[idx].len) { if (func) { - trace("data length %lu, offset %lu from length %u, " + trace("data length %zu, offset %zu from length %u, " "%s:%i", len, offset, p->pkt[idx].len, func, line); } diff --git a/pcap.c b/pcap.c index 524612a..501d52d 100644 --- a/pcap.c +++ b/pcap.c @@ -101,7 +101,7 @@ void pcap(const char *pkt, size_t len) gettimeofday(&tv, NULL); if (pcap_frame(pkt, len, &tv) != 0) - debug("Cannot log packet, length %lu", len); + debug("Cannot log packet, length %zu", len); } /** @@ -123,7 +123,7 @@ void pcap_multiple(const struct iovec *iov, unsigned int n, size_t offset) for (i = 0; i < n; i++) { if (pcap_frame((char *)iov[i].iov_base + offset, iov[i].iov_len - offset, &tv) != 0) { - debug("Cannot log packet, length %lu", + debug("Cannot log packet, length %zu", iov->iov_len - offset); return; } diff --git a/tap.c b/tap.c index 4f11000..2ceda8d 100644 --- a/tap.c +++ b/tap.c @@ -191,7 +191,7 @@ void tap_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sport, memcpy(data, in, len); if (tap_send(c, buf, len + (data - buf)) < 0) - debug("tap: failed to send %lu bytes (IPv4)", len); + debug("tap: failed to send %zu bytes (IPv4)", len); } /** @@ -214,7 +214,7 @@ void tap_icmp4_send(const struct ctx *c, struct in_addr src, struct in_addr dst, csum_icmp4(icmp4h, icmp4h + 1, len - sizeof(*icmp4h)); if (tap_send(c, buf, len + (data - buf)) < 0) - debug("tap: failed to send %lu bytes (IPv4)", len); + debug("tap: failed to send %zu bytes (IPv4)", len); } /** @@ -278,7 +278,7 @@ void tap_udp6_send(const struct ctx *c, memcpy(data, in, len); if (tap_send(c, buf, len + (data - buf)) < 1) - debug("tap: failed to send %lu bytes (IPv6)", len); + debug("tap: failed to send %zu bytes (IPv6)", len); } /** @@ -302,7 +302,7 @@ void tap_icmp6_send(const struct ctx *c, csum_icmp6(icmp6h, src, dst, icmp6h + 1, len - sizeof(*icmp6h)); if (tap_send(c, buf, len + (data - buf)) < 1) - debug("tap: failed to send %lu bytes (IPv6)", len); + debug("tap: failed to send %zu bytes (IPv6)", len); } /** @@ -364,7 +364,7 @@ static void tap_send_remainder(const struct ctx *c, const struct iovec *iov, ssize_t sent = send(c->fd_tap, base + offset, len - offset, MSG_NOSIGNAL); if (sent < 0) { - err("tap: partial frame send (missing %lu bytes): %s", + err("tap: partial frame send (missing %zu bytes): %s", len - offset, strerror(errno)); return; } @@ -433,7 +433,7 @@ size_t tap_send_frames(const struct ctx *c, const struct iovec *iov, size_t n) m = tap_send_frames_pasta(c, iov, n); if (m < n) - debug("tap: failed to send %lu frames of %lu", n - m, n); + debug("tap: failed to send %zu frames of %zu", n - m, n); pcap_multiple(iov, m, c->mode == MODE_PASST ? sizeof(uint32_t) : 0); diff --git a/tcp.c b/tcp.c index 40e3dec..44468ca 100644 --- a/tcp.c +++ b/tcp.c @@ -2570,7 +2570,8 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int af, return 1; } - trace("TCP: packet length %lu from tap for index %lu", len, CONN_IDX(conn)); + trace("TCP: packet length %zu from tap for index %lu", + len, CONN_IDX(conn)); if (th->rst) { conn_event(c, conn, CLOSED); diff --git a/tcp_splice.c b/tcp_splice.c index a5c1332..0a23584 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -321,7 +321,7 @@ static int tcp_splice_connect_finish(const struct ctx *c, if (fcntl(conn->pipe[side][0], F_SETPIPE_SZ, c->tcp.pipe_size)) { - trace("TCP (spliced): cannot set %d->%d pipe size to %lu", + trace("TCP (spliced): cannot set %d->%d pipe size to %zu", side, !side, c->tcp.pipe_size); } } @@ -554,7 +554,7 @@ retry: readlen = splice(conn->s[fromside], NULL, conn->pipe[fromside][1], NULL, c->tcp.pipe_size, SPLICE_F_MOVE | SPLICE_F_NONBLOCK); - trace("TCP (spliced): %li from read-side call", readlen); + trace("TCP (spliced): %zi from read-side call", readlen); if (readlen < 0) { if (errno == EINTR) goto retry; @@ -580,7 +580,7 @@ eintr: written = splice(conn->pipe[fromside][0], NULL, conn->s[!fromside], NULL, to_write, SPLICE_F_MOVE | more | SPLICE_F_NONBLOCK); - trace("TCP (spliced): %li from write-side call (passed %lu)", + trace("TCP (spliced): %zi from write-side call (passed %zi)", written, to_write); /* Most common case: skip updating counters. */ @@ -718,7 +718,7 @@ static void tcp_splice_pipe_refill(const struct ctx *c) if (fcntl(splice_pipe_pool[i][0], F_SETPIPE_SZ, c->tcp.pipe_size)) { - trace("TCP (spliced): cannot set pool pipe size to %lu", + trace("TCP (spliced): cannot set pool pipe size to %zu", c->tcp.pipe_size); } } -- 2.39.2
On Thu, Nov 30, 2023 at 11:07:24AM +0100, Stefano Brivio wrote:Types size_t and ssize_t are not necessarily long, it depends on the architecture. Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>Reviewed-by: David Gibson <david(a)gibson.dropbear.id.au>--- netlink.c | 2 +- packet.c | 14 +++++++------- pcap.c | 4 ++-- tap.c | 12 ++++++------ tcp.c | 3 ++- tcp_splice.c | 8 ++++---- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/netlink.c b/netlink.c index 6cc04a0..379d46e 100644 --- a/netlink.c +++ b/netlink.c @@ -130,7 +130,7 @@ static uint32_t nl_send(int s, void *req, uint16_t type, if (n < 0) die("netlink: Failed to send(): %s", strerror(errno)); else if (n < len) - die("netlink: Short send (%lu of %lu bytes)", n, len); + die("netlink: Short send (%zd of %zd bytes)", n, len); return nh->nlmsg_seq; } diff --git a/packet.c b/packet.c index 9589824..12ac76b 100644 --- a/packet.c +++ b/packet.c @@ -36,7 +36,7 @@ void packet_add_do(struct pool *p, size_t len, const char *start, size_t idx = p->count; if (idx >= p->size) { - trace("add packet index %lu to pool with size %lu, %s:%i", + trace("add packet index %zu to pool with size %zu, %s:%i", idx, p->size, func, line); return; } @@ -48,14 +48,14 @@ void packet_add_do(struct pool *p, size_t len, const char *start, } if (start + len > p->buf + p->buf_size) { - trace("add packet start %p, length: %lu, buffer end %p, %s:%i", + trace("add packet start %p, length: %zu, buffer end %p, %s:%i", (void *)start, len, (void *)(p->buf + p->buf_size), func, line); return; } if (len > UINT16_MAX) { - trace("add packet length %lu, %s:%i", len, func, line); + trace("add packet length %zu, %s:%i", len, func, line); return; } @@ -90,7 +90,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, { if (idx >= p->size || idx >= p->count) { if (func) { - trace("packet %lu from pool size: %lu, count: %lu, " + trace("packet %zu from pool size: %zu, count: %zu, " "%s:%i", idx, p->size, p->count, func, line); } return NULL; @@ -98,7 +98,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, if (len > UINT16_MAX || len + offset > UINT32_MAX) { if (func) { - trace("packet data length %lu, offset %lu, %s:%i", + trace("packet data length %zu, offset %zu, %s:%i", len, offset, func, line); } return NULL; @@ -106,7 +106,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, if (p->pkt[idx].offset + len + offset > p->buf_size) { if (func) { - trace("packet offset plus length %lu from size %lu, " + trace("packet offset plus length %lu from size %zu, " "%s:%i", p->pkt[idx].offset + len + offset, p->buf_size, func, line); } @@ -115,7 +115,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, if (len + offset > p->pkt[idx].len) { if (func) { - trace("data length %lu, offset %lu from length %u, " + trace("data length %zu, offset %zu from length %u, " "%s:%i", len, offset, p->pkt[idx].len, func, line); } diff --git a/pcap.c b/pcap.c index 524612a..501d52d 100644 --- a/pcap.c +++ b/pcap.c @@ -101,7 +101,7 @@ void pcap(const char *pkt, size_t len) gettimeofday(&tv, NULL); if (pcap_frame(pkt, len, &tv) != 0) - debug("Cannot log packet, length %lu", len); + debug("Cannot log packet, length %zu", len); } /** @@ -123,7 +123,7 @@ void pcap_multiple(const struct iovec *iov, unsigned int n, size_t offset) for (i = 0; i < n; i++) { if (pcap_frame((char *)iov[i].iov_base + offset, iov[i].iov_len - offset, &tv) != 0) { - debug("Cannot log packet, length %lu", + debug("Cannot log packet, length %zu", iov->iov_len - offset); return; } diff --git a/tap.c b/tap.c index 4f11000..2ceda8d 100644 --- a/tap.c +++ b/tap.c @@ -191,7 +191,7 @@ void tap_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sport, memcpy(data, in, len); if (tap_send(c, buf, len + (data - buf)) < 0) - debug("tap: failed to send %lu bytes (IPv4)", len); + debug("tap: failed to send %zu bytes (IPv4)", len); } /** @@ -214,7 +214,7 @@ void tap_icmp4_send(const struct ctx *c, struct in_addr src, struct in_addr dst, csum_icmp4(icmp4h, icmp4h + 1, len - sizeof(*icmp4h)); if (tap_send(c, buf, len + (data - buf)) < 0) - debug("tap: failed to send %lu bytes (IPv4)", len); + debug("tap: failed to send %zu bytes (IPv4)", len); } /** @@ -278,7 +278,7 @@ void tap_udp6_send(const struct ctx *c, memcpy(data, in, len); if (tap_send(c, buf, len + (data - buf)) < 1) - debug("tap: failed to send %lu bytes (IPv6)", len); + debug("tap: failed to send %zu bytes (IPv6)", len); } /** @@ -302,7 +302,7 @@ void tap_icmp6_send(const struct ctx *c, csum_icmp6(icmp6h, src, dst, icmp6h + 1, len - sizeof(*icmp6h)); if (tap_send(c, buf, len + (data - buf)) < 1) - debug("tap: failed to send %lu bytes (IPv6)", len); + debug("tap: failed to send %zu bytes (IPv6)", len); } /** @@ -364,7 +364,7 @@ static void tap_send_remainder(const struct ctx *c, const struct iovec *iov, ssize_t sent = send(c->fd_tap, base + offset, len - offset, MSG_NOSIGNAL); if (sent < 0) { - err("tap: partial frame send (missing %lu bytes): %s", + err("tap: partial frame send (missing %zu bytes): %s", len - offset, strerror(errno)); return; } @@ -433,7 +433,7 @@ size_t tap_send_frames(const struct ctx *c, const struct iovec *iov, size_t n) m = tap_send_frames_pasta(c, iov, n); if (m < n) - debug("tap: failed to send %lu frames of %lu", n - m, n); + debug("tap: failed to send %zu frames of %zu", n - m, n); pcap_multiple(iov, m, c->mode == MODE_PASST ? sizeof(uint32_t) : 0); diff --git a/tcp.c b/tcp.c index 40e3dec..44468ca 100644 --- a/tcp.c +++ b/tcp.c @@ -2570,7 +2570,8 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int af, return 1; } - trace("TCP: packet length %lu from tap for index %lu", len, CONN_IDX(conn)); + trace("TCP: packet length %zu from tap for index %lu", + len, CONN_IDX(conn)); if (th->rst) { conn_event(c, conn, CLOSED); diff --git a/tcp_splice.c b/tcp_splice.c index a5c1332..0a23584 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -321,7 +321,7 @@ static int tcp_splice_connect_finish(const struct ctx *c, if (fcntl(conn->pipe[side][0], F_SETPIPE_SZ, c->tcp.pipe_size)) { - trace("TCP (spliced): cannot set %d->%d pipe size to %lu", + trace("TCP (spliced): cannot set %d->%d pipe size to %zu", side, !side, c->tcp.pipe_size); } } @@ -554,7 +554,7 @@ retry: readlen = splice(conn->s[fromside], NULL, conn->pipe[fromside][1], NULL, c->tcp.pipe_size, SPLICE_F_MOVE | SPLICE_F_NONBLOCK); - trace("TCP (spliced): %li from read-side call", readlen); + trace("TCP (spliced): %zi from read-side call", readlen); if (readlen < 0) { if (errno == EINTR) goto retry; @@ -580,7 +580,7 @@ eintr: written = splice(conn->pipe[fromside][0], NULL, conn->s[!fromside], NULL, to_write, SPLICE_F_MOVE | more | SPLICE_F_NONBLOCK); - trace("TCP (spliced): %li from write-side call (passed %lu)", + trace("TCP (spliced): %zi from write-side call (passed %zi)", written, to_write); /* Most common case: skip updating counters. */ @@ -718,7 +718,7 @@ static void tcp_splice_pipe_refill(const struct ctx *c) if (fcntl(splice_pipe_pool[i][0], F_SETPIPE_SZ, c->tcp.pipe_size)) { - trace("TCP (spliced): cannot set pool pipe size to %lu", + trace("TCP (spliced): cannot set pool pipe size to %zu", c->tcp.pipe_size); } }-- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
According to gcc, PRIu32 matches the type of the argument we're printing here on both 64 and 32-bits architectures. According to Clang, though, that's not the case, as the result of the sum is an unsigned long on 64-bit. Use the z modifier, given that we're summing uint32_t to size_t, and the result is at most promoted to size_t. Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com> --- packet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packet.c b/packet.c index 12ac76b..ccfc846 100644 --- a/packet.c +++ b/packet.c @@ -106,7 +106,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, if (p->pkt[idx].offset + len + offset > p->buf_size) { if (func) { - trace("packet offset plus length %lu from size %zu, " + trace("packet offset plus length %zu from size %zu, " "%s:%i", p->pkt[idx].offset + len + offset, p->buf_size, func, line); } -- 2.39.2
On Thu, Nov 30, 2023 at 11:07:25AM +0100, Stefano Brivio wrote:According to gcc, PRIu32 matches the type of the argument we're printing here on both 64 and 32-bits architectures. According to Clang, though, that's not the case, as the result of the sum is an unsigned long on 64-bit. Use the z modifier, given that we're summing uint32_t to size_t, and the result is at most promoted to size_t. Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>Reviewed-by: David Gibson <david(a)gibson.dropbear.id.au>--- packet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packet.c b/packet.c index 12ac76b..ccfc846 100644 --- a/packet.c +++ b/packet.c @@ -106,7 +106,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, if (p->pkt[idx].offset + len + offset > p->buf_size) { if (func) { - trace("packet offset plus length %lu from size %zu, " + trace("packet offset plus length %zu from size %zu, " "%s:%i", p->pkt[idx].offset + len + offset, p->buf_size, func, line); }-- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
lseek() is declared in unistd.h, and stdio.h provides sscanf(). Include these two headers in port_fwd.c. SIGCHLD, even if used exclusively for clone(), is defined in signal.h: add the include to util.h, as NS_CALL needs it. Reported-by: lemmi <lemmi(a)nerd2nerd.org> Link: https://github.com/void-linux/void-packages/actions/runs/6999782606/job/190… Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com> Reviewed-by: David Gibson <david(a)gibson.dropbear.id.au> --- port_fwd.c | 2 ++ util.h | 1 + 2 files changed, 3 insertions(+) diff --git a/port_fwd.c b/port_fwd.c index 7943a30..6f6c836 100644 --- a/port_fwd.c +++ b/port_fwd.c @@ -17,6 +17,8 @@ #include <errno.h> #include <fcntl.h> #include <sched.h> +#include <unistd.h> +#include <stdio.h> #include "util.h" #include "port_fwd.h" diff --git a/util.h b/util.h index 1f02588..86f1a7e 100644 --- a/util.h +++ b/util.h @@ -10,6 +10,7 @@ #include <stdarg.h> #include <stdbool.h> #include <string.h> +#include <signal.h> #include "log.h" -- 2.39.2