From patchwork Mon Apr 1 00:21:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Schenk X-Patchwork-Id: 708 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director12.mail.ord1d.rsapps.net ([172.27.255.57]) by backend30.mail.ord1d.rsapps.net with LMTP id uEBZCIz0oVywEwAAIUCqbw for ; Mon, 01 Apr 2019 07:22:52 -0400 Received: from proxy12.mail.iad3a.rsapps.net ([172.27.255.57]) by director12.mail.ord1d.rsapps.net with LMTP id yIG6BYz0oVx/UwAAIasKDg ; Mon, 01 Apr 2019 07:22:52 -0400 Received: from smtp12.gate.iad3a ([172.27.255.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy12.mail.iad3a.rsapps.net with LMTP id WLJkO4v0oVztUwAAh9K5Vw ; Mon, 01 Apr 2019 07:22:51 -0400 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: smtp12.gate.iad3a.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; dmarc=fail (p=none; dis=none) header.from=mail.uni-paderborn.de X-Suspicious-Flag: YES X-Classification-ID: 7c04d928-5470-11e9-bdd8-525400068c1c-1-1 Received: from [216.105.38.7] ([216.105.38.7:47347] helo=lists.sourceforge.net) by smtp12.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 75/EF-13628-B84F1AC5; Mon, 01 Apr 2019 07:22:51 -0400 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.90_1) (envelope-from ) id 1hAv0x-0008CD-Ks; Mon, 01 Apr 2019 11:22:07 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1hAv0u-0008Bt-Ch for openvpn-devel@lists.sourceforge.net; Mon, 01 Apr 2019 11:22:04 +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:Cc:To:From:Sender:Reply-To: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=0hcRVa+Oxwo+RM2uk/LNESv7p/9UzYhzlmnB1bnN8X0=; b=lQuUYirY2KrjjW7Qrutt4Br5Ba 7l8lPHQN0BrZvTBA0aFW4Smw4ysh9luJuGFcTKapf+GJN2KJ+YrNmUoNcgFJjI33UznXrSiSBN0Wl l7Buvw4BTtN6/NHZ02W9IhYXLwbnQyknr4IzFo4+JlEe5AZpFsSDmyLpd5UpZB/MIJOw=; 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:Cc:To:From:Sender:Reply-To: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=0hcRVa+Oxwo+RM2uk/LNESv7p/9UzYhzlmnB1bnN8X0=; b=JY7qVM10/7RRCuLxDT4YPyuDvu hAqCh8yJdm05ekpDeg8xs1tKmqiTSzJ+Y3BLvgNm7BX5W68ExO06vhNcMNMf/Nmw5umJ+VedtMHS7 DuAMyZZHSaktKz0BCc1twFss2Fbe5JeoD39FRmKgs5aHcsN5YhO7PZX5+Sp0mIWoj2v0=; Received: from mail.uni-paderborn.de ([131.234.142.9]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1hAv0s-006eaw-FE for openvpn-devel@lists.sourceforge.net; Mon, 01 Apr 2019 11:22:04 +0000 Received: from wormulon.uni-paderborn.de ([131.234.189.22] helo=localhost.localdomain) by mail.uni-paderborn.de with esmtp (Exim 4.89 spheron) id 1hAv0l-0001wh-GC for openvpn-devel@lists.sourceforge.net; Mon, 01 Apr 2019 13:21:55 +0200 Received: from mail.uni-paderborn.de by wormulon with queue id 3245486-5 for openvpn-devel@lists.sourceforge.net; Mon, 01 Apr 2019 11:21:53 GMT From: Christopher Schenk To: openvpn-devel@lists.sourceforge.net Date: Mon, 1 Apr 2019 13:21:39 +0200 Message-Id: <20190401112140.13212-3-cschenk@mail.uni-paderborn.de> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190401112140.13212-1-cschenk@mail.uni-paderborn.de> References: <20190329193805.GQ31008@greenie.muc.de> <20190401112140.13212-1-cschenk@mail.uni-paderborn.de> MIME-Version: 1.0 X-PMX-Version: 6.4.6.2792898, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2019.4.1.111516, AntiVirus-Engine: 5.58.0, AntiVirus-Data: 2019.2.22.5580002 X-IMT-Spam-Score: 0.0 () X-IMT-Authenticated-Sender: X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1hAv0s-006eaw-FE Subject: [Openvpn-devel] [PATCH 3/4] Use netioapi instead of netsh to set mtu 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 --- src/openvpn/tun.c | 68 +++++++++++++++++++---------------- src/openvpnserv/interactive.c | 44 +++++------------------ 2 files changed, 46 insertions(+), 66 deletions(-) diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index b0230a7c..9fe8444f 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -69,10 +69,8 @@ static void netsh_ifconfig(const struct tuntap_options *to, const in_addr_t netmask, const unsigned int flags); -static void netsh_set_mtu_ipv4(const char *flex_name, - const int mtu); - -static void netsh_set_mtu_ipv6(const char *flex_name, +static void windows_set_mtu(const int iface_indey, + short family, const int mtu); static void netsh_set_dns6_servers(const struct in6_addr *addr_list, @@ -1064,7 +1062,7 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu, netsh_command(&argv, 4, M_FATAL); /* set ipv6 dns servers if any are specified */ netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len, ifname); - netsh_set_mtu_ipv6(ifname, tun_mtu); + windows_set_mtu(tt->adapter_index, AF_INET6, tun_mtu); } /* explicit route needed */ @@ -1464,7 +1462,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, } else { - netsh_set_mtu_ipv4(ifname, tun_mtu); + windows_set_mtu(tt->adapter_index, AF_INET, tun_mtu); } } @@ -5309,35 +5307,45 @@ out: } static void -netsh_set_mtu_ipv4(const char *flex_name, - const int mtu) -{ - struct argv argv = argv_new(); - argv_printf(&argv, "%s%sc interface ipv4 set subinterface %s mtu = %d store=active", - get_win_sys_path(), - NETSH_PATH_SUFFIX, - flex_name, - mtu); - - netsh_command(&argv, 3, M_WARN); - argv_reset(&argv); -} - -static void -netsh_set_mtu_ipv6(const char *flex_name, +windows_set_mtu(const int iface_index, const short family, const int mtu) { - struct argv argv = argv_new(); - argv_printf(&argv, "%s%sc interface ipv6 set subinterface %s mtu = %d store=active", - get_win_sys_path(), - NETSH_PATH_SUFFIX, - flex_name, - mtu); + DWORD err = 0; + struct gc_arena gc = gc_new(); + MIB_IPINTERFACE_ROW row; + InitializeIpInterfaceEntry(&row); + row.Family = family; + row.InterfaceIndex = iface_index; + row.NlMtu = mtu; - netsh_command(&argv, 3, M_WARN); - argv_reset(&argv); + err = SetIpInterfaceEntry(&row); + if (family == AF_INET) + { + if (err != NO_ERROR) + { + msg(M_WARN, "TUN: Setting IPv4 mtu failed: %s [status=%u if_index=%d]", + strerror_win32(err, &gc), err, iface_index); + } + else + { + msg(M_INFO, "Successfully set IPv4 mtu on interface %d", iface_index); + } + } + else if (family == AF_INET6) + { + if (err != NO_ERROR) + { + msg(M_WARN, "TUN: Setting IPv6 mtu failed: %s [status=%u if_index=%d]", + strerror_win32(err, &gc), err, iface_index); + } + else + { + msg(M_INFO, "Successfully set IPv6 mtu on interface %d", iface_index); + } + } } + /* * Return a TAP name for netsh commands. */ diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index 31e4afa0..6e6a63fe 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef HAVE_VERSIONHELPERS_H #include @@ -1202,42 +1203,13 @@ static DWORD HandleMTUMessage(const set_mtu_message_t *mtu) { DWORD err = 0; - DWORD timeout = 5000; /* in milli seconds */ - wchar_t argv0[MAX_PATH]; - - /* Path of netsh */ - swprintf(argv0, _countof(argv0), L"%s\\%s", get_win_sys_path(), L"netsh.exe"); - argv0[_countof(argv0) - 1] = L'\0'; - - /* cmd template: - * netsh interface $family set subinterface "$if_name" mtu=$mtu - */ - const wchar_t *fmt; - if (mtu->family == AF_INET) - { - fmt = L"netsh interface ipv4 set subinterface \"%d\" mtu= %d"; - } - else if (mtu->family == AF_INET6) - { - fmt = L"netsh interface ipv6 set subinterface \"%d\" mtu= %d"; - } - - /* max cmdline length in wchars -- include room for if index: - * 20 chars for two 32 bit int in decimal and +1 for NUL - */ - size_t ncmdline = wcslen(fmt) + 20 + 1; - wchar_t *cmdline = malloc(ncmdline * sizeof(wchar_t)); - if (!cmdline) - { - err = ERROR_OUTOFMEMORY; - return err; - } - - openvpn_sntprintf(cmdline, ncmdline, fmt, mtu->iface.index, mtu->mtu); - - err = ExecCommand(argv0, cmdline, timeout); - - free(cmdline); + MIB_IPINTERFACE_ROW row; + InitializeIpInterfaceEntry(&row); + row.Family = mtu->family; + row.InterfaceIndex = mtu->iface.index; + row.NlMtu = mtu->mtu; + + err = SetIpInterfaceEntry(&row); return err; }