From patchwork Fri Nov 25 15:53:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristof Provost X-Patchwork-Id: 2854 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id KHAvOJHmgGM8XwAAIUCqbw (envelope-from ) for ; Fri, 25 Nov 2022 11:00:17 -0500 Received: from proxy13.mail.ord1d.rsapps.net ([172.30.191.6]) by director7.mail.ord1d.rsapps.net with LMTP id EItAOJHmgGNRFgAAovjBpQ (envelope-from ) for ; Fri, 25 Nov 2022 11:00:17 -0500 Received: from smtp27.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy13.mail.ord1d.rsapps.net with LMTPS id 4MQOOJHmgGNmPQAAgjf6aA (envelope-from ) for ; Fri, 25 Nov 2022 11:00:17 -0500 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp27.gate.ord1d.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=netgate.com; dmarc=pass (p=none; dis=none) header.from=lists.sourceforge.net X-Suspicious-Flag: YES X-Classification-ID: 40950e68-6cda-11ed-b45d-5254003773d7-1-1 Received: from [216.105.38.7] ([216.105.38.7:53188] helo=lists.sourceforge.net) by smtp27.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 3E/A3-05938-096E0836; Fri, 25 Nov 2022 11:00:16 -0500 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 1oyb6t-0000nl-OO; Fri, 25 Nov 2022 15:59:27 +0000 Received: from [172.30.20.202] (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 1oyb6s-0000na-To for openvpn-devel@lists.sourceforge.net; Fri, 25 Nov 2022 15:59:27 +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=gyVWD5gL6uX2/IYi81qaAqYu51++hvrQYoYo25/6Z9s=; b=EporHgsj/kLwDFRG5SqT0hmprq HMeHixGLO10YvvtgK0okQT4t3HXqIx77mkmxrBFNl2EoWFJ13e8B3pWvA9WMoaAaiUV28ST7h5+za vcpkwlj+AGrn/AnqM0Rd7XPy+FbrtHebsC3K8Wcs3IWDEDWqsY2AK+PI6SrqbC+mtwv4=; 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=gyVWD5gL6uX2/IYi81qaAqYu51++hvrQYoYo25/6Z9s=; b=KnezgQBK0EyLX+N20X0SMhasqt 4JXF8GNzaWpiJz106uivEBq3U6tyNPJPh1T0xoGELdByL2fcQouwcKCSx4d6OPj6sUbke5M4yZKn8 ClcTcqlByyydpujoQ6fKP7cQ/l/x/03iY5tuq+4lL+FnW3PLh95r754w9Y2xrlSlPZ6A=; Received: from mail-ej1-f53.google.com ([209.85.218.53]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1oyb6p-00AoPK-40 for openvpn-devel@lists.sourceforge.net; Fri, 25 Nov 2022 15:59:26 +0000 Received: by mail-ej1-f53.google.com with SMTP id ho10so11281979ejc.1 for ; Fri, 25 Nov 2022 07:59:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netgate.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=gyVWD5gL6uX2/IYi81qaAqYu51++hvrQYoYo25/6Z9s=; b=YtoBUsSv9L5AooYMGAdGjm45hwsmdj+6Q86rEcwlW6yTFuDVUO7gieJnPK0J9kQ/qH rz+Qn1CCVylqKSZrkDes0I00skn3lKSDr0/zBstacEGRJ6Cx9wD+/qK8VMu7cYIG5zEA fIFsT+WfTusQLMpa2FWo/PhHwe9vzD14hVlKI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gyVWD5gL6uX2/IYi81qaAqYu51++hvrQYoYo25/6Z9s=; b=0iylj+aC8EvSNGtV5eTagSI7HqrRT2SuFlwK/732UbphNJvlyVTP6v8w7KpftPg7oD IbsL4mtp5oqeo7LfhRsLyJhv+ijd/5liJT7ExpQJEs0h5IK2I/KvrgIWtePumihj+y/P ujTO3aq3PlvRT1cBoF20Vm4VsMbFGHE169Av9fHiFuWQQq2thW05Ox2MkCAvX2GztywA 6wEwRSRk5T9aE9n2gy/LecIAtATnrdQ3xmEZXQSytOjPRDhqJB9N3J6QjK8/NFHdaVMQ aBVbskjzwt+bbeWhddPSQAnYcrinUvcwEPur4NI4AioNfPa5MqRFxovWheI8Jbh9BAci gYEw== X-Gm-Message-State: ANoB5pnB8MTdiWAorhaApTv41sBBJDujtC4+4YAGwNrCyaPbcNcf3yIl tdkUv4joFgC9fv1nEO5KiZVhxgTGa1KHDyA3 X-Google-Smtp-Source: AA0mqf5YBeOG0r/ZrEFwjPHwWrnacrBzbPXOh8fr1Dg4pqE8mNiMZ81yEnt5O3p4vIjM3n3S2Ub6Yg== X-Received: by 2002:a05:6402:5406:b0:467:4b3d:f2ed with SMTP id ev6-20020a056402540600b004674b3df2edmr18714163edb.101.1669391624601; Fri, 25 Nov 2022 07:53:44 -0800 (PST) Received: from nut.jupiter.sigsegv.be (ptr-8rfalzsse26o3oo9imw.18120a2.ip6.access.telenet.be. [2a02:1811:2402:bf00:f602:70ff:feae:6e98]) by smtp.googlemail.com with ESMTPSA id ce24-20020a170906b25800b007826c0a05ecsm1689653ejb.209.2022.11.25.07.53.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 07:53:44 -0800 (PST) To: openvpn-devel Date: Fri, 25 Nov 2022 16:53:41 +0100 Message-Id: <20221125155341.19456-2-kprovost@netgate.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221125155341.19456-1-kprovost@netgate.com> References: <20221125155341.19456-1-kprovost@netgate.com> MIME-Version: 1.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: Kristof Provost FreeBSD allows packets to be sent through the socket even when the if_dco driver is active, so prefer that path. Also remove the FreeBSD dco_do_write() implementation, as this function will never be called any more on FreeBSD. Assert this. Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 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_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.218.53 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.218.53 listed in wl.mailspike.net] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-Headers-End: 1oyb6p-00AoPK-40 Subject: [Openvpn-devel] [PATCH] dco: pass control packets through the socket on FreeBSD 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: , X-Patchwork-Original-From: Kristof Provost via Openvpn-devel From: Kristof Provost Reply-To: Kristof Provost Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Kristof Provost FreeBSD allows packets to be sent through the socket even when the if_dco driver is active, so prefer that path. Also remove the FreeBSD dco_do_write() implementation, as this function will never be called any more on FreeBSD. Assert this. Signed-off-by: Kristof Provost --- src/openvpn/dco_freebsd.c | 33 ++++----------------------------- src/openvpn/forward.c | 7 +++++-- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index 8e5ee436..9102222f 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -536,35 +536,10 @@ dco_do_read(dco_context_t *dco) int dco_do_write(dco_context_t *dco, int peer_id, struct buffer *buf) { - struct ifdrv drv; - nvlist_t *nvl; - int ret; - - nvl = nvlist_create(0); - - nvlist_add_binary(nvl, "packet", BSTR(buf), BLEN(buf)); - nvlist_add_number(nvl, "peerid", peer_id); - - CLEAR(drv); - snprintf(drv.ifd_name, IFNAMSIZ, "%s", dco->ifname); - drv.ifd_cmd = OVPN_SEND_PKT; - drv.ifd_data = nvlist_pack(nvl, &drv.ifd_len); - - ret = ioctl(dco->fd, SIOCSDRVSPEC, &drv); - if (ret) - { - msg(M_WARN | M_ERRNO, "Failed to send control packet"); - ret = -errno; - } - else - { - ret = BLEN(buf); - } - - free(drv.ifd_data); - nvlist_destroy(nvl); - - return ret; + /* Control packets are passed through the socket, so this should never get + * called. See should_use_dco_socket(). */ + assert(false); + return -EINVAL; } bool diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 622be841..1dcaabd8 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1635,20 +1635,23 @@ process_ip_header(struct context *c, unsigned int flags, struct buffer *buf) } } -/* Linux-like DCO implementations pass the socket to the kernel and +/* Linux DCO implementations pass the socket to the kernel and * disallow usage of it from userland, so (control) packets sent and * received by OpenVPN need to go through the DCO interface. * * Windows DCO needs control packets to be sent via the normal * standard Overlapped I/O. * + * FreeBSD DCO allows control packets to pass through the socket in both + * directions. + * * Hide that complexity (...especially if more platforms show up * in the future...) in a small inline function. */ static inline bool should_use_dco_socket(struct link_socket_actual *actual) { -#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) +#if defined(TARGET_LINUX) return actual->dco_installed; #else return false;