Deleted Added
sdiff udiff text old ( 117058 ) new ( 119643 )
full compact
1/* $FreeBSD: head/sys/netipsec/xform_ipcomp.c 119643 2003-09-01 05:35:55Z sam $ */
2/* $OpenBSD: ip_ipcomp.c,v 1.1 2001/07/05 12:08:52 jjbg Exp $ */
3
4/*
5 * Copyright (c) 2001 Jean-Jacques Bernard-Gundol (jj@wabbitt.org)
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:

--- 20 unchanged lines hidden (view full) ---

30
31/* IP payload compression protocol (IPComp), see RFC 2393 */
32#include "opt_inet.h"
33#include "opt_inet6.h"
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/mbuf.h>
38#include <sys/lock.h>
39#include <sys/mutex.h>
40#include <sys/socket.h>
41#include <sys/kernel.h>
42#include <sys/protosw.h>
43#include <sys/sysctl.h>
44
45#include <netinet/in.h>
46#include <netinet/in_systm.h>
47#include <netinet/ip.h>

--- 164 unchanged lines hidden (view full) ---

212{
213 struct cryptodesc *crd;
214 struct tdb_crypto *tc;
215 int skip, protoff;
216 struct mtag *mtag;
217 struct mbuf *m;
218 struct secasvar *sav;
219 struct secasindex *saidx;
220 int hlen = IPCOMP_HLENGTH, error, clen;
221 u_int8_t nproto;
222 caddr_t addr;
223
224 crd = crp->crp_desc;
225
226 tc = (struct tdb_crypto *) crp->crp_opaque;
227 KASSERT(tc != NULL, ("ipcomp_input_cb: null opaque crypto data area!"));
228 skip = tc->tc_skip;
229 protoff = tc->tc_protoff;
230 mtag = (struct mtag *) tc->tc_ptr;
231 m = (struct mbuf *) crp->crp_buf;
232
233 sav = KEY_ALLOCSA(&tc->tc_dst, tc->tc_proto, tc->tc_spi);
234 if (sav == NULL) {
235 ipcompstat.ipcomps_notdb++;
236 DPRINTF(("ipcomp_input_cb: SA expired while in crypto\n"));
237 error = ENOBUFS; /*XXX*/
238 goto bad;
239 }
240

--- 6 unchanged lines hidden (view full) ---

247 /* Check for crypto errors */
248 if (crp->crp_etype) {
249 /* Reset the session ID */
250 if (sav->tdb_cryptoid != 0)
251 sav->tdb_cryptoid = crp->crp_sid;
252
253 if (crp->crp_etype == EAGAIN) {
254 KEY_FREESAV(&sav);
255 return crypto_dispatch(crp);
256 }
257
258 ipcompstat.ipcomps_noxform++;
259 DPRINTF(("ipcomp_input_cb: crypto error %d\n", crp->crp_etype));
260 error = crp->crp_etype;
261 goto bad;
262 }

--- 37 unchanged lines hidden (view full) ---

300 }
301
302 /* Restore the Next Protocol field */
303 m_copyback(m, protoff, sizeof (u_int8_t), (u_int8_t *) &nproto);
304
305 IPSEC_COMMON_INPUT_CB(m, sav, skip, protoff, NULL);
306
307 KEY_FREESAV(&sav);
308 return error;
309bad:
310 if (sav)
311 KEY_FREESAV(&sav);
312 if (m)
313 m_freem(m);
314 if (tc != NULL)
315 free(tc, M_XDATA);
316 if (crp)
317 crypto_freereq(crp);
318 return error;
319}

--- 172 unchanged lines hidden (view full) ---

492 */
493static int
494ipcomp_output_cb(struct cryptop *crp)
495{
496 struct tdb_crypto *tc;
497 struct ipsecrequest *isr;
498 struct secasvar *sav;
499 struct mbuf *m;
500 int error, skip, rlen;
501
502 tc = (struct tdb_crypto *) crp->crp_opaque;
503 KASSERT(tc != NULL, ("ipcomp_output_cb: null opaque data area!"));
504 m = (struct mbuf *) crp->crp_buf;
505 skip = tc->tc_skip;
506 rlen = crp->crp_ilen - skip;
507
508 isr = tc->tc_isr;
509 mtx_lock(&isr->lock);
510 sav = KEY_ALLOCSA(&tc->tc_dst, tc->tc_proto, tc->tc_spi);
511 if (sav == NULL) {
512 ipcompstat.ipcomps_notdb++;
513 DPRINTF(("ipcomp_output_cb: SA expired while in crypto\n"));
514 error = ENOBUFS; /*XXX*/
515 goto bad;
516 }
517 KASSERT(isr->sav == sav, ("ipcomp_output_cb: SA changed\n"));
518
519 /* Check for crypto errors */
520 if (crp->crp_etype) {
521 /* Reset session ID */
522 if (sav->tdb_cryptoid != 0)
523 sav->tdb_cryptoid = crp->crp_sid;
524
525 if (crp->crp_etype == EAGAIN) {
526 KEY_FREESAV(&sav);
527 mtx_unlock(&isr->lock);
528 return crypto_dispatch(crp);
529 }
530 ipcompstat.ipcomps_noxform++;
531 DPRINTF(("ipcomp_output_cb: crypto error %d\n", crp->crp_etype));
532 error = crp->crp_etype;
533 goto bad;
534 }
535 /* Shouldn't happen... */

--- 36 unchanged lines hidden (view full) ---

572
573 /* Release the crypto descriptor */
574 free(tc, M_XDATA);
575 crypto_freereq(crp);
576
577 /* NB: m is reclaimed by ipsec_process_done. */
578 error = ipsec_process_done(m, isr);
579 KEY_FREESAV(&sav);
580 mtx_unlock(&isr->lock);
581
582 return error;
583bad:
584 if (sav)
585 KEY_FREESAV(&sav);
586 mtx_unlock(&isr->lock);
587 if (m)
588 m_freem(m);
589 free(tc, M_XDATA);
590 crypto_freereq(crp);
591 return error;
592}
593
594static struct xformsw ipcomp_xformsw = {
595 XF_IPCOMP, XFT_COMP, "IPcomp",
596 ipcomp_init, ipcomp_zeroize, ipcomp_input,
597 ipcomp_output
598};
599
600static void
601ipcomp_attach(void)
602{
603 xform_register(&ipcomp_xformsw);
604}
605SYSINIT(ipcomp_xform_init, SI_SUB_DRIVERS, SI_ORDER_FIRST, ipcomp_attach, NULL)