From owner-svn-soc-all@FreeBSD.ORG Tue Jul 29 10:50:00 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 12F3C895 for ; Tue, 29 Jul 2014 10:50:00 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E7F0B292E for ; Tue, 29 Jul 2014 10:49:59 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s6TAnxwW079942 for ; Tue, 29 Jul 2014 10:49:59 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s6TAnwcw079903 for svn-soc-all@FreeBSD.org; Tue, 29 Jul 2014 10:49:58 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 29 Jul 2014 10:49:58 GMT Message-Id: <201407291049.s6TAnwcw079903@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271525 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jul 2014 10:50:00 -0000 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 + #include #include #include #include #include +#include #include #include #include #include +#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 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 *);