]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/ipv6/raw.c
[RAW]: Consolidate proto->unhash callback
[net-next-2.6.git] / net / ipv6 / raw.c
index e27383d855dedfeffc1855ec906ea2522c8344e2..422d27cfbe16545e6cec5e3c78898e86ea0c6b19 100644 (file)
@@ -35,6 +35,7 @@
 #include <asm/uaccess.h>
 #include <asm/ioctls.h>
 
+#include <net/net_namespace.h>
 #include <net/ip.h>
 #include <net/sock.h>
 #include <net/snmp.h>
 #include <net/mip6.h>
 #endif
 
+#include <net/raw.h>
 #include <net/rawv6.h>
 #include <net/xfrm.h>
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 
-struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE];
-DEFINE_RWLOCK(raw_v6_lock);
+static struct raw_hashinfo raw_v6_hashinfo = {
+       .lock = __RW_LOCK_UNLOCKED(),
+};
 
 static void raw_v6_hash(struct sock *sk)
 {
-       struct hlist_head *list = &raw_v6_htable[inet_sk(sk)->num &
-                                                (RAWV6_HTABLE_SIZE - 1)];
-
-       write_lock_bh(&raw_v6_lock);
-       sk_add_node(sk, list);
-       sock_prot_inc_use(sk->sk_prot);
-       write_unlock_bh(&raw_v6_lock);
+       raw_hash_sk(sk, &raw_v6_hashinfo);
 }
 
 static void raw_v6_unhash(struct sock *sk)
 {
-       write_lock_bh(&raw_v6_lock);
-       if (sk_del_node_init(sk))
-               sock_prot_dec_use(sk->sk_prot);
-       write_unlock_bh(&raw_v6_lock);
+       raw_unhash_sk(sk, &raw_v6_hashinfo);
 }
 
 
