2019-05-27 09:55:01 +03:00
// SPDX-License-Identifier: GPL-2.0-or-later
2005-04-17 02:20:36 +04:00
/* net/atm/pppoatm.c - RFC2364 PPP over ATM/AAL5 */
/* Copyright 1999-2000 by Mitchell Blank Jr */
/* Based on clip.c; 1995-1999 by Werner Almesberger, EPFL LRC/ICA */
/* And on ppp_async.c; Copyright 1999 Paul Mackerras */
/* And help from Jens Axboe */
/*
*
* This driver provides the encapsulation and framing for sending
* and receiving PPP frames in ATM AAL5 PDUs .
*/
/*
* One shortcoming of this driver is that it does not comply with
* section 8 of RFC2364 - we are supposed to detect a change
* in encapsulation and immediately abort the connection ( in order
* to avoid a black - hole being created if our peer loses state
* and changes encapsulation unilaterally . However , since the
* ppp_generic layer actually does the decapsulation , we need
* a way of notifying it when we _think_ there might be a problem )
* There ' s two cases :
* 1. LLC - encapsulation was missing when it was enabled . In
* this case , we should tell the upper layer " tear down
* this session if this skb looks ok to you "
* 2. LLC - encapsulation was present when it was disabled . Then
* we need to tell the upper layer " this packet may be
* ok , but if its in error tear down the session "
* These hooks are not yet available in ppp_generic
*/
2010-01-26 14:40:00 +03:00
# define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
2005-04-17 02:20:36 +04:00
# include <linux/module.h>
# include <linux/init.h>
2011-06-06 14:43:46 +04:00
# include <linux/interrupt.h>
2005-04-17 02:20:36 +04:00
# include <linux/skbuff.h>
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
# include <linux/slab.h>
2005-04-17 02:20:36 +04:00
# include <linux/atm.h>
# include <linux/atmdev.h>
2006-01-11 23:17:47 +03:00
# include <linux/capability.h>
2005-04-17 02:20:36 +04:00
# include <linux/ppp_defs.h>
2012-03-04 16:56:55 +04:00
# include <linux/ppp-ioctl.h>
2005-04-17 02:20:36 +04:00
# include <linux/ppp_channel.h>
# include <linux/atmppp.h>
# include "common.h"
enum pppoatm_encaps {
e_autodetect = PPPOATM_ENCAPS_AUTODETECT ,
e_vc = PPPOATM_ENCAPS_VC ,
e_llc = PPPOATM_ENCAPS_LLC ,
} ;
struct pppoatm_vcc {
struct atm_vcc * atmvcc ; /* VCC descriptor */
void ( * old_push ) ( struct atm_vcc * , struct sk_buff * ) ;
void ( * old_pop ) ( struct atm_vcc * , struct sk_buff * ) ;
2012-11-28 04:05:52 +04:00
void ( * old_release_cb ) ( struct atm_vcc * ) ;
2012-11-07 02:16:59 +04:00
struct module * old_owner ;
2005-04-17 02:20:36 +04:00
/* keep old push/pop for detaching */
enum pppoatm_encaps encaps ;
2012-04-08 13:55:43 +04:00
atomic_t inflight ;
unsigned long blocked ;
2005-04-17 02:20:36 +04:00
int flags ; /* SC_COMP_PROT - compress protocol */
struct ppp_channel chan ; /* interface to generic ppp layer */
struct tasklet_struct wakeup_tasklet ;
} ;
2012-04-08 13:55:43 +04:00
/*
* We want to allow two packets in the queue . The one that ' s currently in
* flight , and * one * queued up ready for the ATM device to send immediately
* from its TX done IRQ . We want to be able to use atomic_inc_not_zero ( ) , so
* inflight = = - 2 represents an empty queue , - 1 one packet , and zero means
* there are two packets in the queue .
*/
# define NONE_INFLIGHT -2
# define BLOCKED 0
2005-04-17 02:20:36 +04:00
/*
* Header used for LLC Encapsulated PPP ( 4 bytes ) followed by the LCP protocol
* ID ( 0xC021 ) used in autodetection
*/
static const unsigned char pppllc [ 6 ] = { 0xFE , 0xFE , 0x03 , 0xCF , 0xC0 , 0x21 } ;
# define LLC_LEN (4)
static inline struct pppoatm_vcc * atmvcc_to_pvcc ( const struct atm_vcc * atmvcc )
{
return ( struct pppoatm_vcc * ) ( atmvcc - > user_back ) ;
}
static inline struct pppoatm_vcc * chan_to_pvcc ( const struct ppp_channel * chan )
{
return ( struct pppoatm_vcc * ) ( chan - > private ) ;
}
/*
* We can ' t do this directly from our _pop handler , since the ppp code
* doesn ' t want to be called in interrupt context , so we do it from
* a tasklet
*/
2021-01-27 20:32:56 +03:00
static void pppoatm_wakeup_sender ( struct tasklet_struct * t )
2005-04-17 02:20:36 +04:00
{
2021-01-27 20:32:56 +03:00
struct pppoatm_vcc * pvcc = from_tasklet ( pvcc , t , wakeup_tasklet ) ;
ppp_output_wakeup ( & pvcc - > chan ) ;
2005-04-17 02:20:36 +04:00
}
2012-11-28 04:05:52 +04:00
static void pppoatm_release_cb ( struct atm_vcc * atmvcc )
{
struct pppoatm_vcc * pvcc = atmvcc_to_pvcc ( atmvcc ) ;
2012-11-28 14:15:05 +04:00
/*
* As in pppoatm_pop ( ) , it ' s safe to clear the BLOCKED bit here because
* the wakeup * can ' t * race with pppoatm_send ( ) . They both hold the PPP
* channel ' s - > downl lock . And the potential race with * setting * it ,
* which leads to the double - check dance in pppoatm_may_send ( ) , doesn ' t
* exist here . In the sock_owned_by_user ( ) case in pppoatm_send ( ) , we
* set the BLOCKED bit while the socket is still locked . We know that
* - > release_cb ( ) can ' t be called until that ' s done .
*/
if ( test_and_clear_bit ( BLOCKED , & pvcc - > blocked ) )
tasklet_schedule ( & pvcc - > wakeup_tasklet ) ;
2012-11-28 04:05:52 +04:00
if ( pvcc - > old_release_cb )
pvcc - > old_release_cb ( atmvcc ) ;
}
2005-04-17 02:20:36 +04:00
/*
* This gets called every time the ATM card has finished sending our
* skb . The - > old_pop will take care up normal atm flow control ,
* but we also need to wake up the device if we blocked it
*/
static void pppoatm_pop ( struct atm_vcc * atmvcc , struct sk_buff * skb )
{
struct pppoatm_vcc * pvcc = atmvcc_to_pvcc ( atmvcc ) ;
2012-04-08 13:55:43 +04:00
2005-04-17 02:20:36 +04:00
pvcc - > old_pop ( atmvcc , skb ) ;
2012-04-08 13:55:43 +04:00
atomic_dec ( & pvcc - > inflight ) ;
2005-04-17 02:20:36 +04:00
/*
2012-04-08 13:55:43 +04:00
* We always used to run the wakeup tasklet unconditionally here , for
* fear of race conditions where we clear the BLOCKED flag just as we
* refuse another packet in pppoatm_send ( ) . This was quite inefficient .
*
* In fact it ' s OK . The PPP core will only ever call pppoatm_send ( )
* while holding the channel - > downl lock . And ppp_output_wakeup ( ) as
* called by the tasklet will * also * grab that lock . So even if another
* CPU is in pppoatm_send ( ) right now , the tasklet isn ' t going to race
* with it . The wakeup * will * happen after the other CPU is safely out
* of pppoatm_send ( ) again .
*
* So if the CPU in pppoatm_send ( ) has already set the BLOCKED bit and
* it about to return , that ' s fine . We trigger a wakeup which will
* happen later . And if the CPU in pppoatm_send ( ) * hasn ' t * set the
* BLOCKED bit yet , that ' s fine too because of the double check in
* pppoatm_may_send ( ) which is commented there .
2005-04-17 02:20:36 +04:00
*/
2012-04-08 13:55:43 +04:00
if ( test_and_clear_bit ( BLOCKED , & pvcc - > blocked ) )
tasklet_schedule ( & pvcc - > wakeup_tasklet ) ;
2005-04-17 02:20:36 +04:00
}
/*
* Unbind from PPP - currently we only do this when closing the socket ,
* but we could put this into an ioctl if need be
*/
static void pppoatm_unassign_vcc ( struct atm_vcc * atmvcc )
{
struct pppoatm_vcc * pvcc ;
pvcc = atmvcc_to_pvcc ( atmvcc ) ;
atmvcc - > push = pvcc - > old_push ;
atmvcc - > pop = pvcc - > old_pop ;
2012-11-28 04:05:52 +04:00
atmvcc - > release_cb = pvcc - > old_release_cb ;
2005-04-17 02:20:36 +04:00
tasklet_kill ( & pvcc - > wakeup_tasklet ) ;
ppp_unregister_channel ( & pvcc - > chan ) ;
atmvcc - > user_back = NULL ;
kfree ( pvcc ) ;
}
/* Called when an AAL5 PDU comes in */
static void pppoatm_push ( struct atm_vcc * atmvcc , struct sk_buff * skb )
{
struct pppoatm_vcc * pvcc = atmvcc_to_pvcc ( atmvcc ) ;
2010-01-26 14:40:00 +03:00
pr_debug ( " \n " ) ;
2005-04-17 02:20:36 +04:00
if ( skb = = NULL ) { /* VCC was closed */
2012-11-07 02:16:59 +04:00
struct module * module ;
2007-08-29 02:22:09 +04:00
pr_debug ( " removing ATMPPP VCC %p \n " , pvcc ) ;
2012-11-07 02:16:59 +04:00
module = pvcc - > old_owner ;
2005-04-17 02:20:36 +04:00
pppoatm_unassign_vcc ( atmvcc ) ;
atmvcc - > push ( atmvcc , NULL ) ; /* Pass along bad news */
2012-11-07 02:16:59 +04:00
module_put ( module ) ;
2005-04-17 02:20:36 +04:00
return ;
}
atm_return ( atmvcc , skb - > truesize ) ;
switch ( pvcc - > encaps ) {
case e_llc :
if ( skb - > len < LLC_LEN | |
memcmp ( skb - > data , pppllc , LLC_LEN ) )
goto error ;
skb_pull ( skb , LLC_LEN ) ;
break ;
case e_autodetect :
if ( pvcc - > chan . ppp = = NULL ) { /* Not bound yet! */
kfree_skb ( skb ) ;
return ;
}
if ( skb - > len > = sizeof ( pppllc ) & &
! memcmp ( skb - > data , pppllc , sizeof ( pppllc ) ) ) {
pvcc - > encaps = e_llc ;
skb_pull ( skb , LLC_LEN ) ;
break ;
}
if ( skb - > len > = ( sizeof ( pppllc ) - LLC_LEN ) & &
! memcmp ( skb - > data , & pppllc [ LLC_LEN ] ,
sizeof ( pppllc ) - LLC_LEN ) ) {
pvcc - > encaps = e_vc ;
pvcc - > chan . mtu + = LLC_LEN ;
break ;
}
2019-09-04 20:44:59 +03:00
pr_debug ( " Couldn't autodetect yet (skb: %6ph) \n " , skb - > data ) ;
2005-04-17 02:20:36 +04:00
goto error ;
case e_vc :
break ;
}
ppp_input ( & pvcc - > chan , skb ) ;
return ;
2010-01-26 14:40:12 +03:00
error :
2005-04-17 02:20:36 +04:00
kfree_skb ( skb ) ;
ppp_input_error ( & pvcc - > chan , 0 ) ;
}
2012-11-07 02:17:02 +04:00
static int pppoatm_may_send ( struct pppoatm_vcc * pvcc , int size )
2012-04-08 13:55:43 +04:00
{
/*
* It ' s not clear that we need to bother with using atm_may_send ( )
* to check we don ' t exceed sk - > sk_sndbuf . If userspace sets a
* value of sk_sndbuf which is lower than the MTU , we ' re going to
* block for ever . But the code always did that before we introduced
* the packet count limit , so . . .
*/
if ( atm_may_send ( pvcc - > atmvcc , size ) & &
atomics/treewide: Remove atomic_inc_not_zero_hint()
While documentation suggests atomic_inc_not_zero_hint() will perform better
than atomic_inc_not_zero(), this is unlikely to be the case. No architectures
implement atomic_inc_not_zero_hint() directly, and thus it either falls back to
atomic_inc_not_zero(), or a loop using atomic_cmpxchg().
Whenever the hint does not match the value in memory, the repeated use of
atomic_cmpxchg() will be more expensive than the read that
atomic_inc_not_zero_hint() attempts to avoid. For architectures with LL/SC
atomics, a read cannot be avoided, and it would always be better to use
atomic_inc_not_zero() directly. For other architectures, their own
atomic_inc_not_zero() is likely to be more optimal than an atomic_cmpxchg()
loop regardless.
Generally, atomic_inc_not_zero_hint() is liable to perform worse than
atomic_inc_not_zero(). Further, atomic_inc_not_zero_hint() only exists
for atomic_t, and not atomic64_t or atomic_long_t, and there is only one
user in the kernel tree.
Given all this, let's remove atomic_inc_not_zero_hint(), and migrate the
existing user over to atomic_inc_not_zero().
There should be no functional change as a result of this patch.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Will Deacon <will.deacon@arm.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/lkml/20180621121321.4761-4-mark.rutland@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2018-06-21 15:13:06 +03:00
atomic_inc_not_zero ( & pvcc - > inflight ) )
2012-04-08 13:55:43 +04:00
return 1 ;
/*
* We use test_and_set_bit ( ) rather than set_bit ( ) here because
* we need to ensure there ' s a memory barrier after it . The bit
* * must * be set before we do the atomic_inc ( ) on pvcc - > inflight .
* There ' s no smp_mb__after_set_bit ( ) , so it ' s this or abuse
2014-03-17 21:06:10 +04:00
* smp_mb__after_atomic ( ) .
2012-04-08 13:55:43 +04:00
*/
test_and_set_bit ( BLOCKED , & pvcc - > blocked ) ;
/*
* We may have raced with pppoatm_pop ( ) . If it ran for the
* last packet in the queue , * just * before we set the BLOCKED
* bit , then it might never run again and the channel could
* remain permanently blocked . Cope with that race by checking
* * again * . If it did run in that window , we ' ll have space on
* the queue now and can return success . It ' s harmless to leave
* the BLOCKED flag set , since it ' s only used as a trigger to
* run the wakeup tasklet . Another wakeup will never hurt .
* If pppoatm_pop ( ) is running but hasn ' t got as far as making
* space on the queue yet , then it hasn ' t checked the BLOCKED
* flag yet either , so we ' re safe in that case too . It ' ll issue
* an " immediate " wakeup . . . where " immediate " actually involves
* taking the PPP channel ' s - > downl lock , which is held by the
* code path that calls pppoatm_send ( ) , and is thus going to
* wait for us to finish .
*/
if ( atm_may_send ( pvcc - > atmvcc , size ) & &
atomic_inc_not_zero ( & pvcc - > inflight ) )
return 1 ;
return 0 ;
}
2005-04-17 02:20:36 +04:00
/*
* Called by the ppp_generic . c to send a packet - returns true if packet
* was accepted . If we return false , then it ' s our job to call
* ppp_output_wakeup ( chan ) when we ' re feeling more up to it .
* Note that in the ENOMEM case ( as opposed to the ! atm_may_send case )
* we should really drop the packet , but the generic layer doesn ' t
* support this yet . We just return ' DROP_PACKET ' which we actually define
* as success , just to be clear what we ' re really doing .
*/
# define DROP_PACKET 1
static int pppoatm_send ( struct ppp_channel * chan , struct sk_buff * skb )
{
struct pppoatm_vcc * pvcc = chan_to_pvcc ( chan ) ;
2012-11-07 02:17:00 +04:00
struct atm_vcc * vcc ;
int ret ;
2005-04-17 02:20:36 +04:00
ATM_SKB ( skb ) - > vcc = pvcc - > atmvcc ;
2010-01-26 14:40:00 +03:00
pr_debug ( " (skb=0x%p, vcc=0x%p) \n " , skb , pvcc - > atmvcc ) ;
2005-04-17 02:20:36 +04:00
if ( skb - > data [ 0 ] = = ' \0 ' & & ( pvcc - > flags & SC_COMP_PROT ) )
( void ) skb_pull ( skb , 1 ) ;
2012-11-07 02:17:00 +04:00
vcc = ATM_SKB ( skb ) - > vcc ;
bh_lock_sock ( sk_atm ( vcc ) ) ;
2012-11-28 14:15:05 +04:00
if ( sock_owned_by_user ( sk_atm ( vcc ) ) ) {
/*
* Needs to happen ( and be flushed , hence test_and_ ) before we unlock
* the socket . It needs to be seen by the time our - > release_cb gets
* called .
*/
test_and_set_bit ( BLOCKED , & pvcc - > blocked ) ;
2012-11-07 02:17:00 +04:00
goto nospace ;
2012-11-28 14:15:05 +04:00
}
2012-11-11 02:33:19 +04:00
if ( test_bit ( ATM_VF_RELEASED , & vcc - > flags ) | |
test_bit ( ATM_VF_CLOSE , & vcc - > flags ) | |
! test_bit ( ATM_VF_READY , & vcc - > flags ) ) {
bh_unlock_sock ( sk_atm ( vcc ) ) ;
kfree_skb ( skb ) ;
return DROP_PACKET ;
}
2012-11-07 02:17:00 +04:00
2005-04-17 02:20:36 +04:00
switch ( pvcc - > encaps ) { /* LLC encapsulation needed */
case e_llc :
if ( skb_headroom ( skb ) < LLC_LEN ) {
struct sk_buff * n ;
n = skb_realloc_headroom ( skb , LLC_LEN ) ;
if ( n ! = NULL & &
2012-04-08 13:55:43 +04:00
! pppoatm_may_send ( pvcc , n - > truesize ) ) {
2005-04-17 02:20:36 +04:00
kfree_skb ( n ) ;
goto nospace ;
}
2012-06-04 05:17:19 +04:00
consume_skb ( skb ) ;
2010-01-26 14:40:12 +03:00
skb = n ;
2012-11-07 02:17:00 +04:00
if ( skb = = NULL ) {
bh_unlock_sock ( sk_atm ( vcc ) ) ;
2005-04-17 02:20:36 +04:00
return DROP_PACKET ;
2012-11-07 02:17:00 +04:00
}
2012-04-08 13:55:43 +04:00
} else if ( ! pppoatm_may_send ( pvcc , skb - > truesize ) )
2005-04-17 02:20:36 +04:00
goto nospace ;
memcpy ( skb_push ( skb , LLC_LEN ) , pppllc , LLC_LEN ) ;
break ;
case e_vc :
2012-04-08 13:55:43 +04:00
if ( ! pppoatm_may_send ( pvcc , skb - > truesize ) )
2005-04-17 02:20:36 +04:00
goto nospace ;
break ;
case e_autodetect :
2012-11-07 02:17:00 +04:00
bh_unlock_sock ( sk_atm ( vcc ) ) ;
2007-08-29 02:22:09 +04:00
pr_debug ( " Trying to send without setting encaps! \n " ) ;
2005-04-17 02:20:36 +04:00
kfree_skb ( skb ) ;
return 1 ;
}
atm: Preserve value of skb->truesize when accounting to vcc
ATM accounts for in-flight TX packets in sk_wmem_alloc of the VCC on
which they are to be sent. But it doesn't take ownership of those
packets from the sock (if any) which originally owned them. They should
remain owned by their actual sender until they've left the box.
There's a hack in pskb_expand_head() to avoid adjusting skb->truesize
for certain skbs, precisely to avoid messing up sk_wmem_alloc
accounting. Ideally that hack would cover the ATM use case too, but it
doesn't — skbs which aren't owned by any sock, for example PPP control
frames, still get their truesize adjusted when the low-level ATM driver
adds headroom.
This has always been an issue, it seems. The truesize of a packet
increases, and sk_wmem_alloc on the VCC goes negative. But this wasn't
for normal traffic, only for control frames. So I think we just got away
with it, and we probably needed to send 2GiB of LCP echo frames before
the misaccounting would ever have caused a problem and caused
atm_may_send() to start refusing packets.
Commit 14afee4b609 ("net: convert sock.sk_wmem_alloc from atomic_t to
refcount_t") did exactly what it was intended to do, and turned this
mostly-theoretical problem into a real one, causing PPPoATM to fail
immediately as sk_wmem_alloc underflows and atm_may_send() *immediately*
starts refusing to allow new packets.
The least intrusive solution to this problem is to stash the value of
skb->truesize that was accounted to the VCC, in a new member of the
ATM_SKB(skb) structure. Then in atm_pop_raw() subtract precisely that
value instead of the then-current value of skb->truesize.
Fixes: 158f323b9868 ("net: adjust skb->truesize in pskb_expand_head()")
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Tested-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-06-16 13:55:44 +03:00
atm_account_tx ( vcc , skb ) ;
2010-01-26 14:40:00 +03:00
pr_debug ( " atm_skb(%p)->vcc(%p)->dev(%p) \n " ,
skb , ATM_SKB ( skb ) - > vcc , ATM_SKB ( skb ) - > vcc - > dev ) ;
2012-11-07 02:17:00 +04:00
ret = ATM_SKB ( skb ) - > vcc - > send ( ATM_SKB ( skb ) - > vcc , skb )
2005-04-17 02:20:36 +04:00
? DROP_PACKET : 1 ;
2012-11-07 02:17:00 +04:00
bh_unlock_sock ( sk_atm ( vcc ) ) ;
return ret ;
2010-01-26 14:40:12 +03:00
nospace :
2012-11-07 02:17:00 +04:00
bh_unlock_sock ( sk_atm ( vcc ) ) ;
2005-04-17 02:20:36 +04:00
/*
* We don ' t have space to send this SKB now , but we might have
* already applied SC_COMP_PROT compression , so may need to undo
*/
if ( ( pvcc - > flags & SC_COMP_PROT ) & & skb_headroom ( skb ) > 0 & &
skb - > data [ - 1 ] = = ' \0 ' )
( void ) skb_push ( skb , 1 ) ;
return 0 ;
}
/* This handles ioctls sent to the /dev/ppp interface */
static int pppoatm_devppp_ioctl ( struct ppp_channel * chan , unsigned int cmd ,
unsigned long arg )
{
switch ( cmd ) {
case PPPIOCGFLAGS :
return put_user ( chan_to_pvcc ( chan ) - > flags , ( int __user * ) arg )
? - EFAULT : 0 ;
case PPPIOCSFLAGS :
return get_user ( chan_to_pvcc ( chan ) - > flags , ( int __user * ) arg )
? - EFAULT : 0 ;
}
return - ENOTTY ;
}
2010-08-04 11:34:36 +04:00
static const struct ppp_channel_ops pppoatm_ops = {
2005-04-17 02:20:36 +04:00
. start_xmit = pppoatm_send ,
. ioctl = pppoatm_devppp_ioctl ,
} ;
static int pppoatm_assign_vcc ( struct atm_vcc * atmvcc , void __user * arg )
{
struct atm_backend_ppp be ;
struct pppoatm_vcc * pvcc ;
int err ;
2021-01-27 20:32:55 +03:00
2005-04-17 02:20:36 +04:00
if ( copy_from_user ( & be , arg , sizeof be ) )
return - EFAULT ;
if ( be . encaps ! = PPPOATM_ENCAPS_AUTODETECT & &
be . encaps ! = PPPOATM_ENCAPS_VC & & be . encaps ! = PPPOATM_ENCAPS_LLC )
return - EINVAL ;
2006-07-22 01:51:30 +04:00
pvcc = kzalloc ( sizeof ( * pvcc ) , GFP_KERNEL ) ;
2005-04-17 02:20:36 +04:00
if ( pvcc = = NULL )
return - ENOMEM ;
pvcc - > atmvcc = atmvcc ;
2012-04-08 13:55:43 +04:00
/* Maximum is zero, so that we can use atomic_inc_not_zero() */
atomic_set ( & pvcc - > inflight , NONE_INFLIGHT ) ;
2005-04-17 02:20:36 +04:00
pvcc - > old_push = atmvcc - > push ;
pvcc - > old_pop = atmvcc - > pop ;
2012-11-07 02:16:59 +04:00
pvcc - > old_owner = atmvcc - > owner ;
2012-11-28 04:05:52 +04:00
pvcc - > old_release_cb = atmvcc - > release_cb ;
2005-04-17 02:20:36 +04:00
pvcc - > encaps = ( enum pppoatm_encaps ) be . encaps ;
pvcc - > chan . private = pvcc ;
pvcc - > chan . ops = & pppoatm_ops ;
pvcc - > chan . mtu = atmvcc - > qos . txtp . max_sdu - PPP_HDRLEN -
( be . encaps = = e_vc ? 0 : LLC_LEN ) ;
2021-01-27 20:32:56 +03:00
tasklet_setup ( & pvcc - > wakeup_tasklet , pppoatm_wakeup_sender ) ;
2010-01-26 14:40:12 +03:00
err = ppp_register_channel ( & pvcc - > chan ) ;
if ( err ! = 0 ) {
2005-04-17 02:20:36 +04:00
kfree ( pvcc ) ;
return err ;
}
atmvcc - > user_back = pvcc ;
atmvcc - > push = pppoatm_push ;
atmvcc - > pop = pppoatm_pop ;
2012-11-28 04:05:52 +04:00
atmvcc - > release_cb = pppoatm_release_cb ;
2005-04-17 02:20:36 +04:00
__module_get ( THIS_MODULE ) ;
2012-11-07 02:16:59 +04:00
atmvcc - > owner = THIS_MODULE ;
2011-11-21 14:25:57 +04:00
/* re-process everything received between connection setup and
backend setup */
vcc_process_recv_queue ( atmvcc ) ;
2005-04-17 02:20:36 +04:00
return 0 ;
}
/*
* This handles ioctls actually performed on our vcc - we must return
* - ENOIOCTLCMD for any unrecognized ioctl
*/
static int pppoatm_ioctl ( struct socket * sock , unsigned int cmd ,
unsigned long arg )
{
struct atm_vcc * atmvcc = ATM_SD ( sock ) ;
void __user * argp = ( void __user * ) arg ;
if ( cmd ! = ATM_SETBACKEND & & atmvcc - > push ! = pppoatm_push )
return - ENOIOCTLCMD ;
switch ( cmd ) {
case ATM_SETBACKEND : {
atm_backend_t b ;
if ( get_user ( b , ( atm_backend_t __user * ) argp ) )
return - EFAULT ;
if ( b ! = ATM_BACKEND_PPP )
return - ENOIOCTLCMD ;
if ( ! capable ( CAP_NET_ADMIN ) )
return - EPERM ;
2012-11-07 02:16:58 +04:00
if ( sock - > state ! = SS_CONNECTED )
return - EINVAL ;
2005-04-17 02:20:36 +04:00
return pppoatm_assign_vcc ( atmvcc , argp ) ;
}
case PPPIOCGCHAN :
return put_user ( ppp_channel_index ( & atmvcc_to_pvcc ( atmvcc ) - >
chan ) , ( int __user * ) argp ) ? - EFAULT : 0 ;
case PPPIOCGUNIT :
return put_user ( ppp_unit_number ( & atmvcc_to_pvcc ( atmvcc ) - >
chan ) , ( int __user * ) argp ) ? - EFAULT : 0 ;
}
return - ENOIOCTLCMD ;
}
static struct atm_ioctl pppoatm_ioctl_ops = {
. owner = THIS_MODULE ,
. ioctl = pppoatm_ioctl ,
} ;
static int __init pppoatm_init ( void )
{
register_atm_ioctl ( & pppoatm_ioctl_ops ) ;
return 0 ;
}
static void __exit pppoatm_exit ( void )
{
deregister_atm_ioctl ( & pppoatm_ioctl_ops ) ;
}
module_init ( pppoatm_init ) ;
module_exit ( pppoatm_exit ) ;
MODULE_AUTHOR ( " Mitchell Blank Jr <mitch@sfgoth.com> " ) ;
MODULE_DESCRIPTION ( " RFC2364 PPP over ATM/AAL5 " ) ;
MODULE_LICENSE ( " GPL " ) ;