Commit 59f379f9 authored by Kees Cook's avatar Kees Cook Committed by David S. Miller

inet/connection_sock: Convert timers to use timer_setup()

In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" <davem@davemloft.net>
Cc: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Cc: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Cc: netdev@vger.kernel.org
Cc: dccp@vger.kernel.org
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a92c5751
...@@ -169,9 +169,9 @@ enum inet_csk_ack_state_t { ...@@ -169,9 +169,9 @@ enum inet_csk_ack_state_t {
}; };
void inet_csk_init_xmit_timers(struct sock *sk, void inet_csk_init_xmit_timers(struct sock *sk,
void (*retransmit_handler)(unsigned long), void (*retransmit_handler)(struct timer_list *),
void (*delack_handler)(unsigned long), void (*delack_handler)(struct timer_list *),
void (*keepalive_handler)(unsigned long)); void (*keepalive_handler)(struct timer_list *));
void inet_csk_clear_xmit_timers(struct sock *sk); void inet_csk_clear_xmit_timers(struct sock *sk);
static inline void inet_csk_schedule_ack(struct sock *sk) static inline void inet_csk_schedule_ack(struct sock *sk)
......
...@@ -125,10 +125,11 @@ static void dccp_retransmit_timer(struct sock *sk) ...@@ -125,10 +125,11 @@ static void dccp_retransmit_timer(struct sock *sk)
__sk_dst_reset(sk); __sk_dst_reset(sk);
} }
static void dccp_write_timer(unsigned long data) static void dccp_write_timer(struct timer_list *t)
{ {
struct sock *sk = (struct sock *)data; struct inet_connection_sock *icsk =
struct inet_connection_sock *icsk = inet_csk(sk); from_timer(icsk, t, icsk_retransmit_timer);
struct sock *sk = &icsk->icsk_inet.sk;
int event = 0; int event = 0;
bh_lock_sock(sk); bh_lock_sock(sk);
...@@ -161,19 +162,20 @@ static void dccp_write_timer(unsigned long data) ...@@ -161,19 +162,20 @@ static void dccp_write_timer(unsigned long data)
sock_put(sk); sock_put(sk);
} }
static void dccp_keepalive_timer(unsigned long data) static void dccp_keepalive_timer(struct timer_list *t)
{ {
struct sock *sk = (struct sock *)data; struct sock *sk = from_timer(sk, t, sk_timer);
pr_err("dccp should not use a keepalive timer !\n"); pr_err("dccp should not use a keepalive timer !\n");
sock_put(sk); sock_put(sk);
} }
/* This is the same as tcp_delack_timer, sans prequeue & mem_reclaim stuff */ /* This is the same as tcp_delack_timer, sans prequeue & mem_reclaim stuff */
static void dccp_delack_timer(unsigned long data) static void dccp_delack_timer(struct timer_list *t)
{ {
struct sock *sk = (struct sock *)data; struct inet_connection_sock *icsk =
struct inet_connection_sock *icsk = inet_csk(sk); from_timer(icsk, t, icsk_delack_timer);
struct sock *sk = &icsk->icsk_inet.sk;
bh_lock_sock(sk); bh_lock_sock(sk);
if (sock_owned_by_user(sk)) { if (sock_owned_by_user(sk)) {
......
...@@ -494,17 +494,15 @@ EXPORT_SYMBOL(inet_csk_accept); ...@@ -494,17 +494,15 @@ EXPORT_SYMBOL(inet_csk_accept);
* to optimize. * to optimize.
*/ */
void inet_csk_init_xmit_timers(struct sock *sk, void inet_csk_init_xmit_timers(struct sock *sk,
void (*retransmit_handler)(unsigned long), void (*retransmit_handler)(struct timer_list *t),
void (*delack_handler)(unsigned long), void (*delack_handler)(struct timer_list *t),
void (*keepalive_handler)(unsigned long)) void (*keepalive_handler)(struct timer_list *t))
{ {
struct inet_connection_sock *icsk = inet_csk(sk); struct inet_connection_sock *icsk = inet_csk(sk);
setup_timer(&icsk->icsk_retransmit_timer, retransmit_handler, timer_setup(&icsk->icsk_retransmit_timer, retransmit_handler, 0);
(unsigned long)sk); timer_setup(&icsk->icsk_delack_timer, delack_handler, 0);
setup_timer(&icsk->icsk_delack_timer, delack_handler, timer_setup(&sk->sk_timer, keepalive_handler, 0);
(unsigned long)sk);
setup_timer(&sk->sk_timer, keepalive_handler, (unsigned long)sk);
icsk->icsk_pending = icsk->icsk_ack.pending = 0; icsk->icsk_pending = icsk->icsk_ack.pending = 0;
} }
EXPORT_SYMBOL(inet_csk_init_xmit_timers); EXPORT_SYMBOL(inet_csk_init_xmit_timers);
...@@ -676,9 +674,9 @@ void inet_csk_reqsk_queue_drop_and_put(struct sock *sk, struct request_sock *req ...@@ -676,9 +674,9 @@ void inet_csk_reqsk_queue_drop_and_put(struct sock *sk, struct request_sock *req
} }
EXPORT_SYMBOL(inet_csk_reqsk_queue_drop_and_put); EXPORT_SYMBOL(inet_csk_reqsk_queue_drop_and_put);
static void reqsk_timer_handler(unsigned long data) static void reqsk_timer_handler(struct timer_list *t)
{ {
struct request_sock *req = (struct request_sock *)data; struct request_sock *req = from_timer(req, t, rsk_timer);
struct sock *sk_listener = req->rsk_listener; struct sock *sk_listener = req->rsk_listener;
struct net *net = sock_net(sk_listener); struct net *net = sock_net(sk_listener);
struct inet_connection_sock *icsk = inet_csk(sk_listener); struct inet_connection_sock *icsk = inet_csk(sk_listener);
...@@ -749,8 +747,7 @@ static void reqsk_queue_hash_req(struct request_sock *req, ...@@ -749,8 +747,7 @@ static void reqsk_queue_hash_req(struct request_sock *req,
req->num_timeout = 0; req->num_timeout = 0;
req->sk = NULL; req->sk = NULL;
setup_pinned_timer(&req->rsk_timer, reqsk_timer_handler, timer_setup(&req->rsk_timer, reqsk_timer_handler, TIMER_PINNED);
(unsigned long)req);
mod_timer(&req->rsk_timer, jiffies + timeout); mod_timer(&req->rsk_timer, jiffies + timeout);
inet_ehash_insert(req_to_sk(req), NULL); inet_ehash_insert(req_to_sk(req), NULL);
......
...@@ -288,15 +288,17 @@ void tcp_delack_timer_handler(struct sock *sk) ...@@ -288,15 +288,17 @@ void tcp_delack_timer_handler(struct sock *sk)
* *
* Returns: Nothing (void) * Returns: Nothing (void)
*/ */
static void tcp_delack_timer(unsigned long data) static void tcp_delack_timer(struct timer_list *t)
{ {
struct sock *sk = (struct sock *)data; struct inet_connection_sock *icsk =
from_timer(icsk, t, icsk_delack_timer);
struct sock *sk = &icsk->icsk_inet.sk;
bh_lock_sock(sk); bh_lock_sock(sk);
if (!sock_owned_by_user(sk)) { if (!sock_owned_by_user(sk)) {
tcp_delack_timer_handler(sk); tcp_delack_timer_handler(sk);
} else { } else {
inet_csk(sk)->icsk_ack.blocked = 1; icsk->icsk_ack.blocked = 1;
__NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKLOCKED); __NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKLOCKED);
/* deleguate our work to tcp_release_cb() */ /* deleguate our work to tcp_release_cb() */
if (!test_and_set_bit(TCP_DELACK_TIMER_DEFERRED, &sk->sk_tsq_flags)) if (!test_and_set_bit(TCP_DELACK_TIMER_DEFERRED, &sk->sk_tsq_flags))
...@@ -576,9 +578,11 @@ void tcp_write_timer_handler(struct sock *sk) ...@@ -576,9 +578,11 @@ void tcp_write_timer_handler(struct sock *sk)
sk_mem_reclaim(sk); sk_mem_reclaim(sk);
} }
static void tcp_write_timer(unsigned long data) static void tcp_write_timer(struct timer_list *t)
{ {
struct sock *sk = (struct sock *)data; struct inet_connection_sock *icsk =
from_timer(icsk, t, icsk_retransmit_timer);
struct sock *sk = &icsk->icsk_inet.sk;
bh_lock_sock(sk); bh_lock_sock(sk);
if (!sock_owned_by_user(sk)) { if (!sock_owned_by_user(sk)) {
...@@ -613,9 +617,9 @@ void tcp_set_keepalive(struct sock *sk, int val) ...@@ -613,9 +617,9 @@ void tcp_set_keepalive(struct sock *sk, int val)
EXPORT_SYMBOL_GPL(tcp_set_keepalive); EXPORT_SYMBOL_GPL(tcp_set_keepalive);
static void tcp_keepalive_timer (unsigned long data) static void tcp_keepalive_timer (struct timer_list *t)
{ {
struct sock *sk = (struct sock *) data; struct sock *sk = from_timer(sk, t, sk_timer);
struct inet_connection_sock *icsk = inet_csk(sk); struct inet_connection_sock *icsk = inet_csk(sk);
struct tcp_sock *tp = tcp_sk(sk); struct tcp_sock *tp = tcp_sk(sk);
u32 elapsed; u32 elapsed;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment