From eac0adf4b2b038690c761a126cb3e55a888060df Mon Sep 17 00:00:00 2001 From: Kozlov Dmitry Date: Thu, 9 Sep 2010 16:10:40 +0400 Subject: radius: implemented DM/CoA extensions --- accel-pptpd/triton/mempool.c | 4 ++++ accel-pptpd/triton/triton.c | 32 ++++++++++++++++++++++++++++++++ accel-pptpd/triton/triton.h | 1 + accel-pptpd/triton/triton_p.h | 9 +++++++++ 4 files changed, 46 insertions(+) (limited to 'accel-pptpd/triton') diff --git a/accel-pptpd/triton/mempool.c b/accel-pptpd/triton/mempool.c index 973fec5..dacb611 100644 --- a/accel-pptpd/triton/mempool.c +++ b/accel-pptpd/triton/mempool.c @@ -47,6 +47,10 @@ 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"); + return NULL; + } it->owner = p; it->magic = p->magic; return it->ptr; diff --git a/accel-pptpd/triton/triton.c b/accel-pptpd/triton/triton.c index ba08c12..4ecf0a8 100644 --- a/accel-pptpd/triton/triton.c +++ b/accel-pptpd/triton/triton.c @@ -23,6 +23,7 @@ struct triton_context_t *default_ctx; static int terminate; static mempool_t *ctx_pool; +static mempool_t *call_pool; void triton_thread_wakeup(struct _triton_thread_t *thread) { @@ -74,6 +75,7 @@ static void ctx_thread(struct _triton_context_t *ctx) { struct _triton_md_handler_t *h; struct _triton_timer_t *t; + struct _triton_ctx_call_t *call; uint64_t tt; ucontext_t *uctx; @@ -110,6 +112,13 @@ static void ctx_thread(struct _triton_context_t *ctx) h->trig_epoll_events = 0; continue; } + if (!list_empty(&ctx->pending_calls)) { + call = list_entry(ctx->pending_calls.next, typeof(*call), entry); + list_del(&call->entry); + spin_unlock(&ctx->lock); + call->func(call->arg); + mempool_free(call); + } ctx->thread = NULL; spin_unlock(&ctx->lock); @@ -159,6 +168,9 @@ int __export triton_context_register(struct triton_context_t *ud) { struct _triton_context_t *ctx = mempool_alloc(ctx_pool); + if (!ctx) + return -1; + memset(ctx, 0, sizeof(*ctx)); ctx->ud = ud; spinlock_init(&ctx->lock); @@ -166,6 +178,7 @@ int __export triton_context_register(struct triton_context_t *ud) INIT_LIST_HEAD(&ctx->timers); INIT_LIST_HEAD(&ctx->pending_handlers); INIT_LIST_HEAD(&ctx->pending_timers); + INIT_LIST_HEAD(&ctx->pending_calls); if (getcontext(&ctx->uctx)) { triton_log_error("getcontext: %s\n", strerror(errno)); @@ -252,9 +265,28 @@ void __export triton_context_wakeup(struct triton_context_t *ud) triton_thread_wakeup(ctx->thread); } +int __export triton_context_call(struct triton_context_t *ud, void (*func)(void *), void *arg) +{ + struct _triton_context_t *ctx = (struct _triton_context_t *)ud->tpd; + struct _triton_ctx_call_t *call = mempool_alloc(call_pool); + + if (!call) + return -1; + + call->func = func; + call->arg = arg; + + spin_lock(&ctx->lock); + list_add_tail(&call->entry, &ctx->pending_calls); + spin_unlock(&ctx->lock); + + return 0; +} + int __export triton_init(const char *conf_file, const char *mod_sect) { ctx_pool = mempool_create(sizeof(struct _triton_context_t)); + call_pool = mempool_create(sizeof(struct _triton_ctx_call_t)); default_ctx = malloc(sizeof(*default_ctx)); if (!default_ctx) { diff --git a/accel-pptpd/triton/triton.h b/accel-pptpd/triton/triton.h index 735264a..d9baa7d 100644 --- a/accel-pptpd/triton/triton.h +++ b/accel-pptpd/triton/triton.h @@ -45,6 +45,7 @@ int triton_context_register(struct triton_context_t *); void triton_context_unregister(struct triton_context_t *); void triton_context_schedule(struct triton_context_t *); void triton_context_wakeup(struct triton_context_t *); +int triton_context_call(struct triton_context_t *, void (*func)(void *), void *arg); #define MD_MODE_READ 1 #define MD_MODE_WRITE 2 diff --git a/accel-pptpd/triton/triton_p.h b/accel-pptpd/triton/triton_p.h index 0aa37b1..5e498fc 100644 --- a/accel-pptpd/triton/triton_p.h +++ b/accel-pptpd/triton/triton_p.h @@ -33,6 +33,7 @@ struct _triton_context_t struct list_head timers; struct list_head pending_handlers; struct list_head pending_timers; + struct list_head pending_calls; ucontext_t uctx; @@ -71,6 +72,14 @@ struct _triton_event_t struct list_head handlers; }; +struct _triton_ctx_call_t +{ + struct list_head entry; + + void *arg; + void (*func)(void *); +}; + typedef void * mempool_t; mempool_t *mempool_create(int size); void *mempool_alloc(mempool_t*); -- cgit v1.2.3