예제 #1
0
파일: adddialog.cpp 프로젝트: tailored/bf
void AddDialog::accept()
{
    mFr.base.proto = get_proto(ui->cbProto->currentText().toStdString().c_str());

    mFr.base.src_port = ui->leSourcePort->text().toUInt();

    bool any = ui->rbAnyone->isChecked();

    QHostAddress hostaddr(any?"0.0.0.0":ui->leSourceHostIP->text());

    if( hostaddr.isNull() )
    {
        /*QMessageBox::StandardButton reply =*/ QMessageBox::critical(this, tr("Data error")
                             , tr("Wrong ip address")
                             , QMessageBox::Ok );

    }
    else if( mFr.base.src_port==0 )
    {
        /*QMessageBox::StandardButton reply =*/ QMessageBox::critical(this, tr("Data error")
                             , tr("Wrong port number")
                             , QMessageBox::Ok );

    }
    else
    {
        mFr.base.s_addr.addr = static_cast<quint32>(htonl(hostaddr.toIPv4Address()));
        emit accept_rule(mFr);
        QDialog::accept();
    }

}
예제 #2
0
	// for optimization I don't want to put '__constructor__' into as_object
	// so the missing of '__constructor__' in a object means 
	// that it is a instance of as_object
	bool	as_object::is_instance_of(const as_function* constructor) const
	{
		// by default ctor is as_global_object_ctor
		as_value ctor;
		get_ctor(&ctor);
		if (ctor.is_undefined())
		{
			ctor.set_as_c_function(as_global_object_ctor);
		}

		const as_s_function* sf = cast_to<as_s_function>(constructor);
		if (sf && sf == cast_to<as_s_function>(ctor.to_function()))
		{
			return true;
		}

		const as_c_function* cf1 = cast_to<as_c_function>(constructor);
		const as_c_function* cf2 = cast_to<as_c_function>(ctor.to_function());
		if (cf1 && cf2 && cf1->m_func == cf2->m_func)
		{
			return true;
		}

		as_object* proto = get_proto();
		if (proto)
		{
			return proto->is_instance_of(constructor);
		}
		return false;
	}
예제 #3
0
파일: symmetric.c 프로젝트: Henauxg/minix
unsigned 
pgp_key_size(pgp_symm_alg_t alg)
{
	const pgp_crypt_t *p = get_proto(alg);

	return (p == NULL) ? 0 : (unsigned)p->keysize;
}
예제 #4
0
	bool	as_object::get_member(const tu_stringi& name, as_value* val)
	{
		//printf("GET MEMBER: %s at %p for object %p\n", name.c_str(), val, this);
		
		// first try built-ins object methods
		if (get_builtin(BUILTIN_OBJECT_METHOD, name, val))
		{
			return true;
		}

		if (m_members.get(name, val) == false)
		{
			as_object* proto = get_proto();
			if (proto == NULL)
			{
				return false;
			}

			if (proto->get_member(name, val) == false)
			{
				return false;
			}
		}

		if (val->is_property())
		{
			val->set_property_target(this);
		}

		return true;
	}
예제 #5
0
unsigned 
__ops_key_size(__ops_symm_alg_t alg)
{
	const __ops_crypt_t *p = get_proto(alg);

	return (p == NULL) ? 0 : (unsigned)p->keysize;
}
예제 #6
0
/*
 *			M A I N
 *
 */
int
main(int argc, char **argv)
{
    char	*prototype;		/* Contains full text of prototype document */
    char	proto_file[256] = {0};

    FILE	*table;
    char	table_file[256] = {0};

    if ( argc < 2 || argc > 3 )  {
	fprintf(stderr, "Usage:  tabsub prototype_file [table_file]\n");
	bu_exit(12, NULL);
    }
    bu_strlcpy(proto_file, argv[1], sizeof(proto_file));

    /* Acquire in-core copy of prototype file */
    get_proto( &prototype, proto_file );

    if ( argc < 3 )  {
	table = stdin;
    } else {
	bu_strlcpy(table_file, argv[2], sizeof(table_file));
	if ( (table = fopen( table_file, "r" )) == NULL )  {
	    perror( table_file );
	    bu_exit(3, NULL);
	}
    }
    do_lines( table, prototype );
    return 0;
}
예제 #7
0
/*
 * MPID_Probe 
 */
void MPID_Probe(struct MPIR_COMMUNICATOR *comm,
                int tag,
                int context_id,
                int src_lrank,
                int *error_code,
                MPI_Status *status)
{
    int found   = 0;
    *error_code = 0;

#   if defined(VMPI)
    {
	int proto = get_proto(comm, src_lrank);

	if (proto == mpi)
	{
	    void * vmpi_status;
	    int vmpi_src;
	    int vmpi_tag;

	    vmpi_status = STATUS_INFO_GET_VMPI_PTR(*status);
	    
	    if (src_lrank == MPI_ANY_SOURCE)
	    {
		vmpi_src = VMPI_ANY_SOURCE;
	    }
	    else
	    {
		vmpi_src = comm->lrank_to_vlrank[src_lrank];
	    }

	    vmpi_tag = (tag == MPI_ANY_TAG ? VMPI_ANY_TAG : tag);

	    *error_code = vmpi_error_to_mpich_error(
		mp_probe(vmpi_src, vmpi_tag, comm->vmpi_comm, vmpi_status));

	    status->MPI_SOURCE = comm->vlrank_to_lrank[
		mp_status_get_source(vmpi_status)];
	    status->MPI_TAG = mp_status_get_tag(vmpi_status);
	    status->MPI_ERROR = *error_code;
	    STATUS_INFO_SET_COUNT_VMPI(*status);

	    return;
	}
    }
#   endif /* defined(VMPI) */
    
    while (*error_code == 0 && !found)
    {
	MPID_Iprobe(comm,
		    tag,
		    context_id,
		    src_lrank,
		    &found,
		    error_code,
		    status);
    } /* endwhile */

} /* end MPID_Probe() */
예제 #8
0
static int l_deepactivelines(lua_State *L) {
    luaL_checktype(L, 1, LUA_TFUNCTION);
    luaL_argcheck(L, !lua_iscfunction(L, 1), 1,
        "Lua function expected, got C function");
    lua_settop(L, 1);
    lua_newtable(L);
    add_activelines(L, get_proto(L));
    return 1;
}
예제 #9
0
파일: symmetric.c 프로젝트: Henauxg/minix
int 
pgp_crypt_any(pgp_crypt_t *crypt, pgp_symm_alg_t alg)
{
	const pgp_crypt_t *ptr = get_proto(alg);

	if (ptr) {
		*crypt = *ptr;
		return 1;
	} else {
		(void) memset(crypt, 0x0, sizeof(*crypt));
		return 0;
	}
}
static inline void uih_frame(int level, struct frame *frm, long_frame_head *head)
{
	uint32_t proto;

	if (!head->addr.server_chn) {
		mcc_frame(level, frm, head); 
	} else {
		p_indent(level, frm);
		printf("RFCOMM(d): UIH: ");
		print_rfcomm_hdr(head, frm->ptr, frm->len);
		if (GET_PF(head->control)) {
			printf("credits %d\n", *(uint8_t *)(frm->ptr));
			frm->ptr++;
			frm->len--;
		} else
			printf("\n");

		frm->len--;
		frm->dlci = GET_DLCI(head->addr);
		frm->channel = head->addr.server_chn;

		proto = get_proto(frm->handle, RFCOMM_PSM, frm->channel);

		if (frm->len > 0) {
			switch (proto) {
			case SDP_UUID_OBEX:
				if (!p_filter(FILT_OBEX))
					obex_dump(level + 1, frm);
				else
					raw_dump(level, frm);
				break;

			case SDP_UUID_LAN_ACCESS_PPP:
			case SDP_UUID_DIALUP_NETWORKING:
				if (!p_filter(FILT_PPP))
					ppp_dump(level + 1, frm);
				else
					raw_dump(level, frm);
				break;

			default:
				if (p_filter(FILT_RFCOMM))
					break;

				raw_dump(level, frm);
				break;
			}
		}
	}
}
예제 #11
0
/*
 * This returns all the pointer-bearing registers whose pointees :insn will
 * read from.
 */
