xform_ipcomp.c (117058) | xform_ipcomp.c (119643) |
---|---|
1/* $FreeBSD: head/sys/netipsec/xform_ipcomp.c 117058 2003-06-30 05:09:32Z sam $ */ | 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> | 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> |
|
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; | 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; |
218 int s, hlen = IPCOMP_HLENGTH, error, clen; | 220 int 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 | 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 |
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); | 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); | 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); |
309 splx(s); | |
310 return error; 311bad: 312 if (sav) 313 KEY_FREESAV(&sav); | 308 return error; 309bad: 310 if (sav) 311 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; | 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; |
503 int s, error, skip, rlen; | 500 int 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 | 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 |
511 s = splnet(); 512 | |
513 isr = tc->tc_isr; | 508 isr = tc->tc_isr; |
509 mtx_lock(&isr->lock); |
|
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); | 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); |
531 splx(s); | 527 mtx_unlock(&isr->lock); |
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); | 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); |
584 splx(s); | 580 mtx_unlock(&isr->lock); 581 |
585 return error; 586bad: 587 if (sav) 588 KEY_FREESAV(&sav); | 582 return error; 583bad: 584 if (sav) 585 KEY_FREESAV(&sav); |
589 splx(s); | 586 mtx_unlock(&isr->lock); |
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) | 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) |