Example #1
0
int main(int argc, char **argv)
{
	struct producer_config pc;
	struct consumer_config cc;
	struct flow_table flowtable;
	pthread_t tid[4];

	if (argc != 2) {
		fprintf(stderr, "usage: %s <model-file>\n", argv[0]);
		return STATUS_ERROR;
	}

	if (setup_packet_capture(&pc, SENSOR_NETFILTER) != STATUS_OK) {
		fprintf(stderr, "%s: could not setup packet capture interface!\n", argv[0]);
		return STATUS_ERROR;
	}

	if (listen_for_requests(&cc, SENSOR_LISTEN_PORT) != STATUS_OK) {
		fprintf(stderr, "%s: error listening for client requests!\n", argv[0]);
		return STATUS_ERROR;
	}

	if ((cc.model = svm_load_model(argv[1])) == 0) {
		fprintf(stderr, "%s: could not open model file %s\n", argv[0], argv[1]);
		return STATUS_ERROR;
	}

	/* everything is sent in network byte order */
	cc.n_max_payload = htonl(PAYLOAD_BUFFER_LENGTH);

	/* initialize tables and stuff */
	flowtable_init(&flowtable, FLOWTABLE_BUCKETS, FLOWTABLE_RECORDS);
	cc.keep_going = &keep_going;
	pc.keep_going = &keep_going;
	cc.flowtable = &flowtable;
	pc.flowtable = &flowtable;

	if ((cc.x = (struct svm_node *)malloc(max_nr_attr * sizeof(struct svm_node))) == NULL) {
		fprintf(stderr, "%s: could not allocate memory for classifier!\n", argv[0]);
		flowtable_finit(&flowtable);
		svm_destroy_model(cc.model);
		close_pcap_interface(&pc.pcap);
		return STATUS_ERROR;
	}

	signal(SIGINT, siginthandler);
	signal(SIGPIPE, SIG_IGN);

	/* let the games begin! */
	if (pthread_create(&tid[0], NULL, produce_flowtable, (void *)&pc) != 0) {
		fprintf(stderr, "%s: could not spawn thread!\n", argv[0]);
		return STATUS_ERROR;
	}

	if (pthread_create(&tid[1], NULL, accept_connections_for_flows, (void *)&cc) != 0) {
		fprintf(stderr, "%s: could not spawn thread\n", argv[0]);
		return STATUS_ERROR;
	}

	consume_flowtable((void *)&cc);
	flowtable_finit(&flowtable);
	print_pcap_stats(stderr, &pc.pcap);
	close_pcap_interface(&pc.pcap);

	return STATUS_OK;
}
Example #2
0
int main(int argc, char **argv)
{
	struct producer_config pc;
	struct consumer_config cc;
	struct flow_table flowtable;
	pthread_t tid[4];
	int i;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s <network_interface>\n", argv[0]);
		fprintf(stderr, "For example: %s eth0\n", argv[0]);
		fprintf(stderr, "\t see %s for results\n", EU_LOG);
		return ERROR;
	}

	if(setup_packet_capture(&pc, argv[1], NETFILTER) != 0){
		fprintf(stderr, "%s: error setting up packet capture interface!\n", argv[0]);
		return ERROR;
	}

	if(listen_for_requests(&cc, SERVER_PORT) != 0){
		fprintf(stderr, "%s: error listening for client requests!\n", argv[0]);
		return ERROR;
	}

	if ((cc.model = svm_load_model(model_file)) == 0) {
		fprintf(stderr, "could not open model file %s\n", model_file);
		return ERROR;
	}

	signal(SIGINT, siginthandler);
	signal(SIGPIPE, SIG_IGN);
#ifdef EU_STATS
	signal(SIGALRM, sigalarmhandler);
	alarm(STAT_TIME);
	memset(&stats, 0, sizeof(struct eu_stats));
	cc.stats= &stats; pc.stats= &stats;
	pthread_mutex_init(&(update_mutex), NULL);
	cc.update_mutex= &update_mutex; pc.update_mutex= &update_mutex;
