Exemple #1
0
int LUA_fail_delay(struct RPC2_addrinfo *Addr, RPC2_PacketBuffer *pb, int out,
		   struct timeval *tv)
{
    char addr[RPC2_ADDRSTRLEN];
    int rc, color;

    if (out) rc = setup_function("fail_delay_tx");
    else     rc = setup_function("fail_delay_rx");
    if (rc) return 0;

    ntohPktColor(pb);
    color = GetPktColor(pb);

    RPC2_formataddrinfo(Addr, addr, RPC2_ADDRSTRLEN);
    lua_pushstring(L, addr);
    lua_pushinteger(L, pb->Prefix.LengthOfPacket);
    lua_pushinteger(L, color);
    if (lua_pcall(L, 3, 2, 0)) { badscript(); return 0; }

    if (!lua_isnil(L, -2)) {
	l2c_totimeval(L, -2, tv); /* delay packet */
	rc = (tv->tv_sec >= 0);
    } else
	rc = -1;		  /* drop packet */

    if (lua_isnumber(L, -1)) { /* not nil, set new color value */
	color = lua_tointeger(L, -1);
	SetPktColor(pb, color);
    }
    lua_pop(L, 2);

    htonPktColor(pb);
    return rc;
}
Exemple #2
0
static int push_hosttable(struct HEntry *he)
{
    char addr[RPC2_ADDRSTRLEN];

    lua_pushlightuserdata(L, he);
    lua_rawget(L, LUA_REGISTRYINDEX);
    if (!lua_isnil(L, -1)) return 0;
    lua_pop(L, 1);

    /* create a new 'host' table */
    lua_newtable(L);

    /* set host.name = he->Addr */
    rpc2_formataddrinfo(he->Addr, addr, RPC2_ADDRSTRLEN, 0);

    lua_pushstring(L, addr);
    lua_setfield(L, -2, "name");

    /* make sure we can find the table again */
    lua_pushlightuserdata(L, he);
    lua_pushvalue(L, -2); /* push host */
    lua_rawset(L, LUA_REGISTRYINDEX);

    /* run custom initializer */
    if (setup_function("rtt_init")) return 0;
    lua_pushvalue(L, -2); /* push host */
    if (lua_pcall(L, 1, 0, 0)) { badscript(); return -1; }

    return 0;
}
Exemple #3
0
int LUA_rtt_getbandwidth(struct HEntry *he, uint32_t *bw_tx, uint32_t *bw_rx)
{
    if (setup_function("rtt_getbandwidth")) return 0;
    if (push_hosttable(he)) return 0;
    if (lua_pcall(L, 1, 2, 0)) { badscript(); return 0; }

    if (bw_tx) *bw_tx = (uint32_t)lua_tointeger(L, -2);
    if (bw_rx) *bw_rx = (uint32_t)lua_tointeger(L, -1);
    lua_pop(L, 2);
    return 1;
}
Exemple #4
0
void LUA_rtt_update(struct HEntry *he, uint32_t rtt, uint32_t tx, uint32_t rx)
{
    struct timeval tv;
    if (setup_function("rtt_update")) return;
    if (push_hosttable(he)) return;

    tv.tv_sec = rtt / 1000000;
    tv.tv_usec = rtt % 1000000;
    l2c_pushtimeval(L, &tv);

    lua_pushinteger(L, (lua_Integer)tx);
    lua_pushinteger(L, (lua_Integer)rx);
    if (lua_pcall(L, 4, 0, 0)) badscript();
}
Exemple #5
0
int LUA_rtt_getrto(struct HEntry *he, uint32_t tx, uint32_t rx)
{
    struct timeval tv;
    uint32_t rtt;

    if (setup_function("rtt_getrto")) return 0;
    if (push_hosttable(he)) return 0;
    lua_pushinteger(L, (lua_Integer)tx);
    lua_pushinteger(L, (lua_Integer)rx);
    if (lua_pcall(L, 3, 1, 0)) { badscript(); return 0; }

    l2c_totimeval(L, -1, &tv);
    rtt = tv.tv_sec * 1000000 + tv.tv_usec;
    lua_pop(L, 1);
    return rtt;
}
Exemple #6
0
int LUA_rtt_retryinterval(struct HEntry *he, uint32_t n, uint32_t tx, uint32_t rx)
{
    struct timeval tv;
    int rtt = -1;

    if (setup_function("rtt_retryinterval")) return 0;
    if (push_hosttable(he)) return 0;
    lua_pushinteger(L, (lua_Integer)n);
    lua_pushinteger(L, (lua_Integer)tx);
    lua_pushinteger(L, (lua_Integer)rx);
    if (lua_pcall(L, 4, 1, 0)) { badscript(); return 0; }

    if (!lua_isnil(L, -1)) {
	l2c_totimeval(L, -1, &tv);
	rtt = tv.tv_sec * 1000000 + tv.tv_usec;
    }
    lua_pop(L, 1);
    return rtt;
}
Exemple #7
0
 void DisassemblerContext::run_term(const ValuePtr<>& term) {
   switch (term->term_type()) {
   case term_function: {
     ValuePtr<Function> function = value_cast<Function>(term);
     setup_term_name(function);
     setup_function(function);
     build_unique_names();
     print_definitions(m_global_definitions, "", true);
     print_function(function);
     break;
   }
   
   case term_block: {
     ValuePtr<Block> block = value_cast<Block>(term);
     m_in_function_mode = true;
     setup_term_name(block);
     setup_block(block);
     build_unique_names();
     print_block(block, m_global_definitions);
     break;
   }
   
   default:
     m_in_function_mode = true;
     setup_term_definition(term);
     build_unique_names();
     print_definitions(m_global_definitions);
     
     switch (term->term_type()) {
     case term_instruction:
     case term_phi:
     case term_function_parameter:
     case term_recursive:
       print_term_definition(term, true);
       break;
       
     default:
       break;
     }
     break;
   }
 }
