Commit 9c3b5751 authored by Kees Cook's avatar Kees Cook Committed by David S. Miller

net: sctp: 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: Vlad Yasevich <vyasevich@gmail.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: linux-sctp@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a4cdd9ff
...@@ -72,7 +72,7 @@ typedef enum sctp_disposition (sctp_state_fn_t) ( ...@@ -72,7 +72,7 @@ typedef enum sctp_disposition (sctp_state_fn_t) (
const union sctp_subtype type, const union sctp_subtype type,
void *arg, void *arg,
struct sctp_cmd_seq *commands); struct sctp_cmd_seq *commands);
typedef void (sctp_timer_event_t) (unsigned long); typedef void (sctp_timer_event_t) (struct timer_list *);
struct sctp_sm_table_entry { struct sctp_sm_table_entry {
sctp_state_fn_t *fn; sctp_state_fn_t *fn;
const char *name; const char *name;
...@@ -314,10 +314,10 @@ int sctp_do_sm(struct net *net, enum sctp_event event_type, ...@@ -314,10 +314,10 @@ int sctp_do_sm(struct net *net, enum sctp_event event_type,
void *event_arg, gfp_t gfp); void *event_arg, gfp_t gfp);
/* 2nd level prototypes */ /* 2nd level prototypes */
void sctp_generate_t3_rtx_event(unsigned long peer); void sctp_generate_t3_rtx_event(struct timer_list *t);
void sctp_generate_heartbeat_event(unsigned long peer); void sctp_generate_heartbeat_event(struct timer_list *t);
void sctp_generate_reconf_event(unsigned long peer); void sctp_generate_reconf_event(struct timer_list *t);
void sctp_generate_proto_unreach_event(unsigned long peer); void sctp_generate_proto_unreach_event(struct timer_list *t);
void sctp_ootb_pkt_free(struct sctp_packet *packet); void sctp_ootb_pkt_free(struct sctp_packet *packet);
......
...@@ -149,8 +149,7 @@ static struct sctp_association *sctp_association_init( ...@@ -149,8 +149,7 @@ static struct sctp_association *sctp_association_init(
/* Initializes the timers */ /* Initializes the timers */
for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i) for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i)
setup_timer(&asoc->timers[i], sctp_timer_events[i], timer_setup(&asoc->timers[i], sctp_timer_events[i], 0);
(unsigned long)asoc);
/* Pull default initialization values from the sock options. /* Pull default initialization values from the sock options.
* Note: This assumes that the values have already been * Note: This assumes that the values have already been
......
...@@ -622,9 +622,9 @@ static void sctp_v4_ecn_capable(struct sock *sk) ...@@ -622,9 +622,9 @@ static void sctp_v4_ecn_capable(struct sock *sk)
INET_ECN_xmit(sk); INET_ECN_xmit(sk);
} }
static void sctp_addr_wq_timeout_handler(unsigned long arg) static void sctp_addr_wq_timeout_handler(struct timer_list *t)
{ {
struct net *net = (struct net *)arg; struct net *net = from_timer(net, t, sctp.addr_wq_timer);
struct sctp_sockaddr_entry *addrw, *temp; struct sctp_sockaddr_entry *addrw, *temp;
struct sctp_sock *sp; struct sctp_sock *sp;
...@@ -1304,8 +1304,7 @@ static int __net_init sctp_defaults_init(struct net *net) ...@@ -1304,8 +1304,7 @@ static int __net_init sctp_defaults_init(struct net *net)
INIT_LIST_HEAD(&net->sctp.auto_asconf_splist); INIT_LIST_HEAD(&net->sctp.auto_asconf_splist);
spin_lock_init(&net->sctp.addr_wq_lock); spin_lock_init(&net->sctp.addr_wq_lock);
net->sctp.addr_wq_timer.expires = 0; net->sctp.addr_wq_timer.expires = 0;
setup_timer(&net->sctp.addr_wq_timer, sctp_addr_wq_timeout_handler, timer_setup(&net->sctp.addr_wq_timer, sctp_addr_wq_timeout_handler, 0);
(unsigned long)net);
return 0; return 0;
......
...@@ -243,9 +243,10 @@ static int sctp_gen_sack(struct sctp_association *asoc, int force, ...@@ -243,9 +243,10 @@ static int sctp_gen_sack(struct sctp_association *asoc, int force,
/* When the T3-RTX timer expires, it calls this function to create the /* When the T3-RTX timer expires, it calls this function to create the
* relevant state machine event. * relevant state machine event.
*/ */
void sctp_generate_t3_rtx_event(unsigned long peer) void sctp_generate_t3_rtx_event(struct timer_list *t)
{ {
struct sctp_transport *transport = (struct sctp_transport *) peer; struct sctp_transport *transport =
from_timer(transport, t, T3_rtx_timer);
struct sctp_association *asoc = transport->asoc; struct sctp_association *asoc = transport->asoc;
struct sock *sk = asoc->base.sk; struct sock *sk = asoc->base.sk;
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
...@@ -319,50 +320,63 @@ static void sctp_generate_timeout_event(struct sctp_association *asoc, ...@@ -319,50 +320,63 @@ static void sctp_generate_timeout_event(struct sctp_association *asoc,
sctp_association_put(asoc); sctp_association_put(asoc);
} }
static void sctp_generate_t1_cookie_event(unsigned long data) static void sctp_generate_t1_cookie_event(struct timer_list *t)
{ {
struct sctp_association *asoc = (struct sctp_association *) data; struct sctp_association *asoc =
from_timer(asoc, t, timers[SCTP_EVENT_TIMEOUT_T1_COOKIE]);
sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T1_COOKIE); sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T1_COOKIE);
} }
static void sctp_generate_t1_init_event(unsigned long data) static void sctp_generate_t1_init_event(struct timer_list *t)
{ {
struct sctp_association *asoc = (struct sctp_association *) data; struct sctp_association *asoc =
from_timer(asoc, t, timers[SCTP_EVENT_TIMEOUT_T1_INIT]);
sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T1_INIT); sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T1_INIT);
} }
static void sctp_generate_t2_shutdown_event(unsigned long data) static void sctp_generate_t2_shutdown_event(struct timer_list *t)
{ {
struct sctp_association *asoc = (struct sctp_association *) data; struct sctp_association *asoc =
from_timer(asoc, t, timers[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN]);
sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T2_SHUTDOWN); sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T2_SHUTDOWN);
} }
static void sctp_generate_t4_rto_event(unsigned long data) static void sctp_generate_t4_rto_event(struct timer_list *t)
{ {
struct sctp_association *asoc = (struct sctp_association *) data; struct sctp_association *asoc =
from_timer(asoc, t, timers[SCTP_EVENT_TIMEOUT_T4_RTO]);
sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T4_RTO); sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T4_RTO);
} }
static void sctp_generate_t5_shutdown_guard_event(unsigned long data) static void sctp_generate_t5_shutdown_guard_event(struct timer_list *t)
{ {
struct sctp_association *asoc = (struct sctp_association *)data; struct sctp_association *asoc =
from_timer(asoc, t,
timers[SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD]);
sctp_generate_timeout_event(asoc, sctp_generate_timeout_event(asoc,
SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD); SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD);
} /* sctp_generate_t5_shutdown_guard_event() */ } /* sctp_generate_t5_shutdown_guard_event() */
static void sctp_generate_autoclose_event(unsigned long data) static void sctp_generate_autoclose_event(struct timer_list *t)
{ {
struct sctp_association *asoc = (struct sctp_association *) data; struct sctp_association *asoc =
from_timer(asoc, t, timers[SCTP_EVENT_TIMEOUT_AUTOCLOSE]);
sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_AUTOCLOSE); sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_AUTOCLOSE);
} }
/* Generate a heart beat event. If the sock is busy, reschedule. Make /* Generate a heart beat event. If the sock is busy, reschedule. Make
* sure that the transport is still valid. * sure that the transport is still valid.
*/ */
void sctp_generate_heartbeat_event(unsigned long data) void sctp_generate_heartbeat_event(struct timer_list *t)
{ {
struct sctp_transport *transport = (struct sctp_transport *) data; struct sctp_transport *transport = from_timer(transport, t, hb_timer);
struct sctp_association *asoc = transport->asoc; struct sctp_association *asoc = transport->asoc;
struct sock *sk = asoc->base.sk; struct sock *sk = asoc->base.sk;
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
...@@ -405,9 +419,10 @@ void sctp_generate_heartbeat_event(unsigned long data) ...@@ -405,9 +419,10 @@ void sctp_generate_heartbeat_event(unsigned long data)
/* Handle the timeout of the ICMP protocol unreachable timer. Trigger /* Handle the timeout of the ICMP protocol unreachable timer. Trigger
* the correct state machine transition that will close the association. * the correct state machine transition that will close the association.
*/ */
void sctp_generate_proto_unreach_event(unsigned long data) void sctp_generate_proto_unreach_event(struct timer_list *t)
{ {
struct sctp_transport *transport = (struct sctp_transport *)data; struct sctp_transport *transport =
from_timer(transport, t, proto_unreach_timer);
struct sctp_association *asoc = transport->asoc; struct sctp_association *asoc = transport->asoc;
struct sock *sk = asoc->base.sk; struct sock *sk = asoc->base.sk;
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
...@@ -439,9 +454,10 @@ void sctp_generate_proto_unreach_event(unsigned long data) ...@@ -439,9 +454,10 @@ void sctp_generate_proto_unreach_event(unsigned long data)
} }
/* Handle the timeout of the RE-CONFIG timer. */ /* Handle the timeout of the RE-CONFIG timer. */
void sctp_generate_reconf_event(unsigned long data) void sctp_generate_reconf_event(struct timer_list *t)
{ {
struct sctp_transport *transport = (struct sctp_transport *)data; struct sctp_transport *transport =
from_timer(transport, t, reconf_timer);
struct sctp_association *asoc = transport->asoc; struct sctp_association *asoc = transport->asoc;
struct sock *sk = asoc->base.sk; struct sock *sk = asoc->base.sk;
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
...@@ -471,24 +487,27 @@ void sctp_generate_reconf_event(unsigned long data) ...@@ -471,24 +487,27 @@ void sctp_generate_reconf_event(unsigned long data)
} }
/* Inject a SACK Timeout event into the state machine. */ /* Inject a SACK Timeout event into the state machine. */
static void sctp_generate_sack_event(unsigned long data) static void sctp_generate_sack_event(struct timer_list *t)
{ {
struct sctp_association *asoc = (struct sctp_association *)data; struct sctp_association *asoc =
from_timer(asoc, t, timers[SCTP_EVENT_TIMEOUT_SACK]);
sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK); sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
} }
sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = { sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
NULL, [SCTP_EVENT_TIMEOUT_NONE] = NULL,
sctp_generate_t1_cookie_event, [SCTP_EVENT_TIMEOUT_T1_COOKIE] = sctp_generate_t1_cookie_event,
sctp_generate_t1_init_event, [SCTP_EVENT_TIMEOUT_T1_INIT] = sctp_generate_t1_init_event,
sctp_generate_t2_shutdown_event, [SCTP_EVENT_TIMEOUT_T2_SHUTDOWN] = sctp_generate_t2_shutdown_event,
NULL, [SCTP_EVENT_TIMEOUT_T3_RTX] = NULL,
sctp_generate_t4_rto_event, [SCTP_EVENT_TIMEOUT_T4_RTO] = sctp_generate_t4_rto_event,
sctp_generate_t5_shutdown_guard_event, [SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD] =
NULL, sctp_generate_t5_shutdown_guard_event,
NULL, [SCTP_EVENT_TIMEOUT_HEARTBEAT] = NULL,
sctp_generate_sack_event, [SCTP_EVENT_TIMEOUT_RECONF] = NULL,
sctp_generate_autoclose_event, [SCTP_EVENT_TIMEOUT_SACK] = sctp_generate_sack_event,
[SCTP_EVENT_TIMEOUT_AUTOCLOSE] = sctp_generate_autoclose_event,
}; };
......
...@@ -87,14 +87,11 @@ static struct sctp_transport *sctp_transport_init(struct net *net, ...@@ -87,14 +87,11 @@ static struct sctp_transport *sctp_transport_init(struct net *net,
INIT_LIST_HEAD(&peer->send_ready); INIT_LIST_HEAD(&peer->send_ready);
INIT_LIST_HEAD(&peer->transports); INIT_LIST_HEAD(&peer->transports);
setup_timer(&peer->T3_rtx_timer, sctp_generate_t3_rtx_event, timer_setup(&peer->T3_rtx_timer, sctp_generate_t3_rtx_event, 0);
(unsigned long)peer); timer_setup(&peer->hb_timer, sctp_generate_heartbeat_event, 0);
setup_timer(&peer->hb_timer, sctp_generate_heartbeat_event, timer_setup(&peer->reconf_timer, sctp_generate_reconf_event, 0);
(unsigned long)peer); timer_setup(&peer->proto_unreach_timer,
setup_timer(&peer->reconf_timer, sctp_generate_reconf_event, sctp_generate_proto_unreach_event, 0);
(unsigned long)peer);
setup_timer(&peer->proto_unreach_timer,
sctp_generate_proto_unreach_event, (unsigned long)peer);
/* Initialize the 64-bit random nonce sent with heartbeat. */ /* Initialize the 64-bit random nonce sent with heartbeat. */
get_random_bytes(&peer->hb_nonce, sizeof(peer->hb_nonce)); get_random_bytes(&peer->hb_nonce, sizeof(peer->hb_nonce));
......
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