x86: signal: cosmetic unification of NR_restart_syscall
[safe/jmp/linux-2.6] / net / ipv4 / inet_connection_sock.c
index a7fcaf2..bd1278a 100644 (file)
@@ -30,20 +30,22 @@ EXPORT_SYMBOL(inet_csk_timer_bug_msg);
 #endif
 
 /*
- * This array holds the first and last local port number.
+ * This struct holds the first and last local port number.
  */
-int sysctl_local_port_range[2] = { 32768, 61000 };
-DEFINE_SEQLOCK(sysctl_port_range_lock);
+struct local_ports sysctl_local_ports __read_mostly = {
+       .lock = SEQLOCK_UNLOCKED,
+       .range = { 32768, 61000 },
+};
 
 void inet_get_local_port_range(int *low, int *high)
 {
        unsigned seq;
        do {
-               seq = read_seqbegin(&sysctl_port_range_lock);
+               seq = read_seqbegin(&sysctl_local_ports.lock);
 
-               *low = sysctl_local_port_range[0];
-               *high = sysctl_local_port_range[1];
-       } while (read_seqretry(&sysctl_port_range_lock, seq));
+               *low = sysctl_local_ports.range[0];
+               *high = sysctl_local_ports.range[1];
+       } while (read_seqretry(&sysctl_local_ports.lock, seq));
 }
 EXPORT_SYMBOL(inet_get_local_port_range);
 