Exemple #8
0
    void DisassemblerContext::setup_term_definition(const ValuePtr<>& term) {
      if (!m_defined_terms.insert(term).second)
        return;
      
      setup_term_name(term);

      switch (term->term_type()) {
      case term_recursive: {
        ValuePtr<RecursiveType> recursive = value_cast<RecursiveType>(term);
        for (RecursiveType::ParameterList::const_iterator ii = recursive->parameters().begin(), ie = recursive->parameters().end(); ii != ie; ++ii) {
          setup_term_name(*ii);
          setup_term((*ii)->type());
        }
        if (recursive->result())
          setup_term(recursive->result());
        break;
      }
        
      case term_global_variable: {
        ValuePtr<GlobalVariable> gvar = value_cast<GlobalVariable>(term);
        setup_term(gvar->value_type());
        if (gvar->value())
          setup_term(gvar->value());
        break;
      }
      
      case term_function: {
        ValuePtr<Function> function = value_cast<Function>(term);
        setup_function(function);
        break;
      }
      
      case term_function_parameter: {
        ValuePtr<FunctionParameter> param = value_cast<FunctionParameter>(term);
        setup_term(param->type());
        break;
      }
      
      case term_instruction: {
        class MyVisitor : public InstructionVisitor {
          DisassemblerContext *m_self;
        public:
          MyVisitor(DisassemblerContext *self) : m_self(self) {}
          virtual void next(ValuePtr<>& v) {if (v) m_self->setup_term(v);}
        };
        
        MyVisitor my_visitor(this);
        ValuePtr<Instruction> insn = value_cast<Instruction>(term);
        insn->instruction_visit(my_visitor);
        m_local_definitions[insn->block()].push_back(insn);
        break;
      }
      
      case term_phi: {
        ValuePtr<Phi> phi = value_cast<Phi>(term);
        const std::vector<PhiEdge>& edges = phi->edges();
        for (std::vector<PhiEdge>::const_iterator ii = edges.begin(), ie = edges.end(); ii != ie; ++ii) {
          setup_term(ii->block);
          setup_term(ii->value);
        }
        break;
      }
      
      default:
        setup_term(term);
        break;
      }
    }