From 47d51c689d2e80f09b0815d0905e15e4d16ae0bb Mon Sep 17 00:00:00 2001 From: Guillaume Nault Date: Fri, 15 Mar 2013 21:47:53 +0100 Subject: l2tp: Centralise management of tunnel establishment timers Handle tunnel timeout timers in l2tp_tunnel_start() and l2tp_tunnel_connect(). This avoids timer code duplication across functions that are spectific to the tunnel establishment mode. Signed-off-by: Guillaume Nault --- accel-pppd/ctrl/l2tp/l2tp.c | 46 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) (limited to 'accel-pppd') diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index c16304b..00b2f0f 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -956,27 +956,35 @@ static int l2tp_tunnel_start(struct l2tp_conn_t *conn, if (triton_context_register(&conn->ctx, NULL) < 0) { log_error("l2tp: impossible to start new tunnel:" " context registration failed\n"); - return -1; + goto err; } triton_md_register_handler(&conn->ctx, &conn->hnd); if (triton_md_enable_handler(&conn->hnd, MD_MODE_READ) < 0) { log_error("l2tp: impossible to start new tunnel:" " enabling handler failed\n"); - goto out_err; + goto err_ctx; } triton_context_wakeup(&conn->ctx); + if (triton_timer_add(&conn->ctx, &conn->timeout_timer, 0) < 0) { + log_error("l2tp: impossible to start new tunnel:" + " setting tunnel establishment timer failed\n"); + goto err_ctx_md; + } if (triton_context_call(&conn->ctx, start_func, start_param) < 0) { log_error("l2tp: impossible to start new tunnel:" " call to tunnel context failed\n"); - goto out_err; + goto err_ctx_md_timer; } return 0; -out_err: +err_ctx_md_timer: + triton_timer_del(&conn->timeout_timer); +err_ctx_md: triton_md_unregister_handler(&conn->hnd); +err_ctx: triton_context_unregister(&conn->ctx); - +err: return -1; } @@ -1264,8 +1272,12 @@ static int l2tp_tunnel_connect(struct l2tp_conn_t *conn) log_tunnel(log_error, conn, "impossible to connect tunnel:" " setting HELLO timer failed\n"); + goto out_err; } + if (conn->timeout_timer.tpd) + triton_timer_del(&conn->timeout_timer); + return 0; out_err: @@ -1495,16 +1507,6 @@ static void l2tp_send_SCCRQ(void *peer_addr) goto err; } - if (!conn->timeout_timer.tpd) { - if (triton_timer_add(&conn->ctx, &conn->timeout_timer, 0) < 0) - log_tunnel(log_warn, conn, "SCCRQ: setting tunnel" - " establishment timer failed\n"); - } else { - if (triton_timer_mod(&conn->timeout_timer, 0) < 0) - log_tunnel(log_warn, conn, "SCCRQ: resetting tunnel" - " establishment timer failed\n"); - } - conn->state = STATE_WAIT_SCCRP; return; @@ -1574,16 +1576,6 @@ static void l2tp_send_SCCRP(struct l2tp_conn_t *conn) goto out; } - if (!conn->timeout_timer.tpd) { - if (triton_timer_add(&conn->ctx, &conn->timeout_timer, 0) < 0) - log_tunnel(log_warn, conn, "SCCRP: setting tunnel" - " establishment timer failed\n"); - } else { - if (triton_timer_mod(&conn->timeout_timer, 0) < 0) - log_tunnel(log_warn, conn, "SCCRP: resetting tunnel" - " establishment timer failed\n"); - } - conn->state = STATE_WAIT_SCCCN; return; @@ -2010,8 +2002,6 @@ static int l2tp_recv_SCCRP(struct l2tp_conn_t *conn, return -1; } - triton_timer_del(&conn->timeout_timer); - list_for_each_entry(attr, &pack->attrs, entry) { switch (attr->attr->id) { case Message_Type: @@ -2138,8 +2128,6 @@ static int l2tp_recv_SCCCN(struct l2tp_conn_t *conn, return 0; } - triton_timer_del(&conn->timeout_timer); - list_for_each_entry(attr, &pack->attrs, entry) { switch (attr->attr->id) { case Message_Type: -- cgit v1.2.3