-/* Grumble... icmp and ip_input want to get at this... */
-struct sock *__raw_v6_lookup(struct sock *sk, unsigned short num,
-                            struct in6_addr *loc_addr, struct in6_addr *rmt_addr,
-                            int dif)
+static struct sock *__raw_v6_lookup(struct sock *sk, unsigned short num,
+               struct in6_addr *loc_addr, struct in6_addr *rmt_addr, int dif)
 {
        struct hlist_node *node;
        int is_multicast = ipv6_addr_is_multicast(loc_addr);
@@ -166,7 +158,7 @@ EXPORT_SYMBOL(rawv6_mh_filter_unregister);
  *
  *     Caller owns SKB so we must make clones.
  */
-int ipv6_raw_deliver(struct sk_buff *skb, int nexthdr)
+static int ipv6_raw_deliver(struct sk_buff *skb, int nexthdr)
 {
        struct in6_addr *saddr;
        struct in6_addr *daddr;
@@ -179,8 +171,8 @@ int ipv6_raw_deliver(struct sk_buff *skb, int nexthdr)
 
        hash = nexthdr & (MAX_INET_PROTOS - 1);
 
-       read_lock(&raw_v6_lock);
-       sk = sk_head(&raw_v6_htable[hash]);
+       read_lock(&raw_v6_hashinfo.lock);
+       sk = sk_head(&raw_v6_hashinfo.ht[hash]);
 
        /*
         *      The first socket found will be delivered after
@@ -237,10 +229,21 @@ int ipv6_raw_deliver(struct sk_buff *skb, int nexthdr)
                                     IP6CB(skb)->iif);
        }
 out:
-       read_unlock(&raw_v6_lock);
+       read_unlock(&raw_v6_hashinfo.lock);
        return delivered;
 }
 
+int raw6_local_deliver(struct sk_buff *skb, int nexthdr)
+{
+       struct sock *raw_sk;
+
+       raw_sk = sk_head(&raw_v6_hashinfo.ht[nexthdr & (MAX_INET_PROTOS - 1)]);
+       if (raw_sk && !ipv6_raw_deliver(skb, nexthdr))
+               raw_sk = NULL;
+
+       return raw_sk != NULL;
+}
+
 /* This cleans up af_inet6 a bit. -DaveM */
 static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
 {
@@ -282,7 +285,7 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
                        if (!sk->sk_bound_dev_if)
                                goto out;
 
-                       dev = dev_get_by_index(sk->sk_bound_dev_if);
+                       dev = dev_get_by_index(&init_net, sk->sk_bound_dev_if);
                        if (!dev) {
                                err = -ENODEV;
                                goto out;
@@ -315,7 +318,7 @@ out:
        return err;
 }
 
-void rawv6_err(struct sock *sk, struct sk_buff *skb,
+static void rawv6_err(struct sock *sk, struct sk_buff *skb,
               struct inet6_skb_parm *opt,
               int type, int code, int offset, __be32 info)
 {
@@ -349,18 +352,43 @@ void rawv6_err(struct sock *sk, struct sk_buff *skb,
        }
 }
 
+void raw6_icmp_error(struct sk_buff *skb, int nexthdr,
+               int type, int code, int inner_offset, __be32 info)
+{
+       struct sock *sk;
+       int hash;
+       struct in6_addr *saddr, *daddr;
+
+       hash = nexthdr & (RAW_HTABLE_SIZE - 1);
+
+       read_lock(&raw_v6_hashinfo.lock);
+       sk = sk_head(&raw_v6_hashinfo.ht[hash]);
+       if (sk != NULL) {
+               saddr = &ipv6_hdr(skb)->saddr;
+               daddr = &ipv6_hdr(skb)->daddr;
+
+               while ((sk = __raw_v6_lookup(sk, nexthdr, saddr, daddr,
+                                               IP6CB(skb)->iif))) {
+                       rawv6_err(sk, skb, NULL, type, code,
+                                       inner_offset, info);
+                       sk = sk_next(sk);
+               }
+       }
+       read_unlock(&raw_v6_hashinfo.lock);
+}
+
 static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
 {
        if ((raw6_sk(sk)->checksum || sk->sk_filter) &&
            skb_checksum_complete(skb)) {
-               /* FIXME: increment a raw6 drops counter here */
+               atomic_inc(&sk->sk_drops);
                kfree_skb(skb);
                return 0;
        }
 
        /* Charge it to the socket. */
        if (sock_queue_rcv_skb(sk,skb)<0) {
-               /* FIXME: increment a raw6 drops counter here */
+               atomic_inc(&sk->sk_drops);
                kfree_skb(skb);
                return 0;
        }
@@ -381,6 +409,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
        struct raw6_sock *rp = raw6_sk(sk);
 
        if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
+               atomic_inc(&sk->sk_drops);
                kfree_skb(skb);
                return NET_RX_DROP;
        }
@@ -404,7 +433,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
 
        if (inet->hdrincl) {
                if (skb_checksum_complete(skb)) {
-                       /* FIXME: increment a raw6 drops counter here */
+                       atomic_inc(&sk->sk_drops);
                        kfree_skb(skb);
                        return 0;
                }
@@ -495,7 +524,7 @@ csum_copy_err:
           as some normal condition.
         */
        err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
-       /* FIXME: increment a raw6 drops counter here */
+       atomic_inc(&sk->sk_drops);
        goto out;
 }
 
@@ -617,7 +646,7 @@ static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
                goto error_fault;
 
        IP6_INC_STATS(rt->rt6i_idev, IPSTATS_MIB_OUTREQUESTS);
-       err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
+       err = NF_HOOK(PF_INET6, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
                      dst_output);
        if (err > 0)
                err = np->recverr ? net_xmit_errno(err) : 0;
@@ -882,11 +911,10 @@ back_from_confirm:
                        ip6_flush_pending_frames(sk);
                else if (!(msg->msg_flags & MSG_MORE))
                        err = rawv6_push_pending_frames(sk, &fl, rp);
+               release_sock(sk);
        }
 done:
        dst_release(dst);
-       if (!inet->hdrincl)
-               release_sock(sk);
 out:
        fl6_sock_release(flowlabel);
        return err<0?err:len;
@@ -1144,6 +1172,8 @@ static int rawv6_init_sk(struct sock *sk)
        return(0);
 }
 
+DEFINE_PROTO_INUSE(rawv6)
+
 struct proto rawv6_prot = {
        .name              = "RAWv6",
        .owner             = THIS_MODULE,
@@ -1166,6 +1196,7 @@ struct proto rawv6_prot = {
        .compat_setsockopt = compat_rawv6_setsockopt,
        .compat_getsockopt = compat_rawv6_getsockopt,
 #endif
+       REF_PROTO_INUSE(rawv6)
 };
 
 #ifdef CONFIG_PROC_FS
@@ -1181,8 +1212,9 @@ static struct sock *raw6_get_first(struct seq_file *seq)
        struct hlist_node *node;
        struct raw6_iter_state* state = raw6_seq_private(seq);
 
-       for (state->bucket = 0; state->bucket < RAWV6_HTABLE_SIZE; ++state->bucket)
-               sk_for_each(sk, node, &raw_v6_htable[state->bucket])
+       for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
+                       ++state->bucket)
+               sk_for_each(sk, node, &raw_v6_hashinfo.ht[state->bucket])
                        if (sk->sk_family == PF_INET6)
                                goto out;
        sk = NULL;
@@ -1200,8 +1232,8 @@ try_again:
                ;
        } while (sk && sk->sk_family != PF_INET6);
 
-       if (!sk && ++state->bucket < RAWV6_HTABLE_SIZE) {
-               sk = sk_head(&raw_v6_htable[state->bucket]);
+       if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
+               sk = sk_head(&raw_v6_hashinfo.ht[state->bucket]);
                goto try_again;
        }
        return sk;
@@ -1218,7 +1250,7 @@ static struct sock *raw6_get_idx(struct seq_file *seq, loff_t pos)
 
 static void *raw6_seq_start(struct seq_file *seq, loff_t *pos)
 {
-       read_lock(&raw_v6_lock);
+       read_lock(&raw_v6_hashinfo.lock);
        return *pos ? raw6_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
 }
 
@@ -1236,7 +1268,7 @@ static void *raw6_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 
 static void raw6_seq_stop(struct seq_file *seq, void *v)
 {
-       read_unlock(&raw_v6_lock);
+       read_unlock(&raw_v6_hashinfo.lock);
 }
 
 static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
@@ -1251,7 +1283,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
        srcp  = inet_sk(sp)->num;
        seq_printf(seq,
                   "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
-                  "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p\n",
+                  "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
                   i,
                   src->s6_addr32[0], src->s6_addr32[1],
                   src->s6_addr32[2], src->s6_addr32[3], srcp,
@@ -1263,7 +1295,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
                   0, 0L, 0,
                   sock_i_uid(sp), 0,
                   sock_i_ino(sp),
-                  atomic_read(&sp->sk_refcnt), sp);
+                  atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
 }
 
 static int raw6_seq_show(struct seq_file *seq, void *v)
