2024-06-19 15:06:14 +08:00
|
|
|
#pragma once
|
2024-02-23 18:19:52 +08:00
|
|
|
|
2024-04-22 14:23:45 +08:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
2024-04-21 11:30:41 +08:00
|
|
|
#ifdef __cplusplus
|
2024-02-23 18:19:52 +08:00
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "udp_utils.h"
|
|
|
|
|
#include "tcp_utils.h"
|
2024-07-09 11:17:03 +08:00
|
|
|
#include "ip4_utils.h"
|
|
|
|
|
#include "ip6_utils.h"
|
2024-03-08 13:55:17 +08:00
|
|
|
#include "ip_reassembly.h"
|
2024-06-24 17:07:05 +08:00
|
|
|
#include "packet_def.h"
|
2024-06-14 19:24:27 +08:00
|
|
|
#include "packet_utils.h"
|
2024-06-24 17:07:05 +08:00
|
|
|
#include "packet_parse.h"
|
|
|
|
|
#include "packet_layer.h"
|
2024-02-23 18:19:52 +08:00
|
|
|
|
|
|
|
|
static inline void packet_set_ipv4_src_addr(struct packet *pkt, uint32_t saddr)
|
|
|
|
|
{
|
2024-06-14 10:48:11 +08:00
|
|
|
const struct raw_layer *ipv4_layer = packet_get_innermost_raw_layer(pkt, LAYER_PROTO_IPV4);
|
2024-02-23 18:19:52 +08:00
|
|
|
EXPECT_TRUE(ipv4_layer);
|
|
|
|
|
struct ip *hdr = (struct ip *)ipv4_layer->hdr_ptr;
|
2024-07-09 11:17:03 +08:00
|
|
|
ip4_hdr_set_src_addr(hdr, saddr);
|
2024-02-23 18:19:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void packet_set_ipv6_src_addr(struct packet *pkt, struct in6_addr saddr)
|
|
|
|
|
{
|
2024-06-14 10:48:11 +08:00
|
|
|
const struct raw_layer *ipv6_layer = packet_get_innermost_raw_layer(pkt, LAYER_PROTO_IPV6);
|
2024-02-23 18:19:52 +08:00
|
|
|
EXPECT_TRUE(ipv6_layer);
|
|
|
|
|
struct ip6_hdr *hdr = (struct ip6_hdr *)ipv6_layer->hdr_ptr;
|
2024-07-09 11:17:03 +08:00
|
|
|
ip6_hdr_set_src_in6_addr(hdr, saddr);
|
2024-02-23 18:19:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void packet_set_ipv6_frag_offset(struct packet *pkt, uint16_t offset)
|
|
|
|
|
{
|
2024-06-14 10:48:11 +08:00
|
|
|
const struct raw_layer *ipv6_layer = packet_get_innermost_raw_layer(pkt, LAYER_PROTO_IPV6);
|
2024-02-23 18:19:52 +08:00
|
|
|
EXPECT_TRUE(ipv6_layer);
|
|
|
|
|
struct ip6_hdr *hdr = (struct ip6_hdr *)ipv6_layer->hdr_ptr;
|
2024-07-09 11:17:03 +08:00
|
|
|
struct ip6_frag *frag_hdr = ip6_hdr_get_frag_ext(hdr);
|
2024-02-23 18:19:52 +08:00
|
|
|
EXPECT_TRUE(frag_hdr);
|
|
|
|
|
ipv6_frag_set_offset(frag_hdr, offset);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 13:55:17 +08:00
|
|
|
static inline void check_stat(struct ip_reassembly_stat *stat,
|
2024-02-23 18:19:52 +08:00
|
|
|
uint64_t ip4_flow_find, uint64_t ip4_flow_add, uint64_t ip4_flow_del, uint64_t ip4_flow_timeout,
|
|
|
|
|
uint64_t ip4_flow_fail_no_space, uint64_t ip4_flow_fail_overlap, uint64_t ip4_flow_fail_many_frag,
|
|
|
|
|
uint64_t ip4_flow_fail_invalid_length, uint64_t ip4_flow_bypass_dup_fist_frag, uint64_t ip4_flow_bypass_dup_last_frag,
|
|
|
|
|
uint64_t ip6_flow_find, uint64_t ip6_flow_add, uint64_t ip6_flow_del, uint64_t ip6_flow_timeout,
|
|
|
|
|
uint64_t ip6_flow_fail_no_space, uint64_t ip6_flow_fail_overlap, uint64_t ip6_flow_fail_many_frag,
|
|
|
|
|
uint64_t ip6_flow_fail_invalid_length, uint64_t ip6_flow_bypass_dup_fist_frag, uint64_t ip6_flow_bypass_dup_last_frag)
|
|
|
|
|
{
|
|
|
|
|
EXPECT_TRUE(stat != NULL);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(stat->ip4_flow_find == ip4_flow_find);
|
|
|
|
|
EXPECT_TRUE(stat->ip4_flow_add == ip4_flow_add);
|
|
|
|
|
EXPECT_TRUE(stat->ip4_flow_del == ip4_flow_del);
|
|
|
|
|
EXPECT_TRUE(stat->ip4_flow_timeout == ip4_flow_timeout);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(stat->ip4_flow_fail_no_space == ip4_flow_fail_no_space);
|
|
|
|
|
EXPECT_TRUE(stat->ip4_flow_fail_overlap == ip4_flow_fail_overlap);
|
|
|
|
|
EXPECT_TRUE(stat->ip4_flow_fail_many_frag == ip4_flow_fail_many_frag);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(stat->ip4_flow_fail_invalid_length == ip4_flow_fail_invalid_length);
|
|
|
|
|
EXPECT_TRUE(stat->ip4_flow_bypass_dup_fist_frag == ip4_flow_bypass_dup_fist_frag);
|
|
|
|
|
EXPECT_TRUE(stat->ip4_flow_bypass_dup_last_frag == ip4_flow_bypass_dup_last_frag);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(stat->ip6_flow_find == ip6_flow_find);
|
|
|
|
|
EXPECT_TRUE(stat->ip6_flow_add == ip6_flow_add);
|
|
|
|
|
EXPECT_TRUE(stat->ip6_flow_del == ip6_flow_del);
|
|
|
|
|
EXPECT_TRUE(stat->ip6_flow_timeout == ip6_flow_timeout);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(stat->ip6_flow_fail_no_space == ip6_flow_fail_no_space);
|
|
|
|
|
EXPECT_TRUE(stat->ip6_flow_fail_overlap == ip6_flow_fail_overlap);
|
|
|
|
|
EXPECT_TRUE(stat->ip6_flow_fail_many_frag == ip6_flow_fail_many_frag);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(stat->ip6_flow_fail_invalid_length == ip6_flow_fail_invalid_length);
|
|
|
|
|
EXPECT_TRUE(stat->ip6_flow_bypass_dup_fist_frag == ip6_flow_bypass_dup_fist_frag);
|
|
|
|
|
EXPECT_TRUE(stat->ip6_flow_bypass_dup_last_frag == ip6_flow_bypass_dup_last_frag);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-21 11:30:41 +08:00
|
|
|
#ifdef __cplusplus
|
2024-02-23 18:19:52 +08:00
|
|
|
}
|
|
|
|
|
#endif
|