socsvn commit: r273620 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw

dpl at FreeBSD.org dpl at FreeBSD.org
Thu Sep 4 12:25:33 UTC 2014


Author: dpl
Date: Thu Sep  4 12:25:32 2014
New Revision: 273620
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273620

Log:
  Added boilerplate for code generation.

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	Thu Sep  4 11:15:38 2014	(r273619)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc	Thu Sep  4 12:25:32 2014	(r273620)
@@ -184,12 +184,13 @@
 	}
 
 	BasicBlock*
-	nextRule(int num)
+	nextRule()
 	{
-		if (num >= rules.size())
+		int nextn = rulenumber+1;
+		if (nextn >= rules.size())
 			return (End);
 		else
-			return (rules[num]);
+			return (rules[nextn]);
 	}
 
 	// Create the needed variables to perform pkt filtering.
@@ -393,8 +394,8 @@
 			Dst_ip, Src_port, Dst_port, Etype, Ext_hd, Iplen, Pktlen, Is_ipv4,
 			Is_ipv6, Hlen, Proto, Icmp6_type, Ip6f_mf, Offset, UlpL});
 
-		Value *Cond = Irb.CreateICmpEQ(InspectPktCall, ConstantInt::get(Int32Ty, 1));
-		Irb.CreateCondBr(Cond, PullupFailed, CheckTag);
+		Value *Comp = Irb.CreateICmpEQ(InspectPktCall, ConstantInt::get(Int32Ty, 1));
+		Irb.CreateCondBr(Comp, PullupFailed, CheckTag);
 	}
 
 	// This is equivalent to the pullup_failed tag.
@@ -643,7 +644,7 @@
 
 		Irb.SetInsertPoint(jt);
 		//		continue;
-		Irb.CreateBr(nextRule(rulenumber+1));
+		Irb.CreateBr(nextRule());
 
 		// skip_or = 0;
 		Irb.SetInsertPoint(jf);
@@ -715,7 +716,7 @@
 
 		Irb.SetInsertPoint(secondf);
 		// continue;
-		Irb.CreateBr(nextRule(rulenumber+1));
+		Irb.CreateBr(nextRule());
 
 		Irb.SetInsertPoint(firstf);
 		// match = 0;
@@ -808,7 +809,7 @@
 		//     break;
 		AndOp = Irb.CreateAnd(LenL, ConstantInt::get(Int8Ty, F_OR));
 		Comp = Irb.CreateICmpEQ(AndOp, ConstantInt::get(Int8Ty, 0));
-		Irb.CreateCondBr(Comp, nextRule(rulenumber+1) /* break */, Continue);
+		Irb.CreateCondBr(Comp, nextRule() /* break */, Continue);
 		
 		Irb.SetInsertPoint(Continue);
 	}
@@ -828,7 +829,7 @@
 		//		break;
 		Value *DoneL = Irb.CreateLoad(Done);
 		Value *Comp = Irb.CreateICmpNE(DoneL, ConstantInt::get(Int32Ty, 0));
-		Irb.CreateCondBr(Comp, End, nextRule(rulenumber+1));
+		Irb.CreateCondBr(Comp, End, nextRule());
 	}
 
 
@@ -945,6 +946,8 @@
 	void
 	emit_nop()
 	{
+			//break;
+			Irb.CreateBr(nextRule());
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 1), Match);
 	}
 
@@ -954,29 +957,54 @@
 		printf("Compilation error:\n");
 		printf("ipfwjitter: opcode %d unimplemented\n", opcode);
 		printf("Compilation continues.\n");
