2002-10-16 02:10:08 +00:00
|
|
|
/* $FreeBSD$ */
|
|
|
|
/* $OpenBSD: ip_ipcomp.c,v 1.1 2001/07/05 12:08:52 jjbg Exp $ */
|
|
|
|
|
2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
2002-10-16 02:10:08 +00:00
|
|
|
* Copyright (c) 2001 Jean-Jacques Bernard-Gundol (jj@wabbitt.org)
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* IP payload compression protocol (IPComp), see RFC 2393 */
|
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_inet6.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
2003-09-01 05:35:55 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
2002-10-16 02:10:08 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_var.h>
|
2016-04-24 09:02:17 +00:00
|
|
|
#include <netinet/ip_encap.h>
|
2002-10-16 02:10:08 +00:00
|
|
|
|
2016-04-24 09:02:17 +00:00
|
|
|
#include <net/netisr.h>
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
#include <net/vnet.h>
|
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
#include <netipsec/ipsec.h>
|
|
|
|
#include <netipsec/xform.h>
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet/ip6.h>
|
2016-04-24 17:09:51 +00:00
|
|
|
#include <netinet6/ip6_var.h>
|
2002-10-16 02:10:08 +00:00
|
|
|
#include <netipsec/ipsec6.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <netipsec/ipcomp.h>
|
|
|
|
#include <netipsec/ipcomp_var.h>
|
|
|
|
|
|
|
|
#include <netipsec/key.h>
|
2017-02-06 08:49:57 +00:00
|
|
|
#include <netipsec/key_debug.h>
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
#include <opencrypto/cryptodev.h>
|
|
|
|
#include <opencrypto/deflate.h>
|
|
|
|
#include <opencrypto/xform.h>
|
|
|
|
|
2009-11-29 20:47:43 +00:00
|
|
|
VNET_DEFINE(int, ipcomp_enable) = 1;
|
2013-07-09 10:08:13 +00:00
|
|
|
VNET_PCPUSTAT_DEFINE(struct ipcompstat, ipcompstat);
|
|
|
|
VNET_PCPUSTAT_SYSINIT(ipcompstat);
|
|
|
|
|
|
|
|
#ifdef VIMAGE
|
|
|
|
VNET_PCPUSTAT_SYSUNINIT(ipcompstat);
|
|
|
|
#endif /* VIMAGE */
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
SYSCTL_DECL(_net_inet_ipcomp);
|
2014-11-07 09:39:05 +00:00
|
|
|
SYSCTL_INT(_net_inet_ipcomp, OID_AUTO, ipcomp_enable,
|
|
|
|
CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ipcomp_enable), 0, "");
|
2013-07-09 10:08:13 +00:00
|
|
|
SYSCTL_VNET_PCPUSTAT(_net_inet_ipcomp, IPSECCTL_STATS, stats,
|
|
|
|
struct ipcompstat, ipcompstat,
|
|
|
|
"IPCOMP statistics (struct ipcompstat, netipsec/ipcomp_var.h");
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
static int ipcomp_input_cb(struct cryptop *crp);
|
|
|
|
static int ipcomp_output_cb(struct cryptop *crp);
|
|
|
|
|
2016-04-24 09:02:17 +00:00
|
|
|
/*
|
|
|
|
* RFC 3173 p 2.2. Non-Expansion Policy:
|
|
|
|
* If the total size of a compressed payload and the IPComp header, as
|
|
|
|
* defined in section 3, is not smaller than the size of the original
|
|
|
|
* payload, the IP datagram MUST be sent in the original non-compressed
|
|
|
|
* form.
|
|
|
|
*
|
|
|
|
* When we use IPComp in tunnel mode, for small packets we will receive
|
|
|
|
* encapsulated IP-IP datagrams without any compression and without IPComp
|
|
|
|
* header.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ipcomp_encapcheck(union sockaddr_union *src, union sockaddr_union *dst)
|
|
|
|
{
|
|
|
|
struct secasvar *sav;
|
|
|
|
|
2017-02-06 08:49:57 +00:00
|
|
|
sav = key_allocsa_tunnel(src, dst, IPPROTO_IPCOMP);
|
2016-04-24 09:02:17 +00:00
|
|
|
if (sav == NULL)
|
|
|
|
return (0);
|
2017-02-06 08:49:57 +00:00
|
|
|
key_freesav(&sav);
|
2016-04-24 09:02:17 +00:00
|
|
|
|
|
|
|
if (src->sa.sa_family == AF_INET)
|
|
|
|
return (sizeof(struct in_addr) << 4);
|
|
|
|
else
|
|
|
|
return (sizeof(struct in6_addr) << 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ipcomp_nonexp_input(struct mbuf **mp, int *offp, int proto)
|
|
|
|
{
|
|
|
|
int isr;
|
|
|
|
|
|
|
|
switch (proto) {
|
|
|
|
#ifdef INET
|
|
|
|
case IPPROTO_IPV4:
|
|
|
|
isr = NETISR_IP;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case IPPROTO_IPV6:
|
|
|
|
isr = NETISR_IPV6;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
IPCOMPSTAT_INC(ipcomps_nopf);
|
|
|
|
m_freem(*mp);
|
|
|
|
return (IPPROTO_DONE);
|
|
|
|
}
|
|
|
|
m_adj(*mp, *offp);
|
|
|
|
IPCOMPSTAT_ADD(ipcomps_ibytes, (*mp)->m_pkthdr.len);
|
|
|
|
IPCOMPSTAT_INC(ipcomps_input);
|
|
|
|
netisr_dispatch(isr, *mp);
|
|
|
|
return (IPPROTO_DONE);
|
|
|
|
}
|
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
/*
|
|
|
|
* ipcomp_init() is called when an CPI is being set up.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ipcomp_init(struct secasvar *sav, struct xformsw *xsp)
|
|
|
|
{
|
2017-02-06 08:49:57 +00:00
|
|
|
const struct comp_algo *tcomp;
|
2002-10-16 02:10:08 +00:00
|
|
|
struct cryptoini cric;
|
|
|
|
|
|
|
|
/* NB: algorithm really comes in alg_enc and not alg_comp! */
|
2017-02-06 08:49:57 +00:00
|
|
|
tcomp = comp_algorithm_lookup(sav->alg_enc);
|
2002-10-16 02:10:08 +00:00
|
|
|
if (tcomp == NULL) {
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: unsupported compression algorithm %d\n", __func__,
|
2002-10-16 02:10:08 +00:00
|
|
|
sav->alg_comp));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
sav->alg_comp = sav->alg_enc; /* set for doing histogram */
|
|
|
|
sav->tdb_xform = xsp;
|
|
|
|
sav->tdb_compalgxform = tcomp;
|
|
|
|
|
|
|
|
/* Initialize crypto session */
|
|
|
|
bzero(&cric, sizeof (cric));
|
|
|
|
cric.cri_alg = sav->tdb_compalgxform->type;
|
|
|
|
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
return crypto_newsession(&sav->tdb_cryptoid, &cric, V_crypto_support);
|
2002-10-16 02:10:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ipcomp_zeroize() used when IPCA is deleted
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ipcomp_zeroize(struct secasvar *sav)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = crypto_freesession(sav->tdb_cryptoid);
|
|
|
|
sav->tdb_cryptoid = 0;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ipcomp_input() gets called to uncompress an input packet
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ipcomp_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff)
|
|
|
|
{
|
2017-02-06 08:49:57 +00:00
|
|
|
struct xform_data *xd;
|
2002-10-16 02:10:08 +00:00
|
|
|
struct cryptodesc *crdc;
|
|
|
|
struct cryptop *crp;
|
2011-04-01 14:13:49 +00:00
|
|
|
struct ipcomp *ipcomp;
|
|
|
|
caddr_t addr;
|
2002-10-16 02:10:08 +00:00
|
|
|
int hlen = IPCOMP_HLENGTH;
|
|
|
|
|
2011-04-01 14:13:49 +00:00
|
|
|
/*
|
|
|
|
* Check that the next header of the IPComp is not IPComp again, before
|
|
|
|
* doing any real work. Given it is not possible to do double
|
|
|
|
* compression it means someone is playing tricks on us.
|
|
|
|
*/
|
|
|
|
if (m->m_len < skip + hlen && (m = m_pullup(m, skip + hlen)) == NULL) {
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_hdrops); /*XXX*/
|
2011-04-01 14:13:49 +00:00
|
|
|
DPRINTF(("%s: m_pullup failed\n", __func__));
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
addr = (caddr_t) mtod(m, struct ip *) + skip;
|
|
|
|
ipcomp = (struct ipcomp *)addr;
|
|
|
|
if (ipcomp->comp_nxt == IPPROTO_IPCOMP) {
|
|
|
|
m_freem(m);
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_pdrops); /* XXX have our own stats? */
|
2011-04-01 14:13:49 +00:00
|
|
|
DPRINTF(("%s: recursive compression detected\n", __func__));
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
/* Get crypto descriptors */
|
|
|
|
crp = crypto_getreq(1);
|
|
|
|
if (crp == NULL) {
|
|
|
|
m_freem(m);
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: no crypto descriptors\n", __func__));
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_crypto);
|
2002-10-16 02:10:08 +00:00
|
|
|
return ENOBUFS;
|
|
|
|
}
|
|
|
|
/* Get IPsec-specific opaque pointer */
|
2017-02-06 08:49:57 +00:00
|
|
|
xd = malloc(sizeof(*xd), M_XDATA, M_NOWAIT | M_ZERO);
|
|
|
|
if (xd == NULL) {
|
|
|
|
DPRINTF(("%s: cannot allocate xform_data\n", __func__));
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_crypto);
|
2017-02-06 08:49:57 +00:00
|
|
|
crypto_freereq(crp);
|
|
|
|
m_freem(m);
|
2002-10-16 02:10:08 +00:00
|
|
|
return ENOBUFS;
|
|
|
|
}
|
|
|
|
crdc = crp->crp_desc;
|
|
|
|
|
|
|
|
crdc->crd_skip = skip + hlen;
|
|
|
|
crdc->crd_len = m->m_pkthdr.len - (skip + hlen);
|
|
|
|
crdc->crd_inject = skip;
|
|
|
|
|
|
|
|
/* Decompression operation */
|
|
|
|
crdc->crd_alg = sav->tdb_compalgxform->type;
|
|
|
|
|
2017-02-06 08:49:57 +00:00
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
/* Crypto operation descriptor */
|
|
|
|
crp->crp_ilen = m->m_pkthdr.len - (skip + hlen);
|
2003-06-30 05:09:32 +00:00
|
|
|
crp->crp_flags = CRYPTO_F_IMBUF | CRYPTO_F_CBIFSYNC;
|
2002-10-16 02:10:08 +00:00
|
|
|
crp->crp_buf = (caddr_t) m;
|
|
|
|
crp->crp_callback = ipcomp_input_cb;
|
2017-02-06 08:49:57 +00:00
|
|
|
crp->crp_opaque = (caddr_t) xd;
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
/* These are passed as-is to the callback */
|
2017-02-06 08:49:57 +00:00
|
|
|
xd->sav = sav;
|
|
|
|
xd->protoff = protoff;
|
|
|
|
xd->skip = skip;
|
|
|
|
|
|
|
|
SECASVAR_LOCK(sav);
|
|
|
|
crp->crp_sid = xd->cryptoid = sav->tdb_cryptoid;
|
|
|
|
SECASVAR_UNLOCK(sav);
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
return crypto_dispatch(crp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IPComp input callback from the crypto driver.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ipcomp_input_cb(struct cryptop *crp)
|
|
|
|
{
|
2017-02-06 08:49:57 +00:00
|
|
|
char buf[IPSEC_ADDRSTRLEN];
|
2002-10-16 02:10:08 +00:00
|
|
|
struct cryptodesc *crd;
|
2017-02-06 08:49:57 +00:00
|
|
|
struct xform_data *xd;
|
2002-10-16 02:10:08 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
struct secasvar *sav;
|
|
|
|
struct secasindex *saidx;
|
|
|
|
caddr_t addr;
|
2017-02-06 08:49:57 +00:00
|
|
|
uint64_t cryptoid;
|
|
|
|
int hlen = IPCOMP_HLENGTH, error, clen;
|
|
|
|
int skip, protoff;
|
|
|
|
uint8_t nproto;
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
crd = crp->crp_desc;
|
|
|
|
|
|
|
|
m = (struct mbuf *) crp->crp_buf;
|
2017-02-06 08:49:57 +00:00
|
|
|
xd = (struct xform_data *) crp->crp_opaque;
|
|
|
|
sav = xd->sav;
|
|
|
|
skip = xd->skip;
|
|
|
|
protoff = xd->protoff;
|
|
|
|
cryptoid = xd->cryptoid;
|
2002-10-16 02:10:08 +00:00
|
|
|
saidx = &sav->sah->saidx;
|
2003-09-29 22:57:43 +00:00
|
|
|
IPSEC_ASSERT(saidx->dst.sa.sa_family == AF_INET ||
|
2002-10-16 02:10:08 +00:00
|
|
|
saidx->dst.sa.sa_family == AF_INET6,
|
2003-09-29 22:57:43 +00:00
|
|
|
("unexpected protocol family %u", saidx->dst.sa.sa_family));
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
/* Check for crypto errors */
|
|
|
|
if (crp->crp_etype) {
|
|
|
|
if (crp->crp_etype == EAGAIN) {
|
2017-02-06 08:49:57 +00:00
|
|
|
/* Reset the session ID */
|
|
|
|
if (ipsec_updateid(sav, &crp->crp_sid, &cryptoid) != 0)
|
|
|
|
crypto_freesession(cryptoid);
|
|
|
|
xd->cryptoid = crp->crp_sid;
|
|
|
|
return (crypto_dispatch(crp));
|
2002-10-16 02:10:08 +00:00
|
|
|
}
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_noxform);
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: crypto error %d\n", __func__, crp->crp_etype));
|
2002-10-16 02:10:08 +00:00
|
|
|
error = crp->crp_etype;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
/* Shouldn't happen... */
|
|
|
|
if (m == NULL) {
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_crypto);
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: null mbuf returned from crypto\n", __func__));
|
2002-10-16 02:10:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_hist[sav->alg_comp]);
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
clen = crp->crp_olen; /* Length of data after processing */
|
|
|
|
|
|
|
|
/* Release the crypto descriptors */
|
2017-02-06 08:49:57 +00:00
|
|
|
free(xd, M_XDATA), xd = NULL;
|
2002-10-16 02:10:08 +00:00
|
|
|
crypto_freereq(crp), crp = NULL;
|
|
|
|
|
|
|
|
/* In case it's not done already, adjust the size of the mbuf chain */
|
|
|
|
m->m_pkthdr.len = clen + hlen + skip;
|
|
|
|
|
2016-04-15 17:30:33 +00:00
|
|
|
if (m->m_len < skip + hlen && (m = m_pullup(m, skip + hlen)) == NULL) {
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_hdrops); /*XXX*/
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: m_pullup failed\n", __func__));
|
2002-10-16 02:10:08 +00:00
|
|
|
error = EINVAL; /*XXX*/
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Keep the next protocol field */
|
|
|
|
addr = (caddr_t) mtod(m, struct ip *) + skip;
|
|
|
|
nproto = ((struct ipcomp *) addr)->comp_nxt;
|
|
|
|
|
|
|
|
/* Remove the IPCOMP header */
|
|
|
|
error = m_striphdr(m, skip, hlen);
|
|
|
|
if (error) {
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_hdrops);
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: bad mbuf chain, IPCA %s/%08lx\n", __func__,
|
2015-04-18 16:58:33 +00:00
|
|
|
ipsec_address(&sav->sah->saidx.dst, buf, sizeof(buf)),
|
|
|
|
(u_long) ntohl(sav->spi)));
|
2002-10-16 02:10:08 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore the Next Protocol field */
|
|
|
|
m_copyback(m, protoff, sizeof (u_int8_t), (u_int8_t *) &nproto);
|
|
|
|
|
2011-04-27 19:28:42 +00:00
|
|
|
switch (saidx->dst.sa.sa_family) {
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2014-12-11 17:14:49 +00:00
|
|
|
error = ipsec6_common_input_cb(m, sav, skip, protoff);
|
2011-04-27 19:28:42 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2014-12-11 17:14:49 +00:00
|
|
|
error = ipsec4_common_input_cb(m, sav, skip, protoff);
|
2011-04-27 19:28:42 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
panic("%s: Unexpected address family: %d saidx=%p", __func__,
|
|
|
|
saidx->dst.sa.sa_family, saidx);
|
|
|
|
}
|
2002-10-16 02:10:08 +00:00
|
|
|
return error;
|
|
|
|
bad:
|
2017-02-06 08:49:57 +00:00
|
|
|
if (sav != NULL)
|
|
|
|
key_freesav(&sav);
|
|
|
|
if (m != NULL)
|
2002-10-16 02:10:08 +00:00
|
|
|
m_freem(m);
|
2017-02-06 08:49:57 +00:00
|
|
|
if (xd != NULL)
|
|
|
|
free(xd, M_XDATA);
|
|
|
|
if (crp != NULL)
|
2002-10-16 02:10:08 +00:00
|
|
|
crypto_freereq(crp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-02-06 08:49:57 +00:00
|
|
|
* IPComp output routine, called by ipsec[46]_perform_request()
|
2002-10-16 02:10:08 +00:00
|
|
|
*/
|
|
|
|
static int
|
2017-02-06 08:49:57 +00:00
|
|
|
ipcomp_output(struct mbuf *m, struct secpolicy *sp, struct secasvar *sav,
|
|
|
|
u_int idx, int skip, int protoff)
|
2002-10-16 02:10:08 +00:00
|
|
|
{
|
2017-02-06 08:49:57 +00:00
|
|
|
char buf[IPSEC_ADDRSTRLEN];
|
|
|
|
const struct comp_algo *ipcompx;
|
2002-10-16 02:10:08 +00:00
|
|
|
struct cryptodesc *crdc;
|
|
|
|
struct cryptop *crp;
|
2017-02-06 08:49:57 +00:00
|
|
|
struct xform_data *xd;
|
|
|
|
int error, ralen, maxpacketsize;
|
2002-10-16 02:10:08 +00:00
|
|
|
|
2003-09-29 22:57:43 +00:00
|
|
|
IPSEC_ASSERT(sav != NULL, ("null SA"));
|
2002-10-16 02:10:08 +00:00
|
|
|
ipcompx = sav->tdb_compalgxform;
|
2003-09-29 22:57:43 +00:00
|
|
|
IPSEC_ASSERT(ipcompx != NULL, ("null compression xform"));
|
2002-10-16 02:10:08 +00:00
|
|
|
|
2009-11-28 21:40:57 +00:00
|
|
|
/*
|
|
|
|
* Do not touch the packet in case our payload to compress
|
|
|
|
* is lower than the minimal threshold of the compression
|
|
|
|
* alogrithm. We will just send out the data uncompressed.
|
|
|
|
* See RFC 3173, 2.2. Non-Expansion Policy.
|
|
|
|
*/
|
|
|
|
if (m->m_pkthdr.len <= ipcompx->minlen) {
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_threshold);
|
2017-02-06 08:49:57 +00:00
|
|
|
return ipsec_process_done(m, sp, sav, idx);
|
2009-11-28 21:40:57 +00:00
|
|
|
}
|
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
ralen = m->m_pkthdr.len - skip; /* Raw payload length before comp. */
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_output);
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
/* Check for maximum packet size violations. */
|
|
|
|
switch (sav->sah->saidx.dst.sa.sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2009-11-28 21:42:39 +00:00
|
|
|
maxpacketsize = IP_MAXPACKET;
|
2002-10-16 02:10:08 +00:00
|
|
|
break;
|
|
|
|
#endif /* INET */
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2009-11-28 21:42:39 +00:00
|
|
|
maxpacketsize = IPV6_MAXPACKET;
|
2002-10-16 02:10:08 +00:00
|
|
|
break;
|
|
|
|
#endif /* INET6 */
|
|
|
|
default:
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_nopf);
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: unknown/unsupported protocol family %d, "
|
|
|
|
"IPCA %s/%08lx\n", __func__,
|
2002-10-16 02:10:08 +00:00
|
|
|
sav->sah->saidx.dst.sa.sa_family,
|
2015-04-18 16:58:33 +00:00
|
|
|
ipsec_address(&sav->sah->saidx.dst, buf, sizeof(buf)),
|
2002-10-16 02:10:08 +00:00
|
|
|
(u_long) ntohl(sav->spi)));
|
|
|
|
error = EPFNOSUPPORT;
|
|
|
|
goto bad;
|
|
|
|
}
|
2009-11-29 10:53:34 +00:00
|
|
|
if (ralen + skip + IPCOMP_HLENGTH > maxpacketsize) {
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_toobig);
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: packet in IPCA %s/%08lx got too big "
|
|
|
|
"(len %u, max len %u)\n", __func__,
|
2015-04-18 16:58:33 +00:00
|
|
|
ipsec_address(&sav->sah->saidx.dst, buf, sizeof(buf)),
|
2002-10-16 02:10:08 +00:00
|
|
|
(u_long) ntohl(sav->spi),
|
2009-11-29 10:53:34 +00:00
|
|
|
ralen + skip + IPCOMP_HLENGTH, maxpacketsize));
|
2002-10-16 02:10:08 +00:00
|
|
|
error = EMSGSIZE;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the counters */
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_ADD(ipcomps_obytes, m->m_pkthdr.len - skip);
|
2002-10-16 02:10:08 +00:00
|
|
|
|
2006-03-15 21:11:11 +00:00
|
|
|
m = m_unshare(m, M_NOWAIT);
|
2002-10-16 02:10:08 +00:00
|
|
|
if (m == NULL) {
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_hdrops);
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: cannot clone mbuf chain, IPCA %s/%08lx\n",
|
2015-04-18 16:58:33 +00:00
|
|
|
__func__, ipsec_address(&sav->sah->saidx.dst, buf,
|
|
|
|
sizeof(buf)), (u_long) ntohl(sav->spi)));
|
2002-10-16 02:10:08 +00:00
|
|
|
error = ENOBUFS;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2009-11-29 10:53:34 +00:00
|
|
|
/* Ok now, we can pass to the crypto processing. */
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
/* Get crypto descriptors */
|
|
|
|
crp = crypto_getreq(1);
|
|
|
|
if (crp == NULL) {
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_crypto);
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: failed to acquire crypto descriptor\n",__func__));
|
2002-10-16 02:10:08 +00:00
|
|
|
error = ENOBUFS;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
crdc = crp->crp_desc;
|
|
|
|
|
|
|
|
/* Compression descriptor */
|
2009-11-29 10:53:34 +00:00
|
|
|
crdc->crd_skip = skip;
|
|
|
|
crdc->crd_len = ralen;
|
2002-10-16 02:10:08 +00:00
|
|
|
crdc->crd_flags = CRD_F_COMP;
|
2009-11-29 10:53:34 +00:00
|
|
|
crdc->crd_inject = skip;
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
/* Compression operation */
|
|
|
|
crdc->crd_alg = ipcompx->type;
|
|
|
|
|
|
|
|
/* IPsec-specific opaque crypto info */
|
2017-02-06 08:49:57 +00:00
|
|
|
xd = malloc(sizeof(struct xform_data), M_XDATA, M_NOWAIT | M_ZERO);
|
|
|
|
if (xd == NULL) {
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_crypto);
|
2017-02-06 08:49:57 +00:00
|
|
|
DPRINTF(("%s: failed to allocate xform_data\n", __func__));
|
2002-10-16 02:10:08 +00:00
|
|
|
crypto_freereq(crp);
|
|
|
|
error = ENOBUFS;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2017-02-06 08:49:57 +00:00
|
|
|
xd->sp = sp;
|
|
|
|
xd->sav = sav;
|
|
|
|
xd->idx = idx;
|
|
|
|
xd->skip = skip;
|
|
|
|
xd->protoff = protoff;
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
/* Crypto operation descriptor */
|
|
|
|
crp->crp_ilen = m->m_pkthdr.len; /* Total input length */
|
2003-06-30 05:09:32 +00:00
|
|
|
crp->crp_flags = CRYPTO_F_IMBUF | CRYPTO_F_CBIFSYNC;
|
2002-10-16 02:10:08 +00:00
|
|
|
crp->crp_buf = (caddr_t) m;
|
|
|
|
crp->crp_callback = ipcomp_output_cb;
|
2017-02-06 08:49:57 +00:00
|
|
|
crp->crp_opaque = (caddr_t) xd;
|
|
|
|
|
|
|
|
SECASVAR_LOCK(sav);
|
|
|
|
crp->crp_sid = xd->cryptoid = sav->tdb_cryptoid;
|
|
|
|
SECASVAR_UNLOCK(sav);
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
return crypto_dispatch(crp);
|
|
|
|
bad:
|
|
|
|
if (m)
|
|
|
|
m_freem(m);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IPComp output callback from the crypto driver.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ipcomp_output_cb(struct cryptop *crp)
|
|
|
|
{
|
2017-02-06 08:49:57 +00:00
|
|
|
char buf[IPSEC_ADDRSTRLEN];
|
|
|
|
struct xform_data *xd;
|
|
|
|
struct secpolicy *sp;
|
2002-10-16 02:10:08 +00:00
|
|
|
struct secasvar *sav;
|
|
|
|
struct mbuf *m;
|
2017-02-06 08:49:57 +00:00
|
|
|
uint64_t cryptoid;
|
|
|
|
u_int idx;
|
|
|
|
int error, skip, protoff;
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
m = (struct mbuf *) crp->crp_buf;
|
2017-02-06 08:49:57 +00:00
|
|
|
xd = (struct xform_data *) crp->crp_opaque;
|
|
|
|
idx = xd->idx;
|
|
|
|
sp = xd->sp;
|
|
|
|
sav = xd->sav;
|
|
|
|
skip = xd->skip;
|
|
|
|
protoff = xd->protoff;
|
|
|
|
cryptoid = xd->cryptoid;
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
/* Check for crypto errors */
|
|
|
|
if (crp->crp_etype) {
|
|
|
|
if (crp->crp_etype == EAGAIN) {
|
2017-02-06 08:49:57 +00:00
|
|
|
/* Reset the session ID */
|
|
|
|
if (ipsec_updateid(sav, &crp->crp_sid, &cryptoid) != 0)
|
|
|
|
crypto_freesession(cryptoid);
|
|
|
|
xd->cryptoid = crp->crp_sid;
|
|
|
|
return (crypto_dispatch(crp));
|
2002-10-16 02:10:08 +00:00
|
|
|
}
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_noxform);
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: crypto error %d\n", __func__, crp->crp_etype));
|
2002-10-16 02:10:08 +00:00
|
|
|
error = crp->crp_etype;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
/* Shouldn't happen... */
|
|
|
|
if (m == NULL) {
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_crypto);
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: bogus return buffer from crypto\n", __func__));
|
2002-10-16 02:10:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_hist[sav->alg_comp]);
|
2002-10-16 02:10:08 +00:00
|
|
|
|
2009-11-29 10:53:34 +00:00
|
|
|
if (crp->crp_ilen - skip > crp->crp_olen) {
|
|
|
|
struct mbuf *mo;
|
|
|
|
struct ipcomp *ipcomp;
|
|
|
|
int roff;
|
|
|
|
uint8_t prot;
|
|
|
|
|
|
|
|
/* Compression helped, inject IPCOMP header. */
|
|
|
|
mo = m_makespace(m, skip, IPCOMP_HLENGTH, &roff);
|
|
|
|
if (mo == NULL) {
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_wrap);
|
2017-02-06 08:49:57 +00:00
|
|
|
DPRINTF(("%s: IPCOMP header inject failed "
|
|
|
|
"for IPCA %s/%08lx\n",
|
2015-04-18 16:58:33 +00:00
|
|
|
__func__, ipsec_address(&sav->sah->saidx.dst, buf,
|
|
|
|
sizeof(buf)), (u_long) ntohl(sav->spi)));
|
2009-11-29 10:53:34 +00:00
|
|
|
error = ENOBUFS;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
ipcomp = (struct ipcomp *)(mtod(mo, caddr_t) + roff);
|
|
|
|
|
|
|
|
/* Initialize the IPCOMP header */
|
|
|
|
/* XXX alignment always correct? */
|
|
|
|
switch (sav->sah->saidx.dst.sa.sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
ipcomp->comp_nxt = mtod(m, struct ip *)->ip_p;
|
|
|
|
break;
|
|
|
|
#endif /* INET */
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
ipcomp->comp_nxt = mtod(m, struct ip6_hdr *)->ip6_nxt;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
ipcomp->comp_flags = 0;
|
|
|
|
ipcomp->comp_cpi = htons((u_int16_t) ntohl(sav->spi));
|
|
|
|
|
|
|
|
/* Fix Next Protocol in IPv4/IPv6 header */
|
|
|
|
prot = IPPROTO_IPCOMP;
|
2017-02-06 08:49:57 +00:00
|
|
|
m_copyback(m, protoff, sizeof(u_int8_t),
|
2009-11-29 10:53:34 +00:00
|
|
|
(u_char *)&prot);
|
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
/* Adjust the length in the IP header */
|
|
|
|
switch (sav->sah->saidx.dst.sa.sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
mtod(m, struct ip *)->ip_len = htons(m->m_pkthdr.len);
|
|
|
|
break;
|
|
|
|
#endif /* INET */
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
mtod(m, struct ip6_hdr *)->ip6_plen =
|
|
|
|
htons(m->m_pkthdr.len) - sizeof(struct ip6_hdr);
|
|
|
|
break;
|
|
|
|
#endif /* INET6 */
|
|
|
|
default:
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_nopf);
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: unknown/unsupported protocol "
|
|
|
|
"family %d, IPCA %s/%08lx\n", __func__,
|
2002-10-16 02:10:08 +00:00
|
|
|
sav->sah->saidx.dst.sa.sa_family,
|
2015-04-18 16:58:33 +00:00
|
|
|
ipsec_address(&sav->sah->saidx.dst, buf,
|
|
|
|
sizeof(buf)), (u_long) ntohl(sav->spi)));
|
2002-10-16 02:10:08 +00:00
|
|
|
error = EPFNOSUPPORT;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
} else {
|
2009-11-29 20:37:30 +00:00
|
|
|
/* Compression was useless, we have lost time. */
|
2013-06-20 11:44:16 +00:00
|
|
|
IPCOMPSTAT_INC(ipcomps_uncompr);
|
2009-11-29 20:37:30 +00:00
|
|
|
DPRINTF(("%s: compressions was useless %d - %d <= %d\n",
|
|
|
|
__func__, crp->crp_ilen, skip, crp->crp_olen));
|
2009-11-29 10:53:34 +00:00
|
|
|
/* XXX remember state to not compress the next couple
|
|
|
|
* of packets, RFC 3173, 2.2. Non-Expansion Policy */
|
2002-10-16 02:10:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the crypto descriptor */
|
2017-02-06 08:49:57 +00:00
|
|
|
free(xd, M_XDATA);
|
2002-10-16 02:10:08 +00:00
|
|
|
crypto_freereq(crp);
|
|
|
|
|
|
|
|
/* NB: m is reclaimed by ipsec_process_done. */
|
2017-02-06 08:49:57 +00:00
|
|
|
error = ipsec_process_done(m, sp, sav, idx);
|
2015-04-27 00:55:56 +00:00
|
|
|
return (error);
|
2002-10-16 02:10:08 +00:00
|
|
|
bad:
|
|
|
|
if (m)
|
|
|
|
m_freem(m);
|
2017-02-06 08:49:57 +00:00
|
|
|
free(xd, M_XDATA);
|
2002-10-16 02:10:08 +00:00
|
|
|
crypto_freereq(crp);
|
2017-02-06 08:49:57 +00:00
|
|
|
key_freesav(&sav);
|
|
|
|
key_freesp(&sp);
|
2015-04-27 00:55:56 +00:00
|
|
|
return (error);
|
2002-10-16 02:10:08 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 09:02:17 +00:00
|
|
|
#ifdef INET
|
|
|
|
static const struct encaptab *ipe4_cookie = NULL;
|
2016-04-24 17:09:51 +00:00
|
|
|
extern struct domain inetdomain;
|
|
|
|
static struct protosw ipcomp4_protosw = {
|
|
|
|
.pr_type = SOCK_RAW,
|
|
|
|
.pr_domain = &inetdomain,
|
|
|
|
.pr_protocol = 0 /* IPPROTO_IPV[46] */,
|
|
|
|
.pr_flags = PR_ATOMIC | PR_ADDR | PR_LASTHDR,
|
|
|
|
.pr_input = ipcomp_nonexp_input,
|
|
|
|
.pr_output = rip_output,
|
|
|
|
.pr_ctloutput = rip_ctloutput,
|
|
|
|
.pr_usrreqs = &rip_usrreqs
|
|
|
|
};
|
|
|
|
|
2016-04-24 09:02:17 +00:00
|
|
|
static int
|
|
|
|
ipcomp4_nonexp_encapcheck(const struct mbuf *m, int off, int proto,
|
|
|
|
void *arg __unused)
|
|
|
|
{
|
|
|
|
union sockaddr_union src, dst;
|
|
|
|
const struct ip *ip;
|
|
|
|
|
|
|
|
if (V_ipcomp_enable == 0)
|
|
|
|
return (0);
|
2016-04-24 17:09:51 +00:00
|
|
|
if (proto != IPPROTO_IPV4 && proto != IPPROTO_IPV6)
|
|
|
|
return (0);
|
2016-04-24 09:02:17 +00:00
|
|
|
bzero(&src, sizeof(src));
|
|
|
|
bzero(&dst, sizeof(dst));
|
|
|
|
src.sa.sa_family = dst.sa.sa_family = AF_INET;
|
|
|
|
src.sin.sin_len = dst.sin.sin_len = sizeof(struct sockaddr_in);
|
|
|
|
ip = mtod(m, const struct ip *);
|
|
|
|
src.sin.sin_addr = ip->ip_src;
|
|
|
|
dst.sin.sin_addr = ip->ip_dst;
|
|
|
|
return (ipcomp_encapcheck(&src, &dst));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
static const struct encaptab *ipe6_cookie = NULL;
|
2016-04-24 17:09:51 +00:00
|
|
|
extern struct domain inet6domain;
|
|
|
|
static struct protosw ipcomp6_protosw = {
|
|
|
|
.pr_type = SOCK_RAW,
|
|
|
|
.pr_domain = &inet6domain,
|
|
|
|
.pr_protocol = 0 /* IPPROTO_IPV[46] */,
|
|
|
|
.pr_flags = PR_ATOMIC | PR_ADDR | PR_LASTHDR,
|
|
|
|
.pr_input = ipcomp_nonexp_input,
|
|
|
|
.pr_output = rip6_output,
|
|
|
|
.pr_ctloutput = rip6_ctloutput,
|
|
|
|
.pr_usrreqs = &rip6_usrreqs
|
|
|
|
};
|
|
|
|
|
2016-04-24 09:02:17 +00:00
|
|
|
static int
|
|
|
|
ipcomp6_nonexp_encapcheck(const struct mbuf *m, int off, int proto,
|
|
|
|
void *arg __unused)
|
|
|
|
{
|
|
|
|
union sockaddr_union src, dst;
|
|
|
|
const struct ip6_hdr *ip6;
|
|
|
|
|
|
|
|
if (V_ipcomp_enable == 0)
|
|
|
|
return (0);
|
2016-04-24 17:09:51 +00:00
|
|
|
if (proto != IPPROTO_IPV4 && proto != IPPROTO_IPV6)
|
|
|
|
return (0);
|
2016-04-24 09:02:17 +00:00
|
|
|
bzero(&src, sizeof(src));
|
|
|
|
bzero(&dst, sizeof(dst));
|
|
|
|
src.sa.sa_family = dst.sa.sa_family = AF_INET;
|
|
|
|
src.sin6.sin6_len = dst.sin6.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
ip6 = mtod(m, const struct ip6_hdr *);
|
|
|
|
src.sin6.sin6_addr = ip6->ip6_src;
|
|
|
|
dst.sin6.sin6_addr = ip6->ip6_dst;
|
|
|
|
if (IN6_IS_SCOPE_LINKLOCAL(&src.sin6.sin6_addr)) {
|
|
|
|
/* XXX: sa6_recoverscope() */
|
|
|
|
src.sin6.sin6_scope_id =
|
|
|
|
ntohs(src.sin6.sin6_addr.s6_addr16[1]);
|
|
|
|
src.sin6.sin6_addr.s6_addr16[1] = 0;
|
|
|
|
}
|
|
|
|
if (IN6_IS_SCOPE_LINKLOCAL(&dst.sin6.sin6_addr)) {
|
|
|
|
/* XXX: sa6_recoverscope() */
|
|
|
|
dst.sin6.sin6_scope_id =
|
|
|
|
ntohs(dst.sin6.sin6_addr.s6_addr16[1]);
|
|
|
|
dst.sin6.sin6_addr.s6_addr16[1] = 0;
|
|
|
|
}
|
|
|
|
return (ipcomp_encapcheck(&src, &dst));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-02-06 08:49:57 +00:00
|
|
|
static struct xformsw ipcomp_xformsw = {
|
|
|
|
.xf_type = XF_IPCOMP,
|
|
|
|
.xf_name = "IPcomp",
|
|
|
|
.xf_init = ipcomp_init,
|
|
|
|
.xf_zeroize = ipcomp_zeroize,
|
|
|
|
.xf_input = ipcomp_input,
|
|
|
|
.xf_output = ipcomp_output,
|
|
|
|
};
|
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
static void
|
|
|
|
ipcomp_attach(void)
|
|
|
|
{
|
2008-11-19 09:39:34 +00:00
|
|
|
|
2016-04-24 09:02:17 +00:00
|
|
|
#ifdef INET
|
2016-04-24 17:09:51 +00:00
|
|
|
ipe4_cookie = encap_attach_func(AF_INET, -1,
|
|
|
|
ipcomp4_nonexp_encapcheck, &ipcomp4_protosw, NULL);
|
2016-04-24 09:02:17 +00:00
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
2016-04-24 17:09:51 +00:00
|
|
|
ipe6_cookie = encap_attach_func(AF_INET6, -1,
|
|
|
|
ipcomp6_nonexp_encapcheck, &ipcomp6_protosw, NULL);
|
2016-04-24 09:02:17 +00:00
|
|
|
#endif
|
2017-02-06 08:49:57 +00:00
|
|
|
xform_attach(&ipcomp_xformsw);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ipcomp_detach(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
encap_detach(ipe4_cookie);
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
encap_detach(ipe6_cookie);
|
|
|
|
#endif
|
|
|
|
xform_detach(&ipcomp_xformsw);
|
First pass at separating per-vnet initializer functions
from existing functions for initializing global state.
At this stage, the new per-vnet initializer functions are
directly called from the existing global initialization code,
which should in most cases result in compiler inlining those
new functions, hence yielding a near-zero functional change.
Modify the existing initializer functions which are invoked via
protosw, like ip_init() et. al., to allow them to be invoked
multiple times, i.e. per each vnet. Global state, if any,
is initialized only if such functions are called within the
context of vnet0, which will be determined via the
IS_DEFAULT_VNET(curvnet) check (currently always true).
While here, V_irtualize a few remaining global UMA zones
used by net/netinet/netipsec networking code. While it is
not yet clear to me or anybody else whether this is the right
thing to do, at this stage this makes the code more readable,
and makes it easier to track uncollected UMA-zone-backed
objects on vnet removal. In the long run, it's quite possible
that some form of shared use of UMA zone pools among multiple
vnets should be considered.
Bump __FreeBSD_version due to changes in layout of structs
vnet_ipfw, vnet_inet and vnet_net.
Approved by: julian (mentor)
2009-04-06 22:29:41 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 09:02:17 +00:00
|
|
|
SYSINIT(ipcomp_xform_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE,
|
|
|
|
ipcomp_attach, NULL);
|
2017-02-06 08:49:57 +00:00
|
|
|
SYSUNINIT(ipcomp_xform_uninit, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE,
|
|
|
|
ipcomp_detach, NULL);
|