From 5cf93f33f2350ed3b92f73ead1d2829a6883810a Mon Sep 17 00:00:00 2001 From: Kozlov Dmitry Date: Tue, 5 Oct 2010 17:51:23 +0400 Subject: tidied logs --- accel-pptpd/ppp/ipcp_opt_ipaddr.c | 2 +- accel-pptpd/ppp/lcp_opt_mru.c | 22 +- accel-pptpd/ppp/ppp.c | 183 ++++++------- accel-pptpd/ppp/ppp.h | 1 + accel-pptpd/ppp/ppp_auth.c | 203 +++++++------- accel-pptpd/ppp/ppp_auth.h | 1 + accel-pptpd/ppp/ppp_ccp.c | 456 ++++++++++++++++--------------- accel-pptpd/ppp/ppp_ipcp.c | 502 +++++++++++++++++----------------- accel-pptpd/ppp/ppp_lcp.c | 556 ++++++++++++++++++++------------------ 9 files changed, 993 insertions(+), 933 deletions(-) (limited to 'accel-pptpd/ppp') diff --git a/accel-pptpd/ppp/ipcp_opt_ipaddr.c b/accel-pptpd/ppp/ipcp_opt_ipaddr.c index 108e350..efbc41e 100644 --- a/accel-pptpd/ppp/ipcp_opt_ipaddr.c +++ b/accel-pptpd/ppp/ipcp_opt_ipaddr.c @@ -67,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_mru.c b/accel-pptpd/ppp/lcp_opt_mru.c index 9bf7af6..eab57b0 100644 --- a/accel-pptpd/ppp/lcp_opt_mru.c +++ b/accel-pptpd/ppp/lcp_opt_mru.c @@ -14,7 +14,9 @@ #include "memdebug.h" static int conf_mtu; +static int conf_mru; static int conf_min_mtu = 100; +static int conf_max_mtu = 1500; static struct lcp_option_t *mru_init(struct ppp_lcp_t *lcp); static void mru_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt); @@ -46,8 +48,12 @@ static struct lcp_option_t *mru_init(struct ppp_lcp_t *lcp) { struct mru_option_t *mru_opt=_malloc(sizeof(*mru_opt)); memset(mru_opt, 0, sizeof(*mru_opt)); - mru_opt->mtu = 0; - mru_opt->mru = (conf_mtu && conf_mtu <= lcp->ppp->ctrl->max_mtu) ? conf_mtu : lcp->ppp->ctrl->max_mtu; + mru_opt->mru = (conf_mru && conf_mru <= lcp->ppp->ctrl->max_mtu) ? conf_mru : lcp->ppp->ctrl->max_mtu; + if (mru_opt->mru > conf_max_mtu) + mru_opt->mru = conf_max_mtu; + mru_opt->mtu = (conf_mtu && conf_mtu <= lcp->ppp->ctrl->max_mtu) ? conf_mtu : lcp->ppp->ctrl->max_mtu; + if (mru_opt->mtu > conf_max_mtu) + mru_opt->mtu = conf_max_mtu; mru_opt->opt.id = CI_MRU; mru_opt->opt.len = 4; @@ -77,7 +83,7 @@ static int mru_send_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui struct lcp_opt16_t *opt16 = (struct lcp_opt16_t*)ptr; opt16->hdr.id = CI_MRU; opt16->hdr.len = 4; - opt16->val = htons(mru_opt->mtu ? mru_opt->mtu : lcp->ppp->ctrl->max_mtu); + opt16->val = htons(mru_opt->mtu); return 4; } @@ -92,7 +98,7 @@ static int mru_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui if (opt16->hdr.len != 4) return LCP_OPT_REJ; - if (ntohs(opt16->val) < conf_min_mtu || ntohs(opt16->val) > lcp->ppp->ctrl->max_mtu) + if (ntohs(opt16->val) < conf_min_mtu || ntohs(opt16->val) > lcp->ppp->ctrl->max_mtu || ntohs(opt16->val) > conf_max_mtu) return LCP_OPT_NAK; mru_opt->mtu = ntohs(opt16->val); @@ -136,9 +142,17 @@ static void __init mru_opt_init() if (opt && atoi(opt) > 0) conf_mtu = atoi(opt); + opt = conf_get_opt("ppp", "mru"); + if (opt && atoi(opt) > 0) + conf_mru = atoi(opt); + opt = conf_get_opt("ppp", "min-mtu"); if (opt && atoi(opt) > 0) conf_min_mtu = atoi(opt); + + opt = conf_get_opt("ppp", "max-mtu"); + if (opt && atoi(opt) > 0) + conf_max_mtu = atoi(opt); lcp_option_register(&mru_opt_hnd); } diff --git a/accel-pptpd/ppp/ppp.c b/accel-pptpd/ppp/ppp.c index ee7e13c..3e51ecb 100644 --- a/accel-pptpd/ppp/ppp.c +++ b/accel-pptpd/ppp/ppp.c @@ -21,7 +21,7 @@ #include "memdebug.h" -int conf_ppp_verbose; +int __export conf_ppp_verbose; static LIST_HEAD(layers); int __export sock_fd; @@ -79,87 +79,80 @@ static void generate_sessionid(struct ppp_t *ppp) int __export establish_ppp(struct ppp_t *ppp) { /* Open an instance of /dev/ppp and connect the channel to it */ - if (ioctl(ppp->fd, PPPIOCGCHAN, &ppp->chan_idx)==-1) - { - log_ppp_error("Couldn't get channel number\n"); - return -1; + if (ioctl(ppp->fd, PPPIOCGCHAN, &ppp->chan_idx) == -1) { + log_ppp_error("Couldn't get channel number\n"); + return -1; } - ppp->chan_fd=open("/dev/ppp", O_RDWR); - if (ppp->chan_fd<0) - { - log_ppp_error("Couldn't reopen /dev/ppp\n"); - return -1; + ppp->chan_fd = open("/dev/ppp", O_RDWR); + if (ppp->chan_fd < 0) { + log_ppp_error("Couldn't reopen /dev/ppp\n"); + return -1; } - if (ioctl(ppp->chan_fd, PPPIOCATTCHAN, &ppp->chan_idx)<0) - { - log_ppp_error("Couldn't attach to channel %d\n", ppp->chan_idx); - goto exit_close_chan; + if (ioctl(ppp->chan_fd, PPPIOCATTCHAN, &ppp->chan_idx) < 0) { + log_ppp_error("Couldn't attach to channel %d\n", ppp->chan_idx); + goto exit_close_chan; } - ppp->unit_fd=open("/dev/ppp", O_RDWR); - if (ppp->unit_fd<0) - { - log_ppp_error("Couldn't reopen /dev/ppp\n"); - goto exit_close_chan; + ppp->unit_fd = open("/dev/ppp", O_RDWR); + if (ppp->unit_fd < 0) { + log_ppp_error("Couldn't reopen /dev/ppp\n"); + goto exit_close_chan; } - ppp->unit_idx=-1; - if (ioctl(ppp->unit_fd, PPPIOCNEWUNIT, &ppp->unit_idx)<0) - { + ppp->unit_idx = -1; + if (ioctl(ppp->unit_fd, PPPIOCNEWUNIT, &ppp->unit_idx) < 0) { log_ppp_error("Couldn't create new ppp unit\n"); goto exit_close_unit; } - if (ioctl(ppp->chan_fd, PPPIOCCONNECT, &ppp->unit_idx)<0) - { + if (ioctl(ppp->chan_fd, PPPIOCCONNECT, &ppp->unit_idx) < 0) { log_ppp_error("Couldn't attach to PPP unit %d\n", ppp->unit_idx); goto exit_close_unit; } + if (fcntl(ppp->chan_fd, F_SETFL, O_NONBLOCK)) { + log_ppp_error("ppp: cann't to set nonblocking mode: %s\n", strerror(errno)); + goto exit_close_unit; + } + + if (fcntl(ppp->unit_fd, F_SETFL, O_NONBLOCK)) { + log_ppp_error("ppp: cann't to set nonblocking mode: %s\n", strerror(errno)); + goto exit_close_unit; + } + ppp->start_time = time(NULL); generate_sessionid(ppp); sprintf(ppp->ifname, "ppp%i", ppp->unit_idx); - log_ppp_info("connect: ppp%i <--> pptp(%s)\n",ppp->unit_idx,ppp->chan_name); + if (conf_ppp_verbose) + log_ppp_info("connect: %s <--> %s(%s)\n", ppp->ifname, ppp->ctrl->name, ppp->chan_name); - ppp->chan_buf=_malloc(PPP_MRU); - ppp->unit_buf=_malloc(PPP_MRU); - init_layers(ppp); - if (list_empty(&ppp->layers)) - { + if (list_empty(&ppp->layers)) { log_ppp_error("no layers to start\n"); goto exit_close_unit; } - if (fcntl(ppp->chan_fd, F_SETFL, O_NONBLOCK)) { - log_ppp_error("ppp: cann't to set nonblocking mode: %s\n", strerror(errno)); - goto exit_close_unit; - } - - if (fcntl(ppp->unit_fd, F_SETFL, O_NONBLOCK)) { - log_ppp_error("ppp: cann't to set nonblocking mode: %s\n", strerror(errno)); - goto exit_close_unit; - } + ppp->chan_buf = _malloc(PPP_MRU); + ppp->unit_buf = _malloc(PPP_MRU); - ppp->chan_hnd.fd=ppp->chan_fd; - ppp->chan_hnd.read=ppp_chan_read; - //ppp->chan_hnd.twait=-1; - ppp->unit_hnd.fd=ppp->unit_fd; - ppp->unit_hnd.read=ppp_unit_read; - //ppp->unit_hnd.twait=-1; + ppp->chan_hnd.fd = ppp->chan_fd; + ppp->chan_hnd.read = ppp_chan_read; + ppp->unit_hnd.fd = ppp->unit_fd; + ppp->unit_hnd.read = ppp_unit_read; triton_md_register_handler(ppp->ctrl->ctx, &ppp->chan_hnd); triton_md_register_handler(ppp->ctrl->ctx, &ppp->unit_hnd); - triton_md_enable_handler(&ppp->chan_hnd,MD_MODE_READ); - triton_md_enable_handler(&ppp->unit_hnd,MD_MODE_READ); + triton_md_enable_handler(&ppp->chan_hnd, MD_MODE_READ); + triton_md_enable_handler(&ppp->unit_hnd, MD_MODE_READ); log_ppp_debug("ppp established\n"); triton_event_fire(EV_PPP_STARTING, ppp); + start_first_layer(ppp); return 0; @@ -202,13 +195,13 @@ static void destablish_ppp(struct ppp_t *ppp) } } -void print_buf(uint8_t *buf,int size) +/*void print_buf(uint8_t *buf, int size) { int i; for(i=0;ichan_fd,data,size); - if (nchan_fd,data,size); + if (n < size) + log_ppp_error("ppp_chan_send: short write %i, excpected %i\n", n, size); return n; } @@ -230,8 +223,8 @@ int __export ppp_unit_send(struct ppp_t *ppp, void *data, int size) //printf("ppp_unit_send: "); //print_buf((uint8_t*)data,size); - n=write(ppp->unit_fd,data,size); - if (nunit_fd, data, size); + if (n < size) log_ppp_error("ppp_unit_send: short write %i, excpected %i\n",n,size); return n; } @@ -246,11 +239,9 @@ static int ppp_chan_read(struct triton_md_handler_t *h) cont: ppp->chan_buf_size = read(h->fd, ppp->chan_buf, PPP_MRU); if (ppp->chan_buf_size < 0) { - if (errno == EINTR) - continue; if (errno == EAGAIN) return 0; - log_ppp_error("ppp_chan_read: %s\n",strerror(errno)); + log_ppp_error("ppp_chan_read: %s\n", strerror(errno)); return 0; } @@ -289,8 +280,6 @@ static int ppp_unit_read(struct triton_md_handler_t *h) cont: ppp->unit_buf_size = read(h->fd, ppp->unit_buf, PPP_MRU); if (ppp->unit_buf_size < 0) { - if (errno == EINTR) - continue; if (errno == EAGAIN) return 0; log_ppp_error("ppp_chan_read: %s\n",strerror(errno)); @@ -324,26 +313,23 @@ cont: void __export ppp_layer_started(struct ppp_t *ppp, struct ppp_layer_data_t *d) { - struct layer_node_t *n=d->node; + struct layer_node_t *n = d->node; if (d->started) return; - d->started=1; + d->started = 1; - list_for_each_entry(d,&n->items,entry) + list_for_each_entry(d, &n->items, entry) if (!d->started) return; - if (n->entry.next==&ppp->layers) - { + if (n->entry.next == &ppp->layers) { ppp->ctrl->started(ppp); triton_event_fire(EV_PPP_STARTED, ppp); - }else - { - n=list_entry(n->entry.next,typeof(*n),entry); - list_for_each_entry(d,&n->items,entry) - { - d->starting=1; + } else { + n = list_entry(n->entry.next, typeof(*n), entry); + list_for_each_entry(d, &n->items, entry) { + d->starting = 1; if (d->layer->start(d)) { ppp_terminate(ppp, 0); return; @@ -354,15 +340,13 @@ void __export ppp_layer_started(struct ppp_t *ppp, struct ppp_layer_data_t *d) void __export ppp_layer_finished(struct ppp_t *ppp, struct ppp_layer_data_t *d) { - struct layer_node_t *n=d->node; + struct layer_node_t *n = d->node; d->finished = 1; d->starting = 0; - list_for_each_entry(n,&ppp->layers,entry) - { - list_for_each_entry(d,&n->items,entry) - { + list_for_each_entry(n, &ppp->layers, entry) { + list_for_each_entry(d, &n->items, entry) { if (!d->finished) return; } @@ -434,34 +418,32 @@ int __export ppp_register_layer(const char *name, struct ppp_layer_t *layer) int order; struct layer_node_t *n,*n1; - order=get_layer_order(name); + order = get_layer_order(name); - if (order<0) + if (order < 0) return order; - list_for_each_entry(n,&layers,entry) - { - if (order>n->order) + list_for_each_entry(n, &layers, entry) { + if (order > n->order) continue; - if (orderorder) - { - n1=_malloc(sizeof(*n1)); - memset(n1,0,sizeof(*n1)); - n1->order=order; + if (order < n->order) { + n1 = _malloc(sizeof(*n1)); + memset(n1, 0, sizeof(*n1)); + n1->order = order; INIT_LIST_HEAD(&n1->items); - list_add_tail(&n1->entry,&n->entry); - n=n1; + list_add_tail(&n1->entry, &n->entry); + n = n1; } goto insert; } - n1=_malloc(sizeof(*n1)); - memset(n1,0,sizeof(*n1)); - n1->order=order; + n1 = _malloc(sizeof(*n1)); + memset(n1, 0, sizeof(*n1)); + n1->order = order; INIT_LIST_HEAD(&n1->items); - list_add_tail(&n1->entry,&layers); - n=n1; + list_add_tail(&n1->entry, &layers); + n = n1; insert: - list_add_tail(&layer->entry,&n->items); + list_add_tail(&layer->entry, &n->items); return 0; } @@ -513,10 +495,9 @@ static void start_first_layer(struct ppp_t *ppp) struct layer_node_t *n; struct ppp_layer_data_t *d; - n=list_entry(ppp->layers.next,typeof(*n),entry); - list_for_each_entry(d,&n->items,entry) - { - d->starting=1; + n = list_entry(ppp->layers.next, typeof(*n), entry); + list_for_each_entry(d, &n->items, entry) { + d->starting = 1; if (d->layer->start(d)) { ppp_terminate(ppp, 0); return; @@ -529,11 +510,9 @@ struct ppp_layer_data_t *ppp_find_layer_data(struct ppp_t *ppp, struct ppp_layer struct layer_node_t *n; struct ppp_layer_data_t *d; - list_for_each_entry(n,&ppp->layers,entry) - { - list_for_each_entry(d,&n->items,entry) - { - if (d->layer==layer) + list_for_each_entry(n,&ppp->layers,entry) { + list_for_each_entry(d,&n->items,entry) { + if (d->layer == layer) return d; } } diff --git a/accel-pptpd/ppp/ppp.h b/accel-pptpd/ppp/ppp.h index afc26a3..fb6b20f 100644 --- a/accel-pptpd/ppp/ppp.h +++ b/accel-pptpd/ppp/ppp.h @@ -51,6 +51,7 @@ struct ppp_t; struct ppp_ctrl_t { struct triton_context_t *ctx; + const char *name; int max_mtu; char *calling_station_id; char *called_station_id; diff --git a/accel-pptpd/ppp/ppp_auth.c b/accel-pptpd/ppp/ppp_auth.c index ada01ad..65ca223 100644 --- a/accel-pptpd/ppp/ppp_auth.c +++ b/accel-pptpd/ppp/ppp_auth.c @@ -12,7 +12,7 @@ #include "memdebug.h" static LIST_HEAD(auth_handlers); -static int extra_opt_len=0; +static int extra_opt_len = 0; static struct lcp_option_t *auth_init(struct ppp_lcp_t *lcp); static void auth_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt); @@ -21,7 +21,7 @@ static int auth_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, u static int auth_recv_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr); static int auth_recv_conf_rej(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr); static int auth_recv_conf_ack(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr); -static void auth_print(void (*print)(const char *fmt,...),struct lcp_option_t*, uint8_t *ptr); +static void auth_print(void (*print)(const char *fmt,...), struct lcp_option_t*, uint8_t *ptr); static struct ppp_layer_data_t *auth_layer_init(struct ppp_t*); static int auth_layer_start(struct ppp_layer_data_t *); @@ -44,25 +44,25 @@ struct auth_layer_data_t int started:1; }; -static struct lcp_option_handler_t auth_opt_hnd= +static struct lcp_option_handler_t auth_opt_hnd = { - .init=auth_init, - .send_conf_req=auth_send_conf_req, - .send_conf_nak=auth_send_conf_req, - .recv_conf_req=auth_recv_conf_req, - .recv_conf_nak=auth_recv_conf_nak, - .recv_conf_rej=auth_recv_conf_rej, - .recv_conf_ack=auth_recv_conf_ack, - .free=auth_free, - .print=auth_print, + .init = auth_init, + .send_conf_req = auth_send_conf_req, + .send_conf_nak = auth_send_conf_req, + .recv_conf_req = auth_recv_conf_req, + .recv_conf_nak = auth_recv_conf_nak, + .recv_conf_rej = auth_recv_conf_rej, + .recv_conf_ack = auth_recv_conf_ack, + .free = auth_free, + .print = auth_print, }; -static struct ppp_layer_t auth_layer= +static struct ppp_layer_t auth_layer = { - .init=auth_layer_init, - .start=auth_layer_start, - .finish=auth_layer_finish, - .free=auth_layer_free, + .init = auth_layer_init, + .start = auth_layer_start, + .finish = auth_layer_finish, + .free = auth_layer_free, }; static struct lcp_option_t *auth_init(struct ppp_lcp_t *lcp) @@ -71,18 +71,17 @@ static struct lcp_option_t *auth_init(struct ppp_lcp_t *lcp) struct auth_data_t *d; struct auth_layer_data_t *ad; - ad=container_of(ppp_find_layer_data(lcp->ppp,&auth_layer),typeof(*ad),ld); + ad = container_of(ppp_find_layer_data(lcp->ppp, &auth_layer), typeof(*ad), ld); - ad->auth_opt.opt.id=CI_AUTH; - ad->auth_opt.opt.len=4+extra_opt_len; + ad->auth_opt.opt.id = CI_AUTH; + ad->auth_opt.opt.len = 4 + extra_opt_len; INIT_LIST_HEAD(&ad->auth_opt.auth_list); - list_for_each_entry(h,&auth_handlers,entry) - { - d=h->init(lcp->ppp); - d->h=h; - list_add_tail(&d->entry,&ad->auth_opt.auth_list); + list_for_each_entry(h, &auth_handlers, entry) { + d = h->init(lcp->ppp); + d->h = h; + list_add_tail(&d->entry, &ad->auth_opt.auth_list); } return &ad->auth_opt.opt; @@ -90,49 +89,47 @@ static struct lcp_option_t *auth_init(struct ppp_lcp_t *lcp) static void auth_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt) { - struct auth_option_t *auth_opt=container_of(opt,typeof(*auth_opt),opt); + struct auth_option_t *auth_opt = container_of(opt, typeof(*auth_opt), opt); struct auth_data_t *d; - while(!list_empty(&auth_opt->auth_list)) - { - d=list_entry(auth_opt->auth_list.next,typeof(*d),entry); + while(!list_empty(&auth_opt->auth_list)) { + d = list_entry(auth_opt->auth_list.next, typeof(*d), entry); list_del(&d->entry); - d->h->free(lcp->ppp,d); + d->h->free(lcp->ppp, d); } } static int auth_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) { - struct auth_option_t *auth_opt=container_of(opt,typeof(*auth_opt),opt); - struct lcp_opt16_t *opt16=(struct lcp_opt16_t*)ptr; + struct auth_option_t *auth_opt = container_of(opt, typeof(*auth_opt), opt); + struct lcp_opt16_t *opt16 = (struct lcp_opt16_t*)ptr; struct auth_data_t *d; int n; - if (list_empty(&auth_opt->auth_list)) return 0; + if (list_empty(&auth_opt->auth_list)) + return 0; - if (!auth_opt->auth || auth_opt->auth->state==LCP_OPT_NAK) - { - list_for_each_entry(d,&auth_opt->auth_list,entry) - { - if (d->state==LCP_OPT_NAK || d->state==LCP_OPT_REJ) + if (!auth_opt->auth || auth_opt->auth->state == LCP_OPT_NAK) { + list_for_each_entry(d, &auth_opt->auth_list, entry) { + if (d->state == LCP_OPT_NAK || d->state == LCP_OPT_REJ) continue; - auth_opt->auth=d; + auth_opt->auth = d; break; } } - opt16->hdr.id=CI_AUTH; - opt16->val=htons(auth_opt->auth->proto); - n=auth_opt->auth->h->send_conf_req(lcp->ppp,auth_opt->auth,(uint8_t*)(opt16+1)); - opt16->hdr.len=4+n; + opt16->hdr.id = CI_AUTH; + opt16->val = htons(auth_opt->auth->proto); + n = auth_opt->auth->h->send_conf_req(lcp->ppp, auth_opt->auth, (uint8_t*)(opt16 + 1)); + opt16->hdr.len = 4 + n; - return 4+n; + return 4 + n; } static int auth_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) { - struct auth_option_t *auth_opt=container_of(opt,typeof(*auth_opt),opt); - struct lcp_opt16_t *opt16=(struct lcp_opt16_t*)ptr; + struct auth_option_t *auth_opt = container_of(opt,typeof(*auth_opt),opt); + struct lcp_opt16_t *opt16 = (struct lcp_opt16_t*)ptr; struct auth_data_t *d; int r; @@ -143,112 +140,104 @@ static int auth_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, u return LCP_OPT_ACK; - list_for_each_entry(d,&auth_opt->auth_list,entry) - { - if (d->proto==ntohs(opt16->val)) - { - r=d->h->recv_conf_req(lcp->ppp,d,(uint8_t*)(opt16+1)); - if (r==LCP_OPT_FAIL) + list_for_each_entry(d, &auth_opt->auth_list, entry) { + if (d->proto == ntohs(opt16->val)) { + r = d->h->recv_conf_req(lcp->ppp, d, (uint8_t*)(opt16 + 1)); + if (r == LCP_OPT_FAIL) return LCP_OPT_FAIL; - if (r==LCP_OPT_REJ) + if (r == LCP_OPT_REJ) break; - auth_opt->peer_auth=d; + auth_opt->peer_auth = d; return r; } } - list_for_each_entry(d,&auth_opt->auth_list,entry) - { - if (d->state!=LCP_OPT_NAK) - { - auth_opt->peer_auth=d; + list_for_each_entry(d, &auth_opt->auth_list, entry) { + if (d->state != LCP_OPT_NAK) { + auth_opt->peer_auth = d; return LCP_OPT_NAK; } } - log_ppp_msg("cann't negotiate authentication type\n"); + log_ppp_error("cann't negotiate authentication type\n"); return LCP_OPT_FAIL; } static int auth_recv_conf_ack(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) { - struct auth_option_t *auth_opt=container_of(opt,typeof(*auth_opt),opt); + struct auth_option_t *auth_opt = container_of(opt, typeof(*auth_opt), opt); - auth_opt->peer_auth=NULL; + auth_opt->peer_auth = NULL; return 0; } static int auth_recv_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) { - struct auth_option_t *auth_opt=container_of(opt,typeof(*auth_opt),opt); + struct auth_option_t *auth_opt = container_of(opt, typeof(*auth_opt), opt); struct auth_data_t *d; - if (!auth_opt->auth) - { + if (!auth_opt->auth) { log_ppp_error("auth: unexcepcted configure-nak\n"); return -1; } - auth_opt->auth->state=LCP_OPT_NAK; + auth_opt->auth->state = LCP_OPT_NAK; if (auth_opt->peer_auth) - auth_opt->auth=auth_opt->peer_auth; + auth_opt->auth = auth_opt->peer_auth; - list_for_each_entry(d,&auth_opt->auth_list,entry) - { - if (d->state!=LCP_OPT_NAK) + list_for_each_entry(d, &auth_opt->auth_list, entry) { + if (d->state != LCP_OPT_NAK) return 0; } - log_ppp_msg("cann't negotiate authentication type\n"); + log_ppp_error("cann't negotiate authentication type\n"); return -1; } static int auth_recv_conf_rej(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) { - struct auth_option_t *auth_opt=container_of(opt,typeof(*auth_opt),opt); + struct auth_option_t *auth_opt = container_of(opt, typeof(*auth_opt), opt); struct auth_data_t *d; - if (!auth_opt->auth) - { + if (!auth_opt->auth) { log_ppp_error("auth: unexcepcted configure-reject\n"); return -1; } - auth_opt->auth->state=LCP_OPT_NAK; + + auth_opt->auth->state = LCP_OPT_NAK; if (auth_opt->peer_auth) - auth_opt->auth=auth_opt->peer_auth; + auth_opt->auth = auth_opt->peer_auth; - list_for_each_entry(d,&auth_opt->auth_list,entry) - { - if (d->state!=LCP_OPT_NAK) + list_for_each_entry(d, &auth_opt->auth_list, entry) { + if (d->state != LCP_OPT_NAK) return 0; } - log_ppp_msg("cann't negotiate authentication type\n"); + log_ppp_error("cann't negotiate authentication type\n"); return -1; } -static void auth_print(void (*print)(const char *fmt,...),struct lcp_option_t *opt, uint8_t *ptr) +static void auth_print(void (*print)(const char *fmt,...), struct lcp_option_t *opt, uint8_t *ptr) { - struct auth_option_t *auth_opt=container_of(opt,typeof(*auth_opt),opt); - struct lcp_opt16_t *opt16=(struct lcp_opt16_t*)ptr; + struct auth_option_t *auth_opt = container_of(opt, typeof(*auth_opt), opt); + struct lcp_opt16_t *opt16 = (struct lcp_opt16_t*)ptr; struct auth_data_t *d; - if (ptr) - { - list_for_each_entry(d,&auth_opt->auth_list,entry) - { - if (d->proto==ntohs(opt16->val)) + if (ptr) { + list_for_each_entry(d, &auth_opt->auth_list, entry) { + if (d->proto == ntohs(opt16->val) && (!d->h->check || d->h->check((uint8_t *)(opt16 + 1)))) goto print_d; } - print("",ntohs(opt16->val)); + print("", ntohs(opt16->val)); + return; + } else if (auth_opt->auth) + d = auth_opt->auth; + else return; - } - else if (auth_opt->auth) d=auth_opt->auth; - else return; print_d: - print("",d->h->name); + print("", d->h->name); } static struct ppp_layer_data_t *auth_layer_init(struct ppp_t *ppp) @@ -257,26 +246,26 @@ static struct ppp_layer_data_t *auth_layer_init(struct ppp_t *ppp) log_ppp_debug("auth_layer_init\n"); - memset(ad,0,sizeof(*ad)); + memset(ad, 0, sizeof(*ad)); - ad->ppp=ppp; + ad->ppp = ppp; return &ad->ld; } static int auth_layer_start(struct ppp_layer_data_t *ld) { - struct auth_layer_data_t *ad=container_of(ld,typeof(*ad),ld); + struct auth_layer_data_t *ad = container_of(ld,typeof(*ad),ld); log_ppp_debug("auth_layer_start\n"); ad->started = 1; if (ad->auth_opt.auth) - ad->auth_opt.auth->h->start(ad->ppp,ad->auth_opt.auth); + ad->auth_opt.auth->h->start(ad->ppp, ad->auth_opt.auth); else { log_ppp_debug("auth_layer_started\n"); - ppp_layer_started(ad->ppp,ld); + ppp_layer_started(ad->ppp, ld); } return 0; @@ -284,37 +273,37 @@ static int auth_layer_start(struct ppp_layer_data_t *ld) static void auth_layer_finish(struct ppp_layer_data_t *ld) { - struct auth_layer_data_t *ad=container_of(ld,typeof(*ad),ld); + struct auth_layer_data_t *ad = container_of(ld, typeof(*ad), ld); log_ppp_debug("auth_layer_finish\n"); if (ad->auth_opt.auth) - ad->auth_opt.auth->h->finish(ad->ppp,ad->auth_opt.auth); + ad->auth_opt.auth->h->finish(ad->ppp, ad->auth_opt.auth); ad->started = 0; log_ppp_debug("auth_layer_finished\n"); - ppp_layer_finished(ad->ppp,ld); + ppp_layer_finished(ad->ppp, ld); } static void auth_layer_free(struct ppp_layer_data_t *ld) { - struct auth_layer_data_t *ad=container_of(ld,typeof(*ad),ld); + struct auth_layer_data_t *ad = container_of(ld, typeof(*ad), ld); log_ppp_debug("auth_layer_free\n"); if (ad->started && ad->auth_opt.auth) - ad->auth_opt.auth->h->finish(ad->ppp,ad->auth_opt.auth); + ad->auth_opt.auth->h->finish(ad->ppp, ad->auth_opt.auth); _free(ad); } void __export auth_successed(struct ppp_t *ppp, char *username) { - struct auth_layer_data_t *ad=container_of(ppp_find_layer_data(ppp,&auth_layer),typeof(*ad),ld); + struct auth_layer_data_t *ad = container_of(ppp_find_layer_data(ppp, &auth_layer), typeof(*ad), ld); log_ppp_debug("auth_layer_started\n"); ppp->username = username; - ppp_layer_started(ppp,&ad->ld); + ppp_layer_started(ppp, &ad->ld); triton_event_fire(EV_PPP_AUTHORIZED, ppp); } @@ -325,13 +314,13 @@ void __export auth_failed(struct ppp_t *ppp) int __export ppp_auth_register_handler(struct ppp_auth_handler_t *h) { - list_add_tail(&h->entry,&auth_handlers); + list_add_tail(&h->entry, &auth_handlers); return 0; } static void __init ppp_auth_init() { - ppp_register_layer("auth",&auth_layer); + ppp_register_layer("auth", &auth_layer); lcp_option_register(&auth_opt_hnd); } diff --git a/accel-pptpd/ppp/ppp_auth.h b/accel-pptpd/ppp/ppp_auth.h index f858d33..fbd2017 100644 --- a/accel-pptpd/ppp/ppp_auth.h +++ b/accel-pptpd/ppp/ppp_auth.h @@ -23,6 +23,7 @@ struct ppp_auth_handler_t int (*start)(struct ppp_t*, struct auth_data_t*); int (*finish)(struct ppp_t*, struct auth_data_t*); void (*free)(struct ppp_t*,struct auth_data_t*); + int (*check)(uint8_t *); }; int ppp_auth_register_handler(struct ppp_auth_handler_t*); diff --git a/accel-pptpd/ppp/ppp_ccp.c b/accel-pptpd/ppp/ppp_ccp.c index ca12892..ae9e637 100644 --- a/accel-pptpd/ppp/ppp_ccp.c +++ b/accel-pptpd/ppp/ppp_ccp.c @@ -43,14 +43,12 @@ static void ccp_options_init(struct ppp_ccp_t *ccp) ccp->conf_req_len = sizeof(struct ccp_hdr_t); - list_for_each_entry(h,&option_handlers,entry) - { - lopt=h->init(ccp); - if (lopt) - { - lopt->h=h; - list_add_tail(&lopt->entry,&ccp->options); - ccp->conf_req_len+=lopt->len; + list_for_each_entry(h, &option_handlers, entry) { + lopt = h->init(ccp); + if (lopt) { + lopt->h = h; + list_add_tail(&lopt->entry, &ccp->options); + ccp->conf_req_len += lopt->len; } } } @@ -59,11 +57,10 @@ static void ccp_options_free(struct ppp_ccp_t *ccp) { struct ccp_option_t *lopt; - while(!list_empty(&ccp->options)) - { - lopt=list_entry(ccp->options.next,typeof(*lopt),entry); + while (!list_empty(&ccp->options)) { + lopt = list_entry(ccp->options.next, typeof(*lopt), entry); list_del(&lopt->entry); - lopt->h->free(ccp,lopt); + lopt->h->free(ccp, lopt); } } @@ -89,18 +86,18 @@ static int ccp_set_flags(int fd, int isopen, int isup) static struct ppp_layer_data_t *ccp_layer_init(struct ppp_t *ppp) { - struct ppp_ccp_t *ccp=_malloc(sizeof(*ccp)); - memset(ccp,0,sizeof(*ccp)); + struct ppp_ccp_t *ccp = _malloc(sizeof(*ccp)); + memset(ccp, 0, sizeof(*ccp)); log_ppp_debug("ccp_layer_init\n"); - ccp->ppp=ppp; - ccp->fsm.ppp=ppp; + ccp->ppp = ppp; + ccp->fsm.ppp = ppp; - ccp->hnd.proto=PPP_CCP; - ccp->hnd.recv=ccp_recv; + ccp->hnd.proto = PPP_CCP; + ccp->hnd.recv = ccp_recv; - ppp_register_unit_handler(ppp,&ccp->hnd); + ppp_register_unit_handler(ppp, &ccp->hnd); INIT_LIST_HEAD(&ccp->options); ccp_options_init(ccp); @@ -110,14 +107,14 @@ static struct ppp_layer_data_t *ccp_layer_init(struct ppp_t *ppp) ccp->fsm.proto = PPP_CCP; ppp_fsm_init(&ccp->fsm); - ccp->fsm.layer_up=ccp_layer_up; - ccp->fsm.layer_finished=ccp_layer_down; - ccp->fsm.send_conf_req=send_conf_req; - ccp->fsm.send_conf_ack=send_conf_ack; - ccp->fsm.send_conf_nak=send_conf_nak; - ccp->fsm.send_conf_rej=send_conf_rej; - ccp->fsm.send_term_req=send_term_req; - ccp->fsm.send_term_ack=send_term_ack; + ccp->fsm.layer_up = ccp_layer_up; + ccp->fsm.layer_finished = ccp_layer_down; + ccp->fsm.send_conf_req = send_conf_req; + ccp->fsm.send_conf_ack = send_conf_ack; + ccp->fsm.send_conf_nak = send_conf_nak; + ccp->fsm.send_conf_rej = send_conf_rej; + ccp->fsm.send_term_req = send_term_req; + ccp->fsm.send_term_ack = send_term_ack; INIT_LIST_HEAD(&ccp->ropt_list); @@ -126,7 +123,7 @@ static struct ppp_layer_data_t *ccp_layer_init(struct ppp_t *ppp) int ccp_layer_start(struct ppp_layer_data_t *ld) { - struct ppp_ccp_t *ccp=container_of(ld,typeof(*ccp),ld); + struct ppp_ccp_t *ccp = container_of(ld, typeof(*ccp), ld); log_ppp_debug("ccp_layer_start\n"); @@ -149,23 +146,23 @@ int ccp_layer_start(struct ppp_layer_data_t *ld) void ccp_layer_finish(struct ppp_layer_data_t *ld) { - struct ppp_ccp_t *ccp=container_of(ld,typeof(*ccp),ld); + struct ppp_ccp_t *ccp = container_of(ld, typeof(*ccp), ld); log_ppp_debug("ccp_layer_finish\n"); ccp_set_flags(ccp->ppp->unit_fd, 0, 0); ccp->fsm.fsm_state = FSM_Closed; - ppp_layer_finished(ccp->ppp,&ccp->ld); + ppp_layer_finished(ccp->ppp, &ccp->ld); } void ccp_layer_free(struct ppp_layer_data_t *ld) { - struct ppp_ccp_t *ccp=container_of(ld,typeof(*ccp),ld); + struct ppp_ccp_t *ccp = container_of(ld, typeof(*ccp), ld); log_ppp_debug("ccp_layer_free\n"); - ppp_unregister_handler(ccp->ppp,&ccp->hnd); + ppp_unregister_handler(ccp->ppp, &ccp->hnd); ccp_options_free(ccp); ppp_fsm_free(&ccp->fsm); @@ -174,7 +171,8 @@ void ccp_layer_free(struct ppp_layer_data_t *ld) static void ccp_layer_up(struct ppp_fsm_t *fsm) { - struct ppp_ccp_t *ccp=container_of(fsm,typeof(*ccp),fsm); + struct ppp_ccp_t *ccp = container_of(fsm, typeof(*ccp), fsm); + log_ppp_debug("ccp_layer_started\n"); if (!ccp->started) { @@ -183,31 +181,32 @@ static void ccp_layer_up(struct ppp_fsm_t *fsm) ppp_terminate(ccp->ppp, 0); return; } - ppp_layer_started(ccp->ppp,&ccp->ld); + ppp_layer_started(ccp->ppp, &ccp->ld); } } static void ccp_layer_down(struct ppp_fsm_t *fsm) { - struct ppp_ccp_t *ccp=container_of(fsm,typeof(*ccp),fsm); + struct ppp_ccp_t *ccp = container_of(fsm, typeof(*ccp), fsm); + log_ppp_debug("ccp_layer_finished\n"); + if (!ccp->started) ppp_layer_started(ccp->ppp, &ccp->ld); ccp->started = 0; - ppp_layer_finished(ccp->ppp,&ccp->ld); + ppp_layer_finished(ccp->ppp, &ccp->ld); } static void print_ropt(struct recv_opt_t *ropt) { int i; - uint8_t *ptr=(uint8_t*)ropt->hdr; + uint8_t *ptr = (uint8_t*)ropt->hdr; - log_ppp_debug(" <"); - for(i=0; ilen; i++) - { - log_ppp_debug(" %x",ptr[i]); + log_ppp_info("<"); + for (i = 0; i < ropt->len; i++) { + log_ppp_info(" %x", ptr[i]); } - log_ppp_debug(" >"); + log_ppp_info(" >"); } static int send_conf_req(struct ppp_fsm_t *fsm) @@ -233,24 +232,27 @@ static int send_conf_req(struct ppp_fsm_t *fsm) ptr = (uint8_t*)(ccp_hdr + 1); - log_ppp_debug("send [CCP ConfReq id=%x", ccp_hdr->id); + if (conf_ppp_verbose) + log_ppp_info("send [CCP ConfReq id=%x", ccp_hdr->id); - list_for_each_entry(lopt,&ccp->options,entry) { - n = lopt->h->send_conf_req(ccp,lopt,ptr); + list_for_each_entry(lopt, &ccp->options, entry) { + n = lopt->h->send_conf_req(ccp, lopt, ptr); if (n < 0) return -1; if (n) { - log_ppp_debug(" "); - lopt->h->print(log_ppp_debug, lopt, NULL); - lopt->state = CCP_OPT_ACK; + if (conf_ppp_verbose) { + log_ppp_info(" "); + lopt->h->print(log_ppp_info, lopt, NULL); + } } ptr += n; } - log_ppp_debug("]\n"); + if (conf_ppp_verbose) + log_ppp_info("]\n"); - ccp_hdr->len = htons((ptr-buf)-2); - ppp_unit_send(ccp->ppp, ccp_hdr, ptr-buf); + ccp_hdr->len = htons(ptr - buf - 2); + ppp_unit_send(ccp->ppp, ccp_hdr, ptr - buf); _free(buf); @@ -259,86 +261,94 @@ 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 ppp_ccp_t *ccp = container_of(fsm, typeof(*ccp), fsm); + struct ccp_hdr_t *hdr = (struct ccp_hdr_t*)ccp->ppp->unit_buf; + + hdr->code = CONFACK; - hdr->code=CONFACK; - log_ppp_debug("send [CCP ConfAck id=%x ]\n",ccp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("send [CCP ConfAck id=%x]\n", ccp->fsm.recv_id); ppp_unit_send(ccp->ppp,hdr,ntohs(hdr->len)+2); } 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; - struct ccp_hdr_t *ccp_hdr=(struct ccp_hdr_t*)ptr; + struct ppp_ccp_t *ccp = container_of(fsm, typeof(*ccp), fsm); + 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; - log_ppp_debug("send [CCP ConfNak id=%x",ccp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("send [CCP ConfNak id=%x", ccp->fsm.recv_id); - ccp_hdr->proto=htons(PPP_CCP); - ccp_hdr->code=CONFNAK; - ccp_hdr->id=ccp->fsm.recv_id; - ccp_hdr->len=0; + ccp_hdr->proto = htons(PPP_CCP); + ccp_hdr->code = CONFNAK; + ccp_hdr->id = ccp->fsm.recv_id; + ccp_hdr->len = 0; - ptr+=sizeof(*ccp_hdr); + ptr += sizeof(*ccp_hdr); - list_for_each_entry(ropt,&ccp->ropt_list,entry) - { - if (ropt->state==CCP_OPT_NAK) - { - log_ppp_debug(" "); - ropt->lopt->h->print(log_ppp_debug,ropt->lopt,NULL); - ptr+=ropt->lopt->h->send_conf_nak(ccp,ropt->lopt,ptr); + list_for_each_entry(ropt, &ccp->ropt_list, entry) { + if (ropt->state == CCP_OPT_NAK) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + ropt->lopt->h->print(log_ppp_info, ropt->lopt, NULL); + } + ptr += ropt->lopt->h->send_conf_nak(ccp, ropt->lopt, ptr); } } - log_ppp_debug("]\n"); + if (conf_ppp_verbose) + log_ppp_info("]\n"); - ccp_hdr->len=htons((ptr-buf)-2); - ppp_unit_send(ccp->ppp,ccp_hdr,ptr-buf); + 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 + sizeof(struct ccp_hdr_t)), *ptr=buf; - struct ccp_hdr_t *ccp_hdr=(struct ccp_hdr_t*)ptr; + struct ppp_ccp_t *ccp = container_of(fsm, typeof(*ccp), fsm); + 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; - log_ppp_debug("send [CCP ConfRej id=%x ",ccp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("send [CCP ConfRej id=%x", ccp->fsm.recv_id); - ccp_hdr->proto=htons(PPP_CCP); - ccp_hdr->code=CONFREJ; - ccp_hdr->id=ccp->fsm.recv_id; - ccp_hdr->len=0; + ccp_hdr->proto = htons(PPP_CCP); + ccp_hdr->code = CONFREJ; + ccp_hdr->id = ccp->fsm.recv_id; + ccp_hdr->len = 0; - ptr+=sizeof(*ccp_hdr); + ptr += sizeof(*ccp_hdr); - list_for_each_entry(ropt,&ccp->ropt_list,entry) - { - if (ropt->state==CCP_OPT_REJ) - { - log_ppp_debug(" "); - if (ropt->lopt) ropt->lopt->h->print(log_ppp_debug,ropt->lopt,(uint8_t*)ropt->hdr); - else print_ropt(ropt); - memcpy(ptr,ropt->hdr,ropt->len); - ptr+=ropt->len; + list_for_each_entry(ropt, &ccp->ropt_list, entry) { + if (ropt->state == CCP_OPT_REJ) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + if (ropt->lopt) + ropt->lopt->h->print(log_ppp_info, ropt->lopt, (uint8_t*)ropt->hdr); + else + print_ropt(ropt); + } + memcpy(ptr, ropt->hdr, ropt->len); + ptr += ropt->len; } } - log_ppp_debug("]\n"); + if (conf_ppp_verbose) + log_ppp_info("]\n"); - ccp_hdr->len=htons((ptr-buf)-2); - ppp_unit_send(ccp->ppp,ccp_hdr,ptr-buf); + 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) +static int ccp_recv_conf_req(struct ppp_ccp_t *ccp, uint8_t *data, int size) { struct ccp_opt_hdr_t *hdr; struct recv_opt_t *ropt; @@ -348,30 +358,35 @@ static int ccp_recv_conf_req(struct ppp_ccp_t *ccp,uint8_t *data,int size) ccp->need_req = 0; ccp->ropt_len = size; - while(size>0) - { - hdr=(struct ccp_opt_hdr_t *)data; - - ropt=_malloc(sizeof(*ropt)); - memset(ropt,0,sizeof(*ropt)); - if (hdr->len>size) ropt->len=size; - else ropt->len=hdr->len; - ropt->hdr=hdr; - ropt->state=CCP_OPT_NONE; - list_add_tail(&ropt->entry,&ccp->ropt_list); - - data+=ropt->len; - size-=ropt->len; + while (size > 0) { + hdr = (struct ccp_opt_hdr_t *)data; + + ropt = _malloc(sizeof(*ropt)); + memset(ropt, 0, sizeof(*ropt)); + + if (hdr->len > size) + ropt->len = size; + else + ropt->len = hdr->len; + + ropt->hdr = hdr; + ropt->state = CCP_OPT_NONE; + list_add_tail(&ropt->entry, &ccp->ropt_list); + + data += ropt->len; + size -= ropt->len; } - log_ppp_debug("recv [CCP ConfReq id=%x", ccp->fsm.recv_id); - list_for_each_entry(ropt, &ccp->ropt_list, entry) - { - list_for_each_entry(lopt, &ccp->options, entry) - { + if (conf_ppp_verbose) + log_ppp_info("recv [CCP ConfReq id=%x", ccp->fsm.recv_id); + + list_for_each_entry(ropt, &ccp->ropt_list, entry) { + list_for_each_entry(lopt, &ccp->options, entry) { if (lopt->id == ropt->hdr->id) { - log_ppp_debug(" "); - lopt->h->print(log_ppp_debug, lopt, (uint8_t*)ropt->hdr); + if (conf_ppp_verbose) { + log_ppp_info(" "); + lopt->h->print(log_ppp_info, lopt, (uint8_t*)ropt->hdr); + } r = lopt->h->recv_conf_req(ccp, lopt, (uint8_t*)ropt->hdr); if (ack) { lopt->state = CCP_OPT_REJ; @@ -391,13 +406,17 @@ static int ccp_recv_conf_req(struct ppp_ccp_t *ccp,uint8_t *data,int size) if (ropt->state == CCP_OPT_ACK || ropt->state == CCP_OPT_NAK) ack = 1; else if (!ropt->lopt) { - log_ppp_debug(" "); - print_ropt(ropt); + if (conf_ppp_verbose) { + log_ppp_info(" "); + print_ropt(ropt); + } ropt->state = CCP_OPT_REJ; ret = CCP_OPT_REJ; } } - log_ppp_debug("]\n"); + + if (conf_ppp_verbose) + log_ppp_info("]\n"); /*list_for_each_entry(lopt,&ccp->options,entry) { @@ -416,130 +435,136 @@ static void ccp_free_conf_req(struct ppp_ccp_t *ccp) { struct recv_opt_t *ropt; - while(!list_empty(&ccp->ropt_list)) - { - ropt=list_entry(ccp->ropt_list.next,typeof(*ropt),entry); + while (!list_empty(&ccp->ropt_list)) { + ropt = list_entry(ccp->ropt_list.next, typeof(*ropt), entry); list_del(&ropt->entry); _free(ropt); } } -static int ccp_recv_conf_rej(struct ppp_ccp_t *ccp,uint8_t *data,int size) +static int ccp_recv_conf_rej(struct ppp_ccp_t *ccp, uint8_t *data, int size) { struct ccp_opt_hdr_t *hdr; struct ccp_option_t *lopt; - int res=0; + int res = 0; - log_ppp_debug("recv [CCP ConfRej id=%x",ccp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("recv [CCP ConfRej id=%x", ccp->fsm.recv_id); - if (ccp->fsm.recv_id!=ccp->fsm.id) - { - log_ppp_debug(": id mismatch ]\n"); + if (ccp->fsm.recv_id != ccp->fsm.id) { + if (conf_ppp_verbose) + log_ppp_info(": id mismatch ]\n"); return 0; } - while(size>0) - { - hdr=(struct ccp_opt_hdr_t *)data; + while (size > 0) { + hdr = (struct ccp_opt_hdr_t *)data; - list_for_each_entry(lopt,&ccp->options,entry) - { - if (lopt->id==hdr->id) - { + list_for_each_entry(lopt, &ccp->options, entry) { + if (lopt->id == hdr->id) { if (!lopt->h->recv_conf_rej) - res=-1; - else if (lopt->h->recv_conf_rej(ccp,lopt,data)) - res=-1; + res = -1; + else if (lopt->h->recv_conf_rej(ccp, lopt, data)) + res = -1; break; } } - data+=hdr->len; - size-=hdr->len; + data += hdr->len; + size -= hdr->len; } - log_ppp_debug("]\n"); + + if (conf_ppp_verbose) + log_ppp_info("]\n"); + return res; } -static int ccp_recv_conf_nak(struct ppp_ccp_t *ccp,uint8_t *data,int size) +static int ccp_recv_conf_nak(struct ppp_ccp_t *ccp, uint8_t *data, int size) { struct ccp_opt_hdr_t *hdr; struct ccp_option_t *lopt; - int res=0; + int res = 0; - log_ppp_debug("recv [CCP ConfNak id=%x",ccp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("recv [CCP ConfNak id=%x", ccp->fsm.recv_id); - if (ccp->fsm.recv_id!=ccp->fsm.id) - { - log_ppp_debug(": id mismatch ]\n"); + if (ccp->fsm.recv_id != ccp->fsm.id) { + if (conf_ppp_verbose) + log_ppp_info(": id mismatch ]\n"); return 0; } - while(size>0) - { - hdr=(struct ccp_opt_hdr_t *)data; + while (size > 0) { + hdr = (struct ccp_opt_hdr_t *)data; - list_for_each_entry(lopt,&ccp->options,entry) - { - if (lopt->id==hdr->id) - { - log_ppp_debug(" "); - lopt->h->print(log_ppp_debug,lopt,data); - if (lopt->h->recv_conf_nak(ccp,lopt,data)) - res=-1; + list_for_each_entry(lopt, &ccp->options, entry) { + if (lopt->id == hdr->id) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + lopt->h->print(log_ppp_info, lopt, data); + } + if (lopt->h->recv_conf_nak(ccp, lopt, data)) + res = -1; break; } } - data+=hdr->len; - size-=hdr->len; + data += hdr->len; + size -= hdr->len; } - log_ppp_debug("]\n"); + + if (conf_ppp_verbose) + log_ppp_info("]\n"); + return res; } -static int ccp_recv_conf_ack(struct ppp_ccp_t *ccp,uint8_t *data,int size) +static int ccp_recv_conf_ack(struct ppp_ccp_t *ccp, uint8_t *data, int size) { struct ccp_opt_hdr_t *hdr; struct ccp_option_t *lopt; - int res=0; + int res = 0; - log_ppp_debug("recv [CCP ConfAck id=%x",ccp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("recv [CCP ConfAck id=%x", ccp->fsm.recv_id); - if (ccp->fsm.recv_id!=ccp->fsm.id) - { - log_ppp_debug(": id mismatch ]\n"); + if (ccp->fsm.recv_id != ccp->fsm.id) { + if (conf_ppp_verbose) + log_ppp_info(": id mismatch ]\n"); return 0; } - while(size>0) - { - hdr=(struct ccp_opt_hdr_t *)data; + while (size > 0) { + hdr = (struct ccp_opt_hdr_t *)data; - list_for_each_entry(lopt,&ccp->options,entry) - { - if (lopt->id==hdr->id) - { - log_ppp_debug(" "); - lopt->h->print(log_ppp_debug,lopt,data); + list_for_each_entry(lopt, &ccp->options, entry) { + if (lopt->id == hdr->id) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + lopt->h->print(log_ppp_info,lopt,data); + } if (!lopt->h->recv_conf_ack) break; - if (lopt->h->recv_conf_ack(ccp,lopt,data)) - res=-1; + if (lopt->h->recv_conf_ack(ccp, lopt, data)) + res = -1; break; } } - data+=hdr->len; - size-=hdr->len; + data += hdr->len; + size -= hdr->len; } - log_ppp_debug("]\n"); + + if (conf_ppp_verbose) + log_ppp_info("]\n"); + return res; } static void send_term_req(struct ppp_fsm_t *fsm) { - struct ppp_ccp_t *ccp=container_of(fsm,typeof(*ccp),fsm); + struct ppp_ccp_t *ccp = container_of(fsm, typeof(*ccp), fsm); struct ccp_hdr_t hdr = { .proto = htons(PPP_CCP), .code = TERMREQ, @@ -547,14 +572,15 @@ static void send_term_req(struct ppp_fsm_t *fsm) .len = htons(4), }; - log_ppp_debug("send [CCP TermReq id=%i \"\"]\n",hdr.id); + if (conf_ppp_verbose) + log_ppp_info("send [CCP TermReq id=%i]\n", hdr.id); ppp_chan_send(ccp->ppp, &hdr, 6); } static void send_term_ack(struct ppp_fsm_t *fsm) { - struct ppp_ccp_t *ccp=container_of(fsm,typeof(*ccp),fsm); + struct ppp_ccp_t *ccp = container_of(fsm, typeof(*ccp), fsm); struct ccp_hdr_t hdr = { .proto = htons(PPP_CCP), .code = TERMACK, @@ -562,7 +588,8 @@ static void send_term_ack(struct ppp_fsm_t *fsm) .len = htons(4), }; - log_ppp_debug("send [CCP TermAck id=%i \"\"]\n", hdr.id); + if (conf_ppp_verbose) + log_ppp_info("send [CCP TermAck id=%i]\n", hdr.id); ppp_chan_send(ccp->ppp, &hdr, 6); } @@ -570,37 +597,32 @@ static void send_term_ack(struct ppp_fsm_t *fsm) static void ccp_recv(struct ppp_handler_t*h) { struct ccp_hdr_t *hdr; - struct ppp_ccp_t *ccp=container_of(h,typeof(*ccp),hnd); + struct ppp_ccp_t *ccp = container_of(h, typeof(*ccp), hnd); int r; - char *term_msg; - if (ccp->fsm.fsm_state==FSM_Initial || ccp->fsm.fsm_state==FSM_Closed) - { - log_ppp_warn("CCP: discaring packet\n"); + if (ccp->fsm.fsm_state == FSM_Initial || ccp->fsm.fsm_state == FSM_Closed) { + if (conf_ppp_verbose) + log_ppp_warn("CCP: discaring packet\n"); lcp_send_proto_rej(ccp->ppp, htons(PPP_CCP)); return; } - if (ccp->ppp->unit_buf_sizeppp->unit_buf_size < PPP_HEADERLEN + 2) { log_ppp_warn("CCP: short packet received\n"); return; } - hdr=(struct ccp_hdr_t *)ccp->ppp->unit_buf; - if (ntohs(hdr->len)ppp->unit_buf; + if (ntohs(hdr->len) < PPP_HEADERLEN) { log_ppp_warn("CCP: short packet received\n"); return; } - ccp->fsm.recv_id=hdr->id; - switch(hdr->code) - { + ccp->fsm.recv_id = hdr->id; + switch(hdr->code) { case CONFREQ: - r=ccp_recv_conf_req(ccp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN); - switch(r) - { + r = ccp_recv_conf_req(ccp, (uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN); + switch(r) { case CCP_OPT_ACK: ppp_fsm_recv_conf_req_ack(&ccp->fsm); break; @@ -621,7 +643,7 @@ static void ccp_recv(struct ppp_handler_t*h) ppp_terminate(ccp->ppp, 0); break; case CONFACK: - if (ccp_recv_conf_ack(ccp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN)) + if (ccp_recv_conf_ack(ccp, (uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN)) ppp_terminate(ccp->ppp, 0); else { ppp_fsm_recv_conf_ack(&ccp->fsm); @@ -630,30 +652,29 @@ static void ccp_recv(struct ppp_handler_t*h) } break; case CONFNAK: - ccp_recv_conf_nak(ccp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN); + ccp_recv_conf_nak(ccp, (uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN); ppp_fsm_recv_conf_rej(&ccp->fsm); break; case CONFREJ: - if (ccp_recv_conf_rej(ccp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN)) + if (ccp_recv_conf_rej(ccp, (uint8_t*)(hdr + 1),ntohs(hdr->len) - PPP_HDRLEN)) ppp_terminate(ccp->ppp, 0); else ppp_fsm_recv_conf_rej(&ccp->fsm); break; case TERMREQ: - term_msg=_strndup((char*)(hdr+1),ntohs(hdr->len) - 4); - log_ppp_debug("recv [CCP TermReq id=%x \"%s\"]\n",hdr->id,term_msg); - _free(term_msg); + if (conf_ppp_verbose) + log_ppp_info("recv [CCP TermReq id=%x]\n", hdr->id); ppp_fsm_recv_term_req(&ccp->fsm); ppp_fsm_close(&ccp->fsm); break; case TERMACK: - term_msg=_strndup((char*)(hdr+1),ntohs(hdr->len) - 4); - log_ppp_debug("recv [CCP TermAck id=%x \"%s\"]\n",hdr->id,term_msg); - _free(term_msg); + if (conf_ppp_verbose) + log_ppp_info("recv [CCP TermAck id=%x]\n", hdr->id); ppp_fsm_recv_term_ack(&ccp->fsm); break; case CODEREJ: - log_ppp_debug("recv [CCP CodeRej id=%x]\n",hdr->id); + if (conf_ppp_verbose) + log_ppp_info("recv [CCP CodeRej id=%x]\n", hdr->id); ppp_fsm_recv_code_rej_bad(&ccp->fsm); break; default: @@ -690,13 +711,14 @@ struct ccp_option_t *ccp_find_option(struct ppp_t *ppp, struct ccp_option_handle static struct ppp_layer_t ccp_layer= { - .init=ccp_layer_init, - .start=ccp_layer_start, - .finish=ccp_layer_finish, - .free=ccp_layer_free, + .init = ccp_layer_init, + .start = ccp_layer_start, + .finish = ccp_layer_finish, + .free = ccp_layer_free, }; static void __init ccp_init(void) { - ppp_register_layer("ccp",&ccp_layer); + ppp_register_layer("ccp", &ccp_layer); } + diff --git a/accel-pptpd/ppp/ppp_ipcp.c b/accel-pptpd/ppp/ppp_ipcp.c index f8d0a3f..c46b1bd 100644 --- a/accel-pptpd/ppp/ppp_ipcp.c +++ b/accel-pptpd/ppp/ppp_ipcp.c @@ -41,14 +41,12 @@ static void ipcp_options_init(struct ppp_ipcp_t *ipcp) ipcp->conf_req_len = sizeof(struct ipcp_hdr_t); - list_for_each_entry(h,&option_handlers,entry) - { - lopt=h->init(ipcp); - if (lopt) - { - lopt->h=h; - list_add_tail(&lopt->entry,&ipcp->options); - ipcp->conf_req_len+=lopt->len; + list_for_each_entry(h,&option_handlers,entry) { + lopt = h->init(ipcp); + if (lopt) { + lopt->h = h; + list_add_tail(&lopt->entry, &ipcp->options); + ipcp->conf_req_len += lopt->len; } } } @@ -57,40 +55,39 @@ static void ipcp_options_free(struct ppp_ipcp_t *ipcp) { struct ipcp_option_t *lopt; - while(!list_empty(&ipcp->options)) - { - lopt=list_entry(ipcp->options.next,typeof(*lopt),entry); + while (!list_empty(&ipcp->options)) { + lopt = list_entry(ipcp->options.next, typeof(*lopt), entry); list_del(&lopt->entry); - lopt->h->free(ipcp,lopt); + lopt->h->free(ipcp, lopt); } } static struct ppp_layer_data_t *ipcp_layer_init(struct ppp_t *ppp) { - struct ppp_ipcp_t *ipcp=_malloc(sizeof(*ipcp)); - memset(ipcp,0,sizeof(*ipcp)); + struct ppp_ipcp_t *ipcp = _malloc(sizeof(*ipcp)); + memset(ipcp, 0, sizeof(*ipcp)); log_ppp_debug("ipcp_layer_init\n"); - ipcp->ppp=ppp; - ipcp->fsm.ppp=ppp; + ipcp->ppp = ppp; + ipcp->fsm.ppp = ppp; - ipcp->hnd.proto=PPP_IPCP; - ipcp->hnd.recv=ipcp_recv; + ipcp->hnd.proto = PPP_IPCP; + ipcp->hnd.recv = ipcp_recv; - ppp_register_unit_handler(ppp,&ipcp->hnd); + ppp_register_unit_handler(ppp, &ipcp->hnd); ipcp->fsm.proto = PPP_IPCP; ppp_fsm_init(&ipcp->fsm); - ipcp->fsm.layer_up=ipcp_layer_up; - ipcp->fsm.layer_finished=ipcp_layer_down; - ipcp->fsm.send_conf_req=send_conf_req; - ipcp->fsm.send_conf_ack=send_conf_ack; - ipcp->fsm.send_conf_nak=send_conf_nak; - ipcp->fsm.send_conf_rej=send_conf_rej; - ipcp->fsm.send_term_req=send_term_req; - ipcp->fsm.send_term_ack=send_term_ack; + ipcp->fsm.layer_up = ipcp_layer_up; + ipcp->fsm.layer_finished = ipcp_layer_down; + ipcp->fsm.send_conf_req = send_conf_req; + ipcp->fsm.send_conf_ack = send_conf_ack; + ipcp->fsm.send_conf_nak = send_conf_nak; + ipcp->fsm.send_conf_rej = send_conf_rej; + ipcp->fsm.send_term_req = send_term_req; + ipcp->fsm.send_term_ack = send_term_ack; INIT_LIST_HEAD(&ipcp->options); INIT_LIST_HEAD(&ipcp->ropt_list); @@ -100,7 +97,7 @@ static struct ppp_layer_data_t *ipcp_layer_init(struct ppp_t *ppp) int ipcp_layer_start(struct ppp_layer_data_t *ld) { - struct ppp_ipcp_t *ipcp=container_of(ld,typeof(*ipcp),ld); + struct ppp_ipcp_t *ipcp = container_of(ld, typeof(*ipcp), ld); log_ppp_debug("ipcp_layer_start\n"); @@ -114,21 +111,21 @@ int ipcp_layer_start(struct ppp_layer_data_t *ld) void ipcp_layer_finish(struct ppp_layer_data_t *ld) { - struct ppp_ipcp_t *ipcp=container_of(ld,typeof(*ipcp),ld); + struct ppp_ipcp_t *ipcp = container_of(ld, typeof(*ipcp), ld); log_ppp_debug("ipcp_layer_finish\n"); ipcp->fsm.fsm_state = FSM_Closed; - ppp_layer_finished(ipcp->ppp,&ipcp->ld); + ppp_layer_finished(ipcp->ppp, &ipcp->ld); } void ipcp_layer_free(struct ppp_layer_data_t *ld) { - struct ppp_ipcp_t *ipcp=container_of(ld,typeof(*ipcp),ld); + struct ppp_ipcp_t *ipcp = container_of(ld, typeof(*ipcp), ld); log_ppp_debug("ipcp_layer_free\n"); - ppp_unregister_handler(ipcp->ppp,&ipcp->hnd); + ppp_unregister_handler(ipcp->ppp, &ipcp->hnd); ipcp_options_free(ipcp); ppp_fsm_free(&ipcp->fsm); @@ -137,19 +134,23 @@ void ipcp_layer_free(struct ppp_layer_data_t *ld) static void ipcp_layer_up(struct ppp_fsm_t *fsm) { - struct ppp_ipcp_t *ipcp=container_of(fsm,typeof(*ipcp),fsm); + struct ppp_ipcp_t *ipcp = container_of(fsm, typeof(*ipcp), fsm); + log_ppp_debug("ipcp_layer_started\n"); + if (!ipcp->started) { ipcp->started = 1; - ppp_layer_started(ipcp->ppp,&ipcp->ld); + ppp_layer_started(ipcp->ppp, &ipcp->ld); } } static void ipcp_layer_down(struct ppp_fsm_t *fsm) { - struct ppp_ipcp_t *ipcp=container_of(fsm,typeof(*ipcp),fsm); + struct ppp_ipcp_t *ipcp = container_of(fsm, typeof(*ipcp), fsm); + log_ppp_debug("ipcp_layer_finished\n"); - ppp_layer_finished(ipcp->ppp,&ipcp->ld); + + ppp_layer_finished(ipcp->ppp, &ipcp->ld); if (ipcp->started) ipcp->started = 0; else @@ -159,56 +160,54 @@ static void ipcp_layer_down(struct ppp_fsm_t *fsm) static void print_ropt(struct recv_opt_t *ropt) { int i; - uint8_t *ptr=(uint8_t*)ropt->hdr; + uint8_t *ptr = (uint8_t*)ropt->hdr; - log_ppp_debug(" <"); - for(i=0; ilen; i++) - { - log_ppp_debug(" %x",ptr[i]); + log_ppp_info("<"); + for (i = 0; i < ropt->len; i++) { + log_ppp_info(" %x", ptr[i]); } - log_ppp_debug(" >"); + log_ppp_info(" >"); } 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; - struct ipcp_hdr_t *ipcp_hdr=(struct ipcp_hdr_t*)ptr; + struct ppp_ipcp_t *ipcp = container_of(fsm, typeof(*ipcp), fsm); + 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; - ipcp_hdr->proto=htons(PPP_IPCP); - ipcp_hdr->code=CONFREQ; - ipcp_hdr->id=++ipcp->fsm.id; - ipcp_hdr->len=0; + ipcp_hdr->proto = htons(PPP_IPCP); + ipcp_hdr->code = CONFREQ; + ipcp_hdr->id = ++ipcp->fsm.id; + ipcp_hdr->len = 0; - ptr+=sizeof(*ipcp_hdr); + ptr += sizeof(*ipcp_hdr); - list_for_each_entry(lopt,&ipcp->options,entry) - { + list_for_each_entry(lopt, &ipcp->options, entry) { n = lopt->h->send_conf_req(ipcp, lopt, ptr); if (n < 0) return -1; if (n) { - ptr+=n; + ptr += n; lopt->print = 1; } else lopt->print = 0; } if (conf_ppp_verbose) { - log_ppp_debug("send [IPCP ConfReq id=%x", ipcp_hdr->id); - list_for_each_entry(lopt,&ipcp->options,entry){ + log_ppp_info("send [IPCP ConfReq id=%x", ipcp_hdr->id); + list_for_each_entry(lopt,&ipcp->options,entry) { if (lopt->print) { - log_ppp_debug(" "); - lopt->h->print(log_ppp_debug,lopt,NULL); + log_ppp_info(" "); + lopt->h->print(log_ppp_debug, lopt, NULL); } } - log_ppp_debug("]\n"); + log_ppp_info("]\n"); } - ipcp_hdr->len=htons((ptr-buf)-2); - ppp_unit_send(ipcp->ppp,ipcp_hdr,ptr-buf); + ipcp_hdr->len = htons(ptr - buf - 2); + ppp_unit_send(ipcp->ppp, ipcp_hdr, ptr - buf); _free(buf); @@ -217,139 +216,155 @@ 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 ppp_ipcp_t *ipcp = container_of(fsm, typeof(*ipcp), fsm); + struct ipcp_hdr_t *hdr = (struct ipcp_hdr_t*)ipcp->ppp->unit_buf; - hdr->code=CONFACK; - log_ppp_debug("send [IPCP ConfAck id=%x ]\n",ipcp->fsm.recv_id); + hdr->code = CONFACK; - ppp_unit_send(ipcp->ppp,hdr,ntohs(hdr->len)+2); + if (conf_ppp_verbose) + log_ppp_info("send [IPCP ConfAck id=%x]\n", ipcp->fsm.recv_id); + + ppp_unit_send(ipcp->ppp, hdr, ntohs(hdr->len) + 2); } 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; - struct ipcp_hdr_t *ipcp_hdr=(struct ipcp_hdr_t*)ptr; + struct ppp_ipcp_t *ipcp = container_of(fsm, typeof(*ipcp), fsm); + 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; - log_ppp_debug("send [IPCP ConfNak id=%x",ipcp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("send [IPCP ConfNak id=%x", ipcp->fsm.recv_id); - ipcp_hdr->proto=htons(PPP_IPCP); - ipcp_hdr->code=CONFNAK; - ipcp_hdr->id=ipcp->fsm.recv_id; - ipcp_hdr->len=0; + ipcp_hdr->proto = htons(PPP_IPCP); + ipcp_hdr->code = CONFNAK; + ipcp_hdr->id = ipcp->fsm.recv_id; + ipcp_hdr->len = 0; - ptr+=sizeof(*ipcp_hdr); + ptr += sizeof(*ipcp_hdr); - list_for_each_entry(ropt,&ipcp->ropt_list,entry) - { - if (ropt->state==IPCP_OPT_NAK) - { - log_ppp_debug(" "); - ropt->lopt->h->print(log_ppp_debug,ropt->lopt,NULL); - ptr+=ropt->lopt->h->send_conf_nak(ipcp,ropt->lopt,ptr); + list_for_each_entry(ropt, &ipcp->ropt_list, entry) { + if (ropt->state == IPCP_OPT_NAK) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + ropt->lopt->h->print(log_ppp_info, ropt->lopt, NULL); + } + ptr += ropt->lopt->h->send_conf_nak(ipcp, ropt->lopt, ptr); } } - log_ppp_debug("]\n"); + if (conf_ppp_verbose) + log_ppp_info("]\n"); - ipcp_hdr->len=htons((ptr-buf)-2); - ppp_unit_send(ipcp->ppp,ipcp_hdr,ptr-buf); + 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 + sizeof(struct ipcp_hdr_t)), *ptr=buf; - struct ipcp_hdr_t *ipcp_hdr=(struct ipcp_hdr_t*)ptr; + struct ppp_ipcp_t *ipcp = container_of(fsm, typeof(*ipcp), fsm); + 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; - log_ppp_debug("send [IPCP ConfRej id=%x ",ipcp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("send [IPCP ConfRej id=%x", ipcp->fsm.recv_id); - ipcp_hdr->proto=htons(PPP_IPCP); - ipcp_hdr->code=CONFREJ; - ipcp_hdr->id=ipcp->fsm.recv_id; - ipcp_hdr->len=0; + ipcp_hdr->proto = htons(PPP_IPCP); + ipcp_hdr->code = CONFREJ; + ipcp_hdr->id = ipcp->fsm.recv_id; + ipcp_hdr->len = 0; - ptr+=sizeof(*ipcp_hdr); + ptr += sizeof(*ipcp_hdr); - list_for_each_entry(ropt,&ipcp->ropt_list,entry) - { - if (ropt->state==IPCP_OPT_REJ) - { - log_ppp_debug(" "); - if (ropt->lopt) ropt->lopt->h->print(log_ppp_debug,ropt->lopt,(uint8_t*)ropt->hdr); - else print_ropt(ropt); - memcpy(ptr,ropt->hdr,ropt->len); - ptr+=ropt->len; + list_for_each_entry(ropt, &ipcp->ropt_list, entry) { + if (ropt->state == IPCP_OPT_REJ) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + if (ropt->lopt) + ropt->lopt->h->print(log_ppp_info, ropt->lopt, (uint8_t*)ropt->hdr); + else + print_ropt(ropt); + } + memcpy(ptr, ropt->hdr, ropt->len); + ptr += ropt->len; } } - log_ppp_debug("]\n"); + if (conf_ppp_verbose) + log_ppp_info("]\n"); - ipcp_hdr->len=htons((ptr-buf)-2); - ppp_unit_send(ipcp->ppp,ipcp_hdr,ptr-buf); + 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) +static int ipcp_recv_conf_req(struct ppp_ipcp_t *ipcp, uint8_t *data, int size) { struct ipcp_opt_hdr_t *hdr; struct recv_opt_t *ropt; struct ipcp_option_t *lopt; - int r,ret=1; + int r,ret = 1; - ipcp->ropt_len=size; + ipcp->ropt_len = size; - while(size>0) - { - hdr=(struct ipcp_opt_hdr_t *)data; - - ropt=_malloc(sizeof(*ropt)); - memset(ropt,0,sizeof(*ropt)); - if (hdr->len>size) ropt->len=size; - else ropt->len=hdr->len; - ropt->hdr=hdr; - ropt->state=IPCP_OPT_NONE; - list_add_tail(&ropt->entry,&ipcp->ropt_list); - - data+=ropt->len; - size-=ropt->len; + while (size > 0) { + hdr = (struct ipcp_opt_hdr_t *)data; + + ropt = _malloc(sizeof(*ropt)); + memset(ropt, 0, sizeof(*ropt)); + + if (hdr->len > size) + ropt->len = size; + else + ropt->len = hdr->len; + ropt->hdr = hdr; + ropt->state = IPCP_OPT_NONE; + list_add_tail(&ropt->entry, &ipcp->ropt_list); + + data += ropt->len; + size -= ropt->len; } - list_for_each_entry(lopt,&ipcp->options,entry) + list_for_each_entry(lopt, &ipcp->options, entry) lopt->state=IPCP_OPT_NONE; - log_ppp_debug("recv [IPCP ConfReq id=%x",ipcp->fsm.recv_id); - list_for_each_entry(ropt,&ipcp->ropt_list,entry) - { - list_for_each_entry(lopt,&ipcp->options,entry) - { - if (lopt->id==ropt->hdr->id) - { - log_ppp_debug(" "); - lopt->h->print(log_ppp_debug,lopt,(uint8_t*)ropt->hdr); - r=lopt->h->recv_conf_req(ipcp,lopt,(uint8_t*)ropt->hdr); - lopt->state=r; - ropt->state=r; - ropt->lopt=lopt; - if (rfsm.recv_id); + + list_for_each_entry(ropt, &ipcp->ropt_list, entry) { + list_for_each_entry(lopt, &ipcp->options, entry) { + if (lopt->id == ropt->hdr->id) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + lopt->h->print(log_ppp_info, lopt, (uint8_t*)ropt->hdr); + } + r = lopt->h->recv_conf_req(ipcp, lopt, (uint8_t*)ropt->hdr); + lopt->state = r; + ropt->state = r; + ropt->lopt = lopt; + if (r < ret) + ret = r; break; } } if (!ropt->lopt) { - log_ppp_debug(" "); - print_ropt(ropt); - ropt->state=IPCP_OPT_REJ; - ret=IPCP_OPT_REJ; + if (conf_ppp_verbose) { + log_ppp_debug(" "); + print_ropt(ropt); + } + ropt->state = IPCP_OPT_REJ; + ret = IPCP_OPT_REJ; } } - log_ppp_debug("]\n"); + + if (conf_ppp_verbose) + log_ppp_info("]\n"); /*list_for_each_entry(lopt,&ipcp->options,entry) { @@ -368,130 +383,136 @@ static void ipcp_free_conf_req(struct ppp_ipcp_t *ipcp) { struct recv_opt_t *ropt; - while(!list_empty(&ipcp->ropt_list)) - { - ropt=list_entry(ipcp->ropt_list.next,typeof(*ropt),entry); + while (!list_empty(&ipcp->ropt_list)) { + ropt = list_entry(ipcp->ropt_list.next, typeof(*ropt), entry); list_del(&ropt->entry); _free(ropt); } } -static int ipcp_recv_conf_rej(struct ppp_ipcp_t *ipcp,uint8_t *data,int size) +static int ipcp_recv_conf_rej(struct ppp_ipcp_t *ipcp, uint8_t *data, int size) { struct ipcp_opt_hdr_t *hdr; struct ipcp_option_t *lopt; - int res=0; + int res = 0; - log_ppp_debug("recv [IPCP ConfRej id=%x",ipcp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("recv [IPCP ConfRej id=%x", ipcp->fsm.recv_id); - if (ipcp->fsm.recv_id!=ipcp->fsm.id) - { - log_ppp_debug(": id mismatch ]\n"); + if (ipcp->fsm.recv_id != ipcp->fsm.id) { + if (conf_ppp_verbose) + log_ppp_info(": id mismatch ]\n"); return 0; } - while(size>0) - { - hdr=(struct ipcp_opt_hdr_t *)data; + while (size > 0) { + hdr = (struct ipcp_opt_hdr_t *)data; - list_for_each_entry(lopt,&ipcp->options,entry) - { - if (lopt->id==hdr->id) - { + list_for_each_entry(lopt, &ipcp->options, entry) { + if (lopt->id == hdr->id) { if (!lopt->h->recv_conf_rej) - res=-1; - else if (lopt->h->recv_conf_rej(ipcp,lopt,data)) - res=-1; + res = -1; + else if (lopt->h->recv_conf_rej(ipcp, lopt, data)) + res = -1; break; } } - data+=hdr->len; - size-=hdr->len; + data += hdr->len; + size -= hdr->len; } - log_ppp_debug("]\n"); + + if (conf_ppp_verbose) + log_ppp_info("]\n"); + return res; } -static int ipcp_recv_conf_nak(struct ppp_ipcp_t *ipcp,uint8_t *data,int size) +static int ipcp_recv_conf_nak(struct ppp_ipcp_t *ipcp, uint8_t *data, int size) { struct ipcp_opt_hdr_t *hdr; struct ipcp_option_t *lopt; - int res=0; + int res = 0; - log_ppp_debug("recv [IPCP ConfNak id=%x",ipcp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("recv [IPCP ConfNak id=%x", ipcp->fsm.recv_id); - if (ipcp->fsm.recv_id!=ipcp->fsm.id) - { - log_ppp_debug(": id mismatch ]\n"); + if (ipcp->fsm.recv_id != ipcp->fsm.id) { + if (conf_ppp_verbose) + log_ppp_info(": id mismatch ]\n"); return 0; } - while(size>0) - { - hdr=(struct ipcp_opt_hdr_t *)data; + while (size > 0) { + hdr = (struct ipcp_opt_hdr_t *)data; - list_for_each_entry(lopt,&ipcp->options,entry) - { - if (lopt->id==hdr->id) - { - log_ppp_debug(" "); - lopt->h->print(log_ppp_debug,lopt,data); - if (lopt->h->recv_conf_nak(ipcp,lopt,data)) - res=-1; + list_for_each_entry(lopt, &ipcp->options, entry) { + if (lopt->id == hdr->id) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + lopt->h->print(log_ppp_info,lopt,data); + } + if (lopt->h->recv_conf_nak(ipcp, lopt, data)) + res =- 1; break; } } - data+=hdr->len; - size-=hdr->len; + data += hdr->len; + size -= hdr->len; } - log_ppp_debug("]\n"); + + if (conf_ppp_verbose) + log_ppp_info("]\n"); + return res; } -static int ipcp_recv_conf_ack(struct ppp_ipcp_t *ipcp,uint8_t *data,int size) +static int ipcp_recv_conf_ack(struct ppp_ipcp_t *ipcp, uint8_t *data, int size) { struct ipcp_opt_hdr_t *hdr; struct ipcp_option_t *lopt; - int res=0; + int res = 0; - log_ppp_debug("recv [IPCP ConfAck id=%x",ipcp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("recv [IPCP ConfAck id=%x", ipcp->fsm.recv_id); - if (ipcp->fsm.recv_id!=ipcp->fsm.id) - { - log_ppp_debug(": id mismatch ]\n"); + if (ipcp->fsm.recv_id != ipcp->fsm.id) { + if (conf_ppp_verbose) + log_ppp_info(": id mismatch ]\n"); return 0; } - while(size>0) - { - hdr=(struct ipcp_opt_hdr_t *)data; + while (size > 0) { + hdr = (struct ipcp_opt_hdr_t *)data; - list_for_each_entry(lopt,&ipcp->options,entry) - { - if (lopt->id==hdr->id) - { - log_ppp_debug(" "); - lopt->h->print(log_ppp_debug,lopt,data); + list_for_each_entry(lopt, &ipcp->options, entry) { + if (lopt->id == hdr->id) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + lopt->h->print(log_ppp_info, lopt, data); + } if (!lopt->h->recv_conf_ack) break; - if (lopt->h->recv_conf_ack(ipcp,lopt,data)) - res=-1; + if (lopt->h->recv_conf_ack(ipcp, lopt, data)) + res = -1; break; } } - data+=hdr->len; - size-=hdr->len; + data += hdr->len; + size -= hdr->len; } - log_ppp_debug("]\n"); + + if (conf_ppp_verbose) + log_ppp_info("]\n"); + return res; } static void send_term_req(struct ppp_fsm_t *fsm) { - struct ppp_ipcp_t *ipcp=container_of(fsm,typeof(*ipcp),fsm); + struct ppp_ipcp_t *ipcp = container_of(fsm, typeof(*ipcp), fsm); struct ipcp_hdr_t hdr = { .proto = htons(PPP_IPCP), .code = TERMREQ, @@ -499,14 +520,15 @@ static void send_term_req(struct ppp_fsm_t *fsm) .len = htons(4), }; - log_ppp_debug("send [IPCP TermReq id=%i \"\"]\n",hdr.id); + if (conf_ppp_verbose) + log_ppp_info("send [IPCP TermReq id=%i]\n", hdr.id); ppp_unit_send(ipcp->ppp, &hdr, 6); } static void send_term_ack(struct ppp_fsm_t *fsm) { - struct ppp_ipcp_t *ipcp=container_of(fsm,typeof(*ipcp),fsm); + struct ppp_ipcp_t *ipcp = container_of(fsm, typeof(*ipcp), fsm); struct ipcp_hdr_t hdr = { .proto = htons(PPP_IPCP), .code = TERMACK, @@ -514,7 +536,8 @@ static void send_term_ack(struct ppp_fsm_t *fsm) .len = htons(4), }; - log_ppp_debug("send [IPCP TermAck id=%i \"\"]\n", hdr.id); + if (conf_ppp_verbose) + log_ppp_info("send [IPCP TermAck id=%i]\n", hdr.id); ppp_unit_send(ipcp->ppp, &hdr, 6); } @@ -522,36 +545,31 @@ static void send_term_ack(struct ppp_fsm_t *fsm) static void ipcp_recv(struct ppp_handler_t*h) { struct ipcp_hdr_t *hdr; - struct ppp_ipcp_t *ipcp=container_of(h,typeof(*ipcp),hnd); + struct ppp_ipcp_t *ipcp = container_of(h, typeof(*ipcp), hnd); int r; - char *term_msg; - if (ipcp->fsm.fsm_state==FSM_Initial || ipcp->fsm.fsm_state==FSM_Closed) - { - log_ppp_warn("IPCP: discaring packet\n"); + if (ipcp->fsm.fsm_state == FSM_Initial || ipcp->fsm.fsm_state == FSM_Closed) { + if (conf_ppp_verbose) + log_ppp_warn("IPCP: discaring packet\n"); return; } - if (ipcp->ppp->unit_buf_sizeppp->unit_buf_size < PPP_HEADERLEN + 2) { log_ppp_warn("IPCP: short packet received\n"); return; } - hdr=(struct ipcp_hdr_t *)ipcp->ppp->unit_buf; - if (ntohs(hdr->len)ppp->unit_buf; + if (ntohs(hdr->len) < PPP_HEADERLEN) { log_ppp_warn("IPCP: short packet received\n"); return; } - ipcp->fsm.recv_id=hdr->id; - switch(hdr->code) - { + ipcp->fsm.recv_id = hdr->id; + switch(hdr->code) { case CONFREQ: - r=ipcp_recv_conf_req(ipcp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN); - switch(r) - { + r = ipcp_recv_conf_req(ipcp,(uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN); + switch(r) { case IPCP_OPT_ACK: ppp_fsm_recv_conf_req_ack(&ipcp->fsm); break; @@ -563,41 +581,40 @@ static void ipcp_recv(struct ppp_handler_t*h) break; } ipcp_free_conf_req(ipcp); - if (r==IPCP_OPT_FAIL) + if (r == IPCP_OPT_FAIL) ppp_terminate(ipcp->ppp, 0); break; case CONFACK: - if (ipcp_recv_conf_ack(ipcp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN)) + if (ipcp_recv_conf_ack(ipcp,(uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN)) ppp_terminate(ipcp->ppp, 0); else ppp_fsm_recv_conf_ack(&ipcp->fsm); break; case CONFNAK: - ipcp_recv_conf_nak(ipcp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN); + ipcp_recv_conf_nak(ipcp,(uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN); ppp_fsm_recv_conf_rej(&ipcp->fsm); break; case CONFREJ: - if (ipcp_recv_conf_rej(ipcp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN)) + if (ipcp_recv_conf_rej(ipcp, (uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN)) ppp_terminate(ipcp->ppp, 0); else ppp_fsm_recv_conf_rej(&ipcp->fsm); break; case TERMREQ: - term_msg=_strndup((char*)(hdr+1),ntohs(hdr->len) - 4); - log_ppp_debug("recv [IPCP TermReq id=%x \"%s\"]\n",hdr->id,term_msg); - _free(term_msg); + if (conf_ppp_verbose) + log_ppp_info("recv [IPCP TermReq id=%x]\n", hdr->id); ppp_fsm_recv_term_req(&ipcp->fsm); ppp_terminate(ipcp->ppp, 0); break; case TERMACK: - term_msg=_strndup((char*)(hdr+1),ntohs(hdr->len) - 4); - log_ppp_debug("recv [IPCP TermAck id=%x \"%s\"]\n",hdr->id,term_msg); - _free(term_msg); + if (conf_ppp_verbose) + log_ppp_info("recv [IPCP TermAck id=%x]\n", hdr->id); ppp_fsm_recv_term_ack(&ipcp->fsm); ppp_terminate(ipcp->ppp, 0); break; case CODEREJ: - log_ppp_debug("recv [IPCP CodeRej id=%x]\n",hdr->id); + if (conf_ppp_verbose) + log_ppp_info("recv [IPCP CodeRej id=%x]\n", hdr->id); ppp_fsm_recv_code_rej_bad(&ipcp->fsm); break; default: @@ -614,20 +631,21 @@ int ipcp_option_register(struct ipcp_option_handler_t *h) if (p->id==h->id) return -1;*/ - list_add_tail(&h->entry,&option_handlers); + list_add_tail(&h->entry, &option_handlers); return 0; } -static struct ppp_layer_t ipcp_layer= +static struct ppp_layer_t ipcp_layer = { - .init=ipcp_layer_init, - .start=ipcp_layer_start, - .finish=ipcp_layer_finish, - .free=ipcp_layer_free, + .init = ipcp_layer_init, + .start = ipcp_layer_start, + .finish = ipcp_layer_finish, + .free = ipcp_layer_free, }; static void __init ipcp_init(void) { - ppp_register_layer("ipcp",&ipcp_layer); + ppp_register_layer("ipcp", &ipcp_layer); } + diff --git a/accel-pptpd/ppp/ppp_lcp.c b/accel-pptpd/ppp/ppp_lcp.c index 90141aa..08fd359 100644 --- a/accel-pptpd/ppp/ppp_lcp.c +++ b/accel-pptpd/ppp/ppp_lcp.c @@ -51,14 +51,12 @@ static void lcp_options_init(struct ppp_lcp_t *lcp) lcp->conf_req_len = sizeof(struct lcp_hdr_t); - list_for_each_entry(h,&option_handlers,entry) - { - lopt=h->init(lcp); - if (lopt) - { - lopt->h=h; - list_add_tail(&lopt->entry,&lcp->options); - lcp->conf_req_len+=lopt->len; + list_for_each_entry(h, &option_handlers, entry) { + lopt = h->init(lcp); + if (lopt) { + lopt->h = h; + list_add_tail(&lopt->entry, &lcp->options); + lcp->conf_req_len += lopt->len; } } } @@ -67,42 +65,41 @@ static void lcp_options_free(struct ppp_lcp_t *lcp) { struct lcp_option_t *lopt; - while(!list_empty(&lcp->options)) - { - lopt=list_entry(lcp->options.next,typeof(*lopt),entry); + while (!list_empty(&lcp->options)) { + lopt = list_entry(lcp->options.next, typeof(*lopt), entry); list_del(&lopt->entry); - lopt->h->free(lcp,lopt); + lopt->h->free(lcp, lopt); } } static struct ppp_layer_data_t *lcp_layer_init(struct ppp_t *ppp) { - struct ppp_lcp_t *lcp=_malloc(sizeof(*lcp)); - memset(lcp,0,sizeof(*lcp)); + struct ppp_lcp_t *lcp = _malloc(sizeof(*lcp)); + memset(lcp, 0, sizeof(*lcp)); log_ppp_debug("lcp_layer_init\n"); - lcp->ppp=ppp; - lcp->fsm.ppp=ppp; + lcp->ppp = ppp; + lcp->fsm.ppp = ppp; - lcp->hnd.proto=PPP_LCP; - lcp->hnd.recv=lcp_recv; + lcp->hnd.proto = PPP_LCP; + lcp->hnd.recv = lcp_recv; - ppp_register_chan_handler(ppp,&lcp->hnd); + ppp_register_chan_handler(ppp, &lcp->hnd); lcp->fsm.proto = PPP_LCP; ppp_fsm_init(&lcp->fsm); - lcp->fsm.layer_up=lcp_layer_up; - lcp->fsm.layer_down=lcp_layer_down; - lcp->fsm.layer_finished=lcp_layer_finished; - lcp->fsm.send_conf_req=send_conf_req; - lcp->fsm.send_conf_ack=send_conf_ack; - lcp->fsm.send_conf_nak=send_conf_nak; - lcp->fsm.send_conf_rej=send_conf_rej; - lcp->fsm.send_code_rej=send_code_rej; - lcp->fsm.send_term_req=send_term_req; - lcp->fsm.send_term_ack=send_term_ack; + lcp->fsm.layer_up = lcp_layer_up; + lcp->fsm.layer_down = lcp_layer_down; + lcp->fsm.layer_finished = lcp_layer_finished; + lcp->fsm.send_conf_req = send_conf_req; + lcp->fsm.send_conf_ack = send_conf_ack; + lcp->fsm.send_conf_nak = send_conf_nak; + lcp->fsm.send_conf_rej = send_conf_rej; + lcp->fsm.send_code_rej = send_code_rej; + lcp->fsm.send_term_req = send_term_req; + lcp->fsm.send_term_ack = send_term_ack; INIT_LIST_HEAD(&lcp->ropt_list); @@ -111,7 +108,7 @@ static struct ppp_layer_data_t *lcp_layer_init(struct ppp_t *ppp) int lcp_layer_start(struct ppp_layer_data_t *ld) { - struct ppp_lcp_t *lcp=container_of(ld,typeof(*lcp),ld); + struct ppp_lcp_t *lcp = container_of(ld, typeof(*lcp), ld); log_ppp_debug("lcp_layer_start\n"); @@ -125,7 +122,7 @@ int lcp_layer_start(struct ppp_layer_data_t *ld) void lcp_layer_finish(struct ppp_layer_data_t *ld) { - struct ppp_lcp_t *lcp=container_of(ld,typeof(*lcp),ld); + struct ppp_lcp_t *lcp = container_of(ld,typeof(*lcp),ld); log_ppp_debug("lcp_layer_finish\n"); @@ -136,12 +133,12 @@ void lcp_layer_finish(struct ppp_layer_data_t *ld) void lcp_layer_free(struct ppp_layer_data_t *ld) { - struct ppp_lcp_t *lcp=container_of(ld,typeof(*lcp),ld); + struct ppp_lcp_t *lcp = container_of(ld, typeof(*lcp), ld); log_ppp_debug("lcp_layer_free\n"); stop_echo(lcp); - ppp_unregister_handler(lcp->ppp,&lcp->hnd); + ppp_unregister_handler(lcp->ppp, &lcp->hnd); lcp_options_free(lcp); ppp_fsm_free(&lcp->fsm); @@ -150,12 +147,13 @@ void lcp_layer_free(struct ppp_layer_data_t *ld) static void lcp_layer_up(struct ppp_fsm_t *fsm) { - struct ppp_lcp_t *lcp=container_of(fsm,typeof(*lcp),fsm); + struct ppp_lcp_t *lcp = container_of(fsm, typeof(*lcp), fsm); + log_ppp_debug("lcp_layer_started\n"); if (!lcp->started) { lcp->started = 1; - ppp_layer_started(lcp->ppp,&lcp->ld); + ppp_layer_started(lcp->ppp, &lcp->ld); start_echo(lcp); } @@ -163,7 +161,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); + struct ppp_lcp_t *lcp = container_of(fsm, typeof(*lcp), fsm); //ppp_fsm_close(&lcp->fsm); stop_echo(lcp); //ppp_layer_finished(lcp->ppp,&lcp->ld); @@ -171,10 +169,12 @@ static void lcp_layer_down(struct ppp_fsm_t *fsm) static void lcp_layer_finished(struct ppp_fsm_t *fsm) { - struct ppp_lcp_t *lcp=container_of(fsm,typeof(*lcp),fsm); + struct ppp_lcp_t *lcp = container_of(fsm, typeof(*lcp), fsm); + log_ppp_debug("lcp_layer_finished\n"); + stop_echo(lcp); - ppp_layer_finished(lcp->ppp,&lcp->ld); + ppp_layer_finished(lcp->ppp, &lcp->ld); if (lcp->started) lcp->started = 0; else @@ -184,58 +184,54 @@ static void lcp_layer_finished(struct ppp_fsm_t *fsm) static void print_ropt(struct recv_opt_t *ropt) { int i; - uint8_t *ptr=(uint8_t*)ropt->hdr; + uint8_t *ptr = (uint8_t*)ropt->hdr; - log_ppp_debug(" <"); - for(i=0; ilen; i++) - { - log_ppp_debug(" %x",ptr[i]); + log_ppp_debug("<"); + for (i = 0; i < ropt->len; i++) { + log_ppp_info(" %x", ptr[i]); } log_ppp_debug(" >"); } 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; - struct lcp_hdr_t *lcp_hdr=(struct lcp_hdr_t*)ptr; + struct ppp_lcp_t *lcp = container_of(fsm, typeof(*lcp), fsm); + 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; - lcp_hdr->proto=htons(PPP_LCP); - lcp_hdr->code=CONFREQ; - lcp_hdr->id=++lcp->fsm.id; - lcp_hdr->len=0; + lcp_hdr->proto = htons(PPP_LCP); + lcp_hdr->code = CONFREQ; + lcp_hdr->id = ++lcp->fsm.id; + lcp_hdr->len = 0; - ptr+=sizeof(*lcp_hdr); + ptr += sizeof(*lcp_hdr); - list_for_each_entry(lopt,&lcp->options,entry) - { - n=lopt->h->send_conf_req(lcp,lopt,ptr); + list_for_each_entry(lopt, &lcp->options, entry) { + n = lopt->h->send_conf_req(lcp, lopt, ptr); if (n < 0) return -1; - if (n) - { - ptr+=n; + if (n) { + ptr += n; lopt->print = 1; } else lopt->print = 0; } if (conf_ppp_verbose) { - log_ppp_debug("send [LCP ConfReq id=%x", lcp_hdr->id); - list_for_each_entry(lopt,&lcp->options,entry) - { + log_ppp_info("send [LCP ConfReq id=%x", lcp_hdr->id); + list_for_each_entry(lopt,&lcp->options,entry) { if (lopt->print) { log_ppp_debug(" "); - lopt->h->print(log_ppp_debug,lopt,NULL); + lopt->h->print(log_ppp_debug, lopt, NULL); } } log_ppp_debug("]\n"); } - lcp_hdr->len=htons((ptr-buf)-2); - ppp_chan_send(lcp->ppp,lcp_hdr,ptr-buf); + lcp_hdr->len = htons(ptr - buf - 2); + ppp_chan_send(lcp->ppp, lcp_hdr, ptr-buf); _free(buf); @@ -244,148 +240,170 @@ 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 ppp_lcp_t *lcp = container_of(fsm, typeof(*lcp), fsm); + struct lcp_hdr_t *hdr = (struct lcp_hdr_t*)lcp->ppp->chan_buf; + + hdr->code = CONFACK; - hdr->code=CONFACK; - log_ppp_debug("send [LCP ConfAck id=%x ]\n",lcp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("send [LCP ConfAck id=%x ]\n", lcp->fsm.recv_id); - ppp_chan_send(lcp->ppp,hdr,ntohs(hdr->len)+2); + ppp_chan_send(lcp->ppp, hdr, ntohs(hdr->len) + 2); } 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 ppp_lcp_t *lcp = container_of(fsm, typeof(*lcp), fsm); + struct lcp_hdr_t *hdr = (struct lcp_hdr_t*)lcp->ppp->chan_buf; + + hdr->code = CONFACK; - hdr->code=CONFACK; - log_ppp_debug("send [LCP CodeRej %x id=%x ]\n",hdr->code, lcp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("send [LCP CodeRej %x id=%x ]\n",hdr->code, lcp->fsm.recv_id); - ppp_chan_send(lcp->ppp,hdr,ntohs(hdr->len)+2); + ppp_chan_send(lcp->ppp, hdr, ntohs(hdr->len) + 2); } 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; - struct lcp_hdr_t *lcp_hdr=(struct lcp_hdr_t*)ptr; + struct ppp_lcp_t *lcp = container_of(fsm, typeof(*lcp), fsm); + 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; - log_ppp_debug("send [LCP ConfNak id=%x",lcp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_debug("send [LCP ConfNak id=%x", lcp->fsm.recv_id); - lcp_hdr->proto=htons(PPP_LCP); - lcp_hdr->code=CONFNAK; - lcp_hdr->id=lcp->fsm.recv_id; - lcp_hdr->len=0; + lcp_hdr->proto = htons(PPP_LCP); + lcp_hdr->code = CONFNAK; + lcp_hdr->id = lcp->fsm.recv_id; + lcp_hdr->len = 0; - ptr+=sizeof(*lcp_hdr); + ptr += sizeof(*lcp_hdr); list_for_each_entry(lopt, &lcp->options, entry) { if (lopt->state == LCP_OPT_NAK) { - log_ppp_debug(" "); - lopt->h->print(log_ppp_debug,lopt,NULL); ptr+=lopt->h->send_conf_nak(lcp,lopt,ptr); + + if (conf_ppp_verbose) { + log_ppp_debug(" "); + lopt->h->print(log_ppp_info, lopt, NULL); + } } } - log_ppp_debug("]\n"); + if (conf_ppp_verbose) + log_ppp_info("]\n"); - lcp_hdr->len=htons((ptr-buf)-2); - ppp_chan_send(lcp->ppp,lcp_hdr,ptr-buf); + lcp_hdr->len = htons(ptr - buf - 2); + ppp_chan_send(lcp->ppp, lcp_hdr,ptr - buf); _free(buf); } 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 + sizeof(struct lcp_hdr_t)), *ptr=buf; - struct lcp_hdr_t *lcp_hdr=(struct lcp_hdr_t*)ptr; + struct ppp_lcp_t *lcp = container_of(fsm, typeof(*lcp), fsm); + 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; - log_ppp_debug("send [LCP ConfRej id=%x ",lcp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("send [LCP ConfRej id=%x ", lcp->fsm.recv_id); - lcp_hdr->proto=htons(PPP_LCP); - lcp_hdr->code=CONFREJ; - lcp_hdr->id=lcp->fsm.recv_id; - lcp_hdr->len=0; + lcp_hdr->proto = htons(PPP_LCP); + lcp_hdr->code = CONFREJ; + lcp_hdr->id = lcp->fsm.recv_id; + lcp_hdr->len = 0; - ptr+=sizeof(*lcp_hdr); + ptr += sizeof(*lcp_hdr); - list_for_each_entry(ropt,&lcp->ropt_list,entry) - { - if (ropt->state==LCP_OPT_REJ) - { - log_ppp_debug(" "); - if (ropt->lopt) ropt->lopt->h->print(log_ppp_debug,ropt->lopt,(uint8_t*)ropt->hdr); - else print_ropt(ropt); - memcpy(ptr,ropt->hdr,ropt->len); - ptr+=ropt->len; + list_for_each_entry(ropt, &lcp->ropt_list, entry) { + if (ropt->state == LCP_OPT_REJ) { + memcpy(ptr, ropt->hdr, ropt->len); + ptr += ropt->len; + + if (conf_ppp_verbose) { + log_ppp_info(" "); + if (ropt->lopt) + ropt->lopt->h->print(log_ppp_info, ropt->lopt, (uint8_t*)ropt->hdr); + else + print_ropt(ropt); + } } } - log_ppp_debug("]\n"); + if (conf_ppp_verbose) + log_ppp_info("]\n"); - lcp_hdr->len=htons((ptr-buf)-2); - ppp_chan_send(lcp->ppp,lcp_hdr,ptr-buf); + 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) +static int lcp_recv_conf_req(struct ppp_lcp_t *lcp, uint8_t *data, int size) { struct lcp_opt_hdr_t *hdr; struct recv_opt_t *ropt; struct lcp_option_t *lopt; - int r,ret=1; + int r, ret = 1; - lcp->ropt_len=size; + lcp->ropt_len = size; - while(size>0) - { - hdr=(struct lcp_opt_hdr_t *)data; + while (size > 0) { + hdr = (struct lcp_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; - ropt->hdr=hdr; - ropt->state=LCP_OPT_NONE; - list_add_tail(&ropt->entry,&lcp->ropt_list); - - data+=ropt->len; - size-=ropt->len; + + if (hdr->len > size) + ropt->len = size; + else + ropt->len = hdr->len; + + ropt->hdr = hdr; + ropt->state = LCP_OPT_NONE; + list_add_tail(&ropt->entry, &lcp->ropt_list); + + data += ropt->len; + size -= ropt->len; } - list_for_each_entry(lopt,&lcp->options,entry) - lopt->state=LCP_OPT_NONE; - - log_ppp_debug("recv [LCP ConfReq id=%x",lcp->fsm.recv_id); - list_for_each_entry(ropt,&lcp->ropt_list,entry) - { - list_for_each_entry(lopt,&lcp->options,entry) - { - if (lopt->id==ropt->hdr->id) - { - log_ppp_debug(" "); - lopt->h->print(log_ppp_debug,lopt,(uint8_t*)ropt->hdr); - r=lopt->h->recv_conf_req(lcp,lopt,(uint8_t*)ropt->hdr); - lopt->state=r; - ropt->state=r; - ropt->lopt=lopt; - if (roptions, entry) + lopt->state = LCP_OPT_NONE; + + if (conf_ppp_verbose) + log_ppp_info("recv [LCP ConfReq id=%x", lcp->fsm.recv_id); + + list_for_each_entry(ropt, &lcp->ropt_list, entry) { + list_for_each_entry(lopt, &lcp->options, entry) { + if (lopt->id == ropt->hdr->id) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + lopt->h->print(log_ppp_info, lopt, (uint8_t*)ropt->hdr); + } + r = lopt->h->recv_conf_req(lcp, lopt, (uint8_t*)ropt->hdr); + lopt->state = r; + ropt->state = r; + ropt->lopt = lopt; + if (rlopt) - { - log_ppp_debug(" "); - print_ropt(ropt); + if (!ropt->lopt) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + print_ropt(ropt); + } ropt->state=LCP_OPT_REJ; ret=LCP_OPT_REJ; } } - log_ppp_debug("]\n"); + + if (conf_ppp_verbose) + log_ppp_info("]\n"); /*list_for_each_entry(lopt,&lcp->options,entry) { @@ -404,128 +422,138 @@ static void lcp_free_conf_req(struct ppp_lcp_t *lcp) { struct recv_opt_t *ropt; - while(!list_empty(&lcp->ropt_list)) - { - ropt=list_entry(lcp->ropt_list.next,typeof(*ropt),entry); + while (!list_empty(&lcp->ropt_list)) { + ropt = list_entry(lcp->ropt_list.next, typeof(*ropt), entry); list_del(&ropt->entry); _free(ropt); } } -static int lcp_recv_conf_rej(struct ppp_lcp_t *lcp,uint8_t *data,int size) +static int lcp_recv_conf_rej(struct ppp_lcp_t *lcp, uint8_t *data, int size) { struct lcp_opt_hdr_t *hdr; struct lcp_option_t *lopt; - int res=0; + int res = 0; - log_ppp_debug("recv [LCP ConfRej id=%x",lcp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("recv [LCP ConfRej id=%x", lcp->fsm.recv_id); - if (lcp->fsm.recv_id!=lcp->fsm.id) - { - log_ppp_debug(": id mismatch ]\n"); + if (lcp->fsm.recv_id != lcp->fsm.id) { + if (conf_ppp_verbose) + log_ppp_info(": id mismatch ]\n"); return 0; } - while(size>0) - { - hdr=(struct lcp_opt_hdr_t *)data; + while (size > 0) { + hdr = (struct lcp_opt_hdr_t *)data; - list_for_each_entry(lopt,&lcp->options,entry) - { - if (lopt->id==hdr->id) - { + list_for_each_entry(lopt, &lcp->options, entry) { + if (lopt->id == hdr->id) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + lopt->h->print(log_ppp_info, lopt, (uint8_t*)hdr); + } if (!lopt->h->recv_conf_rej) - res=-1; - else if (lopt->h->recv_conf_rej(lcp,lopt,data)) - res=-1; + res = -1; + else if (lopt->h->recv_conf_rej(lcp, lopt, data)) + res = -1; break; } } - data+=hdr->len; - size-=hdr->len; + data += hdr->len; + size -= hdr->len; } - log_ppp_debug("]\n"); + + if (conf_ppp_verbose) + log_ppp_info("]\n"); + return res; } -static int lcp_recv_conf_nak(struct ppp_lcp_t *lcp,uint8_t *data,int size) +static int lcp_recv_conf_nak(struct ppp_lcp_t *lcp, uint8_t *data, int size) { struct lcp_opt_hdr_t *hdr; struct lcp_option_t *lopt; - int res=0; + int res = 0; - log_ppp_debug("recv [LCP ConfNak id=%x",lcp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("recv [LCP ConfNak id=%x", lcp->fsm.recv_id); - if (lcp->fsm.recv_id!=lcp->fsm.id) - { - log_ppp_debug(": id mismatch ]\n"); + if (lcp->fsm.recv_id != lcp->fsm.id) { + if (conf_ppp_verbose) + log_ppp_info(": id mismatch ]\n"); return 0; } - while(size>0) - { - hdr=(struct lcp_opt_hdr_t *)data; + while (size > 0) { + hdr = (struct lcp_opt_hdr_t *)data; - list_for_each_entry(lopt,&lcp->options,entry) - { - if (lopt->id==hdr->id) - { - log_ppp_debug(" "); - lopt->h->print(log_ppp_debug,lopt,data); - if (lopt->h->recv_conf_nak(lcp,lopt,data)) - res=-1; + list_for_each_entry(lopt,&lcp->options,entry) { + if (lopt->id == hdr->id) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + lopt->h->print(log_ppp_info, lopt, data); + } + if (lopt->h->recv_conf_nak(lcp, lopt, data)) + res = -1; break; } } - data+=hdr->len; - size-=hdr->len; + data += hdr->len; + size -= hdr->len; } - log_ppp_debug("]\n"); + + if (conf_ppp_verbose) + log_ppp_info("]\n"); + return res; } -static int lcp_recv_conf_ack(struct ppp_lcp_t *lcp,uint8_t *data,int size) +static int lcp_recv_conf_ack(struct ppp_lcp_t *lcp, uint8_t *data, int size) { struct lcp_opt_hdr_t *hdr; struct lcp_option_t *lopt; int res=0; - log_ppp_debug("recv [LCP ConfAck id=%x",lcp->fsm.recv_id); + if (conf_ppp_verbose) + log_ppp_info("recv [LCP ConfAck id=%x", lcp->fsm.recv_id); - if (lcp->fsm.recv_id!=lcp->fsm.id) - { - log_ppp_debug(": id mismatch ]\n"); + if (lcp->fsm.recv_id != lcp->fsm.id) { + if (conf_ppp_verbose) + log_ppp_info(": id mismatch ]\n"); return 0; } - while(size>0) - { - hdr=(struct lcp_opt_hdr_t *)data; + while (size > 0) { + hdr = (struct lcp_opt_hdr_t *)data; - list_for_each_entry(lopt,&lcp->options,entry) - { - if (lopt->id==hdr->id) - { - log_ppp_debug(" "); - lopt->h->print(log_ppp_debug,lopt,data); + list_for_each_entry(lopt, &lcp->options, entry) { + if (lopt->id == hdr->id) { + if (conf_ppp_verbose) { + log_ppp_info(" "); + lopt->h->print(log_ppp_info, lopt, data); + } if (!lopt->h->recv_conf_ack) break; - if (lopt->h->recv_conf_ack(lcp,lopt,data)) - res=-1; + if (lopt->h->recv_conf_ack(lcp, lopt, data)) + res = -1; break; } } - data+=hdr->len; - size-=hdr->len; + data += hdr->len; + size -= hdr->len; } - log_ppp_debug("]\n"); + + if (conf_ppp_verbose) + log_ppp_info("]\n"); + return res; } -static void lcp_recv_echo_repl(struct ppp_lcp_t *lcp,uint8_t *data,int size) +static void lcp_recv_echo_repl(struct ppp_lcp_t *lcp, uint8_t *data, int size) { uint32_t magic = *(uint32_t *)data; @@ -534,10 +562,11 @@ static void lcp_recv_echo_repl(struct ppp_lcp_t *lcp,uint8_t *data,int size) ppp_terminate(lcp->ppp, 0); } - log_ppp_debug("recv [LCP EchoRep id=%x ]\n",lcp->fsm.recv_id,magic); + if (conf_ppp_verbose) + log_ppp_info("recv [LCP EchoRep id=%x ]\n", lcp->fsm.recv_id, magic); if (magic == lcp->magic) { - log_ppp_error("lcp:echo: loop-back detected\n"); + log_ppp_error("lcp: echo: loop-back detected\n"); ppp_terminate(lcp->ppp, 0); } @@ -546,15 +575,18 @@ 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; - uint32_t magic = *(uint32_t *)(hdr+1); + struct lcp_hdr_t *hdr = (struct lcp_hdr_t*)lcp->ppp->chan_buf; + uint32_t magic = *(uint32_t *)(hdr + 1); + + hdr->code = ECHOREP; + *(uint32_t *)(hdr + 1) = lcp->magic; - hdr->code=ECHOREP; - *(uint32_t *)(hdr+1) = lcp->magic; - log_ppp_debug("send [LCP EchoRep id=%x ]\n", hdr->id, magic); + if (conf_ppp_verbose) + log_ppp_info("send [LCP EchoRep id=%x ]\n", hdr->id, magic); - ppp_chan_send(lcp->ppp,hdr,ntohs(hdr->len)+2); + ppp_chan_send(lcp->ppp, hdr, ntohs(hdr->len) + 2); } + static void send_echo_request(struct triton_timer_t *t) { struct ppp_lcp_t *lcp = container_of(t, typeof(*lcp), echo_timer); @@ -574,7 +606,8 @@ static void send_echo_request(struct triton_timer_t *t) log_ppp_warn("lcp: no echo reply\n"); ppp_terminate(lcp->ppp, 0); } else { - log_ppp_debug("send [LCP EchoReq id=%x ]\n", msg.hdr.id, msg.magic); + if (conf_ppp_verbose) + log_ppp_info("send [LCP EchoReq id=%x ]\n", msg.hdr.id, msg.magic); ppp_chan_send(lcp->ppp,&msg,ntohs(msg.hdr.len)+2); } } @@ -605,14 +638,15 @@ static void send_term_req(struct ppp_fsm_t *fsm) .len = htons(4), }; - log_ppp_debug("send [LCP TermReq id=%i \"\"]\n",hdr.id); + if (conf_ppp_verbose) + log_ppp_info("send [LCP TermReq id=%i]\n", hdr.id); ppp_chan_send(lcp->ppp, &hdr, 6); } static void send_term_ack(struct ppp_fsm_t *fsm) { - struct ppp_lcp_t *lcp=container_of(fsm,typeof(*lcp),fsm); + struct ppp_lcp_t *lcp = container_of(fsm, typeof(*lcp), fsm); struct lcp_hdr_t hdr = { .proto = htons(PPP_LCP), .code = TERMACK, @@ -620,7 +654,8 @@ static void send_term_ack(struct ppp_fsm_t *fsm) .len = htons(4), }; - log_ppp_debug("send [LCP TermAck id=%i \"\"]\n", hdr.id); + if (conf_ppp_verbose) + log_ppp_info("send [LCP TermAck id=%i]\n", hdr.id); ppp_chan_send(lcp->ppp, &hdr, 6); } @@ -640,7 +675,8 @@ void lcp_send_proto_rej(struct ppp_t *ppp, uint16_t proto) .proto = proto, }; - log_ppp_debug("send [LCP ProtoRej id=%i <%x>]\n", msg.hdr.id, proto); + if (conf_ppp_verbose) + log_ppp_info("send [LCP ProtoRej id=%i <%04x>]\n", msg.hdr.id, proto); ppp_chan_send(lcp->ppp, &msg, sizeof(msg)); } @@ -648,30 +684,26 @@ void lcp_send_proto_rej(struct ppp_t *ppp, uint16_t proto) static void lcp_recv(struct ppp_handler_t*h) { struct lcp_hdr_t *hdr; - struct ppp_lcp_t *lcp=container_of(h,typeof(*lcp),hnd); + struct ppp_lcp_t *lcp = container_of(h, typeof(*lcp), hnd); int r; char *term_msg; - if (lcp->ppp->chan_buf_sizeppp->chan_buf_size < PPP_HEADERLEN + 2) { log_ppp_warn("LCP: short packet received\n"); return; } - hdr=(struct lcp_hdr_t *)lcp->ppp->chan_buf; - if (ntohs(hdr->len)ppp->chan_buf; + if (ntohs(hdr->len) < PPP_HEADERLEN) { log_ppp_warn("LCP: short packet received\n"); return; } - lcp->fsm.recv_id=hdr->id; - switch(hdr->code) - { + lcp->fsm.recv_id = hdr->id; + switch(hdr->code) { case CONFREQ: - r=lcp_recv_conf_req(lcp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN); - switch(r) - { + r = lcp_recv_conf_req(lcp, (uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN); + switch(r) { case LCP_OPT_ACK: ppp_fsm_recv_conf_req_ack(&lcp->fsm); break; @@ -683,65 +715,69 @@ static void lcp_recv(struct ppp_handler_t*h) break; } lcp_free_conf_req(lcp); - if (r==LCP_OPT_FAIL) + if (r == LCP_OPT_FAIL) ppp_terminate(lcp->ppp, 0); break; case CONFACK: - if (lcp_recv_conf_ack(lcp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN)) + 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) + 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) + 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)) + 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) + 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); - log_ppp_debug("recv [LCP TermReq id=%x \"%s\"]\n",hdr->id,term_msg); - _free(term_msg); + if (conf_ppp_verbose) + log_ppp_info("recv [LCP TermReq id=%x]\n", hdr->id); 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); - log_ppp_debug("recv [LCP TermAck id=%x \"%s\"]\n",hdr->id,term_msg); - _free(term_msg); + if (conf_ppp_verbose) + log_ppp_info("recv [LCP TermAck id=%x]\n", hdr->id); ppp_fsm_recv_term_ack(&lcp->fsm); break; case CODEREJ: - log_ppp_debug("recv [LCP CodeRej id=%x]\n",hdr->id); + if (conf_ppp_verbose) + log_ppp_info("recv [LCP CodeRej id=%x]\n", hdr->id); ppp_fsm_recv_code_rej_bad(&lcp->fsm); break; case ECHOREQ: - log_ppp_debug("recv [LCP EchoReq id=%x ]\n",hdr->id, *(uint32_t*)(hdr + 1)); + if (conf_ppp_verbose) + log_ppp_info("recv [LCP EchoReq id=%x ]\n", hdr->id, *(uint32_t*)(hdr + 1)); send_echo_reply(lcp); break; case ECHOREP: - lcp_recv_echo_repl(lcp,(uint8_t*)(hdr+1),ntohs(hdr->len)-PPP_HDRLEN); + lcp_recv_echo_repl(lcp, (uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN); break; case PROTOREJ: - log_ppp_debug("recv [LCP ProtoRej id=%x <%x>]\n",hdr->code, hdr->id, *(uint16_t*)(hdr + 1)); + if (conf_ppp_verbose) + log_ppp_info("recv [LCP ProtoRej id=%x <%x>]\n", hdr->code, hdr->id, *(uint16_t*)(hdr + 1)); break; case IDENT: - term_msg = _strndup((char*)(hdr + 1) + 4, ntohs(hdr->len) - 4 - 4); - log_ppp_debug("recv [LCP Ident id=%x <%s>]\n", hdr->id, term_msg); - _free(term_msg); + if (conf_ppp_verbose) { + term_msg = _strndup((char*)(hdr + 1) + 4, ntohs(hdr->len) - 4 - 4); + log_ppp_info("recv [LCP Ident id=%x <%s>]\n", hdr->id, term_msg); + _free(term_msg); + } break; default: - log_ppp_debug("recv [LCP Unknown %x]\n",hdr->code); + if (conf_ppp_verbose) + log_ppp_info("recv [LCP Unknown %x]\n", hdr->code); ppp_fsm_recv_unk(&lcp->fsm); break; } @@ -755,24 +791,24 @@ int lcp_option_register(struct lcp_option_handler_t *h) if (p->id==h->id) return -1;*/ - list_add_tail(&h->entry,&option_handlers); + list_add_tail(&h->entry, &option_handlers); return 0; } static struct ppp_layer_t lcp_layer= { - .init=lcp_layer_init, - .start=lcp_layer_start, - .finish=lcp_layer_finish, - .free=lcp_layer_free, + .init = lcp_layer_init, + .start = lcp_layer_start, + .finish = lcp_layer_finish, + .free = lcp_layer_free, }; static void __init lcp_init(void) { char *opt; - ppp_register_layer("lcp",&lcp_layer); + ppp_register_layer("lcp", &lcp_layer); opt = conf_get_opt("lcp", "echo-interval"); if (opt && atoi(opt) > 0) @@ -781,5 +817,5 @@ static void __init lcp_init(void) opt = conf_get_opt("lcp", "echo-failure"); if (opt && atoi(opt) > 0) conf_echo_failure = atoi(opt); - } + -- cgit v1.2.3