From patchwork Thu May 15 15:00:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4251 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:a32a:b0:656:592e:a137 with SMTP id jh42csp980766mab; Thu, 15 May 2025 08:01:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW7p6Zl1A3C5tcvldBIv19PHLX476JLNfz60FJXJDRNRGna7Mj7DDEzMTdQANy2zHeC5JEsD/idsXg=@openvpn.net X-Google-Smtp-Source: AGHT+IGg+fZVAFST18QxbxQsLijvQn59kbq87DvpRBnDCSxZ47Y/ALm9tACb5UOtEnIuf3aiv8mA X-Received: by 2002:a92:cd84:0:b0:3d8:1e96:1f0 with SMTP id e9e14a558f8ab-3db6f81a358mr94141415ab.20.1747321261314; Thu, 15 May 2025 08:01:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1747321261; cv=none; d=google.com; s=arc-20240605; b=NHNlE1009XW9kS5DwLCOD+dqO/dtdQhIjwQPAk61Vup3MThZP7H5cy0BxuEGdWVM8W EK9vK83se8OirE/YbsmtRZYDcmRl3hLZIvLgcNdRj1TFeKgbwKrCgTOpIaYoSb6FuZu/ 2KWieOxXpUY1pXKQUYB9vYLtRm+8k5Ke4EKHxgT0ifnJ65uCNTVN0cZtdDAgF/zOsWcD jXxuYVv2p3/aHhiwfeCLmEeKIv2A7JDmLjInj3F+i+675wPqE6ufxlm8GOmMS81qjNdo G98g50V1fKkbIc7zG0dRMcJire3YWAaRYJh4Pc/OfSv4z+OrDUJVFC0vbPSuK2ncUQxS fO7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=T2BUMR+4YCn/MmTfl8/Au5/LVYX8QJ3boZtv9dZB1lA=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=FarvzHWbKrccGoL9OlklJpQ0S+cqmf6dDKi0ON6K+evqWNYyFFClOVrCmyvkzl+iKZ 5yoFWziVya4LMs0K0O0RUZ+3mA2cWX3zARTqxmisTvFVrq9FpqE6rW/nSEANBa/FT4EQ 1wXUtOj+6QmYJ+y7fJrxl6vbW3zz0Tlxx15GF70/FxIEuvy2RkOeQKD1g8wfv3dsPwOH pt23HqBjMa56GC66WD/PhSLsh8bSj2a64tDFeeWU7WDVOjQ5i8SBqt7T22ulYB8A4KA+ 9RAeXiyOoKNop6SAFJv9Jq50M3wbwYyJVX875wlzgJb8MBU90gmU4MIwQdwilOoXUtqZ mVpw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b="Pk6hM/KE"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Dw3q+Ol1; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Kbqq+aQx; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id e9e14a558f8ab-3da7e11d227si85362395ab.5.2025.05.15.08.01.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 May 2025 08:01:00 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b="Pk6hM/KE"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Dw3q+Ol1; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Kbqq+aQx; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=T2BUMR+4YCn/MmTfl8/Au5/LVYX8QJ3boZtv9dZB1lA=; b=Pk6hM/KEF8XM4RbeOOxKcYng1F JVpAqttxu1NkEQ+kQTysbzOGJM3jUycqnOYcXqb9F94ooCFlHVC5P8mHkdrZ03WAz4JbZ6OQFy+hU AJikBNTQ5DNJ4d4gwT18+vmLgF3qeixjxQXm/cyjBqPDZgcFw2H5F49bFdREMPzzbUEk=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1uFa4t-0005Oq-It; Thu, 15 May 2025 15:00:55 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uFa4s-0005Of-4A for openvpn-devel@lists.sourceforge.net; Thu, 15 May 2025 15:00:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=qIpGLMHhyAoNw3xCX+JLDjcfIt0PAIRGRBRPnToSMsE=; b=Dw3q+Ol1SEOa5ZCNXh3w4dxP3j /yJbeGousbseAyh1QcelHOunBRVPJRx7Q+E1+u2QzduifEMqVDKKW/sLNUsVUwJnUiO33vuVoLeyL XbdZIkHsWZ7JPtTjmSHSMj/tleamzB6bKlIQVyAQG+sOshsVkT+TKjPwTkA3/dLIoM1s=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=qIpGLMHhyAoNw3xCX+JLDjcfIt0PAIRGRBRPnToSMsE=; b=Kbqq+aQx8WTa7K44ApkfogCO9q rKY3hKdINpJhOggqlZp8rd+xjf5IKlCddtrPCfOaWZqiAMQHHt2ArpVrstm/V1xA5ySfasEUdA3sN qm5u3RGCFolZnVbP7DTJQ5Ovvz2yDbC1BA/zqXSRWY9xAhn5Sa+vtXnfx71CA2fK9LJE=; Received: from [193.149.48.143] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1uFa4k-0004Eg-Ey for openvpn-devel@lists.sourceforge.net; Thu, 15 May 2025 15:00:48 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.17.1.9/8.17.1.9) with ESMTP id 54FF0dPK030130 for ; Thu, 15 May 2025 17:00:39 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.17.1.9/8.17.1.9/Submit) id 54FF0dX6030129 for openvpn-devel@lists.sourceforge.net; Thu, 15 May 2025 17:00:39 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Thu, 15 May 2025 17:00:31 +0200 Message-ID: <20250515150038.30097-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "6901ab67b84d", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Ralf Lici Add detection of the ovpn kernel module type: if a backported (out-of-tree) version is loaded, the MODULE_VERSION string is read from sysfs; otherwise, for the in-tree module, the function reports the [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1uFa4k-0004Eg-Ey Subject: [Openvpn-devel] [PATCH v2] Implement ovpn version detection X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1832199139165826969?= X-GMAIL-MSGID: =?utf-8?q?1832199139165826969?= From: Ralf Lici Add detection of the ovpn kernel module type: if a backported (out-of-tree) version is loaded, the MODULE_VERSION string is read from sysfs; otherwise, for the in-tree module, the function reports the kernel release and version. Change-Id: I7fc033a7ffee73045316763356a95d75ef23f5ad Signed-off-by: Ralf Lici Acked-by: Gert Doering --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1022 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c index c950e3d..a5f9e06 100644 --- a/src/openvpn/dco_linux.c +++ b/src/openvpn/dco_linux.c @@ -1117,10 +1117,77 @@ return true; } +/** + * There's no version indicator in the ovpn in-tree module, so we return a + * string containing info about the kernel version and release. + */ +static const char * +dco_version_string_in_tree(struct gc_arena *gc) +{ + struct buffer buf = alloc_buf_gc(256, gc); + struct utsname system; + + if (uname(&system)) + { + return "ERR"; + } + + buf_puts(&buf, system.release); + buf_puts(&buf, " "); + buf_puts(&buf, system.version); + return BSTR(&buf); +} + +/** + * When the module is loaded, the backports version of ovpn has a version file + * in sysfs. Read it and return the string. + * + * The caller is responsible for closing the file pointer. + */ +static const char * +dco_version_string_backports(FILE *fp, struct gc_arena *gc) +{ + char *str = gc_malloc(PATH_MAX, false, gc); + + if (!fgets(str, PATH_MAX, fp)) + { + return "ERR"; + } + + /* remove potential newline at the end of the string */ + char *nl = strchr(str, '\n'); + if (nl) + { + *nl = '\0'; + } + + return str; +} + const char * dco_version_string(struct gc_arena *gc) { - return "Unknown"; + const char *version; + struct stat sb; + FILE *fp; + + if (stat("/sys/module/ovpn", &sb) != 0 || !S_ISDIR(sb.st_mode)) + { + return "N/A"; + } + + /* now that we know for sure that the module is loaded, if there's no + * version file it means we're dealing with the in-tree version, otherwise + * it's backports */ + fp = fopen("/sys/module/ovpn/version", "r"); + if (!fp) + { + return dco_version_string_in_tree(gc); + } + version = dco_version_string_backports(fp, gc); + + fclose(fp); + return version; } void