patch-2.1.92 linux/drivers/net/ppp_deflate.c

Next file: linux/drivers/net/smc-mca.c
Previous file: linux/drivers/net/ppp.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.91/linux/drivers/net/ppp_deflate.c linux/drivers/net/ppp_deflate.c
@@ -1,5 +1,5 @@
 /*
- *  ==FILEVERSION 971001==
+ *  ==FILEVERSION 980319==
  *
  * ppp_deflate.c - interface the zlib procedures for Deflate compression
  * and decompression (as used by gzip) to the PPP code.
@@ -188,20 +188,21 @@
 	struct ppp_deflate_state *state;
 	int w_size;
 
-	MOD_INC_USE_COUNT;
-	if (opt_len != CILEN_DEFLATE || options[0] != CI_DEFLATE
+	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)
-		goto out_fail;
+		return NULL;
 	w_size = DEFLATE_SIZE(options[2]);
 	if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
-		goto out_fail;
+		return NULL;
 
 	state = (struct ppp_deflate_state *) kmalloc(sizeof(*state), GFP_KERNEL);
 	if (state == NULL)
-		goto out_fail;
+		return NULL;
 
+	MOD_INC_USE_COUNT;
 	memset (state, 0, sizeof (struct ppp_deflate_state));
 	state->strm.next_in = NULL;
 	state->strm.zalloc  = zalloc_init;
@@ -217,7 +218,6 @@
 
 out_free:
 	z_comp_free(state);
-out_fail:
 	MOD_DEC_USE_COUNT;
 	return NULL;
 }
@@ -230,7 +230,8 @@
 {
 	struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
 
-	if (opt_len < CILEN_DEFLATE || options[0] != CI_DEFLATE
+	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
@@ -264,7 +265,7 @@
     int isize, osize;
 {
 	struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
-	int r, proto, off, olen;
+	int r, proto, off, olen, oavail;
 	unsigned char *wptr;
 
 	/*
@@ -291,9 +292,10 @@
 	wptr += PPP_HDRLEN;
 	wptr[0] = state->seqno >> 8;
 	wptr[1] = state->seqno;
-	wptr += 2;
+	wptr += DEFLATE_OVHD;
+	olen = PPP_HDRLEN + DEFLATE_OVHD;
 	state->strm.next_out = wptr;
-	state->strm.avail_out = osize - (PPP_HDRLEN + 2);
+	state->strm.avail_out = oavail = osize - olen;
 	++state->seqno;
 
 	off = (proto > 0xff) ? 2 : 3;	/* skip 1st proto byte if 0 */
@@ -301,25 +303,23 @@
 	state->strm.next_in = rptr;
 	state->strm.avail_in = (isize - off);
 
-	olen = 0;
 	for (;;) {
 		r = deflate(&state->strm, Z_PACKET_FLUSH);
 		if (r != Z_OK) {
 			if (state->debug)
-				printk(KERN_DEBUG "z_compress: deflate returned %d (%s)\n",
-				       r, (state->strm.msg? state->strm.msg: ""));
+				printk(KERN_ERR
+				       "z_compress: deflate returned %d\n", r);
 			break;
 		}
 		if (state->strm.avail_out == 0) {
-			olen += osize;
+			olen += oavail;
 			state->strm.next_out = NULL;
-			state->strm.avail_out = 1000000;
+			state->strm.avail_out = oavail = 1000000;
 		} else {
 			break;		/* all done */
 		}
 	}
-	if (olen < osize)
-		olen += osize - state->strm.avail_out;
+	olen += oavail - state->strm.avail_out;
 
 	/*
 	 * See if we managed to reduce the size of the packet.
@@ -372,19 +372,21 @@
 	struct ppp_deflate_state *state;
 	int w_size;
 
-	MOD_INC_USE_COUNT;
-	if (opt_len != CILEN_DEFLATE || options[0] != CI_DEFLATE
+	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)
-		goto out_fail;
+		return NULL;
 	w_size = DEFLATE_SIZE(options[2]);
 	if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
-		goto out_fail;
+		return NULL;
 
 	state = (struct ppp_deflate_state *) kmalloc(sizeof(*state), GFP_KERNEL);
 	if (state == NULL)
-		goto out_fail;
+		return NULL;
+
+	MOD_INC_USE_COUNT;
 	memset (state, 0, sizeof (struct ppp_deflate_state));
 	state->w_size        = w_size;
 	state->strm.next_out = NULL;
@@ -398,7 +400,6 @@
 
 out_free:
 	z_decomp_free(state);
-out_fail:
 	MOD_DEC_USE_COUNT;
 	return NULL;
 }
@@ -411,7 +412,8 @@
 {
 	struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
 
-	if (opt_len < CILEN_DEFLATE || options[0] != CI_DEFLATE
+	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
@@ -543,8 +545,12 @@
 		}
 	}
 
-	if (decode_proto)
+	if (decode_proto) {
+		if (state->debug)
+			printk(KERN_DEBUG "z_decompress%d: didn't get proto\n",
+			       state->unit);
 		return DECOMP_ERROR;
+	}
 
 	olen = osize + overflow - state->strm.avail_out;
 	state->stats.unc_bytes += olen;
@@ -634,6 +640,23 @@
 	z_comp_stats,		/* decomp_stat */
 };
 
+struct compressor ppp_deflate_draft = {
+	CI_DEFLATE_DRAFT,	/* compress_proto */
+	z_comp_alloc,		/* comp_alloc */
+	z_comp_free,		/* comp_free */
+	z_comp_init,		/* comp_init */
+	z_comp_reset,		/* comp_reset */
+	z_compress,		/* compress */
+	z_comp_stats,		/* comp_stat */
+	z_decomp_alloc,		/* decomp_alloc */
+	z_decomp_free,		/* decomp_free */
+	z_decomp_init,		/* decomp_init */
+	z_decomp_reset,		/* decomp_reset */
+	z_decompress,		/* decompress */
+	z_incomp,		/* incomp */
+	z_comp_stats,		/* decomp_stat */
+};
+
 #ifdef MODULE
 /*************************************************************
  * Module support routines
@@ -646,6 +669,7 @@
         if (answer == 0)
                 printk (KERN_INFO
 			"PPP Deflate Compression module registered\n");
+	ppp_register_compressor(&ppp_deflate_draft);
         return answer;
 }
      
@@ -655,7 +679,9 @@
 	if (MOD_IN_USE)
 		printk (KERN_INFO
 			"Deflate Compression module busy, remove delayed\n");
-	else
+	else {
 	        ppp_unregister_compressor (&ppp_deflate);
+	        ppp_unregister_compressor (&ppp_deflate_draft);
+	}
 }
 #endif

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov