Beispiel #1
0
static struct thread_state *init_thread_state(struct packet_module *packet_module,
		int thread_id, bool dissector_graph)
{
	struct thread_state *state;

	assert(packet_module);

	state = malloc(sizeof(struct thread_state));
	if (!state) {
		return NULL;
	}

	memset(state, 0, sizeof(struct thread_state));

	state->thread_id = thread_id;
	state->packet_module = packet_module;
	state->state = STATE_NOTSARTED;
	state->engine = NULL;

	LOG_INFO(core, "initializing thread %d", thread_id);

	state->lua = lua_state_init();
	if (!state->lua) {
		LOG_FATAL(core, "unable to create lua state");
		cleanup_thread_state(state);
		return NULL;
	}

	/* Set grammar debugging */
	lua_getglobal(state->lua->L, "haka");
	lua_getfield(state->lua->L, -1, "grammar");
	lua_pushboolean(state->lua->L, dissector_graph);
	lua_setfield(state->lua->L, -2, "debug");

	/* Set state machine debugging */
	lua_getglobal(state->lua->L, "haka");
	lua_getfield(state->lua->L, -1, "state_machine");
	lua_pushboolean(state->lua->L, dissector_graph);
	lua_setfield(state->lua->L, -2, "debug");

	/* Load Lua sources */
	lua_state_require(state->lua, "rule");
	lua_state_require(state->lua, "rule_group");
	lua_state_require(state->lua, "interactive");
	lua_state_require(state->lua, "protocol/raw");

	state->capture = packet_module->init_state(thread_id);
	if (!state->capture) {
		LOG_FATAL(core, "unable to create packet capture state");
		cleanup_thread_state(state);
		return NULL;
	}

	return state;
}
Beispiel #2
0
static int run_console(int fd, int argc, char *argv[])
{
	struct lua_state *state;
	struct luadebug_user *user;

	state = lua_state_init();
	if (!state) {
		messagef(HAKA_LOG_FATAL, "hakactl", clear_error());
		return COMMAND_FAILED;
	}

	console_fd = fd;

	lua_pushcfunction(state->L, luaopen_hakactl);
	lua_call(state->L, 0, 1);
	lua_setglobal(state->L, "hakactl");

	if (!initialize_console(state)) {
		messagef(HAKA_LOG_FATAL, "hakactl", clear_error());
		lua_state_close(state);
		return COMMAND_FAILED;
	}

	user = luadebug_user_readline();
	if (!user) {
		messagef(HAKA_LOG_FATAL, "hakactl", clear_error());
		lua_state_close(state);
		return COMMAND_FAILED;
	}

	/* Load Lua console utilities */
	luadebug_interactive_enter(state->L, ">  ", ">> ", NULL, -1, user);
	luadebug_user_release(&user);

	lua_state_close(state);

	return COMMAND_SUCCESS;
}