git: d47c1c2cf562 - main - sbin/setkey: add -Z option to disable receive timeouts

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 27 Jan 2026 00:45:08 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=d47c1c2cf562a7583758387cd652e98b91ab83f6

commit d47c1c2cf562a7583758387cd652e98b91ab83f6
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-01-20 12:09:47 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-01-27 00:44:03 +0000

    sbin/setkey: add -Z option to disable receive timeouts
    
    Sponsored by:   NVidia networking
    MFC after:      1 week
---
 sbin/setkey/setkey.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/sbin/setkey/setkey.c b/sbin/setkey/setkey.c
index f7268d8f1e10..3caf83c8eebc 100644
--- a/sbin/setkey/setkey.c
+++ b/sbin/setkey/setkey.c
@@ -86,6 +86,7 @@ static int f_policy = 0;
 static int f_hexdump = 0;
 static int f_tflag = 0;
 static int f_scope = 0;
+static int f_notimeout = 0;
 static time_t thiszone;
 
 extern int lineno;
@@ -129,7 +130,7 @@ main(int ac, char **av)
 
 	thiszone = gmt2local(0);
 
-	while ((c = getopt(ac, av, "acde:f:ghltvxDFP")) != -1) {
+	while ((c = getopt(ac, av, "abcde:f:ghltvxDFPZ")) != -1) {
 		switch (c) {
 		case 'c':
 			f_mode = MODE_SCRIPT;
@@ -187,6 +188,9 @@ main(int ac, char **av)
 		case 'v':
 			f_verbose = 1;
 			break;
+		case 'Z':
+			f_notimeout = 1;
+			break;
 		default:
 			usage();
 			/*NOTREACHED*/
@@ -332,16 +336,18 @@ sendkeymsg(char *buf, size_t len)
 	u_char rbuf[1024 * 32];	/* XXX: Enough ? Should I do MSG_PEEK ? */
 	ssize_t l;
 	struct sadb_msg *msg;
-
-    {
 	struct timeval tv;
-	tv.tv_sec = 1;
-	tv.tv_usec = 0;
-	if (setsockopt(so, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
-		perror("setsockopt");
-		goto end;
+
+
+	if (!f_notimeout) {
+		tv.tv_sec = 1;
+		tv.tv_usec = 0;
+		if (setsockopt(so, SOL_SOCKET, SO_RCVTIMEO, &tv,
+		    sizeof(tv)) < 0) {
+			perror("setsockopt");
+			goto end;
+		}
 	}
-    }
 
 	if (f_forever)
 		shortdump_hdr();