Refactor the session manager using session transformation 2D array & Update test case
This commit is contained in:
@@ -365,7 +365,7 @@ static inline void ip_frag_pkt_free(struct ip_frag_pkt *frag)
|
||||
* ip flow
|
||||
******************************************************************************/
|
||||
|
||||
static inline void ip_flow_init(struct ip_flow *flow, const struct ip_flow_key *key, uint64_t now_sec)
|
||||
static inline void ip_flow_init(struct ip_flow *flow, const struct ip_flow_key *key, uint64_t now)
|
||||
{
|
||||
static const struct ip_frag_pkt zero_frag = {
|
||||
.data = NULL,
|
||||
@@ -376,7 +376,7 @@ static inline void ip_flow_init(struct ip_flow *flow, const struct ip_flow_key *
|
||||
flow->lru.tqe_next = NULL;
|
||||
flow->lru.tqe_prev = NULL;
|
||||
flow->key = *key;
|
||||
flow->create_time = now_sec;
|
||||
flow->create_time = now;
|
||||
flow->expected_total_size = UINT32_MAX;
|
||||
flow->received_frag_size = 0;
|
||||
flow->next_fill_idx = IP_MIN_FRAG_NUM;
|
||||
@@ -478,11 +478,11 @@ static inline void ip_reassembly_del_flow(struct ip_reassembly *mgr, struct ip_f
|
||||
mgr->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_sec)
|
||||
static inline void ip_reassembly_reuse_flow(struct ip_reassembly *mgr, struct ip_flow *flow, const struct ip_flow_key *key, uint64_t now)
|
||||
{
|
||||
ip_reassembly_del_flow(mgr, flow);
|
||||
ip_flow_free(flow);
|
||||
ip_flow_init(flow, key, now_sec);
|
||||
ip_flow_init(flow, key, now);
|
||||
ip_reassembly_add_flow(mgr, flow);
|
||||
}
|
||||
|
||||
@@ -491,7 +491,7 @@ static inline void ip_reassembly_reuse_flow(struct ip_reassembly *mgr, struct ip
|
||||
* free : the first empty 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_sec)
|
||||
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)
|
||||
{
|
||||
ip_reassembly_stat_inc(mgr, find, key);
|
||||
|
||||
@@ -532,7 +532,7 @@ static struct ip_flow *ip_reassembly_find_flow(struct ip_reassembly *mgr, const
|
||||
{
|
||||
empty = (empty == NULL) ? (p1 + i) : empty;
|
||||
}
|
||||
else if (timeout + p1[i].create_time <= now_sec)
|
||||
else if (timeout + p1[i].create_time <= now)
|
||||
{
|
||||
old = (old == NULL) ? (p1 + i) : old;
|
||||
}
|
||||
@@ -547,7 +547,7 @@ static struct ip_flow *ip_reassembly_find_flow(struct ip_reassembly *mgr, const
|
||||
{
|
||||
empty = (empty == NULL) ? (p2 + i) : empty;
|
||||
}
|
||||
else if (timeout + p2[i].create_time <= now_sec)
|
||||
else if (timeout + p2[i].create_time <= now)
|
||||
{
|
||||
old = (old == NULL) ? (p2 + i) : old;
|
||||
}
|
||||
@@ -558,19 +558,19 @@ static struct ip_flow *ip_reassembly_find_flow(struct ip_reassembly *mgr, const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct ip_flow *ip_reassembly_update_flow(struct ip_reassembly *mgr, const struct ip_flow_key *key, uint64_t now_sec)
|
||||
static struct ip_flow *ip_reassembly_update_flow(struct ip_reassembly *mgr, const struct ip_flow_key *key, uint64_t now)
|
||||
{
|
||||
struct ip_flow *flow = NULL;
|
||||
struct ip_flow *free = NULL;
|
||||
struct ip_flow *expired = NULL;
|
||||
|
||||
flow = ip_reassembly_find_flow(mgr, key, &free, &expired, now_sec);
|
||||
flow = ip_reassembly_find_flow(mgr, key, &free, &expired, now);
|
||||
if (flow == NULL)
|
||||
{
|
||||
if (expired)
|
||||
{
|
||||
IP_REASSEMBLE_DEBUG1("add ip flow success: reuse expired entry", key);
|
||||
ip_reassembly_reuse_flow(mgr, expired, key, now_sec);
|
||||
ip_reassembly_reuse_flow(mgr, expired, key, now);
|
||||
ip_reassembly_stat_inc(mgr, timeout, key);
|
||||
|
||||
mgr->last = expired;
|
||||
@@ -580,7 +580,7 @@ static struct ip_flow *ip_reassembly_update_flow(struct ip_reassembly *mgr, cons
|
||||
if (free)
|
||||
{
|
||||
IP_REASSEMBLE_DEBUG1("add ip flow success: use free entry", key);
|
||||
ip_flow_init(free, key, now_sec);
|
||||
ip_flow_init(free, key, now);
|
||||
ip_reassembly_add_flow(mgr, free);
|
||||
|
||||
mgr->last = free;
|
||||
@@ -595,10 +595,10 @@ static struct ip_flow *ip_reassembly_update_flow(struct ip_reassembly *mgr, cons
|
||||
else
|
||||
{
|
||||
// expired
|
||||
if (mgr->timeout + flow->create_time <= now_sec)
|
||||
if (mgr->timeout + flow->create_time <= now)
|
||||
{
|
||||
IP_REASSEMBLE_DEBUG1("add ip flow success: reuse expired entry", key);
|
||||
ip_reassembly_reuse_flow(mgr, flow, key, now_sec);
|
||||
ip_reassembly_reuse_flow(mgr, flow, key, now);
|
||||
ip_reassembly_stat_inc(mgr, timeout, key);
|
||||
|
||||
mgr->last = flow;
|
||||
@@ -814,13 +814,13 @@ void ip_reassembly_free(struct ip_reassembly *mgr)
|
||||
}
|
||||
}
|
||||
|
||||
void ip_reassembly_expire(struct ip_reassembly *mgr, uint64_t now_sec)
|
||||
void ip_reassembly_expire(struct ip_reassembly *mgr, uint64_t now)
|
||||
{
|
||||
struct ip_flow *flow = NULL;
|
||||
uint64_t timeout = mgr->timeout;
|
||||
|
||||
TAILQ_FOREACH(flow, &mgr->lru, lru)
|
||||
if (timeout + flow->create_time <= now_sec)
|
||||
if (timeout + flow->create_time <= now)
|
||||
{
|
||||
IP_REASSEMBLE_DEBUG1("expire ip flow: discarding old fragmented packets", &flow->key);
|
||||
ip_reassembly_del_flow(mgr, flow);
|
||||
@@ -846,7 +846,7 @@ struct ip_reassembly_stat *ip_reassembly_get_stat(struct ip_reassembly *mgr)
|
||||
* 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_sec)
|
||||
struct packet *ip_reassembly_packet(struct ip_reassembly *mgr, const struct packet *pkt, uint64_t now)
|
||||
{
|
||||
struct packet *pkt1;
|
||||
struct packet *pkt2;
|
||||
@@ -864,10 +864,10 @@ struct packet *ip_reassembly_packet(struct ip_reassembly *mgr, const struct pack
|
||||
|
||||
if (layer->type == LAYER_TYPE_IPV4)
|
||||
{
|
||||
pkt1 = ipv4_reassembly_packet(mgr, pkt, now_sec);
|
||||
pkt1 = ipv4_reassembly_packet(mgr, pkt, now);
|
||||
if (pkt1 && pkt1->frag_layer)
|
||||
{
|
||||
pkt2 = ip_reassembly_packet(mgr, pkt1, now_sec);
|
||||
pkt2 = ip_reassembly_packet(mgr, pkt1, now);
|
||||
packet_free(pkt1);
|
||||
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)
|
||||
{
|
||||
pkt1 = ipv6_reassembly_packet(mgr, pkt, now_sec);
|
||||
pkt1 = ipv6_reassembly_packet(mgr, pkt, now);
|
||||
if (pkt1 && pkt1->frag_layer)
|
||||
{
|
||||
pkt2 = ip_reassembly_packet(mgr, pkt1, now_sec);
|
||||
pkt2 = ip_reassembly_packet(mgr, pkt1, now);
|
||||
packet_free(pkt1);
|
||||
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_sec)
|
||||
struct packet *ipv4_reassembly_packet(struct ip_reassembly *mgr, const struct packet *pkt, uint64_t now)
|
||||
{
|
||||
const struct layer *layer = pkt->frag_layer;
|
||||
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.proto = ipv4_hdr_get_proto(hdr);
|
||||
|
||||
struct ip_flow *flow = ip_reassembly_update_flow(mgr, &key, now_sec);
|
||||
struct ip_flow *flow = ip_reassembly_update_flow(mgr, &key, now);
|
||||
if (flow == NULL)
|
||||
{
|
||||
return NULL;
|
||||
@@ -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_sec)
|
||||
struct packet *ipv6_reassembly_packet(struct ip_reassembly *mgr, const struct packet *pkt, uint64_t now)
|
||||
{
|
||||
const struct layer *layer = pkt->frag_layer;
|
||||
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.proto = 0; // only first fragment has the upper layer protocol
|
||||
|
||||
struct ip_flow *flow = ip_reassembly_update_flow(mgr, &key, now_sec);
|
||||
struct ip_flow *flow = ip_reassembly_update_flow(mgr, &key, now);
|
||||
if (flow == NULL)
|
||||
{
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user