phase global variable moved to ppp_control structure

This commit is contained in:
Sylvain Rochet 2012-06-09 15:39:16 +02:00
parent 945f2912a7
commit 42f672d85d
4 changed files with 151 additions and 151 deletions

View File

@ -578,7 +578,7 @@ void start_link(unit)
char *msg; char *msg;
status = EXIT_NEGOTIATION_FAILED; status = EXIT_NEGOTIATION_FAILED;
new_phase(PHASE_SERIALCONN); new_phase(unit, PHASE_SERIALCONN);
hungup = 0; hungup = 0;
devfd = the_channel->connect(); devfd = the_channel->connect();
@ -614,18 +614,18 @@ void start_link(unit)
notice("Starting negotiation on %s", ppp_devnam); notice("Starting negotiation on %s", ppp_devnam);
add_fd(fd_ppp); add_fd(fd_ppp);
new_phase(PHASE_ESTABLISH); new_phase(unit, PHASE_ESTABLISH);
lcp_lowerup(0); lcp_lowerup(0);
return; return;
disconnect: disconnect:
new_phase(PHASE_DISCONNECT); new_phase(unit, PHASE_DISCONNECT);
if (the_channel->disconnect) if (the_channel->disconnect)
the_channel->disconnect(); the_channel->disconnect();
fail: fail:
new_phase(PHASE_DEAD); new_phase(unit, PHASE_DEAD);
if (the_channel->cleanup) if (the_channel->cleanup)
(*the_channel->cleanup)(); (*the_channel->cleanup)();
} }
@ -639,9 +639,10 @@ void
link_terminated(unit) link_terminated(unit)
int unit; int unit;
{ {
if (phase == PHASE_DEAD || phase == PHASE_MASTER) ppp_control *pc = &ppp_control_list[unit];
if (pc->phase == PHASE_DEAD || pc->phase == PHASE_MASTER)
return; return;
new_phase(PHASE_DISCONNECT); new_phase(unit, PHASE_DISCONNECT);
#if 0 /* UNUSED */ #if 0 /* UNUSED */
if (pap_logout_hook) { if (pap_logout_hook) {
@ -660,7 +661,7 @@ link_terminated(unit)
lcp_lowerdown(0); lcp_lowerdown(0);
new_phase(PHASE_DEAD); new_phase(unit, PHASE_DEAD);
ppp_link_terminated(unit); ppp_link_terminated(unit);
#if 0 #if 0
/* /*
@ -702,11 +703,11 @@ link_terminated(unit)
if (doing_multilink && multilink_master) { if (doing_multilink && multilink_master) {
if (!bundle_terminating) if (!bundle_terminating)
new_phase(PHASE_MASTER); new_phase(unit, PHASE_MASTER);
else else
mp_bundle_terminated(); mp_bundle_terminated();
} else } else
new_phase(PHASE_DEAD); new_phase(unit, PHASE_DEAD);
#endif #endif
} }
@ -717,14 +718,15 @@ void
link_down(unit) link_down(unit)
int unit; int unit;
{ {
ppp_control *pc = &ppp_control_list[unit];
#if PPP_NOTIFY #if PPP_NOTIFY
notify(link_down_notifier, 0); notify(link_down_notifier, 0);
#endif /* #if PPP_NOTIFY */ #endif /* #if PPP_NOTIFY */
if (!doing_multilink) { if (!doing_multilink) {
upper_layers_down(unit); upper_layers_down(unit);
if (phase != PHASE_DEAD && phase != PHASE_MASTER) if (pc->phase != PHASE_DEAD && pc->phase != PHASE_MASTER)
new_phase(PHASE_ESTABLISH); new_phase(unit, PHASE_ESTABLISH);
} }
/* XXX if doing_multilink, should do something to stop /* XXX if doing_multilink, should do something to stop
network-layer traffic on the link */ network-layer traffic on the link */
@ -817,7 +819,7 @@ link_established(unit)
} }
#endif /* UNUSED */ #endif /* UNUSED */
new_phase(PHASE_AUTHENTICATE); new_phase(unit, PHASE_AUTHENTICATE);
auth = 0; auth = 0;
#if PPP_SERVER #if PPP_SERVER
#if EAP_SUPPORT #if EAP_SUPPORT
@ -909,7 +911,7 @@ network_phase(unit)
* If we negotiated callback, do it now. * If we negotiated callback, do it now.
*/ */
if (go->neg_cbcp) { if (go->neg_cbcp) {
new_phase(PHASE_CALLBACK); new_phase(unit, PHASE_CALLBACK);
(*cbcp_protent.open)(unit); (*cbcp_protent.open)(unit);
return; return;
} }
@ -943,7 +945,7 @@ start_networks(unit)
int mppe_required; int mppe_required;
#endif /* MPPE */ #endif /* MPPE */
new_phase(PHASE_NETWORK); new_phase(unit, PHASE_NETWORK);
#ifdef HAVE_MULTILINK #ifdef HAVE_MULTILINK
if (multilink) { if (multilink) {
@ -1212,7 +1214,7 @@ np_up(unit, proto)
*/ */
status = EXIT_OK; status = EXIT_OK;
unsuccess = 0; unsuccess = 0;
new_phase(PHASE_RUNNING); new_phase(unit, PHASE_RUNNING);
#if 0 /* UNUSED */ #if 0 /* UNUSED */
if (idle_time_hook != 0) if (idle_time_hook != 0)
@ -1259,7 +1261,7 @@ np_down(unit, proto)
#ifdef MAXOCTETS #ifdef MAXOCTETS
UNTIMEOUT(check_maxoctets, NULL); UNTIMEOUT(check_maxoctets, NULL);
#endif #endif
new_phase(PHASE_NETWORK); new_phase(unit, PHASE_NETWORK);
} }
} }

