summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--accel-pptpd/CMakeLists.txt5
-rw-r--r--accel-pptpd/accel-pptpd.conf9
-rw-r--r--accel-pptpd/auth/auth_chap_md5.c30
-rw-r--r--accel-pptpd/auth/auth_mschap_v1.c30
-rw-r--r--accel-pptpd/auth/auth_mschap_v2.c32
-rw-r--r--accel-pptpd/auth/auth_pap.c16
-rw-r--r--accel-pptpd/ctrl/pptp.c70
-rw-r--r--accel-pptpd/include/events.h3
l---------accel-pptpd/include/spinlock.h1
-rw-r--r--accel-pptpd/log.c436
-rw-r--r--accel-pptpd/log.h77
-rw-r--r--accel-pptpd/logs/CMakeLists.txt2
-rw-r--r--accel-pptpd/logs/log_file.c435
-rw-r--r--accel-pptpd/ppp/ipcp_opt_ipaddr.c17
-rw-r--r--accel-pptpd/ppp/lcp_opt_magic.c2
-rw-r--r--accel-pptpd/ppp/lcp_opt_mru.c7
-rw-r--r--accel-pptpd/ppp/ppp.c58
-rw-r--r--accel-pptpd/ppp/ppp.h3
-rw-r--r--accel-pptpd/ppp/ppp_auth.c24
-rw-r--r--accel-pptpd/ppp/ppp_ccp.c97
-rw-r--r--accel-pptpd/ppp/ppp_fsm.c12
-rw-r--r--accel-pptpd/ppp/ppp_ipcp.c95
-rw-r--r--accel-pptpd/ppp/ppp_lcp.c106
-rw-r--r--accel-pptpd/radius/acct.c22
-rw-r--r--accel-pptpd/radius/auth.c4
-rw-r--r--accel-pptpd/radius/dict.c8
-rw-r--r--accel-pptpd/radius/dm_coa.c20
-rw-r--r--accel-pptpd/radius/packet.c40
-rw-r--r--accel-pptpd/radius/radius.c8
-rw-r--r--accel-pptpd/radius/req.c22
-rw-r--r--accel-pptpd/triton/CMakeLists.txt1
-rw-r--r--accel-pptpd/triton/mempool.c8
-rw-r--r--accel-pptpd/triton/mempool.h10
-rw-r--r--accel-pptpd/triton/spinlock.h2
-rw-r--r--accel-pptpd/triton/timer.c1
-rw-r--r--accel-pptpd/triton/triton.c10
-rw-r--r--accel-pptpd/triton/triton.h3
-rw-r--r--accel-pptpd/triton/triton_p.h7
38 files changed, 1277 insertions, 456 deletions
diff --git a/accel-pptpd/CMakeLists.txt b/accel-pptpd/CMakeLists.txt
index 9753e11b..1621e35a 100644
--- a/accel-pptpd/CMakeLists.txt
+++ b/accel-pptpd/CMakeLists.txt
@@ -1,7 +1,7 @@
PROJECT (pptpd)
cmake_minimum_required(VERSION 2.6)
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fvisibility=hidden -D_GNU_SOURCE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fvisibility=hidden -D_GNU_SOURCE -DSPINLOCK_GCC")
INCLUDE_DIRECTORIES(include)
@@ -9,6 +9,7 @@ ADD_SUBDIRECTORY(triton)
ADD_SUBDIRECTORY(ctrl)
ADD_SUBDIRECTORY(auth)
ADD_SUBDIRECTORY(radius)
+ADD_SUBDIRECTORY(logs)
ADD_EXECUTABLE(pptpd
ppp/ppp.c
@@ -24,13 +25,13 @@ ADD_EXECUTABLE(pptpd
ppp/ipcp_opt_dns.c
ppp/ppp_ccp.c
- log.c
pwdb.c
ipdb.c
iprange.c
ippool.c
+ log.c
main.c
)
TARGET_LINK_LIBRARIES(pptpd triton rt pthread ssl)
diff --git a/accel-pptpd/accel-pptpd.conf b/accel-pptpd/accel-pptpd.conf
index 206c9d2d..ff338c90 100644
--- a/accel-pptpd/accel-pptpd.conf
+++ b/accel-pptpd/accel-pptpd.conf
@@ -3,6 +3,7 @@
./libauth_pap.so
./libauth_chap_md5.so
./libradius.so
+./liblog_file.so
[core]
log-error=/dev/stderr
@@ -34,3 +35,11 @@ verbose=1
#gw-ip-address=192.168.100.10
gw=192.168.100.210-211
tunnel=192.168.100.200-201
+
+[log]
+log-file=/dev/stdout
+log-emerg=/dev/stderr
+#color=1
+per-user-dir=per_user
+per-session-dir=per_session
+per-session=1
diff --git a/accel-pptpd/auth/auth_chap_md5.c b/accel-pptpd/auth/auth_chap_md5.c
index 1abf63b8..058dc677 100644
--- a/accel-pptpd/auth/auth_chap_md5.c
+++ b/accel-pptpd/auth/auth_chap_md5.c
@@ -76,13 +76,13 @@ static void print_buf(const uint8_t *buf,int size)
{
int i;
for(i=0;i<size;i++)
- log_debug("%x ",buf[i]);
+ log_ppp_debug("%x",buf[i]);
}
static void print_str(const char *buf,int size)
{
int i;
for(i=0;i<size;i++)
- log_debug("%c",buf[i]);
+ log_ppp_debug("%c",buf[i]);
}
@@ -152,7 +152,7 @@ static void chap_send_failure(struct chap_auth_data_t *ad)
.message=MSG_FAILURE,
};
- log_debug("send [CHAP Failure id=%x \"%s\"]\n",msg.hdr.id,MSG_FAILURE);
+ log_ppp_debug("send [CHAP Failure id=%x \"%s\"]\n",msg.hdr.id,MSG_FAILURE);
ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2);
}
@@ -168,7 +168,7 @@ static void chap_send_success(struct chap_auth_data_t *ad)
.message=MSG_SUCCESS,
};
- log_debug("send [CHAP Success id=%x \"%s\"]\n",msg.hdr.id,MSG_SUCCESS);
+ log_ppp_debug("send [CHAP Success id=%x \"%s\"]\n",msg.hdr.id,MSG_SUCCESS);
ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2);
}
@@ -187,9 +187,9 @@ static void chap_send_challenge(struct chap_auth_data_t *ad)
read(urandom_fd,ad->val,VALUE_SIZE);
memcpy(msg.val,ad->val,VALUE_SIZE);
- log_debug("send [CHAP Challenge id=%x <",msg.hdr.id);
+ log_ppp_debug("send [CHAP Challenge id=%x <",msg.hdr.id);
print_buf(msg.val,VALUE_SIZE);
- log_debug(">]\n");
+ log_ppp_debug(">]\n");
ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2);
}
@@ -203,22 +203,22 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h
int r;
struct chap_challenge_t *msg=(struct chap_challenge_t*)hdr;
- log_debug("recv [CHAP Response id=%x <", msg->hdr.id);
+ log_ppp_debug("recv [CHAP Response id=%x <", msg->hdr.id);
print_buf(msg->val,msg->val_size);
- log_debug(">, name=\"");
+ log_ppp_debug(">, name=\"");
print_str(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2);
- log_debug("\"]\n");
+ log_ppp_debug("\"]\n");
if (msg->hdr.id!=ad->id)
{
- log_error("chap-md5: id mismatch\n");
+ log_ppp_error("chap-md5: id mismatch\n");
chap_send_failure(ad);
ppp_terminate(ad->ppp, 0);
}
if (msg->val_size!=VALUE_SIZE)
{
- log_error("chap-md5: value-size should be %i, expected %i\n",VALUE_SIZE,msg->val_size);
+ log_ppp_error("chap-md5: value-size should be %i, expected %i\n",VALUE_SIZE,msg->val_size);
chap_send_failure(ad);
ppp_terminate(ad->ppp, 0);
}
@@ -232,7 +232,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h
if (!passwd)
{
free(name);
- log_debug("chap-md5: user not found\n");
+ log_ppp_debug("chap-md5: user not found\n");
chap_send_failure(ad);
return;
}
@@ -245,7 +245,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h
if (memcmp(md5,msg->val,sizeof(md5)))
{
- log_debug("chap-md5: challenge response mismatch\n");
+ log_ppp_debug("chap-md5: challenge response mismatch\n");
chap_send_failure(ad);
auth_failed(ad->ppp);
}else
@@ -282,14 +282,14 @@ static void chap_recv(struct ppp_handler_t *h)
if (d->ppp->chan_buf_size<sizeof(*hdr) || ntohs(hdr->len)<HDR_LEN || ntohs(hdr->len)<d->ppp->chan_buf_size-2)
{
- log_warn("CHAP: short packet received\n");
+ log_ppp_warn("CHAP: short packet received\n");
return;
}
if (hdr->code==CHAP_RESPONSE) chap_recv_response(d,hdr);
else
{
- log_warn("CHAP: unknown code received %x\n",hdr->code);
+ log_ppp_warn("CHAP: unknown code received %x\n",hdr->code);
}
}
diff --git a/accel-pptpd/auth/auth_mschap_v1.c b/accel-pptpd/auth/auth_mschap_v1.c
index 4a7341bd..3a75d674 100644
--- a/accel-pptpd/auth/auth_mschap_v1.c
+++ b/accel-pptpd/auth/auth_mschap_v1.c
@@ -88,13 +88,13 @@ static void print_buf(const uint8_t *buf,int size)
{
int i;
for(i=0;i<size;i++)
- log_debug("%x",buf[i]);
+ log_ppp_debug("%x",buf[i]);
}
static void print_str(const char *buf,int size)
{
int i;
for(i=0;i<size;i++)
- log_debug("%c",buf[i]);
+ log_ppp_debug("%c",buf[i]);
}
@@ -164,7 +164,7 @@ static void chap_send_failure(struct chap_auth_data_t *ad)
.message=MSG_FAILURE,
};
- log_debug("send [MSCHAP-v1 Failure id=%x \"%s\"]\n",msg.hdr.id,MSG_FAILURE);
+ log_ppp_debug("send [MSCHAP-v1 Failure id=%x \"%s\"]\n",msg.hdr.id,MSG_FAILURE);
ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2);
}
@@ -180,7 +180,7 @@ static void chap_send_success(struct chap_auth_data_t *ad)
.message=MSG_SUCCESS,
};
- log_debug("send [MSCHAP-v1 Success id=%x \"%s\"]\n",msg.hdr.id,MSG_SUCCESS);
+ log_ppp_debug("send [MSCHAP-v1 Success id=%x \"%s\"]\n",msg.hdr.id,MSG_SUCCESS);
ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2);
}
@@ -199,9 +199,9 @@ static void chap_send_challenge(struct chap_auth_data_t *ad)
read(urandom_fd,ad->val,VALUE_SIZE);
memcpy(msg.val,ad->val,VALUE_SIZE);
- log_debug("send [MSCHAP-v1 Challenge id=%x <",msg.hdr.id);
+ log_ppp_debug("send [MSCHAP-v1 Challenge id=%x <",msg.hdr.id);
print_buf(msg.val,VALUE_SIZE);
- log_debug(">]\n");
+ log_ppp_debug(">]\n");
ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2);
}
@@ -211,24 +211,24 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h
struct chap_response_t *msg=(struct chap_response_t*)hdr;
char *name;
- log_debug("recv [MSCHAP-v1 Response id=%x <", msg->hdr.id);
+ log_ppp_debug("recv [MSCHAP-v1 Response id=%x <", msg->hdr.id);
print_buf(msg->lm_hash,24);
- log_debug(">, <");
+ log_ppp_debug(">, <");
print_buf(msg->nt_hash,24);
- log_debug(">, F=%i, name=\"",msg->use_nt_hash);
+ log_ppp_debug(">, F=%i, name=\"",msg->use_nt_hash);
print_str(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2);
- log_debug("\"]\n");
+ log_ppp_debug("\"]\n");
if (msg->hdr.id!=ad->id)
{
- log_error("mschap-v1: id mismatch\n");
+ log_ppp_error("mschap-v1: id mismatch\n");
chap_send_failure(ad);
auth_failed(ad->ppp);
}
if (msg->val_size!=RESPONSE_VALUE_SIZE)
{
- log_error("mschap-v1: value-size should be %i, expected %i\n",RESPONSE_VALUE_SIZE,msg->val_size);
+ log_ppp_error("mschap-v1: value-size should be %i, expected %i\n",RESPONSE_VALUE_SIZE,msg->val_size);
chap_send_failure(ad);
auth_failed(ad->ppp);
}
@@ -289,7 +289,7 @@ static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response
if (!passwd)
{
free(name);
- log_debug("mschap-v1: user not found\n");
+ log_ppp_debug("mschap-v1: user not found\n");
chap_send_failure(ad);
return -1;
}
@@ -335,14 +335,14 @@ static void chap_recv(struct ppp_handler_t *h)
if (d->ppp->chan_buf_size<sizeof(*hdr) || ntohs(hdr->len)<HDR_LEN || ntohs(hdr->len)<d->ppp->chan_buf_size-2)
{
- log_warn("mschap-v1: short packet received\n");
+ log_ppp_warn("mschap-v1: short packet received\n");
return;
}
if (hdr->code==CHAP_RESPONSE) chap_recv_response(d,hdr);
else
{
- log_warn("mschap-v1: unknown code received %x\n",hdr->code);
+ log_ppp_warn("mschap-v1: unknown code received %x\n",hdr->code);
}
}
diff --git a/accel-pptpd/auth/auth_mschap_v2.c b/accel-pptpd/auth/auth_mschap_v2.c
index 6f1de0ed..6bd2c658 100644
--- a/accel-pptpd/auth/auth_mschap_v2.c
+++ b/accel-pptpd/auth/auth_mschap_v2.c
@@ -101,13 +101,13 @@ static void print_buf(const uint8_t *buf,int size)
{
int i;
for(i=0;i<size;i++)
- log_debug("%x",buf[i]);
+ log_ppp_debug("%x",buf[i]);
}
static void print_str(const char *buf,int size)
{
int i;
for(i=0;i<size;i++)
- log_debug("%c",buf[i]);
+ log_ppp_debug("%c",buf[i]);
}
@@ -177,7 +177,7 @@ static void chap_send_failure(struct chap_auth_data_t *ad)
.message=MSG_FAILURE,
};
- log_debug("send [MSCHAP-v2 Failure id=%x \"%s\"]\n",msg.hdr.id,MSG_FAILURE);
+ log_ppp_debug("send [MSCHAP-v2 Failure id=%x \"%s\"]\n",msg.hdr.id,MSG_FAILURE);
ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2);
}
@@ -260,7 +260,7 @@ static void chap_send_success(struct chap_auth_data_t *ad, struct chap_response_
sprintf(msg.message+2+i*2,"%02X",response[i]);
msg.message[2+i*2]=' ';
- log_debug("send [MSCHAP-v2 Success id=%x \"%s\"]\n",msg.hdr.id,msg.message);
+ log_ppp_debug("send [MSCHAP-v2 Success id=%x \"%s\"]\n",msg.hdr.id,msg.message);
ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2);
}
@@ -279,9 +279,9 @@ static void chap_send_challenge(struct chap_auth_data_t *ad)
read(urandom_fd,ad->val,VALUE_SIZE);
memcpy(msg.val,ad->val,VALUE_SIZE);
- log_debug("send [MSCHAP-v2 Challenge id=%x <",msg.hdr.id);
+ log_ppp_debug("send [MSCHAP-v2 Challenge id=%x <",msg.hdr.id);
print_buf(msg.val,VALUE_SIZE);
- log_debug(">]\n");
+ log_ppp_debug(">]\n");
ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2);
}
@@ -291,31 +291,31 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h
struct chap_response_t *msg=(struct chap_response_t*)hdr;
char *name;
- log_debug("recv [MSCHAP-v2 Response id=%x <", msg->hdr.id);
+ log_ppp_debug("recv [MSCHAP-v2 Response id=%x <", msg->hdr.id);
print_buf(msg->peer_challenge,16);
- log_debug(">, <");
+ log_ppp_debug(">, <");
print_buf(msg->nt_hash,24);
- log_debug(">, F=%i, name=\"",msg->flags);
+ log_ppp_debug(">, F=%i, name=\"",msg->flags);
print_str(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2);
- log_debug("\"]\n");
+ log_ppp_debug("\"]\n");
if (msg->hdr.id!=ad->id)
{
- log_error("mschap-v2: id mismatch\n");
+ log_ppp_error("mschap-v2: id mismatch\n");
chap_send_failure(ad);
ppp_terminate(ad->ppp, 0);
}
if (msg->val_size!=RESPONSE_VALUE_SIZE)
{
- log_error("mschap-v2: value-size should be %i, expected %i\n",RESPONSE_VALUE_SIZE,msg->val_size);
+ log_ppp_error("mschap-v2: value-size should be %i, expected %i\n",RESPONSE_VALUE_SIZE,msg->val_size);
chap_send_failure(ad);
ppp_terminate(ad->ppp, 0);
}
name=strndup(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2);
if (!name) {
- log_error("mschap-v2: out of memory\n");
+ log_emerg("mschap-v2: out of memory\n");
auth_failed(ad->ppp);
return;
}
@@ -376,7 +376,7 @@ static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response
if (!passwd)
{
free(name);
- log_debug("mschap-v2: user not found\n");
+ log_ppp_debug("mschap-v2: user not found\n");
chap_send_failure(ad);
return -1;
}
@@ -428,14 +428,14 @@ static void chap_recv(struct ppp_handler_t *h)
if (d->ppp->chan_buf_size<sizeof(*hdr) || ntohs(hdr->len)<HDR_LEN || ntohs(hdr->len)<d->ppp->chan_buf_size-2)
{
- log_warn("mschap-v2: short packet received\n");
+ log_ppp_warn("mschap-v2: short packet received\n");
return;
}
if (hdr->code==CHAP_RESPONSE) chap_recv_response(d,hdr);
else
{
- log_warn("mschap-v2: unknown code received %x\n",hdr->code);
+ log_ppp_warn("mschap-v2: unknown code received %x\n",hdr->code);
}
}
diff --git a/accel-pptpd/auth/auth_pap.c b/accel-pptpd/auth/auth_pap.c
index 288bccb9..81098ce9 100644
--- a/accel-pptpd/auth/auth_pap.c
+++ b/accel-pptpd/auth/auth_pap.c
@@ -120,7 +120,7 @@ static void pap_send_ack(struct pap_auth_data_t *p, int id)
msg->msg_len=sizeof(MSG_SUCCESSED)-1;
memcpy(msg->msg,MSG_SUCCESSED,sizeof(MSG_SUCCESSED));
- log_debug("send [PAP AuthAck id=%x \"%s\"]\n",id,MSG_SUCCESSED);
+ log_ppp_debug("send [PAP AuthAck id=%x \"%s\"]\n",id,MSG_SUCCESSED);
ppp_chan_send(p->ppp,msg,ntohs(msg->hdr.len)+2);
}
@@ -136,7 +136,7 @@ static void pap_send_nak(struct pap_auth_data_t *p, int id)
msg->msg_len=sizeof(MSG_FAILED)-1;
memcpy(msg->msg,MSG_FAILED,sizeof(MSG_FAILED));
- log_debug("send [PAP AuthNak id=%x \"%s\"]\n",id,MSG_FAILED);
+ log_ppp_debug("send [PAP AuthNak id=%x \"%s\"]\n",id,MSG_FAILED);
ppp_chan_send(p->ppp,msg,ntohs(msg->hdr.len)+2);
}
@@ -151,12 +151,12 @@ static int pap_recv_req(struct pap_auth_data_t *p,struct pap_hdr_t *hdr)
int passwd_len;
uint8_t *ptr=(uint8_t*)(hdr+1);
- log_debug("recv [PAP AuthReq id=%x]\n",hdr->id);
+ log_ppp_debug("recv [PAP AuthReq id=%x]\n",hdr->id);
peer_id_len=*(uint8_t*)ptr; ptr++;
if (peer_id_len>ntohs(hdr->len)-sizeof(*hdr)+2-1)
{
- log_warn("PAP: short packet received\n");
+ log_ppp_warn("PAP: short packet received\n");
return -1;
}
peer_id=(char*)ptr; ptr+=peer_id_len;
@@ -164,7 +164,7 @@ static int pap_recv_req(struct pap_auth_data_t *p,struct pap_hdr_t *hdr)
passwd_len=*(uint8_t*)ptr; ptr++;
if (passwd_len>ntohs(hdr->len)-sizeof(*hdr)+2-2-peer_id_len)
{
- log_warn("PAP: short packet received\n");
+ log_ppp_warn("PAP: short packet received\n");
return -1;
}
@@ -180,7 +180,7 @@ static int pap_recv_req(struct pap_auth_data_t *p,struct pap_hdr_t *hdr)
r = PWDB_SUCCESS;
}
if (r == PWDB_DENIED) {
- log_warn("PAP: authentication error\n");
+ log_ppp_warn("PAP: authentication error\n");
pap_send_nak(p, hdr->id);
auth_failed(p->ppp);
ret=-1;
@@ -203,14 +203,14 @@ static void pap_recv(struct ppp_handler_t *h)
if (d->ppp->chan_buf_size<sizeof(*hdr) || ntohs(hdr->len)<HDR_LEN || ntohs(hdr->len)<d->ppp->chan_buf_size-2)
{
- log_warn("PAP: short packet received\n");
+ log_ppp_warn("PAP: short packet received\n");
return;
}
if (hdr->code==PAP_REQ) pap_recv_req(d,hdr);
else
{
- log_warn("PAP: unknown code received %x\n",hdr->code);
+ log_ppp_warn("PAP: unknown code received %x\n",hdr->code);
}
}
diff --git a/accel-pptpd/ctrl/pptp.c b/accel-pptpd/ctrl/pptp.c
index 38f8473c..dab807c8 100644
--- a/accel-pptpd/ctrl/pptp.c
+++ b/accel-pptpd/ctrl/pptp.c
@@ -12,6 +12,7 @@
#include "if_pppox.h"
+#include "events.h"
#include "list.h"
#include "pptp_prot.h"
#include "triton.h"
@@ -58,20 +59,18 @@ static void disconnect(struct pptp_conn_t *conn)
triton_md_unregister_handler(&conn->hnd);
close(conn->hnd.fd);
- if (conn->timeout_timer.period) {
+ if (conn->timeout_timer.tpd)
triton_timer_del(&conn->timeout_timer);
- conn->timeout_timer.period = 0;
- }
- if (conn->echo_timer.period) {
+ if (conn->echo_timer.tpd)
triton_timer_del(&conn->echo_timer);
- conn->echo_timer.period = 0;
- }
if (conn->state == STATE_PPP) {
conn->state = STATE_CLOSE;
ppp_terminate(&conn->ppp, 1);
}
+
+ triton_event_fire(EV_CTRL_FINISHED, &conn->ppp);
triton_context_unregister(&conn->ctx);
@@ -84,7 +83,7 @@ static int post_msg(struct pptp_conn_t *conn, void *buf, int size)
{
int n;
if (conn->out_size) {
- log_debug("post_msg: buffer is not empty\n");
+ log_error("post_msg: buffer is not empty\n");
return -1;
}
@@ -94,7 +93,7 @@ static int post_msg(struct pptp_conn_t *conn, void *buf, int size)
n = 0;
else {
if (errno != EPIPE)
- log_debug("post_msg: failed to write socket %i\n",errno);
+ log_ppp_debug("post_msg: failed to write socket %i\n",errno);
return -1;
}
}
@@ -131,7 +130,7 @@ static int send_pptp_stop_ctrl_conn_rply(struct pptp_conn_t *conn, int reason, i
static int pptp_stop_ctrl_conn_rqst(struct pptp_conn_t *conn)
{
struct pptp_stop_ctrl_conn *msg = (struct pptp_stop_ctrl_conn *)conn->in_buf;
- log_info("PPTP_STOP_CTRL_CONN_RQST reason=%i error_code=%i\n",msg->reason_result, msg->error_code);
+ log_ppp_info("PPTP_STOP_CTRL_CONN_RQST reason=%i error_code=%i\n",msg->reason_result, msg->error_code);
if (conn->state == STATE_PPP) {
conn->state = STATE_FIN;
@@ -168,20 +167,20 @@ static int pptp_start_ctrl_conn_rqst(struct pptp_conn_t *conn)
struct pptp_start_ctrl_conn *msg = (struct pptp_start_ctrl_conn *)conn->in_buf;
if (conn->state != STATE_IDLE) {
- log_info("unexpected PPTP_START_CTRL_CONN_RQST\n");
+ log_ppp_warn("unexpected PPTP_START_CTRL_CONN_RQST\n");
if (send_pptp_start_ctrl_conn_rply(conn, PPTP_CONN_RES_EXISTS, 0))
return -1;
return 0;
}
if (msg->version != htons(PPTP_VERSION)) {
- log_info("PPTP version mismatch: expecting %x, received %s\n", PPTP_VERSION, msg->version);
+ log_ppp_warn("PPTP version mismatch: expecting %x, received %s\n", PPTP_VERSION, msg->version);
if (send_pptp_start_ctrl_conn_rply(conn, PPTP_CONN_RES_PROTOCOL, 0))
return -1;
return 0;
}
if (!(ntohl(msg->framing_cap) & PPTP_FRAME_SYNC)) {
- log_info("connection does not supports sync mode\n");
+ log_ppp_warn("connection does not supports sync mode\n");
if (send_pptp_start_ctrl_conn_rply(conn, PPTP_CONN_RES_GE, 0))
return -1;
return 0;
@@ -223,7 +222,7 @@ static int pptp_out_call_rqst(struct pptp_conn_t *conn)
int pptp_sock;
if (conn->state != STATE_ESTB) {
- log_error("unexpected PPTP_OUT_CALL_RQST\n");
+ log_ppp_warn("unexpected PPTP_OUT_CALL_RQST\n");
if (send_pptp_out_call_rply(conn, msg, 0, PPTP_CALL_RES_GE, PPTP_GE_NOCONN))
return -1;
return 0;
@@ -245,11 +244,11 @@ static int pptp_out_call_rqst(struct pptp_conn_t *conn)
pptp_sock = socket(AF_PPPOX, SOCK_STREAM, PX_PROTO_PPTP);
if (pptp_sock < 0) {
- log_error("failed to create PPTP socket (%s)\n", strerror(errno));
+ log_ppp_error("failed to create PPTP socket (%s)\n", strerror(errno));
return -1;
}
if (bind(pptp_sock, (struct sockaddr*)&src_addr, sizeof(src_addr))) {
- log_error("failed to bind PPTP socket (%s)\n", strerror(errno));
+ log_ppp_error("failed to bind PPTP socket (%s)\n", strerror(errno));
close(pptp_sock);
return -1;
}
@@ -257,7 +256,7 @@ static int pptp_out_call_rqst(struct pptp_conn_t *conn)
getsockname(pptp_sock, (struct sockaddr*)&src_addr, &addrlen);
if (connect(pptp_sock, (struct sockaddr*)&dst_addr, sizeof(dst_addr))) {
- log_error("failed to connect PPTP socket (%s)\n", strerror(errno));
+ log_ppp_error("failed to connect PPTP socket (%s)\n", strerror(errno));
close(pptp_sock);
return -1;
}
@@ -267,10 +266,9 @@ static int pptp_out_call_rqst(struct pptp_conn_t *conn)
conn->ppp.fd = pptp_sock;
conn->ppp.chan_name = strdup(inet_ntoa(dst_addr.sa_addr.pptp.sin_addr));
- conn->ppp.ctrl = &conn->ctrl;
- conn->ctrl.ctx = &conn->ctx;
- conn->ctrl.started = ppp_started;
- conn->ctrl.finished = ppp_finished;
+
+ triton_event_fire(EV_CTRL_STARTED, &conn->ppp);
+
if (establish_ppp(&conn->ppp)) {
close(pptp_sock);
//if (send_pptp_stop_ctrl_conn_rqst(conn, 0, 0))
@@ -279,8 +277,8 @@ static int pptp_out_call_rqst(struct pptp_conn_t *conn)
}
conn->state = STATE_PPP;
- triton_timer_del(&conn->timeout_timer);
- conn->timeout_timer.period = 0;
+ if (conn->timeout_timer.tpd)
+ triton_timer_del(&conn->timeout_timer);
if (conf_echo_interval) {
conn->echo_timer.period = conf_echo_interval * 1000;
@@ -306,7 +304,7 @@ static int pptp_echo_rply(struct pptp_conn_t *conn)
{
struct pptp_echo_rply *msg = (struct pptp_echo_rply *)conn->in_buf;
if (msg->identifier != conn->echo_sent) {
- log_error("pptp:echo: identifier mismatch\n");
+ log_ppp_warn("pptp:echo: identifier mismatch\n");
return -1;
}
conn->echo_sent = 0;
@@ -320,7 +318,7 @@ static void pptp_send_echo(struct triton_timer_t *t)
};
if (conn->echo_sent) {
- log_warn("pptp: no echo reply\n");
+ log_ppp_warn("pptp: no echo reply\n");
disconnect(conn);
return;
}
@@ -364,7 +362,7 @@ static int pptp_read(struct triton_md_handler_t *h)
continue;
if (errno == EAGAIN)
return 0;
- log_error("pptp: read: %s\n",strerror(errno));
+ log_ppp_error("pptp: read: %s\n",strerror(errno));
goto drop;
}
if (n == 0)
@@ -405,7 +403,7 @@ static int pptp_write(struct triton_md_handler_t *h)
n = 0;
else {
if (errno != EPIPE)
- log_error("pptp:post_msg: %s\n", strerror(errno));
+ log_ppp_error("pptp:post_msg: %s\n", strerror(errno));
disconnect(conn);
return 1;
}
@@ -436,18 +434,17 @@ static void pptp_close(struct triton_context_t *ctx)
}
static void ppp_started(struct ppp_t *ppp)
{
- log_msg("ppp_started\n");
+ log_ppp_debug("ppp_started\n");
}
static void ppp_finished(struct ppp_t *ppp)
{
struct pptp_conn_t *conn = container_of(ppp, typeof(*conn), ppp);
- log_msg("ppp_finished\n");
- close(conn->ppp.fd);
//send_pptp_stop_ctrl_conn_rqst(conn, 0, 0);
if (conn->state != STATE_CLOSE) {
+ log_ppp_debug("ppp_finished\n");
conn->state = STATE_CLOSE;
- disconnect(conn);
+ triton_context_call(&conn->ctx, (void (*)(void*))disconnect, conn);
}
}
@@ -495,16 +492,25 @@ static int pptp_connect(struct triton_md_handler_t *h)
conn->hnd.read = pptp_read;
conn->hnd.write = pptp_write;
conn->ctx.close = pptp_close;
+ conn->ctx.before_switch = log_switch;
conn->in_buf = malloc(PPTP_CTRL_SIZE_MAX);
conn->out_buf = malloc(PPTP_CTRL_SIZE_MAX);
conn->timeout_timer.expire = pptp_timeout;
conn->timeout_timer.period = conf_timeout * 1000;
conn->echo_timer.expire = pptp_send_echo;
+ conn->ctrl.ctx = &conn->ctx;
+ conn->ctrl.started = ppp_started;
+ conn->ctrl.finished = ppp_finished;
+
+ ppp_init(&conn->ppp);
+ conn->ppp.ctrl = &conn->ctrl;
- triton_context_register(&conn->ctx);
+ triton_context_register(&conn->ctx, &conn->ppp);
triton_md_register_handler(&conn->ctx, &conn->hnd);
triton_md_enable_handler(&conn->hnd,MD_MODE_READ);
triton_timer_add(&conn->ctx, &conn->timeout_timer, 0);
+
+ triton_event_fire(EV_CTRL_STARTING, &conn->ppp);
}
return 0;
}
@@ -552,7 +558,7 @@ static void __init pptp_init(void)
return;
}
- triton_context_register(&serv.ctx);
+ triton_context_register(&serv.ctx, NULL);
triton_md_register_handler(&serv.ctx, &serv.hnd);
triton_md_enable_handler(&serv.hnd, MD_MODE_READ);
diff --git a/accel-pptpd/include/events.h b/accel-pptpd/include/events.h
index 85e1bc73..332b4e31 100644
--- a/accel-pptpd/include/events.h
+++ b/accel-pptpd/include/events.h
@@ -6,6 +6,9 @@
#define EV_PPP_FINISHING 3
#define EV_PPP_FINISHED 4
#define EV_PPP_AUTHORIZED 5
+#define EV_CTRL_STARTING 6
+#define EV_CTRL_STARTED 7
+#define EV_CTRL_FINISHED 8
#define EV_IP_CHANGED 100
#define EV_SHAPE_CHANGED 101
diff --git a/accel-pptpd/include/spinlock.h b/accel-pptpd/include/spinlock.h
new file mode 120000
index 00000000..09edcf6b
--- /dev/null
+++ b/accel-pptpd/include/spinlock.h
@@ -0,0 +1 @@
+../triton/spinlock.h \ No newline at end of file
diff --git a/accel-pptpd/log.c b/accel-pptpd/log.c
index a29ce846..76603d41 100644
--- a/accel-pptpd/log.c
+++ b/accel-pptpd/log.c
@@ -1,118 +1,422 @@
-/*
-* C Implementation: log
-*
-* Description:
-*
-*
-* Author: <xeb@mail.ru>, (C) 2009
-*
-* Copyright: See COPYING file that comes with this distribution
-*
-*/
-
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
-#include <pthread.h>
#include <stdarg.h>
#include <errno.h>
#include <string.h>
-#include <pthread.h>
+#include <stdint.h>
#include <sys/time.h>
-#include "triton/triton.h"
+#include "triton/mempool.h"
+#include "events.h"
+#include "ppp.h"
+
#include "log.h"
-#define RED_COLOR "\033[1;31m"
-#define GREEN_COLOR "\033[1;32m"
-#define YELLOW_COLOR "\033[1;33m"
-#define BLUE_COLOR "\033[1;34m"
-#define NORMAL_COLOR "\033[0;39m"
+#define LOG_MAX_SIZE 4096
+
+struct log_pd_t
+{
+ struct ppp_pd_t pd;
+ struct ppp_t *ppp;
+ struct list_head msgs;
+ struct log_msg_t *msg;
+};
-#define LOG_ERROR 0
-#define LOG_WARN 1
-#define LOG_INFO 2
-#define LOG_DEBUG 3
+struct _log_msg_t
+{
+ struct list_head entry;
+ int level;
+ struct timeval timestamp;
+ struct list_head chunks;
+ uint8_t refs;
+};
-static FILE *log_file;
static int log_level=10;
-static int log_color=1;
-static const char* level_name[]={"error","warning","info","debug"};
-static const char* level_color[]={RED_COLOR,YELLOW_COLOR,GREEN_COLOR,BLUE_COLOR};
-static pthread_mutex_t lock=PTHREAD_MUTEX_INITIALIZER;
+static LIST_HEAD(targets);
+static mempool_t msg_pool;
+static mempool_t _msg_pool;
+static mempool_t chunk_pool;
+
+static __thread struct ppp_t *cur_ppp;
+static __thread struct _log_msg_t *cur_msg;
+static __thread char stat_buf[LOG_MAX_SIZE+1];
+
+static FILE *emerg_file;
+
+static void *pd_key;
-static int msg_completed=1;
+static void _log_free_msg(struct _log_msg_t *msg);
+static struct log_msg_t *clone_msg(struct _log_msg_t *msg);
+static int add_msg(struct _log_msg_t *msg, const char *buf);
+static struct log_pd_t *find_pd(struct ppp_t *ppp);
-static void do_log(int level,const char *fmt,va_list ap)
+static void do_log(int level, const char *fmt, va_list ap, struct ppp_t *ppp)
{
- struct timeval tv;
+ struct log_target_t *t;
+ struct log_msg_t *m;
+ struct log_pd_t *lpd;
- //pthread_mutex_lock(&lock);
- if (!log_file)
- log_file=stdout;
- if (msg_completed)
- {
- gettimeofday(&tv,NULL);
- if (log_color) fprintf(log_file,"[%s%li.%03li] [%s]%s ",level_color[level],tv.tv_sec,tv.tv_usec/1000,NORMAL_COLOR,level_name[level]);
- else fprintf(log_file,"[%li.%03li] [%s] ",tv.tv_sec,tv.tv_usec/1000,level_name[level]);
+ if (list_empty(&targets))
+ return;
+
+ vsnprintf(stat_buf, LOG_MAX_SIZE, fmt, ap);
+ if (!cur_msg) {
+ cur_msg = mempool_alloc(_msg_pool);
+ if (!cur_msg)
+ return;
+ INIT_LIST_HEAD(&cur_msg->chunks);
+ cur_msg->refs = 1;
+ cur_msg->level = level;
+ gettimeofday(&cur_msg->timestamp, NULL);
}
- vfprintf(log_file,fmt,ap);
+ if (add_msg(cur_msg, stat_buf))
+ goto out;
+
+ if (stat_buf[strlen(stat_buf) - 1] != '\n')
+ return;
+
+ if (ppp && !ppp->username) {
+ lpd = find_pd(ppp);
+ list_add_tail(&cur_msg->entry, &lpd->msgs);
+ cur_msg = NULL;
+ return;
+ }
- msg_completed=fmt[strlen(fmt)-1]=='\n';
- //if (msg_completed) pthread_mutex_unlock(&lock);
+ list_for_each_entry(t, &targets, entry) {
+ if (ppp) {
+ if (t->session_log) {
+ m = clone_msg(cur_msg);
+ if (!m)
+ break;
+ t->session_log(ppp, m);
+ }
+ } else {
+ if (t->log) {
+ m = clone_msg(cur_msg);
+ if (!m)
+ break;
+ t->log(m);
+ }
+ }
+ }
+
+out:
+ _log_free_msg(cur_msg);
+ cur_msg = NULL;
}
+
void __export log_error(const char *fmt,...)
{
- if (log_level>=1)
- {
+ if (log_level >= LOG_ERROR) {
va_list ap;
va_start(ap,fmt);
- do_log(LOG_ERROR,fmt,ap);
+ do_log(LOG_ERROR, fmt, ap, NULL);
+ va_end(ap);
}
}
+
void __export log_warn(const char *fmt,...)
{
- if (log_level>=2)
- {
+ if (log_level >= LOG_WARN) {
va_list ap;
va_start(ap,fmt);
- do_log(LOG_WARN,fmt,ap);
+ do_log(LOG_WARN, fmt, ap, NULL);
+ va_end(ap);
}
}
+
void __export log_info(const char *fmt,...)
{
- if (log_level>=3)
- {
+ if (log_level >= LOG_INFO) {
va_list ap;
- va_start(ap,fmt);
- do_log(LOG_INFO,fmt,ap);
+ va_start(ap, fmt);
+ do_log(LOG_INFO, fmt, ap, NULL);
+ va_end(ap);
}
}
+
void __export log_debug(const char *fmt,...)
{
- if (log_level>=4)
- {
+ if (log_level >= LOG_DEBUG) {
va_list ap;
- va_start(ap,fmt);
- do_log(LOG_DEBUG,fmt,ap);
+ va_start(ap, fmt);
+ do_log(LOG_DEBUG, fmt, ap, NULL);
+ va_end(ap);
}
}
void __export log_msg(const char *fmt,...)
{
va_list ap;
- if (msg_completed) return;
- va_start(ap,fmt);
- vfprintf(log_file,fmt,ap);
- msg_completed=fmt[strlen(fmt)-1]=='\n';
- if (msg_completed) pthread_mutex_unlock(&lock);
+ va_start(ap, fmt);
+ do_log(LOG_MSG, fmt, ap, NULL);
+ va_end(ap);
+}
+
+void __export log_ppp_error(const char *fmt,...)
+{
+ if (log_level >= LOG_ERROR) {
+ va_list ap;
+ va_start(ap, fmt);
+ do_log(LOG_ERROR, fmt, ap, cur_ppp);
+ va_end(ap);
+ }
+}
+
+void __export log_ppp_warn(const char *fmt,...)
+{
+ if (log_level >= LOG_WARN) {
+ va_list ap;
+ va_start(ap, fmt);
+ do_log(LOG_WARN, fmt, ap, cur_ppp);
+ va_end(ap);
+ }
+}
+
+void __export log_ppp_info(const char *fmt,...)
+{
+ if (log_level >= LOG_INFO) {
+ va_list ap;
+ va_start(ap, fmt);
+ do_log(LOG_INFO, fmt, ap, cur_ppp);
+ va_end(ap);
+ }
+}
+
+void __export log_ppp_debug(const char *fmt,...)
+{
+ if (log_level >= LOG_DEBUG) {
+ va_list ap;
+ va_start(ap, fmt);
+ do_log(LOG_DEBUG, fmt, ap, cur_ppp);
+ va_end(ap);
+ }
+}
+
+void __export log_ppp_msg(const char *fmt,...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ do_log(LOG_MSG, fmt, ap, cur_ppp);
+ va_end(ap);
+}
+
+void __export log_emerg(const char *fmt, ...)
+{
+ if (emerg_file) {
+ va_list ap;
+ va_start(ap, fmt);
+ vfprintf(emerg_file, fmt, ap);
+ va_end(ap);
+ }
+}
+
+void __export log_free_msg(struct log_msg_t *m)
+{
+ struct _log_msg_t *msg = (struct _log_msg_t *)m->lpd;
+
+ mempool_free(m->hdr);
+ _log_free_msg(msg);
+
+ mempool_free(m);
+}
+
+
+static void _log_free_msg(struct _log_msg_t *msg)
+{
+ struct log_chunk_t *chunk;
+
+ if (__sync_sub_and_fetch(&msg->refs, 1))
+ return;
+
+ while(!list_empty(&msg->chunks)) {
+ chunk = list_entry(msg->chunks.next, typeof(*chunk), entry);
+ list_del(&chunk->entry);
+ mempool_free(chunk);
+ }
+
+ mempool_free(msg);
}
-void __export log_init(FILE *f,int level,int color)
+static struct log_msg_t *clone_msg(struct _log_msg_t *msg)
{
- log_file=f;
- log_level=level;
- log_color=color;
+ struct log_msg_t *m = mempool_alloc(msg_pool);
+ if (!m) {
+ log_emerg("log: out of memory\n");
+ return NULL;
+ }
+
+ m->hdr = mempool_alloc(chunk_pool);
+ if (!m->hdr) {
+ log_emerg("log: out of memory\n");
+ mempool_free(m);
+ return NULL;
+ }
+
+ m->hdr->len = 0;
+ m->lpd = msg;
+ m->chunks = &msg->chunks;
+ m->timestamp = msg->timestamp;
+ m->level = msg->level;
+
+ __sync_add_and_fetch(&msg->refs, 1);
+
+ return m;
}
+static int add_msg(struct _log_msg_t *msg, const char *buf)
+{
+ struct log_chunk_t *chunk;
+ int i, len, chunk_cnt;
+
+ len = strlen(buf);
+ chunk_cnt = (len - 1)/LOG_CHUNK_SIZE + 1;
+
+ for (i = 0; i < chunk_cnt; i++) {
+ chunk = mempool_alloc(chunk_pool);
+ if (!chunk)
+ return -1;
+
+ chunk->len = i == chunk_cnt -1 ? len - i * LOG_CHUNK_SIZE : LOG_CHUNK_SIZE;
+ memcpy(chunk->msg, buf + i * LOG_CHUNK_SIZE, chunk->len);
+ chunk->msg[chunk->len] = 0;
+
+ list_add_tail(&chunk->entry, &msg->chunks);
+ }
+
+ return 0;
+}
+
+static struct log_pd_t *find_pd(struct ppp_t *ppp)
+{
+ struct ppp_pd_t *pd;
+ struct log_pd_t *lpd;
+
+ list_for_each_entry(pd, &ppp->pd_list, entry) {
+ if (pd->key == &pd_key) {
+ lpd = container_of(pd, typeof(*lpd), pd);
+ return lpd;
+ }
+ }
+ list_for_each_entry(pd, &ppp->pd_list, entry)
+ printf("%p %p\n", pd->key, &pd_key);
+ log_emerg("log:BUG: pd not found\n");
+ abort();
+}
+
+static void ev_ctrl_starting(struct ppp_t *ppp)
+{
+ struct log_pd_t *lpd = malloc(sizeof(*lpd));
+ if (!lpd) {
+ log_emerg("log: out of memory\n");
+ return;
+ }
+
+ memset(lpd, 0, sizeof(*lpd));
+ lpd->pd.key = &pd_key;
+ lpd->ppp = ppp;
+ INIT_LIST_HEAD(&lpd->msgs);
+ list_add_tail(&lpd->pd.entry, &ppp->pd_list);
+}
+
+static void ev_ctrl_finished(struct ppp_t *ppp)
+{
+ struct log_pd_t *lpd = find_pd(ppp);
+ struct _log_msg_t *msg;
+ struct log_msg_t *m;
+ struct log_target_t *t;
+
+ if (lpd->msg) {
+ log_emerg("log:BUG: lpd->msg is not NULL\n");
+ abort();
+ }
+
+ if (ppp->username) {
+ if (!list_empty(&lpd->msgs)) {
+ log_emerg("log:BUG: lpd->msgs is not empty\n");
+ abort();
+ }
+ list_for_each_entry(t, &targets, entry)
+ if (t->session_stop)
+ t->session_stop(ppp);
+ }
+
+ while (!list_empty(&lpd->msgs)) {
+ msg = list_entry(lpd->msgs.next, typeof(*msg), entry);
+ list_del(&msg->entry);
+
+ list_for_each_entry(t, &targets, entry) {
+ if (!t->log)
+ continue;
+ m = clone_msg(msg);
+ if (!m)
+ break;
+ t->log(m);
+ }
+
+ _log_free_msg(msg);
+ }
+
+ list_del(&lpd->pd.entry);
+ free(lpd);
+}
+
+static void ev_ppp_authorized(struct ppp_t *ppp)
+{
+ struct log_pd_t *lpd = find_pd(ppp);
+ struct _log_msg_t *msg;
+ struct log_msg_t *m;
+ struct log_target_t *t;
+
+ list_for_each_entry(t, &targets, entry)
+ if (t->session_start)
+ t->session_start(ppp);
+
+ while(!list_empty(&lpd->msgs)) {
+ msg = list_entry(lpd->msgs.next, typeof(*msg), entry);
+ list_del(&msg->entry);
+
+ list_for_each_entry(t, &targets, entry) {
+ if (!t->session_log)
+ continue;
+ m = clone_msg(msg);
+ if (!m)
+ break;
+ t->session_log(lpd->ppp, m);
+ }
+
+ _log_free_msg(msg);
+ }
+}
+
+void __export log_switch(struct triton_context_t *ctx, void *arg)
+{
+ cur_ppp = (struct ppp_t *)arg;
+}
+
+void __export log_register_target(struct log_target_t *t)
+{
+ list_add_tail(&t->entry, &targets);
+}
+
+static void __init log_init(void)
+{
+ char *opt;
+
+ opt = conf_get_opt("log", "log-emerg");
+ if (opt) {
+ emerg_file = fopen(opt, "a");
+ if (!emerg_file)
+ fprintf(stderr, "log:open: %s\n", strerror(errno));
+ }
+
+ msg_pool = mempool_create(sizeof(struct log_msg_t));
+ _msg_pool = mempool_create(sizeof(struct _log_msg_t));
+ chunk_pool = mempool_create(sizeof(struct log_chunk_t) + LOG_CHUNK_SIZE + 1);
+
+ triton_event_register_handler(EV_CTRL_STARTING, (triton_event_func)ev_ctrl_starting);
+ triton_event_register_handler(EV_CTRL_FINISHED, (triton_event_func)ev_ctrl_finished);
+ triton_event_register_handler(EV_PPP_AUTHORIZED, (triton_event_func)ev_ppp_authorized);
+}
diff --git a/accel-pptpd/log.h b/accel-pptpd/log.h
index 25f9f976..2e825263 100644
--- a/accel-pptpd/log.h
+++ b/accel-pptpd/log.h
@@ -1,25 +1,66 @@
-//
-// C++ Interface: log
-//
-// Description:
-//
-//
-// Author: <xeb@mail.ru>, (C) 2009
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-
-#ifndef LOG_H
-#define LOG_H
-
-#include <stdio.h>
-
-void log_init(FILE *f,int level,int color);
+#ifndef __LOG_H
+#define __LOG_H
+
+#include <stdarg.h>
+#include <sys/time.h>
+#include "list.h"
+
+#define LOG_MSG 0
+#define LOG_ERROR 1
+#define LOG_WARN 2
+#define LOG_INFO 3
+#define LOG_DEBUG 4
+
+#define LOG_CHUNK_SIZE 128
+
+struct ppp_t;
+struct triton_context_t;
+
+struct log_msg_t
+{
+ struct list_head entry;
+ void *lpd;
+ struct timeval timestamp;
+ int level;
+ struct log_chunk_t *hdr;
+ struct list_head *chunks;
+};
+
+struct log_chunk_t
+{
+ struct list_head entry;
+ int len;
+ char msg[0];
+};
+
+struct log_target_t
+{
+ struct list_head entry;
+
+ void (*log)(struct log_msg_t *);
+ void (*session_log)(struct ppp_t *ppp, struct log_msg_t *);
+ void (*session_start)(struct ppp_t *ppp);
+ void (*session_stop)(struct ppp_t *ppp);
+};
+
+void log_free_msg(struct log_msg_t *msg);
+
+void log_emerg(const char *fmt, ...);
+
void log_error(const char *fmt,...);
void log_warn(const char *fmt,...);
void log_info(const char *fmt,...);
void log_debug(const char *fmt,...);
void log_msg(const char *fmt,...);
+void log_ppp_error(const char *fmt,...);
+void log_ppp_warn(const char *fmt,...);
+void log_ppp_info(const char *fmt,...);
+void log_ppp_debug(const char *fmt,...);
+void log_ppp_msg(const char *fmt,...);
+
+void log_switch(struct triton_context_t *ctx, void *arg);
+
+void log_register_target(struct log_target_t *t);
+
#endif
diff --git a/accel-pptpd/logs/CMakeLists.txt b/accel-pptpd/logs/CMakeLists.txt
new file mode 100644
index 00000000..1c1f4860
--- /dev/null
+++ b/accel-pptpd/logs/CMakeLists.txt
@@ -0,0 +1,2 @@
+ADD_LIBRARY(log_file SHARED log_file.c)
+
diff --git a/accel-pptpd/logs/log_file.c b/accel-pptpd/logs/log_file.c
new file mode 100644
index 00000000..4b44e715
--- /dev/null
+++ b/accel-pptpd/logs/log_file.c
@@ -0,0 +1,435 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+
+#include "log.h"
+#include "ppp.h"
+#include "spinlock.h"
+
+#define RED_COLOR "\033[1;31m"
+#define GREEN_COLOR "\033[1;32m"
+#define YELLOW_COLOR "\033[1;33m"
+#define BLUE_COLOR "\033[1;34m"
+#define NORMAL_COLOR "\033[0;39m"
+
+struct log_file_t
+{
+ struct triton_context_t ctx;
+ struct triton_md_handler_t hnd;
+ struct list_head msgs;
+ struct log_msg_t *cur_msg;
+ struct log_chunk_t *cur_chunk;
+ int cur_pos;
+ spinlock_t lock;
+ int sleeping:1;
+ int need_free:1;
+ struct log_file_pd_t *lpd;
+};
+
+struct log_file_pd_t
+{
+ struct ppp_pd_t pd;
+ struct log_file_t lf;
+};
+
+static int conf_color;
+static int conf_per_session;
+static char *conf_per_user_dir;
+static char *conf_per_session_dir;
+
+static const char* level_name[]={" msg", "error", " warn", " info", "debug"};
+static const char* level_color[]={NORMAL_COLOR, RED_COLOR, YELLOW_COLOR, GREEN_COLOR, BLUE_COLOR};
+
+static void *pd_key1;
+static void *pd_key2;
+static struct log_file_t *log_file;
+
+static int log_write(struct triton_md_handler_t *h);
+
+static int log_file_init(struct log_file_t *lf, const char *fname)
+{
+ spinlock_init(&lf->lock);
+ lf->sleeping = 1;
+ INIT_LIST_HEAD(&lf->msgs);
+ lf->hnd.write = log_write;
+
+ lf->hnd.fd = open(fname, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
+ if (lf->hnd.fd < 0) {
+ log_emerg("log_file: open '%s': %s\n", fname, strerror(errno));
+ return -1;
+ }
+
+ lseek(lf->hnd.fd, 0, SEEK_END);
+
+ if (fcntl(lf->hnd.fd, F_SETFL, O_NONBLOCK)) {
+ log_emerg("log_file: cann't to set nonblocking mode: %s\n", strerror(errno));
+ goto out_err;
+ }
+
+ if (triton_context_register(&lf->ctx, NULL))
+ goto out_err;
+ triton_md_register_handler(&lf->ctx, &lf->hnd);
+ return 0;
+
+out_err:
+ close(lf->hnd.fd);
+ return -1;
+}
+
+static void set_hdr(struct log_msg_t *msg, struct ppp_t *ppp)
+{
+ struct tm tm;
+ char timestamp[32];
+
+ localtime_r(&msg->timestamp.tv_sec, &tm);
+
+ strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", &tm);
+ sprintf(msg->hdr->msg, "%s[%s]: %s: %s%s%s", conf_color ? level_color[msg->level] : "",
+ timestamp, level_name[msg->level],
+ ppp ? ppp->ifname : "",
+ ppp ? ":" : "",
+ conf_color ? NORMAL_COLOR : "");
+ msg->hdr->len = strlen(msg->hdr->msg);
+}
+static int write_chunk(int fd, struct log_chunk_t *chunk, int pos)
+{
+ int n;
+
+ while (1) {
+ n = write(fd, chunk->msg + pos, chunk->len - pos);
+ if (n < 0) {
+ if (errno == EINTR)
+ continue;
+ if (errno == EAGAIN)
+ return pos;
+ log_emerg("log_file: write: %s\n", strerror(errno));
+ break;
+ }
+ pos += n;
+ if (pos == chunk->len)
+ return 0;
+ }
+ return -1;
+}
+static int write_msg(struct log_file_t *lf)
+{
+ if (!lf->cur_chunk)
+ lf->cur_chunk = lf->cur_msg->hdr;
+
+ if (lf->cur_chunk == lf->cur_msg->hdr) {
+ lf->cur_pos = write_chunk(lf->hnd.fd, lf->cur_chunk, lf->cur_pos);
+ if (lf->cur_pos < 0)
+ goto out;
+ if (lf->cur_pos)
+ return -1;
+ lf->cur_chunk = list_entry(lf->cur_msg->chunks->next, typeof(*lf->cur_chunk), entry);
+ }
+
+ while(&lf->cur_chunk->entry != lf->cur_msg->chunks) {
+ lf->cur_pos = write_chunk(lf->hnd.fd, lf->cur_chunk, lf->cur_pos);
+ if (lf->cur_pos < 0)
+ break;
+ if (lf->cur_pos)
+ return -1;
+ lf->cur_chunk = list_entry(lf->cur_chunk->entry.next, typeof(*lf->cur_chunk), entry);
+ }
+
+out:
+ log_free_msg(lf->cur_msg);
+ lf->cur_chunk = NULL;
+ lf->cur_msg = NULL;
+ lf->cur_pos = 0;
+ return 0;
+}
+
+static int log_write(struct triton_md_handler_t *h)
+{
+ struct log_file_t *lf = container_of(h, typeof(*lf), hnd);
+
+ if (lf->cur_msg)
+ if (write_msg(lf))
+ return 0;
+
+ while (1) {
+ spin_lock(&lf->lock);
+ if (!list_empty(&lf->msgs)) {
+ lf->cur_msg = list_entry(lf->msgs.next, typeof(*lf->cur_msg), entry);
+ list_del(&lf->cur_msg->entry);
+ spin_unlock(&lf->lock);
+
+ if (write_msg(lf))
+ return 0;
+
+ continue;
+ }
+ if (lf->need_free) {
+ spin_unlock(&lf->lock);
+ triton_md_unregister_handler(&lf->hnd);
+ close(lf->hnd.fd);
+ triton_context_unregister(&lf->ctx);
+ free(lf->lpd);
+ return 1;
+ }
+ lf->sleeping = 1;
+ spin_unlock(&lf->lock);
+ triton_md_disable_handler(&lf->hnd, MD_MODE_WRITE);
+ return 0;
+ }
+}
+
+static void log_wakeup(struct log_file_t *lf)
+{
+ if (log_write(&lf->hnd))
+ return ;
+
+ if (!lf->sleeping)
+ triton_md_enable_handler(&lf->hnd, MD_MODE_WRITE);
+}
+
+static void log_queue(struct log_file_t *lf, struct log_msg_t *msg)
+{
+ int r;
+ spin_lock(&lf->lock);
+ list_add_tail(&msg->entry, &lf->msgs);
+ r = lf->sleeping;
+ lf->sleeping = 0;
+ spin_unlock(&lf->lock);
+
+ if (r)
+ triton_context_call(&lf->ctx, (void (*)(void *))log_wakeup, lf);
+}
+
+static void general_log(struct log_msg_t *msg)
+{
+ if (!log_file)
+ return;
+ set_hdr(msg, NULL);
+ log_queue(log_file, msg);
+}
+
+static void general_session_log(struct ppp_t *ppp, struct log_msg_t *msg)
+{
+ if (!log_file)
+ return;
+ set_hdr(msg, ppp);
+ log_queue(log_file, msg);
+}
+
+static struct log_file_pd_t *find_pd(struct ppp_t *ppp, void *pd_key)
+{
+ struct ppp_pd_t *pd;
+ struct log_file_pd_t *lpd;
+
+ list_for_each_entry(pd, &ppp->pd_list, entry) {
+ if (pd->key == pd_key) {
+ lpd = container_of(pd, typeof(*lpd), pd);
+ return lpd;
+ }
+ }
+ //log_emerg("log:BUG: pd not found\n");
+ //abort();
+ return NULL;
+}
+
+static void session_log(struct ppp_t *ppp, struct log_msg_t *msg, void *pd_key)
+{
+ struct log_file_pd_t *lpd = find_pd(ppp, pd_key);
+
+ if (!lpd)
+ return;
+
+ set_hdr(msg, ppp);
+ log_queue(&lpd->lf, msg);
+}
+
+static void per_user_session_log(struct ppp_t *ppp, struct log_msg_t *msg)
+{
+ session_log(ppp, msg, &pd_key1);
+}
+
+static void per_session_log(struct ppp_t *ppp, struct log_msg_t *msg)
+{
+ session_log(ppp, msg, &pd_key2);
+}
+
+static void per_user_session_start(struct ppp_t *ppp)
+{
+ struct log_file_pd_t *lpd;
+ char *fname;
+
+ fname = malloc(PATH_MAX + 32);
+ if (!fname) {
+ log_emerg("log_file: out of memory\n");
+ return;
+ }
+
+ lpd = malloc(sizeof(*lpd));
+ if (!lpd) {
+ log_emerg("log_file: out of memory\n");
+ goto out_err;
+ }
+
+ memset(lpd, 0, sizeof(*lpd));
+ lpd->pd.key = &pd_key1;
+ lpd->lf.hnd.fd = -1;
+ lpd->lf.lpd = lpd;
+
+ strcpy(fname, conf_per_user_dir);
+ strcat(fname, "/");
+ strcat(fname, ppp->username);
+ if (conf_per_session) {
+ if (mkdir(fname, S_IRWXU) && errno != EEXIST) {
+ log_emerg("log_file: mkdir '%s': %s'\n", fname, strerror(errno));
+ goto out_err;
+ }
+ strcat(fname, "/");
+ strcat(fname, ppp->sessionid);
+ }
+ strcat(fname, ".log");
+
+ if (log_file_init(&lpd->lf, fname))
+ goto out_err;
+
+
+ list_add_tail(&lpd->pd.entry, &ppp->pd_list);
+ free(fname);
+ return;
+
+out_err:
+ free(fname);
+ if (lpd)
+ free(lpd);
+}
+static void per_session_start(struct ppp_t *ppp)
+{
+ struct log_file_pd_t *lpd;
+ char *fname;
+
+ fname = malloc(PATH_MAX + 32);
+ if (!fname) {
+ log_emerg("log_file: out of memory\n");
+ return;
+ }
+
+ lpd = malloc(sizeof(*lpd));
+ if (!lpd) {
+ log_emerg("log_file: out of memory\n");
+ goto out_err;
+ }
+
+ memset(lpd, 0, sizeof(*lpd));
+ lpd->pd.key = &pd_key2;
+ lpd->lf.hnd.fd = -1;
+ lpd->lf.lpd = lpd;
+
+ strcpy(fname, conf_per_session_dir);
+ strcat(fname, "/");
+ strcat(fname, ppp->sessionid);
+ strcat(fname, ".log");
+
+
+ if (log_file_init(&lpd->lf, fname))
+ goto out_err;
+
+ list_add_tail(&lpd->pd.entry, &ppp->pd_list);
+ free(fname);
+ return;
+
+out_err:
+ free(fname);
+ if (lpd)
+ free(lpd);
+}
+
+static void session_stop(struct ppp_t *ppp, void *pd_key)
+{
+ struct log_file_pd_t *lpd = find_pd(ppp, pd_key);
+ int r;
+
+ spin_lock(&lpd->lf.lock);
+ r = lpd->lf.sleeping;
+ lpd->lf.sleeping = 0;
+ lpd->lf.need_free = 1;
+ spin_unlock(&lpd->lf.lock);
+
+ if (r)
+ triton_context_call(&lpd->lf.ctx, (void (*)(void *))log_wakeup, &lpd->lf);
+}
+
+static void per_user_session_stop(struct ppp_t *ppp)
+{
+ session_stop(ppp, &pd_key1);
+}
+
+static void per_session_stop(struct ppp_t *ppp)
+{
+ session_stop(ppp, &pd_key2);
+}
+
+static struct log_target_t target =
+{
+ .log = general_log,
+};
+
+static struct log_target_t per_user_target =
+{
+ .session_log = per_user_session_log,
+ .session_start = per_user_session_start,
+ .session_stop = per_user_session_stop,
+};
+
+static struct log_target_t per_session_target =
+{
+ .session_log = per_session_log,
+ .session_start = per_session_start,
+ .session_stop = per_session_stop,
+};
+
+
+static void __init init(void)
+{
+ char *opt;
+
+ opt = conf_get_opt("log","color");
+ if (opt && atoi(opt) > 0)
+ conf_color = 1;
+
+ opt = conf_get_opt("log", "log-file");
+ if (opt) {
+ log_file = malloc(sizeof(*log_file));
+ memset(log_file, 0, sizeof(*log_file));
+ if (log_file_init(log_file, opt)) {
+ free(log_file);
+ log_file = NULL;
+ }
+ }
+
+ opt = conf_get_opt("log", "per-user-dir");
+ if (opt)
+ conf_per_user_dir = opt;
+
+ opt = conf_get_opt("log", "per-session-dir");
+ if (opt)
+ conf_per_session_dir = opt;
+
+ opt = conf_get_opt("log", "per-session");
+ if (opt && atoi(opt) > 0)
+ conf_per_session = 1;
+
+ if (conf_per_user_dir)
+ log_register_target(&per_user_target);
+
+ if (conf_per_session_dir)
+ log_register_target(&per_session_target);
+
+ if (log_file) {
+ if (!conf_per_user_dir && !conf_per_session_dir)
+ target.session_log = general_session_log;
+ log_register_target(&target);
+ }
+}
+
diff --git a/accel-pptpd/ppp/ipcp_opt_ipaddr.c b/accel-pptpd/ppp/ipcp_opt_ipaddr.c
index 64f06cd2..b7f86365 100644
--- a/accel-pptpd/ppp/ipcp_opt_ipaddr.c
+++ b/accel-pptpd/ppp/ipcp_opt_ipaddr.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
@@ -64,12 +65,12 @@ static int ipaddr_send_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *o
if (!ipaddr_opt->ip) {
ipaddr_opt->ip = ipdb_get(ipcp->ppp);
if (!ipaddr_opt->ip) {
- log_warn("ppp:ipcp: no free IP address\n");
+ log_ppp_warn("ppp:ipcp: no free IP address\n");
return -1;
}
}
if (!iprange_client_check(ipaddr_opt->ip->peer_addr)) {
- log_warn("ppp:ipcp: to avoid hard loops requested IP cannot be assigned (%i.%i.%i.%i)\n",
+ log_ppp_warn("ppp:ipcp: to avoid hard loops requested IP cannot be assigned (%i.%i.%i.%i)\n",
ipaddr_opt->ip->peer_addr&0xff,
(ipaddr_opt->ip->peer_addr >> 8)&0xff,
(ipaddr_opt->ip->peer_addr >> 16)&0xff,
@@ -115,34 +116,34 @@ ack:
memset(&ifr, 0, sizeof(ifr));
memset(&addr, 0, sizeof(addr));
- sprintf(ifr.ifr_name,"ppp%i",ipcp->ppp->unit_idx);
+ strcpy(ifr.ifr_name, ipcp->ppp->ifname);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = ipaddr_opt->ip->addr;
memcpy(&ifr.ifr_addr,&addr,sizeof(addr));
if (ioctl(sock_fd, SIOCSIFADDR, &ifr))
- log_error("\nipcp: failed to set PA address: %s\n", strerror(errno));
+ log_ppp_error("ipcp: failed to set PA address: %s\n", strerror(errno));
addr.sin_addr.s_addr = ipaddr_opt->ip->peer_addr;
memcpy(&ifr.ifr_dstaddr,&addr,sizeof(addr));
if (ioctl(sock_fd, SIOCSIFDSTADDR, &ifr))
- log_error("\nipcp: failed to set remote PA address: %s\n", strerror(errno));
+ log_ppp_error("ipcp: failed to set remote PA address: %s\n", strerror(errno));
if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr))
- log_error("\nipcp: failed to get interface flags: %s\n", strerror(errno));
+ log_ppp_error("ipcp: failed to get interface flags: %s\n", strerror(errno));
ifr.ifr_flags |= IFF_UP | IFF_POINTOPOINT;
if (ioctl(sock_fd, SIOCSIFFLAGS, &ifr))
- log_error("\nipcp: failed to set interface flags: %s\n", strerror(errno));
+ log_ppp_error("ipcp: failed to set interface flags: %s\n", strerror(errno));
np.protocol = PPP_IP;
np.mode = NPMODE_PASS;
if (ioctl(ipcp->ppp->unit_fd, PPPIOCSNPMODE, &np))
- log_error("\nipcp: failed to set NP mode: %s\n", strerror(errno));
+ log_ppp_error("ipcp: failed to set NP mode: %s\n", strerror(errno));
return IPCP_OPT_ACK;
}
diff --git a/accel-pptpd/ppp/lcp_opt_magic.c b/accel-pptpd/ppp/lcp_opt_magic.c
index dc94ac62..d6094c0c 100644
--- a/accel-pptpd/ppp/lcp_opt_magic.c
+++ b/accel-pptpd/ppp/lcp_opt_magic.c
@@ -64,7 +64,7 @@ static int magic_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt,
if (magic_opt->magic==ntohl(opt32->val))
{
- log_error("loop detected");
+ log_ppp_error("loop detected");
return -1;
}
return LCP_OPT_ACK;
diff --git a/accel-pptpd/ppp/lcp_opt_mru.c b/accel-pptpd/ppp/lcp_opt_mru.c
index e1c13b47..fc79db38 100644
--- a/accel-pptpd/ppp/lcp_opt_mru.c
+++ b/accel-pptpd/ppp/lcp_opt_mru.c
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <stdio.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <linux/if_ppp.h>
@@ -96,13 +97,13 @@ static int mru_recv_conf_ack(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui
.ifr_mtu = mru_opt->mtu,
};
- sprintf(ifr.ifr_name,"ppp%i",lcp->ppp->unit_idx);
+ strcpy(ifr.ifr_name, lcp->ppp->ifname);
if (ioctl(lcp->ppp->unit_fd, PPPIOCSMRU, &mru_opt->mru))
- log_error("\nlcp:mru: failed to set MRU: %s\n", strerror(errno));
+ log_ppp_error("lcp:mru: failed to set MRU: %s\n", strerror(errno));
if (ioctl(sock_fd, SIOCSIFMTU, &ifr))
- log_error("\nlcp:mru: failed to set MTU: %s\n", strerror(errno));
+ log_ppp_error("lcp:mru: failed to set MTU: %s\n", strerror(errno));
return 0;
}
diff --git a/accel-pptpd/ppp/ppp.c b/accel-pptpd/ppp/ppp.c
index 8f385e71..87c8e8e0 100644
--- a/accel-pptpd/ppp/ppp.c
+++ b/accel-pptpd/ppp/ppp.c
@@ -37,11 +37,12 @@ static void init_layers(struct ppp_t *);
static void free_layers(struct ppp_t *);
static void start_first_layer(struct ppp_t *);
-struct ppp_t *init_ppp(void)
+void __export ppp_init(struct ppp_t *ppp)
{
- struct ppp_t *ppp=malloc(sizeof(*ppp));
memset(ppp,0,sizeof(*ppp));
- return ppp;
+ INIT_LIST_HEAD(&ppp->chan_handlers);
+ INIT_LIST_HEAD(&ppp->unit_handlers);
+ INIT_LIST_HEAD(&ppp->pd_list);
}
static void free_ppp(struct ppp_t *ppp)
@@ -77,70 +78,67 @@ int __export establish_ppp(struct ppp_t *ppp)
/* Open an instance of /dev/ppp and connect the channel to it */
if (ioctl(ppp->fd, PPPIOCGCHAN, &ppp->chan_idx)==-1)
{
- log_error("Couldn't get channel number\n");
+ log_ppp_error("Couldn't get channel number\n");
return -1;
}
ppp->chan_fd=open("/dev/ppp", O_RDWR);
if (ppp->chan_fd<0)
{
- log_error("Couldn't reopen /dev/ppp\n");
+ log_ppp_error("Couldn't reopen /dev/ppp\n");
return -1;
}
if (ioctl(ppp->chan_fd, PPPIOCATTCHAN, &ppp->chan_idx)<0)
{
- log_error("Couldn't attach to channel %d\n", ppp->chan_idx);
+ log_ppp_error("Couldn't attach to channel %d\n", ppp->chan_idx);
goto exit_close_chan;
}
ppp->unit_fd=open("/dev/ppp", O_RDWR);
if (ppp->unit_fd<0)
{
- log_error("Couldn't reopen /dev/ppp\n");
+ log_ppp_error("Couldn't reopen /dev/ppp\n");
goto exit_close_chan;
}
ppp->unit_idx=-1;
if (ioctl(ppp->unit_fd, PPPIOCNEWUNIT, &ppp->unit_idx)<0)
{
- log_error("Couldn't create new ppp unit\n");
+ log_ppp_error("Couldn't create new ppp unit\n");
goto exit_close_unit;
}
if (ioctl(ppp->chan_fd, PPPIOCCONNECT, &ppp->unit_idx)<0)
{
- log_error("Couldn't attach to PPP unit %d\n", ppp->unit_idx);
+ log_ppp_error("Couldn't attach to PPP unit %d\n", ppp->unit_idx);
goto exit_close_unit;
}
ppp->start_time = time(NULL);
generate_sessionid(ppp);
+ sprintf(ppp->ifname, "ppp%i", ppp->unit_idx);
- log_info("connect: ppp%i <--> pptp(%s)\n",ppp->unit_idx,ppp->chan_name);
+ log_ppp_info("connect: ppp%i <--> pptp(%s)\n",ppp->unit_idx,ppp->chan_name);
ppp->chan_buf=malloc(PPP_MRU);
ppp->unit_buf=malloc(PPP_MRU);
- INIT_LIST_HEAD(&ppp->chan_handlers);
- INIT_LIST_HEAD(&ppp->unit_handlers);
- INIT_LIST_HEAD(&ppp->pd_list);
-
init_layers(ppp);
if (list_empty(&ppp->layers))
{
- log_error("no layers to start\n");
+ log_ppp_error("no layers to start\n");
goto exit_close_unit;
}
if (fcntl(ppp->chan_fd, F_SETFL, O_NONBLOCK)) {
- log_error("ppp: cann't to set nonblocking mode: %s\n", strerror(errno));
+ log_ppp_error("ppp: cann't to set nonblocking mode: %s\n", strerror(errno));
goto exit_close_unit;
}
if (fcntl(ppp->unit_fd, F_SETFL, O_NONBLOCK)) {
- log_error("ppp: cann't to set nonblocking mode: %s\n", strerror(errno));
+ log_ppp_error("ppp: cann't to set nonblocking mode: %s\n", strerror(errno));
goto exit_close_unit;
}
@@ -156,7 +154,7 @@ int __export establish_ppp(struct ppp_t *ppp)
triton_md_enable_handler(&ppp->chan_hnd,MD_MODE_READ);
triton_md_enable_handler(&ppp->unit_hnd,MD_MODE_READ);
- log_debug("ppp established\n");
+ log_ppp_debug("ppp established\n");
triton_event_fire(EV_PPP_STARTING, ppp);
start_first_layer(ppp);
@@ -180,6 +178,7 @@ static void destablish_ppp(struct ppp_t *ppp)
close(ppp->unit_fd);
close(ppp->chan_fd);
+ close(ppp->fd);
ppp->unit_fd = -1;
ppp->chan_fd = -1;
@@ -189,7 +188,7 @@ static void destablish_ppp(struct ppp_t *ppp)
free_layers(ppp);
- log_debug("ppp destablished\n");
+ log_ppp_debug("ppp destablished\n");
triton_event_fire(EV_PPP_FINISHED, ppp);
ppp->ctrl->finished(ppp);
@@ -212,7 +211,7 @@ int __export ppp_chan_send(struct ppp_t *ppp, void *data, int size)
n=write(ppp->chan_fd,data,size);
if (n<size)
- log_error("ppp_chan_send: short write %i, excpected %i\n",n,size);
+ log_ppp_error("ppp_chan_send: short write %i, excpected %i\n",n,size);
return n;
}
@@ -225,7 +224,7 @@ int __export ppp_unit_send(struct ppp_t *ppp, void *data, int size)
n=write(ppp->unit_fd,data,size);
if (n<size)
- log_error("ppp_unit_send: short write %i, excpected %i\n",n,size);
+ log_ppp_error("ppp_unit_send: short write %i, excpected %i\n",n,size);
return n;
}
@@ -243,7 +242,7 @@ cont:
continue;
if (errno == EAGAIN)
return 0;
- log_error("ppp_chan_read: %s\n",strerror(errno));
+ log_ppp_error("ppp_chan_read: %s\n",strerror(errno));
return 0;
}
@@ -251,7 +250,7 @@ cont:
//print_buf(ppp->chan_buf,ppp->chan_buf_size);
if (ppp->chan_buf_size < 2) {
- log_error("ppp_chan_read: short read %i\n", ppp->chan_buf_size);
+ log_ppp_error("ppp_chan_read: short read %i\n", ppp->chan_buf_size);
continue;
}
@@ -267,7 +266,7 @@ cont:
}
}
- log_warn("ppp_chan_read: discarding unknown packet %x\n", proto);
+ log_ppp_warn("ppp_chan_read: discarding unknown packet %x\n", proto);
}
}
@@ -285,7 +284,7 @@ cont:
continue;
if (errno == EAGAIN)
return 0;
- log_error("ppp_chan_read: %s\n",strerror(errno));
+ log_ppp_error("ppp_chan_read: %s\n",strerror(errno));
return 0;
}
@@ -293,7 +292,7 @@ cont:
//print_buf(ppp->unit_buf,ppp->unit_buf_size);
if (ppp->unit_buf_size < 2) {
- log_error("ppp_chan_read: short read %i\n", ppp->unit_buf_size);
+ log_ppp_error("ppp_chan_read: short read %i\n", ppp->unit_buf_size);
continue;
}
@@ -309,7 +308,7 @@ cont:
}
}
- log_warn("ppp_unit_read: discarding unknown packet %x\n",proto);
+ log_ppp_warn("ppp_unit_read: discarding unknown packet %x\n",proto);
}
}
@@ -365,7 +364,7 @@ void __export ppp_terminate(struct ppp_t *ppp, int hard)
struct ppp_layer_data_t *d;
int s = 0;
- log_debug("ppp_terminate\n");
+ log_ppp_debug("ppp_terminate\n");
triton_event_fire(EV_PPP_FINISHING, ppp);
@@ -523,7 +522,7 @@ struct ppp_layer_data_t *ppp_find_layer_data(struct ppp_t *ppp, struct ppp_layer
return NULL;
}
-static void __init ppp_init(void)
+static void __init init(void)
{
char *opt;
@@ -537,3 +536,4 @@ static void __init ppp_init(void)
if (opt && atoi(opt) > 0)
conf_ppp_verbose = 1;
}
+
diff --git a/accel-pptpd/ppp/ppp.h b/accel-pptpd/ppp/ppp.h
index ce6854a3..76b379f4 100644
--- a/accel-pptpd/ppp/ppp.h
+++ b/accel-pptpd/ppp/ppp.h
@@ -43,6 +43,7 @@
#define PPP_LAYER_IPCP 4
#define PPP_SESSIONID_LEN 32
+#define PPP_IFNAME_LEN 10
struct ppp_t;
@@ -71,6 +72,7 @@ struct ppp_t
int unit_idx;
char *chan_name;
+ char ifname[PPP_IFNAME_LEN];
char sessionid[PPP_SESSIONID_LEN+1];
time_t start_time;
char *username;
@@ -122,6 +124,7 @@ struct ppp_handler_t
};
struct ppp_t *alloc_ppp(void);
+void ppp_init(struct ppp_t *ppp);
int establish_ppp(struct ppp_t *ppp);
int ppp_chan_send(struct ppp_t *ppp, void *data, int size);
int ppp_unit_send(struct ppp_t *ppp, void *data, int size);
diff --git a/accel-pptpd/ppp/ppp_auth.c b/accel-pptpd/ppp/ppp_auth.c
index 0a6630be..5ad7444e 100644
--- a/accel-pptpd/ppp/ppp_auth.c
+++ b/accel-pptpd/ppp/ppp_auth.c
@@ -160,7 +160,7 @@ static int auth_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, u
}
}
- log_msg("cann't negotiate authentication type\n");
+ log_ppp_msg("cann't negotiate authentication type\n");
return LCP_OPT_FAIL;
}
@@ -180,7 +180,7 @@ static int auth_recv_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, u
if (!auth_opt->auth)
{
- log_error("auth: unexcepcted configure-nak\n");
+ log_ppp_error("auth: unexcepcted configure-nak\n");
return -1;
}
auth_opt->auth->state=LCP_OPT_NAK;
@@ -193,7 +193,7 @@ static int auth_recv_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, u
return 0;
}
- log_msg("cann't negotiate authentication type\n");
+ log_ppp_msg("cann't negotiate authentication type\n");
return -1;
}
@@ -204,7 +204,7 @@ static int auth_recv_conf_rej(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, u
if (!auth_opt->auth)
{
- log_error("auth: unexcepcted configure-reject\n");
+ log_ppp_error("auth: unexcepcted configure-reject\n");
return -1;
}
auth_opt->auth->state=LCP_OPT_NAK;
@@ -217,7 +217,7 @@ static int auth_recv_conf_rej(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, u
return 0;
}
- log_msg("cann't negotiate authentication type\n");
+ log_ppp_msg("cann't negotiate authentication type\n");
return -1;
}
@@ -249,7 +249,7 @@ static struct ppp_layer_data_t *auth_layer_init(struct ppp_t *ppp)
{
struct auth_layer_data_t *ad=(struct auth_layer_data_t*)malloc(sizeof(*ad));
- log_debug("auth_layer_init\n");
+ log_ppp_debug("auth_layer_init\n");
memset(ad,0,sizeof(*ad));
@@ -262,13 +262,13 @@ static int auth_layer_start(struct ppp_layer_data_t *ld)
{
struct auth_layer_data_t *ad=container_of(ld,typeof(*ad),ld);
- log_debug("auth_layer_start\n");
+ log_ppp_debug("auth_layer_start\n");
if (ad->auth_opt.auth)
ad->auth_opt.auth->h->start(ad->ppp,ad->auth_opt.auth);
else
{
- log_debug("auth_layer_started\n");
+ log_ppp_debug("auth_layer_started\n");
ppp_layer_started(ad->ppp,ld);
}
@@ -279,12 +279,12 @@ static void auth_layer_finish(struct ppp_layer_data_t *ld)
{
struct auth_layer_data_t *ad=container_of(ld,typeof(*ad),ld);
- log_debug("auth_layer_finish\n");
+ log_ppp_debug("auth_layer_finish\n");
if (ad->auth_opt.auth)
ad->auth_opt.auth->h->finish(ad->ppp,ad->auth_opt.auth);
- log_debug("auth_layer_finished\n");
+ log_ppp_debug("auth_layer_finished\n");
ppp_layer_finished(ad->ppp,ld);
}
@@ -292,7 +292,7 @@ static void auth_layer_free(struct ppp_layer_data_t *ld)
{
struct auth_layer_data_t *ad=container_of(ld,typeof(*ad),ld);
- log_debug("auth_layer_free\n");
+ log_ppp_debug("auth_layer_free\n");
free(ad);
}
@@ -300,7 +300,7 @@ static void auth_layer_free(struct ppp_layer_data_t *ld)
void __export auth_successed(struct ppp_t *ppp, char *username)
{
struct auth_layer_data_t *ad=container_of(ppp_find_layer_data(ppp,&auth_layer),typeof(*ad),ld);
- log_debug("auth_layer_started\n");
+ log_ppp_debug("auth_layer_started\n");
ppp->username = username;
triton_event_fire(EV_PPP_AUTHORIZED, ppp);
ppp_layer_started(ppp,&ad->ld);
diff --git a/accel-pptpd/ppp/ppp_ccp.c b/accel-pptpd/ppp/ppp_ccp.c
index f895da9b..8f240bc9 100644
--- a/accel-pptpd/ppp/ppp_ccp.c
+++ b/accel-pptpd/ppp/ppp_ccp.c
@@ -35,8 +35,6 @@ static void ccp_options_init(struct ppp_ccp_t *ccp)
struct ccp_option_t *lopt;
struct ccp_option_handler_t *h;
- INIT_LIST_HEAD(&ccp->options);
-
list_for_each_entry(h,&option_handlers,entry)
{
lopt=h->init(ccp);
@@ -66,7 +64,7 @@ static struct ppp_layer_data_t *ccp_layer_init(struct ppp_t *ppp)
struct ppp_ccp_t *ccp=malloc(sizeof(*ccp));
memset(ccp,0,sizeof(*ccp));
- log_debug("ccp_layer_init\n");
+ log_ppp_debug("ccp_layer_init\n");
ccp->ppp=ppp;
ccp->fsm.ppp=ppp;
@@ -85,6 +83,7 @@ static struct ppp_layer_data_t *ccp_layer_init(struct ppp_t *ppp)
ccp->fsm.send_conf_nak=send_conf_nak;
ccp->fsm.send_conf_rej=send_conf_rej;
+ INIT_LIST_HEAD(&ccp->options);
INIT_LIST_HEAD(&ccp->ropt_list);
return &ccp->ld;
@@ -94,7 +93,7 @@ int ccp_layer_start(struct ppp_layer_data_t *ld)
{
struct ppp_ccp_t *ccp=container_of(ld,typeof(*ccp),ld);
- log_debug("ccp_layer_start\n");
+ log_ppp_debug("ccp_layer_start\n");
ccp_options_init(ccp);
ppp_fsm_lower_up(&ccp->fsm);
@@ -108,7 +107,7 @@ void ccp_layer_finish(struct ppp_layer_data_t *ld)
{
struct ppp_ccp_t *ccp=container_of(ld,typeof(*ccp),ld);
- log_debug("ccp_layer_finish\n");
+ log_ppp_debug("ccp_layer_finish\n");
ccp->fsm.fsm_state = FSM_Closed;
ppp_layer_finished(ccp->ppp,&ccp->ld);
@@ -118,7 +117,7 @@ void ccp_layer_free(struct ppp_layer_data_t *ld)
{
struct ppp_ccp_t *ccp=container_of(ld,typeof(*ccp),ld);
- log_debug("ccp_layer_free\n");
+ log_ppp_debug("ccp_layer_free\n");
ppp_unregister_handler(ccp->ppp,&ccp->hnd);
ccp_options_free(ccp);
@@ -130,14 +129,14 @@ void ccp_layer_free(struct ppp_layer_data_t *ld)
static void ccp_layer_up(struct ppp_fsm_t *fsm)
{
struct ppp_ccp_t *ccp=container_of(fsm,typeof(*ccp),fsm);
- log_debug("ccp_layer_started\n");
+ log_ppp_debug("ccp_layer_started\n");
ppp_layer_started(ccp->ppp,&ccp->ld);
}
static void ccp_layer_down(struct ppp_fsm_t *fsm)
{
struct ppp_ccp_t *ccp=container_of(fsm,typeof(*ccp),fsm);
- log_debug("ccp_layer_finished\n");
+ log_ppp_debug("ccp_layer_finished\n");
ppp_layer_finished(ccp->ppp,&ccp->ld);
}
@@ -146,12 +145,12 @@ static void print_ropt(struct recv_opt_t *ropt)
int i;
uint8_t *ptr=(uint8_t*)ropt->hdr;
- log_debug(" <");
+ log_ppp_debug(" <");
for(i=0; i<ropt->len; i++)
{
- log_debug(" %x",ptr[i]);
+ log_ppp_debug(" %x",ptr[i]);
}
- log_debug(" >");
+ log_ppp_debug(" >");
}
static int send_conf_req(struct ppp_fsm_t *fsm)
@@ -162,12 +161,12 @@ static int send_conf_req(struct ppp_fsm_t *fsm)
struct ccp_option_t *lopt;
int n;
- log_debug("send [CCP ConfReq");
+ log_ppp_debug("send [CCP ConfReq");
ccp_hdr->proto=htons(PPP_CCP);
ccp_hdr->code=CONFREQ;
ccp_hdr->id=++ccp->fsm.id;
ccp_hdr->len=0;
- log_debug(" id=%x",ccp_hdr->id);
+ log_ppp_debug(" id=%x",ccp_hdr->id);
ptr+=sizeof(*ccp_hdr);
@@ -178,13 +177,13 @@ static int send_conf_req(struct ppp_fsm_t *fsm)
return -1;
if (n)
{
- log_debug(" ");
- lopt->h->print(log_debug,lopt,NULL);
+ log_ppp_debug(" ");
+ lopt->h->print(log_ppp_debug,lopt,NULL);
ptr+=n;
}
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
ccp_hdr->len=htons((ptr-buf)-2);
ppp_unit_send(ccp->ppp,ccp_hdr,ptr-buf);
@@ -198,7 +197,7 @@ static void send_conf_ack(struct ppp_fsm_t *fsm)
struct ccp_hdr_t *hdr=(struct ccp_hdr_t*)ccp->ppp->unit_buf;
hdr->code=CONFACK;
- log_debug("send [CCP ConfAck id=%x ]\n",ccp->fsm.recv_id);
+ log_ppp_debug("send [CCP ConfAck id=%x ]\n",ccp->fsm.recv_id);
ppp_unit_send(ccp->ppp,hdr,ntohs(hdr->len)+2);
}
@@ -210,7 +209,7 @@ static void send_conf_nak(struct ppp_fsm_t *fsm)
struct ccp_hdr_t *ccp_hdr=(struct ccp_hdr_t*)ptr;
struct recv_opt_t *ropt;
- log_debug("send [CCP ConfNak id=%x",ccp->fsm.recv_id);
+ log_ppp_debug("send [CCP ConfNak id=%x",ccp->fsm.recv_id);
ccp_hdr->proto=htons(PPP_CCP);
ccp_hdr->code=CONFNAK;
@@ -223,13 +222,13 @@ static void send_conf_nak(struct ppp_fsm_t *fsm)
{
if (ropt->state==CCP_OPT_NAK)
{
- log_debug(" ");
- ropt->lopt->h->print(log_debug,ropt->lopt,NULL);
+ log_ppp_debug(" ");
+ ropt->lopt->h->print(log_ppp_debug,ropt->lopt,NULL);
ptr+=ropt->lopt->h->send_conf_nak(ccp,ropt->lopt,ptr);
}
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
ccp_hdr->len=htons((ptr-buf)-2);
ppp_unit_send(ccp->ppp,ccp_hdr,ptr-buf);
@@ -242,7 +241,7 @@ static void send_conf_rej(struct ppp_fsm_t *fsm)
struct ccp_hdr_t *ccp_hdr=(struct ccp_hdr_t*)ptr;
struct recv_opt_t *ropt;
- log_debug("send [CCP ConfRej id=%x ",ccp->fsm.recv_id);
+ log_ppp_debug("send [CCP ConfRej id=%x ",ccp->fsm.recv_id);
ccp_hdr->proto=htons(PPP_CCP);
ccp_hdr->code=CONFREJ;
@@ -255,15 +254,15 @@ static void send_conf_rej(struct ppp_fsm_t *fsm)
{
if (ropt->state==CCP_OPT_REJ)
{
- log_debug(" ");
- if (ropt->lopt) ropt->lopt->h->print(log_debug,ropt->lopt,(uint8_t*)ropt->hdr);
+ log_ppp_debug(" ");
+ if (ropt->lopt) ropt->lopt->h->print(log_ppp_debug,ropt->lopt,(uint8_t*)ropt->hdr);
else print_ropt(ropt);
memcpy(ptr,ropt->hdr,ropt->len);
ptr+=ropt->len;
}
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
ccp_hdr->len=htons((ptr-buf)-2);
ppp_unit_send(ccp->ppp,ccp_hdr,ptr-buf);
@@ -297,15 +296,15 @@ static int ccp_recv_conf_req(struct ppp_ccp_t *ccp,uint8_t *data,int size)
list_for_each_entry(lopt,&ccp->options,entry)
lopt->state=CCP_OPT_NONE;
- log_debug("recv [CCP ConfReq id=%x",ccp->fsm.recv_id);
+ log_ppp_debug("recv [CCP ConfReq id=%x",ccp->fsm.recv_id);
list_for_each_entry(ropt,&ccp->ropt_list,entry)
{
list_for_each_entry(lopt,&ccp->options,entry)
{
if (lopt->id==ropt->hdr->id)
{
- log_debug(" ");
- lopt->h->print(log_debug,lopt,(uint8_t*)ropt->hdr);
+ log_ppp_debug(" ");
+ lopt->h->print(log_ppp_debug,lopt,(uint8_t*)ropt->hdr);
r=lopt->h->recv_conf_req(ccp,lopt,(uint8_t*)ropt->hdr);
if (ack)
{
@@ -325,13 +324,13 @@ static int ccp_recv_conf_req(struct ppp_ccp_t *ccp,uint8_t *data,int size)
ack=1;
else if (!ropt->lopt)
{
- log_debug(" ");
+ log_ppp_debug(" ");
print_ropt(ropt);
ropt->state=CCP_OPT_REJ;
ret=CCP_OPT_REJ;
}
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
/*list_for_each_entry(lopt,&ccp->options,entry)
{
@@ -364,11 +363,11 @@ static int ccp_recv_conf_rej(struct ppp_ccp_t *ccp,uint8_t *data,int size)
struct ccp_option_t *lopt;
int res=0;
- log_debug("recv [CCP ConfRej id=%x",ccp->fsm.recv_id);
+ log_ppp_debug("recv [CCP ConfRej id=%x",ccp->fsm.recv_id);
if (ccp->fsm.recv_id!=ccp->fsm.id)
{
- log_debug(": id mismatch ]\n");
+ log_ppp_debug(": id mismatch ]\n");
return 0;
}
@@ -391,7 +390,7 @@ static int ccp_recv_conf_rej(struct ppp_ccp_t *ccp,uint8_t *data,int size)
data+=hdr->len;
size-=hdr->len;
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
return res;
}
@@ -401,11 +400,11 @@ static int ccp_recv_conf_nak(struct ppp_ccp_t *ccp,uint8_t *data,int size)
struct ccp_option_t *lopt;
int res=0;
- log_debug("recv [CCP ConfNak id=%x",ccp->fsm.recv_id);
+ log_ppp_debug("recv [CCP ConfNak id=%x",ccp->fsm.recv_id);
if (ccp->fsm.recv_id!=ccp->fsm.id)
{
- log_debug(": id mismatch ]\n");
+ log_ppp_debug(": id mismatch ]\n");
return 0;
}
@@ -417,8 +416,8 @@ static int ccp_recv_conf_nak(struct ppp_ccp_t *ccp,uint8_t *data,int size)
{
if (lopt->id==hdr->id)
{
- log_debug(" ");
- lopt->h->print(log_debug,lopt,data);
+ log_ppp_debug(" ");
+ lopt->h->print(log_ppp_debug,lopt,data);
if (lopt->h->recv_conf_nak(ccp,lopt,data))
res=-1;
break;
@@ -428,7 +427,7 @@ static int ccp_recv_conf_nak(struct ppp_ccp_t *ccp,uint8_t *data,int size)
data+=hdr->len;
size-=hdr->len;
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
return res;
}
@@ -438,11 +437,11 @@ static int ccp_recv_conf_ack(struct ppp_ccp_t *ccp,uint8_t *data,int size)
struct ccp_option_t *lopt;
int res=0;
- log_debug("recv [CCP ConfAck id=%x",ccp->fsm.recv_id);
+ log_ppp_debug("recv [CCP ConfAck id=%x",ccp->fsm.recv_id);
if (ccp->fsm.recv_id!=ccp->fsm.id)
{
- log_debug(": id mismatch ]\n");
+ log_ppp_debug(": id mismatch ]\n");
return 0;
}
@@ -454,8 +453,8 @@ static int ccp_recv_conf_ack(struct ppp_ccp_t *ccp,uint8_t *data,int size)
{
if (lopt->id==hdr->id)
{
- log_debug(" ");
- lopt->h->print(log_debug,lopt,data);
+ log_ppp_debug(" ");
+ lopt->h->print(log_ppp_debug,lopt,data);
if (!lopt->h->recv_conf_ack)
break;
if (lopt->h->recv_conf_ack(ccp,lopt,data))
@@ -467,7 +466,7 @@ static int ccp_recv_conf_ack(struct ppp_ccp_t *ccp,uint8_t *data,int size)
data+=hdr->len;
size-=hdr->len;
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
return res;
}
@@ -480,20 +479,20 @@ static void ccp_recv(struct ppp_handler_t*h)
if (ccp->fsm.fsm_state==FSM_Initial || ccp->fsm.fsm_state==FSM_Closed)
{
- log_warn("CCP: discaring packet\n");
+ log_ppp_warn("CCP: discaring packet\n");
return;
}
if (ccp->ppp->unit_buf_size<PPP_HEADERLEN+2)
{
- log_warn("CCP: short packet received\n");
+ log_ppp_warn("CCP: short packet received\n");
return;
}
hdr=(struct ccp_hdr_t *)ccp->ppp->unit_buf;
if (ntohs(hdr->len)<PPP_HEADERLEN)
{
- log_warn("CCP: short packet received\n");
+ log_ppp_warn("CCP: short packet received\n");
return;
}
@@ -536,19 +535,19 @@ static void ccp_recv(struct ppp_handler_t*h)
break;
case TERMREQ:
term_msg=strndup((char*)(hdr+1),ntohs(hdr->len));
- log_debug("recv [CCP TermReq id=%x \"%s\"]\n",hdr->id,term_msg);
+ log_ppp_debug("recv [CCP TermReq id=%x \"%s\"]\n",hdr->id,term_msg);
free(term_msg);
ppp_fsm_recv_term_req(&ccp->fsm);
ppp_terminate(ccp->ppp, 0);
break;
case TERMACK:
term_msg=strndup((char*)(hdr+1),ntohs(hdr->len));
- log_debug("recv [CCP TermAck id=%x \"%s\"]\n",hdr->id,term_msg);
+ log_ppp_debug("recv [CCP TermAck id=%x \"%s\"]\n",hdr->id,term_msg);
free(term_msg);
ppp_fsm_recv_term_ack(&ccp->fsm);
break;
case CODEREJ:
- log_debug("recv [CCP CodeRej id=%x]\n",hdr->id);
+ log_ppp_debug("recv [CCP CodeRej id=%x]\n",hdr->id);
ppp_fsm_recv_code_rej_bad(&ccp->fsm);
break;
default:
diff --git a/accel-pptpd/ppp/ppp_fsm.c b/accel-pptpd/ppp/ppp_fsm.c
index a99453f0..20fe8fff 100644
--- a/accel-pptpd/ppp/ppp_fsm.c
+++ b/accel-pptpd/ppp/ppp_fsm.c
@@ -466,7 +466,7 @@ void send_term_req(struct ppp_fsm_t *layer)
.len = htons(4),
};
- log_debug("send [LCP TermReq id=%i \"\"]\n",hdr.id);
+ log_ppp_debug("send [LCP TermReq id=%i \"\"]\n",hdr.id);
--layer->restart_counter;
ppp_chan_send(layer->ppp, &hdr, 6);
@@ -480,27 +480,23 @@ void send_term_ack(struct ppp_fsm_t *layer)
.len = htons(4),
};
- log_debug("send [LCP TermAck id=%i \"\"]\n", hdr.id);
+ log_ppp_debug("send [LCP TermAck id=%i \"\"]\n", hdr.id);
ppp_chan_send(layer->ppp, &hdr, 6);
}
static void stop_timer(struct ppp_fsm_t *fsm)
{
- if (fsm->restart_timer.period) {
- fsm->restart_timer.period = 0;
+ if (fsm->restart_timer.tpd)
triton_timer_del(&fsm->restart_timer);
- }
}
static void init_req_counter(struct ppp_fsm_t *layer,int timeout)
{
layer->restart_timer.expire_tv.tv_sec=0;
layer->restart_counter = timeout;
- if (!layer->restart_timer.period) {
- layer->restart_timer.period = layer->timeout * 1000;
+ if (!layer->restart_timer.tpd)
triton_timer_add(layer->ppp->ctrl->ctx, &layer->restart_timer, 0);
- }
}
static void zero_req_counter(struct ppp_fsm_t *layer)
{
diff --git a/accel-pptpd/ppp/ppp_ipcp.c b/accel-pptpd/ppp/ppp_ipcp.c
index bb6369e0..b8dfe7f7 100644
--- a/accel-pptpd/ppp/ppp_ipcp.c
+++ b/accel-pptpd/ppp/ppp_ipcp.c
@@ -35,8 +35,6 @@ static void ipcp_options_init(struct ppp_ipcp_t *ipcp)
struct ipcp_option_t *lopt;
struct ipcp_option_handler_t *h;
- INIT_LIST_HEAD(&ipcp->options);
-
list_for_each_entry(h,&option_handlers,entry)
{
lopt=h->init(ipcp);
@@ -66,7 +64,7 @@ static struct ppp_layer_data_t *ipcp_layer_init(struct ppp_t *ppp)
struct ppp_ipcp_t *ipcp=malloc(sizeof(*ipcp));
memset(ipcp,0,sizeof(*ipcp));
- log_debug("ipcp_layer_init\n");
+ log_ppp_debug("ipcp_layer_init\n");
ipcp->ppp=ppp;
ipcp->fsm.ppp=ppp;
@@ -85,6 +83,7 @@ static struct ppp_layer_data_t *ipcp_layer_init(struct ppp_t *ppp)
ipcp->fsm.send_conf_nak=send_conf_nak;
ipcp->fsm.send_conf_rej=send_conf_rej;
+ INIT_LIST_HEAD(&ipcp->options);
INIT_LIST_HEAD(&ipcp->ropt_list);
return &ipcp->ld;
@@ -94,7 +93,7 @@ int ipcp_layer_start(struct ppp_layer_data_t *ld)
{
struct ppp_ipcp_t *ipcp=container_of(ld,typeof(*ipcp),ld);
- log_debug("ipcp_layer_start\n");
+ log_ppp_debug("ipcp_layer_start\n");
ipcp_options_init(ipcp);
ppp_fsm_lower_up(&ipcp->fsm);
@@ -108,7 +107,7 @@ void ipcp_layer_finish(struct ppp_layer_data_t *ld)
{
struct ppp_ipcp_t *ipcp=container_of(ld,typeof(*ipcp),ld);
- log_debug("ipcp_layer_finish\n");
+ log_ppp_debug("ipcp_layer_finish\n");
ipcp->fsm.fsm_state = FSM_Closed;
ppp_layer_finished(ipcp->ppp,&ipcp->ld);
@@ -118,7 +117,7 @@ void ipcp_layer_free(struct ppp_layer_data_t *ld)
{
struct ppp_ipcp_t *ipcp=container_of(ld,typeof(*ipcp),ld);
- log_debug("ipcp_layer_free\n");
+ log_ppp_debug("ipcp_layer_free\n");
ppp_unregister_handler(ipcp->ppp,&ipcp->hnd);
ipcp_options_free(ipcp);
@@ -130,14 +129,14 @@ void ipcp_layer_free(struct ppp_layer_data_t *ld)
static void ipcp_layer_up(struct ppp_fsm_t *fsm)
{
struct ppp_ipcp_t *ipcp=container_of(fsm,typeof(*ipcp),fsm);
- log_debug("ipcp_layer_started\n");
+ log_ppp_debug("ipcp_layer_started\n");
ppp_layer_started(ipcp->ppp,&ipcp->ld);
}
static void ipcp_layer_down(struct ppp_fsm_t *fsm)
{
struct ppp_ipcp_t *ipcp=container_of(fsm,typeof(*ipcp),fsm);
- log_debug("ipcp_layer_finished\n");
+ log_ppp_debug("ipcp_layer_finished\n");
ppp_layer_finished(ipcp->ppp,&ipcp->ld);
}
@@ -146,12 +145,12 @@ static void print_ropt(struct recv_opt_t *ropt)
int i;
uint8_t *ptr=(uint8_t*)ropt->hdr;
- log_debug(" <");
+ log_ppp_debug(" <");
for(i=0; i<ropt->len; i++)
{
- log_debug(" %x",ptr[i]);
+ log_ppp_debug(" %x",ptr[i]);
}
- log_debug(" >");
+ log_ppp_debug(" >");
}
static int send_conf_req(struct ppp_fsm_t *fsm)
@@ -182,14 +181,14 @@ static int send_conf_req(struct ppp_fsm_t *fsm)
}
if (conf_ppp_verbose) {
- log_debug("send [IPCP ConfReq id=%x", ipcp_hdr->id);
+ log_ppp_debug("send [IPCP ConfReq id=%x", ipcp_hdr->id);
list_for_each_entry(lopt,&ipcp->options,entry){
if (lopt->print) {
- log_debug(" ");
- lopt->h->print(log_debug,lopt,NULL);
+ log_ppp_debug(" ");
+ lopt->h->print(log_ppp_debug,lopt,NULL);
}
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
}
ipcp_hdr->len=htons((ptr-buf)-2);
@@ -204,7 +203,7 @@ static void send_conf_ack(struct ppp_fsm_t *fsm)
struct ipcp_hdr_t *hdr=(struct ipcp_hdr_t*)ipcp->ppp->unit_buf;
hdr->code=CONFACK;
- log_debug("send [IPCP ConfAck id=%x ]\n",ipcp->fsm.recv_id);
+ log_ppp_debug("send [IPCP ConfAck id=%x ]\n",ipcp->fsm.recv_id);
ppp_unit_send(ipcp->ppp,hdr,ntohs(hdr->len)+2);
}
@@ -216,7 +215,7 @@ static void send_conf_nak(struct ppp_fsm_t *fsm)
struct ipcp_hdr_t *ipcp_hdr=(struct ipcp_hdr_t*)ptr;
struct recv_opt_t *ropt;
- log_debug("send [IPCP ConfNak id=%x",ipcp->fsm.recv_id);
+ log_ppp_debug("send [IPCP ConfNak id=%x",ipcp->fsm.recv_id);
ipcp_hdr->proto=htons(PPP_IPCP);
ipcp_hdr->code=CONFNAK;
@@ -229,13 +228,13 @@ static void send_conf_nak(struct ppp_fsm_t *fsm)
{
if (ropt->state==IPCP_OPT_NAK)
{
- log_debug(" ");
- ropt->lopt->h->print(log_debug,ropt->lopt,NULL);
+ log_ppp_debug(" ");
+ ropt->lopt->h->print(log_ppp_debug,ropt->lopt,NULL);
ptr+=ropt->lopt->h->send_conf_nak(ipcp,ropt->lopt,ptr);
}
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
ipcp_hdr->len=htons((ptr-buf)-2);
ppp_unit_send(ipcp->ppp,ipcp_hdr,ptr-buf);
@@ -248,7 +247,7 @@ static void send_conf_rej(struct ppp_fsm_t *fsm)
struct ipcp_hdr_t *ipcp_hdr=(struct ipcp_hdr_t*)ptr;
struct recv_opt_t *ropt;
- log_debug("send [IPCP ConfRej id=%x ",ipcp->fsm.recv_id);
+ log_ppp_debug("send [IPCP ConfRej id=%x ",ipcp->fsm.recv_id);
ipcp_hdr->proto=htons(PPP_IPCP);
ipcp_hdr->code=CONFREJ;
@@ -261,15 +260,15 @@ static void send_conf_rej(struct ppp_fsm_t *fsm)
{
if (ropt->state==IPCP_OPT_REJ)
{
- log_debug(" ");
- if (ropt->lopt) ropt->lopt->h->print(log_debug,ropt->lopt,(uint8_t*)ropt->hdr);
+ log_ppp_debug(" ");
+ if (ropt->lopt) ropt->lopt->h->print(log_ppp_debug,ropt->lopt,(uint8_t*)ropt->hdr);
else print_ropt(ropt);
memcpy(ptr,ropt->hdr,ropt->len);
ptr+=ropt->len;
}
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
ipcp_hdr->len=htons((ptr-buf)-2);
ppp_unit_send(ipcp->ppp,ipcp_hdr,ptr-buf);
@@ -303,15 +302,15 @@ static int ipcp_recv_conf_req(struct ppp_ipcp_t *ipcp,uint8_t *data,int size)
list_for_each_entry(lopt,&ipcp->options,entry)
lopt->state=IPCP_OPT_NONE;
- log_debug("recv [IPCP ConfReq id=%x",ipcp->fsm.recv_id);
+ log_ppp_debug("recv [IPCP ConfReq id=%x",ipcp->fsm.recv_id);
list_for_each_entry(ropt,&ipcp->ropt_list,entry)
{
list_for_each_entry(lopt,&ipcp->options,entry)
{
if (lopt->id==ropt->hdr->id)
{
- log_debug(" ");
- lopt->h->print(log_debug,lopt,(uint8_t*)ropt->hdr);
+ log_ppp_debug(" ");
+ lopt->h->print(log_ppp_debug,lopt,(uint8_t*)ropt->hdr);
r=lopt->h->recv_conf_req(ipcp,lopt,(uint8_t*)ropt->hdr);
lopt->state=r;
ropt->state=r;
@@ -322,13 +321,13 @@ static int ipcp_recv_conf_req(struct ppp_ipcp_t *ipcp,uint8_t *data,int size)
}
if (!ropt->lopt)
{
- log_debug(" ");
+ log_ppp_debug(" ");
print_ropt(ropt);
ropt->state=IPCP_OPT_REJ;
ret=IPCP_OPT_REJ;
}
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
/*list_for_each_entry(lopt,&ipcp->options,entry)
{
@@ -361,11 +360,11 @@ static int ipcp_recv_conf_rej(struct ppp_ipcp_t *ipcp,uint8_t *data,int size)
struct ipcp_option_t *lopt;
int res=0;
- log_debug("recv [IPCP ConfRej id=%x",ipcp->fsm.recv_id);
+ log_ppp_debug("recv [IPCP ConfRej id=%x",ipcp->fsm.recv_id);
if (ipcp->fsm.recv_id!=ipcp->fsm.id)
{
- log_debug(": id mismatch ]\n");
+ log_ppp_debug(": id mismatch ]\n");
return 0;
}
@@ -388,7 +387,7 @@ static int ipcp_recv_conf_rej(struct ppp_ipcp_t *ipcp,uint8_t *data,int size)
data+=hdr->len;
size-=hdr->len;
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
return res;
}
@@ -398,11 +397,11 @@ static int ipcp_recv_conf_nak(struct ppp_ipcp_t *ipcp,uint8_t *data,int size)
struct ipcp_option_t *lopt;
int res=0;
- log_debug("recv [IPCP ConfNak id=%x",ipcp->fsm.recv_id);
+ log_ppp_debug("recv [IPCP ConfNak id=%x",ipcp->fsm.recv_id);
if (ipcp->fsm.recv_id!=ipcp->fsm.id)
{
- log_debug(": id mismatch ]\n");
+ log_ppp_debug(": id mismatch ]\n");
return 0;
}
@@ -414,8 +413,8 @@ static int ipcp_recv_conf_nak(struct ppp_ipcp_t *ipcp,uint8_t *data,int size)
{
if (lopt->id==hdr->id)
{
- log_debug(" ");
- lopt->h->print(log_debug,lopt,data);
+ log_ppp_debug(" ");
+ lopt->h->print(log_ppp_debug,lopt,data);
if (lopt->h->recv_conf_nak(ipcp,lopt,data))
res=-1;
break;
@@ -425,7 +424,7 @@ static int ipcp_recv_conf_nak(struct ppp_ipcp_t *ipcp,uint8_t *data,int size)
data+=hdr->len;
size-=hdr->len;
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
return res;
}
@@ -435,11 +434,11 @@ static int ipcp_recv_conf_ack(struct ppp_ipcp_t *ipcp,uint8_t *data,int size)
struct ipcp_option_t *lopt;
int res=0;
- log_debug("recv [IPCP ConfAck id=%x",ipcp->fsm.recv_id);
+ log_ppp_debug("recv [IPCP ConfAck id=%x",ipcp->fsm.recv_id);
if (ipcp->fsm.recv_id!=ipcp->fsm.id)
{
- log_debug(": id mismatch ]\n");
+ log_ppp_debug(": id mismatch ]\n");
return 0;
}
@@ -451,8 +450,8 @@ static int ipcp_recv_conf_ack(struct ppp_ipcp_t *ipcp,uint8_t *data,int size)
{
if (lopt->id==hdr->id)
{
- log_debug(" ");
- lopt->h->print(log_debug,lopt,data);
+ log_ppp_debug(" ");
+ lopt->h->print(log_ppp_debug,lopt,data);
if (!lopt->h->recv_conf_ack)
break;
if (lopt->h->recv_conf_ack(ipcp,lopt,data))
@@ -464,7 +463,7 @@ static int ipcp_recv_conf_ack(struct ppp_ipcp_t *ipcp,uint8_t *data,int size)
data+=hdr->len;
size-=hdr->len;
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
return res;
}
@@ -477,20 +476,20 @@ static void ipcp_recv(struct ppp_handler_t*h)
if (ipcp->fsm.fsm_state==FSM_Initial || ipcp->fsm.fsm_state==FSM_Closed)
{
- log_warn("IPCP: discaring packet\n");
+ log_ppp_warn("IPCP: discaring packet\n");
return;
}
if (ipcp->ppp->unit_buf_size<PPP_HEADERLEN+2)
{
- log_warn("IPCP: short packet received\n");
+ log_ppp_warn("IPCP: short packet received\n");
return;
}
hdr=(struct ipcp_hdr_t *)ipcp->ppp->unit_buf;
if (ntohs(hdr->len)<PPP_HEADERLEN)
{
- log_warn("IPCP: short packet received\n");
+ log_ppp_warn("IPCP: short packet received\n");
return;
}
@@ -533,19 +532,19 @@ static void ipcp_recv(struct ppp_handler_t*h)
break;
case TERMREQ:
term_msg=strndup((char*)(hdr+1),ntohs(hdr->len));
- log_debug("recv [IPCP TermReq id=%x \"%s\"]\n",hdr->id,term_msg);
+ log_ppp_debug("recv [IPCP TermReq id=%x \"%s\"]\n",hdr->id,term_msg);
free(term_msg);
ppp_fsm_recv_term_req(&ipcp->fsm);
ppp_terminate(ipcp->ppp, 0);
break;
case TERMACK:
term_msg=strndup((char*)(hdr+1),ntohs(hdr->len));
- log_debug("recv [IPCP TermAck id=%x \"%s\"]\n",hdr->id,term_msg);
+ log_ppp_debug("recv [IPCP TermAck id=%x \"%s\"]\n",hdr->id,term_msg);
free(term_msg);
ppp_fsm_recv_term_ack(&ipcp->fsm);
break;
case CODEREJ:
- log_debug("recv [IPCP CodeRej id=%x]\n",hdr->id);
+ log_ppp_debug("recv [IPCP CodeRej id=%x]\n",hdr->id);
ppp_fsm_recv_code_rej_bad(&ipcp->fsm);
break;
default:
diff --git a/accel-pptpd/ppp/ppp_lcp.c b/accel-pptpd/ppp/ppp_lcp.c
index 22e6313d..3b937d6e 100644
--- a/accel-pptpd/ppp/ppp_lcp.c
+++ b/accel-pptpd/ppp/ppp_lcp.c
@@ -71,7 +71,7 @@ static struct ppp_layer_data_t *lcp_layer_init(struct ppp_t *ppp)
struct ppp_lcp_t *lcp=malloc(sizeof(*lcp));
memset(lcp,0,sizeof(*lcp));
- log_debug("lcp_layer_init\n");
+ log_ppp_debug("lcp_layer_init\n");
lcp->ppp=ppp;
lcp->fsm.ppp=ppp;
@@ -99,7 +99,7 @@ int lcp_layer_start(struct ppp_layer_data_t *ld)
{
struct ppp_lcp_t *lcp=container_of(ld,typeof(*lcp),ld);
- log_debug("lcp_layer_start\n");
+ log_ppp_debug("lcp_layer_start\n");
lcp_options_init(lcp);
ppp_fsm_lower_up(&lcp->fsm);
@@ -113,7 +113,7 @@ void lcp_layer_finish(struct ppp_layer_data_t *ld)
{
struct ppp_lcp_t *lcp=container_of(ld,typeof(*lcp),ld);
- log_debug("lcp_layer_finish\n");
+ log_ppp_debug("lcp_layer_finish\n");
stop_echo(lcp);
@@ -124,7 +124,7 @@ void lcp_layer_free(struct ppp_layer_data_t *ld)
{
struct ppp_lcp_t *lcp=container_of(ld,typeof(*lcp),ld);
- log_debug("lcp_layer_free\n");
+ log_ppp_debug("lcp_layer_free\n");
stop_echo(lcp);
ppp_unregister_handler(lcp->ppp,&lcp->hnd);
@@ -137,7 +137,7 @@ void lcp_layer_free(struct ppp_layer_data_t *ld)
static void lcp_layer_up(struct ppp_fsm_t *fsm)
{
struct ppp_lcp_t *lcp=container_of(fsm,typeof(*lcp),fsm);
- log_debug("lcp_layer_started\n");
+ log_ppp_debug("lcp_layer_started\n");
ppp_layer_started(lcp->ppp,&lcp->ld);
start_echo(lcp);
@@ -146,7 +146,7 @@ static void lcp_layer_up(struct ppp_fsm_t *fsm)
static void lcp_layer_down(struct ppp_fsm_t *fsm)
{
struct ppp_lcp_t *lcp=container_of(fsm,typeof(*lcp),fsm);
- log_debug("lcp_layer_finished\n");
+ log_ppp_debug("lcp_layer_finished\n");
stop_echo(lcp);
ppp_layer_finished(lcp->ppp,&lcp->ld);
}
@@ -156,12 +156,12 @@ static void print_ropt(struct recv_opt_t *ropt)
int i;
uint8_t *ptr=(uint8_t*)ropt->hdr;
- log_debug(" <");
+ log_ppp_debug(" <");
for(i=0; i<ropt->len; i++)
{
- log_debug(" %x",ptr[i]);
+ log_ppp_debug(" %x",ptr[i]);
}
- log_debug(" >");
+ log_ppp_debug(" >");
}
static int send_conf_req(struct ppp_fsm_t *fsm)
@@ -193,15 +193,15 @@ static int send_conf_req(struct ppp_fsm_t *fsm)
}
if (conf_ppp_verbose) {
- log_debug("send [LCP ConfReq id=%x", lcp_hdr->id);
+ log_ppp_debug("send [LCP ConfReq id=%x", lcp_hdr->id);
list_for_each_entry(lopt,&lcp->options,entry)
{
if (lopt->print) {
- log_debug(" ");
- lopt->h->print(log_debug,lopt,NULL);
+ log_ppp_debug(" ");
+ lopt->h->print(log_ppp_debug,lopt,NULL);
}
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
}
lcp_hdr->len=htons((ptr-buf)-2);
@@ -216,7 +216,7 @@ static void send_conf_ack(struct ppp_fsm_t *fsm)
struct lcp_hdr_t *hdr=(struct lcp_hdr_t*)lcp->ppp->chan_buf;
hdr->code=CONFACK;
- log_debug("send [LCP ConfAck id=%x ]\n",lcp->fsm.recv_id);
+ log_ppp_debug("send [LCP ConfAck id=%x ]\n",lcp->fsm.recv_id);
ppp_chan_send(lcp->ppp,hdr,ntohs(hdr->len)+2);
}
@@ -228,7 +228,7 @@ static void send_conf_nak(struct ppp_fsm_t *fsm)
struct lcp_hdr_t *lcp_hdr=(struct lcp_hdr_t*)ptr;
struct recv_opt_t *ropt;
- log_debug("send [LCP ConfNak id=%x",lcp->fsm.recv_id);
+ log_ppp_debug("send [LCP ConfNak id=%x",lcp->fsm.recv_id);
lcp_hdr->proto=htons(PPP_LCP);
lcp_hdr->code=CONFNAK;
@@ -241,13 +241,13 @@ static void send_conf_nak(struct ppp_fsm_t *fsm)
{
if (ropt->state==LCP_OPT_NAK)
{
- log_debug(" ");
- ropt->lopt->h->print(log_debug,ropt->lopt,NULL);
+ log_ppp_debug(" ");
+ ropt->lopt->h->print(log_ppp_debug,ropt->lopt,NULL);
ptr+=ropt->lopt->h->send_conf_nak(lcp,ropt->lopt,ptr);
}
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
lcp_hdr->len=htons((ptr-buf)-2);
ppp_chan_send(lcp->ppp,lcp_hdr,ptr-buf);
@@ -260,7 +260,7 @@ static void send_conf_rej(struct ppp_fsm_t *fsm)
struct lcp_hdr_t *lcp_hdr=(struct lcp_hdr_t*)ptr;
struct recv_opt_t *ropt;
- log_debug("send [LCP ConfRej id=%x ",lcp->fsm.recv_id);
+ log_ppp_debug("send [LCP ConfRej id=%x ",lcp->fsm.recv_id);
lcp_hdr->proto=htons(PPP_LCP);
lcp_hdr->code=CONFREJ;
@@ -273,15 +273,15 @@ static void send_conf_rej(struct ppp_fsm_t *fsm)
{
if (ropt->state==LCP_OPT_REJ)
{
- log_debug(" ");
- if (ropt->lopt) ropt->lopt->h->print(log_debug,ropt->lopt,(uint8_t*)ropt->hdr);
+ log_ppp_debug(" ");
+ if (ropt->lopt) ropt->lopt->h->print(log_ppp_debug,ropt->lopt,(uint8_t*)ropt->hdr);
else print_ropt(ropt);
memcpy(ptr,ropt->hdr,ropt->len);
ptr+=ropt->len;
}
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
lcp_hdr->len=htons((ptr-buf)-2);
ppp_chan_send(lcp->ppp,lcp_hdr,ptr-buf);
@@ -314,15 +314,15 @@ static int lcp_recv_conf_req(struct ppp_lcp_t *lcp,uint8_t *data,int size)
list_for_each_entry(lopt,&lcp->options,entry)
lopt->state=LCP_OPT_NONE;
- log_debug("recv [LCP ConfReq id=%x",lcp->fsm.recv_id);
+ log_ppp_debug("recv [LCP ConfReq id=%x",lcp->fsm.recv_id);
list_for_each_entry(ropt,&lcp->ropt_list,entry)
{
list_for_each_entry(lopt,&lcp->options,entry)
{
if (lopt->id==ropt->hdr->id)
{
- log_debug(" ");
- lopt->h->print(log_debug,lopt,(uint8_t*)ropt->hdr);
+ log_ppp_debug(" ");
+ lopt->h->print(log_ppp_debug,lopt,(uint8_t*)ropt->hdr);
r=lopt->h->recv_conf_req(lcp,lopt,(uint8_t*)ropt->hdr);
lopt->state=r;
ropt->state=r;
@@ -333,13 +333,13 @@ static int lcp_recv_conf_req(struct ppp_lcp_t *lcp,uint8_t *data,int size)
}
if (!ropt->lopt)
{
- log_debug(" ");
+ log_ppp_debug(" ");
print_ropt(ropt);
ropt->state=LCP_OPT_REJ;
ret=LCP_OPT_REJ;
}
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
/*list_for_each_entry(lopt,&lcp->options,entry)
{
@@ -372,11 +372,11 @@ static int lcp_recv_conf_rej(struct ppp_lcp_t *lcp,uint8_t *data,int size)
struct lcp_option_t *lopt;
int res=0;
- log_debug("recv [LCP ConfRej id=%x",lcp->fsm.recv_id);
+ log_ppp_debug("recv [LCP ConfRej id=%x",lcp->fsm.recv_id);
if (lcp->fsm.recv_id!=lcp->fsm.id)
{
- log_debug(": id mismatch ]\n");
+ log_ppp_debug(": id mismatch ]\n");
return 0;
}
@@ -399,7 +399,7 @@ static int lcp_recv_conf_rej(struct ppp_lcp_t *lcp,uint8_t *data,int size)
data+=hdr->len;
size-=hdr->len;
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
return res;
}
@@ -409,11 +409,11 @@ static int lcp_recv_conf_nak(struct ppp_lcp_t *lcp,uint8_t *data,int size)
struct lcp_option_t *lopt;
int res=0;
- log_debug("recv [LCP ConfNak id=%x",lcp->fsm.recv_id);
+ log_ppp_debug("recv [LCP ConfNak id=%x",lcp->fsm.recv_id);
if (lcp->fsm.recv_id!=lcp->fsm.id)
{
- log_debug(": id mismatch ]\n");
+ log_ppp_debug(": id mismatch ]\n");
return 0;
}
@@ -425,8 +425,8 @@ static int lcp_recv_conf_nak(struct ppp_lcp_t *lcp,uint8_t *data,int size)
{
if (lopt->id==hdr->id)
{
- log_debug(" ");
- lopt->h->print(log_debug,lopt,data);
+ log_ppp_debug(" ");
+ lopt->h->print(log_ppp_debug,lopt,data);
if (lopt->h->recv_conf_nak(lcp,lopt,data))
res=-1;
break;
@@ -436,7 +436,7 @@ static int lcp_recv_conf_nak(struct ppp_lcp_t *lcp,uint8_t *data,int size)
data+=hdr->len;
size-=hdr->len;
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
return res;
}
@@ -446,11 +446,11 @@ static int lcp_recv_conf_ack(struct ppp_lcp_t *lcp,uint8_t *data,int size)
struct lcp_option_t *lopt;
int res=0;
- log_debug("recv [LCP ConfAck id=%x",lcp->fsm.recv_id);
+ log_ppp_debug("recv [LCP ConfAck id=%x",lcp->fsm.recv_id);
if (lcp->fsm.recv_id!=lcp->fsm.id)
{
- log_debug(": id mismatch ]\n");
+ log_ppp_debug(": id mismatch ]\n");
return 0;
}
@@ -462,8 +462,8 @@ static int lcp_recv_conf_ack(struct ppp_lcp_t *lcp,uint8_t *data,int size)
{
if (lopt->id==hdr->id)
{
- log_debug(" ");
- lopt->h->print(log_debug,lopt,data);
+ log_ppp_debug(" ");
+ lopt->h->print(log_ppp_debug,lopt,data);
if (!lopt->h->recv_conf_ack)
break;
if (lopt->h->recv_conf_ack(lcp,lopt,data))
@@ -475,7 +475,7 @@ static int lcp_recv_conf_ack(struct ppp_lcp_t *lcp,uint8_t *data,int size)
data+=hdr->len;
size-=hdr->len;
}
- log_debug("]\n");
+ log_ppp_debug("]\n");
return res;
}
@@ -484,14 +484,14 @@ static void lcp_recv_echo_repl(struct ppp_lcp_t *lcp,uint8_t *data,int size)
uint32_t magic = *(uint32_t *)data;
if (size != 4) {
- log_error("lcp:echo: magic number size mismatch\n");
+ log_ppp_error("lcp:echo: magic number size mismatch\n");
ppp_terminate(lcp->ppp, 0);
}
- log_debug("recv [LCP EchoRep id=%x <magic %x>]\n",lcp->fsm.recv_id,magic);
+ log_ppp_debug("recv [LCP EchoRep id=%x <magic %x>]\n",lcp->fsm.recv_id,magic);
if (magic == lcp->magic) {
- log_error("lcp:echo: loop-back detected\n");
+ log_ppp_error("lcp:echo: loop-back detected\n");
ppp_terminate(lcp->ppp, 0);
}
@@ -504,7 +504,7 @@ static void send_echo_reply(struct ppp_lcp_t *lcp)
uint32_t magic = *(uint32_t *)(hdr+1);
hdr->code=ECHOREP;
- log_debug("send [LCP EchoRep id=%x <magic %x>]\n", hdr->id, magic);
+ log_ppp_debug("send [LCP EchoRep id=%x <magic %x>]\n", hdr->id, magic);
ppp_chan_send(lcp->ppp,hdr,ntohs(hdr->len)+2);
}
@@ -524,10 +524,10 @@ static void send_echo_request(struct triton_timer_t *t)
};
if (++lcp->echo_sent > lcp->echo_failure) {
- log_warn("lcp: no echo reply\n");
+ log_ppp_warn("lcp: no echo reply\n");
ppp_terminate(lcp->ppp, 0);
} else {
- log_debug("send [LCP EchoReq id=%x <magic %x>]\n", msg.hdr.id, msg.magic);
+ log_ppp_debug("send [LCP EchoReq id=%x <magic %x>]\n", msg.hdr.id, msg.magic);
ppp_chan_send(lcp->ppp,&msg,ntohs(msg.hdr.len)+2);
}
}
@@ -544,10 +544,8 @@ static void start_echo(struct ppp_lcp_t *lcp)
}
static void stop_echo(struct ppp_lcp_t *lcp)
{
- if (lcp->echo_interval) {
+ if (lcp->echo_timer.tpd)
triton_timer_del(&lcp->echo_timer);
- lcp->echo_interval = 0;
- }
}
static void lcp_recv(struct ppp_handler_t*h)
@@ -559,14 +557,14 @@ static void lcp_recv(struct ppp_handler_t*h)
if (lcp->ppp->chan_buf_size<PPP_HEADERLEN+2)
{
- log_warn("LCP: short packet received\n");
+ log_ppp_warn("LCP: short packet received\n");
return;
}
hdr=(struct lcp_hdr_t *)lcp->ppp->chan_buf;
if (ntohs(hdr->len)<PPP_HEADERLEN)
{
- log_warn("LCP: short packet received\n");
+ log_ppp_warn("LCP: short packet received\n");
return;
}
@@ -609,19 +607,19 @@ static void lcp_recv(struct ppp_handler_t*h)
break;
case TERMREQ:
term_msg=strndup((char*)(hdr+1),ntohs(hdr->len));
- log_debug("recv [LCP TermReq id=%x \"%s\"]\n",hdr->id,term_msg);
+ log_ppp_debug("recv [LCP TermReq id=%x \"%s\"]\n",hdr->id,term_msg);
free(term_msg);
ppp_fsm_recv_term_req(&lcp->fsm);
ppp_terminate(lcp->ppp, 0);
break;
case TERMACK:
term_msg=strndup((char*)(hdr+1),ntohs(hdr->len));
- log_debug("recv [LCP TermAck id=%x \"%s\"]\n",hdr->id,term_msg);
+ log_ppp_debug("recv [LCP TermAck id=%x \"%s\"]\n",hdr->id,term_msg);
free(term_msg);
ppp_fsm_recv_term_ack(&lcp->fsm);
break;
case CODEREJ:
- log_debug("recv [LCP CodeRej id=%x]\n",hdr->id);
+ log_ppp_debug("recv [LCP CodeRej id=%x]\n",hdr->id);
ppp_fsm_recv_code_rej_bad(&lcp->fsm);
break;
case ECHOREQ:
diff --git a/accel-pptpd/radius/acct.c b/accel-pptpd/radius/acct.c
index 53e5e381..785eab3a 100644
--- a/accel-pptpd/radius/acct.c
+++ b/accel-pptpd/radius/acct.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
@@ -30,10 +31,10 @@ static void req_set_stat(struct rad_req_t *req, struct ppp_t *ppp)
memset(&ifreq, 0, sizeof(ifreq));
ifreq.stats_ptr = (void *)&ifreq.stats;
- sprintf(ifreq.ifr__name, "ppp%i", ppp->unit_idx);
+ strcpy(ifreq.ifr__name, ppp->ifname);
if (ioctl(sock_fd, SIOCGPPPSTATS, &ifreq)) {
- log_error("radius: failed to get ppp statistics: %s\n", strerror(errno));
+ log_ppp_error("radius: failed to get ppp statistics: %s\n", strerror(errno));
return;
}
@@ -53,8 +54,8 @@ static int rad_acct_read(struct triton_md_handler_t *h)
return 0;
if (conf_verbose) {
- log_debug("send ");
- rad_packet_print(req->reply, log_debug);
+ log_ppp_debug("send ");
+ rad_packet_print(req->reply, log_ppp_debug);
}
if (req->reply->code != CODE_ACCOUNTING_RESPONSE || req->reply->id != req->pack->id) {
@@ -62,7 +63,6 @@ static int rad_acct_read(struct triton_md_handler_t *h)
req->reply = NULL;
} else {
req->pack->id++;
- req->timeout.period = 0;
triton_timer_del(&req->timeout);
}
@@ -80,7 +80,7 @@ static void rad_acct_interim_update(struct triton_timer_t *t)
{
struct radius_pd_t *rpd = container_of(t, typeof(*rpd), acct_interim_timer);
- if (rpd->acct_req->timeout.period)
+ if (rpd->acct_req->timeout.tpd)
return;
rad_packet_change_val(rpd->acct_req->pack, "Acct-Status-Type", "Interim-Update");
@@ -95,12 +95,12 @@ int rad_acct_start(struct radius_pd_t *rpd)
{
rpd->acct_req = rad_req_alloc(rpd, CODE_ACCOUNTING_REQUEST, rpd->ppp->username);
if (!rpd->acct_req) {
- log_error("radius: out of memory\n");
+ log_emerg("radius: out of memory\n");
return -1;
}
if (rad_req_acct_fill(rpd->acct_req)) {
- log_error("radius:acct: failed to fill accounting attributes\n");
+ log_ppp_error("radius:acct: failed to fill accounting attributes\n");
goto out_err;
}
@@ -147,12 +147,12 @@ void rad_acct_stop(struct radius_pd_t *rpd)
{
int i;
- if (rpd->acct_interim_timer.period)
+ if (rpd->acct_interim_timer.tpd)
triton_timer_del(&rpd->acct_interim_timer);
if (rpd->acct_req) {
triton_md_unregister_handler(&rpd->acct_req->hnd);
- if (rpd->acct_req->timeout.period)
+ if (rpd->acct_req->timeout.tpd)
triton_timer_del(&rpd->acct_req->timeout);
rad_packet_change_val(rpd->acct_req->pack, "Acct-Status-Type", "Stop");
@@ -172,7 +172,7 @@ void rad_acct_stop(struct radius_pd_t *rpd)
break;
}
if (!rpd->acct_req->reply)
- log_warn("radius:acct_stop: no response\n");
+ log_ppp_warn("radius:acct_stop: no response\n");
rad_req_free(rpd->acct_req);
rpd->acct_req = NULL;
diff --git a/accel-pptpd/radius/auth.c b/accel-pptpd/radius/auth.c
index 2415a058..e2d2478b 100644
--- a/accel-pptpd/radius/auth.c
+++ b/accel-pptpd/radius/auth.c
@@ -19,7 +19,7 @@ static uint8_t* encrypt_password(const char *passwd, const char *secret, const u
epasswd = malloc(chunk_cnt * 16);
if (!epasswd) {
- log_error("radius: out of memory\n");
+ log_emerg("radius: out of memory\n");
return NULL;
}
@@ -137,7 +137,7 @@ int rad_auth_chap_md5(struct radius_pd_t *rpd, const char *username, va_list arg
}
if (!req->reply)
- log_warn("radius:auth: no response\n");
+ log_ppp_warn("radius:auth: no response\n");
else if (req->reply->code == CODE_ACCESS_ACCEPT) {
rad_proc_attrs(req);
r = PWDB_SUCCESS;
diff --git a/accel-pptpd/radius/dict.c b/accel-pptpd/radius/dict.c
index 4a0435a5..0e969627 100644
--- a/accel-pptpd/radius/dict.c
+++ b/accel-pptpd/radius/dict.c
@@ -78,14 +78,14 @@ int rad_dict_load(const char *fname)
buf = malloc(BUF_SIZE);
if (!buf) {
- log_error("radius: out of memory\n");
+ log_emerg("radius: out of memory\n");
fclose(f);
return -1;
}
dict = malloc(sizeof(*dict));
if (!dict) {
- log_error("radius: out of memory\n");
+ log_emerg("radius: out of memory\n");
fclose(f);
free(buf);
return -1;
@@ -104,7 +104,7 @@ int rad_dict_load(const char *fname)
if (!strcmp(buf, "ATTRIBUTE")) {
attr = malloc(sizeof(*attr));
if (!attr) {
- log_error("radius: out of memory\n");
+ log_emerg("radius: out of memory\n");
goto out_err;
}
memset(attr, 0, sizeof(*attr));
@@ -138,7 +138,7 @@ int rad_dict_load(const char *fname)
}
val = malloc(sizeof(*val));
if (!val) {
- log_error("radius: out of memory\n");
+ log_emerg("radius: out of memory\n");
goto out_err;
}
memset(val, 0, sizeof(*val));
diff --git a/accel-pptpd/radius/dm_coa.c b/accel-pptpd/radius/dm_coa.c
index c337b6af..784ad826 100644
--- a/accel-pptpd/radius/dm_coa.c
+++ b/accel-pptpd/radius/dm_coa.c
@@ -74,8 +74,8 @@ static int dm_coa_send_ack(int fd, struct rad_packet_t *req, struct sockaddr_in
dm_coa_set_RA(reply, conf_dm_coa_secret);
if (conf_verbose) {
- log_debug("send ");
- rad_packet_print(reply, log_debug);
+ log_ppp_debug("send ");
+ rad_packet_print(reply, log_ppp_debug);
}
rad_packet_send(reply, fd, addr);
@@ -108,8 +108,8 @@ static int dm_coa_send_nak(int fd, struct rad_packet_t *req, struct sockaddr_in
dm_coa_set_RA(reply, conf_dm_coa_secret);
if (conf_verbose) {
- log_debug("send ");
- rad_packet_print(reply, log_debug);
+ log_ppp_debug("send ");
+ rad_packet_print(reply, log_ppp_debug);
}
rad_packet_send(reply, fd, addr);
@@ -122,6 +122,11 @@ static int dm_coa_send_nak(int fd, struct rad_packet_t *req, struct sockaddr_in
static void disconnect_request(struct radius_pd_t *rpd)
{
+ if (conf_verbose) {
+ log_ppp_debug("recv ");
+ rad_packet_print(rpd->dm_coa_req, log_ppp_debug);
+ }
+
dm_coa_send_ack(serv.hnd.fd, rpd->dm_coa_req, &rpd->dm_coa_addr);
rad_packet_free(rpd->dm_coa_req);
@@ -132,6 +137,10 @@ static void disconnect_request(struct radius_pd_t *rpd)
static void coa_request(struct radius_pd_t *rpd)
{
+ if (conf_verbose) {
+ log_ppp_debug("recv ");
+ rad_packet_print(rpd->dm_coa_req, log_ppp_debug);
+ }
/// TODO: CoA handling
rad_packet_free(rpd->dm_coa_req);
@@ -207,6 +216,7 @@ static void dm_coa_close(struct triton_context_t *ctx)
static struct dm_coa_serv_t serv = {
.ctx.close = dm_coa_close,
+ .ctx.before_switch = log_switch,
.hnd.read = dm_coa_read,
};
@@ -237,7 +247,7 @@ static void __init init(void)
return;
}
- triton_context_register(&serv.ctx);
+ triton_context_register(&serv.ctx, NULL);
triton_md_register_handler(&serv.ctx, &serv.hnd);
triton_md_enable_handler(&serv.hnd, MD_MODE_READ);
}
diff --git a/accel-pptpd/radius/packet.c b/accel-pptpd/radius/packet.c
index dcc1053a..7d418d7a 100644
--- a/accel-pptpd/radius/packet.c
+++ b/accel-pptpd/radius/packet.c
@@ -16,7 +16,7 @@ struct rad_packet_t *rad_packet_alloc(int code)
pack = malloc(sizeof(*pack));
if (!pack) {
- log_error("radius:packet: out of memory\n");
+ log_emerg("radius:packet: out of memory\n");
return NULL;
}
@@ -48,7 +48,7 @@ int rad_packet_build(struct rad_packet_t *pack, uint8_t *RA)
ptr = malloc(pack->len);
if (!ptr) {
- log_error("radius:packet: out of memory\n");
+ log_emerg("radius:packet: out of memory\n");
return -1;
}
@@ -76,7 +76,7 @@ int rad_packet_build(struct rad_packet_t *pack, uint8_t *RA)
*(uint32_t*)ptr = htonl(attr->val.date);
break;
default:
- log_error("radius:packet:BUG: unknown attribute type\n");
+ log_emerg("radius:packet:BUG: unknown attribute type\n");
abort();
}
ptr += attr->len;
@@ -101,7 +101,7 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr)
pack->buf = malloc(REQ_LENGTH_MAX);
if (!pack->buf) {
- log_error("radius:packet: out of memory\n");
+ log_emerg("radius:packet: out of memory\n");
goto out_err;
}
@@ -113,14 +113,14 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr)
if (n < 0) {
if (errno == EINTR)
continue;
- log_error("radius:packet:read: %s\n", strerror(errno));
+ log_ppp_error("radius:packet:read: %s\n", strerror(errno));
goto out_err;
}
break;
}
if (n < 20) {
- log_warn("radius:packet: short packed received (%i)\n", n);
+ log_ppp_warn("radius:packet: short packed received (%i)\n", n);
goto out_err;
}
@@ -131,7 +131,7 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr)
pack->len = ntohs(*(uint16_t*)ptr); ptr += 2;
if (pack->len > n) {
- log_warn("radius:packet: short packet received %i, expected %i\n", pack->len, n);
+ log_ppp_warn("radius:packet: short packet received %i, expected %i\n", pack->len, n);
goto out_err;
}
@@ -142,18 +142,18 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr)
id = *ptr; ptr++;
len = *ptr - 2; ptr++;
if (len < 0) {
- log_warn("radius:packet short attribute len received\n");
+ log_ppp_warn("radius:packet short attribute len received\n");
goto out_err;
}
if (2 + len > n) {
- log_warn("radius:packet: too long attribute received (%i, %i)\n", id, len);
+ log_ppp_warn("radius:packet: too long attribute received (%i, %i)\n", id, len);
goto out_err;
}
da = rad_dict_find_attr_id(id);
if (da) {
attr = malloc(sizeof(*attr));
if (!attr) {
- log_error("radius:packet: out of memory\n");
+ log_emerg("radius:packet: out of memory\n");
goto out_err;
}
attr->attr = da;
@@ -162,7 +162,7 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr)
case ATTR_TYPE_STRING:
attr->val.string = malloc(len+1);
if (!attr->val.string) {
- log_error("radius:packet: out of memory\n");
+ log_emerg("radius:packet: out of memory\n");
free(attr);
goto out_err;
}
@@ -172,7 +172,7 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr)
case ATTR_TYPE_OCTETS:
attr->val.octets = malloc(len);
if (!attr->val.octets) {
- log_error("radius:packet: out of memory\n");
+ log_emerg("radius:packet: out of memory\n");
free(attr);
goto out_err;
}
@@ -188,7 +188,7 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr)
}
list_add_tail(&attr->entry, &pack->attrs);
} else
- log_warn("radius:packet: unknown attribute received (%i)\n", id);
+ log_ppp_warn("radius:packet: unknown attribute received (%i)\n", id);
ptr += len;
n -= 2 + len;
}
@@ -340,7 +340,7 @@ int rad_packet_add_octets(struct rad_packet_t *pack, const char *name, uint8_t *
ra = malloc(sizeof(*ra));
if (!ra) {
- log_error("radius: out of memory\n");
+ log_emerg("radius: out of memory\n");
return -1;
}
@@ -348,7 +348,7 @@ int rad_packet_add_octets(struct rad_packet_t *pack, const char *name, uint8_t *
ra->len = len;
ra->val.octets = malloc(len);
if (!ra->val.octets) {
- log_error("radius: out of memory\n");
+ log_emerg("radius: out of memory\n");
free(ra);
return -1;
}
@@ -372,7 +372,7 @@ int rad_packet_add_str(struct rad_packet_t *pack, const char *name, const char *
ra = malloc(sizeof(*ra));
if (!ra) {
- log_error("radius: out of memory\n");
+ log_emerg("radius: out of memory\n");
return -1;
}
@@ -380,7 +380,7 @@ int rad_packet_add_str(struct rad_packet_t *pack, const char *name, const char *
ra->len = len;
ra->val.string = malloc(len+1);
if (!ra->val.string) {
- log_error("radius: out of memory\n");
+ log_emerg("radius: out of memory\n");
free(ra);
return -1;
}
@@ -406,7 +406,7 @@ int rad_packet_change_str(struct rad_packet_t *pack, const char *name, const cha
ra->val.string = realloc(ra->val.string, len + 1);
if (!ra->val.string) {
- log_error("radius: out of memory\n");
+ log_emerg("radius: out of memory\n");
return -1;
}
@@ -491,10 +491,10 @@ int rad_packet_send(struct rad_packet_t *pack, int fd, struct sockaddr_in *addr)
if (n < 0) {
if (errno == EINTR)
continue;
- log_error("radius:write: %s\n", strerror(errno));
+ log_ppp_error("radius:write: %s\n", strerror(errno));
return -1;
} else if (n != pack->len) {
- log_error("radius:write: short write %i, excpected %i\n", n, pack->len);
+ log_ppp_error("radius:write: short write %i, excpected %i\n", n, pack->len);
return -1;
}
break;
diff --git a/accel-pptpd/radius/radius.c b/accel-pptpd/radius/radius.c
index 47a9aeaa..0e9d4b1b 100644
--- a/accel-pptpd/radius/radius.c
+++ b/accel-pptpd/radius/radius.c
@@ -46,7 +46,7 @@ void rad_proc_attrs(struct rad_req_t *req)
list_for_each_entry(attr, &req->reply->attrs, entry) {
if (!strcmp(attr->attr->name, "Framed-IP-Address")) {
if (!conf_gw_ip_address)
- log_warn("radius: gw-ip-address not specified, cann't assign IP address...\n");
+ log_ppp_warn("radius: gw-ip-address not specified, cann't assign IP address...\n");
else {
req->rpd->ipaddr.owner = &ipdb;
req->rpd->ipaddr.peer_addr = attr->val.ipaddr;
@@ -105,7 +105,7 @@ static void ppp_starting(struct ppp_t *ppp)
struct radius_pd_t *pd = malloc(sizeof(*pd));
memset(pd, 0, sizeof(*pd));
- pd->pd.key = pd_key;
+ pd->pd.key = &pd_key;
pd->ppp = ppp;
pthread_mutex_init(&pd->lock, NULL);
list_add_tail(&pd->pd.entry, &ppp->pd_list);
@@ -151,12 +151,12 @@ struct radius_pd_t *find_pd(struct ppp_t *ppp)
struct radius_pd_t *rpd;
list_for_each_entry(pd, &ppp->pd_list, entry) {
- if (pd->key == pd_key) {
+ if (pd->key == &pd_key) {
rpd = container_of(pd, typeof(*rpd), pd);
return rpd;
}
}
- log_error("radius:BUG: rpd not found\n");
+ log_emerg("radius:BUG: rpd not found\n");
abort();
}
diff --git a/accel-pptpd/radius/req.c b/accel-pptpd/radius/req.c
index 40397a8b..4a7ac432 100644
--- a/accel-pptpd/radius/req.c
+++ b/accel-pptpd/radius/req.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
@@ -25,6 +26,7 @@ struct rad_req_t *rad_req_alloc(struct radius_pd_t *rpd, int code, const char *u
memset(req, 0, sizeof(*req));
req->rpd = rpd;
req->hnd.fd = -1;
+ req->ctx.before_switch = log_switch;
req->server_name = conf_auth_server;
req->server_port = conf_auth_server_port;
@@ -33,7 +35,7 @@ struct rad_req_t *rad_req_alloc(struct radius_pd_t *rpd, int code, const char *u
if (read(urandom_fd, req->RA, 16) != 16) {
if (errno == EINTR)
continue;
- log_error("radius:req:read urandom: %s\n", strerror(errno));
+ log_ppp_error("radius:req:read urandom: %s\n", strerror(errno));
goto out_err;
}
break;
@@ -106,7 +108,7 @@ static int make_socket(struct rad_req_t *req)
req->hnd.fd = socket(PF_INET, SOCK_DGRAM, 0);
if (req->hnd.fd < 0) {
- log_error("radius:socket: %s\n", strerror(errno));
+ log_ppp_error("radius:socket: %s\n", strerror(errno));
return -1;
}
@@ -116,7 +118,7 @@ static int make_socket(struct rad_req_t *req)
if (conf_nas_ip_address) {
addr.sin_addr.s_addr = inet_addr(conf_nas_ip_address);
if (bind(req->hnd.fd, (struct sockaddr *) &addr, sizeof(addr))) {
- log_error("radius:bind: %s\n", strerror(errno));
+ log_ppp_error("radius:bind: %s\n", strerror(errno));
goto out_err;
}
}
@@ -125,12 +127,12 @@ static int make_socket(struct rad_req_t *req)
addr.sin_port = htons(req->server_port);
if (connect(req->hnd.fd, (struct sockaddr *) &addr, sizeof(addr))) {
- log_error("radius:connect: %s\n", strerror(errno));
+ log_ppp_error("radius:connect: %s\n", strerror(errno));
goto out_err;
}
if (fcntl(req->hnd.fd, F_SETFL, O_NONBLOCK)) {
- log_error("radius: failed to set nonblocking mode: %s\n", strerror(errno));
+ log_ppp_error("radius: failed to set nonblocking mode: %s\n", strerror(errno));
goto out_err;
}
@@ -151,8 +153,8 @@ int rad_req_send(struct rad_req_t *req)
goto out_err;
if (conf_verbose) {
- log_debug("send ");
- rad_packet_print(req->pack, log_debug);
+ log_ppp_debug("send ");
+ rad_packet_print(req->pack, log_ppp_debug);
}
rad_packet_send(req->pack, req->hnd.fd, NULL);
@@ -193,7 +195,7 @@ int rad_req_wait(struct rad_req_t *req, int timeout)
req->hnd.read = rad_req_read;
req->timeout.expire = rad_req_timeout;
- triton_context_register(&req->ctx);
+ triton_context_register(&req->ctx, req->rpd->ppp);
triton_md_register_handler(&req->ctx, &req->hnd);
if (triton_md_enable_handler(&req->hnd, MD_MODE_READ))
return -1;
@@ -205,8 +207,8 @@ int rad_req_wait(struct rad_req_t *req, int timeout)
triton_context_schedule(req->rpd->ppp->ctrl->ctx);
if (conf_verbose && req->reply) {
- log_debug("recv ");
- rad_packet_print(req->reply, log_debug);
+ log_ppp_debug("recv ");
+ rad_packet_print(req->reply, log_ppp_debug);
}
return 0;
}
diff --git a/accel-pptpd/triton/CMakeLists.txt b/accel-pptpd/triton/CMakeLists.txt
index 41339d97..95ab4160 100644
--- a/accel-pptpd/triton/CMakeLists.txt
+++ b/accel-pptpd/triton/CMakeLists.txt
@@ -10,7 +10,6 @@ SET(sources_c
event.c
)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
-ADD_DEFINITIONS("-DUSE_SPINLOCK")
ADD_LIBRARY(${target} SHARED ${sources_c})
diff --git a/accel-pptpd/triton/mempool.c b/accel-pptpd/triton/mempool.c
index dacb6118..6d9172a1 100644
--- a/accel-pptpd/triton/mempool.c
+++ b/accel-pptpd/triton/mempool.c
@@ -20,7 +20,7 @@ struct _item_t
char ptr[0];
};
-mempool_t *mempool_create(int size)
+__export mempool_t *mempool_create(int size)
{
struct _mempool_t *p = malloc(sizeof(*p));
@@ -33,7 +33,7 @@ mempool_t *mempool_create(int size)
return (mempool_t *)p;
}
-void *mempool_alloc(mempool_t *pool)
+__export void *mempool_alloc(mempool_t *pool)
{
struct _mempool_t *p = (struct _mempool_t *)pool;
struct _item_t *it;
@@ -48,7 +48,7 @@ void *mempool_alloc(mempool_t *pool)
spin_unlock(&p->lock);
it = malloc(sizeof(*it) + p->size);
if (!it) {
- triton_log_error("out of memory\n");
+ triton_log_error("mempool: out of memory\n");
return NULL;
}
it->owner = p;
@@ -56,7 +56,7 @@ void *mempool_alloc(mempool_t *pool)
return it->ptr;
}
-void mempool_free(void *ptr)
+__export void mempool_free(void *ptr)
{
struct _item_t *it = container_of(ptr, typeof(*it), ptr);
diff --git a/accel-pptpd/triton/mempool.h b/accel-pptpd/triton/mempool.h
new file mode 100644
index 00000000..e8bcaf6a
--- /dev/null
+++ b/accel-pptpd/triton/mempool.h
@@ -0,0 +1,10 @@
+#ifndef __TRITON_MEMPOOL_H
+#define __TRITON_MEMPOOL_H
+
+typedef void * mempool_t;
+mempool_t *mempool_create(int size);
+void *mempool_alloc(mempool_t*);
+void mempool_free(void*);
+
+#endif
+
diff --git a/accel-pptpd/triton/spinlock.h b/accel-pptpd/triton/spinlock.h
index b6d1656a..5ef9c488 100644
--- a/accel-pptpd/triton/spinlock.h
+++ b/accel-pptpd/triton/spinlock.h
@@ -1,7 +1,7 @@
#ifndef __TRITON_SPINLOCK_H
#define __TRITON_SPINLOCK_H
-#ifdef USE_SPINLOCK
+#ifdef GCC_SPINLOCK
typedef unsigned char spinlock_t;
#define spin_lock(l) {while(__sync_lock_test_and_set(l,1));}
#define spin_unlock(l) __sync_lock_release(l)
diff --git a/accel-pptpd/triton/timer.c b/accel-pptpd/triton/timer.c
index e9fd66a0..d2249786 100644
--- a/accel-pptpd/triton/timer.c
+++ b/accel-pptpd/triton/timer.c
@@ -164,5 +164,6 @@ void __export triton_timer_del(struct triton_timer_t *ud)
spin_unlock(&t->ctx->lock);
sched_yield();
mempool_free(t);
+ ud->tpd = NULL;
}
diff --git a/accel-pptpd/triton/triton.c b/accel-pptpd/triton/triton.c
index 8b25f039..b0aedbc7 100644
--- a/accel-pptpd/triton/triton.c
+++ b/accel-pptpd/triton/triton.c
@@ -43,9 +43,10 @@ static void* triton_thread(struct _triton_thread_t *thread)
sigwait(&set, &sig);
cont:
- if (swapcontext(&thread->uctx, &thread->ctx->uctx)) {
+ if (thread->ctx->ud->before_switch)
+ thread->ctx->ud->before_switch(thread->ctx->ud, thread->ctx->bf_arg);
+ if (swapcontext(&thread->uctx, &thread->ctx->uctx))
triton_log_error("swapcontext: %s\n", strerror(errno));
- }
if (thread->ctx->need_free)
mempool_free(thread->ctx);
@@ -164,7 +165,7 @@ int triton_queue_ctx(struct _triton_context_t *ctx)
return 1;
}
-int __export triton_context_register(struct triton_context_t *ud)
+int __export triton_context_register(struct triton_context_t *ud, void *bf_arg)
{
struct _triton_context_t *ctx = mempool_alloc(ctx_pool);
@@ -173,6 +174,7 @@ int __export triton_context_register(struct triton_context_t *ud)
memset(ctx, 0, sizeof(*ctx));
ctx->ud = ud;
+ ctx->bf_arg = bf_arg;
spinlock_init(&ctx->lock);
INIT_LIST_HEAD(&ctx->handlers);
INIT_LIST_HEAD(&ctx->timers);
@@ -299,7 +301,7 @@ int __export triton_init(const char *conf_file, const char *mod_sect)
fprintf(stderr,"cann't allocate memory\n");
return -1;
}
- triton_context_register(default_ctx);
+ triton_context_register(default_ctx, NULL);
if (conf_load(conf_file))
return -1;
diff --git a/accel-pptpd/triton/triton.h b/accel-pptpd/triton/triton.h
index d9baa7da..b1df4971 100644
--- a/accel-pptpd/triton/triton.h
+++ b/accel-pptpd/triton/triton.h
@@ -10,6 +10,7 @@ struct triton_context_t
const void *tpd; // triton private data, don't touch!
void (*close)(struct triton_context_t*);
void (*free)(struct triton_context_t*);
+ void (*before_switch)(struct triton_context_t *ctx, void *arg);
};
struct triton_md_handler_t
@@ -41,7 +42,7 @@ struct conf_sect_t
struct list_head items;
};
-int triton_context_register(struct triton_context_t *);
+int triton_context_register(struct triton_context_t *, void *arg);
void triton_context_unregister(struct triton_context_t *);
void triton_context_schedule(struct triton_context_t *);
void triton_context_wakeup(struct triton_context_t *);
diff --git a/accel-pptpd/triton/triton_p.h b/accel-pptpd/triton/triton_p.h
index 5e498fcd..ec2eb840 100644
--- a/accel-pptpd/triton/triton_p.h
+++ b/accel-pptpd/triton/triton_p.h
@@ -8,6 +8,7 @@
#include "triton.h"
#include "list.h"
#include "spinlock.h"
+#include "mempool.h"
#define CTX_STACK_SIZE 8196
@@ -43,6 +44,7 @@ struct _triton_context_t
int need_free:1;
struct triton_context_t *ud;
+ void *bf_arg;
};
struct _triton_md_handler_t
@@ -80,11 +82,6 @@ struct _triton_ctx_call_t
void (*func)(void *);
};
-typedef void * mempool_t;
-mempool_t *mempool_create(int size);
-void *mempool_alloc(mempool_t*);
-void mempool_free(void*);
-
int log_init(void);
int md_init();
int timer_init();