From patchwork Mon Nov 3 09:15:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4558 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7001:a40d:b0:72f:f16c:e055 with SMTP id vo13csp1284671mab; Mon, 3 Nov 2025 01:15:49 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVlfi2iqDm1T2TPhU4CSYJEMN8N9PFJyknDxgL7072NBBTYgWlquI+isFDANrRkehdh8h15XSGZVMU=@openvpn.net X-Google-Smtp-Source: AGHT+IE9nRWqSeN9ArJuns6M3/yJMOokVlNsry65psK0/DjfYSN7GY7ghsGi6/1adla9QY5DbqGG X-Received: by 2002:a05:6602:3411:b0:941:76d:7c27 with SMTP id ca18e2360f4ac-9482290267cmr1833234339f.8.1762161348853; Mon, 03 Nov 2025 01:15:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1762161348; cv=none; d=google.com; s=arc-20240605; b=KqA6SIRPcHt9wDabKfMJcbpBdSkiqPIHNfNLCBZwCv8aAR+7FtnNTzfgucDd5UHu3P Dc0ICjH4otqP1MfXateddL9nnLajNISy4MArKj63zCcXHIqyAB4blZzprFn9dMD8Xc8a 39L43pBcIpDnrT9zZ+kT0f7sbRNVarIhG6GIlsPFst2YusVfEGqJ7nD5g7LhebuTCm0b mpyUw1pPyxK9vUF1PVPMHQlYB7HgW8MVjspWbqueYEGnAWp2M7jhtdKbWb3e/XH+wyaQ +OjztuVDtmx0JG9hbKpzFD42UOwkhd1cnbred9iiqjygAZjERo1s5Womg3NahP7SAwSO 66QA== 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:dkim-signature; bh=SxAnQns+P1QoJYfzeN5gVpKI03LDyXIIzylvIV3nJzs=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=Z+jfwWRoNebrICaAmngd1BneGOJL/1fB2yc/UCcINMBLl4DiQOvogqGuLj6IRn5iSl URVAlRXBAkYsklIi2/F6VtQdTreVKCXmDNoF6UY+CPMpMPhi6grtQ0MEdKzfztW6nEle TJhLNyXfrIRMepZV+y3h2Ud5V5rVbVtMz1buLUtr1EPXunNCeRdYtgKPNtCDAiLmX13L PZYACBvtCB2ZXz44adrJIfRc0sT5CzUFKxR4/fKA89KS2tzQdImzkOwMo7HcBnGDuWxV fEEwNO2RR/UCwFWuWIhUs3lTiH7rwkrwm/hX4oL8dweZwfTTycK7NGukiLBYGG+Dt47M 44NA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=cvWvAGWS; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=NsNBYhOz; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=U8sQK950; 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 ca18e2360f4ac-94827c18807si684385839f.299.2025.11.03.01.15.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Nov 2025 01:15:48 -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=cvWvAGWS; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=NsNBYhOz; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=U8sQK950; 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-Owner; bh=SxAnQns+P1QoJYfzeN5gVpKI03LDyXIIzylvIV3nJzs=; b=cvWvAGWSXROKA1i8gTYlN5V7jQ qwvDdtI6E9A8cpZ6vyIV3JuyIRxnpVaDufCN+GRjUN6Jn6O8ilywj00qy65CDTJvzOZhk4Lygha/y 7BIqd5PBkKXWC1Ja3MmuEeoYZ/iAaYBTKty2hoJWm1IHcJ2fzLOI9W3l+NIdqHYcl5RU=; 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 1vFqfA-0007nb-DK; Mon, 03 Nov 2025 09:15:44 +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 1vFqf5-0007nT-ML for openvpn-devel@lists.sourceforge.net; Mon, 03 Nov 2025 09:15:39 +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=M24yxMmyQboBDOaZPrK6u2U9KGgN83MI/6qZJ6n1GsU=; b=NsNBYhOziWx1+CL6LbgpSg7lZj E+6eGFOUCDpEHZGLt91zryvp4zQolMh5HRp6qZL55t5uqf+9TExgrpmjf0bE85seY1Wtk1zkw+oy3 FtdFjEFF00SNBNgr9I5cmPEazgWcCK0v+2zDmDLXoRiQJVqbMZQthTbcnBdouhocJwtk=; 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=M24yxMmyQboBDOaZPrK6u2U9KGgN83MI/6qZJ6n1GsU=; b=U8sQK950yeER3XNMhBfa+a0sBi Nkmak6TUOONHBc6fEqeQoAIpQgFeHXuiNKHnOrFnq8B98TJv0KPxRpxZqE7EJ/ZdrfP7Gym6w7Jns ydjkJGCGWgVnUm1+Vkqy2HQqYM+4DJnf5Uu9i5cOP34LAbYqLTFS+Sup9cksLGKTO/SQ=; Received: from [193.149.48.134] (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 1vFqf4-0002tD-00 for openvpn-devel@lists.sourceforge.net; Mon, 03 Nov 2025 09:15:39 +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 5A39FP5d022129 for ; Mon, 3 Nov 2025 10:15:25 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 5A39FPcc022128 for openvpn-devel@lists.sourceforge.net; Mon, 3 Nov 2025 10:15:25 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Mon, 3 Nov 2025 10:15:17 +0100 Message-ID: <20251103091525.22108-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.49.1 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-1.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: Heiko Hund We use the interface index with netsh everywhere else, so convert the remaining invocations of netsh to index use as well. Change-Id: I5cf45cfe0567da8fb5d47118a432a35b358f3809 Signed-off-by: Heiko Hund Acked-by: Lev Stipakov Gerrit URL: https://gerrit.openvpn.net/c/openvpn/ [...] 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: 1vFqf4-0002tD-00 Subject: [Openvpn-devel] [PATCH v1] iservice: use interface index with netsh 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?1847760098541894761?= X-GMAIL-MSGID: =?utf-8?q?1847760098541894761?= From: Heiko Hund We use the interface index with netsh everywhere else, so convert the remaining invocations of netsh to index use as well. Change-Id: I5cf45cfe0567da8fb5d47118a432a35b358f3809 Signed-off-by: Heiko Hund Acked-by: Lev Stipakov Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1337 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to release/2.6. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1337 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Lev Stipakov diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index c12d34f..b35005c 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -1035,16 +1035,16 @@ } /** - * Run the command: netsh interface $proto $action dns $if_name $addr [validate=no] + * Run the command: netsh interface $proto $action dns $if_index $addr [validate=no] * @param action "delete" or "add" * @param proto "ipv6" or "ip" - * @param if_name "name_of_interface" + * @param if_index index of the interface to modify DNS for * @param addr IPv4 (for proto = ip) or IPv6 address as a string * * If addr is null and action = "delete" all addresses are deleted. */ static DWORD -netsh_dns_cmd(const wchar_t *action, const wchar_t *proto, const wchar_t *if_name, const wchar_t *addr) +netsh_dns_cmd(const wchar_t *action, const wchar_t *proto, int if_index, const wchar_t *addr) { DWORD err = 0; int timeout = 30000; /* in msec */ @@ -1069,10 +1069,10 @@ /* cmd template: * netsh interface $proto $action dns $if_name $addr [validate=no] */ - const wchar_t *fmt = L"netsh interface %ls %ls dns \"%ls\" %ls"; + const wchar_t *fmt = L"netsh interface %ls %ls dns %d %ls"; /* max cmdline length in wchars -- include room for worst case and some */ - size_t ncmdline = wcslen(fmt) + wcslen(if_name) + wcslen(addr) + 32 + 1; + size_t ncmdline = wcslen(fmt) + 11 /*if_index*/ + wcslen(addr) + 32 + 1; cmdline = malloc(ncmdline*sizeof(wchar_t)); if (!cmdline) { @@ -1080,7 +1080,7 @@ goto out; } - openvpn_swprintf(cmdline, ncmdline, fmt, proto, action, if_name, addr); + openvpn_swprintf(cmdline, ncmdline, fmt, proto, action, if_index, addr); if (IsWindows7OrGreater()) { @@ -1094,16 +1094,16 @@ } /** - * Run the command: netsh interface ip $action wins $if_name [static] $addr + * Run the command: netsh interface ip $action wins $if_index [static] $addr * @param action "delete", "add" or "set" - * @param if_name "name_of_interface" + * @param if_index index of the interface to modify WINS for * @param addr IPv4 address as a string * * If addr is null and action = "delete" all addresses are deleted. * if action = "set" then "static" is added before $addr */ static DWORD -netsh_wins_cmd(const wchar_t *action, const wchar_t *if_name, const wchar_t *addr) +netsh_wins_cmd(const wchar_t *action, int if_index, const wchar_t *addr) { DWORD err = 0; int timeout = 30000; /* in msec */ @@ -1129,11 +1129,11 @@ /* cmd template: * netsh interface ip $action wins $if_name $static $addr */ - const wchar_t *fmt = L"netsh interface ip %ls wins \"%ls\" %ls %ls"; + const wchar_t *fmt = L"netsh interface ip %ls wins %d %ls %ls"; /* max cmdline length in wchars -- include room for worst case and some */ - size_t ncmdline = wcslen(fmt) + wcslen(if_name) + wcslen(action) + wcslen(addr) - +wcslen(addr_static) + 32 + 1; + size_t ncmdline = wcslen(fmt) + 11 /*if_index*/ + wcslen(action) + wcslen(addr) + + wcslen(addr_static) + 32 + 1; cmdline = malloc(ncmdline * sizeof(wchar_t)); if (!cmdline) { @@ -1141,7 +1141,7 @@ goto out; } - openvpn_swprintf(cmdline, ncmdline, fmt, action, if_name, addr_static, addr); + openvpn_swprintf(cmdline, ncmdline, fmt, action, if_index, addr_static, addr); err = ExecCommand(argv0, cmdline, timeout); @@ -1184,18 +1184,18 @@ /* Delete all IPv4 or IPv6 dns servers for an interface */ static DWORD -DeleteDNS(short family, wchar_t *if_name) +DeleteDNS(short family, int if_index) { wchar_t *proto = (family == AF_INET6) ? L"ipv6" : L"ip"; - return netsh_dns_cmd(L"delete", proto, if_name, NULL); + return netsh_dns_cmd(L"delete", proto, if_index, NULL); } /* Add an IPv4 or IPv6 dns server to an interface */ static DWORD -AddDNS(short family, wchar_t *if_name, wchar_t *addr) +AddDNS(short family, int if_index, wchar_t *addr) { wchar_t *proto = (family == AF_INET6) ? L"ipv6" : L"ip"; - return netsh_dns_cmd(L"add", proto, if_name, addr); + return netsh_dns_cmd(L"add", proto, if_index, addr); } static BOOL @@ -1295,12 +1295,12 @@ */ if (addr_len > 0 || msg->header.type == msg_del_dns_cfg) { - err = DeleteDNS(msg->family, wide_name); + err = DeleteDNS(msg->family, msg->iface.index); if (err) { goto out; } - free(RemoveListItem(&(*lists)[undo_type], CmpWString, wide_name)); + free(RemoveListItem(&(*lists)[undo_type], CmpAny, NULL)); } if (msg->header.type == msg_del_dns_cfg) @@ -1323,7 +1323,7 @@ { RtlIpv4AddressToStringW(&msg->addr[i].ipv4, addr); } - err = AddDNS(msg->family, wide_name, addr); + err = AddDNS(msg->family, msg->iface.index, addr); if (i == 0 && err) { goto out; @@ -1337,11 +1337,15 @@ if (msg->addr_len > 0) { - wchar_t *tmp_name = _wcsdup(wide_name); - if (!tmp_name || AddListItem(&(*lists)[undo_type], tmp_name)) + int *tmp_index = malloc(sizeof(msg->iface.index)); + if (tmp_index) { - free(tmp_name); - DeleteDNS(msg->family, wide_name); + *tmp_index = msg->iface.index; + } + if (!tmp_index || AddListItem(&(*lists)[undo_type], tmp_index)) + { + free(tmp_index); + DeleteDNS(msg->family, msg->iface.index); err = ERROR_OUTOFMEMORY; goto out; } @@ -1360,7 +1364,7 @@ static DWORD HandleWINSConfigMessage(const wins_cfg_message_t *msg, undo_lists_t *lists) { - DWORD err = 0; + DWORD err = NO_ERROR; wchar_t addr[16]; /* large enough to hold string representation of an ipv4 */ int addr_len = msg->addr_len; @@ -1370,37 +1374,25 @@ addr_len = _countof(msg->addr); } - if (!msg->iface.name[0]) /* interface name is required */ + if (!msg->iface.index) /* interface index is required */ { return ERROR_MESSAGE_DATA; } - /* use a non-const reference with limited scope to enforce null-termination of strings from client */ - { - wins_cfg_message_t *msgptr = (wins_cfg_message_t *)msg; - msgptr->iface.name[_countof(msg->iface.name) - 1] = '\0'; - } - - wchar_t *wide_name = utf8to16(msg->iface.name); /* utf8 to wide-char */ - if (!wide_name) - { - return ERROR_OUTOFMEMORY; - } - /* We delete all current addresses before adding any * OR if the message type is del_wins_cfg */ if (addr_len > 0 || msg->header.type == msg_del_wins_cfg) { - err = netsh_wins_cmd(L"delete", wide_name, NULL); + err = netsh_wins_cmd(L"delete", msg->iface.index, NULL); if (err) { goto out; } - free(RemoveListItem(&(*lists)[undo_wins], CmpWString, wide_name)); + free(RemoveListItem(&(*lists)[undo_wins], CmpAny, NULL)); } - if (msg->header.type == msg_del_wins_cfg) + if (addr_len == 0 || msg->header.type == msg_del_wins_cfg) { goto out; /* job done */ } @@ -1408,7 +1400,7 @@ for (int i = 0; i < addr_len; ++i) { RtlIpv4AddressToStringW(&msg->addr[i].ipv4, addr); - err = netsh_wins_cmd(i == 0 ? L"set" : L"add", wide_name, addr); + err = netsh_wins_cmd(i == 0 ? L"set" : L"add", msg->iface.index, addr); if (i == 0 && err) { goto out; @@ -1418,22 +1410,23 @@ */ } - err = 0; - - if (addr_len > 0) + int *if_index = malloc(sizeof(msg->iface.index)); + if (if_index) { - wchar_t *tmp_name = _wcsdup(wide_name); - if (!tmp_name || AddListItem(&(*lists)[undo_wins], tmp_name)) - { - free(tmp_name); - netsh_wins_cmd(L"delete", wide_name, NULL); - err = ERROR_OUTOFMEMORY; - goto out; - } + *if_index = msg->iface.index; } + if (!if_index || AddListItem(&(*lists)[undo_wins], if_index)) + { + free(if_index); + netsh_wins_cmd(L"delete", msg->iface.index, NULL); + err = ERROR_OUTOFMEMORY; + goto out; + } + + err = 0; + out: - free(wide_name); return err; } @@ -1734,15 +1727,15 @@ break; case undo_dns4: - DeleteDNS(AF_INET, item->data); + DeleteDNS(AF_INET, *(int *)item->data); break; case undo_dns6: - DeleteDNS(AF_INET6, item->data); + DeleteDNS(AF_INET6, *(int *)item->data); break; case undo_wins: - netsh_wins_cmd(L"delete", item->data, NULL); + netsh_wins_cmd(L"delete", *(int *)item->data, NULL); break; case undo_domain: