<div dir="ltr">If I recall correctly your step 5 is where things matter - make sure at that point (basically after nat POSTROUTING) that the traffic source/dest matches your left/rightsubnets.  Don't worry about the routing decision (your step 3).  You should only need one DNAT and one SNAT for your traffic.<div><br></div><div>-Bryan</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 6, 2015 at 9:36 AM, Tormod Macleod <span dir="ltr"><<a href="mailto:TMacleod@paywizard.com" target="_blank">TMacleod@paywizard.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div style="FONT:10pt Segoe UI;MARGIN:4px 4px 1px">
<div>Hello,</div>
<div> </div>
<div>I'm currently testing a site to site VPN. I need to change both the source and destination address on the left device before forwarding the packets over the VPN to the right device. I believe it all happens in the order below but I may be wrong.</div>
<div> </div>
<div>1 IPTables Prerouting</div>
<div>2 Route selected</div>
<div>3 A determination is made on whether the packets should be encapsulated with IPSec</div>
<div>4 IPTables Postrouting</div>
<div>5 Packets are encapsultaed with IPSec where applicable</div>
<div>6 Packets are forwarded</div>
<div> </div>
<div>I believe I have a solution but I'm not sure whether it's the best and I'd welcome some ideas...</div>
<div> </div>
<div>In order to have the traffic encapsulated I had to create two child SAs on the left side. The first has the original source address and the translated destination address. This is only used in step 3. In step 4 the destination address is translated and by the time it gets to step 5 the traffic source and destination addresses match that of the second child SA which also matches the single child SA on the right side.</div>
<div> </div>
<div>I'm concerned that I might run into some problems with this approach that I have not yet foreseen.</div>
<div> </div>
<div>Here's my config...</div>
<div> </div>
<div><font face="Courier New">config setup<br>        # strictcrlpolicy=yes<br>        # uniqueids=no</font></div>
<div><font face="Courier New"></font> </div>
<div><font face="Courier New">conn %default<br>        ikelifetime=1440m<br>        keylife=60m<br>        margintime=3m<br>        keyingtries=5<br>        keyexchange=ikev2<br>        authby=secret<br>        left=10.180.0.12<br>        leftid=2.2.2.2<br>        auto=start<br>        ike=aes128-md5-modp1536<br>        esp=aes128-sha1<br>        reauth=no<br>        dpdaction=hold<br>        dpddelay=40</font></div>
<div><font face="Courier New"></font> </div>
<div><font face="Courier New">conn SecurityAssociation-1<br>        leftsubnet=<a href="http://10.176.0.0/13" target="_blank">10.176.0.0/13</a><br>        right=3.3.3.3<br>        rightsubnet=<a href="http://192.168.0.0/16" target="_blank">192.168.0.0/16</a><br>        rightid=3.3.3.3</font></div>
<div><font face="Courier New"></font> </div>
<div><font face="Courier New">conn SecurityAssociation-2<br>        leftsubnet=<a href="http://1.1.1.0/24" target="_blank">1.1.1.0/24</a><br>        right=3.3.3.3<br>        rightsubnet=<a href="http://192.168.0.0/16" target="_blank">192.168.0.0/16</a><br>        rightid=3.3.3.3</font></div>
<div> </div>
<div> </div>
<div>Here's the statusall...</div>
<div> </div>
<div><font face="Courier New">[root@localhost ~]# /opt/strongswan522/sbin/ipsec statusall<br>Status of IKE charon daemon (strongSwan 5.2.2, Linux 2.6.32-504.12.2.el6.x86_64, x86_64):<br>  uptime: 3 days, since Apr 03 14:47:09 2015<br>  malloc: sbrk 270336, mmap 0, used 210768, free 59568<br>  worker threads: 11 of 16 idle, 5/0/0/0 working, job queue: 0/0/0/0, scheduled: 4<br>  loaded plugins: charon aes des rc2 sha1 sha2 md5 random nonce x509 revocation constraints pubkey pkcs1 pkcs7 pkcs8 pkcs12 pgp dnskey sshkey pem fips-prf gmp xcbc cmac hmac attr kernel-netlink resolve socket-default stroke updown xauth-generic unity<br>Listening IP addresses:<br>  10.180.0.12<br>Connections:<br>SecurityAssociation-1:  10.180.0.12...3.3.3.3  IKEv2, dpddelay=40s<br>SecurityAssociation-1:   local:  [2.2.2.2] uses pre-shared key authentication<br>SecurityAssociation-1:   remote: [3.3.3.3] uses pre-shared key authentication<br>SecurityAssociation-1:   child:  <a href="http://10.176.0.0/13" target="_blank">10.176.0.0/13</a> === <a href="http://192.168.0.0/16" target="_blank">192.168.0.0/16</a> TUNNEL, dpdaction=hold<br>SecurityAssociation-2:   child:  <a href="http://1.1.1.0/24" target="_blank">1.1.1.0/24</a> === <a href="http://192.168.0.0/16" target="_blank">192.168.0.0/16</a> TUNNEL, dpdaction=hold<br>Security Associations (1 up, 0 connecting):<br>SecurityAssociation-1[4]: ESTABLISHED 41 minutes ago, 10.180.0.12[2.2.2.2]...3.3.3.3[3.3.3.3]<br>SecurityAssociation-1[4]: IKEv2 SPIs: 75498cd903d39dfa_i* 9dca56ab7071039a_r, rekeying in 23 hours<br>SecurityAssociation-1[4]: IKE proposal: AES_CBC_128/HMAC_MD5_96/PRF_HMAC_SHA1/MODP_1536<br>SecurityAssociation-2{2}:  INSTALLED, TUNNEL, ESP in UDP SPIs: cb5e661f_i 9add0a95_o<br>SecurityAssociation-2{2}:  AES_CBC_128/HMAC_SHA1_96, 0 bytes_i, 0 bytes_o, rekeying in 48 minutes<br>SecurityAssociation-2{2}:   <a href="http://1.1.1.0/24" target="_blank">1.1.1.0/24</a> === <a href="http://192.168.0.0/16" target="_blank">192.168.0.0/16</a></font> <br></div>
<div>And here's the IPTABLES commands I used to send traffic both ways...</div>
<div> </div>
<div><font face="Courier New">  iptables -t nat -A PREROUTING -p tcp -s <a href="http://10.176.0.10/32" target="_blank">10.176.0.10/32</a> -d <a href="http://10.180.0.12/32" target="_blank">10.180.0.12/32</a> --dport 61001 -j DNAT --to-destination <a href="http://192.168.1.1:23" target="_blank">192.168.1.1:23</a><br>  iptables -t nat -A POSTROUTING -s <a href="http://10.176.0.10/32" target="_blank">10.176.0.10/32</a> -d <a href="http://192.168.1.1/32" target="_blank">192.168.1.1/32</a> -j SNAT --to-source 1.1.1.2<br>  iptables -t nat -A PREROUTING -p tcp -s <a href="http://192.168.1.1/32" target="_blank">192.168.1.1/32</a> -d <a href="http://1.1.1.3/32" target="_blank">1.1.1.3/32</a> --dport 61002 -j DNAT --to-destination <a href="http://10.176.0.10:23" target="_blank">10.176.0.10:23</a><br>  iptables -t nat -A POSTROUTING -s <a href="http://192.168.1.1/32" target="_blank">192.168.1.1/32</a> -d <a href="http://10.176.0.10/32" target="_blank">10.176.0.10/32</a> -j SNAT --to-source 10.180.0.12<br></font></div>
<div>It's a bit convoluted but it works. I'd love to know if someone has a better idea.</div>
<div> </div>
<div>Cheers,</div>
<div> </div>
<div> </div>
<div><font face="Courier New"><font face="Segoe UI">Tormod</font></font></div><br>

    <div>
      <div>
        <div>
          <font face="Arial" color="#008000">Please consider the 
          environment before printing this email</font><font face="Arial">
