From patchwork Tue Oct 30 01:53:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lev Stipakov X-Patchwork-Id: 580 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director12.mail.ord1d.rsapps.net ([172.28.255.1]) by backend30.mail.ord1d.rsapps.net with LMTP id MHcWH4pV2FtLfgAAIUCqbw for ; Tue, 30 Oct 2018 08:58:50 -0400 Received: from director6.mail.ord1c.rsapps.net ([172.28.255.1]) by director12.mail.ord1d.rsapps.net with LMTP id gAULH4pV2FveDQAAIasKDg ; Tue, 30 Oct 2018 08:58:50 -0400 Received: from smtp25.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by director6.mail.ord1c.rsapps.net with LMTP id uG2JHopV2FvYCgAA5akwjA ; Tue, 30 Oct 2018 08:58:50 -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: smtp25.gate.ord1c.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: 8adf3772-dc43-11e8-9b11-b8ca3a673c88-1-1 Received: from [216.105.38.7] ([216.105.38.7:17811] helo=lists.sourceforge.net) by smtp25.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 63/5C-04315-98558DB5; Tue, 30 Oct 2018 08:58:50 -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 1gHTaf-0003Oc-HE; Tue, 30 Oct 2018 12:57:49 +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 1gHTae-0003OW-Hi for openvpn-devel@lists.sourceforge.net; Tue, 30 Oct 2018 12:57:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:To: From:Sender:Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: 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=RcHMYg4SoAt1l7G9XlKyxHNdJwAOPhN7x5AV9LPTIIA=; b=iQkCRdn8nKWEO7+szfD4/8hP04 WWswYIG0Uk5uEZ+5vX22xQWz3OqDMaDC9F5FmhVDiJz2t4EvtLqYz2/axQAX9lXvbJK9aI5500zFk JY9ayDyQYGl0YjWmKHEi6CJHIZXecN8oF3wGS8uUJZ0z4xmDpqFwlv2Tycaq4nu/Y3GM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc :MIME-Version:Content-Type:Content-Transfer-Encoding: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=RcHMYg4SoAt1l7G9XlKyxHNdJwAOPhN7x5AV9LPTIIA=; b=Yxsv/igsRHchUH4d9ddkSgdBII 0ZqippIW97gSocbxNg2T3RHkqM72n7OqC2pyFEkM0poa7JkORdLEYx6+XNCysF2GhXmGXzSl6Jiw5 N9xYWmTut+96grjBnLBqiFBnM2+pv1Te9M9mAbWH/1a99gvMmmmd1eSOxipt4Qc+vA5E=; Received: from mail-ed1-f65.google.com ([209.85.208.65]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) id 1gHTac-00Ey12-Vo for openvpn-devel@lists.sourceforge.net; Tue, 30 Oct 2018 12:57:48 +0000 Received: by mail-ed1-f65.google.com with SMTP id d6-v6so2294526edi.2 for ; Tue, 30 Oct 2018 05:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=RcHMYg4SoAt1l7G9XlKyxHNdJwAOPhN7x5AV9LPTIIA=; b=TdQealW65+qD1jrcZsisgeih+hGSK5I8H3Rd9A4ysBiviIk8Z5B2g9rJLt7PUzgmwT +dl1+NXygnBQ4M7QFrzL3jH5D2Fd8xwhfFUdZdS+OKWE77QjC2H518sYKb53DHj4dPlb a0ai+Fww15pwIBJXjHhnMc/kFf9RgmjejE7Gly/GI6kSpwXgiCzNYt784Q9lnKjxdcDk 8laJQ0SRuzQmkKEWbyh7HL38fzVPTlFeo+VY3iQqZ5zZzcWArFSwdXLcMkyU5jrCqxb+ ygTTflOk8+SyR5T+xNllcMtbmMq5UAL8d1+oEvGLviDOhPCFM30iOS1uu67Who45lwze R0CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=RcHMYg4SoAt1l7G9XlKyxHNdJwAOPhN7x5AV9LPTIIA=; b=pG7nXBJrkG8AbEFw/fG2iVWsanOfdE8C0zIKvmW1PD3SyS020F7MmKHGY4GVR77+Fv 3wLF+rQZGztxh9vtQqXSr2PleEsP7UgFLeLdhSXvSrw5jNpYlKmim01GY+fxNLcWE/jt JfnjiXiXr4xM4WWa3uOLVIdrE5XL7wcTxAyth+b7ESq/2TH/i0Ab3GBeBf/yxHWG98hQ kLM2awb+K8LXM4GVHC4YxSZpLMb4wz4cR/2wS4Hv3edN2hvMkGKQeMbHXdFYsNDe3ZS5 LOzfVP3FerZ0D5r63SjlmuOtQhYgPyH9mDM2vcKZsdeet3XhLGr7YCIBrhf/5rnv7Uj2 vAAg== X-Gm-Message-State: AGRZ1gIppo/SrW6Qse2meT8pXUrtztfOYE0k0CiGKKkacSBYT/AB//IV LiL2FtF8yjITNXX0a8NiI52J3L11hWM= X-Google-Smtp-Source: AJdET5evfXgCWP+5TWec6qvhKwttXILgHpRc0FOSnFmq98XuE9rpJC4acgMJTbBcMWWcSWUWUC2Wow== X-Received: by 2002:a50:ee91:: with SMTP id f17-v6mr17007240edr.136.1540904259802; Tue, 30 Oct 2018 05:57:39 -0700 (PDT) Received: from stipakov.fi (stipakov.fi. [128.199.52.117]) by smtp.gmail.com with ESMTPSA id o13-v6sm4255806ejb.34.2018.10.30.05.57.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Oct 2018 05:57:38 -0700 (PDT) From: Lev Stipakov To: openvpn-devel@lists.sourceforge.net Date: Tue, 30 Oct 2018 14:53:59 +0200 Message-Id: <1540904039-2129-1-git-send-email-lstipakov@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1538820128-27086-1-git-send-email-lstipakov@gmail.com> References: <1538820128-27086-1-git-send-email-lstipakov@gmail.com> 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_MSPIKE_H2 RBL: Average reputation (+2) [209.85.208.65 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.208.65 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_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1gHTac-00Ey12-Vo Subject: [Openvpn-devel] [PATCH v4] Improve "recursive routing" warning message 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 From: Lev Stipakov This patch provides additional information, such as source address/port and destination address/port, to a "recursive routing" warning message. It also mentiones possible workaround. Trac #843 Signed-off-by: Lev Stipakov --- v4: - remove unneeded format specifier for const string v3: - factor out ports extraction code into own function to avoid code duplication - better commit message v2: - print protocol, source/dest addresses and ports - mention "--allow-recursive-routing" - add possible usecase to manpage doc/openvpn.8 | 4 ++- src/openvpn/forward.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 93 insertions(+), 9 deletions(-) diff --git a/doc/openvpn.8 b/doc/openvpn.8 index 94b5cc4..fb9eb84 100644 --- a/doc/openvpn.8 +++ b/doc/openvpn.8 @@ -4090,7 +4090,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 f8faa81..e96c546 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1291,10 +1291,42 @@ read_incoming_tun(struct context *c) perf_pop(); } +/* + * Extracts sport and dport from packet, used + * in recursive routing warning. + */ +static void +extract_sport_dport(const struct buffer *buf, uint8_t protocol, int offset_to_payload, int packet_len, uint16_t *sport, uint16_t *dport) +{ + /* whole packet? */ + if (BLEN(buf) == packet_len) + { + const uint8_t *payload = BPTR(buf) + offset_to_payload; + + 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 + { + *sport = 0; + *dport = 0; + } +} + /** * 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. @@ -1306,6 +1338,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; @@ -1320,7 +1357,7 @@ drop_if_recursive_routing(struct context *c, struct buffer *buf) const struct openvpn_iphdr *pip; /* make sure we got whole IP header */ - if (BLEN(buf) < ((int) sizeof(struct openvpn_iphdr) + ip_hdr_offset)) + if (BLEN(buf) < ((int)sizeof(struct openvpn_iphdr) + ip_hdr_offset)) { return; } @@ -1331,12 +1368,21 @@ 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 */ + + saddr = ntohl(pip->saddr); + daddr = ntohl(pip->daddr); + protocol = pip->protocol; + + extract_sport_dport(buf, protocol, ip_hdr_offset + sizeof(struct openvpn_iphdr), + ip_hdr_offset + (int)(ntohs(pip->tot_len)), &sport, &dport); } } else if (proto_ver == 6) @@ -1344,7 +1390,7 @@ drop_if_recursive_routing(struct context *c, struct buffer *buf) const struct openvpn_ipv6hdr *pip6; /* make sure we got whole IPv6 header */ - if (BLEN(buf) < ((int) sizeof(struct openvpn_ipv6hdr) + ip_hdr_offset)) + if (BLEN(buf) < ((int)sizeof(struct openvpn_ipv6hdr) + ip_hdr_offset)) { return; } @@ -1355,22 +1401,58 @@ 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 */ + + saddr6 = pip6->saddr; + daddr6 = pip6->daddr; + protocol = pip6->nexthdr; + + extract_sport_dport(buf, protocol, ip_hdr_offset + sizeof(struct openvpn_ipv6hdr), + (int)sizeof(struct openvpn_ipv6hdr) + ip_hdr_offset + (int)ntohs(pip6->payload_len), + &sport, &dport); } } 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, "UDP"); + } + else if (protocol == OPENVPN_IPPROTO_TCP) + { + buf_printf(&addrs_buf, "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); } }