* ESP input processing, called (eventually) through the protocol switch. */
| 257 | * ESP input processing, called (eventually) through the protocol switch. |
| 258 | */ |
| 259 | static int |
| 260 | esp_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff) |
| 261 | { |
| 262 | IPSEC_DEBUG_DECLARE(char buf[128]); |
| 263 | const struct auth_hash *esph; |
| 264 | const struct enc_xform *espx; |
| 265 | struct xform_data *xd; |
| 266 | struct cryptop *crp; |
| 267 | struct newesp *esp; |
| 268 | uint8_t *ivp; |
| 269 | crypto_session_t cryptoid; |
| 270 | int alen, error, hlen, plen; |
| 271 | uint32_t seqh; |
| 272 | const struct crypto_session_params *csp; |
| 273 | |
| 274 | IPSEC_ASSERT(sav != NULL, ("null SA")); |
| 275 | IPSEC_ASSERT(sav->tdb_encalgxform != NULL, ("null encoding xform")); |
| 276 | |
| 277 | error = EINVAL; |
| 278 | /* Valid IP Packet length ? */ |
| 279 | if ( (skip&3) || (m->m_pkthdr.len&3) ){ |
| 280 | DPRINTF(("%s: misaligned packet, skip %u pkt len %u", |
| 281 | __func__, skip, m->m_pkthdr.len)); |
| 282 | ESPSTAT_INC(esps_badilen); |
| 283 | goto bad; |
| 284 | } |
| 285 | |
| 286 | if (m->m_len < skip + sizeof(*esp)) { |
| 287 | m = m_pullup(m, skip + sizeof(*esp)); |
| 288 | if (m == NULL) { |
| 289 | DPRINTF(("%s: cannot pullup header\n", __func__)); |
| 290 | ESPSTAT_INC(esps_hdrops); /*XXX*/ |
| 291 | error = ENOBUFS; |
| 292 | goto bad; |
| 293 | } |
| 294 | } |
| 295 | esp = (struct newesp *)(mtod(m, caddr_t) + skip); |
| 296 | |
| 297 | esph = sav->tdb_authalgxform; |
| 298 | espx = sav->tdb_encalgxform; |
| 299 | |
| 300 | /* Determine the ESP header and auth length */ |
| 301 | if (sav->flags & SADB_X_EXT_OLD) |
| 302 | hlen = sizeof (struct esp) + sav->ivlen; |
| 303 | else |
| 304 | hlen = sizeof (struct newesp) + sav->ivlen; |
| 305 | |
| 306 | alen = xform_ah_authsize(esph); |
| 307 | |
| 308 | /* |
| 309 | * Verify payload length is multiple of encryption algorithm |
| 310 | * block size. |
| 311 | * |
| 312 | * NB: This works for the null algorithm because the blocksize |
| 313 | * is 4 and all packets must be 4-byte aligned regardless |
| 314 | * of the algorithm. |
| 315 | */ |
| 316 | plen = m->m_pkthdr.len - (skip + hlen + alen); |
nothing calls this directly
no test coverage detected