diff options
Diffstat (limited to 'accel-pptpd/ppp')
-rw-r--r-- | accel-pptpd/ppp/ipcp_opt_dns.c | 8 | ||||
-rw-r--r-- | accel-pptpd/ppp/ipcp_opt_ipaddr.c | 8 | ||||
-rw-r--r-- | accel-pptpd/ppp/lcp_opt_accomp.c | 6 | ||||
-rw-r--r-- | accel-pptpd/ppp/lcp_opt_magic.c | 6 | ||||
-rw-r--r-- | accel-pptpd/ppp/lcp_opt_mru.c | 6 | ||||
-rw-r--r-- | accel-pptpd/ppp/lcp_opt_pcomp.c | 6 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp.c | 42 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_auth.c | 5 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_ccp.c | 32 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_fsm.c | 6 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_ipcp.c | 32 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_lcp.c | 37 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_pd.c | 2 |
13 files changed, 127 insertions, 69 deletions
diff --git a/accel-pptpd/ppp/ipcp_opt_dns.c b/accel-pptpd/ppp/ipcp_opt_dns.c index b741798..16ef7af 100644 --- a/accel-pptpd/ppp/ipcp_opt_dns.c +++ b/accel-pptpd/ppp/ipcp_opt_dns.c @@ -7,6 +7,8 @@ #include "log.h" #include "ipdb.h" +#include "memdebug.h" + static struct ipcp_option_t *dns1_init(struct ppp_ipcp_t *ipcp); static struct ipcp_option_t *dns2_init(struct ppp_ipcp_t *ipcp); static void dns_free(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt); @@ -43,7 +45,7 @@ static struct ipcp_option_handler_t dns2_opt_hnd= static struct ipcp_option_t *dns1_init(struct ppp_ipcp_t *ipcp) { - struct dns_option_t *dns_opt=malloc(sizeof(*dns_opt)); + struct dns_option_t *dns_opt=_malloc(sizeof(*dns_opt)); memset(dns_opt,0,sizeof(*dns_opt)); dns_opt->opt.id=CI_DNS1; dns_opt->opt.len=6; @@ -53,7 +55,7 @@ static struct ipcp_option_t *dns1_init(struct ppp_ipcp_t *ipcp) static struct ipcp_option_t *dns2_init(struct ppp_ipcp_t *ipcp) { - struct dns_option_t *dns_opt=malloc(sizeof(*dns_opt)); + struct dns_option_t *dns_opt=_malloc(sizeof(*dns_opt)); memset(dns_opt,0,sizeof(*dns_opt)); dns_opt->opt.id=CI_DNS2; dns_opt->opt.len=6; @@ -65,7 +67,7 @@ static void dns_free(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt) { struct dns_option_t *dns_opt=container_of(opt,typeof(*dns_opt),opt); - free(dns_opt); + _free(dns_opt); } static int dns_send_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt, uint8_t *ptr) diff --git a/accel-pptpd/ppp/ipcp_opt_ipaddr.c b/accel-pptpd/ppp/ipcp_opt_ipaddr.c index 1f9af3e..963d473 100644 --- a/accel-pptpd/ppp/ipcp_opt_ipaddr.c +++ b/accel-pptpd/ppp/ipcp_opt_ipaddr.c @@ -13,6 +13,8 @@ #include "ipdb.h" #include "iprange.h" +#include "memdebug.h" + static struct ipcp_option_t *ipaddr_init(struct ppp_ipcp_t *ipcp); static void ipaddr_free(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt); static int ipaddr_send_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt, uint8_t *ptr); @@ -39,7 +41,7 @@ static struct ipcp_option_handler_t ipaddr_opt_hnd= static struct ipcp_option_t *ipaddr_init(struct ppp_ipcp_t *ipcp) { - struct ipaddr_option_t *ipaddr_opt=malloc(sizeof(*ipaddr_opt)); + struct ipaddr_option_t *ipaddr_opt=_malloc(sizeof(*ipaddr_opt)); memset(ipaddr_opt,0,sizeof(*ipaddr_opt)); ipaddr_opt->opt.id=CI_ADDR; ipaddr_opt->opt.len=6; @@ -54,7 +56,7 @@ static void ipaddr_free(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt) if (ipaddr_opt->ip) ipdb_put(ipcp->ppp, ipaddr_opt->ip); - free(ipaddr_opt); + _free(ipaddr_opt); } static int ipaddr_send_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt, uint8_t *ptr) @@ -65,7 +67,7 @@ static int ipaddr_send_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *o if (!ipaddr_opt->ip) { ipaddr_opt->ip = ipdb_get(ipcp->ppp); if (!ipaddr_opt->ip) { - log_ppp_warn("ppp:ipcp: no free IP address\n"); + log_ppp_warn("ppp:ipcp: no _free IP address\n"); return -1; } } diff --git a/accel-pptpd/ppp/lcp_opt_accomp.c b/accel-pptpd/ppp/lcp_opt_accomp.c index c4c221c..8545f9d 100644 --- a/accel-pptpd/ppp/lcp_opt_accomp.c +++ b/accel-pptpd/ppp/lcp_opt_accomp.c @@ -6,6 +6,8 @@ #include "ppp_lcp.h" #include "log.h" +#include "memdebug.h" + static struct lcp_option_t *accomp_init(struct ppp_lcp_t *lcp); static void accomp_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt); static int accomp_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr); @@ -31,7 +33,7 @@ static struct lcp_option_handler_t accomp_opt_hnd= static struct lcp_option_t *accomp_init(struct ppp_lcp_t *lcp) { - struct accomp_option_t *accomp_opt=malloc(sizeof(*accomp_opt)); + struct accomp_option_t *accomp_opt=_malloc(sizeof(*accomp_opt)); memset(accomp_opt,0,sizeof(*accomp_opt)); accomp_opt->accomp=0; accomp_opt->opt.id=CI_ACCOMP; @@ -44,7 +46,7 @@ static void accomp_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt) { struct accomp_option_t *accomp_opt=container_of(opt,typeof(*accomp_opt),opt); - free(accomp_opt); + _free(accomp_opt); } static int accomp_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) diff --git a/accel-pptpd/ppp/lcp_opt_magic.c b/accel-pptpd/ppp/lcp_opt_magic.c index d6094c0..cec40ce 100644 --- a/accel-pptpd/ppp/lcp_opt_magic.c +++ b/accel-pptpd/ppp/lcp_opt_magic.c @@ -6,6 +6,8 @@ #include "ppp_lcp.h" #include "log.h" +#include "memdebug.h" + static struct lcp_option_t *magic_init(struct ppp_lcp_t *lcp); static void magic_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt); static int magic_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr); @@ -29,7 +31,7 @@ static struct lcp_option_handler_t magic_opt_hnd= static struct lcp_option_t *magic_init(struct ppp_lcp_t *lcp) { - struct magic_option_t *magic_opt=malloc(sizeof(*magic_opt)); + struct magic_option_t *magic_opt=_malloc(sizeof(*magic_opt)); memset(magic_opt,0,sizeof(*magic_opt)); magic_opt->magic=random(); magic_opt->opt.id=CI_MAGIC; @@ -44,7 +46,7 @@ static void magic_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt) { struct magic_option_t *magic_opt=container_of(opt,typeof(*magic_opt),opt); - free(magic_opt); + _free(magic_opt); } static int magic_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) diff --git a/accel-pptpd/ppp/lcp_opt_mru.c b/accel-pptpd/ppp/lcp_opt_mru.c index fc79db3..4dc9685 100644 --- a/accel-pptpd/ppp/lcp_opt_mru.c +++ b/accel-pptpd/ppp/lcp_opt_mru.c @@ -11,6 +11,8 @@ #include "ppp_lcp.h" #include "log.h" +#include "memdebug.h" + #define MAX_MTU 1436 static struct lcp_option_t *mru_init(struct ppp_lcp_t *lcp); @@ -41,7 +43,7 @@ static struct lcp_option_handler_t mru_opt_hnd= static struct lcp_option_t *mru_init(struct ppp_lcp_t *lcp) { - struct mru_option_t *mru_opt=malloc(sizeof(*mru_opt)); + struct mru_option_t *mru_opt=_malloc(sizeof(*mru_opt)); memset(mru_opt,0,sizeof(*mru_opt)); mru_opt->mtu=0; mru_opt->mru=MAX_MTU; @@ -55,7 +57,7 @@ static void mru_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt) { struct mru_option_t *mru_opt=container_of(opt,typeof(*mru_opt),opt); - free(mru_opt); + _free(mru_opt); } static int mru_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) diff --git a/accel-pptpd/ppp/lcp_opt_pcomp.c b/accel-pptpd/ppp/lcp_opt_pcomp.c index 8700bf4..0ff4d11 100644 --- a/accel-pptpd/ppp/lcp_opt_pcomp.c +++ b/accel-pptpd/ppp/lcp_opt_pcomp.c @@ -6,6 +6,8 @@ #include "ppp_lcp.h" #include "log.h" +#include "memdebug.h" + static struct lcp_option_t *pcomp_init(struct ppp_lcp_t *lcp); static void pcomp_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt); static int pcomp_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr); @@ -31,7 +33,7 @@ static struct lcp_option_handler_t pcomp_opt_hnd= static struct lcp_option_t *pcomp_init(struct ppp_lcp_t *lcp) { - struct pcomp_option_t *pcomp_opt=malloc(sizeof(*pcomp_opt)); + struct pcomp_option_t *pcomp_opt=_malloc(sizeof(*pcomp_opt)); memset(pcomp_opt,0,sizeof(*pcomp_opt)); pcomp_opt->pcomp=0; pcomp_opt->opt.id=CI_PCOMP; @@ -44,7 +46,7 @@ static void pcomp_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt) { struct pcomp_option_t *pcomp_opt=container_of(opt,typeof(*pcomp_opt),opt); - free(pcomp_opt); + _free(pcomp_opt); } static int pcomp_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) diff --git a/accel-pptpd/ppp/ppp.c b/accel-pptpd/ppp/ppp.c index 87c8e8e..4deb135 100644 --- a/accel-pptpd/ppp/ppp.c +++ b/accel-pptpd/ppp/ppp.c @@ -19,6 +19,8 @@ #include "ppp_fsm.h" #include "log.h" +#include "memdebug.h" + int conf_ppp_verbose; static LIST_HEAD(layers); @@ -34,24 +36,25 @@ struct layer_node_t static int ppp_chan_read(struct triton_md_handler_t*); static int ppp_unit_read(struct triton_md_handler_t*); static void init_layers(struct ppp_t *); -static void free_layers(struct ppp_t *); +static void _free_layers(struct ppp_t *); static void start_first_layer(struct ppp_t *); void __export ppp_init(struct ppp_t *ppp) { memset(ppp,0,sizeof(*ppp)); + INIT_LIST_HEAD(&ppp->layers); INIT_LIST_HEAD(&ppp->chan_handlers); INIT_LIST_HEAD(&ppp->unit_handlers); INIT_LIST_HEAD(&ppp->pd_list); } -static void free_ppp(struct ppp_t *ppp) +static void _free_ppp(struct ppp_t *ppp) { - free(ppp->chan_buf); - free(ppp->unit_buf); + _free(ppp->chan_buf); + _free(ppp->unit_buf); if (ppp->username) - free(ppp->username); + _free(ppp->username); } static void generate_sessionid(struct ppp_t *ppp) @@ -121,8 +124,8 @@ int __export establish_ppp(struct ppp_t *ppp) log_ppp_info("connect: ppp%i <--> pptp(%s)\n",ppp->unit_idx,ppp->chan_name); - ppp->chan_buf=malloc(PPP_MRU); - ppp->unit_buf=malloc(PPP_MRU); + ppp->chan_buf=_malloc(PPP_MRU); + ppp->unit_buf=_malloc(PPP_MRU); init_layers(ppp); @@ -166,7 +169,7 @@ exit_close_unit: exit_close_chan: close(ppp->chan_fd); - free_ppp(ppp); + _free_ppp(ppp); return -1; } @@ -183,15 +186,20 @@ static void destablish_ppp(struct ppp_t *ppp) ppp->unit_fd = -1; ppp->chan_fd = -1; - free(ppp->unit_buf); - free(ppp->chan_buf); + _free(ppp->unit_buf); + _free(ppp->chan_buf); - free_layers(ppp); + _free_layers(ppp); log_ppp_debug("ppp destablished\n"); triton_event_fire(EV_PPP_FINISHED, ppp); ppp->ctrl->finished(ppp); + + if (ppp->username) { + _free(ppp->username); + ppp->username = NULL; + } } void print_buf(uint8_t *buf,int size) @@ -424,7 +432,7 @@ int __export ppp_register_layer(const char *name, struct ppp_layer_t *layer) continue; if (order<n->order) { - n1=malloc(sizeof(*n1)); + n1=_malloc(sizeof(*n1)); memset(n1,0,sizeof(*n1)); n1->order=order; INIT_LIST_HEAD(&n1->items); @@ -433,7 +441,7 @@ int __export ppp_register_layer(const char *name, struct ppp_layer_t *layer) } goto insert; } - n1=malloc(sizeof(*n1)); + n1=_malloc(sizeof(*n1)); memset(n1,0,sizeof(*n1)); n1->order=order; INIT_LIST_HEAD(&n1->items); @@ -455,10 +463,8 @@ static void init_layers(struct ppp_t *ppp) struct ppp_layer_t *l; struct ppp_layer_data_t *d; - INIT_LIST_HEAD(&ppp->layers); - list_for_each_entry(n,&layers,entry) { - n1 = (struct layer_node_t*)malloc(sizeof(*n1)); + n1 = _malloc(sizeof(*n1)); memset(n1, 0, sizeof(*n1)); INIT_LIST_HEAD(&n1->items); list_add_tail(&n1->entry, &ppp->layers); @@ -472,7 +478,7 @@ static void init_layers(struct ppp_t *ppp) } } -static void free_layers(struct ppp_t *ppp) +static void _free_layers(struct ppp_t *ppp) { struct layer_node_t *n; struct ppp_layer_data_t *d; @@ -485,7 +491,7 @@ static void free_layers(struct ppp_t *ppp) d->layer->free(d); } list_del(&n->entry); - free(n); + _free(n); } } diff --git a/accel-pptpd/ppp/ppp_auth.c b/accel-pptpd/ppp/ppp_auth.c index 5ad7444..d141b81 100644 --- a/accel-pptpd/ppp/ppp_auth.c +++ b/accel-pptpd/ppp/ppp_auth.c @@ -9,6 +9,7 @@ #include "ppp_auth.h" +#include "memdebug.h" static LIST_HEAD(auth_handlers); static int extra_opt_len=0; @@ -247,7 +248,7 @@ print_d: static struct ppp_layer_data_t *auth_layer_init(struct ppp_t *ppp) { - struct auth_layer_data_t *ad=(struct auth_layer_data_t*)malloc(sizeof(*ad)); + struct auth_layer_data_t *ad = _malloc(sizeof(*ad)); log_ppp_debug("auth_layer_init\n"); @@ -294,7 +295,7 @@ static void auth_layer_free(struct ppp_layer_data_t *ld) log_ppp_debug("auth_layer_free\n"); - free(ad); + _free(ad); } void __export auth_successed(struct ppp_t *ppp, char *username) diff --git a/accel-pptpd/ppp/ppp_ccp.c b/accel-pptpd/ppp/ppp_ccp.c index 8f240bc..301c238 100644 --- a/accel-pptpd/ppp/ppp_ccp.c +++ b/accel-pptpd/ppp/ppp_ccp.c @@ -11,6 +11,8 @@ #include "ppp.h" #include "ppp_ccp.h" +#include "memdebug.h" + struct recv_opt_t { struct list_head entry; @@ -35,6 +37,8 @@ static void ccp_options_init(struct ppp_ccp_t *ccp) struct ccp_option_t *lopt; struct ccp_option_handler_t *h; + ccp->conf_req_len = sizeof(struct ccp_hdr_t); + list_for_each_entry(h,&option_handlers,entry) { lopt=h->init(ccp); @@ -61,7 +65,7 @@ static void ccp_options_free(struct ppp_ccp_t *ccp) static struct ppp_layer_data_t *ccp_layer_init(struct ppp_t *ppp) { - struct ppp_ccp_t *ccp=malloc(sizeof(*ccp)); + struct ppp_ccp_t *ccp=_malloc(sizeof(*ccp)); memset(ccp,0,sizeof(*ccp)); log_ppp_debug("ccp_layer_init\n"); @@ -123,7 +127,7 @@ void ccp_layer_free(struct ppp_layer_data_t *ld) ccp_options_free(ccp); ppp_fsm_free(&ccp->fsm); - free(ccp); + _free(ccp); } static void ccp_layer_up(struct ppp_fsm_t *fsm) @@ -156,7 +160,7 @@ static void print_ropt(struct recv_opt_t *ropt) static int send_conf_req(struct ppp_fsm_t *fsm) { struct ppp_ccp_t *ccp=container_of(fsm,typeof(*ccp),fsm); - uint8_t *buf=malloc(ccp->conf_req_len), *ptr=buf; + uint8_t *buf=_malloc(ccp->conf_req_len), *ptr=buf; struct ccp_hdr_t *ccp_hdr=(struct ccp_hdr_t*)ptr; struct ccp_option_t *lopt; int n; @@ -188,6 +192,8 @@ static int send_conf_req(struct ppp_fsm_t *fsm) ccp_hdr->len=htons((ptr-buf)-2); ppp_unit_send(ccp->ppp,ccp_hdr,ptr-buf); + _free(buf); + return 0; } @@ -205,7 +211,7 @@ static void send_conf_ack(struct ppp_fsm_t *fsm) static void send_conf_nak(struct ppp_fsm_t *fsm) { struct ppp_ccp_t *ccp=container_of(fsm,typeof(*ccp),fsm); - uint8_t *buf=malloc(ccp->conf_req_len), *ptr=buf; + uint8_t *buf=_malloc(ccp->conf_req_len), *ptr=buf; struct ccp_hdr_t *ccp_hdr=(struct ccp_hdr_t*)ptr; struct recv_opt_t *ropt; @@ -232,12 +238,14 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) ccp_hdr->len=htons((ptr-buf)-2); ppp_unit_send(ccp->ppp,ccp_hdr,ptr-buf); + + _free(buf); } static void send_conf_rej(struct ppp_fsm_t *fsm) { struct ppp_ccp_t *ccp=container_of(fsm,typeof(*ccp),fsm); - uint8_t *buf=malloc(ccp->ropt_len), *ptr=buf; + uint8_t *buf=_malloc(ccp->ropt_len + sizeof(struct ccp_hdr_t)), *ptr=buf; struct ccp_hdr_t *ccp_hdr=(struct ccp_hdr_t*)ptr; struct recv_opt_t *ropt; @@ -266,6 +274,8 @@ static void send_conf_rej(struct ppp_fsm_t *fsm) ccp_hdr->len=htons((ptr-buf)-2); ppp_unit_send(ccp->ppp,ccp_hdr,ptr-buf); + + _free(buf); } static int ccp_recv_conf_req(struct ppp_ccp_t *ccp,uint8_t *data,int size) @@ -281,7 +291,7 @@ static int ccp_recv_conf_req(struct ppp_ccp_t *ccp,uint8_t *data,int size) { hdr=(struct ccp_opt_hdr_t *)data; - ropt=malloc(sizeof(*ropt)); + ropt=_malloc(sizeof(*ropt)); memset(ropt,0,sizeof(*ropt)); if (hdr->len>size) ropt->len=size; else ropt->len=hdr->len; @@ -353,7 +363,7 @@ static void ccp_free_conf_req(struct ppp_ccp_t *ccp) { ropt=list_entry(ccp->ropt_list.next,typeof(*ropt),entry); list_del(&ropt->entry); - free(ropt); + _free(ropt); } } @@ -534,16 +544,16 @@ static void ccp_recv(struct ppp_handler_t*h) ppp_fsm_recv_conf_rej(&ccp->fsm); break; case TERMREQ: - term_msg=strndup((char*)(hdr+1),ntohs(hdr->len)); + term_msg=_strndup((char*)(hdr+1),ntohs(hdr->len)); log_ppp_debug("recv [CCP TermReq id=%x \"%s\"]\n",hdr->id,term_msg); - free(term_msg); + _free(term_msg); ppp_fsm_recv_term_req(&ccp->fsm); ppp_terminate(ccp->ppp, 0); break; case TERMACK: - term_msg=strndup((char*)(hdr+1),ntohs(hdr->len)); + term_msg=_strndup((char*)(hdr+1),ntohs(hdr->len)); log_ppp_debug("recv [CCP TermAck id=%x \"%s\"]\n",hdr->id,term_msg); - free(term_msg); + _free(term_msg); ppp_fsm_recv_term_ack(&ccp->fsm); break; case CODEREJ: diff --git a/accel-pptpd/ppp/ppp_fsm.c b/accel-pptpd/ppp/ppp_fsm.c index 0e11b66..3b8d854 100644 --- a/accel-pptpd/ppp/ppp_fsm.c +++ b/accel-pptpd/ppp/ppp_fsm.c @@ -8,6 +8,8 @@ #include "ppp_lcp.h" #include "log.h" +#include "memdebug.h" + static int conf_max_terminate = 2; static int conf_max_configure = 5; static int conf_max_failure = 5; @@ -372,7 +374,7 @@ void ppp_fsm_recv_term_req(struct ppp_fsm_t *layer) { case FSM_Opened: if (layer->layer_down) layer->layer_down(layer); - send_term_req(layer); + //send_term_req(layer); send_term_ack(layer); //if (layer->zero_req_cnt) layer->zero_req_cnt(layer); zero_req_counter(layer); @@ -381,7 +383,7 @@ void ppp_fsm_recv_term_req(struct ppp_fsm_t *layer) case FSM_Req_Sent: case FSM_Ack_Rcvd: case FSM_Ack_Sent: - send_term_req(layer); + send_term_ack(layer); layer->fsm_state=FSM_Req_Sent; break; default: diff --git a/accel-pptpd/ppp/ppp_ipcp.c b/accel-pptpd/ppp/ppp_ipcp.c index b8dfe7f..f3c20a6 100644 --- a/accel-pptpd/ppp/ppp_ipcp.c +++ b/accel-pptpd/ppp/ppp_ipcp.c @@ -11,6 +11,8 @@ #include "ppp.h" #include "ppp_ipcp.h" +#include "memdebug.h" + struct recv_opt_t { struct list_head entry; @@ -35,6 +37,8 @@ static void ipcp_options_init(struct ppp_ipcp_t *ipcp) struct ipcp_option_t *lopt; struct ipcp_option_handler_t *h; + ipcp->conf_req_len = sizeof(struct ipcp_hdr_t); + list_for_each_entry(h,&option_handlers,entry) { lopt=h->init(ipcp); @@ -61,7 +65,7 @@ static void ipcp_options_free(struct ppp_ipcp_t *ipcp) static struct ppp_layer_data_t *ipcp_layer_init(struct ppp_t *ppp) { - struct ppp_ipcp_t *ipcp=malloc(sizeof(*ipcp)); + struct ppp_ipcp_t *ipcp=_malloc(sizeof(*ipcp)); memset(ipcp,0,sizeof(*ipcp)); log_ppp_debug("ipcp_layer_init\n"); @@ -123,7 +127,7 @@ void ipcp_layer_free(struct ppp_layer_data_t *ld) ipcp_options_free(ipcp); ppp_fsm_free(&ipcp->fsm); - free(ipcp); + _free(ipcp); } static void ipcp_layer_up(struct ppp_fsm_t *fsm) @@ -156,7 +160,7 @@ static void print_ropt(struct recv_opt_t *ropt) static int send_conf_req(struct ppp_fsm_t *fsm) { struct ppp_ipcp_t *ipcp=container_of(fsm,typeof(*ipcp),fsm); - uint8_t *buf=malloc(ipcp->conf_req_len), *ptr=buf; + uint8_t *buf=_malloc(ipcp->conf_req_len), *ptr=buf; struct ipcp_hdr_t *ipcp_hdr=(struct ipcp_hdr_t*)ptr; struct ipcp_option_t *lopt; int n; @@ -194,6 +198,8 @@ static int send_conf_req(struct ppp_fsm_t *fsm) ipcp_hdr->len=htons((ptr-buf)-2); ppp_unit_send(ipcp->ppp,ipcp_hdr,ptr-buf); + _free(buf); + return 0; } @@ -211,7 +217,7 @@ static void send_conf_ack(struct ppp_fsm_t *fsm) static void send_conf_nak(struct ppp_fsm_t *fsm) { struct ppp_ipcp_t *ipcp=container_of(fsm,typeof(*ipcp),fsm); - uint8_t *buf=malloc(ipcp->conf_req_len), *ptr=buf; + uint8_t *buf=_malloc(ipcp->conf_req_len), *ptr=buf; struct ipcp_hdr_t *ipcp_hdr=(struct ipcp_hdr_t*)ptr; struct recv_opt_t *ropt; @@ -238,12 +244,14 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) ipcp_hdr->len=htons((ptr-buf)-2); ppp_unit_send(ipcp->ppp,ipcp_hdr,ptr-buf); + + _free(buf); } static void send_conf_rej(struct ppp_fsm_t *fsm) { struct ppp_ipcp_t *ipcp=container_of(fsm,typeof(*ipcp),fsm); - uint8_t *buf=malloc(ipcp->ropt_len), *ptr=buf; + uint8_t *buf=_malloc(ipcp->ropt_len + sizeof(struct ipcp_hdr_t)), *ptr=buf; struct ipcp_hdr_t *ipcp_hdr=(struct ipcp_hdr_t*)ptr; struct recv_opt_t *ropt; @@ -272,6 +280,8 @@ static void send_conf_rej(struct ppp_fsm_t *fsm) ipcp_hdr->len=htons((ptr-buf)-2); ppp_unit_send(ipcp->ppp,ipcp_hdr,ptr-buf); + + _free(buf); } static int ipcp_recv_conf_req(struct ppp_ipcp_t *ipcp,uint8_t *data,int size) @@ -287,7 +297,7 @@ static int ipcp_recv_conf_req(struct ppp_ipcp_t *ipcp,uint8_t *data,int size) { hdr=(struct ipcp_opt_hdr_t *)data; - ropt=malloc(sizeof(*ropt)); + ropt=_malloc(sizeof(*ropt)); memset(ropt,0,sizeof(*ropt)); if (hdr->len>size) ropt->len=size; else ropt->len=hdr->len; @@ -350,7 +360,7 @@ static void ipcp_free_conf_req(struct ppp_ipcp_t *ipcp) { ropt=list_entry(ipcp->ropt_list.next,typeof(*ropt),entry); list_del(&ropt->entry); - free(ropt); + _free(ropt); } } @@ -531,16 +541,16 @@ static void ipcp_recv(struct ppp_handler_t*h) ppp_fsm_recv_conf_rej(&ipcp->fsm); break; case TERMREQ: - term_msg=strndup((char*)(hdr+1),ntohs(hdr->len)); + term_msg=_strndup((char*)(hdr+1),ntohs(hdr->len)); log_ppp_debug("recv [IPCP TermReq id=%x \"%s\"]\n",hdr->id,term_msg); - free(term_msg); + _free(term_msg); ppp_fsm_recv_term_req(&ipcp->fsm); ppp_terminate(ipcp->ppp, 0); break; case TERMACK: - term_msg=strndup((char*)(hdr+1),ntohs(hdr->len)); + term_msg=_strndup((char*)(hdr+1),ntohs(hdr->len)); log_ppp_debug("recv [IPCP TermAck id=%x \"%s\"]\n",hdr->id,term_msg); - free(term_msg); + _free(term_msg); ppp_fsm_recv_term_ack(&ipcp->fsm); break; case CODEREJ: diff --git a/accel-pptpd/ppp/ppp_lcp.c b/accel-pptpd/ppp/ppp_lcp.c index b5afb5a..a85b3d1 100644 --- a/accel-pptpd/ppp/ppp_lcp.c +++ b/accel-pptpd/ppp/ppp_lcp.c @@ -11,6 +11,8 @@ #include "ppp.h" #include "ppp_lcp.h" +#include "memdebug.h" + struct recv_opt_t { struct list_head entry; @@ -42,6 +44,8 @@ static void lcp_options_init(struct ppp_lcp_t *lcp) INIT_LIST_HEAD(&lcp->options); + lcp->conf_req_len = sizeof(struct lcp_hdr_t); + list_for_each_entry(h,&option_handlers,entry) { lopt=h->init(lcp); @@ -68,7 +72,7 @@ static void lcp_options_free(struct ppp_lcp_t *lcp) static struct ppp_layer_data_t *lcp_layer_init(struct ppp_t *ppp) { - struct ppp_lcp_t *lcp=malloc(sizeof(*lcp)); + struct ppp_lcp_t *lcp=_malloc(sizeof(*lcp)); memset(lcp,0,sizeof(*lcp)); log_ppp_debug("lcp_layer_init\n"); @@ -131,7 +135,7 @@ void lcp_layer_free(struct ppp_layer_data_t *ld) lcp_options_free(lcp); ppp_fsm_free(&lcp->fsm); - free(lcp); + _free(lcp); } static void lcp_layer_up(struct ppp_fsm_t *fsm) @@ -146,6 +150,7 @@ static void lcp_layer_up(struct ppp_fsm_t *fsm) static void lcp_layer_down(struct ppp_fsm_t *fsm) { struct ppp_lcp_t *lcp=container_of(fsm,typeof(*lcp),fsm); + ppp_fsm_close(&lcp->fsm); log_ppp_debug("lcp_layer_finished\n"); stop_echo(lcp); ppp_layer_finished(lcp->ppp,&lcp->ld); @@ -167,7 +172,7 @@ static void print_ropt(struct recv_opt_t *ropt) static int send_conf_req(struct ppp_fsm_t *fsm) { struct ppp_lcp_t *lcp=container_of(fsm,typeof(*lcp),fsm); - uint8_t *buf=malloc(lcp->conf_req_len), *ptr=buf; + uint8_t *buf=_malloc(lcp->conf_req_len), *ptr=buf; struct lcp_hdr_t *lcp_hdr=(struct lcp_hdr_t*)ptr; struct lcp_option_t *lopt; int n; @@ -207,6 +212,8 @@ static int send_conf_req(struct ppp_fsm_t *fsm) lcp_hdr->len=htons((ptr-buf)-2); ppp_chan_send(lcp->ppp,lcp_hdr,ptr-buf); + _free(buf); + return 0; } @@ -224,7 +231,7 @@ static void send_conf_ack(struct ppp_fsm_t *fsm) static void send_conf_nak(struct ppp_fsm_t *fsm) { struct ppp_lcp_t *lcp=container_of(fsm,typeof(*lcp),fsm); - uint8_t *buf=malloc(lcp->conf_req_len), *ptr=buf; + uint8_t *buf=_malloc(lcp->conf_req_len), *ptr=buf; struct lcp_hdr_t *lcp_hdr=(struct lcp_hdr_t*)ptr; struct recv_opt_t *ropt; @@ -256,7 +263,7 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) static void send_conf_rej(struct ppp_fsm_t *fsm) { struct ppp_lcp_t *lcp=container_of(fsm,typeof(*lcp),fsm); - uint8_t *buf=malloc(lcp->ropt_len), *ptr=buf; + uint8_t *buf=_malloc(lcp->ropt_len + sizeof(struct lcp_hdr_t)), *ptr=buf; struct lcp_hdr_t *lcp_hdr=(struct lcp_hdr_t*)ptr; struct recv_opt_t *ropt; @@ -285,6 +292,8 @@ static void send_conf_rej(struct ppp_fsm_t *fsm) lcp_hdr->len=htons((ptr-buf)-2); ppp_chan_send(lcp->ppp,lcp_hdr,ptr-buf); + + _free(buf); } static int lcp_recv_conf_req(struct ppp_lcp_t *lcp,uint8_t *data,int size) @@ -300,7 +309,7 @@ static int lcp_recv_conf_req(struct ppp_lcp_t *lcp,uint8_t *data,int size) { hdr=(struct lcp_opt_hdr_t *)data; - ropt=malloc(sizeof(*ropt)); + ropt=_malloc(sizeof(*ropt)); if (hdr->len>size) ropt->len=size; else ropt->len=hdr->len; ropt->hdr=hdr; @@ -362,7 +371,7 @@ static void lcp_free_conf_req(struct ppp_lcp_t *lcp) { ropt=list_entry(lcp->ropt_list.next,typeof(*ropt),entry); list_del(&ropt->entry); - free(ropt); + _free(ropt); } } @@ -594,29 +603,35 @@ static void lcp_recv(struct ppp_handler_t*h) if (lcp_recv_conf_ack(lcp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN)) ppp_terminate(lcp->ppp, 0); else + if (lcp->fsm.recv_id!=lcp->fsm.id) + break; ppp_fsm_recv_conf_ack(&lcp->fsm); break; case CONFNAK: lcp_recv_conf_nak(lcp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN); + if (lcp->fsm.recv_id!=lcp->fsm.id) + break; ppp_fsm_recv_conf_rej(&lcp->fsm); break; case CONFREJ: if (lcp_recv_conf_rej(lcp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN)) ppp_terminate(lcp->ppp, 0); else + if (lcp->fsm.recv_id!=lcp->fsm.id) + break; ppp_fsm_recv_conf_rej(&lcp->fsm); break; case TERMREQ: - term_msg=strndup((char*)(hdr+1),ntohs(hdr->len)-4); + term_msg=_strndup((char*)(hdr+1),ntohs(hdr->len)-4); log_ppp_debug("recv [LCP TermReq id=%x \"%s\"]\n",hdr->id,term_msg); - free(term_msg); + _free(term_msg); ppp_fsm_recv_term_req(&lcp->fsm); ppp_terminate(lcp->ppp, 0); break; case TERMACK: - term_msg=strndup((char*)(hdr+1),ntohs(hdr->len)-4); + term_msg=_strndup((char*)(hdr+1),ntohs(hdr->len)-4); log_ppp_debug("recv [LCP TermAck id=%x \"%s\"]\n",hdr->id,term_msg); - free(term_msg); + _free(term_msg); ppp_fsm_recv_term_ack(&lcp->fsm); break; case CODEREJ: diff --git a/accel-pptpd/ppp/ppp_pd.c b/accel-pptpd/ppp/ppp_pd.c index fe51bc0..f770208 100644 --- a/accel-pptpd/ppp/ppp_pd.c +++ b/accel-pptpd/ppp/ppp_pd.c @@ -1,5 +1,7 @@ #include "ppp.h" +#include "memdebug.h" + int ppp_store_pd(struct ppp_t *ppp, pd_key_t key, void *data) { struct ppp_pd_t *pd; |