diff options
author | Guillaume Nault <g.nault@alphalink.fr> | 2013-06-26 20:50:52 +0200 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2013-06-29 15:01:08 +0400 |
commit | 6bf07eec92361996df794552e7e4f2ea36886b33 (patch) | |
tree | 31f24d9222b59831a88a2db4e955462a0c5ea2e9 | |
parent | ca024045c6f8b1fd19c928db861c3437bdc705a6 (diff) | |
download | accel-ppp-6bf07eec92361996df794552e7e4f2ea36886b33.tar.gz accel-ppp-6bf07eec92361996df794552e7e4f2ea36886b33.zip |
l2tp: Close tunnel's PPPoL2TP socket
The PPPoL2TP socket created upon tunnel connection is never used
afterwards. It can be closed right after associating (connecting)
the tunnel with the underlying UDP socket (kernel won't cleanup a
tunnel as long as its UDP socket is open).
Signed-off-by: Vladislav Grishenko <themiron@mail.ru>
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
-rw-r--r-- | accel-pppd/ctrl/l2tp/l2tp.c | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index 146a03e..d81516e 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -97,8 +97,6 @@ struct l2tp_conn_t struct triton_timer_t rtimeout_timer; struct triton_timer_t hello_timer; - int tunnel_fd; - struct sockaddr_in peer_addr; struct sockaddr_in host_addr; uint16_t tid; @@ -706,9 +704,6 @@ static void l2tp_tunnel_free(struct l2tp_conn_t *conn) l2tp_conn[conn->tid] = NULL; pthread_mutex_unlock(&l2tp_lock); - if (conn->tunnel_fd != -1) - close(conn->tunnel_fd); - if (conn->ctx.tpd) triton_context_unregister(&conn->ctx); @@ -1123,8 +1118,6 @@ static struct l2tp_conn_t *l2tp_tunnel_alloc(const struct sockaddr_in *peer, conn->hello_timer.expire = l2tp_send_HELLO; conn->hello_timer.period = conf_hello_interval * 1000; - conn->tunnel_fd = -1; - conn->sessions = NULL; conn->sess_count = 0; conn->lns_mode = lns_mode; @@ -1269,6 +1262,7 @@ out_err: static int l2tp_tunnel_connect(struct l2tp_conn_t *conn) { struct sockaddr_pppol2tp pppox_addr; + int tunnel_fd; int flg; memset(&pppox_addr, 0, sizeof(pppox_addr)); @@ -1280,31 +1274,31 @@ static int l2tp_tunnel_connect(struct l2tp_conn_t *conn) pppox_addr.pppol2tp.s_tunnel = conn->tid; pppox_addr.pppol2tp.d_tunnel = conn->peer_tid; - conn->tunnel_fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP); - if (conn->tunnel_fd < 0) { + tunnel_fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP); + if (tunnel_fd < 0) { log_tunnel(log_error, conn, "impossible to connect tunnel:" " socket(AF_PPPOX) failed: %s\n", strerror(errno)); - goto out_err; + goto err; } - flg = fcntl(conn->tunnel_fd, F_GETFD); + flg = fcntl(tunnel_fd, F_GETFD); if (flg < 0) { log_tunnel(log_error, conn, "impossible to connect tunnel:" " fcntl(F_GETFD) failed: %s\n", strerror(errno)); - goto out_err; + goto err_fd; } - flg = fcntl(conn->tunnel_fd, F_SETFD, flg | FD_CLOEXEC); + flg = fcntl(tunnel_fd, F_SETFD, flg | FD_CLOEXEC); if (flg < 0) { log_tunnel(log_error, conn, "impossible to connect tunnel:" " fcntl(F_SETFD) failed: %s\n", strerror(errno)); - goto out_err; + goto err_fd; } - if (connect(conn->tunnel_fd, + if (connect(tunnel_fd, (struct sockaddr *)&pppox_addr, sizeof(pppox_addr)) < 0) { log_tunnel(log_error, conn, "impossible to connect tunnel:" " connect() failed: %s\n", strerror(errno)); - goto out_err; + goto err_fd; } if (conf_hello_interval) @@ -1312,19 +1306,19 @@ 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; + goto err_fd; } if (conn->timeout_timer.tpd) triton_timer_del(&conn->timeout_timer); + close(tunnel_fd); + return 0; -out_err: - if (conn->tunnel_fd >= 0) { - close(conn->tunnel_fd); - conn->tunnel_fd = -1; - } +err_fd: + close(tunnel_fd); +err: return -1; } |