int create_tcp_packet(struct sk_buff **skb, l3_protocol l3_proto, bool syn, bool rst, bool fin) { struct tcphdr *hdr_tcp; struct tuple tuple; int error; switch (l3_proto) { case L3PROTO_IPV4: error = init_tuple4(&tuple, "8.7.6.5", 8765, "5.6.7.8", 5678, L4PROTO_TCP); if (error) return error; error = create_skb4_tcp(&tuple, skb, 100, 32); if (error) return error; break; case L3PROTO_IPV6: error = init_tuple6(&tuple, "1::2", 1212, "3::4", 3434, L4PROTO_TCP); if (error) return error; error = create_skb6_tcp(&tuple, skb, 100, 32); if (error) return error; break; } hdr_tcp = tcp_hdr(*skb); hdr_tcp->syn = syn; hdr_tcp->rst = rst; hdr_tcp->fin = fin; return 0; }
static bool test_determine_in_tuple_ipv6(void) { struct packet pkt; struct sk_buff *skb; struct tuple actual, expected; bool success = true; if (is_error(init_ipv6_tuple(&expected, "1::2", 1212, "3::4", 3434, L4PROTO_TCP))) return false; if (is_error(create_skb6_tcp(&expected, &skb, 8, 32))) return false; if (is_error(pkt_init_ipv6(&pkt, skb))) return false; success &= assert_equals_int(VERDICT_CONTINUE, determine_in_tuple(&pkt, &actual), "verdict"); success &= assert_equals_tuple(&expected, &actual, "tuple"); kfree_skb(skb); return success; }