2 /* $OpenBSD: ip_ipcomp.c,v 1.1 2001/07/05 12:08:52 jjbg Exp $ */
5 * SPDX-License-Identifier: BSD-3-Clause
7 * Copyright (c) 2001 Jean-Jacques Bernard-Gundol (jj@wabbitt.org)
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* IP payload compression protocol (IPComp), see RFC 2393 */
35 #include "opt_inet6.h"
36 #include "opt_ipsec.h"
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/malloc.h>
43 #include <sys/mutex.h>
44 #include <sys/socket.h>
45 #include <sys/kernel.h>
46 #include <sys/protosw.h>
47 #include <sys/sysctl.h>
49 #include <netinet/in.h>
50 #include <netinet/in_systm.h>
51 #include <netinet/ip.h>
52 #include <netinet/ip_var.h>
53 #include <netinet/ip_encap.h>
55 #include <net/netisr.h>
57 #include <net/if.h> /* XXXGL: net_epoch should move out there */
58 #include <net/if_var.h> /* XXXGL: net_epoch should move out there */
60 #include <netipsec/ipsec.h>
61 #include <netipsec/xform.h>
64 #include <netinet/ip6.h>
65 #include <netinet6/ip6_var.h>
66 #include <netipsec/ipsec6.h>
69 #include <netipsec/ipcomp.h>
70 #include <netipsec/ipcomp_var.h>
72 #include <netipsec/key.h>
73 #include <netipsec/key_debug.h>
75 #include <opencrypto/cryptodev.h>
76 #include <opencrypto/deflate.h>
77 #include <opencrypto/xform.h>
79 VNET_DEFINE(int, ipcomp_enable) = 1;
80 VNET_PCPUSTAT_DEFINE(struct ipcompstat, ipcompstat);
81 VNET_PCPUSTAT_SYSINIT(ipcompstat);
84 VNET_PCPUSTAT_SYSUNINIT(ipcompstat);
87 SYSCTL_DECL(_net_inet_ipcomp);
88 SYSCTL_INT(_net_inet_ipcomp, OID_AUTO, ipcomp_enable,
89 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ipcomp_enable), 0, "");
90 SYSCTL_VNET_PCPUSTAT(_net_inet_ipcomp, IPSECCTL_STATS, stats,
91 struct ipcompstat, ipcompstat,
92 "IPCOMP statistics (struct ipcompstat, netipsec/ipcomp_var.h");
94 static MALLOC_DEFINE(M_IPCOMP, "ipcomp", "IPCOMP");
96 static int ipcomp_input_cb(struct cryptop *crp);
97 static int ipcomp_output_cb(struct cryptop *crp);
100 * RFC 3173 p 2.2. Non-Expansion Policy:
101 * If the total size of a compressed payload and the IPComp header, as
102 * defined in section 3, is not smaller than the size of the original
103 * payload, the IP datagram MUST be sent in the original non-compressed
106 * When we use IPComp in tunnel mode, for small packets we will receive
107 * encapsulated IP-IP datagrams without any compression and without IPComp
111 ipcomp_encapcheck(union sockaddr_union *src, union sockaddr_union *dst)
113 struct secasvar *sav;
115 sav = key_allocsa_tunnel(src, dst, IPPROTO_IPCOMP);
120 if (src->sa.sa_family == AF_INET)
121 return (sizeof(struct in_addr) << 4);
123 return (sizeof(struct in6_addr) << 4);
127 ipcomp_nonexp_input(struct mbuf *m, int off, int proto, void *arg __unused)
145 IPCOMPSTAT_INC(ipcomps_nopf);
147 return (IPPROTO_DONE);
150 IPCOMPSTAT_ADD(ipcomps_ibytes, m->m_pkthdr.len);
151 IPCOMPSTAT_INC(ipcomps_input);
152 netisr_dispatch(isr, m);
153 return (IPPROTO_DONE);
157 * ipcomp_init() is called when an CPI is being set up.
160 ipcomp_init(struct secasvar *sav, struct xformsw *xsp)
162 const struct comp_algo *tcomp;
163 struct crypto_session_params csp;
165 /* NB: algorithm really comes in alg_enc and not alg_comp! */
166 tcomp = comp_algorithm_lookup(sav->alg_enc);
168 DPRINTF(("%s: unsupported compression algorithm %d\n", __func__,
172 sav->alg_comp = sav->alg_enc; /* set for doing histogram */
173 sav->tdb_xform = xsp;
174 sav->tdb_compalgxform = tcomp;
176 /* Initialize crypto session */
177 memset(&csp, 0, sizeof(csp));
178 csp.csp_mode = CSP_MODE_COMPRESS;
179 csp.csp_cipher_alg = sav->tdb_compalgxform->type;
181 return crypto_newsession(&sav->tdb_cryptoid, &csp, V_crypto_support);
185 * ipcomp_cleanup() used when IPCA is deleted
188 ipcomp_cleanup(struct secasvar *sav)
191 crypto_freesession(sav->tdb_cryptoid);
192 sav->tdb_cryptoid = NULL;
196 * ipcomp_input() gets called to uncompress an input packet
199 ipcomp_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff)
201 struct xform_data *xd;
203 struct ipcomp *ipcomp;
204 crypto_session_t cryptoid;
206 int error, hlen = IPCOMP_HLENGTH;
209 * Check that the next header of the IPComp is not IPComp again, before
210 * doing any real work. Given it is not possible to do double
211 * compression it means someone is playing tricks on us.
214 if (m->m_len < skip + hlen && (m = m_pullup(m, skip + hlen)) == NULL) {
215 IPCOMPSTAT_INC(ipcomps_hdrops); /*XXX*/
216 DPRINTF(("%s: m_pullup failed\n", __func__));
220 addr = (caddr_t) mtod(m, struct ip *) + skip;
221 ipcomp = (struct ipcomp *)addr;
222 if (ipcomp->comp_nxt == IPPROTO_IPCOMP) {
223 IPCOMPSTAT_INC(ipcomps_pdrops); /* XXX have our own stats? */
224 DPRINTF(("%s: recursive compression detected\n", __func__));
230 cryptoid = sav->tdb_cryptoid;
231 SECASVAR_UNLOCK(sav);
233 /* Get crypto descriptors */
234 crp = crypto_getreq(cryptoid, M_NOWAIT);
236 DPRINTF(("%s: no crypto descriptors\n", __func__));
237 IPCOMPSTAT_INC(ipcomps_crypto);
240 /* Get IPsec-specific opaque pointer */
241 xd = malloc(sizeof(*xd), M_IPCOMP, M_NOWAIT | M_ZERO);
243 DPRINTF(("%s: cannot allocate xform_data\n", __func__));
244 IPCOMPSTAT_INC(ipcomps_crypto);
249 /* Decompression operation */
250 crp->crp_op = CRYPTO_OP_DECOMPRESS;
251 crp->crp_payload_start = skip + hlen;
252 crp->crp_payload_length = m->m_pkthdr.len - (skip + hlen);
254 /* Crypto operation descriptor */
255 crp->crp_flags = CRYPTO_F_CBIFSYNC;
256 crypto_use_mbuf(crp, m);
257 crp->crp_callback = ipcomp_input_cb;
258 crp->crp_opaque = xd;
260 /* These are passed as-is to the callback */
262 xd->protoff = protoff;
265 xd->cryptoid = cryptoid;
268 crp->crp_session = xd->cryptoid = sav->tdb_cryptoid;
269 SECASVAR_UNLOCK(sav);
271 return crypto_dispatch(crp);
279 * IPComp input callback from the crypto driver.
282 ipcomp_input_cb(struct cryptop *crp)
284 IPSEC_DEBUG_DECLARE(char buf[IPSEC_ADDRSTRLEN]);
285 struct xform_data *xd;
287 struct secasvar *sav;
288 struct secasindex *saidx;
290 crypto_session_t cryptoid;
291 int hlen = IPCOMP_HLENGTH, error, clen;
295 m = crp->crp_buf.cb_mbuf;
296 xd = crp->crp_opaque;
297 CURVNET_SET(xd->vnet);
300 protoff = xd->protoff;
301 cryptoid = xd->cryptoid;
302 saidx = &sav->sah->saidx;
303 IPSEC_ASSERT(saidx->dst.sa.sa_family == AF_INET ||
304 saidx->dst.sa.sa_family == AF_INET6,
305 ("unexpected protocol family %u", saidx->dst.sa.sa_family));
307 /* Check for crypto errors */
308 if (crp->crp_etype) {
309 if (crp->crp_etype == EAGAIN) {
310 /* Reset the session ID */
311 if (ipsec_updateid(sav, &crp->crp_session, &cryptoid) != 0)
312 crypto_freesession(cryptoid);
313 xd->cryptoid = crp->crp_session;
315 return (crypto_dispatch(crp));
317 IPCOMPSTAT_INC(ipcomps_noxform);
318 DPRINTF(("%s: crypto error %d\n", __func__, crp->crp_etype));
319 error = crp->crp_etype;
322 /* Shouldn't happen... */
324 IPCOMPSTAT_INC(ipcomps_crypto);
325 DPRINTF(("%s: null mbuf returned from crypto\n", __func__));
329 IPCOMPSTAT_INC(ipcomps_hist[sav->alg_comp]);
331 clen = crp->crp_olen; /* Length of data after processing */
333 /* Release the crypto descriptors */
334 free(xd, M_IPCOMP), xd = NULL;
335 crypto_freereq(crp), crp = NULL;
337 /* In case it's not done already, adjust the size of the mbuf chain */
338 m->m_pkthdr.len = clen + hlen + skip;
340 if (m->m_len < skip + hlen && (m = m_pullup(m, skip + hlen)) == NULL) {
341 IPCOMPSTAT_INC(ipcomps_hdrops); /*XXX*/
342 DPRINTF(("%s: m_pullup failed\n", __func__));
343 error = EINVAL; /*XXX*/
347 /* Keep the next protocol field */
348 addr = (caddr_t) mtod(m, struct ip *) + skip;
349 nproto = ((struct ipcomp *) addr)->comp_nxt;
351 /* Remove the IPCOMP header */
352 error = m_striphdr(m, skip, hlen);
354 IPCOMPSTAT_INC(ipcomps_hdrops);
355 DPRINTF(("%s: bad mbuf chain, IPCA %s/%08lx\n", __func__,
356 ipsec_address(&sav->sah->saidx.dst, buf, sizeof(buf)),
357 (u_long) ntohl(sav->spi)));
361 /* Restore the Next Protocol field */
362 m_copyback(m, protoff, sizeof (u_int8_t), (u_int8_t *) &nproto);
364 switch (saidx->dst.sa.sa_family) {
367 error = ipsec6_common_input_cb(m, sav, skip, protoff);
372 error = ipsec4_common_input_cb(m, sav, skip, protoff);
376 panic("%s: Unexpected address family: %d saidx=%p", __func__,
377 saidx->dst.sa.sa_family, saidx);
395 * IPComp output routine, called by ipsec[46]_perform_request()
398 ipcomp_output(struct mbuf *m, struct secpolicy *sp, struct secasvar *sav,
399 u_int idx, int skip, int protoff)
401 IPSEC_DEBUG_DECLARE(char buf[IPSEC_ADDRSTRLEN]);
402 const struct comp_algo *ipcompx;
404 struct xform_data *xd;
405 crypto_session_t cryptoid;
406 int error, ralen, maxpacketsize;
408 IPSEC_ASSERT(sav != NULL, ("null SA"));
409 ipcompx = sav->tdb_compalgxform;
410 IPSEC_ASSERT(ipcompx != NULL, ("null compression xform"));
413 * Do not touch the packet in case our payload to compress
414 * is lower than the minimal threshold of the compression
415 * alogrithm. We will just send out the data uncompressed.
416 * See RFC 3173, 2.2. Non-Expansion Policy.
418 if (m->m_pkthdr.len <= ipcompx->minlen) {
419 IPCOMPSTAT_INC(ipcomps_threshold);
420 return ipsec_process_done(m, sp, sav, idx);
423 ralen = m->m_pkthdr.len - skip; /* Raw payload length before comp. */
424 IPCOMPSTAT_INC(ipcomps_output);
426 /* Check for maximum packet size violations. */
427 switch (sav->sah->saidx.dst.sa.sa_family) {
430 maxpacketsize = IP_MAXPACKET;
435 maxpacketsize = IPV6_MAXPACKET;
439 IPCOMPSTAT_INC(ipcomps_nopf);
440 DPRINTF(("%s: unknown/unsupported protocol family %d, "
441 "IPCA %s/%08lx\n", __func__,
442 sav->sah->saidx.dst.sa.sa_family,
443 ipsec_address(&sav->sah->saidx.dst, buf, sizeof(buf)),
444 (u_long) ntohl(sav->spi)));
445 error = EPFNOSUPPORT;
448 if (ralen + skip + IPCOMP_HLENGTH > maxpacketsize) {
449 IPCOMPSTAT_INC(ipcomps_toobig);
450 DPRINTF(("%s: packet in IPCA %s/%08lx got too big "
451 "(len %u, max len %u)\n", __func__,
452 ipsec_address(&sav->sah->saidx.dst, buf, sizeof(buf)),
453 (u_long) ntohl(sav->spi),
454 ralen + skip + IPCOMP_HLENGTH, maxpacketsize));
459 /* Update the counters */
460 IPCOMPSTAT_ADD(ipcomps_obytes, m->m_pkthdr.len - skip);
462 m = m_unshare(m, M_NOWAIT);
464 IPCOMPSTAT_INC(ipcomps_hdrops);
465 DPRINTF(("%s: cannot clone mbuf chain, IPCA %s/%08lx\n",
466 __func__, ipsec_address(&sav->sah->saidx.dst, buf,
467 sizeof(buf)), (u_long) ntohl(sav->spi)));
472 /* Ok now, we can pass to the crypto processing. */
474 cryptoid = sav->tdb_cryptoid;
475 SECASVAR_UNLOCK(sav);
477 /* Get crypto descriptors */
478 crp = crypto_getreq(cryptoid, M_NOWAIT);
480 IPCOMPSTAT_INC(ipcomps_crypto);
481 DPRINTF(("%s: failed to acquire crypto descriptor\n",__func__));
486 /* Compression descriptor */
487 crp->crp_op = CRYPTO_OP_COMPRESS;
488 crp->crp_payload_start = skip;
489 crp->crp_payload_length = ralen;
491 /* IPsec-specific opaque crypto info */
492 xd = malloc(sizeof(struct xform_data), M_IPCOMP, M_NOWAIT | M_ZERO);
494 IPCOMPSTAT_INC(ipcomps_crypto);
495 DPRINTF(("%s: failed to allocate xform_data\n", __func__));
505 xd->protoff = protoff;
507 xd->cryptoid = cryptoid;
509 /* Crypto operation descriptor */
510 crp->crp_flags = CRYPTO_F_CBIFSYNC;
511 crypto_use_mbuf(crp, m);
512 crp->crp_callback = ipcomp_output_cb;
513 crp->crp_opaque = xd;
515 return crypto_dispatch(crp);
525 * IPComp output callback from the crypto driver.
528 ipcomp_output_cb(struct cryptop *crp)
530 IPSEC_DEBUG_DECLARE(char buf[IPSEC_ADDRSTRLEN]);
531 struct xform_data *xd;
532 struct secpolicy *sp;
533 struct secasvar *sav;
535 crypto_session_t cryptoid;
537 int error, skip, protoff;
539 m = crp->crp_buf.cb_mbuf;
540 xd = crp->crp_opaque;
541 CURVNET_SET(xd->vnet);
546 protoff = xd->protoff;
547 cryptoid = xd->cryptoid;
549 /* Check for crypto errors */
550 if (crp->crp_etype) {
551 if (crp->crp_etype == EAGAIN) {
552 /* Reset the session ID */
553 if (ipsec_updateid(sav, &crp->crp_session, &cryptoid) != 0)
554 crypto_freesession(cryptoid);
555 xd->cryptoid = crp->crp_session;
557 return (crypto_dispatch(crp));
559 IPCOMPSTAT_INC(ipcomps_noxform);
560 DPRINTF(("%s: crypto error %d\n", __func__, crp->crp_etype));
561 error = crp->crp_etype;
564 /* Shouldn't happen... */
566 IPCOMPSTAT_INC(ipcomps_crypto);
567 DPRINTF(("%s: bogus return buffer from crypto\n", __func__));
571 IPCOMPSTAT_INC(ipcomps_hist[sav->alg_comp]);
573 if (crp->crp_payload_length > crp->crp_olen) {
575 struct ipcomp *ipcomp;
579 /* Compression helped, inject IPCOMP header. */
580 mo = m_makespace(m, skip, IPCOMP_HLENGTH, &roff);
582 IPCOMPSTAT_INC(ipcomps_wrap);
583 DPRINTF(("%s: IPCOMP header inject failed "
584 "for IPCA %s/%08lx\n",
585 __func__, ipsec_address(&sav->sah->saidx.dst, buf,
586 sizeof(buf)), (u_long) ntohl(sav->spi)));
590 ipcomp = (struct ipcomp *)(mtod(mo, caddr_t) + roff);
592 /* Initialize the IPCOMP header */
593 /* XXX alignment always correct? */
594 switch (sav->sah->saidx.dst.sa.sa_family) {
597 ipcomp->comp_nxt = mtod(m, struct ip *)->ip_p;
602 ipcomp->comp_nxt = mtod(m, struct ip6_hdr *)->ip6_nxt;
606 ipcomp->comp_flags = 0;
607 ipcomp->comp_cpi = htons((u_int16_t) ntohl(sav->spi));
609 /* Fix Next Protocol in IPv4/IPv6 header */
610 prot = IPPROTO_IPCOMP;
611 m_copyback(m, protoff, sizeof(u_int8_t),
614 /* Adjust the length in the IP header */
615 switch (sav->sah->saidx.dst.sa.sa_family) {
618 mtod(m, struct ip *)->ip_len = htons(m->m_pkthdr.len);
623 mtod(m, struct ip6_hdr *)->ip6_plen =
624 htons(m->m_pkthdr.len) - sizeof(struct ip6_hdr);
628 IPCOMPSTAT_INC(ipcomps_nopf);
629 DPRINTF(("%s: unknown/unsupported protocol "
630 "family %d, IPCA %s/%08lx\n", __func__,
631 sav->sah->saidx.dst.sa.sa_family,
632 ipsec_address(&sav->sah->saidx.dst, buf,
633 sizeof(buf)), (u_long) ntohl(sav->spi)));
634 error = EPFNOSUPPORT;
638 /* Compression was useless, we have lost time. */
639 IPCOMPSTAT_INC(ipcomps_uncompr);
640 DPRINTF(("%s: compressions was useless %d <= %d\n",
641 __func__, crp->crp_payload_length, crp->crp_olen));
642 /* XXX remember state to not compress the next couple
643 * of packets, RFC 3173, 2.2. Non-Expansion Policy */
646 /* Release the crypto descriptor */
650 /* NB: m is reclaimed by ipsec_process_done. */
651 error = ipsec_process_done(m, sp, sav, idx);
667 ipcomp4_nonexp_encapcheck(const struct mbuf *m, int off, int proto,
670 union sockaddr_union src, dst;
673 if (V_ipcomp_enable == 0)
675 if (proto != IPPROTO_IPV4 && proto != IPPROTO_IPV6)
677 bzero(&src, sizeof(src));
678 bzero(&dst, sizeof(dst));
679 src.sa.sa_family = dst.sa.sa_family = AF_INET;
680 src.sin.sin_len = dst.sin.sin_len = sizeof(struct sockaddr_in);
681 ip = mtod(m, const struct ip *);
682 src.sin.sin_addr = ip->ip_src;
683 dst.sin.sin_addr = ip->ip_dst;
684 return (ipcomp_encapcheck(&src, &dst));
687 static const struct encaptab *ipe4_cookie = NULL;
688 static const struct encap_config ipv4_encap_cfg = {
690 .min_length = sizeof(struct ip),
691 .exact_match = sizeof(in_addr_t) << 4,
692 .check = ipcomp4_nonexp_encapcheck,
693 .input = ipcomp_nonexp_input
698 ipcomp6_nonexp_encapcheck(const struct mbuf *m, int off, int proto,
701 union sockaddr_union src, dst;
702 const struct ip6_hdr *ip6;
704 if (V_ipcomp_enable == 0)
706 if (proto != IPPROTO_IPV4 && proto != IPPROTO_IPV6)
708 bzero(&src, sizeof(src));
709 bzero(&dst, sizeof(dst));
710 src.sa.sa_family = dst.sa.sa_family = AF_INET;
711 src.sin6.sin6_len = dst.sin6.sin6_len = sizeof(struct sockaddr_in6);
712 ip6 = mtod(m, const struct ip6_hdr *);
713 src.sin6.sin6_addr = ip6->ip6_src;
714 dst.sin6.sin6_addr = ip6->ip6_dst;
715 if (IN6_IS_SCOPE_LINKLOCAL(&src.sin6.sin6_addr)) {
716 /* XXX: sa6_recoverscope() */
717 src.sin6.sin6_scope_id =
718 ntohs(src.sin6.sin6_addr.s6_addr16[1]);
719 src.sin6.sin6_addr.s6_addr16[1] = 0;
721 if (IN6_IS_SCOPE_LINKLOCAL(&dst.sin6.sin6_addr)) {
722 /* XXX: sa6_recoverscope() */
723 dst.sin6.sin6_scope_id =
724 ntohs(dst.sin6.sin6_addr.s6_addr16[1]);
725 dst.sin6.sin6_addr.s6_addr16[1] = 0;
727 return (ipcomp_encapcheck(&src, &dst));
730 static const struct encaptab *ipe6_cookie = NULL;
731 static const struct encap_config ipv6_encap_cfg = {
733 .min_length = sizeof(struct ip6_hdr),
734 .exact_match = sizeof(struct in6_addr) << 4,
735 .check = ipcomp6_nonexp_encapcheck,
736 .input = ipcomp_nonexp_input
740 static struct xformsw ipcomp_xformsw = {
741 .xf_type = XF_IPCOMP,
743 .xf_init = ipcomp_init,
744 .xf_cleanup = ipcomp_cleanup,
745 .xf_input = ipcomp_input,
746 .xf_output = ipcomp_output,
754 ipe4_cookie = ip_encap_attach(&ipv4_encap_cfg, NULL, M_WAITOK);
757 ipe6_cookie = ip6_encap_attach(&ipv6_encap_cfg, NULL, M_WAITOK);
759 xform_attach(&ipcomp_xformsw);
767 ip_encap_detach(ipe4_cookie);
770 ip6_encap_detach(ipe6_cookie);
772 xform_detach(&ipcomp_xformsw);
775 SYSINIT(ipcomp_xform_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE,
776 ipcomp_attach, NULL);
777 SYSUNINIT(ipcomp_xform_uninit, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE,
778 ipcomp_detach, NULL);