NPF: convert to bpf_jit_generate()/bpf_jit_freecode(). trunk
authorrmind <rmind@NetBSD.org>
Sat, 16 Nov 2013 01:18:58 +0000
branchtrunk
changeset 222498 ec5020d949a0
parent 222497 cd31ccf30450
child 222499 13df49d641b1
NPF: convert to bpf_jit_generate()/bpf_jit_freecode().
sys/net/npf/npf_bpf.c
sys/net/npf/npf_impl.h
sys/net/npf/npf_ruleset.c
--- a/sys/net/npf/npf_bpf.c	Sat Nov 16 01:13:52 2013 +0000
+++ b/sys/net/npf/npf_bpf.c	Sat Nov 16 01:18:58 2013 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_bpf.c,v 1.3 2013/11/15 00:12:44 rmind Exp $	*/
+/*	$NetBSD: npf_bpf.c,v 1.4 2013/11/16 01:18:58 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
@@ -34,12 +34,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_bpf.c,v 1.3 2013/11/15 00:12:44 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_bpf.c,v 1.4 2013/11/16 01:18:58 rmind Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
 
 #include <sys/mbuf.h>
+#include <net/bpf.h>
 
 #define NPF_BPFCOP
 #include "npf_impl.h"
@@ -96,6 +97,12 @@
 	return bpf_filter_ext(npf_bpfctx, code, &args);
 }
 
+void *
+npf_bpf_compile(void *code, size_t size)
+{
+	return bpf_jit_generate(npf_bpfctx, code, size);
+}
+
 bool
 npf_bpf_validate(const void *code, size_t len)
 {
--- a/sys/net/npf/npf_impl.h	Sat Nov 16 01:13:52 2013 +0000
+++ b/sys/net/npf/npf_impl.h	Sat Nov 16 01:18:58 2013 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_impl.h,v 1.39 2013/11/15 00:12:45 rmind Exp $	*/
+/*	$NetBSD: npf_impl.h,v 1.40 2013/11/16 01:18:58 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
@@ -209,6 +209,7 @@
 void		npf_bpf_sysfini(void);
 int		npf_bpf_filter(npf_cache_t *, nbuf_t *,
 		    const void *, bpfjit_func_t);
+void *		npf_bpf_compile(void *, size_t);
 bool		npf_bpf_validate(const void *, size_t);
 
 /* Tableset interface. */
--- a/sys/net/npf/npf_ruleset.c	Sat Nov 16 01:13:52 2013 +0000
+++ b/sys/net/npf/npf_ruleset.c	Sat Nov 16 01:18:58 2013 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_ruleset.c,v 1.27 2013/11/15 00:12:45 rmind Exp $	*/
+/*	$NetBSD: npf_ruleset.c,v 1.28 2013/11/16 01:18:58 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.27 2013/11/15 00:12:45 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_ruleset.c,v 1.28 2013/11/16 01:18:58 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -563,17 +563,14 @@
 npf_rule_setcode(npf_rule_t *rl, const int type, void *code, size_t size)
 {
 	KASSERT(type == NPF_CODE_BPF);
-	rl->r_type = type;
-	rl->r_code = code;
-	rl->r_clen = size;
-#if 0
-	/* Perform BPF JIT if possible. */
-	if (membar_consumer(), bpfjit_module_ops.bj_generate_code != NULL) {
-		KASSERT(rl->r_jcode == NULL);
-		rl->r_jcode = bpfjit_module_ops.bj_generate_code(code, size);
+
+	if ((rl->r_jcode = npf_bpf_compile(code, size)) == NULL) {
+		rl->r_code = code;
+		rl->r_clen = size;
+	} else {
 		rl->r_code = NULL;
 	}
-#endif
+	rl->r_type = type;
 }
 
 /*
@@ -609,8 +606,7 @@
 	}
 	if (rl->r_jcode) {
 		/* Free JIT code. */
-		KASSERT(bpfjit_module_ops.bj_free_code != NULL);
-		bpfjit_module_ops.bj_free_code(rl->r_jcode);
+		bpf_jit_freecode(rl->r_jcode);
 	}
 	if (rl->r_dict) {
 		/* Destroy the dictionary. */