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: lemmi@nerd2nerd.org
Subject: [PATCH 3/4] tcp, tcp_splice: CONN_IDX subtraction of pointers isn't always long
Date: Wed, 29 Nov 2023 14:46:09 +0100	[thread overview]
Message-ID: <20231129134610.3796809-4-sbrivio@redhat.com> (raw)
In-Reply-To: <20231129134610.3796809-1-sbrivio@redhat.com>

On 32-bit architectures, it's a regular int. C99 introduced ptrdiff_t
for this case, with a matching length modifier, 't'.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 tcp.c        | 39 +++++++++++++++++++++------------------
 tcp_splice.c | 14 +++++++-------
 2 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/tcp.c b/tcp.c
index 44468ca..c32c9cb 100644
--- a/tcp.c
+++ b/tcp.c
@@ -727,7 +727,7 @@ static void tcp_timer_ctl(const struct ctx *c, struct tcp_tap_conn *conn)
 		it.it_value.tv_sec = ACT_TIMEOUT;
 	}
 
-	debug("TCP: index %li, timer expires in %lu.%03lus", CONN_IDX(conn),
+	debug("TCP: index %ti, timer expires in %lu.%03lus", CONN_IDX(conn),
 	      it.it_value.tv_sec, it.it_value.tv_nsec / 1000 / 1000);
 
 	timerfd_settime(conn->timer, 0, &it, NULL);
@@ -750,7 +750,7 @@ static void conn_flag_do(const struct ctx *c, struct tcp_tap_conn *conn,
 
 		conn->flags &= flag;
 		if (flag_index >= 0) {
-			debug("TCP: index %li: %s dropped", CONN_IDX(conn),
+			debug("TCP: index %ti: %s dropped", CONN_IDX(conn),
 			      tcp_flag_str[flag_index]);
 		}
 	} else {
@@ -771,7 +771,7 @@ static void conn_flag_do(const struct ctx *c, struct tcp_tap_conn *conn,
 
 		conn->flags |= flag;
 		if (flag_index >= 0) {
-			debug("TCP: index %li: %s", CONN_IDX(conn),
+			debug("TCP: index %ti: %s", CONN_IDX(conn),
 			      tcp_flag_str[flag_index]);
 		}
 	}
@@ -821,12 +821,12 @@ static void conn_event_do(const struct ctx *c, struct tcp_tap_conn *conn,
 		new += 5;
 
 	if (prev != new) {
-		debug("TCP: index %li, %s: %s -> %s", CONN_IDX(conn),
+		debug("TCP: index %ti, %s: %s -> %s", CONN_IDX(conn),
 		      num == -1 	       ? "CLOSED" : tcp_event_str[num],
 		      prev == -1	       ? "CLOSED" : tcp_state_str[prev],
 		      (new == -1 || num == -1) ? "CLOSED" : tcp_state_str[new]);
 	} else {
-		debug("TCP: index %li, %s", CONN_IDX(conn),
+		debug("TCP: index %ti, %s", CONN_IDX(conn),
 		      num == -1 	       ? "CLOSED" : tcp_event_str[num]);
 	}
 
@@ -1209,7 +1209,7 @@ static void tcp_hash_insert(const struct ctx *c, struct tcp_tap_conn *conn)
 	conn->next_index = tc_hash[b] ? CONN_IDX(tc_hash[b]) : -1;
 	tc_hash[b] = conn;
 
-	debug("TCP: hash table insert: index %li, sock %i, bucket: %i, next: "
+	debug("TCP: hash table insert: index %ti, sock %i, bucket: %i, next: "
 	      "%p", CONN_IDX(conn), conn->sock, b,
 	      (void *)conn_at_idx(conn->next_index));
 }
@@ -1236,7 +1236,7 @@ static void tcp_hash_remove(const struct ctx *c,
 		}
 	}
 
-	debug("TCP: hash table remove: index %li, sock %i, bucket: %i, new: %p",
+	debug("TCP: hash table remove: index %ti, sock %i, bucket: %i, new: %p",
 	      CONN_IDX(conn), conn->sock, b,
 	      (void *)(prev ? conn_at_idx(prev->next_index) : tc_hash[b]));
 }
@@ -1264,7 +1264,7 @@ static void tcp_tap_conn_update(const struct ctx *c, struct tcp_tap_conn *old,
 		}
 	}
 
-	debug("TCP: hash table update: old index %li, new index %li, sock %i, "
+	debug("TCP: hash table update: old index %ti, new index %ti, sock %i, "
 	      "bucket: %i, old: %p, new: %p",
 	      CONN_IDX(old), CONN_IDX(new), new->sock, b,
 	      (void *)old, (void *)new);
@@ -1310,7 +1310,7 @@ void tcp_table_compact(struct ctx *c, union tcp_conn *hole)
 	union tcp_conn *from;
 
 	if (CONN_IDX(hole) == --c->tcp.conn_count) {
-		debug("TCP: table compaction: maximum index was %li (%p)",
+		debug("TCP: table compaction: maximum index was %ti (%p)",
 		      CONN_IDX(hole), (void *)hole);
 		memset(hole, 0, sizeof(*hole));
 		return;
@@ -1324,8 +1324,8 @@ void tcp_table_compact(struct ctx *c, union tcp_conn *hole)
 	else
 		tcp_tap_conn_update(c, &from->tap, &hole->tap);
 
-	debug("TCP: table compaction (spliced=%d): old index %li, new index %li, "
-	      "from: %p, to: %p",
+	debug("TCP: table compaction (spliced=%d): old index %ti, new index %ti"
+	      ", from: %p, to: %p",
 	      from->c.spliced, CONN_IDX(from), CONN_IDX(hole),
 	      (void *)from, (void *)hole);
 
@@ -1352,7 +1352,7 @@ static void tcp_conn_destroy(struct ctx *c, union tcp_conn *conn_union)
 static void tcp_rst_do(struct ctx *c, struct tcp_tap_conn *conn);
 #define tcp_rst(c, conn)						\
 	do {								\
-		debug("TCP: index %li, reset at %s:%i", CONN_IDX(conn), \
+		debug("TCP: index %ti, reset at %s:%i", CONN_IDX(conn),	\
 		      __func__, __LINE__);				\
 		tcp_rst_do(c, conn);					\
 	} while (0)
@@ -2570,7 +2570,7 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int af,
 		return 1;
 	}
 
-	trace("TCP: packet length %zu from tap for index %lu",
+	trace("TCP: packet length %zu from tap for index %ti",
 	      len, CONN_IDX(conn));
 
 	if (th->rst) {
@@ -2811,17 +2811,19 @@ void tcp_timer_handler(struct ctx *c, union epoll_ref ref)
 		tcp_timer_ctl(c, conn);
 	} else if (conn->flags & ACK_FROM_TAP_DUE) {
 		if (!(conn->events & ESTABLISHED)) {
-			debug("TCP: index %li, handshake timeout", CONN_IDX(conn));
+			debug("TCP: index %ti, handshake timeout",
+			      CONN_IDX(conn));
 			tcp_rst(c, conn);
 		} else if (CONN_HAS(conn, SOCK_FIN_SENT | TAP_FIN_ACKED)) {
-			debug("TCP: index %li, FIN timeout", CONN_IDX(conn));
+			debug("TCP: index %ti, FIN timeout", CONN_IDX(conn));
 			tcp_rst(c, conn);
 		} else if (conn->retrans == TCP_MAX_RETRANS) {
-			debug("TCP: index %li, retransmissions count exceeded",
+			debug("TCP: index %ti, retransmissions count exceeded",
 			      CONN_IDX(conn));
 			tcp_rst(c, conn);
 		} else {
-			debug("TCP: index %li, ACK timeout, retry", CONN_IDX(conn));
+			debug("TCP: index %ti, ACK timeout, retry",
+			      CONN_IDX(conn));
 			conn->retrans++;
 			conn->seq_to_tap = conn->seq_ack_from_tap;
 			tcp_data_from_sock(c, conn);
@@ -2839,7 +2841,8 @@ void tcp_timer_handler(struct ctx *c, union epoll_ref ref)
 		 */
 		timerfd_settime(conn->timer, 0, &new, &old);
 		if (old.it_value.tv_sec == ACT_TIMEOUT) {
-			debug("TCP: index %li, activity timeout", CONN_IDX(conn));
+			debug("TCP: index %ti, activity timeout",
+			      CONN_IDX(conn));
 			tcp_rst(c, conn);
 		}
 	}
diff --git a/tcp_splice.c b/tcp_splice.c
index 8d08bb4..cb8a73e 100644
--- a/tcp_splice.c
+++ b/tcp_splice.c
@@ -138,7 +138,7 @@ static int tcp_splice_epoll_ctl(const struct ctx *c,
 	if (epoll_ctl(c->epollfd, m, conn->s[0], &ev[0]) ||
 	    epoll_ctl(c->epollfd, m, conn->s[1], &ev[1])) {
 		int ret = -errno;
-		err("TCP (spliced): index %li, ERROR on epoll_ctl(): %s",
+		err("TCP (spliced): index %ti, ERROR on epoll_ctl(): %s",
 		    CONN_IDX(conn), strerror(errno));
 		return ret;
 	}
@@ -165,8 +165,8 @@ static void conn_flag_do(const struct ctx *c, struct tcp_splice_conn *conn,
 
 		conn->flags &= flag;
 		if (flag_index >= 0) {
-			debug("TCP (spliced): index %li: %s dropped", CONN_IDX(conn),
-			      tcp_splice_flag_str[flag_index]);
+			debug("TCP (spliced): index %ti: %s dropped",
+			      CONN_IDX(conn), tcp_splice_flag_str[flag_index]);
 		}
 	} else {
 		int flag_index = fls(flag);
@@ -176,7 +176,7 @@ static void conn_flag_do(const struct ctx *c, struct tcp_splice_conn *conn,
 
 		conn->flags |= flag;
 		if (flag_index >= 0) {
-			debug("TCP (spliced): index %li: %s", CONN_IDX(conn),
+			debug("TCP (spliced): index %ti: %s", CONN_IDX(conn),
 			      tcp_splice_flag_str[flag_index]);
 		}
 	}
@@ -211,7 +211,7 @@ static void conn_event_do(const struct ctx *c, struct tcp_splice_conn *conn,
 
 		conn->events &= event;
 		if (flag_index >= 0) {
-			debug("TCP (spliced): index %li, ~%s", CONN_IDX(conn),
+			debug("TCP (spliced): index %ti, ~%s", CONN_IDX(conn),
 			      tcp_splice_event_str[flag_index]);
 		}
 	} else {
@@ -222,7 +222,7 @@ static void conn_event_do(const struct ctx *c, struct tcp_splice_conn *conn,
 
 		conn->events |= event;
 		if (flag_index >= 0) {
-			debug("TCP (spliced): index %li, %s", CONN_IDX(conn),
+			debug("TCP (spliced): index %ti, %s", CONN_IDX(conn),
 			      tcp_splice_event_str[flag_index]);
 		}
 	}
@@ -280,7 +280,7 @@ void tcp_splice_destroy(struct ctx *c, union tcp_conn *conn_union)
 
 	conn->events = SPLICE_CLOSED;
 	conn->flags = 0;
-	debug("TCP (spliced): index %li, CLOSED", CONN_IDX(conn));
+	debug("TCP (spliced): index %ti, CLOSED", CONN_IDX(conn));
 
 	tcp_table_compact(c, conn_union);
 }
-- 
@@ -138,7 +138,7 @@ static int tcp_splice_epoll_ctl(const struct ctx *c,
 	if (epoll_ctl(c->epollfd, m, conn->s[0], &ev[0]) ||
 	    epoll_ctl(c->epollfd, m, conn->s[1], &ev[1])) {
 		int ret = -errno;
-		err("TCP (spliced): index %li, ERROR on epoll_ctl(): %s",
+		err("TCP (spliced): index %ti, ERROR on epoll_ctl(): %s",
 		    CONN_IDX(conn), strerror(errno));
 		return ret;
 	}
@@ -165,8 +165,8 @@ static void conn_flag_do(const struct ctx *c, struct tcp_splice_conn *conn,
 
 		conn->flags &= flag;
 		if (flag_index >= 0) {
-			debug("TCP (spliced): index %li: %s dropped", CONN_IDX(conn),
-			      tcp_splice_flag_str[flag_index]);
+			debug("TCP (spliced): index %ti: %s dropped",
+			      CONN_IDX(conn), tcp_splice_flag_str[flag_index]);
 		}
 	} else {
 		int flag_index = fls(flag);
@@ -176,7 +176,7 @@ static void conn_flag_do(const struct ctx *c, struct tcp_splice_conn *conn,
 
 		conn->flags |= flag;
 		if (flag_index >= 0) {
-			debug("TCP (spliced): index %li: %s", CONN_IDX(conn),
+			debug("TCP (spliced): index %ti: %s", CONN_IDX(conn),
 			      tcp_splice_flag_str[flag_index]);
 		}
 	}
@@ -211,7 +211,7 @@ static void conn_event_do(const struct ctx *c, struct tcp_splice_conn *conn,
 
 		conn->events &= event;
 		if (flag_index >= 0) {
-			debug("TCP (spliced): index %li, ~%s", CONN_IDX(conn),
+			debug("TCP (spliced): index %ti, ~%s", CONN_IDX(conn),
 			      tcp_splice_event_str[flag_index]);
 		}
 	} else {
@@ -222,7 +222,7 @@ static void conn_event_do(const struct ctx *c, struct tcp_splice_conn *conn,
 
 		conn->events |= event;
 		if (flag_index >= 0) {
-			debug("TCP (spliced): index %li, %s", CONN_IDX(conn),
+			debug("TCP (spliced): index %ti, %s", CONN_IDX(conn),
 			      tcp_splice_event_str[flag_index]);
 		}
 	}
@@ -280,7 +280,7 @@ void tcp_splice_destroy(struct ctx *c, union tcp_conn *conn_union)
 
 	conn->events = SPLICE_CLOSED;
 	conn->flags = 0;
-	debug("TCP (spliced): index %li, CLOSED", CONN_IDX(conn));
+	debug("TCP (spliced): index %ti, CLOSED", CONN_IDX(conn));
 
 	tcp_table_compact(c, conn_union);
 }
-- 
2.39.2


  parent reply	other threads:[~2023-11-29 13:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-29 13:46 [PATCH 0/4] Fix build warnings and errors for 32-bit and musl Stefano Brivio
2023-11-29 13:46 ` [PATCH 1/4] treewide: Use 'z' length modifier for size_t/ssize_t conversions Stefano Brivio
2023-11-30  0:15   ` David Gibson
2023-11-30  9:06     ` Stefano Brivio
2023-11-30 23:10       ` David Gibson
2023-11-29 13:46 ` [PATCH 2/4] packet: Offset plus length is not always uint32_t, but it's always size_t Stefano Brivio
2023-11-30  0:18   ` David Gibson
2023-11-30  9:06     ` Stefano Brivio
2023-11-30  9:07     ` Stefano Brivio
2023-11-30 23:12       ` David Gibson
2023-11-29 13:46 ` Stefano Brivio [this message]
2023-11-29 13:58   ` [PATCH 3/4] tcp, tcp_splice: CONN_IDX subtraction of pointers isn't always long Stefano Brivio
2023-11-30  0:27     ` David Gibson
2023-11-30  9:07       ` Stefano Brivio
2023-11-30 23:13         ` David Gibson
2023-11-29 13:46 ` [PATCH 4/4] port_fwd, util: Include additional headers to fix build with musl Stefano Brivio
2023-11-30  0:30   ` 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=20231129134610.3796809-4-sbrivio@redhat.com \
    --to=sbrivio@redhat.com \
    --cc=lemmi@nerd2nerd.org \
    --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).