From patchwork Fri Jan 31 08:47:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4112 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:c520:b0:5e7:b9eb:58e8 with SMTP id jx32csp538382mab; Fri, 31 Jan 2025 00:47:36 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWx2yqTe9hjp6g0Zf/T+MtSXcCyH4NKkZdl+RAmtJH/Y+I5SJxB7ZICJoFr5hgRRIMTMgZjvqDSS2w=@openvpn.net X-Google-Smtp-Source: AGHT+IHkE44myNEQk/8bVDDmNitdsKc02648nEoKe0E3DNKfZbHyijzFRnMtFfHn420+kZl/BQ8k X-Received: by 2002:a05:6820:1b84:b0:5fa:2edd:8e65 with SMTP id 006d021491bc7-5fc004b7d65mr7226726eaf.8.1738313256804; Fri, 31 Jan 2025 00:47:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1738313256; cv=none; d=google.com; s=arc-20240605; b=Re5tILsc47QQWxwYcb+s1+IX9HAM72X/8Z4DSBtIGU1+SCWE+cu4b1vSO5wpI7eUib jmCLBls/+N5PyHX2atRLUpoLudSs0QvcwplqGzPisYmIbr0l4PeaDmjCn+tQ34UKBhzD 2ht2LOBbizzB0Z8oAnFVQntGmTA9ntPPH6Non+4oYW0PeEqIkWnR1qkQrnCEJe32XFam 6TNiAT42MTdgioTp4Ed/JcszpgLlkxc//8WPfyBTaOM/yJ1iX3OnwST8f8Wfk8UZ3PNf z4gXy4mOCb3/+ViKxR1b4E3NDKd0XTd1dFvHGDyI7SD4UeHpH07lf9JUbItwt9rDUlcn KB7Q== 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; bh=T4ccAYl3DqQTpKBKiE6klUdFHPpv6MrhiTBiIYKh9II=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=bl1LaIAMKSPgKMMhxLv7xYAPbst68w50x6LRO1AHJfAhraWa6P1E6fWMg7LnCiuiOa IdLjRPcnVK5+HyePdHROhk4jvQFOL/5bdPHEWd2/w2KcNTJRtVMajPPVxAl92j3uoKz9 RdBGHHy4Hf4dcXgk33EmcwIRCiaB7UatugT0OWhVf5NOh37xVcyWWr9dgsPYAJaYUMIq O+UkzqEeBT9nXqgOGECjYflkANYpegEMW6QPCwJjEr1mGCQWLWXvsQgiAkeAKobLPTHd zz0bX3qgerbbIv1S5MYc2QjrDclhLqb/QOyJOopQRJMF8LACgYSzyio2ZYev2voVJ58I DhAQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=ZGcndgTh; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=UftZiIG1; 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 006d021491bc7-5fc104c5341si3687397eaf.19.2025.01.31.00.47.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jan 2025 00:47:36 -0800 (PST) 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=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=ZGcndgTh; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=UftZiIG1; 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 [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 1tdmgV-0005TF-J6; Fri, 31 Jan 2025 08:47:32 +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 1tdmgO-0005QT-Ki for openvpn-devel@lists.sourceforge.net; Fri, 31 Jan 2025 08:47:25 +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=xV4E1vcd+h9UMqX5qeFO19+G0V7WiXHebp6dWSmGkew=; b=ZGcndgThLx9JpyflkHhGBVIB6d DgJgbEjt0gFQ7WpH1Z+R3TXcsYhUQqUOYdMF32g9QwTXXB+7KvoCNvglsTgy5Qh35awAKQy5vSqwr CMxvLOHKjzAoWPCUUIz26y+bRJQrDt4oDu5MNmVXWelyN0QzFrmWDXovkHL8dS/SFBdg=; 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=xV4E1vcd+h9UMqX5qeFO19+G0V7WiXHebp6dWSmGkew=; b=UftZiIG1Y/QTWp9ET8J1Jt2jKd 3++m933Y6ahVm4DqusKWfL2I4PPA/Ba3RrGv8j8d7+7L196XQOn50PBH7mDqxnx9otGc+8GaRNz6o n/lQ7++GuV52vmY2DjsRBQ1R3mHiy3/XWRXq2bNdPG5KyUGQiiqUPkpcjFbYZ6kpbf3Q=; Received: from dhcp-174.greenie.muc.de ([193.149.48.174] 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 1tdmgJ-0007qS-A3 for openvpn-devel@lists.sourceforge.net; Fri, 31 Jan 2025 08:47:20 +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 50V8l7pT024917 for ; Fri, 31 Jan 2025 09:47:07 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.17.1.9/8.17.1.9/Submit) id 50V8l7QO024916 for openvpn-devel@lists.sourceforge.net; Fri, 31 Jan 2025 09:47:07 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Fri, 31 Jan 2025 09:47:07 +0100 Message-ID: <20250131084707.24905-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-1.v13.lw.sourceforge.com", 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: Remove the old "read /proc/net/route and try to parse it" implementation and always use the sitnl/netlink implementation of net_route_v4_best_gw(). This was kept "because we had it and it was working" but does not really provide any benefit - netlink for route queries is there for v6 anyway, and the main argument for keeping --enable-iproute2 is [...] Content analysis details: (0.0 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [193.149.48.174 listed in sa-accredit.habeas.com] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [193.149.48.174 listed in bl.score.senderscore.com] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1tdmgJ-0007qS-A3 Subject: [Openvpn-devel] [PATCH v2] get_default_gateway(): implement platform support for Linux/IPROUTE2 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?1822753561663155788?= X-GMAIL-MSGID: =?utf-8?q?1822753561663155788?= Remove the old "read /proc/net/route and try to parse it" implementation and always use the sitnl/netlink implementation of net_route_v4_best_gw(). This was kept "because we had it and it was working" but does not really provide any benefit - netlink for route queries is there for v6 anyway, and the main argument for keeping --enable-iproute2 is "some users want to run non-standard 'ip' binaries to do things" - which is not affected by this change. Change-Id: I6f17140109106b37e6b0e690df1d87720ccf6f91 Signed-off-by: Gert Doering Acked-by: Antonio Quartulli --- 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/+/884 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Antonio Quartulli diff --git a/src/openvpn/networking_iproute2.c b/src/openvpn/networking_iproute2.c index 975282c..6f13ef5 100644 --- a/src/openvpn/networking_iproute2.c +++ b/src/openvpn/networking_iproute2.c @@ -394,63 +394,15 @@ return ret; } -int -net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, - in_addr_t *best_gw, char *best_iface) -{ - best_iface[0] = '\0'; - - FILE *fp = fopen("/proc/net/route", "r"); - if (!fp) - { - return -1; - } - - char line[256]; - int count = 0; - unsigned int lowest_metric = UINT_MAX; - while (fgets(line, sizeof(line), fp) != NULL) - { - if (count) - { - unsigned int net_x = 0; - unsigned int mask_x = 0; - unsigned int gw_x = 0; - unsigned int metric = 0; - unsigned int flags = 0; - char name[16]; - name[0] = '\0'; - - const int np = sscanf(line, "%15s\t%x\t%x\t%x\t%*s\t%*s\t%d\t%x", - name, &net_x, &gw_x, &flags, &metric, - &mask_x); - - if (np == 6 && (flags & IFF_UP)) - { - const in_addr_t net = ntohl(net_x); - const in_addr_t mask = ntohl(mask_x); - const in_addr_t gw = ntohl(gw_x); - - if (!net && !mask && metric < lowest_metric) - { - *best_gw = gw; - strcpy(best_iface, name); - lowest_metric = metric; - } - } - } - ++count; - } - fclose(fp); - - return 0; -} - /* - * The following function is not implemented in the iproute backend as it + * The following functions are not implemented in the iproute backend as it * uses the sitnl implementation from networking_sitnl.c. * * int + * net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, + * in_addr_t *best_gw, char *best_iface) + * + * int * net_route_v6_best_gw(const struct in6_addr *dst, * struct in6_addr *best_gw, char *best_iface) */ diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c index 6b750e8..9de8912 100644 --- a/src/openvpn/networking_sitnl.c +++ b/src/openvpn/networking_sitnl.c @@ -619,8 +619,7 @@ } -#ifdef ENABLE_SITNL - +/* used by iproute2 implementation too */ int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, in_addr_t *best_gw, char *best_iface) @@ -652,6 +651,8 @@ return ret; } +#ifdef ENABLE_SITNL + int net_iface_up(openvpn_net_ctx_t *ctx, const char *iface, bool up) {