diff options
Diffstat (limited to 'accel-pptpd/ppp_fsm.c')
-rw-r--r-- | accel-pptpd/ppp_fsm.c | 143 |
1 files changed, 95 insertions, 48 deletions
diff --git a/accel-pptpd/ppp_fsm.c b/accel-pptpd/ppp_fsm.c index 72a42d0e..c2d00dc6 100644 --- a/accel-pptpd/ppp_fsm.c +++ b/accel-pptpd/ppp_fsm.c @@ -1,39 +1,41 @@ -/* -* C Implementation: ppp_fsm -* -* Description: -* -* -* Author: <xeb@mail.ru>, (C) 2009 -* -* Copyright: See COPYING file that comes with this distribution -* -*/ - #include <arpa/inet.h> +#include <stdlib.h> #include "triton/triton.h" + #include "ppp.h" #include "ppp_fsm.h" #include "ppp_lcp.h" #include "log.h" +static int conf_max_terminate = 2; +static int conf_max_configure = 5; +static int conf_max_failure = 5; +static int conf_timeout = 3; + void send_term_req(struct ppp_fsm_t *layer); void send_term_ack(struct ppp_fsm_t *layer); void send_echo_reply(struct ppp_fsm_t *layer); static void init_req_counter(struct ppp_fsm_t *layer,int timeout); static void zero_req_counter(struct ppp_fsm_t *layer); -static int restart_timer_func(struct triton_timer_t*t); +static void restart_timer_func(struct triton_timer_t *t); +static void stop_timer(struct ppp_fsm_t *fsm); void ppp_fsm_init(struct ppp_fsm_t *layer) { - layer->fsm_state=FSM_Initial; - //layer->restart_timer.active=0; - layer->restart_counter=0; - layer->max_terminate=2; - layer->max_configure=10; - layer->max_failure=5; + layer->fsm_state = FSM_Initial; + layer->restart_timer.expire = restart_timer_func; + layer->restart_counter = 0; + + layer->max_terminate = conf_max_terminate; + layer->max_configure = conf_max_configure; + layer->max_failure = conf_max_failure; + layer->timeout = conf_timeout; +} +void ppp_fsm_free(struct ppp_fsm_t *layer) +{ + stop_timer(layer); } void ppp_fsm_lower_up(struct ppp_fsm_t *layer) @@ -46,6 +48,7 @@ void ppp_fsm_lower_up(struct ppp_fsm_t *layer) case FSM_Starting: //if (layer->init_req_cnt) layer->init_req_cnt(layer); init_req_counter(layer,layer->max_configure); + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); layer->fsm_state=FSM_Req_Sent; break; @@ -94,6 +97,7 @@ void ppp_fsm_open(struct ppp_fsm_t *layer) case FSM_Closed: //if (layer->init_req_cnt) layer->init_req_cnt(layer); init_req_counter(layer,layer->max_configure); + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); layer->fsm_state=FSM_Req_Sent; break; @@ -150,6 +154,7 @@ void ppp_fsm_timeout0(struct ppp_fsm_t *layer) layer->fsm_state=FSM_Req_Sent; case FSM_Req_Sent: case FSM_Ack_Sent: + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); break; default: @@ -162,16 +167,19 @@ void ppp_fsm_timeout1(struct ppp_fsm_t *layer) switch(layer->fsm_state) { case FSM_Closing: + stop_timer(layer); if (layer->layer_finished) layer->layer_finished(layer); layer->fsm_state=FSM_Closed; break; case FSM_Stopping: + stop_timer(layer); if (layer->layer_finished) layer->layer_finished(layer); layer->fsm_state=FSM_Stopped; break; case FSM_Ack_Rcvd: case FSM_Req_Sent: case FSM_Ack_Sent: + stop_timer(layer); if (layer->layer_finished) layer->layer_finished(layer); layer->fsm_state=FSM_Stopped; break; @@ -190,6 +198,7 @@ void ppp_fsm_recv_conf_req_ack(struct ppp_fsm_t *layer) case FSM_Stopped: //if (layer->init_req_cnt) layer->init_req_cnt(layer); init_req_counter(layer,layer->max_configure); + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); case FSM_Req_Sent: case FSM_Ack_Sent: @@ -198,12 +207,13 @@ void ppp_fsm_recv_conf_req_ack(struct ppp_fsm_t *layer) break; case FSM_Ack_Rcvd: if (layer->send_conf_ack) layer->send_conf_ack(layer); - //tlu + stop_timer(layer); if (layer->layer_up) layer->layer_up(layer); layer->fsm_state=FSM_Opened; break; case FSM_Opened: if (layer->layer_down) layer->layer_down(layer); + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); if (layer->send_conf_ack) layer->send_conf_ack(layer); layer->fsm_state=FSM_Ack_Sent; @@ -223,6 +233,7 @@ void ppp_fsm_recv_conf_req_nak(struct ppp_fsm_t *layer) case FSM_Stopped: //if (layer->init_req_cnt) layer->init_req_cnt(layer); init_req_counter(layer,layer->max_configure); + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); case FSM_Ack_Sent: if (layer->send_conf_nak) layer->send_conf_nak(layer); @@ -234,6 +245,7 @@ void ppp_fsm_recv_conf_req_nak(struct ppp_fsm_t *layer) break; case FSM_Opened: if (layer->layer_down) layer->layer_down(layer); + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); if (layer->send_conf_nak) layer->send_conf_nak(layer); layer->fsm_state=FSM_Req_Sent; @@ -253,6 +265,7 @@ void ppp_fsm_recv_conf_req_rej(struct ppp_fsm_t *layer) case FSM_Stopped: //if (layer->init_req_cnt) layer->init_req_cnt(layer); init_req_counter(layer,layer->max_configure); + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); case FSM_Ack_Sent: if (layer->send_conf_rej) layer->send_conf_rej(layer); @@ -264,6 +277,7 @@ void ppp_fsm_recv_conf_req_rej(struct ppp_fsm_t *layer) break; case FSM_Opened: if (layer->layer_down) layer->layer_down(layer); + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); if (layer->send_conf_rej) layer->send_conf_rej(layer); layer->fsm_state=FSM_Req_Sent; @@ -287,18 +301,21 @@ void ppp_fsm_recv_conf_ack(struct ppp_fsm_t *layer) layer->fsm_state=FSM_Ack_Rcvd; break; case FSM_Ack_Rcvd: + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); layer->fsm_state=FSM_Req_Sent; break; case FSM_Ack_Sent: //if (layer->init_req_cnt) layer->init_req_cnt(layer); - init_req_counter(layer,layer->max_configure); + //init_req_counter(layer,layer->max_configure); //tlu + stop_timer(layer); if (layer->layer_up) layer->layer_up(layer); layer->fsm_state=FSM_Opened; break; case FSM_Opened: if (layer->layer_down) layer->layer_down(layer); + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); layer->fsm_state=FSM_Req_Sent; default: @@ -317,19 +334,23 @@ void ppp_fsm_recv_conf_rej(struct ppp_fsm_t *layer) case FSM_Req_Sent: //if (layer->init_req_cnt) layer->init_req_cnt(layer); init_req_counter(layer,layer->max_failure); + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); break; case FSM_Ack_Rcvd: + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); layer->fsm_state=FSM_Req_Sent; break; case FSM_Ack_Sent: //if (layer->init_req_cnt) layer->init_req_cnt(layer); init_req_counter(layer,layer->max_configure); + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); break; case FSM_Opened: if (layer->layer_down) layer->layer_down(layer); + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); layer->fsm_state=FSM_Req_Sent; break; @@ -379,6 +400,7 @@ void ppp_fsm_recv_term_ack(struct ppp_fsm_t *layer) break; case FSM_Opened: if (layer->layer_down) layer->layer_down(layer); + --layer->restart_counter; if (layer->send_conf_req) layer->send_conf_req(layer); layer->fsm_state=FSM_Req_Sent; break; @@ -431,57 +453,82 @@ void ppp_fsm_recv_code_rej_bad(struct ppp_fsm_t *layer) void send_term_req(struct ppp_fsm_t *layer) { - struct lcp_hdr_t hdr={ - .proto=htons(PPP_LCP), - .code=TERMREQ, - .id=++layer->id, - .len=htons(4), + struct lcp_hdr_t hdr = { + .proto = htons(PPP_LCP), + .code = TERMREQ, + .id = ++layer->id, + .len = htons(4), }; log_debug("send [LCP TermReq id=%i \"\"]\n",hdr.id); - ppp_chan_send(layer->ppp,&hdr,6); + --layer->restart_counter; + ppp_chan_send(layer->ppp, &hdr, 6); } void send_term_ack(struct ppp_fsm_t *layer) { - struct lcp_hdr_t hdr={ - .proto=htons(PPP_LCP), - .code=TERMACK, - .id=layer->recv_id, - .len=htons(4), + struct lcp_hdr_t hdr = { + .proto = htons(PPP_LCP), + .code = TERMACK, + .id = layer->recv_id, + .len = htons(4), }; - log_debug("send [LCP TermAck id=%i \"\"]\n",hdr.id); + log_debug("send [LCP TermAck id=%i \"\"]\n", hdr.id); - ppp_chan_send(layer->ppp,&hdr,6); + ppp_chan_send(layer->ppp, &hdr, 6); } +static void stop_timer(struct ppp_fsm_t *fsm) +{ + if (fsm->restart_timer.period) { + fsm->restart_timer.period = 0; + triton_timer_del(&fsm->restart_timer); + } +} static void init_req_counter(struct ppp_fsm_t *layer,int timeout) { - //triton_timer_del(&layer->restart_timer); layer->restart_timer.expire_tv.tv_sec=0; - //triton_timer_add(&layer->restart_timer); - layer->restart_counter=timeout; + layer->restart_counter = timeout; + + if (!layer->restart_timer.period) { + layer->restart_timer.period = layer->timeout * 1000; + triton_timer_add(layer->ppp->ctrl->ctx, &layer->restart_timer, 0); + } } static void zero_req_counter(struct ppp_fsm_t *layer) { - //triton_timer_del(&layer->restart_timer); layer->restart_timer.expire_tv.tv_sec=0; - //triton_timer_add(&layer->restart_timer); layer->restart_counter=0; } -/*static int restart_timer_func(struct triton_timer_t*t) +static void restart_timer_func(struct triton_timer_t *t) { - struct ppp_fsm_t *layer=(struct ppp_fsm_t *)t->pd; + struct ppp_fsm_t *layer = container_of(t, typeof(*layer), restart_timer); - if (layer->restart_counter) - { + if (layer->restart_counter>0) ppp_fsm_timeout0(layer); - return 1; - } + else + ppp_fsm_timeout1(layer); +} - ppp_fsm_timeout1(layer); - return 0; -}*/ +void __init fsm_init(void) +{ + char *opt; + + opt = conf_get_opt("lcp", "max-terminate"); + if (opt && atoi(opt) > 0) + conf_max_terminate = atoi(opt); + + opt = conf_get_opt("lcp", "max-configure"); + if (opt && atoi(opt) > 0) + conf_max_configure = atoi(opt); + opt = conf_get_opt("lcp", "max-failure"); + if (opt && atoi(opt) > 0) + conf_max_failure = atoi(opt); + + opt = conf_get_opt("lcp", "timeout"); + if (opt && atoi(opt) > 0) + conf_timeout = atoi(opt); +} |