</font>        </div>
      </div>
    </div>
    <div>
      <font face="Arial">
</font>    </div>
    <span><font face="Arial">*********************************************************************
</font></span><font face="Arial"><br><span><br>This 
    e-mail and any attachments are confidential.  If it is not for you, please 
    inform us and delete it immediately without disclosing, copying, or 
    distributing it.<br><br>If the content is not about the business of 
    PayWizard Group PLC or its clients, then it is neither from nor sanctioned 
    by PayWizard Group PLC.  Use of this or any other PayWizard Group PLC 
    e-mail facility signifies consent to interception by PayWizard Group PLC.  
    The views expressed in this email or any attachments may not reflect the 
    views and opinions of PayWizard Group PLC.<br><br>This message has been 
    scanned for viruses and dangerous content by MailScanner, but PayWizard 
    Group PLC accepts no liability for any damage caused by the transmission 
    of any viruses.<br><br>PayWizard Group PLC is a public limited company 
    registered in Scotland (SC175703) with its registered office at Cluny 
    Court, John Smith Business Park, Kirkcaldy, Fife, KY2 6QJ.<br><br>*******************************************************************</span>*</font>
  <br><span class="HOEnZb"><font color="#888888">-- 
<br>This message has been scanned for viruses and
<br>dangerous content by
<a href="http://www.mailscanner.info/" target="_blank"><b>MailScanner</b></a>, and is
<br>believed to be clean.
</font></span></div>
<br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.strongswan.org">Users@lists.strongswan.org</a><br>
<a href="https://lists.strongswan.org/mailman/listinfo/users" target="_blank">https://lists.strongswan.org/mailman/listinfo/users</a><br></blockquote></div><br></div>