View File

@ -462,11 +462,12 @@ lcp_close(unit, reason)
int unit; int unit;
char *reason; char *reason;
{ {
ppp_control *pc = &ppp_control_list[unit];
fsm *f = &lcp_fsm[unit]; fsm *f = &lcp_fsm[unit];
int oldstate; int oldstate;
if (phase != PHASE_DEAD && phase != PHASE_MASTER) if (pc->phase != PHASE_DEAD && pc->phase != PHASE_MASTER)
new_phase(PHASE_TERMINATE); new_phase(unit, PHASE_TERMINATE);
if (f->flags & DELAYED_UP) { if (f->flags & DELAYED_UP) {
UNTIMEOUT(lcp_delayed_up, f); UNTIMEOUT(lcp_delayed_up, f);

View File

@ -150,7 +150,6 @@
*/ */
/* FIXME: global variables per PPP session */ /* FIXME: global variables per PPP session */
/* FIXME: clean global variables */ /* FIXME: clean global variables */
int phase; /* where the link is at */
int error_count; /* # of times error() has been called */ int error_count; /* # of times error() has been called */
int unsuccess; /* # unsuccessful connection attempts */ int unsuccess; /* # unsuccessful connection attempts */
int listen_time; /* time to listen first (ms) */ int listen_time; /* time to listen first (ms) */
@ -233,64 +232,6 @@ typedef enum {
#endif #endif
#endif /* PPPOS_SUPPORT */ #endif /* PPPOS_SUPPORT */
typedef struct ppp_control_rx_s {
/** unit number / ppp descriptor */
int pd;
/** the rx file descriptor */
sio_fd_t fd;
/** receive buffer - encoded data is stored here */
#if PPPOS_SUPPORT && PPP_INPROC_OWNTHREAD
u_char rxbuf[PPPOS_RX_BUFSIZE];
#endif /* PPPOS_SUPPORT && PPP_INPROC_OWNTHREAD */
#if PPPOS_SUPPORT
/* The input packet. */
struct pbuf *in_head, *in_tail;
u16_t in_protocol; /* The input protocol code. */
u16_t in_fcs; /* Input Frame Check Sequence value. */
ppp_dev_states in_state; /* The input process state. */
char in_escaped; /* Escape next character. */
ext_accm in_accm; /* Async-Ctl-Char-Map for input. */
#endif /* PPPOS_SUPPORT */
} ppp_control_rx;
/*
* PPP interface control block.
*/
typedef struct ppp_control_s {
ppp_control_rx rx;
char open_flag; /* True when in use. */
#if PPPOE_SUPPORT
struct netif *ethif;
struct pppoe_softc *pppoe_sc;
#endif /* PPPOE_SUPPORT */
int if_up; /* True when the interface is up. */
int err_code; /* Code indicating why interface is down. */
#if PPPOS_SUPPORT
sio_fd_t fd; /* File device ID of port. */
#endif /* PPPOS_SUPPORT */
u16_t mtu; /* Peer's mru */
int pcomp; /* Does peer accept protocol compression? */
int accomp; /* Does peer accept addr/ctl compression? */
u_long last_xmit; /* Time of last transmission. */
#if PPPOS_SUPPORT
ext_accm out_accm; /* Async-Ctl-Char-Map for output. */
#endif /* PPPOS_SUPPORT */
#if PPPOS_SUPPORT && VJ_SUPPORT
int vj_enabled; /* Flag indicating VJ compression enabled. */
struct vjcompress vj_comp; /* Van Jacobson compression header. */
#endif /* PPPOS_SUPPORT && VJ_SUPPORT */
struct netif netif;
struct ppp_addrs addrs;
void (*link_status_cb)(void *ctx, int err_code, void *arg);
void *link_status_ctx;
} ppp_control;
/* Prototypes for procedures local to this file. */ /* Prototypes for procedures local to this file. */
/* FIXME: PPPoE close seem bogus, it was actually not exported at all in the previous port */ /* FIXME: PPPoE close seem bogus, it was actually not exported at all in the previous port */
@ -299,7 +240,7 @@ void ppp_over_ethernet_close(int pd);
#endif /* UNUSED */ #endif /* UNUSED */
static void ppp_start(int pd); /** Initiate LCP open request */ static void ppp_start(int pd); /** Initiate LCP open request */
static void ppp_input(void *arg); static void ppp_input(int unit, void *arg);
#if PPPOS_SUPPORT #if PPPOS_SUPPORT
static void ppp_receive_wakeup(int pd); static void ppp_receive_wakeup(int pd);
@ -329,7 +270,6 @@ static int ppp_write_over_ethernet(int pd, const u_char *s, int n);
/******************************/ /******************************/
/*** PUBLIC DATA STRUCTURES ***/ /*** PUBLIC DATA STRUCTURES ***/
/******************************/ /******************************/
static ppp_control ppp_control_list[NUM_PPP]; /* The PPP interface control blocks. */
/** Input helper struct, must be packed since it is stored to pbuf->payload, /** Input helper struct, must be packed since it is stored to pbuf->payload,
* which might be unaligned. * which might be unaligned.
@ -356,7 +296,6 @@ int ppp_init(void) {
int i; int i;
struct protent *protp; struct protent *protp;
new_phase(PHASE_INITIALIZE);
error_count = 0; error_count = 0;
unsuccess = 0; unsuccess = 0;
listen_time = 0; listen_time = 0;
@ -365,12 +304,7 @@ int ppp_init(void) {
link_stats_valid = 0; link_stats_valid = 0;
#endif /* PPP_STATS_SUPPORT */ #endif /* PPP_STATS_SUPPORT */
/* /* FIXME: Remove that, do a user provided ppp_settings with a ppp_settings init function */
openlog("LWIP-PPP", LOG_PID | LOG_NDELAY, LOG_DAEMON);
setlogmask(LOG_UPTO(LOG_DEBUG));
syslog(LOG_DEBUG, "hello, this is gradator lwIP PPP!");
*/
memset(&ppp_settings, 0, sizeof(ppp_settings)); memset(&ppp_settings, 0, sizeof(ppp_settings));
ppp_settings.usepeerdns = 1; ppp_settings.usepeerdns = 1;
ppp_settings.persist = 1; ppp_settings.persist = 1;
@ -509,18 +443,16 @@ int ppp_over_serial_open(sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void
ppp_control *pc; ppp_control *pc;
int pd; int pd;
if (link_status_cb == NULL) {
/* PPP is single-threaded: without a callback, /* PPP is single-threaded: without a callback,
* there is no way to know when the link is up. */ * there is no way to know when the link is up. */
if (link_status_cb == NULL)
return PPPERR_PARAM; return PPPERR_PARAM;
}
/* Find a free PPP session descriptor. */ /* Find a free PPP session descriptor. */
for (pd = 0; pd < NUM_PPP && ppp_control_list[pd].open_flag != 0; pd++); for (pd = 0; pd < NUM_PPP && ppp_control_list[pd].open_flag != 0; pd++);
if (pd >= NUM_PPP)
return PPPERR_OPEN;
if (pd >= NUM_PPP) {
pd = PPPERR_OPEN;
} else {
pc = &ppp_control_list[pd]; pc = &ppp_control_list[pd];
/* input pbuf left over from last session? */ /* input pbuf left over from last session? */
ppp_free_current_input_packet(&pc->rx); ppp_free_current_input_packet(&pc->rx);
@ -532,6 +464,8 @@ int ppp_over_serial_open(sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void
pc->open_flag = 1; pc->open_flag = 1;
pc->fd = fd; pc->fd = fd;
new_phase(pd, PHASE_INITIALIZE);
#if VJ_SUPPORT #if VJ_SUPPORT
vj_compress_init(&pc->vj_comp); vj_compress_init(&pc->vj_comp);
#endif /* VJ_SUPPORT */ #endif /* VJ_SUPPORT */
@ -554,7 +488,6 @@ int ppp_over_serial_open(sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void
#if PPP_INPROC_OWNTHREAD #if PPP_INPROC_OWNTHREAD
sys_thread_new(PPP_THREAD_NAME, ppp_input_thread, (void*)&pc->rx, PPP_THREAD_STACKSIZE, PPP_THREAD_PRIO); sys_thread_new(PPP_THREAD_NAME, ppp_input_thread, (void*)&pc->rx, PPP_THREAD_STACKSIZE, PPP_THREAD_PRIO);
#endif /* PPP_INPROC_OWNTHREAD */ #endif /* PPP_INPROC_OWNTHREAD */
}
return pd; return pd;
} }
@ -584,22 +517,23 @@ int ppp_over_ethernet_open(struct netif *ethif, const char *service_name, const
LWIP_UNUSED_ARG(service_name); LWIP_UNUSED_ARG(service_name);
LWIP_UNUSED_ARG(concentrator_name); LWIP_UNUSED_ARG(concentrator_name);
if (link_status_cb == NULL) {
/* PPP is single-threaded: without a callback, /* PPP is single-threaded: without a callback,
* there is no way to know when the link is up. */ * there is no way to know when the link is up. */
if (link_status_cb == NULL)
return PPPERR_PARAM; return PPPERR_PARAM;
}
/* Find a free PPP session descriptor. Critical region? */ /* Find a free PPP session descriptor. Critical region? */
for (pd = 0; pd < NUM_PPP && ppp_control_list[pd].open_flag != 0; pd++); for (pd = 0; pd < NUM_PPP && ppp_control_list[pd].open_flag != 0; pd++);
if (pd >= NUM_PPP) { if (pd >= NUM_PPP)
pd = PPPERR_OPEN; pd = PPPERR_OPEN;
} else {
pc = &ppp_control_list[pd]; pc = &ppp_control_list[pd];
memset(pc, 0, sizeof(ppp_control)); memset(pc, 0, sizeof(ppp_control));
pc->open_flag = 1; pc->open_flag = 1;
pc->ethif = ethif; pc->ethif = ethif;
new_phase(pd, PHASE_INITIALIZE);
pc->link_status_cb = link_status_cb; pc->link_status_cb = link_status_cb;
pc->link_status_ctx = link_status_ctx; pc->link_status_ctx = link_status_ctx;
@ -619,8 +553,6 @@ int ppp_over_ethernet_open(struct netif *ethif, const char *service_name, const
} }
pppoe_connect(pc->pppoe_sc, ppp_settings.persist); pppoe_connect(pc->pppoe_sc, ppp_settings.persist);
}
return pd; return pd;
} }
@ -717,7 +649,8 @@ ppp_hup(int pd)
* this is totally stupid to make room for it and then modify the packet directly * this is totally stupid to make room for it and then modify the packet directly
* or it is used in output ? have to find out... * or it is used in output ? have to find out...
*/ */
static void ppp_input(void *arg) { static void ppp_input(int unit, void *arg) {
ppp_control *pc = &ppp_control_list[unit];
struct pbuf *nb = (struct pbuf *)arg; struct pbuf *nb = (struct pbuf *)arg;
u16_t protocol; u16_t protocol;
int pd; int pd;
@ -748,7 +681,7 @@ static void ppp_input(void *arg) {
* Until we get past the authentication phase, toss all packets * Until we get past the authentication phase, toss all packets
* except LCP, LQR and authentication packets. * except LCP, LQR and authentication packets.
*/ */
if (phase <= PHASE_AUTHENTICATE if (pc->phase <= PHASE_AUTHENTICATE
&& !(protocol == PPP_LCP && !(protocol == PPP_LCP
#if LQR_SUPPORT #if LQR_SUPPORT
|| protocol == PPP_LQR || protocol == PPP_LQR
@ -764,7 +697,7 @@ static void ppp_input(void *arg) {
#endif /* EAP_SUPPORT */ #endif /* EAP_SUPPORT */
)) { )) {
dbglog("discarding proto 0x%x in phase %d", dbglog("discarding proto 0x%x in phase %d",
protocol, phase); protocol, pc->phase);
goto drop; goto drop;
} }
@ -1068,7 +1001,7 @@ void ppp_input_over_ethernet(int pd, struct pbuf *pb) {
pih->proto = in_protocol; /* pih->proto is now in host byte order */ pih->proto = in_protocol; /* pih->proto is now in host byte order */
/* Dispatch the packet thereby consuming it. */ /* Dispatch the packet thereby consuming it. */
ppp_input(pb); ppp_input(pd, pb);
return; return;
drop: drop:
@ -1214,7 +1147,7 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *i
} }
/* Check that the link is up. */ /* Check that the link is up. */
if (phase == PHASE_DEAD) { if (pc->phase == PHASE_DEAD) {
PPPDEBUG(LOG_ERR, ("ppp_netif_output[%d]: link not up\n", pd)); PPPDEBUG(LOG_ERR, ("ppp_netif_output[%d]: link not up\n", pd));
LINK_STATS_INC(link.rterr); LINK_STATS_INC(link.rterr);
LINK_STATS_INC(link.drop); LINK_STATS_INC(link.drop);
@ -1962,8 +1895,9 @@ ppp_set_netif_linkcallback(int pd, netif_status_callback_fn link_callback)
/* /*
* new_phase - signal the start of a new phase of pppd's operation. * new_phase - signal the start of a new phase of pppd's operation.
*/ */
void new_phase(int p) { void new_phase(int unit, int p) {
phase = p; ppp_control *pc = &ppp_control_list[unit];
pc->phase = p;
#if PPP_NOTIFY #if PPP_NOTIFY
/* The one willing notify support should add here the code to be notified of phase changes */ /* The one willing notify support should add here the code to be notified of phase changes */
#endif /* PPP_NOTIFY */ #endif /* PPP_NOTIFY */

View File

@ -448,6 +448,69 @@ struct ppp_settings {
struct ppp_settings ppp_settings; struct ppp_settings ppp_settings;
/*
* PPP interface RX control block.
*/
typedef struct ppp_control_rx_s {
/** unit number / ppp descriptor */
int pd;
/** the rx file descriptor */
sio_fd_t fd;
/** receive buffer - encoded data is stored here */
#if PPPOS_SUPPORT && PPP_INPROC_OWNTHREAD
u_char rxbuf[PPPOS_RX_BUFSIZE];
#endif /* PPPOS_SUPPORT && PPP_INPROC_OWNTHREAD */
#if PPPOS_SUPPORT
/* The input packet. */
struct pbuf *in_head, *in_tail;
u16_t in_protocol; /* The input protocol code. */
u16_t in_fcs; /* Input Frame Check Sequence value. */
ppp_dev_states in_state; /* The input process state. */
char in_escaped; /* Escape next character. */
ext_accm in_accm; /* Async-Ctl-Char-Map for input. */
#endif /* PPPOS_SUPPORT */
} ppp_control_rx;
/*
* PPP interface control block.
*/
typedef struct ppp_control_s {
ppp_control_rx rx;
char open_flag; /* True when in use. */
u8_t phase; /* where the link is at */
#if PPPOE_SUPPORT
struct netif *ethif;
struct pppoe_softc *pppoe_sc;
#endif /* PPPOE_SUPPORT */
int if_up; /* True when the interface is up. */
int err_code; /* Code indicating why interface is down. */
#if PPPOS_SUPPORT
sio_fd_t fd; /* File device ID of port. */
#endif /* PPPOS_SUPPORT */
u16_t mtu; /* Peer's mru */
int pcomp; /* Does peer accept protocol compression? */
int accomp; /* Does peer accept addr/ctl compression? */
u_long last_xmit; /* Time of last transmission. */
#if PPPOS_SUPPORT
ext_accm out_accm; /* Async-Ctl-Char-Map for output. */
#endif /* PPPOS_SUPPORT */
#if PPPOS_SUPPORT && VJ_SUPPORT
int vj_enabled; /* Flag indicating VJ compression enabled. */
struct vjcompress vj_comp; /* Van Jacobson compression header. */
#endif /* PPPOS_SUPPORT && VJ_SUPPORT */
struct netif netif;
struct ppp_addrs addrs;
void (*link_status_cb)(void *ctx, int err_code, void *arg);
void *link_status_ctx;
} ppp_control;
ppp_control ppp_control_list[NUM_PPP]; /* The PPP interface control blocks. */
/* PPP flow functions /* PPP flow functions
*/ */
@ -471,7 +534,7 @@ struct pbuf * ppp_singlebuf(struct pbuf *p);
/* Functions called by various PPP subsystems to configure /* Functions called by various PPP subsystems to configure
* the PPP interface or change the PPP phase. * the PPP interface or change the PPP phase.
*/ */
void new_phase(int p); void new_phase(int unit, int p);
#if PPPOS_SUPPORT #if PPPOS_SUPPORT
void ppp_set_xaccm(int unit, ext_accm *accm); void ppp_set_xaccm(int unit, ext_accm *accm);