[IPV6]: remove useless test in ip6_append_data
[linux-2.6-microblaze.git] / net / netrom / af_netrom.c
index 162a85f..d44981f 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/socket.h>
@@ -39,7 +40,7 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <net/ip.h>
-#include <net/tcp.h>
+#include <net/tcp_states.h>
 #include <net/arp.h>
 #include <linux/init.h>
 
@@ -56,13 +57,14 @@ int sysctl_netrom_transport_requested_window_size = NR_DEFAULT_WINDOW;
 int sysctl_netrom_transport_no_activity_timeout   = NR_DEFAULT_IDLE;
 int sysctl_netrom_routing_control                 = NR_DEFAULT_ROUTING;
 int sysctl_netrom_link_fails_count                = NR_DEFAULT_FAILS;
+int sysctl_netrom_reset_circuit                   = NR_DEFAULT_RESET;
 
 static unsigned short circuit = 0x101;
 
 static HLIST_HEAD(nr_list);
 static DEFINE_SPINLOCK(nr_list_lock);
 
-static struct proto_ops nr_proto_ops;
+static const struct proto_ops nr_proto_ops;
 
 /*
  *     Socket removal during an interrupt is now safe.
@@ -858,17 +860,16 @@ int nr_rx_frame(struct sk_buff *skb, struct net_device *dev)
        frametype          = skb->data[19] & 0x0F;
        flags              = skb->data[19] & 0xF0;
 
-#ifdef CONFIG_INET
        /*
         * Check for an incoming IP over NET/ROM frame.
         */
-       if (frametype == NR_PROTOEXT && circuit_index == NR_PROTO_IP && circuit_id == NR_PROTO_IP) {
+       if (frametype == NR_PROTOEXT &&
+           circuit_index == NR_PROTO_IP && circuit_id == NR_PROTO_IP) {
                skb_pull(skb, NR_NETWORK_LEN + NR_TRANSPORT_LEN);
                skb->h.raw = skb->data;
 
                return nr_rx_ip(skb, dev);
        }
-#endif
 
        /*
         * Find an existing socket connection, based on circuit ID, if it's
@@ -909,17 +910,17 @@ int nr_rx_frame(struct sk_buff *skb, struct net_device *dev)
        if (frametype != NR_CONNREQ) {
                /*
                 * Here it would be nice to be able to send a reset but
-                * NET/ROM doesn't have one. The following hack would
-                * have been a way to extend the protocol but apparently
-                * it kills BPQ boxes... :-(
-                */
-#if 0
-               /*
-                * Never reply to a CONNACK/CHOKE.
+                * NET/ROM doesn't have one.  We've tried to extend the protocol
+                * by sending NR_CONNACK | NR_CHOKE_FLAGS replies but that
+                * apparently kills BPQ boxes... :-(
+                * So now we try to follow the established behaviour of
+                * G8PZT's Xrouter which is sending packets with command type 7
+                * as an extension of the protocol.
                 */
-               if (frametype != NR_CONNACK || flags != NR_CHOKE_FLAG)
-                       nr_transmit_refusal(skb, 1);
-#endif
+               if (sysctl_netrom_reset_circuit &&
+                   (frametype != NR_RESET || flags != 0))
+                       nr_transmit_reset(skb, 1);
+
                return 0;
        }
 
@@ -1166,10 +1167,11 @@ static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
        void __user *argp = (void __user *)arg;
        int ret;
 
-       lock_sock(sk);
        switch (cmd) {
        case TIOCOUTQ: {
                long amount;
+
+               lock_sock(sk);
                amount = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
                if (amount < 0)
                        amount = 0;
@@ -1180,6 +1182,8 @@ static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
        case TIOCINQ: {
                struct sk_buff *skb;
                long amount = 0L;
+
+               lock_sock(sk);
                /* These two are safe on a single CPU system as only user tasks fiddle here */
                if ((skb = skb_peek(&sk->sk_receive_queue)) != NULL)
                        amount = skb->len;
@@ -1188,9 +1192,8 @@ static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
        }
 
        case SIOCGSTAMP:
-               ret = -EINVAL;
-               if (sk != NULL)
-                       ret = sock_get_timestamp(sk, argp);
+               lock_sock(sk);
+               ret = sock_get_timestamp(sk, argp);
                release_sock(sk);
                return ret;
 
@@ -1204,21 +1207,17 @@ static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
        case SIOCSIFNETMASK:
        case SIOCGIFMETRIC:
        case SIOCSIFMETRIC:
-               release_sock(sk);
                return -EINVAL;
 
        case SIOCADDRT:
        case SIOCDELRT:
        case SIOCNRDECOBS:
-               release_sock(sk);
                if (!capable(CAP_NET_ADMIN)) return -EPERM;
                return nr_rt_ioctl(cmd, argp);
 
        default:
-               release_sock(sk);
-               return dev_ioctl(cmd, argp);
+               return -ENOIOCTLCMD;
        }
-       release_sock(sk);
 
        return 0;
 }
@@ -1262,6 +1261,7 @@ static int nr_info_show(struct seq_file *seq, void *v)
        struct net_device *dev;
        struct nr_sock *nr;
        const char *devname;
+       char buf[11];
 
        if (v == SEQ_START_TOKEN)
                seq_puts(seq,
@@ -1277,11 +1277,11 @@ static int nr_info_show(struct seq_file *seq, void *v)
                else
                        devname = dev->name;
 
-               seq_printf(seq, "%-9s ", ax2asc(&nr->user_addr));
-               seq_printf(seq, "%-9s ", ax2asc(&nr->dest_addr));
+               seq_printf(seq, "%-9s ", ax2asc(buf, &nr->user_addr));
+               seq_printf(seq, "%-9s ", ax2asc(buf, &nr->dest_addr));
                seq_printf(seq, 
 "%-9s %-3s  %02X/%02X %02X/%02X %2d %3d %3d %3d %3lu/%03lu %2lu/%02lu %3lu/%03lu %3lu/%03lu %2d/%02d %3d %5d %5d %ld\n",
-                       ax2asc(&nr->source_addr),
+                       ax2asc(buf, &nr->source_addr),
                        devname,
                        nr->my_index,
                        nr->my_id,
@@ -1338,7 +1338,7 @@ static struct net_proto_family nr_family_ops = {
        .owner          =       THIS_MODULE,
 };
 
-static struct proto_ops nr_proto_ops = {
+static const struct proto_ops nr_proto_ops = {
        .family         =       PF_NETROM,
        .owner          =       THIS_MODULE,
        .release        =       nr_release,
@@ -1393,8 +1393,7 @@ static int __init nr_proto_init(void)
                struct net_device *dev;
 
                sprintf(name, "nr%d", i);
-               dev = alloc_netdev(sizeof(struct net_device_stats), name,
-                                         nr_setup);
+               dev = alloc_netdev(sizeof(struct nr_private), name, nr_setup);
                if (!dev) {
                        printk(KERN_ERR "NET/ROM: nr_proto_init - unable to allocate device structure\n");
                        goto fail;