diff options
author | Kozlov Dmitry <dima@server> | 2010-09-02 19:01:47 +0400 |
---|---|---|
committer | Kozlov Dmitry <dima@server> | 2010-09-02 19:01:47 +0400 |
commit | b43d224c8a306ff54bbb913c5aab891f82541f6e (patch) | |
tree | c3b6c135030fcd4bba4a2ea44d21745fba254a6c | |
parent | 81515c09f55f152e8330c3b43ad159be64f494e8 (diff) | |
download | accel-ppp-b43d224c8a306ff54bbb913c5aab891f82541f6e.tar.gz accel-ppp-b43d224c8a306ff54bbb913c5aab891f82541f6e.zip |
rewriting triton library ...
-rw-r--r-- | accel-pptpd/CMakeLists.txt | 3 | ||||
-rw-r--r-- | accel-pptpd/main.c | 121 | ||||
-rw-r--r-- | accel-pptpd/ppp.c | 107 | ||||
-rw-r--r-- | accel-pptpd/ppp.h | 13 | ||||
-rw-r--r-- | accel-pptpd/pptp.c | 128 | ||||
-rw-r--r-- | accel-pptpd/triton/CMakeLists.txt | 3 | ||||
-rw-r--r-- | accel-pptpd/triton/conf_file.c | 17 | ||||
-rw-r--r-- | accel-pptpd/triton/log.c | 8 | ||||
-rw-r--r-- | accel-pptpd/triton/md.c | 19 | ||||
-rw-r--r-- | accel-pptpd/triton/timer.c | 6 | ||||
-rw-r--r-- | accel-pptpd/triton/triton.c | 15 | ||||
-rw-r--r-- | accel-pptpd/triton/triton.h | 16 |
12 files changed, 273 insertions, 183 deletions
diff --git a/accel-pptpd/CMakeLists.txt b/accel-pptpd/CMakeLists.txt index d68cbe91..e22bdc69 100644 --- a/accel-pptpd/CMakeLists.txt +++ b/accel-pptpd/CMakeLists.txt @@ -6,7 +6,6 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fvisibility=hidden -D_GNU_SOURCE") ADD_SUBDIRECTORY(triton) ADD_EXECUTABLE(pptpd - main.c pptp.c log.c ppp.c @@ -32,5 +31,7 @@ ADD_EXECUTABLE(pptpd pwdb.c ipdb.c + + main.c ) TARGET_LINK_LIBRARIES(pptpd pthread triton ssl) diff --git a/accel-pptpd/main.c b/accel-pptpd/main.c index 90f206df..31069f31 100644 --- a/accel-pptpd/main.c +++ b/accel-pptpd/main.c @@ -4,38 +4,64 @@ #include <stdlib.h> #include <stdio.h> #include <sys/stat.h> +#include <sys/mman.h> #include "triton/triton.h" -void sigterm(int num) +static int goto_daemon; +static char *pid_file; +static char *conf_file; + +static void sigterm(int num) { } -int main(int argc,char **argv) -{ + +#define ARG_MAX 128 +static int parse_cmdline(char ***argv) +{ + FILE *f; int i; - int daemon=0; - char *pid_file=NULL; - char *conf_file=NULL; - sigset_t set; + size_t len; - if (argc<2) - goto usage; + f = fopen("/proc/self/cmdline", "r"); + if (!f) { + perror("open cmdline"); + _exit(EXIT_FAILURE); + } - for(i=1; i<argc; i++) + *argv = malloc(ARG_MAX * sizeof(void *)); + memset(*argv, 0, ARG_MAX * sizeof(void *)); + + for(i = 0; i < ARG_MAX; i++) { - if (!strcmp(argv[i],"-d")) - daemon=1; - else if (!strcmp(argv[i],"-p")) - { - if (i==argc-1) + len = 0; + if (getdelim(&(*argv)[i], &len, 0, f) < 0) + break; + } + + return i; +} +static void __init __main(void) +{ + int i,argc; + char **argv; + + argc=parse_cmdline(&argv); + + if (argc < 2) + goto usage; + + for(i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-d")) + goto_daemon = 1; + else if (!strcmp(argv[i], "-p")) { + if (i == argc - 1) goto usage; - pid_file=argv[++i]; - } - else if (!strcmp(argv[i],"-c")) - { - if (i==argc-1) + pid_file = argv[++i]; + } else if (!strcmp(argv[i], "-c")) { + if (i == argc - 1) goto usage; - conf_file=argv[++i]; + conf_file = argv[++i]; } } @@ -43,21 +69,33 @@ int main(int argc,char **argv) goto usage; if (triton_init(conf_file)) - return EXIT_FAILURE; - - if (daemon) - { - pid_t pid=fork(); - if (pid>0) + _exit(EXIT_FAILURE); + + return; + +usage: + printf("usage: pptpd [-d] [-p <file>] -c <file>\n\ + where:\n\ + -d - daemon mode\n\ + -p - write pid to <file>\n\ + -c - config file\n"); + _exit(EXIT_FAILURE); +} +int main(int argc, char **argv) +{ + sigset_t set; + + if (goto_daemon) { + pid_t pid = fork(); + if (pid > 0) _exit(EXIT_SUCCESS); - if (pid<0) - { + if (pid < 0) { perror("fork"); return EXIT_FAILURE; } - if (setsid()<0) - return EXIT_FAILURE; - pid=fork(); + if (setsid() < 0) + _exit(EXIT_FAILURE); + pid = fork(); if (pid) _exit(0); umask(0); @@ -67,19 +105,17 @@ int main(int argc,char **argv) close(STDERR_FILENO); } - if (pid_file) - { - FILE *f=fopen("pid_file","w"); - if (f) - { - fprintf(f,"%i",getpid()); + if (pid_file) { + FILE *f = fopen("pid_file", "w"); + if (f) { + fprintf(f, "%i", getpid()); fclose(f); } } triton_run(); - signal(SIGTERM,sigterm); + signal(SIGTERM, sigterm); sigfillset(&set); sigdelset(&set, SIGTERM); sigdelset(&set, SIGSEGV); @@ -92,12 +128,5 @@ int main(int argc,char **argv) triton_terminate(); return EXIT_SUCCESS; -usage: - printf("usage: pptpd [-d] [-p <file>] -c <file>\ - where:\ - -d - daemon mode\ - -p - write pid to <file>\ - -c - config file\n"); - return EXIT_FAILURE; } diff --git a/accel-pptpd/ppp.c b/accel-pptpd/ppp.c index b4388718..2ba41f1b 100644 --- a/accel-pptpd/ppp.c +++ b/accel-pptpd/ppp.c @@ -5,6 +5,7 @@ #include <stdlib.h> #include <stdint.h> #include <string.h> +#include <errno.h> #include <sys/ioctl.h> #include <arpa/inet.h> #include <linux/ppp_defs.h> @@ -101,9 +102,21 @@ int establish_ppp(struct ppp_t *ppp) 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)); + 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)); + goto exit_close_unit; + } + + ppp->chan_hnd.ctx=ppp->ctrl->ctx; ppp->chan_hnd.fd=ppp->chan_fd; ppp->chan_hnd.read=ppp_chan_read; //ppp->chan_hnd.twait=-1; + ppp->unit_hnd.ctx=ppp->ctrl->ctx; ppp->unit_hnd.fd=ppp->unit_fd; ppp->unit_hnd.read=ppp_unit_read; //ppp->unit_hnd.twait=-1; @@ -179,66 +192,80 @@ int ppp_unit_send(struct ppp_t *ppp, void *data, int size) return n; } -static int ppp_chan_read(struct triton_md_handler_t*h) +static int ppp_chan_read(struct triton_md_handler_t *h) { - struct ppp_t *ppp=container_of(h,typeof(*ppp),chan_hnd); + struct ppp_t *ppp = container_of(h, typeof(*ppp), chan_hnd); struct ppp_handler_t *ppp_h; uint16_t proto; - ppp->chan_buf_size=read(h->fd,ppp->chan_buf,PPP_MRU); + while(1) { +cont: + ppp->chan_buf_size = read(h->fd, ppp->chan_buf, PPP_MRU); + if (ppp->chan_buf_size < 0) { + if (errno == EINTR) + continue; + if (errno == EAGAIN) + return 0; + log_error("ppp_chan_read: %s\n",strerror(errno)); + return 0; + } - //printf("ppp_chan_read: "); - //print_buf(ppp->chan_buf,ppp->chan_buf_size); + //printf("ppp_chan_read: "); + //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); - return 0; - } + if (ppp->chan_buf_size < 2) { + log_error("ppp_chan_read: short read %i\n", ppp->chan_buf_size); + continue; + } - proto=ntohs(*(uint16_t*)ppp->chan_buf); - list_for_each_entry(ppp_h,&ppp->chan_handlers,entry) - { - if (ppp_h->proto==proto) - { - ppp_h->recv(ppp_h); - return 0; + proto = ntohs(*(uint16_t*)ppp->chan_buf); + list_for_each_entry(ppp_h, &ppp->chan_handlers, entry) { + if (ppp_h->proto == proto) { + ppp_h->recv(ppp_h); + goto cont; + } } - } - log_warn("ppp_chan_read: discarding unknown packet %x\n",proto); - return 0; + log_warn("ppp_chan_read: discarding unknown packet %x\n", proto); + } } -static int ppp_unit_read(struct triton_md_handler_t*h) +static int ppp_unit_read(struct triton_md_handler_t *h) { - struct ppp_t *ppp=container_of(h,typeof(*ppp),unit_hnd); + struct ppp_t *ppp = container_of(h, typeof(*ppp), unit_hnd); struct ppp_handler_t *ppp_h; uint16_t proto; - ppp->unit_buf_size=read(h->fd,ppp->unit_buf,PPP_MRU); + while (1) { +cont: + ppp->unit_buf_size = read(h->fd, ppp->unit_buf, PPP_MRU); + if (ppp->unit_buf_size < 0) { + if (errno == EINTR) + continue; + if (errno == EAGAIN) + return 0; + log_error("ppp_chan_read: %s\n",strerror(errno)); + return 0; + } - printf("ppp_unit_read: "); - print_buf(ppp->unit_buf,ppp->unit_buf_size); + //printf("ppp_unit_read: "); + //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); - return 0; - } + if (ppp->unit_buf_size < 2) { + log_error("ppp_chan_read: short read %i\n", ppp->unit_buf_size); + continue; + } - proto=ntohs(*(uint16_t*)ppp->unit_buf); - list_for_each_entry(ppp_h,&ppp->unit_handlers,entry) - { - if (ppp_h->proto==proto) - { - ppp_h->recv(ppp_h); - return 0; + proto=ntohs(*(uint16_t*)ppp->unit_buf); + list_for_each_entry(ppp_h, &ppp->unit_handlers, entry) { + if (ppp_h->proto == proto) { + ppp_h->recv(ppp_h); + goto cont; + } } - } - log_warn("ppp_chan_read: discarding unknown packet %x\n",proto); - return 0; + log_warn("ppp_chan_read: discarding unknown packet %x\n",proto); + } } void ppp_layer_started(struct ppp_t *ppp, struct ppp_layer_data_t *d) diff --git a/accel-pptpd/ppp.h b/accel-pptpd/ppp.h index 6dd05bea..a0a6f0ed 100644 --- a/accel-pptpd/ppp.h +++ b/accel-pptpd/ppp.h @@ -136,17 +136,4 @@ int ppp_register_layer(const char *name, struct ppp_layer_t *); void ppp_unregister_layer(struct ppp_layer_t *); struct ppp_layer_data_t *ppp_find_layer_data(struct ppp_t *, struct ppp_layer_t *); -#define __init __attribute__((constructor)) - -#undef offsetof -#ifdef __compiler_offsetof -#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER) -#else -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) -#endif - -#define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) - #endif diff --git a/accel-pptpd/pptp.c b/accel-pptpd/pptp.c index 1ec35c8f..f932e0b6 100644 --- a/accel-pptpd/pptp.c +++ b/accel-pptpd/pptp.c @@ -1,21 +1,10 @@ -/* -* C Implementation: ctrl -* -* 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 <stdarg.h> #include <errno.h> #include <string.h> +#include <fcntl.h> #include <arpa/inet.h> #include <netinet/in.h> @@ -296,27 +285,34 @@ static int pptp_read(struct triton_md_handler_t *h) struct pptp_header *hdr=(struct pptp_header *)conn->in_buf; int n; - n=read(h->fd,conn->in_buf,PPTP_CTRL_SIZE_MAX-conn->in_size); - if (n<=0) - { - if (errno==EAGAIN) return 0; - goto drop; - } - conn->in_size+=n; - if (conn->in_size>=sizeof(*hdr)) - { - if (hdr->magic!=htonl(PPTP_MAGIC)) goto drop; - if (ntohs(hdr->length)>=PPTP_CTRL_SIZE_MAX) goto drop; - if (ntohs(hdr->length)>conn->in_size) goto drop; - if (ntohs(hdr->length)==conn->in_size) + while(1) { + n = read(h->fd,conn->in_buf,PPTP_CTRL_SIZE_MAX-conn->in_size); + if (n <= 0) { - if (ntohs(hdr->length)!=PPTP_CTRL_SIZE(ntohs(hdr->ctrl_type))) goto drop; - if (process_packet(conn)) goto drop; - conn->in_size=0; + if (errno == EINTR) + continue; + if (errno == EAGAIN) + return 0; + log_error("pptp: read: %s\n",strerror(errno)); + goto drop; + } + conn->in_size += n; + if (conn->in_size >= sizeof(*hdr)) { + if (hdr->magic != htonl(PPTP_MAGIC)) + goto drop; + if (ntohs(hdr->length) >= PPTP_CTRL_SIZE_MAX) + goto drop; + if (ntohs(hdr->length) > conn->in_size) + goto drop; + if (ntohs(hdr->length) == conn->in_size) { + if (ntohs(hdr->length) != PPTP_CTRL_SIZE(ntohs(hdr->ctrl_type))) + goto drop; + if (process_packet(conn)) + goto drop; + conn->in_size = 0; + } } } - //h->twait=TIMEOUT; - return 0; drop: disconnect(conn); return 1; @@ -391,30 +387,37 @@ struct pptp_serv_t static int pptp_connect(struct triton_md_handler_t *h) { struct sockaddr_in addr; - socklen_t size=sizeof(addr); + socklen_t size = sizeof(addr); int sock; struct pptp_conn_t *conn; - while(1) - { - sock=accept(h->fd,(struct sockaddr *)&addr,&size); - if (sock<0) - { - if (errno==EAGAIN) + while(1) { + sock = accept(h->fd, (struct sockaddr *)&addr, &size); + if (sock < 0) { + if (errno == EAGAIN) return 0; - log_error("pptp: accept failed\n"); - continue; + log_error("pptp: accept failed: %s\n", strerror(errno)); + continue; + } + + log_info("pptp: new connection from %s\n", inet_ntoa(addr.sin_addr)); + + if (fcntl(sock, F_SETFL, O_NONBLOCK)) { + log_error("pptp: failed to set nonblocking mode: %s, closing connection...\n", strerror(errno)); + close(sock); + continue; } - conn=malloc(sizeof(*conn)); - memset(conn,0,sizeof(*conn)); - conn->hnd.fd=sock; - conn->hnd.read=pptp_read; - conn->hnd.write=pptp_write; - conn->ctx.close=pptp_close; - conn->ctx.free=pptp_free; - conn->hnd.ctx=&conn->ctx; - conn->in_buf=malloc(PPTP_CTRL_SIZE_MAX); - conn->out_buf=malloc(PPTP_CTRL_SIZE_MAX); + + conn = malloc(sizeof(*conn)); + memset(conn, 0, sizeof(*conn)); + conn->hnd.fd = sock; + conn->hnd.read = pptp_read; + conn->hnd.write = pptp_write; + conn->ctx.close = pptp_close; + conn->ctx.free = pptp_free; + conn->hnd.ctx = &conn->ctx; + conn->in_buf = malloc(PPTP_CTRL_SIZE_MAX); + conn->out_buf = malloc(PPTP_CTRL_SIZE_MAX); triton_register_ctx(&conn->ctx); triton_md_register_handler(&conn->hnd); @@ -436,36 +439,39 @@ static struct pptp_serv_t serv= .hnd.ctx=&serv.ctx, }; -void __init pptp_init() +void __init pptp_init(void) { struct sockaddr_in addr; - serv.hnd.fd=socket (PF_INET, SOCK_STREAM, 0); - if (serv.hnd.fd<0) - { - log_error("pptp: failed to create server socket\n"); + serv.hnd.fd = socket (PF_INET, SOCK_STREAM, 0); + if (serv.hnd.fd < 0) { + log_error("pptp: failed to create server socket: %s\n", strerror(errno)); return; } addr.sin_family = AF_INET; addr.sin_port = htons (PPTP_PORT); addr.sin_addr.s_addr = htonl (INADDR_ANY); - if (bind (serv.hnd.fd, (struct sockaddr *) &addr, sizeof (addr)) < 0) - { + if (bind (serv.hnd.fd, (struct sockaddr *) &addr, sizeof (addr)) < 0) { perror("pptp: bind"); - log_error("pptp: failed to bind socket\n"); + log_error("pptp: failed to bind socket: %s\n", strerror(errno)); close(serv.hnd.fd); return; } - if (listen (serv.hnd.fd, 100)<0) - { - log_error("pptp: failed to listen socket\n"); + if (listen (serv.hnd.fd, 100) < 0) { + log_error("pptp: failed to listen socket: %s\n", strerror(errno)); close(serv.hnd.fd); return; } + + if (fcntl(serv.hnd.fd, F_SETFL, O_NONBLOCK)) { + log_error("pptp: failed to set nonblocking mode: %s\n", strerror(errno)); + close(serv.hnd.fd); + return; + } triton_register_ctx(&serv.ctx); triton_md_register_handler(&serv.hnd); - triton_md_enable_handler(&serv.hnd,MD_MODE_READ); + triton_md_enable_handler(&serv.hnd, MD_MODE_READ); } diff --git a/accel-pptpd/triton/CMakeLists.txt b/accel-pptpd/triton/CMakeLists.txt index c78703d1..b11025d8 100644 --- a/accel-pptpd/triton/CMakeLists.txt +++ b/accel-pptpd/triton/CMakeLists.txt @@ -10,4 +10,5 @@ SET(sources_c INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) ADD_DEFINITIONS("-DUSE_SPINLOCK") -ADD_LIBRARY(${target} STATIC ${sources_c}) +ADD_LIBRARY(${target} SHARED ${sources_c}) + diff --git a/accel-pptpd/triton/conf_file.c b/accel-pptpd/triton/conf_file.c index b0bc58b7..e99afaa9 100644 --- a/accel-pptpd/triton/conf_file.c +++ b/accel-pptpd/triton/conf_file.c @@ -164,8 +164,23 @@ static struct conf_option_t *find_item(struct conf_sect_t *sect, const char *nam return NULL; } -struct conf_sect_t *conf_file_get_section(const char *name) +struct conf_sect_t * conf_get_section(const char *name) { return find_sect(name); } +char * conf_get_opt(const char *sect, const char *name) +{ + struct conf_option_t *opt; + struct conf_sect_t *s = conf_get_section(sect); + + if (!s) + return NULL; + + opt = find_item(s, name); + if (!opt) + return NULL; + + return opt->val; +} + diff --git a/accel-pptpd/triton/log.c b/accel-pptpd/triton/log.c index 7ff90f87..4504db4f 100644 --- a/accel-pptpd/triton/log.c +++ b/accel-pptpd/triton/log.c @@ -9,8 +9,8 @@ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; int log_init(void) { - char *log_error = conf_get_opt("core","log_error"); - char *log_debug = conf_get_opt("core","log_debug"); + char *log_error = conf_get_opt("core","log-error"); + char *log_debug = conf_get_opt("core","log-debug"); if (log_error) { f_error = fopen(log_error, "a"); @@ -48,8 +48,10 @@ static void do_log(FILE *f, const char *fmt, va_list ap) void triton_log_error(const char *fmt,...) { va_list ap; + if (!f_error) return; + va_start(ap, fmt); do_log(f_error, fmt, ap); } @@ -57,8 +59,10 @@ void triton_log_error(const char *fmt,...) void triton_log_debug(const char *fmt,...) { va_list ap; + if (!f_debug) return; + va_start(ap, fmt); do_log(f_debug, fmt, ap); } diff --git a/accel-pptpd/triton/md.c b/accel-pptpd/triton/md.c index 874e4948..c1aefcf6 100644 --- a/accel-pptpd/triton/md.c +++ b/accel-pptpd/triton/md.c @@ -63,10 +63,13 @@ static void *md_thread(void *arg) for(i = 0; i < n; i++) { h = (struct triton_md_handler_t *)epoll_events[i].data.ptr; spin_lock(&h->ctx->lock); - h->trig_epoll_events = epoll_events[i].events; - list_add_tail(&h->entry2, &h->ctx->pending_handlers); - h->pending = 1; - r=triton_queue_ctx(h->ctx); + h->trig_epoll_events |= epoll_events[i].events; + if (!h->pending) { + list_add_tail(&h->entry2, &h->ctx->pending_handlers); + h->pending = 1; + r = triton_queue_ctx(h->ctx); + } else + r = 0; spin_unlock(&h->ctx->lock); if (r) triton_thread_wakeup(h->ctx->thread); @@ -76,7 +79,7 @@ static void *md_thread(void *arg) return NULL; } -void triton_md_register_handler(struct triton_md_handler_t *h) +void __export triton_md_register_handler(struct triton_md_handler_t *h) { h->epoll_event.data.ptr = h; if (!h->ctx) @@ -85,7 +88,7 @@ void triton_md_register_handler(struct triton_md_handler_t *h) list_add_tail(&h->entry, &h->ctx->handlers); spin_unlock(&h->ctx->lock); } -void triton_md_unregister_handler(struct triton_md_handler_t *h) +void __export triton_md_unregister_handler(struct triton_md_handler_t *h) { spin_lock(&h->ctx->lock); list_del(&h->entry); @@ -93,7 +96,7 @@ void triton_md_unregister_handler(struct triton_md_handler_t *h) list_del(&h->entry2); spin_unlock(&h->ctx->lock); } -int triton_md_enable_handler(struct triton_md_handler_t *h, int mode) +int __export triton_md_enable_handler(struct triton_md_handler_t *h, int mode) { int r; int events = h->epoll_event.events; @@ -115,7 +118,7 @@ int triton_md_enable_handler(struct triton_md_handler_t *h, int mode) return r; } -int triton_md_disable_handler(struct triton_md_handler_t *h,int mode) +int __export triton_md_disable_handler(struct triton_md_handler_t *h,int mode) { int r=0; diff --git a/accel-pptpd/triton/timer.c b/accel-pptpd/triton/timer.c index 92187be7..5f7de93e 100644 --- a/accel-pptpd/triton/timer.c +++ b/accel-pptpd/triton/timer.c @@ -76,7 +76,7 @@ void *timer_thread(void *arg) return NULL; } -int triton_timer_add(struct triton_timer_t *t, int abs_time) +int __export triton_timer_add(struct triton_timer_t *t, int abs_time) { t->epoll_event.data.ptr = t; t->epoll_event.events = EPOLLIN | EPOLLET; @@ -108,7 +108,7 @@ int triton_timer_add(struct triton_timer_t *t, int abs_time) return 0; } -int triton_timer_mod(struct triton_timer_t *t,int abs_time) +int __export triton_timer_mod(struct triton_timer_t *t,int abs_time) { struct itimerspec ts = { .it_value.tv_sec = t->expire_tv.tv_sec, @@ -127,7 +127,7 @@ int triton_timer_mod(struct triton_timer_t *t,int abs_time) return 0; } -void triton_timer_del(struct triton_timer_t *t) +void __export triton_timer_del(struct triton_timer_t *t) { epoll_ctl(epoll_fd, EPOLL_CTL_DEL, t->fd, &t->epoll_event); close(t->fd); diff --git a/accel-pptpd/triton/triton.c b/accel-pptpd/triton/triton.c index 2b160a91..121e6957 100644 --- a/accel-pptpd/triton/triton.c +++ b/accel-pptpd/triton/triton.c @@ -7,7 +7,7 @@ #include "triton_p.h" -int thread_count = 64; +int thread_count = 4; int max_events = 64; static spinlock_t threads_lock = SPINLOCK_INITIALIZER; @@ -66,7 +66,7 @@ cont: if (h->read) if (h->read(h)) continue; - if (h->trig_epoll_events & EPOLLOUT) + if (h->trig_epoll_events & (EPOLLOUT | EPOLLERR | EPOLLHUP)) if (h->write) if (h->write(h)) continue; @@ -130,13 +130,14 @@ int triton_queue_ctx(struct triton_ctx_t *ctx) } ctx->thread = list_entry(sleep_threads.next, typeof(*ctx->thread), entry2); + ctx->thread->ctx = ctx; list_del(&ctx->thread->entry2); spin_unlock(&threads_lock); return 1; } -void triton_register_ctx(struct triton_ctx_t *ctx) +void __export triton_register_ctx(struct triton_ctx_t *ctx) { spinlock_init(&ctx->lock); INIT_LIST_HEAD(&ctx->handlers); @@ -149,7 +150,7 @@ void triton_register_ctx(struct triton_ctx_t *ctx) spin_unlock(&ctx_list_lock); } -void triton_unregister_ctx(struct triton_ctx_t *ctx) +void __export triton_unregister_ctx(struct triton_ctx_t *ctx) { ctx->need_free = 1; spin_lock(&ctx_list_lock); @@ -157,7 +158,7 @@ void triton_unregister_ctx(struct triton_ctx_t *ctx) spin_unlock(&ctx_list_lock); } -int triton_init(const char *conf_file) +int __export triton_init(const char *conf_file) { default_ctx=malloc(sizeof(*default_ctx)); if (!default_ctx) { @@ -181,7 +182,7 @@ int triton_init(const char *conf_file) return 0; } -void triton_run() +void __export triton_run() { struct triton_thread_t *t; int i; @@ -199,7 +200,7 @@ void triton_run() timer_run(); } -void triton_terminate() +void __export triton_terminate() { struct triton_ctx_t *ctx; struct triton_thread_t *t; diff --git a/accel-pptpd/triton/triton.h b/accel-pptpd/triton/triton.h index 73640219..2cc4edb4 100644 --- a/accel-pptpd/triton/triton.h +++ b/accel-pptpd/triton/triton.h @@ -115,4 +115,20 @@ int triton_init(const char *conf_file); void triton_run(void); void triton_terminate(void); + +#define __init __attribute__((constructor)) + +#undef offsetof +#ifdef __compiler_offsetof +#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER) +#else +#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#endif + +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + +#define __export __attribute__((visibility("default"))) + #endif |