feature: packet IO support IP reassembly
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <assert.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "uthash.h"
|
||||
@@ -23,14 +24,14 @@ const struct route_ctx *packet_get_route_ctx(const struct packet *pkt)
|
||||
return &pkt->meta.route_ctx;
|
||||
}
|
||||
|
||||
void packet_set_origin_ctx(struct packet *pkt, void *ctx)
|
||||
void packet_set_origin(struct packet *pkt, struct packet_origin *origin)
|
||||
{
|
||||
pkt->meta.origin_ctx = ctx;
|
||||
pkt->origin = *origin;
|
||||
}
|
||||
|
||||
const void *packet_get_origin_ctx(const struct packet *pkt)
|
||||
struct packet_origin *packet_get_origin(struct packet *pkt)
|
||||
{
|
||||
return pkt->meta.origin_ctx;
|
||||
return &pkt->origin;
|
||||
}
|
||||
|
||||
void packet_set_sids(struct packet *pkt, const struct sids *sids)
|
||||
@@ -925,7 +926,14 @@ struct packet *packet_dup(const struct packet *pkt)
|
||||
dup_pkt->frag_layer = &dup_pkt->layers[pkt->frag_layer - pkt->layers];
|
||||
}
|
||||
memcpy(&dup_pkt->meta, &pkt->meta, sizeof(struct metadata));
|
||||
packet_set_origin_ctx(dup_pkt, (void *)NULL);
|
||||
struct packet_origin origin = {
|
||||
.type = ORIGIN_TYPE_USER,
|
||||
.ctx = NULL,
|
||||
.cb = NULL,
|
||||
.args = NULL,
|
||||
.thr_idx = -1,
|
||||
};
|
||||
packet_set_origin(dup_pkt, &origin);
|
||||
|
||||
return dup_pkt;
|
||||
}
|
||||
@@ -941,6 +949,11 @@ void packet_free(struct packet *pkt)
|
||||
return;
|
||||
}
|
||||
|
||||
if (pkt->origin.cb)
|
||||
{
|
||||
pkt->origin.cb(pkt, pkt->origin.args);
|
||||
}
|
||||
|
||||
if (pkt->need_free)
|
||||
{
|
||||
free((void *)pkt);
|
||||
@@ -953,14 +966,54 @@ int packet_is_fragment(const struct packet *pkt)
|
||||
return (pkt->frag_layer) ? 1 : 0;
|
||||
}
|
||||
|
||||
int packet_is_defraged(const struct packet *pkt)
|
||||
{
|
||||
return pkt->is_defraged;
|
||||
}
|
||||
|
||||
void packet_set_defraged(struct packet *pkt)
|
||||
{
|
||||
pkt->is_defraged = 1;
|
||||
TAILQ_INIT(&pkt->frag_list);
|
||||
}
|
||||
|
||||
void packet_push_frag(struct packet *pkt, struct packet *frag)
|
||||
{
|
||||
if (!packet_is_defraged(pkt))
|
||||
{
|
||||
assert(0);
|
||||
return;
|
||||
}
|
||||
|
||||
TAILQ_INSERT_TAIL(&pkt->frag_list, frag, frag_tqe);
|
||||
}
|
||||
|
||||
struct packet *packet_pop_frag(struct packet *pkt)
|
||||
{
|
||||
if (!packet_is_defraged(pkt))
|
||||
{
|
||||
assert(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct packet *frag = TAILQ_FIRST(&pkt->frag_list);
|
||||
if (frag)
|
||||
{
|
||||
TAILQ_REMOVE(&pkt->frag_list, frag, frag_tqe);
|
||||
}
|
||||
return frag;
|
||||
}
|
||||
|
||||
void packet_set_exdata(struct packet *pkt, int idx, void *ex_ptr)
|
||||
{
|
||||
struct exdata_runtime *exdata_rt = (struct exdata_runtime *)packet_get_user_data(pkt);
|
||||
assert(exdata_rt);
|
||||
exdata_set(exdata_rt, idx, ex_ptr);
|
||||
}
|
||||
|
||||
void *packet_get_exdata(struct packet *pkt, int idx)
|
||||
{
|
||||
struct exdata_runtime *exdata_rt = (struct exdata_runtime *)packet_get_user_data(pkt);
|
||||
assert(exdata_rt);
|
||||
return exdata_get(exdata_rt, idx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user