summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrian <brian@cvs.openbsd.org>2002-05-16 01:13:40 +0000
committerbrian <brian@cvs.openbsd.org>2002-05-16 01:13:40 +0000
commit5f1172106b4b654d9d5ded2dc9eb8f27c2f86ac5 (patch)
tree12594c65845d22dc71deaef8b0c4926567f7266f
parent2bd48043d848f337cd8dd19270a3fd343f361ac4 (diff)
o Bump the version number
o Tidy up includes o Fix macros in auth.h o Insist on context for ``set mru'' in MP mode o Usage -> usage o Don't intialise after processing config requests o Show FSM values for ConfigAcks o Make ident output prettier o Fix some Id keywords o Handle RADIUS pool address 255.255.255.254 o Support RADIUS Session-Timeout attributes o Support RADIUS Reply-Message attributes o Support RADIUS CHAP-Error attributes o Store RADIUS Filter-Id attributes o Provide a NAS-Port-Type attribute to RADIUS servers o Provide a better NAS-Port attribute to RADIUS servers o Support MS-CHAP with RADIUS o Improve FSM decode functions o Support an OCTETSIN variable o Support an OCTETSOUT variable o Support an PACKETSIN variable o Support an PACKETSOUT variable o Support an IPOCTETSIN variable o Support an IPOCTETSOUT variable o Support an IPPACKETSIN variable o Support an IPPACKETSOUT variable o Support an IPV6OCTETSIN variable o Support an IPV6OCTETSOUT variable o Support an IPV6PACKETSIN variable o Support an IPV6PACKETSOUT variable o Support a SOCKNAME variable
-rw-r--r--usr.sbin/ppp/ppp/atm.c3
-rw-r--r--usr.sbin/ppp/ppp/auth.c6
-rw-r--r--usr.sbin/ppp/ppp/auth.h6
-rw-r--r--usr.sbin/ppp/ppp/bundle.c86
-rw-r--r--usr.sbin/ppp/ppp/bundle.h14
-rw-r--r--usr.sbin/ppp/ppp/cbcp.c7
-rw-r--r--usr.sbin/ppp/ppp/ccp.c113
-rw-r--r--usr.sbin/ppp/ppp/ccp.h18
-rw-r--r--usr.sbin/ppp/ppp/chap.c26
-rw-r--r--usr.sbin/ppp/ppp/chap_ms.c6
-rw-r--r--usr.sbin/ppp/ppp/chat.c3
-rw-r--r--usr.sbin/ppp/ppp/command.c133
-rw-r--r--usr.sbin/ppp/ppp/datalink.c3
-rw-r--r--usr.sbin/ppp/ppp/deflate.c25
-rw-r--r--usr.sbin/ppp/ppp/defs.c17
-rw-r--r--usr.sbin/ppp/ppp/defs.h4
-rw-r--r--usr.sbin/ppp/ppp/ether.c49
-rw-r--r--usr.sbin/ppp/ppp/exec.c3
-rw-r--r--usr.sbin/ppp/ppp/filter.c6
-rw-r--r--usr.sbin/ppp/ppp/fsm.c163
-rw-r--r--usr.sbin/ppp/ppp/fsm.h60
-rw-r--r--usr.sbin/ppp/ppp/i4b.c17
-rw-r--r--usr.sbin/ppp/ppp/iface.c4
-rw-r--r--usr.sbin/ppp/ppp/ip.c4
-rw-r--r--usr.sbin/ppp/ppp/ipcp.c303
-rw-r--r--usr.sbin/ppp/ppp/ipv6cp.c86
-rw-r--r--usr.sbin/ppp/ppp/lcp.c676
-rw-r--r--usr.sbin/ppp/ppp/lcp.h16
-rw-r--r--usr.sbin/ppp/ppp/lqr.c6
-rw-r--r--usr.sbin/ppp/ppp/main.c6
-rw-r--r--usr.sbin/ppp/ppp/mp.c3
-rw-r--r--usr.sbin/ppp/ppp/mppe.c29
-rw-r--r--usr.sbin/ppp/ppp/nat_cmd.c12
-rw-r--r--usr.sbin/ppp/ppp/ncp.c16
-rw-r--r--usr.sbin/ppp/ppp/ncp.h2
-rw-r--r--usr.sbin/ppp/ppp/ncpaddr.c5
-rw-r--r--usr.sbin/ppp/ppp/ncpaddr.h2
-rw-r--r--usr.sbin/ppp/ppp/netgraph.c1
-rw-r--r--usr.sbin/ppp/ppp/pap.c14
-rw-r--r--usr.sbin/ppp/ppp/physical.c15
-rw-r--r--usr.sbin/ppp/ppp/physical.h4
-rw-r--r--usr.sbin/ppp/ppp/ppp.8.m461
-rw-r--r--usr.sbin/ppp/ppp/pred.c32
-rw-r--r--usr.sbin/ppp/ppp/prompt.c3
-rw-r--r--usr.sbin/ppp/ppp/radius.c289
-rw-r--r--usr.sbin/ppp/ppp/radius.h9
-rw-r--r--usr.sbin/ppp/ppp/radlib.c66
-rw-r--r--usr.sbin/ppp/ppp/radlib.h16
-rw-r--r--usr.sbin/ppp/ppp/radlib_private.h10
-rw-r--r--usr.sbin/ppp/ppp/radlib_vs.h79
-rw-r--r--usr.sbin/ppp/ppp/route.c27
-rw-r--r--usr.sbin/ppp/ppp/server.c4
-rw-r--r--usr.sbin/ppp/ppp/sig.c4
-rw-r--r--usr.sbin/ppp/ppp/slcompress.c3
-rw-r--r--usr.sbin/ppp/ppp/systems.c5
-rw-r--r--usr.sbin/ppp/ppp/tcp.c3
-rw-r--r--usr.sbin/ppp/ppp/tcpmss.c3
-rw-r--r--usr.sbin/ppp/ppp/tcpmss.h2
-rw-r--r--usr.sbin/ppp/ppp/throughput.c4
-rw-r--r--usr.sbin/ppp/ppp/timer.c4
-rw-r--r--usr.sbin/ppp/ppp/tty.c30
-rw-r--r--usr.sbin/ppp/ppp/tun.c3
-rw-r--r--usr.sbin/ppp/ppp/udp.c3
-rw-r--r--usr.sbin/ppp/ppp/vjcomp.c3
64 files changed, 1629 insertions, 1006 deletions
diff --git a/usr.sbin/ppp/ppp/atm.c b/usr.sbin/ppp/ppp/atm.c
index 01a3ded13aa..2979f4277f0 100644
--- a/usr.sbin/ppp/ppp/atm.c
+++ b/usr.sbin/ppp/ppp/atm.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: atm.c,v 1.7 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: atm.c,v 1.8 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/types.h>
@@ -136,6 +136,7 @@ static const struct device baseatmdevice = {
atm_Sendto,
atm_device2iov,
NULL,
+ NULL,
NULL
};
diff --git a/usr.sbin/ppp/ppp/auth.c b/usr.sbin/ppp/ppp/auth.c
index ce8337dd983..f558d13ff29 100644
--- a/usr.sbin/ppp/ppp/auth.c
+++ b/usr.sbin/ppp/ppp/auth.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: auth.c,v 1.17 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: auth.c,v 1.18 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -53,7 +53,6 @@
#include "lqr.h"
#include "hdlc.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "auth.h"
#include "systems.h"
@@ -170,7 +169,8 @@ auth_Select(struct bundle *bundle, const char *name)
}
#ifndef NORADIUS
- if (bundle->radius.valid && bundle->radius.ip.s_addr != INADDR_NONE) {
+ if (bundle->radius.valid && bundle->radius.ip.s_addr != INADDR_NONE &&
+ bundle->radius.ip.s_addr != RADIUS_INADDR_POOL) {
/* We've got a radius IP - it overrides everything */
if (!ipcp_UseHisIPaddr(bundle, bundle->radius.ip))
return 0;
diff --git a/usr.sbin/ppp/ppp/auth.h b/usr.sbin/ppp/ppp/auth.h
index 530cf9cf752..6454af5f848 100644
--- a/usr.sbin/ppp/ppp/auth.h
+++ b/usr.sbin/ppp/ppp/auth.h
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: auth.h,v 1.8 2001/06/13 21:33:40 brian Exp $
+ * $OpenBSD: auth.h,v 1.9 2002/05/16 01:13:39 brian Exp $
*/
struct physical;
@@ -52,8 +52,8 @@ struct authinfo {
} cfg;
};
-#define auth_Failure(a) (*a->fn.failure)(a);
-#define auth_Success(a) (*a->fn.success)(a);
+#define auth_Failure(a) (*(a)->fn.failure)(a)
+#define auth_Success(a) (*(a)->fn.success)(a)
extern const char *Auth2Nam(u_short, u_char);
extern void auth_Init(struct authinfo *, struct physical *,
diff --git a/usr.sbin/ppp/ppp/bundle.c b/usr.sbin/ppp/ppp/bundle.c
index 8349ede415c..5cbe89c3656 100644
--- a/usr.sbin/ppp/ppp/bundle.c
+++ b/usr.sbin/ppp/ppp/bundle.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: bundle.c,v 1.63 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: bundle.c,v 1.64 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -227,6 +227,13 @@ bundle_LinkAdded(struct bundle *bundle, struct datalink *dl)
if (dl->state == DATALINK_OPEN)
bundle->phys_type.open |= dl->physical->type;
+#ifndef NORADIUS
+ if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL))
+ != bundle->phys_type.open && bundle->session.timer.state == TIMER_STOPPED)
+ if (bundle->radius.sessiontime)
+ bundle_StartSessionTimer(bundle, 0);
+#endif
+
if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL))
!= bundle->phys_type.open && bundle->idle.timer.state == TIMER_STOPPED)
/* We may need to start our idle timer */
@@ -246,8 +253,13 @@ bundle_LinksRemoved(struct bundle *bundle)
mp_CheckAutoloadTimer(&bundle->ncp.mp);
if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL))
- == bundle->phys_type.open)
+ == bundle->phys_type.open) {
+#ifndef NORADIUS
+ if (bundle->radius.sessiontime)
+ bundle_StopSessionTimer(bundle);
+#endif
bundle_StopIdleTimer(bundle);
+ }
}
static void
@@ -274,6 +286,10 @@ bundle_LayerUp(void *v, struct fsm *fp)
if (ncp_LayersOpen(&fp->bundle->ncp) == 1) {
bundle_CalculateBandwidth(fp->bundle);
time(&bundle->upat);
+#ifndef NORADIUS
+ if (bundle->radius.sessiontime)
+ bundle_StartSessionTimer(bundle, 0);
+#endif
bundle_StartIdleTimer(bundle, 0);
mp_CheckAutoloadTimer(&fp->bundle->ncp.mp);
}
@@ -300,6 +316,10 @@ bundle_LayerDown(void *v, struct fsm *fp)
if (isncp(fp->proto)) {
if (ncp_LayersOpen(&fp->bundle->ncp) == 0) {
+#ifndef NORADIUS
+ if (bundle->radius.sessiontime)
+ bundle_StopSessionTimer(bundle);
+#endif
bundle_StopIdleTimer(bundle);
bundle->upat = 0;
mp_StopAutoloadTimer(&bundle->ncp.mp);
@@ -399,6 +419,10 @@ bundle_Close(struct bundle *bundle, const char *name, int how)
}
if (!others_active) {
+#ifndef NORADIUS
+ if (bundle->radius.sessiontime)
+ bundle_StopSessionTimer(bundle);
+#endif
bundle_StopIdleTimer(bundle);
if (ncp_LayersUnfinished(&bundle->ncp))
ncp_Close(&bundle->ncp);
@@ -526,11 +550,11 @@ bundle_DescriptorRead(struct fdescriptor *d, struct bundle *bundle,
if (FD_ISSET(bundle->dev.fd, fdset)) {
struct tun_data tun;
int n, pri;
- char *data;
+ u_char *data;
size_t sz;
if (bundle->dev.header) {
- data = (char *)&tun;
+ data = (u_char *)&tun;
sz = sizeof tun;
} else {
data = tun.data;
@@ -708,10 +732,11 @@ bundle_Create(const char *prefix, int type, int unit)
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
if (bundle.unit == minunit && !kldtried++) {
/*
- * Attempt to load the tunnel interface KLD if it isn't loaded
- * already.
+ * Attempt to load the tunnel interface KLD if it isn't loaded
+ * already.
*/
- loadmodules(LOAD_VERBOSLY, "if_tun", NULL);
+ if (loadmodules(LOAD_VERBOSLY, "if_tun", NULL))
+ bundle.unit--;
continue;
}
#endif
@@ -941,6 +966,10 @@ bundle_LinkClosed(struct bundle *bundle, struct datalink *dl)
ncp2initial(&bundle->ncp);
mp_Down(&bundle->ncp.mp);
bundle_NewPhase(bundle, PHASE_DEAD);
+#ifndef NORADIUS
+ if (bundle->radius.sessiontime)
+ bundle_StopSessionTimer(bundle);
+#endif
bundle_StopIdleTimer(bundle);
}
}
@@ -1183,6 +1212,47 @@ bundle_RemainingIdleTime(struct bundle *bundle)
return -1;
}
+#ifndef NORADIUS
+
+static void
+bundle_SessionTimeout(void *v)
+{
+ struct bundle *bundle = (struct bundle *)v;
+
+ log_Printf(LogPHASE, "Session-Timeout timer expired\n");
+ bundle_StopSessionTimer(bundle);
+ bundle_Close(bundle, NULL, CLOSE_STAYDOWN);
+}
+
+void
+bundle_StartSessionTimer(struct bundle *bundle, unsigned secs)
+{
+ timer_Stop(&bundle->session.timer);
+ if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) !=
+ bundle->phys_type.open && bundle->radius.sessiontime) {
+ time_t now = time(NULL);
+
+ if (secs == 0)
+ secs = bundle->radius.sessiontime;
+
+ bundle->session.timer.func = bundle_SessionTimeout;
+ bundle->session.timer.name = "session";
+ bundle->session.timer.load = secs * SECTICKS;
+ bundle->session.timer.arg = bundle;
+ timer_Start(&bundle->session.timer);
+ bundle->session.done = now + secs;
+ }
+}
+
+void
+bundle_StopSessionTimer(struct bundle *bundle)
+{
+ timer_Stop(&bundle->session.timer);
+ bundle->session.done = 0;
+}
+
+#endif
+
int
bundle_IsDead(struct bundle *bundle)
{
@@ -1824,7 +1894,7 @@ bundle_CalculateBandwidth(struct bundle *bundle)
}
}
- if(bundle->bandwidth == 0)
+ if (bundle->bandwidth == 0)
bundle->bandwidth = 115200; /* Shrug */
if (bundle->ncp.mp.active) {
diff --git a/usr.sbin/ppp/ppp/bundle.h b/usr.sbin/ppp/ppp/bundle.h
index 19404cd96a1..430deffc42f 100644
--- a/usr.sbin/ppp/ppp/bundle.h
+++ b/usr.sbin/ppp/ppp/bundle.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: bundle.h,v 1.23 2001/11/23 11:17:03 brian Exp $
+ * $OpenBSD: bundle.h,v 1.24 2002/05/16 01:13:39 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@@ -127,6 +127,13 @@ struct bundle {
time_t done;
} idle;
+#ifndef NORADIUS
+ struct {
+ struct pppTimer timer;
+ time_t done;
+ } session;
+#endif
+
struct {
int fd; /* write status here */
} notify;
@@ -163,6 +170,11 @@ extern void bundle_StopIdleTimer(struct bundle *);
extern int bundle_IsDead(struct bundle *);
extern struct datalink *bundle2datalink(struct bundle *, const char *);
+#ifndef NORADIUS
+extern void bundle_StartSessionTimer(struct bundle *, unsigned secs);
+extern void bundle_StopSessionTimer(struct bundle *);
+#endif
+
extern void bundle_RegisterDescriptor(struct bundle *, struct fdescriptor *);
extern void bundle_UnRegisterDescriptor(struct bundle *, struct fdescriptor *);
diff --git a/usr.sbin/ppp/ppp/cbcp.c b/usr.sbin/ppp/ppp/cbcp.c
index 20af6606ec5..ebf2a5799dc 100644
--- a/usr.sbin/ppp/ppp/cbcp.c
+++ b/usr.sbin/ppp/ppp/cbcp.c
@@ -23,11 +23,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: cbcp.c,v 1.14 2000/07/19 11:06:31 brian Exp $
+ * $OpenBSD: cbcp.c,v 1.15 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
+#ifdef __FreeBSD__
+#include <netinet/in.h>
+#endif
#include <sys/un.h>
#include <string.h>
@@ -560,7 +563,7 @@ cbcp_CheckResponse(struct cbcp *cbcp, struct cbcp_data *data)
}
return CBCP_ACTION_DOWN;
}
- log_Printf(LogPHASE, "Internal CBCP error - agreed on %d ??!?\n",
+ log_Printf(LogPHASE, "Internal CBCP error - agreed on %d !\n",
(int)cbcp->fsm.type);
return CBCP_ACTION_DOWN;
} else if (data->type == CBCP_NONUM && cbcp->fsm.type == CBCP_CLIENTNUM) {
diff --git a/usr.sbin/ppp/ppp/ccp.c b/usr.sbin/ppp/ppp/ccp.c
index 033f1d83882..aabe4e31cfe 100644
--- a/usr.sbin/ppp/ppp/ccp.c
+++ b/usr.sbin/ppp/ppp/ccp.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: ccp.c,v 1.26 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: ccp.c,v 1.27 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -58,7 +58,6 @@
#include "lcp.h"
#include "ccp.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
@@ -80,7 +79,7 @@
static void CcpSendConfigReq(struct fsm *);
static void CcpSentTerminateReq(struct fsm *);
static void CcpSendTerminateAck(struct fsm *, u_char);
-static void CcpDecodeConfig(struct fsm *, u_char *, int, int,
+static void CcpDecodeConfig(struct fsm *, u_char *, u_char *, int,
struct fsm_decode *);
static void CcpLayerStart(struct fsm *);
static void CcpLayerFinish(struct fsm *);
@@ -276,7 +275,7 @@ ccp_Setup(struct ccp *ccp)
ccp->reset_sent = ccp->last_reset = -1;
ccp->in.algorithm = ccp->out.algorithm = -1;
ccp->in.state = ccp->out.state = NULL;
- ccp->in.opt.id = -1;
+ ccp->in.opt.hdr.id = -1;
ccp->out.opt = NULL;
ccp->his_reject = ccp->my_reject = 0;
ccp->uncompout = ccp->compout = 0;
@@ -361,26 +360,26 @@ CcpSendConfigReq(struct fsm *fp)
if (!alloc)
for (o = &ccp->out.opt; *o != NULL; o = &(*o)->next)
- if ((*o)->val.id == algorithm[f]->id && (*o)->algorithm == f)
+ if ((*o)->val.hdr.id == algorithm[f]->id && (*o)->algorithm == f)
break;
if (alloc || *o == NULL) {
*o = (struct ccp_opt *)malloc(sizeof(struct ccp_opt));
- (*o)->val.id = algorithm[f]->id;
- (*o)->val.len = 2;
+ (*o)->val.hdr.id = algorithm[f]->id;
+ (*o)->val.hdr.len = 2;
(*o)->next = NULL;
(*o)->algorithm = f;
(*algorithm[f]->o.OptInit)(&(*o)->val, &ccp->cfg);
}
- if (cp + (*o)->val.len > buff + sizeof buff) {
+ if (cp + (*o)->val.hdr.len > buff + sizeof buff) {
log_Printf(LogERROR, "%s: CCP REQ buffer overrun !\n", fp->link->name);
break;
}
- memcpy(cp, &(*o)->val, (*o)->val.len);
- cp += (*o)->val.len;
+ memcpy(cp, &(*o)->val, (*o)->val.hdr.len);
+ cp += (*o)->val.hdr.len;
- ccp->my_proto = (*o)->val.id;
+ ccp->my_proto = (*o)->val.hdr.id;
ccp->out.algorithm = f;
if (alloc)
@@ -555,93 +554,79 @@ CcpLayerUp(struct fsm *fp)
}
static void
-CcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
+CcpDecodeConfig(struct fsm *fp, u_char *cp, u_char *end, int mode_type,
struct fsm_decode *dec)
{
/* Deal with incoming data */
struct ccp *ccp = fsm2ccp(fp);
- int type, length, f;
- const char *end;
+ int f;
+ const char *disp;
+ struct fsm_opt *opt;
if (mode_type == MODE_REQ)
ccp->in.algorithm = -1; /* In case we've received two REQs in a row */
- while (plen >= sizeof(struct fsmconfig)) {
- type = *cp;
- length = cp[1];
-
- if (length == 0) {
- log_Printf(LogCCP, "%s: CCP size zero\n", fp->link->name);
+ while (end - cp >= sizeof(opt->hdr)) {
+ if ((opt = fsm_readopt(&cp)) == NULL)
break;
- }
-
- if (length > sizeof(struct lcp_opt)) {
- length = sizeof(struct lcp_opt);
- log_Printf(LogCCP, "%s: Warning: Truncating length to %d\n",
- fp->link->name, length);
- }
for (f = NALGORITHMS-1; f > -1; f--)
- if (algorithm[f]->id == type)
+ if (algorithm[f]->id == opt->hdr.id)
break;
- end = f == -1 ? "" : (*algorithm[f]->Disp)((struct lcp_opt *)cp);
- if (end == NULL)
- end = "";
+ disp = f == -1 ? "" : (*algorithm[f]->Disp)(opt);
+ if (disp == NULL)
+ disp = "";
- log_Printf(LogCCP, " %s[%d] %s\n", protoname(type), length, end);
+ log_Printf(LogCCP, " %s[%d] %s\n", protoname(opt->hdr.id),
+ opt->hdr.len, disp);
if (f == -1) {
/* Don't understand that :-( */
if (mode_type == MODE_REQ) {
- ccp->my_reject |= (1 << type);
- memcpy(dec->rejend, cp, length);
- dec->rejend += length;
+ ccp->my_reject |= (1 << opt->hdr.id);
+ fsm_rej(dec, opt);
}
} else {
struct ccp_opt *o;
switch (mode_type) {
case MODE_REQ:
- if (IsAccepted(ccp->cfg.neg[algorithm[f]->Neg]) &&
+ if (IsAccepted(ccp->cfg.neg[algorithm[f]->Neg]) &&
(*algorithm[f]->Usable)(fp) &&
ccp->in.algorithm == -1) {
- memcpy(&ccp->in.opt, cp, length);
+ memcpy(&ccp->in.opt, opt, opt->hdr.len);
switch ((*algorithm[f]->i.Set)(&ccp->in.opt, &ccp->cfg)) {
case MODE_REJ:
- memcpy(dec->rejend, &ccp->in.opt, ccp->in.opt.len);
- dec->rejend += ccp->in.opt.len;
+ fsm_rej(dec, &ccp->in.opt);
break;
case MODE_NAK:
- memcpy(dec->nakend, &ccp->in.opt, ccp->in.opt.len);
- dec->nakend += ccp->in.opt.len;
+ fsm_nak(dec, &ccp->in.opt);
break;
case MODE_ACK:
- memcpy(dec->ackend, cp, length);
- dec->ackend += length;
- ccp->his_proto = type;
+ fsm_ack(dec, &ccp->in.opt);
+ ccp->his_proto = opt->hdr.id;
ccp->in.algorithm = f; /* This one'll do :-) */
break;
}
- } else {
- memcpy(dec->rejend, cp, length);
- dec->rejend += length;
- }
- break;
+ } else {
+ fsm_rej(dec, opt);
+ }
+ break;
case MODE_NAK:
for (o = ccp->out.opt; o != NULL; o = o->next)
- if (o->val.id == cp[0])
+ if (o->val.hdr.id == opt->hdr.id)
break;
if (o == NULL)
log_Printf(LogCCP, "%s: Warning: Ignoring peer NAK of unsent"
" option\n", fp->link->name);
else {
- memcpy(&o->val, cp, length);
+ memcpy(&o->val, opt, opt->hdr.len);
if ((*algorithm[f]->o.Set)(&o->val, &ccp->cfg) == MODE_ACK)
ccp->my_proto = algorithm[f]->id;
else {
- ccp->his_reject |= (1 << type);
- ccp->my_proto = -1;
+ ccp->his_reject |= (1 << opt->hdr.id);
+ ccp->my_proto = -1;
if (algorithm[f]->Required(fp)) {
log_Printf(LogWARN, "%s: Cannot understand peers (required)"
" %s negotiation\n", fp->link->name,
@@ -652,33 +637,21 @@ CcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
}
break;
case MODE_REJ:
- ccp->his_reject |= (1 << type);
- ccp->my_proto = -1;
+ ccp->his_reject |= (1 << opt->hdr.id);
+ ccp->my_proto = -1;
if (algorithm[f]->Required(fp)) {
log_Printf(LogWARN, "%s: Peer rejected (required) %s negotiation\n",
fp->link->name, protoname(algorithm[f]->id));
fsm_Close(&fp->link->lcp.fsm);
}
- break;
+ break;
}
}
-
- plen -= cp[1];
- cp += cp[1];
}
if (mode_type != MODE_NOP) {
- if (dec->rejend != dec->rej) {
- /* rejects are preferred */
- dec->ackend = dec->ack;
- dec->nakend = dec->nak;
- if (ccp->in.state == NULL) {
- ccp->his_proto = -1;
- ccp->in.algorithm = -1;
- }
- } else if (dec->nakend != dec->nak) {
- /* then NAKs */
- dec->ackend = dec->ack;
+ fsm_opt_normalise(dec);
+ if (dec->rejend != dec->rej || dec->nakend != dec->nak) {
if (ccp->in.state == NULL) {
ccp->his_proto = -1;
ccp->in.algorithm = -1;
diff --git a/usr.sbin/ppp/ppp/ccp.h b/usr.sbin/ppp/ppp/ccp.h
index d6d83655191..c04dbfe1bf3 100644
--- a/usr.sbin/ppp/ppp/ccp.h
+++ b/usr.sbin/ppp/ppp/ccp.h
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: ccp.h,v 1.12 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: ccp.h,v 1.13 2002/05/16 01:13:39 brian Exp $
*/
#define CCP_MAXCODE CODE_RESETACK
@@ -85,7 +85,7 @@ struct ccp_config {
struct ccp_opt {
struct ccp_opt *next;
int algorithm;
- struct lcp_opt val;
+ struct fsm_opt val;
};
struct ccp {
@@ -100,7 +100,7 @@ struct ccp {
struct {
int algorithm; /* Algorithm in use */
void *state; /* Returned by implementations Init() */
- struct lcp_opt opt; /* Set by implementation's OptInit() */
+ struct fsm_opt opt; /* Set by implementation's OptInit() */
} in;
struct {
@@ -123,12 +123,12 @@ struct ccp {
struct ccp_algorithm {
int id;
int Neg; /* ccp_config neg array item */
- const char *(*Disp)(struct lcp_opt *); /* Use result immediately ! */
+ const char *(*Disp)(struct fsm_opt *); /* Use result immediately ! */
int (*Usable)(struct fsm *); /* Ok to negotiate ? */
int (*Required)(struct fsm *); /* Must negotiate ? */
struct {
- int (*Set)(struct lcp_opt *, const struct ccp_config *);
- void *(*Init)(struct lcp_opt *);
+ int (*Set)(struct fsm_opt *, const struct ccp_config *);
+ void *(*Init)(struct fsm_opt *);
void (*Term)(void *);
void (*Reset)(void *);
struct mbuf *(*Read)(void *, struct ccp *, u_short *, struct mbuf *);
@@ -136,9 +136,9 @@ struct ccp_algorithm {
} i;
struct {
int MTUOverhead;
- void (*OptInit)(struct lcp_opt *, const struct ccp_config *);
- int (*Set)(struct lcp_opt *, const struct ccp_config *);
- void *(*Init)(struct lcp_opt *);
+ void (*OptInit)(struct fsm_opt *, const struct ccp_config *);
+ int (*Set)(struct fsm_opt *, const struct ccp_config *);
+ void *(*Init)(struct fsm_opt *);
void (*Term)(void *);
int (*Reset)(void *);
struct mbuf *(*Write)(void *, struct ccp *, struct link *, int, u_short *,
diff --git a/usr.sbin/ppp/ppp/chap.c b/usr.sbin/ppp/ppp/chap.c
index 473e66267db..50f62645045 100644
--- a/usr.sbin/ppp/ppp/chap.c
+++ b/usr.sbin/ppp/ppp/chap.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: chap.c,v 1.31 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: chap.c,v 1.32 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -68,7 +68,6 @@
#include "iplist.h"
#include "slcompress.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "ccp.h"
@@ -544,7 +543,9 @@ chap_Challenge(struct authinfo *authp)
static void
chap_Success(struct authinfo *authp)
{
+ struct bundle *bundle = authp->physical->dl->bundle;
const char *msg;
+
datalink_GotAuthname(authp->physical->dl, authp->in.name);
#ifndef NODES
if (authp->physical->link.lcp.want_authtype == 0x81) {
@@ -552,13 +553,18 @@ chap_Success(struct authinfo *authp)
MPPE_MasterKeyValid = 1; /* XXX Global ! */
} else
#endif
+#ifndef NORADIUS
+ if (*bundle->radius.cfg.file && bundle->radius.repstr)
+ msg = bundle->radius.repstr;
+ else
+#endif
msg = "Welcome!!";
ChapOutput(authp->physical, CHAP_SUCCESS, authp->id, msg, strlen(msg),
NULL);
authp->physical->link.lcp.auth_ineed = 0;
- if (Enabled(authp->physical->dl->bundle, OPT_UTMP))
+ if (Enabled(bundle, OPT_UTMP))
physical_Login(authp->physical, authp->in.name);
if (authp->physical->link.lcp.auth_iwait == 0)
@@ -573,13 +579,21 @@ static void
chap_Failure(struct authinfo *authp)
{
#ifndef NODES
- char buf[1024];
+ char buf[1024], *ptr;
#endif
const char *msg;
+#ifndef NORADIUS
+ struct bundle *bundle = authp->physical->link.lcp.fsm.bundle;
+ if (*bundle->radius.cfg.file && bundle->radius.errstr)
+ msg = bundle->radius.errstr;
+ else
+#endif
#ifndef NODES
- if (authp->physical->link.lcp.want_authtype == 0x81) {
- char *ptr;
+ if (authp->physical->link.lcp.want_authtype == 0x80) {
+ sprintf(buf, "E=691 R=1 M=Invalid!");
+ msg = buf;
+ } else if (authp->physical->link.lcp.want_authtype == 0x81) {
int i;
ptr = buf;
diff --git a/usr.sbin/ppp/ppp/chap_ms.c b/usr.sbin/ppp/ppp/chap_ms.c
index fe09803d937..cb8e48b4917 100644
--- a/usr.sbin/ppp/ppp/chap_ms.c
+++ b/usr.sbin/ppp/ppp/chap_ms.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: chap_ms.c,v 1.10 2001/08/10 17:43:40 brian Exp $
+ * $OpenBSD: chap_ms.c,v 1.11 2002/05/16 01:13:39 brian Exp $
*/
#include <ctype.h>
@@ -36,7 +36,11 @@
#else
#include <sys/types.h>
#include <stdlib.h>
+#ifdef __NetBSD__
+#include <openssl/des.h>
+#else
#include <des.h>
+#endif
#include <openssl/sha.h>
#endif
#include <md4.h>
diff --git a/usr.sbin/ppp/ppp/chat.c b/usr.sbin/ppp/ppp/chat.c
index f260636cd2d..1eb43c440b7 100644
--- a/usr.sbin/ppp/ppp/chat.c
+++ b/usr.sbin/ppp/ppp/chat.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: chat.c,v 1.18 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: chat.c,v 1.19 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -65,7 +65,6 @@
#include "slcompress.h"
#include "iplist.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "cbcp.h"
diff --git a/usr.sbin/ppp/ppp/command.c b/usr.sbin/ppp/ppp/command.c
index c87cc579848..49b6784c48f 100644
--- a/usr.sbin/ppp/ppp/command.c
+++ b/usr.sbin/ppp/ppp/command.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: command.c,v 1.72 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: command.c,v 1.73 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -71,7 +71,6 @@
#include "hdlc.h"
#include "lcp.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#ifndef NONAT
#include "nat_cmd.h"
@@ -164,7 +163,7 @@
#define NEG_MPPE 54
#define NEG_CHAP81 55
-const char Version[] = "3.0.1";
+const char Version[] = "3.0.4";
static int ShowCommand(struct cmdargs const *);
static int TerminalCommand(struct cmdargs const *);
@@ -458,13 +457,48 @@ subst(char *tgt, const char *oldstr, const char *newstr)
return tgt;
}
+static char *
+substip(char *tgt, const char *oldstr, struct in_addr ip)
+{
+ return subst(tgt, oldstr, inet_ntoa(ip));
+}
+
+static char *
+substint(char *tgt, const char *oldstr, int i)
+{
+ char buf[12];
+
+ snprintf(buf, sizeof buf, "%d", i);
+
+ return subst(tgt, oldstr, buf);
+}
+
+static char *
+substull(char *tgt, const char *oldstr, unsigned long long ull)
+{
+ char buf[21];
+
+ snprintf(buf, sizeof buf, "%llu", ull);
+
+ return subst(tgt, oldstr, buf);
+}
+
+
+#ifndef NOINET6
+static char *
+substipv6(char *tgt, const char *oldstr, const struct ncpaddr *ip)
+{
+ return subst(tgt, oldstr, ncpaddr_ntoa(ip));
+}
+#endif
+
void
command_Expand(char **nargv, int argc, char const *const *oargv,
struct bundle *bundle, int inc0, pid_t pid)
{
int arg, secs;
- char buf[20];
- char pidstr[12];
+ char uptime[20];
+ unsigned long long oin, oout, pin, pout;
if (inc0)
arg = 0; /* Start at arg 0 */
@@ -472,44 +506,75 @@ command_Expand(char **nargv, int argc, char const *const *oargv,
nargv[0] = strdup(oargv[0]);
arg = 1;
}
- snprintf(pidstr, sizeof pidstr, "%d", (int)pid);
+
+ secs = bundle_Uptime(bundle);
+ snprintf(uptime, sizeof uptime, "%d:%02d:%02d",
+ secs / 3600, (secs / 60) % 60, secs % 60);
+ oin = bundle->ncp.ipcp.throughput.OctetsIn;
+ oout = bundle->ncp.ipcp.throughput.OctetsOut;
+ pin = bundle->ncp.ipcp.throughput.PacketsIn;
+ pout = bundle->ncp.ipcp.throughput.PacketsOut;
+#ifndef NOINET6
+ oin += bundle->ncp.ipv6cp.throughput.OctetsIn;
+ oout += bundle->ncp.ipv6cp.throughput.OctetsOut;
+ pin += bundle->ncp.ipv6cp.throughput.PacketsIn;
+ pout += bundle->ncp.ipv6cp.throughput.PacketsOut;
+#endif
+
for (; arg < argc; arg++) {
nargv[arg] = strdup(oargv[arg]);
- nargv[arg] = subst(nargv[arg], "HISADDR",
- inet_ntoa(bundle->ncp.ipcp.peer_ip));
+ nargv[arg] = subst(nargv[arg], "AUTHNAME", bundle->cfg.auth.name);
+ nargv[arg] = subst(nargv[arg], "COMPILATIONDATE", __DATE__);
+ nargv[arg] = substip(nargv[arg], "DNS0", bundle->ncp.ipcp.ns.dns[0]);
+ nargv[arg] = substip(nargv[arg], "DNS1", bundle->ncp.ipcp.ns.dns[1]);
+ nargv[arg] = subst(nargv[arg], "ENDDISC",
+ mp_Enddisc(bundle->ncp.mp.cfg.enddisc.class,
+ bundle->ncp.mp.cfg.enddisc.address,
+ bundle->ncp.mp.cfg.enddisc.len));
+ nargv[arg] = substip(nargv[arg], "HISADDR", bundle->ncp.ipcp.peer_ip);
#ifndef NOINET6
- nargv[arg] = subst(nargv[arg], "HISADDR6",
- ncpaddr_ntoa(&bundle->ncp.ipv6cp.hisaddr));
+ nargv[arg] = substipv6(nargv[arg], "HISADDR6", &bundle->ncp.ipv6cp.hisaddr);
#endif
- nargv[arg] = subst(nargv[arg], "AUTHNAME", bundle->cfg.auth.name);
nargv[arg] = subst(nargv[arg], "INTERFACE", bundle->iface->name);
- nargv[arg] = subst(nargv[arg], "MYADDR", inet_ntoa(bundle->ncp.ipcp.my_ip));
+ nargv[arg] = substull(nargv[arg], "IPOCTETSIN",
+ bundle->ncp.ipcp.throughput.OctetsIn);
+ nargv[arg] = substull(nargv[arg], "IPOCTETSOUT",
+ bundle->ncp.ipcp.throughput.OctetsOut);
+ nargv[arg] = substull(nargv[arg], "IPPACKETSIN",
+ bundle->ncp.ipcp.throughput.PacketsIn);
+ nargv[arg] = substull(nargv[arg], "IPPACKETSOUT",
+ bundle->ncp.ipcp.throughput.PacketsOut);
#ifndef NOINET6
- nargv[arg] = subst(nargv[arg], "MYADDR6",
- ncpaddr_ntoa(&bundle->ncp.ipv6cp.myaddr));
+ nargv[arg] = substull(nargv[arg], "IPV6OCTETSIN",
+ bundle->ncp.ipv6cp.throughput.OctetsIn);
+ nargv[arg] = substull(nargv[arg], "IPV6OCTETSOUT",
+ bundle->ncp.ipv6cp.throughput.OctetsOut);
+ nargv[arg] = substull(nargv[arg], "IPV6PACKETSIN",
+ bundle->ncp.ipv6cp.throughput.PacketsIn);
+ nargv[arg] = substull(nargv[arg], "IPV6PACKETSOUT",
+ bundle->ncp.ipv6cp.throughput.PacketsOut);
#endif
- nargv[arg] = subst(nargv[arg], "USER", bundle->ncp.mp.peer.authname);
+ nargv[arg] = subst(nargv[arg], "LABEL", bundle_GetLabel(bundle));
+ nargv[arg] = substip(nargv[arg], "MYADDR", bundle->ncp.ipcp.my_ip);
+#ifndef NOINET6
+ nargv[arg] = substipv6(nargv[arg], "MYADDR6", &bundle->ncp.ipv6cp.myaddr);
+#endif
+ nargv[arg] = substull(nargv[arg], "OCTETSIN", oin);
+ nargv[arg] = substull(nargv[arg], "OCTETSOUT", oout);
+ nargv[arg] = substull(nargv[arg], "PACKETSIN", pin);
+ nargv[arg] = substull(nargv[arg], "PACKETSOUT", pout);
nargv[arg] = subst(nargv[arg], "PEER_ENDDISC",
mp_Enddisc(bundle->ncp.mp.peer.enddisc.class,
bundle->ncp.mp.peer.enddisc.address,
bundle->ncp.mp.peer.enddisc.len));
- nargv[arg] = subst(nargv[arg], "ENDDISC",
- mp_Enddisc(bundle->ncp.mp.cfg.enddisc.class,
- bundle->ncp.mp.cfg.enddisc.address,
- bundle->ncp.mp.cfg.enddisc.len));
- nargv[arg] = subst(nargv[arg], "PROCESSID", pidstr);
- nargv[arg] = subst(nargv[arg], "LABEL", bundle_GetLabel(bundle));
- nargv[arg] = subst(nargv[arg], "DNS0",
- inet_ntoa(bundle->ncp.ipcp.ns.dns[0]));
- nargv[arg] = subst(nargv[arg], "DNS1",
- inet_ntoa(bundle->ncp.ipcp.ns.dns[1]));
+ nargv[arg] = substint(nargv[arg], "PROCESSID", pid);
+ if (server.cfg.port)
+ nargv[arg] = substint(nargv[arg], "SOCKNAME", server.cfg.port);
+ else
+ nargv[arg] = subst(nargv[arg], "SOCKNAME", server.cfg.sockname);
+ nargv[arg] = subst(nargv[arg], "UPTIME", uptime);
+ nargv[arg] = subst(nargv[arg], "USER", bundle->ncp.mp.peer.authname);
nargv[arg] = subst(nargv[arg], "VERSION", Version);
- nargv[arg] = subst(nargv[arg], "COMPILATIONDATE", __DATE__);
-
- secs = bundle_Uptime(bundle);
- snprintf(buf, sizeof buf, "%d:%02d:%02d", secs / 3600, (secs / 60) % 60,
- secs % 60);
- nargv[arg] = subst(nargv[arg], "UPTIME", buf);
}
nargv[arg] = NULL;
}
@@ -1026,7 +1091,7 @@ FindExec(struct bundle *bundle, struct cmdtab const *cmds, int argc, int argn,
mkPrefix(argn+1, argv, prefix, sizeof prefix));
if (val == -1)
- log_Printf(LogWARN, "Usage: %s\n", cmd->syntax);
+ log_Printf(LogWARN, "usage: %s\n", cmd->syntax);
else if (val)
log_Printf(LogWARN, "%s: Failed %d\n",
mkPrefix(argn+1, argv, prefix, sizeof prefix), val);
@@ -2253,7 +2318,7 @@ static struct cmdtab const SetCommands[] = {
"set mode interactive|auto|ddial|background", (const void *)VAR_MODE},
{"mrru", NULL, SetVariable, LOCAL_AUTH, "MRRU value",
"set mrru value", (const void *)VAR_MRRU},
- {"mru", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX_OPT,
+ {"mru", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
"MRU value", "set mru [max[imum]] [value]", (const void *)VAR_MRU},
{"mtu", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
"interface MTU value", "set mtu [max[imum]] [value]", (const void *)VAR_MTU},
@@ -2540,7 +2605,7 @@ LinkCommand(struct cmdargs const *arg)
return result;
}
- log_Printf(LogWARN, "Usage: %s\n", arg->cmd->syntax);
+ log_Printf(LogWARN, "usage: %s\n", arg->cmd->syntax);
return 2;
}
diff --git a/usr.sbin/ppp/ppp/datalink.c b/usr.sbin/ppp/ppp/datalink.c
index 74734922941..0f306400b8a 100644
--- a/usr.sbin/ppp/ppp/datalink.c
+++ b/usr.sbin/ppp/ppp/datalink.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: datalink.c,v 1.40 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: datalink.c,v 1.41 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -58,7 +58,6 @@
#include "iplist.h"
#include "slcompress.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "mp.h"
diff --git a/usr.sbin/ppp/ppp/deflate.c b/usr.sbin/ppp/ppp/deflate.c
index 84edd30531c..4d69280a25e 100644
--- a/usr.sbin/ppp/ppp/deflate.c
+++ b/usr.sbin/ppp/ppp/deflate.c
@@ -23,24 +23,19 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: deflate.c,v 1.13 2001/07/03 22:23:56 brian Exp $
+ * $OpenBSD: deflate.c,v 1.14 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
-#include <termios.h>
#include <zlib.h>
-#include "defs.h"
#include "mbuf.h"
#include "log.h"
#include "timer.h"
#include "fsm.h"
-#include "lqr.h"
-#include "hdlc.h"
-#include "lcp.h"
#include "ccp.h"
#include "deflate.h"
@@ -436,7 +431,7 @@ DeflateDictSetup(void *v, struct ccp *ccp, u_short proto, struct mbuf *mi)
}
static const char *
-DeflateDispOpts(struct lcp_opt *o)
+DeflateDispOpts(struct fsm_opt *o)
{
static char disp[7]; /* Must be used immediately */
@@ -445,17 +440,17 @@ DeflateDispOpts(struct lcp_opt *o)
}
static void
-DeflateInitOptsOutput(struct lcp_opt *o, const struct ccp_config *cfg)
+DeflateInitOptsOutput(struct fsm_opt *o, const struct ccp_config *cfg)
{
- o->len = 4;
+ o->hdr.len = 4;
o->data[0] = ((cfg->deflate.out.winsize - 8) << 4) + 8;
o->data[1] = '\0';
}
static int
-DeflateSetOptsOutput(struct lcp_opt *o, const struct ccp_config *cfg)
+DeflateSetOptsOutput(struct fsm_opt *o, const struct ccp_config *cfg)
{
- if (o->len != 4 || (o->data[0] & 15) != 8 || o->data[1] != '\0')
+ if (o->hdr.len != 4 || (o->data[0] & 15) != 8 || o->data[1] != '\0')
return MODE_REJ;
if ((o->data[0] >> 4) + 8 > 15) {
@@ -467,11 +462,11 @@ DeflateSetOptsOutput(struct lcp_opt *o, const struct ccp_config *cfg)
}
static int
-DeflateSetOptsInput(struct lcp_opt *o, const struct ccp_config *cfg)
+DeflateSetOptsInput(struct fsm_opt *o, const struct ccp_config *cfg)
{
int want;
- if (o->len != 4 || (o->data[0] & 15) != 8 || o->data[1] != '\0')
+ if (o->hdr.len != 4 || (o->data[0] & 15) != 8 || o->data[1] != '\0')
return MODE_REJ;
want = (o->data[0] >> 4) + 8;
@@ -488,7 +483,7 @@ DeflateSetOptsInput(struct lcp_opt *o, const struct ccp_config *cfg)
}
static void *
-DeflateInitInput(struct lcp_opt *o)
+DeflateInitInput(struct fsm_opt *o)
{
struct deflate_state *state;
@@ -511,7 +506,7 @@ DeflateInitInput(struct lcp_opt *o)
}
static void *
-DeflateInitOutput(struct lcp_opt *o)
+DeflateInitOutput(struct fsm_opt *o)
{
struct deflate_state *state;
diff --git a/usr.sbin/ppp/ppp/defs.c b/usr.sbin/ppp/ppp/defs.c
index cbbeeca6e6c..693fac08ee0 100644
--- a/usr.sbin/ppp/ppp/defs.c
+++ b/usr.sbin/ppp/ppp/defs.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: defs.c,v 1.23 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: defs.c,v 1.24 2002/05/16 01:13:39 brian Exp $
*/
@@ -40,7 +40,6 @@
#include <stdlib.h>
#include <string.h>
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
-#include <sys/linker.h>
#include <sys/module.h>
#endif
#include <termios.h>
@@ -420,19 +419,25 @@ Concatinate(char *buf, size_t sz, int argc, const char *const *argv)
}
}
-void
+int
loadmodules(int how, const char *module, ...)
{
+ int loaded = 0;
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
va_list ap;
va_start(ap, module);
while (module != NULL) {
- if (modfind(module) == -1 && ID0kldload(module) == -1 &&
- how == LOAD_VERBOSLY)
- log_Printf(LogWARN, "%s: Cannot load module\n", module);
+ if (modfind(module) == -1) {
+ if (ID0kldload(module) == -1) {
+ if (how == LOAD_VERBOSLY)
+ log_Printf(LogWARN, "%s: Cannot load module\n", module);
+ } else
+ loaded++;
+ }
module = va_arg(ap, const char *);
}
va_end(ap);
#endif
+ return loaded;
}
diff --git a/usr.sbin/ppp/ppp/defs.h b/usr.sbin/ppp/ppp/defs.h
index 1313891cf14..dbbd5243077 100644
--- a/usr.sbin/ppp/ppp/defs.h
+++ b/usr.sbin/ppp/ppp/defs.h
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: defs.h,v 1.23 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: defs.h,v 1.24 2002/05/16 01:13:39 brian Exp $
*/
/* Check the following definitions for your machine environment */
@@ -139,4 +139,4 @@ extern void SetTitle(const char *);
extern fd_set *mkfdset(void);
extern void zerofdset(fd_set *);
extern void Concatinate(char *, size_t, int, const char *const *);
-extern void loadmodules(int, const char *, ...);
+extern int loadmodules(int, const char *, ...);
diff --git a/usr.sbin/ppp/ppp/ether.c b/usr.sbin/ppp/ppp/ether.c
index 93cc1a6f468..12a5fc083b0 100644
--- a/usr.sbin/ppp/ppp/ether.c
+++ b/usr.sbin/ppp/ppp/ether.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: ether.c,v 1.15 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: ether.c,v 1.16 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -53,6 +53,7 @@
#include <sys/uio.h>
#include <termios.h>
#include <sys/time.h>
+#include <syslog.h>
#include <unistd.h>
#include "layer.h"
@@ -91,6 +92,7 @@
#include "bundle.h"
#include "id.h"
#include "iface.h"
+#include "route.h"
#include "ether.h"
@@ -102,6 +104,7 @@ struct etherdevice {
int connected; /* Are we connected yet ? */
int timeout; /* Seconds attempting to connect */
char hook[sizeof TUN_NAME + 11]; /* Our socket node hook */
+ u_int32_t slot; /* ifindex << 24 | unit */
};
#define device2ether(d) \
@@ -177,6 +180,15 @@ ether_OpenInfo(struct physical *p)
return "disconnected";
}
+static int
+ether_Slot(struct physical *p)
+{
+ struct etherdevice *dev = device2ether(p->handler);
+
+ return dev->slot;
+}
+
+
static void
ether_device2iov(struct device *d, struct iovec *iov, int *niov,
int maxiov, int *auxfd, int *nauxfd)
@@ -204,10 +216,11 @@ ether_MessageIn(struct etherdevice *dev)
char msgbuf[sizeof(struct ng_mesg) + sizeof(struct ngpppoe_sts)];
struct ng_mesg *rep = (struct ng_mesg *)msgbuf;
struct ngpppoe_sts *sts = (struct ngpppoe_sts *)(msgbuf + sizeof *rep);
- char unknown[14];
+ char *end, unknown[14], sessionid[5];
const char *msg;
struct timeval t;
fd_set *r;
+ u_long slot;
int ret;
if (dev->cs < 0)
@@ -255,6 +268,17 @@ ether_MessageIn(struct etherdevice *dev)
if (setenv("ACNAME", sts->hook, 1) != 0)
log_Printf(LogWARN, "setenv: cannot set ACNAME=%s: %m", sts->hook);
break;
+ case NGM_PPPOE_SESSIONID:
+ msg = "SESSIONID";
+ snprintf(sessionid, sizeof sessionid, "%04x", *(u_int16_t *)sts);
+ if (setenv("SESSIONID", sessionid, 1) != 0)
+ syslog(LOG_WARNING, "setenv: cannot set SESSIONID=%s: %m",
+ sessionid);
+ /* Use this in preference to our interface index */
+ slot = strtoul(sessionid, &end, 16);
+ if (end != sessionid && *end == '\0')
+ dev->slot = slot;
+ break;
default:
snprintf(unknown, sizeof unknown, "<%d>", (int)rep->header.cmd);
msg = unknown;
@@ -304,7 +328,8 @@ static const struct device baseetherdevice = {
ether_Write,
ether_device2iov,
NULL,
- ether_OpenInfo
+ ether_OpenInfo,
+ ether_Slot
};
struct device *
@@ -409,7 +434,7 @@ ether_Create(struct physical *p)
struct ng_mesg *resp;
const struct hooklist *hlist;
const struct nodeinfo *ninfo;
- char *path;
+ char *path, *sessionid;
int ifacelen, f;
dev = NULL;
@@ -625,7 +650,8 @@ ether_Create(struct physical *p)
dev->timeout = dev->dev.cd.delay;
dev->connected = CARRIER_PENDING;
-
+ /* This will be overridden by our session id - if provided by netgraph */
+ dev->slot = GetIfIndex(path);
} else {
/* See if we're a netgraph socket */
struct stat st;
@@ -661,6 +687,19 @@ ether_Create(struct physical *p)
dev->timeout = 0;
dev->connected = CARRIER_OK;
*dev->hook = '\0';
+
+ /*
+ * If we're being envoked from pppoed(8), we may have a SESSIONID
+ * set in the environment. If so, use it as the slot
+ */
+ if ((sessionid = getenv("SESSIONID")) != NULL) {
+ char *end;
+ u_long slot;
+
+ slot = strtoul(sessionid, &end, 16);
+ dev->slot = end != sessionid && *end == '\0' ? slot : 0;
+ } else
+ dev->slot = 0;
}
}
}
diff --git a/usr.sbin/ppp/ppp/exec.c b/usr.sbin/ppp/ppp/exec.c
index 9a57104a76f..b9a517cca45 100644
--- a/usr.sbin/ppp/ppp/exec.c
+++ b/usr.sbin/ppp/ppp/exec.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: exec.c,v 1.17 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: exec.c,v 1.18 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -82,6 +82,7 @@ static struct device execdevice = {
NULL,
NULL,
NULL,
+ NULL,
NULL
};
diff --git a/usr.sbin/ppp/ppp/filter.c b/usr.sbin/ppp/ppp/filter.c
index 82727cf3e50..f11f0e4484f 100644
--- a/usr.sbin/ppp/ppp/filter.c
+++ b/usr.sbin/ppp/ppp/filter.c
@@ -25,12 +25,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: filter.c,v 1.20 2001/08/19 23:22:17 brian Exp $
+ * $OpenBSD: filter.c,v 1.21 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
#include <netinet/in.h>
-#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
@@ -39,7 +38,7 @@
#include <stdio.h>
#include <stdlib.h>
-#include <strings.h>
+#include <string.h>
#include <termios.h>
#include "layer.h"
@@ -58,7 +57,6 @@
#include "link.h"
#include "slcompress.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
diff --git a/usr.sbin/ppp/ppp/fsm.c b/usr.sbin/ppp/ppp/fsm.c
index 822fa604a76..f51bf405d2e 100644
--- a/usr.sbin/ppp/ppp/fsm.c
+++ b/usr.sbin/ppp/ppp/fsm.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: fsm.c,v 1.20 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: fsm.c,v 1.21 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -51,7 +51,6 @@
#include "throughput.h"
#include "slcompress.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
@@ -170,7 +169,7 @@ static void
NewState(struct fsm *fp, int new)
{
log_Printf(fp->LogLevel, "%s: State change %s --> %s\n",
- fp->link->name, State2Nam(fp->state), State2Nam(new));
+ fp->link->name, State2Nam(fp->state), State2Nam(new));
if (fp->state == ST_STOPPED && fp->StoppedTimer.state == TIMER_RUNNING)
timer_Stop(&fp->StoppedTimer);
fp->state = new;
@@ -201,8 +200,8 @@ fsm_Output(struct fsm *fp, u_int code, u_int id, u_char *ptr, int count,
case CODE_CONFIGACK:
case CODE_CONFIGREJ:
case CODE_CONFIGNAK:
- (*fp->fn->DecodeConfig)(fp, ptr, count, MODE_NOP, NULL);
- if (count < sizeof(struct fsmconfig))
+ (*fp->fn->DecodeConfig)(fp, ptr, ptr + count, MODE_NOP, NULL);
+ if (count < sizeof(struct fsm_opt_hdr))
log_Printf(fp->LogLevel, " [EMPTY]\n");
break;
}
@@ -470,16 +469,35 @@ FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
struct fsm_decode dec;
int plen, flen;
int ackaction = 0;
+ u_char *cp;
+ bp = m_pullup(bp);
plen = m_length(bp);
flen = ntohs(lhp->length) - sizeof *lhp;
if (plen < flen) {
log_Printf(LogWARN, "%s: FsmRecvConfigReq: plen (%d) < flen (%d)\n",
- fp->link->name, plen, flen);
+ fp->link->name, plen, flen);
m_freem(bp);
return;
}
+ /* Some things must be done before we Decode the packet */
+ switch (fp->state) {
+ case ST_OPENED:
+ (*fp->fn->LayerDown)(fp);
+ }
+
+ dec.ackend = dec.ack;
+ dec.nakend = dec.nak;
+ dec.rejend = dec.rej;
+ cp = MBUF_CTOP(bp);
+ (*fp->fn->DecodeConfig)(fp, cp, cp + flen, MODE_REQ, &dec);
+ if (flen < sizeof(struct fsm_opt_hdr))
+ log_Printf(fp->LogLevel, " [EMPTY]\n");
+
+ if (dec.nakend == dec.nak && dec.rejend == dec.rej)
+ ackaction = 1;
+
/* Check and process easy case */
switch (fp->state) {
case ST_INITIAL:
@@ -511,27 +529,9 @@ FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
case ST_STOPPING:
m_freem(bp);
return;
- case ST_OPENED:
- (*fp->fn->LayerDown)(fp);
- break;
- }
-
- bp = m_pullup(bp);
- dec.ackend = dec.ack;
- dec.nakend = dec.nak;
- dec.rejend = dec.rej;
- (*fp->fn->DecodeConfig)(fp, MBUF_CTOP(bp), flen, MODE_REQ, &dec);
- if (flen < sizeof(struct fsmconfig))
- log_Printf(fp->LogLevel, " [EMPTY]\n");
-
- if (dec.nakend == dec.nak && dec.rejend == dec.rej)
- ackaction = 1;
-
- switch (fp->state) {
case ST_STOPPED:
FsmInitRestartCounter(fp, FSM_REQ_TIMER);
- /* Fall through */
-
+ /* Drop through */
case ST_OPENED:
FsmSendConfigReq(fp);
break;
@@ -609,6 +609,26 @@ static void
FsmRecvConfigAck(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
/* RCA */
{
+ struct fsm_decode dec;
+ int plen, flen;
+ u_char *cp;
+
+ plen = m_length(bp);
+ flen = ntohs(lhp->length) - sizeof *lhp;
+ if (plen < flen) {
+ m_freem(bp);
+ return;
+ }
+
+ bp = m_pullup(bp);
+ dec.ackend = dec.ack;
+ dec.nakend = dec.nak;
+ dec.rejend = dec.rej;
+ cp = MBUF_CTOP(bp);
+ (*fp->fn->DecodeConfig)(fp, cp, cp + flen, MODE_ACK, &dec);
+ if (flen < sizeof(struct fsm_opt_hdr))
+ log_Printf(fp->LogLevel, " [EMPTY]\n");
+
switch (fp->state) {
case ST_CLOSED:
case ST_STOPPED:
@@ -654,6 +674,7 @@ FsmRecvConfigNak(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
{
struct fsm_decode dec;
int plen, flen;
+ u_char *cp;
plen = m_length(bp);
flen = ntohs(lhp->length) - sizeof *lhp;
@@ -687,8 +708,9 @@ FsmRecvConfigNak(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
dec.ackend = dec.ack;
dec.nakend = dec.nak;
dec.rejend = dec.rej;
- (*fp->fn->DecodeConfig)(fp, MBUF_CTOP(bp), flen, MODE_NAK, &dec);
- if (flen < sizeof(struct fsmconfig))
+ cp = MBUF_CTOP(bp);
+ (*fp->fn->DecodeConfig)(fp, cp, cp + flen, MODE_NAK, &dec);
+ if (flen < sizeof(struct fsm_opt_hdr))
log_Printf(fp->LogLevel, " [EMPTY]\n");
switch (fp->state) {
@@ -782,6 +804,7 @@ FsmRecvConfigRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
{
struct fsm_decode dec;
int plen, flen;
+ u_char *cp;
plen = m_length(bp);
flen = ntohs(lhp->length) - sizeof *lhp;
@@ -817,8 +840,9 @@ FsmRecvConfigRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
dec.ackend = dec.ack;
dec.nakend = dec.nak;
dec.rejend = dec.rej;
- (*fp->fn->DecodeConfig)(fp, MBUF_CTOP(bp), flen, MODE_REJ, &dec);
- if (flen < sizeof(struct fsmconfig))
+ cp = MBUF_CTOP(bp);
+ (*fp->fn->DecodeConfig)(fp, cp, cp + flen, MODE_REJ, &dec);
+ if (flen < sizeof(struct fsm_opt_hdr))
log_Printf(fp->LogLevel, " [EMPTY]\n");
switch (fp->state) {
@@ -1052,12 +1076,12 @@ fsm_Input(struct fsm *fp, struct mbuf *bp)
if (lh.id != fp->reqid && codep->check_reqid &&
Enabled(fp->bundle, OPT_IDCHECK)) {
log_Printf(fp->LogLevel, "%s: Recv%s(%d), dropped (expected %d)\n",
- fp->link->name, codep->name, lh.id, fp->reqid);
+ fp->link->name, codep->name, lh.id, fp->reqid);
return;
}
log_Printf(fp->LogLevel, "%s: Recv%s(%d) state = %s\n",
- fp->link->name, codep->name, lh.id, State2Nam(fp->state));
+ fp->link->name, codep->name, lh.id, State2Nam(fp->state));
if (codep->inc_reqid && (lh.id == fp->reqid ||
(!Enabled(fp->bundle, OPT_IDCHECK) && codep->check_reqid)))
@@ -1106,3 +1130,80 @@ fsm2initial(struct fsm *fp)
if (fp->state > ST_INITIAL)
fsm_Close(fp);
}
+
+struct fsm_opt *
+fsm_readopt(u_char **cp)
+{
+ struct fsm_opt *o = (struct fsm_opt *)*cp;
+
+ if (o->hdr.len < sizeof(struct fsm_opt_hdr)) {
+ log_Printf(LogERROR, "Bad option length %d (out of phase?)\n", o->hdr.len);
+ return NULL;
+ }
+
+ *cp += o->hdr.len;
+
+ if (o->hdr.len > sizeof(struct fsm_opt)) {
+ o->hdr.len = sizeof(struct fsm_opt);
+ log_Printf(LogERROR, "Warning: Truncating option length to %d\n",
+ o->hdr.len);
+ }
+
+ return o;
+}
+
+static int
+fsm_opt(u_char *opt, int optlen, const struct fsm_opt *o)
+{
+ int cplen = o->hdr.len;
+
+ if (optlen < sizeof(struct fsm_opt_hdr))
+ optlen = 0;
+
+ if (cplen > optlen) {
+ log_Printf(LogERROR, "Can't REJ length %d - trunating to %d\n",
+ cplen, optlen);
+ cplen = optlen;
+ }
+ memcpy(opt, o, cplen);
+ if (cplen)
+ opt[1] = cplen;
+
+ return cplen;
+}
+
+void
+fsm_rej(struct fsm_decode *dec, const struct fsm_opt *o)
+{
+ if (!dec)
+ return;
+ dec->rejend += fsm_opt(dec->rejend, FSM_OPTLEN - (dec->rejend - dec->rej), o);
+}
+
+void
+fsm_ack(struct fsm_decode *dec, const struct fsm_opt *o)
+{
+ if (!dec)
+ return;
+ dec->ackend += fsm_opt(dec->ackend, FSM_OPTLEN - (dec->ackend - dec->ack), o);
+}
+
+void
+fsm_nak(struct fsm_decode *dec, const struct fsm_opt *o)
+{
+ if (!dec)
+ return;
+ dec->nakend += fsm_opt(dec->nakend, FSM_OPTLEN - (dec->nakend - dec->nak), o);
+}
+
+void
+fsm_opt_normalise(struct fsm_decode *dec)
+{
+ if (dec->rejend != dec->rej) {
+ /* rejects are preferred */
+ dec->ackend = dec->ack;
+ dec->nakend = dec->nak;
+ } else if (dec->nakend != dec->nak)
+ /* then NAKs */
+ dec->ackend = dec->ack;
+}
diff --git a/usr.sbin/ppp/ppp/fsm.h b/usr.sbin/ppp/ppp/fsm.h
index 200dc15d1dd..769bb7a2416 100644
--- a/usr.sbin/ppp/ppp/fsm.h
+++ b/usr.sbin/ppp/ppp/fsm.h
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: fsm.h,v 1.8 2001/06/19 10:24:53 brian Exp $
+ * $OpenBSD: fsm.h,v 1.9 2002/05/16 01:13:39 brian Exp $
*/
/*
@@ -56,6 +56,8 @@
#define FSM_REQ_TIMER 1
#define FSM_TRM_TIMER 2
+#define FSM_OPTLEN 100
+
struct fsm;
struct fsm_retry {
@@ -65,24 +67,24 @@ struct fsm_retry {
};
struct fsm_decode {
- u_char ack[100], *ackend;
- u_char nak[100], *nakend;
- u_char rej[100], *rejend;
+ u_char ack[FSM_OPTLEN], *ackend;
+ u_char nak[FSM_OPTLEN], *nakend;
+ u_char rej[FSM_OPTLEN], *rejend;
};
struct fsm_callbacks {
- int (*LayerUp) (struct fsm *); /* Layer is now up (tlu) */
- void (*LayerDown) (struct fsm *); /* About to come down (tld) */
- void (*LayerStart) (struct fsm *); /* Layer about to start up (tls) */
- void (*LayerFinish) (struct fsm *); /* Layer now down (tlf) */
- void (*InitRestartCounter) (struct fsm *, int); /* Set fsm timer load */
- void (*SendConfigReq) (struct fsm *); /* Send REQ please */
- void (*SentTerminateReq) (struct fsm *); /* Term REQ just sent */
- void (*SendTerminateAck) (struct fsm *, u_char); /* Send Term ACK please */
- void (*DecodeConfig) (struct fsm *, u_char *, int, int, struct fsm_decode *);
- /* Deal with incoming data */
- int (*RecvResetReq) (struct fsm *fp); /* Reset output */
- void (*RecvResetAck) (struct fsm *fp, u_char); /* Reset input */
+ int (*LayerUp)(struct fsm *); /* Layer is now up (tlu) */
+ void (*LayerDown)(struct fsm *); /* About to come down (tld) */
+ void (*LayerStart)(struct fsm *); /* Layer about to start (tls) */
+ void (*LayerFinish)(struct fsm *); /* Layer now down (tlf) */
+ void (*InitRestartCounter)(struct fsm *, int);/* Set fsm timer load */
+ void (*SendConfigReq)(struct fsm *); /* Send REQ please */
+ void (*SentTerminateReq)(struct fsm *); /* Term REQ just sent */
+ void (*SendTerminateAck)(struct fsm *, u_char); /* Send Term ACK please */
+ void (*DecodeConfig)(struct fsm *, u_char *, u_char *, int,
+ struct fsm_decode *); /* Deal with incoming data */
+ int (*RecvResetReq)(struct fsm *fp); /* Reset output */
+ void (*RecvResetAck)(struct fsm *fp, u_char); /* Reset input */
};
struct fsm_parent {
@@ -159,12 +161,25 @@ struct fsmheader {
#define CODE_RESETREQ 14 /* Used in CCP */
#define CODE_RESETACK 15 /* Used in CCP */
-/* Minimum config req size. This struct is *only* used for it's size */
-struct fsmconfig {
- u_char type;
- u_char length;
+struct fsm_opt_hdr {
+ u_char id;
+ u_char len;
+};
+
+#define MAX_FSM_OPT_LEN 20
+struct fsm_opt {
+ struct fsm_opt_hdr hdr;
+ u_char data[MAX_FSM_OPT_LEN-2];
};
+#define INC_FSM_OPT(ty, length, o) \
+ do { \
+ (o)->hdr.id = (ty); \
+ (o)->hdr.len = (length); \
+ (o) = (struct fsm_opt *)((u_char *)(o) + (length)); \
+ } while (0)
+
+
extern void fsm_Init(struct fsm *, const char *, u_short, int, int, int,
struct bundle *, struct link *, const struct fsm_parent *,
struct fsm_callbacks *, const char * const [3]);
@@ -179,3 +194,8 @@ extern void fsm_NullRecvResetAck(struct fsm *, u_char);
extern void fsm_Reopen(struct fsm *);
extern void fsm2initial(struct fsm *);
extern const char *State2Nam(u_int);
+extern struct fsm_opt *fsm_readopt(u_char **);
+extern void fsm_rej(struct fsm_decode *, const struct fsm_opt *);
+extern void fsm_ack(struct fsm_decode *, const struct fsm_opt *);
+extern void fsm_nak(struct fsm_decode *, const struct fsm_opt *);
+extern void fsm_opt_normalise(struct fsm_decode *);
diff --git a/usr.sbin/ppp/ppp/i4b.c b/usr.sbin/ppp/ppp/i4b.c
index 71342ff6094..7c9685e36ac 100644
--- a/usr.sbin/ppp/ppp/i4b.c
+++ b/usr.sbin/ppp/ppp/i4b.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: i4b.c,v 1.7 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: i4b.c,v 1.8 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -32,6 +32,7 @@
#if defined(__OpenBSD__) || defined(__NetBSD__)
#include <sys/ioctl.h>
#endif
+#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
@@ -274,6 +275,17 @@ i4b_OpenInfo(struct physical *p)
return buf;
}
+static int
+i4b_Slot(struct physical *p)
+{
+ struct stat st;
+
+ if (fstat(p->fd, &st) == 0)
+ return minor(st.st_rdev);
+
+ return -1;
+}
+
static void
i4b_device2iov(struct device *d, struct iovec *iov, int *niov,
int maxiov, int *auxfd, int *nauxfd)
@@ -312,7 +324,8 @@ static struct device basei4bdevice = {
NULL,
i4b_device2iov,
i4b_Speed,
- i4b_OpenInfo
+ i4b_OpenInfo,
+ i4b_Slot
};
struct device *
diff --git a/usr.sbin/ppp/ppp/iface.c b/usr.sbin/ppp/ppp/iface.c
index c40d487a583..6140c76ad26 100644
--- a/usr.sbin/ppp/ppp/iface.c
+++ b/usr.sbin/ppp/ppp/iface.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: iface.c,v 1.23 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: iface.c,v 1.24 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -35,7 +35,6 @@
#include <net/if_var.h>
#endif
#include <net/route.h>
-#include <arpa/inet.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
@@ -68,7 +67,6 @@
#include "slcompress.h"
#include "descriptor.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "lcp.h"
diff --git a/usr.sbin/ppp/ppp/ip.c b/usr.sbin/ppp/ppp/ip.c
index 67ecbf51388..ce02d7ad390 100644
--- a/usr.sbin/ppp/ppp/ip.c
+++ b/usr.sbin/ppp/ppp/ip.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: ip.c,v 1.34 2001/08/19 23:22:17 brian Exp $
+ * $OpenBSD: ip.c,v 1.35 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -40,13 +40,11 @@
#include <netinet/ip_icmp.h>
#include <netinet/udp.h>
#include <netinet/tcp.h>
-#include <arpa/inet.h>
#include <sys/un.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
diff --git a/usr.sbin/ppp/ppp/ipcp.c b/usr.sbin/ppp/ppp/ipcp.c
index 3f81b3253f8..48627502ee2 100644
--- a/usr.sbin/ppp/ppp/ipcp.c
+++ b/usr.sbin/ppp/ppp/ipcp.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: ipcp.c,v 1.34 2002/01/16 14:13:06 brian Exp $
+ * $OpenBSD: ipcp.c,v 1.35 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -114,7 +114,7 @@ static void IpcpInitRestartCounter(struct fsm *, int);
static void IpcpSendConfigReq(struct fsm *);
static void IpcpSentTerminateReq(struct fsm *);
static void IpcpSendTerminateAck(struct fsm *, u_char);
-static void IpcpDecodeConfig(struct fsm *, u_char *, int, int,
+static void IpcpDecodeConfig(struct fsm *, u_char *, u_char *, int,
struct fsm_decode *);
static struct fsm_callbacks ipcp_Callbacks = {
@@ -351,9 +351,9 @@ ipcp_Show(struct cmdargs const *arg)
State2Nam(ipcp->fsm.state));
if (ipcp->fsm.state == ST_OPENED) {
prompt_Printf(arg->prompt, " His side: %s, %s\n",
- inet_ntoa(ipcp->peer_ip), vj2asc(ipcp->peer_compproto));
+ inet_ntoa(ipcp->peer_ip), vj2asc(ipcp->peer_compproto));
prompt_Printf(arg->prompt, " My side: %s, %s\n",
- inet_ntoa(ipcp->my_ip), vj2asc(ipcp->my_compproto));
+ inet_ntoa(ipcp->my_ip), vj2asc(ipcp->my_compproto));
prompt_Printf(arg->prompt, " Queued packets: %lu\n",
(unsigned long)ipcp_QueueLen(ipcp));
}
@@ -364,7 +364,7 @@ ipcp_Show(struct cmdargs const *arg)
ipcp->cfg.fsm.maxreq, ipcp->cfg.fsm.maxreq == 1 ? "" : "s",
ipcp->cfg.fsm.maxtrm, ipcp->cfg.fsm.maxtrm == 1 ? "" : "s");
prompt_Printf(arg->prompt, " My Address: %s\n",
- ncprange_ntoa(&ipcp->cfg.my_range));
+ ncprange_ntoa(&ipcp->cfg.my_range));
if (ipcp->cfg.HaveTriggerAddress)
prompt_Printf(arg->prompt, " Trigger address: %s\n",
inet_ntoa(ipcp->cfg.TriggerAddress));
@@ -378,7 +378,7 @@ ipcp_Show(struct cmdargs const *arg)
ipcp->cfg.peer_list.src);
else
prompt_Printf(arg->prompt, " His Address: %s\n",
- ncprange_ntoa(&ipcp->cfg.peer_range));
+ ncprange_ntoa(&ipcp->cfg.peer_range));
prompt_Printf(arg->prompt, " DNS: %s",
ipcp->cfg.ns.dns[0].s_addr == INADDR_NONE ?
@@ -396,7 +396,7 @@ ipcp_Show(struct cmdargs const *arg)
prompt_Printf(arg->prompt, ", %s",
inet_ntoa(ipcp->ns.dns[1]));
prompt_Printf(arg->prompt, "\n NetBIOS NS: %s, ",
- inet_ntoa(ipcp->cfg.ns.nbns[0]));
+ inet_ntoa(ipcp->cfg.ns.nbns[0]));
prompt_Printf(arg->prompt, "%s\n\n",
inet_ntoa(ipcp->cfg.ns.nbns[1]));
@@ -754,13 +754,13 @@ IpcpSendConfigReq(struct fsm *fp)
struct physical *p = link2physical(fp->link);
struct ipcp *ipcp = fsm2ipcp(fp);
u_char buff[24];
- struct lcp_opt *o;
+ struct fsm_opt *o;
- o = (struct lcp_opt *)buff;
+ o = (struct fsm_opt *)buff;
if ((p && !physical_IsSync(p)) || !REJECTED(ipcp, TY_IPADDR)) {
memcpy(o->data, &ipcp->my_ip.s_addr, 4);
- INC_LCP_OPT(TY_IPADDR, 6, o);
+ INC_FSM_OPT(TY_IPADDR, 6, o);
}
if (ipcp->my_compproto && !REJECTED(ipcp, TY_COMPPROTO)) {
@@ -768,7 +768,7 @@ IpcpSendConfigReq(struct fsm *fp)
u_int16_t proto = PROTO_VJCOMP;
ua_htons(&proto, o->data);
- INC_LCP_OPT(TY_COMPPROTO, 4, o);
+ INC_FSM_OPT(TY_COMPPROTO, 4, o);
} else {
struct compreq req;
@@ -776,19 +776,19 @@ IpcpSendConfigReq(struct fsm *fp)
req.slots = (ipcp->my_compproto >> 8) & 255;
req.compcid = ipcp->my_compproto & 1;
memcpy(o->data, &req, 4);
- INC_LCP_OPT(TY_COMPPROTO, 6, o);
+ INC_FSM_OPT(TY_COMPPROTO, 6, o);
}
}
if (IsEnabled(ipcp->cfg.ns.dns_neg)) {
if (!REJECTED(ipcp, TY_PRIMARY_DNS - TY_ADJUST_NS)) {
memcpy(o->data, &ipcp->ns.dns[0].s_addr, 4);
- INC_LCP_OPT(TY_PRIMARY_DNS, 6, o);
+ INC_FSM_OPT(TY_PRIMARY_DNS, 6, o);
}
if (!REJECTED(ipcp, TY_SECONDARY_DNS - TY_ADJUST_NS)) {
memcpy(o->data, &ipcp->ns.dns[1].s_addr, 4);
- INC_LCP_OPT(TY_SECONDARY_DNS, 6, o);
+ INC_FSM_OPT(TY_SECONDARY_DNS, 6, o);
}
}
@@ -1033,130 +1033,126 @@ ipcp_ValidateReq(struct ipcp *ipcp, struct in_addr ip, struct fsm_decode *dec)
}
static void
-IpcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
+IpcpDecodeConfig(struct fsm *fp, u_char *cp, u_char *end, int mode_type,
struct fsm_decode *dec)
{
/* Deal with incoming PROTO_IPCP */
struct ncpaddr ncpaddr;
struct ipcp *ipcp = fsm2ipcp(fp);
- int type, length, gotdnsnak;
+ int gotdnsnak;
u_int32_t compproto;
struct compreq *pcomp;
struct in_addr ipaddr, dstipaddr, have_ip;
char tbuff[100], tbuff2[100];
+ struct fsm_opt *opt, nak;
gotdnsnak = 0;
- while (plen >= sizeof(struct fsmconfig)) {
- type = *cp;
- length = cp[1];
-
- if (length == 0) {
- log_Printf(LogIPCP, "%s: IPCP size zero\n", fp->link->name);
+ while (end - cp >= sizeof(opt->hdr)) {
+ if ((opt = fsm_readopt(&cp)) == NULL)
break;
- }
- snprintf(tbuff, sizeof tbuff, " %s[%d] ", protoname(type), length);
+ snprintf(tbuff, sizeof tbuff, " %s[%d]", protoname(opt->hdr.id),
+ opt->hdr.len);
- switch (type) {
+ switch (opt->hdr.id) {
case TY_IPADDR: /* RFC1332 */
- memcpy(&ipaddr.s_addr, cp + 2, 4);
+ memcpy(&ipaddr.s_addr, opt->data, 4);
log_Printf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
switch (mode_type) {
case MODE_REQ:
ipcp->peer_req = 1;
ipcp_ValidateReq(ipcp, ipaddr, dec);
- break;
+ break;
case MODE_NAK:
if (ncprange_containsip4(&ipcp->cfg.my_range, ipaddr)) {
- /* Use address suggested by peer */
- snprintf(tbuff2, sizeof tbuff2, "%s changing address: %s ", tbuff,
- inet_ntoa(ipcp->my_ip));
- log_Printf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
- ipcp->my_ip = ipaddr;
+ /* Use address suggested by peer */
+ snprintf(tbuff2, sizeof tbuff2, "%s changing address: %s ", tbuff,
+ inet_ntoa(ipcp->my_ip));
+ log_Printf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
+ ipcp->my_ip = ipaddr;
ncpaddr_setip4(&ncpaddr, ipcp->my_ip);
bundle_AdjustFilters(fp->bundle, &ncpaddr, NULL);
- } else {
- log_Printf(log_IsKept(LogIPCP) ? LogIPCP : LogPHASE,
+ } else {
+ log_Printf(log_IsKept(LogIPCP) ? LogIPCP : LogPHASE,
"%s: Unacceptable address!\n", inet_ntoa(ipaddr));
fsm_Close(&ipcp->fsm);
- }
- break;
+ }
+ break;
case MODE_REJ:
- ipcp->peer_reject |= (1 << type);
- break;
+ ipcp->peer_reject |= (1 << opt->hdr.id);
+ break;
}
break;
case TY_COMPPROTO:
- pcomp = (struct compreq *)(cp + 2);
+ pcomp = (struct compreq *)opt->data;
compproto = (ntohs(pcomp->proto) << 16) + (pcomp->slots << 8) +
pcomp->compcid;
log_Printf(LogIPCP, "%s %s\n", tbuff, vj2asc(compproto));
switch (mode_type) {
case MODE_REQ:
- if (!IsAccepted(ipcp->cfg.vj.neg)) {
- memcpy(dec->rejend, cp, length);
- dec->rejend += length;
- } else {
- switch (length) {
- case 4: /* RFC1172 */
- if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
- log_Printf(LogWARN, "Peer is speaking RFC1172 compression "
+ if (!IsAccepted(ipcp->cfg.vj.neg))
+ fsm_rej(dec, opt);
+ else {
+ switch (opt->hdr.len) {
+ case 4: /* RFC1172 */
+ if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
+ log_Printf(LogWARN, "Peer is speaking RFC1172 compression "
"protocol !\n");
- ipcp->heis1172 = 1;
- ipcp->peer_compproto = compproto;
- memcpy(dec->ackend, cp, length);
- dec->ackend += length;
- } else {
- memcpy(dec->nakend, cp, 2);
- pcomp->proto = htons(PROTO_VJCOMP);
- memcpy(dec->nakend+2, &pcomp, 2);
- dec->nakend += length;
- }
- break;
- case 6: /* RFC1332 */
- if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
+ ipcp->heis1172 = 1;
+ ipcp->peer_compproto = compproto;
+ fsm_ack(dec, opt);
+ } else {
+ pcomp->proto = htons(PROTO_VJCOMP);
+ nak.hdr.id = TY_COMPPROTO;
+ nak.hdr.len = 4;
+ memcpy(nak.data, &pcomp, 2);
+ fsm_nak(dec, &nak);
+ }
+ break;
+ case 6: /* RFC1332 */
+ if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
if (pcomp->slots <= MAX_VJ_STATES
&& pcomp->slots >= MIN_VJ_STATES) {
/* Ok, we can do that */
- ipcp->peer_compproto = compproto;
- ipcp->heis1172 = 0;
- memcpy(dec->ackend, cp, length);
- dec->ackend += length;
- } else {
+ ipcp->peer_compproto = compproto;
+ ipcp->heis1172 = 0;
+ fsm_ack(dec, opt);
+ } else {
/* Get as close as we can to what he wants */
- ipcp->heis1172 = 0;
- memcpy(dec->nakend, cp, 2);
- pcomp->slots = pcomp->slots < MIN_VJ_STATES ?
+ ipcp->heis1172 = 0;
+ pcomp->slots = pcomp->slots < MIN_VJ_STATES ?
MIN_VJ_STATES : MAX_VJ_STATES;
- memcpy(dec->nakend+2, &pcomp, sizeof pcomp);
- dec->nakend += length;
+ nak.hdr.id = TY_COMPPROTO;
+ nak.hdr.len = 4;
+ memcpy(nak.data, &pcomp, 2);
+ fsm_nak(dec, &nak);
}
- } else {
+ } else {
/* What we really want */
- memcpy(dec->nakend, cp, 2);
- pcomp->proto = htons(PROTO_VJCOMP);
- pcomp->slots = DEF_VJ_STATES;
- pcomp->compcid = 1;
- memcpy(dec->nakend+2, &pcomp, sizeof pcomp);
- dec->nakend += length;
- }
- break;
- default:
- memcpy(dec->rejend, cp, length);
- dec->rejend += length;
- break;
- }
- }
- break;
+ pcomp->proto = htons(PROTO_VJCOMP);
+ pcomp->slots = DEF_VJ_STATES;
+ pcomp->compcid = 1;
+ nak.hdr.id = TY_COMPPROTO;
+ nak.hdr.len = 6;
+ memcpy(nak.data, &pcomp, sizeof pcomp);
+ fsm_nak(dec, &nak);
+ }
+ break;
+ default:
+ fsm_rej(dec, opt);
+ break;
+ }
+ }
+ break;
case MODE_NAK:
- if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
+ if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
if (pcomp->slots > MAX_VJ_STATES)
pcomp->slots = MAX_VJ_STATES;
else if (pcomp->slots < MIN_VJ_STATES)
@@ -1165,51 +1161,49 @@ IpcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
pcomp->compcid;
} else
compproto = 0;
- log_Printf(LogIPCP, "%s changing compproto: %08x --> %08x\n",
- tbuff, ipcp->my_compproto, compproto);
+ log_Printf(LogIPCP, "%s changing compproto: %08x --> %08x\n",
+ tbuff, ipcp->my_compproto, compproto);
ipcp->my_compproto = compproto;
- break;
+ break;
case MODE_REJ:
- ipcp->peer_reject |= (1 << type);
- break;
+ ipcp->peer_reject |= (1 << opt->hdr.id);
+ break;
}
break;
case TY_IPADDRS: /* RFC1172 */
- memcpy(&ipaddr.s_addr, cp + 2, 4);
- memcpy(&dstipaddr.s_addr, cp + 6, 4);
+ memcpy(&ipaddr.s_addr, opt->data, 4);
+ memcpy(&dstipaddr.s_addr, opt->data + 4, 4);
snprintf(tbuff2, sizeof tbuff2, "%s %s,", tbuff, inet_ntoa(ipaddr));
log_Printf(LogIPCP, "%s %s\n", tbuff2, inet_ntoa(dstipaddr));
switch (mode_type) {
case MODE_REQ:
- memcpy(dec->rejend, cp, length);
- dec->rejend += length;
- break;
+ fsm_rej(dec, opt);
+ break;
case MODE_NAK:
case MODE_REJ:
- break;
+ break;
}
break;
case TY_PRIMARY_DNS: /* DNS negotiation (rfc1877) */
case TY_SECONDARY_DNS:
- memcpy(&ipaddr.s_addr, cp + 2, 4);
+ memcpy(&ipaddr.s_addr, opt->data, 4);
log_Printf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
switch (mode_type) {
case MODE_REQ:
if (!IsAccepted(ipcp->cfg.ns.dns_neg)) {
- ipcp->my_reject |= (1 << (type - TY_ADJUST_NS));
- memcpy(dec->rejend, cp, length);
- dec->rejend += length;
- break;
+ ipcp->my_reject |= (1 << (opt->hdr.id - TY_ADJUST_NS));
+ fsm_rej(dec, opt);
+ break;
}
- have_ip = ipcp->ns.dns[type == TY_PRIMARY_DNS ? 0 : 1];
+ have_ip = ipcp->ns.dns[opt->hdr.id == TY_PRIMARY_DNS ? 0 : 1];
- if (type == TY_PRIMARY_DNS && ipaddr.s_addr != have_ip.s_addr &&
+ if (opt->hdr.id == TY_PRIMARY_DNS && ipaddr.s_addr != have_ip.s_addr &&
ipaddr.s_addr == ipcp->ns.dns[1].s_addr) {
/* Swap 'em 'round */
ipcp->ns.dns[0] = ipcp->ns.dns[1];
@@ -1217,86 +1211,81 @@ IpcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
have_ip = ipcp->ns.dns[0];
}
- if (ipaddr.s_addr != have_ip.s_addr) {
- /*
- * The client has got the DNS stuff wrong (first request) so
- * we'll tell 'em how it is
- */
- memcpy(dec->nakend, cp, 2); /* copy first two (type/length) */
- memcpy(dec->nakend + 2, &have_ip.s_addr, length - 2);
- dec->nakend += length;
- } else {
- /*
- * Otherwise they have it right (this time) so we send a ack packet
- * back confirming it... end of story
- */
- memcpy(dec->ackend, cp, length);
- dec->ackend += length;
+ if (ipaddr.s_addr != have_ip.s_addr) {
+ /*
+ * The client has got the DNS stuff wrong (first request) so
+ * we'll tell 'em how it is
+ */
+ nak.hdr.id = opt->hdr.id;
+ nak.hdr.len = 6;
+ memcpy(nak.data, &have_ip.s_addr, 4);
+ fsm_nak(dec, &nak);
+ } else {
+ /*
+ * Otherwise they have it right (this time) so we send a ack packet
+ * back confirming it... end of story
+ */
+ fsm_ack(dec, opt);
}
- break;
+ break;
case MODE_NAK:
if (IsEnabled(ipcp->cfg.ns.dns_neg)) {
gotdnsnak = 1;
- memcpy(&ipcp->ns.dns[type == TY_PRIMARY_DNS ? 0 : 1].s_addr,
- cp + 2, 4);
- }
- break;
+ memcpy(&ipcp->ns.dns[opt->hdr.id == TY_PRIMARY_DNS ? 0 : 1].s_addr,
+ opt->data, 4);
+ }
+ break;
case MODE_REJ: /* Can't do much, stop asking */
- ipcp->peer_reject |= (1 << (type - TY_ADJUST_NS));
- break;
+ ipcp->peer_reject |= (1 << (opt->hdr.id - TY_ADJUST_NS));
+ break;
}
break;
case TY_PRIMARY_NBNS: /* M$ NetBIOS nameserver hack (rfc1877) */
case TY_SECONDARY_NBNS:
- memcpy(&ipaddr.s_addr, cp + 2, 4);
+ memcpy(&ipaddr.s_addr, opt->data, 4);
log_Printf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
switch (mode_type) {
case MODE_REQ:
- have_ip.s_addr =
- ipcp->cfg.ns.nbns[type == TY_PRIMARY_NBNS ? 0 : 1].s_addr;
+ have_ip.s_addr =
+ ipcp->cfg.ns.nbns[opt->hdr.id == TY_PRIMARY_NBNS ? 0 : 1].s_addr;
if (have_ip.s_addr == INADDR_ANY) {
- log_Printf(LogIPCP, "NBNS REQ - rejected - nbns not set\n");
- ipcp->my_reject |= (1 << (type - TY_ADJUST_NS));
- memcpy(dec->rejend, cp, length);
- dec->rejend += length;
- break;
+ log_Printf(LogIPCP, "NBNS REQ - rejected - nbns not set\n");
+ ipcp->my_reject |= (1 << (opt->hdr.id - TY_ADJUST_NS));
+ fsm_rej(dec, opt);
+ break;
}
- if (ipaddr.s_addr != have_ip.s_addr) {
- memcpy(dec->nakend, cp, 2);
- memcpy(dec->nakend+2, &have_ip.s_addr, length);
- dec->nakend += length;
- } else {
- memcpy(dec->ackend, cp, length);
- dec->ackend += length;
- }
- break;
+ if (ipaddr.s_addr != have_ip.s_addr) {
+ nak.hdr.id = opt->hdr.id;
+ nak.hdr.len = 6;
+ memcpy(nak.data, &have_ip.s_addr, 4);
+ fsm_nak(dec, &nak);
+ } else
+ fsm_ack(dec, opt);
+ break;
case MODE_NAK:
- log_Printf(LogIPCP, "MS NBNS req %d - NAK??\n", type);
- break;
+ log_Printf(LogIPCP, "MS NBNS req %d - NAK??\n", opt->hdr.id);
+ break;
case MODE_REJ:
- log_Printf(LogIPCP, "MS NBNS req %d - REJ??\n", type);
- break;
+ log_Printf(LogIPCP, "MS NBNS req %d - REJ??\n", opt->hdr.id);
+ break;
}
break;
default:
if (mode_type != MODE_NOP) {
- ipcp->my_reject |= (1 << type);
- memcpy(dec->rejend, cp, length);
- dec->rejend += length;
+ ipcp->my_reject |= (1 << opt->hdr.id);
+ fsm_rej(dec, opt);
}
break;
}
- plen -= length;
- cp += length;
}
if (gotdnsnak) {
@@ -1328,13 +1317,7 @@ IpcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
ipaddr.s_addr = INADDR_ANY;
ipcp_ValidateReq(ipcp, ipaddr, dec);
}
- if (dec->rejend != dec->rej) {
- /* rejects are preferred */
- dec->ackend = dec->ack;
- dec->nakend = dec->nak;
- } else if (dec->nakend != dec->nak)
- /* then NAKs */
- dec->ackend = dec->ack;
+ fsm_opt_normalise(dec);
}
}
diff --git a/usr.sbin/ppp/ppp/ipv6cp.c b/usr.sbin/ppp/ppp/ipv6cp.c
index 229b02e4871..0c76927efbd 100644
--- a/usr.sbin/ppp/ppp/ipv6cp.c
+++ b/usr.sbin/ppp/ppp/ipv6cp.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
+ * $OpenBSD: ipv6cp.c,v 1.2 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -85,7 +85,7 @@ static void ipv6cp_InitRestartCounter(struct fsm *, int);
static void ipv6cp_SendConfigReq(struct fsm *);
static void ipv6cp_SentTerminateReq(struct fsm *);
static void ipv6cp_SendTerminateAck(struct fsm *, u_char);
-static void ipv6cp_DecodeConfig(struct fsm *, u_char *, int, int,
+static void ipv6cp_DecodeConfig(struct fsm *, u_char *, u_char *, int,
struct fsm_decode *);
static struct fsm_callbacks ipv6cp_Callbacks = {
@@ -233,9 +233,9 @@ ipv6cp_Show(struct cmdargs const *arg)
State2Nam(ipv6cp->fsm.state));
if (ipv6cp->fsm.state == ST_OPENED) {
prompt_Printf(arg->prompt, " His side: %s\n",
- ncpaddr_ntoa(&ipv6cp->hisaddr));
+ ncpaddr_ntoa(&ipv6cp->hisaddr));
prompt_Printf(arg->prompt, " My side: %s\n",
- ncpaddr_ntoa(&ipv6cp->myaddr));
+ ncpaddr_ntoa(&ipv6cp->myaddr));
prompt_Printf(arg->prompt, " Queued packets: %lu\n",
(unsigned long)ipv6cp_QueueLen(ipv6cp));
}
@@ -455,13 +455,13 @@ ipv6cp_SendConfigReq(struct fsm *fp)
struct physical *p = link2physical(fp->link);
struct ipv6cp *ipv6cp = fsm2ipv6cp(fp);
u_char buff[6];
- struct lcp_opt *o;
+ struct fsm_opt *o;
- o = (struct lcp_opt *)buff;
+ o = (struct fsm_opt *)buff;
if ((p && !physical_IsSync(p)) || !REJECTED(ipv6cp, TY_TOKEN)) {
memcpy(o->data, &ipv6cp->my_token, 4);
- INC_LCP_OPT(TY_TOKEN, 6, o);
+ INC_FSM_OPT(TY_TOKEN, 6, o);
}
fsm_Output(fp, CODE_CONFIGREQ, fp->reqid, buff, (u_char *)o - buff,
@@ -496,61 +496,56 @@ static void
ipv6cp_ValidateToken(struct ipv6cp *ipv6cp, u_int32_t token,
struct fsm_decode *dec)
{
+ struct fsm_opt opt;
+
if (token != 0 && token != ipv6cp->my_token)
ipv6cp->peer_token = token;
- if (token == ipv6cp->peer_token) {
- *dec->ackend++ = TY_TOKEN;
- *dec->ackend++ = 6;
- memcpy(dec->ackend, &ipv6cp->peer_token, 4);
- dec->ackend += 4;
- } else {
- *dec->nakend++ = TY_TOKEN;
- *dec->nakend++ = 6;
- memcpy(dec->nakend, &ipv6cp->peer_token, 4);
- dec->nakend += 4;
- }
+ opt.hdr.id = TY_TOKEN;
+ opt.hdr.len = 6;
+ memcpy(opt.data, &ipv6cp->peer_token, 4);
+ if (token == ipv6cp->peer_token)
+ fsm_ack(dec, &opt);
+ else
+ fsm_nak(dec, &opt);
}
static void
-ipv6cp_DecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
+ipv6cp_DecodeConfig(struct fsm *fp, u_char *cp, u_char *end, int mode_type,
struct fsm_decode *dec)
{
/* Deal with incoming PROTO_IPV6CP */
struct ipv6cp *ipv6cp = fsm2ipv6cp(fp);
- int type, length, n;
+ int n;
char tbuff[100];
u_int32_t token;
+ struct fsm_opt *opt;
- while (plen >= sizeof(struct fsmconfig)) {
- type = *cp;
- length = cp[1];
-
- if (length == 0) {
- log_Printf(LogIPV6CP, "%s: IPV6CP size zero\n", fp->link->name);
+ while (end - cp >= sizeof(opt->hdr)) {
+ if ((opt = fsm_readopt(&cp)) == NULL)
break;
- }
- snprintf(tbuff, sizeof tbuff, " %s[%d] ", protoname(type), length);
+ snprintf(tbuff, sizeof tbuff, " %s[%d]", protoname(opt->hdr.id),
+ opt->hdr.len);
- switch (type) {
+ switch (opt->hdr.id) {
case TY_TOKEN:
- memcpy(&token, cp + 2, 4);
+ memcpy(&token, opt->data, 4);
log_Printf(LogIPV6CP, "%s 0x%08lx\n", tbuff, (unsigned long)token);
switch (mode_type) {
case MODE_REQ:
ipv6cp->peer_tokenreq = 1;
ipv6cp_ValidateToken(ipv6cp, token, dec);
- break;
+ break;
case MODE_NAK:
if (token == 0) {
- log_Printf(log_IsKept(LogIPV6CP) ? LogIPV6CP : LogPHASE,
+ log_Printf(log_IsKept(LogIPV6CP) ? LogIPV6CP : LogPHASE,
"0x00000000: Unacceptable token!\n");
fsm_Close(&ipv6cp->fsm);
} else if (token == ipv6cp->peer_token)
- log_Printf(log_IsKept(LogIPV6CP) ? LogIPV6CP : LogPHASE,
+ log_Printf(log_IsKept(LogIPV6CP) ? LogIPV6CP : LogPHASE,
"0x%08lx: Unacceptable token!\n", (unsigned long)token);
else if (token != ipv6cp->my_token) {
n = 100;
@@ -561,35 +556,32 @@ ipv6cp_DecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
}
if (n == 0) {
- log_Printf(log_IsKept(LogIPV6CP) ? LogIPV6CP : LogPHASE,
+ log_Printf(log_IsKept(LogIPV6CP) ? LogIPV6CP : LogPHASE,
"0x00000000: Unacceptable token!\n");
fsm_Close(&ipv6cp->fsm);
} else {
- log_Printf(LogIPV6CP, "%s changing token: 0x%08lx --> 0x%08lx\n",
+ log_Printf(LogIPV6CP, "%s changing token: 0x%08lx --> 0x%08lx\n",
tbuff, (unsigned long)ipv6cp->my_token,
(unsigned long)token);
ipv6cp->my_token = token;
bundle_AdjustFilters(fp->bundle, &ipv6cp->myaddr, NULL);
}
}
- break;
+ break;
case MODE_REJ:
- ipv6cp->his_reject |= (1 << type);
- break;
+ ipv6cp->his_reject |= (1 << opt->hdr.id);
+ break;
}
break;
default:
if (mode_type != MODE_NOP) {
- ipv6cp->my_reject |= (1 << type);
- memcpy(dec->rejend, cp, length);
- dec->rejend += length;
+ ipv6cp->my_reject |= (1 << opt->hdr.id);
+ fsm_rej(dec, opt);
}
break;
}
- plen -= length;
- cp += length;
}
if (mode_type != MODE_NOP) {
@@ -606,13 +598,7 @@ ipv6cp_DecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
}
ipv6cp_ValidateToken(ipv6cp, 0, dec);
}
- if (dec->rejend != dec->rej) {
- /* rejects are preferred */
- dec->ackend = dec->ack;
- dec->nakend = dec->nak;
- } else if (dec->nakend != dec->nak)
- /* then NAKs */
- dec->ackend = dec->ack;
+ fsm_opt_normalise(dec);
}
}
#endif
diff --git a/usr.sbin/ppp/ppp/lcp.c b/usr.sbin/ppp/ppp/lcp.c
index 57ded851603..7b561663f24 100644
--- a/usr.sbin/ppp/ppp/lcp.c
+++ b/usr.sbin/ppp/ppp/lcp.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: lcp.c,v 1.35 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: lcp.c,v 1.36 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -64,7 +64,6 @@
#include "prompt.h"
#include "slcompress.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "mp.h"
@@ -82,8 +81,7 @@
/* for received LQRs */
struct lqrreq {
- u_char type;
- u_char length;
+ struct fsm_opt_hdr hdr;
u_short proto; /* Quality protocol */
u_int32_t period; /* Reporting interval */
};
@@ -96,7 +94,7 @@ static void LcpInitRestartCounter(struct fsm *, int);
static void LcpSendConfigReq(struct fsm *);
static void LcpSentTerminateReq(struct fsm *);
static void LcpSendTerminateAck(struct fsm *, u_char);
-static void LcpDecodeConfig(struct fsm *, u_char *, int, int,
+static void LcpDecodeConfig(struct fsm *, u_char *, u_char *, int,
struct fsm_decode *);
static struct fsm_callbacks lcp_Callbacks = {
@@ -166,15 +164,15 @@ lcp_ReportStatus(struct cmdargs const *arg)
prompt_Printf(arg->prompt, "%s: %s [%s]\n", l->name, lcp->fsm.name,
State2Nam(lcp->fsm.state));
prompt_Printf(arg->prompt,
- " his side: MRU %d, ACCMAP %08lx, PROTOCOMP %s, ACFCOMP %s,\n"
- " MAGIC %08lx, MRRU %u, SHORTSEQ %s, REJECT %04x\n",
- lcp->his_mru, (u_long)lcp->his_accmap,
+ " his side: MRU %d, ACCMAP %08lx, PROTOCOMP %s, ACFCOMP %s,\n"
+ " MAGIC %08lx, MRRU %u, SHORTSEQ %s, REJECT %04x\n",
+ lcp->his_mru, (u_long)lcp->his_accmap,
lcp->his_protocomp ? "on" : "off",
lcp->his_acfcomp ? "on" : "off",
(u_long)lcp->his_magic, lcp->his_mrru,
lcp->his_shortseq ? "on" : "off", lcp->his_reject);
prompt_Printf(arg->prompt,
- " my side: MRU %d, ACCMAP %08lx, PROTOCOMP %s, ACFCOMP %s,\n"
+ " my side: MRU %d, ACCMAP %08lx, PROTOCOMP %s, ACFCOMP %s,\n"
" MAGIC %08lx, MRRU %u, SHORTSEQ %s, REJECT %04x\n",
lcp->want_mru, (u_long)lcp->want_accmap,
lcp->want_protocomp ? "on" : "off",
@@ -381,7 +379,7 @@ LcpSendConfigReq(struct fsm *fp)
struct physical *p = link2physical(fp->link);
struct lcp *lcp = fsm2lcp(fp);
u_char buff[200];
- struct lcp_opt *o;
+ struct fsm_opt *o;
struct mp *mp;
u_int16_t proto;
u_short maxmru;
@@ -392,17 +390,17 @@ LcpSendConfigReq(struct fsm *fp)
return;
}
- o = (struct lcp_opt *)buff;
+ o = (struct fsm_opt *)buff;
if (!physical_IsSync(p)) {
if (lcp->want_acfcomp && !REJECTED(lcp, TY_ACFCOMP))
- INC_LCP_OPT(TY_ACFCOMP, 2, o);
+ INC_FSM_OPT(TY_ACFCOMP, 2, o);
if (lcp->want_protocomp && !REJECTED(lcp, TY_PROTOCOMP))
- INC_LCP_OPT(TY_PROTOCOMP, 2, o);
+ INC_FSM_OPT(TY_PROTOCOMP, 2, o);
if (!REJECTED(lcp, TY_ACCMAP)) {
ua_htonl(&lcp->want_accmap, o->data);
- INC_LCP_OPT(TY_ACCMAP, 6, o);
+ INC_FSM_OPT(TY_ACCMAP, 6, o);
}
}
@@ -416,43 +414,43 @@ LcpSendConfigReq(struct fsm *fp)
}
if (!REJECTED(lcp, TY_MRU)) {
ua_htons(&lcp->want_mru, o->data);
- INC_LCP_OPT(TY_MRU, 4, o);
+ INC_FSM_OPT(TY_MRU, 4, o);
}
if (lcp->want_magic && !REJECTED(lcp, TY_MAGICNUM)) {
ua_htonl(&lcp->want_magic, o->data);
- INC_LCP_OPT(TY_MAGICNUM, 6, o);
+ INC_FSM_OPT(TY_MAGICNUM, 6, o);
}
if (lcp->want_lqrperiod && !REJECTED(lcp, TY_QUALPROTO)) {
proto = PROTO_LQR;
ua_htons(&proto, o->data);
ua_htonl(&lcp->want_lqrperiod, o->data + 2);
- INC_LCP_OPT(TY_QUALPROTO, 8, o);
+ INC_FSM_OPT(TY_QUALPROTO, 8, o);
}
switch (lcp->want_auth) {
case PROTO_PAP:
proto = PROTO_PAP;
ua_htons(&proto, o->data);
- INC_LCP_OPT(TY_AUTHPROTO, 4, o);
+ INC_FSM_OPT(TY_AUTHPROTO, 4, o);
break;
case PROTO_CHAP:
proto = PROTO_CHAP;
ua_htons(&proto, o->data);
o->data[2] = lcp->want_authtype;
- INC_LCP_OPT(TY_AUTHPROTO, 5, o);
+ INC_FSM_OPT(TY_AUTHPROTO, 5, o);
break;
}
if (!REJECTED(lcp, TY_CALLBACK)) {
if (lcp->want_callback.opmask & CALLBACK_BIT(CALLBACK_AUTH)) {
*o->data = CALLBACK_AUTH;
- INC_LCP_OPT(TY_CALLBACK, 3, o);
+ INC_FSM_OPT(TY_CALLBACK, 3, o);
} else if (lcp->want_callback.opmask & CALLBACK_BIT(CALLBACK_CBCP)) {
*o->data = CALLBACK_CBCP;
- INC_LCP_OPT(TY_CALLBACK, 3, o);
+ INC_FSM_OPT(TY_CALLBACK, 3, o);
} else if (lcp->want_callback.opmask & CALLBACK_BIT(CALLBACK_E164)) {
int sz = strlen(lcp->want_callback.msg);
@@ -462,16 +460,16 @@ LcpSendConfigReq(struct fsm *fp)
}
*o->data = CALLBACK_E164;
memcpy(o->data + 1, lcp->want_callback.msg, sz);
- INC_LCP_OPT(TY_CALLBACK, sz + 3, o);
+ INC_FSM_OPT(TY_CALLBACK, sz + 3, o);
}
}
if (lcp->want_mrru && !REJECTED(lcp, TY_MRRU)) {
ua_htons(&lcp->want_mrru, o->data);
- INC_LCP_OPT(TY_MRRU, 4, o);
+ INC_FSM_OPT(TY_MRRU, 4, o);
if (lcp->want_shortseq && !REJECTED(lcp, TY_SHORTSEQ))
- INC_LCP_OPT(TY_SHORTSEQ, 2, o);
+ INC_FSM_OPT(TY_SHORTSEQ, 2, o);
}
mp = &lcp->fsm.bundle->ncp.mp;
@@ -479,7 +477,7 @@ LcpSendConfigReq(struct fsm *fp)
!REJECTED(lcp, TY_ENDDISC)) {
*o->data = mp->cfg.enddisc.class;
memcpy(o->data+1, mp->cfg.enddisc.address, mp->cfg.enddisc.len);
- INC_LCP_OPT(TY_ENDDISC, mp->cfg.enddisc.len + 3, o);
+ INC_FSM_OPT(TY_ENDDISC, mp->cfg.enddisc.len + 3, o);
}
fsm_Output(fp, CODE_CONFIGREQ, fp->reqid, buff, (u_char *)o - buff,
@@ -514,9 +512,9 @@ lcp_SendIdentification(struct lcp *lcp)
strncpy(msg + 4, exp[0], sizeof msg - 5);
msg[sizeof msg - 1] = '\0';
- log_Printf(LogLCP, "Sending ident magic %08x text %s\n", lcp->want_magic,
- msg + 4);
fsm_Output(&lcp->fsm, CODE_IDENT, id++, msg, 4 + strlen(msg + 4), MB_LCPOUT);
+ log_Printf(LogLCP, " MAGICNUM %08x\n", lcp->want_magic);
+ log_Printf(LogLCP, " TEXT %s\n", msg + 4);
command_Free(1, exp);
return 1;
@@ -525,7 +523,8 @@ lcp_SendIdentification(struct lcp *lcp)
void
lcp_RecvIdentification(struct lcp *lcp, char *data)
{
- log_Printf(LogLCP, "Received ident: %s\n", data);
+ log_Printf(LogLCP, " MAGICNUM %08x\n", lcp->his_magic);
+ log_Printf(LogLCP, " TEXT %s\n", data);
}
static void
@@ -614,37 +613,72 @@ E164ok(struct callback *cb, char *req, int sz)
return 0;
}
+static int
+lcp_auth_nak(struct lcp *lcp, struct fsm_decode *dec)
+{
+ struct fsm_opt nak;
+
+ nak.hdr.id = TY_AUTHPROTO;
+
+ if (IsAccepted(lcp->cfg.pap)) {
+ nak.hdr.len = 4;
+ nak.data[0] = (unsigned char)(PROTO_PAP >> 8);
+ nak.data[1] = (unsigned char)PROTO_PAP;
+ fsm_nak(dec, &nak);
+ return 1;
+ }
+
+ nak.hdr.len = 5;
+ nak.data[0] = (unsigned char)(PROTO_CHAP >> 8);
+ nak.data[1] = (unsigned char)PROTO_CHAP;
+
+ if (IsAccepted(lcp->cfg.chap05)) {
+ nak.data[2] = 0x05;
+ fsm_nak(dec, &nak);
+#ifndef NODES
+ } else if (IsAccepted(lcp->cfg.chap80nt) ||
+ IsAccepted(lcp->cfg.chap80lm)) {
+ nak.data[2] = 0x80;
+ fsm_nak(dec, &nak);
+ } else if (IsAccepted(lcp->cfg.chap81)) {
+ nak.data[2] = 0x81;
+ fsm_nak(dec, &nak);
+#endif
+ } else {
+ return 0;
+ }
+
+ return 1;
+}
+
static void
-LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
+LcpDecodeConfig(struct fsm *fp, u_char *cp, u_char *end, int mode_type,
struct fsm_decode *dec)
{
/* Deal with incoming PROTO_LCP */
struct lcp *lcp = fsm2lcp(fp);
- int type, length, sz, pos, op, callback_req;
+ int sz, pos, op, callback_req, chap_type;
u_int32_t magic, accmap;
u_short mru, phmtu, maxmtu, maxmru, wantmtu, wantmru, proto;
struct lqrreq *req;
char request[20], desc[22];
struct mp *mp;
struct physical *p = link2physical(fp->link);
+ struct fsm_opt *opt, nak;
sz = op = callback_req = 0;
- while (plen >= sizeof(struct fsmconfig)) {
- type = *cp;
- length = cp[1];
-
- snprintf(request, sizeof request, " %s[%d]", protoname(type), length);
-
- if (length < 2) {
- log_Printf(LogLCP, "%s:%s: Bad LCP length\n", fp->link->name, request);
+ while (end - cp >= sizeof(opt->hdr)) {
+ if ((opt = fsm_readopt(&cp)) == NULL)
break;
- }
- switch (type) {
+ snprintf(request, sizeof request, " %s[%d]", protoname(opt->hdr.id),
+ opt->hdr.len);
+
+ switch (opt->hdr.id) {
case TY_MRRU:
mp = &lcp->fsm.bundle->ncp.mp;
- ua_ntohs(cp + 2, &mru);
+ ua_ntohs(opt->data, &mru);
log_Printf(LogLCP, "%s %u\n", request, mru);
switch (mode_type) {
@@ -652,34 +686,37 @@ LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
if (mp->cfg.mrru) {
if (REJECTED(lcp, TY_MRRU))
/* Ignore his previous reject so that we REQ next time */
- lcp->his_reject &= ~(1 << type);
+ lcp->his_reject &= ~(1 << opt->hdr.id);
if (mru > MAX_MRU) {
/* Push him down to MAX_MRU */
lcp->his_mrru = MAX_MRU;
- memcpy(dec->nakend, cp, 2);
- ua_htons(&lcp->his_mrru, dec->nakend + 2);
- dec->nakend += 4;
+ nak.hdr.id = TY_MRRU;
+ nak.hdr.len = 4;
+ ua_htons(&lcp->his_mrru, nak.data);
+ fsm_nak(dec, &nak);
} else if (mru < MIN_MRU) {
/* Push him up to MIN_MRU */
lcp->his_mrru = MIN_MRU;
- memcpy(dec->nakend, cp, 2);
- ua_htons(&lcp->his_mrru, dec->nakend + 2);
- dec->nakend += 4;
- } else {
+ nak.hdr.id = TY_MRRU;
+ nak.hdr.len = 4;
+ ua_htons(&lcp->his_mrru, nak.data);
+ fsm_nak(dec, &nak);
+ } else {
lcp->his_mrru = mru;
- memcpy(dec->ackend, cp, 4);
- dec->ackend += 4;
- }
- break;
- } else
- goto reqreject;
+ fsm_ack(dec, opt);
+ }
+ break;
+ } else {
+ fsm_rej(dec, opt);
+ lcp->my_reject |= (1 << opt->hdr.id);
+ }
break;
case MODE_NAK:
if (mp->cfg.mrru) {
if (REJECTED(lcp, TY_MRRU))
/* Must have changed his mind ! */
- lcp->his_reject &= ~(1 << type);
+ lcp->his_reject &= ~(1 << opt->hdr.id);
if (mru > MAX_MRU)
lcp->want_mrru = MAX_MRU;
@@ -691,15 +728,15 @@ LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
/* else we honour our config and don't send the suggested REQ */
break;
case MODE_REJ:
- lcp->his_reject |= (1 << type);
+ lcp->his_reject |= (1 << opt->hdr.id);
lcp->want_mrru = 0; /* Ah well, no multilink :-( */
- break;
+ break;
}
break;
case TY_MRU:
lcp->mru_req = 1;
- ua_ntohs(cp + 2, &mru);
+ ua_ntohs(opt->data, &mru);
log_Printf(LogLCP, "%s %d\n", request, mru);
switch (mode_type) {
@@ -716,21 +753,22 @@ LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
if (maxmtu && mru > maxmtu) {
lcp->his_mru = maxmtu;
- memcpy(dec->nakend, cp, 2);
- ua_htons(&lcp->his_mru, dec->nakend + 2);
- dec->nakend += 4;
+ nak.hdr.id = TY_MRU;
+ nak.hdr.len = 4;
+ ua_htons(&lcp->his_mru, nak.data);
+ fsm_nak(dec, &nak);
} else if (wantmtu && mru < wantmtu) {
/* Push him up to MTU or MIN_MRU */
lcp->his_mru = wantmtu;
- memcpy(dec->nakend, cp, 2);
- ua_htons(&lcp->his_mru, dec->nakend + 2);
- dec->nakend += 4;
+ nak.hdr.id = TY_MRU;
+ nak.hdr.len = 4;
+ ua_htons(&lcp->his_mru, nak.data);
+ fsm_nak(dec, &nak);
} else {
lcp->his_mru = mru;
- memcpy(dec->ackend, cp, 4);
- dec->ackend += 4;
+ fsm_ack(dec, opt);
}
- break;
+ break;
case MODE_NAK:
maxmru = p ? physical_DeviceMTU(p) : 0;
if (lcp->cfg.max_mru && (!maxmru || maxmru > lcp->cfg.max_mru))
@@ -745,260 +783,212 @@ LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
lcp->want_mru = MIN_MRU;
else
lcp->want_mru = mru;
- break;
+ break;
case MODE_REJ:
- lcp->his_reject |= (1 << type);
- break;
+ lcp->his_reject |= (1 << opt->hdr.id);
+ break;
}
break;
case TY_ACCMAP:
- ua_ntohl(cp + 2, &accmap);
+ ua_ntohl(opt->data, &accmap);
log_Printf(LogLCP, "%s 0x%08lx\n", request, (u_long)accmap);
switch (mode_type) {
case MODE_REQ:
- lcp->his_accmap = accmap;
- memcpy(dec->ackend, cp, 6);
- dec->ackend += 6;
- break;
+ lcp->his_accmap = accmap;
+ fsm_ack(dec, opt);
+ break;
case MODE_NAK:
- lcp->want_accmap = accmap;
- break;
+ lcp->want_accmap = accmap;
+ break;
case MODE_REJ:
- lcp->his_reject |= (1 << type);
- break;
+ lcp->his_reject |= (1 << opt->hdr.id);
+ break;
}
break;
case TY_AUTHPROTO:
- ua_ntohs(cp + 2, &proto);
+ ua_ntohs(opt->data, &proto);
+ chap_type = opt->hdr.len == 5 ? opt->data[2] : 0;
+
log_Printf(LogLCP, "%s 0x%04x (%s)\n", request, proto,
- Auth2Nam(proto, length > 4 ? cp[4] : 0));
+ Auth2Nam(proto, chap_type));
switch (mode_type) {
case MODE_REQ:
- switch (proto) {
- case PROTO_PAP:
- if (length != 4) {
- log_Printf(LogLCP, " Bad length!\n");
- goto reqreject;
- }
- if (IsAccepted(lcp->cfg.pap)) {
- lcp->his_auth = proto;
- lcp->his_authtype = 0;
- memcpy(dec->ackend, cp, length);
- dec->ackend += length;
- } else if (IsAccepted(lcp->cfg.chap05)) {
- *dec->nakend++ = *cp;
- *dec->nakend++ = 5;
- *dec->nakend++ = (unsigned char) (PROTO_CHAP >> 8);
- *dec->nakend++ = (unsigned char) PROTO_CHAP;
- *dec->nakend++ = 0x05;
-#ifndef NODES
- } else if (IsAccepted(lcp->cfg.chap80nt) ||
- IsAccepted(lcp->cfg.chap80lm)) {
- *dec->nakend++ = *cp;
- *dec->nakend++ = 5;
- *dec->nakend++ = (unsigned char) (PROTO_CHAP >> 8);
- *dec->nakend++ = (unsigned char) PROTO_CHAP;
- *dec->nakend++ = 0x80;
- } else if (IsAccepted(lcp->cfg.chap81)) {
- *dec->nakend++ = *cp;
- *dec->nakend++ = 5;
- *dec->nakend++ = (unsigned char) (PROTO_CHAP >> 8);
- *dec->nakend++ = (unsigned char) PROTO_CHAP;
- *dec->nakend++ = 0x81;
-#endif
- } else
- goto reqreject;
- break;
-
- case PROTO_CHAP:
- if (length != 5) {
- log_Printf(LogLCP, " Bad length!\n");
- goto reqreject;
- }
- if ((cp[4] == 0x05 && IsAccepted(lcp->cfg.chap05))
+ switch (proto) {
+ case PROTO_PAP:
+ if (opt->hdr.len == 4 && IsAccepted(lcp->cfg.pap)) {
+ lcp->his_auth = proto;
+ lcp->his_authtype = 0;
+ fsm_ack(dec, opt);
+ } else if (!lcp_auth_nak(lcp, dec)) {
+ lcp->my_reject |= (1 << opt->hdr.id);
+ fsm_rej(dec, opt);
+ }
+ break;
+
+ case PROTO_CHAP:
+ if ((chap_type == 0x05 && IsAccepted(lcp->cfg.chap05))
#ifndef NODES
- || (cp[4] == 0x80 && (IsAccepted(lcp->cfg.chap80nt) ||
+ || (chap_type == 0x80 && (IsAccepted(lcp->cfg.chap80nt) ||
(IsAccepted(lcp->cfg.chap80lm))))
- || (cp[4] == 0x81 && IsAccepted(lcp->cfg.chap81))
+ || (chap_type == 0x81 && IsAccepted(lcp->cfg.chap81))
#endif
) {
- lcp->his_auth = proto;
- lcp->his_authtype = cp[4];
- memcpy(dec->ackend, cp, length);
- dec->ackend += length;
- } else {
-#ifndef HAVE_DES
- if (cp[4] == 0x80) {
+ lcp->his_auth = proto;
+ lcp->his_authtype = chap_type;
+ fsm_ack(dec, opt);
+ } else {
+#ifdef NODES
+ if (chap_type == 0x80) {
log_Printf(LogWARN, "CHAP 0x80 not available without DES\n");
- } else if (cp[4] == 0x81) {
+ } else if (chap_type == 0x81) {
log_Printf(LogWARN, "CHAP 0x81 not available without DES\n");
} else
#endif
- if (cp[4] != 0x05)
+ if (chap_type != 0x05)
log_Printf(LogWARN, "%s not supported\n",
- Auth2Nam(PROTO_CHAP, cp[4]));
-
- if (IsAccepted(lcp->cfg.chap05)) {
- *dec->nakend++ = *cp;
- *dec->nakend++ = 5;
- *dec->nakend++ = (unsigned char) (PROTO_CHAP >> 8);
- *dec->nakend++ = (unsigned char) PROTO_CHAP;
- *dec->nakend++ = 0x05;
-#ifndef NODES
- } else if (IsAccepted(lcp->cfg.chap80nt) ||
- IsAccepted(lcp->cfg.chap80lm)) {
- *dec->nakend++ = *cp;
- *dec->nakend++ = 5;
- *dec->nakend++ = (unsigned char) (PROTO_CHAP >> 8);
- *dec->nakend++ = (unsigned char) PROTO_CHAP;
- *dec->nakend++ = 0x80;
- } else if (IsAccepted(lcp->cfg.chap81)) {
- *dec->nakend++ = *cp;
- *dec->nakend++ = 5;
- *dec->nakend++ = (unsigned char) (PROTO_CHAP >> 8);
- *dec->nakend++ = (unsigned char) PROTO_CHAP;
- *dec->nakend++ = 0x81;
-#endif
- } else if (IsAccepted(lcp->cfg.pap)) {
- *dec->nakend++ = *cp;
- *dec->nakend++ = 4;
- *dec->nakend++ = (unsigned char) (PROTO_PAP >> 8);
- *dec->nakend++ = (unsigned char) PROTO_PAP;
- } else
- goto reqreject;
+ Auth2Nam(PROTO_CHAP, chap_type));
+
+ if (!lcp_auth_nak(lcp, dec)) {
+ lcp->my_reject |= (1 << opt->hdr.id);
+ fsm_rej(dec, opt);
+ }
}
- break;
+ break;
- default:
- log_Printf(LogLCP, "%s 0x%04x - not recognised, NAK\n",
+ default:
+ log_Printf(LogLCP, "%s 0x%04x - not recognised\n",
request, proto);
- memcpy(dec->nakend, cp, length);
- dec->nakend += length;
- break;
- }
- break;
+ if (!lcp_auth_nak(lcp, dec)) {
+ lcp->my_reject |= (1 << opt->hdr.id);
+ fsm_rej(dec, opt);
+ }
+ break;
+ }
+ break;
+
case MODE_NAK:
- switch (proto) {
- case PROTO_PAP:
+ switch (proto) {
+ case PROTO_PAP:
if (IsEnabled(lcp->cfg.pap)) {
lcp->want_auth = PROTO_PAP;
lcp->want_authtype = 0;
} else {
log_Printf(LogLCP, "Peer will only send PAP (not enabled)\n");
- lcp->his_reject |= (1 << type);
+ lcp->his_reject |= (1 << opt->hdr.id);
}
break;
- case PROTO_CHAP:
- if (cp[4] == 0x05 && IsEnabled(lcp->cfg.chap05)) {
+ case PROTO_CHAP:
+ if (chap_type == 0x05 && IsEnabled(lcp->cfg.chap05)) {
lcp->want_auth = PROTO_CHAP;
lcp->want_authtype = 0x05;
#ifndef NODES
- } else if (cp[4] == 0x80 && (IsEnabled(lcp->cfg.chap80nt) ||
- IsEnabled(lcp->cfg.chap80lm))) {
+ } else if (chap_type == 0x80 && (IsEnabled(lcp->cfg.chap80nt) ||
+ IsEnabled(lcp->cfg.chap80lm))) {
lcp->want_auth = PROTO_CHAP;
lcp->want_authtype = 0x80;
- } else if (cp[4] == 0x81 && IsEnabled(lcp->cfg.chap81)) {
+ } else if (chap_type == 0x81 && IsEnabled(lcp->cfg.chap81)) {
lcp->want_auth = PROTO_CHAP;
lcp->want_authtype = 0x81;
#endif
} else {
-#ifndef HAVE_DES
- if (cp[4] == 0x80) {
+#ifdef NODES
+ if (chap_type == 0x80) {
log_Printf(LogLCP, "Peer will only send MSCHAP (not available"
" without DES)\n");
- } else if (cp[4] == 0x81) {
+ } else if (chap_type == 0x81) {
log_Printf(LogLCP, "Peer will only send MSCHAPV2 (not available"
" without DES)\n");
} else
#endif
log_Printf(LogLCP, "Peer will only send %s (not %s)\n",
- Auth2Nam(PROTO_CHAP, cp[4]),
+ Auth2Nam(PROTO_CHAP, chap_type),
#ifndef NODES
- (cp[4] == 0x80 || cp[4] == 0x81) ? "configured" :
+ (chap_type == 0x80 || chap_type == 0x81) ? "configured" :
#endif
"supported");
- lcp->his_reject |= (1 << type);
+ lcp->his_reject |= (1 << opt->hdr.id);
}
break;
default:
/* We've been NAK'd with something we don't understand :-( */
- lcp->his_reject |= (1 << type);
+ lcp->his_reject |= (1 << opt->hdr.id);
break;
}
- break;
+ break;
+
case MODE_REJ:
- lcp->his_reject |= (1 << type);
- break;
+ lcp->his_reject |= (1 << opt->hdr.id);
+ break;
}
break;
case TY_QUALPROTO:
- req = (struct lqrreq *)cp;
+ req = (struct lqrreq *)opt;
log_Printf(LogLCP, "%s proto %x, interval %lums\n",
request, ntohs(req->proto), (u_long)ntohl(req->period) * 10);
switch (mode_type) {
case MODE_REQ:
- if (ntohs(req->proto) != PROTO_LQR || !IsAccepted(lcp->cfg.lqr))
- goto reqreject;
- else {
- lcp->his_lqrperiod = ntohl(req->period);
- if (lcp->his_lqrperiod < MIN_LQRPERIOD * 100)
- lcp->his_lqrperiod = MIN_LQRPERIOD * 100;
- req->period = htonl(lcp->his_lqrperiod);
- memcpy(dec->ackend, cp, length);
- dec->ackend += length;
- }
- break;
+ if (ntohs(req->proto) != PROTO_LQR || !IsAccepted(lcp->cfg.lqr)) {
+ fsm_rej(dec, opt);
+ lcp->my_reject |= (1 << opt->hdr.id);
+ } else {
+ lcp->his_lqrperiod = ntohl(req->period);
+ if (lcp->his_lqrperiod < MIN_LQRPERIOD * 100)
+ lcp->his_lqrperiod = MIN_LQRPERIOD * 100;
+ req->period = htonl(lcp->his_lqrperiod);
+ fsm_ack(dec, opt);
+ }
+ break;
case MODE_NAK:
- break;
+ lcp->want_lqrperiod = ntohl(req->period);
+ break;
case MODE_REJ:
- lcp->his_reject |= (1 << type);
- break;
+ lcp->his_reject |= (1 << opt->hdr.id);
+ break;
}
break;
case TY_MAGICNUM:
- ua_ntohl(cp + 2, &magic);
+ ua_ntohl(opt->data, &magic);
log_Printf(LogLCP, "%s 0x%08lx\n", request, (u_long)magic);
switch (mode_type) {
case MODE_REQ:
- if (lcp->want_magic) {
- /* Validate magic number */
- if (magic == lcp->want_magic) {
- sigset_t emptyset;
+ if (lcp->want_magic) {
+ /* Validate magic number */
+ if (magic == lcp->want_magic) {
+ sigset_t emptyset;
- log_Printf(LogLCP, "Magic is same (%08lx) - %d times\n",
+ log_Printf(LogLCP, "Magic is same (%08lx) - %d times\n",
(u_long)magic, ++lcp->LcpFailedMagic);
- lcp->want_magic = GenerateMagic();
- memcpy(dec->nakend, cp, 6);
- dec->nakend += 6;
+ lcp->want_magic = GenerateMagic();
+ fsm_nak(dec, opt);
ualarm(TICKUNIT * (4 + 4 * lcp->LcpFailedMagic), 0);
- sigemptyset(&emptyset);
- sigsuspend(&emptyset);
- } else {
- lcp->his_magic = magic;
- memcpy(dec->ackend, cp, length);
- dec->ackend += length;
+ sigemptyset(&emptyset);
+ sigsuspend(&emptyset);
+ } else {
+ lcp->his_magic = magic;
lcp->LcpFailedMagic = 0;
- }
- } else {
- goto reqreject;
- }
- break;
+ fsm_ack(dec, opt);
+ }
+ } else {
+ lcp->my_reject |= (1 << opt->hdr.id);
+ fsm_rej(dec, opt);
+ }
+ break;
case MODE_NAK:
- log_Printf(LogLCP, " Magic 0x%08lx is NAKed!\n", (u_long)magic);
- lcp->want_magic = GenerateMagic();
- break;
+ log_Printf(LogLCP, " Magic 0x%08lx is NAKed!\n", (u_long)magic);
+ lcp->want_magic = GenerateMagic();
+ break;
case MODE_REJ:
- log_Printf(LogLCP, " Magic 0x%08x is REJected!\n", magic);
- lcp->want_magic = 0;
- lcp->his_reject |= (1 << type);
- break;
+ log_Printf(LogLCP, " Magic 0x%08x is REJected!\n", magic);
+ lcp->want_magic = 0;
+ lcp->his_reject |= (1 << opt->hdr.id);
+ break;
}
break;
@@ -1007,25 +997,24 @@ LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
switch (mode_type) {
case MODE_REQ:
- if (IsAccepted(lcp->cfg.protocomp)) {
- lcp->his_protocomp = 1;
- memcpy(dec->ackend, cp, 2);
- dec->ackend += 2;
- } else {
+ if (IsAccepted(lcp->cfg.protocomp)) {
+ lcp->his_protocomp = 1;
+ fsm_ack(dec, opt);
+ } else {
#ifdef OLDMST
- /* MorningStar before v1.3 needs NAK */
- memcpy(dec->nakend, cp, 2);
- dec->nakend += 2;
+ /* MorningStar before v1.3 needs NAK */
+ fsm_nak(dec, opt);
#else
- goto reqreject;
+ fsm_rej(dec, opt);
+ lcp->my_reject |= (1 << opt->hdr.id);
#endif
- }
- break;
+ }
+ break;
case MODE_NAK:
case MODE_REJ:
- lcp->want_protocomp = 0;
- lcp->his_reject |= (1 << type);
- break;
+ lcp->want_protocomp = 0;
+ lcp->his_reject |= (1 << opt->hdr.id);
+ break;
}
break;
@@ -1033,25 +1022,24 @@ LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
log_Printf(LogLCP, "%s\n", request);
switch (mode_type) {
case MODE_REQ:
- if (IsAccepted(lcp->cfg.acfcomp)) {
- lcp->his_acfcomp = 1;
- memcpy(dec->ackend, cp, 2);
- dec->ackend += 2;
- } else {
+ if (IsAccepted(lcp->cfg.acfcomp)) {
+ lcp->his_acfcomp = 1;
+ fsm_ack(dec, opt);
+ } else {
#ifdef OLDMST
- /* MorningStar before v1.3 needs NAK */
- memcpy(dec->nakend, cp, 2);
- dec->nakend += 2;
+ /* MorningStar before v1.3 needs NAK */
+ fsm_nak(dec, opt);
#else
- goto reqreject;
+ fsm_rej(dec, opt);
+ lcp->my_reject |= (1 << opt->hdr.id);
#endif
- }
- break;
+ }
+ break;
case MODE_NAK:
case MODE_REJ:
- lcp->want_acfcomp = 0;
- lcp->his_reject |= (1 << type);
- break;
+ lcp->want_acfcomp = 0;
+ lcp->his_reject |= (1 << opt->hdr.id);
+ break;
}
break;
@@ -1061,31 +1049,32 @@ LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
case MODE_REQ:
case MODE_NAK:
case MODE_REJ:
- break;
+ break;
}
break;
case TY_CALLBACK:
- if (length == 2)
+ if (opt->hdr.len == 2)
op = CALLBACK_NONE;
else
- op = (int)cp[2];
- sz = length - 3;
+ op = (int)opt->data[0];
+ sz = opt->hdr.len - 3;
switch (op) {
case CALLBACK_AUTH:
log_Printf(LogLCP, "%s Auth\n", request);
break;
case CALLBACK_DIALSTRING:
- log_Printf(LogLCP, "%s Dialstring %.*s\n", request, sz, cp + 3);
+ log_Printf(LogLCP, "%s Dialstring %.*s\n", request, sz,
+ opt->data + 1);
break;
case CALLBACK_LOCATION:
- log_Printf(LogLCP, "%s Location %.*s\n", request, sz, cp + 3);
+ log_Printf(LogLCP, "%s Location %.*s\n", request, sz, opt->data + 1);
break;
case CALLBACK_E164:
- log_Printf(LogLCP, "%s E.164 (%.*s)\n", request, sz, cp + 3);
+ log_Printf(LogLCP, "%s E.164 (%.*s)\n", request, sz, opt->data + 1);
break;
case CALLBACK_NAME:
- log_Printf(LogLCP, "%s Name %.*s\n", request, sz, cp + 3);
+ log_Printf(LogLCP, "%s Name %.*s\n", request, sz, opt->data + 1);
break;
case CALLBACK_CBCP:
log_Printf(LogLCP, "%s CBCP\n", request);
@@ -1098,41 +1087,43 @@ LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
switch (mode_type) {
case MODE_REQ:
callback_req = 1;
- if (p->type != PHYS_DIRECT)
- goto reqreject;
+ if (p->type != PHYS_DIRECT) {
+ fsm_rej(dec, opt);
+ lcp->my_reject |= (1 << opt->hdr.id);
+ }
+ nak.hdr.id = opt->hdr.id;
+ nak.hdr.len = 3;
if ((p->dl->cfg.callback.opmask & CALLBACK_BIT(op)) &&
(op != CALLBACK_AUTH || p->link.lcp.want_auth) &&
(op != CALLBACK_E164 ||
- E164ok(&p->dl->cfg.callback, cp + 3, sz))) {
- lcp->his_callback.opmask = CALLBACK_BIT(op);
+ E164ok(&p->dl->cfg.callback, opt->data + 1, sz))) {
+ lcp->his_callback.opmask = CALLBACK_BIT(op);
if (sz > sizeof lcp->his_callback.msg - 1) {
sz = sizeof lcp->his_callback.msg - 1;
log_Printf(LogWARN, "Truncating option arg to %d octets\n", sz);
}
- memcpy(lcp->his_callback.msg, cp + 3, sz);
- lcp->his_callback.msg[sz] = '\0';
- memcpy(dec->ackend, cp, sz + 3);
- dec->ackend += sz + 3;
+ memcpy(lcp->his_callback.msg, opt->data + 1, sz);
+ lcp->his_callback.msg[sz] = '\0';
+ fsm_ack(dec, opt);
} else if ((p->dl->cfg.callback.opmask & CALLBACK_BIT(CALLBACK_AUTH)) &&
p->link.lcp.auth_ineed) {
- *dec->nakend++ = *cp;
- *dec->nakend++ = 3;
- *dec->nakend++ = CALLBACK_AUTH;
+ nak.data[0] = CALLBACK_AUTH;
+ fsm_nak(dec, &nak);
} else if (p->dl->cfg.callback.opmask & CALLBACK_BIT(CALLBACK_CBCP)) {
- *dec->nakend++ = *cp;
- *dec->nakend++ = 3;
- *dec->nakend++ = CALLBACK_CBCP;
+ nak.data[0] = CALLBACK_CBCP;
+ fsm_nak(dec, &nak);
} else if (p->dl->cfg.callback.opmask & CALLBACK_BIT(CALLBACK_E164)) {
- *dec->nakend++ = *cp;
- *dec->nakend++ = 3;
- *dec->nakend++ = CALLBACK_E164;
+ nak.data[0] = CALLBACK_E164;
+ fsm_nak(dec, &nak);
} else if (p->dl->cfg.callback.opmask & CALLBACK_BIT(CALLBACK_AUTH)) {
log_Printf(LogWARN, "Cannot insist on auth callback without"
" PAP or CHAP enabled !\n");
- *dec->nakend++ = *cp;
- *dec->nakend++ = 2;
- } else
- goto reqreject;
+ nak.data[0] = 2;
+ fsm_nak(dec, &nak);
+ } else {
+ lcp->my_reject |= (1 << opt->hdr.id);
+ fsm_rej(dec, opt);
+ }
break;
case MODE_NAK:
/* We don't do what he NAKs with, we do things in our preferred order */
@@ -1152,13 +1143,13 @@ LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
break;
case MODE_REJ:
if (lcp->want_callback.opmask & CALLBACK_BIT(CALLBACK_NONE)) {
- lcp->his_reject |= (1 << type);
+ lcp->his_reject |= (1 << opt->hdr.id);
lcp->want_callback.opmask = 0;
} else {
log_Printf(LogPHASE, "Peer rejected *required* callback\n");
fsm_Close(&lcp->fsm);
}
- break;
+ break;
}
break;
@@ -1170,10 +1161,11 @@ LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
case MODE_REQ:
if (lcp->want_mrru && IsAccepted(mp->cfg.shortseq)) {
lcp->his_shortseq = 1;
- memcpy(dec->ackend, cp, length);
- dec->ackend += length;
- } else
- goto reqreject;
+ fsm_ack(dec, opt);
+ } else {
+ fsm_rej(dec, opt);
+ lcp->my_reject |= (1 << opt->hdr.id);
+ }
break;
case MODE_NAK:
/*
@@ -1182,78 +1174,69 @@ LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
*/
break;
case MODE_REJ:
- lcp->his_reject |= (1 << type);
+ lcp->his_reject |= (1 << opt->hdr.id);
lcp->want_shortseq = 0; /* For when we hit MP */
- break;
+ break;
}
break;
case TY_ENDDISC:
mp = &lcp->fsm.bundle->ncp.mp;
log_Printf(LogLCP, "%s %s\n", request,
- mp_Enddisc(cp[2], cp + 3, length - 3));
+ mp_Enddisc(opt->data[0], opt->data + 1, opt->hdr.len - 3));
switch (mode_type) {
case MODE_REQ:
if (!p) {
log_Printf(LogLCP, " ENDDISC rejected - not a physical link\n");
- goto reqreject;
- } else if (!IsAccepted(mp->cfg.negenddisc))
- goto reqreject;
- else if (length-3 < sizeof p->dl->peer.enddisc.address &&
- cp[2] <= MAX_ENDDISC_CLASS) {
- p->dl->peer.enddisc.class = cp[2];
- p->dl->peer.enddisc.len = length-3;
- memcpy(p->dl->peer.enddisc.address, cp + 3, length - 3);
- p->dl->peer.enddisc.address[length - 3] = '\0';
+ fsm_rej(dec, opt);
+ lcp->my_reject |= (1 << opt->hdr.id);
+ } else if (!IsAccepted(mp->cfg.negenddisc)) {
+ lcp->my_reject |= (1 << opt->hdr.id);
+ fsm_rej(dec, opt);
+ } else if (opt->hdr.len - 3 < sizeof p->dl->peer.enddisc.address &&
+ opt->data[0] <= MAX_ENDDISC_CLASS) {
+ p->dl->peer.enddisc.class = opt->data[0];
+ p->dl->peer.enddisc.len = opt->hdr.len - 3;
+ memcpy(p->dl->peer.enddisc.address, opt->data + 1, opt->hdr.len - 3);
+ p->dl->peer.enddisc.address[opt->hdr.len - 3] = '\0';
/* XXX: If mp->active, compare and NAK with mp->peer ? */
- memcpy(dec->ackend, cp, length);
- dec->ackend += length;
+ fsm_ack(dec, opt);
} else {
- if (cp[2] > MAX_ENDDISC_CLASS)
+ if (opt->data[0] > MAX_ENDDISC_CLASS)
log_Printf(LogLCP, " ENDDISC rejected - unrecognised class %d\n",
- cp[2]);
+ opt->data[0]);
else
log_Printf(LogLCP, " ENDDISC rejected - local max length is %ld\n",
(long)(sizeof p->dl->peer.enddisc.address - 1));
- goto reqreject;
+ fsm_rej(dec, opt);
+ lcp->my_reject |= (1 << opt->hdr.id);
}
- break;
+ break;
case MODE_NAK: /* Treat this as a REJ, we don't vary our disc (yet) */
case MODE_REJ:
- lcp->his_reject |= (1 << type);
- break;
+ lcp->his_reject |= (1 << opt->hdr.id);
+ break;
}
break;
default:
sz = (sizeof desc - 2) / 2;
- if (sz > length - 2)
- sz = length - 2;
+ if (sz > opt->hdr.len - 2)
+ sz = opt->hdr.len - 2;
pos = 0;
desc[0] = sz ? ' ' : '\0';
for (pos = 0; sz--; pos++)
- sprintf(desc+(pos<<1)+1, "%02x", cp[pos+2]);
+ sprintf(desc+(pos<<1)+1, "%02x", opt->data[pos]);
log_Printf(LogLCP, "%s%s\n", request, desc);
if (mode_type == MODE_REQ) {
-reqreject:
- if (length > sizeof dec->rej - (dec->rejend - dec->rej)) {
- length = sizeof dec->rej - (dec->rejend - dec->rej);
- log_Printf(LogLCP, "Can't REJ length %d - trunating to %d\n",
- cp[1], length);
- }
- memcpy(dec->rejend, cp, length);
- dec->rejend += length;
- lcp->my_reject |= (1 << type);
- if (length != cp[1])
- length = 0; /* force our way out of the loop */
+ fsm_rej(dec, opt);
+ lcp->my_reject |= (1 << opt->hdr.id);
}
break;
}
- plen -= length;
- cp += length;
}
if (mode_type != MODE_NOP) {
@@ -1261,20 +1244,21 @@ reqreject:
p->dl->cfg.callback.opmask && !callback_req &&
!(p->dl->cfg.callback.opmask & CALLBACK_BIT(CALLBACK_NONE))) {
/* We *REQUIRE* that the peer requests callback */
- *dec->nakend++ = TY_CALLBACK;
- *dec->nakend++ = 3;
+ nak.hdr.id = TY_CALLBACK;
+ nak.hdr.len = 3;
if ((p->dl->cfg.callback.opmask & CALLBACK_BIT(CALLBACK_AUTH)) &&
p->link.lcp.want_auth)
- *dec->nakend++ = CALLBACK_AUTH;
+ nak.data[0] = CALLBACK_AUTH;
else if (p->dl->cfg.callback.opmask & CALLBACK_BIT(CALLBACK_CBCP))
- *dec->nakend++ = CALLBACK_CBCP;
+ nak.data[0] = CALLBACK_CBCP;
else if (p->dl->cfg.callback.opmask & CALLBACK_BIT(CALLBACK_E164))
- *dec->nakend++ = CALLBACK_E164;
+ nak.data[0] = CALLBACK_E164;
else {
log_Printf(LogWARN, "Cannot insist on auth callback without"
" PAP or CHAP enabled !\n");
- dec->nakend[-1] = 2; /* XXX: Silly ! */
+ nak.hdr.len = 2; /* XXX: Silly ! */
}
+ fsm_nak(dec, &nak);
}
if (mode_type == MODE_REQ && !lcp->mru_req) {
mru = DEF_MRU;
@@ -1286,20 +1270,14 @@ reqreject:
if (mru < DEF_MRU) {
/* Don't let the peer use the default MRU */
lcp->his_mru = lcp->cfg.mtu && lcp->cfg.mtu < mru ? lcp->cfg.mtu : mru;
- *dec->nakend++ = TY_MRU;
- *dec->nakend++ = 4;
- ua_htons(&lcp->his_mru, dec->nakend);
- dec->nakend += 2;
+ nak.hdr.id = TY_MRU;
+ nak.hdr.len = 4;
+ ua_htons(&lcp->his_mru, nak.data);
+ fsm_nak(dec, &nak);
lcp->mru_req = 1; /* Don't keep NAK'ing this */
}
}
- if (dec->rejend != dec->rej) {
- /* rejects are preferred */
- dec->ackend = dec->ack;
- dec->nakend = dec->nak;
- } else if (dec->nakend != dec->nak)
- /* then NAKs */
- dec->ackend = dec->ack;
+ fsm_opt_normalise(dec);
}
}
diff --git a/usr.sbin/ppp/ppp/lcp.h b/usr.sbin/ppp/ppp/lcp.h
index 66ba19b1f43..19c8037ac42 100644
--- a/usr.sbin/ppp/ppp/lcp.h
+++ b/usr.sbin/ppp/ppp/lcp.h
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: lcp.h,v 1.12 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: lcp.h,v 1.13 2002/05/16 01:13:39 brian Exp $
*/
/* callback::opmask values */
@@ -123,20 +123,6 @@ struct lcp {
#define TY_SHORTSEQ 18 /* Want short seqs (12bit) please (see mp.h) */
#define TY_ENDDISC 19 /* Endpoint discriminator */
-#define MAX_LCP_OPT_LEN 20
-struct lcp_opt {
- u_char id;
- u_char len;
- u_char data[MAX_LCP_OPT_LEN-2];
-};
-
-#define INC_LCP_OPT(ty, length, o) \
- do { \
- (o)->id = (ty); \
- (o)->len = (length); \
- (o) = (struct lcp_opt *)((char *)(o) + (length)); \
- } while (0)
-
struct mbuf;
struct link;
struct bundle;
diff --git a/usr.sbin/ppp/ppp/lqr.c b/usr.sbin/ppp/ppp/lqr.c
index 949c7b574ec..52fac67b48a 100644
--- a/usr.sbin/ppp/ppp/lqr.c
+++ b/usr.sbin/ppp/ppp/lqr.c
@@ -25,10 +25,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: lqr.c,v 1.12 2001/06/13 21:33:41 brian Exp $
+ * $OpenBSD: lqr.c,v 1.13 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
+
+#ifdef __FreeBSD__
+#include <netinet/in.h>
+#endif
#include <sys/un.h>
#include <string.h>
diff --git a/usr.sbin/ppp/ppp/main.c b/usr.sbin/ppp/ppp/main.c
index 5ade23042ce..50fba63e364 100644
--- a/usr.sbin/ppp/ppp/main.c
+++ b/usr.sbin/ppp/ppp/main.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: main.c,v 1.31 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: main.c,v 1.32 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -43,7 +43,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/time.h>
#include <termios.h>
#include <unistd.h>
#include <sys/stat.h>
@@ -72,7 +71,6 @@
#include "throughput.h"
#include "slcompress.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
@@ -186,7 +184,7 @@ RestartServer(int signo)
static void
Usage(void)
{
- fprintf(stderr, "Usage: ppp [-auto | -foreground | -background | -direct |"
+ fprintf(stderr, "usage: ppp [-auto | -foreground | -background | -direct |"
" -dedicated | -ddial | -interactive]"
#ifndef NOALIAS
" [-nat]"
diff --git a/usr.sbin/ppp/ppp/mp.c b/usr.sbin/ppp/ppp/mp.c
index f2b01a89fd5..4b61ab6f70d 100644
--- a/usr.sbin/ppp/ppp/mp.c
+++ b/usr.sbin/ppp/ppp/mp.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: mp.c,v 1.29 2002/05/14 01:38:46 brian Exp $
+ * $OpenBSD: mp.c,v 1.30 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -62,7 +62,6 @@
#include "lqr.h"
#include "hdlc.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "auth.h"
#include "lcp.h"
diff --git a/usr.sbin/ppp/ppp/mppe.c b/usr.sbin/ppp/ppp/mppe.c
index 41c0de34751..90a37853cd5 100644
--- a/usr.sbin/ppp/ppp/mppe.c
+++ b/usr.sbin/ppp/ppp/mppe.c
@@ -23,20 +23,18 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: mppe.c,v 1.11 2002/03/13 10:34:46 brian Exp $
+ * $OpenBSD: mppe.c,v 1.12 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/types.h>
+#ifdef __FreeBSD__
+#include <netinet/in.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <termios.h>
-#ifdef __FreeBSD__
-#include <sha.h>
-#else
-#include <openssl/sha.h>
-#endif
#include <openssl/rc4.h>
#include "defs.h"
@@ -123,6 +121,7 @@ MPPEReduceSessionKey(struct mppe_state *mp)
case 56:
mp->sesskey[0] = 0xd1;
case 128:
+ break;
}
}
@@ -362,7 +361,7 @@ MPPEDictSetup(void *v, struct ccp *ccp, u_short proto, struct mbuf *mi)
}
static const char *
-MPPEDispOpts(struct lcp_opt *o)
+MPPEDispOpts(struct fsm_opt *o)
{
static char buf[70];
u_int32_t val;
@@ -458,11 +457,11 @@ MPPE_ConfigVal(const struct ccp_config *cfg)
* What options should we use for our first configure request
*/
static void
-MPPEInitOptsOutput(struct lcp_opt *o, const struct ccp_config *cfg)
+MPPEInitOptsOutput(struct fsm_opt *o, const struct ccp_config *cfg)
{
u_int32_t mval;
- o->len = 6;
+ o->hdr.len = 6;
if (!MPPE_MasterKeyValid) {
log_Printf(LogCCP, "MPPE: MasterKey is invalid,"
@@ -479,7 +478,7 @@ MPPEInitOptsOutput(struct lcp_opt *o, const struct ccp_config *cfg)
* Our CCP request was NAK'd with the given options
*/
static int
-MPPESetOptsOutput(struct lcp_opt *o, const struct ccp_config *cfg)
+MPPESetOptsOutput(struct fsm_opt *o, const struct ccp_config *cfg)
{
u_int32_t mval, peer;
@@ -517,7 +516,7 @@ MPPESetOptsOutput(struct lcp_opt *o, const struct ccp_config *cfg)
* The peer has requested the given options
*/
static int
-MPPESetOptsInput(struct lcp_opt *o, const struct ccp_config *cfg)
+MPPESetOptsInput(struct fsm_opt *o, const struct ccp_config *cfg)
{
u_int32_t mval, peer;
int res = MODE_ACK;
@@ -586,7 +585,7 @@ MPPESetOptsInput(struct lcp_opt *o, const struct ccp_config *cfg)
}
static struct mppe_state *
-MPPE_InitState(struct lcp_opt *o)
+MPPE_InitState(struct fsm_opt *o)
{
struct mppe_state *mp;
u_int32_t val;
@@ -620,7 +619,7 @@ MPPE_InitState(struct lcp_opt *o)
}
static void *
-MPPEInitInput(struct lcp_opt *o)
+MPPEInitInput(struct fsm_opt *o)
{
struct mppe_state *mip;
@@ -666,7 +665,7 @@ MPPEInitInput(struct lcp_opt *o)
}
static void *
-MPPEInitOutput(struct lcp_opt *o)
+MPPEInitOutput(struct fsm_opt *o)
{
struct mppe_state *mop;
diff --git a/usr.sbin/ppp/ppp/nat_cmd.c b/usr.sbin/ppp/ppp/nat_cmd.c
index edcc8e90ef1..c348b7f809d 100644
--- a/usr.sbin/ppp/ppp/nat_cmd.c
+++ b/usr.sbin/ppp/ppp/nat_cmd.c
@@ -24,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: nat_cmd.c,v 1.21 2001/11/23 11:17:03 brian Exp $
+ * $OpenBSD: nat_cmd.c,v 1.22 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -215,7 +215,7 @@ nat_RedirectAddr(struct cmdargs const *arg)
error = StrToAddr(arg->argv[arg->argn+1], &aliasaddr);
if (error) {
prompt_Printf(arg->prompt, "address redirect: invalid alias address\n");
- prompt_Printf(arg->prompt, "Usage: nat %s %s\n", arg->cmd->name,
+ prompt_Printf(arg->prompt, "usage: nat %s %s\n", arg->cmd->name,
arg->cmd->syntax);
return 1;
}
@@ -223,7 +223,7 @@ nat_RedirectAddr(struct cmdargs const *arg)
if (link == NULL) {
prompt_Printf(arg->prompt, "address redirect: packet aliasing"
" engine error\n");
- prompt_Printf(arg->prompt, "Usage: nat %s %s\n", arg->cmd->name,
+ prompt_Printf(arg->prompt, "usage: nat %s %s\n", arg->cmd->name,
arg->cmd->syntax);
}
} else
@@ -269,7 +269,7 @@ nat_RedirectProto(struct cmdargs const *arg)
error = StrToAddr(arg->argv[arg->argn + 2], &publicIP);
if (error) {
prompt_Printf(arg->prompt, "proto redirect: invalid alias address\n");
- prompt_Printf(arg->prompt, "Usage: nat %s %s\n", arg->cmd->name,
+ prompt_Printf(arg->prompt, "usage: nat %s %s\n", arg->cmd->name,
arg->cmd->syntax);
return 1;
}
@@ -280,7 +280,7 @@ nat_RedirectProto(struct cmdargs const *arg)
error = StrToAddr(arg->argv[arg->argn + 2], &remoteIP);
if (error) {
prompt_Printf(arg->prompt, "proto redirect: invalid dst address\n");
- prompt_Printf(arg->prompt, "Usage: nat %s %s\n", arg->cmd->name,
+ prompt_Printf(arg->prompt, "usage: nat %s %s\n", arg->cmd->name,
arg->cmd->syntax);
return 1;
}
@@ -291,7 +291,7 @@ nat_RedirectProto(struct cmdargs const *arg)
if (link == NULL) {
prompt_Printf(arg->prompt, "proto redirect: packet aliasing"
" engine error\n");
- prompt_Printf(arg->prompt, "Usage: nat %s %s\n", arg->cmd->name,
+ prompt_Printf(arg->prompt, "usage: nat %s %s\n", arg->cmd->name,
arg->cmd->syntax);
}
} else
diff --git a/usr.sbin/ppp/ppp/ncp.c b/usr.sbin/ppp/ppp/ncp.c
index a68c91f1e0f..347049ad556 100644
--- a/usr.sbin/ppp/ppp/ncp.c
+++ b/usr.sbin/ppp/ppp/ncp.c
@@ -23,38 +23,30 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
+ * $OpenBSD: ncp.c,v 1.2 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
-#include <arpa/inet.h>
#include <sys/socket.h>
-#include <net/if.h>
#include <net/route.h>
-#include <netdb.h>
#include <sys/un.h>
#include <errno.h>
-#include <fcntl.h>
#include <resolv.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/stat.h>
#include <termios.h>
-#include <unistd.h>
#include "layer.h"
-#include "ua.h"
#include "defs.h"
#include "command.h"
#include "mbuf.h"
#include "log.h"
#include "timer.h"
#include "fsm.h"
-#include "proto.h"
#include "iplist.h"
#include "throughput.h"
#include "slcompress.h"
@@ -62,11 +54,9 @@
#include "hdlc.h"
#include "lcp.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
-#include "vjcomp.h"
#include "async.h"
#include "ccp.h"
#include "link.h"
@@ -78,16 +68,12 @@
#include "ipv6cp.h"
#include "ncp.h"
#include "bundle.h"
-#include "id.h"
-#include "arp.h"
-#include "systems.h"
#include "prompt.h"
#include "route.h"
#include "iface.h"
#include "chat.h"
#include "auth.h"
#include "chap.h"
-#include "pap.h"
#include "cbcp.h"
#include "datalink.h"
diff --git a/usr.sbin/ppp/ppp/ncp.h b/usr.sbin/ppp/ppp/ncp.h
index c9c3be53c3b..4f3c2fbcc02 100644
--- a/usr.sbin/ppp/ppp/ncp.h
+++ b/usr.sbin/ppp/ppp/ncp.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
+ * $OpenBSD: ncp.h,v 1.2 2002/05/16 01:13:39 brian Exp $
*/
struct port_range {
diff --git a/usr.sbin/ppp/ppp/ncpaddr.c b/usr.sbin/ppp/ppp/ncpaddr.c
index 943db3dd937..eb94f662daf 100644
--- a/usr.sbin/ppp/ppp/ncpaddr.c
+++ b/usr.sbin/ppp/ppp/ncpaddr.c
@@ -23,20 +23,21 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
+ * $OpenBSD: ncpaddr.c,v 1.4 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/types.h>
#include <sys/socket.h>
+#ifdef __OpenBSD__
#include <net/if_types.h>
#include <net/route.h>
+#endif
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <sys/un.h>
-#include <limits.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/usr.sbin/ppp/ppp/ncpaddr.h b/usr.sbin/ppp/ppp/ncpaddr.h
index 8c6b8861232..7730986e834 100644
--- a/usr.sbin/ppp/ppp/ncpaddr.h
+++ b/usr.sbin/ppp/ppp/ncpaddr.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
+ * $OpenBSD: ncpaddr.h,v 1.3 2002/05/16 01:13:39 brian Exp $
*/
/*
diff --git a/usr.sbin/ppp/ppp/netgraph.c b/usr.sbin/ppp/ppp/netgraph.c
index e048054f365..13c69041ca4 100644
--- a/usr.sbin/ppp/ppp/netgraph.c
+++ b/usr.sbin/ppp/ppp/netgraph.c
@@ -312,6 +312,7 @@ static const struct device basengdevice = {
ng_Write,
ng_device2iov,
NULL,
+ NULL,
NULL
};
diff --git a/usr.sbin/ppp/ppp/pap.c b/usr.sbin/ppp/ppp/pap.c
index 488ae4b6f3b..09e4bf3c656 100644
--- a/usr.sbin/ppp/ppp/pap.c
+++ b/usr.sbin/ppp/ppp/pap.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: pap.c,v 1.17 2001/08/19 23:22:18 brian Exp $
+ * $OpenBSD: pap.c,v 1.18 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -60,7 +60,6 @@
#include "iplist.h"
#include "slcompress.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "mp.h"
@@ -143,10 +142,17 @@ SendPapCode(struct authinfo *authp, int code, const char *message)
static void
pap_Success(struct authinfo *authp)
{
+ struct bundle *bundle = authp->physical->dl->bundle;
+
datalink_GotAuthname(authp->physical->dl, authp->in.name);
- SendPapCode(authp, PAP_ACK, "Greetings!!");
+#ifndef NORADIUS
+ if (*bundle->radius.cfg.file && bundle->radius.repstr)
+ SendPapCode(authp, PAP_ACK, bundle->radius.repstr);
+ else
+#endif
+ SendPapCode(authp, PAP_ACK, "Greetings!!");
authp->physical->link.lcp.auth_ineed = 0;
- if (Enabled(authp->physical->dl->bundle, OPT_UTMP))
+ if (Enabled(bundle, OPT_UTMP))
physical_Login(authp->physical, authp->in.name);
if (authp->physical->link.lcp.auth_iwait == 0)
diff --git a/usr.sbin/ppp/ppp/physical.c b/usr.sbin/ppp/ppp/physical.c
index 641bf8ee81b..770220b4329 100644
--- a/usr.sbin/ppp/ppp/physical.c
+++ b/usr.sbin/ppp/ppp/physical.c
@@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $OpenBSD: physical.c,v 1.33 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: physical.c,v 1.34 2002/05/16 01:13:39 brian Exp $
*
*/
@@ -30,9 +30,6 @@
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
-#ifdef NOSUID
-#include <signal.h>
-#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -71,7 +68,6 @@
#include "iplist.h"
#include "slcompress.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
@@ -1114,3 +1110,12 @@ physical_SetAsyncParams(struct physical *p, u_int32_t mymap, u_int32_t hismap)
async_SetLinkParams(&p->async, mymap, hismap);
}
+
+int
+physical_Slot(struct physical *p)
+{
+ if (p->handler && p->handler->slot)
+ return (*p->handler->slot)(p);
+
+ return -1;
+}
diff --git a/usr.sbin/ppp/ppp/physical.h b/usr.sbin/ppp/ppp/physical.h
index 633e62ac583..75a30e8e624 100644
--- a/usr.sbin/ppp/ppp/physical.h
+++ b/usr.sbin/ppp/ppp/physical.h
@@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $OpenBSD: physical.h,v 1.19 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: physical.h,v 1.20 2002/05/16 01:13:39 brian Exp $
*
*/
@@ -73,6 +73,7 @@ struct device {
void (*device2iov)(struct device *, struct iovec *, int *, int, int *, int *);
int (*speed)(struct physical *);
const char *(*openinfo)(struct physical *);
+ int (*slot)(struct physical *);
};
struct physical {
@@ -169,3 +170,4 @@ extern int physical_MaxDeviceSize(void);
extern int physical_AwaitCarrier(struct physical *);
extern void physical_SetDescriptor(struct physical *);
extern void physical_SetAsyncParams(struct physical *, u_int32_t, u_int32_t);
+extern int physical_Slot(struct physical *);
diff --git a/usr.sbin/ppp/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp/ppp.8.m4
index fff5c168cb6..17dcaa01ec1 100644
--- a/usr.sbin/ppp/ppp/ppp.8.m4
+++ b/usr.sbin/ppp/ppp/ppp.8.m4
@@ -25,7 +25,7 @@ changecom(,)dnl
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $OpenBSD: ppp.8.m4,v 1.6 2002/03/31 02:38:49 brian Exp $
+.\" $OpenBSD: ppp.8.m4,v 1.7 2002/05/16 01:13:39 brian Exp $
.\"
.Dd September 20, 1995
.Dt PPP 8
@@ -3497,7 +3497,7 @@ which comes with the source distribution.
The given
.Ar command
is executed in the background with the following words replaced:
-.Bl -tag -width PEER_ENDDISC
+.Bl -tag -width COMPILATIONDATE
.It Li AUTHNAME
This is replaced with the local
.Ar authname
@@ -3523,6 +3523,30 @@ This is replaced with the peers IP number.
This is replaced with the peers IPv6 number.
.It Li INTERFACE
This is replaced with the name of the interface that's in use.
+.It Li IPOCTETSIN
+This is replaced with the number of IP bytes received since the connection
+was established.
+.It Li IPOCTETSOUT
+This is replaced with the number of IP bytes sent since the connection
+was established.
+.It Li IPPACKETSIN
+This is replaced with the number of IP packets received since the connection
+was established.
+.It Li IPPACKETSOUT
+This is replaced with the number of IP packets sent since the connection
+was established.
+.It Li IPV6OCTETSIN
+This is replaced with the number of IPv6 bytes received since the connection
+was established.
+.It Li IPV6OCTETSOUT
+This is replaced with the number of IPv6 bytes sent since the connection
+was established.
+.It Li IPV6PACKETSIN
+This is replaced with the number of IPv6 packets received since the connection
+was established.
+.It Li IPV6PACKETSOUT
+This is replaced with the number of IPv6 packets sent since the connection
+was established.
.It Li LABEL
This is replaced with the last label name used.
A label may be specified on the
@@ -3538,13 +3562,24 @@ file.
This is replaced with the IP number assigned to the local interface.
.It Li MYADDR6
This is replaced with the IPv6 number assigned to the local interface.
+.It Li OCTETSIN
+This is replaced with the number of bytes received since the connection
+was established.
+.It Li OCTETSOUT
+This is replaced with the number of bytes sent since the connection
+was established.
+.It Li PACKETSIN
+This is replaced with the number of packets received since the connection
+was established.
+.It Li PACKETSOUT
+This is replaced with the number of packets sent since the connection
+was established.
.It Li PEER_ENDDISC
This is replaced with the value of the peers endpoint discriminator.
.It Li PROCESSID
This is replaced with the current process id.
-.It Li VERSION
-This is replaced with the current version number of
-.Nm ppp .
+.It Li SOCKNAME
+This is replaced with the name of the diagnostic socket.
.It Li UPTIME
This is replaced with the bundle uptime in HH:MM:SS format.
.It Li USER
@@ -3552,6 +3587,9 @@ This is replaced with the username that has been authenticated with PAP or
CHAP.
Normally, this variable is assigned only in -direct mode.
This value is available irrespective of whether utmp logging is enabled.
+.It Li VERSION
+This is replaced with the current version number of
+.Nm .
.El
.Pp
These substitutions are also done by the
@@ -5240,6 +5278,8 @@ If the received compression type is
will request VJ compression during IPCP negotiations despite any
.Dq disable vj
configuration command.
+.It RAD_FILTER_ID
+This attribute is stored but not yet used.
.It RAD_FRAMED_ROUTE
The received string is expected to be in the format
.Ar dest Ns Op / Ns Ar bits
@@ -5286,6 +5326,17 @@ or
.Dv HISADDR
keywords.
.Pp
+.It RAD_SESSION_TIMEOUT
+If supplied, the client connection is closed after the given number of
+seconds.
+.It RAD_REPLY_MESSAGE
+If supplied, this message is passed back to the peer as the authentication
+SUCCESS text.
+.It RAD_MICROSOFT_MS_CHAP_ERROR
+If this
+.Dv RAD_VENDOR_MICROSOFT
+vendor specific attribute is supplied, it is passed back to the peer as the
+authentication FAILURE text.
.El
Values received from the RADIUS server may be viewed using
.Dq show bundle .
diff --git a/usr.sbin/ppp/ppp/pred.c b/usr.sbin/ppp/ppp/pred.c
index c3e52be8006..85f87d45fdb 100644
--- a/usr.sbin/ppp/ppp/pred.c
+++ b/usr.sbin/ppp/ppp/pred.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: pred.c,v 1.12 2001/07/03 22:23:56 brian Exp $
+ * $OpenBSD: pred.c,v 1.13 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/types.h>
@@ -151,7 +151,7 @@ Pred1ResetOutput(void *v)
}
static void *
-Pred1InitInput(struct lcp_opt *o)
+Pred1InitInput(struct fsm_opt *o)
{
struct pred1_state *state;
state = (struct pred1_state *)malloc(sizeof(struct pred1_state));
@@ -161,7 +161,7 @@ Pred1InitInput(struct lcp_opt *o)
}
static void *
-Pred1InitOutput(struct lcp_opt *o)
+Pred1InitOutput(struct fsm_opt *o)
{
struct pred1_state *state;
state = (struct pred1_state *)malloc(sizeof(struct pred1_state));
@@ -294,32 +294,22 @@ Pred1DictSetup(void *v, struct ccp *ccp, u_short proto, struct mbuf *bp)
}
static const char *
-Pred1DispOpts(struct lcp_opt *o)
+Pred1DispOpts(struct fsm_opt *o)
{
return NULL;
}
static void
-Pred1InitOptsOutput(struct lcp_opt *o, const struct ccp_config *cfg)
+Pred1InitOptsOutput(struct fsm_opt *o, const struct ccp_config *cfg)
{
- o->len = 2;
+ o->hdr.len = 2;
}
static int
-Pred1SetOptsOutput(struct lcp_opt *o, const struct ccp_config *cfg)
+Pred1SetOpts(struct fsm_opt *o, const struct ccp_config *cfg)
{
- if (o->len != 2) {
- o->len = 2;
- return MODE_NAK;
- }
- return MODE_ACK;
-}
-
-static int
-Pred1SetOptsInput(struct lcp_opt *o, const struct ccp_config *cfg)
-{
- if (o->len != 2) {
- o->len = 2;
+ if (o->hdr.len != 2) {
+ o->hdr.len = 2;
return MODE_NAK;
}
return MODE_ACK;
@@ -332,7 +322,7 @@ const struct ccp_algorithm Pred1Algorithm = {
ccp_DefaultUsable,
ccp_DefaultRequired,
{
- Pred1SetOptsInput,
+ Pred1SetOpts,
Pred1InitInput,
Pred1Term,
Pred1ResetInput,
@@ -342,7 +332,7 @@ const struct ccp_algorithm Pred1Algorithm = {
{
0,
Pred1InitOptsOutput,
- Pred1SetOptsOutput,
+ Pred1SetOpts,
Pred1InitOutput,
Pred1Term,
Pred1ResetOutput,
diff --git a/usr.sbin/ppp/ppp/prompt.c b/usr.sbin/ppp/ppp/prompt.c
index 6a547678087..9207e0900d5 100644
--- a/usr.sbin/ppp/ppp/prompt.c
+++ b/usr.sbin/ppp/ppp/prompt.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: prompt.c,v 1.11 2001/08/19 23:22:18 brian Exp $
+ * $OpenBSD: prompt.c,v 1.12 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -59,7 +59,6 @@
#include "hdlc.h"
#include "lcp.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "async.h"
diff --git a/usr.sbin/ppp/ppp/radius.c b/usr.sbin/ppp/ppp/radius.c
index eab24931a72..cb9b44704ca 100644
--- a/usr.sbin/ppp/ppp/radius.c
+++ b/usr.sbin/ppp/ppp/radius.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: radius.c,v 1.13 2001/08/19 23:22:18 brian Exp $
+ * $OpenBSD: radius.c,v 1.14 2002/05/16 01:13:39 brian Exp $
*
*/
@@ -38,8 +38,10 @@
#ifdef LOCALRAD
#include "radlib.h"
+#include "radlib_vs.h"
#else
#include <radlib.h>
+#include <radlib_vs.h>
#endif
#include <errno.h>
@@ -48,7 +50,6 @@
#include <string.h>
#include <sys/time.h>
#include <termios.h>
-#include <ttyent.h>
#include <unistd.h>
#include <netdb.h>
@@ -86,6 +87,16 @@
#include "datalink.h"
#include "ncp.h"
#include "bundle.h"
+#include "proto.h"
+
+#ifndef NODES
+struct mschap_request {
+ u_char ident;
+ u_char flags;
+ u_char lm_response[24];
+ u_char nt_response[24];
+};
+#endif
/*
* rad_continue_send_request() has given us `got' (non-zero). Deal with it.
@@ -95,13 +106,13 @@ radius_Process(struct radius *r, int got)
{
char *argv[MAXARGS], *nuke;
struct bundle *bundle;
- int argc, addrs, width;
+ int argc, addrs, res, width;
size_t len;
struct ncprange dest;
struct ncpaddr gw;
const void *data;
const char *stype;
- u_int32_t ipaddr;
+ u_int32_t ipaddr, vendor;
struct in_addr ip;
r->cx.fd = -1; /* Stop select()ing */
@@ -118,10 +129,11 @@ radius_Process(struct radius *r, int got)
case RAD_ACCESS_REJECT:
log_Printf(LogPHASE, "Radius(%s): REJECT received\n", stype);
- if (r->cx.auth)
- auth_Failure(r->cx.auth);
- rad_close(r->cx.rad);
- return;
+ if (!r->cx.auth) {
+ rad_close(r->cx.rad);
+ return;
+ }
+ break;
case RAD_ACCESS_CHALLENGE:
/* we can't deal with this (for now) ! */
@@ -156,25 +168,41 @@ radius_Process(struct radius *r, int got)
return;
}
- /* So we've been accepted ! Let's see what we've got in our reply :-I */
+ /* Let's see what we've got in our reply */
r->ip.s_addr = r->mask.s_addr = INADDR_NONE;
r->mtu = 0;
r->vj = 0;
- while ((got = rad_get_attr(r->cx.rad, &data, &len)) > 0) {
- switch (got) {
+ while ((res = rad_get_attr(r->cx.rad, &data, &len)) > 0) {
+ switch (res) {
case RAD_FRAMED_IP_ADDRESS:
r->ip = rad_cvt_addr(data);
- log_Printf(LogPHASE, " IP %s\n", inet_ntoa(r->ip));
+ log_Printf(LogPHASE, " IP %s\n", inet_ntoa(r->ip));
+ break;
+
+ case RAD_FILTER_ID:
+ free(r->filterid);
+ if ((r->filterid = rad_cvt_string(data, len)) == NULL) {
+ log_Printf(LogERROR, "rad_cvt_string: %s\n", rad_strerror(r->cx.rad));
+ auth_Failure(r->cx.auth);
+ rad_close(r->cx.rad);
+ return;
+ }
+ log_Printf(LogPHASE, " Filter \"%s\"\n", r->filterid);
+ break;
+
+ case RAD_SESSION_TIMEOUT:
+ r->sessiontime = rad_cvt_int(data);
+ log_Printf(LogPHASE, " Session-Timeout %lu\n", r->sessiontime);
break;
case RAD_FRAMED_IP_NETMASK:
r->mask = rad_cvt_addr(data);
- log_Printf(LogPHASE, " Netmask %s\n", inet_ntoa(r->mask));
+ log_Printf(LogPHASE, " Netmask %s\n", inet_ntoa(r->mask));
break;
case RAD_FRAMED_MTU:
r->mtu = rad_cvt_int(data);
- log_Printf(LogPHASE, " MTU %lu\n", r->mtu);
+ log_Printf(LogPHASE, " MTU %lu\n", r->mtu);
break;
case RAD_FRAMED_ROUTING:
@@ -186,7 +214,7 @@ radius_Process(struct radius *r, int got)
case RAD_FRAMED_COMPRESSION:
r->vj = rad_cvt_int(data) == 1 ? 1 : 0;
- log_Printf(LogPHASE, " VJ %sabled\n", r->vj ? "en" : "dis");
+ log_Printf(LogPHASE, " VJ %sabled\n", r->vj ? "en" : "dis");
break;
case RAD_FRAMED_ROUTE:
@@ -199,11 +227,12 @@ radius_Process(struct radius *r, int got)
if ((nuke = rad_cvt_string(data, len)) == NULL) {
log_Printf(LogERROR, "rad_cvt_string: %s\n", rad_strerror(r->cx.rad));
+ auth_Failure(r->cx.auth);
rad_close(r->cx.rad);
return;
}
- log_Printf(LogPHASE, " Route: %s\n", nuke);
+ log_Printf(LogPHASE, " Route: %s\n", nuke);
bundle = r->cx.auth->physical->dl->bundle;
ip.s_addr = INADDR_ANY;
ncprange_setip4host(&dest, ip);
@@ -243,19 +272,73 @@ radius_Process(struct radius *r, int got)
}
free(nuke);
break;
+
+ case RAD_REPLY_MESSAGE:
+ free(r->repstr);
+ if ((r->repstr = rad_cvt_string(data, len)) == NULL) {
+ log_Printf(LogERROR, "rad_cvt_string: %s\n", rad_strerror(r->cx.rad));
+ auth_Failure(r->cx.auth);
+ rad_close(r->cx.rad);
+ return;
+ }
+ log_Printf(LogPHASE, " Reply-Message \"%s\"\n", r->repstr);
+ break;
+
+ case RAD_VENDOR_SPECIFIC:
+ if ((res = rad_get_vendor_attr(&vendor, &data, &len)) <= 0) {
+ log_Printf(LogERROR, "rad_get_vendor_attr: %s (failing!)\n",
+ rad_strerror(r->cx.rad));
+ auth_Failure(r->cx.auth);
+ rad_close(r->cx.rad);
+ return;
+ }
+
+ switch (vendor) {
+ case RAD_VENDOR_MICROSOFT:
+ switch (res) {
+ case RAD_MICROSOFT_MS_CHAP_ERROR:
+ free(r->errstr);
+ if ((r->errstr = rad_cvt_string(data, len)) == NULL) {
+ log_Printf(LogERROR, "rad_cvt_string: %s\n",
+ rad_strerror(r->cx.rad));
+ auth_Failure(r->cx.auth);
+ rad_close(r->cx.rad);
+ return;
+ }
+ log_Printf(LogPHASE, " MS-CHAP-Error \"%s\"\n", r->errstr);
+ break;
+
+ default:
+ log_Printf(LogDEBUG, "Dropping MICROSOFT vendor specific "
+ "RADIUS attribute %d\n", res);
+ break;
+ }
+ break;
+
+ default:
+ log_Printf(LogDEBUG, "Dropping vendor %lu RADIUS attribute %d\n",
+ (unsigned long)vendor, res);
+ break;
+ }
+ break;
+
+ default:
+ log_Printf(LogDEBUG, "Dropping RADIUS attribute %d\n", res);
+ break;
}
}
- if (got == -1) {
+ if (res == -1) {
log_Printf(LogERROR, "rad_get_attr: %s (failing!)\n",
rad_strerror(r->cx.rad));
auth_Failure(r->cx.auth);
- rad_close(r->cx.rad);
- } else {
+ } else if (got == RAD_ACCESS_REJECT)
+ auth_Failure(r->cx.auth);
+ else {
r->valid = 1;
auth_Success(r->cx.auth);
- rad_close(r->cx.rad);
}
+ rad_close(r->cx.rad);
}
/*
@@ -343,15 +426,24 @@ radius_Write(struct fdescriptor *d, struct bundle *bundle, const fd_set *fdset)
void
radius_Init(struct radius *r)
{
- r->valid = 0;
- r->cx.fd = -1;
- *r->cfg.file = '\0';;
r->desc.type = RADIUS_DESCRIPTOR;
r->desc.UpdateSet = radius_UpdateSet;
r->desc.IsSet = radius_IsSet;
r->desc.Read = radius_Read;
r->desc.Write = radius_Write;
+ r->cx.fd = -1;
+ r->cx.rad = NULL;
memset(&r->cx.timer, '\0', sizeof r->cx.timer);
+ r->cx.auth = NULL;
+ r->valid = 0;
+ r->vj = 0;
+ r->ip.s_addr = INADDR_ANY;
+ r->mask.s_addr = INADDR_NONE;
+ r->routes = NULL;
+ r->mtu = DEF_MTU;
+ r->repstr = NULL;
+ r->errstr = NULL;
+ *r->cfg.file = '\0';;
log_Printf(LogDEBUG, "Radius: radius_Init\n");
}
@@ -365,12 +457,63 @@ radius_Destroy(struct radius *r)
log_Printf(LogDEBUG, "Radius: radius_Destroy\n");
timer_Stop(&r->cx.timer);
route_DeleteAll(&r->routes);
+ free(r->filterid);
+ r->filterid = NULL;
+ free(r->repstr);
+ r->repstr = NULL;
+ free(r->errstr);
+ r->errstr = NULL;
if (r->cx.fd != -1) {
r->cx.fd = -1;
rad_close(r->cx.rad);
}
}
+static int
+radius_put_physical_details(struct rad_handle *rad, struct physical *p)
+{
+ int slot, type;
+
+ type = RAD_VIRTUAL;
+ if (p->handler)
+ switch (p->handler->type) {
+ case I4B_DEVICE:
+ type = RAD_ISDN_SYNC;
+ break;
+
+ case TTY_DEVICE:
+ type = RAD_ASYNC;
+ break;
+
+ case ETHER_DEVICE:
+ type = RAD_ETHERNET;
+ break;
+
+ case TCP_DEVICE:
+ case UDP_DEVICE:
+ case EXEC_DEVICE:
+ case ATM_DEVICE:
+ case NG_DEVICE:
+ type = RAD_VIRTUAL;
+ break;
+ }
+
+ if (rad_put_int(rad, RAD_NAS_PORT_TYPE, type) != 0) {
+ log_Printf(LogERROR, "rad_put: rad_put_int: %s\n", rad_strerror(rad));
+ rad_close(rad);
+ return 0;
+ }
+
+ if ((slot = physical_Slot(p)) >= 0)
+ if (rad_put_int(rad, RAD_NAS_PORT, slot) != 0) {
+ log_Printf(LogERROR, "rad_put: rad_put_int: %s\n", rad_strerror(rad));
+ rad_close(rad);
+ return 0;
+ }
+
+ return 1;
+}
+
/*
* Start an authentication request to the RADIUS server.
*/
@@ -378,12 +521,14 @@ void
radius_Authenticate(struct radius *r, struct authinfo *authp, const char *name,
const char *key, int klen, const char *challenge, int clen)
{
- struct ttyent *ttyp;
struct timeval tv;
- int got, slot;
+ int got;
char hostname[MAXHOSTNAMELEN];
struct hostent *hp;
struct in_addr hostaddr;
+#ifndef NODES
+ struct mschap_request msreq;
+#endif
if (!*r->cfg.file)
return;
@@ -422,20 +567,54 @@ radius_Authenticate(struct radius *r, struct authinfo *authp, const char *name,
return;
}
- if (challenge != NULL) {
- /* We're talking CHAP */
- if (rad_put_attr(r->cx.rad, RAD_CHAP_PASSWORD, key, klen) != 0 ||
- rad_put_attr(r->cx.rad, RAD_CHAP_CHALLENGE, challenge, clen) != 0) {
- log_Printf(LogERROR, "CHAP: rad_put_string: %s\n",
+ switch (authp->physical->link.lcp.want_auth) {
+ case PROTO_PAP:
+ /* We're talking PAP */
+ if (rad_put_attr(r->cx.rad, RAD_USER_PASSWORD, key, klen) != 0) {
+ log_Printf(LogERROR, "PAP: rad_put_string: %s\n",
rad_strerror(r->cx.rad));
rad_close(r->cx.rad);
return;
}
- } else if (rad_put_attr(r->cx.rad, RAD_USER_PASSWORD, key, klen) != 0) {
- /* We're talking PAP */
- log_Printf(LogERROR, "PAP: rad_put_string: %s\n", rad_strerror(r->cx.rad));
- rad_close(r->cx.rad);
- return;
+ break;
+
+ case PROTO_CHAP:
+ switch (authp->physical->link.lcp.want_authtype) {
+ case 0x5:
+ if (rad_put_attr(r->cx.rad, RAD_CHAP_PASSWORD, key, klen) != 0 ||
+ rad_put_attr(r->cx.rad, RAD_CHAP_CHALLENGE, challenge, clen) != 0) {
+ log_Printf(LogERROR, "CHAP: rad_put_string: %s\n",
+ rad_strerror(r->cx.rad));
+ rad_close(r->cx.rad);
+ return;
+ }
+ break;
+
+#ifndef NODES
+ case 0x80:
+ if (klen != 50) {
+ log_Printf(LogERROR, "CHAP80: Unrecognised length %d\n", klen);
+ rad_close(r->cx.rad);
+ return;
+ }
+ rad_put_vendor_attr(r->cx.rad, RAD_VENDOR_MICROSOFT,
+ RAD_MICROSOFT_MS_CHAP_CHALLENGE, challenge, clen);
+ msreq.ident = *key;
+ msreq.flags = 0x01;
+ memcpy(msreq.lm_response, key + 1, 24);
+ memcpy(msreq.nt_response, key + 25, 24);
+ rad_put_vendor_attr(r->cx.rad, RAD_VENDOR_MICROSOFT,
+ RAD_MICROSOFT_MS_CHAP_RESPONSE, &msreq, 50);
+ break;
+
+ case 0x81:
+#endif
+ default:
+ log_Printf(LogERROR, "CHAP: Unrecognised type 0x%02x\n",
+ authp->physical->link.lcp.want_authtype);
+ rad_close(r->cx.rad);
+ return;
+ }
}
if (gethostname(hostname, sizeof hostname) != 0)
@@ -458,23 +637,7 @@ radius_Authenticate(struct radius *r, struct authinfo *authp, const char *name,
}
}
- if (authp->physical->handler &&
- authp->physical->handler->type == TTY_DEVICE) {
- setttyent();
- for (slot = 1; (ttyp = getttyent()); ++slot)
- if (!strcmp(ttyp->ty_name, authp->physical->name.base)) {
- if(rad_put_int(r->cx.rad, RAD_NAS_PORT, slot) != 0) {
- log_Printf(LogERROR, "rad_put: rad_put_string: %s\n",
- rad_strerror(r->cx.rad));
- rad_close(r->cx.rad);
- endttyent();
- return;
- }
- break;
- }
- endttyent();
- }
-
+ radius_put_physical_details(r->cx.rad, authp->physical);
r->cx.auth = authp;
if ((got = rad_init_send_request(r->cx.rad, &r->cx.fd, &tv)))
@@ -498,9 +661,8 @@ radius_Account(struct radius *r, struct radacct *ac, struct datalink *dl,
int acct_type, struct in_addr *peer_ip, struct in_addr *netmask,
struct pppThroughput *stats)
{
- struct ttyent *ttyp;
struct timeval tv;
- int got, slot;
+ int got;
char hostname[MAXHOSTNAMELEN];
struct hostent *hp;
struct in_addr hostaddr;
@@ -588,22 +750,7 @@ radius_Account(struct radius *r, struct radacct *ac, struct datalink *dl,
}
}
- if (dl->physical->handler &&
- dl->physical->handler->type == TTY_DEVICE) {
- setttyent();
- for (slot = 1; (ttyp = getttyent()); ++slot)
- if (!strcmp(ttyp->ty_name, dl->physical->name.base)) {
- if(rad_put_int(r->cx.rad, RAD_NAS_PORT, slot) != 0) {
- log_Printf(LogERROR, "rad_put: rad_put_string: %s\n",
- rad_strerror(r->cx.rad));
- rad_close(r->cx.rad);
- endttyent();
- return;
- }
- break;
- }
- endttyent();
- }
+ radius_put_physical_details(r->cx.rad, dl->physical);
if (rad_put_int(r->cx.rad, RAD_ACCT_STATUS_TYPE, acct_type) != 0 ||
rad_put_string(r->cx.rad, RAD_ACCT_SESSION_ID, ac->session_id) != 0 ||
@@ -656,6 +803,8 @@ radius_Show(struct radius *r, struct prompt *p)
prompt_Printf(p, " Netmask: %s\n", inet_ntoa(r->mask));
prompt_Printf(p, " MTU: %lu\n", r->mtu);
prompt_Printf(p, " VJ: %sabled\n", r->vj ? "en" : "dis");
+ prompt_Printf(p, " Message: %s\n", r->repstr ? r->repstr : "");
+ prompt_Printf(p, " Error Message: %s\n", r->errstr ? r->errstr : "");
if (r->routes)
route_ShowSticky(p, r->routes, " Routes", 16);
} else
diff --git a/usr.sbin/ppp/ppp/radius.h b/usr.sbin/ppp/ppp/radius.h
index c920c0169d4..11f79197bb2 100644
--- a/usr.sbin/ppp/ppp/radius.h
+++ b/usr.sbin/ppp/ppp/radius.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: radius.h,v 1.6 2001/04/01 22:41:23 brian Exp $
+ * $OpenBSD: radius.h,v 1.7 2002/05/16 01:13:39 brian Exp $
*/
struct radius {
@@ -39,7 +39,11 @@ struct radius {
struct in_addr ip; /* FRAMED IP */
struct in_addr mask; /* FRAMED Netmask */
unsigned long mtu; /* FRAMED MTU */
+ unsigned long sessiontime; /* Session-Timeout */
+ char *filterid; /* FRAMED Filter Id */
struct sticky_route *routes; /* FRAMED Routes */
+ char *repstr; /* Reply-Message */
+ char *errstr; /* Error-Message */
struct {
char file[PATH_MAX]; /* Radius config file */
} cfg;
@@ -76,3 +80,6 @@ extern void radius_Account(struct radius *, struct radacct *,
#define RAD_START 1
#define RAD_STOP 2
#endif
+
+/* Get address from NAS pool */
+#define RADIUS_INADDR_POOL htonl(0xfffffffe) /* 255.255.255.254 */
diff --git a/usr.sbin/ppp/ppp/radlib.c b/usr.sbin/ppp/ppp/radlib.c
index 482d5edb53b..197aeaaab18 100644
--- a/usr.sbin/ppp/ppp/radlib.c
+++ b/usr.sbin/ppp/ppp/radlib.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: radlib.c,v 1.5 2000/11/16 22:18:50 brian Exp $
+ * $OpenBSD: radlib.c,v 1.6 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/types.h>
@@ -864,3 +864,67 @@ split(char *str, char *fields[], int maxfields, char *msg, size_t msglen)
}
return i;
}
+
+int
+rad_get_vendor_attr(u_int32_t *vendor, const void **data, size_t *len)
+{
+ struct vendor_attribute *attr;
+
+ attr = (struct vendor_attribute *)*data;
+ *vendor = ntohl(attr->vendor_value);
+ *data = attr->attrib_data;
+ *len = attr->attrib_len - 2;
+
+ return (attr->attrib_type);
+}
+
+int
+rad_put_vendor_addr(struct rad_handle *h, int vendor, int type,
+ struct in_addr addr)
+{
+ return (rad_put_vendor_attr(h, vendor, type, &addr.s_addr,
+ sizeof addr.s_addr));
+}
+
+int
+rad_put_vendor_attr(struct rad_handle *h, int vendor, int type,
+ const void *value, size_t len)
+{
+ struct vendor_attribute *attr;
+ int res;
+
+ if ((attr = malloc(len + 6)) == NULL) {
+ generr(h, "malloc failure (%d bytes)", len + 6);
+ return -1;
+ }
+
+ attr->vendor_value = htonl(vendor);
+ attr->attrib_type = type;
+ attr->attrib_len = len + 2;
+ memcpy(attr->attrib_data, value, len);
+
+ res = put_raw_attr(h, RAD_VENDOR_SPECIFIC, attr, len + 6);
+ free(attr);
+ if (res == 0 && vendor == RAD_VENDOR_MICROSOFT
+ && (type == RAD_MICROSOFT_MS_CHAP_RESPONSE
+ || type == RAD_MICROSOFT_MS_CHAP2_RESPONSE)) {
+ h->chap_pass = 1;
+ }
+ return (res);
+}
+
+int
+rad_put_vendor_int(struct rad_handle *h, int vendor, int type, u_int32_t i)
+{
+ u_int32_t value;
+
+ value = htonl(i);
+ return (rad_put_vendor_attr(h, vendor, type, &value, sizeof value));
+}
+
+int
+rad_put_vendor_string(struct rad_handle *h, int vendor, int type,
+ const char *str)
+{
+ return (rad_put_vendor_attr(h, vendor, type, str, strlen(str)));
+}
diff --git a/usr.sbin/ppp/ppp/radlib.h b/usr.sbin/ppp/ppp/radlib.h
index cb5bb8d7565..cdd4d236518 100644
--- a/usr.sbin/ppp/ppp/radlib.h
+++ b/usr.sbin/ppp/ppp/radlib.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: radlib.h,v 1.2 2000/08/13 22:05:47 brian Exp $
+ * $OpenBSD: radlib.h,v 1.3 2002/05/16 01:13:39 brian Exp $
*/
#ifndef _RADLIB_H_
@@ -106,6 +106,20 @@
#define RAD_ISDN_ASYNC_V120 3
#define RAD_ISDN_ASYNC_V110 4
#define RAD_VIRTUAL 5
+ #define RAD_PIAFS 6
+ #define RAD_HDLC_CLEAR_CHANNEL 7
+ #define RAD_X_25 8
+ #define RAD_X_75 9
+ #define RAD_G_3_FAX 10
+ #define RAD_SDSL 11
+ #define RAD_ADSL_CAP 12
+ #define RAD_ADSL_DMT 13
+ #define RAD_IDSL 14
+ #define RAD_ETHERNET 15
+ #define RAD_XDSL 16
+ #define RAD_CABLE 17
+ #define RAD_WIRELESS_OTHER 18
+ #define RAD_WIRELESS_IEEE_802_11 19
#define RAD_PORT_LIMIT 62 /* Integer */
#define RAD_LOGIN_LAT_PORT 63 /* Integer */
#define RAD_CONNECT_INFO 77 /* String */
diff --git a/usr.sbin/ppp/ppp/radlib_private.h b/usr.sbin/ppp/ppp/radlib_private.h
index dd8560684f6..5ec83e83dea 100644
--- a/usr.sbin/ppp/ppp/radlib_private.h
+++ b/usr.sbin/ppp/ppp/radlib_private.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: radlib_private.h,v 1.2 2000/08/13 22:05:48 brian Exp $
+ * $OpenBSD: radlib_private.h,v 1.3 2002/05/16 01:13:39 brian Exp $
*/
#ifndef RADLIB_PRIVATE_H
@@ -33,6 +33,7 @@
#include <netinet/in.h>
#include "radlib.h"
+#include "radlib_vs.h"
/* Handle types */
#define RADIUS_AUTH 0 /* RADIUS authentication, default */
@@ -89,4 +90,11 @@ struct rad_handle {
int type; /* Handle type */
};
+struct vendor_attribute {
+ u_int32_t vendor_value;
+ u_char attrib_type;
+ u_char attrib_len;
+ u_char attrib_data[1];
+};
+
#endif
diff --git a/usr.sbin/ppp/ppp/radlib_vs.h b/usr.sbin/ppp/ppp/radlib_vs.h
new file mode 100644
index 00000000000..08b2cf15e78
--- /dev/null
+++ b/usr.sbin/ppp/ppp/radlib_vs.h
@@ -0,0 +1,79 @@
+/*-
+ * Copyright (c) 2002 Brian Somers <brian@Awfulhak.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#ifndef _RADLIB_VS_H_
+#define _RADLIB_VS_H_
+
+#include <sys/types.h>
+#include <netinet/in.h>
+
+#define RAD_VENDOR_MICROSOFT 311 /* rfc2548 */
+ #define RAD_MICROSOFT_MS_CHAP_RESPONSE 1
+ #define RAD_MICROSOFT_MS_CHAP_ERROR 2
+ #define RAD_MICROSOFT_MS_CHAP_PW_1 3
+ #define RAD_MICROSOFT_MS_CHAP_PW_2 4
+ #define RAD_MICROSOFT_MS_CHAP_LM_ENC_PW 5
+ #define RAD_MICROSOFT_MS_CHAP_NT_ENC_PW 6
+ #define RAD_MICROSOFT_MS_MPPE_ENCRYPTION_POLICY 7
+ #define RAD_MICROSOFT_MS_MPPE_ENCRYPTION_TYPES 8
+ #define RAD_MICROSOFT_MS_RAS_VENDOR 9
+ #define RAD_MICROSOFT_MS_CHAP_DOMAIN 10
+ #define RAD_MICROSOFT_MS_CHAP_CHALLENGE 11
+ #define RAD_MICROSOFT_MS_CHAP_MPPE_KEYS 12
+ #define RAD_MICROSOFT_MS_BAP_USAGE 13
+ #define RAD_MICROSOFT_MS_LINK_UTILIZATION_THRESHOLD 14
+ #define RAD_MICROSOFT_MS_LINK_DROP_TIME_LIMIT 15
+ #define RAD_MICROSOFT_MS_MPPE_SEND_KEY 16
+ #define RAD_MICROSOFT_MS_MPPE_RECV_KEY 17
+ #define RAD_MICROSOFT_MS_RAS_VERSION 18
+ #define RAD_MICROSOFT_MS_OLD_ARAP_PASSWORD 19
+ #define RAD_MICROSOFT_MS_NEW_ARAP_PASSWORD 20
+ #define RAD_MICROSOFT_MS_ARAP_PASSWORD_CHANGE_REASON 21
+ #define RAD_MICROSOFT_MS_FILTER 22
+ #define RAD_MICROSOFT_MS_ACCT_AUTH_TYPE 23
+ #define RAD_MICROSOFT_MS_ACCT_EAP_TYPE 24
+ #define RAD_MICROSOFT_MS_CHAP2_RESPONSE 25
+ #define RAD_MICROSOFT_MS_CHAP2_SUCCESS 26
+ #define RAD_MICROSOFT_MS_CHAP2_PW 27
+ #define RAD_MICROSOFT_MS_PRIMARY_DNS_SERVER 28
+ #define RAD_MICROSOFT_MS_SECONDARY_DNS_SERVER 29
+ #define RAD_MICROSOFT_MS_PRIMARY_NBNS_SERVER 30
+ #define RAD_MICROSOFT_MS_SECONDARY_NBNS_SERVER 31
+ #define RAD_MICROSOFT_MS_ARAP_CHALLENGE 33
+
+struct rad_handle;
+
+__BEGIN_DECLS
+int rad_get_vendor_attr(u_int32_t *, const void **, size_t *);
+int rad_put_vendor_addr(struct rad_handle *, int, int, struct in_addr);
+int rad_put_vendor_attr(struct rad_handle *, int, int, const void *,
+ size_t);
+int rad_put_vendor_int(struct rad_handle *, int, int, u_int32_t);
+int rad_put_vendor_string(struct rad_handle *, int, int, const char *);
+__END_DECLS
+
+#endif /* _RADLIB_VS_H_ */
diff --git a/usr.sbin/ppp/ppp/route.c b/usr.sbin/ppp/ppp/route.c
index 252b6d88b7a..2a2a8bd951f 100644
--- a/usr.sbin/ppp/ppp/route.c
+++ b/usr.sbin/ppp/ppp/route.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: route.c,v 1.25 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: route.c,v 1.26 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -39,7 +39,6 @@
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <sys/un.h>
-#include <netdb.h>
#include <errno.h>
#include <stdio.h>
@@ -65,7 +64,6 @@
#include "link.h"
#include "slcompress.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
@@ -200,6 +198,8 @@ p_flags(struct prompt *prompt, u_int32_t f, int max)
prompt_Printf(prompt, "%-*.*s", max, max, name);
}
+static int route_nifs = -1;
+
const char *
Index2Nam(int idx)
{
@@ -210,9 +210,9 @@ Index2Nam(int idx)
* the PCCARD insert/remove events can signal ppp.
*/
static char **ifs; /* Figure these out once */
- static int nifs, debug_done; /* Figure out how many once, and debug once */
+ static int debug_done; /* Debug once */
- if (idx > nifs || (idx > 0 && ifs[idx-1] == NULL)) {
+ if (idx > route_nifs || (idx > 0 && ifs[idx-1] == NULL)) {
int mib[6], have, had;
size_t needed;
char *buf, *ptr, *end;
@@ -222,7 +222,7 @@ Index2Nam(int idx)
if (ifs) {
free(ifs);
ifs = NULL;
- nifs = 0;
+ route_nifs = 0;
}
debug_done = 0;
@@ -264,7 +264,7 @@ Index2Nam(int idx)
newifs = (char **)malloc(sizeof(char *) * have);
if (!newifs) {
log_Printf(LogDEBUG, "Index2Nam: %s\n", strerror(errno));
- nifs = 0;
+ route_nifs = 0;
if (ifs) {
free(ifs);
ifs = NULL;
@@ -279,8 +279,8 @@ Index2Nam(int idx)
ifs[ifm->ifm_index-1] = (char *)malloc(dl->sdl_nlen+1);
memcpy(ifs[ifm->ifm_index-1], dl->sdl_data, dl->sdl_nlen);
ifs[ifm->ifm_index-1][dl->sdl_nlen] = '\0';
- if (nifs < ifm->ifm_index)
- nifs = ifm->ifm_index;
+ if (route_nifs < ifm->ifm_index)
+ route_nifs = ifm->ifm_index;
}
} else if (log_IsKept(LogDEBUG))
log_Printf(LogDEBUG, "Skipping out-of-range interface %d!\n",
@@ -293,13 +293,13 @@ Index2Nam(int idx)
int f;
log_Printf(LogDEBUG, "Found the following interfaces:\n");
- for (f = 0; f < nifs; f++)
+ for (f = 0; f < route_nifs; f++)
if (ifs[f] != NULL)
log_Printf(LogDEBUG, " Index %d, name \"%s\"\n", f+1, ifs[f]);
debug_done = 1;
}
- if (idx < 1 || idx > nifs || ifs[idx-1] == NULL)
+ if (idx < 1 || idx > route_nifs || ifs[idx-1] == NULL)
return NumStr(idx, NULL, 0);
return ifs[idx-1];
@@ -529,11 +529,10 @@ int
GetIfIndex(char *name)
{
int idx;
- const char *got;
idx = 1;
- while (strcmp(got = Index2Nam(idx), "???"))
- if (!strcmp(got, name))
+ while (route_nifs == -1 || idx < route_nifs)
+ if (strcmp(Index2Nam(idx), name) == 0)
return idx;
else
idx++;
diff --git a/usr.sbin/ppp/ppp/server.c b/usr.sbin/ppp/ppp/server.c
index 934e559e311..0b0199074bb 100644
--- a/usr.sbin/ppp/ppp/server.c
+++ b/usr.sbin/ppp/ppp/server.c
@@ -23,14 +23,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: server.c,v 1.14 2002/01/16 14:13:06 brian Exp $
+ * $OpenBSD: server.c,v 1.15 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
-#include <arpa/inet.h>
#include <sys/un.h>
#include <errno.h>
@@ -43,7 +42,6 @@
#include "log.h"
#include "descriptor.h"
#include "server.h"
-#include "id.h"
#include "prompt.h"
#include "ncpaddr.h"
#include "probe.h"
diff --git a/usr.sbin/ppp/ppp/sig.c b/usr.sbin/ppp/ppp/sig.c
index 4ec2591af13..c69f6632574 100644
--- a/usr.sbin/ppp/ppp/sig.c
+++ b/usr.sbin/ppp/ppp/sig.c
@@ -23,11 +23,9 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: sig.c,v 1.5 2001/08/21 04:09:20 brian Exp $
+ * $OpenBSD: sig.c,v 1.6 2002/05/16 01:13:39 brian Exp $
*/
-#include <sys/types.h>
-
#include <signal.h>
#include "log.h"
diff --git a/usr.sbin/ppp/ppp/slcompress.c b/usr.sbin/ppp/ppp/slcompress.c
index c3b84438997..97c7ac0f119 100644
--- a/usr.sbin/ppp/ppp/slcompress.c
+++ b/usr.sbin/ppp/ppp/slcompress.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $OpenBSD: slcompress.c,v 1.13 2001/08/19 23:22:18 brian Exp $
+ * $OpenBSD: slcompress.c,v 1.14 2002/05/16 01:13:39 brian Exp $
*
* Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
* - Initial distribution.
@@ -50,7 +50,6 @@
#include "lqr.h"
#include "hdlc.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "lcp.h"
diff --git a/usr.sbin/ppp/ppp/systems.c b/usr.sbin/ppp/ppp/systems.c
index 0efd7bc06b3..f940967e473 100644
--- a/usr.sbin/ppp/ppp/systems.c
+++ b/usr.sbin/ppp/ppp/systems.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: systems.c,v 1.17 2001/06/13 21:33:42 brian Exp $
+ * $OpenBSD: systems.c,v 1.18 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -36,7 +36,6 @@
#include <stdlib.h>
#include <string.h>
#include <termios.h>
-#include <unistd.h>
#include "defs.h"
#include "command.h"
@@ -186,7 +185,7 @@ DecodeCtrlCommand(char *line, char *arg)
if (!strncasecmp(line, "include", 7) && issep(line[7])) {
end = InterpretArg(line+8, arg);
if (*end && *end != '#')
- log_Printf(LogWARN, "Usage: !include filename\n");
+ log_Printf(LogWARN, "usage: !include filename\n");
else
return CTRL_INCLUDE;
}
diff --git a/usr.sbin/ppp/ppp/tcp.c b/usr.sbin/ppp/ppp/tcp.c
index 1af56e94bc9..239a87be676 100644
--- a/usr.sbin/ppp/ppp/tcp.c
+++ b/usr.sbin/ppp/ppp/tcp.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: tcp.c,v 1.14 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: tcp.c,v 1.15 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/types.h>
@@ -114,6 +114,7 @@ static struct device tcpdevice = {
NULL,
NULL,
NULL,
+ NULL,
NULL
};
diff --git a/usr.sbin/ppp/ppp/tcpmss.c b/usr.sbin/ppp/ppp/tcpmss.c
index c99739e5104..41e484d3f6a 100644
--- a/usr.sbin/ppp/ppp/tcpmss.c
+++ b/usr.sbin/ppp/ppp/tcpmss.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
+ * $OpenBSD: tcpmss.c,v 1.5 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -53,7 +53,6 @@
#include "iplist.h"
#include "slcompress.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
diff --git a/usr.sbin/ppp/ppp/tcpmss.h b/usr.sbin/ppp/ppp/tcpmss.h
index ffd7b827963..93e1f26bf1b 100644
--- a/usr.sbin/ppp/ppp/tcpmss.h
+++ b/usr.sbin/ppp/ppp/tcpmss.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
+ * $OpenBSD: tcpmss.h,v 1.2 2002/05/16 01:13:39 brian Exp $
*/
extern struct layer tcpmsslayer;
diff --git a/usr.sbin/ppp/ppp/throughput.c b/usr.sbin/ppp/ppp/throughput.c
index ddd225f289f..d35fa1b9bd4 100644
--- a/usr.sbin/ppp/ppp/throughput.c
+++ b/usr.sbin/ppp/ppp/throughput.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: throughput.c,v 1.9 2000/08/28 22:44:42 brian Exp $
+ * $OpenBSD: throughput.c,v 1.10 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/types.h>
@@ -141,7 +141,7 @@ throughput_log(struct pppThroughput *t, int level, const char *title)
log_Printf(level, "%s%sConnect time: %d secs: %llu octets in, %llu octets"
" out\n", title, *title ? ": " : "", secs_up, t->OctetsIn,
t->OctetsOut);
- log_Printf(level, "%s%s: %llu packets in, %llu packets out\n",
+ log_Printf(level, "%s%s%llu packets in, %llu packets out\n",
title, *title ? ": " : "", t->PacketsIn, t->PacketsOut);
if (secs_up == 0)
secs_up = 1;
diff --git a/usr.sbin/ppp/ppp/timer.c b/usr.sbin/ppp/ppp/timer.c
index 67a3de36a85..53e713b3894 100644
--- a/usr.sbin/ppp/ppp/timer.c
+++ b/usr.sbin/ppp/ppp/timer.c
@@ -25,14 +25,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: timer.c,v 1.10 2001/09/04 23:35:59 millert Exp $
+ * $OpenBSD: timer.c,v 1.11 2002/05/16 01:13:39 brian Exp $
*/
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
+#ifdef __NetBSD__
#include <sys/time.h>
+#endif
#include <termios.h>
#include "log.h"
diff --git a/usr.sbin/ppp/ppp/tty.c b/usr.sbin/ppp/ppp/tty.c
index 51db0fec40f..31b044d179c 100644
--- a/usr.sbin/ppp/ppp/tty.c
+++ b/usr.sbin/ppp/ppp/tty.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: tty.c,v 1.17 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: tty.c,v 1.18 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -40,6 +40,7 @@
#include <sysexits.h>
#include <sys/uio.h>
#include <termios.h>
+#include <ttyent.h>
#include <unistd.h>
#ifndef NONETGRAPH
#include <netgraph.h>
@@ -260,6 +261,13 @@ LoadLineDiscipline(struct physical *p)
struct ngm_connect ngc;
int ldisc, cs, ds, hot, speed;
+ /*
+ * Don't use the netgraph line discipline for now. Using it works, but
+ * carrier cannot be detected via TIOCMGET and the device doesn't become
+ * selectable with 0 bytes to read when carrier is lost :(
+ */
+ return 0;
+
reply = (struct ng_mesg *)rbuf;
info = (struct nodeinfo *)reply->data;
@@ -546,6 +554,23 @@ tty_OpenInfo(struct physical *p)
return buf;
}
+static int
+tty_Slot(struct physical *p)
+{
+ struct ttyent *ttyp;
+ int slot;
+
+ setttyent();
+ for (slot = 1; (ttyp = getttyent()); ++slot)
+ if (!strcmp(ttyp->ty_name, p->name.base)) {
+ endttyent();
+ return slot;
+ }
+
+ endttyent();
+ return -1;
+}
+
static void
tty_device2iov(struct device *d, struct iovec *iov, int *niov,
int maxiov, int *auxfd, int *nauxfd)
@@ -591,7 +616,8 @@ static struct device basettydevice = {
tty_Write,
tty_device2iov,
tty_Speed,
- tty_OpenInfo
+ tty_OpenInfo,
+ tty_Slot
};
struct device *
diff --git a/usr.sbin/ppp/ppp/tun.c b/usr.sbin/ppp/ppp/tun.c
index 7636cb1eb9d..09b209c8e0d 100644
--- a/usr.sbin/ppp/ppp/tun.c
+++ b/usr.sbin/ppp/ppp/tun.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: tun.c,v 1.14 2002/01/16 14:13:06 brian Exp $
+ * $OpenBSD: tun.c,v 1.15 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -64,7 +64,6 @@
#include "iplist.h"
#include "slcompress.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
diff --git a/usr.sbin/ppp/ppp/udp.c b/usr.sbin/ppp/ppp/udp.c
index 19477fb016b..61930f010ad 100644
--- a/usr.sbin/ppp/ppp/udp.c
+++ b/usr.sbin/ppp/ppp/udp.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: udp.c,v 1.14 2002/03/31 02:38:49 brian Exp $
+ * $OpenBSD: udp.c,v 1.15 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/types.h>
@@ -168,6 +168,7 @@ static const struct device baseudpdevice = {
udp_Sendto,
udp_device2iov,
NULL,
+ NULL,
NULL
};
diff --git a/usr.sbin/ppp/ppp/vjcomp.c b/usr.sbin/ppp/ppp/vjcomp.c
index 6d66951012d..7c8b176d6b4 100644
--- a/usr.sbin/ppp/ppp/vjcomp.c
+++ b/usr.sbin/ppp/ppp/vjcomp.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: vjcomp.c,v 1.15 2002/01/24 23:01:19 millert Exp $
+ * $OpenBSD: vjcomp.c,v 1.16 2002/05/16 01:13:39 brian Exp $
*/
#include <sys/param.h>
@@ -52,7 +52,6 @@
#include "iplist.h"
#include "throughput.h"
#include "ncpaddr.h"
-#include "ip.h"
#include "ipcp.h"
#include "lcp.h"
#include "ccp.h"