std::vector<uint16_t> object_read_registers(const IRInstruction* insn) {
  switch (insn->opcode()) {
  case OPCODE_AGET:
  case OPCODE_AGET_WIDE:
  case OPCODE_AGET_BOOLEAN:
  case OPCODE_AGET_BYTE:
  case OPCODE_AGET_CHAR:
  case OPCODE_AGET_SHORT:
  case OPCODE_AGET_OBJECT:
  case OPCODE_IGET:
  case OPCODE_IGET_WIDE:
  case OPCODE_IGET_BOOLEAN:
  case OPCODE_IGET_BYTE:
  case OPCODE_IGET_CHAR:
  case OPCODE_IGET_SHORT:
  case OPCODE_IGET_OBJECT:

  case OPCODE_APUT_OBJECT:
  case OPCODE_IPUT_OBJECT:
  case OPCODE_SPUT_OBJECT:

  case OPCODE_RETURN_OBJECT:
    return {insn->src(0)};

  case OPCODE_INVOKE_SUPER:
  case OPCODE_INVOKE_DIRECT:
  case OPCODE_INVOKE_STATIC:
  case OPCODE_INVOKE_VIRTUAL:
  case OPCODE_INVOKE_INTERFACE: {
    std::vector<uint16_t> regs;
    size_t idx{0};
    if (insn->opcode() != OPCODE_INVOKE_STATIC) {
      // The `this` parameter
      regs.emplace_back(insn->src(idx++));
    }
    auto callee = insn->get_method();
    auto arg_types = callee->get_proto()->get_args()->get_type_list();
    for (DexType* arg_type : arg_types) {
      if (!is_primitive(arg_type)) {
        regs.emplace_back(insn->src(idx));
      }
      ++idx;
    }
    return regs;
  }
  default:
    return {};
  }
}
예제 #12
0
파일: Bridge.cpp 프로젝트: facebook/redex
 void exclude_referenced_bridgee(DexMethod* code_method, IRCode& code) {
   for (auto& mie : InstructionIterable(&code)) {
     auto inst = mie.insn;
     if (!is_invoke(inst->opcode())) continue;
     auto method = inst->get_method();
     auto range = m_potential_bridgee_refs.equal_range(
         MethodRef(method->get_class(), method->get_name(),
             method->get_proto()));
     for (auto it = range.first; it != range.second; ++it) {
       auto referenced_bridge = it->second;
       // Don't count the bridge itself
       if (referenced_bridge == code_method) continue;
       TRACE(BRIDGE,
             5,
             "Rejecting, reference `%s.%s.%s' in `%s' blocks `%s'\n",
             SHOW(method->get_class()),
             SHOW(method->get_name()),
             SHOW(method->get_proto()),
             SHOW(code_method),
             SHOW(referenced_bridge));
       m_bridges_to_bridgees.erase(referenced_bridge);
     }
   }
 }
예제 #13
0
파일: Bridge.cpp 프로젝트: dutao-88/redex
 void exclude_referenced_bridgee(DexMethod* code_method, const DexCode& code) {
   auto const& insts = code.get_instructions();
   for (auto inst : insts) {
     if (!is_invoke(inst->opcode())) continue;
     auto method = static_cast<DexOpcodeMethod*>(inst)->get_method();
     auto range = m_potential_bridgee_refs.equal_range(
         MethodRef(method->get_class(), method->get_name(),
             method->get_proto()));
     for (auto it = range.first; it != range.second; ++it) {
       auto referenced_bridge = it->second;
       // Don't count the bridge itself
       if (referenced_bridge == code_method) continue;
       TRACE(BRIDGE,
             5,
             "Rejecting, reference `%s.%s.%s' in `%s' blocks `%s'\n",
             SHOW(method->get_class()),
             SHOW(method->get_name()),
             SHOW(method->get_proto()),
             SHOW(code_method),
             SHOW(referenced_bridge));
       m_bridges_to_bridgees.erase(referenced_bridge);
     }
   }
 }
예제 #14
0
/**
 * Change the visibility of members accessed in a callee as they are moved
 * to the caller context.
 * We make everything public but we could be more precise and only
 * relax visibility as needed.
 */
