Module Name: src Committed By: rmind Date: Wed Sep 18 23:34:55 UTC 2013
Modified Files: src/sys/external/bsd/ipf/netinet: fil.c src/sys/net: bpf.c bpf.h bpf_filter.c if_ppp.c src/sys/net/npf: npf_ruleset.c Log Message: Add bpf_filter_ext() to use with BPF COP, restore bpf_filter() as it was originally to preserve compatibility. Similarly, add bpf_validate_ext() which takes bpf_ctx_t. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/external/bsd/ipf/netinet/fil.c cvs rdiff -u -r1.176 -r1.177 src/sys/net/bpf.c cvs rdiff -u -r1.61 -r1.62 src/sys/net/bpf.h cvs rdiff -u -r1.57 -r1.58 src/sys/net/bpf_filter.c cvs rdiff -u -r1.140 -r1.141 src/sys/net/if_ppp.c cvs rdiff -u -r1.22 -r1.23 src/sys/net/npf/npf_ruleset.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/external/bsd/ipf/netinet/fil.c diff -u src/sys/external/bsd/ipf/netinet/fil.c:1.11 src/sys/external/bsd/ipf/netinet/fil.c:1.12 --- src/sys/external/bsd/ipf/netinet/fil.c:1.11 Thu Sep 12 20:03:10 2013 +++ src/sys/external/bsd/ipf/netinet/fil.c Wed Sep 18 23:34:55 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fil.c,v 1.11 2013/09/12 20:03:10 martin Exp $ */ +/* $NetBSD: fil.c,v 1.12 2013/09/18 23:34:55 rmind Exp $ */ /* * Copyright (C) 2012 by Darren Reed. @@ -138,7 +138,7 @@ extern struct timeout ipf_slowtimer_ch; #if !defined(lint) #if defined(__NetBSD__) #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fil.c,v 1.11 2013/09/12 20:03:10 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fil.c,v 1.12 2013/09/18 23:34:55 rmind Exp $"); #else static const char sccsid[] = "@(#)fil.c 1.36 6/5/96 (C) 1993-2000 Darren Reed"; static const char rcsid[] = "@(#)Id: fil.c,v 1.1.1.2 2012/07/22 13:45:07 darrenr Exp $"; @@ -2405,14 +2405,8 @@ ipf_scanlist(fr_info_t *fin, u_32_t pass continue; mc = (u_char *)fin->fin_m; wlen = fin->fin_dlen + fin->fin_hlen; -#if defined(__NetBSD__) - if (!bpf_filter(bpf_def_ctx, NULL, - fr->fr_data, mc, wlen, 0)) - continue; -#else if (!bpf_filter(fr->fr_data, mc, wlen, 0)) continue; -#endif break; } #endif Index: src/sys/net/bpf.c diff -u src/sys/net/bpf.c:1.176 src/sys/net/bpf.c:1.177 --- src/sys/net/bpf.c:1.176 Mon Sep 9 20:53:51 2013 +++ src/sys/net/bpf.c Wed Sep 18 23:34:55 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: bpf.c,v 1.176 2013/09/09 20:53:51 christos Exp $ */ +/* $NetBSD: bpf.c,v 1.177 2013/09/18 23:34:55 rmind Exp $ */ /* * Copyright (c) 1990, 1991, 1993 @@ -39,7 +39,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.176 2013/09/09 20:53:51 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.177 2013/09/18 23:34:55 rmind Exp $"); #if defined(_KERNEL_OPT) #include "opt_bpf.h" @@ -1382,8 +1382,7 @@ bpf_deliver(struct bpf_if *bp, void *(*c if (d->bd_jitcode != NULL) slen = d->bd_jitcode(pkt, pktlen, buflen); else - slen = bpf_filter(bpf_def_ctx, NULL, d->bd_filter, - pkt, pktlen, buflen); + slen = bpf_filter(d->bd_filter, pkt, pktlen, buflen); if (!slen) { continue; Index: src/sys/net/bpf.h diff -u src/sys/net/bpf.h:1.61 src/sys/net/bpf.h:1.62 --- src/sys/net/bpf.h:1.61 Fri Aug 30 15:00:08 2013 +++ src/sys/net/bpf.h Wed Sep 18 23:34:55 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: bpf.h,v 1.61 2013/08/30 15:00:08 rmind Exp $ */ +/* $NetBSD: bpf.h,v 1.62 2013/09/18 23:34:55 rmind Exp $ */ /* * Copyright (c) 1990, 1991, 1993 @@ -384,23 +384,20 @@ struct bpf_ctx; typedef struct bpf_ctx bpf_ctx_t; typedef uint32_t (*bpf_copfunc_t)(const struct mbuf *, void *, uint32_t, uint32_t *); -extern bpf_ctx_t *bpf_def_ctx; bpf_ctx_t *bpf_create(void); void bpf_destroy(bpf_ctx_t *); int bpf_set_cop(bpf_ctx_t *, const bpf_copfunc_t *, size_t); -u_int bpf_filter(bpf_ctx_t *, void *, const struct bpf_insn *, +u_int bpf_filter_ext(bpf_ctx_t *, void *, const struct bpf_insn *, const u_char *, u_int, u_int); -int bpf_validate(const struct bpf_insn *, int); +int bpf_validate_ext(bpf_ctx_t *, const struct bpf_insn *, int); -#else +#endif int bpf_validate(const struct bpf_insn *, int); u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int); -#endif - __END_DECLS /* Index: src/sys/net/bpf_filter.c diff -u src/sys/net/bpf_filter.c:1.57 src/sys/net/bpf_filter.c:1.58 --- src/sys/net/bpf_filter.c:1.57 Fri Aug 30 15:00:08 2013 +++ src/sys/net/bpf_filter.c Wed Sep 18 23:34:55 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: bpf_filter.c,v 1.57 2013/08/30 15:00:08 rmind Exp $ */ +/* $NetBSD: bpf_filter.c,v 1.58 2013/09/18 23:34:55 rmind Exp $ */ /*- * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: bpf_filter.c,v 1.57 2013/08/30 15:00:08 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bpf_filter.c,v 1.58 2013/09/18 23:34:55 rmind Exp $"); #if 0 #if !(defined(lint) || defined(KERNEL)) @@ -61,8 +61,7 @@ struct bpf_ctx { }; /* Default BPF context (zeroed). */ -static bpf_ctx_t bpf_def_ctx1; -bpf_ctx_t * bpf_def_ctx = &bpf_def_ctx1; +static bpf_ctx_t bpf_def_ctx; bpf_ctx_t * bpf_create(void) @@ -179,8 +178,16 @@ m_xbyte(const struct mbuf *m, uint32_t k * buflen is the amount of data present */ #ifdef _KERNEL + u_int -bpf_filter(bpf_ctx_t *bc, void *arg, const struct bpf_insn *pc, +bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen, + u_int buflen) +{ + return bpf_filter_ext(&bpf_def_ctx, NULL, pc, p, wirelen, buflen); +} + +u_int +bpf_filter_ext(bpf_ctx_t *bc, void *arg, const struct bpf_insn *pc, const u_char *p, u_int wirelen, u_int buflen) #else u_int @@ -547,9 +554,21 @@ bpf_filter(const struct bpf_insn *pc, co */ __CTASSERT(BPF_MEMWORDS == sizeof(uint16_t) * NBBY); +#if defined(KERNEL) || defined(_KERNEL) + int bpf_validate(const struct bpf_insn *f, int signed_len) { + return bpf_validate_ext(&bpf_def_ctx, f, signed_len); +} + +int +bpf_validate_ext(bpf_ctx_t *bc, const struct bpf_insn *f, int signed_len) +#else +int +bpf_validate(const struct bpf_insn *f, int signed_len) +#endif +{ u_int i, from, len, ok = 0; const struct bpf_insn *p; #if defined(KERNEL) || defined(_KERNEL) Index: src/sys/net/if_ppp.c diff -u src/sys/net/if_ppp.c:1.140 src/sys/net/if_ppp.c:1.141 --- src/sys/net/if_ppp.c:1.140 Fri Aug 30 15:00:08 2013 +++ src/sys/net/if_ppp.c Wed Sep 18 23:34:55 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ppp.c,v 1.140 2013/08/30 15:00:08 rmind Exp $ */ +/* $NetBSD: if_ppp.c,v 1.141 2013/09/18 23:34:55 rmind Exp $ */ /* Id: if_ppp.c,v 1.6 1997/03/04 03:33:00 paulus Exp */ /* @@ -102,7 +102,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.140 2013/08/30 15:00:08 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.141 2013/09/18 23:34:55 rmind Exp $"); #include "ppp.h" @@ -946,7 +946,7 @@ pppoutput(struct ifnet *ifp, struct mbuf * but only if it is a data packet. */ if (sc->sc_pass_filt_out.bf_insns != 0 - && bpf_filter(bpf_def_ctx, NULL, sc->sc_pass_filt_out.bf_insns, + && bpf_filter(sc->sc_pass_filt_out.bf_insns, (u_char *)m0, len, 0) == 0) { error = 0; /* drop this packet */ goto bad; @@ -956,7 +956,7 @@ pppoutput(struct ifnet *ifp, struct mbuf * Update the time we sent the most recent packet. */ if (sc->sc_active_filt_out.bf_insns == 0 - || bpf_filter(bpf_def_ctx, NULL, sc->sc_active_filt_out.bf_insns, + || bpf_filter(sc->sc_active_filt_out.bf_insns, (u_char *)m0, len, 0)) sc->sc_last_sent = time_second; #else @@ -1584,14 +1584,14 @@ ppp_inproc(struct ppp_softc *sc, struct * if it counts as link activity. */ if (sc->sc_pass_filt_in.bf_insns != 0 - && bpf_filter(bpf_def_ctx, NULL, sc->sc_pass_filt_in.bf_insns, + && bpf_filter(sc->sc_pass_filt_in.bf_insns, (u_char *)m, ilen, 0) == 0) { /* drop this packet */ m_freem(m); return; } if (sc->sc_active_filt_in.bf_insns == 0 - || bpf_filter(bpf_def_ctx, NULL, sc->sc_active_filt_in.bf_insns, + || bpf_filter(sc->sc_active_filt_in.bf_insns, (u_char *)m, ilen, 0)) sc->sc_last_recv = time_second; #else Index: src/sys/net/npf/npf_ruleset.c diff -u src/sys/net/npf/npf_ruleset.c:1.22 src/sys/net/npf/npf_ruleset.c:1.23 --- src/sys/net/npf/npf_ruleset.c:1.22 Fri Aug 30 15:00:08 2013 +++ src/sys/net/npf/npf_ruleset.c Wed Sep 18 23:34:55 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_ruleset.c,v 1.22 2013/08/30 15:00:08 rmind Exp $ */ +/* $NetBSD: npf_ruleset.c,v 1.23 2013/09/18 23:34:55 rmind Exp $ */ /*- * Copyright (c) 2009-2013 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: npf_ruleset.c,v 1.22 2013/08/30 15:00:08 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: npf_ruleset.c,v 1.23 2013/09/18 23:34:55 rmind Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -681,8 +681,7 @@ npf_rule_inspect(npf_cache_t *npc, nbuf_ case NPF_CODE_BPF: { struct mbuf *m = nbuf_head_mbuf(nbuf); size_t pktlen = m_length(m); - return bpf_filter(bpf_def_ctx, NULL, code, - (unsigned char *)m, pktlen, 0) != 0; + return bpf_filter(code, (unsigned char *)m, pktlen, 0) != 0; } default: KASSERT(false);