From: Matt Domsch Date: Tue, 20 Jul 2004 20:46:36 +0000 Subject: Re: [1/2]: ppp_mppe inclusion Message-Id: <20040720204636.GB27576@lists.us.dell.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-ppp@vger.kernel.org On Tue, Jul 20, 2004 at 03:45:40PM -0500, Matt Domsch wrote: > This mail will be followed by two patches, for comment on proposed > solution. I've compiled this, but am not able to test this week. > > 1: ppp_generic.patch adds three new fields to struct compressor, > allowing ppp_generic.c to allocate additional skb space for > compression/decompression routines that may need such, and a > 'must_compress' flag to be used to avoid sending non-encrypted packets > when SC_CCP_UP is not set. -- Matt Domsch Sr. Software Engineer, Lead Engineer Dell Linux Solutions linux.dell.com & www.dell.com/linux Linux on Dell mailing lists @ http://lists.us.dell.com You can import this changeset into BK by piping this whole message to '| bk receive [path to repository]' or apply the patch as usual. ================================= ChangeSet@1.1849, 2004-07-20 16:27:00-04:00, Matt_Domsch@dell.com PPP: add fields to struct compressor, use them in ppp-generic.c Add fields to struct compressor to allocate extra skb space for compression/decompression, and a flag to drop packets if CCP is down but required by the compression (encryption) alg. drivers/net/ppp_generic.c | 76 ++++++++++++++++++++++++++++++++-------------- include/linux/ppp-comp.h | 14 ++++++++ 2 files changed, 67 insertions(+), 23 deletions(-) diff -Nru a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c --- a/drivers/net/ppp_generic.c 2004-07-20 16:36:44 -04:00 +++ b/drivers/net/ppp_generic.c 2004-07-20 16:36:44 -04:00 @@ -1008,6 +1008,51 @@ ppp_xmit_unlock(ppp); } +static inline struct sk_buff * +pad_compress_skb(struct ppp *ppp, struct sk_buff *skb) +{ + struct sk_buff *new_skb; + int len; + int new_skb_size = ppp->dev->mtu + ppp->xcomp->comp_skb_extra_space + ppp->dev->hard_header_len; + int compressor_skb_size = ppp->dev->mtu + ppp->xcomp->comp_skb_extra_space + PPP_HDRLEN; + new_skb = alloc_skb(new_skb_size, GFP_ATOMIC); + if (!new_skb) { + printk(KERN_ERR "PPP: no memory (comp pkt)\n"); + return NULL; + } + if (ppp->dev->hard_header_len > PPP_HDRLEN) + skb_reserve(new_skb, + ppp->dev->hard_header_len - PPP_HDRLEN); + + /* compressor still expects A/C bytes in hdr */ + len = ppp->xcomp->compress(ppp->xc_state, skb->data - 2, + new_skb->data, skb->len + 2, + compressor_skb_size); + if (len > 0 && (ppp->flags & SC_CCP_UP)) { + kfree_skb(skb); + skb = new_skb; + skb_put(skb, len); + skb_pull(skb, 2); /* pull off A/C bytes */ + } else if (len = 0) { + /* didn't compress, or CCP not up yet */ + kfree_skb(new_skb); + new_skb = NULL; + } else { + /* + * (len < 0) + * MPPE requires that we do not send unencrypted + * frames. The compressor will return -1 if we + * should drop the frame. We cannot simply test + * the compress_proto because MPPE and MPPC share + * the same number. + */ + printk(KERN_ERR "ppp: compressor dropped pkt\n"); + kfree_skb(new_skb); + new_skb = NULL; + } + return new_skb; +} + /* * Compress and send a frame. * The caller should have locked the xmit path, @@ -1098,29 +1143,13 @@ /* try to do packet compression */ if ((ppp->xstate & SC_COMP_RUN) && ppp->xc_state != 0 && proto != PPP_LCP && proto != PPP_CCP) { - new_skb = alloc_skb(ppp->dev->mtu + ppp->dev->hard_header_len, - GFP_ATOMIC); - if (new_skb = 0) { - printk(KERN_ERR "PPP: no memory (comp pkt)\n"); + if (!(ppp->flags & SC_CCP_UP) && ppp->xcomp->must_compress) { + printk(KERN_ERR "ppp: compression required but down - pkt dropped.\n"); goto drop; } - if (ppp->dev->hard_header_len > PPP_HDRLEN) - skb_reserve(new_skb, - ppp->dev->hard_header_len - PPP_HDRLEN); - - /* compressor still expects A/C bytes in hdr */ - len = ppp->xcomp->compress(ppp->xc_state, skb->data - 2, - new_skb->data, skb->len + 2, - ppp->dev->mtu + PPP_HDRLEN); - if (len > 0 && (ppp->flags & SC_CCP_UP)) { - kfree_skb(skb); - skb = new_skb; - skb_put(skb, len); - skb_pull(skb, 2); /* pull off A/C bytes */ - } else { - /* didn't compress, or CCP not up yet */ - kfree_skb(new_skb); - } + skb = pad_compress_skb(ppp, skb); + if (!skb) + goto drop; } /* @@ -1140,7 +1169,8 @@ return; drop: - kfree_skb(skb); + if (skb) + kfree_skb(skb); ++ppp->stats.tx_errors; } @@ -1628,7 +1658,7 @@ goto err; if (proto = PPP_COMP) { - ns = dev_alloc_skb(ppp->mru + PPP_HDRLEN); + ns = dev_alloc_skb(ppp->mru + ppp->rcomp->decomp_skb_extra_space + PPP_HDRLEN); if (ns = 0) { printk(KERN_ERR "ppp_decompress_frame: no memory\n"); goto err; diff -Nru a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h --- a/include/linux/ppp-comp.h 2004-07-20 16:36:44 -04:00 +++ b/include/linux/ppp-comp.h 2004-07-20 16:36:44 -04:00 @@ -111,6 +111,13 @@ /* Used in locking compressor modules */ struct module *owner; + /* Extra skb space needed by the compressor algorithm */ + unsigned int comp_skb_extra_space; + /* Extra skb space needed by the decompressor algorithm */ + unsigned int decomp_skb_extra_space; + /* if must_compress is set, but ppp->flags != SC_CCP_UP + * then drop the packet */ + unsigned int must_compress; }; /* @@ -189,6 +196,13 @@ #define DEFLATE_METHOD(x) ((x) & 0x0F) #define DEFLATE_MAKE_OPT(w) ((((w) - 8) << 4) + DEFLATE_METHOD_VAL) #define DEFLATE_CHK_SEQUENCE 0 + +/* + * Definitions for MPPE. + */ + +#define CI_MPPE 18 /* config option for MPPE */ +#define CILEN_MPPE 6 /* length of config option */ /* * Definitions for other, as yet unsupported, compression methods. ================================= This BitKeeper patch contains the following changesets: 1.1849 ## Wrapped with gzip_uu ## M'XL( %R"_4 [58:7/;-A#]+/Z*33*36HX.7CI=>>S*;I*)G6B<>/JA[G @ M$A0YXE4 M.-6^>]=@*1$6Y:=HY$U% DN'AX6NXL'OX!+3MFX<4Z$<$[2F+N! M]@+>I%R,&QZ-HHZ;QMAPD:;8T(T]96%VY\MNG&6T&X5)_KEM=GH:&LV(< .X MIHR/&T;'6K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