Esempio n. 1
0
static char *test_linkedlist_insert_two() {
	linkedlist_t list;
	linkedlist_init(&list);

	int x = 1;
	linkedlist_insert(&list, &x);

	mu_assert_equals_int("Error: Invalid head value", 
		x, 
		*(int *)linkedlist_gethead(&list));

	int y = 2;
	linkedlist_insert(&list, &y);

	mu_assert_equals_int("Error: Invalid head value", 
		x, 
		*(int *)linkedlist_gethead(&list));

	mu_assert_equals_int("Error: Invalid tail value", 
		y, 
		*(int *)linkedlist_gettail(&list));

	mu_assert_equals_int("Error: incorrect size.", 2, linkedlist_getsize(&list));

	linkedlist_destroy(&list);
	return 0;
}
Esempio n. 2
0
File: nat.c Progetto: xHire/wrapsix
/**
 * Remove expired connections from NAT.
 */
void nat_cleaning(void)
{
	linkedlist_node_t *tmp;
	time_t curtime = time(NULL);

	/* TCP FRAGMENTS	[2 secs] */
	tmp = timeout_tcp_fragments->first.next;
	while (tmp->next != NULL && curtime - tmp->time >= 2) {
		tmp = tmp->next;

		/* destroy queue */
		linkedlist_destroy(((struct s_nat_fragments *)
				    tmp->prev->data)->queue);

		/* remove connection */
		nat_in_fragments_cleanup(nat4_tcp_fragments,
					 ((struct s_nat_fragments *)
					  tmp->prev->data)->connection->ipv4,
					 ((struct s_nat_fragments *)
					  tmp->prev->data)->id);

		free(((struct s_nat_fragments *) tmp->prev->data)->connection);
		free(tmp->prev->data);

		linkedlist_delete(timeout_tcp_fragments, tmp->prev);
	}

	/* ICMP		[60 secs] */
	tmp = timeout_icmp->first.next;
	while (tmp->next != NULL && curtime - tmp->time >= 60) {
		tmp = tmp->next;
		nat_delete_connection(nat4_icmp, nat6_icmp, tmp->prev->data);
		linkedlist_delete(timeout_icmp, tmp->prev);
	}

	/* TCP -- TRANS	[4 mins] */
	tmp = timeout_tcp_trans->first.next;
	while (tmp->next != NULL && curtime - tmp->time >= 4 * 60) {
		tmp = tmp->next;
		nat_delete_connection(nat4_tcp, nat6_tcp, tmp->prev->data);
		linkedlist_delete(timeout_tcp_trans, tmp->prev);
	}

	/* UDP		[5 mins (minimum is 2 mins)] */
	tmp = timeout_udp->first.next;
	while (tmp->next != NULL && curtime - tmp->time >= 5 * 60) {
		tmp = tmp->next;
		nat_delete_connection(nat4_udp, nat6_udp, tmp->prev->data);
		linkedlist_delete(timeout_udp, tmp->prev);
	}

	/* TCP -- EST	[2 hrs and 4 mins] */
	tmp = timeout_tcp_est->first.next;
	while (tmp->next != NULL && curtime - tmp->time >= 124 * 60) {
		tmp = tmp->next;
		nat_delete_connection(nat4_tcp, nat6_tcp, tmp->prev->data);
		linkedlist_delete(timeout_tcp_est, tmp->prev);
	}
}
Esempio n. 3
0
void hash_destroy(struct hash *h)
{
	for(size_t index = 0;index < h->length;index++) {
		if(h->table[index])
			linkedlist_destroy(h->table[index]);
	}
	kfree(h->table);
	mutex_destroy(&h->lock);
	KOBJ_DESTROY(h, HASH_ALLOC);
}
Esempio n. 4
0
__attribute__((noinline)) static void tm_process_exit(int code)
{
	spinlock_acquire(&current_thread->status_lock);
	if(code != -9) 
		current_process->exit_reason.cause = __EXIT;
	current_process->exit_reason.ret = code;
	current_process->exit_reason.pid = current_process->pid;
	spinlock_release(&current_thread->status_lock);

	/* update times */
	if(current_process->parent) {
		time_t total_utime = current_process->utime + current_process->cutime;
		time_t total_stime = current_process->stime + current_process->cstime;
		atomic_fetch_add_explicit(&current_process->parent->cutime,
				total_utime, memory_order_relaxed);
		atomic_fetch_add_explicit(&current_process->parent->cstime,
				total_stime, memory_order_relaxed);
	}
	file_close_all();
	if(current_process->root)
		vfs_icache_put(current_process->root);
	if(current_process->cwd)
		vfs_icache_put(current_process->cwd);
	mutex_destroy(&current_process->fdlock);
	mm_destroy_all_mappings(current_process);
	linkedlist_destroy(&(current_process->mappings));
	valloc_destroy(&current_process->mmf_valloc);

	/* this is done before SIGCHILD is sent out */
	atomic_fetch_or(&current_process->flags, PROCESS_EXITED);
	if(current_process->parent) {
		struct process *init = tm_process_get(0);
		assert(init);
		
		__linkedlist_lock(process_list);
		struct process *child;
		struct linkedentry *node;
		for(node = linkedlist_iter_start(process_list);
				node != linkedlist_iter_end(process_list);
				node = linkedlist_iter_next(node)) {
			child = linkedentry_obj(node);
			if(child->parent == current_process) {
				tm_process_inc_reference(init);
				child->parent = init;
				tm_process_put(current_process);
			}
		}
		__linkedlist_unlock(process_list);
		tm_signal_send_process(current_process->parent, SIGCHILD);
		tm_blocklist_wakeall(&current_process->waitlist);
		tm_process_put(init);
	}
	tm_process_put(current_process); /* fork starts us out at refs = 1 */
}
Esempio n. 5
0
File: nat.c Progetto: xHire/wrapsix
/**
 * Clean-up of NAT tables.
 */
