From nobody Thu May 05 12:06:43 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id A00BA1AA8B7E; Thu, 5 May 2022 12:06:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KvC9H44Csz4hxj; Thu, 5 May 2022 12:06:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651752403; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pzmOivkXHGB/JnPcFZUUktnl2eptLu9mKvVpQlQ00K0=; b=O3GNTearxxO1L8uqysM1pgieC4wFa0GF0BSCa5KjURfrEXR7kWC3JMoZMr3u/TAkoSUM59 9kayIzDJLJXhTW7R3yuJtwlw7wy4lajgATcpQr1vibJH/fFnd0cjc+DyMMzwG920KQkRGn Qr3Rxq/uaSWtaF9NYmW1cU0O1gokeyizy0i+2RJp4wfKgtPEhAEokjgYtGVgzLsK4fkXzT 2Qs2JtNrh8GYipYNBxk6cGvjf3lGLx1ThEqDMy/YIQfWq519GLMsqdnTu5mN7h9+mN4H4Z VZd9yB7lDpHst2LthCBxyd1Z1kHYo2T1HrJ6xyVGIt4tJblcRxWVHAR+sAWqew== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6BDC22712C; Thu, 5 May 2022 12:06:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 245C6hnY010118; Thu, 5 May 2022 12:06:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 245C6h0O010117; Thu, 5 May 2022 12:06:43 GMT (envelope-from git) Date: Thu, 5 May 2022 12:06:43 GMT Message-Id: <202205051206.245C6h0O010117@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Eugene Grosbein Subject: git: 0aef8628458a - main - If setkey(8) is used without ipsec.ko loaded beforehand, its attempt to install SA/SPD into the kernel results in cryptic EINVAL error code. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: eugen X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0aef8628458a7d03e3c7e63ae05e228191167eec Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651752403; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pzmOivkXHGB/JnPcFZUUktnl2eptLu9mKvVpQlQ00K0=; b=tMj8AVQBXuXs2ngUe8s32I/lI21x0/BKFoIDWwk2B2/TblXUqpVSo8m+WukLMo7eofAv0u jEdu3uLIy+++55NOP31USiPpBVMgfRBv942/SlaHdg251YuIK5VSlBLCSlp7U9a18EYFGI tvcl3BLmzWFhxRk64/TeQLH6CQgojp2xEYoiDcjitMDbs/bT5gZUjmMbpwHgivDFYtVsOK SjGZQ+XBEcsn1iknX4uUgEV9TriKM+Xd7WEzEL7KcnWr8+O+xPwDwXkYq27hoMqHMPbY8S jBuQii+OO1hNS4xCdSXu1kg+3fzV6x4xe2gFj/6Jv9Ytln9wthwYlShEGEc0NQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651752403; a=rsa-sha256; cv=none; b=cQpaWDRD219qg2+gGqNGpoGCixZsRIriK/RNAUNljZk1zh8t2kGXXlV8HZhg20z+V9vDZa Tk+YtRhxudoFAhGMhBJph6aeniIR5+DgC6/pAmOu1T1s93YdLnCkxaN90lDNZbTUgbOkwD EYxIcQ7R8BbQCT3FQTFVOPuiRzVg2iaE4mMQgD10QlEyH9noDdQxaH0wZozAWbjnszJhjD hFgoTArIIIkIfzTktLHc6bqsh7IxV8AMEpCP2Q2nRox1p8K2214/54di5x8+upmql4fcqs WkMwwbgUK3AZsr9mJSNrBZIJ/8S6Kil5OOPlH4++sxVwPkAa11X2v2Kwoz+70Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by eugen: URL: https://cgit.FreeBSD.org/src/commit/?id=0aef8628458a7d03e3c7e63ae05e228191167eec commit 0aef8628458a7d03e3c7e63ae05e228191167eec Author: Eugene Grosbein AuthorDate: 2022-05-05 12:02:29 +0000 Commit: Eugene Grosbein CommitDate: 2022-05-05 12:02:29 +0000 If setkey(8) is used without ipsec.ko loaded beforehand, its attempt to install SA/SPD into the kernel results in cryptic EINVAL error code. Let it be a bit more user-friendly and try to load ipsec.ko automatically if it is not loaded, just like ifconfig(8) does it for modules it needs. PR: 263379 MFC after: 2 weeks --- sbin/setkey/setkey.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sbin/setkey/setkey.c b/sbin/setkey/setkey.c index d556a842f048..faf6373b312e 100644 --- a/sbin/setkey/setkey.c +++ b/sbin/setkey/setkey.c @@ -34,6 +34,8 @@ #include #include +#include +#include #include #include #include @@ -67,6 +69,7 @@ void shortdump_hdr(void); void shortdump(struct sadb_msg *); static void printdate(void); static int32_t gmt2local(time_t); +static int modload(const char *name); #define MODE_SCRIPT 1 #define MODE_CMDDUMP 2 @@ -102,6 +105,17 @@ usage(void) exit(1); } +static int +modload(const char *name) +{ + if (modfind(name) < 0) + if (kldload(name) < 0 || modfind(name) < 0) { + warn("%s: module not found", name); + return 0; + } + return 1; +} + int main(int ac, char **av) { @@ -165,6 +179,7 @@ main(int ac, char **av) } } + modload("ipsec"); so = pfkey_open(); if (so < 0) { perror("pfkey_open");