protent prototype switched from unit to ppp_pcb

This commit is contained in:
Sylvain Rochet 2012-06-16 02:43:13 +02:00
parent 4b7e3af77c
commit 4a8ff6d824
11 changed files with 165 additions and 199 deletions

View File

@ -711,9 +711,9 @@ void upper_layers_down(ppp_pcb *pcb) {
if (!protp->enabled_flag) if (!protp->enabled_flag)
continue; continue;
if (protp->protocol != PPP_LCP && protp->lowerdown != NULL) if (protp->protocol != PPP_LCP && protp->lowerdown != NULL)
(*protp->lowerdown)(pcb->unit); (*protp->lowerdown)(pcb);
if (protp->protocol < 0xC000 && protp->close != NULL) if (protp->protocol < 0xC000 && protp->close != NULL)
(*protp->close)(pcb->unit, "LCP down"); (*protp->close)(pcb, "LCP down");
} }
pcb->num_np_open = 0; pcb->num_np_open = 0;
pcb->num_np_up = 0; pcb->num_np_up = 0;
@ -742,7 +742,7 @@ void link_established(ppp_pcb *pcb) {
for (i = 0; (protp = protocols[i]) != NULL; ++i) for (i = 0; (protp = protocols[i]) != NULL; ++i)
if (protp->protocol != PPP_LCP && protp->enabled_flag if (protp->protocol != PPP_LCP && protp->enabled_flag
&& protp->lowerup != NULL) && protp->lowerup != NULL)
(*protp->lowerup)(pcb->unit); (*protp->lowerup)(pcb);
} }
#if 0 /* UNUSED */ #if 0 /* UNUSED */
@ -979,7 +979,7 @@ void continue_networks(ppp_pcb *pcb) {
&& protp->protocol != PPP_ECP && protp->protocol != PPP_ECP
#endif /* ECP_SUPPORT */ #endif /* ECP_SUPPORT */
&& protp->enabled_flag && protp->open != NULL) { && protp->enabled_flag && protp->open != NULL) {
(*protp->open)(0); (*protp->open)(pcb);
++pcb->num_np_open; ++pcb->num_np_open;
} }
@ -1083,7 +1083,7 @@ void auth_withpeer_fail(ppp_pcb *pcb, int protocol) {
* we can do except wait for that. * we can do except wait for that.
*/ */
ppp_ioctl(pcb, PPPCTLS_ERRCODE, &errcode); ppp_ioctl(pcb, PPPCTLS_ERRCODE, &errcode);
lcp_close(pcb->unit, "Failed to authenticate ourselves to peer"); lcp_close(pcb, "Failed to authenticate ourselves to peer");
} }
/* /*

View File

@ -91,9 +91,9 @@ static option_t chap_option_list[] = {
/* /*
* Prototypes. * Prototypes.
*/ */
static void chap_init(int unit); static void chap_init(ppp_pcb *pcb);
static void chap_lowerup(int unit); static void chap_lowerup(ppp_pcb *pcb);
static void chap_lowerdown(int unit); static void chap_lowerdown(ppp_pcb *pcb);
#if PPP_SERVER #if PPP_SERVER
static void chap_timeout(void *arg); static void chap_timeout(void *arg);
static void chap_generate_challenge(ppp_pcb *pcb); static void chap_generate_challenge(ppp_pcb *pcb);
@ -108,8 +108,8 @@ static void chap_respond(ppp_pcb *pcb, int id,
unsigned char *pkt, int len); unsigned char *pkt, int len);
static void chap_handle_status(ppp_pcb *pcb, int code, int id, static void chap_handle_status(ppp_pcb *pcb, int code, int id,
unsigned char *pkt, int len); unsigned char *pkt, int len);
static void chap_protrej(int unit); static void chap_protrej(ppp_pcb *pcb);
static void chap_input(int unit, unsigned char *pkt, int pktlen); static void chap_input(ppp_pcb *pcb, unsigned char *pkt, int pktlen);
#if PRINTPKT_SUPPORT #if PRINTPKT_SUPPORT
static int chap_print_pkt(unsigned char *p, int plen, static int chap_print_pkt(unsigned char *p, int plen,
void (*printer) (void *, char *, ...), void *arg); void (*printer) (void *, char *, ...), void *arg);
@ -121,8 +121,7 @@ static struct chap_digest_type *chap_digests;
/* /*
* chap_init - reset to initial state. * chap_init - reset to initial state.
*/ */
static void chap_init(int unit) { static void chap_init(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
memset(&pcb->chap_client, 0, sizeof(chap_client_state)); memset(&pcb->chap_client, 0, sizeof(chap_client_state));
#if PPP_SERVER #if PPP_SERVER
@ -148,8 +147,7 @@ void chap_register_digest(struct chap_digest_type *dp) {
/* /*
* chap_lowerup - we can start doing stuff now. * chap_lowerup - we can start doing stuff now.
*/ */
static void chap_lowerup(int unit) { static void chap_lowerup(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
pcb->chap_client.flags |= LOWERUP; pcb->chap_client.flags |= LOWERUP;
#if PPP_SERVER #if PPP_SERVER
@ -159,8 +157,7 @@ static void chap_lowerup(int unit) {
#endif /* PPP_SERVER */ #endif /* PPP_SERVER */
} }
static void chap_lowerdown(int unit) { static void chap_lowerdown(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
pcb->chap_client.flags = 0; pcb->chap_client.flags = 0;
#if PPP_SERVER #if PPP_SERVER
@ -502,8 +499,7 @@ static void chap_handle_status(ppp_pcb *pcb, int code, int id,
} }
} }
static void chap_input(int unit, unsigned char *pkt, int pktlen) { static void chap_input(ppp_pcb *pcb, unsigned char *pkt, int pktlen) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
unsigned char code, id; unsigned char code, id;
int len; int len;
@ -532,8 +528,7 @@ static void chap_input(int unit, unsigned char *pkt, int pktlen) {
} }
} }
static void chap_protrej(int unit) { static void chap_protrej(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
#if PPP_SERVER #if PPP_SERVER
if (pcb->chap_server.flags & TIMEOUT_PENDING) { if (pcb->chap_server.flags & TIMEOUT_PENDING) {

View File

@ -96,11 +96,11 @@ static option_t eap_option_list[] = {
/* /*
* Protocol entry points. * Protocol entry points.
*/ */
static void eap_init(int unit); static void eap_init(ppp_pcb *pcb);
static void eap_input(int unit, u_char *inp, int inlen); static void eap_input(ppp_pcb *pcb, u_char *inp, int inlen);
static void eap_protrej(int unit); static void eap_protrej(ppp_pcb *pcb);
static void eap_lowerup(int unit); static void eap_lowerup(ppp_pcb *pcb);
static void eap_lowerdown(int unit); static void eap_lowerdown(ppp_pcb *pcb);
#if PRINTPKT_SUPPORT #if PRINTPKT_SUPPORT
static int eap_printpkt(u_char *inp, int inlen, static int eap_printpkt(u_char *inp, int inlen,
void (*)(void *arg, char *fmt, ...), void *arg); void (*)(void *arg, char *fmt, ...), void *arg);
@ -195,11 +195,9 @@ enum eap_state_code esc;
* eap_init - Initialize state for an EAP user. This is currently * eap_init - Initialize state for an EAP user. This is currently
* called once by main() during start-up. * called once by main() during start-up.
*/ */
static void eap_init(int unit) { static void eap_init(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
BZERO(&pcb->eap, sizeof(eap_state)); BZERO(&pcb->eap, sizeof(eap_state));
pcb->eap.es_unit = unit;
#if PPP_SERVER #if PPP_SERVER
pcb->eap.es_server.ea_timeout = EAP_DEFTIMEOUT; pcb->eap.es_server.ea_timeout = EAP_DEFTIMEOUT;
pcb->eap.es_server.ea_maxrequests = EAP_DEFTRANSMITS; pcb->eap.es_server.ea_maxrequests = EAP_DEFTRANSMITS;
@ -955,8 +953,7 @@ void *arg;
* return to closed state so that those two routines will do the right * return to closed state so that those two routines will do the right
* thing. * thing.
*/ */
static void eap_lowerup(int unit) { static void eap_lowerup(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
/* Discard any (possibly authenticated) peer name. */ /* Discard any (possibly authenticated) peer name. */
#if PPP_SERVER #if PPP_SERVER
@ -980,8 +977,7 @@ static void eap_lowerup(int unit) {
* *
* Cancel all timeouts and return to initial state. * Cancel all timeouts and return to initial state.
*/ */
static void eap_lowerdown(int unit) { static void eap_lowerdown(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
if (eap_client_active(pcb) && pcb->eap.es_client.ea_timeout > 0) { if (eap_client_active(pcb) && pcb->eap.es_client.ea_timeout > 0) {
UNTIMEOUT(eap_client_timeout, pcb); UNTIMEOUT(eap_client_timeout, pcb);
@ -1014,8 +1010,7 @@ static void eap_lowerdown(int unit) {
* This shouldn't happen. If it does, it represents authentication * This shouldn't happen. If it does, it represents authentication
* failure. * failure.
*/ */
static void eap_protrej(int unit) { static void eap_protrej(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
if (eap_client_active(pcb)) { if (eap_client_active(pcb)) {
error("EAP authentication failed due to Protocol-Reject"); error("EAP authentication failed due to Protocol-Reject");
@ -1027,7 +1022,7 @@ static void eap_protrej(int unit) {
auth_peer_fail(pcb, PPP_EAP); auth_peer_fail(pcb, PPP_EAP);
} }
#endif /* PPP_SERVER */ #endif /* PPP_SERVER */
eap_lowerdown(unit); eap_lowerdown(pcb);
} }
/* /*
@ -2029,8 +2024,7 @@ static void eap_failure(ppp_pcb *pcb, u_char *inp, int id, int len) {
/* /*
* eap_input - Handle received EAP message. * eap_input - Handle received EAP message.
*/ */
static void eap_input(int unit, u_char *inp, int inlen) { static void eap_input(ppp_pcb *pcb, u_char *inp, int inlen) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
u_char code, id; u_char code, id;
int len; int len;

View File

@ -71,6 +71,7 @@
*/ */
typedef struct fsm { typedef struct fsm {
int unit; /* Interface unit number */ int unit; /* Interface unit number */
void *pcb; /* FIXME: Temporary */
int protocol; /* Data Link Layer Protocol field value */ int protocol; /* Data Link Layer Protocol field value */
int state; /* State */ int state; /* State */
int flags; /* Contains option bits */ int flags; /* Contains option bits */

View File

@ -249,13 +249,13 @@ static option_t ipcp_option_list[] = {
/* /*
* Protocol entry points from main code. * Protocol entry points from main code.
*/ */
static void ipcp_init(int unit); static void ipcp_init(ppp_pcb *pcb);
static void ipcp_open(int unit); static void ipcp_open(ppp_pcb *pcb);
static void ipcp_close(int unit, char *reason); static void ipcp_close(ppp_pcb *pcb, char *reason);
static void ipcp_lowerup(int unit); static void ipcp_lowerup(ppp_pcb *pcb);
static void ipcp_lowerdown(int unit); static void ipcp_lowerdown(ppp_pcb *pcb);
static void ipcp_input(int unit, u_char *p, int len); static void ipcp_input(ppp_pcb *pcb, u_char *p, int len);
static void ipcp_protrej(int unit); static void ipcp_protrej(ppp_pcb *pcb);
#if PRINTPKT_SUPPORT #if PRINTPKT_SUPPORT
static int ipcp_printpkt(u_char *p, int plen, static int ipcp_printpkt(u_char *p, int plen,
void (*printer) (void *, char *, ...), void *arg); void (*printer) (void *, char *, ...), void *arg);
@ -584,14 +584,14 @@ parse_dotted_ip(p, vp)
/* /*
* ipcp_init - Initialize IPCP. * ipcp_init - Initialize IPCP.
*/ */
static void ipcp_init(int unit) { static void ipcp_init(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->ipcp_fsm; fsm *f = &pcb->ipcp_fsm;
ipcp_options *wo = &pcb->ipcp_wantoptions; ipcp_options *wo = &pcb->ipcp_wantoptions;
ipcp_options *ao = &pcb->ipcp_allowoptions; ipcp_options *ao = &pcb->ipcp_allowoptions;
f->unit = unit; f->unit = pcb->unit;
f->pcb = (void*)pcb;
f->protocol = PPP_IPCP; f->protocol = PPP_IPCP;
f->callbacks = &ipcp_callbacks; f->callbacks = &ipcp_callbacks;
fsm_init(f); fsm_init(f);
@ -638,8 +638,7 @@ static void ipcp_init(int unit) {
/* /*
* ipcp_open - IPCP is allowed to come up. * ipcp_open - IPCP is allowed to come up.
*/ */
static void ipcp_open(int unit) { static void ipcp_open(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->ipcp_fsm; fsm *f = &pcb->ipcp_fsm;
fsm_open(f); fsm_open(f);
ipcp_is_open = 1; ipcp_is_open = 1;
@ -649,8 +648,7 @@ static void ipcp_open(int unit) {
/* /*
* ipcp_close - Take IPCP down. * ipcp_close - Take IPCP down.
*/ */
static void ipcp_close(int unit, char *reason) { static void ipcp_close(ppp_pcb *pcb, char *reason) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->ipcp_fsm; fsm *f = &pcb->ipcp_fsm;
fsm_close(f, reason); fsm_close(f, reason);
} }
@ -659,8 +657,7 @@ static void ipcp_close(int unit, char *reason) {
/* /*
* ipcp_lowerup - The lower layer is up. * ipcp_lowerup - The lower layer is up.
*/ */
static void ipcp_lowerup(int unit) { static void ipcp_lowerup(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->ipcp_fsm; fsm *f = &pcb->ipcp_fsm;
fsm_lowerup(f); fsm_lowerup(f);
} }
@ -669,8 +666,7 @@ static void ipcp_lowerup(int unit) {
/* /*
* ipcp_lowerdown - The lower layer is down. * ipcp_lowerdown - The lower layer is down.
*/ */
static void ipcp_lowerdown(int unit) { static void ipcp_lowerdown(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->ipcp_fsm; fsm *f = &pcb->ipcp_fsm;
fsm_lowerdown(f); fsm_lowerdown(f);
} }
@ -679,8 +675,7 @@ static void ipcp_lowerdown(int unit) {
/* /*
* ipcp_input - Input IPCP packet. * ipcp_input - Input IPCP packet.
*/ */
static void ipcp_input(int unit, u_char *p, int len) { static void ipcp_input(ppp_pcb *pcb, u_char *p, int len) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->ipcp_fsm; fsm *f = &pcb->ipcp_fsm;
fsm_input(f, p, len); fsm_input(f, p, len);
} }
@ -691,8 +686,7 @@ static void ipcp_input(int unit, u_char *p, int len) {
* *
* Pretend the lower layer went down, so we shut up. * Pretend the lower layer went down, so we shut up.
*/ */
static void ipcp_protrej(int unit) { static void ipcp_protrej(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->ipcp_fsm; fsm *f = &pcb->ipcp_fsm;
fsm_lowerdown(f); fsm_lowerdown(f);
} }
@ -1776,12 +1770,12 @@ static void ipcp_up(fsm *f) {
if (!(go->neg_addr || go->old_addrs) && (wo->neg_addr || wo->old_addrs) if (!(go->neg_addr || go->old_addrs) && (wo->neg_addr || wo->old_addrs)
&& wo->ouraddr != 0) { && wo->ouraddr != 0) {
error("Peer refused to agree to our IP address"); error("Peer refused to agree to our IP address");
ipcp_close(f->unit, "Refused our IP address"); ipcp_close(f->pcb, "Refused our IP address");
return; return;
} }
if (go->ouraddr == 0) { if (go->ouraddr == 0) {
error("Could not determine local IP address"); error("Could not determine local IP address");
ipcp_close(f->unit, "Could not determine local IP address"); ipcp_close(f->pcb, "Could not determine local IP address");
return; return;
} }
if (ho->hisaddr == 0 && !noremoteip) { if (ho->hisaddr == 0 && !noremoteip) {
@ -1889,7 +1883,7 @@ static void ipcp_up(fsm *f) {
#if PPP_DEBUG #if PPP_DEBUG
warn("Interface configuration failed"); warn("Interface configuration failed");
#endif /* PPP_DEBUG */ #endif /* PPP_DEBUG */
ipcp_close(f->unit, "Interface configuration failed"); ipcp_close(f->pcb, "Interface configuration failed");
return; return;
} }
#endif #endif
@ -1899,7 +1893,7 @@ static void ipcp_up(fsm *f) {
#if PPP_DEBUG #if PPP_DEBUG
warn("Interface failed to come up"); warn("Interface failed to come up");
#endif /* PPP_DEBUG */ #endif /* PPP_DEBUG */
ipcp_close(f->unit, "Interface configuration failed"); ipcp_close(f->pcb, "Interface configuration failed");
return; return;
} }

View File

@ -241,8 +241,8 @@ static void lcp_rprotrej (fsm *, u_char *, int);
* routines to send LCP echos to peer * routines to send LCP echos to peer
*/ */
static void lcp_echo_lowerup(int unit); static void lcp_echo_lowerup(ppp_pcb *pcb);
static void lcp_echo_lowerdown(int unit); static void lcp_echo_lowerdown(ppp_pcb *pcb);
static void LcpEchoTimeout (void *); static void LcpEchoTimeout (void *);
static void lcp_received_echo_reply (fsm *, int, u_char *, int); static void lcp_received_echo_reply (fsm *, int, u_char *, int);
static void LcpSendEchoRequest (fsm *); static void LcpSendEchoRequest (fsm *);
@ -272,9 +272,9 @@ static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
* Some of these are called directly. * Some of these are called directly.
*/ */
static void lcp_init(int unit); static void lcp_init(ppp_pcb *pcb);
static void lcp_input(int unit, u_char *p, int len); static void lcp_input(ppp_pcb *pcb, u_char *p, int len);
static void lcp_protrej(int unit); static void lcp_protrej(ppp_pcb *pcb);
#if PRINTPKT_SUPPORT #if PRINTPKT_SUPPORT
static int lcp_printpkt(u_char *p, int plen, static int lcp_printpkt(u_char *p, int plen,
void (*printer) (void *, char *, ...), void *arg); void (*printer) (void *, char *, ...), void *arg);
@ -369,13 +369,13 @@ printendpoint(opt, printer, arg)
/* /*
* lcp_init - Initialize LCP. * lcp_init - Initialize LCP.
*/ */
static void lcp_init(int unit) { static void lcp_init(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->lcp_fsm; fsm *f = &pcb->lcp_fsm;
lcp_options *wo = &pcb->lcp_wantoptions; lcp_options *wo = &pcb->lcp_wantoptions;
lcp_options *ao = &pcb->lcp_allowoptions; lcp_options *ao = &pcb->lcp_allowoptions;
f->unit = unit; f->unit = pcb->unit;
f->pcb = (void*)pcb;
f->protocol = PPP_LCP; f->protocol = PPP_LCP;
f->callbacks = &lcp_callbacks; f->callbacks = &lcp_callbacks;
@ -413,12 +413,12 @@ static void lcp_init(int unit) {
* Set transmit escape for the flag and escape characters plus anything * Set transmit escape for the flag and escape characters plus anything
* set for the allowable options. * set for the allowable options.
*/ */
memset(xmit_accm[unit], 0, sizeof(xmit_accm[0])); memset(xmit_accm[pcb->unit], 0, sizeof(xmit_accm[0]));
xmit_accm[unit][15] = 0x60; xmit_accm[pcb->unit][15] = 0x60;
xmit_accm[unit][0] = (u_char)((ao->asyncmap & 0xFF)); xmit_accm[pcb->unit][0] = (u_char)((ao->asyncmap & 0xFF));
xmit_accm[unit][1] = (u_char)((ao->asyncmap >> 8) & 0xFF); xmit_accm[pcb->unit][1] = (u_char)((ao->asyncmap >> 8) & 0xFF);
xmit_accm[unit][2] = (u_char)((ao->asyncmap >> 16) & 0xFF); xmit_accm[pcb->unit][2] = (u_char)((ao->asyncmap >> 16) & 0xFF);
xmit_accm[unit][3] = (u_char)((ao->asyncmap >> 24) & 0xFF); xmit_accm[pcb->unit][3] = (u_char)((ao->asyncmap >> 24) & 0xFF);
LCPDEBUG(("lcp_init: xmit_accm=%X %X %X %X\n", LCPDEBUG(("lcp_init: xmit_accm=%X %X %X %X\n",
xmit_accm[unit][0], xmit_accm[unit][0],
xmit_accm[unit][1], xmit_accm[unit][1],
@ -431,8 +431,7 @@ static void lcp_init(int unit) {
/* /*
* lcp_open - LCP is allowed to come up. * lcp_open - LCP is allowed to come up.
*/ */
void lcp_open(int unit) { void lcp_open(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->lcp_fsm; fsm *f = &pcb->lcp_fsm;
lcp_options *wo = &pcb->lcp_wantoptions; lcp_options *wo = &pcb->lcp_wantoptions;
@ -448,8 +447,7 @@ void lcp_open(int unit) {
/* /*
* lcp_close - Take LCP down. * lcp_close - Take LCP down.
*/ */
void lcp_close(int unit, char *reason) { void lcp_close(ppp_pcb *pcb, char *reason) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->lcp_fsm; fsm *f = &pcb->lcp_fsm;
int oldstate; int oldstate;
@ -480,8 +478,7 @@ void lcp_close(int unit, char *reason) {
/* /*
* lcp_lowerup - The lower layer is up. * lcp_lowerup - The lower layer is up.
*/ */
void lcp_lowerup(int unit) { void lcp_lowerup(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
lcp_options *wo = &pcb->lcp_wantoptions; lcp_options *wo = &pcb->lcp_wantoptions;
#if PPPOS_SUPPORT #if PPPOS_SUPPORT
lcp_options *ao = &pcb->lcp_allowoptions; lcp_options *ao = &pcb->lcp_allowoptions;
@ -493,19 +490,19 @@ void lcp_lowerup(int unit) {
* if we are going to ask for A/C and protocol compression. * if we are going to ask for A/C and protocol compression.
*/ */
#if PPPOS_SUPPORT #if PPPOS_SUPPORT
ppp_set_xaccm(pcb, &xmit_accm[unit]); ppp_set_xaccm(pcb, &xmit_accm[pcb->unit]);
#endif /* PPPOS_SUPPORT */ #endif /* PPPOS_SUPPORT */
if (ppp_send_config(pcb, PPP_MRU, 0xffffffff, 0, 0) < 0 if (ppp_send_config(pcb, PPP_MRU, 0xffffffff, 0, 0) < 0
|| ppp_recv_config(pcb, PPP_MRU, (lax_recv? 0: 0xffffffff), || ppp_recv_config(pcb, PPP_MRU, (lax_recv? 0: 0xffffffff),
wo->neg_pcompression, wo->neg_accompression) < 0) wo->neg_pcompression, wo->neg_accompression) < 0)
return; return;
peer_mru[unit] = PPP_MRU; peer_mru[pcb->unit] = PPP_MRU;
#if PPPOS_SUPPORT #if PPPOS_SUPPORT
ao->asyncmap = (u_long)xmit_accm[unit][0] ao->asyncmap = (u_long)xmit_accm[f->unit][0]
| ((u_long)xmit_accm[unit][1] << 8) | ((u_long)xmit_accm[pcb->unit][1] << 8)
| ((u_long)xmit_accm[unit][2] << 16) | ((u_long)xmit_accm[pcb->unit][2] << 16)
| ((u_long)xmit_accm[unit][3] << 24); | ((u_long)xmit_accm[pcb->unit][3] << 24);
LCPDEBUG(("lcp_lowerup: asyncmap=%X %X %X %X\n", LCPDEBUG(("lcp_lowerup: asyncmap=%X %X %X %X\n",
xmit_accm[unit][3], xmit_accm[unit][3],
xmit_accm[unit][2], xmit_accm[unit][2],
@ -524,8 +521,7 @@ void lcp_lowerup(int unit) {
/* /*
* lcp_lowerdown - The lower layer is down. * lcp_lowerdown - The lower layer is down.
*/ */
void lcp_lowerdown(int unit) { void lcp_lowerdown(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->lcp_fsm; fsm *f = &pcb->lcp_fsm;
if (f->flags & DELAYED_UP) { if (f->flags & DELAYED_UP) {
@ -552,8 +548,7 @@ static void lcp_delayed_up(void *arg) {
/* /*
* lcp_input - Input LCP packet. * lcp_input - Input LCP packet.
*/ */
static void lcp_input(int unit, u_char *p, int len) { static void lcp_input(ppp_pcb *pcb, u_char *p, int len) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->lcp_fsm; fsm *f = &pcb->lcp_fsm;
if (f->flags & DELAYED_UP) { if (f->flags & DELAYED_UP) {
@ -657,7 +652,7 @@ lcp_rprotrej(f, inp, len)
else else
#endif /* PPP_PROTOCOLNAME */ #endif /* PPP_PROTOCOLNAME */
dbglog("Protocol-Reject for 0x%x received", prot); dbglog("Protocol-Reject for 0x%x received", prot);
(*protp->protrej)(f->unit); (*protp->protrej)(f->pcb);
return; return;
} }
@ -675,8 +670,7 @@ lcp_rprotrej(f, inp, len)
* lcp_protrej - A Protocol-Reject was received. * lcp_protrej - A Protocol-Reject was received.
*/ */
/*ARGSUSED*/ /*ARGSUSED*/
static void lcp_protrej(int unit) { static void lcp_protrej(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
/* /*
* Can't reject LCP! * Can't reject LCP!
*/ */
@ -688,8 +682,7 @@ static void lcp_protrej(int unit) {
/* /*
* lcp_sprotrej - Send a Protocol-Reject for some protocol. * lcp_sprotrej - Send a Protocol-Reject for some protocol.
*/ */
void lcp_sprotrej(int unit, u_char *p, int len) { void lcp_sprotrej(ppp_pcb *pcb, u_char *p, int len) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->lcp_fsm; fsm *f = &pcb->lcp_fsm;
/* /*
* Send back the protocol and the information field of the * Send back the protocol and the information field of the
@ -1536,7 +1529,7 @@ lcp_nakci(f, p, len, treat_as_reject)
if (++try.numloops >= lcp_loopbackfail) { if (++try.numloops >= lcp_loopbackfail) {
notice("Serial line is looped back."); notice("Serial line is looped back.");
pcb->status = EXIT_LOOPBACK; pcb->status = EXIT_LOOPBACK;
lcp_close(f->unit, "Loopback detected"); lcp_close(f->pcb, "Loopback detected");
} }
} else } else
try.numloops = 0; try.numloops = 0;
@ -2296,7 +2289,7 @@ lcp_up(f)
if (ho->neg_mru) if (ho->neg_mru)
peer_mru[f->unit] = ho->mru; peer_mru[f->unit] = ho->mru;
lcp_echo_lowerup(f->unit); /* Enable echo messages */ lcp_echo_lowerup(f->pcb); /* Enable echo messages */
link_established(pcb); link_established(pcb);
} }
@ -2314,7 +2307,7 @@ lcp_down(f)
ppp_pcb *pcb = &ppp_pcb_list[f->unit]; ppp_pcb *pcb = &ppp_pcb_list[f->unit];
lcp_options *go = &pcb->lcp_gotoptions; lcp_options *go = &pcb->lcp_gotoptions;
lcp_echo_lowerdown(f->unit); lcp_echo_lowerdown(f->pcb);
link_down(pcb); link_down(pcb);
@ -2613,7 +2606,7 @@ void LcpLinkFailure (f)
info("No response to %d echo-requests", lcp_echos_pending); info("No response to %d echo-requests", lcp_echos_pending);
notice("Serial link appears to be disconnected."); notice("Serial link appears to be disconnected.");
pc->status = EXIT_PEER_DEAD; pc->status = EXIT_PEER_DEAD;
lcp_close(f->unit, "Peer not responding"); lcp_close(f->pcb, "Peer not responding");
} }
} }
@ -2742,8 +2735,7 @@ LcpSendEchoRequest (f)
* lcp_echo_lowerup - Start the timer for the LCP frame * lcp_echo_lowerup - Start the timer for the LCP frame
*/ */
static void lcp_echo_lowerup(int unit) { static void lcp_echo_lowerup(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->lcp_fsm; fsm *f = &pcb->lcp_fsm;
/* Clear the parameters for generating echo frames */ /* Clear the parameters for generating echo frames */
@ -2760,8 +2752,7 @@ static void lcp_echo_lowerup(int unit) {
* lcp_echo_lowerdown - Stop the timer for the LCP frame * lcp_echo_lowerdown - Stop the timer for the LCP frame
*/ */
static void lcp_echo_lowerdown(int unit) { static void lcp_echo_lowerdown(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
fsm *f = &pcb->lcp_fsm; fsm *f = &pcb->lcp_fsm;
if (lcp_echo_timer_running != 0) { if (lcp_echo_timer_running != 0) {

View File

@ -48,6 +48,8 @@
#ifndef LCP_H #ifndef LCP_H
#define LCP_H #define LCP_H
#include "ppp.h"
/* /*
* Options. * Options.
*/ */
@ -88,57 +90,6 @@
/* Value used as data for CI_CALLBACK option */ /* Value used as data for CI_CALLBACK option */
#define CBCP_OPT 6 /* Use callback control protocol */ #define CBCP_OPT 6 /* Use callback control protocol */
/* FIXME: moved temporarily from ppp.h */
/* An endpoint discriminator, used with multilink. */
#define MAX_ENDP_LEN 20 /* maximum length of discriminator value */
struct epdisc {
unsigned char class;
unsigned char length;
unsigned char value[MAX_ENDP_LEN];
};
/*
* The state of options is described by an lcp_options structure.
*/
typedef struct lcp_options {
bool passive; /* Don't die if we don't get a response */
bool silent; /* Wait for the other end to start first */
bool restart; /* Restart vs. exit after close */
bool neg_mru; /* Negotiate the MRU? */
bool neg_asyncmap; /* Negotiate the async map? */
#if PAP_SUPPORT
bool neg_upap; /* Ask for UPAP authentication? */
#endif /* PAP_SUPPORT */
#if CHAP_SUPPORT
bool neg_chap; /* Ask for CHAP authentication? */
#endif /* CHAP_SUPPORT */
#if EAP_SUPPORT
bool neg_eap; /* Ask for EAP authentication? */
#endif /* EAP_SUPPORT */
bool neg_magicnumber; /* Ask for magic number? */
bool neg_pcompression; /* HDLC Protocol Field Compression? */
bool neg_accompression; /* HDLC Address/Control Field Compression? */
#if LQR_SUPPORT
bool neg_lqr; /* Negotiate use of Link Quality Reports */
#endif /* LQR_SUPPORT */
bool neg_cbcp; /* Negotiate use of CBCP */
bool neg_mrru; /* negotiate multilink MRRU */
bool neg_ssnhf; /* negotiate short sequence numbers */
bool neg_endpoint; /* negotiate endpoint discriminator */
int mru; /* Value of MRU */
int mrru; /* Value of MRRU, and multilink enable */
#if CHAP_SUPPORT
u_char chap_mdtype; /* which MD types (hashing algorithm) */
#endif /* CHAP_SUPPORT */
u_int32_t asyncmap; /* Value of async map */
u_int32_t magicnumber;
int numloops; /* Number of loops during magic number neg. */
#if LQR_SUPPORT
u_int32_t lqr_period; /* Reporting period for LQR 1/100ths second */
#endif /* LQR_SUPPORT */
struct epdisc endpoint; /* endpoint discriminator */
} lcp_options;
#if PPPOS_SUPPORT #if PPPOS_SUPPORT
extern ext_accm xmit_accm[]; extern ext_accm xmit_accm[];
#endif /* #if PPPOS_SUPPORT */ #endif /* #if PPPOS_SUPPORT */
@ -147,11 +98,11 @@ extern ext_accm xmit_accm[];
#define MINMRU 128 /* No MRUs below this */ #define MINMRU 128 /* No MRUs below this */
#define MAXMRU 16384 /* Normally limit MRU to this */ #define MAXMRU 16384 /* Normally limit MRU to this */
void lcp_open(int unit); void lcp_open(ppp_pcb *pcb);
void lcp_close(int unit, char *reason); void lcp_close(ppp_pcb *pcb, char *reason);
void lcp_lowerup(int unit); void lcp_lowerup(ppp_pcb *pcb);
void lcp_lowerdown(int unit); void lcp_lowerdown(ppp_pcb *pcb);
void lcp_sprotrej(int unit, u_char *p, int len); /* send protocol reject */ void lcp_sprotrej(ppp_pcb *pcb, u_char *p, int len); /* send protocol reject */
extern struct protent lcp_protent; extern struct protent lcp_protent;

View File

@ -267,7 +267,7 @@ ppp_pcb *ppp_new(void) {
* Initialize each protocol. * Initialize each protocol.
*/ */
for (i = 0; (protp = protocols[i]) != NULL; ++i) for (i = 0; (protp = protocols[i]) != NULL; ++i)
(*protp->init)(pd); (*protp->init)(pcb);
return pcb; return pcb;
} }
@ -475,21 +475,21 @@ ppp_sighup(ppp_pcb *pcb)
/** Initiate LCP open request */ /** Initiate LCP open request */
static void ppp_start(ppp_pcb *pcb) { static void ppp_start(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_start: unit %d\n", pcb->unit)); PPPDEBUG(LOG_DEBUG, ("ppp_start: unit %d\n", pcb->unit));
lcp_open(pcb->unit); /* Start protocol */ lcp_open(pcb); /* Start protocol */
lcp_lowerup(pcb->unit); lcp_lowerup(pcb);
PPPDEBUG(LOG_DEBUG, ("ppp_start: finished\n")); PPPDEBUG(LOG_DEBUG, ("ppp_start: finished\n"));
} }
/** LCP close request */ /** LCP close request */
static void ppp_stop(ppp_pcb *pcb) { static void ppp_stop(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_stop: unit %d\n", pcb->unit)); PPPDEBUG(LOG_DEBUG, ("ppp_stop: unit %d\n", pcb->unit));
lcp_close(pcb->unit, "User request"); lcp_close(pcb, "User request");
} }
/** Called when carrier/link is lost */ /** Called when carrier/link is lost */
static void ppp_hup(ppp_pcb *pcb) { static void ppp_hup(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_hup: unit %d\n", pcb->unit)); PPPDEBUG(LOG_DEBUG, ("ppp_hup: unit %d\n", pcb->unit));
lcp_lowerdown(pcb->unit); lcp_lowerdown(pcb);
link_terminated(pcb); link_terminated(pcb);
} }
@ -599,7 +599,7 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) {
for (i = 0; (protp = protocols[i]) != NULL; ++i) { for (i = 0; (protp = protocols[i]) != NULL; ++i) {
if (protp->protocol == protocol && protp->enabled_flag) { if (protp->protocol == protocol && protp->enabled_flag) {
pb = ppp_singlebuf(pb); pb = ppp_singlebuf(pb);
(*protp->input)(pcb->unit, pb->payload, pb->len); (*protp->input)(pcb, pb->payload, pb->len);
goto out; goto out;
} }
#if 0 /* UNUSED #if 0 /* UNUSED
@ -632,7 +632,7 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) {
LWIP_ASSERT("pbuf_header failed\n", 0); LWIP_ASSERT("pbuf_header failed\n", 0);
goto drop; goto drop;
} }
lcp_sprotrej(pcb->unit, pb->payload, pb->len); lcp_sprotrej(pcb, pb->payload, pb->len);
} }
break; break;
} }

View File

@ -89,7 +89,6 @@ typedef unsigned char bool;
#endif #endif
#include "fsm.h" #include "fsm.h"
#include "lcp.h"
#include "ipcp.h" #include "ipcp.h"
@ -227,12 +226,61 @@ typedef struct ppp_pcb_rx_s {
} ppp_pcb_rx; } ppp_pcb_rx;
#endif /* PPPOS_SUPPORT */ #endif /* PPPOS_SUPPORT */
/* An endpoint discriminator, used with multilink. */
#define MAX_ENDP_LEN 20 /* maximum length of discriminator value */
struct epdisc {
unsigned char class;
unsigned char length;
unsigned char value[MAX_ENDP_LEN];
};
/*
* The state of options is described by an lcp_options structure.
*/
typedef struct lcp_options {
bool passive; /* Don't die if we don't get a response */
bool silent; /* Wait for the other end to start first */
bool restart; /* Restart vs. exit after close */
bool neg_mru; /* Negotiate the MRU? */
bool neg_asyncmap; /* Negotiate the async map? */
#if PAP_SUPPORT
bool neg_upap; /* Ask for UPAP authentication? */
#endif /* PAP_SUPPORT */
#if CHAP_SUPPORT
bool neg_chap; /* Ask for CHAP authentication? */
#endif /* CHAP_SUPPORT */
#if EAP_SUPPORT
bool neg_eap; /* Ask for EAP authentication? */
#endif /* EAP_SUPPORT */
bool neg_magicnumber; /* Ask for magic number? */
bool neg_pcompression; /* HDLC Protocol Field Compression? */
bool neg_accompression; /* HDLC Address/Control Field Compression? */
#if LQR_SUPPORT
bool neg_lqr; /* Negotiate use of Link Quality Reports */
#endif /* LQR_SUPPORT */
bool neg_cbcp; /* Negotiate use of CBCP */
bool neg_mrru; /* negotiate multilink MRRU */
bool neg_ssnhf; /* negotiate short sequence numbers */
bool neg_endpoint; /* negotiate endpoint discriminator */
int mru; /* Value of MRU */
int mrru; /* Value of MRRU, and multilink enable */
#if CHAP_SUPPORT
u_char chap_mdtype; /* which MD types (hashing algorithm) */
#endif /* CHAP_SUPPORT */
u_int32_t asyncmap; /* Value of async map */
u_int32_t magicnumber;
int numloops; /* Number of loops during magic number neg. */
#if LQR_SUPPORT
u_int32_t lqr_period; /* Reporting period for LQR 1/100ths second */
#endif /* LQR_SUPPORT */
struct epdisc endpoint; /* endpoint discriminator */
} lcp_options;
/* /*
* Each interface is described by upap structure. * Each interface is described by upap structure.
*/ */
#if PAP_SUPPORT #if PAP_SUPPORT
typedef struct upap_state { typedef struct upap_state {
int us_unit; /* Interface unit number */
char *us_user; /* User */ char *us_user; /* User */
int us_userlen; /* User length */ int us_userlen; /* User length */
char *us_passwd; /* Password */ char *us_passwd; /* Password */
@ -314,7 +362,6 @@ struct eap_auth {
#define EAP_MAX_CHALLENGE_LENGTH 24 #define EAP_MAX_CHALLENGE_LENGTH 24
#endif #endif
typedef struct eap_state { typedef struct eap_state {
int es_unit; /* Interface unit number */
struct eap_auth es_client; /* Client (authenticatee) data */ struct eap_auth es_client; /* Client (authenticatee) data */
#if PPP_SERVER #if PPP_SERVER
struct eap_auth es_server; /* Server (authenticator) data */ struct eap_auth es_server; /* Server (authenticator) data */

View File

@ -221,7 +221,7 @@ struct ppp_idle {
}; };
/* FIXME: make endpoint discriminator optional */ /* FIXME: make endpoint discriminator optional */
/* FIXME: moved temporarily to lcp.h */ /* FIXME: moved temporarily to ppp.h */
/* values for epdisc.class */ /* values for epdisc.class */
#define EPD_NULL 0 /* null discriminator, no data */ #define EPD_NULL 0 /* null discriminator, no data */
@ -269,19 +269,19 @@ extern int maxoctets_timeout; /* Timeout for check of octets limit */
struct protent { struct protent {
u_short protocol; /* PPP protocol number */ u_short protocol; /* PPP protocol number */
/* Initialization procedure */ /* Initialization procedure */
void (*init) (int unit); void (*init) (ppp_pcb *pcb);
/* Process a received packet */ /* Process a received packet */
void (*input) (int unit, u_char *pkt, int len); void (*input) (ppp_pcb *pcb, u_char *pkt, int len);
/* Process a received protocol-reject */ /* Process a received protocol-reject */
void (*protrej) (int unit); void (*protrej) (ppp_pcb *pcb);
/* Lower layer has come up */ /* Lower layer has come up */
void (*lowerup) (int unit); void (*lowerup) (ppp_pcb *pcb);
/* Lower layer has gone down */ /* Lower layer has gone down */
void (*lowerdown) (int unit); void (*lowerdown) (ppp_pcb *pcb);
/* Open the protocol */ /* Open the protocol */
void (*open) (int unit); void (*open) (ppp_pcb *pcb);
/* Close the protocol */ /* Close the protocol */
void (*close) (int unit, char *reason); void (*close) (ppp_pcb *pcb, char *reason);
#if PRINTPKT_SUPPORT #if PRINTPKT_SUPPORT
/* Print a packet in readable form */ /* Print a packet in readable form */
int (*printpkt) (u_char *pkt, int len, int (*printpkt) (u_char *pkt, int len,
@ -292,7 +292,7 @@ struct protent {
* should we remove this entry and save some flash ? * should we remove this entry and save some flash ?
*/ */
/* Process a received data packet */ /* Process a received data packet */
void (*datainput) (int unit, u_char *pkt, int len); void (*datainput) (ppp_pcb *pcb, u_char *pkt, int len);
bool enabled_flag; /* 0 if protocol is disabled */ bool enabled_flag; /* 0 if protocol is disabled */
#if PRINTPKT_SUPPORT #if PRINTPKT_SUPPORT
char *name; /* Text name of protocol */ char *name; /* Text name of protocol */

View File

@ -80,11 +80,11 @@ static option_t pap_option_list[] = {
/* /*
* Protocol entry points. * Protocol entry points.
*/ */
static void upap_init(int unit); static void upap_init(ppp_pcb *pcb);
static void upap_lowerup(int unit); static void upap_lowerup(ppp_pcb *pcb);
static void upap_lowerdown(int unit); static void upap_lowerdown(ppp_pcb *pcb);
static void upap_input(int unit, u_char *inpacket, int l); static void upap_input(ppp_pcb *pcb, u_char *inpacket, int l);
static void upap_protrej(int unit); static void upap_protrej(ppp_pcb *pcb);
#if PRINTPKT_SUPPORT #if PRINTPKT_SUPPORT
static int upap_printpkt(u_char *p, int plen, void (*printer) (void *, char *, ...), void *arg); static int upap_printpkt(u_char *p, int plen, void (*printer) (void *, char *, ...), void *arg);
#endif /* PRINTPKT_SUPPORT */ #endif /* PRINTPKT_SUPPORT */
@ -135,10 +135,7 @@ static void upap_sresp(ppp_pcb *pcb, u_char code, u_char id, char *msg, int msgl
/* /*
* upap_init - Initialize a UPAP unit. * upap_init - Initialize a UPAP unit.
*/ */
static void upap_init(int unit) { static void upap_init(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
pcb->upap.us_unit = unit;
pcb->upap.us_user = NULL; pcb->upap.us_user = NULL;
pcb->upap.us_userlen = 0; pcb->upap.us_userlen = 0;
pcb->upap.us_passwd = NULL; pcb->upap.us_passwd = NULL;
@ -240,8 +237,7 @@ static void upap_reqtimeout(void *arg) {
* *
* Start authenticating if pending. * Start authenticating if pending.
*/ */
static void upap_lowerup(int unit) { static void upap_lowerup(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
if (pcb->upap.us_clientstate == UPAPCS_INITIAL) if (pcb->upap.us_clientstate == UPAPCS_INITIAL)
pcb->upap.us_clientstate = UPAPCS_CLOSED; pcb->upap.us_clientstate = UPAPCS_CLOSED;
@ -266,8 +262,7 @@ static void upap_lowerup(int unit) {
* *
* Cancel all timeouts. * Cancel all timeouts.
*/ */
static void upap_lowerdown(int unit) { static void upap_lowerdown(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
if (pcb->upap.us_clientstate == UPAPCS_AUTHREQ) /* Timeout pending? */ if (pcb->upap.us_clientstate == UPAPCS_AUTHREQ) /* Timeout pending? */
UNTIMEOUT(upap_timeout, pcb); /* Cancel timeout */ UNTIMEOUT(upap_timeout, pcb); /* Cancel timeout */
@ -288,8 +283,7 @@ static void upap_lowerdown(int unit) {
* *
* This shouldn't happen. In any case, pretend lower layer went down. * This shouldn't happen. In any case, pretend lower layer went down.
*/ */
static void upap_protrej(int unit) { static void upap_protrej(ppp_pcb *pcb) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
if (pcb->upap.us_clientstate == UPAPCS_AUTHREQ) { if (pcb->upap.us_clientstate == UPAPCS_AUTHREQ) {
error("PAP authentication failed due to protocol-reject"); error("PAP authentication failed due to protocol-reject");
@ -301,15 +295,14 @@ static void upap_protrej(int unit) {
auth_peer_fail(pcb, PPP_PAP); auth_peer_fail(pcb, PPP_PAP);
} }
#endif /* PPP_SERVER */ #endif /* PPP_SERVER */
upap_lowerdown(unit); upap_lowerdown(pcb);
} }
/* /*
* upap_input - Input UPAP packet. * upap_input - Input UPAP packet.
*/ */
static void upap_input(int unit, u_char *inpacket, int l) { static void upap_input(ppp_pcb *pcb, u_char *inpacket, int l) {
ppp_pcb *pcb = &ppp_pcb_list[unit];
u_char *inp; u_char *inp;
u_char code, id; u_char code, id;
int len; int len;