Esempio n. 1
0
static void _asn_fcdir(thash *hash, const char *path, mmatic *mm)
{
	struct dirent *dirp;
	DIR *subd;
	char *np, *v;
	uint32_t len;

	if (!(subd = opendir(path)))
		die("opendir(%s) failed: %m\n", path);

	while ((dirp = readdir(subd))) {
		if (dirp->d_name[0] == '.') continue;

		np = (streq(path, ".")) ? dirp->d_name : mmprintf("%s/%s", path, dirp->d_name);
		if (asn_isdir(np) == 1) {
			_asn_fcdir(hash, np, mm);
		}
		else {
			v = asn_readfile(np, mm);
			if (!v) die("%s: could not read config file (%m)\n", np); /* fopen() failed */

			/* trim endlines at the end */
			len = strlen(v);
			if (len && v[len-1] == '\n') v[len-1] = '\0';

			thash_set(hash, np, v);
		}
	}

	closedir(subd);
}
Esempio n. 2
0
struct spi_ep *ep_new_pkt(struct spi_source *source, spi_epaddr_t epa,
	const struct timeval *ts, void *data, uint32_t size)
{
	struct spi *spi = source->spi;
	struct spi_ep *ep;
	char *key;
	struct spi_pkt *pkt;
	mmatic *mm;

	key = _k(source, epa);
	ep = thash_get(spi->eps, key);
	if (!ep) {
		mm = mmatic_create();
		ep = mmatic_zalloc(mm, sizeof *ep);
		ep->mm = mm;
		ep->source = source;
		ep->epa = epa;
		thash_set(spi->eps, key, ep);

		source->eps++;

		dbg(8, "new ep %s\n", spi_epa2a(epa));
	}

	/* make packet */
	pkt = mmatic_zalloc(ep->mm, sizeof *pkt);
	pkt->size = size;
	pkt->payload = mmatic_zalloc(ep->mm, spi->options.N);
	memcpy(pkt->payload, data, spi->options.N);
	memcpy(&pkt->ts, ts, sizeof(struct timeval));

	/* update last packet time */
	memcpy(&ep->last, ts, sizeof(struct timeval));

	/* store packet */
	if (!ep->pkts)
		ep->pkts = tlist_create(mmatic_free, ep->mm);

	tlist_push(ep->pkts, pkt);

	/* generate event if pkts big enough */
	if (ep->gclock1 == 0 && tlist_count(ep->pkts) >= spi->options.C) {
		ep->gclock1++;
		spi_announce(spi, "endpointPacketsReady", 0, ep, false);
		dbg(7, "ep %s ready\n", spi_epa2a(epa));
	}

	return ep;
}
Esempio n. 3
0
static void pkt(struct lfc *lfc, void *pdata,
	struct lfc_flow *lf, void *data,
	double ts, bool up, bool is_new, libtrace_packet_t *pkt)
{
	struct flow *f = data;
	char *name, *uri;
	libtrace_out_t *out;

	if (f->ignore)
		return;

	if (is_new) {
		/* find the flow by its id in the ARFF file, get output file name */
		name = thash_uint_get(fd->cache, lf->id);
		if (!name) {
			cache_update();
			name = thash_uint_get(fd->cache, lf->id);
			if (!name) {
				f->ignore = true;
				thash_uint_set(fd->cache, lf->id, NULL);
				return;
			}
		}

		/* ignore flows with column values we are not interested in */
		if (fd->value && !streq(fd->value, name)) {
			f->ignore = true;
			thash_uint_set(fd->cache, lf->id, NULL);
			return;
		}

		/* get libtrace output file */
		out = thash_get(fd->out_files, name);
		if (!out) {
			uri = mmatic_sprintf(fd->mm, "pcap:%s/%s.pcap", fd->dir, name);

			out = trace_create_output(uri);
			if (!out) {
				cleanup();
				die("trace_create_output(%s) failed\n", uri);
			}

			if (trace_is_err_output(out)) {
				trace_perror_output(out, "Opening output trace file");
				cleanup();
				die("trace_create_output(%s) failed\n", uri);
			}

			if (trace_start_output(out) == -1) {
				trace_perror_output(out, "Starting output trace");
				cleanup();
				die("trace_start_output(%s) failed\n", uri);
			}

			thash_set(fd->out_files, name, out);
		}

		f->out = out;

		/* remove id from cache */
		thash_uint_set(fd->cache, lf->id, NULL);
	}

	trace_write_packet(f->out, pkt);
	if (trace_is_err_output(f->out)) {
		trace_perror_output(f->out, "Writing packet to output trace file");
		cleanup();
		die("trace_write_packet() failed\n");
	}
}
Esempio n. 4
0
static inline void _set_flow(struct spi_source *source, spi_epaddr_t src, spi_epaddr_t dst, struct spi_flow *flow)
{
	thash_set(source->spi->flows, _k(source, src, dst), flow);
}