Make the code format more in line with style(9).
Update loadalias to use the new libalias api. Update to version 1.1.
This commit is contained in:
parent
30761f8783
commit
944f709824
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28679
@ -15,198 +15,185 @@
|
||||
#include "vars.h"
|
||||
|
||||
static int
|
||||
StrToAddr (char *, struct in_addr* addr);
|
||||
StrToAddr(char *, struct in_addr * addr);
|
||||
|
||||
static int
|
||||
StrToPort (char *, u_short *port, char *proto);
|
||||
StrToPort(char *, u_short * port, char *proto);
|
||||
|
||||
static int
|
||||
StrToAddrAndPort (char *, struct in_addr *addr, u_short *port, char *proto);
|
||||
StrToAddrAndPort(char *, struct in_addr * addr, u_short * port, char *proto);
|
||||
|
||||
|
||||
int
|
||||
AliasRedirectPort (struct cmdtab *list,
|
||||
int argc,
|
||||
char **argv,
|
||||
void *param)
|
||||
AliasRedirectPort(struct cmdtab * list,
|
||||
int argc,
|
||||
char **argv,
|
||||
void *param)
|
||||
{
|
||||
if (!(mode & MODE_ALIAS)) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "Alias not enabled\n");
|
||||
} else if (argc == 3) {
|
||||
char proto_constant;
|
||||
char *proto;
|
||||
u_short local_port;
|
||||
u_short alias_port;
|
||||
int error;
|
||||
struct in_addr local_addr;
|
||||
struct in_addr null_addr;
|
||||
struct alias_link *link;
|
||||
if (!(mode & MODE_ALIAS)) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "Alias not enabled\n");
|
||||
} else if (argc == 3) {
|
||||
char proto_constant;
|
||||
char *proto;
|
||||
u_short local_port;
|
||||
u_short alias_port;
|
||||
int error;
|
||||
struct in_addr local_addr;
|
||||
struct in_addr null_addr;
|
||||
struct alias_link *link;
|
||||
|
||||
proto = argv[0];
|
||||
if (strcmp(proto, "tcp") == 0) {
|
||||
proto_constant = IPPROTO_TCP;
|
||||
} else if (strcmp(proto, "udp") == 0) {
|
||||
proto_constant = IPPROTO_UDP;
|
||||
} else {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "port redirect: protocol must be tcp or udp\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name,
|
||||
list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
proto = argv[0];
|
||||
if (strcmp(proto, "tcp") == 0) {
|
||||
proto_constant = IPPROTO_TCP;
|
||||
} else if (strcmp(proto, "udp") == 0) {
|
||||
proto_constant = IPPROTO_UDP;
|
||||
} else {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "port redirect: protocol must be tcp or udp\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name,
|
||||
list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
error = StrToAddrAndPort(argv[1], &local_addr, &local_port, proto);
|
||||
if (error) {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "port redirect: error reading local addr:port\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
error = StrToAddrAndPort(argv[1], &local_addr, &local_port, proto);
|
||||
if (error) {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "port redirect: error reading local addr:port\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
error = StrToPort(argv[2], &alias_port, proto);
|
||||
if (error) {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "port redirect: error reading alias port\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
null_addr.s_addr = 0;
|
||||
|
||||
error = StrToPort(argv[2], &alias_port, proto);
|
||||
if (error) {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "port redirect: error reading alias port\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
link = VarPacketAliasRedirectPort(local_addr, local_port,
|
||||
null_addr, 0,
|
||||
null_addr, alias_port,
|
||||
proto_constant);
|
||||
|
||||
null_addr.s_addr = 0;
|
||||
if (link == NULL && VarTerm)
|
||||
fprintf(VarTerm, "port redirect: error returned by packed"
|
||||
" aliasing engine (code=%d)\n", error);
|
||||
} else if (VarTerm)
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
|
||||
link = VarPacketAliasRedirectPort(local_addr, local_port,
|
||||
null_addr, 0,
|
||||
null_addr, alias_port,
|
||||
proto_constant);
|
||||
|
||||
if (link == NULL && VarTerm)
|
||||
fprintf(VarTerm, "port redirect: error returned by packed"
|
||||
" aliasing engine (code=%d)\n", error);
|
||||
} else if (VarTerm)
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
AliasRedirectAddr(struct cmdtab *list,
|
||||
int argc,
|
||||
char **argv,
|
||||
void *param)
|
||||
AliasRedirectAddr(struct cmdtab * list,
|
||||
int argc,
|
||||
char **argv,
|
||||
void *param)
|
||||
{
|
||||
if (!(mode & MODE_ALIAS)) {
|
||||
if (!(mode & MODE_ALIAS)) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "alias not enabled\n");
|
||||
} else if (argc == 2) {
|
||||
int error;
|
||||
struct in_addr local_addr;
|
||||
struct in_addr alias_addr;
|
||||
struct alias_link *link;
|
||||
|
||||
error = StrToAddr(argv[0], &local_addr);
|
||||
if (error) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "alias not enabled\n");
|
||||
} else if (argc == 2) {
|
||||
int error;
|
||||
struct in_addr local_addr;
|
||||
struct in_addr alias_addr;
|
||||
struct alias_link *link;
|
||||
fprintf(VarTerm, "address redirect: invalid local address\n");
|
||||
return 1;
|
||||
}
|
||||
error = StrToAddr(argv[1], &alias_addr);
|
||||
if (error) {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "address redirect: invalid alias address\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
link = VarPacketAliasRedirectAddr(local_addr, alias_addr);
|
||||
if (link == NULL && VarTerm) {
|
||||
fprintf(VarTerm, "address redirect: packet aliasing engine error\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
} else if (VarTerm)
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
|
||||
error = StrToAddr(argv[0], &local_addr);
|
||||
if (error) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "address redirect: invalid local address\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
error = StrToAddr(argv[1], &alias_addr);
|
||||
if (error) {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "address redirect: invalid alias address\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
link = VarPacketAliasRedirectAddr(local_addr, alias_addr);
|
||||
if (link == NULL && VarTerm) {
|
||||
fprintf(VarTerm, "address redirect: packet aliasing engine error\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
} else if (VarTerm)
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
StrToAddr (char* str,
|
||||
struct in_addr* addr)
|
||||
StrToAddr(char *str,
|
||||
struct in_addr * addr)
|
||||
{
|
||||
struct hostent* hp;
|
||||
struct hostent *hp;
|
||||
|
||||
if (inet_aton (str, addr))
|
||||
return 0;
|
||||
|
||||
hp = gethostbyname (str);
|
||||
if (!hp)
|
||||
{
|
||||
LogPrintf(LogWARN, "StrToAddr: Unknown host %s.\n", str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*addr = *((struct in_addr *) hp->h_addr);
|
||||
if (inet_aton(str, addr))
|
||||
return 0;
|
||||
|
||||
hp = gethostbyname(str);
|
||||
if (!hp) {
|
||||
LogPrintf(LogWARN, "StrToAddr: Unknown host %s.\n", str);
|
||||
return -1;
|
||||
}
|
||||
*addr = *((struct in_addr *) hp->h_addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
StrToPort (char *str,
|
||||
u_short *port,
|
||||
char *proto)
|
||||
StrToPort(char *str,
|
||||
u_short * port,
|
||||
char *proto)
|
||||
{
|
||||
int iport;
|
||||
struct servent* sp;
|
||||
char* end;
|
||||
int iport;
|
||||
struct servent *sp;
|
||||
char *end;
|
||||
|
||||
iport = strtol (str, &end, 10);
|
||||
if (end != str)
|
||||
{
|
||||
*port = htons(iport);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sp = getservbyname (str, proto);
|
||||
if (!sp)
|
||||
{
|
||||
LogPrintf(LogWARN, "StrToAddr: Unknown port or service %s/%s.\n",
|
||||
str, proto);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*port = sp->s_port;
|
||||
iport = strtol(str, &end, 10);
|
||||
if (end != str) {
|
||||
*port = htons(iport);
|
||||
return 0;
|
||||
}
|
||||
sp = getservbyname(str, proto);
|
||||
if (!sp) {
|
||||
LogPrintf(LogWARN, "StrToAddr: Unknown port or service %s/%s.\n",
|
||||
str, proto);
|
||||
return -1;
|
||||
}
|
||||
*port = sp->s_port;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
StrToAddrAndPort (char* str,
|
||||
struct in_addr* addr,
|
||||
u_short *port,
|
||||
char *proto)
|
||||
StrToAddrAndPort(char *str,
|
||||
struct in_addr * addr,
|
||||
u_short * port,
|
||||
char *proto)
|
||||
{
|
||||
char *ptr;
|
||||
char *ptr;
|
||||
|
||||
ptr = strchr (str, ':');
|
||||
if (!ptr)
|
||||
{
|
||||
LogPrintf(LogWARN, "StrToAddrAndPort: %s is missing port number.\n",
|
||||
str);
|
||||
return -1;
|
||||
}
|
||||
ptr = strchr(str, ':');
|
||||
if (!ptr) {
|
||||
LogPrintf(LogWARN, "StrToAddrAndPort: %s is missing port number.\n",
|
||||
str);
|
||||
return -1;
|
||||
}
|
||||
*ptr = '\0';
|
||||
++ptr;
|
||||
|
||||
*ptr = '\0';
|
||||
++ptr;
|
||||
if (StrToAddr(str, addr) != 0)
|
||||
return -1;
|
||||
|
||||
if (StrToAddr (str, addr) != 0)
|
||||
return -1;
|
||||
|
||||
return StrToPort (ptr, port, proto);
|
||||
return StrToPort(ptr, port, proto);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
extern int
|
||||
AliasRedirectPort (struct cmdtab *, int, char **, void *);
|
||||
AliasRedirectPort(struct cmdtab *, int, char **, void *);
|
||||
|
||||
extern int
|
||||
AliasRedirectAddr (struct cmdtab *, int, char **, void *);
|
||||
AliasRedirectAddr(struct cmdtab *, int, char **, void *);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: arp.c,v 1.11 1997/04/15 00:03:35 brian Exp $
|
||||
* $Id: arp.c,v 1.12 1997/06/09 03:27:11 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -75,156 +75,142 @@ static int get_ether_addr(int, u_long, struct sockaddr_dl *);
|
||||
* sifproxyarp - Make a proxy ARP entry for the peer.
|
||||
*/
|
||||
static struct {
|
||||
struct rt_msghdr hdr;
|
||||
struct sockaddr_inarp dst;
|
||||
struct sockaddr_dl hwa;
|
||||
char extra[128];
|
||||
} arpmsg;
|
||||
struct rt_msghdr hdr;
|
||||
struct sockaddr_inarp dst;
|
||||
struct sockaddr_dl hwa;
|
||||
char extra[128];
|
||||
} arpmsg;
|
||||
|
||||
static int arpmsg_valid;
|
||||
|
||||
int
|
||||
sifproxyarp(unit, hisaddr)
|
||||
int unit;
|
||||
u_long hisaddr;
|
||||
sifproxyarp(int unit, u_long hisaddr)
|
||||
{
|
||||
int routes;
|
||||
int routes;
|
||||
|
||||
/*
|
||||
* Get the hardware address of an interface on the same subnet
|
||||
* as our local address.
|
||||
*/
|
||||
memset(&arpmsg, 0, sizeof(arpmsg));
|
||||
if (!get_ether_addr(unit, hisaddr, &arpmsg.hwa)) {
|
||||
LogPrintf(LogERROR, "Cannot determine ethernet address"
|
||||
" for proxy ARP\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
|
||||
LogPrintf(LogERROR, "sifproxyarp: opening routing socket: %s\n",
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
arpmsg.hdr.rtm_type = RTM_ADD;
|
||||
arpmsg.hdr.rtm_flags = RTF_ANNOUNCE | RTF_HOST | RTF_STATIC;
|
||||
arpmsg.hdr.rtm_version = RTM_VERSION;
|
||||
arpmsg.hdr.rtm_seq = ++rtm_seq;
|
||||
arpmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY;
|
||||
arpmsg.hdr.rtm_inits = RTV_EXPIRE;
|
||||
arpmsg.dst.sin_len = sizeof(struct sockaddr_inarp);
|
||||
arpmsg.dst.sin_family = AF_INET;
|
||||
arpmsg.dst.sin_addr.s_addr = hisaddr;
|
||||
arpmsg.dst.sin_other = SIN_PROXY;
|
||||
|
||||
arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg
|
||||
+ arpmsg.hwa.sdl_len;
|
||||
if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
|
||||
LogPrintf(LogERROR, "Add proxy arp entry: %s\n", strerror(errno));
|
||||
close(routes);
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* Get the hardware address of an interface on the same subnet as our local
|
||||
* address.
|
||||
*/
|
||||
memset(&arpmsg, 0, sizeof(arpmsg));
|
||||
if (!get_ether_addr(unit, hisaddr, &arpmsg.hwa)) {
|
||||
LogPrintf(LogERROR, "Cannot determine ethernet address"
|
||||
" for proxy ARP\n");
|
||||
return 0;
|
||||
}
|
||||
if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
|
||||
LogPrintf(LogERROR, "sifproxyarp: opening routing socket: %s\n",
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
arpmsg.hdr.rtm_type = RTM_ADD;
|
||||
arpmsg.hdr.rtm_flags = RTF_ANNOUNCE | RTF_HOST | RTF_STATIC;
|
||||
arpmsg.hdr.rtm_version = RTM_VERSION;
|
||||
arpmsg.hdr.rtm_seq = ++rtm_seq;
|
||||
arpmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY;
|
||||
arpmsg.hdr.rtm_inits = RTV_EXPIRE;
|
||||
arpmsg.dst.sin_len = sizeof(struct sockaddr_inarp);
|
||||
arpmsg.dst.sin_family = AF_INET;
|
||||
arpmsg.dst.sin_addr.s_addr = hisaddr;
|
||||
arpmsg.dst.sin_other = SIN_PROXY;
|
||||
|
||||
arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg
|
||||
+ arpmsg.hwa.sdl_len;
|
||||
if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
|
||||
LogPrintf(LogERROR, "Add proxy arp entry: %s\n", strerror(errno));
|
||||
close(routes);
|
||||
arpmsg_valid = 1;
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
close(routes);
|
||||
arpmsg_valid = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* cifproxyarp - Delete the proxy ARP entry for the peer.
|
||||
*/
|
||||
int
|
||||
cifproxyarp(unit, hisaddr)
|
||||
int unit;
|
||||
u_long hisaddr;
|
||||
cifproxyarp(int unit, u_long hisaddr)
|
||||
{
|
||||
int routes;
|
||||
int routes;
|
||||
|
||||
if (!arpmsg_valid)
|
||||
return 0;
|
||||
arpmsg_valid = 0;
|
||||
if (!arpmsg_valid)
|
||||
return 0;
|
||||
arpmsg_valid = 0;
|
||||
|
||||
arpmsg.hdr.rtm_type = RTM_DELETE;
|
||||
arpmsg.hdr.rtm_seq = ++rtm_seq;
|
||||
|
||||
if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
|
||||
LogPrintf(LogERROR, "sifproxyarp: opening routing socket: %s\n",
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
|
||||
LogPrintf(LogERROR, "Delete proxy arp entry: %s\n", strerror(errno));
|
||||
close(routes);
|
||||
return 0;
|
||||
}
|
||||
arpmsg.hdr.rtm_type = RTM_DELETE;
|
||||
arpmsg.hdr.rtm_seq = ++rtm_seq;
|
||||
|
||||
if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
|
||||
LogPrintf(LogERROR, "sifproxyarp: opening routing socket: %s\n",
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
|
||||
LogPrintf(LogERROR, "Delete proxy arp entry: %s\n", strerror(errno));
|
||||
close(routes);
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
close(routes);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else /* RTM_VERSION */
|
||||
#else /* RTM_VERSION */
|
||||
|
||||
/*
|
||||
* sifproxyarp - Make a proxy ARP entry for the peer.
|
||||
*/
|
||||
int
|
||||
sifproxyarp(unit, hisaddr)
|
||||
int unit;
|
||||
u_long hisaddr;
|
||||
sifproxyarp(int unit, u_long hisaddr)
|
||||
{
|
||||
struct arpreq arpreq;
|
||||
struct {
|
||||
struct sockaddr_dl sdl;
|
||||
char space[128];
|
||||
} dls;
|
||||
struct arpreq arpreq;
|
||||
struct {
|
||||
struct sockaddr_dl sdl;
|
||||
char space[128];
|
||||
} dls;
|
||||
|
||||
BZERO(&arpreq, sizeof(arpreq));
|
||||
BZERO(&arpreq, sizeof(arpreq));
|
||||
|
||||
/*
|
||||
* Get the hardware address of an interface on the same subnet
|
||||
* as our local address.
|
||||
*/
|
||||
if (!get_ether_addr(unit, hisaddr, &dls.sdl)) {
|
||||
LogPrintf(LOG_PHASE_BIT, "Cannot determine ethernet address for proxy ARP\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
arpreq.arp_ha.sa_len = sizeof(struct sockaddr);
|
||||
arpreq.arp_ha.sa_family = AF_UNSPEC;
|
||||
BCOPY(LLADDR(&dls.sdl), arpreq.arp_ha.sa_data, dls.sdl.sdl_alen);
|
||||
SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
|
||||
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
|
||||
arpreq.arp_flags = ATF_PERM | ATF_PUBL;
|
||||
if (ioctl(unit, SIOCSARP, (caddr_t)&arpreq) < 0) {
|
||||
LogPrintf(LogERROR, "sifproxyarp: ioctl(SIOCSARP): \n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
/*
|
||||
* Get the hardware address of an interface on the same subnet as our local
|
||||
* address.
|
||||
*/
|
||||
if (!get_ether_addr(unit, hisaddr, &dls.sdl)) {
|
||||
LogPrintf(LOG_PHASE_BIT, "Cannot determine ethernet address for proxy ARP\n");
|
||||
return 0;
|
||||
}
|
||||
arpreq.arp_ha.sa_len = sizeof(struct sockaddr);
|
||||
arpreq.arp_ha.sa_family = AF_UNSPEC;
|
||||
BCOPY(LLADDR(&dls.sdl), arpreq.arp_ha.sa_data, dls.sdl.sdl_alen);
|
||||
SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
|
||||
((struct sockaddr_in *) & arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
|
||||
arpreq.arp_flags = ATF_PERM | ATF_PUBL;
|
||||
if (ioctl(unit, SIOCSARP, (caddr_t) & arpreq) < 0) {
|
||||
LogPrintf(LogERROR, "sifproxyarp: ioctl(SIOCSARP): \n");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* cifproxyarp - Delete the proxy ARP entry for the peer.
|
||||
*/
|
||||
int
|
||||
cifproxyarp(unit, hisaddr)
|
||||
int unit;
|
||||
u_long hisaddr;
|
||||
cifproxyarp(int unit, u_long hisaddr)
|
||||
{
|
||||
struct arpreq arpreq;
|
||||
struct arpreq arpreq;
|
||||
|
||||
BZERO(&arpreq, sizeof(arpreq));
|
||||
SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
|
||||
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
|
||||
if (ioctl(unit, SIOCDARP, (caddr_t)&arpreq) < 0) {
|
||||
LogPrintf(LogERROR, "cifproxyarp: ioctl(SIOCDARP): \n");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
BZERO(&arpreq, sizeof(arpreq));
|
||||
SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
|
||||
((struct sockaddr_in *) & arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
|
||||
if (ioctl(unit, SIOCDARP, (caddr_t) & arpreq) < 0) {
|
||||
LogPrintf(LogERROR, "cifproxyarp: ioctl(SIOCDARP): \n");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif /* RTM_VERSION */
|
||||
|
||||
#endif /* RTM_VERSION */
|
||||
|
||||
|
||||
/*
|
||||
@ -234,87 +220,86 @@ cifproxyarp(unit, hisaddr)
|
||||
#define MAX_IFS 32
|
||||
|
||||
int
|
||||
get_ether_addr(s, ipaddr, hwaddr)
|
||||
int s;
|
||||
u_long ipaddr;
|
||||
struct sockaddr_dl *hwaddr;
|
||||
get_ether_addr(int s, u_long ipaddr, struct sockaddr_dl * hwaddr)
|
||||
{
|
||||
struct ifreq *ifr, *ifend, *ifp;
|
||||
u_long ina, mask;
|
||||
struct sockaddr_dl *dla;
|
||||
struct ifreq ifreq;
|
||||
struct ifconf ifc;
|
||||
struct ifreq ifs[MAX_IFS];
|
||||
|
||||
ifc.ifc_len = sizeof(ifs);
|
||||
ifc.ifc_req = ifs;
|
||||
if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
|
||||
LogPrintf(LogERROR, "get_ether_addr: ioctl(SIOCGIFCONF): \n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Scan through looking for an interface with an Internet
|
||||
* address on the same subnet as `ipaddr'.
|
||||
*/
|
||||
ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
|
||||
for (ifr = ifc.ifc_req; ifr < ifend; ) {
|
||||
if (ifr->ifr_addr.sa_family == AF_INET) {
|
||||
ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
|
||||
strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
|
||||
ifreq.ifr_name[sizeof(ifreq.ifr_name)-1]='\0';
|
||||
/*
|
||||
* Check that the interface is up, and not point-to-point
|
||||
* or loopback.
|
||||
*/
|
||||
if (ioctl(s, SIOCGIFFLAGS, &ifreq) < 0)
|
||||
continue;
|
||||
if ((ifreq.ifr_flags &
|
||||
(IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT|IFF_LOOPBACK|IFF_NOARP))
|
||||
!= (IFF_UP|IFF_BROADCAST))
|
||||
goto nextif;
|
||||
/*
|
||||
* Get its netmask and check that it's on the right subnet.
|
||||
*/
|
||||
if (ioctl(s, SIOCGIFNETMASK, &ifreq) < 0)
|
||||
continue;
|
||||
mask = ((struct sockaddr_in *) &ifreq.ifr_addr)->sin_addr.s_addr;
|
||||
if ((ipaddr & mask) != (ina & mask))
|
||||
goto nextif;
|
||||
|
||||
break;
|
||||
}
|
||||
nextif:
|
||||
ifr = (struct ifreq *) ((char *)&ifr->ifr_addr + ifr->ifr_addr.sa_len);
|
||||
}
|
||||
|
||||
if (ifr >= ifend)
|
||||
return 0;
|
||||
LogPrintf(LogPHASE, "Found interface %s for proxy arp\n", ifr->ifr_name);
|
||||
|
||||
/*
|
||||
* Now scan through again looking for a link-level address
|
||||
* for this interface.
|
||||
*/
|
||||
ifp = ifr;
|
||||
for (ifr = ifc.ifc_req; ifr < ifend; ) {
|
||||
if (strcmp(ifp->ifr_name, ifr->ifr_name) == 0
|
||||
&& ifr->ifr_addr.sa_family == AF_LINK) {
|
||||
/*
|
||||
* Found the link-level address - copy it out
|
||||
*/
|
||||
dla = (struct sockaddr_dl *) &ifr->ifr_addr;
|
||||
#ifdef __bsdi__
|
||||
if (dla->sdl_alen == 0)
|
||||
kmemgetether(ifr->ifr_name, dla);
|
||||
#endif
|
||||
BCOPY(dla, hwaddr, dla->sdl_len);
|
||||
return 1;
|
||||
}
|
||||
ifr = (struct ifreq *) ((char *)&ifr->ifr_addr + ifr->ifr_addr.sa_len);
|
||||
}
|
||||
struct ifreq *ifr, *ifend, *ifp;
|
||||
u_long ina, mask;
|
||||
struct sockaddr_dl *dla;
|
||||
struct ifreq ifreq;
|
||||
struct ifconf ifc;
|
||||
struct ifreq ifs[MAX_IFS];
|
||||
|
||||
ifc.ifc_len = sizeof(ifs);
|
||||
ifc.ifc_req = ifs;
|
||||
if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
|
||||
LogPrintf(LogERROR, "get_ether_addr: ioctl(SIOCGIFCONF): \n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Scan through looking for an interface with an Internet address on the
|
||||
* same subnet as `ipaddr'.
|
||||
*/
|
||||
ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
|
||||
for (ifr = ifc.ifc_req; ifr < ifend;) {
|
||||
if (ifr->ifr_addr.sa_family == AF_INET) {
|
||||
ina = ((struct sockaddr_in *) & ifr->ifr_addr)->sin_addr.s_addr;
|
||||
strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
|
||||
ifreq.ifr_name[sizeof(ifreq.ifr_name) - 1] = '\0';
|
||||
|
||||
/*
|
||||
* Check that the interface is up, and not point-to-point or loopback.
|
||||
*/
|
||||
if (ioctl(s, SIOCGIFFLAGS, &ifreq) < 0)
|
||||
continue;
|
||||
if ((ifreq.ifr_flags &
|
||||
(IFF_UP | IFF_BROADCAST | IFF_POINTOPOINT | IFF_LOOPBACK | IFF_NOARP))
|
||||
!= (IFF_UP | IFF_BROADCAST))
|
||||
goto nextif;
|
||||
|
||||
/*
|
||||
* Get its netmask and check that it's on the right subnet.
|
||||
*/
|
||||
if (ioctl(s, SIOCGIFNETMASK, &ifreq) < 0)
|
||||
continue;
|
||||
mask = ((struct sockaddr_in *) & ifreq.ifr_addr)->sin_addr.s_addr;
|
||||
if ((ipaddr & mask) != (ina & mask))
|
||||
goto nextif;
|
||||
|
||||
break;
|
||||
}
|
||||
nextif:
|
||||
ifr = (struct ifreq *) ((char *) &ifr->ifr_addr + ifr->ifr_addr.sa_len);
|
||||
}
|
||||
|
||||
if (ifr >= ifend)
|
||||
return 0;
|
||||
LogPrintf(LogPHASE, "Found interface %s for proxy arp\n", ifr->ifr_name);
|
||||
|
||||
/*
|
||||
* Now scan through again looking for a link-level address for this
|
||||
* interface.
|
||||
*/
|
||||
ifp = ifr;
|
||||
for (ifr = ifc.ifc_req; ifr < ifend;) {
|
||||
if (strcmp(ifp->ifr_name, ifr->ifr_name) == 0
|
||||
&& ifr->ifr_addr.sa_family == AF_LINK) {
|
||||
|
||||
/*
|
||||
* Found the link-level address - copy it out
|
||||
*/
|
||||
dla = (struct sockaddr_dl *) & ifr->ifr_addr;
|
||||
#ifdef __bsdi__
|
||||
if (dla->sdl_alen == 0)
|
||||
kmemgetether(ifr->ifr_name, dla);
|
||||
#endif
|
||||
BCOPY(dla, hwaddr, dla->sdl_len);
|
||||
return 1;
|
||||
}
|
||||
ifr = (struct ifreq *) ((char *) &ifr->ifr_addr + ifr->ifr_addr.sa_len);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __bsdi__
|
||||
@ -322,8 +307,8 @@ get_ether_addr(s, ipaddr, hwaddr)
|
||||
|
||||
struct nlist nl[] = {
|
||||
#define N_IFNET 0
|
||||
{ "_ifnet" },
|
||||
"",
|
||||
{"_ifnet"},
|
||||
"",
|
||||
};
|
||||
|
||||
|
||||
@ -333,10 +318,7 @@ kvm_t *kvmd;
|
||||
* Read kernel memory, return 0 on success.
|
||||
*/
|
||||
int
|
||||
kread(addr, buf, size)
|
||||
u_long addr;
|
||||
char *buf;
|
||||
int size;
|
||||
kread(u_long addr, char *buf, int size)
|
||||
{
|
||||
if (kvm_read(kvmd, addr, buf, size) != size) {
|
||||
/* XXX this duplicates kvm_read's error printout */
|
||||
@ -346,21 +328,20 @@ kread(addr, buf, size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
kmemgetether(ifname, dlo)
|
||||
char *ifname;
|
||||
struct sockaddr_dl *dlo;
|
||||
void
|
||||
kmemgetether(char *ifname, struct sockaddr_dl * dlo)
|
||||
{
|
||||
struct ifnet ifnet;
|
||||
int n;
|
||||
u_long addr, ifaddraddr, ifnetfound, ifaddrfound;
|
||||
char name[16+32];
|
||||
char name[16 + 32];
|
||||
struct sockaddr *sa;
|
||||
char *cp;
|
||||
struct sockaddr_dl *sdl;
|
||||
union {
|
||||
struct ifaddr ifa;
|
||||
struct in_ifaddr in;
|
||||
} ifaddr;
|
||||
struct ifaddr ifa;
|
||||
struct in_ifaddr in;
|
||||
} ifaddr;
|
||||
struct arpcom ac;
|
||||
|
||||
kvmd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
|
||||
@ -368,62 +349,64 @@ struct sockaddr_dl *dlo;
|
||||
n = kvm_nlist(kvmd, nl);
|
||||
if (n >= 0) {
|
||||
addr = nl[N_IFNET].n_value;
|
||||
kread(addr, (char *)&addr, sizeof(addr));
|
||||
kread(addr, (char *) &addr, sizeof(addr));
|
||||
ifaddraddr = ifnetfound = 0;
|
||||
while (addr || ifaddraddr) {
|
||||
ifnetfound = addr;
|
||||
if (ifaddraddr == 0) {
|
||||
if (kread(addr, (char *)&ifnet, sizeof(ifnet)) ||
|
||||
kread((u_long)ifnet.if_name, name, 16))
|
||||
return;
|
||||
if (kread(addr, (char *) &ifnet, sizeof(ifnet)) ||
|
||||
kread((u_long) ifnet.if_name, name, 16))
|
||||
return;
|
||||
name[15] = 0;
|
||||
addr = (u_long) ifnet.if_next;
|
||||
cp = (char *)index(name, '\0');
|
||||
cp = (char *) index(name, '\0');
|
||||
cp += sprintf(cp, "%d", ifnet.if_unit);
|
||||
*cp = '\0';
|
||||
ifaddraddr = (u_long)ifnet.if_addrlist;
|
||||
ifaddraddr = (u_long) ifnet.if_addrlist;
|
||||
}
|
||||
ifaddrfound = ifaddraddr;
|
||||
if (ifaddraddr) {
|
||||
if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) {
|
||||
if (kread(ifaddraddr, (char *) &ifaddr, sizeof ifaddr)) {
|
||||
ifaddraddr = 0;
|
||||
continue;
|
||||
}
|
||||
#define CP(x) ((char *)(x))
|
||||
cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) + CP(&ifaddr);
|
||||
sa = (struct sockaddr *)cp;
|
||||
sa = (struct sockaddr *) cp;
|
||||
if (sa->sa_family == AF_LINK && strcmp(ifname, name) == 0) {
|
||||
sdl = (struct sockaddr_dl *)sa;
|
||||
cp = (char *)LLADDR(sdl);
|
||||
sdl = (struct sockaddr_dl *) sa;
|
||||
cp = (char *) LLADDR(sdl);
|
||||
n = sdl->sdl_alen;
|
||||
if (ifnet.if_type == IFT_ETHER) {
|
||||
if (n == 0) {
|
||||
kread(ifnetfound, (char *)&ac, sizeof(ac));
|
||||
cp = (char *)LLADDR(sdl);
|
||||
bcopy((char *)ac.ac_enaddr, cp, 6);
|
||||
sdl->sdl_alen = 6;
|
||||
}
|
||||
bcopy(sdl, dlo, sizeof(*sdl));
|
||||
return;
|
||||
if (n == 0) {
|
||||
kread(ifnetfound, (char *) &ac, sizeof(ac));
|
||||
cp = (char *) LLADDR(sdl);
|
||||
bcopy((char *) ac.ac_enaddr, cp, 6);
|
||||
sdl->sdl_alen = 6;
|
||||
}
|
||||
bcopy(sdl, dlo, sizeof(*sdl));
|
||||
return;
|
||||
}
|
||||
}
|
||||
ifaddraddr = (u_long)ifaddr.ifa.ifa_next;
|
||||
ifaddraddr = (u_long) ifaddr.ifa.ifa_next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
main()
|
||||
{
|
||||
u_long ipaddr;
|
||||
int s;
|
||||
u_long ipaddr;
|
||||
int s;
|
||||
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
ipaddr = inet_addr("192.168.1.32");
|
||||
sifproxyarp(s, ipaddr);
|
||||
close(s);
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
ipaddr = inet_addr("192.168.1.32");
|
||||
sifproxyarp(s, ipaddr);
|
||||
close(s);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: arp.h,v 1.3 1997/02/22 16:09:57 peter Exp $
|
||||
* $Id: arp.h,v 1.4 1997/06/09 03:27:12 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -25,4 +25,5 @@
|
||||
#define _ARP_H_
|
||||
extern int cifproxyarp(int, u_long);
|
||||
extern int sifproxyarp(int, u_long);
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: async.c,v 1.9 1997/06/09 03:27:12 brian Exp $
|
||||
* $Id: async.c,v 1.10 1997/06/23 23:08:23 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include "fsm.h"
|
||||
@ -38,7 +38,7 @@ struct async_state {
|
||||
u_char xbuff[HDLCSIZE]; /* xmit buffer */
|
||||
u_long my_accmap;
|
||||
u_long his_accmap;
|
||||
} AsyncState;
|
||||
} AsyncState;
|
||||
|
||||
#define MODE_HUNT 0x01
|
||||
#define MODE_ESC 0x02
|
||||
@ -54,8 +54,7 @@ AsyncInit()
|
||||
}
|
||||
|
||||
void
|
||||
SetLinkParams(lcp)
|
||||
struct lcpstate *lcp;
|
||||
SetLinkParams(struct lcpstate * lcp)
|
||||
{
|
||||
struct async_state *stp = &AsyncState;
|
||||
|
||||
@ -67,20 +66,17 @@ struct lcpstate *lcp;
|
||||
* Encode into async HDLC byte code if necessary
|
||||
*/
|
||||
static void
|
||||
HdlcPutByte(cp, c, proto)
|
||||
u_char **cp;
|
||||
u_char c;
|
||||
int proto;
|
||||
HdlcPutByte(u_char ** cp, u_char c, int proto)
|
||||
{
|
||||
u_char *wp;
|
||||
|
||||
wp = *cp;
|
||||
if ((c < 0x20 && (proto == PROTO_LCP || (AsyncState.his_accmap & (1<<c))))
|
||||
|| (c == HDLC_ESC) || (c == HDLC_SYN)) {
|
||||
if ((c < 0x20 && (proto == PROTO_LCP || (AsyncState.his_accmap & (1 << c))))
|
||||
|| (c == HDLC_ESC) || (c == HDLC_SYN)) {
|
||||
*wp++ = HDLC_ESC;
|
||||
c ^= HDLC_XOR;
|
||||
}
|
||||
if (EscMap[32] && EscMap[c >> 3] & (1 << (c&7))) {
|
||||
if (EscMap[32] && EscMap[c >> 3] & (1 << (c & 7))) {
|
||||
*wp++ = HDLC_ESC;
|
||||
c ^= HDLC_XOR;
|
||||
}
|
||||
@ -89,10 +85,7 @@ int proto;
|
||||
}
|
||||
|
||||
void
|
||||
AsyncOutput(pri, bp, proto)
|
||||
int pri;
|
||||
struct mbuf *bp;
|
||||
int proto;
|
||||
AsyncOutput(int pri, struct mbuf * bp, int proto)
|
||||
{
|
||||
struct async_state *hs = &AsyncState;
|
||||
u_char *cp, *sp, *ep;
|
||||
@ -106,7 +99,7 @@ int proto;
|
||||
cp = hs->xbuff;
|
||||
ep = cp + HDLCSIZE - 10;
|
||||
wp = bp;
|
||||
*cp ++ = HDLC_SYN;
|
||||
*cp++ = HDLC_SYN;
|
||||
while (wp) {
|
||||
sp = MBUF_CTOP(wp);
|
||||
for (cnt = wp->cnt; cnt > 0; cnt--) {
|
||||
@ -118,33 +111,32 @@ int proto;
|
||||
}
|
||||
wp = wp->next;
|
||||
}
|
||||
*cp ++ = HDLC_SYN;
|
||||
*cp++ = HDLC_SYN;
|
||||
|
||||
cnt = cp - hs->xbuff;
|
||||
LogDumpBuff(LogASYNC, "WriteModem", hs->xbuff, cnt);
|
||||
WriteModem(pri, (char *)hs->xbuff, cnt);
|
||||
WriteModem(pri, (char *) hs->xbuff, cnt);
|
||||
OsAddOutOctets(cnt);
|
||||
pfree(bp);
|
||||
}
|
||||
|
||||
struct mbuf *
|
||||
AsyncDecode(c)
|
||||
u_char c;
|
||||
AsyncDecode(u_char c)
|
||||
{
|
||||
struct async_state *hs = &AsyncState;
|
||||
struct mbuf *bp;
|
||||
|
||||
if ((hs->mode & MODE_HUNT) && c != HDLC_SYN)
|
||||
return(NULLBUFF);
|
||||
return (NULLBUFF);
|
||||
|
||||
switch (c) {
|
||||
case HDLC_SYN:
|
||||
hs->mode &= ~MODE_HUNT;
|
||||
if (hs->length) { /* packet is ready. */
|
||||
if (hs->length) { /* packet is ready. */
|
||||
bp = mballoc(hs->length, MB_ASYNC);
|
||||
mbwrite(bp, hs->hbuff, hs->length);
|
||||
hs->length = 0;
|
||||
return(bp);
|
||||
return (bp);
|
||||
}
|
||||
break;
|
||||
case HDLC_ESC:
|
||||
@ -172,9 +164,7 @@ u_char c;
|
||||
}
|
||||
|
||||
void
|
||||
AsyncInput(buff, cnt)
|
||||
u_char *buff;
|
||||
int cnt;
|
||||
AsyncInput(u_char * buff, int cnt)
|
||||
{
|
||||
struct mbuf *bp;
|
||||
|
||||
@ -188,7 +178,7 @@ int cnt;
|
||||
while (cnt > 0) {
|
||||
bp = AsyncDecode(*buff++);
|
||||
if (bp)
|
||||
HdlcInput(bp);
|
||||
HdlcInput(bp);
|
||||
cnt--;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: auth.c,v 1.13 1997/05/26 00:43:55 brian Exp $
|
||||
* $Id: auth.c,v 1.14 1997/06/09 03:27:13 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Implement check against with registered IP addresses.
|
||||
@ -35,45 +35,46 @@ extern FILE *OpenSecret();
|
||||
extern void CloseSecret();
|
||||
|
||||
LOCAL_AUTH_VALID
|
||||
LocalAuthInit(void)
|
||||
LocalAuthInit()
|
||||
{
|
||||
|
||||
char *p;
|
||||
|
||||
if ( gethostname( VarShortHost, sizeof(VarShortHost))) {
|
||||
return(NOT_FOUND);
|
||||
if (gethostname(VarShortHost, sizeof(VarShortHost))) {
|
||||
return (NOT_FOUND);
|
||||
}
|
||||
p = strchr( VarShortHost, '.' );
|
||||
if (p)
|
||||
*p = '\0';
|
||||
p = strchr(VarShortHost, '.');
|
||||
if (p)
|
||||
*p = '\0';
|
||||
|
||||
VarLocalAuth = LOCAL_NO_AUTH;
|
||||
return LocalAuthValidate( SECRETFILE, VarShortHost, "" );
|
||||
return LocalAuthValidate(SECRETFILE, VarShortHost, "");
|
||||
|
||||
}
|
||||
|
||||
LOCAL_AUTH_VALID
|
||||
LocalAuthValidate( char *fname, char *system, char *key) {
|
||||
LocalAuthValidate(char *fname, char *system, char *key)
|
||||
{
|
||||
FILE *fp;
|
||||
int n;
|
||||
char *vector[20]; /* XXX */
|
||||
char buff[200]; /* XXX */
|
||||
char *vector[20]; /* XXX */
|
||||
char buff[200]; /* XXX */
|
||||
LOCAL_AUTH_VALID rc;
|
||||
|
||||
rc = NOT_FOUND; /* No system entry */
|
||||
fp = OpenSecret(fname);
|
||||
if (fp == NULL)
|
||||
return( rc );
|
||||
return (rc);
|
||||
while (fgets(buff, sizeof(buff), fp)) {
|
||||
if (buff[0] == '#')
|
||||
continue;
|
||||
buff[strlen(buff)-1] = 0;
|
||||
buff[strlen(buff) - 1] = 0;
|
||||
bzero(vector, sizeof(vector));
|
||||
n = MakeArgs(buff, vector, VECSIZE(vector));
|
||||
if (n < 1)
|
||||
continue;
|
||||
if (strcmp(vector[0], system) == 0) {
|
||||
if ( vector[1] != (char *) NULL && strcmp(vector[1], key) == 0) {
|
||||
if (vector[1] != (char *) NULL && strcmp(vector[1], key) == 0) {
|
||||
rc = VALID; /* Valid */
|
||||
} else {
|
||||
rc = INVALID; /* Invalid */
|
||||
@ -82,12 +83,11 @@ LocalAuthValidate( char *fname, char *system, char *key) {
|
||||
}
|
||||
}
|
||||
CloseSecret(fp);
|
||||
return( rc );
|
||||
return (rc);
|
||||
}
|
||||
|
||||
int
|
||||
AuthValidate(fname, system, key)
|
||||
char *fname, *system, *key;
|
||||
AuthValidate(char *fname, char *system, char *key)
|
||||
{
|
||||
FILE *fp;
|
||||
int n;
|
||||
@ -97,11 +97,11 @@ char *fname, *system, *key;
|
||||
|
||||
fp = OpenSecret(fname);
|
||||
if (fp == NULL)
|
||||
return(0);
|
||||
return (0);
|
||||
while (fgets(buff, sizeof(buff), fp)) {
|
||||
if (buff[0] == '#')
|
||||
continue;
|
||||
buff[strlen(buff)-1] = 0;
|
||||
buff[strlen(buff) - 1] = 0;
|
||||
bzero(vector, sizeof(vector));
|
||||
n = MakeArgs(buff, vector, VECSIZE(vector));
|
||||
if (n < 2)
|
||||
@ -110,29 +110,27 @@ char *fname, *system, *key;
|
||||
ExpandString(vector[1], passwd, sizeof(passwd), 0);
|
||||
if (strcmp(passwd, key) == 0) {
|
||||
CloseSecret(fp);
|
||||
bzero(&DefHisAddress, sizeof(DefHisAddress));
|
||||
n -= 2;
|
||||
if (n > 0) {
|
||||
bzero(&DefHisAddress, sizeof(DefHisAddress));
|
||||
n -= 2;
|
||||
if (n > 0) {
|
||||
if (ParseAddr(n--, &vector[2],
|
||||
&DefHisAddress.ipaddr,
|
||||
&DefHisAddress.mask,
|
||||
&DefHisAddress.width) == 0) {
|
||||
return(0); /* Invalid */
|
||||
&DefHisAddress.ipaddr,
|
||||
&DefHisAddress.mask,
|
||||
&DefHisAddress.width) == 0) {
|
||||
return (0); /* Invalid */
|
||||
}
|
||||
}
|
||||
IpcpInit();
|
||||
return(1); /* Valid */
|
||||
return (1); /* Valid */
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseSecret(fp);
|
||||
return(0); /* Invalid */
|
||||
return (0); /* Invalid */
|
||||
}
|
||||
|
||||
char *
|
||||
AuthGetSecret(fname, system, len, setaddr)
|
||||
char *fname, *system;
|
||||
int len, setaddr;
|
||||
AuthGetSecret(char *fname, char *system, int len, int setaddr)
|
||||
{
|
||||
FILE *fp;
|
||||
int n;
|
||||
@ -142,11 +140,11 @@ int len, setaddr;
|
||||
|
||||
fp = OpenSecret(fname);
|
||||
if (fp == NULL)
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
while (fgets(buff, sizeof(buff), fp)) {
|
||||
if (buff[0] == '#')
|
||||
continue;
|
||||
buff[strlen(buff)-1] = 0;
|
||||
buff[strlen(buff) - 1] = 0;
|
||||
bzero(vector, sizeof(vector));
|
||||
n = MakeArgs(buff, vector, VECSIZE(vector));
|
||||
if (n < 2)
|
||||
@ -154,7 +152,7 @@ int len, setaddr;
|
||||
if (strlen(vector[0]) == len && strncmp(vector[0], system, len) == 0) {
|
||||
ExpandString(vector[1], passwd, sizeof(passwd), 0);
|
||||
if (setaddr) {
|
||||
bzero(&DefHisAddress, sizeof(DefHisAddress));
|
||||
bzero(&DefHisAddress, sizeof(DefHisAddress));
|
||||
}
|
||||
n -= 2;
|
||||
if (n > 0 && setaddr) {
|
||||
@ -163,18 +161,17 @@ int len, setaddr;
|
||||
&DefHisAddress.ipaddr,
|
||||
&DefHisAddress.mask,
|
||||
&DefHisAddress.width) != 0)
|
||||
IpcpInit();
|
||||
IpcpInit();
|
||||
}
|
||||
return(passwd);
|
||||
return (passwd);
|
||||
}
|
||||
}
|
||||
CloseSecret(fp);
|
||||
return(NULL); /* Invalid */
|
||||
return (NULL); /* Invalid */
|
||||
}
|
||||
|
||||
static void
|
||||
AuthTimeout(authp)
|
||||
struct authinfo *authp;
|
||||
AuthTimeout(struct authinfo * authp)
|
||||
{
|
||||
struct pppTimer *tp;
|
||||
|
||||
@ -182,13 +179,12 @@ struct authinfo *authp;
|
||||
StopTimer(tp);
|
||||
if (--authp->retry > 0) {
|
||||
StartTimer(tp);
|
||||
(authp->ChallengeFunc)(++authp->id);
|
||||
(authp->ChallengeFunc) (++authp->id);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StartAuthChallenge(authp)
|
||||
struct authinfo *authp;
|
||||
StartAuthChallenge(struct authinfo * authp)
|
||||
{
|
||||
struct pppTimer *tp;
|
||||
|
||||
@ -197,16 +193,15 @@ struct authinfo *authp;
|
||||
tp->func = AuthTimeout;
|
||||
tp->load = VarRetryTimeout * SECTICKS;
|
||||
tp->state = TIMER_STOPPED;
|
||||
tp->arg = (void *)authp;
|
||||
tp->arg = (void *) authp;
|
||||
StartTimer(tp);
|
||||
authp->retry = 3;
|
||||
authp->id = 1;
|
||||
(authp->ChallengeFunc)(authp->id);
|
||||
(authp->ChallengeFunc) (authp->id);
|
||||
}
|
||||
|
||||
void
|
||||
StopAuthTimer(authp)
|
||||
struct authinfo *authp;
|
||||
StopAuthTimer(struct authinfo * authp)
|
||||
{
|
||||
StopTimer(&authp->authtimer);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: auth.h,v 1.5 1997/02/22 16:10:02 peter Exp $
|
||||
* $Id: auth.h,v 1.6 1997/06/09 03:27:13 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -23,11 +23,13 @@
|
||||
#ifndef _AUTH_H_
|
||||
#define _AUTH_H_
|
||||
|
||||
typedef enum { VALID, INVALID, NOT_FOUND } LOCAL_AUTH_VALID;
|
||||
LOCAL_AUTH_VALID LocalAuthValidate( char *, char *, char *);
|
||||
typedef enum {
|
||||
VALID, INVALID, NOT_FOUND
|
||||
} LOCAL_AUTH_VALID;
|
||||
LOCAL_AUTH_VALID LocalAuthValidate(char *, char *, char *);
|
||||
|
||||
struct authinfo {
|
||||
void (*ChallengeFunc)();
|
||||
void (*ChallengeFunc) ();
|
||||
struct pppTimer authtimer;
|
||||
int retry;
|
||||
int id;
|
||||
@ -41,4 +43,5 @@ extern void StopAuthTimer(struct authinfo *);
|
||||
extern void StartAuthChallenge(struct authinfo *);
|
||||
extern LOCAL_AUTH_VALID LocalAuthInit(void);
|
||||
extern int AuthValidate(char *, char *, char *);
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: ccp.c,v 1.13 1997/06/09 03:27:14 brian Exp $
|
||||
* $Id: ccp.c,v 1.14 1997/08/20 23:47:40 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Support other compression protocols
|
||||
@ -34,9 +34,9 @@
|
||||
struct ccpstate CcpInfo;
|
||||
|
||||
static void CcpSendConfigReq(struct fsm *);
|
||||
static void CcpSendTerminateReq(struct fsm *fp);
|
||||
static void CcpSendTerminateAck(struct fsm *fp);
|
||||
static void CcpDecodeConfig(u_char *cp, int flen, int mode);
|
||||
static void CcpSendTerminateReq(struct fsm * fp);
|
||||
static void CcpSendTerminateAck(struct fsm * fp);
|
||||
static void CcpDecodeConfig(u_char * cp, int flen, int mode);
|
||||
static void CcpLayerStart(struct fsm *);
|
||||
static void CcpLayerFinish(struct fsm *);
|
||||
static void CcpLayerUp(struct fsm *);
|
||||
@ -53,8 +53,8 @@ struct fsm CcpFsm = {
|
||||
ST_INITIAL,
|
||||
0, 0, 0,
|
||||
0,
|
||||
{ 0, 0, 0, NULL, NULL, NULL },
|
||||
{ 0, 0, 0, NULL, NULL, NULL },
|
||||
{0, 0, 0, NULL, NULL, NULL},
|
||||
{0, 0, 0, NULL, NULL, NULL},
|
||||
LogCCP,
|
||||
|
||||
CcpLayerUp,
|
||||
@ -69,12 +69,12 @@ struct fsm CcpFsm = {
|
||||
};
|
||||
|
||||
static char const *cftypes[] = {
|
||||
/* 0 */ "OUI", "PRED1", "PRED2", "PUDDLE",
|
||||
/* 4 */ "???", "???", "???", "???",
|
||||
/* 8 */ "???", "???", "???", "???",
|
||||
/* 12 */ "???", "???", "???", "???",
|
||||
/* 16 */ "HWPPC", "STAC", "MSPPC", "GAND",
|
||||
/* 20 */ "V42BIS", "BSD",
|
||||
/* 0 */ "OUI", "PRED1", "PRED2", "PUDDLE",
|
||||
/* 4 */ "???", "???", "???", "???",
|
||||
/* 8 */ "???", "???", "???", "???",
|
||||
/* 12 */ "???", "???", "???", "???",
|
||||
/* 16 */ "HWPPC", "STAC", "MSPPC", "GAND",
|
||||
/* 20 */ "V42BIS", "BSD",
|
||||
};
|
||||
|
||||
int
|
||||
@ -106,16 +106,14 @@ CcpInit()
|
||||
}
|
||||
|
||||
static void
|
||||
CcpInitRestartCounter(fp)
|
||||
struct fsm *fp;
|
||||
CcpInitRestartCounter(struct fsm * fp)
|
||||
{
|
||||
fp->FsmTimer.load = VarRetryTimeout * SECTICKS;
|
||||
fp->restart = 5;
|
||||
}
|
||||
|
||||
static void
|
||||
CcpSendConfigReq(fp)
|
||||
struct fsm *fp;
|
||||
CcpSendConfigReq(struct fsm * fp)
|
||||
{
|
||||
u_char *cp;
|
||||
struct ccpstate *icp = &CcpInfo;
|
||||
@ -123,59 +121,53 @@ struct fsm *fp;
|
||||
cp = ReqBuff;
|
||||
LogPrintf(LogCCP, "CcpSendConfigReq\n");
|
||||
if (icp->want_proto && !REJECTED(icp, TY_PRED1)) {
|
||||
*cp++ = TY_PRED1; *cp++ = 2;
|
||||
*cp++ = TY_PRED1;
|
||||
*cp++ = 2;
|
||||
}
|
||||
FsmOutput(fp, CODE_CONFIGREQ, fp->reqid++, ReqBuff, cp - ReqBuff);
|
||||
}
|
||||
|
||||
void
|
||||
CcpSendResetReq(fp)
|
||||
struct fsm *fp;
|
||||
CcpSendResetReq(struct fsm * fp)
|
||||
{
|
||||
Pred1Init(1); /* Initialize Input part */
|
||||
Pred1Init(1); /* Initialize Input part */
|
||||
LogPrintf(LogCCP, "CcpSendResetReq\n");
|
||||
FsmOutput(fp, CODE_RESETREQ, fp->reqid, NULL, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
CcpSendTerminateReq(fp)
|
||||
struct fsm *fp;
|
||||
CcpSendTerminateReq(struct fsm * fp)
|
||||
{
|
||||
/* XXX: No code yet */
|
||||
}
|
||||
|
||||
static void
|
||||
CcpSendTerminateAck(fp)
|
||||
struct fsm *fp;
|
||||
CcpSendTerminateAck(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogCCP, "CcpSendTerminateAck\n");
|
||||
FsmOutput(fp, CODE_TERMACK, fp->reqid++, NULL, 0);
|
||||
}
|
||||
|
||||
void
|
||||
CcpRecvResetReq(fp)
|
||||
struct fsm *fp;
|
||||
CcpRecvResetReq(struct fsm * fp)
|
||||
{
|
||||
Pred1Init(2); /* Initialize Output part */
|
||||
Pred1Init(2); /* Initialize Output part */
|
||||
}
|
||||
|
||||
static void
|
||||
CcpLayerStart(fp)
|
||||
struct fsm *fp;
|
||||
CcpLayerStart(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogCCP, "CcpLayerStart.\n");
|
||||
}
|
||||
|
||||
static void
|
||||
CcpLayerFinish(fp)
|
||||
struct fsm *fp;
|
||||
CcpLayerFinish(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogCCP, "CcpLayerFinish.\n");
|
||||
}
|
||||
|
||||
static void
|
||||
CcpLayerDown(fp)
|
||||
struct fsm *fp;
|
||||
CcpLayerDown(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogCCP, "CcpLayerDown.\n");
|
||||
}
|
||||
@ -184,13 +176,12 @@ struct fsm *fp;
|
||||
* Called when CCP has reached to OPEN state
|
||||
*/
|
||||
static void
|
||||
CcpLayerUp(fp)
|
||||
struct fsm *fp;
|
||||
CcpLayerUp(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogCCP, "CcpLayerUp(%d).\n", fp->state);
|
||||
LogPrintf(LogCCP, "myproto = %d, hisproto = %d\n",
|
||||
CcpInfo.want_proto, CcpInfo.his_proto);
|
||||
Pred1Init(3); /* Initialize Input and Output */
|
||||
CcpInfo.want_proto, CcpInfo.his_proto);
|
||||
Pred1Init(3); /* Initialize Input and Output */
|
||||
}
|
||||
|
||||
void
|
||||
@ -208,10 +199,7 @@ CcpOpen()
|
||||
}
|
||||
|
||||
static void
|
||||
CcpDecodeConfig(cp, plen, mode)
|
||||
u_char *cp;
|
||||
int plen;
|
||||
int mode;
|
||||
CcpDecodeConfig(u_char * cp, int plen, int mode)
|
||||
{
|
||||
int type, length;
|
||||
char tbuff[100];
|
||||
@ -265,7 +253,7 @@ int mode;
|
||||
}
|
||||
|
||||
void
|
||||
CcpInput(struct mbuf *bp)
|
||||
CcpInput(struct mbuf * bp)
|
||||
{
|
||||
if (phase == PHASE_NETWORK)
|
||||
FsmInput(&CcpFsm, bp);
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: ccp.h,v 1.5 1997/02/22 16:10:03 peter Exp $
|
||||
* $Id: ccp.h,v 1.6 1997/06/09 03:27:14 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -37,14 +37,14 @@
|
||||
#define TY_BSD 21 /* BSD LZW Compress */
|
||||
|
||||
struct ccpstate {
|
||||
u_long his_proto; /* peer's compression protocol */
|
||||
u_long want_proto; /* my compression protocol */
|
||||
u_long his_proto; /* peer's compression protocol */
|
||||
u_long want_proto; /* my compression protocol */
|
||||
|
||||
u_long his_reject; /* Request codes rejected by peer */
|
||||
u_long my_reject; /* Request codes I have rejected */
|
||||
u_long his_reject; /* Request codes rejected by peer */
|
||||
u_long my_reject; /* Request codes I have rejected */
|
||||
|
||||
u_long orgout, compout;
|
||||
u_long orgin, compin;
|
||||
u_long orgout, compout;
|
||||
u_long orgin, compin;
|
||||
};
|
||||
|
||||
extern struct ccpstate CcpInfo;
|
||||
@ -55,4 +55,5 @@ void CcpInput(struct mbuf *);
|
||||
void CcpUp(void);
|
||||
void CcpOpen(void);
|
||||
void CcpInit(void);
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: chap.c,v 1.18 1997/06/09 03:27:15 brian Exp $
|
||||
* $Id: chap.c,v 1.19 1997/06/14 00:21:23 ache Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -37,7 +37,7 @@ static char *chapcodes[] = {
|
||||
"???", "CHALLENGE", "RESPONSE", "SUCCESS", "FAILURE"
|
||||
};
|
||||
|
||||
struct authinfo AuthChapInfo = {
|
||||
struct authinfo AuthChapInfo = {
|
||||
SendChapChallenge,
|
||||
};
|
||||
|
||||
@ -45,16 +45,13 @@ extern char *AuthGetSecret();
|
||||
extern int randinit;
|
||||
|
||||
void
|
||||
ChapOutput(code, id, ptr, count)
|
||||
u_int code, id;
|
||||
u_char *ptr;
|
||||
int count;
|
||||
ChapOutput(u_int code, u_int id, u_char * ptr, int count)
|
||||
{
|
||||
int plen;
|
||||
struct fsmheader lh;
|
||||
struct mbuf *bp;
|
||||
|
||||
plen = sizeof(struct fsmheader) + count;
|
||||
plen = sizeof(struct fsmheader) + count;
|
||||
lh.code = code;
|
||||
lh.id = id;
|
||||
lh.length = htons(plen);
|
||||
@ -69,11 +66,10 @@ int count;
|
||||
|
||||
|
||||
static char challenge_data[80];
|
||||
static int challenge_len;
|
||||
static int challenge_len;
|
||||
|
||||
void
|
||||
SendChapChallenge(chapid)
|
||||
int chapid;
|
||||
SendChapChallenge(int chapid)
|
||||
{
|
||||
int len, i;
|
||||
char *cp;
|
||||
@ -82,7 +78,6 @@ int chapid;
|
||||
randinit = 1;
|
||||
srandomdev();
|
||||
}
|
||||
|
||||
cp = challenge_data;
|
||||
*cp++ = challenge_len = random() % 32 + 16;
|
||||
for (i = 0; i < challenge_len; i++)
|
||||
@ -94,22 +89,20 @@ int chapid;
|
||||
}
|
||||
|
||||
void
|
||||
RecvChapTalk(chp, bp)
|
||||
struct fsmheader *chp;
|
||||
struct mbuf *bp;
|
||||
RecvChapTalk(struct fsmheader * chp, struct mbuf * bp)
|
||||
{
|
||||
int valsize, len;
|
||||
int arglen, keylen, namelen;
|
||||
char *cp, *argp, *ap, *name, *digest;
|
||||
char *keyp;
|
||||
MD5_CTX context; /* context */
|
||||
MD5_CTX context; /* context */
|
||||
char answer[100];
|
||||
char cdigest[16];
|
||||
|
||||
len = ntohs(chp->length);
|
||||
LogPrintf(LogDEBUG, "RecvChapTalk: length: %d\n", len);
|
||||
arglen = len - sizeof(struct fsmheader);
|
||||
cp = (char *)MBUF_CTOP(bp);
|
||||
cp = (char *) MBUF_CTOP(bp);
|
||||
valsize = *cp++ & 255;
|
||||
name = cp + valsize;
|
||||
namelen = arglen - valsize - 1;
|
||||
@ -157,6 +150,7 @@ struct mbuf *bp;
|
||||
break;
|
||||
case CHAP_RESPONSE:
|
||||
if (keyp) {
|
||||
|
||||
/*
|
||||
* Compute correct digest value
|
||||
*/
|
||||
@ -167,10 +161,11 @@ struct mbuf *bp;
|
||||
ap += keylen;
|
||||
MD5Init(&context);
|
||||
MD5Update(&context, answer, ap - answer);
|
||||
MD5Update(&context, challenge_data+1, challenge_len);
|
||||
MD5Update(&context, challenge_data + 1, challenge_len);
|
||||
MD5Final(cdigest, &context);
|
||||
LogDumpBuff(LogDEBUG, "got", cp, 16);
|
||||
LogDumpBuff(LogDEBUG, "expect", cdigest, 16);
|
||||
|
||||
/*
|
||||
* Compare with the response
|
||||
*/
|
||||
@ -180,6 +175,7 @@ struct mbuf *bp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Peer is not registerd, or response digest is wrong.
|
||||
*/
|
||||
@ -191,9 +187,7 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
void
|
||||
RecvChapResult(chp, bp)
|
||||
struct fsmheader *chp;
|
||||
struct mbuf *bp;
|
||||
RecvChapResult(struct fsmheader * chp, struct mbuf * bp)
|
||||
{
|
||||
int len;
|
||||
struct lcpstate *lcp = &LcpInfo;
|
||||
@ -207,6 +201,7 @@ struct mbuf *bp;
|
||||
NewPhase(PHASE_NETWORK);
|
||||
}
|
||||
} else {
|
||||
|
||||
/*
|
||||
* Maybe, we shoud close LCP. Of cause, peer may take close action, too.
|
||||
*/
|
||||
@ -215,13 +210,13 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
void
|
||||
ChapInput(struct mbuf *bp)
|
||||
ChapInput(struct mbuf * bp)
|
||||
{
|
||||
int len = plength(bp);
|
||||
struct fsmheader *chp;
|
||||
|
||||
if (len >= sizeof(struct fsmheader)) {
|
||||
chp = (struct fsmheader *)MBUF_CTOP(bp);
|
||||
chp = (struct fsmheader *) MBUF_CTOP(bp);
|
||||
if (len >= ntohs(chp->length)) {
|
||||
if (chp->code < 1 || chp->code > 4)
|
||||
chp->code = 0;
|
||||
|
@ -18,7 +18,7 @@
|
||||
* Columbus, OH 43221
|
||||
* (614)451-1883
|
||||
*
|
||||
* $Id: chat.c,v 1.30 1997/08/17 20:38:43 brian Exp $
|
||||
* $Id: chat.c,v 1.31 1997/08/17 22:47:07 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Support more UUCP compatible control sequences.
|
||||
@ -54,7 +54,7 @@ static int TimeoutSec;
|
||||
static int abort_next, timeout_next;
|
||||
static int numaborts;
|
||||
char *AbortStrings[50];
|
||||
char inbuff[IBSIZE*2+1];
|
||||
char inbuff[IBSIZE * 2 + 1];
|
||||
|
||||
extern int ChangeParity(char *);
|
||||
|
||||
@ -72,13 +72,13 @@ findblank(char *p, int instring)
|
||||
if (!*p)
|
||||
break;
|
||||
} else if (*p == '"')
|
||||
return(p);
|
||||
return (p);
|
||||
p++;
|
||||
}
|
||||
} else {
|
||||
while (*p) {
|
||||
if (isblank(*p))
|
||||
return(p);
|
||||
return (p);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
@ -100,10 +100,11 @@ MakeArgs(char *script, char **pvect, int maxargs)
|
||||
instring = 1;
|
||||
script++;
|
||||
if (*script == '\0')
|
||||
break; /* Shouldn't return here. Need to null terminate below */
|
||||
break; /* Shouldn't return here. Need to null
|
||||
* terminate below */
|
||||
} else
|
||||
instring = 0;
|
||||
if (nargs >= maxargs-1)
|
||||
if (nargs >= maxargs - 1)
|
||||
break;
|
||||
*pvect++ = script;
|
||||
nargs++;
|
||||
@ -147,19 +148,29 @@ ExpandString(char *str, char *result, int reslen, int sendmode)
|
||||
addcr = 0;
|
||||
break;
|
||||
case 'd': /* Delay 2 seconds */
|
||||
sleep(2); break;
|
||||
sleep(2);
|
||||
break;
|
||||
case 'p':
|
||||
usleep(250000); break; /* Pause 0.25 sec */
|
||||
usleep(250000);
|
||||
break; /* Pause 0.25 sec */
|
||||
case 'n':
|
||||
*result++ = '\n'; reslen--; break;
|
||||
*result++ = '\n';
|
||||
reslen--;
|
||||
break;
|
||||
case 'r':
|
||||
*result++ = '\r'; reslen--; break;
|
||||
*result++ = '\r';
|
||||
reslen--;
|
||||
break;
|
||||
case 's':
|
||||
*result++ = ' '; reslen--; break;
|
||||
*result++ = ' ';
|
||||
reslen--;
|
||||
break;
|
||||
case 't':
|
||||
*result++ = '\t'; reslen--; break;
|
||||
*result++ = '\t';
|
||||
reslen--;
|
||||
break;
|
||||
case 'P':
|
||||
strncpy(result, VarAuthKey, reslen);
|
||||
strncpy(result, VarAuthKey, reslen);
|
||||
reslen -= strlen(result);
|
||||
result += strlen(result);
|
||||
break;
|
||||
@ -186,11 +197,11 @@ ExpandString(char *str, char *result, int reslen, int sendmode)
|
||||
break;
|
||||
default:
|
||||
reslen--;
|
||||
*result++ = *str;
|
||||
*result++ = *str;
|
||||
break;
|
||||
}
|
||||
if (*str)
|
||||
str++;
|
||||
if (*str)
|
||||
str++;
|
||||
break;
|
||||
case '^':
|
||||
str++;
|
||||
@ -211,42 +222,47 @@ ExpandString(char *str, char *result, int reslen, int sendmode)
|
||||
}
|
||||
if (--reslen > 0)
|
||||
*result++ = '\0';
|
||||
return(result);
|
||||
return (result);
|
||||
}
|
||||
|
||||
#define MAXLOGBUFF 200
|
||||
static char logbuff[MAXLOGBUFF];
|
||||
static int loglen = 0;
|
||||
|
||||
static void clear_log()
|
||||
static void
|
||||
clear_log()
|
||||
{
|
||||
memset(logbuff,0,MAXLOGBUFF);
|
||||
memset(logbuff, 0, MAXLOGBUFF);
|
||||
loglen = 0;
|
||||
}
|
||||
|
||||
static void flush_log()
|
||||
static void
|
||||
flush_log()
|
||||
{
|
||||
if (LogIsKept(LogCONNECT))
|
||||
LogPrintf(LogCONNECT,"%s", logbuff);
|
||||
else if (LogIsKept(LogCARRIER) && strstr(logbuff,"CARRIER"))
|
||||
LogPrintf(LogCARRIER,"%s", logbuff);
|
||||
LogPrintf(LogCONNECT, "%s", logbuff);
|
||||
else if (LogIsKept(LogCARRIER) && strstr(logbuff, "CARRIER"))
|
||||
LogPrintf(LogCARRIER, "%s", logbuff);
|
||||
|
||||
clear_log();
|
||||
}
|
||||
|
||||
static void connect_log(char *str, int single_p)
|
||||
static void
|
||||
connect_log(char *str, int single_p)
|
||||
{
|
||||
int space = MAXLOGBUFF - loglen - 1;
|
||||
|
||||
|
||||
while (space--) {
|
||||
if (*str == '\n') {
|
||||
flush_log();
|
||||
} else {
|
||||
logbuff[loglen++] = *str;
|
||||
}
|
||||
if (single_p || !*++str) break;
|
||||
if (single_p || !*++str)
|
||||
break;
|
||||
}
|
||||
if (!space) flush_log();
|
||||
if (!space)
|
||||
flush_log();
|
||||
}
|
||||
|
||||
int
|
||||
@ -262,6 +278,7 @@ WaitforString(char *estr)
|
||||
|
||||
#ifdef SIGALRM
|
||||
int omask;
|
||||
|
||||
omask = sigblock(sigmask(SIGALRM));
|
||||
#endif
|
||||
clear_log();
|
||||
@ -270,19 +287,19 @@ WaitforString(char *estr)
|
||||
str = buff;
|
||||
inp = inbuff;
|
||||
|
||||
if (strlen(str)>=IBSIZE){
|
||||
str[IBSIZE-1]=0;
|
||||
if (strlen(str) >= IBSIZE) {
|
||||
str[IBSIZE - 1] = 0;
|
||||
LogPrintf(LogCHAT, "Truncating String to %d character: %s", IBSIZE, str);
|
||||
}
|
||||
|
||||
nfds = modem + 1;
|
||||
s = str;
|
||||
for (;;) {
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(modem, &rfds);
|
||||
|
||||
/*
|
||||
* Because it is not clear whether select() modifies timeout value,
|
||||
* it is better to initialize timeout values everytime.
|
||||
* Because it is not clear whether select() modifies timeout value, it is
|
||||
* better to initialize timeout values everytime.
|
||||
*/
|
||||
timeout.tv_sec = TimeoutSec;
|
||||
timeout.tv_usec = 0;
|
||||
@ -298,8 +315,8 @@ WaitforString(char *estr)
|
||||
#endif
|
||||
LogPrintf(LogERROR, "select: %s", strerror(errno));
|
||||
*inp = 0;
|
||||
return(NOMATCH);
|
||||
} else if (i == 0) { /* Timeout reached! */
|
||||
return (NOMATCH);
|
||||
} else if (i == 0) { /* Timeout reached! */
|
||||
*inp = 0;
|
||||
if (inp != inbuff)
|
||||
LogPrintf(LogCHAT, "Got: %s", inbuff);
|
||||
@ -307,54 +324,56 @@ WaitforString(char *estr)
|
||||
#ifdef SIGALRM
|
||||
sigsetmask(omask);
|
||||
#endif
|
||||
return(NOMATCH);
|
||||
return (NOMATCH);
|
||||
}
|
||||
if (FD_ISSET(modem, &rfds)) { /* got something */
|
||||
if (DEV_IS_SYNC) {
|
||||
int length;
|
||||
if ((length=strlen(inbuff))>IBSIZE){
|
||||
bcopy(&(inbuff[IBSIZE]),inbuff,IBSIZE+1); /* shuffle down next part*/
|
||||
length=strlen(inbuff);
|
||||
|
||||
if ((length = strlen(inbuff)) > IBSIZE) {
|
||||
bcopy(&(inbuff[IBSIZE]), inbuff, IBSIZE + 1); /* shuffle down next
|
||||
* part */
|
||||
length = strlen(inbuff);
|
||||
}
|
||||
nb = read(modem, &(inbuff[length]), IBSIZE);
|
||||
inbuff[nb + length] = 0;
|
||||
connect_log(inbuff,0);
|
||||
connect_log(inbuff, 0);
|
||||
if (strstr(inbuff, str)) {
|
||||
#ifdef SIGALRM
|
||||
sigsetmask(omask);
|
||||
sigsetmask(omask);
|
||||
#endif
|
||||
flush_log();
|
||||
return(MATCH);
|
||||
return (MATCH);
|
||||
}
|
||||
for (i = 0; i < numaborts; i++) {
|
||||
if (strstr(inbuff, AbortStrings[i])) {
|
||||
LogPrintf(LogCHAT, "Abort: %s", AbortStrings[i]);
|
||||
#ifdef SIGALRM
|
||||
sigsetmask(omask);
|
||||
sigsetmask(omask);
|
||||
#endif
|
||||
flush_log();
|
||||
return(ABORT);
|
||||
return (ABORT);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (read(modem, &ch, 1) < 0) {
|
||||
LogPrintf(LogERROR, "read error: %s", strerror(errno));
|
||||
*inp = '\0';
|
||||
return(NOMATCH);
|
||||
if (read(modem, &ch, 1) < 0) {
|
||||
LogPrintf(LogERROR, "read error: %s", strerror(errno));
|
||||
*inp = '\0';
|
||||
return (NOMATCH);
|
||||
}
|
||||
connect_log(&ch,1);
|
||||
*inp++ = ch;
|
||||
if (ch == *s) {
|
||||
connect_log(&ch, 1);
|
||||
*inp++ = ch;
|
||||
if (ch == *s) {
|
||||
s++;
|
||||
if (*s == '\0') {
|
||||
#ifdef SIGALRM
|
||||
sigsetmask(omask);
|
||||
sigsetmask(omask);
|
||||
#endif
|
||||
*inp = 0;
|
||||
flush_log();
|
||||
return(MATCH);
|
||||
return (MATCH);
|
||||
}
|
||||
} else
|
||||
} else
|
||||
s = str;
|
||||
if (inp == inbuff + IBSIZE) {
|
||||
bcopy(inp - 100, inbuff, 100);
|
||||
@ -371,13 +390,13 @@ WaitforString(char *estr)
|
||||
LogPrintf(LogCHAT, "Abort: %s", s1);
|
||||
*inp = 0;
|
||||
#ifdef SIGALRM
|
||||
sigsetmask(omask);
|
||||
sigsetmask(omask);
|
||||
#endif
|
||||
flush_log();
|
||||
return(ABORT);
|
||||
return (ABORT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -412,7 +431,6 @@ ExecStr(char *command, char *out)
|
||||
LogPrintf(LogCHAT, "Unable to create pipe in ExecStr: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
TermTimerService();
|
||||
@ -478,15 +496,15 @@ SendString(char *str)
|
||||
TimeoutSec = 30;
|
||||
} else {
|
||||
if (*str == '!') {
|
||||
(void) ExpandString(str+1, buff+2, sizeof(buff)-2, 0);
|
||||
(void) ExpandString(str + 1, buff + 2, sizeof(buff) - 2, 0);
|
||||
ExecStr(buff + 2, buff + 2);
|
||||
} else {
|
||||
(void) ExpandString(str, buff+2, sizeof(buff)-2, 1);
|
||||
(void) ExpandString(str, buff + 2, sizeof(buff) - 2, 1);
|
||||
}
|
||||
if (strstr(str, "\\P")) { /* Do not log the password itself. */
|
||||
if (strstr(str, "\\P")) { /* Do not log the password itself. */
|
||||
LogPrintf(LogCHAT, "sending: %s", str);
|
||||
} else {
|
||||
LogPrintf(LogCHAT, "sending: %s", buff+2);
|
||||
LogPrintf(LogCHAT, "sending: %s", buff + 2);
|
||||
}
|
||||
cp = buff;
|
||||
if (DEV_IS_SYNC)
|
||||
@ -506,16 +524,17 @@ ExpectString(char *str)
|
||||
|
||||
if (strcmp(str, "ABORT") == 0) {
|
||||
++abort_next;
|
||||
return(MATCH);
|
||||
return (MATCH);
|
||||
}
|
||||
if (strcmp(str, "TIMEOUT") == 0) {
|
||||
++timeout_next;
|
||||
return(MATCH);
|
||||
return (MATCH);
|
||||
}
|
||||
LogPrintf(LogCHAT, "Expecting %s", str);
|
||||
while (*str) {
|
||||
|
||||
/*
|
||||
* Check whether if string contains sub-send-expect.
|
||||
* Check whether if string contains sub-send-expect.
|
||||
*/
|
||||
for (minus = str; *minus; minus++) {
|
||||
if (*minus == '-') {
|
||||
@ -523,11 +542,12 @@ ExpectString(char *str)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (*minus == '-') { /* We have sub-send-expect. */
|
||||
if (*minus == '-') { /* We have sub-send-expect. */
|
||||
*minus++ = '\0';
|
||||
state = WaitforString(str);
|
||||
if (state != NOMATCH)
|
||||
return(state);
|
||||
return (state);
|
||||
|
||||
/*
|
||||
* Can't get expect string. Sendout send part.
|
||||
*/
|
||||
@ -544,26 +564,27 @@ ExpectString(char *str)
|
||||
str = minus;
|
||||
} else {
|
||||
SendString(str);
|
||||
return(MATCH);
|
||||
return (MATCH);
|
||||
}
|
||||
} else {
|
||||
|
||||
/*
|
||||
* Simple case. Wait for string.
|
||||
* Simple case. Wait for string.
|
||||
*/
|
||||
return(WaitforString(str));
|
||||
return (WaitforString(str));
|
||||
}
|
||||
}
|
||||
return(MATCH);
|
||||
return (MATCH);
|
||||
}
|
||||
|
||||
static jmp_buf ChatEnv;
|
||||
static void (*oint)(int);
|
||||
static void (*oint) (int);
|
||||
|
||||
static void
|
||||
StopDial(int sig)
|
||||
{
|
||||
LogPrintf(LogPHASE, "DoChat: Caught signal %d, abort connect\n", sig);
|
||||
longjmp(ChatEnv,1);
|
||||
longjmp(ChatEnv, 1);
|
||||
}
|
||||
|
||||
int
|
||||
@ -579,7 +600,7 @@ DoChat(char *script)
|
||||
/* While we're chatting, we want an INT to fail us */
|
||||
if (setjmp(ChatEnv)) {
|
||||
signal(SIGINT, oint);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
oint = signal(SIGINT, StopDial);
|
||||
|
||||
@ -613,9 +634,9 @@ DoChat(char *script)
|
||||
#endif
|
||||
case NOMATCH:
|
||||
signal(SIGINT, oint);
|
||||
return(NOMATCH);
|
||||
return (NOMATCH);
|
||||
}
|
||||
}
|
||||
signal(SIGINT, oint);
|
||||
return(MATCH);
|
||||
return (MATCH);
|
||||
}
|
||||
|
@ -18,12 +18,13 @@
|
||||
* Columbus, OH 43221
|
||||
* (614)451-1883
|
||||
*
|
||||
* $Id: chat.h,v 1.5 1997/05/07 23:01:24 brian Exp $
|
||||
* $Id: chat.h,v 1.6 1997/06/09 03:27:16 brian Exp $
|
||||
*
|
||||
*/
|
||||
#ifndef _CHAT_H_
|
||||
#define _CHAT_H_
|
||||
extern char * ExpandString(char *, char *, int, int);
|
||||
extern char *ExpandString(char *, char *, int, int);
|
||||
extern int MakeArgs(char *, char **, int);
|
||||
|
||||
#define VECSIZE(v) (sizeof(v) / sizeof(v[0]))
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id$
|
||||
* $Id: command.h,v 1.4 1997/02/22 16:10:09 peter Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -23,8 +23,8 @@
|
||||
struct cmdtab {
|
||||
char *name;
|
||||
char *alias;
|
||||
int (*func)();
|
||||
u_char lauth;
|
||||
int (*func) ();
|
||||
u_char lauth;
|
||||
char *helpmes;
|
||||
char *syntax;
|
||||
void *args;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: defs.h,v 1.16 1997/06/13 02:07:29 brian Exp $
|
||||
* $Id: defs.h,v 1.17 1997/06/23 23:10:09 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -37,14 +37,14 @@
|
||||
* Check follwiing definitions for your machine envirinment
|
||||
*/
|
||||
#ifdef __FreeBSD__
|
||||
#define MODEM_DEV "/dev/cuaa1" /* name of tty device */
|
||||
#define BASE_MODEM_DEV "cuaa1" /* name of base tty device */
|
||||
#define MODEM_DEV "/dev/cuaa1" /* name of tty device */
|
||||
#define BASE_MODEM_DEV "cuaa1" /* name of base tty device */
|
||||
#else
|
||||
#define MODEM_DEV "/dev/tty01" /* name of tty device */
|
||||
#define BASE_MODEM_DEV "tty01" /* name of base tty device */
|
||||
#define MODEM_DEV "/dev/tty01" /* name of tty device */
|
||||
#define BASE_MODEM_DEV "tty01" /* name of base tty device */
|
||||
#endif
|
||||
#define MODEM_SPEED B38400 /* tty speed */
|
||||
#define SERVER_PORT 3000 /* Base server port no. */
|
||||
#define MODEM_SPEED B38400 /* tty speed */
|
||||
#define SERVER_PORT 3000 /* Base server port no. */
|
||||
|
||||
#define MODEM_CTSRTS TRUE /* Default (true): use CTS/RTS signals */
|
||||
#define RECONNECT_TIMER 3 /* Default timer for carrier loss */
|
||||
@ -99,4 +99,4 @@ char *dstsystem;
|
||||
#define FALSE (0)
|
||||
#endif
|
||||
|
||||
#endif /* _DEFS_H_ */
|
||||
#endif /* _DEFS_H_ */
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: filter.c,v 1.11 1997/06/28 01:34:03 brian Exp $
|
||||
* $Id: filter.c,v 1.12 1997/07/27 23:26:23 brian Exp $
|
||||
*
|
||||
* TODO: Shoud send ICMP error message when we discard packets.
|
||||
*/
|
||||
@ -42,36 +42,35 @@
|
||||
static struct filterent filterdata;
|
||||
|
||||
static u_long netmasks[33] = {
|
||||
0x00000000,
|
||||
0x80000000, 0xC0000000, 0xE0000000, 0xF0000000,
|
||||
0xF8000000, 0xFC000000, 0xFE000000, 0xFF000000,
|
||||
0xFF800000, 0xFFC00000, 0xFFE00000, 0xFFF00000,
|
||||
0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000,
|
||||
0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000,
|
||||
0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00, 0xFFFFFF00,
|
||||
0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0, 0xFFFFFFF0,
|
||||
0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE, 0xFFFFFFFF,
|
||||
0x00000000,
|
||||
0x80000000, 0xC0000000, 0xE0000000, 0xF0000000,
|
||||
0xF8000000, 0xFC000000, 0xFE000000, 0xFF000000,
|
||||
0xFF800000, 0xFFC00000, 0xFFE00000, 0xFFF00000,
|
||||
0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000,
|
||||
0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000,
|
||||
0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00, 0xFFFFFF00,
|
||||
0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0, 0xFFFFFFF0,
|
||||
0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE, 0xFFFFFFFF,
|
||||
};
|
||||
|
||||
int
|
||||
ParseAddr(argc, argv, paddr, pmask, pwidth)
|
||||
int argc;
|
||||
char **argv;
|
||||
struct in_addr *paddr;
|
||||
struct in_addr *pmask;
|
||||
int *pwidth;
|
||||
ParseAddr(int argc,
|
||||
char **argv,
|
||||
struct in_addr * paddr,
|
||||
struct in_addr * pmask,
|
||||
int *pwidth)
|
||||
{
|
||||
int bits;
|
||||
char *cp, *wp;
|
||||
|
||||
if (argc < 1) {
|
||||
LogPrintf(LogWARN, "ParseAddr: address/mask is expected.\n");
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
pmask->s_addr = 0xffffffff; /* Assume 255.255.255.255 as default */
|
||||
cp = index(*argv, '/');
|
||||
if (cp) *cp++ = '\0';
|
||||
if (cp)
|
||||
*cp++ = '\0';
|
||||
if (strcasecmp(*argv, "HISADDR") == 0)
|
||||
*paddr = IpcpInfo.his_ipaddr;
|
||||
else if (strcasecmp(*argv, "MYADDR") == 0)
|
||||
@ -82,7 +81,7 @@ int *pwidth;
|
||||
bits = strtol(cp, &wp, 0);
|
||||
if (cp == wp || bits < 0 || bits > 32) {
|
||||
LogPrintf(LogWARN, "ParseAddr: bad mask width.\n");
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
} else {
|
||||
/* if width is not given, assume whole 32 bits are meaningfull */
|
||||
@ -92,18 +91,16 @@ int *pwidth;
|
||||
*pwidth = bits;
|
||||
pmask->s_addr = htonl(netmasks[bits]);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int
|
||||
ParseProto(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
ParseProto(int argc, char **argv)
|
||||
{
|
||||
int proto;
|
||||
|
||||
if (argc < 1)
|
||||
return(P_NONE);
|
||||
return (P_NONE);
|
||||
|
||||
if (STREQ(*argv, "tcp"))
|
||||
proto = P_TCP;
|
||||
@ -113,13 +110,11 @@ char **argv;
|
||||
proto = P_ICMP;
|
||||
else
|
||||
proto = P_NONE;
|
||||
return(proto);
|
||||
return (proto);
|
||||
}
|
||||
|
||||
static int
|
||||
ParsePort(service, proto)
|
||||
char *service;
|
||||
int proto;
|
||||
ParsePort(char *service, int proto)
|
||||
{
|
||||
char *protocol_name, *cp;
|
||||
struct servent *servent;
|
||||
@ -136,26 +131,24 @@ int proto;
|
||||
protocol_name = 0;
|
||||
}
|
||||
|
||||
servent = getservbyname (service, protocol_name);
|
||||
servent = getservbyname(service, protocol_name);
|
||||
if (servent != 0)
|
||||
return(ntohs(servent->s_port));
|
||||
return (ntohs(servent->s_port));
|
||||
|
||||
port = strtol(service, &cp, 0);
|
||||
if (cp == service) {
|
||||
LogPrintf(LogWARN, "ParsePort: %s is not a port name or number.\n",
|
||||
service);
|
||||
return(0);
|
||||
service);
|
||||
return (0);
|
||||
}
|
||||
return(port);
|
||||
return (port);
|
||||
}
|
||||
|
||||
/*
|
||||
* ICMP Syntax: src eq icmp_message_type
|
||||
*/
|
||||
static int
|
||||
ParseIcmp(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
ParseIcmp(int argc, char **argv)
|
||||
{
|
||||
int type;
|
||||
char *cp;
|
||||
@ -167,25 +160,24 @@ char **argv;
|
||||
break;
|
||||
default:
|
||||
LogPrintf(LogWARN, "ParseIcmp: bad icmp syntax.\n");
|
||||
return(0);
|
||||
return (0);
|
||||
case 3:
|
||||
if (STREQ(*argv, "src") && STREQ(argv[1], "eq")) {
|
||||
type = strtol(argv[2], &cp, 0);
|
||||
if (cp == argv[2]) {
|
||||
LogPrintf(LogWARN, "ParseIcmp: type is expected.\n");
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
filterdata.opt.srcop = OP_EQ;
|
||||
filterdata.opt.srcport = type;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int
|
||||
ParseOp(cp)
|
||||
char *cp;
|
||||
ParseOp(char *cp)
|
||||
{
|
||||
int op = OP_NONE;
|
||||
|
||||
@ -195,74 +187,69 @@ char *cp;
|
||||
op = OP_GT;
|
||||
else if (STREQ(cp, "lt"))
|
||||
op = OP_LT;
|
||||
return(op);
|
||||
return (op);
|
||||
}
|
||||
|
||||
/*
|
||||
* UDP Syntax: [src op port] [dst op port]
|
||||
*/
|
||||
static int
|
||||
ParseUdpOrTcp(argc, argv, proto)
|
||||
int argc;
|
||||
char **argv;
|
||||
int proto;
|
||||
ParseUdpOrTcp(int argc, char **argv, int proto)
|
||||
{
|
||||
|
||||
if (argc == 0) {
|
||||
/* permit/deny all tcp traffic */
|
||||
filterdata.opt.srcop = filterdata.opt.dstop = A_NONE;
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
if (argc < 3) {
|
||||
LogPrintf(LogWARN, "ParseUdpOrTcp: bad udp/tcp syntax.\n");
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
if (argc >= 3 && STREQ(*argv, "src")) {
|
||||
filterdata.opt.srcop = ParseOp(argv[1]);
|
||||
if (filterdata.opt.srcop == OP_NONE) {
|
||||
LogPrintf(LogWARN, "ParseUdpOrTcp: bad operation\n");
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
filterdata.opt.srcport = ParsePort(argv[2], proto);
|
||||
if (filterdata.opt.srcport == 0)
|
||||
return(0);
|
||||
argc -= 3; argv += 3;
|
||||
return (0);
|
||||
argc -= 3;
|
||||
argv += 3;
|
||||
if (argc == 0)
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
if (argc >= 3 && STREQ(argv[0], "dst")) {
|
||||
filterdata.opt.dstop = ParseOp(argv[1]);
|
||||
if (filterdata.opt.dstop == OP_NONE) {
|
||||
LogPrintf(LogWARN, "ParseUdpOrTcp: bad operation\n");
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
filterdata.opt.dstport = ParsePort(argv[2], proto);
|
||||
if (filterdata.opt.dstport == 0)
|
||||
return(0);
|
||||
argc -= 3; argv += 3;
|
||||
return (0);
|
||||
argc -= 3;
|
||||
argv += 3;
|
||||
if (argc == 0)
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
if (argc == 1) {
|
||||
if (STREQ(*argv, "estab")) {
|
||||
filterdata.opt.estab = 1;
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
LogPrintf(LogWARN, "ParseUdpOrTcp: estab is expected: %s\n", *argv);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
if (argc > 0)
|
||||
LogPrintf(LogWARN, "ParseUdpOrTcp: bad src/dst port syntax: %s\n", *argv);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *opname[] = { "none", "eq", "gt", "lt" };
|
||||
char *opname[] = {"none", "eq", "gt", "lt"};
|
||||
|
||||
static int
|
||||
Parse(argc, argv, ofp)
|
||||
int argc;
|
||||
char **argv;
|
||||
struct filterent *ofp;
|
||||
Parse(int argc, char **argv, struct filterent * ofp)
|
||||
{
|
||||
int action, proto;
|
||||
int val;
|
||||
@ -272,7 +259,7 @@ struct filterent *ofp;
|
||||
val = strtol(*argv, &wp, 0);
|
||||
if (*argv == wp || val > MAXFILTERS) {
|
||||
LogPrintf(LogWARN, "Parse: invalid filter number.\n");
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
if (val < 0) {
|
||||
for (val = 0; val < MAXFILTERS; val++) {
|
||||
@ -280,13 +267,13 @@ struct filterent *ofp;
|
||||
ofp++;
|
||||
}
|
||||
LogPrintf(LogWARN, "Parse: filter cleared.\n");
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
ofp += val;
|
||||
|
||||
if (--argc == 0) {
|
||||
LogPrintf(LogWARN, "Parse: missing action.\n");
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
argv++;
|
||||
|
||||
@ -299,47 +286,54 @@ struct filterent *ofp;
|
||||
action = A_DENY;
|
||||
} else if (STREQ(*argv, "clear")) {
|
||||
ofp->action = A_NONE;
|
||||
return(1);
|
||||
return (1);
|
||||
} else {
|
||||
LogPrintf(LogWARN, "Parse: bad action: %s\n", *argv);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
fp->action = action;
|
||||
|
||||
argc--; argv++;
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (fp->action == A_DENY) {
|
||||
if (STREQ(*argv, "host")) {
|
||||
fp->action |= A_UHOST;
|
||||
argc--; argv++;
|
||||
argc--;
|
||||
argv++;
|
||||
} else if (STREQ(*argv, "port")) {
|
||||
fp->action |= A_UPORT;
|
||||
argc--; argv++;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
}
|
||||
|
||||
proto = ParseProto(argc, argv);
|
||||
if (proto == P_NONE) {
|
||||
if (ParseAddr(argc, argv, &fp->saddr, &fp->smask, &fp->swidth)) {
|
||||
argc--; argv++;
|
||||
argc--;
|
||||
argv++;
|
||||
proto = ParseProto(argc, argv);
|
||||
if (proto == P_NONE) {
|
||||
if (ParseAddr(argc, argv, &fp->daddr, &fp->dmask, &fp->dwidth)) {
|
||||
argc--; argv++;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
proto = ParseProto(argc, argv);
|
||||
if (proto) {
|
||||
argc--; argv++;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
} else {
|
||||
argc--; argv++;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
} else {
|
||||
LogPrintf(LogWARN, "Parse: Address/protocol expected.\n");
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
} else {
|
||||
argc--; argv++;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
val = 1;
|
||||
@ -371,62 +365,46 @@ struct filterent *ofp;
|
||||
|
||||
if (val)
|
||||
*ofp = *fp;
|
||||
return(val);
|
||||
return (val);
|
||||
}
|
||||
|
||||
int
|
||||
SetIfilter(list, argc, argv)
|
||||
struct cmdtab *list;
|
||||
int argc;
|
||||
char **argv;
|
||||
SetIfilter(struct cmdtab * list, int argc, char **argv)
|
||||
{
|
||||
if (argc > 0) {
|
||||
(void) Parse(argc, argv, ifilters);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
SetOfilter(list, argc, argv)
|
||||
struct cmdtab *list;
|
||||
int argc;
|
||||
char **argv;
|
||||
SetOfilter(struct cmdtab * list, int argc, char **argv)
|
||||
{
|
||||
if (argc > 0) {
|
||||
(void) Parse(argc, argv, ofilters);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
SetDfilter(list, argc, argv)
|
||||
struct cmdtab *list;
|
||||
int argc;
|
||||
char **argv;
|
||||
SetDfilter(struct cmdtab * list, int argc, char **argv)
|
||||
{
|
||||
if (argc > 0) {
|
||||
(void) Parse(argc, argv, dfilters);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
SetAfilter(list, argc, argv)
|
||||
struct cmdtab *list;
|
||||
int argc;
|
||||
char **argv;
|
||||
SetAfilter(struct cmdtab * list, int argc, char **argv)
|
||||
{
|
||||
if (argc > 0) {
|
||||
(void) Parse(argc, argv, afilters);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -439,8 +417,7 @@ static char *actname[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
ShowFilter(fp)
|
||||
struct filterent *fp;
|
||||
ShowFilter(struct filterent * fp)
|
||||
{
|
||||
int n;
|
||||
|
||||
@ -457,10 +434,10 @@ struct filterent *fp;
|
||||
|
||||
if (fp->opt.srcop)
|
||||
fprintf(VarTerm, " src %s %d", opname[fp->opt.srcop],
|
||||
fp->opt.srcport);
|
||||
fp->opt.srcport);
|
||||
if (fp->opt.dstop)
|
||||
fprintf(VarTerm, " dst %s %d", opname[fp->opt.dstop],
|
||||
fp->opt.dstport);
|
||||
fp->opt.dstport);
|
||||
if (fp->opt.estab)
|
||||
fprintf(VarTerm, " estab");
|
||||
|
||||
@ -471,40 +448,28 @@ struct filterent *fp;
|
||||
}
|
||||
|
||||
int
|
||||
ShowIfilter(list, argc, argv)
|
||||
struct cmdtab *list;
|
||||
int argc;
|
||||
char **argv;
|
||||
ShowIfilter(struct cmdtab * list, int argc, char **argv)
|
||||
{
|
||||
ShowFilter(ifilters);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ShowOfilter(list, argc, argv)
|
||||
struct cmdtab *list;
|
||||
int argc;
|
||||
char **argv;
|
||||
ShowOfilter(struct cmdtab * list, int argc, char **argv)
|
||||
{
|
||||
ShowFilter(ofilters);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ShowDfilter(list, argc, argv)
|
||||
struct cmdtab *list;
|
||||
int argc;
|
||||
char **argv;
|
||||
ShowDfilter(struct cmdtab * list, int argc, char **argv)
|
||||
{
|
||||
ShowFilter(dfilters);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ShowAfilter(list, argc, argv)
|
||||
struct cmdtab *list;
|
||||
int argc;
|
||||
char **argv;
|
||||
ShowAfilter(struct cmdtab * list, int argc, char **argv)
|
||||
{
|
||||
ShowFilter(afilters);
|
||||
return 0;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: filter.h,v 1.7 1997/05/10 01:22:09 brian Exp $
|
||||
* $Id: filter.h,v 1.8 1997/06/09 03:27:20 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -51,21 +51,21 @@
|
||||
#define OP_LT 4
|
||||
|
||||
struct filterent {
|
||||
int action; /* Filtering action */
|
||||
int swidth; /* Effective source address width */
|
||||
int action; /* Filtering action */
|
||||
int swidth; /* Effective source address width */
|
||||
struct in_addr saddr; /* Source address */
|
||||
struct in_addr smask; /* Source address mask */
|
||||
int dwidth; /* Effective destination address width */
|
||||
int dwidth; /* Effective destination address width */
|
||||
struct in_addr daddr; /* Destination address */
|
||||
struct in_addr dmask; /* Destination address mask */
|
||||
int proto; /* Protocol */
|
||||
int proto; /* Protocol */
|
||||
struct {
|
||||
short srcop;
|
||||
short srcop;
|
||||
u_short srcport;
|
||||
short dstop;
|
||||
short dstop;
|
||||
u_short dstport;
|
||||
int estab;
|
||||
} opt;
|
||||
int estab;
|
||||
} opt;
|
||||
};
|
||||
|
||||
#define MAXFILTERS 20
|
||||
@ -79,5 +79,6 @@ struct filterent ofilters[MAXFILTERS];
|
||||
struct filterent dfilters[MAXFILTERS];
|
||||
struct filterent afilters[MAXFILTERS]; /* keep Alive packet filter */
|
||||
|
||||
extern int ParseAddr(int, char **, struct in_addr *, struct in_addr *, int*);
|
||||
#endif /* _FILTER_H_ */
|
||||
extern int ParseAddr(int, char **, struct in_addr *, struct in_addr *, int *);
|
||||
|
||||
#endif /* _FILTER_H_ */
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: fsm.c,v 1.14 1997/08/17 20:45:46 brian Exp $
|
||||
* $Id: fsm.c,v 1.15 1997/08/20 23:47:42 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Refer loglevel for log output
|
||||
@ -33,10 +33,10 @@
|
||||
#include "loadalias.h"
|
||||
#include "vars.h"
|
||||
|
||||
void FsmSendConfigReq(struct fsm *fp);
|
||||
void FsmSendTerminateReq(struct fsm *fp);
|
||||
void FsmInitRestartCounter(struct fsm *fp);
|
||||
void FsmTimeout(struct fsm *fp);
|
||||
void FsmSendConfigReq(struct fsm * fp);
|
||||
void FsmSendTerminateReq(struct fsm * fp);
|
||||
void FsmInitRestartCounter(struct fsm * fp);
|
||||
void FsmTimeout(struct fsm * fp);
|
||||
|
||||
char const *StateNames[] = {
|
||||
"Initial", "Starting", "Closed", "Stopped", "Closing", "Stopping",
|
||||
@ -44,8 +44,7 @@ char const *StateNames[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
StoppedTimeout(fp)
|
||||
struct fsm *fp;
|
||||
StoppedTimeout(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "Stopped timer expired\n");
|
||||
if (modem != -1)
|
||||
@ -55,8 +54,7 @@ struct fsm *fp;
|
||||
}
|
||||
|
||||
void
|
||||
FsmInit(fp)
|
||||
struct fsm *fp;
|
||||
FsmInit(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogDEBUG, "FsmInit\n");
|
||||
fp->state = ST_INITIAL;
|
||||
@ -66,38 +64,32 @@ struct fsm *fp;
|
||||
}
|
||||
|
||||
void
|
||||
NewState(fp, new)
|
||||
struct fsm *fp;
|
||||
int new;
|
||||
NewState(struct fsm * fp, int new)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "State change %s --> %s\n",
|
||||
StateNames[fp->state], StateNames[new]);
|
||||
StateNames[fp->state], StateNames[new]);
|
||||
if (fp->state == ST_STOPPED && fp->StoppedTimer.state == TIMER_RUNNING)
|
||||
StopTimer(&fp->StoppedTimer);
|
||||
StopTimer(&fp->StoppedTimer);
|
||||
fp->state = new;
|
||||
if ((new >= ST_INITIAL && new <= ST_STOPPED) || (new == ST_OPENED)) {
|
||||
StopTimer(&fp->FsmTimer);
|
||||
if (new == ST_STOPPED && fp->StoppedTimer.load) {
|
||||
fp->StoppedTimer.state = TIMER_STOPPED;
|
||||
fp->StoppedTimer.func = StoppedTimeout;
|
||||
fp->StoppedTimer.arg = (void *)fp;
|
||||
fp->StoppedTimer.arg = (void *) fp;
|
||||
StartTimer(&fp->StoppedTimer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FsmOutput(fp, code, id, ptr, count)
|
||||
struct fsm *fp;
|
||||
u_int code, id;
|
||||
u_char *ptr;
|
||||
int count;
|
||||
FsmOutput(struct fsm * fp, u_int code, u_int id, u_char * ptr, int count)
|
||||
{
|
||||
int plen;
|
||||
struct fsmheader lh;
|
||||
struct mbuf *bp;
|
||||
|
||||
plen = sizeof(struct fsmheader) + count;
|
||||
plen = sizeof(struct fsmheader) + count;
|
||||
lh.code = code;
|
||||
lh.id = id;
|
||||
lh.length = htons(plen);
|
||||
@ -110,12 +102,11 @@ int count;
|
||||
}
|
||||
|
||||
void
|
||||
FsmOpen(fp)
|
||||
struct fsm *fp;
|
||||
FsmOpen(struct fsm * fp)
|
||||
{
|
||||
switch (fp->state) {
|
||||
case ST_INITIAL:
|
||||
(fp->LayerStart)(fp);
|
||||
case ST_INITIAL:
|
||||
(fp->LayerStart) (fp);
|
||||
NewState(fp, ST_STARTING);
|
||||
break;
|
||||
case ST_STARTING:
|
||||
@ -129,25 +120,24 @@ struct fsm *fp;
|
||||
NewState(fp, ST_REQSENT);
|
||||
}
|
||||
break;
|
||||
case ST_STOPPED: /* XXX: restart option */
|
||||
case ST_STOPPED: /* XXX: restart option */
|
||||
case ST_REQSENT:
|
||||
case ST_ACKRCVD:
|
||||
case ST_ACKSENT:
|
||||
case ST_OPENED: /* XXX: restart option */
|
||||
case ST_OPENED: /* XXX: restart option */
|
||||
break;
|
||||
case ST_CLOSING: /* XXX: restart option */
|
||||
case ST_STOPPING: /* XXX: restart option */
|
||||
case ST_CLOSING: /* XXX: restart option */
|
||||
case ST_STOPPING: /* XXX: restart option */
|
||||
NewState(fp, ST_STOPPING);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FsmUp(fp)
|
||||
struct fsm *fp;
|
||||
FsmUp(struct fsm * fp)
|
||||
{
|
||||
switch (fp->state) {
|
||||
case ST_INITIAL:
|
||||
case ST_INITIAL:
|
||||
NewState(fp, ST_CLOSED);
|
||||
break;
|
||||
case ST_STARTING:
|
||||
@ -162,16 +152,15 @@ struct fsm *fp;
|
||||
}
|
||||
|
||||
void
|
||||
FsmDown(fp)
|
||||
struct fsm *fp;
|
||||
FsmDown(struct fsm * fp)
|
||||
{
|
||||
switch (fp->state) {
|
||||
case ST_CLOSED:
|
||||
case ST_CLOSING:
|
||||
case ST_CLOSED:
|
||||
case ST_CLOSING:
|
||||
NewState(fp, ST_INITIAL);
|
||||
break;
|
||||
case ST_STOPPED:
|
||||
(fp->LayerStart)(fp);
|
||||
(fp->LayerStart) (fp);
|
||||
/* Fall into.. */
|
||||
case ST_STOPPING:
|
||||
case ST_REQSENT:
|
||||
@ -180,18 +169,17 @@ struct fsm *fp;
|
||||
NewState(fp, ST_STARTING);
|
||||
break;
|
||||
case ST_OPENED:
|
||||
(fp->LayerDown)(fp);
|
||||
(fp->LayerDown) (fp);
|
||||
NewState(fp, ST_STARTING);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FsmClose(fp)
|
||||
struct fsm *fp;
|
||||
FsmClose(struct fsm * fp)
|
||||
{
|
||||
switch (fp->state) {
|
||||
case ST_STARTING:
|
||||
case ST_STARTING:
|
||||
NewState(fp, ST_INITIAL);
|
||||
break;
|
||||
case ST_STOPPED:
|
||||
@ -201,7 +189,7 @@ struct fsm *fp;
|
||||
NewState(fp, ST_CLOSING);
|
||||
break;
|
||||
case ST_OPENED:
|
||||
(fp->LayerDown)(fp);
|
||||
(fp->LayerDown) (fp);
|
||||
/* Fall down */
|
||||
case ST_REQSENT:
|
||||
case ST_ACKRCVD:
|
||||
@ -217,11 +205,10 @@ struct fsm *fp;
|
||||
* Send functions
|
||||
*/
|
||||
void
|
||||
FsmSendConfigReq(fp)
|
||||
struct fsm *fp;
|
||||
FsmSendConfigReq(struct fsm * fp)
|
||||
{
|
||||
if (--fp->maxconfig > 0) {
|
||||
(fp->SendConfigReq)(fp);
|
||||
(fp->SendConfigReq) (fp);
|
||||
StartTimer(&fp->FsmTimer); /* Start restart timer */
|
||||
fp->restart--; /* Decrement restart counter */
|
||||
} else {
|
||||
@ -230,49 +217,45 @@ struct fsm *fp;
|
||||
}
|
||||
|
||||
void
|
||||
FsmSendTerminateReq(fp)
|
||||
struct fsm *fp;
|
||||
FsmSendTerminateReq(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "SendTerminateReq.\n");
|
||||
FsmOutput(fp, CODE_TERMREQ, fp->reqid++, NULL, 0);
|
||||
(fp->SendTerminateReq)(fp);
|
||||
(fp->SendTerminateReq) (fp);
|
||||
StartTimer(&fp->FsmTimer); /* Start restart timer */
|
||||
fp->restart--; /* Decrement restart counter */
|
||||
}
|
||||
|
||||
static void
|
||||
FsmSendConfigAck(fp, lhp, option, count)
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
u_char *option;
|
||||
int count;
|
||||
FsmSendConfigAck(struct fsm * fp,
|
||||
struct fsmheader * lhp,
|
||||
u_char * option,
|
||||
int count)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "SendConfigAck(%s)\n", StateNames[fp->state]);
|
||||
(fp->DecodeConfig)(option, count, MODE_NOP);
|
||||
(fp->DecodeConfig) (option, count, MODE_NOP);
|
||||
FsmOutput(fp, CODE_CONFIGACK, lhp->id, option, count);
|
||||
}
|
||||
|
||||
static void
|
||||
FsmSendConfigRej(fp, lhp, option, count)
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
u_char *option;
|
||||
int count;
|
||||
FsmSendConfigRej(struct fsm * fp,
|
||||
struct fsmheader * lhp,
|
||||
u_char * option,
|
||||
int count)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "SendConfigRej(%s)\n", StateNames[fp->state]);
|
||||
(fp->DecodeConfig)(option, count, MODE_NOP);
|
||||
(fp->DecodeConfig) (option, count, MODE_NOP);
|
||||
FsmOutput(fp, CODE_CONFIGREJ, lhp->id, option, count);
|
||||
}
|
||||
|
||||
static void
|
||||
FsmSendConfigNak(fp, lhp, option, count)
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
u_char *option;
|
||||
int count;
|
||||
FsmSendConfigNak(struct fsm * fp,
|
||||
struct fsmheader * lhp,
|
||||
u_char * option,
|
||||
int count)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "SendConfigNak(%s)\n", StateNames[fp->state]);
|
||||
(fp->DecodeConfig)(option, count, MODE_NOP);
|
||||
(fp->DecodeConfig) (option, count, MODE_NOP);
|
||||
FsmOutput(fp, CODE_CONFIGNAK, lhp->id, option, count);
|
||||
}
|
||||
|
||||
@ -280,13 +263,12 @@ int count;
|
||||
* Timeout actions
|
||||
*/
|
||||
void
|
||||
FsmTimeout(fp)
|
||||
struct fsm *fp;
|
||||
FsmTimeout(struct fsm * fp)
|
||||
{
|
||||
if (fp->restart) {
|
||||
switch (fp->state) {
|
||||
case ST_CLOSING:
|
||||
case ST_STOPPING:
|
||||
case ST_CLOSING:
|
||||
case ST_STOPPING:
|
||||
FsmSendTerminateReq(fp);
|
||||
break;
|
||||
case ST_REQSENT:
|
||||
@ -303,41 +285,38 @@ struct fsm *fp;
|
||||
switch (fp->state) {
|
||||
case ST_CLOSING:
|
||||
NewState(fp, ST_CLOSED);
|
||||
(fp->LayerFinish)(fp);
|
||||
(fp->LayerFinish) (fp);
|
||||
break;
|
||||
case ST_STOPPING:
|
||||
NewState(fp, ST_STOPPED);
|
||||
(fp->LayerFinish)(fp);
|
||||
(fp->LayerFinish) (fp);
|
||||
break;
|
||||
case ST_REQSENT: /* XXX: 3p */
|
||||
case ST_ACKSENT:
|
||||
case ST_ACKRCVD:
|
||||
NewState(fp, ST_STOPPED);
|
||||
(fp->LayerFinish)(fp);
|
||||
(fp->LayerFinish) (fp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FsmInitRestartCounter(fp)
|
||||
struct fsm *fp;
|
||||
FsmInitRestartCounter(struct fsm * fp)
|
||||
{
|
||||
StopTimer(&fp->FsmTimer);
|
||||
fp->FsmTimer.state = TIMER_STOPPED;
|
||||
fp->FsmTimer.func = FsmTimeout;
|
||||
fp->FsmTimer.arg = (void *)fp;
|
||||
(fp->InitRestartCounter)(fp);
|
||||
fp->FsmTimer.arg = (void *) fp;
|
||||
(fp->InitRestartCounter) (fp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Actions when receive packets
|
||||
*/
|
||||
void
|
||||
FsmRecvConfigReq(fp, lhp, bp) /* RCR */
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvConfigReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
/* RCR */
|
||||
{
|
||||
int plen, flen;
|
||||
int ackaction = 0;
|
||||
@ -350,9 +329,8 @@ struct mbuf *bp;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check and process easy case
|
||||
* Check and process easy case
|
||||
*/
|
||||
switch (fp->state) {
|
||||
case ST_INITIAL:
|
||||
@ -361,7 +339,7 @@ struct mbuf *bp;
|
||||
pfree(bp);
|
||||
return;
|
||||
case ST_CLOSED:
|
||||
(fp->SendTerminateAck)(fp);
|
||||
(fp->SendTerminateAck) (fp);
|
||||
pfree(bp);
|
||||
return;
|
||||
case ST_CLOSING:
|
||||
@ -371,14 +349,14 @@ struct mbuf *bp;
|
||||
return;
|
||||
}
|
||||
|
||||
(fp->DecodeConfig)(MBUF_CTOP(bp), flen, MODE_REQ);
|
||||
(fp->DecodeConfig) (MBUF_CTOP(bp), flen, MODE_REQ);
|
||||
|
||||
if (nakp == NakBuff && rejp == RejBuff)
|
||||
ackaction = 1;
|
||||
|
||||
switch (fp->state) {
|
||||
case ST_OPENED:
|
||||
(fp->LayerDown)(fp);
|
||||
(fp->LayerDown) (fp);
|
||||
FsmSendConfigReq(fp);
|
||||
break;
|
||||
case ST_STOPPED:
|
||||
@ -409,7 +387,7 @@ struct mbuf *bp;
|
||||
case ST_ACKRCVD:
|
||||
if (ackaction) {
|
||||
NewState(fp, ST_OPENED);
|
||||
(fp->LayerUp)(fp);
|
||||
(fp->LayerUp) (fp);
|
||||
}
|
||||
break;
|
||||
case ST_ACKSENT:
|
||||
@ -421,15 +399,13 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvConfigAck(fp, lhp, bp) /* RCA */
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvConfigAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
/* RCA */
|
||||
{
|
||||
switch (fp->state) {
|
||||
case ST_CLOSED:
|
||||
case ST_STOPPED:
|
||||
(fp->SendTerminateAck)(fp);
|
||||
case ST_CLOSED:
|
||||
case ST_STOPPED:
|
||||
(fp->SendTerminateAck) (fp);
|
||||
break;
|
||||
case ST_CLOSING:
|
||||
case ST_STOPPING:
|
||||
@ -445,10 +421,10 @@ struct mbuf *bp;
|
||||
case ST_ACKSENT:
|
||||
FsmInitRestartCounter(fp);
|
||||
NewState(fp, ST_OPENED);
|
||||
(fp->LayerUp)(fp);
|
||||
(fp->LayerUp) (fp);
|
||||
break;
|
||||
case ST_OPENED:
|
||||
(fp->LayerDown)(fp);
|
||||
(fp->LayerDown) (fp);
|
||||
FsmSendConfigReq(fp);
|
||||
NewState(fp, ST_REQSENT);
|
||||
break;
|
||||
@ -457,10 +433,8 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvConfigNak(fp, lhp, bp) /* RCN */
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvConfigNak(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
/* RCN */
|
||||
{
|
||||
int plen, flen;
|
||||
|
||||
@ -472,7 +446,7 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check and process easy case
|
||||
* Check and process easy case
|
||||
*/
|
||||
switch (fp->state) {
|
||||
case ST_INITIAL:
|
||||
@ -482,7 +456,7 @@ struct mbuf *bp;
|
||||
return;
|
||||
case ST_CLOSED:
|
||||
case ST_STOPPED:
|
||||
(fp->SendTerminateAck)(fp);
|
||||
(fp->SendTerminateAck) (fp);
|
||||
pfree(bp);
|
||||
return;
|
||||
case ST_CLOSING:
|
||||
@ -491,7 +465,7 @@ struct mbuf *bp;
|
||||
return;
|
||||
}
|
||||
|
||||
(fp->DecodeConfig)(MBUF_CTOP(bp), flen, MODE_NAK);
|
||||
(fp->DecodeConfig) (MBUF_CTOP(bp), flen, MODE_NAK);
|
||||
|
||||
switch (fp->state) {
|
||||
case ST_REQSENT:
|
||||
@ -500,7 +474,7 @@ struct mbuf *bp;
|
||||
FsmSendConfigReq(fp);
|
||||
break;
|
||||
case ST_OPENED:
|
||||
(fp->LayerDown)(fp);
|
||||
(fp->LayerDown) (fp);
|
||||
/* Fall down */
|
||||
case ST_ACKRCVD:
|
||||
FsmSendConfigReq(fp);
|
||||
@ -512,14 +486,12 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvTermReq(fp, lhp, bp) /* RTR */
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvTermReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
/* RTR */
|
||||
{
|
||||
switch (fp->state) {
|
||||
case ST_INITIAL:
|
||||
case ST_STARTING:
|
||||
case ST_INITIAL:
|
||||
case ST_STARTING:
|
||||
LogPrintf(fp->LogLevel, "Oops, RTR in %s\n", StateNames[fp->state]);
|
||||
break;
|
||||
case ST_CLOSED:
|
||||
@ -527,16 +499,16 @@ struct mbuf *bp;
|
||||
case ST_CLOSING:
|
||||
case ST_STOPPING:
|
||||
case ST_REQSENT:
|
||||
(fp->SendTerminateAck)(fp);
|
||||
(fp->SendTerminateAck) (fp);
|
||||
break;
|
||||
case ST_ACKRCVD:
|
||||
case ST_ACKSENT:
|
||||
(fp->SendTerminateAck)(fp);
|
||||
(fp->SendTerminateAck) (fp);
|
||||
NewState(fp, ST_REQSENT);
|
||||
break;
|
||||
case ST_OPENED:
|
||||
(fp->LayerDown)(fp);
|
||||
(fp->SendTerminateAck)(fp);
|
||||
(fp->LayerDown) (fp);
|
||||
(fp->SendTerminateAck) (fp);
|
||||
StartTimer(&fp->FsmTimer); /* Start restart timer */
|
||||
fp->restart = 0;
|
||||
NewState(fp, ST_STOPPING);
|
||||
@ -546,25 +518,23 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvTermAck(fp, lhp, bp) /* RTA */
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvTermAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
/* RTA */
|
||||
{
|
||||
switch (fp->state) {
|
||||
case ST_CLOSING:
|
||||
case ST_CLOSING:
|
||||
NewState(fp, ST_CLOSED);
|
||||
(fp->LayerFinish)(fp);
|
||||
(fp->LayerFinish) (fp);
|
||||
break;
|
||||
case ST_STOPPING:
|
||||
NewState(fp, ST_STOPPED);
|
||||
(fp->LayerFinish)(fp);
|
||||
(fp->LayerFinish) (fp);
|
||||
break;
|
||||
case ST_ACKRCVD:
|
||||
NewState(fp, ST_REQSENT);
|
||||
break;
|
||||
case ST_OPENED:
|
||||
(fp->LayerDown)(fp);
|
||||
(fp->LayerDown) (fp);
|
||||
FsmSendConfigReq(fp);
|
||||
NewState(fp, ST_REQSENT);
|
||||
break;
|
||||
@ -573,10 +543,8 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvConfigRej(fp, lhp, bp) /* RCJ */
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvConfigRej(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
/* RCJ */
|
||||
{
|
||||
int plen, flen;
|
||||
|
||||
@ -589,7 +557,7 @@ struct mbuf *bp;
|
||||
LogPrintf(fp->LogLevel, "RecvConfigRej.\n");
|
||||
|
||||
/*
|
||||
* Check and process easy case
|
||||
* Check and process easy case
|
||||
*/
|
||||
switch (fp->state) {
|
||||
case ST_INITIAL:
|
||||
@ -599,7 +567,7 @@ struct mbuf *bp;
|
||||
return;
|
||||
case ST_CLOSED:
|
||||
case ST_STOPPED:
|
||||
(fp->SendTerminateAck)(fp);
|
||||
(fp->SendTerminateAck) (fp);
|
||||
pfree(bp);
|
||||
return;
|
||||
case ST_CLOSING:
|
||||
@ -608,7 +576,7 @@ struct mbuf *bp;
|
||||
return;
|
||||
}
|
||||
|
||||
(fp->DecodeConfig)(MBUF_CTOP(bp), flen, MODE_REJ);
|
||||
(fp->DecodeConfig) (MBUF_CTOP(bp), flen, MODE_REJ);
|
||||
|
||||
switch (fp->state) {
|
||||
case ST_REQSENT:
|
||||
@ -617,7 +585,7 @@ struct mbuf *bp;
|
||||
FsmSendConfigReq(fp);
|
||||
break;
|
||||
case ST_OPENED:
|
||||
(fp->LayerDown)(fp);
|
||||
(fp->LayerDown) (fp);
|
||||
/* Fall down */
|
||||
case ST_ACKRCVD:
|
||||
FsmSendConfigReq(fp);
|
||||
@ -628,24 +596,18 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvCodeRej(fp, lhp, bp)
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvCodeRej(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "RecvCodeRej\n");
|
||||
pfree(bp);
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvProtoRej(fp, lhp, bp)
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvProtoRej(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
{
|
||||
u_short *sp, proto;
|
||||
|
||||
sp = (u_short *)MBUF_CTOP(bp);
|
||||
sp = (u_short *) MBUF_CTOP(bp);
|
||||
proto = ntohs(*sp);
|
||||
LogPrintf(fp->LogLevel, "-- Protocol (%04x) was rejected.\n", proto);
|
||||
|
||||
@ -655,7 +617,7 @@ struct mbuf *bp;
|
||||
break;
|
||||
case PROTO_CCP:
|
||||
fp = &CcpFsm;
|
||||
(fp->LayerFinish)(fp);
|
||||
(fp->LayerFinish) (fp);
|
||||
switch (fp->state) {
|
||||
case ST_CLOSED:
|
||||
case ST_CLOSING:
|
||||
@ -670,22 +632,18 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvEchoReq(fp, lhp, bp)
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvEchoReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
{
|
||||
u_char *cp;
|
||||
u_long *lp, magic;
|
||||
|
||||
cp = MBUF_CTOP(bp);
|
||||
lp = (u_long *)cp;
|
||||
lp = (u_long *) cp;
|
||||
magic = ntohl(*lp);
|
||||
if (magic != LcpInfo.his_magic) {
|
||||
LogPrintf(LogERROR, "RecvEchoReq: his magic is bad!!\n");
|
||||
/* XXX: We should send terminate request */
|
||||
}
|
||||
|
||||
if (fp->state == ST_OPENED) {
|
||||
*lp = htonl(LcpInfo.want_magic); /* Insert local magic number */
|
||||
LogPrintf(fp->LogLevel, "SendEchoRep(%s)\n", StateNames[fp->state]);
|
||||
@ -695,24 +653,22 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvEchoRep(fp, lhp, bp)
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvEchoRep(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
{
|
||||
u_long *lp, magic;
|
||||
|
||||
lp = (u_long *)MBUF_CTOP(bp);
|
||||
lp = (u_long *) MBUF_CTOP(bp);
|
||||
magic = ntohl(*lp);
|
||||
/*
|
||||
* Tolerate echo replies with either magic number
|
||||
*/
|
||||
if (magic != 0 && magic != LcpInfo.his_magic && magic != LcpInfo.want_magic) {
|
||||
LogPrintf(LogERROR, "RecvEchoRep: his magic is wrong! expect: %x got: %x\n",
|
||||
LcpInfo.his_magic, magic);
|
||||
LcpInfo.his_magic, magic);
|
||||
|
||||
/*
|
||||
* XXX: We should send terminate request. But poor implementation
|
||||
* may die as a result.
|
||||
* XXX: We should send terminate request. But poor implementation may die
|
||||
* as a result.
|
||||
*/
|
||||
}
|
||||
RecvEchoLqr(bp);
|
||||
@ -720,40 +676,28 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvDiscReq(fp, lhp, bp)
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvDiscReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "RecvDiscReq\n");
|
||||
pfree(bp);
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvIdent(fp, lhp, bp)
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvIdent(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "RecvIdent\n");
|
||||
pfree(bp);
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvTimeRemain(fp, lhp, bp)
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvTimeRemain(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "RecvTimeRemain\n");
|
||||
pfree(bp);
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvResetReq(fp, lhp, bp)
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvResetReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "RecvResetReq\n");
|
||||
CcpRecvResetReq(fp);
|
||||
@ -763,10 +707,7 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
void
|
||||
FsmRecvResetAck(fp, lhp, bp)
|
||||
struct fsm *fp;
|
||||
struct fsmheader *lhp;
|
||||
struct mbuf *bp;
|
||||
FsmRecvResetAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "RecvResetAck\n");
|
||||
fp->reqid++;
|
||||
@ -774,27 +715,25 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
struct fsmcodedesc FsmCodes[] = {
|
||||
{ FsmRecvConfigReq, "Configure Request", },
|
||||
{ FsmRecvConfigAck, "Configure Ack", },
|
||||
{ FsmRecvConfigNak, "Configure Nak", },
|
||||
{ FsmRecvConfigRej, "Configure Reject", },
|
||||
{ FsmRecvTermReq, "Terminate Request", },
|
||||
{ FsmRecvTermAck, "Terminate Ack", },
|
||||
{ FsmRecvCodeRej, "Code Reject", },
|
||||
{ FsmRecvProtoRej, "Protocol Reject", },
|
||||
{ FsmRecvEchoReq, "Echo Request", },
|
||||
{ FsmRecvEchoRep, "Echo Reply", },
|
||||
{ FsmRecvDiscReq, "Discard Request", },
|
||||
{ FsmRecvIdent, "Ident", },
|
||||
{ FsmRecvTimeRemain, "Time Remain", },
|
||||
{ FsmRecvResetReq, "Reset Request", },
|
||||
{ FsmRecvResetAck, "Reset Ack", },
|
||||
{FsmRecvConfigReq, "Configure Request",},
|
||||
{FsmRecvConfigAck, "Configure Ack",},
|
||||
{FsmRecvConfigNak, "Configure Nak",},
|
||||
{FsmRecvConfigRej, "Configure Reject",},
|
||||
{FsmRecvTermReq, "Terminate Request",},
|
||||
{FsmRecvTermAck, "Terminate Ack",},
|
||||
{FsmRecvCodeRej, "Code Reject",},
|
||||
{FsmRecvProtoRej, "Protocol Reject",},
|
||||
{FsmRecvEchoReq, "Echo Request",},
|
||||
{FsmRecvEchoRep, "Echo Reply",},
|
||||
{FsmRecvDiscReq, "Discard Request",},
|
||||
{FsmRecvIdent, "Ident",},
|
||||
{FsmRecvTimeRemain, "Time Remain",},
|
||||
{FsmRecvResetReq, "Reset Request",},
|
||||
{FsmRecvResetAck, "Reset Ack",},
|
||||
};
|
||||
|
||||
void
|
||||
FsmInput(fp, bp)
|
||||
struct fsm *fp;
|
||||
struct mbuf *bp;
|
||||
FsmInput(struct fsm * fp, struct mbuf * bp)
|
||||
{
|
||||
int len;
|
||||
struct fsmheader *lhp;
|
||||
@ -805,21 +744,20 @@ struct mbuf *bp;
|
||||
pfree(bp);
|
||||
return;
|
||||
}
|
||||
lhp = (struct fsmheader *)MBUF_CTOP(bp);
|
||||
lhp = (struct fsmheader *) MBUF_CTOP(bp);
|
||||
if (lhp->code == 0 || lhp->code > fp->max_code) {
|
||||
pfree(bp); /* XXX: Should send code reject */
|
||||
pfree(bp); /* XXX: Should send code reject */
|
||||
return;
|
||||
}
|
||||
|
||||
bp->offset += sizeof(struct fsmheader);
|
||||
bp->cnt -= sizeof(struct fsmheader);
|
||||
|
||||
codep = FsmCodes + lhp->code - 1;
|
||||
LogPrintf(fp->LogLevel, "Received %s (%d) state = %s (%d)\n",
|
||||
codep->name, lhp->id, StateNames[fp->state], fp->state);
|
||||
codep->name, lhp->id, StateNames[fp->state], fp->state);
|
||||
if (LogIsKept(LogDEBUG))
|
||||
LogMemory();
|
||||
(codep->action)(fp, lhp, bp);
|
||||
(codep->action) (fp, lhp, bp);
|
||||
if (LogIsKept(LogDEBUG))
|
||||
LogMemory();
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: fsm.h,v 1.8 1997/06/09 03:27:21 brian Exp $
|
||||
* $Id: fsm.h,v 1.9 1997/08/20 23:47:43 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -53,46 +53,45 @@
|
||||
#define OPEN_PASSIVE 1
|
||||
|
||||
struct fsm {
|
||||
char *name; /* Name of protocol */
|
||||
char *name; /* Name of protocol */
|
||||
u_short proto; /* Protocol number */
|
||||
u_short max_code;
|
||||
int open_mode;
|
||||
int state; /* State of the machine */
|
||||
int reqid; /* Next request id */
|
||||
int restart; /* Restart counter value */
|
||||
int maxconfig;
|
||||
int open_mode;
|
||||
int state; /* State of the machine */
|
||||
int reqid; /* Next request id */
|
||||
int restart; /* Restart counter value */
|
||||
int maxconfig;
|
||||
|
||||
int reqcode; /* Request code sent */
|
||||
int reqcode; /* Request code sent */
|
||||
struct pppTimer FsmTimer; /* Restart Timer */
|
||||
|
||||
/*
|
||||
* This timer times the ST_STOPPED state out after the given value
|
||||
* (specified via "set stopped ..."). Although this isn't
|
||||
* specified in the rfc, the rfc *does* say that "the application
|
||||
* may use higher level timers to avoid deadlock".
|
||||
* The StoppedTimer takes effect when the other side ABENDs rather
|
||||
* than going into ST_ACKSENT (and sending the ACK), causing ppp to
|
||||
* time out and drop into ST_STOPPED. At this point, nothing will
|
||||
* change this state :-(
|
||||
* (specified via "set stopped ..."). Although this isn't specified in the
|
||||
* rfc, the rfc *does* say that "the application may use higher level
|
||||
* timers to avoid deadlock". The StoppedTimer takes effect when the other
|
||||
* side ABENDs rather than going into ST_ACKSENT (and sending the ACK),
|
||||
* causing ppp to time out and drop into ST_STOPPED. At this point,
|
||||
* nothing will change this state :-(
|
||||
*/
|
||||
struct pppTimer StoppedTimer;
|
||||
int LogLevel;
|
||||
|
||||
void (*LayerUp)(struct fsm *);
|
||||
void (*LayerDown)(struct fsm *);
|
||||
void (*LayerStart)(struct fsm *);
|
||||
void (*LayerFinish)(struct fsm *);
|
||||
void (*InitRestartCounter)(struct fsm *);
|
||||
void (*SendConfigReq)(struct fsm *);
|
||||
void (*SendTerminateReq)(struct fsm *);
|
||||
void (*SendTerminateAck)(struct fsm *);
|
||||
void (*DecodeConfig)(u_char *, int, int);
|
||||
void (*LayerUp) (struct fsm *);
|
||||
void (*LayerDown) (struct fsm *);
|
||||
void (*LayerStart) (struct fsm *);
|
||||
void (*LayerFinish) (struct fsm *);
|
||||
void (*InitRestartCounter) (struct fsm *);
|
||||
void (*SendConfigReq) (struct fsm *);
|
||||
void (*SendTerminateReq) (struct fsm *);
|
||||
void (*SendTerminateAck) (struct fsm *);
|
||||
void (*DecodeConfig) (u_char *, int, int);
|
||||
};
|
||||
|
||||
struct fsmheader {
|
||||
u_char code; /* Request code */
|
||||
u_char id; /* Identification */
|
||||
u_short length; /* Length of packet */
|
||||
u_char code; /* Request code */
|
||||
u_char id; /* Identification */
|
||||
u_short length; /* Length of packet */
|
||||
};
|
||||
|
||||
#define CODE_CONFIGREQ 1
|
||||
@ -103,16 +102,16 @@ struct fsmheader {
|
||||
#define CODE_TERMACK 6
|
||||
#define CODE_CODEREJ 7
|
||||
#define CODE_PROTOREJ 8
|
||||
#define CODE_ECHOREQ 9 /* Used in LCP */
|
||||
#define CODE_ECHOREP 10 /* Used in LCP */
|
||||
#define CODE_ECHOREQ 9 /* Used in LCP */
|
||||
#define CODE_ECHOREP 10 /* Used in LCP */
|
||||
#define CODE_DISCREQ 11
|
||||
#define CODE_IDENT 12 /* Used in LCP Extension */
|
||||
#define CODE_TIMEREM 13 /* Used in LCP Extension */
|
||||
#define CODE_RESETREQ 14 /* Used in CCP */
|
||||
#define CODE_RESETACK 15 /* Used in CCP */
|
||||
#define CODE_IDENT 12 /* Used in LCP Extension */
|
||||
#define CODE_TIMEREM 13 /* Used in LCP Extension */
|
||||
#define CODE_RESETREQ 14 /* Used in CCP */
|
||||
#define CODE_RESETACK 15 /* Used in CCP */
|
||||
|
||||
struct fsmcodedesc {
|
||||
void (*action)(struct fsm *, struct fsmheader *, struct mbuf *);
|
||||
void (*action) (struct fsm *, struct fsmheader *, struct mbuf *);
|
||||
char *name;
|
||||
};
|
||||
|
||||
@ -142,8 +141,8 @@ extern void FsmRecvConfigAck(struct fsm *, struct fsmheader *, struct mbuf *);
|
||||
extern void FsmRecvConfigNak(struct fsm *, struct fsmheader *, struct mbuf *);
|
||||
extern void FsmRecvTermReq(struct fsm *, struct fsmheader *, struct mbuf *);
|
||||
extern void FsmRecvTermAck(struct fsm *, struct fsmheader *, struct mbuf *);
|
||||
extern void FsmClose(struct fsm *fp);
|
||||
extern void FsmClose(struct fsm * fp);
|
||||
|
||||
extern struct fsm LcpFsm, IpcpFsm, CcpFsm;
|
||||
|
||||
#endif /* _FSM_H_ */
|
||||
#endif /* _FSM_H_ */
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: hdlc.c,v 1.15 1997/05/26 00:43:59 brian Exp $
|
||||
* $Id: hdlc.c,v 1.16 1997/06/09 03:27:22 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -33,11 +33,11 @@
|
||||
#include "ccp.h"
|
||||
|
||||
struct hdlcstat {
|
||||
int badfcs;
|
||||
int badaddr;
|
||||
int badcommand;
|
||||
int unknownproto;
|
||||
} HdlcStat;
|
||||
int badfcs;
|
||||
int badaddr;
|
||||
int badcommand;
|
||||
int unknownproto;
|
||||
} HdlcStat;
|
||||
|
||||
static int ifOutPackets, ifOutOctets, ifOutLQRs;
|
||||
static int ifInPackets, ifInOctets;
|
||||
@ -47,55 +47,80 @@ struct protostat {
|
||||
char *name;
|
||||
u_long in_count;
|
||||
u_long out_count;
|
||||
} ProtocolStat[] = {
|
||||
{ PROTO_IP, "IP" },
|
||||
{ PROTO_VJUNCOMP, "VJ_UNCOMP" },
|
||||
{ PROTO_VJCOMP, "VJ_COMP" },
|
||||
{ PROTO_COMPD, "COMPD" },
|
||||
{ PROTO_LCP, "LCP" },
|
||||
{ PROTO_IPCP, "IPCP" },
|
||||
{ PROTO_CCP, "CCP" },
|
||||
{ PROTO_PAP, "PAP" },
|
||||
{ PROTO_LQR, "LQR" },
|
||||
{ PROTO_CHAP, "CHAP" },
|
||||
{ 0, "Others" },
|
||||
} ProtocolStat[] = {
|
||||
|
||||
{
|
||||
PROTO_IP, "IP"
|
||||
},
|
||||
{
|
||||
PROTO_VJUNCOMP, "VJ_UNCOMP"
|
||||
},
|
||||
{
|
||||
PROTO_VJCOMP, "VJ_COMP"
|
||||
},
|
||||
{
|
||||
PROTO_COMPD, "COMPD"
|
||||
},
|
||||
{
|
||||
PROTO_LCP, "LCP"
|
||||
},
|
||||
{
|
||||
PROTO_IPCP, "IPCP"
|
||||
},
|
||||
{
|
||||
PROTO_CCP, "CCP"
|
||||
},
|
||||
{
|
||||
PROTO_PAP, "PAP"
|
||||
},
|
||||
{
|
||||
PROTO_LQR, "LQR"
|
||||
},
|
||||
{
|
||||
PROTO_CHAP, "CHAP"
|
||||
},
|
||||
{
|
||||
0, "Others"
|
||||
},
|
||||
};
|
||||
|
||||
static u_short const fcstab[256] = {
|
||||
/* 00 */ 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
|
||||
/* 08 */ 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
|
||||
/* 10 */ 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
|
||||
/* 18 */ 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
|
||||
/* 20 */ 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
|
||||
/* 28 */ 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
|
||||
/* 30 */ 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
|
||||
/* 38 */ 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
|
||||
/* 40 */ 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
|
||||
/* 48 */ 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
|
||||
/* 50 */ 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
|
||||
/* 58 */ 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
|
||||
/* 60 */ 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
|
||||
/* 68 */ 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
|
||||
/* 70 */ 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
|
||||
/* 78 */ 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
|
||||
/* 80 */ 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
|
||||
/* 88 */ 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
|
||||
/* 90 */ 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
|
||||
/* 98 */ 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
|
||||
/* a0 */ 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
|
||||
/* a8 */ 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
|
||||
/* b0 */ 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
|
||||
/* b8 */ 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
|
||||
/* c0 */ 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
|
||||
/* c8 */ 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
|
||||
/* d0 */ 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
|
||||
/* d8 */ 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
|
||||
/* e0 */ 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
|
||||
/* e8 */ 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
|
||||
/* f0 */ 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
|
||||
/* f8 */ 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
|
||||
/* 00 */ 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
|
||||
/* 08 */ 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
|
||||
/* 10 */ 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
|
||||
/* 18 */ 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
|
||||
/* 20 */ 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
|
||||
/* 28 */ 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
|
||||
/* 30 */ 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
|
||||
/* 38 */ 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
|
||||
/* 40 */ 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
|
||||
/* 48 */ 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
|
||||
/* 50 */ 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
|
||||
/* 58 */ 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
|
||||
/* 60 */ 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
|
||||
/* 68 */ 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
|
||||
/* 70 */ 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
|
||||
/* 78 */ 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
|
||||
/* 80 */ 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
|
||||
/* 88 */ 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
|
||||
/* 90 */ 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
|
||||
/* 98 */ 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
|
||||
/* a0 */ 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
|
||||
/* a8 */ 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
|
||||
/* b0 */ 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
|
||||
/* b8 */ 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
|
||||
/* c0 */ 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
|
||||
/* c8 */ 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
|
||||
/* d0 */ 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
|
||||
/* d8 */ 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
|
||||
/* e0 */ 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
|
||||
/* e8 */ 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
|
||||
/* f0 */ 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
|
||||
/* f8 */ 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
|
||||
};
|
||||
|
||||
u_char EscMap[33];
|
||||
|
||||
void
|
||||
HdlcInit()
|
||||
{
|
||||
@ -108,16 +133,16 @@ HdlcInit()
|
||||
* HDLC FCS computation. Read RFC 1171 Appendix B and CCITT X.25 section
|
||||
* 2.27 for further details.
|
||||
*/
|
||||
inline u_short
|
||||
HdlcFcs(u_short fcs, u_char *cp, int len)
|
||||
inline u_short
|
||||
HdlcFcs(u_short fcs, u_char * cp, int len)
|
||||
{
|
||||
while (len--)
|
||||
fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff];
|
||||
return(fcs);
|
||||
return (fcs);
|
||||
}
|
||||
|
||||
void
|
||||
HdlcOutput(int pri, u_short proto, struct mbuf *bp)
|
||||
HdlcOutput(int pri, u_short proto, struct mbuf * bp)
|
||||
{
|
||||
struct mbuf *mhp, *mfcs;
|
||||
struct protostat *statp;
|
||||
@ -143,8 +168,9 @@ HdlcOutput(int pri, u_short proto, struct mbuf *bp)
|
||||
*cp++ = HDLC_UI;
|
||||
mhp->cnt += 2;
|
||||
}
|
||||
|
||||
/*
|
||||
* If possible, compress protocol field.
|
||||
* If possible, compress protocol field.
|
||||
*/
|
||||
if (LcpInfo.his_protocomp && (proto & 0xff00) == 0) {
|
||||
*cp++ = proto;
|
||||
@ -174,18 +200,16 @@ HdlcOutput(int pri, u_short proto, struct mbuf *bp)
|
||||
lqr->PeerInOctets = HisLqrSave.SaveInOctets;
|
||||
lqr->PeerOutLQRs = ++ifOutLQRs;
|
||||
LqrDump("LqrOutput", lqr);
|
||||
LqrChangeOrder(lqr, (struct lqrdata *)(MBUF_CTOP(bp)));
|
||||
LqrChangeOrder(lqr, (struct lqrdata *) (MBUF_CTOP(bp)));
|
||||
}
|
||||
|
||||
if (!DEV_IS_SYNC) {
|
||||
fcs = HdlcFcs(INITFCS, MBUF_CTOP(mhp), mhp->cnt);
|
||||
fcs = HdlcFcs(fcs, MBUF_CTOP(bp), bp->cnt);
|
||||
fcs = ~fcs;
|
||||
cp = MBUF_CTOP(mfcs);
|
||||
*cp++ = fcs & 0377; /* Low byte first!! */
|
||||
*cp++ = fcs & 0377; /* Low byte first!! */
|
||||
*cp++ = fcs >> 8;
|
||||
}
|
||||
|
||||
LogDumpBp(LogHDLC, "HdlcOutput", mhp);
|
||||
for (statp = ProtocolStat; statp->number; statp++)
|
||||
if (statp->number == proto)
|
||||
@ -198,7 +222,7 @@ HdlcOutput(int pri, u_short proto, struct mbuf *bp)
|
||||
}
|
||||
|
||||
void
|
||||
DecodePacket(u_short proto, struct mbuf *bp)
|
||||
DecodePacket(u_short proto, struct mbuf * bp)
|
||||
{
|
||||
u_char *cp;
|
||||
|
||||
@ -242,7 +266,7 @@ DecodePacket(u_short proto, struct mbuf *bp)
|
||||
bp->offset -= 2;
|
||||
bp->cnt += 2;
|
||||
cp = MBUF_CTOP(bp);
|
||||
LcpSendProtoRej(cp, bp->cnt);
|
||||
LcpSendProtoRej(cp, bp->cnt);
|
||||
HisLqrSave.SaveInDiscards++;
|
||||
HdlcStat.unknownproto++;
|
||||
pfree(bp);
|
||||
@ -263,15 +287,15 @@ ReportProtStatus()
|
||||
do {
|
||||
statp++;
|
||||
fprintf(VarTerm, " %-9s: %8lu, %8lu",
|
||||
statp->name, statp->in_count, statp->out_count);
|
||||
statp->name, statp->in_count, statp->out_count);
|
||||
if (++cnt == 2) {
|
||||
fprintf(VarTerm, "\n");
|
||||
cnt = 0;
|
||||
}
|
||||
} while (statp->number);
|
||||
if (cnt)
|
||||
fprintf(VarTerm, "\n");
|
||||
return(1);
|
||||
fprintf(VarTerm, "\n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
int
|
||||
@ -282,7 +306,7 @@ ReportHdlcStatus()
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "HDLC level errors\n\n");
|
||||
fprintf(VarTerm, "FCS: %u ADDR: %u COMMAND: %u PROTO: %u\n",
|
||||
hp->badfcs, hp->badaddr, hp->badcommand, hp->unknownproto);
|
||||
hp->badfcs, hp->badaddr, hp->badcommand, hp->unknownproto);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -297,14 +321,14 @@ HdlcErrorCheck()
|
||||
|
||||
if (bcmp(hp, op, sizeof(laststat))) {
|
||||
LogPrintf(LogPHASE, "HDLC errors -> FCS: %u ADDR: %u COMD: %u PROTO: %u\n",
|
||||
hp->badfcs - op->badfcs, hp->badaddr - op->badaddr,
|
||||
hp->badcommand - op->badcommand, hp->unknownproto - op->unknownproto);
|
||||
hp->badfcs - op->badfcs, hp->badaddr - op->badaddr,
|
||||
hp->badcommand - op->badcommand, hp->unknownproto - op->unknownproto);
|
||||
}
|
||||
laststat = HdlcStat;
|
||||
}
|
||||
|
||||
void
|
||||
HdlcInput(struct mbuf *bp)
|
||||
HdlcInput(struct mbuf * bp)
|
||||
{
|
||||
u_short fcs, proto;
|
||||
u_char *cp, addr, ctrl;
|
||||
@ -318,7 +342,7 @@ HdlcInput(struct mbuf *bp)
|
||||
HisLqrSave.SaveInOctets += bp->cnt + 1;
|
||||
|
||||
LogPrintf(LogDEBUG, "HdlcInput: fcs = %04x (%s)\n",
|
||||
fcs, (fcs == GOODFCS)? "good" : "bad");
|
||||
fcs, (fcs == GOODFCS) ? "good" : "bad");
|
||||
if (fcs != GOODFCS) {
|
||||
HisLqrSave.SaveInErrors++;
|
||||
LogPrintf(LogDEBUG, "HdlcInput: Bad FCS\n");
|
||||
@ -330,18 +354,18 @@ HdlcInput(struct mbuf *bp)
|
||||
bp->cnt -= 2; /* discard FCS part */
|
||||
|
||||
if (bp->cnt < 2) { /* XXX: raise this bar ? */
|
||||
pfree(bp);
|
||||
return;
|
||||
pfree(bp);
|
||||
return;
|
||||
}
|
||||
|
||||
cp = MBUF_CTOP(bp);
|
||||
|
||||
ifInPackets++;
|
||||
ifInOctets += bp->cnt;
|
||||
|
||||
if (!LcpInfo.want_acfcomp) {
|
||||
|
||||
/*
|
||||
* We expect that packet is not compressed.
|
||||
* We expect that packet is not compressed.
|
||||
*/
|
||||
addr = *cp++;
|
||||
if (addr != HDLC_ADDR) {
|
||||
@ -351,7 +375,6 @@ HdlcInput(struct mbuf *bp)
|
||||
pfree(bp);
|
||||
return;
|
||||
}
|
||||
|
||||
ctrl = *cp++;
|
||||
if (ctrl != HDLC_UI) {
|
||||
HisLqrSave.SaveInErrors++;
|
||||
@ -363,20 +386,22 @@ HdlcInput(struct mbuf *bp)
|
||||
bp->offset += 2;
|
||||
bp->cnt -= 2;
|
||||
} else if (cp[0] == HDLC_ADDR && cp[1] == HDLC_UI) {
|
||||
|
||||
/*
|
||||
* We can receive compressed packet, but peer still send
|
||||
* uncompressed packet to me.
|
||||
* We can receive compressed packet, but peer still send uncompressed
|
||||
* packet to me.
|
||||
*/
|
||||
cp += 2;
|
||||
bp->offset += 2;
|
||||
bp->cnt -= 2;
|
||||
}
|
||||
|
||||
if (LcpInfo.want_protocomp) {
|
||||
proto = 0;
|
||||
cp--;
|
||||
do {
|
||||
cp++; bp->offset++; bp->cnt--;
|
||||
cp++;
|
||||
bp->offset++;
|
||||
bp->cnt--;
|
||||
proto = proto << 8;
|
||||
proto += *cp;
|
||||
} while (!(proto & 1));
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: hdlc.h,v 1.8 1997/06/01 11:35:02 brian Exp $
|
||||
* $Id: hdlc.h,v 1.9 1997/06/09 03:27:22 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -26,17 +26,17 @@
|
||||
/*
|
||||
* Definition for Async HDLC
|
||||
*/
|
||||
#define HDLC_SYN 0x7e /* SYNC character */
|
||||
#define HDLC_ESC 0x7d /* Escape character */
|
||||
#define HDLC_XOR 0x20 /* Modifier value */
|
||||
#define HDLC_SYN 0x7e /* SYNC character */
|
||||
#define HDLC_ESC 0x7d /* Escape character */
|
||||
#define HDLC_XOR 0x20 /* Modifier value */
|
||||
|
||||
#define HDLC_ADDR 0xff
|
||||
#define HDLC_UI 0x03
|
||||
/*
|
||||
* Definition for HDLC Frame Check Sequence
|
||||
*/
|
||||
#define INITFCS 0xffff /* Initial value for FCS computation */
|
||||
#define GOODFCS 0xf0b8 /* Good FCS value */
|
||||
#define INITFCS 0xffff /* Initial value for FCS computation */
|
||||
#define GOODFCS 0xf0b8 /* Good FCS value */
|
||||
|
||||
#define DEF_MRU 1500
|
||||
#define MAX_MRU 2048
|
||||
@ -58,13 +58,14 @@
|
||||
#define PRI_FAST 1 /* Fast (interractive) */
|
||||
#define PRI_LINK 1 /* Urgent (LQR packets) */
|
||||
|
||||
unsigned char EscMap[33];
|
||||
extern u_char EscMap[33];
|
||||
|
||||
void HdlcInit(void);
|
||||
void HdlcErrorCheck(void);
|
||||
void HdlcInput(struct mbuf *bp);
|
||||
void HdlcOutput(int pri, u_short proto, struct mbuf *bp);
|
||||
void AsyncOutput(int pri, struct mbuf *bp, int proto);
|
||||
void HdlcInput(struct mbuf * bp);
|
||||
void HdlcOutput(int pri, u_short proto, struct mbuf * bp);
|
||||
void AsyncOutput(int pri, struct mbuf * bp, int proto);
|
||||
u_short HdlcFcs(u_short, u_char *, int);
|
||||
void DecodePacket(u_short, struct mbuf *);
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: ip.c,v 1.21 1997/06/09 03:27:23 brian Exp $
|
||||
* $Id: ip.c,v 1.22 1997/06/16 21:20:00 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Return ICMP message for filterd packet
|
||||
@ -44,7 +44,8 @@ extern void LcpClose();
|
||||
|
||||
static struct pppTimer IdleTimer;
|
||||
|
||||
static void IdleTimeout()
|
||||
static void
|
||||
IdleTimeout()
|
||||
{
|
||||
LogPrintf(LogPHASE, "Idle timer expired.\n");
|
||||
reconnect(RECON_FALSE);
|
||||
@ -58,7 +59,7 @@ static void IdleTimeout()
|
||||
void
|
||||
StartIdleTimer()
|
||||
{
|
||||
if (!(mode & (MODE_DEDICATED|MODE_DDIAL))) {
|
||||
if (!(mode & (MODE_DEDICATED | MODE_DDIAL))) {
|
||||
StopTimer(&IdleTimer);
|
||||
IdleTimer.func = IdleTimeout;
|
||||
IdleTimer.load = VarIdleTimeout * SECTICKS;
|
||||
@ -86,15 +87,15 @@ StopIdleTimer()
|
||||
static void
|
||||
RestartIdleTimer()
|
||||
{
|
||||
if (!(mode & (MODE_DEDICATED|MODE_DDIAL)) && ipKeepAlive ) {
|
||||
if (!(mode & (MODE_DEDICATED | MODE_DDIAL)) && ipKeepAlive) {
|
||||
StartTimer(&IdleTimer);
|
||||
ipIdleSecs = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static u_short interactive_ports[32] = {
|
||||
544, 513, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 21, 22, 23, 0, 0, 0, 0, 0, 0, 0, 543,
|
||||
544, 513, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 21, 22, 23, 0, 0, 0, 0, 0, 0, 0, 543,
|
||||
};
|
||||
|
||||
#define INTERACTIVE(p) (interactive_ports[(p) & 0x1F] == (p))
|
||||
@ -103,23 +104,21 @@ static char *TcpFlags[] = {
|
||||
"FIN", "SYN", "RST", "PSH", "ACK", "URG",
|
||||
};
|
||||
|
||||
static char *Direction[] = { "INP", "OUT", "OUT", "IN/OUT" };
|
||||
static struct filterent *Filters[] = { ifilters, ofilters, dfilters, afilters };
|
||||
static char *Direction[] = {"INP", "OUT", "OUT", "IN/OUT"};
|
||||
static struct filterent *Filters[] = {ifilters, ofilters, dfilters, afilters};
|
||||
|
||||
static int
|
||||
PortMatch(op, pport, rport)
|
||||
int op;
|
||||
u_short pport, rport;
|
||||
PortMatch(int op, u_short pport, u_short rport)
|
||||
{
|
||||
switch (op) {
|
||||
case OP_EQ:
|
||||
return(pport == rport);
|
||||
case OP_EQ:
|
||||
return (pport == rport);
|
||||
case OP_GT:
|
||||
return(pport > rport);
|
||||
return (pport > rport);
|
||||
case OP_LT:
|
||||
return(pport < rport);
|
||||
return (pport < rport);
|
||||
default:
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,9 +126,7 @@ u_short pport, rport;
|
||||
* Check a packet against with defined filters
|
||||
*/
|
||||
static int
|
||||
FilterCheck(pip, direction)
|
||||
struct ip *pip;
|
||||
int direction;
|
||||
FilterCheck(struct ip * pip, int direction)
|
||||
{
|
||||
struct filterent *fp = Filters[direction];
|
||||
int gotinfo, cproto, estab, n;
|
||||
@ -144,78 +141,81 @@ int direction;
|
||||
sport = dport = 0;
|
||||
for (n = 0; n < MAXFILTERS; n++) {
|
||||
if (fp->action) {
|
||||
/* permit fragments on in and out filter */
|
||||
if ((direction == FL_IN || direction == FL_OUT) &&
|
||||
(ntohs(pip->ip_off) & IP_OFFMASK) != 0) {
|
||||
return(A_PERMIT);
|
||||
}
|
||||
LogPrintf(LogDEBUG, "rule = %d\n", n);
|
||||
/* permit fragments on in and out filter */
|
||||
if ((direction == FL_IN || direction == FL_OUT) &&
|
||||
(ntohs(pip->ip_off) & IP_OFFMASK) != 0) {
|
||||
return (A_PERMIT);
|
||||
}
|
||||
LogPrintf(LogDEBUG, "rule = %d\n", n);
|
||||
if ((pip->ip_src.s_addr & fp->smask.s_addr) == fp->saddr.s_addr
|
||||
&& (pip->ip_dst.s_addr & fp->dmask.s_addr) == fp->daddr.s_addr) {
|
||||
if (fp->proto) {
|
||||
if (!gotinfo) {
|
||||
ptop = (char *)pip + (pip->ip_hl << 2);
|
||||
ptop = (char *) pip + (pip->ip_hl << 2);
|
||||
|
||||
switch (pip->ip_p) {
|
||||
case IPPROTO_ICMP:
|
||||
cproto = P_ICMP; ih = (struct icmp *)ptop;
|
||||
sport = ih->icmp_type; estab = 1;
|
||||
cproto = P_ICMP;
|
||||
ih = (struct icmp *) ptop;
|
||||
sport = ih->icmp_type;
|
||||
estab = 1;
|
||||
break;
|
||||
case IPPROTO_UDP:
|
||||
cproto = P_UDP; uh = (struct udphdr *)ptop;
|
||||
sport = ntohs(uh->uh_sport); dport = ntohs(uh->uh_dport);
|
||||
cproto = P_UDP;
|
||||
uh = (struct udphdr *) ptop;
|
||||
sport = ntohs(uh->uh_sport);
|
||||
dport = ntohs(uh->uh_dport);
|
||||
estab = 1;
|
||||
break;
|
||||
case IPPROTO_TCP:
|
||||
cproto = P_TCP; th = (struct tcphdr *)ptop;
|
||||
sport = ntohs(th->th_sport); dport = ntohs(th->th_dport);
|
||||
cproto = P_TCP;
|
||||
th = (struct tcphdr *) ptop;
|
||||
sport = ntohs(th->th_sport);
|
||||
dport = ntohs(th->th_dport);
|
||||
estab = (th->th_flags & TH_ACK);
|
||||
if (estab == 0)
|
||||
LogPrintf(LogDEBUG, "flag = %02x, sport = %d, dport = %d\n",
|
||||
th->th_flags, sport, dport);
|
||||
if (estab == 0)
|
||||
LogPrintf(LogDEBUG, "flag = %02x, sport = %d, dport = %d\n",
|
||||
th->th_flags, sport, dport);
|
||||
break;
|
||||
default:
|
||||
return(A_DENY); /* We'll block unknown type of packet */
|
||||
return (A_DENY);/* We'll block unknown type of packet */
|
||||
}
|
||||
gotinfo = 1;
|
||||
LogPrintf(LogDEBUG, "dir = %d, proto = %d, srcop = %d,"
|
||||
" dstop = %d, estab = %d\n", direction, cproto,
|
||||
fp->opt.srcop, fp->opt.dstop, estab);
|
||||
LogPrintf(LogDEBUG, "dir = %d, proto = %d, srcop = %d,"
|
||||
" dstop = %d, estab = %d\n", direction, cproto,
|
||||
fp->opt.srcop, fp->opt.dstop, estab);
|
||||
}
|
||||
|
||||
LogPrintf(LogDEBUG, "check0: rule = %d, proto = %d, sport = %d,"
|
||||
" dport = %d\n", n, cproto, sport, dport);
|
||||
" dport = %d\n", n, cproto, sport, dport);
|
||||
LogPrintf(LogDEBUG, "check0: action = %d\n", fp->action);
|
||||
|
||||
if (cproto == fp->proto) {
|
||||
if ((fp->opt.srcop == OP_NONE ||
|
||||
PortMatch(fp->opt.srcop, sport, fp->opt.srcport))
|
||||
&&
|
||||
PortMatch(fp->opt.srcop, sport, fp->opt.srcport))
|
||||
&&
|
||||
(fp->opt.dstop == OP_NONE ||
|
||||
PortMatch(fp->opt.dstop, dport, fp->opt.dstport))
|
||||
&&
|
||||
PortMatch(fp->opt.dstop, dport, fp->opt.dstport))
|
||||
&&
|
||||
(fp->opt.estab == 0 || estab)) {
|
||||
return(fp->action);
|
||||
return (fp->action);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Address is mached. Make a decision. */
|
||||
LogPrintf(LogDEBUG, "check1: action = %d\n", fp->action);
|
||||
return(fp->action);
|
||||
return (fp->action);
|
||||
}
|
||||
}
|
||||
}
|
||||
fp++;
|
||||
}
|
||||
return(A_DENY); /* No rule is mached. Deny this packet */
|
||||
return (A_DENY); /* No rule is mached. Deny this packet */
|
||||
}
|
||||
return(A_PERMIT); /* No rule is given. Permit this packet */
|
||||
return (A_PERMIT); /* No rule is given. Permit this packet */
|
||||
}
|
||||
|
||||
static void
|
||||
IcmpError(pip, code)
|
||||
struct ip *pip;
|
||||
int code;
|
||||
IcmpError(struct ip * pip, int code)
|
||||
{
|
||||
#ifdef notdef
|
||||
struct mbuf *bp;
|
||||
@ -234,10 +234,7 @@ int code;
|
||||
* For debugging aid.
|
||||
*/
|
||||
int
|
||||
PacketCheck(cp, nb, direction)
|
||||
char *cp;
|
||||
int nb;
|
||||
int direction;
|
||||
PacketCheck(char *cp, int nb, int direction)
|
||||
{
|
||||
struct ip *pip;
|
||||
struct tcphdr *th;
|
||||
@ -252,78 +249,76 @@ int direction;
|
||||
logit = LogIsKept(LogTCPIP);
|
||||
loglen = 0;
|
||||
|
||||
pip = (struct ip *)cp;
|
||||
pip = (struct ip *) cp;
|
||||
|
||||
if (logit && loglen < sizeof logbuf) {
|
||||
snprintf(logbuf+loglen, sizeof logbuf - loglen, "%s ",
|
||||
Direction[direction]);
|
||||
loglen += strlen(logbuf+loglen);
|
||||
snprintf(logbuf + loglen, sizeof logbuf - loglen, "%s ",
|
||||
Direction[direction]);
|
||||
loglen += strlen(logbuf + loglen);
|
||||
}
|
||||
|
||||
ptop = (cp + (pip->ip_hl << 2));
|
||||
|
||||
switch (pip->ip_p) {
|
||||
case IPPROTO_ICMP:
|
||||
if (logit && loglen < sizeof logbuf) {
|
||||
icmph = (struct icmp *)ptop;
|
||||
snprintf(logbuf+loglen, sizeof logbuf - loglen,
|
||||
"ICMP: %s:%d ---> ", inet_ntoa(pip->ip_src), icmph->icmp_type);
|
||||
loglen += strlen(logbuf+loglen);
|
||||
snprintf(logbuf+loglen, sizeof logbuf - loglen,
|
||||
"%s:%d", inet_ntoa(pip->ip_dst), icmph->icmp_type);
|
||||
loglen += strlen(logbuf+loglen);
|
||||
icmph = (struct icmp *) ptop;
|
||||
snprintf(logbuf + loglen, sizeof logbuf - loglen,
|
||||
"ICMP: %s:%d ---> ", inet_ntoa(pip->ip_src), icmph->icmp_type);
|
||||
loglen += strlen(logbuf + loglen);
|
||||
snprintf(logbuf + loglen, sizeof logbuf - loglen,
|
||||
"%s:%d", inet_ntoa(pip->ip_dst), icmph->icmp_type);
|
||||
loglen += strlen(logbuf + loglen);
|
||||
}
|
||||
break;
|
||||
case IPPROTO_UDP:
|
||||
if (logit && loglen < sizeof logbuf) {
|
||||
uh = (struct udphdr *)ptop;
|
||||
snprintf(logbuf+loglen, sizeof logbuf - loglen,
|
||||
"UDP: %s:%d ---> ", inet_ntoa(pip->ip_src), ntohs(uh->uh_sport));
|
||||
loglen += strlen(logbuf+loglen);
|
||||
snprintf(logbuf+loglen, sizeof logbuf - loglen,
|
||||
"%s:%d", inet_ntoa(pip->ip_dst), ntohs(uh->uh_dport));
|
||||
loglen += strlen(logbuf+loglen);
|
||||
uh = (struct udphdr *) ptop;
|
||||
snprintf(logbuf + loglen, sizeof logbuf - loglen,
|
||||
"UDP: %s:%d ---> ", inet_ntoa(pip->ip_src), ntohs(uh->uh_sport));
|
||||
loglen += strlen(logbuf + loglen);
|
||||
snprintf(logbuf + loglen, sizeof logbuf - loglen,
|
||||
"%s:%d", inet_ntoa(pip->ip_dst), ntohs(uh->uh_dport));
|
||||
loglen += strlen(logbuf + loglen);
|
||||
}
|
||||
break;
|
||||
case IPPROTO_TCP:
|
||||
th = (struct tcphdr *)ptop;
|
||||
th = (struct tcphdr *) ptop;
|
||||
if (pip->ip_tos == IPTOS_LOWDELAY)
|
||||
pri = PRI_FAST;
|
||||
else if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0) {
|
||||
if (INTERACTIVE(ntohs(th->th_sport)) || INTERACTIVE(ntohs(th->th_dport)))
|
||||
pri = PRI_FAST;
|
||||
pri = PRI_FAST;
|
||||
}
|
||||
|
||||
if (logit && loglen < sizeof logbuf) {
|
||||
len = ntohs(pip->ip_len) - (pip->ip_hl << 2) - (th->th_off << 2);
|
||||
snprintf(logbuf+loglen, sizeof logbuf - loglen,
|
||||
"TCP: %s:%d ---> ", inet_ntoa(pip->ip_src), ntohs(th->th_sport));
|
||||
loglen += strlen(logbuf+loglen);
|
||||
snprintf(logbuf+loglen, sizeof logbuf - loglen,
|
||||
"%s:%d", inet_ntoa(pip->ip_dst), ntohs(th->th_dport));
|
||||
loglen += strlen(logbuf+loglen);
|
||||
snprintf(logbuf + loglen, sizeof logbuf - loglen,
|
||||
"TCP: %s:%d ---> ", inet_ntoa(pip->ip_src), ntohs(th->th_sport));
|
||||
loglen += strlen(logbuf + loglen);
|
||||
snprintf(logbuf + loglen, sizeof logbuf - loglen,
|
||||
"%s:%d", inet_ntoa(pip->ip_dst), ntohs(th->th_dport));
|
||||
loglen += strlen(logbuf + loglen);
|
||||
n = 0;
|
||||
for (mask = TH_FIN; mask != 0x40; mask <<= 1) {
|
||||
if (th->th_flags & mask) {
|
||||
snprintf(logbuf+loglen, sizeof logbuf - loglen, " %s", TcpFlags[n]);
|
||||
loglen += strlen(logbuf+loglen);
|
||||
}
|
||||
snprintf(logbuf + loglen, sizeof logbuf - loglen, " %s", TcpFlags[n]);
|
||||
loglen += strlen(logbuf + loglen);
|
||||
}
|
||||
n++;
|
||||
}
|
||||
snprintf(logbuf+loglen, sizeof logbuf - loglen,
|
||||
" seq:%x ack:%x (%d/%d)",
|
||||
ntohl(th->th_seq), ntohl(th->th_ack), len, nb);
|
||||
loglen += strlen(logbuf+loglen);
|
||||
snprintf(logbuf + loglen, sizeof logbuf - loglen,
|
||||
" seq:%x ack:%x (%d/%d)",
|
||||
ntohl(th->th_seq), ntohl(th->th_ack), len, nb);
|
||||
loglen += strlen(logbuf + loglen);
|
||||
if ((th->th_flags & TH_SYN) && nb > 40) {
|
||||
u_short *sp;
|
||||
u_short *sp;
|
||||
|
||||
ptop += 20;
|
||||
sp = (u_short *)ptop;
|
||||
sp = (u_short *) ptop;
|
||||
if (ntohs(sp[0]) == 0x0204) {
|
||||
snprintf(logbuf+loglen, sizeof logbuf - loglen,
|
||||
" MSS = %d", ntohs(sp[1]));
|
||||
loglen += strlen(logbuf+loglen);
|
||||
}
|
||||
snprintf(logbuf + loglen, sizeof logbuf - loglen,
|
||||
" MSS = %d", ntohs(sp[1]));
|
||||
loglen += strlen(logbuf + loglen);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -331,25 +326,25 @@ int direction;
|
||||
|
||||
if (logit)
|
||||
LogPrintf(LogTCPIP, "%s\n", logbuf);
|
||||
|
||||
|
||||
if ((FilterCheck(pip, direction) & A_DENY)) {
|
||||
LogPrintf(LogDEBUG, "blocked.\n");
|
||||
if (direction == 0) IcmpError(pip, pri);
|
||||
return(-1);
|
||||
if (direction == 0)
|
||||
IcmpError(pip, pri);
|
||||
return (-1);
|
||||
} else {
|
||||
if ( FilterCheck(pip, FL_KEEP ) & A_DENY ) { /* Check Keep Alive filter */
|
||||
ipKeepAlive = FALSE;
|
||||
if (FilterCheck(pip, FL_KEEP) & A_DENY) { /* Check Keep Alive filter */
|
||||
ipKeepAlive = FALSE;
|
||||
} else {
|
||||
ipKeepAlive = TRUE;
|
||||
ipKeepAlive = TRUE;
|
||||
}
|
||||
return(pri);
|
||||
return (pri);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
IpInput(bp)
|
||||
struct mbuf *bp; /* IN: Pointer to IP pakcet */
|
||||
{
|
||||
IpInput(struct mbuf * bp)
|
||||
{ /* IN: Pointer to IP pakcet */
|
||||
u_char *cp;
|
||||
struct mbuf *wp;
|
||||
int nb, nw;
|
||||
@ -357,7 +352,7 @@ struct mbuf *bp; /* IN: Pointer to IP pakcet */
|
||||
|
||||
cp = tunbuff;
|
||||
nb = 0;
|
||||
for (wp = bp; wp; wp = wp->next) { /* Copy to contiguous region */
|
||||
for (wp = bp; wp; wp = wp->next) { /* Copy to contiguous region */
|
||||
bcopy(MBUF_CTOP(wp), cp, wp->cnt);
|
||||
cp += wp->cnt;
|
||||
nb += wp->cnt;
|
||||
@ -375,51 +370,44 @@ struct mbuf *bp; /* IN: Pointer to IP pakcet */
|
||||
pfree(bp);
|
||||
return;
|
||||
}
|
||||
|
||||
if (iresult == PKT_ALIAS_OK
|
||||
|| iresult == PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
|
||||
if ( PacketCheck(tunbuff, nb, FL_IN ) < 0) {
|
||||
pfree(bp);
|
||||
return;
|
||||
|| iresult == PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
|
||||
if (PacketCheck(tunbuff, nb, FL_IN) < 0) {
|
||||
pfree(bp);
|
||||
return;
|
||||
}
|
||||
|
||||
ipInOctets += nb;
|
||||
|
||||
nb = ntohs(((struct ip *) tunbuff)->ip_len);
|
||||
nw = write(tun_out, tunbuff, nb);
|
||||
if (nw != nb)
|
||||
LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
|
||||
LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
|
||||
|
||||
if (iresult == PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
|
||||
while ((fptr = VarGetNextFragmentPtr(tunbuff)) != NULL) {
|
||||
VarFragmentAliasIn(tunbuff, fptr);
|
||||
nb = ntohs(((struct ip *) fptr)->ip_len);
|
||||
nw = write(tun_out, fptr, nb);
|
||||
if (nw != nb)
|
||||
LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
|
||||
free(fptr);
|
||||
}
|
||||
while ((fptr = VarPacketAliasGetFragment(tunbuff)) != NULL) {
|
||||
VarPacketAliasFragmentIn(tunbuff, fptr);
|
||||
nb = ntohs(((struct ip *) fptr)->ip_len);
|
||||
nw = write(tun_out, fptr, nb);
|
||||
if (nw != nb)
|
||||
LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
|
||||
free(fptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (iresult == PKT_ALIAS_UNRESOLVED_FRAGMENT) {
|
||||
} else if (iresult == PKT_ALIAS_UNRESOLVED_FRAGMENT) {
|
||||
nb = ntohs(((struct ip *) tunbuff)->ip_len);
|
||||
fptr = malloc(nb);
|
||||
if (fptr == NULL)
|
||||
LogPrintf(LogALERT, "IpInput: Cannot allocate memory for fragment\n");
|
||||
LogPrintf(LogALERT, "IpInput: Cannot allocate memory for fragment\n");
|
||||
else {
|
||||
memcpy(fptr, tunbuff, nb);
|
||||
VarSaveFragmentPtr(fptr);
|
||||
memcpy(fptr, tunbuff, nb);
|
||||
VarPacketAliasSaveFragment(fptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* no aliasing */
|
||||
if ( PacketCheck(tunbuff, nb, FL_IN ) < 0)
|
||||
{
|
||||
} else { /* no aliasing */
|
||||
if (PacketCheck(tunbuff, nb, FL_IN) < 0) {
|
||||
pfree(bp);
|
||||
return;
|
||||
}
|
||||
|
||||
ipInOctets += nb;
|
||||
nw = write(tun_out, tunbuff, nb);
|
||||
if (nw != nb)
|
||||
@ -430,13 +418,10 @@ struct mbuf *bp; /* IN: Pointer to IP pakcet */
|
||||
RestartIdleTimer();
|
||||
}
|
||||
|
||||
static struct mqueue IpOutputQueues[PRI_FAST+1];
|
||||
static struct mqueue IpOutputQueues[PRI_FAST + 1];
|
||||
|
||||
void
|
||||
IpEnqueue(pri, ptr, count)
|
||||
int pri;
|
||||
char *ptr;
|
||||
int count;
|
||||
IpEnqueue(int pri, char *ptr, int count)
|
||||
{
|
||||
struct mbuf *bp;
|
||||
|
||||
@ -449,14 +434,15 @@ int
|
||||
IsIpEnqueued()
|
||||
{
|
||||
struct mqueue *queue;
|
||||
int exist = FALSE;
|
||||
int exist = FALSE;
|
||||
|
||||
for (queue = &IpOutputQueues[PRI_FAST]; queue >= IpOutputQueues; queue--) {
|
||||
if ( queue->qlen > 0 ) {
|
||||
exist = TRUE;
|
||||
break;
|
||||
}
|
||||
if (queue->qlen > 0) {
|
||||
exist = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return( exist );
|
||||
return (exist);
|
||||
}
|
||||
|
||||
void
|
||||
@ -477,7 +463,7 @@ IpStartOutput()
|
||||
RestartIdleTimer();
|
||||
ipOutOctets += cnt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,13 +17,14 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: ip.h,v 1.3 1997/02/22 16:10:19 peter Exp $
|
||||
* $Id: ip.h,v 1.4 1997/06/09 03:27:23 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _IP_H_
|
||||
#define _IP_H_
|
||||
extern void IpStartOutput(void);
|
||||
extern int PacketCheck(char *, int , int);
|
||||
extern int PacketCheck(char *, int, int);
|
||||
extern void IpEnqueue(int, char *, int);
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: ipcp.c,v 1.24 1997/08/19 01:10:20 brian Exp $
|
||||
* $Id: ipcp.c,v 1.25 1997/08/20 23:47:44 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o More RFC1772 backwoard compatibility
|
||||
@ -48,6 +48,7 @@ int HaveTriggerAddress;
|
||||
|
||||
#ifndef NOMSEXT
|
||||
struct in_addr ns_entries[2], nbns_entries[2];
|
||||
|
||||
#endif
|
||||
|
||||
static void IpcpSendConfigReq(struct fsm *);
|
||||
@ -75,8 +76,8 @@ struct fsm IpcpFsm = {
|
||||
0, 0, 0,
|
||||
|
||||
0,
|
||||
{ 0, 0, 0, NULL, NULL, NULL },
|
||||
{ 0, 0, 0, NULL, NULL, NULL },
|
||||
{0, 0, 0, NULL, NULL, NULL},
|
||||
{0, 0, 0, NULL, NULL, NULL},
|
||||
LogIPCP,
|
||||
|
||||
IpcpLayerUp,
|
||||
@ -132,19 +133,19 @@ ReportIpcpStatus()
|
||||
return 1;
|
||||
fprintf(VarTerm, "%s [%s]\n", fp->name, StateNames[fp->state]);
|
||||
fprintf(VarTerm, " his side: %s, %lx\n",
|
||||
inet_ntoa(icp->his_ipaddr), icp->his_compproto);
|
||||
inet_ntoa(icp->his_ipaddr), icp->his_compproto);
|
||||
fprintf(VarTerm, " my side: %s, %lx\n",
|
||||
inet_ntoa(icp->want_ipaddr), icp->want_compproto);
|
||||
inet_ntoa(icp->want_ipaddr), icp->want_compproto);
|
||||
fprintf(VarTerm, "connected: %d secs, idle: %d secs\n\n", ipConnectSecs, ipIdleSecs);
|
||||
fprintf(VarTerm, "Defaults:\n");
|
||||
fprintf(VarTerm, " My Address: %s/%d\n",
|
||||
inet_ntoa(DefMyAddress.ipaddr), DefMyAddress.width);
|
||||
inet_ntoa(DefMyAddress.ipaddr), DefMyAddress.width);
|
||||
fprintf(VarTerm, " His Address: %s/%d\n",
|
||||
inet_ntoa(DefHisAddress.ipaddr), DefHisAddress.width);
|
||||
inet_ntoa(DefHisAddress.ipaddr), DefHisAddress.width);
|
||||
if (HaveTriggerAddress)
|
||||
fprintf(VarTerm, " Negotiation(trigger): %s\n", inet_ntoa(TriggerAddress));
|
||||
fprintf(VarTerm, " Negotiation(trigger): %s\n", inet_ntoa(TriggerAddress));
|
||||
else
|
||||
fprintf(VarTerm, " Negotiation(trigger): MYADDR\n");
|
||||
fprintf(VarTerm, " Negotiation(trigger): MYADDR\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -160,10 +161,10 @@ IpcpDefAddress()
|
||||
TriggerAddress.s_addr = 0;
|
||||
HaveTriggerAddress = 0;
|
||||
if (gethostname(name, sizeof(name)) == 0) {
|
||||
hp = gethostbyname(name);
|
||||
if (hp && hp->h_addrtype == AF_INET) {
|
||||
bcopy(hp->h_addr, (char *)&DefMyAddress.ipaddr.s_addr, hp->h_length);
|
||||
}
|
||||
hp = gethostbyname(name);
|
||||
if (hp && hp->h_addrtype == AF_INET) {
|
||||
bcopy(hp->h_addr, (char *) &DefMyAddress.ipaddr.s_addr, hp->h_length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,16 +183,14 @@ IpcpInit()
|
||||
}
|
||||
|
||||
/*
|
||||
* Some implementation of PPP are:
|
||||
* Starting a negotiaion by require sending *special* value as my address,
|
||||
* even though standard of PPP is defined full negotiation based.
|
||||
* (e.g. "0.0.0.0" or Not "0.0.0.0")
|
||||
* Some implementation of PPP are: Starting a negotiaion by require sending
|
||||
* *special* value as my address, even though standard of PPP is defined
|
||||
* full negotiation based. (e.g. "0.0.0.0" or Not "0.0.0.0")
|
||||
*/
|
||||
if (HaveTriggerAddress) {
|
||||
icp->want_ipaddr.s_addr = TriggerAddress.s_addr;
|
||||
LogPrintf(LogIPCP, "Using trigger address %s\n", inet_ntoa(TriggerAddress));
|
||||
}
|
||||
|
||||
if (Enabled(ConfVjcomp))
|
||||
icp->want_compproto = (PROTO_VJCOMP << 16) | ((MAX_STATES - 1) << 8);
|
||||
else
|
||||
@ -201,16 +200,14 @@ IpcpInit()
|
||||
}
|
||||
|
||||
static void
|
||||
IpcpInitRestartCounter(fp)
|
||||
struct fsm *fp;
|
||||
IpcpInitRestartCounter(struct fsm * fp)
|
||||
{
|
||||
fp->FsmTimer.load = VarRetryTimeout * SECTICKS;
|
||||
fp->restart = 5;
|
||||
}
|
||||
|
||||
static void
|
||||
IpcpSendConfigReq(fp)
|
||||
struct fsm *fp;
|
||||
IpcpSendConfigReq(struct fsm * fp)
|
||||
{
|
||||
u_char *cp;
|
||||
struct ipcpstate *icp = &IpcpInfo;
|
||||
@ -229,30 +226,26 @@ struct fsm *fp;
|
||||
}
|
||||
|
||||
static void
|
||||
IpcpSendTerminateReq(fp)
|
||||
struct fsm *fp;
|
||||
IpcpSendTerminateReq(struct fsm * fp)
|
||||
{
|
||||
/* XXX: No code yet */
|
||||
}
|
||||
|
||||
static void
|
||||
IpcpSendTerminateAck(fp)
|
||||
struct fsm *fp;
|
||||
IpcpSendTerminateAck(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogIPCP, "IpcpSendTerminateAck\n");
|
||||
FsmOutput(fp, CODE_TERMACK, fp->reqid++, NULL, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
IpcpLayerStart(fp)
|
||||
struct fsm *fp;
|
||||
IpcpLayerStart(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogIPCP, "IpcpLayerStart.\n");
|
||||
}
|
||||
|
||||
static void
|
||||
IpcpLayerFinish(fp)
|
||||
struct fsm *fp;
|
||||
IpcpLayerFinish(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogIPCP, "IpcpLayerFinish.\n");
|
||||
reconnect(RECON_FALSE);
|
||||
@ -261,8 +254,7 @@ struct fsm *fp;
|
||||
}
|
||||
|
||||
static void
|
||||
IpcpLayerDown(fp)
|
||||
struct fsm *fp;
|
||||
IpcpLayerDown(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogIPCP, "IpcpLayerDown.\n");
|
||||
StopTimer(&IpcpReportTimer);
|
||||
@ -272,24 +264,23 @@ struct fsm *fp;
|
||||
* Called when IPCP has reached to OPEN state
|
||||
*/
|
||||
static void
|
||||
IpcpLayerUp(fp)
|
||||
struct fsm *fp;
|
||||
IpcpLayerUp(struct fsm * fp)
|
||||
{
|
||||
char tbuff[100];
|
||||
|
||||
Prompt();
|
||||
LogPrintf(LogIPCP, "IpcpLayerUp(%d).\n", fp->state);
|
||||
snprintf(tbuff, sizeof(tbuff), "myaddr = %s ",
|
||||
inet_ntoa(IpcpInfo.want_ipaddr));
|
||||
snprintf(tbuff, sizeof(tbuff), "myaddr = %s ",
|
||||
inet_ntoa(IpcpInfo.want_ipaddr));
|
||||
LogPrintf(LogIsKept(LogIPCP) ? LogIPCP : LogLINK, " %s hisaddr = %s\n",
|
||||
tbuff, inet_ntoa(IpcpInfo.his_ipaddr));
|
||||
tbuff, inet_ntoa(IpcpInfo.his_ipaddr));
|
||||
if (OsSetIpaddress(IpcpInfo.want_ipaddr, IpcpInfo.his_ipaddr, ifnetmask) < 0) {
|
||||
if (VarTerm)
|
||||
LogPrintf(LogERROR, "IpcpLayerUp: unable to set ip address\n");
|
||||
return;
|
||||
}
|
||||
if (mode & MODE_ALIAS)
|
||||
VarSetPacketAliasAddress(IpcpInfo.want_ipaddr);
|
||||
VarPacketAliasSetAddress(IpcpInfo.want_ipaddr);
|
||||
OsLinkup();
|
||||
IpcpStartReport();
|
||||
StartIdleTimer();
|
||||
@ -309,24 +300,19 @@ IpcpOpen()
|
||||
}
|
||||
|
||||
static int
|
||||
AcceptableAddr(prange, ipaddr)
|
||||
struct in_range *prange;
|
||||
struct in_addr ipaddr;
|
||||
AcceptableAddr(struct in_range * prange, struct in_addr ipaddr)
|
||||
{
|
||||
LogPrintf(LogDEBUG, "requested = %x ", htonl(ipaddr.s_addr));
|
||||
LogPrintf(LogDEBUG, "range = %x", htonl(prange->ipaddr.s_addr));
|
||||
LogPrintf(LogDEBUG, "/%x\n", htonl(prange->mask.s_addr));
|
||||
LogPrintf(LogDEBUG, "%x, %x\n", htonl(prange->ipaddr.s_addr & prange->
|
||||
mask.s_addr), htonl(ipaddr.s_addr & prange->mask.s_addr));
|
||||
mask.s_addr), htonl(ipaddr.s_addr & prange->mask.s_addr));
|
||||
return (prange->ipaddr.s_addr & prange->mask.s_addr) ==
|
||||
(ipaddr.s_addr & prange->mask.s_addr) && ipaddr.s_addr;
|
||||
(ipaddr.s_addr & prange->mask.s_addr) && ipaddr.s_addr;
|
||||
}
|
||||
|
||||
static void
|
||||
IpcpDecodeConfig(cp, plen, mode)
|
||||
u_char *cp;
|
||||
int plen;
|
||||
int mode;
|
||||
IpcpDecodeConfig(u_char * cp, int plen, int mode)
|
||||
{
|
||||
int type, length;
|
||||
u_long *lp, compproto;
|
||||
@ -351,21 +337,22 @@ int mode;
|
||||
|
||||
switch (type) {
|
||||
case TY_IPADDR: /* RFC1332 */
|
||||
lp = (u_long *)(cp + 2);
|
||||
lp = (u_long *) (cp + 2);
|
||||
ipaddr.s_addr = *lp;
|
||||
LogPrintf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
|
||||
|
||||
switch (mode) {
|
||||
case MODE_REQ:
|
||||
if (!AcceptableAddr(&DefHisAddress, ipaddr)) {
|
||||
/*
|
||||
* If destination address is not acceptable, insist to use
|
||||
* what we want to use.
|
||||
*/
|
||||
|
||||
/*
|
||||
* If destination address is not acceptable, insist to use what we
|
||||
* want to use.
|
||||
*/
|
||||
bcopy(cp, nakp, 2);
|
||||
bcopy(&IpcpInfo.his_ipaddr.s_addr, nakp+2, length);
|
||||
nakp += length;
|
||||
break;
|
||||
bcopy(&IpcpInfo.his_ipaddr.s_addr, nakp + 2, length);
|
||||
nakp += length;
|
||||
break;
|
||||
|
||||
}
|
||||
IpcpInfo.his_ipaddr = ipaddr;
|
||||
@ -374,9 +361,10 @@ int mode;
|
||||
break;
|
||||
case MODE_NAK:
|
||||
if (AcceptableAddr(&DefMyAddress, ipaddr)) {
|
||||
/*
|
||||
* Use address suggested by peer.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Use address suggested by peer.
|
||||
*/
|
||||
snprintf(tbuff2, sizeof(tbuff2), "%s changing address: %s ", tbuff, inet_ntoa(IpcpInfo.want_ipaddr));
|
||||
LogPrintf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
|
||||
IpcpInfo.want_ipaddr = ipaddr;
|
||||
@ -388,7 +376,7 @@ int mode;
|
||||
}
|
||||
break;
|
||||
case TY_COMPPROTO:
|
||||
lp = (u_long *)(cp + 2);
|
||||
lp = (u_long *) (cp + 2);
|
||||
compproto = htonl(*lp);
|
||||
LogPrintf(LogIPCP, "%s %08x\n", tbuff, compproto);
|
||||
|
||||
@ -398,9 +386,9 @@ int mode;
|
||||
bcopy(cp, rejp, length);
|
||||
rejp += length;
|
||||
} else {
|
||||
pcomp = (struct compreq *)(cp + 2);
|
||||
pcomp = (struct compreq *) (cp + 2);
|
||||
switch (length) {
|
||||
case 4: /* RFC1172 */
|
||||
case 4: /* RFC1172 */
|
||||
if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
|
||||
LogPrintf(LogWARN, "Peer is speaking RFC1172 compression protocol !\n");
|
||||
IpcpInfo.heis1172 = 1;
|
||||
@ -414,9 +402,9 @@ int mode;
|
||||
nakp += length;
|
||||
}
|
||||
break;
|
||||
case 6: /* RFC1332 */
|
||||
case 6: /* RFC1332 */
|
||||
if (ntohs(pcomp->proto) == PROTO_VJCOMP
|
||||
&& pcomp->slots < MAX_STATES && pcomp->slots > 2) {
|
||||
&& pcomp->slots < MAX_STATES && pcomp->slots > 2) {
|
||||
IpcpInfo.his_compproto = compproto;
|
||||
IpcpInfo.heis1172 = 0;
|
||||
bcopy(cp, ackp, length);
|
||||
@ -439,7 +427,7 @@ int mode;
|
||||
break;
|
||||
case MODE_NAK:
|
||||
LogPrintf(LogIPCP, "%s changing compproto: %08x --> %08x\n",
|
||||
tbuff, IpcpInfo.want_compproto, compproto);
|
||||
tbuff, IpcpInfo.want_compproto, compproto);
|
||||
IpcpInfo.want_compproto = compproto;
|
||||
break;
|
||||
case MODE_REJ:
|
||||
@ -447,10 +435,10 @@ int mode;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TY_IPADDRS: /* RFC1172 */
|
||||
lp = (u_long *)(cp + 2);
|
||||
case TY_IPADDRS: /* RFC1172 */
|
||||
lp = (u_long *) (cp + 2);
|
||||
ipaddr.s_addr = *lp;
|
||||
lp = (u_long *)(cp + 6);
|
||||
lp = (u_long *) (cp + 6);
|
||||
dstipaddr.s_addr = *lp;
|
||||
LogPrintf(LogIPCP, "%s %s, ", tbuff, inet_ntoa(ipaddr));
|
||||
LogPrintf(LogIPCP, "%s\n", inet_ntoa(dstipaddr));
|
||||
@ -464,7 +452,7 @@ int mode;
|
||||
break;
|
||||
case MODE_NAK:
|
||||
LogPrintf(LogIPCP, "%s changing address: %s ",
|
||||
tbuff, inet_ntoa(IpcpInfo.want_ipaddr));
|
||||
tbuff, inet_ntoa(IpcpInfo.want_ipaddr));
|
||||
LogPrintf(LogIPCP, "--> %s\n", inet_ntoa(ipaddr));
|
||||
IpcpInfo.want_ipaddr = ipaddr;
|
||||
IpcpInfo.his_ipaddr = dstipaddr;
|
||||
@ -475,95 +463,95 @@ int mode;
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* MS extensions for MS's PPP
|
||||
*/
|
||||
/*
|
||||
* MS extensions for MS's PPP
|
||||
*/
|
||||
|
||||
#ifndef NOMSEXT
|
||||
case TY_PRIMARY_DNS: /* MS PPP DNS negotiation hack */
|
||||
case TY_PRIMARY_DNS: /* MS PPP DNS negotiation hack */
|
||||
case TY_SECONDARY_DNS:
|
||||
if( !Enabled( ConfMSExt ) ) {
|
||||
if (!Enabled(ConfMSExt)) {
|
||||
LogPrintf(LogIPCP, "MS NS req - rejected - msext disabled\n");
|
||||
IpcpInfo.my_reject |= ( 1 << type );
|
||||
IpcpInfo.my_reject |= (1 << type);
|
||||
bcopy(cp, rejp, length);
|
||||
rejp += length;
|
||||
break;
|
||||
}
|
||||
switch( mode ){
|
||||
switch (mode) {
|
||||
case MODE_REQ:
|
||||
lp = (u_long *)(cp + 2);
|
||||
lp = (u_long *) (cp + 2);
|
||||
dnsstuff.s_addr = *lp;
|
||||
ms_info_req.s_addr = ns_entries[((type - TY_PRIMARY_DNS)?1:0)].s_addr;
|
||||
if( dnsstuff.s_addr != ms_info_req.s_addr )
|
||||
{
|
||||
ms_info_req.s_addr = ns_entries[((type - TY_PRIMARY_DNS) ? 1 : 0)].s_addr;
|
||||
if (dnsstuff.s_addr != ms_info_req.s_addr) {
|
||||
|
||||
/*
|
||||
So the client has got the DNS stuff wrong (first request)
|
||||
so well tell 'em how it is
|
||||
*/
|
||||
bcopy( cp, nakp, 2 ); /* copy first two (type/length) */
|
||||
LogPrintf( LogIPCP, "MS NS req %d:%s->%s - nak\n",
|
||||
type,
|
||||
inet_ntoa( dnsstuff ),
|
||||
inet_ntoa( ms_info_req ));
|
||||
bcopy( &ms_info_req, nakp+2, length );
|
||||
* So the client has got the DNS stuff wrong (first request) so
|
||||
* well tell 'em how it is
|
||||
*/
|
||||
bcopy(cp, nakp, 2); /* copy first two (type/length) */
|
||||
LogPrintf(LogIPCP, "MS NS req %d:%s->%s - nak\n",
|
||||
type,
|
||||
inet_ntoa(dnsstuff),
|
||||
inet_ntoa(ms_info_req));
|
||||
bcopy(&ms_info_req, nakp + 2, length);
|
||||
nakp += length;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
Otherwise they have it right (this time) so we send
|
||||
a ack packet back confirming it... end of story
|
||||
*/
|
||||
LogPrintf( LogIPCP, "MS NS req %d:%s ok - ack\n",
|
||||
type,
|
||||
inet_ntoa( ms_info_req ));
|
||||
bcopy( cp, ackp, length );
|
||||
|
||||
/*
|
||||
* Otherwise they have it right (this time) so we send a ack packet
|
||||
* back confirming it... end of story
|
||||
*/
|
||||
LogPrintf(LogIPCP, "MS NS req %d:%s ok - ack\n",
|
||||
type,
|
||||
inet_ntoa(ms_info_req));
|
||||
bcopy(cp, ackp, length);
|
||||
ackp += length;
|
||||
break;
|
||||
case MODE_NAK: /* what does this mean?? */
|
||||
LogPrintf(LogIPCP, "MS NS req %d - NAK??\n", type );
|
||||
case MODE_NAK: /* what does this mean?? */
|
||||
LogPrintf(LogIPCP, "MS NS req %d - NAK??\n", type);
|
||||
break;
|
||||
case MODE_REJ: /* confused?? me to :) */
|
||||
LogPrintf(LogIPCP, "MS NS req %d - REJ??\n", type );
|
||||
case MODE_REJ: /* confused?? me to :) */
|
||||
LogPrintf(LogIPCP, "MS NS req %d - REJ??\n", type);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case TY_PRIMARY_NBNS: /* MS PPP NetBIOS nameserver hack */
|
||||
case TY_PRIMARY_NBNS: /* MS PPP NetBIOS nameserver hack */
|
||||
case TY_SECONDARY_NBNS:
|
||||
if( !Enabled( ConfMSExt ) ) {
|
||||
LogPrintf( LogIPCP, "MS NBNS req - rejected - msext disabled\n" );
|
||||
IpcpInfo.my_reject |= ( 1 << type );
|
||||
bcopy( cp, rejp, length );
|
||||
rejp += length;
|
||||
break;
|
||||
}
|
||||
switch( mode ){
|
||||
if (!Enabled(ConfMSExt)) {
|
||||
LogPrintf(LogIPCP, "MS NBNS req - rejected - msext disabled\n");
|
||||
IpcpInfo.my_reject |= (1 << type);
|
||||
bcopy(cp, rejp, length);
|
||||
rejp += length;
|
||||
break;
|
||||
}
|
||||
switch (mode) {
|
||||
case MODE_REQ:
|
||||
lp = (u_long *)(cp + 2);
|
||||
lp = (u_long *) (cp + 2);
|
||||
dnsstuff.s_addr = *lp;
|
||||
ms_info_req.s_addr = nbns_entries[((type - TY_PRIMARY_NBNS)?1:0)].s_addr;
|
||||
if( dnsstuff.s_addr != ms_info_req.s_addr )
|
||||
{
|
||||
bcopy( cp, nakp, 2 );
|
||||
bcopy( &ms_info_req.s_addr , nakp+2, length );
|
||||
ms_info_req.s_addr = nbns_entries[((type - TY_PRIMARY_NBNS) ? 1 : 0)].s_addr;
|
||||
if (dnsstuff.s_addr != ms_info_req.s_addr) {
|
||||
bcopy(cp, nakp, 2);
|
||||
bcopy(&ms_info_req.s_addr, nakp + 2, length);
|
||||
LogPrintf(LogIPCP, "MS NBNS req %d:%s->%s - nak\n",
|
||||
type,
|
||||
inet_ntoa( dnsstuff ),
|
||||
inet_ntoa( ms_info_req ));
|
||||
type,
|
||||
inet_ntoa(dnsstuff),
|
||||
inet_ntoa(ms_info_req));
|
||||
nakp += length;
|
||||
break;
|
||||
}
|
||||
LogPrintf(LogIPCP, "MS NBNS req %d:%s ok - ack\n",
|
||||
type,
|
||||
inet_ntoa( ms_info_req ));
|
||||
bcopy( cp, ackp, length );
|
||||
type,
|
||||
inet_ntoa(ms_info_req));
|
||||
bcopy(cp, ackp, length);
|
||||
ackp += length;
|
||||
break;
|
||||
case MODE_NAK:
|
||||
LogPrintf(LogIPCP, "MS NBNS req %d - NAK??\n", type );
|
||||
LogPrintf(LogIPCP, "MS NBNS req %d - NAK??\n", type);
|
||||
break;
|
||||
case MODE_REJ:
|
||||
LogPrintf(LogIPCP, "MS NBNS req %d - REJ??\n", type );
|
||||
LogPrintf(LogIPCP, "MS NBNS req %d - REJ??\n", type);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -582,7 +570,7 @@ int mode;
|
||||
}
|
||||
|
||||
void
|
||||
IpcpInput(struct mbuf *bp)
|
||||
IpcpInput(struct mbuf * bp)
|
||||
{
|
||||
FsmInput(&IpcpFsm, bp);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: ipcp.h,v 1.7 1997/06/09 03:27:24 brian Exp $
|
||||
* $Id: ipcp.h,v 1.8 1997/08/19 01:10:22 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -39,27 +39,27 @@
|
||||
#endif
|
||||
|
||||
struct ipcpstate {
|
||||
struct in_addr his_ipaddr; /* IP address he is willing to use */
|
||||
u_long his_compproto;
|
||||
struct in_addr his_ipaddr; /* IP address he is willing to use */
|
||||
u_long his_compproto;
|
||||
|
||||
struct in_addr want_ipaddr; /* IP address I'm willing to use */
|
||||
u_long want_compproto;
|
||||
struct in_addr want_ipaddr; /* IP address I'm willing to use */
|
||||
u_long want_compproto;
|
||||
|
||||
u_long his_reject; /* Request codes rejected by peer */
|
||||
u_long my_reject; /* Request codes I have rejected */
|
||||
int heis1172; /* True if he is speaking rfc1172 */
|
||||
u_long his_reject; /* Request codes rejected by peer */
|
||||
u_long my_reject; /* Request codes I have rejected */
|
||||
int heis1172; /* True if he is speaking rfc1172 */
|
||||
};
|
||||
|
||||
struct compreq {
|
||||
u_short proto;
|
||||
u_char slots;
|
||||
u_char compcid;
|
||||
u_char slots;
|
||||
u_char compcid;
|
||||
};
|
||||
|
||||
struct in_range {
|
||||
struct in_addr ipaddr;
|
||||
struct in_addr mask;
|
||||
int width;
|
||||
int width;
|
||||
};
|
||||
|
||||
extern struct ipcpstate IpcpInfo;
|
||||
@ -71,8 +71,10 @@ extern int HaveTriggerAddress;
|
||||
#ifndef NOMSEXT
|
||||
extern struct in_addr ns_entries[2];
|
||||
extern struct in_addr nbns_entries[2];
|
||||
|
||||
#endif
|
||||
|
||||
extern void IpcpInit(void);
|
||||
extern void IpcpDefAddress(void);
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: lcp.c,v 1.25 1997/08/01 02:02:28 brian Exp $
|
||||
* $Id: lcp.c,v 1.26 1997/08/20 23:47:45 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Validate magic number received from peer.
|
||||
@ -51,9 +51,9 @@ extern int randinit;
|
||||
struct lcpstate LcpInfo;
|
||||
|
||||
static void LcpSendConfigReq(struct fsm *);
|
||||
static void LcpSendTerminateReq(struct fsm *fp);
|
||||
static void LcpSendTerminateAck(struct fsm *fp);
|
||||
static void LcpDecodeConfig(u_char *cp, int flen,int mode);
|
||||
static void LcpSendTerminateReq(struct fsm * fp);
|
||||
static void LcpSendTerminateAck(struct fsm * fp);
|
||||
static void LcpDecodeConfig(u_char * cp, int flen, int mode);
|
||||
static void LcpInitRestartCounter(struct fsm *);
|
||||
static void LcpLayerUp(struct fsm *);
|
||||
static void LcpLayerDown(struct fsm *);
|
||||
@ -77,8 +77,8 @@ struct fsm LcpFsm = {
|
||||
ST_INITIAL, /* State of machine */
|
||||
0, 0, 0,
|
||||
0,
|
||||
{ 0, 0, 0, NULL, NULL, NULL },
|
||||
{ 0, 0, 0, NULL, NULL, NULL },
|
||||
{0, 0, 0, NULL, NULL, NULL},
|
||||
{0, 0, 0, NULL, NULL, NULL},
|
||||
LogLCP,
|
||||
|
||||
LcpLayerUp,
|
||||
@ -99,8 +99,7 @@ char *PhaseNames[] = {
|
||||
};
|
||||
|
||||
void
|
||||
NewPhase(new)
|
||||
int new;
|
||||
NewPhase(int new)
|
||||
{
|
||||
struct lcpstate *lcp = &LcpInfo;
|
||||
|
||||
@ -159,18 +158,18 @@ ReportLcpStatus()
|
||||
return 1;
|
||||
|
||||
fprintf(VarTerm, "%s [%s]\n", fp->name, StateNames[fp->state]);
|
||||
fprintf(VarTerm,
|
||||
" his side: MRU %ld, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d, MAGIC %08lx,\n"
|
||||
" REJECT %04lx\n",
|
||||
lcp->his_mru, lcp->his_accmap, lcp->his_protocomp, lcp->his_acfcomp,
|
||||
lcp->his_magic, lcp->his_reject);
|
||||
fprintf(VarTerm,
|
||||
" my side: MRU %ld, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d, MAGIC %08lx,\n"
|
||||
" REJECT %04lx\n",
|
||||
fprintf(VarTerm,
|
||||
" his side: MRU %ld, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d, MAGIC %08lx,\n"
|
||||
" REJECT %04lx\n",
|
||||
lcp->his_mru, lcp->his_accmap, lcp->his_protocomp, lcp->his_acfcomp,
|
||||
lcp->his_magic, lcp->his_reject);
|
||||
fprintf(VarTerm,
|
||||
" my side: MRU %ld, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d, MAGIC %08lx,\n"
|
||||
" REJECT %04lx\n",
|
||||
lcp->want_mru, lcp->want_accmap, lcp->want_protocomp, lcp->want_acfcomp,
|
||||
lcp->want_magic, lcp->my_reject);
|
||||
lcp->want_magic, lcp->my_reject);
|
||||
fprintf(VarTerm, "\nDefaults: MRU = %ld, ACCMAP = %08x\t", VarMRU, VarAccmap);
|
||||
fprintf(VarTerm, "Open Mode: %s\n", (VarOpenMode == OPEN_ACTIVE)? "active" : "passive");
|
||||
fprintf(VarTerm, "Open Mode: %s\n", (VarOpenMode == OPEN_ACTIVE) ? "active" : "passive");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -184,7 +183,6 @@ GenerateMagic()
|
||||
randinit = 1;
|
||||
srandomdev();
|
||||
}
|
||||
|
||||
return (random());
|
||||
}
|
||||
|
||||
@ -207,38 +205,36 @@ LcpInit()
|
||||
lcp->want_auth = PROTO_CHAP;
|
||||
else if (Enabled(ConfPap))
|
||||
lcp->want_auth = PROTO_PAP;
|
||||
if (Enabled(ConfLqr)) lcp->want_lqrperiod = VarLqrTimeout * 100;
|
||||
if (Enabled(ConfAcfcomp)) lcp->want_acfcomp = 1;
|
||||
if (Enabled(ConfProtocomp)) lcp->want_protocomp = 1;
|
||||
if (Enabled(ConfLqr))
|
||||
lcp->want_lqrperiod = VarLqrTimeout * 100;
|
||||
if (Enabled(ConfAcfcomp))
|
||||
lcp->want_acfcomp = 1;
|
||||
if (Enabled(ConfProtocomp))
|
||||
lcp->want_protocomp = 1;
|
||||
LcpFsm.maxconfig = 10;
|
||||
}
|
||||
|
||||
static void
|
||||
LcpInitRestartCounter(fp)
|
||||
struct fsm *fp;
|
||||
LcpInitRestartCounter(struct fsm * fp)
|
||||
{
|
||||
fp->FsmTimer.load = VarRetryTimeout * SECTICKS;
|
||||
fp->restart = 5;
|
||||
}
|
||||
|
||||
void
|
||||
PutConfValue(cpp, types, type, len, val)
|
||||
u_char **cpp;
|
||||
char **types;
|
||||
u_char type;
|
||||
int len;
|
||||
u_long val;
|
||||
PutConfValue(u_char ** cpp, char **types, u_char type, int len, u_long val)
|
||||
{
|
||||
u_char *cp;
|
||||
struct in_addr ina;
|
||||
|
||||
cp = *cpp;
|
||||
*cp++ = type; *cp++ = len;
|
||||
*cp++ = type;
|
||||
*cp++ = len;
|
||||
if (len == 6) {
|
||||
if (type == TY_IPADDR) {
|
||||
ina.s_addr = htonl(val);
|
||||
LogPrintf(LogLCP, " %s [%d] %s\n",
|
||||
types[type], len, inet_ntoa(ina));
|
||||
types[type], len, inet_ntoa(ina));
|
||||
} else {
|
||||
LogPrintf(LogLCP, " %s [%d] %08x\n", types[type], len, val);
|
||||
}
|
||||
@ -252,8 +248,7 @@ u_long val;
|
||||
}
|
||||
|
||||
static void
|
||||
LcpSendConfigReq(fp)
|
||||
struct fsm *fp;
|
||||
LcpSendConfigReq(struct fsm * fp)
|
||||
{
|
||||
u_char *cp;
|
||||
struct lcpstate *lcp = &LcpInfo;
|
||||
@ -263,11 +258,13 @@ struct fsm *fp;
|
||||
cp = ReqBuff;
|
||||
if (!DEV_IS_SYNC) {
|
||||
if (lcp->want_acfcomp && !REJECTED(lcp, TY_ACFCOMP)) {
|
||||
*cp++ = TY_ACFCOMP; *cp++ = 2;
|
||||
*cp++ = TY_ACFCOMP;
|
||||
*cp++ = 2;
|
||||
LogPrintf(LogLCP, " %s\n", cftypes[TY_ACFCOMP]);
|
||||
}
|
||||
if (lcp->want_protocomp && !REJECTED(lcp, TY_PROTOCOMP)) {
|
||||
*cp++ = TY_PROTOCOMP; *cp++ = 2;
|
||||
*cp++ = TY_PROTOCOMP;
|
||||
*cp++ = 2;
|
||||
LogPrintf(LogLCP, " %s\n", cftypes[TY_PROTOCOMP]);
|
||||
}
|
||||
if (!REJECTED(lcp, TY_ACCMAP))
|
||||
@ -278,8 +275,9 @@ struct fsm *fp;
|
||||
if (lcp->want_magic && !REJECTED(lcp, TY_MAGICNUM))
|
||||
PutConfValue(&cp, cftypes, TY_MAGICNUM, 6, lcp->want_magic);
|
||||
if (lcp->want_lqrperiod && !REJECTED(lcp, TY_QUALPROTO)) {
|
||||
req = (struct lqrreq *)cp;
|
||||
req->type = TY_QUALPROTO; req->length = sizeof(struct lqrreq);
|
||||
req = (struct lqrreq *) cp;
|
||||
req->type = TY_QUALPROTO;
|
||||
req->length = sizeof(struct lqrreq);
|
||||
req->proto = htons(PROTO_LQR);
|
||||
req->period = htonl(lcp->want_lqrperiod);
|
||||
cp += sizeof(struct lqrreq);
|
||||
@ -291,16 +289,14 @@ struct fsm *fp;
|
||||
break;
|
||||
case PROTO_CHAP:
|
||||
PutConfValue(&cp, cftypes, TY_AUTHPROTO, 5, lcp->want_auth);
|
||||
*cp++ = 5; /* Use MD5 */
|
||||
*cp++ = 5; /* Use MD5 */
|
||||
break;
|
||||
}
|
||||
FsmOutput(fp, CODE_CONFIGREQ, fp->reqid++, ReqBuff, cp - ReqBuff);
|
||||
}
|
||||
|
||||
void
|
||||
LcpSendProtoRej(option, count)
|
||||
u_char *option;
|
||||
int count;
|
||||
LcpSendProtoRej(u_char * option, int count)
|
||||
{
|
||||
struct fsm *fp = &LcpFsm;
|
||||
|
||||
@ -309,23 +305,20 @@ int count;
|
||||
}
|
||||
|
||||
static void
|
||||
LcpSendTerminateReq(fp)
|
||||
struct fsm *fp;
|
||||
LcpSendTerminateReq(struct fsm * fp)
|
||||
{
|
||||
/* Most thins are done in fsm layer. Nothing to to. */
|
||||
/* Most thins are done in fsm layer. Nothing to to. */
|
||||
}
|
||||
|
||||
static void
|
||||
LcpSendTerminateAck(fp)
|
||||
struct fsm *fp;
|
||||
LcpSendTerminateAck(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogLCP, "LcpSendTerminateAck.\n");
|
||||
FsmOutput(fp, CODE_TERMACK, fp->reqid++, NULL, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
LcpLayerStart(fp)
|
||||
struct fsm *fp;
|
||||
LcpLayerStart(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogLCP, "LcpLayerStart\n");
|
||||
NewPhase(PHASE_ESTABLISH);
|
||||
@ -343,20 +336,18 @@ StopAllTimers()
|
||||
}
|
||||
|
||||
static void
|
||||
LcpLayerFinish(fp)
|
||||
struct fsm *fp;
|
||||
LcpLayerFinish(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogLCP, "LcpLayerFinish\n");
|
||||
OsCloseLink(1);
|
||||
NewPhase(PHASE_DEAD);
|
||||
StopAllTimers();
|
||||
(void)OsInterfaceDown(0);
|
||||
(void) OsInterfaceDown(0);
|
||||
Prompt();
|
||||
}
|
||||
|
||||
static void
|
||||
LcpLayerUp(fp)
|
||||
struct fsm *fp;
|
||||
LcpLayerUp(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogLCP, "LcpLayerUp\n");
|
||||
OsSetInterfaceParams(23, LcpInfo.his_mru, ModemSpeed());
|
||||
@ -373,8 +364,7 @@ struct fsm *fp;
|
||||
}
|
||||
|
||||
static void
|
||||
LcpLayerDown(fp)
|
||||
struct fsm *fp;
|
||||
LcpLayerDown(struct fsm * fp)
|
||||
{
|
||||
LogPrintf(LogLCP, "LcpLayerDown\n");
|
||||
StopAllTimers();
|
||||
@ -389,16 +379,15 @@ LcpUp()
|
||||
}
|
||||
|
||||
void
|
||||
LcpDown() /* Sudden death */
|
||||
{
|
||||
LcpDown()
|
||||
{ /* Sudden death */
|
||||
NewPhase(PHASE_DEAD);
|
||||
StopAllTimers();
|
||||
FsmDown(&LcpFsm);
|
||||
}
|
||||
|
||||
void
|
||||
LcpOpen(mode)
|
||||
int mode;
|
||||
LcpOpen(int mode)
|
||||
{
|
||||
LcpFsm.open_mode = mode;
|
||||
FsmOpen(&LcpFsm);
|
||||
@ -414,10 +403,7 @@ LcpClose()
|
||||
* XXX: Should validate option length
|
||||
*/
|
||||
static void
|
||||
LcpDecodeConfig(cp, plen, mode)
|
||||
u_char *cp;
|
||||
int plen;
|
||||
int mode;
|
||||
LcpDecodeConfig(u_char * cp, int plen, int mode)
|
||||
{
|
||||
char *request;
|
||||
int type, length, mru;
|
||||
@ -439,7 +425,7 @@ int mode;
|
||||
|
||||
switch (type) {
|
||||
case TY_MRU:
|
||||
sp = (u_short *)(cp + 2);
|
||||
sp = (u_short *) (cp + 2);
|
||||
mru = htons(*sp);
|
||||
LogPrintf(LogLCP, " %s %d\n", request, mru);
|
||||
|
||||
@ -447,13 +433,16 @@ int mode;
|
||||
case MODE_REQ:
|
||||
if (mru > MAX_MRU) {
|
||||
*sp = htons(MAX_MRU);
|
||||
bcopy(cp, nakp, 4); nakp += 4;
|
||||
bcopy(cp, nakp, 4);
|
||||
nakp += 4;
|
||||
} else if (mru < MIN_MRU) {
|
||||
*sp = htons(MIN_MRU);
|
||||
bcopy(cp, nakp, 4); nakp += 4;
|
||||
bcopy(cp, nakp, 4);
|
||||
nakp += 4;
|
||||
} else {
|
||||
LcpInfo.his_mru = mru;
|
||||
bcopy(cp, ackp, 4); ackp += 4;
|
||||
bcopy(cp, ackp, 4);
|
||||
ackp += 4;
|
||||
}
|
||||
break;
|
||||
case MODE_NAK:
|
||||
@ -466,14 +455,15 @@ int mode;
|
||||
}
|
||||
break;
|
||||
case TY_ACCMAP:
|
||||
lp = (u_long *)(cp + 2);
|
||||
lp = (u_long *) (cp + 2);
|
||||
accmap = htonl(*lp);
|
||||
LogPrintf(LogLCP, " %s %08x\n", request, accmap);
|
||||
|
||||
switch (mode) {
|
||||
case MODE_REQ:
|
||||
LcpInfo.his_accmap = accmap;
|
||||
bcopy(cp, ackp, 6); ackp += 6;
|
||||
bcopy(cp, ackp, 6);
|
||||
ackp += 6;
|
||||
break;
|
||||
case MODE_NAK:
|
||||
LcpInfo.want_accmap = accmap;
|
||||
@ -484,7 +474,7 @@ int mode;
|
||||
}
|
||||
break;
|
||||
case TY_AUTHPROTO:
|
||||
sp = (u_short *)(cp + 2);
|
||||
sp = (u_short *) (cp + 2);
|
||||
proto = ntohs(*sp);
|
||||
LogPrintf(LogLCP, " %s proto = %04x\n", request, proto);
|
||||
|
||||
@ -498,11 +488,13 @@ int mode;
|
||||
}
|
||||
if (Acceptable(ConfPap)) {
|
||||
LcpInfo.his_auth = proto;
|
||||
bcopy(cp, ackp, length); ackp += length;
|
||||
bcopy(cp, ackp, length);
|
||||
ackp += length;
|
||||
} else if (Acceptable(ConfChap)) {
|
||||
*nakp++ = *cp; *nakp++ = 5;
|
||||
*nakp++ = (unsigned char)(PROTO_CHAP >> 8);
|
||||
*nakp++ = (unsigned char)PROTO_CHAP;
|
||||
*nakp++ = *cp;
|
||||
*nakp++ = 5;
|
||||
*nakp++ = (unsigned char) (PROTO_CHAP >> 8);
|
||||
*nakp++ = (unsigned char) PROTO_CHAP;
|
||||
*nakp++ = 5;
|
||||
} else
|
||||
goto reqreject;
|
||||
@ -514,19 +506,21 @@ int mode;
|
||||
}
|
||||
if (Acceptable(ConfChap) && cp[4] == 5) {
|
||||
LcpInfo.his_auth = proto;
|
||||
bcopy(cp, ackp, length); ackp += length;
|
||||
bcopy(cp, ackp, length);
|
||||
ackp += length;
|
||||
} else if (Acceptable(ConfPap)) {
|
||||
*nakp++ = *cp; *nakp++ = 4;
|
||||
*nakp++ = (unsigned char)(PROTO_PAP >> 8);
|
||||
*nakp++ = (unsigned char)PROTO_PAP;
|
||||
*nakp++ = *cp;
|
||||
*nakp++ = 4;
|
||||
*nakp++ = (unsigned char) (PROTO_PAP >> 8);
|
||||
*nakp++ = (unsigned char) PROTO_PAP;
|
||||
} else
|
||||
goto reqreject;
|
||||
break;
|
||||
default:
|
||||
LogPrintf(LogLCP, " %s not implemented, NAK.\n", request);
|
||||
bcopy(cp, nakp, length);
|
||||
nakp += length;
|
||||
break;
|
||||
LogPrintf(LogLCP, " %s not implemented, NAK.\n", request);
|
||||
bcopy(cp, nakp, length);
|
||||
nakp += length;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case MODE_NAK:
|
||||
@ -537,9 +531,9 @@ int mode;
|
||||
}
|
||||
break;
|
||||
case TY_QUALPROTO:
|
||||
req = (struct lqrreq *)cp;
|
||||
req = (struct lqrreq *) cp;
|
||||
LogPrintf(LogLCP, " %s proto: %x, interval: %dms\n",
|
||||
request, ntohs(req->proto), ntohl(req->period)*10);
|
||||
request, ntohs(req->proto), ntohl(req->period) * 10);
|
||||
switch (mode) {
|
||||
case MODE_REQ:
|
||||
if (ntohs(req->proto) != PROTO_LQR || !Acceptable(ConfLqr))
|
||||
@ -549,7 +543,8 @@ int mode;
|
||||
if (LcpInfo.his_lqrperiod < 500)
|
||||
LcpInfo.his_lqrperiod = 500;
|
||||
req->period = htonl(LcpInfo.his_lqrperiod);
|
||||
bcopy(cp, ackp, length); ackp += length;
|
||||
bcopy(cp, ackp, length);
|
||||
ackp += length;
|
||||
}
|
||||
break;
|
||||
case MODE_NAK:
|
||||
@ -560,7 +555,7 @@ int mode;
|
||||
}
|
||||
break;
|
||||
case TY_MAGICNUM:
|
||||
lp = (u_long *)(cp + 2);
|
||||
lp = (u_long *) (cp + 2);
|
||||
magic = ntohl(*lp);
|
||||
LogPrintf(LogLCP, " %s %08x\n", request, magic);
|
||||
|
||||
@ -572,11 +567,12 @@ int mode;
|
||||
LogPrintf(LogLCP, "Magic is same (%08x)\n", magic);
|
||||
LcpInfo.want_magic = GenerateMagic();
|
||||
bcopy(cp, nakp, 6);
|
||||
nakp += 6;
|
||||
} else {
|
||||
nakp += 6;
|
||||
} else {
|
||||
LcpInfo.his_magic = magic;
|
||||
bcopy(cp, ackp, length); ackp += length;
|
||||
}
|
||||
bcopy(cp, ackp, length);
|
||||
ackp += length;
|
||||
}
|
||||
} else {
|
||||
LcpInfo.my_reject |= (1 << type);
|
||||
goto reqreject;
|
||||
@ -598,20 +594,24 @@ int mode;
|
||||
|
||||
switch (mode) {
|
||||
case MODE_REQ:
|
||||
if (Acceptable(ConfProtocomp)) {
|
||||
if (Acceptable(ConfProtocomp)) {
|
||||
LcpInfo.his_protocomp = 1;
|
||||
bcopy(cp, ackp, 2); ackp += 2;
|
||||
} else {
|
||||
bcopy(cp, ackp, 2);
|
||||
ackp += 2;
|
||||
} else {
|
||||
#ifdef OLDMST
|
||||
|
||||
/*
|
||||
* MorningStar before v1.3 needs NAK
|
||||
*/
|
||||
bcopy(cp, nakp, 2); nakp += 2;
|
||||
bcopy(cp, nakp, 2);
|
||||
nakp += 2;
|
||||
#else
|
||||
bcopy(cp, rejp, 2); rejp += 2;
|
||||
bcopy(cp, rejp, 2);
|
||||
rejp += 2;
|
||||
LcpInfo.my_reject |= (1 << type);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MODE_NAK:
|
||||
case MODE_REJ:
|
||||
@ -624,12 +624,13 @@ int mode;
|
||||
LogPrintf(LogLCP, " %s\n", request);
|
||||
switch (mode) {
|
||||
case MODE_REQ:
|
||||
if (Acceptable(ConfAcfcomp)) {
|
||||
if (Acceptable(ConfAcfcomp)) {
|
||||
LcpInfo.his_acfcomp = 1;
|
||||
bcopy(cp, ackp, 2);
|
||||
ackp += 2;
|
||||
} else {
|
||||
} else {
|
||||
#ifdef OLDMST
|
||||
|
||||
/*
|
||||
* MorningStar before v1.3 needs NAK
|
||||
*/
|
||||
@ -661,10 +662,10 @@ int mode;
|
||||
default:
|
||||
LogPrintf(LogLCP, " ???[%02x]\n", type);
|
||||
if (mode == MODE_REQ) {
|
||||
reqreject:
|
||||
bcopy(cp, rejp, length);
|
||||
rejp += length;
|
||||
LcpInfo.my_reject |= (1 << type);
|
||||
reqreject:
|
||||
bcopy(cp, rejp, length);
|
||||
rejp += length;
|
||||
LcpInfo.my_reject |= (1 << type);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -673,14 +674,13 @@ int mode;
|
||||
LogPrintf(LogLCP, "LCP size zero\n");
|
||||
break;
|
||||
}
|
||||
|
||||
plen -= length;
|
||||
cp += length;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LcpInput(struct mbuf *bp)
|
||||
LcpInput(struct mbuf * bp)
|
||||
{
|
||||
FsmInput(&LcpFsm, bp);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: lcp.h,v 1.6 1997/02/22 16:10:24 peter Exp $
|
||||
* $Id: lcp.h,v 1.7 1997/06/09 03:27:25 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -24,24 +24,24 @@
|
||||
#define _LPC_H_
|
||||
|
||||
struct lcpstate {
|
||||
u_long his_mru;
|
||||
u_long his_accmap;
|
||||
u_long his_magic;
|
||||
u_long his_lqrperiod;
|
||||
u_char his_protocomp;
|
||||
u_char his_acfcomp;
|
||||
u_long his_mru;
|
||||
u_long his_accmap;
|
||||
u_long his_magic;
|
||||
u_long his_lqrperiod;
|
||||
u_char his_protocomp;
|
||||
u_char his_acfcomp;
|
||||
u_short his_auth;
|
||||
|
||||
u_long want_mru;
|
||||
u_long want_accmap;
|
||||
u_long want_magic;
|
||||
u_long want_lqrperiod;
|
||||
u_char want_protocomp;
|
||||
u_char want_acfcomp;
|
||||
u_long want_mru;
|
||||
u_long want_accmap;
|
||||
u_long want_magic;
|
||||
u_long want_lqrperiod;
|
||||
u_char want_protocomp;
|
||||
u_char want_acfcomp;
|
||||
u_short want_auth;
|
||||
|
||||
u_long his_reject; /* Request codes rejected by peer */
|
||||
u_long my_reject; /* Request codes I have rejected */
|
||||
u_long his_reject; /* Request codes rejected by peer */
|
||||
u_long my_reject; /* Request codes I have rejected */
|
||||
|
||||
u_short auth_iwait;
|
||||
u_short auth_ineed;
|
||||
@ -66,10 +66,10 @@ struct lcpstate {
|
||||
#define TY_COMPFRAME 15 /* Compound-Frames */
|
||||
|
||||
struct lqrreq {
|
||||
u_char type;
|
||||
u_char length;
|
||||
u_char type;
|
||||
u_char length;
|
||||
u_short proto; /* Quality protocol */
|
||||
u_long period; /* Reporting interval */
|
||||
u_long period; /* Reporting interval */
|
||||
};
|
||||
|
||||
extern struct lcpstate LcpInfo;
|
||||
@ -80,4 +80,5 @@ extern void LcpSendProtoRej(u_char *, int);
|
||||
extern void LcpOpen(int mode);
|
||||
extern void LcpClose(void);
|
||||
extern void LcpDown(void);
|
||||
|
||||
#endif
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: lcpproto.h,v 1.6 1997/02/22 16:10:25 peter Exp $
|
||||
* $Id: lcpproto.h,v 1.7 1997/06/09 03:27:25 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -26,11 +26,11 @@
|
||||
/*
|
||||
* Definition of protocol numbers
|
||||
*/
|
||||
#define PROTO_IP 0x0021 /* IP */
|
||||
#define PROTO_VJUNCOMP 0x002f /* VJ Uncompressed */
|
||||
#define PROTO_VJCOMP 0x002d /* VJ Compressed */
|
||||
#define PROTO_ICOMPD 0x00fb /* Individual link compressed */
|
||||
#define PROTO_COMPD 0x00fd /* Compressed datagram */
|
||||
#define PROTO_IP 0x0021 /* IP */
|
||||
#define PROTO_VJUNCOMP 0x002f /* VJ Uncompressed */
|
||||
#define PROTO_VJCOMP 0x002d /* VJ Compressed */
|
||||
#define PROTO_ICOMPD 0x00fb /* Individual link compressed */
|
||||
#define PROTO_COMPD 0x00fd /* Compressed datagram */
|
||||
|
||||
#define PROTO_IPCP 0x8021
|
||||
#define PROTO_ICCP 0x80fb
|
||||
@ -41,12 +41,13 @@
|
||||
#define PROTO_LQR 0xc025
|
||||
#define PROTO_CHAP 0xc223
|
||||
|
||||
extern void LcpInput(struct mbuf *bp);
|
||||
extern void PapInput(struct mbuf *bp);
|
||||
extern void LqpInput(struct mbuf *bp);
|
||||
extern void ChapInput(struct mbuf *bp);
|
||||
extern void IpInput(struct mbuf *bp);
|
||||
extern struct mbuf *VjCompInput(struct mbuf *bp, int proto);
|
||||
extern void IpcpInput(struct mbuf *bp);
|
||||
extern void LqrInput(struct mbuf *bp);
|
||||
extern void LcpInput(struct mbuf * bp);
|
||||
extern void PapInput(struct mbuf * bp);
|
||||
extern void LqpInput(struct mbuf * bp);
|
||||
extern void ChapInput(struct mbuf * bp);
|
||||
extern void IpInput(struct mbuf * bp);
|
||||
extern struct mbuf *VjCompInput(struct mbuf * bp, int proto);
|
||||
extern void IpcpInput(struct mbuf * bp);
|
||||
extern void LqrInput(struct mbuf * bp);
|
||||
|
||||
#endif
|
||||
|
@ -18,67 +18,67 @@
|
||||
#define entry(a) { off(a), "_" #a }
|
||||
|
||||
static struct {
|
||||
int offset;
|
||||
char *name;
|
||||
int offset;
|
||||
char *name;
|
||||
} map[] = {
|
||||
entry(GetNextFragmentPtr),
|
||||
entry(GetNextFragmentPtr),
|
||||
entry(InitPacketAlias),
|
||||
entry(PacketAliasIn),
|
||||
entry(PacketAliasOut),
|
||||
entry(PacketAliasRedirectAddr),
|
||||
entry(PacketAliasRedirectPort),
|
||||
entry(SaveFragmentPtr),
|
||||
entry(SetPacketAliasAddress),
|
||||
entry(SetPacketAliasMode),
|
||||
entry(FragmentAliasIn),
|
||||
{ 0, 0 }
|
||||
entry(PacketAliasGetFragment),
|
||||
entry(PacketAliasInit),
|
||||
entry(PacketAliasIn),
|
||||
entry(PacketAliasOut),
|
||||
entry(PacketAliasRedirectAddr),
|
||||
entry(PacketAliasRedirectPort),
|
||||
entry(PacketAliasSaveFragment),
|
||||
entry(PacketAliasSetAddress),
|
||||
entry(PacketAliasSetMode),
|
||||
entry(PacketAliasFragmentIn),
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static void *dl;
|
||||
|
||||
int loadAliasHandlers(struct aliasHandlers *h)
|
||||
int
|
||||
loadAliasHandlers(struct aliasHandlers * h)
|
||||
{
|
||||
char *path;
|
||||
char *env;
|
||||
int i;
|
||||
char *path;
|
||||
char *env;
|
||||
int i;
|
||||
|
||||
path = _PATH_ALIAS;
|
||||
env = getenv("_PATH_ALIAS");
|
||||
if (env)
|
||||
if (OrigUid() == 0)
|
||||
path = env;
|
||||
else
|
||||
LogPrintf(LogALERT, "Ignoring environment _PATH_ALIAS value (%s)",
|
||||
env);
|
||||
path = _PATH_ALIAS;
|
||||
env = getenv("_PATH_ALIAS");
|
||||
if (env)
|
||||
if (OrigUid() == 0)
|
||||
path = env;
|
||||
else
|
||||
LogPrintf(LogALERT, "Ignoring environment _PATH_ALIAS value (%s)",
|
||||
env);
|
||||
|
||||
dl = dlopen(path, RTLD_LAZY);
|
||||
if (dl == (void *)0) {
|
||||
LogPrintf(LogWARN, "_PATH_ALIAS (%s): Invalid lib: %s\n",
|
||||
path, dlerror());
|
||||
return -1;
|
||||
dl = dlopen(path, RTLD_LAZY);
|
||||
if (dl == (void *) 0) {
|
||||
LogPrintf(LogWARN, "_PATH_ALIAS (%s): Invalid lib: %s\n",
|
||||
path, dlerror());
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; map[i].name; i++) {
|
||||
*(void **) ((char *) h + map[i].offset) = dlsym(dl, map[i].name);
|
||||
if (*(void **) ((char *) h + map[i].offset) == (void *) 0) {
|
||||
LogPrintf(LogWARN, "_PATH_ALIAS (%s): %s: %s\n", path,
|
||||
map[i].name, dlerror());
|
||||
(void) dlclose(dl);
|
||||
dl = (void *) 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; map[i].name; i++) {
|
||||
*(void **)((char *)h + map[i].offset) = dlsym(dl, map[i].name);
|
||||
if (*(void **)((char *)h + map[i].offset) == (void *)0) {
|
||||
LogPrintf(LogWARN, "_PATH_ALIAS (%s): %s: %s\n", path,
|
||||
map[i].name, dlerror());
|
||||
(void)dlclose(dl);
|
||||
dl = (void *)0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
VarPacketAliasInit();
|
||||
|
||||
VarInitPacketAlias();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void unloadAliasHandlers()
|
||||
void
|
||||
unloadAliasHandlers()
|
||||
{
|
||||
if (dl) {
|
||||
dlclose(dl);
|
||||
dl = (void *)0;
|
||||
}
|
||||
if (dl) {
|
||||
dlclose(dl);
|
||||
dl = (void *) 0;
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
struct aliasHandlers {
|
||||
char *(*GetNextFragmentPtr)(char *);
|
||||
void (*InitPacketAlias)();
|
||||
int (*PacketAliasIn)(char *,int);
|
||||
int (*PacketAliasOut)(char *,int);
|
||||
struct alias_link *(*PacketAliasRedirectAddr)
|
||||
(struct in_addr, struct in_addr);
|
||||
struct alias_link *(*PacketAliasRedirectPort)
|
||||
(struct in_addr, u_short, struct in_addr, u_short,
|
||||
struct in_addr, u_short, u_char);
|
||||
int (*SaveFragmentPtr)(char *);
|
||||
void (*SetPacketAliasAddress)(struct in_addr);
|
||||
unsigned (*SetPacketAliasMode)(unsigned, unsigned);
|
||||
void (*FragmentAliasIn)(char *, char *);
|
||||
char *(*PacketAliasGetFragment) (char *);
|
||||
void (*PacketAliasInit) ();
|
||||
int (*PacketAliasIn) (char *, int);
|
||||
int (*PacketAliasOut) (char *, int);
|
||||
struct alias_link *(*PacketAliasRedirectAddr)
|
||||
(struct in_addr, struct in_addr);
|
||||
struct alias_link *(*PacketAliasRedirectPort)
|
||||
(struct in_addr, u_short, struct in_addr, u_short,
|
||||
struct in_addr, u_short, u_char);
|
||||
int (*PacketAliasSaveFragment) (char *);
|
||||
void (*PacketAliasSetAddress) (struct in_addr);
|
||||
unsigned (*PacketAliasSetMode) (unsigned, unsigned);
|
||||
void (*PacketAliasFragmentIn) (char *, char *);
|
||||
};
|
||||
|
||||
extern int loadAliasHandlers(struct aliasHandlers *);
|
||||
|
@ -11,24 +11,24 @@
|
||||
#include "vars.h"
|
||||
|
||||
static char *LogNames[] = {
|
||||
"Async",
|
||||
"Carrier",
|
||||
"CCP",
|
||||
"Chat",
|
||||
"Command",
|
||||
"Connect",
|
||||
"Debug",
|
||||
"HDLC",
|
||||
"IPCP",
|
||||
"LCP",
|
||||
"Link",
|
||||
"LQM",
|
||||
"Phase",
|
||||
"TCP/IP",
|
||||
"Tun",
|
||||
"Warning",
|
||||
"Error",
|
||||
"Alert"
|
||||
"Async",
|
||||
"Carrier",
|
||||
"CCP",
|
||||
"Chat",
|
||||
"Command",
|
||||
"Connect",
|
||||
"Debug",
|
||||
"HDLC",
|
||||
"IPCP",
|
||||
"LCP",
|
||||
"Link",
|
||||
"LQM",
|
||||
"Phase",
|
||||
"TCP/IP",
|
||||
"Tun",
|
||||
"Warning",
|
||||
"Error",
|
||||
"Alert"
|
||||
};
|
||||
|
||||
#define MSK(n) (1<<((n)-1))
|
||||
@ -39,112 +39,116 @@ static int LogTunno = -1;
|
||||
static int
|
||||
syslogLevel(int lev)
|
||||
{
|
||||
switch (lev) {
|
||||
case LogDEBUG: return LOG_DEBUG;
|
||||
case LogWARN: return LOG_WARNING;
|
||||
case LogERROR: return LOG_ERR;
|
||||
case LogALERT: return LOG_ALERT;
|
||||
}
|
||||
return lev >= LogMIN && lev <= LogMAX ? LOG_INFO : 0;
|
||||
switch (lev) {
|
||||
case LogDEBUG:return LOG_DEBUG;
|
||||
case LogWARN:
|
||||
return LOG_WARNING;
|
||||
case LogERROR:
|
||||
return LOG_ERR;
|
||||
case LogALERT:
|
||||
return LOG_ALERT;
|
||||
}
|
||||
return lev >= LogMIN && lev <= LogMAX ? LOG_INFO : 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
LogName(int id)
|
||||
{
|
||||
return id < LogMIN || id > LogMAX ? "Unknown" : LogNames[id-1];
|
||||
return id < LogMIN || id > LogMAX ? "Unknown" : LogNames[id - 1];
|
||||
}
|
||||
|
||||
void
|
||||
LogKeep(int id)
|
||||
{
|
||||
if (id >= LogMIN && id <= LogMAXCONF)
|
||||
LogMask |= MSK(id);
|
||||
if (id >= LogMIN && id <= LogMAXCONF)
|
||||
LogMask |= MSK(id);
|
||||
}
|
||||
|
||||
void
|
||||
LogDiscard(int id)
|
||||
{
|
||||
if (id >= LogMIN && id <= LogMAXCONF)
|
||||
LogMask &= ~MSK(id);
|
||||
if (id >= LogMIN && id <= LogMAXCONF)
|
||||
LogMask &= ~MSK(id);
|
||||
}
|
||||
|
||||
void
|
||||
LogDiscardAll()
|
||||
{
|
||||
LogMask = 0;
|
||||
LogMask = 0;
|
||||
}
|
||||
|
||||
int
|
||||
LogIsKept(int id)
|
||||
{
|
||||
if (id < LogMIN)
|
||||
return 0;
|
||||
if (id <= LogMAXCONF)
|
||||
return LogMask & MSK(id);
|
||||
return id <= LogMAX;
|
||||
if (id < LogMIN)
|
||||
return 0;
|
||||
if (id <= LogMAXCONF)
|
||||
return LogMask & MSK(id);
|
||||
return id <= LogMAX;
|
||||
}
|
||||
|
||||
void
|
||||
LogOpen(const char *Name)
|
||||
{
|
||||
openlog(Name, LOG_PID, LOG_DAEMON);
|
||||
openlog(Name, LOG_PID, LOG_DAEMON);
|
||||
}
|
||||
|
||||
void
|
||||
LogSetTun(int tunno)
|
||||
{
|
||||
LogTunno = tunno;
|
||||
LogTunno = tunno;
|
||||
}
|
||||
|
||||
void
|
||||
LogClose()
|
||||
{
|
||||
closelog();
|
||||
LogTunno = -1;
|
||||
closelog();
|
||||
LogTunno = -1;
|
||||
}
|
||||
|
||||
void
|
||||
LogPrintf(int lev, char *fmt, ...)
|
||||
LogPrintf(int lev, char *fmt,...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
if (LogIsKept(lev)) {
|
||||
static char nfmt[200];
|
||||
va_list ap;
|
||||
|
||||
if (LogIsKept(LogTUN) && LogTunno != -1)
|
||||
snprintf(nfmt, sizeof nfmt, "tun%d: %s: %s",
|
||||
LogTunno, LogName(lev), fmt);
|
||||
else
|
||||
snprintf(nfmt, sizeof nfmt, "%s: %s", LogName(lev), fmt);
|
||||
if ((lev == LogERROR || lev == LogALERT || lev == LogWARN) && VarTerm)
|
||||
vfprintf(VarTerm, fmt, ap);
|
||||
if (lev != LogWARN || !VarTerm)
|
||||
vsyslog(syslogLevel(lev), nfmt, ap);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
LogDumpBp(int lev, char *hdr, struct mbuf *bp)
|
||||
{
|
||||
LogDumpBuff(lev, hdr, MBUF_CTOP(bp), bp->cnt);
|
||||
}
|
||||
|
||||
void
|
||||
LogDumpBuff(int lev, char *hdr, u_char *ptr, int n)
|
||||
{
|
||||
if (LogIsKept(lev)) {
|
||||
char buf[49];
|
||||
char *b;
|
||||
int f;
|
||||
|
||||
if (hdr && *hdr)
|
||||
LogPrintf(lev, "%s", hdr);
|
||||
while (n > 0) {
|
||||
b = buf;
|
||||
for (f = 0; f < 16 && n--; f++, b += 3)
|
||||
sprintf(b, " %02x", (int)*ptr++);
|
||||
LogPrintf(lev, buf);
|
||||
}
|
||||
va_start(ap, fmt);
|
||||
if (LogIsKept(lev)) {
|
||||
static char nfmt[200];
|
||||
|
||||
if (LogIsKept(LogTUN) && LogTunno != -1)
|
||||
snprintf(nfmt, sizeof nfmt, "tun%d: %s: %s",
|
||||
LogTunno, LogName(lev), fmt);
|
||||
else
|
||||
snprintf(nfmt, sizeof nfmt, "%s: %s", LogName(lev), fmt);
|
||||
if ((lev == LogERROR || lev == LogALERT || lev == LogWARN) && VarTerm)
|
||||
vfprintf(VarTerm, fmt, ap);
|
||||
if (lev != LogWARN || !VarTerm)
|
||||
vsyslog(syslogLevel(lev), nfmt, ap);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
LogDumpBp(int lev, char *hdr, struct mbuf * bp)
|
||||
{
|
||||
LogDumpBuff(lev, hdr, MBUF_CTOP(bp), bp->cnt);
|
||||
}
|
||||
|
||||
void
|
||||
LogDumpBuff(int lev, char *hdr, u_char * ptr, int n)
|
||||
{
|
||||
if (LogIsKept(lev)) {
|
||||
char buf[49];
|
||||
char *b;
|
||||
int f;
|
||||
|
||||
if (hdr && *hdr)
|
||||
LogPrintf(lev, "%s", hdr);
|
||||
while (n > 0) {
|
||||
b = buf;
|
||||
for (f = 0; f < 16 && n--; f++, b += 3)
|
||||
sprintf(b, " %02x", (int) *ptr++);
|
||||
LogPrintf(lev, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
#define LogMIN (1)
|
||||
#define LogASYNC (1) /* syslog(LOG_INFO, ....) */
|
||||
#define LogASYNC (1) /* syslog(LOG_INFO, ....) */
|
||||
#define LogCARRIER (2)
|
||||
#define LogCCP (3)
|
||||
#define LogCHAT (4)
|
||||
#define LogCOMMAND (5)
|
||||
#define LogCONNECT (6)
|
||||
#define LogDEBUG (7) /* syslog(LOG_DEBUG, ....) */
|
||||
#define LogDEBUG (7) /* syslog(LOG_DEBUG, ....) */
|
||||
#define LogHDLC (8)
|
||||
#define LogIPCP (9)
|
||||
#define LogLCP (10)
|
||||
@ -17,7 +17,7 @@
|
||||
#define LogMAXCONF (15)
|
||||
#define LogWARN (16) /* Sent to VarTerm else syslog(LOG_WARNING, ) */
|
||||
#define LogERROR (17) /* syslog(LOG_ERR, ....), + sent to VarTerm */
|
||||
#define LogALERT (18) /* syslog(LOG_ALERT, ....) */
|
||||
#define LogALERT (18) /* syslog(LOG_ALERT, ....) */
|
||||
#define LogMAX (18)
|
||||
|
||||
/* The first int arg for all of the following is one of the above values */
|
||||
@ -29,6 +29,6 @@ extern int LogIsKept(int);
|
||||
extern void LogOpen(const char *);
|
||||
extern void LogSetTun(int);
|
||||
extern void LogClose();
|
||||
extern void LogPrintf(int, char *, ...);
|
||||
extern void LogDumpBp(int, char *hdr, struct mbuf *bp);
|
||||
extern void LogDumpBuff(int, char *hdr, u_char *ptr, int n);
|
||||
extern void LogPrintf(int, char *,...);
|
||||
extern void LogDumpBp(int, char *hdr, struct mbuf * bp);
|
||||
extern void LogDumpBuff(int, char *hdr, u_char * ptr, int n);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: lqr.c,v 1.15 1997/06/09 03:27:27 brian Exp $
|
||||
* $Id: lqr.c,v 1.16 1997/07/02 19:18:42 phk Exp $
|
||||
*
|
||||
* o LQR based on RFC1333
|
||||
*
|
||||
@ -36,7 +36,7 @@
|
||||
|
||||
struct pppTimer LqrTimer;
|
||||
|
||||
static u_long lastpeerin = (u_long)-1;
|
||||
static u_long lastpeerin = (u_long) - 1;
|
||||
|
||||
static int lqmmethod;
|
||||
static int echoseq;
|
||||
@ -64,19 +64,18 @@ SendEchoReq()
|
||||
LogPrintf(LogLQM, "Send echo LQR [%d]\n", echoseq);
|
||||
lqr->sequence = htonl(echoseq++);
|
||||
FsmOutput(fp, CODE_ECHOREQ, fp->reqid++,
|
||||
(u_char *)lqr, sizeof(struct echolqr));
|
||||
(u_char *) lqr, sizeof(struct echolqr));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RecvEchoLqr(bp)
|
||||
struct mbuf *bp;
|
||||
RecvEchoLqr(struct mbuf * bp)
|
||||
{
|
||||
struct echolqr *lqr;
|
||||
u_long seq;
|
||||
|
||||
if (plength(bp) == sizeof(struct echolqr)) {
|
||||
lqr = (struct echolqr *)MBUF_CTOP(bp);
|
||||
lqr = (struct echolqr *) MBUF_CTOP(bp);
|
||||
if (htonl(lqr->signature) == SIGNATURE) {
|
||||
seq = ntohl(lqr->sequence);
|
||||
LogPrintf(LogLQM, "Got echo LQR [%d]\n", ntohl(lqr->sequence));
|
||||
@ -86,14 +85,14 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
void
|
||||
LqrChangeOrder(src, dst)
|
||||
struct lqrdata *src, *dst;
|
||||
LqrChangeOrder(struct lqrdata * src, struct lqrdata * dst)
|
||||
{
|
||||
u_long *sp, *dp;
|
||||
int n;
|
||||
|
||||
sp = (u_long *)src; dp = (u_long *)dst;
|
||||
for (n = 0; n < sizeof(struct lqrdata)/sizeof(u_long); n++)
|
||||
sp = (u_long *) src;
|
||||
dp = (u_long *) dst;
|
||||
for (n = 0; n < sizeof(struct lqrdata) / sizeof(u_long); n++)
|
||||
*dp++ = ntohl(*sp++);
|
||||
}
|
||||
|
||||
@ -106,11 +105,12 @@ SendLqrReport()
|
||||
|
||||
if (lqmmethod & LQM_LQR) {
|
||||
if (lqrsendcnt > 5) {
|
||||
|
||||
/*
|
||||
* XXX: Should implement LQM strategy
|
||||
*/
|
||||
LogPrintf(LogPHASE, "** 1 Too many ECHO packets are lost. **\n");
|
||||
lqmmethod = 0; /* Prevent rcursion via LcpClose() */
|
||||
lqmmethod = 0; /* Prevent rcursion via LcpClose() */
|
||||
reconnect(RECON_TRUE);
|
||||
LcpClose();
|
||||
} else {
|
||||
@ -121,19 +121,18 @@ SendLqrReport()
|
||||
} else if (lqmmethod & LQM_ECHO) {
|
||||
if (echoseq - gotseq > 5) {
|
||||
LogPrintf(LogPHASE, "** 2 Too many ECHO packets are lost. **\n");
|
||||
lqmmethod = 0; /* Prevent rcursion via LcpClose() */
|
||||
lqmmethod = 0; /* Prevent rcursion via LcpClose() */
|
||||
reconnect(RECON_TRUE);
|
||||
LcpClose();
|
||||
} else
|
||||
SendEchoReq();
|
||||
}
|
||||
|
||||
if (lqmmethod && Enabled(ConfLqr))
|
||||
StartTimer(&LqrTimer);
|
||||
}
|
||||
|
||||
void
|
||||
LqrInput(struct mbuf *bp)
|
||||
LqrInput(struct mbuf * bp)
|
||||
{
|
||||
int len;
|
||||
u_char *cp;
|
||||
@ -144,7 +143,6 @@ LqrInput(struct mbuf *bp)
|
||||
pfree(bp);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Acceptable(ConfLqr)) {
|
||||
bp->offset -= 2;
|
||||
bp->cnt += 2;
|
||||
@ -153,10 +151,10 @@ LqrInput(struct mbuf *bp)
|
||||
LcpSendProtoRej(cp, bp->cnt);
|
||||
} else {
|
||||
cp = MBUF_CTOP(bp);
|
||||
lqr = (struct lqrdata *)cp;
|
||||
lqr = (struct lqrdata *) cp;
|
||||
if (ntohl(lqr->MagicNumber) != LcpInfo.his_magic) {
|
||||
LogPrintf(LogERROR, "LqrInput: magic %x != expecting %x\n",
|
||||
ntohl(lqr->MagicNumber), LcpInfo.his_magic);
|
||||
ntohl(lqr->MagicNumber), LcpInfo.his_magic);
|
||||
pfree(bp);
|
||||
return;
|
||||
}
|
||||
@ -166,12 +164,11 @@ LqrInput(struct mbuf *bp)
|
||||
*/
|
||||
LqrChangeOrder(lqr, &HisLqrData);
|
||||
LqrDump("LqrInput", &HisLqrData);
|
||||
lqrsendcnt = 0; /* we have received LQR from peer */
|
||||
lqrsendcnt = 0; /* we have received LQR from peer */
|
||||
|
||||
/*
|
||||
* Generate LQR responce to peer, if
|
||||
* i) We are not running LQR timer.
|
||||
* ii) Two successive LQR's PeerInLQRs are same.
|
||||
* Generate LQR responce to peer, if i) We are not running LQR timer. ii)
|
||||
* Two successive LQR's PeerInLQRs are same.
|
||||
*/
|
||||
if (LqrTimer.load == 0 || lastpeerin == HisLqrData.PeerInLQRs) {
|
||||
lqmmethod |= LQM_LQR;
|
||||
@ -191,10 +188,10 @@ StartLqm()
|
||||
struct lcpstate *lcp = &LcpInfo;
|
||||
int period;
|
||||
|
||||
lqrsendcnt = 0; /* start waiting all over for ECHOs */
|
||||
lqrsendcnt = 0; /* start waiting all over for ECHOs */
|
||||
echoseq = 0;
|
||||
gotseq = 0;
|
||||
|
||||
|
||||
lqmmethod = LQM_ECHO;
|
||||
if (Enabled(ConfLqr))
|
||||
lqmmethod |= LQM_LQR;
|
||||
@ -202,8 +199,9 @@ StartLqm()
|
||||
LogPrintf(LogLQM, "LQM method = %d\n", lqmmethod);
|
||||
|
||||
if (lcp->his_lqrperiod || lcp->want_lqrperiod) {
|
||||
|
||||
/*
|
||||
* We need to run timer. Let's figure out period.
|
||||
* We need to run timer. Let's figure out period.
|
||||
*/
|
||||
period = lcp->his_lqrperiod ? lcp->his_lqrperiod : lcp->want_lqrperiod;
|
||||
StopTimer(&LqrTimer);
|
||||
@ -213,21 +211,20 @@ StartLqm()
|
||||
SendLqrReport();
|
||||
StartTimer(&LqrTimer);
|
||||
LogPrintf(LogLQM, "Will send LQR every %d.%d secs\n",
|
||||
period/100, period % 100);
|
||||
period / 100, period % 100);
|
||||
} else {
|
||||
LogPrintf(LogLQM, "LQR is not activated.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StopLqrTimer(void)
|
||||
StopLqrTimer()
|
||||
{
|
||||
StopTimer(&LqrTimer);
|
||||
StopTimer(&LqrTimer);
|
||||
}
|
||||
|
||||
void
|
||||
StopLqr(method)
|
||||
int method;
|
||||
StopLqr(int method)
|
||||
{
|
||||
LogPrintf(LogLQM, "StopLqr method = %x\n", method);
|
||||
|
||||
@ -243,9 +240,7 @@ int method;
|
||||
}
|
||||
|
||||
void
|
||||
LqrDump(message, lqr)
|
||||
char *message;
|
||||
struct lqrdata *lqr;
|
||||
LqrDump(char *message, struct lqrdata * lqr)
|
||||
{
|
||||
if (LogIsKept(LogLQM)) {
|
||||
LogPrintf(LogLQM, "%s:", message);
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: lqr.h,v 1.5 1997/02/22 16:10:29 peter Exp $
|
||||
* $Id: lqr.h,v 1.6 1997/06/09 03:27:27 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -27,26 +27,26 @@
|
||||
* Structure of LQR packet defined in RFC1333
|
||||
*/
|
||||
struct lqrdata {
|
||||
u_long MagicNumber;
|
||||
u_long LastOutLQRs;
|
||||
u_long LastOutPackets;
|
||||
u_long LastOutOctets;
|
||||
u_long PeerInLQRs;
|
||||
u_long PeerInPackets;
|
||||
u_long PeerInDiscards;
|
||||
u_long PeerInErrors;
|
||||
u_long PeerInOctets;
|
||||
u_long PeerOutLQRs;
|
||||
u_long PeerOutPackets;
|
||||
u_long PeerOutOctets;
|
||||
u_long MagicNumber;
|
||||
u_long LastOutLQRs;
|
||||
u_long LastOutPackets;
|
||||
u_long LastOutOctets;
|
||||
u_long PeerInLQRs;
|
||||
u_long PeerInPackets;
|
||||
u_long PeerInDiscards;
|
||||
u_long PeerInErrors;
|
||||
u_long PeerInOctets;
|
||||
u_long PeerOutLQRs;
|
||||
u_long PeerOutPackets;
|
||||
u_long PeerOutOctets;
|
||||
};
|
||||
|
||||
struct lqrsave {
|
||||
u_long SaveInLQRs;
|
||||
u_long SaveInPackets;
|
||||
u_long SaveInDiscards;
|
||||
u_long SaveInErrors;
|
||||
u_long SaveInOctets;
|
||||
u_long SaveInLQRs;
|
||||
u_long SaveInPackets;
|
||||
u_long SaveInDiscards;
|
||||
u_long SaveInErrors;
|
||||
u_long SaveInOctets;
|
||||
};
|
||||
|
||||
struct lqrdata MyLqrData, HisLqrData;
|
||||
@ -64,4 +64,5 @@ extern void StartLqm(void);
|
||||
extern void StopLqr(int);
|
||||
extern void StopLqrTimer(void);
|
||||
extern void RecvEchoLqr(struct mbuf *);
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: main.c,v 1.69 1997/07/01 21:31:23 brian Exp $
|
||||
* $Id: main.c,v 1.70 1997/08/21 16:21:34 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Add commands for traffic summary, version display, etc.
|
||||
@ -64,7 +64,7 @@
|
||||
|
||||
extern void VjInit(), AsyncInit();
|
||||
extern void AsyncInput();
|
||||
extern int SelectSystem();
|
||||
extern int SelectSystem();
|
||||
|
||||
extern void DecodeCommand(), Prompt();
|
||||
extern int aft_cmd;
|
||||
@ -73,8 +73,8 @@ static void DoLoop(void);
|
||||
static void TerminalStop();
|
||||
static char *ex_desc();
|
||||
|
||||
static struct termios oldtio; /* Original tty mode */
|
||||
static struct termios comtio; /* Command level tty mode */
|
||||
static struct termios oldtio; /* Original tty mode */
|
||||
static struct termios comtio; /* Command level tty mode */
|
||||
int TermMode;
|
||||
static pid_t BGPid = 0;
|
||||
static char pid_filename[MAXPATHLEN];
|
||||
@ -90,11 +90,11 @@ TtyInit(int DontWantInt)
|
||||
|
||||
stat = fcntl(0, F_GETFL, 0);
|
||||
if (stat > 0) {
|
||||
stat |= O_NONBLOCK;
|
||||
(void)fcntl(0, F_SETFL, stat);
|
||||
stat |= O_NONBLOCK;
|
||||
(void) fcntl(0, F_SETFL, stat);
|
||||
}
|
||||
newtio = oldtio;
|
||||
newtio.c_lflag &= ~(ECHO|ISIG|ICANON);
|
||||
newtio.c_lflag &= ~(ECHO | ISIG | ICANON);
|
||||
newtio.c_iflag = 0;
|
||||
newtio.c_oflag &= ~OPOST;
|
||||
newtio.c_cc[VEOF] = _POSIX_VDISABLE;
|
||||
@ -111,8 +111,7 @@ TtyInit(int DontWantInt)
|
||||
* Set tty into command mode. We allow canonical input and echo processing.
|
||||
*/
|
||||
void
|
||||
TtyCommandMode(prompt)
|
||||
int prompt;
|
||||
TtyCommandMode(int prompt)
|
||||
{
|
||||
struct termios newtio;
|
||||
int stat;
|
||||
@ -120,17 +119,18 @@ int prompt;
|
||||
if (!(mode & MODE_INTER))
|
||||
return;
|
||||
tcgetattr(0, &newtio);
|
||||
newtio.c_lflag |= (ECHO|ISIG|ICANON);
|
||||
newtio.c_lflag |= (ECHO | ISIG | ICANON);
|
||||
newtio.c_iflag = oldtio.c_iflag;
|
||||
newtio.c_oflag |= OPOST;
|
||||
tcsetattr(0, TCSADRAIN, &newtio);
|
||||
stat = fcntl(0, F_GETFL, 0);
|
||||
if (stat > 0) {
|
||||
stat |= O_NONBLOCK;
|
||||
(void)fcntl(0, F_SETFL, stat);
|
||||
stat |= O_NONBLOCK;
|
||||
(void) fcntl(0, F_SETFL, stat);
|
||||
}
|
||||
TermMode = 0;
|
||||
if(prompt) Prompt();
|
||||
if (prompt)
|
||||
Prompt();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -144,8 +144,8 @@ TtyTermMode()
|
||||
tcsetattr(0, TCSADRAIN, &comtio);
|
||||
stat = fcntl(0, F_GETFL, 0);
|
||||
if (stat > 0) {
|
||||
stat &= ~O_NONBLOCK;
|
||||
(void)fcntl(0, F_SETFL, stat);
|
||||
stat &= ~O_NONBLOCK;
|
||||
(void) fcntl(0, F_SETFL, stat);
|
||||
}
|
||||
TermMode = 1;
|
||||
}
|
||||
@ -157,15 +157,14 @@ TtyOldMode()
|
||||
|
||||
stat = fcntl(0, F_GETFL, 0);
|
||||
if (stat > 0) {
|
||||
stat &= ~O_NONBLOCK;
|
||||
(void)fcntl(0, F_SETFL, stat);
|
||||
stat &= ~O_NONBLOCK;
|
||||
(void) fcntl(0, F_SETFL, stat);
|
||||
}
|
||||
tcsetattr(0, TCSANOW, &oldtio);
|
||||
}
|
||||
|
||||
void
|
||||
Cleanup(excode)
|
||||
int excode;
|
||||
Cleanup(int excode)
|
||||
{
|
||||
|
||||
OsLinkdown();
|
||||
@ -173,18 +172,19 @@ int excode;
|
||||
sleep(1);
|
||||
if (mode & MODE_AUTO)
|
||||
DeleteIfRoutes(1);
|
||||
(void)unlink(pid_filename);
|
||||
(void)unlink(if_filename);
|
||||
(void) unlink(pid_filename);
|
||||
(void) unlink(if_filename);
|
||||
OsInterfaceDown(1);
|
||||
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
|
||||
char c = EX_ERRDEAD;
|
||||
if (write(BGFiledes[1],&c,1) == 1)
|
||||
LogPrintf(LogPHASE,"Parent notified of failure.\n");
|
||||
|
||||
if (write(BGFiledes[1], &c, 1) == 1)
|
||||
LogPrintf(LogPHASE, "Parent notified of failure.\n");
|
||||
else
|
||||
LogPrintf(LogPHASE,"Failed to notify parent of failure.\n");
|
||||
LogPrintf(LogPHASE, "Failed to notify parent of failure.\n");
|
||||
close(BGFiledes[1]);
|
||||
}
|
||||
LogPrintf(LogPHASE, "PPP Terminated (%s).\n",ex_desc(excode));
|
||||
LogPrintf(LogPHASE, "PPP Terminated (%s).\n", ex_desc(excode));
|
||||
LogClose();
|
||||
ServerClose();
|
||||
TtyOldMode();
|
||||
@ -193,29 +193,29 @@ int excode;
|
||||
}
|
||||
|
||||
static void
|
||||
CloseConnection(signo)
|
||||
int signo;
|
||||
CloseConnection(int signo)
|
||||
{
|
||||
/* NOTE, these are manual, we've done a setsid() */
|
||||
LogPrintf(LogPHASE, "Caught signal %d, abort connection\n", signo);
|
||||
reconnectState = RECON_FALSE; \
|
||||
reconnectCount = 0; \
|
||||
DownConnection();
|
||||
reconnectState = RECON_FALSE;
|
||||
\
|
||||
reconnectCount = 0;
|
||||
\
|
||||
DownConnection();
|
||||
dial_up = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
CloseSession(signo)
|
||||
int signo;
|
||||
CloseSession(int signo)
|
||||
{
|
||||
if (BGPid) {
|
||||
kill (BGPid, SIGINT);
|
||||
exit (EX_TERM);
|
||||
}
|
||||
LogPrintf(LogPHASE, "Signal %d, terminate.\n", signo);
|
||||
reconnect(RECON_FALSE);
|
||||
LcpClose();
|
||||
Cleanup(EX_TERM);
|
||||
if (BGPid) {
|
||||
kill(BGPid, SIGINT);
|
||||
exit(EX_TERM);
|
||||
}
|
||||
LogPrintf(LogPHASE, "Signal %d, terminate.\n", signo);
|
||||
reconnect(RECON_FALSE);
|
||||
LcpClose();
|
||||
Cleanup(EX_TERM);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -227,8 +227,7 @@ TerminalCont()
|
||||
}
|
||||
|
||||
static void
|
||||
TerminalStop(signo)
|
||||
int signo;
|
||||
TerminalStop(int signo)
|
||||
{
|
||||
pending_signal(SIGCONT, TerminalCont);
|
||||
TtyOldMode();
|
||||
@ -237,23 +236,23 @@ int signo;
|
||||
}
|
||||
|
||||
static void
|
||||
SetUpServer(signo)
|
||||
int signo;
|
||||
SetUpServer(int signo)
|
||||
{
|
||||
int res;
|
||||
if ((res = ServerTcpOpen(SERVER_PORT+tunno)) != 0)
|
||||
LogPrintf(LogERROR, "Failed %d to open port %d\n", res, SERVER_PORT+tunno);
|
||||
|
||||
if ((res = ServerTcpOpen(SERVER_PORT + tunno)) != 0)
|
||||
LogPrintf(LogERROR, "Failed %d to open port %d\n", res, SERVER_PORT + tunno);
|
||||
}
|
||||
|
||||
static char *
|
||||
ex_desc(int ex)
|
||||
{
|
||||
static char num[12];
|
||||
static char *desc[] = { "normal", "start", "sock",
|
||||
static char *desc[] = {"normal", "start", "sock",
|
||||
"modem", "dial", "dead", "done", "reboot", "errdead",
|
||||
"hangup", "term", "nodial", "nologin" };
|
||||
"hangup", "term", "nodial", "nologin"};
|
||||
|
||||
if (ex >= 0 && ex < sizeof(desc)/sizeof(*desc))
|
||||
if (ex >= 0 && ex < sizeof(desc) / sizeof(*desc))
|
||||
return desc[ex];
|
||||
snprintf(num, sizeof num, "%d", ex);
|
||||
return num;
|
||||
@ -263,7 +262,7 @@ void
|
||||
Usage()
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Usage: ppp [-auto | -background | -direct | -dedicated | -ddial ] [ -alias ] [system]\n");
|
||||
"Usage: ppp [-auto | -background | -direct | -dedicated | -ddial ] [ -alias ] [system]\n");
|
||||
exit(EX_START);
|
||||
}
|
||||
|
||||
@ -279,30 +278,31 @@ ProcessArgs(int argc, char **argv)
|
||||
if (strcmp(cp, "auto") == 0)
|
||||
mode |= MODE_AUTO;
|
||||
else if (strcmp(cp, "background") == 0)
|
||||
mode |= MODE_BACKGROUND|MODE_AUTO;
|
||||
mode |= MODE_BACKGROUND | MODE_AUTO;
|
||||
else if (strcmp(cp, "direct") == 0)
|
||||
mode |= MODE_DIRECT;
|
||||
else if (strcmp(cp, "dedicated") == 0)
|
||||
mode |= MODE_DEDICATED;
|
||||
else if (strcmp(cp, "ddial") == 0)
|
||||
mode |= MODE_DDIAL|MODE_AUTO;
|
||||
mode |= MODE_DDIAL | MODE_AUTO;
|
||||
else if (strcmp(cp, "alias") == 0) {
|
||||
if (loadAliasHandlers(&VarAliasHandlers) == 0)
|
||||
mode |= MODE_ALIAS;
|
||||
mode |= MODE_ALIAS;
|
||||
else
|
||||
LogPrintf(LogWARN, "Cannot load alias library\n");
|
||||
optc--; /* this option isn't exclusive */
|
||||
}
|
||||
else
|
||||
LogPrintf(LogWARN, "Cannot load alias library\n");
|
||||
optc--; /* this option isn't exclusive */
|
||||
} else
|
||||
Usage();
|
||||
optc++;
|
||||
argv++; argc--;
|
||||
argv++;
|
||||
argc--;
|
||||
}
|
||||
if (argc > 1) {
|
||||
fprintf(stderr, "specify only one system label.\n");
|
||||
exit(EX_START);
|
||||
}
|
||||
if (argc == 1) dstsystem = *argv;
|
||||
if (argc == 1)
|
||||
dstsystem = *argv;
|
||||
|
||||
if (optc > 1) {
|
||||
fprintf(stderr, "specify only one mode.\n");
|
||||
@ -320,18 +320,17 @@ Greetings()
|
||||
}
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
FILE *lockfile;
|
||||
char *name;
|
||||
|
||||
VarTerm = 0;
|
||||
name = rindex(argv[0], '/');
|
||||
LogOpen(name ? name+1 : argv[0]);
|
||||
LogOpen(name ? name + 1 : argv[0]);
|
||||
|
||||
argc--; argv++;
|
||||
argc--;
|
||||
argv++;
|
||||
mode = MODE_INTER; /* default operation is interactive mode */
|
||||
netfd = modem = tun_in = -1;
|
||||
server = -2;
|
||||
@ -349,8 +348,7 @@ char **argv;
|
||||
LogPrintf(LogWARN, "open_tun: %s\n", strerror(errno));
|
||||
return EX_START;
|
||||
}
|
||||
|
||||
if (mode & (MODE_AUTO|MODE_DIRECT|MODE_DEDICATED))
|
||||
if (mode & (MODE_AUTO | MODE_DIRECT | MODE_DEDICATED))
|
||||
mode &= ~MODE_INTER;
|
||||
if (mode & MODE_INTER) {
|
||||
fprintf(VarTerm, "Interactive mode\n");
|
||||
@ -359,13 +357,12 @@ char **argv;
|
||||
fprintf(VarTerm, "Automatic Dialer mode\n");
|
||||
if (dstsystem == NULL) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "Destination system must be specified in"
|
||||
" auto, background or ddial mode.\n");
|
||||
fprintf(VarTerm, "Destination system must be specified in"
|
||||
" auto, background or ddial mode.\n");
|
||||
return EX_START;
|
||||
}
|
||||
}
|
||||
|
||||
tcgetattr(0, &oldtio); /* Save original tty mode */
|
||||
tcgetattr(0, &oldtio); /* Save original tty mode */
|
||||
|
||||
pending_signal(SIGHUP, CloseSession);
|
||||
pending_signal(SIGTERM, CloseSession);
|
||||
@ -377,7 +374,7 @@ char **argv;
|
||||
#ifdef SIGALRM
|
||||
pending_signal(SIGALRM, SIG_IGN);
|
||||
#endif
|
||||
if(mode & MODE_INTER) {
|
||||
if (mode & MODE_INTER) {
|
||||
#ifdef SIGTSTP
|
||||
pending_signal(SIGTSTP, TerminalStop);
|
||||
#endif
|
||||
@ -400,46 +397,44 @@ char **argv;
|
||||
}
|
||||
if ((mode & MODE_AUTO) && DefHisAddress.ipaddr.s_addr == INADDR_ANY) {
|
||||
LogPrintf(LogWARN, "Must specify dstaddr with"
|
||||
" auto, background or ddial mode.\n");
|
||||
" auto, background or ddial mode.\n");
|
||||
Cleanup(EX_START);
|
||||
}
|
||||
}
|
||||
|
||||
if (ServerType() != NO_SERVER)
|
||||
switch ( LocalAuthInit() ) {
|
||||
case NOT_FOUND:
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm,LAUTH_M1);
|
||||
fprintf(VarTerm,LAUTH_M2);
|
||||
fflush(VarTerm);
|
||||
}
|
||||
/* Fall down */
|
||||
case VALID:
|
||||
VarLocalAuth = LOCAL_AUTH;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (LocalAuthInit()) {
|
||||
case NOT_FOUND:
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, LAUTH_M1);
|
||||
fprintf(VarTerm, LAUTH_M2);
|
||||
fflush(VarTerm);
|
||||
}
|
||||
/* Fall down */
|
||||
case VALID:
|
||||
VarLocalAuth = LOCAL_AUTH;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(mode & MODE_INTER)) {
|
||||
if (mode & MODE_BACKGROUND) {
|
||||
if (pipe (BGFiledes)) {
|
||||
LogPrintf(LogERROR, "pipe: %s", strerror(errno));
|
||||
if (pipe(BGFiledes)) {
|
||||
LogPrintf(LogERROR, "pipe: %s", strerror(errno));
|
||||
Cleanup(EX_SOCK);
|
||||
}
|
||||
}
|
||||
|
||||
/* Create server socket and listen. */
|
||||
if (server == -2 && ServerTcpOpen(SERVER_PORT + tunno) != 0)
|
||||
Cleanup(EX_SOCK);
|
||||
Cleanup(EX_SOCK);
|
||||
|
||||
if (!(mode & MODE_DIRECT)) {
|
||||
pid_t bgpid;
|
||||
|
||||
bgpid = fork ();
|
||||
bgpid = fork();
|
||||
if (bgpid == -1) {
|
||||
LogPrintf(LogERROR, "fork: %s", strerror(errno));
|
||||
Cleanup (EX_SOCK);
|
||||
LogPrintf(LogERROR, "fork: %s", strerror(errno));
|
||||
Cleanup(EX_SOCK);
|
||||
}
|
||||
if (bgpid) {
|
||||
char c = EX_NORMAL;
|
||||
@ -447,53 +442,52 @@ char **argv;
|
||||
if (mode & MODE_BACKGROUND) {
|
||||
/* Wait for our child to close its pipe before we exit. */
|
||||
BGPid = bgpid;
|
||||
close(BGFiledes[1]);
|
||||
close(BGFiledes[1]);
|
||||
if (read(BGFiledes[0], &c, 1) != 1) {
|
||||
fprintf(VarTerm, "Child exit, no status.\n");
|
||||
LogPrintf (LogPHASE, "Parent: Child exit, no status.\n");
|
||||
LogPrintf(LogPHASE, "Parent: Child exit, no status.\n");
|
||||
} else if (c == EX_NORMAL) {
|
||||
fprintf(VarTerm, "PPP enabled.\n");
|
||||
LogPrintf (LogPHASE, "Parent: PPP enabled.\n");
|
||||
LogPrintf(LogPHASE, "Parent: PPP enabled.\n");
|
||||
} else {
|
||||
fprintf(VarTerm, "Child failed (%s).\n",ex_desc((int)c));
|
||||
fprintf(VarTerm, "Child failed (%s).\n", ex_desc((int) c));
|
||||
LogPrintf(LogPHASE, "Parent: Child failed (%s).\n",
|
||||
ex_desc((int)c));
|
||||
}
|
||||
close(BGFiledes[0]);
|
||||
ex_desc((int) c));
|
||||
}
|
||||
close(BGFiledes[0]);
|
||||
}
|
||||
return c;
|
||||
return c;
|
||||
} else if (mode & MODE_BACKGROUND)
|
||||
close(BGFiledes[0]);
|
||||
close(BGFiledes[0]);
|
||||
}
|
||||
|
||||
snprintf(pid_filename, sizeof (pid_filename), "%stun%d.pid",
|
||||
_PATH_VARRUN, tunno);
|
||||
(void)unlink(pid_filename);
|
||||
snprintf(pid_filename, sizeof(pid_filename), "%stun%d.pid",
|
||||
_PATH_VARRUN, tunno);
|
||||
(void) unlink(pid_filename);
|
||||
|
||||
if ((lockfile = fopen(pid_filename, "w")) != NULL) {
|
||||
fprintf(lockfile, "%d\n", (int)getpid());
|
||||
fprintf(lockfile, "%d\n", (int) getpid());
|
||||
fclose(lockfile);
|
||||
} else
|
||||
LogPrintf(LogALERT, "Warning: Can't create %s: %s\n",
|
||||
pid_filename, strerror(errno));
|
||||
pid_filename, strerror(errno));
|
||||
|
||||
snprintf(if_filename, sizeof if_filename, "%s%s.if",
|
||||
_PATH_VARRUN, VarBaseDevice);
|
||||
(void)unlink(if_filename);
|
||||
_PATH_VARRUN, VarBaseDevice);
|
||||
(void) unlink(if_filename);
|
||||
|
||||
if ((lockfile = fopen(if_filename, "w")) != NULL) {
|
||||
fprintf(lockfile, "tun%d\n", tunno);
|
||||
fclose(lockfile);
|
||||
} else
|
||||
LogPrintf(LogALERT, "Warning: Can't create %s: %s\n",
|
||||
if_filename, strerror(errno));
|
||||
if_filename, strerror(errno));
|
||||
|
||||
VarTerm = 0; /* We know it's currently stdout */
|
||||
VarTerm = 0; /* We know it's currently stdout */
|
||||
close(0);
|
||||
close(2);
|
||||
|
||||
#ifdef DOTTYINIT
|
||||
if (mode & (MODE_DIRECT|MODE_DEDICATED))
|
||||
if (mode & (MODE_DIRECT | MODE_DEDICATED))
|
||||
#else
|
||||
if (mode & MODE_DIRECT)
|
||||
#endif
|
||||
@ -510,7 +504,7 @@ char **argv;
|
||||
|
||||
|
||||
do
|
||||
DoLoop();
|
||||
DoLoop();
|
||||
while (mode & MODE_DEDICATED);
|
||||
|
||||
Cleanup(EX_DONE);
|
||||
@ -527,7 +521,6 @@ PacketMode()
|
||||
LogPrintf(LogWARN, "PacketMode: Not connected.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
AsyncInit();
|
||||
VjInit();
|
||||
LcpInit();
|
||||
@ -536,7 +529,7 @@ PacketMode()
|
||||
LcpUp();
|
||||
|
||||
LcpOpen(VarOpenMode);
|
||||
if ((mode & (MODE_INTER|MODE_AUTO)) == MODE_INTER) {
|
||||
if ((mode & (MODE_INTER | MODE_AUTO)) == MODE_INTER) {
|
||||
TtyCommandMode(1);
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "Packet mode.\n");
|
||||
@ -565,13 +558,14 @@ ReadTty()
|
||||
char ch;
|
||||
static int ttystate;
|
||||
FILE *oVarTerm;
|
||||
|
||||
#define MAXLINESIZE 200
|
||||
char linebuff[MAXLINESIZE];
|
||||
|
||||
LogPrintf(LogDEBUG, "termode = %d, netfd = %d, mode = %d\n",
|
||||
TermMode, netfd, mode);
|
||||
TermMode, netfd, mode);
|
||||
if (!TermMode) {
|
||||
n = read(netfd, linebuff, sizeof(linebuff)-1);
|
||||
n = read(netfd, linebuff, sizeof(linebuff) - 1);
|
||||
if (n > 0) {
|
||||
aft_cmd = 1;
|
||||
DecodeCommand(linebuff, n, 1);
|
||||
@ -582,7 +576,7 @@ ReadTty()
|
||||
oVarTerm = VarTerm;
|
||||
VarTerm = 0;
|
||||
if (oVarTerm && oVarTerm != stdout)
|
||||
fclose(oVarTerm);
|
||||
fclose(oVarTerm);
|
||||
close(netfd);
|
||||
netfd = -1;
|
||||
}
|
||||
@ -590,7 +584,7 @@ ReadTty()
|
||||
}
|
||||
|
||||
/*
|
||||
* We are in terminal mode, decode special sequences
|
||||
* We are in terminal mode, decode special sequences
|
||||
*/
|
||||
n = read(fileno(VarTerm), &ch, 1);
|
||||
LogPrintf(LogDEBUG, "Got %d bytes (reading from the terminal)", n);
|
||||
@ -609,6 +603,7 @@ ReadTty()
|
||||
ShowHelp();
|
||||
break;
|
||||
case 'p':
|
||||
|
||||
/*
|
||||
* XXX: Should check carrier.
|
||||
*/
|
||||
@ -658,23 +653,21 @@ static char *FrameHeaders[] = {
|
||||
};
|
||||
|
||||
u_char *
|
||||
HdlcDetect(cp, n)
|
||||
u_char *cp;
|
||||
int n;
|
||||
HdlcDetect(u_char * cp, int n)
|
||||
{
|
||||
char *ptr, *fp, **hp;
|
||||
|
||||
cp[n] = '\0'; /* be sure to null terminated */
|
||||
cp[n] = '\0'; /* be sure to null terminated */
|
||||
ptr = NULL;
|
||||
for (hp = FrameHeaders; *hp; hp++) {
|
||||
fp = *hp;
|
||||
if (DEV_IS_SYNC)
|
||||
fp++;
|
||||
ptr = strstr((char *)cp, fp);
|
||||
ptr = strstr((char *) cp, fp);
|
||||
if (ptr)
|
||||
break;
|
||||
}
|
||||
return((u_char *)ptr);
|
||||
return ((u_char *) ptr);
|
||||
}
|
||||
|
||||
static struct pppTimer RedialTimer;
|
||||
@ -687,8 +680,7 @@ RedialTimeout()
|
||||
}
|
||||
|
||||
static void
|
||||
StartRedialTimer(Timeout)
|
||||
int Timeout;
|
||||
StartRedialTimer(int Timeout)
|
||||
{
|
||||
StopTimer(&RedialTimer);
|
||||
|
||||
@ -696,9 +688,9 @@ StartRedialTimer(Timeout)
|
||||
RedialTimer.state = TIMER_STOPPED;
|
||||
|
||||
if (Timeout > 0)
|
||||
RedialTimer.load = Timeout * SECTICKS;
|
||||
RedialTimer.load = Timeout * SECTICKS;
|
||||
else
|
||||
RedialTimer.load = (random() % REDIAL_PERIOD) * SECTICKS;
|
||||
RedialTimer.load = (random() % REDIAL_PERIOD) * SECTICKS;
|
||||
|
||||
LogPrintf(LogPHASE, "Enter pause (%d) for redialing.\n",
|
||||
RedialTimer.load / SECTICKS);
|
||||
@ -735,7 +727,6 @@ DoLoop()
|
||||
if (modem < 0)
|
||||
modem = OpenModem(mode);
|
||||
}
|
||||
|
||||
fflush(VarTerm);
|
||||
|
||||
timeout.tv_sec = 0;
|
||||
@ -743,99 +734,99 @@ DoLoop()
|
||||
reconnectState = RECON_UNKNOWN;
|
||||
|
||||
if (mode & MODE_BACKGROUND)
|
||||
dial_up = TRUE; /* Bring the line up */
|
||||
dial_up = TRUE; /* Bring the line up */
|
||||
else
|
||||
dial_up = FALSE; /* XXXX */
|
||||
dial_up = FALSE; /* XXXX */
|
||||
tries = 0;
|
||||
for (;;) {
|
||||
nfds = 0;
|
||||
FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&efds);
|
||||
|
||||
/*
|
||||
* If the link is down and we're in DDIAL mode, bring it back
|
||||
* up.
|
||||
*/
|
||||
if (mode & MODE_DDIAL && LcpFsm.state <= ST_CLOSED)
|
||||
dial_up = TRUE;
|
||||
FD_ZERO(&rfds);
|
||||
FD_ZERO(&wfds);
|
||||
FD_ZERO(&efds);
|
||||
|
||||
/*
|
||||
* If we lost carrier and want to re-establish the connection
|
||||
* due to the "set reconnect" value, we'd better bring the line
|
||||
* back up.
|
||||
* If the link is down and we're in DDIAL mode, bring it back up.
|
||||
*/
|
||||
if (mode & MODE_DDIAL && LcpFsm.state <= ST_CLOSED)
|
||||
dial_up = TRUE;
|
||||
|
||||
/*
|
||||
* If we lost carrier and want to re-establish the connection due to the
|
||||
* "set reconnect" value, we'd better bring the line back up.
|
||||
*/
|
||||
if (LcpFsm.state <= ST_CLOSED) {
|
||||
if (dial_up != TRUE && reconnectState == RECON_TRUE) {
|
||||
if (++reconnectCount <= VarReconnectTries) {
|
||||
LogPrintf(LogPHASE, "Connection lost, re-establish (%d/%d)\n",
|
||||
reconnectCount, VarReconnectTries);
|
||||
if (++reconnectCount <= VarReconnectTries) {
|
||||
LogPrintf(LogPHASE, "Connection lost, re-establish (%d/%d)\n",
|
||||
reconnectCount, VarReconnectTries);
|
||||
StartRedialTimer(VarReconnectTimer);
|
||||
dial_up = TRUE;
|
||||
} else {
|
||||
if (VarReconnectTries)
|
||||
LogPrintf(LogPHASE, "Connection lost, maximum (%d) times\n",
|
||||
VarReconnectTries);
|
||||
reconnectCount = 0;
|
||||
if (mode & MODE_BACKGROUND)
|
||||
Cleanup(EX_DEAD);
|
||||
}
|
||||
reconnectState = RECON_ENVOKED;
|
||||
dial_up = TRUE;
|
||||
} else {
|
||||
if (VarReconnectTries)
|
||||
LogPrintf(LogPHASE, "Connection lost, maximum (%d) times\n",
|
||||
VarReconnectTries);
|
||||
reconnectCount = 0;
|
||||
if (mode & MODE_BACKGROUND)
|
||||
Cleanup(EX_DEAD);
|
||||
}
|
||||
reconnectState = RECON_ENVOKED;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If Ip packet for output is enqueued and require dial up,
|
||||
* Just do it!
|
||||
*/
|
||||
if ( dial_up && RedialTimer.state != TIMER_RUNNING ) {
|
||||
/*
|
||||
* If Ip packet for output is enqueued and require dial up, Just do it!
|
||||
*/
|
||||
if (dial_up && RedialTimer.state != TIMER_RUNNING) {
|
||||
LogPrintf(LogDEBUG, "going to dial: modem = %d\n", modem);
|
||||
modem = OpenModem(mode);
|
||||
if (modem < 0) {
|
||||
tries++;
|
||||
if (!(mode & MODE_DDIAL) && VarDialTries)
|
||||
LogPrintf(LogCHAT, "Failed to open modem (attempt %u of %d)\n",
|
||||
tries, VarDialTries);
|
||||
else
|
||||
LogPrintf(LogCHAT, "Failed to open modem (attempt %u)\n", tries);
|
||||
tries++;
|
||||
if (!(mode & MODE_DDIAL) && VarDialTries)
|
||||
LogPrintf(LogCHAT, "Failed to open modem (attempt %u of %d)\n",
|
||||
tries, VarDialTries);
|
||||
else
|
||||
LogPrintf(LogCHAT, "Failed to open modem (attempt %u)\n", tries);
|
||||
|
||||
if (!(mode & MODE_DDIAL) && VarDialTries && tries >= VarDialTries) {
|
||||
if (mode & MODE_BACKGROUND)
|
||||
Cleanup(EX_DIAL); /* Can't get the modem */
|
||||
Cleanup(EX_DIAL); /* Can't get the modem */
|
||||
dial_up = FALSE;
|
||||
reconnectState = RECON_UNKNOWN;
|
||||
reconnectCount = 0;
|
||||
reconnectState = RECON_UNKNOWN;
|
||||
reconnectCount = 0;
|
||||
tries = 0;
|
||||
} else
|
||||
} else
|
||||
StartRedialTimer(VarRedialTimeout);
|
||||
} else {
|
||||
tries++; /* Tries are per number, not per list of numbers. */
|
||||
if (!(mode & MODE_DDIAL) && VarDialTries)
|
||||
tries++; /* Tries are per number, not per list of
|
||||
* numbers. */
|
||||
if (!(mode & MODE_DDIAL) && VarDialTries)
|
||||
LogPrintf(LogCHAT, "Dial attempt %u of %d\n", tries, VarDialTries);
|
||||
else
|
||||
LogPrintf(LogCHAT, "Dial attempt %u\n", tries);
|
||||
else
|
||||
LogPrintf(LogCHAT, "Dial attempt %u\n", tries);
|
||||
|
||||
if ((res = DialModem()) == EX_DONE) {
|
||||
sleep(1); /* little pause to allow peer starts */
|
||||
sleep(1); /* little pause to allow peer starts */
|
||||
ModemTimeout();
|
||||
PacketMode();
|
||||
dial_up = FALSE;
|
||||
reconnectState = RECON_UNKNOWN;
|
||||
reconnectState = RECON_UNKNOWN;
|
||||
tries = 0;
|
||||
} else {
|
||||
CloseModem();
|
||||
if (mode & MODE_BACKGROUND) {
|
||||
if (VarNextPhone == NULL || res == EX_SIG)
|
||||
Cleanup(EX_DIAL); /* Tried all numbers - no luck */
|
||||
Cleanup(EX_DIAL); /* Tried all numbers - no luck */
|
||||
else
|
||||
/* Try all numbers in background mode */
|
||||
StartRedialTimer(VarRedialNextTimeout);
|
||||
} else if (!(mode & MODE_DDIAL) &&
|
||||
((VarDialTries && tries >= VarDialTries) ||
|
||||
res == EX_SIG)) {
|
||||
((VarDialTries && tries >= VarDialTries) ||
|
||||
res == EX_SIG)) {
|
||||
/* I give up ! Can't get through :( */
|
||||
StartRedialTimer(VarRedialTimeout);
|
||||
dial_up = FALSE;
|
||||
reconnectState = RECON_UNKNOWN;
|
||||
reconnectCount = 0;
|
||||
reconnectState = RECON_UNKNOWN;
|
||||
reconnectCount = 0;
|
||||
tries = 0;
|
||||
} else if (VarNextPhone == NULL)
|
||||
/* Dial failed. Keep quite during redial wait period. */
|
||||
@ -851,7 +842,6 @@ DoLoop()
|
||||
IpStartOutput();
|
||||
qlen = ModemQlen();
|
||||
}
|
||||
|
||||
if (modem >= 0) {
|
||||
if (modem + 1 > nfds)
|
||||
nfds = modem + 1;
|
||||
@ -867,12 +857,13 @@ DoLoop()
|
||||
FD_SET(server, &rfds);
|
||||
}
|
||||
|
||||
/* *** IMPORTANT ***
|
||||
*
|
||||
* CPU is serviced every TICKUNIT micro seconds.
|
||||
* This value must be chosen with great care. If this values is
|
||||
* too big, it results loss of characters from modem and poor responce.
|
||||
* If this values is too small, ppp process eats many CPU time.
|
||||
/*
|
||||
* *** IMPORTANT ***
|
||||
*
|
||||
* CPU is serviced every TICKUNIT micro seconds. This value must be chosen
|
||||
* with great care. If this values is too big, it results loss of
|
||||
* characters from modem and poor responce. If this values is too small,
|
||||
* ppp process eats many CPU time.
|
||||
*/
|
||||
#ifndef SIGALRM
|
||||
usleep(TICKUNIT);
|
||||
@ -887,55 +878,52 @@ DoLoop()
|
||||
nfds = tun_in + 1;
|
||||
FD_SET(tun_in, &rfds);
|
||||
}
|
||||
|
||||
if (netfd >= 0) {
|
||||
if (netfd + 1 > nfds)
|
||||
nfds = netfd + 1;
|
||||
FD_SET(netfd, &rfds);
|
||||
FD_SET(netfd, &efds);
|
||||
}
|
||||
|
||||
#ifndef SIGALRM
|
||||
|
||||
/*
|
||||
* Normally, select() will not block because modem is writable.
|
||||
* In AUTO mode, select will block until we find packet from tun
|
||||
* Normally, select() will not block because modem is writable. In AUTO
|
||||
* mode, select will block until we find packet from tun
|
||||
*/
|
||||
tp = (RedialTimer.state == TIMER_RUNNING)? &timeout : NULL;
|
||||
tp = (RedialTimer.state == TIMER_RUNNING) ? &timeout : NULL;
|
||||
i = select(nfds, &rfds, &wfds, &efds, tp);
|
||||
#else
|
||||
|
||||
/*
|
||||
* When SIGALRM timer is running, a select function will be
|
||||
* return -1 and EINTR after a Time Service signal hundler
|
||||
* is done. If the redial timer is not running and we are
|
||||
* trying to dial, poll with a 0 value timer.
|
||||
* When SIGALRM timer is running, a select function will be return -1 and
|
||||
* EINTR after a Time Service signal hundler is done. If the redial
|
||||
* timer is not running and we are trying to dial, poll with a 0 value
|
||||
* timer.
|
||||
*/
|
||||
tp = (dial_up && RedialTimer.state != TIMER_RUNNING) ? &timeout : NULL;
|
||||
i = select(nfds, &rfds, &wfds, &efds, tp);
|
||||
#endif
|
||||
|
||||
if ( i == 0 ) {
|
||||
continue;
|
||||
if (i == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( i < 0 ) {
|
||||
if ( errno == EINTR ) {
|
||||
handle_signals();
|
||||
continue;
|
||||
}
|
||||
LogPrintf(LogERROR, "select: %s", strerror(errno));
|
||||
break;
|
||||
if (i < 0) {
|
||||
if (errno == EINTR) {
|
||||
handle_signals();
|
||||
continue;
|
||||
}
|
||||
LogPrintf(LogERROR, "select: %s", strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
if ((netfd >= 0 && FD_ISSET(netfd, &efds)) || (modem >= 0 && FD_ISSET(modem, &efds))) {
|
||||
LogPrintf(LogALERT, "Exception detected.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (server >= 0 && FD_ISSET(server, &rfds)) {
|
||||
LogPrintf(LogPHASE, "connected to client.\n");
|
||||
wfd = accept(server, (struct sockaddr *)&hisaddr, &ssize);
|
||||
wfd = accept(server, (struct sockaddr *) & hisaddr, &ssize);
|
||||
if (wfd < 0) {
|
||||
LogPrintf(LogERROR, "accept: %s", strerror(errno));
|
||||
LogPrintf(LogERROR, "accept: %s", strerror(errno));
|
||||
continue;
|
||||
}
|
||||
if (netfd >= 0) {
|
||||
@ -947,24 +935,23 @@ DoLoop()
|
||||
VarTerm = fdopen(netfd, "a+");
|
||||
mode |= MODE_INTER;
|
||||
Greetings();
|
||||
switch ( LocalAuthInit() ) {
|
||||
case NOT_FOUND:
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm,LAUTH_M1);
|
||||
fprintf(VarTerm,LAUTH_M2);
|
||||
fflush(VarTerm);
|
||||
}
|
||||
/* Fall down */
|
||||
case VALID:
|
||||
VarLocalAuth = LOCAL_AUTH;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (LocalAuthInit()) {
|
||||
case NOT_FOUND:
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, LAUTH_M1);
|
||||
fprintf(VarTerm, LAUTH_M2);
|
||||
fflush(VarTerm);
|
||||
}
|
||||
/* Fall down */
|
||||
case VALID:
|
||||
VarLocalAuth = LOCAL_AUTH;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
(void) IsInteractive();
|
||||
Prompt();
|
||||
}
|
||||
|
||||
if ((mode & MODE_INTER) && (netfd >= 0 && FD_ISSET(netfd, &rfds)) &&
|
||||
((mode & MODE_AUTO) || pgroup == tcgetpgrp(0))) {
|
||||
/* something to read from tty */
|
||||
@ -972,7 +959,7 @@ DoLoop()
|
||||
}
|
||||
if (modem >= 0) {
|
||||
if (FD_ISSET(modem, &wfds)) { /* ready to write into modem */
|
||||
ModemStartOutput(modem);
|
||||
ModemStartOutput(modem);
|
||||
}
|
||||
if (FD_ISSET(modem, &rfds)) { /* something to read from modem */
|
||||
if (LcpFsm.state <= ST_CLOSED)
|
||||
@ -981,21 +968,23 @@ DoLoop()
|
||||
if ((mode & MODE_DIRECT) && n <= 0) {
|
||||
DownConnection();
|
||||
} else
|
||||
LogDumpBuff(LogASYNC, "ReadFromModem", rbuff, n);
|
||||
LogDumpBuff(LogASYNC, "ReadFromModem", rbuff, n);
|
||||
|
||||
if (LcpFsm.state <= ST_CLOSED) {
|
||||
|
||||
/*
|
||||
* In dedicated mode, we just discard input until LCP is started.
|
||||
* In dedicated mode, we just discard input until LCP is started.
|
||||
*/
|
||||
if (!(mode & MODE_DEDICATED)) {
|
||||
cp = HdlcDetect(rbuff, n);
|
||||
if (cp) {
|
||||
|
||||
/*
|
||||
* LCP packet is detected. Turn ourselves into packet mode.
|
||||
*/
|
||||
if (cp != rbuff) {
|
||||
write(modem, rbuff, cp - rbuff);
|
||||
write(modem, "\r\n", 2);
|
||||
write(modem, rbuff, cp - rbuff);
|
||||
write(modem, "\r\n", 2);
|
||||
}
|
||||
PacketMode();
|
||||
} else
|
||||
@ -1007,23 +996,23 @@ DoLoop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tun_in >= 0 && FD_ISSET(tun_in, &rfds)) { /* something to read from tun */
|
||||
if (tun_in >= 0 && FD_ISSET(tun_in, &rfds)) { /* something to read
|
||||
* from tun */
|
||||
n = read(tun_in, rbuff, sizeof(rbuff));
|
||||
if (n < 0) {
|
||||
LogPrintf(LogERROR, "read from tun: %s", strerror(errno));
|
||||
LogPrintf(LogERROR, "read from tun: %s", strerror(errno));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (((struct ip *)rbuff)->ip_dst.s_addr == IpcpInfo.want_ipaddr.s_addr) {
|
||||
if (((struct ip *) rbuff)->ip_dst.s_addr == IpcpInfo.want_ipaddr.s_addr) {
|
||||
/* we've been asked to send something addressed *to* us :( */
|
||||
if (VarLoopback) {
|
||||
pri = PacketCheck(rbuff, n, FL_IN);
|
||||
if (pri >= 0) {
|
||||
struct mbuf *bp;
|
||||
|
||||
if (mode & MODE_ALIAS) {
|
||||
VarPacketAliasIn(rbuff, sizeof rbuff);
|
||||
n = ntohs(((struct ip *)rbuff)->ip_len);
|
||||
n = ntohs(((struct ip *) rbuff)->ip_len);
|
||||
}
|
||||
bp = mballoc(n, MB_IPIN);
|
||||
bcopy(rbuff, MBUF_CTOP(bp), n);
|
||||
@ -1031,32 +1020,32 @@ DoLoop()
|
||||
LogPrintf(LogDEBUG, "Looped back packet addressed to myself\n");
|
||||
}
|
||||
continue;
|
||||
} else
|
||||
} else
|
||||
LogPrintf(LogDEBUG, "Oops - forwarding packet addressed to myself\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Process on-demand dialup. Output packets are queued within tunnel
|
||||
* device until IPCP is opened.
|
||||
* Process on-demand dialup. Output packets are queued within tunnel
|
||||
* device until IPCP is opened.
|
||||
*/
|
||||
if (LcpFsm.state <= ST_CLOSED && (mode & MODE_AUTO)) {
|
||||
pri = PacketCheck(rbuff, n, FL_DIAL);
|
||||
if (pri >= 0) {
|
||||
if (mode & MODE_ALIAS) {
|
||||
VarPacketAliasOut(rbuff, sizeof rbuff);
|
||||
n = ntohs(((struct ip *)rbuff)->ip_len);
|
||||
n = ntohs(((struct ip *) rbuff)->ip_len);
|
||||
}
|
||||
IpEnqueue(pri, rbuff, n);
|
||||
dial_up = TRUE; /* XXX */
|
||||
dial_up = TRUE; /* XXX */
|
||||
}
|
||||
continue;
|
||||
}
|
||||
pri = PacketCheck(rbuff, n, FL_OUT);
|
||||
if (pri >= 0) {
|
||||
if (mode & MODE_ALIAS) {
|
||||
VarPacketAliasOut(rbuff, sizeof rbuff);
|
||||
n = ntohs(((struct ip *)rbuff)->ip_len);
|
||||
}
|
||||
if (mode & MODE_ALIAS) {
|
||||
VarPacketAliasOut(rbuff, sizeof rbuff);
|
||||
n = ntohs(((struct ip *) rbuff)->ip_len);
|
||||
}
|
||||
IpEnqueue(pri, rbuff, n);
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,12 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: main.h,v 1.3 1997/02/22 16:10:33 peter Exp $
|
||||
* $Id: main.h,v 1.4 1997/06/09 03:27:28 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _MAIN_H_
|
||||
#define _MAIN_H_
|
||||
void Cleanup(int);
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: mbuf.c,v 1.7 1997/06/09 03:27:29 brian Exp $
|
||||
* $Id: mbuf.c,v 1.8 1997/06/25 19:30:02 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
@ -31,40 +31,37 @@
|
||||
|
||||
struct memmap {
|
||||
struct mbuf *queue;
|
||||
int count;
|
||||
} MemMap[MB_MAX+2];
|
||||
int count;
|
||||
} MemMap[MB_MAX + 2];
|
||||
|
||||
static int totalalloced;
|
||||
|
||||
int
|
||||
plength(bp)
|
||||
struct mbuf *bp;
|
||||
plength(struct mbuf * bp)
|
||||
{
|
||||
int len;
|
||||
|
||||
for (len = 0; bp; bp = bp->next)
|
||||
len += bp->cnt;
|
||||
return(len);
|
||||
return (len);
|
||||
}
|
||||
|
||||
struct mbuf *
|
||||
mballoc(cnt, type)
|
||||
int cnt;
|
||||
int type;
|
||||
mballoc(int cnt, int type)
|
||||
{
|
||||
u_char *p;
|
||||
struct mbuf *bp;
|
||||
|
||||
if (type > MB_MAX)
|
||||
LogPrintf(LogERROR, "Bad mbuf type %d\n", type);
|
||||
bp = (struct mbuf *)malloc(sizeof(struct mbuf));
|
||||
bp = (struct mbuf *) malloc(sizeof(struct mbuf));
|
||||
if (bp == NULL) {
|
||||
LogPrintf(LogALERT, "failed to allocate memory: %u\n", sizeof(struct mbuf));
|
||||
ServerClose();
|
||||
exit(1);
|
||||
}
|
||||
bzero(bp, sizeof(struct mbuf));
|
||||
p = (u_char *)malloc(cnt);
|
||||
p = (u_char *) malloc(cnt);
|
||||
if (p == NULL) {
|
||||
LogPrintf(LogALERT, "failed to allocate memory: %d\n", cnt);
|
||||
ServerClose();
|
||||
@ -75,11 +72,11 @@ int type;
|
||||
bp->base = p;
|
||||
bp->size = bp->cnt = cnt;
|
||||
bp->type = type;
|
||||
return(bp);
|
||||
return (bp);
|
||||
}
|
||||
|
||||
struct mbuf *
|
||||
mbfree(struct mbuf *bp)
|
||||
mbfree(struct mbuf * bp)
|
||||
{
|
||||
struct mbuf *nbp;
|
||||
|
||||
@ -89,23 +86,20 @@ mbfree(struct mbuf *bp)
|
||||
totalalloced -= bp->size;
|
||||
free(bp->base);
|
||||
free(bp);
|
||||
return(nbp);
|
||||
return (nbp);
|
||||
}
|
||||
return(bp);
|
||||
return (bp);
|
||||
}
|
||||
|
||||
void
|
||||
pfree(struct mbuf *bp)
|
||||
pfree(struct mbuf * bp)
|
||||
{
|
||||
while (bp)
|
||||
bp = mbfree(bp);
|
||||
}
|
||||
|
||||
struct mbuf *
|
||||
mbread(bp, ptr, len)
|
||||
struct mbuf *bp;
|
||||
u_char *ptr;
|
||||
int len;
|
||||
mbread(struct mbuf * bp, u_char * ptr, int len)
|
||||
{
|
||||
int nb;
|
||||
|
||||
@ -127,14 +121,11 @@ int len;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return(bp);
|
||||
return (bp);
|
||||
}
|
||||
|
||||
void
|
||||
mbwrite(bp, ptr, cnt)
|
||||
struct mbuf *bp;
|
||||
u_char *ptr;
|
||||
int cnt;
|
||||
mbwrite(struct mbuf * bp, u_char * ptr, int cnt)
|
||||
{
|
||||
int plen;
|
||||
int nb;
|
||||
@ -144,7 +135,7 @@ int cnt;
|
||||
cnt = plen;
|
||||
|
||||
while (cnt > 0) {
|
||||
nb = (cnt < bp->cnt)? cnt : bp->cnt;
|
||||
nb = (cnt < bp->cnt) ? cnt : bp->cnt;
|
||||
bcopy(ptr, MBUF_CTOP(bp), nb);
|
||||
cnt -= bp->cnt;
|
||||
bp = bp->next;
|
||||
@ -161,7 +152,7 @@ ShowMemMap()
|
||||
|
||||
for (i = 0; i <= MB_MAX; i += 2)
|
||||
fprintf(VarTerm, "%d: %d %d: %d\n",
|
||||
i, MemMap[i].count, i+1, MemMap[i+1].count);
|
||||
i, MemMap[i].count, i + 1, MemMap[i + 1].count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: mbuf.h,v 1.4 1997/02/22 16:10:35 peter Exp $
|
||||
* $Id: mbuf.h,v 1.5 1997/06/09 03:27:29 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -24,13 +24,13 @@
|
||||
#define _MBUF_H_
|
||||
|
||||
struct mbuf {
|
||||
u_char *base; /* pointer to top of buffer space */
|
||||
short size; /* size allocated from base */
|
||||
short offset; /* offset to start position */
|
||||
short cnt; /* available byte count in buffer */
|
||||
u_char *base; /* pointer to top of buffer space */
|
||||
short size; /* size allocated from base */
|
||||
short offset; /* offset to start position */
|
||||
short cnt; /* available byte count in buffer */
|
||||
short type;
|
||||
struct mbuf *next; /* link to next mbuf */
|
||||
struct mbuf *pnext; /* link to next packet */
|
||||
struct mbuf *next; /* link to next mbuf */
|
||||
struct mbuf *pnext; /* link to next packet */
|
||||
};
|
||||
|
||||
struct mqueue {
|
||||
@ -55,15 +55,16 @@ struct mqueue {
|
||||
#define MB_IPQ 10
|
||||
#define MB_MAX MB_IPQ
|
||||
|
||||
extern int plength(struct mbuf *bp);
|
||||
extern int plength(struct mbuf * bp);
|
||||
extern struct mbuf *mballoc(int cnt, int type);
|
||||
extern struct mbuf *mbfree(struct mbuf *bp);
|
||||
extern void pfree(struct mbuf *bp);
|
||||
extern void mbwrite(struct mbuf *bp, u_char *ptr, int cnt);
|
||||
extern struct mbuf *mbread(struct mbuf *bp, u_char *ptr, int cnt);
|
||||
extern void DumpBp(struct mbuf *bp);
|
||||
extern void Enqueue(struct mqueue *queue, struct mbuf *bp);
|
||||
extern struct mbuf *Dequeue(struct mqueue *queue);
|
||||
extern struct mbuf *mbfree(struct mbuf * bp);
|
||||
extern void pfree(struct mbuf * bp);
|
||||
extern void mbwrite(struct mbuf * bp, u_char * ptr, int cnt);
|
||||
extern struct mbuf *mbread(struct mbuf * bp, u_char * ptr, int cnt);
|
||||
extern void DumpBp(struct mbuf * bp);
|
||||
extern void Enqueue(struct mqueue * queue, struct mbuf * bp);
|
||||
extern struct mbuf *Dequeue(struct mqueue * queue);
|
||||
extern void LogMemory();
|
||||
extern int ShowMemMap();
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: modem.c,v 1.47 1997/08/17 20:38:43 brian Exp $
|
||||
* $Id: modem.c,v 1.48 1997/08/23 23:14:23 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -47,7 +47,7 @@
|
||||
|
||||
extern int DoChat();
|
||||
|
||||
static int mbits; /* Current DCD status */
|
||||
static int mbits; /* Current DCD status */
|
||||
static int connect_count;
|
||||
static struct pppTimer ModemTimer;
|
||||
|
||||
@ -57,13 +57,11 @@ extern int TermMode;
|
||||
#define Online (mbits & TIOCM_CD)
|
||||
|
||||
static struct mbuf *modemout;
|
||||
static struct mqueue OutputQueues[PRI_LINK+1];
|
||||
static struct mqueue OutputQueues[PRI_LINK + 1];
|
||||
static int dev_is_modem;
|
||||
|
||||
void
|
||||
Enqueue(queue, bp)
|
||||
struct mqueue *queue;
|
||||
struct mbuf *bp;
|
||||
Enqueue(struct mqueue * queue, struct mbuf * bp)
|
||||
{
|
||||
if (queue->last) {
|
||||
queue->last->pnext = bp;
|
||||
@ -75,8 +73,7 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
struct mbuf *
|
||||
Dequeue(queue)
|
||||
struct mqueue *queue;
|
||||
Dequeue(struct mqueue * queue)
|
||||
{
|
||||
struct mbuf *bp;
|
||||
|
||||
@ -91,111 +88,162 @@ struct mqueue *queue;
|
||||
LogPrintf(LogDEBUG, "Dequeue: Not zero (%d)!!!\n", queue->qlen);
|
||||
}
|
||||
}
|
||||
return(bp);
|
||||
return (bp);
|
||||
}
|
||||
|
||||
static struct speeds{
|
||||
static struct speeds {
|
||||
int nspeed;
|
||||
speed_t speed;
|
||||
} speeds[] = {
|
||||
} speeds[] = {
|
||||
|
||||
#ifdef B50
|
||||
{ 50, B50, },
|
||||
{
|
||||
50, B50,
|
||||
},
|
||||
#endif
|
||||
#ifdef B75
|
||||
{ 75, B75, },
|
||||
{
|
||||
75, B75,
|
||||
},
|
||||
#endif
|
||||
#ifdef B110
|
||||
{ 110, B110, },
|
||||
{
|
||||
110, B110,
|
||||
},
|
||||
#endif
|
||||
#ifdef B134
|
||||
{ 134, B134, },
|
||||
{
|
||||
134, B134,
|
||||
},
|
||||
#endif
|
||||
#ifdef B150
|
||||
{ 150, B150, },
|
||||
{
|
||||
150, B150,
|
||||
},
|
||||
#endif
|
||||
#ifdef B200
|
||||
{ 200, B200, },
|
||||
{
|
||||
200, B200,
|
||||
},
|
||||
#endif
|
||||
#ifdef B300
|
||||
{ 300, B300, },
|
||||
{
|
||||
300, B300,
|
||||
},
|
||||
#endif
|
||||
#ifdef B600
|
||||
{ 600, B600, },
|
||||
{
|
||||
600, B600,
|
||||
},
|
||||
#endif
|
||||
#ifdef B1200
|
||||
{ 1200, B1200, },
|
||||
{
|
||||
1200, B1200,
|
||||
},
|
||||
#endif
|
||||
#ifdef B1800
|
||||
{ 1800, B1800, },
|
||||
{
|
||||
1800, B1800,
|
||||
},
|
||||
#endif
|
||||
#ifdef B2400
|
||||
{ 2400, B2400, },
|
||||
{
|
||||
2400, B2400,
|
||||
},
|
||||
#endif
|
||||
#ifdef B4800
|
||||
{ 4800, B4800, },
|
||||
{
|
||||
4800, B4800,
|
||||
},
|
||||
#endif
|
||||
#ifdef B9600
|
||||
{ 9600, B9600, },
|
||||
{
|
||||
9600, B9600,
|
||||
},
|
||||
#endif
|
||||
#ifdef B19200
|
||||
{ 19200, B19200, },
|
||||
{
|
||||
19200, B19200,
|
||||
},
|
||||
#endif
|
||||
#ifdef B38400
|
||||
{ 38400, B38400, },
|
||||
{
|
||||
38400, B38400,
|
||||
},
|
||||
#endif
|
||||
#ifndef _POSIX_SOURCE
|
||||
#ifdef B7200
|
||||
{ 7200, B7200, },
|
||||
{
|
||||
7200, B7200,
|
||||
},
|
||||
#endif
|
||||
#ifdef B14400
|
||||
{ 14400, B14400, },
|
||||
{
|
||||
14400, B14400,
|
||||
},
|
||||
#endif
|
||||
#ifdef B28800
|
||||
{ 28800, B28800, },
|
||||
{
|
||||
28800, B28800,
|
||||
},
|
||||
#endif
|
||||
#ifdef B57600
|
||||
{ 57600, B57600, },
|
||||
{
|
||||
57600, B57600,
|
||||
},
|
||||
#endif
|
||||
#ifdef B76800
|
||||
{ 76800, B76800, },
|
||||
{
|
||||
76800, B76800,
|
||||
},
|
||||
#endif
|
||||
#ifdef B115200
|
||||
{ 115200, B115200, },
|
||||
{
|
||||
115200, B115200,
|
||||
},
|
||||
#endif
|
||||
#ifdef B230400
|
||||
{ 230400, B230400, },
|
||||
{
|
||||
230400, B230400,
|
||||
},
|
||||
#endif
|
||||
#ifdef EXTA
|
||||
{ 19200, EXTA, },
|
||||
{
|
||||
19200, EXTA,
|
||||
},
|
||||
#endif
|
||||
#ifdef EXTB
|
||||
{ 38400, EXTB, },
|
||||
{
|
||||
38400, EXTB,
|
||||
},
|
||||
#endif
|
||||
#endif /*_POSIX_SOURCE */
|
||||
{ 0, 0 }
|
||||
#endif /* _POSIX_SOURCE */
|
||||
{
|
||||
0, 0
|
||||
}
|
||||
};
|
||||
|
||||
int SpeedToInt(speed)
|
||||
speed_t speed;
|
||||
int
|
||||
SpeedToInt(speed_t speed)
|
||||
{
|
||||
struct speeds *sp;
|
||||
|
||||
for (sp = speeds; sp->nspeed; sp++) {
|
||||
if (sp->speed == speed) {
|
||||
return(sp->nspeed);
|
||||
return (sp->nspeed);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
speed_t IntToSpeed(nspeed)
|
||||
int nspeed;
|
||||
speed_t
|
||||
IntToSpeed(int nspeed)
|
||||
{
|
||||
struct speeds *sp;
|
||||
|
||||
for (sp = speeds; sp->nspeed; sp++) {
|
||||
if (sp->nspeed == nspeed) {
|
||||
return(sp->speed);
|
||||
return (sp->speed);
|
||||
}
|
||||
}
|
||||
return B0;
|
||||
@ -212,7 +260,7 @@ DownConnection()
|
||||
if (uptime)
|
||||
LogPrintf(LogPHASE, "Connect time: %d secs\n", time(NULL) - uptime);
|
||||
uptime = 0;
|
||||
strcpy(ScriptBuffer, VarHangupScript); /* arrays are the same size */
|
||||
strcpy(ScriptBuffer, VarHangupScript); /* arrays are the same size */
|
||||
DoChat(ScriptBuffer);
|
||||
if (!TermMode) {
|
||||
CloseModem();
|
||||
@ -236,26 +284,27 @@ ModemTimeout()
|
||||
if (dev_is_modem) {
|
||||
if (modem >= 0) {
|
||||
if (ioctl(modem, TIOCMGET, &mbits) < 0) {
|
||||
LogPrintf(LogPHASE, "ioctl error (%s)!\n", strerror(errno));
|
||||
DownConnection();
|
||||
return;
|
||||
LogPrintf(LogPHASE, "ioctl error (%s)!\n", strerror(errno));
|
||||
DownConnection();
|
||||
return;
|
||||
}
|
||||
} else
|
||||
mbits = 0;
|
||||
change = ombits ^ mbits;
|
||||
if (change & TIOCM_CD) {
|
||||
if (Online) {
|
||||
time(&uptime);
|
||||
LogPrintf(LogPHASE, "*Connected!\n");
|
||||
connect_count++;
|
||||
/*
|
||||
* In dedicated mode, start packet mode immediate
|
||||
* after we detected carrier.
|
||||
*/
|
||||
if (mode & MODE_DEDICATED)
|
||||
time(&uptime);
|
||||
LogPrintf(LogPHASE, "*Connected!\n");
|
||||
connect_count++;
|
||||
|
||||
/*
|
||||
* In dedicated mode, start packet mode immediate after we detected
|
||||
* carrier.
|
||||
*/
|
||||
if (mode & MODE_DEDICATED)
|
||||
PacketMode();
|
||||
} else {
|
||||
reconnect(RECON_TRUE);
|
||||
reconnect(RECON_TRUE);
|
||||
DownConnection();
|
||||
}
|
||||
}
|
||||
@ -284,15 +333,23 @@ StartModemTimer()
|
||||
struct parity {
|
||||
char *name;
|
||||
char *name1;
|
||||
int set;
|
||||
} validparity[] = {
|
||||
{ "even", "P_EVEN", CS7 | PARENB }, { "odd", "P_ODD", CS7 | PARENB | PARODD },
|
||||
{ "none", "P_ZERO", CS8 }, { NULL, 0 },
|
||||
int set;
|
||||
} validparity[] = {
|
||||
|
||||
{
|
||||
"even", "P_EVEN", CS7 | PARENB
|
||||
}, {
|
||||
"odd", "P_ODD", CS7 | PARENB | PARODD
|
||||
},
|
||||
{
|
||||
"none", "P_ZERO", CS8
|
||||
}, {
|
||||
NULL, 0
|
||||
},
|
||||
};
|
||||
|
||||
int
|
||||
GetParityValue(str)
|
||||
char *str;
|
||||
GetParityValue(char *str)
|
||||
{
|
||||
struct parity *pp;
|
||||
|
||||
@ -302,12 +359,11 @@ char *str;
|
||||
return VarParity = pp->set;
|
||||
}
|
||||
}
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
ChangeParity(str)
|
||||
char *str;
|
||||
ChangeParity(char *str)
|
||||
{
|
||||
struct termios rstio;
|
||||
int val;
|
||||
@ -316,7 +372,7 @@ char *str;
|
||||
if (val > 0) {
|
||||
VarParity = val;
|
||||
tcgetattr(modem, &rstio);
|
||||
rstio.c_cflag &= ~(CSIZE|PARODD|PARENB);
|
||||
rstio.c_cflag &= ~(CSIZE | PARODD | PARENB);
|
||||
rstio.c_cflag |= val;
|
||||
tcsetattr(modem, TCSADRAIN, &rstio);
|
||||
return 0;
|
||||
@ -326,8 +382,7 @@ char *str;
|
||||
}
|
||||
|
||||
int
|
||||
OpenConnection(host, port)
|
||||
char *host, *port;
|
||||
OpenConnection(char *host, char *port)
|
||||
{
|
||||
struct sockaddr_in dest;
|
||||
int sock;
|
||||
@ -342,7 +397,7 @@ char *host, *port;
|
||||
bcopy(hp->h_addr_list[0], &dest.sin_addr.s_addr, 4);
|
||||
} else {
|
||||
LogPrintf(LogWARN, "OpenConnection: unknown host: %s\n", host);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
dest.sin_port = htons(atoi(port));
|
||||
@ -352,28 +407,27 @@ char *host, *port;
|
||||
dest.sin_port = sp->s_port;
|
||||
} else {
|
||||
LogPrintf(LogWARN, "OpenConnection: unknown service: %s\n", port);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
LogPrintf(LogPHASE, "Connected to %s:%s\n", host, port);
|
||||
|
||||
sock = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if (sock < 0) {
|
||||
return(sock);
|
||||
return (sock);
|
||||
}
|
||||
if (connect(sock, (struct sockaddr *)&dest, sizeof(dest)) < 0) {
|
||||
if (connect(sock, (struct sockaddr *) & dest, sizeof(dest)) < 0) {
|
||||
LogPrintf(LogWARN, "OpenConnection: connection failed.\n");
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
LogPrintf(LogDEBUG, "OpenConnection: modem fd is %d.\n", sock);
|
||||
return(sock);
|
||||
return (sock);
|
||||
}
|
||||
|
||||
static struct termios modemios;
|
||||
|
||||
int
|
||||
OpenModem(mode)
|
||||
int mode;
|
||||
OpenModem(int mode)
|
||||
{
|
||||
struct termios rstio;
|
||||
int oldflag;
|
||||
@ -383,29 +437,29 @@ int mode;
|
||||
mbits = 0;
|
||||
if (mode & MODE_DIRECT) {
|
||||
if (isatty(0)) {
|
||||
modem = open(ctermid(NULL), O_RDWR|O_NONBLOCK);
|
||||
modem = open(ctermid(NULL), O_RDWR | O_NONBLOCK);
|
||||
if (modem < 0) {
|
||||
LogPrintf(LogPHASE, "Open Failed %s\n", ctermid(NULL));
|
||||
return(modem);
|
||||
return (modem);
|
||||
}
|
||||
} else
|
||||
/* must be a tcp connection */
|
||||
return modem = dup(1);
|
||||
/* must be a tcp connection */
|
||||
return modem = dup(1);
|
||||
} else if (modem < 0) {
|
||||
if (strncmp(VarDevice, "/dev/", 5) == 0) {
|
||||
if ((res = uu_lock(VarBaseDevice)) != UU_LOCK_OK) {
|
||||
if (res == UU_LOCK_INUSE)
|
||||
LogPrintf(LogPHASE, "Modem %s is in use\n", VarDevice);
|
||||
else
|
||||
LogPrintf(LogPHASE, "Modem %s is in use: uu_lock: %s\n",
|
||||
VarDevice, uu_lockerr(res));
|
||||
return(-1);
|
||||
if (res == UU_LOCK_INUSE)
|
||||
LogPrintf(LogPHASE, "Modem %s is in use\n", VarDevice);
|
||||
else
|
||||
LogPrintf(LogPHASE, "Modem %s is in use: uu_lock: %s\n",
|
||||
VarDevice, uu_lockerr(res));
|
||||
return (-1);
|
||||
}
|
||||
modem = open(VarDevice, O_RDWR|O_NONBLOCK);
|
||||
modem = open(VarDevice, O_RDWR | O_NONBLOCK);
|
||||
if (modem < 0) {
|
||||
LogPrintf(LogPHASE, "Open Failed %s\n", VarDevice);
|
||||
(void) uu_unlock(VarBaseDevice);
|
||||
return(modem);
|
||||
LogPrintf(LogPHASE, "Open Failed %s\n", VarDevice);
|
||||
(void) uu_unlock(VarBaseDevice);
|
||||
return (modem);
|
||||
}
|
||||
} else {
|
||||
/* XXX: PPP over TCP */
|
||||
@ -413,24 +467,25 @@ int mode;
|
||||
if (cp) {
|
||||
*cp = 0;
|
||||
host = VarDevice;
|
||||
port = cp + 1;
|
||||
port = cp + 1;
|
||||
if (*host && *port) {
|
||||
modem = OpenConnection(host, port);
|
||||
*cp = ':'; /* Don't destroy VarDevice */
|
||||
if (modem < 0) return(-1);
|
||||
*cp = ':'; /* Don't destroy VarDevice */
|
||||
if (modem < 0)
|
||||
return (-1);
|
||||
} else {
|
||||
*cp = ':'; /* Don't destroy VarDevice */
|
||||
return(-1);
|
||||
*cp = ':'; /* Don't destroy VarDevice */
|
||||
return (-1);
|
||||
}
|
||||
} else
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If we are working on tty device, change it's mode into
|
||||
* the one desired for further operation. In this implementation,
|
||||
* we assume that modem is configuted to use CTS/RTS flow control.
|
||||
* If we are working on tty device, change it's mode into the one desired
|
||||
* for further operation. In this implementation, we assume that modem is
|
||||
* configuted to use CTS/RTS flow control.
|
||||
*/
|
||||
dev_is_modem = isatty(modem) || DEV_IS_SYNC;
|
||||
if (DEV_IS_SYNC)
|
||||
@ -443,19 +498,20 @@ int mode;
|
||||
" cflag = %x\n", rstio.c_iflag, rstio.c_oflag, rstio.c_cflag);
|
||||
cfmakeraw(&rstio);
|
||||
if (VarCtsRts)
|
||||
rstio.c_cflag |= CLOCAL | CCTS_OFLOW|CRTS_IFLOW;
|
||||
rstio.c_cflag |= CLOCAL | CCTS_OFLOW | CRTS_IFLOW;
|
||||
else {
|
||||
rstio.c_cflag |= CLOCAL;
|
||||
rstio.c_iflag |= IXOFF;
|
||||
rstio.c_cflag |= CLOCAL;
|
||||
rstio.c_iflag |= IXOFF;
|
||||
}
|
||||
rstio.c_iflag |= IXON;
|
||||
if (!(mode & MODE_DEDICATED))
|
||||
rstio.c_cflag |= HUPCL;
|
||||
if ((mode & MODE_DIRECT) == 0) {
|
||||
|
||||
/*
|
||||
* If we are working as direct mode, don't change tty speed.
|
||||
*/
|
||||
rstio.c_cflag &= ~(CSIZE|PARODD|PARENB);
|
||||
rstio.c_cflag &= ~(CSIZE | PARODD | PARENB);
|
||||
rstio.c_cflag |= VarParity;
|
||||
if (cfsetspeed(&rstio, IntToSpeed(VarSpeed)) == -1) {
|
||||
LogPrintf(LogWARN, "Unable to set modem speed (modem %d to %d)\n",
|
||||
@ -464,21 +520,21 @@ int mode;
|
||||
}
|
||||
tcsetattr(modem, TCSADRAIN, &rstio);
|
||||
LogPrintf(LogDEBUG, "modem (put): iflag = %x, oflag = %x, cflag = %x\n",
|
||||
rstio.c_iflag, rstio.c_oflag, rstio.c_cflag);
|
||||
rstio.c_iflag, rstio.c_oflag, rstio.c_cflag);
|
||||
|
||||
if (!(mode & MODE_DIRECT))
|
||||
if (ioctl(modem, TIOCMGET, &mbits))
|
||||
return(-1);
|
||||
return (-1);
|
||||
LogPrintf(LogDEBUG, "OpenModem: modem control = %o\n", mbits);
|
||||
|
||||
oldflag = fcntl(modem, F_GETFL, 0);
|
||||
if (oldflag < 0)
|
||||
return(-1);
|
||||
(void)fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
|
||||
return (-1);
|
||||
(void) fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
|
||||
}
|
||||
StartModemTimer();
|
||||
|
||||
return(modem);
|
||||
return (modem);
|
||||
}
|
||||
|
||||
int
|
||||
@ -487,44 +543,42 @@ ModemSpeed()
|
||||
struct termios rstio;
|
||||
|
||||
tcgetattr(modem, &rstio);
|
||||
return(SpeedToInt(cfgetispeed(&rstio)));
|
||||
return (SpeedToInt(cfgetispeed(&rstio)));
|
||||
}
|
||||
|
||||
/*
|
||||
* Put modem tty line into raw mode which is necessary in packet mode operation
|
||||
*/
|
||||
int
|
||||
RawModem(modem)
|
||||
int modem;
|
||||
RawModem(int modem)
|
||||
{
|
||||
struct termios rstio;
|
||||
int oldflag;
|
||||
|
||||
if (!isatty(modem) || DEV_IS_SYNC)
|
||||
return(0);
|
||||
return (0);
|
||||
if (!(mode & MODE_DIRECT) && modem >= 0 && !Online) {
|
||||
LogPrintf(LogDEBUG, "RawModem: mode = %d, modem = %d, mbits = %x\n", mode, modem, mbits);
|
||||
}
|
||||
tcgetattr(modem, &rstio);
|
||||
cfmakeraw(&rstio);
|
||||
if (VarCtsRts)
|
||||
rstio.c_cflag |= CLOCAL | CCTS_OFLOW|CRTS_IFLOW;
|
||||
rstio.c_cflag |= CLOCAL | CCTS_OFLOW | CRTS_IFLOW;
|
||||
else
|
||||
rstio.c_cflag |= CLOCAL;
|
||||
rstio.c_cflag |= CLOCAL;
|
||||
|
||||
if (!(mode & MODE_DEDICATED))
|
||||
rstio.c_cflag |= HUPCL;
|
||||
tcsetattr(modem, TCSADRAIN, &rstio);
|
||||
oldflag = fcntl(modem, F_GETFL, 0);
|
||||
if (oldflag < 0)
|
||||
return(-1);
|
||||
(void)fcntl(modem, F_SETFL, oldflag | O_NONBLOCK);
|
||||
return(0);
|
||||
return (-1);
|
||||
(void) fcntl(modem, F_SETFL, oldflag | O_NONBLOCK);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
UnrawModem(modem)
|
||||
int modem;
|
||||
UnrawModem(int modem)
|
||||
{
|
||||
int oldflag;
|
||||
|
||||
@ -532,27 +586,25 @@ int modem;
|
||||
tcsetattr(modem, TCSAFLUSH, &modemios);
|
||||
oldflag = fcntl(modem, F_GETFL, 0);
|
||||
if (oldflag < 0)
|
||||
return;
|
||||
(void)fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
|
||||
return;
|
||||
(void) fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
HangupModem(flag)
|
||||
int flag;
|
||||
HangupModem(int flag)
|
||||
{
|
||||
struct termios tio;
|
||||
|
||||
if (!isatty(modem)) {
|
||||
mbits &= ~TIOCM_DTR;
|
||||
close(modem);
|
||||
modem = -1; /* Mark as modem has closed */
|
||||
modem = -1; /* Mark as modem has closed */
|
||||
return;
|
||||
}
|
||||
|
||||
if (modem >= 0 && Online) {
|
||||
mbits &= ~TIOCM_DTR;
|
||||
#ifdef __bsdi__ /* not a POSIX way */
|
||||
#ifdef __bsdi__ /* not a POSIX way */
|
||||
ioctl(modem, TIOCMSET, &mbits);
|
||||
#else
|
||||
tcgetattr(modem, &tio);
|
||||
@ -563,28 +615,29 @@ int flag;
|
||||
#endif
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we are working as dedicated mode, never close it
|
||||
* until we are directed to quit program.
|
||||
* If we are working as dedicated mode, never close it until we are
|
||||
* directed to quit program.
|
||||
*/
|
||||
if (modem >= 0 && (flag || !(mode & MODE_DEDICATED))) {
|
||||
ModemTimeout(); /* XXX */
|
||||
StopTimer(&ModemTimer); /* XXX */
|
||||
ModemTimeout(); /* XXX */
|
||||
StopTimer(&ModemTimer); /* XXX */
|
||||
|
||||
/* ModemTimeout() may call DownConection() to close the modem
|
||||
* resulting in modem == 0.
|
||||
*/
|
||||
if (modem >= 0)
|
||||
{
|
||||
/*
|
||||
* ModemTimeout() may call DownConection() to close the modem resulting
|
||||
* in modem == 0.
|
||||
*/
|
||||
if (modem >= 0) {
|
||||
char ScriptBuffer[200];
|
||||
|
||||
strcpy(ScriptBuffer, VarHangupScript); /* arrays are the same size */
|
||||
strcpy(ScriptBuffer, VarHangupScript); /* arrays are the same size */
|
||||
DoChat(ScriptBuffer);
|
||||
tcflush(modem, TCIOFLUSH);
|
||||
UnrawModem(modem);
|
||||
close(modem);
|
||||
}
|
||||
modem = -1; /* Mark as modem has closed */
|
||||
modem = -1; /* Mark as modem has closed */
|
||||
(void) uu_unlock(VarBaseDevice);
|
||||
} else if (modem >= 0) {
|
||||
char ScriptBuffer[200];
|
||||
@ -597,7 +650,7 @@ int flag;
|
||||
cfsetspeed(&ts, IntToSpeed(VarSpeed));
|
||||
tcsetattr(modem, TCSADRAIN, &ts);
|
||||
#endif
|
||||
strcpy(ScriptBuffer, VarHangupScript); /* arrays are the same size */
|
||||
strcpy(ScriptBuffer, VarHangupScript); /* arrays are the same size */
|
||||
DoChat(ScriptBuffer);
|
||||
}
|
||||
}
|
||||
@ -605,10 +658,9 @@ int flag;
|
||||
void
|
||||
CloseModem()
|
||||
{
|
||||
if (modem >= 0)
|
||||
{
|
||||
close(modem);
|
||||
modem = -1;
|
||||
if (modem >= 0) {
|
||||
close(modem);
|
||||
modem = -1;
|
||||
}
|
||||
(void) uu_unlock(VarBaseDevice);
|
||||
}
|
||||
@ -618,26 +670,21 @@ CloseModem()
|
||||
* to the line when ModemStartOutput() is called.
|
||||
*/
|
||||
void
|
||||
WriteModem(pri, ptr, count)
|
||||
int pri;
|
||||
char *ptr;
|
||||
int count;
|
||||
WriteModem(int pri, char *ptr, int count)
|
||||
{
|
||||
struct mbuf *bp;
|
||||
|
||||
bp = mballoc(count, MB_MODEM);
|
||||
bcopy(ptr, MBUF_CTOP(bp), count);
|
||||
|
||||
/* Should be NORMAL and LINK only.
|
||||
* All IP frames get here marked NORMAL.
|
||||
*/
|
||||
/*
|
||||
* Should be NORMAL and LINK only. All IP frames get here marked NORMAL.
|
||||
*/
|
||||
Enqueue(&OutputQueues[pri], bp);
|
||||
}
|
||||
|
||||
void
|
||||
ModemOutput(pri, bp)
|
||||
int pri;
|
||||
struct mbuf *bp;
|
||||
ModemOutput(int pri, struct mbuf * bp)
|
||||
{
|
||||
struct mbuf *wp;
|
||||
int len;
|
||||
@ -656,38 +703,38 @@ ModemQlen()
|
||||
int len = 0;
|
||||
int i;
|
||||
|
||||
for ( i = PRI_NORMAL; i <= PRI_LINK; i ++ ) {
|
||||
queue = &OutputQueues[i];
|
||||
len += queue->qlen;
|
||||
for (i = PRI_NORMAL; i <= PRI_LINK; i++) {
|
||||
queue = &OutputQueues[i];
|
||||
len += queue->qlen;
|
||||
}
|
||||
return(len);
|
||||
return (len);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
ModemStartOutput(fd)
|
||||
int fd;
|
||||
ModemStartOutput(int fd)
|
||||
{
|
||||
struct mqueue *queue;
|
||||
int nb, nw;
|
||||
int i;
|
||||
|
||||
if (modemout == NULL && ModemQlen() == 0)
|
||||
IpStartOutput();
|
||||
if (modemout == NULL && ModemQlen() == 0)
|
||||
IpStartOutput();
|
||||
if (modemout == NULL) {
|
||||
i = PRI_LINK;
|
||||
for (queue = &OutputQueues[PRI_LINK]; queue >= OutputQueues; queue--) {
|
||||
if (queue->top) {
|
||||
modemout = Dequeue(queue);
|
||||
if (LogIsKept(LogDEBUG)) {
|
||||
if (LogIsKept(LogDEBUG)) {
|
||||
if (i > PRI_NORMAL) {
|
||||
struct mqueue *q;
|
||||
|
||||
q = &OutputQueues[0];
|
||||
LogPrintf(LogDEBUG, "ModemStartOutput: Output from queue %d,"
|
||||
" normal has %d\n", i, q->qlen);
|
||||
}
|
||||
LogPrintf(LogDEBUG, "ModemStartOutput: Dequeued %d\n", i);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
i--;
|
||||
@ -695,7 +742,8 @@ int fd;
|
||||
}
|
||||
if (modemout) {
|
||||
nb = modemout->cnt;
|
||||
if (nb > 1600) nb = 1600;
|
||||
if (nb > 1600)
|
||||
nb = 1600;
|
||||
nw = write(fd, MBUF_CTOP(modemout), nb);
|
||||
LogPrintf(LogDEBUG, "ModemStartOutput: wrote: %d(%d)\n", nw, nb);
|
||||
LogDumpBuff(LogDEBUG, "ModemStartOutput: modem write",
|
||||
@ -709,8 +757,8 @@ int fd;
|
||||
}
|
||||
} else if (nw < 0) {
|
||||
if (errno != EAGAIN) {
|
||||
LogPrintf(LogERROR, "modem write (%d): %s", modem, strerror(errno));
|
||||
reconnect(RECON_TRUE);
|
||||
LogPrintf(LogERROR, "modem write (%d): %s", modem, strerror(errno));
|
||||
reconnect(RECON_TRUE);
|
||||
DownConnection();
|
||||
}
|
||||
}
|
||||
@ -723,16 +771,16 @@ DialModem()
|
||||
char ScriptBuffer[200];
|
||||
int excode;
|
||||
|
||||
strncpy(ScriptBuffer, VarDialScript,sizeof(ScriptBuffer)-1);
|
||||
ScriptBuffer[sizeof(ScriptBuffer)-1] = '\0';
|
||||
strncpy(ScriptBuffer, VarDialScript, sizeof(ScriptBuffer) - 1);
|
||||
ScriptBuffer[sizeof(ScriptBuffer) - 1] = '\0';
|
||||
if ((excode = DoChat(ScriptBuffer)) > 0) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "dial OK!\n");
|
||||
strncpy(ScriptBuffer, VarLoginScript,sizeof(ScriptBuffer)-1);
|
||||
strncpy(ScriptBuffer, VarLoginScript, sizeof(ScriptBuffer) - 1);
|
||||
if ((excode = DoChat(ScriptBuffer)) > 0) {
|
||||
VarAltPhone = NULL;
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "login OK!\n");
|
||||
fprintf(VarTerm, "login OK!\n");
|
||||
return EX_DONE;
|
||||
} else if (excode == -1)
|
||||
excode = EX_SIG;
|
||||
@ -740,7 +788,7 @@ DialModem()
|
||||
LogPrintf(LogWARN, "DialModem: login failed.\n");
|
||||
excode = EX_NOLOGIN;
|
||||
}
|
||||
ModemTimeout(); /* Dummy call to check modem status */
|
||||
ModemTimeout(); /* Dummy call to check modem status */
|
||||
} else if (excode == -1)
|
||||
excode = EX_SIG;
|
||||
else {
|
||||
@ -748,7 +796,7 @@ DialModem()
|
||||
excode = EX_NODIAL;
|
||||
}
|
||||
HangupModem(0);
|
||||
return(excode);
|
||||
return (excode);
|
||||
}
|
||||
|
||||
int
|
||||
@ -756,6 +804,7 @@ ShowModemStatus()
|
||||
{
|
||||
#ifdef TIOCOUTQ
|
||||
int nb;
|
||||
|
||||
#endif
|
||||
|
||||
if (!VarTerm)
|
||||
@ -783,7 +832,7 @@ ShowModemStatus()
|
||||
} else
|
||||
fprintf(VarTerm, "no parity, ");
|
||||
|
||||
fprintf(VarTerm, "CTS/RTS %s.\n", (VarCtsRts? "on" : "off"));
|
||||
fprintf(VarTerm, "CTS/RTS %s.\n", (VarCtsRts ? "on" : "off"));
|
||||
|
||||
if (LogIsKept(LogDEBUG))
|
||||
fprintf(VarTerm, "fd = %d, modem control = %o\n", modem, mbits);
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: modem.h,v 1.7 1997/02/22 16:10:37 peter Exp $
|
||||
* $Id: modem.h,v 1.8 1997/06/09 03:27:30 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -41,4 +41,5 @@ extern speed_t IntToSpeed(int);
|
||||
extern void ModemTimeout(void);
|
||||
extern void DownConnection(void);
|
||||
extern void ModemOutput(int, struct mbuf *);
|
||||
|
||||
#endif
|
||||
|
@ -15,198 +15,185 @@
|
||||
#include "vars.h"
|
||||
|
||||
static int
|
||||
StrToAddr (char *, struct in_addr* addr);
|
||||
StrToAddr(char *, struct in_addr * addr);
|
||||
|
||||
static int
|
||||
StrToPort (char *, u_short *port, char *proto);
|
||||
StrToPort(char *, u_short * port, char *proto);
|
||||
|
||||
static int
|
||||
StrToAddrAndPort (char *, struct in_addr *addr, u_short *port, char *proto);
|
||||
StrToAddrAndPort(char *, struct in_addr * addr, u_short * port, char *proto);
|
||||
|
||||
|
||||
int
|
||||
AliasRedirectPort (struct cmdtab *list,
|
||||
int argc,
|
||||
char **argv,
|
||||
void *param)
|
||||
AliasRedirectPort(struct cmdtab * list,
|
||||
int argc,
|
||||
char **argv,
|
||||
void *param)
|
||||
{
|
||||
if (!(mode & MODE_ALIAS)) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "Alias not enabled\n");
|
||||
} else if (argc == 3) {
|
||||
char proto_constant;
|
||||
char *proto;
|
||||
u_short local_port;
|
||||
u_short alias_port;
|
||||
int error;
|
||||
struct in_addr local_addr;
|
||||
struct in_addr null_addr;
|
||||
struct alias_link *link;
|
||||
if (!(mode & MODE_ALIAS)) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "Alias not enabled\n");
|
||||
} else if (argc == 3) {
|
||||
char proto_constant;
|
||||
char *proto;
|
||||
u_short local_port;
|
||||
u_short alias_port;
|
||||
int error;
|
||||
struct in_addr local_addr;
|
||||
struct in_addr null_addr;
|
||||
struct alias_link *link;
|
||||
|
||||
proto = argv[0];
|
||||
if (strcmp(proto, "tcp") == 0) {
|
||||
proto_constant = IPPROTO_TCP;
|
||||
} else if (strcmp(proto, "udp") == 0) {
|
||||
proto_constant = IPPROTO_UDP;
|
||||
} else {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "port redirect: protocol must be tcp or udp\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name,
|
||||
list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
proto = argv[0];
|
||||
if (strcmp(proto, "tcp") == 0) {
|
||||
proto_constant = IPPROTO_TCP;
|
||||
} else if (strcmp(proto, "udp") == 0) {
|
||||
proto_constant = IPPROTO_UDP;
|
||||
} else {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "port redirect: protocol must be tcp or udp\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name,
|
||||
list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
error = StrToAddrAndPort(argv[1], &local_addr, &local_port, proto);
|
||||
if (error) {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "port redirect: error reading local addr:port\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
error = StrToAddrAndPort(argv[1], &local_addr, &local_port, proto);
|
||||
if (error) {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "port redirect: error reading local addr:port\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
error = StrToPort(argv[2], &alias_port, proto);
|
||||
if (error) {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "port redirect: error reading alias port\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
null_addr.s_addr = 0;
|
||||
|
||||
error = StrToPort(argv[2], &alias_port, proto);
|
||||
if (error) {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "port redirect: error reading alias port\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
link = VarPacketAliasRedirectPort(local_addr, local_port,
|
||||
null_addr, 0,
|
||||
null_addr, alias_port,
|
||||
proto_constant);
|
||||
|
||||
null_addr.s_addr = 0;
|
||||
if (link == NULL && VarTerm)
|
||||
fprintf(VarTerm, "port redirect: error returned by packed"
|
||||
" aliasing engine (code=%d)\n", error);
|
||||
} else if (VarTerm)
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
|
||||
link = VarPacketAliasRedirectPort(local_addr, local_port,
|
||||
null_addr, 0,
|
||||
null_addr, alias_port,
|
||||
proto_constant);
|
||||
|
||||
if (link == NULL && VarTerm)
|
||||
fprintf(VarTerm, "port redirect: error returned by packed"
|
||||
" aliasing engine (code=%d)\n", error);
|
||||
} else if (VarTerm)
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
AliasRedirectAddr(struct cmdtab *list,
|
||||
int argc,
|
||||
char **argv,
|
||||
void *param)
|
||||
AliasRedirectAddr(struct cmdtab * list,
|
||||
int argc,
|
||||
char **argv,
|
||||
void *param)
|
||||
{
|
||||
if (!(mode & MODE_ALIAS)) {
|
||||
if (!(mode & MODE_ALIAS)) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "alias not enabled\n");
|
||||
} else if (argc == 2) {
|
||||
int error;
|
||||
struct in_addr local_addr;
|
||||
struct in_addr alias_addr;
|
||||
struct alias_link *link;
|
||||
|
||||
error = StrToAddr(argv[0], &local_addr);
|
||||
if (error) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "alias not enabled\n");
|
||||
} else if (argc == 2) {
|
||||
int error;
|
||||
struct in_addr local_addr;
|
||||
struct in_addr alias_addr;
|
||||
struct alias_link *link;
|
||||
fprintf(VarTerm, "address redirect: invalid local address\n");
|
||||
return 1;
|
||||
}
|
||||
error = StrToAddr(argv[1], &alias_addr);
|
||||
if (error) {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "address redirect: invalid alias address\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
link = VarPacketAliasRedirectAddr(local_addr, alias_addr);
|
||||
if (link == NULL && VarTerm) {
|
||||
fprintf(VarTerm, "address redirect: packet aliasing engine error\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
} else if (VarTerm)
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
|
||||
error = StrToAddr(argv[0], &local_addr);
|
||||
if (error) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "address redirect: invalid local address\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
error = StrToAddr(argv[1], &alias_addr);
|
||||
if (error) {
|
||||
if (VarTerm) {
|
||||
fprintf(VarTerm, "address redirect: invalid alias address\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
link = VarPacketAliasRedirectAddr(local_addr, alias_addr);
|
||||
if (link == NULL && VarTerm) {
|
||||
fprintf(VarTerm, "address redirect: packet aliasing engine error\n");
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
}
|
||||
} else if (VarTerm)
|
||||
fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax);
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
StrToAddr (char* str,
|
||||
struct in_addr* addr)
|
||||
StrToAddr(char *str,
|
||||
struct in_addr * addr)
|
||||
{
|
||||
struct hostent* hp;
|
||||
struct hostent *hp;
|
||||
|
||||
if (inet_aton (str, addr))
|
||||
return 0;
|
||||
|
||||
hp = gethostbyname (str);
|
||||
if (!hp)
|
||||
{
|
||||
LogPrintf(LogWARN, "StrToAddr: Unknown host %s.\n", str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*addr = *((struct in_addr *) hp->h_addr);
|
||||
if (inet_aton(str, addr))
|
||||
return 0;
|
||||
|
||||
hp = gethostbyname(str);
|
||||
if (!hp) {
|
||||
LogPrintf(LogWARN, "StrToAddr: Unknown host %s.\n", str);
|
||||
return -1;
|
||||
}
|
||||
*addr = *((struct in_addr *) hp->h_addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
StrToPort (char *str,
|
||||
u_short *port,
|
||||
char *proto)
|
||||
StrToPort(char *str,
|
||||
u_short * port,
|
||||
char *proto)
|
||||
{
|
||||
int iport;
|
||||
struct servent* sp;
|
||||
char* end;
|
||||
int iport;
|
||||
struct servent *sp;
|
||||
char *end;
|
||||
|
||||
iport = strtol (str, &end, 10);
|
||||
if (end != str)
|
||||
{
|
||||
*port = htons(iport);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sp = getservbyname (str, proto);
|
||||
if (!sp)
|
||||
{
|
||||
LogPrintf(LogWARN, "StrToAddr: Unknown port or service %s/%s.\n",
|
||||
str, proto);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*port = sp->s_port;
|
||||
iport = strtol(str, &end, 10);
|
||||
if (end != str) {
|
||||
*port = htons(iport);
|
||||
return 0;
|
||||
}
|
||||
sp = getservbyname(str, proto);
|
||||
if (!sp) {
|
||||
LogPrintf(LogWARN, "StrToAddr: Unknown port or service %s/%s.\n",
|
||||
str, proto);
|
||||
return -1;
|
||||
}
|
||||
*port = sp->s_port;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
StrToAddrAndPort (char* str,
|
||||
struct in_addr* addr,
|
||||
u_short *port,
|
||||
char *proto)
|
||||
StrToAddrAndPort(char *str,
|
||||
struct in_addr * addr,
|
||||
u_short * port,
|
||||
char *proto)
|
||||
{
|
||||
char *ptr;
|
||||
char *ptr;
|
||||
|
||||
ptr = strchr (str, ':');
|
||||
if (!ptr)
|
||||
{
|
||||
LogPrintf(LogWARN, "StrToAddrAndPort: %s is missing port number.\n",
|
||||
str);
|
||||
return -1;
|
||||
}
|
||||
ptr = strchr(str, ':');
|
||||
if (!ptr) {
|
||||
LogPrintf(LogWARN, "StrToAddrAndPort: %s is missing port number.\n",
|
||||
str);
|
||||
return -1;
|
||||
}
|
||||
*ptr = '\0';
|
||||
++ptr;
|
||||
|
||||
*ptr = '\0';
|
||||
++ptr;
|
||||
if (StrToAddr(str, addr) != 0)
|
||||
return -1;
|
||||
|
||||
if (StrToAddr (str, addr) != 0)
|
||||
return -1;
|
||||
|
||||
return StrToPort (ptr, port, proto);
|
||||
return StrToPort(ptr, port, proto);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
extern int
|
||||
AliasRedirectPort (struct cmdtab *, int, char **, void *);
|
||||
AliasRedirectPort(struct cmdtab *, int, char **, void *);
|
||||
|
||||
extern int
|
||||
AliasRedirectAddr (struct cmdtab *, int, char **, void *);
|
||||
AliasRedirectAddr(struct cmdtab *, int, char **, void *);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: os.c,v 1.22 1997/06/09 03:27:31 brian Exp $
|
||||
* $Id: os.c,v 1.23 1997/06/13 02:07:30 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include "fsm.h"
|
||||
@ -53,15 +53,17 @@ static int linkup;
|
||||
|
||||
#ifdef bsdi
|
||||
extern char *inet_ntoa();
|
||||
|
||||
#endif
|
||||
extern void HangupModem();
|
||||
|
||||
char *IfDevName;
|
||||
|
||||
static int
|
||||
SetIpDevice(myaddr, hisaddr, netmask, updown)
|
||||
struct in_addr myaddr, hisaddr, netmask;
|
||||
int updown;
|
||||
SetIpDevice(struct in_addr myaddr,
|
||||
struct in_addr hisaddr,
|
||||
struct in_addr netmask,
|
||||
int updown)
|
||||
{
|
||||
struct sockaddr_in *sin;
|
||||
int s;
|
||||
@ -71,15 +73,14 @@ int updown;
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "socket: %s", strerror(errno));
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (updown == 0) {
|
||||
if (Enabled(ConfProxy))
|
||||
cifproxyarp(s, oldhis.s_addr);
|
||||
if (oldmine.s_addr == 0 && oldhis.s_addr == 0) {
|
||||
close(s);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
bzero(&ifra.ifra_addr, sizeof(ifra.ifra_addr));
|
||||
bzero(&ifra.ifra_broadaddr, sizeof(ifra.ifra_addr));
|
||||
@ -87,40 +88,44 @@ int updown;
|
||||
if (ioctl(s, SIOCDIFADDR, &ifra) < 0) {
|
||||
LogPrintf(LogERROR, "ioctl(SIOCDIFADDR): %s", strerror(errno));
|
||||
close(s);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
oldmine.s_addr = oldhis.s_addr = 0;
|
||||
} else {
|
||||
|
||||
/*
|
||||
* If given addresses are alreay set, then ignore this request.
|
||||
*/
|
||||
if (oldmine.s_addr == myaddr.s_addr && oldhis.s_addr == hisaddr.s_addr) {
|
||||
close(s);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* If different address has been set, then delete it first.
|
||||
*/
|
||||
if (oldmine.s_addr || oldhis.s_addr) {
|
||||
changeaddr = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set interface address
|
||||
* Set interface address
|
||||
*/
|
||||
sin = (struct sockaddr_in *)&(ifra.ifra_addr);
|
||||
sin = (struct sockaddr_in *) & (ifra.ifra_addr);
|
||||
sin->sin_family = AF_INET;
|
||||
sin->sin_addr = oldmine = myaddr;
|
||||
sin->sin_len = sizeof(*sin);
|
||||
|
||||
/*
|
||||
* Set destination address
|
||||
* Set destination address
|
||||
*/
|
||||
sin = (struct sockaddr_in *)&(ifra.ifra_broadaddr);
|
||||
sin = (struct sockaddr_in *) & (ifra.ifra_broadaddr);
|
||||
sin->sin_family = AF_INET;
|
||||
sin->sin_addr = oldhis = hisaddr;
|
||||
sin->sin_len = sizeof(*sin);
|
||||
|
||||
/*
|
||||
*/
|
||||
* */
|
||||
addr = ntohl(myaddr.s_addr);
|
||||
if (IN_CLASSA(addr))
|
||||
mask = IN_CLASSA_NET;
|
||||
@ -128,49 +133,52 @@ int updown;
|
||||
mask = IN_CLASSB_NET;
|
||||
else
|
||||
mask = IN_CLASSC_NET;
|
||||
|
||||
/*
|
||||
* if subnet mask is given, use it instead of class mask.
|
||||
* if subnet mask is given, use it instead of class mask.
|
||||
*/
|
||||
if (netmask.s_addr && (ntohl(netmask.s_addr) & mask) == mask)
|
||||
mask = ntohl(netmask.s_addr);
|
||||
|
||||
sin = (struct sockaddr_in *)&(ifra.ifra_mask);
|
||||
sin = (struct sockaddr_in *) & (ifra.ifra_mask);
|
||||
sin->sin_family = AF_INET;
|
||||
sin->sin_addr.s_addr = htonl(mask);
|
||||
sin->sin_len = sizeof(*sin);
|
||||
|
||||
if (changeaddr) {
|
||||
|
||||
/*
|
||||
* Interface already exists. Just change the address.
|
||||
*/
|
||||
bcopy(&ifra.ifra_addr, &ifrq.ifr_addr, sizeof(struct sockaddr));
|
||||
if (ioctl(s, SIOCSIFADDR, &ifra) < 0)
|
||||
LogPrintf(LogERROR, "ioctl(SIFADDR): %s", strerror(errno));
|
||||
LogPrintf(LogERROR, "ioctl(SIFADDR): %s", strerror(errno));
|
||||
bcopy(&ifra.ifra_broadaddr, &ifrq.ifr_dstaddr, sizeof(struct sockaddr));
|
||||
if (ioctl(s, SIOCSIFDSTADDR, &ifrq) < 0)
|
||||
LogPrintf(LogERROR, "ioctl(SIFDSTADDR): %s", strerror(errno));
|
||||
LogPrintf(LogERROR, "ioctl(SIFDSTADDR): %s", strerror(errno));
|
||||
#ifdef notdef
|
||||
bcopy(&ifra.ifra_mask, &ifrq.ifr_broadaddr, sizeof(struct sockaddr));
|
||||
if (ioctl(s, SIOCSIFBRDADDR, &ifrq) < 0)
|
||||
LogPrintf(LogERROR, "ioctl(SIFBRDADDR): %s", strerror(errno));
|
||||
LogPrintf(LogERROR, "ioctl(SIFBRDADDR): %s", strerror(errno));
|
||||
#endif
|
||||
} else if (ioctl(s, SIOCAIFADDR, &ifra) < 0) {
|
||||
LogPrintf(LogERROR, "ioctl(SIOCAIFADDR): %s", strerror(errno));
|
||||
close(s);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
if (Enabled(ConfProxy))
|
||||
sifproxyarp(s, hisaddr.s_addr);
|
||||
}
|
||||
close(s);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
OsSetIpaddress(myaddr, hisaddr, netmask)
|
||||
struct in_addr myaddr, hisaddr, netmask;
|
||||
OsSetIpaddress(struct in_addr myaddr,
|
||||
struct in_addr hisaddr,
|
||||
struct in_addr netmask)
|
||||
{
|
||||
return(SetIpDevice(myaddr, hisaddr, netmask, 1));
|
||||
return (SetIpDevice(myaddr, hisaddr, netmask, 1));
|
||||
}
|
||||
|
||||
static struct in_addr peer_addr;
|
||||
@ -184,16 +192,17 @@ OsLinkup()
|
||||
if (linkup == 0) {
|
||||
reconnectState = RECON_UNKNOWN;
|
||||
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
|
||||
char c = EX_NORMAL;
|
||||
if (write(BGFiledes[1],&c,1) == 1)
|
||||
LogPrintf(LogPHASE,"Parent notified of success.\n");
|
||||
else
|
||||
LogPrintf(LogPHASE,"Failed to notify parent of success.\n");
|
||||
close(BGFiledes[1]);
|
||||
BGFiledes[1] = -1;
|
||||
char c = EX_NORMAL;
|
||||
|
||||
if (write(BGFiledes[1], &c, 1) == 1)
|
||||
LogPrintf(LogPHASE, "Parent notified of success.\n");
|
||||
else
|
||||
LogPrintf(LogPHASE, "Failed to notify parent of success.\n");
|
||||
close(BGFiledes[1]);
|
||||
BGFiledes[1] = -1;
|
||||
}
|
||||
peer_addr = IpcpInfo.his_ipaddr;
|
||||
s = (char *)inet_ntoa(peer_addr);
|
||||
s = (char *) inet_ntoa(peer_addr);
|
||||
if (LogIsKept(LogLINK))
|
||||
LogPrintf(LogLINK, "OsLinkup: %s\n", s);
|
||||
else
|
||||
@ -201,10 +210,10 @@ OsLinkup()
|
||||
|
||||
if (SelectSystem(inet_ntoa(IpcpInfo.want_ipaddr), LINKUPFILE) < 0) {
|
||||
if (dstsystem) {
|
||||
if (SelectSystem(dstsystem, LINKUPFILE) < 0)
|
||||
SelectSystem("MYADDR", LINKUPFILE);
|
||||
if (SelectSystem(dstsystem, LINKUPFILE) < 0)
|
||||
SelectSystem("MYADDR", LINKUPFILE);
|
||||
} else
|
||||
SelectSystem("MYADDR", LINKUPFILE);
|
||||
SelectSystem("MYADDR", LINKUPFILE);
|
||||
}
|
||||
linkup = 1;
|
||||
}
|
||||
@ -216,7 +225,7 @@ OsLinkdown()
|
||||
char *s;
|
||||
|
||||
if (linkup) {
|
||||
s = (char *)inet_ntoa(peer_addr);
|
||||
s = (char *) inet_ntoa(peer_addr);
|
||||
if (LogIsKept(LogLINK))
|
||||
LogPrintf(LogLINK, "OsLinkdown: %s\n", s);
|
||||
else
|
||||
@ -227,46 +236,43 @@ OsLinkdown()
|
||||
linkup = 0;
|
||||
if (SelectSystem(s, LINKDOWNFILE) < 0) {
|
||||
if (dstsystem) {
|
||||
if (SelectSystem(dstsystem, LINKDOWNFILE) < 0)
|
||||
SelectSystem("MYADDR", LINKDOWNFILE);
|
||||
if (SelectSystem(dstsystem, LINKDOWNFILE) < 0)
|
||||
SelectSystem("MYADDR", LINKDOWNFILE);
|
||||
} else
|
||||
SelectSystem("MYADDR", LINKDOWNFILE);
|
||||
SelectSystem("MYADDR", LINKDOWNFILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
OsInterfaceDown(final)
|
||||
int final;
|
||||
OsInterfaceDown(int final)
|
||||
{
|
||||
struct in_addr zeroaddr;
|
||||
int s;
|
||||
|
||||
OsLinkdown();
|
||||
if (!final && (mode & MODE_AUTO)) /* We still want interface alive */
|
||||
return(0);
|
||||
return (0);
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "socket: %s", strerror(errno));
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
ifrq.ifr_flags &= ~IFF_UP;
|
||||
if (ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) {
|
||||
LogPrintf(LogERROR, "ioctl(SIOCSIFFLAGS): %s", strerror(errno));
|
||||
close(s);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
zeroaddr.s_addr = 0;
|
||||
SetIpDevice(zeroaddr, zeroaddr, zeroaddr, 0);
|
||||
|
||||
close(s);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
OsSetInterfaceParams(type, mtu, speed)
|
||||
int type, mtu, speed;
|
||||
OsSetInterfaceParams(int type, int mtu, int speed)
|
||||
{
|
||||
struct tuninfo info;
|
||||
|
||||
@ -289,32 +295,31 @@ int type, mtu, speed;
|
||||
* 'Device not configured' (ENXIO), or the third *
|
||||
* 'No such file or directory' (ENOENT) error. */
|
||||
int
|
||||
OpenTunnel(ptun)
|
||||
int *ptun;
|
||||
OpenTunnel(int *ptun)
|
||||
{
|
||||
int s;
|
||||
char ifname[IFNAMSIZ];
|
||||
static char devname[14]; /* sufficient room for "/dev/tun65535" */
|
||||
unsigned unit, enoentcount=0;
|
||||
static char devname[14]; /* sufficient room for "/dev/tun65535" */
|
||||
unsigned unit, enoentcount = 0;
|
||||
int err;
|
||||
|
||||
err = ENOENT;
|
||||
for( unit=0; unit <= MAX_TUN ; unit++ ) {
|
||||
snprintf( devname, sizeof(devname), "/dev/tun%d", unit );
|
||||
for (unit = 0; unit <= MAX_TUN; unit++) {
|
||||
snprintf(devname, sizeof(devname), "/dev/tun%d", unit);
|
||||
tun_out = open(devname, O_RDWR);
|
||||
if( tun_out >= 0 )
|
||||
break;
|
||||
if( errno == ENXIO ) {
|
||||
if (tun_out >= 0)
|
||||
break;
|
||||
if (errno == ENXIO) {
|
||||
unit = MAX_TUN;
|
||||
err = errno;
|
||||
} else if (errno == ENOENT) {
|
||||
enoentcount++;
|
||||
if (enoentcount > 2)
|
||||
unit = MAX_TUN;
|
||||
err = errno;
|
||||
} else if( errno == ENOENT ) {
|
||||
enoentcount++;
|
||||
if( enoentcount > 2 )
|
||||
unit=MAX_TUN;
|
||||
} else
|
||||
err = errno;
|
||||
err = errno;
|
||||
}
|
||||
if( unit > MAX_TUN ) {
|
||||
if (unit > MAX_TUN) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "No tunnel device is available (%s).\n", strerror(err));
|
||||
return -1;
|
||||
@ -326,66 +331,60 @@ int *ptun;
|
||||
/*
|
||||
* At first, name the interface.
|
||||
*/
|
||||
strncpy(ifname, devname + 5, IFNAMSIZ-1);
|
||||
strncpy(ifname, devname + 5, IFNAMSIZ - 1);
|
||||
|
||||
bzero((char *)&ifra, sizeof(ifra));
|
||||
bzero((char *)&ifrq, sizeof(ifrq));
|
||||
bzero((char *) &ifra, sizeof(ifra));
|
||||
bzero((char *) &ifrq, sizeof(ifrq));
|
||||
|
||||
strncpy(ifrq.ifr_name, ifname, IFNAMSIZ-1);
|
||||
strncpy(ifra.ifra_name, ifname, IFNAMSIZ-1);
|
||||
strncpy(ifrq.ifr_name, ifname, IFNAMSIZ - 1);
|
||||
strncpy(ifra.ifra_name, ifname, IFNAMSIZ - 1);
|
||||
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "socket: %s", strerror(errno));
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Now, bring up the interface.
|
||||
* Now, bring up the interface.
|
||||
*/
|
||||
if (ioctl(s, SIOCGIFFLAGS, &ifrq) < 0) {
|
||||
LogPrintf(LogERROR, "ioctl(SIOCGIFFLAGS): %s", strerror(errno));
|
||||
close(s);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ifrq.ifr_flags |= IFF_UP;
|
||||
if (ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) {
|
||||
LogPrintf(LogERROR, "ioctl(SIOCSIFFLAGS): %s", strerror(errno));
|
||||
close(s);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
tun_in = tun_out;
|
||||
IfDevName = devname + 5;
|
||||
if (GetIfIndex(IfDevName) < 0) {
|
||||
LogPrintf(LogERROR, "OpenTunnel: Can't find ifindex.\n");
|
||||
close(s);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "Using interface: %s\n", IfDevName);
|
||||
LogPrintf(LogPHASE, "Using interface: %s\n", IfDevName);
|
||||
close(s);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
OsCloseLink(flag)
|
||||
int flag;
|
||||
OsCloseLink(int flag)
|
||||
{
|
||||
HangupModem(flag);
|
||||
}
|
||||
|
||||
void
|
||||
OsAddInOctets(cnt)
|
||||
int cnt;
|
||||
OsAddInOctets(int cnt)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
OsAddOutOctets(cnt)
|
||||
int cnt;
|
||||
OsAddOutOctets(int cnt)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: os.h,v 1.5 1997/02/22 16:10:39 peter Exp $
|
||||
* $Id: os.h,v 1.6 1997/06/09 03:27:32 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -29,9 +29,10 @@ void OsSetInterfaceParams(int type, int mtu, int speed);
|
||||
int OpenTunnel(int *);
|
||||
void OsCloseLink(int flag);
|
||||
void OsLinkup(void);
|
||||
void OsLinkdown (void);
|
||||
void OsLinkdown(void);
|
||||
void OsSetRoute(int, struct in_addr, struct in_addr, struct in_addr);
|
||||
void DeleteIfRoutes(int);
|
||||
void OsAddInOctets(int cnt);
|
||||
void OsAddOutOctets(int cnt);
|
||||
|
||||
#endif
|
||||
|
@ -18,7 +18,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: pap.c,v 1.12 1997/05/26 00:44:08 brian Exp $
|
||||
* $Id: pap.c,v 1.13 1997/06/09 03:27:32 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -33,20 +33,19 @@
|
||||
#include "auth.h"
|
||||
|
||||
#ifndef NOPASSWDAUTH
|
||||
# include "passwdauth.h"
|
||||
#include "passwdauth.h"
|
||||
#endif
|
||||
|
||||
static char *papcodes[] = {
|
||||
"???", "REQUEST", "ACK", "NAK"
|
||||
};
|
||||
|
||||
struct authinfo AuthPapInfo = {
|
||||
struct authinfo AuthPapInfo = {
|
||||
SendPapChallenge,
|
||||
};
|
||||
|
||||
void
|
||||
SendPapChallenge(papid)
|
||||
int papid;
|
||||
SendPapChallenge(int papid)
|
||||
{
|
||||
struct fsmheader lh;
|
||||
struct mbuf *bp;
|
||||
@ -75,10 +74,7 @@ int papid;
|
||||
}
|
||||
|
||||
static void
|
||||
SendPapCode(id, code, message)
|
||||
int id;
|
||||
char *message;
|
||||
int code;
|
||||
SendPapCode(int id, int code, char *message)
|
||||
{
|
||||
struct fsmheader lh;
|
||||
struct mbuf *bp;
|
||||
@ -103,8 +99,7 @@ int code;
|
||||
* Validate given username and passwrd against with secret table
|
||||
*/
|
||||
static int
|
||||
PapValidate(name, key)
|
||||
u_char *name, *key;
|
||||
PapValidate(u_char * name, u_char * key)
|
||||
{
|
||||
int nlen, klen;
|
||||
|
||||
@ -116,19 +111,17 @@ u_char *name, *key;
|
||||
name, nlen, key, klen);
|
||||
|
||||
#ifndef NOPASSWDAUTH
|
||||
if( Enabled( ConfPasswdAuth ) )
|
||||
{
|
||||
LogPrintf( LogLCP, "PasswdAuth enabled - calling\n" );
|
||||
return PasswdAuth( name, key );
|
||||
if (Enabled(ConfPasswdAuth)) {
|
||||
LogPrintf(LogLCP, "PasswdAuth enabled - calling\n");
|
||||
return PasswdAuth(name, key);
|
||||
}
|
||||
#endif
|
||||
|
||||
return(AuthValidate(SECRETFILE, name, key));
|
||||
return (AuthValidate(SECRETFILE, name, key));
|
||||
}
|
||||
|
||||
void
|
||||
PapInput(bp)
|
||||
struct mbuf *bp;
|
||||
PapInput(struct mbuf * bp)
|
||||
{
|
||||
int len = plength(bp);
|
||||
struct fsmheader *php;
|
||||
@ -136,7 +129,7 @@ struct mbuf *bp;
|
||||
u_char *cp;
|
||||
|
||||
if (len >= sizeof(struct fsmheader)) {
|
||||
php = (struct fsmheader *)MBUF_CTOP(bp);
|
||||
php = (struct fsmheader *) MBUF_CTOP(bp);
|
||||
if (len >= ntohs(php->length)) {
|
||||
if (php->code < PAP_REQUEST || php->code > PAP_NAK)
|
||||
php->code = 0;
|
||||
@ -152,13 +145,13 @@ struct mbuf *bp;
|
||||
NewPhase(PHASE_NETWORK);
|
||||
} else {
|
||||
SendPapCode(php->id, PAP_NAK, "Login incorrect");
|
||||
reconnect(RECON_FALSE);
|
||||
reconnect(RECON_FALSE);
|
||||
LcpClose();
|
||||
}
|
||||
break;
|
||||
case PAP_ACK:
|
||||
StopAuthTimer(&AuthPapInfo);
|
||||
cp = (u_char *)(php + 1);
|
||||
cp = (u_char *) (php + 1);
|
||||
len = *cp++;
|
||||
cp[len] = 0;
|
||||
LogPrintf(LogPHASE, "Received PAP_ACK (%s)\n", cp);
|
||||
@ -170,11 +163,11 @@ struct mbuf *bp;
|
||||
break;
|
||||
case PAP_NAK:
|
||||
StopAuthTimer(&AuthPapInfo);
|
||||
cp = (u_char *)(php + 1);
|
||||
cp = (u_char *) (php + 1);
|
||||
len = *cp++;
|
||||
cp[len] = 0;
|
||||
LogPrintf(LogPHASE, "Received PAP_NAK (%s)\n", cp);
|
||||
reconnect(RECON_FALSE);
|
||||
reconnect(RECON_FALSE);
|
||||
LcpClose();
|
||||
break;
|
||||
}
|
||||
|
@ -28,81 +28,77 @@
|
||||
#include "passwdauth.h"
|
||||
|
||||
int
|
||||
PasswdAuth(name, key)
|
||||
char *name, *key;
|
||||
PasswdAuth(char *name, char *key)
|
||||
{
|
||||
static int logged_in = 0;
|
||||
struct passwd *pwd;
|
||||
char *salt, *ep;
|
||||
struct utmp utmp;
|
||||
|
||||
LogPrintf(LogDEBUG, "PasswdAuth: Called with name %s, key %s\n", name, key );
|
||||
LogPrintf(LogDEBUG, "PasswdAuth: Called with name %s, key %s\n", name, key);
|
||||
|
||||
if(( pwd = getpwnam( name ) ))
|
||||
if ((pwd = getpwnam(name)))
|
||||
salt = pwd->pw_passwd;
|
||||
else
|
||||
{
|
||||
else {
|
||||
endpwent();
|
||||
LogPrintf( LogLCP, "PasswdAuth - user (%s) not in passwd file\n", name );
|
||||
return 0; /* false - failed to authenticate (password not in file) */
|
||||
LogPrintf(LogLCP, "PasswdAuth - user (%s) not in passwd file\n", name);
|
||||
return 0; /* false - failed to authenticate (password
|
||||
* not in file) */
|
||||
}
|
||||
|
||||
#ifdef LOCALHACK
|
||||
|
||||
/*
|
||||
* All our PPP usernames start with 'P' so i check that here... if you
|
||||
* don't do this i suggest all your PPP users be members of a group
|
||||
* and you check the guid
|
||||
* don't do this i suggest all your PPP users be members of a group and you
|
||||
* check the guid
|
||||
*/
|
||||
|
||||
if( name[0] != 'P' )
|
||||
{
|
||||
LogPrintf( LogLCP, "PasswdAuth - user (%s) not a PPP user\n", name );
|
||||
if (name[0] != 'P') {
|
||||
LogPrintf(LogLCP, "PasswdAuth - user (%s) not a PPP user\n", name);
|
||||
endpwent();
|
||||
return 0;
|
||||
}
|
||||
#endif /* LOCALHACK */
|
||||
|
||||
#endif /* LOCALHACK */
|
||||
|
||||
ep = crypt( key, salt );
|
||||
ep = crypt(key, salt);
|
||||
|
||||
/* strcmp returns 0 if same */
|
||||
if( strcmp( ep, pwd->pw_passwd ) != 0 )
|
||||
{
|
||||
LogPrintf( LogLCP, "PasswdAuth - user (%s,%s) authentication failed\n",
|
||||
name, key );
|
||||
if (strcmp(ep, pwd->pw_passwd) != 0) {
|
||||
LogPrintf(LogLCP, "PasswdAuth - user (%s,%s) authentication failed\n",
|
||||
name, key);
|
||||
endpwent();
|
||||
return 0; /* false - failed to authenticate (didn't match up) */
|
||||
return 0; /* false - failed to authenticate (didn't
|
||||
* match up) */
|
||||
}
|
||||
|
||||
/*
|
||||
* now we log them in... we have a static login flag so we don't
|
||||
* do it twice :)
|
||||
* now we log them in... we have a static login flag so we don't do it
|
||||
* twice :)
|
||||
*/
|
||||
|
||||
if( ! logged_in )
|
||||
{
|
||||
(void)time(&utmp.ut_time);
|
||||
(void)strncpy(utmp.ut_name, name, sizeof(utmp.ut_name));
|
||||
if (!logged_in) {
|
||||
(void) time(&utmp.ut_time);
|
||||
(void) strncpy(utmp.ut_name, name, sizeof(utmp.ut_name));
|
||||
|
||||
/*
|
||||
* if the first three chacters are "pap" trim them off before doing
|
||||
* utmp entry (see sample.ppp-pap-dialup
|
||||
* if the first three chacters are "pap" trim them off before doing utmp
|
||||
* entry (see sample.ppp-pap-dialup
|
||||
*/
|
||||
|
||||
if( strncmp( "pap", dstsystem, 3 ) == 0 )
|
||||
(void)strncpy(utmp.ut_line, (char *)(dstsystem + 3), sizeof(utmp.ut_line));
|
||||
if (strncmp("pap", dstsystem, 3) == 0)
|
||||
(void) strncpy(utmp.ut_line, (char *) (dstsystem + 3), sizeof(utmp.ut_line));
|
||||
else
|
||||
(void)strncpy(utmp.ut_line, dstsystem, sizeof(utmp.ut_line));
|
||||
(void) strncpy(utmp.ut_line, dstsystem, sizeof(utmp.ut_line));
|
||||
|
||||
(void)strncpy(utmp.ut_host, "auto-ppp",sizeof(utmp.ut_host));
|
||||
(void) strncpy(utmp.ut_host, "auto-ppp", sizeof(utmp.ut_host));
|
||||
login(&utmp);
|
||||
(void)setlogin( pwd->pw_name );
|
||||
(void) setlogin(pwd->pw_name);
|
||||
|
||||
LogPrintf( LogLCP, "PasswdAuth has logged in user %s\n", name );
|
||||
LogPrintf(LogLCP, "PasswdAuth has logged in user %s\n", name);
|
||||
|
||||
logged_in = 1;
|
||||
}
|
||||
|
||||
endpwent();
|
||||
|
||||
return 1;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: phase.h,v 1.5 1997/02/22 16:10:44 peter Exp $
|
||||
* $Id: phase.h,v 1.6 1997/06/09 03:27:35 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -23,15 +23,16 @@
|
||||
#ifndef _PHASE_H_
|
||||
#define _PHASE_H_
|
||||
|
||||
#define PHASE_DEAD 0 /* Link is dead */
|
||||
#define PHASE_ESTABLISH 1 /* Establishing link */
|
||||
#define PHASE_AUTHENTICATE 2 /* Being authenticated */
|
||||
#define PHASE_DEAD 0 /* Link is dead */
|
||||
#define PHASE_ESTABLISH 1 /* Establishing link */
|
||||
#define PHASE_AUTHENTICATE 2 /* Being authenticated */
|
||||
#define PHASE_NETWORK 3
|
||||
#define PHASE_TERMINATE 4 /* Terminating link */
|
||||
#define PHASE_OSLINKED 5 /* The OS is linked up */
|
||||
#define PHASE_TERMINATE 4 /* Terminating link */
|
||||
#define PHASE_OSLINKED 5 /* The OS is linked up */
|
||||
|
||||
int phase; /* Curent phase */
|
||||
int phase; /* Curent phase */
|
||||
|
||||
extern void NewPhase(int);
|
||||
extern char *PhaseNames[];
|
||||
|
||||
#endif
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
/*
|
||||
*
|
||||
* $Id: pred.c,v 1.12 1997/06/09 03:27:35 brian Exp $
|
||||
* $Id: pred.c,v 1.13 1997/06/09 23:38:37 brian Exp $
|
||||
*
|
||||
* pred.c -- Test program for Dave Rand's rendition of the
|
||||
* predictor algorithm
|
||||
@ -28,105 +28,100 @@ static unsigned char InputGuessTable[65536];
|
||||
static unsigned char OutputGuessTable[65536];
|
||||
|
||||
static int
|
||||
compress(source, dest, len)
|
||||
unsigned char *source, *dest;
|
||||
int len;
|
||||
compress(u_char * source, u_char * dest, int len)
|
||||
{
|
||||
int i, bitmask;
|
||||
unsigned char *flagdest, flags, *orgdest;
|
||||
int i, bitmask;
|
||||
unsigned char *flagdest, flags, *orgdest;
|
||||
|
||||
orgdest = dest;
|
||||
while (len) {
|
||||
flagdest = dest++; flags = 0; /* All guess wrong initially */
|
||||
for (bitmask=1, i=0; i < 8 && len; i++, bitmask <<= 1) {
|
||||
if (OutputGuessTable[oHash] == *source) {
|
||||
flags |= bitmask; /* Guess was right - don't output */
|
||||
} else {
|
||||
OutputGuessTable[oHash] = *source;
|
||||
*dest++ = *source; /* Guess wrong, output char */
|
||||
}
|
||||
OHASH(*source++);len--;
|
||||
}
|
||||
*flagdest = flags;
|
||||
orgdest = dest;
|
||||
while (len) {
|
||||
flagdest = dest++;
|
||||
flags = 0; /* All guess wrong initially */
|
||||
for (bitmask = 1, i = 0; i < 8 && len; i++, bitmask <<= 1) {
|
||||
if (OutputGuessTable[oHash] == *source) {
|
||||
flags |= bitmask; /* Guess was right - don't output */
|
||||
} else {
|
||||
OutputGuessTable[oHash] = *source;
|
||||
*dest++ = *source; /* Guess wrong, output char */
|
||||
}
|
||||
OHASH(*source++);
|
||||
len--;
|
||||
}
|
||||
return(dest - orgdest);
|
||||
*flagdest = flags;
|
||||
}
|
||||
return (dest - orgdest);
|
||||
}
|
||||
|
||||
static void
|
||||
SyncTable(source, dest, len)
|
||||
unsigned char *source, *dest;
|
||||
int len;
|
||||
SyncTable(u_char * source, u_char * dest, int len)
|
||||
{
|
||||
|
||||
while (len--) {
|
||||
if (InputGuessTable[iHash] != *source) {
|
||||
InputGuessTable[iHash] = *source;
|
||||
}
|
||||
IHASH(*dest++ = *source++);
|
||||
while (len--) {
|
||||
if (InputGuessTable[iHash] != *source) {
|
||||
InputGuessTable[iHash] = *source;
|
||||
}
|
||||
IHASH(*dest++ = *source++);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
decompress(source, dest, len)
|
||||
unsigned char *source, *dest;
|
||||
int len;
|
||||
decompress(u_char * source, u_char * dest, int len)
|
||||
{
|
||||
int i, bitmask;
|
||||
unsigned char flags, *orgdest;
|
||||
int i, bitmask;
|
||||
unsigned char flags, *orgdest;
|
||||
|
||||
orgdest = dest;
|
||||
while (len) {
|
||||
flags = *source++;
|
||||
len--;
|
||||
for (i=0, bitmask = 1; i < 8; i++, bitmask <<= 1) {
|
||||
if (flags & bitmask) {
|
||||
*dest = InputGuessTable[iHash]; /* Guess correct */
|
||||
} else {
|
||||
if (!len)
|
||||
break; /* we seem to be really done -- cabo */
|
||||
InputGuessTable[iHash] = *source; /* Guess wrong */
|
||||
*dest = *source++; /* Read from source */
|
||||
len--;
|
||||
}
|
||||
IHASH(*dest++);
|
||||
}
|
||||
orgdest = dest;
|
||||
while (len) {
|
||||
flags = *source++;
|
||||
len--;
|
||||
for (i = 0, bitmask = 1; i < 8; i++, bitmask <<= 1) {
|
||||
if (flags & bitmask) {
|
||||
*dest = InputGuessTable[iHash]; /* Guess correct */
|
||||
} else {
|
||||
if (!len)
|
||||
break; /* we seem to be really done -- cabo */
|
||||
InputGuessTable[iHash] = *source; /* Guess wrong */
|
||||
*dest = *source++; /* Read from source */
|
||||
len--;
|
||||
}
|
||||
IHASH(*dest++);
|
||||
}
|
||||
return(dest - orgdest);
|
||||
}
|
||||
return (dest - orgdest);
|
||||
}
|
||||
|
||||
void
|
||||
Pred1Init(direction)
|
||||
int direction;
|
||||
Pred1Init(int direction)
|
||||
{
|
||||
if (direction & 1) { /* Input part */
|
||||
if (direction & 1) { /* Input part */
|
||||
iHash = 0;
|
||||
bzero(InputGuessTable, sizeof(InputGuessTable));
|
||||
}
|
||||
if (direction & 2) { /* Output part */
|
||||
if (direction & 2) { /* Output part */
|
||||
oHash = 0;
|
||||
bzero(OutputGuessTable, sizeof(OutputGuessTable));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Pred1Output(int pri, u_short proto, struct mbuf *bp)
|
||||
Pred1Output(int pri, u_short proto, struct mbuf * bp)
|
||||
{
|
||||
struct mbuf *mwp;
|
||||
u_char *cp, *wp, *hp;
|
||||
int orglen, len;
|
||||
u_char bufp[MAX_MTU+2];
|
||||
u_char bufp[MAX_MTU + 2];
|
||||
u_short fcs;
|
||||
|
||||
orglen = plength(bp) + 2; /* add count of proto */
|
||||
mwp = mballoc((orglen+2)/8*9+12, MB_HDLCOUT);
|
||||
mwp = mballoc((orglen + 2) / 8 * 9 + 12, MB_HDLCOUT);
|
||||
hp = wp = MBUF_CTOP(mwp);
|
||||
cp = bufp;
|
||||
*wp++ = *cp++ = orglen >> 8;
|
||||
*wp++ = *cp++ = orglen & 0377;
|
||||
*cp++ = proto >> 8;
|
||||
*cp++ = proto & 0377;
|
||||
mbread(bp, cp, orglen-2);
|
||||
fcs = HdlcFcs(INITFCS, bufp, 2+orglen);
|
||||
mbread(bp, cp, orglen - 2);
|
||||
fcs = HdlcFcs(INITFCS, bufp, 2 + orglen);
|
||||
fcs = ~fcs;
|
||||
|
||||
len = compress(bufp + 2, wp, orglen);
|
||||
@ -137,7 +132,7 @@ Pred1Output(int pri, u_short proto, struct mbuf *bp)
|
||||
wp += len;
|
||||
CcpInfo.compout += len;
|
||||
} else {
|
||||
bcopy(bufp+2, wp, orglen);
|
||||
bcopy(bufp + 2, wp, orglen);
|
||||
wp += orglen;
|
||||
CcpInfo.compout += orglen;
|
||||
}
|
||||
@ -149,8 +144,7 @@ Pred1Output(int pri, u_short proto, struct mbuf *bp)
|
||||
}
|
||||
|
||||
void
|
||||
Pred1Input(bp)
|
||||
struct mbuf *bp;
|
||||
Pred1Input(struct mbuf * bp)
|
||||
{
|
||||
u_char *cp, *pp;
|
||||
int len, olen, len1;
|
||||
@ -158,7 +152,7 @@ struct mbuf *bp;
|
||||
u_char *bufp;
|
||||
u_short fcs, proto;
|
||||
|
||||
wp = mballoc(MAX_MTU+2, MB_IPIN);
|
||||
wp = mballoc(MAX_MTU + 2, MB_IPIN);
|
||||
cp = MBUF_CTOP(bp);
|
||||
olen = plength(bp);
|
||||
pp = bufp = MBUF_CTOP(wp);
|
||||
@ -171,7 +165,7 @@ struct mbuf *bp;
|
||||
len1 = decompress(cp, pp, olen - 4);
|
||||
CcpInfo.compin += olen;
|
||||
len &= 0x7fff;
|
||||
if (len != len1) { /* Error is detected. Send reset request */
|
||||
if (len != len1) { /* Error is detected. Send reset request */
|
||||
LogPrintf(LogLCP, "%s: Length Error\n", CcpFsm.name);
|
||||
CcpSendResetReq(&CcpFsm);
|
||||
pfree(bp);
|
||||
@ -186,12 +180,12 @@ struct mbuf *bp;
|
||||
cp += len;
|
||||
pp += len;
|
||||
}
|
||||
*pp++ = *cp++; /* CRC */
|
||||
*pp++ = *cp++; /* CRC */
|
||||
*pp++ = *cp++;
|
||||
fcs = HdlcFcs(INITFCS, bufp, wp->cnt = pp - bufp);
|
||||
if (fcs != GOODFCS)
|
||||
LogPrintf(LogDEBUG, "Pred1Input: fcs = 0x%04x (%s), len = 0x%x,"
|
||||
" olen = 0x%x\n", fcs, (fcs == GOODFCS)? "good" : "bad",
|
||||
" olen = 0x%x\n", fcs, (fcs == GOODFCS) ? "good" : "bad",
|
||||
len, olen);
|
||||
if (fcs == GOODFCS) {
|
||||
wp->offset += 2; /* skip length */
|
||||
@ -207,12 +201,10 @@ struct mbuf *bp;
|
||||
proto = (proto << 8) | *pp++;
|
||||
}
|
||||
DecodePacket(proto, wp);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogDumpBp(LogHDLC, "Bad FCS", wp);
|
||||
CcpSendResetReq(&CcpFsm);
|
||||
pfree(wp);
|
||||
} else {
|
||||
LogDumpBp(LogHDLC, "Bad FCS", wp);
|
||||
CcpSendResetReq(&CcpFsm);
|
||||
pfree(wp);
|
||||
}
|
||||
pfree(bp);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: pred.h,v 1.3 1997/02/22 16:10:48 peter Exp $
|
||||
* $Id: pred.h,v 1.4 1997/06/09 03:27:35 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -23,7 +23,8 @@
|
||||
#ifndef _PRED_H_
|
||||
#define _PRED_H_
|
||||
|
||||
extern void Pred1Output(int, u_short, struct mbuf *bp);
|
||||
extern void Pred1Input(struct mbuf*);
|
||||
extern void Pred1Output(int, u_short, struct mbuf * bp);
|
||||
extern void Pred1Input(struct mbuf *);
|
||||
extern void Pred1Init(int);
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: route.c,v 1.16 1997/06/20 23:43:35 brian Exp $
|
||||
* $Id: route.c,v 1.17 1997/07/28 01:02:27 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
@ -54,11 +54,10 @@ struct rtmsg {
|
||||
static int seqno;
|
||||
|
||||
void
|
||||
OsSetRoute(cmd, dst, gateway, mask)
|
||||
int cmd;
|
||||
struct in_addr dst;
|
||||
struct in_addr gateway;
|
||||
struct in_addr mask;
|
||||
OsSetRoute(int cmd,
|
||||
struct in_addr dst,
|
||||
struct in_addr gateway,
|
||||
struct in_addr mask)
|
||||
{
|
||||
struct rtmsg rtmes;
|
||||
int s, nb, wb;
|
||||
@ -71,7 +70,6 @@ struct in_addr mask;
|
||||
LogPrintf(LogERROR, "OsSetRoute: socket: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
bzero(&rtmes, sizeof(rtmes));
|
||||
rtmes.m_rtm.rtm_version = RTM_VERSION;
|
||||
rtmes.m_rtm.rtm_type = cmd;
|
||||
@ -94,11 +92,10 @@ struct in_addr mask;
|
||||
bcopy(&rtdata, cp, 16);
|
||||
cp += 16;
|
||||
}
|
||||
|
||||
if (dst.s_addr == INADDR_ANY)
|
||||
mask.s_addr = INADDR_ANY;
|
||||
|
||||
lp = (u_long *)cp;
|
||||
lp = (u_long *) cp;
|
||||
|
||||
if (mask.s_addr) {
|
||||
*lp++ = 8;
|
||||
@ -108,68 +105,84 @@ struct in_addr mask;
|
||||
*lp = 0;
|
||||
cp += sizeof(u_long);
|
||||
|
||||
nb = cp - (char *)&rtmes;
|
||||
nb = cp - (char *) &rtmes;
|
||||
rtmes.m_rtm.rtm_msglen = nb;
|
||||
wb = write(s, &rtmes, nb);
|
||||
if (wb < 0) {
|
||||
LogPrintf(LogTCPIP, "OsSetRoute: Dst = %s\n", inet_ntoa(dst));
|
||||
LogPrintf(LogTCPIP, "OsSetRoute: Gateway = %s\n", inet_ntoa(gateway));
|
||||
LogPrintf(LogTCPIP, "OsSetRoute: Mask = %s\n", inet_ntoa(mask));
|
||||
switch(rtmes.m_rtm.rtm_errno) {
|
||||
case EEXIST:
|
||||
LogPrintf(LogTCPIP, "Add route failed: Already exists\n");
|
||||
break;
|
||||
case ESRCH:
|
||||
LogPrintf(LogTCPIP, "Del route failed: Non-existent\n");
|
||||
break;
|
||||
case ENOBUFS:
|
||||
default:
|
||||
LogPrintf(LogTCPIP, "Add/Del route failed: %s\n",
|
||||
strerror(rtmes.m_rtm.rtm_errno));
|
||||
break;
|
||||
switch (rtmes.m_rtm.rtm_errno) {
|
||||
case EEXIST:
|
||||
LogPrintf(LogTCPIP, "Add route failed: Already exists\n");
|
||||
break;
|
||||
case ESRCH:
|
||||
LogPrintf(LogTCPIP, "Del route failed: Non-existent\n");
|
||||
break;
|
||||
case ENOBUFS:
|
||||
default:
|
||||
LogPrintf(LogTCPIP, "Add/Del route failed: %s\n",
|
||||
strerror(rtmes.m_rtm.rtm_errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LogPrintf(LogDEBUG, "wrote %d: dst = %x, gateway = %x\n", nb,
|
||||
dst.s_addr, gateway.s_addr);
|
||||
dst.s_addr, gateway.s_addr);
|
||||
close(s);
|
||||
}
|
||||
|
||||
static void
|
||||
p_sockaddr(sa, width)
|
||||
struct sockaddr *sa;
|
||||
int width;
|
||||
p_sockaddr(struct sockaddr * sa, int width)
|
||||
{
|
||||
if (VarTerm) {
|
||||
register char *cp;
|
||||
register struct sockaddr_in *sin = (struct sockaddr_in *)sa;
|
||||
register struct sockaddr_in *sin = (struct sockaddr_in *) sa;
|
||||
|
||||
cp = (sin->sin_addr.s_addr == 0) ? "default" :
|
||||
inet_ntoa(sin->sin_addr);
|
||||
inet_ntoa(sin->sin_addr);
|
||||
fprintf(VarTerm, "%-*.*s ", width, width, cp);
|
||||
}
|
||||
}
|
||||
|
||||
struct bits {
|
||||
short b_mask;
|
||||
char b_val;
|
||||
} bits[] = {
|
||||
{ RTF_UP, 'U' },
|
||||
{ RTF_GATEWAY, 'G' },
|
||||
{ RTF_HOST, 'H' },
|
||||
{ RTF_DYNAMIC, 'D' },
|
||||
{ RTF_MODIFIED, 'M' },
|
||||
{ RTF_CLONING, 'C' },
|
||||
{ RTF_XRESOLVE, 'X' },
|
||||
{ RTF_LLINFO, 'L' },
|
||||
{ RTF_REJECT, 'R' },
|
||||
{ 0 }
|
||||
char b_val;
|
||||
} bits[] = {
|
||||
|
||||
{
|
||||
RTF_UP, 'U'
|
||||
},
|
||||
{
|
||||
RTF_GATEWAY, 'G'
|
||||
},
|
||||
{
|
||||
RTF_HOST, 'H'
|
||||
},
|
||||
{
|
||||
RTF_DYNAMIC, 'D'
|
||||
},
|
||||
{
|
||||
RTF_MODIFIED, 'M'
|
||||
},
|
||||
{
|
||||
RTF_CLONING, 'C'
|
||||
},
|
||||
{
|
||||
RTF_XRESOLVE, 'X'
|
||||
},
|
||||
{
|
||||
RTF_LLINFO, 'L'
|
||||
},
|
||||
{
|
||||
RTF_REJECT, 'R'
|
||||
},
|
||||
{
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
static void
|
||||
p_flags(f, format)
|
||||
register int f;
|
||||
char *format;
|
||||
p_flags(int f, char *format)
|
||||
{
|
||||
if (VarTerm) {
|
||||
char name[33], *flags;
|
||||
@ -177,7 +190,7 @@ char *format;
|
||||
|
||||
for (flags = name; p->b_mask; p++)
|
||||
if (p->b_mask & f)
|
||||
*flags++ = p->b_val;
|
||||
*flags++ = p->b_val;
|
||||
*flags = '\0';
|
||||
fprintf(VarTerm, format, name);
|
||||
}
|
||||
@ -206,50 +219,48 @@ ShowRoute()
|
||||
mib[5] = 0;
|
||||
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) {
|
||||
LogPrintf(LogERROR, "sysctl: estimate: %s", strerror(errno));
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (needed < 0)
|
||||
return(1);
|
||||
return (1);
|
||||
sp = malloc(needed);
|
||||
if (sp == NULL)
|
||||
return(1);
|
||||
return (1);
|
||||
if (sysctl(mib, 6, sp, &needed, NULL, 0) < 0) {
|
||||
LogPrintf(LogERROR, "sysctl: getroute: %s", strerror(errno));
|
||||
free(sp);
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
ep = sp + needed;
|
||||
|
||||
for (cp = sp; cp < ep; cp += rtm->rtm_msglen) {
|
||||
rtm = (struct rt_msghdr *)cp;
|
||||
sa = (struct sockaddr *)(rtm + 1);
|
||||
rtm = (struct rt_msghdr *) cp;
|
||||
sa = (struct sockaddr *) (rtm + 1);
|
||||
mask = 0xffffffff;
|
||||
if (rtm->rtm_addrs == RTA_DST)
|
||||
p_sockaddr(sa, 36);
|
||||
else {
|
||||
wp = (u_char *)cp + rtm->rtm_msglen;
|
||||
wp = (u_char *) cp + rtm->rtm_msglen;
|
||||
p_sockaddr(sa, 16);
|
||||
if (sa->sa_len == 0)
|
||||
sa->sa_len = sizeof(long);
|
||||
sa = (struct sockaddr *)(sa->sa_len + (char *)sa);
|
||||
sa = (struct sockaddr *) (sa->sa_len + (char *) sa);
|
||||
p_sockaddr(sa, 18);
|
||||
lp = (int *)(sa->sa_len + (char *)sa);
|
||||
if ((char *)lp < (char *)wp && *lp) {
|
||||
lp = (int *) (sa->sa_len + (char *) sa);
|
||||
if ((char *) lp < (char *) wp && *lp) {
|
||||
LogPrintf(LogDEBUG, " flag = %x, rest = %d", rtm->rtm_flags, *lp);
|
||||
wp = (u_char *)(lp + 1);
|
||||
wp = (u_char *) (lp + 1);
|
||||
mask = 0;
|
||||
for (nb = *(char *)lp; nb > 4; nb--) {
|
||||
for (nb = *(char *) lp; nb > 4; nb--) {
|
||||
mask <<= 8;
|
||||
mask |= *wp++;
|
||||
}
|
||||
for (nb = 8 - *(char *)lp; nb > 0; nb--)
|
||||
for (nb = 8 - *(char *) lp; nb > 0; nb--)
|
||||
mask <<= 8;
|
||||
}
|
||||
}
|
||||
fprintf(VarTerm, "%08lx ", mask);
|
||||
p_flags(rtm->rtm_flags & (RTF_UP|RTF_GATEWAY|RTF_HOST), "%-6.6s ");
|
||||
p_flags(rtm->rtm_flags & (RTF_UP | RTF_GATEWAY | RTF_HOST), "%-6.6s ");
|
||||
fprintf(VarTerm, "(%d)\n", rtm->rtm_index);
|
||||
}
|
||||
free(sp);
|
||||
@ -260,8 +271,7 @@ ShowRoute()
|
||||
* Delete routes associated with our interface
|
||||
*/
|
||||
void
|
||||
DeleteIfRoutes(all)
|
||||
int all;
|
||||
DeleteIfRoutes(int all)
|
||||
{
|
||||
struct rt_msghdr *rtm;
|
||||
struct sockaddr *sa;
|
||||
@ -285,7 +295,6 @@ int all;
|
||||
LogPrintf(LogERROR, "sysctl: estimate: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
if (needed < 0)
|
||||
return;
|
||||
|
||||
@ -301,28 +310,28 @@ int all;
|
||||
ep = sp + needed;
|
||||
|
||||
for (cp = sp; cp < ep; cp += rtm->rtm_msglen) {
|
||||
rtm = (struct rt_msghdr *)cp;
|
||||
sa = (struct sockaddr *)(rtm + 1);
|
||||
rtm = (struct rt_msghdr *) cp;
|
||||
sa = (struct sockaddr *) (rtm + 1);
|
||||
LogPrintf(LogDEBUG, "DeleteIfRoutes: addrs: %x, index: %d, flags: %x,"
|
||||
" dstnet: %s\n",
|
||||
rtm->rtm_addrs, rtm->rtm_index, rtm->rtm_flags,
|
||||
inet_ntoa(((struct sockaddr_in *)sa)->sin_addr));
|
||||
" dstnet: %s\n",
|
||||
rtm->rtm_addrs, rtm->rtm_index, rtm->rtm_flags,
|
||||
inet_ntoa(((struct sockaddr_in *) sa)->sin_addr));
|
||||
if (rtm->rtm_addrs != RTA_DST &&
|
||||
(rtm->rtm_index == IfIndex) &&
|
||||
(all || (rtm->rtm_flags & RTF_GATEWAY))) {
|
||||
(rtm->rtm_index == IfIndex) &&
|
||||
(all || (rtm->rtm_flags & RTF_GATEWAY))) {
|
||||
LogPrintf(LogDEBUG, "DeleteIfRoutes: Remove it\n");
|
||||
dstnet = ((struct sockaddr_in *)sa)->sin_addr;
|
||||
wp = (u_char *)cp + rtm->rtm_msglen;
|
||||
dstnet = ((struct sockaddr_in *) sa)->sin_addr;
|
||||
wp = (u_char *) cp + rtm->rtm_msglen;
|
||||
if (sa->sa_len == 0)
|
||||
sa->sa_len = sizeof(long);
|
||||
sa = (struct sockaddr *)(sa->sa_len + (char *)sa);
|
||||
gateway = ((struct sockaddr_in *)sa)->sin_addr;
|
||||
lp = (int *)(sa->sa_len + (char *)sa);
|
||||
sa = (struct sockaddr *) (sa->sa_len + (char *) sa);
|
||||
gateway = ((struct sockaddr_in *) sa)->sin_addr;
|
||||
lp = (int *) (sa->sa_len + (char *) sa);
|
||||
mask = 0;
|
||||
if ((char *)lp < (char *)wp && *lp) {
|
||||
if ((char *) lp < (char *) wp && *lp) {
|
||||
LogPrintf(LogDEBUG, "DeleteIfRoutes: flag = %x, rest = %d",
|
||||
rtm->rtm_flags, *lp);
|
||||
wp = (u_char *)(lp + 1);
|
||||
wp = (u_char *) (lp + 1);
|
||||
for (nb = *lp; nb > 4; nb--) {
|
||||
mask <<= 8;
|
||||
mask |= *wp++;
|
||||
@ -334,7 +343,7 @@ int all;
|
||||
LogPrintf(LogDEBUG, "DeleteIfRoutes: Gw: %s\n", inet_ntoa(gateway));
|
||||
LogPrintf(LogDEBUG, "DeleteIfRoutes: Index: %d\n", rtm->rtm_index);
|
||||
if (dstnet.s_addr == INADDR_ANY)
|
||||
mask = INADDR_ANY;
|
||||
mask = INADDR_ANY;
|
||||
maddr.s_addr = htonl(mask);
|
||||
OsSetRoute(RTM_DELETE, dstnet, gateway, maddr);
|
||||
}
|
||||
@ -347,41 +356,41 @@ int all;
|
||||
*/
|
||||
|
||||
int
|
||||
GetIfIndex(name)
|
||||
char *name;
|
||||
GetIfIndex(char *name)
|
||||
{
|
||||
char *buffer;
|
||||
struct ifreq *ifrp;
|
||||
int s, len, elen, index;
|
||||
struct ifconf ifconfs;
|
||||
|
||||
/* struct ifreq reqbuf[256]; -- obsoleted :) */
|
||||
int oldbufsize, bufsize = sizeof(struct ifreq);
|
||||
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "GetIfIndex: socket: %s", strerror(errno));
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
buffer = malloc(bufsize); /* allocate first buffer */
|
||||
ifconfs.ifc_len = bufsize; /* Initial setting */
|
||||
|
||||
buffer = malloc(bufsize); /* allocate first buffer */
|
||||
ifconfs.ifc_len = bufsize; /* Initial setting */
|
||||
/*
|
||||
* Iterate through here until we don't get many more data
|
||||
* Iterate through here until we don't get many more data
|
||||
*/
|
||||
|
||||
do {
|
||||
oldbufsize = ifconfs.ifc_len;
|
||||
bufsize += 1+sizeof(struct ifreq);
|
||||
buffer = realloc((void *)buffer, bufsize); /* Make it bigger */
|
||||
LogPrintf(LogDEBUG, "GetIfIndex: Growing buffer to %d\n", bufsize);
|
||||
ifconfs.ifc_len = bufsize;
|
||||
ifconfs.ifc_buf = buffer;
|
||||
if (ioctl(s, SIOCGIFCONF, &ifconfs) < 0) {
|
||||
LogPrintf(LogERROR, "ioctl(SIOCGIFCONF): %s", strerror(errno));
|
||||
close(s);
|
||||
free(buffer);
|
||||
return(-1);
|
||||
}
|
||||
oldbufsize = ifconfs.ifc_len;
|
||||
bufsize += 1 + sizeof(struct ifreq);
|
||||
buffer = realloc((void *) buffer, bufsize); /* Make it bigger */
|
||||
LogPrintf(LogDEBUG, "GetIfIndex: Growing buffer to %d\n", bufsize);
|
||||
ifconfs.ifc_len = bufsize;
|
||||
ifconfs.ifc_buf = buffer;
|
||||
if (ioctl(s, SIOCGIFCONF, &ifconfs) < 0) {
|
||||
LogPrintf(LogERROR, "ioctl(SIOCGIFCONF): %s", strerror(errno));
|
||||
close(s);
|
||||
free(buffer);
|
||||
return (-1);
|
||||
}
|
||||
} while (ifconfs.ifc_len > oldbufsize);
|
||||
|
||||
ifrp = ifconfs.ifc_req;
|
||||
@ -394,20 +403,19 @@ char *name;
|
||||
index, IFNAMSIZ, IFNAMSIZ, ifrp->ifr_name,
|
||||
ifrp->ifr_addr.sa_family, elen);
|
||||
if (strcmp(ifrp->ifr_name, name) == 0) {
|
||||
IfIndex = index;
|
||||
IfIndex = index;
|
||||
close(s);
|
||||
free(buffer);
|
||||
return(index);
|
||||
return (index);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
len -= elen;
|
||||
ifrp = (struct ifreq *)((char *)ifrp + elen);
|
||||
ifrp = (struct ifreq *) ((char *) ifrp + elen);
|
||||
ifrp++;
|
||||
}
|
||||
|
||||
close(s);
|
||||
free(buffer);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
@ -17,11 +17,12 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: route.h,v 1.3 1997/02/22 16:10:50 peter Exp $
|
||||
* $Id: route.h,v 1.4 1997/06/09 03:27:36 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ROUTE_H_
|
||||
#define _ROUTE_H_
|
||||
int GetIfIndex(char *);
|
||||
|
||||
#endif
|
||||
|
@ -23,78 +23,77 @@ static char *rm;
|
||||
int
|
||||
ServerLocalOpen(const char *name, mode_t mask)
|
||||
{
|
||||
int s;
|
||||
int s;
|
||||
|
||||
ifsun.sun_len = strlen(name);
|
||||
if (ifsun.sun_len > sizeof ifsun.sun_path - 1) {
|
||||
LogPrintf(LogERROR, "Local: %s: Path too long\n", name);
|
||||
return 1;
|
||||
}
|
||||
ifsun.sun_family = AF_LOCAL;
|
||||
strcpy(ifsun.sun_path, name);
|
||||
ifsun.sun_len = strlen(name);
|
||||
if (ifsun.sun_len > sizeof ifsun.sun_path - 1) {
|
||||
LogPrintf(LogERROR, "Local: %s: Path too long\n", name);
|
||||
return 1;
|
||||
}
|
||||
ifsun.sun_family = AF_LOCAL;
|
||||
strcpy(ifsun.sun_path, name);
|
||||
|
||||
s = socket(PF_LOCAL, SOCK_STREAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "Local: socket: %s\n", strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
|
||||
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &s, sizeof s);
|
||||
mask = umask(mask);
|
||||
if (bind(s, (struct sockaddr *) &ifsun, sizeof(ifsun)) < 0) {
|
||||
umask(mask);
|
||||
LogPrintf(LogERROR, "Local: bind: %s\n", strerror(errno));
|
||||
if (errno == EADDRINUSE && VarTerm)
|
||||
fprintf(VarTerm, "Wait for a while, then try again.\n");
|
||||
close(s);
|
||||
unlink(name);
|
||||
return 3;
|
||||
}
|
||||
s = socket(PF_LOCAL, SOCK_STREAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "Local: socket: %s\n", strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &s, sizeof s);
|
||||
mask = umask(mask);
|
||||
if (bind(s, (struct sockaddr *) & ifsun, sizeof(ifsun)) < 0) {
|
||||
umask(mask);
|
||||
if (listen(s, 5) != 0) {
|
||||
LogPrintf(LogERROR, "Local: Unable to listen to socket - OS overload?\n");
|
||||
close(s);
|
||||
unlink(name);
|
||||
return 4;
|
||||
}
|
||||
ServerClose();
|
||||
server = s;
|
||||
rm = ifsun.sun_path;
|
||||
LogPrintf(LogPHASE, "Listening at local socket %s.\n", name);
|
||||
return 0;
|
||||
LogPrintf(LogERROR, "Local: bind: %s\n", strerror(errno));
|
||||
if (errno == EADDRINUSE && VarTerm)
|
||||
fprintf(VarTerm, "Wait for a while, then try again.\n");
|
||||
close(s);
|
||||
unlink(name);
|
||||
return 3;
|
||||
}
|
||||
umask(mask);
|
||||
if (listen(s, 5) != 0) {
|
||||
LogPrintf(LogERROR, "Local: Unable to listen to socket - OS overload?\n");
|
||||
close(s);
|
||||
unlink(name);
|
||||
return 4;
|
||||
}
|
||||
ServerClose();
|
||||
server = s;
|
||||
rm = ifsun.sun_path;
|
||||
LogPrintf(LogPHASE, "Listening at local socket %s.\n", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ServerTcpOpen(int port)
|
||||
{
|
||||
struct sockaddr_in ifsin;
|
||||
int s;
|
||||
struct sockaddr_in ifsin;
|
||||
int s;
|
||||
|
||||
s = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "Tcp: socket: %s\n", strerror(errno));
|
||||
return 5;
|
||||
}
|
||||
ifsin.sin_family = AF_INET;
|
||||
ifsin.sin_addr.s_addr = INADDR_ANY;
|
||||
ifsin.sin_port = htons(port);
|
||||
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &s, sizeof s);
|
||||
if (bind(s, (struct sockaddr *) &ifsin, sizeof(ifsin)) < 0) {
|
||||
LogPrintf(LogERROR, "Tcp: bind: %s\n", strerror(errno));
|
||||
if (errno == EADDRINUSE && VarTerm)
|
||||
fprintf(VarTerm, "Wait for a while, then try again.\n");
|
||||
close(s);
|
||||
return 6;
|
||||
}
|
||||
if (listen(s, 5) != 0) {
|
||||
LogPrintf(LogERROR, "Tcp: Unable to listen to socket - OS overload?\n");
|
||||
close(s);
|
||||
return 7;
|
||||
}
|
||||
ServerClose();
|
||||
server = s;
|
||||
LogPrintf(LogPHASE, "Listening at port %d.\n", port);
|
||||
return 0;
|
||||
s = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "Tcp: socket: %s\n", strerror(errno));
|
||||
return 5;
|
||||
}
|
||||
ifsin.sin_family = AF_INET;
|
||||
ifsin.sin_addr.s_addr = INADDR_ANY;
|
||||
ifsin.sin_port = htons(port);
|
||||
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &s, sizeof s);
|
||||
if (bind(s, (struct sockaddr *) & ifsin, sizeof(ifsin)) < 0) {
|
||||
LogPrintf(LogERROR, "Tcp: bind: %s\n", strerror(errno));
|
||||
if (errno == EADDRINUSE && VarTerm)
|
||||
fprintf(VarTerm, "Wait for a while, then try again.\n");
|
||||
close(s);
|
||||
return 6;
|
||||
}
|
||||
if (listen(s, 5) != 0) {
|
||||
LogPrintf(LogERROR, "Tcp: Unable to listen to socket - OS overload?\n");
|
||||
close(s);
|
||||
return 7;
|
||||
}
|
||||
ServerClose();
|
||||
server = s;
|
||||
LogPrintf(LogPHASE, "Listening at port %d.\n", port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -26,7 +26,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: sig.c,v 1.6 1997/03/13 12:45:33 brian Exp $
|
||||
* $Id: sig.c,v 1.7 1997/06/09 03:27:36 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*
|
||||
@ -44,52 +44,57 @@ static sig_type handler[NSIG]; /* all start at SIG_DFL */
|
||||
|
||||
/* Record a signal in the "caused" array */
|
||||
|
||||
static void signal_recorder(int sig) {
|
||||
caused[sig-1]++;
|
||||
static void
|
||||
signal_recorder(int sig)
|
||||
{
|
||||
caused[sig - 1]++;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
set up signal_recorder, and record handler as the function to ultimately
|
||||
call in handle_signal()
|
||||
* Set up signal_recorder, and record handler as the function to ultimately
|
||||
* call in handle_signal()
|
||||
*/
|
||||
|
||||
sig_type pending_signal(int sig,sig_type fn) {
|
||||
sig_type Result;
|
||||
sig_type
|
||||
pending_signal(int sig, sig_type fn)
|
||||
{
|
||||
sig_type Result;
|
||||
|
||||
if (sig <= 0 || sig > NSIG) {
|
||||
/* Oops - we must be a bit out of date (too many sigs ?) */
|
||||
LogPrintf(LogALERT, "Eeek! %s:%s: I must be out of date!\n",
|
||||
__FILE__,__LINE__);
|
||||
return signal(sig,fn);
|
||||
}
|
||||
|
||||
Result = handler[sig-1];
|
||||
if (fn == SIG_DFL || fn == SIG_IGN) {
|
||||
signal(sig,fn);
|
||||
handler[sig-1] = (sig_type)0;
|
||||
} else {
|
||||
handler[sig-1] = fn;
|
||||
signal(sig,signal_recorder);
|
||||
}
|
||||
caused[sig-1] = 0;
|
||||
return Result;
|
||||
if (sig <= 0 || sig > NSIG) {
|
||||
/* Oops - we must be a bit out of date (too many sigs ?) */
|
||||
LogPrintf(LogALERT, "Eeek! %s:%s: I must be out of date!\n",
|
||||
__FILE__, __LINE__);
|
||||
return signal(sig, fn);
|
||||
}
|
||||
Result = handler[sig - 1];
|
||||
if (fn == SIG_DFL || fn == SIG_IGN) {
|
||||
signal(sig, fn);
|
||||
handler[sig - 1] = (sig_type) 0;
|
||||
} else {
|
||||
handler[sig - 1] = fn;
|
||||
signal(sig, signal_recorder);
|
||||
}
|
||||
caused[sig - 1] = 0;
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
/* Call the handlers for any pending signals */
|
||||
|
||||
void handle_signals() {
|
||||
int sig;
|
||||
int got;
|
||||
void
|
||||
handle_signals()
|
||||
{
|
||||
int sig;
|
||||
int got;
|
||||
|
||||
do {
|
||||
got = 0;
|
||||
for (sig = 0; sig < NSIG; sig++)
|
||||
if (caused[sig]) {
|
||||
caused[sig]--;
|
||||
got++;
|
||||
(*handler[sig])(sig+1);
|
||||
}
|
||||
} while(got);
|
||||
do {
|
||||
got = 0;
|
||||
for (sig = 0; sig < NSIG; sig++)
|
||||
if (caused[sig]) {
|
||||
caused[sig]--;
|
||||
got++;
|
||||
(*handler[sig]) (sig + 1);
|
||||
}
|
||||
} while (got);
|
||||
}
|
||||
|
@ -26,13 +26,13 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: sig.h,v 1.7 1997/03/13 12:45:35 brian Exp $
|
||||
* $Id: sig.h,v 1.8 1997/06/09 03:27:37 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*
|
||||
*/
|
||||
|
||||
typedef void (*sig_type)(int);
|
||||
typedef void (*sig_type) (int);
|
||||
|
||||
/* Call this instead of signal() */
|
||||
extern sig_type pending_signal(int, sig_type);
|
||||
|
@ -17,13 +17,14 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: slcompress.c,v 1.8 1997/02/22 16:10:54 peter Exp $
|
||||
* $Id: slcompress.c,v 1.9 1997/06/09 03:27:37 brian Exp $
|
||||
*
|
||||
* Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
|
||||
* - Initial distribution.
|
||||
*/
|
||||
#ifndef lint
|
||||
static char const rcsid[] = "$Id: slcompress.c,v 1.8 1997/02/22 16:10:54 peter Exp $";
|
||||
static char const rcsid[] = "$Id: slcompress.c,v 1.9 1997/06/09 03:27:37 brian Exp $";
|
||||
|
||||
#endif
|
||||
|
||||
#include "defs.h"
|
||||
@ -46,23 +47,22 @@ struct slstat slstat;
|
||||
#endif
|
||||
|
||||
void
|
||||
sl_compress_init(comp)
|
||||
struct slcompress *comp;
|
||||
sl_compress_init(struct slcompress * comp)
|
||||
{
|
||||
register u_int i;
|
||||
register struct cstate *tstate = comp->tstate;
|
||||
register u_int i;
|
||||
register struct cstate *tstate = comp->tstate;
|
||||
|
||||
bzero((char *)comp, sizeof(*comp));
|
||||
for (i = MAX_STATES - 1; i > 0; --i) {
|
||||
tstate[i].cs_id = i;
|
||||
tstate[i].cs_next = &tstate[i - 1];
|
||||
}
|
||||
tstate[0].cs_next = &tstate[MAX_STATES - 1];
|
||||
tstate[0].cs_id = 0;
|
||||
comp->last_cs = &tstate[0];
|
||||
comp->last_recv = 255;
|
||||
comp->last_xmit = 255;
|
||||
comp->flags = SLF_TOSS;
|
||||
bzero((char *) comp, sizeof(*comp));
|
||||
for (i = MAX_STATES - 1; i > 0; --i) {
|
||||
tstate[i].cs_id = i;
|
||||
tstate[i].cs_next = &tstate[i - 1];
|
||||
}
|
||||
tstate[0].cs_next = &tstate[MAX_STATES - 1];
|
||||
tstate[0].cs_id = 0;
|
||||
comp->last_cs = &tstate[0];
|
||||
comp->last_recv = 255;
|
||||
comp->last_xmit = 255;
|
||||
comp->flags = SLF_TOSS;
|
||||
}
|
||||
|
||||
|
||||
@ -120,446 +120,449 @@ sl_compress_init(comp)
|
||||
|
||||
|
||||
u_char
|
||||
sl_compress_tcp(m, ip, comp, compress_cid)
|
||||
struct mbuf *m;
|
||||
register struct ip *ip;
|
||||
struct slcompress *comp;
|
||||
int compress_cid;
|
||||
sl_compress_tcp(struct mbuf * m,
|
||||
struct ip * ip,
|
||||
struct slcompress * comp,
|
||||
int compress_cid)
|
||||
{
|
||||
register struct cstate *cs = comp->last_cs->cs_next;
|
||||
register u_int hlen = ip->ip_hl;
|
||||
register struct tcphdr *oth;
|
||||
register struct tcphdr *th;
|
||||
register u_int deltaS, deltaA;
|
||||
register u_int changes = 0;
|
||||
u_char new_seq[16];
|
||||
register u_char *cp = new_seq;
|
||||
register struct cstate *cs = comp->last_cs->cs_next;
|
||||
register u_int hlen = ip->ip_hl;
|
||||
register struct tcphdr *oth;
|
||||
register struct tcphdr *th;
|
||||
register u_int deltaS, deltaA;
|
||||
register u_int changes = 0;
|
||||
u_char new_seq[16];
|
||||
register u_char *cp = new_seq;
|
||||
|
||||
/*
|
||||
* 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). (We assume that the caller has already made sure the
|
||||
* packet is IP proto TCP).
|
||||
*/
|
||||
if ((ip->ip_off & htons(0x3fff)) || m->cnt < 40) {
|
||||
LogPrintf(LogDEBUG, "??? 1 ip_off = %x, cnt = %d\n",
|
||||
ip->ip_off, m->cnt);
|
||||
LogDumpBp(LogDEBUG, "", m);
|
||||
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). (We assume that
|
||||
* the caller has already made sure the packet is IP proto TCP).
|
||||
*/
|
||||
if ((ip->ip_off & htons(0x3fff)) || m->cnt < 40) {
|
||||
LogPrintf(LogDEBUG, "??? 1 ip_off = %x, cnt = %d\n",
|
||||
ip->ip_off, m->cnt);
|
||||
LogDumpBp(LogDEBUG, "", m);
|
||||
return (TYPE_IP);
|
||||
}
|
||||
th = (struct tcphdr *) & ((int *) ip)[hlen];
|
||||
if ((th->th_flags & (TH_SYN | TH_FIN | TH_RST | TH_ACK)) != TH_ACK) {
|
||||
LogPrintf(LogDEBUG, "??? 2 th_flags = %x\n", th->th_flags);
|
||||
LogDumpBp(LogDEBUG, "", m);
|
||||
return (TYPE_IP);
|
||||
}
|
||||
|
||||
th = (struct tcphdr *)&((int *)ip)[hlen];
|
||||
if ((th->th_flags & (TH_SYN|TH_FIN|TH_RST|TH_ACK)) != TH_ACK) {
|
||||
LogPrintf(LogDEBUG, "??? 2 th_flags = %x\n", th->th_flags);
|
||||
LogDumpBp(LogDEBUG, "", m);
|
||||
return (TYPE_IP);
|
||||
}
|
||||
/*
|
||||
* Packet is compressible -- we're going to send either a COMPRESSED_TCP or
|
||||
* UNCOMPRESSED_TCP packet. Either way we need to locate (or create) the
|
||||
* connection state. Special case the most recently used connection since
|
||||
* it's most likely to be used again & we don't have to do any reordering
|
||||
* if it's used.
|
||||
*/
|
||||
INCR(sls_packets)
|
||||
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 ||
|
||||
*(int *) th != ((int *) &cs->cs_ip)[cs->cs_ip.ip_hl]) {
|
||||
|
||||
/*
|
||||
* Packet is compressible -- we're going to send either a
|
||||
* COMPRESSED_TCP or UNCOMPRESSED_TCP packet. Either way we need
|
||||
* to locate (or create) the connection state. Special case the
|
||||
* most recently used connection since it's most likely to be used
|
||||
* again & we don't have to do any reordering if it's used.
|
||||
*/
|
||||
INCR(sls_packets)
|
||||
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 ||
|
||||
*(int *)th != ((int *)&cs->cs_ip)[cs->cs_ip.ip_hl]) {
|
||||
/*
|
||||
* Wasn't the first -- search for it.
|
||||
*
|
||||
* States are kept in a circularly linked list with
|
||||
* last_cs pointing to the end of the list. The
|
||||
* list is kept in lru order by moving a state to the
|
||||
* head of the list whenever it is referenced. Since
|
||||
* the list is short and, empirically, the connection
|
||||
* we want is almost always near the front, we locate
|
||||
* states via linear search. If we don't find a state
|
||||
* for the datagram, the oldest state is (re-)used.
|
||||
*/
|
||||
register struct cstate *lcs;
|
||||
register struct cstate *lastcs = comp->last_cs;
|
||||
/*
|
||||
* Wasn't the first -- search for it.
|
||||
*
|
||||
* States are kept in a circularly linked list with last_cs pointing to the
|
||||
* end of the list. The list is kept in lru order by moving a state to
|
||||
* the head of the list whenever it is referenced. Since the list is
|
||||
* short and, empirically, the connection we want is almost always near
|
||||
* the front, we locate states via linear search. If we don't find a
|
||||
* state for the datagram, the oldest state is (re-)used.
|
||||
*/
|
||||
register struct cstate *lcs;
|
||||
register struct cstate *lastcs = comp->last_cs;
|
||||
|
||||
do {
|
||||
lcs = cs; cs = cs->cs_next;
|
||||
INCR(sls_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
|
||||
&& *(int *)th == ((int *)&cs->cs_ip)[cs->cs_ip.ip_hl])
|
||||
goto found;
|
||||
} while (cs != lastcs);
|
||||
do {
|
||||
lcs = cs;
|
||||
cs = cs->cs_next;
|
||||
INCR(sls_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
|
||||
&& *(int *) th == ((int *) &cs->cs_ip)[cs->cs_ip.ip_hl])
|
||||
goto found;
|
||||
} while (cs != lastcs);
|
||||
|
||||
/*
|
||||
* Didn't find it -- re-use oldest cstate. Send an
|
||||
* uncompressed packet that tells the other side what
|
||||
* connection number we're using for this conversation.
|
||||
* Note that since the state list is circular, the oldest
|
||||
* state points to the newest and we only need to set
|
||||
* last_cs to update the lru linkage.
|
||||
*/
|
||||
INCR(sls_misses)
|
||||
comp->last_cs = lcs;
|
||||
/*
|
||||
* Didn't find it -- re-use oldest cstate. Send an uncompressed packet
|
||||
* that tells the other side what connection number we're using for this
|
||||
* conversation. Note that since the state list is circular, the oldest
|
||||
* state points to the newest and we only need to set last_cs to update
|
||||
* the lru linkage.
|
||||
*/
|
||||
INCR(sls_misses)
|
||||
comp->last_cs = lcs;
|
||||
#define THOFFSET(th) (th->th_off)
|
||||
hlen += th->th_off;
|
||||
hlen <<= 2;
|
||||
if (hlen > m->cnt)
|
||||
return(TYPE_IP);
|
||||
goto uncompressed;
|
||||
hlen += th->th_off;
|
||||
hlen <<= 2;
|
||||
if (hlen > m->cnt)
|
||||
return (TYPE_IP);
|
||||
goto uncompressed;
|
||||
|
||||
found:
|
||||
/*
|
||||
* Found it -- move to the front on the connection list.
|
||||
*/
|
||||
if (cs == lastcs)
|
||||
comp->last_cs = lcs;
|
||||
else {
|
||||
lcs->cs_next = cs->cs_next;
|
||||
cs->cs_next = lastcs->cs_next;
|
||||
lastcs->cs_next = cs;
|
||||
}
|
||||
}
|
||||
found:
|
||||
|
||||
/*
|
||||
* Make sure that only what we expect to change changed. The first
|
||||
* line of the `if' checks the IP protocol version, header length &
|
||||
* type of service. The 2nd line checks the "Don't fragment" bit.
|
||||
* The 3rd line checks the time-to-live and protocol (the protocol
|
||||
* check is unnecessary but costless). The 4th line checks the TCP
|
||||
* header length. The 5th line checks IP options, if any. The 6th
|
||||
* line checks TCP options, if any. If any of these things are
|
||||
* different between the previous & current datagram, we send the
|
||||
* current datagram `uncompressed'.
|
||||
*/
|
||||
oth = (struct tcphdr *)&((int *)&cs->cs_ip)[hlen];
|
||||
deltaS = hlen;
|
||||
hlen += th->th_off;
|
||||
hlen <<= 2;
|
||||
if (hlen > m->cnt)
|
||||
return(TYPE_IP);
|
||||
/*
|
||||
* Found it -- move to the front on the connection list.
|
||||
*/
|
||||
if (cs == lastcs)
|
||||
comp->last_cs = lcs;
|
||||
else {
|
||||
lcs->cs_next = cs->cs_next;
|
||||
cs->cs_next = lastcs->cs_next;
|
||||
lastcs->cs_next = cs;
|
||||
}
|
||||
}
|
||||
|
||||
if (((u_short *)ip)[0] != ((u_short *)&cs->cs_ip)[0] ||
|
||||
((u_short *)ip)[3] != ((u_short *)&cs->cs_ip)[3] ||
|
||||
((u_short *)ip)[4] != ((u_short *)&cs->cs_ip)[4] ||
|
||||
THOFFSET(th) != THOFFSET(oth) ||
|
||||
(deltaS > 5 &&
|
||||
BCMP(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2)) ||
|
||||
(THOFFSET(th) > 5 &&
|
||||
BCMP(th + 1, oth + 1, (THOFFSET(th) - 5) << 2))) {
|
||||
goto uncompressed;
|
||||
}
|
||||
/*
|
||||
* Make sure that only what we expect to change changed. The first line of
|
||||
* the `if' checks the IP protocol version, header length & type of
|
||||
* service. The 2nd line checks the "Don't fragment" bit. The 3rd line
|
||||
* checks the time-to-live and protocol (the protocol check is unnecessary
|
||||
* but costless). The 4th line checks the TCP header length. The 5th line
|
||||
* checks IP options, if any. The 6th line checks TCP options, if any. If
|
||||
* any of these things are different between the previous & current
|
||||
* datagram, we send the current datagram `uncompressed'.
|
||||
*/
|
||||
oth = (struct tcphdr *) & ((int *) &cs->cs_ip)[hlen];
|
||||
deltaS = hlen;
|
||||
hlen += th->th_off;
|
||||
hlen <<= 2;
|
||||
if (hlen > m->cnt)
|
||||
return (TYPE_IP);
|
||||
|
||||
/*
|
||||
* Figure out which of the changing fields changed. The
|
||||
* receiver expects changes in the order: urgent, window,
|
||||
* ack, seq (the order minimizes the number of temporaries
|
||||
* needed in this section of code).
|
||||
*/
|
||||
if (th->th_flags & TH_URG) {
|
||||
deltaS = ntohs(th->th_urp);
|
||||
ENCODEZ(deltaS);
|
||||
changes |= NEW_U;
|
||||
} 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 (((u_short *) ip)[0] != ((u_short *) & cs->cs_ip)[0] ||
|
||||
((u_short *) ip)[3] != ((u_short *) & cs->cs_ip)[3] ||
|
||||
((u_short *) ip)[4] != ((u_short *) & cs->cs_ip)[4] ||
|
||||
THOFFSET(th) != THOFFSET(oth) ||
|
||||
(deltaS > 5 &&
|
||||
BCMP(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2)) ||
|
||||
(THOFFSET(th) > 5 &&
|
||||
BCMP(th + 1, oth + 1, (THOFFSET(th) - 5) << 2))) {
|
||||
goto uncompressed;
|
||||
}
|
||||
|
||||
deltaS = (u_short)(ntohs(th->th_win) - ntohs(oth->th_win));
|
||||
if (deltaS) {
|
||||
ENCODE(deltaS);
|
||||
changes |= NEW_W;
|
||||
}
|
||||
/*
|
||||
* Figure out which of the changing fields changed. The receiver expects
|
||||
* changes in the order: urgent, window, ack, seq (the order minimizes the
|
||||
* number of temporaries needed in this section of code).
|
||||
*/
|
||||
if (th->th_flags & TH_URG) {
|
||||
deltaS = ntohs(th->th_urp);
|
||||
ENCODEZ(deltaS);
|
||||
changes |= NEW_U;
|
||||
} else if (th->th_urp != oth->th_urp) {
|
||||
|
||||
deltaA = ntohl(th->th_ack) - ntohl(oth->th_ack);
|
||||
if (deltaA) {
|
||||
if (deltaA > 0xffff) {
|
||||
goto uncompressed;
|
||||
}
|
||||
ENCODE(deltaA);
|
||||
changes |= NEW_A;
|
||||
}
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
deltaS = (u_short) (ntohs(th->th_win) - ntohs(oth->th_win));
|
||||
if (deltaS) {
|
||||
ENCODE(deltaS);
|
||||
changes |= NEW_W;
|
||||
}
|
||||
deltaA = ntohl(th->th_ack) - ntohl(oth->th_ack);
|
||||
if (deltaA) {
|
||||
if (deltaA > 0xffff) {
|
||||
goto uncompressed;
|
||||
}
|
||||
ENCODE(deltaA);
|
||||
changes |= NEW_A;
|
||||
}
|
||||
deltaS = ntohl(th->th_seq) - ntohl(oth->th_seq);
|
||||
if (deltaS) {
|
||||
if (deltaS > 0xffff) {
|
||||
goto uncompressed;
|
||||
}
|
||||
ENCODE(deltaS);
|
||||
changes |= NEW_S;
|
||||
}
|
||||
switch (changes) {
|
||||
|
||||
deltaS = ntohl(th->th_seq) - ntohl(oth->th_seq);
|
||||
if (deltaS) {
|
||||
if (deltaS > 0xffff) {
|
||||
goto uncompressed;
|
||||
}
|
||||
ENCODE(deltaS);
|
||||
changes |= NEW_S;
|
||||
}
|
||||
case 0:
|
||||
|
||||
switch(changes) {
|
||||
/*
|
||||
* Nothing changed. If this packet contains data and the last one didn't,
|
||||
* this is probably a data packet following an ack (normal on an
|
||||
* interactive connection) and we send it compressed. Otherwise it's
|
||||
* probably a retransmit, retransmitted ack or window probe. Send it
|
||||
* uncompressed 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)
|
||||
break;
|
||||
|
||||
case 0:
|
||||
/*
|
||||
* Nothing changed. If this packet contains data and the
|
||||
* last one didn't, this is probably a data packet following
|
||||
* an ack (normal on an interactive connection) and we send
|
||||
* it compressed. Otherwise it's probably a retransmit,
|
||||
* retransmitted ack or window probe. Send it uncompressed
|
||||
* 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)
|
||||
break;
|
||||
/* (fall through) */
|
||||
|
||||
/* (fall through) */
|
||||
case SPECIAL_I:
|
||||
case SPECIAL_D:
|
||||
|
||||
case SPECIAL_I:
|
||||
case SPECIAL_D:
|
||||
/*
|
||||
* actual changes match one of our special case encodings --
|
||||
* send packet uncompressed.
|
||||
*/
|
||||
goto uncompressed;
|
||||
/*
|
||||
* actual changes match one of our special case encodings -- send packet
|
||||
* uncompressed.
|
||||
*/
|
||||
goto uncompressed;
|
||||
|
||||
case NEW_S|NEW_A:
|
||||
if (deltaS == deltaA &&
|
||||
deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
|
||||
/* special case for echoed terminal traffic */
|
||||
changes = SPECIAL_I;
|
||||
cp = new_seq;
|
||||
}
|
||||
break;
|
||||
case NEW_S | NEW_A:
|
||||
if (deltaS == deltaA &&
|
||||
deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
|
||||
/* special case for echoed terminal traffic */
|
||||
changes = SPECIAL_I;
|
||||
cp = new_seq;
|
||||
}
|
||||
break;
|
||||
|
||||
case NEW_S:
|
||||
if (deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
|
||||
/* special case for data xfer */
|
||||
changes = SPECIAL_D;
|
||||
cp = new_seq;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEW_S:
|
||||
if (deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
|
||||
/* special case for data xfer */
|
||||
changes = SPECIAL_D;
|
||||
cp = new_seq;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
deltaS = ntohs(ip->ip_id) - ntohs(cs->cs_ip.ip_id);
|
||||
if (deltaS != 1) {
|
||||
ENCODEZ(deltaS);
|
||||
changes |= NEW_I;
|
||||
}
|
||||
if (th->th_flags & TH_PUSH)
|
||||
changes |= TCP_PUSH_BIT;
|
||||
/*
|
||||
* Grab the cksum before we overwrite it below. Then update our
|
||||
* state with this packet's header.
|
||||
*/
|
||||
deltaA = ntohs(th->th_sum);
|
||||
BCOPY(ip, &cs->cs_ip, hlen);
|
||||
deltaS = ntohs(ip->ip_id) - ntohs(cs->cs_ip.ip_id);
|
||||
if (deltaS != 1) {
|
||||
ENCODEZ(deltaS);
|
||||
changes |= NEW_I;
|
||||
}
|
||||
if (th->th_flags & TH_PUSH)
|
||||
changes |= TCP_PUSH_BIT;
|
||||
|
||||
/*
|
||||
* We want to use the original packet as our compressed packet.
|
||||
* (cp - new_seq) is the number of bytes we need for compressed
|
||||
* sequence numbers. In addition we need one byte for the change
|
||||
* mask, one for the connection id and two for the tcp checksum.
|
||||
* So, (cp - new_seq) + 4 bytes of header are needed. hlen is how
|
||||
* many bytes of the original packet to toss so subtract the two to
|
||||
* get the new packet size.
|
||||
*/
|
||||
deltaS = cp - new_seq;
|
||||
cp = (u_char *)ip;
|
||||
/*
|
||||
* Grab the cksum before we overwrite it below. Then update our state with
|
||||
* this packet's header.
|
||||
*/
|
||||
deltaA = ntohs(th->th_sum);
|
||||
BCOPY(ip, &cs->cs_ip, hlen);
|
||||
|
||||
/*
|
||||
* Since fastq traffic can jump ahead of the background traffic,
|
||||
* we don't know what order packets will go on the line. In this
|
||||
* case, we always send a "new" connection id so the receiver state
|
||||
* stays synchronized.
|
||||
*/
|
||||
/*
|
||||
* We want to use the original packet as our compressed packet. (cp -
|
||||
* new_seq) is the number of bytes we need for compressed sequence numbers.
|
||||
* In addition we need one byte for the change mask, one for the connection
|
||||
* id and two for the tcp checksum. So, (cp - new_seq) + 4 bytes of header
|
||||
* are needed. hlen is how many bytes of the original packet to toss so
|
||||
* subtract the two to get the new packet size.
|
||||
*/
|
||||
deltaS = cp - new_seq;
|
||||
cp = (u_char *) ip;
|
||||
|
||||
/*
|
||||
* Since fastq traffic can jump ahead of the background traffic, we don't
|
||||
* know what order packets will go on the line. In this case, we always
|
||||
* send a "new" connection id so the receiver state stays synchronized.
|
||||
*/
|
||||
#ifdef SL_NOFASTQ
|
||||
if (comp->last_xmit == cs->cs_id) {
|
||||
hlen -= deltaS + 3;
|
||||
cp += hlen;
|
||||
*cp++ = changes;
|
||||
} else
|
||||
if (comp->last_xmit == cs->cs_id) {
|
||||
hlen -= deltaS + 3;
|
||||
cp += hlen;
|
||||
*cp++ = changes;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
comp->last_xmit = cs->cs_id;
|
||||
hlen -= deltaS + 4;
|
||||
cp += hlen;
|
||||
*cp++ = changes | NEW_C;
|
||||
*cp++ = cs->cs_id;
|
||||
}
|
||||
m->cnt -= hlen;
|
||||
m->offset += hlen;
|
||||
*cp++ = deltaA >> 8;
|
||||
*cp++ = deltaA;
|
||||
BCOPY(new_seq, cp, deltaS);
|
||||
INCR(sls_compressed)
|
||||
return (TYPE_COMPRESSED_TCP);
|
||||
{
|
||||
comp->last_xmit = cs->cs_id;
|
||||
hlen -= deltaS + 4;
|
||||
cp += hlen;
|
||||
*cp++ = changes | NEW_C;
|
||||
*cp++ = cs->cs_id;
|
||||
}
|
||||
m->cnt -= hlen;
|
||||
m->offset += hlen;
|
||||
*cp++ = deltaA >> 8;
|
||||
*cp++ = deltaA;
|
||||
BCOPY(new_seq, cp, deltaS);
|
||||
INCR(sls_compressed)
|
||||
return (TYPE_COMPRESSED_TCP);
|
||||
|
||||
/*
|
||||
* Update connection state cs & send uncompressed packet ('uncompressed'
|
||||
* means a regular ip/tcp packet but with the 'conversation id' we hope
|
||||
* to use on future compressed packets in the protocol field).
|
||||
*/
|
||||
/*
|
||||
* Update connection state cs & send uncompressed packet ('uncompressed'
|
||||
* means a regular ip/tcp packet but with the 'conversation id' we hope to
|
||||
* use on future compressed packets in the protocol field).
|
||||
*/
|
||||
uncompressed:
|
||||
BCOPY(ip, &cs->cs_ip, hlen);
|
||||
ip->ip_p = cs->cs_id;
|
||||
comp->last_xmit = cs->cs_id;
|
||||
return (TYPE_UNCOMPRESSED_TCP);
|
||||
BCOPY(ip, &cs->cs_ip, hlen);
|
||||
ip->ip_p = cs->cs_id;
|
||||
comp->last_xmit = cs->cs_id;
|
||||
return (TYPE_UNCOMPRESSED_TCP);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
sl_uncompress_tcp(bufp, len, type, comp)
|
||||
u_char **bufp;
|
||||
int len;
|
||||
u_int type;
|
||||
struct slcompress *comp;
|
||||
sl_uncompress_tcp(u_char ** bufp,
|
||||
int len,
|
||||
u_int type,
|
||||
struct slcompress * comp)
|
||||
{
|
||||
register u_char *cp;
|
||||
register u_int hlen, changes;
|
||||
register struct tcphdr *th;
|
||||
register struct cstate *cs;
|
||||
register struct ip *ip;
|
||||
register u_char *cp;
|
||||
register u_int hlen, changes;
|
||||
register struct tcphdr *th;
|
||||
register struct cstate *cs;
|
||||
register struct ip *ip;
|
||||
|
||||
switch (type) {
|
||||
switch (type) {
|
||||
|
||||
case TYPE_UNCOMPRESSED_TCP:
|
||||
ip = (struct ip *) *bufp;
|
||||
if (ip->ip_p >= MAX_STATES)
|
||||
goto bad;
|
||||
cs = &comp->rstate[comp->last_recv = ip->ip_p];
|
||||
comp->flags &=~ SLF_TOSS;
|
||||
ip->ip_p = IPPROTO_TCP;
|
||||
/*
|
||||
* Calculate the size of the TCP/IP header and make sure that
|
||||
* we don't overflow the space we have available for it.
|
||||
*/
|
||||
hlen = ip->ip_hl << 2;
|
||||
if (hlen + sizeof(struct tcphdr) > len)
|
||||
goto bad;
|
||||
th = (struct tcphdr *)&((char *)ip)[hlen];
|
||||
hlen += THOFFSET(th) << 2;
|
||||
if (hlen > MAX_HDR)
|
||||
goto bad;
|
||||
BCOPY(ip, &cs->cs_ip, hlen);
|
||||
cs->cs_ip.ip_sum = 0;
|
||||
cs->cs_hlen = hlen;
|
||||
INCR(sls_uncompressedin)
|
||||
return (len);
|
||||
case TYPE_UNCOMPRESSED_TCP:
|
||||
ip = (struct ip *) * bufp;
|
||||
if (ip->ip_p >= MAX_STATES)
|
||||
goto bad;
|
||||
cs = &comp->rstate[comp->last_recv = ip->ip_p];
|
||||
comp->flags &= ~SLF_TOSS;
|
||||
ip->ip_p = IPPROTO_TCP;
|
||||
|
||||
default:
|
||||
goto bad;
|
||||
/*
|
||||
* Calculate the size of the TCP/IP header and make sure that we don't
|
||||
* overflow the space we have available for it.
|
||||
*/
|
||||
hlen = ip->ip_hl << 2;
|
||||
if (hlen + sizeof(struct tcphdr) > len)
|
||||
goto bad;
|
||||
th = (struct tcphdr *) & ((char *) ip)[hlen];
|
||||
hlen += THOFFSET(th) << 2;
|
||||
if (hlen > MAX_HDR)
|
||||
goto bad;
|
||||
BCOPY(ip, &cs->cs_ip, hlen);
|
||||
cs->cs_ip.ip_sum = 0;
|
||||
cs->cs_hlen = hlen;
|
||||
INCR(sls_uncompressedin)
|
||||
return (len);
|
||||
|
||||
case TYPE_COMPRESSED_TCP:
|
||||
break;
|
||||
default:
|
||||
goto bad;
|
||||
|
||||
case TYPE_COMPRESSED_TCP:
|
||||
break;
|
||||
}
|
||||
/* We've got a compressed packet. */
|
||||
INCR(sls_compressedin)
|
||||
cp = *bufp;
|
||||
changes = *cp++;
|
||||
LogPrintf(LogDEBUG, "compressed: changes = %02x\n", changes);
|
||||
if (changes & NEW_C) {
|
||||
|
||||
/*
|
||||
* Make sure the state index is in range, then grab the state. If we have
|
||||
* a good state index, clear the 'discard' flag.
|
||||
*/
|
||||
if (*cp >= MAX_STATES || comp->last_recv == 255)
|
||||
goto bad;
|
||||
|
||||
comp->flags &= ~SLF_TOSS;
|
||||
comp->last_recv = *cp++;
|
||||
} else {
|
||||
|
||||
/*
|
||||
* this packet has an implicit state index. If we've had a line error
|
||||
* since the last time we got an explicit state index, we have to toss
|
||||
* the packet.
|
||||
*/
|
||||
if (comp->flags & SLF_TOSS) {
|
||||
INCR(sls_tossed)
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
cs = &comp->rstate[comp->last_recv];
|
||||
hlen = cs->cs_ip.ip_hl << 2;
|
||||
th = (struct tcphdr *) & ((u_char *) & cs->cs_ip)[hlen];
|
||||
th->th_sum = htons((*cp << 8) | cp[1]);
|
||||
cp += 2;
|
||||
if (changes & TCP_PUSH_BIT)
|
||||
th->th_flags |= TH_PUSH;
|
||||
else
|
||||
th->th_flags &= ~TH_PUSH;
|
||||
|
||||
switch (changes & SPECIALS_MASK) {
|
||||
case SPECIAL_I:
|
||||
{
|
||||
register u_int i = ntohs(cs->cs_ip.ip_len) - cs->cs_hlen;
|
||||
|
||||
th->th_ack = htonl(ntohl(th->th_ack) + i);
|
||||
th->th_seq = htonl(ntohl(th->th_seq) + i);
|
||||
}
|
||||
break;
|
||||
|
||||
case SPECIAL_D:
|
||||
th->th_seq = htonl(ntohl(th->th_seq) + ntohs(cs->cs_ip.ip_len)
|
||||
- cs->cs_hlen);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (changes & NEW_U) {
|
||||
th->th_flags |= TH_URG;
|
||||
DECODEU(th->th_urp)
|
||||
} else
|
||||
th->th_flags &= ~TH_URG;
|
||||
if (changes & NEW_W)
|
||||
DECODES(th->th_win)
|
||||
if (changes & NEW_A)
|
||||
DECODEL(th->th_ack)
|
||||
if (changes & NEW_S) {
|
||||
LogPrintf(LogDEBUG, "NEW_S: %02x, %02x, %02x\n",
|
||||
*cp, cp[1], cp[2]);
|
||||
DECODEL(th->th_seq)
|
||||
}
|
||||
/* We've got a compressed packet. */
|
||||
INCR(sls_compressedin)
|
||||
cp = *bufp;
|
||||
changes = *cp++;
|
||||
LogPrintf(LogDEBUG, "compressed: changes = %02x\n", changes);
|
||||
if (changes & NEW_C) {
|
||||
/* Make sure the state index is in range, then grab the state.
|
||||
* If we have a good state index, clear the 'discard' flag. */
|
||||
if (*cp >= MAX_STATES || comp->last_recv == 255)
|
||||
goto bad;
|
||||
break;
|
||||
}
|
||||
if (changes & NEW_I) {
|
||||
DECODES(cs->cs_ip.ip_id)
|
||||
} else
|
||||
cs->cs_ip.ip_id = htons(ntohs(cs->cs_ip.ip_id) + 1);
|
||||
|
||||
comp->flags &=~ SLF_TOSS;
|
||||
comp->last_recv = *cp++;
|
||||
} else {
|
||||
/* this packet has an implicit state index. If we've
|
||||
* had a line error since the last time we got an
|
||||
* explicit state index, we have to toss the packet. */
|
||||
if (comp->flags & SLF_TOSS) {
|
||||
INCR(sls_tossed)
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
cs = &comp->rstate[comp->last_recv];
|
||||
hlen = cs->cs_ip.ip_hl << 2;
|
||||
th = (struct tcphdr *)&((u_char *)&cs->cs_ip)[hlen];
|
||||
th->th_sum = htons((*cp << 8) | cp[1]);
|
||||
cp += 2;
|
||||
if (changes & TCP_PUSH_BIT)
|
||||
th->th_flags |= TH_PUSH;
|
||||
else
|
||||
th->th_flags &=~ TH_PUSH;
|
||||
LogPrintf(LogDEBUG, "Uncompress: id = %04x, seq = %08x\n",
|
||||
cs->cs_ip.ip_id, ntohl(th->th_seq));
|
||||
|
||||
switch (changes & SPECIALS_MASK) {
|
||||
case SPECIAL_I:
|
||||
{
|
||||
register u_int i = ntohs(cs->cs_ip.ip_len) - cs->cs_hlen;
|
||||
th->th_ack = htonl(ntohl(th->th_ack) + i);
|
||||
th->th_seq = htonl(ntohl(th->th_seq) + i);
|
||||
}
|
||||
break;
|
||||
/*
|
||||
* At this point, cp points to the first byte of data in the packet. If
|
||||
* we're not aligned on a 4-byte boundary, copy the data down so the ip &
|
||||
* tcp headers will be aligned. Then back up cp by the tcp/ip header
|
||||
* length to make room for the reconstructed header (we assume the packet
|
||||
* we were handed has enough space to prepend 128 bytes of header). Adjust
|
||||
* the length to account for the new header & fill in the IP total length.
|
||||
*/
|
||||
len -= (cp - *bufp);
|
||||
if (len < 0)
|
||||
|
||||
case SPECIAL_D:
|
||||
th->th_seq = htonl(ntohl(th->th_seq) + ntohs(cs->cs_ip.ip_len)
|
||||
- cs->cs_hlen);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (changes & NEW_U) {
|
||||
th->th_flags |= TH_URG;
|
||||
DECODEU(th->th_urp)
|
||||
} else
|
||||
th->th_flags &=~ TH_URG;
|
||||
if (changes & NEW_W)
|
||||
DECODES(th->th_win)
|
||||
if (changes & NEW_A)
|
||||
DECODEL(th->th_ack)
|
||||
if (changes & NEW_S) {
|
||||
LogPrintf(LogDEBUG, "NEW_S: %02x, %02x, %02x\n",
|
||||
*cp, cp[1], cp[2]);
|
||||
DECODEL(th->th_seq)
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (changes & NEW_I) {
|
||||
DECODES(cs->cs_ip.ip_id)
|
||||
} else
|
||||
cs->cs_ip.ip_id = htons(ntohs(cs->cs_ip.ip_id) + 1);
|
||||
|
||||
LogPrintf(LogDEBUG, "Uncompress: id = %04x, seq = %08x\n",
|
||||
cs->cs_ip.ip_id, ntohl(th->th_seq));
|
||||
|
||||
/*
|
||||
* At this point, cp points to the first byte of data in the
|
||||
* packet. If we're not aligned on a 4-byte boundary, copy the
|
||||
* data down so the ip & tcp headers will be aligned. Then back up
|
||||
* cp by the tcp/ip header length to make room for the reconstructed
|
||||
* header (we assume the packet we were handed has enough space to
|
||||
* prepend 128 bytes of header). Adjust the length to account for
|
||||
* the new header & fill in the IP total length.
|
||||
*/
|
||||
len -= (cp - *bufp);
|
||||
if (len < 0)
|
||||
/* we must have dropped some characters (crc should detect
|
||||
* this but the old slip framing won't) */
|
||||
goto bad;
|
||||
/*
|
||||
* we must have dropped some characters (crc should detect this but the
|
||||
* old slip framing won't)
|
||||
*/
|
||||
goto bad;
|
||||
|
||||
#ifdef notdef
|
||||
if ((int)cp & 3) {
|
||||
if (len > 0)
|
||||
(void) ovbcopy(cp, (caddr_t)((int)cp &~ 3), len);
|
||||
cp = (u_char *)((int)cp &~ 3);
|
||||
}
|
||||
if ((int) cp & 3) {
|
||||
if (len > 0)
|
||||
(void) ovbcopy(cp, (caddr_t) ((int) cp & ~3), len);
|
||||
cp = (u_char *) ((int) cp & ~3);
|
||||
}
|
||||
#endif
|
||||
|
||||
cp -= cs->cs_hlen;
|
||||
len += cs->cs_hlen;
|
||||
cs->cs_ip.ip_len = htons(len);
|
||||
BCOPY(&cs->cs_ip, cp, cs->cs_hlen);
|
||||
*bufp = cp;
|
||||
cp -= cs->cs_hlen;
|
||||
len += cs->cs_hlen;
|
||||
cs->cs_ip.ip_len = htons(len);
|
||||
BCOPY(&cs->cs_ip, cp, cs->cs_hlen);
|
||||
*bufp = cp;
|
||||
|
||||
/* recompute the ip header checksum */
|
||||
{
|
||||
register u_short *bp = (u_short *)cp;
|
||||
for (changes = 0; hlen > 0; hlen -= 2)
|
||||
changes += *bp++;
|
||||
changes = (changes & 0xffff) + (changes >> 16);
|
||||
changes = (changes & 0xffff) + (changes >> 16);
|
||||
((struct ip *)cp)->ip_sum = ~ changes;
|
||||
}
|
||||
return (len);
|
||||
/* recompute the ip header checksum */
|
||||
{
|
||||
register u_short *bp = (u_short *) cp;
|
||||
|
||||
for (changes = 0; hlen > 0; hlen -= 2)
|
||||
changes += *bp++;
|
||||
changes = (changes & 0xffff) + (changes >> 16);
|
||||
changes = (changes & 0xffff) + (changes >> 16);
|
||||
((struct ip *) cp)->ip_sum = ~changes;
|
||||
}
|
||||
return (len);
|
||||
bad:
|
||||
comp->flags |= SLF_TOSS;
|
||||
INCR(sls_errorin)
|
||||
return (0);
|
||||
comp->flags |= SLF_TOSS;
|
||||
INCR(sls_errorin)
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
@ -569,12 +572,12 @@ ReportCompress()
|
||||
return 1;
|
||||
|
||||
fprintf(VarTerm, "Out: %d (compress) / %d (total)",
|
||||
slstat.sls_compressed, slstat.sls_packets);
|
||||
slstat.sls_compressed, slstat.sls_packets);
|
||||
fprintf(VarTerm, " %d (miss) / %d (search)\n",
|
||||
slstat.sls_misses, slstat.sls_searches);
|
||||
slstat.sls_misses, slstat.sls_searches);
|
||||
fprintf(VarTerm, "In: %d (compress), %d (uncompress)",
|
||||
slstat.sls_compressedin, slstat.sls_uncompressedin);
|
||||
slstat.sls_compressedin, slstat.sls_uncompressedin);
|
||||
fprintf(VarTerm, " %d (error), %d (tossed)\n",
|
||||
slstat.sls_errorin, slstat.sls_tossed);
|
||||
slstat.sls_errorin, slstat.sls_tossed);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Definitions for tcp compression routines.
|
||||
*
|
||||
* $Header: /home/ncvs/src/usr.sbin/ppp/slcompress.h,v 1.5 1997/02/22 16:10:55 peter Exp $
|
||||
* $Header: /home/ncvs/src/usr.sbin/ppp/slcompress.h,v 1.6 1997/06/09 03:27:38 brian Exp $
|
||||
*
|
||||
* Copyright (c) 1989 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
@ -18,7 +18,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: slcompress.h,v 1.5 1997/02/22 16:10:55 peter Exp $
|
||||
* $Id: slcompress.h,v 1.6 1997/06/09 03:27:38 brian Exp $
|
||||
*
|
||||
* Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
|
||||
* - Initial distribution.
|
||||
@ -77,7 +77,7 @@
|
||||
#define TYPE_ERROR 0x00
|
||||
|
||||
/* Bits in first octet of compressed packet */
|
||||
#define NEW_C 0x40 /* flag bits for what changed in a packet */
|
||||
#define NEW_C 0x40 /* flag bits for what changed in a packet */
|
||||
#define NEW_I 0x20
|
||||
#define NEW_S 0x08
|
||||
#define NEW_A 0x04
|
||||
@ -85,7 +85,7 @@
|
||||
#define NEW_U 0x01
|
||||
|
||||
/* reserved, special-case values of above */
|
||||
#define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */
|
||||
#define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */
|
||||
#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */
|
||||
#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
|
||||
|
||||
@ -98,15 +98,16 @@
|
||||
* the transmit & receive ends of the line use to locate saved header.
|
||||
*/
|
||||
struct cstate {
|
||||
struct cstate *cs_next; /* next most recently used cstate (xmit only) */
|
||||
u_short cs_hlen; /* size of hdr (receive only) */
|
||||
u_char cs_id; /* connection # associated with this state */
|
||||
u_char cs_filler;
|
||||
union {
|
||||
char csu_hdr[MAX_HDR];
|
||||
struct ip csu_ip; /* ip/tcp hdr from most recent packet */
|
||||
} slcs_u;
|
||||
struct cstate *cs_next; /* next most recently used cstate (xmit only) */
|
||||
u_short cs_hlen; /* size of hdr (receive only) */
|
||||
u_char cs_id; /* connection # associated with this state */
|
||||
u_char cs_filler;
|
||||
union {
|
||||
char csu_hdr[MAX_HDR];
|
||||
struct ip csu_ip; /* ip/tcp hdr from most recent packet */
|
||||
} slcs_u;
|
||||
};
|
||||
|
||||
#define cs_ip slcs_u.csu_ip
|
||||
#define cs_hdr slcs_u.csu_hdr
|
||||
|
||||
@ -115,12 +116,12 @@ struct cstate {
|
||||
* per line).
|
||||
*/
|
||||
struct slcompress {
|
||||
struct cstate *last_cs; /* most recently used tstate */
|
||||
u_char last_recv; /* last rcvd conn. id */
|
||||
u_char last_xmit; /* last sent conn. id */
|
||||
u_short flags;
|
||||
struct cstate tstate[MAX_STATES]; /* xmit connection states */
|
||||
struct cstate rstate[MAX_STATES]; /* receive connection states */
|
||||
struct cstate *last_cs; /* most recently used tstate */
|
||||
u_char last_recv; /* last rcvd conn. id */
|
||||
u_char last_xmit; /* last sent conn. id */
|
||||
u_short flags;
|
||||
struct cstate tstate[MAX_STATES]; /* xmit connection states */
|
||||
struct cstate rstate[MAX_STATES]; /* receive connection states */
|
||||
};
|
||||
|
||||
struct slstat {
|
||||
@ -128,8 +129,8 @@ struct slstat {
|
||||
int sls_compressed; /* outbound compressed packets */
|
||||
int sls_searches; /* searches for connection state */
|
||||
int sls_misses; /* times couldn't find conn. state */
|
||||
int sls_uncompressedin; /* inbound uncompressed packets */
|
||||
int sls_compressedin; /* inbound compressed packets */
|
||||
int sls_uncompressedin; /* inbound uncompressed packets */
|
||||
int sls_compressedin; /* inbound compressed packets */
|
||||
int sls_errorin; /* inbound unknown type packets */
|
||||
int sls_tossed; /* inbound packets tossed because of error */
|
||||
};
|
||||
@ -138,6 +139,7 @@ struct slstat {
|
||||
#define SLF_TOSS 1 /* tossing rcvd frames because of input err */
|
||||
|
||||
extern void sl_compress_init(struct slcompress *);
|
||||
extern u_char sl_compress_tcp __P((struct mbuf *, struct ip *,
|
||||
struct slcompress *, int compress_cid_flag));
|
||||
extern int sl_uncompress_tcp(u_char **, int, u_int, struct slcompress *);
|
||||
extern u_char sl_compress_tcp
|
||||
__P((struct mbuf *, struct ip *,
|
||||
struct slcompress *, int compress_cid_flag));
|
||||
extern int sl_uncompress_tcp(u_char **, int, u_int, struct slcompress *);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: systems.c,v 1.12 1997/06/09 03:27:38 brian Exp $
|
||||
* $Id: systems.c,v 1.13 1997/06/25 19:30:05 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -28,6 +28,7 @@
|
||||
#include "pathnames.h"
|
||||
#include "vars.h"
|
||||
#include "server.h"
|
||||
#include "command.h"
|
||||
|
||||
extern void DecodeCommand();
|
||||
|
||||
@ -38,7 +39,7 @@ static int usermode;
|
||||
int
|
||||
OrigUid()
|
||||
{
|
||||
return uid;
|
||||
return uid;
|
||||
}
|
||||
|
||||
void
|
||||
@ -88,8 +89,7 @@ SetPppId()
|
||||
}
|
||||
|
||||
FILE *
|
||||
OpenSecret(file)
|
||||
char *file;
|
||||
OpenSecret(char *file)
|
||||
{
|
||||
FILE *fp;
|
||||
char *cp;
|
||||
@ -110,28 +110,25 @@ char *file;
|
||||
if (fp == NULL) {
|
||||
LogPrintf(LogWARN, "OpenSecret: Can't open %s.\n", line);
|
||||
SetPppId();
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
return(fp);
|
||||
return (fp);
|
||||
}
|
||||
|
||||
void
|
||||
CloseSecret(fp)
|
||||
FILE *fp;
|
||||
CloseSecret(FILE * fp)
|
||||
{
|
||||
fclose(fp);
|
||||
SetPppId();
|
||||
}
|
||||
|
||||
int
|
||||
SelectSystem(name, file)
|
||||
char *name;
|
||||
char *file;
|
||||
SelectSystem(char *name, char *file)
|
||||
{
|
||||
FILE *fp;
|
||||
char *cp, *wp;
|
||||
int n;
|
||||
u_char olauth;
|
||||
u_char olauth;
|
||||
char line[200];
|
||||
char filename[200];
|
||||
int linenum;
|
||||
@ -144,14 +141,14 @@ char *file;
|
||||
fp = fopen(filename, "r");
|
||||
}
|
||||
if (fp == NULL) {
|
||||
SetPppId(); /* fix from pdp@ark.jr3uom.iijnet.or.jp */
|
||||
SetPppId(); /* fix from pdp@ark.jr3uom.iijnet.or.jp */
|
||||
snprintf(filename, sizeof filename, "%s/%s", _PATH_PPP, file);
|
||||
fp = fopen(filename, "r");
|
||||
}
|
||||
if (fp == NULL) {
|
||||
LogPrintf(LogDEBUG, "SelectSystem: Can't open %s.\n", filename);
|
||||
SetPppId();
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
LogPrintf(LogDEBUG, "SelectSystem: Checking %s (%s).\n", name, filename);
|
||||
|
||||
@ -160,7 +157,7 @@ char *file;
|
||||
linenum++;
|
||||
cp = line;
|
||||
switch (*cp) {
|
||||
case '#': /* comment */
|
||||
case '#': /* comment */
|
||||
break;
|
||||
case ' ':
|
||||
case '\t':
|
||||
@ -169,8 +166,8 @@ char *file;
|
||||
wp = strpbrk(cp, ":\n");
|
||||
if (wp == NULL) {
|
||||
LogPrintf(LogWARN, "Bad rule in %s (line %d) - missing colon.\n",
|
||||
filename, linenum);
|
||||
ServerClose();
|
||||
filename, linenum);
|
||||
ServerClose();
|
||||
exit(1);
|
||||
}
|
||||
*wp = '\0';
|
||||
@ -182,10 +179,10 @@ char *file;
|
||||
cp += n;
|
||||
LogPrintf(LogCOMMAND, "%s: %s", name, cp);
|
||||
SetPppId();
|
||||
olauth = VarLocalAuth;
|
||||
olauth = VarLocalAuth;
|
||||
VarLocalAuth = LOCAL_AUTH;
|
||||
DecodeCommand(cp, strlen(cp), 0);
|
||||
VarLocalAuth = olauth;
|
||||
VarLocalAuth = olauth;
|
||||
SetUserId();
|
||||
} else if (*cp == '#') {
|
||||
continue;
|
||||
@ -194,7 +191,7 @@ char *file;
|
||||
}
|
||||
fclose(fp);
|
||||
SetPppId();
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -205,10 +202,7 @@ char *file;
|
||||
}
|
||||
|
||||
int
|
||||
LoadCommand(list, argc, argv)
|
||||
struct cmdtab *list;
|
||||
int argc;
|
||||
char **argv;
|
||||
LoadCommand(struct cmdtab const * list, int argc, char **argv)
|
||||
{
|
||||
char *name;
|
||||
|
||||
@ -221,15 +215,11 @@ char **argv;
|
||||
LogPrintf(LogWARN, "%s: not found.\n", name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SaveCommand(list, argc, argv)
|
||||
struct cmdtab *list;
|
||||
int argc;
|
||||
char **argv;
|
||||
SaveCommand(struct cmdtab const * list, int argc, char **argv)
|
||||
{
|
||||
LogPrintf(LogWARN, "save command is not implemented (yet).\n");
|
||||
return 1;
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: systems.h,v 1.4 1997/05/26 00:44:09 brian Exp $
|
||||
* $Id: systems.h,v 1.5 1997/06/09 03:27:38 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -25,5 +25,6 @@
|
||||
#define _SYSTEMS_H_
|
||||
extern int OrigUid(void);
|
||||
extern void GetUid(void);
|
||||
extern int SelectSystem(char *, char*);
|
||||
extern int SelectSystem(char *, char *);
|
||||
|
||||
#endif
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: timeout.h,v 1.9 1997/02/22 16:10:58 peter Exp $
|
||||
* $Id: timeout.h,v 1.10 1997/06/09 03:27:39 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -23,15 +23,15 @@
|
||||
#ifndef _TIMEOUT_H_
|
||||
#define _TIMEOUT_H_
|
||||
|
||||
#define TICKUNIT 100000 /* Unit in usec */
|
||||
#define TICKUNIT 100000 /* Unit in usec */
|
||||
#define SECTICKS (1000000/TICKUNIT)
|
||||
|
||||
struct pppTimer {
|
||||
int state;
|
||||
u_long rest; /* Ticks to expire */
|
||||
u_long load; /* Initial load value */
|
||||
void (*func)(); /* Function called when timer is expired */
|
||||
void *arg; /* Argument passed to timeout function */
|
||||
int state;
|
||||
u_long rest; /* Ticks to expire */
|
||||
u_long load; /* Initial load value */
|
||||
void (*func) (); /* Function called when timer is expired */
|
||||
void *arg; /* Argument passed to timeout function */
|
||||
struct pppTimer *next; /* Link to next timer */
|
||||
struct pppTimer *enext; /* Link to next expired timer */
|
||||
};
|
||||
@ -50,4 +50,5 @@ extern void TermTimerService(void);
|
||||
extern void StartIdleTimer(void);
|
||||
extern void UpdateIdleTimer(void);
|
||||
extern void ShowTimers();
|
||||
#endif /* _TIMEOUT_H_ */
|
||||
|
||||
#endif /* _TIMEOUT_H_ */
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: timer.c,v 1.16 1997/05/10 01:22:19 brian Exp $
|
||||
* $Id: timer.c,v 1.17 1997/06/09 03:27:40 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -30,13 +30,14 @@
|
||||
#endif
|
||||
#include "sig.h"
|
||||
|
||||
void StopTimerNoBlock( struct pppTimer *);
|
||||
void StopTimerNoBlock(struct pppTimer *);
|
||||
|
||||
void
|
||||
StopTimer( struct pppTimer *tp )
|
||||
StopTimer(struct pppTimer * tp)
|
||||
{
|
||||
#ifdef SIGALRM
|
||||
int omask;
|
||||
int omask;
|
||||
|
||||
omask = sigblock(sigmask(SIGALRM));
|
||||
#endif
|
||||
StopTimerNoBlock(tp);
|
||||
@ -46,14 +47,14 @@ StopTimer( struct pppTimer *tp )
|
||||
}
|
||||
|
||||
void
|
||||
StartTimer(tp)
|
||||
struct pppTimer *tp;
|
||||
StartTimer(struct pppTimer * tp)
|
||||
{
|
||||
struct pppTimer *t, *pt;
|
||||
u_long ticks = 0;
|
||||
|
||||
#ifdef SIGALRM
|
||||
int omask;
|
||||
int omask;
|
||||
|
||||
omask = sigblock(sigmask(SIGALRM));
|
||||
#endif
|
||||
|
||||
@ -68,7 +69,7 @@ struct pppTimer *tp;
|
||||
pt = NULL;
|
||||
for (t = TimerList; t; t = t->next) {
|
||||
LogPrintf(LogDEBUG, "StartTimer: %x(%d): ticks: %d, rest: %d\n",
|
||||
t, t->state, ticks, t->rest);
|
||||
t, t->state, ticks, t->rest);
|
||||
if (ticks + t->rest >= tp->load)
|
||||
break;
|
||||
ticks += t->rest;
|
||||
@ -78,7 +79,7 @@ struct pppTimer *tp;
|
||||
tp->state = TIMER_RUNNING;
|
||||
tp->rest = tp->load - ticks;
|
||||
LogPrintf(LogDEBUG, "StartTimer: Inserting %x before %x, rest = %d\n",
|
||||
tp, t, tp->rest);
|
||||
tp, t, tp->rest);
|
||||
/* Insert given *tp just before *t */
|
||||
tp->next = t;
|
||||
if (pt) {
|
||||
@ -96,35 +97,32 @@ struct pppTimer *tp;
|
||||
}
|
||||
|
||||
void
|
||||
StopTimerNoBlock(tp)
|
||||
struct pppTimer *tp;
|
||||
StopTimerNoBlock(struct pppTimer * tp)
|
||||
{
|
||||
struct pppTimer *t, *pt;
|
||||
|
||||
/*
|
||||
* A Running Timer should be removing TimerList,
|
||||
* But STOPPED/EXPIRED is already removing TimerList.
|
||||
* So just marked as TIMER_STOPPED.
|
||||
* Do not change tp->enext!! (Might be Called by expired proc)
|
||||
* A Running Timer should be removing TimerList, But STOPPED/EXPIRED is
|
||||
* already removing TimerList. So just marked as TIMER_STOPPED. Do not
|
||||
* change tp->enext!! (Might be Called by expired proc)
|
||||
*/
|
||||
LogPrintf(LogDEBUG, "StopTimer: %x, next = %x state=%x\n",
|
||||
tp, tp->next, tp->state);
|
||||
tp, tp->next, tp->state);
|
||||
if (tp->state != TIMER_RUNNING) {
|
||||
tp->next = NULL;
|
||||
tp->state = TIMER_STOPPED;
|
||||
tp->next = NULL;
|
||||
tp->state = TIMER_STOPPED;
|
||||
return;
|
||||
}
|
||||
|
||||
pt = NULL;
|
||||
for (t = TimerList; t != tp && t !=NULL ; t = t->next)
|
||||
for (t = TimerList; t != tp && t != NULL; t = t->next)
|
||||
pt = t;
|
||||
if (t) {
|
||||
if (pt) {
|
||||
pt->next = t->next;
|
||||
} else {
|
||||
TimerList = t->next;
|
||||
if ( TimerList == NULL ) /* Last one ? */
|
||||
TermTimerService(); /* Terminate Timer Service */
|
||||
if (TimerList == NULL) /* Last one ? */
|
||||
TermTimerService(); /* Terminate Timer Service */
|
||||
}
|
||||
if (t->next)
|
||||
t->next->rest += tp->rest;
|
||||
@ -146,6 +144,7 @@ TimerService()
|
||||
if (tp) {
|
||||
tp->rest--;
|
||||
if (tp->rest == 0) {
|
||||
|
||||
/*
|
||||
* Multiple timers may expires at once. Create list of expired timers.
|
||||
*/
|
||||
@ -160,10 +159,11 @@ TimerService()
|
||||
} while (tp && (tp->rest == 0));
|
||||
|
||||
TimerList = tp;
|
||||
if ( TimerList == NULL ) /* No timers ? */
|
||||
TermTimerService(); /* Terminate Timer Service */
|
||||
if (TimerList == NULL) /* No timers ? */
|
||||
TermTimerService(); /* Terminate Timer Service */
|
||||
LogPrintf(LogDEBUG, "TimerService: next is %x(%d)\n",
|
||||
TimerList, TimerList? TimerList->rest : 0);
|
||||
TimerList, TimerList ? TimerList->rest : 0);
|
||||
|
||||
/*
|
||||
* Process all expired timers.
|
||||
*/
|
||||
@ -172,13 +172,13 @@ TimerService()
|
||||
StopTimer(exp);
|
||||
#endif
|
||||
if (exp->func)
|
||||
(*exp->func)(exp->arg);
|
||||
(*exp->func) (exp->arg);
|
||||
|
||||
/*
|
||||
* Just Removing each item from expired list
|
||||
* And exp->enext will be intialized at next expire
|
||||
* in this funtion.
|
||||
*/
|
||||
exp = exp->enext;
|
||||
* Just Removing each item from expired list And exp->enext will be
|
||||
* intialized at next expire in this funtion.
|
||||
*/
|
||||
exp = exp->enext;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -192,83 +192,88 @@ ShowTimers()
|
||||
LogPrintf(LogDEBUG, "---- Begin of Timer Service List---\n");
|
||||
for (pt = TimerList; pt; pt = pt->next)
|
||||
LogPrintf(LogDEBUG, "%x: load = %d, rest = %d, state =%x\n",
|
||||
pt, pt->load, pt->rest, pt->state);
|
||||
pt, pt->load, pt->rest, pt->state);
|
||||
LogPrintf(LogDEBUG, "---- End of Timer Service List ---\n");
|
||||
}
|
||||
|
||||
#ifdef SIGALRM
|
||||
u_int
|
||||
sleep( u_int sec )
|
||||
sleep(u_int sec)
|
||||
{
|
||||
struct timeval to,st,et;
|
||||
struct timeval to, st, et;
|
||||
long sld, nwd, std;
|
||||
|
||||
gettimeofday( &st, NULL );
|
||||
to.tv_sec = sec;
|
||||
gettimeofday(&st, NULL);
|
||||
to.tv_sec = sec;
|
||||
to.tv_usec = 0;
|
||||
std = st.tv_sec * 1000000 + st.tv_usec;
|
||||
for (;;) {
|
||||
if ( select ( 0, NULL, NULL, NULL, &to) == 0 ||
|
||||
errno != EINTR ) {
|
||||
break;
|
||||
} else {
|
||||
gettimeofday( &et, NULL );
|
||||
sld = to.tv_sec * 1000000 + to.tv_sec;
|
||||
nwd = et.tv_sec * 1000000 + et.tv_usec - std;
|
||||
if ( sld > nwd )
|
||||
sld -= nwd;
|
||||
else
|
||||
sld = 1; /* Avoid both tv_sec/usec is 0 */
|
||||
if (select(0, NULL, NULL, NULL, &to) == 0 ||
|
||||
errno != EINTR) {
|
||||
break;
|
||||
} else {
|
||||
gettimeofday(&et, NULL);
|
||||
sld = to.tv_sec * 1000000 + to.tv_sec;
|
||||
nwd = et.tv_sec * 1000000 + et.tv_usec - std;
|
||||
if (sld > nwd)
|
||||
sld -= nwd;
|
||||
else
|
||||
sld = 1; /* Avoid both tv_sec/usec is 0 */
|
||||
|
||||
/* Calculate timeout value for select */
|
||||
to.tv_sec = sld / 1000000;
|
||||
to.tv_usec = sld % 1000000;
|
||||
/* Calculate timeout value for select */
|
||||
to.tv_sec = sld / 1000000;
|
||||
to.tv_usec = sld % 1000000;
|
||||
}
|
||||
}
|
||||
return (0L);
|
||||
}
|
||||
|
||||
void usleep( u_int usec)
|
||||
void
|
||||
usleep(u_int usec)
|
||||
{
|
||||
struct timeval to,st,et;
|
||||
struct timeval to, st, et;
|
||||
long sld, nwd, std;
|
||||
|
||||
gettimeofday( &st, NULL );
|
||||
to.tv_sec = 0;
|
||||
gettimeofday(&st, NULL);
|
||||
to.tv_sec = 0;
|
||||
to.tv_usec = usec;
|
||||
std = st.tv_sec * 1000000 + st.tv_usec;
|
||||
for (;;) {
|
||||
if ( select ( 0, NULL, NULL, NULL, &to) == 0 ||
|
||||
errno != EINTR ) {
|
||||
break;
|
||||
} else {
|
||||
gettimeofday( &et, NULL );
|
||||
sld = to.tv_sec * 1000000 + to.tv_sec;
|
||||
nwd = et.tv_sec * 1000000 + et.tv_usec - std;
|
||||
if ( sld > nwd )
|
||||
sld -= nwd;
|
||||
else
|
||||
sld = 1; /* Avoid both tv_sec/usec is 0 */
|
||||
if (select(0, NULL, NULL, NULL, &to) == 0 ||
|
||||
errno != EINTR) {
|
||||
break;
|
||||
} else {
|
||||
gettimeofday(&et, NULL);
|
||||
sld = to.tv_sec * 1000000 + to.tv_sec;
|
||||
nwd = et.tv_sec * 1000000 + et.tv_usec - std;
|
||||
if (sld > nwd)
|
||||
sld -= nwd;
|
||||
else
|
||||
sld = 1; /* Avoid both tv_sec/usec is 0 */
|
||||
|
||||
/* Calculate timeout value for select */
|
||||
to.tv_sec = sld / 1000000;
|
||||
to.tv_usec = sld % 1000000;
|
||||
/* Calculate timeout value for select */
|
||||
to.tv_sec = sld / 1000000;
|
||||
to.tv_usec = sld % 1000000;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InitTimerService( void ) {
|
||||
void
|
||||
InitTimerService(void)
|
||||
{
|
||||
struct itimerval itimer;
|
||||
|
||||
pending_signal(SIGALRM, (void (*)(int))TimerService);
|
||||
pending_signal(SIGALRM, (void (*) (int)) TimerService);
|
||||
itimer.it_interval.tv_sec = itimer.it_value.tv_sec = 0;
|
||||
itimer.it_interval.tv_usec = itimer.it_value.tv_usec = TICKUNIT;
|
||||
if (setitimer(ITIMER_REAL, &itimer, NULL) == -1)
|
||||
LogPrintf(LogERROR, "Unable to set itimer.\n");
|
||||
}
|
||||
|
||||
void TermTimerService( void ) {
|
||||
void
|
||||
TermTimerService(void)
|
||||
{
|
||||
struct itimerval itimer;
|
||||
|
||||
itimer.it_interval.tv_usec = itimer.it_interval.tv_sec = 0;
|
||||
@ -277,4 +282,5 @@ void TermTimerService( void ) {
|
||||
LogPrintf(LogERROR, "Unable to set itimer.\n");
|
||||
pending_signal(SIGALRM, SIG_IGN);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: vars.c,v 1.23 1997/08/21 16:21:38 brian Exp $
|
||||
* $Id: vars.c,v 1.24 1997/08/21 17:20:00 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include "fsm.h"
|
||||
@ -29,31 +29,31 @@
|
||||
#include "auth.h"
|
||||
#include "defs.h"
|
||||
|
||||
char VarVersion[] = "PPP Version 1.02";
|
||||
char VarLocalVersion[] = "$Date: 1997/08/21 16:21:38 $";
|
||||
char VarVersion[] = "PPP Version 1.1";
|
||||
char VarLocalVersion[] = "$Date: 1997/08/21 17:20:00 $";
|
||||
|
||||
/*
|
||||
* Order of conf option is important. See vars.h.
|
||||
*/
|
||||
struct confdesc pppConfs[] = {
|
||||
{ "vjcomp", CONF_ENABLE, CONF_ACCEPT },
|
||||
{ "lqr", CONF_ENABLE, CONF_ACCEPT },
|
||||
{ "chap", CONF_DISABLE, CONF_ACCEPT },
|
||||
{ "pap", CONF_DISABLE, CONF_ACCEPT },
|
||||
{ "acfcomp", CONF_ENABLE, CONF_ACCEPT },
|
||||
{ "protocomp", CONF_ENABLE, CONF_ACCEPT },
|
||||
{ "pred1", CONF_ENABLE, CONF_ACCEPT },
|
||||
{ "proxy", CONF_DISABLE, CONF_DENY },
|
||||
{ "msext", CONF_DISABLE, CONF_ACCEPT },
|
||||
{ "passwdauth",CONF_DISABLE, CONF_DENY },
|
||||
{ NULL },
|
||||
{"vjcomp", CONF_ENABLE, CONF_ACCEPT},
|
||||
{"lqr", CONF_ENABLE, CONF_ACCEPT},
|
||||
{"chap", CONF_DISABLE, CONF_ACCEPT},
|
||||
{"pap", CONF_DISABLE, CONF_ACCEPT},
|
||||
{"acfcomp", CONF_ENABLE, CONF_ACCEPT},
|
||||
{"protocomp", CONF_ENABLE, CONF_ACCEPT},
|
||||
{"pred1", CONF_ENABLE, CONF_ACCEPT},
|
||||
{"proxy", CONF_DISABLE, CONF_DENY},
|
||||
{"msext", CONF_DISABLE, CONF_ACCEPT},
|
||||
{"passwdauth", CONF_DISABLE, CONF_DENY},
|
||||
{NULL},
|
||||
};
|
||||
|
||||
struct pppvars pppVars = {
|
||||
DEF_MRU, DEF_MTU, 0, MODEM_SPEED, CS8, MODEM_CTSRTS, 180, 30, 3,
|
||||
RECONNECT_TIMER, RECONNECT_TRIES, REDIAL_PERIOD,
|
||||
NEXT_REDIAL_PERIOD, 1, 1, MODEM_DEV, BASE_MODEM_DEV,
|
||||
OPEN_ACTIVE, LOCAL_NO_AUTH,0
|
||||
OPEN_ACTIVE, LOCAL_NO_AUTH, 0
|
||||
};
|
||||
|
||||
int
|
||||
@ -69,14 +69,14 @@ DisplayCommand()
|
||||
fprintf(VarTerm, "----------------------------------------\n");
|
||||
for (vp = pppConfs; vp->name; vp++)
|
||||
fprintf(VarTerm, "%-10s\t%s\t\t%s\n", vp->name,
|
||||
(vp->myside == CONF_ENABLE)? "enable" : "disable",
|
||||
(vp->hisside == CONF_ACCEPT)? "accept" : "deny");
|
||||
(vp->myside == CONF_ENABLE) ? "enable" : "disable",
|
||||
(vp->hisside == CONF_ACCEPT) ? "accept" : "deny");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
ConfigCommand(struct cmdtab *list, int argc, char **argv, int mine, int val)
|
||||
ConfigCommand(struct cmdtab * list, int argc, char **argv, int mine, int val)
|
||||
{
|
||||
struct confdesc *vp;
|
||||
int err;
|
||||
@ -88,15 +88,14 @@ ConfigCommand(struct cmdtab *list, int argc, char **argv, int mine, int val)
|
||||
do {
|
||||
for (vp = pppConfs; vp->name; vp++)
|
||||
if (strcasecmp(vp->name, *argv) == 0) {
|
||||
if (mine)
|
||||
if (mine)
|
||||
vp->myside = val;
|
||||
else
|
||||
else
|
||||
vp->hisside = val;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!vp->name) {
|
||||
LogPrintf(LogWARN, "Config: %s: No such key word\n", *argv );
|
||||
LogPrintf(LogWARN, "Config: %s: No such key word\n", *argv);
|
||||
err++;
|
||||
}
|
||||
argc--;
|
||||
@ -107,53 +106,50 @@ ConfigCommand(struct cmdtab *list, int argc, char **argv, int mine, int val)
|
||||
}
|
||||
|
||||
int
|
||||
EnableCommand(struct cmdtab *list, int argc, char **argv)
|
||||
EnableCommand(struct cmdtab * list, int argc, char **argv)
|
||||
{
|
||||
return ConfigCommand(list, argc, argv, 1, CONF_ENABLE);
|
||||
}
|
||||
|
||||
int
|
||||
DisableCommand(struct cmdtab *list, int argc, char **argv)
|
||||
DisableCommand(struct cmdtab * list, int argc, char **argv)
|
||||
{
|
||||
return ConfigCommand(list, argc, argv, 1, CONF_DISABLE);
|
||||
}
|
||||
|
||||
int
|
||||
AcceptCommand(struct cmdtab *list, int argc, char **argv)
|
||||
AcceptCommand(struct cmdtab * list, int argc, char **argv)
|
||||
{
|
||||
return ConfigCommand(list, argc, argv, 0, CONF_ACCEPT);
|
||||
}
|
||||
|
||||
int
|
||||
DenyCommand(struct cmdtab *list, int argc, char **argv)
|
||||
DenyCommand(struct cmdtab * list, int argc, char **argv)
|
||||
{
|
||||
return ConfigCommand(list, argc, argv, 0, CONF_DENY);
|
||||
}
|
||||
|
||||
int
|
||||
LocalAuthCommand(list, argc, argv)
|
||||
struct cmdtab *list;
|
||||
int argc;
|
||||
char **argv;
|
||||
LocalAuthCommand(struct cmdtab * list, int argc, char **argv)
|
||||
{
|
||||
if (argc != 1)
|
||||
return -1;
|
||||
|
||||
switch ( LocalAuthValidate( SECRETFILE, VarShortHost, *argv ) ) {
|
||||
case INVALID:
|
||||
pppVars.lauth = LOCAL_NO_AUTH;
|
||||
break;
|
||||
case VALID:
|
||||
pppVars.lauth = LOCAL_AUTH;
|
||||
break;
|
||||
case NOT_FOUND:
|
||||
pppVars.lauth = LOCAL_AUTH;
|
||||
LogPrintf(LogWARN, "WARING: No Entry for this system\n");
|
||||
break;
|
||||
default:
|
||||
pppVars.lauth = LOCAL_NO_AUTH;
|
||||
LogPrintf(LogERROR, "LocalAuthCommand: Ooops?\n");
|
||||
return 1;
|
||||
switch (LocalAuthValidate(SECRETFILE, VarShortHost, *argv)) {
|
||||
case INVALID:
|
||||
pppVars.lauth = LOCAL_NO_AUTH;
|
||||
break;
|
||||
case VALID:
|
||||
pppVars.lauth = LOCAL_AUTH;
|
||||
break;
|
||||
case NOT_FOUND:
|
||||
pppVars.lauth = LOCAL_AUTH;
|
||||
LogPrintf(LogWARN, "WARING: No Entry for this system\n");
|
||||
break;
|
||||
default:
|
||||
pppVars.lauth = LOCAL_NO_AUTH;
|
||||
LogPrintf(LogERROR, "LocalAuthCommand: Ooops?\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: vars.h,v 1.23 1997/08/20 23:47:53 brian Exp $
|
||||
* $Id: vars.h,v 1.24 1997/08/21 16:21:39 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -27,7 +27,7 @@
|
||||
|
||||
struct confdesc {
|
||||
char *name;
|
||||
int myside, hisside;
|
||||
int myside, hisside;
|
||||
};
|
||||
|
||||
#define CONF_DISABLE 0
|
||||
@ -51,44 +51,44 @@ struct confdesc {
|
||||
#define Enabled(x) (pppConfs[x].myside & CONF_ENABLE)
|
||||
#define Acceptable(x) (pppConfs[x].hisside & CONF_ACCEPT)
|
||||
|
||||
extern struct confdesc pppConfs[MAXCONFS+1];
|
||||
extern struct confdesc pppConfs[MAXCONFS + 1];
|
||||
|
||||
struct pppvars {
|
||||
u_long var_mru; /* Initial MRU value */
|
||||
u_long pref_mtu; /* Preferred MTU value */
|
||||
int var_accmap; /* Initial ACCMAP value */
|
||||
int modem_speed; /* Current modem speed */
|
||||
int modem_parity; /* Parity setting */
|
||||
int modem_ctsrts; /* Use CTS/RTS on modem port? (boolean) */
|
||||
int idle_timeout; /* Idle timeout value */
|
||||
int lqr_timeout; /* LQR timeout value */
|
||||
int retry_timeout; /* Retry timeout value */
|
||||
int reconnect_timer; /* Timeout before reconnect on carrier loss */
|
||||
int reconnect_tries; /* Attempt reconnect on carrier loss */
|
||||
int redial_timeout; /* Redial timeout value */
|
||||
int redial_next_timeout; /* Redial next timeout value */
|
||||
int dial_tries; /* Dial attempts before giving up, 0 == inf */
|
||||
int loopback; /* Turn around packets addressed to me */
|
||||
char modem_dev[40]; /* Name of device / host:port */
|
||||
char *base_modem_dev; /* Pointer to base of modem_dev */
|
||||
int open_mode; /* LCP open mode */
|
||||
int var_accmap; /* Initial ACCMAP value */
|
||||
int modem_speed; /* Current modem speed */
|
||||
int modem_parity; /* Parity setting */
|
||||
int modem_ctsrts; /* Use CTS/RTS on modem port? (boolean) */
|
||||
int idle_timeout; /* Idle timeout value */
|
||||
int lqr_timeout; /* LQR timeout value */
|
||||
int retry_timeout; /* Retry timeout value */
|
||||
int reconnect_timer; /* Timeout before reconnect on carrier loss */
|
||||
int reconnect_tries; /* Attempt reconnect on carrier loss */
|
||||
int redial_timeout; /* Redial timeout value */
|
||||
int redial_next_timeout; /* Redial next timeout value */
|
||||
int dial_tries; /* Dial attempts before giving up, 0 == inf */
|
||||
int loopback; /* Turn around packets addressed to me */
|
||||
char modem_dev[40]; /* Name of device / host:port */
|
||||
char *base_modem_dev; /* Pointer to base of modem_dev */
|
||||
int open_mode; /* LCP open mode */
|
||||
#define LOCAL_AUTH 0x01
|
||||
#define LOCAL_NO_AUTH 0x02
|
||||
u_char lauth; /* Local Authorized status */
|
||||
FILE *termfp; /* The terminal */
|
||||
#define DIALUP_REQ 0x01
|
||||
#define DIALUP_DONE 0x02
|
||||
char dial_script[200]; /* Dial script */
|
||||
char login_script[200]; /* Login script */
|
||||
char auth_key[50]; /* PAP/CHAP key */
|
||||
char auth_name[50]; /* PAP/CHAP system name */
|
||||
char phone_numbers[200]; /* Telephone Numbers */
|
||||
char phone_copy[200]; /* copy for strsep() */
|
||||
char *next_phone; /* Next phone from the list */
|
||||
char *alt_phone; /* Next phone from the list */
|
||||
char shostname[MAXHOSTNAMELEN];/* Local short Host Name */
|
||||
char hangup_script[200]; /* Hangup script before modem is closed */
|
||||
struct aliasHandlers handler; /* Alias function pointers */
|
||||
char dial_script[200]; /* Dial script */
|
||||
char login_script[200]; /* Login script */
|
||||
char auth_key[50]; /* PAP/CHAP key */
|
||||
char auth_name[50]; /* PAP/CHAP system name */
|
||||
char phone_numbers[200]; /* Telephone Numbers */
|
||||
char phone_copy[200]; /* copy for strsep() */
|
||||
char *next_phone; /* Next phone from the list */
|
||||
char *alt_phone; /* Next phone from the list */
|
||||
char shostname[MAXHOSTNAMELEN]; /* Local short Host Name */
|
||||
char hangup_script[200]; /* Hangup script before modem is closed */
|
||||
struct aliasHandlers handler; /* Alias function pointers */
|
||||
};
|
||||
|
||||
#define VarAccmap pppVars.var_accmap
|
||||
@ -123,17 +123,17 @@ struct pppvars {
|
||||
#define VarTerm pppVars.termfp
|
||||
|
||||
#define VarAliasHandlers pppVars.handler
|
||||
#define VarGetNextFragmentPtr (*pppVars.handler.GetNextFragmentPtr)
|
||||
#define VarGetNextFragmentPtr (*pppVars.handler.GetNextFragmentPtr)
|
||||
#define VarInitPacketAlias (*pppVars.handler.InitPacketAlias)
|
||||
#define VarPacketAliasGetFragment (*pppVars.handler.PacketAliasGetFragment)
|
||||
#define VarPacketAliasGetFragment (*pppVars.handler.PacketAliasGetFragment)
|
||||
#define VarPacketAliasInit (*pppVars.handler.PacketAliasInit)
|
||||
#define VarPacketAliasIn (*pppVars.handler.PacketAliasIn)
|
||||
#define VarPacketAliasOut (*pppVars.handler.PacketAliasOut)
|
||||
#define VarPacketAliasRedirectAddr (*pppVars.handler.PacketAliasRedirectAddr)
|
||||
#define VarPacketAliasRedirectPort (*pppVars.handler.PacketAliasRedirectPort)
|
||||
#define VarSaveFragmentPtr (*pppVars.handler.SaveFragmentPtr)
|
||||
#define VarSetPacketAliasAddress (*pppVars.handler.SetPacketAliasAddress)
|
||||
#define VarSetPacketAliasMode (*pppVars.handler.SetPacketAliasMode)
|
||||
#define VarFragmentAliasIn (*pppVars.handler.FragmentAliasIn)
|
||||
#define VarPacketAliasSaveFragment (*pppVars.handler.PacketAliasSaveFragment)
|
||||
#define VarPacketAliasSetAddress (*pppVars.handler.PacketAliasSetAddress)
|
||||
#define VarPacketAliasSetMode (*pppVars.handler.PacketAliasSetMode)
|
||||
#define VarPacketAliasFragmentIn (*pppVars.handler.PacketAliasFragmentIn)
|
||||
|
||||
#define DEV_IS_SYNC (VarSpeed == 0)
|
||||
|
||||
@ -156,6 +156,7 @@ int ipConnectSecs, ipIdleSecs;
|
||||
while(0)
|
||||
|
||||
int reconnectState, reconnectCount;
|
||||
|
||||
/*
|
||||
* This is the logic behind the reconnect variables:
|
||||
* We have four reconnect "states". We start off not requiring anything
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: vjcomp.c,v 1.7 1997/05/07 23:30:50 brian Exp $
|
||||
* $Id: vjcomp.c,v 1.8 1997/06/09 03:27:43 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -29,7 +29,7 @@
|
||||
#include "hdlc.h"
|
||||
#include "ipcp.h"
|
||||
|
||||
#define MAX_VJHEADER 16 /* Maximum size of compressed header */
|
||||
#define MAX_VJHEADER 16 /* Maximum size of compressed header */
|
||||
|
||||
struct slcompress cslc;
|
||||
|
||||
@ -40,17 +40,16 @@ VjInit()
|
||||
}
|
||||
|
||||
void
|
||||
SendPppFrame(bp)
|
||||
struct mbuf *bp;
|
||||
SendPppFrame(struct mbuf * bp)
|
||||
{
|
||||
int type;
|
||||
int proto;
|
||||
int cproto = IpcpInfo.his_compproto >> 16;
|
||||
|
||||
LogPrintf(LogDEBUG, "SendPppFrame: proto = %x\n", IpcpInfo.his_compproto);
|
||||
if (((struct ip *)MBUF_CTOP(bp))->ip_p == IPPROTO_TCP
|
||||
&& cproto== PROTO_VJCOMP) {
|
||||
type = sl_compress_tcp(bp, (struct ip *)MBUF_CTOP(bp), &cslc, IpcpInfo.his_compproto & 0xff);
|
||||
if (((struct ip *) MBUF_CTOP(bp))->ip_p == IPPROTO_TCP
|
||||
&& cproto == PROTO_VJCOMP) {
|
||||
type = sl_compress_tcp(bp, (struct ip *) MBUF_CTOP(bp), &cslc, IpcpInfo.his_compproto & 0xff);
|
||||
|
||||
LogPrintf(LogDEBUG, "SendPppFrame: type = %x\n", type);
|
||||
switch (type) {
|
||||
@ -74,20 +73,19 @@ struct mbuf *bp;
|
||||
}
|
||||
|
||||
static struct mbuf *
|
||||
VjUncompressTcp(bp, type)
|
||||
struct mbuf *bp;
|
||||
u_char type;
|
||||
VjUncompressTcp(struct mbuf * bp, u_char type)
|
||||
{
|
||||
u_char *bufp;
|
||||
int len, olen, rlen;
|
||||
struct mbuf *nbp;
|
||||
u_char work[MAX_HDR+MAX_VJHEADER]; /* enough to hold TCP/IP header */
|
||||
u_char work[MAX_HDR + MAX_VJHEADER]; /* enough to hold TCP/IP header */
|
||||
|
||||
olen = len = plength(bp);
|
||||
if (type == TYPE_UNCOMPRESSED_TCP) {
|
||||
|
||||
/*
|
||||
* Uncompressed packet does NOT change its size, so that we can
|
||||
* use mbuf space for uncompression job.
|
||||
* Uncompressed packet does NOT change its size, so that we can use mbuf
|
||||
* space for uncompression job.
|
||||
*/
|
||||
bufp = MBUF_CTOP(bp);
|
||||
len = sl_uncompress_tcp(&bufp, len, type, &cslc);
|
||||
@ -95,16 +93,16 @@ u_char type;
|
||||
pfree(bp);
|
||||
bp = NULLBUFF;
|
||||
}
|
||||
return(bp);
|
||||
return (bp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle compressed packet.
|
||||
* 1) Read upto MAX_VJHEADER bytes into work space.
|
||||
* 2) Try to uncompress it.
|
||||
* 3) Compute amount of necesary space.
|
||||
* 4) Copy unread data info there.
|
||||
* Handle compressed packet. 1) Read upto MAX_VJHEADER bytes into work
|
||||
* space. 2) Try to uncompress it. 3) Compute amount of necesary space. 4)
|
||||
* Copy unread data info there.
|
||||
*/
|
||||
if (len > MAX_VJHEADER) len = MAX_VJHEADER;
|
||||
if (len > MAX_VJHEADER)
|
||||
len = MAX_VJHEADER;
|
||||
rlen = len;
|
||||
bufp = work + MAX_HDR;
|
||||
bp = mbread(bp, bufp, rlen);
|
||||
@ -118,13 +116,11 @@ u_char type;
|
||||
nbp = mballoc(len, MB_VJCOMP);
|
||||
bcopy(bufp, MBUF_CTOP(nbp), len);
|
||||
nbp->next = bp;
|
||||
return(nbp);
|
||||
return (nbp);
|
||||
}
|
||||
|
||||
struct mbuf *
|
||||
VjCompInput(bp, proto)
|
||||
struct mbuf *bp;
|
||||
int proto;
|
||||
VjCompInput(struct mbuf * bp, int proto)
|
||||
{
|
||||
u_char type;
|
||||
|
||||
@ -140,8 +136,8 @@ int proto;
|
||||
break;
|
||||
default:
|
||||
LogPrintf(LogERROR, "VjCompInput...???\n");
|
||||
return(bp);
|
||||
return (bp);
|
||||
}
|
||||
bp = VjUncompressTcp(bp, type);
|
||||
return(bp);
|
||||
return (bp);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user