PR/20844: Iain Hibbert: PPP Compressors cannot be loaded as LKM

This commit is contained in:
christos 2003-03-27 17:50:06 +00:00
parent 479a3334a4
commit e950c1ac8f
9 changed files with 227 additions and 6 deletions

View File

@ -1,5 +1,5 @@
# $NetBSD: Makefile,v 1.5 2000/12/11 13:48:10 jdolecek Exp $
# $NetBSD: Makefile,v 1.6 2003/03/27 17:50:06 christos Exp $
SUBDIR= arch compat exec misc netinet vfs syscall
SUBDIR= arch compat exec misc net netinet vfs syscall
.include <bsd.subdir.mk>

3
sys/lkm/net/Makefile Normal file
View File

@ -0,0 +1,3 @@
SUBDIR= bsdcomp deflate
.include <bsd.subdir.mk>

4
sys/lkm/net/Makefile.inc Normal file
View File

@ -0,0 +1,4 @@
S!= cd ${.CURDIR}/../../..;pwd
.include "../Makefile.inc"

View File

@ -0,0 +1,10 @@
.include "../Makefile.inc"
.PATH: $S/net
CPPFLAGS+=-DDO_BSD_COMPRESS=1
MKMAN= no
KMOD= bsdcomp
SRCS= lkminit_bsdcomp.c bsd-comp.c
.include <bsd.kmod.mk>

View File

@ -0,0 +1,87 @@
/*
* lkminit_bsdcomp.c
*
* written by Iain Hibbert <plunky@rya-online.net>
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/exec.h>
#include <sys/lkm.h>
#include <sys/file.h>
#include <sys/errno.h>
#include <sys/mbuf.h>
#define PACKETPTR struct mbuf *
#include <net/ppp_defs.h>
#include <net/ppp-comp.h>
extern struct compressor *ppp_compressors[];
extern struct compressor ppp_bsd_compress;
static int bsdcomp_handle(struct lkm_table *lkmtp, int cmd);
int bsdcomp_lkmentry(struct lkm_table *lkmtp, int cmd, int ver);
MOD_MISC("bsdcomp")
static int
bsdcomp_handle(struct lkm_table *lkmtp, int cmd)
{
int i = 0;
switch (cmd) {
case LKM_E_LOAD:
/*
* Load the compressor into the master table in the first
* available slot, unless we already have a CI_BSD_COMPRESS
* type listed. Leave a space at the end, its a NULL
* terminated list.
*/
while (ppp_compressors[i]) {
if (ppp_compressors[i]->compress_proto
== CI_BSD_COMPRESS)
return EEXIST; /* either me, or the
* in-kernel version */
if (++i == PPP_COMPRESSORS_MAX - 1)
return ENFILE; /* no room */
}
ppp_compressors[i] = &ppp_bsd_compress;
break;
case LKM_E_UNLOAD:
/*
* Find the first instance of CI_BSD_COMPRESS in the table,
* and * unload it. If this instance was not mine, Somebody has
* been Playing With Fire, and will likely Get Burnt.
*/
while (ppp_compressors[i]->compress_proto != CI_BSD_COMPRESS)
i++;
while (ppp_compressors[i] && i < (PPP_COMPRESSORS_MAX - 1)) {
ppp_compressors[i] = ppp_compressors[i + 1];
i++;
}
ppp_compressors[i] = NULL;
break;
case LKM_E_STAT:
break;
default:
return EINVAL;
}
return 0; /* success */
}
/*
* the module entry point.
*/
int
bsdcomp_lkmentry(struct lkm_table *lkmtp, int cmd, int ver)
{
DISPATCH(lkmtp, cmd, ver, bsdcomp_handle, bsdcomp_handle,
bsdcomp_handle)
}

View File

@ -0,0 +1,13 @@
.include "../Makefile.inc"
.PATH: $S/net
CPPFLAGS+=-DDO_DEFLATE=1
MKMAN= no
KMOD= deflate
SRCS= lkminit_deflate.c ppp-deflate.c zlib.c
.include <bsd.kmod.mk>
.include "../Makefile.inc"

View File

