rename ip_reassembly args name 'mgr' -> 'assembler'

This commit is contained in:
luwenpeng
2024-03-15 09:59:33 +08:00
parent ce00122557
commit 5b8d5610a2
4 changed files with 244 additions and 244 deletions

View File

@@ -14,7 +14,7 @@
#define IPV6_KEYLEN 4 #define IPV6_KEYLEN 4
#define PRIME_VALUE 0xeaad8405 #define PRIME_VALUE 0xeaad8405
#define IP_FRAG_HASH_FNUM 2 #define IP_FRAG_HASH_FNUM 2
#define IP_FRAG_TBL_POS(mgr, sig) ((mgr)->table + ((sig) & (mgr)->entry_mask)) #define IP_FRAG_TBL_POS(assembler, sig) ((assembler)->table + ((sig) & (assembler)->entry_mask))
#define KEY_TO_STR(key, str_str, dst_str) \ #define KEY_TO_STR(key, str_str, dst_str) \
do \ do \
@@ -136,15 +136,15 @@ struct ip_reassembly
* utils * utils
******************************************************************************/ ******************************************************************************/
#define ip_reassembly_stat_inc(mgr, filed, key) \ #define ip_reassembly_stat_inc(assembler, filed, key) \
{ \ { \
if ((key)->src_dst_len == IPV4_KEYLEN) \ if ((key)->src_dst_len == IPV4_KEYLEN) \
{ \ { \
(mgr)->stat.ip4_flow_##filed++; \ (assembler)->stat.ip4_flow_##filed++; \
} \ } \
else \ else \
{ \ { \
(mgr)->stat.ip6_flow_##filed++; \ (assembler)->stat.ip6_flow_##filed++; \
} \ } \
} }
@@ -402,7 +402,7 @@ static inline int ip_flow_is_ready(struct ip_flow *flow)
// return 0 : success // return 0 : success
// return -1 : failed // return -1 : failed
static inline int ip_flow_update(struct ip_reassembly *mgr, static inline int ip_flow_update(struct ip_reassembly *assembler,
struct ip_flow *flow, const struct packet *pkt, struct ip_flow *flow, const struct packet *pkt,
char *frag_data, uint16_t frag_len, uint16_t frag_offset, bool more_frags) char *frag_data, uint16_t frag_len, uint16_t frag_offset, bool more_frags)
{ {
@@ -424,7 +424,7 @@ static inline int ip_flow_update(struct ip_reassembly *mgr,
if (flow->frags[IP_FIRST_FRAG_IDX].data != NULL) if (flow->frags[IP_FIRST_FRAG_IDX].data != NULL)
{ {
IP_REASSEMBLE_DEBUG1("duplicate first fragment bypass", &flow->key); IP_REASSEMBLE_DEBUG1("duplicate first fragment bypass", &flow->key);
ip_reassembly_stat_inc(mgr, bypass_dup_fist_frag, &flow->key); ip_reassembly_stat_inc(assembler, bypass_dup_fist_frag, &flow->key);
return 0; return 0;
} }
idx = IP_FIRST_FRAG_IDX; idx = IP_FIRST_FRAG_IDX;
@@ -435,7 +435,7 @@ static inline int ip_flow_update(struct ip_reassembly *mgr,
if (flow->frags[IP_LAST_FRAG_IDX].data != NULL) if (flow->frags[IP_LAST_FRAG_IDX].data != NULL)
{ {
IP_REASSEMBLE_DEBUG1("duplicate last fragment bypass", &flow->key); IP_REASSEMBLE_DEBUG1("duplicate last fragment bypass", &flow->key);
ip_reassembly_stat_inc(mgr, bypass_dup_last_frag, &flow->key); ip_reassembly_stat_inc(assembler, bypass_dup_last_frag, &flow->key);
return 0; return 0;
} }
idx = IP_LAST_FRAG_IDX; idx = IP_LAST_FRAG_IDX;
@@ -446,7 +446,7 @@ static inline int ip_flow_update(struct ip_reassembly *mgr,
if (flow->next_fill_idx >= IP_MAX_FRAG_NUM) if (flow->next_fill_idx >= IP_MAX_FRAG_NUM)
{ {
IP_REASSEMBLE_ERROR1("max number of fragment exceeded", &flow->key); IP_REASSEMBLE_ERROR1("max number of fragment exceeded", &flow->key);
ip_reassembly_stat_inc(mgr, fail_many_frag, &flow->key); ip_reassembly_stat_inc(assembler, fail_many_frag, &flow->key);
return -1; return -1;
} }
idx = flow->next_fill_idx; idx = flow->next_fill_idx;
@@ -464,26 +464,26 @@ static inline int ip_flow_update(struct ip_reassembly *mgr,
* ip reassemble manager add/del/reuse/find/update flow * ip reassemble manager add/del/reuse/find/update flow
******************************************************************************/ ******************************************************************************/
static inline void ip_reassembly_add_flow(struct ip_reassembly *mgr, struct ip_flow *flow) static inline void ip_reassembly_add_flow(struct ip_reassembly *assembler, struct ip_flow *flow)
{ {
ip_reassembly_stat_inc(mgr, add, &flow->key); ip_reassembly_stat_inc(assembler, add, &flow->key);
TAILQ_INSERT_TAIL(&mgr->lru, flow, lru); TAILQ_INSERT_TAIL(&assembler->lru, flow, lru);
mgr->entry_used++; assembler->entry_used++;
} }
static inline void ip_reassembly_del_flow(struct ip_reassembly *mgr, struct ip_flow *flow) static inline void ip_reassembly_del_flow(struct ip_reassembly *assembler, struct ip_flow *flow)
{ {
ip_reassembly_stat_inc(mgr, del, &flow->key); ip_reassembly_stat_inc(assembler, del, &flow->key);
TAILQ_REMOVE(&mgr->lru, flow, lru); TAILQ_REMOVE(&assembler->lru, flow, lru);
mgr->entry_used--; assembler->entry_used--;
} }
static inline void ip_reassembly_reuse_flow(struct ip_reassembly *mgr, struct ip_flow *flow, const struct ip_flow_key *key, uint64_t now) static inline void ip_reassembly_reuse_flow(struct ip_reassembly *assembler, struct ip_flow *flow, const struct ip_flow_key *key, uint64_t now)
{ {
ip_reassembly_del_flow(mgr, flow); ip_reassembly_del_flow(assembler, flow);
ip_flow_free(flow); ip_flow_free(flow);
ip_flow_init(flow, key, now); ip_flow_init(flow, key, now);
ip_reassembly_add_flow(mgr, flow); ip_reassembly_add_flow(assembler, flow);
} }
/* /*
@@ -491,13 +491,13 @@ static inline void ip_reassembly_reuse_flow(struct ip_reassembly *mgr, struct ip
* free : the first empty entry in the bucket * free : the first empty entry in the bucket
* expired: the first timed-out entry in the bucket * expired: the first timed-out entry in the bucket
*/ */
static struct ip_flow *ip_reassembly_find_flow(struct ip_reassembly *mgr, const struct ip_flow_key *key, struct ip_flow **free, struct ip_flow **expired, uint64_t now) static struct ip_flow *ip_reassembly_find_flow(struct ip_reassembly *assembler, const struct ip_flow_key *key, struct ip_flow **free, struct ip_flow **expired, uint64_t now)
{ {
ip_reassembly_stat_inc(mgr, find, key); ip_reassembly_stat_inc(assembler, find, key);
if (mgr->last != NULL && ip_flow_key_cmp(key, &mgr->last->key) == 0) if (assembler->last != NULL && ip_flow_key_cmp(key, &assembler->last->key) == 0)
{ {
return mgr->last; return assembler->last;
} }
uint32_t sig1 = 0; uint32_t sig1 = 0;
@@ -512,14 +512,14 @@ static struct ip_flow *ip_reassembly_find_flow(struct ip_reassembly *mgr, const
} }
// get the bucket by hash // get the bucket by hash
struct ip_flow *p1 = IP_FRAG_TBL_POS(mgr, sig1); struct ip_flow *p1 = IP_FRAG_TBL_POS(assembler, sig1);
struct ip_flow *p2 = IP_FRAG_TBL_POS(mgr, sig2); struct ip_flow *p2 = IP_FRAG_TBL_POS(assembler, sig2);
// search in the bucket // search in the bucket
struct ip_flow *old = NULL; struct ip_flow *old = NULL;
struct ip_flow *empty = NULL; struct ip_flow *empty = NULL;
uint64_t timeout = mgr->timeout; uint64_t timeout = assembler->timeout;
uint32_t assoc = mgr->bucket_entries; uint32_t assoc = assembler->bucket_entries;
for (uint32_t i = 0; i != assoc; i++) for (uint32_t i = 0; i != assoc; i++)
{ {
if (ip_flow_key_cmp(key, &p1[i].key) == 0) if (ip_flow_key_cmp(key, &p1[i].key) == 0)
@@ -558,22 +558,22 @@ static struct ip_flow *ip_reassembly_find_flow(struct ip_reassembly *mgr, const
return NULL; return NULL;
} }
static struct ip_flow *ip_reassembly_update_flow(struct ip_reassembly *mgr, const struct ip_flow_key *key, uint64_t now) static struct ip_flow *ip_reassembly_update_flow(struct ip_reassembly *assembler, const struct ip_flow_key *key, uint64_t now)
{ {
struct ip_flow *flow = NULL; struct ip_flow *flow = NULL;
struct ip_flow *free = NULL; struct ip_flow *free = NULL;
struct ip_flow *expired = NULL; struct ip_flow *expired = NULL;
flow = ip_reassembly_find_flow(mgr, key, &free, &expired, now); flow = ip_reassembly_find_flow(assembler, key, &free, &expired, now);
if (flow == NULL) if (flow == NULL)
{ {
if (expired) if (expired)
{ {
IP_REASSEMBLE_DEBUG1("add ip flow success: reuse expired entry", key); IP_REASSEMBLE_DEBUG1("add ip flow success: reuse expired entry", key);
ip_reassembly_reuse_flow(mgr, expired, key, now); ip_reassembly_reuse_flow(assembler, expired, key, now);
ip_reassembly_stat_inc(mgr, timeout, key); ip_reassembly_stat_inc(assembler, timeout, key);
mgr->last = expired; assembler->last = expired;
return expired; return expired;
} }
@@ -581,27 +581,27 @@ static struct ip_flow *ip_reassembly_update_flow(struct ip_reassembly *mgr, cons
{ {
IP_REASSEMBLE_DEBUG1("add ip flow success: use free entry", key); IP_REASSEMBLE_DEBUG1("add ip flow success: use free entry", key);
ip_flow_init(free, key, now); ip_flow_init(free, key, now);
ip_reassembly_add_flow(mgr, free); ip_reassembly_add_flow(assembler, free);
mgr->last = free; assembler->last = free;
return free; return free;
} }
// no space // no space
IP_REASSEMBLE_ERROR1("add ip flow failed: bucket full", key); IP_REASSEMBLE_ERROR1("add ip flow failed: bucket full", key);
ip_reassembly_stat_inc(mgr, fail_no_space, key); ip_reassembly_stat_inc(assembler, fail_no_space, key);
return NULL; return NULL;
} }
else else
{ {
// expired // expired
if (mgr->timeout + flow->create_time <= now) if (assembler->timeout + flow->create_time <= now)
{ {
IP_REASSEMBLE_DEBUG1("add ip flow success: reuse expired entry", key); IP_REASSEMBLE_DEBUG1("add ip flow success: reuse expired entry", key);
ip_reassembly_reuse_flow(mgr, flow, key, now); ip_reassembly_reuse_flow(assembler, flow, key, now);
ip_reassembly_stat_inc(mgr, timeout, key); ip_reassembly_stat_inc(assembler, timeout, key);
mgr->last = flow; assembler->last = flow;
return flow; return flow;
} }
// not expired // not expired
@@ -609,7 +609,7 @@ static struct ip_flow *ip_reassembly_update_flow(struct ip_reassembly *mgr, cons
{ {
IP_REASSEMBLE_DEBUG1("find ip flow success: not expire", key); IP_REASSEMBLE_DEBUG1("find ip flow success: not expire", key);
mgr->last = flow; assembler->last = flow;
return flow; return flow;
} }
} }
@@ -619,7 +619,7 @@ static struct ip_flow *ip_reassembly_update_flow(struct ip_reassembly *mgr, cons
* frag reassemble * frag reassemble
******************************************************************************/ ******************************************************************************/
static struct packet *ip_frag_reassemble(struct ip_reassembly *mgr, struct ip_flow *flow) static struct packet *ip_frag_reassemble(struct ip_reassembly *assembler, struct ip_flow *flow)
{ {
struct ip_frag_pkt *first = &flow->frags[IP_FIRST_FRAG_IDX]; struct ip_frag_pkt *first = &flow->frags[IP_FIRST_FRAG_IDX];
struct ip_frag_pkt *last = &flow->frags[IP_LAST_FRAG_IDX]; struct ip_frag_pkt *last = &flow->frags[IP_LAST_FRAG_IDX];
@@ -735,12 +735,12 @@ static struct packet *ip_frag_reassemble(struct ip_reassembly *mgr, struct ip_fl
return pkt; return pkt;
error_out_invalid_length: error_out_invalid_length:
ip_reassembly_stat_inc(mgr, fail_invalid_length, &flow->key); ip_reassembly_stat_inc(assembler, fail_invalid_length, &flow->key);
packet_free(pkt); packet_free(pkt);
return NULL; return NULL;
error_out_overlap: error_out_overlap:
ip_reassembly_stat_inc(mgr, fail_overlap, &flow->key); ip_reassembly_stat_inc(assembler, fail_overlap, &flow->key);
packet_free(pkt); packet_free(pkt);
return NULL; return NULL;
} }
@@ -756,84 +756,84 @@ struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_options *opts
return NULL; return NULL;
} }
struct ip_reassembly *mgr = (struct ip_reassembly *)calloc(1, sizeof(struct ip_reassembly)); struct ip_reassembly *assembler = (struct ip_reassembly *)calloc(1, sizeof(struct ip_reassembly));
if (mgr == NULL) if (assembler == NULL)
{ {
IP_REASSEMBLE_ERROR("unable to allocate memory"); IP_REASSEMBLE_ERROR("unable to allocate memory");
return NULL; return NULL;
} }
mgr->enable = opts->enable; assembler->enable = opts->enable;
mgr->timeout = opts->timeout; assembler->timeout = opts->timeout;
mgr->bucket_entries = opts->bucket_entries; assembler->bucket_entries = opts->bucket_entries;
mgr->bucket_num = opts->bucket_num; assembler->bucket_num = opts->bucket_num;
if (!mgr->enable) if (!assembler->enable)
{ {
return mgr; return assembler;
} }
uint64_t entry_total = align32pow2(mgr->bucket_num) * mgr->bucket_entries * IP_FRAG_HASH_FNUM; uint64_t entry_total = align32pow2(assembler->bucket_num) * assembler->bucket_entries * IP_FRAG_HASH_FNUM;
if (entry_total > UINT32_MAX) if (entry_total > UINT32_MAX)
{ {
IP_REASSEMBLE_ERROR("bucket_num * bucket_entries is too large"); IP_REASSEMBLE_ERROR("bucket_num * bucket_entries is too large");
free(mgr); free(assembler);
return NULL; return NULL;
} }
mgr->entry_total = (uint32_t)entry_total; assembler->entry_total = (uint32_t)entry_total;
mgr->entry_mask = (mgr->entry_total - 1) & ~(mgr->bucket_entries - 1); assembler->entry_mask = (assembler->entry_total - 1) & ~(assembler->bucket_entries - 1);
mgr->table = (struct ip_flow *)calloc(mgr->entry_total, sizeof(struct ip_flow)); assembler->table = (struct ip_flow *)calloc(assembler->entry_total, sizeof(struct ip_flow));
if (mgr->table == NULL) if (assembler->table == NULL)
{ {
IP_REASSEMBLE_ERROR("unable to allocate memory"); IP_REASSEMBLE_ERROR("unable to allocate memory");
free(mgr); free(assembler);
return NULL; return NULL;
} }
TAILQ_INIT(&(mgr->lru)); TAILQ_INIT(&(assembler->lru));
return mgr; return assembler;
} }
void ip_reassembly_free(struct ip_reassembly *mgr) void ip_reassembly_free(struct ip_reassembly *assembler)
{ {
if (mgr) if (assembler)
{ {
if (mgr->table) if (assembler->table)
{ {
for (uint32_t i = 0; i < mgr->entry_total; i++) for (uint32_t i = 0; i < assembler->entry_total; i++)
{ {
ip_flow_free(mgr->table + i); ip_flow_free(assembler->table + i);
} }
free(mgr->table); free(assembler->table);
mgr->table = NULL; assembler->table = NULL;
} }
free(mgr); free(assembler);
mgr = NULL; assembler = NULL;
} }
} }
void ip_reassembly_expire(struct ip_reassembly *mgr, uint64_t now) void ip_reassembly_expire(struct ip_reassembly *assembler, uint64_t now)
{ {
struct ip_flow *flow = NULL; struct ip_flow *flow = NULL;
uint64_t timeout = mgr->timeout; uint64_t timeout = assembler->timeout;
TAILQ_FOREACH(flow, &mgr->lru, lru) TAILQ_FOREACH(flow, &assembler->lru, lru)
if (timeout + flow->create_time <= now) if (timeout + flow->create_time <= now)
{ {
IP_REASSEMBLE_DEBUG1("expire ip flow: discarding old fragmented packets", &flow->key); IP_REASSEMBLE_DEBUG1("expire ip flow: discarding old fragmented packets", &flow->key);
ip_reassembly_del_flow(mgr, flow); ip_reassembly_del_flow(assembler, flow);
ip_reassembly_stat_inc(mgr, timeout, &flow->key); ip_reassembly_stat_inc(assembler, timeout, &flow->key);
ip_flow_free(flow); ip_flow_free(flow);
} }
} }
struct ip_reassembly_stat *ip_reassembly_get_stat(struct ip_reassembly *mgr) struct ip_reassembly_stat *ip_reassembly_get_stat(struct ip_reassembly *assembler)
{ {
if (mgr) if (assembler)
{ {
return &(mgr->stat); return &(assembler->stat);
} }
else else
{ {
@@ -846,12 +846,12 @@ struct ip_reassembly_stat *ip_reassembly_get_stat(struct ip_reassembly *mgr)
* The returned packet should be freed by calling the packet_free() function * The returned packet should be freed by calling the packet_free() function
*/ */
struct packet *ip_reassembly_packet(struct ip_reassembly *mgr, const struct packet *pkt, uint64_t now) struct packet *ip_reassembly_packet(struct ip_reassembly *assembler, const struct packet *pkt, uint64_t now)
{ {
struct packet *pkt1; struct packet *pkt1;
struct packet *pkt2; struct packet *pkt2;
if (!mgr->enable) if (!assembler->enable)
{ {
return NULL; return NULL;
} }
@@ -864,10 +864,10 @@ struct packet *ip_reassembly_packet(struct ip_reassembly *mgr, const struct pack
if (layer->type == LAYER_TYPE_IPV4) if (layer->type == LAYER_TYPE_IPV4)
{ {
pkt1 = ipv4_reassembly_packet(mgr, pkt, now); pkt1 = ipv4_reassembly_packet(assembler, pkt, now);
if (pkt1 && pkt1->frag_layer) if (pkt1 && pkt1->frag_layer)
{ {
pkt2 = ip_reassembly_packet(mgr, pkt1, now); pkt2 = ip_reassembly_packet(assembler, pkt1, now);
packet_free(pkt1); packet_free(pkt1);
return pkt2; return pkt2;
} }
@@ -876,10 +876,10 @@ struct packet *ip_reassembly_packet(struct ip_reassembly *mgr, const struct pack
} }
else if (layer->type == LAYER_TYPE_IPV6) else if (layer->type == LAYER_TYPE_IPV6)
{ {
pkt1 = ipv6_reassembly_packet(mgr, pkt, now); pkt1 = ipv6_reassembly_packet(assembler, pkt, now);
if (pkt1 && pkt1->frag_layer) if (pkt1 && pkt1->frag_layer)
{ {
pkt2 = ip_reassembly_packet(mgr, pkt1, now); pkt2 = ip_reassembly_packet(assembler, pkt1, now);
packet_free(pkt1); packet_free(pkt1);
return pkt2; return pkt2;
} }
@@ -892,7 +892,7 @@ struct packet *ip_reassembly_packet(struct ip_reassembly *mgr, const struct pack
} }
} }
struct packet *ipv4_reassembly_packet(struct ip_reassembly *mgr, const struct packet *pkt, uint64_t now) struct packet *ipv4_reassembly_packet(struct ip_reassembly *assembler, const struct packet *pkt, uint64_t now)
{ {
const struct layer *layer = pkt->frag_layer; const struct layer *layer = pkt->frag_layer;
const struct ip *hdr = (const struct ip *)layer->hdr_ptr; const struct ip *hdr = (const struct ip *)layer->hdr_ptr;
@@ -911,7 +911,7 @@ struct packet *ipv4_reassembly_packet(struct ip_reassembly *mgr, const struct pa
key.ip_id = ipv4_hdr_get_ipid(hdr); key.ip_id = ipv4_hdr_get_ipid(hdr);
key.proto = ipv4_hdr_get_proto(hdr); key.proto = ipv4_hdr_get_proto(hdr);
struct ip_flow *flow = ip_reassembly_update_flow(mgr, &key, now); struct ip_flow *flow = ip_reassembly_update_flow(assembler, &key, now);
if (flow == NULL) if (flow == NULL)
{ {
return NULL; return NULL;
@@ -920,9 +920,9 @@ struct packet *ipv4_reassembly_packet(struct ip_reassembly *mgr, const struct pa
char *frag_data = (char *)layer->pld_ptr; char *frag_data = (char *)layer->pld_ptr;
bool more_frags = ipv4_hdr_get_mf_flag(hdr); bool more_frags = ipv4_hdr_get_mf_flag(hdr);
uint16_t frag_offset = ipv4_hdr_get_frag_offset(hdr); uint16_t frag_offset = ipv4_hdr_get_frag_offset(hdr);
if (ip_flow_update(mgr, flow, pkt, frag_data, frag_len, frag_offset, more_frags) != 0) if (ip_flow_update(assembler, flow, pkt, frag_data, frag_len, frag_offset, more_frags) != 0)
{ {
ip_reassembly_del_flow(mgr, flow); ip_reassembly_del_flow(assembler, flow);
ip_flow_free(flow); ip_flow_free(flow);
return NULL; return NULL;
} }
@@ -932,8 +932,8 @@ struct packet *ipv4_reassembly_packet(struct ip_reassembly *mgr, const struct pa
return NULL; return NULL;
} }
struct packet *new_pkt = ip_frag_reassemble(mgr, flow); struct packet *new_pkt = ip_frag_reassemble(assembler, flow);
ip_reassembly_del_flow(mgr, flow); ip_reassembly_del_flow(assembler, flow);
ip_flow_free(flow); ip_flow_free(flow);
return new_pkt; return new_pkt;
@@ -978,7 +978,7 @@ struct packet *ipv4_reassembly_packet(struct ip_reassembly *mgr, const struct pa
* +-----------------+-----------------+--------+--------+-//-+--------+ * +-----------------+-----------------+--------+--------+-//-+--------+
*/ */
struct packet *ipv6_reassembly_packet(struct ip_reassembly *mgr, const struct packet *pkt, uint64_t now) struct packet *ipv6_reassembly_packet(struct ip_reassembly *assembler, const struct packet *pkt, uint64_t now)
{ {
const struct layer *layer = pkt->frag_layer; const struct layer *layer = pkt->frag_layer;
const struct ip6_hdr *hdr = (const struct ip6_hdr *)layer->hdr_ptr; const struct ip6_hdr *hdr = (const struct ip6_hdr *)layer->hdr_ptr;
@@ -1003,7 +1003,7 @@ struct packet *ipv6_reassembly_packet(struct ip_reassembly *mgr, const struct pa
key.ip_id = ipv6_frag_get_ident(frag_hdr); key.ip_id = ipv6_frag_get_ident(frag_hdr);
key.proto = 0; // only first fragment has the upper layer protocol key.proto = 0; // only first fragment has the upper layer protocol
struct ip_flow *flow = ip_reassembly_update_flow(mgr, &key, now); struct ip_flow *flow = ip_reassembly_update_flow(assembler, &key, now);
if (flow == NULL) if (flow == NULL)
{ {
return NULL; return NULL;
@@ -1011,9 +1011,9 @@ struct packet *ipv6_reassembly_packet(struct ip_reassembly *mgr, const struct pa
bool more_frags = ipv6_frag_get_more(frag_hdr); bool more_frags = ipv6_frag_get_more(frag_hdr);
uint16_t frag_offset = ipv6_frag_get_offset(frag_hdr); uint16_t frag_offset = ipv6_frag_get_offset(frag_hdr);
if (ip_flow_update(mgr, flow, pkt, frag_data, frag_len, frag_offset, more_frags) != 0) if (ip_flow_update(assembler, flow, pkt, frag_data, frag_len, frag_offset, more_frags) != 0)
{ {
ip_reassembly_del_flow(mgr, flow); ip_reassembly_del_flow(assembler, flow);
ip_flow_free(flow); ip_flow_free(flow);
return NULL; return NULL;
} }
@@ -1023,8 +1023,8 @@ struct packet *ipv6_reassembly_packet(struct ip_reassembly *mgr, const struct pa
return NULL; return NULL;
} }
struct packet *new_pkt = ip_frag_reassemble(mgr, flow); struct packet *new_pkt = ip_frag_reassemble(assembler, flow);
ip_reassembly_del_flow(mgr, flow); ip_reassembly_del_flow(assembler, flow);
ip_flow_free(flow); ip_flow_free(flow);
return new_pkt; return new_pkt;

View File

@@ -51,17 +51,17 @@ struct ip_reassembly_stat
}; };
struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_options *opts); struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_options *opts);
void ip_reassembly_free(struct ip_reassembly *mgr); void ip_reassembly_free(struct ip_reassembly *assembler);
void ip_reassembly_expire(struct ip_reassembly *mgr, uint64_t now); void ip_reassembly_expire(struct ip_reassembly *assembler, uint64_t now);
struct ip_reassembly_stat *ip_reassembly_get_stat(struct ip_reassembly *mgr); struct ip_reassembly_stat *ip_reassembly_get_stat(struct ip_reassembly *assembler);
/* /*
* Returns the reassembled packet, or NULL if the packet is not reassembled * Returns the reassembled packet, or NULL if the packet is not reassembled
* The returned packet should be freed by calling the packet_free() function * The returned packet should be freed by calling the packet_free() function
*/ */
struct packet *ip_reassembly_packet(struct ip_reassembly *mgr, const struct packet *pkt, uint64_t now); struct packet *ip_reassembly_packet(struct ip_reassembly *assembler, const struct packet *pkt, uint64_t now);
struct packet *ipv4_reassembly_packet(struct ip_reassembly *mgr, const struct packet *pkt, uint64_t now); struct packet *ipv4_reassembly_packet(struct ip_reassembly *assembler, const struct packet *pkt, uint64_t now);
struct packet *ipv6_reassembly_packet(struct ip_reassembly *mgr, const struct packet *pkt, uint64_t now); struct packet *ipv6_reassembly_packet(struct ip_reassembly *assembler, const struct packet *pkt, uint64_t now);
#ifdef __cpluscplus #ifdef __cpluscplus
} }

View File

@@ -197,7 +197,7 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER)
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
const struct layer *layer; const struct layer *layer;
struct ip_reassembly *mgr; struct ip_reassembly *assembler;
struct ip_reassembly_options opts = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
@@ -205,10 +205,10 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER)
.bucket_num = 8, .bucket_num = 8,
}; };
mgr = ip_reassembly_new(&opts); assembler = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(assembler != NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -216,10 +216,10 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER)
// frag1 // frag1
packet_parse(&pkt, (const char *)frag1, sizeof(frag1)); packet_parse(&pkt, (const char *)frag1, sizeof(frag1));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
1, 1, 0, 0, // ip4: find, add, del, timeout 1, 1, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -227,10 +227,10 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER)
// frag2 // frag2
packet_parse(&pkt, (const char *)frag2, sizeof(frag2)); packet_parse(&pkt, (const char *)frag2, sizeof(frag2));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt); EXPECT_TRUE(new_pkt);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
2, 1, 1, 0, // ip4: find, add, del, timeout 2, 1, 1, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -280,7 +280,7 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER)
// free packet // free packet
packet_free(new_pkt); packet_free(new_pkt);
ip_reassembly_free(mgr); ip_reassembly_free(assembler);
} }
#endif #endif
@@ -290,7 +290,7 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER)
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
const struct layer *layer; const struct layer *layer;
struct ip_reassembly *mgr; struct ip_reassembly *assembler;
struct ip_reassembly_options opts = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
@@ -298,10 +298,10 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER)
.bucket_num = 8, .bucket_num = 8,
}; };
mgr = ip_reassembly_new(&opts); assembler = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(assembler != NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -309,10 +309,10 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER)
// frag2 // frag2
packet_parse(&pkt, (const char *)frag2, sizeof(frag2)); packet_parse(&pkt, (const char *)frag2, sizeof(frag2));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
1, 1, 0, 0, // ip4: find, add, del, timeout 1, 1, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -320,10 +320,10 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER)
// frag1 // frag1
packet_parse(&pkt, (const char *)frag1, sizeof(frag1)); packet_parse(&pkt, (const char *)frag1, sizeof(frag1));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt); EXPECT_TRUE(new_pkt);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
2, 1, 1, 0, // ip4: find, add, del, timeout 2, 1, 1, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -373,7 +373,7 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER)
// free packet // free packet
packet_free(new_pkt); packet_free(new_pkt);
ip_reassembly_free(mgr); ip_reassembly_free(assembler);
} }
#endif #endif
@@ -382,7 +382,7 @@ TEST(IPV4_REASSEMBLE, EXPIRE)
{ {
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
struct ip_reassembly *mgr; struct ip_reassembly *assembler;
struct ip_reassembly_options opts = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
@@ -390,10 +390,10 @@ TEST(IPV4_REASSEMBLE, EXPIRE)
.bucket_num = 8, .bucket_num = 8,
}; };
mgr = ip_reassembly_new(&opts); assembler = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(assembler != NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -401,10 +401,10 @@ TEST(IPV4_REASSEMBLE, EXPIRE)
// frag1 // frag1
packet_parse(&pkt, (const char *)frag1, sizeof(frag1)); packet_parse(&pkt, (const char *)frag1, sizeof(frag1));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
1, 1, 0, 0, // ip4: find, add, del, timeout 1, 1, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -412,10 +412,10 @@ TEST(IPV4_REASSEMBLE, EXPIRE)
// frag2 // frag2
packet_parse(&pkt, (const char *)frag2, sizeof(frag2)); packet_parse(&pkt, (const char *)frag2, sizeof(frag2));
new_pkt = ip_reassembly_packet(mgr, &pkt, 2); new_pkt = ip_reassembly_packet(assembler, &pkt, 2);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
2, 2, 1, 1, // ip4: find, add, del, timeout 2, 2, 1, 1, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -424,7 +424,7 @@ TEST(IPV4_REASSEMBLE, EXPIRE)
// free packet // free packet
packet_free(new_pkt); packet_free(new_pkt);
ip_reassembly_free(mgr); ip_reassembly_free(assembler);
} }
#endif #endif
@@ -434,7 +434,7 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
const struct layer *layer; const struct layer *layer;
struct ip_reassembly *mgr; struct ip_reassembly *assembler;
struct ip_reassembly_options opts = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
@@ -442,10 +442,10 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
.bucket_num = 8, .bucket_num = 8,
}; };
mgr = ip_reassembly_new(&opts); assembler = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(assembler != NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -453,10 +453,10 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
// frag1 // frag1
packet_parse(&pkt, (const char *)frag1, sizeof(frag1)); packet_parse(&pkt, (const char *)frag1, sizeof(frag1));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
1, 1, 0, 0, // ip4: find, add, del, timeout 1, 1, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -464,10 +464,10 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
// frag1 // frag1
packet_parse(&pkt, (const char *)frag1, sizeof(frag1)); packet_parse(&pkt, (const char *)frag1, sizeof(frag1));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
2, 1, 0, 0, // ip4: find, add, del, timeout 2, 1, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 1, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 1, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -475,10 +475,10 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
// frag2 // frag2
packet_parse(&pkt, (const char *)frag2, sizeof(frag2)); packet_parse(&pkt, (const char *)frag2, sizeof(frag2));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt); EXPECT_TRUE(new_pkt);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
3, 1, 1, 0, // ip4: find, add, del, timeout 3, 1, 1, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 1, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 1, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -528,7 +528,7 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
// free packet // free packet
packet_free(new_pkt); packet_free(new_pkt);
ip_reassembly_free(mgr); ip_reassembly_free(assembler);
} }
#endif #endif
@@ -538,7 +538,7 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
const struct layer *layer; const struct layer *layer;
struct ip_reassembly *mgr; struct ip_reassembly *assembler;
struct ip_reassembly_options opts = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
@@ -546,10 +546,10 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
.bucket_num = 8, .bucket_num = 8,
}; };
mgr = ip_reassembly_new(&opts); assembler = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(assembler != NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -557,10 +557,10 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
// frag2 // frag2
packet_parse(&pkt, (const char *)frag2, sizeof(frag2)); packet_parse(&pkt, (const char *)frag2, sizeof(frag2));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
1, 1, 0, 0, // ip4: find, add, del, timeout 1, 1, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -568,10 +568,10 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
// frag2 // frag2
packet_parse(&pkt, (const char *)frag2, sizeof(frag2)); packet_parse(&pkt, (const char *)frag2, sizeof(frag2));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
2, 1, 0, 0, // ip4: find, add, del, timeout 2, 1, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 1, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 1, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -579,10 +579,10 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
// frag1 // frag1
packet_parse(&pkt, (const char *)frag1, sizeof(frag1)); packet_parse(&pkt, (const char *)frag1, sizeof(frag1));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt); EXPECT_TRUE(new_pkt);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
3, 1, 1, 0, // ip4: find, add, del, timeout 3, 1, 1, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 1, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 1, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -632,7 +632,7 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
// free packet // free packet
packet_free(new_pkt); packet_free(new_pkt);
ip_reassembly_free(mgr); ip_reassembly_free(assembler);
} }
#endif #endif
@@ -641,7 +641,7 @@ TEST(IPV4_REASSEMBLE, FULL)
{ {
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
struct ip_reassembly *mgr; struct ip_reassembly *assembler;
struct ip_reassembly_options opts = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
@@ -649,10 +649,10 @@ TEST(IPV4_REASSEMBLE, FULL)
.bucket_num = 1, .bucket_num = 1,
}; };
mgr = ip_reassembly_new(&opts); assembler = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(assembler != NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -664,10 +664,10 @@ TEST(IPV4_REASSEMBLE, FULL)
// flow1 // flow1
packet_set_ipv4_src_addr(&pkt, 1); packet_set_ipv4_src_addr(&pkt, 1);
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
1, 1, 0, 0, // ip4: find, add, del, timeout 1, 1, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -675,10 +675,10 @@ TEST(IPV4_REASSEMBLE, FULL)
// flow2 // flow2
packet_set_ipv4_src_addr(&pkt, 2); packet_set_ipv4_src_addr(&pkt, 2);
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
2, 2, 0, 0, // ip4: find, add, del, timeout 2, 2, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -686,10 +686,10 @@ TEST(IPV4_REASSEMBLE, FULL)
// flow3 // flow3
packet_set_ipv4_src_addr(&pkt, 3); packet_set_ipv4_src_addr(&pkt, 3);
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
3, 2, 0, 0, // ip4: find, add, del, timeout 3, 2, 0, 0, // ip4: find, add, del, timeout
1, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 1, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -698,7 +698,7 @@ TEST(IPV4_REASSEMBLE, FULL)
// free packet // free packet
packet_free(new_pkt); packet_free(new_pkt);
ip_reassembly_free(mgr); ip_reassembly_free(assembler);
} }
#endif #endif

