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 F2C4170AC4 for ; Fri, 14 May 2021 15:45:44 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E266E17C98 for ; Fri, 14 May 2021 15:45:14 +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 86F2A17B8F for ; Fri, 14 May 2021 15:45:13 +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 618004656A for ; Fri, 14 May 2021 15:45:13 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Fri, 14 May 2021 15:44:51 +0200 Message-Id: <20210514134457.1447930-16-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.012 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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. [proxmox-backup-proxy.rs, tools.rs, socket.rs, http.rs] Subject: [pbs-devel] [PATCH proxmox-backup 2/8] refactor: move socket helper to proxmox crate 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:45 -0000 and constant to tools module. Signed-off-by: Fabian Grünbichler --- Notes: requires proxmox patch #5 and proxmox version bump src/bin/proxmox-backup-proxy.rs | 6 ++---- src/tools.rs | 4 +++- src/tools/http.rs | 7 +++---- src/tools/socket.rs | 23 ----------------------- 4 files changed, 8 insertions(+), 32 deletions(-) delete mode 100644 src/tools/socket.rs diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index 71517023..a53f554a 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -11,6 +11,7 @@ use serde_json::Value; use proxmox::try_block; use proxmox::api::RpcEnvironmentType; +use proxmox::sys::linux::socket::set_tcp_keepalive; use proxmox_backup::{ backup::DataStore, @@ -38,6 +39,7 @@ use proxmox_backup::buildcfg; use proxmox_backup::server; use proxmox_backup::auth_helpers::*; use proxmox_backup::tools::{ + PROXMOX_BACKUP_TCP_KEEPALIVE_TIME, daemon, disks::{ DiskManage, @@ -45,10 +47,6 @@ use proxmox_backup::tools::{ get_pool_from_dataset, }, logrotate::LogRotate, - socket::{ - set_tcp_keepalive, - PROXMOX_BACKUP_TCP_KEEPALIVE_TIME, - }, }; use proxmox_backup::api2::pull::do_sync_job; diff --git a/src/tools.rs b/src/tools.rs index 8f2acded..8a1d0bc7 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -43,7 +43,6 @@ pub mod lru_cache; pub mod nom; pub mod runtime; pub mod serde_filter; -pub mod socket; pub mod statistics; pub mod subscription; pub mod systemd; @@ -483,6 +482,9 @@ impl AsAny for T { } } +/// The default 2 hours are far too long for PBS +pub const PROXMOX_BACKUP_TCP_KEEPALIVE_TIME: u32 = 120; + /// This used to be: `SIMPLE_ENCODE_SET` plus space, `"`, `#`, `<`, `>`, backtick, `?`, `{`, `}` pub const DEFAULT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS // 0..1f and 7e // The SIMPLE_ENCODE_SET adds space and anything >= 0x7e (7e itself is already included above) diff --git a/src/tools/http.rs b/src/tools/http.rs index 0821992a..1d96c70f 100644 --- a/src/tools/http.rs +++ b/src/tools/http.rs @@ -18,12 +18,11 @@ use tokio::{ }; use tokio_openssl::SslStream; +use proxmox::sys::linux::socket::set_tcp_keepalive; + use crate::tools::{ + PROXMOX_BACKUP_TCP_KEEPALIVE_TIME, async_io::MaybeTlsStream, - socket::{ - set_tcp_keepalive, - PROXMOX_BACKUP_TCP_KEEPALIVE_TIME, - }, }; // Build a http::uri::Authority ("host:port"), use '[..]' around IPv6 addresses diff --git a/src/tools/socket.rs b/src/tools/socket.rs deleted file mode 100644 index 01e5edec..00000000 --- a/src/tools/socket.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::os::unix::io::RawFd; - -use nix::sys::socket::sockopt::{KeepAlive, TcpKeepIdle}; -use nix::sys::socket::setsockopt; - -pub const PROXMOX_BACKUP_TCP_KEEPALIVE_TIME: u32 = 120; - -/// 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 -/// our backup tools. -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