2019-05-20 17:08:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-16 22:20:36 +00: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 14:25:27 +00:00
|
|
|
* screw up. It might even work.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* This code REQUIRES 2.1.15 or higher
|
|
|
|
*
|
|
|
|
* History
|
|
|
|
* X.25 001 Jonathan Naylor Started coding.
|
|
|
|
* X.25 002 Jonathan Naylor New timer architecture.
|
|
|
|
* 2000-09-04 Henner Eisen Prevented x25_output() skb leakage.
|
|
|
|
* 2000-10-27 Henner Eisen MSG_DONTWAIT for fragment allocation.
|
|
|
|
* 2000-11-10 Henner Eisen x25_send_iframe(): re-queued frames
|
|
|
|
* needed cleaned seq-number fields.
|
|
|
|
*/
|
|
|
|
|
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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/socket.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <net/sock.h>
|
|
|
|
#include <net/x25.h>
|
|
|
|
|
|
|
|
static int x25_pacsize_to_bytes(unsigned int pacsize)
|
|
|
|
{
|
|
|
|
int bytes = 1;
|
|
|
|
|
|
|
|
if (!pacsize)
|
|
|
|
return 128;
|
|
|
|
|
|
|
|
while (pacsize-- > 0)
|
|
|
|
bytes *= 2;
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is where all X.25 information frames pass.
|
|
|
|
*
|
|
|
|
* Returns the amount of user data bytes sent on success
|
|
|
|
* or a negative error code on failure.
|
|
|
|
*/
|
|
|
|
int x25_output(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct sk_buff *skbn;
|
|
|
|
unsigned char header[X25_EXT_MIN_LEN];
|
|
|
|
int err, frontlen, len;
|
|
|
|
int sent=0, noblock = X25_SKB_CB(skb)->flags & MSG_DONTWAIT;
|
|
|
|
struct x25_sock *x25 = x25_sk(sk);
|
|
|
|
int header_len = x25->neighbour->extended ? X25_EXT_MIN_LEN :
|
|
|
|
X25_STD_MIN_LEN;
|
|
|
|
int max_len = x25_pacsize_to_bytes(x25->facilities.pacsize_out);
|
|
|
|
|
|
|
|
if (skb->len - header_len > max_len) {
|
|
|
|
/* Save a copy of the Header */
|
2007-03-27 21:55:52 +00:00
|
|
|
skb_copy_from_linear_data(skb, header, header_len);
|
2005-04-16 22:20:36 +00:00
|
|
|
skb_pull(skb, header_len);
|
|
|
|
|
|
|
|
frontlen = skb_headroom(skb);
|
|
|
|
|
|
|
|
while (skb->len > 0) {
|
2011-01-22 22:44:59 +00:00
|
|
|
release_sock(sk);
|
|
|
|
skbn = sock_alloc_send_skb(sk, frontlen + max_len,
|
|
|
|
noblock, &err);
|
|
|
|
lock_sock(sk);
|
|
|
|
if (!skbn) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err == -EWOULDBLOCK && noblock){
|
|
|
|
kfree_skb(skb);
|
|
|
|
return sent;
|
|
|
|
}
|
2023-12-19 14:38:19 +00:00
|
|
|
net_dbg_ratelimited("x25_output: fragment alloc"
|
2005-04-16 22:20:36 +00:00
|
|
|
" failed, err=%d, %d bytes "
|
|
|
|
"sent\n", err, sent);
|
|
|
|
return err;
|
|
|
|
}
|
2007-02-09 14:25:27 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
skb_reserve(skbn, frontlen);
|
|
|
|
|
|
|
|
len = max_len > skb->len ? skb->len : max_len;
|
|
|
|
|
|
|
|
/* Copy the user data */
|
2007-03-27 21:55:52 +00:00
|
|
|
skb_copy_from_linear_data(skb, skb_put(skbn, len), len);
|
2005-04-16 22:20:36 +00:00
|
|
|
skb_pull(skb, len);
|
|
|
|
|
|
|
|
/* Duplicate the Header */
|
|
|
|
skb_push(skbn, header_len);
|
2007-03-31 14:55:19 +00:00
|
|
|
skb_copy_to_linear_data(skbn, header, header_len);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (skb->len > 0) {
|
|
|
|
if (x25->neighbour->extended)
|
|
|
|
skbn->data[3] |= X25_EXT_M_BIT;
|
|
|
|
else
|
|
|
|
skbn->data[2] |= X25_STD_M_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_queue_tail(&sk->sk_write_queue, skbn);
|
|
|
|
sent += len;
|
|
|
|
}
|
2007-02-09 14:25:27 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree_skb(skb);
|
|
|
|
} else {
|
|
|
|
skb_queue_tail(&sk->sk_write_queue, skb);
|
|
|
|
sent = skb->len - header_len;
|
|
|
|
}
|
|
|
|
return sent;
|
|
|
|
}
|
|
|
|
|
2007-02-09 14:25:27 +00:00
|
|
|
/*
|
2005-04-16 22:20:36 +00:00
|
|
|
* This procedure is passed a buffer descriptor for an iframe. It builds
|
|
|
|
* the rest of the control part of the frame and then writes it out.
|
|
|
|
*/
|
|
|
|
static void x25_send_iframe(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct x25_sock *x25 = x25_sk(sk);
|
|
|
|
|
|
|
|
if (!skb)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (x25->neighbour->extended) {
|
|
|
|
skb->data[2] = (x25->vs << 1) & 0xFE;
|
|
|
|
skb->data[3] &= X25_EXT_M_BIT;
|
|
|
|
skb->data[3] |= (x25->vr << 1) & 0xFE;
|
|
|
|
} else {
|
|
|
|
skb->data[2] &= X25_STD_M_BIT;
|
|
|
|
skb->data[2] |= (x25->vs << 1) & 0x0E;
|
|
|
|
skb->data[2] |= (x25->vr << 5) & 0xE0;
|
|
|
|
}
|
|
|
|
|
2007-02-09 14:25:27 +00:00
|
|
|
x25_transmit_link(skb, x25->neighbour);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void x25_kick(struct sock *sk)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb, *skbn;
|
|
|
|
unsigned short start, end;
|
|
|
|
int modulus;
|
|
|
|
struct x25_sock *x25 = x25_sk(sk);
|
|
|
|
|
|
|
|
if (x25->state != X25_STATE_3)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transmit interrupt data.
|
|
|
|
*/
|
2010-05-16 23:00:02 +00:00
|
|
|
if (skb_peek(&x25->interrupt_out_queue) != NULL &&
|
|
|
|
!test_and_set_bit(X25_INTERRUPT_FLAG, &x25->flags)) {
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
skb = skb_dequeue(&x25->interrupt_out_queue);
|
|
|
|
x25_transmit_link(skb, x25->neighbour);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x25->condition & X25_COND_PEER_RX_BUSY)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!skb_peek(&sk->sk_write_queue))
|
|
|
|
return;
|
|
|
|
|
|
|
|
modulus = x25->neighbour->extended ? X25_EMODULUS : X25_SMODULUS;
|
|
|
|
|
|
|
|
start = skb_peek(&x25->ack_queue) ? x25->vs : x25->va;
|
|
|
|
end = (x25->va + x25->facilities.winsize_out) % modulus;
|
|
|
|
|
|
|
|
if (start == end)
|
|
|
|
return;
|
|
|
|
|
|
|
|
x25->vs = start;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transmit data until either we're out of data to send or
|
|
|
|
* the window is full.
|
|
|
|
*/
|
|
|
|
|
|
|
|
skb = skb_dequeue(&sk->sk_write_queue);
|
|
|
|
|
|
|
|
do {
|
|
|
|
if ((skbn = skb_clone(skb, GFP_ATOMIC)) == NULL) {
|
|
|
|
skb_queue_head(&sk->sk_write_queue, skb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_set_owner_w(skbn, sk);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transmit the frame copy.
|
|
|
|
*/
|
|
|
|
x25_send_iframe(sk, skbn);
|
|
|
|
|
|
|
|
x25->vs = (x25->vs + 1) % modulus;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Requeue the original data frame.
|
|
|
|
*/
|
|
|
|
skb_queue_tail(&x25->ack_queue, skb);
|
|
|
|
|
|
|
|
} while (x25->vs != end &&
|
|
|
|
(skb = skb_dequeue(&sk->sk_write_queue)) != NULL);
|
|
|
|
|
|
|
|
x25->vl = x25->vr;
|
|
|
|
x25->condition &= ~X25_COND_ACK_PENDING;
|
|
|
|
|
|
|
|
x25_stop_timer(sk);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following routines are taken from page 170 of the 7th ARRL Computer
|
|
|
|
* Networking Conference paper, as is the whole state machine.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void x25_enquiry_response(struct sock *sk)
|
|
|
|
{
|
|
|
|
struct x25_sock *x25 = x25_sk(sk);
|
|
|
|
|
|
|
|
if (x25->condition & X25_COND_OWN_RX_BUSY)
|
|
|
|
x25_write_internal(sk, X25_RNR);
|
|
|
|
else
|
|
|
|
x25_write_internal(sk, X25_RR);
|
|
|
|
|
|
|
|
x25->vl = x25->vr;
|
|
|
|
x25->condition &= ~X25_COND_ACK_PENDING;
|
|
|
|
|
|
|
|
x25_stop_timer(sk);
|
|
|
|
}
|