summaryrefslogtreecommitdiff
path: root/accel-pppd
diff options
context:
space:
mode:
Diffstat (limited to 'accel-pppd')
-rw-r--r--accel-pppd/ctrl/l2tp/l2tp.c38
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;
}