From patchwork Sun Sep 13 15:23:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael Gava X-Patchwork-Id: 1445 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id QAdoGVLGXl9KUQAAIUCqbw (envelope-from ) for ; Sun, 13 Sep 2020 21:24:34 -0400 Received: from proxy5.mail.ord1d.rsapps.net ([172.30.191.6]) by director10.mail.ord1d.rsapps.net with LMTP id 2PRfGVLGXl/PGAAApN4f7A (envelope-from ) for ; Sun, 13 Sep 2020 21:24:34 -0400 Received: from smtp28.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy5.mail.ord1d.rsapps.net with LMTPS id EB4nGVLGXl9UYQAA8Zzt7w (envelope-from ) for ; Sun, 13 Sep 2020 21:24:34 -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: smtp28.gate.ord1d.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: 0b8cbef2-f629-11ea-ad3b-525400ea129b-1-1 Received: from [216.105.38.7] ([216.105.38.7:37582] helo=lists.sourceforge.net) by smtp28.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 59/BA-20408-156CE5F5; Sun, 13 Sep 2020 21:24:34 -0400 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1kHdDa-000792-H7; Mon, 14 Sep 2020 01:23:42 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHdDY-00078t-MN for openvpn-devel@lists.sourceforge.net; Mon, 14 Sep 2020 01:23:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:To:Subject:Message-ID:Date:From: MIME-Version:Sender:Reply-To:Cc: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=8beVJc8H/DqLoBkBN7pBuLE0p3YwsYSMV6nNeRg3TaA=; b=cx6wfYM+eQfo1XBV1B5MgXHm0M 2TB3Z6nNokqxTLmpkrFeTWIkA8M9KxZG/bjbFKZeL7rkcJhBdw4DqPfiedRBudUlQZWwdrapi2gFF K+NDHrD1b0FSVz3QtM5f3rT7Cz3ec/pS1Vc9CpItL2jym9crvftZm6PqzHekVmnhQKNg=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:To:Subject:Message-ID:Date:From:MIME-Version:Sender:Reply-To :Cc: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=8beVJc8H/DqLoBkBN7pBuLE0p3YwsYSMV6nNeRg3TaA=; b=K 1fqPAHDPYXZ8LpDNfDbAEmQIXd2Oxqv+lY5JS8qzyjHFGgj8JjYL9K50hY7cQy1+jE9ojbYSVwrLq +A6pCPN//47hQP9MT/gn5OJclKTsFnTP2sQUEjRD6/ejzSD9VPN7iTCsuaCyQpCHy/Hp8fyeedJD9 PB85vbaehSlwTzQI=; Received: from mail-io1-f53.google.com ([209.85.166.53]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.2) id 1kHdDR-007lgH-Md for openvpn-devel@lists.sourceforge.net; Mon, 14 Sep 2020 01:23:40 +0000 Received: by mail-io1-f53.google.com with SMTP id b6so18093783iof.6 for ; Sun, 13 Sep 2020 18:23:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=8beVJc8H/DqLoBkBN7pBuLE0p3YwsYSMV6nNeRg3TaA=; b=pBvAoOuCtEFER4b3GoRayJcQwuX9aLf4ob0nkMOlvA1ggKElmrRNtoE7ebzTnRXitu U321X7lGxy21b8LynhGmU23tgoLvKU+CVKx2MwInoe1LAqoTJckjbeVzHHIwPfJrlvO4 I4HcSvol/jvZIKcoKnpFpcgIF3RhbxP+v6ifvr1x1APgJL1ub9qFVYLFE8oYRLxLHF2/ ZNwAKQEUc2q/svDO1umyO/BfP+aodtQWU0jg3amWSnpFYac7njHAgx7TCGxx86XM66G2 9uuzZzhnv/zaE+1GlDjeITkWlOe7eyBhkDfaixkaUTLs1aXb5iM+aONdJsBQZf+cBUNj IKKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=8beVJc8H/DqLoBkBN7pBuLE0p3YwsYSMV6nNeRg3TaA=; b=s60lwHF5Fysd4qlX8H8r/29VbpfEUjlb9hbJIXndEWzYHvrkiJiGh+Iipds4pQSl8z p5S9CiLdSsrKKnR2tKBHNt9XMXezoeZSFrfRu8XNEpieQwLMXProuCFr8bDUBMazIJil 2KidiyKwYNoYysqSQYETQf04/RZAmts40XDAV5hXSUx9J7heZvK8wj9vkmyJIGwUjLQq VbSq44Ps5o+iXwUdYBmz1ACflgH3g14TMnDzpmyjz43+SWqEWou7A15PkGUNyZIr5zRY RZ8Skyv4DajgX3IElkjWLxMS20KWNWHN6EwOjGuLSPIo3UZcDyhK6zNwRhsVivjymfKX MZLQ== X-Gm-Message-State: AOAM531cFjOKb2+07Fy3HBooC5c54yE/9odHgh+UarAiRCCSch962XWf QsUSD+8e4OXagfXoAfJ+AZYq12Drn53HVi1EL7NcRv9J8fc= X-Google-Smtp-Source: ABdhPJzn9mUeN/J3Jq4lh6TqF170RrT8QHTuPiEaq3RYnw0mTDVINLf8M7fjbC5Po2fQ53jEkUJ/SH37NHLKAxcrJGA= X-Received: by 2002:a05:6638:3b5:: with SMTP id z21mr11228677jap.33.1600046607734; Sun, 13 Sep 2020 18:23:27 -0700 (PDT) MIME-Version: 1.0 From: Rafael Gava Date: Sun, 13 Sep 2020 22:23:16 -0300 Message-ID: To: openvpn-devel 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 (gava100[at]gmail.com) -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.166.53 listed in list.dnswl.org] 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: venturus.org.br] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.166.53 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (gava100[at]gmail.com) 1.0 HTML_MESSAGE BODY: HTML included in message -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 X-Headers-End: 1kHdDR-007lgH-Md Subject: [Openvpn-devel] NAT client-ip 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 Hello guys, A couple years ago I submitted this patch which allows the user to set the 'client-ip' as a convenient way to use the leased IP address received from OpenVPN server in NAT configuration. For example: client-nat snat client-ip 255.255.255.255 172.20.1.15 , where 'client-ip' string is replaced with the leased IP address received from OpenVPN server. At that time, it was NACKED due to the fact that I was using both client-ip and localhost strings. So, it's changed now and I'd like to re-submit it again for appreciation. Thanks Gava ------------------------------------- From e273b13bc10da8f917a981957cf2c43ba6bd1e10 Mon Sep 17 00:00:00 2001 From: Rafael Gava de Oliveira Date: Sat, 12 Sep 2020 19:27:25 -0300 Subject: [PATCH] Allows the usage of the string 'client-ip' in the client-nat network configuration in a way that is not necessary to inform the IP address beforehand. Openvpn will dynamically set the received IP from DHCP. Example: client-nat snat client-ip 255.255.255.255 172.20.1.15 Replaces the 'client-ip' string with the DHCP address received from the openvpn server. --- src/openvpn/clinat.c | 45 ++++++++++++++++++++++++++++++++++++++++----- src/openvpn/clinat.h | 2 ++ src/openvpn/init.c | 2 ++ src/openvpn/options.c | 2 +- 4 files changed, 45 insertions(+), 6 deletions(-) mode change 100644 => 100755 src/openvpn/clinat.c "--setenv name value : Set a custom environmental variable to pass to script.\n" "--setenv FORWARD_COMPATIBLE 1 : Relax config file syntax checking to allow\n" diff --git a/src/openvpn/clinat.c b/src/openvpn/clinat.c old mode 100644 new mode 100755 index b08fd54..865b0e2 --- a/src/openvpn/clinat.c +++ b/src/openvpn/clinat.c @@ -128,12 +128,16 @@ add_client_nat_to_option_list(struct client_nat_option_list *dest, msg(msglevel, "client-nat: type must be 'snat' or 'dnat'"); return; } - - e.network = getaddr(0, network, 0, &ok, NULL); - if (!ok) + if (network && !strcmp(network, "client-ip")) { - msg(msglevel, "client-nat: bad network: %s", network); - return; + e.network = 0xFFFFFFFF; + } else { + e.network = getaddr(0, network, 0, &ok, NULL); + if (!ok) + { + msg(msglevel, "client-nat: bad network: %s", network); + return; + } } e.netmask = getaddr(0, netmask, 0, &ok, NULL); if (!ok) @@ -276,3 +280,34 @@ client_nat_transform(const struct client_nat_option_list *list, } } } + +/* +* Replaces the client-ip token with the IP received from OpenVPN Server +*/ +bool +update_client_ip_nat(struct client_nat_option_list *dest, in_addr_t local_ip) +{ + int i; + bool ret = false; + + if (!dest) + return ret; + + for (i=0; i <= dest->n; i++) + { + struct client_nat_entry *nat_entry = &dest->entries[i]; + if (nat_entry && nat_entry->network == 0xFFFFFFFF) + { + struct in_addr addr; + + nat_entry->network = ntohl(local_ip); + addr.s_addr = nat_entry->network; + char *dot_ip = inet_ntoa(addr); + + msg (M_INFO, "Updating NAT table client-ip to: %s", dot_ip); + ret = true; + } + } + + return ret; +} diff --git a/src/openvpn/clinat.h b/src/openvpn/clinat.h index eec7a03..c2941b9 100644 --- a/src/openvpn/clinat.h +++ b/src/openvpn/clinat.h @@ -64,4 +64,6 @@ void client_nat_transform(const struct client_nat_option_list *list, struct buffer *ipbuf, const int direction); +bool update_client_ip_nat(struct client_nat_option_list *dest, in_addr_t local_ip); + #endif /* if !defined(CLINAT_H) */ diff --git a/src/openvpn/init.c b/src/openvpn/init.c index a785934..8d6f9a8 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -1920,6 +1920,8 @@ do_open_tun(struct context *c) SET_MTU_TUN | SET_MTU_UPPER_BOUND); } + update_client_ip_nat(c->options.client_nat, c->c1.tuntap->local); + ret = true; static_context = c; #ifndef TARGET_ANDROID diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 8bf82c5..26f11fa 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -231,7 +231,7 @@ static const char usage_message[] = " ICMPv6 host unreachable messages on the client.\n" " (Server) Instead of forwarding IPv6 packets send\n" " ICMPv6 host unreachable packets to the client.\n" - "--client-nat snat|dnat network netmask alias : on client add 1-to-1 NAT rule.\n" + "--client-nat snat|dnat network|'client-ip' netmask alias : on client add 1-to-1 NAT rule.\n" "--push-peer-info : (client only) push client info to server.\n"