summaryrefslogtreecommitdiff
path: root/accel-pptpd
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2010-09-26 20:25:21 +0400
committerDmitry Kozlov <xeb@mail.ru>2010-09-26 20:25:21 +0400
commitf122327288ae4429bb88a0fefdcef0bf80f54023 (patch)
treeed614bad3d0d1e156e39683da1d30871cad54c94 /accel-pptpd
parent863e1de3aa67a03bdf2b9720b32eafe6670b29a3 (diff)
downloadaccel-ppp-f122327288ae4429bb88a0fefdcef0bf80f54023.tar.gz
accel-ppp-f122327288ae4429bb88a0fefdcef0bf80f54023.zip
various bug fixed and improvements
Diffstat (limited to 'accel-pptpd')
-rw-r--r--accel-pptpd/accel-pptpd.conf5
-rw-r--r--accel-pptpd/extra/pppd_compat.c8
-rw-r--r--accel-pptpd/include/events.h10
-rw-r--r--accel-pptpd/log.c5
-rw-r--r--accel-pptpd/logs/log_file.c41
-rw-r--r--accel-pptpd/memdebug.c27
-rw-r--r--accel-pptpd/memdebug.h1
-rw-r--r--accel-pptpd/ppp/ppp.c1
-rw-r--r--accel-pptpd/radius/packet.c28
-rw-r--r--accel-pptpd/sigchld.c2
-rw-r--r--accel-pptpd/triton/spinlock.h2
-rw-r--r--accel-pptpd/triton/triton.c3
12 files changed, 106 insertions, 27 deletions
diff --git a/accel-pptpd/accel-pptpd.conf b/accel-pptpd/accel-pptpd.conf
index 356b5f02..d14fe180 100644
--- a/accel-pptpd/accel-pptpd.conf
+++ b/accel-pptpd/accel-pptpd.conf
@@ -1,5 +1,5 @@
[modules]
-#./liblog_file.so
+./liblog_file.so
./liblog_pgsql.so
./libpptp.so
./libauth_pap.so
@@ -39,6 +39,7 @@ verbose=1
192.168.10.20-20
192.168.10.6/32
192.168.10.1/32
+192.168.11.0/24
[ip-pool]
gw-ip-address=192.168.100.1
@@ -55,7 +56,7 @@ log-emerg=/dev/stderr
log-debug=debug.log
copy=1
#color=1
-per-user-dir=per_user
+#per-user-dir=per_user
per-session-dir=per_session
#per-session=1
diff --git a/accel-pptpd/extra/pppd_compat.c b/accel-pptpd/extra/pppd_compat.c
index dbba96d7..e45d609a 100644
--- a/accel-pptpd/extra/pppd_compat.c
+++ b/accel-pptpd/extra/pppd_compat.c
@@ -117,7 +117,7 @@ static void ev_ppp_started(struct ppp_t *ppp)
sigchld_unlock();
} else if (pid == 0) {
execv(conf_ip_up, argv);
- log_error("pppd_compat: exec '%s': %s\n", conf_ip_up, strerror(errno));
+ log_emerg("pppd_compat: exec '%s': %s\n", conf_ip_up, strerror(errno));
_exit(EXIT_FAILURE);
} else
log_error("pppd_compat: fork: %s\n", strerror(errno));
@@ -159,9 +159,11 @@ static void ev_ppp_finished(struct ppp_t *ppp)
log_ppp_debug("pppd_compat: ip-down started (pid %i)\n", pid);
sigchld_unlock();
triton_context_schedule(pd->ppp->ctrl->ctx);
+ pthread_mutex_lock(&pd->ip_down_hnd.lock);
+ pthread_mutex_unlock(&pd->ip_down_hnd.lock);
} else if (pid == 0) {
execv(conf_ip_down, argv);
- log_error("pppd_compat: exec '%s': %s\n", conf_ip_change, strerror(errno));
+ log_emerg("pppd_compat: exec '%s': %s\n", conf_ip_change, strerror(errno));
_exit(EXIT_FAILURE);
} else
log_error("pppd_compat: fork: %s\n", strerror(errno));
@@ -222,7 +224,7 @@ static void ev_radius_coa(struct ev_radius_t *ev)
ev->res = pd->ip_change_res;
} else if (pid == 0) {
execv(conf_ip_change, argv);
- log_error("pppd_compat: exec '%s': %s\n", conf_ip_change, strerror(errno));
+ log_emerg("pppd_compat: exec '%s': %s\n", conf_ip_change, strerror(errno));
_exit(EXIT_FAILURE);
} else
log_error("pppd_compat: fork: %s\n", strerror(errno));
diff --git a/accel-pptpd/include/events.h b/accel-pptpd/include/events.h
index 0b37d0fd..f3278cb2 100644
--- a/accel-pptpd/include/events.h
+++ b/accel-pptpd/include/events.h
@@ -10,7 +10,8 @@
#define EV_CTRL_STARTED 7
#define EV_CTRL_FINISHED 8
#define EV_IP_CHANGED 100
-#define EV_SHAPE_CHANGED 101
+#define EV_SHAPE_CHANGED 101
+#define EV_MPPE_KEYS 102
#define EV_RADIUS_ACCESS_ACCEPT 200
#define EV_RADIUS_COA 201
@@ -24,5 +25,12 @@ struct ev_radius_t
int res;
};
+struct ev_mppe_keys_t
+{
+ struct ppp_t *ppp;
+ uint8_t *recv_key;
+ uint8_t *send_key;
+};
+
#endif
diff --git a/accel-pptpd/log.c b/accel-pptpd/log.c
index 60ac57e4..fee1b548 100644
--- a/accel-pptpd/log.c
+++ b/accel-pptpd/log.c
@@ -42,7 +42,7 @@ 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 __thread char *stat_buf;
static FILE *emerg_file;
static FILE *debug_file;
@@ -58,6 +58,9 @@ static void do_log(int level, const char *fmt, va_list ap, struct ppp_t *ppp)
struct log_target_t *t;
struct log_msg_t *m;
+ if (!stat_buf)
+ stat_buf = _malloc(LOG_MAX_SIZE + 1);
+
vsnprintf(stat_buf, LOG_MAX_SIZE, fmt, ap);
if (!cur_msg) {
diff --git a/accel-pptpd/logs/log_file.c b/accel-pptpd/logs/log_file.c
index c364fbd5..79af4c68 100644
--- a/accel-pptpd/logs/log_file.c
+++ b/accel-pptpd/logs/log_file.c
@@ -35,6 +35,8 @@ struct log_file_t
int fd;
off_t offset;
+ int cnt;
+ uint64_t magic;
};
struct log_file_pd_t
@@ -74,11 +76,14 @@ static uint64_t temp_seq;
static void send_next_chunk();
+#define MAGIC 0x9988776655443322llu
+
static void log_file_init(struct log_file_t *lf)
{
spinlock_init(&lf->lock);
INIT_LIST_HEAD(&lf->msgs);
lf->fd = -1;
+ lf->magic = MAGIC;
}
static int log_file_open(struct log_file_t *lf, const char *fname)
@@ -99,13 +104,22 @@ static void sigio(int num, siginfo_t *si, void *uc)
struct log_file_t *lf;
int n;
+ if (si->si_signo != SIGIO)
+ return;
+
+ if (si->si_code != SI_ASYNCIO) {
+ if (aio_write(&aiocb))
+ log_emerg("log_file: aio_write: %s\n", strerror(errno));
+ return;
+ }
+
lf = (struct log_file_t *)si->si_ptr;
n = aio_return(&aiocb);
if (n < 0)
log_emerg("log_file: %s\n", strerror(aio_error(&aiocb)));
- else if (n < aiocb.aio_nbytes)
- log_emerg("log_file: short write %i %lu\n", n, aiocb.aio_nbytes);
+ else if (n != aiocb.aio_nbytes)
+ log_emerg("log_file: short write %p %i %lu\n", lf, n, aiocb.aio_nbytes);
spin_lock(&lf->lock);
lf->offset += n;
@@ -145,16 +159,16 @@ static int dequeue_log(struct log_file_t *lf)
list_del(&msg->entry);
spin_unlock(&lf->lock);
+ if (pos + msg->hdr->len > LOG_BUF_SIZE)
+ goto overrun;
memcpy(log_buf + pos, msg->hdr->msg, msg->hdr->len);
n = msg->hdr->len;
- if (pos + n > LOG_BUF_SIZE)
- goto overrun;
list_for_each_entry(chunk, msg->chunks, entry) {
+ if (pos + n + chunk->len > LOG_BUF_SIZE)
+ goto overrun;
memcpy(log_buf + pos + n, chunk->msg, chunk->len);
n += chunk->len;
- if (pos + n > LOG_BUF_SIZE)
- goto overrun;
}
log_free_msg(msg);
@@ -172,6 +186,7 @@ overrun:
static void send_next_chunk(void)
{
struct log_file_t *lf;
+ int n;
spin_lock(&lf_queue_lock);
if (list_empty(&lf_queue)) {
@@ -180,13 +195,17 @@ static void send_next_chunk(void)
return;
}
lf = list_entry(lf_queue.next, typeof(*lf), entry);
+
+ n = log_file->entry.next == NULL;
list_del(&lf->entry);
+
spin_unlock(&lf_queue_lock);
aiocb.aio_fildes = lf->fd;
aiocb.aio_offset = lf->offset;
aiocb.aio_sigevent.sigev_value.sival_ptr = lf;
aiocb.aio_nbytes = dequeue_log(lf);
+ __sync_add_and_fetch(&lf->cnt, 1);
if (aio_write(&aiocb))
log_emerg("log_file: aio_write: %s\n", strerror(errno));
@@ -261,8 +280,6 @@ static struct log_file_pd_t *find_pd(struct ppp_t *ppp, void *pd_key)
return lpd;
}
}
- //log_emerg("log:BUG: pd not found\n");
- //abort();
return NULL;
}
@@ -311,6 +328,7 @@ static void free_lpd(struct log_file_pd_t *lpd)
struct log_msg_t *msg;
spin_lock(&lpd->lf.lock);
+ list_del(&lpd->pd.entry);
lpd->lf.need_free = 1;
if (lpd->lf.queued)
spin_unlock(&lpd->lf.lock);
@@ -322,7 +340,6 @@ 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);
}
@@ -513,9 +530,15 @@ static struct log_target_t per_session_target =
static void __init init(void)
{
char *opt;
+
+ sigset_t set;
+ sigemptyset(&set);
+ sigaddset(&set, SIGIO);
+
struct sigaction sa = {
.sa_sigaction = sigio,
.sa_flags = SA_SIGINFO,
+ .sa_mask = set,
};
lpd_pool = mempool_create(sizeof(struct log_file_pd_t));
diff --git a/accel-pptpd/memdebug.c b/accel-pptpd/memdebug.c
index 780f16b8..2acdc7a8 100644
--- a/accel-pptpd/memdebug.c
+++ b/accel-pptpd/memdebug.c
@@ -147,7 +147,34 @@ static void siginfo(int num)
printf("total = %lu\n", total);
}
+static void siginfo2(int num)
+{
+ struct mem_t *mem;
+
+ spin_lock(&mem_list_lock);
+ list_for_each_entry(mem, &mem_list, entry) {
+ if (mem->magic1 != MAGIC1 || mem->magic2 != *(uint64_t*)(mem->data + mem->size))
+ printf("%s:%i %lu\n", mem->fname, mem->line, mem->size);
+ }
+ spin_unlock(&mem_list_lock);
+}
+
+void __export md_check(void *ptr)
+{
+ struct mem_t *mem = container_of(ptr, typeof(*mem), data);
+
+ if (!ptr)
+ abort();
+
+ if (mem->magic1 != MAGIC1)
+ abort();
+
+ if (mem->magic2 != *(uint64_t*)(mem->data + mem->size))
+ abort();
+}
+
static void __init init(void)
{
signal(36, siginfo);
+ signal(37, siginfo2);
}
diff --git a/accel-pptpd/memdebug.h b/accel-pptpd/memdebug.h
index ad57f4a8..dc6b9ad1 100644
--- a/accel-pptpd/memdebug.h
+++ b/accel-pptpd/memdebug.h
@@ -16,6 +16,7 @@ void *md_realloc(void *ptr, size_t size, const char *fname, int line);
void md_free(void *ptr, const char *fname, int line);
char* md_strdup(const char *ptr, const char *fname, int line);
char* md_strndup(const char *ptr, size_t size, const char *fname, int line);
+void md_check(void *ptr);
#else
#define _malloc(size) malloc(size)
diff --git a/accel-pptpd/ppp/ppp.c b/accel-pptpd/ppp/ppp.c
index 4deb1356..dfe5bbe0 100644
--- a/accel-pptpd/ppp/ppp.c
+++ b/accel-pptpd/ppp/ppp.c
@@ -296,6 +296,7 @@ cont:
return 0;
}
+ md_check(ppp->unit_buf);
//printf("ppp_unit_read: ");
//print_buf(ppp->unit_buf,ppp->unit_buf_size);
diff --git a/accel-pptpd/radius/packet.c b/accel-pptpd/radius/packet.c
index 28dbca89..e3d4cfc0 100644
--- a/accel-pptpd/radius/packet.c
+++ b/accel-pptpd/radius/packet.c
@@ -7,16 +7,20 @@
#include <fcntl.h>
#include "log.h"
+#include "mempool.h"
#include "radius_p.h"
#include "memdebug.h"
+static mempool_t packet_pool;
+static mempool_t attr_pool;
+
struct rad_packet_t *rad_packet_alloc(int code)
{
struct rad_packet_t *pack;
- pack = _malloc(sizeof(*pack));
+ pack = mempool_alloc(packet_pool);
if (!pack) {
log_emerg("radius:packet: out of memory\n");
return NULL;
@@ -171,7 +175,7 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr)
vendor = NULL;
da = rad_dict_find_attr_id(vendor, id);
if (da) {
- attr = _malloc(sizeof(*attr));
+ attr = mempool_alloc(attr_pool);
if (!attr) {
log_emerg("radius:packet: out of memory\n");
goto out_err;
@@ -234,10 +238,10 @@ void rad_packet_free(struct rad_packet_t *pack)
list_del(&attr->entry);
if (attr->attr->type == ATTR_TYPE_STRING || attr->attr->type == ATTR_TYPE_OCTETS)
_free(attr->val.string);
- _free(attr);
+ mempool_free(attr);
}
- _free(pack);
+ mempool_free(pack);
}
void rad_packet_print(struct rad_packet_t *pack, void (*print)(const char *fmt, ...))
@@ -325,7 +329,7 @@ int rad_packet_add_int(struct rad_packet_t *pack, const char *name, int val)
if (!attr)
return -1;
- ra = _malloc(sizeof(*ra));
+ ra = mempool_alloc(attr_pool);
if (!ra)
return -1;
@@ -364,7 +368,7 @@ int rad_packet_add_octets(struct rad_packet_t *pack, const char *name, uint8_t *
if (!attr)
return -1;
- ra = _malloc(sizeof(*ra));
+ ra = mempool_alloc(attr_pool);
if (!ra) {
log_emerg("radius: out of memory\n");
return -1;
@@ -397,7 +401,7 @@ int rad_packet_add_str(struct rad_packet_t *pack, const char *name, const char *
if (!attr)
return -1;
- ra = _malloc(sizeof(*ra));
+ ra = mempool_alloc(attr_pool);
if (!ra) {
log_emerg("radius: out of memory\n");
return -1;
@@ -465,7 +469,7 @@ int rad_packet_add_val(struct rad_packet_t *pack, const char *name, const char *
if (!v)
return -1;
- ra = _malloc(sizeof(*ra));
+ ra = mempool_alloc(attr_pool);
if (!ra)
return -1;
@@ -555,7 +559,7 @@ int rad_packet_add_vendor_octets(struct rad_packet_t *pack, const char *vendor_n
if (!attr)
return -1;
- ra = _malloc(sizeof(*ra));
+ ra = mempool_alloc(attr_pool);
if (!ra) {
log_emerg("radius: out of memory\n");
return -1;
@@ -595,3 +599,9 @@ struct rad_attr_t *rad_packet_find_vendor_attr(struct rad_packet_t *pack, const
return NULL;
}
+
+static void __init init(void)
+{
+ attr_pool = mempool_create(sizeof(struct rad_attr_t));
+ packet_pool = mempool_create(sizeof(struct rad_packet_t));
+}
diff --git a/accel-pptpd/sigchld.c b/accel-pptpd/sigchld.c
index fd07c0a6..19c76533 100644
--- a/accel-pptpd/sigchld.c
+++ b/accel-pptpd/sigchld.c
@@ -64,8 +64,8 @@ static void* sigchld_thread(void *arg)
}
pthread_mutex_unlock(&handlers_lock);
if (h0) {
- h0->handler(h0, WEXITSTATUS(status));
list_del(&h0->entry);
+ h0->handler(h0, WEXITSTATUS(status));
h0->pid = 0;
pthread_mutex_unlock(&h0->lock);
}
diff --git a/accel-pptpd/triton/spinlock.h b/accel-pptpd/triton/spinlock.h
index 5ef9c488..b13cde61 100644
--- a/accel-pptpd/triton/spinlock.h
+++ b/accel-pptpd/triton/spinlock.h
@@ -2,7 +2,7 @@
#define __TRITON_SPINLOCK_H
#ifdef GCC_SPINLOCK
-typedef unsigned char spinlock_t;
+typedef volatile unsigned char spinlock_t;
#define spin_lock(l) {while(__sync_lock_test_and_set(l,1));}
#define spin_unlock(l) __sync_lock_release(l)
#define SPINLOCK_INITIALIZER 0
diff --git a/accel-pptpd/triton/triton.c b/accel-pptpd/triton/triton.c
index ce880e96..d7939041 100644
--- a/accel-pptpd/triton/triton.c
+++ b/accel-pptpd/triton/triton.c
@@ -74,6 +74,9 @@ static void* triton_thread(struct _triton_thread_t *thread)
sigwait(&set, &sig);
//printf("thread %p: exit sigwait\n", thread);
__sync_fetch_and_add(&triton_stat.thread_active, 1);
+
+ if (!thread->ctx)
+ continue;
}
cont: