]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/unix/af_unix.c
Merge git://git.infradead.org/battery-2.6
[linux-2.6-omap-h63xx.git] / net / unix / af_unix.c
index 65ebccc0a698f31fff7de9c3fa7eebd3689e5969..9163ec526c2a0e66ed2fdf20f232173f6aed8d90 100644 (file)
 #include <asm/uaccess.h>
 #include <linux/skbuff.h>
 #include <linux/netdevice.h>
+#include <net/net_namespace.h>
 #include <net/sock.h>
 #include <net/tcp_states.h>
 #include <net/af_unix.h>
 
 int sysctl_unix_max_dgram_qlen __read_mostly = 10;
 
-struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
-DEFINE_SPINLOCK(unix_table_lock);
+static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
+static DEFINE_SPINLOCK(unix_table_lock);
 static atomic_t unix_nr_socks = ATOMIC_INIT(0);
 
 #define unix_sockets_unbound   (&unix_socket_table[UNIX_HASH_SIZE])
 
 #define UNIX_ABSTRACT(sk)      (unix_sk(sk)->addr->hash != UNIX_HASH_SIZE)
 
+static struct sock *first_unix_socket(int *i)
+{
+       for (*i = 0; *i <= UNIX_HASH_SIZE; (*i)++) {
+               if (!hlist_empty(&unix_socket_table[*i]))
+                       return __sk_head(&unix_socket_table[*i]);
+       }
+       return NULL;
+}
+
+static struct sock *next_unix_socket(int *i, struct sock *s)
+{
+       struct sock *next = sk_next(s);
+       /* More in this chain? */
+       if (next)
+               return next;
+       /* Look for next non-empty chain. */
+       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
+               if (!hlist_empty(&unix_socket_table[*i]))
+                       return __sk_head(&unix_socket_table[*i]);
+       }
+       return NULL;
+}
+
+#define forall_unix_sockets(i, s) \
+       for (s = first_unix_socket(&(i)); s; s = next_unix_socket(&(i),(s)))
+
 #ifdef CONFIG_SECURITY_NETWORK
 static void unix_get_secdata(struct scm_cookie *scm, struct sk_buff *skb)
 {
@@ -307,7 +334,7 @@ static void unix_write_space(struct sock *sk)
        read_lock(&sk->sk_callback_lock);
        if (unix_writable(sk)) {
                if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
-                       wake_up_interruptible(sk->sk_sleep);
+                       wake_up_interruptible_sync(sk->sk_sleep);
                sk_wake_async(sk, 2, POLL_OUT);
        }
        read_unlock(&sk->sk_callback_lock);
@@ -456,7 +483,7 @@ static int unix_listen(struct socket *sock, int backlog)
        sk->sk_max_ack_backlog  = backlog;
        sk->sk_state            = TCP_LISTEN;
        /* set credentials so connect can copy them */
-       sk->sk_peercred.pid     = current->tgid;
+       sk->sk_peercred.pid     = task_tgid_vnr(current);
        sk->sk_peercred.uid     = current->euid;
        sk->sk_peercred.gid     = current->egid;
        err = 0;
@@ -567,7 +594,7 @@ static struct proto unix_proto = {
  */
 static struct lock_class_key af_unix_sk_receive_queue_lock_key;
 
-static struct sock * unix_create1(struct socket *sock)
+static struct sock * unix_create1(struct net *net, struct socket *sock)
 {
        struct sock *sk = NULL;
        struct unix_sock *u;
@@ -575,7 +602,7 @@ static struct sock * unix_create1(struct socket *sock)
        if (atomic_read(&unix_nr_socks) >= 2*get_max_files())
                goto out;
 
-       sk = sk_alloc(PF_UNIX, GFP_KERNEL, &unix_proto, 1);
+       sk = sk_alloc(net, PF_UNIX, GFP_KERNEL, &unix_proto, 1);
        if (!sk)
                goto out;
 
@@ -601,8 +628,11 @@ out:
        return sk;
 }
 
-static int unix_create(struct socket *sock, int protocol)
+static int unix_create(struct net *net, struct socket *sock, int protocol)
 {
+       if (net != &init_net)
+               return -EAFNOSUPPORT;
+
        if (protocol && protocol != PF_UNIX)
                return -EPROTONOSUPPORT;
 
@@ -628,7 +658,7 @@ static int unix_create(struct socket *sock, int protocol)
                return -ESOCKTNOSUPPORT;
        }
 
-       return unix_create1(sock) ? 0 : -ENOMEM;
+       return unix_create1(net, sock) ? 0 : -ENOMEM;
 }
 
 static int unix_release(struct socket *sock)
@@ -1012,7 +1042,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
        err = -ENOMEM;
 
        /* create new sock for complete connection */
-       newsk = unix_create1(NULL);
+       newsk = unix_create1(sk->sk_net, NULL);
        if (newsk == NULL)
                goto out;
 
@@ -1103,7 +1133,7 @@ restart:
        unix_peer(newsk)        = sk;
        newsk->sk_state         = TCP_ESTABLISHED;
        newsk->sk_type          = sk->sk_type;
-       newsk->sk_peercred.pid  = current->tgid;
+       newsk->sk_peercred.pid  = task_tgid_vnr(current);
        newsk->sk_peercred.uid  = current->euid;
        newsk->sk_peercred.gid  = current->egid;
        newu = unix_sk(newsk);
@@ -1164,7 +1194,7 @@ static int unix_socketpair(struct socket *socka, struct socket *sockb)
        sock_hold(skb);
        unix_peer(ska)=skb;
        unix_peer(skb)=ska;
-       ska->sk_peercred.pid = skb->sk_peercred.pid = current->tgid;
+       ska->sk_peercred.pid = skb->sk_peercred.pid = task_tgid_vnr(current);
        ska->sk_peercred.uid = skb->sk_peercred.uid = current->euid;
        ska->sk_peercred.gid = skb->sk_peercred.gid = current->egid;
 
@@ -1609,7 +1639,7 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
        if (!skb)
                goto out_unlock;
 
-       wake_up_interruptible(&u->peer_wait);
+       wake_up_interruptible_sync(&u->peer_wait);
 
        if (msg->msg_name)
                unix_copy_addr(msg, skb->sk);
@@ -2056,25 +2086,7 @@ static const struct seq_operations unix_seq_ops = {
 
 static int unix_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       int *iter = kmalloc(sizeof(int), GFP_KERNEL);
-
-       if (!iter)
-               goto out;
-
-       rc = seq_open(file, &unix_seq_ops);
-       if (rc)
-               goto out_kfree;
-
-       seq          = file->private_data;
-       seq->private = iter;
-       *iter = 0;
-out:
-       return rc;
-out_kfree:
-       kfree(iter);
-       goto out;
+       return seq_open_private(file, &unix_seq_ops, sizeof(int));
 }
 
 static const struct file_operations unix_seq_fops = {
@@ -2109,7 +2121,7 @@ static int __init af_unix_init(void)
 
        sock_register(&unix_family_ops);
 #ifdef CONFIG_PROC_FS
-       proc_net_fops_create("unix", 0, &unix_seq_fops);
+       proc_net_fops_create(&init_net, "unix", 0, &unix_seq_fops);
 #endif
        unix_sysctl_register();
 out:
@@ -2120,7 +2132,7 @@ static void __exit af_unix_exit(void)
 {
        sock_unregister(PF_UNIX);
        unix_sysctl_unregister();
-       proc_net_remove("unix");
+       proc_net_remove(&init_net, "unix");
        proto_unregister(&unix_proto);
 }