diff options
62 files changed, 1739 insertions, 2149 deletions
diff --git a/usr.sbin/ppp/Makefile b/usr.sbin/ppp/Makefile index b11a511..05173f3 100644 --- a/usr.sbin/ppp/Makefile +++ b/usr.sbin/ppp/Makefile @@ -1,14 +1,13 @@ -# $Id: Makefile,v 1.19 1997/05/23 04:53:49 brian Exp $ +# $Id: Makefile,v 1.20 1997/05/26 00:43:54 brian Exp $ PROG= ppp SRCS= alias_cmd.c arp.c async.c auth.c ccp.c chap.c chat.c command.c \ filter.c fsm.c hdlc.c ip.c ipcp.c lcp.c loadalias.c log.c lqr.c \ main.c mbuf.c modem.c os.c pap.c passwdauth.c pred.c route.c sig.c \ slcompress.c systems.c timer.c vars.c vjcomp.c -#CFLAGS+= -DHAVE_SHELL_CMD_WITH_ANY_MODE -CFLAGS += -Wall -DMSEXT -DPASSWDAUTH -LDADD += -lmd -lcrypt -lutil -DPADD += ${LIBMD} ${LIBCRYPT} ${LIBUTIL} +CFLAGS+=-Wall +LDADD+= -lmd -lcrypt -lutil +DPADD+= ${LIBMD} ${LIBCRYPT} ${LIBUTIL} MAN8= ppp.8 BINMODE=4555 BINOWN= root diff --git a/usr.sbin/ppp/alias_cmd.c b/usr.sbin/ppp/alias_cmd.c index 0603c7a..f6aa1be 100644 --- a/usr.sbin/ppp/alias_cmd.c +++ b/usr.sbin/ppp/alias_cmd.c @@ -30,9 +30,10 @@ AliasRedirectPort (struct cmdtab *list, char **argv, void *param) { - if (!(mode & MODE_ALIAS)) - printf("alias not enabled\n"); - else if (argc == 3) { + 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; @@ -48,23 +49,30 @@ AliasRedirectPort (struct cmdtab *list, } else if (strcmp(proto, "udp") == 0) { proto_constant = IPPROTO_UDP; } else { - printf("port redirect: protocol must be tcp or udp\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); + 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) { - printf("port redirect: error reading local addr:port\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); - return 1; + 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) { - printf("port redirect: error reading alias port\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); - return 1; + 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; @@ -74,11 +82,11 @@ AliasRedirectPort (struct cmdtab *list, null_addr, alias_port, proto_constant); - if (link == NULL) - printf("port redirect: error returned by packed aliasing engine" - "(code=%d)\n", error); - } else - printf("Usage: alias %s %s\n", list->name, list->syntax); + 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; } @@ -90,9 +98,10 @@ AliasRedirectAddr(struct cmdtab *list, char **argv, void *param) { - if (!(mode & MODE_ALIAS)) - printf("alias not enabled\n"); - else if (argc == 2) { + 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; @@ -100,25 +109,27 @@ AliasRedirectAddr(struct cmdtab *list, error = StrToAddr(argv[0], &local_addr); if (error) { - printf("address redirect: invalid local address\n"); + if (VarTerm) + fprintf(VarTerm, "address redirect: invalid local address\n"); return 1; } error = StrToAddr(argv[1], &alias_addr); if (error) { - printf("address redirect: invalid alias address\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); - return 1; + 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) { - printf("address redirect: packet aliasing engine error\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); + 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 - printf("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; } @@ -136,7 +147,7 @@ StrToAddr (char* str, hp = gethostbyname (str); if (!hp) { - fprintf (stderr, "Unknown host %s.\n", str); + LogPrintf(LogWARN, "StrToAddr: Unknown host %s.\n", str); return -1; } @@ -164,8 +175,8 @@ StrToPort (char *str, sp = getservbyname (str, proto); if (!sp) { - fprintf (stderr, "Unknown port or service %s/%s.\n", - str, proto); + LogPrintf(LogWARN, "StrToAddr: Unknown port or service %s/%s.\n", + str, proto); return -1; } @@ -185,7 +196,8 @@ StrToAddrAndPort (char* str, ptr = strchr (str, ':'); if (!ptr) { - fprintf (stderr, "%s is missing port number.\n", str); + LogPrintf(LogWARN, "StrToAddrAndPort: %s is missing port number.\n", + str); return -1; } diff --git a/usr.sbin/ppp/arp.c b/usr.sbin/ppp/arp.c index d816be3..24f691c 100644 --- a/usr.sbin/ppp/arp.c +++ b/usr.sbin/ppp/arp.c @@ -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.10 1997/02/25 14:04:50 brian Exp $ + * $Id: arp.c,v 1.11 1997/04/15 00:03:35 brian Exp $ * */ @@ -55,7 +55,7 @@ static int rtm_seq; -static int get_ether_addr __P((int, u_long, struct sockaddr_dl *)); +static int get_ether_addr(int, u_long, struct sockaddr_dl *); #define BCOPY(s, d, l) memcpy(d, s, l) #define BZERO(s, n) memset(s, 0, n) @@ -96,12 +96,14 @@ sifproxyarp(unit, hisaddr) */ memset(&arpmsg, 0, sizeof(arpmsg)); if (!get_ether_addr(unit, hisaddr, &arpmsg.hwa)) { - logprintf("Cannot determine ethernet address for proxy ARP\n"); + LogPrintf(LogERROR, "Cannot determine ethernet address" + " for proxy ARP\n"); return 0; } if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) { - logprintf("sifproxyarp: opening routing socket: \n"); + LogPrintf(LogERROR, "sifproxyarp: opening routing socket: %s\n", + strerror(errno)); return 0; } @@ -119,7 +121,7 @@ sifproxyarp(unit, hisaddr) arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg + arpmsg.hwa.sdl_len; if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) { - logprintf("add proxy arp entry: \n"); + LogPrintf(LogERROR, "Add proxy arp entry: %s\n", strerror(errno)); close(routes); return 0; } @@ -147,12 +149,13 @@ cifproxyarp(unit, hisaddr) arpmsg.hdr.rtm_seq = ++rtm_seq; if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) { - logprintf("sifproxyarp: opening routing socket: \n"); + LogPrintf(LogERROR, "sifproxyarp: opening routing socket: %s\n", + strerror(errno)); return 0; } if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) { - logprintf("delete proxy arp entry: \n"); + LogPrintf(LogERROR, "Delete proxy arp entry: %s\n", strerror(errno)); close(routes); return 0; } @@ -195,7 +198,7 @@ sifproxyarp(unit, hisaddr) ((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) { - fprintf(stderr, "ioctl(SIOCSARP): \n"); + LogPrintf(LogERROR, "sifproxyarp: ioctl(SIOCSARP): \n"); return 0; } @@ -216,7 +219,7 @@ cifproxyarp(unit, hisaddr) 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) { - fprintf(stderr, "ioctl(SIOCDARP): \n"); + LogPrintf(LogERROR, "cifproxyarp: ioctl(SIOCDARP): \n"); return 0; } return 1; @@ -246,7 +249,7 @@ get_ether_addr(s, ipaddr, hwaddr) ifc.ifc_len = sizeof(ifs); ifc.ifc_req = ifs; if (ioctl(s, SIOCGIFCONF, &ifc) < 0) { - fprintf(stderr, "ioctl(SIOCGIFCONF): \n"); + LogPrintf(LogERROR, "get_ether_addr: ioctl(SIOCGIFCONF): \n"); return 0; } @@ -287,7 +290,7 @@ nextif: if (ifr >= ifend) return 0; - LogPrintf(LOG_PHASE_BIT, "found interface %s for proxy arp\n", ifr->ifr_name); + LogPrintf(LogPHASE, "Found interface %s for proxy arp\n", ifr->ifr_name); /* * Now scan through again looking for a link-level address @@ -335,14 +338,12 @@ kread(addr, buf, size) char *buf; int size; { - - if (kvm_read(kvmd, addr, buf, size) != size) { - /* XXX this duplicates kvm_read's error printout */ - (void)fprintf(stderr, "kvm_read %s\n", - kvm_geterr(kvmd)); - return (-1); - } - return (0); + if (kvm_read(kvmd, addr, buf, size) != size) { + /* XXX this duplicates kvm_read's error printout */ + LogPrintf(LogERROR, "kvm_read %s\n", kvm_geterr(kvmd)); + return -1; + } + return 0; } kmemgetether(ifname, dlo) diff --git a/usr.sbin/ppp/arp.h b/usr.sbin/ppp/arp.h index 5273716..b2e38e6 100644 --- a/usr.sbin/ppp/arp.h +++ b/usr.sbin/ppp/arp.h @@ -17,12 +17,12 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: arp.h,v 1.3 1997/02/22 16:09:57 peter Exp $ * */ #ifndef _ARP_H_ #define _ARP_H_ -extern int cifproxyarp __P((int, u_long)); -extern int sifproxyarp __P((int, u_long)); +extern int cifproxyarp(int, u_long); +extern int sifproxyarp(int, u_long); #endif diff --git a/usr.sbin/ppp/async.c b/usr.sbin/ppp/async.c index f122c40..c4a101b 100644 --- a/usr.sbin/ppp/async.c +++ b/usr.sbin/ppp/async.c @@ -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.7 1997/02/22 16:09:59 peter Exp $ + * $Id: async.c,v 1.8 1997/05/26 00:43:55 brian Exp $ * */ #include "fsm.h" @@ -121,7 +121,7 @@ int proto; *cp ++ = HDLC_SYN; cnt = cp - hs->xbuff; - LogDumpBuff(LOG_ASYNC, "WriteModem", hs->xbuff, cnt); + LogDumpBuff(LogASYNC, "WriteModem", hs->xbuff, cnt); WriteModem(pri, (char *)hs->xbuff, cnt); OsAddOutOctets(cnt); pfree(bp); @@ -156,7 +156,7 @@ u_char c; default: if (hs->length >= HDLCSIZE) { /* packet is too large, discard it */ - logprintf("too large, diacarding.\n"); + LogPrintf(LogERROR, "Packet too large (%d), diacarding.\n", hs->length); hs->length = 0; hs->mode = MODE_HUNT; break; diff --git a/usr.sbin/ppp/auth.c b/usr.sbin/ppp/auth.c index af99f04..17b3424 100644 --- a/usr.sbin/ppp/auth.c +++ b/usr.sbin/ppp/auth.c @@ -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.12 1997/05/10 01:22:05 brian Exp $ + * $Id: auth.c,v 1.13 1997/05/26 00:43:55 brian Exp $ * * TODO: * o Implement check against with registered IP addresses. @@ -158,9 +158,7 @@ int len, setaddr; } n -= 2; if (n > 0 && setaddr) { -#ifdef DEBUG - LogPrintf(LOG_LCP_BIT, "*** n = %d, %s\n", n, vector[2]); -#endif + LogPrintf(LogDEBUG, "AuthGetSecret: n = %d, %s\n", n, vector[2]); if (ParseAddr(n--, &vector[2], &DefHisAddress.ipaddr, &DefHisAddress.mask, diff --git a/usr.sbin/ppp/auth.h b/usr.sbin/ppp/auth.h index 169f84c..4ca72ae 100644 --- a/usr.sbin/ppp/auth.h +++ b/usr.sbin/ppp/auth.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: auth.h,v 1.5 1997/02/22 16:10:02 peter Exp $ * * TODO: */ @@ -35,10 +35,10 @@ struct authinfo { extern struct authinfo AuthPapInfo; extern struct authinfo AuthChapInfo; -extern void SendPapChallenge __P((int)); -extern void SendChapChallenge __P((int)); -extern void StopAuthTimer __P((struct authinfo *)); -extern void StartAuthChallenge __P((struct authinfo *)); -extern LOCAL_AUTH_VALID LocalAuthInit __P((void)); -extern int AuthValidate __P((char *, char *, char *)); +extern void SendPapChallenge(int); +extern void SendChapChallenge(int); +extern void StopAuthTimer(struct authinfo *); +extern void StartAuthChallenge(struct authinfo *); +extern LOCAL_AUTH_VALID LocalAuthInit(void); +extern int AuthValidate(char *, char *, char *); #endif diff --git a/usr.sbin/ppp/ccp.c b/usr.sbin/ppp/ccp.c index 5b11272..bee7131 100644 --- a/usr.sbin/ppp/ccp.c +++ b/usr.sbin/ppp/ccp.c @@ -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.11 1997/05/10 01:22:06 brian Exp $ + * $Id: ccp.c,v 1.12 1997/05/26 00:43:56 brian Exp $ * * TODO: * o Support other compression protocols @@ -30,19 +30,18 @@ #include "loadalias.h" #include "vars.h" #include "pred.h" -#include "cdefs.h" struct ccpstate CcpInfo; -static void CcpSendConfigReq __P((struct fsm *)); -static void CcpSendTerminateReq __P((struct fsm *fp)); -static void CcpSendTerminateAck __P((struct fsm *fp)); -static void CcpDecodeConfig __P((u_char *cp, int flen, int mode)); -static void CcpLayerStart __P((struct fsm *)); -static void CcpLayerFinish __P((struct fsm *)); -static void CcpLayerUp __P((struct fsm *)); -static void CcpLayerDown __P((struct fsm *)); -static void CcpInitRestartCounter __P((struct fsm *)); +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 CcpLayerStart(struct fsm *); +static void CcpLayerFinish(struct fsm *); +static void CcpLayerUp(struct fsm *); +static void CcpLayerDown(struct fsm *); +static void CcpInitRestartCounter(struct fsm *); #define REJECTED(p, x) (p->his_reject & (1<<x)) @@ -83,11 +82,13 @@ ReportCcpStatus() struct ccpstate *icp = &CcpInfo; struct fsm *fp = &CcpFsm; - printf("%s [%s]\n", fp->name, StateNames[fp->state]); - printf("myproto = %s, hisproto = %s\n", - cftypes[icp->want_proto], cftypes[icp->his_proto]); - printf("Input: %ld --> %ld, Output: %ld --> %ld\n", - icp->orgin, icp->compin, icp->orgout, icp->compout); + if (VarTerm) { + fprintf(VarTerm, "%s [%s]\n", fp->name, StateNames[fp->state]); + fprintf(VarTerm, "myproto = %s, hisproto = %s\n", + cftypes[icp->want_proto], cftypes[icp->his_proto]); + fprintf(VarTerm, "Input: %ld --> %ld, Output: %ld --> %ld\n", + icp->orgin, icp->compin, icp->orgout, icp->compout); + } return 0; } @@ -119,7 +120,7 @@ struct fsm *fp; struct ccpstate *icp = &CcpInfo; cp = ReqBuff; - LogPrintf(LOG_LCP_BIT, "%s: SendConfigReq\n", fp->name); + LogPrintf(LogLCP, "CcpSendConfigReq\n"); if (icp->want_proto && !REJECTED(icp, TY_PRED1)) { *cp++ = TY_PRED1; *cp++ = 2; } @@ -131,7 +132,7 @@ CcpSendResetReq(fp) struct fsm *fp; { Pred1Init(1); /* Initialize Input part */ - LogPrintf(LOG_LCP_BIT, "%s: SendResetReq\n", fp->name); + LogPrintf(LogLCP, "CcpSendResetReq\n"); FsmOutput(fp, CODE_RESETREQ, fp->reqid, NULL, 0); } @@ -146,7 +147,7 @@ static void CcpSendTerminateAck(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, " %s: SendTerminateAck\n", fp->name); + LogPrintf(LogLCP, "CcpSendTerminateAck\n"); FsmOutput(fp, CODE_TERMACK, fp->reqid++, NULL, 0); } @@ -161,21 +162,21 @@ static void CcpLayerStart(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: LayerStart.\n", fp->name); + LogPrintf(LogLCP, "CcpLayerStart.\n"); } static void CcpLayerFinish(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: LayerFinish.\n", fp->name); + LogPrintf(LogLCP, "CcpLayerFinish.\n"); } static void CcpLayerDown(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: LayerDown.\n", fp->name); + LogPrintf(LogLCP, "CcpLayerDown.\n"); } /* @@ -185,11 +186,8 @@ static void CcpLayerUp(fp) struct fsm *fp; { -#ifdef VERBOSE - fprintf(stderr, "%s: LayerUp(%d).\r\n", fp->name, fp->state); -#endif - LogPrintf(LOG_LCP_BIT, "%s: LayerUp.\n", fp->name); - LogPrintf(LOG_LCP_BIT, "myproto = %d, hisproto = %d\n", + LogPrintf(LogLCP, "CcpLayerUp(%d).\n", fp->state); + LogPrintf(LogLCP, "myproto = %d, hisproto = %d\n", CcpInfo.want_proto, CcpInfo.his_proto); Pred1Init(3); /* Initialize Input and Output */ } @@ -198,7 +196,7 @@ void CcpUp() { FsmUp(&CcpFsm); - LogPrintf(LOG_LCP_BIT, "CCP Up event!!\n"); + LogPrintf(LogLCP, "CCP Up event!!\n"); } void @@ -231,7 +229,7 @@ int mode; else snprintf(tbuff, sizeof(tbuff), " "); - LogPrintf(LOG_LCP_BIT, "%s\n", tbuff); + LogPrintf(LogLCP, "%s\n", tbuff); switch (type) { case TY_PRED1: @@ -271,7 +269,7 @@ CcpInput(struct mbuf *bp) if (phase == PHASE_NETWORK) FsmInput(&CcpFsm, bp); else { - logprintf("ccp in phase %d\n", phase); + LogPrintf(LogERROR, "Unexpected CCP in phase %d\n", phase); pfree(bp); } } diff --git a/usr.sbin/ppp/ccp.h b/usr.sbin/ppp/ccp.h index 785c573..acb2a1b 100644 --- a/usr.sbin/ppp/ccp.h +++ b/usr.sbin/ppp/ccp.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: ccp.h,v 1.5 1997/02/22 16:10:03 peter Exp $ * * TODO: */ @@ -49,10 +49,10 @@ struct ccpstate { extern struct ccpstate CcpInfo; -void CcpRecvResetReq __P((struct fsm *)); -void CcpSendResetReq __P((struct fsm *)); -void CcpInput __P((struct mbuf *)); -void CcpUp __P((void)); -void CcpOpen __P((void)); -void CcpInit __P((void)); +void CcpRecvResetReq(struct fsm *); +void CcpSendResetReq(struct fsm *); +void CcpInput(struct mbuf *); +void CcpUp(void); +void CcpOpen(void); +void CcpInit(void); #endif diff --git a/usr.sbin/ppp/cdefs.h b/usr.sbin/ppp/cdefs.h deleted file mode 100644 index 540905d..0000000 --- a/usr.sbin/ppp/cdefs.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Written by Toshiharu OHNO (tony-o@iij.ad.jp) - * - * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the Internet Initiative Japan. The name of the - * IIJ may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: cdefs.h,v 1.3 1997/02/22 16:10:04 peter Exp $ - * - * TODO: - */ - -#ifndef __P -#if defined(__bsdi__) || defined(__FreeBSD__) -#include <sys/cdefs.h> -#else -#ifdef __STDC__ -#define __P(arg) arg -#else -#define __P(arg) () -#endif /* __STDC__ */ -#endif /* __bsdi__ */ -#endif /* __P */ diff --git a/usr.sbin/ppp/chap.c b/usr.sbin/ppp/chap.c index ee40421..0ca0c7f 100644 --- a/usr.sbin/ppp/chap.c +++ b/usr.sbin/ppp/chap.c @@ -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.16 1997/05/24 17:32:32 brian Exp $ + * $Id: chap.c,v 1.17 1997/05/26 00:43:56 brian Exp $ * * TODO: */ @@ -62,10 +62,8 @@ int count; bcopy(&lh, MBUF_CTOP(bp), sizeof(struct fsmheader)); if (count) bcopy(ptr, MBUF_CTOP(bp) + sizeof(struct fsmheader), count); -#ifdef DEBUG - DumpBp(bp); -#endif - LogPrintf(LOG_LCP_BIT, "ChapOutput: %s\n", chapcodes[code]); + LogDumpBp(LogDEBUG, "ChapOutput", bp); + LogPrintf(LogLCP, "ChapOutput: %s\n", chapcodes[code]); HdlcOutput(PRI_LINK, PROTO_CHAP, bp); } @@ -96,23 +94,6 @@ int chapid; ChapOutput(CHAP_CHALLENGE, chapid, challenge_data, cp - challenge_data); } -#ifdef DEBUG -void -DumpDigest(mes, cp, len) -char *mes; -char *cp; -int len; -{ - int i; - - logprintf("%s: ", mes); - for (i = 0; i < len; i++) { - logprintf(" %02x", *cp++ & 0xff); - } - logprintf("\n"); -} -#endif - void RecvChapTalk(chp, bp) struct fsmheader *chp; @@ -127,16 +108,14 @@ struct mbuf *bp; char cdigest[16]; len = ntohs(chp->length); -#ifdef DEBUG - logprintf("length: %d\n", len); -#endif + LogPrintf(LogDEBUG, "RecvChapTalk: length: %d\n", len); arglen = len - sizeof(struct fsmheader); cp = (char *)MBUF_CTOP(bp); valsize = *cp++ & 255; name = cp + valsize; namelen = arglen - valsize - 1; name[namelen] = 0; - LogPrintf(LOG_PHASE_BIT, " Valsize = %d, Name = %s\n", valsize, name); + LogPrintf(LogPHASE, " Valsize = %d, Name = %s\n", valsize, name); /* * Get a secret key corresponds to the peer @@ -165,16 +144,12 @@ struct mbuf *bp; bcopy(keyp, ap, keylen); ap += keylen; bcopy(cp, ap, valsize); -#ifdef DEBUG - DumpDigest("recv", ap, valsize); -#endif + LogDumpBuff(LogDEBUG, "recv", ap, valsize); ap += valsize; MD5Init(&context); MD5Update(&context, answer, ap - answer); MD5Final(digest, &context); -#ifdef DEBUG - DumpDigest("answer", digest, 16); -#endif + LogDumpBuff(LogDEBUG, "answer", digest, 16); bcopy(name, digest + 16, namelen); ap += namelen; /* Send answer to the peer */ @@ -195,10 +170,8 @@ struct mbuf *bp; MD5Update(&context, answer, ap - answer); MD5Update(&context, challenge_data+1, challenge_len); MD5Final(cdigest, &context); -#ifdef DEBUG - DumpDigest("got", cp, 16); - DumpDigest("expect", cdigest, 16); -#endif + LogDumpBuff(LogDEBUG, "got", cp, 16); + LogDumpBuff(LogDEBUG, "expect", cdigest, 16); /* * Compare with the response */ @@ -227,9 +200,7 @@ struct mbuf *bp; struct lcpstate *lcp = &LcpInfo; len = ntohs(chp->length); -#ifdef DEBUG - logprintf("length: %d\n", len); -#endif + LogPrintf(LogDEBUG, "RecvChapResult: length: %d\n", len); if (chp->code == CHAP_SUCCESS) { if (lcp->auth_iwait == PROTO_CHAP) { lcp->auth_iwait = 0; @@ -255,7 +226,7 @@ ChapInput(struct mbuf *bp) if (len >= ntohs(chp->length)) { if (chp->code < 1 || chp->code > 4) chp->code = 0; - LogPrintf(LOG_LCP_BIT, "ChapInput: %s\n", chapcodes[chp->code]); + LogPrintf(LogLCP, "ChapInput: %s\n", chapcodes[chp->code]); bp->offset += sizeof(struct fsmheader); bp->cnt -= sizeof(struct fsmheader); diff --git a/usr.sbin/ppp/chap.h b/usr.sbin/ppp/chap.h index 6c992a5..acb5585 100644 --- a/usr.sbin/ppp/chap.h +++ b/usr.sbin/ppp/chap.h @@ -15,15 +15,15 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: chap.h,v 1.5 1997/02/22 16:10:06 peter Exp $ * * TODO: */ #ifndef _CHAP_H_ #define _CHAP_H_ -#include "global.h" #include <md5.h> +#include "global.h" #define CHAP_CHALLENGE 1 #define CHAP_RESPONSE 2 diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c index 6659ee2..6ba72e4 100644 --- a/usr.sbin/ppp/chat.c +++ b/usr.sbin/ppp/chat.c @@ -18,7 +18,7 @@ * Columbus, OH 43221 * (614)451-1883 * - * $Id: chat.c,v 1.24 1997/05/10 01:22:07 brian Exp $ + * $Id: chat.c,v 1.25 1997/05/26 00:43:57 brian Exp $ * * TODO: * o Support more UUCP compatible control sequences. @@ -180,9 +180,9 @@ int sendmode; strncpy(result, phone, reslen); reslen -= strlen(result); result += strlen(result); - if ((mode & (MODE_INTER|MODE_AUTO)) == MODE_INTER) - fprintf(stderr, "Phone: %s\n", phone); - LogPrintf(LOG_PHASE_BIT, "Phone: %s\n", phone); + if (VarTerm) + fprintf(VarTerm, "Phone: %s\n", phone); + LogPrintf(LogPHASE, "Phone: %s", phone); break; case 'U': strncpy(result, VarAuthName, reslen); @@ -229,11 +229,11 @@ static void clear_log() { } static void flush_log() { - if ((loglevel & LOG_CONNECT_BIT) - || ((loglevel & LOG_CARRIER_BIT) - && strstr(logbuff,"CARRIER"))) { - LogPrintf(LOG_CONNECT_BIT|LOG_CARRIER_BIT,"Chat: %s\n",logbuff); - } + if (LogIsKept(LogCONNECT)) + LogPrintf(LogCONNECT,"%s", logbuff); + else if (LogIsKept(LogCARRIER) && strstr(logbuff,"CARRIER")) + LogPrintf(LogCARRIER,"%s", logbuff); + clear_log(); } @@ -271,13 +271,13 @@ char *estr; #endif clear_log(); (void) ExpandString(estr, buff, sizeof(buff), 0); - LogPrintf(LOG_CHAT_BIT, "Wait for (%d): %s --> %s\n", TimeoutSec, estr, buff); + LogPrintf(LogCHAT, "Wait for (%d): %s --> %s", TimeoutSec, estr, buff); str = buff; inp = inbuff; if (strlen(str)>=IBSIZE){ str[IBSIZE-1]=0; - LogPrintf(LOG_CHAT_BIT, "Truncating String to %d character: %s\n", IBSIZE, str); + LogPrintf(LogCHAT, "Truncating String to %d character: %s", IBSIZE, str); } nfds = modem + 1; @@ -301,14 +301,14 @@ char *estr; continue; sigsetmask(omask); #endif - perror("select"); + LogPrintf(LogERROR, "select: %s", strerror(errno)); *inp = 0; return(NOMATCH); } else if (i == 0) { /* Timeout reached! */ *inp = 0; if (inp != inbuff) - LogPrintf(LOG_CHAT_BIT, "got: %s\n", inbuff); - LogPrintf(LOG_CHAT_BIT, "can't get (%d).\n", timeout.tv_sec); + LogPrintf(LogCHAT, "Got: %s", inbuff); + LogPrintf(LogCHAT, "Can't get (%d).", timeout.tv_sec); #ifdef SIGALRM sigsetmask(omask); #endif @@ -333,7 +333,7 @@ char *estr; } for (i = 0; i < numaborts; i++) { if (strstr(inbuff, AbortStrings[i])) { - LogPrintf(LOG_CHAT_BIT, "Abort: %s\n", AbortStrings[i]); + LogPrintf(LogCHAT, "Abort: %s", AbortStrings[i]); #ifdef SIGALRM sigsetmask(omask); #endif @@ -343,7 +343,7 @@ char *estr; } } else { if (read(modem, &ch, 1) < 0) { - perror("read error"); + LogPrintf(LogERROR, "read error: %s", strerror(errno)); *inp = '\0'; return(NOMATCH); } @@ -372,7 +372,7 @@ char *estr; s1 = AbortStrings[i]; len = strlen(s1); if ((len <= inp - inbuff) && (strncmp(inp - len, s1, len) == 0)) { - LogPrintf(LOG_CHAT_BIT, "Abort: %s\n", s1); + LogPrintf(LogCHAT, "Abort: %s", s1); *inp = 0; #ifdef SIGALRM sigsetmask(omask); @@ -408,15 +408,13 @@ char *command, *out; cp--; } if (snprintf(tmp, sizeof tmp, "%s %s", command, cp) >= sizeof tmp) { - LogPrintf(LOG_CHAT_BIT, "Too long string to ExecStr: \"%s\"\n", - command); + LogPrintf(LogCHAT, "Too long string to ExecStr: \"%s\"", command); return; } (void) MakeArgs(tmp, vector, VECSIZE(vector)); if (pipe(fids) < 0) { - LogPrintf(LOG_CHAT_BIT, "Unable to create pipe in ExecStr: %s\n", - strerror(errno)); + LogPrintf(LogCHAT, "Unable to create pipe in ExecStr: %s", strerror(errno)); return; } @@ -430,29 +428,27 @@ char *command, *out; signal(SIGALRM, SIG_DFL); close(fids[0]); if (dup2(fids[1], 1) < 0) { - LogPrintf(LOG_CHAT_BIT, "dup2(fids[1], 1) in ExecStr: %s\n", - strerror(errno)); + LogPrintf(LogCHAT, "dup2(fids[1], 1) in ExecStr: %s", strerror(errno)); return; } close(fids[1]); nb = open("/dev/tty", O_RDWR); if (dup2(nb, 0) < 0) { - LogPrintf(LOG_CHAT_BIT, "dup2(nb, 0) in ExecStr: %s\n", - strerror(errno)); + LogPrintf(LogCHAT, "dup2(nb, 0) in ExecStr: %s", strerror(errno)); return; } - LogPrintf(LOG_CHAT_BIT, "exec: %s\n", command); + LogPrintf(LogCHAT, "exec: %s", command); /* switch back to original privileges */ if (setgid(getgid()) < 0) { - LogPrintf(LOG_CHAT_BIT, "setgid: %s\n", strerror(errno)); + LogPrintf(LogCHAT, "setgid: %s", strerror(errno)); exit(1); } if (setuid(getuid()) < 0) { - LogPrintf(LOG_CHAT_BIT, "setuid: %s\n", strerror(errno)); + LogPrintf(LogCHAT, "setuid: %s", strerror(errno)); exit(1); } pid = execvp(command, vector); - LogPrintf(LOG_CHAT_BIT, "execvp failed for (%d/%d): %s\n", pid, errno, command); + LogPrintf(LogCHAT, "execvp failed for (%d/%d): %s", pid, errno, command); exit(127); } else { close(fids[1]); @@ -494,9 +490,9 @@ char *str; (void) ExpandString(str, buff+2, sizeof(buff)-2, 1); } if (strstr(str, "\\P")) { /* Do not log the password itself. */ - LogPrintf(LOG_CHAT_BIT, "sending: %s\n", str); + LogPrintf(LogCHAT, "sending: %s", str); } else { - LogPrintf(LOG_CHAT_BIT, "sending: %s\n", buff+2); + LogPrintf(LogCHAT, "sending: %s", buff+2); } cp = buff; if (DEV_IS_SYNC) @@ -523,7 +519,7 @@ char *str; ++timeout_next; return(MATCH); } - LogPrintf(LOG_CHAT_BIT, "Expecting %s\n", str); + LogPrintf(LogCHAT, "Expecting %s", str); while (*str) { /* * Check whether if string contains sub-send-expect. @@ -574,9 +570,6 @@ char *script; char *vector[40]; char **argv; int argc, n, state; -#ifdef DEBUG - int i; -#endif timeout_next = abort_next = 0; for (n = 0; AbortStrings[n]; n++) { @@ -587,11 +580,6 @@ char *script; bzero(vector, sizeof(vector)); n = MakeArgs(script, vector, VECSIZE(vector)); -#ifdef DEBUG - logprintf("n = %d\n", n); - for (i = 0; i < n; i++) - logprintf(" %s\n", vector[i]); -#endif argc = n; argv = vector; TimeoutSec = 30; diff --git a/usr.sbin/ppp/chat.h b/usr.sbin/ppp/chat.h index 14ddc39..cdb032f 100644 --- a/usr.sbin/ppp/chat.h +++ b/usr.sbin/ppp/chat.h @@ -18,13 +18,12 @@ * Columbus, OH 43221 * (614)451-1883 * - * $Id: chat.h,v 1.4 1997/02/22 16:10:07 peter Exp $ + * $Id: chat.h,v 1.5 1997/05/07 23:01:24 brian Exp $ * */ #ifndef _CHAT_H_ #define _CHAT_H_ -#include "cdefs.h" -extern char * ExpandString __P((char *, char *, int, int)); -extern int MakeArgs __P((char *, char **, int)); +extern char * ExpandString(char *, char *, int, int); +extern int MakeArgs(char *, char **, int); #define VECSIZE(v) (sizeof(v) / sizeof(v[0])) #endif diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index 85bea97..e314d57 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: command.c,v 1.52 1997/05/31 16:37:19 brian Exp $ + * $Id: command.c,v 1.53 1997/06/01 01:13:00 brian Exp $ * */ #include <sys/types.h> @@ -32,6 +32,8 @@ #include <net/route.h> #include <paths.h> #include <alias.h> +#include <fcntl.h> +#include <errno.h> #include "fsm.h" #include "phase.h" #include "lcp.h" @@ -46,6 +48,7 @@ #include "systems.h" #include "chat.h" #include "os.h" +#include "timeout.h" extern void Cleanup(), TtyTermMode(), PacketMode(); extern int EnableCommand(), DisableCommand(), DisplayCommand(); @@ -80,27 +83,32 @@ struct cmdtab *plist; struct cmdtab *cmd; int n; + if (!VarTerm) + return 0; + if (argc > 0) { - for (cmd = plist; cmd->name; cmd++) { + for (cmd = plist; cmd->name; cmd++) if (strcasecmp(cmd->name, *argv) == 0 && (cmd->lauth & VarLocalAuth)) { if (plist == SetCommands) - printf("set "); - printf("%s %s\n", cmd->name, cmd->syntax); - return(1); + fprintf(VarTerm, "set "); + fprintf(VarTerm, "%s\n", cmd->syntax); + return 0; } - } - return(1); + + return -1; } + n = 0; - for (cmd = plist; cmd->func; cmd++) { + for (cmd = plist; cmd->func; cmd++) if (cmd->name && (cmd->lauth & VarLocalAuth)) { - printf(" %-8s: %-20s\n", cmd->name, cmd->helpmes); + fprintf(VarTerm, " %-8s: %-20s\n", cmd->name, cmd->helpmes); n++; } - } + if (n & 1) - printf("\n"); - return(1); + fprintf(VarTerm, "\n"); + + return 0; } int @@ -119,10 +127,11 @@ IsInteractive() else if (mode & MODE_DEDICATED) mes = "Working in dedicated mode."; if (mes) { - printf("%s\n", mes); - return(0); + if (VarTerm) + fprintf(VarTerm, "%s\n", mes); + return 0; } - return(1); + return 1; } static int @@ -134,23 +143,30 @@ char **argv; int tries; if (LcpFsm.state > ST_CLOSED) { - printf("LCP state is [%s]\n", StateNames[LcpFsm.state]); - return(1); + if (VarTerm) + fprintf(VarTerm, "LCP state is [%s]\n", StateNames[LcpFsm.state]); + return 0; } + if (!IsInteractive()) return(1); + if (argc > 0) { if (SelectSystem(*argv, CONFFILE) < 0) { - printf("%s: not found.\n", *argv); - return(1); + if (VarTerm) + fprintf(VarTerm, "%s: not found.\n", *argv); + return -1; } } + tries = 0; do { - printf("Dial attempt %u of %d\n", ++tries, VarDialTries); + if (VarTerm) + fprintf(VarTerm, "Dial attempt %u of %d\n", ++tries, VarDialTries); modem = OpenModem(mode); if (modem < 0) { - printf("failed to open modem.\n"); + if (VarTerm) + fprintf(VarTerm, "Failed to open modem.\n"); break; } if (DialModem() == EX_DONE) { @@ -160,7 +176,8 @@ char **argv; break; } } while (VarDialTries == 0 || tries < VarDialTries); - return(1); + + return 0; } static int @@ -171,33 +188,50 @@ char **argv; { const char *shell; pid_t shpid; + FILE *oVarTerm; - if((shell = getenv("SHELL")) == 0) { - shell = _PATH_BSHELL; - } #ifdef SHELL_ONLY_INTERACTIVELY -#ifndef HAVE_SHELL_CMD_WITH_ANY_MODE - if( mode != MODE_INTER) { - fprintf(stdout, - "Can only start a shell in interactive mode\n"); - return(1); - } -#else - if(argc == 0 && !(mode & MODE_INTER)) { - fprintf(stderr, - "Can only start an interactive shell in interactive mode\n"); - return(1); + if (mode != MODE_INTER) { + LogPrintf(LogWARN, "Can only start a shell in interactive mode\n"); + return 1; } -#endif /* HAVE_SHELL_CMD_WITH_ANY_MODE */ #else if ((mode & (MODE_AUTO|MODE_INTER)) == (MODE_AUTO|MODE_INTER)) { - fprintf(stdout, - "Shell is not allowed interactively in auto mode\n"); - return(1); + LogPrintf(LogWARN, "Shell is not allowed interactively in auto mode\n"); + return 1; + } +#endif + + if(argc == 0 && !(mode & MODE_INTER)) { + LogPrintf(LogWARN, "Can only start an interactive shell in" + " interactive mode\n"); + return 1; } -#endif /* SHELL_ONLY_INTERACTIVELY */ + + if((shell = getenv("SHELL")) == 0) + shell = _PATH_BSHELL; + if((shpid = fork()) == 0) { - int dtablesize, i ; + int dtablesize, i, fd; + + if (VarTerm) + fd = fileno(VarTerm); + else if ((fd = open("/dev/null", O_RDWR)) == -1) { + LogPrintf(LogALERT, "Failed to open /dev/null: %s\n", strerror(errno)); + exit(1); + } + + for (i = 0; i < 3; i++) + dup2(fd, i); + + if (fd > 2) + if (VarTerm) { + oVarTerm = VarTerm; + VarTerm = 0; + if (oVarTerm && oVarTerm != stdout) + fclose(oVarTerm); + } else + close(fd); for (dtablesize = getdtablesize(), i = 3; i < dtablesize; i++) (void)close(i); @@ -207,11 +241,11 @@ char **argv; * real user for avoiding security problems. */ if (setgid(getgid()) < 0) { - perror("setgid"); + LogPrintf(LogERROR, "setgid: %s\n", strerror(errno)); exit(1); } if (setuid(getuid()) < 0) { - perror("setuid"); + LogPrintf(LogERROR, "setuid: %s\n", strerror(errno)); exit(1); } TtyOldMode(); @@ -233,11 +267,12 @@ char **argv; else (void)execl(shell, shell, NULL); - fprintf(stdout, "exec() of %s failed\n", argc > 0? argv[0]: shell); + LogPrintf(LogWARN, "exec() of %s failed\n", argc > 0 ? argv[0] : shell); exit(255); } + if( shpid == (pid_t)-1 ) { - fprintf(stdout, "Fork failed\n"); + LogPrintf(LogERROR, "Fork failed: %s\n", strerror(errno)); } else { int status; (void)waitpid(shpid, &status, 0); @@ -248,51 +283,47 @@ char **argv; return(0); } -static char StrOption[] = "option .."; -static char StrRemote[] = "[remote]"; -char StrNull[] = ""; - struct cmdtab const Commands[] = { { "accept", NULL, AcceptCommand, LOCAL_AUTH, - "accept option request", StrOption}, + "accept option request", "accept option .."}, { "add", NULL, AddCommand, LOCAL_AUTH, - "add route", "dest mask gateway"}, + "add route", "add dest mask gateway"}, { "close", NULL, CloseCommand, LOCAL_AUTH, - "Close connection", StrNull}, + "Close connection", "close"}, { "delete", NULL, DeleteCommand, LOCAL_AUTH, - "delete route", "ALL | dest gateway [mask]"}, + "delete route", "delete ALL | dest gateway [mask]"}, { "deny", NULL, DenyCommand, LOCAL_AUTH, - "Deny option request", StrOption}, + "Deny option request", "deny option .."}, { "dial", "call", DialCommand, LOCAL_AUTH, - "Dial and login", StrRemote}, + "Dial and login", "dial|call [remote]"}, { "disable", NULL, DisableCommand, LOCAL_AUTH, - "Disable option", StrOption}, + "Disable option", "disable option .."}, { "display", NULL, DisplayCommand, LOCAL_AUTH, - "Display option configs", StrNull}, + "Display option configs", "display"}, { "enable", NULL, EnableCommand, LOCAL_AUTH, - "Enable option", StrOption}, + "Enable option", "enable option .."}, { "passwd", NULL, LocalAuthCommand,LOCAL_NO_AUTH, - "Password for manipulation", StrOption}, + "Password for manipulation", "passwd option .."}, { "load", NULL, LoadCommand, LOCAL_AUTH, - "Load settings", StrRemote}, + "Load settings", "load [remote]"}, { "save", NULL, SaveCommand, LOCAL_AUTH, - "Save settings", StrNull}, + "Save settings", "save"}, { "set", "setup", SetCommand, LOCAL_AUTH, - "Set parameters", "var value"}, + "Set parameters", "set[up] var value"}, { "shell", "!", ShellCommand, LOCAL_AUTH, - "Run a subshell", "[sh command]"}, + "Run a subshell", "shell|! [sh command]"}, { "show", NULL, ShowCommand, LOCAL_AUTH, - "Show status and statictics", "var"}, + "Show status and statictics", "show var"}, { "term", NULL, TerminalCommand,LOCAL_AUTH, - "Enter to terminal mode", StrNull}, + "Enter to terminal mode", "term"}, { "alias", NULL, AliasCommand, LOCAL_AUTH, - "alias control", "option [yes|no]"}, + "alias control", "alias option [yes|no]"}, { "quit", "bye", QuitCommand, LOCAL_AUTH | LOCAL_NO_AUTH, - "Quit PPP program", "[all]"}, + "Quit PPP program", "quit|bye [all]"}, { "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH, - "Display this message", "[command]", (void *)Commands }, + "Display this message", "help|? [command]", (void *)Commands }, { NULL, "down", DownCommand, LOCAL_AUTH, - "Generate down event", StrNull}, + "Generate down event", "down"}, { NULL, NULL, NULL }, }; @@ -305,56 +336,56 @@ extern int ShowModemStatus(); extern int ReportHdlcStatus(); extern int ShowMemMap(); -static char *LogLevelName[] = { - LM_PHASE, LM_CHAT, LM_LQM, LM_LCP, - LM_TCPIP, LM_HDLC, LM_ASYNC, LM_LINK, - LM_CONNECT, LM_CARRIER, -}; - -static int ShowDebugLevel() +static int ShowLogLevel() { int i; - printf("%02x: ", loglevel); - for (i = LOG_PHASE; i < MAXLOGLEVEL; i++) { - if (loglevel & (1 << i)) - printf("%s ", LogLevelName[i]); + if (!VarTerm) + return 0; + fprintf(VarTerm, "Log:"); + for (i = LogMIN; i < LogMAXCONF; i++) { + if (LogIsKept(i)) + fprintf(VarTerm, " %s", LogName(i)); } - printf("\n"); - return(1); + fprintf(VarTerm, "\n"); + + return 0; } static int ShowEscape() { int code, bit; + if (!VarTerm) + return 0; if (EscMap[32]) { - for (code = 0; code < 32; code++) { - if (EscMap[code]) { - for (bit = 0; bit < 8; bit++) { - if (EscMap[code] & (1<<bit)) { - printf(" 0x%02x", (code << 3) + bit); - } - } - } - } - printf("\n"); + for (code = 0; code < 32; code++) + if (EscMap[code]) + for (bit = 0; bit < 8; bit++) + if (EscMap[code] & (1<<bit)) + fprintf(VarTerm, " 0x%02x", (code << 3) + bit); + fprintf(VarTerm, "\n"); } - return(1); + return 1; } static int ShowTimeout() { - printf(" Idle Timer: %d secs LQR Timer: %d secs Retry Timer: %d secs\n", - VarIdleTimeout, VarLqrTimeout, VarRetryTimeout); - return(1); + if (!VarTerm) + return 0; + fprintf(VarTerm, " Idle Timer: %d secs LQR Timer: %d secs" + " Retry Timer: %d secs\n", VarIdleTimeout, VarLqrTimeout, + VarRetryTimeout); + return 1; } static int ShowAuthKey() { - printf("AuthName = %s\n", VarAuthName); - printf("AuthKey = %s\n", VarAuthKey); - return(1); + if (!VarTerm) + return 0; + fprintf(VarTerm, "AuthName = %s\n", VarAuthName); + fprintf(VarTerm, "AuthKey = %s\n", VarAuthKey); + return 1; } static int ShowVersion() @@ -362,134 +393,137 @@ static int ShowVersion() extern char VarVersion[]; extern char VarLocalVersion[]; - printf("%s - %s \n", VarVersion, VarLocalVersion); - return(1); -} - -static int ShowLogList() -{ - ListLog(); - return(1); + if (!VarTerm) + return 0; + fprintf(VarTerm, "%s - %s \n", VarVersion, VarLocalVersion); + return 1; } static int ShowInitialMRU() { - printf(" Initial MRU: %ld\n", VarMRU); - return(1); + if (!VarTerm) + return 0; + fprintf(VarTerm, " Initial MRU: %ld\n", VarMRU); + return 1; } static int ShowPreferredMTU() { + if (!VarTerm) + return 0; if (VarPrefMTU) - printf(" Preferred MTU: %ld\n", VarPrefMTU); + fprintf(VarTerm, " Preferred MTU: %ld\n", VarPrefMTU); else - printf(" Preferred MTU: unspecified\n"); - return(1); + fprintf(VarTerm, " Preferred MTU: unspecified\n"); + return 1; } static int ShowReconnect() { - printf(" Reconnect Timer: %d, %d tries\n", + if (!VarTerm) + return 0; + fprintf(VarTerm, " Reconnect Timer: %d, %d tries\n", VarReconnectTimer, VarReconnectTries); - return(1); + return 1; } static int ShowRedial() { - printf(" Redial Timer: "); + if (!VarTerm) + return 0; + fprintf(VarTerm, " Redial Timer: "); if (VarRedialTimeout >= 0) { - printf(" %d seconds, ", VarRedialTimeout); + fprintf(VarTerm, " %d seconds, ", VarRedialTimeout); } else { - printf(" Random 0 - %d seconds, ", REDIAL_PERIOD); + fprintf(VarTerm, " Random 0 - %d seconds, ", REDIAL_PERIOD); } - printf(" Redial Next Timer: "); + fprintf(VarTerm, " Redial Next Timer: "); if (VarRedialNextTimeout >= 0) { - printf(" %d seconds, ", VarRedialNextTimeout); + fprintf(VarTerm, " %d seconds, ", VarRedialNextTimeout); } else { - printf(" Random 0 - %d seconds, ", REDIAL_PERIOD); + fprintf(VarTerm, " Random 0 - %d seconds, ", REDIAL_PERIOD); } if (VarDialTries) - printf("%d dial tries", VarDialTries); + fprintf(VarTerm, "%d dial tries", VarDialTries); - printf("\n"); + fprintf(VarTerm, "\n"); - return(1); + return 1; } -#ifdef MSEXT +#ifndef NOMSEXT static int ShowMSExt() { - printf(" MS PPP extention values \n" ); - printf(" Primary NS : %s\n", inet_ntoa( ns_entries[0] )); - printf(" Secondary NS : %s\n", inet_ntoa( ns_entries[1] )); - printf(" Primary NBNS : %s\n", inet_ntoa( nbns_entries[0] )); - printf(" Secondary NBNS : %s\n", inet_ntoa( nbns_entries[1] )); - - return(1); + if (!VarTerm) + return 0; + fprintf(VarTerm, " MS PPP extention values \n" ); + fprintf(VarTerm, " Primary NS : %s\n", inet_ntoa( ns_entries[0] )); + fprintf(VarTerm, " Secondary NS : %s\n", inet_ntoa( ns_entries[1] )); + fprintf(VarTerm, " Primary NBNS : %s\n", inet_ntoa( nbns_entries[0] )); + fprintf(VarTerm, " Secondary NBNS : %s\n", inet_ntoa( nbns_entries[1] )); + return 1; } -#endif /* MSEXT */ +#endif extern int ShowIfilter(), ShowOfilter(), ShowDfilter(), ShowAfilter(); struct cmdtab const ShowCommands[] = { { "afilter", NULL, ShowAfilter, LOCAL_AUTH, - "Show keep Alive filters", StrOption}, + "Show keep Alive filters", "show afilter option .."}, { "auth", NULL, ShowAuthKey, LOCAL_AUTH, - "Show auth name/key", StrNull}, + "Show auth name/key", "show auth"}, { "ccp", NULL, ReportCcpStatus, LOCAL_AUTH, - "Show CCP status", StrNull}, + "Show CCP status", "show cpp"}, { "compress", NULL, ReportCompress, LOCAL_AUTH, - "Show compression statictics", StrNull}, - { "debug", NULL, ShowDebugLevel, LOCAL_AUTH, - "Show current debug level", StrNull}, + "Show compression statictics", "show compress"}, { "dfilter", NULL, ShowDfilter, LOCAL_AUTH, - "Show Demand filters", StrOption}, + "Show Demand filters", "show dfilteroption .."}, { "escape", NULL, ShowEscape, LOCAL_AUTH, - "Show escape characters", StrNull}, + "Show escape characters", "show escape"}, { "hdlc", NULL, ReportHdlcStatus, LOCAL_AUTH, - "Show HDLC error summary", StrNull}, + "Show HDLC error summary", "show hdlc"}, { "ifilter", NULL, ShowIfilter, LOCAL_AUTH, - "Show Input filters", StrOption}, + "Show Input filters", "show ifilter option .."}, { "ipcp", NULL, ReportIpcpStatus, LOCAL_AUTH, - "Show IPCP status", StrNull}, + "Show IPCP status", "show ipcp"}, { "lcp", NULL, ReportLcpStatus, LOCAL_AUTH, - "Show LCP status", StrNull}, - { "log", NULL, ShowLogList, LOCAL_AUTH, - "Show log records", StrNull}, + "Show LCP status", "show lcp"}, + { "log", NULL, ShowLogLevel, LOCAL_AUTH, + "Show current log level", "show log"}, { "mem", NULL, ShowMemMap, LOCAL_AUTH, - "Show memory map", StrNull}, + "Show memory map", "show mem"}, { "modem", NULL, ShowModemStatus, LOCAL_AUTH, - "Show modem setups", StrNull}, + "Show modem setups", "show modem"}, { "mru", NULL, ShowInitialMRU, LOCAL_AUTH, - "Show Initial MRU", StrNull}, + "Show Initial MRU", "show mru"}, { "mtu", NULL, ShowPreferredMTU, LOCAL_AUTH, - "Show Preferred MTU", StrNull}, + "Show Preferred MTU", "show mtu"}, { "ofilter", NULL, ShowOfilter, LOCAL_AUTH, - "Show Output filters", StrOption}, + "Show Output filters", "show ofilter option .."}, { "proto", NULL, ReportProtStatus, LOCAL_AUTH, - "Show protocol summary", StrNull}, + "Show protocol summary", "show proto"}, { "reconnect",NULL, ShowReconnect, LOCAL_AUTH, - "Show Reconnect timer,tries", StrNull}, + "Show Reconnect timer,tries", "show reconnect"}, { "redial", NULL, ShowRedial, LOCAL_AUTH, - "Show Redial timeout value", StrNull}, + "Show Redial timeout value", "show redial"}, { "route", NULL, ShowRoute, LOCAL_AUTH, - "Show routing table", StrNull}, + "Show routing table", "show route"}, { "timeout", NULL, ShowTimeout, LOCAL_AUTH, - "Show Idle timeout value", StrNull}, -#ifdef MSEXT + "Show Idle timeout value", "show timeout"}, +#ifndef NOMSEXT { "msext", NULL, ShowMSExt, LOCAL_AUTH, - "Show MS PPP extentions", StrNull}, -#endif /* MSEXT */ + "Show MS PPP extentions", "show msext"}, +#endif { "version", NULL, ShowVersion, LOCAL_NO_AUTH | LOCAL_AUTH, - "Show version string", StrNull}, + "Show version string", "show version"}, { "help", "?", HelpCommand, LOCAL_NO_AUTH | LOCAL_AUTH, - "Display this message", StrNull, (void *)ShowCommands}, + "Display this message", "show help|?", (void *)ShowCommands}, { NULL, NULL, NULL }, }; @@ -499,22 +533,33 @@ struct cmdtab *cmds; char *str; int *pmatch; { - int nmatch = 0; - int len = strlen(str); - struct cmdtab *found = NULL; + int nmatch; + int len; + struct cmdtab *found; + found = NULL; + len = strlen(str); + nmatch = 0; while (cmds->func) { if (cmds->name && strncasecmp(str, cmds->name, len) == 0) { + if (cmds->name[len] == '\0') { + *pmatch = 1; + return cmds; + } nmatch++; found = cmds; - } else if (cmds->alias && strncasecmp(str, cmds->alias, len) == 0) { + } else if(cmds->alias && strncasecmp(str, cmds->alias, len) == 0) { + if (cmds->alias[len] == '\0') { + *pmatch = 1; + return cmds; + } nmatch++; found = cmds; } cmds++; } *pmatch = nmatch; - return(found); + return found; } int @@ -529,26 +574,33 @@ char **argv; cmd = FindCommand(cmdlist, *argv, &nmatch); if (nmatch > 1) - printf("Ambiguous.\n"); + LogPrintf(LogWARN, "%s: Ambiguous command\n", *argv); else if (cmd && ( cmd->lauth & VarLocalAuth ) ) val = (cmd->func)(cmd, --argc, ++argv, cmd->args); else - printf("what?\n"); - return(val); + LogPrintf(LogWARN, "%s: Invalid command\n", *argv); + + if (val == -1) + LogPrintf(LogWARN, "Usage: %s\n", cmd->syntax); + else if(val) + LogPrintf(LogCOMMAND, "%s: Failed %d\n", *argv, val); + + return val; } int aft_cmd = 1; +extern int TermMode; void Prompt() { char *pconnect, *pauth; - if (!(mode & MODE_INTER)) + if (!(mode & MODE_INTER) || !VarTerm || TermMode) return; if (!aft_cmd) - printf("\n"); + fprintf(VarTerm, "\n"); else aft_cmd = 0; @@ -560,8 +612,8 @@ Prompt() pconnect = "PPP"; else pconnect = "ppp"; - printf("%s%s%s> ", pconnect, pauth, VarShortHost); - fflush(stdout); + fprintf(VarTerm, "%s%s%s> ", pconnect, pauth, VarShortHost); + fflush(VarTerm); } void @@ -572,23 +624,20 @@ int prompt; { char *vector[20]; char **argv; - int argc, val; + int argc; char *cp; - val = 1; if (nb > 0) { cp = buff + strcspn(buff, "\r\n"); if (cp) *cp = '\0'; - { - argc = MakeArgs(buff, vector, VECSIZE(vector)); - argv = vector; + argc = MakeArgs(buff, vector, VECSIZE(vector)); + argv = vector; - if (argc > 0) - val = FindExec(Commands, argc, argv); - } + if (argc > 0) + FindExec(Commands, argc, argv); } - if (val && prompt) + if (prompt) Prompt(); } @@ -598,31 +647,36 @@ struct cmdtab *list; int argc; char **argv; { - int val = 1; - if (argc > 0) - val = FindExec(ShowCommands, argc, argv); + FindExec(ShowCommands, argc, argv); + else if (VarTerm) + fprintf(VarTerm, "Use ``show ?'' to get a list.\n"); else - printf("Use ``show ?'' to get a list.\n"); - return(val); + LogPrintf(LogWARN, "show command must have arguments\n"); + + return 0; } static int TerminalCommand() { if (LcpFsm.state > ST_CLOSED) { - printf("LCP state is [%s]\n", StateNames[LcpFsm.state]); - return(1); + if (VarTerm) + fprintf(VarTerm, "LCP state is [%s]\n", StateNames[LcpFsm.state]); + return 1; } if (!IsInteractive()) return(1); modem = OpenModem(mode); if (modem < 0) { - printf("failed to open modem.\n"); + if (VarTerm) + fprintf(VarTerm, "Failed to open modem.\n"); return(1); } - printf("Enter to terminal mode.\n"); - printf("Type `~?' for help.\n"); + if (VarTerm) { + fprintf(VarTerm, "Enter to terminal mode.\n"); + fprintf(VarTerm, "Type `~?' for help.\n"); + } TtyTermMode(); return(0); } @@ -633,22 +687,31 @@ struct cmdtab *list; int argc; char **argv; { + FILE *oVarTerm; + if (mode & (MODE_DIRECT|MODE_DEDICATED|MODE_AUTO)) { if (argc > 0 && (VarLocalAuth & LOCAL_AUTH)) { Cleanup(EX_NORMAL); mode &= ~MODE_INTER; + oVarTerm = VarTerm; + VarTerm = 0; + if (oVarTerm && oVarTerm != stdout) + fclose(oVarTerm); } else { - LogPrintf(LOG_PHASE_BIT, "client connection closed.\n"); + LogPrintf(LogPHASE, "Client connection closed.\n"); VarLocalAuth = LOCAL_NO_AUTH; + mode &= ~MODE_INTER; + oVarTerm = VarTerm; + VarTerm = 0; + if (oVarTerm && oVarTerm != stdout) + fclose(oVarTerm); close(netfd); - close(1); - dup2(2, 1); /* Have to have something here or the modem will be 1 */ netfd = -1; - mode &= ~MODE_INTER; } } else Cleanup(EX_NORMAL); - return(1); + + return 0; } static int @@ -658,14 +721,14 @@ CloseCommand() LcpClose(); if (mode & MODE_BACKGROUND) Cleanup(EX_NORMAL); - return(1); + return 0; } static int DownCommand() { LcpDown(); - return(1); + return 0; } static int @@ -679,16 +742,16 @@ char **argv; if (argc > 0) { if (strcmp(*argv, "sync") == 0) { VarSpeed = 0; - return(1); + return 0; } speed = atoi(*argv); if (IntToSpeed(speed) != B0) { VarSpeed = speed; - return(1); + return 0; } - printf("invalid speed.\n"); + LogPrintf(LogWARN, "%s: Invalid speed\n", *argv); } - return(1); + return -1; } static int @@ -700,9 +763,10 @@ char **argv; if (argc == 2) { VarReconnectTimer = atoi(argv[0]); VarReconnectTries = atoi(argv[1]); - } else - printf("Usage: %s %s\n", list->name, list->syntax); - return(1); + return 0; + } + + return -1; } static int @@ -719,22 +783,19 @@ char **argv; if (strncasecmp(argv[0], "random", 6) == 0 && (argv[0][6] == '\0' || argv[0][6] == '.')) { VarRedialTimeout = -1; - printf("Using random redial timeout.\n"); if (!randinit) { randinit = 1; if (srandomdev() < 0) srandom((unsigned long)(time(NULL) ^ getpid())); } - } - else { + } else { timeout = atoi(argv[0]); - if (timeout >= 0) { + if (timeout >= 0) VarRedialTimeout = timeout; - } else { - printf("invalid redial timeout\n"); - printf("Usage: %s %s\n", list->name, list->syntax); + LogPrintf(LogWARN, "Invalid redial timeout\n"); + return -1; } } @@ -742,7 +803,6 @@ char **argv; if (dot) { if (strcasecmp(++dot, "random") == 0) { VarRedialNextTimeout = -1; - printf("Using random next redial timeout.\n"); if (!randinit) { randinit = 1; if (srandomdev() < 0) @@ -751,12 +811,11 @@ char **argv; } else { timeout = atoi(dot); - if (timeout >= 0) { + if (timeout >= 0) VarRedialNextTimeout = timeout; - } else { - printf("invalid next redial timeout\n"); - printf("Usage: %s %s\n", list->name, list->syntax); + LogPrintf(LogWARN, "Invalid next redial timeout\n"); + return -1; } } } @@ -767,18 +826,16 @@ char **argv; tries = atoi(argv[1]); if (tries >= 0) { - VarDialTries = tries; - } - else { - printf("invalid retry value\n"); - printf("Usage: %s %s\n", list->name, list->syntax); + VarDialTries = tries; + } else { + LogPrintf(LogWARN, "Invalid retry value\n"); + return 1; } } + return 0; } - else { - printf("Usage: %s %s\n", list->name, list->syntax); - } - return(1); + + return -1; } static int @@ -792,40 +849,46 @@ char **argv; if (argc > 0) { parity = ChangeParity(*argv); if (parity < 0) - printf("Invalid parity.\n"); - else + LogPrintf(LogWARN, "Invalid parity.\n"); + else { VarParity = parity; + return 0; + } } - return(1); + + return -1; } static int -SetDebugLevel(list, argc, argv) +SetLogLevel(list, argc, argv) struct cmdtab *list; int argc; char **argv; { - int level, w; - - for (level = 0; argc-- > 0; argv++) { - if (isdigit(**argv)) { - w = atoi(*argv); - if (w < 0 || w >= MAXLOGLEVEL) { - printf("invalid log level.\n"); + int i; + int res; + char *arg; + + res = 0; + if (argc == 0 || (argv[0][0] != '+' && argv[0][0] != '-')) + LogDiscardAll(); + while (argc--) { + arg = **argv == '+' || **argv == '-' ? *argv + 1 : *argv; + for (i = LogMIN; i <= LogMAX; i++) + if (strcasecmp(arg, LogName(i)) == 0) { + if (**argv == '-') + LogDiscard(i); + else + LogKeep(i); break; - } else - level |= (1 << w); - } else { - for (w = 0; w < MAXLOGLEVEL; w++) { - if (strcasecmp(*argv, LogLevelName[w]) == 0) { - level |= (1 << w); - continue; - } } + if (i > LogMAX) { + LogPrintf(LogWARN, "%s: Invalid log value\n", arg); + res = -1; } + argv++; } - loglevel = level; - return(1); + return res; } static int @@ -844,7 +907,7 @@ char **argv; EscMap[code >> 3] |= (1 << (code&7)); EscMap[32] = 1; } - return(1); + return 0; } static int @@ -854,19 +917,22 @@ int argc; char **argv; { long mru; + char *err; if (argc > 0) { mru = atol(*argv); if (mru < MIN_MRU) - printf("Given MRU value (%ld) is too small.\n", mru); + err = "Given MRU value (%ld) is too small.\n"; else if (mru > MAX_MRU) - printf("Given MRU value (%ld) is too big.\n", mru); - else + err = "Given MRU value (%ld) is too big.\n"; + else { VarMRU = mru; - } else - printf("Usage: %s %s\n", list->name, list->syntax); + return 0; + } + LogPrintf(LogWARN, err, mru); + } - return(1); + return -1; } static int @@ -876,21 +942,25 @@ int argc; char **argv; { long mtu; + char *err; if (argc > 0) { mtu = atol(*argv); - if (mtu == 0) + if (mtu == 0) { VarPrefMTU = 0; - else if (mtu < MIN_MTU) - printf("Given MTU value (%ld) is too small.\n", mtu); + return 0; + } else if (mtu < MIN_MTU) + err = "Given MTU value (%ld) is too small.\n"; else if (mtu > MAX_MTU) - printf("Given MTU value (%ld) is too big.\n", mtu); - else + err = "Given MTU value (%ld) is too big.\n"; + else { VarPrefMTU = mtu; - } else - printf("Usage: %s %s\n", list->name, list->syntax); + return 0; + } + LogPrintf(LogWARN, err, mtu); + } - return(1); + return -1; } static int @@ -901,6 +971,7 @@ char **argv; { if (argc-- > 0) { VarIdleTimeout = atoi(*argv++); + UpdateIdleTimer(); /* If we're connected, restart the idle timer */ if (argc-- > 0) { VarLqrTimeout = atoi(*argv++); if (VarLqrTimeout < 1) @@ -911,8 +982,10 @@ char **argv; VarRetryTimeout = 3; } } + return 0; } - return(1); + + return -1; } struct in_addr @@ -938,22 +1011,21 @@ char **argv; { DefMyAddress.ipaddr.s_addr = DefHisAddress.ipaddr.s_addr = 0L; - if (argc > 4) { - printf("set ifaddr: too many arguments (%d > 4)\n", argc); - return(0); - } + if (argc > 4) + return -1; + if (argc > 0) { if (ParseAddr(argc, argv++, &DefMyAddress.ipaddr, &DefMyAddress.mask, &DefMyAddress.width) == 0) - return(0); + return 1; if (--argc > 0) { if (ParseAddr(argc, argv++, &DefHisAddress.ipaddr, &DefHisAddress.mask, &DefHisAddress.width) == 0) - return(0); + return 2; if (--argc > 0) { ifnetmask = GetIpAddr(*argv); if (--argc > 0) { @@ -961,7 +1033,7 @@ char **argv; &DefTriggerAddress.ipaddr, &DefTriggerAddress.mask, &DefTriggerAddress.width) == 0) - return(0); + return 3; } } } @@ -981,12 +1053,12 @@ char **argv; if ((mode & MODE_AUTO) || ((mode & MODE_DEDICATED) && dstsystem)) { if (OsSetIpaddress(DefMyAddress.ipaddr, DefHisAddress.ipaddr, ifnetmask) < 0) - return(0); + return 4; } - return(1); + return 0; } -#ifdef MSEXT +#ifndef NOMSEXT void SetMSEXT(pri_addr, sec_addr, argc, argv) @@ -1025,7 +1097,7 @@ int argc; char **argv; { SetMSEXT(&ns_entries[0], &ns_entries[1], argc, argv); - return(1); + return 0; } static int @@ -1035,7 +1107,7 @@ int argc; char **argv; { SetMSEXT(&nbns_entries[0], &nbns_entries[1], argc, argv); - return(1); + return 0; } #endif /* MS_EXT */ @@ -1076,6 +1148,7 @@ int param; VarLoginScript[sizeof(VarLoginScript)-1] = '\0'; break; case VAR_DEVICE: + CloseModem(); strncpy(VarDevice, *argv, sizeof(VarDevice)-1); VarDevice[sizeof(VarDevice)-1] = '\0'; VarBaseDevice = rindex(VarDevice, '/'); @@ -1093,7 +1166,7 @@ int param; break; } } - return(1); + return 0; } static int SetCtsRts(list, argc, argv) @@ -1107,9 +1180,10 @@ char **argv; else if (strcmp(*argv, "off") == 0) VarCtsRts = FALSE; else - printf("usage: set ctsrts [on|off].\n"); + return -1; + return 0; } - return(1); + return -1; } @@ -1124,70 +1198,69 @@ char **argv; else if (strcmp(*argv, "passive") == 0) VarOpenMode = OPEN_PASSIVE; else - printf("Invalid mode.\n"); + return -1; + return 0; } - return(1); + return -1; } -static char StrChatStr[] = "chat-script"; -static char StrValue[] = "value"; extern int SetIfilter(), SetOfilter(), SetDfilter(), SetAfilter(); struct cmdtab const SetCommands[] = { { "accmap", NULL, SetVariable, LOCAL_AUTH, - "Set accmap value", "hex-value", (void *)VAR_ACCMAP}, + "Set accmap value", "set accmap hex-value", (void *)VAR_ACCMAP}, { "afilter", NULL, SetAfilter, LOCAL_AUTH, - "Set keep Alive filter", "..."}, + "Set keep Alive filter", "set afilter ..."}, { "authkey", "key", SetVariable, LOCAL_AUTH, - "Set authentication key", "key", (void *)VAR_AUTHKEY}, + "Set authentication key", "set authkey|key key", (void *)VAR_AUTHKEY}, { "authname", NULL, SetVariable, LOCAL_AUTH, - "Set authentication name", "name", (void *)VAR_AUTHNAME}, + "Set authentication name", "set authname name", (void *)VAR_AUTHNAME}, { "ctsrts", NULL, SetCtsRts, LOCAL_AUTH, - "Use CTS/RTS modem signalling", "[on|off]"}, - { "debug", NULL, SetDebugLevel, LOCAL_AUTH, - "Set debug level", StrValue}, + "Use CTS/RTS modem signalling", "set ctsrts [on|off]"}, { "device", "line", SetVariable, LOCAL_AUTH, - "Set modem device name", "device-name", (void *)VAR_DEVICE}, + "Set modem device name", "set device|line device-name", (void *)VAR_DEVICE}, { "dfilter", NULL, SetDfilter, LOCAL_AUTH, - "Set demand filter", "..."}, + "Set demand filter", "set dfilter ..."}, { "dial", NULL, SetVariable, LOCAL_AUTH, - "Set dialing script", StrChatStr, (void *)VAR_DIAL}, + "Set dialing script", "set dial chat-script", (void *)VAR_DIAL}, { "escape", NULL, SetEscape, LOCAL_AUTH, - "Set escape characters", "hex-digit ..."}, + "Set escape characters", "set escape hex-digit ..."}, { "ifaddr", NULL, SetInterfaceAddr, LOCAL_AUTH, - "Set destination address", "[src-addr [dst-addr [netmask [trg-addr]]]]"}, + "Set destination address", "set ifaddr [src-addr [dst-addr [netmask [trg-addr]]]]"}, { "ifilter", NULL, SetIfilter, LOCAL_AUTH, - "Set input filter", "..."}, + "Set input filter", "set ifilter ..."}, + { "log", NULL, SetLogLevel, LOCAL_AUTH, + "Set log level", "set log [+|-]value..."}, { "login", NULL, SetVariable, LOCAL_AUTH, - "Set login script", StrChatStr, (void *)VAR_LOGIN }, + "Set login script", "set login chat-script", (void *)VAR_LOGIN }, { "mru", NULL, SetInitialMRU, LOCAL_AUTH, - "Set Initial MRU value", StrValue }, + "Set Initial MRU value", "set mru value" }, { "mtu", NULL, SetPreferredMTU, LOCAL_AUTH, - "Set Preferred MTU value", StrValue }, + "Set Preferred MTU value", "set mtu value" }, { "ofilter", NULL, SetOfilter, LOCAL_AUTH, - "Set output filter", "..." }, + "Set output filter", "set ofilter ..." }, { "openmode", NULL, SetOpenMode, LOCAL_AUTH, - "Set open mode", "[active|passive]"}, + "Set open mode", "set openmode [active|passive]"}, { "parity", NULL, SetModemParity, LOCAL_AUTH, - "Set modem parity", "[odd|even|none]"}, + "Set modem parity", "set parity [odd|even|none]"}, { "phone", NULL, SetVariable, LOCAL_AUTH, - "Set telephone number(s)", "phone1[:phone2[...]]", (void *)VAR_PHONE }, + "Set telephone number(s)", "set phone phone1[:phone2[...]]", (void *)VAR_PHONE }, { "reconnect",NULL, SetReconnect, LOCAL_AUTH, - "Set Reconnect timeout", "value ntries"}, + "Set Reconnect timeout", "set reconnect value ntries"}, { "redial", NULL, SetRedialTimeout, LOCAL_AUTH, - "Set Redial timeout", "value|random[.value|random] [dial_attempts]"}, + "Set Redial timeout", "set redial value|random[.value|random] [dial_attempts]"}, { "speed", NULL, SetModemSpeed, LOCAL_AUTH, - "Set modem speed", "speed"}, + "Set modem speed", "set speed value"}, { "timeout", NULL, SetIdleTimeout, LOCAL_AUTH, - "Set Idle timeout", StrValue}, -#ifdef MSEXT + "Set Idle timeout", "set timeout value"}, +#ifndef NOMSEXT { "ns", NULL, SetNS, LOCAL_AUTH, - "Set NameServer", "pri-addr [sec-addr]"}, + "Set NameServer", "set ns pri-addr [sec-addr]"}, { "nbns", NULL, SetNBNS, LOCAL_AUTH, - "Set NetBIOS NameServer", "pri-addr [sec-addr]"}, -#endif /* MSEXT */ + "Set NetBIOS NameServer", "set nbns pri-addr [sec-addr]"}, +#endif { "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH, - "Display this message", StrNull, (void *)SetCommands}, + "Display this message", "set help|?", (void *)SetCommands}, { NULL, NULL, NULL }, }; @@ -1197,13 +1270,15 @@ struct cmdtab *list; int argc; char **argv; { - int val = 1; - if (argc > 0) - val = FindExec(SetCommands, argc, argv); + FindExec(SetCommands, argc, argv); + else if (VarTerm) + fprintf(VarTerm, "Use `set ?' to get a list or `set ? <var>' for" + " syntax help.\n"); else - printf("Use `set ?' to get a list or `set ? <var>' for syntax help.\n"); - return(val); + LogPrintf(LogWARN, "set command must have arguments\n"); + + return 0; } @@ -1223,10 +1298,10 @@ char **argv; else gateway = GetIpAddr(argv[2]); OsSetRoute(RTM_ADD, dest, gateway, netmask); - } else { - printf("Usage: %s %s\n", list->name, list->syntax); + return 0; } - return(1); + + return -1; } static int @@ -1245,50 +1320,49 @@ char **argv; gateway = GetIpAddr(argv[1]); netmask.s_addr = 0; if (argc == 3) { - if (inet_aton(argv[1], &netmask) == 0) { - printf("bad netmask value.\n"); - return(1); + if (inet_aton(argv[2], &netmask) == 0) { + LogPrintf(LogWARN, "Bad netmask value.\n"); + return -1; } } OsSetRoute(RTM_DELETE, dest, gateway, netmask); - } else if (argc == 1 && strcasecmp(argv[0], "ALL") == 0) { + } else if (argc == 1 && strcasecmp(argv[0], "all") == 0) { DeleteIfRoutes(0); - } else { - printf("Usage: %s %s\n", list->name, list->syntax); - } - return(1); -} + } else + return -1; + return 0; +} static int AliasEnable(); static int AliasOption(); - static struct cmdtab const AliasCommands[] = { { "enable", NULL, AliasEnable, LOCAL_AUTH, - "enable IP aliasing", "[yes|no]"}, + "enable IP aliasing", "alias enable [yes|no]"}, { "port", NULL, AliasRedirectPort, LOCAL_AUTH, - "port redirection", "[proto addr_local:port_local port_alias]"}, + "port redirection", "alias port [proto addr_local:port_local port_alias]"}, { "addr", NULL, AliasRedirectAddr, LOCAL_AUTH, - "static address translation", "[addr_local addr_alias]"}, + "static address translation", "alias addr [addr_local addr_alias]"}, { "deny_incoming", NULL, AliasOption, LOCAL_AUTH, - "stop incoming connections", "[yes|no]", + "stop incoming connections", "alias deny_incoming [yes|no]", (void*)PKT_ALIAS_DENY_INCOMING}, { "log", NULL, AliasOption, LOCAL_AUTH, - "log aliasing link creation", "[yes|no]", + "log aliasing link creation", "alias log [yes|no]", (void*)PKT_ALIAS_LOG}, { "same_ports", NULL, AliasOption, LOCAL_AUTH, - "try to leave port numbers unchanged", "[yes|no]", + "try to leave port numbers unchanged", "alias same_ports [yes|no]", (void*)PKT_ALIAS_SAME_PORTS}, { "use_sockets", NULL, AliasOption, LOCAL_AUTH, - "allocate host sockets", "[yes|no]", + "allocate host sockets", "alias use_sockets [yes|no]", (void*)PKT_ALIAS_USE_SOCKETS }, { "unregistered_only", NULL, AliasOption, LOCAL_AUTH, - "alias unregistered (private) IP address space only", "[yes|no]", + "alias unregistered (private) IP address space only", + "alias unregistered_only [yes|no]", (void*)PKT_ALIAS_UNREGISTERED_ONLY}, { "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH, - "Display this message", StrNull, + "Display this message", "alias help|?", (void *)AliasCommands}, { NULL, NULL, NULL }, }; @@ -1300,16 +1374,16 @@ struct cmdtab *list; int argc; char **argv; { - int val = 1; - if (argc > 0) - val = FindExec(AliasCommands, argc, argv); + FindExec(AliasCommands, argc, argv); + else if (VarTerm) + fprintf(VarTerm, "Use `alias help' to get a list or `alias help <option>'" + " for syntax help.\n"); else - printf("Use `alias help' to get a list or `alias help <option>' for syntax h -elp.\n"); - return(val); -} + LogPrintf(LogWARN, "alias command must have arguments\n"); + return 0; +} static int AliasEnable(list, argc, argv) @@ -1317,21 +1391,26 @@ struct cmdtab *list; int argc; char **argv; { - if (argc == 1 && strcmp(argv[0], "yes") == 0) { - if (!(mode & MODE_ALIAS)) - if (loadAliasHandlers(&VarAliasHandlers) == 0) - mode |= MODE_ALIAS; - else - printf("Cannot load alias library\n"); - } else if (argc == 1 && strcmp(argv[0], "no") == 0) { - if (mode & MODE_ALIAS) { - unloadAliasHandlers(); - mode &= ~MODE_ALIAS; + if (argc == 1) + if (strcasecmp(argv[0], "yes") == 0) { + if (!(mode & MODE_ALIAS)) { + if (loadAliasHandlers(&VarAliasHandlers) == 0) { + mode |= MODE_ALIAS; + return 0; } - } else { - printf("Usage: alias %s %s\n", list->name, list->syntax); + LogPrintf(LogWARN, "Cannot load alias library\n"); + return 1; + } + return 0; + } else if (strcasecmp(argv[0], "no") == 0) { + if (mode & MODE_ALIAS) { + unloadAliasHandlers(); + mode &= ~MODE_ALIAS; + } + return 0; } - return(1); + + return -1; } @@ -1342,18 +1421,20 @@ int argc; char **argv; void* param; { - if (argc == 1 && strcmp(argv[0], "yes") == 0) { - if (mode & MODE_ALIAS) + if (argc == 1) + if (strcasecmp(argv[0], "yes") == 0) { + if (mode & MODE_ALIAS) { VarSetPacketAliasMode((unsigned)param, (unsigned)param); - else - printf("alias not enabled\n"); - } else if (argc == 1 && strcmp(argv[0], "no") == 0) { - if (mode & MODE_ALIAS) + return 0; + } + LogPrintf(LogWARN, "alias not enabled\n"); + } else if (strcmp(argv[0], "no") == 0) { + if (mode & MODE_ALIAS) { VarSetPacketAliasMode(0, (unsigned)param); - else - printf("alias not enabled\n"); - } else { - printf("Usage: alias %s %s\n", list->name, list->syntax); - } - return(1); + return 0; + } + LogPrintf(LogWARN, "alias not enabled\n"); + } + + return -1; } diff --git a/usr.sbin/ppp/defs.h b/usr.sbin/ppp/defs.h index bd5e1ad..a4aefca 100644 --- a/usr.sbin/ppp/defs.h +++ b/usr.sbin/ppp/defs.h @@ -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.13 1997/05/04 02:39:03 ache Exp $ + * $Id: defs.h,v 1.14 1997/05/10 03:39:52 brian Exp $ * * TODO: */ @@ -36,7 +36,6 @@ /* * Check follwiing definitions for your machine envirinment */ -#define LOGFILE "/var/log/ppp.tun%d.log" /* Name of log file */ #ifdef __FreeBSD__ #define MODEM_DEV "/dev/cuaa1" /* name of tty device */ #define BASE_MODEM_DEV "cuaa1" /* name of base tty device */ diff --git a/usr.sbin/ppp/filter.c b/usr.sbin/ppp/filter.c index 4fd4a67..305573e 100644 --- a/usr.sbin/ppp/filter.c +++ b/usr.sbin/ppp/filter.c @@ -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.8 1997/02/22 16:10:12 peter Exp $ + * $Id: filter.c,v 1.9 1997/05/10 01:22:08 brian Exp $ * * TODO: Shoud send ICMP error message when we discard packets. */ @@ -32,7 +32,11 @@ #include <stdlib.h> #include <strings.h> #include "command.h" +#include "mbuf.h" +#include "log.h" #include "filter.h" +#include "loadalias.h" +#include "vars.h" static struct filterent filterdata; @@ -61,9 +65,7 @@ int *pwidth; char *cp, *wp; if (argc < 1) { -#ifdef notdef - printf("address/mask is expected.\n"); -#endif + LogPrintf(LogWARN, "ParseAddr: address/mask is expected.\n"); return(0); } @@ -75,7 +77,7 @@ int *pwidth; if (cp && *cp) { bits = strtol(cp, &wp, 0); if (cp == wp || bits < 0 || bits > 32) { - printf("bad mask width.\n"); + LogPrintf(LogWARN, "ParseAddr: bad mask width.\n"); return(0); } } else { @@ -136,7 +138,8 @@ int proto; port = strtol(service, &cp, 0); if (cp == service) { - printf("%s is not a port name or number.\n", service); + LogPrintf(LogWARN, "ParsePort: %s is not a port name or number.\n", + service); return(0); } return(port); @@ -159,13 +162,13 @@ char **argv; filterdata.opt.srcop = OP_NONE; break; default: - printf("bad icmp syntax.\n"); + LogPrintf(LogWARN, "ParseIcmp: bad icmp syntax.\n"); return(0); case 3: if (STREQ(*argv, "src") && STREQ(argv[1], "eq")) { type = strtol(argv[2], &cp, 0); if (cp == argv[2]) { - printf("type is expected.\n"); + LogPrintf(LogWARN, "ParseIcmp: type is expected.\n"); return(0); } filterdata.opt.srcop = OP_EQ; @@ -207,15 +210,13 @@ int proto; return(1); } if (argc < 3) { -#ifdef notdef - printf("bad udp syntax.\n"); -#endif + LogPrintf(LogWARN, "ParseUdpOrTcp: bad udp/tcp syntax.\n"); return(0); } if (argc >= 3 && STREQ(*argv, "src")) { filterdata.opt.srcop = ParseOp(argv[1]); if (filterdata.opt.srcop == OP_NONE) { - printf("bad operation\n"); + LogPrintf(LogWARN, "ParseUdpOrTcp: bad operation\n"); return(0); } filterdata.opt.srcport = ParsePort(argv[2], proto); @@ -228,7 +229,7 @@ int proto; if (argc >= 3 && STREQ(argv[0], "dst")) { filterdata.opt.dstop = ParseOp(argv[1]); if (filterdata.opt.dstop == OP_NONE) { - printf("bad operation\n"); + LogPrintf(LogWARN, "ParseUdpOrTcp: bad operation\n"); return(0); } filterdata.opt.dstport = ParsePort(argv[2], proto); @@ -243,11 +244,11 @@ int proto; filterdata.opt.estab = 1; return(1); } - printf("estab is expected: %s\n", *argv); + LogPrintf(LogWARN, "ParseUdpOrTcp: estab is expected: %s\n", *argv); return(0); } if (argc > 0) - printf("bad src/dst port syntax: %s\n", *argv); + LogPrintf(LogWARN, "ParseUdpOrTcp: bad src/dst port syntax: %s\n", *argv); return(0); } @@ -266,7 +267,7 @@ struct filterent *ofp; val = strtol(*argv, &wp, 0); if (*argv == wp || val > MAXFILTERS) { - printf("invalid filter number.\n"); + LogPrintf(LogWARN, "Parse: invalid filter number.\n"); return(0); } if (val < 0) { @@ -274,13 +275,13 @@ struct filterent *ofp; ofp->action = A_NONE; ofp++; } - printf("filter cleard.\n"); + LogPrintf(LogWARN, "Parse: filter cleared.\n"); return(1); } ofp += val; if (--argc == 0) { - printf("missing action.\n"); + LogPrintf(LogWARN, "Parse: missing action.\n"); return(0); } argv++; @@ -296,7 +297,7 @@ struct filterent *ofp; ofp->action = A_NONE; return(1); } else { - printf("bad action: %s\n", *argv); + LogPrintf(LogWARN, "Parse: bad action: %s\n", *argv); return(0); } fp->action = action; @@ -328,7 +329,7 @@ struct filterent *ofp; } } } else { - printf("Address/protocol expected.\n"); + LogPrintf(LogWARN, "Parse: Address/protocol expected.\n"); return(0); } } else { @@ -350,16 +351,17 @@ struct filterent *ofp; break; } -#ifdef DEBUG - printf("src: %s/", inet_ntoa(fp->saddr)); - printf("%s ", inet_ntoa(fp->smask)); - printf("dst: %s/", inet_ntoa(fp->daddr)); - printf("%s proto = %d\n", inet_ntoa(fp->dmask), proto); + LogPrintf(LogDEBUG, "Parse: Src: %s", inet_ntoa(fp->saddr)); + LogPrintf(LogDEBUG, "Parse: Src mask: %s ", inet_ntoa(fp->smask)); + LogPrintf(LogDEBUG, "Parse: Dst: %s", inet_ntoa(fp->daddr)); + LogPrintf(LogDEBUG, "Parse: Dst mask: %s\n", inet_ntoa(fp->dmask)); + LogPrintf(LogDEBUG, "Parse: Proto = %d\n", proto); - printf("src: %s (%d)\n", opname[fp->opt.srcop], fp->opt.srcport); - printf("dst: %s (%d)\n", opname[fp->opt.dstop], fp->opt.dstport); - printf("estab: %d\n", fp->opt.estab); -#endif + LogPrintf(LogDEBUG, "Parse: src: %s (%d)\n", opname[fp->opt.srcop], + fp->opt.srcport); + LogPrintf(LogDEBUG, "Parse: dst: %s (%d)\n", opname[fp->opt.dstop], + fp->opt.dstport); + LogPrintf(LogDEBUG, "Parse: estab: %d\n", fp->opt.estab); if (val) *ofp = *fp; @@ -372,12 +374,12 @@ struct cmdtab *list; int argc; char **argv; { - if (argc > 0) + if (argc > 0) { (void) Parse(argc, argv, ifilters); - else - printf("syntax error.\n"); + return 0; + } - return(1); + return -1; } int @@ -386,11 +388,12 @@ struct cmdtab *list; int argc; char **argv; { - if (argc > 0) + if (argc > 0) { (void) Parse(argc, argv, ofilters); - else - printf("syntax error.\n"); - return(1); + return 0; + } + + return -1; } int @@ -399,11 +402,12 @@ struct cmdtab *list; int argc; char **argv; { - if (argc > 0) + if (argc > 0) { (void) Parse(argc, argv, dfilters); - else - printf("syntax error.\n"); - return(1); + return 0; + } + + return -1; } int @@ -412,11 +416,12 @@ struct cmdtab *list; int argc; char **argv; { - if (argc > 0) + if (argc > 0) { (void) Parse(argc, argv, afilters); - else - printf("syntax error.\n"); - return(1); + return 0; + } + + return -1; } static char *protoname[] = { @@ -433,24 +438,28 @@ struct filterent *fp; { int n; + if (!VarTerm) + return; + for (n = 0; n < MAXFILTERS; n++, fp++) { if (fp->action != A_NONE) { - printf("%2d %s", n, actname[fp->action]); - - printf("%s/%d ", inet_ntoa(fp->saddr), fp->swidth); - printf("%s/%d ", inet_ntoa(fp->daddr), fp->dwidth); + fprintf(VarTerm, "%2d %s", n, actname[fp->action]); + fprintf(VarTerm, "%s/%d ", inet_ntoa(fp->saddr), fp->swidth); + fprintf(VarTerm, "%s/%d ", inet_ntoa(fp->daddr), fp->dwidth); if (fp->proto) { - printf("%s", protoname[fp->proto]); + fprintf(VarTerm, "%s", protoname[fp->proto]); if (fp->opt.srcop) - printf(" src %s %d", opname[fp->opt.srcop], fp->opt.srcport); + fprintf(VarTerm, " src %s %d", opname[fp->opt.srcop], + fp->opt.srcport); if (fp->opt.dstop) - printf(" dst %s %d", opname[fp->opt.dstop], fp->opt.dstport); + fprintf(VarTerm, " dst %s %d", opname[fp->opt.dstop], + fp->opt.dstport); if (fp->opt.estab) - printf(" estab"); + fprintf(VarTerm, " estab"); } - printf("\n"); + fprintf(VarTerm, "\n"); } } } @@ -462,7 +471,7 @@ int argc; char **argv; { ShowFilter(ifilters); - return(1); + return 0; } int @@ -472,7 +481,7 @@ int argc; char **argv; { ShowFilter(ofilters); - return(1); + return 0; } int @@ -482,7 +491,7 @@ int argc; char **argv; { ShowFilter(dfilters); - return(1); + return 0; } int @@ -492,5 +501,5 @@ int argc; char **argv; { ShowFilter(afilters); - return(1); + return 0; } diff --git a/usr.sbin/ppp/filter.h b/usr.sbin/ppp/filter.h index 365412b..9653560 100644 --- a/usr.sbin/ppp/filter.h +++ b/usr.sbin/ppp/filter.h @@ -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.6 1997/02/22 16:10:12 peter Exp $ + * $Id: filter.h,v 1.7 1997/05/10 01:22:09 brian Exp $ * * TODO: */ @@ -79,5 +79,5 @@ struct filterent ofilters[MAXFILTERS]; struct filterent dfilters[MAXFILTERS]; struct filterent afilters[MAXFILTERS]; /* keep Alive packet filter */ -extern int ParseAddr __P((int, char **, struct in_addr *, struct in_addr *, int*)); +extern int ParseAddr(int, char **, struct in_addr *, struct in_addr *, int*); #endif /* _FILTER_H_ */ diff --git a/usr.sbin/ppp/fsm.c b/usr.sbin/ppp/fsm.c index 27f5566..ec1b2b7 100644 --- a/usr.sbin/ppp/fsm.c +++ b/usr.sbin/ppp/fsm.c @@ -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.11 1997/06/01 14:37:19 brian Exp $ + * $Id: fsm.c,v 1.12 1997/06/02 00:04:40 brian Exp $ * * TODO: * o Refer loglevel for log output @@ -37,16 +37,14 @@ void FsmTimeout(struct fsm *fp); char const *StateNames[] = { "Initial", "Starting", "Closed", "Stopped", "Closing", "Stopping", - "Req-Sent", "Ack-Rcvd", "Ack-Sent", "Opend", + "Req-Sent", "Ack-Rcvd", "Ack-Sent", "Opened", }; void FsmInit(fp) struct fsm *fp; { -#ifdef DEBUG - logprintf("FsmInit\n"); -#endif + LogPrintf(LogDEBUG, "FsmInit\n"); fp->state = ST_INITIAL; fp->reqid = 1; fp->restart = 1; @@ -58,8 +56,8 @@ NewState(fp, new) struct fsm *fp; int new; { - LogPrintf(LOG_LCP_BIT, "%s: state change %s --> %s\n", - fp->name, StateNames[fp->state], StateNames[new]); + LogPrintf(LogLCP, "State change %s --> %s\n", + StateNames[fp->state], StateNames[new]); fp->state = new; if ((new >= ST_INITIAL && new <= ST_STOPPED) || (new == ST_OPENED)) StopTimer(&fp->FsmTimer); @@ -84,9 +82,7 @@ int count; bcopy(&lh, MBUF_CTOP(bp), sizeof(struct fsmheader)); if (count) bcopy(ptr, MBUF_CTOP(bp) + sizeof(struct fsmheader), count); -#ifdef DEBUG - DumpBp(bp); -#endif + LogDumpBp(LogDEBUG, "FsmOutput", bp); HdlcOutput(PRI_LINK, fp->proto, bp); } @@ -137,8 +133,7 @@ struct fsm *fp; NewState(fp, ST_REQSENT); break; default: - LogPrintf(LOG_LCP_BIT, "%s: Oops, Up at %s\n", - fp->name, StateNames[fp->state]); + LogPrintf(LogLCP, "Oops, Up at %s\n", StateNames[fp->state]); break; } } @@ -215,7 +210,7 @@ void FsmSendTerminateReq(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: SendTerminateReq.\n", fp->name); + LogPrintf(LogLCP, "SendTerminateReq.\n"); FsmOutput(fp, CODE_TERMREQ, fp->reqid++, NULL, 0); (fp->SendTerminateReq)(fp); StartTimer(&fp->FsmTimer); /* Start restart timer */ @@ -229,7 +224,7 @@ struct fsmheader *lhp; u_char *option; int count; { - LogPrintf(LOG_LCP_BIT, "%s: SendConfigAck(%s)\n", fp->name, StateNames[fp->state]); + LogPrintf(LogLCP, "SendConfigAck(%s)\n", StateNames[fp->state]); (fp->DecodeConfig)(option, count, MODE_NOP); FsmOutput(fp, CODE_CONFIGACK, lhp->id, option, count); } @@ -241,7 +236,7 @@ struct fsmheader *lhp; u_char *option; int count; { - LogPrintf(LOG_LCP_BIT, "%s: SendConfigRej(%s)\n", fp->name, StateNames[fp->state]); + LogPrintf(LogLCP, "SendConfigRej(%s)\n", StateNames[fp->state]); (fp->DecodeConfig)(option, count, MODE_NOP); FsmOutput(fp, CODE_CONFIGREJ, lhp->id, option, count); } @@ -253,8 +248,7 @@ struct fsmheader *lhp; u_char *option; int count; { - LogPrintf(LOG_LCP_BIT, "%s: SendConfigNak(%s)\n", - fp->name, StateNames[fp->state]); + LogPrintf(LogLCP, "SendConfigNak(%s)\n", StateNames[fp->state]); (fp->DecodeConfig)(option, count, MODE_NOP); FsmOutput(fp, CODE_CONFIGNAK, lhp->id, option, count); } @@ -328,7 +322,7 @@ struct mbuf *bp; plen = plength(bp); flen = ntohs(lhp->length) - sizeof(*lhp); if (plen < flen) { - logprintf("** plen (%d) < flen (%d)\n", plen, flen); + LogPrintf(LogERROR, "FsmRecvConfigReq: plen (%d) < flen (%d)", plen, flen); pfree(bp); return; } @@ -340,8 +334,7 @@ struct mbuf *bp; switch (fp->state) { case ST_INITIAL: case ST_STARTING: - LogPrintf(LOG_LCP_BIT, "%s: Oops, RCR in %s.\n", - fp->name, StateNames[fp->state]); + LogPrintf(LogLCP, "Oops, RCR in %s.\n", StateNames[fp->state]); pfree(bp); return; case ST_CLOSED: @@ -350,7 +343,7 @@ struct mbuf *bp; return; case ST_CLOSING: case ST_STOPPING: - logprintf("## state = %d\n", fp->state); + LogPrintf(LogERROR, "Got ConfigReq while state = %d\n", fp->state); pfree(bp); return; } @@ -461,8 +454,7 @@ struct mbuf *bp; switch (fp->state) { case ST_INITIAL: case ST_STARTING: - LogPrintf(LOG_LCP_BIT, "%s: Oops, RCN in %s.\n", - fp->name, StateNames[fp->state]); + LogPrintf(LogLCP, "Oops, RCN in %s.\n", StateNames[fp->state]); pfree(bp); return; case ST_CLOSED: @@ -505,8 +497,7 @@ struct mbuf *bp; switch (fp->state) { case ST_INITIAL: case ST_STARTING: - LogPrintf(LOG_LCP_BIT, "%s: Oops, RTR in %s\n", fp->name, - StateNames[fp->state]); + LogPrintf(LogLCP, "Oops, RTR in %s\n", StateNames[fp->state]); break; case ST_CLOSED: case ST_STOPPED: @@ -572,7 +563,7 @@ struct mbuf *bp; pfree(bp); return; } - LogPrintf(LOG_LCP_BIT, "%s: RecvConfigRej.\n", fp->name); + LogPrintf(LogLCP, "RecvConfigRej.\n"); /* * Check and process easy case @@ -580,8 +571,7 @@ struct mbuf *bp; switch (fp->state) { case ST_INITIAL: case ST_STARTING: - LogPrintf(LOG_LCP_BIT, "%s: Oops, RCJ in %s.\n", - fp->name, StateNames[fp->state]); + LogPrintf(LogLCP, "Oops, RCJ in %s.\n", StateNames[fp->state]); pfree(bp); return; case ST_CLOSED: @@ -620,7 +610,7 @@ struct fsm *fp; struct fsmheader *lhp; struct mbuf *bp; { - LogPrintf(LOG_LCP_BIT, "%s: RecvCodeRej\n", fp->name); + LogPrintf(LogLCP, "RecvCodeRej\n"); pfree(bp); } @@ -634,7 +624,7 @@ struct mbuf *bp; sp = (u_short *)MBUF_CTOP(bp); proto = ntohs(*sp); - LogPrintf(LOG_LCP_BIT, "-- Protocol (%04x) was rejected.\n", proto); + LogPrintf(LogLCP, "-- Protocol (%04x) was rejected.\n", proto); switch (proto) { case PROTO_LQR: @@ -669,13 +659,13 @@ struct mbuf *bp; lp = (u_long *)cp; magic = ntohl(*lp); if (magic != LcpInfo.his_magic) { - logprintf("RecvEchoReq: his magic is bad!!\n"); + 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(LOG_LCP_BIT, "%s: SendEchoRep(%s)\n", fp->name, StateNames[fp->state]); + LogPrintf(LogLCP, "SendEchoRep(%s)\n", StateNames[fp->state]); FsmOutput(fp, CODE_ECHOREP, lhp->id, cp, plength(bp)); } pfree(bp); @@ -695,7 +685,7 @@ struct mbuf *bp; * Tolerate echo replies with either magic number */ if (magic != 0 && magic != LcpInfo.his_magic && magic != LcpInfo.want_magic) { - logprintf("RecvEchoRep: his magic is wrong! expect: %x got: %x\n", + LogPrintf(LogERROR, "RecvEchoRep: his magic is wrong! expect: %x got: %x\n", LcpInfo.his_magic, magic); /* * XXX: We should send terminate request. But poor implementation @@ -712,7 +702,7 @@ struct fsm *fp; struct fsmheader *lhp; struct mbuf *bp; { - LogPrintf(LOG_LCP_BIT, "%s: RecvDiscReq\n", fp->name); + LogPrintf(LogLCP, "RecvDiscReq\n"); pfree(bp); } @@ -722,7 +712,7 @@ struct fsm *fp; struct fsmheader *lhp; struct mbuf *bp; { - LogPrintf(LOG_LCP_BIT, "%s: RecvIdent\n", fp->name); + LogPrintf(LogLCP, "RecvIdent\n"); pfree(bp); } @@ -732,7 +722,7 @@ struct fsm *fp; struct fsmheader *lhp; struct mbuf *bp; { - LogPrintf(LOG_LCP_BIT, "%s: RecvTimeRemain\n", fp->name); + LogPrintf(LogLCP, "RecvTimeRemain\n"); pfree(bp); } @@ -742,9 +732,9 @@ struct fsm *fp; struct fsmheader *lhp; struct mbuf *bp; { - LogPrintf(LOG_LCP_BIT, "%s: RecvResetReq\n", fp->name); + LogPrintf(LogLCP, "RecvResetReq\n"); CcpRecvResetReq(fp); - LogPrintf(LOG_LCP_BIT, "%s: SendResetAck\n", fp->name); + LogPrintf(LogLCP, "SendResetAck\n"); FsmOutput(fp, CODE_RESETACK, fp->reqid, NULL, 0); pfree(bp); } @@ -755,7 +745,7 @@ struct fsm *fp; struct fsmheader *lhp; struct mbuf *bp; { - LogPrintf(LOG_LCP_BIT, "%s: RecvResetAck\n", fp->name); + LogPrintf(LogLCP, "RecvResetAck\n"); fp->reqid++; pfree(bp); } @@ -802,13 +792,11 @@ struct mbuf *bp; bp->cnt -= sizeof(struct fsmheader); codep = FsmCodes + lhp->code - 1; - LogPrintf(LOG_LCP_BIT, "%s: Received %s (%d) state = %s (%d)\n", - fp->name, codep->name, lhp->id, StateNames[fp->state], fp->state); -#ifdef DEBUG - LogMemory(); -#endif + LogPrintf(LogLCP, "Received %s (%d) state = %s (%d)\n", + codep->name, lhp->id, StateNames[fp->state], fp->state); + if (LogIsKept(LogDEBUG)) + LogMemory(); (codep->action)(fp, lhp, bp); -#ifdef DEBUG - LogMemory(); -#endif + if (LogIsKept(LogDEBUG)) + LogMemory(); } diff --git a/usr.sbin/ppp/fsm.h b/usr.sbin/ppp/fsm.h index 1709a41..0b55a89 100644 --- a/usr.sbin/ppp/fsm.h +++ b/usr.sbin/ppp/fsm.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: fsm.h,v 1.7 1997/02/22 16:10:14 peter Exp $ * * TODO: */ @@ -26,7 +26,6 @@ #include "defs.h" #include <netinet/in.h> #include "timeout.h" -#include "cdefs.h" /* * State of machine @@ -66,15 +65,15 @@ struct fsm { int reqcode; /* Request code sent */ struct pppTimer FsmTimer; /* Restart Timer */ - void (*LayerUp) __P((struct fsm *)); - void (*LayerDown) __P((struct fsm *)); - void (*LayerStart) __P((struct fsm *)); - void (*LayerFinish) __P((struct fsm *)); - void (*InitRestartCounter) __P((struct fsm *)); - void (*SendConfigReq) __P((struct fsm *)); - void (*SendTerminateReq) __P((struct fsm *)); - void (*SendTerminateAck) __P((struct fsm *)); - void (*DecodeConfig) __P((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 { @@ -100,7 +99,7 @@ struct fsmheader { #define CODE_RESETACK 15 /* Used in CCP */ struct fsmcodedesc { - void (*action) __P((struct fsm *, struct fsmheader *, struct mbuf *)); + void (*action)(struct fsm *, struct fsmheader *, struct mbuf *); char *name; }; @@ -117,20 +116,20 @@ u_char ReqBuff[200]; u_char *ackp, *nakp, *rejp; extern char const *StateNames[]; -extern void FsmInit __P((struct fsm *)); -extern void NewState __P((struct fsm *, int)); -extern void FsmOutput __P((struct fsm *, u_int, u_int, u_char *, int)); -extern void FsmOpen __P((struct fsm *)); -extern void FsmUp __P((struct fsm *)); -extern void FsmDown __P((struct fsm *)); -extern void FsmInput __P((struct fsm *, struct mbuf *)); - -extern void FsmRecvConfigReq __P((struct fsm *, struct fsmheader *, struct mbuf *)); -extern void FsmRecvConfigAck __P((struct fsm *, struct fsmheader *, struct mbuf *)); -extern void FsmRecvConfigNak __P((struct fsm *, struct fsmheader *, struct mbuf *)); -extern void FsmRecvTermReq __P((struct fsm *, struct fsmheader *, struct mbuf *)); -extern void FsmRecvTermAck __P((struct fsm *, struct fsmheader *, struct mbuf *)); -extern void FsmClose __P((struct fsm *fp)); +extern void FsmInit(struct fsm *); +extern void NewState(struct fsm *, int); +extern void FsmOutput(struct fsm *, u_int, u_int, u_char *, int); +extern void FsmOpen(struct fsm *); +extern void FsmUp(struct fsm *); +extern void FsmDown(struct fsm *); +extern void FsmInput(struct fsm *, struct mbuf *); + +extern void FsmRecvConfigReq(struct fsm *, struct fsmheader *, struct mbuf *); +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 struct fsm LcpFsm, IpcpFsm, CcpFsm; diff --git a/usr.sbin/ppp/hdlc.c b/usr.sbin/ppp/hdlc.c index a7a37c8..814981c 100644 --- a/usr.sbin/ppp/hdlc.c +++ b/usr.sbin/ppp/hdlc.c @@ -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.14 1997/05/10 01:22:10 brian Exp $ + * $Id: hdlc.c,v 1.15 1997/05/26 00:43:59 brian Exp $ * * TODO: */ @@ -186,7 +186,7 @@ HdlcOutput(int pri, u_short proto, struct mbuf *bp) *cp++ = fcs >> 8; } - LogDumpBp(LOG_HDLC, "HdlcOutput", mhp); + LogDumpBp(LogHDLC, "HdlcOutput", mhp); for (statp = ProtocolStat; statp->number; statp++) if (statp->number == proto) break; @@ -200,11 +200,10 @@ HdlcOutput(int pri, u_short proto, struct mbuf *bp) void DecodePacket(u_short proto, struct mbuf *bp) { -#ifdef DEBUG - logprintf("proto = %04x\n", proto); -#endif u_char *cp; + LogPrintf(LogDEBUG, "DecodePacket: proto = %04x\n", proto); + switch (proto) { case PROTO_LCP: LcpInput(bp); @@ -239,7 +238,7 @@ DecodePacket(u_short proto, struct mbuf *bp) Pred1Input(bp); break; default: - LogPrintf(LOG_PHASE_BIT, "Unknown protocol 0x%04x\n", proto); + LogPrintf(LogPHASE, "Unknown protocol 0x%04x\n", proto); bp->offset -= 2; bp->cnt += 2; cp = MBUF_CTOP(bp); @@ -260,18 +259,18 @@ ReportProtStatus() statp = ProtocolStat; statp--; cnt = 0; - printf(" Protocol in out Protocol in out\n"); + fprintf(VarTerm, " Protocol in out Protocol in out\n"); do { statp++; - printf(" %-9s: %8lu, %8lu", + fprintf(VarTerm, " %-9s: %8lu, %8lu", statp->name, statp->in_count, statp->out_count); if (++cnt == 2) { - printf("\n"); + fprintf(VarTerm, "\n"); cnt = 0; } } while (statp->number); if (cnt) - printf("\n"); + fprintf(VarTerm, "\n"); return(1); } @@ -280,10 +279,12 @@ ReportHdlcStatus() { struct hdlcstat *hp = &HdlcStat; - printf("HDLC level errors\n\n"); - printf("FCS: %u ADDR: %u COMMAND: %u PROTO: %u\n", - hp->badfcs, hp->badaddr, hp->badcommand, hp->unknownproto); - return(1); + 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); + } + return 0; } static struct hdlcstat laststat; @@ -295,7 +296,7 @@ HdlcErrorCheck() struct hdlcstat *op = &laststat; if (bcmp(hp, op, sizeof(laststat))) { - LogPrintf(LOG_PHASE_BIT, "HDLC errors -> FCS: %u ADDR: %u COMD: %u PROTO: %u\n", + 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); } @@ -309,21 +310,18 @@ HdlcInput(struct mbuf *bp) u_char *cp, addr, ctrl; struct protostat *statp; - LogDumpBp(LOG_HDLC, "HdlcInput:", bp); + LogDumpBp(LogHDLC, "HdlcInput:", bp); if (DEV_IS_SYNC) fcs = GOODFCS; else fcs = HdlcFcs(INITFCS, MBUF_CTOP(bp), bp->cnt); HisLqrSave.SaveInOctets += bp->cnt + 1; -#ifdef DEBUG - logprintf("fcs = %04x (%s)\n", fcs, (fcs == GOODFCS)? "good" : "bad"); -#endif + LogPrintf(LogDEBUG, "HdlcInput: fcs = %04x (%s)\n", + fcs, (fcs == GOODFCS)? "good" : "bad"); if (fcs != GOODFCS) { HisLqrSave.SaveInErrors++; -#ifdef DEBUG - logprintf("Bad FCS\n"); -#endif + LogPrintf(LogDEBUG, "HdlcInput: Bad FCS\n"); HdlcStat.badfcs++; pfree(bp); return; @@ -349,9 +347,7 @@ HdlcInput(struct mbuf *bp) if (addr != HDLC_ADDR) { HisLqrSave.SaveInErrors++; HdlcStat.badaddr++; -#ifdef DEBUG - logprintf("addr %02x\n", *cp); -#endif + LogPrintf(LogDEBUG, "HdlcInput: addr %02x\n", *cp); pfree(bp); return; } @@ -360,9 +356,7 @@ HdlcInput(struct mbuf *bp) if (ctrl != HDLC_UI) { HisLqrSave.SaveInErrors++; HdlcStat.badcommand++; -#ifdef DEBUG - logprintf("command %02x\n", *cp); -#endif + LogPrintf(LogDEBUG, "HdlcInput: %02x\n", *cp); pfree(bp); return; } diff --git a/usr.sbin/ppp/hdlc.h b/usr.sbin/ppp/hdlc.h index c0789b0..4f3ff02 100644 --- a/usr.sbin/ppp/hdlc.h +++ b/usr.sbin/ppp/hdlc.h @@ -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.7 1997/06/01 01:13:02 brian Exp $ + * $Id: hdlc.h,v 1.8 1997/06/01 11:35:02 brian Exp $ * * TODO: */ @@ -60,11 +60,11 @@ unsigned char EscMap[33]; -void HdlcInit __P((void)); -void HdlcErrorCheck __P((void)); -void HdlcInput __P((struct mbuf *bp)); -void HdlcOutput __P((int pri, u_short proto, struct mbuf *bp)); -void AsyncOutput __P((int pri, struct mbuf *bp, int proto)); -u_short HdlcFcs __P((u_short, u_char *, int)); -void DecodePacket __P((u_short, struct mbuf *)); +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); +u_short HdlcFcs(u_short, u_char *, int); +void DecodePacket(u_short, struct mbuf *); #endif diff --git a/usr.sbin/ppp/ip.c b/usr.sbin/ppp/ip.c index 72b7a11..baa7bca 100644 --- a/usr.sbin/ppp/ip.c +++ b/usr.sbin/ppp/ip.c @@ -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.19 1997/05/24 17:32:35 brian Exp $ + * $Id: ip.c,v 1.20 1997/05/26 00:44:01 brian Exp $ * * TODO: * o Return ICMP message for filterd packet @@ -36,6 +36,8 @@ #include "loadalias.h" #include "vars.h" #include "filter.h" +#include "mbuf.h" +#include "log.h" extern void SendPppFrame(); extern void LcpClose(); @@ -44,7 +46,7 @@ static struct pppTimer IdleTimer; static void IdleTimeout() { - LogPrintf(LOG_PHASE_BIT, "Idle timer expired.\n"); + LogPrintf(LogPHASE, "Idle timer expired.\n"); reconnect(RECON_FALSE); LcpClose(); } @@ -66,6 +68,13 @@ StartIdleTimer() } void +UpdateIdleTimer() +{ + if (IdleTimer.state == TIMER_RUNNING) + StartIdleTimer(); +} + +void StopIdleTimer() { StopTimer(&IdleTimer); @@ -140,9 +149,7 @@ int direction; (ntohs(pip->ip_off) & IP_OFFMASK) != 0) { return(A_PERMIT); } -#ifdef DEBUG -logprintf("rule = %d\n", n); -#endif + 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) { @@ -163,25 +170,23 @@ logprintf("rule = %d\n", n); cproto = P_TCP; th = (struct tcphdr *)ptop; sport = ntohs(th->th_sport); dport = ntohs(th->th_dport); estab = (th->th_flags & TH_ACK); -#ifdef DEBUG -if (estab == 0) -logprintf("flag = %02x, sport = %d, dport = %d\n", th->th_flags, sport, dport); -#endif + 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 */ } gotinfo = 1; -#ifdef DEBUG -logprintf("dir = %d, proto = %d, srcop = %d, dstop = %d, estab = %d\n", -direction, cproto, fp->opt.srcop, fp->opt.dstop, estab); -#endif + LogPrintf(LogDEBUG, "dir = %d, proto = %d, srcop = %d," + " dstop = %d, estab = %d\n", direction, cproto, + fp->opt.srcop, fp->opt.dstop, estab); } -#ifdef DEBUG - logprintf("check0: rule = %d, proto = %d, sport = %d, dport = %d\n", - n, cproto, sport, dport); - logprintf("check0: action = %d\n", fp->action); -#endif + + LogPrintf(LogDEBUG, "check0: rule = %d, proto = %d, sport = %d," + " 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)) @@ -195,9 +200,7 @@ direction, cproto, fp->opt.srcop, fp->opt.dstop, estab); } } else { /* Address is mached. Make a decision. */ -#ifdef DEBUG - logprintf("check1: action = %d\n", fp->action); -#endif + LogPrintf(LogDEBUG, "check1: action = %d\n", fp->action); return(fp->action); } } @@ -245,11 +248,11 @@ int direction; int logit; int pri = PRI_NORMAL; - logit = (loglevel & (1 << LOG_TCPIP)); + logit = LogIsKept(LogTCPIP); pip = (struct ip *)cp; - if (logit) logprintf("%s ", Direction[direction]); + if (logit) LogPrintf(LogTCPIP, "%s ", Direction[direction]); ptop = (cp + (pip->ip_hl << 2)); @@ -257,15 +260,15 @@ int direction; case IPPROTO_ICMP: if (logit) { icmph = (struct icmp *)ptop; - logprintf("ICMP: %s:%d ---> ", inet_ntoa(pip->ip_src), icmph->icmp_type); - logprintf("%s:%d\n", inet_ntoa(pip->ip_dst), icmph->icmp_type); + LogPrintf(LogTCPIP, "ICMP: %s:%d ---> ", inet_ntoa(pip->ip_src), icmph->icmp_type); + LogPrintf(LogTCPIP, "%s:%d\n", inet_ntoa(pip->ip_dst), icmph->icmp_type); } break; case IPPROTO_UDP: if (logit) { uh = (struct udphdr *)ptop; - logprintf("UDP: %s:%d ---> ", inet_ntoa(pip->ip_src), ntohs(uh->uh_sport)); - logprintf("%s:%d\n", inet_ntoa(pip->ip_dst), ntohs(uh->uh_dport)); + LogPrintf(LogTCPIP, "UDP: %s:%d ---> ", inet_ntoa(pip->ip_src), ntohs(uh->uh_sport)); + LogPrintf(LogTCPIP, "%s:%d\n", inet_ntoa(pip->ip_dst), ntohs(uh->uh_dport)); } break; case IPPROTO_TCP: @@ -279,15 +282,15 @@ int direction; if (logit) { len = ntohs(pip->ip_len) - (pip->ip_hl << 2) - (th->th_off << 2); - logprintf("TCP: %s:%d ---> ", inet_ntoa(pip->ip_src), ntohs(th->th_sport)); - logprintf("%s:%d", inet_ntoa(pip->ip_dst), ntohs(th->th_dport)); + LogPrintf(LogTCPIP, "TCP: %s:%d ---> ", inet_ntoa(pip->ip_src), ntohs(th->th_sport)); + LogPrintf(LogTCPIP, "%s:%d", inet_ntoa(pip->ip_dst), ntohs(th->th_dport)); n = 0; for (mask = TH_FIN; mask != 0x40; mask <<= 1) { if (th->th_flags & mask) - logprintf(" %s", TcpFlags[n]); + LogPrintf(LogTCPIP, " %s", TcpFlags[n]); n++; } - logprintf(" seq:%x ack:%x (%d/%d)\n", + LogPrintf(LogTCPIP, " seq:%x ack:%x (%d/%d)\n", ntohl(th->th_seq), ntohl(th->th_ack), len, nb); if ((th->th_flags & TH_SYN) && nb > 40) { u_short *sp; @@ -295,16 +298,14 @@ int direction; ptop += 20; sp = (u_short *)ptop; if (ntohs(sp[0]) == 0x0204) - logprintf(" MSS = %d\n", ntohs(sp[1])); + LogPrintf(LogTCPIP, " MSS = %d\n", ntohs(sp[1])); } } break; } if ((FilterCheck(pip, direction) & A_DENY)) { -#ifdef DEBUG - logprintf("blocked.\n"); -#endif + LogPrintf(LogDEBUG, "blocked.\n"); if (direction == 0) IcmpError(pip, pri); return(-1); } else { @@ -328,7 +329,7 @@ struct mbuf *bp; /* IN: Pointer to IP pakcet */ cp = tunbuff; nb = 0; - for (wp = bp; wp; wp = wp->next) { /* Copy to continuois 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; @@ -342,7 +343,7 @@ struct mbuf *bp; /* IN: Pointer to IP pakcet */ nb = ntohs(((struct ip *) tunbuff)->ip_len); if (nb > MAX_MRU) { - fprintf(stderr, "Problem with IP header length\n"); + LogPrintf(LogERROR, "IpInput: Problem with IP header length\n"); pfree(bp); return; } @@ -359,7 +360,7 @@ struct mbuf *bp; /* IN: Pointer to IP pakcet */ nb = ntohs(((struct ip *) tunbuff)->ip_len); nw = write(tun_out, tunbuff, nb); if (nw != nb) - fprintf(stderr, "wrote %d, got %d\r\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) { @@ -367,7 +368,7 @@ struct mbuf *bp; /* IN: Pointer to IP pakcet */ nb = ntohs(((struct ip *) fptr)->ip_len); nw = write(tun_out, fptr, nb); if (nw != nb) - fprintf(stderr, "wrote %d, got %d\r\n", nb, nw); + LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw); free(fptr); } } @@ -375,9 +376,8 @@ struct mbuf *bp; /* IN: Pointer to IP pakcet */ else if (iresult == PKT_ALIAS_UNRESOLVED_FRAGMENT) { nb = ntohs(((struct ip *) tunbuff)->ip_len); fptr = malloc(nb); - if (fptr == NULL) { - fprintf(stderr, "Cannot allocate memory for fragment\n"); - } + if (fptr == NULL) + LogPrintf(LogALERT, "IpInput: Cannot allocate memory for fragment\n"); else { memcpy(fptr, tunbuff, nb); VarSaveFragmentPtr(fptr); @@ -395,7 +395,7 @@ struct mbuf *bp; /* IN: Pointer to IP pakcet */ ipInOctets += nb; nw = write(tun_out, tunbuff, nb); if (nw != nb) - fprintf(stderr, "wrote %d, got %d\r\n", nb, nw); + LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw); } pfree(bp); diff --git a/usr.sbin/ppp/ip.h b/usr.sbin/ppp/ip.h index 710fffa..ab4b4a0 100644 --- a/usr.sbin/ppp/ip.h +++ b/usr.sbin/ppp/ip.h @@ -17,13 +17,13 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: ip.h,v 1.3 1997/02/22 16:10:19 peter Exp $ * */ #ifndef _IP_H_ #define _IP_H_ -extern void IpStartOutput __P((void)); -extern int PacketCheck __P((char *, int , int)); -extern void IpEnqueue __P((int, char *, int)); +extern void IpStartOutput(void); +extern int PacketCheck(char *, int , int); +extern void IpEnqueue(int, char *, int); #endif diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c index 2df6e87..da19707 100644 --- a/usr.sbin/ppp/ipcp.c +++ b/usr.sbin/ppp/ipcp.c @@ -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.19 1997/05/24 17:32:35 brian Exp $ + * $Id: ipcp.c,v 1.20 1997/05/26 00:44:01 brian Exp $ * * TODO: * o More RFC1772 backwoard compatibility @@ -44,19 +44,19 @@ extern struct in_addr ifnetmask; struct ipcpstate IpcpInfo; struct in_range DefMyAddress, DefHisAddress, DefTriggerAddress; -#ifdef MSEXT +#ifndef NOMSEXT struct in_addr ns_entries[2], nbns_entries[2]; -#endif /* MSEXT */ - -static void IpcpSendConfigReq __P((struct fsm *)); -static void IpcpSendTerminateAck __P((struct fsm *)); -static void IpcpSendTerminateReq __P((struct fsm *)); -static void IpcpDecodeConfig __P((u_char *, int, int)); -static void IpcpLayerStart __P((struct fsm *)); -static void IpcpLayerFinish __P((struct fsm *)); -static void IpcpLayerUp __P((struct fsm *)); -static void IpcpLayerDown __P((struct fsm *)); -static void IpcpInitRestartCounter __P((struct fsm *)); +#endif + +static void IpcpSendConfigReq(struct fsm *); +static void IpcpSendTerminateAck(struct fsm *); +static void IpcpSendTerminateReq(struct fsm *); +static void IpcpDecodeConfig(u_char *, int, int); +static void IpcpLayerStart(struct fsm *); +static void IpcpLayerFinish(struct fsm *); +static void IpcpLayerUp(struct fsm *); +static void IpcpLayerDown(struct fsm *); +static void IpcpInitRestartCounter(struct fsm *); struct pppTimer IpcpReportTimer; @@ -124,20 +124,23 @@ ReportIpcpStatus() struct ipcpstate *icp = &IpcpInfo; struct fsm *fp = &IpcpFsm; - printf("%s [%s]\n", fp->name, StateNames[fp->state]); - printf(" his side: %s, %lx\n", + if (!VarTerm) + 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); - printf(" my side: %s, %lx\n", + fprintf(VarTerm, " my side: %s, %lx\n", inet_ntoa(icp->want_ipaddr), icp->want_compproto); - printf("connected: %d secs, idle: %d secs\n\n", ipConnectSecs, ipIdleSecs); - printf("Defaults:\n"); - printf(" My Address: %s/%d\n", + 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); - printf(" His Address: %s/%d\n", + fprintf(VarTerm, " His Address: %s/%d\n", inet_ntoa(DefHisAddress.ipaddr), DefHisAddress.width); - printf(" Negotiation: %s/%d\n", + fprintf(VarTerm, " Negotiation: %s/%d\n", inet_ntoa(DefTriggerAddress.ipaddr), DefTriggerAddress.width); - return 1; + + return 0; } void @@ -205,7 +208,7 @@ struct fsm *fp; struct ipcpstate *icp = &IpcpInfo; cp = ReqBuff; - LogPrintf(LOG_LCP_BIT, "%s: SendConfigReq\n", fp->name); + LogPrintf(LogLCP, "IpcpSendConfigReq\n"); if (!DEV_IS_SYNC || !REJECTED(icp, TY_IPADDR)) PutConfValue(&cp, cftypes, TY_IPADDR, 6, ntohl(icp->want_ipaddr.s_addr)); if (icp->want_compproto && !REJECTED(icp, TY_COMPPROTO)) { @@ -228,7 +231,7 @@ static void IpcpSendTerminateAck(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, " %s: SendTerminateAck\n", fp->name); + LogPrintf(LogLCP, "IpcpSendTerminateAck\n"); FsmOutput(fp, CODE_TERMACK, fp->reqid++, NULL, 0); } @@ -236,14 +239,14 @@ static void IpcpLayerStart(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: LayerStart.\n", fp->name); + LogPrintf(LogLCP, "IpcpLayerStart.\n"); } static void IpcpLayerFinish(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: LayerFinish.\n", fp->name); + LogPrintf(LogLCP, "IpcpLayerFinish.\n"); reconnect(RECON_FALSE); LcpClose(); NewPhase(PHASE_TERMINATE); @@ -253,7 +256,7 @@ static void IpcpLayerDown(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: LayerDown.\n", fp->name); + LogPrintf(LogLCP, "IpcpLayerDown.\n"); StopTimer(&IpcpReportTimer); } @@ -266,17 +269,16 @@ struct fsm *fp; { char tbuff[100]; -#ifdef VERBOSE - fprintf(stderr, "%s: LayerUp(%d).\r\n", fp->name, fp->state); -#endif Prompt(); - LogPrintf(LOG_LCP_BIT, "%s: LayerUp.\n", fp->name); + LogPrintf(LogLCP, "IpcpLayerUp(%d).\n", fp->state); snprintf(tbuff, sizeof(tbuff), "myaddr = %s ", inet_ntoa(IpcpInfo.want_ipaddr)); - LogPrintf(LOG_LCP_BIT|LOG_LINK_BIT, " %s hisaddr = %s\n", tbuff, inet_ntoa(IpcpInfo.his_ipaddr)); + LogPrintf(LogIsKept(LogLCP) ? LogLCP : LogLINK, " %s hisaddr = %s\n", + tbuff, inet_ntoa(IpcpInfo.his_ipaddr)); if (OsSetIpaddress(IpcpInfo.want_ipaddr, IpcpInfo.his_ipaddr, ifnetmask) < 0) { - printf("unable to set ip address\n"); - return; + if (VarTerm) + LogPrintf(LogERROR, "IpcpLayerUp: unable to set ip address\n"); + return; } OsLinkup(); IpcpStartReport(); @@ -289,7 +291,7 @@ void IpcpUp() { FsmUp(&IpcpFsm); - LogPrintf(LOG_LCP_BIT, "IPCP Up event!!\n"); + LogPrintf(LogLCP, "IPCP Up event!!\n"); } void @@ -303,13 +305,11 @@ AcceptableAddr(prange, ipaddr) struct in_range *prange; struct in_addr ipaddr; { -#ifdef DEBUG - logprintf("requested = %x ", htonl(ipaddr.s_addr)); - logprintf("range = %x", htonl(prange->ipaddr.s_addr)); - logprintf("/%x\n", htonl(prange->mask.s_addr)); - logprintf("%x, %x\n", htonl(prange->ipaddr.s_addr & prange->mask.s_addr), - htonl(ipaddr.s_addr & prange->mask.s_addr)); -#endif + 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)); return (prange->ipaddr.s_addr & prange->mask.s_addr) == (ipaddr.s_addr & prange->mask.s_addr) && ipaddr.s_addr; } @@ -345,7 +345,7 @@ int mode; case TY_IPADDR: /* RFC1332 */ lp = (u_long *)(cp + 2); ipaddr.s_addr = *lp; - LogPrintf(LOG_LCP_BIT, "%s %s\n", tbuff, inet_ntoa(ipaddr)); + LogPrintf(LogLCP, "%s %s\n", tbuff, inet_ntoa(ipaddr)); switch (mode) { case MODE_REQ: @@ -370,7 +370,7 @@ int mode; * Use address suggested by peer. */ snprintf(tbuff2, sizeof(tbuff2), "%s changing address: %s ", tbuff, inet_ntoa(IpcpInfo.want_ipaddr)); - LogPrintf(LOG_LCP_BIT, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr)); + LogPrintf(LogLCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr)); IpcpInfo.want_ipaddr = ipaddr; } break; @@ -382,7 +382,7 @@ int mode; case TY_COMPPROTO: lp = (u_long *)(cp + 2); compproto = htonl(*lp); - LogPrintf(LOG_LCP_BIT, "%s %08x\n", tbuff, compproto); + LogPrintf(LogLCP, "%s %08x\n", tbuff, compproto); switch (mode) { case MODE_REQ: @@ -394,7 +394,7 @@ int mode; switch (length) { case 4: /* RFC1172 */ if (ntohs(pcomp->proto) == PROTO_VJCOMP) { - logprintf("** Peer is speaking RFC1172 compression protocol **\n"); + LogPrintf(LogWARN, "Peer is speaking RFC1172 compression protocol !n"); IpcpInfo.heis1172 = 1; IpcpInfo.his_compproto = compproto; bcopy(cp, ackp, length); @@ -430,7 +430,7 @@ int mode; } break; case MODE_NAK: - LogPrintf(LOG_LCP_BIT, "%s changing compproto: %08x --> %08x\n", + LogPrintf(LogLCP, "%s changing compproto: %08x --> %08x\n", tbuff, IpcpInfo.want_compproto, compproto); IpcpInfo.want_compproto = compproto; break; @@ -444,8 +444,8 @@ int mode; ipaddr.s_addr = *lp; lp = (u_long *)(cp + 6); dstipaddr.s_addr = *lp; - LogPrintf(LOG_LCP_BIT, "%s %s, ", tbuff, inet_ntoa(ipaddr)); - LogPrintf(LOG_LCP_BIT, "%s\n", inet_ntoa(dstipaddr)); + LogPrintf(LogLCP, "%s %s, ", tbuff, inet_ntoa(ipaddr)); + LogPrintf(LogLCP, "%s\n", inet_ntoa(dstipaddr)); switch (mode) { case MODE_REQ: @@ -455,9 +455,9 @@ int mode; ackp += length; break; case MODE_NAK: - LogPrintf(LOG_LCP_BIT, "%s changing address: %s ", + LogPrintf(LogLCP, "%s changing address: %s ", tbuff, inet_ntoa(IpcpInfo.want_ipaddr)); - LogPrintf(LOG_LCP_BIT, "--> %s\n", inet_ntoa(ipaddr)); + LogPrintf(LogLCP, "--> %s\n", inet_ntoa(ipaddr)); IpcpInfo.want_ipaddr = ipaddr; IpcpInfo.his_ipaddr = dstipaddr; break; @@ -471,11 +471,11 @@ int mode; * MS extensions for MS's PPP */ -#ifdef MSEXT +#ifndef NOMSEXT case TY_PRIMARY_DNS: /* MS PPP DNS negotiation hack */ case TY_SECONDARY_DNS: if( !Enabled( ConfMSExt ) ) { - LogPrintf( LOG_LCP, "MS NS req - rejected - msext disabled\n" ); + LogPrintf(LogLCP, "MS NS req - rejected - msext disabled\n"); IpcpInfo.my_reject |= ( 1 << type ); bcopy(cp, rejp, length); rejp += length; @@ -493,7 +493,7 @@ int mode; so well tell 'em how it is */ bcopy( cp, nakp, 2 ); /* copy first two (type/length) */ - LogPrintf( LOG_LCP, "MS NS req %d:%s->%s - nak\n", + LogPrintf( LogLCP, "MS NS req %d:%s->%s - nak\n", type, inet_ntoa( dnsstuff ), inet_ntoa( ms_info_req )); @@ -505,17 +505,17 @@ int mode; Otherwise they have it right (this time) so we send a ack packet back confirming it... end of story */ - LogPrintf( LOG_LCP, "MS NS req %d:%s ok - ack\n", + LogPrintf( LogLCP, "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(LOG_LCP, "MS NS req %d - NAK??\n", type ); + LogPrintf(LogLCP, "MS NS req %d - NAK??\n", type ); break; case MODE_REJ: /* confused?? me to :) */ - LogPrintf(LOG_LCP, "MS NS req %d - REJ??\n", type ); + LogPrintf(LogLCP, "MS NS req %d - REJ??\n", type ); break; } break; @@ -523,7 +523,7 @@ int mode; case TY_PRIMARY_NBNS: /* MS PPP NetBIOS nameserver hack */ case TY_SECONDARY_NBNS: if( !Enabled( ConfMSExt ) ) { - LogPrintf( LOG_LCP, "MS NBNS req - rejected - msext disabled\n" ); + LogPrintf( LogLCP, "MS NBNS req - rejected - msext disabled\n" ); IpcpInfo.my_reject |= ( 1 << type ); bcopy( cp, rejp, length ); rejp += length; @@ -538,29 +538,29 @@ int mode; { bcopy( cp, nakp, 2 ); bcopy( &ms_info_req.s_addr , nakp+2, length ); - LogPrintf( LOG_LCP, "MS NBNS req %d:%s->%s - nak\n", + LogPrintf( LogLCP, "MS NBNS req %d:%s->%s - nak\n", type, inet_ntoa( dnsstuff ), inet_ntoa( ms_info_req )); nakp += length; break; } - LogPrintf( LOG_LCP, "MS NBNS req %d:%s ok - ack\n", + LogPrintf( LogLCP, "MS NBNS req %d:%s ok - ack\n", type, inet_ntoa( ms_info_req )); bcopy( cp, ackp, length ); ackp += length; break; case MODE_NAK: - LogPrintf( LOG_LCP, "MS NBNS req %d - NAK??\n", type ); + LogPrintf( LogLCP, "MS NBNS req %d - NAK??\n", type ); break; case MODE_REJ: - LogPrintf( LOG_LCP, "MS NBNS req %d - REJ??\n", type ); + LogPrintf( LogLCP, "MS NBNS req %d - REJ??\n", type ); break; } break; -#endif /* MSEXT */ +#endif default: IpcpInfo.my_reject |= (1 << type); diff --git a/usr.sbin/ppp/ipcp.h b/usr.sbin/ppp/ipcp.h index ab42143..864d974 100644 --- a/usr.sbin/ppp/ipcp.h +++ b/usr.sbin/ppp/ipcp.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: ipcp.h,v 1.6 1997/02/22 16:10:22 peter Exp $ * * TODO: */ @@ -31,14 +31,12 @@ /* MS PPP NameServer and NetBIOS NameServer stuff */ -#ifdef MSEXT - +#ifndef NOMSEXT #define TY_PRIMARY_DNS 129 #define TY_PRIMARY_NBNS 130 #define TY_SECONDARY_DNS 131 #define TY_SECONDARY_NBNS 132 - -#endif /* MSEXT */ +#endif struct ipcpstate { struct in_addr his_ipaddr; /* IP address he is willing to use */ @@ -69,11 +67,11 @@ extern struct in_range DefMyAddress; extern struct in_range DefHisAddress; extern struct in_range DefTriggerAddress; -#ifdef MSEXT +#ifndef NOMSEXT extern struct in_addr ns_entries[2]; extern struct in_addr nbns_entries[2]; -#endif /* MSEXT */ +#endif -extern void IpcpInit __P((void)); -extern void IpcpDefAddress __P((void)); +extern void IpcpInit(void); +extern void IpcpDefAddress(void); #endif diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c index 8134329..522dbbee 100644 --- a/usr.sbin/ppp/lcp.c +++ b/usr.sbin/ppp/lcp.c @@ -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.21 1997/05/26 00:44:03 brian Exp $ + * $Id: lcp.c,v 1.22 1997/06/01 03:43:22 brian Exp $ * * TODO: * o Validate magic number received from peer. @@ -52,15 +52,15 @@ extern int randinit; struct lcpstate LcpInfo; -static void LcpSendConfigReq __P((struct fsm *)); -static void LcpSendTerminateReq __P((struct fsm *fp)); -static void LcpSendTerminateAck __P((struct fsm *fp)); -static void LcpDecodeConfig __P((u_char *cp, int flen,int mode)); -static void LcpInitRestartCounter __P((struct fsm *)); -static void LcpLayerUp __P((struct fsm *)); -static void LcpLayerDown __P((struct fsm *)); -static void LcpLayerStart __P((struct fsm *)); -static void LcpLayerFinish __P((struct fsm *)); +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 LcpInitRestartCounter(struct fsm *); +static void LcpLayerUp(struct fsm *); +static void LcpLayerDown(struct fsm *); +static void LcpLayerStart(struct fsm *); +static void LcpLayerFinish(struct fsm *); extern int ModemSpeed(); @@ -106,13 +106,13 @@ int new; struct lcpstate *lcp = &LcpInfo; phase = new; - LogPrintf(LOG_PHASE_BIT, "Phase: %s\n", PhaseNames[phase]); + LogPrintf(LogPHASE, "NewPhase: %s\n", PhaseNames[phase]); switch (phase) { case PHASE_AUTHENTICATE: lcp->auth_ineed = lcp->want_auth; lcp->auth_iwait = lcp->his_auth; if (lcp->his_auth || lcp->want_auth) { - LogPrintf(LOG_PHASE_BIT, " his = %x, mine = %x\n", lcp->his_auth, lcp->want_auth); + LogPrintf(LogPHASE, " his = %x, mine = %x\n", lcp->his_auth, lcp->want_auth); if (lcp->his_auth == PROTO_PAP) StartAuthChallenge(&AuthPapInfo); if (lcp->want_auth == PROTO_CHAP) @@ -138,12 +138,12 @@ int new; static void LcpReportTime() { -#ifdef VERBOSE - time_t t; + if (LogIsKept(LogDEBUG)) { + time_t t; - time(&t); - logprintf("%s", ctime(&t)); -#endif + time(&t); + LogPrintf(LogDEBUG, "LcpReportTime: %s", ctime(&t)); + } StopTimer(&LcpReportTimer); LcpReportTimer.state = TIMER_STOPPED; StartTimer(&LcpReportTimer); @@ -156,20 +156,23 @@ ReportLcpStatus() struct lcpstate *lcp = &LcpInfo; struct fsm *fp = &LcpFsm; - printf("%s [%s]\n", fp->name, StateNames[fp->state]); - printf( + if (!VarTerm) + 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); - printf( + 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); - printf("\nDefaults: MRU = %ld, ACCMAP = %08x\t", VarMRU, VarAccmap); - printf("Open Mode: %s\n", (VarOpenMode == OPEN_ACTIVE)? "active" : "passive"); - return(1); + fprintf(VarTerm, "\nDefaults: MRU = %ld, ACCMAP = %08x\t", VarMRU, VarAccmap); + fprintf(VarTerm, "Open Mode: %s\n", (VarOpenMode == OPEN_ACTIVE)? "active" : "passive"); + return 0; } /* @@ -236,15 +239,15 @@ u_long val; if (len == 6) { if (type == TY_IPADDR) { ina.s_addr = htonl(val); - LogPrintf(LOG_LCP_BIT, " %s [%d] %s\n", + LogPrintf(LogLCP, " %s [%d] %s\n", types[type], len, inet_ntoa(ina)); } else { - LogPrintf(LOG_LCP_BIT, " %s [%d] %08x\n", types[type], len, val); + LogPrintf(LogLCP, " %s [%d] %08x\n", types[type], len, val); } *cp++ = (val >> 24) & 0377; *cp++ = (val >> 16) & 0377; } else - LogPrintf(LOG_LCP_BIT, " %s [%d] %d\n", types[type], len, val); + LogPrintf(LogLCP, " %s [%d] %d\n", types[type], len, val); *cp++ = (val >> 8) & 0377; *cp++ = val & 0377; *cpp = cp; @@ -258,16 +261,16 @@ struct fsm *fp; struct lcpstate *lcp = &LcpInfo; struct lqrreq *req; - LogPrintf(LOG_LCP_BIT, "%s: SendConfigReq\n", fp->name); + LogPrintf(LogLCP, "LcpSendConfigReq\n"); cp = ReqBuff; if (!DEV_IS_SYNC) { if (lcp->want_acfcomp && !REJECTED(lcp, TY_ACFCOMP)) { *cp++ = TY_ACFCOMP; *cp++ = 2; - LogPrintf(LOG_LCP_BIT, " %s\n", cftypes[TY_ACFCOMP]); + LogPrintf(LogLCP, " %s\n", cftypes[TY_ACFCOMP]); } if (lcp->want_protocomp && !REJECTED(lcp, TY_PROTOCOMP)) { *cp++ = TY_PROTOCOMP; *cp++ = 2; - LogPrintf(LOG_LCP_BIT, " %s\n", cftypes[TY_PROTOCOMP]); + LogPrintf(LogLCP, " %s\n", cftypes[TY_PROTOCOMP]); } if (!REJECTED(lcp, TY_ACCMAP)) PutConfValue(&cp, cftypes, TY_ACCMAP, 6, lcp->want_accmap); @@ -282,7 +285,7 @@ struct fsm *fp; req->proto = htons(PROTO_LQR); req->period = htonl(lcp->want_lqrperiod); cp += sizeof(struct lqrreq); - LogPrintf(LOG_LCP_BIT, " %s (%d)\n", cftypes[TY_QUALPROTO], lcp->want_lqrperiod); + LogPrintf(LogLCP, " %s (%d)\n", cftypes[TY_QUALPROTO], lcp->want_lqrperiod); } switch (lcp->want_auth) { case PROTO_PAP: @@ -303,7 +306,7 @@ int count; { struct fsm *fp = &LcpFsm; - LogPrintf(LOG_LCP_BIT, "%s: SendProtoRej\n", fp->name); + LogPrintf(LogLCP, "LcpSendProtoRej\n"); FsmOutput(fp, CODE_PROTOREJ, fp->reqid, option, count); } @@ -318,7 +321,7 @@ static void LcpSendTerminateAck(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: SendTerminateAck.\n", fp->name); + LogPrintf(LogLCP, "LcpSendTerminateAck.\n"); FsmOutput(fp, CODE_TERMACK, fp->reqid++, NULL, 0); } @@ -326,7 +329,7 @@ static void LcpLayerStart(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: LayerStart\n", fp->name); + LogPrintf(LogLCP, "LcpLayerStart\n"); NewPhase(PHASE_ESTABLISH); } @@ -345,26 +348,19 @@ static void LcpLayerFinish(fp) struct fsm *fp; { -#ifdef VERBOSE - fprintf(stderr, "%s: LayerFinish\r\n", fp->name); -#endif - Prompt(); - LogPrintf(LOG_LCP_BIT, "%s: LayerFinish\n", fp->name); -#ifdef notdef - OsCloseLink(0); -#else + LogPrintf(LogLCP, "LcpLayerFinish\n"); OsCloseLink(1); -#endif NewPhase(PHASE_DEAD); StopAllTimers(); (void)OsInterfaceDown(0); + Prompt(); } static void LcpLayerUp(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: LayerUp\n", fp->name); + LogPrintf(LogLCP, "LcpLayerUp\n"); OsSetInterfaceParams(23, LcpInfo.his_mru, ModemSpeed()); SetLinkParams(&LcpInfo); @@ -382,11 +378,10 @@ static void LcpLayerDown(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: LayerDown\n", fp->name); + LogPrintf(LogLCP, "LcpLayerDown\n"); StopAllTimers(); OsLinkdown(); NewPhase(PHASE_TERMINATE); - Prompt(); } void @@ -448,7 +443,7 @@ int mode; case TY_MRU: sp = (u_short *)(cp + 2); mru = htons(*sp); - LogPrintf(LOG_LCP_BIT, " %s %d\n", request, mru); + LogPrintf(LogLCP, " %s %d\n", request, mru); switch (mode) { case MODE_REQ: @@ -475,7 +470,7 @@ int mode; case TY_ACCMAP: lp = (u_long *)(cp + 2); accmap = htonl(*lp); - LogPrintf(LOG_LCP_BIT, " %s %08x\n", request, accmap); + LogPrintf(LogLCP, " %s %08x\n", request, accmap); switch (mode) { case MODE_REQ: @@ -493,14 +488,14 @@ int mode; case TY_AUTHPROTO: sp = (u_short *)(cp + 2); proto = ntohs(*sp); - LogPrintf(LOG_LCP_BIT, " %s proto = %04x\n", request, proto); + LogPrintf(LogLCP, " %s proto = %04x\n", request, proto); switch (mode) { case MODE_REQ: switch (proto) { case PROTO_PAP: if (length != 4) { - LogPrintf(LOG_LCP_BIT, " %s bad length (%d)\n", request, length); + LogPrintf(LogLCP, " %s bad length (%d)\n", request, length); goto reqreject; } if (Acceptable(ConfPap)) { @@ -516,7 +511,7 @@ int mode; break; case PROTO_CHAP: if (length < 5) { - LogPrintf(LOG_LCP_BIT, " %s bad length (%d)\n", request, length); + LogPrintf(LogLCP, " %s bad length (%d)\n", request, length); goto reqreject; } if (Acceptable(ConfChap) && cp[4] == 5) { @@ -530,7 +525,7 @@ int mode; goto reqreject; break; default: - LogPrintf(LOG_LCP_BIT, " %s not implemented, NAK.\n", request); + LogPrintf(LogLCP, " %s not implemented, NAK.\n", request); bcopy(cp, nakp, length); nakp += length; break; @@ -545,7 +540,7 @@ int mode; break; case TY_QUALPROTO: req = (struct lqrreq *)cp; - LogPrintf(LOG_LCP_BIT, " %s proto: %x, interval: %dms\n", + LogPrintf(LogLCP, " %s proto: %x, interval: %dms\n", request, ntohs(req->proto), ntohl(req->period)*10); switch (mode) { case MODE_REQ: @@ -569,14 +564,14 @@ int mode; case TY_MAGICNUM: lp = (u_long *)(cp + 2); magic = ntohl(*lp); - LogPrintf(LOG_LCP_BIT, " %s %08x\n", request, magic); + LogPrintf(LogLCP, " %s %08x\n", request, magic); switch (mode) { case MODE_REQ: if (LcpInfo.want_magic) { /* Validate magic number */ if (magic == LcpInfo.want_magic) { - LogPrintf(LOG_LCP_BIT, "Magic is same (%08x)\n", magic); + LogPrintf(LogLCP, "Magic is same (%08x)\n", magic); LcpInfo.want_magic = GenerateMagic(); bcopy(cp, nakp, 6); nakp += 6; @@ -590,18 +585,18 @@ int mode; } break; case MODE_NAK: - LogPrintf(LOG_LCP_BIT, " %s magic %08x has NAKed\n", request, magic); + LogPrintf(LogLCP, " %s magic %08x has NAKed\n", request, magic); LcpInfo.want_magic = GenerateMagic(); break; case MODE_REJ: - LogPrintf(LOG_LCP_BIT, " %s magic has REJected\n", request); + LogPrintf(LogLCP, " %s magic has REJected\n", request); LcpInfo.want_magic = 0; LcpInfo.his_reject |= (1 << type); break; } break; case TY_PROTOCOMP: - LogPrintf(LOG_LCP_BIT, " %s\n", request); + LogPrintf(LogLCP, " %s\n", request); switch (mode) { case MODE_REQ: @@ -628,7 +623,7 @@ int mode; } break; case TY_ACFCOMP: - LogPrintf(LOG_LCP_BIT, " %s\n", request); + LogPrintf(LogLCP, " %s\n", request); switch (mode) { case MODE_REQ: if (Acceptable(ConfAcfcomp)) { @@ -657,7 +652,7 @@ int mode; } break; case TY_SDP: - LogPrintf(LOG_LCP_BIT, " %s\n", request); + LogPrintf(LogLCP, " %s\n", request); switch (mode) { case MODE_REQ: case MODE_NAK: @@ -666,7 +661,7 @@ int mode; } break; default: - LogPrintf(LOG_LCP_BIT, " ???[%02x]\n", type); + LogPrintf(LogLCP, " ???[%02x]\n", type); if (mode == MODE_REQ) { reqreject: bcopy(cp, rejp, length); @@ -677,7 +672,7 @@ reqreject: } /* to avoid inf. loop */ if (length == 0) { - LogPrintf(LOG_LCP, "LCP size zero\n"); + LogPrintf(LogLCP, "LCP size zero\n"); break; } diff --git a/usr.sbin/ppp/lcp.h b/usr.sbin/ppp/lcp.h index d9a4f54..6995878 100644 --- a/usr.sbin/ppp/lcp.h +++ b/usr.sbin/ppp/lcp.h @@ -15,14 +15,13 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: lcp.h,v 1.6 1997/02/22 16:10:24 peter Exp $ * * TODO: */ #ifndef _LCP_H_ #define _LPC_H_ -#include "cdefs.h" struct lcpstate { u_long his_mru; @@ -75,10 +74,10 @@ struct lqrreq { extern struct lcpstate LcpInfo; -extern void LcpInit __P((void)); -extern void LcpUp __P((void)); -extern void LcpSendProtoRej __P((u_char *, int)); -extern void LcpOpen __P((int mode)); -extern void LcpClose __P((void)); -extern void LcpDown __P((void)); +extern void LcpInit(void); +extern void LcpUp(void); +extern void LcpSendProtoRej(u_char *, int); +extern void LcpOpen(int mode); +extern void LcpClose(void); +extern void LcpDown(void); #endif diff --git a/usr.sbin/ppp/lcpproto.h b/usr.sbin/ppp/lcpproto.h index f4ddadf..f918893 100644 --- a/usr.sbin/ppp/lcpproto.h +++ b/usr.sbin/ppp/lcpproto.h @@ -15,14 +15,13 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: lcpproto.h,v 1.6 1997/02/22 16:10:25 peter Exp $ * * TODO: */ #ifndef _LCPPROTO_H_ #define _LCPPROTO_H_ -#include "cdefs.h" /* * Definition of protocol numbers @@ -42,12 +41,12 @@ #define PROTO_LQR 0xc025 #define PROTO_CHAP 0xc223 -extern void LcpInput __P((struct mbuf *bp)); -extern void PapInput __P((struct mbuf *bp)); -extern void LqpInput __P((struct mbuf *bp)); -extern void ChapInput __P((struct mbuf *bp)); -extern void IpInput __P((struct mbuf *bp)); -extern struct mbuf *VjCompInput __P((struct mbuf *bp, int proto)); -extern void IpcpInput __P((struct mbuf *bp)); -extern void LqrInput __P((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 diff --git a/usr.sbin/ppp/loadalias.c b/usr.sbin/ppp/loadalias.c index 5e26bd4..e0acf5e 100644 --- a/usr.sbin/ppp/loadalias.c +++ b/usr.sbin/ppp/loadalias.c @@ -41,7 +41,6 @@ int loadAliasHandlers(struct aliasHandlers *h) { char *path; char *env; - char *err; int i; path = _PATH_ALIAS; @@ -49,25 +48,22 @@ int loadAliasHandlers(struct aliasHandlers *h) if (env) if (OrigUid() == 0) path = env; - else { - logprintf("Ignoring environment _PATH_ALIAS value (%s)\n", env); - printf("Ignoring environment _PATH_ALIAS value (%s)\n", env); - } + else + LogPrintf(LogALERT, "Ignoring environment _PATH_ALIAS value (%s)", + env); dl = dlopen(path, RTLD_LAZY); if (dl == (void *)0) { - err = dlerror(); - logprintf("_PATH_ALIAS (%s): Invalid lib: %s\n", path, err); - printf("_PATH_ALIAS (%s): Invalid lib: %s\n", path, err); + 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) { - err = dlerror(); - logprintf("_PATH_ALIAS (%s): %s: %s\n", path, map[i].name, err); - printf("_PATH_ALIAS (%s): %s: %s\n", path, map[i].name, err); + LogPrintf(LogWARN, "_PATH_ALIAS (%s): %s: %s\n", path, + map[i].name, dlerror()); (void)dlclose(dl); dl = (void *)0; return -1; diff --git a/usr.sbin/ppp/log.c b/usr.sbin/ppp/log.c index 7cd4332..a9ec54a 100644 --- a/usr.sbin/ppp/log.c +++ b/usr.sbin/ppp/log.c @@ -1,317 +1,148 @@ -/* - * PPP logging facility - * - * Written by Toshiharu OHNO (tony-o@iij.ad.jp) - * - * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the Internet Initiative Japan, Inc. The name of the - * IIJ may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: log.c,v 1.11 1997/05/26 00:44:05 brian Exp $ - * - */ -#include "defs.h" -#include <time.h> -#include <netdb.h> -#ifdef __STDC__ +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/param.h> +#include <netinet/in.h> +#include <syslog.h> #include <stdarg.h> -#else -#include <varargs.h> -#endif -#ifdef NO_VSPRINTF #include <stdio.h> -#endif - -#include "hdlc.h" - -#define MAXLOG 70 - -#define USELOGFILE - -#ifdef USELOGFILE -static FILE *logfile; -#endif -static char logbuff[MAX_MRU*3+(MAX_MRU/16+1)*22+80]; -char *logptr; -static struct mbuf *logtop; -static struct mbuf *lognext; -static int logcnt; -static int mypid; - -int loglevel = LOG_LINK_BIT | LOG_CARRIER_BIT | LOG_PHASE_BIT; - -void -ListLog() +#include "mbuf.h" +#include "log.h" +#include "loadalias.h" +#include "vars.h" + +static char *LogNames[] = { + "Async", + "Carrier", + "Chat", + "Command", + "Connect", + "Debug", + "HDLC", + "LCP", + "Link", + "LQM", + "Phase", + "TCP/IP", + "Tun", + "Warning", + "Error", + "Alert" +}; + +#define MSK(n) (1<<((n)-1)) + +static u_long LogMask = MSK(LogLINK) | MSK(LogCARRIER) | MSK(LogPHASE); +static int LogTunno = -1; + +static int +syslogLevel(int lev) { - struct mbuf *bp; - - for (bp = logtop; bp; bp = bp->next) { - write(1, MBUF_CTOP(bp), bp->cnt); - usleep(10); - } + 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; } -int -LogOpen(tunno) -int tunno; +const char * +LogName(int id) { -#ifdef USELOGFILE - char buf[80]; - - sprintf(buf, LOGFILE, tunno); - logfile = fopen(buf, "a"); - if (logfile == NULL) { - fprintf(stderr, "can't open %s.\r\n", buf); - return(1); - } -#endif - if (!(mode & MODE_DIRECT)) - fprintf(stderr, "Log level is %02x\r\n", loglevel); - logptr = logbuff; - logcnt = 0; - logtop = lognext = NULL; - return(0); + return id < LogMIN || id > LogMAX ? "Unknown" : LogNames[id-1]; } void -LogFlush() +LogKeep(int id) { - struct mbuf *bp; - int cnt; - -#ifdef USELOGFILE - *logptr = 0; - fprintf(logfile, "%s", logbuff); - fflush(logfile); -#endif - cnt = logptr - logbuff + 1; - bp = mballoc(cnt, MB_LOG); - bcopy(logbuff, MBUF_CTOP(bp), cnt); - bp->cnt = cnt; - if (lognext) { - lognext->next = bp; - lognext = bp; - if (++logcnt > MAXLOG) { - logcnt--; - logtop = mbfree(logtop); - } - } else { - lognext = logtop = bp; - } - logptr = logbuff; + if (id >= LogMIN && id <= LogMAXCONF) + LogMask |= MSK(id); } void -DupLog() +LogDiscard(int id) { - mypid = 0; -#ifdef USELOGFILE - dup2(fileno(logfile), 2); -#endif + if (id >= LogMIN && id <= LogMAXCONF) + LogMask &= ~MSK(id); } void -LogClose() +LogDiscardAll() { - LogFlush(); -#ifdef USELOGFILE - fclose(logfile); -#endif - logptr = NULL; + LogMask = 0; } -#ifdef NO_VSPRINTF -void -vsprintf(buf, fmt, av) -char *buf; -char *fmt; -va_list av; -{ - FILE foo; - - foo._cnt = BUFSIZ; - foo._base = foo._ptr = buf; /* may have to cast(unsigned char *) */ - foo._flag = _IOWRT+_IOSTRG; - (void) _doprnt(fmt, (va_list)av, &foo); - *foo._ptr = '\0'; /* plant terminating null character */ -} -#endif - -static void -vlogprintf(format, ap) -char *format; -va_list ap; +int +LogIsKept(int id) { - if (logptr) { - vsnprintf(logptr, sizeof(logbuff)-(logptr-logbuff), format, ap); - logptr += strlen(logptr); - LogFlush(); - } + if (id < LogMIN) + return 0; + if (id <= LogMAXCONF) + return LogMask & MSK(id); + return id <= LogMAX; } void -#ifdef __STDC__ -logprintf(char *format, ...) -#else -logprintf(va_alist) -va_dcl -#endif +LogOpen(const char *Name) { - va_list ap; -#ifdef __STDC__ - va_start(ap, format); -#else - char *format; - - va_start(ap); - format = va_arg(ap, char *); -#endif - vlogprintf(format, ap); - va_end(ap); + openlog(Name, LOG_PID, LOG_DAEMON); } void -LogDumpBp(level, header, bp) -int level; -char *header; -struct mbuf *bp; +LogSetTun(int tunno) { - u_char *cp; - int cnt, loc; - - if (!(loglevel & (1 << level))) - return; - LogTimeStamp(); - snprintf(logptr, sizeof(logbuff)-(logptr-logbuff), "%s\n", header); - logptr += strlen(logptr); - loc = 0; - LogTimeStamp(); - while (bp) { - cp = MBUF_CTOP(bp); - cnt = bp->cnt; - while (cnt-- > 0) { - snprintf(logptr, sizeof(logbuff)-(logptr-logbuff), " %02x", *cp++); - logptr += strlen(logptr); - if (++loc == 16) { - loc = 0; - *logptr++ = '\n'; - if (logptr - logbuff > 1500) - LogFlush(); - if (cnt) LogTimeStamp(); - } - } - bp = bp->next; - } - if (loc) *logptr++ = '\n'; - LogFlush(); + LogTunno = tunno; } void -LogDumpBuff(level, header, ptr, cnt) -int level; -char *header; -u_char *ptr; -int cnt; +LogClose() { - int loc; - - if (cnt < 1) return; - if (!(loglevel & (1 << level))) - return; - LogTimeStamp(); - snprintf(logptr, sizeof(logbuff)-(logptr-logbuff), "%s\n", header); - logptr += strlen(logptr); - LogTimeStamp(); - loc = 0; - while (cnt-- > 0) { - snprintf(logptr, sizeof(logbuff)-(logptr-logbuff), " %02x", *ptr++); - logptr += strlen(logptr); - if (++loc == 16) { - loc = 0; - *logptr++ = '\n'; - if (cnt) LogTimeStamp(); - } - } - if (loc) *logptr++ = '\n'; - LogFlush(); + closelog(); + LogTunno = -1; } void -LogTimeStamp() +LogPrintf(int lev, char *fmt, ...) { - struct tm *ptm; - time_t ltime; - - if (mypid == 0) - mypid = getpid(); - ltime = time(0); - ptm = localtime(<ime); - snprintf(logptr, sizeof(logbuff)-(logptr-logbuff), - "%02d-%02d %02d:%02d:%02d [%d] ", - ptm->tm_mon + 1, ptm->tm_mday, - ptm->tm_hour, ptm->tm_min, ptm->tm_sec, mypid); - logptr += strlen(logptr); + va_list ap; + 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 -#ifdef __STDC__ -LogPrintf(int level, char *format, ...) -#else -LogPrintf(va_alist) -va_dcl -#endif +LogDumpBp(int lev, char *hdr, struct mbuf *bp) { - va_list ap; -#ifdef __STDC__ - va_start(ap, format); -#else - int level; - char *format; - - va_start(ap); - int = va_arg(ap, int); - format = va_arg(ap, char *); -#endif - if (!(loglevel & level)) - return; - LogTimeStamp(); - vlogprintf(format, ap); - va_end(ap); + LogDumpBuff(lev, hdr, MBUF_CTOP(bp), bp->cnt); } void -LogReOpen( sig ) -int sig; +LogDumpBuff(int lev, char *hdr, u_char *ptr, int n) { -#ifdef USELOGFILE - FILE *nlogfile; - char buf[80]; - - sprintf(buf, LOGFILE, tunno); - nlogfile = fopen(buf, "a"); - if (nlogfile == NULL) { - LogPrintf(~0,"can't re-open %s.\r\n", buf); - } - else { - LogPrintf(~0,"log file closed due to signal %d.\r\n",sig); - LogFlush(); - fclose(logfile); - logfile = nlogfile; - logptr = logbuff; - logcnt = 0; - logtop = lognext = NULL; - LogPrintf(~0,"log file opened due to signal %d.\r\n",sig); - } -#endif - LogFlush(); + 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); + } + } } diff --git a/usr.sbin/ppp/log.h b/usr.sbin/ppp/log.h index 31ae57d..3a68cbf 100644 --- a/usr.sbin/ppp/log.h +++ b/usr.sbin/ppp/log.h @@ -1,73 +1,32 @@ -/* - * Written by Toshiharu OHNO (tony-o@iij.ad.jp) - * - * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the Internet Initiative Japan. The name of the - * IIJ may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: log.h,v 1.9 1997/03/13 14:53:54 brian Exp $ - * - * TODO: - */ +#define LogMIN (1) +#define LogASYNC (1) /* syslog(LOG_INFO, ....) */ +#define LogCARRIER (2) +#define LogCHAT (3) +#define LogCOMMAND (4) +#define LogCONNECT (5) +#define LogDEBUG (6) /* syslog(LOG_DEBUG, ....) */ +#define LogHDLC (7) +#define LogLCP (8) +#define LogLINK (9) +#define LogLQM (10) +#define LogPHASE (11) +#define LogTCPIP (12) +#define LogTUN (13) /* If set, tun%d is output with each message */ +#define LogMAXCONF (13) +#define LogWARN (14) /* Sent to VarTerm else syslog(LOG_WARNING, ) */ +#define LogERROR (15) /* syslog(LOG_ERR, ....), + sent to VarTerm */ +#define LogALERT (16) /* syslog(LOG_ALERT, ....) */ +#define LogMAX (16) -#ifndef _LOG_H_ -#define _LOG_H_ -#include "cdefs.h" -/* - * Definition of log level - */ -#define LOG_PHASE 0 -#define LOG_PHASE_BIT (1 << LOG_PHASE) -# define LM_PHASE "Phase" -#define LOG_CHAT 1 -#define LOG_CHAT_BIT (1 << LOG_CHAT) -# define LM_CHAT "Chat" -#define LOG_LQM 2 -#define LOG_LQM_BIT (1 << LOG_LQM) -# define LM_LQM "LQM" -#define LOG_LCP 3 -#define LOG_LCP_BIT (1 << LOG_LCP) -# define LM_LCP "LCP" -#define LOG_TCPIP 4 -#define LOG_TCPIP_BIT (1 << LOG_TCPIP) -# define LM_TCPIP "TCP/IP" -#define LOG_HDLC 5 -#define LOG_HDLC_BIT (1 << LOG_HDLC) -# define LM_HDLC "HDLC" -#define LOG_ASYNC 6 -#define LOG_ASYNC_BIT (1 << LOG_ASYNC) -# define LM_ASYNC "Async" -#define LOG_LINK 7 -#define LOG_LINK_BIT (1 << LOG_LINK) -# define LM_LINK "Link" -#define LOG_CONNECT 8 -#define LOG_CONNECT_BIT (1 << LOG_CONNECT) -# define LM_CONNECT "Connect" -#define LOG_CARRIER 9 -#define LOG_CARRIER_BIT (1 << LOG_CARRIER) -# define LM_CARRIER "Carrier" -#define MAXLOGLEVEL 10 - -extern int loglevel, tunno; -extern char *logptr; - -extern void LogTimeStamp __P((void)); -extern int LogOpen __P((int)); -extern void LogReOpen __P((int)); -extern void DupLog __P((void)); -extern void LogClose __P((void)); -extern void logprintf __P((char *, ...)), LogPrintf __P((int, char *, ...)); -extern void LogDumpBp __P((int level, char *header, struct mbuf *bp)); -extern void LogDumpBuff __P((int level, char *header, u_char *ptr, int cnt)); -extern void ListLog __P((void)); -#endif +/* The first int arg for all of the following is one of the above values */ +extern const char *LogName(int); +extern void LogKeep(int); +extern void LogDiscard(int); +extern void LogDiscardAll(); +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); diff --git a/usr.sbin/ppp/lqr.c b/usr.sbin/ppp/lqr.c index 77713de..798bcf9 100644 --- a/usr.sbin/ppp/lqr.c +++ b/usr.sbin/ppp/lqr.c @@ -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.13 1997/05/24 17:32:39 brian Exp $ + * $Id: lqr.c,v 1.14 1997/05/26 00:44:05 brian Exp $ * * o LQR based on RFC1333 * @@ -61,7 +61,7 @@ SendEchoReq() lqr = &lqrdata; lqr->magic = htonl(LcpInfo.want_magic); lqr->signature = htonl(SIGNATURE); - LogPrintf(LOG_LQM_BIT, "Send echo LQR [%d]\n", echoseq); + LogPrintf(LogLQM, "Send echo LQR [%d]\n", echoseq); lqr->sequence = htonl(echoseq++); FsmOutput(fp, CODE_ECHOREQ, fp->reqid++, (u_char *)lqr, sizeof(struct echolqr)); @@ -79,7 +79,7 @@ struct mbuf *bp; lqr = (struct echolqr *)MBUF_CTOP(bp); if (htonl(lqr->signature) == SIGNATURE) { seq = ntohl(lqr->sequence); - LogPrintf(LOG_LQM_BIT, "Got echo LQR [%d]\n", ntohl(lqr->sequence)); + LogPrintf(LogLQM, "Got echo LQR [%d]\n", ntohl(lqr->sequence)); gotseq = seq; } } @@ -109,7 +109,7 @@ SendLqrReport() /* * XXX: Should implement LQM strategy */ - LogPrintf(LOG_PHASE_BIT, "** 1 Too many ECHO packets are lost. **\n"); + LogPrintf(LogPHASE, "** 1 Too many ECHO packets are lost. **\n"); lqmmethod = 0; /* Prevent rcursion via LcpClose() */ reconnect(RECON_TRUE); LcpClose(); @@ -120,7 +120,7 @@ SendLqrReport() } } else if (lqmmethod & LQM_ECHO) { if (echoseq - gotseq > 5) { - LogPrintf(LOG_PHASE_BIT, "** 2 Too many ECHO packets are lost. **\n"); + LogPrintf(LogPHASE, "** 2 Too many ECHO packets are lost. **\n"); lqmmethod = 0; /* Prevent rcursion via LcpClose() */ reconnect(RECON_TRUE); LcpClose(); @@ -155,9 +155,8 @@ LqrInput(struct mbuf *bp) cp = MBUF_CTOP(bp); lqr = (struct lqrdata *)cp; if (ntohl(lqr->MagicNumber) != LcpInfo.his_magic) { -#ifdef notdef -logprintf("*** magic %x != expecting %x\n", ntohl(lqr->MagicNumber), LcpInfo.his_magic); -#endif + LogPrintf(LogERROR, "LqrInput: magic %x != expecting %x\n", + ntohl(lqr->MagicNumber), LcpInfo.his_magic); pfree(bp); return; } @@ -197,7 +196,7 @@ StartLqm() if (Enabled(ConfLqr)) lqmmethod |= LQM_LQR; StopTimer(&LqrTimer); - LogPrintf(LOG_LQM_BIT, "LQM method = %d\n", lqmmethod); + LogPrintf(LogLQM, "LQM method = %d\n", lqmmethod); if (lcp->his_lqrperiod || lcp->want_lqrperiod) { /* @@ -210,10 +209,10 @@ StartLqm() LqrTimer.func = SendLqrReport; SendLqrReport(); StartTimer(&LqrTimer); - LogPrintf(LOG_LQM_BIT, "Will send LQR every %d.%d secs\n", + LogPrintf(LogLQM, "Will send LQR every %d.%d secs\n", period/100, period % 100); } else { - LogPrintf(LOG_LQM_BIT, "LQR is not activated.\n"); + LogPrintf(LogLQM, "LQR is not activated.\n"); } } @@ -227,12 +226,12 @@ void StopLqr(method) int method; { - LogPrintf(LOG_LQM_BIT, "StopLqr method = %x\n", method); + LogPrintf(LogLQM, "StopLqr method = %x\n", method); if (method == LQM_LQR) - LogPrintf(LOG_LQM_BIT, "Stop sending LQR, Use LCP ECHO instead.\n"); + LogPrintf(LogLQM, "Stop sending LQR, Use LCP ECHO instead.\n"); if (method == LQM_ECHO) - LogPrintf(LOG_LQM_BIT, "Stop sending LCP ECHO.\n"); + LogPrintf(LogLQM, "Stop sending LCP ECHO.\n"); lqmmethod &= ~method; if (lqmmethod) SendLqrReport(); @@ -245,26 +244,19 @@ LqrDump(message, lqr) char *message; struct lqrdata *lqr; { - if (loglevel & (1 << LOG_LQM)) { - LogTimeStamp(); - logprintf("%s:\n", message); - LogTimeStamp(); - logprintf(" Magic: %08x LastOutLQRs: %08x\n", - lqr->MagicNumber, lqr->LastOutLQRs); - LogTimeStamp(); - logprintf(" LastOutPackets: %08x LastOutOctets: %08x\n", - lqr->LastOutPackets, lqr->LastOutOctets); - LogTimeStamp(); - logprintf(" PeerInLQRs: %08x PeerInPackets: %08x\n", - lqr->PeerInLQRs, lqr->PeerInPackets); - LogTimeStamp(); - logprintf(" PeerInDiscards: %08x PeerInErrors: %08x\n", - lqr->PeerInDiscards, lqr->PeerInErrors); - LogTimeStamp(); - logprintf(" PeerInOctets: %08x PeerOutLQRs: %08x\n", - lqr->PeerInOctets, lqr->PeerOutLQRs); - LogTimeStamp(); - logprintf(" PeerOutPackets: %08x PeerOutOctets: %08x\n", - lqr->PeerOutPackets, lqr->PeerOutOctets); + if (LogIsKept(LogLQM)) { + LogPrintf(LogLQM, "%s:", message); + LogPrintf(LogLQM, " Magic: %08x LastOutLQRs: %08x\n", + lqr->MagicNumber, lqr->LastOutLQRs); + LogPrintf(LogLQM, " LastOutPackets: %08x LastOutOctets: %08x\n", + lqr->LastOutPackets, lqr->LastOutOctets); + LogPrintf(LogLQM, " PeerInLQRs: %08x PeerInPackets: %08x\n", + lqr->PeerInLQRs, lqr->PeerInPackets); + LogPrintf(LogLQM, " PeerInDiscards: %08x PeerInErrors: %08x\n", + lqr->PeerInDiscards, lqr->PeerInErrors); + LogPrintf(LogLQM, " PeerInOctets: %08x PeerOutLQRs: %08x\n", + lqr->PeerInOctets, lqr->PeerOutLQRs); + LogPrintf(LogLQM, " PeerOutPackets: %08x PeerOutOctets: %08x\n", + lqr->PeerOutPackets, lqr->PeerOutOctets); } } diff --git a/usr.sbin/ppp/lqr.h b/usr.sbin/ppp/lqr.h index d668bef..3b649e6 100644 --- a/usr.sbin/ppp/lqr.h +++ b/usr.sbin/ppp/lqr.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: lqr.h,v 1.5 1997/02/22 16:10:29 peter Exp $ * * TODO: */ @@ -58,10 +58,10 @@ struct lqrsave HisLqrSave; #define LQM_LQR 1 #define LQM_ECHO 2 -extern void LqrDump __P((char *, struct lqrdata *)); -extern void LqrChangeOrder __P((struct lqrdata *, struct lqrdata *)); -extern void StartLqm __P((void)); -extern void StopLqr __P((int)); -extern void StopLqrTimer __P((void)); -extern void RecvEchoLqr __P((struct mbuf *)); +extern void LqrDump(char *, struct lqrdata *); +extern void LqrChangeOrder(struct lqrdata *, struct lqrdata *); +extern void StartLqm(void); +extern void StopLqr(int); +extern void StopLqrTimer(void); +extern void RecvEchoLqr(struct mbuf *); #endif diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index ec01a47..ad423a5 100644 --- a/usr.sbin/ppp/main.c +++ b/usr.sbin/ppp/main.c @@ -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.58 1997/05/29 02:29:12 brian Exp $ + * $Id: main.c,v 1.59 1997/06/01 03:43:25 brian Exp $ * * TODO: * o Add commands for traffic summary, version display, etc. @@ -52,7 +52,7 @@ #include "sig.h" #define LAUTH_M1 "Warning: No password entry for this host in ppp.secret\n" -#define LAUTH_M2 "Warning: All manipulation is allowed by anyone in the world\n" +#define LAUTH_M2 "Warning: Manipulation is allowed by anyone\n" #ifndef O_NONBLOCK #ifdef O_NDELAY @@ -177,12 +177,12 @@ int excode; if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) { char c = EX_ERRDEAD; if (write(BGFiledes[1],&c,1) == 1) - LogPrintf(LOG_PHASE_BIT,"Parent notified of failure.\n"); + LogPrintf(LogPHASE,"Parent notified of failure.\n"); else - LogPrintf(LOG_PHASE_BIT,"Failed to notify parent of failure.\n"); + LogPrintf(LogPHASE,"Failed to notify parent of failure.\n"); close(BGFiledes[1]); } - LogPrintf(LOG_PHASE_BIT, "PPP Terminated (%s).\n",ex_desc(excode)); + LogPrintf(LogPHASE, "PPP Terminated (%s).\n",ex_desc(excode)); LogClose(); if (server >= 0) { close(server); @@ -198,17 +198,19 @@ static void Hangup(signo) int signo; { +#ifdef TRAPSEGV if (signo == SIGSEGV) { - LogPrintf(LOG_PHASE_BIT, "Signal %d, core dump.\n", signo); + LogPrintf(LogPHASE, "Signal %d, core dump.\n", signo); LogClose(); abort(); } +#endif if (BGPid) { kill (BGPid, SIGTERM); exit (EX_HANGUP); } else { - LogPrintf(LOG_PHASE_BIT, "Signal %d, hangup.\n", signo); + LogPrintf(LogPHASE, "Signal %d, hangup.\n", signo); Cleanup(EX_HANGUP); } } @@ -221,12 +223,10 @@ int signo; kill (BGPid, SIGINT); exit (EX_TERM); } - else { - LogPrintf(LOG_PHASE_BIT, "Signal %d, terminate.\n", signo); - reconnect(RECON_FALSE); - LcpClose(); - Cleanup(EX_TERM); - } + LogPrintf(LogPHASE, "Signal %d, terminate.\n", signo); + reconnect(RECON_FALSE); + LcpClose(); + Cleanup(EX_TERM); } static void @@ -292,7 +292,7 @@ ProcessArgs(int argc, char **argv) if (loadAliasHandlers(&VarAliasHandlers) == 0) mode |= MODE_ALIAS; else - printf("Cannot load alias library\n"); + LogPrintf(LogWARN, "Cannot load alias library\n"); optc--; /* this option isn't exclusive */ } else @@ -315,8 +315,10 @@ ProcessArgs(int argc, char **argv) static void Greetings() { - printf("User Process PPP. Written by Toshiharu OHNO.\r\n"); - fflush(stdout); + if (VarTerm) { + fprintf(VarTerm, "User Process PPP. Written by Toshiharu OHNO.\n"); + fflush(VarTerm); + } } void @@ -325,8 +327,13 @@ int argc; char **argv; { FILE *lockfile; - argc--; argv++; + char *name; + + VarTerm = stdout; + name = rindex(argv[0], '/'); + LogOpen(name ? name+1 : argv[0]); + argc--; argv++; mode = MODE_INTER; /* default operation is interactive mode */ netfd = server = modem = tun_in = -1; ProcessArgs(argc, argv); @@ -335,16 +342,14 @@ char **argv; GetUid(); IpcpDefAddress(); - if (SelectSystem("default", CONFFILE) < 0) { - fprintf(stderr, "Warning: No default entry is given in config file.\n"); - } + if (SelectSystem("default", CONFFILE) < 0 && VarTerm) + fprintf(VarTerm, "Warning: No default entry is given in config file.\n"); switch ( LocalAuthInit() ) { case NOT_FOUND: - if (!(mode & MODE_DIRECT)) { - fprintf(stderr,LAUTH_M1); - fprintf(stderr,LAUTH_M2); - fflush (stderr); + if (VarTerm) { + fprintf(VarTerm,LAUTH_M1); + fprintf(VarTerm,LAUTH_M2); } /* Fall down */ case VALID: @@ -355,19 +360,20 @@ char **argv; } if (OpenTunnel(&tunno) < 0) { - perror("open_tun"); + LogPrintf(LogWARN, "open_tun: %s", strerror(errno)); exit(EX_START); } if (mode & (MODE_AUTO|MODE_DIRECT|MODE_DEDICATED)) mode &= ~MODE_INTER; if (mode & MODE_INTER) { - printf("Interactive mode\n"); + fprintf(VarTerm, "Interactive mode\n"); netfd = STDIN_FILENO; } else if (mode & MODE_AUTO) { - printf("Automatic Dialer mode\n"); + fprintf(VarTerm, "Automatic Dialer mode\n"); if (dstsystem == NULL) { - fprintf(stderr, "Destination system must be specified in" + if (VarTerm) + fprintf(VarTerm, "Destination system must be specified in" " auto, background or ddial mode.\n"); exit(EX_START); } @@ -375,11 +381,11 @@ char **argv; tcgetattr(0, &oldtio); /* Save original tty mode */ - pending_signal(SIGHUP, LogReOpen); + pending_signal(SIGHUP, Hangup); pending_signal(SIGTERM, CloseSession); pending_signal(SIGINT, CloseSession); pending_signal(SIGQUIT, CloseSession); -#ifdef SIGSEGV +#ifdef TRAPSEGV signal(SIGSEGV, Hangup); #endif #ifdef SIGPIPE @@ -403,24 +409,26 @@ char **argv; if (dstsystem) { if (SelectSystem(dstsystem, CONFFILE) < 0) { - fprintf(stderr, "Destination system not found in conf file.\n"); + if (VarTerm) + fprintf(VarTerm, "Destination system not found in conf file.\n"); Cleanup(EX_START); } if ((mode & MODE_AUTO) && DefHisAddress.ipaddr.s_addr == INADDR_ANY) { - fprintf(stderr, "Must specify dstaddr with" + if (VarTerm) + fprintf(VarTerm, "Must specify dstaddr with" " auto, background or ddial mode.\n"); Cleanup(EX_START); } } if (mode & MODE_DIRECT) - printf("Packet mode enabled.\n"); + fprintf(VarTerm, "Packet mode enabled.\n"); if (!(mode & MODE_INTER)) { int port = SERVER_PORT + tunno; if (mode & MODE_BACKGROUND) { if (pipe (BGFiledes)) { - perror("pipe"); + LogPrintf(LogERROR, "pipe: %s", strerror(errno)); Cleanup(EX_SOCK); } } @@ -428,7 +436,7 @@ char **argv; /* Create server socket and listen at there. */ server = socket(PF_INET, SOCK_STREAM, 0); if (server < 0) { - perror("socket"); + LogPrintf(LogERROR, "socket: %s", strerror(errno)); Cleanup(EX_SOCK); } ifsin.sin_family = AF_INET; @@ -436,22 +444,22 @@ char **argv; ifsin.sin_port = htons(port); setsockopt(server, SOL_SOCKET, SO_REUSEADDR, &server, sizeof server); if (bind(server, (struct sockaddr *) &ifsin, sizeof(ifsin)) < 0) { - perror("bind"); - if (errno == EADDRINUSE) - fprintf(stderr, "Wait for a while, then try again.\n"); + LogPrintf(LogERROR, "bind: %s", strerror(errno)); + if (errno == EADDRINUSE && VarTerm) + fprintf(VarTerm, "Wait for a while, then try again.\n"); Cleanup(EX_SOCK); } if (listen(server, 5) != 0) { - fprintf(stderr, "Unable to listen to socket - OS overload?\n"); + LogPrintf(LogERROR, "Unable to listen to socket - OS overload?\n"); + Cleanup(EX_SOCK); } - DupLog(); if (!(mode & MODE_DIRECT)) { pid_t bgpid; bgpid = fork (); if (bgpid == -1) { - perror ("fork"); + LogPrintf(LogERROR, "fork: %s", strerror(errno)); Cleanup (EX_SOCK); } if (bgpid) { @@ -460,19 +468,19 @@ 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) { - printf("Child exit, no status.\n"); - LogPrintf (LOG_PHASE_BIT, "Parent: Child exit, no status.\n"); + fprintf(VarTerm, "Child exit, no status.\n"); + LogPrintf (LogPHASE, "Parent: Child exit, no status.\n"); } else if (c == EX_NORMAL) { - printf("PPP enabled.\n"); - LogPrintf (LOG_PHASE_BIT, "Parent: PPP enabled.\n"); + fprintf(VarTerm, "PPP enabled.\n"); + LogPrintf (LogPHASE, "Parent: PPP enabled.\n"); } else { - printf("Child failed (%s).\n",ex_desc((int)c)); - LogPrintf(LOG_PHASE_BIT, "Parent: Child failed (%s).\n", + fprintf(VarTerm, "Child failed (%s).\n",ex_desc((int)c)); + LogPrintf(LogPHASE, "Parent: Child failed (%s).\n", ex_desc((int)c)); } - close (BGFiledes[0]); + close(BGFiledes[0]); } exit(c); } else if (mode & MODE_BACKGROUND) @@ -487,7 +495,8 @@ char **argv; fprintf(lockfile, "%d\n", (int)getpid()); fclose(lockfile); } else - logprintf("Warning: Can't create %s: %s\n", pid_filename, strerror(errno)); + LogPrintf(LogALERT, "Warning: Can't create %s: %s\n", + pid_filename, strerror(errno)); snprintf(if_filename, sizeof if_filename, "%s%s.if", _PATH_VARRUN, VarBaseDevice); @@ -497,33 +506,24 @@ char **argv; fprintf(lockfile, "tun%d\n", tunno); fclose(lockfile); } else - logprintf("Warning: Can't create %s: %s\n", if_filename, strerror(errno)); + LogPrintf(LogALERT, "Warning: Can't create %s: %s\n", + if_filename, strerror(errno)); if (server >= 0) - LogPrintf(LOG_PHASE_BIT, "Listening at %d.\n", port); + LogPrintf(LogPHASE, "Listening at %d.\n", port); #ifdef DOTTYINIT - if (mode & (MODE_DIRECT|MODE_DEDICATED)) { /* } */ + if (mode & (MODE_DIRECT|MODE_DEDICATED)) #else - if (mode & MODE_DIRECT) { + if (mode & MODE_DIRECT) #endif TtyInit(); - } else { - int fd; - - setsid(); /* detach control tty */ - if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { - (void)dup2(fd, STDIN_FILENO); - (void)dup2(fd, STDOUT_FILENO); - (void)dup2(fd, STDERR_FILENO); - if (fd > 2) - (void)close (fd); - } - } + else + daemon(0,0); } else { TtyInit(); TtyCommandMode(1); } - LogPrintf(LOG_PHASE_BIT, "PPP Started.\n"); + LogPrintf(LogPHASE, "PPP Started.\n"); do @@ -540,7 +540,7 @@ void PacketMode() { if (RawModem(modem) < 0) { - fprintf(stderr, "Not connected.\r\n"); + LogPrintf(LogWARN, "PacketMode: Not connected.\n"); return; } @@ -554,20 +554,24 @@ PacketMode() LcpOpen(VarOpenMode); if ((mode & (MODE_INTER|MODE_AUTO)) == MODE_INTER) { TtyCommandMode(1); - fprintf(stderr, "Packet mode.\r\n"); - aft_cmd = 1; + if (VarTerm) { + fprintf(VarTerm, "Packet mode.\n"); + aft_cmd = 1; + } } } static void ShowHelp() { - fprintf(stderr, "The following commands are available:\r\n"); - fprintf(stderr, " ~p\tEnter to Packet mode\r\n"); - fprintf(stderr, " ~-\tDecrease log level\r\n"); - fprintf(stderr, " ~+\tIncrease log level\r\n"); - fprintf(stderr, " ~.\tTerminate program\r\n"); - fprintf(stderr, " ~?\tThis help\r\n"); + fprintf(stderr, "The following commands are available:\n"); + fprintf(stderr, " ~p\tEnter Packet mode\n"); + fprintf(stderr, " ~-\tDecrease log level\n"); + fprintf(stderr, " ~+\tIncrease log level\n"); + fprintf(stderr, " ~t\tShow timers (only in \"log debug\" mode)\n"); + fprintf(stderr, " ~m\tShow memory map (only in \"log debug\" mode)\n"); + fprintf(stderr, " ~.\tTerminate program\n"); + fprintf(stderr, " ~?\tThis help\n"); } static void @@ -576,25 +580,27 @@ ReadTty() int n; char ch; static int ttystate; + FILE *oVarTerm; #define MAXLINESIZE 200 char linebuff[MAXLINESIZE]; -#ifdef DEBUG - logprintf("termode = %d, netfd = %d, mode = %d\n", TermMode, netfd, mode); -#endif + LogPrintf(LogDEBUG, "termode = %d, netfd = %d, mode = %d\n", + TermMode, netfd, mode); if (!TermMode) { n = read(netfd, linebuff, sizeof(linebuff)-1); - aft_cmd = 1; if (n > 0) { + aft_cmd = 1; DecodeCommand(linebuff, n, 1); } else { - LogPrintf(LOG_PHASE_BIT, "client connection closed.\n"); + LogPrintf(LogPHASE, "client connection closed.\n"); VarLocalAuth = LOCAL_NO_AUTH; + mode &= ~MODE_INTER; + oVarTerm = VarTerm; + VarTerm = 0; + if (oVarTerm && oVarTerm != stdout) + fclose(oVarTerm); close(netfd); - close(1); - dup2(2, 1); /* Have to have something here or the modem will be 1 */ netfd = -1; - mode &= ~MODE_INTER; } return; } @@ -602,10 +608,8 @@ ReadTty() /* * We are in terminal mode, decode special sequences */ - n = read(0, &ch, 1); -#ifdef DEBUG - logprintf("got %d bytes\n", n); -#endif + n = read(fileno(VarTerm), &ch, 1); + LogPrintf(LogDEBUG, "Got %d bytes (reading from the terminal)", n); if (n > 0) { switch (ttystate) { @@ -620,21 +624,6 @@ ReadTty() case '?': ShowHelp(); break; - case '-': - if (loglevel > 0) { - loglevel--; - fprintf(stderr, "New loglevel is %d\r\n", loglevel); - } - break; - case '+': - loglevel++; - fprintf(stderr, "New loglevel is %d\r\n", loglevel); - break; -#ifdef DEBUG - case 'm': - ShowMemMap(); - break; -#endif case 'p': /* * XXX: Should check carrier. @@ -644,18 +633,24 @@ ReadTty() PacketMode(); } break; -#ifdef DEBUG - case 't': - ShowTimers(); - break; -#endif case '.': TermMode = 1; + aft_cmd = 1; TtyCommandMode(1); break; + case 't': + if (LogIsKept(LogDEBUG)) { + ShowTimers(); + break; + } + case 'm': + if (LogIsKept(LogDEBUG)) { + ShowMemMap(); + break; + } default: if (write(modem, &ch, n) < 0) - fprintf(stderr, "err in write.\r\n"); + LogPrintf(LogERROR, "error writing to modem.\n"); break; } ttystate = 0; @@ -704,7 +699,7 @@ static void RedialTimeout() { StopTimer(&RedialTimer); - LogPrintf(LOG_PHASE_BIT, "Redialing timer expired.\n"); + LogPrintf(LogPHASE, "Redialing timer expired.\n"); } static void @@ -721,7 +716,7 @@ StartRedialTimer(Timeout) else RedialTimer.load = (random() % REDIAL_PERIOD) * SECTICKS; - LogPrintf(LOG_PHASE_BIT, "Enter pause (%d) for redialing.\n", + LogPrintf(LogPHASE, "Enter pause (%d) for redialing.\n", RedialTimer.load / SECTICKS); RedialTimer.func = RedialTimeout; @@ -749,15 +744,14 @@ DoLoop() if (mode & MODE_DIRECT) { modem = OpenModem(mode); - LogPrintf(LOG_PHASE_BIT, "Packet mode enabled\n"); - fflush(stderr); + LogPrintf(LogPHASE, "Packet mode enabled\n"); PacketMode(); } else if (mode & MODE_DEDICATED) { if (modem < 0) modem = OpenModem(mode); } - fflush(stdout); + fflush(VarTerm); timeout.tv_sec = 0; timeout.tv_usec = 0; @@ -787,13 +781,13 @@ DoLoop() if (LcpFsm.state <= ST_CLOSED) { if (dial_up != TRUE && reconnectState == RECON_TRUE) { if (++reconnectCount <= VarReconnectTries) { - LogPrintf(LOG_PHASE_BIT, "Connection lost, re-establish (%d/%d)\n", + LogPrintf(LogPHASE, "Connection lost, re-establish (%d/%d)\n", reconnectCount, VarReconnectTries); StartRedialTimer(VarReconnectTimer); dial_up = TRUE; } else { if (VarReconnectTries) - LogPrintf(LOG_PHASE_BIT, "Connection lost, maximum (%d) times\n", + LogPrintf(LogPHASE, "Connection lost, maximum (%d) times\n", VarReconnectTries); reconnectCount = 0; if (mode & MODE_BACKGROUND) @@ -808,19 +802,17 @@ DoLoop() * Just do it! */ if ( dial_up && RedialTimer.state != TIMER_RUNNING ) { -#ifdef DEBUG - logprintf("going to dial: modem = %d\n", modem); -#endif + LogPrintf(LogDEBUG, "going to dial: modem = %d\n", modem); modem = OpenModem(mode); if (modem < 0) { StartRedialTimer(VarRedialTimeout); } else { tries++; /* Tries are per number, not per list of numbers. */ if (VarDialTries) - LogPrintf(LOG_CHAT_BIT, "Dial attempt %u of %d\n", tries, + LogPrintf(LogCHAT, "Dial attempt %u of %d\n", tries, VarDialTries); else - LogPrintf(LOG_CHAT_BIT, "Dial attempt %u\n", tries); + LogPrintf(LogCHAT, "Dial attempt %u\n", tries); if (DialModem() == EX_DONE) { sleep(1); /* little pause to allow peer starts */ ModemTimeout(); @@ -928,20 +920,20 @@ DoLoop() handle_signals(); continue; } - perror("select"); + LogPrintf(LogERROR, "select: %s", strerror(errno)); break; } if ((netfd >= 0 && FD_ISSET(netfd, &efds)) || (modem >= 0 && FD_ISSET(modem, &efds))) { - logprintf("Exception detected.\n"); + LogPrintf(LogALERT, "Exception detected.\n"); break; } if (server >= 0 && FD_ISSET(server, &rfds)) { - LogPrintf(LOG_PHASE_BIT, "connected to client.\n"); + LogPrintf(LogPHASE, "connected to client.\n"); wfd = accept(server, (struct sockaddr *)&hisaddr, &ssize); if (wfd < 0) { - perror("accept"); + LogPrintf(LogERROR, "accept: %s", strerror(errno)); continue; } if (netfd >= 0) { @@ -950,19 +942,16 @@ DoLoop() continue; } else netfd = wfd; - if (dup2(netfd, 1) < 0) { - perror("dup2"); - close(netfd); - netfd = -1; - continue; - } + VarTerm = fdopen(netfd, "a+"); mode |= MODE_INTER; Greetings(); switch ( LocalAuthInit() ) { case NOT_FOUND: - fprintf(stdout,LAUTH_M1); - fprintf(stdout,LAUTH_M2); - fflush(stdout); + if (VarTerm) { + fprintf(VarTerm,LAUTH_M1); + fprintf(VarTerm,LAUTH_M2); + fflush(VarTerm); + } /* Fall down */ case VALID: VarLocalAuth = LOCAL_AUTH; @@ -990,7 +979,7 @@ DoLoop() if ((mode & MODE_DIRECT) && n <= 0) { DownConnection(); } else - LogDumpBuff(LOG_ASYNC, "ReadFromModem", rbuff, n); + LogDumpBuff(LogASYNC, "ReadFromModem", rbuff, n); if (LcpFsm.state <= ST_CLOSED) { /* @@ -1003,12 +992,12 @@ DoLoop() * LCP packet is detected. Turn ourselves into packet mode. */ if (cp != rbuff) { - write(1, rbuff, cp - rbuff); - write(1, "\r\n", 2); + write(modem, rbuff, cp - rbuff); + write(modem, "\r\n", 2); } PacketMode(); } else - write(1, rbuff, n); + write(fileno(VarTerm), rbuff, n); } } else { if (n > 0) @@ -1020,7 +1009,7 @@ DoLoop() if (tun_in >= 0 && FD_ISSET(tun_in, &rfds)) { /* something to read from tun */ n = read(tun_in, rbuff, sizeof(rbuff)); if (n < 0) { - perror("read from tun"); + LogPrintf(LogERROR, "read from tun: %s", strerror(errno)); continue; } /* @@ -1049,5 +1038,5 @@ DoLoop() } } } - logprintf("job done.\n"); + LogPrintf(LogDEBUG, "Job (DoLoop) done.\n"); } diff --git a/usr.sbin/ppp/main.h b/usr.sbin/ppp/main.h index a6e591d..bc4e6f3 100644 --- a/usr.sbin/ppp/main.h +++ b/usr.sbin/ppp/main.h @@ -17,11 +17,11 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: main.h,v 1.3 1997/02/22 16:10:33 peter Exp $ * */ #ifndef _MAIN_H_ #define _MAIN_H_ -void Cleanup __P((int)); +void Cleanup(int); #endif diff --git a/usr.sbin/ppp/mbuf.c b/usr.sbin/ppp/mbuf.c index 7454726..3fbaebe 100644 --- a/usr.sbin/ppp/mbuf.c +++ b/usr.sbin/ppp/mbuf.c @@ -17,10 +17,16 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: mbuf.c,v 1.5 1997/02/22 16:10:34 peter Exp $ + * $Id: mbuf.c,v 1.6 1997/05/10 01:22:15 brian Exp $ * */ +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/param.h> +#include <netinet/in.h> #include "defs.h" +#include "loadalias.h" +#include "vars.h" struct memmap { struct mbuf *queue; @@ -49,19 +55,17 @@ int type; struct mbuf *bp; if (type > MB_MAX) - logprintf("bad type %d\n", type); + LogPrintf(LogERROR, "Bad mbuf type %d\n", type); bp = (struct mbuf *)malloc(sizeof(struct mbuf)); if (bp == NULL) { - logprintf("failed to allocate memory: %u\n", sizeof(struct mbuf)); - fprintf(stderr,"failed to allocate memory: %u\n", sizeof(struct mbuf)); - exit(0); + LogPrintf(LogALERT, "failed to allocate memory: %u\n", sizeof(struct mbuf)); + exit(1); } bzero(bp, sizeof(struct mbuf)); p = (u_char *)malloc(cnt); if (p == NULL) { - logprintf("failed to allocate memory: %d\n", cnt); - fprintf(stderr,"failed to allocate memory: %d\n", cnt); - exit(0); + LogPrintf(LogALERT, "failed to allocate memory: %d\n", cnt); + exit(1); } MemMap[type].count += cnt; totalalloced += cnt; @@ -144,53 +148,27 @@ int cnt; } } -void -DumpBp(bp) -struct mbuf *bp; -{ - u_char *cp; - int cnt, loc; - - logprintf("dump bp = %x (%d)\n", bp, plength(bp)); - loc = 0; - while (bp) { - cp = MBUF_CTOP(bp); - cnt = bp->cnt; - while (cnt > 0) { - logprintf("%02x", *cp++); - loc++; - if (loc == 16) { - loc = 0; - logprintf("\n"); - } else - logprintf(" "); - cnt--; - } - bp = bp->next; - } - if (loc) logprintf("\n"); -} - int ShowMemMap() { int i; - for (i = 0; i <= MB_MAX; i += 2) { - printf("%d: %d %d: %d\r\n", + if (!VarTerm) + return 1; + + 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); - } - return(1); + + return 0; } void LogMemory() { -#ifdef DEBUG - logprintf("mem alloced: %d\n", totalalloced); - logprintf(" 1: %d 2: %d 3: %d 4: %d\n", + LogPrintf(LogDEBUG, "LogMemory: mem alloced: %d\n", totalalloced); + LogPrintf(LogDEBUG, "LogMemory: 1: %d 2: %d 3: %d 4: %d\n", MemMap[1].count, MemMap[2].count, MemMap[3].count, MemMap[4].count); - logprintf(" 5: %d 6: %d 7: %d 8: %d\n", + LogPrintf(LogDEBUG, "LogMemory: 5: %d 6: %d 7: %d 8: %d\n", MemMap[5].count, MemMap[6].count, MemMap[7].count, MemMap[8].count); -#endif } diff --git a/usr.sbin/ppp/mbuf.h b/usr.sbin/ppp/mbuf.h index 9ec0e53..f7f7b7b 100644 --- a/usr.sbin/ppp/mbuf.h +++ b/usr.sbin/ppp/mbuf.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: mbuf.h,v 1.4 1997/02/22 16:10:35 peter Exp $ * * TODO: */ @@ -55,13 +55,15 @@ struct mqueue { #define MB_IPQ 10 #define MB_MAX MB_IPQ -extern int plength __P((struct mbuf *bp)); -extern struct mbuf *mballoc __P((int cnt, int type)); -extern struct mbuf *mbfree __P((struct mbuf *bp)); -extern void pfree __P((struct mbuf *bp)); -extern void mbwrite __P((struct mbuf *bp, u_char *ptr, int cnt)); -extern struct mbuf *mbread __P((struct mbuf *bp, u_char *ptr, int cnt)); -extern void DumpBp __P((struct mbuf *bp)); -extern void Enqueue __P((struct mqueue *queue, struct mbuf *bp)); -extern struct mbuf *Dequeue __P((struct mqueue *queue)); +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 void LogMemory(); +extern int ShowMemMap(); #endif diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c index e4cbecd..d5dc70f 100644 --- a/usr.sbin/ppp/modem.c +++ b/usr.sbin/ppp/modem.c @@ -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.40 1997/05/26 00:44:06 brian Exp $ + * $Id: modem.c,v 1.41 1997/05/29 02:29:13 brian Exp $ * * TODO: */ @@ -26,6 +26,9 @@ #include <termios.h> #include <sys/ioctl.h> #include <sys/tty.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <netdb.h> #include <errno.h> #include <time.h> #include <libutil.h> @@ -57,8 +60,6 @@ static struct mbuf *modemout; static struct mqueue OutputQueues[PRI_LINK+1]; static int dev_is_modem; -#undef QDEBUG - void Enqueue(queue, bp) struct mqueue *queue; @@ -70,9 +71,7 @@ struct mbuf *bp; } else queue->last = queue->top = bp; queue->qlen++; -#ifdef QDEBUG - logprintf("Enqueue: len = %d\n", queue->qlen); -#endif + LogPrintf(LogDEBUG, "Enqueue: len = %d\n", queue->qlen); } struct mbuf * @@ -81,19 +80,15 @@ struct mqueue *queue; { struct mbuf *bp; -#ifdef QDEBUG - logprintf("Dequeue: len = %d\n", queue->qlen); -#endif + LogPrintf(LogDEBUG, "Dequeue: len = %d\n", queue->qlen); bp = queue->top; if (bp) { queue->top = queue->top->pnext; queue->qlen--; if (queue->top == NULL) { queue->last = queue->top; -#ifdef QDEBUG if (queue->qlen) - logprintf("!!! not zero (%d)!!!\n", queue->qlen); -#endif + LogPrintf(LogDEBUG, "Dequeue: Not zero (%d)!!!\n", queue->qlen); } } return(bp); @@ -211,8 +206,8 @@ static time_t uptime; void DownConnection() { - LogPrintf(LOG_PHASE_BIT, "Disconnected!\n"); - LogPrintf(LOG_PHASE_BIT, "Connect time: %d secs\n", time(NULL) - uptime); + LogPrintf(LogPHASE, "Disconnected!\n"); + LogPrintf(LogPHASE, "Connect time: %d secs\n", time(NULL) - uptime); if (!TermMode) { CloseModem(); LcpDown(); @@ -235,7 +230,7 @@ ModemTimeout() if (dev_is_modem) { if (modem >= 0) { if (ioctl(modem, TIOCMGET, &mbits) < 0) { - LogPrintf(LOG_PHASE_BIT, "ioctl error (%s)!\n", strerror(errno)); + LogPrintf(LogPHASE, "ioctl error (%s)!\n", strerror(errno)); DownConnection(); return; } @@ -245,7 +240,7 @@ ModemTimeout() if (change & TIOCM_CD) { if (Online) { time(&uptime); - LogPrintf(LOG_PHASE_BIT, "*Connected!\n"); + LogPrintf(LogPHASE, "*Connected!\n"); connect_count++; /* * In dedicated mode, start packet mode immediate @@ -261,7 +256,7 @@ ModemTimeout() } else { if (!Online) { time(&uptime); - LogPrintf(LOG_PHASE_BIT, "Connected!\n"); + LogPrintf(LogPHASE, "Connected!\n"); mbits = TIOCM_CD; connect_count++; } else if (uptime == 0) { @@ -298,8 +293,7 @@ char *str; for (pp = validparity; pp->name; pp++) { if (strcasecmp(pp->name, str) == 0 || strcasecmp(pp->name1, str) == 0) { - VarParity = pp->set; - return(pp->set); + return VarParity = pp->set; } } return(-1); @@ -319,14 +313,12 @@ char *str; rstio.c_cflag &= ~(CSIZE|PARODD|PARENB); rstio.c_cflag |= val; tcsetattr(modem, TCSADRAIN, &rstio); + return 0; } - return(val); + LogPrintf(LogWARN, "ChangeParity: %s: Invalid parity\n", str); + return -1; } -#include <sys/socket.h> -#include <arpa/inet.h> -#include <netdb.h> - int OpenConnection(host, port) char *host, *port; @@ -343,7 +335,7 @@ char *host, *port; if (hp) { bcopy(hp->h_addr_list[0], &dest.sin_addr.s_addr, 4); } else { - printf("unknown host: %s\n", host); + LogPrintf(LogWARN, "OpenConnection: unknown host: %s\n", host); return(-1); } } @@ -353,18 +345,18 @@ char *host, *port; if (sp) { dest.sin_port = sp->s_port; } else { - printf("unknown service: %s\n", port); + LogPrintf(LogWARN, "OpenConnection: unknown service: %s\n", port); return(-1); } } - LogPrintf(LOG_PHASE_BIT, "Connected to %s:%s\n", host, port); + LogPrintf(LogPHASE, "Connected to %s:%s\n", host, port); sock = socket(PF_INET, SOCK_STREAM, 0); if (sock < 0) { return(sock); } if (connect(sock, (struct sockaddr *)&dest, sizeof(dest)) < 0) { - printf("connection failed.\n"); + LogPrintf(LogWARN, "OpenConnection: connection failed.\n"); return(-1); } return(sock); @@ -386,7 +378,7 @@ int mode; if (isatty(0)) { modem = open(ctermid(NULL), O_RDWR|O_NONBLOCK); if (modem < 0) { - LogPrintf(LOG_PHASE_BIT, "Open Failed %s\n", ctermid(NULL)); + LogPrintf(LogPHASE, "Open Failed %s\n", ctermid(NULL)); return(modem); } } else if (modem < 0) @@ -395,15 +387,15 @@ int mode; if (strncmp(VarDevice, "/dev/", 5) == 0) { if ((res = uu_lock(VarBaseDevice)) != UU_LOCK_OK) { if (res == UU_LOCK_INUSE) - LogPrintf(LOG_PHASE_BIT, "Modem %s is in use\n", VarDevice); + LogPrintf(LogPHASE, "Modem %s is in use\n", VarDevice); else - LogPrintf(LOG_PHASE_BIT, "Modem %s is in use: uu_lock: %s\n", + LogPrintf(LogPHASE, "Modem %s is in use: uu_lock: %s\n", VarDevice, uu_lockerr(res)); return(-1); } modem = open(VarDevice, O_RDWR|O_NONBLOCK); if (modem < 0) { - LogPrintf(LOG_PHASE_BIT, "Open Failed %s\n", VarDevice); + LogPrintf(LogPHASE, "Open Failed %s\n", VarDevice); (void) uu_unlock(VarBaseDevice); return(modem); } @@ -427,21 +419,6 @@ int mode; } } - /* This code gets around the problem of closing descriptor 0 - * when it should not have been closed and closing descriptor 1 - * when the telnet connection dies. Since this program always - * opens a descriptor for the modem in auto and direct mode, - * having to dup the descriptor here is a fatal error. - * - * With the other changes I have made this should no longer happen. - * JC - */ - while (modem < 3) - { - logprintf("Duping modem fd %d\n", modem); - modem = dup(modem); - } - /* * If we are working on tty device, change it's mode into * the one desired for further operation. In this implementation, @@ -453,11 +430,9 @@ int mode; if (dev_is_modem && !DEV_IS_SYNC) { tcgetattr(modem, &rstio); modemios = rstio; -#ifdef DEBUG - logprintf("## modem = %d\n", modem); - logprintf("modem (get): iflag = %x, oflag = %x, cflag = %x\n", - rstio.c_iflag, rstio.c_oflag, rstio.c_cflag); -#endif + LogPrintf(LogDEBUG, "OpenModem: modem = %d\n", modem); + LogPrintf(LogDEBUG, "OpenModem: modem (get): iflag = %x, oflag = %x," + " cflag = %x\n", rstio.c_iflag, rstio.c_oflag, rstio.c_cflag); cfmakeraw(&rstio); if (VarCtsRts) rstio.c_cflag |= CLOCAL | CCTS_OFLOW|CRTS_IFLOW; @@ -475,22 +450,18 @@ int mode; rstio.c_cflag &= ~(CSIZE|PARODD|PARENB); rstio.c_cflag |= VarParity; if (cfsetspeed(&rstio, IntToSpeed(VarSpeed)) == -1) { - logprintf("Unable to set modem speed (modem %d to %d)\n", + LogPrintf(LogWARN, "Unable to set modem speed (modem %d to %d)\n", modem, VarSpeed); } } tcsetattr(modem, TCSADRAIN, &rstio); -#ifdef DEBUG - logprintf("modem (put): iflag = %x, oflag = %x, cflag = %x\n", - rstio.c_iflag, rstio.c_oflag, rstio.c_cflag); -#endif + LogPrintf(LogDEBUG, "modem (put): iflag = %x, oflag = %x, cflag = %x\n", + rstio.c_iflag, rstio.c_oflag, rstio.c_cflag); if (!(mode & MODE_DIRECT)) if (ioctl(modem, TIOCMGET, &mbits)) return(-1); -#ifdef DEBUG - fprintf(stderr, "modem control = %o\n", mbits); -#endif + LogPrintf(LogDEBUG, "OpenModem: modem control = %o\n", mbits); oldflag = fcntl(modem, F_GETFL, 0); if (oldflag < 0) @@ -524,12 +495,7 @@ int modem; if (!isatty(modem) || DEV_IS_SYNC) return(0); if (!(mode & MODE_DIRECT) && modem >= 0 && !Online) { -#ifdef DEBUG - logprintf("mode = %d, modem = %d, mbits = %x\n", mode, modem, mbits); -#endif -#ifdef notdef - return(-1); -#endif + LogPrintf(LogDEBUG, "RawModem: mode = %d, modem = %d, mbits = %x\n", mode, modem, mbits); } tcgetattr(modem, &rstio); cfmakeraw(&rstio); @@ -545,12 +511,6 @@ int modem; if (oldflag < 0) return(-1); (void)fcntl(modem, F_SETFL, oldflag | O_NONBLOCK); -#ifdef DEBUG - oldflag = fcntl(modem, F_GETFL, 0); - logprintf("modem (put2): iflag = %x, oflag = %x, cflag = %x\n", - rstio.c_iflag, rstio.c_oflag, rstio.c_cflag); - logprintf("flag = %x\n", oldflag); -#endif return(0); } @@ -589,14 +549,11 @@ int flag; #else tcgetattr(modem, &tio); if (cfsetspeed(&tio, B0) == -1) { - logprintf("Unable to set modem to speed 0\n"); + LogPrintf(LogWARN, "Unable to set modem to speed 0\n"); } tcsetattr(modem, TCSANOW, &tio); #endif sleep(1); -#ifdef notdef - mbits &= ~TIOCM_CD; -#endif } /* * If we are working as dedicated mode, never close it @@ -697,33 +654,27 @@ int fd; { struct mqueue *queue; int nb, nw; -#ifdef QDEBUG int i; -#endif if (modemout == NULL && ModemQlen() == 0) IpStartOutput(); if (modemout == NULL) { -#ifdef QDEBUG i = PRI_LINK; -#endif for (queue = &OutputQueues[PRI_LINK]; queue >= OutputQueues; queue--) { if (queue->top) { modemout = Dequeue(queue); -#ifdef QDEBUG - if (i > PRI_NORMAL) { - struct mqueue *q; - - q = &OutputQueues[0]; - logprintf("output from queue %d, normal has %d\n", i, q->qlen); - } - logprintf("Dequeue(%d): ", i); -#endif + 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; } -#ifdef QDEBUG i--; -#endif } } if (modemout) { @@ -731,22 +682,19 @@ int fd; if (nb > 1600) nb = 1600; if (fd == 0) fd = 1; /* XXX WTFO! This is bogus */ nw = write(fd, MBUF_CTOP(modemout), nb); -#ifdef QDEBUG - logprintf("wrote: %d(%d)\n", nw, nb); - LogDumpBuff(LOG_HDLC, "modem write", MBUF_CTOP(modemout), nb); -#endif + LogPrintf(LogDEBUG, "ModemStartOutput: wrote: %d(%d)\n", nw, nb); + LogDumpBuff(LogDEBUG, "ModemStartOutput: modem write", + MBUF_CTOP(modemout), nb); if (nw > 0) { modemout->cnt -= nw; modemout->offset += nw; if (modemout->cnt == 0) { modemout = mbfree(modemout); -#ifdef QDEBUG - logprintf(" mbfree\n"); -#endif + LogPrintf(LogDEBUG, "ModemStartOutput: mbfree\n"); } } else if (nw < 0) { if (errno != EAGAIN) - perror("modem write"); + LogPrintf(LogERROR, "modem write: %s", strerror(errno)); } } } @@ -760,22 +708,20 @@ DialModem() strncpy(ScriptBuffer, VarDialScript,sizeof(ScriptBuffer)-1); ScriptBuffer[sizeof(ScriptBuffer)-1] = '\0'; if (DoChat(ScriptBuffer) > 0) { - if ((mode & (MODE_INTER|MODE_AUTO)) == MODE_INTER) - fprintf(stderr, "dial OK!\n"); + if (VarTerm) + fprintf(VarTerm, "dial OK!\n"); strncpy(ScriptBuffer, VarLoginScript,sizeof(ScriptBuffer)-1); if (DoChat(ScriptBuffer) > 0) { - if ((mode & (MODE_INTER|MODE_AUTO)) == MODE_INTER) - fprintf(stderr, "login OK!\n"); + if (VarTerm) + fprintf(VarTerm, "login OK!\n"); return EX_DONE; } - if ((mode & (MODE_INTER|MODE_AUTO)) == MODE_INTER) - fprintf(stderr, "login failed.\n"); + LogPrintf(LogWARN, "DialModem: login failed.\n"); ModemTimeout(); /* Dummy call to check modem status */ excode = EX_NOLOGIN; } else { - if ((mode & (MODE_INTER|MODE_AUTO)) == MODE_INTER) - fprintf(stderr, "dial failed.\n"); + LogPrintf(LogWARN, "DialModem: dial failed.\n"); excode = EX_NODIAL; } HangupModem(0); @@ -789,43 +735,46 @@ ShowModemStatus() int nb; #endif - printf("device: %s speed: ", VarDevice); + if (!VarTerm) + return 1; + + fprintf(VarTerm, "device: %s speed: ", VarDevice); if (DEV_IS_SYNC) - printf("sync\n"); + fprintf(VarTerm, "sync\n"); else - printf("%d\n", VarSpeed); + fprintf(VarTerm, "%d\n", VarSpeed); switch (VarParity & CSIZE) { case CS7: - printf("cs7, "); + fprintf(VarTerm, "cs7, "); break; case CS8: - printf("cs8, "); + fprintf(VarTerm, "cs8, "); break; } if (VarParity & PARENB) { if (VarParity & PARODD) - printf("odd parity, "); + fprintf(VarTerm, "odd parity, "); else - printf("even parity, "); + fprintf(VarTerm, "even parity, "); } else - printf("no parity, "); + fprintf(VarTerm, "no parity, "); - printf("CTS/RTS %s.\n", (VarCtsRts? "on" : "off")); + fprintf(VarTerm, "CTS/RTS %s.\n", (VarCtsRts? "on" : "off")); -#ifdef DEBUG - printf("fd = %d, modem control = %o\n", modem, mbits); -#endif - printf("connect count: %d\n", connect_count); + if (LogIsKept(LogDEBUG)) + fprintf(VarTerm, "fd = %d, modem control = %o\n", modem, mbits); + fprintf(VarTerm, "connect count: %d\n", connect_count); #ifdef TIOCOUTQ if (ioctl(modem, TIOCOUTQ, &nb) > 0) - printf("outq: %d\n", nb); + fprintf(VarTerm, "outq: %d\n", nb); else - printf("outq: ioctl probe failed.\n"); + fprintf(VarTerm, "outq: ioctl probe failed.\n"); #endif - printf("outqlen: %d\n", ModemQlen()); - printf("DialScript = %s\n", VarDialScript); - printf("LoginScript = %s\n", VarLoginScript); - printf("PhoneNumber(s) = %s\n", VarPhoneList); - return(1); + fprintf(VarTerm, "outqlen: %d\n", ModemQlen()); + fprintf(VarTerm, "DialScript = %s\n", VarDialScript); + fprintf(VarTerm, "LoginScript = %s\n", VarLoginScript); + fprintf(VarTerm, "PhoneNumber(s) = %s\n", VarPhoneList); + + return 0; } diff --git a/usr.sbin/ppp/modem.h b/usr.sbin/ppp/modem.h index b4befe0..1cdace7 100644 --- a/usr.sbin/ppp/modem.h +++ b/usr.sbin/ppp/modem.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: modem.h,v 1.7 1997/02/22 16:10:37 peter Exp $ * * TODO: */ @@ -24,22 +24,21 @@ #define _MODEM_H_ #include <termios.h> #include "mbuf.h" -#include "cdefs.h" -extern int RawModem __P((int)); -extern void UnrawModem __P((int)); -extern void UpModem __P((int)); -extern void DownModem __P((int)); -extern void WriteModem __P((int, char *, int)); -extern void ModemStartOutput __P((int)); -extern int OpenModem __P((int)); -extern void CloseModem __P((void)); -extern int ModemSpeed __P((void)); -extern int ModemQlen __P((void)); -extern int DialModem __P((void)); -extern int SpeedToInt __P((speed_t)); -extern speed_t IntToSpeed __P((int)); -extern void ModemTimeout __P((void)); -extern void DownConnection __P((void)); -extern void ModemOutput __P((int, struct mbuf *)); +extern int RawModem(int); +extern void UnrawModem(int); +extern void UpModem(int); +extern void DownModem(int); +extern void WriteModem(int, char *, int); +extern void ModemStartOutput(int); +extern int OpenModem(int); +extern void CloseModem(void); +extern int ModemSpeed(void); +extern int ModemQlen(void); +extern int DialModem(void); +extern int SpeedToInt(speed_t); +extern speed_t IntToSpeed(int); +extern void ModemTimeout(void); +extern void DownConnection(void); +extern void ModemOutput(int, struct mbuf *); #endif diff --git a/usr.sbin/ppp/nat_cmd.c b/usr.sbin/ppp/nat_cmd.c index 0603c7a..f6aa1be 100644 --- a/usr.sbin/ppp/nat_cmd.c +++ b/usr.sbin/ppp/nat_cmd.c @@ -30,9 +30,10 @@ AliasRedirectPort (struct cmdtab *list, char **argv, void *param) { - if (!(mode & MODE_ALIAS)) - printf("alias not enabled\n"); - else if (argc == 3) { + 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; @@ -48,23 +49,30 @@ AliasRedirectPort (struct cmdtab *list, } else if (strcmp(proto, "udp") == 0) { proto_constant = IPPROTO_UDP; } else { - printf("port redirect: protocol must be tcp or udp\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); + 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) { - printf("port redirect: error reading local addr:port\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); - return 1; + 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) { - printf("port redirect: error reading alias port\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); - return 1; + 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; @@ -74,11 +82,11 @@ AliasRedirectPort (struct cmdtab *list, null_addr, alias_port, proto_constant); - if (link == NULL) - printf("port redirect: error returned by packed aliasing engine" - "(code=%d)\n", error); - } else - printf("Usage: alias %s %s\n", list->name, list->syntax); + 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; } @@ -90,9 +98,10 @@ AliasRedirectAddr(struct cmdtab *list, char **argv, void *param) { - if (!(mode & MODE_ALIAS)) - printf("alias not enabled\n"); - else if (argc == 2) { + 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; @@ -100,25 +109,27 @@ AliasRedirectAddr(struct cmdtab *list, error = StrToAddr(argv[0], &local_addr); if (error) { - printf("address redirect: invalid local address\n"); + if (VarTerm) + fprintf(VarTerm, "address redirect: invalid local address\n"); return 1; } error = StrToAddr(argv[1], &alias_addr); if (error) { - printf("address redirect: invalid alias address\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); - return 1; + 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) { - printf("address redirect: packet aliasing engine error\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); + 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 - printf("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; } @@ -136,7 +147,7 @@ StrToAddr (char* str, hp = gethostbyname (str); if (!hp) { - fprintf (stderr, "Unknown host %s.\n", str); + LogPrintf(LogWARN, "StrToAddr: Unknown host %s.\n", str); return -1; } @@ -164,8 +175,8 @@ StrToPort (char *str, sp = getservbyname (str, proto); if (!sp) { - fprintf (stderr, "Unknown port or service %s/%s.\n", - str, proto); + LogPrintf(LogWARN, "StrToAddr: Unknown port or service %s/%s.\n", + str, proto); return -1; } @@ -185,7 +196,8 @@ StrToAddrAndPort (char* str, ptr = strchr (str, ':'); if (!ptr) { - fprintf (stderr, "%s is missing port number.\n", str); + LogPrintf(LogWARN, "StrToAddrAndPort: %s is missing port number.\n", + str); return -1; } diff --git a/usr.sbin/ppp/os.c b/usr.sbin/ppp/os.c index d2a161a..2c384ef 100644 --- a/usr.sbin/ppp/os.c +++ b/usr.sbin/ppp/os.c @@ -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.20 1997/06/01 01:13:03 brian Exp $ + * $Id: os.c,v 1.21 1997/06/01 03:43:26 brian Exp $ * */ #include "fsm.h" @@ -70,7 +70,7 @@ int updown; s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { - perror("socket"); + LogPrintf(LogERROR, "socket: %s", strerror(errno)); return(-1); } @@ -84,11 +84,8 @@ int updown; bzero(&ifra.ifra_addr, sizeof(ifra.ifra_addr)); bzero(&ifra.ifra_broadaddr, sizeof(ifra.ifra_addr)); bzero(&ifra.ifra_mask, sizeof(ifra.ifra_addr)); -#ifdef DEBUG - logprintf("DIFADDR\n"); -#endif if (ioctl(s, SIOCDIFADDR, &ifra) < 0) { - perror("SIOCDIFADDR"); + LogPrintf(LogERROR, "ioctl(SIOCDIFADDR): %s", strerror(errno)); close(s); return(-1); } @@ -148,17 +145,17 @@ int updown; */ bcopy(&ifra.ifra_addr, &ifrq.ifr_addr, sizeof(struct sockaddr)); if (ioctl(s, SIOCSIFADDR, &ifra) < 0) - perror("SIFADDR");; + LogPrintf(LogERROR, "ioctl(SIFADDR): %s", strerror(errno)); bcopy(&ifra.ifra_broadaddr, &ifrq.ifr_dstaddr, sizeof(struct sockaddr)); if (ioctl(s, SIOCSIFDSTADDR, &ifrq) < 0) - perror("SIFDSTADDR");; + 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) - perror("SIFBRDADDR"); + LogPrintf(LogERROR, "ioctl(SIFBRDADDR): %s", strerror(errno)); #endif } else if (ioctl(s, SIOCAIFADDR, &ifra) < 0) { - perror("SIOCAIFADDR"); + LogPrintf(LogERROR, "ioctl(SIOCAIFADDR): %s", strerror(errno)); close(s); return(-1); } @@ -186,20 +183,23 @@ OsLinkup() if (linkup == 0) { if (setuid(0) < 0) - logprintf("setuid failed\n"); + LogPrintf(LogERROR, "setuid failed\n"); reconnectState = RECON_UNKNOWN; if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) { char c = EX_NORMAL; if (write(BGFiledes[1],&c,1) == 1) - LogPrintf(LOG_PHASE_BIT,"Parent notified of success.\n"); + LogPrintf(LogPHASE,"Parent notified of success.\n"); else - LogPrintf(LOG_PHASE_BIT,"Failed to notify parent of success.\n"); + 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); - LogPrintf(LOG_LINK_BIT|LOG_LCP_BIT, "OsLinkup: %s\n", s); + if (LogIsKept(LogLINK)) + LogPrintf(LogLINK, "OsLinkup: %s\n", s); + else + LogPrintf(LogLCP, "OsLinkup: %s\n", s); if (SelectSystem(inet_ntoa(IpcpInfo.want_ipaddr), LINKFILE) < 0) { if (dstsystem) { @@ -219,9 +219,14 @@ OsLinkdown() if (linkup) { s = (char *)inet_ntoa(peer_addr); - LogPrintf(LOG_LINK_BIT|LOG_LCP_BIT, "OsLinkdown: %s\n", s); + if (LogIsKept(LogLINK)) + LogPrintf(LogLINK, "OsLinkdown: %s\n", s); + else + LogPrintf(LogLCP, "OsLinkdown: %s\n", s); + if (!(mode & MODE_AUTO)) DeleteIfRoutes(0); + linkup = 0; } } @@ -238,12 +243,12 @@ int final; return(0); s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { - perror("socket"); + LogPrintf(LogERROR, "socket: %s", strerror(errno)); return(-1); } ifrq.ifr_flags &= ~IFF_UP; if (ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) { - perror("SIOCSIFFLAGS"); + LogPrintf(LogERROR, "ioctl(SIOCSIFFLAGS): %s", strerror(errno)); close(s); return(-1); } @@ -267,7 +272,7 @@ int type, mtu, speed; info.mtu = VarPrefMTU; info.baudrate = speed; if (ioctl(tun_out, TUNSIFINFO, &info) < 0) - perror("TUNSIFINFO"); + LogPrintf(LogERROR, "ioctl(TUNSIFINFO): %s", strerror(errno)); } /* @@ -287,30 +292,32 @@ int *ptun; char ifname[IFNAMSIZ]; 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 ); tun_out = open(devname, O_RDWR); if( tun_out >= 0 ) break; - if( errno == ENXIO ) - unit=MAX_TUN+1; - else if( errno == ENOENT ) { + if( errno == ENXIO ) { + unit = MAX_TUN; + err = errno; + } else if( errno == ENOENT ) { enoentcount++; if( enoentcount > 2 ) - unit=MAX_TUN+1; - } + unit=MAX_TUN; + } else + err = errno; } if( unit > MAX_TUN ) { - fprintf(stderr, "No tunnel device is available.\n"); - return(-1); + if (VarTerm) + fprintf(VarTerm, "No tunnel device is available (%s).\n", strerror(err)); + return -1; } *ptun = unit; - if (logptr != NULL) - LogClose(); - if (LogOpen(unit)) - return(-1); + LogSetTun(unit); /* * At first, name the interface. @@ -325,7 +332,7 @@ int *ptun; s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { - perror("socket"); + LogPrintf(LogERROR, "socket: %s", strerror(errno)); return(-1); } @@ -333,14 +340,14 @@ int *ptun; * Now, bring up the interface. */ if (ioctl(s, SIOCGIFFLAGS, &ifrq) < 0) { - perror("SIOCGIFFLAGS"); + LogPrintf(LogERROR, "ioctl(SIOCGIFFLAGS): %s", strerror(errno)); close(s); return(-1); } ifrq.ifr_flags |= IFF_UP; if (ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) { - perror("SIOCSIFFLAGS"); + LogPrintf(LogERROR, "ioctl(SIOCSIFFLAGS): %s", strerror(errno)); close(s); return(-1); } @@ -348,13 +355,13 @@ int *ptun; tun_in = tun_out; IfDevName = devname + 5; if (GetIfIndex(IfDevName) < 0) { - fprintf(stderr, "can't find ifindex.\n"); + LogPrintf(LogERROR, "OpenTunnel: Can't find ifindex.\n"); close(s); return(-1); } - if (!(mode & MODE_DIRECT)) - printf("Using interface: %s\r\n", IfDevName); - LogPrintf(LOG_PHASE_BIT, "Using interface: %s\n", IfDevName); + if (VarTerm) + fprintf(VarTerm, "Using interface: %s\n", IfDevName); + LogPrintf(LogPHASE, "Using interface: %s\n", IfDevName); close(s); return(0); } diff --git a/usr.sbin/ppp/os.h b/usr.sbin/ppp/os.h index 461fe01..6e9e827 100644 --- a/usr.sbin/ppp/os.h +++ b/usr.sbin/ppp/os.h @@ -15,23 +15,23 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: os.h,v 1.5 1997/02/22 16:10:39 peter Exp $ * * TODO: */ #ifndef _OS_H_ #define _OS_H_ -#include "cdefs.h" -int OsSetIpaddress __P((struct in_addr myaddr, struct in_addr hisaddr, struct in_addr netmask)); -int OsInterfaceDown __P((int)); -void OsSetInterfaceParams __P((int type, int mtu, int speed)); -int OpenTunnel __P((int *)); -void OsCloseLink __P((int flag)); -void OsLinkup __P((void)), OsLinkdown __P((void)); -void OsSetRoute __P((int, struct in_addr, struct in_addr, struct in_addr)); -void DeleteIfRoutes __P((int)); -void OsAddInOctets __P((int cnt)); -void OsAddOutOctets __P((int cnt)); +int OsSetIpaddress(struct in_addr myaddr, struct in_addr hisaddr, struct in_addr netmask); +int OsInterfaceDown(int); +void OsSetInterfaceParams(int type, int mtu, int speed); +int OpenTunnel(int *); +void OsCloseLink(int flag); +void OsLinkup(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 diff --git a/usr.sbin/ppp/pap.c b/usr.sbin/ppp/pap.c index 89c387d..75f4384 100644 --- a/usr.sbin/ppp/pap.c +++ b/usr.sbin/ppp/pap.c @@ -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.11 1997/05/24 17:32:42 brian Exp $ + * $Id: pap.c,v 1.12 1997/05/26 00:44:08 brian Exp $ * * TODO: */ @@ -32,7 +32,7 @@ #include "phase.h" #include "auth.h" -#ifdef PASSWDAUTH +#ifndef NOPASSWDAUTH # include "passwdauth.h" #endif @@ -56,10 +56,9 @@ int papid; namelen = strlen(VarAuthName); keylen = strlen(VarAuthKey); plen = namelen + keylen + 2; -#ifdef DEBUG - logprintf("namelen = %d, keylen = %d\n", namelen, keylen); -#endif - LogPrintf(LOG_PHASE_BIT, "PAP: %s (%s)\n", VarAuthName, VarAuthKey); + LogPrintf(LogDEBUG, "SendPapChallenge: namelen = %d, keylen = %d\n", + namelen, keylen); + LogPrintf(LogPHASE, "PAP: %s (%s)\n", VarAuthName, VarAuthKey); lh.code = PAP_REQUEST; lh.id = papid; lh.length = htons(plen + sizeof(struct fsmheader)); @@ -96,7 +95,7 @@ int code; cp = MBUF_CTOP(bp) + sizeof(struct fsmheader); *cp++ = mlen; bcopy(message, cp, mlen); - LogPrintf(LOG_PHASE_BIT, "PapOutput: %s\n", papcodes[code]); + LogPrintf(LogPHASE, "PapOutput: %s\n", papcodes[code]); HdlcOutput(PRI_LINK, PROTO_PAP, bp); } @@ -113,17 +112,16 @@ u_char *name, *key; klen = *key; *key++ = 0; key[klen] = 0; -#ifdef DEBUG - logprintf("name: %s (%d), key: %s (%d)\n", name, nlen, key, klen); -#endif + LogPrintf(LogDEBUG, "PapValidate: name %s (%d), key %s (%d)\n", + name, nlen, key, klen); -#ifdef PASSWDAUTH +#ifndef NOPASSWDAUTH if( Enabled( ConfPasswdAuth ) ) { - LogPrintf( LOG_LCP, "PasswdAuth enabled - calling\n" ); + LogPrintf( LogLCP, "PasswdAuth enabled - calling\n" ); return PasswdAuth( name, key ); } -#endif /* PASSWDAUTH */ +#endif return(AuthValidate(SECRETFILE, name, key)); } @@ -142,7 +140,7 @@ struct mbuf *bp; if (len >= ntohs(php->length)) { if (php->code < PAP_REQUEST || php->code > PAP_NAK) php->code = 0; - LogPrintf(LOG_PHASE_BIT, "PapInput: %s\n", papcodes[php->code]); + LogPrintf(LogPHASE, "PapInput: %s\n", papcodes[php->code]); switch (php->code) { case PAP_REQUEST: @@ -163,7 +161,7 @@ struct mbuf *bp; cp = (u_char *)(php + 1); len = *cp++; cp[len] = 0; - LogPrintf(LOG_PHASE_BIT, "Received PAP_ACK (%s)\n", cp); + LogPrintf(LogPHASE, "Received PAP_ACK (%s)\n", cp); if (lcp->auth_iwait == PROTO_PAP) { lcp->auth_iwait = 0; if (lcp->auth_ineed == 0) @@ -175,7 +173,7 @@ struct mbuf *bp; cp = (u_char *)(php + 1); len = *cp++; cp[len] = 0; - LogPrintf(LOG_PHASE_BIT, "Received PAP_NAK (%s)\n", cp); + LogPrintf(LogPHASE, "Received PAP_NAK (%s)\n", cp); reconnect(RECON_FALSE); LcpClose(); break; diff --git a/usr.sbin/ppp/passwdauth.c b/usr.sbin/ppp/passwdauth.c index 5de62f7..78f738d 100644 --- a/usr.sbin/ppp/passwdauth.c +++ b/usr.sbin/ppp/passwdauth.c @@ -36,16 +36,14 @@ char *name, *key; char *salt, *ep; struct utmp utmp; -#ifdef DEBUG - logprintf( "passwdauth called with name= %s, key= %s\n", name, key ); -#endif /* DEBUG */ + LogPrintf(LogDEBUG, "PasswdAuth: Called with name %s, key %s\n", name, key ); if(( pwd = getpwnam( name ) )) salt = pwd->pw_passwd; else { endpwent(); - LogPrintf( LOG_LCP, "PasswdAuth - user (%s) not in passwd file\n", name ); + LogPrintf( LogLCP, "PasswdAuth - user (%s) not in passwd file\n", name ); return 0; /* false - failed to authenticate (password not in file) */ } @@ -58,7 +56,7 @@ char *name, *key; if( name[0] != 'P' ) { - LogPrintf( LOG_LCP, "PasswdAuth - user (%s) not a PPP user\n", name ); + LogPrintf( LogLCP, "PasswdAuth - user (%s) not a PPP user\n", name ); endpwent(); return 0; } @@ -70,7 +68,7 @@ char *name, *key; /* strcmp returns 0 if same */ if( strcmp( ep, pwd->pw_passwd ) != 0 ) { - LogPrintf( LOG_LCP, "PasswdAuth - user (%s,%s) authentication failed\n", + LogPrintf( LogLCP, "PasswdAuth - user (%s,%s) authentication failed\n", name, key ); endpwent(); return 0; /* false - failed to authenticate (didn't match up) */ @@ -100,7 +98,7 @@ char *name, *key; login(&utmp); (void)setlogin( pwd->pw_name ); - LogPrintf( LOG_LCP, "PasswdAuth has logged in user %s\n", name ); + LogPrintf( LogLCP, "PasswdAuth has logged in user %s\n", name ); logged_in = 1; } diff --git a/usr.sbin/ppp/passwdauth.h b/usr.sbin/ppp/passwdauth.h index da34ccb..05ba1f3 100644 --- a/usr.sbin/ppp/passwdauth.h +++ b/usr.sbin/ppp/passwdauth.h @@ -6,6 +6,6 @@ #ifndef _PASSWDAUTH_H_ #define _PASSWDAUTH_H_ -extern int PasswdAuth __P((char *, char *)); +extern int PasswdAuth(char *, char *); #endif diff --git a/usr.sbin/ppp/phase.h b/usr.sbin/ppp/phase.h index 25614c4..2bee812 100644 --- a/usr.sbin/ppp/phase.h +++ b/usr.sbin/ppp/phase.h @@ -15,14 +15,13 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: phase.h,v 1.5 1997/02/22 16:10:44 peter Exp $ * * TODO: */ #ifndef _PHASE_H_ #define _PHASE_H_ -#include "cdefs.h" #define PHASE_DEAD 0 /* Link is dead */ #define PHASE_ESTABLISH 1 /* Establishing link */ @@ -33,6 +32,6 @@ int phase; /* Curent phase */ -extern void NewPhase __P((int)); +extern void NewPhase(int); extern char *PhaseNames[]; #endif diff --git a/usr.sbin/ppp/pred.c b/usr.sbin/ppp/pred.c index d7fb09d..93d2a96 100644 --- a/usr.sbin/ppp/pred.c +++ b/usr.sbin/ppp/pred.c @@ -5,7 +5,7 @@ /* * - * $Id: pred.c,v 1.10 1997/05/10 01:22:18 brian Exp $ + * $Id: pred.c,v 1.11 1997/06/01 11:35:04 brian Exp $ * * pred.c -- Test program for Dave Rand's rendition of the * predictor algorithm @@ -130,9 +130,7 @@ Pred1Output(int pri, u_short proto, struct mbuf *bp) fcs = ~fcs; len = compress(bufp + 2, wp, orglen); -#ifdef DEBUG - logprintf("orglen (%d) --> len (%d)\n", orglen, len); -#endif + LogPrintf(LogDEBUG, "Pred1Output: orglen (%d) --> len (%d)\n", orglen, len); CcpInfo.orgout += orglen; if (len < orglen) { *hp |= 0x80; @@ -174,7 +172,7 @@ struct mbuf *bp; CcpInfo.compin += olen; len &= 0x7fff; if (len != len1) { /* Error is detected. Send reset request */ - LogPrintf(LOG_LCP_BIT, "%s: Length Error\n", CcpFsm.name); + LogPrintf(LogLCP, "%s: Length Error\n", CcpFsm.name); CcpSendResetReq(&CcpFsm); pfree(bp); pfree(wp); @@ -191,11 +189,10 @@ struct mbuf *bp; *pp++ = *cp++; /* CRC */ *pp++ = *cp++; fcs = HdlcFcs(INITFCS, bufp, wp->cnt = pp - bufp); -#ifdef DEBUG if (fcs != GOODFCS) - logprintf("fcs = 0x%04x (%s), len = 0x%x, olen = 0x%x\n", - fcs, (fcs == GOODFCS)? "good" : "bad", len, olen); -#endif + LogPrintf(LogDEBUG, "Pred1Input: fcs = 0x%04x (%s), len = 0x%x," + " olen = 0x%x\n", fcs, (fcs == GOODFCS)? "good" : "bad", + len, olen); if (fcs == GOODFCS) { wp->offset += 2; /* skip length */ wp->cnt -= 4; /* skip length & CRC */ @@ -213,7 +210,7 @@ struct mbuf *bp; } else { - LogDumpBp(LOG_HDLC, "Bad FCS", wp); + LogDumpBp(LogHDLC, "Bad FCS", wp); CcpSendResetReq(&CcpFsm); pfree(wp); } diff --git a/usr.sbin/ppp/pred.h b/usr.sbin/ppp/pred.h index 1e49c58..356a034 100644 --- a/usr.sbin/ppp/pred.h +++ b/usr.sbin/ppp/pred.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: pred.h,v 1.3 1997/02/22 16:10:48 peter Exp $ * * TODO: */ @@ -23,7 +23,7 @@ #ifndef _PRED_H_ #define _PRED_H_ -extern void Pred1Output __P((int, u_short, struct mbuf *bp)); -extern void Pred1Input __P((struct mbuf*)); -extern void Pred1Init __P((int)); +extern void Pred1Output(int, u_short, struct mbuf *bp); +extern void Pred1Input(struct mbuf*); +extern void Pred1Init(int); #endif diff --git a/usr.sbin/ppp/route.c b/usr.sbin/ppp/route.c index c475935..7fcbd49 100644 --- a/usr.sbin/ppp/route.c +++ b/usr.sbin/ppp/route.c @@ -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.12 1997/02/22 16:10:49 peter Exp $ + * $Id: route.c,v 1.13 1997/05/10 01:22:18 brian Exp $ * */ #include <sys/types.h> @@ -25,11 +25,7 @@ #include <sys/ioctl.h> #include <sys/param.h> #include <sys/socket.h> -#if (BSD >= 199306) #include <sys/sysctl.h> -#else -#include <sys/kinfo.h> -#endif #include <sys/time.h> #include <errno.h> @@ -45,6 +41,8 @@ #include <arpa/inet.h> #include "log.h" +#include "loadalias.h" +#include "vars.h" static int IfIndex; @@ -70,7 +68,7 @@ struct in_addr mask; s = socket(PF_ROUTE, SOCK_RAW, 0); if (s < 0) - logprintf("socket\n"); + LogPrintf(LogERROR, "socket: %s", strerror(errno)); bzero(&rtmes, sizeof(rtmes)); rtmes.m_rtm.rtm_version = RTM_VERSION; @@ -113,12 +111,11 @@ struct in_addr mask; rtmes.m_rtm.rtm_msglen = nb; wb = write(s, &rtmes, nb); if (wb < 0) { - LogPrintf(LOG_TCPIP_BIT, "Already set route addr dst=%x, gateway=%x\n" + LogPrintf(LogTCPIP, "Already set route addr dst=%x, gateway=%x\n" ,dst.s_addr, gateway.s_addr); } -#ifdef DEBUG - logprintf("wrote %d: dst = %x, gateway = %x\n", nb, dst.s_addr, gateway.s_addr); -#endif + LogPrintf(LogDEBUG, "wrote %d: dst = %x, gateway = %x\n", nb, + dst.s_addr, gateway.s_addr); close(s); } @@ -127,12 +124,14 @@ p_sockaddr(sa, width) struct sockaddr *sa; int width; { - register char *cp; - register struct sockaddr_in *sin = (struct sockaddr_in *)sa; + if (VarTerm) { + register char *cp; + register struct sockaddr_in *sin = (struct sockaddr_in *)sa; - cp = (sin->sin_addr.s_addr == 0) ? "default" : + cp = (sin->sin_addr.s_addr == 0) ? "default" : inet_ntoa(sin->sin_addr); - printf("%-*.*s ", width, width, cp); + fprintf(VarTerm, "%-*.*s ", width, width, cp); + } } struct bits { @@ -156,14 +155,16 @@ p_flags(f, format) register int f; char *format; { - char name[33], *flags; - register struct bits *p = bits; - - for (flags = name; p->b_mask; p++) - if (p->b_mask & f) - *flags++ = p->b_val; - *flags = '\0'; - printf(format, name); + if (VarTerm) { + char name[33], *flags; + register struct bits *p = bits; + + for (flags = name; p->b_mask; p++) + if (p->b_mask & f) + *flags++ = p->b_val; + *flags = '\0'; + fprintf(VarTerm, format, name); + } } int @@ -176,11 +177,11 @@ ShowRoute() int *lp; int needed, nb; u_long mask; -#if (BSD >= 199306) int mib[6]; -#endif -#if (BSD >= 199306) + if (!VarTerm) + return 1; + mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; @@ -188,28 +189,21 @@ ShowRoute() mib[4] = NET_RT_DUMP; mib[5] = 0; if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { - perror("sysctl-estimate"); + LogPrintf(LogERROR, "sysctl: estimate: %s", strerror(errno)); return(1); } -#else - needed = getkerninfo(KINFO_RT_DUMP, 0, 0, 0); -#endif + if (needed < 0) return(1); sp = malloc(needed); if (sp == NULL) return(1); -#if (BSD >= 199306) if (sysctl(mib, 6, sp, &needed, NULL, 0) < 0) { - perror("sysctl-getroute"); + LogPrintf(LogERROR, "sysctl: getroute: %s", strerror(errno)); free(sp); return(1); } -#else - if (getkerninfo(KINFO_RT_DUMP, sp, &needed, 0) < 0) - free(sp); - return(1); -#endif + ep = sp + needed; for (cp = sp; cp < ep; cp += rtm->rtm_msglen) { @@ -227,9 +221,7 @@ ShowRoute() p_sockaddr(sa, 18); lp = (int *)(sa->sa_len + (char *)sa); if ((char *)lp < (char *)wp && *lp) { -#ifdef DEBUG - logprintf(" flag = %x, rest = %d", rtm->rtm_flags, *lp); -#endif + LogPrintf(LogDEBUG, " flag = %x, rest = %d", rtm->rtm_flags, *lp); wp = (u_char *)(lp + 1); mask = 0; for (nb = *(char *)lp; nb > 4; nb--) { @@ -240,12 +232,12 @@ ShowRoute() mask <<= 8; } } - printf("%08lx ", mask); + fprintf(VarTerm, "%08lx ", mask); p_flags(rtm->rtm_flags & (RTF_UP|RTF_GATEWAY|RTF_HOST), "%-6.6s "); - printf("(%d)\n", rtm->rtm_index); + fprintf(VarTerm, "(%d)\n", rtm->rtm_index); } free(sp); - return(1); + return 0; } /* @@ -263,14 +255,10 @@ int all; u_long mask; int *lp, nb; u_char *wp; -#if (BSD >= 199306) int mib[6]; -#endif -#ifdef DEBUG - logprintf("DeleteIfRoutes (%d)\n", IfIndex); -#endif -#if (BSD >= 199306) + LogPrintf(LogDEBUG, "DeleteIfRoutes (%d)\n", IfIndex); + mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; @@ -278,12 +266,9 @@ int all; mib[4] = NET_RT_DUMP; mib[5] = 0; if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { - perror("sysctl-estimate"); + LogPrintf(LogERROR, "sysctl: estimate: %s", strerror(errno)); return; } -#else - needed = getkerninfo(KINFO_RT_DUMP, 0, 0, 0); -#endif if (needed < 0) return; @@ -292,28 +277,20 @@ int all; if (sp == NULL) return; -#if (BSD >= 199306) if (sysctl(mib, 6, sp, &needed, NULL, 0) < 0) { - free(sp); - perror("sysctl-getroute"); - return; - } -#else - if (getkerninfo(KINFO_RT_DUMP, sp, &needed, 0) < 0) { + LogPrintf(LogERROR, "sysctl: getroute: %s", strerror(errno)); free(sp); return; } -#endif ep = sp + needed; for (cp = sp; cp < ep; cp += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)cp; sa = (struct sockaddr *)(rtm + 1); -#ifdef DEBUG - logprintf("addrs: %x, index: %d, flags: %x, dstnet: %x\n", - rtm->rtm_addrs, rtm->rtm_index, rtm->rtm_flags, - ((struct sockaddr_in *)sa)->sin_addr); -#endif + LogPrintf(LogDEBUG, "DeleteIfRoutes: addrs: %x, index: %d, flags: %x," + " dstnet: %x\n", + rtm->rtm_addrs, rtm->rtm_index, rtm->rtm_flags, + ((struct sockaddr_in *)sa)->sin_addr); if (rtm->rtm_addrs != RTA_DST && (rtm->rtm_index == IfIndex) && (all || (rtm->rtm_flags & RTF_GATEWAY))) { @@ -326,9 +303,8 @@ int all; lp = (int *)(sa->sa_len + (char *)sa); mask = 0; if ((char *)lp < (char *)wp && *lp) { -#ifdef DEBUG - printf(" flag = %x, rest = %d", rtm->rtm_flags, *lp); -#endif + LogPrintf(LogDEBUG, "DeleteIfRoutes: flag = %x, rest = %d", + rtm->rtm_flags, *lp); wp = (u_char *)(lp + 1); for (nb = *lp; nb > 4; nb--) { mask <<= 8; @@ -337,10 +313,9 @@ int all; for (nb = 8 - *lp; nb > 0; nb--) mask <<= 8; } -#ifdef DEBUG - logprintf("## %s ", inet_ntoa(dstnet)); - logprintf(" %s %d\n", inet_ntoa(gateway), rtm->rtm_index); -#endif + LogPrintf(LogDEBUG, "DeleteIfRoutes: Dest: %s\n", inet_ntoa(dstnet)); + LogPrintf(LogDEBUG, "DeleteIfRoutes: Gw: %s\n", inet_ntoa(gateway)); + LogPrintf(LogDEBUG, "DeleteIfRoutes: Index: %d\n", rtm->rtm_index); if (dstnet.s_addr == INADDR_ANY) { gateway.s_addr = INADDR_ANY; mask = INADDR_ANY; @@ -348,11 +323,9 @@ int all; maddr.s_addr = htonl(mask); OsSetRoute(RTM_DELETE, dstnet, gateway, maddr); } -#ifdef DEBUG - else if (rtm->rtm_index == IfIndex) { - logprintf("??? addrs: %x, flags = %x\n", rtm->rtm_addrs, rtm->rtm_flags); - } -#endif + else if(rtm->rtm_index == IfIndex) + LogPrintf(LogDEBUG, "DeleteIfRoutes: Ignoring (looking for index %d)\n", + IfIndex); } free(sp); } @@ -374,7 +347,7 @@ char *name; s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { - perror("socket"); + LogPrintf(LogERROR, "socket: %s", strerror(errno)); return(-1); } @@ -388,13 +361,11 @@ char *name; oldbufsize = ifconfs.ifc_len; bufsize += 1+sizeof(struct ifreq); buffer = realloc((void *)buffer, bufsize); /* Make it bigger */ -#ifdef DEBUG - logprintf ("Growing buffer to %d\n", bufsize); -#endif + LogPrintf(LogDEBUG, "GetIfIndex: Growing buffer to %d\n", bufsize); ifconfs.ifc_len = bufsize; ifconfs.ifc_buf = buffer; if (ioctl(s, SIOCGIFCONF, &ifconfs) < 0) { - perror("IFCONF"); + LogPrintf(LogERROR, "ioctl(SIOCGIFCONF): %s", strerror(errno)); free(buffer); return(-1); } @@ -406,10 +377,9 @@ char *name; for (len = ifconfs.ifc_len; len > 0; len -= sizeof(struct ifreq)) { elen = ifrp->ifr_addr.sa_len - sizeof(struct sockaddr); if (ifrp->ifr_addr.sa_family == AF_LINK) { -#ifdef DEBUG - logprintf("%d: %-*.*s, %d, %d\n", index, IFNAMSIZ, IFNAMSIZ, ifrp->ifr_name, - ifrp->ifr_addr.sa_family, elen); -#endif + LogPrintf(LogDEBUG, "GetIfIndex: %d: %-*.*s, %d, %d\n", + index, IFNAMSIZ, IFNAMSIZ, ifrp->ifr_name, + ifrp->ifr_addr.sa_family, elen); if (strcmp(ifrp->ifr_name, name) == 0) { IfIndex = index; free(buffer); diff --git a/usr.sbin/ppp/route.h b/usr.sbin/ppp/route.h index 764042c..43f1011 100644 --- a/usr.sbin/ppp/route.h +++ b/usr.sbin/ppp/route.h @@ -17,11 +17,11 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: route.h,v 1.3 1997/02/22 16:10:50 peter Exp $ * */ #ifndef _ROUTE_H_ #define _ROUTE_H_ -int GetIfIndex __P((char *)); +int GetIfIndex(char *); #endif diff --git a/usr.sbin/ppp/sig.c b/usr.sbin/ppp/sig.c index c54ea77..b9c1451 100644 --- a/usr.sbin/ppp/sig.c +++ b/usr.sbin/ppp/sig.c @@ -26,13 +26,12 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: sig.c,v 1.4 1997/02/25 14:05:10 brian Exp $ + * $Id: sig.c,v 1.6 1997/03/13 12:45:33 brian Exp $ * * TODO: * */ -#include <sys/cdefs.h> #include "sig.h" #include <sys/types.h> #include <signal.h> @@ -60,7 +59,8 @@ sig_type pending_signal(int sig,sig_type fn) { if (sig <= 0 || sig > NSIG) { /* Oops - we must be a bit out of date (too many sigs ?) */ - logprintf("Eeek! %s:%s: I must be out of date!\n",__FILE__,__LINE__); + LogPrintf(LogALERT, "Eeek! %s:%s: I must be out of date!\n", + __FILE__,__LINE__); return signal(sig,fn); } diff --git a/usr.sbin/ppp/sig.h b/usr.sbin/ppp/sig.h index 42598a6..1584edc 100644 --- a/usr.sbin/ppp/sig.h +++ b/usr.sbin/ppp/sig.h @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: sig.h,v 1.5 1997/02/25 14:05:13 brian Exp $ + * $Id: sig.h,v 1.7 1997/03/13 12:45:35 brian Exp $ * * TODO: * @@ -35,7 +35,7 @@ typedef void (*sig_type)(int); /* Call this instead of signal() */ -extern sig_type pending_signal __P((int, sig_type)); +extern sig_type pending_signal(int, sig_type); /* Call this when you want things to *actually* happen */ -extern void handle_signals __P((void)); +extern void handle_signals(void); diff --git a/usr.sbin/ppp/slcompress.c b/usr.sbin/ppp/slcompress.c index d0c5883..39babc9 100644 --- a/usr.sbin/ppp/slcompress.c +++ b/usr.sbin/ppp/slcompress.c @@ -17,13 +17,13 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: slcompress.c,v 1.8 1997/02/22 16:10:54 peter Exp $ * * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989: * - Initial distribution. */ #ifndef lint -static char const rcsid[] = "$Id$"; +static char const rcsid[] = "$Id: slcompress.c,v 1.8 1997/02/22 16:10:54 peter Exp $"; #endif #include "defs.h" @@ -32,6 +32,8 @@ static char const rcsid[] = "$Id$"; #include <netinet/tcp.h> #include <netinet/ip.h> #include "slcompress.h" +#include "loadalias.h" +#include "vars.h" struct slstat slstat; @@ -139,28 +141,19 @@ sl_compress_tcp(m, ip, comp, compress_cid) * set). (We assume that the caller has already made sure the * packet is IP proto TCP). */ -#ifdef DEBUG if ((ip->ip_off & htons(0x3fff)) || m->cnt < 40) { - logprintf("??? 1 ip_off = %x, cnt = %d\n", ip->ip_off, m->cnt); - DumpBp(m); + LogPrintf(LogDEBUG, "??? 1 ip_off = %x, cnt = %d\n", + ip->ip_off, m->cnt); + LogDumpBp(LogDEBUG, "", m); return (TYPE_IP); } -#else - if ((ip->ip_off & htons(0x3fff)) || m->cnt < 40) - return (TYPE_IP); -#endif th = (struct tcphdr *)&((int *)ip)[hlen]; -#ifdef DEBUG if ((th->th_flags & (TH_SYN|TH_FIN|TH_RST|TH_ACK)) != TH_ACK) { - logprintf("??? 2 th_flags = %x\n", th->th_flags); - DumpBp(m); + LogPrintf(LogDEBUG, "??? 2 th_flags = %x\n", th->th_flags); + LogDumpBp(LogDEBUG, "", m); return (TYPE_IP); } -#else - if ((th->th_flags & (TH_SYN|TH_FIN|TH_RST|TH_ACK)) != TH_ACK) - return (TYPE_IP); -#endif /* * Packet is compressible -- we're going to send either a @@ -457,9 +450,7 @@ sl_uncompress_tcp(bufp, len, type, comp) INCR(sls_compressedin) cp = *bufp; changes = *cp++; -#ifdef DEBUG - logprintf("compressed: changes = %02x\n", changes); -#endif + 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. */ @@ -512,9 +503,8 @@ sl_uncompress_tcp(bufp, len, type, comp) if (changes & NEW_A) DECODEL(th->th_ack) if (changes & NEW_S) { -#ifdef DEBUG - logprintf("NEW_S: %02x, %02x, %02x\r\n", *cp, cp[1], cp[2]); -#endif + LogPrintf(LogDEBUG, "NEW_S: %02x, %02x, %02x\n", + *cp, cp[1], cp[2]); DECODEL(th->th_seq) } break; @@ -523,9 +513,9 @@ sl_uncompress_tcp(bufp, len, type, comp) DECODES(cs->cs_ip.ip_id) } else cs->cs_ip.ip_id = htons(ntohs(cs->cs_ip.ip_id) + 1); -#ifdef DEBUG - logprintf("id = %04x, seq = %08x\r\n", cs->cs_ip.ip_id, ntohl(th->th_seq)); -#endif + + 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 @@ -575,13 +565,16 @@ bad: int ReportCompress() { - printf("Out: %d (compress) / %d (total)", + if (!VarTerm) + return 1; + + fprintf(VarTerm, "Out: %d (compress) / %d (total)", slstat.sls_compressed, slstat.sls_packets); - printf(" %d (miss) / %d (search)\n", + fprintf(VarTerm, " %d (miss) / %d (search)\n", slstat.sls_misses, slstat.sls_searches); - printf("In: %d (compress), %d (uncompress)", + fprintf(VarTerm, "In: %d (compress), %d (uncompress)", slstat.sls_compressedin, slstat.sls_uncompressedin); - printf(" %d (error), %d (tossed)\n", + fprintf(VarTerm, " %d (error), %d (tossed)\n", slstat.sls_errorin, slstat.sls_tossed); - return(1); + return 0; } diff --git a/usr.sbin/ppp/slcompress.h b/usr.sbin/ppp/slcompress.h index 9442656..35b9199 100644 --- a/usr.sbin/ppp/slcompress.h +++ b/usr.sbin/ppp/slcompress.h @@ -1,7 +1,7 @@ /* * Definitions for tcp compression routines. * - * $Header: /home/ncvs/src/usr.sbin/ppp/slcompress.h,v 1.4 1997/01/14 07:15:40 jkh Exp $ + * $Header: /home/ncvs/src/usr.sbin/ppp/slcompress.h,v 1.5 1997/02/22 16:10:55 peter Exp $ * * Copyright (c) 1989 Regents of the University of California. * All rights reserved. @@ -18,12 +18,11 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: slcompress.h,v 1.5 1997/02/22 16:10:55 peter Exp $ * * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989: * - Initial distribution. */ -#include "cdefs.h" #define MAX_STATES 16 /* must be > 2 and < 256 */ #define MAX_HDR 128 /* XXX 4bsd-ism: should really be 128 */ @@ -138,7 +137,7 @@ struct slstat { /* flag values */ #define SLF_TOSS 1 /* tossing rcvd frames because of input err */ -extern void sl_compress_init __P((struct slcompress *)); +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 __P((u_char **, int, u_int, struct slcompress *)); +extern int sl_uncompress_tcp(u_char **, int, u_int, struct slcompress *); diff --git a/usr.sbin/ppp/systems.c b/usr.sbin/ppp/systems.c index 57a4e2d..0922dde 100644 --- a/usr.sbin/ppp/systems.c +++ b/usr.sbin/ppp/systems.c @@ -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.10 1997/05/10 01:22:19 brian Exp $ + * $Id: systems.c,v 1.11 1997/05/26 00:44:09 brian Exp $ * * TODO: */ @@ -55,11 +55,11 @@ SetUserId() { if (!usermode) { if (setreuid(euid, uid) == -1) { - logprintf("unable to setreuid!\n"); + LogPrintf(LogERROR, "unable to setreuid!\n"); exit(1); } if (setregid(egid, gid) == -1) { - logprintf("unable to setregid!\n"); + LogPrintf(LogERROR, "unable to setregid!\n"); exit(1); } usermode = 1; @@ -71,11 +71,11 @@ SetPppId() { if (usermode) { if (setreuid(uid, euid) == -1) { - logprintf("unable to setreuid!\n"); + LogPrintf(LogERROR, "unable to setreuid!\n"); exit(1); } if (setregid(gid, egid) == -1) { - logprintf("unable to setregid!\n"); + LogPrintf(LogERROR, "unable to setregid!\n"); exit(1); } usermode = 0; @@ -103,7 +103,7 @@ char *file; fp = fopen(line, "r"); } if (fp == NULL) { - fprintf(stderr, "can't open %s.\n", line); + LogPrintf(LogWARN, "OpenSecret: Can't open %s.\n", line); SetPppId(); return(NULL); } @@ -126,7 +126,6 @@ char *file; FILE *fp; char *cp, *wp; int n; - int val = -1; u_char olauth; char line[200]; char filename[200]; @@ -145,15 +144,11 @@ char *file; fp = fopen(filename, "r"); } if (fp == NULL) { -#ifdef DEBUG - fprintf(stderr, "can't open %s.\n", filename); -#endif + LogPrintf(LogDEBUG, "SelectSystem: Can't open %s.\n", filename); SetPppId(); return(-1); } -#ifdef DEBUG - fprintf(stderr, "checking %s (%s).\n", name, filename); -#endif + LogPrintf(LogDEBUG, "SelectSystem: Checking %s (%s).\n", name, filename); linenum = 0; while (fgets(line, sizeof(line), fp)) { @@ -168,7 +163,7 @@ char *file; default: wp = strpbrk(cp, ":\n"); if (wp == NULL) { - fprintf(stderr, "Bad rule in %s (line %d) - missing colon.\n", + LogPrintf(LogWARN, "Bad rule in %s (line %d) - missing colon.\n", filename, linenum); exit(1); } @@ -179,9 +174,7 @@ char *file; if (*cp == ' ' || *cp == '\t') { n = strspn(cp, " \t"); cp += n; -#ifdef DEBUG - fprintf(stderr, "%s", cp); -#endif + LogPrintf(LogCOMMAND, "%s: %s", name, cp); SetPppId(); olauth = VarLocalAuth; VarLocalAuth = LOCAL_AUTH; @@ -202,7 +195,7 @@ char *file; } fclose(fp); SetPppId(); - return(val); + return -1; } int @@ -219,10 +212,11 @@ char **argv; name = "default"; if (SelectSystem(name, CONFFILE) < 0) { - printf("%s: not found.\n", name); - return(-1); + LogPrintf(LogWARN, "%s: not found.\n", name); + return -1; } - return(1); + + return 0; } int @@ -231,6 +225,6 @@ struct cmdtab *list; int argc; char **argv; { - printf("save command is not implemented (yet).\n"); - return(1); + LogPrintf(LogWARN, "save command is not implemented (yet).\n"); + return 1; } diff --git a/usr.sbin/ppp/systems.h b/usr.sbin/ppp/systems.h index 823bdbb..ff85241 100644 --- a/usr.sbin/ppp/systems.h +++ b/usr.sbin/ppp/systems.h @@ -17,13 +17,13 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: systems.h,v 1.3 1997/02/22 16:10:57 peter Exp $ + * $Id: systems.h,v 1.4 1997/05/26 00:44:09 brian Exp $ * */ #ifndef _SYSTEMS_H_ #define _SYSTEMS_H_ -extern int OrigUid __P((void)); -extern void GetUid __P((void)); -extern int SelectSystem __P((char *, char*)); +extern int OrigUid(void); +extern void GetUid(void); +extern int SelectSystem(char *, char*); #endif diff --git a/usr.sbin/ppp/timeout.h b/usr.sbin/ppp/timeout.h index 4e77e20..fec8f86 100644 --- a/usr.sbin/ppp/timeout.h +++ b/usr.sbin/ppp/timeout.h @@ -15,14 +15,13 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: timeout.h,v 1.9 1997/02/22 16:10:58 peter Exp $ * * TODO: */ #ifndef _TIMEOUT_H_ #define _TIMEOUT_H_ -#include "cdefs.h" #define TICKUNIT 100000 /* Unit in usec */ #define SECTICKS (1000000/TICKUNIT) @@ -43,10 +42,12 @@ struct pppTimer { struct pppTimer *TimerList; -extern void StartTimer __P((struct pppTimer *)); -extern void StopTimer __P((struct pppTimer *)); -extern void TimerService __P((void)); -extern void InitTimerService __P((void)); -extern void TermTimerService __P((void)); -extern void StartIdleTimer __P((void)); +extern void StartTimer(struct pppTimer *); +extern void StopTimer(struct pppTimer *); +extern void TimerService(void); +extern void InitTimerService(void); +extern void TermTimerService(void); +extern void StartIdleTimer(void); +extern void UpdateIdleTimer(void); +extern void ShowTimers(); #endif /* _TIMEOUT_H_ */ diff --git a/usr.sbin/ppp/timer.c b/usr.sbin/ppp/timer.c index fbc46d9..00eaa49 100644 --- a/usr.sbin/ppp/timer.c +++ b/usr.sbin/ppp/timer.c @@ -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.15 1997/05/09 20:48:21 brian Exp $ + * $Id: timer.c,v 1.16 1997/05/10 01:22:19 brian Exp $ * * TODO: */ @@ -31,7 +31,6 @@ #include "sig.h" void StopTimerNoBlock( struct pppTimer *); -void ShowTimers(void); void StopTimer( struct pppTimer *tp ) @@ -45,6 +44,7 @@ StopTimer( struct pppTimer *tp ) sigsetmask(omask); #endif } + void StartTimer(tp) struct pppTimer *tp; @@ -61,17 +61,14 @@ struct pppTimer *tp; StopTimerNoBlock(tp); } if (tp->load == 0) { -#ifdef DEBUG - logprintf("timer %x has 0 load!\n", tp); -#endif + LogPrintf(LogDEBUG, "timer %x has 0 load!\n", tp); sigsetmask(omask); return; } pt = NULL; for (t = TimerList; t; t = t->next) { -#ifdef DEBUG - logprintf("StartTimer: %x(%d): ticks: %d, rest: %d\n", t, t->state, ticks, t->rest); -#endif + LogPrintf(LogDEBUG, "StartTimer: %x(%d): ticks: %d, rest: %d\n", + t, t->state, ticks, t->rest); if (ticks + t->rest >= tp->load) break; ticks += t->rest; @@ -80,9 +77,8 @@ struct pppTimer *tp; tp->state = TIMER_RUNNING; tp->rest = tp->load - ticks; -#ifdef DEBUG - logprintf("Inserting %x before %x, rest = %d\n", tp, t, tp->rest); -#endif + LogPrintf(LogDEBUG, "StartTimer: Inserting %x before %x, rest = %d\n", + tp, t, tp->rest); /* Insert given *tp just before *t */ tp->next = t; if (pt) { @@ -111,9 +107,8 @@ struct pppTimer *tp; * So just marked as TIMER_STOPPED. * Do not change tp->enext!! (Might be Called by expired proc) */ -#ifdef DEBUG - logprintf("StopTimer: %x, next = %x state=%x\n", tp, tp->next, tp->state); -#endif + LogPrintf(LogDEBUG, "StopTimer: %x, next = %x state=%x\n", + tp, tp->next, tp->state); if (tp->state != TIMER_RUNNING) { tp->next = NULL; tp->state = TIMER_STOPPED; @@ -133,9 +128,9 @@ struct pppTimer *tp; } if (t->next) t->next->rest += tp->rest; - } else { - logprintf("Oops, timer not found!!\n"); - } + } else + LogPrintf(LogERROR, "Oops, timer not found!!\n"); + tp->next = NULL; tp->state = TIMER_STOPPED; } @@ -145,9 +140,8 @@ TimerService() { struct pppTimer *tp, *exp, *wt; -#ifdef DEBUG - ShowTimers(); -#endif + if (LogIsKept(LogDEBUG)) + ShowTimers(); tp = TimerList; if (tp) { tp->rest--; @@ -161,19 +155,15 @@ TimerService() wt = tp->next; tp->enext = exp; exp = tp; -#ifdef DEBUG - logprintf("Add %x to exp\n", tp); -#endif + LogPrintf(LogDEBUG, "TimerService: Add %x to exp\n", tp); tp = wt; } while (tp && (tp->rest == 0)); TimerList = tp; if ( TimerList == NULL ) /* No timers ? */ TermTimerService(); /* Terminate Timer Service */ -#ifdef DEBUG - logprintf("TimerService: next is %x(%d)\n", + LogPrintf(LogDEBUG, "TimerService: next is %x(%d)\n", TimerList, TimerList? TimerList->rest : 0); -#endif /* * Process all expired timers. */ @@ -199,11 +189,11 @@ ShowTimers() { struct pppTimer *pt; - logprintf("---- Begin of Timer Service List---\n"); + LogPrintf(LogDEBUG, "---- Begin of Timer Service List---\n"); for (pt = TimerList; pt; pt = pt->next) - logprintf("%x: load = %d, rest = %d, state =%x\n", + LogPrintf(LogDEBUG, "%x: load = %d, rest = %d, state =%x\n", pt, pt->load, pt->rest, pt->state); - logprintf("---- End of Timer Service List ---\n"); + LogPrintf(LogDEBUG, "---- End of Timer Service List ---\n"); } #ifdef SIGALRM @@ -274,9 +264,8 @@ void InitTimerService( void ) { 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("Unable to set itimer.\n"); - } + if (setitimer(ITIMER_REAL, &itimer, NULL) == -1) + LogPrintf(LogERROR, "Unable to set itimer.\n"); } void TermTimerService( void ) { @@ -284,9 +273,8 @@ void TermTimerService( void ) { itimer.it_interval.tv_usec = itimer.it_interval.tv_sec = 0; itimer.it_value.tv_usec = itimer.it_value.tv_sec = 0; - if (setitimer(ITIMER_REAL, &itimer, NULL) == -1) { - logprintf("Unable to set itimer.\n"); - } + if (setitimer(ITIMER_REAL, &itimer, NULL) == -1) + LogPrintf(LogERROR, "Unable to set itimer.\n"); pending_signal(SIGALRM, SIG_IGN); } #endif diff --git a/usr.sbin/ppp/vars.c b/usr.sbin/ppp/vars.c index f9e4d1d..918fb7d 100644 --- a/usr.sbin/ppp/vars.c +++ b/usr.sbin/ppp/vars.c @@ -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.17 1997/05/26 00:44:09 brian Exp $ + * $Id: vars.c,v 1.18 1997/06/01 01:13:03 brian Exp $ * */ #include "fsm.h" @@ -30,7 +30,7 @@ #include "defs.h" char VarVersion[] = "Version 0.94"; -char VarLocalVersion[] = "$Date: 1997/05/26 00:44:09 $"; +char VarLocalVersion[] = "$Date: 1997/06/01 01:13:03 $"; /* * Order of conf option is important. See vars.h. @@ -53,7 +53,7 @@ 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, MODEM_DEV, BASE_MODEM_DEV, - OPEN_ACTIVE, LOCAL_NO_AUTH, + OPEN_ACTIVE, LOCAL_NO_AUTH,0 }; int @@ -61,122 +61,73 @@ DisplayCommand() { struct confdesc *vp; - printf("Current configuration option settings..\n\n"); - printf("Name\t\tMy Side\t\tHis Side\n"); - printf("----------------------------------------\n"); + if (!VarTerm) + return 1; + + fprintf(VarTerm, "Current configuration option settings..\n\n"); + fprintf(VarTerm, "Name\t\tMy Side\t\tHis Side\n"); + fprintf(VarTerm, "----------------------------------------\n"); for (vp = pppConfs; vp->name; vp++) - printf("%-10s\t%s\t\t%s\n", vp->name, + fprintf(VarTerm, "%-10s\t%s\t\t%s\n", vp->name, (vp->myside == CONF_ENABLE)? "enable" : "disable", (vp->hisside == CONF_ACCEPT)? "accept" : "deny"); - return(1); + + return 0; } -int -DisableCommand(list, argc, argv) -struct cmdtab *list; -int argc; -char **argv; +static int +ConfigCommand(struct cmdtab *list, int argc, char **argv, int mine, int val) { struct confdesc *vp; - int found = FALSE; + int err; - if (argc < 1) { - printf("disable what?\n"); - return(1); - } + if (argc < 1) + return -1; + + err = 0; do { - for (vp = pppConfs; vp->name; vp++) { + for (vp = pppConfs; vp->name; vp++) if (strcasecmp(vp->name, *argv) == 0) { - vp->myside = CONF_DISABLE; - found = TRUE; + if (mine) + vp->myside = val; + else + vp->hisside = val; + break; } + + if (!vp->name) { + LogPrintf(LogWARN, "Config: %s: No such key word\n", *argv ); + err++; } - if ( found == FALSE ) - printf("%s - No such key word\n", *argv ); - argc--; argv++; + argc--; + argv++; } while (argc > 0); - return(1); + + return err; } int -EnableCommand(list, argc, argv) -struct cmdtab *list; -int argc; -char **argv; +EnableCommand(struct cmdtab *list, int argc, char **argv) { - struct confdesc *vp; - int found = FALSE; - - if (argc < 1) { - printf("enable what?\n"); - return(1); - } - do { - for (vp = pppConfs; vp->name; vp++) { - if (strcasecmp(vp->name, *argv) == 0) { - vp->myside = CONF_ENABLE; - found = TRUE; - } - } - if ( found == FALSE ) - printf("%s - No such key word\n", *argv ); - argc--; argv++; - } while (argc > 0); - return(1); + return ConfigCommand(list, argc, argv, 1, CONF_ENABLE); } int -AcceptCommand(list, argc, argv) -struct cmdtab *list; -int argc; -char **argv; +DisableCommand(struct cmdtab *list, int argc, char **argv) { - struct confdesc *vp; - int found = FALSE; - - if (argc < 1) { - printf("accept what?\n"); - return(1); - } - do { - for (vp = pppConfs; vp->name; vp++) { - if (strcasecmp(vp->name, *argv) == 0) { - vp->hisside = CONF_ACCEPT; - found = TRUE; - } - } - if ( found == FALSE ) - printf("%s - No such key word\n", *argv ); - argc--; argv++; - } while (argc > 0); - return(1); + return ConfigCommand(list, argc, argv, 1, CONF_DISABLE); } int -DenyCommand(list, argc, argv) -struct cmdtab *list; -int argc; -char **argv; +AcceptCommand(struct cmdtab *list, int argc, char **argv) { - struct confdesc *vp; - int found = FALSE; + return ConfigCommand(list, argc, argv, 0, CONF_ACCEPT); +} - if (argc < 1) { - printf("enable what?\n"); - return(1); - } - do { - for (vp = pppConfs; vp->name; vp++) { - if (strcasecmp(vp->name, *argv) == 0) { - vp->hisside = CONF_DENY; - found = TRUE; - } - } - if ( found == FALSE ) - printf("%s - No such key word\n", *argv ); - argc--; argv++; - } while (argc > 0); - return(1); +int +DenyCommand(struct cmdtab *list, int argc, char **argv) +{ + return ConfigCommand(list, argc, argv, 0, CONF_DENY); } int @@ -185,10 +136,8 @@ struct cmdtab *list; int argc; char **argv; { - if (argc < 1) { - printf("Please Enter passwd for manipulating.\n"); - return(1); - } + if (argc != 1) + return -1; switch ( LocalAuthValidate( SECRETFILE, VarShortHost, *argv ) ) { case INVALID: @@ -199,12 +148,12 @@ char **argv; break; case NOT_FOUND: pppVars.lauth = LOCAL_AUTH; - printf("WARING: No Entry for this system\n"); + LogPrintf(LogWARN, "WARING: No Entry for this system\n"); break; default: pppVars.lauth = LOCAL_NO_AUTH; - printf("Ooops?\n"); - break; + LogPrintf(LogERROR, "LocalAuthCommand: Ooops?\n"); + return 1; } - return(1); + return 0; } diff --git a/usr.sbin/ppp/vars.h b/usr.sbin/ppp/vars.h index 3c524f9..2f5b87a 100644 --- a/usr.sbin/ppp/vars.h +++ b/usr.sbin/ppp/vars.h @@ -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.16 1997/05/26 00:44:10 brian Exp $ + * $Id: vars.h,v 1.17 1997/06/01 01:13:04 brian Exp $ * * TODO: */ @@ -67,15 +67,16 @@ struct pppvars { 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 == forever */ + int dial_tries; /* Dial attempts before giving up, 0 == inf */ char modem_dev[20]; /* Name of device */ 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 +#define LOCAL_AUTH 0x01 +#define LOCAL_NO_AUTH 0x02 u_char lauth; /* Local Authorized status */ - #define DIALUP_REQ 0x01 - #define DIALUP_DONE 0x02 + 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 */ @@ -113,6 +114,7 @@ struct pppvars { #define VarRedialTimeout pppVars.redial_timeout #define VarRedialNextTimeout pppVars.redial_next_timeout #define VarDialTries pppVars.dial_tries +#define VarTerm pppVars.termfp #define VarAliasHandlers pppVars.handler #define VarGetNextFragmentPtr (*pppVars.handler.GetNextFragmentPtr) diff --git a/usr.sbin/ppp/vjcomp.c b/usr.sbin/ppp/vjcomp.c index ec1e585..3e02623 100644 --- a/usr.sbin/ppp/vjcomp.c +++ b/usr.sbin/ppp/vjcomp.c @@ -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.6 1997/02/22 16:11:05 peter Exp $ + * $Id: vjcomp.c,v 1.7 1997/05/07 23:30:50 brian Exp $ * * TODO: */ @@ -47,16 +47,12 @@ struct mbuf *bp; int proto; int cproto = IpcpInfo.his_compproto >> 16; -#ifdef DEBUG - logprintf("SendPppFrame: proto = %x\n", IpcpInfo.his_compproto); -#endif + 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); -#ifdef DEBUG - logprintf("type = %x\n", type); -#endif + LogPrintf(LogDEBUG, "SendPppFrame: type = %x\n", type); switch (type) { case TYPE_IP: proto = PROTO_IP; @@ -68,7 +64,7 @@ struct mbuf *bp; proto = PROTO_VJCOMP; break; default: - logprintf("unknown type %x\n", type); + LogPrintf(LogERROR, "Unknown frame type %x\n", type); pfree(bp); return; } @@ -132,10 +128,8 @@ int proto; { u_char type; -#ifdef DEBUG - logprintf("VjCompInput (%02x):\n", proto); - DumpBp(bp); -#endif + LogPrintf(LogDEBUG, "VjCompInput: proto %02x\n", proto); + LogDumpBp(LogDEBUG, "Raw packet info:", bp); switch (proto) { case PROTO_VJCOMP: @@ -145,7 +139,7 @@ int proto; type = TYPE_UNCOMPRESSED_TCP; break; default: - logprintf("???\n"); + LogPrintf(LogERROR, "VjCompInput...???\n"); return(bp); } bp = VjUncompressTcp(bp, type); |