X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/43866e378188c25dd1e2208016ab3cbeb086ae6c..ecc0ceb4089d506a0b8d16686a95817b331af9cb:/bsd/netinet/ip_encap.c diff --git a/bsd/netinet/ip_encap.c b/bsd/netinet/ip_encap.c index 5ae39bb90..6c4d33072 100644 --- a/bsd/netinet/ip_encap.c +++ b/bsd/netinet/ip_encap.c @@ -1,16 +1,19 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2012 Apple Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, 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. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * 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 @@ -20,7 +23,7 @@ * Please see the License for the specific language governing rights and * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* $FreeBSD: src/sys/netinet/ip_encap.c,v 1.1.2.2 2001/07/03 11:01:46 ume Exp $ */ /* $KAME: ip_encap.c,v 1.41 2001/03/15 08:35:08 itojun Exp $ */ @@ -85,7 +88,9 @@ #include #include #include +#include #include +#include #include #include @@ -97,9 +102,6 @@ #include #include #include -#if MROUTING -#include -#endif /* MROUTING */ #if INET6 #include @@ -116,10 +118,11 @@ MALLOC_DEFINE(M_NETADDR, "Export Host", "Export host address structure"); #endif -static void encap_add __P((struct encaptab *)); -static int mask_match __P((const struct encaptab *, const struct sockaddr *, - const struct sockaddr *)); -static void encap_fillarg __P((struct mbuf *, const struct encaptab *)); +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 *); +static void encap_fillarg(struct mbuf *, const struct encaptab *); #ifndef LIST_HEAD_INITIALIZER /* rely upon BSS initialization */ @@ -128,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 @@ -148,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) @@ -168,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; @@ -237,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); } @@ -256,9 +266,7 @@ encap4_input(m, off) #if INET6 int -encap6_input(mp, offp) - struct mbuf **mp; - int *offp; +encap6_input(struct mbuf **mp, int *offp, int proto) { struct mbuf *m = *mp; struct ip6_hdr *ip6; @@ -266,11 +274,11 @@ encap6_input(mp, offp) const struct ip6protosw *psw; struct encaptab *ep, *match; int prio, matchprio; - int proto; - ip6 = mtod(m, struct ip6_hdr *); - proto = ip6->ip6_nxt; + /* 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); @@ -312,7 +320,7 @@ encap6_input(mp, offp) psw = (const struct ip6protosw *)match->psw; if (psw && psw->pr_input) { encap_fillarg(m, match); - return (*psw->pr_input)(mp, offp); + return (*psw->pr_input)(mp, offp, proto); } else { m_freem(m); return IPPROTO_DONE; @@ -320,7 +328,7 @@ encap6_input(mp, offp) } /* last resort: inject to raw socket */ - return rip6_input(mp, offp); + return rip6_input(mp, offp, proto); } #endif @@ -348,9 +356,7 @@ encap_attach(af, proto, sp, sm, dp, dm, psw, arg) { struct encaptab *ep; int error; - int s; - s = splnet(); /* sanity check on args */ if (sp->sa_len > sizeof(ep->src) || dp->sa_len > sizeof(ep->dst)) { error = EINVAL; @@ -384,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; @@ -403,11 +408,9 @@ encap_attach(af, proto, sp, sm, dp, dm, psw, arg) encap_add(ep); error = 0; - splx(s); return ep; fail: - splx(s); return NULL; } @@ -415,27 +418,24 @@ const struct encaptab * encap_attach_func(af, proto, func, psw, arg) int af; int proto; - int (*func) __P((const struct mbuf *, int, int, void *)); + int (*func)(const struct mbuf *, int, int, void *); const struct protosw *psw; void *arg; { struct encaptab *ep; int error; - int s; - s = splnet(); /* sanity check on args */ if (!func) { error = EINVAL; 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; @@ -446,11 +446,9 @@ encap_attach_func(af, proto, func, psw, arg) encap_add(ep); error = 0; - splx(s); return ep; fail: - splx(s); return NULL; } @@ -525,43 +523,42 @@ mask_match(ep, sp, dp) return 0; } +struct encaptabtag { + void* *arg; +}; + static void -encap_fillarg(m, ep) - struct mbuf *m; - const struct encaptab *ep; +encap_fillarg( + struct mbuf *m, + const struct encaptab *ep) { -#if 0 - m->m_pkthdr.aux = ep->arg; -#else - struct mbuf *n; - - n = m_aux_add(m, AF_INET, IPPROTO_IPV4); - if (n) { - *mtod(n, void **) = ep->arg; - n->m_len = sizeof(void *); + struct m_tag *tag; + struct encaptabtag *et; + + tag = m_tag_create(KERNEL_MODULE_TAG_ID, KERNEL_TAG_TYPE_ENCAP, + sizeof(struct encaptabtag), M_WAITOK, m); + + if (tag != NULL) { + et = (struct encaptabtag*)(tag + 1); + et->arg = ep->arg; + m_tag_prepend(m, tag); } -#endif } void * encap_getarg(m) struct mbuf *m; { - void *p; -#if 0 - p = m->m_pkthdr.aux; - m->m_pkthdr.aux = NULL; - return p; -#else - struct mbuf *n; - - p = NULL; - n = m_aux_find(m, AF_INET, IPPROTO_IPV4); - if (n) { - if (n->m_len == sizeof(void *)) - p = *mtod(n, void **); - m_aux_delete(m, n); + struct m_tag *tag; + struct encaptabtag *et; + void *p = NULL; + + tag = m_tag_locate(m, KERNEL_MODULE_TAG_ID, KERNEL_TAG_TYPE_ENCAP, NULL); + if (tag) { + et = (struct encaptabtag*)(tag + 1); + p = et->arg; + m_tag_delete(m, tag); } + return p; -#endif }