From patchwork Thu Dec 5 17:24:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 3974 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:1d8b:b0:5dc:2311:f747 with SMTP id hp11csp315181mab; Thu, 5 Dec 2024 09:25:20 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWV7LjyoG0p4stGR7NBWud5lH/UU1+9HuZ35gCHWek+2v2iUYiXSaE/px/7GqL9qZ5ev09URvMrdaA=@openvpn.net X-Google-Smtp-Source: AGHT+IE9x9smM0pod2ch+EFPDRNiWtB8BCT63Owj0RG45TRaCzDUTb0f2OfpjYkJV6bGj4KDF22h X-Received: by 2002:a05:6808:bcb:b0:3ea:4c1c:50fc with SMTP id 5614622812f47-3eae50cf17amr12040800b6e.37.1733419520490; Thu, 05 Dec 2024 09:25:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733419520; cv=none; d=google.com; s=arc-20240605; b=XTRRIko1v7T1YoJoa2cXyZJe2GKYk+dThJ5SY6Fo3zR2AKqMN1DiojERkVupzDel5u ufAz9ky5BebIO6kTbdA95Jd8zJ1pVAS77pqfLoBu2IwLfff04sKHMX8Zhkb0kwwvFHL0 uqsZ1why3IB+1CtDn2nnyeSqD1PN/mMXG1ykLx0ErCBqyMISytTClsnYycd+ftWrpjmf fqINbaBQ5Ry+LZmNmbC7mKQfnPc1vRjyRe5hjn1EuYJzEa0Io6//6SWjVclbQX922nfv onP8mBqU31ihvyaZk/LDoch1uLt2lKOuf7H9yuZsPPEdb6YujJJmWRzOYKhahO7mGhgH yTRg== 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=tbLazNDEV4+yq0jmyT+CbRUuV2uZ+GyqiNhzZWgkXts=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=T4uGJERPdFl1PZnoMj7huzoyq+6f+b2zOjGsKFj6lxy9NaBeIzCsiPazKdzHRf0ThO QIvpl9Vi10hllOgwPUn3OvHt2YXWxOXw04Adc/BnT9SD5eYdFLDQpGy5+z/4qzrY9n/l DRd3KWcEizGKk05EHj0fNLUhYxBxX208GZ+b0xDj4HYXuH70KfXcg+1AMYbwKpEljSBg iqG8ZLZ6Ebxd6MNiYLZL/wIMvr41knoyRr/ko4dyvjzqPQPKJPbiMz5MNQmv4tO3fI/K 5j8KQUFdIXFNM1byqr0b8MNv/eCeT1EcXC6aTlCEuBavnxpi4G2IXAgFx3n5mA6oH5h4 d5KA==; 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=REnBN08Y; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=I1mKLPAf; 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 5614622812f47-3eb0787a9dbsi881037b6e.228.2024.12.05.09.25.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Dec 2024 09:25:20 -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=REnBN08Y; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=I1mKLPAf; 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 1tJFbG-00066C-Sz; Thu, 05 Dec 2024 17:25:15 +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 1tJFbF-000665-SL for openvpn-devel@lists.sourceforge.net; Thu, 05 Dec 2024 17:25:14 +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=cr1FnX6MsovfGKJ5X+eSVJOgBod9LFJTb6Zj/mmtAAY=; b=REnBN08Y+BHvMBzWOlXBLQvEVR YRkYm8T7b9aBF0QU2049rVRYvsjYkUkI8CsoN0K2zwpoKUlxNCj6VAhiID6m6rSr+th3wyO+2Nl8j yJHn087REGrMga1Kc1idtyIMgkLOdly9+UjVzUKScTAyMcnGsT9b6p80W8iGsY/8lD4c=; 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=cr1FnX6MsovfGKJ5X+eSVJOgBod9LFJTb6Zj/mmtAAY=; b=I1mKLPAf9NsofjxDAo6Ts6BRbq N7KHvcmK8cMRekjJzyDkyiEcYJIHOpgRzKU3zx8LVuHweeY8QeR+gAabzXqtMl8+JgG0oxLMqphlk /vbb+QqlZSVObrgP/8DCWWw/32reyBLi7a17dGfAkZGwWi+bbngyTgRXwP5gRbP4TUaM=; 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 1tJFbE-0006dQ-CV for openvpn-devel@lists.sourceforge.net; Thu, 05 Dec 2024 17:25:14 +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 4B5HP0x6004793 for ; Thu, 5 Dec 2024 18:25:00 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.17.1.9/8.17.1.9/Submit) id 4B5HP0YP004792 for openvpn-devel@lists.sourceforge.net; Thu, 5 Dec 2024 18:25:00 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Thu, 5 Dec 2024 18:24:59 +0100 Message-ID: <20241205172459.4783-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: From: Alexander von Gluck Signed-off-by: Alexander von Gluck Acked-by: Gert Doering Change-Id: I1a22724f28c5cd47f6df178b49f44087d7c2b6fd --- Content analysis details: (0.0 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 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 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. [193.149.48.174 listed in sa-trusted.bondedsender.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-Headers-End: 1tJFbE-0006dQ-CV Subject: [Openvpn-devel] [PATCH v11] 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: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1817622106656652784?= X-GMAIL-MSGID: =?utf-8?q?1817622106656652784?= From: Alexander von Gluck Signed-off-by: Alexander von Gluck Acked-by: Gert Doering Change-Id: I1a22724f28c5cd47f6df178b49f44087d7c2b6fd --- 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/+/688 This mail reflects revision 11 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 2e584c7..42108f3 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -1853,7 +1853,21 @@ 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) */ @@ -2126,6 +2140,20 @@ "ERROR: AIX route add command failed"); status = ret ? RTA_SUCCESS : RTA_ERROR; +#elif defined(TARGET_HAIKU) + + /* ex: route add /dev/net/ipro1000/0 inet6 :: gw beef::cafe prefixlen 64 */ + argv_printf(&argv, "%s add %s inet6 %s gw %s prefixlen %d", + ROUTE_PATH, + r6->iface, + network, + gateway, + r6->netbits); + argv_msg(D_ROUTE, &argv); + bool ret = openvpn_execve_check(&argv, es, 0, + "ERROR: Haiku inet6 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 ipv6' commands on this operating system. Try putting your routes in a --route-up script"); #endif /* if defined(TARGET_LINUX) */ @@ -2329,6 +2357,18 @@ 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 +2544,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 +3939,86 @@ #undef max +#elif defined(TARGET_HAIKU) + +void +get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) +{ + CLEAR(*rgi); + + int sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd < 0) + { + msg(M_ERRNO, "%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_ERRNO, "%s: Error getting routing table size", __func__); + return; + } + + uint32 size = (uint32)config.ifc_value; + if (size == 0) + { + return; + } + + void *buffer = malloc(size); + check_malloc_return(buffer); + + config.ifc_len = size; + config.ifc_buf = buffer; + if (ioctl(sockfd, SIOCGRTTABLE, &config, sizeof(struct ifconf)) < 0) + { + free(buffer); + 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; + strncpy(rgi->iface, interface->ifr_name, sizeof(rgi->iface)); + } + + int32 address_size = 0; + if (route.destination != NULL) + { + address_size += route.destination->sa_len; + } + if (route.mask != NULL) + { + address_size += route.mask->sa_len; + } + if (route.gateway != NULL) + { + address_size += route.gateway->sa_len; + } + + interface = (struct ifreq*)((addr_t)interface + IF_NAMESIZE + + sizeof(struct route_entry) + address_size); + } + free(buffer); +} + +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