From patchwork Thu Jan 30 18:13:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "cron2 (Code Review)" X-Patchwork-Id: 4110 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:c520:b0:5e7:b9eb:58e8 with SMTP id jx32csp227022mab; Thu, 30 Jan 2025 10:13:39 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWMq8e7Xc5Y8TjJfjO4wpYFILB8U18v4bNcbODF2kdCGZ9GWlkaGXR1V1B9rsuEqx5vDlOM10G9IRY=@openvpn.net X-Google-Smtp-Source: AGHT+IET6RAs5r61dSKiWUneOuQdV5hsPH8xjBM99hG7r4Pzk8LKQYezJnhn/iCPoacI+MLK+mWk X-Received: by 2002:a05:6870:6b98:b0:29e:51ca:68b4 with SMTP id 586e51a60fabf-2b32f0ce5aemr5013593fac.19.1738260819462; Thu, 30 Jan 2025 10:13:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1738260819; cv=none; d=google.com; s=arc-20240605; b=Wr7oTo/UJtJHY26vM+kCX8+EMe+fRKIi1Sd7mhukcCC11W+aTOhdigDstxg2VzrBNx JB/mz6AJnX4C+hEG/ZwWMr1Ryx6KbBBi4ix6k9QoqYvwPZvfWB7j0JDXI0b6X7X/JRCA 18rKFGdiVYz8SRWEXR80WU1nEVo8gBwyr8TP8+xHupTq/Q3elgQ/A/WbiTrL6rSZfNuO dlStCMkR9zyJGBS4MeDKcbRK9Nk6EBZISVxr6CD2bV/mrTk25dFoATLomlLZWPsrjMij qqGJ0AKAgqhW0y2V4hbLcrpjum5Jv73ZB2tCWiiA6kpkDVFsnqJeG1gi2SWl0vqT6oFs NaxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:cc:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:user-agent :mime-version:message-id:references:auto-submitted:to:date:from :dkim-signature:dkim-signature:dkim-signature; bh=dP7S1OWlvNp/0TzBl+S6RwkFGDeQGZxRegdhbFvh1ac=; fh=U7wEyxtwz2o5+UdevFSA47vNeG9knhWH0KV//QhD5a0=; b=NKWceP3ffEr1FNvXtwLildQoxrjP2zUnvd3o6vja7ynpbADzk6zv1BgIZFvMKqNEVV A5QgV/H5c0XNRBbTJZAIC2RvBqfQRr5l1ntug1391NJMwEHWzR/UXzdFMPQ9phxmF/oX nmUH63jRKGr4GWqMbvRM0VWZxM8Euz+zQerTrn4vD58eJ733Uv13E9f5nv+w3qOn//YH nXR4gKVabQQB0AhZPO/GMlqnVDFeyqhelUUGq0es0YklJp75aWvcMXpBmseRH1NCGJAa mHCUR5AHg4vqok782rCfzy2UzH4hC53suM5EMVj1eY/b6faJXyhvNU4UyuW1lsXHhLz3 7OGA==; 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=PR2z4The; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Zoqbwe3w; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=dgZ35bDl; 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=openvpn.net; dara=fail header.i=@openvpn.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 586e51a60fabf-2b35672f25bsi2107474fac.282.2025.01.30.10.13.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Jan 2025 10:13:39 -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=PR2z4The; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Zoqbwe3w; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=dgZ35bDl; 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=openvpn.net; dara=fail header.i=@openvpn.net Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tdZ2l-0003ZQ-GP; Thu, 30 Jan 2025 18:13:35 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tdZ2i-0003ZI-L3 for openvpn-devel@lists.sourceforge.net; Thu, 30 Jan 2025 18:13:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Reply-To:References:Subject:List-Unsubscribe:List-Id:Cc:To:Date: From:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help: List-Subscribe:List-Post:List-Owner:List-Archive; bh=YKnhHSab2PC7xC90KTncirDgNqJ6aGUl56BrOB6QMoM=; b=PR2z4ThecUxkPSV3JySZB74dHR Zhh7/eKoWU+/HgLp+AC7pqLfqnPAwEkn2ViStEG9tvLIt7sLmp04JtmFDpIa+ovXF9tFRGcE2OPWQ 3k2ErzN1nx6bEZFI2NBQ6Q2y4EeRFBiE1ShEKBeoHQKnucSokbwTM36KmVqTH1+jjY3A=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Reply-To: References:Subject:List-Unsubscribe:List-Id:Cc:To:Date:From:Sender:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help:List-Subscribe:List-Post: List-Owner:List-Archive; bh=YKnhHSab2PC7xC90KTncirDgNqJ6aGUl56BrOB6QMoM=; b=Z oqbwe3w9arBMKFzLeaOxoYBjQzlASYrehPjthk9d9NtV7P0cr6ISWQbeI/LBgeLq/sMXcwoQppij/ bbXaPVlJU0jhPi5hDlu4987v4n4raD9drO81isAVIK8PjNLbyeagSUppf4T80PbK2NqJwcVYAyt9j 2c0BYjxt0WoZc1ao=; Received: from mail-wm1-f42.google.com ([209.85.128.42]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1tdZ2h-0002fh-Gq for openvpn-devel@lists.sourceforge.net; Thu, 30 Jan 2025 18:13:32 +0000 Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-43626213fffso15017485e9.1 for ; Thu, 30 Jan 2025 10:13:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1738260800; x=1738865600; darn=lists.sourceforge.net; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from:from:to:cc :subject:date:message-id:reply-to; bh=YKnhHSab2PC7xC90KTncirDgNqJ6aGUl56BrOB6QMoM=; b=dgZ35bDl+5Z2n/8Bxe1E8Q/LEFe1bxNag0pwofCNGckdGz67VmpAky1EojrxcXWz+2 Slv1HGqBBqML9rG79RAX1h30nKoOh61lIEdmXTFCwDrXJ9pjCPvrzBZpP0VSadpTYz4X P97X1VG5vz0yjYp0nPgcdJjqBOcRGlSpsWgrMm0PRTP7/9KpSmUiXXkoZes1PUjCmv/U oEVMVu7M4g5hEbfuAgFZDEQCVrTS2rYqlMSx1pKKJ9VJAHvHuzi5pWkBBojRyO6YaYT6 4ZB/4PNUpn/9DxVqe3SKjzxBjXJ+8UoiXdbt58zDulOkREAxJyN53VRQnl5541ses/CA 3ajA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738260800; x=1738865600; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YKnhHSab2PC7xC90KTncirDgNqJ6aGUl56BrOB6QMoM=; b=cfCfJ3fuoii88PiGCRthaXKIqfOAxbi76Ay3oazwZ5Ff3xTyLl+t70I6s6OMIpltCp Ukfq3p5VCy+O5q2qii/zjbngYra0iGbyPRADnITmIrdrjPfkwIdzVO9+0yD/T77Y36NK iPNqWWV5APo1IpDrjtsm3hu599JjXjuLvwSv8CCZz3/0pMvWOdvBwAFnv6Ox7jrjwvhX sAxQY9lrRqUwTegK5n4fcHUBwSjuPuR9GXbGpkPXMha5ngVN1UpAHPyw9nhnzLqcV3Yz hYR7hkVlssi39fDygPq2wtuRgL5aqhiYcasUzTFgUR/sp5HBakzBatVpBYTzQZUlgnU1 tmSw== X-Gm-Message-State: AOJu0YwY1QEFamj538Ix4BiONOTD76Ib+4SK4e9P481Cmo5bK5FtNyIr jV1+Qco2GaGfowWdvvvqeI8/6oep6iaEZeCW44uIArey9satVpi4aXWxzlPbKIWxKy0JudKK1v+ g X-Gm-Gg: ASbGncuIXfgHV2LQtuha/zlT9ewnTZMh6MjZ9KCuD64+g8mlAc1z+mRMeojW+IKiX/1 lN/Mdw/V6CHADXvtTny+3K9xS5vuzcBaEeuIpEXq3SmX4zjiPtsUAaugx4+A5El1JTxXrHOqfHV TsFep92jQdo5hU3cPlz2c/Vmcpg6nR+AFez556kFWa8SEnSLt40hfbkgZBgynStStsRVeRaGCoK afhh97WyMXwks+KVLpcFTKDyyBrHyo/2vzxM7vvyDcBLevgFp06GpyXOUBUu+yu66DUzKdTYmFG 3GLiJz2ARXW9WSc1ClO5xmjvt9Zy0IQEPs/fZda9MNl82nAW++EhStb1ue3W3npR5peqJRgrciH nQG7il30= X-Received: by 2002:a05:600c:3b83:b0:436:e3ea:64dd with SMTP id 5b1f17b1804b1-438e6eff1fbmr5203235e9.11.1738260799870; Thu, 30 Jan 2025 10:13:19 -0800 (PST) Received: from gerrit.openvpn.in (ec2-18-159-0-78.eu-central-1.compute.amazonaws.com. [18.159.0.78]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438e245f5a5sm31902075e9.40.2025.01.30.10.13.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2025 10:13:19 -0800 (PST) From: "cron2 (Code Review)" X-Google-Original-From: "cron2 (Code Review)" X-Gerrit-PatchSet: 1 Date: Thu, 30 Jan 2025 18:13:19 +0000 To: plaisthos , flichtenheld Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange X-Gerrit-Change-Id: I6f17140109106b37e6b0e690df1d87720ccf6f91 X-Gerrit-Change-Number: 884 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: c776fb7df9210ea49c32d304e8982f87f484977b References: Message-ID: MIME-Version: 1.0 User-Agent: Gerrit/3.8.2 X-Spam-Score: -0.2 (/) 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: Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.128.42 listed in list.dnswl.org] 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. [209.85.128.42 listed in sa-trusted.bondedsender.org] 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. [209.85.128.42 listed in bl.score.senderscore.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.128.42 listed in wl.mailspike.net] 0.0 WEIRD_PORT URI: Uses non-standard port number for HTTP 0.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 T_KAM_HTML_FONT_INVALID Test for Invalidly Named or Formatted Colors in HTML X-Headers-End: 1tdZ2h-0002fh-Gq Subject: [Openvpn-devel] [M] Change in openvpn[master]: 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: , Reply-To: gert@greenie.muc.de, arne-openvpn@rfc2549.org, openvpn-devel@lists.sourceforge.net, frank@lichtenheld.com Cc: openvpn-devel Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1822698577006628854?= X-GMAIL-MSGID: =?utf-8?q?1822698577006628854?= X-getmail-filter-classifier: gerrit message type newchange Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/884?usp=email to review the following change. Change subject: get_default_gateway(): implement platform support for Linux/IPROUTE2 ...................................................................... get_default_gateway(): implement platform support for Linux/IPROUTE2 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 --- M src/openvpn/networking_iproute2.c M src/openvpn/networking_sitnl.c 2 files changed, 8 insertions(+), 55 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/84/884/1 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) {