Exemplo n.º 1
0
/*
 * Something else arrives.
 */
static bool test_tcp_trans_state_handle_else(void)
{
	struct session_entry *session;
	struct expire_timer *expirer;
	struct packet pkt;
	struct sk_buff *skb;
	unsigned long timeout = 0;
	bool success = true;

	/* Prepare */
	session = session_create_str_tcp("1::2", 1212, "3::4", 3434, "5.6.7.8", 5678, "8.7.6.5", 8765,
			TRANS);
	if (!session)
		return false;
	if (is_error(create_tcp_packet(&skb, L3PROTO_IPV4, true, false, false)))
		return false;
	if (is_error(pkt_init_ipv4(&pkt, skb)))
		return false;

	/* Evaluate */
	success &= assert_equals_int(0, tcp_trans_state_handle(&pkt, session, &expirer), "else-result");
	success &= assert_equals_u8(ESTABLISHED, session->state, "else-state");
	success &= assert_equals_int(0, sessiondb_get_timeout(session, &timeout), "else-toresult");
	success &= assert_equals_ulong(TCPEST_TIMEOUT, timeout, "else-lifetime");

	kfree_skb(skb);
	return success;
}
Exemplo n.º 2
0
/*
 * A V6 RST packet arrives.
 */
static bool test_tcp_established_state_handle_v6rst(void)
{
	struct session_entry *session;
	struct expire_timer *expirer;
	struct sk_buff *skb;
	unsigned long timeout;
	bool success = true;

	/* Prepare */
	session = session_create_str_tcp("1::2", 1212, "3::4", 3434, "5.6.7.8", 5678, "8.7.6.5", 8765,
			ESTABLISHED);
	if (!session)
		return false;
	if (is_error(create_tcp_packet(&skb, L3PROTO_IPV6, false, true, false)))
		return false;

	/* Evaluate */
	success &= assert_equals_int(0, tcp_established_state_handle(skb, session, &expirer), "result");
	success &= assert_equals_u8(TRANS, session->state, "V6 rst-state");
	success &= assert_equals_int(0, sessiondb_get_timeout(session, &timeout), "V6 rst-toresult");
	success &= assert_equals_ulong(TCPTRANS_TIMEOUT, timeout, "V6 rst-lifetime");

	kfree_skb(skb);
	return success;
}
Exemplo n.º 3
0
/*
 * A V6 FIN packet arrives.
 */
static bool test_tcp_v4_fin_rcv_state_handle_v6fin(void)
{
	struct session_entry *session;
	struct expire_timer *expirer;
	struct packet pkt;
	struct sk_buff *skb;
	unsigned long timeout = 0;
	bool success = true;

	/* Prepare */
	session = session_create_str_tcp("1::2", 1212, "3::4", 3434, "5.6.7.8", 5678, "8.7.6.5", 8765,
			V4_FIN_RCV);
	if (!session)
		return false;
	if (is_error(create_tcp_packet(&skb, L3PROTO_IPV6, false, false, true)))
		return false;
	if (is_error(pkt_init_ipv6(&pkt, skb)))
		return false;

	/* Evaluate */
	success &= assert_equals_int(0, tcp_v4_fin_rcv_state_handle(&pkt, session, &expirer), "V6 fin-result");
	success &= assert_equals_u8(V4_FIN_V6_FIN_RCV, session->state, "V6 fin-state");
	success &= assert_equals_int(0, sessiondb_get_timeout(session, &timeout), "V6 fin-toresult");
	success &= assert_equals_ulong(TCPTRANS_TIMEOUT, timeout, "V6 fin-lifetime");

	kfree_skb(skb);
	return success;
}
Exemplo n.º 4
0
static int session_entry_to_userspace(struct session_entry *entry, void *arg)
{
	struct nl_buffer *buffer = (struct nl_buffer *) arg;
	struct session_entry_usr entry_usr;
	unsigned long dying_time;
	int error;

	error = sessiondb_get_timeout(entry, &dying_time);
	if (error)
		return error;
	dying_time += entry->update_time;

	entry_usr.remote6 = entry->remote6;
	entry_usr.local6 = entry->local6;
	entry_usr.local4 = entry->local4;
	entry_usr.remote4 = entry->remote4;
	entry_usr.state = entry->state;
	entry_usr.dying_time = (dying_time > jiffies) ? jiffies_to_msecs(dying_time - jiffies) : 0;

	return nlbuffer_write(buffer, &entry_usr, sizeof(entry_usr));
}