void MultiMethodInliner::change_visibility(DexMethod* callee) {
  TRACE(MMINL, 6, "checking visibility usage of members in %s\n",
      SHOW(callee));
  for (auto insn : callee->get_code()->get_instructions()) {
    if (insn->has_fields()) {
      auto fop = static_cast<DexOpcodeField*>(insn);
      auto field = fop->field();
      field = resolve_field(field, is_sfield_op(insn->opcode())
          ? FieldSearch::Static : FieldSearch::Instance);
      if (field != nullptr && field->is_concrete()) {
        TRACE(MMINL, 6, "changing visibility of %s.%s %s\n",
            SHOW(field->get_class()), SHOW(field->get_name()),
            SHOW(field->get_type()));
        set_public(field);
        set_public(type_class(field->get_class()));
        fop->rewrite_field(field);
      }
      continue;
    }
    if (insn->has_methods()) {
      auto mop = static_cast<DexOpcodeMethod*>(insn);
      auto method = mop->get_method();
      method = resolver(method, opcode_to_search(insn));
      if (method != nullptr && method->is_concrete()) {
        TRACE(MMINL, 6, "changing visibility of %s.%s: %s\n",
            SHOW(method->get_class()), SHOW(method->get_name()),
            SHOW(method->get_proto()));
        set_public(method);
        set_public(type_class(method->get_class()));
        mop->rewrite_method(method);
      }
      continue;
    }
    if (insn->has_types()) {
      auto type = static_cast<DexOpcodeType*>(insn)->get_type();
      auto cls = type_class(type);
      if (cls != nullptr && !cls->is_external()) {
        TRACE(MMINL, 6, "changing visibility of %s\n", SHOW(type));
        set_public(cls);
      }
      continue;
    }
  }
}
예제 #15
0
/**
 * If the caller is in the primary DEX we want to make sure there are no
 * references in other DEXes that may cause a verification error.
 * Don't inline if so.
 */
bool MultiMethodInliner::refs_not_in_primary(DexMethod* callee) {

  const auto ok_from_primary = [&](DexType* type) {
    if (primary.count(type) == 0 && type_class_internal(type) != nullptr) {
      info.not_in_primary++;
      return false;
    }
    return true;
  };

  for (auto insn : callee->get_code()->get_instructions()) {
    if (insn->has_types()) {
      auto top = static_cast<DexOpcodeType*>(insn);
      if (!ok_from_primary(top->get_type())) {
        return true;
      }
    } else if (insn->has_methods()) {
      auto mop = static_cast<DexOpcodeMethod*>(insn);
      auto meth = mop->get_method();
      if (!ok_from_primary(meth->get_class())) {
        return true;
      }
      auto proto = meth->get_proto();
      if (!ok_from_primary(proto->get_rtype())) {
        return true;
      }
      auto args = proto->get_args();
      if (args == nullptr) continue;
      for (const auto& arg : args->get_type_list()) {
        if (!ok_from_primary(arg)) {
          return true;
        }
      }
    } else if (insn->has_fields()) {
      auto fop = static_cast<DexOpcodeField*>(insn);
      auto field = fop->field();
      if (!ok_from_primary(field->get_class()) ||
          !ok_from_primary(field->get_type())) {
        return true;
      }
    }
  }
  return false;
}
예제 #16
0
TEST_F(PreVerify, InlineInvokeDirect) {
  auto cls = find_class_named(
    classes, "Lcom/facebook/redexinline/InlineTest;");
  auto m = find_vmethod_named(*cls, "testInlineInvokeDirect");
  auto invoke =
      find_invoke(m, OPCODE_INVOKE_DIRECT, "hasNoninlinableInvokeDirect");
  auto noninlinable_invoke_direct =
      find_invoke(invoke->get_method(), OPCODE_INVOKE_DIRECT, "noninlinable");
  auto noninlinable = noninlinable_invoke_direct->get_method();
  ASSERT_EQ(show(noninlinable->get_proto()), "()V");

  // verify that there are two inlinable() methods in the class. The static
  // version exists to test that we don't cause a signature collision when we
  // make the instance method static.
  auto dmethods = cls->get_dmethods();
  ASSERT_EQ(2,
            std::count_if(dmethods.begin(), dmethods.end(), [](DexMethod* m) {
              return !strcmp("noninlinable", m->get_name()->c_str());
            }));
}
예제 #17
0
TEST_F(PostVerify, InlineInvokeDirect) {
  auto cls = find_class_named(
    classes, "Lcom/facebook/redexinline/InlineTest;");
  auto m = find_vmethod_named(*cls, "testInlineInvokeDirect");
  auto noninlinable_invoke_direct =
      find_invoke(m, OPCODE_INVOKE_STATIC, "noninlinable$redex0");
  ASSERT_NE(nullptr, noninlinable_invoke_direct);
  auto noninlinable = noninlinable_invoke_direct->get_method();
  ASSERT_EQ(show(noninlinable->get_proto()),
            "(Lcom/facebook/redexinline/InlineTest;)V");

  auto dmethods = cls->get_dmethods();
  // verify that we've replaced the instance noninlinable() method with
  // noninlinable$redex
  ASSERT_EQ(1,
            std::count_if(dmethods.begin(), dmethods.end(), [](DexMethod* m) {
              return !strcmp("noninlinable", m->get_name()->c_str());
            }));
  ASSERT_EQ(1,
            std::count_if(dmethods.begin(), dmethods.end(), [](DexMethod* m) {
              return !strcmp("noninlinable$redex0", m->get_name()->c_str());
            }));
}
예제 #18
0
	bool	as_object::find_property( const tu_stringi & name, as_value * val )
	{
		as_value dummy;
		if( get_member(name, &dummy) )
		{
			val->set_as_object( this );
			return true;
		}

		if(m_instance.get_ptr() != NULL)
		{
			// create traits
			for (int i = 0; i < m_instance->m_trait.size(); i++)
			{
				traits_info* ti = m_instance->m_trait[i].get();
				const char* traits_name = m_instance->m_abc->get_multiname(ti->m_name);

				if( name == traits_name)
				{
					if(ti->m_kind == traits_info::Trait_Slot)
					{
						val->set_as_object( this );
						return true;
					}
					return false;
				}
			}
		}

		as_object *proto = get_proto();
		if( proto )
		{
			return proto->find_property( name, val );
		}

		return false;
	}
