Fix vpp crash bug while deleting dhcp client
[vpp.git] / src / plugins / nat / nat.c
index 3856add..9eb0384 100755 (executable)
@@ -171,7 +171,7 @@ VNET_FEATURE_INIT (ip4_nat44_ed_hairpinning, static) =
 
 VLIB_PLUGIN_REGISTER () = {
     .version = VPP_BUILD_VER,
-    .description = "Network Address Translation",
+    .description = "Network Address Translation (NAT)",
 };
 /* *INDENT-ON* */
 
@@ -188,11 +188,20 @@ nat_free_session_data (snat_main_t * sm, snat_session_t * s, u32 thread_index,
 
   if (is_fwd_bypass_session (s))
     {
+      if (snat_is_unk_proto_session (s))
+       {
+         ed_key.proto = s->in2out.port;
+         ed_key.r_port = 0;
+         ed_key.l_port = 0;
+       }
+      else
+       {
+         ed_key.proto = snat_proto_to_ip_proto (s->in2out.protocol);
+         ed_key.l_port = s->in2out.port;
+         ed_key.r_port = s->ext_host_port;
+       }
       ed_key.l_addr = s->in2out.addr;
       ed_key.r_addr = s->ext_host_addr;
-      ed_key.l_port = s->in2out.port;
-      ed_key.r_port = s->ext_host_port;
-      ed_key.proto = snat_proto_to_ip_proto (s->in2out.protocol);
       ed_key.fib_index = 0;
       ed_kv.key[0] = ed_key.as_u64[0];
       ed_kv.key[1] = ed_key.as_u64[1];
@@ -713,7 +722,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;
            }
@@ -821,6 +830,7 @@ snat_add_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
        {
          fib_index = sm->inside_fib_index;
          vrf_id = sm->inside_vrf_id;
+         fib_table_lock (fib_index, FIB_PROTOCOL_IP4, FIB_SOURCE_PLUGIN_LOW);
        }
 
       if (!(out2in_only || identity_nat))
@@ -2269,6 +2279,7 @@ snat_init (vlib_main_t * vm)
   sm->workers = 0;
   sm->port_per_thread = 0xffff - 1024;
   sm->fq_in2out_index = ~0;
+  sm->fq_in2out_output_index = ~0;
   sm->fq_out2in_index = ~0;
   sm->udp_timeout = SNAT_UDP_TIMEOUT;
   sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;