nat: prevent creation when-resolved static mappings on errors 63/18963/5
authorAlexander Chernavin <achernavin@netgate.com>
Wed, 17 Apr 2019 08:38:04 +0000 (04:38 -0400)
committerOle Trøan <otroan@employees.org>
Fri, 26 Apr 2019 11:19:07 +0000 (11:19 +0000)
When you create two identical NAT44 static mappings using interface
name as external address and only local or ext port is different,
VALUE_EXIST will be raised but when-resolved static mapping will
remain.

vpp# nat44 add static mapping tcp local 10.128.0.129 443 external GigabitEthernet0/8/0 8443
vpp# nat44 add static mapping tcp local 10.128.0.129 80 external GigabitEthernet0/8/0 8443
nat44 add static mapping: Mapping already exist.
vpp# show nat44 static mappings
NAT44 static mappings:
 tcp local 10.128.0.129:443 external 2.2.2.2:8443 vrf 0
 tcp local 10.128.0.129:443 external GigabitEthernet0/8/0:8443 vrf -1
 tcp local 10.128.0.129:80 external GigabitEthernet0/8/0:8443 vrf -1

With this commit, when-resolved static mapping is not created if the
translation only differs in local or ext port.

Change-Id: Ifc960b9dc1371caa2a8d3206a80a0ffd10d293e4
Signed-off-by: Alexander Chernavin <achernavin@netgate.com>
src/plugins/nat/nat.c

index 43ef325..97e2df1 100755 (executable)
@@ -713,7 +713,7 @@ snat_add_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
 
          if (!addr_only)
            {
-             if (rp->l_port != l_port || rp->e_port != e_port
+             if ((rp->l_port != l_port && rp->e_port != e_port)
                  || rp->proto != proto)
                continue;
            }