aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix/af_unix.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2012-01-19 15:56:50 -0500
committerH. Peter Anvin <hpa@linux.intel.com>2012-01-19 15:56:50 -0500
commit282f445a779ed76fca9884fe377bf56a3088b208 (patch)
treed9abcf526baee0100672851e0a8894c19e762a39 /net/unix/af_unix.c
parent68f30fbee19cc67849b9fa8e153ede70758afe81 (diff)
parent90a4c0f51e8e44111a926be6f4c87af3938a79c3 (diff)
Merge remote-tracking branch 'linus/master' into x86/urgent
Diffstat (limited to 'net/unix/af_unix.c')
-rw-r--r--net/unix/af_unix.c70
1 files changed, 43 insertions, 27 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index b595a3d8679f..aad8fb699989 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
118static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1]; 118struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
119static DEFINE_SPINLOCK(unix_table_lock); 119EXPORT_SYMBOL_GPL(unix_socket_table);
120DEFINE_SPINLOCK(unix_table_lock);
121EXPORT_SYMBOL_GPL(unix_table_lock);
120static atomic_long_t unix_nr_socks; 122static 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
175static struct sock *unix_peer_get(struct sock *s) 177struct 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}
188EXPORT_SYMBOL_GPL(unix_peer_get);
186 189
187static inline void unix_release_addr(struct unix_address *addr) 190static 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
@@ -2062,6 +2065,36 @@ static int unix_shutdown(struct socket *sock, int mode)
2062 return 0; 2065 return 0;
2063} 2066}
2064 2067
2068long unix_inq_len(struct sock *sk)
2069{
2070 struct sk_buff *skb;
2071 long amount = 0;
2072
2073 if (sk->sk_state == TCP_LISTEN)
2074 return -EINVAL;
2075
2076 spin_lock(&sk->sk_receive_queue.lock);
2077 if (sk->sk_type == SOCK_STREAM ||
2078 sk->sk_type == SOCK_SEQPACKET) {
2079 skb_queue_walk(&sk->sk_receive_queue, skb)
2080 amount += skb->len;
2081 } else {
2082 skb = skb_peek(&sk->sk_receive_queue);
2083 if (skb)
2084 amount = skb->len;
2085 }
2086 spin_unlock(&sk->sk_receive_queue.lock);
2087
2088 return amount;
2089}
2090EXPORT_SYMBOL_GPL(unix_inq_len);
2091
2092long unix_outq_len(struct sock *sk)
2093{
2094 return sk_wmem_alloc_get(sk);
2095}
2096EXPORT_SYMBOL_GPL(unix_outq_len);
2097
2065static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 2098static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
2066{ 2099{
2067 struct sock *sk = sock->sk; 2100 struct sock *sk = sock->sk;
@@ -2070,33 +2103,16 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
2070 2103
2071 switch (cmd) { 2104 switch (cmd) {
2072 case SIOCOUTQ: 2105 case SIOCOUTQ:
2073 amount = sk_wmem_alloc_get(sk); 2106 amount = unix_outq_len(sk);
2074 err = put_user(amount, (int __user *)arg); 2107 err = put_user(amount, (int __user *)arg);
2075 break; 2108 break;
2076 case SIOCINQ: 2109 case SIOCINQ:
2077 { 2110 amount = unix_inq_len(sk);
2078 struct sk_buff *skb; 2111 if (amount < 0)
2079 2112 err = amount;
2080 if (sk->sk_state == TCP_LISTEN) { 2113 else
2081 err = -EINVAL;
2082 break;
2083 }
2084
2085 spin_lock(&sk->sk_receive_queue.lock);
2086 if (sk->sk_type == SOCK_STREAM ||
2087 sk->sk_type == SOCK_SEQPACKET) {
2088 skb_queue_walk(&sk->sk_receive_queue, skb)
2089 amount += skb->len;
2090 } else {
2091 skb = skb_peek(&sk->sk_receive_queue);
2092 if (skb)
2093 amount = skb->len;
2094 }
2095 spin_unlock(&sk->sk_receive_queue.lock);
2096 err = put_user(amount, (int __user *)arg); 2114 err = put_user(amount, (int __user *)arg);
2097 break; 2115 break;
2098 }
2099
2100 default: 2116 default:
2101 err = -ENOIOCTLCMD; 2117 err = -ENOIOCTLCMD;
2102 break; 2118 break;