Tue Nov 25 02:40:36 2008 UTC ()
Rework the way PPP compmressors are handled and allow them to be
automatically loaded when needed.


(cube)
diff -r1.18 -r1.19 src/sys/net/bsd-comp.c
diff -r1.124 -r1.125 src/sys/net/if_ppp.c
diff -r1.23 -r1.24 src/sys/net/if_ppp.h
diff -r1.14 -r1.15 src/sys/net/ppp-comp.h
diff -r1.17 -r1.18 src/sys/net/ppp-deflate.c

cvs diff -r1.18 -r1.19 src/sys/net/bsd-comp.c (expand / switch to unified diff)

--- src/sys/net/bsd-comp.c 2008/06/15 16:37:21 1.18
+++ src/sys/net/bsd-comp.c 2008/11/25 02:40:36 1.19
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: bsd-comp.c,v 1.18 2008/06/15 16:37:21 christos Exp $ */ 1/* $NetBSD: bsd-comp.c,v 1.19 2008/11/25 02:40:36 cube Exp $ */
2/* Id: bsd-comp.c,v 1.6 1996/08/28 06:31:58 paulus Exp */ 2/* Id: bsd-comp.c,v 1.6 1996/08/28 06:31:58 paulus Exp */
3 3
4/* Because this code is derived from the 4.3BSD compress source: 4/* Because this code is derived from the 4.3BSD compress source:
5 * 5 *
6 * 6 *
7 * Copyright (c) 1985, 1986 The Regents of the University of California. 7 * Copyright (c) 1985, 1986 The Regents of the University of California.
8 * All rights reserved. 8 * All rights reserved.
9 * 9 *
10 * This code is derived from software contributed to Berkeley by 10 * This code is derived from software contributed to Berkeley by
11 * James A. Woods, derived from original work by Spencer Thomas 11 * James A. Woods, derived from original work by Spencer Thomas
12 * and Joseph Orost. 12 * and Joseph Orost.
13 * 13 *
14 * Redistribution and use in source and binary forms, with or without 14 * Redistribution and use in source and binary forms, with or without
@@ -31,32 +31,33 @@ @@ -31,32 +31,33 @@
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE. 36 * SUCH DAMAGE.
37 */ 37 */
38 38
39/* 39/*
40 * This version is for use with mbufs on BSD-derived systems. 40 * This version is for use with mbufs on BSD-derived systems.
41 */ 41 */
42 42
43#include <sys/cdefs.h> 43#include <sys/cdefs.h>
44__KERNEL_RCSID(0, "$NetBSD: bsd-comp.c,v 1.18 2008/06/15 16:37:21 christos Exp $"); 44__KERNEL_RCSID(0, "$NetBSD: bsd-comp.c,v 1.19 2008/11/25 02:40:36 cube Exp $");
45 45
46#include <sys/param.h> 46#include <sys/param.h>
47#include <sys/systm.h> 47#include <sys/systm.h>
48#include <sys/mbuf.h> 48#include <sys/mbuf.h>
49#include <sys/socket.h> 49#include <sys/socket.h>
 50#include <sys/module.h>