예제 #19
0
nsapi_error_t Socket::open(NetworkStack *stack)
{
    _lock.lock();

    if (_stack != NULL || stack == NULL) {
        _lock.unlock();
        return NSAPI_ERROR_PARAMETER;
    }
    _stack = stack;

    nsapi_socket_t socket;
    nsapi_error_t err = _stack->socket_open(&socket, get_proto());
    if (err) {
        _lock.unlock();
        return err;
    }

    _socket = socket;
    _event.attach(this, &Socket::event);
    _stack->socket_attach(_socket, Callback<void()>::thunk, &_event);

    _lock.unlock();
    return NSAPI_ERROR_OK;
}
예제 #20
0
/* WARNING: doesn't work from failure route (deadlock, uses t_reply => tries
 *  to get the reply lock again */
int t_relay_to( struct sip_msg  *p_msg , struct proxy_l *proxy, int proto,
				int replicate)
{
	int ret;
	int new_tran;
	/* struct hdr_field *hdr; */
	struct cell *t;
	struct dest_info dst;
	unsigned short port;
	str host;
	short comp;
#ifndef TM_DELAYED_REPLY
	int reply_ret;
#endif

	ret=0;
	
	/* special case for CANCEL */
	if ( p_msg->REQ_METHOD==METHOD_CANCEL){
		ret=t_forward_cancel(p_msg, proxy, proto, &t);
		if (t) goto handle_ret;
		goto done;
	}
	new_tran = t_newtran( p_msg );
	
	/* parsing error, memory alloc, whatever ... if via is bad
	   and we are forced to reply there, return with 0 (->break),
	   pass error status otherwise
	   MMA: return value E_SCRIPT means that transaction was already started
	   from the script so continue with that transaction
	*/
	if (likely(new_tran!=E_SCRIPT)) {
		if (new_tran<0) {
			ret = (ser_error==E_BAD_VIA && reply_to_via) ? 0 : new_tran;
			goto done;
		}
		/* if that was a retransmission, return we are happily done */
		if (new_tran==0) {
			ret = 1;
			goto done;
		}
	}else if (unlikely(p_msg->REQ_METHOD==METHOD_ACK)) {
			/* transaction previously found (E_SCRIPT) and msg==ACK
			    => ack to neg. reply  or ack to local trans.
			    => process it and exit */
			/* FIXME: there's no way to distinguish here between acks to
			   local trans. and neg. acks */
			/* in normal operation we should never reach this point, if we
			   do WARN(), it might hide some real bug (apart from possibly
			   hiding a bug the most harm done is calling the TMCB_ACK_NEG
			   callbacks twice) */
			WARN("negative or local ACK caught, please report\n");
			t=get_t();
			if (unlikely(has_tran_tmcbs(t, TMCB_ACK_NEG_IN)))
				run_trans_callbacks(TMCB_ACK_NEG_IN, t, p_msg, 0, 
										p_msg->REQ_METHOD);
			t_release_transaction(t);
			ret=1;
			goto done;
	}

	/* new transaction */

	/* at this point if the msg is an ACK it is an e2e ACK and
	   e2e ACKs do not establish a transaction and are fwd-ed statelessly */
	if ( p_msg->REQ_METHOD==METHOD_ACK) {
		DBG( "SER: forwarding ACK  statelessly \n");
		if (proxy==0) {
			init_dest_info(&dst);
			dst.proto=proto;
			if (get_uri_send_info(GET_NEXT_HOP(p_msg), &host, &port,
									&dst.proto, &comp)!=0){
				ret=E_BAD_ADDRESS;
				goto done;
			}
#ifdef USE_COMP
			dst.comp=comp;
#endif
			/* dst->send_sock not set, but forward_request will take care
			 * of it */
			ret=forward_request(p_msg, &host, port, &dst);
		} else {
			init_dest_info(&dst);
			dst.proto=get_proto(proto, proxy->proto);
			proxy2su(&dst.to, proxy);
			/* dst->send_sock not set, but forward_request will take care
			 * of it */
			ret=forward_request( p_msg , 0, 0, &dst) ;
		}
		goto done;
	}

	/* if replication flag is set, mark the transaction as local
	   so that replies will not be relayed */
	t=get_t();
	if (replicate) t->flags|=T_IS_LOCAL_FLAG;

	/* INVITE processing might take long, particularly because of DNS
	   look-ups -- let upstream know we're working on it */
	if (p_msg->REQ_METHOD==METHOD_INVITE && (t->flags&T_AUTO_INV_100)
		&& (t->uas.status < 100)
	) {
		DBG( "SER: new INVITE\n");
		if (!t_reply( t, p_msg , 100 ,
			cfg_get(tm, tm_cfg, tm_auto_inv_100_r)))
				DBG("SER: ERROR: t_reply (100)\n");
	} 

	/* now go ahead and forward ... */
	ret=t_forward_nonack(t, p_msg, proxy, proto);
handle_ret:
	if (ret<=0) {
		DBG( "t_forward_nonack returned error %d (%d)\n", ret, ser_error);
		/* we don't want to pass upstream any reply regarding replicating
		 * a request; replicated branch must stop at us*/
		if (likely(!replicate)) {
			if(t->flags&T_DISABLE_INTERNAL_REPLY) {
				/* flag set to don't generate the internal negative reply
				 * - let the transaction live further, processing should
				 *   continue in config */
				DBG("not generating immediate reply for error %d\n", ser_error);
				tm_error=ser_error;
				ret = -4;
				goto done;
			}
#ifdef TM_DELAYED_REPLY
			/* current error in tm_error */
			tm_error=ser_error;
			set_kr(REQ_ERR_DELAYED);
			DBG("%d error reply generation delayed \n", ser_error);
#else

			reply_ret=kill_transaction( t, ser_error );
			if (reply_ret>0) {
				/* we have taken care of all -- do nothing in
			  	script */
				DBG("ERROR: generation of a stateful reply "
					"on error succeeded\n");
				/*ret=0; -- we don't want to stop the script */
			}  else {
				DBG("ERROR: generation of a stateful reply "
					"on error failed\n");
				t_release_transaction(t);
			}
#endif /* TM_DELAYED_REPLY */
		}else{
			t_release_transaction(t); /* kill it  silently */
		}
	} else {
		DBG( "SER: new transaction fwd'ed\n");
	}

done:
	return ret;
}
예제 #21
0
파일: parser.c 프로젝트: MarginC/kame
static int
filter6_parser(char *cmdbuf)
{
	char 	w[MAX_WORD], *cp = cmdbuf;
	char 	*ifname, class_name[MAX_WORD], fltr_name[MAX_WORD];
	char	*flname = NULL;
	struct flow_filter6	sfilt;
	int	protocol;
	u_char	tclass, tclassmask;
	int	ruleno;
	int	dontwarn = 0;
	int	ret;

	memset(&sfilt, 0, sizeof(sfilt));
	sfilt.ff_flow6.fi6_family = AF_INET6;

	if (!get_ifname(&cp, &ifname)) {
		LOG(LOG_ERR, 0, "missing interface name");
		return (0);
	}

	if (!next_word(&cp, class_name)) {
		LOG(LOG_ERR, 0, "missing class name");
		return (0);
	}

	fltr_name[0] = '\0';
	ruleno = 0;
	if (!get_fltr_opts(&cp, &fltr_name[0], sizeof(fltr_name), &ruleno)) {
		LOG(LOG_ERR, 0, "bad filter option");
		return (0);
	}
	if (fltr_name[0] != '\0')
		flname = fltr_name;
	sfilt.ff_ruleno = ruleno;

	/* get filter destination address */
	if (!get_ip6addr(&cp, &sfilt.ff_flow6.fi6_dst,
			 &sfilt.ff_mask6.mask6_dst)) {
		LOG(LOG_ERR, 0, "bad destination address");
		return (0);
	}

	/* get filter destination port */
	if (!next_word(&cp, w)) {
		LOG(LOG_ERR, 0, "missing filter destination port");
		return (0);
	}
	if (!get_port(w, &sfilt.ff_flow6.fi6_dport)) {
		LOG(LOG_ERR, 0, "bad filter destination port");
		return (0);
	}

	/* get filter source address */
	if (!get_ip6addr(&cp, &sfilt.ff_flow6.fi6_src,
			 &sfilt.ff_mask6.mask6_src)) {
		LOG(LOG_ERR, 0, "bad source address");
		return (0);
	}

	/* get filter source port */
	if (!next_word(&cp, w)) {
		LOG(LOG_ERR, 0, "missing filter source port");
		return (0);
	}
	if (!get_port(w, &sfilt.ff_flow6.fi6_sport)) {
		LOG(LOG_ERR, 0, "bad filter source port");
		return (0);
	}

	/* get filter protocol id */
	if (!next_word(&cp, w)) {
		LOG(LOG_ERR, 0, "missing filter protocol");
		return (0);
	}
	if (!get_proto(w, &protocol)) {
		LOG(LOG_ERR, 0, "bad protocol");
		return (0);
	}
	sfilt.ff_flow6.fi6_proto = protocol;

	while (next_word(&cp, w)) {
		if (EQUAL(w, "tclass")) {
			tclass = 0;
			tclassmask = 0xff;

			if (next_word(&cp, w)) {
				tclass = (u_char)strtol(w, NULL, 0);
				if (next_word(&cp, w)) {
					if (EQUAL(w, "tclassmask")) {
						next_word(&cp, w);
						tclassmask =
						    (u_char)strtol(w, NULL, 0);
					}
				}
			}
			sfilt.ff_flow6.fi6_tclass = tclass;
			sfilt.ff_mask6.mask6_tclass = tclassmask;
		} else if (EQUAL(w, "gpi")) {
			if (next_word(&cp, w)) {
				sfilt.ff_flow6.fi6_gpi =
					(u_int32_t)strtoul(w, NULL, 0);
				sfilt.ff_flow6.fi6_gpi =
					htonl(sfilt.ff_flow6.fi6_gpi);
			}
		} else if (EQUAL(w, "flowlabel")) {
			if (next_word(&cp, w)) {
				sfilt.ff_flow6.fi6_flowlabel =
				   (u_int32_t)strtoul(w, NULL, 0) & 0x000fffff;
				sfilt.ff_flow6.fi6_flowlabel =
					htonl(sfilt.ff_flow6.fi6_flowlabel);
			}
		} else if (EQUAL(w, "dontwarn"))
			dontwarn = 1;
	}

	/*
	 * Add the filter.
	 */
	filter_dontwarn = dontwarn;	/* XXX */
	ret = qcmd_add_filter(ifname, class_name, flname,
			      (struct flow_filter *)&sfilt);
	filter_dontwarn = 0;		/* XXX */
	if (ret) {
		LOG(LOG_ERR, 0,
		    "can't add filter to class '%s' on interface '%s'",
		    class_name, ifname);
		return (0);
	}

	return (1);
}
예제 #22
0
/*
 * MPID_Iprobe
 */