@@ -55,6 +57,13 @@ int inet_csk_bind_conflict(const struct sock *sk,
        struct hlist_node *node;
        int reuse = sk->sk_reuse;
 
+       /*
+        * Unlike other sk lookup places we do not check
+        * for sk_net here, since _all_ the socks listed
+        * in tb->owners list belong to the same net - the
+        * one this bucket belongs to.
+        */
+
        sk_for_each_bound(sk2, node, &tb->owners) {
                if (sk != sk2 &&
                    !inet_v6_ipv6only(sk2) &&
@@ -96,7 +105,8 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
                rover = net_random() % remaining + low;
 
                do {
-                       head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
+                       head = &hashinfo->bhash[inet_bhashfn(net, rover,
+                                       hashinfo->bhash_size)];
                        spin_lock(&head->lock);
                        inet_bind_bucket_for_each(tb, node, &head->chain)
                                if (tb->ib_net == net && tb->port == rover)
@@ -123,7 +133,8 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
                 */
                snum = rover;
        } else {
-               head = &hashinfo->bhash[inet_bhashfn(snum, hashinfo->bhash_size)];
+               head = &hashinfo->bhash[inet_bhashfn(net, snum,
+                               hashinfo->bhash_size)];
                spin_lock(&head->lock);
                inet_bind_bucket_for_each(tb, node, &head->chain)
                        if (tb->ib_net == net && tb->port == snum)
@@ -133,8 +144,6 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
        goto tb_not_found;
 tb_found:
        if (!hlist_empty(&tb->owners)) {
-               if (sk->sk_reuse > 1)
-                       goto success;
                if (tb->fastreuse > 0 &&
                    sk->sk_reuse && sk->sk_state != TCP_LISTEN) {
                        goto success;
@@ -160,7 +169,7 @@ tb_not_found:
 success:
        if (!inet_csk(sk)->icsk_bind_hash)
                inet_bind_hash(sk, tb, snum);
-       BUG_TRAP(inet_csk(sk)->icsk_bind_hash == tb);
+       WARN_ON(inet_csk(sk)->icsk_bind_hash != tb);
        ret = 0;
 
 fail_unlock:
@@ -253,7 +262,7 @@ struct sock *inet_csk_accept(struct sock *sk, int flags, int *err)
        }
 
        newsk = reqsk_queue_get_child(&icsk->icsk_accept_queue, sk);
-       BUG_TRAP(newsk->sk_state != TCP_SYN_RECV);
+       WARN_ON(newsk->sk_state == TCP_SYN_RECV);
 out:
        release_sock(sk);
        return newsk;
@@ -328,18 +337,20 @@ struct dst_entry* inet_csk_route_req(struct sock *sk,
                                        .saddr = ireq->loc_addr,
                                        .tos = RT_CONN_FLAGS(sk) } },
                            .proto = sk->sk_protocol,
+                           .flags = inet_sk_flowi_flags(sk),
                            .uli_u = { .ports =
                                       { .sport = inet_sk(sk)->sport,
                                         .dport = ireq->rmt_port } } };
+       struct net *net = sock_net(sk);
 
        security_req_classify_flow(req, &fl);
-       if (ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 0)) {
-               IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES);
+       if (ip_route_output_flow(net, &rt, &fl, sk, 0)) {
+               IP_INC_STATS_BH(net, IPSTATS_MIB_OUTNOROUTES);
                return NULL;
        }
        if (opt && opt->is_strictroute && rt->rt_dst != rt->rt_gateway) {
                ip_rt_put(rt);
-               IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES);
+               IP_INC_STATS_BH(net, IPSTATS_MIB_OUTNOROUTES);
                return NULL;
        }
        return &rt->u.dst;
@@ -378,7 +389,7 @@ struct request_sock *inet_csk_search_req(const struct sock *sk,
                    ireq->rmt_addr == raddr &&
                    ireq->loc_addr == laddr &&
                    AF_INET_FAMILY(req->rsk_ops->family)) {
-                       BUG_TRAP(!req->sk);
+                       WARN_ON(req->sk);
                        *prevp = prev;
                        break;
                }
@@ -414,7 +425,8 @@ void inet_csk_reqsk_queue_prune(struct sock *parent,
        struct inet_connection_sock *icsk = inet_csk(parent);
        struct request_sock_queue *queue = &icsk->icsk_accept_queue;
        struct listen_sock *lopt = queue->listen_opt;
-       int thresh = icsk->icsk_syn_retries ? : sysctl_tcp_synack_retries;
+       int max_retries = icsk->icsk_syn_retries ? : sysctl_tcp_synack_retries;
+       int thresh = max_retries;
        unsigned long now = jiffies;
        struct request_sock **reqp, *req;
        int i, budget;
@@ -450,6 +462,9 @@ void inet_csk_reqsk_queue_prune(struct sock *parent,
                }
        }
 
+       if (queue->rskq_defer_accept)
+               max_retries = queue->rskq_defer_accept;
+
        budget = 2 * (lopt->nr_table_entries / (timeout / interval));
        i = lopt->clock_hand;
 
@@ -457,8 +472,9 @@ void inet_csk_reqsk_queue_prune(struct sock *parent,
                reqp=&lopt->syn_table[i];
                while ((req = *reqp) != NULL) {
                        if (time_after_eq(now, req->expires)) {
-                               if (req->retrans < thresh &&
-                                   !req->rsk_ops->rtx_syn_ack(parent, req)) {
+                               if ((req->retrans < thresh ||
+                                    (inet_rsk(req)->acked && req->retrans < max_retries))
+                                   && !req->rsk_ops->rtx_syn_ack(parent, req)) {
                                        unsigned long timeo;
 
                                        if (req->retrans++ == 0)
@@ -502,6 +518,8 @@ struct sock *inet_csk_clone(struct sock *sk, const struct request_sock *req,
                newicsk->icsk_bind_hash = NULL;
 
                inet_sk(newsk)->dport = inet_rsk(req)->rmt_port;
+               inet_sk(newsk)->num = ntohs(inet_rsk(req)->loc_port);
+               inet_sk(newsk)->sport = inet_rsk(req)->loc_port;
                newsk->sk_write_space = sk_stream_write_space;
 
                newicsk->icsk_retransmits = 0;
@@ -526,14 +544,14 @@ EXPORT_SYMBOL_GPL(inet_csk_clone);
  */
 void inet_csk_destroy_sock(struct sock *sk)
 {
-       BUG_TRAP(sk->sk_state == TCP_CLOSE);
-       BUG_TRAP(sock_flag(sk, SOCK_DEAD));
+       WARN_ON(sk->sk_state != TCP_CLOSE);
+       WARN_ON(!sock_flag(sk, SOCK_DEAD));
 
        /* It cannot be in hash table! */
-       BUG_TRAP(sk_unhashed(sk));
+       WARN_ON(!sk_unhashed(sk));
 
        /* If it has not 0 inet_sk(sk)->num, it must be bound */
-       BUG_TRAP(!inet_sk(sk)->num || inet_csk(sk)->icsk_bind_hash);
+       WARN_ON(inet_sk(sk)->num && !inet_csk(sk)->icsk_bind_hash);
 
        sk->sk_prot->destroy(sk);
 
@@ -616,7 +634,7 @@ void inet_csk_listen_stop(struct sock *sk)
 
                local_bh_disable();
                bh_lock_sock(child);
-               BUG_TRAP(!sock_owned_by_user(child));
+               WARN_ON(sock_owned_by_user(child));
                sock_hold(child);
 
                sk->sk_prot->disconnect(child, O_NONBLOCK);
@@ -634,7 +652,7 @@ void inet_csk_listen_stop(struct sock *sk)
                sk_acceptq_removed(sk);
                __reqsk_free(req);
        }
-       BUG_TRAP(!sk->sk_ack_backlog);
+       WARN_ON(sk->sk_ack_backlog);
 }
 
 EXPORT_SYMBOL_GPL(inet_csk_listen_stop);
@@ -651,25 +669,6 @@ void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr)
 
 EXPORT_SYMBOL_GPL(inet_csk_addr2sockaddr);
 
-int inet_csk_ctl_sock_create(struct socket **sock, unsigned short family,
-                            unsigned short type, unsigned char protocol)
-{
-       int rc = sock_create_kern(family, type, protocol, sock);
-
-       if (rc == 0) {
-               (*sock)->sk->sk_allocation = GFP_ATOMIC;
-               inet_sk((*sock)->sk)->uc_ttl = -1;
-               /*
-                * Unhash it so that IP input processing does not even see it,
-                * we do not wish this socket to see incoming packets.
-                */
-               (*sock)->sk->sk_prot->unhash((*sock)->sk);
-       }
-       return rc;
-}
-
-EXPORT_SYMBOL_GPL(inet_csk_ctl_sock_create);
-
 #ifdef CONFIG_COMPAT
 int inet_csk_compat_getsockopt(struct sock *sk, int level, int optname,
                               char __user *optval, int __user *optlen)