sio and PPP updates from Marc

This commit is contained in:
jani 2003-06-02 11:12:56 +00:00
parent 2bfd55fd69
commit 26d9b28f77
10 changed files with 109 additions and 204 deletions

View File

@ -34,9 +34,30 @@
#include "arch/cc.h"
void * sio_open(u8_t);
void sio_send(u8_t, void*);
u8_t sio_recv(void *);
u32_t sio_read(void *, u8_t *, u32_t);
u32_t sio_write(void *, u8_t *, u32_t);
#ifndef __sio_fd_t_defined
typedef void * sio_fd_t;
#endif
#ifndef sio_open
sio_fd_t sio_open(u8_t);
#endif
#ifndef sio_send
void sio_send(u8_t, sio_fd_t);
#endif
#ifndef sio_recv
u8_t sio_recv(sio_fd_t);
#endif
#ifndef sio_read
u32_t sio_read(sio_fd_t, u8_t *, u32_t);
#endif
#ifndef sio_write
u32_t sio_write(sio_fd_t, u8_t *, u32_t);
#endif
#ifndef sio_read_abort
void sio_read_abort(void);
#endif

View File

@ -542,10 +542,10 @@ int check_passwd(
*/
if (attempts++ >= 10) {
ppp_trace(LOG_WARNING, "%d LOGIN FAILURES BY %s\n", attempts, user);
ppp_panic("Excess Bad Logins");
/*ppp_panic("Excess Bad Logins");*/
}
if (attempts > 3) {
ppp_msleep((attempts - 3) * 5);
sys_msleep((attempts - 3) * 5);
}
if (addrs != NULL) {
free_wordlist(addrs);

View File

@ -593,12 +593,12 @@ static int ipcp_nakci(fsm *f, u_char *p, int len)
if (go->accept_local && ciaddr1) { /* Do we know our address? */
try.ouraddr = ciaddr1;
IPCPDEBUG((LOG_INFO, "local IP address %s\n",
ip_ntoa(ciaddr1)));
inet_ntoa(ciaddr1)));
}
if (go->accept_remote && ciaddr2) { /* Does he know his? */
try.hisaddr = ciaddr2;
IPCPDEBUG((LOG_INFO, "remote IP address %s\n",
ip_ntoa(ciaddr2)));
inet_ntoa(ciaddr2)));
}
);
@ -633,12 +633,12 @@ static int ipcp_nakci(fsm *f, u_char *p, int len)
NAKCIDNS(CI_MS_DNS1, req_dns1,
try.dnsaddr[0] = cidnsaddr;
IPCPDEBUG((LOG_INFO, "primary DNS address %s\n", ip_ntoa(cidnsaddr)));
IPCPDEBUG((LOG_INFO, "primary DNS address %s\n", inet_ntoa(cidnsaddr)));
);
NAKCIDNS(CI_MS_DNS2, req_dns2,
try.dnsaddr[1] = cidnsaddr;
IPCPDEBUG((LOG_INFO, "secondary DNS address %s\n", ip_ntoa(cidnsaddr)));
IPCPDEBUG((LOG_INFO, "secondary DNS address %s\n", inet_ntoa(cidnsaddr)));
);
/*
@ -898,7 +898,7 @@ static int ipcp_reqci(
*/
GETLONG(tl, p); /* Parse source address (his) */
ciaddr1 = htonl(tl);
IPCPDEBUG((LOG_INFO, "his addr %s\n", ip_ntoa(ciaddr1)));
IPCPDEBUG((LOG_INFO, "his addr %s\n", inet_ntoa(ciaddr1)));
if (ciaddr1 != wo->hisaddr
&& (ciaddr1 == 0 || !wo->accept_remote)) {
orc = CONFNAK;
@ -922,7 +922,7 @@ static int ipcp_reqci(
*/
GETLONG(tl, p); /* Parse desination address (ours) */
ciaddr2 = htonl(tl);
IPCPDEBUG((LOG_INFO, "our addr %s\n", ip_ntoa(ciaddr2)));
IPCPDEBUG((LOG_INFO, "our addr %s\n", inet_ntoa(ciaddr2)));
if (ciaddr2 != wo->ouraddr) {
if (ciaddr2 == 0 || !wo->accept_local) {
orc = CONFNAK;
@ -970,12 +970,12 @@ static int ipcp_reqci(
tl = ntohl(wo->hisaddr);
PUTLONG(tl, p);
}
IPCPDEBUG((LOG_INFO, "ipcp_reqci: Nak ADDR %s\n", ip_ntoa(ciaddr1)));
IPCPDEBUG((LOG_INFO, "ipcp_reqci: Nak ADDR %s\n", inet_ntoa(ciaddr1)));
} else if (ciaddr1 == 0 && wo->hisaddr == 0) {
/*
* Don't ACK an address of 0.0.0.0 - reject it instead.
*/
IPCPDEBUG((LOG_INFO, "ipcp_reqci: Reject ADDR %s\n", ip_ntoa(ciaddr1)));
IPCPDEBUG((LOG_INFO, "ipcp_reqci: Reject ADDR %s\n", inet_ntoa(ciaddr1)));
orc = CONFREJ;
wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
break;
@ -983,7 +983,7 @@ static int ipcp_reqci(
ho->neg_addr = 1;
ho->hisaddr = ciaddr1;
IPCPDEBUG((LOG_INFO, "ipcp_reqci: ADDR %s\n", ip_ntoa(ciaddr1)));
IPCPDEBUG((LOG_INFO, "ipcp_reqci: ADDR %s\n", inet_ntoa(ciaddr1)));
break;
case CI_MS_DNS1:
@ -1001,7 +1001,7 @@ static int ipcp_reqci(
GETLONG(tl, p);
if (htonl(tl) != ao->dnsaddr[d]) {
IPCPDEBUG((LOG_INFO, "ipcp_reqci: Naking DNS%d Request %d\n",
d+1, ip_ntoa(tl)));
d+1, inet_ntoa(tl)));
DECPTR(sizeof(u32_t), p);
tl = ntohl(ao->dnsaddr[d]);
PUTLONG(tl, p);
@ -1211,7 +1211,7 @@ static void ipcp_up(fsm *f)
*/
if (!auth_ip_addr(f->unit, ho->hisaddr)) {
ppp_trace(LOG_ERR, "Peer is not authorized to use remote address %s\n",
ip_ntoa(ho->hisaddr));
inet_ntoa(ho->hisaddr));
ipcp_close(f->unit, "Unauthorized remote IP address");
return;
}
@ -1224,13 +1224,11 @@ static void ipcp_up(fsm *f)
*/
mask = GetMask(go->ouraddr);
#if !(defined(SVR4) && (defined(SNI) || defined(__USLC__)))
if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask, go->dnsaddr[0], go->dnsaddr[1])) {
IPCPDEBUG((LOG_WARNING, "sifaddr failed\n"));
ipcp_close(f->unit, "Interface configuration failed");
return;
}
#endif
/* bring the interface up for IP */
if (!sifup(f->unit)) {
@ -1239,13 +1237,6 @@ static void ipcp_up(fsm *f)
return;
}
#if (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
IPCPDEBUG((LOG_WARNING, "sifaddr failed\n"));
ipcp_close(f->unit, "Interface configuration failed");
return;
}
#endif
sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
/* assign a default route through the interface if required */
@ -1253,13 +1244,13 @@ static void ipcp_up(fsm *f)
if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
default_route_set[f->unit] = 1;
IPCPDEBUG((LOG_NOTICE, "local IP address %s\n", ip_ntoa(go->ouraddr)));
IPCPDEBUG((LOG_NOTICE, "remote IP address %s\n", ip_ntoa(ho->hisaddr)));
IPCPDEBUG((LOG_NOTICE, "local IP address %s\n", inet_ntoa(go->ouraddr)));
IPCPDEBUG((LOG_NOTICE, "remote IP address %s\n", inet_ntoa(ho->hisaddr)));
if (go->dnsaddr[0]) {
IPCPDEBUG((LOG_NOTICE, "primary DNS address %s\n", ip_ntoa(go->dnsaddr[0])));
IPCPDEBUG((LOG_NOTICE, "primary DNS address %s\n", inet_ntoa(go->dnsaddr[0])));
}
if (go->dnsaddr[1]) {
IPCPDEBUG((LOG_NOTICE, "secondary DNS address %s\n", ip_ntoa(go->dnsaddr[1])));
IPCPDEBUG((LOG_NOTICE, "secondary DNS address %s\n", inet_ntoa(go->dnsaddr[1])));
}
}

