]> git.ozlabs.org Git - ppp.git/blob - linux/mppe/linux-2.4.19-pad.patch
modify ppp_generic patch to avoid an if() test and extra additions on
[ppp.git] / linux / mppe / linux-2.4.19-pad.patch
1 --- linux-2.4.19/drivers/net/ppp_generic.c.orig Mon May 12 01:36:31 2003
2 +++ linux-2.4.19/drivers/net/ppp_generic.c      Mon May 12 03:09:13 2003
3 @@ -99,6 +99,7 @@
4         spinlock_t      rlock;          /* lock for receive side 58 */
5         spinlock_t      wlock;          /* lock for transmit side 5c */
6         int             mru;            /* max receive unit 60 */
7 +       int             mru_alloc;      /* MAX(1500,MRU) for dev_alloc_skb() */
8         unsigned int    flags;          /* control bits 64 */
9         unsigned int    xstate;         /* transmit state bits 68 */
10         unsigned int    rstate;         /* receive state bits 6c */
11 @@ -126,6 +127,7 @@
12         struct sock_fprog pass_filter;  /* filter for packets to pass */
13         struct sock_fprog active_filter;/* filter for pkts to reset idle */
14  #endif /* CONFIG_PPP_FILTER */
15 +       int             comp_pad;       /* padding for compressor (MPPE) */
16  };
17  
18  /*
19 @@ -531,6 +533,10 @@
20                 if (get_user(val, (int *) arg))
21                         break;
22                 ppp->mru = val;
23 +               if (ppp->mru > ppp->mru_alloc)
24 +                   ppp->mru_alloc = ppp->mru;
25 +               else if (ppp->mru < PPP_MRU)
26 +                   ppp->mru_alloc = PPP_MRU;   /* shrink to minimum */
27                 err = 0;
28                 break;
29  
30 @@ -1006,8 +1012,8 @@
31         /* try to do packet compression */
32         if ((ppp->xstate & SC_COMP_RUN) && ppp->xc_state != 0
33             && proto != PPP_LCP && proto != PPP_CCP) {
34 -               new_skb = alloc_skb(ppp->dev->mtu + ppp->dev->hard_header_len,
35 -                                   GFP_ATOMIC);
36 +               new_skb = alloc_skb(ppp->dev->mtu + ppp->dev->hard_header_len
37 +                                   + ppp->comp_pad, GFP_ATOMIC);
38                 if (new_skb == 0) {
39                         printk(KERN_ERR "PPP: no memory (comp pkt)\n");
40                         goto drop;
41 @@ -1019,15 +1025,28 @@
42                 /* compressor still expects A/C bytes in hdr */
43                 len = ppp->xcomp->compress(ppp->xc_state, skb->data - 2,
44                                            new_skb->data, skb->len + 2,
45 -                                          ppp->dev->mtu + PPP_HDRLEN);
46 +                                          ppp->dev->mtu + ppp->comp_pad
47 +                                          + PPP_HDRLEN);
48                 if (len > 0 && (ppp->flags & SC_CCP_UP)) {
49                         kfree_skb(skb);
50                         skb = new_skb;
51                         skb_put(skb, len);
52                         skb_pull(skb, 2);       /* pull off A/C bytes */
53 -               } else {
54 +               } else if (len == 0) {
55                         /* didn't compress, or CCP not up yet */
56                         kfree_skb(new_skb);
57 +               } else {
58 +                       /*
59 +                        * (len < 0)
60 +                        * MPPE requires that we do not send unencrypted
61 +                        * frames.  The compressor will return -1 if we
62 +                        * should drop the frame.  We cannot simply test
63 +                        * the compress_proto because MPPE and MPPC share
64 +                        * the same number.
65 +                        */
66 +                       printk(KERN_ERR "ppp: compressor dropped pkt\n");
67 +                       kfree_skb(new_skb);
68 +                       goto drop;
69                 }
70         }
71  
72 @@ -1515,14 +1534,15 @@
73         int len;
74  
75         if (proto == PPP_COMP) {
76 -               ns = dev_alloc_skb(ppp->mru + PPP_HDRLEN);
77 +               ns = dev_alloc_skb(ppp->mru_alloc + PPP_HDRLEN);
78                 if (ns == 0) {
79                         printk(KERN_ERR "ppp_decompress_frame: no memory\n");
80                         goto err;
81                 }
82                 /* the decompressor still expects the A/C bytes in the hdr */
83                 len = ppp->rcomp->decompress(ppp->rc_state, skb->data - 2,
84 -                               skb->len + 2, ns->data, ppp->mru + PPP_HDRLEN);
85 +                               skb->len + 2, ns->data,
86 +                               ppp->mru_alloc + PPP_HDRLEN);
87                 if (len < 0) {
88                         /* Pass the compressed frame to pppd as an
89                            error indication. */
90 @@ -1949,6 +1969,20 @@
91                         ppp_xmit_unlock(ppp);
92                         err = 0;
93                 }
94 +               if (ccp_option[0] == CI_MPPE)
95 +                       /*
96 +                        * pppd (userland) has reduced the MTU by MPPE_PAD,
97 +                        * to accomodate "compressor" growth.  We must
98 +                        * increase the space allocated for compressor
99 +                        * output in ppp_send_frame() accordingly.  Note
100 +                        * that from a purist's view, it may be more correct
101 +                        * to require multilink and fragment large packets,
102 +                        * but that seems inefficient compared to this
103 +                        * little trick.
104 +                        */
105 +                       ppp->comp_pad = MPPE_PAD;
106 +               else
107 +                       ppp->comp_pad = 0;
108  
109         } else {
110                 ppp_recv_lock(ppp);
111 @@ -2229,6 +2263,7 @@
112  
113         ppp->file.index = unit;
114         ppp->mru = PPP_MRU;
115 +       ppp->mru_alloc = PPP_MRU;
116         init_ppp_file(&ppp->file, INTERFACE);
117         ppp->file.hdrlen = PPP_HDRLEN - 2;      /* don't count proto bytes */
118         for (i = 0; i < NUM_NP; ++i)