Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Aug 2014 13:57:03 GMT
From:      dpl@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r272364 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw
Message-ID:  <201408131357.s7DDv3bB020129@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dpl
Date: Wed Aug 13 13:57:02 2014
New Revision: 272364
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272364

Log:
  Finished allocating and initializing variables.

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

Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc
==============================================================================
--- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc	Wed Aug 13 13:55:48 2014	(r272363)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc	Wed Aug 13 13:57:02 2014	(r272364)
@@ -18,6 +18,7 @@
 extern "C" {
 #include <glue.h>
 #include <missing.h>
+#include <err.h>
 
 #include <sys/mbuf.h>
 #include <sys/types.h>
@@ -55,8 +56,12 @@
 	BasicBlock *entry;
 	BasicBlock *pullup_failed;
 	BasicBlock *startrules;
+	BasicBlock *check_tag;
 
 	// JIT Compiled Vars
+	// These are the function arguments.
+	Value *argsptr;
+	Value *chainptr;
 	// Loop control.
 	Value *match;
 	Value *l;
@@ -169,6 +174,17 @@
 	void
 	setEnv(struct ip_fw_args *args, struct ip_fw_chain *chain)
 	{
+		// Get function arguments.
+		// (struct ip_fw_args *, struct ip_fw_chain *)
+		auto& arglist = func->getArgumentList();
+
+		// Error
+		if (arglist.size() != 2)
+			err(1, "Compilation error: no correct parameters\n");
+
+		argsptr = &arglist.front();
+		chainptr = &arglist.back();
+
 		// Get Type objects
 		int8Ty = Type::getInt8Ty(con);
 		int16Ty = Type::getInt16Ty(con);
@@ -206,8 +222,35 @@
 #ifdef __FreeBSD__
 		ucredPtrTy = PointerType::get(ucredTy, 0);
 #endif
+		// Get Function defs from bitcode.
+		// All of them are auxiliary functions.
+		inspect_pkt = mod->getFunction("inspect_pkt");
+		is_icmp_query = mod->getFunction("is_icmp_query");
+		flags_match = mod->getFunction("flags_match");
+		ipopts_match = mod->getFunction("ipopts_match");
+		tcpopts_match = mod->getFunction("tcpopts_match");
+		iface_match = mod->getFunction("iface_match");
+		verify_path = mod->getFunction("verify_path");
 
-		// Allocate vars.
+#ifdef INET6
+		icmp6type_match = mod->getFunction("icmp6type_match");
+		search_ip6_addr_net = mod->getFunction("search_ip6_addr_net");
+		flow6id_match = mod->getFunction("flow6id_match");
+		verify_path6 = mod->getFunction("verify_path6");
+		is_icmp6_query = mod->getFunction("is_icmp6_query");
+		send_reject6 = mod->getFunction("send_reject6");
+#endif /* INET6 */
+
+		send_reject = mod->getFunction("send_reject");
+		check_uidgid = mod->getFunction("check_uidgid");
+		set_match = mod->getFunction("set_match");
+		jump_fast = mod->getFunction("jump_fast");
+	}
+
+	// Allocate and initialize vars.
+	void
+	allocaAndInit(struct ip_fw_args *args, struct ip_fw_chain *chain)
+	{
 		match = irb.CreateAlloca(int32Ty);
 		l = irb.CreateAlloca(int32Ty);
 		done = irb.CreateAlloca(int32Ty);
@@ -217,11 +260,13 @@
 		retval = irb.CreateAlloca(int32Ty);
 		irb.CreateStore(ConstantInt::get(int32Ty, 0), retval);
 
-		m = irb.CreateAlloca(mbufPtrTy); // Init: args->m
-		// XXX m = args->m
+		// m = args->m (idx: 0)
+		m = irb.CreateAlloca(mbufPtrTy);
+		irb.CreateStore(irb.CreateInBoundsGEP(argsptr, ConstantInt::get(int32Ty, 0)), m);
 
+		// ip = (struct ip *)((m)->m_data) (idx: 2)
 		ip = irb.CreateAlloca(ipPtrTy);
-		// XXX ip = (struct ip *)((m)->m_data);
+		irb.CreateStore(irb.CreateBitCast(irb.CreateInBoundsGEP(argsptr, ConstantInt::get(int32Ty, 2)), ipPtrTy), ip);
 
 #ifdef __FreeBSD__
 		ucred = irb.CreateAlloca(ucredPtrTy); // Init: NULL if type ucred.
@@ -244,26 +289,33 @@
 		ip6f_mf = irb.CreateAlloca(int16Ty);
 		irb.CreateStore(ConstantInt::get(int16Ty, 0), ip6f_mf);
 
+		// proto = args->f_id.proto = 0
+		// proto = 0;
 		proto = irb.CreateAlloca(int8Ty);
 		irb.CreateStore(ConstantInt::get(int8Ty, 0), proto);
-		// XXX proto = args->f_id.proto = 0
+		// args->f_id.proto = 0 (idx: 6, 5)
+		irb.CreateStore(ConstantInt::get(int8Ty, 0), irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 6), ConstantInt::get(int32Ty, 5)} ));
 
 		src_port = irb.CreateAlloca(int16Ty);
 		irb.CreateStore(ConstantInt::get(int16Ty, 0), src_port);
 		dst_port = irb.CreateAlloca(int16Ty);
 		irb.CreateStore(ConstantInt::get(int16Ty, 0), dst_port);
 
