Esempio n. 1
0
unsigned int
peak_netmap_attach(const char *ifname)
{
	struct my_ring *slot = NULL;
	struct my_ring **me = NULL;
	struct pollfd *fd = NULL;
	unsigned int i;

	NETMAP_LOCK();

	/* lazy init */
	if (!NETMAP_COUNT()) {
		bzero(self, sizeof(*self));

		prealloc_init(&self->pkt_pool, NETMAP_MAX,
		    sizeof(struct _peak_netmap));
		prealloc_init(&self->me_pool, NETMAP_MAX,
		    sizeof(struct my_ring));
	}

	i = peak_netmap_find(ifname);
	if (i < NETMAP_COUNT()) {
		NETMAP_UNLOCK();
		alert("netmap interface %s already attached\n");
		return (1);
	}

	slot = NETMAP_GET();
	if (!slot) {
		NETMAP_UNLOCK();
		alert("netmap interface capacity reached\n");
		return (1);
	}

	bzero(slot, sizeof(*slot));

	me = &self->me[NETMAP_COUNT() - 1];
	fd = &self->fd[NETMAP_COUNT() - 1];

	slot->ifname = strdup(ifname);

	if (netmap_open(slot, 0, 1)) {
		free(slot->ifname);
		NETMAP_PUT(slot);
		NETMAP_UNLOCK();
		alert("could not open netmap device %s\n", ifname);
		return (1);
	}

	*me = slot;

	fd->fd = slot->fd;

	NETMAP_UNLOCK();

	return (0);
}
Esempio n. 2
0
static void
init_commands(void)
{
	attr_init();
	bmap_init();
	fadvise_init();
	file_init();
	freeze_init();
	fsync_init();
	getrusage_init();
	help_init();
	imap_init();
	inject_init();
	madvise_init();
	mincore_init();
	mmap_init();
	open_init();
	parent_init();
	pread_init();
	prealloc_init();
	fiemap_init();
	pwrite_init();
	quit_init();
	resblks_init();
	sendfile_init();
	shutdown_init();
	truncate_init();
}
Esempio n. 3
0
struct peak_tracks *
peak_track_init(const size_t max_flows)
{
	struct peak_tracks *self = zalloc(sizeof(*self));

	if (!self) {
		return (NULL);
	}

	if (!prealloc_init(&self->mem, max_flows,
	    sizeof(struct peak_track))) {
		free(self);
		return (NULL);
	}

	TAILQ_INIT(&self->tos);
	RB_INIT(&self->flows);

	return (self);
}