]> git.ozlabs.org Git - ppp.git/commitdiff
optionally include filtering stuff
authorPaul Mackerras <paulus@samba.org>
Wed, 30 Apr 1997 05:42:08 +0000 (05:42 +0000)
committerPaul Mackerras <paulus@samba.org>
Wed, 30 Apr 1997 05:42:08 +0000 (05:42 +0000)
freebsd-2.0/if_ppp.c
freebsd-2.0/if_pppvar.h
freebsd-2.0/ppp_tty.c

index 6e450ea5687968e15a7932b60d1dcc1d1b9845f4..d9369d62c46c3a758aa793972817bd6ac37217c4 100644 (file)
@@ -69,7 +69,7 @@
  * Paul Mackerras (paulus@cs.anu.edu.au).
  */
 
-/* $Id: if_ppp.c,v 1.11 1997/03/04 03:27:28 paulus Exp $ */
+/* $Id: if_ppp.c,v 1.12 1997/04/30 05:42:07 paulus Exp $ */
 /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
 /* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
 
@@ -93,6 +93,9 @@
 #include <net/if_types.h>
 #include <net/netisr.h>
 #include <net/route.h>
+#ifdef PPP_FILTER
+#include <net/bpf.h>
+#endif
 
 #if INET
 #include <netinet/in.h>
@@ -131,7 +134,6 @@ static int  pppsioctl __P((struct ifnet *, int, caddr_t));
 static int     pppoutput __P((struct ifnet *, struct mbuf *,
                               struct sockaddr *, struct rtentry *));
 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 *));
@@ -299,6 +301,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);
@@ -323,6 +337,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
@@ -478,6 +497,40 @@ pppioctl(sc, cmd, data, flag, p)
        splx(s);
        break;
 
+#ifdef PPP_FILTER
+    case PPPIOCSPASS:
+    case PPPIOCSACTIVE:
+       nbp = (struct bpf_program *) data;
+       if ((unsigned) nbp->bf_len > BPF_MAXINSNS)
+           return EINVAL;
+       newcodelen = nbp->bf_len * sizeof(struct bpf_insn);
+       if (newcodelen != 0) {
+           MALLOC(newcode, struct bpf_insn *, newcodelen, M_DEVBUF, M_WAITOK);
+           if (newcode == 0) {
+               return EINVAL;          /* or sumpin */
+           }
+           if ((error = copyin((caddr_t)nbp->bf_insns, (caddr_t)newcode,
+                              newcodelen)) != 0) {
+               FREE(newcode, M_DEVBUF);
+               return error;
+           }
+           if (!bpf_validate(newcode, nbp->bf_len)) {
+               FREE(newcode, M_DEVBUF);
+               return EINVAL;
+           }
+       } else
+           newcode = 0;
+       bp = (cmd == PPPIOCSPASS)? &sc->sc_pass_filt: &sc->sc_active_filt;
+       oldcode = bp->bf_insns;
+       s = splimp();
+       bp->bf_len = nbp->bf_len;
+       bp->bf_insns = newcode;
+       splx(s);
+       if (oldcode != 0)
+           FREE(oldcode, M_DEVBUF);
+       break;
+#endif
+
     default:
        return (-1);
     }
@@ -487,7 +540,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;
     int cmd;
@@ -685,10 +738,33 @@ pppoutput(ifp, m0, dst, rtp)
     }
 
     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
@@ -813,7 +889,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
@@ -1298,11 +1373,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
index e91e8899cc796d52e02497f4da8cc8230a600345..91e8e4e758638a1f994a81452205c3a117175093 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: if_pppvar.h,v 1.4 1997/03/04 03:27:28 paulus Exp $ */
+/*     $Id: if_pppvar.h,v 1.5 1997/04/30 05:42:08 paulus Exp $ */
 /*
  * if_pppvar.h - private structures and declarations for PPP.
  *
@@ -75,6 +75,10 @@ struct ppp_softc {
        void    *sc_rc_state;           /* receive decompressor state */
        time_t  sc_last_sent;           /* time (secs) last NP pkt sent */
        time_t  sc_last_recv;           /* time (secs) last NP pkt rcvd */
+#ifdef PPP_FILTER
+       struct  bpf_program sc_pass_filt;   /* filter for packets to pass */
+       struct  bpf_program sc_active_filt; /* filter for "non-idle" packets */
+#endif /* PPP_FILTER */
 #ifdef VJC
        struct  vjcompress *sc_comp;    /* vjc control buffer */
 #endif
index f06c4d7d32a69edcd23c62d246bae9be788fba06..912f0831a27c7081ee9a8abbc2a86416154de7eb 100644 (file)
@@ -70,7 +70,7 @@
  * Paul Mackerras (paulus@cs.anu.edu.au).
  */
 
-/* $Id: ppp_tty.c,v 1.7 1997/03/04 03:27:28 paulus Exp $ */
+/* $Id: ppp_tty.c,v 1.8 1997/04/30 05:42:08 paulus Exp $ */
 /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
 /* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
 
 #include <net/pppcompress.h>
 #endif
 
+#ifdef PPP_FILTER
+#include <net/bpf.h>
+#endif
 #include <net/ppp_defs.h>
 #include <net/if_ppp.h>
 #include <net/if_pppvar.h>