From patchwork Thu Nov 26 11:58:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5794 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:91c9:10b0:11b:d6c:f273 with SMTP id tl9-n1csp7062251lad; Thu, 26 Nov 2026 03:59:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGSWS4TegVN6LOY8Tqk2xnS+3cWt8MhbKT3FhypcDPmaaE7Z4RlciyMg4ETBKQ2TObs9hLhHJLOYlo=@openvpn.net X-Received: by 2002:a05:7300:cd86:b0:36c:a3ae:936e with SMTP id 5a478bee46e88-384b398741bmr31314988eec.5.1795694340164; Thu, 26 Nov 2026 03:59:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795694340; cv=none; d=google.com; s=arc-20260327; b=Ob3557Z440gb6XBQLKkFOpUyQG4uNvC1Kn7nhjj909NKtWUxi7rhzQxcfH/tuzGNZq 0eWwhKi+iKKQSRjLFq+aXUXdvb1DN75d+P6YMTSIzPtWTtaEIGGaeD+rDYKbK24xaTZb +K/CHsJvYbrUBD9+1HssGP04uxzzmrGzXPx9kjHpF6ULO6+0JAM78d8nkcrk0agU7zpz IRczVFkPesiH2jejzfGbt6lnN4OtqpYjUPYDufTVAUWVXpQvvJUCCGsHZpVGnup+fp8f 0opge61RgRxG8XM7Pif9CXfng4hf8QQk+gDpO4pdEp9ZJ8G56jYalXUckBMTU4ZUH9r+ OSxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; 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:dkim-signature; bh=I4B5Nw4Lfn/jb1Ko+BP+F5e3S/Rf+8IOq34mx0PhPak=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=a6BfivwZHxm6M/NshlQRwI47Bc8Iwag4LUDfqetMGBnEVASfQbACJoIzunZZAtcFiT Z259gTYKwb0KO9IlX6r3uNxN0Ofqk4Pd3lnBS2gZcsvnYeZtzh2tVjhrGVdxXYjcFynF Ix/ZnDRWmrvkqgoEFDXITAdYWkAASHlQEn5kjjIXy4MGgmC/oI7BafsqFWwaS+xo0G/D vgqjSJ+gG5n+zqFXxZh3ndI8Os/tdTRSsur8O+qD3HpOfgXbt59pKOorOrJl0Tk8mZHq iVsNqqeaepVhYMSJ9M2bmJdMaWcuBylyNz+Lm3wqob3SmYz8LUy5gye+V/8DR9HQTdck DLtQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b="cd/3/P13"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="L4/6qXdz"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=drpmaj2b; 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 5a478bee46e88-38567cad3d7si54750391eec.46.2026.11.26.03.58.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Nov 2026 03:59:00 -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=pass header.i=@lists.sourceforge.net header.s=beta header.b="cd/3/P13"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="L4/6qXdz"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=drpmaj2b; 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 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=I4B5Nw4Lfn/jb1Ko+BP+F5e3S/Rf+8IOq34mx0PhPak=; b=cd/3/P13u3R66B 6I3T4xsKgX5kinAHGI87iQK/TSMtidZef00qDj09X8NNlM6MtxZoklvZFm4o5X5Zg3CLHopsbWn2j dTAmk7iWKGj2LjY0fJSD60pYtBYqke5VmhoiCFFaAdP6XP6PzsVxDVOuo0PbrosBG5GFI5A0wQLo5 K4o=; 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.100.1) (envelope-from ) id 1xWY7u-000000007bE-3abU; Thu, 26 Nov 2026 11:58:58 +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.100.1) (envelope-from ) id 1xWY7t-000000007b6-0Xoo for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 11:58:57 +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-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2+wXDH/2G9Vgc8X6qofNTcQvRBUll2GEfImC/nXJLFw=; b=L4/6qXdzO44pmOqXTfXyWetbNp l6ZBu6+ZMlEUCzLNdE0Eve/il8M6zFYMn9TEmdvw0BlEtbxv8FHX7s2kVdejK8/F9s5dCeKS4//ZO D8u58SX/hDo3NPZSwjTFrPrgRsreLCVx4mvmGCRWFePqMrLwFNsAE//mClddfx8S/Odg=; 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-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=2+wXDH/2G9Vgc8X6qofNTcQvRBUll2GEfImC/nXJLFw=; b=drpmaj2b2QWuQ7hQyHLjOzwzQ/ Bh0h4Foz5fSiKrWoL2gfLIrFIWCewWhw5g+PIhz9q7pLzP/iRNGo5WCaLWMy0pwh8zAuOElhs40sS 3/1YU8AhBYYce6/US0OMa43IA4CgCMxWJxWXK84nb73yjbSaduoaibobDSj0O6l7Q63Q=; Received: from [193.149.48.129] (helo=blue.greenie.muc.de) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xWY7r-000000006CP-1x6E for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 11:58:57 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 6AQBwm0s007342 for ; Thu, 26 Nov 2026 12:58:48 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6AQBwmsx007341 for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 12:58:48 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Thu, 26 Nov 2026 12:58:43 +0100 Message-ID: <20261126115848.7329-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", 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: Razvan Cojocaru dhcp_extract_router_msg() assumed a 20-byte IP header, so DHCP replies carrying IP options were not recognised. Use the IHL to find the UDP header and skip fragments, whose UDP checksum covers data we [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1xWY7r-000000006CP-1x6E Subject: [Openvpn-devel] [PATCH v2] dhcp: locate the UDP header via the IP header length 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: 1882921988682143062 X-GMAIL-MSGID: 1882921988682143062 From: Razvan Cojocaru dhcp_extract_router_msg() assumed a 20-byte IP header, so DHCP replies carrying IP options were not recognised. Use the IHL to find the UDP header and skip fragments, whose UDP checksum covers data we don't have. Drop struct dhcp_full, no longer used. Change-Id: I3630ac3defbb64e252ac3009fdd784153367e4fd Signed-off-by: Razvan Cojocaru Acked-by: Lev Stipakov Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2209 --- 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/+/2209 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Lev Stipakov diff --git a/src/openvpn/dhcp.c b/src/openvpn/dhcp.c index 525d567..8c9e520 100644 --- a/src/openvpn/dhcp.c +++ b/src/openvpn/dhcp.c @@ -152,27 +152,49 @@ in_addr_t dhcp_extract_router_msg(struct buffer *ipbuf) { - struct dhcp_full *df = (struct dhcp_full *)BPTR(ipbuf); - const int optlen = - BLEN(ipbuf) - - (int)(sizeof(struct openvpn_iphdr) + sizeof(struct openvpn_udphdr) + sizeof(struct dhcp)); - - if (optlen >= 0 && df->ip.protocol == OPENVPN_IPPROTO_UDP - && df->udp.source == htons(BOOTPS_PORT) && df->udp.dest == htons(BOOTPC_PORT) - && df->dhcp.op == BOOTREPLY) + if (BLENZ(ipbuf) < sizeof(struct openvpn_iphdr)) { - const int message_type = get_dhcp_message_type(&df->dhcp, optlen); + return 0; + } + + const struct openvpn_iphdr *ip = (const struct openvpn_iphdr *)BPTR(ipbuf); + const int hlen = OPENVPN_IPH_GET_LEN(ip->version_len); + + /* Skip fragments: later ones carry no UDP header, and the checksum + * covers the whole datagram. */ + if (ntohs(ip->frag_off) & (OPENVPN_IP_MF | OPENVPN_IP_OFFMASK)) + { + return 0; + } + + /* The UDP header follows any IP options. */ + struct buffer udpbuf = *ipbuf; + if (hlen < (int)sizeof(struct openvpn_iphdr) || !buf_advance(&udpbuf, hlen)) + { + return 0; + } + + struct openvpn_udphdr *udp = (struct openvpn_udphdr *)BPTR(&udpbuf); + struct dhcp *dhcp = (struct dhcp *)(udp + 1); + const int optlen = + BLEN(&udpbuf) - (int)(sizeof(struct openvpn_udphdr) + sizeof(struct dhcp)); + + if (optlen >= 0 && ip->protocol == OPENVPN_IPPROTO_UDP + && udp->source == htons(BOOTPS_PORT) && udp->dest == htons(BOOTPC_PORT) + && dhcp->op == BOOTREPLY) + { + const int message_type = get_dhcp_message_type(dhcp, optlen); if (message_type == DHCPACK || message_type == DHCPOFFER) { /* get the router IP address while padding out all DHCP router options */ - const in_addr_t ret = do_extract(&df->dhcp, optlen); + const in_addr_t ret = do_extract(dhcp, optlen); /* recompute the UDP checksum */ - df->udp.check = 0; - df->udp.check = htons(ip_checksum( - AF_INET, (uint8_t *)&df->udp, + udp->check = 0; + udp->check = htons(ip_checksum( + AF_INET, (uint8_t *)udp, sizeof(struct openvpn_udphdr) + sizeof(struct dhcp) + optlen, - (uint8_t *)&df->ip.saddr, (uint8_t *)&df->ip.daddr, OPENVPN_IPPROTO_UDP)); + (const uint8_t *)&ip->saddr, (const uint8_t *)&ip->daddr, OPENVPN_IPPROTO_UDP)); /* only return the extracted Router address if DHCPACK */ if (message_type == DHCPACK) diff --git a/src/openvpn/dhcp.h b/src/openvpn/dhcp.h index 38ebf8d..8517b92 100644 --- a/src/openvpn/dhcp.h +++ b/src/openvpn/dhcp.h @@ -80,15 +80,6 @@ uint32_t magic; /* must be 0x63825363 (network order) */ }; -struct dhcp_full -{ - struct openvpn_iphdr ip; - struct openvpn_udphdr udp; - struct dhcp dhcp; -#define DHCP_OPTIONS_BUFFER_SIZE 256 - uint8_t options[DHCP_OPTIONS_BUFFER_SIZE]; -}; - #pragma pack() in_addr_t dhcp_extract_router_msg(struct buffer *ipbuf); diff --git a/src/openvpn/proto.h b/src/openvpn/proto.h index 14f9264..0841ad5 100644 --- a/src/openvpn/proto.h +++ b/src/openvpn/proto.h @@ -96,6 +96,7 @@ uint16_t tot_len; uint16_t id; +#define OPENVPN_IP_MF 0x2000 #define OPENVPN_IP_OFFMASK 0x1fff uint16_t frag_off;