Index | Thread | Search

From:
hshoexer <hshoexer@yerbouti.franken.de>
Subject:
iked(8): Ignore IKEv1 messages when not configured
To:
tech@openbsd.org
Date:
Mon, 9 Nov 2026 22:29:21 +0100

Download raw body.

Thread
Hi,

a little follow-up on the recent ikev1 change:  When there are no
ikev1 rules in iked.conf defined, just drop ikev1 packets right
away; no need to forward them to the ikev1 sub-process.  That matches
the original iked behaviour.

ok?

Take care,
HJ.

---
 sbin/iked/iked.h      | 2 ++
 sbin/iked/ikev2_msg.c | 5 +++++
 sbin/iked/parse.y     | 4 ++++
 3 files changed, 11 insertions(+)

diff --git a/sbin/iked/iked.h b/sbin/iked/iked.h
index 8e60b3f043b..4b21f425643 100644
--- a/sbin/iked/iked.h
+++ b/sbin/iked/iked.h
@@ -868,6 +868,7 @@ struct iked_static {
 	in_port_t		 st_nattport;
 	int			 st_stickyaddress; /* addr per DSTID  */
 	int			 st_vendorid;
+	int			 st_ikev1inuse;
 };
 
 struct iked {
@@ -888,6 +889,7 @@ struct iked {
 #define sc_nattport		sc_static.st_nattport
 #define sc_stickyaddress	sc_static.st_stickyaddress
 #define sc_vendorid		sc_static.st_vendorid
+#define sc_ikev1inuse		sc_static.st_ikev1inuse
 
 	struct iked_policies		 sc_policies;
 	struct iked_policy		*sc_defaultcon;
diff --git a/sbin/iked/ikev2_msg.c b/sbin/iked/ikev2_msg.c
index b791e6f7a24..68f170e74cc 100644
--- a/sbin/iked/ikev2_msg.c
+++ b/sbin/iked/ikev2_msg.c
@@ -136,6 +136,11 @@ ikev1_recv(struct iked *env, struct iked_message *msg)
 	    print_addr(&msg->msg_peer), print_addr(&msg->msg_local),
 	    msg->msg_natt ? ", NAT-T" : "");
 
+	if (!env->sc_ikev1inuse) {
+		log_debug("%s: IKEv1 not configured", __func__);
+		return;
+	}
+
 	bzero(&dg, sizeof(dg));
 	memcpy(&dg.dg_peer, &msg->msg_peer, sizeof(dg.dg_peer));
 	dg.dg_peerlen = msg->msg_peerlen;
diff --git a/sbin/iked/parse.y b/sbin/iked/parse.y
index c9e7aa2662e..040f6d0df50 100644
--- a/sbin/iked/parse.y
+++ b/sbin/iked/parse.y
@@ -112,6 +112,7 @@ static long		 ocsp_maxage = -1;
 static int		 cert_partial_chain = 0;
 static struct iked_radopts
 			 radauth, radacct;
+static int		 ikev1inuse = 0;
 
 struct iked_transform ikev2_default_ike_transforms[] = {
 	{ IKEV2_XFORMTYPE_ENCR, IKEV2_XFORMENCR_AES_CBC, 256 },
@@ -590,6 +591,7 @@ ikev1rule	: IKEV1 name ikeflags satype af proto rdomain hosts_list peers
 				yyerror("create_ike failed");
 				YYERROR;
 			}
+			ikev1inuse = 1;
 		}
 		;
 
@@ -2051,6 +2053,7 @@ parse_config(const char *filename, struct iked *x_env)
 	radauth.max_failovers = 0;
 	radacct.max_tries = 3;
 	radacct.max_failovers = 0;
+	ikev1inuse = 0;
 
 	if (env->sc_opts & IKED_OPT_PASSIVE)
 		passive = 1;
@@ -2073,6 +2076,7 @@ parse_config(const char *filename, struct iked *x_env)
 	env->sc_vendorid = vendorid;
 	env->sc_radauth = radauth;
 	env->sc_radacct = radacct;
+	env->sc_ikev1inuse = ikev1inuse;
 
 	if (!rules)
 		log_warnx("%s: no valid configuration rules found",
-- 
2.56.0