50#include <net/if.h> 51#include <net/if.h>
51#include <net/if_types.h> 52#include <net/if_types.h>
52#include <net/ppp_defs.h> 53#include <net/ppp_defs.h>
53#include <net/if_ppp.h> 54#include <net/if_ppp.h>
54 55
55#define PACKETPTR struct mbuf * 56#define PACKETPTR struct mbuf *
56#include <net/ppp-comp.h> 57#include <net/ppp-comp.h>
57 58
58#if DO_BSD_COMPRESS 59#if DO_BSD_COMPRESS
59/* 60/*
60 * PPP "BSD compress" compression 61 * PPP "BSD compress" compression
61 * The differences between this compression and the classic BSD LZW 62 * The differences between this compression and the classic BSD LZW
62 * source are obvious from the requirement that the classic code worked 63 * source are obvious from the requirement that the classic code worked
@@ -137,41 +138,42 @@ static int bsd_comp_init(void *state, u_ @@ -137,41 +138,42 @@ static int bsd_comp_init(void *state, u_
137static int bsd_decomp_init(void *state, u_char *options, int opt_len, 138static int bsd_decomp_init(void *state, u_char *options, int opt_len,
138 int unit, int hdrlen, int mru, int debug); 139 int unit, int hdrlen, int mru, int debug);
139static int bsd_compress(void *state, struct mbuf **mret, 140static int bsd_compress(void *state, struct mbuf **mret,
140 struct mbuf *mp, int slen, int maxolen); 141 struct mbuf *mp, int slen, int maxolen);
141static void bsd_incomp(void *state, struct mbuf *dmsg); 142static void bsd_incomp(void *state, struct mbuf *dmsg);
142static int bsd_decompress(void *state, struct mbuf *cmp, 143static int bsd_decompress(void *state, struct mbuf *cmp,
143 struct mbuf **dmpp); 144 struct mbuf **dmpp);
144static void bsd_reset(void *state); 145static void bsd_reset(void *state);
145static void bsd_comp_stats(void *state, struct compstat *stats); 146static void bsd_comp_stats(void *state, struct compstat *stats);
146 147
147/* 148/*
148 * Procedures exported to if_ppp.c. 149 * Procedures exported to if_ppp.c.
149 */ 150 */
150struct compressor ppp_bsd_compress = { 151static struct compressor ppp_bsd_compress = {
151 CI_BSD_COMPRESS, /* compress_proto */ 152 .compress_proto = CI_BSD_COMPRESS,
152 bsd_comp_alloc, /* comp_alloc */ 153 .comp_alloc = bsd_comp_alloc,
153 bsd_free, /* comp_free */ 154 .comp_free = bsd_free,
154 bsd_comp_init, /* comp_init */ 155 .comp_init = bsd_comp_init,
155 bsd_reset, /* comp_reset */ 156 .comp_reset = bsd_reset,
156 bsd_compress, /* compress */ 157 .compress = bsd_compress,
157 bsd_comp_stats, /* comp_stat */ 158 .comp_stat = bsd_comp_stats,
158 bsd_decomp_alloc, /* decomp_alloc */ 159 .decomp_alloc = bsd_decomp_alloc,
159 bsd_free, /* decomp_free */ 160 .decomp_free = bsd_free,
160 bsd_decomp_init, /* decomp_init */ 161 .decomp_init = bsd_decomp_init,
161 bsd_reset, /* decomp_reset */ 162 .decomp_reset = bsd_reset,
162 bsd_decompress, /* decompress */ 163 .decompress = bsd_decompress,
163 bsd_incomp, /* incomp */ 164 .incomp = bsd_incomp,
164 bsd_comp_stats, /* decomp_stat */ 165 .decomp_stat = bsd_comp_stats,
 166 .comp_name = "ppp_bsdcomp"
165}; 167};
166 168
167/* 169/*
168 * the next two codes should not be changed lightly, as they must not 170 * the next two codes should not be changed lightly, as they must not
169 * lie within the contiguous general code space. 171 * lie within the contiguous general code space.
170 */ 172 */
171#define CLEAR 256 /* table clear output code */ 173#define CLEAR 256 /* table clear output code */
172#define FIRST 257 /* first free entry */ 174#define FIRST 257 /* first free entry */
173#define LAST 255 175#define LAST 255
174 176
175#define MAXCODE(b) ((1 << (b)) - 1) 177#define MAXCODE(b) ((1 << (b)) - 1)
176#define BADCODEM1 MAXCODE(BSD_MAX_BITS) 178#define BADCODEM1 MAXCODE(BSD_MAX_BITS)
177 179
@@ -1078,14 +1080,34 @@ bsd_decompress(void *state, struct mbuf  @@ -1078,14 +1080,34 @@ bsd_decompress(void *state, struct mbuf
1078 printf("bsd_decomp%d: fell off end of chain ", db->unit); 1080 printf("bsd_decomp%d: fell off end of chain ", db->unit);
1079 printf("0x%x at 0x%x by 0x%x, max_ent=0x%x\n", 1081 printf("0x%x at 0x%x by 0x%x, max_ent=0x%x\n",
1080 incode, finchar, db->dict[finchar].cptr, max_ent); 1082 incode, finchar, db->dict[finchar].cptr, max_ent);
1081 } else if (dictp->codem1 != finchar-1) { 1083 } else if (dictp->codem1 != finchar-1) {
1082 printf("bsd_decomp%d: bad code chain 0x%x finchar=0x%x ", 1084 printf("bsd_decomp%d: bad code chain 0x%x finchar=0x%x ",
1083 db->unit, incode, finchar); 1085 db->unit, incode, finchar);
1084 printf("oldcode=0x%x cptr=0x%x codem1=0x%x\n", oldcode, 1086 printf("oldcode=0x%x cptr=0x%x codem1=0x%x\n", oldcode,
1085 db->dict[finchar].cptr, dictp->codem1); 1087 db->dict[finchar].cptr, dictp->codem1);
1086 } 1088 }
1087 m_freem(mret); 1089 m_freem(mret);
1088 return DECOMP_FATALERROR; 1090 return DECOMP_FATALERROR;
1089#endif /* DEBUG */ 1091#endif /* DEBUG */
1090} 1092}
 1093
 1094MODULE(MODULE_CLASS_MISC, ppp_bsdcomp, NULL);
 1095
 1096static int
 1097ppp_bsdcomp_modcmd(modcmd_t cmd, void *arg)
 1098{
 1099
 1100 switch (cmd) {
 1101 case MODULE_CMD_INIT:
 1102 return ppp_register_compressor(&ppp_bsd_compress);
 1103 case MODULE_CMD_FINI:
 1104 return ppp_unregister_compressor(&ppp_bsd_compress);
 1105 case MODULE_CMD_STAT:
 1106 return 0;
 1107 default:
 1108 return ENOTTY;
 1109 }
 1110
 1111 return ENOTTY;
 1112}
1091#endif /* DO_BSD_COMPRESS */ 1113#endif /* DO_BSD_COMPRESS */

cvs diff -r1.124 -r1.125 src/sys/net/if_ppp.c (expand / switch to unified diff)

--- src/sys/net/if_ppp.c 2008/11/07 00:20:13 1.124
+++ src/sys/net/if_ppp.c 2008/11/25 02:40:36 1.125
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_ppp.c,v 1.124 2008/11/07 00:20:13 dyoung Exp $ */ 1/* $NetBSD: if_ppp.c,v 1.125 2008/11/25 02:40:36 cube Exp $ */
2/* Id: if_ppp.c,v 1.6 1997/03/04 03:33:00 paulus Exp */ 2/* Id: if_ppp.c,v 1.6 1997/03/04 03:33:00 paulus Exp */
3 3
4/* 4/*
5 * if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver. 5 * if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver.
6 * 6 *
7 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. 7 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 12 *
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -92,48 +92,50 @@ @@ -92,48 +92,50 @@
92/* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */ 92/* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
93 93
94/* 94/*
95 * XXX IMP ME HARDER 95 * XXX IMP ME HARDER
96 * 96 *
97 * This is an explanation of that comment. This code used to use 97 * This is an explanation of that comment. This code used to use
98 * splimp() to block both network and tty interrupts. However, 98 * splimp() to block both network and tty interrupts. However,
99 * that call is deprecated. So, we have replaced the uses of 99 * that call is deprecated. So, we have replaced the uses of
100 * splimp() with splhigh() in order to applomplish what it needs 100 * splimp() with splhigh() in order to applomplish what it needs
101 * to accomplish, and added that happy little comment. 101 * to accomplish, and added that happy little comment.
102 */ 102 */
103 103
104#include <sys/cdefs.h> 104#include <sys/cdefs.h>
105__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.124 2008/11/07 00:20:13 dyoung Exp $"); 105__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.125 2008/11/25 02:40:36 cube Exp $");
106 106
107#include "ppp.h" 107#include "ppp.h"
108 108
109#include "opt_inet.h" 109#include "opt_inet.h"
110#include "opt_gateway.h" 110#include "opt_gateway.h"
111#include "opt_ppp.h" 111#include "opt_ppp.h"
112 112
113#ifdef INET 113#ifdef INET
114#define VJC 114#define VJC
115#endif 115#endif
116#define PPP_COMPRESS 116#define PPP_COMPRESS
117 117
118#include <sys/param.h> 118#include <sys/param.h>
119#include <sys/proc.h> 119#include <sys/proc.h>
120#include <sys/mbuf.h> 120#include <sys/mbuf.h>
121#include <sys/socket.h> 121#include <sys/socket.h>
122#include <sys/ioctl.h> 122#include <sys/ioctl.h>
123#include <sys/kernel.h> 123#include <sys/kernel.h>
124#include <sys/systm.h> 124#include <sys/systm.h>
125#include <sys/time.h> 125#include <sys/time.h>
126#include <sys/malloc.h> 126#include <sys/malloc.h>
 127#include <sys/module.h>
 128#include <sys/mutex.h>
