From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id CF80A70AA2 for ; Fri, 14 May 2021 15:45:40 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C6CF017B3B for ; Fri, 14 May 2021 15:45:10 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 40E8917AFA for ; Fri, 14 May 2021 15:45:09 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 15FC646566 for ; Fri, 14 May 2021 15:45:04 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Fri, 14 May 2021 15:44:41 +0200 Message-Id: <20210514134457.1447930-6-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210514134457.1447930-1-f.gruenbichler@proxmox.com> References: <20210514134457.1447930-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.036 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [mod.rs, socket.rs] Subject: [pbs-devel] [PATCH proxmox 05/13] proxmox: takeover socket helper from proxmox_backup X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 May 2021 13:45:40 -0000 Signed-off-by: Fabian Grünbichler --- proxmox/src/sys/linux/mod.rs | 1 + proxmox/src/sys/linux/socket.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 proxmox/src/sys/linux/socket.rs diff --git a/proxmox/src/sys/linux/mod.rs b/proxmox/src/sys/linux/mod.rs index ee616a3..ccd710c 100644 --- a/proxmox/src/sys/linux/mod.rs +++ b/proxmox/src/sys/linux/mod.rs @@ -6,6 +6,7 @@ pub mod magic; pub mod pid; pub mod procfs; pub mod pty; +pub mod socket; pub mod tty; /// Get pseudo random data (/dev/urandom) diff --git a/proxmox/src/sys/linux/socket.rs b/proxmox/src/sys/linux/socket.rs new file mode 100644 index 0000000..6c63c3c --- /dev/null +++ b/proxmox/src/sys/linux/socket.rs @@ -0,0 +1,21 @@ +use std::os::unix::io::RawFd; + +use nix::sys::socket::sockopt::{KeepAlive, TcpKeepIdle}; +use nix::sys::socket::setsockopt; + +/// Set TCP keepalive time on a socket +/// +/// See "man 7 tcp" for details. +/// +/// The default on Linux is 7200 (2 hours) which is far too long for +/// many of our use cases. +pub fn set_tcp_keepalive( + socket_fd: RawFd, + tcp_keepalive_time: u32, +) -> nix::Result<()> { + + setsockopt(socket_fd, KeepAlive, &true)?; + setsockopt(socket_fd, TcpKeepIdle, &tcp_keepalive_time)?; + + Ok(()) +} -- 2.20.1