Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Aug 2014 13:12:23 GMT
From:      dpl@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r271850 - in soc2014/dpl/netmap-ipfwjit: . sys/netpfil/ipfw
Message-ID:  <201408041312.s74DCN7T025053@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dpl
Date: Mon Aug  4 13:12:23 2014
New Revision: 271850
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271850

Log:
  Added first version of building code to the JIT-compiler.

Modified:
  soc2014/dpl/netmap-ipfwjit/Makefile.kipfw
  soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc

Modified: soc2014/dpl/netmap-ipfwjit/Makefile.kipfw
==============================================================================
--- soc2014/dpl/netmap-ipfwjit/Makefile.kipfw	Mon Aug  4 13:11:37 2014	(r271849)
+++ soc2014/dpl/netmap-ipfwjit/Makefile.kipfw	Mon Aug  4 13:12:23 2014	(r271850)
@@ -72,6 +72,13 @@
 E_CFLAGS += -D_KERNEL
 E_CFLAGS += $(CFLAGS2)
 
+#Flags needed for jit.cc
+J_CFLAGS += $(INCDIRS) $(NETMAP_FLAGS)
+J_CFLAGS += -DINET -D_KERNEL -D_BSD_SOURCE -DKERNEL_SIDE -DUSERSPACE
+J_CFLAGS += -I ../extra/
+#J_CFLAGS += -include $(M)/../extra/glue.h		# headers
+#J_CFLAGS += -include $(M)/../extra/missing.h		# headers
+
 #ipfw + dummynet section, other parts are not compiled in
 SRCS_IPFW	 = ip_fw2.c ip_fw_pfil.c ip_fw_sockopt.c
 SRCS_IPFW	+= ip_fw_dynamic.c ip_fw_table.c
@@ -136,7 +143,7 @@
 EFILES = $(foreach i,$(EDIRS),$(subst $(empty) , $(i)/, $(EFILES_$(i):  = )))
 
 BCFLAGS=-emit-llvm -c
-CXXFLAGS= -c `llvm-config-devel --cxxflags`
+CXXFLAGS=`llvm-config-devel --cxxflags`
 
 include_e:
 	-@echo "Building $(OBJPATH)/include_e ..."
@@ -154,17 +161,17 @@
 ../ip_fw_rules.bc:
 	@$(CC) $(CFLAGS) $(BCFLAGS) -o ../ip_fw_rules.bc ../sys/netpfil/ipfw/ip_fw_rules.c
 
-radix.o:#	CFLAGS += -U_KERNEL
+radix.o:	CFLAGS += -U_KERNEL
 
 # session.o:	CFLAGS = -O2
 nm_util.o:	CFLAGS = -O2 -Wall -Werror $(NETMAP_FLAGS)
 
-$(MOD): $(IPFW_OBJS) jit.o 
+$(MOD): $(IPFW_OBJS) jit.o
 	$(MSG) "   LD $@"
 	$(HIDE)clang++ -o $@ $^ $(LIBS)
 
 jit.o: jit.cc ../ip_fw_rules.bc
-	@clang++ $(CXXFLAGS) ../sys/netpfil/ipfw/jit.cc -o ./jit.o
+	clang++ $(J_CFLAGS) $(CXXFLAGS) ../sys/netpfil/ipfw/jit.cc -o ./jit.o
 
 clean:
 	-rm -f *.o $(DN) $(MOD)

Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc
==============================================================================
--- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc	Mon Aug  4 13:11:37 2014	(r271849)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc	Mon Aug  4 13:12:23 2014	(r271850)
@@ -1,5 +1,31 @@
 /* JIT compilation code */
-#include <net/vnet.h>
+extern "C" {
+#include <glue.h>
+#include <missing.h>
+#include <sys/types.h>
+#include <stdint.h>
+#include <time.h>
+#include <sys/socket.h>
+#include <sys/queue.h>
+#include <sys/lock.h>
+#include <sys/param.h>
+#include <sys/mutex.h>
+#include <netinet/in.h>
+#include <net/if.h>
+#include <netinet/ip_fw.h>
+#include <netinet/ip_dummynet.h>
+#include <net/netmap_user.h>
+#include <net/if_var.h>
+#include <net/ethernet.h>
+#include <netinet/in_pcb.h>
+#include <netinet/ip_var.h>
+#include <sys/lock.h>
+#include <sys/param.h>
+
+#include <netpfil/ipfw/dn_heap.h>
+#include <netpfil/ipfw/ip_dn_private.h>
+#include <netpfil/ipfw/ip_fw_private.h>
+}
 
 #include <iostream>
 #include <string>
@@ -13,18 +39,11 @@
 #include <llvm/Support/MemoryBuffer.h>
 #include <llvm/Support/ErrorOr.h>
 
