bool test_tcp_established_state_handle( void ) { struct sk_buff *skb; struct session_entry session; bool success = true; /* A V4 FIN packet arrives. */ if (!init_skb_and_session(&skb, &session, PACKET_TYPE_V4_FIN, ESTABLISHED, 10)) return false; success &= assert_true(tcp_established_state_handle( skb, &session ), "V4 fin-result"); success &= assert_equals_u8(V4_FIN_RCV, session.state, "V4 fin-state"); success &= assert_equals_int(10, session.dying_time, "V4 fin-lifetime"); kfree_skb(skb); /* A V6 FIN packet arrives. */ if (!init_skb_and_session(&skb, &session, PACKET_TYPE_V6_FIN, ESTABLISHED, 10)) return false; success &= assert_true(tcp_established_state_handle( skb, &session ), "V6 fin-result"); success &= assert_equals_u8(V6_FIN_RCV, session.state, "V6 fin-state"); success &= assert_equals_int(10, session.dying_time, "V6 fin-lifetime"); kfree_skb(skb); /* A V4 RST packet arrives. */ if (!init_skb_and_session(&skb, &session, PACKET_TYPE_V4_RST, ESTABLISHED, 10)) return false; success &= assert_true(tcp_established_state_handle( skb, &session ), "V4 rst-result"); success &= assert_equals_u8(TRANS, session.state, "V4 rst-state"); success &= assert_not_equals_int(10, session.dying_time, "V4 rst-lifetime"); kfree_skb(skb); /* A V6 RST packet arrives. */ if (!init_skb_and_session(&skb, &session, PACKET_TYPE_V6_RST, ESTABLISHED, 10)) return false; success &= assert_true(tcp_established_state_handle( skb, &session ), "V6 rst-result"); success &= assert_equals_u8(TRANS, session.state, "V6 rst-state"); success &= assert_not_equals_int(10, session.dying_time, "V6 rst-lifetime"); kfree_skb(skb); /* Something else arrives. */ if (!init_skb_and_session(&skb, &session, PACKET_TYPE_V4_SYN, ESTABLISHED, 10)) return false; success &= assert_true(tcp_established_state_handle(skb, &session), "else-result"); success &= assert_equals_u8(ESTABLISHED, session.state, "else-state"); success &= assert_not_equals_int(10, session.dying_time, "else-lifetime"); kfree_skb(skb); return success; }
/* * Something else arrives. */ static bool test_tcp_established_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, ESTABLISHED); 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_established_state_handle(&pkt, session, &expirer), "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_established_state_handle_v6fin(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_IPV6, false, false, true))) return false; if (is_error(pkt_init_ipv6(&pkt, skb))) return false; /* Evaluate */ success &= assert_equals_int(0, tcp_established_state_handle(&pkt, session, &expirer), "result"); success &= assert_equals_u8(V6_FIN_RCV, session->state, "V6 fin-state"); success &= assert_null(session->expirer, "null expirer"); kfree_skb(skb); return success; }