Documentation/memory.txt: remove some very outdated recommendations
[safe/jmp/linux-2.6] / net / ipv4 / tcp_ipv4.c
index cf74c41..7cda24b 100644 (file)
@@ -328,26 +328,29 @@ static void do_pmtu_discovery(struct sock *sk, struct iphdr *iph, u32 mtu)
  *
  */
 
-void tcp_v4_err(struct sk_buff *skb, u32 info)
+void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
 {
-       struct iphdr *iph = (struct iphdr *)skb->data;
-       struct tcphdr *th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
+       struct iphdr *iph = (struct iphdr *)icmp_skb->data;
+       struct tcphdr *th = (struct tcphdr *)(icmp_skb->data + (iph->ihl << 2));
+       struct inet_connection_sock *icsk;
        struct tcp_sock *tp;
        struct inet_sock *inet;
-       const int type = icmp_hdr(skb)->type;
-       const int code = icmp_hdr(skb)->code;
+       const int type = icmp_hdr(icmp_skb)->type;
+       const int code = icmp_hdr(icmp_skb)->code;
        struct sock *sk;
+       struct sk_buff *skb;
        __u32 seq;
+       __u32 remaining;
        int err;
-       struct net *net = dev_net(skb->dev);
+       struct net *net = dev_net(icmp_skb->dev);
 
-       if (skb->len < (iph->ihl << 2) + 8) {
+       if (icmp_skb->len < (iph->ihl << 2) + 8) {
                ICMP_INC_STATS_BH(net, ICMP_MIB_INERRORS);
                return;
        }
 
        sk = inet_lookup(net, &tcp_hashinfo, iph->daddr, th->dest,
-                       iph->saddr, th->source, inet_iif(skb));
+                       iph->saddr, th->source, inet_iif(icmp_skb));
        if (!sk) {
                ICMP_INC_STATS_BH(net, ICMP_MIB_INERRORS);
                return;
@@ -367,6 +370,7 @@ void tcp_v4_err(struct sk_buff *skb, u32 info)
        if (sk->sk_state == TCP_CLOSE)
                goto out;
 
+       icsk = inet_csk(sk);
        tp = tcp_sk(sk);
        seq = ntohl(th->seq);
        if (sk->sk_state != TCP_LISTEN &&
@@ -393,6 +397,39 @@ void tcp_v4_err(struct sk_buff *skb, u32 info)
                }
 
                err = icmp_err_convert[code].errno;
+               /* check if icmp_skb allows revert of backoff
+                * (see draft-zimmermann-tcp-lcd) */
+               if (code != ICMP_NET_UNREACH && code != ICMP_HOST_UNREACH)
+                       break;
+               if (seq != tp->snd_una  || !icsk->icsk_retransmits ||
+                   !icsk->icsk_backoff)
+                       break;
+
+               icsk->icsk_backoff--;
+               inet_csk(sk)->icsk_rto = __tcp_set_rto(tp) <<
+                                        icsk->icsk_backoff;
+               tcp_bound_rto(sk);
+
+               skb = tcp_write_queue_head(sk);
+               BUG_ON(!skb);
+
+               remaining = icsk->icsk_rto - min(icsk->icsk_rto,
+                               tcp_time_stamp - TCP_SKB_CB(skb)->when);
+
+               if (remaining) {
+                       inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
+                                                 remaining, TCP_RTO_MAX);
+               } else if (sock_owned_by_user(sk)) {
+                       /* RTO revert clocked out retransmission,
+                        * but socket is locked. Will defer. */
+                       inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
+                                                 HZ/20, TCP_RTO_MAX);
+               } else {
+                       /* RTO revert clocked out retransmission.
+                        * Will retransmit now */
+                       tcp_retransmit_timer(sk);
+               }
+
                break;
        case ICMP_TIME_EXCEEDED:
                err = EHOSTUNREACH;
@@ -546,7 +583,7 @@ static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb)
        if (th->rst)
                return;
 
