Deleted Added
sdiff udiff text old ( 117058 ) new ( 119643 )
full compact
1/* $FreeBSD: head/sys/netipsec/xform_ipcomp.c 117058 2003-06-30 05:09:32Z 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/socket.h>
39#include <sys/kernel.h>
40#include <sys/protosw.h>
41#include <sys/sysctl.h>
42
43#include <netinet/in.h>
44#include <netinet/in_systm.h>
45#include <netinet/ip.h>

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

210{
211 struct cryptodesc *crd;
212 struct tdb_crypto *tc;
213 int skip, protoff;
214 struct mtag *mtag;
215 struct mbuf *m;
216 struct secasvar *sav;
217 struct secasindex *saidx;
218 int s, hlen = IPCOMP_HLENGTH, error, clen;
219 u_int8_t nproto;
220 caddr_t addr;
221
222 crd = crp->crp_desc;
223
224 tc = (struct tdb_crypto *) crp->crp_opaque;
225 KASSERT(tc != NULL, ("ipcomp_input_cb: null opaque crypto data area!"));
226 skip = tc->tc_skip;
227 protoff = tc->tc_protoff;
228 mtag = (struct mtag *) tc->tc_ptr;
229 m = (struct mbuf *) crp->crp_buf;
230
231 s = splnet();
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 splx(s);
256 return crypto_dispatch(crp);
257 }
258
259 ipcompstat.ipcomps_noxform++;
260 DPRINTF(("ipcomp_input_cb: crypto error %d\n", crp->crp_etype));
261 error = crp->crp_etype;
262 goto bad;
263 }

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

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

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

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

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

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