void MPID_Iprobe(struct MPIR_COMMUNICATOR *comm,
                 int tag,
                 int context_id,
                 int src_lrank,
                 int *found,
                 int *error_code,
                 MPI_Status *status)
{
    MPIR_RHANDLE *unexpected = (MPIR_RHANDLE *) NULL;

    *found = GLOBUS_FALSE;

#   ifdef VMPI
    {
	int proto = get_proto(comm, src_lrank);

	if (proto == mpi || proto == unknown)
	{
	    void * vmpi_status;
	    int vmpi_src;
	    int vmpi_tag;

	    vmpi_status = STATUS_INFO_GET_VMPI_PTR(*status);
	    
	    if (src_lrank == MPI_ANY_SOURCE)
	    {
		vmpi_src = VMPI_ANY_SOURCE;
	    }
	    else
	    {
		vmpi_src = comm->lrank_to_vlrank[src_lrank];
	    }

	    vmpi_tag = (tag == MPI_ANY_TAG ? VMPI_ANY_TAG : tag);

	    *error_code = vmpi_error_to_mpich_error(
		mp_iprobe(vmpi_src,
			  vmpi_tag,
			  comm->vmpi_comm,
			  found,
			  vmpi_status));

	    if (*found)
	    {
		status->MPI_SOURCE = comm->vlrank_to_lrank[
		    mp_status_get_source(vmpi_status)];
		status->MPI_TAG = mp_status_get_tag(vmpi_status);
		status->MPI_ERROR = *error_code;
		STATUS_INFO_SET_COUNT_VMPI(*status);
	    }

	    if (*found || *error_code != MPI_SUCCESS)
	    {
		return;
	    }
	} /* endif */
    }
#   endif 

    /* try TCP */

    /*
     * need G2_POLL here so that if MPID_Iprobe called 
     * by MPID_probe() progress is guaranteed, that is, if
     * MPID_Probe is called before TCP data arrives the waiting 
     * proc (i.e, the one that called MPI_Probe) must be assured
     * that once the TCP data is sent that it (a) will be received
     * and (b) it will be detected (i.e., progress).
     */
    G2_POLL

    /* search 'unexpected' queue ... does NOT remove from queue */
    MPID_Search_unexpected_queue(src_lrank,
				 tag,
				 context_id,
				 GLOBUS_FALSE, /* do not remove from queue */
				 &unexpected);

    if (unexpected)
    {
	*found = GLOBUS_TRUE;

	status->MPI_SOURCE    = unexpected->s.MPI_SOURCE;
	status->MPI_TAG       = unexpected->s.MPI_TAG;
	status->MPI_ERROR     = unexpected->s.MPI_ERROR;
	/* 
	 * setting status->count and bits in status->private_count 
	 * to indicate that status->count should be interpreted 
	 * (e.g., by MPID_Get_{count,elements} as nbytes in data 
	 * origin format
	 */
	status->count         = unexpected->len;
	STATUS_INFO_SET_FORMAT(*status, unexpected->src_format);
	STATUS_INFO_SET_COUNT_REMOTE(*status);
    } /* endif */

} /* end MPID_Iprobe() */
예제 #23
0
파일: t_fwd.c 프로젝트: OPSF/uClinux
/* introduce a new uac to transaction; returns its branch id (>=0)
   or error (<0); it doesn't send a message yet -- a reply to it
   might interfere with the processes of adding multiple branches
*/
int add_uac( struct cell *t, struct sip_msg *request, str *uri, str* next_hop,
             struct proxy_l *proxy, int proto )
{

