diff options
author | Guillaume Nault <g.nault@alphalink.fr> | 2013-02-11 21:01:13 +0100 |
---|---|---|
committer | Kozlov Dmitry <xeb@mail.ru> | 2013-02-12 00:12:47 +0400 |
commit | b454e2fb411b2de072b68b6678876f84554bcabe (patch) | |
tree | de8e50c9edc199c5033b1a885f8b2dd9c54bd316 /accel-pppd/ctrl/l2tp | |
parent | 7c8c13572a5f7b6337edbb16a2f673a25f3de3f0 (diff) | |
download | accel-ppp-b454e2fb411b2de072b68b6678876f84554bcabe.tar.gz accel-ppp-b454e2fb411b2de072b68b6678876f84554bcabe.zip |
l2tp: Separate tunnel launching from initialisation
Register and start triton contexts/handlers in l2tp_tunnel_start()
instead of l2tp_tunnel_alloc(). The objective is to make
l2tp_tunnel_alloc() more generic by removing some specific
initialisation code. At a later stage, these would be done by the
caller between the calls to l2tp_tunnel_alloc() and l2tp_tunnel_start().
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Diffstat (limited to 'accel-pppd/ctrl/l2tp')
-rw-r--r-- | accel-pppd/ctrl/l2tp/l2tp.c | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index 32af83c2..ffa5131f 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -565,6 +565,28 @@ static void l2tp_conn_close(struct triton_context_t *ctx) l2tp_tunnel_free(conn); } +static int l2tp_tunnel_start(struct l2tp_conn_t *conn, + triton_event_func start_func, + void *start_param) +{ + if (triton_context_register(&conn->ctx, NULL) < 0) + return -1; + triton_md_register_handler(&conn->ctx, &conn->hnd); + if (triton_md_enable_handler(&conn->hnd, MD_MODE_READ) < 0) + goto out_err; + triton_context_wakeup(&conn->ctx); + if (triton_context_call(&conn->ctx, start_func, start_param) < 0) + goto out_err; + + return 0; + +out_err: + triton_md_unregister_handler(&conn->hnd); + triton_context_unregister(&conn->ctx); + + return -1; +} + static struct l2tp_conn_t *l2tp_tunnel_alloc(struct l2tp_serv_t *serv, struct l2tp_packet_t *pack, struct in_pktinfo *pkt_info, @@ -691,15 +713,6 @@ static struct l2tp_conn_t *l2tp_tunnel_alloc(struct l2tp_serv_t *serv, conn->tunnel_fd = -1; - if (triton_context_register(&conn->ctx, NULL) < 0) { - log_error("l2tp: tunnel allocation failed:" - " can't register context\n"); - goto out_err; - } - triton_md_register_handler(&conn->ctx, &conn->hnd); - triton_md_enable_handler(&conn->hnd, MD_MODE_READ); - triton_context_wakeup(&conn->ctx); - if (conf_verbose) { log_switch(&conn->ctx, NULL); log_ppp_info2("recv "); @@ -708,7 +721,6 @@ static struct l2tp_conn_t *l2tp_tunnel_alloc(struct l2tp_serv_t *serv, conn->sessions = NULL; conn->sess_count = 0; - triton_context_call(&conn->ctx, (triton_event_func)l2tp_send_SCCRP, conn); return conn; @@ -1076,7 +1088,8 @@ static int l2tp_recv_SCCRQ(struct l2tp_serv_t *serv, struct l2tp_packet_t *pack, struct l2tp_attr_t *framing_cap = NULL; struct l2tp_attr_t *router_id = NULL; struct l2tp_attr_t *challenge = NULL; - + struct l2tp_conn_t *conn = NULL; + if (ap_shutdown) return 0; @@ -1126,9 +1139,15 @@ static int l2tp_recv_SCCRQ(struct l2tp_serv_t *serv, struct l2tp_packet_t *pack, log_warn("l2tp: SCCRQ: no Framing-Capabilities present in message\n"); return -1; } - - if (l2tp_tunnel_alloc(serv, pack, pkt_info, assigned_tid, framing_cap, challenge) == NULL) + + conn = l2tp_tunnel_alloc(serv, pack, pkt_info, assigned_tid, + framing_cap, challenge); + if (conn == NULL) return -1; + if (l2tp_tunnel_start(conn, (triton_event_func)l2tp_send_SCCRP, conn) < 0) { + l2tp_tunnel_free(conn); + return -1; + } } else if (assigned_cid) { // not yet implemented |