127#include <sys/conf.h> 129#include <sys/conf.h>
128#include <sys/kauth.h> 130#include <sys/kauth.h>
129#include <sys/intr.h> 131#include <sys/intr.h>
130#include <sys/simplelock.h> 132#include <sys/simplelock.h>
131#include <sys/socketvar.h> 133#include <sys/socketvar.h>
132 134
133#include <net/if.h> 135#include <net/if.h>
134#include <net/if_types.h> 136#include <net/if_types.h>
135#include <net/netisr.h> 137#include <net/netisr.h>
136#include <net/route.h> 138#include <net/route.h>
137#ifdef PPP_FILTER 139#ifdef PPP_FILTER
138#include <net/bpf.h> 140#include <net/bpf.h>
139#endif 141#endif
@@ -204,59 +206,46 @@ static void pppintr(void *); @@ -204,59 +206,46 @@ static void pppintr(void *);
204static int ppp_clone_create(struct if_clone *, int); 206static int ppp_clone_create(struct if_clone *, int);
205static int ppp_clone_destroy(struct ifnet *); 207static int ppp_clone_destroy(struct ifnet *);
206 208
207static struct ppp_softc *ppp_create(const char *, int); 209static struct ppp_softc *ppp_create(const char *, int);
208 210
209static LIST_HEAD(, ppp_softc) ppp_softc_list; 211static LIST_HEAD(, ppp_softc) ppp_softc_list;
210 212
211struct if_clone ppp_cloner = 213struct if_clone ppp_cloner =
212 IF_CLONE_INITIALIZER("ppp", ppp_clone_create, ppp_clone_destroy); 214 IF_CLONE_INITIALIZER("ppp", ppp_clone_create, ppp_clone_destroy);
213 215
214static struct simplelock ppp_list_mutex = SIMPLELOCK_INITIALIZER; 216static struct simplelock ppp_list_mutex = SIMPLELOCK_INITIALIZER;
215 217
216#ifdef PPP_COMPRESS 218#ifdef PPP_COMPRESS
217/* 219static LIST_HEAD(, compressor) ppp_compressors = { NULL };
218 * List of compressors we know about. 220static kmutex_t ppp_compressors_mtx;
219 * We leave some space so maybe we can modload compressors. 
220 */ 
221 221
222extern struct compressor ppp_bsd_compress; 222static struct compressor *ppp_get_compressor(uint8_t);
223extern struct compressor ppp_deflate, ppp_deflate_draft; 
224 
225struct compressor *ppp_compressors[PPP_COMPRESSORS_MAX] = { 
226#if DO_BSD_COMPRESS && defined(PPP_BSDCOMP) 
227 &ppp_bsd_compress, 
228#endif 
229#if DO_DEFLATE && defined(PPP_DEFLATE) 
230 &ppp_deflate, 
231 &ppp_deflate_draft, 
232#endif 
233 NULL 
234}; 
235#endif /* PPP_COMPRESS */ 223#endif /* PPP_COMPRESS */
236 224
237 225
238/* 226/*
239 * Called from boot code to establish ppp interfaces. 227 * Called from boot code to establish ppp interfaces.
240 */ 228 */
241void 229void
242pppattach(void) 230pppattach(void)
243{ 231{
244 extern struct linesw ppp_disc; 232 extern struct linesw ppp_disc;
245 233
246 if (ttyldisc_attach(&ppp_disc) != 0) 234 if (ttyldisc_attach(&ppp_disc) != 0)
247 panic("pppattach"); 235 panic("pppattach");
248 LIST_INIT(&ppp_softc_list); 236 LIST_INIT(&ppp_softc_list);
249 if_clone_attach(&ppp_cloner); 237 if_clone_attach(&ppp_cloner);
 238 mutex_init(&ppp_compressors_mtx, MUTEX_DEFAULT, IPL_NONE);
250} 239}
251 240
252static struct ppp_softc * 241static struct ppp_softc *
253ppp_create(const char *name, int unit) 242ppp_create(const char *name, int unit)
254{ 243{
255 struct ppp_softc *sc, *sci, *scl = NULL; 244 struct ppp_softc *sc, *sci, *scl = NULL;
256 245
257 MALLOC(sc, struct ppp_softc *, sizeof(*sc), M_DEVBUF, M_WAIT|M_ZERO); 246 MALLOC(sc, struct ppp_softc *, sizeof(*sc), M_DEVBUF, M_WAIT|M_ZERO);
258 247
259 simple_lock(&ppp_list_mutex); 248 simple_lock(&ppp_list_mutex);
260 if (unit == -1) { 249 if (unit == -1) {
261 int i = 0; 250 int i = 0;
262 LIST_FOREACH(sci, &ppp_softc_list, sc_iflist) { 251 LIST_FOREACH(sci, &ppp_softc_list, sc_iflist) {
@@ -477,27 +466,27 @@ pppdealloc(struct ppp_softc *sc) @@ -477,27 +466,27 @@ pppdealloc(struct ppp_softc *sc)
477 (void)ppp_clone_destroy(&sc->sc_if); 466 (void)ppp_clone_destroy(&sc->sc_if);
478} 467}
479 468
480/* 469/*
481 * Ioctl routine for generic ppp devices. 470 * Ioctl routine for generic ppp devices.
482 */ 471 */
483int 472int
484pppioctl(struct ppp_softc *sc, u_long cmd, void *data, int flag, 473pppioctl(struct ppp_softc *sc, u_long cmd, void *data, int flag,
485 struct lwp *l) 474 struct lwp *l)
486{ 475{
487 int s, error, flags, mru, npx; 476 int s, error, flags, mru, npx;
488 u_int nb; 477 u_int nb;
489 struct ppp_option_data *odp; 478 struct ppp_option_data *odp;
490 struct compressor **cp; 479 struct compressor *cp;
491 struct npioctl *npi; 480 struct npioctl *npi;
492 time_t t; 481 time_t t;
493#ifdef PPP_FILTER 482#ifdef PPP_FILTER
494 struct bpf_program *bp, *nbp; 483 struct bpf_program *bp, *nbp;
495 struct bpf_insn *newcode, *oldcode; 484 struct bpf_insn *newcode, *oldcode;
496 int newcodelen; 485 int newcodelen;
497#endif /* PPP_FILTER */ 486#endif /* PPP_FILTER */
498#ifdef PPP_COMPRESS 487#ifdef PPP_COMPRESS
499 u_char ccp_option[CCP_MAX_OPTION_LENGTH]; 488 u_char ccp_option[CCP_MAX_OPTION_LENGTH];
500#endif 489#endif
501 490
502 switch (cmd) { 491 switch (cmd) {
503 case PPPIOCSFLAGS: 492 case PPPIOCSFLAGS:
@@ -585,71 +574,75 @@ pppioctl(struct ppp_softc *sc, u_long cm @@ -585,71 +574,75 @@ pppioctl(struct ppp_softc *sc, u_long cm
585 sc->sc_xfer = l->l_proc->p_pid; 574 sc->sc_xfer = l->l_proc->p_pid;
586 break; 575 break;
587 576
588#ifdef PPP_COMPRESS 577#ifdef PPP_COMPRESS
589 case PPPIOCSCOMPRESS: 578 case PPPIOCSCOMPRESS:
590 odp = (struct ppp_option_data *) data; 579 odp = (struct ppp_option_data *) data;
591 nb = odp->length; 580 nb = odp->length;
592 if (nb > sizeof(ccp_option)) 581 if (nb > sizeof(ccp_option))
593 nb = sizeof(ccp_option); 582 nb = sizeof(ccp_option);
594 if ((error = copyin(odp->ptr, ccp_option, nb)) != 0) 583 if ((error = copyin(odp->ptr, ccp_option, nb)) != 0)
595 return (error); 584 return (error);
596 if (ccp_option[1] < 2) /* preliminary check on the length byte */ 585 if (ccp_option[1] < 2) /* preliminary check on the length byte */
597 return (EINVAL); 586 return (EINVAL);
598 for (cp = ppp_compressors; *cp != NULL; ++cp) 587 cp = ppp_get_compressor(ccp_option[0]);
599 if ((*cp)->compress_proto == ccp_option[0]) { 588 if (cp == NULL) {
600 /* 589 if (sc->sc_flags & SC_DEBUG)
601 * Found a handler for the protocol - try to allocate 590 printf("%s: no compressor for [%x %x %x], %x\n",
602 * a compressor or decompressor. 591 sc->sc_if.if_xname, ccp_option[0], ccp_option[1],
603 */ 592 ccp_option[2], nb);
604 error = 0; 593 return (EINVAL); /* no handler found */
605 if (odp->transmit) { 594 }
606 s = splsoftnet(); 595 /*
607 if (sc->sc_xc_state != NULL) 596 * Found a handler for the protocol - try to allocate
608 (*sc->sc_xcomp->comp_free)(sc->sc_xc_state); 597 * a compressor or decompressor.
609 sc->sc_xcomp = *cp; 598 */
610 sc->sc_xc_state = (*cp)->comp_alloc(ccp_option, nb); 599 error = 0;
611 if (sc->sc_xc_state == NULL) { 600 if (odp->transmit) {
612 if (sc->sc_flags & SC_DEBUG) 601 s = splsoftnet();
613 printf("%s: comp_alloc failed\n", 602 if (sc->sc_xc_state != NULL) {
614 sc->sc_if.if_xname); 603 (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
615 error = ENOBUFS; 604 module_rele(sc->sc_xcomp->comp_name);
616 } 
617 splhigh(); /* XXX IMP ME HARDER */ 
618 sc->sc_flags &= ~SC_COMP_RUN; 
619 splx(s); 
620 } else { 
621 s = splsoftnet(); 
622 if (sc->sc_rc_state != NULL) 
623 (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state); 
624 sc->sc_rcomp = *cp; 
625 sc->sc_rc_state = (*cp)->decomp_alloc(ccp_option, nb); 
626 if (sc->sc_rc_state == NULL) { 
627 if (sc->sc_flags & SC_DEBUG) 
628 printf("%s: decomp_alloc failed\n", 
629 sc->sc_if.if_xname); 
630 error = ENOBUFS; 
631 } 
632 splhigh(); /* XXX IMP ME HARDER */ 
633 sc->sc_flags &= ~SC_DECOMP_RUN; 
634 splx(s); 
635 } 
636 return (error); 
637 } 605 }
638 if (sc->sc_flags & SC_DEBUG) 606 sc->sc_xcomp = cp;
639 printf("%s: no compressor for [%x %x %x], %x\n", 607 sc->sc_xc_state = cp->comp_alloc(ccp_option, nb);
640 sc->sc_if.if_xname, ccp_option[0], ccp_option[1], 608 if (sc->sc_xc_state == NULL) {
641 ccp_option[2], nb); 609 if (sc->sc_flags & SC_DEBUG)
642 return (EINVAL); /* no handler found */ 610 printf("%s: comp_alloc failed\n",
 611 sc->sc_if.if_xname);
 612 error = ENOBUFS;
 613 }
 614 splhigh(); /* XXX IMP ME HARDER */
 615 sc->sc_flags &= ~SC_COMP_RUN;
 616 splx(s);
 617 } else {
 618 s = splsoftnet();
 619 if (sc->sc_rc_state != NULL) {
 620 (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
 621 module_rele(sc->sc_rcomp->comp_name);
 622 }
 623 sc->sc_rcomp = cp;
 624 sc->sc_rc_state = cp->decomp_alloc(ccp_option, nb);
 625 if (sc->sc_rc_state == NULL) {
 626 if (sc->sc_flags & SC_DEBUG)
 627 printf("%s: decomp_alloc failed\n",
 628 sc->sc_if.if_xname);
 629 error = ENOBUFS;
 630 }
 631 splhigh(); /* XXX IMP ME HARDER */
 632 sc->sc_flags &= ~SC_DECOMP_RUN;
 633 splx(s);
 634 }
 635 return (error);
643#endif /* PPP_COMPRESS */ 636#endif /* PPP_COMPRESS */
644 637
645 case PPPIOCGNPMODE: 638 case PPPIOCGNPMODE:
646 case PPPIOCSNPMODE: 639 case PPPIOCSNPMODE:
647 npi = (struct npioctl *) data; 640 npi = (struct npioctl *) data;
648 switch (npi->protocol) { 641 switch (npi->protocol) {
649 case PPP_IP: 642 case PPP_IP:
650 npx = NP_IP; 643 npx = NP_IP;
651 break; 644 break;
652 case PPP_IPV6: 645 case PPP_IPV6:
653 npx = NP_IPV6; 646 npx = NP_IPV6;
654 break; 647 break;
655 default: 648 default:
@@ -1381,30 +1374,32 @@ ppp_ccp(struct ppp_softc *sc, struct mbu @@ -1381,30 +1374,32 @@ ppp_ccp(struct ppp_softc *sc, struct mbu
1381 } 1374 }
1382 break; 1375 break;
1383 } 1376 }
1384} 1377}
1385 1378
1386/* 1379/*
1387 * CCP is down; free (de)compressor state if necessary. 1380 * CCP is down; free (de)compressor state if necessary.
1388 */ 1381 */
1389static void 1382static void
1390ppp_ccp_closed(struct ppp_softc *sc) 1383ppp_ccp_closed(struct ppp_softc *sc)
1391{ 1384{
1392 if (sc->sc_xc_state) { 1385 if (sc->sc_xc_state) {
1393 (*sc->sc_xcomp->comp_free)(sc->sc_xc_state); 1386 (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
 1387 module_rele(sc->sc_xcomp->comp_name);
1394 sc->sc_xc_state = NULL; 1388 sc->sc_xc_state = NULL;
1395 } 1389 }
1396 if (sc->sc_rc_state) { 1390 if (sc->sc_rc_state) {
1397 (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state); 1391 (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
 1392 module_rele(sc->sc_rcomp->comp_name);
1398 sc->sc_rc_state = NULL; 1393 sc->sc_rc_state = NULL;
1399 } 1394 }
1400} 1395}
1401#endif /* PPP_COMPRESS */ 1396#endif /* PPP_COMPRESS */
1402 1397
1403/* 1398/*
1404 * PPP packet input routine. 1399 * PPP packet input routine.
1405 * The caller has checked and removed the FCS and has inserted 1400 * The caller has checked and removed the FCS and has inserted
1406 * the address/control bytes and the protocol high byte if they 1401 * the address/control bytes and the protocol high byte if they
1407 * were omitted. 1402 * were omitted.
1408 */ 1403 */
1409void 1404void
1410ppppktin(struct ppp_softc *sc, struct mbuf *m, int lost) 1405ppppktin(struct ppp_softc *sc, struct mbuf *m, int lost)
@@ -1769,13 +1764,92 @@ done: @@ -1769,13 +1764,92 @@ done:
1769/* 1764/*
1770 * a wrapper to transmit a packet from if_start since ALTQ uses 1765 * a wrapper to transmit a packet from if_start since ALTQ uses
1771 * if_start to send a packet. 1766 * if_start to send a packet.
1772 */ 1767 */
1773static void 1768static void
1774ppp_ifstart(struct ifnet *ifp) 1769ppp_ifstart(struct ifnet *ifp)
1775{ 1770{
1776 struct ppp_softc *sc; 1771 struct ppp_softc *sc;
1777 1772
1778 sc = ifp->if_softc; 1773 sc = ifp->if_softc;
1779 (*sc->sc_start)(sc); 1774 (*sc->sc_start)(sc);
1780} 1775}
1781#endif 1776#endif
 1777
 1778static const struct ppp_known_compressor {
 1779 uint8_t code;
 1780 const char *module;
 1781} ppp_known_compressors[] = {
 1782 { CI_DEFLATE, "ppp_deflate" },
 1783 { CI_DEFLATE_DRAFT, "ppp_deflate" },
 1784 { CI_BSD_COMPRESS, "ppp_bsdcomp" },
 1785 { CI_MPPE, "ppp_mppe" },
 1786 { 0, NULL }
 1787};
 1788
 1789static struct compressor *
 1790ppp_get_compressor_noload(uint8_t ci, bool hold)
 1791{
 1792 struct compressor *cp;
 1793
 1794 mutex_enter(&ppp_compressors_mtx);
 1795 LIST_FOREACH(cp, &ppp_compressors, comp_list) {
 1796 if (cp->compress_proto == ci) {
 1797 mutex_exit(&ppp_compressors_mtx);
 1798 if (hold && module_hold(cp->comp_name) != 0)
 1799 return NULL;
 1800 return cp;
 1801 }
 1802 }
 1803 mutex_exit(&ppp_compressors_mtx);
 1804
 1805 return NULL;
 1806}
 1807
 1808static struct compressor *
 1809ppp_get_compressor(uint8_t ci)
 1810{
 1811 struct compressor *cp;
 1812 const struct ppp_known_compressor *pkc;
 1813
 1814 if ((cp = ppp_get_compressor_noload(ci, true)) != NULL)
 1815 return cp;
 1816
 1817 /* Not found, so try to autoload a module */
 1818 for (pkc = ppp_known_compressors; pkc->module != NULL; pkc++) {
 1819 if (pkc->code == ci) {
 1820 if (module_autoload(pkc->module, MODULE_CLASS_MISC))
 1821 break;
 1822 return ppp_get_compressor_noload(ci, true);
 1823 }
 1824 }
 1825
 1826 return NULL;
 1827}
 1828
 1829int
 1830ppp_register_compressor(struct compressor *pc)
 1831{
 1832
 1833 if (ppp_get_compressor_noload(pc->compress_proto, false) != NULL)
 1834 return EEXIST;
 1835
 1836 mutex_enter(&ppp_compressors_mtx);
 1837 LIST_INSERT_HEAD(&ppp_compressors, pc, comp_list);
 1838 mutex_exit(&ppp_compressors_mtx);
 1839
 1840 return 0;
 1841}
 1842
 1843int
 1844ppp_unregister_compressor(struct compressor *pc)
 1845{
 1846
 1847 if (ppp_get_compressor_noload(pc->compress_proto, false) != pc)
 1848 return ENOENT;
 1849
 1850 mutex_enter(&ppp_compressors_mtx);
 1851 LIST_REMOVE(pc, comp_list);
 1852 mutex_exit(&ppp_compressors_mtx);
 1853
 1854 return 0;
 1855}

cvs diff -r1.23 -r1.24 src/sys/net/if_ppp.h (expand / switch to unified diff)

--- src/sys/net/if_ppp.h 2005/12/11 23:05:25 1.23
+++ src/sys/net/if_ppp.h 2008/11/25 02:40:36 1.24
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_ppp.h,v 1.23 2005/12/11 23:05:25 thorpej Exp $ */ 1/* $NetBSD: if_ppp.h,v 1.24 2008/11/25 02:40:36 cube Exp $ */
2/* Id: if_ppp.h,v 1.16 1997/04/30 05:46:04 paulus Exp */ 2/* Id: if_ppp.h,v 1.16 1997/04/30 05:46:04 paulus Exp */
3 3
4/* 4/*
5 * if_ppp.h - Point-to-Point Protocol definitions. 5 * if_ppp.h - Point-to-Point Protocol definitions.
6 * 6 *
7 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. 7 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 12 *
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -163,15 +163,19 @@ struct ppp_rawin { @@ -163,15 +163,19 @@ struct ppp_rawin {
163/* 163/*
164 * These two are interface ioctls so that pppstats can do them on 164 * These two are interface ioctls so that pppstats can do them on
165 * a socket without having to open the serial device. 165 * a socket without having to open the serial device.
166 */ 166 */
167#define SIOCGPPPSTATS _IOWR('i', 123, struct ifpppstatsreq) 167#define SIOCGPPPSTATS _IOWR('i', 123, struct ifpppstatsreq)
168#define SIOCGPPPCSTATS _IOWR('i', 122, struct ifpppcstatsreq) 168#define SIOCGPPPCSTATS _IOWR('i', 122, struct ifpppcstatsreq)
169 169
170#if !defined(ifr_mtu) 170#if !defined(ifr_mtu)
171#define ifr_mtu ifr_ifru.ifru_metric 171#define ifr_mtu ifr_ifru.ifru_metric
172#endif 172#endif
173 173
174#if defined(_KERNEL) || defined(KERNEL) 174#if defined(_KERNEL) || defined(KERNEL)
175void pppattach(void); 175void pppattach(void);
 176
 177struct compressor;
 178int ppp_register_compressor(struct compressor *);
 179int ppp_unregister_compressor(struct compressor *);
176#endif 180#endif
177#endif /* !_NET_IF_PPP_H_ */ 181#endif /* !_NET_IF_PPP_H_ */

cvs diff -r1.14 -r1.15 src/sys/net/ppp-comp.h (expand / switch to unified diff)

--- src/sys/net/ppp-comp.h 2008/02/20 17:05:53 1.14
+++ src/sys/net/ppp-comp.h 2008/11/25 02:40:36 1.15
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ppp-comp.h,v 1.14 2008/02/20 17:05:53 matt Exp $ */ 1/* $NetBSD: ppp-comp.h,v 1.15 2008/11/25 02:40:36 cube Exp $ */
2 2
3/* 3/*
4 * ppp-comp.h - Definitions for doing PPP packet compression. 4 * ppp-comp.h - Definitions for doing PPP packet compression.
5 * 5 *
6 * Copyright (c) 1989-2002 Paul Mackerras. All rights reserved. 6 * Copyright (c) 1989-2002 Paul Mackerras. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
@@ -52,26 +52,28 @@ @@ -52,26 +52,28 @@
52#define DO_PREDICTOR_2 0 52#define DO_PREDICTOR_2 0
53 53
54/* 54/*
55 * How many entries to make available in the compressors table 55 * How many entries to make available in the compressors table
56 */ 56 */
57#ifndef PPP_COMPRESSORS_MAX 57#ifndef PPP_COMPRESSORS_MAX
58#define PPP_COMPRESSORS_MAX 8 58#define PPP_COMPRESSORS_MAX 8
59#endif 59#endif
60 60
61/* 61/*
62 * Structure giving methods for compression/decompression. 62 * Structure giving methods for compression/decompression.
63 */ 63 */
64#ifdef PACKETPTR 64#ifdef PACKETPTR
 65#include <sys/queue.h>
 66
65struct compressor { 67struct compressor {
66 int compress_proto; /* CCP compression protocol number */ 68 int compress_proto; /* CCP compression protocol number */
67 69
68 /* Allocate space for a compressor (transmit side) */ 70 /* Allocate space for a compressor (transmit side) */
69 void *(*comp_alloc)(u_char *, int); 71 void *(*comp_alloc)(u_char *, int);
70 /* Free space used by a compressor */ 72 /* Free space used by a compressor */
71 void (*comp_free)(void *); 73 void (*comp_free)(void *);
72 /* Initialize a compressor */ 74 /* Initialize a compressor */
73 int (*comp_init)(void *, u_char *, int, int, int, int); 75 int (*comp_init)(void *, u_char *, int, int, int, int);
74 /* Reset a compressor */ 76 /* Reset a compressor */
75 void (*comp_reset)(void *); 77 void (*comp_reset)(void *);
76 /* Compress a packet */ 78 /* Compress a packet */
77 int (*compress)(void *, PACKETPTR *, PACKETPTR, int, int); 79 int (*compress)(void *, PACKETPTR *, PACKETPTR, int, int);
@@ -82,26 +84,29 @@ struct compressor { @@ -82,26 +84,29 @@ struct compressor {
82 void *(*decomp_alloc)(u_char *, int); 84 void *(*decomp_alloc)(u_char *, int);
83 /* Free space used by a decompressor */ 85 /* Free space used by a decompressor */
84 void (*decomp_free)(void *); 86 void (*decomp_free)(void *);
85 /* Initialize a decompressor */ 87 /* Initialize a decompressor */
86 int (*decomp_init)(void *, u_char *, int, int, int, int, int); 88 int (*decomp_init)(void *, u_char *, int, int, int, int, int);
87 /* Reset a decompressor */ 89 /* Reset a decompressor */
88 void (*decomp_reset)(void *); 90 void (*decomp_reset)(void *);
89 /* Decompress a packet. */ 91 /* Decompress a packet. */
90 int (*decompress)(void *, PACKETPTR, PACKETPTR *); 92 int (*decompress)(void *, PACKETPTR, PACKETPTR *);
91 /* Update state for an incompressible packet received */ 93 /* Update state for an incompressible packet received */
92 void (*incomp)(void *, PACKETPTR); 94 void (*incomp)(void *, PACKETPTR);
93 /* Return decompression statistics */ 95 /* Return decompression statistics */
94 void (*decomp_stat)(void *, struct compstat *); 96 void (*decomp_stat)(void *, struct compstat *);
 97
 98 LIST_ENTRY(compressor) comp_list;
 99 const char *comp_name;
95}; 100};
96#endif /* PACKETPTR */ 101#endif /* PACKETPTR */
97 102
98/* 103/*
99 * Return values for decompress routine. 104 * Return values for decompress routine.
100 * We need to make these distinctions so that we can disable certain 105 * We need to make these distinctions so that we can disable certain
101 * useful functionality, namely sending a CCP reset-request as a result 106 * useful functionality, namely sending a CCP reset-request as a result
102 * of an error detected after decompression. This is to avoid infringing 107 * of an error detected after decompression. This is to avoid infringing
103 * a patent held by Motorola. 108 * a patent held by Motorola.
104 * Don't you just lurve software patents. 109 * Don't you just lurve software patents.
105 */ 110 */
106#define DECOMP_OK 0 /* everything went OK */ 111#define DECOMP_OK 0 /* everything went OK */
107#define DECOMP_ERROR 1 /* error detected before decomp. */ 112#define DECOMP_ERROR 1 /* error detected before decomp. */

cvs diff -r1.17 -r1.18 src/sys/net/ppp-deflate.c (expand / switch to unified diff)

--- src/sys/net/ppp-deflate.c 2008/05/05 13:41:30 1.17
+++ src/sys/net/ppp-deflate.c 2008/11/25 02:40:36 1.18
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ppp-deflate.c,v 1.17 2008/05/05 13:41:30 ad Exp $ */ 1/* $NetBSD: ppp-deflate.c,v 1.18 2008/11/25 02:40:36 cube Exp $ */
2/* Id: ppp-deflate.c,v 1.5 1997/03/04 03:33:28 paulus Exp */ 2/* Id: ppp-deflate.c,v 1.5 1997/03/04 03:33:28 paulus Exp */
3 3
4/* 4/*
5 * ppp_deflate.c - interface the zlib procedures for Deflate compression 5 * ppp_deflate.c - interface the zlib procedures for Deflate compression
6 * and decompression (as used by gzip) to the PPP code. 6 * and decompression (as used by gzip) to the PPP code.
7 * This version is for use with mbufs on BSD-derived systems. 7 * This version is for use with mbufs on BSD-derived systems.
8 * 8 *
9 * Copyright (c) 1989-2002 Paul Mackerras. All rights reserved. 9 * Copyright (c) 1989-2002 Paul Mackerras. All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 14 *
@@ -29,32 +29,35 @@ @@ -29,32 +29,35 @@
29 * "This product includes software developed by Paul Mackerras 29 * "This product includes software developed by Paul Mackerras
30 * <paulus@samba.org>". 30 * <paulus@samba.org>".
31 * 31 *
32 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 32 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
33 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 33 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
34 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 34 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
35 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 35 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
36 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 36 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
37 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 37 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
38 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 38 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
39 */ 39 */
40 40
41#include <sys/cdefs.h> 41#include <sys/cdefs.h>
42__KERNEL_RCSID(0, "$NetBSD: ppp-deflate.c,v 1.17 2008/05/05 13:41:30 ad Exp $"); 42__KERNEL_RCSID(0, "$NetBSD: ppp-deflate.c,v 1.18 2008/11/25 02:40:36 cube Exp $");
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/systm.h> 45#include <sys/systm.h>
46#include <sys/mbuf.h> 46#include <sys/mbuf.h>
 47#include <sys/module.h>
 48#include <net/if.h>
47#include <net/ppp_defs.h> 49#include <net/ppp_defs.h>
 50#include <net/if_ppp.h>
48#include <net/zlib.h> 51#include <net/zlib.h>
49 52
50#define PACKETPTR struct mbuf * 53#define PACKETPTR struct mbuf *
51#include <net/ppp-comp.h> 54#include <net/ppp-comp.h>
52 55
53#if DO_DEFLATE 56#if DO_DEFLATE
54 57
55#define DEFLATE_DEBUG 1 58#define DEFLATE_DEBUG 1
56 59
57/* 60/*
58 * State for a Deflate (de)compressor. 61 * State for a Deflate (de)compressor.
59 */ 62 */
60struct deflate_state { 63struct deflate_state {
@@ -82,58 +85,60 @@ static int z_decomp_init(void *state, u_ @@ -82,58 +85,60 @@ static int z_decomp_init(void *state, u_
82 int unit, int hdrlen, int mru, int debug); 85 int unit, int hdrlen, int mru, int debug);
83static int z_compress(void *state, struct mbuf **mret, 86static int z_compress(void *state, struct mbuf **mret,
84 struct mbuf *mp, int slen, int maxolen); 87 struct mbuf *mp, int slen, int maxolen);
85static void z_incomp(void *state, struct mbuf *dmsg); 88static void z_incomp(void *state, struct mbuf *dmsg);
86static int z_decompress(void *state, struct mbuf *cmp, 89static int z_decompress(void *state, struct mbuf *cmp,
87 struct mbuf **dmpp); 90 struct mbuf **dmpp);
88static void z_comp_reset(void *state); 91static void z_comp_reset(void *state);
89static void z_decomp_reset(void *state); 92static void z_decomp_reset(void *state);
90static void z_comp_stats(void *state, struct compstat *stats); 93static void z_comp_stats(void *state, struct compstat *stats);
91 94
92/* 95/*
93 * Procedures exported to if_ppp.c. 96 * Procedures exported to if_ppp.c.
94 */ 97 */
95struct compressor ppp_deflate = { 98static struct compressor ppp_deflate = {
96 CI_DEFLATE, /* compress_proto */ 99 .compress_proto = CI_DEFLATE,
97 z_comp_alloc, /* comp_alloc */ 100 .comp_alloc = z_comp_alloc,
98 z_comp_free, /* comp_free */ 101 .comp_free = z_comp_free,
99 z_comp_init, /* comp_init */ 102 .comp_init = z_comp_init,
100 z_comp_reset, /* comp_reset */ 103 .comp_reset = z_comp_reset,
101 z_compress, /* compress */ 104 .compress = z_compress,
102 z_comp_stats, /* comp_stat */ 105 .comp_stat = z_comp_stats,
103 z_decomp_alloc, /* decomp_alloc */ 106 .decomp_alloc = z_decomp_alloc,
104 z_decomp_free, /* decomp_free */ 107 .decomp_free = z_decomp_free,
105 z_decomp_init, /* decomp_init */ 108 .decomp_init = z_decomp_init,
106 z_decomp_reset, /* decomp_reset */ 109 .decomp_reset = z_decomp_reset,
107 z_decompress, /* decompress */ 110 .decompress = z_decompress,
108 z_incomp, /* incomp */ 111 .incomp = z_incomp,
109 z_comp_stats, /* decomp_stat */ 112 .decomp_stat = z_comp_stats,
 113 .comp_name = "ppp_deflate"
110}; 114};
111 115
112struct compressor ppp_deflate_draft = { 116static struct compressor ppp_deflate_draft = {
113 CI_DEFLATE_DRAFT, /* compress_proto */ 117 .compress_proto = CI_DEFLATE_DRAFT,
114 z_comp_alloc, /* comp_alloc */ 118 .comp_alloc = z_comp_alloc,
115 z_comp_free, /* comp_free */ 119 .comp_free = z_comp_free,
116 z_comp_init, /* comp_init */ 120 .comp_init = z_comp_init,
117 z_comp_reset, /* comp_reset */ 121 .comp_reset = z_comp_reset,
118 z_compress, /* compress */ 122 .compress = z_compress,
119 z_comp_stats, /* comp_stat */ 123 .comp_stat = z_comp_stats,
120 z_decomp_alloc, /* decomp_alloc */ 124 .decomp_alloc = z_decomp_alloc,
121 z_decomp_free, /* decomp_free */ 125 .decomp_free = z_decomp_free,
122 z_decomp_init, /* decomp_init */ 126 .decomp_init = z_decomp_init,
123 z_decomp_reset, /* decomp_reset */ 127 .decomp_reset = z_decomp_reset,
124 z_decompress, /* decompress */ 128 .decompress = z_decompress,
125 z_incomp, /* incomp */ 129 .incomp = z_incomp,
126 z_comp_stats, /* decomp_stat */ 130 .decomp_stat = z_comp_stats,
 131 .comp_name = "ppp_deflate"
127}; 132};
128/* 133/*
129 * Space allocation and freeing routines for use by zlib routines. 134 * Space allocation and freeing routines for use by zlib routines.
130 */ 135 */
131void * 136void *
132zalloc(void *notused, u_int items, u_int size) 137zalloc(void *notused, u_int items, u_int size)
133{ 138{
134 void *ptr; 139 void *ptr;
135 140
136 ptr = malloc(items * size, M_DEVBUF, M_NOWAIT); 141 ptr = malloc(items * size, M_DEVBUF, M_NOWAIT);
137 return ptr; 142 return ptr;
138} 143}
139 144
@@ -654,14 +659,43 @@ z_incomp(void *arg, struct mbuf *mi) @@ -654,14 +659,43 @@ z_incomp(void *arg, struct mbuf *mi)
654 state->strm.avail_in = mi->m_len; 659 state->strm.avail_in = mi->m_len;
655 rlen += mi->m_len; 660 rlen += mi->m_len;
656 } 661 }
657 662
658 /* 663 /*
659 * Update stats. 664 * Update stats.
660 */ 665 */
661 state->stats.inc_bytes += rlen; 666 state->stats.inc_bytes += rlen;
662 state->stats.inc_packets++; 667 state->stats.inc_packets++;
663 state->stats.unc_bytes += rlen; 668 state->stats.unc_bytes += rlen;
664 state->stats.unc_packets++; 669 state->stats.unc_packets++;
665} 670}
666 671
 672MODULE(MODULE_CLASS_MISC, ppp_deflate, NULL);
 673
 674static int
 675ppp_deflate_modcmd(modcmd_t cmd, void *arg)
 676{
 677 int error, error1;
 678
 679 switch (cmd) {
 680 case MODULE_CMD_INIT:
 681 if ((error = ppp_register_compressor(&ppp_deflate)) != 0)
 682 return error;
 683 if ((error =
 684 ppp_register_compressor(&ppp_deflate_draft)) != 0)
 685 (void)ppp_unregister_compressor(&ppp_deflate);
 686 return error;
 687 case MODULE_CMD_FINI:
 688 error = ppp_unregister_compressor(&ppp_deflate);
 689 error1 = ppp_unregister_compressor(&ppp_deflate_draft);
 690 if (error)
 691 return error;
 692 return error1;
 693 case MODULE_CMD_STAT:
 694 return 0;
 695 default:
 696 return ENOTTY;
 697 }
 698
 699 return ENOTTY;
 700}
667#endif /* DO_DEFLATE */ 701#endif /* DO_DEFLATE */