    int ret;
    short temp_proxy;
    union sockaddr_union to;
    unsigned short branch;
    struct socket_info* send_sock;
    char *shbuf;
    unsigned int len;

    branch=t->nr_of_outgoings;
    if (branch==MAX_BRANCHES) {
        LOG(L_ERR, "ERROR: add_uac: maximum number of branches exceeded\n");
        ret=E_CFG;
        goto error;
    }

    /* check existing buffer -- rewriting should never occur */
    if (t->uac[branch].request.buffer) {
        LOG(L_CRIT, "ERROR: add_uac: buffer rewrite attempt\n");
        ret=ser_error=E_BUG;
        goto error;
    }

    /* check DNS resolution */
    if (proxy) {
        temp_proxy=0;
        proto=get_proto(proto, proxy->proto);
    } else {
        proxy=uri2proxy( next_hop ? next_hop : uri, proto );
        if (proxy==0)  {
            ret=E_BAD_ADDRESS;
            goto error;
        }
        proto=proxy->proto; /* uri2proxy will fix it for us */
        temp_proxy=1;
    }

    if (proxy->ok==0) {
        if (proxy->host.h_addr_list[proxy->addr_idx+1])
            proxy->addr_idx++;
        else proxy->addr_idx=0;
        proxy->ok=1;
    }

    hostent2su( &to, &proxy->host, proxy->addr_idx,
                proxy->port ? proxy->port:SIP_PORT);

    send_sock=get_send_socket( request, &to , proto);
    if (send_sock==0) {
        LOG(L_ERR, "ERROR: add_uac: can't fwd to af %d, proto %d "
            " (no corresponding listening socket)\n",
            to.s.sa_family, proto );
        ret=ser_error=E_NO_SOCKET;
        goto error01;
    }

    /* now message printing starts ... */
    shbuf=print_uac_request( t, request, branch, uri,
                             &len, send_sock, proto );
    if (!shbuf) {
        ret=ser_error=E_OUT_OF_MEM;
        goto error01;
    }

    /* things went well, move ahead and install new buffer! */
    t->uac[branch].request.dst.to=to;
    t->uac[branch].request.dst.send_sock=send_sock;
    t->uac[branch].request.dst.proto=proto;
    t->uac[branch].request.dst.proto_reserved1=0;
    t->uac[branch].request.buffer=shbuf;
    t->uac[branch].request.buffer_len=len;
    t->uac[branch].uri.s=t->uac[branch].request.buffer+
                         request->first_line.u.request.method.len+1;
    t->uac[branch].uri.len=uri->len;
    t->nr_of_outgoings++;

    /* update stats */
    proxy->tx++;
    proxy->tx_bytes+=len;

