aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix/af_unix.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-03-21 00:04:47 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-21 00:04:47 -0400
commit3b59bf081622b6446db77ad06c93fe23677bc533 (patch)
tree3f4bb5a27c90cc86994a1f6d3c53fbf9208003cb /net/unix/af_unix.c
parente45836fafe157df137a837093037f741ad8f4c90 (diff)
parentbbdb32cb5b73597386913d052165423b9d736145 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
Pull networking merge from David Miller: "1) Move ixgbe driver over to purely page based buffering on receive. From Alexander Duyck. 2) Add receive packet steering support to e1000e, from Bruce Allan. 3) Convert TCP MD5 support over to RCU, from Eric Dumazet. 4) Reduce cpu usage in handling out-of-order TCP packets on modern systems, also from Eric Dumazet. 5) Support the IP{,V6}_UNICAST_IF socket options, making the wine folks happy, from Erich Hoover. 6) Support VLAN trunking from guests in hyperv driver, from Haiyang Zhang. 7) Support byte-queue-limtis in r8169, from Igor Maravic. 8) Outline code intended for IP_RECVTOS in IP_PKTOPTIONS existed but was never properly implemented, Jiri Benc fixed that. 9) 64-bit statistics support in r8169 and 8139too, from Junchang Wang. 10) Support kernel side dump filtering by ctmark in netfilter ctnetlink, from Pablo Neira Ayuso. 11) Support byte-queue-limits in gianfar driver, from Paul Gortmaker. 12) Add new peek socket options to assist with socket migration, from Pavel Emelyanov. 13) Add sch_plug packet scheduler whose queue is controlled by userland daemons using explicit freeze and release commands. From Shriram Rajagopalan. 14) Fix FCOE checksum offload handling on transmit, from Yi Zou." * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1846 commits) Fix pppol2tp getsockname() Remove printk from rds_sendmsg ipv6: fix incorrent ipv6 ipsec packet fragment cpsw: Hook up default ndo_change_mtu. net: qmi_wwan: fix build error due to cdc-wdm dependecy netdev: driver: ethernet: Add TI CPSW driver netdev: driver: ethernet: add cpsw address lookup engine support phy: add am79c874 PHY support mlx4_core: fix race on comm channel bonding: send igmp report for its master fs_enet: Add MPC5125 FEC support and PHY interface selection net: bpf_jit: fix BPF_S_LDX_B_MSH compilation net: update the usage of CHECKSUM_UNNECESSARY fcoe: use CHECKSUM_UNNECESSARY instead of CHECKSUM_PARTIAL on tx net: do not do gso for CHECKSUM_UNNECESSARY in netif_needs_gso ixgbe: Fix issues with SR-IOV loopback when flow control is disabled net/hyperv: Fix the code handling tx busy ixgbe: fix namespace issues when FCoE/DCB is not enabled rtlwifi: Remove unused ETH_ADDR_LEN defines igbvf: Use ETH_ALEN ... Fix up fairly trivial conflicts in drivers/isdn/gigaset/interface.c and drivers/net/usb/{Kconfig,qmi_wwan.c} as per David.
Diffstat (limited to 'net/unix/af_unix.c')
-rw-r--r--net/unix/af_unix.c52
1 files changed, 44 insertions, 8 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 85d3bb7490aa..8ee85aa79fa7 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -530,6 +530,16 @@ static int unix_seqpacket_sendmsg(struct kiocb *, struct socket *,
530static int unix_seqpacket_recvmsg(struct kiocb *, struct socket *, 530static int unix_seqpacket_recvmsg(struct kiocb *, struct socket *,
531 struct msghdr *, size_t, int); 531 struct msghdr *, size_t, int);
532 532
533static void unix_set_peek_off(struct sock *sk, int val)
534{
535 struct unix_sock *u = unix_sk(sk);
536
537 mutex_lock(&u->readlock);
538 sk->sk_peek_off = val;
539 mutex_unlock(&u->readlock);
540}
541
542
533static const struct proto_ops unix_stream_ops = { 543static const struct proto_ops unix_stream_ops = {
534 .family = PF_UNIX, 544 .family = PF_UNIX,
535 .owner = THIS_MODULE, 545 .owner = THIS_MODULE,
@@ -549,6 +559,7 @@ static const struct proto_ops unix_stream_ops = {
549 .recvmsg = unix_stream_recvmsg, 559 .recvmsg = unix_stream_recvmsg,
550 .mmap = sock_no_mmap, 560 .mmap = sock_no_mmap,
551 .sendpage = sock_no_sendpage, 561 .sendpage = sock_no_sendpage,
562 .set_peek_off = unix_set_peek_off,
552}; 563};
553 564
554static const struct proto_ops unix_dgram_ops = { 565static const struct proto_ops unix_dgram_ops = {
@@ -570,6 +581,7 @@ static const struct proto_ops unix_dgram_ops = {
570 .recvmsg = unix_dgram_recvmsg, 581 .recvmsg = unix_dgram_recvmsg,
571 .mmap = sock_no_mmap, 582 .mmap = sock_no_mmap,
572 .sendpage = sock_no_sendpage, 583 .sendpage = sock_no_sendpage,
584 .set_peek_off = unix_set_peek_off,
573}; 585};
574 586
575static const struct proto_ops unix_seqpacket_ops = { 587static const struct proto_ops unix_seqpacket_ops = {
@@ -591,6 +603,7 @@ static const struct proto_ops unix_seqpacket_ops = {
591 .recvmsg = unix_seqpacket_recvmsg, 603 .recvmsg = unix_seqpacket_recvmsg,
592 .mmap = sock_no_mmap, 604 .mmap = sock_no_mmap,
593 .sendpage = sock_no_sendpage, 605 .sendpage = sock_no_sendpage,
606 .set_peek_off = unix_set_peek_off,
594}; 607};
595 608
596static struct proto unix_proto = { 609static struct proto unix_proto = {
@@ -1756,6 +1769,7 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1756 int noblock = flags & MSG_DONTWAIT; 1769 int noblock = flags & MSG_DONTWAIT;
1757 struct sk_buff *skb; 1770 struct sk_buff *skb;
1758 int err; 1771 int err;
1772 int peeked, skip;
1759 1773
1760 err = -EOPNOTSUPP; 1774 err = -EOPNOTSUPP;
1761 if (flags&MSG_OOB) 1775 if (flags&MSG_OOB)
@@ -1769,7 +1783,9 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1769 goto out; 1783 goto out;
1770 } 1784 }
1771 1785
1772 skb = skb_recv_datagram(sk, flags, noblock, &err); 1786 skip = sk_peek_offset(sk, flags);
1787
1788 skb = __skb_recv_datagram(sk, flags, &peeked, &skip, &err);
1773 if (!skb) { 1789 if (!skb) {
1774 unix_state_lock(sk); 1790 unix_state_lock(sk);
1775 /* Signal EOF on disconnected non-blocking SEQPACKET socket. */ 1791 /* Signal EOF on disconnected non-blocking SEQPACKET socket. */
@@ -1786,12 +1802,12 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1786 if (msg->msg_name) 1802 if (msg->msg_name)
1787 unix_copy_addr(msg, skb->sk); 1803 unix_copy_addr(msg, skb->sk);
1788 1804
1789 if (size > skb->len) 1805 if (size > skb->len - skip)
1790 size = skb->len; 1806 size = skb->len - skip;
1791 else if (size < skb->len) 1807 else if (size < skb->len - skip)
1792 msg->msg_flags |= MSG_TRUNC; 1808 msg->msg_flags |= MSG_TRUNC;
1793 1809
1794 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, size); 1810 err = skb_copy_datagram_iovec(skb, skip, msg->msg_iov, size);
1795 if (err) 1811 if (err)
1796 goto out_free; 1812 goto out_free;
1797 1813
@@ -1808,6 +1824,8 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1808 if (!(flags & MSG_PEEK)) { 1824 if (!(flags & MSG_PEEK)) {
1809 if (UNIXCB(skb).fp) 1825 if (UNIXCB(skb).fp)
1810 unix_detach_fds(siocb->scm, skb); 1826 unix_detach_fds(siocb->scm, skb);
1827
1828 sk_peek_offset_bwd(sk, skb->len);
1811 } else { 1829 } else {
1812 /* It is questionable: on PEEK we could: 1830 /* It is questionable: on PEEK we could:
1813 - do not return fds - good, but too simple 8) 1831 - do not return fds - good, but too simple 8)
@@ -1821,10 +1839,13 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1821 clearly however! 1839 clearly however!
1822 1840
1823 */ 1841 */
1842
1843 sk_peek_offset_fwd(sk, size);
1844
1824 if (UNIXCB(skb).fp) 1845 if (UNIXCB(skb).fp)
1825 siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp); 1846 siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp);
1826 } 1847 }
1827 err = size; 1848 err = (flags & MSG_TRUNC) ? skb->len - skip : size;
1828 1849
1829 scm_recv(sock, msg, siocb->scm, flags); 1850 scm_recv(sock, msg, siocb->scm, flags);
1830 1851
@@ -1884,6 +1905,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1884 int target; 1905 int target;
1885 int err = 0; 1906 int err = 0;
1886 long timeo; 1907 long timeo;
1908 int skip;
1887 1909
1888 err = -EINVAL; 1910 err = -EINVAL;
1889 if (sk->sk_state != TCP_ESTABLISHED) 1911 if (sk->sk_state != TCP_ESTABLISHED)
@@ -1913,12 +1935,15 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1913 goto out; 1935 goto out;
1914 } 1936 }
1915 1937
1938 skip = sk_peek_offset(sk, flags);
1939
1916 do { 1940 do {
1917 int chunk; 1941 int chunk;
1918 struct sk_buff *skb; 1942 struct sk_buff *skb;
1919 1943
1920 unix_state_lock(sk); 1944 unix_state_lock(sk);
1921 skb = skb_peek(&sk->sk_receive_queue); 1945 skb = skb_peek(&sk->sk_receive_queue);
1946again:
1922 if (skb == NULL) { 1947 if (skb == NULL) {
1923 unix_sk(sk)->recursion_level = 0; 1948 unix_sk(sk)->recursion_level = 0;
1924 if (copied >= target) 1949 if (copied >= target)
@@ -1953,6 +1978,13 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1953 unix_state_unlock(sk); 1978 unix_state_unlock(sk);
1954 break; 1979 break;
1955 } 1980 }
1981
1982 if (skip >= skb->len) {
1983 skip -= skb->len;
1984 skb = skb_peek_next(skb, &sk->sk_receive_queue);
1985 goto again;
1986 }
1987
1956 unix_state_unlock(sk); 1988 unix_state_unlock(sk);
1957 1989
1958 if (check_creds) { 1990 if (check_creds) {
@@ -1972,8 +2004,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1972 sunaddr = NULL; 2004 sunaddr = NULL;
1973 } 2005 }
1974 2006
1975 chunk = min_t(unsigned int, skb->len, size); 2007 chunk = min_t(unsigned int, skb->len - skip, size);
1976 if (memcpy_toiovec(msg->msg_iov, skb->data, chunk)) { 2008 if (memcpy_toiovec(msg->msg_iov, skb->data + skip, chunk)) {
1977 if (copied == 0) 2009 if (copied == 0)
1978 copied = -EFAULT; 2010 copied = -EFAULT;
1979 break; 2011 break;
@@ -1985,6 +2017,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1985 if (!(flags & MSG_PEEK)) { 2017 if (!(flags & MSG_PEEK)) {
1986 skb_pull(skb, chunk); 2018 skb_pull(skb, chunk);
1987 2019
2020 sk_peek_offset_bwd(sk, chunk);
2021
1988 if (UNIXCB(skb).fp) 2022 if (UNIXCB(skb).fp)
1989 unix_detach_fds(siocb->scm, skb); 2023 unix_detach_fds(siocb->scm, skb);
1990 2024
@@ -2002,6 +2036,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
2002 if (UNIXCB(skb).fp) 2036 if (UNIXCB(skb).fp)
2003 siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp); 2037 siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp);
2004 2038
2039 sk_peek_offset_fwd(sk, chunk);
2040
2005 break; 2041 break;
2006 } 2042 }
2007 } while (size); 2043 } while (size);