53#include <sys/kernel.h>
55#include <sys/malloc.h>
63#include <netinet/in.h>
64#include <netinet/in_systm.h>
65#include <netinet/ip.h>
66#include <netinet/tcp.h>
68#include <net/slcompress.h>
71#if MAX_STATES != NG_VJC_MAX_CHANNELS
72#error NG_VJC_MAX_CHANNELS must be the same as MAX_STATES
76#define MAX_VJHEADER 19
81 struct slcompress
slc;
89#define ERROUT(x) do { error = (x); goto done; } while (0)
113#define NG_VJC_TSTATE_PTR_TYPE &ng_parse_uint32_type
115#define NG_VJC_TSTATE_PTR_TYPE &ng_parse_uint64_type
246 priv = malloc(
sizeof(*
priv), M_NETGRAPH, M_WAITOK | M_ZERO);
270 hookp = &
priv->vjcomp;
272 hookp = &
priv->vjuncomp;
310 if ((
priv->conf.enableComp ||
priv->conf.enableDecomp)
320 bzero(&
priv->slc,
sizeof(
priv->slc));
339 const struct slcompress *
const sl0 = &
priv->slc;
340 struct slcompress *sl;
348 sl = (
struct slcompress *)resp->
data;
352 if (sl->last_cs != NULL) {
353 index = sl0->last_cs - sl0->tstate;
354 bzero(&sl->last_cs,
sizeof(sl->last_cs));
355 *((u_int16_t *)&sl->last_cs) = index;
357 for (i = 0; i < MAX_STATES; i++) {
358 struct cstate *
const cs = &sl->tstate[i];
360 index = sl0->tstate[i].cs_next - sl0->tstate;
361 bzero(&cs->cs_next,
sizeof(cs->cs_next));
362 *((u_int16_t *)&cs->cs_next) = index;
367 priv->slc.sls_packets = 0;
368 priv->slc.sls_compressed = 0;
369 priv->slc.sls_searches = 0;
370 priv->slc.sls_misses = 0;
371 priv->slc.sls_uncompressedin = 0;
372 priv->slc.sls_compressedin = 0;
373 priv->slc.sls_errorin = 0;
374 priv->slc.sls_tossed = 0;
377 sl_uncompress_tcp(NULL, 0, TYPE_ERROR, &
priv->slc);
406 if (hook ==
priv->ip) {
407 u_int
type = TYPE_IP;
410 if (
priv->conf.enableComp) {
417 ip = mtod(m,
struct ip *);
418 if (ip->ip_p == IPPROTO_TCP) {
419 const int origLen = m->m_len;
421 type = sl_compress_tcp(m, ip,
422 &
priv->slc,
priv->conf.compressCID);
423 m->m_pkthdr.len += m->m_len - origLen;
432 case TYPE_UNCOMPRESSED_TCP:
433 hook =
priv->vjuncomp;
435 case TYPE_COMPRESSED_TCP:
439 panic(
"%s: type=%d", __func__,
type);
441 }
else if (hook ==
priv->vjcomp) {
442 int vjlen, need2pullup;
448 if (!
priv->conf.enableDecomp) {
456 if (need2pullup > m->m_pkthdr.len)
457 need2pullup = m->m_pkthdr.len;
458 if (m->m_len < need2pullup
459 && (m = m_pullup(m, need2pullup)) == NULL) {
460 priv->slc.sls_errorin++;
466 vjlen = sl_uncompress_tcp_core(mtod(m, u_char *),
467 m->m_len, m->m_pkthdr.len, TYPE_COMPRESSED_TCP,
468 &
priv->slc, &hdr, &hlen);
477 MGETHDR(hm, M_NOWAIT, MT_DATA);
479 priv->slc.sls_errorin++;
485 hm->m_pkthdr.rcvif = NULL;
487 if (!(MCLGET(hm, M_NOWAIT))) {
489 priv->slc.sls_errorin++;
495 bcopy(hdr, mtod(hm, u_char *), hlen);
500 hm->m_pkthdr.len = hlen + m->m_pkthdr.len;
503 }
else if (hook ==
priv->vjuncomp) {
508 if (!
priv->conf.enableDecomp) {
521 if (sl_uncompress_tcp_core(mtod(m, u_char *),
522 m->m_len, m->m_pkthdr.len, TYPE_UNCOMPRESSED_TCP,
523 &
priv->slc, &hdr, &hlen) < 0) {
529 }
else if (hook ==
priv->vjip)
532 panic(
"%s: unknown hook", __func__);
548 free(
priv, M_NETGRAPH);
564 if (hook ==
priv->ip)
566 else if (hook ==
priv->vjcomp)
568 else if (hook ==
priv->vjuncomp)
569 priv->vjuncomp = NULL;
570 else if (hook ==
priv->vjip)
573 panic(
"%s: unknown hook", __func__);
597 if (m->m_len <
sizeof(*ip) && (m = m_pullup(m,
sizeof(*ip))) == NULL)
599 ip = mtod(m,
struct ip *);
600 if (!knownTCP && ip->ip_p != IPPROTO_TCP)
602 ihlen = ip->ip_hl << 2;
603 if (m->m_len < ihlen +
sizeof(*tcp)) {
604 if ((m = m_pullup(m, ihlen +
sizeof(*tcp))) == NULL)
606 ip = mtod(m,
struct ip *);
608 tcp = (
struct tcphdr *)((u_char *)ip + ihlen);
609 thlen = tcp->th_off << 2;
610 if (m->m_len < ihlen + thlen)
611 m = m_pullup(m, ihlen + thlen);
#define NG_HOOK_NODE(hook)
int ng_rcvmsg_t(node_p node, item_p item, hook_p lasthook)
int ng_disconnect_t(hook_p hook)
#define NG_NODE_SET_PRIVATE(node, val)
#define NG_RESPOND_MSG(error, here, item, resp)
#define NG_NODE_IS_VALID(node)
#define NG_NODE_FORCE_WRITER(node)
#define NG_NODE_UNREF(node)
int ng_rmnode_self(node_p here)
#define NG_FWD_NEW_DATA(error, item, hook, m)
int ng_rcvdata_t(hook_p hook, item_p item)
int ng_shutdown_t(node_p node)
#define NG_FREE_ITEM(item)
int ng_constructor_t(node_p node)
#define NG_NODE_NUMHOOKS(node)
#define NGI_GET_MSG(i, m)
#define NG_NODE_PRIVATE(node)
int ng_newhook_t(node_p node, hook_p hook, const char *name)
#define NG_MKRESPONSE(rsp, msg, len, how)
const struct ng_parse_type ng_parse_uint16_type
const struct ng_parse_type ng_parse_fixedarray_type
const struct ng_parse_type ng_parse_struct_type
const struct ng_parse_type ng_parse_hint8_type
const struct ng_parse_type ng_parse_uint32_type
const struct ng_parse_type ng_parse_uint8_type
const struct ng_parse_type ng_parse_hint16_type
static const struct ng_parse_type ng_vjc_cstatearray_type
static ng_rcvdata_t ng_vjc_rcvdata
static const struct ng_parse_type ng_vjc_config_type
static struct ng_type ng_vjc_typestruct
static const struct ng_parse_type ng_vjc_cs_hdr_type
NETGRAPH_INIT(vjc, &ng_vjc_typestruct)
static const struct ng_parse_fixedarray_info ng_vjc_cs_hdr_type_info
static ng_rcvmsg_t ng_vjc_rcvmsg
struct ng_vjc_private * priv_p
#define NG_VJC_TSTATE_PTR_TYPE
static ng_disconnect_t ng_vjc_disconnect
static const struct ng_parse_type ng_vjc_cstate_type
static const struct ng_parse_struct_field ng_vjc_cstate_type_fields[]
static ng_constructor_t ng_vjc_constructor
static const struct ng_parse_fixedarray_info ng_vjc_cstatearray_type_info
static const struct ng_cmdlist ng_vjc_cmds[]
static const struct ng_parse_struct_field ng_vjc_config_type_fields[]
static ng_shutdown_t ng_vjc_shutdown
static const struct ng_parse_struct_field ng_vjc_slcompress_type_fields[]
static struct mbuf * ng_vjc_pulluphdrs(struct mbuf *m, int knownTCP)
static const struct ng_parse_type ng_vjc_slcompress_type
static ng_newhook_t ng_vjc_newhook
#define NG_VJC_HOOK_VJCOMP
#define NG_VJC_HOOK_VJUNCOMP
#define NG_VJC_CONFIG_TYPE_INFO
#define NG_VJC_MAX_CHANNELS
#define NG_VJC_MIN_CHANNELS
struct ng_mesg::ng_msghdr header
struct ngm_vjc_config conf