-       if (skb->rtable->rt_type != RTN_LOCAL)
+       if (skb_rtable(skb)->rt_type != RTN_LOCAL)
                return;
 
        /* Swap the send and the receive. */
@@ -590,7 +627,7 @@ static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb)
        arg.csumoffset = offsetof(struct tcphdr, check) / 2;
        arg.flags = (sk && inet_sk(sk)->transparent) ? IP_REPLY_ARG_NOSRCCHECK : 0;
 
-       net = dev_net(skb->dst->dev);
+       net = dev_net(skb_dst(skb)->dev);
        ip_send_reply(net->ipv4.tcp_sock, skb,
                      &arg, arg.iov[0].iov_len);
 
@@ -617,7 +654,7 @@ static void tcp_v4_send_ack(struct sk_buff *skb, u32 seq, u32 ack,
                        ];
        } rep;
        struct ip_reply_arg arg;
-       struct net *net = dev_net(skb->dst->dev);
+       struct net *net = dev_net(skb_dst(skb)->dev);
 
        memset(&rep.th, 0, sizeof(struct tcphdr));
        memset(&arg, 0, sizeof(arg));
@@ -849,7 +886,7 @@ int tcp_v4_md5_do_add(struct sock *sk, __be32 addr,
                        }
                        sk->sk_route_caps &= ~NETIF_F_GSO_MASK;
                }
-               if (tcp_alloc_md5sig_pool() == NULL) {
+               if (tcp_alloc_md5sig_pool(sk) == NULL) {
                        kfree(newkey);
                        return -ENOMEM;
                }
@@ -970,8 +1007,9 @@ static int tcp_v4_parse_md5_keys(struct sock *sk, char __user *optval,
 
        if (!tcp_sk(sk)->md5sig_info) {
                struct tcp_sock *tp = tcp_sk(sk);
-               struct tcp_md5sig_info *p = kzalloc(sizeof(*p), GFP_KERNEL);
+               struct tcp_md5sig_info *p;
 
+               p = kzalloc(sizeof(*p), sk->sk_allocation);
                if (!p)
                        return -EINVAL;
 
@@ -979,7 +1017,7 @@ static int tcp_v4_parse_md5_keys(struct sock *sk, char __user *optval,
                sk->sk_route_caps &= ~NETIF_F_GSO_MASK;
        }
 
-       newkey = kmemdup(cmd.tcpm_key, cmd.tcpm_keylen, GFP_KERNEL);
+       newkey = kmemdup(cmd.tcpm_key, cmd.tcpm_keylen, sk->sk_allocation);
        if (!newkey)
                return -ENOMEM;
        return tcp_v4_md5_do_add(sk, sin->sin_addr.s_addr,
@@ -1158,8 +1196,9 @@ struct request_sock_ops tcp_request_sock_ops __read_mostly = {
 };
 
 #ifdef CONFIG_TCP_MD5SIG
-static struct tcp_request_sock_ops tcp_request_sock_ipv4_ops = {
+static const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops = {
        .md5_lookup     =       tcp_v4_reqsk_md5_lookup,
+       .calc_md5_hash  =       tcp_v4_md5_hash_skb,
 };
 #endif
 
@@ -1185,7 +1224,7 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
 #endif
 
        /* Never answer to SYNs send to broadcast or multicast */
-       if (skb->rtable->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))
+       if (skb_rtable(skb)->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))
                goto drop;
 
        /* TW buckets are converted to open requests without
@@ -1226,27 +1265,19 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
        if (want_cookie && !tmp_opt.saw_tstamp)
                tcp_clear_options(&tmp_opt);
 
-       if (tmp_opt.saw_tstamp && !tmp_opt.rcv_tsval) {
-               /* Some OSes (unknown ones, but I see them on web server, which
-                * contains information interesting only for windows'
-                * users) do not send their stamp in SYN. It is easy case.
-                * We simply do not advertise TS support.
-                */
-               tmp_opt.saw_tstamp = 0;
-               tmp_opt.tstamp_ok  = 0;
-       }
        tmp_opt.tstamp_ok = tmp_opt.saw_tstamp;
 
        tcp_openreq_init(req, &tmp_opt, skb);
 
-       if (security_inet_conn_request(sk, skb, req))
-               goto drop_and_free;
-
        ireq = inet_rsk(req);
        ireq->loc_addr = daddr;
        ireq->rmt_addr = saddr;
        ireq->no_srccheck = inet_sk(sk)->transparent;
        ireq->opt = tcp_v4_save_options(sk, skb);
+
+       if (security_inet_conn_request(sk, skb, req))
+               goto drop_and_free;
+
        if (!want_cookie)
                TCP_ECN_create_request(req, tcp_hdr(skb));
 
@@ -1381,7 +1412,7 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
                 */
                char *newkey = kmemdup(key->key, key->keylen, GFP_ATOMIC);
                if (newkey != NULL)
-                       tcp_v4_md5_do_add(newsk, inet_sk(sk)->daddr,
+                       tcp_v4_md5_do_add(newsk, newinet->daddr,
                                          newkey, key->keylen);
                newsk->sk_route_caps &= ~NETIF_F_GSO_MASK;
        }
@@ -1601,7 +1632,7 @@ process:
 #endif
                {
                        if (!tcp_prequeue(sk, skb))
-                       ret = tcp_v4_do_rcv(sk, skb);
+                               ret = tcp_v4_do_rcv(sk, skb);
                }
        } else
                sk_add_backlog(sk, skb);
@@ -1724,7 +1755,7 @@ int tcp_v4_tw_remember_stamp(struct inet_timewait_sock *tw)
        return 0;
 }
 
