linux/drivers/net/ppp/ppp_deflate.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * ppp_deflate.c - interface the zlib procedures for Deflate compression
 * and decompression (as used by gzip) to the PPP code.
 *
 * Copyright 1994-1998 Paul Mackerras.
 */

#include <linux/module.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/init.h>
#include <linux/string.h>

#include <linux/ppp_defs.h>
#include <linux/ppp-comp.h>

#include <linux/zlib.h>
#include <linux/unaligned.h>

/*
 * State for a Deflate (de)compressor.
 */
struct ppp_deflate_state {};

#define DEFLATE_OVHD

static void	*z_comp_alloc(unsigned char *options, int opt_len);
static void	*z_decomp_alloc(unsigned char *options, int opt_len);
static void	z_comp_free(void *state);
static void	z_decomp_free(void *state);
static int	z_comp_init(void *state, unsigned char *options,
				 int opt_len,
				 int unit, int hdrlen, int debug);
static int	z_decomp_init(void *state, unsigned char *options,
				   int opt_len,
				   int unit, int hdrlen, int mru, int debug);
static int	z_compress(void *state, unsigned char *rptr,
				unsigned char *obuf,
				int isize, int osize);
static void	z_incomp(void *state, unsigned char *ibuf, int icnt);
static int	z_decompress(void *state, unsigned char *ibuf,
				int isize, unsigned char *obuf, int osize);
static void	z_comp_reset(void *state);
static void	z_decomp_reset(void *state);
static void	z_comp_stats(void *state, struct compstat *stats);

/**
 *	z_comp_free - free the memory used by a compressor
 *	@arg:	pointer to the private state for the compressor.
 */
static void z_comp_free(void *arg)
{}

/**
 *	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)
{}

/**
 *	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)
{}

/**
 *	z_comp_reset - reset a previously-allocated compressor.
 *	@arg:	pointer to private state for the compressor.
 *
 *	This clears the history for the compressor and makes it
 *	ready to start emitting a new compressed stream.
 */
static void z_comp_reset(void *arg)
{}

/**
 *	z_compress - compress a PPP packet with Deflate compression.
 *	@arg:	pointer to private state for the compressor
 *	@rptr:	uncompressed packet (input)
 *	@obuf:	compressed packet (output)
 *	@isize:	size of uncompressed packet
 *	@osize:	space available at @obuf
 *
 *	Returns the length of the compressed packet, or 0 if the
 *	packet is incompressible.
 */
static int z_compress(void *arg, unsigned char *rptr, unsigned char *obuf,
	       int isize, int osize)
{}

/**
 *	z_comp_stats - return compression statistics for a compressor
 *		or decompressor.
 *	@arg:	pointer to private space for the (de)compressor
 *	@stats:	pointer to a struct compstat to receive the result.
 */
static void z_comp_stats(void *arg, struct compstat *stats)
{}

/**
 *	z_decomp_free - Free the memory used by a decompressor.
 *	@arg:	pointer to private space for the decompressor.
 */
static void z_decomp_free(void *arg)
{}

/**
 *	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)
{}

/**
 *	z_decomp_init - initialize a previously-allocated decompressor.
 *	@arg:	pointer to the private state for the decompressor
 *	@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)
 *	@mru:	maximum length of decompressed packets
 *	@debug:	debug flag; if non-zero, debug messages are printed.
 *
 *	The CCP options described by @options must match the options
 *	specified when the decompressor was allocated.  The decompressor
 *	history is reset.  Returns 0 for failure (CCP options don't
 *	match) or 1 for success.
 */
static int z_decomp_init(void *arg, unsigned char *options, int opt_len,
			 int unit, int hdrlen, int mru, int debug)
{}

/**
 *	z_decomp_reset - reset a previously-allocated decompressor.
 *	@arg:	pointer to private state for the decompressor.
 *
 *	This clears the history for the decompressor and makes it
 *	ready to receive a new compressed stream.
 */
static void z_decomp_reset(void *arg)
{}

/**
 *	z_decompress - decompress a Deflate-compressed packet.
 *	@arg:	pointer to private state for the decompressor
 *	@ibuf:	pointer to input (compressed) packet data
 *	@isize:	length of input packet
 *	@obuf:	pointer to space for output (decompressed) packet
 *	@osize:	amount of space available at @obuf
 *
 * Because of patent problems, we return DECOMP_ERROR for errors
 * found by inspecting the input data and for system problems, but
 * DECOMP_FATALERROR for any errors which could possibly be said to
 * be being detected "after" decompression.  For DECOMP_ERROR,
 * we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be
 * infringing a patent of Motorola's if we do, so we take CCP down
 * instead.
 *
 * Given that the frame has the correct sequence number and a good FCS,
 * errors such as invalid codes in the input most likely indicate a
 * bug, so we return DECOMP_FATALERROR for them in order to turn off
 * compression, even though they are detected by inspecting the input.
 */
static int z_decompress(void *arg, unsigned char *ibuf, int isize,
		 unsigned char *obuf, int osize)
{}

/**
 *	z_incomp - add incompressible input data to the history.
 *	@arg:	pointer to private state for the decompressor
 *	@ibuf:	pointer to input packet data
 *	@icnt:	length of input data.
 */
static void z_incomp(void *arg, unsigned char *ibuf, int icnt)
{}

/*************************************************************
 * Module interface table
 *************************************************************/

/* These are in ppp_generic.c */
extern int  ppp_register_compressor   (struct compressor *cp);
extern void ppp_unregister_compressor (struct compressor *cp);

/*
 * Procedures exported to if_ppp.c.
 */
static struct compressor ppp_deflate =;

static struct compressor ppp_deflate_draft =;

static int __init deflate_init(void)
{}

static void __exit deflate_cleanup(void)
{}

module_init();
module_exit(deflate_cleanup);
MODULE_DESCRIPTION();
MODULE_LICENSE();
MODULE_ALIAS();
MODULE_ALIAS();