View File

@ -1880,8 +1880,8 @@ static void LcpEchoCheck (fsm *f)
/*
* Start the timer for the next interval.
*/
if (lcp_echo_timer_running != 0)
ppp_panic("LcpEchoCheck");
LWIP_ASSERT("lcp_echo_timer_running == 0", lcp_echo_timer_running == 0);
TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval);
lcp_echo_timer_running = 1;
}

View File

@ -97,7 +97,6 @@
#endif
#include "pppdebug.h"
#include "lwip/sio.h"
/*************************/
/*** LOCAL DEFINITIONS ***/
@ -132,7 +131,7 @@ typedef enum {
typedef struct PPPControl_s {
char openFlag; /* True when in use. */
char oldFrame; /* Old framing character for fd. */
ppp_sio_fd_t fd; /* File device ID of port. */
sio_fd_t fd; /* File device ID of port. */
int kill_link; /* Shut the link down. */
int sig_hup; /* Carrier lost. */
int if_up; /* True when the interface is up. */
@ -156,7 +155,7 @@ typedef struct PPPControl_s {
struct netif *netif;
struct ip_addr our_ipaddr, his_ipaddr, netmask;
struct ip_addr our_ipaddr, his_ipaddr, netmask, dns1, dns2;
void (*linkStatusCB)(void *arg, int errCode);
void *linkStatusArg;
@ -340,17 +339,11 @@ void pppSetAuth(const char *user, const char *passwd)
* established before calling this.
* Return a new PPP connection descriptor on success or
* an error code (negative) on failure. */
int pppOpen(ppp_sio_fd_t fd, void (*linkStatusCB)(void *arg, int errCode), void *linkStatusArg)
int pppOpen(sio_fd_t fd, void (*linkStatusCB)(void *arg, int errCode), void *linkStatusArg)
{
PPPControl *pc;
int pd;
/* XXX
* Ensure that fd is not already used for PPP
* for now this is left for the lower layer to check
* so the arg passed to sio_open means nothing
*/
fd = sio_open(2);
/* Find a free PPP session descriptor. Critical region? */
for (pd = 0; pd < NUM_PPP && pppControl[pd].openFlag != 0; pd++);
if (pd >= NUM_PPP)
@ -396,7 +389,7 @@ int pppOpen(ppp_sio_fd_t fd, void (*linkStatusCB)(void *arg, int errCode), void
sys_thread_new(pppMain, (void*)pd, PPP_THREAD_PRIO);
if(!linkStatusCB) {
while(pd >= 0 && !pc->if_up) {
ppp_msleep(500);
sys_msleep(500);
if (lcp_phase[pd] == PHASE_DEAD) {
pppClose(pd);
if (pc->errCode)
@ -424,7 +417,7 @@ int pppClose(int pd)
if(!pc->linkStatusCB) {
while(st >= 0 && lcp_phase[pd] != PHASE_DEAD) {
ppp_msleep(500);
sys_msleep(500);
break;
}
}
@ -448,7 +441,7 @@ static void nPut(PPPControl *pc, struct pbuf *nb)
for(b = nb; b != NULL; b = b->next) {
if((c = sio_write(pc->fd, b->payload, b->len)) != b->len) {
PPPDEBUG((LOG_WARNING,
"PPP nPut: incomplete ppp_sio_write(%d,, %u) = %d\n", pc->fd, b->len, c));
"PPP nPut: incomplete sio_write(%d,, %u) = %d\n", pc->fd, b->len, c));
#ifdef LINK_STATS
lwip_stats.link.err++;
#endif /* LINK_STATS */
@ -542,9 +535,9 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, struct ip_addr *i
tailMB = headMB;
/* Build the PPP header. */
if ((ppp_jiffies() - pc->lastXMit) >= PPP_MAXIDLEFLAG)
if ((sys_jiffies() - pc->lastXMit) >= PPP_MAXIDLEFLAG)
tailMB = pppMPutRaw(PPP_FLAG, tailMB);
pc->lastXMit = ppp_jiffies();
pc->lastXMit = sys_jiffies();
if (!pc->accomp) {
fcsOut = PPP_FCS(fcsOut, PPP_ALLSTATIONS);
tailMB = pppMPutC(PPP_ALLSTATIONS, &pc->outACCM, tailMB);
@ -637,7 +630,7 @@ int pppIOCtl(int pd, int cmd, void *arg)
break;
case PPPCTLG_FD:
if (arg)
*(ppp_sio_fd_t *)arg = pc->fd;
*(sio_fd_t *)arg = pc->fd;
else
st = PPPERR_PARAM;
break;
@ -691,9 +684,9 @@ int pppWrite(int pd, const u_char *s, int n)
/* If the link has been idle, we'll send a fresh flag character to
* flush any noise. */
if ((ppp_jiffies() - pc->lastXMit) >= PPP_MAXIDLEFLAG)
if ((sys_jiffies() - pc->lastXMit) >= PPP_MAXIDLEFLAG)
tailMB = pppMPutRaw(PPP_FLAG, tailMB);
pc->lastXMit = ppp_jiffies();
pc->lastXMit = sys_jiffies();
/* Load output buffer. */
while (n-- > 0) {
@ -938,8 +931,9 @@ int sifup(int pd)
if(pc->netif) {
pc->if_up = 1;
pc->errCode = 0;
if(pc->linkStatusCB)
pc->linkStatusCB(pc->linkStatusArg, pc->errCode);
if(pc->linkStatusCB)
pc->linkStatusCB(pc->linkStatusArg, pc->errCode);
} else {
st = 0;
PPPDEBUG((LOG_ERR, "sifup[%d]: netif_add failed\n", pd));
@ -954,10 +948,10 @@ int sifup(int pd)
*/
int sifnpmode(int u, int proto, enum NPmode mode)
{
(void)u;
(void)proto;
(void)mode;
return 0;
(void)u;
(void)proto;
(void)mode;
return 0;
}
/*
@ -989,7 +983,9 @@ int sifaddr(
int pd, /* Interface unit ??? */
u32_t o, /* Our IP address ??? */
u32_t h, /* His IP address ??? */
u32_t m /* IP subnet mask ??? */
u32_t m, /* IP subnet mask ??? */
u32_t ns1, /* Primary DNS */
u32_t ns2 /* Secondary DNS */
)
{
PPPControl *pc = &pppControl[pd];
@ -1002,6 +998,8 @@ int sifaddr(
memcpy(&pc->our_ipaddr, &o, sizeof(o));
memcpy(&pc->his_ipaddr, &h, sizeof(h));
memcpy(&pc->netmask, &m, sizeof(m));
memcpy(&pc->dns1, &ns1, sizeof(ns1));
memcpy(&pc->dns2, &ns2, sizeof(ns2));
}
return st;
}
@ -1028,6 +1026,8 @@ int cifaddr(
IP4_ADDR(&pc->our_ipaddr, 0,0,0,0);
IP4_ADDR(&pc->his_ipaddr, 0,0,0,0);
IP4_ADDR(&pc->netmask, 255,255,255,0);
IP4_ADDR(&pc->dns1, 0,0,0,0);
IP4_ADDR(&pc->dns2, 0,0,0,0);
}
return st;
}
@ -1121,10 +1121,14 @@ static void pppMain(void *arg)
int pd = (int)arg;
struct pbuf *p;
PPPControl* pc;
pc = &pppControl[pd];
p = pbuf_alloc(PBUF_RAW, PPP_MRU+PPP_HDRLEN, PBUF_RAM);
if(!p) {
ppp_panic("pppMain: unable to allocate pbuf");
LWIP_ASSERT("p != NULL", p);
pc->errCode = PPPERR_ALLOC;
goto out;
}
/*
@ -1150,6 +1154,8 @@ static void pppMain(void *arg)
}
}
pbuf_free(p);
out:
if(pc->linkStatusCB)
pc->linkStatusCB(pc->linkStatusArg, pc->errCode ? pc->errCode : PPPERR_PROTOCOL);

View File

@ -34,9 +34,17 @@
#ifndef PPP_H
#define PPP_H
#include "target.h"
#include "lwip/opt.h"
#if PPP_SUPPORT > 0
#include "lwip/sio.h"
#include "lwip/api.h"
#include "lwip/sockets.h"
#include "lwip/stats.h"
#include "lwip/mem.h"
#include "lwip/tcpip.h"
#include "lwip/netif.h"
/*
* pppd.h - PPP daemon global declarations.
*
@ -83,6 +91,20 @@
* OR MODIFICATIONS.
*/
#define TIMEOUT(f, a, t) sys_untimeout((f), (a)), sys_timeout((t)*1000, (f), (a))
#define UNTIMEOUT(f, a) sys_untimeout((f), (a))
# ifndef __u_char_defined
/* Type definitions for BSD code. */
typedef unsigned long u_long;
typedef unsigned int u_int;
typedef unsigned short u_short;
typedef unsigned char u_char;
#endif
/*
* Constants and structures defined by the internet system,
* Per RFC 790, September 1981, and numerous additions.
@ -197,40 +219,6 @@ enum NPmode {
PUTCHAR(PPP_UI, p); \
PUTSHORT(t, p); }
/*
* Definitions of bits in internet address integers.
* On subnets, the decomposition of addresses to host and net parts
* is done according to subnet mask, not the masks here.
*/
#define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
#define IN_CLASSA_NET 0xff000000
#define IN_CLASSA_NSHIFT 24
#define IN_CLASSA_HOST 0x00ffffff
#define IN_CLASSA_MAX 128
#define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000)
#define IN_CLASSB_NET 0xffff0000
#define IN_CLASSB_NSHIFT 16
#define IN_CLASSB_HOST 0x0000ffff
#define IN_CLASSB_MAX 65536
#define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000)
#define IN_CLASSC_NET 0xffffff00
#define IN_CLASSC_NSHIFT 8
#define IN_CLASSC_HOST 0x000000ff
#define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
#define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */
#define IN_CLASSD_NSHIFT 28 /* net and host fields, but */
#define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */
#define IN_MULTICAST(i) IN_CLASSD(i)
#define IN_EXPERIMENTAL(i) (((long)(i) & 0xf0000000) == 0xf0000000)
#define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000)
#define IN_LOOPBACKNET 127 /* official! */
/*************************
*** PUBLIC DEFINITIONS ***
*************************/
@ -358,7 +346,7 @@ void pppSetAuth(const char *user, const char *passwd);
* Return a new PPP connection descriptor on success or
* an error code (negative) on failure.
*/
int pppOpen(ppp_sio_fd_t fd, void (*linkStatusCB)(void *arg, int errCode), void *linkStatusArg);
int pppOpen(sio_fd_t fd, void (*linkStatusCB)(void *arg, int errCode), void *linkStatusArg);
/*
* Close a PPP connection and release the descriptor.
@ -410,7 +398,7 @@ int sifnpmode (int u, int proto, enum NPmode mode);
/* Configure i/f down (for IP) */
int sifdown (int);
/* Configure IP addresses for i/f */
int sifaddr (int, u32_t, u32_t, u32_t);
int sifaddr (int, u32_t, u32_t, u32_t, u32_t, u32_t);
/* Reset i/f IP addresses */
int cifaddr (int, u32_t, u32_t);
/* Create default route through i/f */

View File

@ -191,7 +191,7 @@ void avRandomInit()
avRandomSeed += *(u32_t *)clockBuf + *lptr1 + OSIdleCtr
+ ppp_mtime() + ((u32_t)TM1 << 16) + TM1;
#else
avRandomSeed += ppp_jiffies(); /* XXX */
avRandomSeed += sys_jiffies(); /* XXX */
#endif
/* Initialize the Borland random number generator. */
@ -215,9 +215,9 @@ void avRandomize(void)
/* The initialization function also updates the seed. */
} else {
/* avRandomSeed += (avRandomSeed << 16) + TM1; */
avRandomSeed += (ppp_jiffies() - last_jiffies); /* XXX */
avRandomSeed += (sys_jiffies() - last_jiffies); /* XXX */
}
last_jiffies = ppp_jiffies();
last_jiffies = sys_jiffies();
}
/*

View File

@ -1,38 +0,0 @@
#include "ppp.h"
void ppp_panic(char * msg)
{
LWIP_ASSERT("PPP panic: %s\n", msg);
}
void
ppp_msleep(unsigned long ms)
{
sys_sem_t delaysem = sys_sem_new(0);
sys_sem_wait_timeout(delaysem, ms);
sys_sem_free(delaysem);
}
/*
* Make a string representation of a network IP address.
* WARNING: NOT RE-ENTRANT!
*/
char *ip_ntoa(u32_t ipaddr)
{
static char b[20];
ipaddr = ntohl(ipaddr);
#if 0
FIXME
sprintf(b, "%d.%d.%d.%d",
(u_char)(ipaddr >> 24),
(u_char)(ipaddr >> 16),
(u_char)(ipaddr >> 8),
(u_char)(ipaddr));
#endif
return b;
}

View File

@ -1,63 +0,0 @@
#ifndef TARGET_H_
#define TARGET_H_
#include "lwip/opt.h"
#include "lwip/debug.h"
#include "lwip/api.h"
#include "lwip/sockets.h"
#include "lwip/stats.h"
#include "lwip/mem.h"
#include "lwip/tcpip.h"
#include "lwip/netif.h"
/* the following is temporary until sio_common.h defines SIO_ERROR */
#if defined(ERROR) && !defined(SIO_ERROR)
#define SIO_ERROR ERROR
#endif
#define TIMEOUT(f, a, t) sys_untimeout((f), (a)), sys_timeout((t)*1000, (f), (a))
#define UNTIMEOUT(f, a) sys_untimeout((f), (a))
# ifndef __u_char_defined
/* Type definitions for BSD code. */
typedef unsigned long u_long;
typedef unsigned int u_int;
typedef unsigned short u_short;
typedef unsigned char u_char;
#endif
/*
* Sleep ms milliseconds. Note that this only has a (close to) 1 Jiffy
* resolution.
* Note: Since there may me less than a ms left before the next clock
* tick, 1 tick is added to ensure we delay at least ms time.
*/
void ppp_msleep(unsigned long ms);
/*
* Return the number of jiffies that have passed since power up.
*/
unsigned long ppp_jiffies(void);
/* Display a panic message and HALT the system. */
void ppp_panic(char *msg);
/*
* Make a string representation of a network IP address.
* WARNING: NOT RE-ENTRANT!
*/
char *ip_ntoa(u32_t ipaddr);
typedef void * ppp_sio_fd_t;
/*FIXME */
#define sio_read_abort(fd) do { \
} while (0)
#endif /* TARGET_H */

View File

@ -1,7 +1,7 @@
/*
* Definitions for tcp compression routines.
*
* $Id: vj.h,v 1.1 2003/05/27 14:37:56 jani Exp $
* $Id: vj.h,v 1.2 2003/06/02 11:12:56 jani Exp $
*
* Copyright (c) 1989 Regents of the University of California.
* All rights reserved.
@ -144,7 +144,7 @@ struct vjcompress {
};
/* flag values */
#define VJF_TOSS 1 /* tossing rcvd frames because of input err */
#define VJF_TOSS 1U /* tossing rcvd frames because of input err */
extern void vj_compress_init (struct vjcompress *comp);
extern u_int vj_compress_tcp (struct vjcompress *comp, struct pbuf *pb);