void nat_quit(void)
{
	/* 128 + 16 + 32 + 16 = 192 / 6 = 32 */
	radixtree_destroy(nat6_tcp,  32);
	radixtree_destroy(nat6_udp,  32);
	radixtree_destroy(nat6_icmp, 32);

	/* 32 + 16 + 16 + 8 = 72 / 6 = 12 */
	radixtree_destroy(nat4_tcp,  12);
	radixtree_destroy(nat4_udp,  12);
	radixtree_destroy(nat4_icmp, 12);

	/* 32 + 16 = 48 / 6 = 8 */
	radixtree_destroy(nat4_tcp_fragments, 8);

	linkedlist_destroy(timeout_icmp);
	linkedlist_destroy(timeout_udp);
	linkedlist_destroy(timeout_tcp_est);
	linkedlist_destroy(timeout_tcp_trans);
	linkedlist_destroy(timeout_tcp_fragments);
}
Esempio n. 6
0
static char *test_linkedlist_insert_one() {
	linkedlist_t list;
	linkedlist_init(&list);

	int x = 5;
	linkedlist_insert(&list, &x);

	mu_assert_equals_int("Error: insert error.", x, *(int *)linkedlist_gethead(&list));
	mu_assert_equals_int("Error: incorrect size.", 1, linkedlist_getsize(&list));

	linkedlist_destroy(&list);
	return 0;
}
Esempio n. 7
0
void proc_mngr_destroy(proc_mngr *ptr)
{
  KASSERT(ptr != NULL);

  spinlock_cleanup(&ptr->run_lk);
  lock_destroy(ptr->write_lk);
  lock_destroy(ptr->read_lk);
  lock_destroy(ptr->proc_sys_lk);
  lock_destroy(ptr->file_sys_lk);
  Linked_List_Node *runner = ptr->free_ids->first;
  while(runner != NULL){
    kfree(runner->data);
    runner = runner->next;
  }
  linkedlist_destroy(ptr->free_ids);
  multi_queue_destroy(ptr->ready_queue);
  kfree(ptr->threads);
  kfree(ptr->procs);
  kfree(ptr);
}
Esempio n. 8
0
static char *test_linkedlist_remove() {
	linkedlist_t list;
	linkedlist_init(&list);

	int x = 1, y = 2, z = 3;
	linkedlist_insert(&list, &x); 
	linkedlist_insert(&list, &y);
	linkedlist_insert(&list, &z);

	mu_assert_equals_int("Error: head value", x, *(int *)linkedlist_gethead(&list));
	mu_assert_equals_int("Error: tail value", z, *(int *)linkedlist_gettail(&list));
	mu_assert_equals_int("Error: size value before remove", 3, linkedlist_getsize(&list));

	linkedlist_remove(&list, &y);

	mu_assert_equals_int("Error: head value", x, *(int *)linkedlist_gethead(&list));
	mu_assert_equals_int("Error: tail value", z, *(int *)linkedlist_gettail(&list));
	mu_assert_equals_int("Error: size value after remove", 2, linkedlist_getsize(&list));

	linkedlist_destroy(&list);
	return 0;
}