Esempio n. 1
0
/*
 * z_comp_init()
 */
static int
z_comp_init(void *arg, uchar_t *options, int opt_len, int unit, int hdrlen,
	int debug)
{
	struct deflate_state *state = (struct deflate_state *)arg;

	if (opt_len < CILEN_DEFLATE ||
		(options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) ||
		options[1] != CILEN_DEFLATE ||
		DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL ||
		DEFLATE_SIZE(options[2]) != state->w_size ||
		options[3] != DEFLATE_CHK_SEQUENCE) {

		return (0);
	}

	state->seqno = 0;
	state->unit = unit;
	state->hdrlen = hdrlen;
	if (debug)
		state->flags |= DS_DEBUG;
	else
		state->flags &= ~DS_DEBUG;

	(void) deflateReset(&state->strm);

	return (1);
}
Esempio n. 2
0
/**
 *	z_decomp_alloc - allocate space for a decompressor.
 *	@options: pointer to CCP option data
 *	@opt_len: length of the CCP option at @options.
 *
 *	The @options pointer points to the a buffer containing the
 *	CCP option data for the compression being negotiated.  It is
 *	formatted according to RFC1979, and describes the window
 *	size that we are requesting the peer to use in compressing
 *	data to be sent to us.
 *
 *	Returns the pointer to the private state for the decompressor,
 *	or NULL if we could not allocate enough memory.
 */
static void *z_decomp_alloc(unsigned char *options, int opt_len)
{
	struct ppp_deflate_state *state;
	int w_size;

	if (opt_len != CILEN_DEFLATE
	    || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
	    || options[1] != CILEN_DEFLATE
	    || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
	    || options[3] != DEFLATE_CHK_SEQUENCE)
		return NULL;
	w_size = DEFLATE_SIZE(options[2]);
	if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
		return NULL;

	state = kzalloc(sizeof(*state), GFP_KERNEL);
	if (state == NULL)
		return NULL;

	state->w_size         = w_size;
	state->strm.next_out  = NULL;
	state->strm.workspace = kmalloc(zlib_inflate_workspacesize(),
					GFP_KERNEL|__GFP_REPEAT);
	if (state->strm.workspace == NULL)
		goto out_free;

	if (zlib_inflateInit2(&state->strm, -w_size) != Z_OK)
		goto out_free;
	return (void *) state;

out_free:
	z_decomp_free(state);
	return NULL;
}
Esempio n. 3
0
File: ccp.c Progetto: rtemss/rtems
/*
 * ccp_nakci - process received configure-nak.
 * Returns 1 iff the nak was OK.
 */
static int
ccp_nakci(
    fsm *f,
    u_char *p,
    int len)
{
    ccp_options *go = &ccp_gotoptions[f->unit];
    ccp_options no;		/* options we've seen already */
    ccp_options try;		/* options to ask for next time */

    memset(&no, 0, sizeof(no));
    try = *go;

    if (go->deflate && len >= CILEN_DEFLATE
            && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
            && p[1] == CILEN_DEFLATE) {
        no.deflate = 1;
        /*
         * Peer wants us to use a different code size or something.
         * Stop asking for Deflate if we don't understand his suggestion.
         */
        if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
                || DEFLATE_SIZE(p[2]) < DEFLATE_MIN_SIZE
                || p[3] != DEFLATE_CHK_SEQUENCE)
            try.deflate = 0;
        else if (DEFLATE_SIZE(p[2]) < go->deflate_size)
            try.deflate_size = DEFLATE_SIZE(p[2]);
        p += CILEN_DEFLATE;
        len -= CILEN_DEFLATE;
        if (go->deflate_correct && go->deflate_draft
                && len >= CILEN_DEFLATE && p[0] == CI_DEFLATE_DRAFT
                && p[1] == CILEN_DEFLATE) {
            p += CILEN_DEFLATE;
            len -= CILEN_DEFLATE;
        }
    }
Esempio n. 4
0
/*
 * Allocate space for a compressor.
 */
static void *
z_comp_alloc(uchar_t *options, int opt_len)
{
	struct deflate_state	*state;
	int			w_size;

	if (opt_len != CILEN_DEFLATE ||
		(options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) ||
		options[1] != CILEN_DEFLATE ||
		DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL ||
		options[3] != DEFLATE_CHK_SEQUENCE) {

		return (NULL);
	}

	w_size = DEFLATE_SIZE(options[2]);
	/*
	 * Check <= minimum size to avoid unfixable zlib bug -- window size
	 * 256 (w_size 8) is not supported.
	 */
	if (w_size <= DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE) {
		return (NULL);
	}

	state = (struct deflate_state *)kmem_zalloc(sizeof (*state), KM_SLEEP);
	ASSERT(state != NULL);

	state->strm.zalloc = (alloc_func)z_alloc;
	state->strm.zfree = (free_func)z_free;

	if (deflateInit2(&state->strm, Z_DEFAULT_COMPRESSION,
		DEFLATE_METHOD_VAL, -w_size, 8, Z_DEFAULT_STRATEGY) != Z_OK) {

		kmem_free(state, sizeof (*state));

		return (NULL);
	}

	state->w_size = w_size;

	bzero(&state->stats, sizeof (state->stats));

	return ((void *)state);
}
Esempio n. 5
0
/**
 *	z_comp_init - initialize a previously-allocated compressor.
 *	@arg:	pointer to the private state for the compressor
 *	@options: pointer to the CCP option data describing the
 *		compression that was negotiated with the peer
 *	@opt_len: length of the CCP option data at @options
 *	@unit:	PPP unit number for diagnostic messages
 *	@hdrlen: ignored (present for backwards compatibility)
 *	@debug:	debug flag; if non-zero, debug messages are printed.
 *
 *	The CCP options described by @options must match the options
 *	specified when the compressor was allocated.  The compressor
 *	history is reset.  Returns 0 for failure (CCP options don't
 *	match) or 1 for success.
 */
