[NET]: Just move the inet_connection_sock function from tcp sources
Completing the previous changeset, this also generalises tcp_v4_synq_add, renaming it to inet_csk_reqsk_queue_hash_add, already geing used in the DCCP tree, which I plan to merge RSN. Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
463c84b97f
commit
3f421baa47
@@ -5,7 +5,7 @@
|
||||
obj-y := route.o inetpeer.o protocol.o \
|
||||
ip_input.o ip_fragment.o ip_forward.o ip_options.o \
|
||||
ip_output.o ip_sockglue.o inet_hashtables.o \
|
||||
inet_timewait_sock.o \
|
||||
inet_timewait_sock.o inet_connection_sock.o \
|
||||
tcp.o tcp_input.o tcp_output.o tcp_timer.o tcp_ipv4.o \
|
||||
tcp_minisocks.o tcp_cong.o \
|
||||
datagram.o raw.o udp.o arp.o icmp.o devinet.o af_inet.o igmp.o \
|
||||
|
401
net/ipv4/inet_connection_sock.c
Normal file
401
net/ipv4/inet_connection_sock.c
Normal file
@@ -0,0 +1,401 @@
|
||||
/*
|
||||
* INET An implementation of the TCP/IP protocol suite for the LINUX
|
||||
* operating system. INET is implemented using the BSD Socket
|
||||
* interface as the means of communication with the user level.
|
||||
*
|
||||
* Support for INET connection oriented protocols.
|
||||
*
|
||||
* Authors: See the TCP sources
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version
|
||||
* 2 of the License, or(at your option) any later version.
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/jhash.h>
|
||||
|
||||
#include <net/inet_connection_sock.h>
|
||||
#include <net/inet_hashtables.h>
|
||||
#include <net/inet_timewait_sock.h>
|
||||
#include <net/ip.h>
|
||||
#include <net/route.h>
|
||||
#include <net/tcp_states.h>
|
||||
|
||||
#ifdef INET_CSK_DEBUG
|
||||
const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
|
||||
EXPORT_SYMBOL(inet_csk_timer_bug_msg);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This array holds the first and last local port number.
|
||||
* For high-usage systems, use sysctl to change this to
|
||||
* 32768-61000
|
||||
*/
|
||||
int sysctl_local_port_range[2] = { 1024, 4999 };
|
||||
|
||||
static inline int inet_csk_bind_conflict(struct sock *sk, struct inet_bind_bucket *tb)
|
||||
{
|
||||
const u32 sk_rcv_saddr = inet_rcv_saddr(sk);
|
||||
struct sock *sk2;
|
||||
struct hlist_node *node;
|
||||
int reuse = sk->sk_reuse;
|
||||
|
||||
sk_for_each_bound(sk2, node, &tb->owners) {
|
||||
if (sk != sk2 &&
|
||||
!inet_v6_ipv6only(sk2) &&
|
||||
(!sk->sk_bound_dev_if ||
|
||||
!sk2->sk_bound_dev_if ||
|
||||
sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
|
||||
if (!reuse || !sk2->sk_reuse ||
|
||||
sk2->sk_state == TCP_LISTEN) {
|
||||
const u32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
|
||||
if (!sk2_rcv_saddr || !sk_rcv_saddr ||
|
||||
sk2_rcv_saddr == sk_rcv_saddr)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return node != NULL;
|
||||
}
|
||||
|
||||
/* Obtain a reference to a local port for the given sock,
|
||||
* if snum is zero it means select any available local port.
|
||||
*/
|
||||
int inet_csk_get_port(struct inet_hashinfo *hashinfo,
|
||||
struct sock *sk, unsigned short snum)
|
||||
{
|
||||
struct inet_bind_hashbucket *head;
|
||||
struct hlist_node *node;
|
||||
struct inet_bind_bucket *tb;
|
||||
int ret;
|
||||
|
||||
local_bh_disable();
|
||||
if (!snum) {
|
||||
int low = sysctl_local_port_range[0];
|
||||
int high = sysctl_local_port_range[1];
|
||||
int remaining = (high - low) + 1;
|
||||
int rover;
|
||||
|
||||
spin_lock(&hashinfo->portalloc_lock);
|
||||
if (hashinfo->port_rover < low)
|
||||
rover = low;
|
||||
else
|
||||
rover = hashinfo->port_rover;
|
||||
do {
|
||||
rover++;
|
||||
if (rover > high)
|
||||
rover = low;
|
||||
head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
|
||||
spin_lock(&head->lock);
|
||||
inet_bind_bucket_for_each(tb, node, &head->chain)
|
||||
if (tb->port == rover)
|
||||
goto next;
|
||||
break;
|
||||
next:
|
||||
spin_unlock(&head->lock);
|
||||
} while (--remaining > 0);
|
||||
hashinfo->port_rover = rover;
|
||||
spin_unlock(&hashinfo->portalloc_lock);
|
||||
|
||||
/* Exhausted local port range during search? It is not
|
||||
* possible for us to be holding one of the bind hash
|
||||
* locks if this test triggers, because if 'remaining'
|
||||
* drops to zero, we broke out of the do/while loop at
|
||||
* the top level, not from the 'break;' statement.
|
||||
*/
|
||||
ret = 1;
|
||||
if (remaining <= 0)
|
||||
goto fail;
|
||||
|
||||
/* OK, here is the one we will use. HEAD is
|
||||
* non-NULL and we hold it's mutex.
|
||||
*/
|
||||
snum = rover;
|
||||
} else {
|
||||
head = &hashinfo->bhash[inet_bhashfn(snum, hashinfo->bhash_size)];
|
||||
spin_lock(&head->lock);
|
||||
inet_bind_bucket_for_each(tb, node, &head->chain)
|
||||
if (tb->port == snum)
|
||||
goto tb_found;
|
||||
}
|
||||
tb = NULL;
|
||||
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;
|
||||
} else {
|
||||
ret = 1;
|
||||
if (inet_csk_bind_conflict(sk, tb))
|
||||
goto fail_unlock;
|
||||
}
|
||||
}
|
||||
tb_not_found:
|
||||
ret = 1;
|
||||
if (!tb && (tb = inet_bind_bucket_create(hashinfo->bind_bucket_cachep, head, snum)) == NULL)
|
||||
goto fail_unlock;
|
||||
if (hlist_empty(&tb->owners)) {
|
||||
if (sk->sk_reuse && sk->sk_state != TCP_LISTEN)
|
||||
tb->fastreuse = 1;
|
||||
else
|
||||
tb->fastreuse = 0;
|
||||
} else if (tb->fastreuse &&
|
||||
(!sk->sk_reuse || sk->sk_state == TCP_LISTEN))
|
||||
tb->fastreuse = 0;
|
||||
success:
|
||||
if (!inet_csk(sk)->icsk_bind_hash)
|
||||
inet_bind_hash(sk, tb, snum);
|
||||
BUG_TRAP(inet_csk(sk)->icsk_bind_hash == tb);
|
||||
ret = 0;
|
||||
|
||||
fail_unlock:
|
||||
spin_unlock(&head->lock);
|
||||
fail:
|
||||
local_bh_enable();
|
||||
return ret;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL_GPL(inet_csk_get_port);
|
||||
|
||||
/*
|
||||
* Wait for an incoming connection, avoid race conditions. This must be called
|
||||
* with the socket locked.
|
||||
*/
|
||||
static int inet_csk_wait_for_connect(struct sock *sk, long timeo)
|
||||
{
|
||||
struct inet_connection_sock *icsk = inet_csk(sk);
|
||||
DEFINE_WAIT(wait);
|
||||
int err;
|
||||
|
||||
/*
|
||||
* True wake-one mechanism for incoming connections: only
|
||||
* one process gets woken up, not the 'whole herd'.
|
||||
* Since we do not 'race & poll' for established sockets
|
||||
* anymore, the common case will execute the loop only once.
|
||||
*
|
||||
* Subtle issue: "add_wait_queue_exclusive()" will be added
|
||||
* after any current non-exclusive waiters, and we know that
|
||||
* it will always _stay_ after any new non-exclusive waiters
|
||||
* because all non-exclusive waiters are added at the
|
||||
* beginning of the wait-queue. As such, it's ok to "drop"
|
||||
* our exclusiveness temporarily when we get woken up without
|
||||
* having to remove and re-insert us on the wait queue.
|
||||
*/
|
||||
for (;;) {
|
||||
prepare_to_wait_exclusive(sk->sk_sleep, &wait,
|
||||
TASK_INTERRUPTIBLE);
|
||||
release_sock(sk);
|
||||
if (reqsk_queue_empty(&icsk->icsk_accept_queue))
|
||||
timeo = schedule_timeout(timeo);
|
||||
lock_sock(sk);
|
||||
err = 0;
|
||||
if (!reqsk_queue_empty(&icsk->icsk_accept_queue))
|
||||
break;
|
||||
err = -EINVAL;
|
||||
if (sk->sk_state != TCP_LISTEN)
|
||||
break;
|
||||
err = sock_intr_errno(timeo);
|
||||
if (signal_pending(current))
|
||||
break;
|
||||
err = -EAGAIN;
|
||||
if (!timeo)
|
||||
break;
|
||||
}
|
||||
finish_wait(sk->sk_sleep, &wait);
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* This will accept the next outstanding connection.
|
||||
*/
|
||||
struct sock *inet_csk_accept(struct sock *sk, int flags, int *err)
|
||||
{
|
||||
struct inet_connection_sock *icsk = inet_csk(sk);
|
||||
struct sock *newsk;
|
||||
int error;
|
||||
|
||||
lock_sock(sk);
|
||||
|
||||
/* We need to make sure that this socket is listening,
|
||||
* and that it has something pending.
|
||||
*/
|
||||
error = -EINVAL;
|
||||
if (sk->sk_state != TCP_LISTEN)
|
||||
goto out_err;
|
||||
|
||||
/* Find already established connection */
|
||||
if (reqsk_queue_empty(&icsk->icsk_accept_queue)) {
|
||||
long timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
|
||||
|
||||
/* If this is a non blocking socket don't sleep */
|
||||
error = -EAGAIN;
|
||||
if (!timeo)
|
||||
goto out_err;
|
||||
|
||||
error = inet_csk_wait_for_connect(sk, timeo);
|
||||
if (error)
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
newsk = reqsk_queue_get_child(&icsk->icsk_accept_queue, sk);
|
||||
BUG_TRAP(newsk->sk_state != TCP_SYN_RECV);
|
||||
out:
|
||||
release_sock(sk);
|
||||
return newsk;
|
||||
out_err:
|
||||
newsk = NULL;
|
||||
*err = error;
|
||||
goto out;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(inet_csk_accept);
|
||||
|
||||
/*
|
||||
* Using different timers for retransmit, delayed acks and probes
|
||||
* We may wish use just one timer maintaining a list of expire jiffies
|
||||
* to optimize.
|
||||
*/
|
||||
void inet_csk_init_xmit_timers(struct sock *sk,
|
||||
void (*retransmit_handler)(unsigned long),
|
||||
void (*delack_handler)(unsigned long),
|
||||
void (*keepalive_handler)(unsigned long))
|
||||
{
|
||||
struct inet_connection_sock *icsk = inet_csk(sk);
|
||||
|
||||
init_timer(&icsk->icsk_retransmit_timer);
|
||||
init_timer(&icsk->icsk_delack_timer);
|
||||
init_timer(&sk->sk_timer);
|
||||
|
||||
icsk->icsk_retransmit_timer.function = retransmit_handler;
|
||||
icsk->icsk_delack_timer.function = delack_handler;
|
||||
sk->sk_timer.function = keepalive_handler;
|
||||
|
||||
icsk->icsk_retransmit_timer.data =
|
||||
icsk->icsk_delack_timer.data =
|
||||
sk->sk_timer.data = (unsigned long)sk;
|
||||
|
||||
icsk->icsk_pending = icsk->icsk_ack.pending = 0;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(inet_csk_init_xmit_timers);
|
||||
|
||||
void inet_csk_clear_xmit_timers(struct sock *sk)
|
||||
{
|
||||
struct inet_connection_sock *icsk = inet_csk(sk);
|
||||
|
||||
icsk->icsk_pending = icsk->icsk_ack.pending = icsk->icsk_ack.blocked = 0;
|
||||
|
||||
sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
|
||||
sk_stop_timer(sk, &icsk->icsk_delack_timer);
|
||||
sk_stop_timer(sk, &sk->sk_timer);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(inet_csk_clear_xmit_timers);
|
||||
|
||||
void inet_csk_delete_keepalive_timer(struct sock *sk)
|
||||
{
|
||||
sk_stop_timer(sk, &sk->sk_timer);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(inet_csk_delete_keepalive_timer);
|
||||
|
||||
void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long len)
|
||||
{
|
||||
sk_reset_timer(sk, &sk->sk_timer, jiffies + len);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(inet_csk_reset_keepalive_timer);
|
||||
|
||||
struct dst_entry* inet_csk_route_req(struct sock *sk,
|
||||
const struct request_sock *req)
|
||||
{
|
||||
struct rtable *rt;
|
||||
const struct inet_request_sock *ireq = inet_rsk(req);
|
||||
struct ip_options *opt = inet_rsk(req)->opt;
|
||||
struct flowi fl = { .oif = sk->sk_bound_dev_if,
|
||||
.nl_u = { .ip4_u =
|
||||
{ .daddr = ((opt && opt->srr) ?
|
||||
opt->faddr :
|
||||
ireq->rmt_addr),
|
||||
.saddr = ireq->loc_addr,
|
||||
.tos = RT_CONN_FLAGS(sk) } },
|
||||
.proto = sk->sk_protocol,
|
||||
.uli_u = { .ports =
|
||||
{ .sport = inet_sk(sk)->sport,
|
||||
.dport = ireq->rmt_port } } };
|
||||
|
||||
if (ip_route_output_flow(&rt, &fl, sk, 0)) {
|
||||
IP_INC_STATS_BH(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);
|
||||
return NULL;
|
||||
}
|
||||
return &rt->u.dst;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL_GPL(inet_csk_route_req);
|
||||
|
||||
static inline u32 inet_synq_hash(const u32 raddr, const u16 rport,
|
||||
const u32 rnd, const u16 synq_hsize)
|
||||
{
|
||||
return jhash_2words(raddr, (u32)rport, rnd) & (synq_hsize - 1);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
|
||||
#define AF_INET_FAMILY(fam) ((fam) == AF_INET)
|
||||
#else
|
||||
#define AF_INET_FAMILY(fam) 1
|
||||
#endif
|
||||
|
||||
struct request_sock *inet_csk_search_req(const struct sock *sk,
|
||||
struct request_sock ***prevp,
|
||||
const __u16 rport, const __u32 raddr,
|
||||
const __u32 laddr)
|
||||
{
|
||||
const struct inet_connection_sock *icsk = inet_csk(sk);
|
||||
struct listen_sock *lopt = icsk->icsk_accept_queue.listen_opt;
|
||||
struct request_sock *req, **prev;
|
||||
|
||||
for (prev = &lopt->syn_table[inet_synq_hash(raddr, rport, lopt->hash_rnd,
|
||||
lopt->nr_table_entries)];
|
||||
(req = *prev) != NULL;
|
||||
prev = &req->dl_next) {
|
||||
const struct inet_request_sock *ireq = inet_rsk(req);
|
||||
|
||||
if (ireq->rmt_port == rport &&
|
||||
ireq->rmt_addr == raddr &&
|
||||
ireq->loc_addr == laddr &&
|
||||
AF_INET_FAMILY(req->rsk_ops->family)) {
|
||||
BUG_TRAP(!req->sk);
|
||||
*prevp = prev;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return req;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL_GPL(inet_csk_search_req);
|
||||
|
||||
void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
|
||||
const unsigned timeout)
|
||||
{
|
||||
struct inet_connection_sock *icsk = inet_csk(sk);
|
||||
struct listen_sock *lopt = icsk->icsk_accept_queue.listen_opt;
|
||||
const u32 h = inet_synq_hash(inet_rsk(req)->rmt_addr, inet_rsk(req)->rmt_port,
|
||||
lopt->hash_rnd, lopt->nr_table_entries);
|
||||
|
||||
reqsk_queue_hash_req(&icsk->icsk_accept_queue, h, req, timeout);
|
||||
inet_csk_reqsk_queue_added(sk, timeout);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL_GPL(inet_csk_reqsk_queue_hash_add);
|
@@ -1804,98 +1804,6 @@ int tcp_disconnect(struct sock *sk, int flags)
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for an incoming connection, avoid race
|
||||
* conditions. This must be called with the socket locked.
|
||||
*/
|
||||
static int wait_for_connect(struct sock *sk, long timeo)
|
||||
{
|
||||
struct inet_connection_sock *icsk = inet_csk(sk);
|
||||
DEFINE_WAIT(wait);
|
||||
int err;
|
||||
|
||||
/*
|
||||
* True wake-one mechanism for incoming connections: only
|
||||
* one process gets woken up, not the 'whole herd'.
|
||||
* Since we do not 'race & poll' for established sockets
|
||||
* anymore, the common case will execute the loop only once.
|
||||
*
|
||||
* Subtle issue: "add_wait_queue_exclusive()" will be added
|
||||
* after any current non-exclusive waiters, and we know that
|
||||
* it will always _stay_ after any new non-exclusive waiters
|
||||
* because all non-exclusive waiters are added at the
|
||||
* beginning of the wait-queue. As such, it's ok to "drop"
|
||||
* our exclusiveness temporarily when we get woken up without
|
||||
* having to remove and re-insert us on the wait queue.
|
||||
*/
|
||||
for (;;) {
|
||||
prepare_to_wait_exclusive(sk->sk_sleep, &wait,
|
||||
TASK_INTERRUPTIBLE);
|
||||
release_sock(sk);
|
||||
if (reqsk_queue_empty(&icsk->icsk_accept_queue))
|
||||
timeo = schedule_timeout(timeo);
|
||||
lock_sock(sk);
|
||||
err = 0;
|
||||
if (!reqsk_queue_empty(&icsk->icsk_accept_queue))
|
||||
break;
|
||||
err = -EINVAL;
|
||||
if (sk->sk_state != TCP_LISTEN)
|
||||
break;
|
||||
err = sock_intr_errno(timeo);
|
||||
if (signal_pending(current))
|
||||
break;
|
||||
err = -EAGAIN;
|
||||
if (!timeo)
|
||||
break;
|
||||
}
|
||||
finish_wait(sk->sk_sleep, &wait);
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* This will accept the next outstanding connection.
|
||||
*/
|
||||
|
||||
struct sock *inet_csk_accept(struct sock *sk, int flags, int *err)
|
||||
{
|
||||
struct inet_connection_sock *icsk = inet_csk(sk);
|
||||
struct sock *newsk;
|
||||
int error;
|
||||
|
||||
lock_sock(sk);
|
||||
|
||||
/* We need to make sure that this socket is listening,
|
||||
* and that it has something pending.
|
||||
*/
|
||||
error = -EINVAL;
|
||||
if (sk->sk_state != TCP_LISTEN)
|
||||
goto out_err;
|
||||
|
||||
/* Find already established connection */
|
||||
if (reqsk_queue_empty(&icsk->icsk_accept_queue)) {
|
||||
long timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
|
||||
|
||||
/* If this is a non blocking socket don't sleep */
|
||||
error = -EAGAIN;
|
||||
if (!timeo)
|
||||
goto out_err;
|
||||
|
||||
error = wait_for_connect(sk, timeo);
|
||||
if (error)
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
newsk = reqsk_queue_get_child(&icsk->icsk_accept_queue, sk);
|
||||
BUG_TRAP(newsk->sk_state != TCP_SYN_RECV);
|
||||
out:
|
||||
release_sock(sk);
|
||||
return newsk;
|
||||
out_err:
|
||||
newsk = NULL;
|
||||
*err = error;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Socket option code for TCP.
|
||||
*/
|
||||
@@ -2344,7 +2252,6 @@ void __init tcp_init(void)
|
||||
tcp_register_congestion_control(&tcp_reno);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(inet_csk_accept);
|
||||
EXPORT_SYMBOL(tcp_close);
|
||||
EXPORT_SYMBOL(tcp_destroy_sock);
|
||||
EXPORT_SYMBOL(tcp_disconnect);
|
||||
|
@@ -1278,7 +1278,7 @@ static int tcp_check_sack_reneging(struct sock *sk)
|
||||
inet_csk(sk)->icsk_retransmits++;
|
||||
tcp_retransmit_skb(sk, skb_peek(&sk->sk_write_queue));
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
|
||||
inet_csk(sk)->icsk_rto);
|
||||
inet_csk(sk)->icsk_rto, TCP_RTO_MAX);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -1961,7 +1961,7 @@ static inline void tcp_ack_packets_out(struct sock *sk, struct tcp_sock *tp)
|
||||
if (!tp->packets_out) {
|
||||
inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS);
|
||||
} else {
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, inet_csk(sk)->icsk_rto);
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, inet_csk(sk)->icsk_rto, TCP_RTO_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2147,7 +2147,8 @@ static void tcp_ack_probe(struct sock *sk)
|
||||
*/
|
||||
} else {
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0,
|
||||
min(icsk->icsk_rto << icsk->icsk_backoff, TCP_RTO_MAX));
|
||||
min(icsk->icsk_rto << icsk->icsk_backoff, TCP_RTO_MAX),
|
||||
TCP_RTO_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3968,7 +3969,8 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
|
||||
inet_csk(sk)->icsk_ack.ato = TCP_ATO_MIN;
|
||||
tcp_incr_quickack(sk);
|
||||
tcp_enter_quickack_mode(sk);
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK, TCP_DELACK_MAX);
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK,
|
||||
TCP_DELACK_MAX, TCP_RTO_MAX);
|
||||
|
||||
discard:
|
||||
__kfree_skb(skb);
|
||||
|
@@ -97,138 +97,6 @@ struct inet_hashinfo __cacheline_aligned tcp_hashinfo = {
|
||||
.port_rover = 1024 - 1,
|
||||
};
|
||||
|
||||
/*
|
||||
* This array holds the first and last local port number.
|
||||
* For high-usage systems, use sysctl to change this to
|
||||
* 32768-61000
|
||||
*/
|
||||
int sysctl_local_port_range[2] = { 1024, 4999 };
|
||||
|
||||
static inline int inet_csk_bind_conflict(struct sock *sk, struct inet_bind_bucket *tb)
|
||||
{
|
||||
const u32 sk_rcv_saddr = inet_rcv_saddr(sk);
|
||||
struct sock *sk2;
|
||||
struct hlist_node *node;
|
||||
int reuse = sk->sk_reuse;
|
||||
|
||||
sk_for_each_bound(sk2, node, &tb->owners) {
|
||||
if (sk != sk2 &&
|
||||
!inet_v6_ipv6only(sk2) &&
|
||||
(!sk->sk_bound_dev_if ||
|
||||
!sk2->sk_bound_dev_if ||
|
||||
sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
|
||||
if (!reuse || !sk2->sk_reuse ||
|
||||
sk2->sk_state == TCP_LISTEN) {
|
||||
const u32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
|
||||
if (!sk2_rcv_saddr || !sk_rcv_saddr ||
|
||||
sk2_rcv_saddr == sk_rcv_saddr)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return node != NULL;
|
||||
}
|
||||
|
||||
/* Obtain a reference to a local port for the given sock,
|
||||
* if snum is zero it means select any available local port.
|
||||
*/
|
||||
int inet_csk_get_port(struct inet_hashinfo *hashinfo,
|
||||
struct sock *sk, unsigned short snum)
|
||||
{
|
||||
struct inet_bind_hashbucket *head;
|
||||
struct hlist_node *node;
|
||||
struct inet_bind_bucket *tb;
|
||||
int ret;
|
||||
|
||||
local_bh_disable();
|
||||
if (!snum) {
|
||||
int low = sysctl_local_port_range[0];
|
||||
int high = sysctl_local_port_range[1];
|
||||
int remaining = (high - low) + 1;
|
||||
int rover;
|
||||
|
||||
spin_lock(&hashinfo->portalloc_lock);
|
||||
if (hashinfo->port_rover < low)
|
||||
rover = low;
|
||||
else
|
||||
rover = hashinfo->port_rover;
|
||||
do {
|
||||
rover++;
|
||||
if (rover > high)
|
||||
rover = low;
|
||||
head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
|
||||
spin_lock(&head->lock);
|
||||
inet_bind_bucket_for_each(tb, node, &head->chain)
|
||||
if (tb->port == rover)
|
||||
goto next;
|
||||
break;
|
||||
next:
|
||||
spin_unlock(&head->lock);
|
||||
} while (--remaining > 0);
|
||||
hashinfo->port_rover = rover;
|
||||
spin_unlock(&hashinfo->portalloc_lock);
|
||||
|
||||
/* Exhausted local port range during search? It is not
|
||||
* possible for us to be holding one of the bind hash
|
||||
* locks if this test triggers, because if 'remaining'
|
||||
* drops to zero, we broke out of the do/while loop at
|
||||
* the top level, not from the 'break;' statement.
|
||||
*/
|
||||
ret = 1;
|
||||
if (unlikely(remaining <= 0))
|
||||
goto fail;
|
||||
|
||||
/* OK, here is the one we will use. HEAD is
|
||||
* non-NULL and we hold it's mutex.
|
||||
*/
|
||||
snum = rover;
|
||||
} else {
|
||||
head = &hashinfo->bhash[inet_bhashfn(snum, hashinfo->bhash_size)];
|
||||
spin_lock(&head->lock);
|
||||
inet_bind_bucket_for_each(tb, node, &head->chain)
|
||||
if (tb->port == snum)
|
||||
goto tb_found;
|
||||
}
|
||||
tb = NULL;
|
||||
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;
|
||||
} else {
|
||||
ret = 1;
|
||||
if (inet_csk_bind_conflict(sk, tb))
|
||||
goto fail_unlock;
|
||||
}
|
||||
}
|
||||
tb_not_found:
|
||||
ret = 1;
|
||||
if (!tb && (tb = inet_bind_bucket_create(hashinfo->bind_bucket_cachep, head, snum)) == NULL)
|
||||
goto fail_unlock;
|
||||
if (hlist_empty(&tb->owners)) {
|
||||
if (sk->sk_reuse && sk->sk_state != TCP_LISTEN)
|
||||
tb->fastreuse = 1;
|
||||
else
|
||||
tb->fastreuse = 0;
|
||||
} else if (tb->fastreuse &&
|
||||
(!sk->sk_reuse || sk->sk_state == TCP_LISTEN))
|
||||
tb->fastreuse = 0;
|
||||
success:
|
||||
if (!inet_csk(sk)->icsk_bind_hash)
|
||||
inet_bind_hash(sk, tb, snum);
|
||||
BUG_TRAP(inet_csk(sk)->icsk_bind_hash == tb);
|
||||
ret = 0;
|
||||
|
||||
fail_unlock:
|
||||
spin_unlock(&head->lock);
|
||||
fail:
|
||||
local_bh_enable();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int tcp_v4_get_port(struct sock *sk, unsigned short snum)
|
||||
{
|
||||
return inet_csk_get_port(&tcp_hashinfo, sk, snum);
|
||||
@@ -568,52 +436,6 @@ static inline int inet_iif(const struct sk_buff *skb)
|
||||
return ((struct rtable *)skb->dst)->rt_iif;
|
||||
}
|
||||
|
||||
static inline u32 inet_synq_hash(const u32 raddr, const u16 rport,
|
||||
const u32 rnd, const u16 synq_hsize)
|
||||
{
|
||||
return jhash_2words(raddr, (u32)rport, rnd) & (synq_hsize - 1);
|
||||
}
|
||||
|
||||
struct request_sock *inet_csk_search_req(const struct sock *sk,
|
||||
struct request_sock ***prevp,
|
||||
const __u16 rport, const __u32 raddr,
|
||||
const __u32 laddr)
|
||||
{
|
||||
const struct inet_connection_sock *icsk = inet_csk(sk);
|
||||
struct listen_sock *lopt = icsk->icsk_accept_queue.listen_opt;
|
||||
struct request_sock *req, **prev;
|
||||
|
||||
for (prev = &lopt->syn_table[inet_synq_hash(raddr, rport, lopt->hash_rnd,
|
||||
lopt->nr_table_entries)];
|
||||
(req = *prev) != NULL;
|
||||
prev = &req->dl_next) {
|
||||
const struct inet_request_sock *ireq = inet_rsk(req);
|
||||
|
||||
if (ireq->rmt_port == rport &&
|
||||
ireq->rmt_addr == raddr &&
|
||||
ireq->loc_addr == laddr &&
|
||||
AF_INET_FAMILY(req->rsk_ops->family)) {
|
||||
BUG_TRAP(!req->sk);
|
||||
*prevp = prev;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return req;
|
||||
}
|
||||
|
||||
static void tcp_v4_synq_add(struct sock *sk, struct request_sock *req)
|
||||
{
|
||||
struct inet_connection_sock *icsk = inet_csk(sk);
|
||||
struct listen_sock *lopt = icsk->icsk_accept_queue.listen_opt;
|
||||
const u32 h = inet_synq_hash(inet_rsk(req)->rmt_addr, inet_rsk(req)->rmt_port,
|
||||
lopt->hash_rnd, lopt->nr_table_entries);
|
||||
|
||||
reqsk_queue_hash_req(&icsk->icsk_accept_queue, h, req, TCP_TIMEOUT_INIT);
|
||||
inet_csk_reqsk_queue_added(sk, TCP_TIMEOUT_INIT);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This routine does path mtu discovery as defined in RFC1191.
|
||||
*/
|
||||
@@ -963,36 +785,6 @@ static void tcp_v4_reqsk_send_ack(struct sk_buff *skb, struct request_sock *req)
|
||||
req->ts_recent);
|
||||
}
|
||||
|
||||
struct dst_entry* inet_csk_route_req(struct sock *sk,
|
||||
const struct request_sock *req)
|
||||
{
|
||||
struct rtable *rt;
|
||||
const struct inet_request_sock *ireq = inet_rsk(req);
|
||||
struct ip_options *opt = inet_rsk(req)->opt;
|
||||
struct flowi fl = { .oif = sk->sk_bound_dev_if,
|
||||
.nl_u = { .ip4_u =
|
||||
{ .daddr = ((opt && opt->srr) ?
|
||||
opt->faddr :
|
||||
ireq->rmt_addr),
|
||||
.saddr = ireq->loc_addr,
|
||||
.tos = RT_CONN_FLAGS(sk) } },
|
||||
.proto = sk->sk_protocol,
|
||||
.uli_u = { .ports =
|
||||
{ .sport = inet_sk(sk)->sport,
|
||||
.dport = ireq->rmt_port } } };
|
||||
|
||||
if (ip_route_output_flow(&rt, &fl, sk, 0)) {
|
||||
IP_INC_STATS_BH(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);
|
||||
return NULL;
|
||||
}
|
||||
return &rt->u.dst;
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a SYN-ACK after having received an ACK.
|
||||
* This still operates on a request_sock only, not on a big
|
||||
@@ -1222,7 +1014,7 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
|
||||
if (want_cookie) {
|
||||
reqsk_free(req);
|
||||
} else {
|
||||
tcp_v4_synq_add(sk, req);
|
||||
inet_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT);
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
@@ -1493,7 +1493,8 @@ void tcp_xmit_retransmit_queue(struct sock *sk)
|
||||
if (skb ==
|
||||
skb_peek(&sk->sk_write_queue))
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
|
||||
inet_csk(sk)->icsk_rto);
|
||||
inet_csk(sk)->icsk_rto,
|
||||
TCP_RTO_MAX);
|
||||
}
|
||||
|
||||
packet_cnt -= tcp_skb_pcount(skb);
|
||||
@@ -1546,7 +1547,9 @@ void tcp_xmit_retransmit_queue(struct sock *sk)
|
||||
break;
|
||||
|
||||
if (skb == skb_peek(&sk->sk_write_queue))
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, inet_csk(sk)->icsk_rto);
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
|
||||
inet_csk(sk)->icsk_rto,
|
||||
TCP_RTO_MAX);
|
||||
|
||||
NET_INC_STATS_BH(LINUX_MIB_TCPFORWARDRETRANS);
|
||||
}
|
||||
@@ -1826,7 +1829,8 @@ int tcp_connect(struct sock *sk)
|
||||
TCP_INC_STATS(TCP_MIB_ACTIVEOPENS);
|
||||
|
||||
/* Timer for repeating the SYN until an answer. */
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, inet_csk(sk)->icsk_rto);
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
|
||||
inet_csk(sk)->icsk_rto, TCP_RTO_MAX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1901,7 +1905,8 @@ void tcp_send_ack(struct sock *sk)
|
||||
if (buff == NULL) {
|
||||
inet_csk_schedule_ack(sk);
|
||||
inet_csk(sk)->icsk_ack.ato = TCP_ATO_MIN;
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK, TCP_DELACK_MAX);
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK,
|
||||
TCP_DELACK_MAX, TCP_RTO_MAX);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2033,7 +2038,8 @@ void tcp_send_probe0(struct sock *sk)
|
||||
icsk->icsk_backoff++;
|
||||
tp->probes_out++;
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0,
|
||||
min(icsk->icsk_rto << icsk->icsk_backoff, TCP_RTO_MAX));
|
||||
min(icsk->icsk_rto << icsk->icsk_backoff, TCP_RTO_MAX),
|
||||
TCP_RTO_MAX);
|
||||
} else {
|
||||
/* If packet was not sent due to local congestion,
|
||||
* do not backoff and do not remember probes_out.
|
||||
@@ -2045,7 +2051,8 @@ void tcp_send_probe0(struct sock *sk)
|
||||
tp->probes_out=1;
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0,
|
||||
min(icsk->icsk_rto << icsk->icsk_backoff,
|
||||
TCP_RESOURCE_PROBE_INTERVAL));
|
||||
TCP_RESOURCE_PROBE_INTERVAL),
|
||||
TCP_RTO_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -36,55 +36,14 @@ static void tcp_write_timer(unsigned long);
|
||||
static void tcp_delack_timer(unsigned long);
|
||||
static void tcp_keepalive_timer (unsigned long data);
|
||||
|
||||
#ifdef INET_CSK_DEBUG
|
||||
const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
|
||||
EXPORT_SYMBOL(inet_csk_timer_bug_msg);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Using different timers for retransmit, delayed acks and probes
|
||||
* We may wish use just one timer maintaining a list of expire jiffies
|
||||
* to optimize.
|
||||
*/
|
||||
void inet_csk_init_xmit_timers(struct sock *sk,
|
||||
void (*retransmit_handler)(unsigned long),
|
||||
void (*delack_handler)(unsigned long),
|
||||
void (*keepalive_handler)(unsigned long))
|
||||
{
|
||||
struct inet_connection_sock *icsk = inet_csk(sk);
|
||||
|
||||
init_timer(&icsk->icsk_retransmit_timer);
|
||||
init_timer(&icsk->icsk_delack_timer);
|
||||
init_timer(&sk->sk_timer);
|
||||
|
||||
icsk->icsk_retransmit_timer.function = retransmit_handler;
|
||||
icsk->icsk_delack_timer.function = delack_handler;
|
||||
sk->sk_timer.function = keepalive_handler;
|
||||
|
||||
icsk->icsk_retransmit_timer.data =
|
||||
icsk->icsk_delack_timer.data =
|
||||
sk->sk_timer.data = (unsigned long)sk;
|
||||
|
||||
icsk->icsk_pending = icsk->icsk_ack.pending = 0;
|
||||
}
|
||||
|
||||
void inet_csk_clear_xmit_timers(struct sock *sk)
|
||||
{
|
||||
struct inet_connection_sock *icsk = inet_csk(sk);
|
||||
|
||||
icsk->icsk_pending = icsk->icsk_ack.pending = icsk->icsk_ack.blocked = 0;
|
||||
|
||||
sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
|
||||
sk_stop_timer(sk, &icsk->icsk_delack_timer);
|
||||
sk_stop_timer(sk, &sk->sk_timer);
|
||||
}
|
||||
|
||||
void tcp_init_xmit_timers(struct sock *sk)
|
||||
{
|
||||
inet_csk_init_xmit_timers(sk, &tcp_write_timer, &tcp_delack_timer,
|
||||
&tcp_keepalive_timer);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(tcp_init_xmit_timers);
|
||||
|
||||
static void tcp_write_err(struct sock *sk)
|
||||
{
|
||||
sk->sk_err = sk->sk_err_soft ? : ETIMEDOUT;
|
||||
@@ -392,7 +351,8 @@ static void tcp_retransmit_timer(struct sock *sk)
|
||||
if (!icsk->icsk_retransmits)
|
||||
icsk->icsk_retransmits = 1;
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
|
||||
min(icsk->icsk_rto, TCP_RESOURCE_PROBE_INTERVAL));
|
||||
min(icsk->icsk_rto, TCP_RESOURCE_PROBE_INTERVAL),
|
||||
TCP_RTO_MAX);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -416,7 +376,7 @@ static void tcp_retransmit_timer(struct sock *sk)
|
||||
|
||||
out_reset_timer:
|
||||
icsk->icsk_rto = min(icsk->icsk_rto << 1, TCP_RTO_MAX);
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, icsk->icsk_rto);
|
||||
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, icsk->icsk_rto, TCP_RTO_MAX);
|
||||
if (icsk->icsk_retransmits > sysctl_tcp_retries1)
|
||||
__sk_dst_reset(sk);
|
||||
|
||||
@@ -553,16 +513,6 @@ static void tcp_synack_timer(struct sock *sk)
|
||||
inet_csk_reset_keepalive_timer(sk, TCP_SYNQ_INTERVAL);
|
||||
}
|
||||
|
||||
void inet_csk_delete_keepalive_timer(struct sock *sk)
|
||||
{
|
||||
sk_stop_timer(sk, &sk->sk_timer);
|
||||
}
|
||||
|
||||
void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long len)
|
||||
{
|
||||
sk_reset_timer(sk, &sk->sk_timer, jiffies + len);
|
||||
}
|
||||
|
||||
void tcp_set_keepalive(struct sock *sk, int val)
|
||||
{
|
||||
if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))
|
||||
@@ -653,8 +603,3 @@ out:
|
||||
bh_unlock_sock(sk);
|
||||
sock_put(sk);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(inet_csk_clear_xmit_timers);
|
||||
EXPORT_SYMBOL(inet_csk_delete_keepalive_timer);
|
||||
EXPORT_SYMBOL(tcp_init_xmit_timers);
|
||||
EXPORT_SYMBOL(inet_csk_reset_keepalive_timer);
|
||||
|
Reference in New Issue
Block a user