summaryrefslogtreecommitdiff
path: root/accel-pptpd/ctrl
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-10-14 11:28:17 +0400
committerKozlov Dmitry <dima@server>2010-10-14 11:28:17 +0400
commit763fe9e3ba0faeea25cc423152a065900f901a53 (patch)
treed3772cac139507699746461afc16a26e20065f21 /accel-pptpd/ctrl
parent80e8ec99aeffcec505165f099f68d0fb2903e12b (diff)
downloadaccel-ppp-763fe9e3ba0faeea25cc423152a065900f901a53.tar.gz
accel-ppp-763fe9e3ba0faeea25cc423152a065900f901a53.zip
various bug fixed and improvements
Diffstat (limited to 'accel-pptpd/ctrl')
-rw-r--r--accel-pptpd/ctrl/l2tp/l2tp.c10
-rw-r--r--accel-pptpd/ctrl/l2tp/netlink.c40
-rw-r--r--accel-pptpd/ctrl/l2tp/packet.c7
3 files changed, 40 insertions, 17 deletions
diff --git a/accel-pptpd/ctrl/l2tp/l2tp.c b/accel-pptpd/ctrl/l2tp/l2tp.c
index 2996127..2a7687e 100644
--- a/accel-pptpd/ctrl/l2tp/l2tp.c
+++ b/accel-pptpd/ctrl/l2tp/l2tp.c
@@ -137,7 +137,7 @@ static void l2tp_disconnect(struct l2tp_conn_t *conn)
_free(conn->ctrl.calling_station_id);
_free(conn->ctrl.called_station_id);
-
+
mempool_free(conn);
}
@@ -333,6 +333,7 @@ static int l2tp_connect(struct l2tp_conn_t *conn)
pppox_addr.pppol2tp.d_tunnel = conn->peer_tid;
pppox_addr.pppol2tp.d_session = conn->peer_sid;
+ l2tp_nl_delete_tunnel(conn->tid);
l2tp_nl_create_tunnel(conn->hnd.fd, conn->tid, conn->peer_tid);
l2tp_nl_create_session(conn->tid, conn->sid, conn->peer_sid);
@@ -420,7 +421,8 @@ static int l2tp_send(struct l2tp_conn_t *conn, struct l2tp_packet_t *pack)
list_add_tail(&pack->entry, &conn->send_queue);
if (!conn->rtimeout_timer.tpd)
triton_timer_add(&conn->ctx, &conn->rtimeout_timer, 0);
- }
+ } else
+ l2tp_packet_free(pack);
return 0;
@@ -792,8 +794,6 @@ static int l2tp_conn_read(struct triton_md_handler_t *h)
struct l2tp_attr_t *msg_type;
while (1) {
- pack = NULL;
-
if (l2tp_recv(h->fd, &pack))
return 0;
@@ -923,8 +923,6 @@ static int l2tp_udp_read(struct triton_md_handler_t *h)
struct l2tp_attr_t *msg_type;
while (1) {
- pack = NULL;
-
if (l2tp_recv(h->fd, &pack))
break;
diff --git a/accel-pptpd/ctrl/l2tp/netlink.c b/accel-pptpd/ctrl/l2tp/netlink.c
index a50e9b2..0cc5b34 100644
--- a/accel-pptpd/ctrl/l2tp/netlink.c
+++ b/accel-pptpd/ctrl/l2tp/netlink.c
@@ -5,13 +5,18 @@
#include "l2tp_kernel.h"
#include "triton.h"
-static struct nl_handle *nl_sock;
static int family;
void l2tp_nl_delete_tunnel(int tid)
{
- struct nl_msg *msg = nlmsg_alloc();
+ struct nl_handle *nl_sock;
+ struct nl_msg *msg;
+ nl_sock = nl_handle_alloc();
+ msg = nlmsg_alloc();
+
+ genl_connect(nl_sock);
+
genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, NLM_F_REQUEST, L2TP_CMD_TUNNEL_DELETE, L2TP_GENL_VERSION);
nla_put_u32(msg, L2TP_ATTR_CONN_ID, tid);
@@ -19,15 +24,20 @@ void l2tp_nl_delete_tunnel(int tid)
nl_recvmsgs_default(nl_sock);
nlmsg_free(msg);
-
+ nl_close(nl_sock);
+ nl_handle_destroy(nl_sock);
}
void l2tp_nl_create_tunnel(int fd, int tid, int peer_tid)
{
- struct nl_msg *msg = nlmsg_alloc();
-
- l2tp_nl_delete_tunnel(tid);
+ struct nl_handle *nl_sock;
+ struct nl_msg *msg;
+
+ nl_sock = nl_handle_alloc();
+ msg = nlmsg_alloc();
+ genl_connect(nl_sock);
+
genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, NLM_F_REQUEST, L2TP_CMD_TUNNEL_CREATE, L2TP_GENL_VERSION);
nla_put_u16(msg, L2TP_ATTR_ENCAP_TYPE, L2TP_ENCAPTYPE_UDP);
nla_put_u8(msg, L2TP_ATTR_PROTO_VERSION, 2);
@@ -40,12 +50,20 @@ void l2tp_nl_create_tunnel(int fd, int tid, int peer_tid)
nl_recvmsgs_default(nl_sock);
nlmsg_free(msg);
+ nl_close(nl_sock);
+ nl_handle_destroy(nl_sock);
}
void l2tp_nl_create_session(int tid, int sid, int peer_sid)
{
- struct nl_msg *msg = nlmsg_alloc();
+ struct nl_handle *nl_sock;
+ struct nl_msg *msg;
+
+ nl_sock = nl_handle_alloc();
+ msg = nlmsg_alloc();
+ genl_connect(nl_sock);
+
genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, NLM_F_REQUEST, L2TP_CMD_SESSION_CREATE, L2TP_GENL_VERSION);
nla_put_u32(msg, L2TP_ATTR_CONN_ID, tid);
nla_put_u32(msg, L2TP_ATTR_SESSION_ID, sid);
@@ -58,13 +76,19 @@ void l2tp_nl_create_session(int tid, int sid, int peer_sid)
nl_recvmsgs_default(nl_sock);
nlmsg_free(msg);
+ nl_close(nl_sock);
+ nl_handle_destroy(nl_sock);
}
static void __init init(void)
{
- nl_sock = nl_handle_alloc();
+ struct nl_handle *nl_sock = nl_handle_alloc();
genl_connect(nl_sock);
family = genl_ctrl_resolve(nl_sock, L2TP_GENL_NAME);
+
+ nl_close(nl_sock);
+ nl_handle_destroy(nl_sock);
}
+
diff --git a/accel-pptpd/ctrl/l2tp/packet.c b/accel-pptpd/ctrl/l2tp/packet.c
index c127619..2f1b60f 100644
--- a/accel-pptpd/ctrl/l2tp/packet.c
+++ b/accel-pptpd/ctrl/l2tp/packet.c
@@ -107,6 +107,8 @@ int l2tp_recv(int fd, struct l2tp_packet_t **p)
struct sockaddr_in addr;
socklen_t len = sizeof(addr);
+ *p = NULL;
+
if (!buf) {
log_emerg("l2tp: out of memory\n");
return 0;
@@ -115,10 +117,9 @@ int l2tp_recv(int fd, struct l2tp_packet_t **p)
n = recvfrom(fd, buf, L2TP_MAX_PACKET_SIZE, 0, &addr, &len);
if (n < 0) {
- if (errno == EAGAIN) {
- mempool_free(buf);
+ mempool_free(buf);
+ if (errno == EAGAIN)
return -1;
- }
log_error("l2tp: recv: %s\n", strerror(errno));
return 0;
}