#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
+#include <sys/mcache.h>
#include <sys/domain.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/route.h>
-#include <net/netisr.h>
-#include <net/zlib.h>
+#include <libkern/zlib.h>
#include <kern/cpu_number.h>
+#include <kern/locks.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
#include <netinet/ip_ecn.h>
+#include <netinet/kpi_ipfilter_var.h>
#if INET6
#include <netinet/ip6.h>
#include <netkey/keydb.h>
#include <net/net_osdep.h>
+#include <mach/sdt.h>
#define IPLEN_FLIPPED
-
void
ipcomp4_input(struct mbuf *m, int off)
{
size_t newlen, olen;
struct secasvar *sav = NULL;
-
if (m->m_pkthdr.len < off + sizeof(struct ipcomp)) {
ipseclog((LOG_DEBUG, "IPv4 IPComp input: assumption failed "
"(packet too short)\n"));
- ipsecstat.in_inval++;
+ IPSEC_STAT_INCREMENT(ipsecstat.in_inval);
goto fail;
}
md = m_pulldown(m, off, sizeof(*ipcomp), NULL);
- if (!m) {
+ if (!md) {
m = NULL; /*already freed*/
ipseclog((LOG_DEBUG, "IPv4 IPComp input: assumption failed "
"(pulldown failure)\n"));
- ipsecstat.in_inval++;
+ IPSEC_STAT_INCREMENT(ipsecstat.in_inval);
goto fail;
}
ipcomp = mtod(md, struct ipcomp *);
+
+ /* Expect 32-bit aligned data pointer on strict-align platforms */
+ MBUF_STRICT_DATA_ALIGNMENT_CHECK_32(m);
+
ip = mtod(m, struct ip *);
nxt = ipcomp->comp_nxt;
#ifdef _IP_VHL
if (!algo) {
ipseclog((LOG_WARNING, "IPv4 IPComp input: unknown cpi %u\n",
cpi));
- ipsecstat.in_nosa++;
+ IPSEC_STAT_INCREMENT(ipsecstat.in_nosa);
goto fail;
}
newlen = m->m_pkthdr.len - off;
error = (*algo->decompress)(m, m->m_next, &newlen);
if (error != 0) {
- if (error == EINVAL)
- ipsecstat.in_inval++;
- else if (error == ENOBUFS)
- ipsecstat.in_nomem++;
+ if (error == EINVAL) {
+ IPSEC_STAT_INCREMENT(ipsecstat.in_inval);
+ } else if (error == ENOBUFS)
+ IPSEC_STAT_INCREMENT(ipsecstat.in_nomem);
m = NULL;
goto fail;
}
- ipsecstat.in_comphist[cpi]++;
+ IPSEC_STAT_INCREMENT(ipsecstat.in_comphist[cpi]);
/*
* returning decompressed packet onto icmp is meaningless.
len -= olen;
if (len & ~0xffff) {
/* packet too big after decompress */
- ipsecstat.in_inval++;
+ IPSEC_STAT_INCREMENT(ipsecstat.in_inval);
goto fail;
}
#ifdef IPLEN_FLIPPED
if (sav) {
key_sa_recordxfer(sav, m);
if (ipsec_addhist(m, IPPROTO_IPCOMP, (u_int32_t)cpi) != 0) {
- ipsecstat.in_nomem++;
+ IPSEC_STAT_INCREMENT(ipsecstat.in_nomem);
goto fail;
}
- key_freesav(sav);
+ key_freesav(sav, KEY_SADB_UNLOCKED);
sav = NULL;
}
if (nxt != IPPROTO_DONE) {
if ((ip_protox[nxt]->pr_flags & PR_LASTHDR) != 0 &&
ipsec4_in_reject(m, NULL)) {
- ipsecstat.in_polvio++;
+ IPSEC_STAT_INCREMENT(ipsecstat.in_polvio);
goto fail;
}
- (*ip_protox[nxt]->pr_input)(m, off);
+ DTRACE_IP6(receive, struct mbuf *, m, struct inpcb *, NULL,
+ struct ip *, ip, struct ifnet *, m->m_pkthdr.rcvif,
+ struct ip *, ip, struct ip6_hdr *, NULL);
+
+ ip_proto_dispatch_in(m, off, nxt, 0);
} else
m_freem(m);
m = NULL;
- ipsecstat.in_success++;
+ IPSEC_STAT_INCREMENT(ipsecstat.in_success);
return;
fail:
if (sav)
- key_freesav(sav);
+ key_freesav(sav, KEY_SADB_UNLOCKED);
+
if (m)
m_freem(m);
return;
#if INET6
int
-ipcomp6_input(mp, offp)
- struct mbuf **mp;
- int *offp;
+ipcomp6_input(struct mbuf **mp, int *offp, int proto)
{
+#pragma unused(proto)
struct mbuf *m, *md;
int off;
struct ip6_hdr *ip6;
off = *offp;
md = m_pulldown(m, off, sizeof(*ipcomp), NULL);
- if (!m) {
+ if (!md) {
m = NULL; /*already freed*/
ipseclog((LOG_DEBUG, "IPv6 IPComp input: assumption failed "
"(pulldown failure)\n"));
- ipsec6stat.in_inval++;
+ IPSEC_STAT_INCREMENT(ipsec6stat.in_inval);
goto fail;
}
ipcomp = mtod(md, struct ipcomp *);
+
+ /* Expect 32-bit aligned data pointer on strict-align platforms */
+ MBUF_STRICT_DATA_ALIGNMENT_CHECK_32(m);
+
ip6 = mtod(m, struct ip6_hdr *);
nxt = ipcomp->comp_nxt;
if (!algo) {
ipseclog((LOG_WARNING, "IPv6 IPComp input: unknown cpi %u; "
"dropping the packet for simplicity\n", cpi));
- ipsec6stat.in_nosa++;
+ IPSEC_STAT_INCREMENT(ipsec6stat.in_nosa);
goto fail;
}
newlen = m->m_pkthdr.len - off;
error = (*algo->decompress)(m, md, &newlen);
if (error != 0) {
- if (error == EINVAL)
- ipsec6stat.in_inval++;
- else if (error == ENOBUFS)
- ipsec6stat.in_nomem++;
+ if (error == EINVAL) {
+ IPSEC_STAT_INCREMENT(ipsec6stat.in_inval);
+ } else if (error == ENOBUFS)
+ IPSEC_STAT_INCREMENT(ipsec6stat.in_nomem);
m = NULL;
goto fail;
}
- ipsec6stat.in_comphist[cpi]++;
+ IPSEC_STAT_INCREMENT(ipsec6stat.in_comphist[cpi]);
m->m_pkthdr.len = off + newlen;
/*
if (sav) {
key_sa_recordxfer(sav, m);
if (ipsec_addhist(m, IPPROTO_IPCOMP, (u_int32_t)cpi) != 0) {
- ipsec6stat.in_nomem++;
+ IPSEC_STAT_INCREMENT(ipsec6stat.in_nomem);
goto fail;
}
- key_freesav(sav);
+ key_freesav(sav, KEY_SADB_UNLOCKED);
sav = NULL;
}
*offp = off;
*mp = m;
- ipsec6stat.in_success++;
+ IPSEC_STAT_INCREMENT(ipsec6stat.in_success);
return nxt;
fail:
if (m)
m_freem(m);
if (sav)
- key_freesav(sav);
+ key_freesav(sav, KEY_SADB_UNLOCKED);
return IPPROTO_DONE;
}
#endif /* INET6 */