+ /*
+ * Set the csum valid flag, if we authenticated the
+ * packet, the payload shouldn't be corrupt unless
+ * it was corrupted before being signed on the other
+ * side.
+ */
+ if (nxt == IPPROTO_TCP || nxt == IPPROTO_UDP) {
+ m->m_pkthdr.csum_flags = CSUM_DATA_VALID | CSUM_PSEUDO_HDR;
+ m->m_pkthdr.csum_data = 0xFFFF;
+ _CASSERT(offsetof(struct pkthdr, csum_data) == offsetof(struct pkthdr, csum_rx_val));
+ }
+
+ // Input via IPsec interface
+ lck_mtx_lock(sadb_mutex);
+ ifnet_t ipsec_if = sav->sah->ipsec_if;
+ if (ipsec_if != NULL) {
+ // If an interface is found, add a reference count before dropping the lock
+ ifnet_reference(ipsec_if);
+ }
+ lck_mtx_unlock(sadb_mutex);
+ if (ipsec_if != NULL) {
+ esp_input_log(m, sav, spi, seq);
+ ipsec_save_wake_packet(m, ntohl(spi), seq);
+
+ // Return mbuf
+ if (interface != NULL &&
+ interface == ipsec_if) {
+ ifnet_release(ipsec_if);
+ goto done;
+ }
+
+ errno_t inject_error = ipsec_inject_inbound_packet(ipsec_if, m);
+ ifnet_release(ipsec_if);
+
+ if (inject_error == 0) {