Commit f7c8ad70 authored by Ralf Bächle's avatar Ralf Bächle

Implement locking of internal data for NET/ROM and ROSE.

Do socket locking for AX.25
Delete trailing whitespace.
Exchange prehistoric changelogs in headers with GPL + copyright header.
Reformat some of the NET/ROM and ROSE code to 80 columns.
parent e90d44a8
...@@ -207,7 +207,7 @@ extern spinlock_t ax25_list_lock; ...@@ -207,7 +207,7 @@ extern spinlock_t ax25_list_lock;
extern void ax25_free_cb(ax25_cb *); extern void ax25_free_cb(ax25_cb *);
extern void ax25_insert_socket(ax25_cb *); extern void ax25_insert_socket(ax25_cb *);
struct sock *ax25_find_listener(ax25_address *, int, struct net_device *, int); struct sock *ax25_find_listener(ax25_address *, int, struct net_device *, int);
struct sock *ax25_find_socket(ax25_address *, ax25_address *, int); struct sock *ax25_get_socket(ax25_address *, ax25_address *, int);
extern ax25_cb *ax25_find_cb(ax25_address *, ax25_address *, ax25_digi *, struct net_device *); extern ax25_cb *ax25_find_cb(ax25_address *, ax25_address *, ax25_digi *, struct net_device *);
extern struct sock *ax25_addr_match(ax25_address *); extern struct sock *ax25_addr_match(ax25_address *);
extern void ax25_send_to_raw(struct sock *, struct sk_buff *, int); extern void ax25_send_to_raw(struct sock *, struct sk_buff *, int);
......
...@@ -9,6 +9,26 @@ af_ax25.c:ax25_connect: ...@@ -9,6 +9,26 @@ af_ax25.c:ax25_connect:
return sock_error(sk); /* Always set at this point */ return sock_error(sk); /* Always set at this point */
} }
Do the ax25_list_lock, ax25_uid_lock, ax25_route_lock, protocol_list_lock, Do the ax25_list_lock, ax25_dev_lock, linkfail_lockreally, ax25_frag_lock and
ax25_dev_lock, linkfail_lockreally, ax25_frag_lock and listen_lock have to listen_lock have to be interrupt safe?
be interrupt safe?
A device might be deleted after lookup in the SIOCADDRT ioctl but before it's
being used.
Routes to a device begin taken down might be deleted by ax25_rt_device_down
but added by somebody else before the device has been deleted.
Introduce a clear locking strategy. What I've put there is simply an evil
hack to get the code to survive.
Massive amounts of lock_kernel / unlock_kernel are just a temporary solution to
get around the removal of SOCKOPS_WRAP. A serious locking strategy has to be
implemented.
The ax25_rt_find_route synopsys is pervert but I somehow had to deal with
the race caused by the static variable in it's previous implementation.
Implement proper socket locking in netrom and rose.
Check socket locking when ax25_rcv is sending to raw sockets. In particular
ax25_send_to_raw() seems fishy. Heck - ax25_rcv is fishy.
/* /*
* AX.25 release 038 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
* * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* This module: * Copyright (C) Darryl Miles G7LED (dlm@g7led.demon.co.uk)
* This module is free software; you can redistribute it and/or * Copyright (C) Steven Whitehouse GW7RRM (stevew@acm.org)
* modify it under the terms of the GNU General Public License * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
* as published by the Free Software Foundation; either version * Copyright (C) Hans-Joachim Hetscher DD8NE (dd8ne@bnv-bamberg.de)
* 2 of the License, or (at your option) any later version. * Copyright (C) Hans Alblas PE1AYX (hans@esrac.ele.tue.nl)
* * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
* History
* AX.25 006 Alan(GW4PTS) Nearly died of shock - it's working 8-)
* AX.25 007 Alan(GW4PTS) Removed the silliest bugs
* AX.25 008 Alan(GW4PTS) Cleaned up, fixed a few state machine problems, added callbacks
* AX.25 009 Alan(GW4PTS) Emergency patch kit to fix memory corruption
* AX.25 010 Alan(GW4PTS) Added RAW sockets/Digipeat.
* AX.25 011 Alan(GW4PTS) RAW socket and datagram fixes (thanks) - Raw sendto now gets PID right
* datagram sendto uses correct target address.
* AX.25 012 Alan(GW4PTS) Correct incoming connection handling, send DM to failed connects.
* Use skb->data not skb+1. Support sk->priority correctly.
* Correct receive on SOCK_DGRAM.
* AX.25 013 Alan(GW4PTS) Send DM to all unknown frames, missing initialiser fixed
* Leave spare SSID bits set (DAMA etc) - thanks for bug report,
* removed device registration (it's not used or needed). Clean up for
* gcc 2.5.8. PID to AX25_P_
* AX.25 014 Alan(GW4PTS) Cleanup and NET3 merge
* AX.25 015 Alan(GW4PTS) Internal test version.
* AX.25 016 Alan(GW4PTS) Semi Internal version for PI card
* work.
* AX.25 017 Alan(GW4PTS) Fixed some small bugs reported by
* G4KLX
* AX.25 018 Alan(GW4PTS) Fixed a small error in SOCK_DGRAM
* AX.25 019 Alan(GW4PTS) Clean ups for the non INET kernel and device ioctls in AX.25
* AX.25 020 Jonathan(G4KLX) /proc support and other changes.
* AX.25 021 Alan(GW4PTS) Added AX25_T1, AX25_N2, AX25_T3 as requested.
* AX.25 022 Jonathan(G4KLX) More work on the ax25 auto router and /proc improved (again)!
* Alan(GW4PTS) Added TIOCINQ/OUTQ
* AX.25 023 Alan(GW4PTS) Fixed shutdown bug
* AX.25 023 Alan(GW4PTS) Linus changed timers
* AX.25 024 Alan(GW4PTS) Small bug fixes
* AX.25 025 Alan(GW4PTS) More fixes, Linux 1.1.51 compatibility stuff, timers again!
* AX.25 026 Alan(GW4PTS) Small state fix.
* AX.25 027 Alan(GW4PTS) Socket close crash fixes.
* AX.25 028 Alan(GW4PTS) Callsign control including settings per uid.
* Small bug fixes.
* Protocol set by sockets only.
* Small changes to allow for start of NET/ROM layer.
* AX.25 028a Jonathan(G4KLX) Changes to state machine.
* AX.25 028b Jonathan(G4KLX) Extracted ax25 control block
* from sock structure.
* AX.25 029 Alan(GW4PTS) Combined 028b and some KA9Q code
* Jonathan(G4KLX) and removed all the old Berkeley, added IP mode registration.
* Darryl(G7LED) stuff. Cross-port digipeating. Minor fixes and enhancements.
* Alan(GW4PTS) Missed suser() on axassociate checks
* AX.25 030 Alan(GW4PTS) Added variable length headers.
* Jonathan(G4KLX) Added BPQ Ethernet interface.
* Steven(GW7RRM) Added digi-peating control ioctl.
* Added extended AX.25 support.
* Added AX.25 frame segmentation.
* Darryl(G7LED) Changed connect(), recvfrom(), sendto() sockaddr/addrlen to
* fall inline with bind() and new policy.
* Moved digipeating ctl to new ax25_dev structs.
* Fixed ax25_release(), set TCP_CLOSE, wakeup app
* context, THEN make the sock dead.
* Alan(GW4PTS) Cleaned up for single recvmsg methods.
* Alan(GW4PTS) Fixed not clearing error on connect failure.
* AX.25 031 Jonathan(G4KLX) Added binding to any device.
* Joerg(DL1BKE) Added DAMA support, fixed (?) digipeating, fixed buffer locking
* for "virtual connect" mode... Result: Probably the
* "Most Buggiest Code You've Ever Seen" (TM)
* HaJo(DD8NE) Implementation of a T5 (idle) timer
* Joerg(DL1BKE) Renamed T5 to IDLE and changed behaviour:
* the timer gets reloaded on every received or transmitted
* I frame for IP or NETROM. The idle timer is not active
* on "vanilla AX.25" connections. Furthermore added PACLEN
* to provide AX.25-layer based fragmentation (like WAMPES)
* AX.25 032 Joerg(DL1BKE) Fixed DAMA timeout error.
* ax25_send_frame() limits the number of enqueued
* datagrams per socket.
* AX.25 033 Jonathan(G4KLX) Removed auto-router.
* Hans(PE1AYX) Converted to Module.
* Joerg(DL1BKE) Moved BPQ Ethernet to separate driver.
* AX.25 034 Jonathan(G4KLX) 2.1 changes
* Alan(GW4PTS) Small POSIXisations
* AX.25 035 Alan(GW4PTS) Started fixing to the new
* format.
* Hans(PE1AYX) Fixed interface to IP layer.
* Alan(GW4PTS) Added asynchronous support.
* Frederic(F1OAT) Support for pseudo-digipeating.
* Jonathan(G4KLX) Support for packet forwarding.
* AX.25 036 Jonathan(G4KLX) Major restructuring.
* Joerg(DL1BKE) Fixed DAMA Slave.
* Jonathan(G4KLX) Fix wildcard listen parameter setting.
* AX.25 037 Jonathan(G4KLX) New timer architecture.
* AX.25 038 Matthias(DG2FEF) Small fixes to the syscall interface to make kernel
* independent of AX25_MAX_DIGIS used by applications.
* Tomi(OH2BNS) Fixed ax25_getname().
* Joerg(DL1BKE) Starting to phase out the support for full_sockaddr_ax25
* with only 6 digipeaters and sockaddr_ax25 in ax25_bind(),
* ax25_connect() and ax25_sendmsg()
* Joerg(DL1BKE) Added support for SO_BINDTODEVICE
* Arnaldo C. Melo s/suser/capable(CAP_NET_ADMIN)/, some more cleanups
* Michal Ostrowski Module initialization cleanup.
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/errno.h> #include <linux/errno.h>
...@@ -177,7 +86,6 @@ static void ax25_remove_socket(ax25_cb *ax25) ...@@ -177,7 +86,6 @@ static void ax25_remove_socket(ax25_cb *ax25)
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&ax25_list_lock, flags); spin_lock_irqsave(&ax25_list_lock, flags);
if ((s = ax25_list) == ax25) { if ((s = ax25_list) == ax25) {
ax25_list = s->next; ax25_list = s->next;
spin_unlock_irqrestore(&ax25_list_lock, flags); spin_unlock_irqrestore(&ax25_list_lock, flags);
...@@ -193,7 +101,6 @@ static void ax25_remove_socket(ax25_cb *ax25) ...@@ -193,7 +101,6 @@ static void ax25_remove_socket(ax25_cb *ax25)
s = s->next; s = s->next;
} }
spin_unlock_irqrestore(&ax25_list_lock, flags); spin_unlock_irqrestore(&ax25_list_lock, flags);
} }
...@@ -222,7 +129,7 @@ static void ax25_kill_by_device(struct net_device *dev) ...@@ -222,7 +129,7 @@ static void ax25_kill_by_device(struct net_device *dev)
/* /*
* Handle device status changes. * Handle device status changes.
*/ */
static int ax25_device_event(struct notifier_block *this,unsigned long event, static int ax25_device_event(struct notifier_block *this, unsigned long event,
void *ptr) void *ptr)
{ {
struct net_device *dev = (struct net_device *)ptr; struct net_device *dev = (struct net_device *)ptr;
...@@ -291,20 +198,23 @@ struct sock *ax25_find_listener(ax25_address *addr, int digi, ...@@ -291,20 +198,23 @@ struct sock *ax25_find_listener(ax25_address *addr, int digi,
/* /*
* Find an AX.25 socket given both ends. * Find an AX.25 socket given both ends.
*/ */
struct sock *ax25_find_socket(ax25_address *my_addr, ax25_address *dest_addr, struct sock *ax25_get_socket(ax25_address *my_addr, ax25_address *dest_addr,
int type) int type)
{ {
ax25_cb *s; struct sock *sk = NULL;
unsigned long flags; unsigned long flags;
ax25_cb *s;
spin_lock_irqsave(&ax25_list_lock, flags); spin_lock_irqsave(&ax25_list_lock, flags);
for (s = ax25_list; s != NULL; s = s->next) { for (s = ax25_list; s != NULL; s = s->next) {
if (s->sk != NULL && ax25cmp(&s->source_addr, my_addr) == 0 && ax25cmp(&s->dest_addr, dest_addr) == 0 && s->sk->type == type) { if (s->sk != NULL && ax25cmp(&s->source_addr, my_addr) == 0 && ax25cmp(&s->dest_addr, dest_addr) == 0 && s->sk->type == type) {
spin_unlock_irqrestore(&ax25_list_lock, flags); sk = s->sk;
lock_sock(sk);
return s->sk; break;
} }
} }
out:
spin_unlock_irqrestore(&ax25_list_lock, flags); spin_unlock_irqrestore(&ax25_list_lock, flags);
return NULL; return NULL;
...@@ -352,18 +262,21 @@ ax25_cb *ax25_find_cb(ax25_address *src_addr, ax25_address *dest_addr, ...@@ -352,18 +262,21 @@ ax25_cb *ax25_find_cb(ax25_address *src_addr, ax25_address *dest_addr,
struct sock *ax25_addr_match(ax25_address *addr) struct sock *ax25_addr_match(ax25_address *addr)
{ {
unsigned long flags; unsigned long flags;
struct sock *sk = NULL;
ax25_cb *s; ax25_cb *s;
spin_lock_irqsave(&ax25_list_lock, flags); spin_lock_irqsave(&ax25_list_lock, flags);
for (s = ax25_list; s != NULL; s = s->next) { for (s = ax25_list; s != NULL; s = s->next) {
if (s->sk != NULL && ax25cmp(&s->source_addr, addr) == 0 && s->sk->type == SOCK_RAW) { if (s->sk != NULL && ax25cmp(&s->source_addr, addr) == 0 &&
spin_unlock_irqrestore(&ax25_list_lock, flags); s->sk->type == SOCK_RAW) {
return s->sk; sk = s->sk;
lock_sock(sk);
break;
} }
} }
spin_unlock_irqrestore(&ax25_list_lock, flags); spin_unlock_irqrestore(&ax25_list_lock, flags);
return NULL; return sk;
} }
void ax25_send_to_raw(struct sock *sk, struct sk_buff *skb, int proto) void ax25_send_to_raw(struct sock *sk, struct sk_buff *skb, int proto)
...@@ -409,7 +322,7 @@ void ax25_destroy_socket(ax25_cb *ax25) ...@@ -409,7 +322,7 @@ void ax25_destroy_socket(ax25_cb *ax25)
struct sk_buff *skb; struct sk_buff *skb;
unsigned long flags; unsigned long flags;
save_flags(flags); cli(); ax25_remove_socket(ax25);
ax25_stop_heartbeat(ax25); ax25_stop_heartbeat(ax25);
ax25_stop_t1timer(ax25); ax25_stop_t1timer(ax25);
...@@ -417,15 +330,17 @@ void ax25_destroy_socket(ax25_cb *ax25) ...@@ -417,15 +330,17 @@ void ax25_destroy_socket(ax25_cb *ax25)
ax25_stop_t3timer(ax25); ax25_stop_t3timer(ax25);
ax25_stop_idletimer(ax25); ax25_stop_idletimer(ax25);
ax25_remove_socket(ax25);
ax25_clear_queues(ax25); /* Flush the queues */ ax25_clear_queues(ax25); /* Flush the queues */
if (ax25->sk != NULL) { if (ax25->sk != NULL) {
while ((skb = skb_dequeue(&ax25->sk->receive_queue)) != NULL) { while ((skb = skb_dequeue(&ax25->sk->receive_queue)) != NULL) {
if (skb->sk != ax25->sk) { /* A pending connection */ if (skb->sk != ax25->sk) {
/* A pending connection */
ax25_cb *sax25 = ax25_sk(skb->sk); ax25_cb *sax25 = ax25_sk(skb->sk);
skb->sk->dead = 1; /* Queue the unaccepted socket for death */ /* Queue the unaccepted socket for death */
skb->sk->dead = 1;
ax25_start_heartbeat(sax25); ax25_start_heartbeat(sax25);
sax25->state = AX25_STATE_0; sax25->state = AX25_STATE_0;
} }
...@@ -449,8 +364,6 @@ void ax25_destroy_socket(ax25_cb *ax25) ...@@ -449,8 +364,6 @@ void ax25_destroy_socket(ax25_cb *ax25)
} else { } else {
ax25_free_cb(ax25); ax25_free_cb(ax25);
} }
restore_flags(flags);
} }
/* /*
...@@ -648,7 +561,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname, ...@@ -648,7 +561,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
if (get_user(opt, (int *)optval)) if (get_user(opt, (int *)optval))
return -EFAULT; return -EFAULT;
lock_kernel(); lock_sock(sk);
ax25 = ax25_sk(sk); ax25 = ax25_sk(sk);
switch (optname) { switch (optname) {
...@@ -763,7 +676,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname, ...@@ -763,7 +676,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
default: default:
res = -ENOPROTOOPT; res = -ENOPROTOOPT;
} }
unlock_kernel(); release_sock(sk);
return res; return res;
} }
...@@ -791,7 +704,7 @@ static int ax25_getsockopt(struct socket *sock, int level, int optname, ...@@ -791,7 +704,7 @@ static int ax25_getsockopt(struct socket *sock, int level, int optname,
valptr = (void *) &val; valptr = (void *) &val;
length = min_t(unsigned int, maxlen, sizeof(int)); length = min_t(unsigned int, maxlen, sizeof(int));
lock_kernel(); lock_sock(sk);
ax25 = ax25_sk(sk); ax25 = ax25_sk(sk);
switch (optname) { switch (optname) {
...@@ -855,10 +768,10 @@ static int ax25_getsockopt(struct socket *sock, int level, int optname, ...@@ -855,10 +768,10 @@ static int ax25_getsockopt(struct socket *sock, int level, int optname,
break; break;
default: default:
unlock_kernel(); release_sock(sk);
return -ENOPROTOOPT; return -ENOPROTOOPT;
} }
unlock_kernel(); release_sock(sk);
if (put_user(length, optlen)) if (put_user(length, optlen))
return -EFAULT; return -EFAULT;
...@@ -869,17 +782,20 @@ static int ax25_getsockopt(struct socket *sock, int level, int optname, ...@@ -869,17 +782,20 @@ static int ax25_getsockopt(struct socket *sock, int level, int optname,
static int ax25_listen(struct socket *sock, int backlog) static int ax25_listen(struct socket *sock, int backlog)
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
int res = 0;
lock_kernel(); lock_sock(sk);
if (sk->type == SOCK_SEQPACKET && sk->state != TCP_LISTEN) { if (sk->type == SOCK_SEQPACKET && sk->state != TCP_LISTEN) {
sk->max_ack_backlog = backlog; sk->max_ack_backlog = backlog;
sk->state = TCP_LISTEN; sk->state = TCP_LISTEN;
unlock_kernel(); goto out;
return 0;
} }
unlock_kernel(); res = -EOPNOTSUPP;
return -EOPNOTSUPP; out:
release_sock(sk);
return res;
} }
int ax25_create(struct socket *sock, int protocol) int ax25_create(struct socket *sock, int protocol)
...@@ -1028,12 +944,10 @@ static int ax25_release(struct socket *sock) ...@@ -1028,12 +944,10 @@ static int ax25_release(struct socket *sock)
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
ax25_cb *ax25; ax25_cb *ax25;
lock_kernel(); if (sk == NULL)
if (sk == NULL) {
unlock_kernel();
return 0; return 0;
}
lock_sock(sk);
ax25 = ax25_sk(sk); ax25 = ax25_sk(sk);
if (sk->type == SOCK_SEQPACKET) { if (sk->type == SOCK_SEQPACKET) {
...@@ -1054,6 +968,7 @@ static int ax25_release(struct socket *sock) ...@@ -1054,6 +968,7 @@ static int ax25_release(struct socket *sock)
case AX25_STATE_4: case AX25_STATE_4:
ax25_clear_queues(ax25); ax25_clear_queues(ax25);
ax25->n2count = 0; ax25->n2count = 0;
switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
case AX25_PROTO_STD_SIMPLEX: case AX25_PROTO_STD_SIMPLEX:
case AX25_PROTO_STD_DUPLEX: case AX25_PROTO_STD_DUPLEX:
...@@ -1095,7 +1010,7 @@ static int ax25_release(struct socket *sock) ...@@ -1095,7 +1010,7 @@ static int ax25_release(struct socket *sock)
sock->sk = NULL; sock->sk = NULL;
sk->socket = NULL; /* Not used, but we should do this */ sk->socket = NULL; /* Not used, but we should do this */
unlock_kernel(); release_sock(sk);
return 0; return 0;
} }
...@@ -1109,23 +1024,17 @@ static int ax25_release(struct socket *sock) ...@@ -1109,23 +1024,17 @@ static int ax25_release(struct socket *sock)
static int ax25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) static int ax25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
ax25_cb *ax25 = ax25_sk(sk);
struct full_sockaddr_ax25 *addr = (struct full_sockaddr_ax25 *)uaddr; struct full_sockaddr_ax25 *addr = (struct full_sockaddr_ax25 *)uaddr;
ax25_address *call;
ax25_dev *ax25_dev = NULL; ax25_dev *ax25_dev = NULL;
ax25_address *call;
lock_kernel(); ax25_cb *ax25;
if (sk->zapped == 0) { int err = 0;
unlock_kernel();
return -EINVAL;
}
if (addr_len != sizeof(struct sockaddr_ax25) && if (addr_len != sizeof(struct sockaddr_ax25) &&
addr_len != sizeof(struct full_sockaddr_ax25)) { addr_len != sizeof(struct full_sockaddr_ax25)) {
/* support for old structure may go away some time */ /* support for old structure may go away some time */
if ((addr_len < sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 6) || if ((addr_len < sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 6) ||
(addr_len > sizeof(struct full_sockaddr_ax25))) { (addr_len > sizeof(struct full_sockaddr_ax25))) {
unlock_kernel();
return -EINVAL; return -EINVAL;
} }
...@@ -1133,17 +1042,22 @@ static int ax25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) ...@@ -1133,17 +1042,22 @@ static int ax25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
current->comm); current->comm);
} }
if (addr->fsa_ax25.sax25_family != AF_AX25) { if (addr->fsa_ax25.sax25_family != AF_AX25)
unlock_kernel();
return -EINVAL; return -EINVAL;
}
call = ax25_findbyuid(current->euid); call = ax25_findbyuid(current->euid);
if (call == NULL && ax25_uid_policy && !capable(CAP_NET_ADMIN)) { if (call == NULL && ax25_uid_policy && !capable(CAP_NET_ADMIN)) {
unlock_kernel();
return -EACCES; return -EACCES;
} }
lock_sock(sk);
ax25 = ax25_sk(sk);
if (sk->zapped == 0) {
err = -EINVAL;
goto out;
}
if (call == NULL) if (call == NULL)
ax25->source_addr = addr->fsa_ax25.sax25_call; ax25->source_addr = addr->fsa_ax25.sax25_call;
else else
...@@ -1152,20 +1066,19 @@ static int ax25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) ...@@ -1152,20 +1066,19 @@ static int ax25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
/* /*
* User already set interface with SO_BINDTODEVICE * User already set interface with SO_BINDTODEVICE
*/ */
if (ax25->ax25_dev != NULL) if (ax25->ax25_dev != NULL)
goto done; goto done;
if (addr_len > sizeof(struct sockaddr_ax25) && addr->fsa_ax25.sax25_ndigis == 1) { if (addr_len > sizeof(struct sockaddr_ax25) && addr->fsa_ax25.sax25_ndigis == 1) {
if (ax25cmp(&addr->fsa_digipeater[0], &null_ax25_address) != 0 && if (ax25cmp(&addr->fsa_digipeater[0], &null_ax25_address) != 0 &&
(ax25_dev = ax25_addr_ax25dev(&addr->fsa_digipeater[0])) == NULL) { (ax25_dev = ax25_addr_ax25dev(&addr->fsa_digipeater[0])) == NULL) {
unlock_kernel(); err = -EADDRNOTAVAIL;
return -EADDRNOTAVAIL; goto out;
} }
} else { } else {
if ((ax25_dev = ax25_addr_ax25dev(&addr->fsa_ax25.sax25_call)) == NULL) { if ((ax25_dev = ax25_addr_ax25dev(&addr->fsa_ax25.sax25_call)) == NULL) {
unlock_kernel(); err = -EADDRNOTAVAIL;
return -EADDRNOTAVAIL; goto out;
} }
} }
...@@ -1175,7 +1088,9 @@ static int ax25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) ...@@ -1175,7 +1088,9 @@ static int ax25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
done: done:
ax25_insert_socket(ax25); ax25_insert_socket(ax25);
sk->zapped = 0; sk->zapped = 0;
unlock_kernel();
out:
release_sock(sk);
return 0; return 0;
} }
...@@ -1190,35 +1105,7 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -1190,35 +1105,7 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
ax25_cb *ax25 = ax25_sk(sk); ax25_cb *ax25 = ax25_sk(sk);
struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)uaddr; struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)uaddr;
ax25_digi *digi = NULL; ax25_digi *digi = NULL;
int ct = 0, err; int ct = 0, err = 0;
lock_kernel();
/* deal with restarts */
if (sock->state == SS_CONNECTING) {
switch (sk->state) {
case TCP_SYN_SENT: /* still trying */
unlock_kernel();
return -EINPROGRESS;
case TCP_ESTABLISHED: /* connection established */
unlock_kernel();
sock->state = SS_CONNECTED;
return 0;
case TCP_CLOSE: /* connection refused */
unlock_kernel();
sock->state = SS_UNCONNECTED;
return -ECONNREFUSED;
}
}
if (sk->state == TCP_ESTABLISHED && sk->type == SOCK_SEQPACKET) {
unlock_kernel();
return -EISCONN; /* No reconnect on a seqpacket socket */
}
sk->state = TCP_CLOSE;
sock->state = SS_UNCONNECTED;
/* /*
* some sanity checks. code further down depends on this * some sanity checks. code further down depends on this
...@@ -1233,7 +1120,6 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -1233,7 +1120,6 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
/* support for old structure may go away some time */ /* support for old structure may go away some time */
if ((addr_len < sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 6) || if ((addr_len < sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 6) ||
(addr_len > sizeof(struct full_sockaddr_ax25))) { (addr_len > sizeof(struct full_sockaddr_ax25))) {
unlock_kernel();
return -EINVAL; return -EINVAL;
} }
...@@ -1241,11 +1127,37 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -1241,11 +1127,37 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
current->comm); current->comm);
} }
if (fsa->fsa_ax25.sax25_family != AF_AX25) { if (fsa->fsa_ax25.sax25_family != AF_AX25)
unlock_kernel();
return -EINVAL; return -EINVAL;
lock_sock(sk);
/* deal with restarts */
if (sock->state == SS_CONNECTING) {
switch (sk->state) {
case TCP_SYN_SENT: /* still trying */
err = -EINPROGRESS;
goto out;
case TCP_ESTABLISHED: /* connection established */
sock->state = SS_CONNECTED;
goto out;
case TCP_CLOSE: /* connection refused */
sock->state = SS_UNCONNECTED;
err = -ECONNREFUSED;
goto out;
}
} }
if (sk->state == TCP_ESTABLISHED && sk->type == SOCK_SEQPACKET) {
err = -EISCONN; /* No reconnect on a seqpacket socket */
goto out;
}
sk->state = TCP_CLOSE;
sock->state = SS_UNCONNECTED;
if (ax25->digipeat != NULL) { if (ax25->digipeat != NULL) {
kfree(ax25->digipeat); kfree(ax25->digipeat);
ax25->digipeat = NULL; ax25->digipeat = NULL;
...@@ -1254,16 +1166,17 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -1254,16 +1166,17 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
/* /*
* Handle digi-peaters to be used. * Handle digi-peaters to be used.
*/ */
if (addr_len > sizeof(struct sockaddr_ax25) && fsa->fsa_ax25.sax25_ndigis != 0) { if (addr_len > sizeof(struct sockaddr_ax25) &&
fsa->fsa_ax25.sax25_ndigis != 0) {
/* Valid number of digipeaters ? */ /* Valid number of digipeaters ? */
if (fsa->fsa_ax25.sax25_ndigis < 1 || fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGIS) { if (fsa->fsa_ax25.sax25_ndigis < 1 || fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGIS) {
unlock_kernel(); err = -EINVAL;
return -EINVAL; goto out;
} }
if ((digi = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) { if ((digi = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) {
unlock_kernel(); err = -ENOBUFS;
return -ENOBUFS; goto out;
} }
digi->ndigi = fsa->fsa_ax25.sax25_ndigis; digi->ndigi = fsa->fsa_ax25.sax25_ndigis;
...@@ -1292,13 +1205,14 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -1292,13 +1205,14 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
printk(KERN_WARNING "ax25_connect(): %s uses autobind, please contact jreuter@yaina.de\n", printk(KERN_WARNING "ax25_connect(): %s uses autobind, please contact jreuter@yaina.de\n",
current->comm); current->comm);
if ((err = ax25_rt_autobind(ax25, &fsa->fsa_ax25.sax25_call)) < 0) if ((err = ax25_rt_autobind(ax25, &fsa->fsa_ax25.sax25_call)) < 0)
return err; goto out;
ax25_fillin_cb(ax25, ax25->ax25_dev); ax25_fillin_cb(ax25, ax25->ax25_dev);
ax25_insert_socket(ax25); ax25_insert_socket(ax25);
} else { } else {
if (ax25->ax25_dev == NULL) { if (ax25->ax25_dev == NULL) {
unlock_kernel(); err = -EHOSTUNREACH;
return -EHOSTUNREACH; goto out;
} }
} }
...@@ -1307,8 +1221,8 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -1307,8 +1221,8 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
ax25->ax25_dev->dev)) { ax25->ax25_dev->dev)) {
if (digi != NULL) if (digi != NULL)
kfree(digi); kfree(digi);
unlock_kernel(); err = -EADDRINUSE; /* Already such a connection */
return -EADDRINUSE; /* Already such a connection */ goto out;
} }
ax25->dest_addr = fsa->fsa_ax25.sax25_call; ax25->dest_addr = fsa->fsa_ax25.sax25_call;
...@@ -1318,8 +1232,7 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -1318,8 +1232,7 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
if (sk->type != SOCK_SEQPACKET) { if (sk->type != SOCK_SEQPACKET) {
sock->state = SS_CONNECTED; sock->state = SS_CONNECTED;
sk->state = TCP_ESTABLISHED; sk->state = TCP_ESTABLISHED;
unlock_kernel(); goto out;
return 0;
} }
/* Move to connecting socket, ax.25 lapb WAIT_UA.. */ /* Move to connecting socket, ax.25 lapb WAIT_UA.. */
...@@ -1350,8 +1263,8 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -1350,8 +1263,8 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
/* Now the loop */ /* Now the loop */
if (sk->state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) { if (sk->state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) {
unlock_kernel(); err = -EINPROGRESS;
return -EINPROGRESS; goto out;
} }
if (sk->state == TCP_SYN_SENT) { if (sk->state == TCP_SYN_SENT) {
...@@ -1360,11 +1273,13 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -1360,11 +1273,13 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
add_wait_queue(sk->sleep, &wait); add_wait_queue(sk->sleep, &wait);
for (;;) { for (;;) {
set_current_state(TASK_INTERRUPTIBLE);
if (sk->state != TCP_SYN_SENT) if (sk->state != TCP_SYN_SENT)
break; break;
set_current_state(TASK_INTERRUPTIBLE);
release_sock(sk);
if (!signal_pending(tsk)) { if (!signal_pending(tsk)) {
schedule(); schedule();
lock_sock(sk);
continue; continue;
} }
return -ERESTARTSYS; return -ERESTARTSYS;
...@@ -1376,12 +1291,14 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -1376,12 +1291,14 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
if (sk->state != TCP_ESTABLISHED) { if (sk->state != TCP_ESTABLISHED) {
/* Not in ABM, not in WAIT_UA -> failed */ /* Not in ABM, not in WAIT_UA -> failed */
sock->state = SS_UNCONNECTED; sock->state = SS_UNCONNECTED;
unlock_kernel(); err = sock_error(sk); /* Always set at this point */
return sock_error(sk); /* Always set at this point */ goto out;
} }
sock->state = SS_CONNECTED; sock->state = SS_CONNECTED;
unlock_kernel();
out:
release_sock(sk);
return 0; return 0;
} }
...@@ -1457,19 +1374,19 @@ static int ax25_accept(struct socket *sock, struct socket *newsock, int flags) ...@@ -1457,19 +1374,19 @@ static int ax25_accept(struct socket *sock, struct socket *newsock, int flags)
static int ax25_getname(struct socket *sock, struct sockaddr *uaddr, static int ax25_getname(struct socket *sock, struct sockaddr *uaddr,
int *uaddr_len, int peer) int *uaddr_len, int peer)
{ {
struct sock *sk;
ax25_cb *ax25;
struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)uaddr; struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)uaddr;
struct sock *sk = sock->sk;
unsigned char ndigi, i; unsigned char ndigi, i;
ax25_cb *ax25;
int err = 0;
lock_kernel(); lock_sock(sk);
sk = sock->sk;
ax25 = ax25_sk(sk); ax25 = ax25_sk(sk);
if (peer != 0) { if (peer != 0) {
if (sk->state != TCP_ESTABLISHED) { if (sk->state != TCP_ESTABLISHED) {
unlock_kernel(); err = -ENOTCONN;
return -ENOTCONN; goto out;
} }
fsa->fsa_ax25.sax25_family = AF_AX25; fsa->fsa_ax25.sax25_family = AF_AX25;
...@@ -1495,54 +1412,52 @@ static int ax25_getname(struct socket *sock, struct sockaddr *uaddr, ...@@ -1495,54 +1412,52 @@ static int ax25_getname(struct socket *sock, struct sockaddr *uaddr,
} }
} }
*uaddr_len = sizeof (struct full_sockaddr_ax25); *uaddr_len = sizeof (struct full_sockaddr_ax25);
unlock_kernel();
return 0; out:
release_sock(sk);
return err;
} }
static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len, static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len,
struct scm_cookie *scm) struct scm_cookie *scm)
{ {
struct sock *sk = sock->sk;
ax25_cb *ax25;
struct sockaddr_ax25 *usax = (struct sockaddr_ax25 *)msg->msg_name; struct sockaddr_ax25 *usax = (struct sockaddr_ax25 *)msg->msg_name;
int err; struct sock *sk = sock->sk;
struct sockaddr_ax25 sax; struct sockaddr_ax25 sax;
struct sk_buff *skb; struct sk_buff *skb;
ax25_digi dtmp, *dp;
unsigned char *asmptr; unsigned char *asmptr;
int size; ax25_cb *ax25;
ax25_digi *dp; int lv, size, err, addr_len = msg->msg_namelen;
ax25_digi dtmp;
int lv;
int addr_len = msg->msg_namelen;
if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR)) { if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR)) {
return -EINVAL; return -EINVAL;
} }
lock_kernel(); lock_sock(sk);
ax25 = ax25_sk(sk); ax25 = ax25_sk(sk);
if (sk->zapped) { if (sk->zapped) {
unlock_kernel(); err = -EADDRNOTAVAIL;
return -EADDRNOTAVAIL; goto out;
} }
if (sk->shutdown & SEND_SHUTDOWN) { if (sk->shutdown & SEND_SHUTDOWN) {
unlock_kernel();
send_sig(SIGPIPE, current, 0); send_sig(SIGPIPE, current, 0);
return -EPIPE; err = -EPIPE;
goto out;
} }
if (ax25->ax25_dev == NULL) { if (ax25->ax25_dev == NULL) {
unlock_kernel(); err = -ENETUNREACH;
return -ENETUNREACH; goto out;
} }
if (usax != NULL) { if (usax != NULL) {
if (usax->sax25_family != AF_AX25) { if (usax->sax25_family != AF_AX25) {
unlock_kernel(); err = -EINVAL;
return -EINVAL; goto out;
} }
if (addr_len == sizeof(struct sockaddr_ax25)) { if (addr_len == sizeof(struct sockaddr_ax25)) {
...@@ -1553,8 +1468,8 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len, ...@@ -1553,8 +1468,8 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len,
/* support for old structure may go away some time */ /* support for old structure may go away some time */
if ((addr_len < sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 6) || if ((addr_len < sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 6) ||
(addr_len > sizeof(struct full_sockaddr_ax25))) { (addr_len > sizeof(struct full_sockaddr_ax25))) {
unlock_kernel(); err = -EINVAL;
return -EINVAL; goto out;
} }
printk(KERN_WARNING "ax25_sendmsg(): %s uses old (6 digipeater) socket structure.\n", printk(KERN_WARNING "ax25_sendmsg(): %s uses old (6 digipeater) socket structure.\n",
...@@ -1567,8 +1482,8 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len, ...@@ -1567,8 +1482,8 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len,
/* Valid number of digipeaters ? */ /* Valid number of digipeaters ? */
if (usax->sax25_ndigis < 1 || usax->sax25_ndigis > AX25_MAX_DIGIS) { if (usax->sax25_ndigis < 1 || usax->sax25_ndigis > AX25_MAX_DIGIS) {
unlock_kernel(); err = -EINVAL;
return -EINVAL; goto out;
} }
dtmp.ndigi = usax->sax25_ndigis; dtmp.ndigi = usax->sax25_ndigis;
...@@ -1584,8 +1499,8 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len, ...@@ -1584,8 +1499,8 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len,
sax = *usax; sax = *usax;
if (sk->type == SOCK_SEQPACKET && ax25cmp(&ax25->dest_addr, &sax.sax25_call) != 0) { if (sk->type == SOCK_SEQPACKET && ax25cmp(&ax25->dest_addr, &sax.sax25_call) != 0) {
unlock_kernel(); err = -EISCONN;
return -EISCONN; goto out;
} }
if (usax->sax25_ndigis == 0) if (usax->sax25_ndigis == 0)
dp = NULL; dp = NULL;
...@@ -1597,8 +1512,10 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len, ...@@ -1597,8 +1512,10 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len,
* it has become closed (not started closed) and is VC * it has become closed (not started closed) and is VC
* we ought to SIGPIPE, EPIPE * we ought to SIGPIPE, EPIPE
*/ */
if (sk->state != TCP_ESTABLISHED) if (sk->state != TCP_ESTABLISHED) {
return -ENOTCONN; err = -ENOTCONN;
goto out;
}
sax.sax25_family = AF_AX25; sax.sax25_family = AF_AX25;
sax.sax25_call = ax25->dest_addr; sax.sax25_call = ax25->dest_addr;
dp = ax25->digipeat; dp = ax25->digipeat;
...@@ -1612,10 +1529,9 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len, ...@@ -1612,10 +1529,9 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len,
/* Assume the worst case */ /* Assume the worst case */
size = len + 3 + ax25_addr_size(dp) + AX25_BPQ_HEADER_LEN; size = len + 3 + ax25_addr_size(dp) + AX25_BPQ_HEADER_LEN;
if ((skb = sock_alloc_send_skb(sk, size, msg->msg_flags & MSG_DONTWAIT, &err)) == NULL) { skb = sock_alloc_send_skb(sk, size, msg->msg_flags&MSG_DONTWAIT, &err);
unlock_kernel(); if (skb == NULL)
return err; goto out;
}
skb_reserve(skb, size - len); skb_reserve(skb, size - len);
...@@ -1637,16 +1553,17 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len, ...@@ -1637,16 +1553,17 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len,
/* Connected mode sockets go via the LAPB machine */ /* Connected mode sockets go via the LAPB machine */
if (sk->state != TCP_ESTABLISHED) { if (sk->state != TCP_ESTABLISHED) {
kfree_skb(skb); kfree_skb(skb);
unlock_kernel(); err = -ENOTCONN;
return -ENOTCONN; goto out;
} }
/* Shove it onto the queue and kick */ /* Shove it onto the queue and kick */
ax25_output(ax25, ax25->paclen, skb); ax25_output(ax25, ax25->paclen, skb);
unlock_kernel();
return len; err = len;
} else { goto out;
}
asmptr = skb_push(skb, 1 + ax25_addr_size(dp)); asmptr = skb_push(skb, 1 + ax25_addr_size(dp));
SOCK_DEBUG(sk, "Building AX.25 Header (dp=%p).\n", dp); SOCK_DEBUG(sk, "Building AX.25 Header (dp=%p).\n", dp);
...@@ -1671,37 +1588,38 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len, ...@@ -1671,37 +1588,38 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len,
skb->dev = ax25->ax25_dev->dev; skb->dev = ax25->ax25_dev->dev;
ax25_queue_xmit(skb); ax25_queue_xmit(skb);
unlock_kernel();
return len; err = len;
}
out:
release_sock(sk);
return err;
} }
static int ax25_recvmsg(struct socket *sock, struct msghdr *msg, int size, static int ax25_recvmsg(struct socket *sock, struct msghdr *msg, int size,
int flags, struct scm_cookie *scm) int flags, struct scm_cookie *scm)
{ {
struct sock *sk; struct sock *sk = sock->sk;
int copied;
struct sk_buff *skb; struct sk_buff *skb;
int er; int copied;
int err = 0;
lock_kernel();
sk = sock->sk;
lock_sock(sk);
/* /*
* This works for seqpacket too. The receiver has ordered the * This works for seqpacket too. The receiver has ordered the
* queue for us! We do one quick check first though * queue for us! We do one quick check first though
*/ */
if (sk->type == SOCK_SEQPACKET && sk->state != TCP_ESTABLISHED) { if (sk->type == SOCK_SEQPACKET && sk->state != TCP_ESTABLISHED) {
unlock_kernel(); err = -ENOTCONN;
return -ENOTCONN; goto out;
} }
/* Now we can treat all alike */ /* Now we can treat all alike */
if ((skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, flags & MSG_DONTWAIT, &er)) == NULL) { skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
unlock_kernel(); flags & MSG_DONTWAIT, &err);
return er; if (skb == NULL)
} goto out;
if (!ax25_sk(sk)->pidincl) if (!ax25_sk(sk)->pidincl)
skb_pull(skb, 1); /* Remove PID */ skb_pull(skb, 1); /* Remove PID */
...@@ -1741,9 +1659,12 @@ static int ax25_recvmsg(struct socket *sock, struct msghdr *msg, int size, ...@@ -1741,9 +1659,12 @@ static int ax25_recvmsg(struct socket *sock, struct msghdr *msg, int size,
} }
skb_free_datagram(sk, skb); skb_free_datagram(sk, skb);
unlock_kernel(); err = copied;
return copied; out:
release_sock(sk);
return err;
} }
static int ax25_shutdown(struct socket *sk, int how) static int ax25_shutdown(struct socket *sk, int how)
...@@ -1757,7 +1678,7 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1757,7 +1678,7 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
int res = 0; int res = 0;
lock_kernel(); lock_sock(sk);
switch (cmd) { switch (cmd) {
case TIOCOUTQ: { case TIOCOUTQ: {
long amount; long amount;
...@@ -1919,8 +1840,8 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1919,8 +1840,8 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
res = dev_ioctl(cmd, (void *)arg); res = dev_ioctl(cmd, (void *)arg);
break; break;
} }
release_sock(sk);
unlock_kernel();
return res; return res;
} }
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Most of this code is based on the SDL diagrams published in the 7th
* ARRL Computer Networking Conference papers. The diagrams have mistakes
* in them, but are mostly correct. Before you modify the code could you
* read the SDL diagrams as the code is not obvious and probably very
* easy to break;
*
* History
* AX.25 036 Jonathan(G4KLX) Split from ax25_subr.c.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Other kernels modules in this kit are generally BSD derived. See the copyright headers.
*
*
* History
* AX.25 036 Jonathan(G4KLX) Split from ax25_route.c.
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Most of this code is based on the SDL diagrams published in the 7th
* ARRL Computer Networking Conference papers. The diagrams have mistakes
* in them, but are mostly correct. Before you modify the code could you
* read the SDL diagrams as the code is not obvious and probably very
* easy to break;
*
* History
* AX.25 036 Jonathan(G4KLX) Cloned from ax25_in.c
* Joerg(DL1BKE) Fixed it.
* AX.25 037 Jonathan(G4KLX) New timer architecture.
* Joerg(DL1BKE) ax25->n2count never got reset
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Most of this code is based on the SDL diagrams published in the 7th
* ARRL Computer Networking Conference papers. The diagrams have mistakes
* in them, but are mostly correct. Before you modify the code could you
* read the SDL diagrams as the code is not obvious and probably very
* easy to break;
*
* History
* AX.25 036 Jonathan(G4KLX) Cloned from ax25_out.c and ax25_subr.c.
* Joerg(DL1BKE) Changed ax25_ds_enquiry_response(),
* fixed ax25_dama_on() and ax25_dama_off().
* AX.25 037 Jonathan(G4KLX) New timer architecture.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* AX.25 036 Jonathan(G4KLX) Cloned from ax25_timer.c.
* Joerg(DL1BKE) Added DAMA Slave Timeout timer
* AX.25 037 Jonathan(G4KLX) New timer architecture.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* AX.25 036 Jonathan(G4KLX) Split from ax25_timer.c.
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
* * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* This module: * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
* This module is free software; you can redistribute it and/or * Copyright (C) Hans-Joachim Hetscher DD8NE (dd8ne@bnv-bamberg.de)
* 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.
*
* Most of this code is based on the SDL diagrams published in the 7th
* ARRL Computer Networking Conference papers. The diagrams have mistakes
* in them, but are mostly correct. Before you modify the code could you
* read the SDL diagrams as the code is not obvious and probably very
* easy to break;
*
* History
* AX.25 028a Jonathan(G4KLX) New state machine based on SDL diagrams.
* AX.25 028b Jonathan(G4KLX) Extracted AX25 control block from
* the sock structure.
* AX.25 029 Alan(GW4PTS) Switched to KA9Q constant names.
* Jonathan(G4KLX) Added IP mode registration.
* AX.25 030 Jonathan(G4KLX) Added AX.25 fragment reception.
* Upgraded state machine for SABME.
* Added arbitrary protocol id support.
* AX.25 031 Joerg(DL1BKE) Added DAMA support
* HaJo(DD8NE) Added Idle Disc Timer T5
* Joerg(DL1BKE) Renamed it to "IDLE" with a slightly
* different behaviour. Fixed defrag
* routine (I hope)
* AX.25 032 Darryl(G7LED) AX.25 segmentation fixed.
* AX.25 033 Jonathan(G4KLX) Remove auto-router.
* Modularisation changes.
* AX.25 035 Hans(PE1AYX) Fixed interface to IP layer.
* AX.25 036 Jonathan(G4KLX) Move DAMA code into own file.
* Joerg(DL1BKE) Fixed DAMA Slave.
* AX.25 037 Jonathan(G4KLX) New timer architecture.
* Thomas(DL9SAU) Fixed missing initialization of skb->protocol.
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
...@@ -220,17 +190,12 @@ static int ax25_process_rx_frame(ax25_cb *ax25, struct sk_buff *skb, int type, i ...@@ -220,17 +190,12 @@ static int ax25_process_rx_frame(ax25_cb *ax25, struct sk_buff *skb, int type, i
static int ax25_rcv(struct sk_buff *skb, struct net_device *dev, static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
ax25_address *dev_addr, struct packet_type *ptype) ax25_address *dev_addr, struct packet_type *ptype)
{ {
struct sock *make; ax25_address src, dest, *next_digi = NULL;
struct sock *sk; int type = 0, mine = 0, dama;
int type = 0; struct sock *make, *sk, *raw;
ax25_digi dp, reverse_dp; ax25_digi dp, reverse_dp;
ax25_cb *ax25; ax25_cb *ax25;
ax25_address src, dest;
ax25_address *next_digi = NULL;
ax25_dev *ax25_dev; ax25_dev *ax25_dev;
struct sock *raw;
int mine = 0;
int dama;
/* /*
* Process the AX.25/LAPB frame. * Process the AX.25/LAPB frame.
...@@ -275,8 +240,10 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -275,8 +240,10 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
if ((*skb->data & ~0x10) == AX25_UI && dp.lastrepeat + 1 == dp.ndigi) { if ((*skb->data & ~0x10) == AX25_UI && dp.lastrepeat + 1 == dp.ndigi) {
skb->h.raw = skb->data + 2; /* skip control and pid */ skb->h.raw = skb->data + 2; /* skip control and pid */
if ((raw = ax25_addr_match(&dest)) != NULL) if ((raw = ax25_addr_match(&dest)) != NULL) {
ax25_send_to_raw(raw, skb, skb->data[1]); ax25_send_to_raw(raw, skb, skb->data[1]);
release_sock(raw);
}
if (!mine && ax25cmp(&dest, (ax25_address *)dev->broadcast) != 0) { if (!mine && ax25cmp(&dest, (ax25_address *)dev->broadcast) != 0) {
kfree_skb(skb); kfree_skb(skb);
...@@ -308,7 +275,8 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -308,7 +275,8 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
#endif #endif
case AX25_P_TEXT: case AX25_P_TEXT:
/* Now find a suitable dgram socket */ /* Now find a suitable dgram socket */
if ((sk = ax25_find_socket(&dest, &src, SOCK_DGRAM)) != NULL) { sk = ax25_get_socket(&dest, &src, SOCK_DGRAM);
if (sk != NULL) {
if (atomic_read(&sk->rmem_alloc) >= sk->rcvbuf) { if (atomic_read(&sk->rmem_alloc) >= sk->rcvbuf) {
kfree_skb(skb); kfree_skb(skb);
} else { } else {
...@@ -319,6 +287,7 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -319,6 +287,7 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
if (sock_queue_rcv_skb(sk, skb) != 0) if (sock_queue_rcv_skb(sk, skb) != 0)
kfree_skb(skb); kfree_skb(skb);
} }
release_sock(sk);
} else { } else {
kfree_skb(skb); kfree_skb(skb);
} }
...@@ -350,9 +319,10 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -350,9 +319,10 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
if ((ax25 = ax25_find_cb(&dest, &src, &reverse_dp, dev)) != NULL) { if ((ax25 = ax25_find_cb(&dest, &src, &reverse_dp, dev)) != NULL) {
/* /*
* Process the frame. If it is queued up internally it returns one otherwise we * Process the frame. If it is queued up internally it
* free it immediately. This routine itself wakes the user context layers so we * returns one otherwise we free it immediately. This
* do no further work * routine itself wakes the user context layers so we do
* no further work
*/ */
if (ax25_process_rx_frame(ax25, skb, type, dama) == 0) if (ax25_process_rx_frame(ax25, skb, type, dama) == 0)
kfree_skb(skb); kfree_skb(skb);
...@@ -364,7 +334,8 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -364,7 +334,8 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
/* a) received not a SABM(E) */ /* a) received not a SABM(E) */
if ((*skb->data & ~AX25_PF) != AX25_SABM && (*skb->data & ~AX25_PF) != AX25_SABME) { if ((*skb->data & ~AX25_PF) != AX25_SABM &&
(*skb->data & ~AX25_PF) != AX25_SABME) {
/* /*
* Never reply to a DM. Also ignore any connects for * Never reply to a DM. Also ignore any connects for
* addresses that are not our interfaces and not a socket. * addresses that are not our interfaces and not a socket.
...@@ -384,9 +355,12 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -384,9 +355,12 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
sk = ax25_find_listener(next_digi, 1, dev, SOCK_SEQPACKET); sk = ax25_find_listener(next_digi, 1, dev, SOCK_SEQPACKET);
if (sk != NULL) { if (sk != NULL) {
if (sk->ack_backlog == sk->max_ack_backlog || (make = ax25_make_new(sk, ax25_dev)) == NULL) { if (sk->ack_backlog == sk->max_ack_backlog ||
if (mine) ax25_return_dm(dev, &src, &dest, &dp); (make = ax25_make_new(sk, ax25_dev)) == NULL) {
if (mine)
ax25_return_dm(dev, &src, &dest, &dp);
kfree_skb(skb); kfree_skb(skb);
return 0; return 0;
} }
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* AX.25 036 Jonathan(G4KLX) Split from af_ax25.c.
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
* * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* This module: * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Most of this code is based on the SDL diagrams published in the 7th
* ARRL Computer Networking Conference papers. The diagrams have mistakes
* in them, but are mostly correct. Before you modify the code could you
* read the SDL diagrams as the code is not obvious and probably very
* easy to break;
*
* History
* AX.25 028a Jonathan(G4KLX) New state machine based on SDL diagrams.
* AX.25 029 Alan(GW4PTS) Switched to KA9Q constant names.
* Jonathan(G4KLX) Only poll when window is full.
* AX.25 030 Jonathan(G4KLX) Added fragmentation to ax25_output.
* Added support for extended AX.25.
* AX.25 031 Joerg(DL1BKE) Added DAMA support
* Joerg(DL1BKE) Modified fragmenter to fragment vanilla
* AX.25 I-Frames. Added PACLEN parameter.
* Joerg(DL1BKE) Fixed a problem with buffer allocation
* for fragments.
* AX.25 037 Jonathan(G4KLX) New timer architecture.
* Joerg(DL1BKE) Fixed DAMA Slave mode: will work
* on non-DAMA interfaces like AX25L2V2
* again (this behaviour is _required_).
* Joerg(DL1BKE) ax25_check_iframes_acked() returns a
* value now (for DAMA n2count handling)
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
* * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* This module: * Copyright (C) Steven Whitehouse GW7RRM (stevew@acm.org)
* This module is free software; you can redistribute it and/or * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
* modify it under the terms of the GNU General Public License * Copyright (C) Hans-Joachim Hetscher DD8NE (dd8ne@bnv-bamberg.de)
* as published by the Free Software Foundation; either version * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
* 2 of the License, or (at your option) any later version.
*
* Other kernels modules in this kit are generally BSD derived. See the copyright headers.
*
*
* History
* AX.25 020 Jonathan(G4KLX) First go.
* AX.25 022 Jonathan(G4KLX) Added the actual meat to this - we now have a nice heard list.
* AX.25 025 Alan(GW4PTS) First cut at autobinding by route scan.
* AX.25 028b Jonathan(G4KLX) Extracted AX25 control block from the
* sock structure. Device removal now
* removes the heard structure.
* AX.25 029 Steven(GW7RRM) Added /proc information for uid/callsign mapping.
* Jonathan(G4KLX) Handling of IP mode in the routing list and /proc entry.
* AX.25 030 Jonathan(G4KLX) Added digi-peaters to routing table, and
* ioctls to manipulate them. Added port
* configuration.
* AX.25 031 Jonathan(G4KLX) Added concept of default route.
* Joerg(DL1BKE) ax25_rt_build_path() find digipeater list and device by
* destination call. Needed for IP routing via digipeater
* Jonathan(G4KLX) Added routing for IP datagram packets.
* Joerg(DL1BKE) Changed routing for IP datagram and VC to use a default
* route if available. Does not overwrite default routes
* on route-table overflow anymore.
* Joerg(DL1BKE) Fixed AX.25 routing of IP datagram and VC, new ioctl()
* "SIOCAX25OPTRT" to set IP mode and a 'permanent' flag
* on routes.
* AX.25 033 Jonathan(G4KLX) Remove auto-router.
* Joerg(DL1BKE) Moved BPQ Ethernet driver to separate device.
* AX.25 035 Frederic(F1OAT) Support for pseudo-digipeating.
* Jonathan(G4KLX) Support for packet forwarding.
* Arnaldo C. Melo s/suser/capable/
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
* Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
* Copyright (C) Hans-Joachim Hetscher DD8NE (dd8ne@bnv-bamberg.de)
* *
* This module: * Most of this code is based on the SDL diagrams published in the 7th ARRL
* This module is free software; you can redistribute it and/or * Computer Networking Conference papers. The diagrams have mistakes in them,
* modify it under the terms of the GNU General Public License * but are mostly correct. Before you modify the code could you read the SDL
* as published by the Free Software Foundation; either version * diagrams as the code is not obvious and probably very easy to break.
* 2 of the License, or (at your option) any later version.
*
* Most of this code is based on the SDL diagrams published in the 7th
* ARRL Computer Networking Conference papers. The diagrams have mistakes
* in them, but are mostly correct. Before you modify the code could you
* read the SDL diagrams as the code is not obvious and probably very
* easy to break;
*
* History
* AX.25 028a Jonathan(G4KLX) New state machine based on SDL diagrams.
* AX.25 028b Jonathan(G4KLX) Extracted AX25 control block from
* the sock structure.
* AX.25 029 Alan(GW4PTS) Switched to KA9Q constant names.
* Jonathan(G4KLX) Added IP mode registration.
* AX.25 030 Jonathan(G4KLX) Added AX.25 fragment reception.
* Upgraded state machine for SABME.
* Added arbitrary protocol id support.
* AX.25 031 Joerg(DL1BKE) Added DAMA support
* HaJo(DD8NE) Added Idle Disc Timer T5
* Joerg(DL1BKE) Renamed it to "IDLE" with a slightly
* different behaviour. Fixed defrag
* routine (I hope)
* AX.25 032 Darryl(G7LED) AX.25 segmentation fixed.
* AX.25 033 Jonathan(G4KLX) Remove auto-router.
* Modularisation changes.
* AX.25 035 Hans(PE1AYX) Fixed interface to IP layer.
* AX.25 036 Jonathan(G4KLX) Cloned from ax25_in.c.
* AX.25 037 Jonathan(G4KLX) New timer architecture.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Most of this code is based on the SDL diagrams published in the 7th
* ARRL Computer Networking Conference papers. The diagrams have mistakes
* in them, but are mostly correct. Before you modify the code could you
* read the SDL diagrams as the code is not obvious and probably very
* easy to break;
*
* History
* AX.25 036 Jonathan(G4KLX) Split from ax25_out.c.
* AX.25 037 Jonathan(G4KLX) New timer architecture.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
* * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* This module: * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
* This module is free software; you can redistribute it and/or * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* AX.25 028a Jonathan(G4KLX) New state machine based on SDL diagrams.
* AX.25 028b Jonathan(G4KLX) Extracted AX25 control block from the
* sock structure.
* AX.25 029 Alan(GW4PTS) Switched to KA9Q constant names.
* AX.25 031 Joerg(DL1BKE) Added DAMA support
* AX.25 032 Joerg(DL1BKE) Fixed DAMA timeout bug
* AX.25 033 Jonathan(G4KLX) Modularisation functions.
* AX.25 035 Frederic(F1OAT) Support for pseudo-digipeating.
* AX.25 036 Jonathan(G4KLX) Split from ax25_timer.c.
* AX.25 037 Jonathan(G4KLX) New timer architecture.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
* * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* This module: * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
* This module is free software; you can redistribute it and/or * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
* 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.
*
* Most of this code is based on the SDL diagrams published in the 7th
* ARRL Computer Networking Conference papers. The diagrams have mistakes
* in them, but are mostly correct. Before you modify the code could you
* read the SDL diagrams as the code is not obvious and probably very
* easy to break;
*
* History
* AX.25 029 Alan(GW4PTS) Switched to KA9Q constant names. Removed
* old BSD code.
* AX.25 030 Jonathan(G4KLX) Added support for extended AX.25.
* Added fragmentation support.
* Darryl(G7LED) Added function ax25_requeue_frames() to split
* it up from ax25_frames_acked().
* AX.25 031 Joerg(DL1BKE) DAMA needs KISS Fullduplex ON/OFF.
* Thus we have ax25_kiss_cmd() now... ;-)
* Dave Brown(N2RJT)
* Killed a silly bug in the DAMA code.
* Joerg(DL1BKE) Found the real bug in ax25.h, sri.
* AX.25 032 Joerg(DL1BKE) Added ax25_queue_length to count the number of
* enqueued buffers of a socket..
* AX.25 035 Frederic(F1OAT) Support for pseudo-digipeating.
* AX.25 037 Jonathan(G4KLX) New timer architecture.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
* * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* This module: * Copyright (C) Tomi Manninen OH2BNS (oh2bns@sral.fi)
* This module is free software; you can redistribute it and/or * Copyright (C) Darryl Miles G7LED (dlm@g7led.demon.co.uk)
* modify it under the terms of the GNU General Public License * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
* as published by the Free Software Foundation; either version * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
* 2 of the License, or (at your option) any later version.
*
* History
* AX.25 028a Jonathan(G4KLX) New state machine based on SDL diagrams.
* AX.25 028b Jonathan(G4KLX) Extracted AX25 control block from the
* sock structure.
* AX.25 029 Alan(GW4PTS) Switched to KA9Q constant names.
* AX.25 031 Joerg(DL1BKE) Added DAMA support
* AX.25 032 Joerg(DL1BKE) Fixed DAMA timeout bug
* AX.25 033 Jonathan(G4KLX) Modularisation functions.
* AX.25 035 Frederic(F1OAT) Support for pseudo-digipeating.
* AX.25 036 Jonathan(G4KLX) Split Standard and DAMA code into separate files.
* Joerg(DL1BKE) Fixed DAMA Slave. We are *required* to start with
* standard AX.25 mode.
* AX.25 037 Jonathan(G4KLX) New timer architecture.
* Tomi(OH2BNS) Fixed heartbeat expiry (check ax25_dev).
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
......
/* /*
* AX.25 release 037 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* AX.25 036 Jonathan(G4KLX) Split from af_ax25.c.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* -*- linux-c -*- /*
* sysctl_net_ax25.c: sysctl interface to net AX.25 subsystem. * 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.
* *
* Begun April 1, 1996, Mike Shaver. * Copyright (C) 1996 Mike Shaver (shaver@zeroknowledge.com)
* Added /proc/sys/net/ax25 directory entry (empty =) ). [MS]
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/sysctl.h> #include <linux/sysctl.h>
......
/* /*
* NET/ROM release 007 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* * Copyright Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
* This module: * Copyright Darryl Miles G7LED (dlm@g7led.demon.co.uk)
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* NET/ROM 001 Jonathan(G4KLX) Cloned from the AX25 code.
* NET/ROM 002 Darryl(G7LED) Fixes and address enhancement.
* Jonathan(G4KLX) Complete bind re-think.
* Alan(GW4PTS) Trivial tweaks into new format.
* NET/ROM 003 Jonathan(G4KLX) Added G8BPQ extensions.
* Added NET/ROM routing ioctl.
* Darryl(G7LED) Fix autobinding (on connect).
* Fixed nr_release(), set TCP_CLOSE, wakeup app
* context, THEN make the sock dead.
* Circuit ID check before allocating it on
* a connection.
* Alan(GW4PTS) sendmsg/recvmsg only. Fixed connect clear bug
* inherited from AX.25
* NET/ROM 004 Jonathan(G4KLX) Converted to module.
* NET/ROM 005 Jonathan(G4KLX) Linux 2.1
* Alan(GW4PTS) Started POSIXisms
* NET/ROM 006 Alan(GW4PTS) Brought in line with the ANK changes
* Jonathan(G4KLX) Removed hdrincl.
* NET/ROM 007 Jonathan(G4KLX) New timer architecture.
* Implemented Idle timer.
* Arnaldo C. Melo s/suser/capable/, micro cleanups
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/errno.h> #include <linux/errno.h>
...@@ -1268,7 +1243,7 @@ static struct net_proto_family nr_family_ops = { ...@@ -1268,7 +1243,7 @@ static struct net_proto_family nr_family_ops = {
.create = nr_create, .create = nr_create,
}; };
static struct proto_ops SOCKOPS_WRAPPED(nr_proto_ops) = { static struct proto_ops nr_proto_ops = {
.family = PF_NETROM, .family = PF_NETROM,
.release = nr_release, .release = nr_release,
...@@ -1289,11 +1264,8 @@ static struct proto_ops SOCKOPS_WRAPPED(nr_proto_ops) = { ...@@ -1289,11 +1264,8 @@ static struct proto_ops SOCKOPS_WRAPPED(nr_proto_ops) = {
.sendpage = sock_no_sendpage, .sendpage = sock_no_sendpage,
}; };
#include <linux/smp_lock.h>
SOCKOPS_WRAP(nr_proto, PF_NETROM);
static struct notifier_block nr_dev_notifier = { static struct notifier_block nr_dev_notifier = {
.notifier_call =nr_device_event, .notifier_call = nr_device_event,
}; };
static struct net_device *dev_nr; static struct net_device *dev_nr;
......
/* /*
* NET/ROM release 007 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* NET/ROM 001 Jonathan(G4KLX) Cloned from loopback.c
* NET/ROM 002 Steve Whitehouse(GW7RRM) fixed the set_mac_address
* NET/ROM 003 Jonathan(G4KLX) Put nr_rebuild_header into line with
* ax25_rebuild_header
* NET/ROM 004 Jonathan(G4KLX) Callsign registration with AX.25.
* NET/ROM 006 Hans(PE1AYX) Fixed interface to IP layer.
*/ */
#include <linux/config.h> #include <linux/config.h>
#define __NO_VERSION__ #define __NO_VERSION__
#include <linux/module.h> #include <linux/module.h>
......
/* /*
* NET/ROM release 007 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* * Copyright Darryl Miles G7LED (dlm@g7led.demon.co.uk)
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Most of this code is based on the SDL diagrams published in the 7th
* ARRL Computer Networking Conference papers. The diagrams have mistakes
* in them, but are mostly correct. Before you modify the code could you
* read the SDL diagrams as the code is not obvious and probably very
* easy to break;
*
* History
* NET/ROM 001 Jonathan(G4KLX) Cloned from ax25_in.c
* NET/ROM 003 Jonathan(G4KLX) Added NET/ROM fragment reception.
* Darryl(G7LED) Added missing INFO with NAK case, optimized
* INFOACK handling, removed reconnect on error.
* NET/ROM 006 Jonathan(G4KLX) Hdrincl removal changes.
* NET/ROM 007 Jonathan(G4KLX) New timer architecture.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* NET/ROM release 007 * 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
* This code REQUIRES 2.1.15 or higher/ NET3.038 * the Free Software Foundation; either version 2 of the License, or
* * (at your option) any later version.
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* NET/ROM 007 Tomi(OH2BNS) Created this file.
* Small change in nr_loopback_queue().
* *
* Copyright Tomi Manninen OH2BNS (oh2bns@sral.fi)
*/ */
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
#include <linux/timer.h> #include <linux/timer.h>
......
/* /*
* NET/ROM release 007 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* * Copyright Darryl Miles G7LED (dlm@g7led.demon.co.uk)
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* NET/ROM 001 Jonathan(G4KLX) Cloned from ax25_out.c
* NET/ROM 003 Jonathan(G4KLX) Added NET/ROM fragmentation.
* Darryl(G7LED) Fixed NAK, to give out correct reponse.
* NET/ROM 007 Jonathan(G4KLX) New timer architecture.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* NET/ROM release 007 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* * Copyright Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
* This module: * Copyright Tomi Manninen OH2BNS (oh2bns@sral.fi)
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* NET/ROM 001 Jonathan(G4KLX) First attempt.
* NET/ROM 003 Jonathan(G4KLX) Use SIOCADDRT/SIOCDELRT ioctl values
* for NET/ROM routes.
* Use '*' for a blank mnemonic in /proc/net/nr_nodes.
* Change default quality for new neighbour when same
* as node callsign.
* Alan Cox(GW4PTS) Added the firewall hooks.
* NET/ROM 006 Jonathan(G4KLX) Added the setting of digipeated neighbours.
* Tomi(OH2BNS) Routing quality and link failure changes.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
...@@ -47,12 +34,15 @@ ...@@ -47,12 +34,15 @@
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/netfilter.h> #include <linux/netfilter.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/spinlock.h>
#include <net/netrom.h> #include <net/netrom.h>
static unsigned int nr_neigh_no = 1; static unsigned int nr_neigh_no = 1;
static struct nr_node *nr_node_list; static struct nr_node *nr_node_list;
static spinlock_t nr_node_lock;
static struct nr_neigh *nr_neigh_list; static struct nr_neigh *nr_neigh_list;
static spinlock_t nr_neigh_lock;
static void nr_remove_neigh(struct nr_neigh *); static void nr_remove_neigh(struct nr_neigh *);
...@@ -124,13 +114,10 @@ static int nr_add_node(ax25_address *nr, const char *mnemonic, ax25_address *ax2 ...@@ -124,13 +114,10 @@ static int nr_add_node(ax25_address *nr, const char *mnemonic, ax25_address *ax2
memcpy(nr_neigh->digipeat, ax25_digi, sizeof(ax25_digi)); memcpy(nr_neigh->digipeat, ax25_digi, sizeof(ax25_digi));
} }
save_flags(flags); spin_lock_irqsave(&nr_neigh_lock, flags);
cli();
nr_neigh->next = nr_neigh_list; nr_neigh->next = nr_neigh_list;
nr_neigh_list = nr_neigh; nr_neigh_list = nr_neigh;
spin_unlock_irqrestore(&nr_neigh_lock, flags);
restore_flags(flags);
} }
if (quality != 0 && ax25cmp(nr, ax25) == 0 && !nr_neigh->locked) if (quality != 0 && ax25cmp(nr, ax25) == 0 && !nr_neigh->locked)
...@@ -150,13 +137,10 @@ static int nr_add_node(ax25_address *nr, const char *mnemonic, ax25_address *ax2 ...@@ -150,13 +137,10 @@ static int nr_add_node(ax25_address *nr, const char *mnemonic, ax25_address *ax2
nr_node->routes[0].obs_count = obs_count; nr_node->routes[0].obs_count = obs_count;
nr_node->routes[0].neighbour = nr_neigh; nr_node->routes[0].neighbour = nr_neigh;
save_flags(flags); spin_lock_irqsave(&nr_node_lock, flags);
cli();
nr_node->next = nr_node_list; nr_node->next = nr_node_list;
nr_node_list = nr_node; nr_node_list = nr_node;
spin_unlock_irqrestore(&nr_node_lock, flags);
restore_flags(flags);
nr_neigh->count++; nr_neigh->count++;
...@@ -259,12 +243,10 @@ static void nr_remove_node(struct nr_node *nr_node) ...@@ -259,12 +243,10 @@ static void nr_remove_node(struct nr_node *nr_node)
struct nr_node *s; struct nr_node *s;
unsigned long flags; unsigned long flags;
save_flags(flags); spin_lock_irqsave(&nr_node_lock, flags);
cli();
if ((s = nr_node_list) == nr_node) { if ((s = nr_node_list) == nr_node) {
nr_node_list = nr_node->next; nr_node_list = nr_node->next;
restore_flags(flags); spin_unlock_irqrestore(&nr_node_lock, flags);
kfree(nr_node); kfree(nr_node);
return; return;
} }
...@@ -272,7 +254,7 @@ static void nr_remove_node(struct nr_node *nr_node) ...@@ -272,7 +254,7 @@ static void nr_remove_node(struct nr_node *nr_node)
while (s != NULL && s->next != NULL) { while (s != NULL && s->next != NULL) {
if (s->next == nr_node) { if (s->next == nr_node) {
s->next = nr_node->next; s->next = nr_node->next;
restore_flags(flags); spin_unlock_irqrestore(&nr_node_lock, flags);
kfree(nr_node); kfree(nr_node);
return; return;
} }
...@@ -280,7 +262,7 @@ static void nr_remove_node(struct nr_node *nr_node) ...@@ -280,7 +262,7 @@ static void nr_remove_node(struct nr_node *nr_node)
s = s->next; s = s->next;
} }
restore_flags(flags); spin_unlock_irqrestore(&nr_node_lock, flags);
} }
static void nr_remove_neigh(struct nr_neigh *nr_neigh) static void nr_remove_neigh(struct nr_neigh *nr_neigh)
...@@ -288,12 +270,10 @@ static void nr_remove_neigh(struct nr_neigh *nr_neigh) ...@@ -288,12 +270,10 @@ static void nr_remove_neigh(struct nr_neigh *nr_neigh)
struct nr_neigh *s; struct nr_neigh *s;
unsigned long flags; unsigned long flags;
save_flags(flags); spin_lock_irqsave(&nr_neigh_lock, flags);
cli();
if ((s = nr_neigh_list) == nr_neigh) { if ((s = nr_neigh_list) == nr_neigh) {
nr_neigh_list = nr_neigh->next; nr_neigh_list = nr_neigh->next;
restore_flags(flags); spin_unlock_irqrestore(&nr_neigh_lock, flags);
if (nr_neigh->digipeat != NULL) if (nr_neigh->digipeat != NULL)
kfree(nr_neigh->digipeat); kfree(nr_neigh->digipeat);
kfree(nr_neigh); kfree(nr_neigh);
...@@ -303,7 +283,7 @@ static void nr_remove_neigh(struct nr_neigh *nr_neigh) ...@@ -303,7 +283,7 @@ static void nr_remove_neigh(struct nr_neigh *nr_neigh)
while (s != NULL && s->next != NULL) { while (s != NULL && s->next != NULL) {
if (s->next == nr_neigh) { if (s->next == nr_neigh) {
s->next = nr_neigh->next; s->next = nr_neigh->next;
restore_flags(flags); spin_unlock_irqrestore(&nr_neigh_lock, flags);
if (nr_neigh->digipeat != NULL) if (nr_neigh->digipeat != NULL)
kfree(nr_neigh->digipeat); kfree(nr_neigh->digipeat);
kfree(nr_neigh); kfree(nr_neigh);
...@@ -312,8 +292,7 @@ static void nr_remove_neigh(struct nr_neigh *nr_neigh) ...@@ -312,8 +292,7 @@ static void nr_remove_neigh(struct nr_neigh *nr_neigh)
s = s->next; s = s->next;
} }
spin_unlock_irqrestore(&nr_neigh_lock, flags);
restore_flags(flags);
} }
/* /*
...@@ -330,13 +309,15 @@ static int nr_del_node(ax25_address *callsign, ax25_address *neighbour, struct n ...@@ -330,13 +309,15 @@ static int nr_del_node(ax25_address *callsign, ax25_address *neighbour, struct n
if (ax25cmp(callsign, &nr_node->callsign) == 0) if (ax25cmp(callsign, &nr_node->callsign) == 0)
break; break;
if (nr_node == NULL) return -EINVAL; if (nr_node == NULL)
return -EINVAL;
for (nr_neigh = nr_neigh_list; nr_neigh != NULL; nr_neigh = nr_neigh->next) for (nr_neigh = nr_neigh_list; nr_neigh != NULL; nr_neigh = nr_neigh->next)
if (ax25cmp(neighbour, &nr_neigh->callsign) == 0 && nr_neigh->dev == dev) if (ax25cmp(neighbour, &nr_neigh->callsign) == 0 && nr_neigh->dev == dev)
break; break;
if (nr_neigh == NULL) return -EINVAL; if (nr_neigh == NULL)
return -EINVAL;
for (i = 0; i < nr_node->count; i++) { for (i = 0; i < nr_node->count; i++) {
if (nr_node->routes[i].neighbour == nr_neigh) { if (nr_node->routes[i].neighbour == nr_neigh) {
...@@ -404,13 +385,10 @@ static int nr_add_neigh(ax25_address *callsign, ax25_digi *ax25_digi, struct net ...@@ -404,13 +385,10 @@ static int nr_add_neigh(ax25_address *callsign, ax25_digi *ax25_digi, struct net
memcpy(nr_neigh->digipeat, ax25_digi, sizeof(ax25_digi)); memcpy(nr_neigh->digipeat, ax25_digi, sizeof(ax25_digi));
} }
save_flags(flags); spin_lock_irqsave(&nr_neigh_lock, flags);
cli();
nr_neigh->next = nr_neigh_list; nr_neigh->next = nr_neigh_list;
nr_neigh_list = nr_neigh; nr_neigh_list = nr_neigh;
spin_unlock_irqrestore(&nr_neigh_lock, flags);
restore_flags(flags);
return 0; return 0;
} }
...@@ -753,13 +731,13 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25) ...@@ -753,13 +731,13 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)
int nr_nodes_get_info(char *buffer, char **start, off_t offset, int length) int nr_nodes_get_info(char *buffer, char **start, off_t offset, int length)
{ {
struct nr_node *nr_node; struct nr_node *nr_node;
unsigned long flags;
int len = 0; int len = 0;
off_t pos = 0; off_t pos = 0;
off_t begin = 0; off_t begin = 0;
int i; int i;
cli(); spin_lock_irqsave(&nr_node_lock, flags);
len += sprintf(buffer, "callsign mnemonic w n qual obs neigh qual obs neigh qual obs neigh\n"); len += sprintf(buffer, "callsign mnemonic w n qual obs neigh qual obs neigh qual obs neigh\n");
for (nr_node = nr_node_list; nr_node != NULL; nr_node = nr_node->next) { for (nr_node = nr_node_list; nr_node != NULL; nr_node = nr_node->next) {
...@@ -788,8 +766,7 @@ int nr_nodes_get_info(char *buffer, char **start, off_t offset, int length) ...@@ -788,8 +766,7 @@ int nr_nodes_get_info(char *buffer, char **start, off_t offset, int length)
if (pos > offset + length) if (pos > offset + length)
break; break;
} }
spin_unlock_irqrestore(&nr_node_lock, flags);
sti();
*start = buffer + (offset - begin); *start = buffer + (offset - begin);
len -= (offset - begin); len -= (offset - begin);
...@@ -802,13 +779,13 @@ int nr_nodes_get_info(char *buffer, char **start, off_t offset, int length) ...@@ -802,13 +779,13 @@ int nr_nodes_get_info(char *buffer, char **start, off_t offset, int length)
int nr_neigh_get_info(char *buffer, char **start, off_t offset, int length) int nr_neigh_get_info(char *buffer, char **start, off_t offset, int length)
{ {
struct nr_neigh *nr_neigh; struct nr_neigh *nr_neigh;
unsigned long flags;
int len = 0; int len = 0;
off_t pos = 0; off_t pos = 0;
off_t begin = 0; off_t begin = 0;
int i; int i;
cli(); spin_lock_irqsave(&nr_neigh_lock, flags);
len += sprintf(buffer, "addr callsign dev qual lock count failed digipeaters\n"); len += sprintf(buffer, "addr callsign dev qual lock count failed digipeaters\n");
for (nr_neigh = nr_neigh_list; nr_neigh != NULL; nr_neigh = nr_neigh->next) { for (nr_neigh = nr_neigh_list; nr_neigh != NULL; nr_neigh = nr_neigh->next) {
...@@ -839,7 +816,7 @@ int nr_neigh_get_info(char *buffer, char **start, off_t offset, int length) ...@@ -839,7 +816,7 @@ int nr_neigh_get_info(char *buffer, char **start, off_t offset, int length)
break; break;
} }
sti(); spin_unlock_irqrestore(&nr_neigh_lock, flags);
*start = buffer + (offset - begin); *start = buffer + (offset - begin);
len -= (offset - begin); len -= (offset - begin);
......
/* /*
* NET/ROM release 007 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* NET/ROM 001 Jonathan(G4KLX) Cloned from ax25_subr.c
* NET/ROM 003 Jonathan(G4KLX) Added G8BPQ NET/ROM extensions.
* NET/ROM 007 Jonathan(G4KLX) New timer architecture.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* NET/ROM release 007 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* NET/ROM 001 Jonathan(G4KLX) Cloned from ax25_timer.c
* NET/ROM 007 Jonathan(G4KLX) New timer architecture.
* Implemented idle timer.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* -*- linux-c -*- /*
* sysctl_net_netrom.c: sysctl interface to net NET/ROM subsystem. * 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.
* *
* Begun April 1, 1996, Mike Shaver. * Copyright (C) 1996 Mike Shaver (shaver@zeroknowledge.com)
* Added /proc/sys/net/netrom directory entry (empty =) ). [MS]
*/ */
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/sysctl.h> #include <linux/sysctl.h>
#include <linux/init.h> #include <linux/init.h>
......
/* /*
* ROSE release 003 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
* This module: * Copyright (C) Terry Dawson VK2KTJ (terry@animats.net)
* This module is free software; you can redistribute it and/or * Copyright (C) Tomi Manninen OH2BNS (oh2bns@sral.fi)
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* ROSE 001 Jonathan(G4KLX) Cloned from af_netrom.c.
* Alan(GW4PTS) Hacked up for newer API stuff
* Terry (VK2KTJ) Added support for variable length
* address masks.
* ROSE 002 Jonathan(G4KLX) Changed hdrincl to qbitincl.
* Added random number facilities entry.
* Variable number of ROSE devices.
* ROSE 003 Jonathan(G4KLX) New timer architecture.
* Implemented idle timer.
* Added use count to neighbour.
* Tomi(OH2BNS) Fixed rose_getname().
* Arnaldo C. Melo s/suser/capable/ + micro cleanups
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -33,6 +18,7 @@ ...@@ -33,6 +18,7 @@
#include <linux/in.h> #include <linux/in.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/spinlock.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/sockios.h> #include <linux/sockios.h>
...@@ -47,7 +33,7 @@ ...@@ -47,7 +33,7 @@
#include <asm/system.h> #include <asm/system.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/fcntl.h> #include <linux/fcntl.h>
#include <linux/termios.h> /* For TIOCINQ/OUTQ */ #include <linux/termios.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/notifier.h> #include <linux/notifier.h>
...@@ -71,6 +57,7 @@ int sysctl_rose_maximum_vcs = ROSE_DEFAULT_MAXVC; ...@@ -71,6 +57,7 @@ int sysctl_rose_maximum_vcs = ROSE_DEFAULT_MAXVC;
int sysctl_rose_window_size = ROSE_DEFAULT_WINDOW_SIZE; int sysctl_rose_window_size = ROSE_DEFAULT_WINDOW_SIZE;
static struct sock *rose_list; static struct sock *rose_list;
static spinlock_t rose_list_lock = SPIN_LOCK_UNLOCKED;
static struct proto_ops rose_proto_ops; static struct proto_ops rose_proto_ops;
...@@ -175,25 +162,23 @@ static void rose_remove_socket(struct sock *sk) ...@@ -175,25 +162,23 @@ static void rose_remove_socket(struct sock *sk)
struct sock *s; struct sock *s;
unsigned long flags; unsigned long flags;
save_flags(flags); cli(); spin_lock_irqsave(&rose_list_lock, flags);
if ((s = rose_list) == sk) { if ((s = rose_list) == sk) {
rose_list = s->next; rose_list = s->next;
restore_flags(flags); spin_unlock_irqrestore(&rose_list_lock, flags);
return; return;
} }
while (s != NULL && s->next != NULL) { while (s != NULL && s->next != NULL) {
if (s->next == sk) { if (s->next == sk) {
s->next = sk->next; s->next = sk->next;
restore_flags(flags); spin_unlock_irqrestore(&rose_list_lock, flags);
return; return;
} }
s = s->next; s = s->next;
} }
spin_unlock_irqrestore(&rose_list_lock, flags);
restore_flags(flags);
} }
/* /*
...@@ -202,8 +187,10 @@ static void rose_remove_socket(struct sock *sk) ...@@ -202,8 +187,10 @@ static void rose_remove_socket(struct sock *sk)
*/ */
void rose_kill_by_neigh(struct rose_neigh *neigh) void rose_kill_by_neigh(struct rose_neigh *neigh)
{ {
unsigned long flags;
struct sock *s; struct sock *s;
spin_lock_irqsave(&rose_list_lock, flags);
for (s = rose_list; s != NULL; s = s->next) { for (s = rose_list; s != NULL; s = s->next) {
rose_cb *rose = rose_sk(s); rose_cb *rose = rose_sk(s);
...@@ -213,6 +200,7 @@ void rose_kill_by_neigh(struct rose_neigh *neigh) ...@@ -213,6 +200,7 @@ void rose_kill_by_neigh(struct rose_neigh *neigh)
rose->neighbour = NULL; rose->neighbour = NULL;
} }
} }
spin_unlock_irqrestore(&rose_list_lock, flags);
} }
/* /*
...@@ -220,8 +208,10 @@ void rose_kill_by_neigh(struct rose_neigh *neigh) ...@@ -220,8 +208,10 @@ void rose_kill_by_neigh(struct rose_neigh *neigh)
*/ */
static void rose_kill_by_device(struct net_device *dev) static void rose_kill_by_device(struct net_device *dev)
{ {
unsigned long flags;
struct sock *s; struct sock *s;
spin_lock_irqsave(&rose_list_lock, flags);
for (s = rose_list; s != NULL; s = s->next) { for (s = rose_list; s != NULL; s = s->next) {
rose_cb *rose = rose_sk(s); rose_cb *rose = rose_sk(s);
...@@ -231,12 +221,14 @@ static void rose_kill_by_device(struct net_device *dev) ...@@ -231,12 +221,14 @@ static void rose_kill_by_device(struct net_device *dev)
rose->device = NULL; rose->device = NULL;
} }
} }
spin_unlock_irqrestore(&rose_list_lock, flags);
} }
/* /*
* Handle device status changes. * Handle device status changes.
*/ */
static int rose_device_event(struct notifier_block *this, unsigned long event, void *ptr) static int rose_device_event(struct notifier_block *this, unsigned long event,
void *ptr)
{ {
struct net_device *dev = (struct net_device *)ptr; struct net_device *dev = (struct net_device *)ptr;
...@@ -263,12 +255,10 @@ static void rose_insert_socket(struct sock *sk) ...@@ -263,12 +255,10 @@ static void rose_insert_socket(struct sock *sk)
{ {
unsigned long flags; unsigned long flags;
save_flags(flags); cli(); spin_lock_irqsave(&rose_list_lock, flags);
sk->next = rose_list; sk->next = rose_list;
rose_list = sk; rose_list = sk;
spin_unlock_irqrestore(&rose_list_lock, flags);
restore_flags(flags);
} }
/* /*
...@@ -280,15 +270,14 @@ static struct sock *rose_find_listener(rose_address *addr, ax25_address *call) ...@@ -280,15 +270,14 @@ static struct sock *rose_find_listener(rose_address *addr, ax25_address *call)
unsigned long flags; unsigned long flags;
struct sock *s; struct sock *s;
save_flags(flags); cli(); spin_lock_irqsave(&rose_list_lock, flags);
for (s = rose_list; s != NULL; s = s->next) { for (s = rose_list; s != NULL; s = s->next) {
rose_cb *rose = rose_sk(s); rose_cb *rose = rose_sk(s);
if (!rosecmp(&rose->source_addr, addr) && if (!rosecmp(&rose->source_addr, addr) &&
!ax25cmp(&rose->source_call, call) && !ax25cmp(&rose->source_call, call) &&
!rose->source_ndigis && s->state == TCP_LISTEN) { !rose->source_ndigis && s->state == TCP_LISTEN) {
restore_flags(flags); spin_unlock_irqrestore(&rose_list_lock, flags);
return s; return s;
} }
} }
...@@ -299,12 +288,12 @@ static struct sock *rose_find_listener(rose_address *addr, ax25_address *call) ...@@ -299,12 +288,12 @@ static struct sock *rose_find_listener(rose_address *addr, ax25_address *call)
if (!rosecmp(&rose->source_addr, addr) && if (!rosecmp(&rose->source_addr, addr) &&
!ax25cmp(&rose->source_call, &null_ax25_address) && !ax25cmp(&rose->source_call, &null_ax25_address) &&
s->state == TCP_LISTEN) { s->state == TCP_LISTEN) {
restore_flags(flags); spin_unlock_irqrestore(&rose_list_lock, flags);
return s; return s;
} }
} }
spin_unlock_irqrestore(&rose_list_lock, flags);
restore_flags(flags);
return NULL; return NULL;
} }
...@@ -313,21 +302,19 @@ static struct sock *rose_find_listener(rose_address *addr, ax25_address *call) ...@@ -313,21 +302,19 @@ static struct sock *rose_find_listener(rose_address *addr, ax25_address *call)
*/ */
struct sock *rose_find_socket(unsigned int lci, struct rose_neigh *neigh) struct sock *rose_find_socket(unsigned int lci, struct rose_neigh *neigh)
{ {
struct sock *s;
unsigned long flags; unsigned long flags;
struct sock *s;
save_flags(flags); cli(); spin_lock_irqsave(&rose_list_lock, flags);
for (s = rose_list; s != NULL; s = s->next) { for (s = rose_list; s != NULL; s = s->next) {
rose_cb *rose = rose_sk(s); rose_cb *rose = rose_sk(s);
if (rose->lci == lci && rose->neighbour == neigh) { if (rose->lci == lci && rose->neighbour == neigh) {
restore_flags(flags); spin_unlock_irqrestore(&rose_list_lock, flags);
return s; return s;
} }
} }
spin_unlock_irqrestore(&rose_list_lock, flags);
restore_flags(flags);
return NULL; return NULL;
} }
...@@ -366,23 +353,20 @@ static void rose_destroy_timer(unsigned long data) ...@@ -366,23 +353,20 @@ static void rose_destroy_timer(unsigned long data)
} }
/* /*
* This is called from user mode and the timers. Thus it protects itself against * This is called from user mode and the timers. Thus it protects itself
* interrupt users but doesn't worry about being called during work. * against interrupt users but doesn't worry about being called during
* Once it is removed from the queue no interrupt or bottom half will * work. Once it is removed from the queue no interrupt or bottom half
* touch it and we are (fairly 8-) ) safe. * will touch it and we are (fairly 8-) ) safe.
*/ */
void rose_destroy_socket(struct sock *sk) /* Not static as it's used by the timer */ void rose_destroy_socket(struct sock *sk)
{ {
struct sk_buff *skb; struct sk_buff *skb;
unsigned long flags;
save_flags(flags); cli();
rose_remove_socket(sk);
rose_stop_heartbeat(sk); rose_stop_heartbeat(sk);
rose_stop_idletimer(sk); rose_stop_idletimer(sk);
rose_stop_timer(sk); rose_stop_timer(sk);
rose_remove_socket(sk);
rose_clear_queues(sk); /* Flush the queues */ rose_clear_queues(sk); /* Flush the queues */
while ((skb = skb_dequeue(&sk->receive_queue)) != NULL) { while ((skb = skb_dequeue(&sk->receive_queue)) != NULL) {
...@@ -405,8 +389,6 @@ void rose_destroy_socket(struct sock *sk) /* Not static as it's used by the time ...@@ -405,8 +389,6 @@ void rose_destroy_socket(struct sock *sk) /* Not static as it's used by the time
} else { } else {
rose_free_sock(sk); rose_free_sock(sk);
} }
restore_flags(flags);
} }
/* /*
...@@ -877,43 +859,55 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le ...@@ -877,43 +859,55 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le
static int rose_accept(struct socket *sock, struct socket *newsock, int flags) static int rose_accept(struct socket *sock, struct socket *newsock, int flags)
{ {
struct sock *sk; struct task_struct *tsk = current;
struct sock *newsk; DECLARE_WAITQUEUE(wait, tsk);
struct sk_buff *skb; struct sk_buff *skb;
struct sock *newsk;
struct sock *sk;
int err = 0;
if ((sk = sock->sk) == NULL) if ((sk = sock->sk) == NULL)
return -EINVAL; return -EINVAL;
if (sk->type != SOCK_SEQPACKET) lock_sock(sk);
return -EOPNOTSUPP; if (sk->type != SOCK_SEQPACKET) {
err = -EOPNOTSUPP;
goto out;
}
if (sk->state != TCP_LISTEN) if (sk->state != TCP_LISTEN) {
return -EINVAL; err = -EINVAL;
goto out;
}
/* /*
* The write queue this time is holding sockets ready to use * The write queue this time is holding sockets ready to use
* hooked into the SABM we saved * hooked into the SABM we saved
*/ */
do { add_wait_queue(sk->sleep, &wait);
cli(); for (;;) {
if ((skb = skb_dequeue(&sk->receive_queue)) == NULL) { skb = skb_dequeue(&sk->receive_queue);
if (flags & O_NONBLOCK) { if (skb)
sti(); break;
current->state = TASK_INTERRUPTIBLE;
release_sock(sk);
if (flags & O_NONBLOCK)
return -EWOULDBLOCK; return -EWOULDBLOCK;
if (!signal_pending(tsk)) {
schedule();
lock_sock(sk);
continue;
} }
interruptible_sleep_on(sk->sleep);
if (signal_pending(current)) {
sti();
return -ERESTARTSYS; return -ERESTARTSYS;
} }
} current->state = TASK_RUNNING;
} while (skb == NULL); remove_wait_queue(sk->sleep, &wait);
newsk = skb->sk; newsk = skb->sk;
newsk->pair = NULL; newsk->pair = NULL;
newsk->socket = newsock; newsk->socket = newsock;
newsk->sleep = &newsock->wait; newsk->sleep = &newsock->wait;
sti();
/* Now attach up the new socket */ /* Now attach up the new socket */
skb->sk = NULL; skb->sk = NULL;
...@@ -921,7 +915,10 @@ static int rose_accept(struct socket *sock, struct socket *newsock, int flags) ...@@ -921,7 +915,10 @@ static int rose_accept(struct socket *sock, struct socket *newsock, int flags)
sk->ack_backlog--; sk->ack_backlog--;
newsock->sk = newsk; newsock->sk = newsk;
return 0; out:
release_sock(sk);
return err;
} }
static int rose_getname(struct socket *sock, struct sockaddr *uaddr, static int rose_getname(struct socket *sock, struct sockaddr *uaddr,
...@@ -1366,6 +1363,7 @@ static int rose_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1366,6 +1363,7 @@ static int rose_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
static int rose_get_info(char *buffer, char **start, off_t offset, int length) static int rose_get_info(char *buffer, char **start, off_t offset, int length)
{ {
unsigned long flags;
struct sock *s; struct sock *s;
struct net_device *dev; struct net_device *dev;
const char *devname, *callsign; const char *devname, *callsign;
...@@ -1373,7 +1371,7 @@ static int rose_get_info(char *buffer, char **start, off_t offset, int length) ...@@ -1373,7 +1371,7 @@ static int rose_get_info(char *buffer, char **start, off_t offset, int length)
off_t pos = 0; off_t pos = 0;
off_t begin = 0; off_t begin = 0;
cli(); spin_lock_irqsave(&rose_list_lock, flags);
len += sprintf(buffer, "dest_addr dest_call src_addr src_call dev lci neigh st vs vr va t t1 t2 t3 hb idle Snd-Q Rcv-Q inode\n"); len += sprintf(buffer, "dest_addr dest_call src_addr src_call dev lci neigh st vs vr va t t1 t2 t3 hb idle Snd-Q Rcv-Q inode\n");
...@@ -1425,15 +1423,14 @@ static int rose_get_info(char *buffer, char **start, off_t offset, int length) ...@@ -1425,15 +1423,14 @@ static int rose_get_info(char *buffer, char **start, off_t offset, int length)
if (pos > offset + length) if (pos > offset + length)
break; break;
} }
spin_unlock_irqrestore(&rose_list_lock, flags);
sti();
*start = buffer + (offset - begin); *start = buffer + (offset - begin);
len -= (offset - begin); len -= (offset - begin);
if (len > length) len = length; if (len > length) len = length;
return(len); return len;
} }
static struct net_proto_family rose_family_ops = { static struct net_proto_family rose_family_ops = {
...@@ -1441,7 +1438,7 @@ static struct net_proto_family rose_family_ops = { ...@@ -1441,7 +1438,7 @@ static struct net_proto_family rose_family_ops = {
.create = rose_create, .create = rose_create,
}; };
static struct proto_ops SOCKOPS_WRAPPED(rose_proto_ops) = { static struct proto_ops rose_proto_ops = {
.family = PF_ROSE, .family = PF_ROSE,
.release = rose_release, .release = rose_release,
...@@ -1462,11 +1459,8 @@ static struct proto_ops SOCKOPS_WRAPPED(rose_proto_ops) = { ...@@ -1462,11 +1459,8 @@ static struct proto_ops SOCKOPS_WRAPPED(rose_proto_ops) = {
.sendpage = sock_no_sendpage, .sendpage = sock_no_sendpage,
}; };
#include <linux/smp_lock.h>
SOCKOPS_WRAP(rose_proto, PF_ROSE);
static struct notifier_block rose_dev_notifier = { static struct notifier_block rose_dev_notifier = {
.notifier_call =rose_device_event, .notifier_call = rose_device_event,
}; };
static struct net_device *dev_rose; static struct net_device *dev_rose;
...@@ -1562,5 +1556,5 @@ static void __exit rose_exit(void) ...@@ -1562,5 +1556,5 @@ static void __exit rose_exit(void)
kfree(dev_rose); kfree(dev_rose);
} }
module_exit(rose_exit);
module_exit(rose_exit);
/* /*
* ROSE release 003 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* ROSE 001 Jonathan(G4KLX) Cloned from nr_dev.c.
* Hans(PE1AYX) Fixed interface to IP layer.
*/ */
#include <linux/config.h> #include <linux/config.h>
#define __NO_VERSION__ #define __NO_VERSION__
#include <linux/module.h> #include <linux/module.h>
...@@ -29,7 +21,7 @@ ...@@ -29,7 +21,7 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/fcntl.h> #include <linux/fcntl.h>
#include <linux/in.h> #include <linux/in.h>
#include <linux/if_ether.h> /* For the statistics structure. */ #include <linux/if_ether.h>
#include <asm/system.h> #include <asm/system.h>
#include <asm/io.h> #include <asm/io.h>
......
/* /*
* ROSE release 003 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* *
* This module: * Most of this code is based on the SDL diagrams published in the 7th ARRL
* This module is free software; you can redistribute it and/or * Computer Networking Conference papers. The diagrams have mistakes in them,
* modify it under the terms of the GNU General Public License * but are mostly correct. Before you modify the code could you read the SDL
* as published by the Free Software Foundation; either version * diagrams as the code is not obvious and probably very easy to break.
* 2 of the License, or (at your option) any later version.
*
* Most of this code is based on the SDL diagrams published in the 7th
* ARRL Computer Networking Conference papers. The diagrams have mistakes
* in them, but are mostly correct. Before you modify the code could you
* read the SDL diagrams as the code is not obvious and probably very
* easy to break;
*
* History
* ROSE 001 Jonathan(G4KLX) Cloned from nr_in.c
* ROSE 002 Jonathan(G4KLX) Return cause and diagnostic codes from Clear Requests.
* ROSE 003 Jonathan(G4KLX) New timer architecture.
* Removed M bit processing.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* ROSE release 003 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* ROSE 001 Jonathan(G4KLX) Cloned from rose_timer.c
* ROSE 003 Jonathan(G4KLX) New timer architecture.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* ROSE release 003 * 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
* This code REQUIRES 2.1.15 or higher/ NET3.038 * the Free Software Foundation; either version 2 of the License, or
* * (at your option) any later version.
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* ROSE 003 Jonathan(G4KLX) Created this file from nr_loopback.c.
* *
* Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*/ */
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
#include <linux/timer.h> #include <linux/timer.h>
......
/* /*
* ROSE release 003 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* ROSE 001 Jonathan(G4KLX) Cloned from nr_out.c
* ROSE 003 Jonathan(G4KLX) New timer architecture.
* Removed M bit processing.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* ROSE release 003 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* * Copyright (C) Terry Dawson VK2KTJ (terry@animats.net)
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* ROSE 001 Jonathan(G4KLX) Cloned from nr_route.c.
* Terry(VK2KTJ) Added support for variable length
* address masks.
* ROSE 002 Jonathan(G4KLX) Uprated through routing of packets.
* Routing loop detection.
* ROSE 003 Jonathan(G4KLX) New timer architecture.
* Added use count to neighbours.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
...@@ -51,8 +39,11 @@ ...@@ -51,8 +39,11 @@
static unsigned int rose_neigh_no = 1; static unsigned int rose_neigh_no = 1;
static struct rose_node *rose_node_list; static struct rose_node *rose_node_list;
static spinlock_t rose_node_list_lock = SPIN_LOCK_UNLOCKED;
static struct rose_neigh *rose_neigh_list; static struct rose_neigh *rose_neigh_list;
static spinlock_t rose_neigh_list_lock = SPIN_LOCK_UNLOCKED;
static struct rose_route *rose_route_list; static struct rose_route *rose_route_list;
static spinlock_t rose_route_list_lock = SPIN_LOCK_UNLOCKED;
struct rose_neigh *rose_loopback_neigh; struct rose_neigh *rose_loopback_neigh;
...@@ -62,27 +53,45 @@ static void rose_remove_neigh(struct rose_neigh *); ...@@ -62,27 +53,45 @@ static void rose_remove_neigh(struct rose_neigh *);
* Add a new route to a node, and in the process add the node and the * Add a new route to a node, and in the process add the node and the
* neighbour if it is new. * neighbour if it is new.
*/ */
static int rose_add_node(struct rose_route_struct *rose_route, struct net_device *dev) static int rose_add_node(struct rose_route_struct *rose_route,
struct net_device *dev)
{ {
struct rose_node *rose_node, *rose_tmpn, *rose_tmpp; struct rose_node *rose_node, *rose_tmpn, *rose_tmpp;
struct rose_neigh *rose_neigh; struct rose_neigh *rose_neigh;
unsigned long flags; unsigned long flags;
int i; int i, res = 0;
spin_lock_irqsave(&rose_node_list_lock, flags);
spin_lock_irqsave(&rose_neigh_list_lock, flags);
for (rose_node = rose_node_list; rose_node != NULL; rose_node = rose_node->next) rose_node = rose_node_list;
if ((rose_node->mask == rose_route->mask) && (rosecmpm(&rose_route->address, &rose_node->address, rose_route->mask) == 0)) while (rose_node != NULL) {
if ((rose_node->mask == rose_route->mask) &&
(rosecmpm(&rose_route->address, &rose_node->address,
rose_route->mask) == 0))
break; break;
rose_node = rose_node->next;
}
if (rose_node != NULL && rose_node->loopback) if (rose_node != NULL && rose_node->loopback) {
return -EINVAL; res = -EINVAL;
goto out;
}
for (rose_neigh = rose_neigh_list; rose_neigh != NULL; rose_neigh = rose_neigh->next) rose_neigh = rose_neigh_list;
if (ax25cmp(&rose_route->neighbour, &rose_neigh->callsign) == 0 && rose_neigh->dev == dev) while (rose_neigh != NULL) {
if (ax25cmp(&rose_route->neighbour, &rose_neigh->callsign) == 0
&& rose_neigh->dev == dev)
break; break;
rose_neigh = rose_neigh->next;
}
if (rose_neigh == NULL) { if (rose_neigh == NULL) {
if ((rose_neigh = kmalloc(sizeof(*rose_neigh), GFP_ATOMIC)) == NULL) rose_neigh = kmalloc(sizeof(*rose_neigh), GFP_ATOMIC);
return -ENOMEM; if (rose_neigh == NULL) {
res = -ENOMEM;
goto out;
}
rose_neigh->callsign = rose_route->neighbour; rose_neigh->callsign = rose_route->neighbour;
rose_neigh->digipeat = NULL; rose_neigh->digipeat = NULL;
...@@ -103,22 +112,22 @@ static int rose_add_node(struct rose_route_struct *rose_route, struct net_device ...@@ -103,22 +112,22 @@ static int rose_add_node(struct rose_route_struct *rose_route, struct net_device
if (rose_route->ndigis != 0) { if (rose_route->ndigis != 0) {
if ((rose_neigh->digipeat = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) { if ((rose_neigh->digipeat = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) {
kfree(rose_neigh); kfree(rose_neigh);
return -ENOMEM; res = -ENOMEM;
goto out;
} }
rose_neigh->digipeat->ndigi = rose_route->ndigis; rose_neigh->digipeat->ndigi = rose_route->ndigis;
rose_neigh->digipeat->lastrepeat = -1; rose_neigh->digipeat->lastrepeat = -1;
for (i = 0; i < rose_route->ndigis; i++) { for (i = 0; i < rose_route->ndigis; i++) {
rose_neigh->digipeat->calls[i] = rose_route->digipeaters[i]; rose_neigh->digipeat->calls[i] =
rose_route->digipeaters[i];
rose_neigh->digipeat->repeated[i] = 0; rose_neigh->digipeat->repeated[i] = 0;
} }
} }
save_flags(flags); cli();
rose_neigh->next = rose_neigh_list; rose_neigh->next = rose_neigh_list;
rose_neigh_list = rose_neigh; rose_neigh_list = rose_neigh;
restore_flags(flags);
} }
/* /*
...@@ -142,8 +151,11 @@ static int rose_add_node(struct rose_route_struct *rose_route, struct net_device ...@@ -142,8 +151,11 @@ static int rose_add_node(struct rose_route_struct *rose_route, struct net_device
} }
/* create new node */ /* create new node */
if ((rose_node = kmalloc(sizeof(*rose_node), GFP_ATOMIC)) == NULL) rose_node = kmalloc(sizeof(*rose_node), GFP_ATOMIC);
return -ENOMEM; if (rose_node == NULL) {
res = -ENOMEM;
goto out;
}
rose_node->address = rose_route->address; rose_node->address = rose_route->address;
rose_node->mask = rose_route->mask; rose_node->mask = rose_route->mask;
...@@ -151,8 +163,6 @@ static int rose_add_node(struct rose_route_struct *rose_route, struct net_device ...@@ -151,8 +163,6 @@ static int rose_add_node(struct rose_route_struct *rose_route, struct net_device
rose_node->loopback = 0; rose_node->loopback = 0;
rose_node->neighbour[0] = rose_neigh; rose_node->neighbour[0] = rose_neigh;
save_flags(flags); cli();
if (rose_tmpn == NULL) { if (rose_tmpn == NULL) {
if (rose_tmpp == NULL) { /* Empty list */ if (rose_tmpp == NULL) { /* Empty list */
rose_node_list = rose_node; rose_node_list = rose_node;
...@@ -170,12 +180,9 @@ static int rose_add_node(struct rose_route_struct *rose_route, struct net_device ...@@ -170,12 +180,9 @@ static int rose_add_node(struct rose_route_struct *rose_route, struct net_device
rose_node->next = rose_tmpn; rose_node->next = rose_tmpn;
} }
} }
restore_flags(flags);
rose_neigh->count++; rose_neigh->count++;
return 0; goto out;
} }
/* We have space, slot it in */ /* We have space, slot it in */
...@@ -185,20 +192,24 @@ static int rose_add_node(struct rose_route_struct *rose_route, struct net_device ...@@ -185,20 +192,24 @@ static int rose_add_node(struct rose_route_struct *rose_route, struct net_device
rose_neigh->count++; rose_neigh->count++;
} }
return 0; out:
spin_unlock_irqrestore(&rose_neigh_list_lock, flags);
spin_unlock_irqrestore(&rose_node_list_lock, flags);
return res;
} }
/*
* Caller is holding rose_node_list_lock.
*/
static void rose_remove_node(struct rose_node *rose_node) static void rose_remove_node(struct rose_node *rose_node)
{ {
struct rose_node *s;
unsigned long flags; unsigned long flags;
struct rose_node *s;
save_flags(flags); spin_lock_irqsave(&rose_node_list_lock, flags);
cli();
if ((s = rose_node_list) == rose_node) { if ((s = rose_node_list) == rose_node) {
rose_node_list = rose_node->next; rose_node_list = rose_node->next;
restore_flags(flags);
kfree(rose_node); kfree(rose_node);
return; return;
} }
...@@ -206,17 +217,17 @@ static void rose_remove_node(struct rose_node *rose_node) ...@@ -206,17 +217,17 @@ static void rose_remove_node(struct rose_node *rose_node)
while (s != NULL && s->next != NULL) { while (s != NULL && s->next != NULL) {
if (s->next == rose_node) { if (s->next == rose_node) {
s->next = rose_node->next; s->next = rose_node->next;
restore_flags(flags);
kfree(rose_node); kfree(rose_node);
return; return;
} }
s = s->next; s = s->next;
} }
restore_flags(flags);
} }
/*
* Caller is holding rose_neigh_list_lock.
*/
static void rose_remove_neigh(struct rose_neigh *rose_neigh) static void rose_remove_neigh(struct rose_neigh *rose_neigh)
{ {
struct rose_neigh *s; struct rose_neigh *s;
...@@ -227,11 +238,11 @@ static void rose_remove_neigh(struct rose_neigh *rose_neigh) ...@@ -227,11 +238,11 @@ static void rose_remove_neigh(struct rose_neigh *rose_neigh)
skb_queue_purge(&rose_neigh->queue); skb_queue_purge(&rose_neigh->queue);
save_flags(flags); cli(); spin_lock_irqsave(&rose_neigh_list_lock, flags);
if ((s = rose_neigh_list) == rose_neigh) { if ((s = rose_neigh_list) == rose_neigh) {
rose_neigh_list = rose_neigh->next; rose_neigh_list = rose_neigh->next;
restore_flags(flags); spin_unlock_irqrestore(&rose_neigh_list_lock, flags);
if (rose_neigh->digipeat != NULL) if (rose_neigh->digipeat != NULL)
kfree(rose_neigh->digipeat); kfree(rose_neigh->digipeat);
kfree(rose_neigh); kfree(rose_neigh);
...@@ -241,7 +252,7 @@ static void rose_remove_neigh(struct rose_neigh *rose_neigh) ...@@ -241,7 +252,7 @@ static void rose_remove_neigh(struct rose_neigh *rose_neigh)
while (s != NULL && s->next != NULL) { while (s != NULL && s->next != NULL) {
if (s->next == rose_neigh) { if (s->next == rose_neigh) {
s->next = rose_neigh->next; s->next = rose_neigh->next;
restore_flags(flags); spin_unlock_irqrestore(&rose_neigh_list_lock, flags);
if (rose_neigh->digipeat != NULL) if (rose_neigh->digipeat != NULL)
kfree(rose_neigh->digipeat); kfree(rose_neigh->digipeat);
kfree(rose_neigh); kfree(rose_neigh);
...@@ -250,14 +261,15 @@ static void rose_remove_neigh(struct rose_neigh *rose_neigh) ...@@ -250,14 +261,15 @@ static void rose_remove_neigh(struct rose_neigh *rose_neigh)
s = s->next; s = s->next;
} }
spin_unlock_irqrestore(&rose_neigh_list_lock, flags);
restore_flags(flags);
} }
/*
* Caller is holding rose_route_list_lock.
*/
static void rose_remove_route(struct rose_route *rose_route) static void rose_remove_route(struct rose_route *rose_route)
{ {
struct rose_route *s; struct rose_route *s;
unsigned long flags;
if (rose_route->neigh1 != NULL) if (rose_route->neigh1 != NULL)
rose_route->neigh1->use--; rose_route->neigh1->use--;
...@@ -265,11 +277,8 @@ static void rose_remove_route(struct rose_route *rose_route) ...@@ -265,11 +277,8 @@ static void rose_remove_route(struct rose_route *rose_route)
if (rose_route->neigh2 != NULL) if (rose_route->neigh2 != NULL)
rose_route->neigh2->use--; rose_route->neigh2->use--;
save_flags(flags); cli();
if ((s = rose_route_list) == rose_route) { if ((s = rose_route_list) == rose_route) {
rose_route_list = rose_route->next; rose_route_list = rose_route->next;
restore_flags(flags);
kfree(rose_route); kfree(rose_route);
return; return;
} }
...@@ -277,40 +286,55 @@ static void rose_remove_route(struct rose_route *rose_route) ...@@ -277,40 +286,55 @@ static void rose_remove_route(struct rose_route *rose_route)
while (s != NULL && s->next != NULL) { while (s != NULL && s->next != NULL) {
if (s->next == rose_route) { if (s->next == rose_route) {
s->next = rose_route->next; s->next = rose_route->next;
restore_flags(flags);
kfree(rose_route); kfree(rose_route);
return; return;
} }
s = s->next; s = s->next;
} }
restore_flags(flags);
} }
/* /*
* "Delete" a node. Strictly speaking remove a route to a node. The node * "Delete" a node. Strictly speaking remove a route to a node. The node
* is only deleted if no routes are left to it. * is only deleted if no routes are left to it.
*/ */
static int rose_del_node(struct rose_route_struct *rose_route, struct net_device *dev) static int rose_del_node(struct rose_route_struct *rose_route,
struct net_device *dev)
{ {
struct rose_node *rose_node; struct rose_node *rose_node;
struct rose_neigh *rose_neigh; struct rose_neigh *rose_neigh;
int i; unsigned long flags;
int i, err = 0;
for (rose_node = rose_node_list; rose_node != NULL; rose_node = rose_node->next) spin_lock_irqsave(&rose_node_list_lock, flags);
if ((rose_node->mask == rose_route->mask) && (rosecmpm(&rose_route->address, &rose_node->address, rose_route->mask) == 0)) spin_lock_irqsave(&rose_neigh_list_lock, flags);
break;
if (rose_node == NULL) return -EINVAL; rose_node = rose_node_list;
while (rose_node != NULL) {
if ((rose_node->mask == rose_route->mask) &&
(rosecmpm(&rose_route->address, &rose_node->address,
rose_route->mask) == 0))
break;
rose_node = rose_node->next;
}
if (rose_node->loopback) return -EINVAL; if (rose_node == NULL || rose_node->loopback) {
err = -EINVAL;
goto out;
}
for (rose_neigh = rose_neigh_list; rose_neigh != NULL; rose_neigh = rose_neigh->next) rose_neigh = rose_neigh_list;
if (ax25cmp(&rose_route->neighbour, &rose_neigh->callsign) == 0 && rose_neigh->dev == dev) while (rose_neigh != NULL) {
if (ax25cmp(&rose_route->neighbour, &rose_neigh->callsign) == 0
&& rose_neigh->dev == dev)
break; break;
rose_neigh = rose_neigh->next;
}
if (rose_neigh == NULL) return -EINVAL; if (rose_neigh == NULL) {
err = -EINVAL;
goto out;
}
for (i = 0; i < rose_node->count; i++) { for (i = 0; i < rose_node->count; i++) {
if (rose_node->neighbour[i] == rose_neigh) { if (rose_node->neighbour[i] == rose_neigh) {
...@@ -326,19 +350,25 @@ static int rose_del_node(struct rose_route_struct *rose_route, struct net_device ...@@ -326,19 +350,25 @@ static int rose_del_node(struct rose_route_struct *rose_route, struct net_device
} else { } else {
switch (i) { switch (i) {
case 0: case 0:
rose_node->neighbour[0] = rose_node->neighbour[1]; rose_node->neighbour[0] =
rose_node->neighbour[1];
case 1: case 1:
rose_node->neighbour[1] = rose_node->neighbour[2]; rose_node->neighbour[1] =
rose_node->neighbour[2];
case 2: case 2:
break; break;
} }
} }
goto out;
return 0;
} }
} }
err = -EINVAL;
return -EINVAL; out:
spin_unlock_irqrestore(&rose_neigh_list_lock, flags);
spin_unlock_irqrestore(&rose_node_list_lock, flags);
return err;
} }
/* /*
...@@ -367,10 +397,10 @@ int rose_add_loopback_neigh(void) ...@@ -367,10 +397,10 @@ int rose_add_loopback_neigh(void)
init_timer(&rose_loopback_neigh->ftimer); init_timer(&rose_loopback_neigh->ftimer);
init_timer(&rose_loopback_neigh->t0timer); init_timer(&rose_loopback_neigh->t0timer);
save_flags(flags); cli(); spin_lock_irqsave(&rose_neigh_list_lock, flags);
rose_loopback_neigh->next = rose_neigh_list; rose_loopback_neigh->next = rose_neigh_list;
rose_neigh_list = rose_loopback_neigh; rose_neigh_list = rose_loopback_neigh;
restore_flags(flags); spin_unlock_irqrestore(&rose_neigh_list_lock, flags);
return 0; return 0;
} }
...@@ -382,15 +412,26 @@ int rose_add_loopback_node(rose_address *address) ...@@ -382,15 +412,26 @@ int rose_add_loopback_node(rose_address *address)
{ {
struct rose_node *rose_node; struct rose_node *rose_node;
unsigned long flags; unsigned long flags;
unsigned int err = 0;
spin_lock_irqsave(&rose_node_list_lock, flags);
for (rose_node = rose_node_list; rose_node != NULL; rose_node = rose_node->next) rose_node = rose_node_list;
if ((rose_node->mask == 10) && (rosecmpm(address, &rose_node->address, 10) == 0) && rose_node->loopback) while (rose_node != NULL) {
if ((rose_node->mask == 10) &&
(rosecmpm(address, &rose_node->address, 10) == 0) &&
rose_node->loopback)
break; break;
rose_node = rose_node->next;
}
if (rose_node != NULL) return 0; if (rose_node != NULL)
goto out;
if ((rose_node = kmalloc(sizeof(*rose_node), GFP_ATOMIC)) == NULL) if ((rose_node = kmalloc(sizeof(*rose_node), GFP_ATOMIC)) == NULL) {
return -ENOMEM; err = -ENOMEM;
goto out;
}
rose_node->address = *address; rose_node->address = *address;
rose_node->mask = 10; rose_node->mask = 10;
...@@ -399,13 +440,14 @@ int rose_add_loopback_node(rose_address *address) ...@@ -399,13 +440,14 @@ int rose_add_loopback_node(rose_address *address)
rose_node->neighbour[0] = rose_loopback_neigh; rose_node->neighbour[0] = rose_loopback_neigh;
/* Insert at the head of list. Address is always mask=10 */ /* Insert at the head of list. Address is always mask=10 */
save_flags(flags); cli();
rose_node->next = rose_node_list; rose_node->next = rose_node_list;
rose_node_list = rose_node; rose_node_list = rose_node;
restore_flags(flags);
rose_loopback_neigh->count++; rose_loopback_neigh->count++;
out:
spin_unlock_irqrestore(&rose_node_list_lock, flags);
return 0; return 0;
} }
...@@ -415,16 +457,28 @@ int rose_add_loopback_node(rose_address *address) ...@@ -415,16 +457,28 @@ int rose_add_loopback_node(rose_address *address)
void rose_del_loopback_node(rose_address *address) void rose_del_loopback_node(rose_address *address)
{ {
struct rose_node *rose_node; struct rose_node *rose_node;
unsigned long flags;
for (rose_node = rose_node_list; rose_node != NULL; rose_node = rose_node->next) spin_lock_irqsave(&rose_node_list_lock, flags);
if ((rose_node->mask == 10) && (rosecmpm(address, &rose_node->address, 10) == 0) && rose_node->loopback)
rose_node = rose_node_list;
while (rose_node != NULL) {
if ((rose_node->mask == 10) &&
(rosecmpm(address, &rose_node->address, 10) == 0) &&
rose_node->loopback)
break; break;
rose_node = rose_node->next;
}
if (rose_node == NULL) return; if (rose_node == NULL)
goto out;
rose_remove_node(rose_node); rose_remove_node(rose_node);
rose_loopback_neigh->count--; rose_loopback_neigh->count--;
out:
spin_unlock_irqrestore(&rose_node_list_lock, flags);
} }
/* /*
...@@ -432,15 +486,21 @@ void rose_del_loopback_node(rose_address *address) ...@@ -432,15 +486,21 @@ void rose_del_loopback_node(rose_address *address)
*/ */
void rose_rt_device_down(struct net_device *dev) void rose_rt_device_down(struct net_device *dev)
{ {
struct rose_neigh *s, *rose_neigh = rose_neigh_list; struct rose_neigh *s, *rose_neigh;
struct rose_node *t, *rose_node; struct rose_node *t, *rose_node;
unsigned long flags;
int i; int i;
spin_lock_irqsave(&rose_node_list_lock, flags);
spin_lock_irqsave(&rose_neigh_list_lock, flags);
rose_neigh = rose_neigh_list;
while (rose_neigh != NULL) { while (rose_neigh != NULL) {
s = rose_neigh; s = rose_neigh;
rose_neigh = rose_neigh->next; rose_neigh = rose_neigh->next;
if (s->dev == dev) { if (s->dev != dev)
continue;
rose_node = rose_node_list; rose_node = rose_node_list;
while (rose_node != NULL) { while (rose_node != NULL) {
...@@ -448,7 +508,9 @@ void rose_rt_device_down(struct net_device *dev) ...@@ -448,7 +508,9 @@ void rose_rt_device_down(struct net_device *dev)
rose_node = rose_node->next; rose_node = rose_node->next;
for (i = 0; i < t->count; i++) { for (i = 0; i < t->count; i++) {
if (t->neighbour[i] == s) { if (t->neighbour[i] != s)
continue;
t->count--; t->count--;
switch (i) { switch (i) {
...@@ -460,7 +522,6 @@ void rose_rt_device_down(struct net_device *dev) ...@@ -460,7 +522,6 @@ void rose_rt_device_down(struct net_device *dev)
break; break;
} }
} }
}
if (t->count <= 0) if (t->count <= 0)
rose_remove_node(t); rose_remove_node(t);
...@@ -468,16 +529,21 @@ void rose_rt_device_down(struct net_device *dev) ...@@ -468,16 +529,21 @@ void rose_rt_device_down(struct net_device *dev)
rose_remove_neigh(s); rose_remove_neigh(s);
} }
} spin_unlock_irqrestore(&rose_neigh_list_lock, flags);
spin_unlock_irqrestore(&rose_node_list_lock, flags);
} }
#if 0 /* Currently unused */
/* /*
* A device has been removed. Remove its links. * A device has been removed. Remove its links.
*/ */
void rose_route_device_down(struct net_device *dev) void rose_route_device_down(struct net_device *dev)
{ {
struct rose_route *s, *rose_route = rose_route_list; struct rose_route *s, *rose_route;
unsigned long flags;
spin_lock_irqsave(&rose_route_list_lock, flags);
rose_route = rose_route_list;
while (rose_route != NULL) { while (rose_route != NULL) {
s = rose_route; s = rose_route;
rose_route = rose_route->next; rose_route = rose_route->next;
...@@ -485,7 +551,9 @@ void rose_route_device_down(struct net_device *dev) ...@@ -485,7 +551,9 @@ void rose_route_device_down(struct net_device *dev)
if (s->neigh1->dev == dev || s->neigh2->dev == dev) if (s->neigh1->dev == dev || s->neigh2->dev == dev)
rose_remove_route(s); rose_remove_route(s);
} }
spin_unlock_irqrestore(&rose_route_list_lock, flags);
} }
#endif
/* /*
* Clear all nodes and neighbours out, except for neighbours with * Clear all nodes and neighbours out, except for neighbours with
...@@ -494,8 +562,15 @@ void rose_route_device_down(struct net_device *dev) ...@@ -494,8 +562,15 @@ void rose_route_device_down(struct net_device *dev)
*/ */
static int rose_clear_routes(void) static int rose_clear_routes(void)
{ {
struct rose_neigh *s, *rose_neigh = rose_neigh_list; struct rose_neigh *s, *rose_neigh;
struct rose_node *t, *rose_node = rose_node_list; struct rose_node *t, *rose_node;
unsigned long flags;
spin_lock_irqsave(&rose_node_list_lock, flags);
spin_lock_irqsave(&rose_neigh_list_lock, flags);
rose_neigh = rose_neigh_list;
rose_node = rose_node_list;
while (rose_node != NULL) { while (rose_node != NULL) {
t = rose_node; t = rose_node;
...@@ -514,6 +589,9 @@ static int rose_clear_routes(void) ...@@ -514,6 +589,9 @@ static int rose_clear_routes(void)
} }
} }
spin_unlock_irqrestore(&rose_neigh_list_lock, flags);
spin_unlock_irqrestore(&rose_node_list_lock, flags);
return 0; return 0;
} }
...@@ -603,18 +681,23 @@ struct rose_route *rose_route_free_lci(unsigned int lci, struct rose_neigh *neig ...@@ -603,18 +681,23 @@ struct rose_route *rose_route_free_lci(unsigned int lci, struct rose_neigh *neig
/* /*
* Find a neighbour given a ROSE address. * Find a neighbour given a ROSE address.
*/ */
struct rose_neigh *rose_get_neigh(rose_address *addr, unsigned char *cause, unsigned char *diagnostic) struct rose_neigh *rose_get_neigh(rose_address *addr, unsigned char *cause,
unsigned char *diagnostic)
{ {
struct rose_neigh *res = NULL;
struct rose_node *node; struct rose_node *node;
unsigned long flags;
int failed = 0; int failed = 0;
int i; int i;
spin_lock_irqsave(&rose_node_list_lock, flags);
for (node = rose_node_list; node != NULL; node = node->next) { for (node = rose_node_list; node != NULL; node = node->next) {
if (rosecmpm(addr, &node->address, node->mask) == 0) { if (rosecmpm(addr, &node->address, node->mask) == 0) {
for (i = 0; i < node->count; i++) { for (i = 0; i < node->count; i++) {
if (!rose_ftimer_running(node->neighbour[i])) { if (!rose_ftimer_running(node->neighbour[i])) {
return node->neighbour[i]; } res = node->neighbour[i];
else goto out;
} else
failed = 1; failed = 1;
} }
break; break;
...@@ -629,7 +712,10 @@ struct rose_neigh *rose_get_neigh(rose_address *addr, unsigned char *cause, unsi ...@@ -629,7 +712,10 @@ struct rose_neigh *rose_get_neigh(rose_address *addr, unsigned char *cause, unsi
*diagnostic = 0; *diagnostic = 0;
} }
return NULL; out:
spin_unlock_irqrestore(&rose_node_list_lock, flags);
return res;
} }
/* /*
...@@ -642,7 +728,6 @@ int rose_rt_ioctl(unsigned int cmd, void *arg) ...@@ -642,7 +728,6 @@ int rose_rt_ioctl(unsigned int cmd, void *arg)
int err; int err;
switch (cmd) { switch (cmd) {
case SIOCADDRT: case SIOCADDRT:
if (copy_from_user(&rose_route, arg, sizeof(struct rose_route_struct))) if (copy_from_user(&rose_route, arg, sizeof(struct rose_route_struct)))
return -EFAULT; return -EFAULT;
...@@ -668,7 +753,6 @@ int rose_rt_ioctl(unsigned int cmd, void *arg) ...@@ -668,7 +753,6 @@ int rose_rt_ioctl(unsigned int cmd, void *arg)
dev_put(dev); dev_put(dev);
return err; return err;
case SIOCRSCLRRT: case SIOCRSCLRRT:
return rose_clear_routes(); return rose_clear_routes();
...@@ -682,6 +766,7 @@ int rose_rt_ioctl(unsigned int cmd, void *arg) ...@@ -682,6 +766,7 @@ int rose_rt_ioctl(unsigned int cmd, void *arg)
static void rose_del_route_by_neigh(struct rose_neigh *rose_neigh) static void rose_del_route_by_neigh(struct rose_neigh *rose_neigh)
{ {
struct rose_route *rose_route, *s; struct rose_route *rose_route, *s;
unsigned long flags;
rose_neigh->restarted = 0; rose_neigh->restarted = 0;
...@@ -690,6 +775,8 @@ static void rose_del_route_by_neigh(struct rose_neigh *rose_neigh) ...@@ -690,6 +775,8 @@ static void rose_del_route_by_neigh(struct rose_neigh *rose_neigh)
skb_queue_purge(&rose_neigh->queue); skb_queue_purge(&rose_neigh->queue);
spin_lock_irqsave(&rose_route_list_lock, flags);
rose_route = rose_route_list; rose_route = rose_route_list;
while (rose_route != NULL) { while (rose_route != NULL) {
...@@ -716,6 +803,7 @@ static void rose_del_route_by_neigh(struct rose_neigh *rose_neigh) ...@@ -716,6 +803,7 @@ static void rose_del_route_by_neigh(struct rose_neigh *rose_neigh)
rose_route = rose_route->next; rose_route = rose_route->next;
} }
spin_unlock_irqrestore(&rose_route_list_lock, flags);
} }
/* /*
...@@ -726,17 +814,23 @@ static void rose_del_route_by_neigh(struct rose_neigh *rose_neigh) ...@@ -726,17 +814,23 @@ static void rose_del_route_by_neigh(struct rose_neigh *rose_neigh)
void rose_link_failed(ax25_cb *ax25, int reason) void rose_link_failed(ax25_cb *ax25, int reason)
{ {
struct rose_neigh *rose_neigh; struct rose_neigh *rose_neigh;
unsigned long flags;
for (rose_neigh = rose_neigh_list; rose_neigh != NULL; rose_neigh = rose_neigh->next) spin_lock_irqsave(&rose_neigh_list_lock, flags);
rose_neigh = rose_neigh_list;
while (rose_neigh != NULL) {
if (rose_neigh->ax25 == ax25) if (rose_neigh->ax25 == ax25)
break; break;
rose_neigh = rose_neigh->next;
}
if (rose_neigh == NULL) return; if (rose_neigh != NULL) {
rose_neigh->ax25 = NULL; rose_neigh->ax25 = NULL;
rose_del_route_by_neigh(rose_neigh); rose_del_route_by_neigh(rose_neigh);
rose_kill_by_neigh(rose_neigh); rose_kill_by_neigh(rose_neigh);
}
spin_unlock_irqrestore(&rose_neigh_list_lock, flags);
} }
/* /*
...@@ -770,11 +864,11 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25) ...@@ -770,11 +864,11 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)
unsigned char cause, diagnostic; unsigned char cause, diagnostic;
struct net_device *dev; struct net_device *dev;
unsigned long flags; unsigned long flags;
int len; int len, res = 0;
#if 0 #if 0
if (call_in_firewall(PF_ROSE, skb->dev, skb->data, NULL, &skb) != FW_ACCEPT) if (call_in_firewall(PF_ROSE, skb->dev, skb->data, NULL, &skb) != FW_ACCEPT)
return 0; return res;
#endif #endif
frametype = skb->data[2]; frametype = skb->data[2];
...@@ -782,13 +876,22 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25) ...@@ -782,13 +876,22 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)
src_addr = (rose_address *)(skb->data + 9); src_addr = (rose_address *)(skb->data + 9);
dest_addr = (rose_address *)(skb->data + 4); dest_addr = (rose_address *)(skb->data + 4);
for (rose_neigh = rose_neigh_list; rose_neigh != NULL; rose_neigh = rose_neigh->next) spin_lock_irqsave(&rose_node_list_lock, flags);
if (ax25cmp(&ax25->dest_addr, &rose_neigh->callsign) == 0 && ax25->ax25_dev->dev == rose_neigh->dev) spin_lock_irqsave(&rose_neigh_list_lock, flags);
spin_lock_irqsave(&rose_route_list_lock, flags);
rose_neigh = rose_neigh_list;
while (rose_neigh != NULL) {
if (ax25cmp(&ax25->dest_addr, &rose_neigh->callsign) == 0 &&
ax25->ax25_dev->dev == rose_neigh->dev)
break; break;
rose_neigh = rose_neigh->next;
}
if (rose_neigh == NULL) { if (rose_neigh == NULL) {
printk("rose_route : unknown neighbour or device %s\n", ax2asc(&ax25->dest_addr)); printk("rose_route : unknown neighbour or device %s\n",
return 0; ax2asc(&ax25->dest_addr));
goto out;
} }
/* /*
...@@ -802,7 +905,7 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25) ...@@ -802,7 +905,7 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)
*/ */
if (lci == 0) { if (lci == 0) {
rose_link_rx_restart(skb, rose_neigh, frametype); rose_link_rx_restart(skb, rose_neigh, frametype);
return 0; goto out;
} }
/* /*
...@@ -828,7 +931,8 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25) ...@@ -828,7 +931,8 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)
} }
else { else {
skb->h.raw = skb->data; skb->h.raw = skb->data;
return rose_process_rx_frame(sk, skb); res = rose_process_rx_frame(sk, skb);
goto out;
} }
} }
...@@ -837,21 +941,23 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25) ...@@ -837,21 +941,23 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)
*/ */
if (frametype == ROSE_CALL_REQUEST) if (frametype == ROSE_CALL_REQUEST)
if ((dev = rose_dev_get(dest_addr)) != NULL) { if ((dev = rose_dev_get(dest_addr)) != NULL) {
int err = rose_rx_call_request(skb, dev, rose_neigh, lci); res = rose_rx_call_request(skb, dev, rose_neigh, lci);
dev_put(dev); dev_put(dev);
return err; goto out;
} }
if (!sysctl_rose_routing_control) { if (!sysctl_rose_routing_control) {
rose_transmit_clear_request(rose_neigh, lci, ROSE_NOT_OBTAINABLE, 0); rose_transmit_clear_request(rose_neigh, lci, ROSE_NOT_OBTAINABLE, 0);
return 0; goto out;
} }
/* /*
* Route it to the next in line if we have an entry for it. * Route it to the next in line if we have an entry for it.
*/ */
for (rose_route = rose_route_list; rose_route != NULL; rose_route = rose_route->next) { rose_route = rose_route_list;
if (rose_route->lci1 == lci && rose_route->neigh1 == rose_neigh) { while (rose_route != NULL) {
if (rose_route->lci1 == lci &&
rose_route->neigh1 == rose_neigh) {
if (frametype == ROSE_CALL_REQUEST) { if (frametype == ROSE_CALL_REQUEST) {
/* F6FBB - Remove an existing unused route */ /* F6FBB - Remove an existing unused route */
rose_remove_route(rose_route); rose_remove_route(rose_route);
...@@ -863,14 +969,16 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25) ...@@ -863,14 +969,16 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)
rose_transmit_link(skb, rose_route->neigh2); rose_transmit_link(skb, rose_route->neigh2);
if (frametype == ROSE_CLEAR_CONFIRMATION) if (frametype == ROSE_CLEAR_CONFIRMATION)
rose_remove_route(rose_route); rose_remove_route(rose_route);
return 1; res = 1;
goto out;
} else { } else {
if (frametype == ROSE_CLEAR_CONFIRMATION) if (frametype == ROSE_CLEAR_CONFIRMATION)
rose_remove_route(rose_route); rose_remove_route(rose_route);
return 0; goto out;
} }
} }
if (rose_route->lci2 == lci && rose_route->neigh2 == rose_neigh) { if (rose_route->lci2 == lci &&
rose_route->neigh2 == rose_neigh) {
if (frametype == ROSE_CALL_REQUEST) { if (frametype == ROSE_CALL_REQUEST) {
/* F6FBB - Remove an existing unused route */ /* F6FBB - Remove an existing unused route */
rose_remove_route(rose_route); rose_remove_route(rose_route);
...@@ -882,13 +990,15 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25) ...@@ -882,13 +990,15 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)
rose_transmit_link(skb, rose_route->neigh1); rose_transmit_link(skb, rose_route->neigh1);
if (frametype == ROSE_CLEAR_CONFIRMATION) if (frametype == ROSE_CLEAR_CONFIRMATION)
rose_remove_route(rose_route); rose_remove_route(rose_route);
return 1; res = 1;
goto out;
} else { } else {
if (frametype == ROSE_CLEAR_CONFIRMATION) if (frametype == ROSE_CLEAR_CONFIRMATION)
rose_remove_route(rose_route); rose_remove_route(rose_route);
return 0; goto out;
} }
} }
rose_route = rose_route->next;
} }
/* /*
...@@ -906,35 +1016,37 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25) ...@@ -906,35 +1016,37 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)
if (!rose_parse_facilities(skb->data + len + 4, &facilities)) { if (!rose_parse_facilities(skb->data + len + 4, &facilities)) {
rose_transmit_clear_request(rose_neigh, lci, ROSE_INVALID_FACILITY, 76); rose_transmit_clear_request(rose_neigh, lci, ROSE_INVALID_FACILITY, 76);
return 0; goto out;
} }
/* /*
* Check for routing loops. * Check for routing loops.
*/ */
for (rose_route = rose_route_list; rose_route != NULL; rose_route = rose_route->next) { rose_route = rose_route_list;
while (rose_route != NULL) {
if (rose_route->rand == facilities.rand && if (rose_route->rand == facilities.rand &&
rosecmp(src_addr, &rose_route->src_addr) == 0 && rosecmp(src_addr, &rose_route->src_addr) == 0 &&
ax25cmp(&facilities.dest_call, &rose_route->src_call) == 0 && ax25cmp(&facilities.dest_call, &rose_route->src_call) == 0 &&
ax25cmp(&facilities.source_call, &rose_route->dest_call) == 0) { ax25cmp(&facilities.source_call, &rose_route->dest_call) == 0) {
rose_transmit_clear_request(rose_neigh, lci, ROSE_NOT_OBTAINABLE, 120); rose_transmit_clear_request(rose_neigh, lci, ROSE_NOT_OBTAINABLE, 120);
return 0; goto out;
} }
rose_route = rose_route->next;
} }
if ((new_neigh = rose_get_neigh(dest_addr, &cause, &diagnostic)) == NULL) { if ((new_neigh = rose_get_neigh(dest_addr, &cause, &diagnostic)) == NULL) {
rose_transmit_clear_request(rose_neigh, lci, cause, diagnostic); rose_transmit_clear_request(rose_neigh, lci, cause, diagnostic);
return 0; goto out;
} }
if ((new_lci = rose_new_lci(new_neigh)) == 0) { if ((new_lci = rose_new_lci(new_neigh)) == 0) {
rose_transmit_clear_request(rose_neigh, lci, ROSE_NETWORK_CONGESTION, 71); rose_transmit_clear_request(rose_neigh, lci, ROSE_NETWORK_CONGESTION, 71);
return 0; goto out;
} }
if ((rose_route = kmalloc(sizeof(*rose_route), GFP_ATOMIC)) == NULL) { if ((rose_route = kmalloc(sizeof(*rose_route), GFP_ATOMIC)) == NULL) {
rose_transmit_clear_request(rose_neigh, lci, ROSE_NETWORK_CONGESTION, 120); rose_transmit_clear_request(rose_neigh, lci, ROSE_NETWORK_CONGESTION, 120);
return 0; goto out;
} }
rose_route->lci1 = lci; rose_route->lci1 = lci;
...@@ -950,29 +1062,34 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25) ...@@ -950,29 +1062,34 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)
rose_route->neigh1->use++; rose_route->neigh1->use++;
rose_route->neigh2->use++; rose_route->neigh2->use++;
save_flags(flags); cli();
rose_route->next = rose_route_list; rose_route->next = rose_route_list;
rose_route_list = rose_route; rose_route_list = rose_route;
restore_flags(flags);
skb->data[0] &= 0xF0; skb->data[0] &= 0xF0;
skb->data[0] |= (rose_route->lci2 >> 8) & 0x0F; skb->data[0] |= (rose_route->lci2 >> 8) & 0x0F;
skb->data[1] = (rose_route->lci2 >> 0) & 0xFF; skb->data[1] = (rose_route->lci2 >> 0) & 0xFF;
rose_transmit_link(skb, rose_route->neigh2); rose_transmit_link(skb, rose_route->neigh2);
res = 1;
out:
spin_unlock_irqrestore(&rose_route_list_lock, flags);
spin_unlock_irqrestore(&rose_neigh_list_lock, flags);
spin_unlock_irqrestore(&rose_node_list_lock, flags);
return 1; return res;
} }
int rose_nodes_get_info(char *buffer, char **start, off_t offset, int length) int rose_nodes_get_info(char *buffer, char **start, off_t offset, int length)
{ {
struct rose_node *rose_node; struct rose_node *rose_node;
unsigned long flags;
int len = 0; int len = 0;
off_t pos = 0; off_t pos = 0;
off_t begin = 0; off_t begin = 0;
int i; int i;
cli(); spin_lock_irqsave(&rose_neigh_list_lock, flags);
len += sprintf(buffer, "address mask n neigh neigh neigh\n"); len += sprintf(buffer, "address mask n neigh neigh neigh\n");
...@@ -1004,13 +1121,13 @@ int rose_nodes_get_info(char *buffer, char **start, off_t offset, int length) ...@@ -1004,13 +1121,13 @@ int rose_nodes_get_info(char *buffer, char **start, off_t offset, int length)
if (pos > offset + length) if (pos > offset + length)
break; break;
} }
spin_unlock_irqrestore(&rose_neigh_list_lock, flags);
sti();
*start = buffer + (offset - begin); *start = buffer + (offset - begin);
len -= (offset - begin); len -= (offset - begin);
if (len > length) len = length; if (len > length)
len = length;
return len; return len;
} }
...@@ -1018,12 +1135,13 @@ int rose_nodes_get_info(char *buffer, char **start, off_t offset, int length) ...@@ -1018,12 +1135,13 @@ int rose_nodes_get_info(char *buffer, char **start, off_t offset, int length)
int rose_neigh_get_info(char *buffer, char **start, off_t offset, int length) int rose_neigh_get_info(char *buffer, char **start, off_t offset, int length)
{ {
struct rose_neigh *rose_neigh; struct rose_neigh *rose_neigh;
unsigned long flags;
int len = 0; int len = 0;
off_t pos = 0; off_t pos = 0;
off_t begin = 0; off_t begin = 0;
int i; int i;
cli(); spin_lock_irqsave(&rose_neigh_list_lock, flags);
len += sprintf(buffer, "addr callsign dev count use mode restart t0 tf digipeaters\n"); len += sprintf(buffer, "addr callsign dev count use mode restart t0 tf digipeaters\n");
...@@ -1059,12 +1177,13 @@ int rose_neigh_get_info(char *buffer, char **start, off_t offset, int length) ...@@ -1059,12 +1177,13 @@ int rose_neigh_get_info(char *buffer, char **start, off_t offset, int length)
/* } */ /* } */
} }
sti(); spin_unlock_irqrestore(&rose_neigh_list_lock, flags);
*start = buffer + (offset - begin); *start = buffer + (offset - begin);
len -= (offset - begin); len -= (offset - begin);
if (len > length) len = length; if (len > length)
len = length;
return len; return len;
} }
...@@ -1072,11 +1191,12 @@ int rose_neigh_get_info(char *buffer, char **start, off_t offset, int length) ...@@ -1072,11 +1191,12 @@ int rose_neigh_get_info(char *buffer, char **start, off_t offset, int length)
int rose_routes_get_info(char *buffer, char **start, off_t offset, int length) int rose_routes_get_info(char *buffer, char **start, off_t offset, int length)
{ {
struct rose_route *rose_route; struct rose_route *rose_route;
unsigned long flags;
int len = 0; int len = 0;
off_t pos = 0; off_t pos = 0;
off_t begin = 0; off_t begin = 0;
cli(); spin_lock_irqsave(&rose_route_list_lock, flags);
len += sprintf(buffer, "lci address callsign neigh <-> lci address callsign neigh\n"); len += sprintf(buffer, "lci address callsign neigh <-> lci address callsign neigh\n");
...@@ -1112,12 +1232,13 @@ int rose_routes_get_info(char *buffer, char **start, off_t offset, int length) ...@@ -1112,12 +1232,13 @@ int rose_routes_get_info(char *buffer, char **start, off_t offset, int length)
break; break;
} }
sti(); spin_unlock_irqrestore(&rose_route_list_lock, flags);
*start = buffer + (offset - begin); *start = buffer + (offset - begin);
len -= (offset - begin); len -= (offset - begin);
if (len > length) len = length; if (len > length)
len = length;
return len; return len;
} }
......
/* /*
* ROSE release 003 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* ROSE 001 Jonathan(G4KLX) Cloned from nr_subr.c
* ROSE 002 Jonathan(G4KLX) Centralised disconnect processing.
* ROSE 003 Jonathan(G4KLX) Added use count to neighbours.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* /*
* ROSE release 003 * 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.
* *
* This code REQUIRES 2.1.15 or higher/ NET3.038 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* ROSE 001 Jonathan(G4KLX) Cloned from nr_timer.c
* ROSE 003 Jonathan(G4KLX) New timer architecture.
* Implemented idle timer.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/socket.h> #include <linux/socket.h>
......
/* -*- linux-c -*- /*
* sysctl_net_rose.c: sysctl interface to net ROSE subsystem. * 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.
* *
* Begun April 1, 1996, Mike Shaver. * Copyright (C) 1996 Mike Shaver (shaver@zeroknowledge.com)
* Added /proc/sys/net/rose directory entry (empty =) ). [MS]
*/ */
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/sysctl.h> #include <linux/sysctl.h>
#include <linux/init.h> #include <linux/init.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment