MCPcopy Create free account
hub / github.com/F-Stack/f-stack / esp_output_cb

Function esp_output_cb

freebsd/netipsec/xform_esp.c:965–1048  ·  view source on GitHub ↗

* ESP output callback from the crypto driver. */

Source from the content-addressed store, hash-verified

963 * ESP output callback from the crypto driver.
964 */
965static int
966esp_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

Callers

nothing calls this directly

Calls 11

ipsec_updateidFunction · 0.85
crypto_freesessionFunction · 0.85
crypto_dispatchFunction · 0.85
crypto_freereqFunction · 0.85
xform_ah_authsizeFunction · 0.85
m_copybackFunction · 0.85
ipsec_process_doneFunction · 0.85
key_freesavFunction · 0.85
key_freespFunction · 0.85
m_freemFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected