summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-09-03 17:08:41 +0400
committerKozlov Dmitry <dima@server>2010-09-03 17:08:41 +0400
commit9d6cabeeff53b574d9d3a9ceede962f452366747 (patch)
tree8e0013eb69294b699a45bc502ae75f3b3c30055d
parentd00c2d1e3afc883683b3c40b6fbb116c3746b8d0 (diff)
downloadaccel-ppp-9d6cabeeff53b574d9d3a9ceede962f452366747.tar.gz
accel-ppp-9d6cabeeff53b574d9d3a9ceede962f452366747.zip
lcp: implemented configure/terminate timeouts
-rw-r--r--accel-pptpd/ppp_fsm.c143
-rw-r--r--accel-pptpd/ppp_fsm.h2
-rw-r--r--accel-pptpd/ppp_lcp.c30
3 files changed, 114 insertions, 61 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);
+}
diff --git a/accel-pptpd/ppp_fsm.h b/accel-pptpd/ppp_fsm.h
index eddafcfd..bc958fe9 100644
--- a/accel-pptpd/ppp_fsm.h
+++ b/accel-pptpd/ppp_fsm.h
@@ -27,6 +27,7 @@ struct ppp_fsm_t
int max_terminate;
int max_configure;
int max_failure;
+ int timeout;
int id;
int recv_id;
@@ -43,6 +44,7 @@ struct ppp_fsm_t
};
void ppp_fsm_init(struct ppp_fsm_t*);
+void ppp_fsm_free(struct ppp_fsm_t*);
void ppp_fsm_lower_up(struct ppp_fsm_t*);
void ppp_fsm_lower_down(struct ppp_fsm_t*);
diff --git a/accel-pptpd/ppp_lcp.c b/accel-pptpd/ppp_lcp.c
index d1c8707d..6c5fd189 100644
--- a/accel-pptpd/ppp_lcp.c
+++ b/accel-pptpd/ppp_lcp.c
@@ -20,6 +20,9 @@ struct recv_opt_t
struct lcp_option_t *lopt;
};
+static int conf_echo_interval = 0;
+static int conf_echo_failure = 3;
+
static LIST_HEAD(option_handlers);
static void lcp_layer_up(struct ppp_fsm_t*);
@@ -123,6 +126,7 @@ void lcp_layer_free(struct ppp_layer_data_t *ld)
stop_echo(lcp);
ppp_unregister_handler(lcp->ppp,&lcp->hnd);
lcp_options_free(lcp);
+ ppp_fsm_free(&lcp->fsm);
free(lcp);
}
@@ -515,19 +519,8 @@ static void send_echo_request(struct triton_timer_t *t)
static void start_echo(struct ppp_lcp_t *lcp)
{
- char *opt;
-
- opt = conf_get_opt("lcp","echo-failure");
- if (!opt || atoi(opt) <= 0)
- return;
-
- lcp->echo_failure = atoi(opt);
-
- opt = conf_get_opt("lcp","echo-interval");
- if (!opt || atoi(opt) <= 0)
- return;
-
- lcp->echo_interval = atoi(opt);
+ lcp->echo_interval = conf_echo_interval;
+ lcp->echo_failure = conf_echo_failure;
lcp->echo_timer.period = lcp->echo_interval * 1000;
lcp->echo_timer.expire = send_echo_request;
@@ -650,5 +643,16 @@ static struct ppp_layer_t lcp_layer=
static void __init lcp_init(void)
{
+ char *opt;
+
ppp_register_layer("lcp",&lcp_layer);
+
+ opt = conf_get_opt("lcp", "echo-interval");
+ if (opt && atoi(opt) > 0)
+ conf_echo_interval = atoi(opt);
+
+ opt = conf_get_opt("lcp", "echo-failure");
+ if (opt && atoi(opt) > 0)
+ conf_echo_failure = atoi(opt);
+
}