@@ -1274,7 +1306,7 @@ static int raw6_seq_show(struct seq_file *seq, void *v)
                           "local_address                         "
                           "remote_address                        "
                           "st tx_queue rx_queue tr tm->when retrnsmt"
-                          "   uid  timeout inode\n");
+                          "   uid  timeout inode  drops\n");
        else
                raw6_sock_seq_show(seq, v, raw6_seq_private(seq)->bucket);
        return 0;
@@ -1289,21 +1321,8 @@ static const struct seq_operations raw6_seq_ops = {
 
 static int raw6_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       struct raw6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
-       if (!s)
-               goto out;
-       rc = seq_open(file, &raw6_seq_ops);
-       if (rc)
-               goto out_kfree;
-       seq = file->private_data;
-       seq->private = s;
-out:
-       return rc;
-out_kfree:
-       kfree(s);
-       goto out;
+       return seq_open_private(file, &raw6_seq_ops,
+                       sizeof(struct raw6_iter_state));
 }
 
 static const struct file_operations raw6_seq_fops = {
@@ -1316,13 +1335,13 @@ static const struct file_operations raw6_seq_fops = {
 
 int __init raw6_proc_init(void)
 {
-       if (!proc_net_fops_create("raw6", S_IRUGO, &raw6_seq_fops))
+       if (!proc_net_fops_create(&init_net, "raw6", S_IRUGO, &raw6_seq_fops))
                return -ENOMEM;
        return 0;
 }
 
 void raw6_proc_exit(void)
 {
-       proc_net_remove("raw6");
+       proc_net_remove(&init_net, "raw6");
 }
 #endif /* CONFIG_PROC_FS */