static int z_comp_init(void *arg, unsigned char *options, int opt_len,
		       int unit, int hdrlen, int debug)
{
	struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;

	if (opt_len < CILEN_DEFLATE
	    || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
	    || options[1] != CILEN_DEFLATE
	    || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
	    || DEFLATE_SIZE(options[2]) != state->w_size
	    || options[3] != DEFLATE_CHK_SEQUENCE)
		return 0;

	state->seqno = 0;
	state->unit  = unit;
	state->debug = debug;

	zlib_deflateReset(&state->strm);

	return 1;
}
Esempio n. 6
0
/**
 *	z_decomp_alloc - allocate space for a decompressor.
 *	@options: pointer to CCP option data
 *	@opt_len: length of the CCP option at @options.
 *
 *	The @options pointer points to the a buffer containing the
 *	CCP option data for the compression being negotiated.  It is
 *	formatted according to RFC1979, and describes the window
 *	size that we are requesting the peer to use in compressing
 *	data to be sent to us.
 *
 *	Returns the pointer to the private state for the decompressor,
 *	or NULL if we could not allocate enough memory.
 */
static void *z_decomp_alloc(unsigned char *options, int opt_len)
{
	struct ppp_deflate_state *state;
	int w_size;

	if (opt_len != CILEN_DEFLATE ||
	    (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) ||
	    options[1] != CILEN_DEFLATE ||
	    DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL ||
	    options[3] != DEFLATE_CHK_SEQUENCE)
		return NULL;
	w_size = DEFLATE_SIZE(options[2]);
	if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
		return NULL;

	state = kzalloc(sizeof(*state), GFP_KERNEL);
	if (state == NULL)
		return NULL;

	state->w_size         = w_size;
	state->strm.next_out  = NULL;
/* LGE_CHANGE_S [LS855:[email protected]] 2011-07-11, */ 
#if 0  /* Delete Warning Log - OMAPS00243976 */
	state->strm.workspace = kmalloc(zlib_inflate_workspacesize(),
					GFP_KERNEL|__GFP_REPEAT);
#else
	state->strm.workspace = vmalloc(zlib_inflate_workspacesize());
#endif
/* LGE_CHANGE_E [LS855:[email protected]] 2011-07-11 */
	if (state->strm.workspace == NULL)
		goto out_free;

	if (zlib_inflateInit2(&state->strm, -w_size) != Z_OK)
		goto out_free;
	return (void *) state;

out_free:
	z_decomp_free(state);
	return NULL;
}
Esempio n. 7
0
/**
 *	z_comp_alloc - allocate space for a compressor.
 *	@options: pointer to CCP option data
 *	@opt_len: length of the CCP option at @options.
 *
 *	The @options pointer points to the a buffer containing the
 *	CCP option data for the compression being negotiated.  It is
 *	formatted according to RFC1979, and describes the window
 *	size that the peer is requesting that we use in compressing
 *	data to be sent to it.
 *
 *	Returns the pointer to the private state for the compressor,
 *	or NULL if we could not allocate enough memory.
 */
static void *z_comp_alloc(unsigned char *options, int opt_len)
{
	struct ppp_deflate_state *state;
	int w_size;

	if (opt_len != CILEN_DEFLATE
	    || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
	    || options[1] != CILEN_DEFLATE
	    || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
	    || options[3] != DEFLATE_CHK_SEQUENCE)
		return NULL;
	w_size = DEFLATE_SIZE(options[2]);
	if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
		return NULL;

	state = (struct ppp_deflate_state *) kmalloc(sizeof(*state),
						     GFP_KERNEL);
	if (state == NULL)
		return NULL;

	memset (state, 0, sizeof (struct ppp_deflate_state));
	state->strm.next_in   = NULL;
	state->w_size         = w_size;
	state->strm.workspace = vmalloc(zlib_deflate_workspacesize());
	if (state->strm.workspace == NULL)
		goto out_free;

	if (zlib_deflateInit2(&state->strm, Z_DEFAULT_COMPRESSION,
			 DEFLATE_METHOD_VAL, -w_size, 8, Z_DEFAULT_STRATEGY)
	    != Z_OK)
		goto out_free;
	return (void *) state;

out_free:
	z_comp_free(state);
	return NULL;
}