/*
* if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver.
*
- * Copyright (c) 1989 Carnegie Mellon University.
- * All rights reserved.
+ * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
*
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by Carnegie Mellon University. The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * 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.
+ *
+ * 3. The name "Carnegie Mellon University" must not be used to
+ * endorse or promote products derived from this software without
+ * prior written permission. For permission or any legal
+ * details, please contact
+ * Office of Technology Transfer
+ * Carnegie Mellon University
+ * 5000 Forbes Avenue
+ * Pittsburgh, PA 15213-3890
+ * (412) 268-4387, fax: (412) 268-7395
+ * tech-transfer@andrew.cmu.edu
+ *
+ * 4. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by Computing Services
+ * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
+ *
+ * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Drew D. Perkins
* Carnegie Mellon University
/* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
#if !defined(lint)
-static char sccsid[] = "$Revision: 1.3 $ ($Date: 1997/07/14 03:49:07 $)";
+static char sccsid[] = "$Revision: 1.13 $ ($Date: 2002/12/06 09:49:15 $)";
#endif /* not lint*/
#define KERNEL 1
#define KERNEL_FEATURES 1
#define INET 1
-/* #include "ppp.h" */
-
+#if NS_TARGET >= 40
+#if NS_TARGET >= 41
+#include <kernserv/clock_timer.h>
+#include <kernserv/lock.h>
+#else
+#include <kern/lock.h>
+#endif /* NS_TARGET */
+#endif /* NS_TARGET */
#include <sys/param.h>
+#if NS_TARGET >= 41
+typedef simple_lock_data_t lock_data_t; /* XXX */
+#endif /* NS_TARGET */
#include <sys/proc.h>
#include "netbuf.h"
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
+#if !(NS_TARGET >= 40)
#include <kernserv/prototypes.h>
+#endif
#if defined(m68k)
#import "spl.h"
#else
#include <netinet/tcp.h>
#endif
-
#include <net/ppp_defs.h>
#ifdef VJC
#include <net/vjcompress.h>
#endif
#include <net/if_ppp.h>
+#include "NeXT_Version.h"
#include "if_pppvar.h"
+
struct ppp_softc ppp_softc[NUM_PPP];
#include <net/ppp-comp.h>
#endif
-#ifdef NBPFILTER
-#include <bpf/bpf.h>
-/*
- * We store the address of necessary BPF functions
- * here.
- */
-struct bpf_fns fnarg;
-#endif
-
/*
* The max number of NETBUF_Ts we wish to compress and cache for
* sending.
register struct ppp_softc *sc;
register int i = 0;
- IOLog("\nPPP version 2.3.1 for NS 3.2 and 3.3\n");
- IOLog("LKS: %s\n", sccsid);
+ IOLog("\nPPP version 2.3.11-%s for NeXTSTEP and OPENSTEP\n", PPPVERSION);
IOLog("by Stephen Perkins, Philip Prindeville, and Pete French\n");
-
- IOLog("Installing PPP on Line Discipline %d\n", PPPDISC);
if (install_ppp_ld() < 0) {
IOLog("ppp: Could not install line discipline\n");
}
-
- IOLog("Installing interfaces:\n");
for (sc = ppp_softc; i < NUM_PPP; sc++, i++) {
sc->sc_if = if_attach(NULL, NULL, pppoutput,
pppgetbuf, pppcontrol, "ppp", i, "Serial line PPP",
PPP_MTU, IFF_POINTOPOINT, NETIFCLASS_VIRTUAL, (void *) sc);
- IOLog(" Initializing ppp%d\n", i);
nbq_init(&sc->sc_freeq, &qparms[QFREE]);
nbq_init(&sc->sc_rawq, &qparms[QRAW]);
nbq_init(&sc->sc_fastq, &qparms[QFAST]);
nbq_init(&sc->sc_npq, &qparms[QNP]);
nbq_init(&sc->sc_compq, &qparms[QCACHE]);
IOLog(" ppp%d successfully attached.\n", i);
-#ifdef NBPFILTER
- bpfattach((caddr_t *) &sc->sc_bpf, sc->sc_if, DLT_PPP, PPP_HDRLEN);
-#endif
}
ipforwarding = 1;
ipsendredirects = 1;
- IOLog("PPP-2.3 Successfully Installed.\n\n");
+ IOLog("PPP Successfully Installed.\n\n");
}
int
{
int nppp, i;
struct ppp_softc *sc;
+#if NS_TARGET >= 40
+ struct timeval tv_time;
+#endif /* NS_TARGET */
for (nppp = 0, sc = ppp_softc; nppp < NUM_PPP; nppp++, sc++)
if (sc->sc_xfer == pid) {
for (i = 0; i < NUM_NP; ++i)
sc->sc_npmode[i] = NPMODE_ERROR;
/* XXX - I'm not sure why the npqueue was zapped here... */
+
+#if NS_TARGET >= 40
+ ns_time_to_timeval(clock_value(System), &tv_time);
+ sc->sc_last_sent = sc->sc_last_recv = tv_time.tv_sec;
+#else
sc->sc_last_sent = sc->sc_last_recv = time.tv_sec;
+#endif
+
sc->sc_compsched = 0;
sc->sc_decompsched = 0;
#ifdef HAS_BROKEN_TIOCSPGRP
struct tty *tp = sc->sc_devp;
#endif
+#if NS_TARGET >= 40
+ struct timeval tv_time;
+#endif /* NS_TARGET */
+
switch (cmd) {
case FIONREAD:
case PPPIOCGIDLE:
s = splimp();
+#if NS_TARGET >= 40
+ ns_time_to_timeval(clock_value(System), &tv_time);
+ t = tv_time.tv_sec;
+#else
t = time.tv_sec;
+#endif /* NS_TARGET */
((struct ppp_idle *)data)->xmit_idle = t - sc->sc_last_sent;
((struct ppp_idle *)data)->recv_idle = t - sc->sc_last_recv;
splx(s);
goto bad;
}
-#ifdef NETBUF_PROXY
- m0->pktinfo.first.tv_sec = time.tv_sec;
- m0->pktinfo.first.tv_usec = time.tv_usec;
- m0->pktinfo.size1 = NB_SIZE(m0);
-#endif
/*
* Compute PPP header.
*cp++ = protocol >> 8;
*cp++ = protocol & 0xff;
-#if defined(NBPFILTER) && defined(NETBUF_PROXY)
- /*
- * We need to copy the header to the original copy.
- */
- bcopy(mtod(m0, u_char *), NB_MAP_ORIG(m0), PPP_HDRLEN);
-
-#endif
if (sc->sc_flags & SC_LOG_OUTPKT) {
IOLog("ppp%d: output:\n", if_unit(ifp)); /* XXX */
}
-#if defined(NBPFILTER) && !defined(NETBUF_PROXY)
- /*
- * See if bpf wants to look at the packet.
- * We must hand it off _before_ any compression
- * takes place. If NETBUF_PROXY is defined,
- * we do the handoff later (in ppp_tty.c)
- * because we keep a copy of the original
- * datagram around.
- */
-
- if (sc->sc_bpf)
- bpf_tap(sc->sc_bpf, NB_MAP(m0), NB_SIZE(m0));
-
-#endif
-
-
/*
* Put the packet on the appropriate queue.
*/
NETBUF_T m;
u_char *cp;
int address, control, protocol;
+#if NS_TARGET >= 40
+ struct timeval tv_time;
+#endif
/*
* Grab a packet to send: first try the fast queue, then the
control = PPP_CONTROL(cp);
protocol = PPP_PROTOCOL(cp);
-#ifdef NETBUF_PROXY
- m->pktinfo.second.tv_sec = time.tv_sec;
- m->pktinfo.second.tv_usec = time.tv_usec;
-#endif
+#if NS_TARGET >= 40
+ ns_time_to_timeval(clock_value(System), &tv_time);
+#endif /* NS_TARGET */
switch (protocol) {
case PPP_IP:
/*
* Update the time we sent the most recent packet.
*/
- sc->sc_last_sent = time.tv_sec;
+#if NS_TARGET >= 40
+ sc->sc_last_sent = tv_time.tv_sec;
+#else
+ sc->sc_last_sent = time.tv_sec;
+#endif /* NS_TARGET */
#ifdef VJC
/*
switch (type) {
case TYPE_UNCOMPRESSED_TCP:
protocol = PPP_VJC_UNCOMP;
-#ifdef NETBUF_PROXY
- m->pktinfo.flags |= NBFLAG_VJCINC;
-#endif
break;
case TYPE_COMPRESSED_TCP:
NB_SHRINK_TOP(m, vjhdr - (u_char *) ip);
-#ifdef NETBUF_PROXY
- m->pktinfo.flags |= NBFLAG_VJC;
-#endif
protocol = PPP_VJC_COMP;
cp = mtod(m, u_char *);
cp[0] = address; /* header has moved */
}
-#ifdef NETBUF_PROXY
- m->pktinfo.size2 = NB_SIZE(m);
-#endif
-
-
#ifdef PPP_COMPRESS
if (protocol != PPP_LCP && protocol != PPP_CCP
&& sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN)) {
if (mcomp != NULL) {
-#ifdef NETBUF_PROXY
- /*
- * duplicate all the stat info into the new
- * buffer.
- */
- m->pktinfo.flags |= NBFLAG_CCP;
-
- NB_DUPLICATE(m, mcomp);
-#endif
-
NB_FREE(m);
m = mcomp;
cp = mtod(m, u_char *);
protocol = cp[3];
}
-#ifdef NETBUF_PROXY
- else
- m->pktinfo.flags |= NBFLAG_CCPINC;
-#endif
-
}
#endif /* PPP_COMPRESS */
-#ifdef NETBUF_PROXY
- m->pktinfo.size3 = NB_SIZE(m);
-#endif
-
-
/*
* Compress the address/control and protocol, if possible.
*/
protocol != PPP_LCP) {
/* can compress address/control */
NB_SHRINK_TOP(m, 2);
-#ifdef NETBUF_PROXY
- m->pktinfo.flags |= NBFLAG_AC;
-#endif
}
if (sc->sc_flags & SC_COMP_PROT && protocol < 0xFF) {
/* can compress protocol */
cp[1] = cp[0];
}
NB_SHRINK_TOP(m, 1);
-#ifdef NETBUF_PROXY
- m->pktinfo.flags |= NBFLAG_PC;
-#endif
}
-#ifdef NETBUF_PROXY
- m->pktinfo.third.tv_sec = time.tv_sec;
- m->pktinfo.third.tv_usec = time.tv_usec;
-#endif
s = splimp();
nbq_enqueue(&sc->sc_compq, m);
NETBUF_T dmp;
u_char *iphdr;
u_int hlen;
+#if NS_TARGET >= 40
+ struct timeval tv_time;
+#endif /* NS_TARGET */
-#ifdef NETBUF_PROXY
- m->pktinfo.third.tv_sec = time.tv_sec;
- m->pktinfo.third.tv_usec = time.tv_usec;
-#endif
incr_cnt(sc->sc_if, if_ipackets);
*/
if (proto == PPP_COMP && sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)
&& !(sc->sc_flags & SC_DC_ERROR) && !(sc->sc_flags & SC_DC_FERROR)) {
-#ifdef NETBUF_PROXY
- m->pktinfo.flags |= NBFLAG_CCP;
-#endif
/* decompress this packet */
rv = (*sc->sc_rcomp->decompress)(sc->sc_rc_state, m, &dmp);
if (rv == DECOMP_OK){
-#ifdef NETBUF_PROXY
- if (dmp != NULL)
- {
-
- NB_DUPLICATE(m, dmp);
-/* bcopy(&(m->pktinfo), &(dmp->pktinfo), sizeof(bpf_encapsulater)); */
-
- }
-#endif
NB_FREE(m);
if (dmp == NULL){
/* No error, but no decompressed packet returned */
if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN))
{
-#ifdef NETBUF_PROXY
- m->pktinfo.flags |= NBFLAG_CCPINC;
-#endif
(*sc->sc_rcomp->incomp)(sc->sc_rc_state, m);
}
if (proto == PPP_CCP) {
ilen = NB_SIZE(m);
-#ifdef NETBUF_PROXY
- m->pktinfo.size2 = ilen;
-#endif
-
#ifdef VJC
if (sc->sc_flags & SC_VJ_RESET) {
/*
if (sc->sc_flags & SC_REJ_COMP_TCP)
goto bad;
-#ifdef NETBUF_PROXY
- m->pktinfo.flags |= NBFLAG_VJC;
-#endif
xlen = vj_uncompress_tcp(cp + PPP_HDRLEN, ilen - PPP_HDRLEN,
ilen - PPP_HDRLEN,
if (sc->sc_flags & SC_REJ_COMP_TCP)
goto bad;
-#ifdef NETBUF_PROXY
- m->pktinfo.flags |= NBFLAG_VJCINC;
-#endif
vj_uncompress_uncomp(cp + PPP_HDRLEN, ilen-PPP_HDRLEN, &sc->sc_comp);
}
#endif /* VJC */
-#ifdef NETBUF_PROXY
- m->pktinfo.size3 = NB_SIZE(m);
- m->pktinfo.fourth.tv_sec = time.tv_sec;
- m->pktinfo.fourth.tv_usec = time.tv_usec;
-#endif
-
-#ifdef NBPFILTER
- /*
- * See if bpf wants to look at the packet.
- * Size includes the PPP header by not the trailer.
- */
- if (sc->sc_bpf)
-#ifndef NETBUF_PROXY
- bpf_tap(sc->sc_bpf, NB_MAP(m), NB_SIZE(m));
-#else
- bpf_tap(sc->sc_bpf, m, 0);
-#endif
-#endif
rv = 0;
switch (proto) {
}
NB_SHRINK_TOP(m, PPP_HDRLEN);
inet_queue(sc->sc_if, NB_TO_nb(m));
+#if NS_TARGET >= 40
+ /* I am assuming the time is different here than above. */
+ ns_time_to_timeval(clock_value(System), &tv_time);
+ sc->sc_last_recv = tv_time.tv_sec; /* update time of last pkt rcvd */
+#else
sc->sc_last_recv = time.tv_sec; /* update time of last pkt rcvd */
+#endif
return;
#endif