Improve MTU handling
[vpp.git] / src / vnet / ip / ip4_forward.c
index ff58296..b9875d7 100644 (file)
@@ -2109,16 +2109,26 @@ ip4_rewrite_inline (vlib_main_t * vm,
          vnet_buffer (p1)->ip.save_rewrite_length = rw_len1;
 
          /* Check MTU of outgoing interface. */
-         error0 =
-           (vlib_buffer_length_in_chain (vm, p0) >
-            adj0[0].
-            rewrite_header.max_l3_packet_bytes ? IP4_ERROR_MTU_EXCEEDED :
-            error0);
-         error1 =
-           (vlib_buffer_length_in_chain (vm, p1) >
-            adj1[0].
-            rewrite_header.max_l3_packet_bytes ? IP4_ERROR_MTU_EXCEEDED :
-            error1);
+         if (vlib_buffer_length_in_chain (vm, p0) >
+             adj0[0].rewrite_header.max_l3_packet_bytes)
+           {
+             error0 = IP4_ERROR_MTU_EXCEEDED;
+             next0 = IP4_REWRITE_NEXT_ICMP_ERROR;
+             icmp4_error_set_vnet_buffer
+               (p0, ICMP4_destination_unreachable,
+                ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
+                0);
+           }
+         if (vlib_buffer_length_in_chain (vm, p1) >
+             adj1[0].rewrite_header.max_l3_packet_bytes)
+           {
+             error1 = IP4_ERROR_MTU_EXCEEDED;
+             next1 = IP4_REWRITE_NEXT_ICMP_ERROR;
+             icmp4_error_set_vnet_buffer
+               (p1, ICMP4_destination_unreachable,
+                ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
+                0);
+           }
 
          if (is_mcast)
            {
@@ -2130,6 +2140,8 @@ ip4_rewrite_inline (vlib_main_t * vm,
                        IP4_ERROR_SAME_INTERFACE : error1);
            }
 
+         p0->error = error_node->errors[error0];
+         p1->error = error_node->errors[error1];
          /* Don't adjust the buffer for ttl issue; icmp-error node wants
           * to see the IP headerr */
          if (PREDICT_TRUE (error0 == IP4_ERROR_NONE))
@@ -2288,9 +2300,16 @@ ip4_rewrite_inline (vlib_main_t * vm,
               vlib_buffer_length_in_chain (vm, p0) + rw_len0);
 
          /* Check MTU of outgoing interface. */
-         error0 = (vlib_buffer_length_in_chain (vm, p0)
-                   > adj0[0].rewrite_header.max_l3_packet_bytes
-                   ? IP4_ERROR_MTU_EXCEEDED : error0);
+         if (vlib_buffer_length_in_chain (vm, p0) >
+             adj0[0].rewrite_header.max_l3_packet_bytes)
+           {
+             error0 = IP4_ERROR_MTU_EXCEEDED;
+             next0 = IP4_REWRITE_NEXT_ICMP_ERROR;
+             icmp4_error_set_vnet_buffer
+               (p0, ICMP4_destination_unreachable,
+                ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
+                0);
+           }
          if (is_mcast)
            {
              error0 = ((adj0[0].rewrite_header.sw_if_index ==