Date: Fri, 29 Aug 2014 17:33:09 GMT From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273338 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw Message-ID: <201408291733.s7THX9F6091610@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dpl Date: Fri Aug 29 17:33:08 2014 New Revision: 273338 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273338 Log: Style 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 Fri Aug 29 14:47:05 2014 (r273337) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Fri Aug 29 17:33:08 2014 (r273338) @@ -46,127 +46,127 @@ class ipfwJIT { Module *mod; - Function *func; - LLVMContext con; - IRBuilder<> irb; + Function *Func; + LLVMContext Con; + IRBuilder<> Irb; // We'll store the BasicBlock objects for each rule here. int rulenumber = 0; std::vector<BasicBlock *> rules; // Vars Types - Type *int8Ty; - Type *int16Ty; - Type *int32Ty; - Type *int64Ty; - PointerType *int8PtrTy; + Type *Int8Ty; + Type *Int16Ty; + Type *Int32Ty; + Type *Int64Ty; + PointerType *Int8PtrTy; // Basic blocks used - BasicBlock *entry, *end; - BasicBlock *pullup_failed; - BasicBlock *check_tag; - BasicBlock *outer_for_prologue; - BasicBlock *inner_for_prologue; - BasicBlock *outer_for_epilogue; - BasicBlock *inner_for_epilogue; + BasicBlock *Entry, *End; + BasicBlock *Pullup_failed; + BasicBlock *Check_tag; + BasicBlock *Outer_for_prologue; + BasicBlock *Inner_for_prologue; + BasicBlock *Outer_for_epilogue; + BasicBlock *Inner_for_epilogue; // JIT Compiled Vars // These are the function arguments. - Value *args; - Value *chain; + Value *Args; + Value *Chain; // Loop control. - Value *match; - Value *l; - Value *done; - Value *f_pos; - Value *retval; - Value *cmd; - Value *cmdlen; - Value *tablearg; - Value *skip_or; - Value *f; + Value *Match; + Value *L; + Value *Done; + Value *F_pos; + Value *Retval; + Value *Cmd; + Value *Cmdlen; + Value *Tablearg; + Value *Skip_or; + Value *F; // Packet matching variables. - Value *m; - Value *ip; - Value *ucred_cache; - Value *ucred_lookup; - Value *oif; - Value *hlen; //unsigned - Value *offset; //unsigned - Value *ip6f_mf; //unsigned + Value *MPtr; + Value *IpPtr; + Value *Ucred_cache; + Value *Ucred_lookup; + Value *Oif; + Value *Hlen; //unsigned + Value *Offset; //unsigned + Value *Ip6f_mf; //unsigned // Local copies of vars. // On optimization, unused ones will not be included. - Value *proto; //unsigned - Value *src_port; //unsigned - Value *dst_port; //unsigned - Value *src_ip; - Value *dst_ip; - Value *iplen; //unsigned - Value *pktlen; - Value *etype; //unsigned - Value *dyn_dir; - Value *q; - Value *ulp; - - Value *is_ipv4; - Value *is_ipv6; - Value *icmp6_type; //unsigned - Value *ext_hd; //unsigned + Value *Proto; //unsigned + Value *Src_port; //unsigned + Value *Dst_port; //unsigned + Value *Src_ip; + Value *Dst_ip; + Value *Iplen; //unsigned + Value *Pktlen; + Value *Etype; //unsigned + Value *Dyn_dir; + Value *Q; + Value *Ulp; + + Value *Is_ipv4; + Value *Is_ipv6; + Value *Icmp6_type; //unsigned + Value *Ext_hd; //unsigned // This sets up some vars, at star time. - Function *inspect_pkt; + Function *InspectPkt; // Auxiliary functions used by our JITed code. // All this are used from our bitcode. - Function *is_icmp_query; - Function *flags_match; - Function *ipopts_match; - Function *tcpopts_match; - Function *iface_match; - Function *verify_path; + Function *Is_icmp_query; + Function *Flags_match; + Function *Ipopts_match; + Function *Tcpopts_match; + Function *Iface_match; + Function *Verify_path; #ifdef INET6 - Function *icmp6type_match; - Function *search_ip6_addr_net; - Function *flow6id_match; - Function *verify_path6; - Function *is_icmp6_query; - Function *send_reject6; + Function *Icmp6type_match; + Function *Search_ip6_addr_net; + Function *Flow6id_match; + Function *Verify_path6; + Function *Is_icmp6_query; + Function *Send_reject6; #endif /* INET6 */ - Function *send_reject; - Function *set_match; - Function *jump_fast; + Function *Send_reject; + Function *Set_match; + Function *Jump_fast; // Not pkg-filtering related funcs. - Function *printfFunc; - Function *ipfw_find_rule; + Function *PrintfFunc; + Function *Ipfw_find_rule; // Used structs. - StructType *ifnetTy; - StructType *in_addrTy; - StructType *ipTy; - StructType *ip_fw_argsTy; - StructType *ip_fw_chainTy; - StructType *ip_fwTy; - StructType *ipfw_insnTy; - StructType *ipfw_dyn_ruleTy; - StructType *ipfw_insn_ifTy; - StructType *mbufTy; - StructType *ucredTy; + StructType *IfnetTy; + StructType *In_addrTy; + StructType *IpTy; + StructType *Ip_fw_argsTy; + StructType *Ip_fw_chainTy; + StructType *Ip_fwTy; + StructType *Ipfw_insnTy; + StructType *Ipfw_dyn_ruleTy; + StructType *Ipfw_insn_ifTy; + StructType *MbufTy; + StructType *UcredTy; // Pointer to structs type. - PointerType *ifnetPtrTy; - PointerType *in_addrPtrTy; - PointerType *ipPtrTy; - PointerType *ip_fw_argsPtrTy; - PointerType *ip_fw_chainPtrTy; - PointerType *ip_fwPtrTy; - PointerType *ipfw_insnPtrTy; - PointerType *ipfw_dyn_rulePtrTy; - PointerType *ipfw_insn_ifPtrTy; - PointerType *mbufPtrTy; - PointerType *ucredPtrTy; + PointerType *IfnetPtrTy; + PointerType *In_addrPtrTy; + PointerType *IpPtrTy; + PointerType *Ip_fw_argsPtrTy; + PointerType *Ip_fw_chainPtrTy; + PointerType *Ip_fwPtrTy; + PointerType *Ipfw_insnPtrTy; + PointerType *Ipfw_dyn_rulePtrTy; + PointerType *Ipfw_insn_ifPtrTy; + PointerType *MbufPtrTy; + PointerType *UcredPtrTy; // Load the bc for JIT compilation. Module * @@ -178,7 +178,7 @@ return (NULL); } - auto modptr = parseBitcodeFile(buffer.get().get(), con); + auto modptr = parseBitcodeFile(buffer.get().get(), Con); if ((modptr.getError())){ std::cerr << "Failed to parse bitcode: " << buffer.getError() << "\n"; return (NULL); @@ -190,7 +190,7 @@ nextRule(int num) { if (num >= rules.size()) - return (end); + return (End); else return (rules[num]); } @@ -201,79 +201,79 @@ { // Get function arguments. // (struct ip_fw_args *, struct ip_fw_chain *) - auto& arglist = func->getArgumentList(); + auto& arglist = Func->getArgumentList(); // Error if (arglist.size() != 2) err(1, "Compilation error: no correct parameters\n"); - args = &arglist.front(); - chain = &arglist.back(); + Args = &arglist.front(); + Chain = &arglist.back(); // Get Type objects - int8Ty = Type::getInt8Ty(con); - int16Ty = Type::getInt16Ty(con); - int32Ty = Type::getInt32Ty(con); - int64Ty = Type::getInt64Ty(con); - int8PtrTy = PointerType::getUnqual(int8Ty); + Int8Ty = Type::getInt8Ty(Con); + Int16Ty = Type::getInt16Ty(Con); + Int32Ty = Type::getInt32Ty(Con); + Int64Ty = Type::getInt64Ty(Con); + Int8PtrTy = PointerType::getUnqual(Int8Ty); // Get StrucType from bitcode. - mbufTy = mod->getTypeByName("struct.mbuf"); - ifnetTy = mod->getTypeByName("struct.ifnet"); - in_addrTy = mod->getTypeByName("struct.in_addr"); - ipTy = mod->getTypeByName("struct.ip"); - ip_fw_argsTy = mod->getTypeByName("struct.ip_fw_args"); - ip_fw_chainTy = mod->getTypeByName("struct.ip_fw_chain"); - ip_fwTy = mod->getTypeByName("struct.ip_fw"); - ipfw_insnTy = mod->getTypeByName("struct._ipfw_insn"); - ipfw_insn_ifTy = mod->getTypeByName("struct._ipfw_insn_if"); - ipfw_dyn_ruleTy = mod->getTypeByName("struct._ipfw_dyn_rule"); + MbufTy = mod->getTypeByName("struct.mbuf"); + IfnetTy = mod->getTypeByName("struct.ifnet"); + In_addrTy = mod->getTypeByName("struct.in_addr"); + IpTy = mod->getTypeByName("struct.ip"); + Ip_fw_argsTy = mod->getTypeByName("struct.ip_fw_args"); + Ip_fw_chainTy = mod->getTypeByName("struct.ip_fw_chain"); + Ip_fwTy = mod->getTypeByName("struct.ip_fw"); + Ipfw_insnTy = mod->getTypeByName("struct._ipfw_insn"); + Ipfw_insn_ifTy = mod->getTypeByName("struct._ipfw_insn_if"); + Ipfw_dyn_ruleTy = mod->getTypeByName("struct._ipfw_dyn_rule"); #ifdef __FreeBSD__ - ucredTy = mod->getTypeByName("struct.ucred"); + UcredTy = mod->getTypeByName("struct.ucred"); #else - ucredTy = mod->getTypeByName("struct.bsd_ucred"); + UcredTy = mod->getTypeByName("struct.bsd_ucred"); #endif /* __FreeBSD__ */ // Create Pointer to StructType types. - mbufPtrTy = PointerType::getUnqual(mbufTy); - ifnetPtrTy = PointerType::getUnqual(ifnetTy); - in_addrPtrTy = PointerType::getUnqual(in_addrTy); - ipPtrTy = PointerType::getUnqual(ipTy); - ip_fw_argsPtrTy = PointerType::getUnqual(ip_fw_argsTy); - ip_fw_chainPtrTy = PointerType::getUnqual(ip_fw_chainTy); - ip_fwPtrTy = PointerType::getUnqual(ip_fwTy); - ipfw_insnPtrTy = PointerType::getUnqual(ipfw_insnTy); - ipfw_insn_ifPtrTy = PointerType::getUnqual(ipfw_insn_ifTy); - ipfw_dyn_rulePtrTy = PointerType::getUnqual(ipfw_dyn_ruleTy); + MbufPtrTy = PointerType::getUnqual(MbufTy); + IfnetPtrTy = PointerType::getUnqual(IfnetTy); + In_addrPtrTy = PointerType::getUnqual(In_addrTy); + IpPtrTy = PointerType::getUnqual(IpTy); + Ip_fw_argsPtrTy = PointerType::getUnqual(Ip_fw_argsTy); + Ip_fw_chainPtrTy = PointerType::getUnqual(Ip_fw_chainTy); + Ip_fwPtrTy = PointerType::getUnqual(Ip_fwTy); + Ipfw_insnPtrTy = PointerType::getUnqual(Ipfw_insnTy); + Ipfw_insn_ifPtrTy = PointerType::getUnqual(Ipfw_insn_ifTy); + Ipfw_dyn_rulePtrTy = PointerType::getUnqual(Ipfw_dyn_ruleTy); #ifdef __FreeBSD__ - ucredPtrTy = PointerType::getUnqual(ucredTy); + UcredPtrTy = PointerType::getUnqual(UcredTy); #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"); + InspectPkt = 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"); + 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"); - set_match = mod->getFunction("set_match"); - jump_fast = mod->getFunction("jump_fast"); + Send_reject = mod->getFunction("send_reject"); + Set_match = mod->getFunction("set_match"); + Jump_fast = mod->getFunction("jump_fast"); // Functions declared at bitcode. - printfFunc = mod->getFunction("printf"); - ipfw_find_rule = mod->getFunction("ipfw_find_rule"); + PrintfFunc = mod->getFunction("printf"); + Ipfw_find_rule = mod->getFunction("ipfw_find_rule"); } // Allocate and initialize LLVM vars. @@ -282,114 +282,153 @@ void allocaAndInit() { - irb.SetInsertPoint(entry); + Irb.SetInsertPoint(Entry); // Control flow variables. - match = irb.CreateAlloca(int32Ty); - l = irb.CreateAlloca(int32Ty); + L = Irb.CreateAlloca(Int32Ty); - done = irb.CreateAlloca(int32Ty); - irb.CreateStore(ConstantInt::get(int32Ty, 0), done); + Done = Irb.CreateAlloca(Int32Ty); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Done); - f_pos = irb.CreateAlloca(int32Ty); - irb.CreateStore(ConstantInt::get(int32Ty, 0), f_pos); + F_pos = Irb.CreateAlloca(Int32Ty); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), F_pos); - retval = irb.CreateAlloca(int32Ty); - irb.CreateStore(ConstantInt::get(int32Ty, 0), retval); - - cmd = irb.CreateAlloca(ipfw_insnTy); - tablearg = irb.CreateAlloca(int32Ty); - cmdlen = irb.CreateAlloca(int32Ty); - skip_or = irb.CreateAlloca(int32Ty); - f = irb.CreateAlloca(ip_fwTy); + Retval = Irb.CreateAlloca(Int32Ty); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Retval); + + Cmd = Irb.CreateAlloca(Ipfw_insnTy); + Tablearg = Irb.CreateAlloca(Int32Ty); + Cmdlen = Irb.CreateAlloca(Int32Ty); + Skip_or = Irb.CreateAlloca(Int32Ty); + F = Irb.CreateAlloca(Ip_fwTy); // m = args->m (idx: 0) - m = irb.CreateAlloca(mbufPtrTy); - irb.CreateStore(irb.CreateLoad(irb.CreateStructGEP(args, 0)), m); + MPtr = Irb.CreateAlloca(MbufPtrTy); + Irb.CreateStore(Irb.CreateLoad(Irb.CreateStructGEP(Args, 0)), MPtr); + Value *M = Irb.CreateLoad(MPtr); // ip = (struct ip *)((m)->m_data) (idx: 2) - ip = irb.CreateAlloca(ipPtrTy); - irb.CreateStore(irb.CreateBitCast(irb.CreateStructGEP(irb.CreateLoad(m), 2), ipPtrTy), ip); + IpPtr = Irb.CreateAlloca(IpPtrTy); + Value *M_data = Irb.CreateStructGEP(M, 2); + Value *M_casted = Irb.CreateBitCast(M_data, IpPtrTy); + Irb.CreateStore(M_casted, IpPtr); - ucred_cache = irb.CreateAlloca(ucredTy); // Init: NULL if type ucred. + Ucred_cache = Irb.CreateAlloca(UcredTy); // Init: NULL if type ucred. - ucred_lookup = irb.CreateAlloca(int32Ty); - irb.CreateStore(ConstantInt::get(int32Ty, 0), ucred_lookup); + Ucred_lookup = Irb.CreateAlloca(Int32Ty); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Ucred_lookup); - oif = irb.CreateAlloca(ifnetTy); // Init: args->oif - irb.CreateLoad(irb.CreateStructGEP(args, 1), oif); + Oif = Irb.CreateAlloca(IfnetTy); // Init: args->oif + Irb.CreateLoad(Irb.CreateStructGEP(Args, 1), Oif); - hlen = irb.CreateAlloca(int32Ty); - irb.CreateStore(ConstantInt::get(int32Ty, 0), hlen); + Hlen = Irb.CreateAlloca(Int32Ty); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Hlen); - offset = irb.CreateAlloca(int16Ty); - irb.CreateStore(ConstantInt::get(int16Ty, 0), offset); + Offset = Irb.CreateAlloca(Int16Ty); + Irb.CreateStore(ConstantInt::get(Int16Ty, 0), Offset); - ip6f_mf = irb.CreateAlloca(int16Ty); - irb.CreateStore(ConstantInt::get(int16Ty, 0), ip6f_mf); + 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); + Proto = Irb.CreateAlloca(Int8Ty); + Irb.CreateStore(ConstantInt::get(Int8Ty, 0), Proto); // args->f_id.proto = 0 (idx: 6, 5) - irb.CreateStore(ConstantInt::get(int8Ty, 0), irb.CreateStructGEP(irb.CreateStructGEP(args, 6), 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); + Value *F_id = Irb.CreateStructGEP(Args, 6); + Value *Proto = Irb.CreateStructGEP(F_id, 5); + Irb.CreateStore(ConstantInt::get(Int8Ty, 0), Proto); + + 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); - irb.CreateStore(ConstantInt::get(int32Ty, 0), irb.CreateStructGEP(src_ip, 0)); + Src_ip = Irb.CreateAlloca(In_addrTy); + Value *Src_s_addr = Irb.CreateStructGEP(Src_ip, 0); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Src_s_addr); //dst_ip.s_addr = 0; - dst_ip = irb.CreateAlloca(in_addrTy); - irb.CreateStore(ConstantInt::get(int32Ty, 0), irb.CreateStructGEP(dst_ip, 0)); + Dst_ip = Irb.CreateAlloca(In_addrTy); + Value *Dst_s_addr = Irb.CreateStructGEP(Dst_ip, 0); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Dst_s_addr); //iplen = 0; - iplen = irb.CreateAlloca(int16Ty); - irb.CreateStore(ConstantInt::get(int16Ty, 0), iplen); + 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); - irb.CreateStore(irb.CreateStructGEP(irb.CreateStructGEP(irb.CreateLoad(m), 5), 1), pktlen); + Pktlen = Irb.CreateAlloca(Int32Ty); + Value *Header = Irb.CreateStructGEP(M, 5); + Value *LengthPtr = Irb.CreateStructGEP(Header, 1); + Value *Length = Irb.CreateLoad(LengthPtr); + Irb.CreateStore(Length, Pktlen); - etype = irb.CreateAlloca(int16Ty); - irb.CreateStore(ConstantInt::get(int32Ty, 0), etype); + Etype = Irb.CreateAlloca(Int16Ty); + Irb.CreateStore(ConstantInt::get(Int16Ty, 0), Etype); - dyn_dir = irb.CreateAlloca(int32Ty); - irb.CreateStore(ConstantInt::get(int32Ty, MATCH_UNKNOWN), dyn_dir); + Dyn_dir = Irb.CreateAlloca(Int32Ty); + Irb.CreateStore(ConstantInt::get(Int32Ty, MATCH_UNKNOWN), Dyn_dir); - q = irb.CreateAlloca(ipfw_dyn_rulePtrTy); - irb.CreateStore(ConstantPointerNull::get(ipfw_dyn_rulePtrTy), q); + Q = Irb.CreateAlloca(Ipfw_dyn_rulePtrTy); + Irb.CreateStore(ConstantPointerNull::get(Ipfw_dyn_rulePtrTy), Q); // There are no (void *), we use i8* - ulp = irb.CreateAlloca(int8PtrTy); - irb.CreateStore(ConstantPointerNull::get(int8PtrTy), ulp); + Ulp = Irb.CreateAlloca(Int8PtrTy); + Irb.CreateStore(ConstantPointerNull::get(Int8PtrTy), Ulp); - is_ipv4 = irb.CreateAlloca(int32Ty); - irb.CreateStore(ConstantInt::get(int32Ty, 0), is_ipv4); - is_ipv6 = irb.CreateAlloca(int32Ty); - irb.CreateStore(ConstantInt::get(int32Ty, 0), is_ipv6); - icmp6_type = irb.CreateAlloca(int8Ty); - irb.CreateStore(ConstantInt::get(int8Ty, 0), icmp6_type); - ext_hd = irb.CreateAlloca(int16Ty); - irb.CreateStore(ConstantInt::get(int16Ty, 0), ext_hd); + Is_ipv4 = Irb.CreateAlloca(Int32Ty); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Is_ipv4); + Is_ipv6 = Irb.CreateAlloca(Int32Ty); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Is_ipv6); + Icmp6_type = Irb.CreateAlloca(Int8Ty); + Irb.CreateStore(ConstantInt::get(Int8Ty, 0), Icmp6_type); + Ext_hd = Irb.CreateAlloca(Int16Ty); + Irb.CreateStore(ConstantInt::get(Int16Ty, 0), Ext_hd); // If it returns one, goto pullup_failed. // Else, goto first rule. - irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateCall(inspect_pkt, {args, 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, check_tag); + Value *Ip = Irb.CreateLoad(IpPtr); + + Args->getType()->dump(); + Ip->getType()->dump(); + M->getType()->dump(); + Src_ip->getType()->dump(); + Dst_ip->getType()->dump(); + Src_port->getType()->dump(); + Dst_port->getType()->dump(); + Etype->getType()->dump(); + Ext_hd->getType()->dump(); + Iplen->getType()->dump(); + Pktlen->getType()->dump(); + Is_ipv4->getType()->dump(); + Is_ipv6->getType()->dump(); + Hlen->getType()->dump(); + Proto->getType()->dump(); + Icmp6_type->getType()->dump(); + Ip6f_mf->getType()->dump(); + Offset->getType()->dump(); + Ulp->getType()->dump(); + + InspectPkt->dump(); + + Value *InspectPktCall = Irb.CreateCall(InspectPkt, {Args, 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}); + InspectPktCall->dump(); + + Value *Cond = Irb.CreateICmpEQ(InspectPktCall, ConstantInt::get(Int32Ty, 1)); + Irb.CreateCondBr(Cond, Pullup_failed, Check_tag); } void emit_pullup_failed() { - Value *is_verbose, *str; + Value *is_verbose, *str, *Conp; - BasicBlock *print = BasicBlock::Create(con, "print", func); - BasicBlock *ret = BasicBlock::Create(con, "ret", func); + BasicBlock *print = BasicBlock::Create(Con, "print", Func); + BasicBlock *ret = BasicBlock::Create(Con, "ret", Func); // VNET_DECLARE(int, fw_verbose); // #define V_fw_verbose VNET(fw_verbose) @@ -401,32 +440,35 @@ // return (IP_FW_DENY); is_verbose = mod->getGlobalVariable("fw_verbose"); - str = irb.CreateGlobalString("ipfw: pullup failed\n"); + str = Irb.CreateGlobalString("ipfw: pullup failed\n"); - irb.SetInsertPoint(pullup_failed); + Irb.SetInsertPoint(Pullup_failed); // if (V_fw_verbose) - irb.CreateCondBr(irb.CreateICmpEQ(is_verbose, ConstantInt::get(int32Ty, 0)), ret, print); + Comp = Irb.CreateICmpEQ(is_verbose, ConstantInt::get(Int32Ty, 0)); + Irb.CreateCondBr(Comp, ret, print); // printf("ipfw: pullup failed\n"); - irb.SetInsertPoint(print); - irb.CreateCall(printfFunc, str); - irb.CreateBr(ret); + Irb.SetInsertPoint(print); + Irb.CreateCall(PrintfFunc, str); + Irb.CreateBr(ret); // return (IP_FW_DENY); - irb.SetInsertPoint(ret); - irb.CreateRet(ConstantInt::get(int32Ty, IP_FW_DENY)); + Irb.SetInsertPoint(ret); + Irb.CreateRet(ConstantInt::get(Int32Ty, IP_FW_DENY)); } void emit_check_tag() { - BasicBlock *tagged = BasicBlock::Create(con, "tagged", func); - BasicBlock *nottagged = BasicBlock::Create(con, "nottagged", func); - BasicBlock *jt = BasicBlock::Create(con, "jt", func); - BasicBlock *jf = BasicBlock::Create(con, "jf", func); + BasicBlock *Tagged = BasicBlock::Create(Con, "tagged", Func); + BasicBlock *Nottagged = BasicBlock::Create(Con, "nottagged", Func); + BasicBlock *Jt = BasicBlock::Create(Con, "jt", Func); + BasicBlock *Jf = BasicBlock::Create(Con, "jf", Func); - irb.SetInsertPoint(check_tag); + Value *Comp; + + Irb.SetInsertPoint(Check_tag); // if (args->rule.slot) { // /* @@ -445,41 +487,52 @@ // } // if (args->rule.slot) - irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateInBoundsGEP(args, {ConstantInt::get(int32Ty, 0), ConstantInt::get(int32Ty, 4),ConstantInt::get(int32Ty, 0)}), ConstantInt::get(int32Ty, 0)), nottagged, tagged); + Value *Rule = Irb.CreateStructGEP(Args, 4); + Value *Slot = Irb.CreateStructGEP(Rule, 0); + Comp = Irb.CreateICmpEQ(Slot, ConstantInt::get(Int32Ty, 0)); + Irb.CreateCondBr(Comp, Nottagged, Tagged); + + Irb.SetInsertPoint(Tagged); // if (args->rule.chain_id == chain->id) - irb.SetInsertPoint(tagged); - irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateInBoundsGEP(args, {ConstantInt::get(int32Ty, 0), ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 3)}), irb.CreateInBoundsGEP(chain, ConstantInt::get(int32Ty, 12))), jt, jf); + Value *Chain_id = Irb.CreateStructGEP(Rule, 3); + Value *Id = Irb.CreateInBoundsGEP(Chain, ConstantInt::get(Int32Ty, 12)); + Comp = Irb.CreateICmpEQ(Chain_id, Id); + Irb.CreateCondBr(Comp, Jt, Jf); // f_pos = args->rule.slot; - irb.SetInsertPoint(jt); - irb.CreateStore(irb.CreateInBoundsGEP(args, {ConstantInt::get(int32Ty, 0), ConstantInt::get(int32Ty, 4),ConstantInt::get(int32Ty, 0)}), f_pos); - irb.CreateBr(nottagged); + Irb.SetInsertPoint(Jt); + Irb.CreateStore(Slot, F_pos); + Irb.CreateBr(Nottagged); // else fpos = ipfw_find_rule(chain, args->rule.rulenum, args->rule.rule_id) - irb.SetInsertPoint(jf); - irb.CreateStore(irb.CreateCall3(ipfw_find_rule, chain, irb.CreateInBoundsGEP(args, {ConstantInt::get(int32Ty, 0), ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 1)}), irb.CreateInBoundsGEP(args, {ConstantInt::get(int32Ty, 0), ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 2)})), f_pos); + Irb.SetInsertPoint(Jf); + Value *Rulenum = Irb.CreateStructGEP(Rule, 1); + Value *RuleId = Irb.CreateStructGEP(Rule, 2); + Value *FindRuleCall = Irb.CreateCall3(Ipfw_find_rule, Chain, Rulenum, RuleId); + Irb.CreateStore(FindRuleCall, F_pos); - // Branch to nottagged because it + // Branch to Nottagged because it // only finishes the entry BasicBlock. - irb.CreateBr(nottagged); + Irb.CreateBr(Nottagged); // else f_pos = 0; // Since f_pos is initialized by default as 0, we only br. - irb.SetInsertPoint(nottagged); + Irb.SetInsertPoint(Nottagged); // Jump to first rule. - irb.CreateBr(rules.front()); + Irb.CreateBr(rules.front()); } void emit_outer_for_prologue() { - BasicBlock *jt = BasicBlock::Create(con, "jt", func); - BasicBlock *jf = BasicBlock::Create(con, "jf", func); + BasicBlock *jt = BasicBlock::Create(Con, "jt", Func); + BasicBlock *jf = BasicBlock::Create(Con, "jf", Func); + Value *set_disable = mod->getGlobalVariable("set_disable"); // All this variables are already allocated. // ipfw_insn *cmd; - // uint32_t tablearg = 0; + // uInt32_t tablearg = 0; // int l, cmdlen, skip_or; /* skip rest of OR block */ // struct ip_fw *f; // f = chain->map[f_pos]; @@ -487,35 +540,44 @@ // continue; // skip_or = 0; - irb.SetInsertPoint(outer_for_prologue); - // uint32_t tablearg = 0; - irb.CreateStore(ConstantInt::get(int32Ty, 0), tablearg); + Irb.SetInsertPoint(Outer_for_prologue); + // uInt32_t tablearg = 0; + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Tablearg); // f = chain->map[f_pos]; idxs: 5, f_pos - irb.CreateStore(irb.CreateInBoundsGEP(irb.CreateLoad(irb.CreateStructGEP(chain, 5)), f_pos), f); + Value *MapPtr = Irb.CreateStructGEP(Chain, 5); + Value *Map = Irb.CreateLoad(MapPtr); + Value *MapFPos = Irb.CreateInBoundsGEP(Mal,F_pos); + Irb.CreateStore(MapFPos, F); // if (V_set_disable & (1 << f->set) ) - irb.CreateCondBr(irb.CreateICmpNE(irb.CreateAnd(set_disable, irb.CreateShl(ConstantInt::get(int32Ty, 1), irb.CreateStructGEP(f, 5))), ConstantInt::get(int32Ty, 0)), jt, jf); + Value *Set = Irb.CreateStructGEP(F, 5); + Value *ShiftedSet = Irb.CreateShl(ConstantInt::get(Int32Ty, 1), Set); + Value *AndOp = Irb.CreateAnd(set_disable, ShiftedSet); + Value *Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int32Ty, 0)); + Irb.CreateCondBr(Comp, jt, jf); - irb.SetInsertPoint(jt); + Irb.SetInsertPoint(jt); // continue; - irb.CreateBr(nextRule(rulenumber+1)); + Irb.CreateBr(nextRule(rulenumber+1)); // skip_or = 0; - irb.SetInsertPoint(jf); - irb.CreateStore(ConstantInt::get(int32Ty, 0), skip_or); + Irb.SetInsertPoint(jf); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Skip_or); - irb.CreateBr(inner_for_prologue); + Irb.CreateBr(Inner_for_prologue); } void emit_inner_for_prologue() { - BasicBlock *firstt = BasicBlock::Create(con, "firstt", func); - BasicBlock *firstf = BasicBlock::Create(con, "firstf", func); - BasicBlock *secondt = BasicBlock::Create(con, "secondt", func); - BasicBlock *secondf = BasicBlock::Create(con, "secondf", func); + BasicBlock *firstt = BasicBlock::Create(Con, "firstt", Func); + BasicBlock *firstf = BasicBlock::Create(Con, "firstf", Func); + BasicBlock *secondt = BasicBlock::Create(Con, "secondt", Func); + BasicBlock *secondf = BasicBlock::Create(Con, "secondf", Func); + + Value *Comp, *AndOp; // The first to are the intializers of the for loop. // l = f->cmd_len; @@ -529,58 +591,68 @@ // continue; // } // match = 0; /* set to 1 if we succeed */ - irb.SetInsertPoint(inner_for_prologue); + Irb.SetInsertPoint(Inner_for_prologue); // l = f->cmd_len; // XXX - ask David about types. int l; uint16_t cmd_len; - irb.CreateStore(irb.CreateInBoundsGEP(f, {ConstantInt::get(int32Ty, 0), ConstantInt::get(int32Ty, 3)}), l); + Value *CmdLen = Irb.CreateStructGEP(F, 3); + Irb.CreateStore(CmdLen, L); + // cmd = f->cmd; - irb.CreateStore(irb.CreateInBoundsGEP(f, {ConstantInt::get(int32Ty, 0), ConstantInt::get(int32Ty, 11)}), cmd); + Value *FCmd = Irb.CreateStructGEP(F, 11); + Irb.CreateStore(FCmd, Cmd); // int match; - // match is already allocated. + Match = Irb.CreateAlloca(Int32Ty); // cmdlen = ((cmd)->len & F_LEN_MASK); - irb.CreateStore(irb.CreateAnd(irb.CreateInBoundsGEP(cmd, {ConstantInt::get(int32Ty, 0), ConstantInt::get(int32Ty, 1)}), ConstantInt::get(int8Ty, F_LEN_MASK)), cmdlen); + Value *Len = Irb.CreateStructGEP(Cmd, 1); + AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_LEN_MASK)); + Irb.CreateStore(AndOp, Cmdlen); // if (skip_or) - irb.CreateCondBr(irb.CreateICmpNE(skip_or, ConstantInt::get(int32Ty, 0)), firstt, firstf); + Comp = Irb.CreateICmpNE(Skip_or, ConstantInt::get(Int32Ty, 0)); + Irb.CreateCondBr(Comp, firstt, firstf); - irb.SetInsertPoint(firstt); + Irb.SetInsertPoint(firstt); // if ((cmd->len & F_OR) == 0) - irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateAnd(irb.CreateInBoundsGEP(cmd, {ConstantInt::get(int32Ty, 0), ConstantInt::get(int32Ty, 1)}), ConstantInt::get(int8Ty, F_OR)), ConstantInt::get(int8Ty, 0)), secondt, secondf); + AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_OR)); + Comp = Irb.CreateICmpEQ(AndOp, ConstantInt::get(Int8Ty, 0)); + Irb.CreateCondBr(Comp, secondt, secondf); - irb.SetInsertPoint(secondt); + Irb.SetInsertPoint(secondt); // skip_or = 0; - irb.CreateStore(ConstantInt::get(int32Ty, 0), skip_or); - irb.CreateBr(secondf); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Skip_or); + Irb.CreateBr(secondf); - irb.SetInsertPoint(secondf); + Irb.SetInsertPoint(secondf); // continue; - irb.CreateBr(nextRule(rulenumber+1)); + Irb.CreateBr(nextRule(rulenumber+1)); - irb.SetInsertPoint(firstf); + Irb.SetInsertPoint(firstf); // match = 0; - irb.CreateStore(ConstantInt::get(int32Ty, 0), match); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Match); - irb.CreateBr(inner_for_epilogue); + Irb.CreateBr(Inner_for_epilogue); } // We get here ar the end of switch() on opcodes. void emit_inner_for_epilogue() { - BasicBlock *matchnz = BasicBlock::Create(con, "matchnz", func); - BasicBlock *matchz = BasicBlock::Create(con, "matchz", func); - BasicBlock *jt = BasicBlock::Create(con, "jt", func); - BasicBlock *sec_cond = BasicBlock::Create(con, "sec_cond", func); - BasicBlock *matchzero = BasicBlock::Create(con, "matchzero", func); - BasicBlock *matchnotzero = BasicBlock::Create(con, "matchnotzero", func); - BasicBlock *is_or = BasicBlock::Create(con, "is_or", func); + BasicBlock *matchnz = BasicBlock::Create(Con, "matchnz", Func); + BasicBlock *matchz = BasicBlock::Create(Con, "matchz", Func); + BasicBlock *jt = BasicBlock::Create(Con, "jt", Func); + BasicBlock *sec_cond = BasicBlock::Create(Con, "sec_cond", Func); + BasicBlock *matchzero = BasicBlock::Create(Con, "matchzero", Func); + BasicBlock *matchnotzero = BasicBlock::Create(Con, "matchnotzero", Func); + BasicBlock *is_or = BasicBlock::Create(Con, "is_or", Func); + + Value *Comp, *AndOp; // This are the increments of the for loop. // l -= cmdlen, cmd += cmdlen; - irb.CreateStore(irb.CreateNSWSub(l, cmdlen), l); - irb.CreateStore(irb.CreateAdd(cmd, cmdlen), cmd); + Irb.CreateStore(Irb.CreateNSWSub(L, Cmdlen), L); + Irb.CreateStore(Irb.CreateAdd(Cmd, Cmdlen), Cmd); // if (cmd->len & F_NOT) // match = !match; @@ -593,41 +665,50 @@ // break; /* try next rule */ // } - irb.SetInsertPoint(inner_for_epilogue); + Irb.SetInsertPoint(Inner_for_epilogue); // if (cmd->len & F_NOT) - irb.CreateCondBr(irb.CreateICmpNE(irb.CreateAnd(irb.CreateInBoundsGEP(cmd, {ConstantInt::get(int32Ty, 0), ConstantInt::get(int32Ty, 1)}), ConstantInt::get(int8Ty, F_NOT)), ConstantInt::get(int32Ty, 0)), jt, sec_cond); + Value *Len = Irb.CreateStructGEP(Cmd, 1); + AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_NOT)); + Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int32Ty, 0)); + Irb.CreateCondBr(Comp, jt, sec_cond); - irb.SetInsertPoint(jt); + Irb.SetInsertPoint(jt); // match = !match; // match = ((match)?0:1); - irb.CreateCondBr(irb.CreateICmpNE(match, ConstantInt::get(int32Ty, 0)),matchnz, matchz); + Comp = Irb.CreateICmpNE(Match, ConstantInt::get(Int32Ty, 0)); + Irb.CreateCondBr(Comp, matchnz, matchz); - irb.SetInsertPoint(matchnz); - irb.CreateStore(ConstantInt::get(int32Ty, 0), match); - irb.CreateBr(sec_cond); + Irb.SetInsertPoint(matchnz); + Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Match); + Irb.CreateBr(sec_cond); + + Irb.SetInsertPoint(matchz); + Irb.CreateStore(ConstantInt::get(Int32Ty, 1), Match); + Irb.CreateBr(sec_cond); - irb.SetInsertPoint(matchz); - irb.CreateStore(ConstantInt::get(int32Ty, 1), match); - irb.CreateBr(sec_cond); - - irb.SetInsertPoint(sec_cond); + Irb.SetInsertPoint(sec_cond); // if (match) - irb.CreateCondBr(irb.CreateICmpNE(match, ConstantInt::get(int32Ty, 0)), matchnotzero, matchzero); + Comp = Irb.CreateICmpNE(Match, ConstantInt::get(Int32Ty, 0)); + Irb.CreateCondBr(Comp, matchnotzero, matchzero); - irb.SetInsertPoint(matchnotzero); + Irb.SetInsertPoint(matchnotzero); // if (cmd->len & F_OR) - irb.CreateCondBr(irb.CreateICmpNE(irb.CreateAnd(irb.CreateInBoundsGEP(cmd, {ConstantInt::get(int32Ty, 0), ConstantInt::get(int32Ty, 1)}), ConstantInt::get(int8Ty, F_OR)), ConstantInt::get(int32Ty, 0)), is_or, outer_for_epilogue); + AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_OR)) + Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int32Ty, 0)); + Irb.CreateCondBr(Comp, is_or, Outer_for_epilogue); - irb.SetInsertPoint(is_or); + Irb.SetInsertPoint(is_or); // skip_or = 1; - irb.CreateStore(ConstantInt::get(int32Ty, 1), skip_or); - irb.CreateBr(outer_for_epilogue); + Irb.CreateStore(ConstantInt::get(Int32Ty, 1), Skip_or); + Irb.CreateBr(Outer_for_epilogue); - irb.SetInsertPoint(matchzero); + Irb.SetInsertPoint(matchzero); // if (!(cmd->len & F_OR)) /* not an OR block, */ // break; - irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateAnd(irb.CreateInBoundsGEP(cmd, {ConstantInt::get(int32Ty, 0), ConstantInt::get(int32Ty, 1)}), ConstantInt::get(int8Ty, F_OR)), ConstantInt::get(int32Ty, 0)), nextRule(rulenumber+1) /* break */, outer_for_epilogue); + AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_OR)); + Comp = Irb.CreateICmpEQ(AndOp, ConstantInt::get(Int32Ty, 0)); + Irb.CreateCondBr(Comp, nextRule(rulenumber+1) /* break */, Outer_for_epilogue); } // This code gets executed at the end of inner loop. @@ -635,14 +716,16 @@ void emit_outer_for_epilogue() { - irb.SetInsertPoint(outer_for_epilogue); + Irb.SetInsertPoint(Outer_for_epilogue); // f_pos++, increment of the for loop. - irb.CreateStore(irb.CreateAdd(f_pos, ConstantInt::get(int32Ty, 1)), f_pos); + Value AddOp = Irb.CreateAdd(F_pos, ConstantInt::get(Int32Ty, 1)); + Irb.CreateStore(AddOp, F_pos); // if (done) // break; - irb.CreateCondBr(irb.CreateICmpNE(done, ConstantInt::get(int32Ty, 0)), end, nextRule(rulenumber+1)); + Value *Comp = Irb.CreateICmpNE(Done, ConstantInt::get(Int32Ty, 0)); + Irb.CreateCondBr(Comp, End, nextRule(rulenumber+1)); } void @@ -650,9 +733,10 @@ { Value *rule, *time_uptime, *str; - BasicBlock *jt = BasicBlock::Create(con, "jt", func); - BasicBlock *jf = BasicBlock::Create(con, "jf", func); - BasicBlock *ret = BasicBlock::Create(con, "ret", func); + BasicBlock *jt = BasicBlock::Create(Con, "jt", Func); + BasicBlock *jf = BasicBlock::Create(Con, "jf", Func); + BasicBlock *ret = BasicBlock::Create(Con, "ret", Func); + Value *Comp, AddOp; // if (done) { // struct ip_fw *rule = chain->map[f_pos]; @@ -672,90 +756,99 @@ // // return (retval); - irb.SetInsertPoint(end); + Irb.SetInsertPoint(End); // We need to get the timestamp variable. time_uptime = mod->getGlobalVariable("time_uptime"); - str = irb.CreateGlobalString("ipfw: ouch!, skip past end of rules, denying packet\n"); + str = Irb.CreateGlobalString("ipfw: ouch!, skip past end of rules, denying packet\n"); // if (done) - irb.CreateCondBr(irb.CreateICmpNE(done, ConstantInt::get(int32Ty, 0)), jt, jf); + Comp = Irb.CreateICmpNE(Done, ConstantInt::get(Int32Ty, 0)); + Irb.CreateCondBr(Comp, jt, jf); - irb.SetInsertPoint(jt); + Irb.SetInsertPoint(jt); // struct ip_fw *rule = chain->map[f_pos]; - rule = irb.CreateAlloca(ip_fwPtrTy); - irb.CreateStore(irb.CreateInBoundsGEP(irb.CreateLoad(irb.CreateStructGEP(chain, 5)), f_pos), rule); + rule = Irb.CreateAlloca(Ip_fwPtrTy); + Value *MapPtr = Irb.CreateStructGEP(Chain, 5); + Value *Map = Irb.CreateLoad(MapPtr); + Value *MapFPos = Irb.CreateInBoundsGEP(Mal,F_pos); + Irb.CreateStore(MapFPos, rule); // uint64_t pcnt; // (rule)->pcnt++; - Value *pcnt = irb.CreateStructGEP(irb.CreateLoad(rule), 8); - irb.CreateStore(irb.CreateAdd(pcnt, ConstantInt::get(pcnt->getType(), 1)), pcnt); + Value RuleL = Irb.CreateLoad(rule); + Value *Pcnt = Irb.CreateStructGEP(RuleL, 8); + AddOp = Irb.CreateAdd(Pcnt, ConstantInt::get(pcnt->getType(), 1)); + Irb.CreateStore(AddOp, Pcnt); + // uint64_t bnct; *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408291733.s7THX9F6091610>