Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Jul 2014 10:49:58 GMT
From:      dpl@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r271525 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw
Message-ID:  <201407291049.s6TAnwcw079903@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dpl
Date: Tue Jul 29 10:49:57 2014
New Revision: 271525
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271525

Log:
  Added a first version of lockcheckvnet()

Added:
  soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.c
Modified:
  soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c
  soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h
  soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc
  soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.h

Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c
==============================================================================
--- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c	Tue Jul 29 09:46:08 2014	(r271524)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c	Tue Jul 29 10:49:57 2014	(r271525)
@@ -128,7 +128,6 @@
 static unsigned int default_fw_tables = IPFW_TABLES_DEFAULT;
 
 /* JIT compiling API */
-void ipfw_jit_init();
 funcptr compile_code();
 
 /* Pointer to the actual compiled code */
@@ -266,7 +265,7 @@
 ipfw_chk(struct ip_fw_args *args)
 {
 	if (compiledfuncptr == 0)
-		compiledfuncptr = compile_code();
+		compiledfuncptr = compile_code(args);
 
 	if ((int)compiledfuncptr != 0) {
 		return compiledfuncptr();
@@ -655,11 +654,9 @@
 		args->f_id.dst_port = dst_port = ntohs(dst_port);
 	}
 
-	IPFW_PF_RLOCK(chain);
-	if (! V_ipfw_vnet_ready) { /* shutting down, leave NOW. */
-		IPFW_PF_RUNLOCK(chain);
-		return (IP_FW_PASS);	/* accept */
-	}
+	/* Returns -1 on error */
+	if (lockcheckvnet(chain))
+		return (IP_FW_PASS);
 	if (args->rule.slot) {
 		/*
 		 * Packet has already been tagged as a result of a previous
@@ -1230,9 +1227,6 @@
 
 	ipfw_log_bpf(1); /* init */
 
-	/* Start JIT */
-	ipfw_jit_init();
-
 	return (error);
 }
 

Added: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.c	Tue Jul 29 10:49:57 2014	(r271525)
@@ -0,0 +1,7 @@
+/*
+ * This is the file that gets compiled when 
+ * generating bitcode.
+ */
+
+ #define IPFW_RULES_INLINE __unused
+ #include "ip_fw_rules.h"

Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h
==============================================================================
--- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h	Tue Jul 29 09:46:08 2014	(r271524)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h	Tue Jul 29 10:49:57 2014	(r271525)
@@ -1921,3 +1921,19 @@
 	}
 	*done = 1;	/* exit outer loop */
 }
+
+/*
+ * From here on, there's ip_fw2 code, so that
+ * we can add this to our jit compiled code.
+ */
+static IPFW_RULES_INLINE int
+lockcheckvnet(struct ip_fw_chain *chain)
+{
+	IPFW_PF_RLOCK(chain);
+	if (! V_ipfw_vnet_ready) { /* shutting down, leave NOW. */
+		IPFW_PF_RUNLOCK(chain);
+		return (-1);	/* accept */
+	}
+	return 0;
+}
+

Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc
==============================================================================
--- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc	Tue Jul 29 09:46:08 2014	(r271524)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc	Tue Jul 29 10:49:57 2014	(r271525)
@@ -1,15 +1,21 @@
 /* JIT compilation code */
+#include <net/vnet.h>
+
 #include <iostream>
 #include <string>
 #include <vector>
 
 #include <llvm/ADT/OwningPtr.h>
 #include <llvm/Bitcode/ReaderWriter.h>
+#include <llvm/IR/IRBuilder.h>
 #include <llvm/IR/LLVMContext.h>
 #include <llvm/IR/Module.h>
 #include <llvm/Support/MemoryBuffer.h>
 #include <llvm/Support/ErrorOr.h>
 
+#include "ip_fw_private.h"
+#include "ip_fw_private.h"
+
 typedef int (*funcptr)();
 using namespace llvm;
 
@@ -19,6 +25,7 @@
 		LLVMContext con;
 		LLVMContext &c = con;
 		OwningPtr<MemoryBuffer> buffer;
+		//IRBuilder<> irb;
 	public:
 		jitCompiler(std::string name)
 		{
@@ -37,14 +44,27 @@
 			}
 			mod = ptr.get();
 		}
-} ;
 
-extern "C" void
-ipfw_jit_init()
+		int
+		loadStub(std::string funcname)
+		{
+			return 0;
+		}
+};
+
+extern "C" funcptr
+compile_code(struct ip_fw_args *args)
 {
 	jitCompiler("ip_fw_rules.bc");
 
-	/* XXX - We have to understand what we have to here.
+	int f_pos = 0;		/* index of current rule in the array */
+
+	// Now I have to load the stubs of the loaded rules.
+	// For that, I need a table: RULE, "functname", #args
+
+	// Iterate through the rules.
+
+	/*
 	// Get the stub (prototype) for the cell function
 	F = Mod->getFunction("cell");
 	// Set it to have private linkage, so that it can be removed after being
@@ -85,11 +105,5 @@
 	}
 
 	*/
-}
-
-/* The mother of all functions! */
-extern "C" funcptr
-compile_code()
-{
 	return 0;
 }

Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.h
==============================================================================
--- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.h	Tue Jul 29 09:46:08 2014	(r271524)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.h	Tue Jul 29 10:49:57 2014	(r271525)
@@ -1,4 +1,5 @@
+#include "ip_fw_private.h"
+
 typedef int (*funcptr)();
 
-void ipfw_jit_init();
-funcptr compile_code();
+funcptr compile_code(struct ip_fw_args *);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407291049.s6TAnwcw079903>