diff options
author | Kozlov Dmitry <dima@server> | 2010-11-16 17:19:33 +0300 |
---|---|---|
committer | Kozlov Dmitry <dima@server> | 2010-11-16 17:19:33 +0300 |
commit | e95fc28b08669e329916e1cf1eb52fa462ad655a (patch) | |
tree | b584a8719fc5950ae9f683c6ce865ee074e3e450 | |
parent | 50881d86b036e3b658c45e56b57b12a60e1562ef (diff) | |
download | accel-ppp-e95fc28b08669e329916e1cf1eb52fa462ad655a.tar.gz accel-ppp-e95fc28b08669e329916e1cf1eb52fa462ad655a.zip |
log-tcp: fixed incorrect queue overflow handling
ppp: fixed memory leak when ipcp raises error at ConfReq
-rw-r--r-- | accel-pptpd/cli/std_cmd.c | 4 | ||||
-rw-r--r-- | accel-pptpd/cli/tcp.c | 1 | ||||
-rw-r--r-- | accel-pptpd/cli/telnet.c | 1 | ||||
-rw-r--r-- | accel-pptpd/logs/log_tcp.c | 6 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp.c | 8 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp.h | 1 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_ipcp.c | 4 | ||||
-rw-r--r-- | accel-pptpd/triton/triton.c | 24 | ||||
-rw-r--r-- | accel-pptpd/triton/triton.h | 1 | ||||
-rw-r--r-- | accel-pptpd/triton/triton_p.h | 1 |
10 files changed, 36 insertions, 15 deletions
diff --git a/accel-pptpd/cli/std_cmd.c b/accel-pptpd/cli/std_cmd.c index 9a5747e8..47604df8 100644 --- a/accel-pptpd/cli/std_cmd.c +++ b/accel-pptpd/cli/std_cmd.c @@ -112,12 +112,12 @@ static void show_ses_help(char * const *fields, int fields_cnt, void *client) static void ppp_terminate_soft(struct ppp_t *ppp) { - ppp_terminate(ppp, 0, TERM_ADMIN_RESET); + ppp_terminate(ppp, TERM_ADMIN_RESET, 0); } static void ppp_terminate_hard(struct ppp_t *ppp) { - ppp_terminate(ppp, 1, TERM_ADMIN_RESET); + ppp_terminate(ppp, TERM_ADMIN_RESET, 1); } static void terminate_help(char * const *fields, int fields_cnt, void *client); diff --git a/accel-pptpd/cli/tcp.c b/accel-pptpd/cli/tcp.c index 582c1752..f6d2011e 100644 --- a/accel-pptpd/cli/tcp.c +++ b/accel-pptpd/cli/tcp.c @@ -332,6 +332,7 @@ static void start_server(const char *host, int port) addr.sin_addr.s_addr = inet_addr(host); triton_context_register(&serv_ctx, NULL); + triton_context_set_priority(&serv_ctx, 1); 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/cli/telnet.c b/accel-pptpd/cli/telnet.c index d38e056b..fef9b0a0 100644 --- a/accel-pptpd/cli/telnet.c +++ b/accel-pptpd/cli/telnet.c @@ -621,6 +621,7 @@ static void start_server(const char *host, int port) addr.sin_addr.s_addr = inet_addr(host); triton_context_register(&serv_ctx, NULL); + triton_context_set_priority(&serv_ctx, 1); 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_tcp.c b/accel-pptpd/logs/log_tcp.c index 2579ac25..fdef63ee 100644 --- a/accel-pptpd/logs/log_tcp.c +++ b/accel-pptpd/logs/log_tcp.c @@ -111,6 +111,7 @@ static void queue_log(struct tcp_target_t *t, struct log_msg_t *msg) if (t->queue_len == conf_queue_len) { spin_unlock(&t->lock); log_free_msg(msg); + return; } list_add_tail(&msg->entry, &t->queue); t->queue_len++; @@ -182,7 +183,8 @@ static int log_tcp_connect(struct triton_md_handler_t *h) t->wait = 1; spin_unlock(&t->lock); - send_log(t); + if (send_log(t)) + triton_md_enable_handler(&t->hnd, MD_MODE_WRITE); return 0; } @@ -258,6 +260,8 @@ static int start_log(const char *_opt) INIT_LIST_HEAD(&t->queue); + spinlock_init(&t->lock); + start_connect(t); log_register_target(&t->target); diff --git a/accel-pptpd/ppp/ppp.c b/accel-pptpd/ppp/ppp.c index a26e6446..acda605a 100644 --- a/accel-pptpd/ppp/ppp.c +++ b/accel-pptpd/ppp/ppp.c @@ -210,6 +210,8 @@ static void destablish_ppp(struct ppp_t *ppp) _free_layers(ppp); + ppp->terminated = 1; + log_ppp_debug("ppp destablished\n"); triton_event_fire(EV_PPP_FINISHED, ppp); @@ -411,7 +413,11 @@ void __export ppp_terminate(struct ppp_t *ppp, int cause, int hard) struct ppp_layer_data_t *d; int s = 0; - time(&ppp->stop_time); + if (ppp->terminated) + return; + + if (!ppp->stop_time) + time(&ppp->stop_time); if (!ppp->terminate_cause) ppp->terminate_cause = cause; diff --git a/accel-pptpd/ppp/ppp.h b/accel-pptpd/ppp/ppp.h index f74351d4..1a970997 100644 --- a/accel-pptpd/ppp/ppp.h +++ b/accel-pptpd/ppp/ppp.h @@ -98,6 +98,7 @@ struct ppp_t struct ppp_ctrl_t *ctrl; int terminating:1; + int terminated:1; int terminate_cause; void *chan_buf; diff --git a/accel-pptpd/ppp/ppp_ipcp.c b/accel-pptpd/ppp/ppp_ipcp.c index 3248db6c..32298934 100644 --- a/accel-pptpd/ppp/ppp_ipcp.c +++ b/accel-pptpd/ppp/ppp_ipcp.c @@ -579,8 +579,10 @@ static void ipcp_recv(struct ppp_handler_t*h) switch(hdr->code) { case CONFREQ: r = ipcp_recv_conf_req(ipcp,(uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN); - if (ipcp->ppp->stop_time) + if (ipcp->ppp->stop_time) { + ipcp_free_conf_req(ipcp); return; + } switch(r) { case IPCP_OPT_ACK: ppp_fsm_recv_conf_req_ack(&ipcp->fsm); diff --git a/accel-pptpd/triton/triton.c b/accel-pptpd/triton/triton.c index 597288be..e7855ccf 100644 --- a/accel-pptpd/triton/triton.c +++ b/accel-pptpd/triton/triton.c @@ -205,7 +205,10 @@ int triton_queue_ctx(struct _triton_context_t *ctx) spin_lock(&threads_lock); if (list_empty(&sleep_threads)) { - list_add_tail(&ctx->entry2, &ctx_queue); + if (ctx->priority) + list_add(&ctx->entry2, &ctx_queue); + else + list_add_tail(&ctx->entry2, &ctx_queue); spin_unlock(&threads_lock); ctx->queued = 1; //printf("ctx %p: queued\n", ctx); @@ -318,6 +321,13 @@ void __export triton_context_unregister(struct triton_context_t *ud) } } +void __export triton_context_set_priority(struct triton_context_t *ud, int prio) +{ + struct _triton_context_t *ctx = (struct _triton_context_t *)ud->tpd; + + ctx->priority = prio > 0; +} + void __export triton_context_schedule(struct triton_context_t *ud) { struct _triton_context_t *ctx = (struct _triton_context_t *)ud->tpd; @@ -333,16 +343,10 @@ void __export triton_context_schedule(struct triton_context_t *ud) ctx->thread = NULL; spin_unlock(&ctx->lock); - while (1) { - if (swapcontext(&ctx->uctx, uctx)) { - if (errno == EINTR) - continue; - triton_log_error("swaswpntext: %s\n", strerror(errno)); - } else - break; - } - __sync_fetch_and_add(&triton_stat.context_sleeping, 1); + + if (swapcontext(&ctx->uctx, uctx)) + triton_log_error("swaswpntext: %s\n", strerror(errno)); } void triton_context_print(void) diff --git a/accel-pptpd/triton/triton.h b/accel-pptpd/triton/triton.h index f494bb39..94254288 100644 --- a/accel-pptpd/triton/triton.h +++ b/accel-pptpd/triton/triton.h @@ -68,6 +68,7 @@ struct triton_stat_t extern struct triton_stat_t triton_stat; int triton_context_register(struct triton_context_t *, void *arg); void triton_context_unregister(struct triton_context_t *); +void triton_context_set_priority(struct triton_context_t *, int); void triton_context_schedule(struct triton_context_t *); int triton_context_wakeup(struct triton_context_t *); int triton_context_call(struct triton_context_t *, void (*func)(void *), void *arg); diff --git a/accel-pptpd/triton/triton_p.h b/accel-pptpd/triton/triton_p.h index c685051a..f6fb6789 100644 --- a/accel-pptpd/triton/triton_p.h +++ b/accel-pptpd/triton/triton_p.h @@ -44,6 +44,7 @@ struct _triton_context_t int need_close:1; int need_free:1; int pending:1; + int priority:1; struct triton_context_t *ud; void *bf_arg; |