aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/unix/af_unix.c117
1 files changed, 55 insertions, 62 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 4a39771d037e..58db2a2f115a 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -164,7 +164,7 @@ static inline int unix_our_peer(struct sock *sk, struct sock *osk)
164 164
165static inline int unix_may_send(struct sock *sk, struct sock *osk) 165static inline int unix_may_send(struct sock *sk, struct sock *osk)
166{ 166{
167 return (unix_peer(osk) == NULL || unix_our_peer(sk, osk)); 167 return unix_peer(osk) == NULL || unix_our_peer(sk, osk);
168} 168}
169 169
170static inline int unix_recvq_full(struct sock const *sk) 170static inline int unix_recvq_full(struct sock const *sk)
@@ -197,7 +197,7 @@ static inline void unix_release_addr(struct unix_address *addr)
197 * - if started by zero, it is abstract name. 197 * - if started by zero, it is abstract name.
198 */ 198 */
199 199
200static int unix_mkname(struct sockaddr_un * sunaddr, int len, unsigned *hashp) 200static int unix_mkname(struct sockaddr_un *sunaddr, int len, unsigned *hashp)
201{ 201{
202 if (len <= sizeof(short) || len > sizeof(*sunaddr)) 202 if (len <= sizeof(short) || len > sizeof(*sunaddr))
203 return -EINVAL; 203 return -EINVAL;
@@ -216,7 +216,7 @@ static int unix_mkname(struct sockaddr_un * sunaddr, int len, unsigned *hashp)
216 return len; 216 return len;
217 } 217 }
218 218
219 *hashp = unix_hash_fold(csum_partial((char*)sunaddr, len, 0)); 219 *hashp = unix_hash_fold(csum_partial((char *)sunaddr, len, 0));
220 return len; 220 return len;
221} 221}
222 222
@@ -295,8 +295,7 @@ static struct sock *unix_find_socket_byinode(struct net *net, struct inode *i)
295 if (!net_eq(sock_net(s), net)) 295 if (!net_eq(sock_net(s), net))
296 continue; 296 continue;
297 297
298 if(dentry && dentry->d_inode == i) 298 if (dentry && dentry->d_inode == i) {
299 {
300 sock_hold(s); 299 sock_hold(s);
301 goto found; 300 goto found;
302 } 301 }
@@ -354,7 +353,7 @@ static void unix_sock_destructor(struct sock *sk)
354 WARN_ON(!sk_unhashed(sk)); 353 WARN_ON(!sk_unhashed(sk));
355 WARN_ON(sk->sk_socket); 354 WARN_ON(sk->sk_socket);
356 if (!sock_flag(sk, SOCK_DEAD)) { 355 if (!sock_flag(sk, SOCK_DEAD)) {
357 printk("Attempt to release alive unix socket: %p\n", sk); 356 printk(KERN_DEBUG "Attempt to release alive unix socket: %p\n", sk);
358 return; 357 return;
359 } 358 }
360 359
@@ -363,11 +362,12 @@ static void unix_sock_destructor(struct sock *sk)
363 362
364 atomic_dec(&unix_nr_socks); 363 atomic_dec(&unix_nr_socks);
365#ifdef UNIX_REFCNT_DEBUG 364#ifdef UNIX_REFCNT_DEBUG
366 printk(KERN_DEBUG "UNIX %p is destroyed, %d are still alive.\n", sk, atomic_read(&unix_nr_socks)); 365 printk(KERN_DEBUG "UNIX %p is destroyed, %d are still alive.\n", sk,
366 atomic_read(&unix_nr_socks));
367#endif 367#endif
368} 368}
369 369
370static int unix_release_sock (struct sock *sk, int embrion) 370static int unix_release_sock(struct sock *sk, int embrion)
371{ 371{
372 struct unix_sock *u = unix_sk(sk); 372 struct unix_sock *u = unix_sk(sk);
373 struct dentry *dentry; 373 struct dentry *dentry;
@@ -453,11 +453,11 @@ static int unix_listen(struct socket *sock, int backlog)
453 struct unix_sock *u = unix_sk(sk); 453 struct unix_sock *u = unix_sk(sk);
454 454
455 err = -EOPNOTSUPP; 455 err = -EOPNOTSUPP;
456 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET) 456 if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET)
457 goto out; /* Only stream/seqpacket sockets accept */ 457 goto out; /* Only stream/seqpacket sockets accept */
458 err = -EINVAL; 458 err = -EINVAL;
459 if (!u->addr) 459 if (!u->addr)
460 goto out; /* No listens on an unbound socket */ 460 goto out; /* No listens on an unbound socket */
461 unix_state_lock(sk); 461 unix_state_lock(sk);
462 if (sk->sk_state != TCP_CLOSE && sk->sk_state != TCP_LISTEN) 462 if (sk->sk_state != TCP_CLOSE && sk->sk_state != TCP_LISTEN)
463 goto out_unlock; 463 goto out_unlock;
@@ -579,7 +579,7 @@ static struct proto unix_proto = {
579 */ 579 */
580static struct lock_class_key af_unix_sk_receive_queue_lock_key; 580static struct lock_class_key af_unix_sk_receive_queue_lock_key;
581 581
582static struct sock * unix_create1(struct net *net, struct socket *sock) 582static struct sock *unix_create1(struct net *net, struct socket *sock)
583{ 583{
584 struct sock *sk = NULL; 584 struct sock *sk = NULL;
585 struct unix_sock *u; 585 struct unix_sock *u;
@@ -592,7 +592,7 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
592 if (!sk) 592 if (!sk)
593 goto out; 593 goto out;
594 594
595 sock_init_data(sock,sk); 595 sock_init_data(sock, sk);
596 lockdep_set_class(&sk->sk_receive_queue.lock, 596 lockdep_set_class(&sk->sk_receive_queue.lock,
597 &af_unix_sk_receive_queue_lock_key); 597 &af_unix_sk_receive_queue_lock_key);
598 598
@@ -653,7 +653,7 @@ static int unix_release(struct socket *sock)
653 653
654 sock->sk = NULL; 654 sock->sk = NULL;
655 655
656 return unix_release_sock (sk, 0); 656 return unix_release_sock(sk, 0);
657} 657}
658 658
659static int unix_autobind(struct socket *sock) 659static int unix_autobind(struct socket *sock)
@@ -662,7 +662,7 @@ static int unix_autobind(struct socket *sock)
662 struct net *net = sock_net(sk); 662 struct net *net = sock_net(sk);
663 struct unix_sock *u = unix_sk(sk); 663 struct unix_sock *u = unix_sk(sk);
664 static u32 ordernum = 1; 664 static u32 ordernum = 1;
665 struct unix_address * addr; 665 struct unix_address *addr;
666 int err; 666 int err;
667 667
668 mutex_lock(&u->readlock); 668 mutex_lock(&u->readlock);
@@ -681,7 +681,7 @@ static int unix_autobind(struct socket *sock)
681 681
682retry: 682retry:
683 addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short); 683 addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short);
684 addr->hash = unix_hash_fold(csum_partial((void*)addr->name, addr->len, 0)); 684 addr->hash = unix_hash_fold(csum_partial((void *)addr->name, addr->len, 0));
685 685
686 spin_lock(&unix_table_lock); 686 spin_lock(&unix_table_lock);
687 ordernum = (ordernum+1)&0xFFFFF; 687 ordernum = (ordernum+1)&0xFFFFF;
@@ -768,7 +768,7 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
768 struct net *net = sock_net(sk); 768 struct net *net = sock_net(sk);
769 struct unix_sock *u = unix_sk(sk); 769 struct unix_sock *u = unix_sk(sk);
770 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr; 770 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
771 struct dentry * dentry = NULL; 771 struct dentry *dentry = NULL;
772 struct nameidata nd; 772 struct nameidata nd;
773 int err; 773 int err;
774 unsigned hash; 774 unsigned hash;
@@ -1207,7 +1207,7 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags)
1207 int err; 1207 int err;
1208 1208
1209 err = -EOPNOTSUPP; 1209 err = -EOPNOTSUPP;
1210 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET) 1210 if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET)
1211 goto out; 1211 goto out;
1212 1212
1213 err = -EINVAL; 1213 err = -EINVAL;
@@ -1286,7 +1286,7 @@ static void unix_detach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1286 skb->destructor = sock_wfree; 1286 skb->destructor = sock_wfree;
1287 UNIXCB(skb).fp = NULL; 1287 UNIXCB(skb).fp = NULL;
1288 1288
1289 for (i=scm->fp->count-1; i>=0; i--) 1289 for (i = scm->fp->count-1; i >= 0; i--)
1290 unix_notinflight(scm->fp->fp[i]); 1290 unix_notinflight(scm->fp->fp[i]);
1291} 1291}
1292 1292
@@ -1315,7 +1315,7 @@ static int unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1315 if (!UNIXCB(skb).fp) 1315 if (!UNIXCB(skb).fp)
1316 return -ENOMEM; 1316 return -ENOMEM;
1317 1317
1318 for (i=scm->fp->count-1; i>=0; i--) 1318 for (i = scm->fp->count-1; i >= 0; i--)
1319 unix_inflight(scm->fp->fp[i]); 1319 unix_inflight(scm->fp->fp[i]);
1320 skb->destructor = unix_destruct_fds; 1320 skb->destructor = unix_destruct_fds;
1321 return 0; 1321 return 0;
@@ -1385,7 +1385,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1385 unix_get_secdata(siocb->scm, skb); 1385 unix_get_secdata(siocb->scm, skb);
1386 1386
1387 skb_reset_transport_header(skb); 1387 skb_reset_transport_header(skb);
1388 err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len); 1388 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
1389 if (err) 1389 if (err)
1390 goto out_free; 1390 goto out_free;
1391 1391
@@ -1486,7 +1486,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1486 struct sock *sk = sock->sk; 1486 struct sock *sk = sock->sk;
1487 struct sock *other = NULL; 1487 struct sock *other = NULL;
1488 struct sockaddr_un *sunaddr = msg->msg_name; 1488 struct sockaddr_un *sunaddr = msg->msg_name;
1489 int err,size; 1489 int err, size;
1490 struct sk_buff *skb; 1490 struct sk_buff *skb;
1491 int sent = 0; 1491 int sent = 0;
1492 struct scm_cookie tmp_scm; 1492 struct scm_cookie tmp_scm;
@@ -1515,8 +1515,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1515 if (sk->sk_shutdown & SEND_SHUTDOWN) 1515 if (sk->sk_shutdown & SEND_SHUTDOWN)
1516 goto pipe_err; 1516 goto pipe_err;
1517 1517
1518 while(sent < len) 1518 while (sent < len) {
1519 {
1520 /* 1519 /*
1521 * Optimisation for the fact that under 0.01% of X 1520 * Optimisation for the fact that under 0.01% of X
1522 * messages typically need breaking up. 1521 * messages typically need breaking up.
@@ -1535,7 +1534,8 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1535 * Grab a buffer 1534 * Grab a buffer
1536 */ 1535 */
1537 1536
1538 skb = sock_alloc_send_skb(sk,size,msg->msg_flags&MSG_DONTWAIT, &err); 1537 skb = sock_alloc_send_skb(sk, size, msg->msg_flags&MSG_DONTWAIT,
1538 &err);
1539 1539
1540 if (skb == NULL) 1540 if (skb == NULL)
1541 goto out_err; 1541 goto out_err;
@@ -1558,7 +1558,8 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1558 } 1558 }
1559 } 1559 }
1560 1560
1561 if ((err = memcpy_fromiovec(skb_put(skb,size), msg->msg_iov, size)) != 0) { 1561 err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size);
1562 if (err) {
1562 kfree_skb(skb); 1563 kfree_skb(skb);
1563 goto out_err; 1564 goto out_err;
1564 } 1565 }
@@ -1584,8 +1585,8 @@ pipe_err_free:
1584 unix_state_unlock(other); 1585 unix_state_unlock(other);
1585 kfree_skb(skb); 1586 kfree_skb(skb);
1586pipe_err: 1587pipe_err:
1587 if (sent==0 && !(msg->msg_flags&MSG_NOSIGNAL)) 1588 if (sent == 0 && !(msg->msg_flags&MSG_NOSIGNAL))
1588 send_sig(SIGPIPE,current,0); 1589 send_sig(SIGPIPE, current, 0);
1589 err = -EPIPE; 1590 err = -EPIPE;
1590out_err: 1591out_err:
1591 scm_destroy(siocb->scm); 1592 scm_destroy(siocb->scm);
@@ -1675,13 +1676,10 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1675 siocb->scm->creds = *UNIXCREDS(skb); 1676 siocb->scm->creds = *UNIXCREDS(skb);
1676 unix_set_secdata(siocb->scm, skb); 1677 unix_set_secdata(siocb->scm, skb);
1677 1678
1678 if (!(flags & MSG_PEEK)) 1679 if (!(flags & MSG_PEEK)) {
1679 {
1680 if (UNIXCB(skb).fp) 1680 if (UNIXCB(skb).fp)
1681 unix_detach_fds(siocb->scm, skb); 1681 unix_detach_fds(siocb->scm, skb);
1682 } 1682 } else {
1683 else
1684 {
1685 /* It is questionable: on PEEK we could: 1683 /* It is questionable: on PEEK we could:
1686 - do not return fds - good, but too simple 8) 1684 - do not return fds - good, but too simple 8)
1687 - return fds, and do not return them on read (old strategy, 1685 - return fds, and do not return them on read (old strategy,
@@ -1702,7 +1700,7 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1702 scm_recv(sock, msg, siocb->scm, flags); 1700 scm_recv(sock, msg, siocb->scm, flags);
1703 1701
1704out_free: 1702out_free:
1705 skb_free_datagram(sk,skb); 1703 skb_free_datagram(sk, skb);
1706out_unlock: 1704out_unlock:
1707 mutex_unlock(&u->readlock); 1705 mutex_unlock(&u->readlock);
1708out: 1706out:
@@ -1713,7 +1711,7 @@ out:
1713 * Sleep until data has arrive. But check for races.. 1711 * Sleep until data has arrive. But check for races..
1714 */ 1712 */
1715 1713
1716static long unix_stream_data_wait(struct sock * sk, long timeo) 1714static long unix_stream_data_wait(struct sock *sk, long timeo)
1717{ 1715{
1718 DEFINE_WAIT(wait); 1716 DEFINE_WAIT(wait);
1719 1717
@@ -1782,15 +1780,13 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1782 1780
1783 mutex_lock(&u->readlock); 1781 mutex_lock(&u->readlock);
1784 1782
1785 do 1783 do {
1786 {
1787 int chunk; 1784 int chunk;
1788 struct sk_buff *skb; 1785 struct sk_buff *skb;
1789 1786
1790 unix_state_lock(sk); 1787 unix_state_lock(sk);
1791 skb = skb_dequeue(&sk->sk_receive_queue); 1788 skb = skb_dequeue(&sk->sk_receive_queue);
1792 if (skb == NULL) 1789 if (skb == NULL) {
1793 {
1794 if (copied >= target) 1790 if (copied >= target)
1795 goto unlock; 1791 goto unlock;
1796 1792
@@ -1798,7 +1794,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1798 * POSIX 1003.1g mandates this order. 1794 * POSIX 1003.1g mandates this order.
1799 */ 1795 */
1800 1796
1801 if ((err = sock_error(sk)) != 0) 1797 err = sock_error(sk);
1798 if (err)
1802 goto unlock; 1799 goto unlock;
1803 if (sk->sk_shutdown & RCV_SHUTDOWN) 1800 if (sk->sk_shutdown & RCV_SHUTDOWN)
1804 goto unlock; 1801 goto unlock;
@@ -1825,7 +1822,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1825 1822
1826 if (check_creds) { 1823 if (check_creds) {
1827 /* Never glue messages from different writers */ 1824 /* Never glue messages from different writers */
1828 if (memcmp(UNIXCREDS(skb), &siocb->scm->creds, sizeof(siocb->scm->creds)) != 0) { 1825 if (memcmp(UNIXCREDS(skb), &siocb->scm->creds,
1826 sizeof(siocb->scm->creds)) != 0) {
1829 skb_queue_head(&sk->sk_receive_queue, skb); 1827 skb_queue_head(&sk->sk_receive_queue, skb);
1830 break; 1828 break;
1831 } 1829 }
@@ -1836,8 +1834,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1836 } 1834 }
1837 1835
1838 /* Copy address just once */ 1836 /* Copy address just once */
1839 if (sunaddr) 1837 if (sunaddr) {
1840 {
1841 unix_copy_addr(msg, skb->sk); 1838 unix_copy_addr(msg, skb->sk);
1842 sunaddr = NULL; 1839 sunaddr = NULL;
1843 } 1840 }
@@ -1853,16 +1850,14 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1853 size -= chunk; 1850 size -= chunk;
1854 1851
1855 /* Mark read part of skb as used */ 1852 /* Mark read part of skb as used */
1856 if (!(flags & MSG_PEEK)) 1853 if (!(flags & MSG_PEEK)) {
1857 {
1858 skb_pull(skb, chunk); 1854 skb_pull(skb, chunk);
1859 1855
1860 if (UNIXCB(skb).fp) 1856 if (UNIXCB(skb).fp)
1861 unix_detach_fds(siocb->scm, skb); 1857 unix_detach_fds(siocb->scm, skb);
1862 1858
1863 /* put the skb back if we didn't use it up.. */ 1859 /* put the skb back if we didn't use it up.. */
1864 if (skb->len) 1860 if (skb->len) {
1865 {
1866 skb_queue_head(&sk->sk_receive_queue, skb); 1861 skb_queue_head(&sk->sk_receive_queue, skb);
1867 break; 1862 break;
1868 } 1863 }
@@ -1871,9 +1866,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1871 1866
1872 if (siocb->scm->fp) 1867 if (siocb->scm->fp)
1873 break; 1868 break;
1874 } 1869 } else {
1875 else
1876 {
1877 /* It is questionable, see note in unix_dgram_recvmsg. 1870 /* It is questionable, see note in unix_dgram_recvmsg.
1878 */ 1871 */
1879 if (UNIXCB(skb).fp) 1872 if (UNIXCB(skb).fp)
@@ -1939,13 +1932,12 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1939 long amount = 0; 1932 long amount = 0;
1940 int err; 1933 int err;
1941 1934
1942 switch(cmd) 1935 switch (cmd) {
1943 { 1936 case SIOCOUTQ:
1944 case SIOCOUTQ: 1937 amount = atomic_read(&sk->sk_wmem_alloc);
1945 amount = atomic_read(&sk->sk_wmem_alloc); 1938 err = put_user(amount, (int __user *)arg);
1946 err = put_user(amount, (int __user *)arg); 1939 break;
1947 break; 1940 case SIOCINQ:
1948 case SIOCINQ:
1949 { 1941 {
1950 struct sk_buff *skb; 1942 struct sk_buff *skb;
1951 1943
@@ -1969,14 +1961,14 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1969 break; 1961 break;
1970 } 1962 }
1971 1963
1972 default: 1964 default:
1973 err = -ENOIOCTLCMD; 1965 err = -ENOIOCTLCMD;
1974 break; 1966 break;
1975 } 1967 }
1976 return err; 1968 return err;
1977} 1969}
1978 1970
1979static unsigned int unix_poll(struct file * file, struct socket *sock, poll_table *wait) 1971static unsigned int unix_poll(struct file *file, struct socket *sock, poll_table *wait)
1980{ 1972{
1981 struct sock *sk = sock->sk; 1973 struct sock *sk = sock->sk;
1982 unsigned int mask; 1974 unsigned int mask;
@@ -1998,7 +1990,8 @@ static unsigned int unix_poll(struct file * file, struct socket *sock, poll_tabl
1998 mask |= POLLIN | POLLRDNORM; 1990 mask |= POLLIN | POLLRDNORM;
1999 1991
2000 /* Connection-based need to check for termination and startup */ 1992 /* Connection-based need to check for termination and startup */
2001 if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) && sk->sk_state == TCP_CLOSE) 1993 if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) &&
1994 sk->sk_state == TCP_CLOSE)
2002 mask |= POLLHUP; 1995 mask |= POLLHUP;
2003 1996
2004 /* 1997 /*