From owner-freebsd-pf@freebsd.org  Wed Apr  5 02:18:02 2017
Return-Path: <owner-freebsd-pf@freebsd.org>
Delivered-To: freebsd-pf@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id EC37BD2F11C
 for <freebsd-pf@mailman.ysv.freebsd.org>; Wed,  5 Apr 2017 02:18:02 +0000 (UTC)
 (envelope-from paul.g.webster@googlemail.com)
Received: from mail-yb0-x235.google.com (mail-yb0-x235.google.com
 [IPv6:2607:f8b0:4002:c09::235])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (Client CN "smtp.gmail.com",
 Issuer "Google Internet Authority G2" (verified OK))
 by mx1.freebsd.org (Postfix) with ESMTPS id B303322E
 for <freebsd-pf@freebsd.org>; Wed,  5 Apr 2017 02:18:02 +0000 (UTC)
 (envelope-from paul.g.webster@googlemail.com)
Received: by mail-yb0-x235.google.com with SMTP id l201so29391ybf.0
 for <freebsd-pf@freebsd.org>; Tue, 04 Apr 2017 19:18:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=googlemail.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to;
 bh=yQqWy3EPEuKNZlc5fvOOFN7hS/CvG+dEQdnSvEs0O4o=;
 b=V8aFhBLcDyxoAHdTD+fGJo3RYWkYFJjqRSDH3Vj4uT/+XkoEuMTAY7pyScFBztNHv8
 vH8AA8ya6iXhX1C8UruClAU2Hw6CJC86VOw4wvEVZ0wMNiQqO6uj1fIgdIZegxd/j0uR
 Vl/Gv6b3I/SDVA84gjcWe1Eu7FnRlSb1I918xMdJobtcaEAyZ55lsAtne31XZ0Vw+Zm5
 Zj4yeszogRu7Uj32MSHgN+0JlfBTsAV+1p8TzsuVKLwxqLekMu3nHals4T16PX9d7jRr
 wpvmW4+nVPdOLo+nGyYJZDFC5lYzBkWFyi6GDajA6emqqNLANRAAgGPKD8kcmR3ncVoV
 ENXQ==
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=yQqWy3EPEuKNZlc5fvOOFN7hS/CvG+dEQdnSvEs0O4o=;
 b=DEp6K2OUEv6esFvsI1TmppdGLlTmhexN6iUo+U5XioAuLJk9FemICcrojirM1AlEKI
 a+OtBMo8PCPodkiNhRj+XrUVVRfUIXHLrw1v6s4zDczQq6fzQy9rpDIjm1GcOc6+EPQX
 gb4lpqXyA047OJZ782wQovkbZFPggxoLIimRCoipIZh+j86bBsxkIiiO3kttkqfmvdlk
 Dbj2/EAAdg055t1YOHmnL1YgBQqKgNlOf7LismxF8Kirv3DpFSPXErXbH7Pxrwu331U7
 MUcvyBIrbL8P7OGIe5dPgTUXUseH//hBpm6lOqeEERH21dnuMzc4rq5tSxgFTEHx2yBA
 TF8Q==
X-Gm-Message-State: AFeK/H3ewjjc3bAVkl9PkFZxU5HucnQG0e+LlmaW4kZK97OsNco0LzY3VY3mZqYsQC7SAMMQWo0lWrZnUKus/Q==
X-Received: by 10.37.70.66 with SMTP id t63mr16715230yba.196.1491358681581;
 Tue, 04 Apr 2017 19:18:01 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.37.37.5 with HTTP; Tue, 4 Apr 2017 19:18:01 -0700 (PDT)
From: Paul Webster <paul.g.webster@googlemail.com>
Date: Wed, 5 Apr 2017 03:18:01 +0100
Message-ID: <CADdqeiOmW-kAi2q4yAGrQUvLshLZP3kRSTw7-segVJm7z6FONA@mail.gmail.com>
Subject: Complicated NAT setup
To: freebsd-pf@freebsd.org
Content-Type: text/plain; charset=UTF-8
X-Content-Filtered-By: Mailman/MimeDel 2.1.23
X-BeenThere: freebsd-pf@freebsd.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: "Technical discussion and general questions about packet filter
 \(pf\)" <freebsd-pf.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-pf>,
 <mailto:freebsd-pf-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-pf/>
List-Post: <mailto:freebsd-pf@freebsd.org>
List-Help: <mailto:freebsd-pf-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-pf>,
 <mailto:freebsd-pf-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Wed, 05 Apr 2017 02:18:03 -0000

Hey all I am having trouble with freebsd/pf and theattached config

my main issue is with the second nat; 'nat on $int_if from any to
($josh_if) -> $josh_xbox'

it seems to work for TCP inbound but not for UDP or ICMP I cannot see the
reason why; perhaps a binat rule would be better but I could never get it
quite working (in either direction)




# Macros
ext_if=igb0
int_if=igb1
localnet = "{ 172.31.33.2/32, ... lots of ips }"

josh_xbox="172.31.33.254"
josh_if="gre0"
josh_gateway="10.0.0.2"
josh_vpnhost="185.157.232.30"

tcp_services = "{ ssh, smtp, domain, www, pop3, auth, pop3s, 5901 }"
udp_services = "{ domain }"

# Global rules
set skip on lo0
scrub in all

# NAT and redirection
nat on $ext_if from $localnet to any -> ($ext_if)

# xBox redirection
nat on $josh_if from $josh_xbox to any -> ($josh_if)
nat on $int_if from any to ($josh_if) -> $josh_xbox

rdr-anchor "miniupnpd"

# Tables and sets
table <bruteforce> persist
table <blocked> persist

# Filtering rules (Quick first)

# Release GRE and QUICK release the protocol
pass in quick on $ext_if inet proto 47 from $josh_vpnhost to any no state
flags any
pass out quick on $ext_if inet proto 47 from any to $josh_vpnhost no state
flags any

# SSH, DNS, DHCP
block quick on $ext_if proto udp from any to any port 67
pass in quick on $int_if proto tcp from 172.31.33.1/24 to 172.31.33.1/32
port 22
pass in quick on $int_if proto {tcp,udp} from 172.31.33.1/24 to
172.31.33.1/32 port 53
pass in quick on $int_if proto udp from any to 172.31.33.1/32 port 63

# Pass out/in the xbox traffic (THIS MUST GO AFTER THE DNS RULES)
pass in quick on $int_if from $josh_xbox rtable 1       # Swap packets from
the xbox to fib1 routing table
pass in quick on $josh_if rtable 0