Esempio n. 1
0
int wtp_send_ctx_req(wtp_handle_t* handle, unsigned char MAC[6])
{
	aslan_msg_t *msg = calloc(1, sizeof(aslan_msg_t));
	if (!msg)
	{
		errno = ENOMEM;
		perror("ASLAN message send error");
		return -1;
	}

	msg->sender_ip = handle->local_ip;
	msg->sender_port = handle->local_port;
	msg->msg_id = MSG_ID_CTX_REQ;
	msg->msg_length = MSG_LENGTH_CTX_REQ;

	msg->msg.ctx_req = calloc(1, sizeof(aslan_ctx_req_t));
	if (!msg->msg.ctx_req)
	{
		free_msg(&msg);
		return -1;
	}
	memcpy(msg->msg.ctx_req->MAC, MAC, 6);

	pipe_push(handle->msg_send_producer, &msg, 1);

	return 0;
}
Esempio n. 2
0
int wtp_send_disassoc_resp(wtp_handle_t* handle, unsigned char MAC[6])
{
	aslan_msg_t *msg = calloc(1, sizeof(aslan_msg_t));
	if (!msg)
	{
		errno = ENOMEM;
		perror("ASLAN message send error");
		return -1;
	}

	msg->sender_ip = handle->local_ip;
	msg->sender_port = handle->local_port;
	msg->msg_id = MSG_ID_DISASSOC_RESP;
	msg->msg_length = MSG_LENGTH_DISASSOC_RESP;

	msg->msg.disassoc_resp = calloc(1, sizeof(aslan_disassoc_resp_t));
	if (!msg->msg.disassoc_resp)
	{
		free_msg(&msg);
		return -1;
	}
	memcpy(msg->msg.disassoc_resp->MAC, MAC, 6);

	pipe_push(handle->msg_send_producer, &msg, 1);

	return 0;
}
Esempio n. 3
0
/**     
 * runs the current request through the queues
 * \param       msg
 * \param       forced_pipe     is >= 0 if a specific pipe should be used, < 0 otherwise
 * \return	-1 if drop needed, 1 if allowed
 */
static int pl_check(struct sip_msg * msg, str *pipeid)
{
	int ret;

	ret = pipe_push(msg, pipeid);

	return ret;
}
Esempio n. 4
0
static void
dt_send(const dt_env_t *env, void *buf, size_t len_buf)
{
	verbose(VERB_OPS, "dnstap: %s (unbound@%s)", env->identity, env->version);

	dt_message_t *event = dt_message_alloc(len_buf);
	event->length = len_buf;
	event->buffer = buf;
	verbose(VERB_OPS, "dnstap: queueing event (length %d)", event->length);

	pipe_push(env->so_producer, &event, 1);
	verbose(VERB_OPS, "dnstap: queued event");
}
Esempio n. 5
0
/**
 * runs the current request through the queues
 * \param	forced_pipe	is >= 0 if a specific pipe should be used, < 0 otherwise
 * \return -1 if drop needed, 1 if allowed
 */
static int rl_check(struct sip_msg * msg, int forced_pipe)
{
	int que_id, pipe_id, ret;
	str method = msg->first_line.u.request.method;

	LOCK_GET(rl_lock);
	if (forced_pipe < 0) {
		if (find_queue(msg, &que_id)) {
			pipe_id = que_id = 0;
			ret = 1;
			goto out_release;
		}
		pipe_id = *queues[que_id].pipe;
	} else {
		que_id = 0; 
		pipe_id = forced_pipe;
	}

	ret = pipe_push(msg, pipe_id);
out_release:
	LOCK_RELEASE(rl_lock);

	/* no locks here because it's only read and pipes[pipe_id] is always alloc'ed */
	LOG(L_DBG,
			"meth=%.*s queue=%d pipe=%d algo=%d limit=%d pkg_load=%d counter=%d "
			"load=%2.1lf => %s\n",
			method.len,
			method.s, 
			que_id, 
			pipe_id,
			*pipes[pipe_id].algo,
			*pipes[pipe_id].limit,
			*pipes[pipe_id].load,
			*pipes[pipe_id].counter, 
			*load_value,
			(ret == 1) ? "ACCEPT" : "DROP");
	
	return ret;
}
Esempio n. 6
0
/**     
 * runs the current request through the queues
 * \param       forced_pipe     is >= 0 if a specific pipe should be used, < 0 otherwise
 * \return	-1 if drop needed, 1 if allowed
 */
