]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/ipv4/tcp.c
[INET]: Consolidate xxx_frag_intern
[linux-2.6-omap-h63xx.git] / net / ipv4 / tcp.c
index 2cf9a898ce50e8cbb34a6eb19c55e396a2f7a84b..4f322003835dc1886b4202259a91bd641d9139c3 100644 (file)
  *     TCP_CLOSE               socket is finished
  */
 
+#include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/fcntl.h>
 #include <linux/poll.h>
 #include <linux/init.h>
-#include <linux/smp_lock.h>
 #include <linux/fs.h>
 #include <linux/random.h>
 #include <linux/bootmem.h>
@@ -659,9 +659,10 @@ static inline int select_size(struct sock *sk)
        return tmp;
 }
 
-int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
+int tcp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
                size_t size)
 {
+       struct sock *sk = sock->sk;
        struct iovec *iov;
        struct tcp_sock *tp = tcp_sk(sk);
        struct sk_buff *skb;
@@ -1065,7 +1066,11 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
                                        break;
                        }
                        used = recv_actor(desc, skb, offset, len);
-                       if (used <= len) {
+                       if (used < 0) {
+                               if (!copied)
+                                       copied = used;
+                               break;
+                       } else if (used <= len) {
                                seq += used;
                                copied += used;
                                offset += used;
@@ -1087,7 +1092,7 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
        tcp_rcv_space_adjust(sk);
 
        /* Clean up data we have read: This will do ACK frames. */
-       if (copied)
+       if (copied > 0)
                tcp_cleanup_rbuf(sk, copied);
        return copied;
 }
@@ -1113,6 +1118,7 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
        long timeo;
        struct task_struct *user_recv = NULL;
        int copied_early = 0;
+       struct sk_buff *skb;
 
        lock_sock(sk);
 
@@ -1139,16 +1145,26 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
 #ifdef CONFIG_NET_DMA
        tp->ucopy.dma_chan = NULL;
        preempt_disable();
-       if ((len > sysctl_tcp_dma_copybreak) && !(flags & MSG_PEEK) &&
-           !sysctl_tcp_low_latency && __get_cpu_var(softnet_data).net_dma) {
-               preempt_enable_no_resched();
-               tp->ucopy.pinned_list = dma_pin_iovec_pages(msg->msg_iov, len);
-       } else
-               preempt_enable_no_resched();
+       skb = skb_peek_tail(&sk->sk_receive_queue);
+       {
+               int available = 0;
+
+               if (skb)
+                       available = TCP_SKB_CB(skb)->seq + skb->len - (*seq);
+               if ((available < target) &&
+                   (len > sysctl_tcp_dma_copybreak) && !(flags & MSG_PEEK) &&
+                   !sysctl_tcp_low_latency &&
+                   __get_cpu_var(softnet_data).net_dma) {
+                       preempt_enable_no_resched();
+                       tp->ucopy.pinned_list =
+                                       dma_pin_iovec_pages(msg->msg_iov, len);
+               } else {
+                       preempt_enable_no_resched();
+               }
+       }
 #endif
 
        do {
-               struct sk_buff *skb;
                u32 offset;
 
                /* Are we at urgent data? Stop if we have read anything or have SIGURG pending. */
@@ -1436,7 +1452,6 @@ skip_copy:
 
 #ifdef CONFIG_NET_DMA
        if (tp->ucopy.dma_chan) {
-               struct sk_buff *skb;
                dma_cookie_t done, used;
 
                dma_async_memcpy_issue_pending(tp->ucopy.dma_chan);
@@ -1573,14 +1588,12 @@ void tcp_close(struct sock *sk, long timeout)
 
        sk_stream_mem_reclaim(sk);
 
-       /* As outlined in draft-ietf-tcpimpl-prob-03.txt, section
-        * 3.10, we send a RST here because data was lost.  To
-        * witness the awful effects of the old behavior of always
-        * doing a FIN, run an older 2.1.x kernel or 2.0.x, start
-        * a bulk GET in an FTP client, suspend the process, wait
-        * for the client to advertise a zero window, then kill -9
-        * the FTP client, wheee...  Note: timeout is always zero
-        * in such a case.
+       /* As outlined in RFC 2525, section 2.17, we send a RST here because
+        * data was lost. To witness the awful effects of the old behavior of
+        * always doing a FIN, run an older 2.1.x kernel or 2.0.x, start a bulk
+        * GET in an FTP client, suspend the process, wait for the client to
+        * advertise a zero window, then kill -9 the FTP client, wheee...
+        * Note: timeout is always zero in such a case.
         */
        if (data_was_unread) {
                /* Unread data was tossed, zap the connection. */
@@ -1677,9 +1690,8 @@ adjudge_to_death:
        }
        if (sk->sk_state != TCP_CLOSE) {
                sk_stream_mem_reclaim(sk);
-               if (atomic_read(sk->sk_prot->orphan_count) > sysctl_tcp_max_orphans ||
-                   (sk->sk_wmem_queued > SOCK_MIN_SNDBUF &&
-                    atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[2])) {
+               if (tcp_too_many_orphans(sk,
+                               atomic_read(sk->sk_prot->orphan_count))) {
                        if (net_ratelimit())
                                printk(KERN_INFO "TCP: too many of orphaned "
                                       "sockets\n");
@@ -1762,8 +1774,7 @@ int tcp_disconnect(struct sock *sk, int flags)
        tcp_clear_retrans(tp);
        inet_csk_delack_init(sk);
        tcp_init_send_head(sk);
-       tp->rx_opt.saw_tstamp = 0;
-       tcp_sack_reset(&tp->rx_opt);
+       memset(&tp->rx_opt, 0, sizeof(tp->rx_opt));
        __sk_dst_reset(sk);
 
        BUG_TRAP(!inet->num || icsk->icsk_bind_hash);
@@ -2004,7 +2015,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
 
        if (tp->rx_opt.tstamp_ok)
                info->tcpi_options |= TCPI_OPT_TIMESTAMPS;
-       if (tp->rx_opt.sack_ok)
+       if (tcp_is_sack(tp))
                info->tcpi_options |= TCPI_OPT_SACK;
        if (tp->rx_opt.wscale_ok) {
                info->tcpi_options |= TCPI_OPT_WSCALE;
@@ -2020,8 +2031,13 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
        info->tcpi_snd_mss = tp->mss_cache;
        info->tcpi_rcv_mss = icsk->icsk_ack.rcv_mss;
 
-       info->tcpi_unacked = tp->packets_out;
-       info->tcpi_sacked = tp->sacked_out;
+       if (sk->sk_state == TCP_LISTEN) {
+               info->tcpi_unacked = sk->sk_ack_backlog;
+               info->tcpi_sacked = sk->sk_max_ack_backlog;
+       } else {
+               info->tcpi_unacked = tp->packets_out;
+               info->tcpi_sacked = tp->sacked_out;
+       }
        info->tcpi_lost = tp->lost_out;
        info->tcpi_retrans = tp->retrans_out;
        info->tcpi_fackets = tp->fackets_out;
@@ -2200,7 +2216,7 @@ struct sk_buff *tcp_tso_segment(struct sk_buff *skb, int features)
                        goto out;
 
                mss = skb_shinfo(skb)->gso_size;
-               skb_shinfo(skb)->gso_segs = (skb->len + mss - 1) / mss;
+               skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(skb->len, mss);
 
                segs = NULL;
                goto out;
@@ -2421,7 +2437,7 @@ void __init tcp_init(void)
        tcp_hashinfo.bind_bucket_cachep =
                kmem_cache_create("tcp_bind_bucket",
                                  sizeof(struct inet_bind_bucket), 0,
-                                 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
+                                 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
 
        /* Size and allocate the main established and bind bucket
         * hash tables.
@@ -2469,13 +2485,10 @@ void __init tcp_init(void)
                        order++)
                ;
        if (order >= 4) {
-               sysctl_local_port_range[0] = 32768;
-               sysctl_local_port_range[1] = 61000;
                tcp_death_row.sysctl_max_tw_buckets = 180000;
                sysctl_tcp_max_orphans = 4096 << (order - 4);
                sysctl_max_syn_backlog = 1024;
        } else if (order < 3) {
-               sysctl_local_port_range[0] = 1024 * (3 - order);
                tcp_death_row.sysctl_max_tw_buckets >>= (3 - order);
                sysctl_tcp_max_orphans >>= (3 - order);
                sysctl_max_syn_backlog = 128;