Changeset View
Changeset View
Standalone View
Standalone View
sys/netgraph/ng_deflate.c
Show All 35 Lines | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/mbuf.h> | #include <sys/mbuf.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/endian.h> | #include <sys/endian.h> | ||||
#include <sys/errno.h> | #include <sys/errno.h> | ||||
#include <sys/syslog.h> | #include <sys/syslog.h> | ||||
#include <sys/zlib.h> | |||||
#include <netgraph/ng_message.h> | #include <netgraph/ng_message.h> | ||||
#include <netgraph/netgraph.h> | #include <netgraph/netgraph.h> | ||||
#include <netgraph/ng_parse.h> | #include <netgraph/ng_parse.h> | ||||
#include <netgraph/ng_deflate.h> | #include <netgraph/ng_deflate.h> | ||||
#include "opt_netgraph.h" | #include "opt_netgraph.h" | ||||
static MALLOC_DEFINE(M_NETGRAPH_DEFLATE, "netgraph_deflate", | static MALLOC_DEFINE(M_NETGRAPH_DEFLATE, "netgraph_deflate", | ||||
"netgraph deflate node"); | "netgraph deflate node"); | ||||
#include "netgraph/ng_zlib.c" | |||||
ota_j.email.ne.jp: Is it better to move this above line 52, static MALLOC_DEFINE? | |||||
/* DEFLATE header length */ | /* DEFLATE header length */ | ||||
#define DEFLATE_HDRLEN 2 | #define DEFLATE_HDRLEN 2 | ||||
#define PROT_COMPD 0x00fd | #define PROT_COMPD 0x00fd | ||||
#define DEFLATE_BUF_SIZE 4096 | #define DEFLATE_BUF_SIZE 4096 | ||||
/* Node private data */ | /* Node private data */ | ||||
▲ Show 20 Lines • Show All 417 Lines • ▼ Show 20 Lines | ng_deflate_compress(node_p node, struct mbuf *m, struct mbuf **resultp) | ||||
} else { | } else { | ||||
priv->cx.next_in = priv->inbuf + 1; /* compress protocol */ | priv->cx.next_in = priv->inbuf + 1; /* compress protocol */ | ||||
priv->cx.avail_in = inlen - 1; | priv->cx.avail_in = inlen - 1; | ||||
} | } | ||||
priv->cx.next_out = priv->outbuf + 2 + DEFLATE_HDRLEN; | priv->cx.next_out = priv->outbuf + 2 + DEFLATE_HDRLEN; | ||||
priv->cx.avail_out = outlen - 2 - DEFLATE_HDRLEN; | priv->cx.avail_out = outlen - 2 - DEFLATE_HDRLEN; | ||||
/* Compress. */ | /* Compress. */ | ||||
rtn = deflate(&priv->cx, Z_PACKET_FLUSH); | rtn = ng_deflate(&priv->cx, Z_PACKET_FLUSH); | ||||
/* Check return value. */ | /* Check return value. */ | ||||
if (rtn != Z_OK) { | if (rtn != Z_OK) { | ||||
priv->stats.Errors++; | priv->stats.Errors++; | ||||
log(LOG_NOTICE, "ng_deflate: compression error: %d (%s)\n", | log(LOG_NOTICE, "ng_deflate: compression error: %d (%s)\n", | ||||
rtn, priv->cx.msg); | rtn, priv->cx.msg); | ||||
NG_FREE_M(m); | NG_FREE_M(m); | ||||
return (EINVAL); | return (EINVAL); | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | if (proto == PROT_COMPD) { | ||||
/* Prepare to decompress. */ | /* Prepare to decompress. */ | ||||
priv->cx.next_in = priv->inbuf + offset; | priv->cx.next_in = priv->inbuf + offset; | ||||
priv->cx.avail_in = inlen - offset; | priv->cx.avail_in = inlen - offset; | ||||
/* Reserve space for protocol decompression. */ | /* Reserve space for protocol decompression. */ | ||||
priv->cx.next_out = priv->outbuf + 1; | priv->cx.next_out = priv->outbuf + 1; | ||||
priv->cx.avail_out = outlen - 1; | priv->cx.avail_out = outlen - 1; | ||||
/* Decompress. */ | /* Decompress. */ | ||||
rtn = inflate(&priv->cx, Z_PACKET_FLUSH); | rtn = ng_inflate(&priv->cx, Z_PACKET_FLUSH); | ||||
/* Check return value. */ | /* Check return value. */ | ||||
if (rtn != Z_OK && rtn != Z_STREAM_END) { | if (rtn != Z_OK && rtn != Z_STREAM_END) { | ||||
priv->stats.Errors++; | priv->stats.Errors++; | ||||
NG_FREE_M(m); | NG_FREE_M(m); | ||||
priv->seqnum = 0; | priv->seqnum = 0; | ||||
log(LOG_NOTICE, "%s: decompression error: %d (%s)\n", | log(LOG_NOTICE, "%s: decompression error: %d (%s)\n", | ||||
__func__, rtn, priv->cx.msg); | __func__, rtn, priv->cx.msg); | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |
Is it better to move this above line 52, static MALLOC_DEFINE?