+		//src_ip.s_addr = 0;
 		src_ip = irb.CreateAlloca(in_addrTy);
-		dst_ip = irb.CreateAlloca(in_addrTy);
-		// XXX
+		irb.CreateStore(ConstantInt::get(int32Ty, 0), irb.CreateInBoundsGEP(src_ip, ConstantInt::get(int32Ty, 0)));
 		//dst_ip.s_addr = 0;
-		//src_ip.s_addr = 0;
+		dst_ip = irb.CreateAlloca(in_addrTy);
+		irb.CreateStore(ConstantInt::get(int32Ty, 0), irb.CreateInBoundsGEP(dst_ip, ConstantInt::get(int32Ty, 0)));
 
 		iplen = irb.CreateAlloca(int16Ty);
 		irb.CreateStore(ConstantInt::get(int16Ty, 0), iplen);
 
+		// pktlen = m->m_pkthdr.len;
+		// m_pkthdr is the 6th element (idx: 5)
+		// len is the 2nd element (idx: 1)
 		pktlen = irb.CreateAlloca(int32Ty);
-		//XXX pktlen = m->m_pkthdr.len;
+		irb.CreateStore(ConstantInt::get(int32Ty, 0), irb.CreateInBoundsGEP(m, {ConstantInt::get(int32Ty, 5), ConstantInt::get(int32Ty, 1)} ));
 
 		etype = irb.CreateAlloca(int16Ty);
 		irb.CreateStore(ConstantInt::get(int32Ty, 0), etype);
@@ -286,30 +338,6 @@
 		irb.CreateStore(ConstantInt::get(int8Ty, 0), icmp6_type);
 		ext_hd = irb.CreateAlloca(int16Ty);
 		irb.CreateStore(ConstantInt::get(int16Ty, 0), ext_hd);
-
-		// Get Function defs from bitcode.
-		// All of them are auxiliary functions.
-		inspect_pkt = mod->getFunction("inspect_pkt");
-		is_icmp_query = mod->getFunction("is_icmp_query");
-		flags_match = mod->getFunction("flags_match");
-		ipopts_match = mod->getFunction("ipopts_match");
-		tcpopts_match = mod->getFunction("tcpopts_match");
-		iface_match = mod->getFunction("iface_match");
-		verify_path = mod->getFunction("verify_path");
-
-#ifdef INET6
-		icmp6type_match = mod->getFunction("icmp6type_match");
-		search_ip6_addr_net = mod->getFunction("search_ip6_addr_net");
-		flow6id_match = mod->getFunction("flow6id_match");
-		verify_path6 = mod->getFunction("verify_path6");
-		is_icmp6_query = mod->getFunction("is_icmp6_query");
-		send_reject6 = mod->getFunction("send_reject6");
-#endif /* INET6 */
-
-		send_reject = mod->getFunction("send_reject");
-		check_uidgid = mod->getFunction("check_uidgid");
-		set_match = mod->getFunction("set_match");
-		jump_fast = mod->getFunction("jump_fast");
 	}
 
 	void
@@ -354,19 +382,18 @@
 
 		printfFunc = mod->getFunction("printf");
 
-		// Create first BasicBlocks.
+		// Create statics BasicBlocks.
 		entry = BasicBlock::Create(con, "entry", func);
 		pullup_failed = BasicBlock::Create(con, "pullup_failed", func);
+		check_tag = BasicBlock::Create(con, "check_tag", func);
 		startrules = BasicBlock::Create(con, "startrules", func);
 
-		// Create the code related to the pullup_failed Basic Block.
 		emit_pullup_failed();
-
-		// Set the IRBuilder to insert instructions after the entry BB.
-		irb.SetInsertPoint(entry);
+		emit_check_tag();
 
 		// Get struct types, and store vars
-		setEnv(args, chain);
+		setEnv();
+		allocaAndInit(args, chain);
 	}
 	~ipfwJIT()
 	{
@@ -393,7 +420,7 @@
 	{
 		// If it returns one, goto pullup_failed.
 		// Else, goto starrules.
-		irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateCall(inspect_pkt), ConstantInt::get(int32Ty, 1)), pullup_failed, startrules);
+		irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateCall(inspect_pkt, {argsptr, ip, m, src_ip, dst_ip, src_port, dst_port, etype, ext_hd, iplen, pktlen, is_ipv4, is_ipv6, hlen, proto, icmp6_type, ip6f_mf, offset, ulp}), ConstantInt::get(int32Ty, 1)), pullup_failed, startrules);
 		return (0);
 	}
 



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