From patchwork Mon Sep 14 08:23:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 1451 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director9.mail.ord1d.rsapps.net ([172.27.255.51]) by backend30.mail.ord1d.rsapps.net with LMTP id CObCIWi1X192MwAAIUCqbw (envelope-from ) for ; Mon, 14 Sep 2020 14:24:40 -0400 Received: from proxy20.mail.iad3a.rsapps.net ([172.27.255.51]) by director9.mail.ord1d.rsapps.net with LMTP id OJ6jIWi1X1/dFgAAalYnBA (envelope-from ) for ; Mon, 14 Sep 2020 14:24:40 -0400 Received: from smtp13.gate.iad3a ([172.27.255.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy20.mail.iad3a.rsapps.net with LMTPS id 8C6jGmi1X1/AfQAAtfLT2w (envelope-from ) for ; Mon, 14 Sep 2020 14:24:40 -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: smtp13.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=none (p=nil; dis=none) header.from=greenie.muc.de X-Suspicious-Flag: YES X-Classification-ID: 8ce04ad0-f6b7-11ea-a1b9-5254004b83b1-1-1 Received: from [216.105.38.7] ([216.105.38.7:54454] helo=lists.sourceforge.net) by smtp13.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id D9/D1-04452-765BF5F5; Mon, 14 Sep 2020 14:24:39 -0400 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1kHt8j-0007aX-EO; Mon, 14 Sep 2020 18:23:45 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHt8h-0007aQ-N0 for openvpn-devel@lists.sourceforge.net; Mon, 14 Sep 2020 18:23:43 +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: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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=092BewQK7sgnCkl/X+gf+f9ymmSDcX5RUEAlb2dbKe4=; b=aNL7DnEj02tP4QWpFTFZrAX2YB lwk95nBUFLzeXNzWbmvrhWatq1OphL1CvYNI6xDBf276U5LgzAZBh9JSgn9Tu+Em0QdoEGkMRXCKZ k3jak33wfCgjAizfxnixbyKwF93b2Y0SJWof4JP0F+Uyr6Ouc4IqB+WIbcPnAaa4JhlM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version: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:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=092BewQK7sgnCkl/X+gf+f9ymmSDcX5RUEAlb2dbKe4=; b=Y gm2V0ukX/f8wKhu5lATZroTcfosBR5l2YDye4tyUNBPlPCvo/z6ADiI8aMWSLAdiJfBCbEKQjNHnN XopUJARUNwWXUG1LFNRwwgeIjgiIxwP6B3NqImvcB75vrzi+b4J+qcp81fd1Ybfw9XoNeKEU6mj9L PyusCqG/9GBUJHJQ=; Received: from chekov.greenie.muc.de ([193.149.48.178]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1kHt8b-008kvF-Ny for openvpn-devel@lists.sourceforge.net; Mon, 14 Sep 2020 18:23:43 +0000 Received: from chekov.greenie.muc.de (localhost [127.0.0.1]) by chekov.greenie.muc.de (8.15.2/8.15.2) with ESMTPS id 08EINNCc072015 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Mon, 14 Sep 2020 20:23:23 +0200 (CEST) (envelope-from gert@chekov.greenie.muc.de) Received: (from gert@localhost) by chekov.greenie.muc.de (8.15.2/8.15.2/Submit) id 08EINNSp072014 for openvpn-devel@lists.sourceforge.net; Mon, 14 Sep 2020 20:23:23 +0200 (CEST) (envelope-from gert) From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Mon, 14 Sep 2020 20:23:23 +0200 Message-Id: <20200914182323.71971-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: libres.ch] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-Headers-End: 1kHt8b-008kvF-Ny Subject: [Openvpn-devel] [PATCH] Fix netbits setting (in TAP mode) for IPv6 on Windows. 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 For TUN interfaces, the IPv6 address needs to be configured with "address/128" and a local subnet route is needed, pointing to our fake gateway fe80::8. There is no ethernet headers or ND outside the tun/tap interface, so anything but fe80::8 is not resolvable. For TAP interfaces, the proper subnet mask (netbits) must be configured, and no connected route to "our local host address" must be configured, to make make IPv6 ND work inside the local subnet. Our code was nicely consistent in doing the same thing in tun.c ("gui/openvpn running with admin privileges") and in the requests to the interactive service ("gui running with user privs"). Fix in both places. On tun close, symmetric to addition, remove the on-link subnet route only for "tun" interfaces. Address removal works without specifying netbits. While at it, extend do_address_service() to actually log both IPv4 and IPv6 addresses requested via it. Tested on Win10/64. Reported-By: Laurent Fasnacht Reported-By: Klara Mall Trac: #1054 Signed-off-by: Gert Doering --- src/openvpn/tun.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index fde94294..8b3a3b8a 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -115,11 +115,15 @@ do_address_service(const bool add, const short family, const struct tuntap *tt) { addr.address.ipv4.s_addr = htonl(tt->local); addr.prefix_len = netmask_to_netbits2(tt->adapter_netmask); + msg(D_ROUTE, "INET address service: %s %s/%d", add? "add": "remove", + print_in_addr_t(tt->local, 0, &gc), addr.prefix_len); } else { addr.address.ipv6 = tt->local_ipv6; - addr.prefix_len = tt->netbits_ipv6; + addr.prefix_len = (tt->type == DEV_TYPE_TUN)? 128: tt->netbits_ipv6; + msg(D_ROUTE, "INET6 address service: %s %s/%d", add? "add": "remove", + print_in6_addr(tt->local_ipv6, 0, &gc), addr.prefix_len); } if (!send_msg_iservice(pipe, &addr, sizeof(addr), &ack, "TUN")) @@ -1088,24 +1092,36 @@ do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu, else if (tt->options.msg_channel) { do_address_service(true, AF_INET6, tt); - add_route_connected_v6_net(tt, es); + if (tt->type == DEV_TYPE_TUN) + { + add_route_connected_v6_net(tt, es); + } do_dns_service(true, AF_INET6, tt); do_set_mtu_service(tt, AF_INET6, tun_mtu); } else { /* example: netsh interface ipv6 set address interface=42 - * 2001:608:8003::d store=active + * 2001:608:8003::d/bits store=active */ char iface[64]; + /* in TUN mode, we only simulate a subnet, so the interface + * is configured with /128 + a route to fe80::8. In TAP mode, + * the correct netbits must be set, and no on-link route + */ + int netbits = (tt->type == DEV_TYPE_TUN)? 128: tt->netbits_ipv6; + openvpn_snprintf(iface, sizeof(iface), "interface=%lu", tt->adapter_index); - argv_printf(&argv, "%s%s interface ipv6 set address %s %s store=active", + argv_printf(&argv, "%s%s interface ipv6 set address %s %s/%d store=active", get_win_sys_path(), NETSH_PATH_SUFFIX, iface, - ifconfig_ipv6_local); + ifconfig_ipv6_local, netbits); netsh_command(&argv, 4, M_FATAL); - add_route_connected_v6_net(tt, es); + if (tt->type == DEV_TYPE_TUN) + { + add_route_connected_v6_net(tt, es); + } /* set ipv6 dns servers if any are specified */ netsh_set_dns6_servers(tt->options.dns6, tt->options.dns6_len, ifname); windows_set_mtu(tt->adapter_index, AF_INET6, tun_mtu); @@ -6688,7 +6704,7 @@ netsh_delete_address_dns(const struct tuntap *tt, bool ipv6, struct gc_arena *gc netsh_command(&argv, 1, M_WARN); } - if (ipv6) + if (ipv6 && tt->type == DEV_TYPE_TUN) { delete_route_connected_v6_net(tt); }