From 7f0a8597d6f07c56b2dc940125511b7670e2ea21 Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Tue, 25 Mar 2025 21:04:34 +0000 Subject: [PATCH 1/3] feat(logging): include LUN into log messages a process might have a connection to different LUNs on the same target. To be able to distinguish the different connections add the LUN id to the target to log messages. Signed-off-by: Peter Lieven --- lib/logging.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/logging.c b/lib/logging.c index da7160e..55584be 100644 --- a/lib/logging.c +++ b/lib/logging.c @@ -72,9 +72,9 @@ iscsi_log_message(struct iscsi_context *iscsi, int level, const char *format, .. } if (iscsi->target_name[0]) { - static char message2[1282]; + static char message2[1294]; - snprintf(message2, 1282, "%s [%s]", message, iscsi->target_name); + snprintf(message2, sizeof(message2), "%s [%s/%d]", message, iscsi->target_name, iscsi->lun); iscsi->log_fn(level, message2); } else From 98f0f2f7f1a2d36df39e827cbacfd1ee02020c7d Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Tue, 25 Mar 2025 21:20:49 +0000 Subject: [PATCH 2/3] fix(socket): restore logging of local ip and port commit a92b413 removed the logging of local ip and port. For debugging puposes these information can be important. Restore functionality by using the new thread safe replacement for inet_ntoa called inet_ntop. Signed-off-by: Peter Lieven --- lib/socket.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/socket.c b/lib/socket.c index f1a1e15..e26230e 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -1073,7 +1073,10 @@ iscsi_tcp_service(struct iscsi_context *iscsi, int revents) } if (getsockname(iscsi->fd, (struct sockaddr *) &local, &local_l) == 0) { - ISCSI_LOG(iscsi, 2, "connection established to %s", iscsi->connected_portal); + char ip[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, &local.sin_addr, ip, sizeof(ip)); + ISCSI_LOG(iscsi, 2, "connection established (%s:%u -> %s)", ip, + (unsigned)ntohs(local.sin_port), iscsi->connected_portal); } iscsi->is_connected = 1; From 696c946a9b9616fb434de6a3d637461b0de35636 Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Tue, 25 Mar 2025 21:55:18 +0000 Subject: [PATCH 3/3] feat(socket): log resolved ip addresses if portal is a hostname Signed-off-by: Peter Lieven --- lib/socket.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/socket.c b/lib/socket.c index e26230e..00d36fe 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -306,6 +306,7 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal, struct addrinfo *ai = NULL; union socket_address sa; int socksize; + bool portal_is_ip; ISCSI_LOG(iscsi, 2, "connecting to portal %s",portal); @@ -352,6 +353,10 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal, *str = 0; } + /* check if we got an ip address or hostname for portal */ + portal_is_ip = inet_pton(AF_INET, host, &sa) == 1 || + inet_pton(AF_INET6, host, &sa) == 1; + /* is it a hostname ? */ if (getaddrinfo(host, NULL, NULL, &ai) != 0) { iscsi_free(iscsi, addr); @@ -371,6 +376,11 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal, #ifdef HAVE_SOCK_SIN_LEN sa.sin.sin_len = socksize; #endif + if (!portal_is_ip) { + char ip[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, &sa.sin.sin_addr, ip, sizeof(ip)); + ISCSI_LOG(iscsi, 2, "portal resolved to ipv4 address %s", ip); + } break; #ifdef HAVE_SOCKADDR_IN6 case AF_INET6: @@ -381,6 +391,11 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal, #ifdef HAVE_SOCK_SIN_LEN sa.sin6.sin6_len = socksize; #endif + if (!portal_is_ip) { + char ip[INET6_ADDRSTRLEN]; + inet_ntop(AF_INET6, &sa.sin6.sin6_addr, ip, sizeof(ip)); + ISCSI_LOG(iscsi, 2, "portal resolved to ipv6 address %s", ip); + } break; #endif default: