NAT: TCP MSS clamping
[vpp.git] / src / plugins / nat / nat64_in2out.c
index cdfe9b8..e843fcf 100644 (file)
@@ -224,8 +224,6 @@ nat64_in2out_tcp_udp_set_cb (ip6_header_t * ip6, ip4_header_t * ip4,
        return -1;
     }
 
-  nat64_session_reset_timeout (ste, ctx->vm);
-
   ip4->src_address.as_u32 = bibe->out_addr.as_u32;
   udp->src_port = bibe->out_port;
 
@@ -237,12 +235,16 @@ nat64_in2out_tcp_udp_set_cb (ip6_header_t * ip6, ip4_header_t * ip4,
       ip_csum_t csum;
       tcp_header_t *tcp = ip6_next_header (ip6);
 
+      nat64_tcp_session_set_state (ste, tcp, 1);
       checksum = &tcp->checksum;
       csum = ip_csum_sub_even (*checksum, sport);
       csum = ip_csum_add_even (csum, udp->src_port);
+      mss_clamping (nm->sm, tcp, &csum);
       *checksum = ip_csum_fold (csum);
     }
 
+  nat64_session_reset_timeout (ste, ctx->vm);
+
   return 0;
 }
 
@@ -636,6 +638,9 @@ nat64_in2out_tcp_udp_hairpinning (vlib_main_t * vm, vlib_buffer_t * b,
        return -1;
     }
 
+  if (proto == IP_PROTOCOL_TCP)
+    nat64_tcp_session_set_state (ste, tcp, 1);
+
   nat64_session_reset_timeout (ste, vm);
 
   sport = udp->src_port = bibe->out_port;
@@ -1203,6 +1208,7 @@ nat64_in2out_frag_set_cb (ip6_header_t * ip6, ip4_header_t * ip4, void *arg)
          ip_csum_t csum;
          tcp_header_t *tcp = (tcp_header_t *) udp;
 
+         nat64_tcp_session_set_state (ste, tcp, 1);
          checksum = &tcp->checksum;
          csum = ip_csum_sub_even (*checksum, tcp->src_port);
          csum = ip_csum_sub_even (csum, ip6->src_address.as_u64[0]);
@@ -1263,6 +1269,9 @@ nat64_in2out_frag_hairpinning (vlib_buffer_t * b, ip6_header_t * ip6,
   if (!bibe)
     return -1;
 
+  if (ctx->proto == IP_PROTOCOL_TCP)
+    nat64_tcp_session_set_state (ste, tcp, 1);
+
   nat64_session_reset_timeout (ste, ctx->vm);
 
   sport = bibe->out_port;
@@ -1416,7 +1425,8 @@ nat64_in2out_reass_node_fn (vlib_main_t * vm,
              ctx0.first_frag = 0;
              if (PREDICT_FALSE (reass0->sess_index == (u32) ~ 0))
                {
-                 if (nat_ip6_reass_add_fragment (reass0, bi0))
+                 if (nat_ip6_reass_add_fragment
+                     (reass0, bi0, &fragments_to_drop))
                    {
                      b0->error = node->errors[NAT64_IN2OUT_ERROR_MAX_FRAG];
                      next0 = NAT64_IN2OUT_NEXT_DROP;