* ESP output routine, called by ipsec[46]_perform_request(). */
| 670 | * ESP output routine, called by ipsec[46]_perform_request(). |
| 671 | */ |
| 672 | static int |
| 673 | esp_output(struct mbuf *m, struct secpolicy *sp, struct secasvar *sav, |
| 674 | u_int idx, int skip, int protoff) |
| 675 | { |
| 676 | IPSEC_DEBUG_DECLARE(char buf[IPSEC_ADDRSTRLEN]); |
| 677 | struct cryptop *crp; |
| 678 | const struct auth_hash *esph; |
| 679 | const struct enc_xform *espx; |
| 680 | struct mbuf *mo = NULL; |
| 681 | struct xform_data *xd; |
| 682 | struct secasindex *saidx; |
| 683 | unsigned char *pad; |
| 684 | uint8_t *ivp; |
| 685 | uint64_t cntr; |
| 686 | crypto_session_t cryptoid; |
| 687 | int hlen, rlen, padding, blks, alen, i, roff; |
| 688 | int error, maxpacketsize; |
| 689 | uint8_t prot; |
| 690 | uint32_t seqh; |
| 691 | const struct crypto_session_params *csp; |
| 692 | |
| 693 | IPSEC_ASSERT(sav != NULL, ("null SA")); |
| 694 | esph = sav->tdb_authalgxform; |
| 695 | espx = sav->tdb_encalgxform; |
| 696 | IPSEC_ASSERT(espx != NULL, ("null encoding xform")); |
| 697 | |
| 698 | if (sav->flags & SADB_X_EXT_OLD) |
| 699 | hlen = sizeof (struct esp) + sav->ivlen; |
| 700 | else |
| 701 | hlen = sizeof (struct newesp) + sav->ivlen; |
| 702 | |
| 703 | rlen = m->m_pkthdr.len - skip; /* Raw payload length. */ |
| 704 | /* |
| 705 | * RFC4303 2.4 Requires 4 byte alignment. |
| 706 | * Old versions of FreeBSD can't decrypt partial blocks encrypted |
| 707 | * with AES-CTR. Align payload to native_blocksize (16 bytes) |
| 708 | * in order to preserve compatibility. |
| 709 | */ |
| 710 | if (SAV_ISCTR(sav) && V_esp_ctr_compatibility) |
| 711 | blks = MAX(4, espx->native_blocksize); /* Cipher blocksize */ |
| 712 | else |
| 713 | blks = MAX(4, espx->blocksize); |
| 714 | |
| 715 | /* XXX clamp padding length a la KAME??? */ |
| 716 | padding = ((blks - ((rlen + 2) % blks)) % blks) + 2; |
| 717 | |
| 718 | alen = xform_ah_authsize(esph); |
| 719 | |
| 720 | ESPSTAT_INC(esps_output); |
| 721 | |
| 722 | saidx = &sav->sah->saidx; |
| 723 | /* Check for maximum packet size violations. */ |
| 724 | switch (saidx->dst.sa.sa_family) { |
| 725 | #ifdef INET |
| 726 | case AF_INET: |
| 727 | maxpacketsize = IP_MAXPACKET; |
| 728 | break; |
| 729 | #endif /* INET */ |
nothing calls this directly
no test coverage detected