From patchwork Mon May 28 23:55:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lev Stipakov X-Patchwork-Id: 335 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.27.255.51]) by backend30.mail.ord1d.rsapps.net (Dovecot) with LMTP id FKWhEMIjDVtRMwAAIUCqbw for ; Tue, 29 May 2018 05:56:18 -0400 Received: from proxy7.mail.iad3a.rsapps.net ([172.27.255.51]) by director10.mail.ord1d.rsapps.net (Dovecot) with LMTP id GY2UI8IjDVvNWQAApN4f7A ; Tue, 29 May 2018 05:56:18 -0400 Received: from smtp32.gate.iad3a ([172.27.255.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy7.mail.iad3a.rsapps.net with LMTP id eICSKcIjDVtJKQAAnPvY+A ; Tue, 29 May 2018 05:56:18 -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: smtp32.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; dkim=fail (signature verification failed) header.d=gmail.com; dmarc=fail (p=none; dis=none) header.from=gmail.com X-Suspicious-Flag: YES X-Classification-ID: 878585ea-6326-11e8-a347-5254001741cc-1-1 Received: from [216.105.38.7] ([216.105.38.7:35142] helo=lists.sourceforge.net) by smtp32.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 88/A4-27070-1C32D0B5; Tue, 29 May 2018 05:56:17 -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 1fNbLj-0001bs-CE; Tue, 29 May 2018 09:55:27 +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 1fNbLh-0001bk-Mf for openvpn-devel@lists.sourceforge.net; Tue, 29 May 2018 09:55:25 +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:Sender:Reply-To: MIME-Version:Content-Type:Content-Transfer-Encoding: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=fZklJQIeVMwLPevPC1b6IPmKGjT1xDSspLa0Zaq+qR8=; b=Y4VZAWWL2S0OzMLbST6fTJC3tY pD+rtoKuy1nzSpngEwpcE7QbSl85rJsvzogCQ8rsH9TxM9639FaIqt0u60UbkShkmMgJaUw49+xNc JlGNJvpKqjHTXzDBx3Cph1xJoRhch0ocOyl+lE0KVSuj4Pj7mr8pCZQ30yb7ZjFVDsMY=; 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:Sender:Reply-To:MIME-Version: Content-Type:Content-Transfer-Encoding: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=fZklJQIeVMwLPevPC1b6IPmKGjT1xDSspLa0Zaq+qR8=; b=TitvvbzTgF7ZozFT1Pw92q+BGj Me7iOAa+Vi826Z82cmxviyw6CNlCDZdbDKlOSnMFxQzAoww+X7O009urzuZvTVSKf0lDoxVkRtlmr OdhEdHgQydsb2etETt3mDS29N8WzVL9SU4KVf40Q6+CE9ZydGw3q4L0juSbFxpg0N+k0=; Received: from mail-wm0-f51.google.com ([74.125.82.51]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) id 1fNbLg-008VJj-53 for openvpn-devel@lists.sourceforge.net; Tue, 29 May 2018 09:55:25 +0000 Received: by mail-wm0-f51.google.com with SMTP id a67-v6so38593326wmf.3 for ; Tue, 29 May 2018 02:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=fZklJQIeVMwLPevPC1b6IPmKGjT1xDSspLa0Zaq+qR8=; b=PHl/r9HUgJ1jFoen8RQFeP2D+sD8lWHCUQf0eBzQlv2757OTv/zoMLw7jNqn0NgPqk fNNAoBjaK8BRopy+jLg4g1+BjbXKLcGwOMyccVpK8WSx84raVnq8BTxc+eahK18Y7k5k 3Xmzn1q/mwFqv5qK1q4AEu4LzOy6ziWcdgnV3Qfsj87brsLTQvs0ZCia+zLQuASgjYv9 rKAxEepTs4CUthKtd2LzbLCqmthKkJQW/8BSqxtYE5gk1sZ81bhKmw52pfg57zkBORiZ C35xWgBfg6aPjB97kSU8e+awpsqNoIOx14Blb/dZ4qaPswJq6VNTIT9OTxN3C1nWzpqO p1pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=fZklJQIeVMwLPevPC1b6IPmKGjT1xDSspLa0Zaq+qR8=; b=WsfCvr0o4U9OIvZF82IlqfLUoxkGvM7e6H3++1hHd/ot0Pmer1YDpABrWTxFJYT45x yTW8oTIecfqaeuIm+y6noZcgYzFxS9sf/JcQJY0SHQoG5mw/Q0MuUqiZcPmrUULtiDXl y/6vbIwc+1EfbkXtpq8i61m4WlTrgWOFa5upepmVoOjHUj4hxkyLVB60GIo+5pFRBp4D 3yfsdm8XfKrp6c97sdFJiIZfUGjU4JheudQzZaqqv4OMh5bgn6G85UmkMd9nZjSmc6Zj cipcGJWwJheTW2tX8uLAkVfQejWsLquLHHbnRqi1DfSozIcE8UlFVS2whr/SzuEQAtNU r4wg== X-Gm-Message-State: ALKqPweVlR7cNPwtDE/8u/YU/oo+Gs2gSM6AgsBz/hl4oqknPiGsOlU/ rpD7no3B/9E/1gUpyshV0CFBNMAg X-Google-Smtp-Source: ADUXVKJinae7H+J7KLfBukbTjGxT81bx8hY9hliEx1wId3uUUcoxczJE5irljC6Rq8/zX+FutQ520g== X-Received: by 2002:a2e:8759:: with SMTP id q25-v6mr10560014ljj.66.1527587717163; Tue, 29 May 2018 02:55:17 -0700 (PDT) Received: from localhost.localdomain ([93.174.198.226]) by smtp.gmail.com with ESMTPSA id a2-v6sm6270072ljd.18.2018.05.29.02.55.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 May 2018 02:55:16 -0700 (PDT) From: Lev Stipakov X-Google-Original-From: Lev Stipakov To: openvpn-devel@lists.sourceforge.net Date: Tue, 29 May 2018 12:55:07 +0300 Message-Id: <1527587707-21417-1-git-send-email-lev@openvpn.net> X-Mailer: git-send-email 2.7.4 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (lstipakov[at]gmail.com) -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [74.125.82.51 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.51 listed in wl.mailspike.net] -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.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-Headers-End: 1fNbLg-008VJj-53 Subject: [Openvpn-devel] [PATCH] Improve "recursive routing" warning 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: , Cc: Lev Stipakov MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox - print protocol, source/dest addresses and ports - mention "--allow-recursive-routing" - add possible usecase to manpage Trac #843 Signed-off-by: Lev Stipakov --- doc/openvpn.8 | 4 ++- src/openvpn/forward.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 86 insertions(+), 7 deletions(-) diff --git a/doc/openvpn.8 b/doc/openvpn.8 index 4114f40..262d4ea 100644 --- a/doc/openvpn.8 +++ b/doc/openvpn.8 @@ -4072,7 +4072,9 @@ notifications unless this option is enabled. .TP .B \-\-allow\-recursive\-routing When this option is set, OpenVPN will not drop incoming tun packets -with same destination as host. +with same destination as host. Could be useful when packets sent by openvpn +itself are not subject to the routing tables that would move packets +into the tunnel. .\"********************************************************* .SS Data Channel Encryption Options: These options are meaningful for both Static & TLS\-negotiated key modes diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 7d9a338..77a9084 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1068,7 +1068,7 @@ read_incoming_tun(struct context *c) /** * Drops UDP packets which OS decided to route via tun. * - * On Windows and OS X when netwotk adapter is disabled or + * On Windows and OS X when network adapter is disabled or * disconnected, platform starts to use tun as external interface. * When packet is sent to tun, it comes to openvpn, encapsulated * and sent to routing table, which sends it again to tun. @@ -1080,6 +1080,11 @@ drop_if_recursive_routing(struct context *c, struct buffer *buf) struct openvpn_sockaddr tun_sa; int ip_hdr_offset = 0; + uint32_t saddr, daddr; + struct in6_addr saddr6, daddr6; + uint16_t sport, dport; + uint8_t protocol; + if (c->c2.to_link_addr == NULL) /* no remote addr known */ { return; @@ -1105,12 +1110,38 @@ drop_if_recursive_routing(struct context *c, struct buffer *buf) return; } - pip = (struct openvpn_iphdr *) (BPTR(buf) + ip_hdr_offset); + pip = (const struct openvpn_iphdr *) (BPTR(buf) + ip_hdr_offset); - /* drop packets with same dest addr as gateway */ + /* drop packets with the same dest addr as gateway */ if (tun_sa.addr.in4.sin_addr.s_addr == pip->daddr) { drop = true; + + /* collect information for warning message */ + sport = 0; + dport = 0; + + saddr = ntohl(pip->saddr); + daddr = ntohl(pip->daddr); + protocol = pip->protocol; + + /* whole packet? */ + if (BLEN(buf) == (ip_hdr_offset + (int) (ntohs(pip->tot_len)))) + { + const uint8_t *payload = BPTR(buf) + ip_hdr_offset + sizeof(struct openvpn_iphdr); + + if (protocol == OPENVPN_IPPROTO_UDP) + { + const struct openvpn_udphdr *udp = (const struct openvpn_udphdr *) payload; + sport = ntohs(udp->source); + dport = ntohs(udp->dest); + } else if (protocol == OPENVPN_IPPROTO_TCP) + { + const struct openvpn_tcphdr *tcp = (const struct openvpn_tcphdr *) payload; + sport = ntohs(tcp->source); + dport = ntohs(tcp->dest); + } + } } } else if (proto_ver == 6) @@ -1129,22 +1160,68 @@ drop_if_recursive_routing(struct context *c, struct buffer *buf) return; } - /* drop packets with same dest addr as gateway */ + /* drop packets with the same dest addr as gateway */ pip6 = (struct openvpn_ipv6hdr *) (BPTR(buf) + ip_hdr_offset); if (IN6_ARE_ADDR_EQUAL(&tun_sa.addr.in6.sin6_addr, &pip6->daddr)) { drop = true; + + /* collect information for warning message */ + sport = 0; + dport = 0; + + saddr6 = pip6->saddr; + daddr6 = pip6->daddr; + protocol = pip6->nexthdr; + + /* whole packet? */ + if (BLEN(buf) == ((int) sizeof(struct openvpn_ipv6hdr) + ip_hdr_offset + (int) ntohs(pip6->payload_len))) + { + const uint8_t *payload = BPTR(buf) + ip_hdr_offset + sizeof(struct openvpn_ipv6hdr); + + if (protocol == OPENVPN_IPPROTO_UDP) + { + const struct openvpn_udphdr *udp = (const struct openvpn_udphdr *) payload; + sport = ntohs(udp->source); + dport = ntohs(udp->dest); + } else if (protocol == OPENVPN_IPPROTO_TCP) + { + const struct openvpn_tcphdr *tcp = (const struct openvpn_tcphdr *) payload; + sport = ntohs(tcp->source); + dport = ntohs(tcp->dest); + } + } } } if (drop) { struct gc_arena gc = gc_new(); + struct buffer addrs_buf = alloc_buf_gc(128, &gc); + /* drop packet */ c->c2.buf.len = 0; - msg(D_LOW, "Recursive routing detected, drop tun packet to %s", - print_link_socket_actual(c->c2.to_link_addr, &gc)); + if (protocol == OPENVPN_IPPROTO_UDP) + buf_printf(&addrs_buf, "%s", "UDP"); + else if (protocol == OPENVPN_IPPROTO_TCP) + buf_printf(&addrs_buf, "%s", "TCP"); + else + buf_printf(&addrs_buf, "%d", protocol); + + if (proto_ver == 4) + { + buf_printf(&addrs_buf, " %s:%d -> %s:%d", + print_in_addr_t(saddr, 0, &gc), sport, + print_in_addr_t(daddr, 0, &gc), dport); + } else if (proto_ver == 6) + { + buf_printf(&addrs_buf, " %s:%d -> %s:%d", + print_in6_addr(saddr6, 0, &gc), sport, + print_in6_addr(daddr6, 0, &gc), dport); + } + + msg(D_LOW, "Recursive routing detected, drop packet %s. Fix your routing or consider using --allow-recursive-routing option.", BSTR(&addrs_buf)); gc_free(&gc); } }