* ESP input callback from the crypto driver. */
| 478 | * ESP input callback from the crypto driver. |
| 479 | */ |
| 480 | static int |
| 481 | esp_input_cb(struct cryptop *crp) |
| 482 | { |
| 483 | IPSEC_DEBUG_DECLARE(char buf[128]); |
| 484 | uint8_t lastthree[3]; |
| 485 | const struct auth_hash *esph; |
| 486 | struct mbuf *m; |
| 487 | struct xform_data *xd; |
| 488 | struct secasvar *sav; |
| 489 | struct secasindex *saidx; |
| 490 | crypto_session_t cryptoid; |
| 491 | int hlen, skip, protoff, error, alen; |
| 492 | |
| 493 | m = crp->crp_buf.cb_mbuf; |
| 494 | xd = crp->crp_opaque; |
| 495 | CURVNET_SET(xd->vnet); |
| 496 | sav = xd->sav; |
| 497 | skip = xd->skip; |
| 498 | protoff = xd->protoff; |
| 499 | cryptoid = xd->cryptoid; |
| 500 | saidx = &sav->sah->saidx; |
| 501 | esph = sav->tdb_authalgxform; |
| 502 | |
| 503 | /* Check for crypto errors */ |
| 504 | if (crp->crp_etype) { |
| 505 | if (crp->crp_etype == EAGAIN) { |
| 506 | /* Reset the session ID */ |
| 507 | if (ipsec_updateid(sav, &crp->crp_session, &cryptoid) != 0) |
| 508 | crypto_freesession(cryptoid); |
| 509 | xd->cryptoid = crp->crp_session; |
| 510 | CURVNET_RESTORE(); |
| 511 | return (crypto_dispatch(crp)); |
| 512 | } |
| 513 | |
| 514 | /* EBADMSG indicates authentication failure. */ |
| 515 | if (!(crp->crp_etype == EBADMSG && esph != NULL)) { |
| 516 | ESPSTAT_INC(esps_noxform); |
| 517 | DPRINTF(("%s: crypto error %d\n", __func__, |
| 518 | crp->crp_etype)); |
| 519 | error = crp->crp_etype; |
| 520 | goto bad; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | /* Shouldn't happen... */ |
| 525 | if (m == NULL) { |
| 526 | ESPSTAT_INC(esps_crypto); |
| 527 | DPRINTF(("%s: bogus returned buffer from crypto\n", __func__)); |
| 528 | error = EINVAL; |
| 529 | goto bad; |
| 530 | } |
| 531 | ESPSTAT_INC(esps_hist[sav->alg_enc]); |
| 532 | |
| 533 | /* If authentication was performed, check now. */ |
| 534 | if (esph != NULL) { |
| 535 | alen = xform_ah_authsize(esph); |
| 536 | AHSTAT_INC(ahs_hist[sav->alg_auth]); |
| 537 | if (crp->crp_etype == EBADMSG) { |
nothing calls this directly
no test coverage detected