diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2011-01-17 18:08:11 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2011-01-17 18:08:11 +0300 |
commit | c783f297faa2453daca7189182a17f913e003ccc (patch) | |
tree | 0527171103dbe568658ea21262e1027b7023bf9a /accel-pppd/ppp | |
parent | 56762d9574d05bff9709c856f9f466c51156f549 (diff) | |
download | accel-ppp-xebd-c783f297faa2453daca7189182a17f913e003ccc.tar.gz accel-ppp-xebd-c783f297faa2453daca7189182a17f913e003ccc.zip |
memory usage optimization
Diffstat (limited to 'accel-pppd/ppp')
-rw-r--r-- | accel-pppd/ppp/ppp.c | 59 | ||||
-rw-r--r-- | accel-pppd/ppp/ppp.h | 6 | ||||
-rw-r--r-- | accel-pppd/ppp/ppp_ccp.c | 6 | ||||
-rw-r--r-- | accel-pppd/ppp/ppp_ipcp.c | 6 | ||||
-rw-r--r-- | accel-pppd/ppp/ppp_lcp.c | 10 |
5 files changed, 39 insertions, 48 deletions
diff --git a/accel-pppd/ppp/ppp.c b/accel-pppd/ppp/ppp.c index f578e8e..a044d9a 100644 --- a/accel-pppd/ppp/ppp.c +++ b/accel-pppd/ppp/ppp.c @@ -20,6 +20,7 @@ #include "ppp_fsm.h" #include "log.h" #include "spinlock.h" +#include "mempool.h" #include "memdebug.h" @@ -29,17 +30,19 @@ static int conf_sid_ucase; pthread_rwlock_t __export ppp_lock = PTHREAD_RWLOCK_INITIALIZER; __export LIST_HEAD(ppp_list); -static LIST_HEAD(layers); int __export sock_fd; int __export ppp_shutdown; +static mempool_t buf_pool; + +static LIST_HEAD(layers); + static unsigned long long seq; #if __WORDSIZE == 32 static spinlock_t seq_lock; #endif - struct ppp_stat_t ppp_stat; struct layer_node_t @@ -64,16 +67,6 @@ void __export ppp_init(struct ppp_t *ppp) INIT_LIST_HEAD(&ppp->pd_list); } -static void _free_ppp(struct ppp_t *ppp) -{ - if (ppp->chan_buf) - free(ppp->chan_buf); - if (ppp->unit_buf) - _free(ppp->unit_buf); - if (ppp->username) - _free(ppp->username); -} - static void generate_sessionid(struct ppp_t *ppp) { unsigned long long sid; @@ -151,8 +144,7 @@ int __export establish_ppp(struct ppp_t *ppp) goto exit_close_unit; } - ppp->chan_buf = _malloc(PPP_MRU); - ppp->unit_buf = _malloc(PPP_MRU); + ppp->buf = mempool_alloc(buf_pool); ppp->chan_hnd.fd = ppp->chan_fd; ppp->chan_hnd.read = ppp_chan_read; @@ -184,7 +176,8 @@ exit_close_unit: exit_close_chan: close(ppp->chan_fd); - _free_ppp(ppp); + if (ppp->buf) + mempool_free(ppp->buf); return -1; } @@ -218,9 +211,6 @@ static void destablish_ppp(struct ppp_t *ppp) ppp->chan_fd = -1; ppp->fd = -1; - _free(ppp->unit_buf); - _free(ppp->chan_buf); - _free_layers(ppp); ppp->terminated = 1; @@ -230,6 +220,8 @@ static void destablish_ppp(struct ppp_t *ppp) triton_event_fire(EV_PPP_FINISHED, ppp); ppp->ctrl->finished(ppp); + mempool_free(ppp->buf); + if (ppp->username) { _free(ppp->username); ppp->username = NULL; @@ -281,8 +273,8 @@ static int ppp_chan_read(struct triton_md_handler_t *h) while(1) { cont: - ppp->chan_buf_size = read(h->fd, ppp->chan_buf, PPP_MRU); - if (ppp->chan_buf_size < 0) { + ppp->buf_size = read(h->fd, ppp->buf, PPP_MRU); + if (ppp->buf_size < 0) { if (errno == EAGAIN) return 0; log_ppp_error("ppp_chan_read: %s\n", strerror(errno)); @@ -290,18 +282,18 @@ cont: } //printf("ppp_chan_read: "); - //print_buf(ppp->chan_buf,ppp->chan_buf_size); - if (ppp->chan_buf_size == 0) { + //print_buf(ppp->buf,ppp->buf_size); + if (ppp->buf_size == 0) { ppp_terminate(ppp, 1, TERM_NAS_ERROR); return 1; } - if (ppp->chan_buf_size < 2) { - log_ppp_error("ppp_chan_read: short read %i\n", ppp->chan_buf_size); + if (ppp->buf_size < 2) { + log_ppp_error("ppp_chan_read: short read %i\n", ppp->buf_size); continue; } - proto = ntohs(*(uint16_t*)ppp->chan_buf); + proto = ntohs(*(uint16_t*)ppp->buf); list_for_each_entry(ppp_h, &ppp->chan_handlers, entry) { if (ppp_h->proto == proto) { ppp_h->recv(ppp_h); @@ -326,29 +318,28 @@ static int ppp_unit_read(struct triton_md_handler_t *h) while (1) { cont: - ppp->unit_buf_size = read(h->fd, ppp->unit_buf, PPP_MRU); - if (ppp->unit_buf_size < 0) { + ppp->buf_size = read(h->fd, ppp->buf, PPP_MRU); + if (ppp->buf_size < 0) { if (errno == EAGAIN) return 0; log_ppp_error("ppp_unit_read: %s\n",strerror(errno)); return 0; } - md_check(ppp->unit_buf); //printf("ppp_unit_read: "); - //print_buf(ppp->unit_buf,ppp->unit_buf_size); + //print_buf(ppp->buf,ppp->buf_size); - if (ppp->unit_buf_size == 0) { + if (ppp->buf_size == 0) { ppp_terminate(ppp, 1, TERM_NAS_ERROR); return 1; } - if (ppp->unit_buf_size < 2) { - log_ppp_error("ppp_unit_read: short read %i\n", ppp->unit_buf_size); + if (ppp->buf_size < 2) { + log_ppp_error("ppp_unit_read: short read %i\n", ppp->buf_size); continue; } - proto=ntohs(*(uint16_t*)ppp->unit_buf); + proto=ntohs(*(uint16_t*)ppp->buf); list_for_each_entry(ppp_h, &ppp->unit_handlers, entry) { if (ppp_h->proto == proto) { ppp_h->recv(ppp_h); @@ -656,6 +647,8 @@ static void __init init(void) char *opt; FILE *f; + buf_pool = mempool_create(PPP_MRU); + sock_fd = socket(AF_INET, SOCK_DGRAM, 0); if (sock_fd < 0) { perror("socket"); diff --git a/accel-pppd/ppp/ppp.h b/accel-pppd/ppp/ppp.h index c633135..5fee8a4 100644 --- a/accel-pppd/ppp/ppp.h +++ b/accel-pppd/ppp/ppp.h @@ -103,10 +103,8 @@ struct ppp_t int terminated:1; int terminate_cause; - void *chan_buf; - int chan_buf_size; - void *unit_buf; - int unit_buf_size; + void *buf; + int buf_size; struct list_head chan_handlers; struct list_head unit_handlers; diff --git a/accel-pppd/ppp/ppp_ccp.c b/accel-pppd/ppp/ppp_ccp.c index 721dd9b..d4732fa 100644 --- a/accel-pppd/ppp/ppp_ccp.c +++ b/accel-pppd/ppp/ppp_ccp.c @@ -271,7 +271,7 @@ static int send_conf_req(struct ppp_fsm_t *fsm) static void send_conf_ack(struct ppp_fsm_t *fsm) { struct ppp_ccp_t *ccp = container_of(fsm, typeof(*ccp), fsm); - struct ccp_hdr_t *hdr = (struct ccp_hdr_t*)ccp->ppp->unit_buf; + struct ccp_hdr_t *hdr = (struct ccp_hdr_t*)ccp->ppp->buf; hdr->code = CONFACK; @@ -619,12 +619,12 @@ static void ccp_recv(struct ppp_handler_t*h) return; } - if (ccp->ppp->unit_buf_size < PPP_HEADERLEN + 2) { + if (ccp->ppp->buf_size < PPP_HEADERLEN + 2) { log_ppp_warn("CCP: short packet received\n"); return; } - hdr = (struct ccp_hdr_t *)ccp->ppp->unit_buf; + hdr = (struct ccp_hdr_t *)ccp->ppp->buf; if (ntohs(hdr->len) < PPP_HEADERLEN) { log_ppp_warn("CCP: short packet received\n"); return; diff --git a/accel-pppd/ppp/ppp_ipcp.c b/accel-pppd/ppp/ppp_ipcp.c index 7cdcdbc..5d66c9d 100644 --- a/accel-pppd/ppp/ppp_ipcp.c +++ b/accel-pppd/ppp/ppp_ipcp.c @@ -219,7 +219,7 @@ static int send_conf_req(struct ppp_fsm_t *fsm) static void send_conf_ack(struct ppp_fsm_t *fsm) { struct ppp_ipcp_t *ipcp = container_of(fsm, typeof(*ipcp), fsm); - struct ipcp_hdr_t *hdr = (struct ipcp_hdr_t*)ipcp->ppp->unit_buf; + struct ipcp_hdr_t *hdr = (struct ipcp_hdr_t*)ipcp->ppp->buf; hdr->code = CONFACK; @@ -564,12 +564,12 @@ static void ipcp_recv(struct ppp_handler_t*h) return; } - if (ipcp->ppp->unit_buf_size < PPP_HEADERLEN + 2) { + if (ipcp->ppp->buf_size < PPP_HEADERLEN + 2) { log_ppp_warn("IPCP: short packet received\n"); return; } - hdr = (struct ipcp_hdr_t *)ipcp->ppp->unit_buf; + hdr = (struct ipcp_hdr_t *)ipcp->ppp->buf; if (ntohs(hdr->len) < PPP_HEADERLEN) { log_ppp_warn("IPCP: short packet received\n"); return; diff --git a/accel-pppd/ppp/ppp_lcp.c b/accel-pppd/ppp/ppp_lcp.c index e40e321..63fe8ff 100644 --- a/accel-pppd/ppp/ppp_lcp.c +++ b/accel-pppd/ppp/ppp_lcp.c @@ -252,7 +252,7 @@ static int send_conf_req(struct ppp_fsm_t *fsm) static void send_conf_ack(struct ppp_fsm_t *fsm) { struct ppp_lcp_t *lcp = container_of(fsm, typeof(*lcp), fsm); - struct lcp_hdr_t *hdr = (struct lcp_hdr_t*)lcp->ppp->chan_buf; + struct lcp_hdr_t *hdr = (struct lcp_hdr_t*)lcp->ppp->buf; hdr->code = CONFACK; @@ -265,7 +265,7 @@ static void send_conf_ack(struct ppp_fsm_t *fsm) static void send_code_rej(struct ppp_fsm_t *fsm) { struct ppp_lcp_t *lcp = container_of(fsm, typeof(*lcp), fsm); - struct lcp_hdr_t *hdr = (struct lcp_hdr_t*)lcp->ppp->chan_buf; + struct lcp_hdr_t *hdr = (struct lcp_hdr_t*)lcp->ppp->buf; hdr->code = CONFACK; @@ -586,7 +586,7 @@ static void lcp_recv_echo_repl(struct ppp_lcp_t *lcp, uint8_t *data, int size) static void send_echo_reply(struct ppp_lcp_t *lcp) { - struct lcp_hdr_t *hdr = (struct lcp_hdr_t*)lcp->ppp->chan_buf; + struct lcp_hdr_t *hdr = (struct lcp_hdr_t*)lcp->ppp->buf; uint32_t magic = *(uint32_t *)(hdr + 1); hdr->code = ECHOREP; @@ -706,12 +706,12 @@ static void lcp_recv(struct ppp_handler_t*h) return; } - if (lcp->ppp->chan_buf_size < PPP_HEADERLEN + 2) { + if (lcp->ppp->buf_size < PPP_HEADERLEN + 2) { log_ppp_warn("LCP: short packet received\n"); return; } - hdr = (struct lcp_hdr_t *)lcp->ppp->chan_buf; + hdr = (struct lcp_hdr_t *)lcp->ppp->buf; if (ntohs(hdr->len) < PPP_HEADERLEN) { log_ppp_warn("LCP: short packet received\n"); return; |