From patchwork Wed Oct 11 21:07:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Rozman X-Patchwork-Id: 30 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director2.mail.ord1d.rsapps.net ([172.30.157.8]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id 8UwgL+0i31k/DwAAgoeIoA for ; Thu, 12 Oct 2017 04:08:13 -0400 Received: from director7.mail.ord1c.rsapps.net ([172.28.128.196]) by director2.mail.ord1d.rsapps.net (Dovecot) with LMTP id DWwlB+0i31l8QwAAgYhSiA ; Thu, 12 Oct 2017 04:08:13 -0400 Received: from smtp47.gate.ord1a ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by director7.mail.ord1c.rsapps.net (Dovecot) with LMTP id 9ooHK+Ai31nHXgAAqdfm7w ; Thu, 12 Oct 2017 04:08:13 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-MessageSniffer-Scan-Result: 0 X-MessageSniffer-Rules: 0-298-1044-1262-w 0-298-1044-1626-w 0-298-0-17967-f X-CMAE-Scan-Result: 0 X-CNFS-Analysis: v=2.2 cv=OtQN8G3t c=1 sm=1 tr=0 a=Q8DxjiC8O3VT/NpP1XjEZQ==:117 a=Q8DxjiC8O3VT/NpP1XjEZQ==:17 a=kj9zAlcOel0A:10 a=02M-m0pO-4AA:10 a=WiVod9pSvdkA:10 a=9sSjY8p1AAAA:8 a=P_JWiMecAAAA:8 a=FP58Ms26AAAA:8 a=en4qr9RTPJYENwk8s3MA:9 a=20h1c01_FfsfFG6a:21 a=h267pi7OQZj_nDcP:21 a=CjuIK1q_8ugA:10 a=-FEs8UIgK8oA:10 a=NWVoK91CQyQA:10 a=ub54wNWiXv_DzeFsgEJW:22 a=D0-HAvA3Hk9NMREbgwuX:22 X-Orig-To: justin@openvpn.net X-Originating-Ip: [216.34.181.88] Authentication-Results: smtp47.gate.ord1a.rsapps.net; iprev=pass policy.iprev="216.34.181.88"; 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=rozman.si; dmarc=fail (p=none; dis=none) header.from=rozman.si X-Classification-ID: 7dc29ffe-af24-11e7-8817-0022192d87f6-1-1 Received: from [216.34.181.88] ([216.34.181.88:23990] helo=lists.sourceforge.net) by smtp47.gate.ord1a.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 84/42-21737-CE22FD95; Thu, 12 Oct 2017 04:08:12 -0400 Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1e2YWw-0002mM-0R; Thu, 12 Oct 2017 08:07:46 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtps (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.89) (envelope-from ) id 1e2YWu-0002mG-EM for openvpn-devel@lists.sourceforge.net; Thu, 12 Oct 2017 08:07:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Message-Id:Date:Subject:Cc:To:From; bh=vqHuhhn6ju3nb2esdGzc5swnGMpnpsNRD32DqhX1mSU=; b=NUnGoWkZLDcUPh1NVqLSJJKkr9kBdSk6VOvHZz0IPwbcNqN5O8hVcXdGJp29DMzLtJHHUoRR5D19+BwA3DhkPk2sdhmd+ddtx1vQxbzl6lJDQIg6g/x6evjipsbVhV6GoxUe27HYHp9b6B/Ny3dBt9wUlZxrWdwcsa718xD64O8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=Message-Id:Date:Subject:Cc:To:From; bh=vqHuhhn6ju3nb2esdGzc5swnGMpnpsNRD32DqhX1mSU=; b=k1a44UpU3D0VaG6HYlVuqQ+CCPgWsbgInYPQk/fdTbfhCTagNb+1CRrjEjVFdgdkzpGa1v0kH7lgSWS0Y+3zgT/DUn0pPwAkW/mQsc0zaYDqiHLTccoafVqIb0wpBVH7TuIHANvl063+ALS26CKl/WSY90HN/2CNTG/hnG5cmQE=; Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of rozman.si designates 89.212.80.145 as permitted sender) client-ip=89.212.80.145; envelope-from=simon@rozman.si; helo=amebis01.amebis.si; Received: from amebis01.amebis.si ([89.212.80.145]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1e2YWr-0001pb-2V for openvpn-devel@lists.sourceforge.net; Thu, 12 Oct 2017 08:07:44 +0000 Received: from SR5.amebis.doma (sr5.amebis.doma [192.168.100.81]) by amebis01.amebis.si (Postfix) with ESMTP id E5B2A407C0; Thu, 12 Oct 2017 10:07:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=rozman.si; s=default; t=1507795652; bh=vqMEVUTyZDlkB/wn2xue31dd9KUt6V7wRkj31qu99ew=; h=From:To:Cc:Subject:Date:Message-Id; b=IQxoCUwIEZ8FsqW9M9N4GV4e0BUD8xzGTK6v4qOP+DVOaJl/IRZNBbLbUZocUZUg7 /6KkdLhrC0N+bkfu4cVL+Ao6w4/jq4hrQ4yv98gHLba0MO8GwOrPHoCLk0Hanb+zwK IoM0C0MW78eCG2I2WCPcrJpWoXxmaR0qgFETB0eU= From: Simon Rozman To: openvpn-devel@lists.sourceforge.net Date: Thu, 12 Oct 2017 10:07:20 +0200 Message-Id: <20171012080720.7764-1-simon@rozman.si> X-Mailer: git-send-email 2.9.0.windows.1 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [89.212.80.145 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's 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.1 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1e2YWr-0001pb-2V Subject: [Openvpn-devel] [PATCH] Simplify iphlpapi.dll API calls 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: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox Dynamically locating API function addresses at run-time using GetProcAddress() was a leftover from the early days of the interactive service development. It was required before `NTDDI_VERSION` was raised from Windows XP to Windows Vista. After NTDDI_VERSION API level was raised to NTDDI_VISTA, the direct calling of Vista introduced API functions is possible and much simpler. This patch simplifies the code while in the same time it removes controversial function type definitions that caused interactive service not to compile on MSVC. --- src/openvpnserv/interactive.c | 123 +----------------------------------------- 1 file changed, 1 insertion(+), 122 deletions(-) diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index a060a06..bb8c5f6 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -549,23 +549,6 @@ InterfaceLuid(const char *iface_name, PNET_LUID luid) LPWSTR wide_name; int n; - typedef NETIO_STATUS WINAPI (*ConvertInterfaceAliasToLuidFn) (LPCWSTR, PNET_LUID); - static ConvertInterfaceAliasToLuidFn ConvertInterfaceAliasToLuid = NULL; - if (!ConvertInterfaceAliasToLuid) - { - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); - if (iphlpapi == NULL) - { - return GetLastError(); - } - - ConvertInterfaceAliasToLuid = (ConvertInterfaceAliasToLuidFn) GetProcAddress(iphlpapi, "ConvertInterfaceAliasToLuid"); - if (!ConvertInterfaceAliasToLuid) - { - return GetLastError(); - } - } - n = MultiByteToWideChar(CP_UTF8, 0, iface_name, -1, NULL, 0); wide_name = malloc(n * sizeof(WCHAR)); MultiByteToWideChar(CP_UTF8, 0, iface_name, -1, wide_name, n); @@ -584,24 +567,6 @@ CmpAddress(LPVOID item, LPVOID address) static DWORD DeleteAddress(PMIB_UNICASTIPADDRESS_ROW addr_row) { - typedef NETIOAPI_API (*DeleteUnicastIpAddressEntryFn) (const PMIB_UNICASTIPADDRESS_ROW); - static DeleteUnicastIpAddressEntryFn DeleteUnicastIpAddressEntry = NULL; - - if (!DeleteUnicastIpAddressEntry) - { - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); - if (iphlpapi == NULL) - { - return GetLastError(); - } - - DeleteUnicastIpAddressEntry = (DeleteUnicastIpAddressEntryFn) GetProcAddress(iphlpapi, "DeleteUnicastIpAddressEntry"); - if (!DeleteUnicastIpAddressEntry) - { - return GetLastError(); - } - } - return DeleteUnicastIpAddressEntry(addr_row); } @@ -612,32 +577,6 @@ HandleAddressMessage(address_message_t *msg, undo_lists_t *lists) PMIB_UNICASTIPADDRESS_ROW addr_row; BOOL add = msg->header.type == msg_add_address; - typedef NETIOAPI_API (*CreateUnicastIpAddressEntryFn) (const PMIB_UNICASTIPADDRESS_ROW); - typedef NETIOAPI_API (*InitializeUnicastIpAddressEntryFn) (PMIB_UNICASTIPADDRESS_ROW); - static CreateUnicastIpAddressEntryFn CreateUnicastIpAddressEntry = NULL; - static InitializeUnicastIpAddressEntryFn InitializeUnicastIpAddressEntry = NULL; - - if (!CreateUnicastIpAddressEntry || !InitializeUnicastIpAddressEntry) - { - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); - if (iphlpapi == NULL) - { - return GetLastError(); - } - - CreateUnicastIpAddressEntry = (CreateUnicastIpAddressEntryFn) GetProcAddress(iphlpapi, "CreateUnicastIpAddressEntry"); - if (!CreateUnicastIpAddressEntry) - { - return GetLastError(); - } - - InitializeUnicastIpAddressEntry = (InitializeUnicastIpAddressEntryFn) GetProcAddress(iphlpapi, "InitializeUnicastIpAddressEntry"); - if (!InitializeUnicastIpAddressEntry) - { - return GetLastError(); - } - } - addr_row = malloc(sizeof(*addr_row)); if (addr_row == NULL) { @@ -706,24 +645,6 @@ CmpRoute(LPVOID item, LPVOID route) static DWORD DeleteRoute(PMIB_IPFORWARD_ROW2 fwd_row) { - typedef NETIOAPI_API (*DeleteIpForwardEntry2Fn) (PMIB_IPFORWARD_ROW2); - static DeleteIpForwardEntry2Fn DeleteIpForwardEntry2 = NULL; - - if (!DeleteIpForwardEntry2) - { - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); - if (iphlpapi == NULL) - { - return GetLastError(); - } - - DeleteIpForwardEntry2 = (DeleteIpForwardEntry2Fn) GetProcAddress(iphlpapi, "DeleteIpForwardEntry2"); - if (!DeleteIpForwardEntry2) - { - return GetLastError(); - } - } - return DeleteIpForwardEntry2(fwd_row); } @@ -734,24 +655,6 @@ HandleRouteMessage(route_message_t *msg, undo_lists_t *lists) PMIB_IPFORWARD_ROW2 fwd_row; BOOL add = msg->header.type == msg_add_route; - typedef NETIOAPI_API (*CreateIpForwardEntry2Fn) (PMIB_IPFORWARD_ROW2); - static CreateIpForwardEntry2Fn CreateIpForwardEntry2 = NULL; - - if (!CreateIpForwardEntry2) - { - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); - if (iphlpapi == NULL) - { - return GetLastError(); - } - - CreateIpForwardEntry2 = (CreateIpForwardEntry2Fn) GetProcAddress(iphlpapi, "CreateIpForwardEntry2"); - if (!CreateIpForwardEntry2) - { - return GetLastError(); - } - } - fwd_row = malloc(sizeof(*fwd_row)); if (fwd_row == NULL) { @@ -820,36 +723,12 @@ out: static DWORD HandleFlushNeighborsMessage(flush_neighbors_message_t *msg) { - typedef NETIOAPI_API (*FlushIpNetTable2Fn) (ADDRESS_FAMILY, NET_IFINDEX); - static FlushIpNetTable2Fn flush_fn = NULL; - if (msg->family == AF_INET) { return FlushIpNetTable(msg->iface.index); } - if (!flush_fn) - { - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); - if (iphlpapi == NULL) - { - return GetLastError(); - } - - flush_fn = (FlushIpNetTable2Fn) GetProcAddress(iphlpapi, "FlushIpNetTable2"); - if (!flush_fn) - { - if (GetLastError() == ERROR_PROC_NOT_FOUND) - { - return WSAEPFNOSUPPORT; - } - else - { - return GetLastError(); - } - } - } - return flush_fn(msg->family, msg->iface.index); + return FlushIpNetTable2(msg->family, msg->iface.index); } static void