Commit 74fd2593a7 for strongswan.org
commit 74fd2593a71420abf33930eb2b0b78c14e181c7e
Author: Tobias Brunner <tobias@strongswan.org>
Date: Mon Jun 1 09:02:35 2026 +0200
charon-cmd: Make local host configurable
This allows preferring a particular address family (via 0.0.0.0 or ::)
or even a specific local address.
diff --git a/src/charon-cmd/cmd/cmd_connection.c b/src/charon-cmd/cmd/cmd_connection.c
index 9b19bb45ca..030fe6d1db 100644
--- a/src/charon-cmd/cmd/cmd_connection.c
+++ b/src/charon-cmd/cmd/cmd_connection.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Tobias Brunner
+ * Copyright (C) 2013-2026 Tobias Brunner
* Copyright (C) 2013 Martin Willi
*
* Copyright (C) secunet Security Networks AG
@@ -102,6 +102,11 @@ struct private_cmd_connection_t {
*/
char *host;
+ /**
+ * Hostname to connect from
+ */
+ char *host_local;
+
/**
* Server identity, or NULL to use host
*/
@@ -150,7 +155,7 @@ static peer_cfg_t* create_peer_cfg(private_cmd_connection_t *this)
peer_cfg_t *peer_cfg;
proposal_t *proposal;
ike_cfg_create_t ike = {
- .local = "%any",
+ .local = this->host_local ?: "%any",
.remote = this->host,
.remote_port = IKEV2_UDP_PORT,
.fragmentation = FRAGMENTATION_YES,
@@ -502,6 +507,9 @@ METHOD(cmd_connection_t, handle, bool,
case CMD_OPT_HOST:
this->host = arg;
break;
+ case CMD_OPT_HOST_LOCAL:
+ this->host_local = arg;
+ break;
case CMD_OPT_REMOTE_IDENTITY:
this->server = arg;
break;
diff --git a/src/charon-cmd/cmd/cmd_options.c b/src/charon-cmd/cmd/cmd_options.c
index 6731177c3d..97d1d774ea 100644
--- a/src/charon-cmd/cmd/cmd_options.c
+++ b/src/charon-cmd/cmd/cmd_options.c
@@ -31,6 +31,8 @@ cmd_option_t cmd_options[CMD_OPT_COUNT] = {
"set the default log level (-1..4, default: 1)", {}},
{ CMD_OPT_HOST, "host", required_argument, "hostname",
"DNS name or address to connect to", {}},
+ { CMD_OPT_HOST_LOCAL, "host-local", required_argument, "hostname",
+ "DNS name or address to connect from (default: %any)", {}},
{ CMD_OPT_IDENTITY, "identity", required_argument, "identity",
"identity the client uses for the IKE exchange", {}},
{ CMD_OPT_EAP_IDENTITY, "eap-identity", required_argument, "eap-identity",
diff --git a/src/charon-cmd/cmd/cmd_options.h b/src/charon-cmd/cmd/cmd_options.h
index 47249181bb..a97fdd3f6b 100644
--- a/src/charon-cmd/cmd/cmd_options.h
+++ b/src/charon-cmd/cmd/cmd_options.h
@@ -34,6 +34,7 @@ enum cmd_option_type_t {
CMD_OPT_VERSION,
CMD_OPT_DEBUG,
CMD_OPT_HOST,
+ CMD_OPT_HOST_LOCAL,
CMD_OPT_IDENTITY,
CMD_OPT_EAP_IDENTITY,
CMD_OPT_XAUTH_USER,