From patchwork Tue Nov 26 15:28:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "kallisti5 (Code Review)" X-Patchwork-Id: 3965 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:8712:b0:5db:5963:ef83 with SMTP id bv18csp140832mab; Tue, 26 Nov 2024 07:29:18 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUDdmmxrIeEFk293eEGrRxnfv/1yXdJ+rdylwbdCh9Q7U9BbApo76/eA284NXAH3cBE3MeRqGW5ZC0=@openvpn.net X-Google-Smtp-Source: AGHT+IFe1hjdEf4MJrcT0fNfMwhTSXp3EnBVpgl+AMBTjmgU4dkohDTRhExzIU5EW73H/kJtgljw X-Received: by 2002:a05:6602:1654:b0:843:e507:3e32 with SMTP id ca18e2360f4ac-843e507411cmr184502039f.13.1732634958278; Tue, 26 Nov 2024 07:29:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1732634958; cv=none; d=google.com; s=arc-20240605; b=GzamshOZQ2zp916UVadHu4HJSP2BNYaZG6BGY0xzMuJqBm2oPnImwfRr3jObN45qV1 NtmyuLjBZE0Hpx0MGu3AP65rv6/n5t7klgdrqzNyjrpnFM8hUNWGOH+Qm7xqsabHypVQ 5qpWSMO4jTWvE7K5sK1hvI3U6XMQpX+1FyGAOllsfyAmPCWJy7rTXc9KnM2sJP3Rq8iT SNRInAUWaN17tn2zCyBbTcFAR3dKd/7ZyD1IFpcwRqWKNQPk3Rqa6rIaG+paSyZPlPoP 6RHEhLo3mAjDkJE6euUi/bPQSmxoui/p8J7WxsscSj1dkVYIxOvaQYs1QCKAkpgjD7SZ lvtA== 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=obco+TuWh98sMNniaNV6bEOae8Kq3lvK5cxRjdxQfyU=; fh=U7wEyxtwz2o5+UdevFSA47vNeG9knhWH0KV//QhD5a0=; b=EAlNx2ZTUdg57nbecg4vZ0KYAANnMRmS2mBdVLp6C5ER7Y5uhBP2aPDCM9YS2fD40q VqzigO5XmrGZiVToGpalOAXyYr8Ea/sxTmzy26hsKHoDuWDkNx6cUB9TqJJ0eZecxd1r PxrrWLuD5VEj7cCId5b4r1KMPnRC4FSYhY6OOafL9cmclcjYMl6PigAEFzm9syxcQN96 By+xL/qQmUD9fun1BeaMd/VK82BiA9AN8r6XTIhpHUPHNEPUdUj4qsj8NlwMcdQNIcr3 qQP7bEjWN8/591nA3kDuRe4Nz0zMlrm8/3uJkSxoXmqV8yrymA7YBoDls/V//85Xuevr FhLA==; 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=Jj240l3M; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=B1gqo6XJ; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=VQfs8viW; 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 8926c6da1cb9f-4e1ffafb954si3049108173.92.2024.11.26.07.29.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Nov 2024 07:29:18 -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=Jj240l3M; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=B1gqo6XJ; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=VQfs8viW; 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 1tFxUz-0000Dd-Aj; Tue, 26 Nov 2024 15:29:09 +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 1tFxUx-0000DX-V6 for openvpn-devel@lists.sourceforge.net; Tue, 26 Nov 2024 15:29:07 +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=EpcsHp8c8znh3noJEg6qWx3OIAQU8+EN5BjTB4b8Pos=; b=Jj240l3MN55WMkZBsT6kxEA1C4 HZuNEaN8QPMxBJ1f35C9QUC8hnoH+syIG+lv457mRUVfXJm4ycme6uoAq/JcGOR/Ja58uA/qTxyXo 4tkYPwHhkFM8w6H74EcT5K3S6L9iz5bvFrJk4HHBX6VVcrQYMyNKpAqtG9+qD7ECS5JA=; 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=EpcsHp8c8znh3noJEg6qWx3OIAQU8+EN5BjTB4b8Pos=; b=B 1gqo6XJbt9o+gQ4aXXkepbMLne19YbK2kp1d0eDNhbVF3Gniw8fEthIWbIADEIv9G1f8nRYKT31mb wxYl4MdYQGWW9TjkT33eE8q7WzX/os5+IMtk59O09MqQeiJO+HGngVBTtTdHWucJXYfacQUH45S6i Pe//Fm83fMvpWjmo=; Received: from mail-wm1-f49.google.com ([209.85.128.49]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1tFxUv-0003vq-RT for openvpn-devel@lists.sourceforge.net; Tue, 26 Nov 2024 15:29:07 +0000 Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-432d86a3085so52947085e9.2 for ; Tue, 26 Nov 2024 07:29:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1732634934; x=1733239734; 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=EpcsHp8c8znh3noJEg6qWx3OIAQU8+EN5BjTB4b8Pos=; b=VQfs8viWEdSgjVnBcB0BnxpFKtrWjcChQRGJjigBUoNyCNdfQsFRHUx9YHMTONJwb8 Fn6yRkJltYSt+HoP3vaZWsj/dKnX+KgINrF08scH7n+JSPzGuH9TvYKPfB+ORYWVsmuN UeRkxfLdbItHj3xyJKv5l1jhIQxw2TIyua4ceK4040XDlaeT93rfqi4/WOT4+VBa7knD 7bd3SMmVPmYPVOsykb1QNKA5G1sv/CbHMyAq7rKxgE+w2ygy1KGNNmov5R89aDUyHkls ebxCTQfBZ3LwgXH+xtLJLJ9P6h7ZIHgyIkQoy/KibPIJsIB4IP/uxT6vgprW/ZK8mylo /O2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732634934; x=1733239734; 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=EpcsHp8c8znh3noJEg6qWx3OIAQU8+EN5BjTB4b8Pos=; b=oJze7+4a8MKSuqk+wYoh5Ckp0ji275Hpq91FdnysM0oXBbzP0Yvwusz8nqO1qyJziR uJZezzj/IcyJPg7yoK5UJ19GLq48YG9IpJofyCDZVJyO1jqaoWlHyR50ibPD026gcmss nb3fGmMp+RbyvfehXdWFWdUHg2nAntgyn+8PHlSJm+AXJRurA7acDcsganwkC9oQk75Z jQiRiF2/00dZ8R0avCKuU+vU8mQxNvlyeGpJU0bzIgzzgpxKFsTIZKn/wvxNMDhSvohm r7/qGNc/Wpim/JiZoP0uU0lWjwpINIgjkB1Sr3NAEiffG3AK61Ej6HihgI/+xZDUh4l+ 0hXw== X-Gm-Message-State: AOJu0YymLT+UKhr8doq1DrO4tC2hTC1xpwPjxcA/bN+n8xfKQmwdhTEz cj9ezDfjEKH9esu4mkSn33KCWMX/llxlSJN8uuv+cCTFxskvu/Cao8WuJ7GaxAs= X-Gm-Gg: ASbGncsC24q/8BkyHdJBTTqld1J1/Kna0mi76mFqXkmw9QkKfRtYTXx/QcYAn7PpuHW xVqusa8dig7gbUx5fz3AVmgLBKOetkKMCimBZzVnhNucpMXgp4klIM6Htj6YxoRNHg6//EvM4FW UEu5t4uOmo6Cf3oDFTvDEn+L/k6qoEtH0oyOL8OTlGnzOunHCCrE8t0YNXbe1ERw/B0x0iLa3aO iqhS5nfaaUObczj1SEgCMECKw6DLgMo0hLn/vVeobogXVk5Af3ubnUIraqj2jS6LqKhA9FYH2Mz JqNqyqbXwxvcDwEtWJYR7vvL2xCfS9FOFDcl8HODKw== X-Received: by 2002:a05:600c:314b:b0:434:a968:89a3 with SMTP id 5b1f17b1804b1-434a9688a59mr3359715e9.9.1732634934187; Tue, 26 Nov 2024 07:28:54 -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-4349de9d6a5sm91836065e9.20.2024.11.26.07.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2024 07:28:53 -0800 (PST) From: "kallisti5 (Code Review)" X-Google-Original-From: "kallisti5 (Code Review)" X-Gerrit-PatchSet: 1 Date: Tue, 26 Nov 2024 15:28:53 +0000 To: plaisthos , flichtenheld Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange X-Gerrit-Change-Id: I1a22724f28c5cd47f6df178b49f44087d7c2b6fd X-Gerrit-Change-Number: 688 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: 0419e44b1dc8655cb5463d459a27a2460c532445 References: Message-ID: MIME-Version: 1.0 User-Agent: Gerrit/3.8.2 X-Spam-Score: -1.1 (-) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.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: (-1.1 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.49 listed in list.dnswl.org] 0.0 RCVD_IN_VALIDITY_SAFE_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.49 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. [209.85.128.49 listed in bl.score.senderscore.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.9 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.128.49 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_VALID Message has at least one valid DKIM or DK signature 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.0 T_KAM_HTML_FONT_INVALID Test for Invalidly Named or Formatted Colors in HTML X-Headers-End: 1tFxUv-0003vq-RT Subject: [Openvpn-devel] [M] Change in openvpn[master]: Haiku: Add calls to manage routing table 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: alex@terarocket.io, 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?1816799433925180135?= X-GMAIL-MSGID: =?utf-8?q?1816799433925180135?= 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/+/688?usp=email to review the following change. Change subject: Haiku: Add calls to manage routing table ...................................................................... Haiku: Add calls to manage routing table Change-Id: I1a22724f28c5cd47f6df178b49f44087d7c2b6fd --- M INSTALL M src/openvpn/route.c M src/openvpn/syshead.h 3 files changed, 125 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/88/688/1 diff --git a/INSTALL b/INSTALL index 6007338..e7199f8 100644 --- a/INSTALL +++ b/INSTALL @@ -263,6 +263,13 @@ http://www.whiteboard.ne.jp/~admin2/tuntap/ +* Haiku: + + Haiku can't yet dynamically create TUN/TAP devices, so you need to manually + create one before running openvpn: + + # ifconfig tun/0 up + * Windows OpenVPN on Windows needs a TUN/TAP kernel driver to work. OpenVPN installers diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 2e584c7..4813def 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -1853,7 +1853,23 @@ status = ret ? RTA_SUCCESS : RTA_ERROR; } -#else /* if defined(TARGET_LINUX) */ +#elif defined(TARGET_HAIKU) + + { + /* ex: route add /dev/net/ipro1000/0 0.0.0.0 gw 192.168.1.1 netmask 128.0.0.0 */ + argv_printf(&argv, "%s add %s inet %s gw %s netmask %s", + ROUTE_PATH, + rgi->iface, + network, + gateway, + netmask); + argv_msg(D_ROUTE, &argv); + bool ret = openvpn_execve_check(&argv, es, 0, + "ERROR: Haiku inet route add command failed"); + status = ret ? RTA_SUCCESS : RTA_ERROR; + } + +#else /* if defined(TARGET_LINUX) */ msg(M_FATAL, "Sorry, but I don't know how to do 'route' commands on this operating system. Try putting your routes in a --route-up script"); #endif /* if defined(TARGET_LINUX) */ @@ -2329,6 +2345,20 @@ openvpn_execve_check(&argv, es, 0, "ERROR: AIX route delete command failed"); } +#elif defined(TARGET_HAIKU) + + { + /* ex: route del /dev/net/ipro1000/0 inet 192.168.0.0 gw 192.168.1.1 netmask 255.255.0.0 */ + argv_printf(&argv, "%s del %s inet %s gw %s netmask %s", + ROUTE_PATH, + rgi->iface, + network, + gateway, + netmask); + argv_msg(D_ROUTE, &argv); + openvpn_execve_check(&argv, es, 0, "ERROR: Haiku inet route delete command failed"); + } + #else /* if defined(TARGET_LINUX) */ msg(M_FATAL, "Sorry, but I don't know how to do 'route' commands on this operating system. Try putting your routes in a --route-up script"); #endif /* if defined(TARGET_LINUX) */ @@ -2504,10 +2534,23 @@ network, r6->netbits, gateway); argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: AIX route add command failed"); + #elif defined(TARGET_ANDROID) msg(D_ROUTE_DEBUG, "Deleting routes on Android is not possible/not " "needed. The VpnService API allows routes to be set " "on connect only and will clean up automatically."); +#elif defined(TARGET_HAIKU) + { + /* ex: route del /dev/net/ipro1000/0 inet6 :: gw beef::cafe prefixlen 64 */ + argv_printf(&argv, "%s del %s inet6 %s gw %s prefixlen %d", + ROUTE_PATH, + r6->iface, + network, + gateway, + r6->netbits); + argv_msg(D_ROUTE, &argv); + openvpn_execve_check(&argv, es, 0, "ERROR: Haiku inet6 route delete command failed"); + } #else /* if defined(TARGET_LINUX) */ msg(M_FATAL, "Sorry, but I don't know how to do 'route ipv6' commands on this operating system. Try putting your routes in a --route-down script"); #endif /* if defined(TARGET_LINUX) */ @@ -3886,6 +3929,74 @@ #undef max +#elif defined(TARGET_HAIKU) + +void +get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) +{ + CLEAR(*rgi); + + int sockfd = -1; + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd < 0) { + msg(M_INFO, "%s: Error opening socket for AF_INET", __func__); + return; + } + + struct ifconf config; + config.ifc_len = sizeof(config.ifc_value); + if (ioctl(sockfd, SIOCGRTSIZE, &config, sizeof(struct ifconf)) < 0) { + msg(M_INFO, "%s: Error getting routing table size", __func__); + return; + } + + uint32 size = (uint32)config.ifc_value; + if (size == 0) + return; + + void *buffer = malloc(size); + if (buffer == NULL) { + fprintf(stderr, "%s: Out of memory.\n", __func__); + return; + } + + config.ifc_len = size; + config.ifc_buf = buffer; + if (ioctl(sockfd, SIOCGRTTABLE, &config, sizeof(struct ifconf)) < 0) + return; + + struct ifreq *interface = (struct ifreq*)buffer; + struct ifreq *end = (struct ifreq*)((uint8*)buffer + size); + + while (interface < end) { + struct route_entry route = interface->ifr_route; + if ((route.flags & RTF_GATEWAY) != 0 && (route.flags & RTF_DEFAULT) != 0) { + rgi->gateway.addr = ntohl(((struct sockaddr_in *)route.gateway)->sin_addr.s_addr); + rgi->flags = RGI_ADDR_DEFINED | RGI_IFACE_DEFINED; + strcpy(rgi->iface, interface->ifr_name); + } + + int32 addressSize = 0; + if (route.destination != NULL) + addressSize += route.destination->sa_len; + if (route.mask != NULL) + addressSize += route.mask->sa_len; + if (route.gateway != NULL) + addressSize += route.gateway->sa_len; + + interface = (struct ifreq*)((addr_t)interface + IF_NAMESIZE + + sizeof(struct route_entry) + addressSize); + } +} + +void +get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, + const struct in6_addr *dest, openvpn_net_ctx_t *ctx) +{ + /* TODO: Same for ipv6 with AF_INET6 */ + CLEAR(*rgi6); +} + #else /* if defined(_WIN32) */ /* diff --git a/src/openvpn/syshead.h b/src/openvpn/syshead.h index 33a90c1..844e47a 100644 --- a/src/openvpn/syshead.h +++ b/src/openvpn/syshead.h @@ -166,6 +166,12 @@ #include #endif +#if defined(TARGET_HAIKU) +#include /* uint32, etc */ +#include /* ifconf etc */ +#include /* SIOCGRTTABLE, etc */ +#endif /* TARGET_HAIKU */ + #ifdef HAVE_ARPA_INET_H #include #endif