Minor changes in PPP (coding style, tabs, idents...)

This commit is contained in:
fbernon 2007-12-19 20:47:22 +00:00
parent a3ef33c56f
commit fc2d28b851
21 changed files with 4571 additions and 4422 deletions

View File

@ -62,7 +62,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: chap.h,v 1.3 2007/12/02 22:56:19 fbernon Exp $
* $Id: chap.h,v 1.4 2007/12/19 20:47:22 fbernon Exp $
*/
#ifndef CHAP_H

View File

@ -51,7 +51,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: chpms.h,v 1.4 2007/12/02 22:56:19 fbernon Exp $
* $Id: chpms.h,v 1.5 2007/12/19 20:47:23 fbernon Exp $
*/
#ifndef CHPMS_H

View File

@ -48,7 +48,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: fsm.h,v 1.3 2007/12/02 23:24:59 fbernon Exp $
* $Id: fsm.h,v 1.4 2007/12/19 20:47:23 fbernon Exp $
*/
#ifndef FSM_H

View File

@ -188,7 +188,8 @@ static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
* sources. Assumes u32_t instead of struct in_addr.
*/
char * _inet_ntoa(u32_t n)
char *
_inet_ntoa(u32_t n)
{
struct in_addr ia;
ia.s_addr = n;
@ -200,7 +201,8 @@ char * _inet_ntoa(u32_t n)
/*
* ipcp_init - Initialize IPCP.
*/
static void ipcp_init(int unit)
static void
ipcp_init(int unit)
{
fsm *f = &ipcp_fsm[unit];
ipcp_options *wo = &ipcp_wantoptions[unit];
@ -224,7 +226,6 @@ static void ipcp_init(int unit)
wo->vj_protocol = IPCP_VJ_COMP;
wo->maxslotindex = MAX_SLOTS - 1;
wo->cflag = 0;
wo->default_route = 1;
ao->neg_addr = 1;
@ -235,7 +236,6 @@ static void ipcp_init(int unit)
#endif /* VJ_SUPPORT */
ao->maxslotindex = MAX_SLOTS - 1;
ao->cflag = 1;
ao->default_route = 1;
}
@ -243,7 +243,8 @@ static void ipcp_init(int unit)
/*
* ipcp_open - IPCP is allowed to come up.
*/
static void ipcp_open(int unit)
static void
ipcp_open(int unit)
{
fsm_open(&ipcp_fsm[unit]);
}
@ -252,7 +253,8 @@ static void ipcp_open(int unit)
/*
* ipcp_close - Take IPCP down.
*/
static void ipcp_close(int unit, char *reason)
static void
ipcp_close(int unit, char *reason)
{
fsm_close(&ipcp_fsm[unit], reason);
}
@ -261,7 +263,8 @@ static void ipcp_close(int unit, char *reason)
/*
* ipcp_lowerup - The lower layer is up.
*/
static void ipcp_lowerup(int unit)
static void
ipcp_lowerup(int unit)
{
fsm_lowerup(&ipcp_fsm[unit]);
}
@ -270,7 +273,8 @@ static void ipcp_lowerup(int unit)
/*
* ipcp_lowerdown - The lower layer is down.
*/
static void ipcp_lowerdown(int unit)
static void
ipcp_lowerdown(int unit)
{
fsm_lowerdown(&ipcp_fsm[unit]);
}
@ -279,7 +283,8 @@ static void ipcp_lowerdown(int unit)
/*
* ipcp_input - Input IPCP packet.
*/
static void ipcp_input(int unit, u_char *p, int len)
static void
ipcp_input(int unit, u_char *p, int len)
{
fsm_input(&ipcp_fsm[unit], p, len);
}
@ -290,7 +295,8 @@ static void ipcp_input(int unit, u_char *p, int len)
*
* Pretend the lower layer went down, so we shut up.
*/
static void ipcp_protrej(int unit)
static void
ipcp_protrej(int unit)
{
fsm_lowerdown(&ipcp_fsm[unit]);
}
@ -299,15 +305,18 @@ static void ipcp_protrej(int unit)
/*
* ipcp_resetci - Reset our CI.
*/
static void ipcp_resetci(fsm *f)
static void
ipcp_resetci(fsm *f)
{
ipcp_options *wo = &ipcp_wantoptions[f->unit];
wo->req_addr = wo->neg_addr && ipcp_allowoptions[f->unit].neg_addr;
if (wo->ouraddr == 0)
if (wo->ouraddr == 0) {
wo->accept_local = 1;
if (wo->hisaddr == 0)
}
if (wo->hisaddr == 0) {
wo->accept_remote = 1;
}
/* Request DNS addresses from the peer */
wo->req_dns1 = ppp_settings.usepeerdns;
wo->req_dns2 = ppp_settings.usepeerdns;
@ -319,7 +328,8 @@ static void ipcp_resetci(fsm *f)
/*
* ipcp_cilen - Return length of our CI.
*/
static int ipcp_cilen(fsm *f)
static int
ipcp_cilen(fsm *f)
{
ipcp_options *go = &ipcp_gotoptions[f->unit];
ipcp_options *wo = &ipcp_wantoptions[f->unit];
@ -353,8 +363,8 @@ static int ipcp_cilen(fsm *f)
}
}
return (LENCIADDR(go->neg_addr, go->old_addrs)
+ LENCIVJ(go->neg_vj, go->old_vj) +
return (LENCIADDR(go->neg_addr, go->old_addrs) +
LENCIVJ(go->neg_vj, go->old_vj) +
LENCIDNS(go->req_dns1) +
LENCIDNS(go->req_dns2));
}
@ -363,7 +373,8 @@ static int ipcp_cilen(fsm *f)
/*
* ipcp_addci - Add our desired CIs to a packet.
*/
static void ipcp_addci(fsm *f, u_char *ucp, int *lenp)
static void
ipcp_addci(fsm *f, u_char *ucp, int *lenp)
{
ipcp_options *go = &ipcp_gotoptions[f->unit];
int len = *lenp;
@ -380,8 +391,9 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp)
PUTCHAR(cflag, ucp); \
} \
len -= vjlen; \
} else \
} else { \
neg = 0; \
} \
}
#define ADDCIADDR(opt, neg, old, val1, val2) \
@ -398,8 +410,9 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp)
PUTLONG(l, ucp); \
} \
len -= addrlen; \
} else \
} else { \
neg = 0; \
} \
}
#define ADDCIDNS(opt, neg, addr) \
@ -411,8 +424,9 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp)
l = ntohl(addr); \
PUTLONG(l, ucp); \
len -= CILEN_ADDR; \
} else \
} else { \
neg = 0; \
} \
}
ADDCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
@ -436,7 +450,8 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp)
* 0 - Ack was bad.
* 1 - Ack was good.
*/
static int ipcp_ackci(fsm *f, u_char *p, int len)
static int
ipcp_ackci(fsm *f, u_char *p, int len)
{
ipcp_options *go = &ipcp_gotoptions[f->unit];
u_short cilen, citype, cishort;
@ -452,63 +467,75 @@ static int ipcp_ackci(fsm *f, u_char *p, int len)
#define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \
if (neg) { \
int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
if ((len -= vjlen) < 0) \
if ((len -= vjlen) < 0) { \
goto bad; \
} \
GETCHAR(citype, p); \
GETCHAR(cilen, p); \
if (cilen != vjlen || \
citype != opt) \
citype != opt) { \
goto bad; \
} \
GETSHORT(cishort, p); \
if (cishort != val) \
if (cishort != val) { \
goto bad; \
} \
if (!old) { \
GETCHAR(cimaxslotindex, p); \
if (cimaxslotindex != maxslotindex) \
if (cimaxslotindex != maxslotindex) { \
goto bad; \
} \
GETCHAR(cicflag, p); \
if (cicflag != cflag) \
if (cicflag != cflag) { \
goto bad; \
} \
} \
}
#define ACKCIADDR(opt, neg, old, val1, val2) \
if (neg) { \
int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
u32_t l; \
if ((len -= addrlen) < 0) \
if ((len -= addrlen) < 0) { \
goto bad; \
} \
GETCHAR(citype, p); \
GETCHAR(cilen, p); \
if (cilen != addrlen || \
citype != opt) \
citype != opt) { \
goto bad; \
} \
GETLONG(l, p); \
cilong = htonl(l); \
if (val1 != cilong) \
if (val1 != cilong) { \
goto bad; \
} \
if (old) { \
GETLONG(l, p); \
cilong = htonl(l); \
if (val2 != cilong) \
if (val2 != cilong) { \
goto bad; \
} \
} \
}
#define ACKCIDNS(opt, neg, addr) \
if (neg) { \
u32_t l; \
if ((len -= CILEN_ADDR) < 0) \
if ((len -= CILEN_ADDR) < 0) { \
goto bad; \
} \
GETCHAR(citype, p); \
GETCHAR(cilen, p); \
if (cilen != CILEN_ADDR || \
citype != opt) \
citype != opt) { \
goto bad; \
} \
GETLONG(l, p); \
cilong = htonl(l); \
if (addr != cilong) \
if (addr != cilong) { \
goto bad; \
} \
}
ACKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
@ -524,8 +551,9 @@ static int ipcp_ackci(fsm *f, u_char *p, int len)
/*
* If there are any remaining CIs, then this packet is bad.
*/
if (len != 0)
if (len != 0) {
goto bad;
}
return (1);
bad:
@ -542,7 +570,8 @@ bad:
* 0 - Nak was bad.
* 1 - Nak was good.
*/
static int ipcp_nakci(fsm *f, u_char *p, int len)
static int
ipcp_nakci(fsm *f, u_char *p, int len)
{
ipcp_options *go = &ipcp_gotoptions[f->unit];
u_char cimaxslotindex, cicflag;
@ -573,8 +602,9 @@ static int ipcp_nakci(fsm *f, u_char *p, int len)
GETLONG(l, p); \
ciaddr2 = htonl(l); \
no.old_addrs = 1; \
} else \
} else { \
ciaddr2 = 0; \
} \
no.neg = 1; \
code \
}
@ -633,10 +663,12 @@ static int ipcp_nakci(fsm *f, u_char *p, int len)
GETCHAR(cicflag, p);
if (cishort == IPCP_VJ_COMP) {
try.old_vj = 0;
if (cimaxslotindex < go->maxslotindex)
if (cimaxslotindex < go->maxslotindex) {
try.maxslotindex = cimaxslotindex;
if (!cicflag)
}
if (!cicflag) {
try.cflag = 0;
}
} else {
try.neg_vj = 0;
}
@ -669,43 +701,51 @@ static int ipcp_nakci(fsm *f, u_char *p, int len)
while (len > CILEN_VOID) {
GETCHAR(citype, p);
GETCHAR(cilen, p);
if( (len -= cilen) < 0 )
if( (len -= cilen) < 0 ) {
goto bad;
}
next = p + cilen - 2;
switch (citype) {
case CI_COMPRESSTYPE:
if (go->neg_vj || no.neg_vj ||
(cilen != CILEN_VJ && cilen != CILEN_COMPRESS))
(cilen != CILEN_VJ && cilen != CILEN_COMPRESS)) {
goto bad;
}
no.neg_vj = 1;
break;
case CI_ADDRS:
if ((go->neg_addr && go->old_addrs) || no.old_addrs
|| cilen != CILEN_ADDRS)
|| cilen != CILEN_ADDRS) {
goto bad;
}
try.neg_addr = 1;
try.old_addrs = 1;
GETLONG(l, p);
ciaddr1 = htonl(l);
if (ciaddr1 && go->accept_local)
if (ciaddr1 && go->accept_local) {
try.ouraddr = ciaddr1;
}
GETLONG(l, p);
ciaddr2 = htonl(l);
if (ciaddr2 && go->accept_remote)
if (ciaddr2 && go->accept_remote) {
try.hisaddr = ciaddr2;
}
no.old_addrs = 1;
break;
case CI_ADDR:
if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR)
if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR) {
goto bad;
}
try.old_addrs = 0;
GETLONG(l, p);
ciaddr1 = htonl(l);
if (ciaddr1 && go->accept_local)
if (ciaddr1 && go->accept_local) {
try.ouraddr = ciaddr1;
if (try.ouraddr != 0)
}
if (try.ouraddr != 0) {
try.neg_addr = 1;
}
no.neg_addr = 1;
break;
}
@ -713,14 +753,16 @@ static int ipcp_nakci(fsm *f, u_char *p, int len)
}
/* If there is still anything left, this packet is bad. */
if (len != 0)
if (len != 0) {
goto bad;
}
/*
* OK, the Nak is good. Now we can update state.
*/
if (f->state != LS_OPENED)
if (f->state != LS_OPENED) {
*go = try;
}
return 1;
@ -733,7 +775,8 @@ bad:
/*
* ipcp_rejci - Reject some of our CIs.
*/
static int ipcp_rejci(fsm *f, u_char *p, int len)
static int
ipcp_rejci(fsm *f, u_char *p, int len)
{
ipcp_options *go = &ipcp_gotoptions[f->unit];
u_char cimaxslotindex, ciflag, cilen;
@ -758,15 +801,17 @@ static int ipcp_rejci(fsm *f, u_char *p, int len)
GETLONG(l, p); \
cilong = htonl(l); \
/* Check rejected value. */ \
if (cilong != val1) \
if (cilong != val1) { \
goto bad; \
} \
if (old) { \
GETLONG(l, p); \
cilong = htonl(l); \
/* Check rejected value. */ \
if (cilong != val2) \
if (cilong != val2) { \
goto bad; \
} \
} \
try.neg = 0; \
}
@ -779,16 +824,19 @@ static int ipcp_rejci(fsm *f, u_char *p, int len)
INCPTR(2, p); \
GETSHORT(cishort, p); \
/* Check rejected value. */ \
if (cishort != val) \
if (cishort != val) { \
goto bad; \
} \
if (!old) { \
GETCHAR(cimaxslotindex, p); \
if (cimaxslotindex != maxslot) \
if (cimaxslotindex != maxslot) { \
goto bad; \
} \
GETCHAR(ciflag, p); \
if (ciflag != cflag) \
if (ciflag != cflag) { \
goto bad; \
} \
} \
try.neg = 0; \
}
@ -803,8 +851,9 @@ static int ipcp_rejci(fsm *f, u_char *p, int len)
GETLONG(l, p); \
cilong = htonl(l); \
/* Check rejected value. */ \
if (cilong != dnsaddr) \
if (cilong != dnsaddr) { \
goto bad; \
} \
try.neg = 0; \
}
@ -821,13 +870,15 @@ static int ipcp_rejci(fsm *f, u_char *p, int len)
/*
* If there are any remaining CIs, then this packet is bad.
*/
if (len != 0)
if (len != 0) {
goto bad;
}
/*
* Now we can update state.
*/
if (f->state != LS_OPENED)
if (f->state != LS_OPENED) {
*go = try;
}
return 1;
bad:
@ -843,12 +894,8 @@ bad:
* appropriately. If reject_if_disagree is non-zero, doesn't return
* CONFNAK; returns CONFREJ if it can't return CONFACK.
*/
static int ipcp_reqci(
fsm *f,
u_char *inp, /* Requested CIs */
int *len, /* Length of requested CIs */
int reject_if_disagree
)
static int
ipcp_reqci(fsm *f, u_char *inp/* Requested CIs */,int *len/* Length of requested CIs */,int reject_if_disagree)
{
ipcp_options *wo = &ipcp_wantoptions[f->unit];
ipcp_options *ho = &ipcp_hisoptions[f->unit];
@ -1110,16 +1157,18 @@ static int ipcp_reqci(
endswitch:
if (orc == CONFACK && /* Good CI */
rc != CONFACK) /* but prior CI wasnt? */
rc != CONFACK) { /* but prior CI wasnt? */
continue; /* Don't send this one */
}
if (orc == CONFNAK) { /* Nak this CI? */
if (reject_if_disagree) { /* Getting fed up with sending NAKs? */
IPCPDEBUG((LOG_INFO, "ipcp_reqci: Rejecting too many naks\n"));
orc = CONFREJ; /* Get tough if so */
} else {
if (rc == CONFREJ) /* Rejecting prior CI? */
if (rc == CONFREJ) { /* Rejecting prior CI? */
continue; /* Don't send this one */
}
if (rc == CONFACK) { /* Ack'd all prior CIs? */
rc = CONFNAK; /* Not anymore... */
ucp = inp; /* Backup */
@ -1134,8 +1183,9 @@ endswitch:
}
/* Need to move CI? */
if (ucp != cip)
if (ucp != cip) {
BCOPY(cip, ucp, cilen); /* Move it */
}
/* Update output pointer */
INCPTR(cilen, ucp);
@ -1173,7 +1223,8 @@ endswitch:
* ip_check_options - check that any IP-related options are OK,
* and assign appropriate defaults.
*/
static void ip_check_options(u_long localAddr)
static void
ip_check_options(u_long localAddr)
{
ipcp_options *wo = &ipcp_wantoptions[0];
@ -1194,7 +1245,8 @@ static void ip_check_options(u_long localAddr)
*
* Configure the IP network interface appropriately and bring it up.
*/
static void ipcp_up(fsm *f)
static void
ipcp_up(fsm *f)
{
u32_t mask;
ipcp_options *ho = &ipcp_hisoptions[f->unit];
@ -1207,8 +1259,9 @@ static void ipcp_up(fsm *f)
/*
* We must have a non-zero IP address for both ends of the link.
*/
if (!ho->neg_addr)
if (!ho->neg_addr) {
ho->hisaddr = wo->hisaddr;
}
if (ho->hisaddr == 0) {
IPCPDEBUG((LOG_ERR, "Could not determine remote IP address\n"));
@ -1259,9 +1312,11 @@ static void ipcp_up(fsm *f)
sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
/* assign a default route through the interface if required */
if (ipcp_wantoptions[f->unit].default_route)
if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
if (ipcp_wantoptions[f->unit].default_route) {
if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr)) {
default_route_set[f->unit] = 1;
}
}
IPCPDEBUG((LOG_NOTICE, "local IP address %s\n", inet_ntoa(go->ouraddr)));
IPCPDEBUG((LOG_NOTICE, "remote IP address %s\n", inet_ntoa(ho->hisaddr)));
@ -1280,7 +1335,8 @@ static void ipcp_up(fsm *f)
* Take the IP network interface down, clear its addresses
* and delete routes through it.
*/
static void ipcp_down(fsm *f)
static void
ipcp_down(fsm *f)
{
IPCPDEBUG((LOG_INFO, "ipcp: down\n"));
np_down(f->unit, PPP_IP);
@ -1294,7 +1350,8 @@ static void ipcp_down(fsm *f)
/*
* ipcp_clear_addrs() - clear the interface addresses, routes, etc.
*/
static void ipcp_clear_addrs(int unit)
static void
ipcp_clear_addrs(int unit)
{
u32_t ouraddr, hisaddr;
@ -1311,18 +1368,15 @@ static void ipcp_clear_addrs(int unit)
/*
* ipcp_finished - possibly shut down the lower layers.
*/
static void ipcp_finished(fsm *f)
static void
ipcp_finished(fsm *f)
{
np_finished(f->unit, PPP_IP);
}
#if 0
static int ipcp_printpkt(
u_char *p,
int plen,
void (*printer) (void *, char *, ...),
void *arg
)
static int
ipcp_printpkt(u_char *p, int plen, void (*printer) (void *, char *, ...), void *arg)
{
LWIP_UNUSED_ARG(p);
LWIP_UNUSED_ARG(plen);
@ -1354,25 +1408,31 @@ static int ipcp_printpkt(
#define get_tcpoff(x) (((unsigned char *)(x))[12] >> 4)
#define get_tcpflags(x) (((unsigned char *)(x))[13])
static int ip_active_pkt(u_char *pkt, int len)
static int
ip_active_pkt(u_char *pkt, int len)
{
u_char *tcp;
int hlen;
len -= PPP_HDRLEN;
pkt += PPP_HDRLEN;
if (len < IP_HDRLEN)
if (len < IP_HDRLEN) {
return 0;
if ((get_ipoff(pkt) & IP_OFFMASK) != 0)
}
if ((get_ipoff(pkt) & IP_OFFMASK) != 0) {
return 0;
if (get_ipproto(pkt) != IPPROTO_TCP)
}
if (get_ipproto(pkt) != IPPROTO_TCP) {
return 1;
}
hlen = get_iphl(pkt) * 4;
if (len < hlen + TCP_HDRLEN)
if (len < hlen + TCP_HDRLEN) {
return 0;
}
tcp = pkt + hlen;
if ((get_tcpflags(tcp) & TH_FIN) != 0 && len == hlen + get_tcpoff(tcp) * 4)
if ((get_tcpflags(tcp) & TH_FIN) != 0 && len == hlen + get_tcpoff(tcp) * 4) {
return 0;
}
return 1;
}
#endif

View File

@ -48,7 +48,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ipcp.h,v 1.2 2007/11/29 22:19:57 fbernon Exp $
* $Id: ipcp.h,v 1.3 2007/12/19 20:47:23 fbernon Exp $
*/
#ifndef IPCP_H

View File

@ -127,8 +127,7 @@ static void LcpEchoCheck (fsm*);
static void lcp_input (int, u_char *, int);
static void lcp_protrej (int);
#define CODENAME(x) ((x) == CONFACK ? "ACK" : \
(x) == CONFNAK ? "NAK" : "REJ")
#define CODENAME(x) ((x) == CONFACK ? "ACK" : (x) == CONFNAK ? "NAK" : "REJ")
/******************************/
@ -206,7 +205,8 @@ int lcp_loopbackfail = DEFLOOPBACKFAIL;
/*
* lcp_init - Initialize LCP.
*/
void lcp_init(int unit)
void
lcp_init(int unit)
{
fsm *f = &lcp_fsm[unit];
lcp_options *wo = &lcp_wantoptions[unit];
@ -220,8 +220,7 @@ void lcp_init(int unit)
wo->passive = 0;
wo->silent = 0;
wo->restart = 0; /* Set to 1 in kernels or multi-line
* implementations */
wo->restart = 0; /* Set to 1 in kernels or multi-line implementations */
wo->neg_mru = 1;
wo->mru = PPP_DEFMRU;
wo->neg_asyncmap = 1;
@ -254,7 +253,7 @@ void lcp_init(int unit)
*/
memset(xmit_accm[unit], 0, sizeof(xmit_accm[0]));
xmit_accm[unit][15] = 0x60;
xmit_accm[unit][0] = (u_char)(ao->asyncmap & 0xFF);
xmit_accm[unit][0] = (u_char)((ao->asyncmap & 0xFF));
xmit_accm[unit][1] = (u_char)((ao->asyncmap >> 8) & 0xFF);
xmit_accm[unit][2] = (u_char)((ao->asyncmap >> 16) & 0xFF);
xmit_accm[unit][3] = (u_char)((ao->asyncmap >> 24) & 0xFF);
@ -271,16 +270,19 @@ void lcp_init(int unit)
/*
* lcp_open - LCP is allowed to come up.
*/
void lcp_open(int unit)
void
lcp_open(int unit)
{
fsm *f = &lcp_fsm[unit];
lcp_options *wo = &lcp_wantoptions[unit];
f->flags = 0;
if (wo->passive)
if (wo->passive) {
f->flags |= OPT_PASSIVE;
if (wo->silent)
}
if (wo->silent) {
f->flags |= OPT_SILENT;
}
fsm_open(f);
lcp_phase[unit] = PHASE_ESTABLISH;
@ -290,12 +292,14 @@ void lcp_open(int unit)
/*
* lcp_close - Take LCP down.
*/
void lcp_close(int unit, char *reason)
void
lcp_close(int unit, char *reason)
{
fsm *f = &lcp_fsm[unit];
if (lcp_phase[unit] != PHASE_DEAD)
if (lcp_phase[unit] != PHASE_DEAD) {
lcp_phase[unit] = PHASE_TERMINATE;
}
if (f->state == LS_STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
/*
* This action is not strictly according to the FSM in RFC1548,
@ -305,16 +309,17 @@ void lcp_close(int unit, char *reason)
*/
f->state = LS_CLOSED;
lcp_finished(f);
}
else
} else {
fsm_close(&lcp_fsm[unit], reason);
}
}
/*
* lcp_lowerup - The lower layer is up.
*/
void lcp_lowerup(int unit)
void
lcp_lowerup(int unit)
{
lcp_options *wo = &lcp_wantoptions[unit];
@ -328,8 +333,7 @@ void lcp_lowerup(int unit)
ppp_recv_config(unit, PPP_MRU, 0x00000000l,
wo->neg_pcompression, wo->neg_accompression);
peer_mru[unit] = PPP_MRU;
lcp_allowoptions[unit].asyncmap
= (u_long)xmit_accm[unit][0]
lcp_allowoptions[unit].asyncmap = (u_long)xmit_accm[unit][0]
| ((u_long)xmit_accm[unit][1] << 8)
| ((u_long)xmit_accm[unit][2] << 16)
| ((u_long)xmit_accm[unit][3] << 24);
@ -346,7 +350,8 @@ void lcp_lowerup(int unit)
/*
* lcp_lowerdown - The lower layer is down.
*/
void lcp_lowerdown(int unit)
void
lcp_lowerdown(int unit)
{
fsm_lowerdown(&lcp_fsm[unit]);
}
@ -354,15 +359,15 @@ void lcp_lowerdown(int unit)
/*
* lcp_sprotrej - Send a Protocol-Reject for some protocol.
*/
void lcp_sprotrej(int unit, u_char *p, int len)
void
lcp_sprotrej(int unit, u_char *p, int len)
{
/*
* Send back the protocol and the information field of the
* rejected packet. We only get here if LCP is in the LS_OPENED state.
*/
fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id,
p, len);
fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id, p, len);
}
@ -373,7 +378,8 @@ void lcp_sprotrej(int unit, u_char *p, int len)
/*
* lcp_input - Input LCP packet.
*/
static void lcp_input(int unit, u_char *p, int len)
static void
lcp_input(int unit, u_char *p, int len)
{
fsm *f = &lcp_fsm[unit];
@ -384,7 +390,8 @@ static void lcp_input(int unit, u_char *p, int len)
/*
* lcp_extcode - Handle a LCP-specific code.
*/
static int lcp_extcode(fsm *f, int code, u_char id, u_char *inp, int len)
static int
lcp_extcode(fsm *f, int code, u_char id, u_char *inp, int len)
{
u_char *magp;
@ -394,8 +401,9 @@ static int lcp_extcode(fsm *f, int code, u_char id, u_char *inp, int len)
break;
case ECHOREQ:
if (f->state != LS_OPENED)
if (f->state != LS_OPENED) {
break;
}
LCPDEBUG((LOG_INFO, "lcp: Echo-Request, Rcvd id %d\n", id));
magp = inp;
PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
@ -421,59 +429,56 @@ static int lcp_extcode(fsm *f, int code, u_char id, u_char *inp, int len)
*
* Figure out which protocol is rejected and inform it.
*/
static void lcp_rprotrej(fsm *f, u_char *inp, int len)
static void
lcp_rprotrej(fsm *f, u_char *inp, int len)
{
int i;
struct protent *protp;
u_short prot;
if (len < sizeof (u_short)) {
LCPDEBUG((LOG_INFO,
"lcp_rprotrej: Rcvd short Protocol-Reject packet!\n"));
LCPDEBUG((LOG_INFO, "lcp_rprotrej: Rcvd short Protocol-Reject packet!\n"));
return;
}
GETSHORT(prot, inp);
LCPDEBUG((LOG_INFO,
"lcp_rprotrej: Rcvd Protocol-Reject packet for %x!\n",
prot));
LCPDEBUG((LOG_INFO, "lcp_rprotrej: Rcvd Protocol-Reject packet for %x!\n", prot));
/*
* Protocol-Reject packets received in any state other than the LCP
* LS_OPENED state SHOULD be silently discarded.
*/
if( f->state != LS_OPENED ) {
LCPDEBUG((LOG_INFO, "Protocol-Reject discarded: LCP in state %d\n",
f->state));
LCPDEBUG((LOG_INFO, "Protocol-Reject discarded: LCP in state %d\n", f->state));
return;
}
/*
* Upcall the proper Protocol-Reject routine.
*/
for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i)
for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
if (protp->protocol == prot && protp->enabled_flag) {
(*protp->protrej)(f->unit);
return;
}
}
LCPDEBUG((LOG_WARNING, "Protocol-Reject for unsupported protocol 0x%x\n",
prot));
LCPDEBUG((LOG_WARNING, "Protocol-Reject for unsupported protocol 0x%x\n", prot));
}
/*
* lcp_protrej - A Protocol-Reject was received.
*/
static void lcp_protrej(int unit)
static void
lcp_protrej(int unit)
{
LWIP_UNUSED_ARG(unit);
/*
* Can't reject LCP!
*/
LCPDEBUG((LOG_WARNING,
"lcp_protrej: Received Protocol-Reject for LCP!\n"));
LCPDEBUG((LOG_WARNING, "lcp_protrej: Received Protocol-Reject for LCP!\n"));
fsm_protreject(&lcp_fsm[unit]);
}
@ -481,7 +486,8 @@ static void lcp_protrej(int unit)
/*
* lcp_resetci - Reset our CI.
*/
static void lcp_resetci(fsm *f)
static void
lcp_resetci(fsm *f)
{
lcp_wantoptions[f->unit].magicnumber = magic();
lcp_wantoptions[f->unit].numloops = 0;
@ -523,7 +529,8 @@ static int lcp_cilen(fsm *f)
/*
* lcp_addci - Add our desired CIs to a packet.
*/
static void lcp_addci(fsm *f, u_char *ucp, int *lenp)
static void
lcp_addci(fsm *f, u_char *ucp, int *lenp)
{
lcp_options *go = &lcp_gotoptions[f->unit];
u_char *start_ucp = ucp;
@ -573,8 +580,7 @@ static void lcp_addci(fsm *f, u_char *ucp, int *lenp)
}
ADDCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_DEFMRU, go->mru);
ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl,
go->asyncmap);
ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl, go->asyncmap);
ADDCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
@ -598,7 +604,8 @@ static void lcp_addci(fsm *f, u_char *ucp, int *lenp)
* 0 - Ack was bad.
* 1 - Ack was good.
*/
static int lcp_ackci(fsm *f, u_char *p, int len)
static int
lcp_ackci(fsm *f, u_char *p, int len)
{
lcp_options *go = &lcp_gotoptions[f->unit];
u_char cilen, citype, cichar;
@ -616,8 +623,7 @@ static int lcp_ackci(fsm *f, u_char *p, int len)
goto bad; \
GETCHAR(citype, p); \
GETCHAR(cilen, p); \
if (cilen != CILEN_VOID || \
citype != opt) \
if (cilen != CILEN_VOID || citype != opt) \
goto bad; \
}
#define ACKCISHORT(opt, neg, val) \
@ -626,8 +632,7 @@ static int lcp_ackci(fsm *f, u_char *p, int len)
goto bad; \
GETCHAR(citype, p); \
GETCHAR(cilen, p); \
if (cilen != CILEN_SHORT || \
citype != opt) \
if (cilen != CILEN_SHORT || citype != opt) \
goto bad; \
GETSHORT(cishort, p); \
if (cishort != val) \
@ -639,8 +644,7 @@ static int lcp_ackci(fsm *f, u_char *p, int len)
goto bad; \
GETCHAR(citype, p); \
GETCHAR(cilen, p); \
if (cilen != CILEN_CHAR || \
citype != opt) \
if (cilen != CILEN_CHAR || citype != opt) \
goto bad; \
GETCHAR(cichar, p); \
if (cichar != val) \
@ -652,8 +656,7 @@ static int lcp_ackci(fsm *f, u_char *p, int len)
goto bad; \
GETCHAR(citype, p); \
GETCHAR(cilen, p); \
if (cilen != CILEN_CHAP || \
citype != opt) \
if (cilen != CILEN_CHAP || citype != opt) \
goto bad; \
GETSHORT(cishort, p); \
if (cishort != val) \
@ -668,8 +671,7 @@ static int lcp_ackci(fsm *f, u_char *p, int len)
goto bad; \
GETCHAR(citype, p); \
GETCHAR(cilen, p); \
if (cilen != CILEN_LONG || \
citype != opt) \
if (cilen != CILEN_LONG || citype != opt) \
goto bad; \
GETLONG(cilong, p); \
if (cilong != val) \
@ -681,8 +683,7 @@ static int lcp_ackci(fsm *f, u_char *p, int len)
goto bad; \
GETCHAR(citype, p); \
GETCHAR(cilen, p); \
if (cilen != CILEN_LQR || \
citype != opt) \
if (cilen != CILEN_LQR || citype != opt) \
goto bad; \
GETSHORT(cishort, p); \
if (cishort != PPP_LQR) \
@ -693,8 +694,7 @@ static int lcp_ackci(fsm *f, u_char *p, int len)
}
ACKCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_DEFMRU, go->mru);
ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl,
go->asyncmap);
ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl, go->asyncmap);
ACKCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
@ -706,8 +706,9 @@ static int lcp_ackci(fsm *f, u_char *p, int len)
/*
* If there are any remaining CIs, then this packet is bad.
*/
if (len != 0)
if (len != 0) {
goto bad;
}
LCPDEBUG((LOG_INFO, "lcp_acki: Ack\n"));
return (1);
bad:
@ -725,7 +726,8 @@ bad:
* 0 - Nak was bad.
* 1 - Nak was good.
*/
static int lcp_nakci(fsm *f, u_char *p, int len)
static int
lcp_nakci(fsm *f, u_char *p, int len)
{
lcp_options *go = &lcp_gotoptions[f->unit];
lcp_options *wo = &lcp_wantoptions[f->unit];
@ -822,8 +824,9 @@ static int lcp_nakci(fsm *f, u_char *p, int len)
*/
if (go->neg_mru && go->mru != PPP_DEFMRU) {
NAKCISHORT(CI_MRU, neg_mru,
if (cishort <= wo->mru || cishort < PPP_DEFMRU)
if (cishort <= wo->mru || cishort < PPP_DEFMRU) {
try.mru = cishort;
}
);
}
@ -856,8 +859,9 @@ static int lcp_nakci(fsm *f, u_char *p, int len)
* If we weren't asking for CHAP, then we were asking for PAP,
* in which case this Nak is bad.
*/
if (!go->neg_chap)
if (!go->neg_chap) {
goto bad;
}
try.neg_chap = 0;
} else if (cishort == PPP_CHAP && cilen == CILEN_CHAP) {
@ -868,8 +872,9 @@ static int lcp_nakci(fsm *f, u_char *p, int len)
* algorithm. If they can't do MD5, we'll have to stop
* asking for CHAP.
*/
if (cichar != go->chap_mdtype)
if (cichar != go->chap_mdtype) {
try.neg_chap = 0;
}
} else {
/*
* Stop asking for PAP if we were asking for it.
@ -882,10 +887,11 @@ static int lcp_nakci(fsm *f, u_char *p, int len)
* We don't recognize what they're suggesting.
* Stop asking for what we were asking for.
*/
if (go->neg_chap)
if (go->neg_chap) {
try.neg_chap = 0;
else
} else {
try.neg_upap = 0;
}
p += cilen - CILEN_SHORT;
}
}
@ -896,10 +902,11 @@ static int lcp_nakci(fsm *f, u_char *p, int len)
* If they Nak the reporting period, take their value XXX ?
*/
NAKCILQR(CI_QUALITY, neg_lqr,
if (cishort != PPP_LQR)
if (cishort != PPP_LQR) {
try.neg_lqr = 0;
else
} else {
try.lqr_period = cilong;
}
);
/*
@ -948,54 +955,64 @@ static int lcp_nakci(fsm *f, u_char *p, int len)
while (len > CILEN_VOID) {
GETCHAR(citype, p);
GETCHAR(cilen, p);
if (cilen < CILEN_VOID || (len -= cilen) < 0)
if (cilen < CILEN_VOID || (len -= cilen) < 0) {
goto bad;
}
next = p + cilen - 2;
switch (citype) {
case CI_MRU:
if ((go->neg_mru && go->mru != PPP_DEFMRU)
|| no.neg_mru || cilen != CILEN_SHORT)
|| no.neg_mru || cilen != CILEN_SHORT) {
goto bad;
}
GETSHORT(cishort, p);
if (cishort < PPP_DEFMRU)
if (cishort < PPP_DEFMRU) {
try.mru = cishort;
}
break;
case CI_ASYNCMAP:
if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl)
|| no.neg_asyncmap || cilen != CILEN_LONG)
|| no.neg_asyncmap || cilen != CILEN_LONG) {
goto bad;
}
break;
case CI_AUTHTYPE:
if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap)
if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap) {
goto bad;
}
break;
case CI_MAGICNUMBER:
if (go->neg_magicnumber || no.neg_magicnumber ||
cilen != CILEN_LONG)
cilen != CILEN_LONG) {
goto bad;
}
break;
case CI_PCOMPRESSION:
if (go->neg_pcompression || no.neg_pcompression
|| cilen != CILEN_VOID)
|| cilen != CILEN_VOID) {
goto bad;
}
break;
case CI_ACCOMPRESSION:
if (go->neg_accompression || no.neg_accompression
|| cilen != CILEN_VOID)
|| cilen != CILEN_VOID) {
goto bad;
}
break;
case CI_QUALITY:
if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR)
if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR) {
goto bad;
}
break;
}
p = next;
}
/* If there is still anything left, this packet is bad. */
if (len != 0)
if (len != 0) {
goto bad;
}
/*
* OK, the Nak is good. Now we can update state.
@ -1006,9 +1023,9 @@ static int lcp_nakci(fsm *f, u_char *p, int len)
LCPDEBUG((LOG_NOTICE, "Serial line is looped back.\n"));
lcp_close(f->unit, "Loopback detected");
}
}
else
} else {
try.numloops = 0;
}
*go = try;
}
@ -1029,7 +1046,8 @@ bad:
* 0 - Reject was bad.
* 1 - Reject was good.
*/
static int lcp_rejci(fsm *f, u_char *p, int len)
static int
lcp_rejci(fsm *f, u_char *p, int len)
{
lcp_options *go = &lcp_gotoptions[f->unit];
u_char cichar;
@ -1063,8 +1081,9 @@ static int lcp_rejci(fsm *f, u_char *p, int len)
INCPTR(2, p); \
GETSHORT(cishort, p); \
/* Check rejected value. */ \
if (cishort != val) \
if (cishort != val) { \
goto bad; \
} \
try.neg = 0; \
LCPDEBUG((LOG_INFO,"lcp_rejci: short opt %d rejected\n", opt)); \
}
@ -1078,8 +1097,9 @@ static int lcp_rejci(fsm *f, u_char *p, int len)
GETSHORT(cishort, p); \
GETCHAR(cichar, p); \
/* Check rejected value. */ \
if (cishort != val || cichar != digest) \
if (cishort != val || cichar != digest) { \
goto bad; \
} \
try.neg = 0; \
try.neg_upap = 0; \
LCPDEBUG((LOG_INFO,"lcp_rejci: chap opt %d rejected\n", opt)); \
@ -1093,8 +1113,9 @@ static int lcp_rejci(fsm *f, u_char *p, int len)
INCPTR(2, p); \
GETLONG(cilong, p); \
/* Check rejected value. */ \
if (cilong != val) \
if (cilong != val) { \
goto bad; \
} \
try.neg = 0; \
LCPDEBUG((LOG_INFO,"lcp_rejci: long opt %d rejected\n", opt)); \
}
@ -1108,8 +1129,9 @@ static int lcp_rejci(fsm *f, u_char *p, int len)
GETSHORT(cishort, p); \
GETLONG(cilong, p); \
/* Check rejected value. */ \
if (cishort != PPP_LQR || cilong != val) \
if (cishort != PPP_LQR || cilong != val) { \
goto bad; \
} \
try.neg = 0; \
LCPDEBUG((LOG_INFO,"lcp_rejci: LQR opt %d rejected\n", opt)); \
}
@ -1122,8 +1144,9 @@ static int lcp_rejci(fsm *f, u_char *p, int len)
INCPTR(2, p); \
GETCHAR(cichar, p); \
/* Check rejected value. */ \
if (cichar != val) \
if (cichar != val) { \
goto bad; \
} \
try.neg = 0; \
LCPDEBUG((LOG_INFO,"lcp_rejci: Callback opt %d rejected\n", opt)); \
}
@ -1143,13 +1166,15 @@ static int lcp_rejci(fsm *f, u_char *p, int len)
/*
* If there are any remaining CIs, then this packet is bad.
*/
if (len != 0)
if (len != 0) {
goto bad;
}
/*
* Now we can update state.
*/
if (f->state != LS_OPENED)
if (f->state != LS_OPENED) {
*go = try;
}
return 1;
bad:
@ -1165,7 +1190,8 @@ bad:
* appropriately. If reject_if_disagree is non-zero, doesn't return
* CONFNAK; returns CONFREJ if it can't return CONFACK.
*/
static int lcp_reqci(fsm *f,
static int
lcp_reqci(fsm *f,
u_char *inp, /* Requested CIs */
int *lenp, /* Length of requested CIs */
int reject_if_disagree)
@ -1389,8 +1415,7 @@ static int lcp_reqci(fsm *f,
PUTCHAR(CILEN_CHAP, nakp);
PUTSHORT(PPP_CHAP, nakp);
PUTCHAR(ao->chap_mdtype, nakp);
}
else {
} else {
LCPDEBUG((LOG_WARNING, "lcp_reqci: Nak AUTHTYPE %d req PAP\n", cishort));
PUTCHAR(CILEN_SHORT, nakp);
PUTSHORT(PPP_PAP, nakp);
@ -1521,24 +1546,26 @@ static int lcp_reqci(fsm *f,
}
#endif
if (orc == CONFACK && /* Good CI */
rc != CONFACK) /* but prior CI wasnt? */
rc != CONFACK) { /* but prior CI wasnt? */
continue; /* Don't send this one */
}
if (orc == CONFNAK) { /* Nak this CI? */
if (reject_if_disagree /* Getting fed up with sending NAKs? */
&& citype != CI_MAGICNUMBER) {
orc = CONFREJ; /* Get tough if so */
}
else {
if (rc == CONFREJ) /* Rejecting prior CI? */
} else {
if (rc == CONFREJ) { /* Rejecting prior CI? */
continue; /* Don't send this one */
}
rc = CONFNAK;
}
}
if (orc == CONFREJ) { /* Reject this CI */
rc = CONFREJ;
if (cip != rejp) /* Need to move rejected CI? */
if (cip != rejp) { /* Need to move rejected CI? */
BCOPY(cip, rejp, cilen); /* Move it */
}
INCPTR(cilen, rejp); /* Update output pointer */
}
}
@ -1579,17 +1606,20 @@ static int lcp_reqci(fsm *f,
/*
* lcp_up - LCP has come UP.
*/
static void lcp_up(fsm *f)
static void
lcp_up(fsm *f)
{
lcp_options *wo = &lcp_wantoptions[f->unit];
lcp_options *ho = &lcp_hisoptions[f->unit];
lcp_options *go = &lcp_gotoptions[f->unit];
lcp_options *ao = &lcp_allowoptions[f->unit];
if (!go->neg_magicnumber)
if (!go->neg_magicnumber) {
go->magicnumber = 0;
if (!ho->neg_magicnumber)
}
if (!ho->neg_magicnumber) {
ho->magicnumber = 0;
}
/*
* Set our MTU to the smaller of the MTU we wanted and
@ -1609,8 +1639,9 @@ static void lcp_up(fsm *f)
(go->neg_asyncmap? go->asyncmap: 0x00000000),
go->neg_pcompression, go->neg_accompression);
if (ho->neg_mru)
if (ho->neg_mru) {
peer_mru[f->unit] = ho->mru;
}
lcp_echo_lowerup(f->unit); /* Enable echo messages */
@ -1623,7 +1654,8 @@ static void lcp_up(fsm *f)
*
* Alert other protocols.
*/
static void lcp_down(fsm *f)
static void
lcp_down(fsm *f)
{
lcp_options *go = &lcp_gotoptions[f->unit];
@ -1642,7 +1674,8 @@ static void lcp_down(fsm *f)
/*
* lcp_starting - LCP needs the lower layer up.
*/
static void lcp_starting(fsm *f)
static void
lcp_starting(fsm *f)
{
link_required(f->unit);
}
@ -1651,7 +1684,8 @@ static void lcp_starting(fsm *f)
/*
* lcp_finished - LCP has finished with the lower layer.
*/
static void lcp_finished(fsm *f)
static void
lcp_finished(fsm *f)
{
link_terminated(f->unit);
}
@ -1662,12 +1696,8 @@ static void lcp_finished(fsm *f)
* print_string - print a readable representation of a string using
* printer.
*/
static void print_string(
char *p,
int len,
void (*printer) (void *, char *, ...),
void *arg
)
static void
print_string( char *p, int len, void (*printer) (void *, char *, ...), void *arg)
{
int c;
@ -1675,8 +1705,9 @@ static void print_string(
for (; len > 0; --len) {
c = *p++;
if (' ' <= c && c <= '~') {
if (c == '\\' || c == '"')
if (c == '\\' || c == '"') {
printer(arg, "\\");
}
printer(arg, "%c", c);
} else {
switch (c) {
@ -1707,31 +1738,30 @@ static char *lcp_codenames[] = {
"EchoReq", "EchoRep", "DiscReq"
};
static int lcp_printpkt(
u_char *p,
int plen,
void (*printer) (void *, char *, ...),
void *arg
)
static int
lcp_printpkt( u_char *p, int plen, void (*printer) (void *, char *, ...), void *arg)
{
int code, id, len, olen;
u_char *pstart, *optend;
u_short cishort;
u32_t cilong;
if (plen < HEADERLEN)
if (plen < HEADERLEN) {
return 0;
}
pstart = p;
GETCHAR(code, p);
GETCHAR(id, p);
GETSHORT(len, p);
if (len < HEADERLEN || len > plen)
if (len < HEADERLEN || len > plen) {
return 0;
}
if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *))
if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *)) {
printer(arg, " %s", lcp_codenames[code-1]);
else
} else {
printer(arg, " code=0x%x", code);
}
printer(arg, " id=0x%x", id);
len -= HEADERLEN;
switch (code) {
@ -1873,8 +1903,8 @@ static int lcp_printpkt(
/*
* Time to shut down the link because there is nothing out there.
*/
static void LcpLinkFailure (fsm *f)
static void
LcpLinkFailure (fsm *f)
{
if (f->state == LS_OPENED) {
LCPDEBUG((LOG_INFO, "No response to %d echo-requests\n", lcp_echos_pending));
@ -1886,8 +1916,8 @@ static void LcpLinkFailure (fsm *f)
/*
* Timer expired for the LCP echo requests from this process.
*/
static void LcpEchoCheck (fsm *f)
static void
LcpEchoCheck (fsm *f)
{
LcpSendEchoRequest (f);
@ -1903,8 +1933,8 @@ static void LcpEchoCheck (fsm *f)
/*
* LcpEchoTimeout - Timer expired on the LCP echo
*/
static void LcpEchoTimeout (void *arg)
static void
LcpEchoTimeout (void *arg)
{
if (lcp_echo_timer_running != 0) {
lcp_echo_timer_running = 0;
@ -1915,7 +1945,8 @@ static void LcpEchoTimeout (void *arg)
/*
* LcpEchoReply - LCP has received a reply to the echo
*/
static void lcp_received_echo_reply (fsm *f, int id, u_char *inp, int len)
static void
lcp_received_echo_reply (fsm *f, int id, u_char *inp, int len)
{
u32_t magic;
@ -1927,8 +1958,7 @@ static void lcp_received_echo_reply (fsm *f, int id, u_char *inp, int len)
return;
}
GETLONG(magic, inp);
if (lcp_gotoptions[f->unit].neg_magicnumber
&& magic == lcp_gotoptions[f->unit].magicnumber) {
if (lcp_gotoptions[f->unit].neg_magicnumber && magic == lcp_gotoptions[f->unit].magicnumber) {
LCPDEBUG((LOG_WARNING, "appear to have received our own echo-reply!\n"));
return;
}
@ -1940,8 +1970,8 @@ static void lcp_received_echo_reply (fsm *f, int id, u_char *inp, int len)
/*
* LcpSendEchoRequest - Send an echo request frame to the peer
*/
static void LcpSendEchoRequest (fsm *f)
static void
LcpSendEchoRequest (fsm *f)
{
u32_t lcp_magic;
u_char pkt[4], *pktp;
@ -1971,7 +2001,8 @@ static void LcpSendEchoRequest (fsm *f)
* lcp_echo_lowerup - Start the timer for the LCP frame
*/
static void lcp_echo_lowerup (int unit)
static void
lcp_echo_lowerup (int unit)
{
fsm *f = &lcp_fsm[unit];
@ -1981,15 +2012,17 @@ static void lcp_echo_lowerup (int unit)
lcp_echo_timer_running = 0;
/* If a timeout interval is specified then start the timer */
if (lcp_echo_interval != 0)
if (lcp_echo_interval != 0) {
LcpEchoCheck (f);
}
}
/*
* lcp_echo_lowerdown - Stop the timer for the LCP frame
*/
static void lcp_echo_lowerdown (int unit)
static void
lcp_echo_lowerdown (int unit)
{
fsm *f = &lcp_fsm[unit];

View File

@ -48,7 +48,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: lcp.h,v 1.2 2007/11/29 22:19:57 fbernon Exp $
* $Id: lcp.h,v 1.3 2007/12/19 20:47:23 fbernon Exp $
*/
#ifndef LCP_H

View File

@ -82,8 +82,6 @@ static void upap_sauthreq (upap_state *);
static void upap_sresp (upap_state *, u_char, u_char, char *, int);
/******************************/
/*** PUBLIC DATA STRUCTURES ***/
/******************************/
@ -119,7 +117,8 @@ upap_state upap[NUM_PPP]; /* UPAP state; one for each unit */
/*
* Set the default login name and password for the pap sessions
*/
void upap_setloginpasswd(int unit, const char *luser, const char *lpassword)
void
upap_setloginpasswd(int unit, const char *luser, const char *lpassword)
{
upap_state *u = &upap[unit];
@ -136,7 +135,8 @@ void upap_setloginpasswd(int unit, const char *luser, const char *lpassword)
*
* Set new state and send authenticate's.
*/
void upap_authwithpeer(int unit, char *user, char *password)
void
upap_authwithpeer(int unit, char *user, char *password)
{
upap_state *u = &upap[unit];
@ -163,7 +163,8 @@ void upap_authwithpeer(int unit, char *user, char *password)
*
* Set new state.
*/
void upap_authpeer(int unit)
void
upap_authpeer(int unit)
{
upap_state *u = &upap[unit];
@ -175,9 +176,10 @@ void upap_authpeer(int unit)
}
u->us_serverstate = UPAPSS_LISTEN;
if (u->us_reqtimeout > 0)
if (u->us_reqtimeout > 0) {
TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout);
}
}
@ -187,7 +189,8 @@ void upap_authpeer(int unit)
/*
* upap_init - Initialize a UPAP unit.
*/
static void upap_init(int unit)
static void
upap_init(int unit)
{
upap_state *u = &upap[unit];
@ -208,15 +211,17 @@ static void upap_init(int unit)
/*
* upap_timeout - Retransmission timer for sending auth-reqs expired.
*/
static void upap_timeout(void *arg)
static void
upap_timeout(void *arg)
{
upap_state *u = (upap_state *) arg;
UPAPDEBUG((LOG_INFO, "upap_timeout: %d timeout %d expired s=%d\n",
u->us_unit, u->us_timeouttime, u->us_clientstate));
if (u->us_clientstate != UPAPCS_AUTHREQ)
if (u->us_clientstate != UPAPCS_AUTHREQ) {
return;
}
if (u->us_transmits >= u->us_maxtransmits) {
/* give up in disgust */
@ -233,12 +238,14 @@ static void upap_timeout(void *arg)
/*
* upap_reqtimeout - Give up waiting for the peer to send an auth-req.
*/
static void upap_reqtimeout(void *arg)
static void
upap_reqtimeout(void *arg)
{
upap_state *u = (upap_state *) arg;
if (u->us_serverstate != UPAPSS_LISTEN)
if (u->us_serverstate != UPAPSS_LISTEN) {
return; /* huh?? */
}
auth_peer_fail(u->us_unit, PPP_PAP);
u->us_serverstate = UPAPSS_BADAUTH;
@ -250,26 +257,28 @@ static void upap_reqtimeout(void *arg)
*
* Start authenticating if pending.
*/
static void upap_lowerup(int unit)
static void
upap_lowerup(int unit)
{
upap_state *u = &upap[unit];
UPAPDEBUG((LOG_INFO, "upap_lowerup: %d s=%d\n", unit, u->us_clientstate));
if (u->us_clientstate == UPAPCS_INITIAL)
if (u->us_clientstate == UPAPCS_INITIAL) {
u->us_clientstate = UPAPCS_CLOSED;
else if (u->us_clientstate == UPAPCS_PENDING) {
} else if (u->us_clientstate == UPAPCS_PENDING) {
upap_sauthreq(u); /* send an auth-request */
}
if (u->us_serverstate == UPAPSS_INITIAL)
if (u->us_serverstate == UPAPSS_INITIAL) {
u->us_serverstate = UPAPSS_CLOSED;
else if (u->us_serverstate == UPAPSS_PENDING) {
} else if (u->us_serverstate == UPAPSS_PENDING) {
u->us_serverstate = UPAPSS_LISTEN;
if (u->us_reqtimeout > 0)
if (u->us_reqtimeout > 0) {
TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout);
}
}
}
/*
@ -277,16 +286,19 @@ static void upap_lowerup(int unit)
*
* Cancel all timeouts.
*/
static void upap_lowerdown(int unit)
static void
upap_lowerdown(int unit)
{
upap_state *u = &upap[unit];
UPAPDEBUG((LOG_INFO, "upap_lowerdown: %d s=%d\n", unit, u->us_clientstate));
if (u->us_clientstate == UPAPCS_AUTHREQ) /* Timeout pending? */
if (u->us_clientstate == UPAPCS_AUTHREQ) { /* Timeout pending? */
UNTIMEOUT(upap_timeout, u); /* Cancel timeout */
if (u->us_serverstate == UPAPSS_LISTEN && u->us_reqtimeout > 0)
}
if (u->us_serverstate == UPAPSS_LISTEN && u->us_reqtimeout > 0) {
UNTIMEOUT(upap_reqtimeout, u);
}
u->us_clientstate = UPAPCS_INITIAL;
u->us_serverstate = UPAPSS_INITIAL;
@ -298,7 +310,8 @@ static void upap_lowerdown(int unit)
*
* This shouldn't happen. In any case, pretend lower layer went down.
*/
static void upap_protrej(int unit)
static void
upap_protrej(int unit)
{
upap_state *u = &upap[unit];
@ -317,7 +330,8 @@ static void upap_protrej(int unit)
/*
* upap_input - Input UPAP packet.
*/
static void upap_input(int unit, u_char *inpacket, int l)
static void
upap_input(int unit, u_char *inpacket, int l)
{
upap_state *u = &upap[unit];
u_char *inp;
@ -371,12 +385,8 @@ static void upap_input(int unit, u_char *inpacket, int l)
/*
* upap_rauth - Receive Authenticate.
*/
static void upap_rauthreq(
upap_state *u,
u_char *inp,
int id,
int len
)
static void
upap_rauthreq(upap_state *u, u_char *inp, int id, int len)
{
u_char ruserlen, rpasswdlen;
char *ruser, *rpasswd;
@ -386,8 +396,9 @@ static void upap_rauthreq(
UPAPDEBUG((LOG_INFO, "pap_rauth: Rcvd id %d.\n", id));
if (u->us_serverstate < UPAPSS_LISTEN)
if (u->us_serverstate < UPAPSS_LISTEN) {
return;
}
/*
* If we receive a duplicate authenticate-request, we are
@ -427,8 +438,7 @@ static void upap_rauthreq(
/*
* Check the username and password given.
*/
retcode = check_passwd(u->us_unit, ruser, ruserlen, rpasswd,
rpasswdlen, &msg, &msglen);
retcode = check_passwd(u->us_unit, ruser, ruserlen, rpasswd, rpasswdlen, &msg, &msglen);
BZERO(rpasswd, rpasswdlen);
upap_sresp(u, retcode, id, msg, msglen);
@ -441,28 +451,26 @@ static void upap_rauthreq(
auth_peer_fail(u->us_unit, PPP_PAP);
}
if (u->us_reqtimeout > 0)
if (u->us_reqtimeout > 0) {
UNTIMEOUT(upap_reqtimeout, u);
}
}
/*
* upap_rauthack - Receive Authenticate-Ack.
*/
static void upap_rauthack(
upap_state *u,
u_char *inp,
int id,
int len
)
static void
upap_rauthack(upap_state *u, u_char *inp, int id, int len)
{
u_char msglen;
char *msg;
UPAPDEBUG((LOG_INFO, "pap_rauthack: Rcvd id %d s=%d\n", id, u->us_clientstate));
if (u->us_clientstate != UPAPCS_AUTHREQ) /* XXX */
if (u->us_clientstate != UPAPCS_AUTHREQ) { /* XXX */
return;
}
/*
* Parse message.
@ -489,20 +497,17 @@ static void upap_rauthack(
/*
* upap_rauthnak - Receive Authenticate-Nakk.
*/
static void upap_rauthnak(
upap_state *u,
u_char *inp,
int id,
int len
)
static void
upap_rauthnak(upap_state *u, u_char *inp, int id, int len)
{
u_char msglen;
char *msg;
UPAPDEBUG((LOG_INFO, "pap_rauthnak: Rcvd id %d s=%d\n", id, u->us_clientstate));
if (u->us_clientstate != UPAPCS_AUTHREQ) /* XXX */
if (u->us_clientstate != UPAPCS_AUTHREQ) { /* XXX */
return;
}
/*
* Parse message.
@ -530,7 +535,8 @@ static void upap_rauthnak(
/*
* upap_sauthreq - Send an Authenticate-Request.
*/
static void upap_sauthreq(upap_state *u)
static void
upap_sauthreq(upap_state *u)
{
u_char *outp;
int outlen;
@ -563,13 +569,8 @@ static void upap_sauthreq(upap_state *u)
/*
* upap_sresp - Send a response (ack or nak).
*/
static void upap_sresp(
upap_state *u,
u_char code,
u_char id,
char *msg,
int msglen
)
static void
upap_sresp(upap_state *u, u_char code, u_char id, char *msg, int msglen)
{
u_char *outp;
int outlen;
@ -585,8 +586,7 @@ static void upap_sresp(
BCOPY(msg, outp, msglen);
pppWrite(u->us_unit, outpacket_buf[u->us_unit], outlen + PPP_HDRLEN);
UPAPDEBUG((LOG_INFO, "pap_sresp: Sent code %d, id %d s=%d\n",
code, id, u->us_clientstate));
UPAPDEBUG((LOG_INFO, "pap_sresp: Sent code %d, id %d s=%d\n", code, id, u->us_clientstate));
}
#if 0

View File

@ -277,22 +277,27 @@ pppoe_destroy(struct netif *ifp)
struct pppoe_softc * sc;
LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
if (sc->sc_ethif == ifp)
if (sc->sc_ethif == ifp) {
break;
}
}
if(!(sc && (sc->sc_ethif == ifp)))
if(!(sc && (sc->sc_ethif == ifp))) {
return ERR_IF;
}
tcpip_untimeout(pppoe_timeout, sc);
LIST_REMOVE(sc, sc_list);
if (sc->sc_concentrator_name)
if (sc->sc_concentrator_name) {
mem_free(sc->sc_concentrator_name);
if (sc->sc_service_name)
}
if (sc->sc_service_name) {
mem_free(sc->sc_service_name);
if (sc->sc_ac_cookie)
}
if (sc->sc_ac_cookie) {
mem_free(sc->sc_ac_cookie);
}
mem_free(sc);
return ERR_OK;
@ -309,18 +314,20 @@ pppoe_find_softc_by_session(u_int session, struct netif *rcvif)
{
struct pppoe_softc *sc;
if (session == 0)
if (session == 0) {
return NULL;
}
LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
if (sc->sc_state == PPPOE_STATE_SESSION
&& sc->sc_session == session) {
if (sc->sc_ethif == rcvif)
if (sc->sc_ethif == rcvif) {
return sc;
else
} else {
return NULL;
}
}
}
return NULL;
}
@ -331,15 +338,20 @@ pppoe_find_softc_by_hunique(u8_t *token, size_t len, struct netif *rcvif)
{
struct pppoe_softc *sc, *t;
if (LIST_EMPTY(&pppoe_softc_list))
if (LIST_EMPTY(&pppoe_softc_list)) {
return NULL;
}
if (len != sizeof sc)
if (len != sizeof sc) {
return NULL;
}
memcpy(&t, token, len);
LIST_FOREACH(sc, &pppoe_softc_list, sc_list)
if (sc == t) break;
LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
if (sc == t) {
break;
}
}
if (sc == NULL) {
PPPDEBUG((LOG_DEBUG, "pppoe: alien host unique tag, no session found\n"));
@ -414,8 +426,7 @@ pppoe_dispatch_disc_pkt(struct netif *netif, struct pbuf *pb)
ph = (struct pppoehdr *) (ethhdr + 1);
if (ph->vertype != PPPOE_VERTYPE) {
printf("pppoe: unknown version/type packet: 0x%x\n",
ph->vertype);
printf("pppoe: unknown version/type packet: 0x%x\n", ph->vertype);
goto done;
}
session = ntohs(ph->session);
@ -427,8 +438,9 @@ pppoe_dispatch_disc_pkt(struct netif *netif, struct pbuf *pb)
pb->len - off, plen);
goto done;
}
if(pb->tot_len == pb->len)
if(pb->tot_len == pb->len) {
pb->tot_len = pb->len = off + plen; /* ignore trailing garbage */
}
tag = 0;
len = 0;
sc = NULL;
@ -448,15 +460,17 @@ pppoe_dispatch_disc_pkt(struct netif *netif, struct pbuf *pb)
case PPPOE_TAG_ACNAME:
break; /* ignored */
case PPPOE_TAG_HUNIQUE:
if (sc != NULL)
if (sc != NULL) {
break;
}
#ifdef PPPOE_SERVER
hunique = (u8_t*)pb->payload + off + sizeof(pt);
hunique_len = len;
#endif
sc = pppoe_find_softc_by_hunique((u8_t*)pb->payload + off + sizeof(pt), len, netif);
if (sc != NULL)
if (sc != NULL) {
snprintf(devname, sizeof(devname), "%c%c%"U16_F, sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
}
break;
case PPPOE_TAG_ACCOOKIE:
if (ac_cookie == NULL) {
@ -489,13 +503,16 @@ pppoe_dispatch_disc_pkt(struct netif *netif, struct pbuf *pb)
if (error) {
printf("%s: %s: %s\n", devname, err_msg, error);
mem_free(error);
} else
} else {
printf("%s: %s\n", devname, err_msg);
if (errortag)
}
if (errortag) {
goto done;
}
}
off += sizeof(pt) + len;
}
breakbreak:;
switch (ph->code) {
case PPPOE_CODE_PADI:
@ -504,26 +521,32 @@ breakbreak:;
* got service name, concentrator name, and/or host unique.
* ignore if we have no interfaces with IFF_PASSIVE|IFF_UP.
*/
if (LIST_EMPTY(&pppoe_softc_list))
if (LIST_EMPTY(&pppoe_softc_list)) {
goto done;
}
LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
if (!(sc->sc_sppp.pp_if.if_flags & IFF_UP))
if (!(sc->sc_sppp.pp_if.if_flags & IFF_UP)) {
continue;
if (!(sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE))
}
if (!(sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
continue;
if (sc->sc_state == PPPOE_STATE_INITIAL)
}
if (sc->sc_state == PPPOE_STATE_INITIAL) {
break;
}
}
if (sc == NULL) {
/* printf("pppoe: free passive interface is not found\n"); */
goto done;
}
if (hunique) {
if (sc->sc_hunique)
if (sc->sc_hunique) {
mem_free(sc->sc_hunique);
}
sc->sc_hunique = mem_malloc(hunique_len);
if (sc->sc_hunique == NULL)
if (sc->sc_hunique == NULL) {
goto done;
}
sc->sc_hunique_len = hunique_len;
memcpy(sc->sc_hunique, hunique, hunique_len);
}
@ -545,8 +568,9 @@ breakbreak:;
sc = pppoe_find_softc_by_hunique(ac_cookie, ac_cookie_len, netif);
if (sc == NULL) {
/* be quiet if there is not a single pppoe instance */
if (!LIST_EMPTY(&pppoe_softc_list))
if (!LIST_EMPTY(&pppoe_softc_list)) {
printf("pppoe: received PADR but could not find request for it\n");
}
goto done;
}
if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
@ -554,11 +578,13 @@ breakbreak:;
goto done;
}
if (hunique) {
if (sc->sc_hunique)
if (sc->sc_hunique) {
mem_free(sc->sc_hunique);
}
sc->sc_hunique = mem_malloc(hunique_len);
if (sc->sc_hunique == NULL)
if (sc->sc_hunique == NULL) {
goto done;
}
sc->sc_hunique_len = hunique_len;
memcpy(sc->sc_hunique, hunique, hunique_len);
}
@ -573,8 +599,9 @@ breakbreak:;
case PPPOE_CODE_PADO:
if (sc == NULL) {
/* be quiet if there is not a single pppoe instance */
if (!LIST_EMPTY(&pppoe_softc_list))
if (!LIST_EMPTY(&pppoe_softc_list)) {
printf("pppoe: received PADO but could not find request for it\n");
}
goto done;
}
if (sc->sc_state != PPPOE_STATE_PADI_SENT) {
@ -582,11 +609,13 @@ breakbreak:;
goto done;
}
if (ac_cookie) {
if (sc->sc_ac_cookie)
if (sc->sc_ac_cookie) {
mem_free(sc->sc_ac_cookie);
}
sc->sc_ac_cookie = mem_malloc(ac_cookie_len);
if (sc->sc_ac_cookie == NULL)
if (sc->sc_ac_cookie == NULL) {
goto done;
}
sc->sc_ac_cookie_len = ac_cookie_len;
memcpy(sc->sc_ac_cookie, ac_cookie, ac_cookie_len);
}
@ -600,8 +629,9 @@ breakbreak:;
tcpip_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc);
break;
case PPPOE_CODE_PADS:
if (sc == NULL)
if (sc == NULL) {
goto done;
}
sc->sc_session = session;
tcpip_untimeout(pppoe_timeout, sc);
PPPDEBUG((LOG_DEBUG, "pppoe: %c%c%"U16_F": session 0x%x connected\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, session));
@ -609,8 +639,9 @@ breakbreak:;
tcpip_timeout (100, pppoe_linkstatus_up, sc); /* notify upper layers */
break;
case PPPOE_CODE_PADT:
if (sc == NULL)
if (sc == NULL) {
goto done;
}
pppoe_clear_softc(sc, "received PADT");
break;
default:
@ -635,9 +666,10 @@ pppoe_disc_input(struct netif *netif, struct pbuf *p)
/* avoid error messages if there is not a single pppoe instance */
if (!LIST_EMPTY(&pppoe_softc_list)) {
pppoe_dispatch_disc_pkt(netif, p);
} else
} else {
pbuf_free(p);
}
}
void
pppoe_data_input(struct netif *netif, struct pbuf *pb)
@ -676,8 +708,9 @@ pppoe_data_input(struct netif *netif, struct pbuf *pb)
printf("pppoe (data): unknown version/type packet: 0x%x\n", ph->vertype);
goto drop;
}
if (ph->code != 0)
if (ph->code != 0) {
goto drop;
}
session = ntohs(ph->session);
sc = pppoe_find_softc_by_session(session, netif);
@ -702,8 +735,9 @@ pppoe_data_input(struct netif *netif, struct pbuf *pb)
sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num,
pb->len, plen));
if (pb->len < plen)
if (pb->len < plen) {
goto drop;
}
pppInProcOverEthernet(sc->sc_pd, pb);
@ -751,8 +785,9 @@ pppoe_send_padi(struct pppoe_softc *sc)
u8_t *p;
int len, l1 = 0, l2 = 0; /* XXX: gcc */
if (sc->sc_state >PPPOE_STATE_PADI_SENT)
if (sc->sc_state >PPPOE_STATE_PADI_SENT) {
PPPDEBUG((LOG_ERR, "ERROR: pppoe_send_padi in state %d", sc->sc_state));
}
/* calculate length of frame (excluding ethernet header + pppoe header) */
len = 2 + 2 + 2 + 2 + sizeof sc; /* service name tag is required, host unique is send too */
@ -767,8 +802,9 @@ pppoe_send_padi(struct pppoe_softc *sc)
/* allocate a buffer */
pb = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len, PBUF_RAM);
if (!pb)
if (!pb) {
return ERR_MEM;
}
p = (u8_t*)pb->payload + sizeof (struct eth_hdr);
/* fill in pkt */
@ -841,8 +877,7 @@ pppoe_timeout(void *arg)
case PPPOE_STATE_PADR_SENT:
sc->sc_padr_retried++;
if (sc->sc_padr_retried >= PPPOE_DISC_MAXPADR) {
memcpy(&sc->sc_dest, ethbroadcast.addr,
sizeof(sc->sc_dest));
memcpy(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
sc->sc_state = PPPOE_STATE_PADI_SENT;
sc->sc_padr_retried = 0;
if ((err = pppoe_send_padi(sc)) != 0) {
@ -871,13 +906,15 @@ pppoe_connect(struct pppoe_softc *sc)
{
int err;
if (sc->sc_state != PPPOE_STATE_INITIAL)
if (sc->sc_state != PPPOE_STATE_INITIAL) {
return EBUSY;
}
#ifdef PPPOE_SERVER
/* wait PADI if IFF_PASSIVE */
if ((sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE))
if ((sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
return 0;
}
#endif
/* save state, in case we fail to send PADI */
sc->sc_state = PPPOE_STATE_PADI_SENT;
@ -892,8 +929,9 @@ pppoe_connect(struct pppoe_softc *sc)
void
pppoe_disconnect(struct pppoe_softc *sc)
{
if (sc->sc_state < PPPOE_STATE_SESSION)
if (sc->sc_state < PPPOE_STATE_SESSION) {
return;
}
/*
* Do not call pppoe_disconnect here, the upper layer state
* machine gets confused by this. We must return from this
@ -908,9 +946,9 @@ pppoe_do_disconnect(struct pppoe_softc *sc)
{
int err;
if (sc->sc_state < PPPOE_STATE_SESSION)
if (sc->sc_state < PPPOE_STATE_SESSION) {
err = EBUSY;
else {
} else {
PPPDEBUG((LOG_DEBUG, "pppoe: %c%c%"U16_F": disconnecting\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
err = pppoe_send_padt(sc->sc_ethif, sc->sc_session, (const u8_t *)&sc->sc_dest);
}
@ -959,19 +997,22 @@ pppoe_send_padr(struct pppoe_softc *sc)
u8_t *p;
size_t len, l1 = 0; /* XXX: gcc */
if (sc->sc_state != PPPOE_STATE_PADR_SENT)
if (sc->sc_state != PPPOE_STATE_PADR_SENT) {
return ERR_CONN;
}
len = 2 + 2 + 2 + 2 + sizeof(sc); /* service name, host unique */
if (sc->sc_service_name != NULL) { /* service name tag maybe empty */
l1 = strlen(sc->sc_service_name);
len += l1;
}
if (sc->sc_ac_cookie_len > 0)
if (sc->sc_ac_cookie_len > 0) {
len += 2 + 2 + sc->sc_ac_cookie_len; /* AC cookie */
}
pb = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len, PBUF_RAM);
if (!pb)
if (!pb) {
return ERR_MEM;
}
p = (u8_t*)pb->payload + sizeof (struct eth_hdr);
PPPOE_ADD_HEADER(p, PPPOE_CODE_PADR, 0, len);
PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
@ -995,7 +1036,6 @@ pppoe_send_padr(struct pppoe_softc *sc)
return pppoe_output(sc, pb);
}
/* send a PADT packet */
static err_t
pppoe_send_padt(struct netif *outgoing_if, u_int session, const u8_t *dest)
@ -1006,8 +1046,9 @@ pppoe_send_padt(struct netif *outgoing_if, u_int session, const u8_t *dest)
u8_t *p;
pb = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr) + PPPOE_HEADERLEN, PBUF_RAM);
if (!pb)
if (!pb) {
return ERR_MEM;
}
ethhdr = (struct eth_hdr *)pb->payload;
ethhdr->type = htons(ETHTYPE_PPPOEDISC);
@ -1032,8 +1073,9 @@ pppoe_send_pado(struct pppoe_softc *sc)
u8_t *p;
size_t len;
if (sc->sc_state != PPPOE_STATE_PADO_SENT)
if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
return ERR_CONN;
}
/* calc length */
len = 0;
@ -1042,8 +1084,9 @@ pppoe_send_pado(struct pppoe_softc *sc)
/* include hunique */
len += 2 + 2 + sc->sc_hunique_len;
pb = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len, PBUF_RAM);
if (!pb)
if (!pb) {
return ERR_MEM;
}
p = (u8_t*)pb->payload + sizeof (struct eth_hdr);
PPPOE_ADD_HEADER(p, PPPOE_CODE_PADO, 0, len);
PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE);
@ -1063,8 +1106,9 @@ pppoe_send_pads(struct pppoe_softc *sc)
u8_t *p;
size_t len, l1 = 0; /* XXX: gcc */
if (sc->sc_state != PPPOE_STATE_PADO_SENT)
if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
return ERR_CONN;
}
sc->sc_session = mono_time.tv_sec % 0xff + 1;
/* calc length */
@ -1076,8 +1120,9 @@ pppoe_send_pads(struct pppoe_softc *sc)
len += l1;
}
pb = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len, PBUF_RAM);
if (!pb)
if (!pb) {
return ERR_MEM;
}
p = (u8_t*)pb->payload + sizeof (struct eth_hdr);
PPPOE_ADD_HEADER(p, PPPOE_CODE_PADS, sc->sc_session, len);
PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
@ -1132,12 +1177,14 @@ pppoe_ifattach_hook(void *arg, struct pbuf **mp, struct netif *ifp, int dir)
struct pppoe_softc *sc;
int s;
if (mp != (struct pbuf **)PFIL_IFNET_DETACH)
if (mp != (struct pbuf **)PFIL_IFNET_DETACH) {
return 0;
}
LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
if (sc->sc_ethif != ifp)
if (sc->sc_ethif != ifp) {
continue;
}
if (sc->sc_sppp.pp_if.if_flags & IFF_UP) {
sc->sc_sppp.pp_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
printf("%c%c%"U16_F": ethernet interface detached, going down\n",

View File

@ -18,7 +18,7 @@
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
* - Initial distribution.
* Initial distribution.
*
* Modified June 1993 by Paul Mackerras, paulus@cs.anu.edu.au,
* so that the entire packet being decompressed doesn't have
@ -55,7 +55,8 @@
#define getth_off(base) ((base).th_off)
#endif
void vj_compress_init(struct vjcompress *comp)
void
vj_compress_init(struct vjcompress *comp)
{
register u_int i;
register struct cstate *tstate = comp->tstate;
@ -141,10 +142,8 @@ void vj_compress_init(struct vjcompress *comp)
* Return the VJ type code indicating whether or not the packet was
* compressed.
*/
u_int vj_compress_tcp(
struct vjcompress *comp,
struct pbuf *pb
)
u_int
vj_compress_tcp(struct vjcompress *comp, struct pbuf *pb)
{
register struct ip *ip = (struct ip *)pb->payload;
register struct cstate *cs = comp->last_cs->cs_next;
@ -160,20 +159,22 @@ u_int vj_compress_tcp(
/*
* Check that the packet is IP proto TCP.
*/
if (ip->ip_p != IPPROTO_TCP)
if (ip->ip_p != IPPROTO_TCP) {
return (TYPE_IP);
}
/*
* Bail if this is an IP fragment or if the TCP packet isn't
* `compressible' (i.e., ACK isn't set or some other control bit is
* set).
*/
if ((ip->ip_off & htons(0x3fff)) || pb->tot_len < 40)
if ((ip->ip_off & htons(0x3fff)) || pb->tot_len < 40) {
return (TYPE_IP);
}
th = (struct tcphdr *)&((long *)ip)[hlen];
if ((th->th_flags & (TCP_SYN|TCP_FIN|TCP_RST|TCP_ACK)) != TCP_ACK)
if ((th->th_flags & (TCP_SYN|TCP_FIN|TCP_RST|TCP_ACK)) != TCP_ACK) {
return (TYPE_IP);
}
/*
* Packet is compressible -- we're going to send either a
* COMPRESSED_TCP or UNCOMPRESSED_TCP packet. Either way we need
@ -205,8 +206,9 @@ u_int vj_compress_tcp(
INCR(vjs_searches);
if (ip->ip_src.s_addr == cs->cs_ip.ip_src.s_addr
&& ip->ip_dst.s_addr == cs->cs_ip.ip_dst.s_addr
&& *(long *)th == ((long *)&cs->cs_ip)[getip_hl(cs->cs_ip)])
&& *(long *)th == ((long *)&cs->cs_ip)[getip_hl(cs->cs_ip)]) {
goto found;
}
} while (cs != lastcs);
/*
@ -222,17 +224,18 @@ u_int vj_compress_tcp(
hlen += getth_off(*th);
hlen <<= 2;
/* Check that the IP/TCP headers are contained in the first buffer. */
if (hlen > pb->len)
if (hlen > pb->len) {
return (TYPE_IP);
}
goto uncompressed;
found:
/*
* Found it -- move to the front on the connection list.
*/
if (cs == lastcs)
if (cs == lastcs) {
comp->last_cs = lcs;
else {
} else {
lcs->cs_next = cs->cs_next;
cs->cs_next = lastcs->cs_next;
lastcs->cs_next = cs;
@ -245,8 +248,7 @@ u_int vj_compress_tcp(
hlen <<= 2;
/* Check that the IP/TCP headers are contained in the first buffer. */
if (hlen > pb->len) {
PPPDEBUG((LOG_INFO, "vj_compress_tcp: header len %d spans buffers\n",
hlen));
PPPDEBUG((LOG_INFO, "vj_compress_tcp: header len %d spans buffers\n", hlen));
return (TYPE_IP);
}
@ -266,8 +268,9 @@ u_int vj_compress_tcp(
|| ((u_short *)ip)[4] != ((u_short *)&cs->cs_ip)[4]
|| getth_off(*th) != getth_off(*oth)
|| (deltaS > 5 && BCMP(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2))
|| (getth_off(*th) > 5 && BCMP(th + 1, oth + 1, (getth_off(*th) - 5) << 2)))
|| (getth_off(*th) > 5 && BCMP(th + 1, oth + 1, (getth_off(*th) - 5) << 2))) {
goto uncompressed;
}
/*
* Figure out which of the changing fields changed. The
@ -279,12 +282,13 @@ u_int vj_compress_tcp(
deltaS = ntohs(th->th_urp);
ENCODEZ(deltaS);
changes |= NEW_U;
} else if (th->th_urp != oth->th_urp)
} else if (th->th_urp != oth->th_urp) {
/* argh! URG not set but urp changed -- a sensible
* implementation should never do this but RFC793
* doesn't prohibit the change so we have to deal
* with it. */
goto uncompressed;
}
if ((deltaS = (u_short)(ntohs(th->th_win) - ntohs(oth->th_win))) != 0) {
ENCODE(deltaS);
@ -292,23 +296,24 @@ u_int vj_compress_tcp(
}
if ((deltaL = ntohl(th->th_ack) - ntohl(oth->th_ack)) != 0) {
if (deltaL > 0xffff)
if (deltaL > 0xffff) {
goto uncompressed;
}
deltaA = (u_short)deltaL;
ENCODE(deltaA);
changes |= NEW_A;
}
if ((deltaL = ntohl(th->th_seq) - ntohl(oth->th_seq)) != 0) {
if (deltaL > 0xffff)
if (deltaL > 0xffff) {
goto uncompressed;
}
deltaS = (u_short)deltaL;
ENCODE(deltaS);
changes |= NEW_S;
}
switch(changes) {
case 0:
/*
* Nothing changed. If this packet contains data and the
@ -319,8 +324,9 @@ u_int vj_compress_tcp(
* in case the other side missed the compressed version.
*/
if (ip->ip_len != cs->cs_ip.ip_len &&
ntohs(cs->cs_ip.ip_len) == hlen)
ntohs(cs->cs_ip.ip_len) == hlen) {
break;
}
/* (fall through) */
@ -354,8 +360,9 @@ u_int vj_compress_tcp(
ENCODEZ(deltaS);
changes |= NEW_I;
}
if (th->th_flags & TCP_PSH)
if (th->th_flags & TCP_PSH) {
changes |= TCP_PUSH_BIT;
}
/*
* Grab the cksum before we overwrite it below. Then update our
* state with this packet's header.
@ -413,7 +420,8 @@ uncompressed:
/*
* Called when we may have missed a packet.
*/
void vj_uncompress_err(struct vjcompress *comp)
void
vj_uncompress_err(struct vjcompress *comp)
{
comp->flags |= VJF_TOSS;
INCR(vjs_errorin);
@ -423,10 +431,8 @@ void vj_uncompress_err(struct vjcompress *comp)
* "Uncompress" a packet of type TYPE_UNCOMPRESSED_TCP.
* Return 0 on success, -1 on failure.
*/
int vj_uncompress_uncomp(
struct pbuf *nb,
struct vjcompress *comp
)
int
vj_uncompress_uncomp(struct pbuf *nb, struct vjcompress *comp)
{
register u_int hlen;
register struct cstate *cs;
@ -462,10 +468,8 @@ int vj_uncompress_uncomp(
* This procedure replaces the compressed header with the uncompressed
* header and returns the length of the VJ header.
*/
int vj_uncompress_tcp(
struct pbuf **nb,
struct vjcompress *comp
)
int
vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp)
{
u_char *cp;
struct tcphdr *th;
@ -507,10 +511,11 @@ int vj_uncompress_tcp(
th = (struct tcphdr *)&((u_char *)&cs->cs_ip)[hlen];
th->th_sum = htons((*cp << 8) | cp[1]);
cp += 2;
if (changes & TCP_PUSH_BIT)
if (changes & TCP_PUSH_BIT) {
th->th_flags |= TCP_PSH;
else
} else {
th->th_flags &=~ TCP_PSH;
}
switch (changes & SPECIALS_MASK) {
case SPECIAL_I:
@ -534,14 +539,18 @@ int vj_uncompress_tcp(
if (changes & NEW_U) {
th->th_flags |= TCP_URG;
DECODEU(th->th_urp);
} else
} else {
th->th_flags &=~ TCP_URG;
if (changes & NEW_W)
}
if (changes & NEW_W) {
DECODES(th->th_win);
if (changes & NEW_A)
}
if (changes & NEW_A) {
DECODEL(th->th_ack);
if (changes & NEW_S)
}
if (changes & NEW_S) {
DECODEL(th->th_seq);
}
break;
}
if (changes & NEW_I) {
@ -577,8 +586,9 @@ int vj_uncompress_tcp(
/* recompute the ip header checksum */
bp = (u_short *) &cs->cs_ip;
cs->cs_ip.ip_sum = 0;
for (tmp = 0; hlen > 0; hlen -= 2)
for (tmp = 0; hlen > 0; hlen -= 2) {
tmp += *bp++;
}
tmp = (tmp & 0xffff) + (tmp >> 16);
tmp = (tmp & 0xffff) + (tmp >> 16);
cs->cs_ip.ip_sum = (u_short)(~tmp);
@ -590,7 +600,6 @@ int vj_uncompress_tcp(
goto bad;
}
if(LWIP_MEM_ALIGN(n0->payload) != n0->payload) {
struct pbuf *np, *q;
u8_t *bufptr;

View File

@ -1,7 +1,7 @@
/*
* Definitions for tcp compression routines.
*
* $Id: vj.h,v 1.4 2004/02/07 00:30:03 likewise Exp $
* $Id: vj.h,v 1.5 2007/12/19 20:47:23 fbernon Exp $
*
* Copyright (c) 1989 Regents of the University of California.
* All rights reserved.