]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/netinet/ip_encap.c
xnu-3248.40.184.tar.gz
[apple/xnu.git] / bsd / netinet / ip_encap.c
index 0d487326a28b0c1d3b3908bf2dd608e0ada99894..6c4d33072b487d1204faf025ace058bab8282ec1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000,2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2012 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -88,7 +88,9 @@
 #include <sys/socket.h>
 #include <sys/sockio.h>
 #include <sys/mbuf.h>
+#include <sys/mcache.h>
 #include <sys/errno.h>
+#include <sys/domain.h>
 #include <sys/protosw.h>
 #include <sys/queue.h>
 
 #include <netinet/ip.h>
 #include <netinet/ip_var.h>
 #include <netinet/ip_encap.h>
-#if MROUTING
-#include <netinet/ip_mroute.h>
-#endif /* MROUTING */
 
 #if INET6
 #include <netinet/ip6.h>
 MALLOC_DEFINE(M_NETADDR, "Export Host", "Export host address structure");
 #endif
 
+static void encap_init(struct protosw *, struct domain *);
 static void encap_add(struct encaptab *);
 static int mask_match(const struct encaptab *, const struct sockaddr *,
                const struct sockaddr *);
@@ -131,14 +131,18 @@ LIST_HEAD(, encaptab) encaptab;
 LIST_HEAD(, encaptab) encaptab = LIST_HEAD_INITIALIZER(&encaptab);
 #endif
 
-void
-encap_init()
+static void
+encap_init(struct protosw *pp, struct domain *dp)
 {
-       static int initialized = 0;
+#pragma unused(dp)
+       static int encap_initialized = 0;
+
+       VERIFY((pp->pr_flags & (PR_INITIALIZED|PR_ATTACHED)) == PR_ATTACHED);
 
-       if (initialized)
+       /* This gets called by more than one protocols, so initialize once */
+       if (encap_initialized)
                return;
-       initialized++;
+       encap_initialized = 1;
 #if 0
        /*
         * we cannot use LIST_INIT() here, since drivers may want to call
@@ -151,6 +155,18 @@ encap_init()
 #endif
 }
 
+void
+encap4_init(struct protosw *pp, struct domain *dp)
+{
+       encap_init(pp, dp);
+}
+
+void
+encap6_init(struct ip6protosw *pp, struct domain *dp)
+{
+       encap_init((struct protosw *)pp, dp);
+}
+
 #if INET
 void
 encap4_input(m, off)
@@ -171,6 +187,9 @@ encap4_input(m, off)
        va_end(ap);
 #endif
 
+       /* Expect 32-bit aligned data pointer on strict-align platforms */
+       MBUF_STRICT_DATA_ALIGNMENT_CHECK_32(m);
+
        ip = mtod(m, struct ip *);
 #ifdef __APPLE__
        proto = ip->ip_p;
@@ -240,18 +259,6 @@ encap4_input(m, off)
                return;
        }
 
-       /* for backward compatibility */
-# if MROUTING
-#  define COMPATFUNC   ipip_input
-# endif /*MROUTING*/
-
-#if COMPATFUNC
-       if (proto == IPPROTO_IPV4) {
-               COMPATFUNC(m, off);
-               return;
-       }
-#endif
-
        /* last resort: inject to raw socket */
        rip_input(m, off);
 }
@@ -268,8 +275,10 @@ encap6_input(struct mbuf **mp, int *offp, int proto)
        struct encaptab *ep, *match;
        int prio, matchprio;
 
-       ip6 = mtod(m, struct ip6_hdr *);
+       /* Expect 32-bit aligned data pointer on strict-align platforms */
+       MBUF_STRICT_DATA_ALIGNMENT_CHECK_32(m);
 
+       ip6 = mtod(m, struct ip6_hdr *);
        bzero(&s, sizeof(s));
        s.sin6_family = AF_INET6;
        s.sin6_len = sizeof(struct sockaddr_in6);
@@ -381,12 +390,11 @@ encap_attach(af, proto, sp, sm, dp, dm, psw, arg)
                goto fail;
        }
 
-       ep = _MALLOC(sizeof(*ep), M_NETADDR, M_WAITOK); /*XXX*/
+       ep = _MALLOC(sizeof(*ep), M_NETADDR, M_WAITOK | M_ZERO); /* XXX */
        if (ep == NULL) {
                error = ENOBUFS;
                goto fail;
        }
-       bzero(ep, sizeof(*ep));
 
        ep->af = af;
        ep->proto = proto;
@@ -423,12 +431,11 @@ encap_attach_func(af, proto, func, psw, arg)
                goto fail;
        }
 
-       ep = _MALLOC(sizeof(*ep), M_NETADDR, M_WAITOK); /*XXX*/
+       ep = _MALLOC(sizeof(*ep), M_NETADDR, M_WAITOK | M_ZERO); /* XXX */
        if (ep == NULL) {
                error = ENOBUFS;
                goto fail;
        }
-       bzero(ep, sizeof(*ep));
 
        ep->af = af;
        ep->proto = proto;