~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/atm/pppoatm.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /net/atm/pppoatm.c (Version linux-6.12-rc7) and /net/atm/pppoatm.c (Version linux-4.4.302)


  1 // SPDX-License-Identifier: GPL-2.0-or-later   << 
  2 /* net/atm/pppoatm.c - RFC2364 PPP over ATM/AA      1 /* net/atm/pppoatm.c - RFC2364 PPP over ATM/AAL5 */
  3                                                     2 
  4 /* Copyright 1999-2000 by Mitchell Blank Jr */      3 /* Copyright 1999-2000 by Mitchell Blank Jr */
  5 /* Based on clip.c; 1995-1999 by Werner Almesb      4 /* Based on clip.c; 1995-1999 by Werner Almesberger, EPFL LRC/ICA */
  6 /* And on ppp_async.c; Copyright 1999 Paul Mac      5 /* And on ppp_async.c; Copyright 1999 Paul Mackerras */
  7 /* And help from Jens Axboe */                      6 /* And help from Jens Axboe */
  8                                                     7 
  9 /*                                                  8 /*
                                                   >>   9  *  This program is free software; you can redistribute it and/or
                                                   >>  10  *  modify it under the terms of the GNU General Public License
                                                   >>  11  *  as published by the Free Software Foundation; either version
                                                   >>  12  *  2 of the License, or (at your option) any later version.
 10  *                                                 13  *
 11  * This driver provides the encapsulation and      14  * This driver provides the encapsulation and framing for sending
 12  * and receiving PPP frames in ATM AAL5 PDUs.      15  * and receiving PPP frames in ATM AAL5 PDUs.
 13  */                                                16  */
 14                                                    17 
 15 /*                                                 18 /*
 16  * One shortcoming of this driver is that it d     19  * One shortcoming of this driver is that it does not comply with
 17  * section 8 of RFC2364 - we are supposed to d     20  * section 8 of RFC2364 - we are supposed to detect a change
 18  * in encapsulation and immediately abort the      21  * in encapsulation and immediately abort the connection (in order
 19  * to avoid a black-hole being created if our      22  * to avoid a black-hole being created if our peer loses state
 20  * and changes encapsulation unilaterally.  Ho     23  * and changes encapsulation unilaterally.  However, since the
 21  * ppp_generic layer actually does the decapsu     24  * ppp_generic layer actually does the decapsulation, we need
 22  * a way of notifying it when we _think_ there     25  * a way of notifying it when we _think_ there might be a problem)
 23  * There's two cases:                              26  * There's two cases:
 24  *   1. LLC-encapsulation was missing when it      27  *   1. LLC-encapsulation was missing when it was enabled.  In
 25  *      this case, we should tell the upper la     28  *      this case, we should tell the upper layer "tear down
 26  *      this session if this skb looks ok to y     29  *      this session if this skb looks ok to you"
 27  *   2. LLC-encapsulation was present when it      30  *   2. LLC-encapsulation was present when it was disabled.  Then
 28  *      we need to tell the upper layer "this      31  *      we need to tell the upper layer "this packet may be
 29  *      ok, but if its in error tear down the      32  *      ok, but if its in error tear down the session"
 30  * These hooks are not yet available in ppp_ge     33  * These hooks are not yet available in ppp_generic
 31  */                                                34  */
 32                                                    35 
 33 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt     36 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
 34                                                    37 
 35 #include <linux/module.h>                          38 #include <linux/module.h>
 36 #include <linux/init.h>                            39 #include <linux/init.h>
 37 #include <linux/interrupt.h>                       40 #include <linux/interrupt.h>
 38 #include <linux/skbuff.h>                          41 #include <linux/skbuff.h>
 39 #include <linux/slab.h>                            42 #include <linux/slab.h>
 40 #include <linux/atm.h>                             43 #include <linux/atm.h>
 41 #include <linux/atmdev.h>                          44 #include <linux/atmdev.h>
 42 #include <linux/capability.h>                      45 #include <linux/capability.h>
 43 #include <linux/ppp_defs.h>                        46 #include <linux/ppp_defs.h>
 44 #include <linux/ppp-ioctl.h>                       47 #include <linux/ppp-ioctl.h>
 45 #include <linux/ppp_channel.h>                     48 #include <linux/ppp_channel.h>
 46 #include <linux/atmppp.h>                          49 #include <linux/atmppp.h>
 47                                                    50 
 48 #include "common.h"                                51 #include "common.h"
 49                                                    52 
 50 enum pppoatm_encaps {                              53 enum pppoatm_encaps {
 51         e_autodetect = PPPOATM_ENCAPS_AUTODETE     54         e_autodetect = PPPOATM_ENCAPS_AUTODETECT,
 52         e_vc = PPPOATM_ENCAPS_VC,                  55         e_vc = PPPOATM_ENCAPS_VC,
 53         e_llc = PPPOATM_ENCAPS_LLC,                56         e_llc = PPPOATM_ENCAPS_LLC,
 54 };                                                 57 };
 55                                                    58 
 56 struct pppoatm_vcc {                               59 struct pppoatm_vcc {
 57         struct atm_vcc  *atmvcc;        /* VCC     60         struct atm_vcc  *atmvcc;        /* VCC descriptor */
 58         void (*old_push)(struct atm_vcc *, str     61         void (*old_push)(struct atm_vcc *, struct sk_buff *);
 59         void (*old_pop)(struct atm_vcc *, stru     62         void (*old_pop)(struct atm_vcc *, struct sk_buff *);
 60         void (*old_release_cb)(struct atm_vcc      63         void (*old_release_cb)(struct atm_vcc *);
 61         struct module *old_owner;                  64         struct module *old_owner;
 62                                         /* kee     65                                         /* keep old push/pop for detaching */
 63         enum pppoatm_encaps encaps;                66         enum pppoatm_encaps encaps;
 64         atomic_t inflight;                         67         atomic_t inflight;
 65         unsigned long blocked;                     68         unsigned long blocked;
 66         int flags;                      /* SC_     69         int flags;                      /* SC_COMP_PROT - compress protocol */
 67         struct ppp_channel chan;        /* int     70         struct ppp_channel chan;        /* interface to generic ppp layer */
 68         struct tasklet_struct wakeup_tasklet;      71         struct tasklet_struct wakeup_tasklet;
 69 };                                                 72 };
 70                                                    73 
 71 /*                                                 74 /*
 72  * We want to allow two packets in the queue.      75  * We want to allow two packets in the queue. The one that's currently in
 73  * flight, and *one* queued up ready for the A     76  * flight, and *one* queued up ready for the ATM device to send immediately
 74  * from its TX done IRQ. We want to be able to     77  * from its TX done IRQ. We want to be able to use atomic_inc_not_zero(), so
 75  * inflight == -2 represents an empty queue, -     78  * inflight == -2 represents an empty queue, -1 one packet, and zero means
 76  * there are two packets in the queue.             79  * there are two packets in the queue.
 77  */                                                80  */
 78 #define NONE_INFLIGHT -2                           81 #define NONE_INFLIGHT -2
 79                                                    82 
 80 #define BLOCKED 0                                  83 #define BLOCKED 0
 81                                                    84 
 82 /*                                                 85 /*
 83  * Header used for LLC Encapsulated PPP (4 byt     86  * Header used for LLC Encapsulated PPP (4 bytes) followed by the LCP protocol
 84  * ID (0xC021) used in autodetection               87  * ID (0xC021) used in autodetection
 85  */                                                88  */
 86 static const unsigned char pppllc[6] = { 0xFE,     89 static const unsigned char pppllc[6] = { 0xFE, 0xFE, 0x03, 0xCF, 0xC0, 0x21 };
 87 #define LLC_LEN         (4)                        90 #define LLC_LEN         (4)
 88                                                    91 
 89 static inline struct pppoatm_vcc *atmvcc_to_pv     92 static inline struct pppoatm_vcc *atmvcc_to_pvcc(const struct atm_vcc *atmvcc)
 90 {                                                  93 {
 91         return (struct pppoatm_vcc *) (atmvcc-     94         return (struct pppoatm_vcc *) (atmvcc->user_back);
 92 }                                                  95 }
 93                                                    96 
 94 static inline struct pppoatm_vcc *chan_to_pvcc     97 static inline struct pppoatm_vcc *chan_to_pvcc(const struct ppp_channel *chan)
 95 {                                                  98 {
 96         return (struct pppoatm_vcc *) (chan->p     99         return (struct pppoatm_vcc *) (chan->private);
 97 }                                                 100 }
 98                                                   101 
 99 /*                                                102 /*
100  * We can't do this directly from our _pop han    103  * We can't do this directly from our _pop handler, since the ppp code
101  * doesn't want to be called in interrupt cont    104  * doesn't want to be called in interrupt context, so we do it from
102  * a tasklet                                      105  * a tasklet
103  */                                               106  */
104 static void pppoatm_wakeup_sender(struct taskl !! 107 static void pppoatm_wakeup_sender(unsigned long arg)
105 {                                                 108 {
106         struct pppoatm_vcc *pvcc = from_taskle !! 109         ppp_output_wakeup((struct ppp_channel *) arg);
107                                                << 
108         ppp_output_wakeup(&pvcc->chan);        << 
109 }                                                 110 }
110                                                   111 
111 static void pppoatm_release_cb(struct atm_vcc     112 static void pppoatm_release_cb(struct atm_vcc *atmvcc)
112 {                                                 113 {
113         struct pppoatm_vcc *pvcc = atmvcc_to_p    114         struct pppoatm_vcc *pvcc = atmvcc_to_pvcc(atmvcc);
114                                                   115 
115         /*                                        116         /*
116          * As in pppoatm_pop(), it's safe to c    117          * As in pppoatm_pop(), it's safe to clear the BLOCKED bit here because
117          * the wakeup *can't* race with pppoat    118          * the wakeup *can't* race with pppoatm_send(). They both hold the PPP
118          * channel's ->downl lock. And the pot    119          * channel's ->downl lock. And the potential race with *setting* it,
119          * which leads to the double-check dan    120          * which leads to the double-check dance in pppoatm_may_send(), doesn't
120          * exist here. In the sock_owned_by_us    121          * exist here. In the sock_owned_by_user() case in pppoatm_send(), we
121          * set the BLOCKED bit while the socke    122          * set the BLOCKED bit while the socket is still locked. We know that
122          * ->release_cb() can't be called unti    123          * ->release_cb() can't be called until that's done.
123          */                                       124          */
124         if (test_and_clear_bit(BLOCKED, &pvcc-    125         if (test_and_clear_bit(BLOCKED, &pvcc->blocked))
125                 tasklet_schedule(&pvcc->wakeup    126                 tasklet_schedule(&pvcc->wakeup_tasklet);
126         if (pvcc->old_release_cb)                 127         if (pvcc->old_release_cb)
127                 pvcc->old_release_cb(atmvcc);     128                 pvcc->old_release_cb(atmvcc);
128 }                                                 129 }
129 /*                                                130 /*
130  * This gets called every time the ATM card ha    131  * This gets called every time the ATM card has finished sending our
131  * skb.  The ->old_pop will take care up norma    132  * skb.  The ->old_pop will take care up normal atm flow control,
132  * but we also need to wake up the device if w    133  * but we also need to wake up the device if we blocked it
133  */                                               134  */
134 static void pppoatm_pop(struct atm_vcc *atmvcc    135 static void pppoatm_pop(struct atm_vcc *atmvcc, struct sk_buff *skb)
135 {                                                 136 {
136         struct pppoatm_vcc *pvcc = atmvcc_to_p    137         struct pppoatm_vcc *pvcc = atmvcc_to_pvcc(atmvcc);
137                                                   138 
138         pvcc->old_pop(atmvcc, skb);               139         pvcc->old_pop(atmvcc, skb);
139         atomic_dec(&pvcc->inflight);              140         atomic_dec(&pvcc->inflight);
140                                                   141 
141         /*                                        142         /*
142          * We always used to run the wakeup ta    143          * We always used to run the wakeup tasklet unconditionally here, for
143          * fear of race conditions where we cl    144          * fear of race conditions where we clear the BLOCKED flag just as we
144          * refuse another packet in pppoatm_se    145          * refuse another packet in pppoatm_send(). This was quite inefficient.
145          *                                        146          *
146          * In fact it's OK. The PPP core will     147          * In fact it's OK. The PPP core will only ever call pppoatm_send()
147          * while holding the channel->downl lo    148          * while holding the channel->downl lock. And ppp_output_wakeup() as
148          * called by the tasklet will *also* g    149          * called by the tasklet will *also* grab that lock. So even if another
149          * CPU is in pppoatm_send() right now,    150          * CPU is in pppoatm_send() right now, the tasklet isn't going to race
150          * with it. The wakeup *will* happen a    151          * with it. The wakeup *will* happen after the other CPU is safely out
151          * of pppoatm_send() again.               152          * of pppoatm_send() again.
152          *                                        153          *
153          * So if the CPU in pppoatm_send() has    154          * So if the CPU in pppoatm_send() has already set the BLOCKED bit and
154          * it about to return, that's fine. We    155          * it about to return, that's fine. We trigger a wakeup which will
155          * happen later. And if the CPU in ppp    156          * happen later. And if the CPU in pppoatm_send() *hasn't* set the
156          * BLOCKED bit yet, that's fine too be    157          * BLOCKED bit yet, that's fine too because of the double check in
157          * pppoatm_may_send() which is comment    158          * pppoatm_may_send() which is commented there.
158          */                                       159          */
159         if (test_and_clear_bit(BLOCKED, &pvcc-    160         if (test_and_clear_bit(BLOCKED, &pvcc->blocked))
160                 tasklet_schedule(&pvcc->wakeup    161                 tasklet_schedule(&pvcc->wakeup_tasklet);
161 }                                                 162 }
162                                                   163 
163 /*                                                164 /*
164  * Unbind from PPP - currently we only do this    165  * Unbind from PPP - currently we only do this when closing the socket,
165  * but we could put this into an ioctl if need    166  * but we could put this into an ioctl if need be
166  */                                               167  */
167 static void pppoatm_unassign_vcc(struct atm_vc    168 static void pppoatm_unassign_vcc(struct atm_vcc *atmvcc)
168 {                                                 169 {
169         struct pppoatm_vcc *pvcc;                 170         struct pppoatm_vcc *pvcc;
170         pvcc = atmvcc_to_pvcc(atmvcc);            171         pvcc = atmvcc_to_pvcc(atmvcc);
171         atmvcc->push = pvcc->old_push;            172         atmvcc->push = pvcc->old_push;
172         atmvcc->pop = pvcc->old_pop;              173         atmvcc->pop = pvcc->old_pop;
173         atmvcc->release_cb = pvcc->old_release    174         atmvcc->release_cb = pvcc->old_release_cb;
174         tasklet_kill(&pvcc->wakeup_tasklet);      175         tasklet_kill(&pvcc->wakeup_tasklet);
175         ppp_unregister_channel(&pvcc->chan);      176         ppp_unregister_channel(&pvcc->chan);
176         atmvcc->user_back = NULL;                 177         atmvcc->user_back = NULL;
177         kfree(pvcc);                              178         kfree(pvcc);
178 }                                                 179 }
179                                                   180 
180 /* Called when an AAL5 PDU comes in */            181 /* Called when an AAL5 PDU comes in */
181 static void pppoatm_push(struct atm_vcc *atmvc    182 static void pppoatm_push(struct atm_vcc *atmvcc, struct sk_buff *skb)
182 {                                                 183 {
183         struct pppoatm_vcc *pvcc = atmvcc_to_p    184         struct pppoatm_vcc *pvcc = atmvcc_to_pvcc(atmvcc);
184         pr_debug("\n");                           185         pr_debug("\n");
185         if (skb == NULL) {                        186         if (skb == NULL) {                      /* VCC was closed */
186                 struct module *module;            187                 struct module *module;
187                                                   188 
188                 pr_debug("removing ATMPPP VCC     189                 pr_debug("removing ATMPPP VCC %p\n", pvcc);
189                 module = pvcc->old_owner;         190                 module = pvcc->old_owner;
190                 pppoatm_unassign_vcc(atmvcc);     191                 pppoatm_unassign_vcc(atmvcc);
191                 atmvcc->push(atmvcc, NULL);       192                 atmvcc->push(atmvcc, NULL);     /* Pass along bad news */
192                 module_put(module);               193                 module_put(module);
193                 return;                           194                 return;
194         }                                         195         }
195         atm_return(atmvcc, skb->truesize);        196         atm_return(atmvcc, skb->truesize);
196         switch (pvcc->encaps) {                   197         switch (pvcc->encaps) {
197         case e_llc:                               198         case e_llc:
198                 if (skb->len < LLC_LEN ||         199                 if (skb->len < LLC_LEN ||
199                     memcmp(skb->data, pppllc,     200                     memcmp(skb->data, pppllc, LLC_LEN))
200                         goto error;               201                         goto error;
201                 skb_pull(skb, LLC_LEN);           202                 skb_pull(skb, LLC_LEN);
202                 break;                            203                 break;
203         case e_autodetect:                        204         case e_autodetect:
204                 if (pvcc->chan.ppp == NULL) {     205                 if (pvcc->chan.ppp == NULL) {   /* Not bound yet! */
205                         kfree_skb(skb);           206                         kfree_skb(skb);
206                         return;                   207                         return;
207                 }                                 208                 }
208                 if (skb->len >= sizeof(pppllc)    209                 if (skb->len >= sizeof(pppllc) &&
209                     !memcmp(skb->data, pppllc,    210                     !memcmp(skb->data, pppllc, sizeof(pppllc))) {
210                         pvcc->encaps = e_llc;     211                         pvcc->encaps = e_llc;
211                         skb_pull(skb, LLC_LEN)    212                         skb_pull(skb, LLC_LEN);
212                         break;                    213                         break;
213                 }                                 214                 }
214                 if (skb->len >= (sizeof(pppllc    215                 if (skb->len >= (sizeof(pppllc) - LLC_LEN) &&
215                     !memcmp(skb->data, &pppllc    216                     !memcmp(skb->data, &pppllc[LLC_LEN],
216                     sizeof(pppllc) - LLC_LEN))    217                     sizeof(pppllc) - LLC_LEN)) {
217                         pvcc->encaps = e_vc;      218                         pvcc->encaps = e_vc;
218                         pvcc->chan.mtu += LLC_    219                         pvcc->chan.mtu += LLC_LEN;
219                         break;                    220                         break;
220                 }                                 221                 }
221                 pr_debug("Couldn't autodetect  !! 222                 pr_debug("Couldn't autodetect yet (skb: %02X %02X %02X %02X %02X %02X)\n",
                                                   >> 223                          skb->data[0], skb->data[1], skb->data[2],
                                                   >> 224                          skb->data[3], skb->data[4], skb->data[5]);
222                 goto error;                       225                 goto error;
223         case e_vc:                                226         case e_vc:
224                 break;                            227                 break;
225         }                                         228         }
226         ppp_input(&pvcc->chan, skb);              229         ppp_input(&pvcc->chan, skb);
227         return;                                   230         return;
228                                                   231 
229 error:                                            232 error:
230         kfree_skb(skb);                           233         kfree_skb(skb);
231         ppp_input_error(&pvcc->chan, 0);          234         ppp_input_error(&pvcc->chan, 0);
232 }                                                 235 }
233                                                   236 
234 static int pppoatm_may_send(struct pppoatm_vcc    237 static int pppoatm_may_send(struct pppoatm_vcc *pvcc, int size)
235 {                                                 238 {
236         /*                                        239         /*
237          * It's not clear that we need to both    240          * It's not clear that we need to bother with using atm_may_send()
238          * to check we don't exceed sk->sk_snd    241          * to check we don't exceed sk->sk_sndbuf. If userspace sets a
239          * value of sk_sndbuf which is lower t    242          * value of sk_sndbuf which is lower than the MTU, we're going to
240          * block for ever. But the code always    243          * block for ever. But the code always did that before we introduced
241          * the packet count limit, so...          244          * the packet count limit, so...
242          */                                       245          */
243         if (atm_may_send(pvcc->atmvcc, size) &    246         if (atm_may_send(pvcc->atmvcc, size) &&
244             atomic_inc_not_zero(&pvcc->infligh !! 247             atomic_inc_not_zero_hint(&pvcc->inflight, NONE_INFLIGHT))
245                 return 1;                         248                 return 1;
246                                                   249 
247         /*                                        250         /*
248          * We use test_and_set_bit() rather th    251          * We use test_and_set_bit() rather than set_bit() here because
249          * we need to ensure there's a memory     252          * we need to ensure there's a memory barrier after it. The bit
250          * *must* be set before we do the atom    253          * *must* be set before we do the atomic_inc() on pvcc->inflight.
251          * There's no smp_mb__after_set_bit(),    254          * There's no smp_mb__after_set_bit(), so it's this or abuse
252          * smp_mb__after_atomic().                255          * smp_mb__after_atomic().
253          */                                       256          */
254         test_and_set_bit(BLOCKED, &pvcc->block    257         test_and_set_bit(BLOCKED, &pvcc->blocked);
255                                                   258 
256         /*                                        259         /*
257          * We may have raced with pppoatm_pop(    260          * We may have raced with pppoatm_pop(). If it ran for the
258          * last packet in the queue, *just* be    261          * last packet in the queue, *just* before we set the BLOCKED
259          * bit, then it might never run again     262          * bit, then it might never run again and the channel could
260          * remain permanently blocked. Cope wi    263          * remain permanently blocked. Cope with that race by checking
261          * *again*. If it did run in that wind    264          * *again*. If it did run in that window, we'll have space on
262          * the queue now and can return succes    265          * the queue now and can return success. It's harmless to leave
263          * the BLOCKED flag set, since it's on    266          * the BLOCKED flag set, since it's only used as a trigger to
264          * run the wakeup tasklet. Another wak    267          * run the wakeup tasklet. Another wakeup will never hurt.
265          * If pppoatm_pop() is running but has    268          * If pppoatm_pop() is running but hasn't got as far as making
266          * space on the queue yet, then it has    269          * space on the queue yet, then it hasn't checked the BLOCKED
267          * flag yet either, so we're safe in t    270          * flag yet either, so we're safe in that case too. It'll issue
268          * an "immediate" wakeup... where "imm    271          * an "immediate" wakeup... where "immediate" actually involves
269          * taking the PPP channel's ->downl lo    272          * taking the PPP channel's ->downl lock, which is held by the
270          * code path that calls pppoatm_send()    273          * code path that calls pppoatm_send(), and is thus going to
271          * wait for us to finish.                 274          * wait for us to finish.
272          */                                       275          */
273         if (atm_may_send(pvcc->atmvcc, size) &    276         if (atm_may_send(pvcc->atmvcc, size) &&
274             atomic_inc_not_zero(&pvcc->infligh    277             atomic_inc_not_zero(&pvcc->inflight))
275                 return 1;                         278                 return 1;
276                                                   279 
277         return 0;                                 280         return 0;
278 }                                                 281 }
279 /*                                                282 /*
280  * Called by the ppp_generic.c to send a packe    283  * Called by the ppp_generic.c to send a packet - returns true if packet
281  * was accepted.  If we return false, then it'    284  * was accepted.  If we return false, then it's our job to call
282  * ppp_output_wakeup(chan) when we're feeling     285  * ppp_output_wakeup(chan) when we're feeling more up to it.
283  * Note that in the ENOMEM case (as opposed to    286  * Note that in the ENOMEM case (as opposed to the !atm_may_send case)
284  * we should really drop the packet, but the g    287  * we should really drop the packet, but the generic layer doesn't
285  * support this yet.  We just return 'DROP_PAC    288  * support this yet.  We just return 'DROP_PACKET' which we actually define
286  * as success, just to be clear what we're rea    289  * as success, just to be clear what we're really doing.
287  */                                               290  */
288 #define DROP_PACKET 1                             291 #define DROP_PACKET 1
289 static int pppoatm_send(struct ppp_channel *ch    292 static int pppoatm_send(struct ppp_channel *chan, struct sk_buff *skb)
290 {                                                 293 {
291         struct pppoatm_vcc *pvcc = chan_to_pvc    294         struct pppoatm_vcc *pvcc = chan_to_pvcc(chan);
292         struct atm_vcc *vcc;                      295         struct atm_vcc *vcc;
293         int ret;                                  296         int ret;
294                                                   297 
295         ATM_SKB(skb)->vcc = pvcc->atmvcc;         298         ATM_SKB(skb)->vcc = pvcc->atmvcc;
296         pr_debug("(skb=0x%p, vcc=0x%p)\n", skb    299         pr_debug("(skb=0x%p, vcc=0x%p)\n", skb, pvcc->atmvcc);
297         if (skb->data[0] == '\0' && (pvcc->fla    300         if (skb->data[0] == '\0' && (pvcc->flags & SC_COMP_PROT))
298                 (void) skb_pull(skb, 1);          301                 (void) skb_pull(skb, 1);
299                                                   302 
300         vcc = ATM_SKB(skb)->vcc;                  303         vcc = ATM_SKB(skb)->vcc;
301         bh_lock_sock(sk_atm(vcc));                304         bh_lock_sock(sk_atm(vcc));
302         if (sock_owned_by_user(sk_atm(vcc))) {    305         if (sock_owned_by_user(sk_atm(vcc))) {
303                 /*                                306                 /*
304                  * Needs to happen (and be flu    307                  * Needs to happen (and be flushed, hence test_and_) before we unlock
305                  * the socket. It needs to be     308                  * the socket. It needs to be seen by the time our ->release_cb gets
306                  * called.                        309                  * called.
307                  */                               310                  */
308                 test_and_set_bit(BLOCKED, &pvc    311                 test_and_set_bit(BLOCKED, &pvcc->blocked);
309                 goto nospace;                     312                 goto nospace;
310         }                                         313         }
311         if (test_bit(ATM_VF_RELEASED, &vcc->fl    314         if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
312             test_bit(ATM_VF_CLOSE, &vcc->flags    315             test_bit(ATM_VF_CLOSE, &vcc->flags) ||
313             !test_bit(ATM_VF_READY, &vcc->flag    316             !test_bit(ATM_VF_READY, &vcc->flags)) {
314                 bh_unlock_sock(sk_atm(vcc));      317                 bh_unlock_sock(sk_atm(vcc));
315                 kfree_skb(skb);                   318                 kfree_skb(skb);
316                 return DROP_PACKET;               319                 return DROP_PACKET;
317         }                                         320         }
318                                                   321 
319         switch (pvcc->encaps) {         /* LLC    322         switch (pvcc->encaps) {         /* LLC encapsulation needed */
320         case e_llc:                               323         case e_llc:
321                 if (skb_headroom(skb) < LLC_LE    324                 if (skb_headroom(skb) < LLC_LEN) {
322                         struct sk_buff *n;        325                         struct sk_buff *n;
323                         n = skb_realloc_headro    326                         n = skb_realloc_headroom(skb, LLC_LEN);
324                         if (n != NULL &&          327                         if (n != NULL &&
325                             !pppoatm_may_send(    328                             !pppoatm_may_send(pvcc, n->truesize)) {
326                                 kfree_skb(n);     329                                 kfree_skb(n);
327                                 goto nospace;     330                                 goto nospace;
328                         }                         331                         }
329                         consume_skb(skb);         332                         consume_skb(skb);
330                         skb = n;                  333                         skb = n;
331                         if (skb == NULL) {        334                         if (skb == NULL) {
332                                 bh_unlock_sock    335                                 bh_unlock_sock(sk_atm(vcc));
333                                 return DROP_PA    336                                 return DROP_PACKET;
334                         }                         337                         }
335                 } else if (!pppoatm_may_send(p    338                 } else if (!pppoatm_may_send(pvcc, skb->truesize))
336                         goto nospace;             339                         goto nospace;
337                 memcpy(skb_push(skb, LLC_LEN),    340                 memcpy(skb_push(skb, LLC_LEN), pppllc, LLC_LEN);
338                 break;                            341                 break;
339         case e_vc:                                342         case e_vc:
340                 if (!pppoatm_may_send(pvcc, sk    343                 if (!pppoatm_may_send(pvcc, skb->truesize))
341                         goto nospace;             344                         goto nospace;
342                 break;                            345                 break;
343         case e_autodetect:                        346         case e_autodetect:
344                 bh_unlock_sock(sk_atm(vcc));      347                 bh_unlock_sock(sk_atm(vcc));
345                 pr_debug("Trying to send witho    348                 pr_debug("Trying to send without setting encaps!\n");
346                 kfree_skb(skb);                   349                 kfree_skb(skb);
347                 return 1;                         350                 return 1;
348         }                                         351         }
349                                                   352 
350         atm_account_tx(vcc, skb);              !! 353         atomic_add(skb->truesize, &sk_atm(ATM_SKB(skb)->vcc)->sk_wmem_alloc);
                                                   >> 354         ATM_SKB(skb)->atm_options = ATM_SKB(skb)->vcc->atm_options;
351         pr_debug("atm_skb(%p)->vcc(%p)->dev(%p    355         pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n",
352                  skb, ATM_SKB(skb)->vcc, ATM_S    356                  skb, ATM_SKB(skb)->vcc, ATM_SKB(skb)->vcc->dev);
353         ret = ATM_SKB(skb)->vcc->send(ATM_SKB(    357         ret = ATM_SKB(skb)->vcc->send(ATM_SKB(skb)->vcc, skb)
354             ? DROP_PACKET : 1;                    358             ? DROP_PACKET : 1;
355         bh_unlock_sock(sk_atm(vcc));              359         bh_unlock_sock(sk_atm(vcc));
356         return ret;                               360         return ret;
357 nospace:                                          361 nospace:
358         bh_unlock_sock(sk_atm(vcc));              362         bh_unlock_sock(sk_atm(vcc));
359         /*                                        363         /*
360          * We don't have space to send this SK    364          * We don't have space to send this SKB now, but we might have
361          * already applied SC_COMP_PROT compre    365          * already applied SC_COMP_PROT compression, so may need to undo
362          */                                       366          */
363         if ((pvcc->flags & SC_COMP_PROT) && sk    367         if ((pvcc->flags & SC_COMP_PROT) && skb_headroom(skb) > 0 &&
364             skb->data[-1] == '\0')                368             skb->data[-1] == '\0')
365                 (void) skb_push(skb, 1);          369                 (void) skb_push(skb, 1);
366         return 0;                                 370         return 0;
367 }                                                 371 }
368                                                   372 
369 /* This handles ioctls sent to the /dev/ppp in    373 /* This handles ioctls sent to the /dev/ppp interface */
370 static int pppoatm_devppp_ioctl(struct ppp_cha    374 static int pppoatm_devppp_ioctl(struct ppp_channel *chan, unsigned int cmd,
371         unsigned long arg)                        375         unsigned long arg)
372 {                                                 376 {
373         switch (cmd) {                            377         switch (cmd) {
374         case PPPIOCGFLAGS:                        378         case PPPIOCGFLAGS:
375                 return put_user(chan_to_pvcc(c    379                 return put_user(chan_to_pvcc(chan)->flags, (int __user *) arg)
376                     ? -EFAULT : 0;                380                     ? -EFAULT : 0;
377         case PPPIOCSFLAGS:                        381         case PPPIOCSFLAGS:
378                 return get_user(chan_to_pvcc(c    382                 return get_user(chan_to_pvcc(chan)->flags, (int __user *) arg)
379                     ? -EFAULT : 0;                383                     ? -EFAULT : 0;
380         }                                         384         }
381         return -ENOTTY;                           385         return -ENOTTY;
382 }                                                 386 }
383                                                   387 
384 static const struct ppp_channel_ops pppoatm_op    388 static const struct ppp_channel_ops pppoatm_ops = {
385         .start_xmit = pppoatm_send,               389         .start_xmit = pppoatm_send,
386         .ioctl = pppoatm_devppp_ioctl,            390         .ioctl = pppoatm_devppp_ioctl,
387 };                                                391 };
388                                                   392 
389 static int pppoatm_assign_vcc(struct atm_vcc *    393 static int pppoatm_assign_vcc(struct atm_vcc *atmvcc, void __user *arg)
390 {                                                 394 {
391         struct atm_backend_ppp be;                395         struct atm_backend_ppp be;
392         struct pppoatm_vcc *pvcc;                 396         struct pppoatm_vcc *pvcc;
393         int err;                                  397         int err;
394                                                !! 398         /*
                                                   >> 399          * Each PPPoATM instance has its own tasklet - this is just a
                                                   >> 400          * prototypical one used to initialize them
                                                   >> 401          */
                                                   >> 402         static const DECLARE_TASKLET(tasklet_proto, pppoatm_wakeup_sender, 0);
395         if (copy_from_user(&be, arg, sizeof be    403         if (copy_from_user(&be, arg, sizeof be))
396                 return -EFAULT;                   404                 return -EFAULT;
397         if (be.encaps != PPPOATM_ENCAPS_AUTODE    405         if (be.encaps != PPPOATM_ENCAPS_AUTODETECT &&
398             be.encaps != PPPOATM_ENCAPS_VC &&     406             be.encaps != PPPOATM_ENCAPS_VC && be.encaps != PPPOATM_ENCAPS_LLC)
399                 return -EINVAL;                   407                 return -EINVAL;
400         pvcc = kzalloc(sizeof(*pvcc), GFP_KERN    408         pvcc = kzalloc(sizeof(*pvcc), GFP_KERNEL);
401         if (pvcc == NULL)                         409         if (pvcc == NULL)
402                 return -ENOMEM;                   410                 return -ENOMEM;
403         pvcc->atmvcc = atmvcc;                    411         pvcc->atmvcc = atmvcc;
404                                                   412 
405         /* Maximum is zero, so that we can use    413         /* Maximum is zero, so that we can use atomic_inc_not_zero() */
406         atomic_set(&pvcc->inflight, NONE_INFLI    414         atomic_set(&pvcc->inflight, NONE_INFLIGHT);
407         pvcc->old_push = atmvcc->push;            415         pvcc->old_push = atmvcc->push;
408         pvcc->old_pop = atmvcc->pop;              416         pvcc->old_pop = atmvcc->pop;
409         pvcc->old_owner = atmvcc->owner;          417         pvcc->old_owner = atmvcc->owner;
410         pvcc->old_release_cb = atmvcc->release    418         pvcc->old_release_cb = atmvcc->release_cb;
411         pvcc->encaps = (enum pppoatm_encaps) b    419         pvcc->encaps = (enum pppoatm_encaps) be.encaps;
412         pvcc->chan.private = pvcc;                420         pvcc->chan.private = pvcc;
413         pvcc->chan.ops = &pppoatm_ops;            421         pvcc->chan.ops = &pppoatm_ops;
414         pvcc->chan.mtu = atmvcc->qos.txtp.max_    422         pvcc->chan.mtu = atmvcc->qos.txtp.max_sdu - PPP_HDRLEN -
415             (be.encaps == e_vc ? 0 : LLC_LEN);    423             (be.encaps == e_vc ? 0 : LLC_LEN);
416         tasklet_setup(&pvcc->wakeup_tasklet, p !! 424         pvcc->wakeup_tasklet = tasklet_proto;
                                                   >> 425         pvcc->wakeup_tasklet.data = (unsigned long) &pvcc->chan;
417         err = ppp_register_channel(&pvcc->chan    426         err = ppp_register_channel(&pvcc->chan);
418         if (err != 0) {                           427         if (err != 0) {
419                 kfree(pvcc);                      428                 kfree(pvcc);
420                 return err;                       429                 return err;
421         }                                         430         }
422         atmvcc->user_back = pvcc;                 431         atmvcc->user_back = pvcc;
423         atmvcc->push = pppoatm_push;              432         atmvcc->push = pppoatm_push;
424         atmvcc->pop = pppoatm_pop;                433         atmvcc->pop = pppoatm_pop;
425         atmvcc->release_cb = pppoatm_release_c    434         atmvcc->release_cb = pppoatm_release_cb;
426         __module_get(THIS_MODULE);                435         __module_get(THIS_MODULE);
427         atmvcc->owner = THIS_MODULE;              436         atmvcc->owner = THIS_MODULE;
428                                                   437 
429         /* re-process everything received betw    438         /* re-process everything received between connection setup and
430            backend setup */                       439            backend setup */
431         vcc_process_recv_queue(atmvcc);           440         vcc_process_recv_queue(atmvcc);
432         return 0;                                 441         return 0;
433 }                                                 442 }
434                                                   443 
435 /*                                                444 /*
436  * This handles ioctls actually performed on o    445  * This handles ioctls actually performed on our vcc - we must return
437  * -ENOIOCTLCMD for any unrecognized ioctl        446  * -ENOIOCTLCMD for any unrecognized ioctl
438  */                                               447  */
439 static int pppoatm_ioctl(struct socket *sock,     448 static int pppoatm_ioctl(struct socket *sock, unsigned int cmd,
440         unsigned long arg)                        449         unsigned long arg)
441 {                                                 450 {
442         struct atm_vcc *atmvcc = ATM_SD(sock);    451         struct atm_vcc *atmvcc = ATM_SD(sock);
443         void __user *argp = (void __user *)arg    452         void __user *argp = (void __user *)arg;
444                                                   453 
445         if (cmd != ATM_SETBACKEND && atmvcc->p    454         if (cmd != ATM_SETBACKEND && atmvcc->push != pppoatm_push)
446                 return -ENOIOCTLCMD;              455                 return -ENOIOCTLCMD;
447         switch (cmd) {                            456         switch (cmd) {
448         case ATM_SETBACKEND: {                    457         case ATM_SETBACKEND: {
449                 atm_backend_t b;                  458                 atm_backend_t b;
450                 if (get_user(b, (atm_backend_t    459                 if (get_user(b, (atm_backend_t __user *) argp))
451                         return -EFAULT;           460                         return -EFAULT;
452                 if (b != ATM_BACKEND_PPP)         461                 if (b != ATM_BACKEND_PPP)
453                         return -ENOIOCTLCMD;      462                         return -ENOIOCTLCMD;
454                 if (!capable(CAP_NET_ADMIN))      463                 if (!capable(CAP_NET_ADMIN))
455                         return -EPERM;            464                         return -EPERM;
456                 if (sock->state != SS_CONNECTE    465                 if (sock->state != SS_CONNECTED)
457                         return -EINVAL;           466                         return -EINVAL;
458                 return pppoatm_assign_vcc(atmv    467                 return pppoatm_assign_vcc(atmvcc, argp);
459                 }                                 468                 }
460         case PPPIOCGCHAN:                         469         case PPPIOCGCHAN:
461                 return put_user(ppp_channel_in    470                 return put_user(ppp_channel_index(&atmvcc_to_pvcc(atmvcc)->
462                     chan), (int __user *) argp    471                     chan), (int __user *) argp) ? -EFAULT : 0;
463         case PPPIOCGUNIT:                         472         case PPPIOCGUNIT:
464                 return put_user(ppp_unit_numbe    473                 return put_user(ppp_unit_number(&atmvcc_to_pvcc(atmvcc)->
465                     chan), (int __user *) argp    474                     chan), (int __user *) argp) ? -EFAULT : 0;
466         }                                         475         }
467         return -ENOIOCTLCMD;                      476         return -ENOIOCTLCMD;
468 }                                                 477 }
469                                                   478 
470 static struct atm_ioctl pppoatm_ioctl_ops = {     479 static struct atm_ioctl pppoatm_ioctl_ops = {
471         .owner  = THIS_MODULE,                    480         .owner  = THIS_MODULE,
472         .ioctl  = pppoatm_ioctl,                  481         .ioctl  = pppoatm_ioctl,
473 };                                                482 };
474                                                   483 
475 static int __init pppoatm_init(void)              484 static int __init pppoatm_init(void)
476 {                                                 485 {
477         register_atm_ioctl(&pppoatm_ioctl_ops)    486         register_atm_ioctl(&pppoatm_ioctl_ops);
478         return 0;                                 487         return 0;
479 }                                                 488 }
480                                                   489 
481 static void __exit pppoatm_exit(void)             490 static void __exit pppoatm_exit(void)
482 {                                                 491 {
483         deregister_atm_ioctl(&pppoatm_ioctl_op    492         deregister_atm_ioctl(&pppoatm_ioctl_ops);
484 }                                                 493 }
485                                                   494 
486 module_init(pppoatm_init);                        495 module_init(pppoatm_init);
487 module_exit(pppoatm_exit);                        496 module_exit(pppoatm_exit);
488                                                   497 
489 MODULE_AUTHOR("Mitchell Blank Jr <mitch@sfgoth    498 MODULE_AUTHOR("Mitchell Blank Jr <mitch@sfgoth.com>");
490 MODULE_DESCRIPTION("RFC2364 PPP over ATM/AAL5"    499 MODULE_DESCRIPTION("RFC2364 PPP over ATM/AAL5");
491 MODULE_LICENSE("GPL");                            500 MODULE_LICENSE("GPL");
492                                                   501 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php