2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* X.25 Packet Layer release 002
|
|
|
|
*
|
2007-02-09 22:25:27 +08:00
|
|
|
* This is ALPHA test software. This code may break your machine, randomly fail to work with new
|
|
|
|
* releases, misbehave and/or generally screw up. It might even work.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This code REQUIRES 2.1.15 or higher
|
|
|
|
*
|
|
|
|
* This module:
|
|
|
|
* This module is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* History
|
|
|
|
* X.25 001 Jonathan Naylor Started coding.
|
|
|
|
* 2000-09-04 Henner Eisen Prevent freeing a dangling skb.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <net/sock.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <net/x25.h>
|
2010-04-23 07:12:36 +08:00
|
|
|
#include <net/x25device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int x25_receive_data(struct sk_buff *skb, struct x25_neigh *nb)
|
|
|
|
{
|
|
|
|
struct sock *sk;
|
|
|
|
unsigned short frametype;
|
|
|
|
unsigned int lci;
|
|
|
|
|
2011-10-15 02:45:04 +08:00
|
|
|
if (!pskb_may_pull(skb, X25_STD_MIN_LEN))
|
|
|
|
return 0;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
frametype = skb->data[2];
|
2007-02-09 22:25:27 +08:00
|
|
|
lci = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LCI of zero is always for us, and its always a link control
|
|
|
|
* frame.
|
|
|
|
*/
|
|
|
|
if (lci == 0) {
|
|
|
|
x25_link_control(skb, nb, frametype);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find an existing socket.
|
|
|
|
*/
|
|
|
|
if ((sk = x25_find_socket(lci, nb)) != NULL) {
|
|
|
|
int queued = 1;
|
|
|
|
|
2007-03-14 00:06:52 +08:00
|
|
|
skb_reset_transport_header(skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
bh_lock_sock(sk);
|
|
|
|
if (!sock_owned_by_user(sk)) {
|
|
|
|
queued = x25_process_rx_frame(sk, skb);
|
|
|
|
} else {
|
2012-04-23 07:34:26 +08:00
|
|
|
queued = !sk_add_backlog(sk, skb, sk->sk_rcvbuf);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
bh_unlock_sock(sk);
|
2007-01-16 11:29:31 +08:00
|
|
|
sock_put(sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
return queued;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is is a Call Request ? if so process it.
|
|
|
|
*/
|
|
|
|
if (frametype == X25_CALL_REQUEST)
|
|
|
|
return x25_rx_call_request(skb, nb, lci);
|
|
|
|
|
|
|
|
/*
|
2007-02-09 05:34:02 +08:00
|
|
|
* Its not a Call Request, nor is it a control frame.
|
|
|
|
* Can we forward it?
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2007-02-09 05:34:02 +08:00
|
|
|
|
|
|
|
if (x25_forward_data(lci, nb, skb)) {
|
|
|
|
if (frametype == X25_CLEAR_CONFIRMATION) {
|
|
|
|
x25_clear_forward_by_lci(lci);
|
|
|
|
}
|
|
|
|
kfree_skb(skb);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
x25_transmit_clear_request(nb, lci, 0x0D);
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (frametype != X25_CLEAR_CONFIRMATION)
|
|
|
|
printk(KERN_DEBUG "x25_receive_data(): unknown frame type %2x\n",frametype);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int x25_lapb_receive_frame(struct sk_buff *skb, struct net_device *dev,
|
2005-08-10 10:34:12 +08:00
|
|
|
struct packet_type *ptype, struct net_device *orig_dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *nskb;
|
|
|
|
struct x25_neigh *nb;
|
|
|
|
|
2008-07-20 13:34:43 +08:00
|
|
|
if (!net_eq(dev_net(dev), &init_net))
|
2007-09-18 02:53:39 +08:00
|
|
|
goto drop;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
nskb = skb_copy(skb, GFP_ATOMIC);
|
|
|
|
if (!nskb)
|
|
|
|
goto drop;
|
|
|
|
kfree_skb(skb);
|
|
|
|
skb = nskb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Packet received from unrecognised device, throw it away.
|
|
|
|
*/
|
|
|
|
nb = x25_get_neigh(dev);
|
|
|
|
if (!nb) {
|
|
|
|
printk(KERN_DEBUG "X.25: unknown neighbour - %s\n", dev->name);
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
2011-10-15 02:45:04 +08:00
|
|
|
if (!pskb_may_pull(skb, 1))
|
|
|
|
return 0;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (skb->data[0]) {
|
2010-04-23 07:12:36 +08:00
|
|
|
|
|
|
|
case X25_IFACE_DATA:
|
|
|
|
skb_pull(skb, 1);
|
|
|
|
if (x25_receive_data(skb, nb)) {
|
|
|
|
x25_neigh_put(nb);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case X25_IFACE_CONNECT:
|
|
|
|
x25_link_established(nb);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case X25_IFACE_DISCONNECT:
|
|
|
|
x25_link_terminated(nb);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
x25_neigh_put(nb);
|
|
|
|
drop:
|
|
|
|
kfree_skb(skb);
|
|
|
|
out:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void x25_establish_link(struct x25_neigh *nb)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
unsigned char *ptr;
|
|
|
|
|
|
|
|
switch (nb->dev->type) {
|
2011-07-01 17:43:13 +08:00
|
|
|
case ARPHRD_X25:
|
|
|
|
if ((skb = alloc_skb(1, GFP_ATOMIC)) == NULL) {
|
|
|
|
printk(KERN_ERR "x25_dev: out of memory\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ptr = skb_put(skb, 1);
|
|
|
|
*ptr = X25_IFACE_CONNECT;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-12-12 10:58:23 +08:00
|
|
|
#if IS_ENABLED(CONFIG_LLC)
|
2011-07-01 17:43:13 +08:00
|
|
|
case ARPHRD_ETHER:
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2011-07-01 17:43:13 +08:00
|
|
|
default:
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
skb->protocol = htons(ETH_P_X25);
|
|
|
|
skb->dev = nb->dev;
|
|
|
|
|
|
|
|
dev_queue_xmit(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void x25_terminate_link(struct x25_neigh *nb)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
unsigned char *ptr;
|
|
|
|
|
2011-12-12 10:58:23 +08:00
|
|
|
#if IS_ENABLED(CONFIG_LLC)
|
2005-04-17 06:20:36 +08:00
|
|
|
if (nb->dev->type == ARPHRD_ETHER)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
if (nb->dev->type != ARPHRD_X25)
|
|
|
|
return;
|
|
|
|
|
|
|
|
skb = alloc_skb(1, GFP_ATOMIC);
|
|
|
|
if (!skb) {
|
|
|
|
printk(KERN_ERR "x25_dev: out of memory\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = skb_put(skb, 1);
|
2010-04-23 07:12:36 +08:00
|
|
|
*ptr = X25_IFACE_DISCONNECT;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
skb->protocol = htons(ETH_P_X25);
|
|
|
|
skb->dev = nb->dev;
|
|
|
|
dev_queue_xmit(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void x25_send_frame(struct sk_buff *skb, struct x25_neigh *nb)
|
|
|
|
{
|
|
|
|
unsigned char *dptr;
|
|
|
|
|
2007-04-11 11:45:18 +08:00
|
|
|
skb_reset_network_header(skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (nb->dev->type) {
|
2011-07-01 17:43:13 +08:00
|
|
|
case ARPHRD_X25:
|
|
|
|
dptr = skb_push(skb, 1);
|
|
|
|
*dptr = X25_IFACE_DATA;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-12-12 10:58:23 +08:00
|
|
|
#if IS_ENABLED(CONFIG_LLC)
|
2011-07-01 17:43:13 +08:00
|
|
|
case ARPHRD_ETHER:
|
|
|
|
kfree_skb(skb);
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2011-07-01 17:43:13 +08:00
|
|
|
default:
|
|
|
|
kfree_skb(skb);
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
skb->protocol = htons(ETH_P_X25);
|
|
|
|
skb->dev = nb->dev;
|
|
|
|
|
|
|
|
dev_queue_xmit(skb);
|
|
|
|
}
|