From b34cd4f6562185d2bbc96612bbb3dc598f3a8dcd Mon Sep 17 00:00:00 2001 From: Frank Cusack Date: Tue, 13 May 2003 01:25:36 +0000 Subject: [PATCH] modify ppp_generic patch to avoid an if() test and extra additions on every pass through ppp_send_frame(); make a 2.4.19+ version of it; improve mppeinstall.sh. --- linux/mppe/linux-2.4.18-pad.patch | 85 ++++++++++++++++----- linux/mppe/linux-2.4.19-pad.patch | 118 ++++++++++++++++++++++++++++++ linux/mppe/mppeinstall.sh | 39 ++++++++-- 3 files changed, 218 insertions(+), 24 deletions(-) create mode 100644 linux/mppe/linux-2.4.19-pad.patch diff --git a/linux/mppe/linux-2.4.18-pad.patch b/linux/mppe/linux-2.4.18-pad.patch index 01a56ff..40d8a7e 100644 --- a/linux/mppe/linux-2.4.18-pad.patch +++ b/linux/mppe/linux-2.4.18-pad.patch @@ -1,29 +1,50 @@ ---- linux/drivers/net/ppp_generic.c.orig Mon Feb 25 11:37:59 2002 -+++ linux/drivers/net/ppp_generic.c Mon Mar 25 10:19:53 2002 -@@ -1006,8 +1006,15 @@ +--- linux-2.4.18/drivers/net/ppp_generic.c.orig Mon May 12 01:36:31 2003 ++++ linux-2.4.18/drivers/net/ppp_generic.c Mon May 12 03:09:13 2003 +@@ -99,6 +99,7 @@ + spinlock_t rlock; /* lock for receive side */ + spinlock_t wlock; /* lock for transmit side */ + int mru; /* max receive unit */ ++ int mru_alloc; /* MAX(1500,MRU) for dev_alloc_skb() */ + unsigned int flags; /* control bits */ + unsigned int xstate; /* transmit state bits */ + unsigned int rstate; /* receive state bits */ +@@ -126,6 +127,7 @@ + struct sock_fprog pass_filter; /* filter for packets to pass */ + struct sock_fprog active_filter;/* filter for pkts to reset idle */ + #endif /* CONFIG_PPP_FILTER */ ++ int comp_pad; /* padding for compressor (MPPE) */ + }; + + /* +@@ -531,6 +533,10 @@ + if (get_user(val, (int *) arg)) + break; + ppp->mru = val; ++ if (ppp->mru > ppp->mru_alloc) ++ ppp->mru_alloc = ppp->mru; ++ else if (ppp->mru < PPP_MRU) ++ ppp->mru_alloc = PPP_MRU; /* shrink to minimum */ + err = 0; + break; + +@@ -1006,8 +1012,8 @@ /* 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); -+ int new_skb_size = ppp->dev->mtu + ppp->dev->hard_header_len; -+ int compressor_skb_size = ppp->dev->mtu + PPP_HDRLEN; -+ -+ if (ppp->xcomp->compress_proto == CI_MPPE) { -+ /* CCP [must have] reduced MTU by MPPE_PAD. */ -+ new_skb_size += MPPE_PAD; -+ compressor_skb_size += MPPE_PAD; -+ } -+ new_skb = alloc_skb(new_skb_size, GFP_ATOMIC); ++ new_skb = alloc_skb(ppp->dev->mtu + ppp->dev->hard_header_len ++ + ppp->comp_pad, GFP_ATOMIC); if (new_skb == 0) { printk(KERN_ERR "PPP: no memory (comp pkt)\n"); goto drop; -@@ -1019,15 +1026,27 @@ +@@ -1019,15 +1025,28 @@ /* 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); -+ compressor_skb_size); ++ ppp->dev->mtu + ppp->comp_pad ++ + PPP_HDRLEN); if (len > 0 && (ppp->flags & SC_CCP_UP)) { kfree_skb(skb); skb = new_skb; @@ -48,12 +69,12 @@ } } -@@ -1515,14 +1534,14 @@ +@@ -1515,14 +1534,15 @@ int len; if (proto == PPP_COMP) { - ns = dev_alloc_skb(ppp->mru + PPP_HDRLEN); -+ ns = dev_alloc_skb(ppp->mru + 128 + PPP_HDRLEN); ++ ns = dev_alloc_skb(ppp->mru_alloc + PPP_HDRLEN); if (ns == 0) { printk(KERN_ERR "ppp_decompress_frame: no memory\n"); goto err; @@ -61,7 +82,37 @@ /* the decompressor still expects the A/C bytes in the hdr */ len = ppp->rcomp->decompress(ppp->rc_state, skb->data - 2, - skb->len + 2, ns->data, ppp->mru + PPP_HDRLEN); -+ skb->len + 2, ns->data, ppp->mru + 128 + PPP_HDRLEN); ++ skb->len + 2, ns->data, ++ ppp->mru_alloc + PPP_HDRLEN); if (len < 0) { /* Pass the compressed frame to pppd as an error indication. */ +@@ -1949,6 +1969,20 @@ + ppp_xmit_unlock(ppp); + err = 0; + } ++ if (ccp_option[0] == CI_MPPE) ++ /* ++ * pppd (userland) has reduced the MTU by MPPE_PAD, ++ * to accomodate "compressor" growth. We must ++ * increase the space allocated for compressor ++ * output in ppp_send_frame() accordingly. Note ++ * that from a purist's view, it may be more correct ++ * to require multilink and fragment large packets, ++ * but that seems inefficient compared to this ++ * little trick. ++ */ ++ ppp->comp_pad = MPPE_PAD; ++ else ++ ppp->comp_pad = 0; + + } else { + ppp_recv_lock(ppp); +@@ -2229,6 +2263,7 @@ + + ppp->file.index = unit; + ppp->mru = PPP_MRU; ++ ppp->mru_alloc = PPP_MRU; + init_ppp_file(&ppp->file, INTERFACE); + ppp->file.hdrlen = PPP_HDRLEN - 2; /* don't count proto bytes */ + for (i = 0; i < NUM_NP; ++i) diff --git a/linux/mppe/linux-2.4.19-pad.patch b/linux/mppe/linux-2.4.19-pad.patch new file mode 100644 index 0000000..17f751c --- /dev/null +++ b/linux/mppe/linux-2.4.19-pad.patch @@ -0,0 +1,118 @@ +--- linux-2.4.19/drivers/net/ppp_generic.c.orig Mon May 12 01:36:31 2003 ++++ linux-2.4.19/drivers/net/ppp_generic.c Mon May 12 03:09:13 2003 +@@ -99,6 +99,7 @@ + spinlock_t rlock; /* lock for receive side 58 */ + spinlock_t wlock; /* lock for transmit side 5c */ + int mru; /* max receive unit 60 */ ++ int mru_alloc; /* MAX(1500,MRU) for dev_alloc_skb() */ + unsigned int flags; /* control bits 64 */ + unsigned int xstate; /* transmit state bits 68 */ + unsigned int rstate; /* receive state bits 6c */ +@@ -126,6 +127,7 @@ + struct sock_fprog pass_filter; /* filter for packets to pass */ + struct sock_fprog active_filter;/* filter for pkts to reset idle */ + #endif /* CONFIG_PPP_FILTER */ ++ int comp_pad; /* padding for compressor (MPPE) */ + }; + + /* +@@ -531,6 +533,10 @@ + if (get_user(val, (int *) arg)) + break; + ppp->mru = val; ++ if (ppp->mru > ppp->mru_alloc) ++ ppp->mru_alloc = ppp->mru; ++ else if (ppp->mru < PPP_MRU) ++ ppp->mru_alloc = PPP_MRU; /* shrink to minimum */ + err = 0; + break; + +@@ -1006,8 +1012,8 @@ + /* 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); ++ new_skb = alloc_skb(ppp->dev->mtu + ppp->dev->hard_header_len ++ + ppp->comp_pad, GFP_ATOMIC); + if (new_skb == 0) { + printk(KERN_ERR "PPP: no memory (comp pkt)\n"); + goto drop; +@@ -1019,15 +1025,28 @@ + /* 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); ++ ppp->dev->mtu + ppp->comp_pad ++ + 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 { ++ } else if (len == 0) { + /* didn't compress, or CCP not up yet */ + kfree_skb(new_skb); ++ } 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); ++ goto drop; + } + } + +@@ -1515,14 +1534,15 @@ + int len; + + if (proto == PPP_COMP) { +- ns = dev_alloc_skb(ppp->mru + PPP_HDRLEN); ++ ns = dev_alloc_skb(ppp->mru_alloc + PPP_HDRLEN); + if (ns == 0) { + printk(KERN_ERR "ppp_decompress_frame: no memory\n"); + goto err; + } + /* the decompressor still expects the A/C bytes in the hdr */ + len = ppp->rcomp->decompress(ppp->rc_state, skb->data - 2, +- skb->len + 2, ns->data, ppp->mru + PPP_HDRLEN); ++ skb->len + 2, ns->data, ++ ppp->mru_alloc + PPP_HDRLEN); + if (len < 0) { + /* Pass the compressed frame to pppd as an + error indication. */ +@@ -1949,6 +1969,20 @@ + ppp_xmit_unlock(ppp); + err = 0; + } ++ if (ccp_option[0] == CI_MPPE) ++ /* ++ * pppd (userland) has reduced the MTU by MPPE_PAD, ++ * to accomodate "compressor" growth. We must ++ * increase the space allocated for compressor ++ * output in ppp_send_frame() accordingly. Note ++ * that from a purist's view, it may be more correct ++ * to require multilink and fragment large packets, ++ * but that seems inefficient compared to this ++ * little trick. ++ */ ++ ppp->comp_pad = MPPE_PAD; ++ else ++ ppp->comp_pad = 0; + + } else { + ppp_recv_lock(ppp); +@@ -2229,6 +2263,7 @@ + + ppp->file.index = unit; + ppp->mru = PPP_MRU; ++ ppp->mru_alloc = PPP_MRU; + init_ppp_file(&ppp->file, INTERFACE); + ppp->file.hdrlen = PPP_HDRLEN - 2; /* don't count proto bytes */ + for (i = 0; i < NUM_NP; ++i) diff --git a/linux/mppe/mppeinstall.sh b/linux/mppe/mppeinstall.sh index 5a81ffd..6a1f945 100644 --- a/linux/mppe/mppeinstall.sh +++ b/linux/mppe/mppeinstall.sh @@ -1,23 +1,48 @@ #!/bin/sh # -# A quickie script to install MPPE into the 2.2.19+ or 2.4.18 kernel. +# A quickie script to install MPPE into the 2.2.19+ or 2.4.18+ kernel. # Does no error checking!!! # mppe_files="sha1.[ch] arcfour.[ch] ppp_mppe_compress.c" -[ $1 ] || exit 1 -[ -d "$1" ] || exit 1 +if [ -z "$1" -o ! -d "$1" ]; then + echo "Usage: $0 " >&2 + exit 1 +fi -echo -n "Is this a 2.2 kernel or 2.4 kernel: " -read ver +# strip any trailing / +set -- ${1%/} +# strip leading /path/to/linux- +ver=`echo "${1##*/}" | sed -e 's/linux-//'` # -e 's/\/$//' +if ! expr "$ver" : 2.[24] >/dev/null ; then + echo "Unable to determine kernel version ($ver)" >&2 + exit 1 +fi + +# build patch files list +patchdir=`pwd` +patchfiles= +if expr $ver : 2.2 >/dev/null ; then + patchfiles=$patchdir/linux-2.2.*.patch +elif expr $ver : 2.4 >/dev/null ; then + patchfiles=`echo $patchdir/linux-2.4.18-{include,make}.patch` + # need to differentiate a bit + rel=${ver##*.} + if [ $rel -gt 18 ] ; then + patchfiles="$patchfiles $patchdir/linux-2.4.19-pad.patch" + else + patchfiles="$patchfiles $patchdir/linux-2.4.18-pad.patch" + fi +fi + +echo "Detected kernel version $ver" echo "I will now patch the kernel in directory $1" echo -n "Press ret to continue, CTRL-C to exit: " read -patchdir=`pwd` pushd "$1" >/dev/null -for patch in $patchdir/linux-$ver.*.patch; do +for patch in $patchfiles; do patch -p1 < $patch done -- 2.39.2