From 74fd2593a71420abf33930eb2b0b78c14e181c7e Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 Jun 2026 09:02:35 +0200 Subject: [PATCH] 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. --- src/charon-cmd/cmd/cmd_connection.c | 12 ++++++++++-- src/charon-cmd/cmd/cmd_options.c | 2 ++ src/charon-cmd/cmd/cmd_options.h | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/charon-cmd/cmd/cmd_connection.c b/src/charon-cmd/cmd/cmd_connection.c index 9b19bb45c..030fe6d1d 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 6731177c3..97d1d774e 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 47249181b..a97fdd3f6 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,