From patchwork Tue Jul 17 00:56:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi-Hung Wei X-Patchwork-Id: 944634 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hwtvQTys"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41V25x60Yqz9s0n for ; Tue, 17 Jul 2018 11:01:09 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 1EDA1C94; Tue, 17 Jul 2018 00:59:50 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id B91A9BD1 for ; Tue, 17 Jul 2018 00:59:47 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 3E3EA6D6 for ; Tue, 17 Jul 2018 00:59:47 +0000 (UTC) Received: by mail-pf0-f196.google.com with SMTP id k21-v6so2243400pff.11 for ; Mon, 16 Jul 2018 17:59:47 -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:in-reply-to:references; bh=GaDnhg396vE+x+i3YWo/jcrueq6Jk67nhgAtTia+RBc=; b=hwtvQTysNEkQKyUwnJZIIp58KFpR93HwRRnALMgJ01uXpL3BXSZLLt4H05f7ZJY3Sc zz+t0UtL/Nlx5MuZS5yKFtPlAT2JcnYc5ADfo/jRkTob8YSS5FK3yA/x8U3R+uamNFfU +RfM7M2UJtenm5OJYPeE2ds5XWr5MVbYyRAOMSHapLiBY3fP2nEwHRcrwdre6D2hC3kh lE8GcS1QeMKofNW/NDVglEY+oUbddij/qOXKMq2jPDiFFF2KCTXenpu3V93ZP2trim8w 5B/NxitKpf8VHLC3dr5K8nmnUqLSyvVtW9Yy19i30m3zVjWSpBG11o6tDUZHWPd0SFr2 1Apw== 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:in-reply-to :references; bh=GaDnhg396vE+x+i3YWo/jcrueq6Jk67nhgAtTia+RBc=; b=Oc4C3wMrBOBTk/MchwsucsuvlSdBHodQnaqWcmN0KbwqFYbtLOE1KNfP6pWy+bqPZN 5khknJxTNuZFI3j3MmBnFL3c/xR82LarSVw0ctVZZbroTI5SZeENLsOg/sf39s5++z/A RuySSWLHzesOo4GN/hn7mWOtIxk+inuleo5e706AizmlSptvplYD8dTWSG1jDrf5QAaE hW1g3GwRIFtbmlStdC279EVJ6MO7039xRUoIERj8OQLMjOmjxgaV4ABpmigA4Oqy4V3n vCNXbpcLq26rrHrbj+8ov4LiROqhTm2BrpASvPNKBTvovgqPYmm4nbSSH1GU4eZTVK71 CnEA== X-Gm-Message-State: AOUpUlGPE3H8GJ2CVgio1SlxvhTCwLSSHgjmplW9ayd0zewjnJTJr/S6 4u2Ic/Vfk2VLxM43dya0tdVoqyzX X-Google-Smtp-Source: AAOMgpffHICYKTl+s3/1rz8jYKcVVRM7uRyJPQvmYGfeknJ05aMcnMzC8MWFeOtknLpc7vEtVbLlUg== X-Received: by 2002:a63:5964:: with SMTP id j36-v6mr6260636pgm.222.1531789186268; Mon, 16 Jul 2018 17:59:46 -0700 (PDT) Received: from Husky.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id x2-v6sm69932461pfi.166.2018.07.16.17.59.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Jul 2018 17:59:44 -0700 (PDT) From: Yi-Hung Wei To: dev@openvswitch.org Date: Mon, 16 Jul 2018 17:56:00 -0700 Message-Id: <1531788961-46115-4-git-send-email-yihung.wei@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531788961-46115-1-git-send-email-yihung.wei@gmail.com> References: <1531788961-46115-1-git-send-email-yihung.wei@gmail.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 3/4] datapath: NAT support for shifted portmap ranges X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org This patch backports the following upstream commit from net-next, and defines HAVE_NF_NAT_RANGE2 to determine whether to use 'struct nf_nat_range2'. Upstream commit: commit 2eb0f624b709e78ec8e2f4c3412947703db99301 Author: Thierry Du Tre Date: Wed Apr 4 15:38:22 2018 +0200 netfilter: add NAT support for shifted portmap ranges This is a patch proposal to support shifted ranges in portmaps. (i.e. tcp/udp incoming port 5000-5100 on WAN redirected to LAN 192.168.1.5:2000-2100) Currently DNAT only works for single port or identical port ranges. (i.e. ports 5000-5100 on WAN interface redirected to a LAN host while original destination port is not altered) When different port ranges are configured, either 'random' mode should be used, or else all incoming connections are mapped onto the first port in the redirect range. (in described example WAN:5000-5100 will all be mapped to 192.168.1.5:2000) This patch introduces a new mode indicated by flag NF_NAT_RANGE_PROTO_OFFSET which uses a base port value to calculate an offset with the destination port present in the incoming stream. That offset is then applied as index within the redirect port range (index modulo rangewidth to handle range overflow). In described example the base port would be 5000. An incoming stream with destination port 5004 would result in an offset value 4 which means that the NAT'ed stream will be using destination port 2004. Other possibilities include deterministic mapping of larger or multiple ranges to a smaller range : WAN:5000-5999 -> LAN:5000-5099 (maps WAN port 5*xx to port 51xx) This patch does not change any current behavior. It just adds new NAT proto range functionality which must be selected via the specific flag when intended to use. A patch for iptables (libipt_DNAT.c + libip6t_DNAT.c) will also be proposed which makes this functionality immediately available. Signed-off-by: Thierry Du Tre Signed-off-by: Pablo Neira Ayuso Signed-off-by: Yi-Hung Wei Reviewed-by: Greg Rose --- acinclude.m4 | 1 + datapath/conntrack.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index ae8e66fc4967..c6d18611f596 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -619,6 +619,7 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [ [nf_conn_labels], [words]) OVS_GREP_IFELSE([$KSRC/include/net/netfilter/nf_nat.h], [nf_ct_nat_ext_add]) OVS_GREP_IFELSE([$KSRC/include/net/netfilter/nf_nat.h], [nf_nat_alloc_null_binding]) + OVS_GREP_IFELSE([$KSRC/include/net/netfilter/nf_nat.h], [nf_nat_range2]) OVS_GREP_IFELSE([$KSRC/include/net/netfilter/nf_conntrack_seqadj.h], [nf_ct_seq_adjust]) OVS_GREP_IFELSE([$KSRC/include/linux/random.h], [prandom_u32]) diff --git a/datapath/conntrack.c b/datapath/conntrack.c index e53b8e32b3f5..42c7929055f0 100644 --- a/datapath/conntrack.c +++ b/datapath/conntrack.c @@ -41,6 +41,10 @@ #include "flow_netlink.h" #include "gso.h" +#ifndef HAVE_NF_NAT_RANGE2 +#define nf_nat_range2 nf_nat_range +#endif + struct ovs_ct_len_tbl { int maxlen; int minlen; @@ -79,7 +83,7 @@ struct ovs_conntrack_info { struct md_mark mark; struct md_labels labels; #ifdef CONFIG_NF_NAT_NEEDED - struct nf_nat_range range; /* Only present for SRC NAT and DST NAT. */ + struct nf_nat_range2 range; /* Only present for SRC NAT and DST NAT. */ #endif }; @@ -744,7 +748,7 @@ static bool skb_nfct_cached(struct net *net, */ static int ovs_ct_nat_execute(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info ctinfo, - const struct nf_nat_range *range, + const struct nf_nat_range2 *range, enum nf_nat_manip_type maniptype) { int hooknum, nh_off, err = NF_ACCEPT;