2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* X.25 Packet Layer release 002
|
|
|
|
*
|
|
|
|
* This is ALPHA test software. This code may break your machine,
|
|
|
|
* randomly fail to work with new releases, misbehave and/or generally
|
2007-02-09 07:25:27 -07:00
|
|
|
* screw up. It might even work.
|
2005-04-16 16:20:36 -06: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.
|
|
|
|
* X.25 002 Jonathan Naylor Centralised disconnection code.
|
|
|
|
* New timer architecture.
|
2007-02-09 07:25:27 -07:00
|
|
|
* 2000-03-20 Daniela Squassoni Disabling/enabling of facilities
|
2005-04-16 16:20:36 -06:00
|
|
|
* negotiation.
|
|
|
|
* 2000-11-10 Henner Eisen Check and reset for out-of-sequence
|
|
|
|
* i-frames.
|
|
|
|
*/
|
|
|
|
|
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 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <net/sock.h>
|
2005-08-09 21:08:28 -06:00
|
|
|
#include <net/tcp_states.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <net/x25.h>
|
|
|
|
|
|
|
|
static int x25_queue_rx_frame(struct sock *sk, struct sk_buff *skb, int more)
|
|
|
|
{
|
|
|
|
struct sk_buff *skbo, *skbn = skb;
|
|
|
|
struct x25_sock *x25 = x25_sk(sk);
|
|
|
|
|
|
|
|
if (more) {
|
|
|
|
x25->fraglen += skb->len;
|
|
|
|
skb_queue_tail(&x25->fragment_queue, skb);
|
|
|
|
skb_set_owner_r(skb, sk);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!more && x25->fraglen > 0) { /* End of fragment */
|
|
|
|
int len = x25->fraglen + skb->len;
|
|
|
|
|
|
|
|
if ((skbn = alloc_skb(len, GFP_ATOMIC)) == NULL){
|
|
|
|
kfree_skb(skb);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_queue_tail(&x25->fragment_queue, skb);
|
|
|
|
|
2007-03-13 10:06:52 -06:00
|
|
|
skb_reset_transport_header(skbn);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
skbo = skb_dequeue(&x25->fragment_queue);
|
2007-03-31 08:55:45 -06:00
|
|
|
skb_copy_from_linear_data(skbo, skb_put(skbn, skbo->len),
|
|
|
|
skbo->len);
|
2005-04-16 16:20:36 -06:00
|
|
|
kfree_skb(skbo);
|
|
|
|
|
|
|
|
while ((skbo =
|
|
|
|
skb_dequeue(&x25->fragment_queue)) != NULL) {
|
|
|
|
skb_pull(skbo, (x25->neighbour->extended) ?
|
|
|
|
X25_EXT_MIN_LEN : X25_STD_MIN_LEN);
|
2007-03-31 08:55:45 -06:00
|
|
|
skb_copy_from_linear_data(skbo,
|
|
|
|
skb_put(skbn, skbo->len),
|
|
|
|
skbo->len);
|
2005-04-16 16:20:36 -06:00
|
|
|
kfree_skb(skbo);
|
|
|
|
}
|
|
|
|
|
2007-02-09 07:25:27 -07:00
|
|
|
x25->fraglen = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
skb_set_owner_r(skbn, sk);
|
|
|
|
skb_queue_tail(&sk->sk_receive_queue, skbn);
|
|
|
|
if (!sock_flag(sk, SOCK_DEAD))
|
|
|
|
sk->sk_data_ready(sk, skbn->len);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* State machine for state 1, Awaiting Call Accepted State.
|
|
|
|
* The handling of the timer(s) is in file x25_timer.c.
|
|
|
|
* Handling of state 0 and connection release is in af_x25.c.
|
|
|
|
*/
|
|
|
|
static int x25_state1_machine(struct sock *sk, struct sk_buff *skb, int frametype)
|
|
|
|
{
|
|
|
|
struct x25_address source_addr, dest_addr;
|
2010-04-07 22:29:25 -06:00
|
|
|
int len;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
switch (frametype) {
|
|
|
|
case X25_CALL_ACCEPTED: {
|
|
|
|
struct x25_sock *x25 = x25_sk(sk);
|
|
|
|
|
|
|
|
x25_stop_timer(sk);
|
|
|
|
x25->condition = 0x00;
|
|
|
|
x25->vs = 0;
|
|
|
|
x25->va = 0;
|
|
|
|
x25->vr = 0;
|
|
|
|
x25->vl = 0;
|
|
|
|
x25->state = X25_STATE_3;
|
|
|
|
sk->sk_state = TCP_ESTABLISHED;
|
|
|
|
/*
|
|
|
|
* Parse the data in the frame.
|
|
|
|
*/
|
|
|
|
skb_pull(skb, X25_STD_MIN_LEN);
|
2010-04-07 22:29:25 -06:00
|
|
|
|
|
|
|
len = x25_parse_address_block(skb, &source_addr,
|
|
|
|
&dest_addr);
|
|
|
|
if (len > 0)
|
|
|
|
skb_pull(skb, len);
|
|
|
|
|
|
|
|
len = x25_parse_facilities(skb, &x25->facilities,
|
[X25]: allow ITU-T DTE facilities for x25
Allows use of the optional user facility to insert ITU-T
(http://www.itu.int/ITU-T/) specified DTE facilities in call set-up x25
packets. This feature is optional; no facilities will be added if the ioctl
is not used, and call setup packet remains the same as before.
If the ioctls provided by the patch are used, then a facility marker will be
added to the x25 packet header so that the called dte address extension
facility can be differentiated from other types of facilities (as described in
the ITU-T X.25 recommendation) that are also allowed in the x25 packet header.
Facility markers are made up of two octets, and may be present in the x25
packet headers of call-request, incoming call, call accepted, clear request,
and clear indication packets. The first of the two octets represents the
facility code field and is set to zero by this patch. The second octet of the
marker represents the facility parameter field and is set to 0x0F because the
marker will be inserted before ITU-T type DTE facilities.
Since according to ITU-T X.25 Recommendation X.25(10/96)- 7.1 "All networks
will support the facility markers with a facility parameter field set to all
ones or to 00001111", therefore this patch should work with all x.25 networks.
While there are many ITU-T DTE facilities, this patch implements only the
called and calling address extension, with placeholders in the
x25_dte_facilities structure for the rest of the facilities.
Testing:
This patch was tested using a cisco xot router connected on its serial ports
to an X.25 network, and on its lan ports to a host running an xotd daemon.
It is also possible to test this patch using an xotd daemon and an x25tap
patch, where the xotd daemons work back-to-back without actually using an x.25
network. See www.fyonne.net for details on how to do this.
Signed-off-by: Shaun Pereira <spereira@tusc.com.au>
Acked-by: Andrew Hendry <ahendry@tusc.com.au>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-03-22 01:01:31 -07:00
|
|
|
&x25->dte_facilities,
|
2010-04-07 22:29:25 -06:00
|
|
|
&x25->vc_facil_mask);
|
|
|
|
if (len > 0)
|
|
|
|
skb_pull(skb, len);
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Copy any Call User Data.
|
|
|
|
*/
|
2009-10-22 23:21:56 -06:00
|
|
|
if (skb->len > 0) {
|
2007-03-27 15:55:52 -06:00
|
|
|
skb_copy_from_linear_data(skb,
|
|
|
|
x25->calluserdata.cuddata,
|
|
|
|
skb->len);
|
2005-04-16 16:20:36 -06:00
|
|
|
x25->calluserdata.cudlength = skb->len;
|
|
|
|
}
|
|
|
|
if (!sock_flag(sk, SOCK_DEAD))
|
|
|
|
sk->sk_state_change(sk);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case X25_CLEAR_REQUEST:
|
|
|
|
x25_write_internal(sk, X25_CLEAR_CONFIRMATION);
|
|
|
|
x25_disconnect(sk, ECONNREFUSED, skb->data[3], skb->data[4]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* State machine for state 2, Awaiting Clear Confirmation State.
|
|
|
|
* The handling of the timer(s) is in file x25_timer.c
|
|
|
|
* Handling of state 0 and connection release is in af_x25.c.
|
|
|
|
*/
|
|
|
|
static int x25_state2_machine(struct sock *sk, struct sk_buff *skb, int frametype)
|
|
|
|
{
|
|
|
|
switch (frametype) {
|
|
|
|
|
|
|
|
case X25_CLEAR_REQUEST:
|
|
|
|
x25_write_internal(sk, X25_CLEAR_CONFIRMATION);
|
|
|
|
x25_disconnect(sk, 0, skb->data[3], skb->data[4]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case X25_CLEAR_CONFIRMATION:
|
|
|
|
x25_disconnect(sk, 0, 0, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* State machine for state 3, Connected State.
|
|
|
|
* The handling of the timer(s) is in file x25_timer.c
|
|
|
|
* Handling of state 0 and connection release is in af_x25.c.
|
|
|
|
*/
|
|
|
|
static int x25_state3_machine(struct sock *sk, struct sk_buff *skb, int frametype, int ns, int nr, int q, int d, int m)
|
|
|
|
{
|
|
|
|
int queued = 0;
|
|
|
|
int modulus;
|
|
|
|
struct x25_sock *x25 = x25_sk(sk);
|
2007-02-09 07:25:27 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
modulus = (x25->neighbour->extended) ? X25_EMODULUS : X25_SMODULUS;
|
|
|
|
|
|
|
|
switch (frametype) {
|
|
|
|
|
|
|
|
case X25_RESET_REQUEST:
|
|
|
|
x25_write_internal(sk, X25_RESET_CONFIRMATION);
|
|
|
|
x25_stop_timer(sk);
|
|
|
|
x25->condition = 0x00;
|
|
|
|
x25->vs = 0;
|
|
|
|
x25->vr = 0;
|
|
|
|
x25->va = 0;
|
|
|
|
x25->vl = 0;
|
|
|
|
x25_requeue_frames(sk);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case X25_CLEAR_REQUEST:
|
|
|
|
x25_write_internal(sk, X25_CLEAR_CONFIRMATION);
|
|
|
|
x25_disconnect(sk, 0, skb->data[3], skb->data[4]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case X25_RR:
|
|
|
|
case X25_RNR:
|
|
|
|
if (!x25_validate_nr(sk, nr)) {
|
|
|
|
x25_clear_queues(sk);
|
|
|
|
x25_write_internal(sk, X25_RESET_REQUEST);
|
|
|
|
x25_start_t22timer(sk);
|
|
|
|
x25->condition = 0x00;
|
|
|
|
x25->vs = 0;
|
|
|
|
x25->vr = 0;
|
|
|
|
x25->va = 0;
|
|
|
|
x25->vl = 0;
|
|
|
|
x25->state = X25_STATE_4;
|
|
|
|
} else {
|
|
|
|
x25_frames_acked(sk, nr);
|
|
|
|
if (frametype == X25_RNR) {
|
|
|
|
x25->condition |= X25_COND_PEER_RX_BUSY;
|
|
|
|
} else {
|
|
|
|
x25->condition &= ~X25_COND_PEER_RX_BUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case X25_DATA: /* XXX */
|
|
|
|
x25->condition &= ~X25_COND_PEER_RX_BUSY;
|
|
|
|
if ((ns != x25->vr) || !x25_validate_nr(sk, nr)) {
|
|
|
|
x25_clear_queues(sk);
|
|
|
|
x25_write_internal(sk, X25_RESET_REQUEST);
|
|
|
|
x25_start_t22timer(sk);
|
|
|
|
x25->condition = 0x00;
|
|
|
|
x25->vs = 0;
|
|
|
|
x25->vr = 0;
|
|
|
|
x25->va = 0;
|
|
|
|
x25->vl = 0;
|
|
|
|
x25->state = X25_STATE_4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
x25_frames_acked(sk, nr);
|
|
|
|
if (ns == x25->vr) {
|
|
|
|
if (x25_queue_rx_frame(sk, skb, m) == 0) {
|
|
|
|
x25->vr = (x25->vr + 1) % modulus;
|
|
|
|
queued = 1;
|
|
|
|
} else {
|
|
|
|
/* Should never happen */
|
|
|
|
x25_clear_queues(sk);
|
|
|
|
x25_write_internal(sk, X25_RESET_REQUEST);
|
|
|
|
x25_start_t22timer(sk);
|
|
|
|
x25->condition = 0x00;
|
|
|
|
x25->vs = 0;
|
|
|
|
x25->vr = 0;
|
|
|
|
x25->va = 0;
|
|
|
|
x25->vl = 0;
|
|
|
|
x25->state = X25_STATE_4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (atomic_read(&sk->sk_rmem_alloc) >
|
2008-01-13 23:27:52 -07:00
|
|
|
(sk->sk_rcvbuf >> 1))
|
2005-04-16 16:20:36 -06:00
|
|
|
x25->condition |= X25_COND_OWN_RX_BUSY;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the window is full Ack it immediately, else
|
|
|
|
* start the holdback timer.
|
|
|
|
*/
|
|
|
|
if (((x25->vl + x25->facilities.winsize_in) % modulus) == x25->vr) {
|
|
|
|
x25->condition &= ~X25_COND_ACK_PENDING;
|
|
|
|
x25_stop_timer(sk);
|
|
|
|
x25_enquiry_response(sk);
|
|
|
|
} else {
|
|
|
|
x25->condition |= X25_COND_ACK_PENDING;
|
|
|
|
x25_start_t2timer(sk);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case X25_INTERRUPT_CONFIRMATION:
|
2010-05-16 17:00:02 -06:00
|
|
|
clear_bit(X25_INTERRUPT_FLAG, &x25->flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case X25_INTERRUPT:
|
|
|
|
if (sock_flag(sk, SOCK_URGINLINE))
|
|
|
|
queued = !sock_queue_rcv_skb(sk, skb);
|
|
|
|
else {
|
|
|
|
skb_set_owner_r(skb, sk);
|
|
|
|
skb_queue_tail(&x25->interrupt_in_queue, skb);
|
|
|
|
queued = 1;
|
|
|
|
}
|
|
|
|
sk_send_sigurg(sk);
|
|
|
|
x25_write_internal(sk, X25_INTERRUPT_CONFIRMATION);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printk(KERN_WARNING "x25: unknown %02X in state 3\n", frametype);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return queued;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* State machine for state 4, Awaiting Reset Confirmation State.
|
|
|
|
* The handling of the timer(s) is in file x25_timer.c
|
|
|
|
* Handling of state 0 and connection release is in af_x25.c.
|
|
|
|
*/
|
|
|
|
static int x25_state4_machine(struct sock *sk, struct sk_buff *skb, int frametype)
|
|
|
|
{
|
|
|
|
switch (frametype) {
|
|
|
|
|
|
|
|
case X25_RESET_REQUEST:
|
|
|
|
x25_write_internal(sk, X25_RESET_CONFIRMATION);
|
|
|
|
case X25_RESET_CONFIRMATION: {
|
|
|
|
struct x25_sock *x25 = x25_sk(sk);
|
|
|
|
|
|
|
|
x25_stop_timer(sk);
|
|
|
|
x25->condition = 0x00;
|
|
|
|
x25->va = 0;
|
|
|
|
x25->vr = 0;
|
|
|
|
x25->vs = 0;
|
|
|
|
x25->vl = 0;
|
|
|
|
x25->state = X25_STATE_3;
|
|
|
|
x25_requeue_frames(sk);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case X25_CLEAR_REQUEST:
|
|
|
|
x25_write_internal(sk, X25_CLEAR_CONFIRMATION);
|
|
|
|
x25_disconnect(sk, 0, skb->data[3], skb->data[4]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Higher level upcall for a LAPB frame */
|
|
|
|
int x25_process_rx_frame(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct x25_sock *x25 = x25_sk(sk);
|
|
|
|
int queued = 0, frametype, ns, nr, q, d, m;
|
|
|
|
|
|
|
|
if (x25->state == X25_STATE_0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
frametype = x25_decode(sk, skb, &ns, &nr, &q, &d, &m);
|
|
|
|
|
|
|
|
switch (x25->state) {
|
|
|
|
case X25_STATE_1:
|
|
|
|
queued = x25_state1_machine(sk, skb, frametype);
|
|
|
|
break;
|
|
|
|
case X25_STATE_2:
|
|
|
|
queued = x25_state2_machine(sk, skb, frametype);
|
|
|
|
break;
|
|
|
|
case X25_STATE_3:
|
|
|
|
queued = x25_state3_machine(sk, skb, frametype, ns, nr, q, d, m);
|
|
|
|
break;
|
|
|
|
case X25_STATE_4:
|
|
|
|
queued = x25_state4_machine(sk, skb, frametype);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
x25_kick(sk);
|
|
|
|
|
|
|
|
return queued;
|
|
|
|
}
|
|
|
|
|
|
|
|
int x25_backlog_rcv(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
int queued = x25_process_rx_frame(sk, skb);
|
|
|
|
|
|
|
|
if (!queued)
|
|
|
|
kfree_skb(skb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|