    /* done! */
    ret=branch;

error01:
    if (temp_proxy) {
        free_proxy( proxy );
        pkg_free( proxy );
    }
error:
    return ret;
}
예제 #24
0
static int ppp_rx(struct sk_buff *skb)
{
	struct hdlc_header *hdr = (struct hdlc_header*)skb->data;
	struct net_device *dev = skb->dev;
	struct ppp *ppp = get_ppp(dev);
	struct proto *proto;
	struct cp_header *cp;
	unsigned long flags;
	unsigned int len;
	u16 pid;
#if DEBUG_CP
	int i;
	char *ptr;
#endif

	spin_lock_irqsave(&ppp->lock, flags);
	/* Check HDLC header */
	if (skb->len < sizeof(struct hdlc_header))
		goto rx_error;
	cp = (struct cp_header*)skb_pull(skb, sizeof(struct hdlc_header));
	if (hdr->address != HDLC_ADDR_ALLSTATIONS ||
	    hdr->control != HDLC_CTRL_UI)
		goto rx_error;

	pid = ntohs(hdr->protocol);
	proto = get_proto(dev, pid);
	if (!proto) {
		if (ppp->protos[IDX_LCP].state == OPENED)
			ppp_tx_cp(dev, PID_LCP, LCP_PROTO_REJ,
				  ++ppp->seq, skb->len + 2, &hdr->protocol);
		goto rx_error;
	}

	len = ntohs(cp->len);
	if (len < sizeof(struct cp_header) /* no complete CP header? */ ||
	    skb->len < len /* truncated packet? */)
		goto rx_error;
	skb_pull(skb, sizeof(struct cp_header));
	len -= sizeof(struct cp_header);

	/* HDLC and CP headers stripped from skb */
#if DEBUG_CP
	if (cp->code < CP_CODES)
		sprintf(debug_buffer, "[%s id 0x%X]", code_names[cp->code],
			cp->id);
	else
		sprintf(debug_buffer, "[code %u id 0x%X]", cp->code, cp->id);
	ptr = debug_buffer + strlen(debug_buffer);
	for (i = 0; i < min_t(unsigned int, len, DEBUG_CP); i++) {
		sprintf(ptr, " %02X", skb->data[i]);
		ptr += strlen(ptr);
	}
	printk(KERN_DEBUG "%s: RX %s %s\n", dev->name, proto_name(pid),
	       debug_buffer);
#endif

	/* LCP only */
	if (pid == PID_LCP)
		switch (cp->code) {
		case LCP_PROTO_REJ:
			pid = ntohs(*(__be16*)skb->data);
			if (pid == PID_LCP || pid == PID_IPCP ||
			    pid == PID_IPV6CP)
				ppp_cp_event(dev, pid, RXJ_BAD, 0, 0,
					     0, NULL);
			goto out;

		case LCP_ECHO_REQ: /* send Echo-Reply */
			if (len >= 4 && proto->state == OPENED)
				ppp_tx_cp(dev, PID_LCP, LCP_ECHO_REPLY,
					  cp->id, len - 4, skb->data + 4);
			goto out;

		case LCP_ECHO_REPLY:
			if (cp->id == ppp->echo_id)
				ppp->last_pong = jiffies;
			goto out;

		case LCP_DISC_REQ: /* discard */
			goto out;
		}

	/* LCP, IPCP and IPV6CP */
	switch (cp->code) {
	case CP_CONF_REQ:
		ppp_cp_parse_cr(dev, pid, cp->id, len, skb->data);
		goto out;

	case CP_CONF_ACK:
		if (cp->id == proto->cr_id)
			ppp_cp_event(dev, pid, RCA, 0, 0, 0, NULL);
		goto out;

	case CP_CONF_REJ:
	case CP_CONF_NAK:
		if (cp->id == proto->cr_id)
			ppp_cp_event(dev, pid, RCN, 0, 0, 0, NULL);
		goto out;

	case CP_TERM_REQ:
		ppp_cp_event(dev, pid, RTR, 0, cp->id, 0, NULL);
		goto out;

	case CP_TERM_ACK:
		ppp_cp_event(dev, pid, RTA, 0, 0, 0, NULL);
		goto out;

	case CP_CODE_REJ:
		ppp_cp_event(dev, pid, RXJ_BAD, 0, 0, 0, NULL);
		goto out;

	default:
		len += sizeof(struct cp_header);
		if (len > dev->mtu)
			len = dev->mtu;
		ppp_cp_event(dev, pid, RUC, 0, 0, len, cp);
		goto out;
	}
	goto out;

rx_error:
	dev->stats.rx_errors++;
out:
	spin_unlock_irqrestore(&ppp->lock, flags);
	dev_kfree_skb_any(skb);
	ppp_tx_flush();
	return NET_RX_DROP;
}
예제 #25
0
/* SCA: RCR+ must supply id, len and data
   SCN: RCR- must supply code, id, len and data
   STA: RTR must supply id
   SCJ: RUC must supply CP packet len and data */
static void ppp_cp_event(struct net_device *dev, u16 pid, u16 event, u8 code,
			 u8 id, unsigned int len, const void *data)
{
	int old_state, action;
	struct ppp *ppp = get_ppp(dev);
	struct proto *proto = get_proto(dev, pid);

	old_state = proto->state;
	BUG_ON(old_state >= STATES);
	BUG_ON(event >= EVENTS);

#if DEBUG_STATE
	printk(KERN_DEBUG "%s: %s ppp_cp_event(%s) %s ...\n", dev->name,
	       proto_name(pid), event_names[event], state_names[proto->state]);
#endif

	action = cp_table[event][old_state];

	proto->state = action & STATE_MASK;
	if (action & (SCR | STR)) /* set Configure-Req/Terminate-Req timer */
		mod_timer(&proto->timer, proto->timeout =
			  jiffies + ppp->req_timeout * HZ);
	if (action & ZRC)
		proto->restart_counter = 0;
	if (action & IRC)
		proto->restart_counter = (proto->state == STOPPING) ?
			ppp->term_retries : ppp->cr_retries;

	if (action & SCR)	/* send Configure-Request */
		ppp_tx_cp(dev, pid, CP_CONF_REQ, proto->cr_id = ++ppp->seq,
			  0, NULL);
	if (action & SCA)	/* send Configure-Ack */
		ppp_tx_cp(dev, pid, CP_CONF_ACK, id, len, data);
	if (action & SCN)	/* send Configure-Nak/Reject */
		ppp_tx_cp(dev, pid, code, id, len, data);
	if (action & STR)	/* send Terminate-Request */
		ppp_tx_cp(dev, pid, CP_TERM_REQ, ++ppp->seq, 0, NULL);
	if (action & STA)	/* send Terminate-Ack */
		ppp_tx_cp(dev, pid, CP_TERM_ACK, id, 0, NULL);
	if (action & SCJ)	/* send Code-Reject */
		ppp_tx_cp(dev, pid, CP_CODE_REJ, ++ppp->seq, len, data);

	if (old_state != OPENED && proto->state == OPENED) {
		printk(KERN_INFO "%s: %s up\n", dev->name, proto_name(pid));
		if (pid == PID_LCP) {
			netif_dormant_off(dev);
			ppp_cp_event(dev, PID_IPCP, START, 0, 0, 0, NULL);
			ppp_cp_event(dev, PID_IPV6CP, START, 0, 0, 0, NULL);
			ppp->last_pong = jiffies;
			mod_timer(&proto->timer, proto->timeout =
				  jiffies + ppp->keepalive_interval * HZ);
		}
	}
	if (old_state == OPENED && proto->state != OPENED) {
		printk(KERN_INFO "%s: %s down\n", dev->name, proto_name(pid));
		if (pid == PID_LCP) {
			netif_dormant_on(dev);
			ppp_cp_event(dev, PID_IPCP, STOP, 0, 0, 0, NULL);
			ppp_cp_event(dev, PID_IPV6CP, STOP, 0, 0, 0, NULL);
		}
	}
	if (old_state != CLOSED && proto->state == CLOSED)
		del_timer(&proto->timer);

#if DEBUG_STATE
	printk(KERN_DEBUG "%s: %s ppp_cp_event(%s) ... %s\n", dev->name,
	       proto_name(pid), event_names[event], state_names[proto->state]);
#endif
}
예제 #26
0
/* WARNING: doesn't work from failure route (deadlock, uses t_reply => tries
 *  to get the reply lock again */
