Esempio n. 1
0
void mowgli_simple_eventloop_timeout_once(mowgli_eventloop_t *eventloop, int timeout)
{
	time_t delay, currtime;
	int t;

	return_if_fail(eventloop != NULL);
	return_if_fail(eventloop->eventloop_ops != NULL);

	mowgli_eventloop_synchronize(eventloop);

	currtime = mowgli_eventloop_get_time(eventloop);
	delay = mowgli_eventloop_next_timer(eventloop);

	while (delay <= currtime)
	{
		mowgli_eventloop_run_timers(eventloop);
		mowgli_eventloop_synchronize(eventloop);

		currtime = mowgli_eventloop_get_time(eventloop);
		delay = mowgli_eventloop_next_timer(eventloop);
	}

	if (timeout)
		t = timeout;
	else
		t = (delay - currtime) * 1000;

#ifdef DEBUG
	mowgli_log("delay: %ld, currtime: %ld, select period: %d", delay, currtime, t);
#endif

	eventloop->eventloop_ops->select(eventloop, t);

}
Esempio n. 2
0
static banrecord_t *
trigger_ban(trigger_t *t, packet_info_t *packet, iprecord_t *irec)
{
	banrecord_t *rec;
	prefix_t *pfx;
	patricia_node_t *node;
	struct in_addr sin;

	switch (t->type) {
	case TRIGGER_SRC:
		sin.s_addr = packet->pkt_src.s_addr;
		break;
	case TRIGGER_DST:
	default:
		sin.s_addr = packet->pkt_dst.s_addr;
		break;
	};

	if (ban_find(sin.s_addr) != NULL)
		return NULL;

	rec = calloc(sizeof(banrecord_t), 1);

	rec->trigger = t;
	memcpy(&rec->irec, irec, sizeof(iprecord_t));
	memcpy(&rec->pkt, packet, sizeof(packet_info_t));
	rec->added = mowgli_eventloop_get_time(eventloop);
	rec->expiry_ts = rec->added + (t->expiry ? t->expiry : expiry);

	pfx = New_Prefix(AF_INET, &sin, 32);

	node = patricia_lookup(banrecord_trie, pfx);
	node->data = rec;

	Deref_Prefix(pfx);

	run_triggers(ACTION_BAN, t, packet, rec);

	rec->timer = mowgli_timer_add_once(eventloop, "expire_dynamic_trigger", expire_dynamic_trigger, rec, (t->expiry ? t->expiry : expiry));

	return rec;
}
Esempio n. 3
0
/**********************************************************************************
 * netlink glue                                                                   *
 **********************************************************************************/
static void
linux_handle(mowgli_eventloop_t *eventloop, mowgli_eventloop_io_t *io, mowgli_eventloop_io_dir_t dir, void *userdata)
{
	mowgli_eventloop_pollable_t *pollable = mowgli_eventloop_io_pollable(io);
	unsigned char buffer[BUFSIZ];
	size_t len;

	while ((len = recvfrom(pollable->fd, buffer, BUFSIZ, 0, NULL, NULL)) >= 14)
	{
		packet_info_t info;

		info.packets = 1;

		info.len = len;
		info.ts.tv_sec = mowgli_eventloop_get_time(eventloop);
		info.ts.tv_usec = 0;

		info.new_flow = 0;

		dissect_ethernet(&info, buffer);
	}
}