X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=netbsd-1.1%2Fif_ppp.c;h=cbfca8c8ff35f2bcb6bd1abc074f733fbd7d1eb6;hp=d17cf8bde0328f5aeba725f2a9d8417a264632fd;hb=8197e4418d390af8d4286f15589e0704d8a387d0;hpb=9dd596f6706e7aabf5556858d781bd23ac03764e diff --git a/netbsd-1.1/if_ppp.c b/netbsd-1.1/if_ppp.c index d17cf8b..cbfca8c 100644 --- a/netbsd-1.1/if_ppp.c +++ b/netbsd-1.1/if_ppp.c @@ -1,4 +1,4 @@ -/* $Id: if_ppp.c,v 1.3 1996/07/01 01:03:38 paulus Exp $ */ +/* $Id: if_ppp.c,v 1.7 1997/04/30 05:46:49 paulus Exp $ */ /* * if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver. @@ -90,10 +90,17 @@ #include #include +#if NetBSD1_0 && defined(i386) +#include +#endif + #include #include #include #include +#ifdef PPP_FILTER +#include +#endif #if INET #include @@ -104,6 +111,7 @@ #include "bpfilter.h" #if NBPFILTER > 0 +#include #include #endif @@ -116,13 +124,17 @@ #include #include +#if NetBSD1_0 +#define splsoftnet splnet +#endif + #ifdef PPP_COMPRESS #define PACKETPTR struct mbuf * #include #endif +static int pppsioctl __P((struct ifnet *, u_long, caddr_t)); static void ppp_requeue __P((struct ppp_softc *)); -static void ppp_outpkt __P((struct ppp_softc *)); static void ppp_ccp __P((struct ppp_softc *, struct mbuf *m, int rcvd)); static void ppp_ccp_closed __P((struct ppp_softc *)); static void ppp_inproc __P((struct ppp_softc *, struct mbuf *)); @@ -197,6 +209,18 @@ pppattach() bpfattach(&sc->sc_bpf, &sc->sc_if, DLT_PPP, PPP_HDRLEN); #endif } + +#if NetBSD1_0 && defined(i386) + /* + * XXX kludge to fix the bug in the i386 interrupt handling code, + * where software interrupts could be taken while hardware + * interrupts were blocked. + */ + if ((imask[IPL_TTY] & (1 << SIR_NET)) == 0) { + imask[IPL_TTY] |= (1 << SIR_NET); + intr_calculatemasks(); + } +#endif } /* @@ -287,6 +311,18 @@ pppdealloc(sc) sc->sc_xc_state = NULL; sc->sc_rc_state = NULL; #endif /* PPP_COMPRESS */ +#ifdef PPP_FILTER + if (sc->sc_pass_filt.bf_insns != 0) { + FREE(sc->sc_pass_filt.bf_insns, M_DEVBUF); + sc->sc_pass_filt.bf_insns = 0; + sc->sc_pass_filt.bf_len = 0; + } + if (sc->sc_active_filt.bf_insns != 0) { + FREE(sc->sc_active_filt.bf_insns, M_DEVBUF); + sc->sc_active_filt.bf_insns = 0; + sc->sc_active_filt.bf_len = 0; + } +#endif /* PPP_FILTER */ #ifdef VJC if (sc->sc_comp != 0) { FREE(sc->sc_comp, M_DEVBUF); @@ -311,6 +347,11 @@ pppioctl(sc, cmd, data, flag, p) struct compressor **cp; struct npioctl *npi; time_t t; +#ifdef PPP_FILTER + struct bpf_program *bp, *nbp; + struct bpf_insn *newcode, *oldcode; + int newcodelen; +#endif /* PPP_FILTER */ #ifdef PPP_COMPRESS u_char ccp_option[CCP_MAX_OPTION_LENGTH]; #endif @@ -466,7 +507,7 @@ pppioctl(sc, cmd, data, flag, p) splx(s); break; -#if 0 +#ifdef PPP_FILTER case PPPIOCSPASS: case PPPIOCSACTIVE: nbp = (struct bpf_program *) data; @@ -509,7 +550,7 @@ pppioctl(sc, cmd, data, flag, p) /* * Process an ioctl request to the ppp network interface. */ -int +static int pppsioctl(ifp, cmd, data) register struct ifnet *ifp; u_long cmd; @@ -622,6 +663,8 @@ pppoutput(ifp, m0, dst, rtp) struct ip *ip; struct ifqueue *ifq; enum NPmode mode; + int len; + struct mbuf *m; if (sc->sc_devp == NULL || (ifp->if_flags & IFF_RUNNING) == 0 || ((ifp->if_flags & IFF_UP) == 0 && dst->sa_family != AF_UNSPEC)) { @@ -695,16 +738,43 @@ pppoutput(ifp, m0, dst, rtp) *cp++ = protocol & 0xff; m0->m_len += PPP_HDRLEN; + len = 0; + for (m = m0; m != 0; m = m->m_next) + len += m->m_len; + if (sc->sc_flags & SC_LOG_OUTPKT) { printf("ppp%d output: ", ifp->if_unit); pppdumpm(m0); } if ((protocol & 0x8000) == 0) { +#ifdef PPP_FILTER + /* + * Apply the pass and active filters to the packet, + * but only if it is a data packet. + */ + *mtod(m0, u_char *) = 1; /* indicates outbound */ + if (sc->sc_pass_filt.bf_insns != 0 + && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m0, + len, 0) == 0) { + error = 0; /* drop this packet */ + goto bad; + } + + /* + * Update the time we sent the most recent packet. + */ + if (sc->sc_active_filt.bf_insns == 0 + || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m0, len, 0)) + sc->sc_last_sent = time.tv_sec; + + *mtod(m0, u_char *) = address; +#else /* * Update the time we sent the most recent data packet. */ sc->sc_last_sent = time.tv_sec; +#endif /* PPP_FILTER */ } #if NBPFILTER > 0 @@ -829,7 +899,6 @@ ppp_dequeue(sc) struct mbuf *m, *mp; u_char *cp; int address, control, protocol; - int s; /* * Grab a packet to send: first try the fast queue, then the @@ -909,13 +978,18 @@ ppp_dequeue(sc) for (mp = m; mp != NULL; mp = mp->m_next) slen += mp->m_len; clen = (*sc->sc_xcomp->compress) - (sc->sc_xc_state, &mcomp, m, slen, - (sc->sc_flags & SC_CCP_UP? sc->sc_if.if_mtu: 0)); + (sc->sc_xc_state, &mcomp, m, slen, sc->sc_if.if_mtu + PPP_HDRLEN); if (mcomp != NULL) { - m_freem(m); - m = mcomp; - cp = mtod(m, u_char *); - protocol = cp[3]; + if (sc->sc_flags & SC_CCP_UP) { + /* Send the compressed packet instead of the original. */ + m_freem(m); + m = mcomp; + cp = mtod(m, u_char *); + protocol = cp[3]; + } else { + /* Can't transmit compressed packets until CCP is up. */ + m_freem(mcomp); + } } } #endif /* PPP_COMPRESS */ @@ -1309,11 +1383,32 @@ ppp_inproc(sc, m) m->m_pkthdr.len = ilen; m->m_pkthdr.rcvif = ifp; - /* - * Record the time that we received this packet. - */ if ((proto & 0x8000) == 0) { +#ifdef PPP_FILTER + /* + * See whether we want to pass this packet, and + * if it counts as link activity. + */ + adrs = *mtod(m, u_char *); /* save address field */ + *mtod(m, u_char *) = 0; /* indicate inbound */ + if (sc->sc_pass_filt.bf_insns != 0 + && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m, + ilen, 0) == 0) { + /* drop this packet */ + m_freem(m); + return; + } + if (sc->sc_active_filt.bf_insns == 0 + || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m, ilen, 0)) + sc->sc_last_recv = time.tv_sec; + + *mtod(m, u_char *) = adrs; +#else + /* + * Record the time that we received this packet. + */ sc->sc_last_recv = time.tv_sec; +#endif /* PPP_FILTER */ } #if NBPFILTER > 0