@ -0,0 +1,97 @@
/*
* lkminit_deflate.c
*
* written by Iain Hibbert <plunky@rya-online.net>
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/exec.h>
#include <sys/lkm.h>
#include <sys/file.h>
#include <sys/errno.h>
#include <sys/mbuf.h>
#define PACKETPTR struct mbuf *
#include <net/ppp_defs.h>
#include <net/ppp-comp.h>
extern struct compressor *ppp_compressors[];
extern struct compressor ppp_deflate;
extern struct compressor ppp_deflate_draft;
static int deflate_handle(struct lkm_table * lkmtp, int cmd);
int deflate_lkmentry(struct lkm_table * lkmtp, int cmd, int ver);
MOD_MISC("deflate")
static int
deflate_handle(struct lkm_table *lkmtp, int cmd)
{
int i = 0;
static int qty; /* how many compressors we loaded */
switch (cmd) {
case LKM_E_LOAD:
/*
* Load the compressor into the first available slot in the
* kernel compressors table, unless there is a CI_DEFLATE
* compressor already listed. The table is a NULL terminated
* list, so leave a space at the end.
*/
while (ppp_compressors[i]) {
if (ppp_compressors[i]->compress_proto == CI_DEFLATE)
return EEXIST; /* either me, or the
* in-kernel version */
if (++i == PPP_COMPRESSORS_MAX - 1)
return ENFILE; /* no room */
}
ppp_compressors[i] = &ppp_deflate;
qty = 1;
/*
* and add deflate_draft if we have any room left
*/
if (++i < PPP_COMPRESSORS_MAX - 1) {
ppp_compressors[i] = &ppp_deflate_draft;
qty = 2;
}
break;
case LKM_E_UNLOAD:
/*
* Find the first instance of CI_DEFLATE in the table, and
* unload it. If this instance was not mine, Somebody has been
* Playing With Fire, and will likely Get Burnt.
*/
while (ppp_compressors[i]->compress_proto != CI_DEFLATE)
i++;
while (ppp_compressors[i] && i < (PPP_COMPRESSORS_MAX - qty)) {
ppp_compressors[i] = ppp_compressors[i + qty];
i++;
}
ppp_compressors[i] = NULL;
break;
case LKM_E_STAT:
break;
default:
return EINVAL;
}
return 0; /* success */
}
/*
* the module entry point.
*/
int
deflate_lkmentry(struct lkm_table *lkmtp, int cmd, int ver)
{
DISPATCH(lkmtp, cmd, ver, deflate_handle, deflate_handle,
deflate_handle)
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_ppp.c,v 1.82 2003/01/19 23:44:03 simonb Exp $ */
/* $NetBSD: if_ppp.c,v 1.83 2003/03/27 17:50:28 christos Exp $ */
/* Id: if_ppp.c,v 1.6 1997/03/04 03:33:00 paulus Exp */
/*
@ -102,7 +102,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.82 2003/01/19 23:44:03 simonb Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.83 2003/03/27 17:50:28 christos Exp $");
#include "ppp.h"
@ -213,7 +213,7 @@ struct ppp_softc ppp_softc[NPPP];
extern struct compressor ppp_bsd_compress;
extern struct compressor ppp_deflate, ppp_deflate_draft;
struct compressor *ppp_compressors[8] = {
struct compressor *ppp_compressors[PPP_COMPRESSORS_MAX] = {
#if DO_BSD_COMPRESS && defined(PPP_BSDCOMP)
&ppp_bsd_compress,
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: ppp-comp.h,v 1.8 2002/09/13 14:32:11 itojun Exp $ */
/* $NetBSD: ppp-comp.h,v 1.9 2003/03/27 17:50:28 christos Exp $ */
/*
* ppp-comp.h - Definitions for doing PPP packet compression.
@ -51,6 +51,13 @@
#define DO_PREDICTOR_1 0
#define DO_PREDICTOR_2 0
/*
* How many entries to make available in the compressors table
*/
#ifndef PPP_COMPRESSORS_MAX
#define PPP_COMPRESSORS_MAX 8
#endif
/*
* Structure giving methods for compression/decompression.
*/