+		//break;
+		Irb.CreateBr(nextRule());
 	}
 
 	// check_uidgid() returns 0 on userspace.
 	void
 	emit_jail()
 	{
-		// /*
-		//  * We only check offset == 0 && proto != 0,
-		//  * as this ensures that we have a
-		//  * packet with the ports info.
-		//  */
+		BasicBlock *OffsetNZ = BasicBlock::Create(*Con, "offsetnotzero", Func);
+		BasicBlock *OffsetZE = BasicBlock::Create(*Con, "offsetiszero", Func);
+		BasicBlock *TCPorUDP = BasicBlock::Create(*Con, "setmatchzero", Func);
+		BasicBlock *Continue = BasicBlock::Create(*Con, "Continue", Func);
+		Value *Comp;
+
 		// if (offset != 0)
-		//		return;
+		//		break;
 		// if (proto == IPPROTO_TCP ||
 		// 	proto == IPPROTO_UDP)
 		//		*match = 0;
 
 		// if (offset != 0)
-		//		return;
+		//		break;
+		Value *OffsetL = Irb.CreateLoad(Offset);
+		Comp = Irb.CreateICmpNE(OffsetL, ConstantInt::get(Int16Ty, 0));
+		Irb.CreateCondBr(Comp, OffsetNZ, OffsetZE);
+
+		Irb.SetInsertPoint(OffsetNZ);
+		// Go to next rule.
+		Irb.CreateBr(nextRule());
 
 		// if (proto == IPPROTO_TCP ||
 		// 	proto == IPPROTO_UDP)
 		//		*match = 0;
+		Irb.SetInsertPoint(OffsetZE);
+		Value *ProtoL = Irb.CreateLoad(Proto);
+		Comp = Irb.CreateICmpEQ(OffsetL, ConstantInt::get(Int8Ty, IPPROTO_TCP));
+		Value *Comp2 = Irb.CreateICmpEQ(OffsetL, ConstantInt::get(Int8Ty, IPPROTO_UDP));
+		Irb.CreateCondBr(Comp, TCPorUDP, Continue);
+		Irb.CreateCondBr(Comp2, TCPorUDP, Continue);
+
+		Irb.SetInsertPoint(TCPorUDP);
+		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Match);
+		Irb.CreateBr(Continue);
+
+		// Keep on with the for epilogue.
+		Irb.SetInsertPoint(Continue);
+		//break;
+		Irb.CreateBr(nextRule());
 	}
 
 	void
@@ -987,6 +1015,8 @@
 		Value *cmdc = Irb.CreateBitCast(Cmd, Ipfw_insn_ifPtrTy);
 		Value *IfaceMatchCall = Irb.CreateCall4(Iface_match, rcvif, cmdc, Chain, Tablearg);
 		Irb.CreateStore(IfaceMatchCall, Match);
+		//break;
+		Irb.CreateBr(nextRule());
 	}
 
 	void
@@ -996,6 +1026,602 @@
 		Value *Cmdc = Irb.CreateBitCast(Cmd, Ipfw_insn_ifPtrTy);
 		Value *IfaceMatchCall = Irb.CreateCall4(Iface_match, Oif, Cmdc, Chain, Tablearg);
 		Irb.CreateStore(IfaceMatchCall, Match);
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_via()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_macaddr2()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_mac_type()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_frag()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_in()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_layer2()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_diverted()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_proto()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip_src()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip_dst_lookup()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip_dst_mask()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip_src_me()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip6_src_me()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip_src_set()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip_dst()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip_dst_me()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip6_dst_me()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip_dstport()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_icmptype()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_icmp6type()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ipopt()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ipver()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ipttl()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ipprecedence()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_iptos()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_dscp()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_tcpdatalen()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_tcpflags()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_tcpopts()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_tcpseq()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_tcpack()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_tcpwin()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_estab()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_altq()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_log()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_prob()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_verrevpath()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_versrcreach()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_antispoof()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ipsec()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip6_src()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip6_dst()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip6_dst_mask()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_flow6id()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ext_hdr()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip6()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ip4()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_tag()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_fib()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_sockarg()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_tagged()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	/*
+	 * The second set of opcodes represents 'actions',
+	 * i.e. the terminal part of a rule once the packet
+	 * matches all previous patterns.
+	 * Typically there is only one action for each rule,
+	 * and the opcode is stored at the end of the rule
+	 * (but there are exceptions -- see below).
+	 *
+	 * In general, here we set retval and terminate the
+	 * outer loop (would be a 'break 3' in some language,
+	 * but we need to set l=0, done=1)
+	 *
+	 * Exceptions:
+	 * O_COUNT and O_SKIPTO actions:
+	 *   instead of terminating, we jump to the next rule
+	 *   (setting l=0), or to the SKIPTO target (setting
+	 *   f/f_len, cmd and l as needed), respectively.
+	 *
+	 * O_TAG, O_LOG and O_ALTQ action parameters:
+	 *   perform some action and set match = 1;
+	 *
+	 * O_LIMIT and O_KEEP_STATE: these opcodes are
+	 *   not real 'actions', and are stored right
+	 *   before the 'action' part of the rule.
+	 *   These opcodes try to install an entry in the
+	 *   state tables; if successful, we continue with
+	 *   the next opcode (match=1; break;), otherwise
+	 *   the packet must be dropped (set retval,
+	 *   break loops with l=0, done=1)
+	 *
+	 * O_PROBE_STATE and O_CHECK_STATE: these opcodes
+	 *   cause a lookup of the state table, and a jump
+	 *   to the 'action' part of the parent rule
+	 *   if an entry is found, or
+	 *   (CHECK_STATE only) a jump to the next rule if
+	 *   the entry is not found.
+	 *   The result of the lookup is cached so that
+	 *   further instances of these opcodes become NOPs.
+	 *   The jump to the next rule is done by setting
+	 *   l=0, cmdlen=0.
+	 */
+
+	void
+	emit_keep_state()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_check_state()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_accept()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_queue()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_tee()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_count()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_skipto()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_callreturn()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_reject()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_unreach6()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_deny()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_forward_ip()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_forward_ip6()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_ngtee()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_setfib()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_setdscp()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_nat()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
+	}
+
+	void
+	emit_reass()
+	{
+
+		//break;
+		Irb.CreateBr(nextRule());
 	}
 };
 
