2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* DDP: An implementation of the AppleTalk DDP protocol for
|
|
|
|
* Ethernet 'ELAP'.
|
|
|
|
*
|
2008-10-14 06:01:08 +04:00
|
|
|
* Alan Cox <alan@lxorguk.ukuu.org.uk>
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* With more than a little assistance from
|
|
|
|
*
|
|
|
|
* Wesley Craig <netatalk@umich.edu>
|
|
|
|
*
|
|
|
|
* Fixes:
|
|
|
|
* Neil Horman : Added missing device ioctls
|
|
|
|
* Michael Callahan : Made routing work
|
|
|
|
* Wesley Craig : Fix probing to listen to a
|
|
|
|
* passed node id.
|
|
|
|
* Alan Cox : Added send/recvmsg support
|
|
|
|
* Alan Cox : Moved at. to protinfo in
|
|
|
|
* socket.
|
|
|
|
* Alan Cox : Added firewall hooks.
|
|
|
|
* Alan Cox : Supports new ARPHRD_LOOPBACK
|
|
|
|
* Christer Weinigel : Routing and /proc fixes.
|
|
|
|
* Bradford Johnson : LocalTalk.
|
|
|
|
* Tom Dyas : Module support.
|
|
|
|
* Alan Cox : Hooks for PPP (based on the
|
|
|
|
* LocalTalk hook).
|
|
|
|
* Alan Cox : Posix bits
|
|
|
|
* Alan Cox/Mike Freeman : Possible fix to NBP problems
|
|
|
|
* Bradford Johnson : IP-over-DDP (experimental)
|
|
|
|
* Jay Schulist : Moved IP-over-DDP to its own
|
|
|
|
* driver file. (ipddp.c & ipddp.h)
|
2007-02-09 17:24:27 +03:00
|
|
|
* Jay Schulist : Made work as module with
|
2005-04-17 02:20:36 +04:00
|
|
|
* AppleTalk drivers, cleaned it.
|
|
|
|
* Rob Newberry : Added proxy AARP and AARP
|
|
|
|
* procfs, moved probing to AARP
|
|
|
|
* module.
|
2007-02-09 17:24:27 +03:00
|
|
|
* Adrian Sun/
|
|
|
|
* Michael Zuelsdorff : fix for net.0 packets. don't
|
2005-04-17 02:20:36 +04:00
|
|
|
* allow illegal ether/tokentalk
|
2007-02-09 17:24:27 +03:00
|
|
|
* port assignment. we lose a
|
|
|
|
* valid localtalk port as a
|
2005-04-17 02:20:36 +04:00
|
|
|
* result.
|
|
|
|
* Arnaldo C. de Melo : Cleanup, in preparation for
|
|
|
|
* shared skb support 8)
|
|
|
|
* Arnaldo C. de Melo : Move proc stuff to atalk_proc.c,
|
|
|
|
* use seq_file
|
|
|
|
*
|
|
|
|
* This program 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.
|
2007-02-09 17:24:27 +03:00
|
|
|
*
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
|
2006-01-11 23:17:47 +03:00
|
|
|
#include <linux/capability.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/termios.h> /* For TIOCOUTQ/INQ */
|
2009-11-09 07:41:03 +03:00
|
|
|
#include <linux/compat.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 <net/datalink.h>
|
|
|
|
#include <net/psnap.h>
|
|
|
|
#include <net/sock.h>
|
2005-08-10 07:08:28 +04:00
|
|
|
#include <net/tcp_states.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <net/route.h>
|
|
|
|
#include <linux/atalk.h>
|
2012-04-05 13:35:15 +04:00
|
|
|
#include <linux/highmem.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
struct datalink_proto *ddp_dl, *aarp_dl;
|
2005-12-22 23:49:22 +03:00
|
|
|
static const struct proto_ops atalk_dgram_ops;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/**************************************************************************\
|
|
|
|
* *
|
|
|
|
* Handlers for the socket list. *
|
|
|
|
* *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
HLIST_HEAD(atalk_sockets);
|
|
|
|
DEFINE_RWLOCK(atalk_sockets_lock);
|
|
|
|
|
|
|
|
static inline void __atalk_insert_socket(struct sock *sk)
|
|
|
|
{
|
|
|
|
sk_add_node(sk, &atalk_sockets);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void atalk_remove_socket(struct sock *sk)
|
|
|
|
{
|
|
|
|
write_lock_bh(&atalk_sockets_lock);
|
|
|
|
sk_del_node_init(sk);
|
|
|
|
write_unlock_bh(&atalk_sockets_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sock *atalk_search_socket(struct sockaddr_at *to,
|
|
|
|
struct atalk_iface *atif)
|
|
|
|
{
|
|
|
|
struct sock *s;
|
|
|
|
|
|
|
|
read_lock_bh(&atalk_sockets_lock);
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
sk_for_each(s, &atalk_sockets) {
|
2005-04-17 02:20:36 +04:00
|
|
|
struct atalk_sock *at = at_sk(s);
|
|
|
|
|
|
|
|
if (to->sat_port != at->src_port)
|
|
|
|
continue;
|
|
|
|
|
2007-02-09 17:24:27 +03:00
|
|
|
if (to->sat_addr.s_net == ATADDR_ANYNET &&
|
2005-09-28 03:11:29 +04:00
|
|
|
to->sat_addr.s_node == ATADDR_BCAST)
|
2005-04-17 02:20:36 +04:00
|
|
|
goto found;
|
|
|
|
|
2007-02-09 17:24:27 +03:00
|
|
|
if (to->sat_addr.s_net == at->src_net &&
|
2005-04-17 02:20:36 +04:00
|
|
|
(to->sat_addr.s_node == at->src_node ||
|
|
|
|
to->sat_addr.s_node == ATADDR_BCAST ||
|
|
|
|
to->sat_addr.s_node == ATADDR_ANYNODE))
|
|
|
|
goto found;
|
|
|
|
|
2007-02-09 17:24:27 +03:00
|
|
|
/* XXXX.0 -- we got a request for this router. make sure
|
2005-04-17 02:20:36 +04:00
|
|
|
* that the node is appropriately set. */
|
|
|
|
if (to->sat_addr.s_node == ATADDR_ANYNODE &&
|
|
|
|
to->sat_addr.s_net != ATADDR_ANYNET &&
|
|
|
|
atif->address.s_node == at->src_node) {
|
|
|
|
to->sat_addr.s_node = atif->address.s_node;
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s = NULL;
|
|
|
|
found:
|
|
|
|
read_unlock_bh(&atalk_sockets_lock);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* atalk_find_or_insert_socket - Try to find a socket matching ADDR
|
2012-07-10 14:55:09 +04:00
|
|
|
* @sk: socket to insert in the list if it is not there already
|
|
|
|
* @sat: address to search for
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* Try to find a socket matching ADDR in the socket list, if found then return
|
|
|
|
* it. If not, insert SK into the socket list.
|
|
|
|
*
|
|
|
|
* This entire operation must execute atomically.
|
|
|
|
*/
|
|
|
|
static struct sock *atalk_find_or_insert_socket(struct sock *sk,
|
|
|
|
struct sockaddr_at *sat)
|
|
|
|
{
|
|
|
|
struct sock *s;
|
|
|
|
struct atalk_sock *at;
|
|
|
|
|
|
|
|
write_lock_bh(&atalk_sockets_lock);
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
sk_for_each(s, &atalk_sockets) {
|
2005-04-17 02:20:36 +04:00
|
|
|
at = at_sk(s);
|
|
|
|
|
|
|
|
if (at->src_net == sat->sat_addr.s_net &&
|
|
|
|
at->src_node == sat->sat_addr.s_node &&
|
|
|
|
at->src_port == sat->sat_port)
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
s = NULL;
|
|
|
|
__atalk_insert_socket(sk); /* Wheee, it's free, assign and insert. */
|
|
|
|
found:
|
|
|
|
write_unlock_bh(&atalk_sockets_lock);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void atalk_destroy_timer(unsigned long data)
|
|
|
|
{
|
|
|
|
struct sock *sk = (struct sock *)data;
|
|
|
|
|
2009-06-16 14:12:03 +04:00
|
|
|
if (sk_has_allocations(sk)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
|
|
|
|
add_timer(&sk->sk_timer);
|
|
|
|
} else
|
|
|
|
sock_put(sk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void atalk_destroy_socket(struct sock *sk)
|
|
|
|
{
|
|
|
|
atalk_remove_socket(sk);
|
|
|
|
skb_queue_purge(&sk->sk_receive_queue);
|
|
|
|
|
2009-06-16 14:12:03 +04:00
|
|
|
if (sk_has_allocations(sk)) {
|
2008-01-24 08:20:07 +03:00
|
|
|
setup_timer(&sk->sk_timer, atalk_destroy_timer,
|
|
|
|
(unsigned long)sk);
|
2005-04-17 02:20:36 +04:00
|
|
|
sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
|
|
|
|
add_timer(&sk->sk_timer);
|
|
|
|
} else
|
|
|
|
sock_put(sk);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************\
|
|
|
|
* *
|
|
|
|
* Routing tables for the AppleTalk socket layer. *
|
|
|
|
* *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* Anti-deadlock ordering is atalk_routes_lock --> iface_lock -DaveM */
|
|
|
|
struct atalk_route *atalk_routes;
|
|
|
|
DEFINE_RWLOCK(atalk_routes_lock);
|
|
|
|
|
|
|
|
struct atalk_iface *atalk_interfaces;
|
|
|
|
DEFINE_RWLOCK(atalk_interfaces_lock);
|
|
|
|
|
|
|
|
/* For probing devices or in a routerless network */
|
|
|
|
struct atalk_route atrtr_default;
|
|
|
|
|
|
|
|
/* AppleTalk interface control */
|
|
|
|
/*
|
|
|
|
* Drop a device. Doesn't drop any of its routes - that is the caller's
|
|
|
|
* problem. Called when we down the interface or delete the address.
|
|
|
|
*/
|
|
|
|
static void atif_drop_device(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct atalk_iface **iface = &atalk_interfaces;
|
|
|
|
struct atalk_iface *tmp;
|
|
|
|
|
|
|
|
write_lock_bh(&atalk_interfaces_lock);
|
|
|
|
while ((tmp = *iface) != NULL) {
|
|
|
|
if (tmp->dev == dev) {
|
|
|
|
*iface = tmp->next;
|
|
|
|
dev_put(dev);
|
|
|
|
kfree(tmp);
|
|
|
|
dev->atalk_ptr = NULL;
|
|
|
|
} else
|
|
|
|
iface = &tmp->next;
|
|
|
|
}
|
|
|
|
write_unlock_bh(&atalk_interfaces_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct atalk_iface *atif_add_device(struct net_device *dev,
|
|
|
|
struct atalk_addr *sa)
|
|
|
|
{
|
2006-07-22 01:51:30 +04:00
|
|
|
struct atalk_iface *iface = kzalloc(sizeof(*iface), GFP_KERNEL);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (!iface)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
dev_hold(dev);
|
|
|
|
iface->dev = dev;
|
|
|
|
dev->atalk_ptr = iface;
|
|
|
|
iface->address = *sa;
|
|
|
|
iface->status = 0;
|
|
|
|
|
|
|
|
write_lock_bh(&atalk_interfaces_lock);
|
|
|
|
iface->next = atalk_interfaces;
|
|
|
|
atalk_interfaces = iface;
|
|
|
|
write_unlock_bh(&atalk_interfaces_lock);
|
|
|
|
out:
|
|
|
|
return iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform phase 2 AARP probing on our tentative address */
|
|
|
|
static int atif_probe_device(struct atalk_iface *atif)
|
|
|
|
{
|
|
|
|
int netrange = ntohs(atif->nets.nr_lastnet) -
|
|
|
|
ntohs(atif->nets.nr_firstnet) + 1;
|
|
|
|
int probe_net = ntohs(atif->address.s_net);
|
|
|
|
int probe_node = atif->address.s_node;
|
|
|
|
int netct, nodect;
|
|
|
|
|
|
|
|
/* Offset the network we start probing with */
|
|
|
|
if (probe_net == ATADDR_ANYNET) {
|
|
|
|
probe_net = ntohs(atif->nets.nr_firstnet);
|
|
|
|
if (netrange)
|
|
|
|
probe_net += jiffies % netrange;
|
|
|
|
}
|
|
|
|
if (probe_node == ATADDR_ANYNODE)
|
|
|
|
probe_node = jiffies & 0xFF;
|
|
|
|
|
|
|
|
/* Scan the networks */
|
|
|
|
atif->status |= ATIF_PROBE;
|
|
|
|
for (netct = 0; netct <= netrange; netct++) {
|
|
|
|
/* Sweep the available nodes from a given start */
|
|
|
|
atif->address.s_net = htons(probe_net);
|
|
|
|
for (nodect = 0; nodect < 256; nodect++) {
|
|
|
|
atif->address.s_node = (nodect + probe_node) & 0xFF;
|
|
|
|
if (atif->address.s_node > 0 &&
|
|
|
|
atif->address.s_node < 254) {
|
|
|
|
/* Probe a proposed address */
|
|
|
|
aarp_probe_network(atif);
|
|
|
|
|
|
|
|
if (!(atif->status & ATIF_PROBE_FAIL)) {
|
|
|
|
atif->status &= ~ATIF_PROBE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
atif->status &= ~ATIF_PROBE_FAIL;
|
|
|
|
}
|
|
|
|
probe_net++;
|
|
|
|
if (probe_net > ntohs(atif->nets.nr_lastnet))
|
|
|
|
probe_net = ntohs(atif->nets.nr_firstnet);
|
|
|
|
}
|
|
|
|
atif->status &= ~ATIF_PROBE;
|
|
|
|
|
|
|
|
return -EADDRINUSE; /* Network is full... */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Perform AARP probing for a proxy address */
|
|
|
|
static int atif_proxy_probe_device(struct atalk_iface *atif,
|
2014-02-14 11:43:44 +04:00
|
|
|
struct atalk_addr *proxy_addr)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int netrange = ntohs(atif->nets.nr_lastnet) -
|
|
|
|
ntohs(atif->nets.nr_firstnet) + 1;
|
|
|
|
/* we probe the interface's network */
|
|
|
|
int probe_net = ntohs(atif->address.s_net);
|
|
|
|
int probe_node = ATADDR_ANYNODE; /* we'll take anything */
|
|
|
|
int netct, nodect;
|
|
|
|
|
|
|
|
/* Offset the network we start probing with */
|
|
|
|
if (probe_net == ATADDR_ANYNET) {
|
|
|
|
probe_net = ntohs(atif->nets.nr_firstnet);
|
|
|
|
if (netrange)
|
|
|
|
probe_net += jiffies % netrange;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (probe_node == ATADDR_ANYNODE)
|
|
|
|
probe_node = jiffies & 0xFF;
|
2007-02-09 17:24:27 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Scan the networks */
|
|
|
|
for (netct = 0; netct <= netrange; netct++) {
|
|
|
|
/* Sweep the available nodes from a given start */
|
|
|
|
proxy_addr->s_net = htons(probe_net);
|
|
|
|
for (nodect = 0; nodect < 256; nodect++) {
|
|
|
|
proxy_addr->s_node = (nodect + probe_node) & 0xFF;
|
|
|
|
if (proxy_addr->s_node > 0 &&
|
|
|
|
proxy_addr->s_node < 254) {
|
|
|
|
/* Tell AARP to probe a proposed address */
|
|
|
|
int ret = aarp_proxy_probe_network(atif,
|
|
|
|
proxy_addr);
|
|
|
|
|
|
|
|
if (ret != -EADDRINUSE)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
probe_net++;
|
|
|
|
if (probe_net > ntohs(atif->nets.nr_lastnet))
|
|
|
|
probe_net = ntohs(atif->nets.nr_firstnet);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EADDRINUSE; /* Network is full... */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct atalk_addr *atalk_find_dev_addr(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct atalk_iface *iface = dev->atalk_ptr;
|
|
|
|
return iface ? &iface->address : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct atalk_addr *atalk_find_primary(void)
|
|
|
|
{
|
|
|
|
struct atalk_iface *fiface = NULL;
|
|
|
|
struct atalk_addr *retval;
|
|
|
|
struct atalk_iface *iface;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a point-to-point interface only if
|
|
|
|
* there is no non-ptp interface available.
|
|
|
|
*/
|
|
|
|
read_lock_bh(&atalk_interfaces_lock);
|
|
|
|
for (iface = atalk_interfaces; iface; iface = iface->next) {
|
|
|
|
if (!fiface && !(iface->dev->flags & IFF_LOOPBACK))
|
|
|
|
fiface = iface;
|
|
|
|
if (!(iface->dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) {
|
|
|
|
retval = &iface->address;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fiface)
|
|
|
|
retval = &fiface->address;
|
|
|
|
else if (atalk_interfaces)
|
|
|
|
retval = &atalk_interfaces->address;
|
|
|
|
else
|
|
|
|
retval = NULL;
|
|
|
|
out:
|
|
|
|
read_unlock_bh(&atalk_interfaces_lock);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a match for 'any network' - ie any of our interfaces with that
|
|
|
|
* node number will do just nicely.
|
|
|
|
*/
|
|
|
|
static struct atalk_iface *atalk_find_anynet(int node, struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct atalk_iface *iface = dev->atalk_ptr;
|
|
|
|
|
|
|
|
if (!iface || iface->status & ATIF_PROBE)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
if (node != ATADDR_BCAST &&
|
|
|
|
iface->address.s_node != node &&
|
|
|
|
node != ATADDR_ANYNODE)
|
|
|
|
goto out_err;
|
|
|
|
out:
|
|
|
|
return iface;
|
|
|
|
out_err:
|
|
|
|
iface = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find a match for a specific network:node pair */
|
2005-06-21 00:32:05 +04:00
|
|
|
static struct atalk_iface *atalk_find_interface(__be16 net, int node)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct atalk_iface *iface;
|
|
|
|
|
|
|
|
read_lock_bh(&atalk_interfaces_lock);
|
|
|
|
for (iface = atalk_interfaces; iface; iface = iface->next) {
|
|
|
|
if ((node == ATADDR_BCAST ||
|
|
|
|
node == ATADDR_ANYNODE ||
|
|
|
|
iface->address.s_node == node) &&
|
|
|
|
iface->address.s_net == net &&
|
|
|
|
!(iface->status & ATIF_PROBE))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* XXXX.0 -- net.0 returns the iface associated with net */
|
|
|
|
if (node == ATADDR_ANYNODE && net != ATADDR_ANYNET &&
|
|
|
|
ntohs(iface->nets.nr_firstnet) <= ntohs(net) &&
|
|
|
|
ntohs(net) <= ntohs(iface->nets.nr_lastnet))
|
2007-02-09 17:24:27 +03:00
|
|
|
break;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
read_unlock_bh(&atalk_interfaces_lock);
|
|
|
|
return iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a route for an AppleTalk packet. This ought to get cached in
|
|
|
|
* the socket (later on...). We know about host routes and the fact
|
|
|
|
* that a route must be direct to broadcast.
|
|
|
|
*/
|
|
|
|
static struct atalk_route *atrtr_find(struct atalk_addr *target)
|
|
|
|
{
|
|
|
|
/*
|
2007-02-09 17:24:27 +03:00
|
|
|
* we must search through all routes unless we find a
|
2005-04-17 02:20:36 +04:00
|
|
|
* host route, because some host routes might overlap
|
|
|
|
* network routes
|
|
|
|
*/
|
|
|
|
struct atalk_route *net_route = NULL;
|
|
|
|
struct atalk_route *r;
|
2007-02-09 17:24:27 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
read_lock_bh(&atalk_routes_lock);
|
|
|
|
for (r = atalk_routes; r; r = r->next) {
|
|
|
|
if (!(r->flags & RTF_UP))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (r->target.s_net == target->s_net) {
|
|
|
|
if (r->flags & RTF_HOST) {
|
|
|
|
/*
|
|
|
|
* if this host route is for the target,
|
|
|
|
* the we're done
|
|
|
|
*/
|
|
|
|
if (r->target.s_node == target->s_node)
|
|
|
|
goto out;
|
|
|
|
} else
|
|
|
|
/*
|
|
|
|
* this route will work if there isn't a
|
|
|
|
* direct host route, so cache it
|
|
|
|
*/
|
|
|
|
net_route = r;
|
|
|
|
}
|
|
|
|
}
|
2007-02-09 17:24:27 +03:00
|
|
|
|
|
|
|
/*
|
2005-04-17 02:20:36 +04:00
|
|
|
* if we found a network route but not a direct host
|
|
|
|
* route, then return it
|
|
|
|
*/
|
|
|
|
if (net_route)
|
|
|
|
r = net_route;
|
|
|
|
else if (atrtr_default.dev)
|
|
|
|
r = &atrtr_default;
|
|
|
|
else /* No route can be found */
|
|
|
|
r = NULL;
|
|
|
|
out:
|
|
|
|
read_unlock_bh(&atalk_routes_lock);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given an AppleTalk network, find the device to use. This can be
|
|
|
|
* a simple lookup.
|
|
|
|
*/
|
|
|
|
struct net_device *atrtr_get_dev(struct atalk_addr *sa)
|
|
|
|
{
|
|
|
|
struct atalk_route *atr = atrtr_find(sa);
|
|
|
|
return atr ? atr->dev : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up a default router */
|
|
|
|
static void atrtr_set_default(struct net_device *dev)
|
|
|
|
{
|
|
|
|
atrtr_default.dev = dev;
|
|
|
|
atrtr_default.flags = RTF_UP;
|
|
|
|
atrtr_default.gateway.s_net = htons(0);
|
|
|
|
atrtr_default.gateway.s_node = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a router. Basically make sure it looks valid and stuff the
|
|
|
|
* entry in the list. While it uses netranges we always set them to one
|
|
|
|
* entry to work like netatalk.
|
|
|
|
*/
|
|
|
|
static int atrtr_create(struct rtentry *r, struct net_device *devhint)
|
|
|
|
{
|
|
|
|
struct sockaddr_at *ta = (struct sockaddr_at *)&r->rt_dst;
|
|
|
|
struct sockaddr_at *ga = (struct sockaddr_at *)&r->rt_gateway;
|
|
|
|
struct atalk_route *rt;
|
|
|
|
struct atalk_iface *iface, *riface;
|
|
|
|
int retval = -EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fixme: Raise/Lower a routing change semaphore for these
|
|
|
|
* operations.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Validate the request */
|
|
|
|
if (ta->sat_family != AF_APPLETALK ||
|
|
|
|
(!devhint && ga->sat_family != AF_APPLETALK))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Now walk the routing table and make our decisions */
|
|
|
|
write_lock_bh(&atalk_routes_lock);
|
|
|
|
for (rt = atalk_routes; rt; rt = rt->next) {
|
|
|
|
if (r->rt_flags != rt->flags)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ta->sat_addr.s_net == rt->target.s_net) {
|
|
|
|
if (!(rt->flags & RTF_HOST))
|
|
|
|
break;
|
|
|
|
if (ta->sat_addr.s_node == rt->target.s_node)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!devhint) {
|
|
|
|
riface = NULL;
|
|
|
|
|
|
|
|
read_lock_bh(&atalk_interfaces_lock);
|
|
|
|
for (iface = atalk_interfaces; iface; iface = iface->next) {
|
|
|
|
if (!riface &&
|
|
|
|
ntohs(ga->sat_addr.s_net) >=
|
2007-02-09 17:24:27 +03:00
|
|
|
ntohs(iface->nets.nr_firstnet) &&
|
2005-04-17 02:20:36 +04:00
|
|
|
ntohs(ga->sat_addr.s_net) <=
|
2007-02-09 17:24:27 +03:00
|
|
|
ntohs(iface->nets.nr_lastnet))
|
2005-04-17 02:20:36 +04:00
|
|
|
riface = iface;
|
|
|
|
|
|
|
|
if (ga->sat_addr.s_net == iface->address.s_net &&
|
|
|
|
ga->sat_addr.s_node == iface->address.s_node)
|
|
|
|
riface = iface;
|
2007-02-09 17:24:27 +03:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
read_unlock_bh(&atalk_interfaces_lock);
|
|
|
|
|
|
|
|
retval = -ENETUNREACH;
|
|
|
|
if (!riface)
|
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
devhint = riface->dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rt) {
|
2006-07-22 01:51:30 +04:00
|
|
|
rt = kzalloc(sizeof(*rt), GFP_ATOMIC);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
retval = -ENOBUFS;
|
|
|
|
if (!rt)
|
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
rt->next = atalk_routes;
|
|
|
|
atalk_routes = rt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in the routing entry */
|
|
|
|
rt->target = ta->sat_addr;
|
2005-04-20 09:44:17 +04:00
|
|
|
dev_hold(devhint);
|
2005-04-17 02:20:36 +04:00
|
|
|
rt->dev = devhint;
|
|
|
|
rt->flags = r->rt_flags;
|
|
|
|
rt->gateway = ga->sat_addr;
|
|
|
|
|
|
|
|
retval = 0;
|
|
|
|
out_unlock:
|
|
|
|
write_unlock_bh(&atalk_routes_lock);
|
|
|
|
out:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete a route. Find it and discard it */
|
2014-02-14 11:43:44 +04:00
|
|
|
static int atrtr_delete(struct atalk_addr *addr)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct atalk_route **r = &atalk_routes;
|
|
|
|
int retval = 0;
|
|
|
|
struct atalk_route *tmp;
|
|
|
|
|
|
|
|
write_lock_bh(&atalk_routes_lock);
|
|
|
|
while ((tmp = *r) != NULL) {
|
|
|
|
if (tmp->target.s_net == addr->s_net &&
|
|
|
|
(!(tmp->flags&RTF_GATEWAY) ||
|
|
|
|
tmp->target.s_node == addr->s_node)) {
|
|
|
|
*r = tmp->next;
|
|
|
|
dev_put(tmp->dev);
|
|
|
|
kfree(tmp);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
r = &tmp->next;
|
|
|
|
}
|
|
|
|
retval = -ENOENT;
|
|
|
|
out:
|
|
|
|
write_unlock_bh(&atalk_routes_lock);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when a device is downed. Just throw away any routes
|
|
|
|
* via it.
|
|
|
|
*/
|
|
|
|
static void atrtr_device_down(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct atalk_route **r = &atalk_routes;
|
|
|
|
struct atalk_route *tmp;
|
|
|
|
|
|
|
|
write_lock_bh(&atalk_routes_lock);
|
|
|
|
while ((tmp = *r) != NULL) {
|
|
|
|
if (tmp->dev == dev) {
|
|
|
|
*r = tmp->next;
|
|
|
|
dev_put(dev);
|
|
|
|
kfree(tmp);
|
|
|
|
} else
|
|
|
|
r = &tmp->next;
|
|
|
|
}
|
|
|
|
write_unlock_bh(&atalk_routes_lock);
|
|
|
|
|
|
|
|
if (atrtr_default.dev == dev)
|
|
|
|
atrtr_set_default(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Actually down the interface */
|
|
|
|
static inline void atalk_dev_down(struct net_device *dev)
|
|
|
|
{
|
|
|
|
atrtr_device_down(dev); /* Remove all routes for the device */
|
|
|
|
aarp_device_down(dev); /* Remove AARP entries for the device */
|
|
|
|
atif_drop_device(dev); /* Remove the device */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A device event has occurred. Watch for devices going down and
|
|
|
|
* delete our use of them (iface and route).
|
|
|
|
*/
|
|
|
|
static int ddp_device_event(struct notifier_block *this, unsigned long event,
|
|
|
|
void *ptr)
|
|
|
|
{
|
2013-05-28 05:30:21 +04:00
|
|
|
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
|
2007-09-12 13:26:59 +04:00
|
|
|
|
2008-07-20 09:34:43 +04:00
|
|
|
if (!net_eq(dev_net(dev), &init_net))
|
2007-09-12 15:02:17 +04:00
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (event == NETDEV_DOWN)
|
|
|
|
/* Discard any use of this */
|
2007-09-12 13:26:59 +04:00
|
|
|
atalk_dev_down(dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ioctl calls. Shouldn't even need touching */
|
|
|
|
/* Device configuration ioctl calls */
|
|
|
|
static int atif_ioctl(int cmd, void __user *arg)
|
|
|
|
{
|
|
|
|
static char aarp_mcast[6] = { 0x09, 0x00, 0x00, 0xFF, 0xFF, 0xFF };
|
|
|
|
struct ifreq atreq;
|
|
|
|
struct atalk_netrange *nr;
|
|
|
|
struct sockaddr_at *sa;
|
|
|
|
struct net_device *dev;
|
|
|
|
struct atalk_iface *atif;
|
|
|
|
int ct;
|
|
|
|
int limit;
|
|
|
|
struct rtentry rtdef;
|
|
|
|
int add_route;
|
|
|
|
|
|
|
|
if (copy_from_user(&atreq, arg, sizeof(atreq)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2007-09-17 22:56:21 +04:00
|
|
|
dev = __dev_get_by_name(&init_net, atreq.ifr_name);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
sa = (struct sockaddr_at *)&atreq.ifr_addr;
|
|
|
|
atif = atalk_find_dev(dev);
|
|
|
|
|
|
|
|
switch (cmd) {
|
2011-07-01 13:43:02 +04:00
|
|
|
case SIOCSIFADDR:
|
|
|
|
if (!capable(CAP_NET_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
if (sa->sat_family != AF_APPLETALK)
|
|
|
|
return -EINVAL;
|
|
|
|
if (dev->type != ARPHRD_ETHER &&
|
|
|
|
dev->type != ARPHRD_LOOPBACK &&
|
|
|
|
dev->type != ARPHRD_LOCALTLK &&
|
|
|
|
dev->type != ARPHRD_PPP)
|
|
|
|
return -EPROTONOSUPPORT;
|
|
|
|
|
|
|
|
nr = (struct atalk_netrange *)&sa->sat_zero[0];
|
|
|
|
add_route = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if this is a point-to-point iface, and we already
|
|
|
|
* have an iface for this AppleTalk address, then we
|
|
|
|
* should not add a route
|
|
|
|
*/
|
|
|
|
if ((dev->flags & IFF_POINTOPOINT) &&
|
|
|
|
atalk_find_interface(sa->sat_addr.s_net,
|
|
|
|
sa->sat_addr.s_node)) {
|
|
|
|
printk(KERN_DEBUG "AppleTalk: point-to-point "
|
|
|
|
"interface added with "
|
|
|
|
"existing address\n");
|
|
|
|
add_route = 0;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-07-01 13:43:02 +04:00
|
|
|
/*
|
|
|
|
* Phase 1 is fine on LocalTalk but we don't do
|
|
|
|
* EtherTalk phase 1. Anyone wanting to add it go ahead.
|
|
|
|
*/
|
|
|
|
if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
|
|
|
|
return -EPROTONOSUPPORT;
|
|
|
|
if (sa->sat_addr.s_node == ATADDR_BCAST ||
|
|
|
|
sa->sat_addr.s_node == 254)
|
|
|
|
return -EINVAL;
|
|
|
|
if (atif) {
|
|
|
|
/* Already setting address */
|
|
|
|
if (atif->status & ATIF_PROBE)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
atif->address.s_net = sa->sat_addr.s_net;
|
|
|
|
atif->address.s_node = sa->sat_addr.s_node;
|
|
|
|
atrtr_device_down(dev); /* Flush old routes */
|
|
|
|
} else {
|
|
|
|
atif = atif_add_device(dev, &sa->sat_addr);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!atif)
|
2011-07-01 13:43:02 +04:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
atif->nets = *nr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the chosen address is used. If so we
|
|
|
|
* error and atalkd will try another.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!(dev->flags & IFF_LOOPBACK) &&
|
|
|
|
!(dev->flags & IFF_POINTOPOINT) &&
|
|
|
|
atif_probe_device(atif) < 0) {
|
|
|
|
atif_drop_device(dev);
|
|
|
|
return -EADDRINUSE;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-07-01 13:43:02 +04:00
|
|
|
/* Hey it worked - add the direct routes */
|
|
|
|
sa = (struct sockaddr_at *)&rtdef.rt_gateway;
|
|
|
|
sa->sat_family = AF_APPLETALK;
|
|
|
|
sa->sat_addr.s_net = atif->address.s_net;
|
|
|
|
sa->sat_addr.s_node = atif->address.s_node;
|
|
|
|
sa = (struct sockaddr_at *)&rtdef.rt_dst;
|
|
|
|
rtdef.rt_flags = RTF_UP;
|
|
|
|
sa->sat_family = AF_APPLETALK;
|
|
|
|
sa->sat_addr.s_node = ATADDR_ANYNODE;
|
|
|
|
if (dev->flags & IFF_LOOPBACK ||
|
|
|
|
dev->flags & IFF_POINTOPOINT)
|
|
|
|
rtdef.rt_flags |= RTF_HOST;
|
|
|
|
|
|
|
|
/* Routerless initial state */
|
|
|
|
if (nr->nr_firstnet == htons(0) &&
|
|
|
|
nr->nr_lastnet == htons(0xFFFE)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
sa->sat_addr.s_net = atif->address.s_net;
|
2011-07-01 13:43:02 +04:00
|
|
|
atrtr_create(&rtdef, dev);
|
|
|
|
atrtr_set_default(dev);
|
|
|
|
} else {
|
|
|
|
limit = ntohs(nr->nr_lastnet);
|
|
|
|
if (limit - ntohs(nr->nr_firstnet) > 4096) {
|
|
|
|
printk(KERN_WARNING "Too many routes/"
|
|
|
|
"iface.\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EINVAL;
|
2011-07-01 13:43:02 +04:00
|
|
|
}
|
|
|
|
if (add_route)
|
|
|
|
for (ct = ntohs(nr->nr_firstnet);
|
|
|
|
ct <= limit; ct++) {
|
|
|
|
sa->sat_addr.s_net = htons(ct);
|
|
|
|
atrtr_create(&rtdef, dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dev_mc_add_global(dev, aarp_mcast);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
if (!atif)
|
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
|
|
|
|
sa->sat_family = AF_APPLETALK;
|
|
|
|
sa->sat_addr = atif->address;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFBRDADDR:
|
|
|
|
if (!atif)
|
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
|
|
|
|
sa->sat_family = AF_APPLETALK;
|
|
|
|
sa->sat_addr.s_net = atif->address.s_net;
|
|
|
|
sa->sat_addr.s_node = ATADDR_BCAST;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCATALKDIFADDR:
|
|
|
|
case SIOCDIFADDR:
|
|
|
|
if (!capable(CAP_NET_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
if (sa->sat_family != AF_APPLETALK)
|
|
|
|
return -EINVAL;
|
|
|
|
atalk_dev_down(dev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSARP:
|
|
|
|
if (!capable(CAP_NET_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
if (sa->sat_family != AF_APPLETALK)
|
|
|
|
return -EINVAL;
|
|
|
|
/*
|
|
|
|
* for now, we only support proxy AARP on ELAP;
|
|
|
|
* we should be able to do it for LocalTalk, too.
|
|
|
|
*/
|
|
|
|
if (dev->type != ARPHRD_ETHER)
|
|
|
|
return -EPROTONOSUPPORT;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* atif points to the current interface on this network;
|
|
|
|
* we aren't concerned about its current status (at
|
|
|
|
* least for now), but it has all the settings about
|
|
|
|
* the network we're going to probe. Consequently, it
|
|
|
|
* must exist.
|
|
|
|
*/
|
|
|
|
if (!atif)
|
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
|
|
|
|
nr = (struct atalk_netrange *)&(atif->nets);
|
|
|
|
/*
|
|
|
|
* Phase 1 is fine on Localtalk but we don't do
|
|
|
|
* Ethertalk phase 1. Anyone wanting to add it go ahead.
|
|
|
|
*/
|
|
|
|
if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
|
|
|
|
return -EPROTONOSUPPORT;
|
|
|
|
|
|
|
|
if (sa->sat_addr.s_node == ATADDR_BCAST ||
|
|
|
|
sa->sat_addr.s_node == 254)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the chosen address is used. If so we
|
|
|
|
* error and ATCP will try another.
|
|
|
|
*/
|
|
|
|
if (atif_proxy_probe_device(atif, &(sa->sat_addr)) < 0)
|
|
|
|
return -EADDRINUSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We now have an address on the local network, and
|
|
|
|
* the AARP code will defend it for us until we take it
|
|
|
|
* down. We don't set up any routes right now, because
|
|
|
|
* ATCP will install them manually via SIOCADDRT.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCDARP:
|
|
|
|
if (!capable(CAP_NET_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
if (sa->sat_family != AF_APPLETALK)
|
|
|
|
return -EINVAL;
|
|
|
|
if (!atif)
|
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
|
|
|
|
/* give to aarp module to remove proxy entry */
|
|
|
|
aarp_proxy_remove(atif->dev, &(sa->sat_addr));
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return copy_to_user(arg, &atreq, sizeof(atreq)) ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Routing ioctl() calls */
|
|
|
|
static int atrtr_ioctl(unsigned int cmd, void __user *arg)
|
|
|
|
{
|
|
|
|
struct rtentry rt;
|
|
|
|
|
|
|
|
if (copy_from_user(&rt, arg, sizeof(rt)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
switch (cmd) {
|
2011-07-01 13:43:02 +04:00
|
|
|
case SIOCDELRT:
|
|
|
|
if (rt.rt_dst.sa_family != AF_APPLETALK)
|
|
|
|
return -EINVAL;
|
|
|
|
return atrtr_delete(&((struct sockaddr_at *)
|
|
|
|
&rt.rt_dst)->sat_addr);
|
|
|
|
|
|
|
|
case SIOCADDRT: {
|
|
|
|
struct net_device *dev = NULL;
|
|
|
|
if (rt.rt_dev) {
|
|
|
|
char name[IFNAMSIZ];
|
|
|
|
if (copy_from_user(name, rt.rt_dev, IFNAMSIZ-1))
|
|
|
|
return -EFAULT;
|
|
|
|
name[IFNAMSIZ-1] = '\0';
|
|
|
|
dev = __dev_get_by_name(&init_net, name);
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2011-07-01 13:43:02 +04:00
|
|
|
return atrtr_create(&rt, dev);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************\
|
|
|
|
* *
|
|
|
|
* Handling for system calls applied via the various interfaces to an *
|
|
|
|
* AppleTalk socket object. *
|
|
|
|
* *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checksum: This is 'optional'. It's quite likely also a good
|
|
|
|
* candidate for assembler hackery 8)
|
|
|
|
*/
|
2007-02-09 17:24:27 +03:00
|
|
|
static unsigned long atalk_sum_partial(const unsigned char *data,
|
2005-04-17 02:20:36 +04:00
|
|
|
int len, unsigned long sum)
|
|
|
|
{
|
|
|
|
/* This ought to be unwrapped neatly. I'll trust gcc for now */
|
|
|
|
while (len--) {
|
2009-11-04 13:26:13 +03:00
|
|
|
sum += *data++;
|
|
|
|
sum = rol16(sum, 1);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Checksum skb data -- similar to skb_checksum */
|
|
|
|
static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
|
|
|
|
int len, unsigned long sum)
|
|
|
|
{
|
2007-04-28 02:21:23 +04:00
|
|
|
int start = skb_headlen(skb);
|
2009-06-09 11:17:44 +04:00
|
|
|
struct sk_buff *frag_iter;
|
2005-04-17 02:20:36 +04:00
|
|
|
int i, copy;
|
|
|
|
|
|
|
|
/* checksum stuff in header space */
|
2014-02-14 11:43:43 +04:00
|
|
|
if ((copy = start - offset) > 0) {
|
2005-04-17 02:20:36 +04:00
|
|
|
if (copy > len)
|
|
|
|
copy = len;
|
|
|
|
sum = atalk_sum_partial(skb->data + offset, copy, sum);
|
2014-02-14 11:43:43 +04:00
|
|
|
if ((len -= copy) == 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
return sum;
|
|
|
|
|
|
|
|
offset += copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* checksum stuff in frags */
|
|
|
|
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
|
2007-04-28 02:21:23 +04:00
|
|
|
int end;
|
2011-10-19 01:00:24 +04:00
|
|
|
const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
|
2008-07-26 08:43:18 +04:00
|
|
|
WARN_ON(start > offset + len);
|
2007-04-28 02:21:23 +04:00
|
|
|
|
2011-10-19 01:00:24 +04:00
|
|
|
end = start + skb_frag_size(frag);
|
2005-04-17 02:20:36 +04:00
|
|
|
if ((copy = end - offset) > 0) {
|
|
|
|
u8 *vaddr;
|
|
|
|
|
|
|
|
if (copy > len)
|
|
|
|
copy = len;
|
2012-04-05 13:35:15 +04:00
|
|
|
vaddr = kmap_atomic(skb_frag_page(frag));
|
2007-04-28 02:21:23 +04:00
|
|
|
sum = atalk_sum_partial(vaddr + frag->page_offset +
|
|
|
|
offset - start, copy, sum);
|
2012-04-05 13:35:15 +04:00
|
|
|
kunmap_atomic(vaddr);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (!(len -= copy))
|
|
|
|
return sum;
|
|
|
|
offset += copy;
|
|
|
|
}
|
2007-04-28 02:21:23 +04:00
|
|
|
start = end;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2009-06-09 11:17:44 +04:00
|
|
|
skb_walk_frags(skb, frag_iter) {
|
|
|
|
int end;
|
2007-04-28 02:21:23 +04:00
|
|
|
|
2009-06-09 11:17:44 +04:00
|
|
|
WARN_ON(start > offset + len);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-06-09 11:17:44 +04:00
|
|
|
end = start + frag_iter->len;
|
|
|
|
if ((copy = end - offset) > 0) {
|
|
|
|
if (copy > len)
|
|
|
|
copy = len;
|
|
|
|
sum = atalk_sum_skb(frag_iter, offset - start,
|
|
|
|
copy, sum);
|
|
|
|
if ((len -= copy) == 0)
|
|
|
|
return sum;
|
|
|
|
offset += copy;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2009-06-09 11:17:44 +04:00
|
|
|
start = end;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BUG_ON(len > 0);
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2006-09-27 08:22:08 +04:00
|
|
|
static __be16 atalk_checksum(const struct sk_buff *skb, int len)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned long sum;
|
|
|
|
|
|
|
|
/* skip header 4 bytes */
|
|
|
|
sum = atalk_sum_skb(skb, 4, len-4, 0);
|
|
|
|
|
|
|
|
/* Use 0xFFFF for 0. 0 itself means none */
|
2006-09-27 08:22:08 +04:00
|
|
|
return sum ? htons((unsigned short)sum) : htons(0xFFFF);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct proto ddp_proto = {
|
|
|
|
.name = "DDP",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.obj_size = sizeof(struct atalk_sock),
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a socket. Initialise the socket, blank the addresses
|
|
|
|
* set the state.
|
|
|
|
*/
|
2009-11-06 09:18:14 +03:00
|
|
|
static int atalk_create(struct net *net, struct socket *sock, int protocol,
|
|
|
|
int kern)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct sock *sk;
|
|
|
|
int rc = -ESOCKTNOSUPPORT;
|
|
|
|
|
2009-11-26 02:14:13 +03:00
|
|
|
if (!net_eq(net, &init_net))
|
2007-10-09 10:24:22 +04:00
|
|
|
return -EAFNOSUPPORT;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* We permit SOCK_DGRAM and RAW is an extension. It is trivial to do
|
2007-02-09 17:24:27 +03:00
|
|
|
* and gives you the full ELAP frame. Should be handy for CAP 8)
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM)
|
|
|
|
goto out;
|
|
|
|
rc = -ENOMEM;
|
2007-11-01 10:39:31 +03:00
|
|
|
sk = sk_alloc(net, PF_APPLETALK, GFP_KERNEL, &ddp_proto);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!sk)
|
|
|
|
goto out;
|
|
|
|
rc = 0;
|
|
|
|
sock->ops = &atalk_dgram_ops;
|
|
|
|
sock_init_data(sock, sk);
|
|
|
|
|
|
|
|
/* Checksums on by default */
|
|
|
|
sock_set_flag(sk, SOCK_ZAPPED);
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free a socket. No work needed */
|
|
|
|
static int atalk_release(struct socket *sock)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
|
|
|
|
if (sk) {
|
2011-04-01 05:59:10 +04:00
|
|
|
sock_hold(sk);
|
|
|
|
lock_sock(sk);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
sock_orphan(sk);
|
|
|
|
sock->sk = NULL;
|
|
|
|
atalk_destroy_socket(sk);
|
2011-03-22 04:18:00 +03:00
|
|
|
|
2011-04-01 05:59:10 +04:00
|
|
|
release_sock(sk);
|
|
|
|
sock_put(sk);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* atalk_pick_and_bind_port - Pick a source port when one is not given
|
2012-07-10 14:55:09 +04:00
|
|
|
* @sk: socket to insert into the tables
|
|
|
|
* @sat: address to search for
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* Pick a source port when one is not given. If we can find a suitable free
|
|
|
|
* one, we insert the socket into the tables using it.
|
|
|
|
*
|
|
|
|
* This whole operation must be atomic.
|
|
|
|
*/
|
|
|
|
static int atalk_pick_and_bind_port(struct sock *sk, struct sockaddr_at *sat)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
write_lock_bh(&atalk_sockets_lock);
|
|
|
|
|
|
|
|
for (sat->sat_port = ATPORT_RESERVED;
|
|
|
|
sat->sat_port < ATPORT_LAST;
|
|
|
|
sat->sat_port++) {
|
|
|
|
struct sock *s;
|
|
|
|
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
sk_for_each(s, &atalk_sockets) {
|
2005-04-17 02:20:36 +04:00
|
|
|
struct atalk_sock *at = at_sk(s);
|
|
|
|
|
|
|
|
if (at->src_net == sat->sat_addr.s_net &&
|
|
|
|
at->src_node == sat->sat_addr.s_node &&
|
|
|
|
at->src_port == sat->sat_port)
|
|
|
|
goto try_next_port;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wheee, it's free, assign and insert. */
|
|
|
|
__atalk_insert_socket(sk);
|
|
|
|
at_sk(sk)->src_port = sat->sat_port;
|
|
|
|
retval = 0;
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
try_next_port:;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = -EBUSY;
|
|
|
|
out:
|
|
|
|
write_unlock_bh(&atalk_sockets_lock);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int atalk_autobind(struct sock *sk)
|
|
|
|
{
|
|
|
|
struct atalk_sock *at = at_sk(sk);
|
|
|
|
struct sockaddr_at sat;
|
|
|
|
struct atalk_addr *ap = atalk_find_primary();
|
|
|
|
int n = -EADDRNOTAVAIL;
|
|
|
|
|
|
|
|
if (!ap || ap->s_net == htons(ATADDR_ANYNET))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
at->src_net = sat.sat_addr.s_net = ap->s_net;
|
|
|
|
at->src_node = sat.sat_addr.s_node = ap->s_node;
|
|
|
|
|
|
|
|
n = atalk_pick_and_bind_port(sk, &sat);
|
|
|
|
if (!n)
|
|
|
|
sock_reset_flag(sk, SOCK_ZAPPED);
|
|
|
|
out:
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the address 'our end' of the connection */
|
|
|
|
static int atalk_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
|
|
|
|
{
|
|
|
|
struct sockaddr_at *addr = (struct sockaddr_at *)uaddr;
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct atalk_sock *at = at_sk(sk);
|
2009-11-05 07:37:26 +03:00
|
|
|
int err;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (!sock_flag(sk, SOCK_ZAPPED) ||
|
|
|
|
addr_len != sizeof(struct sockaddr_at))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (addr->sat_family != AF_APPLETALK)
|
|
|
|
return -EAFNOSUPPORT;
|
|
|
|
|
2011-01-23 02:21:11 +03:00
|
|
|
lock_sock(sk);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (addr->sat_addr.s_net == htons(ATADDR_ANYNET)) {
|
|
|
|
struct atalk_addr *ap = atalk_find_primary();
|
|
|
|
|
2009-11-05 07:37:26 +03:00
|
|
|
err = -EADDRNOTAVAIL;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!ap)
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
at->src_net = addr->sat_addr.s_net = ap->s_net;
|
2014-02-14 11:43:43 +04:00
|
|
|
at->src_node = addr->sat_addr.s_node = ap->s_node;
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
2009-11-05 07:37:26 +03:00
|
|
|
err = -EADDRNOTAVAIL;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!atalk_find_interface(addr->sat_addr.s_net,
|
|
|
|
addr->sat_addr.s_node))
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
at->src_net = addr->sat_addr.s_net;
|
|
|
|
at->src_node = addr->sat_addr.s_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addr->sat_port == ATADDR_ANYPORT) {
|
2009-11-05 07:37:26 +03:00
|
|
|
err = atalk_pick_and_bind_port(sk, addr);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-11-05 07:37:26 +03:00
|
|
|
if (err < 0)
|
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
|
|
|
at->src_port = addr->sat_port;
|
|
|
|
|
2009-11-05 07:37:26 +03:00
|
|
|
err = -EADDRINUSE;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (atalk_find_or_insert_socket(sk, addr))
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sock_reset_flag(sk, SOCK_ZAPPED);
|
2009-11-05 07:37:26 +03:00
|
|
|
err = 0;
|
|
|
|
out:
|
2011-01-23 02:21:11 +03:00
|
|
|
release_sock(sk);
|
2009-11-05 07:37:26 +03:00
|
|
|
return err;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the address we talk to */
|
|
|
|
static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
|
|
|
|
int addr_len, int flags)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct atalk_sock *at = at_sk(sk);
|
|
|
|
struct sockaddr_at *addr;
|
2009-11-05 07:37:26 +03:00
|
|
|
int err;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
sk->sk_state = TCP_CLOSE;
|
|
|
|
sock->state = SS_UNCONNECTED;
|
|
|
|
|
|
|
|
if (addr_len != sizeof(*addr))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
addr = (struct sockaddr_at *)uaddr;
|
|
|
|
|
|
|
|
if (addr->sat_family != AF_APPLETALK)
|
|
|
|
return -EAFNOSUPPORT;
|
|
|
|
|
|
|
|
if (addr->sat_addr.s_node == ATADDR_BCAST &&
|
|
|
|
!sock_flag(sk, SOCK_BROADCAST)) {
|
2007-02-09 17:24:27 +03:00
|
|
|
#if 1
|
2012-06-06 12:45:59 +04:00
|
|
|
pr_warn("atalk_connect: %s is broken and did not set SO_BROADCAST.\n",
|
2005-04-17 02:20:36 +04:00
|
|
|
current->comm);
|
|
|
|
#else
|
|
|
|
return -EACCES;
|
2007-02-09 17:24:27 +03:00
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2011-01-23 02:21:11 +03:00
|
|
|
lock_sock(sk);
|
2009-11-05 07:37:26 +03:00
|
|
|
err = -EBUSY;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (sock_flag(sk, SOCK_ZAPPED))
|
|
|
|
if (atalk_autobind(sk) < 0)
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-11-05 07:37:26 +03:00
|
|
|
err = -ENETUNREACH;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!atrtr_get_dev(&addr->sat_addr))
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
at->dest_port = addr->sat_port;
|
|
|
|
at->dest_net = addr->sat_addr.s_net;
|
|
|
|
at->dest_node = addr->sat_addr.s_node;
|
|
|
|
|
|
|
|
sock->state = SS_CONNECTED;
|
|
|
|
sk->sk_state = TCP_ESTABLISHED;
|
2009-11-05 07:37:26 +03:00
|
|
|
err = 0;
|
|
|
|
out:
|
2011-01-23 02:21:11 +03:00
|
|
|
release_sock(sk);
|
2009-11-05 07:37:26 +03:00
|
|
|
return err;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the name of an AppleTalk socket. Just copy the right
|
|
|
|
* fields into the sockaddr.
|
|
|
|
*/
|
|
|
|
static int atalk_getname(struct socket *sock, struct sockaddr *uaddr,
|
|
|
|
int *uaddr_len, int peer)
|
|
|
|
{
|
|
|
|
struct sockaddr_at sat;
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct atalk_sock *at = at_sk(sk);
|
2009-11-05 07:37:26 +03:00
|
|
|
int err;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-01-23 02:21:11 +03:00
|
|
|
lock_sock(sk);
|
2009-11-05 07:37:26 +03:00
|
|
|
err = -ENOBUFS;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (sock_flag(sk, SOCK_ZAPPED))
|
|
|
|
if (atalk_autobind(sk) < 0)
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
*uaddr_len = sizeof(struct sockaddr_at);
|
2013-04-23 00:22:15 +04:00
|
|
|
memset(&sat, 0, sizeof(sat));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (peer) {
|
2009-11-05 07:37:26 +03:00
|
|
|
err = -ENOTCONN;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (sk->sk_state != TCP_ESTABLISHED)
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
sat.sat_addr.s_net = at->dest_net;
|
|
|
|
sat.sat_addr.s_node = at->dest_node;
|
|
|
|
sat.sat_port = at->dest_port;
|
|
|
|
} else {
|
|
|
|
sat.sat_addr.s_net = at->src_net;
|
|
|
|
sat.sat_addr.s_node = at->src_node;
|
|
|
|
sat.sat_port = at->src_port;
|
|
|
|
}
|
|
|
|
|
2009-11-05 07:37:26 +03:00
|
|
|
err = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
sat.sat_family = AF_APPLETALK;
|
|
|
|
memcpy(uaddr, &sat, sizeof(sat));
|
2009-11-05 07:37:26 +03:00
|
|
|
|
|
|
|
out:
|
2011-01-23 02:21:11 +03:00
|
|
|
release_sock(sk);
|
2009-11-05 07:37:26 +03:00
|
|
|
return err;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_IPDDP) || defined(CONFIG_IPDDP_MODULE)
|
|
|
|
static __inline__ int is_ip_over_ddp(struct sk_buff *skb)
|
|
|
|
{
|
2007-02-09 17:24:27 +03:00
|
|
|
return skb->data[12] == 22;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_ip_over_ddp(struct sk_buff *skb)
|
|
|
|
{
|
2007-09-17 22:56:21 +04:00
|
|
|
struct net_device *dev = __dev_get_by_name(&init_net, "ipddp0");
|
2005-04-17 02:20:36 +04:00
|
|
|
struct net_device_stats *stats;
|
|
|
|
|
|
|
|
/* This needs to be able to handle ipddp"N" devices */
|
2009-09-11 22:35:22 +04:00
|
|
|
if (!dev) {
|
|
|
|
kfree_skb(skb);
|
|
|
|
return NET_RX_DROP;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-02-09 17:24:27 +03:00
|
|
|
skb->protocol = htons(ETH_P_IP);
|
|
|
|
skb_pull(skb, 13);
|
|
|
|
skb->dev = dev;
|
2007-03-13 19:06:52 +03:00
|
|
|
skb_reset_transport_header(skb);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-11-13 10:39:10 +03:00
|
|
|
stats = netdev_priv(dev);
|
2007-02-09 17:24:27 +03:00
|
|
|
stats->rx_packets++;
|
|
|
|
stats->rx_bytes += skb->len + 13;
|
2009-09-11 22:35:22 +04:00
|
|
|
return netif_rx(skb); /* Send the SKB up to a higher place. */
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* make it easy for gcc to optimize this test out, i.e. kill the code */
|
|
|
|
#define is_ip_over_ddp(skb) 0
|
|
|
|
#define handle_ip_over_ddp(skb) 0
|
|
|
|
#endif
|
|
|
|
|
2009-09-11 22:35:22 +04:00
|
|
|
static int atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
|
|
|
|
struct ddpehdr *ddp, __u16 len_hops, int origlen)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct atalk_route *rt;
|
|
|
|
struct atalk_addr ta;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't route multicast, etc., packets, or packets sent to "this
|
2007-02-09 17:24:27 +03:00
|
|
|
* network"
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
if (skb->pkt_type != PACKET_HOST || !ddp->deh_dnet) {
|
|
|
|
/*
|
|
|
|
* FIXME:
|
|
|
|
*
|
|
|
|
* Can it ever happen that a packet is from a PPP iface and
|
|
|
|
* needs to be broadcast onto the default network?
|
|
|
|
*/
|
|
|
|
if (dev->type == ARPHRD_PPP)
|
|
|
|
printk(KERN_DEBUG "AppleTalk: didn't forward broadcast "
|
|
|
|
"packet received from PPP iface\n");
|
|
|
|
goto free_it;
|
|
|
|
}
|
|
|
|
|
|
|
|
ta.s_net = ddp->deh_dnet;
|
|
|
|
ta.s_node = ddp->deh_dnode;
|
|
|
|
|
|
|
|
/* Route the packet */
|
|
|
|
rt = atrtr_find(&ta);
|
2006-09-27 08:22:08 +04:00
|
|
|
/* increment hops count */
|
|
|
|
len_hops += 1 << 10;
|
|
|
|
if (!rt || !(len_hops & (15 << 10)))
|
2005-04-17 02:20:36 +04:00
|
|
|
goto free_it;
|
2006-09-27 08:22:08 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* FIXME: use skb->cb to be able to use shared skbs */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Route goes through another gateway, so set the target to the
|
|
|
|
* gateway instead.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (rt->flags & RTF_GATEWAY) {
|
|
|
|
ta.s_net = rt->gateway.s_net;
|
|
|
|
ta.s_node = rt->gateway.s_node;
|
|
|
|
}
|
|
|
|
|
2007-02-09 17:24:27 +03:00
|
|
|
/* Fix up skb->len field */
|
|
|
|
skb_trim(skb, min_t(unsigned int, origlen,
|
2005-04-17 02:20:36 +04:00
|
|
|
(rt->dev->hard_header_len +
|
2006-09-27 08:22:08 +04:00
|
|
|
ddp_dl->header_length + (len_hops & 1023))));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* FIXME: use skb->cb to be able to use shared skbs */
|
2006-09-27 08:22:08 +04:00
|
|
|
ddp->deh_len_hops = htons(len_hops);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the buffer onwards
|
|
|
|
*
|
|
|
|
* Now we must always be careful. If it's come from LocalTalk to
|
|
|
|
* EtherTalk it might not fit
|
|
|
|
*
|
|
|
|
* Order matters here: If a packet has to be copied to make a new
|
|
|
|
* headroom (rare hopefully) then it won't need unsharing.
|
|
|
|
*
|
|
|
|
* Note. ddp-> becomes invalid at the realloc.
|
|
|
|
*/
|
|
|
|
if (skb_headroom(skb) < 22) {
|
|
|
|
/* 22 bytes - 12 ether, 2 len, 3 802.2 5 snap */
|
|
|
|
struct sk_buff *nskb = skb_realloc_headroom(skb, 32);
|
|
|
|
kfree_skb(skb);
|
|
|
|
skb = nskb;
|
|
|
|
} else
|
|
|
|
skb = skb_unshare(skb, GFP_ATOMIC);
|
2007-02-09 17:24:27 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* If the buffer didn't vanish into the lack of space bitbucket we can
|
|
|
|
* send it.
|
|
|
|
*/
|
2009-09-11 22:35:22 +04:00
|
|
|
if (skb == NULL)
|
|
|
|
goto drop;
|
|
|
|
|
|
|
|
if (aarp_send_ddp(rt->dev, skb, &ta, NULL) == NET_XMIT_DROP)
|
|
|
|
return NET_RX_DROP;
|
2009-09-13 00:48:43 +04:00
|
|
|
return NET_RX_SUCCESS;
|
2005-04-17 02:20:36 +04:00
|
|
|
free_it:
|
|
|
|
kfree_skb(skb);
|
2009-09-11 22:35:22 +04:00
|
|
|
drop:
|
|
|
|
return NET_RX_DROP;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* atalk_rcv - Receive a packet (in skb) from device dev
|
|
|
|
* @skb - packet received
|
|
|
|
* @dev - network device where the packet comes from
|
|
|
|
* @pt - packet type
|
|
|
|
*
|
|
|
|
* Receive a packet (in skb) from device dev. This has come from the SNAP
|
2007-04-11 08:21:55 +04:00
|
|
|
* decoder, and on entry skb->transport_header is the DDP header, skb->len
|
|
|
|
* is the DDP header, skb->len is the DDP length. The physical headers
|
|
|
|
* have been extracted. PPP should probably pass frames marked as for this
|
|
|
|
* layer. [ie ARPHRD_ETHERTALK]
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
|
2005-08-10 06:34:12 +04:00
|
|
|
struct packet_type *pt, struct net_device *orig_dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct ddpehdr *ddp;
|
|
|
|
struct sock *sock;
|
|
|
|
struct atalk_iface *atif;
|
|
|
|
struct sockaddr_at tosat;
|
2007-02-09 17:24:27 +03:00
|
|
|
int origlen;
|
2006-09-27 08:22:08 +04:00
|
|
|
__u16 len_hops;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-07-20 09:34:43 +04:00
|
|
|
if (!net_eq(dev_net(dev), &init_net))
|
2009-08-07 03:21:22 +04:00
|
|
|
goto drop;
|
2007-09-17 22:53:39 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Don't mangle buffer if shared */
|
2007-02-09 17:24:27 +03:00
|
|
|
if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
|
2005-04-17 02:20:36 +04:00
|
|
|
goto out;
|
2007-02-09 17:24:27 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Size check and make sure header is contiguous */
|
|
|
|
if (!pskb_may_pull(skb, sizeof(*ddp)))
|
2009-08-07 03:21:22 +04:00
|
|
|
goto drop;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
ddp = ddp_hdr(skb);
|
|
|
|
|
2006-09-27 08:22:08 +04:00
|
|
|
len_hops = ntohs(ddp->deh_len_hops);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Trim buffer in case of stray trailing data */
|
|
|
|
origlen = skb->len;
|
2006-09-27 08:22:08 +04:00
|
|
|
skb_trim(skb, min_t(unsigned int, skb->len, len_hops & 1023));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Size check to see if ddp->deh_len was crap
|
|
|
|
* (Otherwise we'll detonate most spectacularly
|
[APPLETALK]: Fix a remotely triggerable crash
When we receive an AppleTalk frame shorter than what its header says,
we still attempt to verify its checksum, and trip on the BUG_ON() at
the end of function atalk_sum_skb() because of the length mismatch.
This has security implications because this can be triggered by simply
sending a specially crafted ethernet frame to a target victim,
effectively crashing that host. Thus this qualifies, I think, as a
remote DoS. Here is the frame I used to trigger the crash, in npg
format:
<Appletalk Killer>
{
# Ethernet header -----
XX XX XX XX XX XX # Destination MAC
00 00 00 00 00 00 # Source MAC
00 1D # Length
# LLC header -----
AA AA 03
08 00 07 80 9B # Appletalk
# Appletalk header -----
00 1B # Packet length (invalid)
00 01 # Fake checksum
00 00 00 00 # Destination and source networks
00 00 00 00 # Destination and source nodes and ports
# Payload -----
0C 0D 0E 0F 10 11 12 13
14
}
The destination MAC address must be set to those of the victim.
The severity is mitigated by two requirements:
* The target host must have the appletalk kernel module loaded. I
suspect this isn't so frequent.
* AppleTalk frames are non-IP, thus I guess they can only travel on
local networks. I am no network expert though, maybe it is possible
to somehow encapsulate AppleTalk packets over IP.
The bug has been reported back in June 2004:
http://bugzilla.kernel.org/show_bug.cgi?id=2979
But it wasn't investigated, and was closed in July 2006 as both
reporters had vanished meanwhile.
This code was new in kernel 2.6.0-test5:
http://git.kernel.org/?p=linux/kernel/git/tglx/history.git;a=commitdiff;h=7ab442d7e0a76402c12553ee256f756097cae2d2
And not modified since then, so we can assume that vanilla kernels
2.6.0-test5 and later, and distribution kernels based thereon, are
affected.
Note that I still do not know for sure what triggered the bug in the
real-world cases. The frame could have been corrupted by the kernel if
we have a bug hiding somewhere. But more likely, we are receiving the
faulty frame from the network.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-04-05 10:52:46 +04:00
|
|
|
* in the middle of atalk_checksum() or recvmsg()).
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
[APPLETALK]: Fix a remotely triggerable crash
When we receive an AppleTalk frame shorter than what its header says,
we still attempt to verify its checksum, and trip on the BUG_ON() at
the end of function atalk_sum_skb() because of the length mismatch.
This has security implications because this can be triggered by simply
sending a specially crafted ethernet frame to a target victim,
effectively crashing that host. Thus this qualifies, I think, as a
remote DoS. Here is the frame I used to trigger the crash, in npg
format:
<Appletalk Killer>
{
# Ethernet header -----
XX XX XX XX XX XX # Destination MAC
00 00 00 00 00 00 # Source MAC
00 1D # Length
# LLC header -----
AA AA 03
08 00 07 80 9B # Appletalk
# Appletalk header -----
00 1B # Packet length (invalid)
00 01 # Fake checksum
00 00 00 00 # Destination and source networks
00 00 00 00 # Destination and source nodes and ports
# Payload -----
0C 0D 0E 0F 10 11 12 13
14
}
The destination MAC address must be set to those of the victim.
The severity is mitigated by two requirements:
* The target host must have the appletalk kernel module loaded. I
suspect this isn't so frequent.
* AppleTalk frames are non-IP, thus I guess they can only travel on
local networks. I am no network expert though, maybe it is possible
to somehow encapsulate AppleTalk packets over IP.
The bug has been reported back in June 2004:
http://bugzilla.kernel.org/show_bug.cgi?id=2979
But it wasn't investigated, and was closed in July 2006 as both
reporters had vanished meanwhile.
This code was new in kernel 2.6.0-test5:
http://git.kernel.org/?p=linux/kernel/git/tglx/history.git;a=commitdiff;h=7ab442d7e0a76402c12553ee256f756097cae2d2
And not modified since then, so we can assume that vanilla kernels
2.6.0-test5 and later, and distribution kernels based thereon, are
affected.
Note that I still do not know for sure what triggered the bug in the
real-world cases. The frame could have been corrupted by the kernel if
we have a bug hiding somewhere. But more likely, we are receiving the
faulty frame from the network.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-04-05 10:52:46 +04:00
|
|
|
if (skb->len < sizeof(*ddp) || skb->len < (len_hops & 1023)) {
|
|
|
|
pr_debug("AppleTalk: dropping corrupted frame (deh_len=%u, "
|
|
|
|
"skb->len=%u)\n", len_hops & 1023, skb->len);
|
2009-08-07 03:21:22 +04:00
|
|
|
goto drop;
|
[APPLETALK]: Fix a remotely triggerable crash
When we receive an AppleTalk frame shorter than what its header says,
we still attempt to verify its checksum, and trip on the BUG_ON() at
the end of function atalk_sum_skb() because of the length mismatch.
This has security implications because this can be triggered by simply
sending a specially crafted ethernet frame to a target victim,
effectively crashing that host. Thus this qualifies, I think, as a
remote DoS. Here is the frame I used to trigger the crash, in npg
format:
<Appletalk Killer>
{
# Ethernet header -----
XX XX XX XX XX XX # Destination MAC
00 00 00 00 00 00 # Source MAC
00 1D # Length
# LLC header -----
AA AA 03
08 00 07 80 9B # Appletalk
# Appletalk header -----
00 1B # Packet length (invalid)
00 01 # Fake checksum
00 00 00 00 # Destination and source networks
00 00 00 00 # Destination and source nodes and ports
# Payload -----
0C 0D 0E 0F 10 11 12 13
14
}
The destination MAC address must be set to those of the victim.
The severity is mitigated by two requirements:
* The target host must have the appletalk kernel module loaded. I
suspect this isn't so frequent.
* AppleTalk frames are non-IP, thus I guess they can only travel on
local networks. I am no network expert though, maybe it is possible
to somehow encapsulate AppleTalk packets over IP.
The bug has been reported back in June 2004:
http://bugzilla.kernel.org/show_bug.cgi?id=2979
But it wasn't investigated, and was closed in July 2006 as both
reporters had vanished meanwhile.
This code was new in kernel 2.6.0-test5:
http://git.kernel.org/?p=linux/kernel/git/tglx/history.git;a=commitdiff;h=7ab442d7e0a76402c12553ee256f756097cae2d2
And not modified since then, so we can assume that vanilla kernels
2.6.0-test5 and later, and distribution kernels based thereon, are
affected.
Note that I still do not know for sure what triggered the bug in the
real-world cases. The frame could have been corrupted by the kernel if
we have a bug hiding somewhere. But more likely, we are receiving the
faulty frame from the network.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-04-05 10:52:46 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Any checksums. Note we don't do htons() on this == is assumed to be
|
|
|
|
* valid for net byte orders all over the networking code...
|
|
|
|
*/
|
|
|
|
if (ddp->deh_sum &&
|
2006-09-27 08:22:08 +04:00
|
|
|
atalk_checksum(skb, len_hops & 1023) != ddp->deh_sum)
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Not a valid AppleTalk frame - dustbin time */
|
2009-08-07 03:21:22 +04:00
|
|
|
goto drop;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Check the packet is aimed at us */
|
|
|
|
if (!ddp->deh_dnet) /* Net 0 is 'this network' */
|
|
|
|
atif = atalk_find_anynet(ddp->deh_dnode, dev);
|
|
|
|
else
|
|
|
|
atif = atalk_find_interface(ddp->deh_dnet, ddp->deh_dnode);
|
|
|
|
|
|
|
|
if (!atif) {
|
2005-09-28 03:11:29 +04:00
|
|
|
/* Not ours, so we route the packet via the correct
|
|
|
|
* AppleTalk iface
|
|
|
|
*/
|
2009-09-11 22:35:22 +04:00
|
|
|
return atalk_route_packet(skb, dev, ddp, len_hops, origlen);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if IP over DDP is not selected this code will be optimized out */
|
|
|
|
if (is_ip_over_ddp(skb))
|
|
|
|
return handle_ip_over_ddp(skb);
|
|
|
|
/*
|
|
|
|
* Which socket - atalk_search_socket() looks for a *full match*
|
|
|
|
* of the <net, node, port> tuple.
|
|
|
|
*/
|
|
|
|
tosat.sat_addr.s_net = ddp->deh_dnet;
|
|
|
|
tosat.sat_addr.s_node = ddp->deh_dnode;
|
|
|
|
tosat.sat_port = ddp->deh_dport;
|
|
|
|
|
|
|
|
sock = atalk_search_socket(&tosat, atif);
|
|
|
|
if (!sock) /* But not one of our sockets */
|
2009-08-07 03:21:22 +04:00
|
|
|
goto drop;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Queue packet (standard) */
|
|
|
|
skb->sk = sock;
|
|
|
|
|
|
|
|
if (sock_queue_rcv_skb(sock, skb) < 0)
|
2009-08-07 03:21:22 +04:00
|
|
|
goto drop;
|
|
|
|
|
|
|
|
return NET_RX_SUCCESS;
|
|
|
|
|
|
|
|
drop:
|
2005-04-17 02:20:36 +04:00
|
|
|
kfree_skb(skb);
|
2009-08-07 03:21:22 +04:00
|
|
|
out:
|
|
|
|
return NET_RX_DROP;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive a LocalTalk frame. We make some demands on the caller here.
|
|
|
|
* Caller must provide enough headroom on the packet to pull the short
|
|
|
|
* header and append a long one.
|
|
|
|
*/
|
|
|
|
static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
|
2005-08-10 06:34:12 +04:00
|
|
|
struct packet_type *pt, struct net_device *orig_dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-07-20 09:34:43 +04:00
|
|
|
if (!net_eq(dev_net(dev), &init_net))
|
2007-09-17 22:53:39 +04:00
|
|
|
goto freeit;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Expand any short form frames */
|
2007-03-20 01:33:04 +03:00
|
|
|
if (skb_mac_header(skb)[2] == 1) {
|
2005-04-17 02:20:36 +04:00
|
|
|
struct ddpehdr *ddp;
|
|
|
|
/* Find our address */
|
|
|
|
struct atalk_addr *ap = atalk_find_dev_addr(dev);
|
|
|
|
|
2006-09-27 08:22:08 +04:00
|
|
|
if (!ap || skb->len < sizeof(__be16) || skb->len > 1023)
|
2005-04-17 02:20:36 +04:00
|
|
|
goto freeit;
|
|
|
|
|
|
|
|
/* Don't mangle buffer if shared */
|
2007-02-09 17:24:27 +03:00
|
|
|
if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The push leaves us with a ddephdr not an shdr, and
|
|
|
|
* handily the port bytes in the right place preset.
|
|
|
|
*/
|
|
|
|
ddp = (struct ddpehdr *) skb_push(skb, sizeof(*ddp) - 4);
|
|
|
|
|
|
|
|
/* Now fill in the long header */
|
|
|
|
|
2007-02-09 17:24:27 +03:00
|
|
|
/*
|
|
|
|
* These two first. The mac overlays the new source/dest
|
|
|
|
* network information so we MUST copy these before
|
|
|
|
* we write the network numbers !
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-03-20 01:33:04 +03:00
|
|
|
ddp->deh_dnode = skb_mac_header(skb)[0]; /* From physical header */
|
|
|
|
ddp->deh_snode = skb_mac_header(skb)[1]; /* From physical header */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
ddp->deh_dnet = ap->s_net; /* Network number */
|
|
|
|
ddp->deh_snet = ap->s_net;
|
|
|
|
ddp->deh_sum = 0; /* No checksum */
|
|
|
|
/*
|
|
|
|
* Not sure about this bit...
|
|
|
|
*/
|
2006-09-27 08:22:08 +04:00
|
|
|
/* Non routable, so force a drop if we slip up later */
|
|
|
|
ddp->deh_len_hops = htons(skb->len + (DDP_MAXHOPS << 10));
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2007-03-13 19:06:52 +03:00
|
|
|
skb_reset_transport_header(skb);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-08-10 06:34:12 +04:00
|
|
|
return atalk_rcv(skb, dev, pt, orig_dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
freeit:
|
|
|
|
kfree_skb(skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct atalk_sock *at = at_sk(sk);
|
2014-01-18 01:53:15 +04:00
|
|
|
DECLARE_SOCKADDR(struct sockaddr_at *, usat, msg->msg_name);
|
2005-04-17 02:20:36 +04:00
|
|
|
int flags = msg->msg_flags;
|
|
|
|
int loopback = 0;
|
|
|
|
struct sockaddr_at local_satalk, gsat;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct net_device *dev;
|
|
|
|
struct ddpehdr *ddp;
|
|
|
|
int size;
|
|
|
|
struct atalk_route *rt;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (len > DDP_MAXSZ)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
2011-01-23 02:21:11 +03:00
|
|
|
lock_sock(sk);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (usat) {
|
2009-11-05 07:37:26 +03:00
|
|
|
err = -EBUSY;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (sock_flag(sk, SOCK_ZAPPED))
|
|
|
|
if (atalk_autobind(sk) < 0)
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-11-05 07:37:26 +03:00
|
|
|
err = -EINVAL;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (msg->msg_namelen < sizeof(*usat) ||
|
|
|
|
usat->sat_family != AF_APPLETALK)
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-11-05 07:37:26 +03:00
|
|
|
err = -EPERM;
|
2009-03-27 10:27:18 +03:00
|
|
|
/* netatalk didn't implement this check */
|
2005-04-17 02:20:36 +04:00
|
|
|
if (usat->sat_addr.s_node == ATADDR_BCAST &&
|
|
|
|
!sock_flag(sk, SOCK_BROADCAST)) {
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
} else {
|
2009-11-05 07:37:26 +03:00
|
|
|
err = -ENOTCONN;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (sk->sk_state != TCP_ESTABLISHED)
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
usat = &local_satalk;
|
|
|
|
usat->sat_family = AF_APPLETALK;
|
|
|
|
usat->sat_port = at->dest_port;
|
|
|
|
usat->sat_addr.s_node = at->dest_node;
|
|
|
|
usat->sat_addr.s_net = at->dest_net;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build a packet */
|
|
|
|
SOCK_DEBUG(sk, "SK %p: Got address.\n", sk);
|
|
|
|
|
|
|
|
/* For headers */
|
|
|
|
size = sizeof(struct ddpehdr) + len + ddp_dl->header_length;
|
|
|
|
|
|
|
|
if (usat->sat_addr.s_net || usat->sat_addr.s_node == ATADDR_ANYNODE) {
|
|
|
|
rt = atrtr_find(&usat->sat_addr);
|
|
|
|
} else {
|
|
|
|
struct atalk_addr at_hint;
|
|
|
|
|
|
|
|
at_hint.s_node = 0;
|
|
|
|
at_hint.s_net = at->src_net;
|
|
|
|
|
|
|
|
rt = atrtr_find(&at_hint);
|
|
|
|
}
|
2009-11-05 07:37:26 +03:00
|
|
|
err = ENETUNREACH;
|
2005-09-28 03:11:29 +04:00
|
|
|
if (!rt)
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2005-09-28 03:11:29 +04:00
|
|
|
|
|
|
|
dev = rt->dev;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
SOCK_DEBUG(sk, "SK %p: Size needed %d, device %s\n",
|
|
|
|
sk, size, dev->name);
|
|
|
|
|
|
|
|
size += dev->hard_header_len;
|
2011-01-23 02:21:11 +03:00
|
|
|
release_sock(sk);
|
2005-04-17 02:20:36 +04:00
|
|
|
skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err);
|
2011-01-23 02:21:11 +03:00
|
|
|
lock_sock(sk);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!skb)
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2007-02-09 17:24:27 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
skb->sk = sk;
|
|
|
|
skb_reserve(skb, ddp_dl->header_length);
|
|
|
|
skb_reserve(skb, dev->hard_header_len);
|
|
|
|
skb->dev = dev;
|
|
|
|
|
|
|
|
SOCK_DEBUG(sk, "SK %p: Begin build.\n", sk);
|
|
|
|
|
|
|
|
ddp = (struct ddpehdr *)skb_put(skb, sizeof(struct ddpehdr));
|
2006-09-27 08:22:08 +04:00
|
|
|
ddp->deh_len_hops = htons(len + sizeof(*ddp));
|
2005-04-17 02:20:36 +04:00
|
|
|
ddp->deh_dnet = usat->sat_addr.s_net;
|
|
|
|
ddp->deh_snet = at->src_net;
|
|
|
|
ddp->deh_dnode = usat->sat_addr.s_node;
|
|
|
|
ddp->deh_snode = at->src_node;
|
|
|
|
ddp->deh_dport = usat->sat_port;
|
|
|
|
ddp->deh_sport = at->src_port;
|
|
|
|
|
|
|
|
SOCK_DEBUG(sk, "SK %p: Copy user data (%Zd bytes).\n", sk, len);
|
|
|
|
|
|
|
|
err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
|
|
|
|
if (err) {
|
|
|
|
kfree_skb(skb);
|
2009-11-05 07:37:26 +03:00
|
|
|
err = -EFAULT;
|
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sk->sk_no_check == 1)
|
|
|
|
ddp->deh_sum = 0;
|
|
|
|
else
|
|
|
|
ddp->deh_sum = atalk_checksum(skb, len + sizeof(*ddp));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loopback broadcast packets to non gateway targets (ie routes
|
|
|
|
* to group we are in)
|
|
|
|
*/
|
|
|
|
if (ddp->deh_dnode == ATADDR_BCAST &&
|
|
|
|
!(rt->flags & RTF_GATEWAY) && !(dev->flags & IFF_LOOPBACK)) {
|
|
|
|
struct sk_buff *skb2 = skb_copy(skb, GFP_KERNEL);
|
|
|
|
|
|
|
|
if (skb2) {
|
|
|
|
loopback = 1;
|
|
|
|
SOCK_DEBUG(sk, "SK %p: send out(copy).\n", sk);
|
2009-09-11 22:35:22 +04:00
|
|
|
/*
|
|
|
|
* If it fails it is queued/sent above in the aarp queue
|
|
|
|
*/
|
|
|
|
aarp_send_ddp(dev, skb2, &usat->sat_addr, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->flags & IFF_LOOPBACK || loopback) {
|
|
|
|
SOCK_DEBUG(sk, "SK %p: Loop back.\n", sk);
|
|
|
|
/* loop back */
|
|
|
|
skb_orphan(skb);
|
2005-09-28 03:11:29 +04:00
|
|
|
if (ddp->deh_dnode == ATADDR_BCAST) {
|
|
|
|
struct atalk_addr at_lo;
|
|
|
|
|
|
|
|
at_lo.s_node = 0;
|
|
|
|
at_lo.s_net = 0;
|
|
|
|
|
|
|
|
rt = atrtr_find(&at_lo);
|
|
|
|
if (!rt) {
|
|
|
|
kfree_skb(skb);
|
2009-11-05 07:37:26 +03:00
|
|
|
err = -ENETUNREACH;
|
|
|
|
goto out;
|
2005-09-28 03:11:29 +04:00
|
|
|
}
|
|
|
|
dev = rt->dev;
|
|
|
|
skb->dev = dev;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
ddp_dl->request(ddp_dl, skb, dev->dev_addr);
|
|
|
|
} else {
|
|
|
|
SOCK_DEBUG(sk, "SK %p: send out.\n", sk);
|
|
|
|
if (rt->flags & RTF_GATEWAY) {
|
|
|
|
gsat.sat_addr = rt->gateway;
|
|
|
|
usat = &gsat;
|
|
|
|
}
|
|
|
|
|
2009-09-11 22:35:22 +04:00
|
|
|
/*
|
|
|
|
* If it fails it is queued/sent above in the aarp queue
|
|
|
|
*/
|
|
|
|
aarp_send_ddp(dev, skb, &usat->sat_addr, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
SOCK_DEBUG(sk, "SK %p: Done write (%Zd).\n", sk, len);
|
|
|
|
|
2009-11-05 07:37:26 +03:00
|
|
|
out:
|
2011-01-23 02:21:11 +03:00
|
|
|
release_sock(sk);
|
2009-11-05 07:37:26 +03:00
|
|
|
return err ? : len;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
|
|
|
|
size_t size, int flags)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct ddpehdr *ddp;
|
|
|
|
int copied = 0;
|
2006-09-27 08:22:08 +04:00
|
|
|
int offset = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
int err = 0;
|
2009-11-05 07:37:26 +03:00
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
|
2005-04-17 02:20:36 +04:00
|
|
|
flags & MSG_DONTWAIT, &err);
|
2011-01-23 02:21:11 +03:00
|
|
|
lock_sock(sk);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!skb)
|
2009-11-05 07:37:26 +03:00
|
|
|
goto out;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* FIXME: use skb->cb to be able to use shared skbs */
|
|
|
|
ddp = ddp_hdr(skb);
|
2006-09-27 08:22:08 +04:00
|
|
|
copied = ntohs(ddp->deh_len_hops) & 1023;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-09-27 08:22:08 +04:00
|
|
|
if (sk->sk_type != SOCK_RAW) {
|
|
|
|
offset = sizeof(*ddp);
|
|
|
|
copied -= offset;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-09-27 08:22:08 +04:00
|
|
|
if (copied > size) {
|
|
|
|
copied = size;
|
|
|
|
msg->msg_flags |= MSG_TRUNC;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2006-09-27 08:22:08 +04:00
|
|
|
err = skb_copy_datagram_iovec(skb, offset, msg->msg_iov, copied);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-11-21 06:14:22 +04:00
|
|
|
if (!err && msg->msg_name) {
|
2014-01-18 01:53:15 +04:00
|
|
|
DECLARE_SOCKADDR(struct sockaddr_at *, sat, msg->msg_name);
|
2013-11-21 06:14:22 +04:00
|
|
|
sat->sat_family = AF_APPLETALK;
|
|
|
|
sat->sat_port = ddp->deh_sport;
|
|
|
|
sat->sat_addr.s_node = ddp->deh_snode;
|
|
|
|
sat->sat_addr.s_net = ddp->deh_snet;
|
|
|
|
msg->msg_namelen = sizeof(*sat);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
skb_free_datagram(sk, skb); /* Free the datagram. */
|
2009-11-05 07:37:26 +03:00
|
|
|
|
|
|
|
out:
|
2011-01-23 02:21:11 +03:00
|
|
|
release_sock(sk);
|
2005-04-17 02:20:36 +04:00
|
|
|
return err ? : copied;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AppleTalk ioctl calls.
|
|
|
|
*/
|
|
|
|
static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2006-01-04 01:18:33 +03:00
|
|
|
int rc = -ENOIOCTLCMD;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
/* Protocol layer */
|
|
|
|
case TIOCOUTQ: {
|
2009-06-18 06:05:41 +04:00
|
|
|
long amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (amount < 0)
|
|
|
|
amount = 0;
|
|
|
|
rc = put_user(amount, (int __user *)argp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TIOCINQ: {
|
|
|
|
/*
|
|
|
|
* These two are safe on a single CPU system as only
|
|
|
|
* user tasks fiddle here
|
|
|
|
*/
|
|
|
|
struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
|
|
|
|
long amount = 0;
|
|
|
|
|
|
|
|
if (skb)
|
|
|
|
amount = skb->len - sizeof(struct ddpehdr);
|
|
|
|
rc = put_user(amount, (int __user *)argp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SIOCGSTAMP:
|
|
|
|
rc = sock_get_timestamp(sk, argp);
|
|
|
|
break;
|
2007-03-19 03:33:16 +03:00
|
|
|
case SIOCGSTAMPNS:
|
|
|
|
rc = sock_get_timestampns(sk, argp);
|
|
|
|
break;
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Routing */
|
|
|
|
case SIOCADDRT:
|
|
|
|
case SIOCDELRT:
|
|
|
|
rc = -EPERM;
|
|
|
|
if (capable(CAP_NET_ADMIN))
|
|
|
|
rc = atrtr_ioctl(cmd, argp);
|
|
|
|
break;
|
|
|
|
/* Interface */
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCGIFBRDADDR:
|
|
|
|
case SIOCATALKDIFADDR:
|
|
|
|
case SIOCDIFADDR:
|
|
|
|
case SIOCSARP: /* proxy AARP */
|
|
|
|
case SIOCDARP: /* proxy AARP */
|
|
|
|
rtnl_lock();
|
|
|
|
rc = atif_ioctl(cmd, argp);
|
|
|
|
rtnl_unlock();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2006-03-28 11:39:31 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
static int atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
/*
|
2009-11-06 11:09:06 +03:00
|
|
|
* SIOCATALKDIFADDR is a SIOCPROTOPRIVATE ioctl number, so we
|
|
|
|
* cannot handle it in common code. The data we access if ifreq
|
|
|
|
* here is compatible, so we can simply call the native
|
|
|
|
* handler.
|
2006-03-28 11:39:31 +04:00
|
|
|
*/
|
2009-11-06 11:09:06 +03:00
|
|
|
if (cmd == SIOCATALKDIFADDR)
|
|
|
|
return atalk_ioctl(sock, cmd, (unsigned long)compat_ptr(arg));
|
|
|
|
|
2006-03-28 11:39:31 +04:00
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-10-05 09:58:39 +04:00
|
|
|
static const struct net_proto_family atalk_family_ops = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.family = PF_APPLETALK,
|
|
|
|
.create = atalk_create,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2009-11-05 07:37:26 +03:00
|
|
|
static const struct proto_ops atalk_dgram_ops = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.family = PF_APPLETALK,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.release = atalk_release,
|
|
|
|
.bind = atalk_bind,
|
|
|
|
.connect = atalk_connect,
|
|
|
|
.socketpair = sock_no_socketpair,
|
|
|
|
.accept = sock_no_accept,
|
|
|
|
.getname = atalk_getname,
|
2011-01-23 02:21:11 +03:00
|
|
|
.poll = datagram_poll,
|
2005-04-17 02:20:36 +04:00
|
|
|
.ioctl = atalk_ioctl,
|
2006-03-28 11:39:31 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
.compat_ioctl = atalk_compat_ioctl,
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
.listen = sock_no_listen,
|
|
|
|
.shutdown = sock_no_shutdown,
|
|
|
|
.setsockopt = sock_no_setsockopt,
|
|
|
|
.getsockopt = sock_no_getsockopt,
|
|
|
|
.sendmsg = atalk_sendmsg,
|
|
|
|
.recvmsg = atalk_recvmsg,
|
|
|
|
.mmap = sock_no_mmap,
|
|
|
|
.sendpage = sock_no_sendpage,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct notifier_block ddp_notifier = {
|
|
|
|
.notifier_call = ddp_device_event,
|
|
|
|
};
|
|
|
|
|
2009-03-09 11:18:29 +03:00
|
|
|
static struct packet_type ltalk_packet_type __read_mostly = {
|
2009-02-01 11:45:17 +03:00
|
|
|
.type = cpu_to_be16(ETH_P_LOCALTALK),
|
2005-04-17 02:20:36 +04:00
|
|
|
.func = ltalk_rcv,
|
|
|
|
};
|
|
|
|
|
2009-03-09 11:18:29 +03:00
|
|
|
static struct packet_type ppptalk_packet_type __read_mostly = {
|
2009-02-01 11:45:17 +03:00
|
|
|
.type = cpu_to_be16(ETH_P_PPPTALK),
|
2005-04-17 02:20:36 +04:00
|
|
|
.func = atalk_rcv,
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned char ddp_snap_id[] = { 0x08, 0x00, 0x07, 0x80, 0x9B };
|
|
|
|
|
|
|
|
/* Export symbols for use by drivers when AppleTalk is a module */
|
|
|
|
EXPORT_SYMBOL(atrtr_get_dev);
|
|
|
|
EXPORT_SYMBOL(atalk_find_dev_addr);
|
|
|
|
|
2009-02-25 13:31:59 +03:00
|
|
|
static const char atalk_err_snap[] __initconst =
|
2005-04-17 02:20:36 +04:00
|
|
|
KERN_CRIT "Unable to register DDP with SNAP.\n";
|
|
|
|
|
|
|
|
/* Called by proto.c on kernel start up */
|
|
|
|
static int __init atalk_init(void)
|
|
|
|
{
|
|
|
|
int rc = proto_register(&ddp_proto, 0);
|
|
|
|
|
|
|
|
if (rc != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
(void)sock_register(&atalk_family_ops);
|
|
|
|
ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
|
|
|
|
if (!ddp_dl)
|
|
|
|
printk(atalk_err_snap);
|
|
|
|
|
|
|
|
dev_add_pack(<alk_packet_type);
|
|
|
|
dev_add_pack(&ppptalk_packet_type);
|
|
|
|
|
|
|
|
register_netdevice_notifier(&ddp_notifier);
|
|
|
|
aarp_proto_init();
|
|
|
|
atalk_proc_init();
|
|
|
|
atalk_register_sysctl();
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
module_init(atalk_init);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No explicit module reference count manipulation is needed in the
|
|
|
|
* protocol. Socket layer sets module reference count for us
|
|
|
|
* and interfaces reference counting is done
|
|
|
|
* by the network device layer.
|
|
|
|
*
|
|
|
|
* Ergo, before the AppleTalk module can be removed, all AppleTalk
|
|
|
|
* sockets be closed from user space.
|
|
|
|
*/
|
|
|
|
static void __exit atalk_exit(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SYSCTL
|
|
|
|
atalk_unregister_sysctl();
|
|
|
|
#endif /* CONFIG_SYSCTL */
|
|
|
|
atalk_proc_exit();
|
|
|
|
aarp_cleanup_module(); /* General aarp clean-up. */
|
|
|
|
unregister_netdevice_notifier(&ddp_notifier);
|
|
|
|
dev_remove_pack(<alk_packet_type);
|
|
|
|
dev_remove_pack(&ppptalk_packet_type);
|
|
|
|
unregister_snap_client(ddp_dl);
|
|
|
|
sock_unregister(PF_APPLETALK);
|
|
|
|
proto_unregister(&ddp_proto);
|
|
|
|
}
|
|
|
|
module_exit(atalk_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-10-14 06:01:08 +04:00
|
|
|
MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
|
2005-04-17 02:20:36 +04:00
|
|
|
MODULE_DESCRIPTION("AppleTalk 0.20\n");
|
|
|
|
MODULE_ALIAS_NETPROTO(PF_APPLETALK);
|