-struct inet_connection_sock_af_ops ipv4_specific = {
+const struct inet_connection_sock_af_ops ipv4_specific = {
        .queue_xmit        = ip_queue_xmit,
        .send_check        = tcp_v4_send_check,
        .rebuild_header    = inet_sk_rebuild_header,
@@ -1744,7 +1775,7 @@ struct inet_connection_sock_af_ops ipv4_specific = {
 };
 
 #ifdef CONFIG_TCP_MD5SIG
-static struct tcp_sock_af_ops tcp_sock_ipv4_specific = {
+static const struct tcp_sock_af_ops tcp_sock_ipv4_specific = {
        .md5_lookup             = tcp_v4_md5_lookup,
        .calc_md5_hash          = tcp_v4_md5_hash_skb,
        .md5_add                = tcp_v4_md5_add_func,
@@ -1777,7 +1808,7 @@ static int tcp_v4_init_sock(struct sock *sk)
        /* See draft-stevens-tcpca-spec-01 for discussion of the
         * initialization of these values.
         */
-       tp->snd_ssthresh = 0x7fffffff;  /* Infinity */
+       tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
        tp->snd_cwnd_clamp = ~0;
        tp->mss_cache = 536;
 
@@ -2253,7 +2284,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
                jiffies_to_clock_t(icsk->icsk_ack.ato),
                (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
                tp->snd_cwnd,
-               tp->snd_ssthresh >= 0xFFFF ? -1 : tp->snd_ssthresh,
+               tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh,
                len);
 }
 
@@ -2351,11 +2382,11 @@ void tcp4_proc_exit(void)
 
 struct sk_buff **tcp4_gro_receive(struct sk_buff **head, struct sk_buff *skb)
 {
-       struct iphdr *iph = ip_hdr(skb);
+       struct iphdr *iph = skb_gro_network_header(skb);
 
        switch (skb->ip_summed) {
        case CHECKSUM_COMPLETE:
-               if (!tcp_v4_check(skb->len, iph->saddr, iph->daddr,
+               if (!tcp_v4_check(skb_gro_len(skb), iph->saddr, iph->daddr,
                                  skb->csum)) {
                        skb->ip_summed = CHECKSUM_UNNECESSARY;
                        break;