diff options
-rw-r--r-- | accel-pppd/cli/tcp.c | 6 | ||||
-rw-r--r-- | accel-pppd/cli/telnet.c | 6 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/arp.c | 3 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/dhcpv4.c | 6 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe_netlink.c | 2 | ||||
-rw-r--r-- | accel-pppd/ctrl/l2tp/l2tp.c | 12 | ||||
-rw-r--r-- | accel-pppd/ctrl/pppoe/pppoe.c | 3 | ||||
-rw-r--r-- | accel-pppd/ctrl/pptp/pptp.c | 6 | ||||
-rw-r--r-- | accel-pppd/ipv6/dhcpv6.c | 3 | ||||
-rw-r--r-- | accel-pppd/ipv6/nd.c | 3 | ||||
-rw-r--r-- | accel-pppd/logs/log_tcp.c | 9 | ||||
-rw-r--r-- | accel-pppd/ppp/ppp.c | 16 | ||||
-rw-r--r-- | accel-pppd/radius/acct.c | 4 | ||||
-rw-r--r-- | accel-pppd/radius/dm_coa.c | 3 | ||||
-rw-r--r-- | accel-pppd/radius/req.c | 2 | ||||
-rw-r--r-- | accel-pppd/radius/serv.c | 8 | ||||
-rw-r--r-- | accel-pppd/triton/md.c | 49 | ||||
-rw-r--r-- | accel-pppd/triton/triton.c | 22 | ||||
-rw-r--r-- | accel-pppd/triton/triton.h | 2 | ||||
-rw-r--r-- | accel-pppd/triton/triton_p.h | 1 |
20 files changed, 92 insertions, 74 deletions
diff --git a/accel-pppd/cli/tcp.c b/accel-pppd/cli/tcp.c index 48fa01a2..4ec49505 100644 --- a/accel-pppd/cli/tcp.c +++ b/accel-pppd/cli/tcp.c @@ -54,8 +54,7 @@ static void disconnect(struct tcp_client_t *cln) list_del(&cln->entry); - triton_md_unregister_handler(&cln->hnd); - close(cln->hnd.fd); + triton_md_unregister_handler(&cln->hnd, 1); if (cln->xmit_buf) _free(cln->xmit_buf); @@ -283,8 +282,7 @@ static void serv_close(struct triton_context_t *ctx) disconnect(cln); } - triton_md_unregister_handler(&serv_hnd); - close(serv_hnd.fd); + triton_md_unregister_handler(&serv_hnd, 1); triton_context_unregister(ctx); } diff --git a/accel-pppd/cli/telnet.c b/accel-pppd/cli/telnet.c index 58d0310a..fb211ea0 100644 --- a/accel-pppd/cli/telnet.c +++ b/accel-pppd/cli/telnet.c @@ -85,8 +85,7 @@ static void disconnect(struct telnet_client_t *cln) list_del(&cln->entry); - triton_md_unregister_handler(&cln->hnd); - close(cln->hnd.fd); + triton_md_unregister_handler(&cln->hnd, 1); if (cln->xmit_buf) _free(cln->xmit_buf); @@ -626,8 +625,7 @@ static void serv_close(struct triton_context_t *ctx) disconnect(cln); } - triton_md_unregister_handler(&serv_hnd); - close(serv_hnd.fd); + triton_md_unregister_handler(&serv_hnd, 1); triton_context_unregister(ctx); } diff --git a/accel-pppd/ctrl/ipoe/arp.c b/accel-pppd/ctrl/ipoe/arp.c index ee4ccded..e019d884 100644 --- a/accel-pppd/ctrl/ipoe/arp.c +++ b/accel-pppd/ctrl/ipoe/arp.c @@ -183,8 +183,7 @@ struct arp_serv *arpd_start(struct ipoe_serv *ipoe) void arpd_stop(struct arp_serv *arp) { - triton_md_unregister_handler(&arp->h); - close(arp->h.fd); + triton_md_unregister_handler(&arp->h, 1); _free(arp); } diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.c b/accel-pppd/ctrl/ipoe/dhcpv4.c index c603c5f1..35fc4688 100644 --- a/accel-pppd/ctrl/ipoe/dhcpv4.c +++ b/accel-pppd/ctrl/ipoe/dhcpv4.c @@ -229,8 +229,7 @@ out_err: void dhcpv4_free(struct dhcpv4_serv *serv) { - triton_md_unregister_handler(&serv->hnd); - close(serv->hnd.fd); + triton_md_unregister_handler(&serv->hnd, 1); if (serv->range) _free(serv->range); _free(serv); @@ -911,8 +910,7 @@ out_err_unlock: static void __dhcpv4_relay_free(struct dhcpv4_relay *r) { - triton_md_unregister_handler(&r->hnd); - close(r->hnd.fd); + triton_md_unregister_handler(&r->hnd, 1); triton_context_unregister(&r->ctx); _free(r); } diff --git a/accel-pppd/ctrl/ipoe/ipoe_netlink.c b/accel-pppd/ctrl/ipoe/ipoe_netlink.c index 68e533ca..e4d1d024 100644 --- a/accel-pppd/ctrl/ipoe/ipoe_netlink.c +++ b/accel-pppd/ctrl/ipoe/ipoe_netlink.c @@ -638,7 +638,7 @@ static int ipoe_mc_read(struct triton_md_handler_t *h) static void ipoe_mc_close(struct triton_context_t *ctx) { - triton_md_unregister_handler(&mc_hnd); + triton_md_unregister_handler(&mc_hnd, 0); triton_context_unregister(ctx); } diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index b41a48b8..2a52d69f 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -1135,7 +1135,7 @@ static void l2tp_tunnel_free(struct l2tp_conn_t *conn) pthread_mutex_unlock(&l2tp_lock); if (conn->hnd.tpd) - triton_md_unregister_handler(&conn->hnd); + triton_md_unregister_handler(&conn->hnd, 0); if (conn->timeout_timer.tpd) triton_timer_del(&conn->timeout_timer); if (conn->rtimeout_timer.tpd) @@ -1533,7 +1533,7 @@ static int l2tp_tunnel_start(struct l2tp_conn_t *conn, err_ctx_md_timer: triton_timer_del(&conn->timeout_timer); err_ctx_md: - triton_md_unregister_handler(&conn->hnd); + triton_md_unregister_handler(&conn->hnd, 0); err_ctx: triton_context_unregister(&conn->ctx); err: @@ -4428,8 +4428,7 @@ skip: static void l2tp_udp_close(struct triton_context_t *ctx) { struct l2tp_serv_t *serv = container_of(ctx, typeof(*serv), ctx); - triton_md_unregister_handler(&serv->hnd); - close(serv->hnd.fd); + triton_md_unregister_handler(&serv->hnd, 1); triton_context_unregister(&serv->ctx); } @@ -4551,8 +4550,11 @@ static int start_udp_server(void) return 0; err_hnd: - triton_md_unregister_handler(&udp_serv.hnd); + triton_md_unregister_handler(&udp_serv.hnd, 1); triton_context_unregister(&udp_serv.ctx); + + return -1; + err_fd: close(udp_serv.hnd.fd); udp_serv.hnd.fd = -1; diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c index 22ddf431..1dc21a3d 100644 --- a/accel-pppd/ctrl/pppoe/pppoe.c +++ b/accel-pppd/ctrl/pppoe/pppoe.c @@ -1399,8 +1399,7 @@ void pppoe_server_free(struct pppoe_serv_t *serv) free_delayed_pado(pado); } - triton_md_unregister_handler(&serv->hnd); - close(serv->hnd.fd); + triton_md_unregister_handler(&serv->hnd, 1); triton_context_unregister(&serv->ctx); _free(serv->ifname); _free(serv); diff --git a/accel-pppd/ctrl/pptp/pptp.c b/accel-pppd/ctrl/pptp/pptp.c index 46e980e0..92770bf6 100644 --- a/accel-pppd/ctrl/pptp/pptp.c +++ b/accel-pppd/ctrl/pptp/pptp.c @@ -77,8 +77,7 @@ static void disconnect(struct pptp_conn_t *conn) { log_ppp_debug("pptp: disconnect\n"); - triton_md_unregister_handler(&conn->hnd); - close(conn->hnd.fd); + triton_md_unregister_handler(&conn->hnd, 1); if (conn->timeout_timer.tpd) triton_timer_del(&conn->timeout_timer); @@ -704,8 +703,7 @@ static int pptp_connect(struct triton_md_handler_t *h) static void pptp_serv_close(struct triton_context_t *ctx) { struct pptp_serv_t *s=container_of(ctx,typeof(*s),ctx); - triton_md_unregister_handler(&s->hnd); - close(s->hnd.fd); + triton_md_unregister_handler(&s->hnd, 1); triton_context_unregister(ctx); } diff --git a/accel-pppd/ipv6/dhcpv6.c b/accel-pppd/ipv6/dhcpv6.c index 5c6d1a52..809496e8 100644 --- a/accel-pppd/ipv6/dhcpv6.c +++ b/accel-pppd/ipv6/dhcpv6.c @@ -796,8 +796,7 @@ static int dhcpv6_read(struct triton_md_handler_t *h) static void dhcpv6_close(struct triton_context_t *ctx) { - triton_md_unregister_handler(&dhcpv6_hnd); - close(dhcpv6_hnd.fd); + triton_md_unregister_handler(&dhcpv6_hnd, 1); triton_context_unregister(ctx); } diff --git a/accel-pppd/ipv6/nd.c b/accel-pppd/ipv6/nd.c index eeaef7a8..d10d4b89 100644 --- a/accel-pppd/ipv6/nd.c +++ b/accel-pppd/ipv6/nd.c @@ -375,8 +375,7 @@ static void ev_ses_finishing(struct ap_session *ses) if (h->timer.tpd) triton_timer_del(&h->timer); - triton_md_unregister_handler(&h->hnd); - close(h->hnd.fd); + triton_md_unregister_handler(&h->hnd, 1); list_del(&h->pd.entry); diff --git a/accel-pppd/logs/log_tcp.c b/accel-pppd/logs/log_tcp.c index b89b7d65..5f592d95 100644 --- a/accel-pppd/logs/log_tcp.c +++ b/accel-pppd/logs/log_tcp.c @@ -47,8 +47,7 @@ static LIST_HEAD(targets); static void disconnect(struct tcp_target_t *t) { - triton_md_unregister_handler(&t->hnd); - close(t->hnd.fd); + triton_md_unregister_handler(&t->hnd, 1); start_connect(t); } @@ -170,8 +169,7 @@ static int log_tcp_connect(struct triton_md_handler_t *h) if (errno == EINPROGRESS) return 0; log_emerg("log-tcp: connect: %s\n", strerror(errno)); - triton_md_unregister_handler(&t->hnd); - close(t->hnd.fd); + triton_md_unregister_handler(&t->hnd, 1); triton_timer_add(&tcp_ctx, &t->conn_timer, 0); return 0; } @@ -241,8 +239,7 @@ static void log_tcp_close(struct triton_context_t *ctx) triton_timer_del(&t->conn_timer); else { t->connected = 0; - triton_md_unregister_handler(&t->hnd); - close(t->hnd.fd); + triton_md_unregister_handler(&t->hnd, 1); } } diff --git a/accel-pppd/ppp/ppp.c b/accel-pppd/ppp/ppp.c index 53630946..6e024805 100644 --- a/accel-pppd/ppp/ppp.c +++ b/accel-pppd/ppp/ppp.c @@ -185,13 +185,14 @@ exit_close_chan: static void destablish_ppp(struct ppp_t *ppp) { struct pppunit_cache *uc; + int close_unit = uc_size >= conf_unit_cache; triton_event_fire(EV_SES_PRE_FINISHED, &ppp->ses); - triton_md_unregister_handler(&ppp->chan_hnd); - triton_md_unregister_handler(&ppp->unit_hnd); + triton_md_unregister_handler(&ppp->chan_hnd, 1); + triton_md_unregister_handler(&ppp->unit_hnd, close_unit); - if (uc_size < conf_unit_cache) { + if (!close_unit) { uc = mempool_alloc(uc_pool); uc->fd = ppp->unit_fd; uc->unit_idx = ppp->ses.unit_idx; @@ -200,14 +201,11 @@ static void destablish_ppp(struct ppp_t *ppp) list_add_tail(&uc->entry, &uc_list); ++uc_size; pthread_mutex_unlock(&uc_lock); - } else - close(ppp->unit_fd); + + ppp->chan_fd = -1; + } - close(ppp->chan_fd); close(ppp->fd); - - ppp->unit_fd = -1; - ppp->chan_fd = -1; ppp->fd = -1; _free_layers(ppp); diff --git a/accel-pppd/radius/acct.c b/accel-pppd/radius/acct.c index 161b959a..18033446 100644 --- a/accel-pppd/radius/acct.c +++ b/accel-pppd/radius/acct.c @@ -343,7 +343,7 @@ out: rpd->acct_interim_timer.expire = rad_acct_interim_update; rpd->acct_interim_timer.period = rpd->acct_interim_interval ? rpd->acct_interim_interval * 1000 : STAT_UPDATE_INTERVAL; if (rpd->acct_interim_interval && triton_timer_add(rpd->ses->ctrl->ctx, &rpd->acct_interim_timer, 0)) { - triton_md_unregister_handler(&rpd->acct_req->hnd); + triton_md_unregister_handler(&rpd->acct_req->hnd, 0); triton_timer_del(&rpd->acct_req->timeout); goto out_err; } @@ -368,7 +368,7 @@ void rad_acct_stop(struct radius_pd_t *rpd) triton_timer_del(&rpd->acct_interim_timer); if (rpd->acct_req) { - triton_md_unregister_handler(&rpd->acct_req->hnd); + triton_md_unregister_handler(&rpd->acct_req->hnd, 0); if (rpd->acct_req->timeout.tpd) triton_timer_del(&rpd->acct_req->timeout); diff --git a/accel-pppd/radius/dm_coa.c b/accel-pppd/radius/dm_coa.c index 13719ae3..0235ba4a 100644 --- a/accel-pppd/radius/dm_coa.c +++ b/accel-pppd/radius/dm_coa.c @@ -268,8 +268,7 @@ static int dm_coa_read(struct triton_md_handler_t *h) static void dm_coa_close(struct triton_context_t *ctx) { struct dm_coa_serv_t *serv = container_of(ctx, typeof(*serv), ctx); - triton_md_unregister_handler(&serv->hnd); - close(serv->hnd.fd); + triton_md_unregister_handler(&serv->hnd, 1); triton_context_unregister(ctx); } diff --git a/accel-pppd/radius/req.c b/accel-pppd/radius/req.c index 70e0431f..2b789ad7 100644 --- a/accel-pppd/radius/req.c +++ b/accel-pppd/radius/req.c @@ -287,7 +287,7 @@ static void req_wakeup(struct rad_req_t *req) struct triton_context_t *ctx = req->wait_ctx; if (req->timeout.tpd) triton_timer_del(&req->timeout); - triton_md_unregister_handler(&req->hnd); + triton_md_unregister_handler(&req->hnd, 0); triton_context_unregister(&req->ctx); triton_context_wakeup(ctx); } diff --git a/accel-pppd/radius/serv.c b/accel-pppd/radius/serv.c index c7b19166..6a080709 100644 --- a/accel-pppd/radius/serv.c +++ b/accel-pppd/radius/serv.c @@ -175,9 +175,11 @@ int rad_server_realloc(struct rad_req_t *req) if (req->hnd.fd != -1) { if (req->hnd.tpd) - triton_md_unregister_handler(&req->hnd); - close(req->hnd.fd); - req->hnd.fd = -1; + triton_md_unregister_handler(&req->hnd, 1); + else { + close(req->hnd.fd); + req->hnd.fd = -1; + } } req->server_addr = req->serv->addr; diff --git a/accel-pppd/triton/md.c b/accel-pppd/triton/md.c index c9ec32e6..a7eb5c8f 100644 --- a/accel-pppd/triton/md.c +++ b/accel-pppd/triton/md.c @@ -97,19 +97,22 @@ static void *md_thread(void *arg) triton_thread_wakeup(h->ctx->thread); } - while (!list_empty(&freed_list2)) { - h = list_entry(freed_list2.next, typeof(*h), entry); - list_del(&h->entry); - mempool_free(h); - } - pthread_mutex_lock(&freed_list_lock); while (!list_empty(&freed_list)) { h = list_entry(freed_list.next, typeof(*h), entry); - list_del(&h->entry); - list_add(&h->entry, &freed_list2); + list_move(&h->entry, &freed_list2); } pthread_mutex_unlock(&freed_list_lock); + + while (!list_empty(&freed_list2)) { + h = list_entry(freed_list2.next, typeof(*h), entry); + list_del(&h->entry); + if (h->fd != -1) { + r = epoll_ctl(epoll_fd, EPOLL_CTL_DEL, h->fd, NULL); + close(h->fd); + } + mempool_free(h); + } } return NULL; @@ -130,13 +133,22 @@ void __export triton_md_register_handler(struct triton_context_t *ctx, struct tr list_add_tail(&h->entry, &h->ctx->handlers); spin_unlock(&h->ctx->lock); - triton_stat.md_handler_count++; + __sync_add_and_fetch(&triton_stat.md_handler_count, 1); } -void __export triton_md_unregister_handler(struct triton_md_handler_t *ud) + +void __export triton_md_unregister_handler(struct triton_md_handler_t *ud, int c) { struct _triton_md_handler_t *h = (struct _triton_md_handler_t *)ud->tpd; triton_md_disable_handler(ud, MD_MODE_READ | MD_MODE_WRITE); + if (c) { + h->fd = ud->fd; + ud->fd = -1; + } else { + triton_md_disable_handler(ud, MD_MODE_READ | MD_MODE_WRITE); + h->fd = -1; + } + spin_lock(&h->ctx->lock); h->ud = NULL; list_del(&h->entry); @@ -146,16 +158,15 @@ void __export triton_md_unregister_handler(struct triton_md_handler_t *ud) } spin_unlock(&h->ctx->lock); - sched_yield(); - pthread_mutex_lock(&freed_list_lock); list_add_tail(&h->entry, &freed_list); pthread_mutex_unlock(&freed_list_lock); ud->tpd = NULL; - triton_stat.md_handler_count--; + __sync_sub_and_fetch(&triton_stat.md_handler_count, 1); } + int __export triton_md_enable_handler(struct triton_md_handler_t *ud, int mode) { struct _triton_md_handler_t *h = (struct _triton_md_handler_t *)ud->tpd; @@ -170,6 +181,9 @@ int __export triton_md_enable_handler(struct triton_md_handler_t *ud, int mode) if (!h->trig_level) h->epoll_event.events |= EPOLLET; + if (events == h->epoll_event.events) + return 0; + if (events) r = epoll_ctl(epoll_fd, EPOLL_CTL_MOD, h->ud->fd, &h->epoll_event); else @@ -182,18 +196,23 @@ int __export triton_md_enable_handler(struct triton_md_handler_t *ud, int mode) return r; } + int __export triton_md_disable_handler(struct triton_md_handler_t *ud,int mode) { struct _triton_md_handler_t *h = (struct _triton_md_handler_t *)ud->tpd; - int r=0; + int r = 0; + int events = h->epoll_event.events; if (!h->epoll_event.events) - return -1; + return 0; if (mode & MD_MODE_READ) h->epoll_event.events &= ~EPOLLIN; if (mode & MD_MODE_WRITE) h->epoll_event.events &= ~EPOLLOUT; + + if (events == h->epoll_event.events) + return 0; if (h->epoll_event.events & (EPOLLIN | EPOLLOUT)) r = epoll_ctl(epoll_fd, EPOLL_CTL_MOD, h->ud->fd, &h->epoll_event); diff --git a/accel-pppd/triton/triton.c b/accel-pppd/triton/triton.c index 8bde56da..ef9078b8 100644 --- a/accel-pppd/triton/triton.c +++ b/accel-pppd/triton/triton.c @@ -183,6 +183,7 @@ static void ctx_thread(struct _triton_context_t *ctx) struct _triton_timer_t *t; struct _triton_ctx_call_t *call; uint64_t tt; + int events; log_debug2("ctx %p %p: enter\n", ctx, ctx->thread); @@ -199,23 +200,33 @@ static void ctx_thread(struct _triton_context_t *ctx) t->ud->expire(t->ud); continue; } + if (!list_empty(&ctx->pending_handlers)) { h = list_entry(ctx->pending_handlers.next, typeof(*h), entry2); list_del(&h->entry2); h->pending = 0; + events = h->trig_epoll_events; spin_unlock(&ctx->lock); + __sync_sub_and_fetch(&triton_stat.md_handler_pending, 1); - if (h->trig_epoll_events & (EPOLLIN | EPOLLERR | EPOLLHUP)) - if (h->ud && h->ud->read) + + if ((events & (EPOLLIN | EPOLLERR | EPOLLHUP)) && (h->epoll_event.events & EPOLLIN)) { + if (h->ud && h->ud->read) { if (h->ud->read(h->ud)) continue; - if (h->trig_epoll_events & (EPOLLOUT | EPOLLERR | EPOLLHUP)) - if (h->ud && h->ud->write) + } + } + + if ((events & (EPOLLOUT | EPOLLERR | EPOLLHUP)) && (h->epoll_event.events & EPOLLOUT)) { + if (h->ud && h->ud->write) { if (h->ud->write(h->ud)) continue; - 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); @@ -224,6 +235,7 @@ static void ctx_thread(struct _triton_context_t *ctx) mempool_free(call); continue; } + ctx->pending = 0; spin_unlock(&ctx->lock); break; diff --git a/accel-pppd/triton/triton.h b/accel-pppd/triton/triton.h index e47eb369..71bb174b 100644 --- a/accel-pppd/triton/triton.h +++ b/accel-pppd/triton/triton.h @@ -85,7 +85,7 @@ struct triton_context_t *triton_context_self(void); #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); +void triton_md_unregister_handler(struct triton_md_handler_t *h, int close); 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); diff --git a/accel-pppd/triton/triton_p.h b/accel-pppd/triton/triton_p.h index 443cedea..d86f1bcc 100644 --- a/accel-pppd/triton/triton_p.h +++ b/accel-pppd/triton/triton_p.h @@ -53,6 +53,7 @@ struct _triton_md_handler_t struct _triton_context_t *ctx; struct epoll_event epoll_event; uint32_t trig_epoll_events; + int fd; int pending:1; int trig_level:1; struct triton_md_handler_t *ud; |