/* * A V6 RST packet arrives. */ static bool test_tcp_trans_state_handle_v6rst(void) { struct session_entry *session; struct expire_timer *expirer; struct packet pkt; struct sk_buff *skb; 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_IPV6, false, true, false))) return false; if (is_error(pkt_init_ipv6(&pkt, skb))) return false; /* Evaluate */ success &= assert_equals_int(0, tcp_trans_state_handle(&pkt, session, &expirer), "V6 rst-result"); success &= assert_equals_u8(TRANS, session->state, "V6 rst-state"); success &= assert_null(session->expirer, "null expirer"); kfree_skb(skb); return success; }
/* * 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; }
/* * 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; }
/* * A V4 FIN packet arrives. */ static bool test_tcp_established_state_handle_v4fin(void) { struct session_entry *session; struct expire_timer *expirer; struct packet pkt; struct sk_buff *skb; 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_IPV4, false, false, true))) return false; if (is_error(pkt_init_ipv4(&pkt, skb))) return false; /* Evaluate */ success &= assert_equals_int(0, tcp_established_state_handle(&pkt, session, &expirer), "result"); success &= assert_equals_u8(V4_FIN_RCV, session->state, "V4 fin-state"); success &= assert_null(session->expirer, "null expirer"); kfree_skb(skb); return success; }
/* * 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; }
/** * "ars" means add, remove, send */ static bool test_pkt_queue_ars(void) { struct session_entry *session; struct sk_buff *skb; struct tuple tuple4; struct tcphdr *hdr_tcp; bool success = true; /* Prepare */ if (is_error(init_ipv4_tuple(&tuple4, "5.6.7.8", 5678, "192.168.2.1", 8765, L4PROTO_TCP))) return false; session = session_create_str_tcp("1::2", 1212, "3::4", 3434, "192.168.2.1", 8765, "5.6.7.8", 5678, V4_INIT); /* The session entry that is supposed to be created in "tcp_close_state_handle". */ if (!session) return false; if (is_error(create_skb4_tcp(&tuple4, &skb, 100, 32))) { session_return(session); return false; } hdr_tcp = tcp_hdr(skb); hdr_tcp->syn = true; hdr_tcp->rst = false; hdr_tcp->fin = false; success &= assert_equals_int(0, pktqueue_add(session, skb), "pktqueue_add 1"); success &= assert_equals_int(0, pktqueue_remove(session), "pktqueue_remove 1"); success &= assert_equals_int(-ENOENT, pktqueue_send(session), "pktqueue_send 1"); success &= assert_equals_int(0, icmp64_pop(), "pktqueue not sent an icmp error"); session_return(session); /* kfree_skb(skb); "skb" kfreed when pktqueue_remove is executed */ return success; }
/* * Something else arrives. */ static bool test_tcp_v4_init_state_handle_else(void) { struct session_entry *session; struct expire_timer *expirer; struct sk_buff *skb; 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_INIT); 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_v4_init_state_handle(skb, session, &expirer), "else-result"); success &= assert_null(session->expirer, "null expirer"); kfree_skb(skb); return success; }