static int rl_check(struct sip_msg * msg, int forced_pipe)
{
	int que_id, pipe_id, ret;
	str method = msg->first_line.u.request.method;

	if (forced_pipe >=0 && (forced_pipe>=MAX_PIPES || *pipes[forced_pipe].algo==PIPE_ALGO_NOP)) {
		LM_ERR("forced pipe %d out of range or not defined "
			" => defaulting to method type checking\n", forced_pipe);
		forced_pipe = -1;
	}

	LOCK_GET(rl_lock);
	if (forced_pipe < 0) { 
		if (find_queue(msg, &que_id)) {
			pipe_id = que_id = 0;
			ret = 1;
			goto out_release;
		}
		pipe_id = *queues[que_id].pipe;
	} else {
		que_id = 0;
		pipe_id = forced_pipe;
	}

	ret = pipe_push(msg, pipe_id);
out_release:
	LOCK_RELEASE(rl_lock);

	/* no locks here because it's only read and pipes[pipe_id] is always alloc'ed */
	LM_DBG("meth=%.*s queue=%d pipe=%d algo=%d limit=%d pkg_load=%d counter=%d "
		"load=%2.1lf network_load=%d => %s\n",
		method.len, method.s, que_id, pipe_id,
		*pipes[pipe_id].algo, *pipes[pipe_id].limit,
		*pipes[pipe_id].load, *pipes[pipe_id].counter,
		*load_value, *network_load_value, (ret == 1) ? "ACCEPT" : "DROP");

	return ret;
}
Esempio n. 7
0
int wtp_send_assoc_resp(wtp_handle_t* handle, unsigned char MAC[6], void* sta_wtp_ctx, uint16_t ctx_length)
{
	if (ctx_length > (MSG_LENGTH_ASSOC_RESP - 9)) return -1;

	aslan_msg_t *msg = calloc(1, sizeof(aslan_msg_t));
	if (!msg)
	{
		errno = ENOMEM;
		perror("ASLAN message send error");
		return -1;
	}

	msg->sender_ip = handle->local_ip;
	msg->sender_port = handle->local_port;
	msg->msg_id = MSG_ID_ASSOC_RESP;
	msg->msg_length = MSG_LENGTH_ASSOC_RESP;

	msg->msg.assoc_resp = calloc(1, sizeof(aslan_assoc_resp_t));
	if (!msg->msg.assoc_resp)
	{
		free_msg(&msg);
		return -1;
	}
	memcpy(msg->msg.assoc_resp->MAC, MAC, 6);
	msg->msg.assoc_resp->sta_wtp_ctx = malloc(ctx_length);
	if (!msg->msg.assoc_resp->sta_wtp_ctx)
	{
		free_msg(&msg);
		return -1;
	}
	memcpy(msg->msg.assoc_resp->sta_wtp_ctx, sta_wtp_ctx, ctx_length);
	msg->msg.assoc_resp->sta_wtp_ctx_length = ctx_length;

	pipe_push(handle->msg_send_producer, &msg, 1);

	return 0;
}
Esempio n. 8
0
void *
__dt_worker(void *arg) {
	verbose(VERB_OPS, "dnstap: starting dt_worker thread");

	dt_env_t *env = (dt_env_t *) arg;
	struct sockaddr_in so_service;

	so_service.sin_family = AF_INET;
	so_service.sin_port = htons(5354);
	so_service.sin_addr.s_addr = inet_addr("127.0.0.1");
	memset(so_service.sin_zero, 0, sizeof so_service.sin_zero);

	if(!__dt_so_connect(env, so_service)) return NULL;

	// Pop events off of the queue
	dt_message_t * event;

	while(pipe_pop(env->so_consumer, &event, 1)) {
		if(send(env->so_socket, event, dt_message_size(event), 0) < 0) {
			verbose(VERB_OPS, "dnstap: error sending message: %s. Trying to reconnect", strerror(errno));

			// Requeue the event for later
			pipe_push(env->so_producer, &event, 1);

			// And try to reconnect
			close(env->so_socket);
			if(!__dt_so_connect(env, so_service)) return NULL;
		} else {
			verbose(VERB_OPS, "dnstap: sent event to dt_service");
			dt_message_free(event);
		}
	}

	verbose(VERB_OPS, "dnstap: stopping dt_worker thread");
	close(env->so_socket);
	pipe_consumer_free(env->so_consumer);
}
Esempio n. 9
0
void *receive_msg_thread(void *arg)
{
	assert(arg);
	wtp_handle_t* handle = (wtp_handle_t *) arg;
	struct sockaddr_in addr_sender = {0};
	addr_sender.sin_family = AF_INET;
	aslan_msg_t *msg = NULL;
	u32 msg_crc, prev_msg_crc = 0;
	unsigned char buf[ETH_DATA_LEN];
	int ret, buf_length, ip_length = sizeof(addr_sender);

	while (1)
	{
		buf_length = recvfrom(handle->udp_socket, buf, ETH_DATA_LEN, 0, (struct sockaddr *) &addr_sender, (socklen_t*) &ip_length);

		if (buf_length == -1)
		{
			perror("Receive ASLAN message error");
			continue;
		}

		msg = calloc(1, sizeof(aslan_msg_t));
		if (!msg)
		{
			errno = ENOMEM;
			perror("ASLAN message parse error");
			continue;
		}

		msg->sender_ip = ntohl(addr_sender.sin_addr.s_addr);
		msg->sender_port = ntohs(addr_sender.sin_port);

		ret = parse_msg(buf,buf_length,msg);
		if (ret == -1)
		{
			errno = ENOMEM;
			perror("ASLAN message parse error");
			free_msg(&msg);
			continue;
		}
		else if (ret == 1)
		{
			wpa_printf(MSG_ERROR, "ERROR: Received unexpected/invalid ASLAN message! Id: %d\n", buf[0]);
			free_msg(&msg);
			continue;
		}

		if (msg->sender_ip != handle->hds_ip)
		{
			wpa_printf(MSG_ERROR, "ERROR: Unexpected HDS IP address: %s\n", inet_ntoa(*(struct in_addr *) &msg->sender_ip));
			free_msg(&msg);
			continue;
		}

		if (msg->sender_port != handle->hds_port)
		{
			wpa_printf(MSG_ERROR, "ERROR: Unexpected HDS port: %u\n", msg->sender_port);
			free_msg(&msg);
			continue;
		}

		msg_crc = crc32((u8*) buf, buf_length);
		if ((prev_msg_crc) && (prev_msg_crc == msg_crc) && (msg->msg_id != MSG_ID_ACK))
		{
			free_msg(&msg);
			continue;
		}
		prev_msg_crc = msg_crc;

		pipe_push(handle->msg_recv_producer, &msg, 1);
	}

	pthread_exit(NULL);
    return NULL;
}
static int readCallback(uint8_t *buffer, int length, FTDIProgressInfo *progress, void *userdata)
{
  /*
   * Keep track of number of bytes read - don't record samples until we have
   * read a large number of bytes. We do this in order to flush out the FIFOs
   * in the FT232H and FPGA to ensure that the samples we receive are
   * continuous.
   */
  static uint64_t total_num_bytes_received = 0;

  /* Array for packing received samples into. */
  if (length){
    if (total_num_bytes_received >= NUM_FLUSH_BYTES){
      if (outputFile) {
        /*
         * Check each byte to see if a FIFO error occurred, and if not, write
         * samples to disk.
         * Format of received and saved bytes is :
         *   [7:5] : Sample 0 (MAX_I1, MAX_I0, MAX_Q1)
         *   [4:2] : Sample 1 (MAX_I1, MAX_I0, MAX_Q1)
         *   [1]   : Unused
         *   [0]   : FPGA FIFO Error flag, active low. Usually indicates
         *           bytes are not being read out of FPGA FIFO quickly enough
         *           to avoid overflow.
         * Note that sample_grabber doesn't know anything about the MAX2769's
         * output bit configuration - it just writes the received bits to disk.
         */
        if (exitRequested != 1) {
          /* Check each byte to see if a FIFO error occured. */
          for (uint64_t ci = 0; ci < length; ci++)
            if (FPGA_FIFO_ERROR_CHECK(buffer[ci])) {
              if (verbose)
                fprintf(stderr,"FPGA FIFO Error Flag at sample number %lld\n",
                       (long long int)(total_unflushed_bytes+ci));
              exitRequested = 1;
              break;
            }
          /* Push values into the pipe. */
          pipe_push(pipe_writer,(void *)buffer,length);
        }
      }
      total_unflushed_bytes += length;
    }
    total_num_bytes_received += length;
  }

  /* bytes_wanted = 0 means program was not run with a size argument. */
  if (bytes_wanted != 0 && total_unflushed_bytes >= bytes_wanted){
    exitRequested = 1;
  }

  /* Print progress : time elapsed, bytes transferred, transfer rate. */
  if (progress){
    if (verbose)
      printf("%10.02fs total time %9.3f MiB captured %7.1f kB/s curr %7.1f kB/s total\n",
              progress->totalTime,
              progress->current.totalBytes / (1024.0 * 1024.0),
              progress->currentRate / 1024.0,
              progress->totalRate / 1024.0);
  }

  return exitRequested ? 1 : 0;
}