+ if (vnet_buffer (b[0])->ipsec.sad_index != current_sa_index)
+ {
+ if (current_sa_pkts)
+ vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
+ current_sa_index,
+ current_sa_pkts,
+ current_sa_bytes);
+ current_sa_bytes = current_sa_pkts = 0;
+
+ current_sa_index = vnet_buffer (b[0])->ipsec.sad_index;
+ sa0 = pool_elt_at_index (im->sad, current_sa_index);
+ cpd.icv_sz = sa0->integ_icv_size;
+ cpd.iv_sz = sa0->crypto_iv_size;
+ cpd.flags = sa0->flags;
+ cpd.sa_index = current_sa_index;
+ }
+
+ /* store packet data for next round for easier prefetch */
+ pd->sa_data = cpd.sa_data;
+ pd->current_data = b[0]->current_data;
+ pd->current_length = b[0]->current_length;
+ pd->hdr_sz = pd->current_data - vnet_buffer (b[0])->l3_hdr_offset;
+ payload = b[0]->data + pd->current_data;
+
+ /* we need 4 extra bytes for HMAC calculation when ESN are used */
+ if (ipsec_sa_is_set_USE_ESN (sa0) && pd->icv_sz &&
+ (pd->current_data + pd->current_length + 4 > buffer_data_size))
+ {
+ b[0]->error = node->errors[ESP_DECRYPT_ERROR_NO_TAIL_SPACE];
+ next[0] = ESP_DECRYPT_NEXT_DROP;
+ goto next;
+ }
+
+ /* anti-reply check */
+ if (ipsec_sa_anti_replay_check (sa0, &((esp_header_t *) payload)->seq))
+ {
+ b[0]->error = node->errors[ESP_DECRYPT_ERROR_REPLAY];
+ next[0] = ESP_DECRYPT_NEXT_DROP;
+ goto next;
+ }
+
+ if (pd->current_length < cpd.icv_sz + esp_sz + cpd.iv_sz)
+ {
+ b[0]->error = node->errors[ESP_DECRYPT_ERROR_RUNT];
+ next[0] = ESP_DECRYPT_NEXT_DROP;
+ goto next;
+ }