@@ -1054,7 +1680,6 @@
 				compiler.emit_xmit();
 				break;
 
-/* XXX
 			case O_VIA:
 				compiler.emit_via();
 				break;
@@ -1105,7 +1730,6 @@
 				compiler.emit_ip_src_me();
 #ifdef INET6
 				/* FALLTHROUGH */
-/* XXX
 			case O_IP6_SRC_ME:
 				compiler.emit_ip6_src_me();
 #endif
@@ -1125,7 +1749,6 @@
 				
 #ifdef INET6
 				/* FALLTHROUGH */
-/* XXX
 			case O_IP6_DST_ME:
 				compiler.emit_ip6_dst_me();
 #endif
@@ -1146,7 +1769,6 @@
 				compiler.emit_icmp6type();
 				break;
 #endif /* INET6 */
-/*
 			case O_IPOPT:
 				compiler.emit_ipopt();
 				break;
@@ -1230,7 +1852,6 @@
 				compiler.emit_ipsec();
 #endif
 				/* otherwise no match */
-/* XXX
 				break;
 
 #ifdef INET6
@@ -1269,7 +1890,6 @@
 				break;
 
 			case O_FIB: /* try match the specified fib */
-/* XXX
 				compiler.emit_fib();
 				break;
 
@@ -1322,7 +1942,6 @@
 			 *   The jump to the next rule is done by setting
 			 *   l=0, cmdlen=0.
 			 */
-/* XXX
 			case O_LIMIT:
 			case O_KEEP_STATE:
 				compiler.emit_keep_state();
@@ -1356,22 +1975,18 @@
 			    continue;
 			    break;	/* NOTREACHED */
 
-/* XXX
 			case O_CALLRETURN:
 				compiler.emit_callreturn();
 				continue;
 				break;	/* NOTREACHED */
-/* XXX
 
 			case O_REJECT:
 				compiler.emit_reject();
 				/* FALLTHROUGH */
-/* XXX
 #ifdef INET6
 			case O_UNREACH6:
 				compiler.emit_unreach6();
 				/* FALLTHROUGH */
-/* XXX
 #endif
 			case O_DENY:
 				compiler.emit_deny();
@@ -1408,7 +2023,6 @@
 				compiler.emit_reass();
 				break;
 
-			*/
 			default:
 				panic("-- unknown opcode %d\n", cmd->opcode);
 			} /* end of switch() on opcodes */


More information about the svn-soc-all mailing list