Generalise tcp_listen_opt
Subsystems (4)
PATCH 1/2 Generalise tcp_listen_opt
Hi David,
Please consider pulling into your net-2.6.13 pending tree from:
rsync://rsync.kernel.org/pub/scm/linux/kernel/git/acme/net-2.6.13.git
The bksend like output below was done using this script, people
starting to use git may find it useful :-)
http://dccp.ghostprotocols.net:81/acme-git-send-changeset
Best Regards,
- Arnaldo
tree f416accfe16809dce40f34fb711d42a67aea892d
parent 0642cf1e6afa649d8d9a9d3dc7275ceebb038ae0
author Arnaldo Carvalho de Melo <[email protected]> 1113623934 -0300 committer Arnaldo Carvalho de Melo <[email protected]> 1116886806 -0300
[NET] Generalise tcp_listen_opt
This chunks out the accept_queue and tcp_listen_opt code and moves them to net/core/request_sock.c and include/net/request_sock.h, to make it useful for other transport protocols, DCCP being the first one to use it.
Next patches will rename tcp_listen_opt to accept_sock and remove the inline tcp functions that just call a reqsk_queue_ function.
------------------------------------------------------------------------------
include/linux/tcp.h | 17 ---- include/net/request_sock.h | 178 +++++++++++++++++++++++++++++++++++++++++++++ include/net/tcp.h | 46 ++--------- net/core/Makefile | 3 net/core/request_sock.c | 48 ++++++++++++ net/ipv4/tcp.c | 67 +++++----------- net/ipv4/tcp_diag.c | 6 - net/ipv4/tcp_ipv4.c | 32 +++----- net/ipv4/tcp_minisocks.c | 6 - net/ipv4/tcp_timer.c | 10 -- net/ipv6/tcp_ipv6.c | 14 --- 11 files changed, 281 insertions(+), 146 deletions(-)
------------------------------------------------------------------------------
include/linux/tcp.h +1 -16
@@ -379,22 +379,7 @@ struct tcp_sock {__u32 total_retrans;/* Total retransmits for entire connection */ -/* The syn_wait_lock is necessary only to avoid proc interface having -* to grab the main lock sock while browsing the listening hash -* (otherwise it's deadlock prone). -* This lock is acquired in read mode only from listening_get_next() -* and it's acquired in write mode _only_ from code that is actively -* changing the syn_wait_queue. All readers that are holding -* the master sock lock don't need to grab this lock in read mode -* too as the syn_wait_queue writes are always protected from -* the main sock lock. -*/ -rwlock_t syn_wait_lock; -struct tcp_listen_opt *listen_opt; - -/* FIFO of established children */ -struct request_sock *accept_queue; -struct request_sock *accept_queue_tail; +struct request_sock_queue accept_queue;/* FIFO of established children */ unsigned int keepalive_time;/* time before keep alive takes place */ unsigned int keepalive_intvl;/* time interval between keep alive probes */
include/net/request_sock.h +178 -0
189 lines not on this page · raw message
include/net/tcp.h +8 -38
79 lines not on this page · raw message
net/core/Makefile +2 -1
@@ -2,7 +2,8 @@ # Makefile for the Linux networking core. # -obj-y := sock.o skbuff.o iovec.o datagram.o stream.o scm.o gen_stats.o gen_estimator.o +obj-y := sock.o request_sock.o skbuff.o iovec.o datagram.o stream.o scm.o \ + gen_stats.o gen_estimator.o obj-$(CONFIG_SYSCTL) += sysctl_net_core.o
net/core/request_sock.c new file +48 -0
48 lines not on this page · raw message
net/ipv4/tcp.c +21 -46
139 lines not on this page · raw message
net/ipv4/tcp_diag.c +3 -3
@@ -529,9 +529,9 @@ static int tcpdiag_dump_reqs(struct sk_b entry.family = sk->sk_family; -read_lock_bh (&tp->syn_wait_lock); +read_lock_bh (&tp->accept_queue.syn_wait_lock); - lopt = tp->listen_opt; + lopt = tp->accept_queue.listen_opt;if (!lopt || !lopt->qlen) goto out;
@@ -588,7 +588,7 @@ static int tcpdiag_dump_reqs(struct sk_b } out: -read_unlock_bh (&tp->syn_wait_lock); +read_unlock_bh (&tp->accept_queue.syn_wait_lock);return err; }
net/ipv4/tcp_ipv4.c +12 -20
@@ -874,7 +874,7 @@ static struct request_sock *tcp_v4_searc__u16 rport, __u32 raddr, __u32 laddr) { - struct tcp_listen_opt *lopt = tp->listen_opt; + struct tcp_listen_opt *lopt = tp->accept_queue.listen_opt;struct request_sock *req, **prev; for (prev = &lopt->syn_table[tcp_v4_synq_hash(raddr, rport, lopt->hash_rnd)];
@@ -898,18 +898,10 @@ static struct request_sock *tcp_v4_searcstatic void tcp_v4_synq_add (struct sock *sk,struct request_sock *req) {struct tcp_sock *tp =tcp_sk (sk); -struct tcp_listen_opt *lopt = tp->listen_opt; +struct tcp_listen_opt *lopt = tp->accept_queue.listen_opt;u32 h =tcp_v4_synq_hash (inet_rsk (req)->rmt_addr,inet_rsk (req)->rmt_port, lopt->hash_rnd); - req->expires = jiffies +TCP_TIMEOUT_INIT ; - req->retrans =0 ; - req->sk =NULL ; - req->dl_next = lopt->syn_table[h]; - -write_lock (&tp->syn_wait_lock); - lopt->syn_table[h] = req; -write_unlock (&tp->syn_wait_lock); - +reqsk_queue_hash_req (&tp->accept_queue, h, req,TCP_TIMEOUT_INIT );tcp_synq_added (sk); }
@@ -2167,17 +2159,17 @@ static void *listening_get_next(struct sif (++st->sbucket >=TCP_SYNQ_HSIZE )break ; get_req: - req = tp->listen_opt->syn_table[st->sbucket]; + req = tp->accept_queue.listen_opt->syn_table[st->sbucket]; } sk =sk_next (st->syn_wait_sk); st->state =TCP_SEQ_STATE_LISTENING ; -read_unlock_bh (&tp->syn_wait_lock); +read_unlock_bh (&tp->accept_queue.syn_wait_lock); }else { tp =tcp_sk (sk); -read_lock_bh (&tp->syn_wait_lock); -if (tp->listen_opt && tp->listen_opt->qlen) +read_lock_bh (&tp->accept_queue.syn_wait_lock); +if (reqsk_queue_len (&tp->accept_queue)) goto start_req; -read_unlock_bh (&tp->syn_wait_lock); +read_unlock_bh (&tp->accept_queue.syn_wait_lock); sk =sk_next (sk); } get_sk:
@@ -2187,8 +2179,8 @@ get_sk: goto out; } tp =tcp_sk (sk); -read_lock_bh (&tp->syn_wait_lock); -if (tp->listen_opt && tp->listen_opt->qlen) { +read_lock_bh (&tp->accept_queue.syn_wait_lock); +if (reqsk_queue_len (&tp->accept_queue)) { start_req: st->uid =sock_i_uid (sk); st->syn_wait_sk = sk;
@@ -2196,7 +2188,7 @@ start_req: st->sbucket =0 ; goto get_req; } -read_unlock_bh (&tp->syn_wait_lock); +read_unlock_bh (&tp->accept_queue.syn_wait_lock); }if (++st->bucket <TCP_LHTABLE_SIZE ) { sk =sk_head (&tcp_listening_hash[st->bucket]);
@@ -2383,7 +2375,7 @@ static void tcp_seq_stop(struct seq_filecase TCP_SEQ_STATE_OPENREQ :if (v) {struct tcp_sock *tp =tcp_sk (st->syn_wait_sk); -read_unlock_bh (&tp->syn_wait_lock); +read_unlock_bh (&tp->accept_queue.syn_wait_lock); }case TCP_SEQ_STATE_LISTENING :if (v !=SEQ_START_TOKEN )
net/ipv4/tcp_minisocks.c +2 -4
@@ -790,10 +790,8 @@ struct sock *tcp_create_openreq_child(st newtp->probes_out =0 ; newtp->rx_opt.num_sacks =0 ; newtp->urg_data =0 ; - newtp->listen_opt =NULL ; - newtp->accept_queue = newtp->accept_queue_tail =NULL ; -/* Deinitialize syn_wait_lock to trap illegal accesses. */ -memset (&newtp->syn_wait_lock,0 ,sizeof (newtp->syn_wait_lock)); +/* Deinitialize accept_queue to trap illegal accesses. */ +memset (&newtp->accept_queue,0 ,sizeof (newtp->accept_queue));/* Back to base struct sock members. */ newsk->sk_err =0 ;
net/ipv4/tcp_timer.c +3 -7
@@ -464,7 +464,7 @@ out_unlock:static void tcp_synack_timer (struct sock *sk) {struct tcp_sock *tp =tcp_sk (sk); -struct tcp_listen_opt *lopt = tp->listen_opt; +struct tcp_listen_opt *lopt = tp->accept_queue.listen_opt;int max_retries = tp->syn_retries ? : sysctl_tcp_synack_retries;int thresh = max_retries;unsigned long now = jiffies;
@@ -527,12 +527,8 @@ static void tcp_synack_timer(struct sock }/* Drop this request */ -write_lock (&tp->syn_wait_lock); - *reqp = req->dl_next; -write_unlock (&tp->syn_wait_lock); - lopt->qlen--; -if (req->retrans ==0 ) - lopt->qlen_young--; +tcp_synq_unlink (tp, req, reqp); +reqsk_queue_removed (&tp->accept_queue, req);reqsk_free (req);continue ; }
net/ipv6/tcp_ipv6.c +3 -11
@@ -401,7 +401,7 @@ static struct request_sock *tcp_v6_searc struct in6_addr *laddr, int iif) { -struct tcp_listen_opt *lopt = tp->listen_opt; +struct tcp_listen_opt *lopt = tp->accept_queue.listen_opt;struct request_sock *req, **prev; for (prev = &lopt->syn_table[tcp_v6_synq_hash(raddr, rport, lopt->hash_rnd)];
@@ -1267,18 +1267,10 @@ static struct sock *tcp_v6_hnd_req(strucstatic void tcp_v6_synq_add (struct sock *sk,struct request_sock *req) {struct tcp_sock *tp =tcp_sk (sk); -struct tcp_listen_opt *lopt = tp->listen_opt; +struct tcp_listen_opt *lopt = tp->accept_queue.listen_opt;u32 h =tcp_v6_synq_hash (&tcp6_rsk (req)->rmt_addr,inet_rsk (req)->rmt_port, lopt->hash_rnd); - req->sk =NULL ; - req->expires = jiffies +TCP_TIMEOUT_INIT ; - req->retrans =0 ; - req->dl_next = lopt->syn_table[h]; - -write_lock (&tp->syn_wait_lock); - lopt->syn_table[h] = req; -write_unlock (&tp->syn_wait_lock); - +reqsk_queue_hash_req (&tp->accept_queue, h, req,TCP_TIMEOUT_INIT );tcp_synq_added (sk); }