Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Aug 2014 10:37:03 GMT
From:      dpl@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r272264 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw
Message-ID:  <201408121037.s7CAb3if074243@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dpl
Date: Tue Aug 12 10:37:03 2014
New Revision: 272264
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272264

Log:
  Added the pullup_failed basic block

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	Tue Aug 12 09:48:54 2014	(r272263)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc	Tue Aug 12 10:37:03 2014	(r272264)
@@ -48,6 +48,11 @@
 	Type *int32Ty;
 	PointerType *int8PtrTy;
 
+	// Basic blocks used
+	BasicBlock *entry;
+	BasicBlock *pullup_failed;
+	BasicBlock *startiter;
+
 	// JIT Compiled Vars
 	// Loop control.
 	Value *match;
@@ -108,6 +113,9 @@
 	Function *set_match;
 	Function *jump_fast;
 
+	// Not pkg-filtering related funcs.
+	Function *printf;
+
 	// Used structs
 	StructType *ifnetTy;
 	StructType *in_addrTy;
@@ -122,7 +130,8 @@
 	StructType *ucredTy;
 
 	// Load the bc for JIT compilation.
-	Module *loadbc(std::string name)
+	Module *
+	loadbc(std::string name)
 	{
 		error_code ec = MemoryBuffer::getFile(name, buffer);
 		if (ec) {
@@ -141,7 +150,7 @@
 	}
 
 	// Create the needed variables to perform pkt filtering.
-	int
+	void
 	setEnv(struct ip_fw_args *args, struct ip_fw_chain *chain)
 	{
 		// Get Type objects
@@ -265,6 +274,37 @@
 		return (0);
 	}
 
+	void
+	emit_pullup_failed()
+	{
+		GlobalValue *is_verbose, *str;
+		BasicBlock *print, *ret;
+
+		// VNET_DECLARE(int, fw_verbose);
+		// #define	V_fw_verbose		VNET(fw_verbose)
+		// We should be fine getting that from the Module.
+
+		// pullup_failed:
+		// 	if (V_fw_verbose)
+		// 		printf("ipfw: pullup failed\n");
+		// 	return (IP_FW_DENY);
+
+		irb.SetInsertPoint(pullup_failed);
+		is_verbose = mod.getGlobalVariable("fw_verbose");
+		str = irb.CreateGlobalString("ipfw: pullup failed\n");
+
+		// if (V_fw_verbose)
+		CreateCondBr(CreateICmpEQ(is_verbose, ConstantInt::get(int32Ty, 0)), ret, print);
+		// printf("ipfw: pullup failed\n");
+		irb.SetInsertPoint(print);
+		irb.CreateCall(printf, str);
+		irb.CreateBr(ret);
+
+		// return (IP_FW_DENY);
+		irb.SetInsertPoint(ret);
+		irb.CreateRet(ConstantInt::get(int32Ty, IP_FW_DENY));
+	}
+
 	public:
 	ipfwJIT(struct ip_fw_args *args, struct ip_fw_chain *chain): irb(con)
 	{
@@ -273,15 +313,22 @@
 
 		func = mod->getFunction("ipfw_chk_jit");
 		func->setLinkage(GlobalValue::ExternalLinkage);
-		// Create the entry point of the function
-		BasicBlock *entry = BasicBlock::Create(con, "entry", func);
-		// Add the entry block to ArrayRef
-		blocks.push_back(entry);
-		// Set the IRBuilder to insert instructions after the basic block.
+
+		printf = mod->getFunction("printf");
+
+		// Create first BasicBlocks.
+		entry = BasicBlock::Create(con, "entry", func);
+		pullup_failed = BasicBlock::Create(con, "pullup_failed", func);
+		startiter = BasicBlock::Create(con, "startiter", 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);
+
 		// Get struct types, and store vars
 		setEnv(args, chain);
-		// Create the code related to the pullup_failed Basic Block.
 	}
 	~ipfwJIT()
 	{



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