ipsec: fix udp-encap in transport mode
[vpp.git] / src / vnet / ipsec / esp_encrypt.c
index 7df537a..4793fdd 100644 (file)
@@ -320,10 +320,8 @@ esp_encrypt_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
       if (is_tun)
        {
          /* we are on a ipsec tunnel's feature arc */
-         u32 next0 = 0;
          config_index = b[0]->current_config_index;
-         vnet_feature_next (&next0, b[0]);
-         next[0] = next0;
+         vnet_feature_next_u16 (&next[0], b[0]);
          vnet_buffer (b[0])->ipsec.sad_index =
            sa_index0 = ipsec_tun_protect_get_sa_out
            (vnet_buffer (b[0])->ip.adj_index[VLIB_TX]);
@@ -465,6 +463,7 @@ esp_encrypt_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          u8 *l2_hdr, l2_len, *ip_hdr, ip_len;
          ip6_ext_header_t *ext_hdr;
          udp_header_t *udp = 0;
+         u16 udp_len = 0;
          u8 *old_ip_hdr = vlib_buffer_get_current (b[0]);
 
          ip_len = is_ip6 ?
@@ -539,7 +538,7 @@ esp_encrypt_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
              if (udp)
                {
                  esp_update_ip4_hdr (ip4, len, /* is_transport */ 1, 1);
-                 esp_fill_udp_hdr (sa0, udp, len - ip_len);
+                 udp_len = len - ip_len;
                }
              else
                esp_update_ip4_hdr (ip4, len, /* is_transport */ 1, 0);
@@ -547,6 +546,11 @@ esp_encrypt_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
 
          clib_memcpy_le64 (ip_hdr, old_ip_hdr, ip_len);
 
+         if (udp)
+           {
+             esp_fill_udp_hdr (sa0, udp, udp_len);
+           }
+
          if (!is_tun)
            next[0] = ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT;
        }