View File

@@ -608,7 +608,7 @@ TEST(IPV6_REASSEMBLE, NORMAL)
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
const struct layer *layer; const struct layer *layer;
struct ip_reassembly *mgr; struct ip_reassembly *assembler;
struct ip_reassembly_options opts = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
@@ -616,10 +616,10 @@ TEST(IPV6_REASSEMBLE, NORMAL)
.bucket_num = 8, .bucket_num = 8,
}; };
mgr = ip_reassembly_new(&opts); assembler = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(assembler != NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -627,10 +627,10 @@ TEST(IPV6_REASSEMBLE, NORMAL)
// frag1 // frag1
packet_parse(&pkt, (const char *)frag1, sizeof(frag1)); packet_parse(&pkt, (const char *)frag1, sizeof(frag1));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
1, 1, 0, 0, // ip6: find, add, del, timeout 1, 1, 0, 0, // ip6: find, add, del, timeout
@@ -638,10 +638,10 @@ TEST(IPV6_REASSEMBLE, NORMAL)
// frag2 // frag2
packet_parse(&pkt, (const char *)frag2, sizeof(frag2)); packet_parse(&pkt, (const char *)frag2, sizeof(frag2));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
2, 1, 0, 0, // ip6: find, add, del, timeout 2, 1, 0, 0, // ip6: find, add, del, timeout
@@ -649,10 +649,10 @@ TEST(IPV6_REASSEMBLE, NORMAL)
// frag3 // frag3
packet_parse(&pkt, (const char *)frag3, sizeof(frag3)); packet_parse(&pkt, (const char *)frag3, sizeof(frag3));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
3, 1, 0, 0, // ip6: find, add, del, timeout 3, 1, 0, 0, // ip6: find, add, del, timeout
@@ -660,10 +660,10 @@ TEST(IPV6_REASSEMBLE, NORMAL)
// frag4 // frag4
packet_parse(&pkt, (const char *)frag4, sizeof(frag4)); packet_parse(&pkt, (const char *)frag4, sizeof(frag4));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt); EXPECT_TRUE(new_pkt);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
4, 1, 1, 0, // ip6: find, add, del, timeout 4, 1, 1, 0, // ip6: find, add, del, timeout
@@ -707,7 +707,7 @@ TEST(IPV6_REASSEMBLE, NORMAL)
// free packet // free packet
packet_free(new_pkt); packet_free(new_pkt);
ip_reassembly_free(mgr); ip_reassembly_free(assembler);
} }
#endif #endif
@@ -716,7 +716,7 @@ TEST(IPV6_REASSEMBLE, EXPIRE)
{ {
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
struct ip_reassembly *mgr; struct ip_reassembly *assembler;
struct ip_reassembly_options opts = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
@@ -724,10 +724,10 @@ TEST(IPV6_REASSEMBLE, EXPIRE)
.bucket_num = 8, .bucket_num = 8,
}; };
mgr = ip_reassembly_new(&opts); assembler = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(assembler != NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -735,10 +735,10 @@ TEST(IPV6_REASSEMBLE, EXPIRE)
// frag1 // frag1
packet_parse(&pkt, (const char *)frag1, sizeof(frag1)); packet_parse(&pkt, (const char *)frag1, sizeof(frag1));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
1, 1, 0, 0, // ip6: find, add, del, timeout 1, 1, 0, 0, // ip6: find, add, del, timeout
@@ -746,10 +746,10 @@ TEST(IPV6_REASSEMBLE, EXPIRE)
// frag2 // frag2
packet_parse(&pkt, (const char *)frag2, sizeof(frag2)); packet_parse(&pkt, (const char *)frag2, sizeof(frag2));
new_pkt = ip_reassembly_packet(mgr, &pkt, 2); new_pkt = ip_reassembly_packet(assembler, &pkt, 2);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
2, 2, 1, 1, // ip6: find, add, del, timeout 2, 2, 1, 1, // ip6: find, add, del, timeout
@@ -758,7 +758,7 @@ TEST(IPV6_REASSEMBLE, EXPIRE)
// free packet // free packet
packet_free(new_pkt); packet_free(new_pkt);
ip_reassembly_free(mgr); ip_reassembly_free(assembler);
} }
#endif #endif
@@ -768,7 +768,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
const struct layer *layer; const struct layer *layer;
struct ip_reassembly *mgr; struct ip_reassembly *assembler;
struct ip_reassembly_options opts = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
@@ -776,10 +776,10 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
.bucket_num = 8, .bucket_num = 8,
}; };
mgr = ip_reassembly_new(&opts); assembler = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(assembler != NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -787,10 +787,10 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
// frag1 // frag1
packet_parse(&pkt, (const char *)frag1, sizeof(frag1)); packet_parse(&pkt, (const char *)frag1, sizeof(frag1));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
1, 1, 0, 0, // ip6: find, add, del, timeout 1, 1, 0, 0, // ip6: find, add, del, timeout
@@ -798,10 +798,10 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
// frag1 // frag1
packet_parse(&pkt, (const char *)frag1, sizeof(frag1)); packet_parse(&pkt, (const char *)frag1, sizeof(frag1));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
2, 1, 0, 0, // ip6: find, add, del, timeout 2, 1, 0, 0, // ip6: find, add, del, timeout
@@ -809,10 +809,10 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
// frag2 // frag2
packet_parse(&pkt, (const char *)frag2, sizeof(frag2)); packet_parse(&pkt, (const char *)frag2, sizeof(frag2));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
3, 1, 0, 0, // ip6: find, add, del, timeout 3, 1, 0, 0, // ip6: find, add, del, timeout
@@ -820,10 +820,10 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
// frag3 // frag3
packet_parse(&pkt, (const char *)frag3, sizeof(frag3)); packet_parse(&pkt, (const char *)frag3, sizeof(frag3));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
4, 1, 0, 0, // ip6: find, add, del, timeout 4, 1, 0, 0, // ip6: find, add, del, timeout
@@ -831,10 +831,10 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
// frag4 // frag4
packet_parse(&pkt, (const char *)frag4, sizeof(frag4)); packet_parse(&pkt, (const char *)frag4, sizeof(frag4));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt); EXPECT_TRUE(new_pkt);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
5, 1, 1, 0, // ip6: find, add, del, timeout 5, 1, 1, 0, // ip6: find, add, del, timeout
@@ -878,7 +878,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
// free packet // free packet
packet_free(new_pkt); packet_free(new_pkt);
ip_reassembly_free(mgr); ip_reassembly_free(assembler);
} }
#endif #endif
@@ -888,7 +888,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
const struct layer *layer; const struct layer *layer;
struct ip_reassembly *mgr; struct ip_reassembly *assembler;
struct ip_reassembly_options opts = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
@@ -896,10 +896,10 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
.bucket_num = 8, .bucket_num = 8,
}; };
mgr = ip_reassembly_new(&opts); assembler = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(assembler != NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -907,10 +907,10 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
// frag4 // frag4
packet_parse(&pkt, (const char *)frag4, sizeof(frag4)); packet_parse(&pkt, (const char *)frag4, sizeof(frag4));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
1, 1, 0, 0, // ip6: find, add, del, timeout 1, 1, 0, 0, // ip6: find, add, del, timeout
@@ -918,10 +918,10 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
// frag4 // frag4
packet_parse(&pkt, (const char *)frag4, sizeof(frag4)); packet_parse(&pkt, (const char *)frag4, sizeof(frag4));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
2, 1, 0, 0, // ip6: find, add, del, timeout 2, 1, 0, 0, // ip6: find, add, del, timeout
@@ -929,10 +929,10 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
// frag3 // frag3
packet_parse(&pkt, (const char *)frag3, sizeof(frag3)); packet_parse(&pkt, (const char *)frag3, sizeof(frag3));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
3, 1, 0, 0, // ip6: find, add, del, timeout 3, 1, 0, 0, // ip6: find, add, del, timeout
@@ -940,10 +940,10 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
// frag2 // frag2
packet_parse(&pkt, (const char *)frag2, sizeof(frag2)); packet_parse(&pkt, (const char *)frag2, sizeof(frag2));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
4, 1, 0, 0, // ip6: find, add, del, timeout 4, 1, 0, 0, // ip6: find, add, del, timeout
@@ -951,10 +951,10 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
// frag1 // frag1
packet_parse(&pkt, (const char *)frag1, sizeof(frag1)); packet_parse(&pkt, (const char *)frag1, sizeof(frag1));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt); EXPECT_TRUE(new_pkt);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
5, 1, 1, 0, // ip6: find, add, del, timeout 5, 1, 1, 0, // ip6: find, add, del, timeout
@@ -998,7 +998,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
// free packet // free packet
packet_free(new_pkt); packet_free(new_pkt);
ip_reassembly_free(mgr); ip_reassembly_free(assembler);
} }
#endif #endif
@@ -1008,7 +1008,7 @@ TEST(IPV6_REASSEMBLE, FULL)
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
struct in6_addr src_addr; struct in6_addr src_addr;
struct ip_reassembly *mgr; struct ip_reassembly *assembler;
struct ip_reassembly_options opts = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
@@ -1016,10 +1016,10 @@ TEST(IPV6_REASSEMBLE, FULL)
.bucket_num = 1, .bucket_num = 1,
}; };
mgr = ip_reassembly_new(&opts); assembler = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(assembler != NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -1032,10 +1032,10 @@ TEST(IPV6_REASSEMBLE, FULL)
// flow1 // flow1
memset(&src_addr, 1, sizeof(src_addr)); memset(&src_addr, 1, sizeof(src_addr));
packet_set_ipv6_src_addr(&pkt, src_addr); packet_set_ipv6_src_addr(&pkt, src_addr);
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
1, 1, 0, 0, // ip6: find, add, del, timeout 1, 1, 0, 0, // ip6: find, add, del, timeout
@@ -1044,10 +1044,10 @@ TEST(IPV6_REASSEMBLE, FULL)
// flow2 // flow2
memset(&src_addr, 2, sizeof(src_addr)); memset(&src_addr, 2, sizeof(src_addr));
packet_set_ipv6_src_addr(&pkt, src_addr); packet_set_ipv6_src_addr(&pkt, src_addr);
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
2, 2, 0, 0, // ip6: find, add, del, timeout 2, 2, 0, 0, // ip6: find, add, del, timeout
@@ -1056,10 +1056,10 @@ TEST(IPV6_REASSEMBLE, FULL)
// flow3 // flow3
memset(&src_addr, 3, sizeof(src_addr)); memset(&src_addr, 3, sizeof(src_addr));
packet_set_ipv6_src_addr(&pkt, src_addr); packet_set_ipv6_src_addr(&pkt, src_addr);
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
3, 2, 0, 0, // ip6: find, add, del, timeout 3, 2, 0, 0, // ip6: find, add, del, timeout
@@ -1068,7 +1068,7 @@ TEST(IPV6_REASSEMBLE, FULL)
// free packet // free packet
packet_free(new_pkt); packet_free(new_pkt);
ip_reassembly_free(mgr); ip_reassembly_free(assembler);
} }
#endif #endif
@@ -1077,7 +1077,7 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
{ {
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
struct ip_reassembly *mgr; struct ip_reassembly *assembler;
struct ip_reassembly_options opts = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
@@ -1085,10 +1085,10 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
.bucket_num = 8, .bucket_num = 8,
}; };
mgr = ip_reassembly_new(&opts); assembler = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(assembler != NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
0, 0, 0, 0, // ip6: find, add, del, timeout 0, 0, 0, 0, // ip6: find, add, del, timeout
@@ -1096,10 +1096,10 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
// frag1 // frag1
packet_parse(&pkt, (const char *)frag1, sizeof(frag1)); packet_parse(&pkt, (const char *)frag1, sizeof(frag1));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
1, 1, 0, 0, // ip6: find, add, del, timeout 1, 1, 0, 0, // ip6: find, add, del, timeout
@@ -1107,10 +1107,10 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
// frag2 // frag2
packet_parse(&pkt, (const char *)frag2, sizeof(frag2)); packet_parse(&pkt, (const char *)frag2, sizeof(frag2));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
2, 1, 0, 0, // ip6: find, add, del, timeout 2, 1, 0, 0, // ip6: find, add, del, timeout
@@ -1121,10 +1121,10 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
memcpy(dup_frag, frag3, sizeof(frag3)); memcpy(dup_frag, frag3, sizeof(frag3));
packet_parse(&pkt, (const char *)dup_frag, sizeof(dup_frag)); packet_parse(&pkt, (const char *)dup_frag, sizeof(dup_frag));
packet_set_ipv6_frag_offset(&pkt, 2048); packet_set_ipv6_frag_offset(&pkt, 2048);
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
3, 1, 0, 0, // ip6: find, add, del, timeout 3, 1, 0, 0, // ip6: find, add, del, timeout
@@ -1132,10 +1132,10 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
// frag4 // frag4
packet_parse(&pkt, (const char *)frag4, sizeof(frag4)); packet_parse(&pkt, (const char *)frag4, sizeof(frag4));
new_pkt = ip_reassembly_packet(mgr, &pkt, 1); new_pkt = ip_reassembly_packet(assembler, &pkt, 1);
EXPECT_TRUE(new_pkt == NULL); EXPECT_TRUE(new_pkt == NULL);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(assembler),
0, 0, 0, 0, // ip4: find, add, del, timeout 0, 0, 0, 0, // ip4: find, add, del, timeout
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag 0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
4, 1, 1, 0, // ip6: find, add, del, timeout 4, 1, 1, 0, // ip6: find, add, del, timeout
@@ -1144,7 +1144,7 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
// free packet // free packet
packet_free(new_pkt); packet_free(new_pkt);
ip_reassembly_free(mgr); ip_reassembly_free(assembler);
} }
#endif #endif