~ [ 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 unix-v6-master)


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

~ [ 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