int t_relay_to( struct sip_msg  *p_msg , struct proxy_l *proxy, int proto,
				int replicate)
{
	int ret;
	int new_tran;
	int reply_ret;
	/* struct hdr_field *hdr; */
	struct cell *t;
	struct dest_info dst;
	unsigned short port;
	str host;
	short comp;

	ret=0;
	
	new_tran = t_newtran( p_msg );
	
	/* parsing error, memory alloc, whatever ... if via is bad
	   and we are forced to reply there, return with 0 (->break),
	   pass error status otherwise

       MMA: return value E_SCRIPT means that transaction was already started from the script
	   so continue with that transaction
	*/
	if (new_tran!=E_SCRIPT) {
		if (new_tran<0) {
			ret = (ser_error==E_BAD_VIA && reply_to_via) ? 0 : new_tran;
			goto done;
		}
		/* if that was a retransmission, return we are happily done */
		if (new_tran==0) {
			ret = 1;
			goto done;
		}
	}

	/* new transaction */

	/* ACKs do not establish a transaction and are fwd-ed statelessly */
	if ( p_msg->REQ_METHOD==METHOD_ACK) {
		DBG( "SER: forwarding ACK  statelessly \n");
		if (proxy==0) {
			init_dest_info(&dst);
			dst.proto=proto;
			if (get_uri_send_info(GET_NEXT_HOP(p_msg), &host, &port,
									&dst.proto, &comp)!=0){
				ret=E_BAD_ADDRESS;
				goto done;
			}
#ifdef USE_COMP
			dst.comp=comp;
#endif
			/* dst->send_sock not set, but forward_request will take care
			 * of it */
			ret=forward_request(p_msg, &host, port, &dst);
		} else {
			init_dest_info(&dst);
			dst.proto=get_proto(proto, proxy->proto);
			proxy2su(&dst.to, proxy);
			/* dst->send_sock not set, but forward_request will take care
			 * of it */
			ret=forward_request( p_msg , 0, 0, &dst) ;
		}
		goto done;
	}

	/* if replication flag is set, mark the transaction as local
	   so that replies will not be relayed */
	t=get_t();
	if (replicate) t->flags|=T_IS_LOCAL_FLAG;

	/* INVITE processing might take long, particularly because of DNS
	   look-ups -- let upstream know we're working on it */
	if (p_msg->REQ_METHOD==METHOD_INVITE )
	{
		DBG( "SER: new INVITE\n");
		if (!t_reply( t, p_msg , 100 ,
			"trying -- your call is important to us"))
				DBG("SER: ERROR: t_reply (100)\n");
	} 

	/* now go ahead and forward ... */
	ret=t_forward_nonack(t, p_msg, proxy, proto);
	if (ret<=0) {
		DBG( "ERROR:tm:t_relay_to:  t_forward_nonack returned error \n");
		/* we don't want to pass upstream any reply regarding replicating
		 * a request; replicated branch must stop at us*/
		if (!replicate) {
			reply_ret=kill_transaction( t );
			if (reply_ret>0) {
				/* we have taken care of all -- do nothing in
			  	script */
				DBG("ERROR: generation of a stateful reply "
					"on error succeeded\n");
				/*ret=0; -- we don't want to stop the script */
			}  else {
				DBG("ERROR: generation of a stateful reply "
					"on error failed\n");
				t_release_transaction(t);
			}
		}else{
			t_release_transaction(t); /* kill it  silently */
		}
	} else {
		DBG( "SER: new transaction fwd'ed\n");
	}

done:
	return ret;
}
예제 #27
0
int t_relay_to( struct sip_msg  *p_msg , struct proxy_l *proxy, int proto,
				int replicate)
{
	int ret;
	int new_tran;
	str *uri;
	int reply_ret;
	/* struct hdr_field *hdr; */
	struct cell *t;

	ret=0;

	new_tran = t_newtran( p_msg );

	/* parsing error, memory alloc, whatever ... if via is bad
	   and we are forced to reply there, return with 0 (->break),
	   pass error status otherwise
	*/
	if (new_tran<0) {
		ret = (ser_error==E_BAD_VIA && reply_to_via) ? 0 : new_tran;
		goto done;
	}
	/* if that was a retransmission, return we are happily done */
	if (new_tran==0) {
		ret = 1;
		goto done;
	}

	/* new transaction */

	/* ACKs do not establish a transaction and are fwd-ed statelessly */
	if ( p_msg->REQ_METHOD==METHOD_ACK) {
		DBG("DEBUG:tm:t_relay: forwarding ACK  statelessly \n");
		if (proxy==0) {
			uri = GET_RURI(p_msg);
			proxy=uri2proxy(GET_NEXT_HOP(p_msg), proto);
			if (proxy==0) {
					ret=E_BAD_ADDRESS;
					goto done;
			}
			proto=proxy->proto; /* uri2proxy set it correctly */
			ret=forward_request( p_msg , proxy, proto) ;
			free_proxy( proxy );	
			pkg_free( proxy );
		} else {
			proto=get_proto(proto, proxy->proto);
			ret=forward_request( p_msg , proxy, proto ) ;
		}
		goto done;
	}

	/* if replication flag is set, mark the transaction as local
	   so that replies will not be relaied */
	t=get_t();
	if (replicate) t->flags|=T_IS_LOCAL_FLAG;

	/* INVITE processing might take long, particularly because of DNS
	   look-ups -- let upstream know we're working on it */
	if (p_msg->REQ_METHOD==METHOD_INVITE )
	{
		DBG("DEBUG:tm:t_relay: new INVITE\n");
		if (!t_reply( t, p_msg , 100 ,
			"trying -- your call is important to us"))
				DBG("SER: ERROR: t_reply (100)\n");
	} 

	/* now go ahead and forward ... */
	ret=t_forward_nonack(t, p_msg, proxy, proto);
	if (ret<=0) {
		DBG( "ERROR:tm:t_relay_to:  t_forward_nonack returned error \n");
		/* we don't want to pass upstream any reply regarding replicating
		 * a request; replicated branch must stop at us*/
		if (!replicate) {
			reply_ret=kill_transaction( t );
			if (reply_ret>0) {
				/* we have taken care of all -- do nothing in
			  	script */
				DBG("ERROR: generation of a stateful reply "
					"on error succeeded\n");
				ret=0;
			}  else {
				DBG("ERROR: generation of a stateful reply "
					"on error failed\n");
			}
		}
	} else {
		DBG( "SER: new transaction fwd'ed\n");
	}

done:
	return ret;
}