2007-02-08 22:34:02 +01:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* 03-01-2007 Added forwarding for x.25 Andrew Hendry
|
|
|
|
*/
|
2013-12-06 12:24:33 +01:00
|
|
|
|
|
|
|
#define pr_fmt(fmt) "X25: " fmt
|
|
|
|
|
2007-02-08 22:34:02 +01:00
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/init.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 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2007-02-08 22:34:02 +01:00
|
|
|
#include <net/x25.h>
|
|
|
|
|
2007-12-07 09:50:43 +01:00
|
|
|
LIST_HEAD(x25_forward_list);
|
2007-02-08 22:34:02 +01:00
|
|
|
DEFINE_RWLOCK(x25_forward_list_lock);
|
|
|
|
|
|
|
|
int x25_forward_call(struct x25_address *dest_addr, struct x25_neigh *from,
|
|
|
|
struct sk_buff *skb, int lci)
|
|
|
|
{
|
|
|
|
struct x25_route *rt;
|
|
|
|
struct x25_neigh *neigh_new = NULL;
|
|
|
|
struct list_head *entry;
|
|
|
|
struct x25_forward *x25_frwd, *new_frwd;
|
|
|
|
struct sk_buff *skbn;
|
|
|
|
short same_lci = 0;
|
|
|
|
int rc = 0;
|
|
|
|
|
2007-03-20 01:04:56 +01:00
|
|
|
if ((rt = x25_get_route(dest_addr)) == NULL)
|
|
|
|
goto out_no_route;
|
2007-02-08 22:34:02 +01:00
|
|
|
|
2007-03-20 01:04:56 +01:00
|
|
|
if ((neigh_new = x25_get_neigh(rt->dev)) == NULL) {
|
2011-03-31 03:57:33 +02:00
|
|
|
/* This shouldn't happen, if it occurs somehow
|
2007-03-20 01:04:56 +01:00
|
|
|
* do something sensible
|
2007-02-08 22:34:02 +01:00
|
|
|
*/
|
2007-03-20 01:04:56 +01:00
|
|
|
goto out_put_route;
|
|
|
|
}
|
2007-02-08 22:34:02 +01:00
|
|
|
|
2007-03-20 01:04:56 +01:00
|
|
|
/* Avoid a loop. This is the normal exit path for a
|
|
|
|
* system with only one x.25 iface and default route
|
|
|
|
*/
|
|
|
|
if (rt->dev == from->dev) {
|
|
|
|
goto out_put_nb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remote end sending a call request on an already
|
2011-03-31 03:57:33 +02:00
|
|
|
* established LCI? It shouldn't happen, just in case..
|
2007-03-20 01:04:56 +01:00
|
|
|
*/
|
|
|
|
read_lock_bh(&x25_forward_list_lock);
|
|
|
|
list_for_each(entry, &x25_forward_list) {
|
|
|
|
x25_frwd = list_entry(entry, struct x25_forward, node);
|
|
|
|
if (x25_frwd->lci == lci) {
|
2013-12-06 12:24:33 +01:00
|
|
|
pr_warn("call request for lci which is already registered!, transmitting but not registering new pair\n");
|
2007-03-20 01:04:56 +01:00
|
|
|
same_lci = 1;
|
2007-02-08 22:34:02 +01:00
|
|
|
}
|
2007-03-20 01:04:56 +01:00
|
|
|
}
|
|
|
|
read_unlock_bh(&x25_forward_list_lock);
|
2007-02-08 22:34:02 +01:00
|
|
|
|
2007-03-20 01:04:56 +01:00
|
|
|
/* Save the forwarding details for future traffic */
|
|
|
|
if (!same_lci){
|
|
|
|
if ((new_frwd = kmalloc(sizeof(struct x25_forward),
|
|
|
|
GFP_ATOMIC)) == NULL){
|
|
|
|
rc = -ENOMEM;
|
2007-02-08 22:34:02 +01:00
|
|
|
goto out_put_nb;
|
|
|
|
}
|
2007-03-20 01:04:56 +01:00
|
|
|
new_frwd->lci = lci;
|
|
|
|
new_frwd->dev1 = rt->dev;
|
|
|
|
new_frwd->dev2 = from->dev;
|
|
|
|
write_lock_bh(&x25_forward_list_lock);
|
|
|
|
list_add(&new_frwd->node, &x25_forward_list);
|
|
|
|
write_unlock_bh(&x25_forward_list_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Forward the call request */
|
|
|
|
if ( (skbn = skb_clone(skb, GFP_ATOMIC)) == NULL){
|
|
|
|
goto out_put_nb;
|
2007-02-08 22:34:02 +01:00
|
|
|
}
|
2007-03-20 01:04:56 +01:00
|
|
|
x25_transmit_link(skbn, neigh_new);
|
|
|
|
rc = 1;
|
2007-02-08 22:34:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
out_put_nb:
|
|
|
|
x25_neigh_put(neigh_new);
|
|
|
|
|
|
|
|
out_put_route:
|
|
|
|
x25_route_put(rt);
|
2007-03-20 01:04:56 +01:00
|
|
|
|
|
|
|
out_no_route:
|
2007-02-08 22:34:02 +01:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int x25_forward_data(int lci, struct x25_neigh *from, struct sk_buff *skb) {
|
|
|
|
|
|
|
|
struct x25_forward *frwd;
|
|
|
|
struct list_head *entry;
|
|
|
|
struct net_device *peer = NULL;
|
|
|
|
struct x25_neigh *nb;
|
|
|
|
struct sk_buff *skbn;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
read_lock_bh(&x25_forward_list_lock);
|
|
|
|
list_for_each(entry, &x25_forward_list) {
|
|
|
|
frwd = list_entry(entry, struct x25_forward, node);
|
|
|
|
if (frwd->lci == lci) {
|
|
|
|
/* The call is established, either side can send */
|
|
|
|
if (from->dev == frwd->dev1) {
|
|
|
|
peer = frwd->dev2;
|
|
|
|
} else {
|
|
|
|
peer = frwd->dev1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
read_unlock_bh(&x25_forward_list_lock);
|
|
|
|
|
|
|
|
if ( (nb = x25_get_neigh(peer)) == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if ( (skbn = pskb_copy(skb, GFP_ATOMIC)) == NULL){
|
[X25]: Add missing x25_neigh_put
The function x25_get_neigh increments a reference count. At the point of
the second goto out, the result of calling x25_get_neigh is only stored in
a local variable, and thus no one outside the function will be able to
decrease the reference count. Thus, x25_neigh_put should be called before
the return in this case.
The problem was found using the following semantic match.
(http://www.emn.fr/x-info/coccinelle/)
// <smpl>
@@
type T,T1,T2;
identifier E;
statement S;
expression x1,x2,x3;
int ret;
@@
T E;
...
* if ((E = x25_get_neigh(...)) == NULL)
S
... when != x25_neigh_put(...,(T1)E,...)
when != if (E != NULL) { ... x25_neigh_put(...,(T1)E,...); ...}
when != x1 = (T1)E
when != E = x3;
when any
if (...) {
... when != x25_neigh_put(...,(T2)E,...)
when != if (E != NULL) { ... x25_neigh_put(...,(T2)E,...); ...}
when != x2 = (T2)E
(
* return;
|
* return ret;
)
}
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-01-02 04:30:30 +01:00
|
|
|
goto output;
|
2007-02-08 22:34:02 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
x25_transmit_link(skbn, nb);
|
|
|
|
|
|
|
|
rc = 1;
|
[X25]: Add missing x25_neigh_put
The function x25_get_neigh increments a reference count. At the point of
the second goto out, the result of calling x25_get_neigh is only stored in
a local variable, and thus no one outside the function will be able to
decrease the reference count. Thus, x25_neigh_put should be called before
the return in this case.
The problem was found using the following semantic match.
(http://www.emn.fr/x-info/coccinelle/)
// <smpl>
@@
type T,T1,T2;
identifier E;
statement S;
expression x1,x2,x3;
int ret;
@@
T E;
...
* if ((E = x25_get_neigh(...)) == NULL)
S
... when != x25_neigh_put(...,(T1)E,...)
when != if (E != NULL) { ... x25_neigh_put(...,(T1)E,...); ...}
when != x1 = (T1)E
when != E = x3;
when any
if (...) {
... when != x25_neigh_put(...,(T2)E,...)
when != if (E != NULL) { ... x25_neigh_put(...,(T2)E,...); ...}
when != x2 = (T2)E
(
* return;
|
* return ret;
)
}
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-01-02 04:30:30 +01:00
|
|
|
output:
|
|
|
|
x25_neigh_put(nb);
|
2007-02-08 22:34:02 +01:00
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void x25_clear_forward_by_lci(unsigned int lci)
|
|
|
|
{
|
|
|
|
struct x25_forward *fwd;
|
|
|
|
struct list_head *entry, *tmp;
|
|
|
|
|
|
|
|
write_lock_bh(&x25_forward_list_lock);
|
|
|
|
|
|
|
|
list_for_each_safe(entry, tmp, &x25_forward_list) {
|
|
|
|
fwd = list_entry(entry, struct x25_forward, node);
|
|
|
|
if (fwd->lci == lci) {
|
|
|
|
list_del(&fwd->node);
|
|
|
|
kfree(fwd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
write_unlock_bh(&x25_forward_list_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void x25_clear_forward_by_dev(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct x25_forward *fwd;
|
|
|
|
struct list_head *entry, *tmp;
|
|
|
|
|
|
|
|
write_lock_bh(&x25_forward_list_lock);
|
|
|
|
|
|
|
|
list_for_each_safe(entry, tmp, &x25_forward_list) {
|
|
|
|
fwd = list_entry(entry, struct x25_forward, node);
|
|
|
|
if ((fwd->dev1 == dev) || (fwd->dev2 == dev)){
|
|
|
|
list_del(&fwd->node);
|
|
|
|
kfree(fwd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
write_unlock_bh(&x25_forward_list_lock);
|
|
|
|
}
|