diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-03-19 20:02:01 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-03-19 20:02:01 -0400 |
commit | 10ce3cc919f50c2043b41ca968b43c26a3672600 (patch) | |
tree | ea409366a5208aced495bc0516a08b81fd43222e /net/unix/af_unix.c | |
parent | 24e3e5ae1e4c2a3a32f5b1f96b4e3fd721806acd (diff) | |
parent | 5c6a7a62c130afef3d61c1dee153012231ff5cd9 (diff) |
Merge branch 'next' into for-linus
Diffstat (limited to 'net/unix/af_unix.c')
-rw-r--r-- | net/unix/af_unix.c | 85 |
1 files changed, 47 insertions, 38 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 466fbcc5cf77..85d3bb7490aa 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c | |||
@@ -115,8 +115,10 @@ | |||
115 | #include <net/checksum.h> | 115 | #include <net/checksum.h> |
116 | #include <linux/security.h> | 116 | #include <linux/security.h> |
117 | 117 | ||
118 | static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1]; | 118 | struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1]; |
119 | static DEFINE_SPINLOCK(unix_table_lock); | 119 | EXPORT_SYMBOL_GPL(unix_socket_table); |
120 | DEFINE_SPINLOCK(unix_table_lock); | ||
121 | EXPORT_SYMBOL_GPL(unix_table_lock); | ||
120 | static atomic_long_t unix_nr_socks; | 122 | static atomic_long_t unix_nr_socks; |
121 | 123 | ||
122 | #define unix_sockets_unbound (&unix_socket_table[UNIX_HASH_SIZE]) | 124 | #define unix_sockets_unbound (&unix_socket_table[UNIX_HASH_SIZE]) |
@@ -172,7 +174,7 @@ static inline int unix_recvq_full(struct sock const *sk) | |||
172 | return skb_queue_len(&sk->sk_receive_queue) > sk->sk_max_ack_backlog; | 174 | return skb_queue_len(&sk->sk_receive_queue) > sk->sk_max_ack_backlog; |
173 | } | 175 | } |
174 | 176 | ||
175 | static struct sock *unix_peer_get(struct sock *s) | 177 | struct sock *unix_peer_get(struct sock *s) |
176 | { | 178 | { |
177 | struct sock *peer; | 179 | struct sock *peer; |
178 | 180 | ||
@@ -183,6 +185,7 @@ static struct sock *unix_peer_get(struct sock *s) | |||
183 | unix_state_unlock(s); | 185 | unix_state_unlock(s); |
184 | return peer; | 186 | return peer; |
185 | } | 187 | } |
188 | EXPORT_SYMBOL_GPL(unix_peer_get); | ||
186 | 189 | ||
187 | static inline void unix_release_addr(struct unix_address *addr) | 190 | static inline void unix_release_addr(struct unix_address *addr) |
188 | { | 191 | { |
@@ -847,7 +850,7 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) | |||
847 | atomic_set(&addr->refcnt, 1); | 850 | atomic_set(&addr->refcnt, 1); |
848 | 851 | ||
849 | if (sun_path[0]) { | 852 | if (sun_path[0]) { |
850 | unsigned int mode; | 853 | umode_t mode; |
851 | err = 0; | 854 | err = 0; |
852 | /* | 855 | /* |
853 | * Get the parent directory, calculate the hash for last | 856 | * Get the parent directory, calculate the hash for last |
@@ -1915,7 +1918,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock, | |||
1915 | struct sk_buff *skb; | 1918 | struct sk_buff *skb; |
1916 | 1919 | ||
1917 | unix_state_lock(sk); | 1920 | unix_state_lock(sk); |
1918 | skb = skb_dequeue(&sk->sk_receive_queue); | 1921 | skb = skb_peek(&sk->sk_receive_queue); |
1919 | if (skb == NULL) { | 1922 | if (skb == NULL) { |
1920 | unix_sk(sk)->recursion_level = 0; | 1923 | unix_sk(sk)->recursion_level = 0; |
1921 | if (copied >= target) | 1924 | if (copied >= target) |
@@ -1955,10 +1958,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock, | |||
1955 | if (check_creds) { | 1958 | if (check_creds) { |
1956 | /* Never glue messages from different writers */ | 1959 | /* Never glue messages from different writers */ |
1957 | if ((UNIXCB(skb).pid != siocb->scm->pid) || | 1960 | if ((UNIXCB(skb).pid != siocb->scm->pid) || |
1958 | (UNIXCB(skb).cred != siocb->scm->cred)) { | 1961 | (UNIXCB(skb).cred != siocb->scm->cred)) |
1959 | skb_queue_head(&sk->sk_receive_queue, skb); | ||
1960 | break; | 1962 | break; |
1961 | } | ||
1962 | } else { | 1963 | } else { |
1963 | /* Copy credentials */ | 1964 | /* Copy credentials */ |
1964 | scm_set_cred(siocb->scm, UNIXCB(skb).pid, UNIXCB(skb).cred); | 1965 | scm_set_cred(siocb->scm, UNIXCB(skb).pid, UNIXCB(skb).cred); |
@@ -1973,7 +1974,6 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock, | |||
1973 | 1974 | ||
1974 | chunk = min_t(unsigned int, skb->len, size); | 1975 | chunk = min_t(unsigned int, skb->len, size); |
1975 | if (memcpy_toiovec(msg->msg_iov, skb->data, chunk)) { | 1976 | if (memcpy_toiovec(msg->msg_iov, skb->data, chunk)) { |
1976 | skb_queue_head(&sk->sk_receive_queue, skb); | ||
1977 | if (copied == 0) | 1977 | if (copied == 0) |
1978 | copied = -EFAULT; | 1978 | copied = -EFAULT; |
1979 | break; | 1979 | break; |
@@ -1988,12 +1988,10 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock, | |||
1988 | if (UNIXCB(skb).fp) | 1988 | if (UNIXCB(skb).fp) |
1989 | unix_detach_fds(siocb->scm, skb); | 1989 | unix_detach_fds(siocb->scm, skb); |
1990 | 1990 | ||
1991 | /* put the skb back if we didn't use it up.. */ | 1991 | if (skb->len) |
1992 | if (skb->len) { | ||
1993 | skb_queue_head(&sk->sk_receive_queue, skb); | ||
1994 | break; | 1992 | break; |
1995 | } | ||
1996 | 1993 | ||
1994 | skb_unlink(skb, &sk->sk_receive_queue); | ||
1997 | consume_skb(skb); | 1995 | consume_skb(skb); |
1998 | 1996 | ||
1999 | if (siocb->scm->fp) | 1997 | if (siocb->scm->fp) |
@@ -2004,8 +2002,6 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock, | |||
2004 | if (UNIXCB(skb).fp) | 2002 | if (UNIXCB(skb).fp) |
2005 | siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp); | 2003 | siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp); |
2006 | 2004 | ||
2007 | /* put message back and return */ | ||
2008 | skb_queue_head(&sk->sk_receive_queue, skb); | ||
2009 | break; | 2005 | break; |
2010 | } | 2006 | } |
2011 | } while (size); | 2007 | } while (size); |
@@ -2058,6 +2054,36 @@ static int unix_shutdown(struct socket *sock, int mode) | |||
2058 | return 0; | 2054 | return 0; |
2059 | } | 2055 | } |
2060 | 2056 | ||
2057 | long unix_inq_len(struct sock *sk) | ||
2058 | { | ||
2059 | struct sk_buff *skb; | ||
2060 | long amount = 0; | ||
2061 | |||
2062 | if (sk->sk_state == TCP_LISTEN) | ||
2063 | return -EINVAL; | ||
2064 | |||
2065 | spin_lock(&sk->sk_receive_queue.lock); | ||
2066 | if (sk->sk_type == SOCK_STREAM || | ||
2067 | sk->sk_type == SOCK_SEQPACKET) { | ||
2068 | skb_queue_walk(&sk->sk_receive_queue, skb) | ||
2069 | amount += skb->len; | ||
2070 | } else { | ||
2071 | skb = skb_peek(&sk->sk_receive_queue); | ||
2072 | if (skb) | ||
2073 | amount = skb->len; | ||
2074 | } | ||
2075 | spin_unlock(&sk->sk_receive_queue.lock); | ||
2076 | |||
2077 | return amount; | ||
2078 | } | ||
2079 | EXPORT_SYMBOL_GPL(unix_inq_len); | ||
2080 | |||
2081 | long unix_outq_len(struct sock *sk) | ||
2082 | { | ||
2083 | return sk_wmem_alloc_get(sk); | ||
2084 | } | ||
2085 | EXPORT_SYMBOL_GPL(unix_outq_len); | ||
2086 | |||
2061 | static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) | 2087 | static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) |
2062 | { | 2088 | { |
2063 | struct sock *sk = sock->sk; | 2089 | struct sock *sk = sock->sk; |
@@ -2066,33 +2092,16 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) | |||
2066 | 2092 | ||
2067 | switch (cmd) { | 2093 | switch (cmd) { |
2068 | case SIOCOUTQ: | 2094 | case SIOCOUTQ: |
2069 | amount = sk_wmem_alloc_get(sk); | 2095 | amount = unix_outq_len(sk); |
2070 | err = put_user(amount, (int __user *)arg); | 2096 | err = put_user(amount, (int __user *)arg); |
2071 | break; | 2097 | break; |
2072 | case SIOCINQ: | 2098 | case SIOCINQ: |
2073 | { | 2099 | amount = unix_inq_len(sk); |
2074 | struct sk_buff *skb; | 2100 | if (amount < 0) |
2075 | 2101 | err = amount; | |
2076 | if (sk->sk_state == TCP_LISTEN) { | 2102 | else |
2077 | err = -EINVAL; | ||
2078 | break; | ||
2079 | } | ||
2080 | |||
2081 | spin_lock(&sk->sk_receive_queue.lock); | ||
2082 | if (sk->sk_type == SOCK_STREAM || | ||
2083 | sk->sk_type == SOCK_SEQPACKET) { | ||
2084 | skb_queue_walk(&sk->sk_receive_queue, skb) | ||
2085 | amount += skb->len; | ||
2086 | } else { | ||
2087 | skb = skb_peek(&sk->sk_receive_queue); | ||
2088 | if (skb) | ||
2089 | amount = skb->len; | ||
2090 | } | ||
2091 | spin_unlock(&sk->sk_receive_queue.lock); | ||
2092 | err = put_user(amount, (int __user *)arg); | 2103 | err = put_user(amount, (int __user *)arg); |
2093 | break; | 2104 | break; |
2094 | } | ||
2095 | |||
2096 | default: | 2105 | default: |
2097 | err = -ENOIOCTLCMD; | 2106 | err = -ENOIOCTLCMD; |
2098 | break; | 2107 | break; |