summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Nault <g.nault@alphalink.fr>2012-09-07 12:33:24 +0200
committerKozlov Dmitry <xeb@mail.ru>2012-09-07 14:46:53 +0400
commitbe64442c49373c947bbdc9a33ead113aa2867202 (patch)
tree006f2b23669f122e8a04d64a58f1b715f63b0773
parent5fcc486dffec346224db935c9e9431777ab939df (diff)
downloadaccel-ppp-be64442c49373c947bbdc9a33ead113aa2867202.tar.gz
accel-ppp-be64442c49373c947bbdc9a33ead113aa2867202.zip
L2TP: Define and use dedicated function to free sessions
Move session specific operations out of l2tp_disconnect(). Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
-rw-r--r--accel-pppd/ctrl/l2tp/l2tp.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c
index 12e8f8a4..e4570b29 100644
--- a/accel-pppd/ctrl/l2tp/l2tp.c
+++ b/accel-pppd/ctrl/l2tp/l2tp.c
@@ -119,10 +119,35 @@ static void l2tp_send_SCCRP(struct l2tp_conn_t *conn);
static int l2tp_send(struct l2tp_conn_t *conn, struct l2tp_packet_t *pack, int log_debug);
static int l2tp_conn_read(struct triton_md_handler_t *);
+static void l2tp_session_free(struct l2tp_conn_t *conn)
+{
+ if (conn->state == STATE_PPP) {
+ __sync_sub_and_fetch(&stat_active, 1);
+ conn->state = STATE_FIN;
+ ap_session_terminate(&conn->sess.ppp.ses,
+ TERM_USER_REQUEST, 1);
+ } else if (conn->state != STATE_FIN)
+ __sync_sub_and_fetch(&stat_starting, 1);
+
+ if (conn->sess.ppp.fd != -1)
+ close(conn->sess.ppp.fd);
+
+ triton_event_fire(EV_CTRL_FINISHED, &conn->sess.ppp.ses);
+
+ log_ppp_info1("disconnected\n");
+
+ if (conn->sess.ppp.ses.chan_name)
+ _free(conn->sess.ppp.ses.chan_name);
+ _free(conn->sess.ctrl.calling_station_id);
+ _free(conn->sess.ctrl.called_station_id);
+}
+
static void l2tp_disconnect(struct l2tp_conn_t *conn)
{
struct l2tp_packet_t *pack;
+ l2tp_session_free(conn);
+
triton_md_unregister_handler(&conn->hnd);
close(conn->hnd.fd);
@@ -135,28 +160,13 @@ static void l2tp_disconnect(struct l2tp_conn_t *conn)
if (conn->hello_timer.tpd)
triton_timer_del(&conn->hello_timer);
- if (conn->state == STATE_PPP) {
- __sync_sub_and_fetch(&stat_active, 1);
- conn->state = STATE_FIN;
- ap_session_terminate(&conn->sess.ppp.ses,
- TERM_USER_REQUEST, 1);
- } else if (conn->state != STATE_FIN)
- __sync_sub_and_fetch(&stat_starting, 1);
-
pthread_mutex_lock(&l2tp_lock);
l2tp_conn[conn->tid] = NULL;
pthread_mutex_unlock(&l2tp_lock);
- if (conn->sess.ppp.fd != -1)
- close(conn->sess.ppp.fd);
-
if (conn->tunnel_fd != -1)
close(conn->tunnel_fd);
- triton_event_fire(EV_CTRL_FINISHED, &conn->sess.ppp.ses);
-
- log_ppp_info1("disconnected\n");
-
triton_context_unregister(&conn->ctx);
while (!list_empty(&conn->send_queue)) {
@@ -165,12 +175,8 @@ static void l2tp_disconnect(struct l2tp_conn_t *conn)
l2tp_packet_free(pack);
}
- if (conn->sess.ppp.ses.chan_name)
- _free(conn->sess.ppp.ses.chan_name);
if (conn->challenge_len)
_free(conn->challenge.octets);
- _free(conn->sess.ctrl.calling_station_id);
- _free(conn->sess.ctrl.called_station_id);
mempool_free(conn);
}