diff options
Diffstat (limited to 'accel-pptpd')
-rw-r--r-- | accel-pptpd/accel-pptpd.conf | 6 | ||||
-rw-r--r-- | accel-pptpd/ctrl/pptp.c | 14 | ||||
-rw-r--r-- | accel-pptpd/logs/log_file.c | 26 | ||||
-rw-r--r-- | accel-pptpd/logs/log_pgsql.c | 59 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_fsm.c | 6 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_lcp.c | 3 | ||||
-rw-r--r-- | accel-pptpd/radius/auth.c | 2 | ||||
-rw-r--r-- | accel-pptpd/radius/dm_coa.c | 1 | ||||
-rw-r--r-- | accel-pptpd/radius/req.c | 9 | ||||
-rw-r--r-- | accel-pptpd/triton/md.c | 9 | ||||
-rw-r--r-- | accel-pptpd/triton/mempool.c | 38 | ||||
-rw-r--r-- | accel-pptpd/triton/triton.c | 62 | ||||
-rw-r--r-- | accel-pptpd/triton/triton.h | 5 | ||||
-rw-r--r-- | accel-pptpd/triton/triton_p.h | 2 |
14 files changed, 159 insertions, 83 deletions
diff --git a/accel-pptpd/accel-pptpd.conf b/accel-pptpd/accel-pptpd.conf index 3aa9b18..356b5f0 100644 --- a/accel-pptpd/accel-pptpd.conf +++ b/accel-pptpd/accel-pptpd.conf @@ -1,6 +1,6 @@ [modules] -./liblog_file.so -#./liblog_pgsql.so +#./liblog_file.so +./liblog_pgsql.so ./libpptp.so ./libauth_pap.so ./libauth_chap_md5.so @@ -52,7 +52,7 @@ gw-ip-address=192.168.100.1 [log] log-file=general.log log-emerg=/dev/stderr -log-debug=/dev/stdout +log-debug=debug.log copy=1 #color=1 per-user-dir=per_user diff --git a/accel-pptpd/ctrl/pptp.c b/accel-pptpd/ctrl/pptp.c index d19420a..f4cd9d3 100644 --- a/accel-pptpd/ctrl/pptp.c +++ b/accel-pptpd/ctrl/pptp.c @@ -529,6 +529,7 @@ static int pptp_connect(struct triton_md_handler_t *h) 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_context_wakeup(&conn->ctx); triton_event_fire(EV_CTRL_STARTING, &conn->ppp); } @@ -578,12 +579,6 @@ static void __init pptp_init(void) return; } - conn_pool = mempool_create(sizeof(struct pptp_conn_t)); - - triton_context_register(&serv.ctx, NULL); - triton_md_register_handler(&serv.ctx, &serv.hnd); - triton_md_enable_handler(&serv.hnd, MD_MODE_READ); - opt = conf_get_opt("pptp", "timeout"); if (opt && atoi(opt) > 0) conf_timeout = atoi(opt); @@ -591,5 +586,12 @@ static void __init pptp_init(void) opt = conf_get_opt("pptp", "echo-interval"); if (opt && atoi(opt) > 0) conf_echo_interval = atoi(opt); + + conn_pool = mempool_create(sizeof(struct pptp_conn_t)); + + triton_context_register(&serv.ctx, NULL); + triton_md_register_handler(&serv.ctx, &serv.hnd); + triton_md_enable_handler(&serv.hnd, MD_MODE_READ); + triton_context_wakeup(&serv.ctx); } diff --git a/accel-pptpd/logs/log_file.c b/accel-pptpd/logs/log_file.c index b39c623..c364fbd 100644 --- a/accel-pptpd/logs/log_file.c +++ b/accel-pptpd/logs/log_file.c @@ -109,12 +109,22 @@ static void sigio(int num, siginfo_t *si, void *uc) spin_lock(&lf->lock); lf->offset += n; - if (list_empty(&lf->msgs) && lf->need_free) { - spin_unlock(&lf->lock); - close(lf->fd); - mempool_free(lf->lpd); - } else + if (list_empty(&lf->msgs)) { + if (lf->need_free) { + spin_unlock(&lf->lock); + close(lf->fd); + mempool_free(lf->lpd); + } else { + lf->queued = 0; + spin_unlock(&lf->lock); + } + } else { spin_unlock(&lf->lock); + + spin_lock(&lf_queue_lock); + list_add_tail(&lf->entry, &lf_queue); + spin_unlock(&lf_queue_lock); + } send_next_chunk(); } @@ -128,7 +138,6 @@ static int dequeue_log(struct log_file_t *lf) while (1) { spin_lock(&lf->lock); if (list_empty(&lf->msgs)) { - lf->queued = 0; spin_unlock(&lf->lock); return pos; } @@ -157,10 +166,6 @@ overrun: list_add(&msg->entry, &lf->msgs); spin_unlock(&lf->lock); - spin_lock(&lf_queue_lock); - list_add_tail(&lf->entry, &lf_queue); - spin_unlock(&lf_queue_lock); - return pos; } @@ -317,6 +322,7 @@ static void free_lpd(struct log_file_pd_t *lpd) } if (lpd->lf.fd != -1) close(lpd->lf.fd); + list_del(&lpd->pd.entry); spin_unlock(&lpd->lf.lock); mempool_free(lpd); } diff --git a/accel-pptpd/logs/log_pgsql.c b/accel-pptpd/logs/log_pgsql.c index 393c3bd..351fc06 100644 --- a/accel-pptpd/logs/log_pgsql.c +++ b/accel-pptpd/logs/log_pgsql.c @@ -74,31 +74,40 @@ static void write_next_msg(void) const char *paramValues[4]; int paramFormats[4] = {0, 0, 0, 0}; char *ptr1, *ptr2; + int r; spin_lock(&queue_lock); - if (!list_empty(&msg_queue)) { - msg = list_entry(msg_queue.next, typeof(*msg), entry); - list_del(&msg->entry); - --queue_size; + if (list_empty(&msg_queue)) { + sleeping = 1; spin_unlock(&queue_lock); + return; + } - unpack_msg(msg); + msg = list_entry(msg_queue.next, typeof(*msg), entry); + list_del(&msg->entry); + --queue_size; + spin_unlock(&queue_lock); - ptr1 = strchr(msg->hdr->msg, 0); - ptr2 = strchr(ptr1 + 1, 0); + unpack_msg(msg); - paramValues[1] = ptr1[1] ? ptr1 + 1 : NULL; - paramValues[2] = ptr2[1] ? ptr2 + 1 : NULL; - paramValues[0] = msg->hdr->msg; - paramValues[3] = log_buf; + ptr1 = strchr(msg->hdr->msg, 0); + ptr2 = strchr(ptr1 + 1, 0); - PQsendQueryParams(conn, conf_query, 4, NULL, paramValues, NULL, paramFormats, 0); - PQflush(conn); - log_free_msg(msg); - return; - } - sleeping = 1; - spin_unlock(&queue_lock); + paramValues[1] = ptr1[1] ? ptr1 + 1 : NULL; + paramValues[2] = ptr2[1] ? ptr2 + 1 : NULL; + paramValues[0] = msg->hdr->msg; + paramValues[3] = log_buf; + + if (!PQsendQueryParams(conn, conf_query, 4, NULL, paramValues, NULL, paramFormats, 0)) + log_emerg("log_pgsql: %s\n", PQerrorMessage(conn)); + + log_free_msg(msg); + + r = PQflush(conn); + if (r == -1) + log_emerg("log_pgsql: %s\n", PQerrorMessage(conn)); + if (r == 0) + triton_md_enable_handler(&pgsql_hnd, MD_MODE_WRITE); } static int pgsql_check_ready(struct triton_md_handler_t *h) @@ -132,7 +141,15 @@ static int pgsql_check_ready(struct triton_md_handler_t *h) static int pgsql_flush(struct triton_md_handler_t *h) { - PQflush(conn); + int r; + + r = PQflush(conn); + if (r == -1) + log_emerg("log_pgsql: %s\n", PQerrorMessage(conn)); + if (r == 1) + return 0; + + triton_md_disable_handler(&pgsql_hnd, MD_MODE_WRITE); return 0; } @@ -196,7 +213,7 @@ static int wait_connect(struct triton_md_handler_t *h) PQsetnonblocking(conn, 1); h->write = pgsql_flush; h->read = pgsql_check_ready; - triton_md_enable_handler(&pgsql_hnd, MD_MODE_READ | MD_MODE_WRITE); + triton_md_enable_handler(&pgsql_hnd, MD_MODE_READ); wakeup_log(); break; default: @@ -266,6 +283,8 @@ static void __init init(void) triton_context_register(&pgsql_ctx, NULL); triton_md_register_handler(&pgsql_ctx, &pgsql_hnd); + triton_md_set_trig(&pgsql_hnd, MD_TRIG_LEVEL); + triton_context_wakeup(&pgsql_ctx); start_connect(); diff --git a/accel-pptpd/ppp/ppp_fsm.c b/accel-pptpd/ppp/ppp_fsm.c index 3b8d854..8f8e855 100644 --- a/accel-pptpd/ppp/ppp_fsm.c +++ b/accel-pptpd/ppp/ppp_fsm.c @@ -177,13 +177,13 @@ void ppp_fsm_timeout1(struct ppp_fsm_t *layer) { case FSM_Closing: stop_timer(layer); - if (layer->layer_finished) layer->layer_finished(layer); layer->fsm_state=FSM_Closed; + if (layer->layer_finished) layer->layer_finished(layer); break; case FSM_Stopping: stop_timer(layer); - if (layer->layer_finished) layer->layer_finished(layer); layer->fsm_state=FSM_Stopped; + if (layer->layer_finished) layer->layer_finished(layer); break; case FSM_Ack_Rcvd: case FSM_Req_Sent: @@ -397,8 +397,8 @@ void ppp_fsm_recv_term_ack(struct ppp_fsm_t *layer) switch(layer->fsm_state) { case FSM_Closing: - if (layer->layer_finished) layer->layer_finished(layer); layer->fsm_state=FSM_Closed; + if (layer->layer_finished) layer->layer_finished(layer); break; case FSM_Stopping: if (layer->layer_finished) layer->layer_finished(layer); diff --git a/accel-pptpd/ppp/ppp_lcp.c b/accel-pptpd/ppp/ppp_lcp.c index d28167e..7081cbb 100644 --- a/accel-pptpd/ppp/ppp_lcp.c +++ b/accel-pptpd/ppp/ppp_lcp.c @@ -267,6 +267,8 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) lcp_hdr->len=htons((ptr-buf)-2); ppp_chan_send(lcp->ppp,lcp_hdr,ptr-buf); + + _free(buf); } static void send_conf_rej(struct ppp_fsm_t *fsm) @@ -319,6 +321,7 @@ static int lcp_recv_conf_req(struct ppp_lcp_t *lcp,uint8_t *data,int size) hdr=(struct lcp_opt_hdr_t *)data; ropt=_malloc(sizeof(*ropt)); + memset(ropt, 0, sizeof(*ropt)); if (hdr->len>size) ropt->len=size; else ropt->len=hdr->len; ropt->hdr=hdr; diff --git a/accel-pptpd/radius/auth.c b/accel-pptpd/radius/auth.c index 46adbd7..ccb8fc0 100644 --- a/accel-pptpd/radius/auth.c +++ b/accel-pptpd/radius/auth.c @@ -70,7 +70,7 @@ static int rad_auth_send(struct rad_req_t *req) else if (req->reply->code == CODE_ACCESS_ACCEPT) { rad_proc_attrs(req); return PWDB_SUCCESS; - } +} out: return PWDB_DENIED; diff --git a/accel-pptpd/radius/dm_coa.c b/accel-pptpd/radius/dm_coa.c index af7c0fe..32466bb 100644 --- a/accel-pptpd/radius/dm_coa.c +++ b/accel-pptpd/radius/dm_coa.c @@ -273,4 +273,5 @@ static void __init init(void) triton_context_register(&serv.ctx, NULL); triton_md_register_handler(&serv.ctx, &serv.hnd); triton_md_enable_handler(&serv.hnd, MD_MODE_READ); + triton_context_wakeup(&serv.ctx); } diff --git a/accel-pptpd/radius/req.c b/accel-pptpd/radius/req.c index cd4a31b..76b7ba3 100644 --- a/accel-pptpd/radius/req.c +++ b/accel-pptpd/radius/req.c @@ -4,6 +4,7 @@ #include <errno.h> #include <fcntl.h> #include <unistd.h> +#include <sched.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> @@ -217,12 +218,12 @@ int rad_req_wait(struct rad_req_t *req, int timeout) req->ctx.fname=__FILE__; req->ctx.line=__LINE__; triton_md_register_handler(&req->ctx, &req->hnd); - if (triton_md_enable_handler(&req->hnd, MD_MODE_READ)) - return -1; + triton_md_enable_handler(&req->hnd, MD_MODE_READ); req->timeout.period = timeout * 1000; - if (triton_timer_add(&req->ctx, &req->timeout, 0)) - return -1; + triton_timer_add(&req->ctx, &req->timeout, 0); + + triton_context_wakeup(&req->ctx); triton_context_schedule(req->rpd->ppp->ctrl->ctx); diff --git a/accel-pptpd/triton/md.c b/accel-pptpd/triton/md.c index 133abe8..444aebf 100644 --- a/accel-pptpd/triton/md.c +++ b/accel-pptpd/triton/md.c @@ -137,7 +137,8 @@ int __export triton_md_enable_handler(struct triton_md_handler_t *ud, int mode) if (mode & MD_MODE_WRITE) h->epoll_event.events |= EPOLLOUT; - h->epoll_event.events |= EPOLLET; + if (!h->trig_level) + h->epoll_event.events |= EPOLLET; if (events) r = epoll_ctl(epoll_fd, EPOLL_CTL_MOD, h->ud->fd, &h->epoll_event); @@ -179,3 +180,9 @@ int __export triton_md_disable_handler(struct triton_md_handler_t *ud,int mode) return r; } +void __export triton_md_set_trig(struct triton_md_handler_t *ud, int mode) +{ + struct _triton_md_handler_t *h = (struct _triton_md_handler_t *)ud->tpd; + h->trig_level = mode; +} + diff --git a/accel-pptpd/triton/mempool.c b/accel-pptpd/triton/mempool.c index 34739b4..16d6ab3 100644 --- a/accel-pptpd/triton/mempool.c +++ b/accel-pptpd/triton/mempool.c @@ -7,6 +7,8 @@ #include "memdebug.h" +#define MAGIC1 0x2233445566778899llu + struct _mempool_t { struct list_head entry; @@ -20,7 +22,8 @@ struct _item_t { struct _mempool_t *owner; struct list_head entry; - uint64_t magic; + uint64_t magic2; + uint64_t magic1; char ptr[0]; }; @@ -49,7 +52,7 @@ __export void *mempool_alloc(mempool_t *pool) { struct _mempool_t *p = (struct _mempool_t *)pool; struct _item_t *it; - uint32_t size = sizeof(*it) + p->size; + uint32_t size = sizeof(*it) + p->size + 8; spin_lock(&p->lock); if (!list_empty(&p->items)) { @@ -59,6 +62,8 @@ __export void *mempool_alloc(mempool_t *pool) __sync_fetch_and_sub(&triton_stat.mempool_available, size); + it->magic1 = MAGIC1; + return it->ptr; } spin_unlock(&p->lock); @@ -69,7 +74,9 @@ __export void *mempool_alloc(mempool_t *pool) return NULL; } it->owner = p; - it->magic = p->magic; + it->magic1 = MAGIC1; + it->magic2 = p->magic; + *(uint64_t*)(it->data + p->size) = it->magic2; __sync_fetch_and_add(&triton_stat.mempool_allocated, size); @@ -81,7 +88,7 @@ void __export *mempool_alloc_md(mempool_t *pool, const char *fname, int line) { struct _mempool_t *p = (struct _mempool_t *)pool; struct _item_t *it; - uint32_t size = sizeof(*it) + p->size; + uint32_t size = sizeof(*it) + p->size + 8; spin_lock(&p->lock); if (!list_empty(&p->items)) { @@ -91,6 +98,8 @@ void __export *mempool_alloc_md(mempool_t *pool, const char *fname, int line) __sync_fetch_and_sub(&triton_stat.mempool_available, size); + it->magic1 = MAGIC1; + return it->ptr; } spin_unlock(&p->lock); @@ -101,7 +110,9 @@ void __export *mempool_alloc_md(mempool_t *pool, const char *fname, int line) return NULL; } it->owner = p; - it->magic = p->magic; + it->magic2 = p->magic; + it->magic1 = MAGIC1; + *(uint64_t*)(it->ptr + p->size) = it->magic2; __sync_fetch_and_add(&triton_stat.mempool_allocated, size); @@ -112,12 +123,25 @@ void __export *mempool_alloc_md(mempool_t *pool, const char *fname, int line) __export void mempool_free(void *ptr) { struct _item_t *it = container_of(ptr, typeof(*it), ptr); - uint32_t size = sizeof(*it) + it->owner->size; + uint32_t size = sizeof(*it) + it->owner->size + 8; + + if (it->magic1 != MAGIC1) { + triton_log_error("mempool: memory corruption detected"); + abort(); + } - if (it->magic != it->owner->magic) { + if (it->magic2 != it->owner->magic) { triton_log_error("mempool: memory corruption detected"); abort(); } + + if (it->magic2 != *(uint64_t*)(it->ptr + it->owner->size)) { + triton_log_error("mempool: memory corruption detected"); + abort(); + } + + it->magic1 = 0; + spin_lock(&it->owner->lock); list_add_tail(&it->entry,&it->owner->items); spin_unlock(&it->owner->lock); diff --git a/accel-pptpd/triton/triton.c b/accel-pptpd/triton/triton.c index 2de2e67..ce880e9 100644 --- a/accel-pptpd/triton/triton.c +++ b/accel-pptpd/triton/triton.c @@ -50,11 +50,31 @@ static void* triton_thread(struct _triton_thread_t *thread) sigaddset(&set, SIGQUIT); while (1) { - __sync_fetch_and_sub(&triton_stat.thread_active, 1); - //printf("thread %p: enter sigwait\n", thread); - sigwait(&set, &sig); - //printf("thread %p: exit sigwait\n", thread); - __sync_fetch_and_add(&triton_stat.thread_active, 1); + spin_lock(&threads_lock); + if (!list_empty(&ctx_queue)) { + thread->ctx = list_entry(ctx_queue.next, typeof(*thread->ctx), entry2); + //printf("thread: %p: dequeued ctx %p\n", thread, thread->ctx); + list_del(&thread->ctx->entry2); + spin_unlock(&threads_lock); + spin_lock(&thread->ctx->lock); + thread->ctx->thread = thread; + thread->ctx->queued = 0; + spin_unlock(&thread->ctx->lock); + __sync_fetch_and_sub(&triton_stat.context_pending, 1); + } else { + //printf("thread: %p: sleeping\n", thread); + if (!terminate) + list_add(&thread->entry2, &sleep_threads); + spin_unlock(&threads_lock); + if (terminate) + return NULL; + + __sync_fetch_and_sub(&triton_stat.thread_active, 1); + //printf("thread %p: enter sigwait\n", thread); + sigwait(&set, &sig); + //printf("thread %p: exit sigwait\n", thread); + __sync_fetch_and_add(&triton_stat.thread_active, 1); + } cont: //printf("thread %p: ctx=%p %p\n", thread, thread->ctx, thread->ctx ? thread->ctx->thread : NULL); @@ -89,27 +109,6 @@ cont: } thread->ctx = NULL; - - spin_lock(&threads_lock); - if (!list_empty(&ctx_queue)) { - thread->ctx = list_entry(ctx_queue.next, typeof(*thread->ctx), entry2); - //printf("thread: %p: dequeued ctx %p\n", thread, thread->ctx); - list_del(&thread->ctx->entry2); - spin_unlock(&threads_lock); - spin_lock(&thread->ctx->lock); - thread->ctx->thread = thread; - thread->ctx->queued = 0; - spin_unlock(&thread->ctx->lock); - __sync_fetch_and_sub(&triton_stat.context_pending, 1); - goto cont; - } else { - //printf("thread: %p: sleeping\n", thread); - if (!terminate) - list_add(&thread->entry2, &sleep_threads); - spin_unlock(&threads_lock); - if (terminate) - return NULL; - } } } @@ -179,7 +178,7 @@ static void ctx_thread(struct _triton_context_t *ctx) struct _triton_thread_t *create_thread() { - struct _triton_thread_t *thread = _malloc(sizeof(*thread)); + struct _triton_thread_t *thread = malloc(sizeof(*thread)); if (!thread) return NULL; @@ -230,6 +229,7 @@ int __export triton_context_register(struct triton_context_t *ud, void *bf_arg) memset(ctx, 0, sizeof(*ctx)); ctx->ud = ud; ctx->bf_arg = bf_arg; + ctx->sleeping = 1; spinlock_init(&ctx->lock); INIT_LIST_HEAD(&ctx->handlers); INIT_LIST_HEAD(&ctx->timers); @@ -259,6 +259,7 @@ int __export triton_context_register(struct triton_context_t *ud, void *bf_arg) list_add_tail(&ctx->entry, &ctx_list); spin_unlock(&ctx_list_lock); + __sync_fetch_and_add(&triton_stat.context_sleeping, 1); __sync_fetch_and_add(&triton_stat.context_count, 1); return 0; @@ -314,6 +315,11 @@ void __export triton_context_schedule(struct triton_context_t *ud) ucontext_t *uctx = &ctx->thread->uctx; spin_lock(&ctx->lock); + if (ctx->wakeup) { + ctx->wakeup = 0; + spin_unlock(&ctx->lock); + return; + } ctx->sleeping = 1; ctx->thread = NULL; spin_unlock(&ctx->lock); @@ -337,6 +343,7 @@ int __export triton_context_wakeup(struct triton_context_t *ud) spin_lock(&ctx->lock); if (!ctx->sleeping) { + ctx->wakeup = 1; spin_unlock(&ctx->lock); return -1; } @@ -426,7 +433,6 @@ void __export triton_run() _exit(-1); list_add_tail(&t->entry, &threads); - list_add_tail(&t->entry2, &sleep_threads); } md_run(); diff --git a/accel-pptpd/triton/triton.h b/accel-pptpd/triton/triton.h index 6f70275..6809df0 100644 --- a/accel-pptpd/triton/triton.h +++ b/accel-pptpd/triton/triton.h @@ -76,10 +76,15 @@ int triton_context_call(struct triton_context_t *, void (*func)(void *), void *a #define MD_MODE_READ 1 #define MD_MODE_WRITE 2 + +#define MD_TRIG_EDGE 0 +#define MD_TRIG_LEVEL 1 + void triton_md_register_handler(struct triton_context_t *, struct triton_md_handler_t *); void triton_md_unregister_handler(struct triton_md_handler_t *h); int triton_md_enable_handler(struct triton_md_handler_t *h, int mode); int triton_md_disable_handler(struct triton_md_handler_t *h,int mode); +void triton_md_set_trig(struct triton_md_handler_t *h, int mode); int triton_timer_add(struct triton_context_t *ctx, struct triton_timer_t*,int abs_time); int triton_timer_mod(struct triton_timer_t *,int abs_time); diff --git a/accel-pptpd/triton/triton_p.h b/accel-pptpd/triton/triton_p.h index 7c0615f..c685051 100644 --- a/accel-pptpd/triton/triton_p.h +++ b/accel-pptpd/triton/triton_p.h @@ -40,6 +40,7 @@ struct _triton_context_t int queued:1; int sleeping:1; + int wakeup:1; int need_close:1; int need_free:1; int pending:1; @@ -56,6 +57,7 @@ struct _triton_md_handler_t struct epoll_event epoll_event; uint32_t trig_epoll_events; int pending:1; + int trig_level:1; struct triton_md_handler_t *ud; }; |