]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/netinet6/ipcomp_core.c
xnu-3789.70.16.tar.gz
[apple/xnu.git] / bsd / netinet6 / ipcomp_core.c
index 1ca1038606bfdb2b82ba110b788910e4284e1c9e..01c9e928b5829f87502ea488ea28bb1578aeb8d9 100644 (file)
@@ -1,3 +1,31 @@
+/*
+ * Copyright (c) 2016 Apple Inc. All rights reserved.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ *
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ */
+
 /*     $FreeBSD: src/sys/netinet6/ipcomp_core.c,v 1.1.2.2 2001/07/03 11:01:54 ume Exp $        */
 /*     $KAME: ipcomp_core.c,v 1.24 2000/10/23 04:24:22 itojun Exp $    */
 
@@ -50,8 +78,9 @@
 
 #include <net/if.h>
 #include <net/route.h>
-#include <net/netisr.h>
-#include <net/zlib.h>
+#if IPCOMP_ZLIB
+#include <libkern/zlib.h>
+#endif
 #include <kern/cpu_number.h>
 
 #include <netinet6/ipcomp.h>
 
 #include <net/net_osdep.h>
 
-static void *deflate_alloc __P((void *, u_int, u_int));
-static void deflate_free __P((void *, void *));
-static int deflate_common __P((struct mbuf *, struct mbuf *, size_t *, int));
-static int deflate_compress __P((struct mbuf *, struct mbuf *, size_t *));
-static int deflate_decompress __P((struct mbuf *, struct mbuf *, size_t *));
+#if IPCOMP_ZLIB
+static void *deflate_alloc(void *, u_int, u_int);
+static void deflate_free(void *, void *);
+static int deflate_common(struct mbuf *, struct mbuf *, size_t *, int);
+static int deflate_compress(struct mbuf *, struct mbuf *, size_t *);
+static int deflate_decompress(struct mbuf *, struct mbuf *, size_t *);
 
 /*
  * We need to use default window size (2^15 = 32Kbytes as of writing) for
@@ -84,16 +114,26 @@ static int deflate_memlevel = MAX_MEM_LEVEL;
 
 static z_stream        deflate_stream;
 static z_stream        inflate_stream;
+#endif /* IPCOMP_ZLIB */
 
+#if IPCOMP_ZLIB
 static const struct ipcomp_algorithm ipcomp_algorithms[] = {
        { deflate_compress, deflate_decompress, 90 },
 };
+#else
+static const struct ipcomp_algorithm ipcomp_algorithms[] __unused = {};
+#endif
 
 const struct ipcomp_algorithm *
-ipcomp_algorithm_lookup(idx)
-       int idx;
+ipcomp_algorithm_lookup(
+#if IPCOMP_ZLIB
+               int idx
+#else
+               __unused int idx
+#endif
+               )
 {
-
+#if IPCOMP_ZLIB
        if (idx == SADB_X_CALG_DEFLATE) {
                /*
                 * Avert your gaze, ugly hack follows!
@@ -130,34 +170,33 @@ ipcomp_algorithm_lookup(idx)
 
                return &ipcomp_algorithms[0];
        }
+#endif /* IPCOMP_ZLIB */
        return NULL;
 }
 
+#if IPCOMP_ZLIB
 static void *
-deflate_alloc(aux, items, siz)
-       void *aux;
-       u_int items;
-       u_int siz;
+deflate_alloc(
+       __unused void *aux,
+       u_int items,
+       u_int siz)
 {
        void *ptr;
-       ptr = _MALLOC(items * siz, M_TEMP, M_WAIT);
+       ptr = _MALLOC(items * siz, M_TEMP, M_NOWAIT);
        return ptr;
 }
 
 static void
-deflate_free(aux, ptr)
-       void *aux;
-       void *ptr;
+deflate_free(
+       __unused void *aux,
+       void *ptr)
 {
        FREE(ptr, M_TEMP);
 }
 
+/* @param mode 0: compress 1: decompress */
 static int
-deflate_common(m, md, lenp, mode)
-       struct mbuf *m;
-       struct mbuf *md;
-       size_t *lenp;
-       int mode;       /* 0: compress 1: decompress */
+deflate_common(struct mbuf *m, struct mbuf *md, size_t *lenp, int mode)
 {
        struct mbuf *mprev;
        struct mbuf *p;
@@ -260,8 +299,8 @@ do { \
                        /* inflate: Z_OK can indicate the end of decode */
                        if (mode && !p && zs->avail_out != 0)
                                goto terminate;
-                       else
-                               ; /*once more.*/
+                       
+                       /* else once more.*/
                } else {
                        if (zs->msg) {
                                ipseclog((LOG_ERR, "ipcomp_%scompress: "
@@ -368,10 +407,7 @@ fail:
 }
 
 static int
-deflate_compress(m, md, lenp)
-       struct mbuf *m;
-       struct mbuf *md;
-       size_t *lenp;
+deflate_compress(struct mbuf *m, struct mbuf *md, size_t *lenp)
 {
        if (!m)
                panic("m == NULL in deflate_compress");
@@ -384,10 +420,7 @@ deflate_compress(m, md, lenp)
 }
 
 static int
-deflate_decompress(m, md, lenp)
-       struct mbuf *m;
-       struct mbuf *md;
-       size_t *lenp;
+deflate_decompress(struct mbuf *m, struct mbuf *md, size_t *lenp)
 {
        if (!m)
                panic("m == NULL in deflate_decompress");
@@ -398,3 +431,4 @@ deflate_decompress(m, md, lenp)
 
        return deflate_common(m, md, lenp, 1);
 }
+#endif /* IPCOMP_ZLIB */