diff options
Diffstat (limited to 'accel-pptpd')
-rw-r--r-- | accel-pptpd/accel-pptpd.conf | 5 | ||||
-rw-r--r-- | accel-pptpd/auth/auth_chap_md5.c | 173 | ||||
-rw-r--r-- | accel-pptpd/auth/auth_mschap_v1.c | 221 | ||||
-rw-r--r-- | accel-pptpd/auth/auth_mschap_v2.c | 184 | ||||
-rw-r--r-- | accel-pptpd/auth/auth_pap.c | 115 | ||||
-rw-r--r-- | accel-pptpd/ctrl/pptp.c | 27 | ||||
-rw-r--r-- | accel-pptpd/log.c | 4 | ||||
-rw-r--r-- | accel-pptpd/ppp/ipcp_opt_ipaddr.c | 2 | ||||
-rw-r--r-- | accel-pptpd/ppp/lcp_opt_mru.c | 22 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp.c | 183 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp.h | 1 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_auth.c | 203 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_auth.h | 1 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_ccp.c | 456 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_ipcp.c | 502 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_lcp.c | 556 | ||||
-rw-r--r-- | accel-pptpd/radius/acct.c | 4 | ||||
-rw-r--r-- | accel-pptpd/radius/dm_coa.c | 16 | ||||
-rw-r--r-- | accel-pptpd/radius/req.c | 10 | ||||
-rw-r--r-- | accel-pptpd/triton/triton.c | 9 | ||||
-rw-r--r-- | accel-pptpd/triton/triton.h | 2 |
21 files changed, 1390 insertions, 1306 deletions
diff --git a/accel-pptpd/accel-pptpd.conf b/accel-pptpd/accel-pptpd.conf index 380213b..80688d9 100644 --- a/accel-pptpd/accel-pptpd.conf +++ b/accel-pptpd/accel-pptpd.conf @@ -8,6 +8,7 @@ auth_mschap_v1 auth_mschap_v2 libradius.so pppd_compat +ippool [core] log-error=/dev/stderr @@ -17,6 +18,7 @@ thread-count=4 verbose=1 min-mtu=1000 mtu=1200 +mru=1200 [lcp] echo-interval=30 @@ -55,12 +57,13 @@ gw-ip-address=192.168.100.1 [log] log-file=general.log log-emerg=/dev/stderr -log-debug=debug.log +log-debug=/dev/stdout copy=1 #color=1 #per-user-dir=per_user per-session-dir=per_session #per-session=1 +level=3 [log-pgsql] conninfo=user=log diff --git a/accel-pptpd/auth/auth_chap_md5.c b/accel-pptpd/auth/auth_chap_md5.c index e0fe2d4..4031a9a 100644 --- a/accel-pptpd/auth/auth_chap_md5.c +++ b/accel-pptpd/auth/auth_chap_md5.c @@ -84,49 +84,49 @@ static void chap_recv(struct ppp_handler_t *h); static void chap_timeout(struct triton_timer_t *t); static void chap_restart(struct triton_timer_t *t); -static void print_buf(const uint8_t *buf,int size) +static void print_buf(const uint8_t *buf, int size) { int i; - for(i=0;i<size;i++) - log_ppp_debug("%x",buf[i]); + for (i=0; i < size; i++) + log_ppp_info("%x", buf[i]); } -static void print_str(const char *buf,int size) +static void print_str(const char *buf, int size) { int i; - for(i=0;i<size;i++) - log_ppp_debug("%c",buf[i]); + for (i = 0; i < size; i++) + log_ppp_info("%c", buf[i]); } static struct auth_data_t* auth_data_init(struct ppp_t *ppp) { - struct chap_auth_data_t *d=_malloc(sizeof(*d)); + struct chap_auth_data_t *d = _malloc(sizeof(*d)); - memset(d,0,sizeof(*d)); - d->auth.proto=PPP_CHAP; - d->ppp=ppp; + memset(d, 0, sizeof(*d)); + d->auth.proto = PPP_CHAP; + d->ppp = ppp; return &d->auth; } -static void auth_data_free(struct ppp_t *ppp,struct auth_data_t *auth) +static void auth_data_free(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); _free(d); } static int chap_start(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); - d->h.proto=PPP_CHAP; - d->h.recv=chap_recv; + d->h.proto = PPP_CHAP; + d->h.recv = chap_recv; d->timeout.expire = chap_timeout; d->timeout.period = conf_timeout * 1000; d->interval.expire = chap_restart; d->interval.period = conf_interval * 1000; - ppp_register_chan_handler(ppp,&d->h); + ppp_register_chan_handler(ppp, &d->h); chap_send_challenge(d); @@ -135,7 +135,7 @@ static int chap_start(struct ppp_t *ppp, struct auth_data_t *auth) static int chap_finish(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); if (d->timeout.tpd) triton_timer_del(&d->timeout); @@ -143,7 +143,7 @@ static int chap_finish(struct ppp_t *ppp, struct auth_data_t *auth) if (d->interval.tpd) triton_timer_del(&d->interval); - ppp_unregister_handler(ppp,&d->h); + ppp_unregister_handler(ppp, &d->h); return 0; } @@ -152,7 +152,8 @@ static void chap_timeout(struct triton_timer_t *t) { struct chap_auth_data_t *d = container_of(t, typeof(*d), timeout); - log_ppp_warn("chap-md5: timeout\n"); + if (conf_ppp_verbose) + log_ppp_warn("chap-md5: timeout\n"); if (++d->failure == conf_max_failure) { if (d->started) @@ -187,55 +188,56 @@ static int lcp_recv_conf_req(struct ppp_t *ppp, struct auth_data_t *d, uint8_t * static void chap_send_failure(struct chap_auth_data_t *ad) { - struct chap_failure_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_FAILURE, - .hdr.id=ad->id, - .hdr.len=htons(sizeof(msg)-1-2), - .message=MSG_FAILURE, + struct chap_failure_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_FAILURE, + .hdr.id = ad->id, + .hdr.len = htons(sizeof(msg) - 1 - 2), + .message = MSG_FAILURE, }; - log_ppp_debug("send [CHAP Failure id=%x \"%s\"]\n",msg.hdr.id,MSG_FAILURE); + if (conf_ppp_verbose) + log_ppp_info("send [CHAP Failure id=%x \"%s\"]\n", msg.hdr.id, MSG_FAILURE); - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); } static void chap_send_success(struct chap_auth_data_t *ad) { - struct chap_success_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_SUCCESS, - .hdr.id=ad->id, - .hdr.len=htons(sizeof(msg)-1-2), - .message=MSG_SUCCESS, + struct chap_success_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_SUCCESS, + .hdr.id = ad->id, + .hdr.len = htons(sizeof(msg)-1-2), + .message = MSG_SUCCESS, }; - log_ppp_debug("send [CHAP Success id=%x \"%s\"]\n",msg.hdr.id,MSG_SUCCESS); + if (conf_ppp_verbose) + log_ppp_info("send [CHAP Success id=%x \"%s\"]\n", msg.hdr.id, MSG_SUCCESS); - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); } static void chap_send_challenge(struct chap_auth_data_t *ad) { - struct chap_challenge_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_CHALLENGE, - .hdr.id=++ad->id, - .hdr.len=htons(sizeof(msg)-2), - .val_size=VALUE_SIZE, + struct chap_challenge_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_CHALLENGE, + .hdr.id = ++ad->id, + .hdr.len = htons(sizeof(msg) - 2), + .val_size = VALUE_SIZE, }; - read(urandom_fd,ad->val,VALUE_SIZE); - memcpy(msg.val,ad->val,VALUE_SIZE); + read(urandom_fd, ad->val, VALUE_SIZE); + memcpy(msg.val, ad->val, VALUE_SIZE); - log_ppp_debug("send [CHAP Challenge id=%x <",msg.hdr.id); - print_buf(msg.val,VALUE_SIZE); - log_ppp_debug(">]\n"); + if (conf_ppp_verbose) { + log_ppp_info("send [CHAP Challenge id=%x <", msg.hdr.id); + print_buf(msg.val, VALUE_SIZE); + log_ppp_info(">]\n"); + } - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); if (conf_timeout && !ad->timeout.tpd) triton_timer_add(ad->ppp->ctrl->ctx, &ad->timeout, 0); @@ -248,32 +250,33 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h char *passwd; char *name; int r; - struct chap_challenge_t *msg=(struct chap_challenge_t*)hdr; + struct chap_challenge_t *msg = (struct chap_challenge_t*)hdr; if (ad->timeout.tpd) triton_timer_del(&ad->timeout); - log_ppp_debug("recv [CHAP Response id=%x <", msg->hdr.id); - print_buf(msg->val,msg->val_size); - log_ppp_debug(">, name=\""); - print_str(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2); - log_ppp_debug("\"]\n"); + if (conf_ppp_verbose) { + log_ppp_info("recv [CHAP Response id=%x <", msg->hdr.id); + print_buf(msg->val, msg->val_size); + log_ppp_info(">, name=\""); + print_str(msg->name, ntohs(msg->hdr.len) - sizeof(*msg) + 2); + log_ppp_info("\"]\n"); + } - if (msg->hdr.id!=ad->id) - { - log_ppp_error("chap-md5: id mismatch\n"); + if (msg->hdr.id != ad->id) { + if (conf_ppp_verbose) + log_ppp_error("chap-md5: id mismatch\n"); chap_send_failure(ad); ppp_terminate(ad->ppp, 0); } - if (msg->val_size!=VALUE_SIZE) - { - log_ppp_error("chap-md5: value-size should be %i, expected %i\n",VALUE_SIZE,msg->val_size); + if (msg->val_size != VALUE_SIZE) { + log_ppp_error("chap-md5: incorrect value-size (%i)\n", msg->val_size); chap_send_failure(ad); ppp_terminate(ad->ppp, 0); } - name = _strndup(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2); + name = _strndup(msg->name,ntohs(msg->hdr.len) - sizeof(*msg) + 2); r = pwdb_check(ad->ppp, name, PPP_CHAP, CHAP_MD5, ad->id, ad->val, VALUE_SIZE, msg->val); @@ -282,7 +285,8 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (!passwd) { _free(name); - log_ppp_debug("chap-md5: user not found\n"); + if (conf_ppp_verbose) + log_ppp_warn("chap-md5: user not found\n"); chap_send_failure(ad); return; } @@ -295,7 +299,8 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (memcmp(md5,msg->val,sizeof(md5))) { - log_ppp_debug("chap-md5: challenge response mismatch\n"); + if (conf_ppp_verbose) + log_ppp_warn("chap-md5: challenge response mismatch\n"); chap_send_failure(ad); if (ad->started) ppp_terminate(ad->ppp, 0); @@ -331,33 +336,37 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h } } +static int chap_check(uint8_t *ptr) +{ + return *ptr == CHAP_MD5; +} + static struct ppp_auth_handler_t chap= { - .name="CHAP-md5", - .init=auth_data_init, - .free=auth_data_free, - .send_conf_req=lcp_send_conf_req, - .recv_conf_req=lcp_recv_conf_req, - .start=chap_start, - .finish=chap_finish, + .name = "CHAP-md5", + .init = auth_data_init, + .free = auth_data_free, + .send_conf_req = lcp_send_conf_req, + .recv_conf_req = lcp_recv_conf_req, + .start = chap_start, + .finish = chap_finish, + .check = chap_check, }; static void chap_recv(struct ppp_handler_t *h) { - struct chap_auth_data_t *d=container_of(h,typeof(*d),h); - struct chap_hdr_t *hdr=(struct chap_hdr_t *)d->ppp->chan_buf; + struct chap_auth_data_t *d = container_of(h, typeof(*d), h); + struct chap_hdr_t *hdr = (struct chap_hdr_t *)d->ppp->chan_buf; - if (d->ppp->chan_buf_size<sizeof(*hdr) || ntohs(hdr->len)<HDR_LEN || ntohs(hdr->len)<d->ppp->chan_buf_size-2) - { - log_ppp_warn("CHAP: short packet received\n"); + if (d->ppp->chan_buf_size < sizeof(*hdr) || ntohs(hdr->len) < HDR_LEN || ntohs(hdr->len) < d->ppp->chan_buf_size - 2) { + log_ppp_warn("chap-md5: short packet received\n"); return; } - if (hdr->code==CHAP_RESPONSE) chap_recv_response(d,hdr); + if (hdr->code == CHAP_RESPONSE) + chap_recv_response(d, hdr); else - { - log_ppp_warn("CHAP: unknown code received %x\n",hdr->code); - } + log_ppp_warn("chap-md5: unknown code received %x\n", hdr->code); } static void __init auth_chap_md5_init() @@ -384,6 +393,6 @@ static void __init auth_chap_md5_init() } if (ppp_auth_register_handler(&chap)) - log_error("chap-md5: failed to register handler\n"); + log_emerg("chap-md5: failed to register handler\n"); } diff --git a/accel-pptpd/auth/auth_mschap_v1.c b/accel-pptpd/auth/auth_mschap_v1.c index 203c25e..5b4935e 100644 --- a/accel-pptpd/auth/auth_mschap_v1.c +++ b/accel-pptpd/auth/auth_mschap_v1.c @@ -101,46 +101,46 @@ static void chap_restart(struct triton_timer_t *t); static void print_buf(const uint8_t *buf,int size) { int i; - for(i=0;i<size;i++) - log_ppp_debug("%x",buf[i]); + for (i = 0; i < size; i++) + log_ppp_info("%x", buf[i]); } -static void print_str(const char *buf,int size) +static void print_str(const char *buf, int size) { int i; - for(i=0;i<size;i++) - log_ppp_debug("%c",buf[i]); + for(i = 0; i < size; i++) + log_ppp_info("%c", buf[i]); } static struct auth_data_t* auth_data_init(struct ppp_t *ppp) { - struct chap_auth_data_t *d=_malloc(sizeof(*d)); + struct chap_auth_data_t *d = _malloc(sizeof(*d)); - memset(d,0,sizeof(*d)); - d->auth.proto=PPP_CHAP; - d->ppp=ppp; + memset(d, 0, sizeof(*d)); + d->auth.proto = PPP_CHAP; + d->ppp = ppp; return &d->auth; } -static void auth_data_free(struct ppp_t *ppp,struct auth_data_t *auth) +static void auth_data_free(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); _free(d); } static int chap_start(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); - d->h.proto=PPP_CHAP; - d->h.recv=chap_recv; + d->h.proto = PPP_CHAP; + d->h.recv = chap_recv; d->timeout.expire = chap_timeout; d->timeout.period = conf_timeout * 1000; d->interval.expire = chap_restart; d->interval.period = conf_interval * 1000; - ppp_register_chan_handler(ppp,&d->h); + ppp_register_chan_handler(ppp, &d->h); chap_send_challenge(d); @@ -149,7 +149,7 @@ static int chap_start(struct ppp_t *ppp, struct auth_data_t *auth) static int chap_finish(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); if (d->timeout.tpd) triton_timer_del(&d->timeout); @@ -157,7 +157,7 @@ static int chap_finish(struct ppp_t *ppp, struct auth_data_t *auth) if (d->interval.tpd) triton_timer_del(&d->interval); - ppp_unregister_handler(ppp,&d->h); + ppp_unregister_handler(ppp, &d->h); return 0; } @@ -166,7 +166,8 @@ static void chap_timeout(struct triton_timer_t *t) { struct chap_auth_data_t *d = container_of(t, typeof(*d), timeout); - log_ppp_warn("mschap-v1: timeout\n"); + if (conf_ppp_verbose) + log_ppp_warn("mschap-v1: timeout\n"); if (++d->failure == conf_max_failure) { if (d->started) @@ -188,68 +189,69 @@ static void chap_restart(struct triton_timer_t *t) static int lcp_send_conf_req(struct ppp_t *ppp, struct auth_data_t *d, uint8_t *ptr) { - *ptr=MSCHAP_V1; + *ptr = MSCHAP_V1; return 1; } static int lcp_recv_conf_req(struct ppp_t *ppp, struct auth_data_t *d, uint8_t *ptr) { - if (*ptr==MSCHAP_V1) + if (*ptr == MSCHAP_V1) return LCP_OPT_ACK; return LCP_OPT_NAK; } static void chap_send_failure(struct chap_auth_data_t *ad) { - struct chap_failure_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_FAILURE, - .hdr.id=ad->id, - .hdr.len=htons(sizeof(msg)-1-2), - .message=MSG_FAILURE, + struct chap_failure_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_FAILURE, + .hdr.id = ad->id, + .hdr.len = htons(sizeof(msg)-1-2), + .message = MSG_FAILURE, }; - log_ppp_debug("send [MSCHAP-v1 Failure id=%x \"%s\"]\n",msg.hdr.id,MSG_FAILURE); + if (conf_ppp_verbose) + log_ppp_info("send [MSCHAP-v1 Failure id=%x \"%s\"]\n", msg.hdr.id, MSG_FAILURE); ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); } static void chap_send_success(struct chap_auth_data_t *ad) { - struct chap_success_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_SUCCESS, - .hdr.id=ad->id, - .hdr.len=htons(sizeof(msg)-1-2), - .message=MSG_SUCCESS, + struct chap_success_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_SUCCESS, + .hdr.id = ad->id, + .hdr.len = htons(sizeof(msg)-1-2), + .message = MSG_SUCCESS, }; - log_ppp_debug("send [MSCHAP-v1 Success id=%x \"%s\"]\n",msg.hdr.id,MSG_SUCCESS); + if (conf_ppp_verbose) + log_ppp_info("send [MSCHAP-v1 Success id=%x \"%s\"]\n", msg.hdr.id, MSG_SUCCESS); - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); } static void chap_send_challenge(struct chap_auth_data_t *ad) { - struct chap_challenge_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_CHALLENGE, - .hdr.id=++ad->id, - .hdr.len=htons(sizeof(msg)-2), - .val_size=VALUE_SIZE, + struct chap_challenge_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_CHALLENGE, + .hdr.id = ++ad->id, + .hdr.len = htons(sizeof(msg) - 2), + .val_size = VALUE_SIZE, }; - read(urandom_fd,ad->val,VALUE_SIZE); - memcpy(msg.val,ad->val,VALUE_SIZE); + read(urandom_fd, ad->val, VALUE_SIZE); + memcpy(msg.val, ad->val, VALUE_SIZE); - log_ppp_debug("send [MSCHAP-v1 Challenge id=%x <",msg.hdr.id); - print_buf(msg.val,VALUE_SIZE); - log_ppp_debug(">]\n"); + if (conf_ppp_verbose) { + log_ppp_info("send [MSCHAP-v1 Challenge id=%x <", msg.hdr.id); + print_buf(msg.val, VALUE_SIZE); + log_ppp_info(">]\n"); + } - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); if (conf_timeout && !ad->timeout.tpd) triton_timer_add(ad->ppp->ctrl->ctx, &ad->timeout, 0); @@ -257,24 +259,26 @@ static void chap_send_challenge(struct chap_auth_data_t *ad) static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *hdr) { - struct chap_response_t *msg=(struct chap_response_t*)hdr; + struct chap_response_t *msg = (struct chap_response_t*)hdr; char *name; int r; if (ad->timeout.tpd) triton_timer_del(&ad->timeout); - log_ppp_debug("recv [MSCHAP-v1 Response id=%x <", msg->hdr.id); - print_buf(msg->lm_hash,24); - log_ppp_debug(">, <"); - print_buf(msg->nt_hash,24); - log_ppp_debug(">, F=%i, name=\"",msg->flags); - print_str(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2); - log_ppp_debug("\"]\n"); + if (conf_ppp_verbose) { + log_ppp_info("recv [MSCHAP-v1 Response id=%x <", msg->hdr.id); + print_buf(msg->lm_hash, 24); + log_ppp_info(">, <"); + print_buf(msg->nt_hash, 24); + log_ppp_info(">, F=%i, name=\"", msg->flags); + print_str(msg->name, ntohs(msg->hdr.len) - sizeof(*msg) + 2); + log_ppp_info("\"]\n"); + } - if (msg->hdr.id!=ad->id) - { - log_ppp_error("mschap-v1: id mismatch\n"); + if (msg->hdr.id != ad->id) { + if (conf_ppp_verbose) + log_ppp_error("mschap-v1: id mismatch\n"); chap_send_failure(ad); if (ad->started) ppp_terminate(ad->ppp, 0); @@ -282,9 +286,8 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h auth_failed(ad->ppp); } - if (msg->val_size!=RESPONSE_VALUE_SIZE) - { - log_ppp_error("mschap-v1: value-size should be %i, expected %i\n",RESPONSE_VALUE_SIZE,msg->val_size); + if (msg->val_size != RESPONSE_VALUE_SIZE) { + log_ppp_error("mschap-v1: incorrect value-size (%i)\n", msg->val_size); chap_send_failure(ad); if (ad->started) ppp_terminate(ad->ppp, 0); @@ -292,7 +295,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h auth_failed(ad->ppp); } - name = _strndup(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2); + name = _strndup(msg->name, ntohs(msg->hdr.len) - sizeof(*msg) + 2); if (!name) { log_emerg("mschap-v1: out of memory\n"); if (ad->started) @@ -326,7 +329,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h static void des_encrypt(const uint8_t *input, const uint8_t *key, uint8_t *output) { - int i,j,parity; + int i, j, parity; union { uint64_t u64; @@ -336,21 +339,21 @@ static void des_encrypt(const uint8_t *input, const uint8_t *key, uint8_t *outpu DES_cblock res; DES_key_schedule ks; - memcpy(p_key.buf,key,7); - p_key.u64=bswap_64(p_key.u64); + memcpy(p_key.buf, key, 7); + p_key.u64 = bswap_64(p_key.u64); - for(i=0;i<8;i++) - { - cb[i]=(((p_key.u64<<(7*i))>>56)&0xfe); - for(j=0, parity=0; j<7; j++) - if ((cb[i]>>(j+1))&1) parity++; - cb[i]|=(~parity)&1; + for (i = 0; i < 8; i++) { + cb[i] = (((p_key.u64 << (7 * i)) >> 56) & 0xfe); + for( j = 0, parity = 0; j < 7; j++) + if ((cb[i] >> (j + 1)) & 1) + parity++; + cb[i] |= (~parity) & 1; } DES_set_key_checked(&cb, &ks); - memcpy(cb,input,8); - DES_ecb_encrypt(&cb,&res,&ks,DES_ENCRYPT); - memcpy(output,res,8); + memcpy(cb, input, 8); + DES_ecb_encrypt(&cb, &res, &ks, DES_ENCRYPT); + memcpy(output, res, 8); } static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response_t *msg, const char *name) @@ -363,62 +366,64 @@ static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response int i; passwd = pwdb_get_passwd(ad->ppp,name); - if (!passwd) - { - log_ppp_debug("mschap-v1: user not found\n"); + if (!passwd) { + if (conf_ppp_verbose) + log_ppp_warn("mschap-v1: user not found\n"); chap_send_failure(ad); return PWDB_DENIED; } - u_passwd=_malloc(strlen(passwd)*2); - for(i=0; i<strlen(passwd); i++) - { - u_passwd[i*2]=passwd[i]; - u_passwd[i*2+1]=0; + u_passwd = _malloc(strlen(passwd) * 2); + for (i = 0; i< strlen(passwd); i++) { + u_passwd[i * 2] = passwd[i]; + u_passwd[i * 2 + 1] = 0; } - memset(z_hash,0,sizeof(z_hash)); + memset(z_hash, 0, sizeof(z_hash)); MD4_Init(&md4_ctx); - MD4_Update(&md4_ctx,u_passwd,strlen(passwd)*2); - MD4_Final(z_hash,&md4_ctx); + MD4_Update(&md4_ctx, u_passwd, strlen(passwd) * 2); + MD4_Final(z_hash, &md4_ctx); - des_encrypt(ad->val,z_hash,nt_hash); - des_encrypt(ad->val,z_hash+7,nt_hash+8); - des_encrypt(ad->val,z_hash+14,nt_hash+16); + des_encrypt(ad->val, z_hash, nt_hash); + des_encrypt(ad->val, z_hash + 7, nt_hash + 8); + des_encrypt(ad->val, z_hash + 14, nt_hash + 16); _free(passwd); _free(u_passwd); - return memcmp(nt_hash,msg->nt_hash,24) ? PWDB_DENIED : PWDB_SUCCESS; + return memcmp(nt_hash, msg->nt_hash, 24) ? PWDB_DENIED : PWDB_SUCCESS; } -static struct ppp_auth_handler_t chap= +static int chap_check(uint8_t *ptr) { - .name="MSCHAP-v1", - .init=auth_data_init, - .free=auth_data_free, - .send_conf_req=lcp_send_conf_req, - .recv_conf_req=lcp_recv_conf_req, - .start=chap_start, - .finish=chap_finish, + return *ptr == MSCHAP_V1; +} + +static struct ppp_auth_handler_t chap = { + .name = "MSCHAP-v1", + .init = auth_data_init, + .free = auth_data_free, + .send_conf_req = lcp_send_conf_req, + .recv_conf_req = lcp_recv_conf_req, + .start = chap_start, + .finish = chap_finish, + .check = chap_check, }; static void chap_recv(struct ppp_handler_t *h) { - struct chap_auth_data_t *d=container_of(h,typeof(*d),h); - struct chap_hdr_t *hdr=(struct chap_hdr_t *)d->ppp->chan_buf; + struct chap_auth_data_t *d = container_of(h, typeof(*d), h); + struct chap_hdr_t *hdr = (struct chap_hdr_t *)d->ppp->chan_buf; - if (d->ppp->chan_buf_size<sizeof(*hdr) || ntohs(hdr->len)<HDR_LEN || ntohs(hdr->len)<d->ppp->chan_buf_size-2) - { + if (d->ppp->chan_buf_size < sizeof(*hdr) || ntohs(hdr->len) < HDR_LEN || ntohs(hdr->len) < d->ppp->chan_buf_size - 2) { log_ppp_warn("mschap-v1: short packet received\n"); return; } - if (hdr->code==CHAP_RESPONSE) chap_recv_response(d,hdr); + if (hdr->code == CHAP_RESPONSE) + chap_recv_response(d, hdr); else - { - log_ppp_warn("mschap-v1: unknown code received %x\n",hdr->code); - } + log_ppp_warn("mschap-v1: unknown code received %x\n", hdr->code); } static void __init auth_mschap_v1_init() diff --git a/accel-pptpd/auth/auth_mschap_v2.c b/accel-pptpd/auth/auth_mschap_v2.c index 44a67ca..a93fad6 100644 --- a/accel-pptpd/auth/auth_mschap_v2.c +++ b/accel-pptpd/auth/auth_mschap_v2.c @@ -112,51 +112,50 @@ static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response static void chap_timeout(struct triton_timer_t *t); static void chap_restart(struct triton_timer_t *t); -static void print_buf(const uint8_t *buf,int size) +static void print_buf(const uint8_t *buf, int size) { int i; - for(i=0;i<size;i++) - log_ppp_debug("%x",buf[i]); + for (i = 0; i < size; i++) + log_ppp_info("%x", buf[i]); } -static void print_str(const char *buf,int size) + +static void print_str(const char *buf, int size) { int i; - for(i=0;i<size;i++) - log_ppp_debug("%c",buf[i]); + for (i = 0; i < size; i++) + log_ppp_info("%c", buf[i]); } - - static struct auth_data_t* auth_data_init(struct ppp_t *ppp) { - struct chap_auth_data_t *d=_malloc(sizeof(*d)); + struct chap_auth_data_t *d = _malloc(sizeof(*d)); - memset(d,0,sizeof(*d)); - d->auth.proto=PPP_CHAP; - d->ppp=ppp; + memset(d, 0, sizeof(*d)); + d->auth.proto = PPP_CHAP; + d->ppp = ppp; return &d->auth; } -static void auth_data_free(struct ppp_t *ppp,struct auth_data_t *auth) +static void auth_data_free(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); _free(d); } static int chap_start(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); - d->h.proto=PPP_CHAP; - d->h.recv=chap_recv; + d->h.proto = PPP_CHAP; + d->h.recv = chap_recv; d->timeout.expire = chap_timeout; d->timeout.period = conf_timeout * 1000; d->interval.expire = chap_restart; d->interval.period = conf_interval * 1000; - ppp_register_chan_handler(ppp,&d->h); + ppp_register_chan_handler(ppp, &d->h); chap_send_challenge(d); @@ -165,7 +164,7 @@ static int chap_start(struct ppp_t *ppp, struct auth_data_t *auth) static int chap_finish(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); if (d->timeout.tpd) triton_timer_del(&d->timeout); @@ -182,7 +181,8 @@ static void chap_timeout(struct triton_timer_t *t) { struct chap_auth_data_t *d = container_of(t, typeof(*d), timeout); - log_ppp_warn("mschap-v2: timeout\n"); + if (conf_ppp_verbose) + log_ppp_warn("mschap-v2: timeout\n"); if (++d->failure == conf_max_failure) { if (d->started) @@ -217,18 +217,18 @@ static int lcp_recv_conf_req(struct ppp_t *ppp, struct auth_data_t *d, uint8_t * static void chap_send_failure(struct chap_auth_data_t *ad) { - struct chap_failure_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_FAILURE, - .hdr.id=ad->id, - .hdr.len=htons(sizeof(msg)-1-2), - .message=MSG_FAILURE, + struct chap_failure_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_FAILURE, + .hdr.id = ad->id, + .hdr.len = htons(sizeof(msg) - 1 - 2), + .message = MSG_FAILURE, }; - log_ppp_debug("send [MSCHAP-v2 Failure id=%x \"%s\"]\n",msg.hdr.id,MSG_FAILURE); + if (conf_ppp_verbose) + log_ppp_info("send [MSCHAP-v2 Failure id=%x \"%s\"]\n", msg.hdr.id, MSG_FAILURE); - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); } static int generate_response(struct chap_auth_data_t *ad, struct chap_response_t *msg, const char *name, char *authenticator) @@ -290,41 +290,42 @@ static int generate_response(struct chap_auth_data_t *ad, struct chap_response_t static void chap_send_success(struct chap_auth_data_t *ad, struct chap_response_t *res_msg, const char *authenticator) { - struct chap_success_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_SUCCESS, - .hdr.id=ad->id, - .hdr.len=htons(sizeof(msg)-1-2), - .message=MSG_SUCCESS, + struct chap_success_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_SUCCESS, + .hdr.id = ad->id, + .hdr.len = htons(sizeof(msg) - 1 - 2), + .message = MSG_SUCCESS, }; memcpy(msg.message + 2, authenticator, 40); - log_ppp_debug("send [MSCHAP-v2 Success id=%x \"%s\"]\n",msg.hdr.id,msg.message); + if (conf_ppp_verbose) + log_ppp_info("send [MSCHAP-v2 Success id=%x \"%s\"]\n", msg.hdr.id, msg.message); - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); } static void chap_send_challenge(struct chap_auth_data_t *ad) { - struct chap_challenge_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_CHALLENGE, - .hdr.id=++ad->id, - .hdr.len=htons(sizeof(msg)-2), - .val_size=VALUE_SIZE, + struct chap_challenge_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_CHALLENGE, + .hdr.id = ++ad->id, + .hdr.len = htons(sizeof(msg) - 2), + .val_size = VALUE_SIZE, }; - read(urandom_fd,ad->val,VALUE_SIZE); - memcpy(msg.val,ad->val,VALUE_SIZE); + read(urandom_fd, ad->val, VALUE_SIZE); + memcpy(msg.val, ad->val, VALUE_SIZE); - log_ppp_debug("send [MSCHAP-v2 Challenge id=%x <",msg.hdr.id); - print_buf(msg.val,VALUE_SIZE); - log_ppp_debug(">]\n"); + if (conf_ppp_verbose) { + log_ppp_info("send [MSCHAP-v2 Challenge id=%x <", msg.hdr.id); + print_buf(msg.val, VALUE_SIZE); + log_ppp_info(">]\n"); + } - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); if (conf_timeout && !ad->timeout.tpd) triton_timer_add(ad->ppp->ctrl->ctx, &ad->timeout, 0); @@ -332,7 +333,7 @@ static void chap_send_challenge(struct chap_auth_data_t *ad) static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *hdr) { - struct chap_response_t *msg=(struct chap_response_t*)hdr; + struct chap_response_t *msg = (struct chap_response_t*)hdr; char *name; char authenticator[40]; int r; @@ -340,17 +341,19 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (ad->timeout.tpd) triton_timer_del(&ad->timeout); - log_ppp_debug("recv [MSCHAP-v2 Response id=%x <", msg->hdr.id); - print_buf(msg->peer_challenge,16); - log_ppp_debug(">, <"); - print_buf(msg->nt_hash,24); - log_ppp_debug(">, F=%i, name=\"",msg->flags); - print_str(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2); - log_ppp_debug("\"]\n"); + if (conf_ppp_verbose) { + log_ppp_info("recv [MSCHAP-v2 Response id=%x <", msg->hdr.id); + print_buf(msg->peer_challenge,16); + log_ppp_info(">, <"); + print_buf(msg->nt_hash, 24); + log_ppp_info(">, F=%i, name=\"", msg->flags); + print_str(msg->name, ntohs(msg->hdr.len) - sizeof(*msg) + 2); + log_ppp_info("\"]\n"); + } - if (msg->hdr.id!=ad->id) - { - log_ppp_error("mschap-v2: id mismatch\n"); + if (msg->hdr.id != ad->id) { + if (conf_ppp_verbose) + log_ppp_error("mschap-v2: id mismatch\n"); chap_send_failure(ad); if (ad->started) ppp_terminate(ad->ppp, 0); @@ -358,9 +361,8 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h auth_failed(ad->ppp); } - if (msg->val_size!=RESPONSE_VALUE_SIZE) - { - log_ppp_error("mschap-v2: value-size should be %i, expected %i\n",RESPONSE_VALUE_SIZE,msg->val_size); + if (msg->val_size != RESPONSE_VALUE_SIZE) { + log_ppp_error("mschap-v2: incorrect value-size (%i)\n", msg->val_size); chap_send_failure(ad); if (ad->started) ppp_terminate(ad->ppp, 0); @@ -368,7 +370,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h auth_failed(ad->ppp); } - name=_strndup(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2); + name = _strndup(msg->name, ntohs(msg->hdr.len) - sizeof(*msg) + 2); if (!name) { log_emerg("mschap-v2: out of memory\n"); if (ad->started) @@ -444,10 +446,10 @@ static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response char *u_passwd; int i; - passwd=pwdb_get_passwd(ad->ppp,name); - if (!passwd) - { - log_ppp_debug("mschap-v2: user not found\n"); + passwd = pwdb_get_passwd(ad->ppp, name); + if (!passwd) { + if (conf_ppp_verbose) + log_ppp_warn("mschap-v2: user not found\n"); chap_send_failure(ad); return -1; } @@ -480,44 +482,48 @@ static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response return memcmp(nt_hash,msg->nt_hash,24); } +static int chap_check(uint8_t *ptr) +{ + return *ptr == MSCHAP_V2; +} + static struct ppp_auth_handler_t chap= { - .name="MSCHAP-v2", - .init=auth_data_init, - .free=auth_data_free, - .send_conf_req=lcp_send_conf_req, - .recv_conf_req=lcp_recv_conf_req, - .start=chap_start, - .finish=chap_finish, + .name = "MSCHAP-v2", + .init = auth_data_init, + .free = auth_data_free, + .send_conf_req = lcp_send_conf_req, + .recv_conf_req = lcp_recv_conf_req, + .start = chap_start, + .finish = chap_finish, + .check = chap_check, }; static void chap_recv(struct ppp_handler_t *h) { - struct chap_auth_data_t *d=container_of(h,typeof(*d),h); - struct chap_hdr_t *hdr=(struct chap_hdr_t *)d->ppp->chan_buf; + struct chap_auth_data_t *d = container_of(h, typeof(*d), h); + struct chap_hdr_t *hdr = (struct chap_hdr_t *)d->ppp->chan_buf; - if (d->ppp->chan_buf_size<sizeof(*hdr) || ntohs(hdr->len)<HDR_LEN || ntohs(hdr->len)<d->ppp->chan_buf_size-2) - { + if (d->ppp->chan_buf_size < sizeof(*hdr) || ntohs(hdr->len) < HDR_LEN || ntohs(hdr->len) < d->ppp->chan_buf_size - 2) { log_ppp_warn("mschap-v2: short packet received\n"); return; } - if (hdr->code==CHAP_RESPONSE) chap_recv_response(d,hdr); + if (hdr->code == CHAP_RESPONSE) + chap_recv_response(d, hdr); else - { log_ppp_warn("mschap-v2: unknown code received %x\n",hdr->code); - } } static void __init auth_mschap_v2_init() { - urandom_fd=open("/dev/urandom",O_RDONLY); - if (urandom_fd<0) - { - log_error("mschap-v2: failed to open /dev/urandom: %s\n",strerror(errno)); + urandom_fd = open("/dev/urandom", O_RDONLY); + if (urandom_fd < 0) { + log_emerg("mschap-v2: failed to open /dev/urandom: %s\n", strerror(errno)); return; } + if (ppp_auth_register_handler(&chap)) - log_error("mschap-v2: failed to register handler\n"); + log_emerg("mschap-v2: failed to register handler\n"); } diff --git a/accel-pptpd/auth/auth_pap.c b/accel-pptpd/auth/auth_pap.c index 0fd6e7f..b044f64 100644 --- a/accel-pptpd/auth/auth_pap.c +++ b/accel-pptpd/auth/auth_pap.c @@ -57,36 +57,36 @@ struct pap_ack_t static struct ppp_auth_handler_t pap= { - .name="PAP", - .init=auth_data_init, - .free=auth_data_free, - .send_conf_req=lcp_send_conf_req, - .recv_conf_req=lcp_recv_conf_req, - .start=pap_start, - .finish=pap_finish, + .name = "PAP", + .init = auth_data_init, + .free = auth_data_free, + .send_conf_req = lcp_send_conf_req, + .recv_conf_req = lcp_recv_conf_req, + .start = pap_start, + .finish = pap_finish, }; static struct auth_data_t* auth_data_init(struct ppp_t *ppp) { - struct pap_auth_data_t *d=_malloc(sizeof(*d)); + struct pap_auth_data_t *d = _malloc(sizeof(*d)); - memset(d,0,sizeof(*d)); - d->auth.proto=PPP_PAP; - d->ppp=ppp; + memset(d, 0, sizeof(*d)); + d->auth.proto = PPP_PAP; + d->ppp = ppp; return &d->auth; } -static void auth_data_free(struct ppp_t *ppp,struct auth_data_t *auth) +static void auth_data_free(struct ppp_t *ppp, struct auth_data_t *auth) { - struct pap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct pap_auth_data_t *d = container_of(auth, typeof(*d), auth); _free(d); } static int pap_start(struct ppp_t *ppp, struct auth_data_t *auth) { - struct pap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct pap_auth_data_t *d = container_of(auth, typeof(*d), auth); d->h.proto = PPP_PAP; d->h.recv = pap_recv; @@ -95,18 +95,18 @@ static int pap_start(struct ppp_t *ppp, struct auth_data_t *auth) triton_timer_add(ppp->ctrl->ctx, &d->timeout, 0); - ppp_register_chan_handler(ppp,&d->h); + ppp_register_chan_handler(ppp, &d->h); return 0; } static int pap_finish(struct ppp_t *ppp, struct auth_data_t *auth) { - struct pap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct pap_auth_data_t *d = container_of(auth, typeof(*d), auth); if (d->timeout.tpd) triton_timer_del(&d->timeout); - ppp_unregister_handler(ppp,&d->h); + ppp_unregister_handler(ppp, &d->h); return 0; } @@ -115,7 +115,9 @@ static void pap_timeout(struct triton_timer_t *t) { struct pap_auth_data_t *d = container_of(t, typeof(*d), timeout); - log_ppp_warn("pap: timeout\n"); + if (conf_ppp_verbose) + log_ppp_warn("pap: timeout\n"); + auth_failed(d->ppp); } @@ -132,36 +134,38 @@ static int lcp_recv_conf_req(struct ppp_t *ppp, struct auth_data_t *d, uint8_t * static void pap_send_ack(struct pap_auth_data_t *p, int id) { uint8_t buf[128]; - struct pap_ack_t *msg=(struct pap_ack_t*)buf; - msg->hdr.proto=htons(PPP_PAP); - msg->hdr.code=PAP_ACK; - msg->hdr.id=id; - msg->hdr.len=htons(HDR_LEN+1+sizeof(MSG_SUCCESSED)-1); - msg->msg_len=sizeof(MSG_SUCCESSED)-1; - memcpy(msg->msg,MSG_SUCCESSED,sizeof(MSG_SUCCESSED)); + struct pap_ack_t *msg = (struct pap_ack_t*)buf; + msg->hdr.proto = htons(PPP_PAP); + msg->hdr.code = PAP_ACK; + msg->hdr.id = id; + msg->hdr.len = htons(HDR_LEN + 1 + sizeof(MSG_SUCCESSED) - 1); + msg->msg_len = sizeof(MSG_SUCCESSED) - 1; + memcpy(msg->msg, MSG_SUCCESSED, sizeof(MSG_SUCCESSED)); - log_ppp_debug("send [PAP AuthAck id=%x \"%s\"]\n",id,MSG_SUCCESSED); + if (conf_ppp_verbose) + log_ppp_info("send [PAP AuthAck id=%x \"%s\"]\n", id, MSG_SUCCESSED); - ppp_chan_send(p->ppp,msg,ntohs(msg->hdr.len)+2); + ppp_chan_send(p->ppp, msg, ntohs(msg->hdr.len) + 2); } static void pap_send_nak(struct pap_auth_data_t *p, int id) { uint8_t buf[128]; - struct pap_ack_t *msg=(struct pap_ack_t*)buf; - msg->hdr.proto=htons(PPP_PAP); - msg->hdr.code=PAP_NAK; - msg->hdr.id=id; - msg->hdr.len=htons(HDR_LEN+1+sizeof(MSG_FAILED)-1); - msg->msg_len=sizeof(MSG_FAILED)-1; - memcpy(msg->msg,MSG_FAILED,sizeof(MSG_FAILED)); + struct pap_ack_t *msg = (struct pap_ack_t*)buf; + msg->hdr.proto = htons(PPP_PAP); + msg->hdr.code = PAP_NAK; + msg->hdr.id = id; + msg->hdr.len = htons(HDR_LEN + 1 + sizeof(MSG_FAILED) - 1); + msg->msg_len = sizeof(MSG_FAILED) - 1; + memcpy(msg->msg, MSG_FAILED, sizeof(MSG_FAILED)); - log_ppp_debug("send [PAP AuthNak id=%x \"%s\"]\n",id,MSG_FAILED); + if (conf_ppp_verbose) + log_ppp_info("send [PAP AuthNak id=%x \"%s\"]\n", id, MSG_FAILED); - ppp_chan_send(p->ppp,msg,ntohs(msg->hdr.len)+2); + ppp_chan_send(p->ppp, msg, ntohs(msg->hdr.len) + 2); } -static int pap_recv_req(struct pap_auth_data_t *p,struct pap_hdr_t *hdr) +static int pap_recv_req(struct pap_auth_data_t *p, struct pap_hdr_t *hdr) { int ret, r; char *peer_id; @@ -169,30 +173,29 @@ static int pap_recv_req(struct pap_auth_data_t *p,struct pap_hdr_t *hdr) const char *passwd2; int peer_id_len; int passwd_len; - uint8_t *ptr=(uint8_t*)(hdr+1); + uint8_t *ptr = (uint8_t*)(hdr + 1); if (p->timeout.tpd) triton_timer_del(&p->timeout); - log_ppp_debug("recv [PAP AuthReq id=%x]\n",hdr->id); + if (conf_ppp_verbose) + log_ppp_info("recv [PAP AuthReq id=%x]\n", hdr->id); - peer_id_len=*(uint8_t*)ptr; ptr++; - if (peer_id_len>ntohs(hdr->len)-sizeof(*hdr)+2-1) - { + peer_id_len = *(uint8_t*)ptr; ptr++; + if (peer_id_len > ntohs(hdr->len) - sizeof(*hdr) + 2 - 1) { log_ppp_warn("PAP: short packet received\n"); return -1; } - peer_id=(char*)ptr; ptr+=peer_id_len; + peer_id = (char*)ptr; ptr += peer_id_len; - passwd_len=*(uint8_t*)ptr; ptr++; - if (passwd_len>ntohs(hdr->len)-sizeof(*hdr)+2-2-peer_id_len) - { + passwd_len = *(uint8_t*)ptr; ptr++; + if (passwd_len > ntohs(hdr->len) - sizeof(*hdr ) + 2 - 2 - peer_id_len) { log_ppp_warn("PAP: short packet received\n"); return -1; } - peer_id=_strndup((const char*)peer_id,peer_id_len); - passwd=_strndup((const char*)ptr,passwd_len); + peer_id = _strndup((const char*)peer_id, peer_id_len); + passwd = _strndup((const char*)ptr, passwd_len); r = pwdb_check(p->ppp, peer_id, PPP_PAP, passwd); if (r == PWDB_NO_IMPL) { @@ -203,7 +206,8 @@ static int pap_recv_req(struct pap_auth_data_t *p,struct pap_hdr_t *hdr) r = PWDB_SUCCESS; } if (r == PWDB_DENIED) { - log_ppp_warn("PAP: authentication error\n"); + if (conf_ppp_verbose) + log_ppp_warn("PAP: authentication error\n"); pap_send_nak(p, hdr->id); if (p->started) ppp_terminate(p->ppp, 0); @@ -227,18 +231,17 @@ static int pap_recv_req(struct pap_auth_data_t *p,struct pap_hdr_t *hdr) static void pap_recv(struct ppp_handler_t *h) { - struct pap_auth_data_t *d=container_of(h,typeof(*d),h); - struct pap_hdr_t *hdr=(struct pap_hdr_t *)d->ppp->chan_buf; + struct pap_auth_data_t *d = container_of(h, typeof(*d), h); + struct pap_hdr_t *hdr = (struct pap_hdr_t *)d->ppp->chan_buf; - if (d->ppp->chan_buf_size<sizeof(*hdr) || ntohs(hdr->len)<HDR_LEN || ntohs(hdr->len)<d->ppp->chan_buf_size-2) - { + if (d->ppp->chan_buf_size < sizeof(*hdr) || ntohs(hdr->len) < HDR_LEN || ntohs(hdr->len) < d->ppp->chan_buf_size - 2) { log_ppp_warn("PAP: short packet received\n"); return; } - if (hdr->code==PAP_REQ) pap_recv_req(d,hdr); - else - { + if (hdr->code == PAP_REQ) + pap_recv_req(d, hdr); + else { log_ppp_warn("PAP: unknown code received %x\n",hdr->code); } } diff --git a/accel-pptpd/ctrl/pptp.c b/accel-pptpd/ctrl/pptp.c index 2c3f73c..4f1146b 100644 --- a/accel-pptpd/ctrl/pptp.c +++ b/accel-pptpd/ctrl/pptp.c @@ -84,6 +84,9 @@ static void disconnect(struct pptp_conn_t *conn) triton_event_fire(EV_CTRL_FINISHED, &conn->ppp); + if (conf_verbose) + log_ppp_info("disconnected\n"); + triton_context_unregister(&conn->ctx); if (conn->ppp.chan_name) @@ -109,9 +112,11 @@ static int post_msg(struct pptp_conn_t *conn, void *buf, int size) if (errno == EINTR || errno == EAGAIN) n = 0; else { - if (errno != EPIPE) - log_ppp_debug("pptp: write: %s\n", strerror(errno)); - return -1; + if (errno != EPIPE) { + if (conf_verbose) + log_ppp_info("pptp: write: %s\n", strerror(errno)); + return -1; + } } } @@ -461,7 +466,8 @@ static int pptp_read(struct triton_md_handler_t *h) goto drop; } if (n == 0) { - log_ppp_debug("pptp: disconnect by peer\n"); + if (conf_verbose) + log_ppp_info("pptp: disconnect by peer\n"); goto drop; } conn->in_size += n; @@ -507,8 +513,10 @@ static int pptp_write(struct triton_md_handler_t *h) if (errno == EAGAIN) n = 0; else { - if (errno != EPIPE) - log_ppp_error("pptp:post_msg: %s\n", strerror(errno)); + if (errno != EPIPE) { + if (conf_verbose) + log_ppp_info("pptp: post_msg: %s\n", strerror(errno)); + } disconnect(conn); return 1; } @@ -552,14 +560,14 @@ static void pptp_close(struct triton_context_t *ctx) } static void ppp_started(struct ppp_t *ppp) { - log_ppp_debug("ppp_started\n"); + log_ppp_debug("pptp: ppp started\n"); } static void ppp_finished(struct ppp_t *ppp) { struct pptp_conn_t *conn = container_of(ppp, typeof(*conn), ppp); if (conn->state != STATE_CLOSE) { - log_ppp_debug("ppp_finished\n"); + log_ppp_debug("pptp: ppp finished\n"); conn->state = STATE_CLOSE; if (send_pptp_call_disconnect_notify(conn, 3)) @@ -629,6 +637,7 @@ static int pptp_connect(struct triton_md_handler_t *h) conn->ctrl.started = ppp_started; conn->ctrl.finished = ppp_finished; conn->ctrl.max_mtu = PPTP_MAX_MTU; + conn->ctrl.name = "pptp"; conn->ctrl.calling_station_id = _malloc(17); conn->ctrl.called_station_id = _malloc(17); @@ -640,8 +649,6 @@ static int pptp_connect(struct triton_md_handler_t *h) conn->ppp.ctrl = &conn->ctrl; triton_context_register(&conn->ctx, &conn->ppp); - conn->ctx.fname=__FILE__; - conn->ctx.line=__LINE__; triton_md_register_handler(&conn->ctx, &conn->hnd); triton_md_enable_handler(&conn->hnd,MD_MODE_READ); triton_timer_add(&conn->ctx, &conn->timeout_timer, 0); diff --git a/accel-pptpd/log.c b/accel-pptpd/log.c index e942686..476c077 100644 --- a/accel-pptpd/log.c +++ b/accel-pptpd/log.c @@ -425,6 +425,10 @@ static void __init log_init(void) .sa_handler = sighup, }; + opt = conf_get_opt("log", "level"); + if (opt && atoi(opt) >= 0) + log_level = atoi(opt); + opt = conf_get_opt("log", "log-emerg"); if (opt) { emerg_file = fopen(opt, "a"); 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;i<size;i++) printf("%x ",buf[i]); printf("\n"); -} +}*/ int __export ppp_chan_send(struct ppp_t *ppp, void *data, int size) { @@ -217,9 +210,9 @@ int __export ppp_chan_send(struct ppp_t *ppp, void *data, int size) //printf("ppp_chan_send: "); //print_buf((uint8_t*)data,size); - n=write(ppp->chan_fd,data,size); - if (n<size) - log_ppp_error("ppp_chan_send: short write %i, excpected %i\n",n,size); + n = write(ppp->chan_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 (n<size) + n=write(ppp->unit_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 (order<n->order) - { - 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("<auth %02x>",ntohs(opt16->val)); + print("<auth %02x>", 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("<auth %s>",d->h->name); + print("<auth %s>", 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; i<ropt->len; 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_size<PPP_HEADERLEN+2) - { + if (ccp->ppp->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_HEADERLEN) - { + hdr = (struct ccp_hdr_t *)ccp->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; i<ropt->len; 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 (r<ret) ret=r; + if (conf_ppp_verbose) + log_ppp_info("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) { + 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_size<PPP_HEADERLEN+2) - { + if (ipcp->ppp->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_HEADERLEN) - { + hdr = (struct ipcp_hdr_t *)ipcp->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; i<ropt->len; 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 (r<ret) ret=r; + list_for_each_entry(lopt, &lcp->options, 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 (r<ret) + ret = r; break; } } - if (!ropt->lopt) - { - 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 <magic %x>]\n",lcp->fsm.recv_id,magic); + if (conf_ppp_verbose) + log_ppp_info("recv [LCP EchoRep id=%x <magic %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 <magic %x>]\n", hdr->id, magic); + if (conf_ppp_verbose) + log_ppp_info("send [LCP EchoRep id=%x <magic %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 <magic %x>]\n", msg.hdr.id, msg.magic); + if (conf_ppp_verbose) + log_ppp_info("send [LCP EchoReq id=%x <magic %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_size<PPP_HEADERLEN+2) - { + if (lcp->ppp->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_HEADERLEN) - { + hdr = (struct lcp_hdr_t *)lcp->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 <magic %x>]\n",hdr->id, *(uint32_t*)(hdr + 1)); + if (conf_ppp_verbose) + log_ppp_info("recv [LCP EchoReq id=%x <magic %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); - } + diff --git a/accel-pptpd/radius/acct.c b/accel-pptpd/radius/acct.c index 987b22b..a8346ed 100644 --- a/accel-pptpd/radius/acct.c +++ b/accel-pptpd/radius/acct.c @@ -71,8 +71,8 @@ static int rad_acct_read(struct triton_md_handler_t *h) return 0; if (conf_verbose) { - log_ppp_debug("recv "); - rad_packet_print(req->reply, log_ppp_debug); + log_ppp_info("recv "); + rad_packet_print(req->reply, log_ppp_info); } if (req->reply->code != CODE_ACCOUNTING_RESPONSE || req->reply->id != req->pack->id) { diff --git a/accel-pptpd/radius/dm_coa.c b/accel-pptpd/radius/dm_coa.c index d94596f..e034321 100644 --- a/accel-pptpd/radius/dm_coa.c +++ b/accel-pptpd/radius/dm_coa.c @@ -77,8 +77,8 @@ static int dm_coa_send_ack(int fd, struct rad_packet_t *req, struct sockaddr_in dm_coa_set_RA(reply, conf_dm_coa_secret); if (conf_verbose) { - log_ppp_debug("send "); - rad_packet_print(reply, log_ppp_debug); + log_ppp_info("send "); + rad_packet_print(reply, log_ppp_info); } rad_packet_send(reply, fd, addr); @@ -112,8 +112,8 @@ static int dm_coa_send_nak(int fd, struct rad_packet_t *req, struct sockaddr_in dm_coa_set_RA(reply, conf_dm_coa_secret); if (conf_verbose) { - log_ppp_debug("send "); - rad_packet_print(reply, log_ppp_debug); + log_ppp_info("send "); + rad_packet_print(reply, log_ppp_info); } rad_packet_send(reply, fd, addr); @@ -127,8 +127,8 @@ static int dm_coa_send_nak(int fd, struct rad_packet_t *req, struct sockaddr_in static void disconnect_request(struct radius_pd_t *rpd) { if (conf_verbose) { - log_ppp_debug("recv "); - rad_packet_print(rpd->dm_coa_req, log_ppp_debug); + log_ppp_info("recv "); + rad_packet_print(rpd->dm_coa_req, log_ppp_info); } dm_coa_send_ack(serv.hnd.fd, rpd->dm_coa_req, &rpd->dm_coa_addr); @@ -147,8 +147,8 @@ static void coa_request(struct radius_pd_t *rpd) }; if (conf_verbose) { - log_ppp_debug("recv "); - rad_packet_print(rpd->dm_coa_req, log_ppp_debug); + log_ppp_info("recv "); + rad_packet_print(rpd->dm_coa_req, log_ppp_info); } triton_event_fire(EV_RADIUS_COA, &ev); diff --git a/accel-pptpd/radius/req.c b/accel-pptpd/radius/req.c index 76b7ba3..bdd02b9 100644 --- a/accel-pptpd/radius/req.c +++ b/accel-pptpd/radius/req.c @@ -171,8 +171,8 @@ int rad_req_send(struct rad_req_t *req) goto out_err; if (conf_verbose) { - log_ppp_debug("send "); - rad_packet_print(req->pack, log_ppp_debug); + log_ppp_info("send "); + rad_packet_print(req->pack, log_ppp_info); } rad_packet_send(req->pack, req->hnd.fd, NULL); @@ -215,8 +215,6 @@ int rad_req_wait(struct rad_req_t *req, int timeout) req->timeout.expire = rad_req_timeout; triton_context_register(&req->ctx, req->rpd->ppp); - req->ctx.fname=__FILE__; - req->ctx.line=__LINE__; triton_md_register_handler(&req->ctx, &req->hnd); triton_md_enable_handler(&req->hnd, MD_MODE_READ); @@ -228,8 +226,8 @@ int rad_req_wait(struct rad_req_t *req, int timeout) triton_context_schedule(req->rpd->ppp->ctrl->ctx); if (conf_verbose && req->reply) { - log_ppp_debug("recv "); - rad_packet_print(req->reply, log_ppp_debug); + log_ppp_info("recv "); + rad_packet_print(req->reply, log_ppp_info); } return 0; } diff --git a/accel-pptpd/triton/triton.c b/accel-pptpd/triton/triton.c index c420532..b2aaa7b 100644 --- a/accel-pptpd/triton/triton.c +++ b/accel-pptpd/triton/triton.c @@ -268,15 +268,6 @@ int __export triton_context_register(struct triton_context_t *ud, void *bf_arg) return 0; } -void __export triton_context_print() -{ - struct _triton_context_t *ctx; - - list_for_each_entry(ctx, &ctx_list, entry) - if (ctx->ud) - printf("%s:%i\n", ctx->ud->fname, ctx->ud->line); -} - void __export triton_context_unregister(struct triton_context_t *ud) { struct _triton_context_t *ctx = (struct _triton_context_t *)ud->tpd; diff --git a/accel-pptpd/triton/triton.h b/accel-pptpd/triton/triton.h index 6809df0..4b4d9c4 100644 --- a/accel-pptpd/triton/triton.h +++ b/accel-pptpd/triton/triton.h @@ -9,8 +9,6 @@ struct triton_context_t { const void *tpd; // triton private data, don't touch - const char *fname; - int line; void (*close)(struct triton_context_t*); void (*free)(struct triton_context_t*); void (*before_switch)(struct triton_context_t *ctx, void *arg); |