summaryrefslogtreecommitdiff
path: root/accel-pppd/ppp
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2011-05-16 18:04:28 +0400
committerKozlov Dmitry <dima@server>2011-05-16 18:04:28 +0400
commit23a958deec775a74d2ff9d0d31ef208c47516a4b (patch)
tree34eb7ae83c3093e8e434fb4fc9cc6e2ba33a235f /accel-pppd/ppp
parentd2cb39985cd33f5678cad3e68b69cca51894bd58 (diff)
downloadaccel-ppp-23a958deec775a74d2ff9d0d31ef208c47516a4b.tar.gz
accel-ppp-23a958deec775a74d2ff9d0d31ef208c47516a4b.zip
ppp: better handling for lost last acknowledge packet
Diffstat (limited to 'accel-pppd/ppp')
-rw-r--r--accel-pppd/ppp/ipcp_opt_ipaddr.c4
-rw-r--r--accel-pppd/ppp/ppp_ccp.c29
-rw-r--r--accel-pppd/ppp/ppp_ipcp.c50
-rw-r--r--accel-pppd/ppp/ppp_ipcp.h2
4 files changed, 38 insertions, 47 deletions
diff --git a/accel-pppd/ppp/ipcp_opt_ipaddr.c b/accel-pppd/ppp/ipcp_opt_ipaddr.c
index 26d72d44..b2a74caf 100644
--- a/accel-pppd/ppp/ipcp_opt_ipaddr.c
+++ b/accel-pppd/ppp/ipcp_opt_ipaddr.c
@@ -133,7 +133,7 @@ static int ipaddr_recv_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *o
if (ipaddr_opt->ip->peer_addr == opt32->val) {
ipcp->ppp->ipaddr = ipaddr_opt->ip->addr;
ipcp->ppp->peer_ipaddr = ipaddr_opt->ip->peer_addr;
- ipcp->delay_ack = 1;
+ ipcp->delay_ack = !ipcp->started;
return IPCP_OPT_ACK;
}
@@ -191,8 +191,6 @@ static void if_up(struct ppp_t *ppp)
if (ioctl(ppp->unit_fd, PPPIOCSNPMODE, &np))
log_ppp_error("ipcp: failed to set NP mode: %s\n", strerror(errno));
-
- ipcp_send_ack(ppp);
}
static void ipaddr_print(void (*print)(const char *fmt,...),struct ipcp_option_t *opt, uint8_t *ptr)
diff --git a/accel-pppd/ppp/ppp_ccp.c b/accel-pppd/ppp/ppp_ccp.c
index d40d21b1..a8b813d5 100644
--- a/accel-pppd/ppp/ppp_ccp.c
+++ b/accel-pppd/ppp/ppp_ccp.c
@@ -609,7 +609,7 @@ static void ccp_recv(struct ppp_handler_t*h)
struct ppp_ccp_t *ccp = container_of(h, typeof(*ccp), hnd);
int r;
- if (ccp->fsm.fsm_state == FSM_Initial || ccp->fsm.fsm_state == FSM_Closed || ccp->fsm.fsm_state == FSM_Opened || ccp->ppp->terminating) {
+ if (ccp->fsm.fsm_state == FSM_Initial || ccp->fsm.fsm_state == FSM_Closed || ccp->ppp->terminating) {
if (conf_ppp_verbose)
log_ppp_warn("CCP: discarding packet\n");
if (ccp->fsm.fsm_state == FSM_Closed || !conf_ccp)
@@ -636,16 +636,23 @@ static void ccp_recv(struct ppp_handler_t*h)
switch(hdr->code) {
case CONFREQ:
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;
- case CCP_OPT_NAK:
- ppp_fsm_recv_conf_req_nak(&ccp->fsm);
- break;
- case CCP_OPT_REJ:
- ppp_fsm_recv_conf_req_rej(&ccp->fsm);
- break;
+ if (ccp->started) {
+ if (r == CCP_OPT_ACK)
+ send_conf_ack(&ccp->fsm);
+ else
+ r = CCP_OPT_FAIL;
+ } else {
+ switch(r) {
+ case CCP_OPT_ACK:
+ ppp_fsm_recv_conf_req_ack(&ccp->fsm);
+ break;
+ case CCP_OPT_NAK:
+ ppp_fsm_recv_conf_req_nak(&ccp->fsm);
+ break;
+ case CCP_OPT_REJ:
+ ppp_fsm_recv_conf_req_rej(&ccp->fsm);
+ break;
+ }
}
ccp_free_conf_req(ccp);
diff --git a/accel-pppd/ppp/ppp_ipcp.c b/accel-pppd/ppp/ppp_ipcp.c
index 8890f2c2..72760d57 100644
--- a/accel-pppd/ppp/ppp_ipcp.c
+++ b/accel-pppd/ppp/ppp_ipcp.c
@@ -61,9 +61,6 @@ static void ipcp_options_free(struct ppp_ipcp_t *ipcp)
list_del(&lopt->entry);
lopt->h->free(ipcp, lopt);
}
-
- if (ipcp->buf)
- _free(ipcp->buf);
}
static struct ppp_layer_data_t *ipcp_layer_init(struct ppp_t *ppp)
@@ -226,10 +223,7 @@ static void send_conf_ack(struct ppp_fsm_t *fsm)
struct ipcp_hdr_t *hdr = (struct ipcp_hdr_t*)ipcp->ppp->buf;
if (ipcp->delay_ack) {
- if (!ipcp->buf) {
- ipcp->buf = _malloc(ntohs(hdr->len) + 2);
- memcpy(ipcp->buf, ipcp->ppp->buf, ntohs(hdr->len) + 2);
- }
+ send_term_ack(fsm);
return;
}
@@ -241,19 +235,6 @@ static void send_conf_ack(struct ppp_fsm_t *fsm)
ppp_unit_send(ipcp->ppp, hdr, ntohs(hdr->len) + 2);
}
-void ipcp_send_ack(struct ppp_t *ppp)
-{
- struct ppp_ipcp_t *ipcp = container_of(ppp_find_layer_data(ppp, &ipcp_layer), typeof(*ipcp), ld);
- struct ipcp_hdr_t *hdr = (struct ipcp_hdr_t*)ipcp->buf;
-
- hdr->code = CONFACK;
-
- if (conf_ppp_verbose)
- log_ppp_info2("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);
@@ -583,7 +564,7 @@ static void ipcp_recv(struct ppp_handler_t*h)
struct ppp_ipcp_t *ipcp = container_of(h, typeof(*ipcp), hnd);
int r;
- if (ipcp->fsm.fsm_state == FSM_Initial || ipcp->fsm.fsm_state == FSM_Closed || ipcp->fsm.fsm_state == FSM_Opened || ipcp->ppp->terminating) {
+ if (ipcp->fsm.fsm_state == FSM_Initial || ipcp->fsm.fsm_state == FSM_Closed || ipcp->ppp->terminating) {
if (conf_ppp_verbose)
log_ppp_warn("IPCP: discarding packet\n");
return;
@@ -612,16 +593,23 @@ static void ipcp_recv(struct ppp_handler_t*h)
ipcp_free_conf_req(ipcp);
return;
}
- switch(r) {
- case IPCP_OPT_ACK:
- ppp_fsm_recv_conf_req_ack(&ipcp->fsm);
- break;
- case IPCP_OPT_NAK:
- ppp_fsm_recv_conf_req_nak(&ipcp->fsm);
- break;
- case IPCP_OPT_REJ:
- ppp_fsm_recv_conf_req_rej(&ipcp->fsm);
- break;
+ if (ipcp->started) {
+ if (r == IPCP_OPT_ACK)
+ send_conf_ack(&ipcp->fsm);
+ else
+ r = IPCP_OPT_FAIL;
+ } else {
+ switch(r) {
+ case IPCP_OPT_ACK:
+ ppp_fsm_recv_conf_req_ack(&ipcp->fsm);
+ break;
+ case IPCP_OPT_NAK:
+ ppp_fsm_recv_conf_req_nak(&ipcp->fsm);
+ break;
+ case IPCP_OPT_REJ:
+ ppp_fsm_recv_conf_req_rej(&ipcp->fsm);
+ break;
+ }
}
ipcp_free_conf_req(ipcp);
if (r == IPCP_OPT_FAIL)
diff --git a/accel-pppd/ppp/ppp_ipcp.h b/accel-pppd/ppp/ppp_ipcp.h
index 2197edd7..f9554618 100644
--- a/accel-pppd/ppp/ppp_ipcp.h
+++ b/accel-pppd/ppp/ppp_ipcp.h
@@ -82,7 +82,6 @@ struct ppp_ipcp_t
struct ppp_fsm_t fsm;
struct ppp_t *ppp;
struct list_head options;
- void *buf;
struct list_head ropt_list; // last received ConfReq
int ropt_len;
@@ -94,7 +93,6 @@ struct ppp_ipcp_t
int ipcp_option_register(struct ipcp_option_handler_t *h);
struct ipcp_option_t *ipcp_find_option(struct ppp_t *ppp, struct ipcp_option_handler_t *h);
-void ipcp_send_ack(struct ppp_t *);
#endif