#endif

	/* everything is sent in network byte order */
	cc.n_max_payload = htonl(MAX_PAYLOAD);

	/* initialize tables and stuff */
	flowtable_init(&flowtable, FLOW_ENTRIES);
	cc.keep_going= &keep_going; pc.keep_going= &keep_going;
	cc.flowtable= &flowtable; pc.flowtable= &flowtable;

	if ((cc.x =
	     (struct svm_node *)malloc(max_nr_attr *
				       sizeof(struct svm_node))) == NULL) {
		fprintf(stderr, "could not allocate memory for svm_node!\n");
		flowtable_finit(&flowtable);
		svm_destroy_model(cc.model);
		close_pcap_interface(&pc.pcap);
		return 1;
	}

	/* let the games begin! */
	if (pthread_create(&tid[0], NULL, accept_connections_for_flows, (void *)&cc) != 0) {
		fprintf(stderr, "%s: could not spawn thread\n", argv[0]);
		return ERROR;
	}

	if (pthread_create(&tid[1], NULL, produce_flowtable, (void *)&pc) != 0) {
		fprintf(stderr, "could not spawn thread\n");
		return ERROR;
	}

	consume_flowtable(&cc);

	fprintf(stderr, "waiting for threads to quit....\n");
	/* done with everything */
	for(i=0; i < 2; ++i)
		if (pthread_join(tid[i], NULL) != 0)
			fprintf(stderr, "%s: error waiting for thread %ld\n", argv[0], tid[i]);

	svm_destroy_model(cc.model);
	flowtable_finit(&flowtable);

	print_pcap_stats(stdout, &pc.pcap);
	close_pcap_interface(&pc.pcap);

	return 0;
}
Example #3
0
int main(int argc, char **argv)
{
	struct producer_config pc;
	struct consumer_config cc;
	struct flow_table flowtable;
	pthread_t tid[4];

	if (argc != 2) {
		fprintf(stderr, "usage: %s <model-file>\n", argv[0]);
		return ERROR;
	}

	if (setup_packet_capture(&pc, NETFILTER) != 0) {
		fprintf(stderr,
			"%s: error setting up packet capture interface!\n",
			argv[0]);
		return ERROR;
	}

	if (listen_for_requests(&cc, SERVER_PORT) != 0) {
		fprintf(stderr, "%s: error listening for client requests!\n",
			argv[0]);
		return ERROR;
	}

	if ((cc.model = svm_load_model(argv[1])) == 0) {
		fprintf(stderr, "could not open model file %s\n", argv[1]);
		return ERROR;
	}

	/* everything is sent in network byte order */
	cc.n_max_payload = htonl(MAX_PAYLOAD);

	/* initialize tables and stuff */
	flowtable_init(&flowtable, FLOW_ENTRIES);
	cc.keep_going = &keep_going;
	pc.keep_going = &keep_going;
	cc.flowtable = &flowtable;
	pc.flowtable = &flowtable;

	if ((cc.x =
	     (struct svm_node *)malloc(max_nr_attr *
				       sizeof(struct svm_node))) == NULL) {
		fprintf(stderr, "could not allocate memory for svm_node!\n");
		flowtable_finit(&flowtable);
		svm_destroy_model(cc.model);
		close_pcap_interface(&pc.pcap);
		return 1;
	}

	if (init_send_buffers(&cc.sb, SEND_BUFFER_SIZE, SEND_BUFFERS) != 0) {
		fprintf(stderr, "could not initialize send buffers!\n");
		free(cc.x);
		flowtable_finit(&flowtable);
		svm_destroy_model(cc.model);
		close_pcap_interface(&pc.pcap);
		return 1;
	}

	signal(SIGINT, siginthandler);
	signal(SIGPIPE, SIG_IGN);

	/* let the games begin! */
	if (pthread_create(&tid[0], NULL, produce_flowtable, (void *)&pc) != 0) {
		fprintf(stderr, "could not spawn thread\n");
		return ERROR;
	}

	if (pthread_create(&tid[1], NULL, consume_flowtable, (void *)&cc) != 0) {
		fprintf(stderr, "could not spawn thread\n");
		return ERROR;
	}

	if (pthread_create
	    (&tid[2], NULL, accept_connections_for_flows, (void *)&cc) != 0) {
		fprintf(stderr, "%s: could not spawn thread\n", argv[0]);
		return ERROR;
	}
#if 0
	if (pthread_create(&tid[3], NULL, write_to_clients, (void *)&cc) != 0) {
		fprintf(stderr, "could not spawn thread\n");
		return ERROR;
	}
	/* done with everything */
	for (i = 0; i < 4; ++i)
		if (pthread_join(tid[i], NULL) != 0)
			fprintf(stderr, "%s: error waiting for thread %ld\n",
				argv[0], tid[i]);
#endif
	write_to_clients((void *)&cc);
	svm_destroy_model(cc.model);
	flowtable_finit(&flowtable);

	print_pcap_stats(stdout, &pc.pcap);
	close_pcap_interface(&pc.pcap);

	return 0;
}