-#include "ip_fw_private.h"
-
 typedef int (*funcptr)();
 
-extern "C" {
-VNET_DECLARE(struct ip_fw_chain, layer3_chain);
-#define	V_layer3_chain		VNET(layer3_chain)
-}
-
 using namespace llvm;
 
-class jitCompiler { 
+class jitCompiler {
 	private:
 		Module *mod;
 		LLVMContext con;
@@ -32,28 +51,33 @@
 		OwningPtr<MemoryBuffer> buffer;
 		//IRBuilder<> irb;
 	public:
-		jitCompiler(std::string name)
+		Module *loadbc(std::string name)
 		{
 			/* We load the bc for JIT compilation */
 			error_code ec = MemoryBuffer::getFile(name, buffer);
 			if (ec) {
 				std::cerr << "Failed to open bitcode: " << ec.message() << "\n";
-				exit(EXIT_FAILURE);
+				return (NULL);
 			}
 
 			ErrorOr<Module*> ptr = parseBitcodeFile(buffer.get(), con);
 			if ((ec = ptr.getError()))
 			{
 				std::cerr << "Failed to parse bitcode: " << ec.message() << "\n";
-				exit(EXIT_FAILURE);
+				return (NULL);
 			}
-			mod = ptr.get();
+			return (ptr.get());
 		}
 
 		int
-		loadStub(std::string funcname)
+		emit_nop(Type *match)
 		{
 			/*
+				static IPFW_RULES_INLINE void
+				rule_nop(int *match)
+				{
+					*match = 1;
+				}
 			// 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
@@ -86,7 +110,7 @@
 			// as a parameter in this.
 			v = B.CreateAlloca(regTy);
 			B.CreateStore(args++, v);
-// Create a load of pointers to the global registers.
+			// Create a load of pointers to the global registers.
 			Value *gArg = args;
 			for (int i=0 ; i<10 ; i++)
 			{
@@ -98,6 +122,13 @@
 		}
 
 		int
+		emit_forward_mac()
+		{
+			return (0);
+		}
+
+		/* Set the needed variables to perform pkt filtering. */
+		int
 		setVars()
 		{
 			return (0);
@@ -105,14 +136,15 @@
 };
 
 extern "C" funcptr
-compile_code(struct ip_fw_args *args)
+compile_code(struct ip_fw_args *args, struct ip_fw_chain *chain)
 {
-	struct ip_fw_chain *chain = &V_layer3_chain;
+	int f_pos, res;
+	Module *bc;
+	jitCompiler comp;
 
-	auto comp = jitCompiler("ip_fw_rules.bc");
+	bc = comp.loadbc("ip_fw_rules.bc");
 
-	// XXX Now I have to load the stubs of the loaded rules.
-	// For that, I need a table: RULE, "functname", #args
+	// Now I have to load the stubs of the loaded rules.
 	// Iterate through the rules.
 	if (args->rule.slot) {
 		/*
@@ -130,6 +162,9 @@
 		f_pos = 0;
 	}
 
+	int done = 0;		/* flag to exit the outer loop */
+	int pktlen = args->m->m_pkthdr.len;
+
 	// Iterate through the rules.
 	for (; f_pos < chain->n_rules; f_pos++) {
 		ipfw_insn *cmd;
@@ -168,247 +203,255 @@
 
 			switch (cmd->opcode) {
 			case O_NOP:
-				comp.loadStub("nop");
+				comp.emit_nop(*match);
 				break;
 
 			case O_FORWARD_MAC:
-				comp.loadStub("forward_mac");
+				comp.emit_forward_mac();
 				break;
-
+/* XXX
 			case O_GID:
 			case O_UID:
 			case O_JAIL:
-				comp.loadStub("jail");
+				comp.emit_jail();
 				break;
 
 			case O_RECV:
-				comp.loadStub("recv");
+				comp.emit_recv();
 				break;
 
 			case O_XMIT:
-				comp.loadStub("xmit");
+				comp.emit_xmit();
 				break;
 
 			case O_VIA:
-				comp.loadStub("via");
+				comp.emit_via();
 				break;
 
 			case O_MACADDR2:
-				comp.loadStub("macaddr2");
+				comp.emit_macaddr2();
 				break;
 
 			case O_MAC_TYPE:
-				comp.loadStub("mac_type");
+				comp.emit_mac_type();
 				break;
 
 			case O_FRAG:
-				comp.loadStub("frag");
+				comp.emit_frag();
 				break;
 
 			case O_IN:
-				comp.loadStub("in");
+				comp.emit_in();
 				break;
 
 			case O_LAYER2:
-				comp.loadStub("layer2");
+				comp.emit_layer2();
 				break;
 
 			case O_DIVERTED:
-				comp.loadStub("diverted");
+				comp.emit_diverted();
 				break;
 
 			case O_PROTO:
-				comp.loadStub("proto");
+				comp.emit_proto();
 				break;
 
 			case O_IP_SRC:
-				comp.loadStub("ip_src");
+				comp.emit_ip_src();
 				break;
 
 			case O_IP_SRC_LOOKUP:
 			case O_IP_DST_LOOKUP:
-				comp.loadStub("ip_dst_lookup");
+				comp.emit_ip_dst_lookup();
 				break;
 
 			case O_IP_SRC_MASK:
 			case O_IP_DST_MASK:
-				comp.loadStub("ip_dst_mask");
+				comp.emit_ip_dst_mask();
 				break;
 
 			case O_IP_SRC_ME:
-				comp.loadStub("ip_src_me");
+				comp.emit_ip_src_me();
 #ifdef INET6
 				/* FALLTHROUGH */
+/* XXX
 			case O_IP6_SRC_ME:
-				comp.loadStub("ip6_src_me");
+				comp.emit_ip6_src_me();
 #endif
 				break;
 
 			case O_IP_DST_SET:
 			case O_IP_SRC_SET:
-				comp.loadStub("ip_src_set");
+				comp.emit_ip_src_set();
 				break;
 
 			case O_IP_DST:
-				comp.loadStub("ip_dst");
+				comp.emit_ip_dst();
 				break;
 
 			case O_IP_DST_ME:
-				comp.loadStub("ip_dst_me");
+				comp.emit_ip_dst_me();
 				
 #ifdef INET6
 				/* FALLTHROUGH */
+/* XXX
 			case O_IP6_DST_ME:
-				comp.loadStub("ip6_dst_me");
+				comp.emit_ip6_dst_me();
 #endif
 				break;
 
 
 			case O_IP_SRCPORT:
 			case O_IP_DSTPORT:
-				comp.loadStub("ip_dstport");
+				comp.emit_ip_dstport();
 				break;
 
 			case O_ICMPTYPE:
-				comp.loadStub("icmptype");
+				comp.emit_icmptype();
 				break;
 
 #ifdef INET6
 			case O_ICMP6TYPE:
-				comp.loadStub("icmp6type");
+				comp.emit_icmp6type();
 				break;
 #endif /* INET6 */
 
+/* XXX
 			case O_IPOPT:
-				comp.loadStub("ipopt");
+				comp.emit_ipopt();
 				break;
 
 			case O_IPVER:
-				comp.loadStub("ipver");
+				comp.emit_ipver();
 				break;
 
 			case O_IPID:
 			case O_IPLEN:
 			case O_IPTTL:
-				comp.loadStub("ipttl");
+				comp.emit_ipttl();
 				break;
 
 			case O_IPPRECEDENCE:
-				comp.loadStub("ipprecedence");
+				comp.emit_ipprecedence();
 				break;
 
 			case O_IPTOS:
-				comp.loadStub("iptos");
+				comp.emit_iptos();
 				break;
 
 			case O_DSCP:
-				comp.loadStub("dscp");
+				comp.emit_dscp();
 				break;
 
 			case O_TCPDATALEN:
-				comp.loadStub("tcpdatalen");
+				comp.emit_tcpdatalen();
 				break;
 
 			case O_TCPFLAGS:
-				comp.loadStub("tcpflags");
+				comp.emit_tcpflags();
 				break;
 
 			case O_TCPOPTS:
-				comp.loadStub("tcpopts");
+				/* if (rule_tcpopts(&match, hlen, ulp, proto, offset, cmd, m, args))
+					goto pullup_failed; */
+/* XXX
+				comp.emit_tcpopts();
 				break;
 
 			case O_TCPSEQ:
-				comp.loadStub("tcpseq");
+				comp.emit_tcpseq();
 				break;
 
 			case O_TCPACK:
-				comp.loadStub("tcpack");
+				comp.emit_tcpack();
 				break;
 
 			case O_TCPWIN:
-				comp.loadStub("tcpwin");
+				comp.emit_tcpwin();
 				break;
 
 			case O_ESTAB:
-				comp.loadStub("estab");
+				comp.emit_estab();
 				break;
 
 			case O_ALTQ:
-				comp.loadStub("altq");
+				comp.emit_altq();
 				break;
 
 			case O_LOG:
-				comp.loadStub("log");
+				comp.emit_log();
 				break;
 
 			case O_PROB:
-				comp.loadStub("prob");
+				comp.emit_prob();
 				break;
 
 			case O_VERREVPATH:
-				comp.loadStub("verrevpath");
+				comp.emit_verrevpath();
 				break;
 
 			case O_VERSRCREACH:
-				comp.loadStub("versrcreach");
+				comp.emit_versrcreach();
 				break;
 
 			case O_ANTISPOOF:
-				comp.loadStub("antispoof");
+				comp.emit_antispoof();
 				break;
 
 			case O_IPSEC:
 #ifdef IPSEC
-				comp.loadStub("ipsec");
+				comp.emit_ipsec();
 #endif
 				/* otherwise no match */
+/* XXX
 				break;
 
 #ifdef INET6
 			case O_IP6_SRC:
-				comp.loadStub("ip6_src");
+				comp.emit_ip6_src();
 				break;
 
 			case O_IP6_DST:
-				comp.loadStub("ip6_dst");
+				comp.emit_ip6_dst();
 				break;
 
 			case O_IP6_SRC_MASK:
 			case O_IP6_DST_MASK:
-				comp.loadStub("ip6_dst_mask");
+				comp.emit_ip6_dst_mask();
 				break;
 
 			case O_FLOW6ID:
-				comp.loadStub("flow6id");
+				comp.emit_flow6id();
 				break;
 
 			case O_EXT_HDR:
-				comp.loadStub("ext_hdr");
+				comp.emit_ext_hdr();
 				break;
 
 			case O_IP6:
-				comp.loadStub("ip6");
+				comp.emit_ip6();
 				break;
 #endif
 
 			case O_IP4:
-				comp.loadStub("ip4");
+				comp.emit_ip4();
 				break;
 
 			case O_TAG: 
-				comp.loadStub("tag");
+				comp.emit_tag();
 				break;
 
 			case O_FIB: /* try match the specified fib */
-				comp.loadStub("fib");
+/* XXX
+				comp.emit_fib();
 				break;
 
 			case O_SOCKARG:
-				comp.loadStub("sockarg");
+				comp.emit_sockarg();
 				break;
 
 			case O_TAGGED:
-				comp.loadStub("tagged");
+				comp.emit_tagged();
 				break;
 				
 			/*
@@ -452,85 +495,90 @@
 			 *   The jump to the next rule is done by setting
 			 *   l=0, cmdlen=0.
 			 */
+/* XXX
 			case O_LIMIT:
 			case O_KEEP_STATE:
-				comp.loadStub("keep_state");
+				comp.emit_keep_state();
 				break;
 
 			case O_PROBE_STATE:
 			case O_CHECK_STATE:
-				comp.loadStub("check_state");
+				comp.emit_check_state();
 				break;
 
 			case O_ACCEPT:
-				comp.loadStub("accept");
+				comp.emit_accept();
 				break;
 
 			case O_PIPE:
 			case O_QUEUE:
-				comp.loadStub("queue");
+				comp.emit_queue();
 				break;
 
 			case O_DIVERT:
 			case O_TEE:
-				comp.loadStub("tee");
+				comp.emit_tee();
 				break;
 
 			case O_COUNT:
-				comp.loadStub("count");
+				comp.emit_count();
 				break;
 
 			case O_SKIPTO:
-				comp.loadStub("skipto");
+				comp.emit_skipto();
 			    continue;
 			    break;	/* NOTREACHED */
+/* XXX
 
 			case O_CALLRETURN:
-				comp.loadStub("callreturn");
+				comp.emit_callreturn();
 				continue;
 				break;	/* NOTREACHED */
 
+/* XXX
 			case O_REJECT:
-				comp.loadStub("reject");
+				comp.emit_reject();
 				/* FALLTHROUGH */
+/* XXX
 #ifdef INET6
 			case O_UNREACH6:
-				comp.loadStub("unreach6");
+				comp.emit_unreach6();
 				/* FALLTHROUGH */
+/* XXX
 #endif
 			case O_DENY:
-				comp.loadStub("deny");
+				comp.emit_deny();
 				break;
 
 			case O_FORWARD_IP:
-				comp.loadStub("forward_ip");
+				comp.emit_forward_ip();
 				break;
 
 #ifdef INET6
 			case O_FORWARD_IP6:
-				comp.loadStub("forward_ip6");
+				comp.emit_forward_ip6();
 				break;
 #endif
 
 			case O_NETGRAPH:
 			case O_NGTEE:
-				comp.loadStub("ngtee");
+				comp.emit_ngtee();
 				break;
 
 			case O_SETFIB:
-				comp.loadStub("setfib");
+				comp.emit_setfib();
 				break;
 
 			case O_SETDSCP:
-				comp.loadStub("setdscp");
+				comp.emit_setdscp();
 				break;
 
 			case O_NAT:
-				comp.loadStub("nat");
+				comp.emit_nat();
 				break;
 
 			case O_REASS:
-				comp.loadStub("reass");
+				comp.emit_reass();
 				break;
 
 			default:



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