* ESP output callback from the crypto driver. */
| 963 | * ESP output callback from the crypto driver. |
| 964 | */ |
| 965 | static int |
| 966 | esp_output_cb(struct cryptop *crp) |
| 967 | { |
| 968 | struct xform_data *xd; |
| 969 | struct secpolicy *sp; |
| 970 | struct secasvar *sav; |
| 971 | struct mbuf *m; |
| 972 | crypto_session_t cryptoid; |
| 973 | u_int idx; |
| 974 | int error; |
| 975 | |
| 976 | xd = (struct xform_data *) crp->crp_opaque; |
| 977 | CURVNET_SET(xd->vnet); |
| 978 | m = crp->crp_buf.cb_mbuf; |
| 979 | sp = xd->sp; |
| 980 | sav = xd->sav; |
| 981 | idx = xd->idx; |
| 982 | cryptoid = xd->cryptoid; |
| 983 | |
| 984 | /* Check for crypto errors. */ |
| 985 | if (crp->crp_etype) { |
| 986 | if (crp->crp_etype == EAGAIN) { |
| 987 | /* Reset the session ID */ |
| 988 | if (ipsec_updateid(sav, &crp->crp_session, &cryptoid) != 0) |
| 989 | crypto_freesession(cryptoid); |
| 990 | xd->cryptoid = crp->crp_session; |
| 991 | CURVNET_RESTORE(); |
| 992 | return (crypto_dispatch(crp)); |
| 993 | } |
| 994 | ESPSTAT_INC(esps_noxform); |
| 995 | DPRINTF(("%s: crypto error %d\n", __func__, crp->crp_etype)); |
| 996 | error = crp->crp_etype; |
| 997 | m_freem(m); |
| 998 | goto bad; |
| 999 | } |
| 1000 | |
| 1001 | /* Shouldn't happen... */ |
| 1002 | if (m == NULL) { |
| 1003 | ESPSTAT_INC(esps_crypto); |
| 1004 | DPRINTF(("%s: bogus returned buffer from crypto\n", __func__)); |
| 1005 | error = EINVAL; |
| 1006 | goto bad; |
| 1007 | } |
| 1008 | free(xd, M_XDATA); |
| 1009 | free(crp->crp_aad, M_XDATA); |
| 1010 | crypto_freereq(crp); |
| 1011 | ESPSTAT_INC(esps_hist[sav->alg_enc]); |
| 1012 | if (sav->tdb_authalgxform != NULL) |
| 1013 | AHSTAT_INC(ahs_hist[sav->alg_auth]); |
| 1014 | |
| 1015 | #ifdef REGRESSION |
| 1016 | /* Emulate man-in-the-middle attack when ipsec_integrity is TRUE. */ |
| 1017 | if (V_ipsec_integrity) { |
| 1018 | static unsigned char ipseczeroes[AH_HMAC_MAXHASHLEN]; |
| 1019 | const struct auth_hash *esph; |
| 1020 | |
| 1021 | /* |
| 1022 | * Corrupt HMAC if we want to test integrity verification of |
nothing calls this directly
no test coverage detected